ves_icall_System_Net_Sockets_Socket_Socket_internal (struct MonoObject * this, gint32 family, gint32 type, gint32 proto, gint32 * error)
{
  void * D.18673;
  int D.18680;
  SOCKET sock;
  gint32 sock_family;
  gint32 sock_proto;
  gint32 sock_type;

  *error = 0;
  sock_family = convert_family (family);
  if (sock_family == -1) goto <D.18671>; else goto <D.18672>;
  <D.18671>:
  *error = 10047;
  D.18673 = 0B;
  return D.18673;
  <D.18672>:
  sock_proto = convert_proto (proto);
  if (sock_proto == -1) goto <D.18674>; else goto <D.18675>;
  <D.18674>:
  *error = 10043;
  D.18673 = 0B;
  return D.18673;
  <D.18675>:
  sock_type = convert_type (type);
  if (sock_type == -1) goto <D.18676>; else goto <D.18677>;
  <D.18676>:
  *error = 10044;
  D.18673 = 0B;
  return D.18673;
  <D.18677>:
  sock = _wapi_socket (sock_family, sock_type, sock_proto, 0B, 0, 1);
  if (sock == 4294967295) goto <D.18678>; else goto <D.18679>;
  <D.18678>:
  D.18680 = WSAGetLastError ();
  *error = D.18680;
  D.18673 = 0B;
  return D.18673;
  <D.18679>:
  if (sock_family == 2) goto <D.18681>; else goto <D.18682>;
  <D.18681>:
  if (sock_type == 1) goto <D.18683>; else goto <D.18684>;
  <D.18683>:
  D.18673 = (void *) sock;
  return D.18673;
  <D.18684>:
  <D.18682>:
  if (sock_family == 10) goto <D.18685>; else goto <D.18686>;
  <D.18685>:
  if (sock_type == 1) goto <D.18687>; else goto <D.18688>;
  <D.18687>:
  D.18673 = (void *) sock;
  return D.18673;
  <D.18688>:
  <D.18686>:
  D.18673 = (void *) sock;
  return D.18673;
}


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

  family = -1;
  switch (mono_family) <default: <D.17938>, case -1: <D.17909>, case 0: <D.17929>, case 1: <D.17930>, case 2: <D.17931>, case 3: <D.17910>, case 4: <D.17911>, case 5: <D.17912>, case 6: <D.17932>, case 7: <D.17913>, case 8: <D.17914>, case 9: <D.17915>, case 10: <D.17916>, case 11: <D.17933>, case 12: <D.17934>, case 13: <D.17917>, case 14: <D.17918>, case 15: <D.17919>, case 16: <D.17935>, case 17: <D.17920>, case 18: <D.17921>, case 19: <D.17922>, case 21: <D.17923>, case 22: <D.17924>, case 23: <D.17936>, case 24: <D.17925>, case 25: <D.17926>, case 26: <D.17937>, case 28: <D.17927>>
  <D.17909>:
  <D.17910>:
  <D.17911>:
  <D.17912>:
  <D.17913>:
  <D.17914>:
  <D.17915>:
  <D.17916>:
  <D.17917>:
  <D.17918>:
  <D.17919>:
  <D.17920>:
  <D.17921>:
  <D.17922>:
  <D.17923>:
  <D.17924>:
  <D.17925>:
  <D.17926>:
  <D.17927>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unsupported value 0x%x", mono_family);
  goto <D.17928>;
  <D.17929>:
  family = 0;
  goto <D.17928>;
  <D.17930>:
  family = 1;
  goto <D.17928>;
  <D.17931>:
  family = 2;
  goto <D.17928>;
  <D.17932>:
  family = 4;
  goto <D.17928>;
  <D.17933>:
  family = 22;
  goto <D.17928>;
  <D.17934>:
  family = 12;
  goto <D.17928>;
  <D.17935>:
  family = 5;
  goto <D.17928>;
  <D.17936>:
  family = 10;
  goto <D.17928>;
  <D.17937>:
  family = 23;
  goto <D.17928>;
  <D.17938>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unknown value 0x%x", mono_family);
  <D.17928>:
  D.18690 = family;
  return D.18690;
}


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

  proto = -1;
  switch (mono_proto) <default: <D.17986>, case -1: <D.17985>, case 0: <D.17970>, case 1: <D.17972>, case 2: <D.17973>, case 3: <D.17974>, case 6: <D.17975>, case 12: <D.17976>, case 17: <D.17977>, case 22: <D.17978>, case 41: <D.17971>, case 77: <D.17980>, case 255: <D.17981>, case 1000: <D.17982>, case 1256: <D.17983>, case 1257: <D.17984>>
  <D.17970>:
  <D.17971>:
  <D.17972>:
  <D.17973>:
  <D.17974>:
  <D.17975>:
  <D.17976>:
  <D.17977>:
  <D.17978>:
  proto = mono_proto;
  goto <D.17979>;
  <D.17980>:
  <D.17981>:
  <D.17982>:
  <D.17983>:
  <D.17984>:
  <D.17985>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.ProtocolType has unsupported value 0x%x", mono_proto);
  goto <D.17979>;
  <D.17986>:
  goto <D.17979>;
  <D.17979>:
  D.18692 = proto;
  return D.18692;
}


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

  type = -1;
  switch (mono_type) <default: <D.17965>, case -1: <D.17964>, case 1: <D.17958>, case 2: <D.17960>, case 3: <D.17961>, case 4: <D.17962>, case 5: <D.17963>>
  <D.17958>:
  type = 2;
  goto <D.17959>;
  <D.17960>:
  type = 1;
  goto <D.17959>;
  <D.17961>:
  type = 3;
  goto <D.17959>;
  <D.17962>:
  type = 4;
  goto <D.17959>;
  <D.17963>:
  type = 5;
  goto <D.17959>;
  <D.17964>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unsupported value 0x%x", mono_type);
  goto <D.17959>;
  <D.17965>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unknown value 0x%x", mono_type);
  <D.17959>:
  D.18695 = type;
  return D.18695;
}


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

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


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

  try
    {
      *error = 0;
      ret = ioctlsocket (sock, 18047, &amount);
      if (ret == -1) goto <D.18700>; else goto <D.18701>;
      <D.18700>:
      D.18702 = WSAGetLastError ();
      *error = D.18702;
      D.18703 = 0;
      return D.18703;
      <D.18701>:
      D.18703 = amount;
      return D.18703;
    }
  finally
    {
      amount = {CLOBBER};
    }
}


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

  *error = 0;
  block.1 = block;
  D.18707 = block.1 == 0;
  block.2 = (int) D.18707;
  block = block.2;
  ret = ioctlsocket (sock, 26238, &block);
  if (ret == -1) goto <D.18709>; else goto <D.18710>;
  <D.18709>:
  D.18711 = WSAGetLastError ();
  *error = D.18711;
  <D.18710>:
}


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

  *error = 0;
  newsock = _wapi_accept (sock, 0B, 0B);
  if (newsock == 4294967295) goto <D.18712>; else goto <D.18713>;
  <D.18712>:
  D.18714 = WSAGetLastError ();
  *error = D.18714;
  D.18715 = 0B;
  return D.18715;
  <D.18713>:
  D.18715 = (void *) newsock;
  return D.18715;
}


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

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


ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.18721;
  int D.18722;
  unsigned int salen.4;
  unsigned int salen.5;
  struct MonoObject * D.18727;
  gchar * iftmp.6;
  int D.18734;
  int salen.7;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.18721 = convert_family (af);
      D.18722 = get_sockaddr_size (D.18721);
      salen.4 = (unsigned int) D.18722;
      salen = salen.4;
      salen.5 = salen;
      if (salen.5 == 0) goto <D.18725>; else goto <D.18726>;
      <D.18725>:
      *error = 10047;
      D.18727 = 0B;
      return D.18727;
      <D.18726>:
      salen.5 = salen;
      if (salen.5 <= 128) goto <D.18729>; else goto <D.18730>;
      <D.18729>:
      salen.5 = salen;
      iftmp.6 = __builtin_alloca (salen.5);
      goto <D.18731>;
      <D.18730>:
      salen.5 = salen;
      iftmp.6 = monoeg_malloc0 (salen.5);
      <D.18731>:
      sa = iftmp.6;
      ret = _wapi_getsockname (sock, sa, &salen);
      if (ret == -1) goto <D.18732>; else goto <D.18733>;
      <D.18732>:
      D.18734 = WSAGetLastError ();
      *error = D.18734;
      salen.5 = salen;
      if (salen.5 > 128) goto <D.18735>; else goto <D.18736>;
      <D.18735>:
      monoeg_g_free (sa);
      <D.18736>:
      D.18727 = 0B;
      return D.18727;
      <D.18733>:
      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.18738>; else goto <D.18739>;
      <D.18738>:
      monoeg_g_free (sa);
      <D.18739>:
      D.18727 = result;
      return D.18727;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


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

  size = 0;
  if (family == 2) goto <D.18742>; else goto <D.18743>;
  <D.18742>:
  size = 16;
  goto <D.18744>;
  <D.18743>:
  if (family == 10) goto <D.18745>; else goto <D.18746>;
  <D.18745>:
  size = 28;
  goto <D.18747>;
  <D.18746>:
  if (family == 1) goto <D.18748>; else goto <D.18749>;
  <D.18748>:
  size = 110;
  <D.18749>:
  <D.18747>:
  <D.18744>:
  D.18750 = size;
  return D.18750;
}


create_object_from_sockaddr (struct sockaddr * saddr, int sa_size, gint32 * error)
{
  struct MonoClass * D.18752;
  struct MonoImage * D.18755;
  struct MonoClass * D.18756;
  _Bool D.18757;
  long int D.18758;
  long int D.18759;
  struct MonoClassField * D.18762;
  struct MonoClassField * D.18765;
  _Bool D.18766;
  long int D.18767;
  long int D.18768;
  struct MonoClass * D.18155;
  struct MonoClass * tmp_klass.8;
  struct MonoClass * D.18774;
  struct MonoClass * tmp_klass.9;
  _Bool D.18776;
  long int D.18777;
  long int D.18778;
  struct MonoVTable * D.18781;
  int D.18782;
  unsigned int D.18783;
  short unsigned int D.18784;
  int D.18785;
  struct MonoObject * D.18788;
  unsigned char D.18789;
  int D.18790;
  unsigned char D.18791;
  short unsigned int port.10;
  unsigned int D.18794;
  struct MonoImage * D.18797;
  struct MonoException * D.18798;
  short unsigned int D.18799;
  unsigned char D.18800;
  unsigned char D.18801;
  unsigned int D.18802;
  unsigned char D.18803;
  unsigned int D.18804;
  unsigned char D.18805;
  unsigned int D.18806;
  unsigned char D.18807;
  unsigned char D.18808;
  short unsigned int port.11;
  struct MonoImage * D.18813;
  struct MonoException * D.18814;
  short unsigned int D.18815;
  unsigned char D.18816;
  unsigned char D.18817;
  struct in6_addr * D.18818;
  int D.18819;
  int D.18822;
  unsigned int D.18823;
  unsigned char D.18825;
  unsigned int D.18826;
  unsigned char D.18827;
  unsigned int D.18828;
  unsigned char D.18829;
  unsigned int D.18830;
  unsigned char D.18831;
  unsigned int D.18832;
  unsigned char D.18833;
  int D.18836;
  unsigned int D.18837;
  char D.18838;
  unsigned char D.18839;
  struct MonoDomain * domain;
  struct MonoObject * sockaddr_obj;
  struct MonoArray * data;
  MonoAddressFamily family;

  domain = mono_domain_get ();
  D.18752 = domain->sockaddr_class;
  if (D.18752 == 0B) goto <D.18753>; else goto <D.18754>;
  <D.18753>:
  D.18755 = get_socket_assembly ();
  D.18756 = mono_class_from_name (D.18755, "System.Net", "SocketAddress");
  domain->sockaddr_class = D.18756;
  D.18752 = domain->sockaddr_class;
  D.18757 = D.18752 == 0B;
  D.18758 = (long int) D.18757;
  D.18759 = __builtin_expect (D.18758, 0);
  if (D.18759 != 0) goto <D.18760>; else goto <D.18761>;
  <D.18760>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 935, "domain->sockaddr_class");
  <D.18761>:
  <D.18754>:
  D.18752 = domain->sockaddr_class;
  sockaddr_obj = mono_object_new (domain, D.18752);
  D.18762 = domain->sockaddr_data_field;
  if (D.18762 == 0B) goto <D.18763>; else goto <D.18764>;
  <D.18763>:
  D.18752 = domain->sockaddr_class;
  D.18765 = mono_class_get_field_from_name (D.18752, "data");
  domain->sockaddr_data_field = D.18765;
  D.18762 = domain->sockaddr_data_field;
  D.18766 = D.18762 == 0B;
  D.18767 = (long int) D.18766;
  D.18768 = __builtin_expect (D.18767, 0);
  if (D.18768 != 0) goto <D.18769>; else goto <D.18770>;
  <D.18769>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 942, "domain->sockaddr_data_field");
  <D.18770>:
  <D.18764>:
  {
    static struct MonoClass * tmp_klass;

    {
      tmp_klass.8 = tmp_klass;
      if (tmp_klass.8 == 0B) goto <D.18772>; else goto <D.18773>;
      <D.18772>:
      D.18774 = mono_get_byte_class ();
      tmp_klass.9 = mono_array_class_get (D.18774, 1);
      tmp_klass = tmp_klass.9;
      tmp_klass.8 = tmp_klass;
      D.18776 = tmp_klass.8 == 0B;
      D.18777 = (long int) D.18776;
      D.18778 = __builtin_expect (D.18777, 0);
      if (D.18778 != 0) goto <D.18779>; else goto <D.18780>;
      <D.18779>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 949, "tmp_klass");
      <D.18780>:
      <D.18773>:
    }
    D.18155 = tmp_klass;
  }
  D.18781 = mono_class_vtable (domain, D.18155);
  D.18782 = sa_size + 2;
  D.18783 = (unsigned int) D.18782;
  data = mono_array_new_specific (D.18781, D.18783);
  D.18784 = saddr->sa_family;
  D.18785 = (int) D.18784;
  family = convert_to_mono_family (D.18785);
  if (family == -1) goto <D.18786>; else goto <D.18787>;
  <D.18786>:
  *error = 10047;
  D.18788 = 0B;
  return D.18788;
  <D.18787>:
  {
    guint8 * __p;

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

    __p = mono_array_addr_with_size (data, 1, 1);
    D.18790 = family >> 8;
    D.18791 = (unsigned char) D.18790;
    *__p = D.18791;
  }
  D.18784 = saddr->sa_family;
  if (D.18784 == 2) goto <D.18792>; else goto <D.18793>;
  <D.18792>:
  {
    struct sockaddr_in * sa_in;
    guint16 port;
    guint32 address;

    sa_in = saddr;
    {
      short unsigned int __bsx;

      __bsx = sa_in->sin_port;
      port.10 = __bsx r>> 8;
    }
    port = port.10;
    D.18794 = sa_in->sin_addr.s_addr;
    address = __bswap_32 (D.18794);
    if (sa_size <= 7) goto <D.18795>; else goto <D.18796>;
    <D.18795>:
    D.18797 = mono_get_corlib ();
    D.18798 = mono_exception_from_name (D.18797, "System", "SystemException");
    mono_raise_exception (D.18798);
    <D.18796>:
    {
      guint8 * __p;

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

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

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

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

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

      __p = mono_array_addr_with_size (data, 1, 7);
      D.18808 = (unsigned char) address;
      *__p = D.18808;
    }
    D.18762 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.18762, data);
    D.18788 = sockaddr_obj;
    return D.18788;
  }
  <D.18793>:
  D.18784 = saddr->sa_family;
  if (D.18784 == 10) goto <D.18809>; else goto <D.18810>;
  <D.18809>:
  {
    struct sockaddr_in6 * sa_in;
    int i;
    guint16 port;

    sa_in = saddr;
    {
      short unsigned int __bsx;

      __bsx = sa_in->sin6_port;
      port.11 = __bsx r>> 8;
    }
    port = port.11;
    if (sa_size <= 27) goto <D.18811>; else goto <D.18812>;
    <D.18811>:
    D.18813 = mono_get_corlib ();
    D.18814 = mono_exception_from_name (D.18813, "System", "SystemException");
    mono_raise_exception (D.18814);
    <D.18812>:
    {
      guint8 * __p;

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

      __p = mono_array_addr_with_size (data, 1, 3);
      D.18817 = (unsigned char) port;
      *__p = D.18817;
    }
    D.18818 = &sa_in->sin6_addr;
    D.18819 = is_ipv4_mapped_any (D.18818);
    if (D.18819 != 0) goto <D.18820>; else goto <D.18821>;
    <D.18820>:
    i = 0;
    goto <D.18178>;
    <D.18177>:
    {
      guint8 * __p;

      D.18822 = i + 8;
      D.18823 = (unsigned int) D.18822;
      __p = mono_array_addr_with_size (data, 1, D.18823);
      *__p = 0;
    }
    i = i + 1;
    <D.18178>:
    if (i <= 15) goto <D.18177>; else goto <D.18179>;
    <D.18179>:
    goto <D.18824>;
    <D.18821>:
    i = 0;
    goto <D.18182>;
    <D.18181>:
    {
      guint8 * __p;

      D.18822 = i + 8;
      D.18823 = (unsigned int) D.18822;
      __p = mono_array_addr_with_size (data, 1, D.18823);
      D.18825 = sa_in->sin6_addr.__in6_u.__u6_addr8[i];
      *__p = D.18825;
    }
    i = i + 1;
    <D.18182>:
    if (i <= 15) goto <D.18181>; else goto <D.18183>;
    <D.18183>:
    <D.18824>:
    {
      guint8 * __p;

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

      __p = mono_array_addr_with_size (data, 1, 25);
      D.18826 = sa_in->sin6_scope_id;
      D.18828 = D.18826 >> 8;
      D.18829 = (unsigned char) D.18828;
      *__p = D.18829;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 26);
      D.18826 = sa_in->sin6_scope_id;
      D.18830 = D.18826 >> 16;
      D.18831 = (unsigned char) D.18830;
      *__p = D.18831;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 27);
      D.18826 = sa_in->sin6_scope_id;
      D.18832 = D.18826 >> 24;
      D.18833 = (unsigned char) D.18832;
      *__p = D.18833;
    }
    D.18762 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.18762, data);
    D.18788 = sockaddr_obj;
    return D.18788;
  }
  <D.18810>:
  D.18784 = saddr->sa_family;
  if (D.18784 == 1) goto <D.18834>; else goto <D.18835>;
  <D.18834>:
  {
    int i;

    i = 0;
    goto <D.18191>;
    <D.18190>:
    {
      guint8 * __p;

      D.18836 = i + 2;
      D.18837 = (unsigned int) D.18836;
      __p = mono_array_addr_with_size (data, 1, D.18837);
      D.18838 = saddr->sa_data[i];
      D.18839 = (unsigned char) D.18838;
      *__p = D.18839;
    }
    i = i + 1;
    <D.18191>:
    if (i < sa_size) goto <D.18190>; else goto <D.18192>;
    <D.18192>:
    D.18762 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.18762, data);
    D.18788 = sockaddr_obj;
    return D.18788;
  }
  <D.18835>:
  *error = 10047;
  D.18788 = 0B;
  return D.18788;
}


