#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr collection_methods[meth_max];
extern cptr set_methods[meth_max];
extern cptr sset_methods[meth_max];
extern cptr entset_methods[meth_max];
extern cptr boolean_methods[meth_max];
extern cptr scope_methods[meth_max];
extern cptr jscope_methods[meth_max];
#include "cint.h"
extern cptr strpool_methods[meth_max];
extern cptr pset_methods[meth_max];

extern cint boolean_True;
extern cint entset_predef;
extern cint object_Undefined;
extern cint scope_global;
extern cint boolean_False;
extern cint scope_curr;
extern cint strpool_str_31;
extern cint strpool_str_32;
extern cint strpool_str_13;
extern cint strpool_str_15;
extern cint strpool_str_63;
extern cint strpool_str_64;
extern cint strpool_str_49;


cptr powset_methods[meth_max];

cint powset_alloc(cint powset_self, cint powset_base_set){
  cint powset_result, powset_bs, powset_i;
  cint t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t18;
  ((cptr)powset_base_set)[1] += 1;
  t2 = ((cptr)(((cptr)powset_base_set)[0]))[38];
  t3 = ((f0)t2)((cint)powset_base_set); /* Eval*/
  powset_bs = t3;
  t5 = set_alloc((cint)powset_self);
  powset_result = t5;
  ((cptr)powset_self)[5] /* representation*/ = strpool_str_63;
  t6 = powset_bs == entset_predef;
  t7 = t6;
  if (t7){
    t8 = ((cptr)scope_curr)[7] /* enclosing*/ == scope_global;
    t7 = t8;
  };
  if (t7){
    ((cptr)powset_self)[6] /* name_space*/ = scope_curr;
  };
  t9 = ((cptr)powset_bs)[6] /* name_space*/ != object_Undefined;
  t10 = t9;
  if (t10){
    t11 = ((cptr)scope_curr)[7] /* enclosing*/ == scope_global;
    t10 = t11;
  };
  if (t10){
    t12 = mem_malloc(36); ((cptr)t12)[0] = jscope_methods;
    t13 = jscope_alloc((cint)t12, (cint)scope_curr, (cint)((cptr)powset_bs)[6] /* name_space*/);
    ((cptr)powset_self)[6] /* name_space*/ = t13;
  };
  ((cptr)powset_self)[7] /* elemtype*/ = powset_base_set;
  t14 = ((cptr)powset_bs)[3] /* len*/ < 8;
  t15 = t14;
  if (t15){
    t16 = ((cptr)powset_bs)[3] /* len*/ >= 0;
    t15 = t16;
  };
  if (t15){
    ((cptr)powset_self)[3] /* len*/ = 1;
    for (powset_i = 1; powset_i <= ((cptr)powset_bs)[3] /* len*/; powset_i++){
      t18 = ((cptr)powset_self)[3] /* len*/ * 2;
      ((cptr)powset_self)[3] /* len*/ = t18;
    };t17:;
  }else{
    ((cptr)powset_self)[3] /* len*/ = -1;
  };
  object_Dec_ref(powset_bs);
  t1 = powset_result;
  goto t1_label;
  t1_label: return t1;
}

cint powset_reclaim(cint powset_self){
  cint t19;
  set_reclaim((cint)powset_self);
  t19_label: return t19;
}

