WaitForSingleObjectEx (void * handle, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9523;
  guint32 D.9526;
  long int handle.0;
  signed int D.9532;
  int D.9535;
  int D.9538;
  int D.9543;
  long int D.9546;
  long int D.9547;
  _Bool D.9550;
  long int D.9551;
  long int D.9552;
  int D.9555;
  int D.9558;
  int D.9563;
  int D.9566;
  int D.9573;
  int D.9578;
  int D.9580;
  _Bool D.9583;
  _Bool D.9584;
  _Bool D.9585;
  int D.9588;
  guint32 ret;
  guint32 waited;
  struct timespec abstime;
  int thr_ret;
  gboolean apc_pending;
  void * current_thread;
  void check_pending = <<< error >>>;
  void done = <<< error >>>;

  try
    {
      apc_pending = 0;
      D.9523 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9523);
      if (current_thread == 0B) goto <D.9524>; else goto <D.9525>;
      <D.9524>:
      SetLastError (6);
      D.9526 = 4294967295;
      return D.9526;
      <D.9525>:
      if (handle == 4294967294B) goto <D.9527>; else goto <D.9528>;
      <D.9527>:
      D.9523 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.9523);
      if (handle == 0B) goto <D.9529>; else goto <D.9530>;
      <D.9529>:
      SetLastError (6);
      D.9526 = 4294967295;
      return D.9526;
      <D.9530>:
      <D.9528>:
      handle.0 = (long int) handle;
      D.9532 = (signed int) handle.0;
      if (D.9532 < 0) goto <D.9533>; else goto <D.9534>;
      <D.9533>:
      SetLastError (6);
      D.9526 = 4294967295;
      return D.9526;
      <D.9534>:
      D.9535 = _wapi_handle_test_capabilities (handle, 1);
      if (D.9535 == 0) goto <D.9536>; else goto <D.9537>;
      <D.9536>:
      D.9526 = 4294967295;
      return D.9526;
      <D.9537>:
      _wapi_handle_ops_prewait (handle);
      D.9538 = _wapi_handle_test_capabilities (handle, 8);
      if (D.9538 == 1) goto <D.9539>; else goto <D.9540>;
      <D.9539>:
      ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
      if (alertable != 0) goto <D.9541>; else goto <D.9542>;
      <D.9541>:
      D.9543 = _wapi_thread_apc_pending (current_thread);
      if (D.9543 != 0) goto <D.9544>; else goto <D.9545>;
      <D.9544>:
      apc_pending = 1;
      ret = 192;
      <D.9545>:
      <D.9542>:
      goto check_pending;
      <D.9540>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc2>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.9546 = (long int) __not_first_call;
            D.9547 = __builtin_expect (D.9546, 0);
            if (D.9547 != 0) goto <D.9548>; else goto <D.9549>;
            <D.9548>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9549>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9550 = thr_ret != 0;
            D.9551 = (long int) D.9550;
            D.9552 = __builtin_expect (D.9551, 0);
            if (D.9552 != 0) goto <D.9553>; else goto <D.9554>;
            <D.9553>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 147, "thr_ret == 0");
            <D.9554>:
            D.9555 = _wapi_handle_test_capabilities (handle, 4);
            if (D.9555 == 1) goto <D.9556>; else goto <D.9557>;
            <D.9556>:
            D.9558 = own_if_owned (handle);
            if (D.9558 == 1) goto <D.9559>; else goto <D.9560>;
            <D.9559>:
            ret = 0;
            goto done;
            <D.9560>:
            <D.9557>:
            if (alertable != 0) goto <D.9561>; else goto <D.9562>;
            <D.9561>:
            D.9563 = _wapi_thread_apc_pending (current_thread);
            if (D.9563 != 0) goto <D.9564>; else goto <D.9565>;
            <D.9564>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9565>:
            <D.9562>:
            D.9566 = own_if_signalled (handle);
            if (D.9566 == 1) goto <D.9567>; else goto <D.9568>;
            <D.9567>:
            ret = 0;
            goto done;
            <D.9568>:
            if (timeout == 0) goto <D.9569>; else goto <D.9570>;
            <D.9569>:
            ret = 258;
            goto done;
            <D.9570>:
            if (timeout != 4294967295) goto <D.9571>; else goto <D.9572>;
            <D.9571>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9572>:
            <D.9407>:
            _wapi_handle_ops_prewait (handle);
            D.9573 = own_if_signalled (handle);
            if (D.9573 != 0) goto <D.9574>; else goto <D.9575>;
            <D.9574>:
            ret = 0;
            goto done;
            <D.9575>:
            if (timeout == 4294967295) goto <D.9576>; else goto <D.9577>;
            <D.9576>:
            D.9578 = _wapi_handle_wait_signal_handle (handle, alertable);
            waited = (guint32) D.9578;
            goto <D.9579>;
            <D.9577>:
            D.9580 = _wapi_handle_timedwait_signal_handle (handle, &abstime, alertable, 0);
            waited = (guint32) D.9580;
            <D.9579>:
            if (alertable != 0) goto <D.9581>; else goto <D.9582>;
            <D.9581>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9582>:
            D.9583 = waited == 0;
            D.9584 = apc_pending == 0;
            D.9585 = D.9583 & D.9584;
            if (D.9585 != 0) goto <D.9586>; else goto <D.9587>;
            <D.9586>:
            D.9588 = own_if_signalled (handle);
            if (D.9588 != 0) goto <D.9589>; else goto <D.9590>;
            <D.9589>:
            ret = 0;
            goto done;
            <D.9590>:
            <D.9587>:
            D.9583 = waited == 0;
            D.9584 = apc_pending == 0;
            D.9585 = D.9583 & D.9584;
            if (D.9585 != 0) goto <D.9407>; else goto <D.9408>;
            <D.9408>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9550 = thr_ret != 0;
            D.9551 = (long int) D.9550;
            D.9552 = __builtin_expect (D.9551, 0);
            if (D.9552 != 0) goto <D.9591>; else goto <D.9592>;
            <D.9591>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 232, "thr_ret == 0");
            <D.9592>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9593>; else goto <D.9594>;
            <D.9593>:
            __cancel_routine (__cancel_arg);
            <D.9594>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      check_pending:
      if (apc_pending != 0) goto <D.9595>; else goto <D.9596>;
      <D.9595>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.9596>:
      D.9526 = ret;
      return D.9526;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  long int handle.1;
  int D.9619;
  <unnamed type> D.9622;
  <unnamed type> D.9624;
  <unnamed type> D.9626;
  <unnamed type> D.9628;
  unsigned int D.9629;
  struct _WapiHandleUnshared * D.9630;
  long unsigned int D.9631;
  long unsigned int D.9632;
  long unsigned int D.9633;
  struct _WapiHandleUnshared * D.9634;
  union mono_mutex_t * D.9635;
  guint32 idx;

  handle.1 = (long int) handle;
  idx = (guint32) handle.1;
  if (idx > 4194303) goto <D.9617>; else goto <D.9618>;
  <D.9617>:
  D.9619 = 0;
  return D.9619;
  <D.9618>:
  _wapi_handle_ref (handle);
  D.9622 = _wapi_handle_type (handle);
  if (D.9622 == 9) goto <D.9620>; else goto <D.9623>;
  <D.9623>:
  D.9624 = _wapi_handle_type (handle);
  if (D.9624 == 11) goto <D.9620>; else goto <D.9625>;
  <D.9625>:
  D.9626 = _wapi_handle_type (handle);
  if (D.9626 == 12) goto <D.9620>; else goto <D.9627>;
  <D.9627>:
  D.9628 = _wapi_handle_type (handle);
  if (D.9628 == 13) goto <D.9620>; else goto <D.9621>;
  <D.9620>:
  D.9619 = 0;
  return D.9619;
  <D.9621>:
  D.9629 = idx / 256;
  D.9630 = _wapi_private_handles[D.9629];
  D.9631 = (long unsigned int) idx;
  D.9632 = D.9631 & 255;
  D.9633 = D.9632 * 200;
  D.9634 = D.9630 + D.9633;
  D.9635 = &D.9634->signal_mutex;
  D.9619 = pthread_mutex_lock (D.9635);
  return D.9619;
}


