WaitForSingleObjectEx (void * handle, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9219;
  guint32 D.9222;
  signed int handle.0;
  int D.9230;
  int D.9233;
  int D.9238;
  long int D.9241;
  _Bool D.9244;
  long int D.9245;
  long int D.9246;
  int D.9249;
  int D.9252;
  int D.9257;
  int D.9260;
  int D.9267;
  int D.9272;
  int D.9274;
  int D.9281;
  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.9219 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9219);
      if (current_thread == 0B) goto <D.9220>; else goto <D.9221>;
      <D.9220>:
      SetLastError (6);
      D.9222 = 4294967295;
      return D.9222;
      <D.9221>:
      if (handle == 4294967294B) goto <D.9223>; else goto <D.9224>;
      <D.9223>:
      D.9219 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.9219);
      if (handle == 0B) goto <D.9225>; else goto <D.9226>;
      <D.9225>:
      SetLastError (6);
      D.9222 = 4294967295;
      return D.9222;
      <D.9226>:
      <D.9224>:
      handle.0 = (signed int) handle;
      if (handle.0 < 0) goto <D.9228>; else goto <D.9229>;
      <D.9228>:
      SetLastError (6);
      D.9222 = 4294967295;
      return D.9222;
      <D.9229>:
      D.9230 = _wapi_handle_test_capabilities (handle, 1);
      if (D.9230 == 0) goto <D.9231>; else goto <D.9232>;
      <D.9231>:
      D.9222 = 4294967295;
      return D.9222;
      <D.9232>:
      _wapi_handle_ops_prewait (handle);
      D.9233 = _wapi_handle_test_capabilities (handle, 8);
      if (D.9233 == 1) goto <D.9234>; else goto <D.9235>;
      <D.9234>:
      ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
      if (alertable != 0) goto <D.9236>; else goto <D.9237>;
      <D.9236>:
      D.9238 = _wapi_thread_apc_pending (current_thread);
      if (D.9238 != 0) goto <D.9239>; else goto <D.9240>;
      <D.9239>:
      apc_pending = 1;
      ret = 192;
      <D.9240>:
      <D.9237>:
      goto check_pending;
      <D.9235>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (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.9241 = __builtin_expect (__not_first_call, 0);
            if (D.9241 != 0) goto <D.9242>; else goto <D.9243>;
            <D.9242>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9243>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9244 = thr_ret != 0;
            D.9245 = (long int) D.9244;
            D.9246 = __builtin_expect (D.9245, 0);
            if (D.9246 != 0) goto <D.9247>; else goto <D.9248>;
            <D.9247>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 147, "thr_ret == 0");
            <D.9248>:
            D.9249 = _wapi_handle_test_capabilities (handle, 4);
            if (D.9249 == 1) goto <D.9250>; else goto <D.9251>;
            <D.9250>:
            D.9252 = own_if_owned (handle);
            if (D.9252 == 1) goto <D.9253>; else goto <D.9254>;
            <D.9253>:
            ret = 0;
            goto done;
            <D.9254>:
            <D.9251>:
            if (alertable != 0) goto <D.9255>; else goto <D.9256>;
            <D.9255>:
            D.9257 = _wapi_thread_apc_pending (current_thread);
            if (D.9257 != 0) goto <D.9258>; else goto <D.9259>;
            <D.9258>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9259>:
            <D.9256>:
            D.9260 = own_if_signalled (handle);
            if (D.9260 == 1) goto <D.9261>; else goto <D.9262>;
            <D.9261>:
            ret = 0;
            goto done;
            <D.9262>:
            if (timeout == 0) goto <D.9263>; else goto <D.9264>;
            <D.9263>:
            ret = 258;
            goto done;
            <D.9264>:
            if (timeout != 4294967295) goto <D.9265>; else goto <D.9266>;
            <D.9265>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9266>:
            <D.9103>:
            _wapi_handle_ops_prewait (handle);
            D.9267 = own_if_signalled (handle);
            if (D.9267 != 0) goto <D.9268>; else goto <D.9269>;
            <D.9268>:
            ret = 0;
            goto done;
            <D.9269>:
            if (timeout == 4294967295) goto <D.9270>; else goto <D.9271>;
            <D.9270>:
            D.9272 = _wapi_handle_wait_signal_handle (handle, alertable);
            waited = (guint32) D.9272;
            goto <D.9273>;
            <D.9271>:
            D.9274 = _wapi_handle_timedwait_signal_handle (handle, &abstime, alertable, 0);
            waited = (guint32) D.9274;
            <D.9273>:
            if (alertable != 0) goto <D.9275>; else goto <D.9276>;
            <D.9275>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9276>:
            if (waited == 0) goto <D.9277>; else goto <D.9278>;
            <D.9277>:
            if (apc_pending == 0) goto <D.9279>; else goto <D.9280>;
            <D.9279>:
            D.9281 = own_if_signalled (handle);
            if (D.9281 != 0) goto <D.9282>; else goto <D.9283>;
            <D.9282>:
            ret = 0;
            goto done;
            <D.9283>:
            <D.9280>:
            <D.9278>:
            if (waited == 0) goto <D.9284>; else goto <D.9104>;
            <D.9284>:
            if (apc_pending == 0) goto <D.9103>; else goto <D.9104>;
            <D.9104>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9244 = thr_ret != 0;
            D.9245 = (long int) D.9244;
            D.9246 = __builtin_expect (D.9245, 0);
            if (D.9246 != 0) goto <D.9285>; else goto <D.9286>;
            <D.9285>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 232, "thr_ret == 0");
            <D.9286>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9287>; else goto <D.9288>;
            <D.9287>:
            __cancel_routine (__cancel_arg);
            <D.9288>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      check_pending:
      if (apc_pending != 0) goto <D.9289>; else goto <D.9290>;
      <D.9289>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.9290>:
      D.9222 = ret;
      return D.9222;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  int D.9312;
  <unnamed type> D.9315;
  <unnamed type> D.9317;
  <unnamed type> D.9319;
  <unnamed type> D.9321;
  unsigned int D.9322;
  struct _WapiHandleUnshared * D.9323;
  unsigned int D.9324;
  unsigned int D.9325;
  struct _WapiHandleUnshared * D.9326;
  union mono_mutex_t * D.9327;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9310>; else goto <D.9311>;
  <D.9310>:
  D.9312 = 0;
  return D.9312;
  <D.9311>:
  _wapi_handle_ref (handle);
  D.9315 = _wapi_handle_type (handle);
  if (D.9315 == 9) goto <D.9313>; else goto <D.9316>;
  <D.9316>:
  D.9317 = _wapi_handle_type (handle);
  if (D.9317 == 11) goto <D.9313>; else goto <D.9318>;
  <D.9318>:
  D.9319 = _wapi_handle_type (handle);
  if (D.9319 == 12) goto <D.9313>; else goto <D.9320>;
  <D.9320>:
  D.9321 = _wapi_handle_type (handle);
  if (D.9321 == 13) goto <D.9313>; else goto <D.9314>;
  <D.9313>:
  D.9312 = 0;
  return D.9312;
  <D.9314>:
  D.9322 = idx / 256;
  D.9323 = _wapi_private_handles[D.9322];
  D.9324 = idx & 255;
  D.9325 = D.9324 * 144;
  D.9326 = D.9323 + D.9325;
  D.9327 = &D.9326->signal_mutex;
  D.9312 = pthread_mutex_lock (D.9327);
  return D.9312;
}