get_socket_assembly ()
{
  struct MonoImage * D.18841;
  struct MonoImage * D.18848;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.18841 = domain->socket_assembly;
  if (D.18841 == 0B) goto <D.18842>; else goto <D.18843>;
  <D.18842>:
  {
    struct MonoImage * socket_assembly;

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

      sa = mono_assembly_open ("System.dll", 0B);
      if (sa == 0B) goto <D.18846>; else goto <D.18847>;
      <D.18846>:
      monoeg_assertion_message ("* Assertion: should not be reached at %s:%d\n", "socket-io.c", 689);
      <D.18847>:
      socket_assembly = mono_assembly_get_image (sa);
    }
    <D.18845>:
    mono_memory_barrier ();
    domain->socket_assembly = socket_assembly;
  }
  <D.18843>:
  D.18848 = domain->socket_assembly;
  return D.18848;
}


mono_memory_barrier ()
{
  __sync_synchronize ();
}


convert_to_mono_family (guint16 af_family)
{
  int D.18850;
  MonoAddressFamily D.18851;
  MonoAddressFamily family;

  family = -1;
  D.18850 = (int) af_family;
  switch (D.18850) <default: <D.17953>, case 0: <D.17943>, case 1: <D.17945>, case 2: <D.17946>, case 4: <D.17947>, case 5: <D.17950>, case 10: <D.17951>, case 12: <D.17949>, case 22: <D.17948>, case 23: <D.17952>>
  <D.17943>:
  family = 0;
  goto <D.17944>;
  <D.17945>:
  family = 1;
  goto <D.17944>;
  <D.17946>:
  family = 2;
  goto <D.17944>;
  <D.17947>:
  family = 6;
  goto <D.17944>;
  <D.17948>:
  family = 11;
  goto <D.17944>;
  <D.17949>:
  family = 12;
  goto <D.17944>;
  <D.17950>:
  family = 16;
  goto <D.17944>;
  <D.17951>:
  family = 23;
  goto <D.17944>;
  <D.17952>:
  family = 26;
  goto <D.17944>;
  <D.17953>:
  D.18850 = (int) af_family;
  monoeg_g_log (0B, 16, "unknown address family 0x%x", D.18850);
  <D.17944>:
  D.18851 = family;
  return D.18851;
}


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

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