_wapi_handle_type (void * handle)
{
  long int handle.2;
  unsigned int D.9641;
  struct _WapiHandleUnshared * D.9642;
  WapiHandleType D.9643;
  unsigned int D.9644;
  struct _WapiHandleUnshared * D.9645;
  long unsigned int D.9646;
  long unsigned int D.9647;
  long unsigned int D.9648;
  struct _WapiHandleUnshared * D.9649;
  guint32 idx;

  handle.2 = (long int) handle;
  idx = (guint32) handle.2;
  if (idx > 4194303) goto <D.9638>; else goto <D.9640>;
  <D.9640>:
  D.9641 = idx / 256;
  D.9642 = _wapi_private_handles[D.9641];
  if (D.9642 == 0B) goto <D.9638>; else goto <D.9639>;
  <D.9638>:
  D.9643 = 0;
  return D.9643;
  <D.9639>:
  D.9644 = idx / 256;
  D.9645 = _wapi_private_handles[D.9644];
  D.9646 = (long unsigned int) idx;
  D.9647 = D.9646 & 255;
  D.9648 = D.9647 * 200;
  D.9649 = D.9645 + D.9648;
  D.9643 = D.9649->type;
  return D.9643;
}


own_if_owned (void * handle)
{
  <unnamed type> D.9653;
  <unnamed type> D.9655;
  <unnamed type> D.9657;
  <unnamed type> D.9659;
  int D.9660;
  gboolean D.9663;
  int D.9664;
  <unnamed type> D.9669;
  <unnamed type> D.9671;
  <unnamed type> D.9673;
  <unnamed type> D.9675;
  gboolean ret;

  ret = 0;
  D.9653 = _wapi_handle_type (handle);
  if (D.9653 == 9) goto <D.9651>; else goto <D.9654>;
  <D.9654>:
  D.9655 = _wapi_handle_type (handle);
  if (D.9655 == 11) goto <D.9651>; else goto <D.9656>;
  <D.9656>:
  D.9657 = _wapi_handle_type (handle);
  if (D.9657 == 12) goto <D.9651>; else goto <D.9658>;
  <D.9658>:
  D.9659 = _wapi_handle_type (handle);
  if (D.9659 == 13) goto <D.9651>; else goto <D.9652>;
  <D.9651>:
  D.9660 = _wapi_handle_trylock_shared_handles ();
  if (D.9660 == 16) goto <D.9661>; else goto <D.9662>;
  <D.9661>:
  D.9663 = 0;
  return D.9663;
  <D.9662>:
  <D.9652>:
  D.9664 = _wapi_handle_ops_isowned (handle);
  if (D.9664 != 0) goto <D.9665>; else goto <D.9666>;
  <D.9665>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9666>:
  D.9669 = _wapi_handle_type (handle);
  if (D.9669 == 9) goto <D.9667>; else goto <D.9670>;
  <D.9670>:
  D.9671 = _wapi_handle_type (handle);
  if (D.9671 == 11) goto <D.9667>; else goto <D.9672>;
  <D.9672>:
  D.9673 = _wapi_handle_type (handle);
  if (D.9673 == 12) goto <D.9667>; else goto <D.9674>;
  <D.9674>:
  D.9675 = _wapi_handle_type (handle);
  if (D.9675 == 13) goto <D.9667>; else goto <D.9668>;
  <D.9667>:
  _wapi_handle_unlock_shared_handles ();
  <D.9668>:
  D.9663 = ret;
  return D.9663;
}


