#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr list_methods[meth_max];
extern cptr string_methods[meth_max];
extern cptr boolean_methods[meth_max];
extern cptr strpool_methods[meth_max];

extern cint object_Undefined;
extern cint boolean_False;
extern cint strpool_str_30;
extern cint strpool_str_12;
extern cint strpool_str_42;
extern cint strpool_str_33;


cptr plist_methods[meth_max];

cint plist_alloc(cint plist_self, cint plist_lst1, cint plist_lst2){
  cint plist_result;
  cint t1, t2, t3, t4;
  t2 = list_alloc((cint)plist_self);
  plist_result = t2;
  ((cptr)plist_self)[5] /* representation*/ = strpool_str_42;
  t3 = ((cptr)plist_lst1)[2] /* hashval*/ + ((cptr)plist_lst2)[2] /* hashval*/;
  ((cptr)plist_self)[2] /* hashval*/ = t3;
  t4 = ((cptr)plist_lst1)[3] /* len*/ + ((cptr)plist_lst2)[3] /* len*/;
  ((cptr)plist_self)[3] /* len*/ = t4;
  ((cptr)plist_self)[8] /* sublst1*/ = plist_lst1;
  ((cptr)plist_self)[9] /* sublst2*/ = plist_lst2;
  t1 = plist_result;
  goto t1_label;
  t1_label: return t1;
}

cint plist_reclaim(cint plist_self){
  cint t5;
  object_Dec_ref(((cptr)plist_self)[8] /* sublst1*/);
  object_Dec_ref(((cptr)plist_self)[9] /* sublst2*/);
  list_reclaim((cint)plist_self);
  t5_label: return t5;
}

cint plist_All_but_last(cint plist_self){
  cint plist_result, plist_r;
  cint t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18;
  t7 = ((cptr)((cptr)plist_self)[8] /* sublst1*/)[3] /* len*/ + 1;
  t8 = ((cptr)plist_self)[3] /* len*/ == t7;
  if (t8){
    ((cptr)((cptr)plist_self)[8] /* sublst1*/)[1] += 1;
    plist_result = ((cptr)plist_self)[8] /* sublst1*/;
    object_Dec_ref(plist_self);
  }else{
    t9 = ((cptr)(((cptr)plist_self)[0]))[21];
    t10 = ((f0)t9)((cint)plist_self); /* copy_of*/
    plist_r = t10;
    t12 = ((cptr)(((cptr)plist_r)[0]))[62];
    t13 = ((f0)t12)((cint)plist_r, (cint)((cptr)plist_r)[3] /* len*/); /* lookup*/
    t14 = ((cptr)plist_r)[2] /* hashval*/ - ((cptr)t13)[2] /* hashval*/;
    ((cptr)plist_r)[2] /* hashval*/ = t14;
    t15 = ((cptr)plist_r)[3] /* len*/ - 1;
    ((cptr)plist_r)[3] /* len*/ = t15;
    t16 = ((cptr)(((cptr)((cptr)plist_r)[9] /* sublst2*/)[0]))[6];
    t17 = ((f0)t16)((cint)((cptr)plist_r)[9] /* sublst2*/); /* All_but_last*/
    ((cptr)plist_r)[9] /* sublst2*/ = t17;
    t6 = plist_r;
    goto t6_label;
  };
  t6 = plist_result;
  goto t6_label;
  t6_label: return t6;
}

