_wapi_thread_cleanup ()
{
  unsigned int thread_hash_key.0;
  _Bool D.15524;
  long int D.15525;
  long int D.15526;
  unsigned int thread_attached_key.1;
  int ret;

  thread_hash_key.0 = thread_hash_key;
  ret = pthread_key_delete (thread_hash_key.0);
  D.15524 = ret != 0;
  D.15525 = (long int) D.15524;
  D.15526 = __builtin_expect (D.15525, 0);
  if (D.15526 != 0) goto <D.15527>; else goto <D.15528>;
  <D.15527>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 86, "ret == 0");
  <D.15528>:
  thread_attached_key.1 = thread_attached_key;
  ret = pthread_key_delete (thread_attached_key.1);
  D.15524 = ret != 0;
  D.15525 = (long int) D.15524;
  D.15526 = __builtin_expect (D.15525, 0);
  if (D.15526 != 0) goto <D.15530>; else goto <D.15531>;
  <D.15530>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 89, "ret == 0");
  <D.15531>:
}


_wapi_thread_set_termination_details (void * handle, guint32 exitstatus)
{
  int D.15534;
  <unnamed type> D.15536;
  long int D.15539;
  _Bool D.15542;
  long int D.15543;
  long int D.15544;
  struct _WapiHandle_thread * thread_handle.2;
  union MonoSemType * D.15548;
  struct GPtrArray * D.15549;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  int thr_ret;
  static const char __func__[37] = "_wapi_thread_set_termination_details";

  try
    {
      D.15534 = _wapi_handle_issignalled (handle);
      if (D.15534 != 0) goto <D.15532>; else goto <D.15535>;
      <D.15535>:
      D.15536 = _wapi_handle_type (handle);
      if (D.15536 == 0) goto <D.15532>; else goto <D.15533>;
      <D.15532>:
      return;
      <D.15533>:
      _wapi_thread_abandon_mutexes (handle);
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.15537>; else goto <D.15538>;
      <D.15537>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      return;
      <D.15538>:
      {
        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.15539 = __builtin_expect (__not_first_call, 0);
            if (D.15539 != 0) goto <D.15540>; else goto <D.15541>;
            <D.15540>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.15541>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.15542 = thr_ret != 0;
            D.15543 = (long int) D.15542;
            D.15544 = __builtin_expect (D.15543, 0);
            if (D.15544 != 0) goto <D.15545>; else goto <D.15546>;
            <D.15545>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 164, "thr_ret == 0");
            <D.15546>:
            thread_handle.2 = thread_handle;
            thread_handle.2->exitstatus = exitstatus;
            thread_handle.2 = thread_handle;
            thread_handle.2->state = 1;
            thread_handle.2 = thread_handle;
            D.15548 = &thread_handle.2->suspend_sem;
            sem_destroy (D.15548);
            thread_handle.2 = thread_handle;
            D.15549 = thread_handle.2->owned_mutexes;
            monoeg_g_ptr_array_free (D.15549, 1);
            _wapi_handle_set_signal_state (handle, 1, 1);
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.15542 = thr_ret != 0;
            D.15543 = (long int) D.15542;
            D.15544 = __builtin_expect (D.15543, 0);
            if (D.15544 != 0) goto <D.15550>; else goto <D.15551>;
            <D.15550>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 174, "thr_ret == 0");
            <D.15551>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.15552>; else goto <D.15553>;
            <D.15552>:
            __cancel_routine (__cancel_arg);
            <D.15553>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      _wapi_handle_unref (handle);
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


_wapi_handle_issignalled (void * handle)
{
  gboolean D.15564;
  <unnamed type> D.15567;
  <unnamed type> D.15569;
  <unnamed type> D.15571;
  <unnamed type> D.15573;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.3;
  unsigned int handle.4;
  unsigned int D.15576;
  struct _WapiHandleUnshared * D.15577;
  unsigned int D.15578;
  unsigned int D.15579;
  struct _WapiHandleUnshared * D.15580;
  unsigned int D.15581;
  unsigned int D.15582;
  struct _WapiHandleUnshared * D.15583;
  unsigned int D.15584;
  unsigned int D.15585;
  struct _WapiHandleUnshared * D.15586;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.15562>; else goto <D.15563>;
  <D.15562>:
  D.15564 = 0;
  return D.15564;
  <D.15563>:
  D.15567 = _wapi_handle_type (handle);
  if (D.15567 == 9) goto <D.15565>; else goto <D.15568>;
  <D.15568>:
  D.15569 = _wapi_handle_type (handle);
  if (D.15569 == 11) goto <D.15565>; else goto <D.15570>;
  <D.15570>:
  D.15571 = _wapi_handle_type (handle);
  if (D.15571 == 12) goto <D.15565>; else goto <D.15572>;
  <D.15572>:
  D.15573 = _wapi_handle_type (handle);
  if (D.15573 == 13) goto <D.15565>; else goto <D.15566>;
  <D.15565>:
  _wapi_shared_layout.3 = _wapi_shared_layout;
  handle.4 = (unsigned int) handle;
  D.15576 = handle.4 / 256;
  D.15577 = _wapi_private_handles[D.15576];
  handle.4 = (unsigned int) handle;
  D.15578 = handle.4 & 255;
  D.15579 = D.15578 * 144;
  D.15580 = D.15577 + D.15579;
  D.15581 = D.15580->u.shared.offset;
  D.15564 = _wapi_shared_layout.3->handles[D.15581].signalled;
  return D.15564;
  <D.15566>:
  D.15582 = idx / 256;
  D.15583 = _wapi_private_handles[D.15582];
  D.15584 = idx & 255;
  D.15585 = D.15584 * 144;
  D.15586 = D.15583 + D.15585;
  D.15564 = D.15586->signalled;
  return D.15564;
}


_wapi_handle_type (void * handle)
{
  unsigned int D.15591;
  struct _WapiHandleUnshared * D.15592;
  WapiHandleType D.15593;
  unsigned int D.15594;
  unsigned int D.15595;
  struct _WapiHandleUnshared * D.15596;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.15588>; else goto <D.15590>;
  <D.15590>:
  D.15591 = idx / 256;
  D.15592 = _wapi_private_handles[D.15591];
  if (D.15592 == 0B) goto <D.15588>; else goto <D.15589>;
  <D.15588>:
  D.15593 = 0;
  return D.15593;
  <D.15589>:
  D.15591 = idx / 256;
  D.15592 = _wapi_private_handles[D.15591];
  D.15594 = idx & 255;
  D.15595 = D.15594 * 144;
  D.15596 = D.15592 + D.15595;
  D.15593 = D.15596->type;
  return D.15593;
}


_wapi_thread_abandon_mutexes (void * handle)
{
  long unsigned int D.15600;
  struct _WapiHandle_thread * thread_handle.5;
  long unsigned int D.15606;
  int D.15607;
  struct GPtrArray * D.15610;
  void * * D.15611;
  unsigned int i.6;
  unsigned int D.15613;
  void * * D.15614;
  unsigned int i.7;
  unsigned int D.15616;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  int i;
  pid_t pid;
  pthread_t tid;
  static const char __func__[29] = "_wapi_thread_abandon_mutexes";

  try
    {
      pid = _wapi_getpid ();
      tid = pthread_self ();
      if (handle == 0B) goto <D.15598>; else goto <D.15599>;
      <D.15598>:
      D.15600 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.15600);
      if (handle == 0B) goto <D.15601>; else goto <D.15602>;
      <D.15601>:
      return;
      <D.15602>:
      <D.15599>:
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.15603>; else goto <D.15604>;
      <D.15603>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      return;
      <D.15604>:
      thread_handle.5 = thread_handle;
      D.15606 = thread_handle.5->id;
      D.15607 = pthread_equal (D.15606, tid);
      if (D.15607 == 0) goto <D.15608>; else goto <D.15609>;
      <D.15608>:
      return;
      <D.15609>:
      i = 0;
      goto <D.15256>;
      <D.15255>:
      {
        void * mutex;

        thread_handle.5 = thread_handle;
        D.15610 = thread_handle.5->owned_mutexes;
        D.15611 = D.15610->pdata;
        i.6 = (unsigned int) i;
        D.15613 = i.6 * 4;
        D.15614 = D.15611 + D.15613;
        mutex = *D.15614;
        _wapi_mutex_abandon (mutex, pid, tid);
        _wapi_thread_disown_mutex (mutex);
      }
      i = i + 1;
      <D.15256>:
      i.7 = (unsigned int) i;
      thread_handle.5 = thread_handle;
      D.15610 = thread_handle.5->owned_mutexes;
      D.15616 = D.15610->len;
      if (i.7 < D.15616) goto <D.15255>; else goto <D.15257>;
      <D.15257>:
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


pthread_equal (pthread_t __thread1, pthread_t __thread2)
{
  int D.15620;
  _Bool D.15621;

  D.15621 = __thread1 == __thread2;
  D.15620 = (int) D.15621;
  return D.15620;
}


_wapi_handle_lock_handle (void * handle)
{
  int D.15625;
  <unnamed type> D.15628;
  <unnamed type> D.15630;
  <unnamed type> D.15632;
  <unnamed type> D.15634;
  unsigned int D.15635;
  struct _WapiHandleUnshared * D.15636;
  unsigned int D.15637;
  unsigned int D.15638;
  struct _WapiHandleUnshared * D.15639;
  union mono_mutex_t * D.15640;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.15623>; else goto <D.15624>;
  <D.15623>:
  D.15625 = 0;
  return D.15625;
  <D.15624>:
  _wapi_handle_ref (handle);
  D.15628 = _wapi_handle_type (handle);
  if (D.15628 == 9) goto <D.15626>; else goto <D.15629>;
  <D.15629>:
  D.15630 = _wapi_handle_type (handle);
  if (D.15630 == 11) goto <D.15626>; else goto <D.15631>;
  <D.15631>:
  D.15632 = _wapi_handle_type (handle);
  if (D.15632 == 12) goto <D.15626>; else goto <D.15633>;
  <D.15633>:
  D.15634 = _wapi_handle_type (handle);
  if (D.15634 == 13) goto <D.15626>; else goto <D.15627>;
  <D.15626>:
  D.15625 = 0;
  return D.15625;
  <D.15627>:
  D.15635 = idx / 256;
  D.15636 = _wapi_private_handles[D.15635];
  D.15637 = idx & 255;
  D.15638 = D.15637 * 144;
  D.15639 = D.15636 + D.15638;
  D.15640 = &D.15639->signal_mutex;
  D.15625 = pthread_mutex_lock (D.15640);
  return D.15625;
}


_wapi_handle_set_signal_state (void * handle, gboolean state, gboolean broadcast)
{
  int iftmp.8;
  <unnamed type> D.15648;
  <unnamed type> D.15650;
  <unnamed type> D.15652;
  <unnamed type> D.15654;
  _Bool D.15655;
  long int D.15656;
  long int D.15657;
  unsigned int D.15660;
  struct _WapiHandleUnshared * D.15661;
  unsigned int D.15662;
  unsigned int D.15663;
  long int D.15666;
  union mono_mutex_t * _wapi_global_signal_mutex.9;
  _Bool D.15672;
  long int D.15673;
  long int D.15674;
  union pthread_cond_t * D.15679;
  union pthread_cond_t * _wapi_global_signal_cond.10;
  guint32 idx;
  struct _WapiHandleUnshared * handle_data;
  int thr_ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.15642>; else goto <D.15643>;
  <D.15642>:
  return;
  <D.15643>:
  D.15648 = _wapi_handle_type (handle);
  if (D.15648 == 9) goto <D.15645>; else goto <D.15649>;
  <D.15649>:
  D.15650 = _wapi_handle_type (handle);
  if (D.15650 == 11) goto <D.15645>; else goto <D.15651>;
  <D.15651>:
  D.15652 = _wapi_handle_type (handle);
  if (D.15652 == 12) goto <D.15645>; else goto <D.15653>;
  <D.15653>:
  D.15654 = _wapi_handle_type (handle);
  if (D.15654 == 13) goto <D.15645>; else goto <D.15646>;
  <D.15645>:
  iftmp.8 = 1;
  goto <D.15647>;
  <D.15646>:
  iftmp.8 = 0;
  <D.15647>:
  D.15655 = iftmp.8 != 0;
  D.15656 = (long int) D.15655;
  D.15657 = __builtin_expect (D.15656, 0);
  if (D.15657 != 0) goto <D.15658>; else goto <D.15659>;
  <D.15658>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 132, "!_WAPI_SHARED_HANDLE(_wapi_handle_type (handle))");
  <D.15659>:
  D.15660 = idx / 256;
  D.15661 = _wapi_private_handles[D.15660];
  D.15662 = idx & 255;
  D.15663 = D.15662 * 144;
  handle_data = D.15661 + D.15663;
  if (state == 1) goto <D.15664>; else goto <D.15665>;
  <D.15664>:
  {
    struct __pthread_unwind_buf_t __cancel_buf;
    void (*<Tc1>) (void *) __cancel_routine;
    void * __cancel_arg;
    int __not_first_call;

    try
      {
        __cancel_routine = mono_mutex_unlock_in_cleanup;
        __cancel_arg = _wapi_global_signal_mutex;
        __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
        D.15666 = __builtin_expect (__not_first_call, 0);
        if (D.15666 != 0) goto <D.15667>; else goto <D.15668>;
        <D.15667>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.15668>:
        __pthread_register_cancel (&__cancel_buf);
        _wapi_global_signal_mutex.9 = _wapi_global_signal_mutex;
        thr_ret = pthread_mutex_lock (_wapi_global_signal_mutex.9);
        if (thr_ret != 0) goto <D.15670>; else goto <D.15671>;
        <D.15670>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.15671>:
        D.15672 = thr_ret != 0;
        D.15673 = (long int) D.15672;
        D.15674 = __builtin_expect (D.15673, 0);
        if (D.15674 != 0) goto <D.15675>; else goto <D.15676>;
        <D.15675>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 151, "thr_ret == 0");
        <D.15676>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.15677>; else goto <D.15678>;
        <D.15677>:
        D.15679 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.15679);
        if (thr_ret != 0) goto <D.15680>; else goto <D.15681>;
        <D.15680>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.15681>:
        D.15672 = thr_ret != 0;
        D.15673 = (long int) D.15672;
        D.15674 = __builtin_expect (D.15673, 0);
        if (D.15674 != 0) goto <D.15682>; else goto <D.15683>;
        <D.15682>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.15683>:
        goto <D.15684>;
        <D.15678>:
        D.15679 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.15679);
        if (thr_ret != 0) goto <D.15685>; else goto <D.15686>;
        <D.15685>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.15686>:
        D.15672 = thr_ret != 0;
        D.15673 = (long int) D.15672;
        D.15674 = __builtin_expect (D.15673, 0);
        if (D.15674 != 0) goto <D.15687>; else goto <D.15688>;
        <D.15687>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.15688>:
        <D.15684>:
        _wapi_global_signal_cond.10 = _wapi_global_signal_cond;
        thr_ret = pthread_cond_broadcast (_wapi_global_signal_cond.10);
        if (thr_ret != 0) goto <D.15690>; else goto <D.15691>;
        <D.15690>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.15691>:
        D.15672 = thr_ret != 0;
        D.15673 = (long int) D.15672;
        D.15674 = __builtin_expect (D.15673, 0);
        if (D.15674 != 0) goto <D.15692>; else goto <D.15693>;
        <D.15692>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.15693>:
        _wapi_global_signal_mutex.9 = _wapi_global_signal_mutex;
        thr_ret = pthread_mutex_unlock (_wapi_global_signal_mutex.9);
        if (thr_ret != 0) goto <D.15694>; else goto <D.15695>;
        <D.15694>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.15695>:
        D.15672 = thr_ret != 0;
        D.15673 = (long int) D.15672;
        D.15674 = __builtin_expect (D.15673, 0);
        if (D.15674 != 0) goto <D.15696>; else goto <D.15697>;
        <D.15696>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.15697>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.15698>; else goto <D.15699>;
        <D.15698>:
        __cancel_routine (__cancel_arg);
        <D.15699>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.15700>;
  <D.15665>:
  handle_data->signalled = state;
  <D.15700>:
}


