ves_icall_System_Net_Sockets_Socket_Socket_internal (struct MonoObject * this, gint32 family, gint32 type, gint32 proto, gint32 * error)
{
  void * D.19075;
  int D.19082;
  _Bool D.19083;
  _Bool D.19084;
  _Bool D.19085;
  long unsigned int D.19088;
  _Bool D.19089;
  _Bool D.19090;
  SOCKET sock;
  gint32 sock_family;
  gint32 sock_proto;
  gint32 sock_type;

  *error = 0;
  sock_family = convert_family (family);
  if (sock_family == -1) goto <D.19073>; else goto <D.19074>;
  <D.19073>:
  *error = 10047;
  D.19075 = 0B;
  return D.19075;
  <D.19074>:
  sock_proto = convert_proto (proto);
  if (sock_proto == -1) goto <D.19076>; else goto <D.19077>;
  <D.19076>:
  *error = 10043;
  D.19075 = 0B;
  return D.19075;
  <D.19077>:
  sock_type = convert_type (type);
  if (sock_type == -1) goto <D.19078>; else goto <D.19079>;
  <D.19078>:
  *error = 10044;
  D.19075 = 0B;
  return D.19075;
  <D.19079>:
  sock = _wapi_socket (sock_family, sock_type, sock_proto, 0B, 0, 1);
  if (sock == 4294967295) goto <D.19080>; else goto <D.19081>;
  <D.19080>:
  D.19082 = WSAGetLastError ();
  *error = D.19082;
  D.19075 = 0B;
  return D.19075;
  <D.19081>:
  D.19083 = sock_family == 2;
  D.19084 = sock_type == 2;
  D.19085 = D.19083 & D.19084;
  if (D.19085 != 0) goto <D.19086>; else goto <D.19087>;
  <D.19086>:
  D.19088 = (long unsigned int) sock;
  D.19075 = (void *) D.19088;
  return D.19075;
  <D.19087>:
  D.19089 = sock_family == 10;
  D.19084 = sock_type == 2;
  D.19090 = D.19089 & D.19084;
  if (D.19090 != 0) goto <D.19091>; else goto <D.19092>;
  <D.19091>:
  D.19088 = (long unsigned int) sock;
  D.19075 = (void *) D.19088;
  return D.19075;
  <D.19092>:
  D.19088 = (long unsigned int) sock;
  D.19075 = (void *) D.19088;
  return D.19075;
}


convert_family (MonoAddressFamily mono_family)
{
  gint32 D.19094;
  gint32 family;

  family = -1;
  switch (mono_family) <default: <D.18336>, case -1: <D.18307>, case 0: <D.18327>, case 1: <D.18328>, case 2: <D.18329>, case 3: <D.18308>, case 4: <D.18309>, case 5: <D.18310>, case 6: <D.18330>, case 7: <D.18311>, case 8: <D.18312>, case 9: <D.18313>, case 10: <D.18314>, case 11: <D.18331>, case 12: <D.18332>, case 13: <D.18315>, case 14: <D.18316>, case 15: <D.18317>, case 16: <D.18333>, case 17: <D.18318>, case 18: <D.18319>, case 19: <D.18320>, case 21: <D.18321>, case 22: <D.18322>, case 23: <D.18334>, case 24: <D.18323>, case 25: <D.18324>, case 26: <D.18335>, case 28: <D.18325>>
  <D.18307>:
  <D.18308>:
  <D.18309>:
  <D.18310>:
  <D.18311>:
  <D.18312>:
  <D.18313>:
  <D.18314>:
  <D.18315>:
  <D.18316>:
  <D.18317>:
  <D.18318>:
  <D.18319>:
  <D.18320>:
  <D.18321>:
  <D.18322>:
  <D.18323>:
  <D.18324>:
  <D.18325>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unsupported value 0x%x", mono_family);
  goto <D.18326>;
  <D.18327>:
  family = 0;
  goto <D.18326>;
  <D.18328>:
  family = 1;
  goto <D.18326>;
  <D.18329>:
  family = 2;
  goto <D.18326>;
  <D.18330>:
  family = 4;
  goto <D.18326>;
  <D.18331>:
  family = 22;
  goto <D.18326>;
  <D.18332>:
  family = 12;
  goto <D.18326>;
  <D.18333>:
  family = 5;
  goto <D.18326>;
  <D.18334>:
  family = 10;
  goto <D.18326>;
  <D.18335>:
  family = 23;
  goto <D.18326>;
  <D.18336>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unknown value 0x%x", mono_family);
  <D.18326>:
  D.19094 = family;
  return D.19094;
}


convert_proto (MonoProtocolType mono_proto)
{
  gint32 D.19096;
  gint32 proto;

  proto = -1;
  switch (mono_proto) <default: <D.18384>, case -1: <D.18383>, case 0: <D.18368>, case 1: <D.18370>, case 2: <D.18371>, case 3: <D.18372>, case 6: <D.18373>, case 12: <D.18374>, case 17: <D.18375>, case 22: <D.18376>, case 41: <D.18369>, case 77: <D.18378>, case 255: <D.18379>, case 1000: <D.18380>, case 1256: <D.18381>, case 1257: <D.18382>>
  <D.18368>:
  <D.18369>:
  <D.18370>:
  <D.18371>:
  <D.18372>:
  <D.18373>:
  <D.18374>:
  <D.18375>:
  <D.18376>:
  proto = mono_proto;
  goto <D.18377>;
  <D.18378>:
  <D.18379>:
  <D.18380>:
  <D.18381>:
  <D.18382>:
  <D.18383>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.ProtocolType has unsupported value 0x%x", mono_proto);
  goto <D.18377>;
  <D.18384>:
  goto <D.18377>;
  <D.18377>:
  D.19096 = proto;
  return D.19096;
}


convert_type (MonoSocketType mono_type)
{
  gint32 D.19099;
  gint32 type;

  type = -1;
  switch (mono_type) <default: <D.18363>, case -1: <D.18362>, case 1: <D.18356>, case 2: <D.18358>, case 3: <D.18359>, case 4: <D.18360>, case 5: <D.18361>>
  <D.18356>:
  type = 1;
  goto <D.18357>;
  <D.18358>:
  type = 2;
  goto <D.18357>;
  <D.18359>:
  type = 3;
  goto <D.18357>;
  <D.18360>:
  type = 4;
  goto <D.18357>;
  <D.18361>:
  type = 5;
  goto <D.18357>;
  <D.18362>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unsupported value 0x%x", mono_type);
  goto <D.18357>;
  <D.18363>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unknown value 0x%x", mono_type);
  <D.18357>:
  D.19099 = type;
  return D.19099;
}


ves_icall_System_Net_Sockets_Socket_Close_internal (SOCKET sock, gint32 * error)
{
  int sock.0;

  *error = 0;
  sock.0 = (int) sock;
  mono_thread_pool_remove_socket (sock.0);
  closesocket (sock);
}


ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal ()
{
  gint32 D.19102;

  D.19102 = WSAGetLastError ();
  return D.19102;
}


ves_icall_System_Net_Sockets_Socket_Available_internal (SOCKET sock, gint32 * error)
{
  int D.19106;
  gint32 D.19107;
  int ret;
  int amount;

  try
    {
      *error = 0;
      ret = ioctlsocket (sock, 21531, &amount);
      if (ret == -1) goto <D.19104>; else goto <D.19105>;
      <D.19104>:
      D.19106 = WSAGetLastError ();
      *error = D.19106;
      D.19107 = 0;
      return D.19107;
      <D.19105>:
      D.19107 = amount;
      return D.19107;
    }
  finally
    {
      amount = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Blocking_internal (SOCKET sock, gboolean block, gint32 * error)
{
  int block.1;
  _Bool D.19111;
  int block.2;
  int D.19115;
  int ret;

  *error = 0;
  block.1 = block;
  D.19111 = block.1 == 0;
  block.2 = (int) D.19111;
  block = block.2;
  ret = ioctlsocket (sock, 21537, &block);
  if (ret == -1) goto <D.19113>; else goto <D.19114>;
  <D.19113>:
  D.19115 = WSAGetLastError ();
  *error = D.19115;
  <D.19114>:
}


ves_icall_System_Net_Sockets_Socket_Accept_internal (SOCKET sock, gint32 * error, gboolean blocking)
{
  int D.19118;
  void * D.19119;
  long unsigned int D.19120;
  SOCKET newsock;

  *error = 0;
  newsock = _wapi_accept (sock, 0B, 0B);
  if (newsock == 4294967295) goto <D.19116>; else goto <D.19117>;
  <D.19116>:
  D.19118 = WSAGetLastError ();
  *error = D.19118;
  D.19119 = 0B;
  return D.19119;
  <D.19117>:
  D.19120 = (long unsigned int) newsock;
  D.19119 = (void *) D.19120;
  return D.19119;
}


ves_icall_System_Net_Sockets_Socket_Listen_internal (SOCKET sock, guint32 backlog, gint32 * error)
{
  int backlog.3;
  int D.19125;
  int ret;

  *error = 0;
  backlog.3 = (int) backlog;
  ret = _wapi_listen (sock, backlog.3);
  if (ret == -1) goto <D.19123>; else goto <D.19124>;
  <D.19123>:
  D.19125 = WSAGetLastError ();
  *error = D.19125;
  <D.19124>:
}


ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.19126;
  int D.19127;
  unsigned int salen.4;
  unsigned int salen.5;
  struct MonoObject * D.19132;
  gchar * iftmp.6;
  long unsigned int D.19136;
  long unsigned int D.19138;
  int D.19141;
  int salen.7;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.19126 = convert_family (af);
      D.19127 = get_sockaddr_size (D.19126);
      salen.4 = (unsigned int) D.19127;
      salen = salen.4;
      salen.5 = salen;
      if (salen.5 == 0) goto <D.19130>; else goto <D.19131>;
      <D.19130>:
      *error = 10047;
      D.19132 = 0B;
      return D.19132;
      <D.19131>:
      salen.5 = salen;
      if (salen.5 <= 128) goto <D.19134>; else goto <D.19135>;
      <D.19134>:
      salen.5 = salen;
      D.19136 = (long unsigned int) salen.5;
      iftmp.6 = __builtin_alloca (D.19136);
      goto <D.19137>;
      <D.19135>:
      salen.5 = salen;
      D.19138 = (long unsigned int) salen.5;
      iftmp.6 = monoeg_malloc0 (D.19138);
      <D.19137>:
      sa = iftmp.6;
      ret = _wapi_getsockname (sock, sa, &salen);
      if (ret == -1) goto <D.19139>; else goto <D.19140>;
      <D.19139>:
      D.19141 = WSAGetLastError ();
      *error = D.19141;
      salen.5 = salen;
      if (salen.5 > 128) goto <D.19142>; else goto <D.19143>;
      <D.19142>:
      monoeg_g_free (sa);
      <D.19143>:
      D.19132 = 0B;
      return D.19132;
      <D.19140>:
      salen.5 = salen;
      salen.7 = (int) salen.5;
      result = create_object_from_sockaddr (sa, salen.7, error);
      salen.5 = salen;
      if (salen.5 > 128) goto <D.19145>; else goto <D.19146>;
      <D.19145>:
      monoeg_g_free (sa);
      <D.19146>:
      D.19132 = result;
      return D.19132;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


get_sockaddr_size (int family)
{
  int D.19157;
  int size;

  size = 0;
  if (family == 2) goto <D.19149>; else goto <D.19150>;
  <D.19149>:
  size = 16;
  goto <D.19151>;
  <D.19150>:
  if (family == 10) goto <D.19152>; else goto <D.19153>;
  <D.19152>:
  size = 28;
  goto <D.19154>;
  <D.19153>:
  if (family == 1) goto <D.19155>; else goto <D.19156>;
  <D.19155>:
  size = 110;
  <D.19156>:
  <D.19154>:
  <D.19151>:
  D.19157 = size;
  return D.19157;
}


create_object_from_sockaddr (struct sockaddr * saddr, int sa_size, gint32 * error)
{
  struct MonoClass * D.19159;
  struct MonoImage * D.19162;
  struct MonoClass * D.19163;
  _Bool D.19164;
  long int D.19165;
  long int D.19166;
  struct MonoClassField * D.19169;
  struct MonoClassField * D.19172;
  _Bool D.19173;
  long int D.19174;
  long int D.19175;
  int D.19178;
  long unsigned int D.19179;
  struct MonoClass * D.18553;
  struct MonoClass * tmp_klass.8;
  struct MonoClass * D.19183;
  struct MonoClass * tmp_klass.9;
  _Bool D.19185;
  long int D.19186;
  long int D.19187;
  struct MonoVTable * D.19190;
  short unsigned int D.19191;
  int D.19192;
  struct MonoObject * D.19195;
  unsigned char D.19196;
  int D.19197;
  unsigned char D.19198;
  short unsigned int port.10;
  int D.19201;
  int D.19202;
  short unsigned int D.19205;
  signed short D.19206;
  int D.19207;
  signed short D.19208;
  signed short D.19209;
  unsigned int D.19211;
  struct MonoImage * D.19214;
  struct MonoException * D.19215;
  short unsigned int D.19216;
  unsigned char D.19217;
  unsigned char D.19218;
  unsigned int D.19219;
  unsigned char D.19220;
  unsigned int D.19221;
  unsigned char D.19222;
  unsigned int D.19223;
  unsigned char D.19224;
  unsigned char D.19225;
  short unsigned int port.11;
  int D.19228;
  int D.19229;
  short unsigned int D.19232;
  signed short D.19233;
  int D.19234;
  signed short D.19235;
  signed short D.19236;
  struct MonoImage * D.19240;
  struct MonoException * D.19241;
  short unsigned int D.19242;
  unsigned char D.19243;
  unsigned char D.19244;
  struct in6_addr * D.19245;
  int D.19246;
  int D.19249;
  long unsigned int D.19250;
  unsigned char D.19252;
  unsigned int D.19253;
  unsigned char D.19254;
  unsigned int D.19255;
  unsigned char D.19256;
  unsigned int D.19257;
  unsigned char D.19258;
  unsigned int D.19259;
  unsigned char D.19260;
  int D.19263;
  long unsigned int D.19264;
  char D.19265;
  unsigned char D.19266;
  struct MonoDomain * domain;
  struct MonoObject * sockaddr_obj;
  struct MonoArray * data;
  MonoAddressFamily family;

  domain = mono_domain_get ();
  D.19159 = domain->sockaddr_class;
  if (D.19159 == 0B) goto <D.19160>; else goto <D.19161>;
  <D.19160>:
  D.19162 = get_socket_assembly ();
  D.19163 = mono_class_from_name (D.19162, "System.Net", "SocketAddress");
  domain->sockaddr_class = D.19163;
  D.19159 = domain->sockaddr_class;
  D.19164 = D.19159 == 0B;
  D.19165 = (long int) D.19164;
  D.19166 = __builtin_expect (D.19165, 0);
  if (D.19166 != 0) goto <D.19167>; else goto <D.19168>;
  <D.19167>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 935, "domain->sockaddr_class");
  <D.19168>:
  <D.19161>:
  D.19159 = domain->sockaddr_class;
  sockaddr_obj = mono_object_new (domain, D.19159);
  D.19169 = domain->sockaddr_data_field;
  if (D.19169 == 0B) goto <D.19170>; else goto <D.19171>;
  <D.19170>:
  D.19159 = domain->sockaddr_class;
  D.19172 = mono_class_get_field_from_name (D.19159, "data");
  domain->sockaddr_data_field = D.19172;
  D.19169 = domain->sockaddr_data_field;
  D.19173 = D.19169 == 0B;
  D.19174 = (long int) D.19173;
  D.19175 = __builtin_expect (D.19174, 0);
  if (D.19175 != 0) goto <D.19176>; else goto <D.19177>;
  <D.19176>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 942, "domain->sockaddr_data_field");
  <D.19177>:
  <D.19171>:
  D.19178 = sa_size + 2;
  D.19179 = (long unsigned int) D.19178;
  {
    static struct MonoClass * tmp_klass;

    {
      tmp_klass.8 = tmp_klass;
      if (tmp_klass.8 == 0B) goto <D.19181>; else goto <D.19182>;
      <D.19181>:
      D.19183 = mono_get_byte_class ();
      tmp_klass.9 = mono_array_class_get (D.19183, 1);
      tmp_klass = tmp_klass.9;
      tmp_klass.8 = tmp_klass;
      D.19185 = tmp_klass.8 == 0B;
      D.19186 = (long int) D.19185;
      D.19187 = __builtin_expect (D.19186, 0);
      if (D.19187 != 0) goto <D.19188>; else goto <D.19189>;
      <D.19188>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 949, "tmp_klass");
      <D.19189>:
      <D.19182>:
    }
    D.18553 = tmp_klass;
  }
  D.19190 = mono_class_vtable (domain, D.18553);
  data = mono_array_new_specific (D.19190, D.19179);
  D.19191 = saddr->sa_family;
  D.19192 = (int) D.19191;
  family = convert_to_mono_family (D.19192);
  if (family == -1) goto <D.19193>; else goto <D.19194>;
  <D.19193>:
  *error = 10047;
  D.19195 = 0B;
  return D.19195;
  <D.19194>:
  {
    guint8 * __p;

    __p = mono_array_addr_with_size (data, 1, 0);
    D.19196 = (unsigned char) family;
    *__p = D.19196;
  }
  {
    guint8 * __p;

    __p = mono_array_addr_with_size (data, 1, 1);
    D.19197 = family >> 8;
    D.19198 = (unsigned char) D.19197;
    *__p = D.19198;
  }
  D.19191 = saddr->sa_family;
  if (D.19191 == 2) goto <D.19199>; else goto <D.19200>;
  <D.19199>:
  {
    struct sockaddr_in * sa_in;
    guint16 port;
    guint32 address;

    sa_in = saddr;
    {
      short unsigned int __v;
      short unsigned int __x;

      __x = sa_in->sin_port;
      {
        D.19201 = (int) __x;
        D.19202 = __builtin_constant_p (D.19201);
        if (D.19202 != 0) goto <D.19203>; else goto <D.19204>;
        <D.19203>:
        D.19205 = __x >> 8;
        D.19206 = (signed short) D.19205;
        D.19201 = (int) __x;
        D.19207 = D.19201 << 8;
        D.19208 = (signed short) D.19207;
        D.19209 = D.19206 | D.19208;
        __v = (short unsigned int) D.19209;
        goto <D.19210>;
        <D.19204>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.19210>:
      }
      port.10 = __v;
    }
    port = port.10;
    D.19211 = sa_in->sin_addr.s_addr;
    address = __bswap_32 (D.19211);
    if (sa_size <= 7) goto <D.19212>; else goto <D.19213>;
    <D.19212>:
    D.19214 = mono_get_corlib ();
    D.19215 = mono_exception_from_name (D.19214, "System", "SystemException");
    mono_raise_exception (D.19215);
    <D.19213>:
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 2);
      D.19216 = port >> 8;
      D.19217 = (unsigned char) D.19216;
      *__p = D.19217;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 3);
      D.19218 = (unsigned char) port;
      *__p = D.19218;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 4);
      D.19219 = address >> 24;
      D.19220 = (unsigned char) D.19219;
      *__p = D.19220;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 5);
      D.19221 = address >> 16;
      D.19222 = (unsigned char) D.19221;
      *__p = D.19222;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 6);
      D.19223 = address >> 8;
      D.19224 = (unsigned char) D.19223;
      *__p = D.19224;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 7);
      D.19225 = (unsigned char) address;
      *__p = D.19225;
    }
    D.19169 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.19169, data);
    D.19195 = sockaddr_obj;
    return D.19195;
  }
  <D.19200>:
  D.19191 = saddr->sa_family;
  if (D.19191 == 10) goto <D.19226>; else goto <D.19227>;
  <D.19226>:
  {
    struct sockaddr_in6 * sa_in;
    int i;
    guint16 port;

    sa_in = saddr;
    {
      short unsigned int __v;
      short unsigned int __x;

      __x = sa_in->sin6_port;
      {
        D.19228 = (int) __x;
        D.19229 = __builtin_constant_p (D.19228);
        if (D.19229 != 0) goto <D.19230>; else goto <D.19231>;
        <D.19230>:
        D.19232 = __x >> 8;
        D.19233 = (signed short) D.19232;
        D.19228 = (int) __x;
        D.19234 = D.19228 << 8;
        D.19235 = (signed short) D.19234;
        D.19236 = D.19233 | D.19235;
        __v = (short unsigned int) D.19236;
        goto <D.19237>;
        <D.19231>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.19237>:
      }
      port.11 = __v;
    }
    port = port.11;
    if (sa_size <= 27) goto <D.19238>; else goto <D.19239>;
    <D.19238>:
    D.19240 = mono_get_corlib ();
    D.19241 = mono_exception_from_name (D.19240, "System", "SystemException");
    mono_raise_exception (D.19241);
    <D.19239>:
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 2);
      D.19242 = port >> 8;
      D.19243 = (unsigned char) D.19242;
      *__p = D.19243;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 3);
      D.19244 = (unsigned char) port;
      *__p = D.19244;
    }
    D.19245 = &sa_in->sin6_addr;
    D.19246 = is_ipv4_mapped_any (D.19245);
    if (D.19246 != 0) goto <D.19247>; else goto <D.19248>;
    <D.19247>:
    i = 0;
    goto <D.18578>;
    <D.18577>:
    {
      guint8 * __p;

      D.19249 = i + 8;
      D.19250 = (long unsigned int) D.19249;
      __p = mono_array_addr_with_size (data, 1, D.19250);
      *__p = 0;
    }
    i = i + 1;
    <D.18578>:
    if (i <= 15) goto <D.18577>; else goto <D.18579>;
    <D.18579>:
    goto <D.19251>;
    <D.19248>:
    i = 0;
    goto <D.18582>;
    <D.18581>:
    {
      guint8 * __p;

      D.19249 = i + 8;
      D.19250 = (long unsigned int) D.19249;
      __p = mono_array_addr_with_size (data, 1, D.19250);
      D.19252 = sa_in->sin6_addr.__in6_u.__u6_addr8[i];
      *__p = D.19252;
    }
    i = i + 1;
    <D.18582>:
    if (i <= 15) goto <D.18581>; else goto <D.18583>;
    <D.18583>:
    <D.19251>:
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 24);
      D.19253 = sa_in->sin6_scope_id;
      D.19254 = (unsigned char) D.19253;
      *__p = D.19254;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 25);
      D.19253 = sa_in->sin6_scope_id;
      D.19255 = D.19253 >> 8;
      D.19256 = (unsigned char) D.19255;
      *__p = D.19256;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 26);
      D.19253 = sa_in->sin6_scope_id;
      D.19257 = D.19253 >> 16;
      D.19258 = (unsigned char) D.19257;
      *__p = D.19258;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 27);
      D.19253 = sa_in->sin6_scope_id;
      D.19259 = D.19253 >> 24;
      D.19260 = (unsigned char) D.19259;
      *__p = D.19260;
    }
    D.19169 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.19169, data);
    D.19195 = sockaddr_obj;
    return D.19195;
  }
  <D.19227>:
  D.19191 = saddr->sa_family;
  if (D.19191 == 1) goto <D.19261>; else goto <D.19262>;
  <D.19261>:
  {
    int i;

    i = 0;
    goto <D.18591>;
    <D.18590>:
    {
      guint8 * __p;

      D.19263 = i + 2;
      D.19264 = (long unsigned int) D.19263;
      __p = mono_array_addr_with_size (data, 1, D.19264);
      D.19265 = saddr->sa_data[i];
      D.19266 = (unsigned char) D.19265;
      *__p = D.19266;
    }
    i = i + 1;
    <D.18591>:
    if (i < sa_size) goto <D.18590>; else goto <D.18592>;
    <D.18592>:
    D.19169 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.19169, data);
    D.19195 = sockaddr_obj;
    return D.19195;
  }
  <D.19262>:
  *error = 10047;
  D.19195 = 0B;
  return D.19195;
}