cint plist_Append(cint plist_self, cint plist_item){
  cint plist_result;
  cint t19, t20, t21, t22, t23, t24, t25, t26, t27;
  t20 = ((cptr)(((cptr)plist_self)[0]))[21];
  t21 = ((f0)t20)((cint)plist_self); /* copy_of*/
  plist_result = t21;
  t23 = ((cptr)(((cptr)((cptr)plist_result)[9] /* sublst2*/)[0]))[7];
  t24 = ((f0)t23)((cint)((cptr)plist_result)[9] /* sublst2*/, (cint)plist_item); /* Append*/
  ((cptr)plist_result)[9] /* sublst2*/ = t24;
  t26 = ((cptr)plist_result)[3] /* len*/ + 1;
  ((cptr)plist_result)[3] /* len*/ = t26;
  t27 = ((cptr)plist_result)[2] /* hashval*/ + ((cptr)plist_item)[2] /* hashval*/;
  ((cptr)plist_result)[2] /* hashval*/ = t27;
  t19 = plist_result;
  goto t19_label;
  t19_label: return t19;
}

cint plist_Contains(cint plist_self, cint plist_ob){
  cint plist_result;
  cint t28, t29, t30, t31, t32, t33, t34, t35;
  ((cptr)((cptr)plist_self)[8] /* sublst1*/)[1] += 1;
  ((cptr)plist_ob)[1] += 1;
  t29 = ((cptr)(((cptr)((cptr)plist_self)[8] /* sublst1*/)[0]))[20];
  t30 = ((f0)t29)((cint)((cptr)plist_self)[8] /* sublst1*/, (cint)plist_ob); /* Contains*/
  plist_result = t30;
  t32 = plist_result == boolean_False;
  if (t32){
    ((cptr)((cptr)plist_self)[9] /* sublst2*/)[1] += 1;
    ((cptr)plist_ob)[1] += 1;
    t33 = ((cptr)(((cptr)((cptr)plist_self)[9] /* sublst2*/)[0]))[20];
    t34 = ((f0)t33)((cint)((cptr)plist_self)[9] /* sublst2*/, (cint)plist_ob); /* Contains*/
    plist_result = t34;
  };
  object_Dec_ref(plist_self);
  object_Dec_ref(plist_ob);
  t28 = plist_result;
  goto t28_label;
  t28_label: return t28;
}

cint plist_copy_of(cint plist_self){
  cint plist_result;
  cint t36, t37, t38, t39;
  t37 = ((cptr)plist_self)[1] /* refcount*/ == 1;
  if (t37){
    t36 = plist_self;
    goto t36_label;
  };
  object_Dec_ref(plist_self);
  t38 = mem_malloc(40); ((cptr)t38)[0] = plist_methods;
  ((cptr)((cptr)plist_self)[8] /* sublst1*/)[1] += 1;
  ((cptr)((cptr)plist_self)[9] /* sublst2*/)[1] += 1;
  t39 = plist_alloc((cint)t38, (cint)((cptr)plist_self)[8] /* sublst1*/, (cint)((cptr)plist_self)[9] /* sublst2*/);
  t36 = t39;
  goto t36_label;
  t36_label: return t36;
}

cint plist_Delete_ith(cint plist_self, cint plist_i){
  cint plist_result, plist_j;
  cint t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53;
  t41 = plist_i - ((cptr)((cptr)plist_self)[8] /* sublst1*/)[3] /* len*/;
  plist_j = t41;
  t42 = ((cptr)(((cptr)plist_self)[0]))[21];
  t43 = ((f0)t42)((cint)plist_self); /* copy_of*/
  plist_result = t43;
  t45 = plist_j <= 0;
  if (t45){
    t46 = ((cptr)(((cptr)((cptr)plist_result)[8] /* sublst1*/)[0]))[29];
    t47 = ((f0)t46)((cint)((cptr)plist_result)[8] /* sublst1*/, (cint)plist_i); /* Delete_ith*/
    ((cptr)plist_result)[8] /* sublst1*/ = t47;
  }else{
    t49 = ((cptr)(((cptr)((cptr)plist_result)[9] /* sublst2*/)[0]))[29];
    t50 = ((f0)t49)((cint)((cptr)plist_result)[9] /* sublst2*/, (cint)plist_j); /* Delete_ith*/
    ((cptr)plist_result)[9] /* sublst2*/ = t50;
  };
  t52 = ((cptr)((cptr)plist_result)[8] /* sublst1*/)[2] /* hashval*/ + ((cptr)((cptr)plist_result)[9] /* sublst2*/)[2] /* hashval*/;
  ((cptr)plist_result)[2] /* hashval*/ = t52;
  t53 = ((cptr)plist_result)[3] /* len*/ - 1;
  ((cptr)plist_result)[3] /* len*/ = t53;
  t40 = plist_result;
  goto t40_label;
  t40_label: return t40;
}

