ves_icall_System_Net_Sockets_Socket_Socket_internal (struct MonoObject * this, gint32 family, gint32 type, gint32 proto, gint32 * error)
{
  void * D.21266;
  int D.21273;
  _Bool D.21274;
  _Bool D.21275;
  _Bool D.21276;
  _Bool D.21279;
  _Bool D.21280;
  SOCKET sock;
  gint32 sock_family;
  gint32 sock_proto;
  gint32 sock_type;

  *error = 0;
  sock_family = convert_family (family);
  if (sock_family == -1) goto <D.21264>; else goto <D.21265>;
  <D.21264>:
  *error = 10047;
  D.21266 = 0B;
  return D.21266;
  <D.21265>:
  sock_proto = convert_proto (proto);
  if (sock_proto == -1) goto <D.21267>; else goto <D.21268>;
  <D.21267>:
  *error = 10043;
  D.21266 = 0B;
  return D.21266;
  <D.21268>:
  sock_type = convert_type (type);
  if (sock_type == -1) goto <D.21269>; else goto <D.21270>;
  <D.21269>:
  *error = 10044;
  D.21266 = 0B;
  return D.21266;
  <D.21270>:
  sock = _wapi_socket (sock_family, sock_type, sock_proto, 0B, 0, 1);
  if (sock == 4294967295) goto <D.21271>; else goto <D.21272>;
  <D.21271>:
  D.21273 = WSAGetLastError ();
  *error = D.21273;
  D.21266 = 0B;
  return D.21266;
  <D.21272>:
  D.21274 = sock_family == 2;
  D.21275 = sock_type == 2;
  D.21276 = D.21274 & D.21275;
  if (D.21276 != 0) goto <D.21277>; else goto <D.21278>;
  <D.21277>:
  D.21266 = (void *) sock;
  return D.21266;
  <D.21278>:
  D.21279 = sock_family == 10;
  D.21275 = sock_type == 2;
  D.21280 = D.21279 & D.21275;
  if (D.21280 != 0) goto <D.21281>; else goto <D.21282>;
  <D.21281>:
  D.21266 = (void *) sock;
  return D.21266;
  <D.21282>:
  D.21266 = (void *) sock;
  return D.21266;
}


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

  family = -1;
  switch (mono_family) <default: <D.20529>, case -1: <D.20500>, case 0: <D.20520>, case 1: <D.20521>, case 2: <D.20522>, case 3: <D.20501>, case 4: <D.20502>, case 5: <D.20503>, case 6: <D.20523>, case 7: <D.20504>, case 8: <D.20505>, case 9: <D.20506>, case 10: <D.20507>, case 11: <D.20524>, case 12: <D.20525>, case 13: <D.20508>, case 14: <D.20509>, case 15: <D.20510>, case 16: <D.20526>, case 17: <D.20511>, case 18: <D.20512>, case 19: <D.20513>, case 21: <D.20514>, case 22: <D.20515>, case 23: <D.20527>, case 24: <D.20516>, case 25: <D.20517>, case 26: <D.20528>, case 28: <D.20518>>
  <D.20500>:
  <D.20501>:
  <D.20502>:
  <D.20503>:
  <D.20504>:
  <D.20505>:
  <D.20506>:
  <D.20507>:
  <D.20508>:
  <D.20509>:
  <D.20510>:
  <D.20511>:
  <D.20512>:
  <D.20513>:
  <D.20514>:
  <D.20515>:
  <D.20516>:
  <D.20517>:
  <D.20518>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unsupported value 0x%x", mono_family);
  goto <D.20519>;
  <D.20520>:
  family = 0;
  goto <D.20519>;
  <D.20521>:
  family = 1;
  goto <D.20519>;
  <D.20522>:
  family = 2;
  goto <D.20519>;
  <D.20523>:
  family = 4;
  goto <D.20519>;
  <D.20524>:
  family = 22;
  goto <D.20519>;
  <D.20525>:
  family = 12;
  goto <D.20519>;
  <D.20526>:
  family = 5;
  goto <D.20519>;
  <D.20527>:
  family = 10;
  goto <D.20519>;
  <D.20528>:
  family = 23;
  goto <D.20519>;
  <D.20529>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.AddressFamily has unknown value 0x%x", mono_family);
  <D.20519>:
  D.21284 = family;
  return D.21284;
}


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

  proto = -1;
  switch (mono_proto) <default: <D.20577>, case -1: <D.20576>, case 0: <D.20561>, case 1: <D.20563>, case 2: <D.20564>, case 3: <D.20565>, case 6: <D.20566>, case 12: <D.20567>, case 17: <D.20568>, case 22: <D.20569>, case 41: <D.20562>, case 77: <D.20571>, case 255: <D.20572>, case 1000: <D.20573>, case 1256: <D.20574>, case 1257: <D.20575>>
  <D.20561>:
  <D.20562>:
  <D.20563>:
  <D.20564>:
  <D.20565>:
  <D.20566>:
  <D.20567>:
  <D.20568>:
  <D.20569>:
  proto = mono_proto;
  goto <D.20570>;
  <D.20571>:
  <D.20572>:
  <D.20573>:
  <D.20574>:
  <D.20575>:
  <D.20576>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.ProtocolType has unsupported value 0x%x", mono_proto);
  goto <D.20570>;
  <D.20577>:
  goto <D.20570>;
  <D.20570>:
  D.21286 = proto;
  return D.21286;
}


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

  type = -1;
  switch (mono_type) <default: <D.20556>, case -1: <D.20555>, case 1: <D.20549>, case 2: <D.20551>, case 3: <D.20552>, case 4: <D.20553>, case 5: <D.20554>>
  <D.20549>:
  type = 1;
  goto <D.20550>;
  <D.20551>:
  type = 2;
  goto <D.20550>;
  <D.20552>:
  type = 3;
  goto <D.20550>;
  <D.20553>:
  type = 4;
  goto <D.20550>;
  <D.20554>:
  type = 5;
  goto <D.20550>;
  <D.20555>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unsupported value 0x%x", mono_type);
  goto <D.20550>;
  <D.20556>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketType has unknown value 0x%x", mono_type);
  <D.20550>:
  D.21289 = type;
  return D.21289;
}


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

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


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

  try
    {
      *error = 0;
      ret = ioctlsocket (sock, 21531, &amount);
      if (ret == -1) goto <D.21294>; else goto <D.21295>;
      <D.21294>:
      D.21296 = WSAGetLastError ();
      *error = D.21296;
      D.21297 = 0;
      return D.21297;
      <D.21295>:
      D.21297 = amount;
      return D.21297;
    }
  finally
    {
      amount = {CLOBBER};
    }
}


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

  *error = 0;
  block.1 = block;
  D.21301 = block.1 == 0;
  block.2 = (int) D.21301;
  block = block.2;
  ret = ioctlsocket (sock, 21537, &block);
  if (ret == -1) goto <D.21303>; else goto <D.21304>;
  <D.21303>:
  D.21305 = WSAGetLastError ();
  *error = D.21305;
  <D.21304>:
}


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

  *error = 0;
  newsock = _wapi_accept (sock, 0B, 0B);
  if (newsock == 4294967295) goto <D.21306>; else goto <D.21307>;
  <D.21306>:
  D.21308 = WSAGetLastError ();
  *error = D.21308;
  D.21309 = 0B;
  return D.21309;
  <D.21307>:
  D.21309 = (void *) newsock;
  return D.21309;
}


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

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


ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.21315;
  int D.21316;
  unsigned int salen.4;
  unsigned int salen.5;
  struct MonoObject * D.21321;
  gchar * iftmp.6;
  int D.21328;
  int salen.7;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.21315 = convert_family (af);
      D.21316 = get_sockaddr_size (D.21315);
      salen.4 = (unsigned int) D.21316;
      salen = salen.4;
      salen.5 = salen;
      if (salen.5 == 0) goto <D.21319>; else goto <D.21320>;
      <D.21319>:
      *error = 10047;
      D.21321 = 0B;
      return D.21321;
      <D.21320>:
      salen.5 = salen;
      if (salen.5 <= 128) goto <D.21323>; else goto <D.21324>;
      <D.21323>:
      salen.5 = salen;
      iftmp.6 = __builtin_alloca (salen.5);
      goto <D.21325>;
      <D.21324>:
      salen.5 = salen;
      iftmp.6 = monoeg_malloc0 (salen.5);
      <D.21325>:
      sa = iftmp.6;
      ret = _wapi_getsockname (sock, sa, &salen);
      if (ret == -1) goto <D.21326>; else goto <D.21327>;
      <D.21326>:
      D.21328 = WSAGetLastError ();
      *error = D.21328;
      salen.5 = salen;
      if (salen.5 > 128) goto <D.21329>; else goto <D.21330>;
      <D.21329>:
      monoeg_g_free (sa);
      <D.21330>:
      D.21321 = 0B;
      return D.21321;
      <D.21327>:
      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.21332>; else goto <D.21333>;
      <D.21332>:
      monoeg_g_free (sa);
      <D.21333>:
      D.21321 = result;
      return D.21321;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


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

  size = 0;
  if (family == 2) goto <D.21336>; else goto <D.21337>;
  <D.21336>:
  size = 16;
  goto <D.21338>;
  <D.21337>:
  if (family == 10) goto <D.21339>; else goto <D.21340>;
  <D.21339>:
  size = 28;
  goto <D.21341>;
  <D.21340>:
  if (family == 1) goto <D.21342>; else goto <D.21343>;
  <D.21342>:
  size = 110;
  <D.21343>:
  <D.21341>:
  <D.21338>:
  D.21344 = size;
  return D.21344;
}


create_object_from_sockaddr (struct sockaddr * saddr, int sa_size, gint32 * error)
{
  struct MonoClass * D.21346;
  struct MonoImage * D.21349;
  struct MonoClass * D.21350;
  _Bool D.21351;
  long int D.21352;
  long int D.21353;
  struct MonoClassField * D.21356;
  struct MonoClassField * D.21359;
  _Bool D.21360;
  long int D.21361;
  long int D.21362;
  struct MonoClass * D.20746;
  struct MonoClass * tmp_klass.8;
  struct MonoClass * D.21368;
  struct MonoClass * tmp_klass.9;
  _Bool D.21370;
  long int D.21371;
  long int D.21372;
  struct MonoVTable * D.21375;
  int D.21376;
  unsigned int D.21377;
  short unsigned int D.21378;
  struct MonoObject * D.21381;
  unsigned char D.21382;
  int D.21383;
  unsigned char D.21384;
  short unsigned int port.10;
  unsigned int D.21387;
  struct MonoImage * D.21390;
  struct MonoException * D.21391;
  short unsigned int D.21392;
  unsigned char D.21393;
  unsigned char D.21394;
  unsigned int D.21395;
  unsigned char D.21396;
  unsigned int D.21397;
  unsigned char D.21398;
  unsigned int D.21399;
  unsigned char D.21400;
  unsigned char D.21401;
  short unsigned int port.11;
  struct MonoImage * D.21406;
  struct MonoException * D.21407;
  short unsigned int D.21408;
  unsigned char D.21409;
  unsigned char D.21410;
  struct in6_addr * D.21411;
  int D.21412;
  int D.21415;
  unsigned int D.21416;
  unsigned char D.21418;
  unsigned int D.21419;
  unsigned char D.21420;
  unsigned int D.21421;
  unsigned char D.21422;
  unsigned int D.21423;
  unsigned char D.21424;
  unsigned int D.21425;
  unsigned char D.21426;
  int D.21429;
  unsigned int D.21430;
  char D.21431;
  struct MonoDomain * domain;
  struct MonoObject * sockaddr_obj;
  struct MonoArray * data;
  MonoAddressFamily family;

  domain = mono_domain_get ();
  D.21346 = domain->sockaddr_class;
  if (D.21346 == 0B) goto <D.21347>; else goto <D.21348>;
  <D.21347>:
  D.21349 = get_socket_assembly ();
  D.21350 = mono_class_from_name (D.21349, "System.Net", "SocketAddress");
  domain->sockaddr_class = D.21350;
  D.21346 = domain->sockaddr_class;
  D.21351 = D.21346 == 0B;
  D.21352 = (long int) D.21351;
  D.21353 = __builtin_expect (D.21352, 0);
  if (D.21353 != 0) goto <D.21354>; else goto <D.21355>;
  <D.21354>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 935, "domain->sockaddr_class");
  <D.21355>:
  <D.21348>:
  D.21346 = domain->sockaddr_class;
  sockaddr_obj = mono_object_new (domain, D.21346);
  D.21356 = domain->sockaddr_data_field;
  if (D.21356 == 0B) goto <D.21357>; else goto <D.21358>;
  <D.21357>:
  D.21346 = domain->sockaddr_class;
  D.21359 = mono_class_get_field_from_name (D.21346, "data");
  domain->sockaddr_data_field = D.21359;
  D.21356 = domain->sockaddr_data_field;
  D.21360 = D.21356 == 0B;
  D.21361 = (long int) D.21360;
  D.21362 = __builtin_expect (D.21361, 0);
  if (D.21362 != 0) goto <D.21363>; else goto <D.21364>;
  <D.21363>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 942, "domain->sockaddr_data_field");
  <D.21364>:
  <D.21358>:
  {
    static struct MonoClass * tmp_klass;

    {
      tmp_klass.8 = tmp_klass;
      if (tmp_klass.8 == 0B) goto <D.21366>; else goto <D.21367>;
      <D.21366>:
      D.21368 = mono_get_byte_class ();
      tmp_klass.9 = mono_array_class_get (D.21368, 1);
      tmp_klass = tmp_klass.9;
      tmp_klass.8 = tmp_klass;
      D.21370 = tmp_klass.8 == 0B;
      D.21371 = (long int) D.21370;
      D.21372 = __builtin_expect (D.21371, 0);
      if (D.21372 != 0) goto <D.21373>; else goto <D.21374>;
      <D.21373>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 949, "tmp_klass");
      <D.21374>:
      <D.21367>:
    }
    D.20746 = tmp_klass;
  }
  D.21375 = mono_class_vtable (domain, D.20746);
  D.21376 = sa_size + 2;
  D.21377 = (unsigned int) D.21376;
  data = mono_array_new_specific (D.21375, D.21377);
  D.21378 = saddr->sa_family;
  family = convert_to_mono_family (D.21378);
  if (family == -1) goto <D.21379>; else goto <D.21380>;
  <D.21379>:
  *error = 10047;
  D.21381 = 0B;
  return D.21381;
  <D.21380>:
  {
    guint8 * __p;

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

    __p = mono_array_addr_with_size (data, 1, 1);
    D.21383 = family >> 8;
    D.21384 = (unsigned char) D.21383;
    *__p = D.21384;
  }
  D.21378 = saddr->sa_family;
  if (D.21378 == 2) goto <D.21385>; else goto <D.21386>;
  <D.21385>:
  {
    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.21387 = sa_in->sin_addr.s_addr;
    address = __bswap_32 (D.21387);
    if (sa_size <= 7) goto <D.21388>; else goto <D.21389>;
    <D.21388>:
    D.21390 = mono_get_corlib ();
    D.21391 = mono_exception_from_name (D.21390, "System", "SystemException");
    mono_raise_exception (D.21391);
    <D.21389>:
    {
      guint8 * __p;

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

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

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

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

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

      __p = mono_array_addr_with_size (data, 1, 7);
      D.21401 = (unsigned char) address;
      *__p = D.21401;
    }
    D.21356 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.21356, data);
    D.21381 = sockaddr_obj;
    return D.21381;
  }
  <D.21386>:
  D.21378 = saddr->sa_family;
  if (D.21378 == 10) goto <D.21402>; else goto <D.21403>;
  <D.21402>:
  {
    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.21404>; else goto <D.21405>;
    <D.21404>:
    D.21406 = mono_get_corlib ();
    D.21407 = mono_exception_from_name (D.21406, "System", "SystemException");
    mono_raise_exception (D.21407);
    <D.21405>:
    {
      guint8 * __p;

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

      __p = mono_array_addr_with_size (data, 1, 3);
      D.21410 = (unsigned char) port;
      *__p = D.21410;
    }
    D.21411 = &sa_in->sin6_addr;
    D.21412 = is_ipv4_mapped_any (D.21411);
    if (D.21412 != 0) goto <D.21413>; else goto <D.21414>;
    <D.21413>:
    i = 0;
    goto <D.20769>;
    <D.20768>:
    {
      guint8 * __p;

      D.21415 = i + 8;
      D.21416 = (unsigned int) D.21415;
      __p = mono_array_addr_with_size (data, 1, D.21416);
      *__p = 0;
    }
    i = i + 1;
    <D.20769>:
    if (i <= 15) goto <D.20768>; else goto <D.20770>;
    <D.20770>:
    goto <D.21417>;
    <D.21414>:
    i = 0;
    goto <D.20773>;
    <D.20772>:
    {
      guint8 * __p;

      D.21415 = i + 8;
      D.21416 = (unsigned int) D.21415;
      __p = mono_array_addr_with_size (data, 1, D.21416);
      D.21418 = sa_in->sin6_addr.__in6_u.__u6_addr8[i];
      *__p = D.21418;
    }
    i = i + 1;
    <D.20773>:
    if (i <= 15) goto <D.20772>; else goto <D.20774>;
    <D.20774>:
    <D.21417>:
    {
      guint8 * __p;

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

      __p = mono_array_addr_with_size (data, 1, 25);
      D.21419 = sa_in->sin6_scope_id;
      D.21421 = D.21419 >> 8;
      D.21422 = (unsigned char) D.21421;
      *__p = D.21422;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 26);
      D.21419 = sa_in->sin6_scope_id;
      D.21423 = D.21419 >> 16;
      D.21424 = (unsigned char) D.21423;
      *__p = D.21424;
    }
    {
      guint8 * __p;

      __p = mono_array_addr_with_size (data, 1, 27);
      D.21419 = sa_in->sin6_scope_id;
      D.21425 = D.21419 >> 24;
      D.21426 = (unsigned char) D.21425;
      *__p = D.21426;
    }
    D.21356 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.21356, data);
    D.21381 = sockaddr_obj;
    return D.21381;
  }
  <D.21403>:
  D.21378 = saddr->sa_family;
  if (D.21378 == 1) goto <D.21427>; else goto <D.21428>;
  <D.21427>:
  {
    int i;

    i = 0;
    goto <D.20782>;
    <D.20781>:
    {
      guint8 * __p;

      D.21429 = i + 2;
      D.21430 = (unsigned int) D.21429;
      __p = mono_array_addr_with_size (data, 1, D.21430);
      D.21431 = saddr->sa_data[i];
      *__p = D.21431;
    }
    i = i + 1;
    <D.20782>:
    if (i < sa_size) goto <D.20781>; else goto <D.20783>;
    <D.20783>:
    D.21356 = domain->sockaddr_data_field;
    mono_field_set_value (sockaddr_obj, D.21356, data);
    D.21381 = sockaddr_obj;
    return D.21381;
  }
  <D.21428>:
  *error = 10047;
  D.21381 = 0B;
  return D.21381;
}