get_socket_assembly ()
{
  struct MonoImage * D.19268;
  struct MonoImage * D.19275;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.19268 = domain->socket_assembly;
  if (D.19268 == 0B) goto <D.19269>; else goto <D.19270>;
  <D.19269>:
  {
    struct MonoImage * socket_assembly;

    socket_assembly = mono_image_loaded ("System");
    if (socket_assembly == 0B) goto <D.19271>; else goto <D.19272>;
    <D.19271>:
    {
      struct MonoAssembly * sa;

      sa = mono_assembly_open ("System.dll", 0B);
      if (sa == 0B) goto <D.19273>; else goto <D.19274>;
      <D.19273>:
      monoeg_assertion_message ("* Assertion: should not be reached at %s:%d\n", "socket-io.c", 689);
      <D.19274>:
      socket_assembly = mono_assembly_get_image (sa);
    }
    <D.19272>:
    domain->socket_assembly = socket_assembly;
  }
  <D.19270>:
  D.19275 = domain->socket_assembly;
  return D.19275;
}


convert_to_mono_family (guint16 af_family)
{
  int D.19277;
  MonoAddressFamily D.19278;
  MonoAddressFamily family;

  family = -1;
  D.19277 = (int) af_family;
  switch (D.19277) <default: <D.18351>, case 0: <D.18341>, case 1: <D.18343>, case 2: <D.18344>, case 4: <D.18345>, case 5: <D.18348>, case 10: <D.18349>, case 12: <D.18347>, case 22: <D.18346>, case 23: <D.18350>>
  <D.18341>:
  family = 0;
  goto <D.18342>;
  <D.18343>:
  family = 1;
  goto <D.18342>;
  <D.18344>:
  family = 2;
  goto <D.18342>;
  <D.18345>:
  family = 6;
  goto <D.18342>;
  <D.18346>:
  family = 11;
  goto <D.18342>;
  <D.18347>:
  family = 12;
  goto <D.18342>;
  <D.18348>:
  family = 16;
  goto <D.18342>;
  <D.18349>:
  family = 23;
  goto <D.18342>;
  <D.18350>:
  family = 26;
  goto <D.18342>;
  <D.18351>:
  D.19277 = (int) af_family;
  monoeg_g_log (0B, 16, "unknown address family 0x%x", D.19277);
  <D.18342>:
  D.19278 = family;
  return D.19278;
}


__bswap_32 (unsigned int __bsx)
{
  unsigned int D.19280;

  D.19280 = __builtin_bswap32 (__bsx);
  return D.19280;
}


