WaitForSingleObjectEx (void * handle, guint32 timeout, gboolean alertable)
{
  long unsigned int D.11798;
  guint32 D.11801;
  signed int handle.0;
  int D.11809;
  int D.11812;
  int D.11817;
  long int D.11820;
  _Bool D.11823;
  long int D.11824;
  long int D.11825;
  int D.11828;
  int D.11831;
  int D.11836;
  int D.11839;
  int D.11846;
  int D.11851;
  int D.11853;
  _Bool D.11856;
  _Bool D.11857;
  _Bool D.11858;
  int D.11861;
  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.11798 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.11798);
      if (current_thread == 0B) goto <D.11799>; else goto <D.11800>;
      <D.11799>:
      SetLastError (6);
      D.11801 = 4294967295;
      return D.11801;
      <D.11800>:
      if (handle == 4294967294B) goto <D.11802>; else goto <D.11803>;
      <D.11802>:
      D.11798 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.11798);
      if (handle == 0B) goto <D.11804>; else goto <D.11805>;
      <D.11804>:
      SetLastError (6);
      D.11801 = 4294967295;
      return D.11801;
      <D.11805>:
      <D.11803>:
      handle.0 = (signed int) handle;
      if (handle.0 < 0) goto <D.11807>; else goto <D.11808>;
      <D.11807>:
      SetLastError (6);
      D.11801 = 4294967295;
      return D.11801;
      <D.11808>:
      D.11809 = _wapi_handle_test_capabilities (handle, 1);
      if (D.11809 == 0) goto <D.11810>; else goto <D.11811>;
      <D.11810>:
      D.11801 = 4294967295;
      return D.11801;
      <D.11811>:
      _wapi_handle_ops_prewait (handle);
      D.11812 = _wapi_handle_test_capabilities (handle, 8);
      if (D.11812 == 1) goto <D.11813>; else goto <D.11814>;
      <D.11813>:
      ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
      if (alertable != 0) goto <D.11815>; else goto <D.11816>;
      <D.11815>:
      D.11817 = _wapi_thread_apc_pending (current_thread);
      if (D.11817 != 0) goto <D.11818>; else goto <D.11819>;
      <D.11818>:
      apc_pending = 1;
      ret = 192;
      <D.11819>:
      <D.11816>:
      goto check_pending;
      <D.11814>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc1>) (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.11820 = __builtin_expect (__not_first_call, 0);
            if (D.11820 != 0) goto <D.11821>; else goto <D.11822>;
            <D.11821>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.11822>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.11823 = thr_ret != 0;
            D.11824 = (long int) D.11823;
            D.11825 = __builtin_expect (D.11824, 0);
            if (D.11825 != 0) goto <D.11826>; else goto <D.11827>;
            <D.11826>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 147, "thr_ret == 0");
            <D.11827>:
            D.11828 = _wapi_handle_test_capabilities (handle, 4);
            if (D.11828 == 1) goto <D.11829>; else goto <D.11830>;
            <D.11829>:
            D.11831 = own_if_owned (handle);
            if (D.11831 == 1) goto <D.11832>; else goto <D.11833>;
            <D.11832>:
            ret = 0;
            goto done;
            <D.11833>:
            <D.11830>:
            if (alertable != 0) goto <D.11834>; else goto <D.11835>;
            <D.11834>:
            D.11836 = _wapi_thread_apc_pending (current_thread);
            if (D.11836 != 0) goto <D.11837>; else goto <D.11838>;
            <D.11837>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.11838>:
            <D.11835>:
            D.11839 = own_if_signalled (handle);
            if (D.11839 == 1) goto <D.11840>; else goto <D.11841>;
            <D.11840>:
            ret = 0;
            goto done;
            <D.11841>:
            if (timeout == 0) goto <D.11842>; else goto <D.11843>;
            <D.11842>:
            ret = 258;
            goto done;
            <D.11843>:
            if (timeout != 4294967295) goto <D.11844>; else goto <D.11845>;
            <D.11844>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.11845>:
            <D.11680>:
            _wapi_handle_ops_prewait (handle);
            D.11846 = own_if_signalled (handle);
            if (D.11846 != 0) goto <D.11847>; else goto <D.11848>;
            <D.11847>:
            ret = 0;
            goto done;
            <D.11848>:
            if (timeout == 4294967295) goto <D.11849>; else goto <D.11850>;
            <D.11849>:
            D.11851 = _wapi_handle_wait_signal_handle (handle, alertable);
            waited = (guint32) D.11851;
            goto <D.11852>;
            <D.11850>:
            D.11853 = _wapi_handle_timedwait_signal_handle (handle, &abstime, alertable, 0);
            waited = (guint32) D.11853;
            <D.11852>:
            if (alertable != 0) goto <D.11854>; else goto <D.11855>;
            <D.11854>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.11855>:
            D.11856 = waited == 0;
            D.11857 = apc_pending == 0;
            D.11858 = D.11856 & D.11857;
            if (D.11858 != 0) goto <D.11859>; else goto <D.11860>;
            <D.11859>:
            D.11861 = own_if_signalled (handle);
            if (D.11861 != 0) goto <D.11862>; else goto <D.11863>;
            <D.11862>:
            ret = 0;
            goto done;
            <D.11863>:
            <D.11860>:
            D.11856 = waited == 0;
            D.11857 = apc_pending == 0;
            D.11858 = D.11856 & D.11857;
            if (D.11858 != 0) goto <D.11680>; else goto <D.11681>;
            <D.11681>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.11823 = thr_ret != 0;
            D.11824 = (long int) D.11823;
            D.11825 = __builtin_expect (D.11824, 0);
            if (D.11825 != 0) goto <D.11864>; else goto <D.11865>;
            <D.11864>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 232, "thr_ret == 0");
            <D.11865>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.11866>; else goto <D.11867>;
            <D.11866>:
            __cancel_routine (__cancel_arg);
            <D.11867>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      check_pending:
      if (apc_pending != 0) goto <D.11868>; else goto <D.11869>;
      <D.11868>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.11869>:
      D.11801 = ret;
      return D.11801;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  int D.11891;
  <unnamed type> D.11894;
  <unnamed type> D.11896;
  <unnamed type> D.11898;
  <unnamed type> D.11900;
  unsigned int D.11901;
  struct _WapiHandleUnshared * D.11902;
  unsigned int D.11903;
  unsigned int D.11904;
  struct _WapiHandleUnshared * D.11905;
  union mono_mutex_t * D.11906;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11889>; else goto <D.11890>;
  <D.11889>:
  D.11891 = 0;
  return D.11891;
  <D.11890>:
  _wapi_handle_ref (handle);
  D.11894 = _wapi_handle_type (handle);
  if (D.11894 == 9) goto <D.11892>; else goto <D.11895>;
  <D.11895>:
  D.11896 = _wapi_handle_type (handle);
  if (D.11896 == 11) goto <D.11892>; else goto <D.11897>;
  <D.11897>:
  D.11898 = _wapi_handle_type (handle);
  if (D.11898 == 12) goto <D.11892>; else goto <D.11899>;
  <D.11899>:
  D.11900 = _wapi_handle_type (handle);
  if (D.11900 == 13) goto <D.11892>; else goto <D.11893>;
  <D.11892>:
  D.11891 = 0;
  return D.11891;
  <D.11893>:
  D.11901 = idx / 256;
  D.11902 = _wapi_private_handles[D.11901];
  D.11903 = idx & 255;
  D.11904 = D.11903 * 144;
  D.11905 = D.11902 + D.11904;
  D.11906 = &D.11905->signal_mutex;
  D.11891 = pthread_mutex_lock (D.11906);
  return D.11891;
}


