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

extern cint strpool_str_7;
extern cint strpool_str_20;
extern cint strpool_str_21;
extern cint strpool_str_22;
extern cint strpool_str_23;
extern cint strpool_str_24;
extern cint strpool_str_25;
extern cint strpool_str_26;
extern cint strpool_str_27;
extern cint strpool_str_28;
extern cint strpool_str_29;

cint character_open_quote;
cint character_close_quote;

cptr character_methods[meth_max];

cint character_init(){
  cint t1, t2, t3, t4, t5;
  t2 = mem_malloc(36); ((cptr)t2)[0] = character_methods;
  t3 = character_alloc((cint)t2, (cint)96, (cint)0);
  character_open_quote = t3;
  t4 = mem_malloc(36); ((cptr)t4)[0] = character_methods;
  t5 = character_alloc((cint)t4, (cint)39, (cint)0);
  character_close_quote = t5;
  t1_label: return t1;
}

cint character_fini(){
  cint t6;
  object_Dec_ref(character_open_quote);
  object_Dec_ref(character_close_quote);
  t6_label: return t6;
}

cint character_alloc(cint character_self, cint character_ch, cint character_buff){
  cint character_result;
  cint t7, t8;
  t8 = string_alloc((cint)character_self);
  character_result = t8;
  ((cptr)character_self)[5] /* representation*/ = strpool_str_7;
  ((cptr)character_self)[2] /* hashval*/ = character_ch;
  ((cptr)character_self)[3] /* len*/ = 1;
  ((cptr)character_self)[8] /* buf*/ = character_buff;
  t7 = character_result;
  goto t7_label;
  t7_label: return t7;
}

cint character_reclaim(cint character_self){
  cint t9, t10;
  t10 = ((cptr)character_self)[8] /* buf*/ != 0;
  if (t10){
    cstring_mem_free((cint)((cptr)character_self)[8] /* buf*/);
  };
  string_reclaim((cint)character_self);
  t9_label: return t9;
}

cint character_copy_of(cint character_self){
  cint character_result;
  cint t11, t12, t13, t14;
  t12 = ((cptr)character_self)[1] /* refcount*/ == 1;
  if (t12){
    t11 = character_self;
    goto t11_label;
  };
  t13 = mem_malloc(36); ((cptr)t13)[0] = character_methods;
  t14 = character_alloc((cint)t13, (cint)((cptr)character_self)[2] /* hashval*/, (cint)0);
  character_result = t14;
  object_Dec_ref(character_self);
  t11 = character_result;
  goto t11_label;
  t11_label: return t11;
}

cint character_equal(cint character_self, cint character_s){
  cint character_result;
  cint t15, t16, t17;
  t16 = ((cptr)character_self)[2] /* hashval*/ != ((cptr)character_s)[2] /* hashval*/;
  if (t16){
    t15 = 0;
    goto t15_label;
  };
  t17 = ((cptr)character_self)[3] /* len*/ != ((cptr)character_s)[3] /* len*/;
  if (t17){
    t15 = 0;
    goto t15_label;
  };
  t15 = 1;
  goto t15_label;
  t15_label: return t15;
}

cint character_less_than(cint character_self, cint character_s){
  cint character_result, character_i;
  cint t18, t19, t20, t21, t22, t23, t24, t25;
  t19 = ((cptr)character_s)[3] /* len*/ == 0;
  if (t19){
    t18 = 0;
    goto t18_label;
  };
  t20 = ((cptr)(((cptr)character_s)[0]))[63];
  t21 = ((f0)t20)((cint)character_s, (cint)1); /* lookup_as_cint*/
  character_i = t21;
  t23 = ((cptr)character_self)[2] /* hashval*/ > character_i;
  if (t23){
    t18 = 0;
    goto t18_label;
  };
  t24 = ((cptr)character_self)[2] /* hashval*/ < character_i;
  if (t24){
    t18 = 1;
    goto t18_label;
  };
  t25 = ((cptr)character_s)[3] /* len*/ == 1;
  if (t25){
    t18 = 0;
    goto t18_label;
  };
  t18 = 1;
  goto t18_label;
  t18_label: return t18;
}

cint character_lookup_as_cint(cint character_self, cint character_i){
  cint character_result;
  cint t26;
  t26 = ((cptr)character_self)[2] /* hashval*/;
  goto t26_label;
  t26_label: return t26;
}

cint character_lookup(cint character_self, cint character_i){
  cint character_result;
  cint t27;
  t27 = character_self;
  goto t27_label;
  t27_label: return t27;
}

cint character_Mkstr(cint character_self){
  cint character_result;
  cint t28, t29, t30, t31, t32, t33, t34, t35, t36, t37;
  ((cptr)character_open_quote)[1] += 1;
  t29 = ((cptr)(((cptr)character_self)[0]))[112];
  t30 = ((f0)t29)((cint)character_self); /* ubstr*/
  t31 = ((cptr)(((cptr)character_open_quote)[0]))[97];
  t32 = ((f0)t31)((cint)character_open_quote, (cint)t30); /* Plus*/
  ((cptr)character_close_quote)[1] += 1;
  t35 = ((cptr)(((cptr)t32)[0]))[97];
  t36 = ((f0)t35)((cint)t32, (cint)character_close_quote); /* Plus*/
  character_result = t36;
  object_Dec_ref(character_self);
  t28 = character_result;
  goto t28_label;
  t28_label: return t28;
}

