#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr boolean_methods[meth_max];
extern cptr integer_methods[meth_max];
extern cptr string_methods[meth_max];
extern cptr sstring_methods[meth_max];
extern cptr slist_methods[meth_max];
#include "cint.h"
#include "cstring.h"
#include "csock.h"
extern cptr collection_methods[meth_max];
#include "cobarray.h"

extern cint boolean_True;
extern cint object_Undefined;
extern cint boolean_False;

cint subsock_Buf;
cint subsock_AF_INET;
cint subsock_SOCK_STREAM;
cint subsock_SOCK_DGRAM;

cptr subsock_methods[meth_max];

cint subsock_init(){
  cint t1, t2, t3, t4, t5, t6, t7;
  subsock_Buf = cstring_mem_malloc((cint)65536);
  t2 = mem_malloc(28); ((cptr)t2)[0] = integer_methods;
  t3 = integer_ialloc((cint)t2, (cint)AF_INET);
  subsock_AF_INET = t3;
  t4 = mem_malloc(28); ((cptr)t4)[0] = integer_methods;
  t5 = integer_ialloc((cint)t4, (cint)SOCK_STREAM);
  subsock_SOCK_STREAM = t5;
  t6 = mem_malloc(28); ((cptr)t6)[0] = integer_methods;
  t7 = integer_ialloc((cint)t6, (cint)SOCK_DGRAM);
  subsock_SOCK_DGRAM = t7;
  csock_initialize();
  t1_label: return t1;
}

cint subsock_fini(){
  cint t8;
  cstring_mem_free((cint)subsock_Buf);
  csock_finalize();
  t8_label: return t8;
}

cint subsock_alloc(cint subsock_self, cint subsock_soc){
  cint subsock_result;
  cint t9, t10;
  t10 = object_alloc((cint)subsock_self);
  subsock_result = t10;
  ((cptr)subsock_result)[7] /* csocket*/ = subsock_soc;
  ((cptr)subsock_result)[2] /* hashval*/ = 0;
  t9 = subsock_result;
  goto t9_label;
  t9_label: return t9;
}

cint subsock_reclaim(cint subsock_self){
  cint subsock_err;
  cint t11, t12, t13;
  t12 = ((cptr)subsock_self)[7] /* csocket*/ != 0;
  if (t12){
    subsock_err = csock_close((cint)((cptr)subsock_self)[7] /* csocket*/);
  };
  t13 = ((cptr)subsock_self)[2] /* hashval*/ != 0;
  if (t13){
    cstring_mem_free((cint)((cptr)subsock_self)[2] /* hashval*/);
  };
  object_reclaim((cint)subsock_self);
  t11_label: return t11;
}

cint subsock_as_cstring(cint subsock_str){
  cint subsock_result, subsock_siz, subsock_r, subsock_i;
  cint t14, t15, t17, t18, t19, t20;
  subsock_siz = ((cptr)subsock_str)[3] /* len*/;
  t15 = subsock_siz + 1;
  subsock_r = cstring_mem_malloc((cint)t15);
  for (subsock_i = 1; subsock_i <= subsock_siz; subsock_i++){
    t17 = subsock_i - 1;
    t18 = ((cptr)(((cptr)subsock_str)[0]))[62];
    t19 = ((f0)t18)((cint)subsock_str, (cint)subsock_i); /* lookup*/
    cstring_update_char((cint)subsock_r, (cint)t17, (cint)((cptr)t19)[2] /* hashval*/);
  };t16:;
  cstring_update_char((cint)subsock_r, (cint)subsock_siz, (cint)0);
  t14 = subsock_r;
  goto t14_label;
  t14_label: return t14;
}

cint subsock_bind_socket_to_port(cint subsock_self, cint subsock_sock_addr){
  cint subsock_result, subsock_err;
  cint t21, t22;
  subsock_result = boolean_False;
  subsock_err = csock_bind((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)((cptr)subsock_sock_addr)[2] /* hashval*/, (cint)((cptr)subsock_sock_addr)[3] /* len*/);
  t22 = subsock_err != 0;
  if (t22){
    subsock_result = boolean_True;
  };
  object_Dec_ref(subsock_self);
  object_Dec_ref(subsock_sock_addr);
  t21 = subsock_result;
  goto t21_label;
  t21_label: return t21;
}

