#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 list_methods[meth_max];
extern cptr boolean_methods[meth_max];
#include "cint.h"
extern cptr strpool_methods[meth_max];
extern cptr pset_methods[meth_max];

extern cint boolean_True;
extern cint object_Undefined;
extern cint boolean_False;
extern cint strpool_str_30;
extern cint strpool_str_31;
extern cint strpool_str_13;
extern cint strpool_str_15;
extern cint strpool_str_65;
extern cint strpool_str_66;
extern cint strpool_str_49;


cptr listset_methods[meth_max];

cint listset_alloc(cint listset_self, cint listset_base_set){
  cint listset_result;
  cint t1, t2;
  t2 = set_alloc((cint)listset_self);
  listset_result = t2;
  ((cptr)listset_result)[5] /* representation*/ = strpool_str_65;
  ((cptr)listset_result)[7] /* elemtype*/ = listset_base_set;
  ((cptr)listset_result)[3] /* len*/ = -1;
  t1 = listset_result;
  goto t1_label;
  t1_label: return t1;
}

cint listset_reclaim(cint listset_self){
  cint t3;
  set_reclaim((cint)listset_self);
  t3_label: return t3;
}

cint listset_Contains(cint listset_self, cint listset_ob){
  cint listset_result, listset_et, listset_ol, listset_i, listset_elem;
  cint t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t18, t19, t20, t21, t22, t23, t24, t25, t26;
  listset_result = boolean_False;
  t5 = ((cptr)(((cptr)listset_ob)[0]))[38];
  t6 = ((f0)t5)((cint)listset_ob); /* Eval*/
  listset_ob = t6;
  ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
  t8 = ((cptr)(((cptr)((cptr)listset_self)[7] /* elemtype*/)[0]))[38];
  t9 = ((f0)t8)((cint)((cptr)listset_self)[7] /* elemtype*/); /* Eval*/
  listset_et = t9;
  t11 = ((cptr)listset_ob)[4] /* class_of*/ == strpool_str_30;
  if (t11){
    listset_ol = listset_ob;
    t12 = ((cptr)listset_ol)[3] /* len*/ > 0;
    if (t12){
      ((cptr)((cptr)listset_ol)[7] /* elemtype*/)[1] += 1;
      ((cptr)listset_et)[1] += 1;
      t13 = ((cptr)(((cptr)((cptr)listset_ol)[7] /* elemtype*/)[0]))[104];
      t14 = ((f0)t13)((cint)((cptr)listset_ol)[7] /* elemtype*/, (cint)listset_et); /* Subset*/
      listset_result = t14;
    };
    t16 = listset_result != boolean_True;
    if (t16){
      listset_result = boolean_True;
      for (listset_i = 1; listset_i <= ((cptr)listset_ol)[3] /* len*/; listset_i++){
        t18 = ((cptr)(((cptr)listset_ol)[0]))[62];
        t19 = ((f0)t18)((cint)listset_ol, (cint)listset_i); /* lookup*/
        listset_elem = t19;
        t21 = listset_elem != object_Undefined;
        if (t21){
          ((cptr)listset_et)[1] += 1;
          ((cptr)listset_elem)[1] += 1;
          t22 = ((cptr)(((cptr)listset_et)[0]))[20];
          t23 = ((f0)t22)((cint)listset_et, (cint)listset_elem); /* Contains*/
          listset_result = t23;
        };
        t25 = listset_result == boolean_False;
        if (t25){
          goto t17;
        };
      };t17:;
      t26 = listset_result == boolean_True;
      if (t26){
        object_Dec_ref(((cptr)listset_ol)[7] /* elemtype*/);
        ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
        ((cptr)listset_ol)[7] /* elemtype*/ = ((cptr)listset_self)[7] /* elemtype*/;
      };
    };
  };
  object_Dec_ref(listset_self);
  object_Dec_ref(listset_ob);
  object_Dec_ref(listset_et);
  t4 = listset_result;
  goto t4_label;
  t4_label: return t4;
}