get_socket_assembly ()
{
  struct MonoImage * D.21433;
  struct MonoImage * D.21440;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.21433 = domain->socket_assembly;
  if (D.21433 == 0B) goto <D.21434>; else goto <D.21435>;
  <D.21434>:
  {
    struct MonoImage * socket_assembly;

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

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


mono_memory_barrier ()
{
  __sync_synchronize ();
}


convert_to_mono_family (guint16 af_family)
{
  int D.21442;
  MonoAddressFamily D.21443;
  MonoAddressFamily family;

  family = -1;
  D.21442 = (int) af_family;
  switch (D.21442) <default: <D.20544>, case 0: <D.20534>, case 1: <D.20536>, case 2: <D.20537>, case 4: <D.20538>, case 5: <D.20541>, case 10: <D.20542>, case 12: <D.20540>, case 22: <D.20539>, case 23: <D.20543>>
  <D.20534>:
  family = 0;
  goto <D.20535>;
  <D.20536>:
  family = 1;
  goto <D.20535>;
  <D.20537>:
  family = 2;
  goto <D.20535>;
  <D.20538>:
  family = 6;
  goto <D.20535>;
  <D.20539>:
  family = 11;
  goto <D.20535>;
  <D.20540>:
  family = 12;
  goto <D.20535>;
  <D.20541>:
  family = 16;
  goto <D.20535>;
  <D.20542>:
  family = 23;
  goto <D.20535>;
  <D.20543>:
  family = 26;
  goto <D.20535>;
  <D.20544>:
  D.21442 = (int) af_family;
  monoeg_g_log (0B, 16, "unknown address family 0x%x", D.21442);
  <D.20535>:
  D.21443 = family;
  return D.21443;
}


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

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


is_ipv4_mapped_any (const struct in6_addr * addr)
{
  unsigned char D.21447;
  gboolean D.21450;
  short unsigned int D.21451;
  short unsigned int D.21452;
  int i;

  i = 0;
  goto <D.20731>;
  <D.20730>:
  D.21447 = addr->__in6_u.__u6_addr8[i];
  if (D.21447 != 0) goto <D.21448>; else goto <D.21449>;
  <D.21448>:
  D.21450 = 0;
  return D.21450;
  <D.21449>:
  i = i + 1;
  <D.20731>:
  if (i <= 9) goto <D.20730>; else goto <D.20732>;
  <D.20732>:
  D.21451 = BIT_FIELD_REF <*addr, 16, 80>;
  D.21452 = D.21451;
  if (D.21452 != 65535) goto <D.21453>; else goto <D.21454>;
  <D.21453>:
  D.21450 = 0;
  return D.21450;
  <D.21454>:
  i = 12;
  goto <D.20734>;
  <D.20733>:
  D.21447 = addr->__in6_u.__u6_addr8[i];
  if (D.21447 != 0) goto <D.21455>; else goto <D.21456>;
  <D.21455>:
  D.21450 = 0;
  return D.21450;
  <D.21456>:
  i = i + 1;
  <D.20734>:
  if (i <= 15) goto <D.20733>; else goto <D.20735>;
  <D.20735>:
  D.21450 = 1;
  return D.21450;
}


ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal (SOCKET sock, gint32 af, gint32 * error)
{
  int D.21458;
  int D.21459;
  unsigned int salen.12;
  unsigned int salen.13;
  struct MonoObject * D.21464;
  gchar * iftmp.14;
  int D.21471;
  int salen.15;
  gchar * sa;
  socklen_t salen;
  int ret;
  struct MonoObject * result;

  try
    {
      *error = 0;
      D.21458 = convert_family (af);
      D.21459 = get_sockaddr_size (D.21458);
      salen.12 = (unsigned int) D.21459;
      salen = salen.12;
      salen.13 = salen;
      if (salen.13 == 0) goto <D.21462>; else goto <D.21463>;
      <D.21462>:
      *error = 10047;
      D.21464 = 0B;
      return D.21464;
      <D.21463>:
      salen.13 = salen;
      if (salen.13 <= 128) goto <D.21466>; else goto <D.21467>;
      <D.21466>:
      salen.13 = salen;
      iftmp.14 = __builtin_alloca (salen.13);
      goto <D.21468>;
      <D.21467>:
      salen.13 = salen;
      iftmp.14 = monoeg_malloc0 (salen.13);
      <D.21468>:
      sa = iftmp.14;
      ret = _wapi_getpeername (sock, sa, &salen);
      if (ret == -1) goto <D.21469>; else goto <D.21470>;
      <D.21469>:
      D.21471 = WSAGetLastError ();
      *error = D.21471;
      salen.13 = salen;
      if (salen.13 > 128) goto <D.21472>; else goto <D.21473>;
      <D.21472>:
      monoeg_g_free (sa);
      <D.21473>:
      D.21464 = 0B;
      return D.21464;
      <D.21470>:
      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.21475>; else goto <D.21476>;
      <D.21475>:
      monoeg_g_free (sa);
      <D.21476>:
      D.21464 = result;
      return D.21464;
    }
  finally
    {
      salen = {CLOBBER};
    }
}


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

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.21479 = *error;
      if (D.21479 != 0) goto <D.21480>; else goto <D.21481>;
      <D.21480>:
      return;
      <D.21481>:
      sa_size.16 = sa_size;
      ret = _wapi_bind (sock, sa, sa_size.16);
      if (ret == -1) goto <D.21483>; else goto <D.21484>;
      <D.21483>:
      D.21485 = WSAGetLastError ();
      *error = D.21485;
      <D.21484>:
      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.21489;
  struct MonoClass * D.21490;
  int D.21491;
  sizetype D.21492;
  struct MonoArray * * D.21493;
  unsigned int D.21494;
  struct MonoImage * D.21497;
  struct MonoException * D.21498;
  char * D.21499;
  unsigned char D.21500;
  int D.21501;
  char * D.21502;
  unsigned char D.21503;
  int D.21504;
  int D.21505;
  int D.21506;
  struct MonoImage * D.21511;
  struct MonoException * D.21512;
  char * D.21513;
  unsigned char D.21514;
  short unsigned int D.21515;
  short unsigned int D.21516;
  char * D.21517;
  unsigned char D.21518;
  short unsigned int D.21519;
  char * D.21520;
  unsigned char D.21521;
  int D.21522;
  int D.21523;
  char * D.21524;
  unsigned char D.21525;
  int D.21526;
  int D.21527;
  int D.21528;
  char * D.21529;
  unsigned char D.21530;
  int D.21531;
  int D.21532;
  int D.21533;
  char * D.21534;
  unsigned char D.21535;
  int D.21536;
  int D.21537;
  short unsigned int D.21538;
  unsigned int D.21539;
  short unsigned int D.20819;
  struct sockaddr * D.21540;
  struct MonoImage * D.21545;
  struct MonoException * D.21546;
  char * D.21547;
  unsigned char D.21548;
  short unsigned int D.21549;
  char * D.21550;
  unsigned char D.21551;
  short unsigned int D.21552;
  short unsigned int D.21553;
  char * D.21554;
  unsigned char D.21555;
  int D.21556;
  char * D.21557;
  unsigned char D.21558;
  int D.21559;
  int D.21560;
  int D.21561;
  char * D.21562;
  unsigned char D.21563;
  int D.21564;
  int D.21565;
  int D.21566;
  char * D.21567;
  unsigned char D.21568;
  int D.21569;
  int D.21570;
  int D.21571;
  short unsigned int D.20825;
  int D.21572;
  unsigned int D.21573;
  char * D.21574;
  unsigned char D.21575;
  struct MonoException * D.21580;
  int D.21581;
  unsigned int D.21582;
  char * D.21583;
  unsigned char D.21584;
  int D.21585;
  unsigned int len.17;
  struct MonoClassField * field;
  struct MonoArray * data;
  gint32 family;
  int len;

  D.21489 = saddr_obj->vtable;
  D.21490 = D.21489->klass;
  field = mono_class_get_field_from_name (D.21490, "data");
  D.21491 = field->offset;
  D.21492 = (sizetype) D.21491;
  D.21493 = saddr_obj + D.21492;
  data = *D.21493;
  D.21494 = mono_array_length (data);
  len = (int) D.21494;
  if (len <= 1) goto <D.21495>; else goto <D.21496>;
  <D.21495>:
  D.21497 = mono_get_corlib ();
  D.21498 = mono_exception_from_name (D.21497, "System", "SystemException");
  mono_raise_exception (D.21498);
  <D.21496>:
  D.21499 = mono_array_addr_with_size (data, 1, 0);
  D.21500 = MEM[(guint8 *)D.21499];
  D.21501 = (int) D.21500;
  D.21502 = mono_array_addr_with_size (data, 1, 1);
  D.21503 = MEM[(guint8 *)D.21502];
  D.21504 = (int) D.21503;
  D.21505 = D.21504 << 8;
  D.21506 = D.21501 + D.21505;
  family = convert_family (D.21506);
  if (family == 2) goto <D.21507>; else goto <D.21508>;
  <D.21507>:
  {
    struct sockaddr_in * sa;
    guint16 port;
    guint32 address;

    if (len <= 7) goto <D.21509>; else goto <D.21510>;
    <D.21509>:
    D.21511 = mono_get_corlib ();
    D.21512 = mono_exception_from_name (D.21511, "System", "SystemException");
    mono_raise_exception (D.21512);
    <D.21510>:
    sa = monoeg_malloc0 (16);
    D.21513 = mono_array_addr_with_size (data, 1, 2);
    D.21514 = MEM[(guint8 *)D.21513];
    D.21515 = (short unsigned int) D.21514;
    D.21516 = D.21515 << 8;
    D.21517 = mono_array_addr_with_size (data, 1, 3);
    D.21518 = MEM[(guint8 *)D.21517];
    D.21519 = (short unsigned int) D.21518;
    port = D.21516 + D.21519;
    D.21520 = mono_array_addr_with_size (data, 1, 4);
    D.21521 = MEM[(guint8 *)D.21520];
    D.21522 = (int) D.21521;
    D.21523 = D.21522 << 24;
    D.21524 = mono_array_addr_with_size (data, 1, 5);
    D.21525 = MEM[(guint8 *)D.21524];
    D.21526 = (int) D.21525;
    D.21527 = D.21526 << 16;
    D.21528 = D.21523 + D.21527;
    D.21529 = mono_array_addr_with_size (data, 1, 6);
    D.21530 = MEM[(guint8 *)D.21529];
    D.21531 = (int) D.21530;
    D.21532 = D.21531 << 8;
    D.21533 = D.21528 + D.21532;
    D.21534 = mono_array_addr_with_size (data, 1, 7);
    D.21535 = MEM[(guint8 *)D.21534];
    D.21536 = (int) D.21535;
    D.21537 = D.21533 + D.21536;
    address = (guint32) D.21537;
    D.21538 = (short unsigned int) family;
    sa->sin_family = D.21538;
    D.21539 = __bswap_32 (address);
    sa->sin_addr.s_addr = D.21539;
    {
      short unsigned int __bsx;

      __bsx = port;
      D.20819 = __bsx r>> 8;
    }
    sa->sin_port = D.20819;
    *sa_size = 16;
    D.21540 = sa;
    return D.21540;
  }
  <D.21508>:
  if (family == 10) goto <D.21541>; else goto <D.21542>;
  <D.21541>:
  {
    struct sockaddr_in6 * sa;
    int i;
    guint16 port;
    guint32 scopeid;

    if (len <= 27) goto <D.21543>; else goto <D.21544>;
    <D.21543>:
    D.21545 = mono_get_corlib ();
    D.21546 = mono_exception_from_name (D.21545, "System", "SystemException");
    mono_raise_exception (D.21546);
    <D.21544>:
    sa = monoeg_malloc0 (28);
    D.21547 = mono_array_addr_with_size (data, 1, 3);
    D.21548 = MEM[(guint8 *)D.21547];
    D.21549 = (short unsigned int) D.21548;
    D.21550 = mono_array_addr_with_size (data, 1, 2);
    D.21551 = MEM[(guint8 *)D.21550];
    D.21552 = (short unsigned int) D.21551;
    D.21553 = D.21552 << 8;
    port = D.21549 + D.21553;
    D.21554 = mono_array_addr_with_size (data, 1, 24);
    D.21555 = MEM[(guint8 *)D.21554];
    D.21556 = (int) D.21555;
    D.21557 = mono_array_addr_with_size (data, 1, 25);
    D.21558 = MEM[(guint8 *)D.21557];
    D.21559 = (int) D.21558;
    D.21560 = D.21559 << 8;
    D.21561 = D.21556 + D.21560;
    D.21562 = mono_array_addr_with_size (data, 1, 26);
    D.21563 = MEM[(guint8 *)D.21562];
    D.21564 = (int) D.21563;
    D.21565 = D.21564 << 16;
    D.21566 = D.21561 + D.21565;
    D.21567 = mono_array_addr_with_size (data, 1, 27);
    D.21568 = MEM[(guint8 *)D.21567];
    D.21569 = (int) D.21568;
    D.21570 = D.21569 << 24;
    D.21571 = D.21566 + D.21570;
    scopeid = (guint32) D.21571;
    D.21538 = (short unsigned int) family;
    sa->sin6_family = D.21538;
    {
      short unsigned int __bsx;

      __bsx = port;
      D.20825 = __bsx r>> 8;
    }
    sa->sin6_port = D.20825;
    sa->sin6_scope_id = scopeid;
    i = 0;
    goto <D.20827>;
    <D.20826>:
    D.21572 = i + 8;
    D.21573 = (unsigned int) D.21572;
    D.21574 = mono_array_addr_with_size (data, 1, D.21573);
    D.21575 = MEM[(guint8 *)D.21574];
    sa->sin6_addr.__in6_u.__u6_addr8[i] = D.21575;
    i = i + 1;
    <D.20827>:
    if (i <= 15) goto <D.20826>; else goto <D.20828>;
    <D.20828>:
    *sa_size = 28;
    D.21540 = sa;
    return D.21540;
  }
  <D.21542>:
  if (family == 1) goto <D.21576>; else goto <D.21577>;
  <D.21576>:
  {
    struct sockaddr_un * sock_un;
    int i;

    if (len > 1) goto <D.21578>; else goto <D.21579>;
    <D.21578>:
    D.21580 = mono_get_exception_index_out_of_range ();
    mono_raise_exception (D.21580);
    <D.21579>:
    sock_un = monoeg_malloc0 (110);
    D.21538 = (short unsigned int) family;
    sock_un->sun_family = D.21538;
    i = 0;
    goto <D.20832>;
    <D.20831>:
    D.21581 = i + 2;
    D.21582 = (unsigned int) D.21581;
    D.21583 = mono_array_addr_with_size (data, 1, D.21582);
    D.21584 = MEM[(guint8 *)D.21583];
    sock_un->sun_path[i] = D.21584;
    i = i + 1;
    <D.20832>:
    D.21585 = len + -2;
    if (D.21585 > i) goto <D.20831>; else goto <D.20833>;
    <D.20833>:
    len.17 = (unsigned int) len;
    *sa_size = len.17;
    D.21540 = sock_un;
    return D.21540;
  }
  <D.21577>:
  *error = 10047;
  D.21540 = 0B;
  return D.21540;
}


ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode, gint timeout, gint32 * error)
{
  int sock.18;
  short int iftmp.19;
  short int iftmp.20;
  int iftmp.21;
  _Bool D.21601;
  _Bool D.21602;
  _Bool D.21603;
  int * D.21606;
  long int D.21607;
  int D.21608;
  int D.21613;
  MonoBoolean D.21620;
  unsigned int D.21624;
  unsigned int D.21625;
  int D.21626;
  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.21590>; else goto <D.21591>;
  <D.21590>:
  if (mode == 1) goto <D.21593>; else goto <D.21594>;
  <D.21593>:
  iftmp.20 = 4;
  goto <D.21595>;
  <D.21594>:
  iftmp.20 = 56;
  <D.21595>:
  iftmp.19 = iftmp.20;
  goto <D.21596>;
  <D.21591>:
  iftmp.19 = 1;
  <D.21596>:
  pfds->events = iftmp.19;
  if (timeout >= 0) goto <D.21598>; else goto <D.21599>;
  <D.21598>:
  iftmp.21 = timeout / 1000;
  goto <D.21600>;
  <D.21599>:
  iftmp.21 = -1;
  <D.21600>:
  timeout = iftmp.21;
  start = time (0B);
  <D.20859>:
  *error = 0;
  ret = mono_poll (pfds, 1, timeout);
  D.21601 = timeout > 0;
  D.21602 = ret < 0;
  D.21603 = D.21601 & D.21602;
  if (D.21603 != 0) goto <D.21604>; else goto <D.21605>;
  <D.21604>:
  {
    int err;
    int sec;

    D.21606 = __errno_location ();
    err = *D.21606;
    D.21607 = time (0B);
    sec = D.21607 - start;
    D.21608 = sec * -1000;
    timeout = D.21608 + timeout;
    if (timeout < 0) goto <D.21609>; else goto <D.21610>;
    <D.21609>:
    timeout = 0;
    <D.21610>:
    D.21606 = __errno_location ();
    *D.21606 = err;
  }
  <D.21605>:
  if (ret == -1) goto <D.21611>; else goto <D.21612>;
  <D.21611>:
  D.21606 = __errno_location ();
  D.21613 = *D.21606;
  if (D.21613 == 4) goto <D.21614>; else goto <D.21615>;
  <D.21614>:
  {
    int leave;

    leave = 0;
    if (thread == 0B) goto <D.21616>; else goto <D.21617>;
    <D.21616>:
    thread = mono_thread_internal_current ();
    <D.21617>:
    leave = mono_thread_test_state (thread, 129);
    if (leave != 0) goto <D.21618>; else goto <D.21619>;
    <D.21618>:
    monoeg_g_free (pfds);
    D.21620 = 0;
    return D.21620;
    <D.21619>:
    mono_thread_interruption_checkpoint ();
    D.21606 = __errno_location ();
    *D.21606 = 4;
  }
  <D.21615>:
  <D.21612>:
  if (ret == -1) goto <D.21621>; else goto <D.20860>;
  <D.21621>:
  D.21606 = __errno_location ();
  D.21613 = *D.21606;
  if (D.21613 == 4) goto <D.20859>; else goto <D.20860>;
  <D.20860>:
  if (ret == -1) goto <D.21622>; else goto <D.21623>;
  <D.21622>:
  D.21606 = __errno_location ();
  D.21613 = *D.21606;
  D.21624 = (unsigned int) D.21613;
  D.21625 = errno_to_WSA (D.21624, &__func__);
  D.21626 = (int) D.21625;
  *error = D.21626;
  monoeg_g_free (pfds);
  D.21620 = 0;
  return D.21620;
  <D.21623>:
  monoeg_g_free (pfds);
  if (ret == 0) goto <D.21627>; else goto <D.21628>;
  <D.21627>:
  D.21620 = 0;
  return D.21620;
  <D.21628>:
  D.21620 = 1;
  return D.21620;
}


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

  try
    {
      *error = 0;
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.21630 = *error;
      if (D.21630 != 0) goto <D.21631>; else goto <D.21632>;
      <D.21631>:
      return;
      <D.21632>:
      sa_size.22 = sa_size;
      ret = _wapi_connect (sock, sa, sa_size.22);
      if (ret == -1) goto <D.21634>; else goto <D.21635>;
      <D.21634>:
      D.21636 = WSAGetLastError ();
      *error = D.21636;
      <D.21635>:
      monoeg_g_free (sa);
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Disconnect_internal (SOCKET sock, MonoBoolean reuse, gint32 * error)
{
  gboolean (*<T2470>) (guint32, struct WapiOverlapped *, guint32, WapiTransmitFileFlags) _wapi_disconnectex.23;
  gboolean (*<T2477>) (guint32, void *, guint32, guint32, struct WapiOverlapped *, struct WapiTransmitFileBuffers *, WapiTransmitFileFlags) _wapi_transmitfile.24;
  int D.21656;
  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 = *.LC0;
      trans_guid = *.LC1;
      _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.21642>; else goto <D.21643>;
      <D.21642>:
      _wapi_disconnectex = 0B;
      ret = WSAIoctl (sock, -939524090, &trans_guid, 16, &_wapi_transmitfile, 4, &output_bytes, 0B, 0B);
      if (ret != 0) goto <D.21644>; else goto <D.21645>;
      <D.21644>:
      _wapi_transmitfile = 0B;
      <D.21645>:
      <D.21643>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      if (_wapi_disconnectex.23 != 0B) goto <D.21647>; else goto <D.21648>;
      <D.21647>:
      _wapi_disconnectex.23 = _wapi_disconnectex;
      bret = _wapi_disconnectex.23 (sock, 0B, 2, 0);
      goto <D.21649>;
      <D.21648>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      if (_wapi_transmitfile.24 != 0B) goto <D.21651>; else goto <D.21652>;
      <D.21651>:
      _wapi_transmitfile.24 = _wapi_transmitfile;
      bret = _wapi_transmitfile.24 (sock, 0B, 0, 0, 0B, 0B, 3);
      goto <D.21653>;
      <D.21652>:
      *error = 50;
      return;
      <D.21653>:
      <D.21649>:
      if (bret == 0) goto <D.21654>; else goto <D.21655>;
      <D.21654>:
      D.21656 = WSAGetLastError ();
      *error = D.21656;
      <D.21655>:
    }
  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.21660;
  int D.21661;
  gint32 D.21664;
  unsigned int offset.25;
  unsigned int count.26;
  int D.21671;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;

  recvflags = 0;
  *error = 0;
  D.21660 = mono_array_length (buffer);
  alen = (gint32) D.21660;
  D.21661 = alen - count;
  if (D.21661 < offset) goto <D.21662>; else goto <D.21663>;
  <D.21662>:
  D.21664 = 0;
  return D.21664;
  <D.21663>:
  offset.25 = (unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, offset.25);
  recvflags = convert_socketflags (flags);
  if (recvflags == -1) goto <D.21666>; else goto <D.21667>;
  <D.21666>:
  *error = 10045;
  D.21664 = 0;
  return D.21664;
  <D.21667>:
  count.26 = (unsigned int) count;
  ret = _wapi_recv (sock, buf, count.26, recvflags);
  if (ret == -1) goto <D.21669>; else goto <D.21670>;
  <D.21669>:
  D.21671 = WSAGetLastError ();
  *error = D.21671;
  D.21664 = 0;
  return D.21664;
  <D.21670>:
  D.21664 = ret;
  return D.21664;
}