cint subsock_close(cint subsock_self){
  cint subsock_result, subsock_err;
  cint t23, t24, t25;
  subsock_result = boolean_False;
  subsock_err = csock_setsockopt((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)SOL_SOCKET, (cint)SO_DONTLINGER, (cint)4);
  t24 = subsock_err == 0;
  if (t24){
    subsock_err = csock_close((cint)((cptr)subsock_self)[7] /* csocket*/);
  };
  t25 = subsock_err != 0;
  if (t25){
    subsock_result = boolean_True;
  };
  object_Dec_ref(subsock_self);
  t23 = subsock_result;
  goto t23_label;
  t23_label: return t23;
}

cint subsock_connect(cint subsock_self, cint subsock_sock_addr){
  cint subsock_result, subsock_err;
  cint t26, t27;
  subsock_result = boolean_False;
  subsock_err = csock_connect((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)((cptr)subsock_sock_addr)[2] /* hashval*/, (cint)((cptr)subsock_sock_addr)[3] /* len*/);
  t27 = subsock_err != 0;
  if (t27){
    subsock_result = boolean_True;
  };
  object_Dec_ref(subsock_self);
  object_Dec_ref(subsock_sock_addr);
  t26 = subsock_result;
  goto t26_label;
  t26_label: return t26;
}

cint subsock_error_message(){
  cint subsock_result, subsock_errstr;
  cint t28, t29, t30;
  subsock_errstr = csock_error_message();
  t29 = mem_malloc(40); ((cptr)t29)[0] = sstring_methods;
  t30 = sstring_alloc((cint)t29, (cint)cstring_strdupl((cint)subsock_errstr));
  t28 = t30;
  goto t28_label;
  t28_label: return t28;
}

cint subsock_get_connection_for_client(cint subsock_self){
  cint subsock_result, subsock_cs;
  cint t31, t32, t33, t34;
  subsock_cs = csock_accept((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)0, (cint)0);
  t32 = subsock_cs == INVALID_SOCKET;
  if (t32){
    subsock_result = object_Undefined;
  }else{
    t33 = mem_malloc(32); ((cptr)t33)[0] = subsock_methods;
    t34 = subsock_alloc((cint)t33, (cint)subsock_cs);
    subsock_result = t34;
  };
  object_Dec_ref(subsock_self);
  t31 = subsock_result;
  goto t31_label;
  t31_label: return t31;
}

cint subsock_host_address_for(cint subsock_name){
  cint subsock_result, subsock_hostaddr, subsock_name_str, subsock_err;
  cint t35, t36, t37, t38;
  subsock_hostaddr = cstring_mem_malloc((cint)16);
  subsock_name_str = subsock_as_cstring((cint)subsock_name);
  subsock_err = csock_host_name_to_address((cint)subsock_name_str, (cint)subsock_hostaddr);
  t36 = subsock_err != 0;
  if (t36){
    cstring_mem_free((cint)subsock_hostaddr);
    subsock_result = object_Undefined;
  }else{
    t37 = mem_malloc(40); ((cptr)t37)[0] = sstring_methods;
    t38 = sstring_alloc((cint)t37, (cint)subsock_hostaddr);
    subsock_result = t38;
  };
  cstring_mem_free((cint)subsock_name_str);
  object_Dec_ref(subsock_name);
  t35 = subsock_result;
  goto t35_label;
  t35_label: return t35;
}

cint subsock_host_name(){
  cint subsock_result, subsock_hostname, subsock_err;
  cint t39, t40, t41, t42, t43;
  t40 = MAXHOSTNAMELEN + 1;
  subsock_hostname = cstring_mem_malloc((cint)t40);
  subsock_err = csock_gethostname((cint)subsock_hostname, (cint)MAXHOSTNAMELEN);
  t41 = subsock_err == -1;
  if (t41){
    cstring_mem_free((cint)subsock_hostname);
    subsock_result = object_Undefined;
  }else{
    t42 = mem_malloc(40); ((cptr)t42)[0] = sstring_methods;
    t43 = sstring_alloc((cint)t42, (cint)subsock_hostname);
    subsock_result = t43;
  };
  t39 = subsock_result;
  goto t39_label;
  t39_label: return t39;
}