_wapi_handle_type (void * handle)
{
  unsigned int D.9333;
  struct _WapiHandleUnshared * D.9334;
  WapiHandleType D.9335;
  unsigned int D.9336;
  unsigned int D.9337;
  struct _WapiHandleUnshared * D.9338;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9329>; else goto <D.9331>;
  <D.9331>:
  if (idx > 268435455) goto <D.9329>; else goto <D.9332>;
  <D.9332>:
  D.9333 = idx / 256;
  D.9334 = _wapi_private_handles[D.9333];
  if (D.9334 == 0B) goto <D.9329>; else goto <D.9330>;
  <D.9329>:
  D.9335 = 0;
  return D.9335;
  <D.9330>:
  D.9333 = idx / 256;
  D.9334 = _wapi_private_handles[D.9333];
  D.9336 = idx & 255;
  D.9337 = D.9336 * 144;
  D.9338 = D.9334 + D.9337;
  D.9335 = D.9338->type;
  return D.9335;
}


own_if_owned (void * handle)
{
  <unnamed type> D.9342;
  <unnamed type> D.9344;
  <unnamed type> D.9346;
  <unnamed type> D.9348;
  int D.9349;
  gboolean D.9352;
  int D.9353;
  <unnamed type> D.9358;
  <unnamed type> D.9360;
  <unnamed type> D.9362;
  <unnamed type> D.9364;
  gboolean ret;

  ret = 0;
  D.9342 = _wapi_handle_type (handle);
  if (D.9342 == 9) goto <D.9340>; else goto <D.9343>;
  <D.9343>:
  D.9344 = _wapi_handle_type (handle);
  if (D.9344 == 11) goto <D.9340>; else goto <D.9345>;
  <D.9345>:
  D.9346 = _wapi_handle_type (handle);
  if (D.9346 == 12) goto <D.9340>; else goto <D.9347>;
  <D.9347>:
  D.9348 = _wapi_handle_type (handle);
  if (D.9348 == 13) goto <D.9340>; else goto <D.9341>;
  <D.9340>:
  D.9349 = _wapi_handle_trylock_shared_handles ();
  if (D.9349 == 16) goto <D.9350>; else goto <D.9351>;
  <D.9350>:
  D.9352 = 0;
  return D.9352;
  <D.9351>:
  <D.9341>:
  D.9353 = _wapi_handle_ops_isowned (handle);
  if (D.9353 != 0) goto <D.9354>; else goto <D.9355>;
  <D.9354>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9355>:
  D.9358 = _wapi_handle_type (handle);
  if (D.9358 == 9) goto <D.9356>; else goto <D.9359>;
  <D.9359>:
  D.9360 = _wapi_handle_type (handle);
  if (D.9360 == 11) goto <D.9356>; else goto <D.9361>;
  <D.9361>:
  D.9362 = _wapi_handle_type (handle);
  if (D.9362 == 12) goto <D.9356>; else goto <D.9363>;
  <D.9363>:
  D.9364 = _wapi_handle_type (handle);
  if (D.9364 == 13) goto <D.9356>; else goto <D.9357>;
  <D.9356>:
  _wapi_handle_unlock_shared_handles ();
  <D.9357>:
  D.9352 = ret;
  return D.9352;
}