convert_socketflags (gint32 sflags)
{
  gint32 D.21675;
  int D.21676;
  int D.21679;
  int D.21682;
  int D.21685;
  int D.21688;
  gint32 flags;

  flags = 0;
  if (sflags == 0) goto <D.21673>; else goto <D.21674>;
  <D.21673>:
  D.21675 = 0;
  return D.21675;
  <D.21674>:
  D.21676 = sflags & -32792;
  if (D.21676 != 0) goto <D.21677>; else goto <D.21678>;
  <D.21677>:
  D.21675 = -1;
  return D.21675;
  <D.21678>:
  D.21679 = sflags & 1;
  if (D.21679 != 0) goto <D.21680>; else goto <D.21681>;
  <D.21680>:
  flags = flags | 1;
  <D.21681>:
  D.21682 = sflags & 2;
  if (D.21682 != 0) goto <D.21683>; else goto <D.21684>;
  <D.21683>:
  flags = flags | 2;
  <D.21684>:
  D.21685 = sflags & 4;
  if (D.21685 != 0) goto <D.21686>; else goto <D.21687>;
  <D.21686>:
  flags = flags | 4;
  <D.21687>:
  D.21688 = sflags & 32768;
  if (D.21688 != 0) goto <D.21689>; else goto <D.21690>;
  <D.21689>:
  flags = flags | 32768;
  <D.21690>:
  D.21675 = flags;
  return D.21675;
}


