WaitForSingleObjectEx (void * handle, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9175;
  guint32 D.9178;
  signed int handle.0;
  int D.9186;
  int D.9189;
  int D.9194;
  long int D.9197;
  _Bool D.9200;
  long int D.9201;
  long int D.9202;
  int D.9205;
  int D.9208;
  int D.9213;
  int D.9216;
  int D.9223;
  int D.9228;
  int D.9230;
  _Bool D.9233;
  _Bool D.9234;
  _Bool D.9235;
  int D.9238;
  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.9175 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9175);
      if (current_thread == 0B) goto <D.9176>; else goto <D.9177>;
      <D.9176>:
      SetLastError (6);
      D.9178 = 4294967295;
      return D.9178;
      <D.9177>:
      if (handle == 4294967294B) goto <D.9179>; else goto <D.9180>;
      <D.9179>:
      D.9175 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.9175);
      if (handle == 0B) goto <D.9181>; else goto <D.9182>;
      <D.9181>:
      SetLastError (6);
      D.9178 = 4294967295;
      return D.9178;
      <D.9182>:
      <D.9180>:
      handle.0 = (signed int) handle;
      if (handle.0 < 0) goto <D.9184>; else goto <D.9185>;
      <D.9184>:
      SetLastError (6);
      D.9178 = 4294967295;
      return D.9178;
      <D.9185>:
      D.9186 = _wapi_handle_test_capabilities (handle, 1);
      if (D.9186 == 0) goto <D.9187>; else goto <D.9188>;
      <D.9187>:
      D.9178 = 4294967295;
      return D.9178;
      <D.9188>:
      _wapi_handle_ops_prewait (handle);
      D.9189 = _wapi_handle_test_capabilities (handle, 8);
      if (D.9189 == 1) goto <D.9190>; else goto <D.9191>;
      <D.9190>:
      ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
      if (alertable != 0) goto <D.9192>; else goto <D.9193>;
      <D.9192>:
      D.9194 = _wapi_thread_apc_pending (current_thread);
      if (D.9194 != 0) goto <D.9195>; else goto <D.9196>;
      <D.9195>:
      apc_pending = 1;
      ret = 192;
      <D.9196>:
      <D.9193>:
      goto check_pending;
      <D.9191>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tbf>) (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.9197 = __builtin_expect (__not_first_call, 0);
            if (D.9197 != 0) goto <D.9198>; else goto <D.9199>;
            <D.9198>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9199>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9200 = thr_ret != 0;
            D.9201 = (long int) D.9200;
            D.9202 = __builtin_expect (D.9201, 0);
            if (D.9202 != 0) goto <D.9203>; else goto <D.9204>;
            <D.9203>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 147, "thr_ret == 0");
            <D.9204>:
            D.9205 = _wapi_handle_test_capabilities (handle, 4);
            if (D.9205 == 1) goto <D.9206>; else goto <D.9207>;
            <D.9206>:
            D.9208 = own_if_owned (handle);
            if (D.9208 == 1) goto <D.9209>; else goto <D.9210>;
            <D.9209>:
            ret = 0;
            goto done;
            <D.9210>:
            <D.9207>:
            if (alertable != 0) goto <D.9211>; else goto <D.9212>;
            <D.9211>:
            D.9213 = _wapi_thread_apc_pending (current_thread);
            if (D.9213 != 0) goto <D.9214>; else goto <D.9215>;
            <D.9214>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9215>:
            <D.9212>:
            D.9216 = own_if_signalled (handle);
            if (D.9216 == 1) goto <D.9217>; else goto <D.9218>;
            <D.9217>:
            ret = 0;
            goto done;
            <D.9218>:
            if (timeout == 0) goto <D.9219>; else goto <D.9220>;
            <D.9219>:
            ret = 258;
            goto done;
            <D.9220>:
            if (timeout != 4294967295) goto <D.9221>; else goto <D.9222>;
            <D.9221>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9222>:
            <D.9059>:
            _wapi_handle_ops_prewait (handle);
            D.9223 = own_if_signalled (handle);
            if (D.9223 != 0) goto <D.9224>; else goto <D.9225>;
            <D.9224>:
            ret = 0;
            goto done;
            <D.9225>:
            if (timeout == 4294967295) goto <D.9226>; else goto <D.9227>;
            <D.9226>:
            D.9228 = _wapi_handle_wait_signal_handle (handle, alertable);
            waited = (guint32) D.9228;
            goto <D.9229>;
            <D.9227>:
            D.9230 = _wapi_handle_timedwait_signal_handle (handle, &abstime, alertable, 0);
            waited = (guint32) D.9230;
            <D.9229>:
            if (alertable != 0) goto <D.9231>; else goto <D.9232>;
            <D.9231>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9232>:
            D.9233 = waited == 0;
            D.9234 = apc_pending == 0;
            D.9235 = D.9233 & D.9234;
            if (D.9235 != 0) goto <D.9236>; else goto <D.9237>;
            <D.9236>:
            D.9238 = own_if_signalled (handle);
            if (D.9238 != 0) goto <D.9239>; else goto <D.9240>;
            <D.9239>:
            ret = 0;
            goto done;
            <D.9240>:
            <D.9237>:
            D.9233 = waited == 0;
            D.9234 = apc_pending == 0;
            D.9235 = D.9233 & D.9234;
            if (D.9235 != 0) goto <D.9059>; else goto <D.9060>;
            <D.9060>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9200 = thr_ret != 0;
            D.9201 = (long int) D.9200;
            D.9202 = __builtin_expect (D.9201, 0);
            if (D.9202 != 0) goto <D.9241>; else goto <D.9242>;
            <D.9241>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 232, "thr_ret == 0");
            <D.9242>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9243>; else goto <D.9244>;
            <D.9243>:
            __cancel_routine (__cancel_arg);
            <D.9244>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      check_pending:
      if (apc_pending != 0) goto <D.9245>; else goto <D.9246>;
      <D.9245>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.9246>:
      D.9178 = ret;
      return D.9178;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  int D.9268;
  <unnamed type> D.9271;
  <unnamed type> D.9273;
  <unnamed type> D.9275;
  <unnamed type> D.9277;
  unsigned int D.9278;
  struct _WapiHandleUnshared * D.9279;
  unsigned int D.9280;
  unsigned int D.9281;
  struct _WapiHandleUnshared * D.9282;
  union mono_mutex_t * D.9283;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9266>; else goto <D.9267>;
  <D.9266>:
  D.9268 = 0;
  return D.9268;
  <D.9267>:
  _wapi_handle_ref (handle);
  D.9271 = _wapi_handle_type (handle);
  if (D.9271 == 9) goto <D.9269>; else goto <D.9272>;
  <D.9272>:
  D.9273 = _wapi_handle_type (handle);
  if (D.9273 == 11) goto <D.9269>; else goto <D.9274>;
  <D.9274>:
  D.9275 = _wapi_handle_type (handle);
  if (D.9275 == 12) goto <D.9269>; else goto <D.9276>;
  <D.9276>:
  D.9277 = _wapi_handle_type (handle);
  if (D.9277 == 13) goto <D.9269>; else goto <D.9270>;
  <D.9269>:
  D.9268 = 0;
  return D.9268;
  <D.9270>:
  D.9278 = idx / 256;
  D.9279 = _wapi_private_handles[D.9278];
  D.9280 = idx & 255;
  D.9281 = D.9280 * 136;
  D.9282 = D.9279 + D.9281;
  D.9283 = &D.9282->signal_mutex;
  D.9268 = pthread_mutex_lock (D.9283);
  return D.9268;
}