is_ipv4_mapped_any (const struct in6_addr * addr)
{
  unsigned char D.19282;
  gboolean D.19285;
  short unsigned int D.19286;
  short unsigned int D.19287;
  int i;

  i = 0;
  goto <D.18538>;
  <D.18537>:
  D.19282 = addr->__in6_u.__u6_addr8[i];
  if (D.19282 != 0) goto <D.19283>; else goto <D.19284>;
  <D.19283>:
  D.19285 = 0;
  return D.19285;
  <D.19284>:
  i = i + 1;
  <D.18538>:
  if (i <= 9) goto <D.18537>; else goto <D.18539>;
  <D.18539>:
  D.19286 = BIT_FIELD_REF <*addr, 16, 80>;
  D.19287 = D.19286;
  if (D.19287 != 65535) goto <D.19288>; else goto <D.19289>;
  <D.19288>:
  D.19285 = 0;
  return D.19285;
  <D.19289>:
  i = 12;
  goto <D.18541>;
  <D.18540>:
  D.19282 = addr->__in6_u.__u6_addr8[i];
  if (D.19282 != 0) goto <D.19290>; else goto <D.19291>;
  <D.19290>:
  D.19285 = 0;
  return D.19285;
  <D.19291>:
  i = i + 1;
  <D.18541>:
  if (i <= 15) goto <D.18540>; else goto <D.18542>;
  <D.18542>:
  D.19285 = 1;
  return D.19285;
}


ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.19293;
  int D.19294;
  unsigned int salen.12;
  unsigned int salen.13;
  struct MonoObject * D.19299;
  gchar * iftmp.14;
  long unsigned int D.19303;
  long unsigned int D.19305;
  int D.19308;
  int salen.15;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.19293 = convert_family (af);
      D.19294 = get_sockaddr_size (D.19293);
      salen.12 = (unsigned int) D.19294;
      salen = salen.12;
      salen.13 = salen;
      if (salen.13 == 0) goto <D.19297>; else goto <D.19298>;
      <D.19297>:
      *error = 10047;
      D.19299 = 0B;
      return D.19299;
      <D.19298>:
      salen.13 = salen;
      if (salen.13 <= 128) goto <D.19301>; else goto <D.19302>;
      <D.19301>:
      salen.13 = salen;
      D.19303 = (long unsigned int) salen.13;
      iftmp.14 = __builtin_alloca (D.19303);
      goto <D.19304>;
      <D.19302>:
      salen.13 = salen;
      D.19305 = (long unsigned int) salen.13;
      iftmp.14 = monoeg_malloc0 (D.19305);
      <D.19304>:
      sa = iftmp.14;
      ret = _wapi_getpeername (sock, sa, &salen);
      if (ret == -1) goto <D.19306>; else goto <D.19307>;
      <D.19306>:
      D.19308 = WSAGetLastError ();
      *error = D.19308;
      salen.13 = salen;
      if (salen.13 > 128) goto <D.19309>; else goto <D.19310>;
      <D.19309>:
      monoeg_g_free (sa);
      <D.19310>:
      D.19299 = 0B;
      return D.19299;
      <D.19307>:
      salen.13 = salen;
      salen.15 = (int) salen.13;
      result = create_object_from_sockaddr (sa, salen.15, error);
      salen.13 = salen;
      if (salen.13 > 128) goto <D.19312>; else goto <D.19313>;
      <D.19312>:
      monoeg_g_free (sa);
      <D.19313>:
      D.19299 = result;
      return D.19299;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Bind_internal (SOCKET sock, struct MonoObject * sockaddr, gint32 * error)
{
  int D.19316;
  unsigned int sa_size.16;
  int D.19322;
  struct sockaddr * sa;
  socklen_t sa_size;
  int ret;

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.19316 = *error;
      if (D.19316 != 0) goto <D.19317>; else goto <D.19318>;
      <D.19317>:
      return;
      <D.19318>:
      sa_size.16 = sa_size;
      ret = _wapi_bind (sock, sa, sa_size.16);
      if (ret == -1) goto <D.19320>; else goto <D.19321>;
      <D.19320>:
      D.19322 = WSAGetLastError ();
      *error = D.19322;
      <D.19321>:
      monoeg_g_free (sa);
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


create_sockaddr_from_object (struct MonoObject * saddr_obj, socklen_t * sa_size, gint32 * error)
{
  struct MonoVTable * D.19326;
  struct MonoClass * D.19327;
  int D.19328;
  sizetype D.19329;
  struct MonoArray * * D.19330;
  long unsigned int D.19331;
  struct MonoImage * D.19334;
  struct MonoException * D.19335;
  char * D.19336;
  unsigned char D.19337;
  int D.19338;
  char * D.19339;
  unsigned char D.19340;
  int D.19341;
  int D.19342;
  int D.19343;
  struct MonoImage * D.19348;
  struct MonoException * D.19349;
  char * D.19350;
  unsigned char D.19351;
  short unsigned int D.19352;
  short unsigned int D.19353;
  char * D.19354;
  unsigned char D.19355;
  short unsigned int D.19356;
  char * D.19357;
  unsigned char D.19358;
  int D.19359;
  int D.19360;
  char * D.19361;
  unsigned char D.19362;
  int D.19363;
  int D.19364;
  int D.19365;
  char * D.19366;
  unsigned char D.19367;
  int D.19368;
  int D.19369;
  int D.19370;
  char * D.19371;
  unsigned char D.19372;
  int D.19373;
  int D.19374;
  short unsigned int D.19375;
  unsigned int D.19376;
  short unsigned int D.18629;
  int D.19377;
  int D.19378;
  short unsigned int D.19381;
  signed short D.19382;
  int D.19383;
  signed short D.19384;
  signed short D.19385;
  struct sockaddr * D.19387;
  struct MonoImage * D.19392;
  struct MonoException * D.19393;
  char * D.19394;
  unsigned char D.19395;
  short unsigned int D.19396;
  char * D.19397;
  unsigned char D.19398;
  short unsigned int D.19399;
  short unsigned int D.19400;
  char * D.19401;
  unsigned char D.19402;
  int D.19403;
  char * D.19404;
  unsigned char D.19405;
  int D.19406;
  int D.19407;
  int D.19408;
  char * D.19409;
  unsigned char D.19410;
  int D.19411;
  int D.19412;
  int D.19413;
  char * D.19414;
  unsigned char D.19415;
  int D.19416;
  int D.19417;
  int D.19418;
  short unsigned int D.18636;
  int D.19419;
  int D.19420;
  short unsigned int D.19423;
  signed short D.19424;
  int D.19425;
  signed short D.19426;
  signed short D.19427;
  int D.19429;
  long unsigned int D.19430;
  char * D.19431;
  unsigned char D.19432;
  struct MonoException * D.19437;
  int D.19438;
  long unsigned int D.19439;
  char * D.19440;
  unsigned char D.19441;
  char D.19442;
  int D.19443;
  unsigned int len.17;
  struct MonoClassField * field;
  struct MonoArray * data;
  gint32 family;
  int len;

  D.19326 = saddr_obj->vtable;
  D.19327 = D.19326->klass;
  field = mono_class_get_field_from_name (D.19327, "data");
  D.19328 = field->offset;
  D.19329 = (sizetype) D.19328;
  D.19330 = saddr_obj + D.19329;
  data = *D.19330;
  D.19331 = mono_array_length (data);
  len = (int) D.19331;
  if (len <= 1) goto <D.19332>; else goto <D.19333>;
  <D.19332>:
  D.19334 = mono_get_corlib ();
  D.19335 = mono_exception_from_name (D.19334, "System", "SystemException");
  mono_raise_exception (D.19335);
  <D.19333>:
  D.19336 = mono_array_addr_with_size (data, 1, 0);
  D.19337 = MEM[(guint8 *)D.19336];
  D.19338 = (int) D.19337;
  D.19339 = mono_array_addr_with_size (data, 1, 1);
  D.19340 = MEM[(guint8 *)D.19339];
  D.19341 = (int) D.19340;
  D.19342 = D.19341 << 8;
  D.19343 = D.19338 + D.19342;
  family = convert_family (D.19343);
  if (family == 2) goto <D.19344>; else goto <D.19345>;
  <D.19344>:
  {
    struct sockaddr_in * sa;
    guint16 port;
    guint32 address;

    if (len <= 7) goto <D.19346>; else goto <D.19347>;
    <D.19346>:
    D.19348 = mono_get_corlib ();
    D.19349 = mono_exception_from_name (D.19348, "System", "SystemException");
    mono_raise_exception (D.19349);
    <D.19347>:
    sa = monoeg_malloc0 (16);
    D.19350 = mono_array_addr_with_size (data, 1, 2);
    D.19351 = MEM[(guint8 *)D.19350];
    D.19352 = (short unsigned int) D.19351;
    D.19353 = D.19352 << 8;
    D.19354 = mono_array_addr_with_size (data, 1, 3);
    D.19355 = MEM[(guint8 *)D.19354];
    D.19356 = (short unsigned int) D.19355;
    port = D.19353 + D.19356;
    D.19357 = mono_array_addr_with_size (data, 1, 4);
    D.19358 = MEM[(guint8 *)D.19357];
    D.19359 = (int) D.19358;
    D.19360 = D.19359 << 24;
    D.19361 = mono_array_addr_with_size (data, 1, 5);
    D.19362 = MEM[(guint8 *)D.19361];
    D.19363 = (int) D.19362;
    D.19364 = D.19363 << 16;
    D.19365 = D.19360 + D.19364;
    D.19366 = mono_array_addr_with_size (data, 1, 6);
    D.19367 = MEM[(guint8 *)D.19366];
    D.19368 = (int) D.19367;
    D.19369 = D.19368 << 8;
    D.19370 = D.19365 + D.19369;
    D.19371 = mono_array_addr_with_size (data, 1, 7);
    D.19372 = MEM[(guint8 *)D.19371];
    D.19373 = (int) D.19372;
    D.19374 = D.19370 + D.19373;
    address = (guint32) D.19374;
    D.19375 = (short unsigned int) family;
    sa->sin_family = D.19375;
    D.19376 = __bswap_32 (address);
    sa->sin_addr.s_addr = D.19376;
    {
      short unsigned int __v;
      short unsigned int __x;

      __x = port;
      {
        D.19377 = (int) __x;
        D.19378 = __builtin_constant_p (D.19377);
        if (D.19378 != 0) goto <D.19379>; else goto <D.19380>;
        <D.19379>:
        D.19381 = __x >> 8;
        D.19382 = (signed short) D.19381;
        D.19377 = (int) __x;
        D.19383 = D.19377 << 8;
        D.19384 = (signed short) D.19383;
        D.19385 = D.19382 | D.19384;
        __v = (short unsigned int) D.19385;
        goto <D.19386>;
        <D.19380>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.19386>:
      }
      D.18629 = __v;
    }
    sa->sin_port = D.18629;
    *sa_size = 16;
    D.19387 = sa;
    return D.19387;
  }
  <D.19345>:
  if (family == 10) goto <D.19388>; else goto <D.19389>;
  <D.19388>:
  {
    struct sockaddr_in6 * sa;
    int i;
    guint16 port;
    guint32 scopeid;

    if (len <= 27) goto <D.19390>; else goto <D.19391>;
    <D.19390>:
    D.19392 = mono_get_corlib ();
    D.19393 = mono_exception_from_name (D.19392, "System", "SystemException");
    mono_raise_exception (D.19393);
    <D.19391>:
    sa = monoeg_malloc0 (28);
    D.19394 = mono_array_addr_with_size (data, 1, 3);
    D.19395 = MEM[(guint8 *)D.19394];
    D.19396 = (short unsigned int) D.19395;
    D.19397 = mono_array_addr_with_size (data, 1, 2);
    D.19398 = MEM[(guint8 *)D.19397];
    D.19399 = (short unsigned int) D.19398;
    D.19400 = D.19399 << 8;
    port = D.19396 + D.19400;
    D.19401 = mono_array_addr_with_size (data, 1, 24);
    D.19402 = MEM[(guint8 *)D.19401];
    D.19403 = (int) D.19402;
    D.19404 = mono_array_addr_with_size (data, 1, 25);
    D.19405 = MEM[(guint8 *)D.19404];
    D.19406 = (int) D.19405;
    D.19407 = D.19406 << 8;
    D.19408 = D.19403 + D.19407;
    D.19409 = mono_array_addr_with_size (data, 1, 26);
    D.19410 = MEM[(guint8 *)D.19409];
    D.19411 = (int) D.19410;
    D.19412 = D.19411 << 16;
    D.19413 = D.19408 + D.19412;
    D.19414 = mono_array_addr_with_size (data, 1, 27);
    D.19415 = MEM[(guint8 *)D.19414];
    D.19416 = (int) D.19415;
    D.19417 = D.19416 << 24;
    D.19418 = D.19413 + D.19417;
    scopeid = (guint32) D.19418;
    D.19375 = (short unsigned int) family;
    sa->sin6_family = D.19375;
    {
      short unsigned int __v;
      short unsigned int __x;

      __x = port;
      {
        D.19419 = (int) __x;
        D.19420 = __builtin_constant_p (D.19419);
        if (D.19420 != 0) goto <D.19421>; else goto <D.19422>;
        <D.19421>:
        D.19423 = __x >> 8;
        D.19424 = (signed short) D.19423;
        D.19419 = (int) __x;
        D.19425 = D.19419 << 8;
        D.19426 = (signed short) D.19425;
        D.19427 = D.19424 | D.19426;
        __v = (short unsigned int) D.19427;
        goto <D.19428>;
        <D.19422>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.19428>:
      }
      D.18636 = __v;
    }
    sa->sin6_port = D.18636;
    sa->sin6_scope_id = scopeid;
    i = 0;
    goto <D.18638>;
    <D.18637>:
    D.19429 = i + 8;
    D.19430 = (long unsigned int) D.19429;
    D.19431 = mono_array_addr_with_size (data, 1, D.19430);
    D.19432 = MEM[(guint8 *)D.19431];
    sa->sin6_addr.__in6_u.__u6_addr8[i] = D.19432;
    i = i + 1;
    <D.18638>:
    if (i <= 15) goto <D.18637>; else goto <D.18639>;
    <D.18639>:
    *sa_size = 28;
    D.19387 = sa;
    return D.19387;
  }
  <D.19389>:
  if (family == 1) goto <D.19433>; else goto <D.19434>;
  <D.19433>:
  {
    struct sockaddr_un * sock_un;
    int i;

    if (len > 109) goto <D.19435>; else goto <D.19436>;
    <D.19435>:
    D.19437 = mono_get_exception_index_out_of_range ();
    mono_raise_exception (D.19437);
    <D.19436>:
    sock_un = monoeg_malloc0 (110);
    D.19375 = (short unsigned int) family;
    sock_un->sun_family = D.19375;
    i = 0;
    goto <D.18643>;
    <D.18642>:
    D.19438 = i + 2;
    D.19439 = (long unsigned int) D.19438;
    D.19440 = mono_array_addr_with_size (data, 1, D.19439);
    D.19441 = MEM[(guint8 *)D.19440];
    D.19442 = (char) D.19441;
    sock_un->sun_path[i] = D.19442;
    i = i + 1;
    <D.18643>:
    D.19443 = len + -2;
    if (D.19443 > i) goto <D.18642>; else goto <D.18644>;
    <D.18644>:
    len.17 = (unsigned int) len;
    *sa_size = len.17;
    D.19387 = sock_un;
    return D.19387;
  }
  <D.19434>:
  *error = 10047;
  D.19387 = 0B;
  return D.19387;
}


ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode, gint timeout, gint32 * error)
{
  int sock.18;
  short int iftmp.19;
  short int iftmp.20;
  int iftmp.21;
  _Bool D.19459;
  _Bool D.19460;
  _Bool D.19461;
  int * D.19464;
  long int D.19465;
  unsigned int D.19466;
  unsigned int D.19467;
  unsigned int D.19468;
  int D.19469;
  int D.19474;
  MonoBoolean D.19481;
  unsigned int D.19485;
  unsigned int D.19486;
  int D.19487;
  struct MonoInternalThread * thread;
  struct mono_pollfd * pfds;
  int ret;
  time_t start;
  static const char __func__[50] = "ves_icall_System_Net_Sockets_Socket_Poll_internal";

  thread = 0B;
  pfds = monoeg_malloc0 (8);
  sock.18 = (int) sock;
  pfds->fd = sock.18;
  if (mode != 0) goto <D.19448>; else goto <D.19449>;
  <D.19448>:
  if (mode == 1) goto <D.19451>; else goto <D.19452>;
  <D.19451>:
  iftmp.20 = 4;
  goto <D.19453>;
  <D.19452>:
  iftmp.20 = 56;
  <D.19453>:
  iftmp.19 = iftmp.20;
  goto <D.19454>;
  <D.19449>:
  iftmp.19 = 1;
  <D.19454>:
  pfds->events = iftmp.19;
  if (timeout >= 0) goto <D.19456>; else goto <D.19457>;
  <D.19456>:
  iftmp.21 = timeout / 1000;
  goto <D.19458>;
  <D.19457>:
  iftmp.21 = -1;
  <D.19458>:
  timeout = iftmp.21;
  start = time (0B);
  <D.18670>:
  *error = 0;
  ret = mono_poll (pfds, 1, timeout);
  D.19459 = timeout > 0;
  D.19460 = ret < 0;
  D.19461 = D.19459 & D.19460;
  if (D.19461 != 0) goto <D.19462>; else goto <D.19463>;
  <D.19462>:
  {
    int err;
    int sec;

    D.19464 = __errno_location ();
    err = *D.19464;
    D.19465 = time (0B);
    D.19466 = (unsigned int) D.19465;
    D.19467 = (unsigned int) start;
    D.19468 = D.19466 - D.19467;
    sec = (int) D.19468;
    D.19469 = sec * -1000;
    timeout = D.19469 + timeout;
    if (timeout < 0) goto <D.19470>; else goto <D.19471>;
    <D.19470>:
    timeout = 0;
    <D.19471>:
    D.19464 = __errno_location ();
    *D.19464 = err;
  }
  <D.19463>:
  if (ret == -1) goto <D.19472>; else goto <D.19473>;
  <D.19472>:
  D.19464 = __errno_location ();
  D.19474 = *D.19464;
  if (D.19474 == 4) goto <D.19475>; else goto <D.19476>;
  <D.19475>:
  {
    int leave;

    leave = 0;
    if (thread == 0B) goto <D.19477>; else goto <D.19478>;
    <D.19477>:
    thread = mono_thread_internal_current ();
    <D.19478>:
    leave = mono_thread_test_state (thread, 129);
    if (leave != 0) goto <D.19479>; else goto <D.19480>;
    <D.19479>:
    monoeg_g_free (pfds);
    D.19481 = 0;
    return D.19481;
    <D.19480>:
    mono_thread_interruption_checkpoint ();
    D.19464 = __errno_location ();
    *D.19464 = 4;
  }
  <D.19476>:
  <D.19473>:
  if (ret == -1) goto <D.19482>; else goto <D.18671>;
  <D.19482>:
  D.19464 = __errno_location ();
  D.19474 = *D.19464;
  if (D.19474 == 4) goto <D.18670>; else goto <D.18671>;
  <D.18671>:
  if (ret == -1) goto <D.19483>; else goto <D.19484>;
  <D.19483>:
  D.19464 = __errno_location ();
  D.19474 = *D.19464;
  D.19485 = (unsigned int) D.19474;
  D.19486 = errno_to_WSA (D.19485, &__func__);
  D.19487 = (int) D.19486;
  *error = D.19487;
  monoeg_g_free (pfds);
  D.19481 = 0;
  return D.19481;
  <D.19484>:
  monoeg_g_free (pfds);
  if (ret == 0) goto <D.19488>; else goto <D.19489>;
  <D.19488>:
  D.19481 = 0;
  return D.19481;
  <D.19489>:
  D.19481 = 1;
  return D.19481;
}


