mono_sem_timedwait (union MonoSemType * sem, guint32 timeout_ms, gboolean alertable)
{
  int D.9631;
  unsigned int D.9634;
  long int D.9635;
  long int D.9636;
  long int D.9637;
  unsigned int D.9638;
  unsigned int D.9639;
  long int D.9640;
  long int D.9641;
  long int D.9642;
  long int D.9643;
  long int D.9644;
  long int D.9645;
  long int D.9646;
  long int D.9647;
  long int D.9650;
  long int D.9651;
  long int D.9652;
  long int D.9653;
  long int D.9654;
  long int D.9655;
  long int D.9656;
  long int D.9662;
  long int D.9663;
  int * D.9667;
  int D.9668;
  struct timespec ts;
  struct timespec copy;
  struct timeval t;
  int res;

  try
    {
      res = 0;
      if (timeout_ms == 0) goto <D.9629>; else goto <D.9630>;
      <D.9629>:
      D.9631 = sem_trywait (sem);
      return D.9631;
      <D.9630>:
      if (timeout_ms == 4294967295) goto <D.9632>; else goto <D.9633>;
      <D.9632>:
      D.9631 = mono_sem_wait (sem, alertable);
      return D.9631;
      <D.9633>:
      gettimeofday (&t, 0B);
      D.9634 = timeout_ms / 1000;
      D.9635 = (long int) D.9634;
      D.9636 = t.tv_sec;
      D.9637 = D.9635 + D.9636;
      ts.tv_sec = D.9637;
      D.9638 = timeout_ms % 1000;
      D.9639 = D.9638 * 1000000;
      D.9640 = (long int) D.9639;
      D.9641 = t.tv_usec;
      D.9642 = D.9641 * 1000;
      D.9643 = D.9640 + D.9642;
      ts.tv_nsec = D.9643;
      goto <D.9607>;
      <D.9606>:
      D.9644 = ts.tv_nsec;
      D.9645 = D.9644 + -1000000000;
      ts.tv_nsec = D.9645;
      D.9646 = ts.tv_sec;
      D.9647 = D.9646 + 1;
      ts.tv_sec = D.9647;
      <D.9607>:
      D.9644 = ts.tv_nsec;
      if (D.9644 > 1000000000) goto <D.9606>; else goto <D.9608>;
      <D.9608>:
      copy = ts;
      goto <D.9611>;
      <D.9610>:
      {
        struct timeval current;

        try
          {
            if (alertable != 0) goto <D.9648>; else goto <D.9649>;
            <D.9648>:
            D.9631 = -1;
            return D.9631;
            <D.9649>:
            gettimeofday (&current, 0B);
            ts = copy;
            D.9646 = ts.tv_sec;
            D.9650 = current.tv_sec;
            D.9636 = t.tv_sec;
            D.9651 = D.9650 - D.9636;
            D.9652 = D.9646 - D.9651;
            ts.tv_sec = D.9652;
            D.9644 = ts.tv_nsec;
            D.9653 = current.tv_usec;
            D.9641 = t.tv_usec;
            D.9654 = D.9653 - D.9641;
            D.9655 = D.9654 * -1000;
            D.9656 = D.9644 + D.9655;
            ts.tv_nsec = D.9656;
            D.9644 = ts.tv_nsec;
            if (D.9644 < 0) goto <D.9657>; else goto <D.9658>;
            <D.9657>:
            D.9646 = ts.tv_sec;
            if (D.9646 <= 0) goto <D.9659>; else goto <D.9660>;
            <D.9659>:
            ts.tv_nsec = 0;
            goto <D.9661>;
            <D.9660>:
            D.9646 = ts.tv_sec;
            D.9662 = D.9646 + -1;
            ts.tv_sec = D.9662;
            D.9644 = ts.tv_nsec;
            D.9663 = D.9644 + 1000000000;
            ts.tv_nsec = D.9663;
            <D.9661>:
            <D.9658>:
            D.9646 = ts.tv_sec;
            if (D.9646 < 0) goto <D.9664>; else goto <D.9665>;
            <D.9664>:
            ts.tv_sec = 0;
            ts.tv_nsec = 0;
            <D.9665>:
          }
        finally
          {
            current = {CLOBBER};
          }
      }
      <D.9611>:
      res = sem_timedwait (sem, &ts);
      if (res == -1) goto <D.9666>; else goto <D.9612>;
      <D.9666>:
      D.9667 = __errno_location ();
      D.9668 = *D.9667;
      if (D.9668 == 4) goto <D.9610>; else goto <D.9612>;
      <D.9612>:
      if (res != 0) goto <D.9669>; else goto <D.9670>;
      <D.9669>:
      res = -1;
      <D.9670>:
      D.9631 = res;
      return D.9631;
    }
  finally
    {
      ts = {CLOBBER};
      copy = {CLOBBER};
      t = {CLOBBER};
    }
}


mono_sem_wait (union MonoSemType * sem, gboolean alertable)
{
  int D.9677;
  int * D.9679;
  int D.9680;
  int res;

  goto <D.9619>;
  <D.9618>:
  if (alertable != 0) goto <D.9675>; else goto <D.9676>;
  <D.9675>:
  D.9677 = -1;
  return D.9677;
  <D.9676>:
  <D.9619>:
  res = sem_wait (sem);
  if (res == -1) goto <D.9678>; else goto <D.9620>;
  <D.9678>:
  D.9679 = __errno_location ();
  D.9680 = *D.9679;
  if (D.9680 == 4) goto <D.9618>; else goto <D.9620>;
  <D.9620>:
  if (res != 0) goto <D.9681>; else goto <D.9682>;
  <D.9681>:
  res = -1;
  <D.9682>:
  D.9677 = res;
  return D.9677;
}


mono_sem_post (union MonoSemType * sem)
{
  int * D.9685;
  int D.9686;
  int D.9687;
  int res;

  goto <D.9626>;
  <D.9625>:
  <D.9626>:
  res = sem_post (sem);
  if (res == -1) goto <D.9684>; else goto <D.9627>;
  <D.9684>:
  D.9685 = __errno_location ();
  D.9686 = *D.9685;
  if (D.9686 == 4) goto <D.9625>; else goto <D.9627>;
  <D.9627>:
  D.9687 = res;
  return D.9687;
}


