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

extern cint boolean_False;
extern cint strpool_str_35;


cptr pstring_methods[meth_max];

cint pstring_alloc(cint pstring_self, cint pstring_str1, cint pstring_str2){
  cint pstring_result;
  cint t1, t2, t3, t4;
  t2 = string_alloc((cint)pstring_self);
  pstring_result = t2;
  ((cptr)pstring_self)[5] /* representation*/ = strpool_str_35;
  t3 = ((cptr)pstring_str1)[2] /* hashval*/ + ((cptr)pstring_str2)[2] /* hashval*/;
  ((cptr)pstring_self)[2] /* hashval*/ = t3;
  t4 = ((cptr)pstring_str1)[3] /* len*/ + ((cptr)pstring_str2)[3] /* len*/;
  ((cptr)pstring_self)[3] /* len*/ = t4;
  ((cptr)pstring_self)[9] /* substr1*/ = pstring_str1;
  ((cptr)pstring_self)[10] /* substr2*/ = pstring_str2;
  t1 = pstring_result;
  goto t1_label;
  t1_label: return t1;
}

cint pstring_reclaim(cint pstring_self){
  cint t5;
  object_Dec_ref(((cptr)pstring_self)[9] /* substr1*/);
  object_Dec_ref(((cptr)pstring_self)[10] /* substr2*/);
  string_reclaim((cint)pstring_self);
  t5_label: return t5;
}

cint pstring_Contains(cint pstring_self, cint pstring_ob){
  cint pstring_result;
  cint t6, t7, t8, t9, t10, t11, t12, t13;
  ((cptr)((cptr)pstring_self)[9] /* substr1*/)[1] += 1;
  ((cptr)pstring_ob)[1] += 1;
  t7 = ((cptr)(((cptr)((cptr)pstring_self)[9] /* substr1*/)[0]))[20];
  t8 = ((f0)t7)((cint)((cptr)pstring_self)[9] /* substr1*/, (cint)pstring_ob); /* Contains*/
  pstring_result = t8;
  t10 = pstring_result == boolean_False;
  if (t10){
    ((cptr)((cptr)pstring_self)[10] /* substr2*/)[1] += 1;
    ((cptr)pstring_ob)[1] += 1;
    t11 = ((cptr)(((cptr)((cptr)pstring_self)[10] /* substr2*/)[0]))[20];
    t12 = ((f0)t11)((cint)((cptr)pstring_self)[10] /* substr2*/, (cint)pstring_ob); /* Contains*/
    pstring_result = t12;
  };
  object_Dec_ref(pstring_self);
  object_Dec_ref(pstring_ob);
  t6 = pstring_result;
  goto t6_label;
  t6_label: return t6;
}

cint pstring_copy_of(cint pstring_self){
  cint pstring_result;
  cint t14, t15, t16, t17;
  t15 = ((cptr)pstring_self)[1] /* refcount*/ == 1;
  if (t15){
    t14 = pstring_self;
    goto t14_label;
  };
  t16 = mem_malloc(44); ((cptr)t16)[0] = pstring_methods;
  ((cptr)((cptr)pstring_self)[9] /* substr1*/)[1] += 1;
  ((cptr)((cptr)pstring_self)[10] /* substr2*/)[1] += 1;
  t17 = pstring_alloc((cint)t16, (cint)((cptr)pstring_self)[9] /* substr1*/, (cint)((cptr)pstring_self)[10] /* substr2*/);
  pstring_result = t17;
  object_Dec_ref(pstring_self);
  t14 = pstring_result;
  goto t14_label;
  t14_label: return t14;
}

cint pstring_lookup_as_cint(cint pstring_self, cint pstring_i){
  cint pstring_result, pstring_str, pstring_j;
  cint t18, t21, t22, t23, t24, t25, t26;
  pstring_str = pstring_self;
  t19:
  t21 = ((cptr)pstring_str)[5] /* representation*/ == strpool_str_35;
  if (!t21) goto t20;
    t22 = pstring_i - ((cptr)((cptr)pstring_str)[9] /* substr1*/)[3] /* len*/;
    pstring_j = t22;
    t23 = pstring_j <= 0;
    if (t23){
      pstring_str = ((cptr)pstring_str)[9] /* substr1*/;
    }else{
      pstring_str = ((cptr)pstring_str)[10] /* substr2*/;
      pstring_i = pstring_j;
    };
  goto t19;
  t20:;
  t24 = ((cptr)(((cptr)pstring_str)[0]))[63];
  t25 = ((f0)t24)((cint)pstring_str, (cint)pstring_i); /* lookup_as_cint*/
  t18 = t25;
  goto t18_label;
  t18_label: return t18;
}

