#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr collection_methods[meth_max];
extern cptr integer_methods[meth_max];
extern cptr character_methods[meth_max];
extern cptr set_methods[meth_max];
extern cptr sset_methods[meth_max];
extern cptr boolean_methods[meth_max];
#include "cint.h"
extern cptr intset_methods[meth_max];
extern cptr charset_methods[meth_max];
extern cptr strpool_methods[meth_max];
extern cptr rset_methods[meth_max];
#include "cstring.h"

extern cint strpool_str_5;
extern cint strpool_str_6;
extern cint boolean_True;
extern cint object_Undefined;
extern cint boolean_False;
extern cint intset_predef;
extern cint charset_predef;
extern cint strpool_str_44;
extern cint strpool_str_48;
extern cint strpool_str_58;


cptr srset_methods[meth_max];

cint srset_alloc(cint srset_self, cint srset_rstart, cint srset_rend, cint srset_incr){
  cint srset_result, srset_i, srset_j;
  cint t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t36, t37, t38, t39, t40, t41, t42, t43, t44, t47, t48, t49, t50, t51, t52, t53;
  t2 = set_alloc((cint)srset_self);
  srset_result = t2;
  t3 = ((cptr)srset_incr)[4] /* class_of*/ == strpool_str_5;
  t4 = t3;
  if (t4){
    t5 = ((cptr)srset_incr)[2] /* hashval*/ == 1;
    t6 = t5;
    if (!t6){      t7 = ((cptr)srset_incr)[2] /* hashval*/ == -1;
      t6 = t7;
    };
    t4 = t6;
  };
  if (t4){
    cstring_mem_free((cint)srset_self);
    object_Dec_ref(srset_incr);
    t8 = ((cptr)srset_rend)[2] /* hashval*/ < ((cptr)srset_rstart)[2] /* hashval*/;
    if (t8){
      t9 = mem_malloc(44); ((cptr)t9)[0] = rset_methods;
      t10 = rset_alloc((cint)t9, (cint)srset_rend, (cint)srset_rstart);
      t1 = t10;
      goto t1_label;
    };
    t11 = mem_malloc(44); ((cptr)t11)[0] = rset_methods;
    t12 = rset_alloc((cint)t11, (cint)srset_rstart, (cint)srset_rend);
    t1 = t12;
    goto t1_label;
  };
  t13 = ((cptr)srset_rstart)[4] /* class_of*/ == strpool_str_5;
  t14 = t13;
  if (t14){
    t15 = ((cptr)srset_rend)[4] /* class_of*/ == strpool_str_5;
    t14 = t15;
  };
  t16 = t14;
  if (t16){
    t17 = ((cptr)srset_incr)[4] /* class_of*/ == strpool_str_5;
    t16 = t17;
  };
  if (t16){
    ((cptr)intset_predef)[1] += 1;
    ((cptr)srset_self)[7] /* elemtype*/ = intset_predef;
    t18 = mem_malloc(28); ((cptr)t18)[0] = integer_methods;
    t19 = integer_ialloc((cint)t18, (cint)0);
    ((cptr)srset_self)[8] /* elem*/ = t19;
  }else{
  t20 = ((cptr)srset_rstart)[4] /* class_of*/ == strpool_str_6;
  t21 = t20;
  if (t21){
    t22 = ((cptr)srset_rstart)[3] /* len*/ == 1;
    t21 = t22;
  };
  t23 = t21;
  if (t23){
    t24 = ((cptr)srset_rend)[4] /* class_of*/ == strpool_str_6;
    t23 = t24;
  };
  t25 = t23;
  if (t25){
    t26 = ((cptr)srset_rend)[3] /* len*/ == 1;
    t25 = t26;
  };
  t27 = t25;
  if (t27){
    t28 = ((cptr)srset_incr)[4] /* class_of*/ == strpool_str_5;
    t27 = t28;
  };
  if (t27){
    ((cptr)charset_predef)[1] += 1;
    ((cptr)srset_self)[7] /* elemtype*/ = charset_predef;
    t29 = mem_malloc(36); ((cptr)t29)[0] = character_methods;
    t30 = character_alloc((cint)t29, (cint)0, (cint)0);
    ((cptr)srset_self)[8] /* elem*/ = t30;
  }else{
    object_Dec_ref(srset_rstart);
    object_Dec_ref(srset_rend);
    set_reclaim((cint)srset_self);
    t1 = object_Undefined;
    goto t1_label;
  };};
  ((cptr)srset_self)[5] /* representation*/ = strpool_str_58;
  ((cptr)srset_self)[9] /* r_start*/ = srset_rstart;
  ((cptr)srset_self)[10] /* r_end*/ = srset_rend;
  ((cptr)srset_self)[11] /* r_incr*/ = srset_incr;
  srset_i = ((cptr)srset_rstart)[2] /* hashval*/;
  ((cptr)srset_self)[3] /* len*/ = 0;
  ((cptr)srset_self)[2] /* hashval*/ = 0;
  t31 = ((cptr)srset_rstart)[2] /* hashval*/ < ((cptr)srset_rend)[2] /* hashval*/;
  t32 = t31;
  if (t32){
    t33 = ((cptr)srset_incr)[2] /* hashval*/ > 0;
    t32 = t33;
  };
  if (t32){
    t34:
    t36 = srset_i <= ((cptr)srset_rend)[2] /* hashval*/;
    if (!t36) goto t35;
      t37 = ((cptr)srset_self)[3] /* len*/ + 1;
      ((cptr)srset_self)[3] /* len*/ = t37;
      t38 = ((cptr)srset_self)[2] /* hashval*/ + srset_i;
      ((cptr)srset_self)[2] /* hashval*/ = t38;
      t39 = srset_i + ((cptr)srset_incr)[2] /* hashval*/;
      srset_j = t39;
      t40 = srset_j < srset_i;
      if (t40){
        goto t35;
      };
      srset_i = srset_j;
    goto t34;
    t35:;
    t41 = ((cptr)srset_self)[3] /* len*/ <= 0;
    if (t41){
      ((cptr)srset_self)[3] /* len*/ = -1;
    };
  }else{
  t42 = ((cptr)srset_rstart)[2] /* hashval*/ > ((cptr)srset_rend)[2] /* hashval*/;
  t43 = t42;
  if (t43){
    t44 = ((cptr)srset_incr)[2] /* hashval*/ < 0;
    t43 = t44;
  };
  if (t43){
    t45:
    t47 = srset_i >= ((cptr)srset_rend)[2] /* hashval*/;
    if (!t47) goto t46;
      t48 = ((cptr)srset_self)[3] /* len*/ + 1;
      ((cptr)srset_self)[3] /* len*/ = t48;
      t49 = ((cptr)srset_self)[2] /* hashval*/ + srset_i;
      ((cptr)srset_self)[2] /* hashval*/ = t49;
      t50 = srset_i + ((cptr)srset_incr)[2] /* hashval*/;
      srset_j = t50;
      t51 = srset_j > srset_i;
      if (t51){
        goto t46;
      };
      srset_i = srset_j;
    goto t45;
    t46:;
    t52 = ((cptr)srset_self)[3] /* len*/ <= 0;
    if (t52){
      ((cptr)srset_self)[3] /* len*/ = -1;
    };
  }else{
  t53 = ((cptr)srset_rstart)[2] /* hashval*/ == ((cptr)srset_rend)[2] /* hashval*/;
  if (t53){
    ((cptr)srset_self)[3] /* len*/ = 1;
    ((cptr)srset_self)[2] /* hashval*/ = ((cptr)srset_rstart)[2] /* hashval*/;
  };};};
  t1 = srset_result;
  goto t1_label;
  t1_label: return t1;
}

