#include "cdefs.h"
#include "mem.h"
extern cptr object_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_33;
extern cint strpool_str_36;


cptr slicestr_methods[meth_max];

cint slicestr_alloc(cint slicestr_self, cint slicestr_bs, cint slicestr_si, cint slicestr_ei){
  cint slicestr_result, slicestr_i;
  cint t1, t2, t3, t4, t6, t7, t8;
  t2 = string_alloc((cint)slicestr_self);
  slicestr_result = t2;
  ((cptr)slicestr_self)[5] /* representation*/ = strpool_str_36;
  t3 = slicestr_ei - slicestr_si;
  t4 = t3 + 1;
  ((cptr)slicestr_self)[3] /* len*/ = t4;
  ((cptr)slicestr_self)[2] /* hashval*/ = 0;
  for (slicestr_i = slicestr_si; slicestr_i <= slicestr_ei; slicestr_i++){
    t6 = ((cptr)(((cptr)slicestr_bs)[0]))[63];
    t7 = ((f0)t6)((cint)slicestr_bs, (cint)slicestr_i); /* lookup_as_cint*/
    t8 = ((cptr)slicestr_self)[2] /* hashval*/ + t7;
    ((cptr)slicestr_self)[2] /* hashval*/ = t8;
  };t5:;
  ((cptr)slicestr_self)[9] /* basestr*/ = slicestr_bs;
  ((cptr)slicestr_self)[10] /* sindex*/ = slicestr_si;
  ((cptr)slicestr_self)[11] /* eindex*/ = slicestr_ei;
  t1 = slicestr_result;
  goto t1_label;
  t1_label: return t1;
}

cint slicestr_reclaim(cint slicestr_self){
  cint t9;
  object_Dec_ref(((cptr)slicestr_self)[9] /* basestr*/);
  string_reclaim((cint)slicestr_self);
  t9_label: return t9;
}

cint slicestr_All_but_last(cint slicestr_self){
  cint slicestr_result;
  cint t10, t11, t12, t13, t14, t15, t16, t17, t18, t19;
  t11 = ((cptr)slicestr_self)[3] /* len*/ == 1;
  if (t11){
    object_Dec_ref(slicestr_self);
    ((cptr)strpool_str_33)[1] += 1;
    t10 = strpool_str_33;
    goto t10_label;
  };
  t12 = ((cptr)(((cptr)slicestr_self)[0]))[21];
  t13 = ((f0)t12)((cint)slicestr_self); /* copy_of*/
  slicestr_result = t13;
  t15 = ((cptr)(((cptr)slicestr_self)[0]))[63];
  t16 = ((f0)t15)((cint)slicestr_self, (cint)((cptr)slicestr_self)[3] /* len*/); /* lookup_as_cint*/
  t17 = ((cptr)slicestr_result)[2] /* hashval*/ - t16;
  ((cptr)slicestr_result)[2] /* hashval*/ = t17;
  t18 = ((cptr)slicestr_result)[11] /* eindex*/ - 1;
  ((cptr)slicestr_result)[11] /* eindex*/ = t18;
  t19 = ((cptr)slicestr_result)[3] /* len*/ - 1;
  ((cptr)slicestr_result)[3] /* len*/ = t19;
  t10 = slicestr_result;
  goto t10_label;
  t10_label: return t10;
}

cint slicestr_copy_of(cint slicestr_self){
  cint slicestr_result;
  cint t20, t21, t22, t23;
  t21 = ((cptr)slicestr_self)[1] /* refcount*/ == 1;
  if (t21){
    t20 = slicestr_self;
    goto t20_label;
  };
  object_Dec_ref(slicestr_self);
  t22 = mem_malloc(48); ((cptr)t22)[0] = slicestr_methods;
  ((cptr)((cptr)slicestr_self)[9] /* basestr*/)[1] += 1;
  t23 = slicestr_alloc((cint)t22, (cint)((cptr)slicestr_self)[9] /* basestr*/, (cint)((cptr)slicestr_self)[10] /* sindex*/, (cint)((cptr)slicestr_self)[11] /* eindex*/);
  t20 = t23;
  goto t20_label;
  t20_label: return t20;
}