_wapi_handle_type (void * handle)
{
  unsigned int D.11911;
  struct _WapiHandleUnshared * D.11912;
  WapiHandleType D.11913;
  unsigned int D.11914;
  unsigned int D.11915;
  struct _WapiHandleUnshared * D.11916;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11908>; else goto <D.11910>;
  <D.11910>:
  D.11911 = idx / 256;
  D.11912 = _wapi_private_handles[D.11911];
  if (D.11912 == 0B) goto <D.11908>; else goto <D.11909>;
  <D.11908>:
  D.11913 = 0;
  return D.11913;
  <D.11909>:
  D.11911 = idx / 256;
  D.11912 = _wapi_private_handles[D.11911];
  D.11914 = idx & 255;
  D.11915 = D.11914 * 144;
  D.11916 = D.11912 + D.11915;
  D.11913 = D.11916->type;
  return D.11913;
}


own_if_owned (void * handle)
{
  <unnamed type> D.11920;
  <unnamed type> D.11922;
  <unnamed type> D.11924;
  <unnamed type> D.11926;
  int D.11927;
  gboolean D.11930;
  int D.11931;
  <unnamed type> D.11936;
  <unnamed type> D.11938;
  <unnamed type> D.11940;
  <unnamed type> D.11942;
  gboolean ret;

  ret = 0;
  D.11920 = _wapi_handle_type (handle);
  if (D.11920 == 9) goto <D.11918>; else goto <D.11921>;
  <D.11921>:
  D.11922 = _wapi_handle_type (handle);
  if (D.11922 == 11) goto <D.11918>; else goto <D.11923>;
  <D.11923>:
  D.11924 = _wapi_handle_type (handle);
  if (D.11924 == 12) goto <D.11918>; else goto <D.11925>;
  <D.11925>:
  D.11926 = _wapi_handle_type (handle);
  if (D.11926 == 13) goto <D.11918>; else goto <D.11919>;
  <D.11918>:
  D.11927 = _wapi_handle_trylock_shared_handles ();
  if (D.11927 == 16) goto <D.11928>; else goto <D.11929>;
  <D.11928>:
  D.11930 = 0;
  return D.11930;
  <D.11929>:
  <D.11919>:
  D.11931 = _wapi_handle_ops_isowned (handle);
  if (D.11931 != 0) goto <D.11932>; else goto <D.11933>;
  <D.11932>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.11933>:
  D.11936 = _wapi_handle_type (handle);
  if (D.11936 == 9) goto <D.11934>; else goto <D.11937>;
  <D.11937>:
  D.11938 = _wapi_handle_type (handle);
  if (D.11938 == 11) goto <D.11934>; else goto <D.11939>;
  <D.11939>:
  D.11940 = _wapi_handle_type (handle);
  if (D.11940 == 12) goto <D.11934>; else goto <D.11941>;
  <D.11941>:
  D.11942 = _wapi_handle_type (handle);
  if (D.11942 == 13) goto <D.11934>; else goto <D.11935>;
  <D.11934>:
  _wapi_handle_unlock_shared_handles ();
  <D.11935>:
  D.11930 = ret;
  return D.11930;
}


