mono_attach_parse_options (char * options)
{
  int D.17668;
  int iftmp.0;
  int D.17667;
  const char[8] * D.17758;
  unsigned char D.17759;
  int D.17760;
  unsigned char D.17761;
  int D.17762;
  _Bool D.17763;
  _Bool D.17764;
  _Bool D.17765;
  const unsigned char * D.17768;
  unsigned char D.17769;
  int D.17770;
  const unsigned char * D.17771;
  unsigned char D.17772;
  int D.17773;
  _Bool D.17774;
  _Bool D.17775;
  const unsigned char * D.17778;
  unsigned char D.17779;
  int D.17780;
  const unsigned char * D.17781;
  unsigned char D.17782;
  int D.17783;
  _Bool D.17784;
  _Bool D.17785;
  const unsigned char * D.17788;
  unsigned char D.17789;
  int D.17790;
  const unsigned char * D.17791;
  unsigned char D.17792;
  int D.17793;

  if (options == 0B) goto <D.17753>; else goto <D.17754>;
  <D.17753>:
  return;
  <D.17754>:
  {
    size_t __s1_len;
    size_t __s2_len;

    __s2_len = 7;
    if (__s2_len <= 3) goto <D.17756>; else goto <D.17757>;
    <D.17756>:
    {
      const unsigned char * __s2;
      int __result;

      __s2 = options;
      D.17758 = "disable";
      D.17759 = MEM[(const unsigned char *)D.17758];
      D.17760 = (int) D.17759;
      D.17761 = *__s2;
      D.17762 = (int) D.17761;
      __result = D.17760 - D.17762;
      {
        D.17763 = __s2_len != 0;
        D.17764 = __result == 0;
        D.17765 = D.17763 & D.17764;
        if (D.17765 != 0) goto <D.17766>; else goto <D.17767>;
        <D.17766>:
        D.17768 = &MEM[(void *)"disable" + 1B];
        D.17769 = *D.17768;
        D.17770 = (int) D.17769;
        D.17771 = __s2 + 1;
        D.17772 = *D.17771;
        D.17773 = (int) D.17772;
        __result = D.17770 - D.17773;
        D.17774 = __s2_len > 1;
        D.17764 = __result == 0;
        D.17775 = D.17774 & D.17764;
        if (D.17775 != 0) goto <D.17776>; else goto <D.17777>;
        <D.17776>:
        D.17778 = &MEM[(void *)"disable" + 2B];
        D.17779 = *D.17778;
        D.17780 = (int) D.17779;
        D.17781 = __s2 + 2;
        D.17782 = *D.17781;
        D.17783 = (int) D.17782;
        __result = D.17780 - D.17783;
        D.17784 = __s2_len > 2;
        D.17764 = __result == 0;
        D.17785 = D.17784 & D.17764;
        if (D.17785 != 0) goto <D.17786>; else goto <D.17787>;
        <D.17786>:
        D.17788 = &MEM[(void *)"disable" + 3B];
        D.17789 = *D.17788;
        D.17790 = (int) D.17789;
        D.17791 = __s2 + 3;
        D.17792 = *D.17791;
        D.17793 = (int) D.17792;
        __result = D.17790 - D.17793;
        <D.17787>:
        <D.17777>:
        <D.17767>:
      }
      D.17667 = __result;
    }
    iftmp.0 = -D.17667;
    goto <D.17794>;
    <D.17757>:
    iftmp.0 = __builtin_strcmp (options, "disable");
    <D.17794>:
    D.17668 = iftmp.0;
  }
  if (D.17668 == 0) goto <D.17795>; else goto <D.17796>;
  <D.17795>:
  config.enabled = 0;
  <D.17796>:
}


mono_attach_init ()
{
  InitializeCriticalSection (&agent_mutex);
  config.enabled = 1;
}


mono_attach_start ()
{
  int started.1;
  gboolean D.17801;
  int D.17802;
  int D.17805;
  char path[256];
  int fd;

  try
    {
      started.1 = started;
      if (started.1 != 0) goto <D.17799>; else goto <D.17800>;
      <D.17799>:
      D.17801 = 0;
      return D.17801;
      <D.17800>:
      D.17802 = getpid ();
      snprintf (&path, 256, "/tmp/.mono_attach_pid%d", D.17802);
      fd = open (&path, 0);
      if (fd == -1) goto <D.17803>; else goto <D.17804>;
      <D.17803>:
      D.17801 = 0;
      return D.17801;
      <D.17804>:
      close (fd);
      D.17805 = config.enabled;
      if (D.17805 == 0) goto <D.17806>; else goto <D.17807>;
      <D.17806>:
      D.17801 = 1;
      return D.17801;
      <D.17807>:
      started.1 = started;
      if (started.1 != 0) goto <D.17808>; else goto <D.17809>;
      <D.17808>:
      D.17801 = 0;
      return D.17801;
      <D.17809>:
      needs_to_start = 1;
      mono_gc_finalize_notify ();
      D.17801 = 1;
      return D.17801;
    }
  finally
    {
      path = {CLOBBER};
    }
}