ves_icall_System_Net_Sockets_Socket_Receive_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  unsigned int D.21692;
  int D.21693;
  unsigned int recvflags.27;
  unsigned int recvflags.28;
  gint32 D.21698;
  unsigned int count.29;
  int D.21702;
  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.21692 = mono_array_length (buffers);
      count = (int) D.21692;
      D.21693 = convert_socketflags (flags);
      recvflags.27 = (unsigned int) D.21693;
      recvflags = recvflags.27;
      recvflags.28 = recvflags;
      if (recvflags.28 == 4294967295) goto <D.21696>; else goto <D.21697>;
      <D.21696>:
      *error = 10045;
      D.21698 = 0;
      return D.21698;
      <D.21697>:
      count.29 = (unsigned int) count;
      ret = WSARecv (sock, wsabufs, count.29, &recv, &recvflags, 0B, 0B);
      if (ret == -1) goto <D.21700>; else goto <D.21701>;
      <D.21700>:
      D.21702 = WSAGetLastError ();
      *error = D.21702;
      D.21698 = 0;
      return D.21698;
      <D.21701>:
      recv.30 = recv;
      D.21698 = (gint32) recv.30;
      return D.21698;
    }
  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.21706;
  int D.21707;
  gint32 D.21710;
  struct MonoObject * D.21711;
  int D.21712;
  unsigned int offset.31;
  unsigned int count.32;
  int D.21721;
  unsigned int sa_size.33;
  int sa_size.34;
  struct MonoObject * D.21726;
  int ret;
  guchar * buf;
  gint32 alen;
  int recvflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      recvflags = 0;
      *error = 0;
      D.21706 = mono_array_length (buffer);
      alen = (gint32) D.21706;
      D.21707 = alen - count;
      if (D.21707 < offset) goto <D.21708>; else goto <D.21709>;
      <D.21708>:
      D.21710 = 0;
      return D.21710;
      <D.21709>:
      D.21711 = *sockaddr;
      sa = create_sockaddr_from_object (D.21711, &sa_size, error);
      D.21712 = *error;
      if (D.21712 != 0) goto <D.21713>; else goto <D.21714>;
      <D.21713>:
      D.21710 = 0;
      return D.21710;
      <D.21714>:
      offset.31 = (unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, offset.31);
      recvflags = convert_socketflags (flags);
      if (recvflags == -1) goto <D.21716>; else goto <D.21717>;
      <D.21716>:
      *error = 10045;
      D.21710 = 0;
      return D.21710;
      <D.21717>:
      count.32 = (unsigned int) count;
      ret = _wapi_recvfrom (sock, buf, count.32, recvflags, sa, &sa_size);
      if (ret == -1) goto <D.21719>; else goto <D.21720>;
      <D.21719>:
      monoeg_g_free (sa);
      D.21721 = WSAGetLastError ();
      *error = D.21721;
      D.21710 = 0;
      return D.21710;
      <D.21720>:
      sa_size.33 = sa_size;
      if (sa_size.33 != 0) goto <D.21723>; else goto <D.21724>;
      <D.21723>:
      sa_size.33 = sa_size;
      sa_size.34 = (int) sa_size.33;
      D.21726 = create_object_from_sockaddr (sa, sa_size.34, error);
      *sockaddr = D.21726;
      goto <D.21727>;
      <D.21724>:
      *sockaddr = 0B;
      <D.21727>:
      monoeg_g_free (sa);
      D.21710 = ret;
      return D.21710;
    }
  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.21730;
  int D.21731;
  gint32 D.21734;
  unsigned int offset.35;
  unsigned int count.36;
  int D.21741;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;

  sendflags = 0;
  *error = 0;
  D.21730 = mono_array_length (buffer);
  alen = (gint32) D.21730;
  D.21731 = alen - count;
  if (D.21731 < offset) goto <D.21732>; else goto <D.21733>;
  <D.21732>:
  D.21734 = 0;
  return D.21734;
  <D.21733>:
  offset.35 = (unsigned int) offset;
  buf = mono_array_addr_with_size (buffer, 1, offset.35);
  sendflags = convert_socketflags (flags);
  if (sendflags == -1) goto <D.21736>; else goto <D.21737>;
  <D.21736>:
  *error = 10045;
  D.21734 = 0;
  return D.21734;
  <D.21737>:
  count.36 = (unsigned int) count;
  ret = _wapi_send (sock, buf, count.36, sendflags);
  if (ret == -1) goto <D.21739>; else goto <D.21740>;
  <D.21739>:
  D.21741 = WSAGetLastError ();
  *error = D.21741;
  D.21734 = 0;
  return D.21734;
  <D.21740>:
  D.21734 = ret;
  return D.21734;
}


