#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr list_methods[meth_max];
extern cptr slist_methods[meth_max];
extern cptr slicelst_methods[meth_max];
extern cptr map_methods[meth_max];
extern cptr stdin_methods[meth_max];
extern cptr scope_methods[meth_max];
extern cptr identifier_methods[meth_max];
extern cptr function_methods[meth_max];
extern cptr procedure_methods[meth_max];
extern cptr strpool_methods[meth_max];
extern cptr string_methods[meth_max];
extern cptr clib_methods[meth_max];
#include "cprocess.h"
extern cptr variable_methods[meth_max];
extern cptr mapset_methods[meth_max];
extern cptr set_methods[meth_max];
extern cptr namelist_methods[meth_max];

extern cint strpool_str_6;
extern cint object_Undefined;
extern cint strpool_str_70;
extern cint strpool_str_60;
extern cint strpool_str_37;
extern cint strpool_str_81;
extern cint strpool_str_76;
extern cint strpool_str_59;
extern cint strpool_str_79;


cptr selector_methods[meth_max];

cint selector_alloc(cint selector_self, cint selector_r, cint selector_indx){
  cint selector_result, selector_id;
  cint t1, t2, t3, t4, t5, t6, t7;
  t2 = object_alloc((cint)selector_self);
  selector_result = t2;
  ((cptr)selector_self)[4] /* class_of*/ = strpool_str_76;
  ((cptr)selector_self)[7] /* root*/ = selector_r;
  t3 = mem_malloc(40); ((cptr)t3)[0] = slist_methods;
  t4 = slist_alloc((cint)t3, (cint)3);
  t5 = ((cptr)(((cptr)t4)[0]))[7];
  t6 = ((f0)t5)((cint)t4, (cint)selector_indx); /* Append*/
  ((cptr)selector_self)[8] /* indices*/ = t6;
  t1 = selector_result;
  goto t1_label;
  t1_label: return t1;
}

cint selector_reclaim(cint selector_self){
  cint t8;
  object_Dec_ref(((cptr)selector_self)[7] /* root*/);
  object_Dec_ref(((cptr)selector_self)[8] /* indices*/);
  object_reclaim((cint)selector_self);
  t8_label: return t8;
}

cint selector_Make_selector(cint selector_self, cint selector_ob){
  cint selector_result;
  cint t9, t10, t11, t12;
  t10 = ((cptr)(((cptr)((cptr)selector_self)[8] /* indices*/)[0]))[7];
  t11 = ((f0)t10)((cint)((cptr)selector_self)[8] /* indices*/, (cint)selector_ob); /* Append*/
  ((cptr)selector_self)[8] /* indices*/ = t11;
  t9 = selector_self;
  goto t9_label;
  t9_label: return t9;
}

