ves_icall_System_Net_Sockets_Socket_Socket_internal (struct MonoObject * this, gint32 family, gint32 type, gint32 proto, gint32 * error)
{
  void * D.18711;
  int D.18718;
  _Bool D.18719;
  _Bool D.18720;
  _Bool D.18721;
  _Bool D.18724;
  _Bool D.18725;
  SOCKET sock;
  gint32 sock_family;
  gint32 sock_proto;
  gint32 sock_type;

  *error = 0;
  sock_family = convert_family (family);
  if (sock_family == -1) goto <D.18709>; else goto <D.18710>;
  <D.18709>:
  *error = 10047;
  D.18711 = 0B;
  return D.18711;
  <D.18710>:
  sock_proto = convert_proto (proto);
  if (sock_proto == -1) goto <D.18712>; else goto <D.18713>;
  <D.18712>:
  *error = 10043;
  D.18711 = 0B;
  return D.18711;
  <D.18713>:
  sock_type = convert_type (type);
  if (sock_type == -1) goto <D.18714>; else goto <D.18715>;
  <D.18714>:
  *error = 10044;
  D.18711 = 0B;
  return D.18711;
  <D.18715>:
  sock = _wapi_socket (sock_family, sock_type, sock_proto, 0B, 0, 1);
  if (sock == 4294967295) goto <D.18716>; else goto <D.18717>;
  <D.18716>:
  D.18718 = WSAGetLastError ();
  *error = D.18718;
  D.18711 = 0B;
  return D.18711;
  <D.18717>:
  D.18719 = sock_family == 2;
  D.18720 = sock_type == 2;
  D.18721 = D.18719 & D.18720;
  if (D.18721 != 0) goto <D.18722>; else goto <D.18723>;
  <D.18722>:
  D.18711 = (void *) sock;
  return D.18711;
  <D.18723>:
  D.18724 = sock_family == 10;
  D.18720 = sock_type == 2;
  D.18725 = D.18724 & D.18720;
  if (D.18725 != 0) goto <D.18726>; else goto <D.18727>;
  <D.18726>:
  D.18711 = (void *) sock;
  return D.18711;
  <D.18727>:
  D.18711 = (void *) sock;
  return D.18711;
}


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

  family = -1;
  switch (mono_family) <default: <D.17972>, case -1: <D.17943>, case 0: <D.17963>, case 1: <D.17964>, case 2: <D.17965>, case 3: <D.17944>, case 4: <D.17945>, case 5: <D.17946>, case 6: <D.17966>, case 7: <D.17947>, case 8: <D.17948>, case 9: <D.17949>, case 10: <D.17950>, case 11: <D.17967>, case 12: <D.17968>, case 13: <D.17951>, case 14: <D.17952>, case 15: <D.17953>, case 16: <D.17969>, case 17: <D.17954>, case 18: <D.17955>, case 19: <D.17956>, case 21: <D.17957>, case 22: <D.17958>, case 23: <D.17970>, case 24: <D.17959>, case 25: <D.17960>, case 26: <D.17971>, case 28: <D.17961>>
  <D.17943>:
  <D.17944>:
  <D.17945>:
  <D.17946>:
  <D.17947>:
  <D.17948>:
  <D.17949>:
  <D.17950>:
  <D.17951>:
  <D.17952>:
  <D.17953>:
  <D.17954>:
  <D.17955>:
  <D.17956>:
  <D.17957>:
  <D.17958>:
  <D.17959>:
  <D.17960>:
  <D.17961>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unsupported value 0x%x", mono_family);
  goto <D.17962>;
  <D.17963>:
  family = 0;
  goto <D.17962>;
  <D.17964>:
  family = 1;
  goto <D.17962>;
  <D.17965>:
  family = 2;
  goto <D.17962>;
  <D.17966>:
  family = 4;
  goto <D.17962>;
  <D.17967>:
  family = 22;
  goto <D.17962>;
  <D.17968>:
  family = 12;
  goto <D.17962>;
  <D.17969>:
  family = 5;
  goto <D.17962>;
  <D.17970>:
  family = 10;
  goto <D.17962>;
  <D.17971>:
  family = 23;
  goto <D.17962>;
  <D.17972>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unknown value 0x%x", mono_family);
  <D.17962>:
  D.18729 = family;
  return D.18729;
}


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

  proto = -1;
  switch (mono_proto) <default: <D.18020>, case -1: <D.18019>, case 0: <D.18004>, case 1: <D.18006>, case 2: <D.18007>, case 3: <D.18008>, case 6: <D.18009>, case 12: <D.18010>, case 17: <D.18011>, case 22: <D.18012>, case 41: <D.18005>, case 77: <D.18014>, case 255: <D.18015>, case 1000: <D.18016>, case 1256: <D.18017>, case 1257: <D.18018>>
  <D.18004>:
  <D.18005>:
  <D.18006>:
  <D.18007>:
  <D.18008>:
  <D.18009>:
  <D.18010>:
  <D.18011>:
  <D.18012>:
  proto = mono_proto;
  goto <D.18013>;
  <D.18014>:
  <D.18015>:
  <D.18016>:
  <D.18017>:
  <D.18018>:
  <D.18019>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.ProtocolType has unsupported value 0x%x", mono_proto);
  goto <D.18013>;
  <D.18020>:
  goto <D.18013>;
  <D.18013>:
  D.18731 = proto;
  return D.18731;
}


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

  type = -1;
  switch (mono_type) <default: <D.17999>, case -1: <D.17998>, case 1: <D.17992>, case 2: <D.17994>, case 3: <D.17995>, case 4: <D.17996>, case 5: <D.17997>>
  <D.17992>:
  type = 1;
  goto <D.17993>;
  <D.17994>:
  type = 2;
  goto <D.17993>;
  <D.17995>:
  type = 3;
  goto <D.17993>;
  <D.17996>:
  type = 4;
  goto <D.17993>;
  <D.17997>:
  type = 5;
  goto <D.17993>;
  <D.17998>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unsupported value 0x%x", mono_type);
  goto <D.17993>;
  <D.17999>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unknown value 0x%x", mono_type);
  <D.17993>:
  D.18734 = type;
  return D.18734;
}


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.18737;

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


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

  try
    {
      *error = 0;
      ret = ioctlsocket (sock, 21531, &amount);
      if (ret == -1) goto <D.18739>; else goto <D.18740>;
      <D.18739>:
      D.18741 = WSAGetLastError ();
      *error = D.18741;
      D.18742 = 0;
      return D.18742;
      <D.18740>:
      D.18742 = amount;
      return D.18742;
    }
  finally
    {
      amount = {CLOBBER};
    }
}


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

  *error = 0;
  block.1 = block;
  D.18746 = block.1 == 0;
  block.2 = (int) D.18746;
  block = block.2;
  ret = ioctlsocket (sock, 21537, &block);
  if (ret == -1) goto <D.18748>; else goto <D.18749>;
  <D.18748>:
  D.18750 = WSAGetLastError ();
  *error = D.18750;
  <D.18749>:
}


ves_icall_System_Net_Sockets_Socket_Accept_internal (SOCKET sock, gint32 * error, gboolean blocking)
{
  int D.18753;
  void * D.18754;
  SOCKET newsock;

  *error = 0;
  newsock = _wapi_accept (sock, 0B, 0B);
  if (newsock == 4294967295) goto <D.18751>; else goto <D.18752>;
  <D.18751>:
  D.18753 = WSAGetLastError ();
  *error = D.18753;
  D.18754 = 0B;
  return D.18754;
  <D.18752>:
  D.18754 = (void *) newsock;
  return D.18754;
}


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

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


ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.18760;
  int D.18761;
  unsigned int salen.4;
  unsigned int salen.5;
  struct MonoObject * D.18766;
  gchar * iftmp.6;
  int D.18773;
  int salen.7;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.18760 = convert_family (af);
      D.18761 = get_sockaddr_size (D.18760);
      salen.4 = (unsigned int) D.18761;
      salen = salen.4;
      salen.5 = salen;
      if (salen.5 == 0) goto <D.18764>; else goto <D.18765>;
      <D.18764>:
      *error = 10047;
      D.18766 = 0B;
      return D.18766;
      <D.18765>:
      salen.5 = salen;
      if (salen.5 <= 128) goto <D.18768>; else goto <D.18769>;
      <D.18768>:
      salen.5 = salen;
      iftmp.6 = __builtin_alloca (salen.5);
      goto <D.18770>;
      <D.18769>:
      salen.5 = salen;
      iftmp.6 = monoeg_malloc0 (salen.5);
      <D.18770>:
      sa = iftmp.6;
      ret = _wapi_getsockname (sock, sa, &salen);
      if (ret == -1) goto <D.18771>; else goto <D.18772>;
      <D.18771>:
      D.18773 = WSAGetLastError ();
      *error = D.18773;
      salen.5 = salen;
      if (salen.5 > 128) goto <D.18774>; else goto <D.18775>;
      <D.18774>:
      monoeg_g_free (sa);
      <D.18775>:
      D.18766 = 0B;
      return D.18766;
      <D.18772>:
      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.18777>; else goto <D.18778>;
      <D.18777>:
      monoeg_g_free (sa);
      <D.18778>:
      D.18766 = result;
      return D.18766;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


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

  size = 0;
  if (family == 2) goto <D.18781>; else goto <D.18782>;
  <D.18781>:
  size = 16;
  goto <D.18783>;
  <D.18782>:
  if (family == 10) goto <D.18784>; else goto <D.18785>;
  <D.18784>:
  size = 28;
  goto <D.18786>;
  <D.18785>:
  if (family == 1) goto <D.18787>; else goto <D.18788>;
  <D.18787>:
  size = 110;
  <D.18788>:
  <D.18786>:
  <D.18783>:
  D.18789 = size;
  return D.18789;
}


create_object_from_sockaddr (struct sockaddr * saddr, int sa_size, gint32 * error)
{
  struct MonoClass * D.18791;
  struct MonoImage * D.18794;
  struct MonoClass * D.18795;
  _Bool D.18796;
  long int D.18797;
  long int D.18798;
  struct MonoClassField * D.18801;
  struct MonoClassField * D.18804;
  _Bool D.18805;
  long int D.18806;
  long int D.18807;
  int D.18810;
  unsigned int D.18811;
  struct MonoClass * D.18189;
  struct MonoClass * tmp_klass.8;
  struct MonoClass * D.18815;
  struct MonoClass * tmp_klass.9;
  _Bool D.18817;
  long int D.18818;
  long int D.18819;
  struct MonoVTable * D.18822;
  short unsigned int D.18823;
  int D.18824;
  struct MonoObject * D.18827;
  unsigned char D.18828;
  int D.18829;
  unsigned char D.18830;
  short unsigned int port.10;
  int D.18833;
  int D.18834;
  short unsigned int D.18837;
  signed short D.18838;
  int D.18839;
  signed short D.18840;
  signed short D.18841;
  unsigned int D.18843;
  struct MonoImage * D.18846;
  struct MonoException * D.18847;
  short unsigned int D.18848;
  unsigned char D.18849;
  unsigned char D.18850;
  unsigned int D.18851;
  unsigned char D.18852;
  unsigned int D.18853;
  unsigned char D.18854;
  unsigned int D.18855;
  unsigned char D.18856;
  unsigned char D.18857;
  short unsigned int port.11;
  int D.18860;
  int D.18861;
  short unsigned int D.18864;
  signed short D.18865;
  int D.18866;
  signed short D.18867;
  signed short D.18868;
  struct MonoImage * D.18872;
  struct MonoException * D.18873;
  short unsigned int D.18874;
  unsigned char D.18875;
  unsigned char D.18876;
  struct in6_addr * D.18877;
  int D.18878;
  int D.18881;
  unsigned int D.18882;
  unsigned char D.18884;
  unsigned int D.18885;
  unsigned char D.18886;
  unsigned int D.18887;
  unsigned char D.18888;
  unsigned int D.18889;
  unsigned char D.18890;
  unsigned int D.18891;
  unsigned char D.18892;
  int D.18895;
  unsigned int D.18896;
  char D.18897;
  unsigned char D.18898;
  struct MonoDomain * domain;
  struct MonoObject * sockaddr_obj;
  struct MonoArray * data;
  MonoAddressFamily family;

  domain = mono_domain_get ();
  D.18791 = domain->sockaddr_class;
  if (D.18791 == 0B) goto <D.18792>; else goto <D.18793>;
  <D.18792>:
  D.18794 = get_socket_assembly ();
  D.18795 = mono_class_from_name (D.18794, "System.Net", "SocketAddress");
  domain->sockaddr_class = D.18795;
  D.18791 = domain->sockaddr_class;
  D.18796 = D.18791 == 0B;
  D.18797 = (long int) D.18796;
  D.18798 = __builtin_expect (D.18797, 0);
  if (D.18798 != 0) goto <D.18799>; else goto <D.18800>;
  <D.18799>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 935, "domain->sockaddr_class");
  <D.18800>:
  <D.18793>:
  D.18791 = domain->sockaddr_class;
  sockaddr_obj = mono_object_new (domain, D.18791);
  D.18801 = domain->sockaddr_data_field;
  if (D.18801 == 0B) goto <D.18802>; else goto <D.18803>;
  <D.18802>:
  D.18791 = domain->sockaddr_class;
  D.18804 = mono_class_get_field_from_name (D.18791, "data");
  domain->sockaddr_data_field = D.18804;
  D.18801 = domain->sockaddr_data_field;
  D.18805 = D.18801 == 0B;
  D.18806 = (long int) D.18805;
  D.18807 = __builtin_expect (D.18806, 0);
  if (D.18807 != 0) goto <D.18808>; else goto <D.18809>;
  <D.18808>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 942, "domain->sockaddr_data_field");
  <D.18809>:
  <D.18803>:
  D.18810 = sa_size + 2;
  D.18811 = (unsigned int) D.18810;
  {
    static struct MonoClass * tmp_klass;

    {
      tmp_klass.8 = tmp_klass;
      if (tmp_klass.8 == 0B) goto <D.18813>; else goto <D.18814>;
      <D.18813>:
      D.18815 = mono_get_byte_class ();
      tmp_klass.9 = mono_array_class_get (D.18815, 1);
      tmp_klass = tmp_klass.9;
      tmp_klass.8 = tmp_klass;
      D.18817 = tmp_klass.8 == 0B;
      D.18818 = (long int) D.18817;
      D.18819 = __builtin_expect (D.18818, 0);
      if (D.18819 != 0) goto <D.18820>; else goto <D.18821>;
      <D.18820>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 949, "tmp_klass");
      <D.18821>:
      <D.18814>:
    }
    D.18189 = tmp_klass;
  }
  D.18822 = mono_class_vtable (domain, D.18189);
  data = mono_array_new_specific (D.18822, D.18811);
  D.18823 = saddr->sa_family;
  D.18824 = (int) D.18823;
  family = convert_to_mono_family (D.18824);
  if (family == -1) goto <D.18825>; else goto <D.18826>;
  <D.18825>:
  *error = 10047;
  D.18827 = 0B;
  return D.18827;
  <D.18826>:
  {
    guint8 * __p;

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

    __p = mono_array_addr_with_size (data, 1, 1);
    D.18829 = family >> 8;
    D.18830 = (unsigned char) D.18829;
    *__p = D.18830;
  }
  D.18823 = saddr->sa_family;
  if (D.18823 == 2) goto <D.18831>; else goto <D.18832>;
  <D.18831>:
  {
    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.18833 = (int) __x;
        D.18834 = __builtin_constant_p (D.18833);
        if (D.18834 != 0) goto <D.18835>; else goto <D.18836>;
        <D.18835>:
        D.18837 = __x >> 8;
        D.18838 = (signed short) D.18837;
        D.18833 = (int) __x;
        D.18839 = D.18833 << 8;
        D.18840 = (signed short) D.18839;
        D.18841 = D.18838 | D.18840;
        __v = (short unsigned int) D.18841;
        goto <D.18842>;
        <D.18836>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.18842>:
      }
      port.10 = __v;
    }
    port = port.10;
    D.18843 = sa_in->sin_addr.s_addr;
    address = __bswap_32 (D.18843);
    if (sa_size <= 7) goto <D.18844>; else goto <D.18845>;
    <D.18844>:
    D.18846 = mono_get_corlib ();
    D.18847 = mono_exception_from_name (D.18846, "System", "SystemException");
    mono_raise_exception (D.18847);
    <D.18845>:
    {
      guint8 * __p;

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

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

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

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

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

      __p = mono_array_addr_with_size (data, 1, 7);
      D.18857 = (unsigned char) address;
      *__p = D.18857;
    }
    D.18801 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.18801, data);
    D.18827 = sockaddr_obj;
    return D.18827;
  }
  <D.18832>:
  D.18823 = saddr->sa_family;
  if (D.18823 == 10) goto <D.18858>; else goto <D.18859>;
  <D.18858>:
  {
    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.18860 = (int) __x;
        D.18861 = __builtin_constant_p (D.18860);
        if (D.18861 != 0) goto <D.18862>; else goto <D.18863>;
        <D.18862>:
        D.18864 = __x >> 8;
        D.18865 = (signed short) D.18864;
        D.18860 = (int) __x;
        D.18866 = D.18860 << 8;
        D.18867 = (signed short) D.18866;
        D.18868 = D.18865 | D.18867;
        __v = (short unsigned int) D.18868;
        goto <D.18869>;
        <D.18863>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.18869>:
      }
      port.11 = __v;
    }
    port = port.11;
    if (sa_size <= 27) goto <D.18870>; else goto <D.18871>;
    <D.18870>:
    D.18872 = mono_get_corlib ();
    D.18873 = mono_exception_from_name (D.18872, "System", "SystemException");
    mono_raise_exception (D.18873);
    <D.18871>:
    {
      guint8 * __p;

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

      __p = mono_array_addr_with_size (data, 1, 3);
      D.18876 = (unsigned char) port;
      *__p = D.18876;
    }
    D.18877 = &sa_in->sin6_addr;
    D.18878 = is_ipv4_mapped_any (D.18877);
    if (D.18878 != 0) goto <D.18879>; else goto <D.18880>;
    <D.18879>:
    i = 0;
    goto <D.18214>;
    <D.18213>:
    {
      guint8 * __p;

      D.18881 = i + 8;
      D.18882 = (unsigned int) D.18881;
      __p = mono_array_addr_with_size (data, 1, D.18882);
      *__p = 0;
    }
    i = i + 1;
    <D.18214>:
    if (i <= 15) goto <D.18213>; else goto <D.18215>;
    <D.18215>:
    goto <D.18883>;
    <D.18880>:
    i = 0;
    goto <D.18218>;
    <D.18217>:
    {
      guint8 * __p;

      D.18881 = i + 8;
      D.18882 = (unsigned int) D.18881;
      __p = mono_array_addr_with_size (data, 1, D.18882);
      D.18884 = sa_in->sin6_addr.__in6_u.__u6_addr8[i];
      *__p = D.18884;
    }
    i = i + 1;
    <D.18218>:
    if (i <= 15) goto <D.18217>; else goto <D.18219>;
    <D.18219>:
    <D.18883>:
    {
      guint8 * __p;

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

      __p = mono_array_addr_with_size (data, 1, 25);
      D.18885 = sa_in->sin6_scope_id;
      D.18887 = D.18885 >> 8;
      D.18888 = (unsigned char) D.18887;
      *__p = D.18888;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 26);
      D.18885 = sa_in->sin6_scope_id;
      D.18889 = D.18885 >> 16;
      D.18890 = (unsigned char) D.18889;
      *__p = D.18890;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 27);
      D.18885 = sa_in->sin6_scope_id;
      D.18891 = D.18885 >> 24;
      D.18892 = (unsigned char) D.18891;
      *__p = D.18892;
    }
    D.18801 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.18801, data);
    D.18827 = sockaddr_obj;
    return D.18827;
  }
  <D.18859>:
  D.18823 = saddr->sa_family;
  if (D.18823 == 1) goto <D.18893>; else goto <D.18894>;
  <D.18893>:
  {
    int i;

    i = 0;
    goto <D.18227>;
    <D.18226>:
    {
      guint8 * __p;

      D.18895 = i + 2;
      D.18896 = (unsigned int) D.18895;
      __p = mono_array_addr_with_size (data, 1, D.18896);
      D.18897 = saddr->sa_data[i];
      D.18898 = (unsigned char) D.18897;
      *__p = D.18898;
    }
    i = i + 1;
    <D.18227>:
    if (i < sa_size) goto <D.18226>; else goto <D.18228>;
    <D.18228>:
    D.18801 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.18801, data);
    D.18827 = sockaddr_obj;
    return D.18827;
  }
  <D.18894>:
  *error = 10047;
  D.18827 = 0B;
  return D.18827;
}