is_ipv4_mapped_any (const struct in6_addr * addr)
{
  unsigned char D.18855;
  gboolean D.18858;
  unsigned int D.18859;
  unsigned int D.18860;
  int i;

  i = 0;
  goto <D.18140>;
  <D.18139>:
  D.18855 = addr->__in6_u.__u6_addr8[i];
  if (D.18855 != 0) goto <D.18856>; else goto <D.18857>;
  <D.18856>:
  D.18858 = 0;
  return D.18858;
  <D.18857>:
  i = i + 1;
  <D.18140>:
  if (i <= 9) goto <D.18139>; else goto <D.18141>;
  <D.18141>:
  D.18859 = BIT_FIELD_REF <*addr, 32, 64>;
  D.18860 = D.18859 & 4294901760;
  if (D.18860 != 4294901760) goto <D.18861>; else goto <D.18862>;
  <D.18861>:
  D.18858 = 0;
  return D.18858;
  <D.18862>:
  i = 12;
  goto <D.18143>;
  <D.18142>:
  D.18855 = addr->__in6_u.__u6_addr8[i];
  if (D.18855 != 0) goto <D.18863>; else goto <D.18864>;
  <D.18863>:
  D.18858 = 0;
  return D.18858;
  <D.18864>:
  i = i + 1;
  <D.18143>:
  if (i <= 15) goto <D.18142>; else goto <D.18144>;
  <D.18144>:
  D.18858 = 1;
  return D.18858;
}


ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.18866;
  int D.18867;
  unsigned int salen.12;
  unsigned int salen.13;
  struct MonoObject * D.18872;
  gchar * iftmp.14;
  int D.18879;
  int salen.15;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.18866 = convert_family (af);
      D.18867 = get_sockaddr_size (D.18866);
      salen.12 = (unsigned int) D.18867;
      salen = salen.12;
      salen.13 = salen;
      if (salen.13 == 0) goto <D.18870>; else goto <D.18871>;
      <D.18870>:
      *error = 10047;
      D.18872 = 0B;
      return D.18872;
      <D.18871>:
      salen.13 = salen;
      if (salen.13 <= 128) goto <D.18874>; else goto <D.18875>;
      <D.18874>:
      salen.13 = salen;
      iftmp.14 = __builtin_alloca (salen.13);
      goto <D.18876>;
      <D.18875>:
      salen.13 = salen;
      iftmp.14 = monoeg_malloc0 (salen.13);
      <D.18876>:
      sa = iftmp.14;
      ret = _wapi_getpeername (sock, sa, &salen);
      if (ret == -1) goto <D.18877>; else goto <D.18878>;
      <D.18877>:
      D.18879 = WSAGetLastError ();
      *error = D.18879;
      salen.13 = salen;
      if (salen.13 > 128) goto <D.18880>; else goto <D.18881>;
      <D.18880>:
      monoeg_g_free (sa);
      <D.18881>:
      D.18872 = 0B;
      return D.18872;
      <D.18878>:
      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.18883>; else goto <D.18884>;
      <D.18883>:
      monoeg_g_free (sa);
      <D.18884>:
      D.18872 = result;
      return D.18872;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


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

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.18887 = *error;
      if (D.18887 != 0) goto <D.18888>; else goto <D.18889>;
      <D.18888>:
      return;
      <D.18889>:
      sa_size.16 = sa_size;
      ret = _wapi_bind (sock, sa, sa_size.16);
      if (ret == -1) goto <D.18891>; else goto <D.18892>;
      <D.18891>:
      D.18893 = WSAGetLastError ();
      *error = D.18893;
      <D.18892>:
      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.18897;
  struct MonoClass * D.18898;
  int D.18899;
  sizetype D.18900;
  struct MonoArray * * D.18901;
  unsigned int D.18902;
  struct MonoImage * D.18905;
  struct MonoException * D.18906;
  char * D.18907;
  unsigned char D.18908;
  int D.18909;
  char * D.18910;
  unsigned char D.18911;
  int D.18912;
  int D.18913;
  int D.18914;
  struct MonoImage * D.18919;
  struct MonoException * D.18920;
  char * D.18921;
  unsigned char D.18922;
  short unsigned int D.18923;
  short unsigned int D.18924;
  char * D.18925;
  unsigned char D.18926;
  short unsigned int D.18927;
  char * D.18928;
  unsigned char D.18929;
  int D.18930;
  int D.18931;
  char * D.18932;
  unsigned char D.18933;
  int D.18934;
  int D.18935;
  int D.18936;
  char * D.18937;
  unsigned char D.18938;
  int D.18939;
  int D.18940;
  int D.18941;
  char * D.18942;
  unsigned char D.18943;
  int D.18944;
  int D.18945;
  short unsigned int D.18946;
  unsigned int D.18947;
  short unsigned int D.18228;
  struct sockaddr * D.18948;
  struct MonoImage * D.18953;
  struct MonoException * D.18954;
  char * D.18955;
  unsigned char D.18956;
  short unsigned int D.18957;
  char * D.18958;
  unsigned char D.18959;
  short unsigned int D.18960;
  short unsigned int D.18961;
  char * D.18962;
  unsigned char D.18963;
  int D.18964;
  char * D.18965;
  unsigned char D.18966;
  int D.18967;
  int D.18968;
  int D.18969;
  char * D.18970;
  unsigned char D.18971;
  int D.18972;
  int D.18973;
  int D.18974;
  char * D.18975;
  unsigned char D.18976;
  int D.18977;
  int D.18978;
  int D.18979;
  short unsigned int D.18234;
  int D.18980;
  unsigned int D.18981;
  char * D.18982;
  unsigned char D.18983;
  struct MonoException * D.18988;
  int D.18989;
  unsigned int D.18990;
  char * D.18991;
  unsigned char D.18992;
  char D.18993;
  int D.18994;
  unsigned int len.17;
  struct MonoClassField * field;
  struct MonoArray * data;
  gint32 family;
  int len;

  D.18897 = saddr_obj->vtable;
  D.18898 = D.18897->klass;
  field = mono_class_get_field_from_name (D.18898, "data");
  D.18899 = field->offset;
  D.18900 = (sizetype) D.18899;
  D.18901 = saddr_obj + D.18900;
  data = *D.18901;
  D.18902 = mono_array_length (data);
  len = (int) D.18902;
  if (len <= 1) goto <D.18903>; else goto <D.18904>;
  <D.18903>:
  D.18905 = mono_get_corlib ();
  D.18906 = mono_exception_from_name (D.18905, "System", "SystemException");
  mono_raise_exception (D.18906);
  <D.18904>:
  D.18907 = mono_array_addr_with_size (data, 1, 0);
  D.18908 = MEM[(guint8 *)D.18907];
  D.18909 = (int) D.18908;
  D.18910 = mono_array_addr_with_size (data, 1, 1);
  D.18911 = MEM[(guint8 *)D.18910];
  D.18912 = (int) D.18911;
  D.18913 = D.18912 << 8;
  D.18914 = D.18909 + D.18913;
  family = convert_family (D.18914);
  if (family == 2) goto <D.18915>; else goto <D.18916>;
  <D.18915>:
  {
    struct sockaddr_in * sa;
    guint16 port;
    guint32 address;

    if (len <= 7) goto <D.18917>; else goto <D.18918>;
    <D.18917>:
    D.18919 = mono_get_corlib ();
    D.18920 = mono_exception_from_name (D.18919, "System", "SystemException");
    mono_raise_exception (D.18920);
    <D.18918>:
    sa = monoeg_malloc0 (16);
    D.18921 = mono_array_addr_with_size (data, 1, 2);
    D.18922 = MEM[(guint8 *)D.18921];
    D.18923 = (short unsigned int) D.18922;
    D.18924 = D.18923 << 8;
    D.18925 = mono_array_addr_with_size (data, 1, 3);
    D.18926 = MEM[(guint8 *)D.18925];
    D.18927 = (short unsigned int) D.18926;
    port = D.18924 + D.18927;
    D.18928 = mono_array_addr_with_size (data, 1, 4);
    D.18929 = MEM[(guint8 *)D.18928];
    D.18930 = (int) D.18929;
    D.18931 = D.18930 << 24;
    D.18932 = mono_array_addr_with_size (data, 1, 5);
    D.18933 = MEM[(guint8 *)D.18932];
    D.18934 = (int) D.18933;
    D.18935 = D.18934 << 16;
    D.18936 = D.18931 + D.18935;
    D.18937 = mono_array_addr_with_size (data, 1, 6);
    D.18938 = MEM[(guint8 *)D.18937];
    D.18939 = (int) D.18938;
    D.18940 = D.18939 << 8;
    D.18941 = D.18936 + D.18940;
    D.18942 = mono_array_addr_with_size (data, 1, 7);
    D.18943 = MEM[(guint8 *)D.18942];
    D.18944 = (int) D.18943;
    D.18945 = D.18941 + D.18944;
    address = (guint32) D.18945;
    D.18946 = (short unsigned int) family;
    sa->sin_family = D.18946;
    D.18947 = __bswap_32 (address);
    sa->sin_addr.s_addr = D.18947;
    {
      short unsigned int __bsx;

      __bsx = port;
      D.18228 = __bsx r>> 8;
    }
    sa->sin_port = D.18228;
    *sa_size = 16;
    D.18948 = sa;
    return D.18948;
  }
  <D.18916>:
  if (family == 10) goto <D.18949>; else goto <D.18950>;
  <D.18949>:
  {
    struct sockaddr_in6 * sa;
    int i;
    guint16 port;
    guint32 scopeid;

    if (len <= 27) goto <D.18951>; else goto <D.18952>;
    <D.18951>:
    D.18953 = mono_get_corlib ();
    D.18954 = mono_exception_from_name (D.18953, "System", "SystemException");
    mono_raise_exception (D.18954);
    <D.18952>:
    sa = monoeg_malloc0 (28);
    D.18955 = mono_array_addr_with_size (data, 1, 3);
    D.18956 = MEM[(guint8 *)D.18955];
    D.18957 = (short unsigned int) D.18956;
    D.18958 = mono_array_addr_with_size (data, 1, 2);
    D.18959 = MEM[(guint8 *)D.18958];
    D.18960 = (short unsigned int) D.18959;
    D.18961 = D.18960 << 8;
    port = D.18957 + D.18961;
    D.18962 = mono_array_addr_with_size (data, 1, 24);
    D.18963 = MEM[(guint8 *)D.18962];
    D.18964 = (int) D.18963;
    D.18965 = mono_array_addr_with_size (data, 1, 25);
    D.18966 = MEM[(guint8 *)D.18965];
    D.18967 = (int) D.18966;
    D.18968 = D.18967 << 8;
    D.18969 = D.18964 + D.18968;
    D.18970 = mono_array_addr_with_size (data, 1, 26);
    D.18971 = MEM[(guint8 *)D.18970];
    D.18972 = (int) D.18971;
    D.18973 = D.18972 << 16;
    D.18974 = D.18969 + D.18973;
    D.18975 = mono_array_addr_with_size (data, 1, 27);
    D.18976 = MEM[(guint8 *)D.18975];
    D.18977 = (int) D.18976;
    D.18978 = D.18977 << 24;
    D.18979 = D.18974 + D.18978;
    scopeid = (guint32) D.18979;
    D.18946 = (short unsigned int) family;
    sa->sin6_family = D.18946;
    {
      short unsigned int __bsx;

      __bsx = port;
      D.18234 = __bsx r>> 8;
    }
    sa->sin6_port = D.18234;
    sa->sin6_scope_id = scopeid;
    i = 0;
    goto <D.18236>;
    <D.18235>:
    D.18980 = i + 8;
    D.18981 = (unsigned int) D.18980;
    D.18982 = mono_array_addr_with_size (data, 1, D.18981);
    D.18983 = MEM[(guint8 *)D.18982];
    sa->sin6_addr.__in6_u.__u6_addr8[i] = D.18983;
    i = i + 1;
    <D.18236>:
    if (i <= 15) goto <D.18235>; else goto <D.18237>;
    <D.18237>:
    *sa_size = 28;
    D.18948 = sa;
    return D.18948;
  }
  <D.18950>:
  if (family == 1) goto <D.18984>; else goto <D.18985>;
  <D.18984>:
  {
    struct sockaddr_un * sock_un;
    int i;

    if (len > 1) goto <D.18986>; else goto <D.18987>;
    <D.18986>:
    D.18988 = mono_get_exception_index_out_of_range ();
    mono_raise_exception (D.18988);
    <D.18987>:
    sock_un = monoeg_malloc0 (110);
    D.18946 = (short unsigned int) family;
    sock_un->sun_family = D.18946;
    i = 0;
    goto <D.18241>;
    <D.18240>:
    D.18989 = i + 2;
    D.18990 = (unsigned int) D.18989;
    D.18991 = mono_array_addr_with_size (data, 1, D.18990);
    D.18992 = MEM[(guint8 *)D.18991];
    D.18993 = (char) D.18992;
    sock_un->sun_path[i] = D.18993;
    i = i + 1;
    <D.18241>:
    D.18994 = len + -2;
    if (D.18994 > i) goto <D.18240>; else goto <D.18242>;
    <D.18242>:
    len.17 = (unsigned int) len;
    *sa_size = len.17;
    D.18948 = sock_un;
    return D.18948;
  }
  <D.18985>:
  *error = 10047;
  D.18948 = 0B;
  return D.18948;
}


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;
  int * D.19014;
  long int D.19015;
  int D.19016;
  int D.19021;
  MonoBoolean D.19028;
  unsigned int D.19032;
  unsigned int D.19033;
  int D.19034;
  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.18999>; else goto <D.19000>;
  <D.18999>:
  if (mode == 1) goto <D.19002>; else goto <D.19003>;
  <D.19002>:
  iftmp.20 = 4;
  goto <D.19004>;
  <D.19003>:
  iftmp.20 = 56;
  <D.19004>:
  iftmp.19 = iftmp.20;
  goto <D.19005>;
  <D.19000>:
  iftmp.19 = 1;
  <D.19005>:
  pfds->events = iftmp.19;
  if (timeout >= 0) goto <D.19007>; else goto <D.19008>;
  <D.19007>:
  iftmp.21 = timeout / 1000;
  goto <D.19009>;
  <D.19008>:
  iftmp.21 = -1;
  <D.19009>:
  timeout = iftmp.21;
  start = time (0B);
  <D.18268>:
  *error = 0;
  ret = mono_poll (pfds, 1, timeout);
  if (timeout > 0) goto <D.19010>; else goto <D.19011>;
  <D.19010>:
  if (ret < 0) goto <D.19012>; else goto <D.19013>;
  <D.19012>:
  {
    int err;
    int sec;

    D.19014 = __errno_location ();
    err = *D.19014;
    D.19015 = time (0B);
    sec = D.19015 - start;
    D.19016 = sec * -1000;
    timeout = D.19016 + timeout;
    if (timeout < 0) goto <D.19017>; else goto <D.19018>;
    <D.19017>:
    timeout = 0;
    <D.19018>:
    D.19014 = __errno_location ();
    *D.19014 = err;
  }
  <D.19013>:
  <D.19011>:
  if (ret == -1) goto <D.19019>; else goto <D.19020>;
  <D.19019>:
  D.19014 = __errno_location ();
  D.19021 = *D.19014;
  if (D.19021 == 4) goto <D.19022>; else goto <D.19023>;
  <D.19022>:
  {
    int leave;

    leave = 0;
    if (thread == 0B) goto <D.19024>; else goto <D.19025>;
    <D.19024>:
    thread = mono_thread_internal_current ();
    <D.19025>:
    leave = mono_thread_test_state (thread, 129);
    if (leave != 0) goto <D.19026>; else goto <D.19027>;
    <D.19026>:
    monoeg_g_free (pfds);
    D.19028 = 0;
    return D.19028;
    <D.19027>:
    mono_thread_interruption_checkpoint ();
    D.19014 = __errno_location ();
    *D.19014 = 4;
  }
  <D.19023>:
  <D.19020>:
  if (ret == -1) goto <D.19029>; else goto <D.18269>;
  <D.19029>:
  D.19014 = __errno_location ();
  D.19021 = *D.19014;
  if (D.19021 == 4) goto <D.18268>; else goto <D.18269>;
  <D.18269>:
  if (ret == -1) goto <D.19030>; else goto <D.19031>;
  <D.19030>:
  D.19014 = __errno_location ();
  D.19021 = *D.19014;
  D.19032 = (unsigned int) D.19021;
  D.19033 = errno_to_WSA (D.19032, &__func__);
  D.19034 = (int) D.19033;
  *error = D.19034;
  monoeg_g_free (pfds);
  D.19028 = 0;
  return D.19028;
  <D.19031>:
  monoeg_g_free (pfds);
  if (ret == 0) goto <D.19035>; else goto <D.19036>;
  <D.19035>:
  D.19028 = 0;
  return D.19028;
  <D.19036>:
  D.19028 = 1;
  return D.19028;
}


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

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.19038 = *error;
      if (D.19038 != 0) goto <D.19039>; else goto <D.19040>;
      <D.19039>:
      return;
      <D.19040>:
      sa_size.22 = sa_size;
      ret = _wapi_connect (sock, sa, sa_size.22);
      if (ret == -1) goto <D.19042>; else goto <D.19043>;
      <D.19042>:
      D.19044 = WSAGetLastError ();
      *error = D.19044;
      <D.19043>:
      monoeg_g_free (sa);
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Disconnect_internal (SOCKET sock, MonoBoolean reuse, gint32 * error)
{
  gboolean (*<T19e6>) (guint32, struct WapiOverlapped *, guint32, WapiTransmitFileFlags) _wapi_disconnectex.23;
  gboolean (*<T19ed>) (guint32, void *, guint32, guint32, struct WapiOverlapped *, struct WapiTransmitFileBuffers *, WapiTransmitFileFlags) _wapi_transmitfile.24;
  int D.19062;
  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.19048>; else goto <D.19049>;
      <D.19048>:
      _wapi_disconnectex = 0B;
      ret = WSAIoctl (sock, -939524090, &trans_guid, 16, &_wapi_transmitfile, 4, &output_bytes, 0B, 0B);
      if (ret != 0) goto <D.19050>; else goto <D.19051>;
      <D.19050>:
      _wapi_transmitfile = 0B;
      <D.19051>:
      <D.19049>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      if (_wapi_disconnectex.23 != 0B) goto <D.19053>; else goto <D.19054>;
      <D.19053>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      bret = _wapi_disconnectex.23 (sock, 0B, 2, 0);
      goto <D.19055>;
      <D.19054>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      if (_wapi_transmitfile.24 != 0B) goto <D.19057>; else goto <D.19058>;
      <D.19057>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      bret = _wapi_transmitfile.24 (sock, 0B, 0, 0, 0B, 0B, 3);
      goto <D.19059>;
      <D.19058>:
      *error = 50;
      return;
      <D.19059>:
      <D.19055>:
      if (bret == 0) goto <D.19060>; else goto <D.19061>;
      <D.19060>:
      D.19062 = WSAGetLastError ();
      *error = D.19062;
      <D.19061>:
    }
  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.19066;
  int D.19067;
  gint32 D.19070;
  unsigned int offset.25;
  unsigned int count.26;
  int D.19077;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;

  recvflags = 0;
  *error = 0;
  D.19066 = mono_array_length (buffer);
  alen = (gint32) D.19066;
  D.19067 = alen - count;
  if (D.19067 < offset) goto <D.19068>; else goto <D.19069>;
  <D.19068>:
  D.19070 = 0;
  return D.19070;
  <D.19069>:
  offset.25 = (unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, offset.25);
  recvflags = convert_socketflags (flags);
  if (recvflags == -1) goto <D.19072>; else goto <D.19073>;
  <D.19072>:
  *error = 10045;
  D.19070 = 0;
  return D.19070;
  <D.19073>:
  count.26 = (unsigned int) count;
  ret = _wapi_recv (sock, buf, count.26, recvflags);
  if (ret == -1) goto <D.19075>; else goto <D.19076>;
  <D.19075>:
  D.19077 = WSAGetLastError ();
  *error = D.19077;
  D.19070 = 0;
  return D.19070;
  <D.19076>:
  D.19070 = ret;
  return D.19070;
}


convert_socketflags (gint32 sflags)
{
  gint32 D.19081;
  int D.19082;
  int D.19085;
  int D.19088;
  int D.19091;
  int D.19094;
  gint32 flags;

  flags = 0;
  if (sflags == 0) goto <D.19079>; else goto <D.19080>;
  <D.19079>:
  D.19081 = 0;
  return D.19081;
  <D.19080>:
  D.19082 = sflags & -32792;
  if (D.19082 != 0) goto <D.19083>; else goto <D.19084>;
  <D.19083>:
  D.19081 = -1;
  return D.19081;
  <D.19084>:
  D.19085 = sflags & 1;
  if (D.19085 != 0) goto <D.19086>; else goto <D.19087>;
  <D.19086>:
  flags = flags | 1;
  <D.19087>:
  D.19088 = sflags & 2;
  if (D.19088 != 0) goto <D.19089>; else goto <D.19090>;
  <D.19089>:
  flags = flags | 2;
  <D.19090>:
  D.19091 = sflags & 4;
  if (D.19091 != 0) goto <D.19092>; else goto <D.19093>;
  <D.19092>:
  flags = flags | 4;
  <D.19093>:
  D.19094 = sflags & 32768;
  if (D.19094 != 0) goto <D.19095>; else goto <D.19096>;
  <D.19095>:
  flags = flags | 32768;
  <D.19096>:
  D.19081 = flags;
  return D.19081;
}