cint listset_Intersect(cint listset_self, cint listset_ob){
  cint listset_result, listset_os, listset_et;
  cint t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51;
  t30 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_31;
  t31 = t30;
  if (!t31){  ((cptr)listset_self)[1] += 1;
  ((cptr)listset_ob)[1] += 1;
  t28 = ((cptr)(((cptr)listset_self)[0]))[104];
  t29 = ((f0)t28)((cint)listset_self, (cint)listset_ob); /* Subset*/
    t32 = t29 == boolean_True;
    t31 = t32;
  };
  if (t31){
    object_Dec_ref(listset_ob);
    t27 = listset_self;
    goto t27_label;
  }else{
  ((cptr)listset_ob)[1] += 1;
  ((cptr)listset_self)[1] += 1;
  t33 = ((cptr)(((cptr)listset_ob)[0]))[104];
  t34 = ((f0)t33)((cint)listset_ob, (cint)listset_self); /* Subset*/
  t35 = t34 == boolean_True;
  if (t35){
    object_Dec_ref(listset_self);
    t27 = listset_ob;
    goto t27_label;
  }else{
  t36 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_65;
  if (t36){
    listset_os = listset_ob;
    ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
    t37 = ((cptr)(((cptr)((cptr)listset_self)[7] /* elemtype*/)[0]))[38];
    t38 = ((f0)t37)((cint)((cptr)listset_self)[7] /* elemtype*/); /* Eval*/
    ((cptr)((cptr)listset_os)[7] /* elemtype*/)[1] += 1;
    t39 = ((cptr)(((cptr)((cptr)listset_os)[7] /* elemtype*/)[0]))[38];
    t40 = ((f0)t39)((cint)((cptr)listset_os)[7] /* elemtype*/); /* Eval*/
    t42 = ((cptr)(((cptr)t38)[0]))[54];
    t43 = ((f0)t42)((cint)t38, (cint)t40); /* Intersect*/
    listset_et = t43;
    object_Dec_ref(listset_self);
    object_Dec_ref(listset_ob);
    t46 = listset_et == object_Undefined;
    t47 = t46;
    if (!t47){      t48 = ((cptr)listset_et)[3] /* len*/ == 0;
      t47 = t48;
    };
    if (t47){
      t27 = listset_et;
      goto t27_label;
    };
    t49 = mem_malloc(32); ((cptr)t49)[0] = listset_methods;
    t50 = listset_alloc((cint)t49, (cint)listset_et);
    t27 = t50;
    goto t27_label;
  }else{
    t51 = set_Intersect((cint)listset_self, (cint)listset_ob);
    t27 = t51;
    goto t27_label;
  };};};
  t27 = listset_result;
  goto t27_label;
  t27_label: return t27;
}

cint listset_Minus(cint listset_self, cint listset_ob){
  cint listset_result, listset_os;
  cint t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62;
  listset_os = listset_ob;
  t55 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_31;
  t56 = t55;
  if (!t56){    t57 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_65;
    t58 = t57;
    if (t58){
  ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
  ((cptr)((cptr)listset_os)[7] /* elemtype*/)[1] += 1;
  t53 = ((cptr)(((cptr)((cptr)listset_self)[7] /* elemtype*/)[0]))[104];
  t54 = ((f0)t53)((cint)((cptr)listset_self)[7] /* elemtype*/, (cint)((cptr)listset_os)[7] /* elemtype*/); /* Subset*/
      t59 = t54 == boolean_True;
      t58 = t59;
    };
    t56 = t58;
  };
  if (t56){
    object_Dec_ref(listset_self);
    object_Dec_ref(listset_ob);
    t60 = mem_malloc(48); ((cptr)t60)[0] = sset_methods;
    t61 = sset_alloc((cint)t60);
    t52 = t61;
    goto t52_label;
  }else{
    t62 = set_Minus((cint)listset_self, (cint)listset_ob);
    t52 = t62;
    goto t52_label;
  };
  t52 = listset_result;
  goto t52_label;
  t52_label: return t52;
}

cint listset_Mkstr(cint listset_self){
  cint listset_result;
  cint t63, t64, t65, t66, t67, t68, t69, t70, t71, t72, t73, t74, t75, t76, t77, t78;
  ((cptr)strpool_str_13)[1] += 1;
  ((cptr)strpool_str_66)[1] += 1;
  t64 = ((cptr)(((cptr)strpool_str_13)[0]))[97];
  t65 = ((f0)t64)((cint)strpool_str_13, (cint)strpool_str_66); /* Plus*/
  ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
  t66 = ((cptr)(((cptr)((cptr)listset_self)[7] /* elemtype*/)[0]))[38];
  t67 = ((f0)t66)((cint)((cptr)listset_self)[7] /* elemtype*/); /* Eval*/
  t69 = ((cptr)(((cptr)t67)[0]))[88];
  t70 = ((f0)t69)((cint)t67); /* Mkstr*/
  t72 = ((cptr)(((cptr)t65)[0]))[97];
  t73 = ((f0)t72)((cint)t65, (cint)t70); /* Plus*/
  ((cptr)strpool_str_15)[1] += 1;
  t76 = ((cptr)(((cptr)t73)[0]))[97];
  t77 = ((f0)t76)((cint)t73, (cint)strpool_str_15); /* Plus*/
  listset_result = t77;
  object_Dec_ref(listset_self);
  t63 = listset_result;
  goto t63_label;
  t63_label: return t63;
}