get_socket_assembly ()
{
  struct MonoImage * D.18900;
  struct MonoImage * D.18907;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.18900 = domain->socket_assembly;
  if (D.18900 == 0B) goto <D.18901>; else goto <D.18902>;
  <D.18901>:
  {
    struct MonoImage * socket_assembly;

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

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


convert_to_mono_family (guint16 af_family)
{
  int D.18909;
  MonoAddressFamily D.18910;
  MonoAddressFamily family;

  family = -1;
  D.18909 = (int) af_family;
  switch (D.18909) <default: <D.17987>, case 0: <D.17977>, case 1: <D.17979>, case 2: <D.17980>, case 4: <D.17981>, case 5: <D.17984>, case 10: <D.17985>, case 12: <D.17983>, case 22: <D.17982>, case 23: <D.17986>>
  <D.17977>:
  family = 0;
  goto <D.17978>;
  <D.17979>:
  family = 1;
  goto <D.17978>;
  <D.17980>:
  family = 2;
  goto <D.17978>;
  <D.17981>:
  family = 6;
  goto <D.17978>;
  <D.17982>:
  family = 11;
  goto <D.17978>;
  <D.17983>:
  family = 12;
  goto <D.17978>;
  <D.17984>:
  family = 16;
  goto <D.17978>;
  <D.17985>:
  family = 23;
  goto <D.17978>;
  <D.17986>:
  family = 26;
  goto <D.17978>;
  <D.17987>:
  D.18909 = (int) af_family;
  monoeg_g_log (0B, 16, "unknown address family 0x%x", D.18909);
  <D.17978>:
  D.18910 = family;
  return D.18910;
}


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

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


is_ipv4_mapped_any (const struct in6_addr * addr)
{
  unsigned char D.18914;
  gboolean D.18917;
  short unsigned int D.18918;
  short unsigned int D.18919;
  int i;

  i = 0;
  goto <D.18174>;
  <D.18173>:
  D.18914 = addr->__in6_u.__u6_addr8[i];
  if (D.18914 != 0) goto <D.18915>; else goto <D.18916>;
  <D.18915>:
  D.18917 = 0;
  return D.18917;
  <D.18916>:
  i = i + 1;
  <D.18174>:
  if (i <= 9) goto <D.18173>; else goto <D.18175>;
  <D.18175>:
  D.18918 = BIT_FIELD_REF <*addr, 16, 80>;
  D.18919 = D.18918;
  if (D.18919 != 65535) goto <D.18920>; else goto <D.18921>;
  <D.18920>:
  D.18917 = 0;
  return D.18917;
  <D.18921>:
  i = 12;
  goto <D.18177>;
  <D.18176>:
  D.18914 = addr->__in6_u.__u6_addr8[i];
  if (D.18914 != 0) goto <D.18922>; else goto <D.18923>;
  <D.18922>:
  D.18917 = 0;
  return D.18917;
  <D.18923>:
  i = i + 1;
  <D.18177>:
  if (i <= 15) goto <D.18176>; else goto <D.18178>;
  <D.18178>:
  D.18917 = 1;
  return D.18917;
}


ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.18925;
  int D.18926;
  unsigned int salen.12;
  unsigned int salen.13;
  struct MonoObject * D.18931;
  gchar * iftmp.14;
  int D.18938;
  int salen.15;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.18925 = convert_family (af);
      D.18926 = get_sockaddr_size (D.18925);
      salen.12 = (unsigned int) D.18926;
      salen = salen.12;
      salen.13 = salen;
      if (salen.13 == 0) goto <D.18929>; else goto <D.18930>;
      <D.18929>:
      *error = 10047;
      D.18931 = 0B;
      return D.18931;
      <D.18930>:
      salen.13 = salen;
      if (salen.13 <= 128) goto <D.18933>; else goto <D.18934>;
      <D.18933>:
      salen.13 = salen;
      iftmp.14 = __builtin_alloca (salen.13);
      goto <D.18935>;
      <D.18934>:
      salen.13 = salen;
      iftmp.14 = monoeg_malloc0 (salen.13);
      <D.18935>:
      sa = iftmp.14;
      ret = _wapi_getpeername (sock, sa, &salen);
      if (ret == -1) goto <D.18936>; else goto <D.18937>;
      <D.18936>:
      D.18938 = WSAGetLastError ();
      *error = D.18938;
      salen.13 = salen;
      if (salen.13 > 128) goto <D.18939>; else goto <D.18940>;
      <D.18939>:
      monoeg_g_free (sa);
      <D.18940>:
      D.18931 = 0B;
      return D.18931;
      <D.18937>:
      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.18942>; else goto <D.18943>;
      <D.18942>:
      monoeg_g_free (sa);
      <D.18943>:
      D.18931 = result;
      return D.18931;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


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

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.18946 = *error;
      if (D.18946 != 0) goto <D.18947>; else goto <D.18948>;
      <D.18947>:
      return;
      <D.18948>:
      sa_size.16 = sa_size;
      ret = _wapi_bind (sock, sa, sa_size.16);
      if (ret == -1) goto <D.18950>; else goto <D.18951>;
      <D.18950>:
      D.18952 = WSAGetLastError ();
      *error = D.18952;
      <D.18951>:
      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.18956;
  struct MonoClass * D.18957;
  int D.18958;
  sizetype D.18959;
  struct MonoArray * * D.18960;
  unsigned int D.18961;
  struct MonoImage * D.18964;
  struct MonoException * D.18965;
  char * D.18966;
  unsigned char D.18967;
  int D.18968;
  char * D.18969;
  unsigned char D.18970;
  int D.18971;
  int D.18972;
  int D.18973;
  struct MonoImage * D.18978;
  struct MonoException * D.18979;
  char * D.18980;
  unsigned char D.18981;
  short unsigned int D.18982;
  short unsigned int D.18983;
  char * D.18984;
  unsigned char D.18985;
  short unsigned int D.18986;
  char * D.18987;
  unsigned char D.18988;
  int D.18989;
  int D.18990;
  char * D.18991;
  unsigned char D.18992;
  int D.18993;
  int D.18994;
  int D.18995;
  char * D.18996;
  unsigned char D.18997;
  int D.18998;
  int D.18999;
  int D.19000;
  char * D.19001;
  unsigned char D.19002;
  int D.19003;
  int D.19004;
  short unsigned int D.19005;
  unsigned int D.19006;
  short unsigned int D.18265;
  int D.19007;
  int D.19008;
  short unsigned int D.19011;
  signed short D.19012;
  int D.19013;
  signed short D.19014;
  signed short D.19015;
  struct sockaddr * D.19017;
  struct MonoImage * D.19022;
  struct MonoException * D.19023;
  char * D.19024;
  unsigned char D.19025;
  short unsigned int D.19026;
  char * D.19027;
  unsigned char D.19028;
  short unsigned int D.19029;
  short unsigned int D.19030;
  char * D.19031;
  unsigned char D.19032;
  int D.19033;
  char * D.19034;
  unsigned char D.19035;
  int D.19036;
  int D.19037;
  int D.19038;
  char * D.19039;
  unsigned char D.19040;
  int D.19041;
  int D.19042;
  int D.19043;
  char * D.19044;
  unsigned char D.19045;
  int D.19046;
  int D.19047;
  int D.19048;
  short unsigned int D.18272;
  int D.19049;
  int D.19050;
  short unsigned int D.19053;
  signed short D.19054;
  int D.19055;
  signed short D.19056;
  signed short D.19057;
  int D.19059;
  unsigned int D.19060;
  char * D.19061;
  unsigned char D.19062;
  struct MonoException * D.19067;
  int D.19068;
  unsigned int D.19069;
  char * D.19070;
  unsigned char D.19071;
  char D.19072;
  int D.19073;
  unsigned int len.17;
  struct MonoClassField * field;
  struct MonoArray * data;
  gint32 family;
  int len;

  D.18956 = saddr_obj->vtable;
  D.18957 = D.18956->klass;
  field = mono_class_get_field_from_name (D.18957, "data");
  D.18958 = field->offset;
  D.18959 = (sizetype) D.18958;
  D.18960 = saddr_obj + D.18959;
  data = *D.18960;
  D.18961 = mono_array_length (data);
  len = (int) D.18961;
  if (len <= 1) goto <D.18962>; else goto <D.18963>;
  <D.18962>:
  D.18964 = mono_get_corlib ();
  D.18965 = mono_exception_from_name (D.18964, "System", "SystemException");
  mono_raise_exception (D.18965);
  <D.18963>:
  D.18966 = mono_array_addr_with_size (data, 1, 0);
  D.18967 = MEM[(guint8 *)D.18966];
  D.18968 = (int) D.18967;
  D.18969 = mono_array_addr_with_size (data, 1, 1);
  D.18970 = MEM[(guint8 *)D.18969];
  D.18971 = (int) D.18970;
  D.18972 = D.18971 << 8;
  D.18973 = D.18968 + D.18972;
  family = convert_family (D.18973);
  if (family == 2) goto <D.18974>; else goto <D.18975>;
  <D.18974>:
  {
    struct sockaddr_in * sa;
    guint16 port;
    guint32 address;

    if (len <= 7) goto <D.18976>; else goto <D.18977>;
    <D.18976>:
    D.18978 = mono_get_corlib ();
    D.18979 = mono_exception_from_name (D.18978, "System", "SystemException");
    mono_raise_exception (D.18979);
    <D.18977>:
    sa = monoeg_malloc0 (16);
    D.18980 = mono_array_addr_with_size (data, 1, 2);
    D.18981 = MEM[(guint8 *)D.18980];
    D.18982 = (short unsigned int) D.18981;
    D.18983 = D.18982 << 8;
    D.18984 = mono_array_addr_with_size (data, 1, 3);
    D.18985 = MEM[(guint8 *)D.18984];
    D.18986 = (short unsigned int) D.18985;
    port = D.18983 + D.18986;
    D.18987 = mono_array_addr_with_size (data, 1, 4);
    D.18988 = MEM[(guint8 *)D.18987];
    D.18989 = (int) D.18988;
    D.18990 = D.18989 << 24;
    D.18991 = mono_array_addr_with_size (data, 1, 5);
    D.18992 = MEM[(guint8 *)D.18991];
    D.18993 = (int) D.18992;
    D.18994 = D.18993 << 16;
    D.18995 = D.18990 + D.18994;
    D.18996 = mono_array_addr_with_size (data, 1, 6);
    D.18997 = MEM[(guint8 *)D.18996];
    D.18998 = (int) D.18997;
    D.18999 = D.18998 << 8;
    D.19000 = D.18995 + D.18999;
    D.19001 = mono_array_addr_with_size (data, 1, 7);
    D.19002 = MEM[(guint8 *)D.19001];
    D.19003 = (int) D.19002;
    D.19004 = D.19000 + D.19003;
    address = (guint32) D.19004;
    D.19005 = (short unsigned int) family;
    sa->sin_family = D.19005;
    D.19006 = __bswap_32 (address);
    sa->sin_addr.s_addr = D.19006;
    {
      short unsigned int __v;
      short unsigned int __x;

      __x = port;
      {
        D.19007 = (int) __x;
        D.19008 = __builtin_constant_p (D.19007);
        if (D.19008 != 0) goto <D.19009>; else goto <D.19010>;
        <D.19009>:
        D.19011 = __x >> 8;
        D.19012 = (signed short) D.19011;
        D.19007 = (int) __x;
        D.19013 = D.19007 << 8;
        D.19014 = (signed short) D.19013;
        D.19015 = D.19012 | D.19014;
        __v = (short unsigned int) D.19015;
        goto <D.19016>;
        <D.19010>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.19016>:
      }
      D.18265 = __v;
    }
    sa->sin_port = D.18265;
    *sa_size = 16;
    D.19017 = sa;
    return D.19017;
  }
  <D.18975>:
  if (family == 10) goto <D.19018>; else goto <D.19019>;
  <D.19018>:
  {
    struct sockaddr_in6 * sa;
    int i;
    guint16 port;
    guint32 scopeid;

    if (len <= 27) goto <D.19020>; else goto <D.19021>;
    <D.19020>:
    D.19022 = mono_get_corlib ();
    D.19023 = mono_exception_from_name (D.19022, "System", "SystemException");
    mono_raise_exception (D.19023);
    <D.19021>:
    sa = monoeg_malloc0 (28);
    D.19024 = mono_array_addr_with_size (data, 1, 3);
    D.19025 = MEM[(guint8 *)D.19024];
    D.19026 = (short unsigned int) D.19025;
    D.19027 = mono_array_addr_with_size (data, 1, 2);
    D.19028 = MEM[(guint8 *)D.19027];
    D.19029 = (short unsigned int) D.19028;
    D.19030 = D.19029 << 8;
    port = D.19026 + D.19030;
    D.19031 = mono_array_addr_with_size (data, 1, 24);
    D.19032 = MEM[(guint8 *)D.19031];
    D.19033 = (int) D.19032;
    D.19034 = mono_array_addr_with_size (data, 1, 25);
    D.19035 = MEM[(guint8 *)D.19034];
    D.19036 = (int) D.19035;
    D.19037 = D.19036 << 8;
    D.19038 = D.19033 + D.19037;
    D.19039 = mono_array_addr_with_size (data, 1, 26);
    D.19040 = MEM[(guint8 *)D.19039];
    D.19041 = (int) D.19040;
    D.19042 = D.19041 << 16;
    D.19043 = D.19038 + D.19042;
    D.19044 = mono_array_addr_with_size (data, 1, 27);
    D.19045 = MEM[(guint8 *)D.19044];
    D.19046 = (int) D.19045;
    D.19047 = D.19046 << 24;
    D.19048 = D.19043 + D.19047;
    scopeid = (guint32) D.19048;
    D.19005 = (short unsigned int) family;
    sa->sin6_family = D.19005;
    {
      short unsigned int __v;
      short unsigned int __x;

      __x = port;
      {
        D.19049 = (int) __x;
        D.19050 = __builtin_constant_p (D.19049);
        if (D.19050 != 0) goto <D.19051>; else goto <D.19052>;
        <D.19051>:
        D.19053 = __x >> 8;
        D.19054 = (signed short) D.19053;
        D.19049 = (int) __x;
        D.19055 = D.19049 << 8;
        D.19056 = (signed short) D.19055;
        D.19057 = D.19054 | D.19056;
        __v = (short unsigned int) D.19057;
        goto <D.19058>;
        <D.19052>:
        __asm__("rorw $8, %w0" : "=r" __v : "0" __x : "cc");
        <D.19058>:
      }
      D.18272 = __v;
    }
    sa->sin6_port = D.18272;
    sa->sin6_scope_id = scopeid;
    i = 0;
    goto <D.18274>;
    <D.18273>:
    D.19059 = i + 8;
    D.19060 = (unsigned int) D.19059;
    D.19061 = mono_array_addr_with_size (data, 1, D.19060);
    D.19062 = MEM[(guint8 *)D.19061];
    sa->sin6_addr.__in6_u.__u6_addr8[i] = D.19062;
    i = i + 1;
    <D.18274>:
    if (i <= 15) goto <D.18273>; else goto <D.18275>;
    <D.18275>:
    *sa_size = 28;
    D.19017 = sa;
    return D.19017;
  }
  <D.19019>:
  if (family == 1) goto <D.19063>; else goto <D.19064>;
  <D.19063>:
  {
    struct sockaddr_un * sock_un;
    int i;

    if (len > 1) goto <D.19065>; else goto <D.19066>;
    <D.19065>:
    D.19067 = mono_get_exception_index_out_of_range ();
    mono_raise_exception (D.19067);
    <D.19066>:
    sock_un = monoeg_malloc0 (110);
    D.19005 = (short unsigned int) family;
    sock_un->sun_family = D.19005;
    i = 0;
    goto <D.18279>;
    <D.18278>:
    D.19068 = i + 2;
    D.19069 = (unsigned int) D.19068;
    D.19070 = mono_array_addr_with_size (data, 1, D.19069);
    D.19071 = MEM[(guint8 *)D.19070];
    D.19072 = (char) D.19071;
    sock_un->sun_path[i] = D.19072;
    i = i + 1;
    <D.18279>:
    D.19073 = len + -2;
    if (D.19073 > i) goto <D.18278>; else goto <D.18280>;
    <D.18280>:
    len.17 = (unsigned int) len;
    *sa_size = len.17;
    D.19017 = sock_un;
    return D.19017;
  }
  <D.19064>:
  *error = 10047;
  D.19017 = 0B;
  return D.19017;
}


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.19089;
  _Bool D.19090;
  _Bool D.19091;
  int * D.19094;
  long int D.19095;
  int D.19096;
  int D.19101;
  MonoBoolean D.19108;
  unsigned int D.19112;
  unsigned int D.19113;
  int D.19114;
  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.19078>; else goto <D.19079>;
  <D.19078>:
  if (mode == 1) goto <D.19081>; else goto <D.19082>;
  <D.19081>:
  iftmp.20 = 4;
  goto <D.19083>;
  <D.19082>:
  iftmp.20 = 56;
  <D.19083>:
  iftmp.19 = iftmp.20;
  goto <D.19084>;
  <D.19079>:
  iftmp.19 = 1;
  <D.19084>:
  pfds->events = iftmp.19;
  if (timeout >= 0) goto <D.19086>; else goto <D.19087>;
  <D.19086>:
  iftmp.21 = timeout / 1000;
  goto <D.19088>;
  <D.19087>:
  iftmp.21 = -1;
  <D.19088>:
  timeout = iftmp.21;
  start = time (0B);
  <D.18306>:
  *error = 0;
  ret = mono_poll (pfds, 1, timeout);
  D.19089 = timeout > 0;
  D.19090 = ret < 0;
  D.19091 = D.19089 & D.19090;
  if (D.19091 != 0) goto <D.19092>; else goto <D.19093>;
  <D.19092>:
  {
    int err;
    int sec;

    D.19094 = __errno_location ();
    err = *D.19094;
    D.19095 = time (0B);
    sec = D.19095 - start;
    D.19096 = sec * -1000;
    timeout = D.19096 + timeout;
    if (timeout < 0) goto <D.19097>; else goto <D.19098>;
    <D.19097>:
    timeout = 0;
    <D.19098>:
    D.19094 = __errno_location ();
    *D.19094 = err;
  }
  <D.19093>:
  if (ret == -1) goto <D.19099>; else goto <D.19100>;
  <D.19099>:
  D.19094 = __errno_location ();
  D.19101 = *D.19094;
  if (D.19101 == 4) goto <D.19102>; else goto <D.19103>;
  <D.19102>:
  {
    int leave;

    leave = 0;
    if (thread == 0B) goto <D.19104>; else goto <D.19105>;
    <D.19104>:
    thread = mono_thread_internal_current ();
    <D.19105>:
    leave = mono_thread_test_state (thread, 129);
    if (leave != 0) goto <D.19106>; else goto <D.19107>;
    <D.19106>:
    monoeg_g_free (pfds);
    D.19108 = 0;
    return D.19108;
    <D.19107>:
    mono_thread_interruption_checkpoint ();
    D.19094 = __errno_location ();
    *D.19094 = 4;
  }
  <D.19103>:
  <D.19100>:
  if (ret == -1) goto <D.19109>; else goto <D.18307>;
  <D.19109>:
  D.19094 = __errno_location ();
  D.19101 = *D.19094;
  if (D.19101 == 4) goto <D.18306>; else goto <D.18307>;
  <D.18307>:
  if (ret == -1) goto <D.19110>; else goto <D.19111>;
  <D.19110>:
  D.19094 = __errno_location ();
  D.19101 = *D.19094;
  D.19112 = (unsigned int) D.19101;
  D.19113 = errno_to_WSA (D.19112, &__func__);
  D.19114 = (int) D.19113;
  *error = D.19114;
  monoeg_g_free (pfds);
  D.19108 = 0;
  return D.19108;
  <D.19111>:
  monoeg_g_free (pfds);
  if (ret == 0) goto <D.19115>; else goto <D.19116>;
  <D.19115>:
  D.19108 = 0;
  return D.19108;
  <D.19116>:
  D.19108 = 1;
  return D.19108;
}


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

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.19118 = *error;
      if (D.19118 != 0) goto <D.19119>; else goto <D.19120>;
      <D.19119>:
      return;
      <D.19120>:
      sa_size.22 = sa_size;
      ret = _wapi_connect (sock, sa, sa_size.22);
      if (ret == -1) goto <D.19122>; else goto <D.19123>;
      <D.19122>:
      D.19124 = WSAGetLastError ();
      *error = D.19124;
      <D.19123>:
      monoeg_g_free (sa);
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Disconnect_internal (SOCKET sock, MonoBoolean reuse, gint32 * error)
{
  gboolean (*<T19d9>) (guint32, struct WapiOverlapped *, guint32, WapiTransmitFileFlags) _wapi_disconnectex.23;
  gboolean (*<T19e0>) (guint32, void *, guint32, guint32, struct WapiOverlapped *, struct WapiTransmitFileBuffers *, WapiTransmitFileFlags) _wapi_transmitfile.24;
  int D.19142;
  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, 4, &output_bytes, 0B, 0B);
      if (ret != 0) goto <D.19128>; else goto <D.19129>;
      <D.19128>:
      _wapi_disconnectex = 0B;
      ret = WSAIoctl (sock, -939524090, &trans_guid, 16, &_wapi_transmitfile, 4, &output_bytes, 0B, 0B);
      if (ret != 0) goto <D.19130>; else goto <D.19131>;
      <D.19130>:
      _wapi_transmitfile = 0B;
      <D.19131>:
      <D.19129>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      if (_wapi_disconnectex.23 != 0B) goto <D.19133>; else goto <D.19134>;
      <D.19133>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      bret = _wapi_disconnectex.23 (sock, 0B, 2, 0);
      goto <D.19135>;
      <D.19134>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      if (_wapi_transmitfile.24 != 0B) goto <D.19137>; else goto <D.19138>;
      <D.19137>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      bret = _wapi_transmitfile.24 (sock, 0B, 0, 0, 0B, 0B, 3);
      goto <D.19139>;
      <D.19138>:
      *error = 50;
      return;
      <D.19139>:
      <D.19135>:
      if (bret == 0) goto <D.19140>; else goto <D.19141>;
      <D.19140>:
      D.19142 = WSAGetLastError ();
      *error = D.19142;
      <D.19141>:
    }
  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)
{
  unsigned int D.19146;
  int D.19147;
  gint32 D.19150;
  unsigned int offset.25;
  unsigned int count.26;
  int D.19157;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;

  recvflags = 0;
  *error = 0;
  D.19146 = mono_array_length (buffer);
  alen = (gint32) D.19146;
  D.19147 = alen - count;
  if (D.19147 < offset) goto <D.19148>; else goto <D.19149>;
  <D.19148>:
  D.19150 = 0;
  return D.19150;
  <D.19149>:
  offset.25 = (unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, offset.25);
  recvflags = convert_socketflags (flags);
  if (recvflags == -1) goto <D.19152>; else goto <D.19153>;
  <D.19152>:
  *error = 10045;
  D.19150 = 0;
  return D.19150;
  <D.19153>:
  count.26 = (unsigned int) count;
  ret = _wapi_recv (sock, buf, count.26, recvflags);
  if (ret == -1) goto <D.19155>; else goto <D.19156>;
  <D.19155>:
  D.19157 = WSAGetLastError ();
  *error = D.19157;
  D.19150 = 0;
  return D.19150;
  <D.19156>:
  D.19150 = ret;
  return D.19150;
}