cint powset_Contains(cint powset_self, cint powset_ob){
  cint powset_result, powset_et, powset_os;
  cint t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41;
  powset_result = boolean_False;
  t21 = ((cptr)(((cptr)powset_ob)[0]))[38];
  t22 = ((f0)t21)((cint)powset_ob); /* Eval*/
  powset_ob = t22;
  ((cptr)((cptr)powset_self)[7] /* elemtype*/)[1] += 1;
  t24 = ((cptr)(((cptr)((cptr)powset_self)[7] /* elemtype*/)[0]))[38];
  t25 = ((f0)t24)((cint)((cptr)powset_self)[7] /* elemtype*/); /* Eval*/
  powset_et = t25;
  t27 = ((cptr)powset_ob)[4] /* class_of*/ == strpool_str_32;
  if (t27){
    powset_os = powset_ob;
    t28 = ((cptr)powset_os)[3] /* len*/ != 0;
    if (t28){
      ((cptr)((cptr)powset_os)[7] /* elemtype*/)[1] += 1;
      ((cptr)powset_et)[1] += 1;
      t29 = ((cptr)(((cptr)((cptr)powset_os)[7] /* elemtype*/)[0]))[104];
      t30 = ((f0)t29)((cint)((cptr)powset_os)[7] /* elemtype*/, (cint)powset_et); /* Subset*/
      powset_result = t30;
    };
    t32 = powset_result != boolean_True;
    if (t32){
      ((cptr)powset_os)[1] += 1;
      ((cptr)powset_et)[1] += 1;
      t33 = ((cptr)(((cptr)powset_os)[0]))[104];
      t34 = ((f0)t33)((cint)powset_os, (cint)powset_et); /* Subset*/
      powset_result = t34;
      t36 = powset_result == boolean_True;
      if (t36){
        object_Dec_ref(((cptr)powset_os)[7] /* elemtype*/);
        ((cptr)((cptr)powset_self)[7] /* elemtype*/)[1] += 1;
        ((cptr)powset_os)[7] /* elemtype*/ = ((cptr)powset_self)[7] /* elemtype*/;
        t37 = ((cptr)powset_os)[6] /* name_space*/ == object_Undefined;
        t38 = t37;
        if (t38){
          t39 = ((cptr)powset_self)[6] /* name_space*/ != object_Undefined;
          t38 = t39;
        };
        t40 = t38;
        if (t40){
          t41 = ((cptr)powset_os)[3] /* len*/ == 0;
          t40 = t41;
        };
        if (t40){
          ((cptr)powset_os)[6] /* name_space*/ = ((cptr)powset_self)[6] /* name_space*/;
        };
      };
    };
  };
  object_Dec_ref(powset_self);
  object_Dec_ref(powset_ob);
  object_Dec_ref(powset_et);
  t20 = powset_result;
  goto t20_label;
  t20_label: return t20;
}

cint powset_Intersect(cint powset_self, cint powset_ob){
  cint powset_result, powset_os, powset_et;
  cint t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63, t64, t65, t66;
  t45 = ((cptr)powset_ob)[5] /* representation*/ == strpool_str_31;
  t46 = t45;
  if (!t46){  ((cptr)powset_self)[1] += 1;
  ((cptr)powset_ob)[1] += 1;
  t43 = ((cptr)(((cptr)powset_self)[0]))[104];
  t44 = ((f0)t43)((cint)powset_self, (cint)powset_ob); /* Subset*/
    t47 = t44 == boolean_True;
    t46 = t47;
  };
  if (t46){
    object_Dec_ref(powset_ob);
    t42 = powset_self;
    goto t42_label;
  }else{
  ((cptr)powset_ob)[1] += 1;
  ((cptr)powset_self)[1] += 1;
  t48 = ((cptr)(((cptr)powset_ob)[0]))[104];
  t49 = ((f0)t48)((cint)powset_ob, (cint)powset_self); /* Subset*/
  t50 = t49 == boolean_True;
  if (t50){
    object_Dec_ref(powset_self);
    t42 = powset_ob;
    goto t42_label;
  }else{
  t51 = ((cptr)powset_ob)[5] /* representation*/ == strpool_str_63;
  if (t51){
    powset_os = powset_ob;
    ((cptr)((cptr)powset_self)[7] /* elemtype*/)[1] += 1;
    t52 = ((cptr)(((cptr)((cptr)powset_self)[7] /* elemtype*/)[0]))[38];
    t53 = ((f0)t52)((cint)((cptr)powset_self)[7] /* elemtype*/); /* Eval*/
    ((cptr)((cptr)powset_os)[7] /* elemtype*/)[1] += 1;
    t54 = ((cptr)(((cptr)((cptr)powset_os)[7] /* elemtype*/)[0]))[38];
    t55 = ((f0)t54)((cint)((cptr)powset_os)[7] /* elemtype*/); /* Eval*/
    t57 = ((cptr)(((cptr)t53)[0]))[54];
    t58 = ((f0)t57)((cint)t53, (cint)t55); /* Intersect*/
    powset_et = t58;
    object_Dec_ref(powset_self);
    object_Dec_ref(powset_ob);
    t61 = powset_et == object_Undefined;
    t62 = t61;
    if (!t62){      t63 = ((cptr)powset_et)[3] /* len*/ == 0;
      t62 = t63;
    };
    if (t62){
      t42 = powset_et;
      goto t42_label;
    };
    t64 = mem_malloc(32); ((cptr)t64)[0] = powset_methods;
    t65 = powset_alloc((cint)t64, (cint)powset_et);
    t42 = t65;
    goto t42_label;
  }else{
    t66 = set_Intersect((cint)powset_self, (cint)powset_ob);
    t42 = t66;
    goto t42_label;
  };};};
  t42 = powset_result;
  goto t42_label;
  t42_label: return t42;
}