_wapi_handle_trylock_shared_handles ()
{
  int D.9677;

  D.9677 = _wapi_shm_sem_trylock (3);
  return D.9677;
}


_wapi_handle_unlock_shared_handles ()
{
  int D.9679;

  D.9679 = _wapi_shm_sem_unlock (3);
  return D.9679;
}


own_if_signalled (void * handle)
{
  <unnamed type> D.9683;
  <unnamed type> D.9685;
  <unnamed type> D.9687;
  <unnamed type> D.9689;
  int D.9690;
  gboolean D.9693;
  int D.9694;
  <unnamed type> D.9699;
  <unnamed type> D.9701;
  <unnamed type> D.9703;
  <unnamed type> D.9705;
  gboolean ret;

  ret = 0;
  D.9683 = _wapi_handle_type (handle);
  if (D.9683 == 9) goto <D.9681>; else goto <D.9684>;
  <D.9684>:
  D.9685 = _wapi_handle_type (handle);
  if (D.9685 == 11) goto <D.9681>; else goto <D.9686>;
  <D.9686>:
  D.9687 = _wapi_handle_type (handle);
  if (D.9687 == 12) goto <D.9681>; else goto <D.9688>;
  <D.9688>:
  D.9689 = _wapi_handle_type (handle);
  if (D.9689 == 13) goto <D.9681>; else goto <D.9682>;
  <D.9681>:
  D.9690 = _wapi_handle_trylock_shared_handles ();
  if (D.9690 == 16) goto <D.9691>; else goto <D.9692>;
  <D.9691>:
  D.9693 = 0;
  return D.9693;
  <D.9692>:
  <D.9682>:
  D.9694 = _wapi_handle_issignalled (handle);
  if (D.9694 != 0) goto <D.9695>; else goto <D.9696>;
  <D.9695>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9696>:
  D.9699 = _wapi_handle_type (handle);
  if (D.9699 == 9) goto <D.9697>; else goto <D.9700>;
  <D.9700>:
  D.9701 = _wapi_handle_type (handle);
  if (D.9701 == 11) goto <D.9697>; else goto <D.9702>;
  <D.9702>:
  D.9703 = _wapi_handle_type (handle);
  if (D.9703 == 12) goto <D.9697>; else goto <D.9704>;
  <D.9704>:
  D.9705 = _wapi_handle_type (handle);
  if (D.9705 == 13) goto <D.9697>; else goto <D.9698>;
  <D.9697>:
  _wapi_handle_unlock_shared_handles ();
  <D.9698>:
  D.9693 = ret;
  return D.9693;
}


_wapi_handle_issignalled (void * handle)
{
  long int handle.3;
  gboolean D.9710;
  <unnamed type> D.9713;
  <unnamed type> D.9715;
  <unnamed type> D.9717;
  <unnamed type> D.9719;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.4;
  unsigned int D.9721;
  unsigned int D.9722;
  struct _WapiHandleUnshared * D.9723;
  long unsigned int D.9724;
  long unsigned int D.9725;
  long unsigned int D.9726;
  struct _WapiHandleUnshared * D.9727;
  unsigned int D.9728;
  unsigned int D.9729;
  struct _WapiHandleUnshared * D.9730;
  long unsigned int D.9731;
  long unsigned int D.9732;
  long unsigned int D.9733;
  struct _WapiHandleUnshared * D.9734;
  guint32 idx;

  handle.3 = (long int) handle;
  idx = (guint32) handle.3;
  if (idx > 4194303) goto <D.9708>; else goto <D.9709>;
  <D.9708>:
  D.9710 = 0;
  return D.9710;
  <D.9709>:
  D.9713 = _wapi_handle_type (handle);
  if (D.9713 == 9) goto <D.9711>; else goto <D.9714>;
  <D.9714>:
  D.9715 = _wapi_handle_type (handle);
  if (D.9715 == 11) goto <D.9711>; else goto <D.9716>;
  <D.9716>:
  D.9717 = _wapi_handle_type (handle);
  if (D.9717 == 12) goto <D.9711>; else goto <D.9718>;
  <D.9718>:
  D.9719 = _wapi_handle_type (handle);
  if (D.9719 == 13) goto <D.9711>; else goto <D.9712>;
  <D.9711>:
  _wapi_shared_layout.4 = _wapi_shared_layout;
  handle.3 = (long int) handle;
  D.9721 = (unsigned int) handle.3;
  D.9722 = D.9721 / 256;
  D.9723 = _wapi_private_handles[D.9722];
  handle.3 = (long int) handle;
  D.9721 = (unsigned int) handle.3;
  D.9724 = (long unsigned int) D.9721;
  D.9725 = D.9724 & 255;
  D.9726 = D.9725 * 200;
  D.9727 = D.9723 + D.9726;
  D.9728 = D.9727->u.shared.offset;
  D.9710 = _wapi_shared_layout.4->handles[D.9728].signalled;
  return D.9710;
  <D.9712>:
  D.9729 = idx / 256;
  D.9730 = _wapi_private_handles[D.9729];
  D.9731 = (long unsigned int) idx;
  D.9732 = D.9731 & 255;
  D.9733 = D.9732 * 200;
  D.9734 = D.9730 + D.9733;
  D.9710 = D.9734->signalled;
  return D.9710;
}


