mono_path_canonicalize (const char * path)
{
  int D.8515;
  int pos.0;
  int lastpos.1;
  char D.8524;
  gchar * D.8530;
  char D.8531;
  int D.8540;
  unsigned int D.8541;
  sizetype len.2;
  sizetype D.8543;
  char * D.8546;
  unsigned int D.8549;
  int D.8550;
  unsigned int D.8551;
  sizetype len.3;
  gchar * D.8553;
  sizetype D.8554;
  gchar * D.8555;
  gchar * D.8556;
  gchar * abspath;
  gchar * pos;
  gchar * lastpos;
  gchar * dest;
  int backc;

  D.8515 = monoeg_g_path_is_absolute (path);
  if (D.8515 != 0) goto <D.8516>; else goto <D.8517>;
  <D.8516>:
  abspath = monoeg_strdup (path);
  goto <D.8518>;
  <D.8517>:
  {
    gchar * tmpdir;

    tmpdir = monoeg_g_get_current_dir ();
    abspath = monoeg_g_build_path ("/", tmpdir, path, 0B);
    monoeg_g_free (tmpdir);
  }
  <D.8518>:
  abspath = monoeg_g_strreverse (abspath);
  backc = 0;
  lastpos = abspath;
  dest = lastpos;
  pos = __builtin_strchr (lastpos, 47);
  goto <D.8478>;
  <D.8477>:
  {
    int len;

    pos.0 = (int) pos;
    lastpos.1 = (int) lastpos;
    len = pos.0 - lastpos.1;
    if (len == 1) goto <D.8523>; else goto <D.8521>;
    <D.8523>:
    D.8524 = *lastpos;
    if (D.8524 == 46) goto <D.8525>; else goto <D.8521>;
    <D.8525>:
    goto <D.8522>;
    <D.8521>:
    if (len == 2) goto <D.8528>; else goto <D.8526>;
    <D.8528>:
    D.8524 = *lastpos;
    if (D.8524 == 46) goto <D.8529>; else goto <D.8526>;
    <D.8529>:
    D.8530 = lastpos + 1;
    D.8531 = *D.8530;
    if (D.8531 == 46) goto <D.8532>; else goto <D.8526>;
    <D.8532>:
    backc = backc + 1;
    goto <D.8527>;
    <D.8526>:
    if (len > 0) goto <D.8533>; else goto <D.8534>;
    <D.8533>:
    if (backc > 0) goto <D.8535>; else goto <D.8536>;
    <D.8535>:
    backc = backc + -1;
    goto <D.8537>;
    <D.8536>:
    if (dest != lastpos) goto <D.8538>; else goto <D.8539>;
    <D.8538>:
    D.8540 = len + 1;
    D.8541 = (unsigned int) D.8540;
    memmove (dest, lastpos, D.8541);
    <D.8539>:
    len.2 = (sizetype) len;
    D.8543 = len.2 + 1;
    dest = dest + D.8543;
    <D.8537>:
    <D.8534>:
    <D.8527>:
    <D.8522>:
    lastpos = pos + 1;
    pos = __builtin_strchr (lastpos, 47);
  }
  <D.8478>:
  if (pos != 0B) goto <D.8477>; else goto <D.8479>;
  <D.8479>:
  if (dest != lastpos) goto <D.8544>; else goto <D.8545>;
  <D.8544>:
  strcpy (dest, lastpos);
  <D.8545>:
  monoeg_g_strreverse (abspath);
  D.8546 = __builtin_strchr (abspath, 47);
  if (D.8546 == 0B) goto <D.8547>; else goto <D.8548>;
  <D.8547>:
  {
    int len;

    D.8549 = strlen (abspath);
    len = (int) D.8549;
    D.8550 = len + 2;
    D.8551 = (unsigned int) D.8550;
    abspath = monoeg_realloc (abspath, D.8551);
    len.3 = (sizetype) len;
    D.8553 = abspath + len.3;
    *D.8553 = 47;
    len.3 = (sizetype) len;
    D.8554 = len.3 + 1;
    D.8555 = abspath + D.8554;
    *D.8555 = 0;
  }
  <D.8548>:
  D.8556 = abspath;
  return D.8556;
}


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

  if (str != 0B) goto <D.8558>; else goto <D.8559>;
  <D.8558>:
  D.8560 = __strdup (str);
  return D.8560;
  <D.8559>:
  D.8560 = 0B;
  return D.8560;
}