cint selector_OpAssign(cint selector_self, cint selector_expr, cint selector_op){
  cint selector_o, selector_b, selector_val, selector_v, selector_t, selector_ms, selector_nval;
  cint t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46;
  t14 = ((cptr)(((cptr)((cptr)selector_self)[8] /* indices*/)[0]))[62];
  t15 = ((f0)t14)((cint)((cptr)selector_self)[8] /* indices*/, (cint)1); /* lookup*/
  selector_o = t15;
  selector_b = ((cptr)selector_self)[7] /* root*/;
  t17 = ((cptr)selector_b)[4] /* class_of*/ == strpool_str_79;
  if (t17){
    t18 = ((cptr)(((cptr)selector_b)[0]))[189];
    t19 = ((f0)t18)((cint)selector_b, (cint)selector_o, (cint)((cptr)((cptr)selector_self)[8] /* indices*/)[3] /* len*/); /* lookup_in_given_scope_and_curr*/
    selector_b = t19;
  }else{
    ((cptr)selector_b)[1] += 1;
    selector_b = selector_b;
  };
  ((cptr)selector_b)[1] += 1;
  t21 = ((cptr)(((cptr)selector_b)[0]))[38];
  t22 = ((f0)t21)((cint)selector_b); /* Eval*/
  selector_val = t22;
  t24 = selector_val == object_Undefined;
  t25 = t24;
  if (t25){
    t26 = ((cptr)selector_b)[4] /* class_of*/ == strpool_str_70;
    t25 = t26;
  };
  if (t25){
    selector_v = selector_b;
    ((cptr)((cptr)selector_v)[7] /* type*/)[1] += 1;
    t27 = ((cptr)(((cptr)((cptr)selector_v)[7] /* type*/)[0]))[38];
    t28 = ((f0)t27)((cint)((cptr)selector_v)[7] /* type*/); /* Eval*/
    selector_t = t28;
    t30 = ((cptr)selector_t)[5] /* representation*/ == strpool_str_59;
    if (t30){
      selector_ms = selector_t;
      t31 = ((cptr)(((cptr)selector_ms)[0]))[193];
      t32 = ((f0)t31)((cint)selector_ms); /* map_for*/
      selector_val = t32;
      ((cptr)selector_v)[1] += 1;
      ((cptr)selector_val)[1] += 1;
      t34 = (cptr)(((cptr)(((cptr)selector_v)[0]))[96]); /* OpAssign*/
      ((f0)t34)((cint)selector_v, (cint)selector_val, (cint)0);
    };
  };
  t35 = ((cptr)selector_val)[1] /* refcount*/ == 2;
  t36 = t35;
  if (!t36){    t37 = ((cptr)selector_val)[4] /* class_of*/ == strpool_str_37;
    t36 = t37;
  };
  if (t36){
    object_Dec_ref(selector_val);
    t38 = ((cptr)(((cptr)selector_self)[0]))[172];
    t39 = ((f0)t38)((cint)selector_self, (cint)selector_val, (cint)1, (cint)selector_expr, (cint)selector_op); /* update_component*/
    selector_nval = t39;
    t41 = selector_nval != selector_val;
    if (t41){
      ((cptr)selector_val)[1] += 1;
      selector_val = selector_val;
      ((cptr)selector_b)[1] += 1;
      t42 = (cptr)(((cptr)(((cptr)selector_b)[0]))[96]); /* OpAssign*/
      ((f0)t42)((cint)selector_b, (cint)selector_nval, (cint)0);
    };
  }else{
    t43 = ((cptr)(((cptr)selector_self)[0]))[172];
    t44 = ((f0)t43)((cint)selector_self, (cint)selector_val, (cint)1, (cint)selector_expr, (cint)selector_op); /* update_component*/
    selector_nval = t44;
    ((cptr)selector_b)[1] += 1;
    t46 = (cptr)(((cptr)(((cptr)selector_b)[0]))[96]); /* OpAssign*/
    ((f0)t46)((cint)selector_b, (cint)selector_nval, (cint)0);
  };
  object_Dec_ref(selector_self);
  object_Dec_ref(selector_b);
  t13_label: return t13;
}

cint selector_Call(cint selector_self){
  cint t47, t48;
  ((cptr)((cptr)selector_self)[7] /* root*/)[1] += 1;
  ((cptr)((cptr)selector_self)[8] /* indices*/)[1] += 1;
  t48 = (cptr)(((cptr)(((cptr)((cptr)selector_self)[7] /* root*/)[0]))[18]); /* Call_with_params*/
  ((f0)t48)((cint)((cptr)selector_self)[7] /* root*/, (cint)((cptr)selector_self)[8] /* indices*/);
  object_Dec_ref(selector_self);
  t47_label: return t47;
}

