WaitForSingleObjectEx (void * handle, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9696;
  guint32 D.9699;
  long int handle.0;
  signed int D.9705;
  int D.9708;
  int D.9711;
  int D.9716;
  long int D.9719;
  long int D.9720;
  _Bool D.9723;
  long int D.9724;
  long int D.9725;
  int D.9728;
  int D.9731;
  int D.9736;
  int D.9739;
  int D.9746;
  int D.9751;
  int D.9753;
  int D.9760;
  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.9696 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9696);
      if (current_thread == 0B) goto <D.9697>; else goto <D.9698>;
      <D.9697>:
      SetLastError (6);
      D.9699 = 4294967295;
      return D.9699;
      <D.9698>:
      if (handle == 4294967294B) goto <D.9700>; else goto <D.9701>;
      <D.9700>:
      D.9696 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.9696);
      if (handle == 0B) goto <D.9702>; else goto <D.9703>;
      <D.9702>:
      SetLastError (6);
      D.9699 = 4294967295;
      return D.9699;
      <D.9703>:
      <D.9701>:
      handle.0 = (long int) handle;
      D.9705 = (signed int) handle.0;
      if (D.9705 < 0) goto <D.9706>; else goto <D.9707>;
      <D.9706>:
      SetLastError (6);
      D.9699 = 4294967295;
      return D.9699;
      <D.9707>:
      D.9708 = _wapi_handle_test_capabilities (handle, 1);
      if (D.9708 == 0) goto <D.9709>; else goto <D.9710>;
      <D.9709>:
      D.9699 = 4294967295;
      return D.9699;
      <D.9710>:
      _wapi_handle_ops_prewait (handle);
      D.9711 = _wapi_handle_test_capabilities (handle, 8);
      if (D.9711 == 1) goto <D.9712>; else goto <D.9713>;
      <D.9712>:
      ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
      if (alertable != 0) goto <D.9714>; else goto <D.9715>;
      <D.9714>:
      D.9716 = _wapi_thread_apc_pending (current_thread);
      if (D.9716 != 0) goto <D.9717>; else goto <D.9718>;
      <D.9717>:
      apc_pending = 1;
      ret = 192;
      <D.9718>:
      <D.9715>:
      goto check_pending;
      <D.9713>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc6>) (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.9719 = (long int) __not_first_call;
            D.9720 = __builtin_expect (D.9719, 0);
            if (D.9720 != 0) goto <D.9721>; else goto <D.9722>;
            <D.9721>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9722>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9723 = thr_ret != 0;
            D.9724 = (long int) D.9723;
            D.9725 = __builtin_expect (D.9724, 0);
            if (D.9725 != 0) goto <D.9726>; else goto <D.9727>;
            <D.9726>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 147, "thr_ret == 0");
            <D.9727>:
            D.9728 = _wapi_handle_test_capabilities (handle, 4);
            if (D.9728 == 1) goto <D.9729>; else goto <D.9730>;
            <D.9729>:
            D.9731 = own_if_owned (handle);
            if (D.9731 == 1) goto <D.9732>; else goto <D.9733>;
            <D.9732>:
            ret = 0;
            goto done;
            <D.9733>:
            <D.9730>:
            if (alertable != 0) goto <D.9734>; else goto <D.9735>;
            <D.9734>:
            D.9736 = _wapi_thread_apc_pending (current_thread);
            if (D.9736 != 0) goto <D.9737>; else goto <D.9738>;
            <D.9737>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9738>:
            <D.9735>:
            D.9739 = own_if_signalled (handle);
            if (D.9739 == 1) goto <D.9740>; else goto <D.9741>;
            <D.9740>:
            ret = 0;
            goto done;
            <D.9741>:
            if (timeout == 0) goto <D.9742>; else goto <D.9743>;
            <D.9742>:
            ret = 258;
            goto done;
            <D.9743>:
            if (timeout != 4294967295) goto <D.9744>; else goto <D.9745>;
            <D.9744>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9745>:
            <D.9580>:
            _wapi_handle_ops_prewait (handle);
            D.9746 = own_if_signalled (handle);
            if (D.9746 != 0) goto <D.9747>; else goto <D.9748>;
            <D.9747>:
            ret = 0;
            goto done;
            <D.9748>:
            if (timeout == 4294967295) goto <D.9749>; else goto <D.9750>;
            <D.9749>:
            D.9751 = _wapi_handle_wait_signal_handle (handle, alertable);
            waited = (guint32) D.9751;
            goto <D.9752>;
            <D.9750>:
            D.9753 = _wapi_handle_timedwait_signal_handle (handle, &abstime, alertable, 0);
            waited = (guint32) D.9753;
            <D.9752>:
            if (alertable != 0) goto <D.9754>; else goto <D.9755>;
            <D.9754>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9755>:
            if (waited == 0) goto <D.9756>; else goto <D.9757>;
            <D.9756>:
            if (apc_pending == 0) goto <D.9758>; else goto <D.9759>;
            <D.9758>:
            D.9760 = own_if_signalled (handle);
            if (D.9760 != 0) goto <D.9761>; else goto <D.9762>;
            <D.9761>:
            ret = 0;
            goto done;
            <D.9762>:
            <D.9759>:
            <D.9757>:
            if (waited == 0) goto <D.9763>; else goto <D.9581>;
            <D.9763>:
            if (apc_pending == 0) goto <D.9580>; else goto <D.9581>;
            <D.9581>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9723 = thr_ret != 0;
            D.9724 = (long int) D.9723;
            D.9725 = __builtin_expect (D.9724, 0);
            if (D.9725 != 0) goto <D.9764>; else goto <D.9765>;
            <D.9764>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 232, "thr_ret == 0");
            <D.9765>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9766>; else goto <D.9767>;
            <D.9766>:
            __cancel_routine (__cancel_arg);
            <D.9767>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      check_pending:
      if (apc_pending != 0) goto <D.9768>; else goto <D.9769>;
      <D.9768>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.9769>:
      D.9699 = ret;
      return D.9699;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  long int handle.1;
  int D.9792;
  <unnamed type> D.9795;
  <unnamed type> D.9797;
  <unnamed type> D.9799;
  <unnamed type> D.9801;
  unsigned int D.9802;
  struct _WapiHandleUnshared * D.9803;
  long unsigned int D.9804;
  long unsigned int D.9805;
  long unsigned int D.9806;
  struct _WapiHandleUnshared * D.9807;
  union mono_mutex_t * D.9808;
  guint32 idx;

  handle.1 = (long int) handle;
  idx = (guint32) handle.1;
  if (idx > 4194303) goto <D.9790>; else goto <D.9791>;
  <D.9790>:
  D.9792 = 0;
  return D.9792;
  <D.9791>:
  _wapi_handle_ref (handle);
  D.9795 = _wapi_handle_type (handle);
  if (D.9795 == 9) goto <D.9793>; else goto <D.9796>;
  <D.9796>:
  D.9797 = _wapi_handle_type (handle);
  if (D.9797 == 11) goto <D.9793>; else goto <D.9798>;
  <D.9798>:
  D.9799 = _wapi_handle_type (handle);
  if (D.9799 == 12) goto <D.9793>; else goto <D.9800>;
  <D.9800>:
  D.9801 = _wapi_handle_type (handle);
  if (D.9801 == 13) goto <D.9793>; else goto <D.9794>;
  <D.9793>:
  D.9792 = 0;
  return D.9792;
  <D.9794>:
  D.9802 = idx / 256;
  D.9803 = _wapi_private_handles[D.9802];
  D.9804 = (long unsigned int) idx;
  D.9805 = D.9804 & 255;
  D.9806 = D.9805 * 200;
  D.9807 = D.9803 + D.9806;
  D.9808 = &D.9807->signal_mutex;
  D.9792 = pthread_mutex_lock (D.9808);
  return D.9792;
}


