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

extern cint object_Undefined;
extern cint strpool_str_46;


cptr slicelst_methods[meth_max];

cint slicelst_alloc(cint slicelst_self, cint slicelst_bl, cint slicelst_si, cint slicelst_ei){
  cint slicelst_result, slicelst_i;
  cint t1, t2, t3, t4, t6, t7, t8;
  t2 = list_alloc((cint)slicelst_self);
  slicelst_result = t2;
  ((cptr)slicelst_self)[5] /* representation*/ = strpool_str_46;
  t3 = slicelst_ei - slicelst_si;
  t4 = t3 + 1;
  ((cptr)slicelst_self)[3] /* len*/ = t4;
  ((cptr)slicelst_self)[2] /* hashval*/ = 0;
  for (slicelst_i = slicelst_si; slicelst_i <= slicelst_ei; slicelst_i++){
    t7 = ((cptr)(((cptr)slicelst_bl)[0]))[62];
    t6 = ((f0)t7)((cint)slicelst_bl, (cint)slicelst_i); /* lookup*/
    t8 = ((cptr)slicelst_self)[2] /* hashval*/ + ((cptr)t6)[2] /* hashval*/;
    ((cptr)slicelst_self)[2] /* hashval*/ = t8;
  };t5:;
  ((cptr)slicelst_self)[8] /* baselst*/ = slicelst_bl;
  ((cptr)slicelst_self)[9] /* sindex*/ = slicelst_si;
  t1 = slicelst_result;
  goto t1_label;
  t1_label: return t1;
}

cint slicelst_reclaim(cint slicelst_self){
  cint t9;
  object_Dec_ref(((cptr)slicelst_self)[8] /* baselst*/);
  list_reclaim((cint)slicelst_self);
  t9_label: return t9;
}

cint slicelst_All_but_last(cint slicelst_self){
  cint slicelst_result;
  cint t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20;
  t11 = ((cptr)slicelst_self)[3] /* len*/ == 1;
  if (t11){
    object_Dec_ref(slicelst_self);
    t12 = mem_malloc(40); ((cptr)t12)[0] = slist_methods;
    t13 = slist_alloc((cint)t12, (cint)1);
    t10 = t13;
    goto t10_label;
  };
  t14 = ((cptr)(((cptr)slicelst_self)[0]))[21];
  t15 = ((f0)t14)((cint)slicelst_self); /* copy_of*/
  slicelst_result = t15;
  t17 = ((cptr)(((cptr)slicelst_self)[0]))[62];
  t18 = ((f0)t17)((cint)slicelst_self, (cint)((cptr)slicelst_self)[3] /* len*/); /* lookup*/
  t19 = ((cptr)slicelst_result)[2] /* hashval*/ - ((cptr)t18)[2] /* hashval*/;
  ((cptr)slicelst_result)[2] /* hashval*/ = t19;
  t20 = ((cptr)slicelst_result)[3] /* len*/ - 1;
  ((cptr)slicelst_result)[3] /* len*/ = t20;
  t10 = slicelst_result;
  goto t10_label;
  t10_label: return t10;
}

cint slicelst_copy_of(cint slicelst_self){
  cint slicelst_result;
  cint t21, t22, t23, t24, t25, t26;
  t22 = ((cptr)slicelst_self)[1] /* refcount*/ == 1;
  if (t22){
    t21 = slicelst_self;
    goto t21_label;
  };
  object_Dec_ref(slicelst_self);
  t23 = mem_malloc(40); ((cptr)t23)[0] = slicelst_methods;
  ((cptr)((cptr)slicelst_self)[8] /* baselst*/)[1] += 1;
  t24 = ((cptr)slicelst_self)[9] /* sindex*/ + ((cptr)slicelst_self)[3] /* len*/;
  t25 = t24 - 1;
  t26 = slicelst_alloc((cint)t23, (cint)((cptr)slicelst_self)[8] /* baselst*/, (cint)((cptr)slicelst_self)[9] /* sindex*/, (cint)t25);
  t21 = t26;
  goto t21_label;
  t21_label: return t21;
}