cint srset_reclaim(cint srset_self){
  cint t54;
  object_Dec_ref(((cptr)srset_self)[9] /* r_start*/);
  object_Dec_ref(((cptr)srset_self)[10] /* r_end*/);
  object_Dec_ref(((cptr)srset_self)[11] /* r_incr*/);
  object_Dec_ref(((cptr)srset_self)[8] /* elem*/);
  set_reclaim((cint)srset_self);
  t54_label: return t54;
}

cint srset_Contains(cint srset_self, cint srset_ob){
  cint srset_result;
  cint t55, t56, t57, t58, t59, t60, t61, t62, t63;
  t56 = ((cptr)srset_ob)[4] /* class_of*/ != ((cptr)((cptr)srset_self)[9] /* r_start*/)[4] /* class_of*/;
  if (t56){
    object_Dec_ref(srset_self);
    object_Dec_ref(srset_ob);
    t55 = boolean_False;
    goto t55_label;
  };
  t57 = ((cptr)((cptr)srset_self)[9] /* r_start*/)[2] /* hashval*/ <= ((cptr)((cptr)srset_self)[10] /* r_end*/)[2] /* hashval*/;
  if (t57){
    t58 = ((cptr)(((cptr)srset_self)[0]))[192];
    t59 = ((f0)t58)((cint)srset_self, (cint)srset_ob, (cint)((cptr)srset_self)[9] /* r_start*/, (cint)((cptr)srset_self)[10] /* r_end*/, (cint)((cptr)srset_self)[11] /* r_incr*/); /* Contained_in*/
    t55 = t59;
    goto t55_label;
  };
  t61 = ((cptr)(((cptr)srset_self)[0]))[192];
  t62 = ((f0)t61)((cint)srset_self, (cint)srset_ob, (cint)((cptr)srset_self)[10] /* r_end*/, (cint)((cptr)srset_self)[9] /* r_start*/, (cint)((cptr)srset_self)[11] /* r_incr*/); /* Contained_in*/
  t55 = t62;
  goto t55_label;
  t55_label: return t55;
}