_wapi_handle_trylock_shared_handles ()
{
  int D.9366;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.9368;

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


own_if_signalled (void * handle)
{
  <unnamed type> D.9372;
  <unnamed type> D.9374;
  <unnamed type> D.9376;
  <unnamed type> D.9378;
  int D.9379;
  gboolean D.9382;
  int D.9383;
  <unnamed type> D.9388;
  <unnamed type> D.9390;
  <unnamed type> D.9392;
  <unnamed type> D.9394;
  gboolean ret;

  ret = 0;
  D.9372 = _wapi_handle_type (handle);
  if (D.9372 == 9) goto <D.9370>; else goto <D.9373>;
  <D.9373>:
  D.9374 = _wapi_handle_type (handle);
  if (D.9374 == 11) goto <D.9370>; else goto <D.9375>;
  <D.9375>:
  D.9376 = _wapi_handle_type (handle);
  if (D.9376 == 12) goto <D.9370>; else goto <D.9377>;
  <D.9377>:
  D.9378 = _wapi_handle_type (handle);
  if (D.9378 == 13) goto <D.9370>; else goto <D.9371>;
  <D.9370>:
  D.9379 = _wapi_handle_trylock_shared_handles ();
  if (D.9379 == 16) goto <D.9380>; else goto <D.9381>;
  <D.9380>:
  D.9382 = 0;
  return D.9382;
  <D.9381>:
  <D.9371>:
  D.9383 = _wapi_handle_issignalled (handle);
  if (D.9383 != 0) goto <D.9384>; else goto <D.9385>;
  <D.9384>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9385>:
  D.9388 = _wapi_handle_type (handle);
  if (D.9388 == 9) goto <D.9386>; else goto <D.9389>;
  <D.9389>:
  D.9390 = _wapi_handle_type (handle);
  if (D.9390 == 11) goto <D.9386>; else goto <D.9391>;
  <D.9391>:
  D.9392 = _wapi_handle_type (handle);
  if (D.9392 == 12) goto <D.9386>; else goto <D.9393>;
  <D.9393>:
  D.9394 = _wapi_handle_type (handle);
  if (D.9394 == 13) goto <D.9386>; else goto <D.9387>;
  <D.9386>:
  _wapi_handle_unlock_shared_handles ();
  <D.9387>:
  D.9382 = ret;
  return D.9382;
}


_wapi_handle_issignalled (void * handle)
{
  gboolean D.9398;
  <unnamed type> D.9401;
  <unnamed type> D.9403;
  <unnamed type> D.9405;
  <unnamed type> D.9407;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.1;
  unsigned int handle.2;
  unsigned int D.9410;
  struct _WapiHandleUnshared * D.9411;
  unsigned int D.9412;
  unsigned int D.9413;
  struct _WapiHandleUnshared * D.9414;
  unsigned int D.9415;
  unsigned int D.9416;
  struct _WapiHandleUnshared * D.9417;
  unsigned int D.9418;
  unsigned int D.9419;
  struct _WapiHandleUnshared * D.9420;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9396>; else goto <D.9397>;
  <D.9396>:
  D.9398 = 0;
  return D.9398;
  <D.9397>:
  D.9401 = _wapi_handle_type (handle);
  if (D.9401 == 9) goto <D.9399>; else goto <D.9402>;
  <D.9402>:
  D.9403 = _wapi_handle_type (handle);
  if (D.9403 == 11) goto <D.9399>; else goto <D.9404>;
  <D.9404>:
  D.9405 = _wapi_handle_type (handle);
  if (D.9405 == 12) goto <D.9399>; else goto <D.9406>;
  <D.9406>:
  D.9407 = _wapi_handle_type (handle);
  if (D.9407 == 13) goto <D.9399>; else goto <D.9400>;
  <D.9399>:
  _wapi_shared_layout.1 = _wapi_shared_layout;
  handle.2 = (unsigned int) handle;
  D.9410 = handle.2 / 256;
  D.9411 = _wapi_private_handles[D.9410];
  handle.2 = (unsigned int) handle;
  D.9412 = handle.2 & 255;
  D.9413 = D.9412 * 144;
  D.9414 = D.9411 + D.9413;
  D.9415 = D.9414->u.shared.offset;
  D.9398 = _wapi_shared_layout.1->handles[D.9415].signalled;
  return D.9398;
  <D.9400>:
  D.9416 = idx / 256;
  D.9417 = _wapi_private_handles[D.9416];
  D.9418 = idx & 255;
  D.9419 = D.9418 * 144;
  D.9420 = D.9417 + D.9419;
  D.9398 = D.9420->signalled;
  return D.9398;
}


_wapi_handle_unlock_handle (void * handle)
{
  int D.9424;
  <unnamed type> D.9427;
  <unnamed type> D.9429;
  <unnamed type> D.9431;
  <unnamed type> D.9433;
  unsigned int D.9434;
  struct _WapiHandleUnshared * D.9435;
  unsigned int D.9436;
  unsigned int D.9437;
  struct _WapiHandleUnshared * D.9438;
  union mono_mutex_t * D.9439;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9422>; else goto <D.9423>;
  <D.9422>:
  D.9424 = 0;
  return D.9424;
  <D.9423>:
  D.9427 = _wapi_handle_type (handle);
  if (D.9427 == 9) goto <D.9425>; else goto <D.9428>;
  <D.9428>:
  D.9429 = _wapi_handle_type (handle);
  if (D.9429 == 11) goto <D.9425>; else goto <D.9430>;
  <D.9430>:
  D.9431 = _wapi_handle_type (handle);
  if (D.9431 == 12) goto <D.9425>; else goto <D.9432>;
  <D.9432>:
  D.9433 = _wapi_handle_type (handle);
  if (D.9433 == 13) goto <D.9425>; else goto <D.9426>;
  <D.9425>:
  _wapi_handle_unref (handle);
  D.9424 = 0;
  return D.9424;
  <D.9426>:
  D.9434 = idx / 256;
  D.9435 = _wapi_private_handles[D.9434];
  D.9436 = idx & 255;
  D.9437 = D.9436 * 144;
  D.9438 = D.9435 + D.9437;
  D.9439 = &D.9438->signal_mutex;
  ret = pthread_mutex_unlock (D.9439);
  _wapi_handle_unref (handle);
  D.9424 = ret;
  return D.9424;
}


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

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


SignalObjectAndWait (void * signal_handle, void * wait, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9443;
  guint32 D.9446;
  signed int signal_handle.3;
  signed int wait.4;
  int D.9461;
  int D.9464;
  int D.9467;
  long int D.9470;
  _Bool D.9473;
  long int D.9474;
  long int D.9475;
  int D.9478;
  int D.9481;
  int D.9486;
  int D.9489;
  int D.9494;
  int D.9499;
  int D.9501;
  int D.9508;
  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.9443 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9443);
      if (current_thread == 0B) goto <D.9444>; else goto <D.9445>;
      <D.9444>:
      SetLastError (6);
      D.9446 = 4294967295;
      return D.9446;
      <D.9445>:
      if (signal_handle == 4294967294B) goto <D.9447>; else goto <D.9448>;
      <D.9447>:
      D.9443 = pthread_self ();
      signal_handle = _wapi_thread_handle_from_id (D.9443);
      if (signal_handle == 0B) goto <D.9449>; else goto <D.9450>;
      <D.9449>:
      SetLastError (6);
      D.9446 = 4294967295;
      return D.9446;
      <D.9450>:
      <D.9448>:
      if (wait == 4294967294B) goto <D.9451>; else goto <D.9452>;
      <D.9451>:
      D.9443 = pthread_self ();
      wait = _wapi_thread_handle_from_id (D.9443);
      if (wait == 0B) goto <D.9453>; else goto <D.9454>;
      <D.9453>:
      SetLastError (6);
      D.9446 = 4294967295;
      return D.9446;
      <D.9454>:
      <D.9452>:
      signal_handle.3 = (signed int) signal_handle;
      if (signal_handle.3 < 0) goto <D.9456>; else goto <D.9457>;
      <D.9456>:
      SetLastError (6);
      D.9446 = 4294967295;
      return D.9446;
      <D.9457>:
      wait.4 = (signed int) wait;
      if (wait.4 < 0) goto <D.9459>; else goto <D.9460>;
      <D.9459>:
      SetLastError (6);
      D.9446 = 4294967295;
      return D.9446;
      <D.9460>:
      D.9461 = _wapi_handle_test_capabilities (signal_handle, 2);
      if (D.9461 == 0) goto <D.9462>; else goto <D.9463>;
      <D.9462>:
      D.9446 = 4294967295;
      return D.9446;
      <D.9463>:
      D.9464 = _wapi_handle_test_capabilities (wait, 1);
      if (D.9464 == 0) goto <D.9465>; else goto <D.9466>;
      <D.9465>:
      D.9446 = 4294967295;
      return D.9446;
      <D.9466>:
      _wapi_handle_ops_prewait (wait);
      D.9467 = _wapi_handle_test_capabilities (wait, 8);
      if (D.9467 == 1) goto <D.9468>; else goto <D.9469>;
      <D.9468>:
      monoeg_g_log (0B, 16, "%s: handle %p has special wait, implement me!!", &__func__, wait);
      D.9446 = 4294967295;
      return D.9446;
      <D.9469>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (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.9470 = __builtin_expect (__not_first_call, 0);
            if (D.9470 != 0) goto <D.9471>; else goto <D.9472>;
            <D.9471>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9472>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (wait);
            D.9473 = thr_ret != 0;
            D.9474 = (long int) D.9473;
            D.9475 = __builtin_expect (D.9474, 0);
            if (D.9475 != 0) goto <D.9476>; else goto <D.9477>;
            <D.9476>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 349, "thr_ret == 0");
            <D.9477>:
            _wapi_handle_ops_signal (signal_handle);
            D.9478 = _wapi_handle_test_capabilities (wait, 4);
            if (D.9478 == 1) goto <D.9479>; else goto <D.9480>;
            <D.9479>:
            D.9481 = own_if_owned (wait);
            if (D.9481 != 0) goto <D.9482>; else goto <D.9483>;
            <D.9482>:
            ret = 0;
            goto done;
            <D.9483>:
            <D.9480>:
            if (alertable != 0) goto <D.9484>; else goto <D.9485>;
            <D.9484>:
            D.9486 = _wapi_thread_apc_pending (current_thread);
            if (D.9486 != 0) goto <D.9487>; else goto <D.9488>;
            <D.9487>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9488>:
            <D.9485>:
            D.9489 = own_if_signalled (wait);
            if (D.9489 != 0) goto <D.9490>; else goto <D.9491>;
            <D.9490>:
            ret = 0;
            goto done;
            <D.9491>:
            if (timeout != 4294967295) goto <D.9492>; else goto <D.9493>;
            <D.9492>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9493>:
            <D.9129>:
            _wapi_handle_ops_prewait (wait);
            D.9494 = own_if_signalled (wait);
            if (D.9494 != 0) goto <D.9495>; else goto <D.9496>;
            <D.9495>:
            ret = 0;
            goto done;
            <D.9496>:
            if (timeout == 4294967295) goto <D.9497>; else goto <D.9498>;
            <D.9497>:
            D.9499 = _wapi_handle_wait_signal_handle (wait, alertable);
            waited = (guint32) D.9499;
            goto <D.9500>;
            <D.9498>:
            D.9501 = _wapi_handle_timedwait_signal_handle (wait, &abstime, alertable, 0);
            waited = (guint32) D.9501;
            <D.9500>:
            if (alertable != 0) goto <D.9502>; else goto <D.9503>;
            <D.9502>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9503>:
            if (waited == 0) goto <D.9504>; else goto <D.9505>;
            <D.9504>:
            if (apc_pending == 0) goto <D.9506>; else goto <D.9507>;
            <D.9506>:
            D.9508 = own_if_signalled (wait);
            if (D.9508 != 0) goto <D.9509>; else goto <D.9510>;
            <D.9509>:
            ret = 0;
            goto done;
            <D.9510>:
            <D.9507>:
            <D.9505>:
            if (waited == 0) goto <D.9511>; else goto <D.9130>;
            <D.9511>:
            if (apc_pending == 0) goto <D.9129>; else goto <D.9130>;
            <D.9130>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (wait);
            D.9473 = thr_ret != 0;
            D.9474 = (long int) D.9473;
            D.9475 = __builtin_expect (D.9474, 0);
            if (D.9475 != 0) goto <D.9512>; else goto <D.9513>;
            <D.9512>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 430, "thr_ret == 0");
            <D.9513>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9514>; else goto <D.9515>;
            <D.9514>:
            __cancel_routine (__cancel_arg);
            <D.9515>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (apc_pending != 0) goto <D.9516>; else goto <D.9517>;
      <D.9516>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.9517>:
      D.9446 = ret;
      return D.9446;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