cint selector_Get(cint selector_self){
  cint selector_ob, selector_num;
  cint t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63;
  t50 = stdin_get_rest_of_line();
  selector_ob = t50;
  t51 = ((cptr)selector_ob)[4] /* class_of*/ != strpool_str_6;
  if (t51){
    ((cptr)selector_self)[1] += 1;
    t52 = (cptr)(((cptr)(((cptr)selector_self)[0]))[96]); /* OpAssign*/
    ((f0)t52)((cint)selector_self, (cint)selector_ob, (cint)0);
  }else{
    ((cptr)selector_ob)[1] += 1;
    t53 = ((cptr)(((cptr)selector_ob)[0]))[87];
    t54 = ((f0)t53)((cint)selector_ob); /* Mknum*/
    selector_num = t54;
    t56 = selector_num == object_Undefined;
    if (t56){
      ((cptr)selector_self)[1] += 1;
      t57 = (cptr)(((cptr)(((cptr)selector_self)[0]))[96]); /* OpAssign*/
      ((f0)t57)((cint)selector_self, (cint)selector_ob, (cint)0);
    }else{
      ((cptr)selector_self)[1] += 1;
      t58 = (cptr)(((cptr)(((cptr)selector_self)[0]))[96]); /* OpAssign*/
      ((f0)t58)((cint)selector_self, (cint)selector_num, (cint)0);
      ((cptr)selector_self)[1] += 1;
      t59 = ((cptr)(((cptr)selector_self)[0]))[38];
      t60 = ((f0)t59)((cint)selector_self); /* Eval*/
      selector_num = t60;
      t62 = selector_num == object_Undefined;
      if (t62){
        ((cptr)selector_self)[1] += 1;
        t63 = (cptr)(((cptr)(((cptr)selector_self)[0]))[96]); /* OpAssign*/
        ((f0)t63)((cint)selector_self, (cint)selector_ob, (cint)0);
      }else{
        object_Dec_ref(selector_ob);
        object_Dec_ref(selector_num);
      };
    };
  };
  object_Dec_ref(selector_self);
  t49_label: return t49;
}

cint selector_Make_name_list(cint selector_self, cint selector_ob){
  cint selector_result;
  cint t64, t65, t66;
  t65 = mem_malloc(32); ((cptr)t65)[0] = namelist_methods;
  t66 = namelist_alloc((cint)t65, (cint)selector_self, (cint)selector_ob);
  t64 = t66;
  goto t64_label;
  t64_label: return t64;
}