_wapi_handle_trylock_shared_handles ()
{
  int D.11944;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.11946;

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


own_if_signalled (void * handle)
{
  <unnamed type> D.11950;
  <unnamed type> D.11952;
  <unnamed type> D.11954;
  <unnamed type> D.11956;
  int D.11957;
  gboolean D.11960;
  int D.11961;
  <unnamed type> D.11966;
  <unnamed type> D.11968;
  <unnamed type> D.11970;
  <unnamed type> D.11972;
  gboolean ret;

  ret = 0;
  D.11950 = _wapi_handle_type (handle);
  if (D.11950 == 9) goto <D.11948>; else goto <D.11951>;
  <D.11951>:
  D.11952 = _wapi_handle_type (handle);
  if (D.11952 == 11) goto <D.11948>; else goto <D.11953>;
  <D.11953>:
  D.11954 = _wapi_handle_type (handle);
  if (D.11954 == 12) goto <D.11948>; else goto <D.11955>;
  <D.11955>:
  D.11956 = _wapi_handle_type (handle);
  if (D.11956 == 13) goto <D.11948>; else goto <D.11949>;
  <D.11948>:
  D.11957 = _wapi_handle_trylock_shared_handles ();
  if (D.11957 == 16) goto <D.11958>; else goto <D.11959>;
  <D.11958>:
  D.11960 = 0;
  return D.11960;
  <D.11959>:
  <D.11949>:
  D.11961 = _wapi_handle_issignalled (handle);
  if (D.11961 != 0) goto <D.11962>; else goto <D.11963>;
  <D.11962>:
  _wapi_handle_ops_own (handle);
  ret = 1;
  <D.11963>:
  D.11966 = _wapi_handle_type (handle);
  if (D.11966 == 9) goto <D.11964>; else goto <D.11967>;
  <D.11967>:
  D.11968 = _wapi_handle_type (handle);
  if (D.11968 == 11) goto <D.11964>; else goto <D.11969>;
  <D.11969>:
  D.11970 = _wapi_handle_type (handle);
  if (D.11970 == 12) goto <D.11964>; else goto <D.11971>;
  <D.11971>:
  D.11972 = _wapi_handle_type (handle);
  if (D.11972 == 13) goto <D.11964>; else goto <D.11965>;
  <D.11964>:
  _wapi_handle_unlock_shared_handles ();
  <D.11965>:
  D.11960 = ret;
  return D.11960;
}


_wapi_handle_issignalled (void * handle)
{
  gboolean D.11976;
  <unnamed type> D.11979;
  <unnamed type> D.11981;
  <unnamed type> D.11983;
  <unnamed type> D.11985;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.1;
  unsigned int handle.2;
  unsigned int D.11988;
  struct _WapiHandleUnshared * D.11989;
  unsigned int D.11990;
  unsigned int D.11991;
  struct _WapiHandleUnshared * D.11992;
  unsigned int D.11993;
  unsigned int D.11994;
  struct _WapiHandleUnshared * D.11995;
  unsigned int D.11996;
  unsigned int D.11997;
  struct _WapiHandleUnshared * D.11998;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11974>; else goto <D.11975>;
  <D.11974>:
  D.11976 = 0;
  return D.11976;
  <D.11975>:
  D.11979 = _wapi_handle_type (handle);
  if (D.11979 == 9) goto <D.11977>; else goto <D.11980>;
  <D.11980>:
  D.11981 = _wapi_handle_type (handle);
  if (D.11981 == 11) goto <D.11977>; else goto <D.11982>;
  <D.11982>:
  D.11983 = _wapi_handle_type (handle);
  if (D.11983 == 12) goto <D.11977>; else goto <D.11984>;
  <D.11984>:
  D.11985 = _wapi_handle_type (handle);
  if (D.11985 == 13) goto <D.11977>; else goto <D.11978>;
  <D.11977>:
  _wapi_shared_layout.1 = _wapi_shared_layout;
  handle.2 = (unsigned int) handle;
  D.11988 = handle.2 / 256;
  D.11989 = _wapi_private_handles[D.11988];
  handle.2 = (unsigned int) handle;
  D.11990 = handle.2 & 255;
  D.11991 = D.11990 * 144;
  D.11992 = D.11989 + D.11991;
  D.11993 = D.11992->u.shared.offset;
  D.11976 = _wapi_shared_layout.1->handles[D.11993].signalled;
  return D.11976;
  <D.11978>:
  D.11994 = idx / 256;
  D.11995 = _wapi_private_handles[D.11994];
  D.11996 = idx & 255;
  D.11997 = D.11996 * 144;
  D.11998 = D.11995 + D.11997;
  D.11976 = D.11998->signalled;
  return D.11976;
}


_wapi_handle_unlock_handle (void * handle)
{
  int D.12002;
  <unnamed type> D.12005;
  <unnamed type> D.12007;
  <unnamed type> D.12009;
  <unnamed type> D.12011;
  unsigned int D.12012;
  struct _WapiHandleUnshared * D.12013;
  unsigned int D.12014;
  unsigned int D.12015;
  struct _WapiHandleUnshared * D.12016;
  union mono_mutex_t * D.12017;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.12000>; else goto <D.12001>;
  <D.12000>:
  D.12002 = 0;
  return D.12002;
  <D.12001>:
  D.12005 = _wapi_handle_type (handle);
  if (D.12005 == 9) goto <D.12003>; else goto <D.12006>;
  <D.12006>:
  D.12007 = _wapi_handle_type (handle);
  if (D.12007 == 11) goto <D.12003>; else goto <D.12008>;
  <D.12008>:
  D.12009 = _wapi_handle_type (handle);
  if (D.12009 == 12) goto <D.12003>; else goto <D.12010>;
  <D.12010>:
  D.12011 = _wapi_handle_type (handle);
  if (D.12011 == 13) goto <D.12003>; else goto <D.12004>;
  <D.12003>:
  _wapi_handle_unref (handle);
  D.12002 = 0;
  return D.12002;
  <D.12004>:
  D.12012 = idx / 256;
  D.12013 = _wapi_private_handles[D.12012];
  D.12014 = idx & 255;
  D.12015 = D.12014 * 144;
  D.12016 = D.12013 + D.12015;
  D.12017 = &D.12016->signal_mutex;
  ret = pthread_mutex_unlock (D.12017);
  _wapi_handle_unref (handle);
  D.12002 = ret;
  return D.12002;
}


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

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


SignalObjectAndWait (void * signal_handle, void * wait, guint32 timeout, gboolean alertable)
{
  long unsigned int D.12021;
  guint32 D.12024;
  signed int signal_handle.3;
  signed int wait.4;
  int D.12039;
  int D.12042;
  int D.12045;
  long int D.12048;
  _Bool D.12051;
  long int D.12052;
  long int D.12053;
  int D.12056;
  int D.12059;
  int D.12064;
  int D.12067;
  int D.12072;
  int D.12077;
  int D.12079;
  _Bool D.12082;
  _Bool D.12083;
  _Bool D.12084;
  int D.12087;
  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.12021 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.12021);
      if (current_thread == 0B) goto <D.12022>; else goto <D.12023>;
      <D.12022>:
      SetLastError (6);
      D.12024 = 4294967295;
      return D.12024;
      <D.12023>:
      if (signal_handle == 4294967294B) goto <D.12025>; else goto <D.12026>;
      <D.12025>:
      D.12021 = pthread_self ();
      signal_handle = _wapi_thread_handle_from_id (D.12021);
      if (signal_handle == 0B) goto <D.12027>; else goto <D.12028>;
      <D.12027>:
      SetLastError (6);
      D.12024 = 4294967295;
      return D.12024;
      <D.12028>:
      <D.12026>:
      if (wait == 4294967294B) goto <D.12029>; else goto <D.12030>;
      <D.12029>:
      D.12021 = pthread_self ();
      wait = _wapi_thread_handle_from_id (D.12021);
      if (wait == 0B) goto <D.12031>; else goto <D.12032>;
      <D.12031>:
      SetLastError (6);
      D.12024 = 4294967295;
      return D.12024;
      <D.12032>:
      <D.12030>:
      signal_handle.3 = (signed int) signal_handle;
      if (signal_handle.3 < 0) goto <D.12034>; else goto <D.12035>;
      <D.12034>:
      SetLastError (6);
      D.12024 = 4294967295;
      return D.12024;
      <D.12035>:
      wait.4 = (signed int) wait;
      if (wait.4 < 0) goto <D.12037>; else goto <D.12038>;
      <D.12037>:
      SetLastError (6);
      D.12024 = 4294967295;
      return D.12024;
      <D.12038>:
      D.12039 = _wapi_handle_test_capabilities (signal_handle, 2);
      if (D.12039 == 0) goto <D.12040>; else goto <D.12041>;
      <D.12040>:
      D.12024 = 4294967295;
      return D.12024;
      <D.12041>:
      D.12042 = _wapi_handle_test_capabilities (wait, 1);
      if (D.12042 == 0) goto <D.12043>; else goto <D.12044>;
      <D.12043>:
      D.12024 = 4294967295;
      return D.12024;
      <D.12044>:
      _wapi_handle_ops_prewait (wait);
      D.12045 = _wapi_handle_test_capabilities (wait, 8);
      if (D.12045 == 1) goto <D.12046>; else goto <D.12047>;
      <D.12046>:
      monoeg_g_log (0B, 16, "%s: handle %p has special wait, implement me!!", &__func__, wait);
      D.12024 = 4294967295;
      return D.12024;
      <D.12047>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc1>) (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.12048 = __builtin_expect (__not_first_call, 0);
            if (D.12048 != 0) goto <D.12049>; else goto <D.12050>;
            <D.12049>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.12050>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (wait);
            D.12051 = thr_ret != 0;
            D.12052 = (long int) D.12051;
            D.12053 = __builtin_expect (D.12052, 0);
            if (D.12053 != 0) goto <D.12054>; else goto <D.12055>;
            <D.12054>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 349, "thr_ret == 0");
            <D.12055>:
            _wapi_handle_ops_signal (signal_handle);
            D.12056 = _wapi_handle_test_capabilities (wait, 4);
            if (D.12056 == 1) goto <D.12057>; else goto <D.12058>;
            <D.12057>:
            D.12059 = own_if_owned (wait);
            if (D.12059 != 0) goto <D.12060>; else goto <D.12061>;
            <D.12060>:
            ret = 0;
            goto done;
            <D.12061>:
            <D.12058>:
            if (alertable != 0) goto <D.12062>; else goto <D.12063>;
            <D.12062>:
            D.12064 = _wapi_thread_apc_pending (current_thread);
            if (D.12064 != 0) goto <D.12065>; else goto <D.12066>;
            <D.12065>:
            apc_pending = 1;
            ret = 192;
            goto done;
            <D.12066>:
            <D.12063>:
            D.12067 = own_if_signalled (wait);
            if (D.12067 != 0) goto <D.12068>; else goto <D.12069>;
            <D.12068>:
            ret = 0;
            goto done;
            <D.12069>:
            if (timeout != 4294967295) goto <D.12070>; else goto <D.12071>;
            <D.12070>:
            _wapi_calc_timeout (&abstime, timeout);
            <D.12071>:
            <D.11706>:
            _wapi_handle_ops_prewait (wait);
            D.12072 = own_if_signalled (wait);
            if (D.12072 != 0) goto <D.12073>; else goto <D.12074>;
            <D.12073>:
            ret = 0;
            goto done;
            <D.12074>:
            if (timeout == 4294967295) goto <D.12075>; else goto <D.12076>;
            <D.12075>:
            D.12077 = _wapi_handle_wait_signal_handle (wait, alertable);
            waited = (guint32) D.12077;
            goto <D.12078>;
            <D.12076>:
            D.12079 = _wapi_handle_timedwait_signal_handle (wait, &abstime, alertable, 0);
            waited = (guint32) D.12079;
            <D.12078>:
            if (alertable != 0) goto <D.12080>; else goto <D.12081>;
            <D.12080>:
            apc_pending = _wapi_thread_apc_pending (current_thread);
            <D.12081>:
            D.12082 = waited == 0;
            D.12083 = apc_pending == 0;
            D.12084 = D.12082 & D.12083;
            if (D.12084 != 0) goto <D.12085>; else goto <D.12086>;
            <D.12085>:
            D.12087 = own_if_signalled (wait);
            if (D.12087 != 0) goto <D.12088>; else goto <D.12089>;
            <D.12088>:
            ret = 0;
            goto done;
            <D.12089>:
            <D.12086>:
            D.12082 = waited == 0;
            D.12083 = apc_pending == 0;
            D.12084 = D.12082 & D.12083;
            if (D.12084 != 0) goto <D.11706>; else goto <D.11707>;
            <D.11707>:
            ret = 258;
            done:
            thr_ret = _wapi_handle_unlock_handle (wait);
            D.12051 = thr_ret != 0;
            D.12052 = (long int) D.12051;
            D.12053 = __builtin_expect (D.12052, 0);
            if (D.12053 != 0) goto <D.12090>; else goto <D.12091>;
            <D.12090>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 430, "thr_ret == 0");
            <D.12091>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.12092>; else goto <D.12093>;
            <D.12092>:
            __cancel_routine (__cancel_arg);
            <D.12093>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (apc_pending != 0) goto <D.12094>; else goto <D.12095>;
      <D.12094>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      ret = 192;
      <D.12095>:
      D.12024 = ret;
      return D.12024;
    }
  finally
    {
      abstime = {CLOBBER};
    }
}