cint powset_lookup(cint powset_self, cint powset_i){
  cint powset_result, powset_et, powset_j;
  cint t67, t68, t69, t70, t71, t72, t73, t76, t77, t78, t79, t80, t81, t82, t83, t84, t85;
  ((cptr)((cptr)powset_self)[7] /* elemtype*/)[1] += 1;
  t68 = ((cptr)(((cptr)((cptr)powset_self)[7] /* elemtype*/)[0]))[38];
  t69 = ((f0)t68)((cint)((cptr)powset_self)[7] /* elemtype*/); /* Eval*/
  powset_et = t69;
  t71 = powset_i - 1;
  powset_i = t71;
  powset_j = 1;
  t72 = mem_malloc(48); ((cptr)t72)[0] = sset_methods;
  t73 = sset_alloc((cint)t72);
  powset_result = t73;
  t74:
  t76 = powset_i > 0;
  if (!t76) goto t75;
    t77 = cint_mod((cint)powset_i, (cint)2) == 1;
    if (t77){
      t80 = ((cptr)(((cptr)powset_et)[0]))[62];
      t79 = ((f0)t80)((cint)powset_et, (cint)powset_j); /* lookup*/
      ((cptr)t79)[1] += 1;
      t81 = ((cptr)(((cptr)powset_result)[0]))[7];
      t82 = ((f0)t81)((cint)powset_result, (cint)t79); /* Append*/
      powset_result = t82;
    };
    t84 = powset_i / 2;
    powset_i = t84;
    t85 = powset_j + 1;
    powset_j = t85;
  goto t74;
  t75:;
  object_Dec_ref(powset_et);
  t67 = powset_result;
  goto t67_label;
  t67_label: return t67;
}

cint powset_Mkstr(cint powset_self){
  cint powset_result, powset_et;
  cint t86, t87, t88, t89, t90, t91, t92, t93, t94, t95, t96, t97, t98, t99, t100, t101, t102, t103;
  ((cptr)((cptr)powset_self)[7] /* elemtype*/)[1] += 1;
  t87 = ((cptr)(((cptr)((cptr)powset_self)[7] /* elemtype*/)[0]))[38];
  t88 = ((f0)t87)((cint)((cptr)powset_self)[7] /* elemtype*/); /* Eval*/
  powset_et = t88;
  t90 = ((cptr)powset_et)[3] /* len*/ < 8;
  if (t90){
    object_Dec_ref(powset_et);
    t91 = set_Mkstr((cint)powset_self);
    t86 = t91;
    goto t86_label;
  };
  ((cptr)strpool_str_13)[1] += 1;
  ((cptr)strpool_str_64)[1] += 1;
  t92 = ((cptr)(((cptr)strpool_str_13)[0]))[97];
  t93 = ((f0)t92)((cint)strpool_str_13, (cint)strpool_str_64); /* Plus*/
  t94 = ((cptr)(((cptr)powset_et)[0]))[88];
  t95 = ((f0)t94)((cint)powset_et); /* Mkstr*/
  t97 = ((cptr)(((cptr)t93)[0]))[97];
  t98 = ((f0)t97)((cint)t93, (cint)t95); /* Plus*/
  ((cptr)strpool_str_15)[1] += 1;
  t101 = ((cptr)(((cptr)t98)[0]))[97];
  t102 = ((f0)t101)((cint)t98, (cint)strpool_str_15); /* Plus*/
  powset_result = t102;
  object_Dec_ref(powset_self);
  t86 = powset_result;
  goto t86_label;
  t86_label: return t86;
}