cint selector_update_component(cint selector_self, cint selector_val, cint selector_i, cint selector_expr, cint selector_op){
  cint selector_result, selector_f, selector_p, selector_params, selector_indx, selector_nval, selector_cval, selector_savedhv, selector_ncval;
  cint t67, t68, t69, t70, t71, t72, t73, t74, t75, t76, t77, t78, t79, t80, t81, t82, t83, t84, t85, t86, t87, t88, t89, t90, t91, t92, t93, t94, t95, t96, t97, t98, t99, t100, t101, t102, t103, t104, t105, t106, t107, t108, t109, t110, t111, t112, t113;
  t68 = ((cptr)selector_val)[4] /* class_of*/ == strpool_str_60;
  if (t68){
    t69 = ((cptr)(((cptr)selector_self)[0]))[173];
    t70 = ((f0)t69)((cint)selector_self, (cint)selector_val, (cint)selector_i, (cint)selector_expr, (cint)selector_op); /* update_map_component*/
    t67 = t70;
    goto t67_label;
  };
  t72 = ((cptr)selector_val)[4] /* class_of*/ == strpool_str_37;
  if (t72){
    selector_f = selector_val;
    t73 = ((cptr)selector_f)[12] /* memo*/ == object_Undefined;
    if (t73){
      t74 = mem_malloc(48); ((cptr)t74)[0] = map_methods;
      t75 = map_alloc((cint)t74);
      ((cptr)selector_f)[12] /* memo*/ = t75;
    };
    t76 = ((cptr)(((cptr)selector_self)[0]))[173];
    t77 = ((f0)t76)((cint)selector_self, (cint)((cptr)selector_f)[12] /* memo*/, (cint)selector_i, (cint)selector_expr, (cint)selector_op); /* update_map_component*/
    ((cptr)selector_f)[12] /* memo*/ = t77;
    t67 = selector_val;
    goto t67_label;
  };
  t79 = ((cptr)selector_val)[4] /* class_of*/ == strpool_str_81;
  t80 = t79;
  if (t80){
    t81 = selector_op == 0;
    t80 = t81;
  };
  if (t80){
    ((cptr)selector_val)[1] += 1;
    selector_p = selector_val;
    ((cptr)((cptr)selector_self)[8] /* indices*/)[1] += 1;
    t82 = ((cptr)(((cptr)((cptr)selector_self)[8] /* indices*/)[0]))[7];
    t83 = ((f0)t82)((cint)((cptr)selector_self)[8] /* indices*/, (cint)selector_expr); /* Append*/
    selector_params = t83;
    t85 = (cptr)(((cptr)(((cptr)selector_p)[0]))[18]); /* Call_with_params*/
    ((f0)t85)((cint)selector_p, (cint)selector_params);
    t67 = selector_val;
    goto t67_label;
  };
  t86 = ((cptr)(((cptr)((cptr)selector_self)[8] /* indices*/)[0]))[62];
  t87 = ((f0)t86)((cint)((cptr)selector_self)[8] /* indices*/, (cint)selector_i); /* lookup*/
  selector_indx = t87;
  t89 = ((cptr)((cptr)selector_self)[8] /* indices*/)[3] /* len*/ == selector_i;
  if (t89){
    ((cptr)selector_indx)[1] += 1;
    t90 = ((cptr)(((cptr)selector_val)[0]))[15];
    t91 = ((f0)t90)((cint)selector_val, (cint)selector_indx, (cint)selector_expr, (cint)selector_op); /* Assign_to_component*/
    selector_nval = t91;
    t93 = selector_nval != selector_val;
    if (t93){
      ((cptr)selector_val)[1] += 1;
      selector_val = selector_val;
    };
    t67 = selector_nval;
    goto t67_label;
  };
  ((cptr)selector_val)[1] += 1;
  ((cptr)selector_indx)[1] += 1;
  t94 = ((cptr)(((cptr)selector_val)[0]))[9];
  t95 = ((f0)t94)((cint)selector_val, (cint)selector_indx); /* Apply*/
  selector_cval = t95;
  t97 = ((cptr)selector_val)[1] /* refcount*/ == 1;
  t98 = t97;
  if (t98){
    t99 = ((cptr)selector_cval)[1] /* refcount*/ == 2;
    t98 = t99;
  };
  if (t98){
    object_Dec_ref(selector_cval);
    selector_savedhv = ((cptr)selector_cval)[2] /* hashval*/;
    t100 = selector_i + 1;
    t101 = ((cptr)(((cptr)selector_self)[0]))[172];
    t102 = ((f0)t101)((cint)selector_self, (cint)selector_cval, (cint)t100, (cint)selector_expr, (cint)selector_op); /* update_component*/
    selector_ncval = t102;
    t104 = selector_cval == selector_ncval;
    if (t104){
      t105 = ((cptr)selector_val)[2] /* hashval*/ - selector_savedhv;
      ((cptr)selector_val)[2] /* hashval*/ = t105;
      t106 = ((cptr)selector_val)[2] /* hashval*/ + ((cptr)selector_ncval)[2] /* hashval*/;
      ((cptr)selector_val)[2] /* hashval*/ = t106;
      t67 = selector_val;
      goto t67_label;
    };
  }else{
    t107 = selector_i + 1;
    t108 = ((cptr)(((cptr)selector_self)[0]))[172];
    t109 = ((f0)t108)((cint)selector_self, (cint)selector_cval, (cint)t107, (cint)selector_expr, (cint)selector_op); /* update_component*/
    selector_ncval = t109;
  };
  ((cptr)selector_indx)[1] += 1;
  t111 = ((cptr)(((cptr)selector_val)[0]))[15];
  t112 = ((f0)t111)((cint)selector_val, (cint)selector_indx, (cint)selector_ncval, (cint)0); /* Assign_to_component*/
  t67 = t112;
  goto t67_label;
  t67_label: return t67;
}