_wapi_handle_unlock_handle (void * handle)
{
  long int handle.5;
  int D.9739;
  <unnamed type> D.9742;
  <unnamed type> D.9744;
  <unnamed type> D.9746;
  <unnamed type> D.9748;
  unsigned int D.9749;
  struct _WapiHandleUnshared * D.9750;
  long unsigned int D.9751;
  long unsigned int D.9752;
  long unsigned int D.9753;
  struct _WapiHandleUnshared * D.9754;
  union mono_mutex_t * D.9755;
  guint32 idx;
  int ret;

  handle.5 = (long int) handle;
  idx = (guint32) handle.5;
  if (idx > 4194303) goto <D.9737>; else goto <D.9738>;
  <D.9737>:
  D.9739 = 0;
  return D.9739;
  <D.9738>:
  D.9742 = _wapi_handle_type (handle);
  if (D.9742 == 9) goto <D.9740>; else goto <D.9743>;
  <D.9743>:
  D.9744 = _wapi_handle_type (handle);
  if (D.9744 == 11) goto <D.9740>; else goto <D.9745>;
  <D.9745>:
  D.9746 = _wapi_handle_type (handle);
  if (D.9746 == 12) goto <D.9740>; else goto <D.9747>;
  <D.9747>:
  D.9748 = _wapi_handle_type (handle);
  if (D.9748 == 13) goto <D.9740>; else goto <D.9741>;
  <D.9740>:
  _wapi_handle_unref (handle);
  D.9739 = 0;
  return D.9739;
  <D.9741>:
  D.9749 = idx / 256;
  D.9750 = _wapi_private_handles[D.9749];
  D.9751 = (long unsigned int) idx;
  D.9752 = D.9751 & 255;
  D.9753 = D.9752 * 200;
  D.9754 = D.9750 + D.9753;
  D.9755 = &D.9754->signal_mutex;
  ret = pthread_mutex_unlock (D.9755);
  _wapi_handle_unref (handle);
  D.9739 = ret;
  return D.9739;
}


WaitForSingleObject (void * handle, guint32 timeout)
{
  guint32 D.9757;

  D.9757 = WaitForSingleObjectEx (handle, timeout, 0);
  return D.9757;
}