ves_icall_System_Net_Sockets_Socket_Connect_internal (SOCKET sock, struct MonoObject * sockaddr, gint32 * error)
{
  int D.19491;
  unsigned int sa_size.22;
  int D.19497;
  struct sockaddr * sa;
  socklen_t sa_size;
  int ret;

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.19491 = *error;
      if (D.19491 != 0) goto <D.19492>; else goto <D.19493>;
      <D.19492>:
      return;
      <D.19493>:
      sa_size.22 = sa_size;
      ret = _wapi_connect (sock, sa, sa_size.22);
      if (ret == -1) goto <D.19495>; else goto <D.19496>;
      <D.19495>:
      D.19497 = WSAGetLastError ();
      *error = D.19497;
      <D.19496>:
      monoeg_g_free (sa);
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Disconnect_internal (SOCKET sock, MonoBoolean reuse, gint32 * error)
{
  gboolean (*<T1a77>) (guint32, struct WapiOverlapped *, guint32, WapiTransmitFileFlags) _wapi_disconnectex.23;
  gboolean (*<T1a7e>) (guint32, void *, guint32, guint32, struct WapiOverlapped *, struct WapiTransmitFileBuffers *, WapiTransmitFileFlags) _wapi_transmitfile.24;
  int D.19515;
  int ret;
  glong output_bytes;
  struct GUID disco_guid;
  struct GUID trans_guid;
  gboolean (*LPFN_DISCONNECTEX) (guint32, struct WapiOverlapped *, guint32, WapiTransmitFileFlags) _wapi_disconnectex;
  gboolean (*LPFN_TRANSMITFILE) (guint32, void *, guint32, guint32, struct WapiOverlapped *, struct WapiTransmitFileBuffers *, WapiTransmitFileFlags) _wapi_transmitfile;
  gboolean bret;

  try
    {
      output_bytes = 0;
      disco_guid.Data1 = 2145005073;
      disco_guid.Data2 = 34352;
      disco_guid.Data3 = 17263;
      disco_guid.Data4[0] = 160;
      disco_guid.Data4[1] = 49;
      disco_guid.Data4[2] = 245;
      disco_guid.Data4[3] = 54;
      disco_guid.Data4[4] = 166;
      disco_guid.Data4[5] = 238;
      disco_guid.Data4[6] = 193;
      disco_guid.Data4[7] = 87;
      trans_guid.Data1 = 3040247280;
      trans_guid.Data2 = 52140;
      trans_guid.Data3 = 4559;
      trans_guid.Data4[0] = 149;
      trans_guid.Data4[1] = 202;
      trans_guid.Data4[2] = 0;
      trans_guid.Data4[3] = 128;
      trans_guid.Data4[4] = 95;
      trans_guid.Data4[5] = 72;
      trans_guid.Data4[6] = 161;
      trans_guid.Data4[7] = 146;
      _wapi_disconnectex = 0B;
      _wapi_transmitfile = 0B;
      *error = 0;
      ret = WSAIoctl (sock, -939524090, &disco_guid, 16, &_wapi_disconnectex, 8, &output_bytes, 0B, 0B);
      if (ret != 0) goto <D.19501>; else goto <D.19502>;
      <D.19501>:
      _wapi_disconnectex = 0B;
      ret = WSAIoctl (sock, -939524090, &trans_guid, 16, &_wapi_transmitfile, 8, &output_bytes, 0B, 0B);
      if (ret != 0) goto <D.19503>; else goto <D.19504>;
      <D.19503>:
      _wapi_transmitfile = 0B;
      <D.19504>:
      <D.19502>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      if (_wapi_disconnectex.23 != 0B) goto <D.19506>; else goto <D.19507>;
      <D.19506>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      bret = _wapi_disconnectex.23 (sock, 0B, 2, 0);
      goto <D.19508>;
      <D.19507>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      if (_wapi_transmitfile.24 != 0B) goto <D.19510>; else goto <D.19511>;
      <D.19510>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      bret = _wapi_transmitfile.24 (sock, 0B, 0, 0, 0B, 0B, 3);
      goto <D.19512>;
      <D.19511>:
      *error = 50;
      return;
      <D.19512>:
      <D.19508>:
      if (bret == 0) goto <D.19513>; else goto <D.19514>;
      <D.19513>:
      D.19515 = WSAGetLastError ();
      *error = D.19515;
      <D.19514>:
    }
  finally
    {
      output_bytes = {CLOBBER};
      disco_guid = {CLOBBER};
      trans_guid = {CLOBBER};
      _wapi_disconnectex = {CLOBBER};
      _wapi_transmitfile = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Receive_internal (SOCKET sock, struct MonoArray * buffer, gint32 offset, gint32 count, gint32 flags, gint32 * error)
{
  long unsigned int D.19519;
  int D.19520;
  gint32 D.19523;
  long unsigned int D.19524;
  long unsigned int D.19527;
  int D.19530;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;

  recvflags = 0;
  *error = 0;
  D.19519 = mono_array_length (buffer);
  alen = (gint32) D.19519;
  D.19520 = alen - count;
  if (D.19520 < offset) goto <D.19521>; else goto <D.19522>;
  <D.19521>:
  D.19523 = 0;
  return D.19523;
  <D.19522>:
  D.19524 = (long unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, D.19524);
  recvflags = convert_socketflags (flags);
  if (recvflags == -1) goto <D.19525>; else goto <D.19526>;
  <D.19525>:
  *error = 10045;
  D.19523 = 0;
  return D.19523;
  <D.19526>:
  D.19527 = (long unsigned int) count;
  ret = _wapi_recv (sock, buf, D.19527, recvflags);
  if (ret == -1) goto <D.19528>; else goto <D.19529>;
  <D.19528>:
  D.19530 = WSAGetLastError ();
  *error = D.19530;
  D.19523 = 0;
  return D.19523;
  <D.19529>:
  D.19523 = ret;
  return D.19523;
}


convert_socketflags (gint32 sflags)
{
  gint32 D.19534;
  int D.19535;
  int D.19538;
  int D.19541;
  int D.19544;
  int D.19547;
  gint32 flags;

  flags = 0;
  if (sflags == 0) goto <D.19532>; else goto <D.19533>;
  <D.19532>:
  D.19534 = 0;
  return D.19534;
  <D.19533>:
  D.19535 = sflags & -32792;
  if (D.19535 != 0) goto <D.19536>; else goto <D.19537>;
  <D.19536>:
  D.19534 = -1;
  return D.19534;
  <D.19537>:
  D.19538 = sflags & 1;
  if (D.19538 != 0) goto <D.19539>; else goto <D.19540>;
  <D.19539>:
  flags = flags | 1;
  <D.19540>:
  D.19541 = sflags & 2;
  if (D.19541 != 0) goto <D.19542>; else goto <D.19543>;
  <D.19542>:
  flags = flags | 2;
  <D.19543>:
  D.19544 = sflags & 4;
  if (D.19544 != 0) goto <D.19545>; else goto <D.19546>;
  <D.19545>:
  flags = flags | 4;
  <D.19546>:
  D.19547 = sflags & 32768;
  if (D.19547 != 0) goto <D.19548>; else goto <D.19549>;
  <D.19548>:
  flags = flags | 32768;
  <D.19549>:
  D.19534 = flags;
  return D.19534;
}


ves_icall_System_Net_Sockets_Socket_Receive_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  long unsigned int D.19551;
  int D.19552;
  unsigned int recvflags.25;
  unsigned int recvflags.26;
  gint32 D.19557;
  unsigned int count.27;
  int D.19561;
  unsigned int recv.28;
  int ret;
  int count;
  DWORD recv;
  struct WSABUF * wsabufs;
  DWORD recvflags;

  try
    {
      recvflags = 0;
      *error = 0;
      wsabufs = mono_array_addr_with_size (buffers, 16, 0);
      D.19551 = mono_array_length (buffers);
      count = (int) D.19551;
      D.19552 = convert_socketflags (flags);
      recvflags.25 = (unsigned int) D.19552;
      recvflags = recvflags.25;
      recvflags.26 = recvflags;
      if (recvflags.26 == 4294967295) goto <D.19555>; else goto <D.19556>;
      <D.19555>:
      *error = 10045;
      D.19557 = 0;
      return D.19557;
      <D.19556>:
      count.27 = (unsigned int) count;
      ret = WSARecv (sock, wsabufs, count.27, &recv, &recvflags, 0B, 0B);
      if (ret == -1) goto <D.19559>; else goto <D.19560>;
      <D.19559>:
      D.19561 = WSAGetLastError ();
      *error = D.19561;
      D.19557 = 0;
      return D.19557;
      <D.19560>:
      recv.28 = recv;
      D.19557 = (gint32) recv.28;
      return D.19557;
    }
  finally
    {
      recv = {CLOBBER};
      recvflags = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_RecvFrom_internal (SOCKET sock, struct MonoArray * buffer, gint32 offset, gint32 count, gint32 flags, struct MonoObject * * sockaddr, gint32 * error)
{
  long unsigned int D.19565;
  int D.19566;
  gint32 D.19569;
  struct MonoObject * D.19570;
  int D.19571;
  long unsigned int D.19574;
  long unsigned int D.19577;
  int D.19580;
  unsigned int sa_size.29;
  int sa_size.30;
  struct MonoObject * D.19585;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      recvflags = 0;
      *error = 0;
      D.19565 = mono_array_length (buffer);
      alen = (gint32) D.19565;
      D.19566 = alen - count;
      if (D.19566 < offset) goto <D.19567>; else goto <D.19568>;
      <D.19567>:
      D.19569 = 0;
      return D.19569;
      <D.19568>:
      D.19570 = *sockaddr;
      sa = create_sockaddr_from_object (D.19570, &sa_size, error);
      D.19571 = *error;
      if (D.19571 != 0) goto <D.19572>; else goto <D.19573>;
      <D.19572>:
      D.19569 = 0;
      return D.19569;
      <D.19573>:
      D.19574 = (long unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, D.19574);
      recvflags = convert_socketflags (flags);
      if (recvflags == -1) goto <D.19575>; else goto <D.19576>;
      <D.19575>:
      *error = 10045;
      D.19569 = 0;
      return D.19569;
      <D.19576>:
      D.19577 = (long unsigned int) count;
      ret = _wapi_recvfrom (sock, buf, D.19577, recvflags, sa, &sa_size);
      if (ret == -1) goto <D.19578>; else goto <D.19579>;
      <D.19578>:
      monoeg_g_free (sa);
      D.19580 = WSAGetLastError ();
      *error = D.19580;
      D.19569 = 0;
      return D.19569;
      <D.19579>:
      sa_size.29 = sa_size;
      if (sa_size.29 != 0) goto <D.19582>; else goto <D.19583>;
      <D.19582>:
      sa_size.29 = sa_size;
      sa_size.30 = (int) sa_size.29;
      D.19585 = create_object_from_sockaddr (sa, sa_size.30, error);
      *sockaddr = D.19585;
      goto <D.19586>;
      <D.19583>:
      *sockaddr = 0B;
      <D.19586>:
      monoeg_g_free (sa);
      D.19569 = ret;
      return D.19569;
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Send_internal (SOCKET sock, struct MonoArray * buffer, gint32 offset, gint32 count, gint32 flags, gint32 * error)
{
  long unsigned int D.19589;
  int D.19590;
  gint32 D.19593;
  long unsigned int D.19594;
  long unsigned int D.19597;
  int D.19600;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;

  sendflags = 0;
  *error = 0;
  D.19589 = mono_array_length (buffer);
  alen = (gint32) D.19589;
  D.19590 = alen - count;
  if (D.19590 < offset) goto <D.19591>; else goto <D.19592>;
  <D.19591>:
  D.19593 = 0;
  return D.19593;
  <D.19592>:
  D.19594 = (long unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, D.19594);
  sendflags = convert_socketflags (flags);
  if (sendflags == -1) goto <D.19595>; else goto <D.19596>;
  <D.19595>:
  *error = 10045;
  D.19593 = 0;
  return D.19593;
  <D.19596>:
  D.19597 = (long unsigned int) count;
  ret = _wapi_send (sock, buf, D.19597, sendflags);
  if (ret == -1) goto <D.19598>; else goto <D.19599>;
  <D.19598>:
  D.19600 = WSAGetLastError ();
  *error = D.19600;
  D.19593 = 0;
  return D.19593;
  <D.19599>:
  D.19593 = ret;
  return D.19593;
}


ves_icall_System_Net_Sockets_Socket_Send_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  long unsigned int D.19602;
  int D.19603;
  gint32 D.19606;
  unsigned int count.31;
  int D.19610;
  unsigned int sent.32;
  int ret;
  int count;
  DWORD sent;
  struct WSABUF * wsabufs;
  DWORD sendflags;

  try
    {
      sendflags = 0;
      *error = 0;
      wsabufs = mono_array_addr_with_size (buffers, 16, 0);
      D.19602 = mono_array_length (buffers);
      count = (int) D.19602;
      D.19603 = convert_socketflags (flags);
      sendflags = (DWORD) D.19603;
      if (sendflags == 4294967295) goto <D.19604>; else goto <D.19605>;
      <D.19604>:
      *error = 10045;
      D.19606 = 0;
      return D.19606;
      <D.19605>:
      count.31 = (unsigned int) count;
      ret = WSASend (sock, wsabufs, count.31, &sent, sendflags, 0B, 0B);
      if (ret == -1) goto <D.19608>; else goto <D.19609>;
      <D.19608>:
      D.19610 = WSAGetLastError ();
      *error = D.19610;
      D.19606 = 0;
      return D.19606;
      <D.19609>:
      sent.32 = sent;
      D.19606 = (gint32) sent.32;
      return D.19606;
    }
  finally
    {
      sent = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_SendTo_internal (SOCKET sock, struct MonoArray * buffer, gint32 offset, gint32 count, gint32 flags, struct MonoObject * sockaddr, gint32 * error)
{
  long unsigned int D.19614;
  int D.19615;
  gint32 D.19618;
  int D.19619;
  long unsigned int D.19622;
  unsigned int sa_size.33;
  long unsigned int D.19626;
  int D.19629;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      sendflags = 0;
      *error = 0;
      D.19614 = mono_array_length (buffer);
      alen = (gint32) D.19614;
      D.19615 = alen - count;
      if (D.19615 < offset) goto <D.19616>; else goto <D.19617>;
      <D.19616>:
      D.19618 = 0;
      return D.19618;
      <D.19617>:
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.19619 = *error;
      if (D.19619 != 0) goto <D.19620>; else goto <D.19621>;
      <D.19620>:
      D.19618 = 0;
      return D.19618;
      <D.19621>:
      D.19622 = (long unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, D.19622);
      sendflags = convert_socketflags (flags);
      if (sendflags == -1) goto <D.19623>; else goto <D.19624>;
      <D.19623>:
      *error = 10045;
      D.19618 = 0;
      return D.19618;
      <D.19624>:
      sa_size.33 = sa_size;
      D.19626 = (long unsigned int) count;
      ret = _wapi_sendto (sock, buf, D.19626, sendflags, sa, sa_size.33);
      if (ret == -1) goto <D.19627>; else goto <D.19628>;
      <D.19627>:
      D.19629 = WSAGetLastError ();
      *error = D.19629;
      <D.19628>:
      monoeg_g_free (sa);
      D.19618 = ret;
      return D.19618;
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Select_internal (struct MonoArray * * sockets, gint32 timeout, gint32 * error)
{
  struct MonoArray * D.19632;
  long unsigned int D.19633;
  long unsigned int D.19634;
  long unsigned int D.19635;
  long unsigned int D.19636;
  char * D.19637;
  long unsigned int D.19642;
  long unsigned int D.19643;
  struct mono_pollfd * D.19644;
  unsigned int D.19645;
  int D.19646;
  short int iftmp.34;
  short int iftmp.35;
  int iftmp.36;
  unsigned int nfds.37;
  _Bool D.19660;
  _Bool D.19661;
  _Bool D.19662;
  int * D.19665;
  long int D.19666;
  unsigned int D.19667;
  unsigned int D.19668;
  unsigned int D.19669;
  int D.19670;
  int D.19675;
  unsigned int D.19685;
  unsigned int D.19686;
  int D.19687;
  struct MonoVTable * D.19690;
  long unsigned int D.19691;
  long unsigned int socks_size.38;
  struct MonoDomain * D.19693;
  char * D.19694;
  int D.19697;
  long unsigned int D.19698;
  long unsigned int D.19699;
  short int D.19700;
  int D.19706;
  int D.19707;
  int idx.39;
  long unsigned int D.19710;
  int D.19714;
  int idx.40;
  long unsigned int D.19717;
  int D.19718;
  int idx.41;
  long unsigned int D.19722;
  _Bool D.19723;
  _Bool D.19724;
  _Bool D.19725;
  struct MonoInternalThread * thread;
  struct MonoObject * obj;
  struct mono_pollfd * pfds;
  int nfds;
  int idx;
  int ret;
  int i;
  int count;
  int mode;
  struct MonoClass * sock_arr_class;
  struct MonoArray * socks;
  time_t start;
  uintptr_t socks_size;
  static const char __func__[52] = "ves_icall_System_Net_Sockets_Socket_Select_internal";

  try
    {
      thread = 0B;
      D.19632 = *sockets;
      D.19633 = mono_array_length (D.19632);
      count = (int) D.19633;
      nfds = count + -3;
      D.19634 = (long unsigned int) nfds;
      D.19635 = D.19634 * 8;
      pfds = monoeg_malloc0 (D.19635);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.18794>;
      <D.18793>:
      D.19636 = (long unsigned int) i;
      D.19632 = *sockets;
      D.19637 = mono_array_addr_with_size (D.19632, 8, D.19636);
      obj = MEM[(struct MonoObject * *)D.19637];
      if (obj == 0B) goto <D.19638>; else goto <D.19639>;
      <D.19638>:
      mode = mode + 1;
      // predicted unlikely by continue predictor.
      goto <D.18792>;
      <D.19639>:
      if (idx >= nfds) goto <D.19640>; else goto <D.19641>;
      <D.19640>:
      monoeg_g_free (pfds);
      *error = 10014;
      return;
      <D.19641>:
      D.19642 = (long unsigned int) idx;
      D.19643 = D.19642 * 8;
      D.19644 = pfds + D.19643;
      D.19645 = Socket_to_SOCKET (obj);
      D.19646 = (int) D.19645;
      D.19644->fd = D.19646;
      D.19642 = (long unsigned int) idx;
      D.19643 = D.19642 * 8;
      D.19644 = pfds + D.19643;
      if (mode != 0) goto <D.19648>; else goto <D.19649>;
      <D.19648>:
      if (mode == 1) goto <D.19651>; else goto <D.19652>;
      <D.19651>:
      iftmp.35 = 4;
      goto <D.19653>;
      <D.19652>:
      iftmp.35 = 56;
      <D.19653>:
      iftmp.34 = iftmp.35;
      goto <D.19654>;
      <D.19649>:
      iftmp.34 = 1;
      <D.19654>:
      D.19644->events = iftmp.34;
      idx = idx + 1;
      <D.18792>:
      i = i + 1;
      <D.18794>:
      if (i < count) goto <D.18793>; else goto <D.18795>;
      <D.18795>:
      if (timeout >= 0) goto <D.19656>; else goto <D.19657>;
      <D.19656>:
      iftmp.36 = timeout / 1000;
      goto <D.19658>;
      <D.19657>:
      iftmp.36 = -1;
      <D.19658>:
      timeout = iftmp.36;
      start = time (0B);
      <D.18799>:
      *error = 0;
      nfds.37 = (unsigned int) nfds;
      ret = mono_poll (pfds, nfds.37, timeout);
      D.19660 = timeout > 0;
      D.19661 = ret < 0;
      D.19662 = D.19660 & D.19661;
      if (D.19662 != 0) goto <D.19663>; else goto <D.19664>;
      <D.19663>:
      {
        int err;
        int sec;

        D.19665 = __errno_location ();
        err = *D.19665;
        D.19666 = time (0B);
        D.19667 = (unsigned int) D.19666;
        D.19668 = (unsigned int) start;
        D.19669 = D.19667 - D.19668;
        sec = (int) D.19669;
        D.19670 = sec * -1000;
        timeout = D.19670 + timeout;
        if (timeout < 0) goto <D.19671>; else goto <D.19672>;
        <D.19671>:
        timeout = 0;
        <D.19672>:
        D.19665 = __errno_location ();
        *D.19665 = err;
      }
      <D.19664>:
      if (ret == -1) goto <D.19673>; else goto <D.19674>;
      <D.19673>:
      D.19665 = __errno_location ();
      D.19675 = *D.19665;
      if (D.19675 == 4) goto <D.19676>; else goto <D.19677>;
      <D.19676>:
      {
        int leave;

        leave = 0;
        if (thread == 0B) goto <D.19678>; else goto <D.19679>;
        <D.19678>:
        thread = mono_thread_internal_current ();
        <D.19679>:
        leave = mono_thread_test_state (thread, 129);
        if (leave != 0) goto <D.19680>; else goto <D.19681>;
        <D.19680>:
        monoeg_g_free (pfds);
        *sockets = 0B;
        return;
        <D.19681>:
        mono_thread_interruption_checkpoint ();
        D.19665 = __errno_location ();
        *D.19665 = 4;
      }
      <D.19677>:
      <D.19674>:
      if (ret == -1) goto <D.19682>; else goto <D.18800>;
      <D.19682>:
      D.19665 = __errno_location ();
      D.19675 = *D.19665;
      if (D.19675 == 4) goto <D.18799>; else goto <D.18800>;
      <D.18800>:
      if (ret == -1) goto <D.19683>; else goto <D.19684>;
      <D.19683>:
      D.19665 = __errno_location ();
      D.19675 = *D.19665;
      D.19685 = (unsigned int) D.19675;
      D.19686 = errno_to_WSA (D.19685, &__func__);
      D.19687 = (int) D.19686;
      *error = D.19687;
      monoeg_g_free (pfds);
      return;
      <D.19684>:
      if (ret == 0) goto <D.19688>; else goto <D.19689>;
      <D.19688>:
      monoeg_g_free (pfds);
      *sockets = 0B;
      return;
      <D.19689>:
      D.19632 = *sockets;
      D.19690 = MEM[(struct MonoObject *)D.19632].vtable;
      sock_arr_class = D.19690->klass;
      D.19691 = (long unsigned int) ret;
      socks_size.38 = D.19691 + 3;
      socks_size = socks_size.38;
      D.19693 = mono_domain_get ();
      socks = mono_array_new_full (D.19693, sock_arr_class, &socks_size, 0B);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.18808>;
      <D.18807>:
      {
        struct mono_pollfd * pfd;

        D.19636 = (long unsigned int) i;
        D.19632 = *sockets;
        D.19694 = mono_array_addr_with_size (D.19632, 8, D.19636);
        obj = MEM[(struct MonoObject * *)D.19694];
        if (obj == 0B) goto <D.19695>; else goto <D.19696>;
        <D.19695>:
        mode = mode + 1;
        idx = idx + 1;
        // predicted unlikely by continue predictor.
        goto <D.18803>;
        <D.19696>:
        D.19697 = i - mode;
        D.19698 = (long unsigned int) D.19697;
        D.19699 = D.19698 * 8;
        pfd = pfds + D.19699;
        D.19700 = pfd->revents;
        if (D.19700 == 0) goto <D.19701>; else goto <D.19702>;
        <D.19701>:
        // predicted unlikely by continue predictor.
        goto <D.18803>;
        <D.19702>:
        ret = ret + -1;
        if (mode == 0) goto <D.19705>; else goto <D.19703>;
        <D.19705>:
        D.19700 = pfd->revents;
        D.19706 = (int) D.19700;
        D.19707 = D.19706 & 57;
        if (D.19707 != 0) goto <D.19708>; else goto <D.19703>;
        <D.19708>:
        {
          void * * __p;

          idx.39 = idx;
          idx = idx.39 + 1;
          D.19710 = (long unsigned int) idx.39;
          __p = mono_array_addr_with_size (socks, 8, D.19710);
          mono_gc_wbarrier_set_arrayref (socks, __p, obj);
        }
        goto <D.19704>;
        <D.19703>:
        if (mode == 1) goto <D.19713>; else goto <D.19711>;
        <D.19713>:
        D.19700 = pfd->revents;
        D.19706 = (int) D.19700;
        D.19714 = D.19706 & 60;
        if (D.19714 != 0) goto <D.19715>; else goto <D.19711>;
        <D.19715>:
        {
          void * * __p;

          idx.40 = idx;
          idx = idx.40 + 1;
          D.19717 = (long unsigned int) idx.40;
          __p = mono_array_addr_with_size (socks, 8, D.19717);
          mono_gc_wbarrier_set_arrayref (socks, __p, obj);
        }
        goto <D.19712>;
        <D.19711>:
        D.19700 = pfd->revents;
        D.19706 = (int) D.19700;
        D.19718 = D.19706 & 56;
        if (D.19718 != 0) goto <D.19719>; else goto <D.19720>;
        <D.19719>:
        {
          void * * __p;

          idx.41 = idx;
          idx = idx.41 + 1;
          D.19722 = (long unsigned int) idx.41;
          __p = mono_array_addr_with_size (socks, 8, D.19722);
          mono_gc_wbarrier_set_arrayref (socks, __p, obj);
        }
        <D.19720>:
        <D.19712>:
        <D.19704>:
      }
      <D.18803>:
      i = i + 1;
      <D.18808>:
      D.19723 = i < count;
      D.19724 = ret > 0;
      D.19725 = D.19723 & D.19724;
      if (D.19725 != 0) goto <D.18807>; else goto <D.18809>;
      <D.18809>:
      *sockets = socks;
      monoeg_g_free (pfds);
    }
  finally
    {
      socks_size = {CLOBBER};
    }
}


Socket_to_SOCKET (struct MonoObject * sockobj)
{
  struct MonoVTable * D.19729;
  struct MonoClass * D.19730;
  int D.19731;
  sizetype D.19732;
  void * * D.19733;
  void * D.19734;
  long int D.19735;
  SOCKET D.19736;
  SOCKET sock;
  struct MonoClassField * field;

  D.19729 = sockobj->vtable;
  D.19730 = D.19729->klass;
  field = mono_class_get_field_from_name (D.19730, "socket");
  D.19731 = field->offset;
  D.19732 = (sizetype) D.19731;
  D.19733 = sockobj + D.19732;
  D.19734 = *D.19733;
  D.19735 = (long int) D.19734;
  sock = (SOCKET) D.19735;
  D.19736 = sock;
  return D.19736;
}


ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal (SOCKET sock, gint32 level, gint32 name, struct MonoObject * * obj_val, gint32 * error)
{
  _Bool D.19738;
  _Bool D.19739;
  _Bool D.19740;
  <unnamed type> level.42;
  struct MonoObject * D.19749;
  int system_name.43;
  int system_level.44;
  int D.19754;
  struct MonoImage * D.19755;
  int D.19756;
  sizetype D.19757;
  guint8 * D.19758;
  int D.19759;
  unsigned char D.19760;
  guint32 * D.19761;
  int D.19762;
  unsigned int D.19763;
  _Bool D.19764;
  int D.19765;
  int time_ms.45;
  struct MonoImage * mono_posix_image.46;
  struct MonoImage * mono_posix_image.47;
  struct MonoImage * mono_posix_image.48;
  int D.19776;
  unsigned int D.19777;
  int D.19778;
  unsigned int D.19779;
  int D.19780;
  int val.49;
  _Bool D.19784;
  int val.50;
  int system_level;
  int system_name;
  int ret;
  int val;
  socklen_t valsize;
  struct linger linger;
  socklen_t lingersize;
  int time_ms;
  socklen_t time_ms_size;
  struct ucred cred;
  socklen_t credsize;
  struct MonoDomain * domain;
  struct MonoObject * obj;
  struct MonoClass * obj_class;
  struct MonoClassField * field;

  try
    {
      valsize = 4;
      lingersize = 8;
      time_ms = 0;
      time_ms_size = 4;
      credsize = 12;
      domain = mono_domain_get ();
      *error = 0;
      D.19738 = level == 65535;
      D.19739 = name == -5;
      D.19740 = D.19738 & D.19739;
      if (D.19740 != 0) goto <D.19741>; else goto <D.19742>;
      <D.19741>:
      system_level = 1;
      system_name = 2;
      ret = 0;
      goto <D.19743>;
      <D.19742>:
      level.42 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.42, name, &system_level, &system_name);
      <D.19743>:
      if (ret == -1) goto <D.19745>; else goto <D.19746>;
      <D.19745>:
      *error = 10042;
      return;
      <D.19746>:
      if (ret == -2) goto <D.19747>; else goto <D.19748>;
      <D.19747>:
      D.19749 = int_to_object (domain, 0);
      *obj_val = D.19749;
      return;
      <D.19748>:
      switch (name) <default: <D.18842>, case -129: <D.18837>, case 128: <D.18836>, case 4101: <D.18839>, case 4102: <D.18840>, case 10001: <D.18841>>
      <D.18836>:
      <D.18837>:
      system_name.43 = system_name;
      system_level.44 = system_level;
      ret = _wapi_getsockopt (sock, system_level.44, system_name.43, &linger, &lingersize);
      goto <D.18838>;
      <D.18839>:
      <D.18840>:
      system_name.43 = system_name;
      system_level.44 = system_level;
      ret = _wapi_getsockopt (sock, system_level.44, system_name.43, &time_ms, &time_ms_size);
      goto <D.18838>;
      <D.18841>:
      system_name.43 = system_name;
      system_level.44 = system_level;
      ret = _wapi_getsockopt (sock, system_level.44, system_name.43, &cred, &credsize);
      goto <D.18838>;
      <D.18842>:
      system_name.43 = system_name;
      system_level.44 = system_level;
      ret = _wapi_getsockopt (sock, system_level.44, system_name.43, &val, &valsize);
      <D.18838>:
      if (ret == -1) goto <D.19752>; else goto <D.19753>;
      <D.19752>:
      D.19754 = WSAGetLastError ();
      *error = D.19754;
      return;
      <D.19753>:
      switch (name) <default: <D.18852>, case -129: <D.18845>, case 128: <D.18843>, case 4101: <D.18846>, case 4102: <D.18847>, case 10001: <D.18848>>
      <D.18843>:
      D.19755 = get_socket_assembly ();
      obj_class = mono_class_from_name (D.19755, "System.Net.Sockets", "LingerOption");
      obj = mono_object_new (domain, obj_class);
      field = mono_class_get_field_from_name (obj_class, "enabled");
      D.19756 = field->offset;
      D.19757 = (sizetype) D.19756;
      D.19758 = obj + D.19757;
      D.19759 = linger.l_onoff;
      D.19760 = (unsigned char) D.19759;
      *D.19758 = D.19760;
      field = mono_class_get_field_from_name (obj_class, "seconds");
      D.19756 = field->offset;
      D.19757 = (sizetype) D.19756;
      D.19761 = obj + D.19757;
      D.19762 = linger.l_linger;
      D.19763 = (unsigned int) D.19762;
      *D.19761 = D.19763;
      goto <D.18844>;
      <D.18845>:
      D.19759 = linger.l_onoff;
      D.19764 = D.19759 == 0;
      D.19765 = (int) D.19764;
      obj = int_to_object (domain, D.19765);
      goto <D.18844>;
      <D.18846>:
      <D.18847>:
      time_ms.45 = time_ms;
      obj = int_to_object (domain, time_ms.45);
      goto <D.18844>;
      <D.18848>:
      {
        static struct MonoImage * mono_posix_image = 0B;
        struct MonoPeerCredData * cred_data;

        mono_posix_image.46 = mono_posix_image;
        if (mono_posix_image.46 == 0B) goto <D.19768>; else goto <D.19769>;
        <D.19768>:
        mono_posix_image.47 = mono_image_loaded ("Mono.Posix");
        mono_posix_image = mono_posix_image.47;
        mono_posix_image.46 = mono_posix_image;
        if (mono_posix_image.46 == 0B) goto <D.19771>; else goto <D.19772>;
        <D.19771>:
        {
          struct MonoAssembly * sa;

          sa = mono_assembly_open ("Mono.Posix.dll", 0B);
          if (sa == 0B) goto <D.19773>; else goto <D.19774>;
          <D.19773>:
          *error = 10042;
          return;
          <D.19774>:
          mono_posix_image.48 = mono_assembly_get_image (sa);
          mono_posix_image = mono_posix_image.48;
        }
        <D.19772>:
        <D.19769>:
        mono_posix_image.46 = mono_posix_image;
        obj_class = mono_class_from_name (mono_posix_image.46, "Mono.Posix", "PeerCredData");
        obj = mono_object_new (domain, obj_class);
        cred_data = obj;
        D.19776 = cred.pid;
        cred_data->pid = D.19776;
        D.19777 = cred.uid;
        D.19778 = (int) D.19777;
        cred_data->uid = D.19778;
        D.19779 = cred.gid;
        D.19780 = (int) D.19779;
        cred_data->gid = D.19780;
        goto <D.18844>;
      }
      <D.18852>:
      D.19738 = level == 65535;
      D.19739 = name == -5;
      D.19740 = D.19738 & D.19739;
      if (D.19740 != 0) goto <D.19781>; else goto <D.19782>;
      <D.19781>:
      val.49 = val;
      D.19784 = val.49 == 0;
      val.50 = (int) D.19784;
      val = val.50;
      <D.19782>:
      val.49 = val;
      obj = int_to_object (domain, val.49);
      <D.18844>:
      *obj_val = obj;
    }
  finally
    {
      system_level = {CLOBBER};
      system_name = {CLOBBER};
      val = {CLOBBER};
      valsize = {CLOBBER};
      linger = {CLOBBER};
      lingersize = {CLOBBER};
      time_ms = {CLOBBER};
      time_ms_size = {CLOBBER};
      cred = {CLOBBER};
      credsize = {CLOBBER};
    }
}


convert_sockopt_level_and_name (MonoSocketOptionLevel mono_level, MonoSocketOptionName mono_name, int * system_level, int * system_name)
{
  gint32 D.19789;
  int cached.51;
  int iftmp.52;
  int proto.53;

  switch (mono_level) <default: <D.18468>, case 0: <D.18420>, case 6: <D.18457>, case 17: <D.18464>, case 41: <D.18438>, case 65535: <D.18395>>
  <D.18395>:
  *system_level = 1;
  switch (mono_name) <default: <D.18418>, case -129: <D.18396>, case -5: <D.18415>, case 1: <D.18398>, case 2: <D.18399>, case 4: <D.18400>, case 8: <D.18401>, case 16: <D.18402>, case 32: <D.18403>, case 64: <D.18416>, case 128: <D.18404>, case 256: <D.18405>, case 4097: <D.18406>, case 4098: <D.18407>, case 4099: <D.18408>, case 4100: <D.18409>, case 4101: <D.18410>, case 4102: <D.18411>, case 4103: <D.18412>, case 4104: <D.18413>, case 10001: <D.18414>, case 2147483647: <D.18417>>
  <D.18396>:
  *system_name = 13;
  goto <D.18397>;
  <D.18398>:
  *system_name = 1;
  goto <D.18397>;
  <D.18399>:
  *system_name = 30;
  goto <D.18397>;
  <D.18400>:
  *system_name = 2;
  goto <D.18397>;
  <D.18401>:
  *system_name = 9;
  goto <D.18397>;
  <D.18402>:
  *system_name = 5;
  goto <D.18397>;
  <D.18403>:
  *system_name = 6;
  goto <D.18397>;
  <D.18404>:
  *system_name = 13;
  goto <D.18397>;
  <D.18405>:
  *system_name = 10;
  goto <D.18397>;
  <D.18406>:
  *system_name = 7;
  goto <D.18397>;
  <D.18407>:
  *system_name = 8;
  goto <D.18397>;
  <D.18408>:
  *system_name = 19;
  goto <D.18397>;
  <D.18409>:
  *system_name = 18;
  goto <D.18397>;
  <D.18410>:
  *system_name = 21;
  goto <D.18397>;
  <D.18411>:
  *system_name = 20;
  goto <D.18397>;
  <D.18412>:
  *system_name = 4;
  goto <D.18397>;
  <D.18413>:
  *system_name = 3;
  goto <D.18397>;
  <D.18414>:
  *system_name = 17;
  goto <D.18397>;
  <D.18415>:
  <D.18416>:
  <D.18417>:
  *system_name = 128;
  goto <D.18397>;
  <D.18418>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at Socket level", mono_name);
  D.19789 = -1;
  return D.19789;
  <D.18397>:
  goto <D.18419>;
  <D.18420>:
  *system_level = 0;
  switch (mono_name) <default: <D.18437>, case 1: <D.18421>, case 2: <D.18423>, case 3: <D.18424>, case 4: <D.18425>, case 9: <D.18426>, case 10: <D.18427>, case 11: <D.18428>, case 12: <D.18429>, case 13: <D.18430>, case 14: <D.18432>, case 15: <D.18433>, case 16: <D.18434>, case 17: <D.18435>, case 18: <D.18436>, case 19: <D.18431>>
  <D.18421>:
  *system_name = 4;
  goto <D.18422>;
  <D.18423>:
  *system_name = 3;
  goto <D.18422>;
  <D.18424>:
  *system_name = 1;
  goto <D.18422>;
  <D.18425>:
  *system_name = 2;
  goto <D.18422>;
  <D.18426>:
  *system_name = 32;
  goto <D.18422>;
  <D.18427>:
  *system_name = 33;
  goto <D.18422>;
  <D.18428>:
  *system_name = 34;
  goto <D.18422>;
  <D.18429>:
  *system_name = 35;
  goto <D.18422>;
  <D.18430>:
  *system_name = 36;
  goto <D.18422>;
  <D.18431>:
  *system_name = 8;
  goto <D.18422>;
  <D.18432>:
  *system_name = 10;
  goto <D.18422>;
  <D.18433>:
  <D.18434>:
  <D.18435>:
  <D.18436>:
  <D.18437>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IP level", mono_name);
  D.19789 = -1;
  return D.19789;
  <D.18422>:
  goto <D.18419>;
  <D.18438>:
  *system_level = 41;
  switch (mono_name) <default: <D.18456>, case 1: <D.18449>, case 2: <D.18448>, case 3: <D.18450>, case 4: <D.18439>, case 9: <D.18442>, case 10: <D.18443>, case 11: <D.18444>, case 12: <D.18445>, case 13: <D.18446>, case 14: <D.18451>, case 15: <D.18452>, case 16: <D.18453>, case 17: <D.18454>, case 18: <D.18455>, case 19: <D.18447>, case 21: <D.18440>>
  <D.18439>:
  <D.18440>:
  *system_name = 16;
  goto <D.18441>;
  <D.18442>:
  *system_name = 17;
  goto <D.18441>;
  <D.18443>:
  *system_name = 18;
  goto <D.18441>;
  <D.18444>:
  *system_name = 19;
  goto <D.18441>;
  <D.18445>:
  *system_name = 20;
  goto <D.18441>;
  <D.18446>:
  *system_name = 21;
  goto <D.18441>;
  <D.18447>:
  *system_name = 50;
  goto <D.18441>;
  <D.18448>:
  <D.18449>:
  <D.18450>:
  <D.18451>:
  <D.18452>:
  <D.18453>:
  <D.18454>:
  <D.18455>:
  <D.18456>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IPv6 level", mono_name);
  D.19789 = -1;
  return D.19789;
  <D.18441>:
  goto <D.18419>;
  <D.18457>:
  if (1 != 0) goto <D.19790>; else goto <D.19791>;
  <D.19790>:
  {
    static int cached = 0;
    static int proto;

    cached.51 = cached;
    if (cached.51 == 0) goto <D.19793>; else goto <D.19794>;
    <D.19793>:
    {
      struct protoent * pent;

      pent = getprotobyname ("TCP");
      if (pent != 0B) goto <D.19796>; else goto <D.19797>;
      <D.19796>:
      iftmp.52 = pent->p_proto;
      goto <D.19798>;
      <D.19797>:
      iftmp.52 = 6;
      <D.19798>:
      proto = iftmp.52;
      cached = 1;
    }
    <D.19794>:
    proto.53 = proto;
    *system_level = proto.53;
  }
  <D.19791>:
  switch (mono_name) <default: <D.18463>, case 1: <D.18461>>
  <D.18461>:
  *system_name = 1;
  goto <D.18462>;
  <D.18463>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at TCP level", mono_name);
  D.19789 = -1;
  return D.19789;
  <D.18462>:
  goto <D.18419>;
  <D.18464>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unsupported value 0x%x", mono_level);
  switch (mono_name) <default: <D.18467>, case 1: <D.18465>, case 20: <D.18466>>
  <D.18465>:
  <D.18466>:
  <D.18467>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at UDP level", mono_name);
  D.19789 = -1;
  return D.19789;
  D.19789 = -1;
  return D.19789;
  <D.18468>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unknown value 0x%x", mono_level);
  D.19789 = -1;
  return D.19789;
  <D.18419>:
  D.19789 = 0;
  return D.19789;
}


int_to_object (struct MonoDomain * domain, int val)
{
  struct MonoObject * D.19802;
  struct MonoClass * D.19803;

  D.19803 = mono_get_int32_class ();
  D.19802 = mono_value_box (domain, D.19803, &val);
  return D.19802;
}


ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal (SOCKET sock, gint32 level, gint32 name, struct MonoArray * * byte_val, gint32 * error)
{
  <unnamed type> level.54;
  struct MonoArray * D.19810;
  long unsigned int D.19811;
  unsigned int valsize.55;
  int system_name.56;
  int system_level.57;
  int D.19817;
  int system_level;
  int system_name;
  int ret;
  guchar * buf;
  socklen_t valsize;

  try
    {
      *error = 0;
      level.54 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.54, name, &system_level, &system_name);
      if (ret == -1) goto <D.19806>; else goto <D.19807>;
      <D.19806>:
      *error = 10042;
      return;
      <D.19807>:
      if (ret == -2) goto <D.19808>; else goto <D.19809>;
      <D.19808>:
      return;
      <D.19809>:
      D.19810 = *byte_val;
      D.19811 = mono_array_length (D.19810);
      valsize.55 = (unsigned int) D.19811;
      valsize = valsize.55;
      D.19810 = *byte_val;
      buf = mono_array_addr_with_size (D.19810, 1, 0);
      system_name.56 = system_name;
      system_level.57 = system_level;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.56, buf, &valsize);
      if (ret == -1) goto <D.19815>; else goto <D.19816>;
      <D.19815>:
      D.19817 = WSAGetLastError ();
      *error = D.19817;
      <D.19816>:
    }
  finally
    {
      system_level = {CLOBBER};
      system_name = {CLOBBER};
      valsize = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal (SOCKET sock, gint32 level, gint32 name, struct MonoObject * obj_val, struct MonoArray * byte_val, gint32 int_val, gint32 * error)
{
  <unnamed type> level.58;
  _Bool D.19822;
  _Bool D.19823;
  _Bool D.19824;
  int int_val.59;
  _Bool D.19828;
  int int_val.60;
  struct MonoVTable * D.19836;
  struct MonoClass * D.19837;
  int D.19838;
  sizetype D.19839;
  guint8 * D.19840;
  unsigned char D.19841;
  int D.19842;
  guint32 * D.19843;
  unsigned int D.19844;
  int D.19845;
  unsigned int valsize.61;
  int system_name.62;
  int system_level.63;
  void * * D.19851;
  guint64 * D.19854;
  long unsigned int D.19855;
  unsigned int D.19856;
  gint32 * D.19864;
  int D.19865;
  long unsigned int D.19869;
  unsigned char D.19872;
  _Bool D.19873;
  int D.19874;
  unsigned int valsize.64;
  unsigned int int_val.65;
  unsigned int D.19879;
  unsigned int D.19880;
  unsigned int D.19881;
  unsigned int D.19882;
  unsigned int D.19883;
  unsigned int D.19884;
  unsigned int D.19885;
  unsigned int D.19886;
  unsigned int D.19887;
  int int_val.66;
  unsigned int D.19889;
  int D.19896;
  struct linger linger;
  int system_level;
  int system_name;
  int ret;
  int sol_ip;
  int sol_ipv6;

  try
    {
      *error = 0;
      sol_ipv6 = 41;
      sol_ip = 0;
      level.58 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.58, name, &system_level, &system_name);
      D.19822 = level == 65535;
      D.19823 = name == -5;
      D.19824 = D.19822 & D.19823;
      if (D.19824 != 0) goto <D.19825>; else goto <D.19826>;
      <D.19825>:
      system_name = 2;
      int_val.59 = int_val;
      D.19828 = int_val.59 == 0;
      int_val.60 = (int) D.19828;
      int_val = int_val.60;
      ret = 0;
      <D.19826>:
      if (ret == -1) goto <D.19830>; else goto <D.19831>;
      <D.19830>:
      *error = 10042;
      return;
      <D.19831>:
      if (ret == -2) goto <D.19832>; else goto <D.19833>;
      <D.19832>:
      return;
      <D.19833>:
      if (obj_val != 0B) goto <D.19834>; else goto <D.19835>;
      <D.19834>:
      {
        struct MonoClassField * field;
        int valsize;

        switch (name) <default: <D.18904>, case 12: <D.18899>, case 13: <D.18900>, case 128: <D.18897>>
        <D.18897>:
        D.19836 = obj_val->vtable;
        D.19837 = D.19836->klass;
        field = mono_class_get_field_from_name (D.19837, "enabled");
        D.19838 = field->offset;
        D.19839 = (sizetype) D.19838;
        D.19840 = obj_val + D.19839;
        D.19841 = *D.19840;
        D.19842 = (int) D.19841;
        linger.l_onoff = D.19842;
        D.19836 = obj_val->vtable;
        D.19837 = D.19836->klass;
        field = mono_class_get_field_from_name (D.19837, "seconds");
        D.19838 = field->offset;
        D.19839 = (sizetype) D.19838;
        D.19843 = obj_val + D.19839;
        D.19844 = *D.19843;
        D.19845 = (int) D.19844;
        linger.l_linger = D.19845;
        valsize = 8;
        valsize.61 = (unsigned int) valsize;
        system_name.62 = system_name;
        system_level.63 = system_level;
        ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &linger, valsize.61);
        goto <D.18898>;
        <D.18899>:
        <D.18900>:
        {
          struct MonoObject * address;

          address = 0B;
          system_level.63 = system_level;
          if (system_level.63 == sol_ipv6) goto <D.19849>; else goto <D.19850>;
          <D.19849>:
          {
            struct ipv6_mreq mreq6;

            try
              {
                D.19836 = obj_val->vtable;
                D.19837 = D.19836->klass;
                field = mono_class_get_field_from_name (D.19837, "group");
                D.19838 = field->offset;
                D.19839 = (sizetype) D.19838;
                D.19851 = obj_val + D.19839;
                address = *D.19851;
                if (address != 0B) goto <D.19852>; else goto <D.19853>;
                <D.19852>:
                mreq6.ipv6mr_multiaddr = ipaddress_to_struct_in6_addr (address);
                <D.19853>:
                D.19836 = obj_val->vtable;
                D.19837 = D.19836->klass;
                field = mono_class_get_field_from_name (D.19837, "ifIndex");
                D.19838 = field->offset;
                D.19839 = (sizetype) D.19838;
                D.19854 = obj_val + D.19839;
                D.19855 = *D.19854;
                D.19856 = (unsigned int) D.19855;
                mreq6.ipv6mr_interface = D.19856;
                system_name.62 = system_name;
                system_level.63 = system_level;
                ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &mreq6, 20);
              }
            finally
              {
                mreq6 = {CLOBBER};
              }
          }
          goto <D.19857>;
          <D.19850>:
          system_level.63 = system_level;
          if (system_level.63 == sol_ip) goto <D.19858>; else goto <D.19859>;
          <D.19858>:
          {
            struct ip_mreqn mreq;

            try
              {
                mreq = {};
                D.19836 = obj_val->vtable;
                D.19837 = D.19836->klass;
                field = mono_class_get_field_from_name (D.19837, "group");
                D.19838 = field->offset;
                D.19839 = (sizetype) D.19838;
                D.19851 = obj_val + D.19839;
                address = *D.19851;
                if (address != 0B) goto <D.19860>; else goto <D.19861>;
                <D.19860>:
                mreq.imr_multiaddr = ipaddress_to_struct_in_addr (address);
                <D.19861>:
                D.19836 = obj_val->vtable;
                D.19837 = D.19836->klass;
                field = mono_class_get_field_from_name (D.19837, "local");
                D.19838 = field->offset;
                D.19839 = (sizetype) D.19838;
                D.19851 = obj_val + D.19839;
                address = *D.19851;
                if (address != 0B) goto <D.19862>; else goto <D.19863>;
                <D.19862>:
                mreq.imr_address = ipaddress_to_struct_in_addr (address);
                <D.19863>:
                D.19836 = obj_val->vtable;
                D.19837 = D.19836->klass;
                field = mono_class_get_field_from_name (D.19837, "iface_index");
                D.19838 = field->offset;
                D.19839 = (sizetype) D.19838;
                D.19864 = obj_val + D.19839;
                D.19865 = *D.19864;
                mreq.imr_ifindex = D.19865;
                system_name.62 = system_name;
                system_level.63 = system_level;
                ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &mreq, 12);
              }
            finally
              {
                mreq = {CLOBBER};
              }
          }
          <D.19859>:
          <D.19857>:
          goto <D.18898>;
        }
        <D.18904>:
        *error = 10022;
        return;
        <D.18898>:
      }
      goto <D.19866>;
      <D.19835>:
      if (byte_val != 0B) goto <D.19867>; else goto <D.19868>;
      <D.19867>:
      {
        int valsize;
        guchar * buf;

        D.19869 = mono_array_length (byte_val);
        valsize = (int) D.19869;
        buf = mono_array_addr_with_size (byte_val, 1, 0);
        switch (name) <default: <D.18909>, case -129: <D.18907>>
        <D.18907>:
        if (valsize == 1) goto <D.19870>; else goto <D.19871>;
        <D.19870>:
        D.19872 = *buf;
        D.19873 = D.19872 == 0;
        D.19874 = (int) D.19873;
        linger.l_onoff = D.19874;
        linger.l_linger = 0;
        system_name.62 = system_name;
        system_level.63 = system_level;
        ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &linger, 8);
        goto <D.19875>;
        <D.19871>:
        *error = 10022;
        <D.19875>:
        goto <D.18908>;
        <D.18909>:
        valsize.64 = (unsigned int) valsize;
        system_name.62 = system_name;
        system_level.63 = system_level;
        ret = _wapi_setsockopt (sock, system_level.63, system_name.62, buf, valsize.64);
        goto <D.18908>;
        <D.18908>:
      }
      goto <D.19877>;
      <D.19868>:
      switch (name) <default: <D.18915>, case -129: <D.18910>, case 9: <D.18912>, case 14: <D.18914>>
      <D.18910>:
      int_val.59 = int_val;
      D.19828 = int_val.59 == 0;
      int_val.60 = (int) D.19828;
      linger.l_onoff = int_val.60;
      linger.l_linger = 0;
      system_name.62 = system_name;
      system_level.63 = system_level;
      ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &linger, 8);
      goto <D.18911>;
      <D.18912>:
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19879 = int_val.65 << 24;
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19880 = int_val.65 & 16711680;
      D.19881 = D.19880 >> 8;
      D.19882 = D.19879 | D.19881;
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19883 = int_val.65 & 65280;
      D.19884 = D.19883 << 8;
      D.19885 = D.19882 | D.19884;
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19886 = int_val.65 >> 24;
      D.19887 = D.19885 | D.19886;
      int_val.66 = (int) D.19887;
      int_val = int_val.66;
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19889 = int_val.65 & 4278190080;
      if (D.19889 == 0) goto <D.19890>; else goto <D.19891>;
      <D.19890>:
      {
        struct ip_mreqn mreq;

        try
          {
            mreq = {};
            int_val.59 = int_val;
            mreq.imr_ifindex = int_val.59;
            system_name.62 = system_name;
            system_level.63 = system_level;
            ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &mreq, 12);
            goto <D.18911>;
          }
        finally
          {
            mreq = {CLOBBER};
          }
      }
      <D.19891>:
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19879 = int_val.65 << 24;
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19880 = int_val.65 & 16711680;
      D.19881 = D.19880 >> 8;
      D.19882 = D.19879 | D.19881;
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19883 = int_val.65 & 65280;
      D.19884 = D.19883 << 8;
      D.19885 = D.19882 | D.19884;
      int_val.59 = int_val;
      int_val.65 = (unsigned int) int_val.59;
      D.19886 = int_val.65 >> 24;
      D.19887 = D.19885 | D.19886;
      int_val.66 = (int) D.19887;
      int_val = int_val.66;
      system_name.62 = system_name;
      system_level.63 = system_level;
      ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &int_val, 4);
      goto <D.18911>;
      <D.18914>:
      int_val.59 = int_val;
      if (int_val.59 == 1) goto <D.19892>; else goto <D.19893>;
      <D.19892>:
      int_val = 2;
      <D.19893>:
      <D.18915>:
      system_name.62 = system_name;
      system_level.63 = system_level;
      ret = _wapi_setsockopt (sock, system_level.63, system_name.62, &int_val, 4);
      <D.18911>:
      <D.19877>:
      <D.19866>:
      if (ret == -1) goto <D.19894>; else goto <D.19895>;
      <D.19894>:
      D.19896 = WSAGetLastError ();
      *error = D.19896;
      <D.19895>:
    }
  finally
    {
      linger = {CLOBBER};
      system_level = {CLOBBER};
      system_name = {CLOBBER};
    }
}