convert_socketflags (gint32 sflags)
{
  gint32 D.19161;
  int D.19162;
  int D.19165;
  int D.19168;
  int D.19171;
  int D.19174;
  gint32 flags;

  flags = 0;
  if (sflags == 0) goto <D.19159>; else goto <D.19160>;
  <D.19159>:
  D.19161 = 0;
  return D.19161;
  <D.19160>:
  D.19162 = sflags & -32792;
  if (D.19162 != 0) goto <D.19163>; else goto <D.19164>;
  <D.19163>:
  D.19161 = -1;
  return D.19161;
  <D.19164>:
  D.19165 = sflags & 1;
  if (D.19165 != 0) goto <D.19166>; else goto <D.19167>;
  <D.19166>:
  flags = flags | 1;
  <D.19167>:
  D.19168 = sflags & 2;
  if (D.19168 != 0) goto <D.19169>; else goto <D.19170>;
  <D.19169>:
  flags = flags | 2;
  <D.19170>:
  D.19171 = sflags & 4;
  if (D.19171 != 0) goto <D.19172>; else goto <D.19173>;
  <D.19172>:
  flags = flags | 4;
  <D.19173>:
  D.19174 = sflags & 32768;
  if (D.19174 != 0) goto <D.19175>; else goto <D.19176>;
  <D.19175>:
  flags = flags | 32768;
  <D.19176>:
  D.19161 = flags;
  return D.19161;
}