cint srset_Contained_in(cint srset_self, cint srset_ob, cint srset_s, cint srset_e, cint srset_i){
  cint srset_result;
  cint t64, t65, t66, t67, t68;
  srset_result = boolean_True;
  t65 = ((cptr)srset_ob)[2] /* hashval*/ < ((cptr)srset_s)[2] /* hashval*/;
  if (t65){
    srset_result = boolean_False;
  };
  t66 = ((cptr)srset_ob)[2] /* hashval*/ > ((cptr)srset_e)[2] /* hashval*/;
  if (t66){
    srset_result = boolean_False;
  };
  t67 = ((cptr)srset_ob)[2] /* hashval*/ - ((cptr)srset_s)[2] /* hashval*/;
  t68 = cint_mod((cint)t67, (cint)((cptr)srset_i)[2] /* hashval*/) != 0;
  if (t68){
    srset_result = boolean_False;
  };
  object_Dec_ref(srset_self);
  object_Dec_ref(srset_ob);
  t64 = srset_result;
  goto t64_label;
  t64_label: return t64;
}

cint srset_lookup(cint srset_self, cint srset_i){
  cint srset_result, srset_j;
  cint t69, t70, t71, t72, t73, t74, t75, t76, t77, t78;
  t70 = srset_i < 1;
  t71 = t70;
  if (!t71){    t72 = srset_i > ((cptr)srset_self)[3] /* len*/;
    t71 = t72;
  };
  if (t71){
    t69 = object_Undefined;
    goto t69_label;
  };
  t73 = srset_i - 1;
  t74 = t73 * ((cptr)((cptr)srset_self)[11] /* r_incr*/)[2] /* hashval*/;
  srset_j = t74;
  t75 = ((cptr)((cptr)srset_self)[9] /* r_start*/)[2] /* hashval*/ + srset_j;
  t76 = ((cptr)(((cptr)((cptr)srset_self)[8] /* elem*/)[0]))[109];
  t77 = ((f0)t76)((cint)((cptr)srset_self)[8] /* elem*/, (cint)t75); /* update_hashval*/
  srset_result = t77;
  ((cptr)srset_self)[8] /* elem*/ = srset_result;
  t69 = srset_result;
  goto t69_label;
  t69_label: return t69;
}

cint srset_Max(cint srset_self, cint srset_ob){
  cint srset_result;
  cint t79, t80, t81, t82, t83, t84, t85;
  t80 = srset_ob != object_Undefined;
  if (t80){
    t81 = collection_Max((cint)srset_self, (cint)srset_ob);
    t79 = t81;
    goto t79_label;
  };
  t82 = ((cptr)((cptr)srset_self)[9] /* r_start*/)[2] /* hashval*/ >= ((cptr)((cptr)srset_self)[10] /* r_end*/)[2] /* hashval*/;
  if (t82){
    srset_result = ((cptr)srset_self)[9] /* r_start*/;
  }else{
    t83 = ((cptr)(((cptr)srset_self)[0]))[62];
    t84 = ((f0)t83)((cint)srset_self, (cint)((cptr)srset_self)[3] /* len*/); /* lookup*/
    srset_result = t84;
  };
  object_Dec_ref(srset_self);
  object_Dec_ref(srset_ob);
  ((cptr)srset_result)[1] += 1;
  t79 = srset_result;
  goto t79_label;
  t79_label: return t79;
}