snprintf (char * restrict __s, size_t __n, const char * restrict __fmt)
{
  int D.17812;
  unsigned int D.17813;

  D.17813 = __builtin_object_size (__s, 1);
  D.17812 = __builtin___snprintf_chk (__s, __n, 1, D.17813, __fmt, __builtin_va_arg_pack ());
  return D.17812;
}


open (const char * __path, int __oflag)
{
  int D.17815;
  int D.17818;
  int D.17823;
  int D.17825;
  int D.17826;
  int D.17829;
  int D.17830;

  D.17815 = __builtin_va_arg_pack_len ();
  if (D.17815 > 1) goto <D.17816>; else goto <D.17817>;
  <D.17816>:
  __open_too_many_args ();
  <D.17817>:
  D.17818 = __builtin_constant_p (__oflag);
  if (D.17818 != 0) goto <D.17819>; else goto <D.17820>;
  <D.17819>:
  D.17823 = __oflag & 64;
  if (D.17823 != 0) goto <D.17821>; else goto <D.17824>;
  <D.17824>:
  D.17825 = __oflag & 4259840;
  if (D.17825 == 4259840) goto <D.17821>; else goto <D.17822>;
  <D.17821>:
  D.17826 = __builtin_va_arg_pack_len ();
  if (D.17826 <= 0) goto <D.17827>; else goto <D.17828>;
  <D.17827>:
  __open_missing_mode ();
  D.17829 = __open_2 (__path, __oflag);
  return D.17829;
  <D.17828>:
  <D.17822>:
  D.17829 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.17829;
  <D.17820>:
  D.17830 = __builtin_va_arg_pack_len ();
  if (D.17830 <= 0) goto <D.17831>; else goto <D.17832>;
  <D.17831>:
  D.17829 = __open_2 (__path, __oflag);
  return D.17829;
  <D.17832>:
  D.17829 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.17829;
}


mono_attach_maybe_start ()
{
  int needs_to_start.2;
  int started.3;

  needs_to_start.2 = needs_to_start;
  if (needs_to_start.2 == 0) goto <D.17835>; else goto <D.17836>;
  <D.17835>:
  return;
  <D.17836>:
  needs_to_start = 0;
  started.3 = started;
  if (started.3 == 0) goto <D.17838>; else goto <D.17839>;
  <D.17838>:
  transport_start_receive ();
  started = 1;
  <D.17839>:
}


transport_start_receive ()
{
  int listen_fd.4;
  void * receiver_thread_handle.5;
  void * receiver_thread_handle.6;
  _Bool D.17846;
  long int D.17847;
  long int D.17848;

  transport_connect ();
  listen_fd.4 = listen_fd;
  if (listen_fd.4 == 0) goto <D.17842>; else goto <D.17843>;
  <D.17842>:
  return;
  <D.17843>:
  receiver_thread_handle.5 = mono_threads_create_thread (receiver_thread, 0B, 0, 0, 0B);
  receiver_thread_handle = receiver_thread_handle.5;
  receiver_thread_handle.6 = receiver_thread_handle;
  D.17846 = receiver_thread_handle.6 == 0B;
  D.17847 = (long int) D.17846;
  D.17848 = __builtin_expect (D.17847, 0);
  if (D.17848 != 0) goto <D.17849>; else goto <D.17850>;
  <D.17849>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 482, "receiver_thread_handle");
  <D.17850>:
}