cint subsock_host_name_for(cint subsock_addr){
  cint subsock_result, subsock_hostname, subsock_addr_str, subsock_err;
  cint t44, t45, t46, t47, t48;
  t45 = MAXHOSTNAMELEN + 1;
  subsock_hostname = cstring_mem_malloc((cint)t45);
  subsock_addr_str = subsock_as_cstring((cint)subsock_addr);
  subsock_err = csock_host_address_to_name((cint)subsock_addr_str, (cint)subsock_hostname);
  t46 = subsock_err != 0;
  if (t46){
    cstring_mem_free((cint)subsock_hostname);
    subsock_result = object_Undefined;
  }else{
    t47 = mem_malloc(40); ((cptr)t47)[0] = sstring_methods;
    t48 = sstring_alloc((cint)t47, (cint)subsock_hostname);
    subsock_result = t48;
  };
  cstring_mem_free((cint)subsock_addr_str);
  object_Dec_ref(subsock_addr);
  t44 = subsock_result;
  goto t44_label;
  t44_label: return t44;
}

cint subsock_local_address(cint subsock_self){
  cint subsock_result, subsock_ad, subsock_err;
  cint t49, t50, t51, t52;
  subsock_ad = cstring_mem_malloc((cint)16);
  subsock_err = csock_local_address((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)subsock_ad);
  t50 = subsock_err == -1;
  if (t50){
    subsock_result = object_Undefined;
    cstring_mem_free((cint)subsock_ad);
  }else{
    t51 = mem_malloc(40); ((cptr)t51)[0] = sstring_methods;
    t52 = sstring_alloc((cint)t51, (cint)subsock_ad);
    subsock_result = t52;
  };
  object_Dec_ref(subsock_self);
  t49 = subsock_result;
  goto t49_label;
  t49_label: return t49;
}

cint subsock_local_address_family(cint subsock_self){
  cint subsock_result, subsock_af;
  cint t53, t54, t55, t56;
  subsock_af = csock_local_address_family((cint)((cptr)subsock_self)[7] /* csocket*/);
  t54 = subsock_af == -1;
  if (t54){
    subsock_result = object_Undefined;
  }else{
    t55 = mem_malloc(40); ((cptr)t55)[0] = sstring_methods;
    t56 = sstring_alloc((cint)t55, (cint)cstring_strdupl((cint)subsock_af));
    subsock_result = t56;
  };
  object_Dec_ref(subsock_self);
  t53 = subsock_result;
  goto t53_label;
  t53_label: return t53;
}

cint subsock_local_port_number(cint subsock_self){
  cint subsock_result, subsock_po;
  cint t57, t58, t59;
  subsock_po = csock_local_port_number((cint)((cptr)subsock_self)[7] /* csocket*/);
  t58 = mem_malloc(28); ((cptr)t58)[0] = integer_methods;
  t59 = integer_ialloc((cint)t58, (cint)subsock_po);
  subsock_result = t59;
  object_Dec_ref(subsock_self);
  t57 = subsock_result;
  goto t57_label;
  t57_label: return t57;
}

cint subsock_make_socket_addr(cint subsock_name, cint subsock_port, cint subsock_addrfam){
  cint subsock_result, subsock_str, subsock_sock_addr;
  cint t60, t61, t62, t63;
  subsock_str = subsock_as_cstring((cint)subsock_name);
  subsock_sock_addr = csock_make_socket_addr((cint)subsock_str, (cint)((cptr)subsock_port)[2] /* hashval*/, (cint)((cptr)subsock_addrfam)[2] /* hashval*/);
  t61 = subsock_sock_addr == -1;
  if (t61){
    subsock_result = object_Undefined;
  }else{
    t62 = mem_malloc(32); ((cptr)t62)[0] = subsock_methods;
    t63 = subsock_alloc((cint)t62, (cint)0);
    subsock_result = t63;
    ((cptr)subsock_result)[2] /* hashval*/ = subsock_sock_addr;
    ((cptr)subsock_result)[3] /* len*/ = csock_sizeof_sockaddr((cint)((cptr)subsock_addrfam)[2] /* hashval*/);
  };
  cstring_mem_free((cint)subsock_str);
  object_Dec_ref(subsock_name);
  object_Dec_ref(subsock_port);
  object_Dec_ref(subsock_addrfam);
  t60 = subsock_result;
  goto t60_label;
  t60_label: return t60;
}

