mono_sem_timedwait (union MonoSemType * sem, guint32 timeout_ms, gboolean alertable)
{
  int D.9105;
  unsigned int D.9108;
  long int D.9109;
  long unsigned int D.9110;
  long unsigned int D.9111;
  long int D.9112;
  unsigned int D.9113;
  unsigned int D.9114;
  long int D.9115;
  long int D.9116;
  long unsigned int D.9117;
  long unsigned int D.9118;
  long int D.9119;
  long int D.9120;
  long int D.9121;
  long int D.9122;
  long int D.9123;
  long int D.9126;
  long int D.9127;
  long int D.9128;
  long int D.9129;
  long int D.9130;
  long int D.9131;
  long int D.9132;
  long int D.9138;
  long int D.9139;
  int * D.9143;
  int D.9144;
  struct timespec ts;
  struct timespec copy;
  struct timeval t;
  int res;

  try
    {
      res = 0;
      if (timeout_ms == 0) goto <D.9103>; else goto <D.9104>;
      <D.9103>:
      D.9105 = sem_trywait (sem);
      return D.9105;
      <D.9104>:
      if (timeout_ms == 4294967295) goto <D.9106>; else goto <D.9107>;
      <D.9106>:
      D.9105 = mono_sem_wait (sem, alertable);
      return D.9105;
      <D.9107>:
      gettimeofday (&t, 0B);
      D.9108 = timeout_ms / 1000;
      D.9109 = t.tv_sec;
      D.9110 = (long unsigned int) D.9109;
      D.9111 = D.9108 + D.9110;
      D.9112 = (long int) D.9111;
      ts.tv_sec = D.9112;
      D.9113 = timeout_ms % 1000;
      D.9114 = D.9113 * 1000000;
      D.9115 = t.tv_usec;
      D.9116 = D.9115 * 1000;
      D.9117 = (long unsigned int) D.9116;
      D.9118 = D.9114 + D.9117;
      D.9119 = (long int) D.9118;
      ts.tv_nsec = D.9119;
      goto <D.9081>;
      <D.9080>:
      D.9120 = ts.tv_nsec;
      D.9121 = D.9120 + -1000000000;
      ts.tv_nsec = D.9121;
      D.9122 = ts.tv_sec;
      D.9123 = D.9122 + 1;
      ts.tv_sec = D.9123;
      <D.9081>:
      D.9120 = ts.tv_nsec;
      if (D.9120 > 1000000000) goto <D.9080>; else goto <D.9082>;
      <D.9082>:
      copy = ts;
      goto <D.9085>;
      <D.9084>:
      {
        struct timeval current;

        try
          {
            if (alertable != 0) goto <D.9124>; else goto <D.9125>;
            <D.9124>:
            D.9105 = -1;
            return D.9105;
            <D.9125>:
            gettimeofday (&current, 0B);
            ts = copy;
            D.9122 = ts.tv_sec;
            D.9109 = t.tv_sec;
            D.9126 = current.tv_sec;
            D.9127 = D.9109 - D.9126;
            D.9128 = D.9122 + D.9127;
            ts.tv_sec = D.9128;
            D.9120 = ts.tv_nsec;
            D.9115 = t.tv_usec;
            D.9129 = current.tv_usec;
            D.9130 = D.9115 - D.9129;
            D.9131 = D.9130 * 1000;
            D.9132 = D.9120 + D.9131;
            ts.tv_nsec = D.9132;
            D.9120 = ts.tv_nsec;
            if (D.9120 < 0) goto <D.9133>; else goto <D.9134>;
            <D.9133>:
            D.9122 = ts.tv_sec;
            if (D.9122 <= 0) goto <D.9135>; else goto <D.9136>;
            <D.9135>:
            ts.tv_nsec = 0;
            goto <D.9137>;
            <D.9136>:
            D.9122 = ts.tv_sec;
            D.9138 = D.9122 + -1;
            ts.tv_sec = D.9138;
            D.9120 = ts.tv_nsec;
            D.9139 = D.9120 + 1000000000;
            ts.tv_nsec = D.9139;
            <D.9137>:
            <D.9134>:
            D.9122 = ts.tv_sec;
            if (D.9122 < 0) goto <D.9140>; else goto <D.9141>;
            <D.9140>:
            ts.tv_sec = 0;
            ts.tv_nsec = 0;
            <D.9141>:
          }
        finally
          {
            current = {CLOBBER};
          }
      }
      <D.9085>:
      res = sem_timedwait (sem, &ts);
      if (res == -1) goto <D.9142>; else goto <D.9086>;
      <D.9142>:
      D.9143 = __errno_location ();
      D.9144 = *D.9143;
      if (D.9144 == 4) goto <D.9084>; else goto <D.9086>;
      <D.9086>:
      if (res != 0) goto <D.9145>; else goto <D.9146>;
      <D.9145>:
      res = -1;
      <D.9146>:
      D.9105 = res;
      return D.9105;
    }
  finally
    {
      ts = {CLOBBER};
      copy = {CLOBBER};
      t = {CLOBBER};
    }
}


mono_sem_wait (union MonoSemType * sem, gboolean alertable)
{
  int D.9153;
  int * D.9155;
  int D.9156;
  int res;

  goto <D.9093>;
  <D.9092>:
  if (alertable != 0) goto <D.9151>; else goto <D.9152>;
  <D.9151>:
  D.9153 = -1;
  return D.9153;
  <D.9152>:
  <D.9093>:
  res = sem_wait (sem);
  if (res == -1) goto <D.9154>; else goto <D.9094>;
  <D.9154>:
  D.9155 = __errno_location ();
  D.9156 = *D.9155;
  if (D.9156 == 4) goto <D.9092>; else goto <D.9094>;
  <D.9094>:
  if (res != 0) goto <D.9157>; else goto <D.9158>;
  <D.9157>:
  res = -1;
  <D.9158>:
  D.9153 = res;
  return D.9153;
}


mono_sem_post (union MonoSemType * sem)
{
  int * D.9161;
  int D.9162;
  int D.9163;
  int res;

  goto <D.9100>;
  <D.9099>:
  <D.9100>:
  res = sem_post (sem);
  if (res == -1) goto <D.9160>; else goto <D.9101>;
  <D.9160>:
  D.9161 = __errno_location ();
  D.9162 = *D.9161;
  if (D.9162 == 4) goto <D.9099>; else goto <D.9101>;
  <D.9101>:
  D.9163 = res;
  return D.9163;
}