_wapi_handle_type (void * handle)
{
  unsigned int D.9288;
  struct _WapiHandleUnshared * D.9289;
  WapiHandleType D.9290;
  unsigned int D.9291;
  unsigned int D.9292;
  struct _WapiHandleUnshared * D.9293;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9285>; else goto <D.9287>;
  <D.9287>:
  D.9288 = idx / 256;
  D.9289 = _wapi_private_handles[D.9288];
  if (D.9289 == 0B) goto <D.9285>; else goto <D.9286>;
  <D.9285>:
  D.9290 = 0;
  return D.9290;
  <D.9286>:
  D.9288 = idx / 256;
  D.9289 = _wapi_private_handles[D.9288];
  D.9291 = idx & 255;
  D.9292 = D.9291 * 136;
  D.9293 = D.9289 + D.9292;
  D.9290 = D.9293->type;
  return D.9290;
}


own_if_owned (void * handle)
{
  <unnamed type> D.9297;
  <unnamed type> D.9299;
  <unnamed type> D.9301;
  <unnamed type> D.9303;
  int D.9304;
  gboolean D.9307;
  int D.9308;
  <unnamed type> D.9313;
  <unnamed type> D.9315;
  <unnamed type> D.9317;
  <unnamed type> D.9319;
  gboolean ret;

  ret = 0;
  D.9297 = _wapi_handle_type (handle);
  if (D.9297 == 9) goto <D.9295>; else goto <D.9298>;
  <D.9298>:
  D.9299 = _wapi_handle_type (handle);
  if (D.9299 == 11) goto <D.9295>; else goto <D.9300>;
  <D.9300>:
  D.9301 = _wapi_handle_type (handle);
  if (D.9301 == 12) goto <D.9295>; else goto <D.9302>;
  <D.9302>:
  D.9303 = _wapi_handle_type (handle);
  if (D.9303 == 13) goto <D.9295>; else goto <D.9296>;
  <D.9295>:
  D.9304 = _wapi_handle_trylock_shared_handles ();
  if (D.9304 == 16) goto <D.9305>; else goto <D.9306>;
  <D.9305>:
  D.9307 = 0;
  return D.9307;
  <D.9306>:
  <D.9296>:
  D.9308 = _wapi_handle_ops_isowned (handle);
  if (D.9308 != 0) goto <D.9309>; else goto <D.9310>;
  <D.9309>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9310>:
  D.9313 = _wapi_handle_type (handle);
  if (D.9313 == 9) goto <D.9311>; else goto <D.9314>;
  <D.9314>:
  D.9315 = _wapi_handle_type (handle);
  if (D.9315 == 11) goto <D.9311>; else goto <D.9316>;
  <D.9316>:
  D.9317 = _wapi_handle_type (handle);
  if (D.9317 == 12) goto <D.9311>; else goto <D.9318>;
  <D.9318>:
  D.9319 = _wapi_handle_type (handle);
  if (D.9319 == 13) goto <D.9311>; else goto <D.9312>;
  <D.9311>:
  _wapi_handle_unlock_shared_handles ();
  <D.9312>:
  D.9307 = ret;
  return D.9307;
}