cint pstring_lookup(cint pstring_self, cint pstring_i){
  cint pstring_result, pstring_str, pstring_j;
  cint t27, t30, t31, t32, t33, t34, t35;
  pstring_str = pstring_self;
  t28:
  t30 = ((cptr)pstring_str)[5] /* representation*/ == strpool_str_35;
  if (!t30) goto t29;
    t31 = pstring_i - ((cptr)((cptr)pstring_str)[9] /* substr1*/)[3] /* len*/;
    pstring_j = t31;
    t32 = pstring_j <= 0;
    if (t32){
      pstring_str = ((cptr)pstring_str)[9] /* substr1*/;
    }else{
      pstring_str = ((cptr)pstring_str)[10] /* substr2*/;
      pstring_i = pstring_j;
    };
  goto t28;
  t29:;
  t33 = ((cptr)(((cptr)pstring_str)[0]))[62];
  t34 = ((f0)t33)((cint)pstring_str, (cint)pstring_i); /* lookup*/
  t27 = t34;
  goto t27_label;
  t27_label: return t27;
}

cint pstring_put_on(cint pstring_self, cint pstring_f, cint pstring_i, cint pstring_j){
  cint pstring_k;
  cint t36, t37, t38, t39, t40, t41, t42, t43, t44;
  t37 = pstring_i <= ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
  if (t37){
    pstring_k = ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
    t38 = pstring_j < ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
    if (t38){
      pstring_k = pstring_j;
    };
    t39 = (cptr)(((cptr)(((cptr)((cptr)pstring_self)[9] /* substr1*/)[0]))[128]); /* put_on*/
    ((f0)t39)((cint)((cptr)pstring_self)[9] /* substr1*/, (cint)pstring_f, (cint)pstring_i, (cint)pstring_k);
  };
  t40 = pstring_j > ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
  if (t40){
    pstring_k = 1;
    t41 = pstring_i > ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
    if (t41){
      t42 = pstring_i - ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
      pstring_k = t42;
    };
    t43 = pstring_j - ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
    t44 = (cptr)(((cptr)(((cptr)((cptr)pstring_self)[10] /* substr2*/)[0]))[128]); /* put_on*/
    ((f0)t44)((cint)((cptr)pstring_self)[10] /* substr2*/, (cint)pstring_f, (cint)pstring_k, (cint)t43);
  };
  t36_label: return t36;
}

cint pstring_update(cint pstring_self, cint pstring_i, cint pstring_ch){
  cint pstring_result, pstring_j;
  cint t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60;
  t46 = pstring_i - ((cptr)((cptr)pstring_self)[9] /* substr1*/)[3] /* len*/;
  pstring_j = t46;
  t47 = pstring_i > ((cptr)pstring_self)[3] /* len*/;
  if (t47){
    t48 = string_update((cint)pstring_self, (cint)pstring_i, (cint)pstring_ch);
    t45 = t48;
    goto t45_label;
  };
  t49 = ((cptr)(((cptr)pstring_self)[0]))[21];
  t50 = ((f0)t49)((cint)pstring_self); /* copy_of*/
  pstring_result = t50;
  t52 = pstring_j <= 0;
  if (t52){
    t53 = ((cptr)(((cptr)((cptr)pstring_result)[9] /* substr1*/)[0]))[130];
    t54 = ((f0)t53)((cint)((cptr)pstring_result)[9] /* substr1*/, (cint)pstring_i, (cint)pstring_ch); /* update*/
    ((cptr)pstring_result)[9] /* substr1*/ = t54;
  }else{
    t56 = ((cptr)(((cptr)((cptr)pstring_result)[10] /* substr2*/)[0]))[130];
    t57 = ((f0)t56)((cint)((cptr)pstring_result)[10] /* substr2*/, (cint)pstring_j, (cint)pstring_ch); /* update*/
    ((cptr)pstring_result)[10] /* substr2*/ = t57;
  };
  t59 = ((cptr)((cptr)pstring_result)[9] /* substr1*/)[2] /* hashval*/ + ((cptr)((cptr)pstring_result)[10] /* substr2*/)[2] /* hashval*/;
  ((cptr)pstring_result)[2] /* hashval*/ = t59;
  t60 = ((cptr)((cptr)pstring_result)[9] /* substr1*/)[3] /* len*/ + ((cptr)((cptr)pstring_result)[10] /* substr2*/)[3] /* len*/;
  ((cptr)pstring_result)[3] /* len*/ = t60;
  t45 = pstring_result;
  goto t45_label;
  t45_label: return t45;
}

void init_pstring(){
  copy_meth_table(pstring_methods, string_methods);
  pstring_methods[0] = 44;
  pstring_methods[3] = pstring_alloc;
  pstring_methods[4] = pstring_reclaim;
  pstring_methods[20] = pstring_Contains;
  pstring_methods[21] = pstring_copy_of;
  pstring_methods[63] = pstring_lookup_as_cint;
  pstring_methods[62] = pstring_lookup;
  pstring_methods[128] = pstring_put_on;
  pstring_methods[130] = pstring_update;
}
