WaitForSingleObjectEx (void * handle, guint32 timeout, gboolean alertable)
{
  long unsigned int D.10041;
  guint32 D.10044;
  long int handle.0;
  signed int D.10050;
  int D.10053;
  int D.10056;
  int D.10061;
  long int D.10064;
  long int D.10065;
  _Bool D.10068;
  long int D.10069;
  long int D.10070;
  int D.10073;
  int D.10076;
  int D.10081;
  int D.10084;
  int D.10091;
  int D.10096;
  int D.10098;
  int D.10105;
  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.10041 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.10041);
      if (current_thread == 0B) goto <D.10042>; else goto <D.10043>;
      <D.10042>:
      SetLastError (6);
      D.10044 = 4294967295;
      return D.10044;
      <D.10043>:
      if (handle == 4294967294B) goto <D.10045>; else goto <D.10046>;
      <D.10045>:
      D.10041 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.10041);
      if (handle == 0B) goto <D.10047>; else goto <D.10048>;
      <D.10047>:
      SetLastError (6);
      D.10044 = 4294967295;
      return D.10044;
      <D.10048>:
      <D.10046>:
      handle.0 = (long int) handle;
      D.10050 = (signed int) handle.0;
      if (D.10050 < 0) goto <D.10051>; else goto <D.10052>;
      <D.10051>:
      SetLastError (6);
      D.10044 = 4294967295;
      return D.10044;
      <D.10052>:
      D.10053 = _wapi_handle_test_capabilities (handle, 1);
      if (D.10053 == 0) goto <D.10054>; else goto <D.10055>;
      <D.10054>:
      D.10044 = 4294967295;
      return D.10044;
      <D.10055>:
      _wapi_handle_ops_prewait (handle);
      D.10056 = _wapi_handle_test_capabilities (handle, 8);
      if (D.10056 == 1) goto <D.10057>; else goto <D.10058>;
      <D.10057>:
      ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
      if (alertable != 0) goto <D.10059>; else goto <D.10060>;
      <D.10059>:
      D.10061 = _wapi_thread_apc_pending (current_thread);
      if (D.10061 != 0) goto <D.10062>; else goto <D.10063>;
      <D.10062>:
      apc_pending = 1;
      ret = 192;
      <D.10063>:
      <D.10060>:
      goto check_pending;
      <D.10058>:
      {
        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.10064 = (long int) __not_first_call;
            D.10065 = __builtin_expect (D.10064, 0);
            if (D.10065 != 0) goto <D.10066>; else goto <D.10067>;
            <D.10066>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10067>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.10068 = thr_ret != 0;
            D.10069 = (long int) D.10068;
            D.10070 = __builtin_expect (D.10069, 0);
            if (D.10070 != 0) goto <D.10071>; else goto <D.10072>;
            <D.10071>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 147, "thr_ret == 0");
            <D.10072>:
            D.10073 = _wapi_handle_test_capabilities (handle, 4);
            if (D.10073 == 1) goto <D.10074>; else goto <D.10075>;
            <D.10074>:
            D.10076 = own_if_owned (handle);
            if (D.10076 == 1) goto <D.10077>; else goto <D.10078>;
            <D.10077>:
            ret = 0;
            goto done;
            <D.10078>:
            <D.10075>:
            if (alertable != 0) goto <D.10079>; else goto <D.10080>;
            <D.10079>:
            D.10081 = _wapi_thread_apc_pending (current_thread);
            if (D.10081 != 0) goto <D.10082>; else goto <D.10083>;
            <D.10082>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.10083>:
            <D.10080>:
            D.10084 = own_if_signalled (handle);
            if (D.10084 == 1) goto <D.10085>; else goto <D.10086>;
            <D.10085>:
            ret = 0;
            goto done;
            <D.10086>:
            if (timeout == 0) goto <D.10087>; else goto <D.10088>;
            <D.10087>:
            ret = 258;
            goto done;
            <D.10088>:
            if (timeout != 4294967295) goto <D.10089>; else goto <D.10090>;
            <D.10089>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.10090>:
            <D.9925>:
            _wapi_handle_ops_prewait (handle);
            D.10091 = own_if_signalled (handle);
            if (D.10091 != 0) goto <D.10092>; else goto <D.10093>;
            <D.10092>:
            ret = 0;
            goto done;
            <D.10093>:
            if (timeout == 4294967295) goto <D.10094>; else goto <D.10095>;
            <D.10094>:
            D.10096 = _wapi_handle_wait_signal_handle (handle, alertable);
            waited = (guint32) D.10096;
            goto <D.10097>;
            <D.10095>:
            D.10098 = _wapi_handle_timedwait_signal_handle (handle, &abstime, alertable, 0);
            waited = (guint32) D.10098;
            <D.10097>:
            if (alertable != 0) goto <D.10099>; else goto <D.10100>;
            <D.10099>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.10100>:
            if (waited == 0) goto <D.10101>; else goto <D.10102>;
            <D.10101>:
            if (apc_pending == 0) goto <D.10103>; else goto <D.10104>;
            <D.10103>:
            D.10105 = own_if_signalled (handle);
            if (D.10105 != 0) goto <D.10106>; else goto <D.10107>;
            <D.10106>:
            ret = 0;
            goto done;
            <D.10107>:
            <D.10104>:
            <D.10102>:
            if (waited == 0) goto <D.10108>; else goto <D.9926>;
            <D.10108>:
            if (apc_pending == 0) goto <D.9925>; else goto <D.9926>;
            <D.9926>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.10068 = thr_ret != 0;
            D.10069 = (long int) D.10068;
            D.10070 = __builtin_expect (D.10069, 0);
            if (D.10070 != 0) goto <D.10109>; else goto <D.10110>;
            <D.10109>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 232, "thr_ret == 0");
            <D.10110>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.10111>; else goto <D.10112>;
            <D.10111>:
            __cancel_routine (__cancel_arg);
            <D.10112>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      check_pending:
      if (apc_pending != 0) goto <D.10113>; else goto <D.10114>;
      <D.10113>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.10114>:
      D.10044 = ret;
      return D.10044;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  long int handle.1;
  int D.10137;
  <unnamed type> D.10140;
  <unnamed type> D.10142;
  <unnamed type> D.10144;
  <unnamed type> D.10146;
  unsigned int D.10147;
  struct _WapiHandleUnshared * D.10148;
  long unsigned int D.10149;
  long unsigned int D.10150;
  long unsigned int D.10151;
  struct _WapiHandleUnshared * D.10152;
  union mono_mutex_t * D.10153;
  guint32 idx;

  handle.1 = (long int) handle;
  idx = (guint32) handle.1;
  if (idx > 4194303) goto <D.10135>; else goto <D.10136>;
  <D.10135>:
  D.10137 = 0;
  return D.10137;
  <D.10136>:
  _wapi_handle_ref (handle);
  D.10140 = _wapi_handle_type (handle);
  if (D.10140 == 9) goto <D.10138>; else goto <D.10141>;
  <D.10141>:
  D.10142 = _wapi_handle_type (handle);
  if (D.10142 == 11) goto <D.10138>; else goto <D.10143>;
  <D.10143>:
  D.10144 = _wapi_handle_type (handle);
  if (D.10144 == 12) goto <D.10138>; else goto <D.10145>;
  <D.10145>:
  D.10146 = _wapi_handle_type (handle);
  if (D.10146 == 13) goto <D.10138>; else goto <D.10139>;
  <D.10138>:
  D.10137 = 0;
  return D.10137;
  <D.10139>:
  D.10147 = idx / 256;
  D.10148 = _wapi_private_handles[D.10147];
  D.10149 = (long unsigned int) idx;
  D.10150 = D.10149 & 255;
  D.10151 = D.10150 * 200;
  D.10152 = D.10148 + D.10151;
  D.10153 = &D.10152->signal_mutex;
  D.10137 = pthread_mutex_lock (D.10153);
  return D.10137;
}