receiver_thread (void * arg)
{
  char * server_uri.7;
  union 
{
  struct sockaddr * restrict __sockaddr__;
  struct sockaddr_at * restrict __sockaddr_at__;
  struct sockaddr_ax25 * restrict __sockaddr_ax25__;
  struct sockaddr_dl * restrict __sockaddr_dl__;
  struct sockaddr_eon * restrict __sockaddr_eon__;
  struct sockaddr_in * restrict __sockaddr_in__;
  struct sockaddr_in6 * restrict __sockaddr_in6__;
  struct sockaddr_inarp * restrict __sockaddr_inarp__;
  struct sockaddr_ipx * restrict __sockaddr_ipx__;
  struct sockaddr_iso * restrict __sockaddr_iso__;
  struct sockaddr_ns * restrict __sockaddr_ns__;
  struct sockaddr_un * restrict __sockaddr_un__;
  struct sockaddr_x25 * restrict __sockaddr_x25__;
} D.17853;
  int listen_fd.8;
  int conn_fd.9;
  int conn_fd.10;
  guint32 D.17859;
  struct MonoDomain * D.17860;
  struct MonoInternalThread * D.17861;
  unsigned int D.17862;
  unsigned int D.17863;
  int * D.17866;
  int D.17867;
  int stop_receiver_thread.11;
  int D.17876;
  unsigned char D.17878;
  unsigned char D.17880;
  struct _IO_FILE * stderr.12;
  guint8 * p.13;
  unsigned int content_len.14;
  unsigned int content_len.15;
  sizetype content_len.16;
  int D.17748;
  int iftmp.17;
  int D.17747;
  const char[7] * D.17891;
  unsigned char D.17892;
  int D.17893;
  unsigned char D.17894;
  int D.17895;
  _Bool D.17896;
  _Bool D.17897;
  _Bool D.17898;
  const unsigned char * D.17901;
  unsigned char D.17902;
  int D.17903;
  const unsigned char * D.17904;
  unsigned char D.17905;
  int D.17906;
  _Bool D.17907;
  _Bool D.17908;
  const unsigned char * D.17911;
  unsigned char D.17912;
  int D.17913;
  const unsigned char * D.17914;
  unsigned char D.17915;
  int D.17916;
  _Bool D.17917;
  _Bool D.17918;
  const unsigned char * D.17921;
  unsigned char D.17922;
  int D.17923;
  const unsigned char * D.17924;
  unsigned char D.17925;
  int D.17926;
  _Bool D.17928;
  long int D.17929;
  long int D.17930;
  struct MonoDomain * D.17933;
  int res;
  int content_len;
  guint8 buffer[256];
  guint8 * p;
  guint8 * p_end;
  struct MonoObject * exc;

  try
    {
      server_uri.7 = server_uri;
      printf ("attach: Listening on \'%s\'...\n", server_uri.7);
      <D.17751>:
      D.17853.__sockaddr__ = 0B;
      listen_fd.8 = listen_fd;
      conn_fd.9 = accept (listen_fd.8, D.17853, 0B);
      conn_fd = conn_fd.9;
      conn_fd.10 = conn_fd;
      if (conn_fd.10 == -1) goto <D.17857>; else goto <D.17858>;
      <D.17857>:
      D.17859 = 0;
      return D.17859;
      <D.17858>:
      printf ("attach: Connected.\n");
      D.17860 = mono_get_root_domain ();
      mono_thread_attach (D.17860);
      D.17861 = mono_thread_internal_current ();
      D.17862 = D.17861->state;
      D.17863 = D.17862 | 4;
      D.17861->state = D.17863;
      <D.17749>:
      {
        char * cmd;
        char * agent_name;
        char * agent_args;
        guint8 * body;

        conn_fd.10 = conn_fd;
        res = read (conn_fd.10, &buffer, 6);
        if (res == -1) goto <D.17864>; else goto <D.17865>;
        <D.17864>:
        D.17866 = __errno_location ();
        D.17867 = *D.17866;
        if (D.17867 == 4) goto <D.17868>; else goto <D.17869>;
        <D.17868>:
        // predicted unlikely by continue predictor.
        goto <D.17729>;
        <D.17869>:
        <D.17865>:
        if (res == -1) goto <D.17730>; else goto <D.17870>;
        <D.17870>:
        stop_receiver_thread.11 = stop_receiver_thread;
        if (stop_receiver_thread.11 != 0) goto <D.17730>; else goto <D.17872>;
        <D.17872>:
        if (res != 6) goto <D.17730>; else goto <D.17873>;
        <D.17873>:
        D.17876 = strncmp (&buffer, "MONO", 4);
        if (D.17876 != 0) goto <D.17874>; else goto <D.17877>;
        <D.17877>:
        D.17878 = buffer[4];
        if (D.17878 != 1) goto <D.17874>; else goto <D.17879>;
        <D.17879>:
        D.17880 = buffer[5];
        if (D.17880 != 0) goto <D.17874>; else goto <D.17875>;
        <D.17874>:
        stderr.12 = stderr;
        fprintf (stderr.12, "attach: message from server has unknown header.\n");
        goto <D.17730>;
        <D.17875>:
        conn_fd.10 = conn_fd;
        res = read (conn_fd.10, &buffer, 4);
        if (res != 4) goto <D.17730>; else goto <D.17882>;
        <D.17882>:
        p = &buffer;
        p.13 = p;
        p_end = p.13 + 8;
        p.13 = p;
        content_len = decode_int (p.13, &p, p_end);
        content_len.14 = (unsigned int) content_len;
        body = monoeg_malloc (content_len.14);
        content_len.15 = (unsigned int) content_len;
        conn_fd.10 = conn_fd;
        res = read (conn_fd.10, body, content_len.15);
        p = body;
        content_len.16 = (sizetype) content_len;
        p_end = body + content_len.16;
        p.13 = p;
        cmd = decode_string_value (p.13, &p, p_end);
        if (cmd == 0B) goto <D.17730>; else goto <D.17887>;
        <D.17887>:
        {
          size_t __s1_len;
          size_t __s2_len;

          __s2_len = 6;
          if (__s2_len <= 3) goto <D.17889>; else goto <D.17890>;
          <D.17889>:
          {
            const unsigned char * __s2;
            int __result;

            __s2 = cmd;
            D.17891 = "attach";
            D.17892 = MEM[(const unsigned char *)D.17891];
            D.17893 = (int) D.17892;
            D.17894 = *__s2;
            D.17895 = (int) D.17894;
            __result = D.17893 - D.17895;
            {
              D.17896 = __s2_len != 0;
              D.17897 = __result == 0;
              D.17898 = D.17896 & D.17897;
              if (D.17898 != 0) goto <D.17899>; else goto <D.17900>;
              <D.17899>:
              D.17901 = &MEM[(void *)"attach" + 1B];
              D.17902 = *D.17901;
              D.17903 = (int) D.17902;
              D.17904 = __s2 + 1;
              D.17905 = *D.17904;
              D.17906 = (int) D.17905;
              __result = D.17903 - D.17906;
              D.17907 = __s2_len > 1;
              D.17897 = __result == 0;
              D.17908 = D.17907 & D.17897;
              if (D.17908 != 0) goto <D.17909>; else goto <D.17910>;
              <D.17909>:
              D.17911 = &MEM[(void *)"attach" + 2B];
              D.17912 = *D.17911;
              D.17913 = (int) D.17912;
              D.17914 = __s2 + 2;
              D.17915 = *D.17914;
              D.17916 = (int) D.17915;
              __result = D.17913 - D.17916;
              D.17917 = __s2_len > 2;
              D.17897 = __result == 0;
              D.17918 = D.17917 & D.17897;
              if (D.17918 != 0) goto <D.17919>; else goto <D.17920>;
              <D.17919>:
              D.17921 = &MEM[(void *)"attach" + 3B];
              D.17922 = *D.17921;
              D.17923 = (int) D.17922;
              D.17924 = __s2 + 3;
              D.17925 = *D.17924;
              D.17926 = (int) D.17925;
              __result = D.17923 - D.17926;
              <D.17920>:
              <D.17910>:
              <D.17900>:
            }
            D.17747 = __result;
          }
          iftmp.17 = -D.17747;
          goto <D.17927>;
          <D.17890>:
          iftmp.17 = __builtin_strcmp (cmd, "attach");
          <D.17927>:
          D.17748 = iftmp.17;
        }
        D.17928 = D.17748 != 0;
        D.17929 = (long int) D.17928;
        D.17930 = __builtin_expect (D.17929, 0);
        if (D.17930 != 0) goto <D.17931>; else goto <D.17932>;
        <D.17931>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 550, "!strcmp (cmd, \"attach\")");
        <D.17932>:
        p.13 = p;
        agent_name = decode_string_value (p.13, &p, p_end);
        p.13 = p;
        agent_args = decode_string_value (p.13, &p, p_end);
        printf ("attach: Loading agent \'%s\'.\n", agent_name);
        D.17933 = mono_domain_get ();
        mono_attach_load_agent (D.17933, agent_name, agent_args, &exc);
        monoeg_g_free (body);
      }
      <D.17729>:
      goto <D.17749>;
      <D.17730>:
      conn_fd.10 = conn_fd;
      close (conn_fd.10);
      conn_fd = 0;
      printf ("attach: Disconnected.\n");
      stop_receiver_thread.11 = stop_receiver_thread;
      if (stop_receiver_thread.11 != 0) goto <D.17750>; else goto <D.17934>;
      <D.17934>:
      goto <D.17751>;
      <D.17750>:
      D.17859 = 0;
      return D.17859;
    }
  finally
    {
      buffer = {CLOBBER};
      p = {CLOBBER};
      exc = {CLOBBER};
    }
}