SignalObjectAndWait (void * signal_handle, void * wait, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9759;
  guint32 D.9762;
  long int signal_handle.6;
  signed int D.9772;
  long int wait.7;
  signed int D.9776;
  int D.9779;
  int D.9782;
  int D.9785;
  long int D.9788;
  long int D.9789;
  _Bool D.9792;
  long int D.9793;
  long int D.9794;
  int D.9797;
  int D.9800;
  int D.9805;
  int D.9808;
  int D.9813;
  int D.9818;
  int D.9820;
  _Bool D.9823;
  _Bool D.9824;
  _Bool D.9825;
  int D.9828;
  guint32 ret;
  guint32 waited;
  struct timespec abstime;
  int thr_ret;
  gboolean apc_pending;
  void * current_thread;
  static const char __func__[20] = "SignalObjectAndWait";
  void done = <<< error >>>;

  try
    {
      apc_pending = 0;
      D.9759 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9759);
      if (current_thread == 0B) goto <D.9760>; else goto <D.9761>;
      <D.9760>:
      SetLastError (6);
      D.9762 = 4294967295;
      return D.9762;
      <D.9761>:
      if (signal_handle == 4294967294B) goto <D.9763>; else goto <D.9764>;
      <D.9763>:
      D.9759 = pthread_self ();
      signal_handle = _wapi_thread_handle_from_id (D.9759);
      if (signal_handle == 0B) goto <D.9765>; else goto <D.9766>;
      <D.9765>:
      SetLastError (6);
      D.9762 = 4294967295;
      return D.9762;
      <D.9766>:
      <D.9764>:
      if (wait == 4294967294B) goto <D.9767>; else goto <D.9768>;
      <D.9767>:
      D.9759 = pthread_self ();
      wait = _wapi_thread_handle_from_id (D.9759);
      if (wait == 0B) goto <D.9769>; else goto <D.9770>;
      <D.9769>:
      SetLastError (6);
      D.9762 = 4294967295;
      return D.9762;
      <D.9770>:
      <D.9768>:
      signal_handle.6 = (long int) signal_handle;
      D.9772 = (signed int) signal_handle.6;
      if (D.9772 < 0) goto <D.9773>; else goto <D.9774>;
      <D.9773>:
      SetLastError (6);
      D.9762 = 4294967295;
      return D.9762;
      <D.9774>:
      wait.7 = (long int) wait;
      D.9776 = (signed int) wait.7;
      if (D.9776 < 0) goto <D.9777>; else goto <D.9778>;
      <D.9777>:
      SetLastError (6);
      D.9762 = 4294967295;
      return D.9762;
      <D.9778>:
      D.9779 = _wapi_handle_test_capabilities (signal_handle, 2);
      if (D.9779 == 0) goto <D.9780>; else goto <D.9781>;
      <D.9780>:
      D.9762 = 4294967295;
      return D.9762;
      <D.9781>:
      D.9782 = _wapi_handle_test_capabilities (wait, 1);
      if (D.9782 == 0) goto <D.9783>; else goto <D.9784>;
      <D.9783>:
      D.9762 = 4294967295;
      return D.9762;
      <D.9784>:
      _wapi_handle_ops_prewait (wait);
      D.9785 = _wapi_handle_test_capabilities (wait, 8);
      if (D.9785 == 1) goto <D.9786>; else goto <D.9787>;
      <D.9786>:
      monoeg_g_log (0B, 16, "%s: handle %p has special wait, implement me!!", &__func__, wait);
      D.9762 = 4294967295;
      return D.9762;
      <D.9787>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc2>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = wait;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.9788 = (long int) __not_first_call;
            D.9789 = __builtin_expect (D.9788, 0);
            if (D.9789 != 0) goto <D.9790>; else goto <D.9791>;
            <D.9790>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9791>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (wait);
            D.9792 = thr_ret != 0;
            D.9793 = (long int) D.9792;
            D.9794 = __builtin_expect (D.9793, 0);
            if (D.9794 != 0) goto <D.9795>; else goto <D.9796>;
            <D.9795>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 349, "thr_ret == 0");
            <D.9796>:
            _wapi_handle_ops_signal (signal_handle);
            D.9797 = _wapi_handle_test_capabilities (wait, 4);
            if (D.9797 == 1) goto <D.9798>; else goto <D.9799>;
            <D.9798>:
            D.9800 = own_if_owned (wait);
            if (D.9800 != 0) goto <D.9801>; else goto <D.9802>;
            <D.9801>:
            ret = 0;
            goto done;
            <D.9802>:
            <D.9799>:
            if (alertable != 0) goto <D.9803>; else goto <D.9804>;
            <D.9803>:
            D.9805 = _wapi_thread_apc_pending (current_thread);
            if (D.9805 != 0) goto <D.9806>; else goto <D.9807>;
            <D.9806>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9807>:
            <D.9804>:
            D.9808 = own_if_signalled (wait);
            if (D.9808 != 0) goto <D.9809>; else goto <D.9810>;
            <D.9809>:
            ret = 0;
            goto done;
            <D.9810>:
            if (timeout != 4294967295) goto <D.9811>; else goto <D.9812>;
            <D.9811>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9812>:
            <D.9433>:
            _wapi_handle_ops_prewait (wait);
            D.9813 = own_if_signalled (wait);
            if (D.9813 != 0) goto <D.9814>; else goto <D.9815>;
            <D.9814>:
            ret = 0;
            goto done;
            <D.9815>:
            if (timeout == 4294967295) goto <D.9816>; else goto <D.9817>;
            <D.9816>:
            D.9818 = _wapi_handle_wait_signal_handle (wait, alertable);
            waited = (guint32) D.9818;
            goto <D.9819>;
            <D.9817>:
            D.9820 = _wapi_handle_timedwait_signal_handle (wait, &abstime, alertable, 0);
            waited = (guint32) D.9820;
            <D.9819>:
            if (alertable != 0) goto <D.9821>; else goto <D.9822>;
            <D.9821>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9822>:
            D.9823 = waited == 0;
            D.9824 = apc_pending == 0;
            D.9825 = D.9823 & D.9824;
            if (D.9825 != 0) goto <D.9826>; else goto <D.9827>;
            <D.9826>:
            D.9828 = own_if_signalled (wait);
            if (D.9828 != 0) goto <D.9829>; else goto <D.9830>;
            <D.9829>:
            ret = 0;
            goto done;
            <D.9830>:
            <D.9827>:
            D.9823 = waited == 0;
            D.9824 = apc_pending == 0;
            D.9825 = D.9823 & D.9824;
            if (D.9825 != 0) goto <D.9433>; else goto <D.9434>;
            <D.9434>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (wait);
            D.9792 = thr_ret != 0;
            D.9793 = (long int) D.9792;
            D.9794 = __builtin_expect (D.9793, 0);
            if (D.9794 != 0) goto <D.9831>; else goto <D.9832>;
            <D.9831>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 430, "thr_ret == 0");
            <D.9832>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9833>; else goto <D.9834>;
            <D.9833>:
            __cancel_routine (__cancel_arg);
            <D.9834>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (apc_pending != 0) goto <D.9835>; else goto <D.9836>;
      <D.9835>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.9836>:
      D.9762 = ret;
      return D.9762;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