ipaddress_to_struct_in6_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.19901;
  struct MonoClass * D.19902;
  int D.19903;
  sizetype D.19904;
  struct MonoArray * * D.19905;
  long unsigned int D.19906;
  char * D.19907;
  short unsigned int D.19908;
  struct in6_addr D.19909;
  struct in6_addr in6addr;
  struct MonoClassField * field;
  struct MonoArray * data;
  int i;

  try
    {
      D.19901 = ipaddr->vtable;
      D.19902 = D.19901->klass;
      field = mono_class_get_field_from_name (D.19902, "m_Numbers");
      D.19903 = field->offset;
      D.19904 = (sizetype) D.19903;
      D.19905 = ipaddr + D.19904;
      data = *D.19905;
      i = 0;
      goto <D.18878>;
      <D.18877>:
      D.19906 = (long unsigned int) i;
      D.19907 = mono_array_addr_with_size (data, 2, D.19906);
      D.19908 = MEM[(guint16 *)D.19907];
      in6addr.__in6_u.__u6_addr16[i] = D.19908;
      i = i + 1;
      <D.18878>:
      if (i <= 7) goto <D.18877>; else goto <D.18879>;
      <D.18879>:
      D.19909 = in6addr;
      return D.19909;
    }
  finally
    {
      in6addr = {CLOBBER};
    }
}