fprintf (struct FILE * restrict __stream, const char * restrict __fmt)
{
  int D.17937;

  D.17937 = __fprintf_chk (__stream, 1, __fmt, __builtin_va_arg_pack ());
  return D.17937;
}


decode_int (guint8 * buf, guint8 * * endbuf, guint8 * limit)
{
  guint8 * D.17939;
  guint8 * D.17940;
  _Bool D.17941;
  long int D.17942;
  long int D.17943;
  int D.17946;
  unsigned char D.17947;
  int D.17948;
  guint8 * D.17949;
  unsigned char D.17950;
  int D.17951;
  int D.17952;
  int D.17953;
  guint8 * D.17954;
  unsigned char D.17955;
  int D.17956;
  int D.17957;
  int D.17958;
  guint8 * D.17959;
  unsigned char D.17960;
  int D.17961;
  int D.17962;

  D.17939 = buf + 4;
  *endbuf = D.17939;
  D.17940 = *endbuf;
  D.17941 = D.17940 > limit;
  D.17942 = (long int) D.17941;
  D.17943 = __builtin_expect (D.17942, 0);
  if (D.17943 != 0) goto <D.17944>; else goto <D.17945>;
  <D.17944>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 126, "*endbuf <= limit");
  <D.17945>:
  D.17947 = *buf;
  D.17948 = (int) D.17947;
  D.17949 = buf + 1;
  D.17950 = *D.17949;
  D.17951 = (int) D.17950;
  D.17952 = D.17951 << 8;
  D.17953 = D.17948 | D.17952;
  D.17954 = buf + 2;
  D.17955 = *D.17954;
  D.17956 = (int) D.17955;
  D.17957 = D.17956 << 16;
  D.17958 = D.17953 | D.17957;
  D.17959 = buf + 3;
  D.17960 = *D.17959;
  D.17961 = (int) D.17960;
  D.17962 = D.17961 << 24;
  D.17946 = D.17958 | D.17962;
  return D.17946;
}