_wapi_handle_trylock_shared_handles ()
{
  int D.9321;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.9323;

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


own_if_signalled (void * handle)
{
  <unnamed type> D.9327;
  <unnamed type> D.9329;
  <unnamed type> D.9331;
  <unnamed type> D.9333;
  int D.9334;
  gboolean D.9337;
  int D.9338;
  <unnamed type> D.9343;
  <unnamed type> D.9345;
  <unnamed type> D.9347;
  <unnamed type> D.9349;
  gboolean ret;

  ret = 0;
  D.9327 = _wapi_handle_type (handle);
  if (D.9327 == 9) goto <D.9325>; else goto <D.9328>;
  <D.9328>:
  D.9329 = _wapi_handle_type (handle);
  if (D.9329 == 11) goto <D.9325>; else goto <D.9330>;
  <D.9330>:
  D.9331 = _wapi_handle_type (handle);
  if (D.9331 == 12) goto <D.9325>; else goto <D.9332>;
  <D.9332>:
  D.9333 = _wapi_handle_type (handle);
  if (D.9333 == 13) goto <D.9325>; else goto <D.9326>;
  <D.9325>:
  D.9334 = _wapi_handle_trylock_shared_handles ();
  if (D.9334 == 16) goto <D.9335>; else goto <D.9336>;
  <D.9335>:
  D.9337 = 0;
  return D.9337;
  <D.9336>:
  <D.9326>:
  D.9338 = _wapi_handle_issignalled (handle);
  if (D.9338 != 0) goto <D.9339>; else goto <D.9340>;
  <D.9339>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9340>:
  D.9343 = _wapi_handle_type (handle);
  if (D.9343 == 9) goto <D.9341>; else goto <D.9344>;
  <D.9344>:
  D.9345 = _wapi_handle_type (handle);
  if (D.9345 == 11) goto <D.9341>; else goto <D.9346>;
  <D.9346>:
  D.9347 = _wapi_handle_type (handle);
  if (D.9347 == 12) goto <D.9341>; else goto <D.9348>;
  <D.9348>:
  D.9349 = _wapi_handle_type (handle);
  if (D.9349 == 13) goto <D.9341>; else goto <D.9342>;
  <D.9341>:
  _wapi_handle_unlock_shared_handles ();
  <D.9342>:
  D.9337 = ret;
  return D.9337;
}


_wapi_handle_issignalled (void * handle)
{
  gboolean D.9353;
  <unnamed type> D.9356;
  <unnamed type> D.9358;
  <unnamed type> D.9360;
  <unnamed type> D.9362;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.1;
  unsigned int handle.2;
  unsigned int D.9365;
  struct _WapiHandleUnshared * D.9366;
  unsigned int D.9367;
  unsigned int D.9368;
  struct _WapiHandleUnshared * D.9369;
  unsigned int D.9370;
  unsigned int D.9371;
  struct _WapiHandleUnshared * D.9372;
  unsigned int D.9373;
  unsigned int D.9374;
  struct _WapiHandleUnshared * D.9375;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9351>; else goto <D.9352>;
  <D.9351>:
  D.9353 = 0;
  return D.9353;
  <D.9352>:
  D.9356 = _wapi_handle_type (handle);
  if (D.9356 == 9) goto <D.9354>; else goto <D.9357>;
  <D.9357>:
  D.9358 = _wapi_handle_type (handle);
  if (D.9358 == 11) goto <D.9354>; else goto <D.9359>;
  <D.9359>:
  D.9360 = _wapi_handle_type (handle);
  if (D.9360 == 12) goto <D.9354>; else goto <D.9361>;
  <D.9361>:
  D.9362 = _wapi_handle_type (handle);
  if (D.9362 == 13) goto <D.9354>; else goto <D.9355>;
  <D.9354>:
  _wapi_shared_layout.1 = _wapi_shared_layout;
  handle.2 = (unsigned int) handle;
  D.9365 = handle.2 / 256;
  D.9366 = _wapi_private_handles[D.9365];
  handle.2 = (unsigned int) handle;
  D.9367 = handle.2 & 255;
  D.9368 = D.9367 * 136;
  D.9369 = D.9366 + D.9368;
  D.9370 = D.9369->u.shared.offset;
  D.9353 = _wapi_shared_layout.1->handles[D.9370].signalled;
  return D.9353;
  <D.9355>:
  D.9371 = idx / 256;
  D.9372 = _wapi_private_handles[D.9371];
  D.9373 = idx & 255;
  D.9374 = D.9373 * 136;
  D.9375 = D.9372 + D.9374;
  D.9353 = D.9375->signalled;
  return D.9353;
}


_wapi_handle_unlock_handle (void * handle)
{
  int D.9379;
  <unnamed type> D.9382;
  <unnamed type> D.9384;
  <unnamed type> D.9386;
  <unnamed type> D.9388;
  unsigned int D.9389;
  struct _WapiHandleUnshared * D.9390;
  unsigned int D.9391;
  unsigned int D.9392;
  struct _WapiHandleUnshared * D.9393;
  union mono_mutex_t * D.9394;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9377>; else goto <D.9378>;
  <D.9377>:
  D.9379 = 0;
  return D.9379;
  <D.9378>:
  D.9382 = _wapi_handle_type (handle);
  if (D.9382 == 9) goto <D.9380>; else goto <D.9383>;
  <D.9383>:
  D.9384 = _wapi_handle_type (handle);
  if (D.9384 == 11) goto <D.9380>; else goto <D.9385>;
  <D.9385>:
  D.9386 = _wapi_handle_type (handle);
  if (D.9386 == 12) goto <D.9380>; else goto <D.9387>;
  <D.9387>:
  D.9388 = _wapi_handle_type (handle);
  if (D.9388 == 13) goto <D.9380>; else goto <D.9381>;
  <D.9380>:
  _wapi_handle_unref (handle);
  D.9379 = 0;
  return D.9379;
  <D.9381>:
  D.9389 = idx / 256;
  D.9390 = _wapi_private_handles[D.9389];
  D.9391 = idx & 255;
  D.9392 = D.9391 * 136;
  D.9393 = D.9390 + D.9392;
  D.9394 = &D.9393->signal_mutex;
  ret = pthread_mutex_unlock (D.9394);
  _wapi_handle_unref (handle);
  D.9379 = ret;
  return D.9379;
}


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

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


SignalObjectAndWait (void * signal_handle, void * wait, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9398;
  guint32 D.9401;
  signed int signal_handle.3;
  signed int wait.4;
  int D.9416;
  int D.9419;
  int D.9422;
  long int D.9425;
  _Bool D.9428;
  long int D.9429;
  long int D.9430;
  int D.9433;
  int D.9436;
  int D.9441;
  int D.9444;
  int D.9449;
  int D.9454;
  int D.9456;
  _Bool D.9459;
  _Bool D.9460;
  _Bool D.9461;
  int D.9464;
  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.9398 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9398);
      if (current_thread == 0B) goto <D.9399>; else goto <D.9400>;
      <D.9399>:
      SetLastError (6);
      D.9401 = 4294967295;
      return D.9401;
      <D.9400>:
      if (signal_handle == 4294967294B) goto <D.9402>; else goto <D.9403>;
      <D.9402>:
      D.9398 = pthread_self ();
      signal_handle = _wapi_thread_handle_from_id (D.9398);
      if (signal_handle == 0B) goto <D.9404>; else goto <D.9405>;
      <D.9404>:
      SetLastError (6);
      D.9401 = 4294967295;
      return D.9401;
      <D.9405>:
      <D.9403>:
      if (wait == 4294967294B) goto <D.9406>; else goto <D.9407>;
      <D.9406>:
      D.9398 = pthread_self ();
      wait = _wapi_thread_handle_from_id (D.9398);
      if (wait == 0B) goto <D.9408>; else goto <D.9409>;
      <D.9408>:
      SetLastError (6);
      D.9401 = 4294967295;
      return D.9401;
      <D.9409>:
      <D.9407>:
      signal_handle.3 = (signed int) signal_handle;
      if (signal_handle.3 < 0) goto <D.9411>; else goto <D.9412>;
      <D.9411>:
      SetLastError (6);
      D.9401 = 4294967295;
      return D.9401;
      <D.9412>:
      wait.4 = (signed int) wait;
      if (wait.4 < 0) goto <D.9414>; else goto <D.9415>;
      <D.9414>:
      SetLastError (6);
      D.9401 = 4294967295;
      return D.9401;
      <D.9415>:
      D.9416 = _wapi_handle_test_capabilities (signal_handle, 2);
      if (D.9416 == 0) goto <D.9417>; else goto <D.9418>;
      <D.9417>:
      D.9401 = 4294967295;
      return D.9401;
      <D.9418>:
      D.9419 = _wapi_handle_test_capabilities (wait, 1);
      if (D.9419 == 0) goto <D.9420>; else goto <D.9421>;
      <D.9420>:
      D.9401 = 4294967295;
      return D.9401;
      <D.9421>:
      _wapi_handle_ops_prewait (wait);
      D.9422 = _wapi_handle_test_capabilities (wait, 8);
      if (D.9422 == 1) goto <D.9423>; else goto <D.9424>;
      <D.9423>:
      monoeg_g_log (0B, 16, "%s: handle %p has special wait, implement me!!", &__func__, wait);
      D.9401 = 4294967295;
      return D.9401;
      <D.9424>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tbf>) (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.9425 = __builtin_expect (__not_first_call, 0);
            if (D.9425 != 0) goto <D.9426>; else goto <D.9427>;
            <D.9426>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9427>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (wait);
            D.9428 = thr_ret != 0;
            D.9429 = (long int) D.9428;
            D.9430 = __builtin_expect (D.9429, 0);
            if (D.9430 != 0) goto <D.9431>; else goto <D.9432>;
            <D.9431>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 349, "thr_ret == 0");
            <D.9432>:
            _wapi_handle_ops_signal (signal_handle);
            D.9433 = _wapi_handle_test_capabilities (wait, 4);
            if (D.9433 == 1) goto <D.9434>; else goto <D.9435>;
            <D.9434>:
            D.9436 = own_if_owned (wait);
            if (D.9436 != 0) goto <D.9437>; else goto <D.9438>;
            <D.9437>:
            ret = 0;
            goto done;
            <D.9438>:
            <D.9435>:
            if (alertable != 0) goto <D.9439>; else goto <D.9440>;
            <D.9439>:
            D.9441 = _wapi_thread_apc_pending (current_thread);
            if (D.9441 != 0) goto <D.9442>; else goto <D.9443>;
            <D.9442>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9443>:
            <D.9440>:
            D.9444 = own_if_signalled (wait);
            if (D.9444 != 0) goto <D.9445>; else goto <D.9446>;
            <D.9445>:
            ret = 0;
            goto done;
            <D.9446>:
            if (timeout != 4294967295) goto <D.9447>; else goto <D.9448>;
            <D.9447>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9448>:
            <D.9085>:
            _wapi_handle_ops_prewait (wait);
            D.9449 = own_if_signalled (wait);
            if (D.9449 != 0) goto <D.9450>; else goto <D.9451>;
            <D.9450>:
            ret = 0;
            goto done;
            <D.9451>:
            if (timeout == 4294967295) goto <D.9452>; else goto <D.9453>;
            <D.9452>:
            D.9454 = _wapi_handle_wait_signal_handle (wait, alertable);
            waited = (guint32) D.9454;
            goto <D.9455>;
            <D.9453>:
            D.9456 = _wapi_handle_timedwait_signal_handle (wait, &abstime, alertable, 0);
            waited = (guint32) D.9456;
            <D.9455>:
            if (alertable != 0) goto <D.9457>; else goto <D.9458>;
            <D.9457>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9458>:
            D.9459 = waited == 0;
            D.9460 = apc_pending == 0;
            D.9461 = D.9459 & D.9460;
            if (D.9461 != 0) goto <D.9462>; else goto <D.9463>;
            <D.9462>:
            D.9464 = own_if_signalled (wait);
            if (D.9464 != 0) goto <D.9465>; else goto <D.9466>;
            <D.9465>:
            ret = 0;
            goto done;
            <D.9466>:
            <D.9463>:
            D.9459 = waited == 0;
            D.9460 = apc_pending == 0;
            D.9461 = D.9459 & D.9460;
            if (D.9461 != 0) goto <D.9085>; else goto <D.9086>;
            <D.9086>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (wait);
            D.9428 = thr_ret != 0;
            D.9429 = (long int) D.9428;
            D.9430 = __builtin_expect (D.9429, 0);
            if (D.9430 != 0) goto <D.9467>; else goto <D.9468>;
            <D.9467>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 430, "thr_ret == 0");
            <D.9468>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9469>; else goto <D.9470>;
            <D.9469>:
            __cancel_routine (__cancel_arg);
            <D.9470>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (apc_pending != 0) goto <D.9471>; else goto <D.9472>;
      <D.9471>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.9472>:
      D.9401 = ret;
      return D.9401;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