cint selector_update_map_component(cint selector_self, cint selector_val, cint selector_i, cint selector_expr, cint selector_op){
  cint selector_result, selector_indx, selector_m, selector_l, selector_cval, selector_mcd, selector_ncval;
  cint t114, t115, t116, t117, t118, t119, t120, t121, t122, t123, t124, t125, t126, t127, t128, t129, t130, t131, t132, t133, t134, t135, t136, t137, t138, t139, t140, t141, t142, t143, t144, t145, t146, t147, t148, t149, t150, t151;
  selector_m = selector_val;
  selector_l = selector_i;
  t115 = ((cptr)selector_m)[7] /* domains*/ != 0;
  if (t115){
    t116 = ((cptr)((cptr)selector_m)[7] /* domains*/)[3] /* len*/ - 1;
    t117 = selector_l + t116;
    selector_l = t117;
  };
  t118 = selector_l > ((cptr)((cptr)selector_self)[8] /* indices*/)[3] /* len*/;
  if (t118){
    selector_l = ((cptr)((cptr)selector_self)[8] /* indices*/)[3] /* len*/;
  };
  t119 = mem_malloc(40); ((cptr)t119)[0] = slicelst_methods;
  ((cptr)((cptr)selector_self)[8] /* indices*/)[1] += 1;
  t120 = slicelst_alloc((cint)t119, (cint)((cptr)selector_self)[8] /* indices*/, (cint)selector_i, (cint)selector_l);
  selector_indx = t120;
  t121 = ((cptr)((cptr)selector_self)[8] /* indices*/)[3] /* len*/ == selector_l;
  if (t121){
    t122 = ((cptr)(((cptr)selector_m)[0]))[15];
    t123 = ((f0)t122)((cint)selector_m, (cint)selector_indx, (cint)selector_expr, (cint)selector_op); /* Assign_to_component*/
    t114 = t123;
    goto t114_label;
  };
  ((cptr)selector_m)[1] += 1;
  ((cptr)selector_indx)[1] += 1;
  t125 = ((cptr)(((cptr)selector_m)[0]))[9];
  t126 = ((f0)t125)((cint)selector_m, (cint)selector_indx); /* Apply*/
  selector_cval = t126;
  t128 = selector_cval == object_Undefined;
  t129 = t128;
  if (t129){
    t130 = ((cptr)((cptr)selector_m)[8] /* codomain*/)[5] /* representation*/ == strpool_str_59;
    t129 = t130;
  };
  if (t129){
    selector_mcd = ((cptr)selector_m)[8] /* codomain*/;
    t131 = ((cptr)(((cptr)selector_mcd)[0]))[193];
    t132 = ((f0)t131)((cint)selector_mcd); /* map_for*/
    selector_cval = t132;
    ((cptr)selector_indx)[1] += 1;
    ((cptr)selector_cval)[1] += 1;
    t134 = ((cptr)(((cptr)selector_m)[0]))[15];
    t135 = ((f0)t134)((cint)selector_m, (cint)selector_indx, (cint)selector_cval, (cint)0); /* Assign_to_component*/
    selector_m = t135;
  };
  t137 = ((cptr)selector_m)[1] /* refcount*/ == 1;
  t138 = t137;
  if (t138){
    t139 = ((cptr)selector_cval)[1] /* refcount*/ == 2;
    t138 = t139;
  };
  if (t138){
    object_Dec_ref(selector_cval);
    t140 = selector_l + 1;
    t141 = ((cptr)(((cptr)selector_self)[0]))[172];
    t142 = ((f0)t141)((cint)selector_self, (cint)selector_cval, (cint)t140, (cint)selector_expr, (cint)selector_op); /* update_component*/
    selector_ncval = t142;
    t144 = selector_cval == selector_ncval;
    if (t144){
      object_Dec_ref(selector_indx);
      t114 = selector_m;
      goto t114_label;
    };
  }else{
    t145 = selector_l + 1;
    t146 = ((cptr)(((cptr)selector_self)[0]))[172];
    t147 = ((f0)t146)((cint)selector_self, (cint)selector_cval, (cint)t145, (cint)selector_expr, (cint)selector_op); /* update_component*/
    selector_ncval = t147;
  };
  t149 = ((cptr)(((cptr)selector_m)[0]))[15];
  t150 = ((f0)t149)((cint)selector_m, (cint)selector_indx, (cint)selector_ncval, (cint)0); /* Assign_to_component*/
  t114 = t150;
  goto t114_label;
  t114_label: return t114;
}

void init_selector(){
  copy_meth_table(selector_methods, object_methods);
  selector_methods[0] = 36;
  selector_methods[3] = selector_alloc;
  selector_methods[4] = selector_reclaim;
  selector_methods[73] = selector_Make_selector;
  selector_methods[96] = selector_OpAssign;
  selector_methods[16] = selector_Call;
  selector_methods[45] = selector_Get;
  selector_methods[69] = selector_Make_name_list;
  selector_methods[172] = selector_update_component;
  selector_methods[173] = selector_update_map_component;
}