_wapi_handle_type (void * handle)
{
  long int handle.2;
  unsigned int D.9815;
  struct _WapiHandleUnshared * D.9816;
  WapiHandleType D.9817;
  unsigned int D.9818;
  struct _WapiHandleUnshared * D.9819;
  long unsigned int D.9820;
  long unsigned int D.9821;
  long unsigned int D.9822;
  struct _WapiHandleUnshared * D.9823;
  guint32 idx;

  handle.2 = (long int) handle;
  idx = (guint32) handle.2;
  if (idx > 4194303) goto <D.9811>; else goto <D.9813>;
  <D.9813>:
  if (idx > 268435455) goto <D.9811>; else goto <D.9814>;
  <D.9814>:
  D.9815 = idx / 256;
  D.9816 = _wapi_private_handles[D.9815];
  if (D.9816 == 0B) goto <D.9811>; else goto <D.9812>;
  <D.9811>:
  D.9817 = 0;
  return D.9817;
  <D.9812>:
  D.9818 = idx / 256;
  D.9819 = _wapi_private_handles[D.9818];
  D.9820 = (long unsigned int) idx;
  D.9821 = D.9820 & 255;
  D.9822 = D.9821 * 200;
  D.9823 = D.9819 + D.9822;
  D.9817 = D.9823->type;
  return D.9817;
}