cint plist_lookup(cint plist_self, cint plist_i){
  cint plist_result, plist_j;
  cint t54, t55, t56, t57, t58, t59, t60, t61, t62;
  t55 = plist_i - ((cptr)((cptr)plist_self)[8] /* sublst1*/)[3] /* len*/;
  plist_j = t55;
  t56 = plist_j <= 0;
  if (t56){
    t57 = ((cptr)(((cptr)((cptr)plist_self)[8] /* sublst1*/)[0]))[62];
    t58 = ((f0)t57)((cint)((cptr)plist_self)[8] /* sublst1*/, (cint)plist_i); /* lookup*/
    t54 = t58;
    goto t54_label;
  };
  t60 = ((cptr)(((cptr)((cptr)plist_self)[9] /* sublst2*/)[0]))[62];
  t61 = ((f0)t60)((cint)((cptr)plist_self)[9] /* sublst2*/, (cint)plist_j); /* lookup*/
  t54 = t61;
  goto t54_label;
  t54_label: return t54;
}

cint plist_Plus(cint plist_self, cint plist_ob){
  cint plist_result;
  cint t63, t64, t65, t66, t67, t68, t69, t70, t71, t72;
  t64 = ((cptr)plist_ob)[4] /* class_of*/ != strpool_str_30;
  if (t64){
    object_Dec_ref(plist_self);
    object_Dec_ref(plist_ob);
    t63 = object_Undefined;
    goto t63_label;
  };
  t65 = ((cptr)(((cptr)plist_self)[0]))[21];
  t66 = ((f0)t65)((cint)plist_self); /* copy_of*/
  plist_result = t66;
  t68 = ((cptr)plist_result)[3] /* len*/ + ((cptr)plist_ob)[3] /* len*/;
  ((cptr)plist_result)[3] /* len*/ = t68;
  t69 = ((cptr)plist_result)[2] /* hashval*/ + ((cptr)plist_ob)[2] /* hashval*/;
  ((cptr)plist_result)[2] /* hashval*/ = t69;
  t70 = ((cptr)(((cptr)((cptr)plist_result)[9] /* sublst2*/)[0]))[97];
  t71 = ((f0)t70)((cint)((cptr)plist_result)[9] /* sublst2*/, (cint)plist_ob); /* Plus*/
  ((cptr)plist_result)[9] /* sublst2*/ = t71;
  t63 = plist_result;
  goto t63_label;
  t63_label: return t63;
}