cint subsock_new_socket(cint subsock_addrfam, cint subsock_socktype){
  cint subsock_result, subsock_cs;
  cint t64, t65, t66, t67;
  subsock_cs = csock_socket((cint)((cptr)subsock_addrfam)[2] /* hashval*/, (cint)((cptr)subsock_socktype)[2] /* hashval*/, (cint)0);
  t65 = subsock_cs == INVALID_SOCKET;
  if (t65){
    subsock_result = object_Undefined;
  }else{
    t66 = mem_malloc(32); ((cptr)t66)[0] = subsock_methods;
    t67 = subsock_alloc((cint)t66, (cint)subsock_cs);
    subsock_result = t67;
  };
  object_Dec_ref(subsock_addrfam);
  object_Dec_ref(subsock_socktype);
  t64 = subsock_result;
  goto t64_label;
  t64_label: return t64;
}

cint subsock_peer_address(cint subsock_self){
  cint subsock_result, subsock_ad, subsock_err;
  cint t68, t69, t70, t71;
  subsock_ad = cstring_mem_malloc((cint)16);
  subsock_err = csock_peer_address((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)subsock_ad);
  t69 = subsock_err == -1;
  if (t69){
    cstring_mem_free((cint)subsock_ad);
    subsock_result = object_Undefined;
  }else{
    t70 = mem_malloc(40); ((cptr)t70)[0] = sstring_methods;
    t71 = sstring_alloc((cint)t70, (cint)subsock_ad);
    subsock_result = t71;
  };
  object_Dec_ref(subsock_self);
  t68 = subsock_result;
  goto t68_label;
  t68_label: return t68;
}

cint subsock_peer_address_family(cint subsock_self){
  cint subsock_result, subsock_af;
  cint t72, t73, t74, t75;
  subsock_af = csock_peer_address_family((cint)((cptr)subsock_self)[7] /* csocket*/);
  t73 = subsock_af == -1;
  if (t73){
    subsock_result = object_Undefined;
  }else{
    t74 = mem_malloc(40); ((cptr)t74)[0] = sstring_methods;
    t75 = sstring_alloc((cint)t74, (cint)cstring_strdupl((cint)subsock_af));
    subsock_result = t75;
  };
  object_Dec_ref(subsock_self);
  t72 = subsock_result;
  goto t72_label;
  t72_label: return t72;
}

cint subsock_peer_port_number(cint subsock_self){
  cint subsock_result, subsock_po;
  cint t76, t77, t78;
  subsock_po = csock_peer_port_number((cint)((cptr)subsock_self)[7] /* csocket*/);
  t77 = mem_malloc(28); ((cptr)t77)[0] = integer_methods;
  t78 = integer_ialloc((cint)t77, (cint)subsock_po);
  subsock_result = t78;
  object_Dec_ref(subsock_self);
  t76 = subsock_result;
  goto t76_label;
  t76_label: return t76;
}

cint subsock_port_name_for(cint subsock_portnum){
  cint subsock_result, subsock_servname, subsock_err;
  cint t79, t80, t81, t82, t83;
  t80 = MAXHOSTNAMELEN + 1;
  subsock_servname = cstring_mem_malloc((cint)t80);
  subsock_err = csock_port_number_to_name((cint)((cptr)subsock_portnum)[2] /* hashval*/, (cint)subsock_servname);
  t81 = subsock_err == -1;
  if (t81){
    cstring_mem_free((cint)subsock_servname);
    subsock_result = object_Undefined;
  }else{
    t82 = mem_malloc(40); ((cptr)t82)[0] = sstring_methods;
    t83 = sstring_alloc((cint)t82, (cint)subsock_servname);
    subsock_result = t83;
  };
  object_Dec_ref(subsock_portnum);
  t79 = subsock_result;
  goto t79_label;
  t79_label: return t79;
}

cint subsock_port_number_for(cint subsock_name){
  cint subsock_result, subsock_name_str, subsock_port_num;
  cint t84, t85, t86, t87;
  subsock_name_str = subsock_as_cstring((cint)subsock_name);
  subsock_port_num = csock_port_number_for((cint)subsock_name_str);
  t85 = subsock_port_num == -1;
  if (t85){
    subsock_result = object_Undefined;
  }else{
    t86 = mem_malloc(28); ((cptr)t86)[0] = integer_methods;
    t87 = integer_ialloc((cint)t86, (cint)subsock_port_num);
    subsock_result = t87;
  };
  object_Dec_ref(subsock_name);
  t84 = subsock_result;
  goto t84_label;
  t84_label: return t84;
}