cint slicestr_lookup_as_cint(cint slicestr_self, cint slicestr_i){
  cint slicestr_result, slicestr_j;
  cint t24, t25, t26, t27, t28, t29, t30;
  t25 = slicestr_i - 1;
  t26 = t25 + ((cptr)slicestr_self)[10] /* sindex*/;
  slicestr_j = t26;
  t27 = slicestr_j <= ((cptr)slicestr_self)[11] /* eindex*/;
  if (t27){
    t28 = ((cptr)(((cptr)((cptr)slicestr_self)[9] /* basestr*/)[0]))[63];
    t29 = ((f0)t28)((cint)((cptr)slicestr_self)[9] /* basestr*/, (cint)slicestr_j); /* lookup_as_cint*/
    t24 = t29;
    goto t24_label;
  };
  t24 = 0;
  goto t24_label;
  t24_label: return t24;
}

cint slicestr_lookup(cint slicestr_self, cint slicestr_i){
  cint slicestr_result, slicestr_j;
  cint t31, t32, t33, t34, t35, t36, t37;
  t32 = slicestr_i - 1;
  t33 = t32 + ((cptr)slicestr_self)[10] /* sindex*/;
  slicestr_j = t33;
  t34 = slicestr_j <= ((cptr)slicestr_self)[11] /* eindex*/;
  if (t34){
    t35 = ((cptr)(((cptr)((cptr)slicestr_self)[9] /* basestr*/)[0]))[62];
    t36 = ((f0)t35)((cint)((cptr)slicestr_self)[9] /* basestr*/, (cint)slicestr_j); /* lookup*/
    t31 = t36;
    goto t31_label;
  };
  t31 = object_Undefined;
  goto t31_label;
  t31_label: return t31;
}

cint slicestr_put_on(cint slicestr_self, cint slicestr_f, cint slicestr_i, cint slicestr_j){
  cint t38, t39, t40, t41, t42, t43, t44;
  t39 = slicestr_j > ((cptr)slicestr_self)[3] /* len*/;
  if (t39){
    slicestr_j = ((cptr)slicestr_self)[3] /* len*/;
  };
  t40 = slicestr_i - 1;
  t41 = t40 + ((cptr)slicestr_self)[10] /* sindex*/;
  t42 = slicestr_j - 1;
  t43 = t42 + ((cptr)slicestr_self)[10] /* sindex*/;
  t44 = (cptr)(((cptr)(((cptr)((cptr)slicestr_self)[9] /* basestr*/)[0]))[128]); /* put_on*/
  ((f0)t44)((cint)((cptr)slicestr_self)[9] /* basestr*/, (cint)slicestr_f, (cint)t41, (cint)t43);
  t38_label: return t38;
}

cint slicestr_Tail(cint slicestr_self){
  cint slicestr_result;
  cint t45, t46, t47, t48, t49, t50, t51, t52, t53, t54;
  t46 = ((cptr)slicestr_self)[3] /* len*/ == 1;
  if (t46){
    object_Dec_ref(slicestr_self);
    ((cptr)strpool_str_33)[1] += 1;
    t45 = strpool_str_33;
    goto t45_label;
  };
  t47 = ((cptr)(((cptr)slicestr_self)[0]))[21];
  t48 = ((f0)t47)((cint)slicestr_self); /* copy_of*/
  slicestr_result = t48;
  t50 = ((cptr)(((cptr)slicestr_self)[0]))[63];
  t51 = ((f0)t50)((cint)slicestr_self, (cint)1); /* lookup_as_cint*/
  t52 = ((cptr)slicestr_result)[2] /* hashval*/ - t51;
  ((cptr)slicestr_result)[2] /* hashval*/ = t52;
  t53 = ((cptr)slicestr_result)[10] /* sindex*/ + 1;
  ((cptr)slicestr_result)[10] /* sindex*/ = t53;
  t54 = ((cptr)slicestr_result)[3] /* len*/ - 1;
  ((cptr)slicestr_result)[3] /* len*/ = t54;
  t45 = slicestr_result;
  goto t45_label;
  t45_label: return t45;
}

void init_slicestr(){
  copy_meth_table(slicestr_methods, string_methods);
  slicestr_methods[0] = 48;
  slicestr_methods[3] = slicestr_alloc;
  slicestr_methods[4] = slicestr_reclaim;
  slicestr_methods[6] = slicestr_All_but_last;
  slicestr_methods[21] = slicestr_copy_of;
  slicestr_methods[63] = slicestr_lookup_as_cint;
  slicestr_methods[62] = slicestr_lookup;
  slicestr_methods[128] = slicestr_put_on;
  slicestr_methods[106] = slicestr_Tail;
}