cint slicelst_lookup(cint slicelst_self, cint slicelst_i){
  cint slicelst_result, slicelst_j;
  cint t27, t28, t29, t30, t31, t32, t33, t34, t35;
  t28 = slicelst_i - 1;
  t29 = t28 + ((cptr)slicelst_self)[9] /* sindex*/;
  slicelst_j = t29;
  t30 = slicelst_i >= 1;
  t31 = t30;
  if (t31){
    t32 = slicelst_i <= ((cptr)slicelst_self)[3] /* len*/;
    t31 = t32;
  };
  if (t31){
    t33 = ((cptr)(((cptr)((cptr)slicelst_self)[8] /* baselst*/)[0]))[62];
    t34 = ((f0)t33)((cint)((cptr)slicelst_self)[8] /* baselst*/, (cint)slicelst_j); /* lookup*/
    t27 = t34;
    goto t27_label;
  };
  t27 = object_Undefined;
  goto t27_label;
  t27_label: return t27;
}

cint slicelst_Tail(cint slicelst_self){
  cint slicelst_result;
  cint t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47;
  t37 = ((cptr)slicelst_self)[3] /* len*/ == 1;
  if (t37){
    object_Dec_ref(slicelst_self);
    t38 = mem_malloc(40); ((cptr)t38)[0] = slist_methods;
    t39 = slist_alloc((cint)t38, (cint)1);
    t36 = t39;
    goto t36_label;
  };
  t40 = ((cptr)(((cptr)slicelst_self)[0]))[21];
  t41 = ((f0)t40)((cint)slicelst_self); /* copy_of*/
  slicelst_result = t41;
  t43 = ((cptr)(((cptr)slicelst_self)[0]))[62];
  t44 = ((f0)t43)((cint)slicelst_self, (cint)1); /* lookup*/
  t45 = ((cptr)slicelst_result)[2] /* hashval*/ - ((cptr)t44)[2] /* hashval*/;
  ((cptr)slicelst_result)[2] /* hashval*/ = t45;
  t46 = ((cptr)slicelst_result)[9] /* sindex*/ + 1;
  ((cptr)slicelst_result)[9] /* sindex*/ = t46;
  t47 = ((cptr)slicelst_result)[3] /* len*/ - 1;
  ((cptr)slicelst_result)[3] /* len*/ = t47;
  t36 = slicelst_result;
  goto t36_label;
  t36_label: return t36;
}

cint slicelst_Trim_trailing_undefineds(cint slicelst_self){
  cint slicelst_result;
  cint t48, t49, t50, t51, t52, t53, t56, t57, t58, t59, t60, t61;
  t49 = ((cptr)(((cptr)slicelst_self)[0]))[21];
  t50 = ((f0)t49)((cint)slicelst_self); /* copy_of*/
  slicelst_result = t50;
  t54:
  t58 = ((cptr)slicelst_result)[3] /* len*/ > 0;
  t59 = t58;
  if (t59){
  t56 = ((cptr)(((cptr)slicelst_self)[0]))[62];
  t57 = ((f0)t56)((cint)slicelst_self, (cint)((cptr)slicelst_result)[3] /* len*/); /* lookup*/
    t60 = t57 == object_Undefined;
    t59 = t60;
  };
  if (!t59) goto t55;
    t61 = ((cptr)slicelst_result)[3] /* len*/ - 1;
    ((cptr)slicelst_result)[3] /* len*/ = t61;
  goto t54;
  t55:;
  t48 = slicelst_result;
  goto t48_label;
  t48_label: return t48;
}

void init_slicelst(){
  copy_meth_table(slicelst_methods, list_methods);
  slicelst_methods[0] = 40;
  slicelst_methods[3] = slicelst_alloc;
  slicelst_methods[4] = slicelst_reclaim;
  slicelst_methods[6] = slicelst_All_but_last;
  slicelst_methods[21] = slicelst_copy_of;
  slicelst_methods[62] = slicelst_lookup;
  slicelst_methods[106] = slicelst_Tail;
  slicelst_methods[107] = slicelst_Trim_trailing_undefineds;
}