ves_icall_System_Net_Sockets_Socket_Send_array_internal (SOCKET sock, struct MonoArray * buffers, gint32 flags, gint32 * error)
{
  unsigned int D.21743;
  int D.21744;
  gint32 D.21747;
  unsigned int count.37;
  int D.21751;
  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.21743 = mono_array_length (buffers);
      count = (int) D.21743;
      D.21744 = convert_socketflags (flags);
      sendflags = (DWORD) D.21744;
      if (sendflags == 4294967295) goto <D.21745>; else goto <D.21746>;
      <D.21745>:
      *error = 10045;
      D.21747 = 0;
      return D.21747;
      <D.21746>:
      count.37 = (unsigned int) count;
      ret = WSASend (sock, wsabufs, count.37, &sent, sendflags, 0B, 0B);
      if (ret == -1) goto <D.21749>; else goto <D.21750>;
      <D.21749>:
      D.21751 = WSAGetLastError ();
      *error = D.21751;
      D.21747 = 0;
      return D.21747;
      <D.21750>:
      sent.38 = sent;
      D.21747 = (gint32) sent.38;
      return D.21747;
    }
  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.21755;
  int D.21756;
  gint32 D.21759;
  int D.21760;
  unsigned int offset.39;
  unsigned int count.40;
  unsigned int sa_size.41;
  int D.21770;
  int ret;
  guchar * buf;
  gint32 alen;
  int sendflags;
  struct sockaddr * sa;
  socklen_t sa_size;

  try
    {
      sendflags = 0;
      *error = 0;
      D.21755 = mono_array_length (buffer);
      alen = (gint32) D.21755;
      D.21756 = alen - count;
      if (D.21756 < offset) goto <D.21757>; else goto <D.21758>;
      <D.21757>:
      D.21759 = 0;
      return D.21759;
      <D.21758>:
      sa = create_sockaddr_from_object (sockaddr, &sa_size, error);
      D.21760 = *error;
      if (D.21760 != 0) goto <D.21761>; else goto <D.21762>;
      <D.21761>:
      D.21759 = 0;
      return D.21759;
      <D.21762>:
      offset.39 = (unsigned int) offset;
      buf = mono_array_addr_with_size (buffer, 1, offset.39);
      sendflags = convert_socketflags (flags);
      if (sendflags == -1) goto <D.21764>; else goto <D.21765>;
      <D.21764>:
      *error = 10045;
      D.21759 = 0;
      return D.21759;
      <D.21765>:
      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.21768>; else goto <D.21769>;
      <D.21768>:
      D.21770 = WSAGetLastError ();
      *error = D.21770;
      <D.21769>:
      monoeg_g_free (sa);
      D.21759 = ret;
      return D.21759;
    }
  finally
    {
      sa_size = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_Select_internal (struct MonoArray * * sockets, gint32 timeout, gint32 * error)
{
  struct MonoArray * D.21773;
  unsigned int D.21774;
  unsigned int nfds.42;
  unsigned int D.21776;
  unsigned int i.43;
  char * D.21778;
  unsigned int idx.44;
  unsigned int D.21784;
  struct mono_pollfd * D.21785;
  unsigned int D.21786;
  int D.21787;
  short int iftmp.45;
  short int iftmp.46;
  int iftmp.47;
  _Bool D.21800;
  _Bool D.21801;
  _Bool D.21802;
  int * D.21805;
  long int D.21806;
  int D.21807;
  int D.21812;
  unsigned int D.21822;
  unsigned int D.21823;
  int D.21824;
  struct MonoVTable * D.21827;
  unsigned int ret.48;
  unsigned int socks_size.49;
  struct MonoDomain * D.21830;
  char * D.21831;
  int D.21834;
  unsigned int D.21835;
  unsigned int D.21836;
  short int D.21837;
  unsigned short D.21843;
  int D.21844;
  int D.21845;
  int idx.50;
  unsigned int idx.51;
  int D.21852;
  int idx.52;
  unsigned int idx.53;
  int D.21856;
  int idx.54;
  unsigned int idx.55;
  _Bool D.21861;
  _Bool D.21862;
  _Bool D.21863;
  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.21773 = *sockets;
      D.21774 = mono_array_length (D.21773);
      count = (int) D.21774;
      nfds = count + -3;
      nfds.42 = (unsigned int) nfds;
      D.21776 = nfds.42 * 8;
      pfds = monoeg_malloc0 (D.21776);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.20983>;
      <D.20982>:
      D.21773 = *sockets;
      i.43 = (unsigned int) i;
      D.21778 = mono_array_addr_with_size (D.21773, 4, i.43);
      obj = MEM[(struct MonoObject * *)D.21778];
      if (obj == 0B) goto <D.21779>; else goto <D.21780>;
      <D.21779>:
      mode = mode + 1;
      // predicted unlikely by continue predictor.
      goto <D.20981>;
      <D.21780>:
      if (idx >= nfds) goto <D.21781>; else goto <D.21782>;
      <D.21781>:
      monoeg_g_free (pfds);
      *error = 10014;
      return;
      <D.21782>:
      idx.44 = (unsigned int) idx;
      D.21784 = idx.44 * 8;
      D.21785 = pfds + D.21784;
      D.21786 = Socket_to_SOCKET (obj);
      D.21787 = (int) D.21786;
      D.21785->fd = D.21787;
      idx.44 = (unsigned int) idx;
      D.21784 = idx.44 * 8;
      D.21785 = pfds + D.21784;
      if (mode != 0) goto <D.21789>; else goto <D.21790>;
      <D.21789>:
      if (mode == 1) goto <D.21792>; else goto <D.21793>;
      <D.21792>:
      iftmp.46 = 4;
      goto <D.21794>;
      <D.21793>:
      iftmp.46 = 56;
      <D.21794>:
      iftmp.45 = iftmp.46;
      goto <D.21795>;
      <D.21790>:
      iftmp.45 = 1;
      <D.21795>:
      D.21785->events = iftmp.45;
      idx = idx + 1;
      <D.20981>:
      i = i + 1;
      <D.20983>:
      if (i < count) goto <D.20982>; else goto <D.20984>;
      <D.20984>:
      if (timeout >= 0) goto <D.21797>; else goto <D.21798>;
      <D.21797>:
      iftmp.47 = timeout / 1000;
      goto <D.21799>;
      <D.21798>:
      iftmp.47 = -1;
      <D.21799>:
      timeout = iftmp.47;
      start = time (0B);
      <D.20988>:
      *error = 0;
      nfds.42 = (unsigned int) nfds;
      ret = mono_poll (pfds, nfds.42, timeout);
      D.21800 = timeout > 0;
      D.21801 = ret < 0;
      D.21802 = D.21800 & D.21801;
      if (D.21802 != 0) goto <D.21803>; else goto <D.21804>;
      <D.21803>:
      {
        int err;
        int sec;

        D.21805 = __errno_location ();
        err = *D.21805;
        D.21806 = time (0B);
        sec = D.21806 - start;
        D.21807 = sec * -1000;
        timeout = D.21807 + timeout;
        if (timeout < 0) goto <D.21808>; else goto <D.21809>;
        <D.21808>:
        timeout = 0;
        <D.21809>:
        D.21805 = __errno_location ();
        *D.21805 = err;
      }
      <D.21804>:
      if (ret == -1) goto <D.21810>; else goto <D.21811>;
      <D.21810>:
      D.21805 = __errno_location ();
      D.21812 = *D.21805;
      if (D.21812 == 4) goto <D.21813>; else goto <D.21814>;
      <D.21813>:
      {
        int leave;

        leave = 0;
        if (thread == 0B) goto <D.21815>; else goto <D.21816>;
        <D.21815>:
        thread = mono_thread_internal_current ();
        <D.21816>:
        leave = mono_thread_test_state (thread, 129);
        if (leave != 0) goto <D.21817>; else goto <D.21818>;
        <D.21817>:
        monoeg_g_free (pfds);
        *sockets = 0B;
        return;
        <D.21818>:
        mono_thread_interruption_checkpoint ();
        D.21805 = __errno_location ();
        *D.21805 = 4;
      }
      <D.21814>:
      <D.21811>:
      if (ret == -1) goto <D.21819>; else goto <D.20989>;
      <D.21819>:
      D.21805 = __errno_location ();
      D.21812 = *D.21805;
      if (D.21812 == 4) goto <D.20988>; else goto <D.20989>;
      <D.20989>:
      if (ret == -1) goto <D.21820>; else goto <D.21821>;
      <D.21820>:
      D.21805 = __errno_location ();
      D.21812 = *D.21805;
      D.21822 = (unsigned int) D.21812;
      D.21823 = errno_to_WSA (D.21822, &__func__);
      D.21824 = (int) D.21823;
      *error = D.21824;
      monoeg_g_free (pfds);
      return;
      <D.21821>:
      if (ret == 0) goto <D.21825>; else goto <D.21826>;
      <D.21825>:
      monoeg_g_free (pfds);
      *sockets = 0B;
      return;
      <D.21826>:
      D.21773 = *sockets;
      D.21827 = MEM[(struct MonoObject *)D.21773].vtable;
      sock_arr_class = D.21827->klass;
      ret.48 = (unsigned int) ret;
      socks_size.49 = ret.48 + 3;
      socks_size = socks_size.49;
      D.21830 = mono_domain_get ();
      socks = mono_array_new_full (D.21830, sock_arr_class, &socks_size, 0B);
      idx = 0;
      mode = idx;
      i = 0;
      goto <D.20997>;
      <D.20996>:
      {
        struct mono_pollfd * pfd;

        D.21773 = *sockets;
        i.43 = (unsigned int) i;
        D.21831 = mono_array_addr_with_size (D.21773, 4, i.43);
        obj = MEM[(struct MonoObject * *)D.21831];
        if (obj == 0B) goto <D.21832>; else goto <D.21833>;
        <D.21832>:
        mode = mode + 1;
        idx = idx + 1;
        // predicted unlikely by continue predictor.
        goto <D.20992>;
        <D.21833>:
        D.21834 = i - mode;
        D.21835 = (unsigned int) D.21834;
        D.21836 = D.21835 * 8;
        pfd = pfds + D.21836;
        D.21837 = pfd->revents;
        if (D.21837 == 0) goto <D.21838>; else goto <D.21839>;
        <D.21838>:
        // predicted unlikely by continue predictor.
        goto <D.20992>;
        <D.21839>:
        ret = ret + -1;
        if (mode == 0) goto <D.21842>; else goto <D.21840>;
        <D.21842>:
        D.21837 = pfd->revents;
        D.21843 = (unsigned short) D.21837;
        D.21844 = (int) D.21843;
        D.21845 = D.21844 & 57;
        if (D.21845 != 0) goto <D.21846>; else goto <D.21840>;
        <D.21846>:
        {
          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.21841>;
        <D.21840>:
        if (mode == 1) goto <D.21851>; else goto <D.21849>;
        <D.21851>:
        D.21837 = pfd->revents;
        D.21843 = (unsigned short) D.21837;
        D.21844 = (int) D.21843;
        D.21852 = D.21844 & 60;
        if (D.21852 != 0) goto <D.21853>; else goto <D.21849>;
        <D.21853>:
        {
          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.21850>;
        <D.21849>:
        D.21837 = pfd->revents;
        D.21843 = (unsigned short) D.21837;
        D.21844 = (int) D.21843;
        D.21856 = D.21844 & 56;
        if (D.21856 != 0) goto <D.21857>; else goto <D.21858>;
        <D.21857>:
        {
          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.21858>:
        <D.21850>:
        <D.21841>:
      }
      <D.20992>:
      i = i + 1;
      <D.20997>:
      D.21861 = i < count;
      D.21862 = ret > 0;
      D.21863 = D.21861 & D.21862;
      if (D.21863 != 0) goto <D.20996>; else goto <D.20998>;
      <D.20998>:
      *sockets = socks;
      monoeg_g_free (pfds);
    }
  finally
    {
      socks_size = {CLOBBER};
    }
}


Socket_to_SOCKET (struct MonoObject * sockobj)
{
  struct MonoVTable * D.21867;
  struct MonoClass * D.21868;
  int D.21869;
  sizetype D.21870;
  void * * D.21871;
  void * D.21872;
  SOCKET D.21873;
  SOCKET sock;
  struct MonoClassField * field;

  D.21867 = sockobj->vtable;
  D.21868 = D.21867->klass;
  field = mono_class_get_field_from_name (D.21868, "socket");
  D.21869 = field->offset;
  D.21870 = (sizetype) D.21869;
  D.21871 = sockobj + D.21870;
  D.21872 = *D.21871;
  sock = (SOCKET) D.21872;
  D.21873 = sock;
  return D.21873;
}


ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal (SOCKET sock, gint32 level, gint32 name, struct MonoObject * * obj_val, gint32 * error)
{
  _Bool D.21875;
  _Bool D.21876;
  _Bool D.21877;
  <unnamed type> level.56;
  struct MonoObject * D.21886;
  int system_level.57;
  int system_name.58;
  int D.21891;
  struct MonoImage * D.21892;
  int D.21893;
  sizetype D.21894;
  guint8 * D.21895;
  int D.21896;
  unsigned char D.21897;
  guint32 * D.21898;
  int D.21899;
  unsigned int D.21900;
  _Bool D.21901;
  int D.21902;
  int time_ms.59;
  struct MonoImage * mono_posix_image.60;
  struct MonoImage * mono_posix_image.61;
  struct MonoImage * mono_posix_image.62;
  int D.21913;
  unsigned int D.21914;
  int D.21915;
  unsigned int D.21916;
  int D.21917;
  int val.63;
  _Bool D.21921;
  int val.64;
  int system_level;
  int system_name;
  int ret;
  int val;
  socklen_t valsize;
  struct linger linger;
  socklen_t lingersize;
  int time_ms;
  socklen_t time_ms_size;
  struct ucred cred;
  socklen_t credsize;
  struct MonoDomain * domain;
  struct MonoObject * obj;
  struct MonoClass * obj_class;
  struct MonoClassField * field;

  try
    {
      valsize = 4;
      lingersize = 8;
      time_ms = 0;
      time_ms_size = 4;
      credsize = 12;
      domain = mono_domain_get ();
      *error = 0;
      D.21875 = level == 65535;
      D.21876 = name == -5;
      D.21877 = D.21875 & D.21876;
      if (D.21877 != 0) goto <D.21878>; else goto <D.21879>;
      <D.21878>:
      system_level = 1;
      system_name = 2;
      ret = 0;
      goto <D.21880>;
      <D.21879>:
      level.56 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.56, name, &system_level, &system_name);
      <D.21880>:
      if (ret == -1) goto <D.21882>; else goto <D.21883>;
      <D.21882>:
      *error = 10042;
      return;
      <D.21883>:
      if (ret == -2) goto <D.21884>; else goto <D.21885>;
      <D.21884>:
      D.21886 = int_to_object (domain, 0);
      *obj_val = D.21886;
      return;
      <D.21885>:
      switch (name) <default: <D.21031>, case -129: <D.21026>, case 128: <D.21025>, case 4101: <D.21028>, case 4102: <D.21029>, case 10001: <D.21030>>
      <D.21025>:
      <D.21026>:
      system_level.57 = system_level;
      system_name.58 = system_name;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.58, &linger, &lingersize);
      goto <D.21027>;
      <D.21028>:
      <D.21029>:
      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.21027>;
      <D.21030>:
      system_level.57 = system_level;
      system_name.58 = system_name;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.58, &cred, &credsize);
      goto <D.21027>;
      <D.21031>:
      system_level.57 = system_level;
      system_name.58 = system_name;
      ret = _wapi_getsockopt (sock, system_level.57, system_name.58, &val, &valsize);
      <D.21027>:
      if (ret == -1) goto <D.21889>; else goto <D.21890>;
      <D.21889>:
      D.21891 = WSAGetLastError ();
      *error = D.21891;
      return;
      <D.21890>:
      switch (name) <default: <D.21041>, case -129: <D.21034>, case 128: <D.21032>, case 4101: <D.21035>, case 4102: <D.21036>, case 10001: <D.21037>>
      <D.21032>:
      D.21892 = get_socket_assembly ();
      obj_class = mono_class_from_name (D.21892, "System.Net.Sockets", "LingerOption");
      obj = mono_object_new (domain, obj_class);
      field = mono_class_get_field_from_name (obj_class, "enabled");
      D.21893 = field->offset;
      D.21894 = (sizetype) D.21893;
      D.21895 = obj + D.21894;
      D.21896 = linger.l_onoff;
      D.21897 = (unsigned char) D.21896;
      *D.21895 = D.21897;
      field = mono_class_get_field_from_name (obj_class, "seconds");
      D.21893 = field->offset;
      D.21894 = (sizetype) D.21893;
      D.21898 = obj + D.21894;
      D.21899 = linger.l_linger;
      D.21900 = (unsigned int) D.21899;
      *D.21898 = D.21900;
      goto <D.21033>;
      <D.21034>:
      D.21896 = linger.l_onoff;
      D.21901 = D.21896 == 0;
      D.21902 = (int) D.21901;
      obj = int_to_object (domain, D.21902);
      goto <D.21033>;
      <D.21035>:
      <D.21036>:
      time_ms.59 = time_ms;
      obj = int_to_object (domain, time_ms.59);
      goto <D.21033>;
      <D.21037>:
      {
        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.21905>; else goto <D.21906>;
        <D.21905>:
        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.21908>; else goto <D.21909>;
        <D.21908>:
        {
          struct MonoAssembly * sa;

          sa = mono_assembly_open ("Mono.Posix.dll", 0B);
          if (sa == 0B) goto <D.21910>; else goto <D.21911>;
          <D.21910>:
          *error = 10042;
          return;
          <D.21911>:
          mono_posix_image.62 = mono_assembly_get_image (sa);
          mono_posix_image = mono_posix_image.62;
        }
        <D.21909>:
        <D.21906>:
        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.21913 = cred.pid;
        cred_data->pid = D.21913;
        D.21914 = cred.uid;
        D.21915 = (int) D.21914;
        cred_data->uid = D.21915;
        D.21916 = cred.gid;
        D.21917 = (int) D.21916;
        cred_data->gid = D.21917;
        goto <D.21033>;
      }
      <D.21041>:
      D.21875 = level == 65535;
      D.21876 = name == -5;
      D.21877 = D.21875 & D.21876;
      if (D.21877 != 0) goto <D.21918>; else goto <D.21919>;
      <D.21918>:
      val.63 = val;
      D.21921 = val.63 == 0;
      val.64 = (int) D.21921;
      val = val.64;
      <D.21919>:
      val.63 = val;
      obj = int_to_object (domain, val.63);
      <D.21033>:
      *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.21926;
  int cached.65;
  int iftmp.66;
  int proto.67;

  switch (mono_level) <default: <D.20661>, case 0: <D.20613>, case 6: <D.20650>, case 17: <D.20657>, case 41: <D.20631>, case 65535: <D.20588>>
  <D.20588>:
  *system_level = 1;
  switch (mono_name) <default: <D.20611>, case -129: <D.20589>, case -5: <D.20608>, case 1: <D.20591>, case 2: <D.20592>, case 4: <D.20593>, case 8: <D.20594>, case 16: <D.20595>, case 32: <D.20596>, case 64: <D.20609>, case 128: <D.20597>, case 256: <D.20598>, case 4097: <D.20599>, case 4098: <D.20600>, case 4099: <D.20601>, case 4100: <D.20602>, case 4101: <D.20603>, case 4102: <D.20604>, case 4103: <D.20605>, case 4104: <D.20606>, case 10001: <D.20607>, case 2147483647: <D.20610>>
  <D.20589>:
  *system_name = 13;
  goto <D.20590>;
  <D.20591>:
  *system_name = 1;
  goto <D.20590>;
  <D.20592>:
  *system_name = 30;
  goto <D.20590>;
  <D.20593>:
  *system_name = 2;
  goto <D.20590>;
  <D.20594>:
  *system_name = 9;
  goto <D.20590>;
  <D.20595>:
  *system_name = 5;
  goto <D.20590>;
  <D.20596>:
  *system_name = 6;
  goto <D.20590>;
  <D.20597>:
  *system_name = 13;
  goto <D.20590>;
  <D.20598>:
  *system_name = 10;
  goto <D.20590>;
  <D.20599>:
  *system_name = 7;
  goto <D.20590>;
  <D.20600>:
  *system_name = 8;
  goto <D.20590>;
  <D.20601>:
  *system_name = 19;
  goto <D.20590>;
  <D.20602>:
  *system_name = 18;
  goto <D.20590>;
  <D.20603>:
  *system_name = 21;
  goto <D.20590>;
  <D.20604>:
  *system_name = 20;
  goto <D.20590>;
  <D.20605>:
  *system_name = 4;
  goto <D.20590>;
  <D.20606>:
  *system_name = 3;
  goto <D.20590>;
  <D.20607>:
  *system_name = 17;
  goto <D.20590>;
  <D.20608>:
  <D.20609>:
  <D.20610>:
  *system_name = 128;
  goto <D.20590>;
  <D.20611>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at Socket level", mono_name);
  D.21926 = -1;
  return D.21926;
  <D.20590>:
  goto <D.20612>;
  <D.20613>:
  *system_level = 0;
  switch (mono_name) <default: <D.20630>, case 1: <D.20614>, case 2: <D.20616>, case 3: <D.20617>, case 4: <D.20618>, case 9: <D.20619>, case 10: <D.20620>, case 11: <D.20621>, case 12: <D.20622>, case 13: <D.20623>, case 14: <D.20625>, case 15: <D.20626>, case 16: <D.20627>, case 17: <D.20628>, case 18: <D.20629>, case 19: <D.20624>>
  <D.20614>:
  *system_name = 4;
  goto <D.20615>;
  <D.20616>:
  *system_name = 3;
  goto <D.20615>;
  <D.20617>:
  *system_name = 1;
  goto <D.20615>;
  <D.20618>:
  *system_name = 2;
  goto <D.20615>;
  <D.20619>:
  *system_name = 32;
  goto <D.20615>;
  <D.20620>:
  *system_name = 33;
  goto <D.20615>;
  <D.20621>:
  *system_name = 34;
  goto <D.20615>;
  <D.20622>:
  *system_name = 35;
  goto <D.20615>;
  <D.20623>:
  *system_name = 36;
  goto <D.20615>;
  <D.20624>:
  *system_name = 8;
  goto <D.20615>;
  <D.20625>:
  *system_name = 10;
  goto <D.20615>;
  <D.20626>:
  <D.20627>:
  <D.20628>:
  <D.20629>:
  <D.20630>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IP level", mono_name);
  D.21926 = -1;
  return D.21926;
  <D.20615>:
  goto <D.20612>;
  <D.20631>:
  *system_level = 41;
  switch (mono_name) <default: <D.20649>, case 1: <D.20642>, case 2: <D.20641>, case 3: <D.20643>, case 4: <D.20632>, case 9: <D.20635>, case 10: <D.20636>, case 11: <D.20637>, case 12: <D.20638>, case 13: <D.20639>, case 14: <D.20644>, case 15: <D.20645>, case 16: <D.20646>, case 17: <D.20647>, case 18: <D.20648>, case 19: <D.20640>, case 21: <D.20633>>
  <D.20632>:
  <D.20633>:
  *system_name = 16;
  goto <D.20634>;
  <D.20635>:
  *system_name = 17;
  goto <D.20634>;
  <D.20636>:
  *system_name = 18;
  goto <D.20634>;
  <D.20637>:
  *system_name = 19;
  goto <D.20634>;
  <D.20638>:
  *system_name = 20;
  goto <D.20634>;
  <D.20639>:
  *system_name = 21;
  goto <D.20634>;
  <D.20640>:
  *system_name = 50;
  goto <D.20634>;
  <D.20641>:
  <D.20642>:
  <D.20643>:
  <D.20644>:
  <D.20645>:
  <D.20646>:
  <D.20647>:
  <D.20648>:
  <D.20649>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at IPv6 level", mono_name);
  D.21926 = -1;
  return D.21926;
  <D.20634>:
  goto <D.20612>;
  <D.20650>:
  if (1 != 0) goto <D.21927>; else goto <D.21928>;
  <D.21927>:
  {
    static int cached = 0;
    static int proto;

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

      pent = getprotobyname ("TCP");
      if (pent != 0B) goto <D.21933>; else goto <D.21934>;
      <D.21933>:
      iftmp.66 = pent->p_proto;
      goto <D.21935>;
      <D.21934>:
      iftmp.66 = 6;
      <D.21935>:
      proto = iftmp.66;
      cached = 1;
    }
    <D.21931>:
    proto.67 = proto;
    *system_level = proto.67;
  }
  <D.21928>:
  switch (mono_name) <default: <D.20656>, case 1: <D.20654>>
  <D.20654>:
  *system_name = 1;
  goto <D.20655>;
  <D.20656>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at TCP level", mono_name);
  D.21926 = -1;
  return D.21926;
  <D.20655>:
  goto <D.20612>;
  <D.20657>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unsupported value 0x%x", mono_level);
  switch (mono_name) <default: <D.20660>, case 1: <D.20658>, case 20: <D.20659>>
  <D.20658>:
  <D.20659>:
  <D.20660>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionName 0x%x is not supported at UDP level", mono_name);
  D.21926 = -1;
  return D.21926;
  D.21926 = -1;
  return D.21926;
  <D.20661>:
  monoeg_g_log (0B, 16, "System.Net.Sockets.SocketOptionLevel has unknown value 0x%x", mono_level);
  D.21926 = -1;
  return D.21926;
  <D.20612>:
  D.21926 = 0;
  return D.21926;
}


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

  D.21940 = mono_get_int32_class ();
  D.21939 = mono_value_box (domain, D.21940, &val);
  return D.21939;
}


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.21947;
  unsigned int valsize.69;
  int system_level.70;
  int system_name.71;
  int D.21953;
  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.21943>; else goto <D.21944>;
      <D.21943>:
      *error = 10042;
      return;
      <D.21944>:
      if (ret == -2) goto <D.21945>; else goto <D.21946>;
      <D.21945>:
      return;
      <D.21946>:
      D.21947 = *byte_val;
      valsize.69 = mono_array_length (D.21947);
      valsize = valsize.69;
      D.21947 = *byte_val;
      buf = mono_array_addr_with_size (D.21947, 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.21951>; else goto <D.21952>;
      <D.21951>:
      D.21953 = WSAGetLastError ();
      *error = D.21953;
      <D.21952>:
    }
  finally
    {
      system_level = {CLOBBER};
      system_name = {CLOBBER};
      valsize = {CLOBBER};
    }
}


ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal (SOCKET sock, gint32 level, gint32 name, struct MonoObject * obj_val, struct MonoArray * byte_val, gint32 int_val, gint32 * error)
{
  <unnamed type> level.72;
  _Bool D.21958;
  _Bool D.21959;
  _Bool D.21960;
  int int_val.73;
  _Bool D.21964;
  int int_val.74;
  struct MonoVTable * D.21972;
  struct MonoClass * D.21973;
  int D.21974;
  sizetype D.21975;
  guint8 * D.21976;
  unsigned char D.21977;
  int D.21978;
  guint32 * D.21979;
  unsigned int D.21980;
  int D.21981;
  int system_level.75;
  int system_name.76;
  unsigned int valsize.77;
  void * * D.21987;
  guint64 * D.21990;
  long long unsigned int D.21991;
  unsigned int D.21992;
  gint32 * D.22000;
  int D.22001;
  unsigned int D.22005;
  unsigned char D.22008;
  _Bool D.22009;
  int D.22010;
  unsigned int valsize.78;
  unsigned int int_val.79;
  unsigned int D.22015;
  unsigned int D.22016;
  unsigned int D.22017;
  unsigned int D.22018;
  unsigned int D.22019;
  unsigned int D.22020;
  unsigned int D.22021;
  unsigned int D.22022;
  unsigned int D.22023;
  int int_val.80;
  unsigned int D.22025;
  int D.22032;
  struct linger linger;
  int system_level;
  int system_name;
  int ret;
  int sol_ip;
  int sol_ipv6;

  try
    {
      *error = 0;
      sol_ipv6 = 41;
      sol_ip = 0;
      level.72 = (<unnamed type>) level;
      ret = convert_sockopt_level_and_name (level.72, name, &system_level, &system_name);
      D.21958 = level == 65535;
      D.21959 = name == -5;
      D.21960 = D.21958 & D.21959;
      if (D.21960 != 0) goto <D.21961>; else goto <D.21962>;
      <D.21961>:
      system_name = 2;
      int_val.73 = int_val;
      D.21964 = int_val.73 == 0;
      int_val.74 = (int) D.21964;
      int_val = int_val.74;
      ret = 0;
      <D.21962>:
      if (ret == -1) goto <D.21966>; else goto <D.21967>;
      <D.21966>:
      *error = 10042;
      return;
      <D.21967>:
      if (ret == -2) goto <D.21968>; else goto <D.21969>;
      <D.21968>:
      return;
      <D.21969>:
      if (obj_val != 0B) goto <D.21970>; else goto <D.21971>;
      <D.21970>:
      {
        struct MonoClassField * field;
        int valsize;

        switch (name) <default: <D.21093>, case 12: <D.21088>, case 13: <D.21089>, case 128: <D.21086>>
        <D.21086>:
        D.21972 = obj_val->vtable;
        D.21973 = D.21972->klass;
        field = mono_class_get_field_from_name (D.21973, "enabled");
        D.21974 = field->offset;
        D.21975 = (sizetype) D.21974;
        D.21976 = obj_val + D.21975;
        D.21977 = *D.21976;
        D.21978 = (int) D.21977;
        linger.l_onoff = D.21978;
        D.21972 = obj_val->vtable;
        D.21973 = D.21972->klass;
        field = mono_class_get_field_from_name (D.21973, "seconds");
        D.21974 = field->offset;
        D.21975 = (sizetype) D.21974;
        D.21979 = obj_val + D.21975;
        D.21980 = *D.21979;
        D.21981 = (int) D.21980;
        linger.l_linger = D.21981;
        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.21087>;
        <D.21088>:
        <D.21089>:
        {
          struct MonoObject * address;

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

            try
              {
                D.21972 = obj_val->vtable;
                D.21973 = D.21972->klass;
                field = mono_class_get_field_from_name (D.21973, "group");
                D.21974 = field->offset;
                D.21975 = (sizetype) D.21974;
                D.21987 = obj_val + D.21975;
                address = *D.21987;
                if (address != 0B) goto <D.21988>; else goto <D.21989>;
                <D.21988>:
                mreq6.ipv6mr_multiaddr = ipaddress_to_struct_in6_addr (address);
                <D.21989>:
                D.21972 = obj_val->vtable;
                D.21973 = D.21972->klass;
                field = mono_class_get_field_from_name (D.21973, "ifIndex");
                D.21974 = field->offset;
                D.21975 = (sizetype) D.21974;
                D.21990 = obj_val + D.21975;
                D.21991 = *D.21990;
                D.21992 = (unsigned int) D.21991;
                mreq6.ipv6mr_interface = D.21992;
                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.21993>;
          <D.21986>:
          system_level.75 = system_level;
          if (system_level.75 == sol_ip) goto <D.21994>; else goto <D.21995>;
          <D.21994>:
          {
            struct ip_mreqn mreq;

            try
              {
                mreq = {};
                D.21972 = obj_val->vtable;
                D.21973 = D.21972->klass;
                field = mono_class_get_field_from_name (D.21973, "group");
                D.21974 = field->offset;
                D.21975 = (sizetype) D.21974;
                D.21987 = obj_val + D.21975;
                address = *D.21987;
                if (address != 0B) goto <D.21996>; else goto <D.21997>;
                <D.21996>:
                mreq.imr_multiaddr = ipaddress_to_struct_in_addr (address);
                <D.21997>:
                D.21972 = obj_val->vtable;
                D.21973 = D.21972->klass;
                field = mono_class_get_field_from_name (D.21973, "local");
                D.21974 = field->offset;
                D.21975 = (sizetype) D.21974;
                D.21987 = obj_val + D.21975;
                address = *D.21987;
                if (address != 0B) goto <D.21998>; else goto <D.21999>;
                <D.21998>:
                mreq.imr_address = ipaddress_to_struct_in_addr (address);
                <D.21999>:
                D.21972 = obj_val->vtable;
                D.21973 = D.21972->klass;
                field = mono_class_get_field_from_name (D.21973, "iface_index");
                D.21974 = field->offset;
                D.21975 = (sizetype) D.21974;
                D.22000 = obj_val + D.21975;
                D.22001 = *D.22000;
                mreq.imr_ifindex = D.22001;
                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.21995>:
          <D.21993>:
          goto <D.21087>;
        }
        <D.21093>:
        *error = 10022;
        return;
        <D.21087>:
      }
      goto <D.22002>;
      <D.21971>:
      if (byte_val != 0B) goto <D.22003>; else goto <D.22004>;
      <D.22003>:
      {
        int valsize;
        guchar * buf;

        D.22005 = mono_array_length (byte_val);
        valsize = (int) D.22005;
        buf = mono_array_addr_with_size (byte_val, 1, 0);
        switch (name) <default: <D.21098>, case -129: <D.21096>>
        <D.21096>:
        if (valsize == 1) goto <D.22006>; else goto <D.22007>;
        <D.22006>:
        D.22008 = *buf;
        D.22009 = D.22008 == 0;
        D.22010 = (int) D.22009;
        linger.l_onoff = D.22010;
        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.22011>;
        <D.22007>:
        *error = 10022;
        <D.22011>:
        goto <D.21097>;
        <D.21098>:
        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.21097>;
        <D.21097>:
      }
      goto <D.22013>;
      <D.22004>:
      switch (name) <default: <D.21104>, case -129: <D.21099>, case 9: <D.21101>, case 14: <D.21103>>
      <D.21099>:
      int_val.73 = int_val;
      D.21964 = int_val.73 == 0;
      int_val.74 = (int) D.21964;
      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.21100>;
      <D.21101>:
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22015 = int_val.79 << 24;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22016 = int_val.79 & 16711680;
      D.22017 = D.22016 >> 8;
      D.22018 = D.22015 | D.22017;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22019 = int_val.79 & 65280;
      D.22020 = D.22019 << 8;
      D.22021 = D.22018 | D.22020;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22022 = int_val.79 >> 24;
      D.22023 = D.22021 | D.22022;
      int_val.80 = (int) D.22023;
      int_val = int_val.80;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22025 = int_val.79 & 4278190080;
      if (D.22025 == 0) goto <D.22026>; else goto <D.22027>;
      <D.22026>:
      {
        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.21100>;
          }
        finally
          {
            mreq = {CLOBBER};
          }
      }
      <D.22027>:
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22015 = int_val.79 << 24;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22016 = int_val.79 & 16711680;
      D.22017 = D.22016 >> 8;
      D.22018 = D.22015 | D.22017;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22019 = int_val.79 & 65280;
      D.22020 = D.22019 << 8;
      D.22021 = D.22018 | D.22020;
      int_val.73 = int_val;
      int_val.79 = (unsigned int) int_val.73;
      D.22022 = int_val.79 >> 24;
      D.22023 = D.22021 | D.22022;
      int_val.80 = (int) D.22023;
      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.21100>;
      <D.21103>:
      int_val.73 = int_val;
      if (int_val.73 == 1) goto <D.22028>; else goto <D.22029>;
      <D.22028>:
      int_val = 2;
      <D.22029>:
      <D.21104>:
      system_level.75 = system_level;
      system_name.76 = system_name;
      ret = _wapi_setsockopt (sock, system_level.75, system_name.76, &int_val, 4);
      <D.21100>:
      <D.22013>:
      <D.22002>:
      if (ret == -1) goto <D.22030>; else goto <D.22031>;
      <D.22030>:
      D.22032 = WSAGetLastError ();
      *error = D.22032;
      <D.22031>:
    }
  finally
    {
      linger = {CLOBBER};
      system_level = {CLOBBER};
      system_name = {CLOBBER};
    }
}


ipaddress_to_struct_in6_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.22038;
  struct MonoClass * D.22039;
  int D.22040;
  sizetype D.22041;
  struct MonoArray * * D.22042;
  unsigned int i.81;
  char * D.22044;
  short unsigned int D.22045;
  struct in6_addr in6addr;
  struct MonoClassField * field;
  struct MonoArray * data;
  int i;

  try
    {
      D.22038 = ipaddr->vtable;
      D.22039 = D.22038->klass;
      field = mono_class_get_field_from_name (D.22039, "m_Numbers");
      D.22040 = field->offset;
      D.22041 = (sizetype) D.22040;
      D.22042 = ipaddr + D.22041;
      data = *D.22042;
      i = 0;
      goto <D.21067>;
      <D.21066>:
      i.81 = (unsigned int) i;
      D.22044 = mono_array_addr_with_size (data, 2, i.81);
      D.22045 = MEM[(guint16 *)D.22044];
      in6addr.__in6_u.__u6_addr16[i] = D.22045;
      i = i + 1;
      <D.21067>:
      if (i <= 7) goto <D.21066>; else goto <D.21068>;
      <D.21068>:
      <retval> = in6addr;
      return <retval>;
    }
  finally
    {
      in6addr = {CLOBBER};
    }
}


ipaddress_to_struct_in_addr (struct MonoObject * ipaddr)
{
  struct MonoVTable * D.22048;
  struct MonoClass * D.22049;
  int D.22050;
  sizetype D.22051;
  guint64 * D.22052;
  long long unsigned int D.22053;
  unsigned int D.22054;
  struct in_addr D.22055;
  struct in_addr inaddr;
  struct MonoClassField * field;

  try
    {
      D.22048 = ipaddr->vtable;
      D.22049 = D.22048->klass;
      field = mono_class_get_field_from_name (D.22049, "m_Address");
      D.22050 = field->offset;
      D.22051 = (sizetype) D.22050;
      D.22052 = ipaddr + D.22051;
      D.22053 = *D.22052;
      D.22054 = (unsigned int) D.22053;
      inaddr.s_addr = D.22054;
      D.22055 = inaddr;
      return D.22055;
    }
  finally
    {
      inaddr = {CLOBBER};
    }
}


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

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


ves_icall_System_Net_Sockets_Socket_WSAIoctl (SOCKET sock, gint32 code, struct MonoArray * input, struct MonoArray * output, gint32 * error)
{
  int D.22063;
  unsigned int D.22067;
  unsigned int D.22071;
  int D.22074;
  glong output_bytes;
  gchar * i_buffer;
  gchar * o_buffer;
  gint i_len;
  gint o_len;
  gint ret;

  try
    {
      output_bytes = 0;
      *error = 0;
      if (code == 21537) goto <D.22061>; else goto <D.22062>;
      <D.22061>:
      D.22063 = -1;
      return D.22063;
      <D.22062>:
      if (input == 0B) goto <D.22064>; else goto <D.22065>;
      <D.22064>:
      i_buffer = 0B;
      i_len = 0;
      goto <D.22066>;
      <D.22065>:
      i_buffer = mono_array_addr_with_size (input, 1, 0);
      D.22067 = mono_array_length (input);
      i_len = (gint) D.22067;
      <D.22066>:
      if (output == 0B) goto <D.22068>; else goto <D.22069>;
      <D.22068>:
      o_buffer = 0B;
      o_len = 0;
      goto <D.22070>;
      <D.22069>:
      o_buffer = mono_array_addr_with_size (output, 1, 0);
      D.22071 = mono_array_length (output);
      o_len = (gint) D.22071;
      <D.22070>:
      ret = WSAIoctl (sock, code, i_buffer, i_len, o_buffer, o_len, &output_bytes, 0B, 0B);
      if (ret == -1) goto <D.22072>; else goto <D.22073>;
      <D.22072>:
      D.22074 = WSAGetLastError ();
      *error = D.22074;
      D.22063 = -1;
      return D.22063;
      <D.22073>:
      D.22063 = output_bytes;
      return D.22063;
    }
  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.22077;
  int D.22082;
  int D.21217;
  int D.22087;
  int D.22090;
  MonoBoolean D.22093;
  struct addrinfo * info.82;
  int D.22095;
  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.22077 = *hostname;
      if (D.22077 == 0) goto <D.22078>; else goto <D.22079>;
      <D.22078>:
      add_local_ips = 1;
      *h_name = host;
      <D.22079>:
      if (add_local_ips == 0) goto <D.22080>; else goto <D.22081>;
      <D.22080>:
      D.22082 = gethostname (&this_hostname, 256);
      if (D.22082 != -1) goto <D.22083>; else goto <D.22084>;
      <D.22083>:
      {
        size_t __s1_len;
        size_t __s2_len;

        D.21217 = __builtin_strcmp (hostname, &this_hostname);
      }
      if (D.21217 == 0) goto <D.22085>; else goto <D.22086>;
      <D.22085>:
      add_local_ips = 1;
      *h_name = host;
      <D.22086>:
      <D.22084>:
      <D.22081>:
      memset (&hints, 0, 32);
      D.22087 = get_family_hint ();
      hints.ai_family = D.22087;
      hints.ai_socktype = 1;
      hints.ai_flags = 2;
      D.22077 = *hostname;
      if (D.22077 != 0) goto <D.22088>; else goto <D.22089>;
      <D.22088>:
      D.22090 = getaddrinfo (hostname, 0B, &hints, &info);
      if (D.22090 == -1) goto <D.22091>; else goto <D.22092>;
      <D.22091>:
      D.22093 = 0;
      return D.22093;
      <D.22092>:
      <D.22089>:
      monoeg_g_free (hostname);
      info.82 = info;
      D.22095 = addrinfo_to_IPHostEntry (info.82, h_name, h_aliases, h_addr_list, add_local_ips);
      D.22093 = (MonoBoolean) D.22095;
      return D.22093;
    }
  finally
    {
      this_hostname = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
    }
}


