mono_sem_timedwait (union MonoSemType * sem, guint32 timeout_ms, gboolean alertable)
{
  int D.9133;
  unsigned int D.9136;
  long int D.9137;
  long unsigned int D.9138;
  long unsigned int D.9139;
  long int D.9140;
  unsigned int D.9141;
  unsigned int D.9142;
  long int D.9143;
  long int D.9144;
  long unsigned int D.9145;
  long unsigned int D.9146;
  long int D.9147;
  long int D.9148;
  long int D.9149;
  long int D.9150;
  long int D.9151;
  long int D.9154;
  long int D.9155;
  long int D.9156;
  long int D.9157;
  long int D.9158;
  long int D.9159;
  long int D.9160;
  long int D.9166;
  long int D.9167;
  int * D.9171;
  int D.9172;
  struct timespec ts;
  struct timespec copy;
  struct timeval t;
  int res;

  try
    {
      res = 0;
      if (timeout_ms == 0) goto <D.9131>; else goto <D.9132>;
      <D.9131>:
      D.9133 = sem_trywait (sem);
      return D.9133;
      <D.9132>:
      if (timeout_ms == 4294967295) goto <D.9134>; else goto <D.9135>;
      <D.9134>:
      D.9133 = mono_sem_wait (sem, alertable);
      return D.9133;
      <D.9135>:
      gettimeofday (&t, 0B);
      D.9136 = timeout_ms / 1000;
      D.9137 = t.tv_sec;
      D.9138 = (long unsigned int) D.9137;
      D.9139 = D.9136 + D.9138;
      D.9140 = (long int) D.9139;
      ts.tv_sec = D.9140;
      D.9141 = timeout_ms % 1000;
      D.9142 = D.9141 * 1000000;
      D.9143 = t.tv_usec;
      D.9144 = D.9143 * 1000;
      D.9145 = (long unsigned int) D.9144;
      D.9146 = D.9142 + D.9145;
      D.9147 = (long int) D.9146;
      ts.tv_nsec = D.9147;
      goto <D.9109>;
      <D.9108>:
      D.9148 = ts.tv_nsec;
      D.9149 = D.9148 + -1000000000;
      ts.tv_nsec = D.9149;
      D.9150 = ts.tv_sec;
      D.9151 = D.9150 + 1;
      ts.tv_sec = D.9151;
      <D.9109>:
      D.9148 = ts.tv_nsec;
      if (D.9148 > 1000000000) goto <D.9108>; else goto <D.9110>;
      <D.9110>:
      copy = ts;
      goto <D.9113>;
      <D.9112>:
      {
        struct timeval current;

        try
          {
            if (alertable != 0) goto <D.9152>; else goto <D.9153>;
            <D.9152>:
            D.9133 = -1;
            return D.9133;
            <D.9153>:
            gettimeofday (&current, 0B);
            ts = copy;
            D.9150 = ts.tv_sec;
            D.9137 = t.tv_sec;
            D.9154 = current.tv_sec;
            D.9155 = D.9137 - D.9154;
            D.9156 = D.9150 + D.9155;
            ts.tv_sec = D.9156;
            D.9148 = ts.tv_nsec;
            D.9143 = t.tv_usec;
            D.9157 = current.tv_usec;
            D.9158 = D.9143 - D.9157;
            D.9159 = D.9158 * 1000;
            D.9160 = D.9148 + D.9159;
            ts.tv_nsec = D.9160;
            D.9148 = ts.tv_nsec;
            if (D.9148 < 0) goto <D.9161>; else goto <D.9162>;
            <D.9161>:
            D.9150 = ts.tv_sec;
            if (D.9150 <= 0) goto <D.9163>; else goto <D.9164>;
            <D.9163>:
            ts.tv_nsec = 0;
            goto <D.9165>;
            <D.9164>:
            D.9150 = ts.tv_sec;
            D.9166 = D.9150 + -1;
            ts.tv_sec = D.9166;
            D.9148 = ts.tv_nsec;
            D.9167 = D.9148 + 1000000000;
            ts.tv_nsec = D.9167;
            <D.9165>:
            <D.9162>:
            D.9150 = ts.tv_sec;
            if (D.9150 < 0) goto <D.9168>; else goto <D.9169>;
            <D.9168>:
            ts.tv_sec = 0;
            ts.tv_nsec = 0;
            <D.9169>:
          }
        finally
          {
            current = {CLOBBER};
          }
      }
      <D.9113>:
      res = sem_timedwait (sem, &ts);
      if (res == -1) goto <D.9170>; else goto <D.9114>;
      <D.9170>:
      D.9171 = __errno_location ();
      D.9172 = *D.9171;
      if (D.9172 == 4) goto <D.9112>; else goto <D.9114>;
      <D.9114>:
      if (res != 0) goto <D.9173>; else goto <D.9174>;
      <D.9173>:
      res = -1;
      <D.9174>:
      D.9133 = res;
      return D.9133;
    }
  finally
    {
      ts = {CLOBBER};
      copy = {CLOBBER};
      t = {CLOBBER};
    }
}


mono_sem_wait (union MonoSemType * sem, gboolean alertable)
{
  int D.9181;
  int * D.9183;
  int D.9184;
  int res;

  goto <D.9121>;
  <D.9120>:
  if (alertable != 0) goto <D.9179>; else goto <D.9180>;
  <D.9179>:
  D.9181 = -1;
  return D.9181;
  <D.9180>:
  <D.9121>:
  res = sem_wait (sem);
  if (res == -1) goto <D.9182>; else goto <D.9122>;
  <D.9182>:
  D.9183 = __errno_location ();
  D.9184 = *D.9183;
  if (D.9184 == 4) goto <D.9120>; else goto <D.9122>;
  <D.9122>:
  if (res != 0) goto <D.9185>; else goto <D.9186>;
  <D.9185>:
  res = -1;
  <D.9186>:
  D.9181 = res;
  return D.9181;
}


mono_sem_post (union MonoSemType * sem)
{
  int * D.9189;
  int D.9190;
  int D.9191;
  int res;

  goto <D.9128>;
  <D.9127>:
  <D.9128>:
  res = sem_post (sem);
  if (res == -1) goto <D.9188>; else goto <D.9129>;
  <D.9188>:
  D.9189 = __errno_location ();
  D.9190 = *D.9189;
  if (D.9190 == 4) goto <D.9127>; else goto <D.9129>;
  <D.9129>:
  D.9191 = res;
  return D.9191;
}