WaitForMultipleObjectsEx (guint32 numobjects, void * * handles, gboolean waitall, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9856;
  guint32 D.9859;
  void * D.9864;
  long unsigned int D.9865;
  long unsigned int D.9866;
  void * * D.9867;
  void * D.9868;
  void * D.9871;
  long int D.9874;
  signed int D.9875;
  int D.9878;
  long unsigned int D.9881;
  unsigned int D.9882;
  void * D.9883;
  void * D.9884;
  <unnamed type> D.9893;
  <unnamed type> D.9895;
  <unnamed type> D.9897;
  <unnamed type> D.9899;
  <unnamed type> D.9901;
  int D.9910;
  int D.9913;
  int D.9916;
  long int D.9919;
  long int D.9920;
  _Bool D.9923;
  long int D.9924;
  long int D.9925;
  int D.9930;
  int D.9934;
  int D.9941;
  int D.9943;
  int D.9951;
  gboolean duplicate;
  gboolean bogustype;
  gboolean done;
  guint32 count;
  guint32 lowest;
  struct timespec abstime;
  guint i;
  guint32 ret;
  int thr_ret;
  void * current_thread;
  guint32 retval;
  gboolean poll;
  void * sorted_handles[64];

  try
    {
      duplicate = 0;
      bogustype = 0;
      D.9856 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9856);
      if (current_thread == 0B) goto <D.9857>; else goto <D.9858>;
      <D.9857>:
      SetLastError (6);
      D.9859 = 4294967295;
      return D.9859;
      <D.9858>:
      if (numobjects > 64) goto <D.9860>; else goto <D.9861>;
      <D.9860>:
      D.9859 = 4294967295;
      return D.9859;
      <D.9861>:
      if (numobjects == 1) goto <D.9862>; else goto <D.9863>;
      <D.9862>:
      D.9864 = *handles;
      D.9859 = WaitForSingleObjectEx (D.9864, timeout, alertable);
      return D.9859;
      <D.9863>:
      i = 0;
      goto <D.9482>;
      <D.9481>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      if (D.9868 == 4294967294B) goto <D.9869>; else goto <D.9870>;
      <D.9869>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9856 = pthread_self ();
      D.9871 = _wapi_thread_handle_from_id (D.9856);
      *D.9867 = D.9871;
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      if (D.9868 == 0B) goto <D.9872>; else goto <D.9873>;
      <D.9872>:
      bogustype = 1;
      goto <D.9480>;
      <D.9873>:
      <D.9870>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9874 = (long int) D.9868;
      D.9875 = (signed int) D.9874;
      if (D.9875 < 0) goto <D.9876>; else goto <D.9877>;
      <D.9876>:
      bogustype = 1;
      goto <D.9480>;
      <D.9877>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9878 = _wapi_handle_test_capabilities (D.9868, 1);
      if (D.9878 == 0) goto <D.9879>; else goto <D.9880>;
      <D.9879>:
      bogustype = 1;
      goto <D.9480>;
      <D.9880>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      sorted_handles[i] = D.9868;
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      _wapi_handle_ops_prewait (D.9868);
      i = i + 1;
      <D.9482>:
      if (i < numobjects) goto <D.9481>; else goto <D.9480>;
      <D.9480>:
      D.9881 = (long unsigned int) numobjects;
      qsort (&sorted_handles, D.9881, 8, monoeg_g_direct_equal);
      i = 1;
      goto <D.9485>;
      <D.9484>:
      D.9882 = i + 4294967295;
      D.9883 = sorted_handles[D.9882];
      D.9884 = sorted_handles[i];
      if (D.9883 == D.9884) goto <D.9885>; else goto <D.9886>;
      <D.9885>:
      duplicate = 1;
      goto <D.9483>;
      <D.9886>:
      i = i + 1;
      <D.9485>:
      if (i < numobjects) goto <D.9484>; else goto <D.9483>;
      <D.9483>:
      if (duplicate == 1) goto <D.9887>; else goto <D.9888>;
      <D.9887>:
      D.9859 = 4294967295;
      return D.9859;
      <D.9888>:
      if (bogustype == 1) goto <D.9889>; else goto <D.9890>;
      <D.9889>:
      D.9859 = 4294967295;
      return D.9859;
      <D.9890>:
      poll = 0;
      i = 0;
      goto <D.9487>;
      <D.9486>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9893 = _wapi_handle_type (D.9868);
      if (D.9893 == 9) goto <D.9891>; else goto <D.9894>;
      <D.9894>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9895 = _wapi_handle_type (D.9868);
      if (D.9895 == 9) goto <D.9891>; else goto <D.9896>;
      <D.9896>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9897 = _wapi_handle_type (D.9868);
      if (D.9897 == 11) goto <D.9891>; else goto <D.9898>;
      <D.9898>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9899 = _wapi_handle_type (D.9868);
      if (D.9899 == 12) goto <D.9891>; else goto <D.9900>;
      <D.9900>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9901 = _wapi_handle_type (D.9868);
      if (D.9901 == 13) goto <D.9891>; else goto <D.9892>;
      <D.9891>:
      poll = 1;
      <D.9892>:
      i = i + 1;
      <D.9487>:
      if (i < numobjects) goto <D.9486>; else goto <D.9488>;
      <D.9488>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.9902>; else goto <D.9903>;
      <D.9902>:
      D.9859 = lowest;
      return D.9859;
      <D.9903>:
      if (timeout == 0) goto <D.9904>; else goto <D.9905>;
      <D.9904>:
      D.9859 = 258;
      return D.9859;
      <D.9905>:
      if (timeout != 4294967295) goto <D.9906>; else goto <D.9907>;
      <D.9906>:
      _wapi_calc_timeout (&abstime, timeout);
      <D.9907>:
      if (alertable != 0) goto <D.9908>; else goto <D.9909>;
      <D.9908>:
      D.9910 = _wapi_thread_apc_pending (current_thread);
      if (D.9910 != 0) goto <D.9911>; else goto <D.9912>;
      <D.9911>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.9859 = 192;
      return D.9859;
      <D.9912>:
      <D.9909>:
      i = 0;
      goto <D.9490>;
      <D.9489>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      _wapi_handle_ref (D.9868);
      i = i + 1;
      <D.9490>:
      if (i < numobjects) goto <D.9489>; else goto <D.9491>;
      <D.9491>:
      <D.9508>:
      i = 0;
      goto <D.9493>;
      <D.9492>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      _wapi_handle_ops_prewait (D.9868);
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9913 = _wapi_handle_test_capabilities (D.9868, 8);
      if (D.9913 == 1) goto <D.9914>; else goto <D.9915>;
      <D.9914>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      D.9916 = _wapi_handle_issignalled (D.9868);
      if (D.9916 == 0) goto <D.9917>; else goto <D.9918>;
      <D.9917>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      _wapi_handle_ops_special_wait (D.9868, 0, alertable);
      <D.9918>:
      <D.9915>:
      i = i + 1;
      <D.9493>:
      if (i < numobjects) goto <D.9492>; else goto <D.9494>;
      <D.9494>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc2>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_signal_mutex;
            __cancel_arg = 0B;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.9919 = (long int) __not_first_call;
            D.9920 = __builtin_expect (D.9919, 0);
            if (D.9920 != 0) goto <D.9921>; else goto <D.9922>;
            <D.9921>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9922>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_signal_mutex ();
            D.9923 = thr_ret != 0;
            D.9924 = (long int) D.9923;
            D.9925 = __builtin_expect (D.9924, 0);
            if (D.9925 != 0) goto <D.9926>; else goto <D.9927>;
            <D.9926>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 650, "thr_ret == 0");
            <D.9927>:
            if (waitall != 0) goto <D.9928>; else goto <D.9929>;
            <D.9928>:
            done = 1;
            i = 0;
            goto <D.9502>;
            <D.9501>:
            D.9865 = (long unsigned int) i;
            D.9866 = D.9865 * 8;
            D.9867 = handles + D.9866;
            D.9868 = *D.9867;
            D.9930 = _wapi_handle_issignalled (D.9868);
            if (D.9930 == 0) goto <D.9931>; else goto <D.9932>;
            <D.9931>:
            done = 0;
            <D.9932>:
            i = i + 1;
            <D.9502>:
            if (i < numobjects) goto <D.9501>; else goto <D.9503>;
            <D.9503>:
            goto <D.9933>;
            <D.9929>:
            done = 0;
            i = 0;
            goto <D.9505>;
            <D.9504>:
            D.9865 = (long unsigned int) i;
            D.9866 = D.9865 * 8;
            D.9867 = handles + D.9866;
            D.9868 = *D.9867;
            D.9934 = _wapi_handle_issignalled (D.9868);
            if (D.9934 != 0) goto <D.9935>; else goto <D.9936>;
            <D.9935>:
            done = 1;
            <D.9936>:
            i = i + 1;
            <D.9505>:
            if (i < numobjects) goto <D.9504>; else goto <D.9506>;
            <D.9506>:
            <D.9933>:
            if (done == 0) goto <D.9937>; else goto <D.9938>;
            <D.9937>:
            if (timeout == 4294967295) goto <D.9939>; else goto <D.9940>;
            <D.9939>:
            D.9941 = _wapi_handle_wait_signal (poll);
            ret = (guint32) D.9941;
            goto <D.9942>;
            <D.9940>:
            D.9943 = _wapi_handle_timedwait_signal (&abstime, poll);
            ret = (guint32) D.9943;
            <D.9942>:
            goto <D.9944>;
            <D.9938>:
            ret = 0;
            <D.9944>:
            thr_ret = _wapi_handle_unlock_signal_mutex (0B);
            D.9923 = thr_ret != 0;
            D.9924 = (long int) D.9923;
            D.9925 = __builtin_expect (D.9924, 0);
            if (D.9925 != 0) goto <D.9945>; else goto <D.9946>;
            <D.9945>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 680, "thr_ret == 0");
            <D.9946>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9947>; else goto <D.9948>;
            <D.9947>:
            __cancel_routine (__cancel_arg);
            <D.9948>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (alertable != 0) goto <D.9949>; else goto <D.9950>;
      <D.9949>:
      D.9951 = _wapi_thread_apc_pending (current_thread);
      if (D.9951 != 0) goto <D.9952>; else goto <D.9953>;
      <D.9952>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      retval = 192;
      goto <D.9507>;
      <D.9953>:
      <D.9950>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.9954>; else goto <D.9955>;
      <D.9954>:
      retval = lowest;
      goto <D.9507>;
      <D.9955>:
      if (ret != 0) goto <D.9956>; else goto <D.9957>;
      <D.9956>:
      if (ret == 110) goto <D.9958>; else goto <D.9959>;
      <D.9958>:
      retval = 258;
      goto <D.9960>;
      <D.9959>:
      retval = 4294967295;
      <D.9960>:
      goto <D.9507>;
      <D.9957>:
      goto <D.9508>;
      <D.9507>:
      i = 0;
      goto <D.9510>;
      <D.9509>:
      D.9865 = (long unsigned int) i;
      D.9866 = D.9865 * 8;
      D.9867 = handles + D.9866;
      D.9868 = *D.9867;
      _wapi_handle_unref (D.9868);
      i = i + 1;
      <D.9510>:
      if (i < numobjects) goto <D.9509>; else goto <D.9511>;
      <D.9511>:
      D.9859 = retval;
      return D.9859;
    }
  finally
    {
      count = {CLOBBER};
      lowest = {CLOBBER};
      abstime = {CLOBBER};
      sorted_handles = {CLOBBER};
    }
}