gethostname (char * __buf, size_t __buflen)
{
  unsigned int D.22098;
  int D.22101;
  int D.22104;
  unsigned int D.22105;
  unsigned int D.22106;
  unsigned int D.22109;

  D.22098 = __builtin_object_size (__buf, 1);
  if (D.22098 != 4294967295) goto <D.22099>; else goto <D.22100>;
  <D.22099>:
  D.22101 = __builtin_constant_p (__buflen);
  if (D.22101 == 0) goto <D.22102>; else goto <D.22103>;
  <D.22102>:
  D.22105 = __builtin_object_size (__buf, 1);
  D.22104 = __gethostname_chk (__buf, __buflen, D.22105);
  return D.22104;
  <D.22103>:
  D.22106 = __builtin_object_size (__buf, 1);
  if (D.22106 < __buflen) goto <D.22107>; else goto <D.22108>;
  <D.22107>:
  D.22109 = __builtin_object_size (__buf, 1);
  D.22104 = __gethostname_chk_warn (__buf, __buflen, D.22109);
  return D.22104;
  <D.22108>:
  <D.22100>:
  D.22104 = __gethostname_alias (__buf, __buflen);
  return D.22104;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.22113;
  int D.22118;
  void * D.22120;
  unsigned int D.22121;

  D.22113 = __builtin_constant_p (__len);
  if (D.22113 != 0) goto <D.22114>; else goto <D.22115>;
  <D.22114>:
  if (__len == 0) goto <D.22116>; else goto <D.22117>;
  <D.22116>:
  D.22118 = __builtin_constant_p (__ch);
  if (D.22118 == 0) goto <D.22111>; else goto <D.22119>;
  <D.22119>:
  if (__ch != 0) goto <D.22111>; else goto <D.22112>;
  <D.22111>:
  __warn_memset_zero_len ();
  D.22120 = __dest;
  return D.22120;
  <D.22112>:
  <D.22117>:
  <D.22115>:
  D.22121 = __builtin_object_size (__dest, 0);
  D.22120 = __builtin___memset_chk (__dest, __ch, __len, D.22121);
  return D.22120;
}