ves_icall_System_Net_Sockets_Socket_Receive_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  unsigned int D.19178;
  int D.19179;
  unsigned int recvflags.27;
  unsigned int recvflags.28;
  gint32 D.19184;
  unsigned int count.29;
  int D.19188;
  unsigned int recv.30;
  int ret;
  int count;
  DWORD recv;
  struct WSABUF * wsabufs;
  DWORD recvflags;

  try
    {
      recvflags = 0;
      *error = 0;
      wsabufs = mono_array_addr_with_size (buffers, 8, 0);
      D.19178 = mono_array_length (buffers);
      count = (int) D.19178;
      D.19179 = convert_socketflags (flags);
      recvflags.27 = (unsigned int) D.19179;
      recvflags = recvflags.27;
      recvflags.28 = recvflags;
      if (recvflags.28 == 4294967295) goto <D.19182>; else goto <D.19183>;
      <D.19182>:
      *error = 10045;
      D.19184 = 0;
      return D.19184;
      <D.19183>:
      count.29 = (unsigned int) count;
      ret = WSARecv (sock, wsabufs, count.29, &recv, &recvflags, 0B, 0B);
      if (ret == -1) goto <D.19186>; else goto <D.19187>;
      <D.19186>:
      D.19188 = WSAGetLastError ();
      *error = D.19188;
      D.19184 = 0;
      return D.19184;
      <D.19187>:
      recv.30 = recv;
      D.19184 = (gint32) recv.30;
      return D.19184;
    }
  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)
{
  unsigned int D.19192;
  int D.19193;
  gint32 D.19196;
  struct MonoObject * D.19197;
  int D.19198;
  unsigned int offset.31;
  unsigned int count.32;
  int D.19207;
  unsigned int sa_size.33;
  int sa_size.34;
  struct MonoObject * D.19212;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      recvflags = 0;
      *error = 0;
      D.19192 = mono_array_length (buffer);
      alen = (gint32) D.19192;
      D.19193 = alen - count;
      if (D.19193 < offset) goto <D.19194>; else goto <D.19195>;
      <D.19194>:
      D.19196 = 0;
      return D.19196;
      <D.19195>:
      D.19197 = *sockaddr;
      sa = create_sockaddr_from_object (D.19197, &sa_size, error);
      D.19198 = *error;
      if (D.19198 != 0) goto <D.19199>; else goto <D.19200>;
      <D.19199>:
      D.19196 = 0;
      return D.19196;
      <D.19200>:
      offset.31 = (unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, offset.31);
      recvflags = convert_socketflags (flags);
      if (recvflags == -1) goto <D.19202>; else goto <D.19203>;
      <D.19202>:
      *error = 10045;
      D.19196 = 0;
      return D.19196;
      <D.19203>:
      count.32 = (unsigned int) count;
      ret = _wapi_recvfrom (sock, buf, count.32, recvflags, sa, &sa_size);
      if (ret == -1) goto <D.19205>; else goto <D.19206>;
      <D.19205>:
      monoeg_g_free (sa);
      D.19207 = WSAGetLastError ();
      *error = D.19207;
      D.19196 = 0;
      return D.19196;
      <D.19206>:
      sa_size.33 = sa_size;
      if (sa_size.33 != 0) goto <D.19209>; else goto <D.19210>;
      <D.19209>:
      sa_size.33 = sa_size;
      sa_size.34 = (int) sa_size.33;
      D.19212 = create_object_from_sockaddr (sa, sa_size.34, error);
      *sockaddr = D.19212;
      goto <D.19213>;
      <D.19210>:
      *sockaddr = 0B;
      <D.19213>:
      monoeg_g_free (sa);
      D.19196 = ret;
      return D.19196;
    }
  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)
{
  unsigned int D.19216;
  int D.19217;
  gint32 D.19220;
  unsigned int offset.35;
  unsigned int count.36;
  int D.19227;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;

  sendflags = 0;
  *error = 0;
  D.19216 = mono_array_length (buffer);
  alen = (gint32) D.19216;
  D.19217 = alen - count;
  if (D.19217 < offset) goto <D.19218>; else goto <D.19219>;
  <D.19218>:
  D.19220 = 0;
  return D.19220;
  <D.19219>:
  offset.35 = (unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, offset.35);
  sendflags = convert_socketflags (flags);
  if (sendflags == -1) goto <D.19222>; else goto <D.19223>;
  <D.19222>:
  *error = 10045;
  D.19220 = 0;
  return D.19220;
  <D.19223>:
  count.36 = (unsigned int) count;
  ret = _wapi_send (sock, buf, count.36, sendflags);
  if (ret == -1) goto <D.19225>; else goto <D.19226>;
  <D.19225>:
  D.19227 = WSAGetLastError ();
  *error = D.19227;
  D.19220 = 0;
  return D.19220;
  <D.19226>:
  D.19220 = ret;
  return D.19220;
}


ves_icall_System_Net_Sockets_Socket_Send_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  unsigned int D.19229;
  int D.19230;
  gint32 D.19233;
  unsigned int count.37;
  int D.19237;
  unsigned int sent.38;
  int ret;
  int count;
  DWORD sent;
  struct WSABUF * wsabufs;
  DWORD sendflags;

  try
    {
      sendflags = 0;
      *error = 0;
      wsabufs = mono_array_addr_with_size (buffers, 8, 0);
      D.19229 = mono_array_length (buffers);
      count = (int) D.19229;
      D.19230 = convert_socketflags (flags);
      sendflags = (DWORD) D.19230;
      if (sendflags == 4294967295) goto <D.19231>; else goto <D.19232>;
      <D.19231>:
      *error = 10045;
      D.19233 = 0;
      return D.19233;
      <D.19232>:
      count.37 = (unsigned int) count;
      ret = WSASend (sock, wsabufs, count.37, &sent, sendflags, 0B, 0B);
      if (ret == -1) goto <D.19235>; else goto <D.19236>;
      <D.19235>:
      D.19237 = WSAGetLastError ();
      *error = D.19237;
      D.19233 = 0;
      return D.19233;
      <D.19236>:
      sent.38 = sent;
      D.19233 = (gint32) sent.38;
      return D.19233;
    }
  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)
{
  unsigned int D.19241;
  int D.19242;
  gint32 D.19245;
  int D.19246;
  unsigned int offset.39;
  unsigned int sa_size.40;
  unsigned int count.41;
  int D.19256;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      sendflags = 0;
      *error = 0;
      D.19241 = mono_array_length (buffer);
      alen = (gint32) D.19241;
      D.19242 = alen - count;
      if (D.19242 < offset) goto <D.19243>; else goto <D.19244>;
      <D.19243>:
      D.19245 = 0;
      return D.19245;
      <D.19244>:
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.19246 = *error;
      if (D.19246 != 0) goto <D.19247>; else goto <D.19248>;
      <D.19247>:
      D.19245 = 0;
      return D.19245;
      <D.19248>:
      offset.39 = (unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, offset.39);
      sendflags = convert_socketflags (flags);
      if (sendflags == -1) goto <D.19250>; else goto <D.19251>;
      <D.19250>:
      *error = 10045;
      D.19245 = 0;
      return D.19245;
      <D.19251>:
      sa_size.40 = sa_size;
      count.41 = (unsigned int) count;
      ret = _wapi_sendto (sock, buf, count.41, sendflags, sa, sa_size.40);
      if (ret == -1) goto <D.19254>; else goto <D.19255>;
      <D.19254>:
      D.19256 = WSAGetLastError ();
      *error = D.19256;
      <D.19255>:
      monoeg_g_free (sa);
      D.19245 = ret;
      return D.19245;
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Select_internal (struct MonoArray * * sockets, gint32 timeout, gint32 * error)
{
  struct MonoArray * D.19259;
  unsigned int D.19260;
  unsigned int nfds.42;
  unsigned int D.19262;
  unsigned int i.43;
  char * D.19264;
  unsigned int idx.44;
  unsigned int D.19270;
  struct mono_pollfd * D.19271;
  unsigned int D.19272;
  int D.19273;
  short int iftmp.45;
  short int iftmp.46;
  int iftmp.47;
  _Bool D.19286;
  _Bool D.19287;
  _Bool D.19288;
  int * D.19291;
  long int D.19292;
  int D.19293;
  int D.19298;
  unsigned int D.19308;
  unsigned int D.19309;
  int D.19310;
  struct MonoVTable * D.19313;
  unsigned int ret.48;
  unsigned int socks_size.49;
  struct MonoDomain * D.19316;
  char * D.19317;
  int D.19320;
  unsigned int D.19321;
  unsigned int D.19322;
  short int D.19323;
  int D.19329;
  int D.19330;
  int idx.50;
  unsigned int idx.51;
  int D.19337;
  int idx.52;
  unsigned int idx.53;
  int D.19341;
  int idx.54;
  unsigned int idx.55;
  _Bool D.19346;
  _Bool D.19347;
  _Bool D.19348;
  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.19259 = *sockets;
      D.19260 = mono_array_length (D.19259);
      count = (int) D.19260;
      nfds = count + -3;
      nfds.42 = (unsigned int) nfds;
      D.19262 = nfds.42 * 8;
      pfds = monoeg_malloc0 (D.19262);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.18430>;
      <D.18429>:
      i.43 = (unsigned int) i;
      D.19259 = *sockets;
      D.19264 = mono_array_addr_with_size (D.19259, 4, i.43);
      obj = MEM[(struct MonoObject * *)D.19264];
      if (obj == 0B) goto <D.19265>; else goto <D.19266>;
      <D.19265>:
      mode = mode + 1;
      // predicted unlikely by continue predictor.
      goto <D.18428>;
      <D.19266>:
      if (idx >= nfds) goto <D.19267>; else goto <D.19268>;
      <D.19267>:
      monoeg_g_free (pfds);
      *error = 10014;
      return;
      <D.19268>:
      idx.44 = (unsigned int) idx;
      D.19270 = idx.44 * 8;
      D.19271 = pfds + D.19270;
      D.19272 = Socket_to_SOCKET (obj);
      D.19273 = (int) D.19272;
      D.19271->fd = D.19273;
      idx.44 = (unsigned int) idx;
      D.19270 = idx.44 * 8;
      D.19271 = pfds + D.19270;
      if (mode != 0) goto <D.19275>; else goto <D.19276>;
      <D.19275>:
      if (mode == 1) goto <D.19278>; else goto <D.19279>;
      <D.19278>:
      iftmp.46 = 4;
      goto <D.19280>;
      <D.19279>:
      iftmp.46 = 56;
      <D.19280>:
      iftmp.45 = iftmp.46;
      goto <D.19281>;
      <D.19276>:
      iftmp.45 = 1;
      <D.19281>:
      D.19271->events = iftmp.45;
      idx = idx + 1;
      <D.18428>:
      i = i + 1;
      <D.18430>:
      if (i < count) goto <D.18429>; else goto <D.18431>;
      <D.18431>:
      if (timeout >= 0) goto <D.19283>; else goto <D.19284>;
      <D.19283>:
      iftmp.47 = timeout / 1000;
      goto <D.19285>;
      <D.19284>:
      iftmp.47 = -1;
      <D.19285>:
      timeout = iftmp.47;
      start = time (0B);
      <D.18435>:
      *error = 0;
      nfds.42 = (unsigned int) nfds;
      ret = mono_poll (pfds, nfds.42, timeout);
      D.19286 = timeout > 0;
      D.19287 = ret < 0;
      D.19288 = D.19286 & D.19287;
      if (D.19288 != 0) goto <D.19289>; else goto <D.19290>;
      <D.19289>:
      {
        int err;
        int sec;

        D.19291 = __errno_location ();
        err = *D.19291;
        D.19292 = time (0B);
        sec = D.19292 - start;
        D.19293 = sec * -1000;
        timeout = D.19293 + timeout;
        if (timeout < 0) goto <D.19294>; else goto <D.19295>;
        <D.19294>:
        timeout = 0;
        <D.19295>:
        D.19291 = __errno_location ();
        *D.19291 = err;
      }
      <D.19290>:
      if (ret == -1) goto <D.19296>; else goto <D.19297>;
      <D.19296>:
      D.19291 = __errno_location ();
      D.19298 = *D.19291;
      if (D.19298 == 4) goto <D.19299>; else goto <D.19300>;
      <D.19299>:
      {
        int leave;

        leave = 0;
        if (thread == 0B) goto <D.19301>; else goto <D.19302>;
        <D.19301>:
        thread = mono_thread_internal_current ();
        <D.19302>:
        leave = mono_thread_test_state (thread, 129);
        if (leave != 0) goto <D.19303>; else goto <D.19304>;
        <D.19303>:
        monoeg_g_free (pfds);
        *sockets = 0B;
        return;
        <D.19304>:
        mono_thread_interruption_checkpoint ();
        D.19291 = __errno_location ();
        *D.19291 = 4;
      }
      <D.19300>:
      <D.19297>:
      if (ret == -1) goto <D.19305>; else goto <D.18436>;
      <D.19305>:
      D.19291 = __errno_location ();
      D.19298 = *D.19291;
      if (D.19298 == 4) goto <D.18435>; else goto <D.18436>;
      <D.18436>:
      if (ret == -1) goto <D.19306>; else goto <D.19307>;
      <D.19306>:
      D.19291 = __errno_location ();
      D.19298 = *D.19291;
      D.19308 = (unsigned int) D.19298;
      D.19309 = errno_to_WSA (D.19308, &__func__);
      D.19310 = (int) D.19309;
      *error = D.19310;
      monoeg_g_free (pfds);
      return;
      <D.19307>:
      if (ret == 0) goto <D.19311>; else goto <D.19312>;
      <D.19311>:
      monoeg_g_free (pfds);
      *sockets = 0B;
      return;
      <D.19312>:
      D.19259 = *sockets;
      D.19313 = MEM[(struct MonoObject *)D.19259].vtable;
      sock_arr_class = D.19313->klass;
      ret.48 = (unsigned int) ret;
      socks_size.49 = ret.48 + 3;
      socks_size = socks_size.49;
      D.19316 = mono_domain_get ();
      socks = mono_array_new_full (D.19316, sock_arr_class, &socks_size, 0B);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.18444>;
      <D.18443>:
      {
        struct mono_pollfd * pfd;

        i.43 = (unsigned int) i;
        D.19259 = *sockets;
        D.19317 = mono_array_addr_with_size (D.19259, 4, i.43);
        obj = MEM[(struct MonoObject * *)D.19317];
        if (obj == 0B) goto <D.19318>; else goto <D.19319>;
        <D.19318>:
        mode = mode + 1;
        idx = idx + 1;
        // predicted unlikely by continue predictor.
        goto <D.18439>;
        <D.19319>:
        D.19320 = i - mode;
        D.19321 = (unsigned int) D.19320;
        D.19322 = D.19321 * 8;
        pfd = pfds + D.19322;
        D.19323 = pfd->revents;
        if (D.19323 == 0) goto <D.19324>; else goto <D.19325>;
        <D.19324>:
        // predicted unlikely by continue predictor.
        goto <D.18439>;
        <D.19325>:
        ret = ret + -1;
        if (mode == 0) goto <D.19328>; else goto <D.19326>;
        <D.19328>:
        D.19323 = pfd->revents;
        D.19329 = (int) D.19323;
        D.19330 = D.19329 & 57;
        if (D.19330 != 0) goto <D.19331>; else goto <D.19326>;
        <D.19331>:
        {
          void * * __p;

          idx.50 = idx;
          idx = idx.50 + 1;
          idx.51 = (unsigned int) idx.50;
          __p = mono_array_addr_with_size (socks, 4, idx.51);
          mono_gc_wbarrier_set_arrayref (socks, __p, obj);
        }
        goto <D.19327>;
        <D.19326>:
        if (mode == 1) goto <D.19336>; else goto <D.19334>;
        <D.19336>:
        D.19323 = pfd->revents;
        D.19329 = (int) D.19323;
        D.19337 = D.19329 & 60;
        if (D.19337 != 0) goto <D.19338>; else goto <D.19334>;
        <D.19338>:
        {
          void * * __p;

          idx.52 = idx;
          idx = idx.52 + 1;
          idx.53 = (unsigned int) idx.52;
          __p = mono_array_addr_with_size (socks, 4, idx.53);
          mono_gc_wbarrier_set_arrayref (socks, __p, obj);
        }
        goto <D.19335>;
        <D.19334>:
        D.19323 = pfd->revents;
        D.19329 = (int) D.19323;
        D.19341 = D.19329 & 56;
        if (D.19341 != 0) goto <D.19342>; else goto <D.19343>;
        <D.19342>:
        {
          void * * __p;

          idx.54 = idx;
          idx = idx.54 + 1;
          idx.55 = (unsigned int) idx.54;
          __p = mono_array_addr_with_size (socks, 4, idx.55);
          mono_gc_wbarrier_set_arrayref (socks, __p, obj);
        }
        <D.19343>:
        <D.19335>:
        <D.19327>:
      }
      <D.18439>:
      i = i + 1;
      <D.18444>:
      D.19346 = i < count;
      D.19347 = ret > 0;
      D.19348 = D.19346 & D.19347;
      if (D.19348 != 0) goto <D.18443>; else goto <D.18445>;
      <D.18445>:
      *sockets = socks;
      monoeg_g_free (pfds);
    }
  finally
    {
      socks_size = {CLOBBER};
    }
}