ipaddress_to_struct_in_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.19912;
  struct MonoClass * D.19913;
  int D.19914;
  sizetype D.19915;
  guint64 * D.19916;
  long unsigned int D.19917;
  unsigned int D.19918;
  struct in_addr D.19919;
  struct in_addr inaddr;
  struct MonoClassField * field;

  try
    {
      D.19912 = ipaddr->vtable;
      D.19913 = D.19912->klass;
      field = mono_class_get_field_from_name (D.19913, "m_Address");
      D.19914 = field->offset;
      D.19915 = (sizetype) D.19914;
      D.19916 = ipaddr + D.19915;
      D.19917 = *D.19916;
      D.19918 = (unsigned int) D.19917;
      inaddr.s_addr = D.19918;
      D.19919 = inaddr;
      return D.19919;
    }
  finally
    {
      inaddr = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Shutdown_internal (SOCKET sock, gint32 how, gint32 * error)
{
  int D.19924;
  int ret;

  *error = 0;
  ret = _wapi_shutdown (sock, how);
  if (ret == -1) goto <D.19922>; else goto <D.19923>;
  <D.19922>:
  D.19924 = WSAGetLastError ();
  *error = D.19924;
  <D.19923>:
}


ves_icall_System_Net_Sockets_Socket_WSAIoctl (SOCKET sock, gint32 code, struct MonoArray * input, struct MonoArray * output, gint32 * error)
{
  int D.19927;
  long unsigned int D.19931;
  long unsigned int D.19935;
  int D.19938;
  long int output_bytes.67;
  glong output_bytes;
  gchar * i_buffer;
  gchar * o_buffer;
  gint i_len;
  gint o_len;
  gint ret;

  try
    {
      output_bytes = 0;
      *error = 0;
      if (code == 21537) goto <D.19925>; else goto <D.19926>;
      <D.19925>:
      D.19927 = -1;
      return D.19927;
      <D.19926>:
      if (input == 0B) goto <D.19928>; else goto <D.19929>;
      <D.19928>:
      i_buffer = 0B;
      i_len = 0;
      goto <D.19930>;
      <D.19929>:
      i_buffer = mono_array_addr_with_size (input, 1, 0);
      D.19931 = mono_array_length (input);
      i_len = (gint) D.19931;
      <D.19930>:
      if (output == 0B) goto <D.19932>; else goto <D.19933>;
      <D.19932>:
      o_buffer = 0B;
      o_len = 0;
      goto <D.19934>;
      <D.19933>:
      o_buffer = mono_array_addr_with_size (output, 1, 0);
      D.19935 = mono_array_length (output);
      o_len = (gint) D.19935;
      <D.19934>:
      ret = WSAIoctl (sock, code, i_buffer, i_len, o_buffer, o_len, &output_bytes, 0B, 0B);
      if (ret == -1) goto <D.19936>; else goto <D.19937>;
      <D.19936>:
      D.19938 = WSAGetLastError ();
      *error = D.19938;
      D.19927 = -1;
      return D.19927;
      <D.19937>:
      output_bytes.67 = output_bytes;
      D.19927 = (int) output_bytes.67;
      return D.19927;
    }
  finally
    {
      output_bytes = {CLOBBER};
    }
}


ves_icall_System_Net_Dns_GetHostByName_internal (struct MonoString * host, struct MonoString * * h_name, struct MonoArray * * h_aliases, struct MonoArray * * h_addr_list)
{
  char D.19942;
  int D.19947;
  int D.19028;
  int D.19952;
  int D.19955;
  MonoBoolean D.19958;
  struct addrinfo * info.68;
  int D.19960;
  gboolean add_local_ips;
  gchar this_hostname[256];
  struct addrinfo * info;
  struct addrinfo hints;
  char * hostname;

  try
    {
      add_local_ips = 0;
      info = 0B;
      hostname = mono_string_to_utf8 (host);
      D.19942 = *hostname;
      if (D.19942 == 0) goto <D.19943>; else goto <D.19944>;
      <D.19943>:
      add_local_ips = 1;
      *h_name = host;
      <D.19944>:
      if (add_local_ips == 0) goto <D.19945>; else goto <D.19946>;
      <D.19945>:
      D.19947 = gethostname (&this_hostname, 256);
      if (D.19947 != -1) goto <D.19948>; else goto <D.19949>;
      <D.19948>:
      {
        size_t __s1_len;
        size_t __s2_len;

        D.19028 = __builtin_strcmp (hostname, &this_hostname);
      }
      if (D.19028 == 0) goto <D.19950>; else goto <D.19951>;
      <D.19950>:
      add_local_ips = 1;
      *h_name = host;
      <D.19951>:
      <D.19949>:
      <D.19946>:
      memset (&hints, 0, 48);
      D.19952 = get_family_hint ();
      hints.ai_family = D.19952;
      hints.ai_socktype = 1;
      hints.ai_flags = 2;
      D.19942 = *hostname;
      if (D.19942 != 0) goto <D.19953>; else goto <D.19954>;
      <D.19953>:
      D.19955 = getaddrinfo (hostname, 0B, &hints, &info);
      if (D.19955 == -1) goto <D.19956>; else goto <D.19957>;
      <D.19956>:
      D.19958 = 0;
      return D.19958;
      <D.19957>:
      <D.19954>:
      monoeg_g_free (hostname);
      info.68 = info;
      D.19960 = addrinfo_to_IPHostEntry (info.68, h_name, h_aliases, h_addr_list, add_local_ips);
      D.19958 = (MonoBoolean) D.19960;
      return D.19958;
    }
  finally
    {
      this_hostname = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
    }
}


gethostname (char * __buf, size_t __buflen)
{
  long unsigned int D.19963;
  int D.19966;
  int D.19969;
  long unsigned int D.19970;
  long unsigned int D.19971;
  long unsigned int D.19974;

  D.19963 = __builtin_object_size (__buf, 1);
  if (D.19963 != 18446744073709551615) goto <D.19964>; else goto <D.19965>;
  <D.19964>:
  D.19966 = __builtin_constant_p (__buflen);
  if (D.19966 == 0) goto <D.19967>; else goto <D.19968>;
  <D.19967>:
  D.19970 = __builtin_object_size (__buf, 1);
  D.19969 = __gethostname_chk (__buf, __buflen, D.19970);
  return D.19969;
  <D.19968>:
  D.19971 = __builtin_object_size (__buf, 1);
  if (D.19971 < __buflen) goto <D.19972>; else goto <D.19973>;
  <D.19972>:
  D.19974 = __builtin_object_size (__buf, 1);
  D.19969 = __gethostname_chk_warn (__buf, __buflen, D.19974);
  return D.19969;
  <D.19973>:
  <D.19965>:
  D.19969 = __gethostname_alias (__buf, __buflen);
  return D.19969;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.19978;
  int D.19983;
  void * D.19985;
  long unsigned int D.19986;

  D.19978 = __builtin_constant_p (__len);
  if (D.19978 != 0) goto <D.19979>; else goto <D.19980>;
  <D.19979>:
  if (__len == 0) goto <D.19981>; else goto <D.19982>;
  <D.19981>:
  D.19983 = __builtin_constant_p (__ch);
  if (D.19983 == 0) goto <D.19976>; else goto <D.19984>;
  <D.19984>:
  if (__ch != 0) goto <D.19976>; else goto <D.19977>;
  <D.19976>:
  __warn_memset_zero_len ();
  D.19985 = __dest;
  return D.19985;
  <D.19977>:
  <D.19982>:
  <D.19980>:
  D.19986 = __builtin_object_size (__dest, 0);
  D.19985 = __builtin___memset_chk (__dest, __ch, __len, D.19986);
  return D.19985;
}


get_family_hint ()
{
  unsigned char D.19988;
  struct MonoImage * D.19991;
  struct MonoDomain * D.19992;
  _Bool D.19993;
  long int D.19994;
  long int D.19995;
  union mono_mutex_t * D.19998;
  _Bool D.20001;
  long int D.20002;
  long int D.20003;
  int ipv4_enabled.69;
  int ipv6_enabled.70;
  _Bool D.20017;
  long int D.20018;
  long int D.20019;
  int D.20022;
  gint32 D.20023;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.19988 = domain->inet_family_hint;
  if (D.19988 == 0) goto <D.19989>; else goto <D.19990>;
  <D.19989>:
  {
    struct MonoClass * socket_class;
    struct MonoClassField * ipv6_field;
    struct MonoClassField * ipv4_field;
    gint32 ipv6_enabled;
    gint32 ipv4_enabled;
    struct MonoVTable * vtable;

    try
      {
        ipv6_enabled = -1;
        ipv4_enabled = -1;
        D.19991 = get_socket_assembly ();
        socket_class = mono_class_from_name (D.19991, "System.Net.Sockets", "Socket");
        ipv4_field = mono_class_get_field_from_name (socket_class, "ipv4Supported");
        ipv6_field = mono_class_get_field_from_name (socket_class, "ipv6Supported");
        D.19992 = mono_domain_get ();
        vtable = mono_class_vtable (D.19992, socket_class);
        D.19993 = vtable == 0B;
        D.19994 = (long int) D.19993;
        D.19995 = __builtin_expect (D.19994, 0);
        if (D.19995 != 0) goto <D.19996>; else goto <D.19997>;
        <D.19996>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 715, "vtable");
        <D.19997>:
        mono_runtime_class_init (vtable);
        mono_field_static_get_value (vtable, ipv4_field, &ipv4_enabled);
        mono_field_static_get_value (vtable, ipv6_field, &ipv6_enabled);
        {
          int ret;

          D.19998 = &domain->lock.mutex;
          ret = pthread_mutex_lock (D.19998);
          if (ret != 0) goto <D.19999>; else goto <D.20000>;
          <D.19999>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d", ret);
          <D.20000>:
          D.20001 = ret != 0;
          D.20002 = (long int) D.20001;
          D.20003 = __builtin_expect (D.20002, 0);
          if (D.20003 != 0) goto <D.20004>; else goto <D.20005>;
          <D.20004>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 721, "ret == 0");
          <D.20005>:
        }
        ipv4_enabled.69 = ipv4_enabled;
        if (ipv4_enabled.69 == 1) goto <D.20009>; else goto <D.20006>;
        <D.20009>:
        ipv6_enabled.70 = ipv6_enabled;
        if (ipv6_enabled.70 == 1) goto <D.20011>; else goto <D.20006>;
        <D.20011>:
        domain->inet_family_hint = 1;
        goto <D.20007>;
        <D.20006>:
        ipv4_enabled.69 = ipv4_enabled;
        if (ipv4_enabled.69 == 1) goto <D.20012>; else goto <D.20013>;
        <D.20012>:
        domain->inet_family_hint = 2;
        goto <D.20014>;
        <D.20013>:
        domain->inet_family_hint = 3;
        <D.20014>:
        <D.20007>:
        {
          int ret;

          D.19998 = &domain->lock.mutex;
          ret = pthread_mutex_unlock (D.19998);
          if (ret != 0) goto <D.20015>; else goto <D.20016>;
          <D.20015>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d", ret);
          <D.20016>:
          D.20017 = ret != 0;
          D.20018 = (long int) D.20017;
          D.20019 = __builtin_expect (D.20018, 0);
          if (D.20019 != 0) goto <D.20020>; else goto <D.20021>;
          <D.20020>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 729, "ret == 0");
          <D.20021>:
        }
      }
    finally
      {
        ipv6_enabled = {CLOBBER};
        ipv4_enabled = {CLOBBER};
      }
  }
  <D.19990>:
  D.19988 = domain->inet_family_hint;
  D.20022 = (int) D.19988;
  switch (D.20022) <default: <D.18490>, case 1: <D.18487>, case 2: <D.18488>, case 3: <D.18489>>
  <D.18487>:
  D.20023 = 0;
  return D.20023;
  <D.18488>:
  D.20023 = 2;
  return D.20023;
  <D.18489>:
  D.20023 = 10;
  return D.20023;
  <D.18490>:
  D.20023 = 0;
  return D.20023;
}