get_family_hint ()
{
  unsigned char D.22123;
  struct MonoImage * D.22126;
  struct MonoDomain * D.22127;
  _Bool D.22128;
  long int D.22129;
  long int D.22130;
  union mono_mutex_t * D.22133;
  _Bool D.22136;
  long int D.22137;
  long int D.22138;
  int ipv4_enabled.83;
  int ipv6_enabled.84;
  _Bool D.22152;
  long int D.22153;
  long int D.22154;
  int D.22157;
  gint32 D.22158;
  struct MonoDomain * domain;

  domain = mono_domain_get ();
  D.22123 = domain->inet_family_hint;
  if (D.22123 == 0) goto <D.22124>; else goto <D.22125>;
  <D.22124>:
  {
    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.22126 = get_socket_assembly ();
        socket_class = mono_class_from_name (D.22126, "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.22127 = mono_domain_get ();
        vtable = mono_class_vtable (D.22127, socket_class);
        D.22128 = vtable == 0B;
        D.22129 = (long int) D.22128;
        D.22130 = __builtin_expect (D.22129, 0);
        if (D.22130 != 0) goto <D.22131>; else goto <D.22132>;
        <D.22131>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 715, "vtable");
        <D.22132>:
        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.22133 = &domain->lock.mutex;
          ret = pthread_mutex_lock (D.22133);
          if (ret != 0) goto <D.22134>; else goto <D.22135>;
          <D.22134>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d", ret);
          <D.22135>:
          D.22136 = ret != 0;
          D.22137 = (long int) D.22136;
          D.22138 = __builtin_expect (D.22137, 0);
          if (D.22138 != 0) goto <D.22139>; else goto <D.22140>;
          <D.22139>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 721, "ret == 0");
          <D.22140>:
        }
        ipv4_enabled.83 = ipv4_enabled;
        if (ipv4_enabled.83 == 1) goto <D.22144>; else goto <D.22141>;
        <D.22144>:
        ipv6_enabled.84 = ipv6_enabled;
        if (ipv6_enabled.84 == 1) goto <D.22146>; else goto <D.22141>;
        <D.22146>:
        domain->inet_family_hint = 1;
        goto <D.22142>;
        <D.22141>:
        ipv4_enabled.83 = ipv4_enabled;
        if (ipv4_enabled.83 == 1) goto <D.22147>; else goto <D.22148>;
        <D.22147>:
        domain->inet_family_hint = 2;
        goto <D.22149>;
        <D.22148>:
        domain->inet_family_hint = 3;
        <D.22149>:
        <D.22142>:
        {
          int ret;

          D.22133 = &domain->lock.mutex;
          ret = pthread_mutex_unlock (D.22133);
          if (ret != 0) goto <D.22150>; else goto <D.22151>;
          <D.22150>:
          monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d", ret);
          <D.22151>:
          D.22152 = ret != 0;
          D.22153 = (long int) D.22152;
          D.22154 = __builtin_expect (D.22153, 0);
          if (D.22154 != 0) goto <D.22155>; else goto <D.22156>;
          <D.22155>:
          monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "socket-io.c", 729, "ret == 0");
          <D.22156>:
        }
      }
    finally
      {
        ipv6_enabled = {CLOBBER};
        ipv4_enabled = {CLOBBER};
      }
  }
  <D.22125>:
  D.22123 = domain->inet_family_hint;
  D.22157 = (int) D.22123;
  switch (D.22157) <default: <D.20683>, case 1: <D.20680>, case 2: <D.20681>, case 3: <D.20682>>
  <D.20680>:
  D.22158 = 0;
  return D.22158;
  <D.20681>:
  D.22158 = 2;
  return D.22158;
  <D.20682>:
  D.22158 = 10;
  return D.22158;
  <D.20683>:
  D.22158 = 0;
  return D.22158;
}


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.22160;
  struct MonoArray * D.22161;
  int nlocal_in.85;
  int nlocal_in6.86;
  struct MonoClass * D.22169;
  int D.22170;
  unsigned int D.22171;
  struct MonoArray * D.22172;
  unsigned int i.87;
  unsigned int D.22176;
  struct in_addr * D.22177;
  struct MonoArray * D.22178;
  unsigned int addr_index.88;
  unsigned int i.89;
  unsigned int D.22183;
  struct in6_addr * D.22184;
  gboolean D.22189;
  int D.22190;
  _Bool D.22191;
  _Bool D.22192;
  _Bool D.22193;
  struct MonoClass * D.22196;
  unsigned int count.90;
  struct MonoArray * D.22198;
  int D.22199;
  _Bool D.22200;
  _Bool D.22201;
  _Bool D.22202;
  int D.22205;
  struct sockaddr * D.22208;
  struct in_addr * D.22209;
  struct in6_addr * D.22211;
  char * D.22217;
  struct MonoString * D.22220;
  struct MonoString * D.22222;
  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.22160 = mono_get_string_class ();
      D.22161 = mono_array_new (domain, D.22160, 0);
      *h_aliases = D.22161;
      if (add_local_ips != 0) goto <D.22162>; else goto <D.22163>;
      <D.22162>:
      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.22164>; else goto <D.22167>;
      <D.22167>:
      nlocal_in6.86 = nlocal_in6;
      if (nlocal_in6.86 != 0) goto <D.22164>; else goto <D.22165>;
      <D.22164>:
      D.22169 = mono_get_string_class ();
      nlocal_in.85 = nlocal_in;
      nlocal_in6.86 = nlocal_in6;
      D.22170 = nlocal_in.85 + nlocal_in6.86;
      D.22171 = (unsigned int) D.22170;
      D.22172 = mono_array_new (domain, D.22169, D.22171);
      *h_addr_list = D.22172;
      nlocal_in.85 = nlocal_in;
      if (nlocal_in.85 != 0) goto <D.22173>; else goto <D.22174>;
      <D.22173>:
      {
        struct MonoString * addr_string;
        char addr[16];
        int i;

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

              D.22178 = *h_addr_list;
              addr_index.88 = (unsigned int) addr_index;
              __p = mono_array_addr_with_size (D.22178, 4, addr_index.88);
              D.22178 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.22178, __p, addr_string);
            }
            addr_index = addr_index + 1;
            i = i + 1;
            <D.21176>:
            nlocal_in.85 = nlocal_in;
            if (i < nlocal_in.85) goto <D.21175>; else goto <D.21177>;
            <D.21177>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.22174>:
      nlocal_in6.86 = nlocal_in6;
      if (nlocal_in6.86 != 0) goto <D.22180>; else goto <D.22181>;
      <D.22180>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char addr[48];
        int i;

        try
          {
            i = 0;
            goto <D.21184>;
            <D.21183>:
            i.89 = (unsigned int) i;
            D.22183 = i.89 * 16;
            D.22184 = local_in6 + D.22183;
            ret = inet_ntop (10, D.22184, &addr, 48);
            if (ret != 0B) goto <D.22185>; else goto <D.22186>;
            <D.22185>:
            addr_string = mono_string_new (domain, &addr);
            {
              void * * __p;

              D.22178 = *h_addr_list;
              addr_index.88 = (unsigned int) addr_index;
              __p = mono_array_addr_with_size (D.22178, 4, addr_index.88);
              D.22178 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.22178, __p, addr_string);
            }
            addr_index = addr_index + 1;
            <D.22186>:
            i = i + 1;
            <D.21184>:
            nlocal_in6.86 = nlocal_in6;
            if (i < nlocal_in6.86) goto <D.21183>; else goto <D.21185>;
            <D.21185>:
          }
        finally
          {
            addr = {CLOBBER};
          }
      }
      <D.22181>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      if (info != 0B) goto <D.22187>; else goto <D.22188>;
      <D.22187>:
      freeaddrinfo (info);
      <D.22188>:
      D.22189 = 1;
      return D.22189;
      <D.22165>:
      monoeg_g_free (local_in);
      monoeg_g_free (local_in6);
      <D.22163>:
      count = 0;
      ai = info;
      goto <D.21188>;
      <D.21187>:
      D.22190 = ai->ai_family;
      D.22191 = D.22190 != 2;
      D.22192 = D.22190 != 10;
      D.22193 = D.22191 & D.22192;
      if (D.22193 != 0) goto <D.22194>; else goto <D.22195>;
      <D.22194>:
      // predicted unlikely by continue predictor.
      goto <D.21186>;
      <D.22195>:
      count = count + 1;
      <D.21186>:
      ai = ai->ai_next;
      <D.21188>:
      if (ai != 0B) goto <D.21187>; else goto <D.21189>;
      <D.21189>:
      D.22196 = mono_get_string_class ();
      count.90 = (unsigned int) count;
      D.22198 = mono_array_new (domain, D.22196, count.90);
      *h_addr_list = D.22198;
      ai = info;
      i = 0;
      goto <D.21196>;
      <D.21195>:
      {
        struct MonoString * addr_string;
        const char * ret;
        char buffer[48];

        try
          {
            D.22199 = ai->ai_family;
            D.22200 = D.22199 != 2;
            D.22201 = D.22199 != 10;
            D.22202 = D.22200 & D.22201;
            if (D.22202 != 0) goto <D.22203>; else goto <D.22204>;
            <D.22203>:
            // predicted unlikely by continue predictor.
            goto <D.21193>;
            <D.22204>:
            D.22205 = ai->ai_family;
            if (D.22205 == 2) goto <D.22206>; else goto <D.22207>;
            <D.22206>:
            D.22205 = ai->ai_family;
            D.22208 = ai->ai_addr;
            D.22209 = &MEM[(struct sockaddr_in *)D.22208].sin_addr;
            ret = inet_ntop (D.22205, D.22209, &buffer, 16);
            goto <D.22210>;
            <D.22207>:
            D.22205 = ai->ai_family;
            D.22208 = ai->ai_addr;
            D.22211 = &MEM[(struct sockaddr_in6 *)D.22208].sin6_addr;
            ret = inet_ntop (D.22205, D.22211, &buffer, 48);
            <D.22210>:
            if (ret != 0B) goto <D.22212>; else goto <D.22213>;
            <D.22212>:
            addr_string = mono_string_new (domain, &buffer);
            goto <D.22214>;
            <D.22213>:
            addr_string = mono_string_new (domain, "");
            <D.22214>:
            {
              void * * __p;

              D.22178 = *h_addr_list;
              addr_index.88 = (unsigned int) addr_index;
              __p = mono_array_addr_with_size (D.22178, 4, addr_index.88);
              D.22178 = *h_addr_list;
              mono_gc_wbarrier_set_arrayref (D.22178, __p, addr_string);
            }
            if (i == 0) goto <D.22215>; else goto <D.22216>;
            <D.22215>:
            i = i + 1;
            D.22217 = ai->ai_canonname;
            if (D.22217 != 0B) goto <D.22218>; else goto <D.22219>;
            <D.22218>:
            D.22217 = ai->ai_canonname;
            D.22220 = mono_string_new (domain, D.22217);
            *h_name = D.22220;
            goto <D.22221>;
            <D.22219>:
            D.22222 = mono_string_new (domain, &buffer);
            *h_name = D.22222;
            <D.22221>:
            <D.22216>:
            addr_index = addr_index + 1;
          }
        finally
          {
            buffer = {CLOBBER};
          }
      }
      <D.21193>:
      ai = ai->ai_next;
      <D.21196>:
      if (ai != 0B) goto <D.21195>; else goto <D.21197>;
      <D.21197>:
      if (info != 0B) goto <D.22223>; else goto <D.22224>;
      <D.22223>:
      freeaddrinfo (info);
      <D.22224>:
      D.22189 = 1;
      return D.22189;
    }
  finally
    {
      nlocal_in = {CLOBBER};
      nlocal_in6 = {CLOBBER};
    }
}


