mono_sem_timedwait (union MonoSemType * sem, guint32 timeout_ms, gboolean alertable)
{
  int D.11717;
  unsigned int D.11720;
  long int D.11721;
  long unsigned int D.11722;
  long unsigned int D.11723;
  long int D.11724;
  unsigned int D.11725;
  unsigned int D.11726;
  long int D.11727;
  long int D.11728;
  long unsigned int D.11729;
  long unsigned int D.11730;
  long int D.11731;
  long int D.11732;
  long int D.11733;
  long int D.11734;
  long int D.11735;
  long int D.11738;
  long int D.11739;
  long int D.11740;
  long int D.11741;
  long int D.11742;
  long int D.11743;
  long int D.11744;
  long int D.11750;
  long int D.11751;
  int * D.11755;
  int D.11756;
  struct timespec ts;
  struct timespec copy;
  struct timeval t;
  int res;

  try
    {
      res = 0;
      if (timeout_ms == 0) goto <D.11715>; else goto <D.11716>;
      <D.11715>:
      D.11717 = sem_trywait (sem);
      return D.11717;
      <D.11716>:
      if (timeout_ms == 4294967295) goto <D.11718>; else goto <D.11719>;
      <D.11718>:
      D.11717 = mono_sem_wait (sem, alertable);
      return D.11717;
      <D.11719>:
      gettimeofday (&t, 0B);
      D.11720 = timeout_ms / 1000;
      D.11721 = t.tv_sec;
      D.11722 = (long unsigned int) D.11721;
      D.11723 = D.11720 + D.11722;
      D.11724 = (long int) D.11723;
      ts.tv_sec = D.11724;
      D.11725 = timeout_ms % 1000;
      D.11726 = D.11725 * 1000000;
      D.11727 = t.tv_usec;
      D.11728 = D.11727 * 1000;
      D.11729 = (long unsigned int) D.11728;
      D.11730 = D.11726 + D.11729;
      D.11731 = (long int) D.11730;
      ts.tv_nsec = D.11731;
      goto <D.11691>;
      <D.11690>:
      D.11732 = ts.tv_nsec;
      D.11733 = D.11732 + -1000000000;
      ts.tv_nsec = D.11733;
      D.11734 = ts.tv_sec;
      D.11735 = D.11734 + 1;
      ts.tv_sec = D.11735;
      <D.11691>:
      D.11732 = ts.tv_nsec;
      if (D.11732 > 1000000000) goto <D.11690>; else goto <D.11692>;
      <D.11692>:
      copy = ts;
      goto <D.11695>;
      <D.11694>:
      {
        struct timeval current;

        try
          {
            if (alertable != 0) goto <D.11736>; else goto <D.11737>;
            <D.11736>:
            D.11717 = -1;
            return D.11717;
            <D.11737>:
            gettimeofday (&current, 0B);
            ts = copy;
            D.11734 = ts.tv_sec;
            D.11721 = t.tv_sec;
            D.11738 = current.tv_sec;
            D.11739 = D.11721 - D.11738;
            D.11740 = D.11734 + D.11739;
            ts.tv_sec = D.11740;
            D.11732 = ts.tv_nsec;
            D.11727 = t.tv_usec;
            D.11741 = current.tv_usec;
            D.11742 = D.11727 - D.11741;
            D.11743 = D.11742 * 1000;
            D.11744 = D.11732 + D.11743;
            ts.tv_nsec = D.11744;
            D.11732 = ts.tv_nsec;
            if (D.11732 < 0) goto <D.11745>; else goto <D.11746>;
            <D.11745>:
            D.11734 = ts.tv_sec;
            if (D.11734 <= 0) goto <D.11747>; else goto <D.11748>;
            <D.11747>:
            ts.tv_nsec = 0;
            goto <D.11749>;
            <D.11748>:
            D.11734 = ts.tv_sec;
            D.11750 = D.11734 + -1;
            ts.tv_sec = D.11750;
            D.11732 = ts.tv_nsec;
            D.11751 = D.11732 + 1000000000;
            ts.tv_nsec = D.11751;
            <D.11749>:
            <D.11746>:
            D.11734 = ts.tv_sec;
            if (D.11734 < 0) goto <D.11752>; else goto <D.11753>;
            <D.11752>:
            ts.tv_sec = 0;
            ts.tv_nsec = 0;
            <D.11753>:
          }
        finally
          {
            current = {CLOBBER};
          }
      }
      <D.11695>:
      res = sem_timedwait (sem, &ts);
      if (res == -1) goto <D.11754>; else goto <D.11696>;
      <D.11754>:
      D.11755 = __errno_location ();
      D.11756 = *D.11755;
      if (D.11756 == 4) goto <D.11694>; else goto <D.11696>;
      <D.11696>:
      if (res != 0) goto <D.11757>; else goto <D.11758>;
      <D.11757>:
      res = -1;
      <D.11758>:
      D.11717 = res;
      return D.11717;
    }
  finally
    {
      ts = {CLOBBER};
      copy = {CLOBBER};
      t = {CLOBBER};
    }
}


mono_sem_wait (union MonoSemType * sem, gboolean alertable)
{
  int D.11765;
  int * D.11767;
  int D.11768;
  int res;

  goto <D.11703>;
  <D.11702>:
  if (alertable != 0) goto <D.11763>; else goto <D.11764>;
  <D.11763>:
  D.11765 = -1;
  return D.11765;
  <D.11764>:
  <D.11703>:
  res = sem_wait (sem);
  if (res == -1) goto <D.11766>; else goto <D.11704>;
  <D.11766>:
  D.11767 = __errno_location ();
  D.11768 = *D.11767;
  if (D.11768 == 4) goto <D.11702>; else goto <D.11704>;
  <D.11704>:
  if (res != 0) goto <D.11769>; else goto <D.11770>;
  <D.11769>:
  res = -1;
  <D.11770>:
  D.11765 = res;
  return D.11765;
}


mono_sem_post (union MonoSemType * sem)
{
  int * D.11773;
  int D.11774;
  int D.11775;
  int res;

  goto <D.11710>;
  <D.11709>:
  <D.11710>:
  res = sem_post (sem);
  if (res == -1) goto <D.11772>; else goto <D.11711>;
  <D.11772>:
  D.11773 = __errno_location ();
  D.11774 = *D.11773;
  if (D.11774 == 4) goto <D.11709>; else goto <D.11711>;
  <D.11711>:
  D.11775 = res;
  return D.11775;
}