Socket_to_SOCKET (struct MonoObject * sockobj)
{
  struct MonoVTable * D.19352;
  struct MonoClass * D.19353;
  int D.19354;
  sizetype D.19355;
  void * * D.19356;
  void * D.19357;
  SOCKET D.19358;
  SOCKET sock;
  struct MonoClassField * field;

  D.19352 = sockobj->vtable;
  D.19353 = D.19352->klass;
  field = mono_class_get_field_from_name (D.19353, "socket");
  D.19354 = field->offset;
  D.19355 = (sizetype) D.19354;
  D.19356 = sockobj + D.19355;
  D.19357 = *D.19356;
  sock = (SOCKET) D.19357;
  D.19358 = sock;
  return D.19358;
}


ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal (SOCKET sock, gint32 level, gint32 name, struct MonoObject * * obj_val, gint32 * error)
{
  _Bool D.19360;
  _Bool D.19361;
  _Bool D.19362;
  <unnamed type> level.56;
  struct MonoObject * D.19371;
  int system_name.57;
  int system_level.58;
  int D.19376;
  struct MonoImage * D.19377;
  int D.19378;
  sizetype D.19379;
  guint8 * D.19380;
  int D.19381;
  unsigned char D.19382;
  guint32 * D.19383;
  int D.19384;
  unsigned int D.19385;
  _Bool D.19386;
  int D.19387;
  int time_ms.59;
  struct MonoImage * mono_posix_image.60;
  struct MonoImage * mono_posix_image.61;
  struct MonoImage * mono_posix_image.62;
  int D.19398;
  unsigned int D.19399;
  int D.19400;
  unsigned int D.19401;
  int D.19402;
  int val.63;
  _Bool D.19406;
  int val.64;
  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.19360 = level == 65535;
      D.19361 = name == -5;
      D.19362 = D.19360 & D.19361;
      if (D.19362 != 0) goto <D.19363>; else goto <D.19364>;
      <D.19363>:
      system_level = 1;
      system_name = 2;
      ret = 0;
      goto <D.19365>;
      <D.19364>:
      level.56 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.56, name, &system_level, &system_name);
      <D.19365>:
      if (ret == -1) goto <D.19367>; else goto <D.19368>;
      <D.19367>:
      *error = 10042;
      return;
      <D.19368>:
      if (ret == -2) goto <D.19369>; else goto <D.19370>;
      <D.19369>:
      D.19371 = int_to_object (domain, 0);
      *obj_val = D.19371;
      return;
      <D.19370>:
      switch (name) <default: <D.18478>, case -129: <D.18473>, case 128: <D.18472>, case 4101: <D.18475>, case 4102: <D.18476>, case 10001: <D.18477>>
      <D.18472>:
      <D.18473>:
      system_name.57 = system_name;
      system_level.58 = system_level;
      ret = _wapi_getsockopt (sock, system_level.58, system_name.57, &linger, &lingersize);
      goto <D.18474>;
      <D.18475>:
      <D.18476>:
      system_name.57 = system_name;
      system_level.58 = system_level;
      ret = _wapi_getsockopt (sock, system_level.58, system_name.57, &time_ms, &time_ms_size);
      goto <D.18474>;
      <D.18477>:
      system_name.57 = system_name;
      system_level.58 = system_level;
      ret = _wapi_getsockopt (sock, system_level.58, system_name.57, &cred, &credsize);
      goto <D.18474>;
      <D.18478>:
      system_name.57 = system_name;
      system_level.58 = system_level;
      ret = _wapi_getsockopt (sock, system_level.58, system_name.57, &val, &valsize);
      <D.18474>:
      if (ret == -1) goto <D.19374>; else goto <D.19375>;
      <D.19374>:
      D.19376 = WSAGetLastError ();
      *error = D.19376;
      return;
      <D.19375>:
      switch (name) <default: <D.18488>, case -129: <D.18481>, case 128: <D.18479>, case 4101: <D.18482>, case 4102: <D.18483>, case 10001: <D.18484>>
      <D.18479>:
      D.19377 = get_socket_assembly ();
      obj_class = mono_class_from_name (D.19377, "System.Net.Sockets", "LingerOption");
      obj = mono_object_new (domain, obj_class);
      field = mono_class_get_field_from_name (obj_class, "enabled");
      D.19378 = field->offset;
      D.19379 = (sizetype) D.19378;
      D.19380 = obj + D.19379;
      D.19381 = linger.l_onoff;
      D.19382 = (unsigned char) D.19381;
      *D.19380 = D.19382;
      field = mono_class_get_field_from_name (obj_class, "seconds");
      D.19378 = field->offset;
      D.19379 = (sizetype) D.19378;
      D.19383 = obj + D.19379;
      D.19384 = linger.l_linger;
      D.19385 = (unsigned int) D.19384;
      *D.19383 = D.19385;
      goto <D.18480>;
      <D.18481>:
      D.19381 = linger.l_onoff;
      D.19386 = D.19381 == 0;
      D.19387 = (int) D.19386;
      obj = int_to_object (domain, D.19387);
      goto <D.18480>;
      <D.18482>:
      <D.18483>:
      time_ms.59 = time_ms;
      obj = int_to_object (domain, time_ms.59);
      goto <D.18480>;
      <D.18484>:
      {
        static struct MonoImage * mono_posix_image = 0B;
        struct MonoPeerCredData * cred_data;

        mono_posix_image.60 = mono_posix_image;
        if (mono_posix_image.60 == 0B) goto <D.19390>; else goto <D.19391>;
        <D.19390>:
        mono_posix_image.61 = mono_image_loaded ("Mono.Posix");
        mono_posix_image = mono_posix_image.61;
        mono_posix_image.60 = mono_posix_image;
        if (mono_posix_image.60 == 0B) goto <D.19393>; else goto <D.19394>;
        <D.19393>:
        {
          struct MonoAssembly * sa;

          sa = mono_assembly_open ("Mono.Posix.dll", 0B);
          if (sa == 0B) goto <D.19395>; else goto <D.19396>;
          <D.19395>:
          *error = 10042;
          return;
          <D.19396>:
          mono_posix_image.62 = mono_assembly_get_image (sa);
          mono_posix_image = mono_posix_image.62;
        }
        <D.19394>:
        <D.19391>:
        mono_posix_image.60 = mono_posix_image;
        obj_class = mono_class_from_name (mono_posix_image.60, "Mono.Posix", "PeerCredData");
        obj = mono_object_new (domain, obj_class);
        cred_data = obj;
        D.19398 = cred.pid;
        cred_data->pid = D.19398;
        D.19399 = cred.uid;
        D.19400 = (int) D.19399;
        cred_data->uid = D.19400;
        D.19401 = cred.gid;
        D.19402 = (int) D.19401;
        cred_data->gid = D.19402;
        goto <D.18480>;
      }
      <D.18488>:
      D.19360 = level == 65535;
      D.19361 = name == -5;
      D.19362 = D.19360 & D.19361;
      if (D.19362 != 0) goto <D.19403>; else goto <D.19404>;
      <D.19403>:
      val.63 = val;
      D.19406 = val.63 == 0;
      val.64 = (int) D.19406;
      val = val.64;
      <D.19404>:
      val.63 = val;
      obj = int_to_object (domain, val.63);
      <D.18480>:
      *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.19411;
  int cached.65;
  int iftmp.66;
  int proto.67;

  switch (mono_level) <default: <D.18104>, case 0: <D.18056>, case 6: <D.18093>, case 17: <D.18100>, case 41: <D.18074>, case 65535: <D.18031>>
  <D.18031>:
  *system_level = 1;
  switch (mono_name) <default: <D.18054>, case -129: <D.18032>, case -5: <D.18051>, case 1: <D.18034>, case 2: <D.18035>, case 4: <D.18036>, case 8: <D.18037>, case 16: <D.18038>, case 32: <D.18039>, case 64: <D.18052>, case 128: <D.18040>, case 256: <D.18041>, case 4097: <D.18042>, case 4098: <D.18043>, case 4099: <D.18044>, case 4100: <D.18045>, case 4101: <D.18046>, case 4102: <D.18047>, case 4103: <D.18048>, case 4104: <D.18049>, case 10001: <D.18050>, case 2147483647: <D.18053>>
  <D.18032>:
  *system_name = 13;
  goto <D.18033>;
  <D.18034>:
  *system_name = 1;
  goto <D.18033>;
  <D.18035>:
  *system_name = 30;
  goto <D.18033>;
  <D.18036>:
  *system_name = 2;
  goto <D.18033>;
  <D.18037>:
  *system_name = 9;
  goto <D.18033>;
  <D.18038>:
  *system_name = 5;
  goto <D.18033>;
  <D.18039>:
  *system_name = 6;
  goto <D.18033>;
  <D.18040>:
  *system_name = 13;
  goto <D.18033>;
  <D.18041>:
  *system_name = 10;
  goto <D.18033>;
  <D.18042>:
  *system_name = 7;
  goto <D.18033>;
  <D.18043>:
  *system_name = 8;
  goto <D.18033>;
  <D.18044>:
  *system_name = 19;
  goto <D.18033>;
  <D.18045>:
  *system_name = 18;
  goto <D.18033>;
  <D.18046>:
  *system_name = 21;
  goto <D.18033>;
  <D.18047>:
  *system_name = 20;
  goto <D.18033>;
  <D.18048>:
  *system_name = 4;
  goto <D.18033>;
  <D.18049>:
  *system_name = 3;
  goto <D.18033>;
  <D.18050>:
  *system_name = 17;
  goto <D.18033>;
  <D.18051>:
  <D.18052>:
  <D.18053>:
  *system_name = 128;
  goto <D.18033>;
  <D.18054>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at Socket level", mono_name);
  D.19411 = -1;
  return D.19411;
  <D.18033>:
  goto <D.18055>;
  <D.18056>:
  *system_level = 0;
  switch (mono_name) <default: <D.18073>, case 1: <D.18057>, case 2: <D.18059>, case 3: <D.18060>, case 4: <D.18061>, case 9: <D.18062>, case 10: <D.18063>, case 11: <D.18064>, case 12: <D.18065>, case 13: <D.18066>, case 14: <D.18068>, case 15: <D.18069>, case 16: <D.18070>, case 17: <D.18071>, case 18: <D.18072>, case 19: <D.18067>>
  <D.18057>:
  *system_name = 4;
  goto <D.18058>;
  <D.18059>:
  *system_name = 3;
  goto <D.18058>;
  <D.18060>:
  *system_name = 1;
  goto <D.18058>;
  <D.18061>:
  *system_name = 2;
  goto <D.18058>;
  <D.18062>:
  *system_name = 32;
  goto <D.18058>;
  <D.18063>:
  *system_name = 33;
  goto <D.18058>;
  <D.18064>:
  *system_name = 34;
  goto <D.18058>;
  <D.18065>:
  *system_name = 35;
  goto <D.18058>;
  <D.18066>:
  *system_name = 36;
  goto <D.18058>;
  <D.18067>:
  *system_name = 8;
  goto <D.18058>;
  <D.18068>:
  *system_name = 10;
  goto <D.18058>;
  <D.18069>:
  <D.18070>:
  <D.18071>:
  <D.18072>:
  <D.18073>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IP level", mono_name);
  D.19411 = -1;
  return D.19411;
  <D.18058>:
  goto <D.18055>;
  <D.18074>:
  *system_level = 41;
  switch (mono_name) <default: <D.18092>, case 1: <D.18085>, case 2: <D.18084>, case 3: <D.18086>, case 4: <D.18075>, case 9: <D.18078>, case 10: <D.18079>, case 11: <D.18080>, case 12: <D.18081>, case 13: <D.18082>, case 14: <D.18087>, case 15: <D.18088>, case 16: <D.18089>, case 17: <D.18090>, case 18: <D.18091>, case 19: <D.18083>, case 21: <D.18076>>
  <D.18075>:
  <D.18076>:
  *system_name = 16;
  goto <D.18077>;
  <D.18078>:
  *system_name = 17;
  goto <D.18077>;
  <D.18079>:
  *system_name = 18;
  goto <D.18077>;
  <D.18080>:
  *system_name = 19;
  goto <D.18077>;
  <D.18081>:
  *system_name = 20;
  goto <D.18077>;
  <D.18082>:
  *system_name = 21;
  goto <D.18077>;
  <D.18083>:
  *system_name = 50;
  goto <D.18077>;
  <D.18084>:
  <D.18085>:
  <D.18086>:
  <D.18087>:
  <D.18088>:
  <D.18089>:
  <D.18090>:
  <D.18091>:
  <D.18092>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IPv6 level", mono_name);
  D.19411 = -1;
  return D.19411;
  <D.18077>:
  goto <D.18055>;
  <D.18093>:
  if (1 != 0) goto <D.19412>; else goto <D.19413>;
  <D.19412>:
  {
    static int cached = 0;
    static int proto;

    cached.65 = cached;
    if (cached.65 == 0) goto <D.19415>; else goto <D.19416>;
    <D.19415>:
    {
      struct protoent * pent;

      pent = getprotobyname ("TCP");
      if (pent != 0B) goto <D.19418>; else goto <D.19419>;
      <D.19418>:
      iftmp.66 = pent->p_proto;
      goto <D.19420>;
      <D.19419>:
      iftmp.66 = 6;
      <D.19420>:
      proto = iftmp.66;
      cached = 1;
    }
    <D.19416>:
    proto.67 = proto;
    *system_level = proto.67;
  }
  <D.19413>:
  switch (mono_name) <default: <D.18099>, case 1: <D.18097>>
  <D.18097>:
  *system_name = 1;
  goto <D.18098>;
  <D.18099>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at TCP level", mono_name);
  D.19411 = -1;
  return D.19411;
  <D.18098>:
  goto <D.18055>;
  <D.18100>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unsupported value 0x%x", mono_level);
  switch (mono_name) <default: <D.18103>, case 1: <D.18101>, case 20: <D.18102>>
  <D.18101>:
  <D.18102>:
  <D.18103>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at UDP level", mono_name);
  D.19411 = -1;
  return D.19411;
  D.19411 = -1;
  return D.19411;
  <D.18104>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unknown value 0x%x", mono_level);
  D.19411 = -1;
  return D.19411;
  <D.18055>:
  D.19411 = 0;
  return D.19411;
}


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

  D.19425 = mono_get_int32_class ();
  D.19424 = mono_value_box (domain, D.19425, &val);
  return D.19424;
}


ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal (SOCKET sock, gint32 level, gint32 name, struct MonoArray * * byte_val, gint32 * error)
{
  <unnamed type> level.68;
  struct MonoArray * D.19432;
  unsigned int valsize.69;
  int system_name.70;
  int system_level.71;
  int D.19438;
  int system_level;
  int system_name;
  int ret;
  guchar * buf;
  socklen_t valsize;

  try
    {
      *error = 0;
      level.68 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.68, name, &system_level, &system_name);
      if (ret == -1) goto <D.19428>; else goto <D.19429>;
      <D.19428>:
      *error = 10042;
      return;
      <D.19429>:
      if (ret == -2) goto <D.19430>; else goto <D.19431>;
      <D.19430>:
      return;
      <D.19431>:
      D.19432 = *byte_val;
      valsize.69 = mono_array_length (D.19432);
      valsize = valsize.69;
      D.19432 = *byte_val;
      buf = mono_array_addr_with_size (D.19432, 1, 0);
      system_name.70 = system_name;
      system_level.71 = system_level;
      ret = _wapi_getsockopt (sock, system_level.71, system_name.70, buf, &valsize);
      if (ret == -1) goto <D.19436>; else goto <D.19437>;
      <D.19436>:
      D.19438 = WSAGetLastError ();
      *error = D.19438;
      <D.19437>:
    }
  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.72;
  _Bool D.19443;
  _Bool D.19444;
  _Bool D.19445;
  int int_val.73;
  _Bool D.19449;
  int int_val.74;
  struct MonoVTable * D.19457;
  struct MonoClass * D.19458;
  int D.19459;
  sizetype D.19460;
  guint8 * D.19461;
  unsigned char D.19462;
  int D.19463;
  guint32 * D.19464;
  unsigned int D.19465;
  int D.19466;
  unsigned int valsize.75;
  int system_name.76;
  int system_level.77;
  void * * D.19472;
  guint64 * D.19475;
  long long unsigned int D.19476;
  unsigned int D.19477;
  gint32 * D.19485;
  int D.19486;
  unsigned int D.19490;
  unsigned char D.19493;
  _Bool D.19494;
  int D.19495;
  unsigned int valsize.78;
  unsigned int int_val.79;
  unsigned int D.19500;
  unsigned int D.19501;
  unsigned int D.19502;
  unsigned int D.19503;
  unsigned int D.19504;
  unsigned int D.19505;
  unsigned int D.19506;
  unsigned int D.19507;
  unsigned int D.19508;
  int int_val.80;
  unsigned int D.19510;
  int D.19517;
  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.72 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.72, name, &system_level, &system_name);
      D.19443 = level == 65535;
      D.19444 = name == -5;
      D.19445 = D.19443 & D.19444;
      if (D.19445 != 0) goto <D.19446>; else goto <D.19447>;
      <D.19446>:
      system_name = 2;
      int_val.73 = int_val;
      D.19449 = int_val.73 == 0;
      int_val.74 = (int) D.19449;
      int_val = int_val.74;
      ret = 0;
      <D.19447>:
      if (ret == -1) goto <D.19451>; else goto <D.19452>;
      <D.19451>:
      *error = 10042;
      return;
      <D.19452>:
      if (ret == -2) goto <D.19453>; else goto <D.19454>;
      <D.19453>:
      return;
      <D.19454>:
      if (obj_val != 0B) goto <D.19455>; else goto <D.19456>;
      <D.19455>:
      {
        struct MonoClassField * field;
        int valsize;

        switch (name) <default: <D.18540>, case 12: <D.18535>, case 13: <D.18536>, case 128: <D.18533>>
        <D.18533>:
        D.19457 = obj_val->vtable;
        D.19458 = D.19457->klass;
        field = mono_class_get_field_from_name (D.19458, "enabled");
        D.19459 = field->offset;
        D.19460 = (sizetype) D.19459;
        D.19461 = obj_val + D.19460;
        D.19462 = *D.19461;
        D.19463 = (int) D.19462;
        linger.l_onoff = D.19463;
        D.19457 = obj_val->vtable;
        D.19458 = D.19457->klass;
        field = mono_class_get_field_from_name (D.19458, "seconds");
        D.19459 = field->offset;
        D.19460 = (sizetype) D.19459;
        D.19464 = obj_val + D.19460;
        D.19465 = *D.19464;
        D.19466 = (int) D.19465;
        linger.l_linger = D.19466;
        valsize = 8;
        valsize.75 = (unsigned int) valsize;
        system_name.76 = system_name;
        system_level.77 = system_level;
        ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &linger, valsize.75);
        goto <D.18534>;
        <D.18535>:
        <D.18536>:
        {
          struct MonoObject * address;

          address = 0B;
          system_level.77 = system_level;
          if (system_level.77 == sol_ipv6) goto <D.19470>; else goto <D.19471>;
          <D.19470>:
          {
            struct ipv6_mreq mreq6;

            try
              {
                D.19457 = obj_val->vtable;
                D.19458 = D.19457->klass;
                field = mono_class_get_field_from_name (D.19458, "group");
                D.19459 = field->offset;
                D.19460 = (sizetype) D.19459;
                D.19472 = obj_val + D.19460;
                address = *D.19472;
                if (address != 0B) goto <D.19473>; else goto <D.19474>;
                <D.19473>:
                mreq6.ipv6mr_multiaddr = ipaddress_to_struct_in6_addr (address);
                <D.19474>:
                D.19457 = obj_val->vtable;
                D.19458 = D.19457->klass;
                field = mono_class_get_field_from_name (D.19458, "ifIndex");
                D.19459 = field->offset;
                D.19460 = (sizetype) D.19459;
                D.19475 = obj_val + D.19460;
                D.19476 = *D.19475;
                D.19477 = (unsigned int) D.19476;
                mreq6.ipv6mr_interface = D.19477;
                system_name.76 = system_name;
                system_level.77 = system_level;
                ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &mreq6, 20);
              }
            finally
              {
                mreq6 = {CLOBBER};
              }
          }
          goto <D.19478>;
          <D.19471>:
          system_level.77 = system_level;
          if (system_level.77 == sol_ip) goto <D.19479>; else goto <D.19480>;
          <D.19479>:
          {
            struct ip_mreqn mreq;

            try
              {
                mreq = {};
                D.19457 = obj_val->vtable;
                D.19458 = D.19457->klass;
                field = mono_class_get_field_from_name (D.19458, "group");
                D.19459 = field->offset;
                D.19460 = (sizetype) D.19459;
                D.19472 = obj_val + D.19460;
                address = *D.19472;
                if (address != 0B) goto <D.19481>; else goto <D.19482>;
                <D.19481>:
                mreq.imr_multiaddr = ipaddress_to_struct_in_addr (address);
                <D.19482>:
                D.19457 = obj_val->vtable;
                D.19458 = D.19457->klass;
                field = mono_class_get_field_from_name (D.19458, "local");
                D.19459 = field->offset;
                D.19460 = (sizetype) D.19459;
                D.19472 = obj_val + D.19460;
                address = *D.19472;
                if (address != 0B) goto <D.19483>; else goto <D.19484>;
                <D.19483>:
                mreq.imr_address = ipaddress_to_struct_in_addr (address);
                <D.19484>:
                D.19457 = obj_val->vtable;
                D.19458 = D.19457->klass;
                field = mono_class_get_field_from_name (D.19458, "iface_index");
                D.19459 = field->offset;
                D.19460 = (sizetype) D.19459;
                D.19485 = obj_val + D.19460;
                D.19486 = *D.19485;
                mreq.imr_ifindex = D.19486;
                system_name.76 = system_name;
                system_level.77 = system_level;
                ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &mreq, 12);
              }
            finally
              {
                mreq = {CLOBBER};
              }
          }
          <D.19480>:
          <D.19478>:
          goto <D.18534>;
        }
        <D.18540>:
        *error = 10022;
        return;
        <D.18534>:
      }
      goto <D.19487>;
      <D.19456>:
      if (byte_val != 0B) goto <D.19488>; else goto <D.19489>;
      <D.19488>:
      {
        int valsize;
        guchar * buf;

        D.19490 = mono_array_length (byte_val);
        valsize = (int) D.19490;
        buf = mono_array_addr_with_size (byte_val, 1, 0);
        switch (name) <default: <D.18545>, case -129: <D.18543>>
        <D.18543>:
        if (valsize == 1) goto <D.19491>; else goto <D.19492>;
        <D.19491>:
        D.19493 = *buf;
        D.19494 = D.19493 == 0;
        D.19495 = (int) D.19494;
        linger.l_onoff = D.19495;
        linger.l_linger = 0;
        system_name.76 = system_name;
        system_level.77 = system_level;
        ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &linger, 8);
        goto <D.19496>;
        <D.19492>:
        *error = 10022;
        <D.19496>:
        goto <D.18544>;
        <D.18545>:
        valsize.78 = (unsigned int) valsize;
        system_name.76 = system_name;
        system_level.77 = system_level;
        ret = _wapi_setsockopt (sock, system_level.77, system_name.76, buf, valsize.78);
        goto <D.18544>;
        <D.18544>:
      }
      goto <D.19498>;
      <D.19489>:
      switch (name) <default: <D.18551>, case -129: <D.18546>, case 9: <D.18548>, case 14: <D.18550>>
      <D.18546>:
      int_val.73 = int_val;
      D.19449 = int_val.73 == 0;
      int_val.74 = (int) D.19449;
      linger.l_onoff = int_val.74;
      linger.l_linger = 0;
      system_name.76 = system_name;
      system_level.77 = system_level;
      ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &linger, 8);
      goto <D.18547>;
      <D.18548>:
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19500 = int_val.79 << 24;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19501 = int_val.79 & 16711680;
      D.19502 = D.19501 >> 8;
      D.19503 = D.19500 | D.19502;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19504 = int_val.79 & 65280;
      D.19505 = D.19504 << 8;
      D.19506 = D.19503 | D.19505;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19507 = int_val.79 >> 24;
      D.19508 = D.19506 | D.19507;
      int_val.80 = (int) D.19508;
      int_val = int_val.80;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19510 = int_val.79 & 4278190080;
      if (D.19510 == 0) goto <D.19511>; else goto <D.19512>;
      <D.19511>:
      {
        struct ip_mreqn mreq;

        try
          {
            mreq = {};
            int_val.73 = int_val;
            mreq.imr_ifindex = int_val.73;
            system_name.76 = system_name;
            system_level.77 = system_level;
            ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &mreq, 12);
            goto <D.18547>;
          }
        finally
          {
            mreq = {CLOBBER};
          }
      }
      <D.19512>:
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19500 = int_val.79 << 24;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19501 = int_val.79 & 16711680;
      D.19502 = D.19501 >> 8;
      D.19503 = D.19500 | D.19502;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19504 = int_val.79 & 65280;
      D.19505 = D.19504 << 8;
      D.19506 = D.19503 | D.19505;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19507 = int_val.79 >> 24;
      D.19508 = D.19506 | D.19507;
      int_val.80 = (int) D.19508;
      int_val = int_val.80;
      system_name.76 = system_name;
      system_level.77 = system_level;
      ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &int_val, 4);
      goto <D.18547>;
      <D.18550>:
      int_val.73 = int_val;
      if (int_val.73 == 1) goto <D.19513>; else goto <D.19514>;
      <D.19513>:
      int_val = 2;
      <D.19514>:
      <D.18551>:
      system_name.76 = system_name;
      system_level.77 = system_level;
      ret = _wapi_setsockopt (sock, system_level.77, system_name.76, &int_val, 4);
      <D.18547>:
      <D.19498>:
      <D.19487>:
      if (ret == -1) goto <D.19515>; else goto <D.19516>;
      <D.19515>:
      D.19517 = WSAGetLastError ();
      *error = D.19517;
      <D.19516>:
    }
  finally
    {
      linger = {CLOBBER};
      system_level = {CLOBBER};
      system_name = {CLOBBER};
    }
}