WaitForMultipleObjectsEx (guint32 numobjects, void * * handles, gboolean waitall, guint32 timeout, gboolean alertable)
{
  long unsigned int D.12115;
  guint32 D.12118;
  void * D.12123;
  unsigned int D.12124;
  void * * D.12125;
  void * D.12126;
  void * D.12129;
  signed int D.12132;
  int D.12135;
  unsigned int D.12138;
  void * D.12139;
  void * D.12140;
  <unnamed type> D.12149;
  <unnamed type> D.12151;
  <unnamed type> D.12153;
  <unnamed type> D.12155;
  <unnamed type> D.12157;
  int D.12166;
  int D.12169;
  int D.12172;
  long int D.12175;
  _Bool D.12178;
  long int D.12179;
  long int D.12180;
  int D.12185;
  int D.12189;
  int D.12196;
  int D.12198;
  int D.12206;
  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.12115 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.12115);
      if (current_thread == 0B) goto <D.12116>; else goto <D.12117>;
      <D.12116>:
      SetLastError (6);
      D.12118 = 4294967295;
      return D.12118;
      <D.12117>:
      if (numobjects > 64) goto <D.12119>; else goto <D.12120>;
      <D.12119>:
      D.12118 = 4294967295;
      return D.12118;
      <D.12120>:
      if (numobjects == 1) goto <D.12121>; else goto <D.12122>;
      <D.12121>:
      D.12123 = *handles;
      D.12118 = WaitForSingleObjectEx (D.12123, timeout, alertable);
      return D.12118;
      <D.12122>:
      i = 0;
      goto <D.11755>;
      <D.11754>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      if (D.12126 == 4294967294B) goto <D.12127>; else goto <D.12128>;
      <D.12127>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12115 = pthread_self ();
      D.12129 = _wapi_thread_handle_from_id (D.12115);
      *D.12125 = D.12129;
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      if (D.12126 == 0B) goto <D.12130>; else goto <D.12131>;
      <D.12130>:
      bogustype = 1;
      goto <D.11753>;
      <D.12131>:
      <D.12128>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12132 = (signed int) D.12126;
      if (D.12132 < 0) goto <D.12133>; else goto <D.12134>;
      <D.12133>:
      bogustype = 1;
      goto <D.11753>;
      <D.12134>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12135 = _wapi_handle_test_capabilities (D.12126, 1);
      if (D.12135 == 0) goto <D.12136>; else goto <D.12137>;
      <D.12136>:
      bogustype = 1;
      goto <D.11753>;
      <D.12137>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      sorted_handles[i] = D.12126;
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      _wapi_handle_ops_prewait (D.12126);
      i = i + 1;
      <D.11755>:
      if (i < numobjects) goto <D.11754>; else goto <D.11753>;
      <D.11753>:
      qsort (&sorted_handles, numobjects, 4, monoeg_g_direct_equal);
      i = 1;
      goto <D.11758>;
      <D.11757>:
      D.12138 = i + 4294967295;
      D.12139 = sorted_handles[D.12138];
      D.12140 = sorted_handles[i];
      if (D.12139 == D.12140) goto <D.12141>; else goto <D.12142>;
      <D.12141>:
      duplicate = 1;
      goto <D.11756>;
      <D.12142>:
      i = i + 1;
      <D.11758>:
      if (i < numobjects) goto <D.11757>; else goto <D.11756>;
      <D.11756>:
      if (duplicate == 1) goto <D.12143>; else goto <D.12144>;
      <D.12143>:
      D.12118 = 4294967295;
      return D.12118;
      <D.12144>:
      if (bogustype == 1) goto <D.12145>; else goto <D.12146>;
      <D.12145>:
      D.12118 = 4294967295;
      return D.12118;
      <D.12146>:
      poll = 0;
      i = 0;
      goto <D.11760>;
      <D.11759>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12149 = _wapi_handle_type (D.12126);
      if (D.12149 == 9) goto <D.12147>; else goto <D.12150>;
      <D.12150>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12151 = _wapi_handle_type (D.12126);
      if (D.12151 == 9) goto <D.12147>; else goto <D.12152>;
      <D.12152>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12153 = _wapi_handle_type (D.12126);
      if (D.12153 == 11) goto <D.12147>; else goto <D.12154>;
      <D.12154>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12155 = _wapi_handle_type (D.12126);
      if (D.12155 == 12) goto <D.12147>; else goto <D.12156>;
      <D.12156>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12157 = _wapi_handle_type (D.12126);
      if (D.12157 == 13) goto <D.12147>; else goto <D.12148>;
      <D.12147>:
      poll = 1;
      <D.12148>:
      i = i + 1;
      <D.11760>:
      if (i < numobjects) goto <D.11759>; else goto <D.11761>;
      <D.11761>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.12158>; else goto <D.12159>;
      <D.12158>:
      D.12118 = lowest;
      return D.12118;
      <D.12159>:
      if (timeout == 0) goto <D.12160>; else goto <D.12161>;
      <D.12160>:
      D.12118 = 258;
      return D.12118;
      <D.12161>:
      if (timeout != 4294967295) goto <D.12162>; else goto <D.12163>;
      <D.12162>:
      _wapi_calc_timeout (&abstime, timeout);
      <D.12163>:
      if (alertable != 0) goto <D.12164>; else goto <D.12165>;
      <D.12164>:
      D.12166 = _wapi_thread_apc_pending (current_thread);
      if (D.12166 != 0) goto <D.12167>; else goto <D.12168>;
      <D.12167>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.12118 = 192;
      return D.12118;
      <D.12168>:
      <D.12165>:
      i = 0;
      goto <D.11763>;
      <D.11762>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      _wapi_handle_ref (D.12126);
      i = i + 1;
      <D.11763>:
      if (i < numobjects) goto <D.11762>; else goto <D.11764>;
      <D.11764>:
      <D.11781>:
      i = 0;
      goto <D.11766>;
      <D.11765>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      _wapi_handle_ops_prewait (D.12126);
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12169 = _wapi_handle_test_capabilities (D.12126, 8);
      if (D.12169 == 1) goto <D.12170>; else goto <D.12171>;
      <D.12170>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      D.12172 = _wapi_handle_issignalled (D.12126);
      if (D.12172 == 0) goto <D.12173>; else goto <D.12174>;
      <D.12173>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      _wapi_handle_ops_special_wait (D.12126, 0, alertable);
      <D.12174>:
      <D.12171>:
      i = i + 1;
      <D.11766>:
      if (i < numobjects) goto <D.11765>; else goto <D.11767>;
      <D.11767>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc1>) (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.12175 = __builtin_expect (__not_first_call, 0);
            if (D.12175 != 0) goto <D.12176>; else goto <D.12177>;
            <D.12176>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.12177>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_signal_mutex ();
            D.12178 = thr_ret != 0;
            D.12179 = (long int) D.12178;
            D.12180 = __builtin_expect (D.12179, 0);
            if (D.12180 != 0) goto <D.12181>; else goto <D.12182>;
            <D.12181>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 650, "thr_ret == 0");
            <D.12182>:
            if (waitall != 0) goto <D.12183>; else goto <D.12184>;
            <D.12183>:
            done = 1;
            i = 0;
            goto <D.11775>;
            <D.11774>:
            D.12124 = i * 4;
            D.12125 = handles + D.12124;
            D.12126 = *D.12125;
            D.12185 = _wapi_handle_issignalled (D.12126);
            if (D.12185 == 0) goto <D.12186>; else goto <D.12187>;
            <D.12186>:
            done = 0;
            <D.12187>:
            i = i + 1;
            <D.11775>:
            if (i < numobjects) goto <D.11774>; else goto <D.11776>;
            <D.11776>:
            goto <D.12188>;
            <D.12184>:
            done = 0;
            i = 0;
            goto <D.11778>;
            <D.11777>:
            D.12124 = i * 4;
            D.12125 = handles + D.12124;
            D.12126 = *D.12125;
            D.12189 = _wapi_handle_issignalled (D.12126);
            if (D.12189 != 0) goto <D.12190>; else goto <D.12191>;
            <D.12190>:
            done = 1;
            <D.12191>:
            i = i + 1;
            <D.11778>:
            if (i < numobjects) goto <D.11777>; else goto <D.11779>;
            <D.11779>:
            <D.12188>:
            if (done == 0) goto <D.12192>; else goto <D.12193>;
            <D.12192>:
            if (timeout == 4294967295) goto <D.12194>; else goto <D.12195>;
            <D.12194>:
            D.12196 = _wapi_handle_wait_signal (poll);
            ret = (guint32) D.12196;
            goto <D.12197>;
            <D.12195>:
            D.12198 = _wapi_handle_timedwait_signal (&abstime, poll);
            ret = (guint32) D.12198;
            <D.12197>:
            goto <D.12199>;
            <D.12193>:
            ret = 0;
            <D.12199>:
            thr_ret = _wapi_handle_unlock_signal_mutex (0B);
            D.12178 = thr_ret != 0;
            D.12179 = (long int) D.12178;
            D.12180 = __builtin_expect (D.12179, 0);
            if (D.12180 != 0) goto <D.12200>; else goto <D.12201>;
            <D.12200>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wait.c", 680, "thr_ret == 0");
            <D.12201>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.12202>; else goto <D.12203>;
            <D.12202>:
            __cancel_routine (__cancel_arg);
            <D.12203>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      if (alertable != 0) goto <D.12204>; else goto <D.12205>;
      <D.12204>:
      D.12206 = _wapi_thread_apc_pending (current_thread);
      if (D.12206 != 0) goto <D.12207>; else goto <D.12208>;
      <D.12207>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      retval = 192;
      goto <D.11780>;
      <D.12208>:
      <D.12205>:
      done = test_and_own (numobjects, handles, waitall, &count, &lowest);
      if (done == 1) goto <D.12209>; else goto <D.12210>;
      <D.12209>:
      retval = lowest;
      goto <D.11780>;
      <D.12210>:
      if (ret != 0) goto <D.12211>; else goto <D.12212>;
      <D.12211>:
      if (ret == 110) goto <D.12213>; else goto <D.12214>;
      <D.12213>:
      retval = 258;
      goto <D.12215>;
      <D.12214>:
      retval = 4294967295;
      <D.12215>:
      goto <D.11780>;
      <D.12212>:
      goto <D.11781>;
      <D.11780>:
      i = 0;
      goto <D.11783>;
      <D.11782>:
      D.12124 = i * 4;
      D.12125 = handles + D.12124;
      D.12126 = *D.12125;
      _wapi_handle_unref (D.12126);
      i = i + 1;
      <D.11783>:
      if (i < numobjects) goto <D.11782>; else goto <D.11784>;
      <D.11784>:
      D.12118 = retval;
      return D.12118;
    }
  finally
    {
      count = {CLOBBER};
      lowest = {CLOBBER};
      abstime = {CLOBBER};
      sorted_handles = {CLOBBER};
    }
}


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

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


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

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