cint powset_Plus(cint powset_self, cint powset_ob){
  cint powset_result, powset_os;
  cint t104, t105, t106, t107, t108, t109, t110, t111;
  powset_os = powset_ob;
  t105 = ((cptr)powset_ob)[5] /* representation*/ == strpool_str_31;
  if (t105){
    object_Dec_ref(powset_self);
    t104 = powset_ob;
    goto t104_label;
  }else{
  t108 = ((cptr)powset_ob)[5] /* representation*/ == strpool_str_63;
  t109 = t108;
  if (t109){
  ((cptr)((cptr)powset_os)[7] /* elemtype*/)[1] += 1;
  ((cptr)((cptr)powset_self)[7] /* elemtype*/)[1] += 1;
  t106 = ((cptr)(((cptr)((cptr)powset_os)[7] /* elemtype*/)[0]))[104];
  t107 = ((f0)t106)((cint)((cptr)powset_os)[7] /* elemtype*/, (cint)((cptr)powset_self)[7] /* elemtype*/); /* Subset*/
    t110 = t107 == boolean_True;
    t109 = t110;
  };
  if (t109){
    object_Dec_ref(powset_ob);
    t104 = powset_self;
    goto t104_label;
  }else{
    t111 = set_Plus((cint)powset_self, (cint)powset_ob);
    t104 = t111;
    goto t104_label;
  };};
  t104 = powset_result;
  goto t104_label;
  t104_label: return t104;
}

cint powset_Subset(cint powset_self, cint powset_ob){
  cint powset_result, powset_os;
  cint t112, t113, t114, t115, t116, t117, t118, t119, t120, t121, t122, t123, t124, t125, t126, t127, t128, t129, t130, t131, t132, t133;
  powset_os = powset_ob;
  t120 = ((cptr)powset_ob)[5] /* representation*/ == strpool_str_31;
  t121 = t120;
  if (!t121){    t122 = ((cptr)powset_ob)[5] /* representation*/ == strpool_str_63;
    t123 = t122;
    if (t123){
  ((cptr)((cptr)powset_self)[7] /* elemtype*/)[1] += 1;
  t113 = ((cptr)(((cptr)((cptr)powset_self)[7] /* elemtype*/)[0]))[38];
  t114 = ((f0)t113)((cint)((cptr)powset_self)[7] /* elemtype*/); /* Eval*/
  ((cptr)((cptr)powset_os)[7] /* elemtype*/)[1] += 1;
  t115 = ((cptr)(((cptr)((cptr)powset_os)[7] /* elemtype*/)[0]))[38];
  t116 = ((f0)t115)((cint)((cptr)powset_os)[7] /* elemtype*/); /* Eval*/
  t118 = ((cptr)(((cptr)t114)[0]))[104];
  t119 = ((f0)t118)((cint)t114, (cint)t116); /* Subset*/
      t124 = t119 == boolean_True;
      t123 = t124;
    };
    t121 = t123;
  };
  if (t121){
    object_Dec_ref(powset_self);
    object_Dec_ref(powset_ob);
    t112 = boolean_True;
    goto t112_label;
  }else{
  t125 = ((cptr)powset_ob)[5] /* representation*/ == strpool_str_49;
  if (t125){
    powset_os = powset_ob;
    ((cptr)powset_self)[1] += 1;
    ((cptr)((cptr)powset_os)[8] /* subset1*/)[1] += 1;
    t126 = ((cptr)(((cptr)powset_self)[0]))[104];
    t127 = ((f0)t126)((cint)powset_self, (cint)((cptr)powset_os)[8] /* subset1*/); /* Subset*/
    powset_result = t127;
    t129 = powset_result == boolean_False;
    if (t129){
      ((cptr)powset_self)[1] += 1;
      ((cptr)((cptr)powset_os)[9] /* subset2*/)[1] += 1;
      t130 = ((cptr)(((cptr)powset_self)[0]))[104];
      t131 = ((f0)t130)((cint)powset_self, (cint)((cptr)powset_os)[9] /* subset2*/); /* Subset*/
      powset_result = t131;
    };
    object_Dec_ref(powset_self);
    object_Dec_ref(powset_ob);
  }else{
    t133 = collection_Subset((cint)powset_self, (cint)powset_ob);
    t112 = t133;
    goto t112_label;
  };};
  t112 = powset_result;
  goto t112_label;
  t112_label: return t112;
}

void init_powset(){
  copy_meth_table(powset_methods, set_methods);
  powset_methods[0] = 32;
  powset_methods[3] = powset_alloc;
  powset_methods[4] = powset_reclaim;
  powset_methods[20] = powset_Contains;
  powset_methods[54] = powset_Intersect;
  powset_methods[62] = powset_lookup;
  powset_methods[88] = powset_Mkstr;
  powset_methods[97] = powset_Plus;
  powset_methods[104] = powset_Subset;
}