_wapi_handle_type (void * handle)
{
  long int handle.2;
  unsigned int D.10160;
  struct _WapiHandleUnshared * D.10161;
  WapiHandleType D.10162;
  unsigned int D.10163;
  struct _WapiHandleUnshared * D.10164;
  long unsigned int D.10165;
  long unsigned int D.10166;
  long unsigned int D.10167;
  struct _WapiHandleUnshared * D.10168;
  guint32 idx;

  handle.2 = (long int) handle;
  idx = (guint32) handle.2;
  if (idx > 4194303) goto <D.10156>; else goto <D.10158>;
  <D.10158>:
  if (idx > 268435455) goto <D.10156>; else goto <D.10159>;
  <D.10159>:
  D.10160 = idx / 256;
  D.10161 = _wapi_private_handles[D.10160];
  if (D.10161 == 0B) goto <D.10156>; else goto <D.10157>;
  <D.10156>:
  D.10162 = 0;
  return D.10162;
  <D.10157>:
  D.10163 = idx / 256;
  D.10164 = _wapi_private_handles[D.10163];
  D.10165 = (long unsigned int) idx;
  D.10166 = D.10165 & 255;
  D.10167 = D.10166 * 200;
  D.10168 = D.10164 + D.10167;
  D.10162 = D.10168->type;
  return D.10162;
}