own_if_owned (void * handle)
{
  <unnamed type> D.9827;
  <unnamed type> D.9829;
  <unnamed type> D.9831;
  <unnamed type> D.9833;
  int D.9834;
  gboolean D.9837;
  int D.9838;
  <unnamed type> D.9843;
  <unnamed type> D.9845;
  <unnamed type> D.9847;
  <unnamed type> D.9849;
  gboolean ret;

  ret = 0;
  D.9827 = _wapi_handle_type (handle);
  if (D.9827 == 9) goto <D.9825>; else goto <D.9828>;
  <D.9828>:
  D.9829 = _wapi_handle_type (handle);
  if (D.9829 == 11) goto <D.9825>; else goto <D.9830>;
  <D.9830>:
  D.9831 = _wapi_handle_type (handle);
  if (D.9831 == 12) goto <D.9825>; else goto <D.9832>;
  <D.9832>:
  D.9833 = _wapi_handle_type (handle);
  if (D.9833 == 13) goto <D.9825>; else goto <D.9826>;
  <D.9825>:
  D.9834 = _wapi_handle_trylock_shared_handles ();
  if (D.9834 == 16) goto <D.9835>; else goto <D.9836>;
  <D.9835>:
  D.9837 = 0;
  return D.9837;
  <D.9836>:
  <D.9826>:
  D.9838 = _wapi_handle_ops_isowned (handle);
  if (D.9838 != 0) goto <D.9839>; else goto <D.9840>;
  <D.9839>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9840>:
  D.9843 = _wapi_handle_type (handle);
  if (D.9843 == 9) goto <D.9841>; else goto <D.9844>;
  <D.9844>:
  D.9845 = _wapi_handle_type (handle);
  if (D.9845 == 11) goto <D.9841>; else goto <D.9846>;
  <D.9846>:
  D.9847 = _wapi_handle_type (handle);
  if (D.9847 == 12) goto <D.9841>; else goto <D.9848>;
  <D.9848>:
  D.9849 = _wapi_handle_type (handle);
  if (D.9849 == 13) goto <D.9841>; else goto <D.9842>;
  <D.9841>:
  _wapi_handle_unlock_shared_handles ();
  <D.9842>:
  D.9837 = ret;
  return D.9837;
}