ves_icall_System_Net_Sockets_Socket_Receive_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  unsigned int D.19098;
  int D.19099;
  unsigned int recvflags.27;
  unsigned int recvflags.28;
  gint32 D.19104;
  unsigned int count.29;
  int D.19108;
  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.19098 = mono_array_length (buffers);
      count = (int) D.19098;
      D.19099 = convert_socketflags (flags);
      recvflags.27 = (unsigned int) D.19099;
      recvflags = recvflags.27;
      recvflags.28 = recvflags;
      if (recvflags.28 == 4294967295) goto <D.19102>; else goto <D.19103>;
      <D.19102>:
      *error = 10045;
      D.19104 = 0;
      return D.19104;
      <D.19103>:
      count.29 = (unsigned int) count;
      ret = WSARecv (sock, wsabufs, count.29, &recv, &recvflags, 0B, 0B);
      if (ret == -1) goto <D.19106>; else goto <D.19107>;
      <D.19106>:
      D.19108 = WSAGetLastError ();
      *error = D.19108;
      D.19104 = 0;
      return D.19104;
      <D.19107>:
      recv.30 = recv;
      D.19104 = (gint32) recv.30;
      return D.19104;
    }
  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.19112;
  int D.19113;
  gint32 D.19116;
  struct MonoObject * D.19117;
  int D.19118;
  unsigned int offset.31;
  unsigned int count.32;
  int D.19127;
  unsigned int sa_size.33;
  int sa_size.34;
  struct MonoObject * D.19132;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      recvflags = 0;
      *error = 0;
      D.19112 = mono_array_length (buffer);
      alen = (gint32) D.19112;
      D.19113 = alen - count;
      if (D.19113 < offset) goto <D.19114>; else goto <D.19115>;
      <D.19114>:
      D.19116 = 0;
      return D.19116;
      <D.19115>:
      D.19117 = *sockaddr;
      sa = create_sockaddr_from_object (D.19117, &sa_size, error);
      D.19118 = *error;
      if (D.19118 != 0) goto <D.19119>; else goto <D.19120>;
      <D.19119>:
      D.19116 = 0;
      return D.19116;
      <D.19120>:
      offset.31 = (unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, offset.31);
      recvflags = convert_socketflags (flags);
      if (recvflags == -1) goto <D.19122>; else goto <D.19123>;
      <D.19122>:
      *error = 10045;
      D.19116 = 0;
      return D.19116;
      <D.19123>:
      count.32 = (unsigned int) count;
      ret = _wapi_recvfrom (sock, buf, count.32, recvflags, sa, &sa_size);
      if (ret == -1) goto <D.19125>; else goto <D.19126>;
      <D.19125>:
      monoeg_g_free (sa);
      D.19127 = WSAGetLastError ();
      *error = D.19127;
      D.19116 = 0;
      return D.19116;
      <D.19126>:
      sa_size.33 = sa_size;
      if (sa_size.33 != 0) goto <D.19129>; else goto <D.19130>;
      <D.19129>:
      sa_size.33 = sa_size;
      sa_size.34 = (int) sa_size.33;
      D.19132 = create_object_from_sockaddr (sa, sa_size.34, error);
      *sockaddr = D.19132;
      goto <D.19133>;
      <D.19130>:
      *sockaddr = 0B;
      <D.19133>:
      monoeg_g_free (sa);
      D.19116 = ret;
      return D.19116;
    }
  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.19136;
  int D.19137;
  gint32 D.19140;
  unsigned int offset.35;
  unsigned int count.36;
  int D.19147;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;

  sendflags = 0;
  *error = 0;
  D.19136 = mono_array_length (buffer);
  alen = (gint32) D.19136;
  D.19137 = alen - count;
  if (D.19137 < offset) goto <D.19138>; else goto <D.19139>;
  <D.19138>:
  D.19140 = 0;
  return D.19140;
  <D.19139>:
  offset.35 = (unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, offset.35);
  sendflags = convert_socketflags (flags);
  if (sendflags == -1) goto <D.19142>; else goto <D.19143>;
  <D.19142>:
  *error = 10045;
  D.19140 = 0;
  return D.19140;
  <D.19143>:
  count.36 = (unsigned int) count;
  ret = _wapi_send (sock, buf, count.36, sendflags);
  if (ret == -1) goto <D.19145>; else goto <D.19146>;
  <D.19145>:
  D.19147 = WSAGetLastError ();
  *error = D.19147;
  D.19140 = 0;
  return D.19140;
  <D.19146>:
  D.19140 = ret;
  return D.19140;
}