own_if_owned (void * handle)
{
  <unnamed type> D.10172;
  <unnamed type> D.10174;
  <unnamed type> D.10176;
  <unnamed type> D.10178;
  int D.10179;
  gboolean D.10182;
  int D.10183;
  <unnamed type> D.10188;
  <unnamed type> D.10190;
  <unnamed type> D.10192;
  <unnamed type> D.10194;
  gboolean ret;

  ret = 0;
  D.10172 = _wapi_handle_type (handle);
  if (D.10172 == 9) goto <D.10170>; else goto <D.10173>;
  <D.10173>:
  D.10174 = _wapi_handle_type (handle);
  if (D.10174 == 11) goto <D.10170>; else goto <D.10175>;
  <D.10175>:
  D.10176 = _wapi_handle_type (handle);
  if (D.10176 == 12) goto <D.10170>; else goto <D.10177>;
  <D.10177>:
  D.10178 = _wapi_handle_type (handle);
  if (D.10178 == 13) goto <D.10170>; else goto <D.10171>;
  <D.10170>:
  D.10179 = _wapi_handle_trylock_shared_handles ();
  if (D.10179 == 16) goto <D.10180>; else goto <D.10181>;
  <D.10180>:
  D.10182 = 0;
  return D.10182;
  <D.10181>:
  <D.10171>:
  D.10183 = _wapi_handle_ops_isowned (handle);
  if (D.10183 != 0) goto <D.10184>; else goto <D.10185>;
  <D.10184>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.10185>:
  D.10188 = _wapi_handle_type (handle);
  if (D.10188 == 9) goto <D.10186>; else goto <D.10189>;
  <D.10189>:
  D.10190 = _wapi_handle_type (handle);
  if (D.10190 == 11) goto <D.10186>; else goto <D.10191>;
  <D.10191>:
  D.10192 = _wapi_handle_type (handle);
  if (D.10192 == 12) goto <D.10186>; else goto <D.10193>;
  <D.10193>:
  D.10194 = _wapi_handle_type (handle);
  if (D.10194 == 13) goto <D.10186>; else goto <D.10187>;
  <D.10186>:
  _wapi_handle_unlock_shared_handles ();
  <D.10187>:
  D.10182 = ret;
  return D.10182;
}