get_local_ips (int family, int * nips)
{
  void * D.22235;
  unsigned int max_ifaces.91;
  unsigned int D.22237;
  int D.22238;
  int D.22239;
  unsigned int D.22240;
  void * D.22241;
  int D.22242;
  char * D.22245;
  unsigned int D.22246;
  unsigned int D.22247;
  char[16] * D.22250;
  int D.22251;
  short int D.22254;
  unsigned short D.22255;
  int D.22256;
  int D.22257;
  int D.22260;
  int D.22263;
  int D.22264;
  unsigned int D.22265;
  char D.22266;
  int D.22269;
  struct sockaddr * D.22272;
  sizetype offset.92;
  void * D.22274;
  int D.22275;
  char * D.22278;
  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.22229>; else goto <D.22230>;
      <D.22229>:
      addr_size = 4;
      offset = 4;
      goto <D.22231>;
      <D.22230>:
      if (family == 10) goto <D.22232>; else goto <D.22233>;
      <D.22232>:
      addr_size = 16;
      offset = 8;
      goto <D.22234>;
      <D.22233>:
      D.22235 = 0B;
      return D.22235;
      <D.22234>:
      <D.22231>:
      fd = socket (family, 1, 0);
      max_ifaces.91 = (unsigned int) max_ifaces;
      D.22237 = max_ifaces.91 * 32;
      D.22238 = (int) D.22237;
      ifc.ifc_len = D.22238;
      D.22239 = ifc.ifc_len;
      D.22240 = (unsigned int) D.22239;
      D.22241 = monoeg_malloc (D.22240);
      ifc.ifc_ifcu.ifcu_buf = D.22241;
      D.22242 = ioctl (fd, 35090, &ifc);
      if (D.22242 < 0) goto <D.22243>; else goto <D.22244>;
      <D.22243>:
      close (fd);
      D.22245 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.22245);
      D.22235 = 0B;
      return D.22235;
      <D.22244>:
      D.22239 = ifc.ifc_len;
      D.22246 = (unsigned int) D.22239;
      D.22247 = D.22246 / 32;
      count = (int) D.22247;
      *nips = count;
      if (count == 0) goto <D.22248>; else goto <D.22249>;
      <D.22248>:
      D.22245 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.22245);
      close (fd);
      D.22235 = 0B;
      return D.22235;
      <D.22249>:
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.21149>;
      <D.21148>:
      D.22250 = &ifr->ifr_ifrn.ifrn_name;
      strcpy (&iflags.ifr_ifrn.ifrn_name, D.22250);
      D.22251 = ioctl (fd, 35091, &iflags);
      if (D.22251 < 0) goto <D.22252>; else goto <D.22253>;
      <D.22252>:
      // predicted unlikely by continue predictor.
      goto <D.21147>;
      <D.22253>:
      D.22254 = iflags.ifr_ifru.ifru_flags;
      D.22255 = (unsigned short) D.22254;
      D.22256 = (int) D.22255;
      D.22257 = D.22256 & 1;
      if (D.22257 == 0) goto <D.22258>; else goto <D.22259>;
      <D.22258>:
      ifr->ifr_ifrn.ifrn_name[0] = 0;
      // predicted unlikely by continue predictor.
      goto <D.21147>;
      <D.22259>:
      D.22254 = iflags.ifr_ifru.ifru_flags;
      D.22255 = (unsigned short) D.22254;
      D.22256 = (int) D.22255;
      D.22260 = D.22256 & 8;
      if (D.22260 == 0) goto <D.22261>; else goto <D.22262>;
      <D.22261>:
      ignore_loopback = 1;
      <D.22262>:
      <D.21147>:
      i = i + 1;
      ifr = ifr + 32;
      <D.21149>:
      D.22263 = *nips;
      if (D.22263 > i) goto <D.21148>; else goto <D.21150>;
      <D.21150>:
      close (fd);
      D.22264 = addr_size * count;
      D.22265 = (unsigned int) D.22264;
      result = monoeg_malloc (D.22265);
      tmp_ptr = result;
      i = 0;
      ifr = ifc.ifc_ifcu.ifcu_req;
      goto <D.21153>;
      <D.21152>:
      D.22266 = ifr->ifr_ifrn.ifrn_name[0];
      if (D.22266 == 0) goto <D.22267>; else goto <D.22268>;
      <D.22267>:
      D.22263 = *nips;
      D.22269 = D.22263 + -1;
      *nips = D.22269;
      // predicted unlikely by continue predictor.
      goto <D.21151>;
      <D.22268>:
      if (ignore_loopback != 0) goto <D.22270>; else goto <D.22271>;
      <D.22270>:
      D.22272 = &ifr->ifr_ifru.ifru_addr;
      offset.92 = (sizetype) offset;
      D.22274 = D.22272 + offset.92;
      D.22275 = is_loopback (family, D.22274);
      if (D.22275 != 0) goto <D.22276>; else goto <D.22277>;
      <D.22276>:
      D.22263 = *nips;
      D.22269 = D.22263 + -1;
      *nips = D.22269;
      // predicted unlikely by continue predictor.
      goto <D.21151>;
      <D.22277>:
      <D.22271>:
      D.22272 = &ifr->ifr_ifru.ifru_addr;
      offset.92 = (sizetype) offset;
      D.22278 = D.22272 + offset.92;
      addr_size.93 = (unsigned int) addr_size;
      memcpy (tmp_ptr, D.22278, addr_size.93);
      addr_size.94 = (sizetype) addr_size;
      tmp_ptr = tmp_ptr + addr_size.94;
      <D.21151>:
      i = i + 1;
      ifr = ifr + 32;
      <D.21153>:
      if (i < count) goto <D.21152>; else goto <D.21154>;
      <D.21154>:
      D.22245 = ifc.ifc_ifcu.ifcu_buf;
      monoeg_g_free (D.22245);
      D.22235 = result;
      return D.22235;
    }
  finally
    {
      ifc = {CLOBBER};
      iflags = {CLOBBER};
    }
}


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

  D.22284 = __builtin_object_size (__dest, 1);
  D.22283 = __builtin___strcpy_chk (__dest, __src, D.22284);
  return D.22283;
}


is_loopback (int family, void * ad)
{
  gboolean D.22288;
  char D.22289;
  _Bool D.22290;
  int D.21130;
  int iftmp.95;
  unsigned int D.22294;
  unsigned int D.22296;
  unsigned int D.22298;
  unsigned int D.22300;
  unsigned int D.22301;
  char * ptr;

  ptr = ad;
  if (family == 2) goto <D.22286>; else goto <D.22287>;
  <D.22286>:
  D.22289 = *ptr;
  D.22290 = D.22289 == 127;
  D.22288 = (gboolean) D.22290;
  return D.22288;
  <D.22287>:
  {
    const struct in6_addr * __a;

    __a = ptr;
    D.22294 = __a->__in6_u.__u6_addr32[0];
    if (D.22294 == 0) goto <D.22295>; else goto <D.22292>;
    <D.22295>:
    D.22296 = __a->__in6_u.__u6_addr32[1];
    if (D.22296 == 0) goto <D.22297>; else goto <D.22292>;
    <D.22297>:
    D.22298 = __a->__in6_u.__u6_addr32[2];
    if (D.22298 == 0) goto <D.22299>; else goto <D.22292>;
    <D.22299>:
    D.22300 = __a->__in6_u.__u6_addr32[3];
    D.22301 = __bswap_32 (1);
    if (D.22300 == D.22301) goto <D.22302>; else goto <D.22292>;
    <D.22302>:
    iftmp.95 = 1;
    goto <D.22293>;
    <D.22292>:
    iftmp.95 = 0;
    <D.22293>:
    D.21130 = iftmp.95;
  }
  D.22288 = D.21130;
  return D.22288;
  D.22288 = 0;
  return D.22288;
}


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

  D.22305 = __builtin_object_size (__dest, 0);
  D.22304 = __builtin___memcpy_chk (__dest, __src, __len, D.22305);
  return D.22304;
}


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.22307;
  int D.22310;
  MonoBoolean D.22313;
  int D.22317;
  int D.22323;
  int D.22326;
  int D.22327;
  struct addrinfo * info.96;
  int D.22331;
  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.22307 = inet_pton (2, address, &saddr.sin_addr);
      if (D.22307 <= 0) goto <D.22308>; else goto <D.22309>;
      <D.22308>:
      D.22310 = inet_pton (10, address, &saddr6.sin6_addr);
      if (D.22310 <= 0) goto <D.22311>; else goto <D.22312>;
      <D.22311>:
      monoeg_g_free (address);
      D.22313 = 0;
      return D.22313;
      <D.22312>:
      family = 10;
      saddr6.sin6_family = 10;
      goto <D.22314>;
      <D.22309>:
      family = 2;
      saddr.sin_family = 2;
      <D.22314>:
      monoeg_g_free (address);
      if (family == 2) goto <D.22315>; else goto <D.22316>;
      <D.22315>:
      D.22317 = getnameinfo (&saddr, 16, &hostname, 1025, 0B, 0, flags);
      if (D.22317 != 0) goto <D.22318>; else goto <D.22319>;
      <D.22318>:
      D.22313 = 0;
      return D.22313;
      <D.22319>:
      goto <D.22320>;
      <D.22316>:
      if (family == 10) goto <D.22321>; else goto <D.22322>;
      <D.22321>:
      D.22323 = getnameinfo (&saddr6, 28, &hostname, 1025, 0B, 0, flags);
      if (D.22323 != 0) goto <D.22324>; else goto <D.22325>;
      <D.22324>:
      D.22313 = 0;
      return D.22313;
      <D.22325>:
      <D.22322>:
      <D.22320>:
      memset (&hints, 0, 32);
      D.22326 = get_family_hint ();
      hints.ai_family = D.22326;
      hints.ai_socktype = 1;
      hints.ai_flags = 34;
      D.22327 = getaddrinfo (&hostname, 0B, &hints, &info);
      if (D.22327 == -1) goto <D.22328>; else goto <D.22329>;
      <D.22328>:
      D.22313 = 0;
      return D.22313;
      <D.22329>:
      info.96 = info;
      D.22331 = addrinfo_to_IPHostEntry (info.96, h_name, h_aliases, h_addr_list, 0);
      D.22313 = (MonoBoolean) D.22331;
      return D.22313;
    }
  finally
    {
      saddr = {CLOBBER};
      saddr6 = {CLOBBER};
      info = {CLOBBER};
      hints = {CLOBBER};
      hostname = {CLOBBER};
    }
}


ves_icall_System_Net_Dns_GetHostName_internal (struct MonoString * * h_name)
{
  MonoBoolean D.22336;
  struct MonoDomain * D.22337;
  struct MonoString * D.22338;
  gchar hostname[256];
  int ret;

  try
    {
      ret = gethostname (&hostname, 256);
      if (ret == -1) goto <D.22334>; else goto <D.22335>;
      <D.22334>:
      D.22336 = 0;
      return D.22336;
      <D.22335>:
      D.22337 = mono_domain_get ();
      D.22338 = mono_string_new (D.22337, &hostname);
      *h_name = D.22338;
      D.22336 = 1;
      return D.22336;
    }
  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.22343;
  int error.97;
  unsigned int error.98;
  char * D.22350;
  unsigned int D.22351;
  char * D.22354;
  unsigned int D.22355;
  unsigned int flags.99;
  int D.22357;
  void * file;
  gint32 error;
  struct TRANSMIT_FILE_BUFFERS buffers;

  try
    {
      if (filename == 0B) goto <D.22341>; else goto <D.22342>;
      <D.22341>:
      D.22343 = 0;
      return D.22343;
      <D.22342>:
      file = ves_icall_System_IO_MonoIO_Open (filename, 3, 1, 1, 0, &error);
      if (file == 4294967295B) goto <D.22344>; else goto <D.22345>;
      <D.22344>:
      error.97 = error;
      error.98 = (unsigned int) error.97;
      SetLastError (error.98);
      D.22343 = 0;
      return D.22343;
      <D.22345>:
      memset (&buffers, 0, 16);
      if (pre_buffer != 0B) goto <D.22348>; else goto <D.22349>;
      <D.22348>:
      D.22350 = mono_array_addr_with_size (pre_buffer, 1, 0);
      buffers.Head = D.22350;
      D.22351 = mono_array_length (pre_buffer);
      buffers.HeadLength = D.22351;
      <D.22349>:
      if (post_buffer != 0B) goto <D.22352>; else goto <D.22353>;
      <D.22352>:
      D.22354 = mono_array_addr_with_size (post_buffer, 1, 0);
      buffers.Tail = D.22354;
      D.22355 = mono_array_length (post_buffer);
      buffers.TailLength = D.22355;
      <D.22353>:
      flags.99 = (unsigned int) flags;
      D.22357 = TransmitFile (sock, file, 0, 0, 0B, &buffers, flags.99);
      if (D.22357 == 0) goto <D.22358>; else goto <D.22359>;
      <D.22358>:
      CloseHandle (file);
      D.22343 = 0;
      return D.22343;
      <D.22359>:
      CloseHandle (file);
      D.22343 = 1;
      return D.22343;
    }
  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.22362>; else goto <D.22363>;
      <D.22362>:
      monoeg_g_log (0B, 4, "%s: Couldn\'t initialise networking", &__func__);
      <D.21253>:
      goto <D.21253>;
      exit (-1);
      <D.22363>:
    }
  finally
    {
      wsadata = {CLOBBER};
    }
}


mono_network_cleanup ()
{
  WSACleanup ();
}


icall_cancel_blocking_socket_operation (struct MonoThread * thread)
{
  int D.22364;
  long long unsigned int D.22367;
  long unsigned int D.22368;
  int D.22370;
  struct MonoInternalThread * internal;

  internal = thread->internal_thread;
  D.22364 = mono_thread_info_new_interrupt_enabled ();
  if (D.22364 != 0) goto <D.22365>; else goto <D.22366>;
  <D.22365>:
  D.22367 = internal->tid;
  D.22368 = (long unsigned int) D.22367;
  mono_thread_info_abort_socket_syscall_for_close (D.22368);
  goto <D.22369>;
  <D.22366>:
  internal->ignore_next_signal = 1;
  D.22370 = mono_thread_get_abort_signal ();
  mono_thread_kill (internal, D.22370);
  <D.22369>:
}