read (int __fd, void * __buf, size_t __nbytes)
{
  unsigned int D.17964;
  int D.17967;
  ssize_t D.17970;
  unsigned int D.17971;
  unsigned int D.17972;
  unsigned int D.17975;

  D.17964 = __builtin_object_size (__buf, 0);
  if (D.17964 != 4294967295) goto <D.17965>; else goto <D.17966>;
  <D.17965>:
  D.17967 = __builtin_constant_p (__nbytes);
  if (D.17967 == 0) goto <D.17968>; else goto <D.17969>;
  <D.17968>:
  D.17971 = __builtin_object_size (__buf, 0);
  D.17970 = __read_chk (__fd, __buf, __nbytes, D.17971);
  return D.17970;
  <D.17969>:
  D.17972 = __builtin_object_size (__buf, 0);
  if (D.17972 < __nbytes) goto <D.17973>; else goto <D.17974>;
  <D.17973>:
  D.17975 = __builtin_object_size (__buf, 0);
  D.17970 = __read_chk_warn (__fd, __buf, __nbytes, D.17975);
  return D.17970;
  <D.17974>:
  <D.17966>:
  D.17970 = __read_alias (__fd, __buf, __nbytes);
  return D.17970;
}


decode_string_value (guint8 * buf, guint8 * * endbuf, guint8 * limit)
{
  guint8 * p.18;
  char * D.17980;
  _Bool D.17981;
  long int D.17982;
  long int D.17983;
  int D.17986;
  int D.17987;
  signed char b.19;
  _Bool D.17990;
  long int D.17991;
  long int D.17992;
  int D.17995;
  unsigned int D.17996;
  sizetype length.20;
  guint8 * p.22;
  _Bool D.17999;
  long int D.18000;
  long int D.18001;
  unsigned int length.21;
  char * D.18005;
  int type;
  gint32 length;
  guint8 * p;
  char * s;

  try
    {
      p = buf;
      p.18 = p;
      type = decode_byte (p.18, &p, limit);
      if (type == 17) goto <D.17978>; else goto <D.17979>;
      <D.17978>:
      p.18 = p;
      *endbuf = p.18;
      D.17980 = 0B;
      return D.17980;
      <D.17979>:
      D.17981 = type != 18;
      D.17982 = (long int) D.17981;
      D.17983 = __builtin_expect (D.17982, 0);
      if (D.17983 != 0) goto <D.17984>; else goto <D.17985>;
      <D.17984>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 153, "type == PRIM_TYPE_STRING");
      <D.17985>:
      length = 0;
      <D.17656>:
      {
        guint8 b;

        p.18 = p;
        D.17986 = decode_byte (p.18, &p, limit);
        b = (guint8) D.17986;
        length = length << 8;
        D.17987 = (int) b;
        length = D.17987 + length;
        b.19 = (signed char) b;
        if (b.19 >= 0) goto <D.17655>; else goto <D.17989>;
        <D.17989>:
      }
      goto <D.17656>;
      <D.17655>:
      D.17990 = length > 65535;
      D.17991 = (long int) D.17990;
      D.17992 = __builtin_expect (D.17991, 0);
      if (D.17992 != 0) goto <D.17993>; else goto <D.17994>;
      <D.17993>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 165, "length < (1 << 16)");
      <D.17994>:
      D.17995 = length + 1;
      D.17996 = (unsigned int) D.17995;
      s = monoeg_malloc (D.17996);
      p.18 = p;
      length.20 = (sizetype) length;
      p.22 = p.18 + length.20;
      D.17999 = p.22 > limit;
      D.18000 = (long int) D.17999;
      D.18001 = __builtin_expect (D.18000, 0);
      if (D.18001 != 0) goto <D.18002>; else goto <D.18003>;
      <D.18002>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 169, "p + length <= limit");
      <D.18003>:
      length.21 = (unsigned int) length;
      p.18 = p;
      memcpy (s, p.18, length.21);
      length.20 = (sizetype) length;
      D.18005 = s + length.20;
      *D.18005 = 0;
      p.18 = p;
      length.20 = (sizetype) length;
      p.22 = p.18 + length.20;
      p = p.22;
      p.18 = p;
      *endbuf = p.18;
      D.17980 = s;
      return D.17980;
    }
  finally
    {
      p = {CLOBBER};
    }
}