_wapi_handle_trylock_shared_handles ()
{
  int D.10196;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.10198;

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


own_if_signalled (void * handle)
{
  <unnamed type> D.10202;
  <unnamed type> D.10204;
  <unnamed type> D.10206;
  <unnamed type> D.10208;
  int D.10209;
  gboolean D.10212;
  int D.10213;
  <unnamed type> D.10218;
  <unnamed type> D.10220;
  <unnamed type> D.10222;
  <unnamed type> D.10224;
  gboolean ret;

  ret = 0;
  D.10202 = _wapi_handle_type (handle);
  if (D.10202 == 9) goto <D.10200>; else goto <D.10203>;
  <D.10203>:
  D.10204 = _wapi_handle_type (handle);
  if (D.10204 == 11) goto <D.10200>; else goto <D.10205>;
  <D.10205>:
  D.10206 = _wapi_handle_type (handle);
  if (D.10206 == 12) goto <D.10200>; else goto <D.10207>;
  <D.10207>:
  D.10208 = _wapi_handle_type (handle);
  if (D.10208 == 13) goto <D.10200>; else goto <D.10201>;
  <D.10200>:
  D.10209 = _wapi_handle_trylock_shared_handles ();
  if (D.10209 == 16) goto <D.10210>; else goto <D.10211>;
  <D.10210>:
  D.10212 = 0;
  return D.10212;
  <D.10211>:
  <D.10201>:
  D.10213 = _wapi_handle_issignalled (handle);
  if (D.10213 != 0) goto <D.10214>; else goto <D.10215>;
  <D.10214>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.10215>:
  D.10218 = _wapi_handle_type (handle);
  if (D.10218 == 9) goto <D.10216>; else goto <D.10219>;
  <D.10219>:
  D.10220 = _wapi_handle_type (handle);
  if (D.10220 == 11) goto <D.10216>; else goto <D.10221>;
  <D.10221>:
  D.10222 = _wapi_handle_type (handle);
  if (D.10222 == 12) goto <D.10216>; else goto <D.10223>;
  <D.10223>:
  D.10224 = _wapi_handle_type (handle);
  if (D.10224 == 13) goto <D.10216>; else goto <D.10217>;
  <D.10216>:
  _wapi_handle_unlock_shared_handles ();
  <D.10217>:
  D.10212 = ret;
  return D.10212;
}


_wapi_handle_issignalled (void * handle)
{
  long int handle.3;
  gboolean D.10229;
  <unnamed type> D.10232;
  <unnamed type> D.10234;
  <unnamed type> D.10236;
  <unnamed type> D.10238;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.4;
  unsigned int D.10240;
  unsigned int D.10241;
  struct _WapiHandleUnshared * D.10242;
  long unsigned int D.10243;
  long unsigned int D.10244;
  long unsigned int D.10245;
  struct _WapiHandleUnshared * D.10246;
  unsigned int D.10247;
  unsigned int D.10248;
  struct _WapiHandleUnshared * D.10249;
  long unsigned int D.10250;
  long unsigned int D.10251;
  long unsigned int D.10252;
  struct _WapiHandleUnshared * D.10253;
  guint32 idx;

  handle.3 = (long int) handle;
  idx = (guint32) handle.3;
  if (idx > 4194303) goto <D.10227>; else goto <D.10228>;
  <D.10227>:
  D.10229 = 0;
  return D.10229;
  <D.10228>:
  D.10232 = _wapi_handle_type (handle);
  if (D.10232 == 9) goto <D.10230>; else goto <D.10233>;
  <D.10233>:
  D.10234 = _wapi_handle_type (handle);
  if (D.10234 == 11) goto <D.10230>; else goto <D.10235>;
  <D.10235>:
  D.10236 = _wapi_handle_type (handle);
  if (D.10236 == 12) goto <D.10230>; else goto <D.10237>;
  <D.10237>:
  D.10238 = _wapi_handle_type (handle);
  if (D.10238 == 13) goto <D.10230>; else goto <D.10231>;
  <D.10230>:
  _wapi_shared_layout.4 = _wapi_shared_layout;
  handle.3 = (long int) handle;
  D.10240 = (unsigned int) handle.3;
  D.10241 = D.10240 / 256;
  D.10242 = _wapi_private_handles[D.10241];
  handle.3 = (long int) handle;
  D.10240 = (unsigned int) handle.3;
  D.10243 = (long unsigned int) D.10240;
  D.10244 = D.10243 & 255;
  D.10245 = D.10244 * 200;
  D.10246 = D.10242 + D.10245;
  D.10247 = D.10246->u.shared.offset;
  D.10229 = _wapi_shared_layout.4->handles[D.10247].signalled;
  return D.10229;
  <D.10231>:
  D.10248 = idx / 256;
  D.10249 = _wapi_private_handles[D.10248];
  D.10250 = (long unsigned int) idx;
  D.10251 = D.10250 & 255;
  D.10252 = D.10251 * 200;
  D.10253 = D.10249 + D.10252;
  D.10229 = D.10253->signalled;
  return D.10229;
}


_wapi_handle_unlock_handle (void * handle)
{
  long int handle.5;
  int D.10258;
  <unnamed type> D.10261;
  <unnamed type> D.10263;
  <unnamed type> D.10265;
  <unnamed type> D.10267;
  unsigned int D.10268;
  struct _WapiHandleUnshared * D.10269;
  long unsigned int D.10270;
  long unsigned int D.10271;
  long unsigned int D.10272;
  struct _WapiHandleUnshared * D.10273;
  union mono_mutex_t * D.10274;
  guint32 idx;
  int ret;

  handle.5 = (long int) handle;
  idx = (guint32) handle.5;
  if (idx > 4194303) goto <D.10256>; else goto <D.10257>;
  <D.10256>:
  D.10258 = 0;
  return D.10258;
  <D.10257>:
  D.10261 = _wapi_handle_type (handle);
  if (D.10261 == 9) goto <D.10259>; else goto <D.10262>;
  <D.10262>:
  D.10263 = _wapi_handle_type (handle);
  if (D.10263 == 11) goto <D.10259>; else goto <D.10264>;
  <D.10264>:
  D.10265 = _wapi_handle_type (handle);
  if (D.10265 == 12) goto <D.10259>; else goto <D.10266>;
  <D.10266>:
  D.10267 = _wapi_handle_type (handle);
  if (D.10267 == 13) goto <D.10259>; else goto <D.10260>;
  <D.10259>:
  _wapi_handle_unref (handle);
  D.10258 = 0;
  return D.10258;
  <D.10260>:
  D.10268 = idx / 256;
  D.10269 = _wapi_private_handles[D.10268];
  D.10270 = (long unsigned int) idx;
  D.10271 = D.10270 & 255;
  D.10272 = D.10271 * 200;
  D.10273 = D.10269 + D.10272;
  D.10274 = &D.10273->signal_mutex;
  ret = pthread_mutex_unlock (D.10274);
  _wapi_handle_unref (handle);
  D.10258 = ret;
  return D.10258;
}


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

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


SignalObjectAndWait (void * signal_handle, void * wait, guint32 timeout, gboolean alertable)
{
  long unsigned int D.10278;
  guint32 D.10281;
  long int signal_handle.6;
  signed int D.10291;
  long int wait.7;
  signed int D.10295;
  int D.10298;
  int D.10301;
  int D.10304;
  long int D.10307;
  long int D.10308;
  _Bool D.10311;
  long int D.10312;
  long int D.10313;
  int D.10316;
  int D.10319;
  int D.10324;
  int D.10327;
  int D.10332;
  int D.10337;
  int D.10339;
  int D.10346;
  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.10278 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.10278);
      if (current_thread == 0B) goto <D.10279>; else goto <D.10280>;
      <D.10279>:
      SetLastError (6);
      D.10281 = 4294967295;
      return D.10281;
      <D.10280>:
      if (signal_handle == 4294967294B) goto <D.10282>; else goto <D.10283>;
      <D.10282>:
      D.10278 = pthread_self ();
      signal_handle = _wapi_thread_handle_from_id (D.10278);
      if (signal_handle == 0B) goto <D.10284>; else goto <D.10285>;
      <D.10284>:
      SetLastError (6);
      D.10281 = 4294967295;
      return D.10281;
      <D.10285>:
      <D.10283>:
      if (wait == 4294967294B) goto <D.10286>; else goto <D.10287>;
      <D.10286>:
      D.10278 = pthread_self ();
      wait = _wapi_thread_handle_from_id (D.10278);
      if (wait == 0B) goto <D.10288>; else goto <D.10289>;
      <D.10288>:
      SetLastError (6);
      D.10281 = 4294967295;
      return D.10281;
      <D.10289>:
      <D.10287>:
      signal_handle.6 = (long int) signal_handle;
      D.10291 = (signed int) signal_handle.6;
      if (D.10291 < 0) goto <D.10292>; else goto <D.10293>;
      <D.10292>:
      SetLastError (6);
      D.10281 = 4294967295;
      return D.10281;
      <D.10293>:
      wait.7 = (long int) wait;
      D.10295 = (signed int) wait.7;
      if (D.10295 < 0) goto <D.10296>; else goto <D.10297>;
      <D.10296>:
      SetLastError (6);
      D.10281 = 4294967295;
      return D.10281;
      <D.10297>:
      D.10298 = _wapi_handle_test_capabilities (signal_handle, 2);
      if (D.10298 == 0) goto <D.10299>; else goto <D.10300>;
      <D.10299>:
      D.10281 = 4294967295;
      return D.10281;
      <D.10300>:
      D.10301 = _wapi_handle_test_capabilities (wait, 1);
      if (D.10301 == 0) goto <D.10302>; else goto <D.10303>;
      <D.10302>:
      D.10281 = 4294967295;
      return D.10281;
      <D.10303>:
      _wapi_handle_ops_prewait (wait);
      D.10304 = _wapi_handle_test_capabilities (wait, 8);
      if (D.10304 == 1) goto <D.10305>; else goto <D.10306>;
      <D.10305>:
      monoeg_g_log (0B, 16, "%s: handle %p has special wait, implement me!!", &__func__, wait);
      D.10281 = 4294967295;
      return D.10281;
      <D.10306>:
      {
        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.10307 = (long int) __not_first_call;
            D.10308 = __builtin_expect (D.10307, 0);
            if (D.10308 != 0) goto <D.10309>; else goto <D.10310>;
            <D.10309>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10310>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (wait);
            D.10311 = thr_ret != 0;
            D.10312 = (long int) D.10311;
            D.10313 = __builtin_expect (D.10312, 0);
            if (D.10313 != 0) goto <D.10314>; else goto <D.10315>;
            <D.10314>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 349, "thr_ret == 0");
            <D.10315>:
            _wapi_handle_ops_signal (signal_handle);
            D.10316 = _wapi_handle_test_capabilities (wait, 4);
            if (D.10316 == 1) goto <D.10317>; else goto <D.10318>;
            <D.10317>:
            D.10319 = own_if_owned (wait);
            if (D.10319 != 0) goto <D.10320>; else goto <D.10321>;
            <D.10320>:
            ret = 0;
            goto done;
            <D.10321>:
            <D.10318>:
            if (alertable != 0) goto <D.10322>; else goto <D.10323>;
            <D.10322>:
            D.10324 = _wapi_thread_apc_pending (current_thread);
            if (D.10324 != 0) goto <D.10325>; else goto <D.10326>;
            <D.10325>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.10326>:
            <D.10323>:
            D.10327 = own_if_signalled (wait);
            if (D.10327 != 0) goto <D.10328>; else goto <D.10329>;
            <D.10328>:
            ret = 0;
            goto done;
            <D.10329>:
            if (timeout != 4294967295) goto <D.10330>; else goto <D.10331>;
            <D.10330>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.10331>:
            <D.9951>:
            _wapi_handle_ops_prewait (wait);
            D.10332 = own_if_signalled (wait);
            if (D.10332 != 0) goto <D.10333>; else goto <D.10334>;
            <D.10333>:
            ret = 0;
            goto done;
            <D.10334>:
            if (timeout == 4294967295) goto <D.10335>; else goto <D.10336>;
            <D.10335>:
            D.10337 = _wapi_handle_wait_signal_handle (wait, alertable);
            waited = (guint32) D.10337;
            goto <D.10338>;
            <D.10336>:
            D.10339 = _wapi_handle_timedwait_signal_handle (wait, &abstime, alertable, 0);
            waited = (guint32) D.10339;
            <D.10338>:
            if (alertable != 0) goto <D.10340>; else goto <D.10341>;
            <D.10340>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.10341>:
            if (waited == 0) goto <D.10342>; else goto <D.10343>;
            <D.10342>:
            if (apc_pending == 0) goto <D.10344>; else goto <D.10345>;
            <D.10344>:
            D.10346 = own_if_signalled (wait);
            if (D.10346 != 0) goto <D.10347>; else goto <D.10348>;
            <D.10347>:
            ret = 0;
            goto done;
            <D.10348>:
            <D.10345>:
            <D.10343>:
            if (waited == 0) goto <D.10349>; else goto <D.9952>;
            <D.10349>:
            if (apc_pending == 0) goto <D.9951>; else goto <D.9952>;
            <D.9952>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (wait);
            D.10311 = thr_ret != 0;
            D.10312 = (long int) D.10311;
            D.10313 = __builtin_expect (D.10312, 0);
            if (D.10313 != 0) goto <D.10350>; else goto <D.10351>;
            <D.10350>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 430, "thr_ret == 0");
            <D.10351>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.10352>; else goto <D.10353>;
            <D.10352>:
            __cancel_routine (__cancel_arg);
            <D.10353>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (apc_pending != 0) goto <D.10354>; else goto <D.10355>;
      <D.10354>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.10355>:
      D.10281 = ret;
      return D.10281;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