mono_mutex_unlock_in_cleanup (union mono_mutex_t * mutex)
{
  int D.15711;

  D.15711 = pthread_mutex_unlock (mutex);
  return D.15711;
}


_wapi_handle_unlock_handle (void * handle)
{
  int D.15715;
  <unnamed type> D.15718;
  <unnamed type> D.15720;
  <unnamed type> D.15722;
  <unnamed type> D.15724;
  unsigned int D.15725;
  struct _WapiHandleUnshared * D.15726;
  unsigned int D.15727;
  unsigned int D.15728;
  struct _WapiHandleUnshared * D.15729;
  union mono_mutex_t * D.15730;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.15713>; else goto <D.15714>;
  <D.15713>:
  D.15715 = 0;
  return D.15715;
  <D.15714>:
  D.15718 = _wapi_handle_type (handle);
  if (D.15718 == 9) goto <D.15716>; else goto <D.15719>;
  <D.15719>:
  D.15720 = _wapi_handle_type (handle);
  if (D.15720 == 11) goto <D.15716>; else goto <D.15721>;
  <D.15721>:
  D.15722 = _wapi_handle_type (handle);
  if (D.15722 == 12) goto <D.15716>; else goto <D.15723>;
  <D.15723>:
  D.15724 = _wapi_handle_type (handle);
  if (D.15724 == 13) goto <D.15716>; else goto <D.15717>;
  <D.15716>:
  _wapi_handle_unref (handle);
  D.15715 = 0;
  return D.15715;
  <D.15717>:
  D.15725 = idx / 256;
  D.15726 = _wapi_private_handles[D.15725];
  D.15727 = idx & 255;
  D.15728 = D.15727 * 144;
  D.15729 = D.15726 + D.15728;
  D.15730 = &D.15729->signal_mutex;
  ret = pthread_mutex_unlock (D.15730);
  _wapi_handle_unref (handle);
  D.15715 = ret;
  return D.15715;
}