ves_icall_System_Net_Sockets_Socket_Send_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  unsigned int D.19149;
  int D.19150;
  gint32 D.19153;
  unsigned int count.37;
  int D.19157;
  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.19149 = mono_array_length (buffers);
      count = (int) D.19149;
      D.19150 = convert_socketflags (flags);
      sendflags = (DWORD) D.19150;
      if (sendflags == 4294967295) goto <D.19151>; else goto <D.19152>;
      <D.19151>:
      *error = 10045;
      D.19153 = 0;
      return D.19153;
      <D.19152>:
      count.37 = (unsigned int) count;
      ret = WSASend (sock, wsabufs, count.37, &sent, sendflags, 0B, 0B);
      if (ret == -1) goto <D.19155>; else goto <D.19156>;
      <D.19155>:
      D.19157 = WSAGetLastError ();
      *error = D.19157;
      D.19153 = 0;
      return D.19153;
      <D.19156>:
      sent.38 = sent;
      D.19153 = (gint32) sent.38;
      return D.19153;
    }
  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.19161;
  int D.19162;
  gint32 D.19165;
  int D.19166;
  unsigned int offset.39;
  unsigned int count.40;
  unsigned int sa_size.41;
  int D.19176;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      sendflags = 0;
      *error = 0;
      D.19161 = mono_array_length (buffer);
      alen = (gint32) D.19161;
      D.19162 = alen - count;
      if (D.19162 < offset) goto <D.19163>; else goto <D.19164>;
      <D.19163>:
      D.19165 = 0;
      return D.19165;
      <D.19164>:
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.19166 = *error;
      if (D.19166 != 0) goto <D.19167>; else goto <D.19168>;
      <D.19167>:
      D.19165 = 0;
      return D.19165;
      <D.19168>:
      offset.39 = (unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, offset.39);
      sendflags = convert_socketflags (flags);
      if (sendflags == -1) goto <D.19170>; else goto <D.19171>;
      <D.19170>:
      *error = 10045;
      D.19165 = 0;
      return D.19165;
      <D.19171>:
      count.40 = (unsigned int) count;
      sa_size.41 = sa_size;
      ret = _wapi_sendto (sock, buf, count.40, sendflags, sa, sa_size.41);
      if (ret == -1) goto <D.19174>; else goto <D.19175>;
      <D.19174>:
      D.19176 = WSAGetLastError ();
      *error = D.19176;
      <D.19175>:
      monoeg_g_free (sa);
      D.19165 = ret;
      return D.19165;
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Select_internal (struct MonoArray * * sockets, gint32 timeout, gint32 * error)
{
  struct MonoArray * D.19179;
  unsigned int D.19180;
  unsigned int nfds.42;
  unsigned int D.19182;
  unsigned int i.43;
  char * D.19184;
  unsigned int idx.44;
  unsigned int D.19190;
  struct mono_pollfd * D.19191;
  unsigned int D.19192;
  int D.19193;
  short int iftmp.45;
  short int iftmp.46;
  int iftmp.47;
  int * D.19210;
  long int D.19211;
  int D.19212;
  int D.19217;
  unsigned int D.19227;
  unsigned int D.19228;
  int D.19229;
  struct MonoVTable * D.19232;
  unsigned int ret.48;
  unsigned int socks_size.49;
  struct MonoDomain * D.19235;
  char * D.19236;
  int D.19239;
  unsigned int D.19240;
  unsigned int D.19241;
  short int D.19242;
  unsigned short D.19248;
  int D.19249;
  int D.19250;
  int idx.50;
  unsigned int idx.51;
  int D.19257;
  int idx.52;
  unsigned int idx.53;
  int D.19261;
  int idx.54;
  unsigned int idx.55;
  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.19179 = *sockets;
      D.19180 = mono_array_length (D.19179);
      count = (int) D.19180;
      nfds = count + -3;
      nfds.42 = (unsigned int) nfds;
      D.19182 = nfds.42 * 8;
      pfds = monoeg_malloc0 (D.19182);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.18392>;
      <D.18391>:
      D.19179 = *sockets;
      i.43 = (unsigned int) i;
      D.19184 = mono_array_addr_with_size (D.19179, 4, i.43);
      obj = MEM[(struct MonoObject * *)D.19184];
      if (obj == 0B) goto <D.19185>; else goto <D.19186>;
      <D.19185>:
      mode = mode + 1;
      // predicted unlikely by continue predictor.
      goto <D.18390>;
      <D.19186>:
      if (idx >= nfds) goto <D.19187>; else goto <D.19188>;
      <D.19187>:
      monoeg_g_free (pfds);
      *error = 10014;
      return;
      <D.19188>:
      idx.44 = (unsigned int) idx;
      D.19190 = idx.44 * 8;
      D.19191 = pfds + D.19190;
      D.19192 = Socket_to_SOCKET (obj);
      D.19193 = (int) D.19192;
      D.19191->fd = D.19193;
      idx.44 = (unsigned int) idx;
      D.19190 = idx.44 * 8;
      D.19191 = pfds + D.19190;
      if (mode != 0) goto <D.19195>; else goto <D.19196>;
      <D.19195>:
      if (mode == 1) goto <D.19198>; else goto <D.19199>;
      <D.19198>:
      iftmp.46 = 4;
      goto <D.19200>;
      <D.19199>:
      iftmp.46 = 56;
      <D.19200>:
      iftmp.45 = iftmp.46;
      goto <D.19201>;
      <D.19196>:
      iftmp.45 = 1;
      <D.19201>:
      D.19191->events = iftmp.45;
      idx = idx + 1;
      <D.18390>:
      i = i + 1;
      <D.18392>:
      if (i < count) goto <D.18391>; else goto <D.18393>;
      <D.18393>:
      if (timeout >= 0) goto <D.19203>; else goto <D.19204>;
      <D.19203>:
      iftmp.47 = timeout / 1000;
      goto <D.19205>;
      <D.19204>:
      iftmp.47 = -1;
      <D.19205>:
      timeout = iftmp.47;
      start = time (0B);
      <D.18397>:
      *error = 0;
      nfds.42 = (unsigned int) nfds;
      ret = mono_poll (pfds, nfds.42, timeout);
      if (timeout > 0) goto <D.19206>; else goto <D.19207>;
      <D.19206>:
      if (ret < 0) goto <D.19208>; else goto <D.19209>;
      <D.19208>:
      {
        int err;
        int sec;

        D.19210 = __errno_location ();
        err = *D.19210;
        D.19211 = time (0B);
        sec = D.19211 - start;
        D.19212 = sec * -1000;
        timeout = D.19212 + timeout;
        if (timeout < 0) goto <D.19213>; else goto <D.19214>;
        <D.19213>:
        timeout = 0;
        <D.19214>:
        D.19210 = __errno_location ();
        *D.19210 = err;
      }
      <D.19209>:
      <D.19207>:
      if (ret == -1) goto <D.19215>; else goto <D.19216>;
      <D.19215>:
      D.19210 = __errno_location ();
      D.19217 = *D.19210;
      if (D.19217 == 4) goto <D.19218>; else goto <D.19219>;
      <D.19218>:
      {
        int leave;

        leave = 0;
        if (thread == 0B) goto <D.19220>; else goto <D.19221>;
        <D.19220>:
        thread = mono_thread_internal_current ();
        <D.19221>:
        leave = mono_thread_test_state (thread, 129);
        if (leave != 0) goto <D.19222>; else goto <D.19223>;
        <D.19222>:
        monoeg_g_free (pfds);
        *sockets = 0B;
        return;
        <D.19223>:
        mono_thread_interruption_checkpoint ();
        D.19210 = __errno_location ();
        *D.19210 = 4;
      }
      <D.19219>:
      <D.19216>:
      if (ret == -1) goto <D.19224>; else goto <D.18398>;
      <D.19224>:
      D.19210 = __errno_location ();
      D.19217 = *D.19210;
      if (D.19217 == 4) goto <D.18397>; else goto <D.18398>;
      <D.18398>:
      if (ret == -1) goto <D.19225>; else goto <D.19226>;
      <D.19225>:
      D.19210 = __errno_location ();
      D.19217 = *D.19210;
      D.19227 = (unsigned int) D.19217;
      D.19228 = errno_to_WSA (D.19227, &__func__);
      D.19229 = (int) D.19228;
      *error = D.19229;
      monoeg_g_free (pfds);
      return;
      <D.19226>:
      if (ret == 0) goto <D.19230>; else goto <D.19231>;
      <D.19230>:
      monoeg_g_free (pfds);
      *sockets = 0B;
      return;
      <D.19231>:
      D.19179 = *sockets;
      D.19232 = MEM[(struct MonoObject *)D.19179].vtable;
      sock_arr_class = D.19232->klass;
      ret.48 = (unsigned int) ret;
      socks_size.49 = ret.48 + 3;
      socks_size = socks_size.49;
      D.19235 = mono_domain_get ();
      socks = mono_array_new_full (D.19235, sock_arr_class, &socks_size, 0B);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.18406>;
      <D.18405>:
      {
        struct mono_pollfd * pfd;

        D.19179 = *sockets;
        i.43 = (unsigned int) i;
        D.19236 = mono_array_addr_with_size (D.19179, 4, i.43);
        obj = MEM[(struct MonoObject * *)D.19236];
        if (obj == 0B) goto <D.19237>; else goto <D.19238>;
        <D.19237>:
        mode = mode + 1;
        idx = idx + 1;
        // predicted unlikely by continue predictor.
        goto <D.18401>;
        <D.19238>:
        D.19239 = i - mode;
        D.19240 = (unsigned int) D.19239;
        D.19241 = D.19240 * 8;
        pfd = pfds + D.19241;
        D.19242 = pfd->revents;
        if (D.19242 == 0) goto <D.19243>; else goto <D.19244>;
        <D.19243>:
        // predicted unlikely by continue predictor.
        goto <D.18401>;
        <D.19244>:
        ret = ret + -1;
        if (mode == 0) goto <D.19247>; else goto <D.19245>;
        <D.19247>:
        D.19242 = pfd->revents;
        D.19248 = (unsigned short) D.19242;
        D.19249 = (int) D.19248;
        D.19250 = D.19249 & 57;
        if (D.19250 != 0) goto <D.19251>; else goto <D.19245>;
        <D.19251>:
        {
          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.19246>;
        <D.19245>:
        if (mode == 1) goto <D.19256>; else goto <D.19254>;
        <D.19256>:
        D.19242 = pfd->revents;
        D.19248 = (unsigned short) D.19242;
        D.19249 = (int) D.19248;
        D.19257 = D.19249 & 60;
        if (D.19257 != 0) goto <D.19258>; else goto <D.19254>;
        <D.19258>:
        {
          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.19255>;
        <D.19254>:
        D.19242 = pfd->revents;
        D.19248 = (unsigned short) D.19242;
        D.19249 = (int) D.19248;
        D.19261 = D.19249 & 56;
        if (D.19261 != 0) goto <D.19262>; else goto <D.19263>;
        <D.19262>:
        {
          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.19263>:
        <D.19255>:
        <D.19246>:
      }
      <D.18401>:
      i = i + 1;
      <D.18406>:
      if (i < count) goto <D.19266>; else goto <D.18407>;
      <D.19266>:
      if (ret > 0) goto <D.18405>; else goto <D.18407>;
      <D.18407>:
      *sockets = socks;
      monoeg_g_free (pfds);
    }
  finally
    {
      socks_size = {CLOBBER};
    }
}


Socket_to_SOCKET (struct MonoObject * sockobj)
{
  struct MonoVTable * D.19270;
  struct MonoClass * D.19271;
  int D.19272;
  sizetype D.19273;
  void * * D.19274;
  void * D.19275;
  SOCKET D.19276;
  SOCKET sock;
  struct MonoClassField * field;

  D.19270 = sockobj->vtable;
  D.19271 = D.19270->klass;
  field = mono_class_get_field_from_name (D.19271, "socket");
  D.19272 = field->offset;
  D.19273 = (sizetype) D.19272;
  D.19274 = sockobj + D.19273;
  D.19275 = *D.19274;
  sock = (SOCKET) D.19275;
  D.19276 = sock;
  return D.19276;
}


ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal (SOCKET sock, gint32 level, gint32 name, struct MonoObject * * obj_val, gint32 * error)
{
  <unnamed type> level.56;
  struct MonoObject * D.19287;
  int system_level.57;
  int system_name.58;
  int D.19292;
  struct MonoImage * D.19293;
  int D.19294;
  sizetype D.19295;
  guint8 * D.19296;
  int D.19297;
  unsigned char D.19298;
  guint32 * D.19299;
  int D.19300;
  unsigned int D.19301;
  _Bool D.19302;
  int D.19303;
  int time_ms.59;
  struct MonoImage * mono_posix_image.60;
  struct MonoImage * mono_posix_image.61;
  struct MonoImage * mono_posix_image.62;
  int D.19314;
  unsigned int D.19315;
  int D.19316;
  unsigned int D.19317;
  int D.19318;
  int val.63;
  _Bool D.19324;
  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;
      if (level == 65535) goto <D.19280>; else goto <D.19278>;
      <D.19280>:
      if (name == -5) goto <D.19281>; else goto <D.19278>;
      <D.19281>:
      system_level = 65535;
      system_name = 4;
      ret = 0;
      goto <D.19279>;
      <D.19278>:
      level.56 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.56, name, &system_level, &system_name);
      <D.19279>:
      if (ret == -1) goto <D.19283>; else goto <D.19284>;
      <D.19283>:
      *error = 10042;
      return;
      <D.19284>:
      if (ret == -2) goto <D.19285>; else goto <D.19286>;
      <D.19285>:
      D.19287 = int_to_object (domain, 0);
      *obj_val = D.19287;
      return;
      <D.19286>:
      switch (name) <default: <D.18440>, case -129: <D.18435>, case 128: <D.18434>, case 4101: <D.18437>, case 4102: <D.18438>, case 10001: <D.18439>>
      <D.18434>:
      <D.18435>:
      system_level.57 = system_level;
      system_name.58 = system_name;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.58, &linger, &lingersize);
      goto <D.18436>;
      <D.18437>:
      <D.18438>:
      system_level.57 = system_level;
      system_name.58 = system_name;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.58, &time_ms, &time_ms_size);
      goto <D.18436>;
      <D.18439>:
      system_level.57 = system_level;
      system_name.58 = system_name;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.58, &cred, &credsize);
      goto <D.18436>;
      <D.18440>:
      system_level.57 = system_level;
      system_name.58 = system_name;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.58, &val, &valsize);
      <D.18436>:
      if (ret == -1) goto <D.19290>; else goto <D.19291>;
      <D.19290>:
      D.19292 = WSAGetLastError ();
      *error = D.19292;
      return;
      <D.19291>:
      switch (name) <default: <D.18450>, case -129: <D.18443>, case 128: <D.18441>, case 4101: <D.18444>, case 4102: <D.18445>, case 10001: <D.18446>>
      <D.18441>:
      D.19293 = get_socket_assembly ();
      obj_class = mono_class_from_name (D.19293, "System.Net.Sockets", "LingerOption");
      obj = mono_object_new (domain, obj_class);
      field = mono_class_get_field_from_name (obj_class, "enabled");
      D.19294 = field->offset;
      D.19295 = (sizetype) D.19294;
      D.19296 = obj + D.19295;
      D.19297 = linger.l_onoff;
      D.19298 = (unsigned char) D.19297;
      *D.19296 = D.19298;
      field = mono_class_get_field_from_name (obj_class, "seconds");
      D.19294 = field->offset;
      D.19295 = (sizetype) D.19294;
      D.19299 = obj + D.19295;
      D.19300 = linger.l_linger;
      D.19301 = (unsigned int) D.19300;
      *D.19299 = D.19301;
      goto <D.18442>;
      <D.18443>:
      D.19297 = linger.l_onoff;
      D.19302 = D.19297 == 0;
      D.19303 = (int) D.19302;
      obj = int_to_object (domain, D.19303);
      goto <D.18442>;
      <D.18444>:
      <D.18445>:
      time_ms.59 = time_ms;
      obj = int_to_object (domain, time_ms.59);
      goto <D.18442>;
      <D.18446>:
      {
        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.19306>; else goto <D.19307>;
        <D.19306>:
        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.19309>; else goto <D.19310>;
        <D.19309>:
        {
          struct MonoAssembly * sa;

          sa = mono_assembly_open ("Mono.Posix.dll", 0B);
          if (sa == 0B) goto <D.19311>; else goto <D.19312>;
          <D.19311>:
          *error = 10042;
          return;
          <D.19312>:
          mono_posix_image.62 = mono_assembly_get_image (sa);
          mono_posix_image = mono_posix_image.62;
        }
        <D.19310>:
        <D.19307>:
        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.19314 = cred.pid;
        cred_data->pid = D.19314;
        D.19315 = cred.uid;
        D.19316 = (int) D.19315;
        cred_data->uid = D.19316;
        D.19317 = cred.gid;
        D.19318 = (int) D.19317;
        cred_data->gid = D.19318;
        goto <D.18442>;
      }
      <D.18450>:
      if (level == 65535) goto <D.19319>; else goto <D.19320>;
      <D.19319>:
      if (name == -5) goto <D.19321>; else goto <D.19322>;
      <D.19321>:
      val.63 = val;
      D.19324 = val.63 == 0;
      val.64 = (int) D.19324;
      val = val.64;
      <D.19322>:
      <D.19320>:
      val.63 = val;
      obj = int_to_object (domain, val.63);
      <D.18442>:
      *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.19329;
  int cached.65;
  int iftmp.66;
  int proto.67;

  switch (mono_level) <default: <D.18070>, case 0: <D.18022>, case 6: <D.18059>, case 17: <D.18066>, case 41: <D.18040>, case 65535: <D.17997>>
  <D.17997>:
  *system_level = 65535;
  switch (mono_name) <default: <D.18020>, case -129: <D.17998>, case -5: <D.18017>, case 1: <D.18000>, case 2: <D.18001>, case 4: <D.18002>, case 8: <D.18003>, case 16: <D.18004>, case 32: <D.18005>, case 64: <D.18018>, case 128: <D.18006>, case 256: <D.18007>, case 4097: <D.18008>, case 4098: <D.18009>, case 4099: <D.18010>, case 4100: <D.18011>, case 4101: <D.18012>, case 4102: <D.18013>, case 4103: <D.18014>, case 4104: <D.18015>, case 10001: <D.18016>, case 2147483647: <D.18019>>
  <D.17998>:
  *system_name = 128;
  goto <D.17999>;
  <D.18000>:
  *system_name = 1;
  goto <D.17999>;
  <D.18001>:
  *system_name = 4105;
  goto <D.17999>;
  <D.18002>:
  *system_name = 4;
  goto <D.17999>;
  <D.18003>:
  *system_name = 8;
  goto <D.17999>;
  <D.18004>:
  *system_name = 16;
  goto <D.17999>;
  <D.18005>:
  *system_name = 32;
  goto <D.17999>;
  <D.18006>:
  *system_name = 128;
  goto <D.17999>;
  <D.18007>:
  *system_name = 256;
  goto <D.17999>;
  <D.18008>:
  *system_name = 4097;
  goto <D.17999>;
  <D.18009>:
  *system_name = 4098;
  goto <D.17999>;
  <D.18010>:
  *system_name = 4099;
  goto <D.17999>;
  <D.18011>:
  *system_name = 4100;
  goto <D.17999>;
  <D.18012>:
  *system_name = 4101;
  goto <D.17999>;
  <D.18013>:
  *system_name = 4102;
  goto <D.17999>;
  <D.18014>:
  *system_name = 4103;
  goto <D.17999>;
  <D.18015>:
  *system_name = 4104;
  goto <D.17999>;
  <D.18016>:
  *system_name = 18;
  goto <D.17999>;
  <D.18017>:
  <D.18018>:
  <D.18019>:
  *system_name = 128;
  goto <D.17999>;
  <D.18020>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at Socket level", mono_name);
  D.19329 = -1;
  return D.19329;
  <D.17999>:
  goto <D.18021>;
  <D.18022>:
  *system_level = 0;
  switch (mono_name) <default: <D.18039>, case 1: <D.18023>, case 2: <D.18025>, case 3: <D.18026>, case 4: <D.18027>, case 9: <D.18028>, case 10: <D.18029>, case 11: <D.18030>, case 12: <D.18031>, case 13: <D.18032>, case 14: <D.18034>, case 15: <D.18035>, case 16: <D.18036>, case 17: <D.18037>, case 18: <D.18038>, case 19: <D.18033>>
  <D.18023>:
  *system_name = 4;
  goto <D.18024>;
  <D.18025>:
  *system_name = 3;
  goto <D.18024>;
  <D.18026>:
  *system_name = 1;
  goto <D.18024>;
  <D.18027>:
  *system_name = 2;
  goto <D.18024>;
  <D.18028>:
  *system_name = 32;
  goto <D.18024>;
  <D.18029>:
  *system_name = 33;
  goto <D.18024>;
  <D.18030>:
  *system_name = 34;
  goto <D.18024>;
  <D.18031>:
  *system_name = 35;
  goto <D.18024>;
  <D.18032>:
  *system_name = 36;
  goto <D.18024>;
  <D.18033>:
  *system_name = 8;
  goto <D.18024>;
  <D.18034>:
  *system_name = 10;
  goto <D.18024>;
  <D.18035>:
  <D.18036>:
  <D.18037>:
  <D.18038>:
  <D.18039>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IP level", mono_name);
  D.19329 = -1;
  return D.19329;
  <D.18024>:
  goto <D.18021>;
  <D.18040>:
  *system_level = 41;
  switch (mono_name) <default: <D.18058>, case 1: <D.18051>, case 2: <D.18050>, case 3: <D.18052>, case 4: <D.18041>, case 9: <D.18044>, case 10: <D.18045>, case 11: <D.18046>, case 12: <D.18047>, case 13: <D.18048>, case 14: <D.18053>, case 15: <D.18054>, case 16: <D.18055>, case 17: <D.18056>, case 18: <D.18057>, case 19: <D.18049>, case 21: <D.18042>>
  <D.18041>:
  <D.18042>:
  *system_name = 16;
  goto <D.18043>;
  <D.18044>:
  *system_name = 17;
  goto <D.18043>;
  <D.18045>:
  *system_name = 18;
  goto <D.18043>;
  <D.18046>:
  *system_name = 19;
  goto <D.18043>;
  <D.18047>:
  *system_name = 20;
  goto <D.18043>;
  <D.18048>:
  *system_name = 21;
  goto <D.18043>;
  <D.18049>:
  *system_name = 50;
  goto <D.18043>;
  <D.18050>:
  <D.18051>:
  <D.18052>:
  <D.18053>:
  <D.18054>:
  <D.18055>:
  <D.18056>:
  <D.18057>:
  <D.18058>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IPv6 level", mono_name);
  D.19329 = -1;
  return D.19329;
  <D.18043>:
  goto <D.18021>;
  <D.18059>:
  if (1 != 0) goto <D.19330>; else goto <D.19331>;
  <D.19330>:
  {
    static int cached = 0;
    static int proto;

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

      pent = getprotobyname ("TCP");
      if (pent != 0B) goto <D.19336>; else goto <D.19337>;
      <D.19336>:
      iftmp.66 = pent->p_proto;
      goto <D.19338>;
      <D.19337>:
      iftmp.66 = 6;
      <D.19338>:
      proto = iftmp.66;
      cached = 1;
    }
    <D.19334>:
    proto.67 = proto;
    *system_level = proto.67;
  }
  <D.19331>:
  switch (mono_name) <default: <D.18065>, case 1: <D.18063>>
  <D.18063>:
  *system_name = 1;
  goto <D.18064>;
  <D.18065>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at TCP level", mono_name);
  D.19329 = -1;
  return D.19329;
  <D.18064>:
  goto <D.18021>;
  <D.18066>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unsupported value 0x%x", mono_level);
  switch (mono_name) <default: <D.18069>, case 1: <D.18067>, case 20: <D.18068>>
  <D.18067>:
  <D.18068>:
  <D.18069>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at UDP level", mono_name);
  D.19329 = -1;
  return D.19329;
  D.19329 = -1;
  return D.19329;
  <D.18070>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unknown value 0x%x", mono_level);
  D.19329 = -1;
  return D.19329;
  <D.18021>:
  D.19329 = 0;
  return D.19329;
}


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

  D.19343 = mono_get_int32_class ();
  D.19342 = mono_value_box (domain, D.19343, &val);
  return D.19342;
}


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.19350;
  unsigned int valsize.69;
  int system_level.70;
  int system_name.71;
  int D.19356;
  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.19346>; else goto <D.19347>;
      <D.19346>:
      *error = 10042;
      return;
      <D.19347>:
      if (ret == -2) goto <D.19348>; else goto <D.19349>;
      <D.19348>:
      return;
      <D.19349>:
      D.19350 = *byte_val;
      valsize.69 = mono_array_length (D.19350);
      valsize = valsize.69;
      D.19350 = *byte_val;
      buf = mono_array_addr_with_size (D.19350, 1, 0);
      system_level.70 = system_level;
      system_name.71 = system_name;
      ret = _wapi_getsockopt (sock, system_level.70, system_name.71, buf, &valsize);
      if (ret == -1) goto <D.19354>; else goto <D.19355>;
      <D.19354>:
      D.19356 = WSAGetLastError ();
      *error = D.19356;
      <D.19355>:
    }
  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;
  int int_val.73;
  _Bool D.19366;
  int int_val.74;
  struct MonoVTable * D.19374;
  struct MonoClass * D.19375;
  int D.19376;
  sizetype D.19377;
  guint8 * D.19378;
  unsigned char D.19379;
  int D.19380;
  guint32 * D.19381;
  unsigned int D.19382;
  int D.19383;
  int system_level.75;
  int system_name.76;
  unsigned int valsize.77;
  void * * D.19389;
  guint64 * D.19392;
  long long unsigned int D.19393;
  unsigned int D.19394;
  gint32 * D.19402;
  int D.19403;
  unsigned int D.19407;
  unsigned char D.19410;
  _Bool D.19411;
  int D.19412;
  unsigned int valsize.78;
  unsigned int int_val.79;
  unsigned int D.19417;
  unsigned int D.19418;
  unsigned int D.19419;
  unsigned int D.19420;
  unsigned int D.19421;
  unsigned int D.19422;
  unsigned int D.19423;
  unsigned int D.19424;
  unsigned int D.19425;
  int int_val.80;
  unsigned int D.19427;
  int D.19434;
  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);
      if (level == 65535) goto <D.19361>; else goto <D.19362>;
      <D.19361>:
      if (name == -5) goto <D.19363>; else goto <D.19364>;
      <D.19363>:
      system_name = 4;
      int_val.73 = int_val;
      D.19366 = int_val.73 == 0;
      int_val.74 = (int) D.19366;
      int_val = int_val.74;
      ret = 0;
      <D.19364>:
      <D.19362>:
      if (ret == -1) goto <D.19368>; else goto <D.19369>;
      <D.19368>:
      *error = 10042;
      return;
      <D.19369>:
      if (ret == -2) goto <D.19370>; else goto <D.19371>;
      <D.19370>:
      return;
      <D.19371>:
      if (obj_val != 0B) goto <D.19372>; else goto <D.19373>;
      <D.19372>:
      {
        struct MonoClassField * field;
        int valsize;

        switch (name) <default: <D.18502>, case 12: <D.18497>, case 13: <D.18498>, case 128: <D.18495>>
        <D.18495>:
        D.19374 = obj_val->vtable;
        D.19375 = D.19374->klass;
        field = mono_class_get_field_from_name (D.19375, "enabled");
        D.19376 = field->offset;
        D.19377 = (sizetype) D.19376;
        D.19378 = obj_val + D.19377;
        D.19379 = *D.19378;
        D.19380 = (int) D.19379;
        linger.l_onoff = D.19380;
        D.19374 = obj_val->vtable;
        D.19375 = D.19374->klass;
        field = mono_class_get_field_from_name (D.19375, "seconds");
        D.19376 = field->offset;
        D.19377 = (sizetype) D.19376;
        D.19381 = obj_val + D.19377;
        D.19382 = *D.19381;
        D.19383 = (int) D.19382;
        linger.l_linger = D.19383;
        valsize = 8;
        system_level.75 = system_level;
        system_name.76 = system_name;
        valsize.77 = (unsigned int) valsize;
        ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &linger, valsize.77);
        goto <D.18496>;
        <D.18497>:
        <D.18498>:
        {
          struct MonoObject * address;

          address = 0B;
          system_level.75 = system_level;
          if (system_level.75 == sol_ipv6) goto <D.19387>; else goto <D.19388>;
          <D.19387>:
          {
            struct ipv6_mreq mreq6;

            try
              {
                D.19374 = obj_val->vtable;
                D.19375 = D.19374->klass;
                field = mono_class_get_field_from_name (D.19375, "group");
                D.19376 = field->offset;
                D.19377 = (sizetype) D.19376;
                D.19389 = obj_val + D.19377;
                address = *D.19389;
                if (address != 0B) goto <D.19390>; else goto <D.19391>;
                <D.19390>:
                mreq6.ipv6mr_multiaddr = ipaddress_to_struct_in6_addr (address);
                <D.19391>:
                D.19374 = obj_val->vtable;
                D.19375 = D.19374->klass;
                field = mono_class_get_field_from_name (D.19375, "ifIndex");
                D.19376 = field->offset;
                D.19377 = (sizetype) D.19376;
                D.19392 = obj_val + D.19377;
                D.19393 = *D.19392;
                D.19394 = (unsigned int) D.19393;
                mreq6.ipv6mr_interface = D.19394;
                system_level.75 = system_level;
                system_name.76 = system_name;
                ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &mreq6, 20);
              }
            finally
              {
                mreq6 = {CLOBBER};
              }
          }
          goto <D.19395>;
          <D.19388>:
          system_level.75 = system_level;
          if (system_level.75 == sol_ip) goto <D.19396>; else goto <D.19397>;
          <D.19396>:
          {
            struct ip_mreqn mreq;

            try
              {
                mreq = {};
                D.19374 = obj_val->vtable;
                D.19375 = D.19374->klass;
                field = mono_class_get_field_from_name (D.19375, "group");
                D.19376 = field->offset;
                D.19377 = (sizetype) D.19376;
                D.19389 = obj_val + D.19377;
                address = *D.19389;
                if (address != 0B) goto <D.19398>; else goto <D.19399>;
                <D.19398>:
                mreq.imr_multiaddr = ipaddress_to_struct_in_addr (address);
                <D.19399>:
                D.19374 = obj_val->vtable;
                D.19375 = D.19374->klass;
                field = mono_class_get_field_from_name (D.19375, "local");
                D.19376 = field->offset;
                D.19377 = (sizetype) D.19376;
                D.19389 = obj_val + D.19377;
                address = *D.19389;
                if (address != 0B) goto <D.19400>; else goto <D.19401>;
                <D.19400>:
                mreq.imr_address = ipaddress_to_struct_in_addr (address);
                <D.19401>:
                D.19374 = obj_val->vtable;
                D.19375 = D.19374->klass;
                field = mono_class_get_field_from_name (D.19375, "iface_index");
                D.19376 = field->offset;
                D.19377 = (sizetype) D.19376;
                D.19402 = obj_val + D.19377;
                D.19403 = *D.19402;
                mreq.imr_ifindex = D.19403;
                system_level.75 = system_level;
                system_name.76 = system_name;
                ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &mreq, 12);
              }
            finally
              {
                mreq = {CLOBBER};
              }
          }
          <D.19397>:
          <D.19395>:
          goto <D.18496>;
        }
        <D.18502>:
        *error = 10022;
        return;
        <D.18496>:
      }
      goto <D.19404>;
      <D.19373>:
      if (byte_val != 0B) goto <D.19405>; else goto <D.19406>;
      <D.19405>:
      {
        int valsize;
        guchar * buf;

        D.19407 = mono_array_length (byte_val);
        valsize = (int) D.19407;
        buf = mono_array_addr_with_size (byte_val, 1, 0);
        switch (name) <default: <D.18507>, case -129: <D.18505>>
        <D.18505>:
        if (valsize == 1) goto <D.19408>; else goto <D.19409>;
        <D.19408>:
        D.19410 = *buf;
        D.19411 = D.19410 == 0;
        D.19412 = (int) D.19411;
        linger.l_onoff = D.19412;
        linger.l_linger = 0;
        system_level.75 = system_level;
        system_name.76 = system_name;
        ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &linger, 8);
        goto <D.19413>;
        <D.19409>:
        *error = 10022;
        <D.19413>:
        goto <D.18506>;
        <D.18507>:
        system_level.75 = system_level;
        system_name.76 = system_name;
        valsize.78 = (unsigned int) valsize;
        ret = _wapi_setsockopt (sock, system_level.75, system_name.76, buf, valsize.78);
        goto <D.18506>;
        <D.18506>:
      }
      goto <D.19415>;
      <D.19406>:
      switch (name) <default: <D.18513>, case -129: <D.18508>, case 9: <D.18510>, case 14: <D.18512>>
      <D.18508>:
      int_val.73 = int_val;
      D.19366 = int_val.73 == 0;
      int_val.74 = (int) D.19366;
      linger.l_onoff = int_val.74;
      linger.l_linger = 0;
      system_level.75 = system_level;
      system_name.76 = system_name;
      ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &linger, 8);
      goto <D.18509>;
      <D.18510>:
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19417 = int_val.79 << 24;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19418 = int_val.79 & 16711680;
      D.19419 = D.19418 >> 8;
      D.19420 = D.19417 | D.19419;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19421 = int_val.79 & 65280;
      D.19422 = D.19421 << 8;
      D.19423 = D.19420 | D.19422;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19424 = int_val.79 >> 24;
      D.19425 = D.19423 | D.19424;
      int_val.80 = (int) D.19425;
      int_val = int_val.80;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19427 = int_val.79 & 4278190080;
      if (D.19427 == 0) goto <D.19428>; else goto <D.19429>;
      <D.19428>:
      {
        struct ip_mreqn mreq;

        try
          {
            mreq = {};
            int_val.73 = int_val;
            mreq.imr_ifindex = int_val.73;
            system_level.75 = system_level;
            system_name.76 = system_name;
            ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &mreq, 12);
            goto <D.18509>;
          }
        finally
          {
            mreq = {CLOBBER};
          }
      }
      <D.19429>:
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19417 = int_val.79 << 24;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19418 = int_val.79 & 16711680;
      D.19419 = D.19418 >> 8;
      D.19420 = D.19417 | D.19419;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19421 = int_val.79 & 65280;
      D.19422 = D.19421 << 8;
      D.19423 = D.19420 | D.19422;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.19424 = int_val.79 >> 24;
      D.19425 = D.19423 | D.19424;
      int_val.80 = (int) D.19425;
      int_val = int_val.80;
      system_level.75 = system_level;
      system_name.76 = system_name;
      ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &int_val, 4);
      goto <D.18509>;
      <D.18512>:
      int_val.73 = int_val;
      if (int_val.73 == 1) goto <D.19430>; else goto <D.19431>;
      <D.19430>:
      int_val = 2;
      <D.19431>:
      <D.18513>:
      system_level.75 = system_level;
      system_name.76 = system_name;
      ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &int_val, 4);
      <D.18509>:
      <D.19415>:
      <D.19404>:
      if (ret == -1) goto <D.19432>; else goto <D.19433>;
      <D.19432>:
      D.19434 = WSAGetLastError ();
      *error = D.19434;
      <D.19433>:
    }
  finally
    {
      linger = {CLOBBER};
      system_level = {CLOBBER};
      system_name = {CLOBBER};
    }
}