WaitForMultipleObjectsEx (guint32 numobjects, void * * handles, gboolean waitall, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9537;
  guint32 D.9540;
  void * D.9545;
  unsigned int D.9546;
  void * * D.9547;
  void * D.9548;
  void * D.9551;
  signed int D.9554;
  int D.9557;
  unsigned int D.9560;
  void * D.9561;
  void * D.9562;
  <unnamed type> D.9571;
  <unnamed type> D.9573;
  <unnamed type> D.9575;
  <unnamed type> D.9577;
  <unnamed type> D.9579;
  int D.9588;
  int D.9591;
  int D.9594;
  long int D.9597;
  _Bool D.9600;
  long int D.9601;
  long int D.9602;
  int D.9607;
  int D.9611;
  int D.9618;
  int D.9620;
  int D.9628;
  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.9537 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9537);
      if (current_thread == 0B) goto <D.9538>; else goto <D.9539>;
      <D.9538>:
      SetLastError (6);
      D.9540 = 4294967295;
      return D.9540;
      <D.9539>:
      if (numobjects > 64) goto <D.9541>; else goto <D.9542>;
      <D.9541>:
      D.9540 = 4294967295;
      return D.9540;
      <D.9542>:
      if (numobjects == 1) goto <D.9543>; else goto <D.9544>;
      <D.9543>:
      D.9545 = *handles;
      D.9540 = WaitForSingleObjectEx (D.9545, timeout, alertable);
      return D.9540;
      <D.9544>:
      i = 0;
      goto <D.9178>;
      <D.9177>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      if (D.9548 == 4294967294B) goto <D.9549>; else goto <D.9550>;
      <D.9549>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9537 = pthread_self ();
      D.9551 = _wapi_thread_handle_from_id (D.9537);
      *D.9547 = D.9551;
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      if (D.9548 == 0B) goto <D.9552>; else goto <D.9553>;
      <D.9552>:
      bogustype = 1;
      goto <D.9176>;
      <D.9553>:
      <D.9550>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9554 = (signed int) D.9548;
      if (D.9554 < 0) goto <D.9555>; else goto <D.9556>;
      <D.9555>:
      bogustype = 1;
      goto <D.9176>;
      <D.9556>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9557 = _wapi_handle_test_capabilities (D.9548, 1);
      if (D.9557 == 0) goto <D.9558>; else goto <D.9559>;
      <D.9558>:
      bogustype = 1;
      goto <D.9176>;
      <D.9559>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      sorted_handles[i] = D.9548;
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      _wapi_handle_ops_prewait (D.9548);
      i = i + 1;
      <D.9178>:
      if (i < numobjects) goto <D.9177>; else goto <D.9176>;
      <D.9176>:
      qsort (&sorted_handles, numobjects, 4, monoeg_g_direct_equal);
      i = 1;
      goto <D.9181>;
      <D.9180>:
      D.9560 = i + 4294967295;
      D.9561 = sorted_handles[D.9560];
      D.9562 = sorted_handles[i];
      if (D.9561 == D.9562) goto <D.9563>; else goto <D.9564>;
      <D.9563>:
      duplicate = 1;
      goto <D.9179>;
      <D.9564>:
      i = i + 1;
      <D.9181>:
      if (i < numobjects) goto <D.9180>; else goto <D.9179>;
      <D.9179>:
      if (duplicate == 1) goto <D.9565>; else goto <D.9566>;
      <D.9565>:
      D.9540 = 4294967295;
      return D.9540;
      <D.9566>:
      if (bogustype == 1) goto <D.9567>; else goto <D.9568>;
      <D.9567>:
      D.9540 = 4294967295;
      return D.9540;
      <D.9568>:
      poll = 0;
      i = 0;
      goto <D.9183>;
      <D.9182>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9571 = _wapi_handle_type (D.9548);
      if (D.9571 == 9) goto <D.9569>; else goto <D.9572>;
      <D.9572>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9573 = _wapi_handle_type (D.9548);
      if (D.9573 == 9) goto <D.9569>; else goto <D.9574>;
      <D.9574>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9575 = _wapi_handle_type (D.9548);
      if (D.9575 == 11) goto <D.9569>; else goto <D.9576>;
      <D.9576>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9577 = _wapi_handle_type (D.9548);
      if (D.9577 == 12) goto <D.9569>; else goto <D.9578>;
      <D.9578>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9579 = _wapi_handle_type (D.9548);
      if (D.9579 == 13) goto <D.9569>; else goto <D.9570>;
      <D.9569>:
      poll = 1;
      <D.9570>:
      i = i + 1;
      <D.9183>:
      if (i < numobjects) goto <D.9182>; else goto <D.9184>;
      <D.9184>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.9580>; else goto <D.9581>;
      <D.9580>:
      D.9540 = lowest;
      return D.9540;
      <D.9581>:
      if (timeout == 0) goto <D.9582>; else goto <D.9583>;
      <D.9582>:
      D.9540 = 258;
      return D.9540;
      <D.9583>:
      if (timeout != 4294967295) goto <D.9584>; else goto <D.9585>;
      <D.9584>:
      _wapi_calc_timeout (&abstime, timeout);
      <D.9585>:
      if (alertable != 0) goto <D.9586>; else goto <D.9587>;
      <D.9586>:
      D.9588 = _wapi_thread_apc_pending (current_thread);
      if (D.9588 != 0) goto <D.9589>; else goto <D.9590>;
      <D.9589>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.9540 = 192;
      return D.9540;
      <D.9590>:
      <D.9587>:
      i = 0;
      goto <D.9186>;
      <D.9185>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      _wapi_handle_ref (D.9548);
      i = i + 1;
      <D.9186>:
      if (i < numobjects) goto <D.9185>; else goto <D.9187>;
      <D.9187>:
      <D.9204>:
      i = 0;
      goto <D.9189>;
      <D.9188>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      _wapi_handle_ops_prewait (D.9548);
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9591 = _wapi_handle_test_capabilities (D.9548, 8);
      if (D.9591 == 1) goto <D.9592>; else goto <D.9593>;
      <D.9592>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      D.9594 = _wapi_handle_issignalled (D.9548);
      if (D.9594 == 0) goto <D.9595>; else goto <D.9596>;
      <D.9595>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      _wapi_handle_ops_special_wait (D.9548, 0, alertable);
      <D.9596>:
      <D.9593>:
      i = i + 1;
      <D.9189>:
      if (i < numobjects) goto <D.9188>; else goto <D.9190>;
      <D.9190>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (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.9597 = __builtin_expect (__not_first_call, 0);
            if (D.9597 != 0) goto <D.9598>; else goto <D.9599>;
            <D.9598>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9599>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_signal_mutex ();
            D.9600 = thr_ret != 0;
            D.9601 = (long int) D.9600;
            D.9602 = __builtin_expect (D.9601, 0);
            if (D.9602 != 0) goto <D.9603>; else goto <D.9604>;
            <D.9603>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 650, "thr_ret == 0");
            <D.9604>:
            if (waitall != 0) goto <D.9605>; else goto <D.9606>;
            <D.9605>:
            done = 1;
            i = 0;
            goto <D.9198>;
            <D.9197>:
            D.9546 = i * 4;
            D.9547 = handles + D.9546;
            D.9548 = *D.9547;
            D.9607 = _wapi_handle_issignalled (D.9548);
            if (D.9607 == 0) goto <D.9608>; else goto <D.9609>;
            <D.9608>:
            done = 0;
            <D.9609>:
            i = i + 1;
            <D.9198>:
            if (i < numobjects) goto <D.9197>; else goto <D.9199>;
            <D.9199>:
            goto <D.9610>;
            <D.9606>:
            done = 0;
            i = 0;
            goto <D.9201>;
            <D.9200>:
            D.9546 = i * 4;
            D.9547 = handles + D.9546;
            D.9548 = *D.9547;
            D.9611 = _wapi_handle_issignalled (D.9548);
            if (D.9611 != 0) goto <D.9612>; else goto <D.9613>;
            <D.9612>:
            done = 1;
            <D.9613>:
            i = i + 1;
            <D.9201>:
            if (i < numobjects) goto <D.9200>; else goto <D.9202>;
            <D.9202>:
            <D.9610>:
            if (done == 0) goto <D.9614>; else goto <D.9615>;
            <D.9614>:
            if (timeout == 4294967295) goto <D.9616>; else goto <D.9617>;
            <D.9616>:
            D.9618 = _wapi_handle_wait_signal (poll);
            ret = (guint32) D.9618;
            goto <D.9619>;
            <D.9617>:
            D.9620 = _wapi_handle_timedwait_signal (&abstime, poll);
            ret = (guint32) D.9620;
            <D.9619>:
            goto <D.9621>;
            <D.9615>:
            ret = 0;
            <D.9621>:
            thr_ret = _wapi_handle_unlock_signal_mutex (0B);
            D.9600 = thr_ret != 0;
            D.9601 = (long int) D.9600;
            D.9602 = __builtin_expect (D.9601, 0);
            if (D.9602 != 0) goto <D.9622>; else goto <D.9623>;
            <D.9622>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 680, "thr_ret == 0");
            <D.9623>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9624>; else goto <D.9625>;
            <D.9624>:
            __cancel_routine (__cancel_arg);
            <D.9625>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (alertable != 0) goto <D.9626>; else goto <D.9627>;
      <D.9626>:
      D.9628 = _wapi_thread_apc_pending (current_thread);
      if (D.9628 != 0) goto <D.9629>; else goto <D.9630>;
      <D.9629>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      retval = 192;
      goto <D.9203>;
      <D.9630>:
      <D.9627>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.9631>; else goto <D.9632>;
      <D.9631>:
      retval = lowest;
      goto <D.9203>;
      <D.9632>:
      if (ret != 0) goto <D.9633>; else goto <D.9634>;
      <D.9633>:
      if (ret == 145) goto <D.9635>; else goto <D.9636>;
      <D.9635>:
      retval = 258;
      goto <D.9637>;
      <D.9636>:
      retval = 4294967295;
      <D.9637>:
      goto <D.9203>;
      <D.9634>:
      goto <D.9204>;
      <D.9203>:
      i = 0;
      goto <D.9206>;
      <D.9205>:
      D.9546 = i * 4;
      D.9547 = handles + D.9546;
      D.9548 = *D.9547;
      _wapi_handle_unref (D.9548);
      i = i + 1;
      <D.9206>:
      if (i < numobjects) goto <D.9205>; else goto <D.9207>;
      <D.9207>:
      D.9540 = retval;
      return D.9540;
    }
  finally
    {
      count = {CLOBBER};
      lowest = {CLOBBER};
      abstime = {CLOBBER};
      sorted_handles = {CLOBBER};
    }
}