memmove (void * __dest, const void * __src, size_t __len)
{
  void * D.8562;
  unsigned int D.8563;

  D.8563 = __builtin_object_size (__dest, 0);
  D.8562 = __builtin___memmove_chk (__dest, __src, __len, D.8563);
  return D.8562;
}


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

  D.8566 = __builtin_object_size (__dest, 1);
  D.8565 = __builtin___strcpy_chk (__dest, __src, D.8566);
  return D.8565;
}


mono_path_resolve_symlinks (const char * path)
{
  int D.8508;
  int iftmp.4;
  int D.8507;
  unsigned int i.5;
  unsigned int D.8572;
  gchar * * D.8573;
  const char[1] * D.8574;
  unsigned char D.8575;
  int D.8576;
  unsigned char D.8577;
  int D.8578;
  _Bool D.8579;
  _Bool D.8580;
  _Bool D.8581;
  const unsigned char * D.8584;
  unsigned char D.8585;
  int D.8586;
  const unsigned char * D.8587;
  unsigned char D.8588;
  int D.8589;
  _Bool D.8590;
  _Bool D.8591;
  const unsigned char * D.8594;
  unsigned char D.8595;
  int D.8596;
  const unsigned char * D.8597;
  unsigned char D.8598;
  int D.8599;
  _Bool D.8600;
  _Bool D.8601;
  const unsigned char * D.8604;
  unsigned char D.8605;
  int D.8606;
  const unsigned char * D.8607;
  unsigned char D.8608;
  int D.8609;
  gchar * D.8611;
  unsigned char D.8612;
  sizetype i.6;
  sizetype D.8616;
  sizetype D.8617;
  gchar * * D.8618;
  gchar * D.8619;
  gchar * D.8622;
  gchar * * split;
  gchar * p;
  int i;

  split = monoeg_g_strsplit (path, "/", -1);
  p = monoeg_strdup ("");
  i = 0;
  goto <D.8510>;
  <D.8509>:
  {
    gchar * tmp;

    tmp = 0B;
    {
      size_t __s1_len;
      size_t __s2_len;

      __s2_len = 0;
      if (__s2_len <= 3) goto <D.8569>; else goto <D.8570>;
      <D.8569>:
      {
        const unsigned char * __s2;
        int __result;

        i.5 = (unsigned int) i;
        D.8572 = i.5 * 4;
        D.8573 = split + D.8572;
        __s2 = *D.8573;
        D.8574 = "";
        D.8575 = MEM[(const unsigned char *)D.8574];
        D.8576 = (int) D.8575;
        D.8577 = *__s2;
        D.8578 = (int) D.8577;
        __result = D.8576 - D.8578;
        {
          D.8579 = __s2_len != 0;
          D.8580 = __result == 0;
          D.8581 = D.8579 & D.8580;
          if (D.8581 != 0) goto <D.8582>; else goto <D.8583>;
          <D.8582>:
          D.8584 = &MEM[(void *)"" + 1B];
          D.8585 = *D.8584;
          D.8586 = (int) D.8585;
          D.8587 = __s2 + 1;
          D.8588 = *D.8587;
          D.8589 = (int) D.8588;
          __result = D.8586 - D.8589;
          D.8590 = __s2_len > 1;
          D.8580 = __result == 0;
          D.8591 = D.8590 & D.8580;
          if (D.8591 != 0) goto <D.8592>; else goto <D.8593>;
          <D.8592>:
          D.8594 = &MEM[(void *)"" + 2B];
          D.8595 = *D.8594;
          D.8596 = (int) D.8595;
          D.8597 = __s2 + 2;
          D.8598 = *D.8597;
          D.8599 = (int) D.8598;
          __result = D.8596 - D.8599;
          D.8600 = __s2_len > 2;
          D.8580 = __result == 0;
          D.8601 = D.8600 & D.8580;
          if (D.8601 != 0) goto <D.8602>; else goto <D.8603>;
          <D.8602>:
          D.8604 = &MEM[(void *)"" + 3B];
          D.8605 = *D.8604;
          D.8606 = (int) D.8605;
          D.8607 = __s2 + 3;
          D.8608 = *D.8607;
          D.8609 = (int) D.8608;
          __result = D.8606 - D.8609;
          <D.8603>:
          <D.8593>:
          <D.8583>:
        }
        D.8507 = __result;
      }
      iftmp.4 = -D.8507;
      goto <D.8610>;
      <D.8570>:
      i.5 = (unsigned int) i;
      D.8572 = i.5 * 4;
      D.8573 = split + D.8572;
      D.8611 = *D.8573;
      D.8612 = MEM[(const unsigned char * {ref-all})D.8611];
      iftmp.4 = (int) D.8612;
      <D.8610>:
      D.8508 = iftmp.4;
    }
    if (D.8508 != 0) goto <D.8613>; else goto <D.8614>;
    <D.8613>:
    i.5 = (unsigned int) i;
    D.8572 = i.5 * 4;
    D.8573 = split + D.8572;
    D.8611 = *D.8573;
    tmp = monoeg_g_strdup_printf ("%s%s", p, D.8611);
    monoeg_g_free (p);
    p = resolve_symlink (tmp);
    monoeg_g_free (tmp);
    <D.8614>:
    i.6 = (sizetype) i;
    D.8616 = i.6 + 1;
    D.8617 = D.8616 * 4;
    D.8618 = split + D.8617;
    D.8619 = *D.8618;
    if (D.8619 != 0B) goto <D.8620>; else goto <D.8621>;
    <D.8620>:
    tmp = monoeg_g_strdup_printf ("%s%s", p, "/");
    monoeg_g_free (p);
    p = tmp;
    <D.8621>:
  }
  i = i + 1;
  <D.8510>:
  i.5 = (unsigned int) i;
  D.8572 = i.5 * 4;
  D.8573 = split + D.8572;
  D.8611 = *D.8573;
  if (D.8611 != 0B) goto <D.8509>; else goto <D.8511>;
  <D.8511>:
  monoeg_g_strfreev (split);
  D.8622 = p;
  return D.8622;
}