ipaddress_to_struct_in6_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.19523;
  struct MonoClass * D.19524;
  int D.19525;
  sizetype D.19526;
  struct MonoArray * * D.19527;
  unsigned int i.81;
  char * D.19529;
  short unsigned int D.19530;
  struct in6_addr in6addr;
  struct MonoClassField * field;
  struct MonoArray * data;
  int i;

  try
    {
      D.19523 = ipaddr->vtable;
      D.19524 = D.19523->klass;
      field = mono_class_get_field_from_name (D.19524, "m_Numbers");
      D.19525 = field->offset;
      D.19526 = (sizetype) D.19525;
      D.19527 = ipaddr + D.19526;
      data = *D.19527;
      i = 0;
      goto <D.18514>;
      <D.18513>:
      i.81 = (unsigned int) i;
      D.19529 = mono_array_addr_with_size (data, 2, i.81);
      D.19530 = MEM[(guint16 *)D.19529];
      in6addr.__in6_u.__u6_addr16[i] = D.19530;
      i = i + 1;
      <D.18514>:
      if (i <= 7) goto <D.18513>; else goto <D.18515>;
      <D.18515>:
      <retval> = in6addr;
      return <retval>;
    }
  finally
    {
      in6addr = {CLOBBER};
    }
}


ipaddress_to_struct_in_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.19534;
  struct MonoClass * D.19535;
  int D.19536;
  sizetype D.19537;
  guint64 * D.19538;
  long long unsigned int D.19539;
  unsigned int D.19540;
  struct in_addr inaddr;
  struct MonoClassField * field;

  try
    {
      D.19534 = ipaddr->vtable;
      D.19535 = D.19534->klass;
      field = mono_class_get_field_from_name (D.19535, "m_Address");
      D.19536 = field->offset;
      D.19537 = (sizetype) D.19536;
      D.19538 = ipaddr + D.19537;
      D.19539 = *D.19538;
      D.19540 = (unsigned int) D.19539;
      inaddr.s_addr = D.19540;
      <retval> = inaddr;
      return <retval>;
    }
  finally
    {
      inaddr = {CLOBBER};
    }
}


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

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