cint srset_Min(cint srset_self, cint srset_ob){
  cint srset_result;
  cint t86, t87, t88, t89, t90, t91, t92;
  t87 = srset_ob != object_Undefined;
  if (t87){
    t88 = collection_Min((cint)srset_self, (cint)srset_ob);
    t86 = t88;
    goto t86_label;
  };
  t89 = ((cptr)((cptr)srset_self)[9] /* r_start*/)[2] /* hashval*/ <= ((cptr)((cptr)srset_self)[10] /* r_end*/)[2] /* hashval*/;
  if (t89){
    srset_result = ((cptr)srset_self)[9] /* r_start*/;
  }else{
    t90 = ((cptr)(((cptr)srset_self)[0]))[62];
    t91 = ((f0)t90)((cint)srset_self, (cint)((cptr)srset_self)[3] /* len*/); /* lookup*/
    srset_result = t91;
  };
  object_Dec_ref(srset_self);
  object_Dec_ref(srset_ob);
  ((cptr)srset_result)[1] += 1;
  t86 = srset_result;
  goto t86_label;
  t86_label: return t86;
}

cint srset_ubstr(cint srset_self){
  cint srset_result;
  cint t93, t94, t95, t96, t97, t98, t99, t100, t101, t102, t103, t104, t105, t106, t107, t108, t109, t110, t111, t112, t113, t114, t115, t116;
  t94 = ((cptr)srset_self)[3] /* len*/ < 100;
  if (t94){
    t95 = collection_ubstr((cint)srset_self);
    t93 = t95;
    goto t93_label;
  };
  ((cptr)((cptr)srset_self)[9] /* r_start*/)[1] += 1;
  t96 = ((cptr)(((cptr)((cptr)srset_self)[9] /* r_start*/)[0]))[88];
  t97 = ((f0)t96)((cint)((cptr)srset_self)[9] /* r_start*/); /* Mkstr*/
  ((cptr)strpool_str_44)[1] += 1;
  t99 = ((cptr)(((cptr)t97)[0]))[97];
  t100 = ((f0)t99)((cint)t97, (cint)strpool_str_44); /* Plus*/
  ((cptr)((cptr)srset_self)[10] /* r_end*/)[1] += 1;
  t101 = ((cptr)(((cptr)((cptr)srset_self)[10] /* r_end*/)[0]))[88];
  t102 = ((f0)t101)((cint)((cptr)srset_self)[10] /* r_end*/); /* Mkstr*/
  t104 = ((cptr)(((cptr)t100)[0]))[97];
  t105 = ((f0)t104)((cint)t100, (cint)t102); /* Plus*/
  ((cptr)strpool_str_48)[1] += 1;
  t108 = ((cptr)(((cptr)t105)[0]))[97];
  t109 = ((f0)t108)((cint)t105, (cint)strpool_str_48); /* Plus*/
  ((cptr)((cptr)srset_self)[11] /* r_incr*/)[1] += 1;
  t110 = ((cptr)(((cptr)((cptr)srset_self)[11] /* r_incr*/)[0]))[88];
  t111 = ((f0)t110)((cint)((cptr)srset_self)[11] /* r_incr*/); /* Mkstr*/
  t113 = ((cptr)(((cptr)t109)[0]))[97];
  t114 = ((f0)t113)((cint)t109, (cint)t111); /* Plus*/
  t93 = t114;
  goto t93_label;
  t93_label: return t93;
}

void init_srset(){
  copy_meth_table(srset_methods, set_methods);
  srset_methods[0] = 48;
  srset_methods[3] = srset_alloc;
  srset_methods[4] = srset_reclaim;
  srset_methods[20] = srset_Contains;
  srset_methods[192] = srset_Contained_in;
  srset_methods[62] = srset_lookup;
  srset_methods[80] = srset_Max;
  srset_methods[82] = srset_Min;
  srset_methods[112] = srset_ubstr;
}