resolve_symlink (const char * path)
{
  gchar * D.8626;
  int D.8627;
  char * p;
  char * concat;
  char * dir;
  char buffer[4097];
  int n;
  int iterations;

  try
    {
      iterations = 0;
      p = monoeg_strdup (path);
      <D.8491>:
      iterations = iterations + 1;
      n = readlink (p, &buffer, 4096);
      if (n < 0) goto <D.8624>; else goto <D.8625>;
      <D.8624>:
      {
        char * copy;

        copy = p;
        p = mono_path_canonicalize (copy);
        monoeg_g_free (copy);
        D.8626 = p;
        return D.8626;
      }
      <D.8625>:
      buffer[n] = 0;
      D.8627 = monoeg_g_path_is_absolute (&buffer);
      if (D.8627 == 0) goto <D.8628>; else goto <D.8629>;
      <D.8628>:
      dir = monoeg_g_path_get_dirname (p);
      concat = monoeg_g_build_path ("/", dir, &buffer, 0B);
      monoeg_g_free (dir);
      goto <D.8630>;
      <D.8629>:
      concat = monoeg_strdup (&buffer);
      <D.8630>:
      monoeg_g_free (p);
      p = mono_path_canonicalize (concat);
      monoeg_g_free (concat);
      if (iterations <= 19) goto <D.8491>; else goto <D.8492>;
      <D.8492>:
      D.8626 = p;
      return D.8626;
    }
  finally
    {
      buffer = {CLOBBER};
    }
}


readlink (const char * restrict __path, char * restrict __buf, size_t __len)
{
  unsigned int D.8633;
  int D.8636;
  ssize_t D.8639;
  unsigned int D.8640;
  unsigned int D.8641;
  unsigned int D.8644;

  D.8633 = __builtin_object_size (__buf, 1);
  if (D.8633 != 4294967295) goto <D.8634>; else goto <D.8635>;
  <D.8634>:
  D.8636 = __builtin_constant_p (__len);
  if (D.8636 == 0) goto <D.8637>; else goto <D.8638>;
  <D.8637>:
  D.8640 = __builtin_object_size (__buf, 1);
  D.8639 = __readlink_chk (__path, __buf, __len, D.8640);
  return D.8639;
  <D.8638>:
  D.8641 = __builtin_object_size (__buf, 1);
  if (D.8641 < __len) goto <D.8642>; else goto <D.8643>;
  <D.8642>:
  D.8644 = __builtin_object_size (__buf, 1);
  D.8639 = __readlink_chk_warn (__path, __buf, __len, D.8644);
  return D.8639;
  <D.8643>:
  <D.8635>:
  D.8639 = __readlink_alias (__path, __buf, __len);
  return D.8639;
}