ves_icall_System_Net_Sockets_Socket_WSAIoctl (SOCKET sock, gint32 code, struct MonoArray * input, struct MonoArray * output, gint32 * error)
{
  int D.19548;
  unsigned int D.19552;
  unsigned int D.19556;
  int D.19559;
  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.19546>; else goto <D.19547>;
      <D.19546>:
      D.19548 = -1;
      return D.19548;
      <D.19547>:
      if (input == 0B) goto <D.19549>; else goto <D.19550>;
      <D.19549>:
      i_buffer = 0B;
      i_len = 0;
      goto <D.19551>;
      <D.19550>:
      i_buffer = mono_array_addr_with_size (input, 1, 0);
      D.19552 = mono_array_length (input);
      i_len = (gint) D.19552;
      <D.19551>:
      if (output == 0B) goto <D.19553>; else goto <D.19554>;
      <D.19553>:
      o_buffer = 0B;
      o_len = 0;
      goto <D.19555>;
      <D.19554>:
      o_buffer = mono_array_addr_with_size (output, 1, 0);
      D.19556 = mono_array_length (output);
      o_len = (gint) D.19556;
      <D.19555>:
      ret = WSAIoctl (sock, code, i_buffer, i_len, o_buffer, o_len, &output_bytes, 0B, 0B);
      if (ret == -1) goto <D.19557>; else goto <D.19558>;
      <D.19557>:
      D.19559 = WSAGetLastError ();
      *error = D.19559;
      D.19548 = -1;
      return D.19548;
      <D.19558>:
      D.19548 = output_bytes;
      return D.19548;
    }
  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.19562;
  int D.19567;
  int D.18664;
  int D.19572;
  int D.19575;
  MonoBoolean D.19578;
  struct addrinfo * info.82;
  int D.19580;
  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.19562 = *hostname;
      if (D.19562 == 0) goto <D.19563>; else goto <D.19564>;
      <D.19563>:
      add_local_ips = 1;
      *h_name = host;
      <D.19564>:
      if (add_local_ips == 0) goto <D.19565>; else goto <D.19566>;
      <D.19565>:
      D.19567 = gethostname (&this_hostname, 256);
      if (D.19567 != -1) goto <D.19568>; else goto <D.19569>;
      <D.19568>:
      {
        size_t __s1_len;
        size_t __s2_len;

        D.18664 = __builtin_strcmp (hostname, &this_hostname);
      }
      if (D.18664 == 0) goto <D.19570>; else goto <D.19571>;
      <D.19570>:
      add_local_ips = 1;
      *h_name = host;
      <D.19571>:
      <D.19569>:
      <D.19566>:
      memset (&hints, 0, 32);
      D.19572 = get_family_hint ();
      hints.ai_family = D.19572;
      hints.ai_socktype = 1;
      hints.ai_flags = 2;
      D.19562 = *hostname;
      if (D.19562 != 0) goto <D.19573>; else goto <D.19574>;
      <D.19573>:
      D.19575 = getaddrinfo (hostname, 0B, &hints, &info);
      if (D.19575 == -1) goto <D.19576>; else goto <D.19577>;
      <D.19576>:
      D.19578 = 0;
      return D.19578;
      <D.19577>:
      <D.19574>:
      monoeg_g_free (hostname);
      info.82 = info;
      D.19580 = addrinfo_to_IPHostEntry (info.82, h_name, h_aliases, h_addr_list, add_local_ips);
      D.19578 = (MonoBoolean) D.19580;
      return D.19578;
    }
  finally
    {
      this_hostname = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
    }
}


gethostname (char * __buf, size_t __buflen)
{
  unsigned int D.19583;
  int D.19586;
  int D.19589;
  unsigned int D.19590;
  unsigned int D.19591;
  unsigned int D.19594;

  D.19583 = __builtin_object_size (__buf, 1);
  if (D.19583 != 4294967295) goto <D.19584>; else goto <D.19585>;
  <D.19584>:
  D.19586 = __builtin_constant_p (__buflen);
  if (D.19586 == 0) goto <D.19587>; else goto <D.19588>;
  <D.19587>:
  D.19590 = __builtin_object_size (__buf, 1);
  D.19589 = __gethostname_chk (__buf, __buflen, D.19590);
  return D.19589;
  <D.19588>:
  D.19591 = __builtin_object_size (__buf, 1);
  if (D.19591 < __buflen) goto <D.19592>; else goto <D.19593>;
  <D.19592>:
  D.19594 = __builtin_object_size (__buf, 1);
  D.19589 = __gethostname_chk_warn (__buf, __buflen, D.19594);
  return D.19589;
  <D.19593>:
  <D.19585>:
  D.19589 = __gethostname_alias (__buf, __buflen);
  return D.19589;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.19598;
  int D.19603;
  void * D.19605;
  unsigned int D.19606;

  D.19598 = __builtin_constant_p (__len);
  if (D.19598 != 0) goto <D.19599>; else goto <D.19600>;
  <D.19599>:
  if (__len == 0) goto <D.19601>; else goto <D.19602>;
  <D.19601>:
  D.19603 = __builtin_constant_p (__ch);
  if (D.19603 == 0) goto <D.19596>; else goto <D.19604>;
  <D.19604>:
  if (__ch != 0) goto <D.19596>; else goto <D.19597>;
  <D.19596>:
  __warn_memset_zero_len ();
  D.19605 = __dest;
  return D.19605;
  <D.19597>:
  <D.19602>:
  <D.19600>:
  D.19606 = __builtin_object_size (__dest, 0);
  D.19605 = __builtin___memset_chk (__dest, __ch, __len, D.19606);
  return D.19605;
}


get_family_hint ()
{
  unsigned char D.19608;
  struct MonoImage * D.19611;
  struct MonoDomain * D.19612;
  _Bool D.19613;
  long int D.19614;
  long int D.19615;
  union mono_mutex_t * D.19618;
  _Bool D.19621;
  long int D.19622;
  long int D.19623;
  int ipv4_enabled.83;
  int ipv6_enabled.84;
  _Bool D.19637;
  long int D.19638;
  long int D.19639;
  int D.19642;
  gint32 D.19643;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.19608 = domain->inet_family_hint;
  if (D.19608 == 0) goto <D.19609>; else goto <D.19610>;
  <D.19609>:
  {
    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.19611 = get_socket_assembly ();
        socket_class = mono_class_from_name (D.19611, "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.19612 = mono_domain_get ();
        vtable = mono_class_vtable (D.19612, socket_class);
        D.19613 = vtable == 0B;
        D.19614 = (long int) D.19613;
        D.19615 = __builtin_expect (D.19614, 0);
        if (D.19615 != 0) goto <D.19616>; else goto <D.19617>;
        <D.19616>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 715, "vtable");
        <D.19617>:
        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.19618 = &domain->lock.mutex;
          ret = pthread_mutex_lock (D.19618);
          if (ret != 0) goto <D.19619>; else goto <D.19620>;
          <D.19619>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d", ret);
          <D.19620>:
          D.19621 = ret != 0;
          D.19622 = (long int) D.19621;
          D.19623 = __builtin_expect (D.19622, 0);
          if (D.19623 != 0) goto <D.19624>; else goto <D.19625>;
          <D.19624>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 721, "ret == 0");
          <D.19625>:
        }
        ipv4_enabled.83 = ipv4_enabled;
        if (ipv4_enabled.83 == 1) goto <D.19629>; else goto <D.19626>;
        <D.19629>:
        ipv6_enabled.84 = ipv6_enabled;
        if (ipv6_enabled.84 == 1) goto <D.19631>; else goto <D.19626>;
        <D.19631>:
        domain->inet_family_hint = 1;
        goto <D.19627>;
        <D.19626>:
        ipv4_enabled.83 = ipv4_enabled;
        if (ipv4_enabled.83 == 1) goto <D.19632>; else goto <D.19633>;
        <D.19632>:
        domain->inet_family_hint = 2;
        goto <D.19634>;
        <D.19633>:
        domain->inet_family_hint = 3;
        <D.19634>:
        <D.19627>:
        {
          int ret;

          D.19618 = &domain->lock.mutex;
          ret = pthread_mutex_unlock (D.19618);
          if (ret != 0) goto <D.19635>; else goto <D.19636>;
          <D.19635>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d", ret);
          <D.19636>:
          D.19637 = ret != 0;
          D.19638 = (long int) D.19637;
          D.19639 = __builtin_expect (D.19638, 0);
          if (D.19639 != 0) goto <D.19640>; else goto <D.19641>;
          <D.19640>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 729, "ret == 0");
          <D.19641>:
        }
      }
    finally
      {
        ipv6_enabled = {CLOBBER};
        ipv4_enabled = {CLOBBER};
      }
  }
  <D.19610>:
  D.19608 = domain->inet_family_hint;
  D.19642 = (int) D.19608;
  switch (D.19642) <default: <D.18126>, case 1: <D.18123>, case 2: <D.18124>, case 3: <D.18125>>
  <D.18123>:
  D.19643 = 0;
  return D.19643;
  <D.18124>:
  D.19643 = 2;
  return D.19643;
  <D.18125>:
  D.19643 = 10;
  return D.19643;
  <D.18126>:
  D.19643 = 0;
  return D.19643;
}


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.19645;
  struct MonoArray * D.19646;
  int nlocal_in.85;
  int nlocal_in6.86;
  int D.19654;
  unsigned int D.19655;
  struct MonoClass * D.19656;
  struct MonoArray * D.19657;
  unsigned int i.87;
  unsigned int D.19661;
  struct in_addr * D.19662;
  unsigned int addr_index.88;
  struct MonoArray * D.19664;
  unsigned int i.89;
  unsigned int D.19668;
  struct in6_addr * D.19669;
  gboolean D.19674;
  int D.19675;
  _Bool D.19676;
  _Bool D.19677;
  _Bool D.19678;
  unsigned int count.90;
  struct MonoClass * D.19682;
  struct MonoArray * D.19683;
  int D.19684;
  _Bool D.19685;
  _Bool D.19686;
  _Bool D.19687;
  int D.19690;
  struct sockaddr * D.19693;
  struct in_addr * D.19694;
  struct in6_addr * D.19696;
  char * D.19702;
  struct MonoString * D.19705;
  struct MonoString * D.19707;
  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.19645 = mono_get_string_class ();
      D.19646 = mono_array_new (domain, D.19645, 0);
      *h_aliases = D.19646;
      if (add_local_ips != 0) goto <D.19647>; else goto <D.19648>;
      <D.19647>:
      local_in = get_local_ips (2, &nlocal_in);
      local_in6 = get_local_ips (10, &nlocal_in6);
      nlocal_in.85 = nlocal_in;
      if (nlocal_in.85 != 0) goto <D.19649>; else goto <D.19652>;
      <D.19652>:
      nlocal_in6.86 = nlocal_in6;
      if (nlocal_in6.86 != 0) goto <D.19649>; else goto <D.19650>;
      <D.19649>:
      nlocal_in.85 = nlocal_in;
      nlocal_in6.86 = nlocal_in6;
      D.19654 = nlocal_in.85 + nlocal_in6.86;
      D.19655 = (unsigned int) D.19654;
      D.19656 = mono_get_string_class ();
      D.19657 = mono_array_new (domain, D.19656, D.19655);
      *h_addr_list = D.19657;
      nlocal_in.85 = nlocal_in;
      if (nlocal_in.85 != 0) goto <D.19658>; else goto <D.19659>;
      <D.19658>:
      {
        struct MonoString * addr_string;
        char addr[16];
        int i;

        try
          {
            i = 0;
            goto <D.18623>;
            <D.18622>:
            i.87 = (unsigned int) i;
            D.19661 = i.87 * 4;
            D.19662 = local_in + D.19661;
            inet_ntop (2, D.19662, &addr, 16);
            addr_string = mono_string_new (domain, &addr);
            {
              void * * __p;

              addr_index.88 = (unsigned int) addr_index;
              D.19664 = *h_addr_list;
              __p = mono_array_addr_with_size (D.19664, 4, addr_index.88);
              D.19664 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.19664, __p, addr_string);
            }
            addr_index = addr_index + 1;
            i = i + 1;
            <D.18623>:
            nlocal_in.85 = nlocal_in;
            if (i < nlocal_in.85) goto <D.18622>; else goto <D.18624>;
            <D.18624>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.19659>:
      nlocal_in6.86 = nlocal_in6;
      if (nlocal_in6.86 != 0) goto <D.19665>; else goto <D.19666>;
      <D.19665>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char addr[48];
        int i;

        try
          {
            i = 0;
            goto <D.18631>;
            <D.18630>:
            i.89 = (unsigned int) i;
            D.19668 = i.89 * 16;
            D.19669 = local_in6 + D.19668;
            ret = inet_ntop (10, D.19669, &addr, 48);
            if (ret != 0B) goto <D.19670>; else goto <D.19671>;
            <D.19670>:
            addr_string = mono_string_new (domain, &addr);
            {
              void * * __p;

              addr_index.88 = (unsigned int) addr_index;
              D.19664 = *h_addr_list;
              __p = mono_array_addr_with_size (D.19664, 4, addr_index.88);
              D.19664 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.19664, __p, addr_string);
            }
            addr_index = addr_index + 1;
            <D.19671>:
            i = i + 1;
            <D.18631>:
            nlocal_in6.86 = nlocal_in6;
            if (i < nlocal_in6.86) goto <D.18630>; else goto <D.18632>;
            <D.18632>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.19666>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      if (info != 0B) goto <D.19672>; else goto <D.19673>;
      <D.19672>:
      freeaddrinfo (info);
      <D.19673>:
      D.19674 = 1;
      return D.19674;
      <D.19650>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      <D.19648>:
      count = 0;
      ai = info;
      goto <D.18635>;
      <D.18634>:
      D.19675 = ai->ai_family;
      D.19676 = D.19675 != 2;
      D.19677 = D.19675 != 10;
      D.19678 = D.19676 & D.19677;
      if (D.19678 != 0) goto <D.19679>; else goto <D.19680>;
      <D.19679>:
      // predicted unlikely by continue predictor.
      goto <D.18633>;
      <D.19680>:
      count = count + 1;
      <D.18633>:
      ai = ai->ai_next;
      <D.18635>:
      if (ai != 0B) goto <D.18634>; else goto <D.18636>;
      <D.18636>:
      count.90 = (unsigned int) count;
      D.19682 = mono_get_string_class ();
      D.19683 = mono_array_new (domain, D.19682, count.90);
      *h_addr_list = D.19683;
      ai = info;
      i = 0;
      goto <D.18643>;
      <D.18642>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char buffer[48];

        try
          {
            D.19684 = ai->ai_family;
            D.19685 = D.19684 != 2;
            D.19686 = D.19684 != 10;
            D.19687 = D.19685 & D.19686;
            if (D.19687 != 0) goto <D.19688>; else goto <D.19689>;
            <D.19688>:
            // predicted unlikely by continue predictor.
            goto <D.18640>;
            <D.19689>:
            D.19690 = ai->ai_family;
            if (D.19690 == 2) goto <D.19691>; else goto <D.19692>;
            <D.19691>:
            D.19693 = ai->ai_addr;
            D.19694 = &MEM[(struct sockaddr_in *)D.19693].sin_addr;
            D.19690 = ai->ai_family;
            ret = inet_ntop (D.19690, D.19694, &buffer, 16);
            goto <D.19695>;
            <D.19692>:
            D.19693 = ai->ai_addr;
            D.19696 = &MEM[(struct sockaddr_in6 *)D.19693].sin6_addr;
            D.19690 = ai->ai_family;
            ret = inet_ntop (D.19690, D.19696, &buffer, 48);
            <D.19695>:
            if (ret != 0B) goto <D.19697>; else goto <D.19698>;
            <D.19697>:
            addr_string = mono_string_new (domain, &buffer);
            goto <D.19699>;
            <D.19698>:
            addr_string = mono_string_new (domain, "");
            <D.19699>:
            {
              void * * __p;

              addr_index.88 = (unsigned int) addr_index;
              D.19664 = *h_addr_list;
              __p = mono_array_addr_with_size (D.19664, 4, addr_index.88);
              D.19664 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.19664, __p, addr_string);
            }
            if (i == 0) goto <D.19700>; else goto <D.19701>;
            <D.19700>:
            i = i + 1;
            D.19702 = ai->ai_canonname;
            if (D.19702 != 0B) goto <D.19703>; else goto <D.19704>;
            <D.19703>:
            D.19702 = ai->ai_canonname;
            D.19705 = mono_string_new (domain, D.19702);
            *h_name = D.19705;
            goto <D.19706>;
            <D.19704>:
            D.19707 = mono_string_new (domain, &buffer);
            *h_name = D.19707;
            <D.19706>:
            <D.19701>:
            addr_index = addr_index + 1;
          }
        finally
          {
            buffer = {CLOBBER};
          }
      }
      <D.18640>:
      ai = ai->ai_next;
      <D.18643>:
      if (ai != 0B) goto <D.18642>; else goto <D.18644>;
      <D.18644>:
      if (info != 0B) goto <D.19708>; else goto <D.19709>;
      <D.19708>:
      freeaddrinfo (info);
      <D.19709>:
      D.19674 = 1;
      return D.19674;
    }
  finally
    {
      nlocal_in = {CLOBBER};
      nlocal_in6 = {CLOBBER};
    }
}