_wapi_thread_signal_self (guint32 exitstatus)
{
  long unsigned int D.15732;
  void * handle;

  D.15732 = pthread_self ();
  handle = _wapi_thread_handle_from_id (D.15732);
  if (handle == 0B) goto <D.15733>; else goto <D.15734>;
  <D.15733>:
  return;
  <D.15734>:
  _wapi_thread_set_termination_details (handle, exitstatus);
}


CreateThread (struct WapiSecurityAttributes * security, guint32 stacksize, guint32 (*WapiThreadStart) (void *) start, void * param, guint32 create, gsize * tid)
{
  void * D.15738;
  struct GPtrArray * D.15739;
  long int D.15742;
  _Bool D.15745;
  long int D.15746;
  long int D.15747;
  struct _WapiHandle_thread * thread_handle_p.11;
  union MonoSemType * D.15761;
  pthread_t * D.15762;
  char * D.15765;
  long unsigned int D.15768;
  struct _WapiHandle_thread thread_handle;
  struct _WapiHandle_thread * thread_handle_p;
  union pthread_attr_t attr;
  void * handle;
  gboolean ok;
  int ret;
  int thr_ret;
  int i;
  int unrefs;
  void * ct_ret;
  static const char __func__[13] = "CreateThread";
  void cleanup = <<< error >>>;

  try
    {
      thread_handle = {};
      unrefs = 0;
      ct_ret = 0B;
      mono_once (&thread_hash_once, thread_hash_init);
      mono_once (&thread_ops_once, thread_ops_init);
      if (start == 0B) goto <D.15736>; else goto <D.15737>;
      <D.15736>:
      D.15738 = 0B;
      return D.15738;
      <D.15737>:
      thread_handle.state = 0;
      D.15739 = monoeg_g_ptr_array_new ();
      thread_handle.owned_mutexes = D.15739;
      thread_handle.create_flags = create;
      thread_handle.start_routine = start;
      thread_handle.start_arg = param;
      handle = _wapi_handle_new (3, &thread_handle);
      if (handle == 4294967295B) goto <D.15740>; else goto <D.15741>;
      <D.15740>:
      monoeg_g_log (0B, 16, "%s: error creating thread handle", &__func__);
      SetLastError (31);
      D.15738 = 0B;
      return D.15738;
      <D.15741>:
      {
        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.15742 = __builtin_expect (__not_first_call, 0);
            if (D.15742 != 0) goto <D.15743>; else goto <D.15744>;
            <D.15743>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.15744>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.15745 = thr_ret != 0;
            D.15746 = (long int) D.15745;
            D.15747 = __builtin_expect (D.15746, 0);
            if (D.15747 != 0) goto <D.15748>; else goto <D.15749>;
            <D.15748>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 360, "thr_ret == 0");
            <D.15749>:
            ok = _wapi_lookup_handle (handle, 3, &thread_handle_p);
            if (ok == 0) goto <D.15750>; else goto <D.15751>;
            <D.15750>:
            monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
            SetLastError (31);
            goto cleanup;
            <D.15751>:
            _wapi_handle_ref (handle);
            thr_ret = pthread_attr_init (&attr);
            D.15745 = thr_ret != 0;
            D.15746 = (long int) D.15745;
            D.15747 = __builtin_expect (D.15746, 0);
            if (D.15747 != 0) goto <D.15752>; else goto <D.15753>;
            <D.15752>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 383, "thr_ret == 0");
            <D.15753>:
            if (stacksize == 0) goto <D.15754>; else goto <D.15755>;
            <D.15754>:
            stacksize = 1048576;
            <D.15755>:
            if (stacksize <= 16383) goto <D.15756>; else goto <D.15757>;
            <D.15756>:
            stacksize = 16384;
            <D.15757>:
            thr_ret = pthread_attr_setstacksize (&attr, stacksize);
            D.15745 = thr_ret != 0;
            D.15746 = (long int) D.15745;
            D.15747 = __builtin_expect (D.15746, 0);
            if (D.15747 != 0) goto <D.15758>; else goto <D.15759>;
            <D.15758>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 409, "thr_ret == 0");
            <D.15759>:
            thread_handle_p.11 = thread_handle_p;
            D.15761 = &thread_handle_p.11->suspend_sem;
            sem_init (D.15761, 0, 0);
            thread_handle_p.11 = thread_handle_p;
            thread_handle_p.11->handle = handle;
            thread_handle_p.11 = thread_handle_p;
            D.15762 = &thread_handle_p.11->id;
            thread_handle_p.11 = thread_handle_p;
            ret = mono_threads_pthread_create (D.15762, &attr, thread_start_routine, thread_handle_p.11);
            if (ret != 0) goto <D.15763>; else goto <D.15764>;
            <D.15763>:
            D.15765 = strerror (ret);
            monoeg_g_log (0B, 16, "%s: Error creating native thread handle %s (%d)", &__func__, D.15765, ret);
            SetLastError (31);
            unrefs = 2;
            goto cleanup;
            <D.15764>:
            ct_ret = handle;
            if (tid != 0B) goto <D.15766>; else goto <D.15767>;
            <D.15766>:
            thread_handle_p.11 = thread_handle_p;
            D.15768 = thread_handle_p.11->id;
            *tid = D.15768;
            <D.15767>:
            cleanup:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.15745 = thr_ret != 0;
            D.15746 = (long int) D.15745;
            D.15747 = __builtin_expect (D.15746, 0);
            if (D.15747 != 0) goto <D.15769>; else goto <D.15770>;
            <D.15769>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 448, "thr_ret == 0");
            <D.15770>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.15771>; else goto <D.15772>;
            <D.15771>:
            __cancel_routine (__cancel_arg);
            <D.15772>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      i = 0;
      goto <D.15333>;
      <D.15332>:
      _wapi_handle_unref (handle);
      i = i + 1;
      <D.15333>:
      if (i < unrefs) goto <D.15332>; else goto <D.15334>;
      <D.15334>:
      D.15738 = ct_ret;
      return D.15738;
    }
  finally
    {
      thread_handle = {CLOBBER};
      thread_handle_p = {CLOBBER};
      attr = {CLOBBER};
    }
}