ipaddress_to_struct_in6_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.19440;
  struct MonoClass * D.19441;
  int D.19442;
  sizetype D.19443;
  struct MonoArray * * D.19444;
  unsigned int i.81;
  char * D.19446;
  short unsigned int D.19447;
  struct in6_addr in6addr;
  struct MonoClassField * field;
  struct MonoArray * data;
  int i;

  try
    {
      D.19440 = ipaddr->vtable;
      D.19441 = D.19440->klass;
      field = mono_class_get_field_from_name (D.19441, "m_Numbers");
      D.19442 = field->offset;
      D.19443 = (sizetype) D.19442;
      D.19444 = ipaddr + D.19443;
      data = *D.19444;
      i = 0;
      goto <D.18476>;
      <D.18475>:
      i.81 = (unsigned int) i;
      D.19446 = mono_array_addr_with_size (data, 2, i.81);
      D.19447 = MEM[(guint16 *)D.19446];
      in6addr.__in6_u.__u6_addr16[i] = D.19447;
      i = i + 1;
      <D.18476>:
      if (i <= 7) goto <D.18475>; else goto <D.18477>;
      <D.18477>:
      <retval> = in6addr;
      return <retval>;
    }
  finally
    {
      in6addr = {CLOBBER};
    }
}


ipaddress_to_struct_in_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.19451;
  struct MonoClass * D.19452;
  int D.19453;
  sizetype D.19454;
  guint64 * D.19455;
  long long unsigned int D.19456;
  unsigned int D.19457;
  struct in_addr inaddr;
  struct MonoClassField * field;

  try
    {
      D.19451 = ipaddr->vtable;
      D.19452 = D.19451->klass;
      field = mono_class_get_field_from_name (D.19452, "m_Address");
      D.19453 = field->offset;
      D.19454 = (sizetype) D.19453;
      D.19455 = ipaddr + D.19454;
      D.19456 = *D.19455;
      D.19457 = (unsigned int) D.19456;
      inaddr.s_addr = D.19457;
      <retval> = inaddr;
      return <retval>;
    }
  finally
    {
      inaddr = {CLOBBER};
    }
}


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

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