cint character_put_on(cint character_self, cint character_f, cint character_i, cint character_j){
  cint t38;
  cfile_fputc((cint)((cptr)character_self)[2] /* hashval*/, (cint)character_f);
  t38_label: return t38;
}

cint character_ubstr(cint character_self){
  cint character_result;
  cint t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60;
  t40 = ((cptr)character_self)[2] /* hashval*/ == 0;
  if (t40){
    ((cptr)strpool_str_20)[1] += 1;
    character_result = strpool_str_20;
  }else{
  t41 = ((cptr)character_self)[2] /* hashval*/ == 7;
  if (t41){
    ((cptr)strpool_str_21)[1] += 1;
    character_result = strpool_str_21;
  }else{
  t42 = ((cptr)character_self)[2] /* hashval*/ == 8;
  if (t42){
    ((cptr)strpool_str_22)[1] += 1;
    character_result = strpool_str_22;
  }else{
  t43 = ((cptr)character_self)[2] /* hashval*/ == 9;
  if (t43){
    ((cptr)strpool_str_23)[1] += 1;
    character_result = strpool_str_23;
  }else{
  t44 = ((cptr)character_self)[2] /* hashval*/ == 10;
  if (t44){
    ((cptr)strpool_str_24)[1] += 1;
    character_result = strpool_str_24;
  }else{
  t45 = ((cptr)character_self)[2] /* hashval*/ == 13;
  if (t45){
    ((cptr)strpool_str_25)[1] += 1;
    character_result = strpool_str_25;
  }else{
  t46 = ((cptr)character_self)[2] /* hashval*/ == 26;
  if (t46){
    ((cptr)strpool_str_26)[1] += 1;
    character_result = strpool_str_26;
  }else{
  t47 = ((cptr)character_self)[2] /* hashval*/ == 27;
  if (t47){
    ((cptr)strpool_str_27)[1] += 1;
    character_result = strpool_str_27;
  }else{
  t48 = ((cptr)character_self)[2] /* hashval*/ == 39;
  if (t48){
    ((cptr)strpool_str_28)[1] += 1;
    ((cptr)character_self)[1] += 1;
    t49 = ((cptr)(((cptr)strpool_str_28)[0]))[97];
    t50 = ((f0)t49)((cint)strpool_str_28, (cint)character_self); /* Plus*/
    character_result = t50;
  }else{
  t52 = ((cptr)character_self)[2] /* hashval*/ == 92;
  if (t52){
    ((cptr)strpool_str_28)[1] += 1;
    ((cptr)character_self)[1] += 1;
    t53 = ((cptr)(((cptr)strpool_str_28)[0]))[97];
    t54 = ((f0)t53)((cint)strpool_str_28, (cint)character_self); /* Plus*/
    character_result = t54;
  }else{
  t56 = ((cptr)character_self)[2] /* hashval*/ == 96;
  if (t56){
    ((cptr)strpool_str_28)[1] += 1;
    ((cptr)character_self)[1] += 1;
    t57 = ((cptr)(((cptr)strpool_str_28)[0]))[97];
    t58 = ((f0)t57)((cint)strpool_str_28, (cint)character_self); /* Plus*/
    character_result = t58;
  }else{
  t60 = ((cptr)character_self)[2] /* hashval*/ == 255;
  if (t60){
    ((cptr)strpool_str_29)[1] += 1;
    character_result = strpool_str_29;
  }else{
    ((cptr)character_self)[1] += 1;
    character_result = character_self;
  };};};};};};};};};};};};
  t39 = character_result;
  goto t39_label;
  t39_label: return t39;
}

cint character_update(cint character_self, cint character_i, cint character_ch){
  cint character_result;
  cint t61, t62, t63, t64, t65, t66;
  t62 = character_i > 1;
  if (t62){
    t63 = string_update((cint)character_self, (cint)character_i, (cint)character_ch);
    t61 = t63;
    goto t61_label;
  };
  t64 = ((cptr)(((cptr)character_self)[0]))[21];
  t65 = ((f0)t64)((cint)character_self); /* copy_of*/
  character_result = t65;
  ((cptr)character_result)[2] /* hashval*/ = character_ch;
  t61 = character_result;
  goto t61_label;
  t61_label: return t61;
}

cint character_update_hashval(cint character_self, cint character_i){
  cint character_result;
  cint t67, t68, t69, t70;
  t68 = ((cptr)(((cptr)character_self)[0]))[21];
  t69 = ((f0)t68)((cint)character_self); /* copy_of*/
  character_result = t69;
  ((cptr)character_result)[2] /* hashval*/ = character_i;
  t67 = character_result;
  goto t67_label;
  t67_label: return t67;
}

void init_character(){
  copy_meth_table(character_methods, string_methods);
  character_methods[0] = 36;
  character_methods[1] = character_init;
  character_methods[2] = character_fini;
  character_methods[3] = character_alloc;
  character_methods[4] = character_reclaim;
  character_methods[21] = character_copy_of;
  character_methods[37] = character_equal;
  character_methods[60] = character_less_than;
  character_methods[63] = character_lookup_as_cint;
  character_methods[62] = character_lookup;
  character_methods[88] = character_Mkstr;
  character_methods[128] = character_put_on;
  character_methods[112] = character_ubstr;
  character_methods[130] = character_update;
  character_methods[109] = character_update_hashval;
}