addrinfo_to_IPHostEntry (struct addrinfo * info, struct MonoString * * h_name, struct MonoArray * * h_aliases, struct MonoArray * * h_addr_list, gboolean add_local_ips)
{
  struct MonoClass * D.20025;
  struct MonoArray * D.20026;
  int nlocal_in.71;
  int nlocal_in6.72;
  int D.20034;
  long unsigned int D.20035;
  struct MonoClass * D.20036;
  struct MonoArray * D.20037;
  long unsigned int D.20040;
  long unsigned int D.20041;
  struct in_addr * D.20042;
  long unsigned int D.20043;
  struct MonoArray * D.20044;
  long unsigned int D.20047;
  long unsigned int D.20048;
  struct in6_addr * D.20049;
  gboolean D.20054;
  int D.20055;
  _Bool D.20056;
  _Bool D.20057;
  _Bool D.20058;
  long unsigned int D.20061;
  struct MonoClass * D.20062;
  struct MonoArray * D.20063;
  int D.20064;
  _Bool D.20065;
  _Bool D.20066;
  _Bool D.20067;
  int D.20070;
  struct sockaddr * D.20073;
  struct in_addr * D.20074;
  struct in6_addr * D.20076;
  char * D.20082;
  struct MonoString * D.20085;
  struct MonoString * D.20087;
  gint32 count;
  gint32 i;
  struct addrinfo * ai;
  struct in_addr * local_in;
  int nlocal_in;
  struct in6_addr * local_in6;
  int nlocal_in6;
  int addr_index;
  struct MonoDomain * domain;

  try
    {
      ai = 0B;
      local_in = 0B;
      nlocal_in = 0;
      local_in6 = 0B;
      nlocal_in6 = 0;
      domain = mono_domain_get ();
      addr_index = 0;
      D.20025 = mono_get_string_class ();
      D.20026 = mono_array_new (domain, D.20025, 0);
      *h_aliases = D.20026;
      if (add_local_ips != 0) goto <D.20027>; else goto <D.20028>;
      <D.20027>:
      local_in = get_local_ips (2, &nlocal_in);
      local_in6 = get_local_ips (10, &nlocal_in6);
      nlocal_in.71 = nlocal_in;
      if (nlocal_in.71 != 0) goto <D.20029>; else goto <D.20032>;
      <D.20032>:
      nlocal_in6.72 = nlocal_in6;
      if (nlocal_in6.72 != 0) goto <D.20029>; else goto <D.20030>;
      <D.20029>:
      nlocal_in.71 = nlocal_in;
      nlocal_in6.72 = nlocal_in6;
      D.20034 = nlocal_in.71 + nlocal_in6.72;
      D.20035 = (long unsigned int) D.20034;
      D.20036 = mono_get_string_class ();
      D.20037 = mono_array_new (domain, D.20036, D.20035);
      *h_addr_list = D.20037;
      nlocal_in.71 = nlocal_in;
      if (nlocal_in.71 != 0) goto <D.20038>; else goto <D.20039>;
      <D.20038>:
      {
        struct MonoString * addr_string;
        char addr[16];
        int i;

        try
          {
            i = 0;
            goto <D.18987>;
            <D.18986>:
            D.20040 = (long unsigned int) i;
            D.20041 = D.20040 * 4;
            D.20042 = local_in + D.20041;
            inet_ntop (2, D.20042, &addr, 16);
            addr_string = mono_string_new (domain, &addr);
            {
              void * * __p;

              D.20043 = (long unsigned int) addr_index;
              D.20044 = *h_addr_list;
              __p = mono_array_addr_with_size (D.20044, 8, D.20043);
              D.20044 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.20044, __p, addr_string);
            }
            addr_index = addr_index + 1;
            i = i + 1;
            <D.18987>:
            nlocal_in.71 = nlocal_in;
            if (i < nlocal_in.71) goto <D.18986>; else goto <D.18988>;
            <D.18988>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.20039>:
      nlocal_in6.72 = nlocal_in6;
      if (nlocal_in6.72 != 0) goto <D.20045>; else goto <D.20046>;
      <D.20045>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char addr[48];
        int i;

        try
          {
            i = 0;
            goto <D.18995>;
            <D.18994>:
            D.20047 = (long unsigned int) i;
            D.20048 = D.20047 * 16;
            D.20049 = local_in6 + D.20048;
            ret = inet_ntop (10, D.20049, &addr, 48);
            if (ret != 0B) goto <D.20050>; else goto <D.20051>;
            <D.20050>:
            addr_string = mono_string_new (domain, &addr);
            {
              void * * __p;

              D.20043 = (long unsigned int) addr_index;
              D.20044 = *h_addr_list;
              __p = mono_array_addr_with_size (D.20044, 8, D.20043);
              D.20044 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.20044, __p, addr_string);
            }
            addr_index = addr_index + 1;
            <D.20051>:
            i = i + 1;
            <D.18995>:
            nlocal_in6.72 = nlocal_in6;
            if (i < nlocal_in6.72) goto <D.18994>; else goto <D.18996>;
            <D.18996>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.20046>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      if (info != 0B) goto <D.20052>; else goto <D.20053>;
      <D.20052>:
      freeaddrinfo (info);
      <D.20053>:
      D.20054 = 1;
      return D.20054;
      <D.20030>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      <D.20028>:
      count = 0;
      ai = info;
      goto <D.18999>;
      <D.18998>:
      D.20055 = ai->ai_family;
      D.20056 = D.20055 != 2;
      D.20057 = D.20055 != 10;
      D.20058 = D.20056 & D.20057;
      if (D.20058 != 0) goto <D.20059>; else goto <D.20060>;
      <D.20059>:
      // predicted unlikely by continue predictor.
      goto <D.18997>;
      <D.20060>:
      count = count + 1;
      <D.18997>:
      ai = ai->ai_next;
      <D.18999>:
      if (ai != 0B) goto <D.18998>; else goto <D.19000>;
      <D.19000>:
      D.20061 = (long unsigned int) count;
      D.20062 = mono_get_string_class ();
      D.20063 = mono_array_new (domain, D.20062, D.20061);
      *h_addr_list = D.20063;
      ai = info;
      i = 0;
      goto <D.19007>;
      <D.19006>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char buffer[48];

        try
          {
            D.20064 = ai->ai_family;
            D.20065 = D.20064 != 2;
            D.20066 = D.20064 != 10;
            D.20067 = D.20065 & D.20066;
            if (D.20067 != 0) goto <D.20068>; else goto <D.20069>;
            <D.20068>:
            // predicted unlikely by continue predictor.
            goto <D.19004>;
            <D.20069>:
            D.20070 = ai->ai_family;
            if (D.20070 == 2) goto <D.20071>; else goto <D.20072>;
            <D.20071>:
            D.20073 = ai->ai_addr;
            D.20074 = &MEM[(struct sockaddr_in *)D.20073].sin_addr;
            D.20070 = ai->ai_family;
            ret = inet_ntop (D.20070, D.20074, &buffer, 16);
            goto <D.20075>;
            <D.20072>:
            D.20073 = ai->ai_addr;
            D.20076 = &MEM[(struct sockaddr_in6 *)D.20073].sin6_addr;
            D.20070 = ai->ai_family;
            ret = inet_ntop (D.20070, D.20076, &buffer, 48);
            <D.20075>:
            if (ret != 0B) goto <D.20077>; else goto <D.20078>;
            <D.20077>:
            addr_string = mono_string_new (domain, &buffer);
            goto <D.20079>;
            <D.20078>:
            addr_string = mono_string_new (domain, "");
            <D.20079>:
            {
              void * * __p;

              D.20043 = (long unsigned int) addr_index;
              D.20044 = *h_addr_list;
              __p = mono_array_addr_with_size (D.20044, 8, D.20043);
              D.20044 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.20044, __p, addr_string);
            }
            if (i == 0) goto <D.20080>; else goto <D.20081>;
            <D.20080>:
            i = i + 1;
            D.20082 = ai->ai_canonname;
            if (D.20082 != 0B) goto <D.20083>; else goto <D.20084>;
            <D.20083>:
            D.20082 = ai->ai_canonname;
            D.20085 = mono_string_new (domain, D.20082);
            *h_name = D.20085;
            goto <D.20086>;
            <D.20084>:
            D.20087 = mono_string_new (domain, &buffer);
            *h_name = D.20087;
            <D.20086>:
            <D.20081>:
            addr_index = addr_index + 1;
          }
        finally
          {
            buffer = {CLOBBER};
          }
      }
      <D.19004>:
      ai = ai->ai_next;
      <D.19007>:
      if (ai != 0B) goto <D.19006>; else goto <D.19008>;
      <D.19008>:
      if (info != 0B) goto <D.20088>; else goto <D.20089>;
      <D.20088>:
      freeaddrinfo (info);
      <D.20089>:
      D.20054 = 1;
      return D.20054;
    }
  finally
    {
      nlocal_in = {CLOBBER};
      nlocal_in6 = {CLOBBER};
    }
}