WaitForMultipleObjectsEx (guint32 numobjects, void * * handles, gboolean waitall, guint32 timeout, gboolean alertable)
{
  long unsigned int D.10375;
  guint32 D.10378;
  void * D.10383;
  long unsigned int D.10384;
  long unsigned int D.10385;
  void * * D.10386;
  void * D.10387;
  void * D.10390;
  long int D.10393;
  signed int D.10394;
  int D.10397;
  long unsigned int D.10400;
  unsigned int D.10401;
  void * D.10402;
  void * D.10403;
  <unnamed type> D.10412;
  <unnamed type> D.10414;
  <unnamed type> D.10416;
  <unnamed type> D.10418;
  <unnamed type> D.10420;
  int D.10429;
  int D.10432;
  int D.10435;
  long int D.10438;
  long int D.10439;
  _Bool D.10442;
  long int D.10443;
  long int D.10444;
  int D.10449;
  int D.10453;
  int D.10460;
  int D.10462;
  int D.10470;
  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.10375 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.10375);
      if (current_thread == 0B) goto <D.10376>; else goto <D.10377>;
      <D.10376>:
      SetLastError (6);
      D.10378 = 4294967295;
      return D.10378;
      <D.10377>:
      if (numobjects > 64) goto <D.10379>; else goto <D.10380>;
      <D.10379>:
      D.10378 = 4294967295;
      return D.10378;
      <D.10380>:
      if (numobjects == 1) goto <D.10381>; else goto <D.10382>;
      <D.10381>:
      D.10383 = *handles;
      D.10378 = WaitForSingleObjectEx (D.10383, timeout, alertable);
      return D.10378;
      <D.10382>:
      i = 0;
      goto <D.10000>;
      <D.9999>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      if (D.10387 == 4294967294B) goto <D.10388>; else goto <D.10389>;
      <D.10388>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10375 = pthread_self ();
      D.10390 = _wapi_thread_handle_from_id (D.10375);
      *D.10386 = D.10390;
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      if (D.10387 == 0B) goto <D.10391>; else goto <D.10392>;
      <D.10391>:
      bogustype = 1;
      goto <D.9998>;
      <D.10392>:
      <D.10389>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10393 = (long int) D.10387;
      D.10394 = (signed int) D.10393;
      if (D.10394 < 0) goto <D.10395>; else goto <D.10396>;
      <D.10395>:
      bogustype = 1;
      goto <D.9998>;
      <D.10396>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10397 = _wapi_handle_test_capabilities (D.10387, 1);
      if (D.10397 == 0) goto <D.10398>; else goto <D.10399>;
      <D.10398>:
      bogustype = 1;
      goto <D.9998>;
      <D.10399>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      sorted_handles[i] = D.10387;
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      _wapi_handle_ops_prewait (D.10387);
      i = i + 1;
      <D.10000>:
      if (i < numobjects) goto <D.9999>; else goto <D.9998>;
      <D.9998>:
      D.10400 = (long unsigned int) numobjects;
      qsort (&sorted_handles, D.10400, 8, monoeg_g_direct_equal);
      i = 1;
      goto <D.10003>;
      <D.10002>:
      D.10401 = i + 4294967295;
      D.10402 = sorted_handles[D.10401];
      D.10403 = sorted_handles[i];
      if (D.10402 == D.10403) goto <D.10404>; else goto <D.10405>;
      <D.10404>:
      duplicate = 1;
      goto <D.10001>;
      <D.10405>:
      i = i + 1;
      <D.10003>:
      if (i < numobjects) goto <D.10002>; else goto <D.10001>;
      <D.10001>:
      if (duplicate == 1) goto <D.10406>; else goto <D.10407>;
      <D.10406>:
      D.10378 = 4294967295;
      return D.10378;
      <D.10407>:
      if (bogustype == 1) goto <D.10408>; else goto <D.10409>;
      <D.10408>:
      D.10378 = 4294967295;
      return D.10378;
      <D.10409>:
      poll = 0;
      i = 0;
      goto <D.10005>;
      <D.10004>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10412 = _wapi_handle_type (D.10387);
      if (D.10412 == 9) goto <D.10410>; else goto <D.10413>;
      <D.10413>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10414 = _wapi_handle_type (D.10387);
      if (D.10414 == 9) goto <D.10410>; else goto <D.10415>;
      <D.10415>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10416 = _wapi_handle_type (D.10387);
      if (D.10416 == 11) goto <D.10410>; else goto <D.10417>;
      <D.10417>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10418 = _wapi_handle_type (D.10387);
      if (D.10418 == 12) goto <D.10410>; else goto <D.10419>;
      <D.10419>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10420 = _wapi_handle_type (D.10387);
      if (D.10420 == 13) goto <D.10410>; else goto <D.10411>;
      <D.10410>:
      poll = 1;
      <D.10411>:
      i = i + 1;
      <D.10005>:
      if (i < numobjects) goto <D.10004>; else goto <D.10006>;
      <D.10006>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.10421>; else goto <D.10422>;
      <D.10421>:
      D.10378 = lowest;
      return D.10378;
      <D.10422>:
      if (timeout == 0) goto <D.10423>; else goto <D.10424>;
      <D.10423>:
      D.10378 = 258;
      return D.10378;
      <D.10424>:
      if (timeout != 4294967295) goto <D.10425>; else goto <D.10426>;
      <D.10425>:
      _wapi_calc_timeout (&abstime, timeout);
      <D.10426>:
      if (alertable != 0) goto <D.10427>; else goto <D.10428>;
      <D.10427>:
      D.10429 = _wapi_thread_apc_pending (current_thread);
      if (D.10429 != 0) goto <D.10430>; else goto <D.10431>;
      <D.10430>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.10378 = 192;
      return D.10378;
      <D.10431>:
      <D.10428>:
      i = 0;
      goto <D.10008>;
      <D.10007>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      _wapi_handle_ref (D.10387);
      i = i + 1;
      <D.10008>:
      if (i < numobjects) goto <D.10007>; else goto <D.10009>;
      <D.10009>:
      <D.10026>:
      i = 0;
      goto <D.10011>;
      <D.10010>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      _wapi_handle_ops_prewait (D.10387);
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10432 = _wapi_handle_test_capabilities (D.10387, 8);
      if (D.10432 == 1) goto <D.10433>; else goto <D.10434>;
      <D.10433>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      D.10435 = _wapi_handle_issignalled (D.10387);
      if (D.10435 == 0) goto <D.10436>; else goto <D.10437>;
      <D.10436>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      _wapi_handle_ops_special_wait (D.10387, 0, alertable);
      <D.10437>:
      <D.10434>:
      i = i + 1;
      <D.10011>:
      if (i < numobjects) goto <D.10010>; else goto <D.10012>;
      <D.10012>:
      {
        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.10438 = (long int) __not_first_call;
            D.10439 = __builtin_expect (D.10438, 0);
            if (D.10439 != 0) goto <D.10440>; else goto <D.10441>;
            <D.10440>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10441>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_signal_mutex ();
            D.10442 = thr_ret != 0;
            D.10443 = (long int) D.10442;
            D.10444 = __builtin_expect (D.10443, 0);
            if (D.10444 != 0) goto <D.10445>; else goto <D.10446>;
            <D.10445>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 650, "thr_ret == 0");
            <D.10446>:
            if (waitall != 0) goto <D.10447>; else goto <D.10448>;
            <D.10447>:
            done = 1;
            i = 0;
            goto <D.10020>;
            <D.10019>:
            D.10384 = (long unsigned int) i;
            D.10385 = D.10384 * 8;
            D.10386 = handles + D.10385;
            D.10387 = *D.10386;
            D.10449 = _wapi_handle_issignalled (D.10387);
            if (D.10449 == 0) goto <D.10450>; else goto <D.10451>;
            <D.10450>:
            done = 0;
            <D.10451>:
            i = i + 1;
            <D.10020>:
            if (i < numobjects) goto <D.10019>; else goto <D.10021>;
            <D.10021>:
            goto <D.10452>;
            <D.10448>:
            done = 0;
            i = 0;
            goto <D.10023>;
            <D.10022>:
            D.10384 = (long unsigned int) i;
            D.10385 = D.10384 * 8;
            D.10386 = handles + D.10385;
            D.10387 = *D.10386;
            D.10453 = _wapi_handle_issignalled (D.10387);
            if (D.10453 != 0) goto <D.10454>; else goto <D.10455>;
            <D.10454>:
            done = 1;
            <D.10455>:
            i = i + 1;
            <D.10023>:
            if (i < numobjects) goto <D.10022>; else goto <D.10024>;
            <D.10024>:
            <D.10452>:
            if (done == 0) goto <D.10456>; else goto <D.10457>;
            <D.10456>:
            if (timeout == 4294967295) goto <D.10458>; else goto <D.10459>;
            <D.10458>:
            D.10460 = _wapi_handle_wait_signal (poll);
            ret = (guint32) D.10460;
            goto <D.10461>;
            <D.10459>:
            D.10462 = _wapi_handle_timedwait_signal (&abstime, poll);
            ret = (guint32) D.10462;
            <D.10461>:
            goto <D.10463>;
            <D.10457>:
            ret = 0;
            <D.10463>:
            thr_ret = _wapi_handle_unlock_signal_mutex (0B);
            D.10442 = thr_ret != 0;
            D.10443 = (long int) D.10442;
            D.10444 = __builtin_expect (D.10443, 0);
            if (D.10444 != 0) goto <D.10464>; else goto <D.10465>;
            <D.10464>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 680, "thr_ret == 0");
            <D.10465>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.10466>; else goto <D.10467>;
            <D.10466>:
            __cancel_routine (__cancel_arg);
            <D.10467>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (alertable != 0) goto <D.10468>; else goto <D.10469>;
      <D.10468>:
      D.10470 = _wapi_thread_apc_pending (current_thread);
      if (D.10470 != 0) goto <D.10471>; else goto <D.10472>;
      <D.10471>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      retval = 192;
      goto <D.10025>;
      <D.10472>:
      <D.10469>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.10473>; else goto <D.10474>;
      <D.10473>:
      retval = lowest;
      goto <D.10025>;
      <D.10474>:
      if (ret != 0) goto <D.10475>; else goto <D.10476>;
      <D.10475>:
      if (ret == 110) goto <D.10477>; else goto <D.10478>;
      <D.10477>:
      retval = 258;
      goto <D.10479>;
      <D.10478>:
      retval = 4294967295;
      <D.10479>:
      goto <D.10025>;
      <D.10476>:
      goto <D.10026>;
      <D.10025>:
      i = 0;
      goto <D.10028>;
      <D.10027>:
      D.10384 = (long unsigned int) i;
      D.10385 = D.10384 * 8;
      D.10386 = handles + D.10385;
      D.10387 = *D.10386;
      _wapi_handle_unref (D.10387);
      i = i + 1;
      <D.10028>:
      if (i < numobjects) goto <D.10027>; else goto <D.10029>;
      <D.10029>:
      D.10378 = retval;
      return D.10378;
    }
  finally
    {
      count = {CLOBBER};
      lowest = {CLOBBER};
      abstime = {CLOBBER};
      sorted_handles = {CLOBBER};
    }
}


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

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


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

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