test_and_own (guint32 numobjects, void * * handles, gboolean waitall, guint32 * count, guint32 * lowest)
{
  long int D.12245;
  unsigned int i.7;
  unsigned int D.12253;
  void * * D.12254;
  void * D.12255;
  unsigned int i.8;
  unsigned int D.12258;
  unsigned int D.12259;
  void * * D.12260;
  void * D.12261;
  gboolean D.12264;
  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 (*<Tc1>) (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.12245 = __builtin_expect (__not_first_call, 0);
            if (D.12245 != 0) goto <D.12246>; else goto <D.12247>;
            <D.12246>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.12247>:
            __pthread_register_cancel (&__cancel_buf);
            done = _wapi_handle_count_signalled_handles (numobjects, handles, waitall, count, lowest);
            if (done == 1) goto <D.12248>; else goto <D.12249>;
            <D.12248>:
            if (waitall == 1) goto <D.12250>; else goto <D.12251>;
            <D.12250>:
            i = 0;
            goto <D.11731>;
            <D.11730>:
            i.7 = (unsigned int) i;
            D.12253 = i.7 * 4;
            D.12254 = handles + D.12253;
            D.12255 = *D.12254;
            own_if_signalled (D.12255);
            i = i + 1;
            <D.11731>:
            i.8 = (unsigned int) i;
            if (i.8 < numobjects) goto <D.11730>; else goto <D.11732>;
            <D.11732>:
            goto <D.12257>;
            <D.12251>:
            D.12258 = *lowest;
            D.12259 = D.12258 * 4;
            D.12260 = handles + D.12259;
            D.12261 = *D.12260;
            own_if_signalled (D.12261);
            <D.12257>:
            <D.12249>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (1 != 0) goto <D.12262>; else goto <D.12263>;
            <D.12262>:
            __cancel_routine (__cancel_arg);
            <D.12263>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.12264 = done;
      return D.12264;
    }
  finally
    {
      cleanup_data = {CLOBBER};
    }
}


handle_cleanup (void * data)
{
  unsigned int D.12268;
  void * * D.12269;
  struct handle_cleanup_data * handles;

  handles = data;
  D.12268 = handles->numobjects;
  D.12269 = handles->handles;
  _wapi_handle_unlock_handles (D.12268, D.12269);
}


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

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


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

  D.12272 = 258;
  return D.12272;
}