_wapi_handle_trylock_shared_handles ()
{
  int D.9851;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.9853;

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


own_if_signalled (void * handle)
{
  <unnamed type> D.9857;
  <unnamed type> D.9859;
  <unnamed type> D.9861;
  <unnamed type> D.9863;
  int D.9864;
  gboolean D.9867;
  int D.9868;
  <unnamed type> D.9873;
  <unnamed type> D.9875;
  <unnamed type> D.9877;
  <unnamed type> D.9879;
  gboolean ret;

  ret = 0;
  D.9857 = _wapi_handle_type (handle);
  if (D.9857 == 9) goto <D.9855>; else goto <D.9858>;
  <D.9858>:
  D.9859 = _wapi_handle_type (handle);
  if (D.9859 == 11) goto <D.9855>; else goto <D.9860>;
  <D.9860>:
  D.9861 = _wapi_handle_type (handle);
  if (D.9861 == 12) goto <D.9855>; else goto <D.9862>;
  <D.9862>:
  D.9863 = _wapi_handle_type (handle);
  if (D.9863 == 13) goto <D.9855>; else goto <D.9856>;
  <D.9855>:
  D.9864 = _wapi_handle_trylock_shared_handles ();
  if (D.9864 == 16) goto <D.9865>; else goto <D.9866>;
  <D.9865>:
  D.9867 = 0;
  return D.9867;
  <D.9866>:
  <D.9856>:
  D.9868 = _wapi_handle_issignalled (handle);
  if (D.9868 != 0) goto <D.9869>; else goto <D.9870>;
  <D.9869>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.9870>:
  D.9873 = _wapi_handle_type (handle);
  if (D.9873 == 9) goto <D.9871>; else goto <D.9874>;
  <D.9874>:
  D.9875 = _wapi_handle_type (handle);
  if (D.9875 == 11) goto <D.9871>; else goto <D.9876>;
  <D.9876>:
  D.9877 = _wapi_handle_type (handle);
  if (D.9877 == 12) goto <D.9871>; else goto <D.9878>;
  <D.9878>:
  D.9879 = _wapi_handle_type (handle);
  if (D.9879 == 13) goto <D.9871>; else goto <D.9872>;
  <D.9871>:
  _wapi_handle_unlock_shared_handles ();
  <D.9872>:
  D.9867 = ret;
  return D.9867;
}


_wapi_handle_issignalled (void * handle)
{
  long int handle.3;
  gboolean D.9884;
  <unnamed type> D.9887;
  <unnamed type> D.9889;
  <unnamed type> D.9891;
  <unnamed type> D.9893;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.4;
  unsigned int D.9895;
  unsigned int D.9896;
  struct _WapiHandleUnshared * D.9897;
  long unsigned int D.9898;
  long unsigned int D.9899;
  long unsigned int D.9900;
  struct _WapiHandleUnshared * D.9901;
  unsigned int D.9902;
  unsigned int D.9903;
  struct _WapiHandleUnshared * D.9904;
  long unsigned int D.9905;
  long unsigned int D.9906;
  long unsigned int D.9907;
  struct _WapiHandleUnshared * D.9908;
  guint32 idx;

  handle.3 = (long int) handle;
  idx = (guint32) handle.3;
  if (idx > 4194303) goto <D.9882>; else goto <D.9883>;
  <D.9882>:
  D.9884 = 0;
  return D.9884;
  <D.9883>:
  D.9887 = _wapi_handle_type (handle);
  if (D.9887 == 9) goto <D.9885>; else goto <D.9888>;
  <D.9888>:
  D.9889 = _wapi_handle_type (handle);
  if (D.9889 == 11) goto <D.9885>; else goto <D.9890>;
  <D.9890>:
  D.9891 = _wapi_handle_type (handle);
  if (D.9891 == 12) goto <D.9885>; else goto <D.9892>;
  <D.9892>:
  D.9893 = _wapi_handle_type (handle);
  if (D.9893 == 13) goto <D.9885>; else goto <D.9886>;
  <D.9885>:
  _wapi_shared_layout.4 = _wapi_shared_layout;
  handle.3 = (long int) handle;
  D.9895 = (unsigned int) handle.3;
  D.9896 = D.9895 / 256;
  D.9897 = _wapi_private_handles[D.9896];
  handle.3 = (long int) handle;
  D.9895 = (unsigned int) handle.3;
  D.9898 = (long unsigned int) D.9895;
  D.9899 = D.9898 & 255;
  D.9900 = D.9899 * 200;
  D.9901 = D.9897 + D.9900;
  D.9902 = D.9901->u.shared.offset;
  D.9884 = _wapi_shared_layout.4->handles[D.9902].signalled;
  return D.9884;
  <D.9886>:
  D.9903 = idx / 256;
  D.9904 = _wapi_private_handles[D.9903];
  D.9905 = (long unsigned int) idx;
  D.9906 = D.9905 & 255;
  D.9907 = D.9906 * 200;
  D.9908 = D.9904 + D.9907;
  D.9884 = D.9908->signalled;
  return D.9884;
}


_wapi_handle_unlock_handle (void * handle)
{
  long int handle.5;
  int D.9913;
  <unnamed type> D.9916;
  <unnamed type> D.9918;
  <unnamed type> D.9920;
  <unnamed type> D.9922;
  unsigned int D.9923;
  struct _WapiHandleUnshared * D.9924;
  long unsigned int D.9925;
  long unsigned int D.9926;
  long unsigned int D.9927;
  struct _WapiHandleUnshared * D.9928;
  union mono_mutex_t * D.9929;
  guint32 idx;
  int ret;

  handle.5 = (long int) handle;
  idx = (guint32) handle.5;
  if (idx > 4194303) goto <D.9911>; else goto <D.9912>;
  <D.9911>:
  D.9913 = 0;
  return D.9913;
  <D.9912>:
  D.9916 = _wapi_handle_type (handle);
  if (D.9916 == 9) goto <D.9914>; else goto <D.9917>;
  <D.9917>:
  D.9918 = _wapi_handle_type (handle);
  if (D.9918 == 11) goto <D.9914>; else goto <D.9919>;
  <D.9919>:
  D.9920 = _wapi_handle_type (handle);
  if (D.9920 == 12) goto <D.9914>; else goto <D.9921>;
  <D.9921>:
  D.9922 = _wapi_handle_type (handle);
  if (D.9922 == 13) goto <D.9914>; else goto <D.9915>;
  <D.9914>:
  _wapi_handle_unref (handle);
  D.9913 = 0;
  return D.9913;
  <D.9915>:
  D.9923 = idx / 256;
  D.9924 = _wapi_private_handles[D.9923];
  D.9925 = (long unsigned int) idx;
  D.9926 = D.9925 & 255;
  D.9927 = D.9926 * 200;
  D.9928 = D.9924 + D.9927;
  D.9929 = &D.9928->signal_mutex;
  ret = pthread_mutex_unlock (D.9929);
  _wapi_handle_unref (handle);
  D.9913 = ret;
  return D.9913;
}


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

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


SignalObjectAndWait (void * signal_handle, void * wait, guint32 timeout, gboolean alertable)
{
  long unsigned int D.9933;
  guint32 D.9936;
  long int signal_handle.6;
  signed int D.9946;
  long int wait.7;
  signed int D.9950;
  int D.9953;
  int D.9956;
  int D.9959;
  long int D.9962;
  long int D.9963;
  _Bool D.9966;
  long int D.9967;
  long int D.9968;
  int D.9971;
  int D.9974;
  int D.9979;
  int D.9982;
  int D.9987;
  int D.9992;
  int D.9994;
  int D.10001;
  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.9933 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.9933);
      if (current_thread == 0B) goto <D.9934>; else goto <D.9935>;
      <D.9934>:
      SetLastError (6);
      D.9936 = 4294967295;
      return D.9936;
      <D.9935>:
      if (signal_handle == 4294967294B) goto <D.9937>; else goto <D.9938>;
      <D.9937>:
      D.9933 = pthread_self ();
      signal_handle = _wapi_thread_handle_from_id (D.9933);
      if (signal_handle == 0B) goto <D.9939>; else goto <D.9940>;
      <D.9939>:
      SetLastError (6);
      D.9936 = 4294967295;
      return D.9936;
      <D.9940>:
      <D.9938>:
      if (wait == 4294967294B) goto <D.9941>; else goto <D.9942>;
      <D.9941>:
      D.9933 = pthread_self ();
      wait = _wapi_thread_handle_from_id (D.9933);
      if (wait == 0B) goto <D.9943>; else goto <D.9944>;
      <D.9943>:
      SetLastError (6);
      D.9936 = 4294967295;
      return D.9936;
      <D.9944>:
      <D.9942>:
      signal_handle.6 = (long int) signal_handle;
      D.9946 = (signed int) signal_handle.6;
      if (D.9946 < 0) goto <D.9947>; else goto <D.9948>;
      <D.9947>:
      SetLastError (6);
      D.9936 = 4294967295;
      return D.9936;
      <D.9948>:
      wait.7 = (long int) wait;
      D.9950 = (signed int) wait.7;
      if (D.9950 < 0) goto <D.9951>; else goto <D.9952>;
      <D.9951>:
      SetLastError (6);
      D.9936 = 4294967295;
      return D.9936;
      <D.9952>:
      D.9953 = _wapi_handle_test_capabilities (signal_handle, 2);
      if (D.9953 == 0) goto <D.9954>; else goto <D.9955>;
      <D.9954>:
      D.9936 = 4294967295;
      return D.9936;
      <D.9955>:
      D.9956 = _wapi_handle_test_capabilities (wait, 1);
      if (D.9956 == 0) goto <D.9957>; else goto <D.9958>;
      <D.9957>:
      D.9936 = 4294967295;
      return D.9936;
      <D.9958>:
      _wapi_handle_ops_prewait (wait);
      D.9959 = _wapi_handle_test_capabilities (wait, 8);
      if (D.9959 == 1) goto <D.9960>; else goto <D.9961>;
      <D.9960>:
      monoeg_g_log (0B, 16, "%s: handle %p has special wait, implement me!!", &__func__, wait);
      D.9936 = 4294967295;
      return D.9936;
      <D.9961>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc6>) (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.9962 = (long int) __not_first_call;
            D.9963 = __builtin_expect (D.9962, 0);
            if (D.9963 != 0) goto <D.9964>; else goto <D.9965>;
            <D.9964>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9965>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (wait);
            D.9966 = thr_ret != 0;
            D.9967 = (long int) D.9966;
            D.9968 = __builtin_expect (D.9967, 0);
            if (D.9968 != 0) goto <D.9969>; else goto <D.9970>;
            <D.9969>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 349, "thr_ret == 0");
            <D.9970>:
            _wapi_handle_ops_signal (signal_handle);
            D.9971 = _wapi_handle_test_capabilities (wait, 4);
            if (D.9971 == 1) goto <D.9972>; else goto <D.9973>;
            <D.9972>:
            D.9974 = own_if_owned (wait);
            if (D.9974 != 0) goto <D.9975>; else goto <D.9976>;
            <D.9975>:
            ret = 0;
            goto done;
            <D.9976>:
            <D.9973>:
            if (alertable != 0) goto <D.9977>; else goto <D.9978>;
            <D.9977>:
            D.9979 = _wapi_thread_apc_pending (current_thread);
            if (D.9979 != 0) goto <D.9980>; else goto <D.9981>;
            <D.9980>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.9981>:
            <D.9978>:
            D.9982 = own_if_signalled (wait);
            if (D.9982 != 0) goto <D.9983>; else goto <D.9984>;
            <D.9983>:
            ret = 0;
            goto done;
            <D.9984>:
            if (timeout != 4294967295) goto <D.9985>; else goto <D.9986>;
            <D.9985>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.9986>:
            <D.9606>:
            _wapi_handle_ops_prewait (wait);
            D.9987 = own_if_signalled (wait);
            if (D.9987 != 0) goto <D.9988>; else goto <D.9989>;
            <D.9988>:
            ret = 0;
            goto done;
            <D.9989>:
            if (timeout == 4294967295) goto <D.9990>; else goto <D.9991>;
            <D.9990>:
            D.9992 = _wapi_handle_wait_signal_handle (wait, alertable);
            waited = (guint32) D.9992;
            goto <D.9993>;
            <D.9991>:
            D.9994 = _wapi_handle_timedwait_signal_handle (wait, &abstime, alertable, 0);
            waited = (guint32) D.9994;
            <D.9993>:
            if (alertable != 0) goto <D.9995>; else goto <D.9996>;
            <D.9995>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.9996>:
            if (waited == 0) goto <D.9997>; else goto <D.9998>;
            <D.9997>:
            if (apc_pending == 0) goto <D.9999>; else goto <D.10000>;
            <D.9999>:
            D.10001 = own_if_signalled (wait);
            if (D.10001 != 0) goto <D.10002>; else goto <D.10003>;
            <D.10002>:
            ret = 0;
            goto done;
            <D.10003>:
            <D.10000>:
            <D.9998>:
            if (waited == 0) goto <D.10004>; else goto <D.9607>;
            <D.10004>:
            if (apc_pending == 0) goto <D.9606>; else goto <D.9607>;
            <D.9607>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (wait);
            D.9966 = thr_ret != 0;
            D.9967 = (long int) D.9966;
            D.9968 = __builtin_expect (D.9967, 0);
            if (D.9968 != 0) goto <D.10005>; else goto <D.10006>;
            <D.10005>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 430, "thr_ret == 0");
            <D.10006>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.10007>; else goto <D.10008>;
            <D.10007>:
            __cancel_routine (__cancel_arg);
            <D.10008>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (apc_pending != 0) goto <D.10009>; else goto <D.10010>;
      <D.10009>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.10010>:
      D.9936 = ret;
      return D.9936;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