decode_byte (guint8 * buf, guint8 * * endbuf, guint8 * limit)
{
  guint8 * D.18008;
  guint8 * D.18009;
  _Bool D.18010;
  long int D.18011;
  long int D.18012;
  int D.18015;
  unsigned char D.18016;

  D.18008 = buf + 1;
  *endbuf = D.18008;
  D.18009 = *endbuf;
  D.18010 = D.18009 > limit;
  D.18011 = (long int) D.18010;
  D.18012 = __builtin_expect (D.18011, 0);
  if (D.18012 != 0) goto <D.18013>; else goto <D.18014>;
  <D.18013>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 118, "*endbuf <= limit");
  <D.18014>:
  D.18016 = *buf;
  D.18015 = (int) D.18016;
  return D.18015;
}


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

  D.18019 = __builtin_object_size (__dest, 0);
  D.18018 = __builtin___memcpy_chk (__dest, __src, __len, D.18019);
  return D.18018;
}


mono_attach_load_agent (struct MonoDomain * domain, char * agent, char * args, struct MonoObject * * exc)
{
  <unnamed type> open_status.23;
  const char * D.18024;
  struct _IO_FILE * stderr.24;
  int D.18026;
  const char * D.18029;
  struct MonoClass * D.18034;
  struct MonoString * D.18035;
  struct MonoAssembly * agent_assembly;
  struct MonoImage * image;
  struct MonoMethod * method;
  guint32 entry;
  struct MonoArray * main_args;
  void * pa[1];
  MonoImageOpenStatus open_status;

  try
    {
      agent_assembly = mono_assembly_open (agent, &open_status);
      if (agent_assembly == 0B) goto <D.18021>; else goto <D.18022>;
      <D.18021>:
      open_status.23 = open_status;
      D.18024 = mono_image_strerror (open_status.23);
      stderr.24 = stderr;
      fprintf (stderr.24, "Cannot open agent assembly \'%s\': %s.\n", agent, D.18024);
      monoeg_g_free (agent);
      D.18026 = 2;
      return D.18026;
      <D.18022>:
      image = mono_assembly_get_image (agent_assembly);
      entry = mono_image_get_entry_point (image);
      if (entry == 0) goto <D.18027>; else goto <D.18028>;
      <D.18027>:
      D.18029 = mono_image_get_filename (image);
      monoeg_g_print ("Assembly \'%s\' doesn\'t have an entry point.\n", D.18029);
      monoeg_g_free (agent);
      D.18026 = 1;
      return D.18026;
      <D.18028>:
      method = mono_get_method (image, entry, 0B);
      if (method == 0B) goto <D.18030>; else goto <D.18031>;
      <D.18030>:
      monoeg_g_print ("The entry point method of assembly \'%s\' could not be loaded\n", agent);
      monoeg_g_free (agent);
      D.18026 = 1;
      return D.18026;
      <D.18031>:
      if (args != 0B) goto <D.18032>; else goto <D.18033>;
      <D.18032>:
      D.18034 = mono_defaults.string_class;
      main_args = mono_array_new (domain, D.18034, 1);
      {
        struct MonoString * * __p;

        __p = mono_array_addr_with_size (main_args, 4, 0);
        D.18035 = mono_string_new (domain, args);
        *__p = D.18035;
      }
      goto <D.18036>;
      <D.18033>:
      D.18034 = mono_defaults.string_class;
      main_args = mono_array_new (domain, D.18034, 0);
      <D.18036>:
      monoeg_g_free (agent);
      pa[0] = main_args;
      mono_runtime_invoke (method, 0B, &pa, exc);
      D.18026 = 0;
      return D.18026;
    }
  finally
    {
      pa = {CLOBBER};
      open_status = {CLOBBER};
    }
}