WaitForMultipleObjectsEx (guint32 numobjects, void * * handles, gboolean waitall, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9492;
  guint32 D.9495;
  void * D.9500;
  unsigned int D.9501;
  void * * D.9502;
  void * D.9503;
  void * D.9506;
  signed int D.9509;
  int D.9512;
  unsigned int D.9515;
  void * D.9516;
  void * D.9517;
  <unnamed type> D.9526;
  <unnamed type> D.9528;
  <unnamed type> D.9530;
  <unnamed type> D.9532;
  <unnamed type> D.9534;
  int D.9543;
  int D.9546;
  int D.9549;
  long int D.9552;
  _Bool D.9555;
  long int D.9556;
  long int D.9557;
  int D.9562;
  int D.9566;
  int D.9573;
  int D.9575;
  int D.9583;
  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.9492 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9492);
      if (current_thread == 0B) goto <D.9493>; else goto <D.9494>;
      <D.9493>:
      SetLastError (6);
      D.9495 = 4294967295;
      return D.9495;
      <D.9494>:
      if (numobjects > 64) goto <D.9496>; else goto <D.9497>;
      <D.9496>:
      D.9495 = 4294967295;
      return D.9495;
      <D.9497>:
      if (numobjects == 1) goto <D.9498>; else goto <D.9499>;
      <D.9498>:
      D.9500 = *handles;
      D.9495 = WaitForSingleObjectEx (D.9500, timeout, alertable);
      return D.9495;
      <D.9499>:
      i = 0;
      goto <D.9134>;
      <D.9133>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      if (D.9503 == 4294967294B) goto <D.9504>; else goto <D.9505>;
      <D.9504>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9492 = pthread_self ();
      D.9506 = _wapi_thread_handle_from_id (D.9492);
      *D.9502 = D.9506;
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      if (D.9503 == 0B) goto <D.9507>; else goto <D.9508>;
      <D.9507>:
      bogustype = 1;
      goto <D.9132>;
      <D.9508>:
      <D.9505>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9509 = (signed int) D.9503;
      if (D.9509 < 0) goto <D.9510>; else goto <D.9511>;
      <D.9510>:
      bogustype = 1;
      goto <D.9132>;
      <D.9511>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9512 = _wapi_handle_test_capabilities (D.9503, 1);
      if (D.9512 == 0) goto <D.9513>; else goto <D.9514>;
      <D.9513>:
      bogustype = 1;
      goto <D.9132>;
      <D.9514>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      sorted_handles[i] = D.9503;
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      _wapi_handle_ops_prewait (D.9503);
      i = i + 1;
      <D.9134>:
      if (i < numobjects) goto <D.9133>; else goto <D.9132>;
      <D.9132>:
      qsort (&sorted_handles, numobjects, 4, monoeg_g_direct_equal);
      i = 1;
      goto <D.9137>;
      <D.9136>:
      D.9515 = i + 4294967295;
      D.9516 = sorted_handles[D.9515];
      D.9517 = sorted_handles[i];
      if (D.9516 == D.9517) goto <D.9518>; else goto <D.9519>;
      <D.9518>:
      duplicate = 1;
      goto <D.9135>;
      <D.9519>:
      i = i + 1;
      <D.9137>:
      if (i < numobjects) goto <D.9136>; else goto <D.9135>;
      <D.9135>:
      if (duplicate == 1) goto <D.9520>; else goto <D.9521>;
      <D.9520>:
      D.9495 = 4294967295;
      return D.9495;
      <D.9521>:
      if (bogustype == 1) goto <D.9522>; else goto <D.9523>;
      <D.9522>:
      D.9495 = 4294967295;
      return D.9495;
      <D.9523>:
      poll = 0;
      i = 0;
      goto <D.9139>;
      <D.9138>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9526 = _wapi_handle_type (D.9503);
      if (D.9526 == 9) goto <D.9524>; else goto <D.9527>;
      <D.9527>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9528 = _wapi_handle_type (D.9503);
      if (D.9528 == 9) goto <D.9524>; else goto <D.9529>;
      <D.9529>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9530 = _wapi_handle_type (D.9503);
      if (D.9530 == 11) goto <D.9524>; else goto <D.9531>;
      <D.9531>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9532 = _wapi_handle_type (D.9503);
      if (D.9532 == 12) goto <D.9524>; else goto <D.9533>;
      <D.9533>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9534 = _wapi_handle_type (D.9503);
      if (D.9534 == 13) goto <D.9524>; else goto <D.9525>;
      <D.9524>:
      poll = 1;
      <D.9525>:
      i = i + 1;
      <D.9139>:
      if (i < numobjects) goto <D.9138>; else goto <D.9140>;
      <D.9140>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.9535>; else goto <D.9536>;
      <D.9535>:
      D.9495 = lowest;
      return D.9495;
      <D.9536>:
      if (timeout == 0) goto <D.9537>; else goto <D.9538>;
      <D.9537>:
      D.9495 = 258;
      return D.9495;
      <D.9538>:
      if (timeout != 4294967295) goto <D.9539>; else goto <D.9540>;
      <D.9539>:
      _wapi_calc_timeout (&abstime, timeout);
      <D.9540>:
      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>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.9495 = 192;
      return D.9495;
      <D.9545>:
      <D.9542>:
      i = 0;
      goto <D.9142>;
      <D.9141>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      _wapi_handle_ref (D.9503);
      i = i + 1;
      <D.9142>:
      if (i < numobjects) goto <D.9141>; else goto <D.9143>;
      <D.9143>:
      <D.9160>:
      i = 0;
      goto <D.9145>;
      <D.9144>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      _wapi_handle_ops_prewait (D.9503);
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9546 = _wapi_handle_test_capabilities (D.9503, 8);
      if (D.9546 == 1) goto <D.9547>; else goto <D.9548>;
      <D.9547>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      D.9549 = _wapi_handle_issignalled (D.9503);
      if (D.9549 == 0) goto <D.9550>; else goto <D.9551>;
      <D.9550>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      _wapi_handle_ops_special_wait (D.9503, 0, alertable);
      <D.9551>:
      <D.9548>:
      i = i + 1;
      <D.9145>:
      if (i < numobjects) goto <D.9144>; else goto <D.9146>;
      <D.9146>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tbf>) (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.9552 = __builtin_expect (__not_first_call, 0);
            if (D.9552 != 0) goto <D.9553>; else goto <D.9554>;
            <D.9553>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9554>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_signal_mutex ();
            D.9555 = thr_ret != 0;
            D.9556 = (long int) D.9555;
            D.9557 = __builtin_expect (D.9556, 0);
            if (D.9557 != 0) goto <D.9558>; else goto <D.9559>;
            <D.9558>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 650, "thr_ret == 0");
            <D.9559>:
            if (waitall != 0) goto <D.9560>; else goto <D.9561>;
            <D.9560>:
            done = 1;
            i = 0;
            goto <D.9154>;
            <D.9153>:
            D.9501 = i * 4;
            D.9502 = handles + D.9501;
            D.9503 = *D.9502;
            D.9562 = _wapi_handle_issignalled (D.9503);
            if (D.9562 == 0) goto <D.9563>; else goto <D.9564>;
            <D.9563>:
            done = 0;
            <D.9564>:
            i = i + 1;
            <D.9154>:
            if (i < numobjects) goto <D.9153>; else goto <D.9155>;
            <D.9155>:
            goto <D.9565>;
            <D.9561>:
            done = 0;
            i = 0;
            goto <D.9157>;
            <D.9156>:
            D.9501 = i * 4;
            D.9502 = handles + D.9501;
            D.9503 = *D.9502;
            D.9566 = _wapi_handle_issignalled (D.9503);
            if (D.9566 != 0) goto <D.9567>; else goto <D.9568>;
            <D.9567>:
            done = 1;
            <D.9568>:
            i = i + 1;
            <D.9157>:
            if (i < numobjects) goto <D.9156>; else goto <D.9158>;
            <D.9158>:
            <D.9565>:
            if (done == 0) goto <D.9569>; else goto <D.9570>;
            <D.9569>:
            if (timeout == 4294967295) goto <D.9571>; else goto <D.9572>;
            <D.9571>:
            D.9573 = _wapi_handle_wait_signal (poll);
            ret = (guint32) D.9573;
            goto <D.9574>;
            <D.9572>:
            D.9575 = _wapi_handle_timedwait_signal (&abstime, poll);
            ret = (guint32) D.9575;
            <D.9574>:
            goto <D.9576>;
            <D.9570>:
            ret = 0;
            <D.9576>:
            thr_ret = _wapi_handle_unlock_signal_mutex (0B);
            D.9555 = thr_ret != 0;
            D.9556 = (long int) D.9555;
            D.9557 = __builtin_expect (D.9556, 0);
            if (D.9557 != 0) goto <D.9577>; else goto <D.9578>;
            <D.9577>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 680, "thr_ret == 0");
            <D.9578>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9579>; else goto <D.9580>;
            <D.9579>:
            __cancel_routine (__cancel_arg);
            <D.9580>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (alertable != 0) goto <D.9581>; else goto <D.9582>;
      <D.9581>:
      D.9583 = _wapi_thread_apc_pending (current_thread);
      if (D.9583 != 0) goto <D.9584>; else goto <D.9585>;
      <D.9584>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      retval = 192;
      goto <D.9159>;
      <D.9585>:
      <D.9582>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.9586>; else goto <D.9587>;
      <D.9586>:
      retval = lowest;
      goto <D.9159>;
      <D.9587>:
      if (ret != 0) goto <D.9588>; else goto <D.9589>;
      <D.9588>:
      if (ret == 110) goto <D.9590>; else goto <D.9591>;
      <D.9590>:
      retval = 258;
      goto <D.9592>;
      <D.9591>:
      retval = 4294967295;
      <D.9592>:
      goto <D.9159>;
      <D.9589>:
      goto <D.9160>;
      <D.9159>:
      i = 0;
      goto <D.9162>;
      <D.9161>:
      D.9501 = i * 4;
      D.9502 = handles + D.9501;
      D.9503 = *D.9502;
      _wapi_handle_unref (D.9503);
      i = i + 1;
      <D.9162>:
      if (i < numobjects) goto <D.9161>; else goto <D.9163>;
      <D.9163>:
      D.9495 = retval;
      return D.9495;
    }
  finally
    {
      count = {CLOBBER};
      lowest = {CLOBBER};
      abstime = {CLOBBER};
      sorted_handles = {CLOBBER};
    }
}


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

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


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

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