ves_icall_System_Net_Sockets_Socket_WSAIoctl (SOCKET sock, gint32 code, struct MonoArray * input, struct MonoArray * output, gint32 * error)
{
  int D.19465;
  unsigned int D.19469;
  unsigned int D.19473;
  int D.19476;
  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 == 26238) goto <D.19463>; else goto <D.19464>;
      <D.19463>:
      D.19465 = -1;
      return D.19465;
      <D.19464>:
      if (input == 0B) goto <D.19466>; else goto <D.19467>;
      <D.19466>:
      i_buffer = 0B;
      i_len = 0;
      goto <D.19468>;
      <D.19467>:
      i_buffer = mono_array_addr_with_size (input, 1, 0);
      D.19469 = mono_array_length (input);
      i_len = (gint) D.19469;
      <D.19468>:
      if (output == 0B) goto <D.19470>; else goto <D.19471>;
      <D.19470>:
      o_buffer = 0B;
      o_len = 0;
      goto <D.19472>;
      <D.19471>:
      o_buffer = mono_array_addr_with_size (output, 1, 0);
      D.19473 = mono_array_length (output);
      o_len = (gint) D.19473;
      <D.19472>:
      ret = WSAIoctl (sock, code, i_buffer, i_len, o_buffer, o_len, &output_bytes, 0B, 0B);
      if (ret == -1) goto <D.19474>; else goto <D.19475>;
      <D.19474>:
      D.19476 = WSAGetLastError ();
      *error = D.19476;
      D.19465 = -1;
      return D.19465;
      <D.19475>:
      D.19465 = output_bytes;
      return D.19465;
    }
  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.19479;
  int D.19484;
  int D.18626;
  int D.19489;
  int D.19492;
  MonoBoolean D.19495;
  struct addrinfo * info.82;
  int D.19497;
  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.19479 = *hostname;
      if (D.19479 == 0) goto <D.19480>; else goto <D.19481>;
      <D.19480>:
      add_local_ips = 1;
      *h_name = host;
      <D.19481>:
      if (add_local_ips == 0) goto <D.19482>; else goto <D.19483>;
      <D.19482>:
      D.19484 = gethostname (&this_hostname, 256);
      if (D.19484 != -1) goto <D.19485>; else goto <D.19486>;
      <D.19485>:
      {
        size_t __s1_len;
        size_t __s2_len;

        D.18626 = __builtin_strcmp (hostname, &this_hostname);
      }
      if (D.18626 == 0) goto <D.19487>; else goto <D.19488>;
      <D.19487>:
      add_local_ips = 1;
      *h_name = host;
      <D.19488>:
      <D.19486>:
      <D.19483>:
      memset (&hints, 0, 32);
      D.19489 = get_family_hint ();
      hints.ai_family = D.19489;
      hints.ai_socktype = 2;
      hints.ai_flags = 2;
      D.19479 = *hostname;
      if (D.19479 != 0) goto <D.19490>; else goto <D.19491>;
      <D.19490>:
      D.19492 = getaddrinfo (hostname, 0B, &hints, &info);
      if (D.19492 == -1) goto <D.19493>; else goto <D.19494>;
      <D.19493>:
      D.19495 = 0;
      return D.19495;
      <D.19494>:
      <D.19491>:
      monoeg_g_free (hostname);
      info.82 = info;
      D.19497 = addrinfo_to_IPHostEntry (info.82, h_name, h_aliases, h_addr_list, add_local_ips);
      D.19495 = (MonoBoolean) D.19497;
      return D.19495;
    }
  finally
    {
      this_hostname = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
    }
}


gethostname (char * __buf, size_t __buflen)
{
  unsigned int D.19500;
  int D.19503;
  int D.19506;
  unsigned int D.19507;
  unsigned int D.19508;
  unsigned int D.19511;

  D.19500 = __builtin_object_size (__buf, 1);
  if (D.19500 != 4294967295) goto <D.19501>; else goto <D.19502>;
  <D.19501>:
  D.19503 = __builtin_constant_p (__buflen);
  if (D.19503 == 0) goto <D.19504>; else goto <D.19505>;
  <D.19504>:
  D.19507 = __builtin_object_size (__buf, 1);
  D.19506 = __gethostname_chk (__buf, __buflen, D.19507);
  return D.19506;
  <D.19505>:
  D.19508 = __builtin_object_size (__buf, 1);
  if (D.19508 < __buflen) goto <D.19509>; else goto <D.19510>;
  <D.19509>:
  D.19511 = __builtin_object_size (__buf, 1);
  D.19506 = __gethostname_chk_warn (__buf, __buflen, D.19511);
  return D.19506;
  <D.19510>:
  <D.19502>:
  D.19506 = __gethostname_alias (__buf, __buflen);
  return D.19506;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.19515;
  int D.19520;
  void * D.19522;
  unsigned int D.19523;

  D.19515 = __builtin_constant_p (__len);
  if (D.19515 != 0) goto <D.19516>; else goto <D.19517>;
  <D.19516>:
  if (__len == 0) goto <D.19518>; else goto <D.19519>;
  <D.19518>:
  D.19520 = __builtin_constant_p (__ch);
  if (D.19520 == 0) goto <D.19513>; else goto <D.19521>;
  <D.19521>:
  if (__ch != 0) goto <D.19513>; else goto <D.19514>;
  <D.19513>:
  __warn_memset_zero_len ();
  D.19522 = __dest;
  return D.19522;
  <D.19514>:
  <D.19519>:
  <D.19517>:
  D.19523 = __builtin_object_size (__dest, 0);
  D.19522 = __builtin___memset_chk (__dest, __ch, __len, D.19523);
  return D.19522;
}


get_family_hint ()
{
  unsigned char D.19525;
  struct MonoImage * D.19528;
  struct MonoDomain * D.19529;
  _Bool D.19530;
  long int D.19531;
  long int D.19532;
  union mono_mutex_t * D.19535;
  _Bool D.19538;
  long int D.19539;
  long int D.19540;
  int ipv4_enabled.83;
  int ipv6_enabled.84;
  _Bool D.19554;
  long int D.19555;
  long int D.19556;
  int D.19559;
  gint32 D.19560;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.19525 = domain->inet_family_hint;
  if (D.19525 == 0) goto <D.19526>; else goto <D.19527>;
  <D.19526>:
  {
    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.19528 = get_socket_assembly ();
        socket_class = mono_class_from_name (D.19528, "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.19529 = mono_domain_get ();
        vtable = mono_class_vtable (D.19529, socket_class);
        D.19530 = vtable == 0B;
        D.19531 = (long int) D.19530;
        D.19532 = __builtin_expect (D.19531, 0);
        if (D.19532 != 0) goto <D.19533>; else goto <D.19534>;
        <D.19533>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 715, "vtable");
        <D.19534>:
        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.19535 = &domain->lock.mutex;
          ret = pthread_mutex_lock (D.19535);
          if (ret != 0) goto <D.19536>; else goto <D.19537>;
          <D.19536>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d", ret);
          <D.19537>:
          D.19538 = ret != 0;
          D.19539 = (long int) D.19538;
          D.19540 = __builtin_expect (D.19539, 0);
          if (D.19540 != 0) goto <D.19541>; else goto <D.19542>;
          <D.19541>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 721, "ret == 0");
          <D.19542>:
        }
        ipv4_enabled.83 = ipv4_enabled;
        if (ipv4_enabled.83 == 1) goto <D.19546>; else goto <D.19543>;
        <D.19546>:
        ipv6_enabled.84 = ipv6_enabled;
        if (ipv6_enabled.84 == 1) goto <D.19548>; else goto <D.19543>;
        <D.19548>:
        domain->inet_family_hint = 1;
        goto <D.19544>;
        <D.19543>:
        ipv4_enabled.83 = ipv4_enabled;
        if (ipv4_enabled.83 == 1) goto <D.19549>; else goto <D.19550>;
        <D.19549>:
        domain->inet_family_hint = 2;
        goto <D.19551>;
        <D.19550>:
        domain->inet_family_hint = 3;
        <D.19551>:
        <D.19544>:
        {
          int ret;

          D.19535 = &domain->lock.mutex;
          ret = pthread_mutex_unlock (D.19535);
          if (ret != 0) goto <D.19552>; else goto <D.19553>;
          <D.19552>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d", ret);
          <D.19553>:
          D.19554 = ret != 0;
          D.19555 = (long int) D.19554;
          D.19556 = __builtin_expect (D.19555, 0);
          if (D.19556 != 0) goto <D.19557>; else goto <D.19558>;
          <D.19557>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 729, "ret == 0");
          <D.19558>:
        }
      }
    finally
      {
        ipv6_enabled = {CLOBBER};
        ipv4_enabled = {CLOBBER};
      }
  }
  <D.19527>:
  D.19525 = domain->inet_family_hint;
  D.19559 = (int) D.19525;
  switch (D.19559) <default: <D.18092>, case 1: <D.18089>, case 2: <D.18090>, case 3: <D.18091>>
  <D.18089>:
  D.19560 = 0;
  return D.19560;
  <D.18090>:
  D.19560 = 2;
  return D.19560;
  <D.18091>:
  D.19560 = 10;
  return D.19560;
  <D.18092>:
  D.19560 = 0;
  return D.19560;
}


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.19562;
  struct MonoArray * D.19563;
  int nlocal_in.85;
  int nlocal_in6.86;
  struct MonoClass * D.19571;
  int D.19572;
  unsigned int D.19573;
  struct MonoArray * D.19574;
  unsigned int i.87;
  unsigned int D.19578;
  struct in_addr * D.19579;
  struct MonoArray * D.19580;
  unsigned int addr_index.88;
  unsigned int i.89;
  unsigned int D.19585;
  struct in6_addr * D.19586;
  gboolean D.19591;
  int D.19592;
  struct MonoClass * D.19597;
  unsigned int count.90;
  struct MonoArray * D.19599;
  struct sockaddr * D.19606;
  struct in_addr * D.19607;
  struct in6_addr * D.19609;
  char * D.19615;
  struct MonoString * D.19618;
  struct MonoString * D.19620;
  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.19562 = mono_get_string_class ();
      D.19563 = mono_array_new (domain, D.19562, 0);
      *h_aliases = D.19563;
      if (add_local_ips != 0) goto <D.19564>; else goto <D.19565>;
      <D.19564>:
      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.19566>; else goto <D.19569>;
      <D.19569>:
      nlocal_in6.86 = nlocal_in6;
      if (nlocal_in6.86 != 0) goto <D.19566>; else goto <D.19567>;
      <D.19566>:
      D.19571 = mono_get_string_class ();
      nlocal_in.85 = nlocal_in;
      nlocal_in6.86 = nlocal_in6;
      D.19572 = nlocal_in.85 + nlocal_in6.86;
      D.19573 = (unsigned int) D.19572;
      D.19574 = mono_array_new (domain, D.19571, D.19573);
      *h_addr_list = D.19574;
      nlocal_in.85 = nlocal_in;
      if (nlocal_in.85 != 0) goto <D.19575>; else goto <D.19576>;
      <D.19575>:
      {
        struct MonoString * addr_string;
        char addr[16];
        int i;

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

              D.19580 = *h_addr_list;
              addr_index.88 = (unsigned int) addr_index;
              __p = mono_array_addr_with_size (D.19580, 4, addr_index.88);
              D.19580 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.19580, __p, addr_string);
            }
            addr_index = addr_index + 1;
            i = i + 1;
            <D.18585>:
            nlocal_in.85 = nlocal_in;
            if (i < nlocal_in.85) goto <D.18584>; else goto <D.18586>;
            <D.18586>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.19576>:
      nlocal_in6.86 = nlocal_in6;
      if (nlocal_in6.86 != 0) goto <D.19582>; else goto <D.19583>;
      <D.19582>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char addr[48];
        int i;

        try
          {
            i = 0;
            goto <D.18593>;
            <D.18592>:
            i.89 = (unsigned int) i;
            D.19585 = i.89 * 16;
            D.19586 = local_in6 + D.19585;
            ret = inet_ntop (10, D.19586, &addr, 48);
            if (ret != 0B) goto <D.19587>; else goto <D.19588>;
            <D.19587>:
            addr_string = mono_string_new (domain, &addr);
            {
              void * * __p;

              D.19580 = *h_addr_list;
              addr_index.88 = (unsigned int) addr_index;
              __p = mono_array_addr_with_size (D.19580, 4, addr_index.88);
              D.19580 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.19580, __p, addr_string);
            }
            addr_index = addr_index + 1;
            <D.19588>:
            i = i + 1;
            <D.18593>:
            nlocal_in6.86 = nlocal_in6;
            if (i < nlocal_in6.86) goto <D.18592>; else goto <D.18594>;
            <D.18594>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.19583>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      if (info != 0B) goto <D.19589>; else goto <D.19590>;
      <D.19589>:
      freeaddrinfo (info);
      <D.19590>:
      D.19591 = 1;
      return D.19591;
      <D.19567>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      <D.19565>:
      count = 0;
      ai = info;
      goto <D.18597>;
      <D.18596>:
      D.19592 = ai->ai_family;
      if (D.19592 != 2) goto <D.19593>; else goto <D.19594>;
      <D.19593>:
      D.19592 = ai->ai_family;
      if (D.19592 != 10) goto <D.19595>; else goto <D.19596>;
      <D.19595>:
      // predicted unlikely by continue predictor.
      goto <D.18595>;
      <D.19596>:
      <D.19594>:
      count = count + 1;
      <D.18595>:
      ai = ai->ai_next;
      <D.18597>:
      if (ai != 0B) goto <D.18596>; else goto <D.18598>;
      <D.18598>:
      D.19597 = mono_get_string_class ();
      count.90 = (unsigned int) count;
      D.19599 = mono_array_new (domain, D.19597, count.90);
      *h_addr_list = D.19599;
      ai = info;
      i = 0;
      goto <D.18605>;
      <D.18604>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char buffer[48];

        try
          {
            D.19592 = ai->ai_family;
            if (D.19592 != 2) goto <D.19600>; else goto <D.19601>;
            <D.19600>:
            D.19592 = ai->ai_family;
            if (D.19592 != 10) goto <D.19602>; else goto <D.19603>;
            <D.19602>:
            // predicted unlikely by continue predictor.
            goto <D.18602>;
            <D.19603>:
            <D.19601>:
            D.19592 = ai->ai_family;
            if (D.19592 == 2) goto <D.19604>; else goto <D.19605>;
            <D.19604>:
            D.19592 = ai->ai_family;
            D.19606 = ai->ai_addr;
            D.19607 = &MEM[(struct sockaddr_in *)D.19606].sin_addr;
            ret = inet_ntop (D.19592, D.19607, &buffer, 16);
            goto <D.19608>;
            <D.19605>:
            D.19592 = ai->ai_family;
            D.19606 = ai->ai_addr;
            D.19609 = &MEM[(struct sockaddr_in6 *)D.19606].sin6_addr;
            ret = inet_ntop (D.19592, D.19609, &buffer, 48);
            <D.19608>:
            if (ret != 0B) goto <D.19610>; else goto <D.19611>;
            <D.19610>:
            addr_string = mono_string_new (domain, &buffer);
            goto <D.19612>;
            <D.19611>:
            addr_string = mono_string_new (domain, "");
            <D.19612>:
            {
              void * * __p;

              D.19580 = *h_addr_list;
              addr_index.88 = (unsigned int) addr_index;
              __p = mono_array_addr_with_size (D.19580, 4, addr_index.88);
              D.19580 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.19580, __p, addr_string);
            }
            if (i == 0) goto <D.19613>; else goto <D.19614>;
            <D.19613>:
            i = i + 1;
            D.19615 = ai->ai_canonname;
            if (D.19615 != 0B) goto <D.19616>; else goto <D.19617>;
            <D.19616>:
            D.19615 = ai->ai_canonname;
            D.19618 = mono_string_new (domain, D.19615);
            *h_name = D.19618;
            goto <D.19619>;
            <D.19617>:
            D.19620 = mono_string_new (domain, &buffer);
            *h_name = D.19620;
            <D.19619>:
            <D.19614>:
            addr_index = addr_index + 1;
          }
        finally
          {
            buffer = {CLOBBER};
          }
      }
      <D.18602>:
      ai = ai->ai_next;
      <D.18605>:
      if (ai != 0B) goto <D.18604>; else goto <D.18606>;
      <D.18606>:
      if (info != 0B) goto <D.19621>; else goto <D.19622>;
      <D.19621>:
      freeaddrinfo (info);
      <D.19622>:
      D.19591 = 1;
      return D.19591;
    }
  finally
    {
      nlocal_in = {CLOBBER};
      nlocal_in6 = {CLOBBER};
    }
}