printf (const char * restrict __fmt)
{
  int D.18039;

  D.18039 = __printf_chk (1, __fmt, __builtin_va_arg_pack ());
  return D.18039;
}


transport_connect ()
{
  ipc_connect ();
}


ipc_connect ()
{
  unsigned int D.18041;
  unsigned int D.18042;
  struct _IO_FILE * stderr.25;
  unsigned int D.18048;
  struct passwd * pw.26;
  _Bool D.18052;
  long int D.18053;
  long int D.18054;
  char * D.18057;
  int * D.18060;
  int D.18061;
  unsigned int D.18066;
  unsigned int D.18067;
  unsigned int D.18070;
  unsigned int D.18071;
  unsigned int D.18074;
  unsigned int D.18075;
  int D.18079;
  unsigned int D.18080;
  union 
{
  const struct sockaddr * restrict __sockaddr__;
  const struct sockaddr_at * restrict __sockaddr_at__;
  const struct sockaddr_ax25 * restrict __sockaddr_ax25__;
  const struct sockaddr_dl * restrict __sockaddr_dl__;
  const struct sockaddr_eon * restrict __sockaddr_eon__;
  const struct sockaddr_in * restrict __sockaddr_in__;
  const struct sockaddr_in6 * restrict __sockaddr_in6__;
  const struct sockaddr_inarp * restrict __sockaddr_inarp__;
  const struct sockaddr_ipx * restrict __sockaddr_ipx__;
  const struct sockaddr_iso * restrict __sockaddr_iso__;
  const struct sockaddr_ns * restrict __sockaddr_ns__;
  const struct sockaddr_un * restrict __sockaddr_un__;
  const struct sockaddr_x25 * restrict __sockaddr_x25__;
} D.18081;
  int D.18082;
  char * D.18085;
  char * D.18090;
  gchar * ipc_filename.27;
  int D.18092;
  gchar * server_uri.28;
  struct sockaddr_un name;
  int sock;
  int res;
  size_t size;
  char * filename;
  char * directory;
  struct stat stat;
  struct passwd pwbuf;
  char buf[1024];
  struct passwd * pw;

  try
    {
      D.18041 = getuid ();
      D.18042 = geteuid ();
      if (D.18041 != D.18042) goto <D.18043>; else goto <D.18044>;
      <D.18043>:
      stderr.25 = stderr;
      fprintf (stderr.25, "attach: disabled listening on an IPC socket when running in setuid mode.\n");
      return;
      <D.18044>:
      sock = socket (1, 1, 0);
      if (sock < 0) goto <D.18046>; else goto <D.18047>;
      <D.18046>:
      perror ("attach: failed to create IPC socket");
      return;
      <D.18047>:
      pw = 0B;
      D.18048 = getuid ();
      res = getpwuid_r (D.18048, &pwbuf, &buf, 1024, &pw);
      if (res != 0) goto <D.18049>; else goto <D.18050>;
      <D.18049>:
      stderr.25 = stderr;
      fprintf (stderr.25, "attach: getpwuid_r () failed.\n");
      return;
      <D.18050>:
      pw.26 = pw;
      D.18052 = pw.26 == 0B;
      D.18053 = (long int) D.18052;
      D.18054 = __builtin_expect (D.18053, 0);
      if (D.18054 != 0) goto <D.18055>; else goto <D.18056>;
      <D.18055>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "attach.c", 379, "pw");
      <D.18056>:
      pw.26 = pw;
      D.18057 = pw.26->pw_name;
      directory = monoeg_g_strdup_printf ("/tmp/mono-%s", D.18057);
      res = mkdir (directory, 448);
      if (res != 0) goto <D.18058>; else goto <D.18059>;
      <D.18058>:
      D.18060 = __errno_location ();
      D.18061 = *D.18060;
      if (D.18061 == 17) goto <D.18062>; else goto <D.18063>;
      <D.18062>:
      res = lstat (directory, &stat);
      if (res != 0) goto <D.18064>; else goto <D.18065>;
      <D.18064>:
      perror ("attach: lstat () failed");
      return;
      <D.18065>:
      D.18066 = stat.st_mode;
      D.18067 = D.18066 & 61440;
      if (D.18067 != 16384) goto <D.18068>; else goto <D.18069>;
      <D.18068>:
      stderr.25 = stderr;
      fprintf (stderr.25, "attach: path \'%s\' is not a directory.\n", directory);
      return;
      <D.18069>:
      D.18070 = stat.st_uid;
      D.18071 = getuid ();
      if (D.18070 != D.18071) goto <D.18072>; else goto <D.18073>;
      <D.18072>:
      stderr.25 = stderr;
      fprintf (stderr.25, "attach: directory \'%s\' is not owned by the current user.\n", directory);
      return;
      <D.18073>:
      D.18074 = BIT_FIELD_REF <stat, 32, 128>;
      D.18075 = D.18074 & 511;
      if (D.18075 != 448) goto <D.18076>; else goto <D.18077>;
      <D.18076>:
      stderr.25 = stderr;
      fprintf (stderr.25, "attach: directory \'%s\' should have protection 0700.\n", directory);
      return;
      <D.18077>:
      goto <D.18078>;
      <D.18063>:
      perror ("attach: mkdir () failed");
      return;
      <D.18078>:
      <D.18059>:
      D.18079 = getpid ();
      filename = monoeg_g_strdup_printf ("%s/.mono-%d", directory, D.18079);
      unlink (filename);
      name.sun_family = 1;
      strcpy (&name.sun_path, filename);
      D.18080 = strlen (&name.sun_path);
      size = D.18080 + 3;
      D.18081.__sockaddr__ = &name;
      D.18082 = bind (sock, D.18081, size);
      if (D.18082 < 0) goto <D.18083>; else goto <D.18084>;
      <D.18083>:
      D.18060 = __errno_location ();
      D.18061 = *D.18060;
      D.18085 = strerror (D.18061);
      stderr.25 = stderr;
      fprintf (stderr.25, "attach: failed to bind IPC socket \'%s\': %s\n", filename, D.18085);
      close (sock);
      return;
      <D.18084>:
      res = chmod (filename, 384);
      if (res != 0) goto <D.18086>; else goto <D.18087>;
      <D.18086>:
      perror ("attach: failed to set permissions on IPC socket");
      close (sock);
      unlink (filename);
      return;
      <D.18087>:
      res = listen (sock, 16);
      if (res != 0) goto <D.18088>; else goto <D.18089>;
      <D.18088>:
      D.18060 = __errno_location ();
      D.18061 = *D.18060;
      D.18090 = strerror (D.18061);
      stderr.25 = stderr;
      fprintf (stderr.25, "attach: listen () failed: %s\n", D.18090);
      exit (1);
      <D.18089>:
      listen_fd = sock;
      ipc_filename.27 = monoeg_strdup (filename);
      ipc_filename = ipc_filename.27;
      D.18092 = getpid ();
      server_uri.28 = monoeg_g_strdup_printf ("unix://%s/.mono-%d?/vm", directory, D.18092);
      server_uri = server_uri.28;
      monoeg_g_free (filename);
      monoeg_g_free (directory);
    }
  finally
    {
      name = {CLOBBER};
      stat = {CLOBBER};
      pwbuf = {CLOBBER};
      buf = {CLOBBER};
      pw = {CLOBBER};
    }
}