thread_start_routine (void * args)
{
  unsigned int D.15781;
  unsigned int D.15782;
  long unsigned int D.15785;
  _Bool D.15786;
  long int D.15787;
  long int D.15788;
  unsigned int thread_hash_key.12;
  void * D.15792;
  unsigned int D.15795;
  guint32 (*<T1fec>) (void *) D.15798;
  void * D.15799;
  unsigned int D.15800;
  struct _WapiHandle_thread * thread;
  int thr_ret;

  thread = args;
  D.15781 = thread->create_flags;
  D.15782 = D.15781 & 268435456;
  if (D.15782 == 0) goto <D.15783>; else goto <D.15784>;
  <D.15783>:
  D.15785 = pthread_self ();
  thr_ret = mono_gc_pthread_detach (D.15785);
  D.15786 = thr_ret != 0;
  D.15787 = (long int) D.15786;
  D.15788 = __builtin_expect (D.15787, 0);
  if (D.15788 != 0) goto <D.15789>; else goto <D.15790>;
  <D.15789>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 259, "thr_ret == 0");
  <D.15790>:
  <D.15784>:
  thread_hash_key.12 = thread_hash_key;
  D.15792 = thread->handle;
  thr_ret = pthread_setspecific (thread_hash_key.12, D.15792);
  if (thr_ret != 0) goto <D.15793>; else goto <D.15794>;
  <D.15793>:
  mono_gc_pthread_exit (0B);
  <D.15794>:
  D.15785 = pthread_self ();
  thread->id = D.15785;
  D.15781 = thread->create_flags;
  D.15795 = D.15781 & 4;
  if (D.15795 != 0) goto <D.15796>; else goto <D.15797>;
  <D.15796>:
  _wapi_thread_suspend (thread);
  <D.15797>:
  D.15798 = thread->start_routine;
  D.15799 = thread->start_arg;
  D.15800 = D.15798 (D.15799);
  D.15792 = thread->handle;
  thread_exit (D.15800, D.15792);
}


_wapi_thread_suspend (struct _WapiHandle_thread * thread)
{
  long unsigned int D.15801;
  long unsigned int D.15802;
  int D.15803;
  _Bool D.15804;
  long int D.15805;
  long int D.15806;
  union MonoSemType * D.15809;
  int D.15810;
  int * D.15812;
  int D.15813;

  D.15801 = thread->id;
  D.15802 = pthread_self ();
  D.15803 = pthread_equal (D.15801, D.15802);
  D.15804 = D.15803 == 0;
  D.15805 = (long int) D.15804;
  D.15806 = __builtin_expect (D.15805, 0);
  if (D.15806 != 0) goto <D.15807>; else goto <D.15808>;
  <D.15807>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 240, "pthread_equal (thread->id, pthread_self ())");
  <D.15808>:
  goto <D.15294>;
  <D.15293>:
  <D.15294>:
  D.15809 = &thread->suspend_sem;
  D.15810 = mono_sem_wait (D.15809, 0);
  if (D.15810 != 0) goto <D.15811>; else goto <D.15295>;
  <D.15811>:
  D.15812 = __errno_location ();
  D.15813 = *D.15812;
  if (D.15813 == 4) goto <D.15293>; else goto <D.15295>;
  <D.15295>:
}


thread_exit (guint32 exitstatus, void * handle)
{
  _wapi_thread_set_termination_details (handle, exitstatus);
  mono_gc_pthread_exit (0B);
}


thread_ops_init ()
{
  _wapi_handle_register_capabilities (3, 1);
}


thread_hash_init ()
{
  _Bool D.15814;
  long int D.15815;
  long int D.15816;
  int thr_ret;

  thr_ret = pthread_key_create (&thread_hash_key, 0B);
  D.15814 = thr_ret != 0;
  D.15815 = (long int) D.15814;
  D.15816 = __builtin_expect (D.15815, 0);
  if (D.15816 != 0) goto <D.15817>; else goto <D.15818>;
  <D.15817>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 231, "thr_ret == 0");
  <D.15818>:
  thr_ret = pthread_key_create (&thread_attached_key, thread_attached_exit);
  D.15814 = thr_ret != 0;
  D.15815 = (long int) D.15814;
  D.15816 = __builtin_expect (D.15815, 0);
  if (D.15816 != 0) goto <D.15819>; else goto <D.15820>;
  <D.15819>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 235, "thr_ret == 0");
  <D.15820>:
}


thread_attached_exit (void * handle)
{
  _wapi_thread_set_termination_details (handle, 0);
}


_wapi_thread_handle_from_id (pthread_t tid)
{
  long unsigned int D.15821;
  int D.15822;
  unsigned int thread_hash_key.13;
  void * D.15828;
  void * ret;

  D.15821 = pthread_self ();
  D.15822 = pthread_equal (tid, D.15821);
  if (D.15822 != 0) goto <D.15823>; else goto <D.15824>;
  <D.15823>:
  thread_hash_key.13 = thread_hash_key;
  ret = pthread_getspecific (thread_hash_key.13);
  if (ret != 0B) goto <D.15826>; else goto <D.15827>;
  <D.15826>:
  D.15828 = ret;
  return D.15828;
  <D.15827>:
  <D.15824>:
  D.15828 = 0B;
  return D.15828;
}


OpenThread (guint32 access, gboolean inherit, gsize tid)
{
  void * tid.14;
  void * D.15834;
  void * ret;

  ret = 0B;
  mono_once (&thread_hash_once, thread_hash_init);
  mono_once (&thread_ops_once, thread_ops_init);
  ret = _wapi_thread_handle_from_id (tid);
  if (ret == 0B) goto <D.15830>; else goto <D.15831>;
  <D.15830>:
  tid.14 = (void *) tid;
  ret = _wapi_search_handle (3, find_thread_by_id, tid.14, 0B, 0);
  goto <D.15833>;
  <D.15831>:
  _wapi_handle_ref (ret);
  <D.15833>:
  D.15834 = ret;
  return D.15834;
}