_wapi_handle_lock_signal_mutex ()
{
  int D.9984;
  union mono_mutex_t * _wapi_global_signal_mutex.8;

  _wapi_global_signal_mutex.8 = _wapi_global_signal_mutex;
  D.9984 = pthread_mutex_lock (_wapi_global_signal_mutex.8);
  return D.9984;
}


_wapi_handle_unlock_signal_mutex (void * unused)
{
  int D.9987;
  union mono_mutex_t * _wapi_global_signal_mutex.9;

  _wapi_global_signal_mutex.9 = _wapi_global_signal_mutex;
  D.9987 = pthread_mutex_unlock (_wapi_global_signal_mutex.9);
  return D.9987;
}


test_and_own (guint32 numobjects, void * * handles, gboolean waitall, guint32 * count, guint32 * lowest)
{
  long int D.9990;
  long int D.9991;
  long unsigned int D.9998;
  long unsigned int D.9999;
  void * * D.10000;
  void * D.10001;
  unsigned int i.10;
  unsigned int D.10004;
  long unsigned int D.10005;
  long unsigned int D.10006;
  void * * D.10007;
  void * D.10008;
  gboolean D.10011;
  struct handle_cleanup_data cleanup_data;
  gboolean done;
  int i;

  try
    {
      cleanup_data.numobjects = numobjects;
      cleanup_data.handles = handles;
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc2>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = handle_cleanup;
            __cancel_arg = &cleanup_data;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.9990 = (long int) __not_first_call;
            D.9991 = __builtin_expect (D.9990, 0);
            if (D.9991 != 0) goto <D.9992>; else goto <D.9993>;
            <D.9992>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9993>:
            __pthread_register_cancel (&__cancel_buf);
            done = _wapi_handle_count_signalled_handles (numobjects, handles, waitall, count, lowest);
            if (done == 1) goto <D.9994>; else goto <D.9995>;
            <D.9994>:
            if (waitall == 1) goto <D.9996>; else goto <D.9997>;
            <D.9996>:
            i = 0;
            goto <D.9458>;
            <D.9457>:
            D.9998 = (long unsigned int) i;
            D.9999 = D.9998 * 8;
            D.10000 = handles + D.9999;
            D.10001 = *D.10000;
            own_if_signalled (D.10001);
            i = i + 1;
            <D.9458>:
            i.10 = (unsigned int) i;
            if (i.10 < numobjects) goto <D.9457>; else goto <D.9459>;
            <D.9459>:
            goto <D.10003>;
            <D.9997>:
            D.10004 = *lowest;
            D.10005 = (long unsigned int) D.10004;
            D.10006 = D.10005 * 8;
            D.10007 = handles + D.10006;
            D.10008 = *D.10007;
            own_if_signalled (D.10008);
            <D.10003>:
            <D.9995>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (1 != 0) goto <D.10009>; else goto <D.10010>;
            <D.10009>:
            __cancel_routine (__cancel_arg);
            <D.10010>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.10011 = done;
      return D.10011;
    }
  finally
    {
      cleanup_data = {CLOBBER};
    }
}


handle_cleanup (void * data)
{
  void * * D.10015;
  unsigned int D.10016;
  struct handle_cleanup_data * handles;

  handles = data;
  D.10015 = handles->handles;
  D.10016 = handles->numobjects;
  _wapi_handle_unlock_handles (D.10016, D.10015);
}


WaitForMultipleObjects (guint32 numobjects, void * * handles, gboolean waitall, guint32 timeout)
{
  guint32 D.10017;

  D.10017 = WaitForMultipleObjectsEx (numobjects, handles, waitall, timeout, 0);
  return D.10017;
}


WaitForInputIdle (void * handle, guint32 timeout)
{
  guint32 D.10019;

  D.10019 = 258;
  return D.10019;
}