lstat (const char * __path, struct stat * __statbuf)
{
  int D.18097;

  D.18097 = __lxstat (3, __path, __statbuf);
  return D.18097;
}


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

  D.18100 = __builtin_object_size (__dest, 1);
  D.18099 = __builtin___strcpy_chk (__dest, __src, D.18100);
  return D.18099;
}


monoeg_strdup (const gchar * str)
{
  gchar * D.18104;

  if (str != 0B) goto <D.18102>; else goto <D.18103>;
  <D.18102>:
  D.18104 = __strdup (str);
  return D.18104;
  <D.18103>:
  D.18104 = 0B;
  return D.18104;
}


mono_attach_cleanup ()
{
  int listen_fd.29;
  char * ipc_filename.30;
  int conn_fd.31;
  void * receiver_thread_handle.32;

  listen_fd.29 = listen_fd;
  if (listen_fd.29 != 0) goto <D.18107>; else goto <D.18108>;
  <D.18107>:
  listen_fd.29 = listen_fd;
  close (listen_fd.29);
  <D.18108>:
  ipc_filename.30 = ipc_filename;
  if (ipc_filename.30 != 0B) goto <D.18110>; else goto <D.18111>;
  <D.18110>:
  ipc_filename.30 = ipc_filename;
  unlink (ipc_filename.30);
  <D.18111>:
  stop_receiver_thread = 1;
  conn_fd.31 = conn_fd;
  if (conn_fd.31 != 0) goto <D.18113>; else goto <D.18114>;
  <D.18113>:
  conn_fd.31 = conn_fd;
  close (conn_fd.31);
  <D.18114>:
  receiver_thread_handle.32 = receiver_thread_handle;
  if (receiver_thread_handle.32 != 0B) goto <D.18116>; else goto <D.18117>;
  <D.18116>:
  receiver_thread_handle.32 = receiver_thread_handle;
  WaitForSingleObjectEx (receiver_thread_handle.32, 0, 0);
  <D.18117>:
}