test_and_own (guint32 numobjects, void * * handles, gboolean waitall, guint32 * count, guint32 * lowest)
{
  long int D.10509;
  long int D.10510;
  long unsigned int D.10517;
  long unsigned int D.10518;
  void * * D.10519;
  void * D.10520;
  unsigned int i.10;
  unsigned int D.10523;
  long unsigned int D.10524;
  long unsigned int D.10525;
  void * * D.10526;
  void * D.10527;
  gboolean D.10530;
  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.10509 = (long int) __not_first_call;
            D.10510 = __builtin_expect (D.10509, 0);
            if (D.10510 != 0) goto <D.10511>; else goto <D.10512>;
            <D.10511>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10512>:
            __pthread_register_cancel (&__cancel_buf);
            done = _wapi_handle_count_signalled_handles (numobjects, handles, waitall, count, lowest);
            if (done == 1) goto <D.10513>; else goto <D.10514>;
            <D.10513>:
            if (waitall == 1) goto <D.10515>; else goto <D.10516>;
            <D.10515>:
            i = 0;
            goto <D.9976>;
            <D.9975>:
            D.10517 = (long unsigned int) i;
            D.10518 = D.10517 * 8;
            D.10519 = handles + D.10518;
            D.10520 = *D.10519;
            own_if_signalled (D.10520);
            i = i + 1;
            <D.9976>:
            i.10 = (unsigned int) i;
            if (i.10 < numobjects) goto <D.9975>; else goto <D.9977>;
            <D.9977>:
            goto <D.10522>;
            <D.10516>:
            D.10523 = *lowest;
            D.10524 = (long unsigned int) D.10523;
            D.10525 = D.10524 * 8;
            D.10526 = handles + D.10525;
            D.10527 = *D.10526;
            own_if_signalled (D.10527);
            <D.10522>:
            <D.10514>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (1 != 0) goto <D.10528>; else goto <D.10529>;
            <D.10528>:
            __cancel_routine (__cancel_arg);
            <D.10529>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.10530 = done;
      return D.10530;
    }
  finally
    {
      cleanup_data = {CLOBBER};
    }
}


handle_cleanup (void * data)
{
  unsigned int D.10534;
  void * * D.10535;
  struct handle_cleanup_data * handles;

  handles = data;
  D.10534 = handles->numobjects;
  D.10535 = handles->handles;
  _wapi_handle_unlock_handles (D.10534, D.10535);
}


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

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


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

  D.10538 = 258;
  return D.10538;
}