WaitForMultipleObjectsEx (guint32 numobjects, void * * handles, gboolean waitall, guint32 timeout, gboolean alertable)
{
  long unsigned int D.10030;
  guint32 D.10033;
  void * D.10038;
  long unsigned int D.10039;
  long unsigned int D.10040;
  void * * D.10041;
  void * D.10042;
  void * D.10045;
  long int D.10048;
  signed int D.10049;
  int D.10052;
  long unsigned int D.10055;
  unsigned int D.10056;
  void * D.10057;
  void * D.10058;
  <unnamed type> D.10067;
  <unnamed type> D.10069;
  <unnamed type> D.10071;
  <unnamed type> D.10073;
  <unnamed type> D.10075;
  int D.10084;
  int D.10087;
  int D.10090;
  long int D.10093;
  long int D.10094;
  _Bool D.10097;
  long int D.10098;
  long int D.10099;
  int D.10104;
  int D.10108;
  int D.10115;
  int D.10117;
  int D.10125;
  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.10030 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.10030);
      if (current_thread == 0B) goto <D.10031>; else goto <D.10032>;
      <D.10031>:
      SetLastError (6);
      D.10033 = 4294967295;
      return D.10033;
      <D.10032>:
      if (numobjects > 64) goto <D.10034>; else goto <D.10035>;
      <D.10034>:
      D.10033 = 4294967295;
      return D.10033;
      <D.10035>:
      if (numobjects == 1) goto <D.10036>; else goto <D.10037>;
      <D.10036>:
      D.10038 = *handles;
      D.10033 = WaitForSingleObjectEx (D.10038, timeout, alertable);
      return D.10033;
      <D.10037>:
      i = 0;
      goto <D.9655>;
      <D.9654>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      if (D.10042 == 4294967294B) goto <D.10043>; else goto <D.10044>;
      <D.10043>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10030 = pthread_self ();
      D.10045 = _wapi_thread_handle_from_id (D.10030);
      *D.10041 = D.10045;
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      if (D.10042 == 0B) goto <D.10046>; else goto <D.10047>;
      <D.10046>:
      bogustype = 1;
      goto <D.9653>;
      <D.10047>:
      <D.10044>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10048 = (long int) D.10042;
      D.10049 = (signed int) D.10048;
      if (D.10049 < 0) goto <D.10050>; else goto <D.10051>;
      <D.10050>:
      bogustype = 1;
      goto <D.9653>;
      <D.10051>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10052 = _wapi_handle_test_capabilities (D.10042, 1);
      if (D.10052 == 0) goto <D.10053>; else goto <D.10054>;
      <D.10053>:
      bogustype = 1;
      goto <D.9653>;
      <D.10054>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      sorted_handles[i] = D.10042;
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      _wapi_handle_ops_prewait (D.10042);
      i = i + 1;
      <D.9655>:
      if (i < numobjects) goto <D.9654>; else goto <D.9653>;
      <D.9653>:
      D.10055 = (long unsigned int) numobjects;
      qsort (&sorted_handles, D.10055, 8, monoeg_g_direct_equal);
      i = 1;
      goto <D.9658>;
      <D.9657>:
      D.10056 = i + 4294967295;
      D.10057 = sorted_handles[D.10056];
      D.10058 = sorted_handles[i];
      if (D.10057 == D.10058) goto <D.10059>; else goto <D.10060>;
      <D.10059>:
      duplicate = 1;
      goto <D.9656>;
      <D.10060>:
      i = i + 1;
      <D.9658>:
      if (i < numobjects) goto <D.9657>; else goto <D.9656>;
      <D.9656>:
      if (duplicate == 1) goto <D.10061>; else goto <D.10062>;
      <D.10061>:
      D.10033 = 4294967295;
      return D.10033;
      <D.10062>:
      if (bogustype == 1) goto <D.10063>; else goto <D.10064>;
      <D.10063>:
      D.10033 = 4294967295;
      return D.10033;
      <D.10064>:
      poll = 0;
      i = 0;
      goto <D.9660>;
      <D.9659>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10067 = _wapi_handle_type (D.10042);
      if (D.10067 == 9) goto <D.10065>; else goto <D.10068>;
      <D.10068>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10069 = _wapi_handle_type (D.10042);
      if (D.10069 == 9) goto <D.10065>; else goto <D.10070>;
      <D.10070>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10071 = _wapi_handle_type (D.10042);
      if (D.10071 == 11) goto <D.10065>; else goto <D.10072>;
      <D.10072>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10073 = _wapi_handle_type (D.10042);
      if (D.10073 == 12) goto <D.10065>; else goto <D.10074>;
      <D.10074>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10075 = _wapi_handle_type (D.10042);
      if (D.10075 == 13) goto <D.10065>; else goto <D.10066>;
      <D.10065>:
      poll = 1;
      <D.10066>:
      i = i + 1;
      <D.9660>:
      if (i < numobjects) goto <D.9659>; else goto <D.9661>;
      <D.9661>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.10076>; else goto <D.10077>;
      <D.10076>:
      D.10033 = lowest;
      return D.10033;
      <D.10077>:
      if (timeout == 0) goto <D.10078>; else goto <D.10079>;
      <D.10078>:
      D.10033 = 258;
      return D.10033;
      <D.10079>:
      if (timeout != 4294967295) goto <D.10080>; else goto <D.10081>;
      <D.10080>:
      _wapi_calc_timeout (&abstime, timeout);
      <D.10081>:
      if (alertable != 0) goto <D.10082>; else goto <D.10083>;
      <D.10082>:
      D.10084 = _wapi_thread_apc_pending (current_thread);
      if (D.10084 != 0) goto <D.10085>; else goto <D.10086>;
      <D.10085>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.10033 = 192;
      return D.10033;
      <D.10086>:
      <D.10083>:
      i = 0;
      goto <D.9663>;
      <D.9662>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      _wapi_handle_ref (D.10042);
      i = i + 1;
      <D.9663>:
      if (i < numobjects) goto <D.9662>; else goto <D.9664>;
      <D.9664>:
      <D.9681>:
      i = 0;
      goto <D.9666>;
      <D.9665>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      _wapi_handle_ops_prewait (D.10042);
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10087 = _wapi_handle_test_capabilities (D.10042, 8);
      if (D.10087 == 1) goto <D.10088>; else goto <D.10089>;
      <D.10088>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      D.10090 = _wapi_handle_issignalled (D.10042);
      if (D.10090 == 0) goto <D.10091>; else goto <D.10092>;
      <D.10091>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      _wapi_handle_ops_special_wait (D.10042, 0, alertable);
      <D.10092>:
      <D.10089>:
      i = i + 1;
      <D.9666>:
      if (i < numobjects) goto <D.9665>; else goto <D.9667>;
      <D.9667>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc6>) (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.10093 = (long int) __not_first_call;
            D.10094 = __builtin_expect (D.10093, 0);
            if (D.10094 != 0) goto <D.10095>; else goto <D.10096>;
            <D.10095>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10096>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_signal_mutex ();
            D.10097 = thr_ret != 0;
            D.10098 = (long int) D.10097;
            D.10099 = __builtin_expect (D.10098, 0);
            if (D.10099 != 0) goto <D.10100>; else goto <D.10101>;
            <D.10100>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 650, "thr_ret == 0");
            <D.10101>:
            if (waitall != 0) goto <D.10102>; else goto <D.10103>;
            <D.10102>:
            done = 1;
            i = 0;
            goto <D.9675>;
            <D.9674>:
            D.10039 = (long unsigned int) i;
            D.10040 = D.10039 * 8;
            D.10041 = handles + D.10040;
            D.10042 = *D.10041;
            D.10104 = _wapi_handle_issignalled (D.10042);
            if (D.10104 == 0) goto <D.10105>; else goto <D.10106>;
            <D.10105>:
            done = 0;
            <D.10106>:
            i = i + 1;
            <D.9675>:
            if (i < numobjects) goto <D.9674>; else goto <D.9676>;
            <D.9676>:
            goto <D.10107>;
            <D.10103>:
            done = 0;
            i = 0;
            goto <D.9678>;
            <D.9677>:
            D.10039 = (long unsigned int) i;
            D.10040 = D.10039 * 8;
            D.10041 = handles + D.10040;
            D.10042 = *D.10041;
            D.10108 = _wapi_handle_issignalled (D.10042);
            if (D.10108 != 0) goto <D.10109>; else goto <D.10110>;
            <D.10109>:
            done = 1;
            <D.10110>:
            i = i + 1;
            <D.9678>:
            if (i < numobjects) goto <D.9677>; else goto <D.9679>;
            <D.9679>:
            <D.10107>:
            if (done == 0) goto <D.10111>; else goto <D.10112>;
            <D.10111>:
            if (timeout == 4294967295) goto <D.10113>; else goto <D.10114>;
            <D.10113>:
            D.10115 = _wapi_handle_wait_signal (poll);
            ret = (guint32) D.10115;
            goto <D.10116>;
            <D.10114>:
            D.10117 = _wapi_handle_timedwait_signal (&abstime, poll);
            ret = (guint32) D.10117;
            <D.10116>:
            goto <D.10118>;
            <D.10112>:
            ret = 0;
            <D.10118>:
            thr_ret = _wapi_handle_unlock_signal_mutex (0B);
            D.10097 = thr_ret != 0;
            D.10098 = (long int) D.10097;
            D.10099 = __builtin_expect (D.10098, 0);
            if (D.10099 != 0) goto <D.10119>; else goto <D.10120>;
            <D.10119>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 680, "thr_ret == 0");
            <D.10120>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.10121>; else goto <D.10122>;
            <D.10121>:
            __cancel_routine (__cancel_arg);
            <D.10122>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (alertable != 0) goto <D.10123>; else goto <D.10124>;
      <D.10123>:
      D.10125 = _wapi_thread_apc_pending (current_thread);
      if (D.10125 != 0) goto <D.10126>; else goto <D.10127>;
      <D.10126>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      retval = 192;
      goto <D.9680>;
      <D.10127>:
      <D.10124>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.10128>; else goto <D.10129>;
      <D.10128>:
      retval = lowest;
      goto <D.9680>;
      <D.10129>:
      if (ret != 0) goto <D.10130>; else goto <D.10131>;
      <D.10130>:
      if (ret == 110) goto <D.10132>; else goto <D.10133>;
      <D.10132>:
      retval = 258;
      goto <D.10134>;
      <D.10133>:
      retval = 4294967295;
      <D.10134>:
      goto <D.9680>;
      <D.10131>:
      goto <D.9681>;
      <D.9680>:
      i = 0;
      goto <D.9683>;
      <D.9682>:
      D.10039 = (long unsigned int) i;
      D.10040 = D.10039 * 8;
      D.10041 = handles + D.10040;
      D.10042 = *D.10041;
      _wapi_handle_unref (D.10042);
      i = i + 1;
      <D.9683>:
      if (i < numobjects) goto <D.9682>; else goto <D.9684>;
      <D.9684>:
      D.10033 = retval;
      return D.10033;
    }
  finally
    {
      count = {CLOBBER};
      lowest = {CLOBBER};
      abstime = {CLOBBER};
      sorted_handles = {CLOBBER};
    }
}


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

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


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

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