get_local_ips (int family, int * nips)
{
  void * D.19720;
  unsigned int max_ifaces.91;
  unsigned int D.19722;
  int D.19723;
  int D.19724;
  unsigned int D.19725;
  void * D.19726;
  int D.19727;
  char * D.19730;
  unsigned int D.19731;
  unsigned int D.19732;
  char[16] * D.19735;
  int D.19736;
  short int D.19739;
  int D.19740;
  int D.19741;
  int D.19744;
  int D.19747;
  int D.19748;
  unsigned int D.19749;
  char D.19750;
  int D.19753;
  struct sockaddr * D.19756;
  sizetype offset.92;
  void * D.19758;
  int D.19759;
  unsigned int addr_size.93;
  char * D.19763;
  sizetype addr_size.94;
  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.19714>; else goto <D.19715>;
      <D.19714>:
      addr_size = 4;
      offset = 4;
      goto <D.19716>;
      <D.19715>:
      if (family == 10) goto <D.19717>; else goto <D.19718>;
      <D.19717>:
      addr_size = 16;
      offset = 8;
      goto <D.19719>;
      <D.19718>:
      D.19720 = 0B;
      return D.19720;
      <D.19719>:
      <D.19716>:
      fd = socket (family, 1, 0);
      max_ifaces.91 = (unsigned int) max_ifaces;
      D.19722 = max_ifaces.91 * 32;
      D.19723 = (int) D.19722;
      ifc.ifc_len = D.19723;
      D.19724 = ifc.ifc_len;
      D.19725 = (unsigned int) D.19724;
      D.19726 = monoeg_malloc (D.19725);
      ifc.ifc_ifcu.ifcu_buf = D.19726;
      D.19727 = ioctl (fd, 35090, &ifc);
      if (D.19727 < 0) goto <D.19728>; else goto <D.19729>;
      <D.19728>:
      close (fd);
      D.19730 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.19730);
      D.19720 = 0B;
      return D.19720;
      <D.19729>:
      D.19724 = ifc.ifc_len;
      D.19731 = (unsigned int) D.19724;
      D.19732 = D.19731 / 32;
      count = (int) D.19732;
      *nips = count;
      if (count == 0) goto <D.19733>; else goto <D.19734>;
      <D.19733>:
      D.19730 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.19730);
      close (fd);
      D.19720 = 0B;
      return D.19720;
      <D.19734>:
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.18596>;
      <D.18595>:
      D.19735 = &ifr->ifr_ifrn.ifrn_name;
      strcpy (&iflags.ifr_ifrn.ifrn_name, D.19735);
      D.19736 = ioctl (fd, 35091, &iflags);
      if (D.19736 < 0) goto <D.19737>; else goto <D.19738>;
      <D.19737>:
      // predicted unlikely by continue predictor.
      goto <D.18594>;
      <D.19738>:
      D.19739 = iflags.ifr_ifru.ifru_flags;
      D.19740 = (int) D.19739;
      D.19741 = D.19740 & 1;
      if (D.19741 == 0) goto <D.19742>; else goto <D.19743>;
      <D.19742>:
      ifr->ifr_ifrn.ifrn_name[0] = 0;
      // predicted unlikely by continue predictor.
      goto <D.18594>;
      <D.19743>:
      D.19739 = iflags.ifr_ifru.ifru_flags;
      D.19740 = (int) D.19739;
      D.19744 = D.19740 & 8;
      if (D.19744 == 0) goto <D.19745>; else goto <D.19746>;
      <D.19745>:
      ignore_loopback = 1;
      <D.19746>:
      <D.18594>:
      i = i + 1;
      ifr = ifr + 32;
      <D.18596>:
      D.19747 = *nips;
      if (D.19747 > i) goto <D.18595>; else goto <D.18597>;
      <D.18597>:
      close (fd);
      D.19748 = addr_size * count;
      D.19749 = (unsigned int) D.19748;
      result = monoeg_malloc (D.19749);
      tmp_ptr = result;
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.18600>;
      <D.18599>:
      D.19750 = ifr->ifr_ifrn.ifrn_name[0];
      if (D.19750 == 0) goto <D.19751>; else goto <D.19752>;
      <D.19751>:
      D.19747 = *nips;
      D.19753 = D.19747 + -1;
      *nips = D.19753;
      // predicted unlikely by continue predictor.
      goto <D.18598>;
      <D.19752>:
      if (ignore_loopback != 0) goto <D.19754>; else goto <D.19755>;
      <D.19754>:
      D.19756 = &ifr->ifr_ifru.ifru_addr;
      offset.92 = (sizetype) offset;
      D.19758 = D.19756 + offset.92;
      D.19759 = is_loopback (family, D.19758);
      if (D.19759 != 0) goto <D.19760>; else goto <D.19761>;
      <D.19760>:
      D.19747 = *nips;
      D.19753 = D.19747 + -1;
      *nips = D.19753;
      // predicted unlikely by continue predictor.
      goto <D.18598>;
      <D.19761>:
      <D.19755>:
      addr_size.93 = (unsigned int) addr_size;
      D.19756 = &ifr->ifr_ifru.ifru_addr;
      offset.92 = (sizetype) offset;
      D.19763 = D.19756 + offset.92;
      memcpy (tmp_ptr, D.19763, addr_size.93);
      addr_size.94 = (sizetype) addr_size;
      tmp_ptr = tmp_ptr + addr_size.94;
      <D.18598>:
      i = i + 1;
      ifr = ifr + 32;
      <D.18600>:
      if (i < count) goto <D.18599>; else goto <D.18601>;
      <D.18601>:
      D.19730 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.19730);
      D.19720 = result;
      return D.19720;
    }
  finally
    {
      ifc = {CLOBBER};
      iflags = {CLOBBER};
    }
}


strcpy (char * restrict __dest, const char * restrict __src)
{
  char * D.19767;
  unsigned int D.19768;

  D.19768 = __builtin_object_size (__dest, 1);
  D.19767 = __builtin___strcpy_chk (__dest, __src, D.19768);
  return D.19767;
}


is_loopback (int family, void * ad)
{
  gboolean D.19772;
  char D.19773;
  _Bool D.19774;
  int D.18577;
  int iftmp.95;
  unsigned int D.19778;
  unsigned int D.19780;
  unsigned int D.19782;
  unsigned int D.19784;
  unsigned int D.19785;
  char * ptr;

  ptr = ad;
  if (family == 2) goto <D.19770>; else goto <D.19771>;
  <D.19770>:
  D.19773 = *ptr;
  D.19774 = D.19773 == 127;
  D.19772 = (gboolean) D.19774;
  return D.19772;
  <D.19771>:
  {
    const struct in6_addr * __a;

    __a = ptr;
    D.19778 = __a->__in6_u.__u6_addr32[0];
    if (D.19778 == 0) goto <D.19779>; else goto <D.19776>;
    <D.19779>:
    D.19780 = __a->__in6_u.__u6_addr32[1];
    if (D.19780 == 0) goto <D.19781>; else goto <D.19776>;
    <D.19781>:
    D.19782 = __a->__in6_u.__u6_addr32[2];
    if (D.19782 == 0) goto <D.19783>; else goto <D.19776>;
    <D.19783>:
    D.19784 = __a->__in6_u.__u6_addr32[3];
    D.19785 = __bswap_32 (1);
    if (D.19784 == D.19785) goto <D.19786>; else goto <D.19776>;
    <D.19786>:
    iftmp.95 = 1;
    goto <D.19777>;
    <D.19776>:
    iftmp.95 = 0;
    <D.19777>:
    D.18577 = iftmp.95;
  }
  D.19772 = D.18577;
  return D.19772;
  D.19772 = 0;
  return D.19772;
}


memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.19788;
  unsigned int D.19789;

  D.19789 = __builtin_object_size (__dest, 0);
  D.19788 = __builtin___memcpy_chk (__dest, __src, __len, D.19789);
  return D.19788;
}


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.19791;
  int D.19794;
  MonoBoolean D.19797;
  int D.19801;
  int D.19807;
  int D.19810;
  int D.19811;
  struct addrinfo * info.96;
  int D.19815;
  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.19791 = inet_pton (2, address, &saddr.sin_addr);
      if (D.19791 <= 0) goto <D.19792>; else goto <D.19793>;
      <D.19792>:
      D.19794 = inet_pton (10, address, &saddr6.sin6_addr);
      if (D.19794 <= 0) goto <D.19795>; else goto <D.19796>;
      <D.19795>:
      monoeg_g_free (address);
      D.19797 = 0;
      return D.19797;
      <D.19796>:
      family = 10;
      saddr6.sin6_family = 10;
      goto <D.19798>;
      <D.19793>:
      family = 2;
      saddr.sin_family = 2;
      <D.19798>:
      monoeg_g_free (address);
      if (family == 2) goto <D.19799>; else goto <D.19800>;
      <D.19799>:
      D.19801 = getnameinfo (&saddr, 16, &hostname, 1025, 0B, 0, flags);
      if (D.19801 != 0) goto <D.19802>; else goto <D.19803>;
      <D.19802>:
      D.19797 = 0;
      return D.19797;
      <D.19803>:
      goto <D.19804>;
      <D.19800>:
      if (family == 10) goto <D.19805>; else goto <D.19806>;
      <D.19805>:
      D.19807 = getnameinfo (&saddr6, 28, &hostname, 1025, 0B, 0, flags);
      if (D.19807 != 0) goto <D.19808>; else goto <D.19809>;
      <D.19808>:
      D.19797 = 0;
      return D.19797;
      <D.19809>:
      <D.19806>:
      <D.19804>:
      memset (&hints, 0, 32);
      D.19810 = get_family_hint ();
      hints.ai_family = D.19810;
      hints.ai_socktype = 1;
      hints.ai_flags = 34;
      D.19811 = getaddrinfo (&hostname, 0B, &hints, &info);
      if (D.19811 == -1) goto <D.19812>; else goto <D.19813>;
      <D.19812>:
      D.19797 = 0;
      return D.19797;
      <D.19813>:
      info.96 = info;
      D.19815 = addrinfo_to_IPHostEntry (info.96, h_name, h_aliases, h_addr_list, 0);
      D.19797 = (MonoBoolean) D.19815;
      return D.19797;
    }
  finally
    {
      saddr = {CLOBBER};
      saddr6 = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
      hostname = {CLOBBER};
    }
}


ves_icall_System_Net_Dns_GetHostName_internal (struct MonoString * * h_name)
{
  MonoBoolean D.19820;
  struct MonoDomain * D.19821;
  struct MonoString * D.19822;
  gchar hostname[256];
  int ret;

  try
    {
      ret = gethostname (&hostname, 256);
      if (ret == -1) goto <D.19818>; else goto <D.19819>;
      <D.19818>:
      D.19820 = 0;
      return D.19820;
      <D.19819>:
      D.19821 = mono_domain_get ();
      D.19822 = mono_string_new (D.19821, &hostname);
      *h_name = D.19822;
      D.19820 = 1;
      return D.19820;
    }
  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.19827;
  int error.97;
  unsigned int error.98;
  char * D.19834;
  unsigned int D.19835;
  char * D.19838;
  unsigned int D.19839;
  unsigned int flags.99;
  int D.19841;
  void * file;
  gint32 error;
  struct TRANSMIT_FILE_BUFFERS buffers;

  try
    {
      if (filename == 0B) goto <D.19825>; else goto <D.19826>;
      <D.19825>:
      D.19827 = 0;
      return D.19827;
      <D.19826>:
      file = ves_icall_System_IO_MonoIO_Open (filename, 3, 1, 1, 0, &error);
      if (file == 4294967295B) goto <D.19828>; else goto <D.19829>;
      <D.19828>:
      error.97 = error;
      error.98 = (unsigned int) error.97;
      SetLastError (error.98);
      D.19827 = 0;
      return D.19827;
      <D.19829>:
      memset (&buffers, 0, 16);
      if (pre_buffer != 0B) goto <D.19832>; else goto <D.19833>;
      <D.19832>:
      D.19834 = mono_array_addr_with_size (pre_buffer, 1, 0);
      buffers.Head = D.19834;
      D.19835 = mono_array_length (pre_buffer);
      buffers.HeadLength = D.19835;
      <D.19833>:
      if (post_buffer != 0B) goto <D.19836>; else goto <D.19837>;
      <D.19836>:
      D.19838 = mono_array_addr_with_size (post_buffer, 1, 0);
      buffers.Tail = D.19838;
      D.19839 = mono_array_length (post_buffer);
      buffers.TailLength = D.19839;
      <D.19837>:
      flags.99 = (unsigned int) flags;
      D.19841 = TransmitFile (sock, file, 0, 0, 0B, &buffers, flags.99);
      if (D.19841 == 0) goto <D.19842>; else goto <D.19843>;
      <D.19842>:
      CloseHandle (file);
      D.19827 = 0;
      return D.19827;
      <D.19843>:
      CloseHandle (file);
      D.19827 = 1;
      return D.19827;
    }
  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.19846>; else goto <D.19847>;
      <D.19846>:
      monoeg_g_log (0B, 4, "%s: Couldn\'t initialise networking", &__func__);
      <D.18700>:
      goto <D.18700>;
      exit (-1);
      <D.19847>:
    }
  finally
    {
      wsadata = {CLOBBER};
    }
}


mono_network_cleanup ()
{
  WSACleanup ();
}


icall_cancel_blocking_socket_operation (struct MonoThread * thread)
{
  int D.19848;
  long long unsigned int D.19851;
  long unsigned int D.19852;
  int D.19854;
  struct MonoInternalThread * internal;

  internal = thread->internal_thread;
  D.19848 = mono_thread_info_new_interrupt_enabled ();
  if (D.19848 != 0) goto <D.19849>; else goto <D.19850>;
  <D.19849>:
  D.19851 = internal->tid;
  D.19852 = (long unsigned int) D.19851;
  mono_thread_info_abort_socket_syscall_for_close (D.19852);
  goto <D.19853>;
  <D.19850>:
  internal->ignore_next_signal = 1;
  D.19854 = mono_thread_get_abort_signal ();
  mono_thread_kill (internal, D.19854);
  <D.19853>:
}