test_and_own (guint32 numobjects, void * * handles, gboolean waitall, guint32 * count, guint32 * lowest)
{
  long int D.9622;
  unsigned int i.7;
  unsigned int D.9630;
  void * * D.9631;
  void * D.9632;
  unsigned int i.8;
  unsigned int D.9635;
  unsigned int D.9636;
  void * * D.9637;
  void * D.9638;
  gboolean D.9641;
  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 (*<Tbf>) (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.9622 = __builtin_expect (__not_first_call, 0);
            if (D.9622 != 0) goto <D.9623>; else goto <D.9624>;
            <D.9623>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9624>:
            __pthread_register_cancel (&__cancel_buf);
            done = _wapi_handle_count_signalled_handles (numobjects, handles, waitall, count, lowest);
            if (done == 1) goto <D.9625>; else goto <D.9626>;
            <D.9625>:
            if (waitall == 1) goto <D.9627>; else goto <D.9628>;
            <D.9627>:
            i = 0;
            goto <D.9110>;
            <D.9109>:
            i.7 = (unsigned int) i;
            D.9630 = i.7 * 4;
            D.9631 = handles + D.9630;
            D.9632 = *D.9631;
            own_if_signalled (D.9632);
            i = i + 1;
            <D.9110>:
            i.8 = (unsigned int) i;
            if (i.8 < numobjects) goto <D.9109>; else goto <D.9111>;
            <D.9111>:
            goto <D.9634>;
            <D.9628>:
            D.9635 = *lowest;
            D.9636 = D.9635 * 4;
            D.9637 = handles + D.9636;
            D.9638 = *D.9637;
            own_if_signalled (D.9638);
            <D.9634>:
            <D.9626>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (1 != 0) goto <D.9639>; else goto <D.9640>;
            <D.9639>:
            __cancel_routine (__cancel_arg);
            <D.9640>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9641 = done;
      return D.9641;
    }
  finally
    {
      cleanup_data = {CLOBBER};
    }
}


handle_cleanup (void * data)
{
  void * * D.9645;
  unsigned int D.9646;
  struct handle_cleanup_data * handles;

  handles = data;
  D.9645 = handles->handles;
  D.9646 = handles->numobjects;
  _wapi_handle_unlock_handles (D.9646, D.9645);
}


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

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


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

  D.9649 = 258;
  return D.9649;
}