cint plist_ubstr(cint plist_self){
  cint plist_result;
  cint t73, t74, t75, t76, t77, t78, t79, t80, t81, t82, t83, t84, t85, t86, t87, t88, t89, t90, t91, t92, t93, t94;
  t74 = ((cptr)plist_self)[3] /* len*/ == 0;
  if (t74){
    ((cptr)strpool_str_33)[1] += 1;
    t73 = strpool_str_33;
    goto t73_label;
  };
  t75 = ((cptr)((cptr)plist_self)[9] /* sublst2*/)[3] /* len*/ == 0;
  if (t75){
    t76 = ((cptr)(((cptr)((cptr)plist_self)[8] /* sublst1*/)[0]))[112];
    t77 = ((f0)t76)((cint)((cptr)plist_self)[8] /* sublst1*/); /* ubstr*/
    t73 = t77;
    goto t73_label;
  };
  t79 = ((cptr)((cptr)plist_self)[8] /* sublst1*/)[3] /* len*/ == 0;
  if (t79){
    t80 = ((cptr)(((cptr)((cptr)plist_self)[9] /* sublst2*/)[0]))[112];
    t81 = ((f0)t80)((cint)((cptr)plist_self)[9] /* sublst2*/); /* ubstr*/
    t73 = t81;
    goto t73_label;
  };
  t83 = ((cptr)(((cptr)((cptr)plist_self)[8] /* sublst1*/)[0]))[112];
  t84 = ((f0)t83)((cint)((cptr)plist_self)[8] /* sublst1*/); /* ubstr*/
  ((cptr)strpool_str_12)[1] += 1;
  t86 = ((cptr)(((cptr)t84)[0]))[97];
  t87 = ((f0)t86)((cint)t84, (cint)strpool_str_12); /* Plus*/
  t88 = ((cptr)(((cptr)((cptr)plist_self)[9] /* sublst2*/)[0]))[112];
  t89 = ((f0)t88)((cint)((cptr)plist_self)[9] /* sublst2*/); /* ubstr*/
  t91 = ((cptr)(((cptr)t87)[0]))[97];
  t92 = ((f0)t91)((cint)t87, (cint)t89); /* Plus*/
  t73 = t92;
  goto t73_label;
  t73_label: return t73;
}

cint plist_update(cint plist_self, cint plist_i, cint plist_ob, cint plist_op){
  cint plist_result, plist_j;
  cint t95, t96, t97, t98, t99, t100, t101, t102, t103, t104, t105, t106, t107, t108;
  t96 = plist_i - ((cptr)((cptr)plist_self)[8] /* sublst1*/)[3] /* len*/;
  plist_j = t96;
  t97 = ((cptr)(((cptr)plist_self)[0]))[21];
  t98 = ((f0)t97)((cint)plist_self); /* copy_of*/
  plist_result = t98;
  t100 = plist_j <= 0;
  if (t100){
    t101 = ((cptr)(((cptr)((cptr)plist_result)[8] /* sublst1*/)[0]))[130];
    t102 = ((f0)t101)((cint)((cptr)plist_result)[8] /* sublst1*/, (cint)plist_i, (cint)plist_ob, (cint)plist_op); /* update*/
    ((cptr)plist_result)[8] /* sublst1*/ = t102;
  }else{
    t104 = ((cptr)(((cptr)((cptr)plist_result)[9] /* sublst2*/)[0]))[130];
    t105 = ((f0)t104)((cint)((cptr)plist_result)[9] /* sublst2*/, (cint)plist_j, (cint)plist_ob, (cint)plist_op); /* update*/
    ((cptr)plist_result)[9] /* sublst2*/ = t105;
  };
  t107 = ((cptr)((cptr)plist_result)[8] /* sublst1*/)[2] /* hashval*/ + ((cptr)((cptr)plist_result)[9] /* sublst2*/)[2] /* hashval*/;
  ((cptr)plist_result)[2] /* hashval*/ = t107;
  t108 = ((cptr)((cptr)plist_result)[8] /* sublst1*/)[3] /* len*/ + ((cptr)((cptr)plist_result)[9] /* sublst2*/)[3] /* len*/;
  ((cptr)plist_result)[3] /* len*/ = t108;
  t95 = plist_result;
  goto t95_label;
  t95_label: return t95;
}

void init_plist(){
  copy_meth_table(plist_methods, list_methods);
  plist_methods[0] = 40;
  plist_methods[3] = plist_alloc;
  plist_methods[4] = plist_reclaim;
  plist_methods[6] = plist_All_but_last;
  plist_methods[7] = plist_Append;
  plist_methods[20] = plist_Contains;
  plist_methods[21] = plist_copy_of;
  plist_methods[29] = plist_Delete_ith;
  plist_methods[62] = plist_lookup;
  plist_methods[97] = plist_Plus;
  plist_methods[112] = plist_ubstr;
  plist_methods[130] = plist_update;
}