find_thread_by_id (void * handle, void * user_data)
{
  int D.15836;
  gboolean D.15841;
  struct _WapiHandle_thread * thread_handle.15;
  long unsigned int D.15843;
  int D.15844;
  pthread_t tid;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;

  try
    {
      tid = (pthread_t) user_data;
      D.15836 = _wapi_handle_issignalled (handle);
      if (D.15836 == 0) goto <D.15837>; else goto <D.15838>;
      <D.15837>:
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.15839>; else goto <D.15840>;
      <D.15839>:
      D.15841 = 0;
      return D.15841;
      <D.15840>:
      thread_handle.15 = thread_handle;
      D.15843 = thread_handle.15->id;
      D.15844 = pthread_equal (D.15843, tid);
      if (D.15844 != 0) goto <D.15845>; else goto <D.15846>;
      <D.15845>:
      D.15841 = 1;
      return D.15841;
      <D.15846>:
      <D.15838>:
      D.15841 = 0;
      return D.15841;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


ExitThread (guint32 exitcode)
{
  long unsigned int D.15849;
  void * thread;

  D.15849 = pthread_self ();
  thread = _wapi_thread_handle_from_id (D.15849);
  if (thread != 0B) goto <D.15850>; else goto <D.15851>;
  <D.15850>:
  thread_exit (exitcode, thread);
  <D.15851>:
  mono_gc_pthread_exit (0B);
}


GetExitCodeThread (void * handle, guint32 * exitcode)
{
  gboolean D.15854;
  struct _WapiHandle_thread * thread_handle.16;
  unsigned char D.15858;
  unsigned char D.15859;
  unsigned int D.15862;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  static const char __func__[18] = "GetExitCodeThread";

  try
    {
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.15852>; else goto <D.15853>;
      <D.15852>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.15854 = 0;
      return D.15854;
      <D.15853>:
      if (exitcode == 0B) goto <D.15855>; else goto <D.15856>;
      <D.15855>:
      D.15854 = 0;
      return D.15854;
      <D.15856>:
      thread_handle.16 = thread_handle;
      D.15858 = BIT_FIELD_REF <*thread_handle.16, 8, 32>;
      D.15859 = D.15858 & 3;
      if (D.15859 != 1) goto <D.15860>; else goto <D.15861>;
      <D.15860>:
      *exitcode = 259;
      D.15854 = 1;
      return D.15854;
      <D.15861>:
      thread_handle.16 = thread_handle;
      D.15862 = thread_handle.16->exitstatus;
      *exitcode = D.15862;
      D.15854 = 1;
      return D.15854;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


GetCurrentThreadId ()
{
  gsize D.15865;
  pthread_t tid;

  tid = pthread_self ();
  D.15865 = tid;
  return D.15865;
}


_wapi_thread_duplicate ()
{
  long unsigned int D.15867;
  void * D.15871;
  void * ret;

  ret = 0B;
  mono_once (&thread_hash_once, thread_hash_init);
  mono_once (&thread_ops_once, thread_ops_init);
  D.15867 = pthread_self ();
  ret = _wapi_thread_handle_from_id (D.15867);
  if (ret == 0B) goto <D.15868>; else goto <D.15869>;
  <D.15868>:
  ret = thread_attach (0B);
  goto <D.15870>;
  <D.15869>:
  _wapi_handle_ref (ret);
  <D.15870>:
  D.15871 = ret;
  return D.15871;
}


thread_attach (gsize * tid)
{
  struct GPtrArray * D.15873;
  void * D.15876;
  long int D.15877;
  _Bool D.15880;
  long int D.15881;
  long int D.15882;
  struct _WapiHandle_thread * thread_handle_p.17;
  union MonoSemType * D.15888;
  long unsigned int D.15889;
  unsigned int thread_hash_key.18;
  unsigned int thread_attached_key.19;
  long unsigned int D.15898;
  struct _WapiHandle_thread thread_handle;
  struct _WapiHandle_thread * thread_handle_p;
  void * handle;
  gboolean ok;
  int thr_ret;
  static const char __func__[14] = "thread_attach";
  void cleanup = <<< error >>>;

  try
    {
      thread_handle = {};
      mono_once (&thread_hash_once, thread_hash_init);
      mono_once (&thread_ops_once, thread_ops_init);
      thread_handle.state = 0;
      D.15873 = monoeg_g_ptr_array_new ();
      thread_handle.owned_mutexes = D.15873;
      handle = _wapi_handle_new (3, &thread_handle);
      if (handle == 4294967295B) goto <D.15874>; else goto <D.15875>;
      <D.15874>:
      monoeg_g_log (0B, 16, "%s: error creating thread handle", &__func__);
      SetLastError (31);
      D.15876 = 0B;
      return D.15876;
      <D.15875>:
      {
        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.15877 = __builtin_expect (__not_first_call, 0);
            if (D.15877 != 0) goto <D.15878>; else goto <D.15879>;
            <D.15878>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.15879>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.15880 = thr_ret != 0;
            D.15881 = (long int) D.15880;
            D.15882 = __builtin_expect (D.15881, 0);
            if (D.15882 != 0) goto <D.15883>; else goto <D.15884>;
            <D.15883>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 663, "thr_ret == 0");
            <D.15884>:
            ok = _wapi_lookup_handle (handle, 3, &thread_handle_p);
            if (ok == 0) goto <D.15885>; else goto <D.15886>;
            <D.15885>:
            monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
            SetLastError (31);
            goto cleanup;
            <D.15886>:
            _wapi_handle_ref (handle);
            thread_handle_p.17 = thread_handle_p;
            D.15888 = &thread_handle_p.17->suspend_sem;
            sem_init (D.15888, 0, 0);
            thread_handle_p.17 = thread_handle_p;
            thread_handle_p.17->handle = handle;
            thread_handle_p.17 = thread_handle_p;
            D.15889 = pthread_self ();
            thread_handle_p.17->id = D.15889;
            thread_hash_key.18 = thread_hash_key;
            thr_ret = pthread_setspecific (thread_hash_key.18, handle);
            D.15880 = thr_ret != 0;
            D.15881 = (long int) D.15880;
            D.15882 = __builtin_expect (D.15881, 0);
            if (D.15882 != 0) goto <D.15891>; else goto <D.15892>;
            <D.15891>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 688, "thr_ret == 0");
            <D.15892>:
            thread_attached_key.19 = thread_attached_key;
            thr_ret = pthread_setspecific (thread_attached_key.19, handle);
            D.15880 = thr_ret != 0;
            D.15881 = (long int) D.15880;
            D.15882 = __builtin_expect (D.15881, 0);
            if (D.15882 != 0) goto <D.15894>; else goto <D.15895>;
            <D.15894>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 691, "thr_ret == 0");
            <D.15895>:
            if (tid != 0B) goto <D.15896>; else goto <D.15897>;
            <D.15896>:
            thread_handle_p.17 = thread_handle_p;
            D.15898 = thread_handle_p.17->id;
            *tid = D.15898;
            <D.15897>:
            cleanup:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.15880 = thr_ret != 0;
            D.15881 = (long int) D.15880;
            D.15882 = __builtin_expect (D.15881, 0);
            if (D.15882 != 0) goto <D.15899>; else goto <D.15900>;
            <D.15899>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 710, "thr_ret == 0");
            <D.15900>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.15901>; else goto <D.15902>;
            <D.15901>:
            __cancel_routine (__cancel_arg);
            <D.15902>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.15876 = handle;
      return D.15876;
    }
  finally
    {
      thread_handle = {CLOBBER};
      thread_handle_p = {CLOBBER};
    }
}


GetCurrentThread ()
{
  void * D.15910;

  mono_once (&thread_hash_once, thread_hash_init);
  mono_once (&thread_ops_once, thread_ops_init);
  D.15910 = 4294967294B;
  return D.15910;
}


ResumeThread (void * handle)
{
  guint32 D.15914;
  struct _WapiHandle_thread * thread_handle.20;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  static const char __func__[13] = "ResumeThread";

  try
    {
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.15912>; else goto <D.15913>;
      <D.15912>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.15914 = 4294967295;
      return D.15914;
      <D.15913>:
      thread_handle.20 = thread_handle;
      _wapi_thread_resume (thread_handle.20);
      D.15914 = 4294967295;
      return D.15914;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


_wapi_thread_resume (struct _WapiHandle_thread * thread)
{
  union MonoSemType * D.15918;

  D.15918 = &thread->suspend_sem;
  mono_sem_post (D.15918);
}


SuspendThread (void * handle)
{
  guint32 D.15919;

  D.15919 = 4294967295;
  return D.15919;
}


SleepEx (guint32 ms, gboolean alertable)
{
  long unsigned int D.15923;
  guint32 D.15926;
  int D.15927;
  unsigned int D.15932;
  unsigned int D.15933;
  int D.15934;
  int D.15937;
  struct timespec req;
  struct timespec rem;
  int ms_quot;
  int ms_rem;
  int ret;
  void * current_thread;
  void again = <<< error >>>;

  try
    {
      current_thread = 0B;
      if (alertable != 0) goto <D.15921>; else goto <D.15922>;
      <D.15921>:
      D.15923 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.15923);
      if (current_thread == 0B) goto <D.15924>; else goto <D.15925>;
      <D.15924>:
      SetLastError (6);
      D.15926 = 4294967295;
      return D.15926;
      <D.15925>:
      D.15927 = _wapi_thread_apc_pending (current_thread);
      if (D.15927 != 0) goto <D.15928>; else goto <D.15929>;
      <D.15928>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.15926 = 192;
      return D.15926;
      <D.15929>:
      <D.15922>:
      if (ms == 0) goto <D.15930>; else goto <D.15931>;
      <D.15930>:
      sched_yield ();
      D.15926 = 0;
      return D.15926;
      <D.15931>:
      D.15932 = ms / 1000;
      ms_quot = (int) D.15932;
      D.15933 = ms % 1000;
      ms_rem = (int) D.15933;
      req.tv_sec = ms_quot;
      D.15934 = ms_rem * 1000000;
      req.tv_nsec = D.15934;
      again:
      memset (&rem, 0, 8);
      ret = nanosleep (&req, &rem);
      if (alertable != 0) goto <D.15935>; else goto <D.15936>;
      <D.15935>:
      D.15937 = _wapi_thread_apc_pending (current_thread);
      if (D.15937 != 0) goto <D.15938>; else goto <D.15939>;
      <D.15938>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.15926 = 192;
      return D.15926;
      <D.15939>:
      <D.15936>:
      if (ret == -1) goto <D.15940>; else goto <D.15941>;
      <D.15940>:
      req = rem;
      goto again;
      <D.15941>:
      D.15926 = 0;
      return D.15926;
    }
  finally
    {
      req = {CLOBBER};
      rem = {CLOBBER};
    }
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.15946;
  int D.15951;
  void * D.15953;
  unsigned int D.15954;

  D.15946 = __builtin_constant_p (__len);
  if (D.15946 != 0) goto <D.15947>; else goto <D.15948>;
  <D.15947>:
  if (__len == 0) goto <D.15949>; else goto <D.15950>;
  <D.15949>:
  D.15951 = __builtin_constant_p (__ch);
  if (D.15951 == 0) goto <D.15944>; else goto <D.15952>;
  <D.15952>:
  if (__ch != 0) goto <D.15944>; else goto <D.15945>;
  <D.15944>:
  __warn_memset_zero_len ();
  D.15953 = __dest;
  return D.15953;
  <D.15945>:
  <D.15950>:
  <D.15948>:
  D.15954 = __builtin_object_size (__dest, 0);
  D.15953 = __builtin___memset_chk (__dest, __ch, __len, D.15954);
  return D.15953;
}


Sleep (guint32 ms)
{
  SleepEx (ms, 0);
}


_wapi_thread_cur_apc_pending ()
{
  long unsigned int D.15956;
  gboolean D.15959;
  void * thread;

  D.15956 = pthread_self ();
  thread = _wapi_thread_handle_from_id (D.15956);
  if (thread == 0B) goto <D.15957>; else goto <D.15958>;
  <D.15957>:
  SetLastError (6);
  D.15959 = 0;
  return D.15959;
  <D.15958>:
  D.15959 = _wapi_thread_apc_pending (thread);
  return D.15959;
}


_wapi_thread_apc_pending (void * handle)
{
  gboolean D.15963;
  int iftmp.21;
  struct _WapiHandle_thread * thread.22;
  unsigned char D.15969;
  unsigned char D.15970;
  void * D.15972;
  struct _WapiHandle_thread * thread;
  gboolean ok;

  try
    {
      ok = _wapi_lookup_handle (handle, 3, &thread);
      if (ok == 0) goto <D.15961>; else goto <D.15962>;
      <D.15961>:
      D.15963 = 0;
      return D.15963;
      <D.15962>:
      thread.22 = thread;
      D.15969 = BIT_FIELD_REF <*thread.22, 8, 32>;
      D.15970 = D.15969 & 8;
      if (D.15970 != 0) goto <D.15965>; else goto <D.15971>;
      <D.15971>:
      thread.22 = thread;
      D.15972 = thread.22->wait_handle;
      if (D.15972 == 4294967294B) goto <D.15965>; else goto <D.15966>;
      <D.15965>:
      iftmp.21 = 1;
      goto <D.15967>;
      <D.15966>:
      iftmp.21 = 0;
      <D.15967>:
      D.15963 = iftmp.21;
      return D.15963;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


_wapi_thread_dispatch_apc_queue (void * handle)
{
  _Bool D.15975;
  long int D.15976;
  long int D.15977;
  struct _WapiHandle_thread * thread.23;
  gboolean D.15981;
  struct _WapiHandle_thread * thread;
  gboolean ok;

  try
    {
      ok = _wapi_lookup_handle (handle, 3, &thread);
      D.15975 = ok == 0;
      D.15976 = (long int) D.15975;
      D.15977 = __builtin_expect (D.15976, 0);
      if (D.15977 != 0) goto <D.15978>; else goto <D.15979>;
      <D.15978>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 910, "ok");
      <D.15979>:
      thread.23 = thread;
      thread.23->has_apc = 0;
      D.15981 = 1;
      return D.15981;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


QueueUserAPC (guint32 (*WapiApcProc) (void *) apc_callback, void * handle, void * param)
{
  guint32 D.15986;
  struct _WapiHandle_thread * thread_handle.24;
  long unsigned int D.15988;
  unsigned int D.15989;
  _Bool D.15990;
  long int D.15991;
  long int D.15992;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  static const char __func__[13] = "QueueUserAPC";

  try
    {
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.15984>; else goto <D.15985>;
      <D.15984>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.15986 = 0;
      return D.15986;
      <D.15985>:
      thread_handle.24 = thread_handle;
      D.15988 = thread_handle.24->id;
      D.15989 = GetCurrentThreadId ();
      D.15990 = D.15988 != D.15989;
      D.15991 = (long int) D.15990;
      D.15992 = __builtin_expect (D.15991, 0);
      if (D.15992 != 0) goto <D.15993>; else goto <D.15994>;
      <D.15993>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 938, "thread_handle->id == (pthread_t)GetCurrentThreadId ()");
      <D.15994>:
      thread_handle.24 = thread_handle;
      thread_handle.24->has_apc = 1;
      D.15986 = 1;
      return D.15986;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


wapi_interrupt_thread (void * thread_handle)
{
  _Bool D.15997;
  long int D.15998;
  long int D.15999;
  struct _WapiHandle_thread * thread.25;
  void * * D.16003;
  unsigned int D.16009;
  struct _WapiHandleUnshared * D.16010;
  unsigned int D.16011;
  unsigned int D.16012;
  struct _WapiHandleUnshared * D.16013;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * wait_handle;
  guint32 idx;
  union pthread_cond_t * cond;
  union mono_mutex_t * mutex;

  try
    {
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.15997 = ok == 0;
      D.15998 = (long int) D.15997;
      D.15999 = __builtin_expect (D.15998, 0);
      if (D.15999 != 0) goto <D.16000>; else goto <D.16001>;
      <D.16000>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 969, "ok");
      <D.16001>:
      <D.15445>:
      thread.25 = thread;
      wait_handle = thread.25->wait_handle;
      thread.25 = thread;
      D.16003 = &thread.25->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.16003, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto <D.16004>; else goto <D.16005>;
      <D.16004>:
      return;
      <D.16005>:
      if (prev_handle == wait_handle) goto <D.15444>; else goto <D.16006>;
      <D.16006>:
      goto <D.15445>;
      <D.15444>:
      if (wait_handle == 0B) goto <D.16007>; else goto <D.16008>;
      <D.16007>:
      return;
      <D.16008>:
      idx = (guint32) wait_handle;
      D.16009 = idx / 256;
      D.16010 = _wapi_private_handles[D.16009];
      D.16011 = idx & 255;
      D.16012 = D.16011 * 144;
      D.16013 = D.16010 + D.16012;
      cond = &D.16013->signal_cond;
      D.16009 = idx / 256;
      D.16010 = _wapi_private_handles[D.16009];
      D.16011 = idx & 255;
      D.16012 = D.16011 * 144;
      D.16013 = D.16010 + D.16012;
      mutex = &D.16013->signal_mutex;
      pthread_mutex_lock (mutex);
      pthread_cond_broadcast (cond);
      pthread_mutex_unlock (mutex);
      _wapi_handle_unref (wait_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


InterlockedCompareExchangePointer (void * volatile * dest, void * exch, void * comp)
{
  void * D.16017;
  unsigned int comp.26;
  unsigned int exch.27;
  unsigned int D.16020;

  comp.26 = (unsigned int) comp;
  exch.27 = (unsigned int) exch;
  D.16020 = __sync_val_compare_and_swap_4 (dest, comp.26, exch.27);
  D.16017 = (void *) D.16020;
  return D.16017;
}


wapi_prepare_interrupt_thread (void * thread_handle)
{
  _Bool D.16022;
  long int D.16023;
  long int D.16024;
  struct _WapiHandle_thread * thread.28;
  void * * D.16028;
  void * D.16031;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * wait_handle;

  try
    {
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.16022 = ok == 0;
      D.16023 = (long int) D.16022;
      D.16024 = __builtin_expect (D.16023, 0);
      if (D.16024 != 0) goto <D.16025>; else goto <D.16026>;
      <D.16025>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1023, "ok");
      <D.16026>:
      <D.15454>:
      thread.28 = thread;
      wait_handle = thread.28->wait_handle;
      thread.28 = thread;
      D.16028 = &thread.28->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.16028, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto <D.16029>; else goto <D.16030>;
      <D.16029>:
      D.16031 = 0B;
      return D.16031;
      <D.16030>:
      if (prev_handle == wait_handle) goto <D.15453>; else goto <D.16032>;
      <D.16032>:
      goto <D.15454>;
      <D.15453>:
      D.16031 = wait_handle;
      return D.16031;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_finish_interrupt_thread (void * wait_handle)
{
  unsigned int D.16037;
  struct _WapiHandleUnshared * D.16038;
  unsigned int D.16039;
  unsigned int D.16040;
  struct _WapiHandleUnshared * D.16041;
  union pthread_cond_t * cond;
  union mono_mutex_t * mutex;
  guint32 idx;

  if (wait_handle == 0B) goto <D.16035>; else goto <D.16036>;
  <D.16035>:
  return;
  <D.16036>:
  idx = (guint32) wait_handle;
  D.16037 = idx / 256;
  D.16038 = _wapi_private_handles[D.16037];
  D.16039 = idx & 255;
  D.16040 = D.16039 * 144;
  D.16041 = D.16038 + D.16040;
  cond = &D.16041->signal_cond;
  D.16037 = idx / 256;
  D.16038 = _wapi_private_handles[D.16037];
  D.16039 = idx & 255;
  D.16040 = D.16039 * 144;
  D.16041 = D.16038 + D.16040;
  mutex = &D.16041->signal_mutex;
  pthread_mutex_lock (mutex);
  pthread_cond_broadcast (cond);
  pthread_mutex_unlock (mutex);
  _wapi_handle_unref (wait_handle);
}


wapi_self_interrupt ()
{
  unsigned int D.16043;
  _Bool D.16044;
  long int D.16045;
  long int D.16046;
  struct _WapiHandle_thread * thread.29;
  void * * D.16050;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * wait_handle;
  void * thread_handle;
  void cleanup = <<< error >>>;

  try
    {
      D.16043 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.16043);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.16044 = ok == 0;
      D.16045 = (long int) D.16044;
      D.16046 = __builtin_expect (D.16045, 0);
      if (D.16046 != 0) goto <D.16047>; else goto <D.16048>;
      <D.16047>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1095, "ok");
      <D.16048>:
      <D.15471>:
      thread.29 = thread;
      wait_handle = thread.29->wait_handle;
      thread.29 = thread;
      D.16050 = &thread.29->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.16050, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto cleanup; else goto <D.16051>;
      <D.16051>:
      if (prev_handle == wait_handle) goto <D.15470>; else goto <D.16052>;
      <D.16052>:
      goto <D.15471>;
      <D.15470>:
      if (wait_handle != 0B) goto <D.16053>; else goto <D.16054>;
      <D.16053>:
      _wapi_handle_unref (wait_handle);
      <D.16054>:
      cleanup:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_clear_interruption ()
{
  unsigned int D.16055;
  _Bool D.16056;
  long int D.16057;
  long int D.16058;
  struct _WapiHandle_thread * thread.30;
  void * * D.16062;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.16055 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.16055);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.16056 = ok == 0;
      D.16057 = (long int) D.16056;
      D.16058 = __builtin_expect (D.16057, 0);
      if (D.16058 != 0) goto <D.16059>; else goto <D.16060>;
      <D.16059>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1142, "ok");
      <D.16060>:
      thread.30 = thread;
      D.16062 = &thread.30->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.16062, 0B, 4294967294B);
      if (prev_handle == 4294967294B) goto <D.16063>; else goto <D.16064>;
      <D.16063>:
      <D.16064>:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_current_thread_desc ()
{
  unsigned int D.16065;
  char * D.16068;
  struct _WapiHandle_thread * thread.31;
  <unnamed type> D.16076;
  const char * D.16077;
  struct GPtrArray * D.16078;
  void * * D.16079;
  unsigned int i.32;
  unsigned int D.16081;
  void * * D.16082;
  unsigned int i.33;
  unsigned int D.16087;
  struct _WapiHandle_thread * thread;
  int i;
  gboolean ok;
  void * handle;
  void * thread_handle;
  struct GString * text;
  char * res;

  try
    {
      D.16065 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.16065);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      if (ok == 0) goto <D.16066>; else goto <D.16067>;
      <D.16066>:
      D.16068 = monoeg_g_strdup_printf ("thread handle %p state : lookup failure", thread_handle);
      return D.16068;
      <D.16067>:
      thread.31 = thread;
      handle = thread.31->wait_handle;
      text = monoeg_g_string_new (0B);
      monoeg_g_string_append_printf (text, "thread handle %p state : ", thread_handle);
      if (handle == 0B) goto <D.16070>; else goto <D.16071>;
      <D.16070>:
      monoeg_g_string_append_printf (text, "not waiting");
      goto <D.16072>;
      <D.16071>:
      if (handle == 4294967294B) goto <D.16073>; else goto <D.16074>;
      <D.16073>:
      monoeg_g_string_append_printf (text, "interrupted state");
      goto <D.16075>;
      <D.16074>:
      D.16076 = _wapi_handle_type (handle);
      D.16077 = _wapi_handle_typename[D.16076];
      monoeg_g_string_append_printf (text, "waiting on %p : %s ", handle, D.16077);
      <D.16075>:
      <D.16072>:
      monoeg_g_string_append_printf (text, " owns (");
      i = 0;
      goto <D.15490>;
      <D.15489>:
      {
        void * mutex;

        thread.31 = thread;
        D.16078 = thread.31->owned_mutexes;
        D.16079 = D.16078->pdata;
        i.32 = (unsigned int) i;
        D.16081 = i.32 * 4;
        D.16082 = D.16079 + D.16081;
        mutex = *D.16082;
        if (i > 0) goto <D.16083>; else goto <D.16084>;
        <D.16083>:
        monoeg_g_string_append_printf (text, ", %p", mutex);
        goto <D.16085>;
        <D.16084>:
        monoeg_g_string_append_printf (text, "%p", mutex);
        <D.16085>:
      }
      i = i + 1;
      <D.15490>:
      i.33 = (unsigned int) i;
      thread.31 = thread;
      D.16078 = thread.31->owned_mutexes;
      D.16087 = D.16078->len;
      if (i.33 < D.16087) goto <D.15489>; else goto <D.15491>;
      <D.15491>:
      monoeg_g_string_append_printf (text, ")");
      res = text->str;
      monoeg_g_string_free (text, 0);
      D.16068 = res;
      return D.16068;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_thread_set_wait_handle (void * handle)
{
  unsigned int D.16090;
  _Bool D.16091;
  long int D.16092;
  long int D.16093;
  struct _WapiHandle_thread * thread.34;
  void * * D.16097;
  _Bool D.16101;
  long int D.16102;
  long int D.16103;
  gboolean D.16106;
  _Bool D.16107;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.16090 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.16090);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.16091 = ok == 0;
      D.16092 = (long int) D.16091;
      D.16093 = __builtin_expect (D.16092, 0);
      if (D.16093 != 0) goto <D.16094>; else goto <D.16095>;
      <D.16094>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1209, "ok");
      <D.16095>:
      thread.34 = thread;
      D.16097 = &thread.34->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.16097, handle, 0B);
      _wapi_handle_unref (thread_handle);
      if (prev_handle == 0B) goto <D.16098>; else goto <D.16099>;
      <D.16098>:
      _wapi_handle_ref (handle);
      goto <D.16100>;
      <D.16099>:
      D.16101 = prev_handle != 4294967294B;
      D.16102 = (long int) D.16101;
      D.16103 = __builtin_expect (D.16102, 0);
      if (D.16103 != 0) goto <D.16104>; else goto <D.16105>;
      <D.16104>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1221, "prev_handle == INTERRUPTION_REQUESTED_HANDLE");
      <D.16105>:
      <D.16100>:
      D.16107 = prev_handle == 0B;
      D.16106 = (gboolean) D.16107;
      return D.16106;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_thread_clear_wait_handle (void * handle)
{
  unsigned int D.16110;
  _Bool D.16111;
  long int D.16112;
  long int D.16113;
  struct _WapiHandle_thread * thread.35;
  void * * D.16117;
  _Bool D.16121;
  _Bool D.16122;
  _Bool D.16123;
  int D.16124;
  _Bool D.16125;
  long int D.16126;
  long int D.16127;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.16110 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.16110);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.16111 = ok == 0;
      D.16112 = (long int) D.16111;
      D.16113 = __builtin_expect (D.16112, 0);
      if (D.16113 != 0) goto <D.16114>; else goto <D.16115>;
      <D.16114>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1243, "ok");
      <D.16115>:
      thread.35 = thread;
      D.16117 = &thread.35->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.16117, 0B, handle);
      if (prev_handle == handle) goto <D.16118>; else goto <D.16119>;
      <D.16118>:
      _wapi_handle_unref (handle);
      goto <D.16120>;
      <D.16119>:
      D.16121 = prev_handle != 4294967294B;
      D.16122 = prev_handle != 0B;
      D.16123 = D.16121 & D.16122;
      D.16124 = (int) D.16123;
      D.16125 = D.16124 != 0;
      D.16126 = (long int) D.16125;
      D.16127 = __builtin_expect (D.16126, 0);
      if (D.16127 != 0) goto <D.16128>; else goto <D.16129>;
      <D.16128>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1253, "prev_handle == INTERRUPTION_REQUESTED_HANDLE || prev_handle == NULL");
      <D.16129>:
      <D.16120>:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


_wapi_thread_own_mutex (void * mutex)
{
  long unsigned int D.16130;
  struct _WapiHandle_thread * thread_handle.36;
  struct GPtrArray * D.16136;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  void * thread;
  static const char __func__[23] = "_wapi_thread_own_mutex";

  try
    {
      D.16130 = pthread_self ();
      thread = _wapi_thread_handle_from_id (D.16130);
      if (thread == 0B) goto <D.16131>; else goto <D.16132>;
      <D.16131>:
      monoeg_g_log (0B, 16, "%s: error looking up thread by ID", &__func__);
      return;
      <D.16132>:
      ok = _wapi_lookup_handle (thread, 3, &thread_handle);
      if (ok == 0) goto <D.16133>; else goto <D.16134>;
      <D.16133>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, thread);
      return;
      <D.16134>:
      _wapi_handle_ref (mutex);
      thread_handle.36 = thread_handle;
      D.16136 = thread_handle.36->owned_mutexes;
      monoeg_g_ptr_array_add (D.16136, mutex);
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


_wapi_thread_disown_mutex (void * mutex)
{
  long unsigned int D.16140;
  struct _WapiHandle_thread * thread_handle.37;
  struct GPtrArray * D.16146;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  void * thread;
  static const char __func__[26] = "_wapi_thread_disown_mutex";

  try
    {
      D.16140 = pthread_self ();
      thread = _wapi_thread_handle_from_id (D.16140);
      if (thread == 0B) goto <D.16141>; else goto <D.16142>;
      <D.16141>:
      monoeg_g_log (0B, 16, "%s: error looking up thread by ID", &__func__);
      return;
      <D.16142>:
      ok = _wapi_lookup_handle (thread, 3, &thread_handle);
      if (ok == 0) goto <D.16143>; else goto <D.16144>;
      <D.16143>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, thread);
      return;
      <D.16144>:
      _wapi_handle_unref (mutex);
      thread_handle.37 = thread_handle;
      D.16146 = thread_handle.37->owned_mutexes;
      monoeg_g_ptr_array_remove (D.16146, mutex);
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