_wapi_handle_lock_signal_mutex ()
{
  int D.9661;
  union mono_mutex_t * _wapi_global_signal_mutex.5;

  _wapi_global_signal_mutex.5 = _wapi_global_signal_mutex;
  D.9661 = pthread_mutex_lock (_wapi_global_signal_mutex.5);
  return D.9661;
}


_wapi_handle_unlock_signal_mutex (void * unused)
{
  int D.9664;
  union mono_mutex_t * _wapi_global_signal_mutex.6;

  _wapi_global_signal_mutex.6 = _wapi_global_signal_mutex;
  D.9664 = pthread_mutex_unlock (_wapi_global_signal_mutex.6);
  return D.9664;
}


test_and_own (guint32 numobjects, void * * handles, gboolean waitall, guint32 * count, guint32 * lowest)
{
  long int D.9667;
  unsigned int i.7;
  unsigned int D.9675;
  void * * D.9676;
  void * D.9677;
  unsigned int i.8;
  unsigned int D.9680;
  unsigned int D.9681;
  void * * D.9682;
  void * D.9683;
  gboolean D.9686;
  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 (*<Tc3>) (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.9667 = __builtin_expect (__not_first_call, 0);
            if (D.9667 != 0) goto <D.9668>; else goto <D.9669>;
            <D.9668>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9669>:
            __pthread_register_cancel (&__cancel_buf);
            done = _wapi_handle_count_signalled_handles (numobjects, handles, waitall, count, lowest);
            if (done == 1) goto <D.9670>; else goto <D.9671>;
            <D.9670>:
            if (waitall == 1) goto <D.9672>; else goto <D.9673>;
            <D.9672>:
            i = 0;
            goto <D.9154>;
            <D.9153>:
            i.7 = (unsigned int) i;
            D.9675 = i.7 * 4;
            D.9676 = handles + D.9675;
            D.9677 = *D.9676;
            own_if_signalled (D.9677);
            i = i + 1;
            <D.9154>:
            i.8 = (unsigned int) i;
            if (i.8 < numobjects) goto <D.9153>; else goto <D.9155>;
            <D.9155>:
            goto <D.9679>;
            <D.9673>:
            D.9680 = *lowest;
            D.9681 = D.9680 * 4;
            D.9682 = handles + D.9681;
            D.9683 = *D.9682;
            own_if_signalled (D.9683);
            <D.9679>:
            <D.9671>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (1 != 0) goto <D.9684>; else goto <D.9685>;
            <D.9684>:
            __cancel_routine (__cancel_arg);
            <D.9685>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9686 = done;
      return D.9686;
    }
  finally
    {
      cleanup_data = {CLOBBER};
    }
}


handle_cleanup (void * data)
{
  unsigned int D.9690;
  void * * D.9691;
  struct handle_cleanup_data * handles;

  handles = data;
  D.9690 = handles->numobjects;
  D.9691 = handles->handles;
  _wapi_handle_unlock_handles (D.9690, D.9691);
}


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

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


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

  D.9694 = 258;
  return D.9694;
}