cint subsock_read(cint subsock_self){
  cint subsock_result, subsock_i, subsock_str, subsock_j, subsock_ch;
  cint t88, t89, t90, t92, t93, t94, t95, t97, t98, t99, t100;
  subsock_i = csock_read((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)subsock_Buf, (cint)65536, (cint)0);
  t89 = subsock_i < 1;
  if (t89){
    object_Dec_ref(subsock_self);
    t88 = object_Undefined;
    goto t88_label;
  };
  t90 = subsock_i + 1;
  subsock_str = cstring_mem_malloc((cint)t90);
  t92 = subsock_i - 1;
  for (subsock_j = 0; subsock_j <= t92; subsock_j++){
    subsock_ch = cstring_lookup_char((cint)subsock_Buf, (cint)subsock_j);
    t93 = subsock_ch == 0;
    if (t93){
      cstring_update_char((cint)subsock_str, (cint)subsock_j, (cint)1);
    }else{
      cstring_update_char((cint)subsock_str, (cint)subsock_j, (cint)cstring_lookup_char((cint)subsock_Buf, (cint)subsock_j));
    };
  };t91:;
  cstring_update_char((cint)subsock_str, (cint)subsock_i, (cint)0);
  t94 = mem_malloc(40); ((cptr)t94)[0] = sstring_methods;
  t95 = sstring_alloc((cint)t94, (cint)subsock_str);
  subsock_result = t95;
  t97 = subsock_i - 1;
  for (subsock_j = 0; subsock_j <= t97; subsock_j++){
    subsock_ch = cstring_lookup_char((cint)subsock_Buf, (cint)subsock_j);
    t98 = subsock_ch == 0;
    if (t98){
      t99 = subsock_j + 1;
      t100 = (cptr)(((cptr)(((cptr)subsock_result)[0]))[130]); /* update*/
      ((f0)t100)((cint)subsock_result, (cint)t99, (cint)0);
    };
  };t96:;
  object_Dec_ref(subsock_self);
  t88 = subsock_result;
  goto t88_label;
  t88_label: return t88;
}

cint subsock_readable(cint subsock_s, cint subsock_timeout){
  cint subsock_result, subsock_cs, subsock_i, subsock_ss, subsock_num;
  cint t101, t102, t103, t105, t106, t107, t108, t109;
  t102 = ((cptr)subsock_s)[3] /* len*/ + 1;
  t103 = 4 * t102;
  subsock_cs = cobarray_mem_malloc((cint)t103);
  for (subsock_i = 1; subsock_i <= ((cptr)subsock_s)[3] /* len*/; subsock_i++){
    t105 = ((cptr)(((cptr)subsock_s)[0]))[62];
    t106 = ((f0)t105)((cint)subsock_s, (cint)subsock_i); /* lookup*/
    subsock_ss = t106;
    t108 = subsock_i - 1;
    ((cptr)(subsock_cs))[t108] = ((cptr)subsock_ss)[7] /* csocket*/;
  };t104:;
  ((cptr)(subsock_cs))[((cptr)subsock_s)[3] /* len*/] = NULL;
  subsock_num = csock_readable((cint)subsock_cs, (cint)((cptr)subsock_timeout)[2] /* hashval*/);
  subsock_result = boolean_False;
  t109 = subsock_num > 0;
  if (t109){
    subsock_result = boolean_True;
  };
  object_Dec_ref(subsock_s);
  object_Dec_ref(subsock_timeout);
  t101 = subsock_result;
  goto t101_label;
  t101_label: return t101;
}

cint subsock_set_number_of_clients(cint subsock_self, cint subsock_numclients){
  cint subsock_result, subsock_err;
  cint t110, t111;
  subsock_result = boolean_False;
  subsock_err = csock_listen((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)((cptr)subsock_numclients)[2] /* hashval*/);
  t111 = subsock_err == -1;
  if (t111){
    subsock_result = boolean_True;
  };
  object_Dec_ref(subsock_self);
  object_Dec_ref(subsock_numclients);
  t110 = subsock_result;
  goto t110_label;
  t110_label: return t110;
}