test_and_own (guint32 numobjects, void * * handles, gboolean waitall, guint32 * count, guint32 * lowest)
{
  long int D.10164;
  long int D.10165;
  long unsigned int D.10172;
  long unsigned int D.10173;
  void * * D.10174;
  void * D.10175;
  unsigned int i.10;
  unsigned int D.10178;
  long unsigned int D.10179;
  long unsigned int D.10180;
  void * * D.10181;
  void * D.10182;
  gboolean D.10185;
  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 (*<Tc6>) (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.10164 = (long int) __not_first_call;
            D.10165 = __builtin_expect (D.10164, 0);
            if (D.10165 != 0) goto <D.10166>; else goto <D.10167>;
            <D.10166>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10167>:
            __pthread_register_cancel (&__cancel_buf);
            done = _wapi_handle_count_signalled_handles (numobjects, handles, waitall, count, lowest);
            if (done == 1) goto <D.10168>; else goto <D.10169>;
            <D.10168>:
            if (waitall == 1) goto <D.10170>; else goto <D.10171>;
            <D.10170>:
            i = 0;
            goto <D.9631>;
            <D.9630>:
            D.10172 = (long unsigned int) i;
            D.10173 = D.10172 * 8;
            D.10174 = handles + D.10173;
            D.10175 = *D.10174;
            own_if_signalled (D.10175);
            i = i + 1;
            <D.9631>:
            i.10 = (unsigned int) i;
            if (i.10 < numobjects) goto <D.9630>; else goto <D.9632>;
            <D.9632>:
            goto <D.10177>;
            <D.10171>:
            D.10178 = *lowest;
            D.10179 = (long unsigned int) D.10178;
            D.10180 = D.10179 * 8;
            D.10181 = handles + D.10180;
            D.10182 = *D.10181;
            own_if_signalled (D.10182);
            <D.10177>:
            <D.10169>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (1 != 0) goto <D.10183>; else goto <D.10184>;
            <D.10183>:
            __cancel_routine (__cancel_arg);
            <D.10184>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.10185 = done;
      return D.10185;
    }
  finally
    {
      cleanup_data = {CLOBBER};
    }
}


handle_cleanup (void * data)
{
  unsigned int D.10189;
  void * * D.10190;
  struct handle_cleanup_data * handles;

  handles = data;
  D.10189 = handles->numobjects;
  D.10190 = handles->handles;
  _wapi_handle_unlock_handles (D.10189, D.10190);
}


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

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


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

  D.10193 = 258;
  return D.10193;
}