get_local_ips (int family, int * nips)
{
  void * D.20100;
  unsigned int max_ifaces.73;
  unsigned int D.20102;
  int D.20103;
  int D.20104;
  long unsigned int D.20105;
  void * D.20106;
  int D.20107;
  char * D.20110;
  long unsigned int D.20111;
  long unsigned int D.20112;
  char[16] * D.20115;
  int D.20116;
  short int D.20119;
  int D.20120;
  int D.20121;
  int D.20124;
  int D.20127;
  int D.20128;
  long unsigned int D.20129;
  char D.20130;
  int D.20133;
  struct sockaddr * D.20136;
  sizetype D.20137;
  void * D.20138;
  int D.20139;
  long unsigned int D.20142;
  char * D.20143;
  sizetype D.20144;
  int addr_size;
  int offset;
  int fd;
  int i;
  int count;
  int max_ifaces;
  struct ifconf ifc;
  struct ifreq * ifr;
  struct ifreq iflags;
  char * result;
  char * tmp_ptr;
  gboolean ignore_loopback;

  try
    {
      max_ifaces = 50;
      ignore_loopback = 0;
      *nips = 0;
      if (family == 2) goto <D.20094>; else goto <D.20095>;
      <D.20094>:
      addr_size = 4;
      offset = 4;
      goto <D.20096>;
      <D.20095>:
      if (family == 10) goto <D.20097>; else goto <D.20098>;
      <D.20097>:
      addr_size = 16;
      offset = 8;
      goto <D.20099>;
      <D.20098>:
      D.20100 = 0B;
      return D.20100;
      <D.20099>:
      <D.20096>:
      fd = socket (family, 1, 0);
      max_ifaces.73 = (unsigned int) max_ifaces;
      D.20102 = max_ifaces.73 * 40;
      D.20103 = (int) D.20102;
      ifc.ifc_len = D.20103;
      D.20104 = ifc.ifc_len;
      D.20105 = (long unsigned int) D.20104;
      D.20106 = monoeg_malloc (D.20105);
      ifc.ifc_ifcu.ifcu_buf = D.20106;
      D.20107 = ioctl (fd, 35090, &ifc);
      if (D.20107 < 0) goto <D.20108>; else goto <D.20109>;
      <D.20108>:
      close (fd);
      D.20110 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.20110);
      D.20100 = 0B;
      return D.20100;
      <D.20109>:
      D.20104 = ifc.ifc_len;
      D.20111 = (long unsigned int) D.20104;
      D.20112 = D.20111 / 40;
      count = (int) D.20112;
      *nips = count;
      if (count == 0) goto <D.20113>; else goto <D.20114>;
      <D.20113>:
      D.20110 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.20110);
      close (fd);
      D.20100 = 0B;
      return D.20100;
      <D.20114>:
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.18960>;
      <D.18959>:
      D.20115 = &ifr->ifr_ifrn.ifrn_name;
      strcpy (&iflags.ifr_ifrn.ifrn_name, D.20115);
      D.20116 = ioctl (fd, 35091, &iflags);
      if (D.20116 < 0) goto <D.20117>; else goto <D.20118>;
      <D.20117>:
      // predicted unlikely by continue predictor.
      goto <D.18958>;
      <D.20118>:
      D.20119 = iflags.ifr_ifru.ifru_flags;
      D.20120 = (int) D.20119;
      D.20121 = D.20120 & 1;
      if (D.20121 == 0) goto <D.20122>; else goto <D.20123>;
      <D.20122>:
      ifr->ifr_ifrn.ifrn_name[0] = 0;
      // predicted unlikely by continue predictor.
      goto <D.18958>;
      <D.20123>:
      D.20119 = iflags.ifr_ifru.ifru_flags;
      D.20120 = (int) D.20119;
      D.20124 = D.20120 & 8;
      if (D.20124 == 0) goto <D.20125>; else goto <D.20126>;
      <D.20125>:
      ignore_loopback = 1;
      <D.20126>:
      <D.18958>:
      i = i + 1;
      ifr = ifr + 40;
      <D.18960>:
      D.20127 = *nips;
      if (D.20127 > i) goto <D.18959>; else goto <D.18961>;
      <D.18961>:
      close (fd);
      D.20128 = addr_size * count;
      D.20129 = (long unsigned int) D.20128;
      result = monoeg_malloc (D.20129);
      tmp_ptr = result;
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.18964>;
      <D.18963>:
      D.20130 = ifr->ifr_ifrn.ifrn_name[0];
      if (D.20130 == 0) goto <D.20131>; else goto <D.20132>;
      <D.20131>:
      D.20127 = *nips;
      D.20133 = D.20127 + -1;
      *nips = D.20133;
      // predicted unlikely by continue predictor.
      goto <D.18962>;
      <D.20132>:
      if (ignore_loopback != 0) goto <D.20134>; else goto <D.20135>;
      <D.20134>:
      D.20136 = &ifr->ifr_ifru.ifru_addr;
      D.20137 = (sizetype) offset;
      D.20138 = D.20136 + D.20137;
      D.20139 = is_loopback (family, D.20138);
      if (D.20139 != 0) goto <D.20140>; else goto <D.20141>;
      <D.20140>:
      D.20127 = *nips;
      D.20133 = D.20127 + -1;
      *nips = D.20133;
      // predicted unlikely by continue predictor.
      goto <D.18962>;
      <D.20141>:
      <D.20135>:
      D.20142 = (long unsigned int) addr_size;
      D.20136 = &ifr->ifr_ifru.ifru_addr;
      D.20137 = (sizetype) offset;
      D.20143 = D.20136 + D.20137;
      memcpy (tmp_ptr, D.20143, D.20142);
      D.20144 = (sizetype) addr_size;
      tmp_ptr = tmp_ptr + D.20144;
      <D.18962>:
      i = i + 1;
      ifr = ifr + 40;
      <D.18964>:
      if (i < count) goto <D.18963>; else goto <D.18965>;
      <D.18965>:
      D.20110 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.20110);
      D.20100 = result;
      return D.20100;
    }
  finally
    {
      ifc = {CLOBBER};
      iflags = {CLOBBER};
    }
}


strcpy (char * restrict __dest, const char * restrict __src)
{
  char * D.20147;
  long unsigned int D.20148;

  D.20148 = __builtin_object_size (__dest, 1);
  D.20147 = __builtin___strcpy_chk (__dest, __src, D.20148);
  return D.20147;
}


is_loopback (int family, void * ad)
{
  gboolean D.20152;
  char D.20153;
  _Bool D.20154;
  int D.18941;
  int iftmp.74;
  unsigned int D.20158;
  unsigned int D.20160;
  unsigned int D.20162;
  unsigned int D.20164;
  unsigned int D.20165;
  char * ptr;

  ptr = ad;
  if (family == 2) goto <D.20150>; else goto <D.20151>;
  <D.20150>:
  D.20153 = *ptr;
  D.20154 = D.20153 == 127;
  D.20152 = (gboolean) D.20154;
  return D.20152;
  <D.20151>:
  {
    const struct in6_addr * __a;

    __a = ptr;
    D.20158 = __a->__in6_u.__u6_addr32[0];
    if (D.20158 == 0) goto <D.20159>; else goto <D.20156>;
    <D.20159>:
    D.20160 = __a->__in6_u.__u6_addr32[1];
    if (D.20160 == 0) goto <D.20161>; else goto <D.20156>;
    <D.20161>:
    D.20162 = __a->__in6_u.__u6_addr32[2];
    if (D.20162 == 0) goto <D.20163>; else goto <D.20156>;
    <D.20163>:
    D.20164 = __a->__in6_u.__u6_addr32[3];
    D.20165 = __bswap_32 (1);
    if (D.20164 == D.20165) goto <D.20166>; else goto <D.20156>;
    <D.20166>:
    iftmp.74 = 1;
    goto <D.20157>;
    <D.20156>:
    iftmp.74 = 0;
    <D.20157>:
    D.18941 = iftmp.74;
  }
  D.20152 = D.18941;
  return D.20152;
  D.20152 = 0;
  return D.20152;
}


memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.20168;
  long unsigned int D.20169;

  D.20169 = __builtin_object_size (__dest, 0);
  D.20168 = __builtin___memcpy_chk (__dest, __src, __len, D.20169);
  return D.20168;
}


ves_icall_System_Net_Dns_GetHostByAddr_internal (struct MonoString * addr, struct MonoString * * h_name, struct MonoArray * * h_aliases, struct MonoArray * * h_addr_list)
{
  int D.20171;
  int D.20174;
  MonoBoolean D.20177;
  int D.20181;
  int D.20187;
  int D.20190;
  int D.20191;
  struct addrinfo * info.75;
  int D.20195;
  char * address;
  struct sockaddr_in saddr;
  struct sockaddr_in6 saddr6;
  struct addrinfo * info;
  struct addrinfo hints;
  gint32 family;
  char hostname[1025];
  int flags;

  try
    {
      info = 0B;
      hostname = {};
      flags = 0;
      address = mono_string_to_utf8 (addr);
      D.20171 = inet_pton (2, address, &saddr.sin_addr);
      if (D.20171 <= 0) goto <D.20172>; else goto <D.20173>;
      <D.20172>:
      D.20174 = inet_pton (10, address, &saddr6.sin6_addr);
      if (D.20174 <= 0) goto <D.20175>; else goto <D.20176>;
      <D.20175>:
      monoeg_g_free (address);
      D.20177 = 0;
      return D.20177;
      <D.20176>:
      family = 10;
      saddr6.sin6_family = 10;
      goto <D.20178>;
      <D.20173>:
      family = 2;
      saddr.sin_family = 2;
      <D.20178>:
      monoeg_g_free (address);
      if (family == 2) goto <D.20179>; else goto <D.20180>;
      <D.20179>:
      D.20181 = getnameinfo (&saddr, 16, &hostname, 1025, 0B, 0, flags);
      if (D.20181 != 0) goto <D.20182>; else goto <D.20183>;
      <D.20182>:
      D.20177 = 0;
      return D.20177;
      <D.20183>:
      goto <D.20184>;
      <D.20180>:
      if (family == 10) goto <D.20185>; else goto <D.20186>;
      <D.20185>:
      D.20187 = getnameinfo (&saddr6, 28, &hostname, 1025, 0B, 0, flags);
      if (D.20187 != 0) goto <D.20188>; else goto <D.20189>;
      <D.20188>:
      D.20177 = 0;
      return D.20177;
      <D.20189>:
      <D.20186>:
      <D.20184>:
      memset (&hints, 0, 48);
      D.20190 = get_family_hint ();
      hints.ai_family = D.20190;
      hints.ai_socktype = 1;
      hints.ai_flags = 34;
      D.20191 = getaddrinfo (&hostname, 0B, &hints, &info);
      if (D.20191 == -1) goto <D.20192>; else goto <D.20193>;
      <D.20192>:
      D.20177 = 0;
      return D.20177;
      <D.20193>:
      info.75 = info;
      D.20195 = addrinfo_to_IPHostEntry (info.75, h_name, h_aliases, h_addr_list, 0);
      D.20177 = (MonoBoolean) D.20195;
      return D.20177;
    }
  finally
    {
      saddr = {CLOBBER};
      saddr6 = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
      hostname = {CLOBBER};
    }
}


ves_icall_System_Net_Dns_GetHostName_internal (struct MonoString * * h_name)
{
  MonoBoolean D.20200;
  struct MonoDomain * D.20201;
  struct MonoString * D.20202;
  gchar hostname[256];
  int ret;

  try
    {
      ret = gethostname (&hostname, 256);
      if (ret == -1) goto <D.20198>; else goto <D.20199>;
      <D.20198>:
      D.20200 = 0;
      return D.20200;
      <D.20199>:
      D.20201 = mono_domain_get ();
      D.20202 = mono_string_new (D.20201, &hostname);
      *h_name = D.20202;
      D.20200 = 1;
      return D.20200;
    }
  finally
    {
      hostname = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_SendFile (SOCKET sock, struct MonoString * filename, struct MonoArray * pre_buffer, struct MonoArray * post_buffer, gint flags)
{
  gboolean D.20207;
  int error.76;
  unsigned int error.77;
  char * D.20214;
  long unsigned int D.20215;
  unsigned int D.20216;
  char * D.20219;
  long unsigned int D.20220;
  unsigned int D.20221;
  unsigned int flags.78;
  int D.20223;
  void * file;
  gint32 error;
  struct TRANSMIT_FILE_BUFFERS buffers;

  try
    {
      if (filename == 0B) goto <D.20205>; else goto <D.20206>;
      <D.20205>:
      D.20207 = 0;
      return D.20207;
      <D.20206>:
      file = ves_icall_System_IO_MonoIO_Open (filename, 3, 1, 1, 0, &error);
      if (file == -1B) goto <D.20208>; else goto <D.20209>;
      <D.20208>:
      error.76 = error;
      error.77 = (unsigned int) error.76;
      SetLastError (error.77);
      D.20207 = 0;
      return D.20207;
      <D.20209>:
      memset (&buffers, 0, 32);
      if (pre_buffer != 0B) goto <D.20212>; else goto <D.20213>;
      <D.20212>:
      D.20214 = mono_array_addr_with_size (pre_buffer, 1, 0);
      buffers.Head = D.20214;
      D.20215 = mono_array_length (pre_buffer);
      D.20216 = (unsigned int) D.20215;
      buffers.HeadLength = D.20216;
      <D.20213>:
      if (post_buffer != 0B) goto <D.20217>; else goto <D.20218>;
      <D.20217>:
      D.20219 = mono_array_addr_with_size (post_buffer, 1, 0);
      buffers.Tail = D.20219;
      D.20220 = mono_array_length (post_buffer);
      D.20221 = (unsigned int) D.20220;
      buffers.TailLength = D.20221;
      <D.20218>:
      flags.78 = (unsigned int) flags;
      D.20223 = TransmitFile (sock, file, 0, 0, 0B, &buffers, flags.78);
      if (D.20223 == 0) goto <D.20224>; else goto <D.20225>;
      <D.20224>:
      CloseHandle (file);
      D.20207 = 0;
      return D.20207;
      <D.20225>:
      CloseHandle (file);
      D.20207 = 1;
      return D.20207;
    }
  finally
    {
      error = {CLOBBER};
      buffers = {CLOBBER};
    }
}


mono_network_init ()
{
  struct WSADATA wsadata;
  int err;
  static const char __func__[18] = "mono_network_init";

  try
    {
      err = WSAStartup (2, &wsadata);
      if (err != 0) goto <D.20228>; else goto <D.20229>;
      <D.20228>:
      monoeg_g_log (0B, 4, "%s: Couldn\'t initialise networking", &__func__);
      <D.19064>:
      goto <D.19064>;
      exit (-1);
      <D.20229>:
    }
  finally
    {
      wsadata = {CLOBBER};
    }
}


mono_network_cleanup ()
{
  WSACleanup ();
}


icall_cancel_blocking_socket_operation (struct MonoThread * thread)
{
  int D.20230;
  long unsigned int D.20233;
  int D.20235;
  struct MonoInternalThread * internal;

  internal = thread->internal_thread;
  D.20230 = mono_thread_info_new_interrupt_enabled ();
  if (D.20230 != 0) goto <D.20231>; else goto <D.20232>;
  <D.20231>:
  D.20233 = internal->tid;
  mono_thread_info_abort_socket_syscall_for_close (D.20233);
  goto <D.20234>;
  <D.20232>:
  internal->ignore_next_signal = 1;
  D.20235 = mono_thread_get_abort_signal ();
  mono_thread_kill (internal, D.20235);
  <D.20234>:
}