cint subsock_write(cint subsock_self, cint subsock_msg, cint subsock_dest_addr){
  cint subsock_result, subsock_m, subsock_n, subsock_k, subsock_i;
  cint t112, t115, t116, t117, t118, t119, t120, t121, t122, t123, t124;
  subsock_m = subsock_as_cstring((cint)subsock_msg);
  subsock_n = ((cptr)subsock_msg)[3] /* len*/;
  subsock_k = 0;
  t113:
  t115 = subsock_k < subsock_n;
  if (!t115) goto t114;
    t116 = subsock_dest_addr == 0;
    if (t116){
      t117 = subsock_m + subsock_k;
      t118 = ((cptr)subsock_msg)[3] /* len*/ - subsock_k;
      subsock_i = csock_write((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)t117, (cint)t118, (cint)0);
    }else{
      t119 = subsock_m + subsock_k;
      t120 = ((cptr)subsock_msg)[3] /* len*/ - subsock_k;
      subsock_i = csock_sendto((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)t119, (cint)t120, (cint)0, (cint)((cptr)subsock_dest_addr)[2] /* hashval*/, (cint)((cptr)subsock_dest_addr)[3] /* len*/);
    };
    t121 = subsock_i < 0;
    if (t121){
      goto t114;
    };
    t122 = subsock_k + subsock_i;
    subsock_k = t122;
  goto t113;
  t114:;
  subsock_result = boolean_False;
  t123 = subsock_k < subsock_n;
  if (t123){
    subsock_result = boolean_True;
  };
  object_Dec_ref(subsock_self);
  object_Dec_ref(subsock_msg);
  t124 = subsock_dest_addr != 0;
  if (t124){
    object_Dec_ref(subsock_dest_addr);
  };
  t112 = subsock_result;
  goto t112_label;
  t112_label: return t112;
}

cint subsock_writeable(cint subsock_s, cint subsock_timeout){
  cint subsock_result, subsock_cs, subsock_i, subsock_ss, subsock_num;
  cint t125, t126, t127, t129, t130, t131, t132, t133;
  t126 = ((cptr)subsock_s)[3] /* len*/ + 1;
  t127 = 4 * t126;
  subsock_cs = cobarray_mem_malloc((cint)t127);
  for (subsock_i = 1; subsock_i <= ((cptr)subsock_s)[3] /* len*/; subsock_i++){
    t129 = ((cptr)(((cptr)subsock_s)[0]))[62];
    t130 = ((f0)t129)((cint)subsock_s, (cint)subsock_i); /* lookup*/
    subsock_ss = t130;
    t132 = subsock_i - 1;
    ((cptr)(subsock_cs))[t132] = ((cptr)subsock_ss)[7] /* csocket*/;
  };t128:;
  ((cptr)(subsock_cs))[((cptr)subsock_s)[3] /* len*/] = NULL;
  subsock_num = csock_writeable((cint)subsock_cs, (cint)((cptr)subsock_timeout)[2] /* hashval*/);
  subsock_result = boolean_False;
  t133 = subsock_num > 0;
  if (t133){
    subsock_result = boolean_True;
  };
  object_Dec_ref(subsock_s);
  object_Dec_ref(subsock_timeout);
  t125 = subsock_result;
  goto t125_label;
  t125_label: return t125;
}