cint listset_Plus(cint listset_self, cint listset_ob){
  cint listset_result, listset_os;
  cint t79, t80, t81, t82, t83, t84, t85, t86, t87, t88, t89, t90, t91;
  listset_os = listset_ob;
  t80 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_31;
  if (t80){
    object_Dec_ref(listset_self);
    t79 = listset_ob;
    goto t79_label;
  }else{
  t83 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_65;
  t84 = t83;
  if (t84){
  ((cptr)((cptr)listset_os)[7] /* elemtype*/)[1] += 1;
  ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
  t81 = ((cptr)(((cptr)((cptr)listset_os)[7] /* elemtype*/)[0]))[104];
  t82 = ((f0)t81)((cint)((cptr)listset_os)[7] /* elemtype*/, (cint)((cptr)listset_self)[7] /* elemtype*/); /* Subset*/
    t85 = t82 == boolean_True;
    t84 = t85;
  };
  if (t84){
    object_Dec_ref(listset_ob);
    t79 = listset_self;
    goto t79_label;
  }else{
  t88 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_65;
  t89 = t88;
  if (t89){
  ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
  ((cptr)((cptr)listset_os)[7] /* elemtype*/)[1] += 1;
  t86 = ((cptr)(((cptr)((cptr)listset_self)[7] /* elemtype*/)[0]))[104];
  t87 = ((f0)t86)((cint)((cptr)listset_self)[7] /* elemtype*/, (cint)((cptr)listset_os)[7] /* elemtype*/); /* Subset*/
    t90 = t87 == boolean_True;
    t89 = t90;
  };
  if (t89){
    object_Dec_ref(listset_self);
    t79 = listset_ob;
    goto t79_label;
  }else{
    t91 = set_Plus((cint)listset_self, (cint)listset_ob);
    t79 = t91;
    goto t79_label;
  };};};
  t79 = listset_result;
  goto t79_label;
  t79_label: return t79;
}

cint listset_Subset(cint listset_self, cint listset_ob){
  cint listset_result, listset_os;
  cint t92, t93, t94, t95, t96, t97, t98, t99, t100, t101, t102, t103, t104, t105, t106, t107, t108;
  listset_os = listset_ob;
  t95 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_31;
  t96 = t95;
  if (!t96){    t97 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_65;
    t98 = t97;
    if (t98){
  ((cptr)((cptr)listset_self)[7] /* elemtype*/)[1] += 1;
  ((cptr)((cptr)listset_os)[7] /* elemtype*/)[1] += 1;
  t93 = ((cptr)(((cptr)((cptr)listset_self)[7] /* elemtype*/)[0]))[104];
  t94 = ((f0)t93)((cint)((cptr)listset_self)[7] /* elemtype*/, (cint)((cptr)listset_os)[7] /* elemtype*/); /* Subset*/
      t99 = t94 == boolean_True;
      t98 = t99;
    };
    t96 = t98;
  };
  if (t96){
    object_Dec_ref(listset_self);
    object_Dec_ref(listset_ob);
    t92 = boolean_True;
    goto t92_label;
  }else{
  t100 = ((cptr)listset_ob)[5] /* representation*/ == strpool_str_49;
  if (t100){
    listset_os = listset_ob;
    ((cptr)listset_self)[1] += 1;
    ((cptr)((cptr)listset_os)[8] /* subset1*/)[1] += 1;
    t101 = ((cptr)(((cptr)listset_self)[0]))[104];
    t102 = ((f0)t101)((cint)listset_self, (cint)((cptr)listset_os)[8] /* subset1*/); /* Subset*/
    listset_result = t102;
    t104 = listset_result == boolean_False;
    if (t104){
      ((cptr)listset_self)[1] += 1;
      ((cptr)((cptr)listset_os)[9] /* subset2*/)[1] += 1;
      t105 = ((cptr)(((cptr)listset_self)[0]))[104];
      t106 = ((f0)t105)((cint)listset_self, (cint)((cptr)listset_os)[9] /* subset2*/); /* Subset*/
      listset_result = t106;
    };
    object_Dec_ref(listset_self);
    object_Dec_ref(listset_ob);
  }else{
    t108 = collection_Subset((cint)listset_self, (cint)listset_ob);
    t92 = t108;
    goto t92_label;
  };};
  t92 = listset_result;
  goto t92_label;
  t92_label: return t92;
}

void init_listset(){
  copy_meth_table(listset_methods, set_methods);
  listset_methods[0] = 32;
  listset_methods[3] = listset_alloc;
  listset_methods[4] = listset_reclaim;
  listset_methods[20] = listset_Contains;
  listset_methods[54] = listset_Intersect;
  listset_methods[83] = listset_Minus;
  listset_methods[88] = listset_Mkstr;
  listset_methods[97] = listset_Plus;
  listset_methods[104] = listset_Subset;
}