get_local_ips (int family, int * nips)
{
  void * D.19633;
  unsigned int max_ifaces.91;
  unsigned int D.19635;
  int D.19636;
  int D.19637;
  unsigned int D.19638;
  void * D.19639;
  int D.19640;
  char * D.19643;
  unsigned int D.19644;
  unsigned int D.19645;
  char[16] * D.19648;
  int D.19649;
  short int D.19652;
  unsigned short D.19653;
  int D.19654;
  int D.19655;
  int D.19658;
  int D.19661;
  int D.19662;
  unsigned int D.19663;
  char D.19664;
  int D.19667;
  struct sockaddr * D.19670;
  sizetype offset.92;
  void * D.19672;
  int D.19673;
  char * D.19676;
  unsigned int addr_size.93;
  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.19627>; else goto <D.19628>;
      <D.19627>:
      addr_size = 4;
      offset = 4;
      goto <D.19629>;
      <D.19628>:
      if (family == 10) goto <D.19630>; else goto <D.19631>;
      <D.19630>:
      addr_size = 16;
      offset = 8;
      goto <D.19632>;
      <D.19631>:
      D.19633 = 0B;
      return D.19633;
      <D.19632>:
      <D.19629>:
      fd = socket (family, 2, 0);
      max_ifaces.91 = (unsigned int) max_ifaces;
      D.19635 = max_ifaces.91 * 32;
      D.19636 = (int) D.19635;
      ifc.ifc_len = D.19636;
      D.19637 = ifc.ifc_len;
      D.19638 = (unsigned int) D.19637;
      D.19639 = monoeg_malloc (D.19638);
      ifc.ifc_ifcu.ifcu_buf = D.19639;
      D.19640 = ioctl (fd, 35090, &ifc);
      if (D.19640 < 0) goto <D.19641>; else goto <D.19642>;
      <D.19641>:
      close (fd);
      D.19643 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.19643);
      D.19633 = 0B;
      return D.19633;
      <D.19642>:
      D.19637 = ifc.ifc_len;
      D.19644 = (unsigned int) D.19637;
      D.19645 = D.19644 / 32;
      count = (int) D.19645;
      *nips = count;
      if (count == 0) goto <D.19646>; else goto <D.19647>;
      <D.19646>:
      D.19643 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.19643);
      close (fd);
      D.19633 = 0B;
      return D.19633;
      <D.19647>:
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.18558>;
      <D.18557>:
      D.19648 = &ifr->ifr_ifrn.ifrn_name;
      strcpy (&iflags.ifr_ifrn.ifrn_name, D.19648);
      D.19649 = ioctl (fd, 35091, &iflags);
      if (D.19649 < 0) goto <D.19650>; else goto <D.19651>;
      <D.19650>:
      // predicted unlikely by continue predictor.
      goto <D.18556>;
      <D.19651>:
      D.19652 = iflags.ifr_ifru.ifru_flags;
      D.19653 = (unsigned short) D.19652;
      D.19654 = (int) D.19653;
      D.19655 = D.19654 & 1;
      if (D.19655 == 0) goto <D.19656>; else goto <D.19657>;
      <D.19656>:
      ifr->ifr_ifrn.ifrn_name[0] = 0;
      // predicted unlikely by continue predictor.
      goto <D.18556>;
      <D.19657>:
      D.19652 = iflags.ifr_ifru.ifru_flags;
      D.19653 = (unsigned short) D.19652;
      D.19654 = (int) D.19653;
      D.19658 = D.19654 & 8;
      if (D.19658 == 0) goto <D.19659>; else goto <D.19660>;
      <D.19659>:
      ignore_loopback = 1;
      <D.19660>:
      <D.18556>:
      i = i + 1;
      ifr = ifr + 32;
      <D.18558>:
      D.19661 = *nips;
      if (D.19661 > i) goto <D.18557>; else goto <D.18559>;
      <D.18559>:
      close (fd);
      D.19662 = addr_size * count;
      D.19663 = (unsigned int) D.19662;
      result = monoeg_malloc (D.19663);
      tmp_ptr = result;
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.18562>;
      <D.18561>:
      D.19664 = ifr->ifr_ifrn.ifrn_name[0];
      if (D.19664 == 0) goto <D.19665>; else goto <D.19666>;
      <D.19665>:
      D.19661 = *nips;
      D.19667 = D.19661 + -1;
      *nips = D.19667;
      // predicted unlikely by continue predictor.
      goto <D.18560>;
      <D.19666>:
      if (ignore_loopback != 0) goto <D.19668>; else goto <D.19669>;
      <D.19668>:
      D.19670 = &ifr->ifr_ifru.ifru_addr;
      offset.92 = (sizetype) offset;
      D.19672 = D.19670 + offset.92;
      D.19673 = is_loopback (family, D.19672);
      if (D.19673 != 0) goto <D.19674>; else goto <D.19675>;
      <D.19674>:
      D.19661 = *nips;
      D.19667 = D.19661 + -1;
      *nips = D.19667;
      // predicted unlikely by continue predictor.
      goto <D.18560>;
      <D.19675>:
      <D.19669>:
      D.19670 = &ifr->ifr_ifru.ifru_addr;
      offset.92 = (sizetype) offset;
      D.19676 = D.19670 + offset.92;
      addr_size.93 = (unsigned int) addr_size;
      memcpy (tmp_ptr, D.19676, addr_size.93);
      addr_size.94 = (sizetype) addr_size;
      tmp_ptr = tmp_ptr + addr_size.94;
      <D.18560>:
      i = i + 1;
      ifr = ifr + 32;
      <D.18562>:
      if (i < count) goto <D.18561>; else goto <D.18563>;
      <D.18563>:
      D.19643 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.19643);
      D.19633 = result;
      return D.19633;
    }
  finally
    {
      ifc = {CLOBBER};
      iflags = {CLOBBER};
    }
}


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

  D.19682 = __builtin_object_size (__dest, 1);
  D.19681 = __builtin___strcpy_chk (__dest, __src, D.19682);
  return D.19681;
}


is_loopback (int family, void * ad)
{
  gboolean D.19686;
  char D.19687;
  _Bool D.19688;
  int D.18539;
  int iftmp.95;
  unsigned int D.19692;
  unsigned int D.19694;
  unsigned int D.19696;
  unsigned int D.19698;
  unsigned int D.19699;
  char * ptr;

  ptr = ad;
  if (family == 2) goto <D.19684>; else goto <D.19685>;
  <D.19684>:
  D.19687 = *ptr;
  D.19688 = D.19687 == 127;
  D.19686 = (gboolean) D.19688;
  return D.19686;
  <D.19685>:
  {
    const struct in6_addr * __a;

    __a = ptr;
    D.19692 = __a->__in6_u.__u6_addr32[0];
    if (D.19692 == 0) goto <D.19693>; else goto <D.19690>;
    <D.19693>:
    D.19694 = __a->__in6_u.__u6_addr32[1];
    if (D.19694 == 0) goto <D.19695>; else goto <D.19690>;
    <D.19695>:
    D.19696 = __a->__in6_u.__u6_addr32[2];
    if (D.19696 == 0) goto <D.19697>; else goto <D.19690>;
    <D.19697>:
    D.19698 = __a->__in6_u.__u6_addr32[3];
    D.19699 = __bswap_32 (1);
    if (D.19698 == D.19699) goto <D.19700>; else goto <D.19690>;
    <D.19700>:
    iftmp.95 = 1;
    goto <D.19691>;
    <D.19690>:
    iftmp.95 = 0;
    <D.19691>:
    D.18539 = iftmp.95;
  }
  D.19686 = D.18539;
  return D.19686;
  D.19686 = 0;
  return D.19686;
}


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

  D.19703 = __builtin_object_size (__dest, 0);
  D.19702 = __builtin___memcpy_chk (__dest, __src, __len, D.19703);
  return D.19702;
}


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.19705;
  int D.19708;
  MonoBoolean D.19711;
  int D.19715;
  int D.19721;
  int D.19724;
  int D.19725;
  struct addrinfo * info.96;
  int D.19729;
  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.19705 = inet_pton (2, address, &saddr.sin_addr);
      if (D.19705 <= 0) goto <D.19706>; else goto <D.19707>;
      <D.19706>:
      D.19708 = inet_pton (10, address, &saddr6.sin6_addr);
      if (D.19708 <= 0) goto <D.19709>; else goto <D.19710>;
      <D.19709>:
      monoeg_g_free (address);
      D.19711 = 0;
      return D.19711;
      <D.19710>:
      family = 10;
      saddr6.sin6_family = 10;
      goto <D.19712>;
      <D.19707>:
      family = 2;
      saddr.sin_family = 2;
      <D.19712>:
      monoeg_g_free (address);
      if (family == 2) goto <D.19713>; else goto <D.19714>;
      <D.19713>:
      D.19715 = getnameinfo (&saddr, 16, &hostname, 1025, 0B, 0, flags);
      if (D.19715 != 0) goto <D.19716>; else goto <D.19717>;
      <D.19716>:
      D.19711 = 0;
      return D.19711;
      <D.19717>:
      goto <D.19718>;
      <D.19714>:
      if (family == 10) goto <D.19719>; else goto <D.19720>;
      <D.19719>:
      D.19721 = getnameinfo (&saddr6, 28, &hostname, 1025, 0B, 0, flags);
      if (D.19721 != 0) goto <D.19722>; else goto <D.19723>;
      <D.19722>:
      D.19711 = 0;
      return D.19711;
      <D.19723>:
      <D.19720>:
      <D.19718>:
      memset (&hints, 0, 32);
      D.19724 = get_family_hint ();
      hints.ai_family = D.19724;
      hints.ai_socktype = 2;
      hints.ai_flags = 34;
      D.19725 = getaddrinfo (&hostname, 0B, &hints, &info);
      if (D.19725 == -1) goto <D.19726>; else goto <D.19727>;
      <D.19726>:
      D.19711 = 0;
      return D.19711;
      <D.19727>:
      info.96 = info;
      D.19729 = addrinfo_to_IPHostEntry (info.96, h_name, h_aliases, h_addr_list, 0);
      D.19711 = (MonoBoolean) D.19729;
      return D.19711;
    }
  finally
    {
      saddr = {CLOBBER};
      saddr6 = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
      hostname = {CLOBBER};
    }
}


ves_icall_System_Net_Dns_GetHostName_internal (struct MonoString * * h_name)
{
  MonoBoolean D.19734;
  struct MonoDomain * D.19735;
  struct MonoString * D.19736;
  gchar hostname[256];
  int ret;

  try
    {
      ret = gethostname (&hostname, 256);
      if (ret == -1) goto <D.19732>; else goto <D.19733>;
      <D.19732>:
      D.19734 = 0;
      return D.19734;
      <D.19733>:
      D.19735 = mono_domain_get ();
      D.19736 = mono_string_new (D.19735, &hostname);
      *h_name = D.19736;
      D.19734 = 1;
      return D.19734;
    }
  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.19741;
  int error.97;
  unsigned int error.98;
  char * D.19748;
  unsigned int D.19749;
  char * D.19752;
  unsigned int D.19753;
  unsigned int flags.99;
  int D.19755;
  void * file;
  gint32 error;
  struct TRANSMIT_FILE_BUFFERS buffers;

  try
    {
      if (filename == 0B) goto <D.19739>; else goto <D.19740>;
      <D.19739>:
      D.19741 = 0;
      return D.19741;
      <D.19740>:
      file = ves_icall_System_IO_MonoIO_Open (filename, 3, 1, 1, 0, &error);
      if (file == 4294967295B) goto <D.19742>; else goto <D.19743>;
      <D.19742>:
      error.97 = error;
      error.98 = (unsigned int) error.97;
      SetLastError (error.98);
      D.19741 = 0;
      return D.19741;
      <D.19743>:
      memset (&buffers, 0, 16);
      if (pre_buffer != 0B) goto <D.19746>; else goto <D.19747>;
      <D.19746>:
      D.19748 = mono_array_addr_with_size (pre_buffer, 1, 0);
      buffers.Head = D.19748;
      D.19749 = mono_array_length (pre_buffer);
      buffers.HeadLength = D.19749;
      <D.19747>:
      if (post_buffer != 0B) goto <D.19750>; else goto <D.19751>;
      <D.19750>:
      D.19752 = mono_array_addr_with_size (post_buffer, 1, 0);
      buffers.Tail = D.19752;
      D.19753 = mono_array_length (post_buffer);
      buffers.TailLength = D.19753;
      <D.19751>:
      flags.99 = (unsigned int) flags;
      D.19755 = TransmitFile (sock, file, 0, 0, 0B, &buffers, flags.99);
      if (D.19755 == 0) goto <D.19756>; else goto <D.19757>;
      <D.19756>:
      CloseHandle (file);
      D.19741 = 0;
      return D.19741;
      <D.19757>:
      CloseHandle (file);
      D.19741 = 1;
      return D.19741;
    }
  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.19760>; else goto <D.19761>;
      <D.19760>:
      monoeg_g_log (0B, 4, "%s: Couldn\'t initialise networking", &__func__);
      <D.18662>:
      goto <D.18662>;
      exit (-1);
      <D.19761>:
    }
  finally
    {
      wsadata = {CLOBBER};
    }
}


mono_network_cleanup ()
{
  WSACleanup ();
}


icall_cancel_blocking_socket_operation (struct MonoThread * thread)
{
  int D.19762;
  long long unsigned int D.19765;
  long unsigned int D.19766;
  int D.19768;
  struct MonoInternalThread * internal;

  internal = thread->internal_thread;
  D.19762 = mono_thread_info_new_interrupt_enabled ();
  if (D.19762 != 0) goto <D.19763>; else goto <D.19764>;
  <D.19763>:
  D.19765 = internal->tid;
  D.19766 = (long unsigned int) D.19765;
  mono_thread_info_abort_socket_syscall_for_close (D.19766);
  goto <D.19767>;
  <D.19764>:
  internal->ignore_next_signal = 1;
  D.19768 = mono_thread_get_abort_signal ();
  mono_thread_kill (internal, D.19768);
  <D.19767>:
}