cint subsock_udp_read(cint subsock_self){
  cint subsock_result, subsock_sa, subsock_sp, subsock_i, subsock_str, subsock_j, subsock_ch, subsock_msg, subsock_send_a, subsock_send_p;
  cint t134, t135, t136, t138, t139, t140, t141, t143, t144, t145, t146, t147, t148, t149, t150, t151, t152, t153, t154, t155, t156, t157, t158, t159, t160, t161;
  subsock_sa = cstring_mem_malloc((cint)16);
  subsock_sp = cobarray_mem_malloc((cint)4);
  subsock_i = csock_udp_read((cint)((cptr)subsock_self)[7] /* csocket*/, (cint)subsock_Buf, (cint)subsock_sa, (cint)subsock_sp);
  t135 = subsock_i < 1;
  if (t135){
    cstring_mem_free((cint)subsock_sa);
    object_Dec_ref(subsock_self);
    t134 = object_Undefined;
    goto t134_label;
  };
  t136 = subsock_i + 1;
  subsock_str = cstring_mem_malloc((cint)t136);
  t138 = subsock_i - 1;
  for (subsock_j = 0; subsock_j <= t138; subsock_j++){
    subsock_ch = cstring_lookup_char((cint)subsock_Buf, (cint)subsock_j);
    t139 = subsock_ch == 0;
    if (t139){
      cstring_update_char((cint)subsock_str, (cint)subsock_j, (cint)1);
    }else{
      cstring_update_char((cint)subsock_str, (cint)subsock_j, (cint)cstring_lookup_char((cint)subsock_Buf, (cint)subsock_j));
    };
  };t137:;
  cstring_update_char((cint)subsock_str, (cint)subsock_i, (cint)0);
  t140 = mem_malloc(40); ((cptr)t140)[0] = sstring_methods;
  t141 = sstring_alloc((cint)t140, (cint)subsock_str);
  subsock_msg = t141;
  t143 = subsock_i - 1;
  for (subsock_j = 0; subsock_j <= t143; subsock_j++){
    subsock_ch = cstring_lookup_char((cint)subsock_Buf, (cint)subsock_j);
    t144 = subsock_ch == 0;
    if (t144){
      t145 = subsock_j + 1;
      t146 = (cptr)(((cptr)(((cptr)subsock_msg)[0]))[130]); /* update*/
      ((f0)t146)((cint)subsock_msg, (cint)t145, (cint)0);
    };
  };t142:;
  t147 = mem_malloc(40); ((cptr)t147)[0] = sstring_methods;
  t148 = sstring_alloc((cint)t147, (cint)subsock_sa);
  subsock_send_a = t148;
  t149 = mem_malloc(28); ((cptr)t149)[0] = integer_methods;
  t150 = integer_ialloc((cint)t149, (cint)((cptr)(subsock_sp))[0]);
  subsock_send_p = t150;
  t151 = mem_malloc(40); ((cptr)t151)[0] = slist_methods;
  t152 = slist_alloc((cint)t151, (cint)1);
  ((cptr)t152)[1] += 1;
  t155 = ((cptr)(((cptr)t152)[0]))[7];
  t154 = ((f0)t155)((cint)t152, (cint)subsock_msg); /* Append*/
  ((cptr)t154)[1] += 1;
  t158 = ((cptr)(((cptr)t154)[0]))[7];
  t157 = ((f0)t158)((cint)t154, (cint)subsock_send_a); /* Append*/
  ((cptr)t157)[1] += 1;
  t159 = ((cptr)(((cptr)t157)[0]))[7];
  t160 = ((f0)t159)((cint)t157, (cint)subsock_send_p); /* Append*/
  subsock_result = t160;
  cobarray_mem_free((cint)subsock_sp);
  object_Dec_ref(subsock_self);
  t134 = subsock_result;
  goto t134_label;
  t134_label: return t134;
}

void init_subsock(){
  copy_meth_table(subsock_methods, object_methods);
  subsock_methods[0] = 32;
  subsock_methods[1] = subsock_init;
  subsock_methods[2] = subsock_fini;
  subsock_methods[3] = subsock_alloc;
  subsock_methods[4] = subsock_reclaim;
  subsock_methods[131] = subsock_as_cstring;
  subsock_methods[356] = subsock_bind_socket_to_port;
  subsock_methods[329] = subsock_close;
  subsock_methods[330] = subsock_connect;
  subsock_methods[338] = subsock_error_message;
  subsock_methods[357] = subsock_get_connection_for_client;
  subsock_methods[358] = subsock_host_address_for;
  subsock_methods[359] = subsock_host_name;
  subsock_methods[360] = subsock_host_name_for;
  subsock_methods[343] = subsock_local_address;
  subsock_methods[344] = subsock_local_address_family;
  subsock_methods[345] = subsock_local_port_number;
  subsock_methods[346] = subsock_make_socket_addr;
  subsock_methods[361] = subsock_new_socket;
  subsock_methods[347] = subsock_peer_address;
  subsock_methods[348] = subsock_peer_address_family;
  subsock_methods[349] = subsock_peer_port_number;
  subsock_methods[362] = subsock_port_name_for;
  subsock_methods[350] = subsock_port_number_for;
  subsock_methods[333] = subsock_read;
  subsock_methods[352] = subsock_readable;
  subsock_methods[363] = subsock_set_number_of_clients;
  subsock_methods[337] = subsock_write;
  subsock_methods[355] = subsock_writeable;
  subsock_methods[354] = subsock_udp_read;
}
