_wapi_thread_cleanup ()
{
  unsigned int thread_hash_key.0;
  _Bool D.12941;
  long int D.12942;
  long int D.12943;
  unsigned int thread_attached_key.1;
  int ret;

  thread_hash_key.0 = thread_hash_key;
  ret = pthread_key_delete (thread_hash_key.0);
  D.12941 = ret != 0;
  D.12942 = (long int) D.12941;
  D.12943 = __builtin_expect (D.12942, 0);
  if (D.12943 != 0) goto <D.12944>; else goto <D.12945>;
  <D.12944>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 86, "ret == 0");
  <D.12945>:
  thread_attached_key.1 = thread_attached_key;
  ret = pthread_key_delete (thread_attached_key.1);
  D.12941 = ret != 0;
  D.12942 = (long int) D.12941;
  D.12943 = __builtin_expect (D.12942, 0);
  if (D.12943 != 0) goto <D.12947>; else goto <D.12948>;
  <D.12947>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 89, "ret == 0");
  <D.12948>:
}


_wapi_thread_set_termination_details (void * handle, guint32 exitstatus)
{
  int D.12951;
  <unnamed type> D.12953;
  long int D.12956;
  _Bool D.12959;
  long int D.12960;
  long int D.12961;
  struct _WapiHandle_thread * thread_handle.2;
  union MonoSemType * D.12965;
  struct GPtrArray * D.12966;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  int thr_ret;
  static const char __func__[37] = "_wapi_thread_set_termination_details";

  try
    {
      D.12951 = _wapi_handle_issignalled (handle);
      if (D.12951 != 0) goto <D.12949>; else goto <D.12952>;
      <D.12952>:
      D.12953 = _wapi_handle_type (handle);
      if (D.12953 == 0) goto <D.12949>; else goto <D.12950>;
      <D.12949>:
      return;
      <D.12950>:
      _wapi_thread_abandon_mutexes (handle);
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.12954>; else goto <D.12955>;
      <D.12954>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      return;
      <D.12955>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (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.12956 = __builtin_expect (__not_first_call, 0);
            if (D.12956 != 0) goto <D.12957>; else goto <D.12958>;
            <D.12957>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.12958>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.12959 = thr_ret != 0;
            D.12960 = (long int) D.12959;
            D.12961 = __builtin_expect (D.12960, 0);
            if (D.12961 != 0) goto <D.12962>; else goto <D.12963>;
            <D.12962>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 164, "thr_ret == 0");
            <D.12963>:
            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.12965 = &thread_handle.2->suspend_sem;
            sem_destroy (D.12965);
            thread_handle.2 = thread_handle;
            D.12966 = thread_handle.2->owned_mutexes;
            monoeg_g_ptr_array_free (D.12966, 1);
            _wapi_handle_set_signal_state (handle, 1, 1);
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.12959 = thr_ret != 0;
            D.12960 = (long int) D.12959;
            D.12961 = __builtin_expect (D.12960, 0);
            if (D.12961 != 0) goto <D.12967>; else goto <D.12968>;
            <D.12967>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 174, "thr_ret == 0");
            <D.12968>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.12969>; else goto <D.12970>;
            <D.12969>:
            __cancel_routine (__cancel_arg);
            <D.12970>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      _wapi_handle_unref (handle);
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


_wapi_handle_issignalled (void * handle)
{
  gboolean D.12981;
  <unnamed type> D.12984;
  <unnamed type> D.12986;
  <unnamed type> D.12988;
  <unnamed type> D.12990;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.3;
  unsigned int handle.4;
  unsigned int D.12993;
  struct _WapiHandleUnshared * D.12994;
  unsigned int D.12995;
  unsigned int D.12996;
  struct _WapiHandleUnshared * D.12997;
  unsigned int D.12998;
  unsigned int D.12999;
  struct _WapiHandleUnshared * D.13000;
  unsigned int D.13001;
  unsigned int D.13002;
  struct _WapiHandleUnshared * D.13003;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.12979>; else goto <D.12980>;
  <D.12979>:
  D.12981 = 0;
  return D.12981;
  <D.12980>:
  D.12984 = _wapi_handle_type (handle);
  if (D.12984 == 9) goto <D.12982>; else goto <D.12985>;
  <D.12985>:
  D.12986 = _wapi_handle_type (handle);
  if (D.12986 == 11) goto <D.12982>; else goto <D.12987>;
  <D.12987>:
  D.12988 = _wapi_handle_type (handle);
  if (D.12988 == 12) goto <D.12982>; else goto <D.12989>;
  <D.12989>:
  D.12990 = _wapi_handle_type (handle);
  if (D.12990 == 13) goto <D.12982>; else goto <D.12983>;
  <D.12982>:
  _wapi_shared_layout.3 = _wapi_shared_layout;
  handle.4 = (unsigned int) handle;
  D.12993 = handle.4 / 256;
  D.12994 = _wapi_private_handles[D.12993];
  handle.4 = (unsigned int) handle;
  D.12995 = handle.4 & 255;
  D.12996 = D.12995 * 144;
  D.12997 = D.12994 + D.12996;
  D.12998 = D.12997->u.shared.offset;
  D.12981 = _wapi_shared_layout.3->handles[D.12998].signalled;
  return D.12981;
  <D.12983>:
  D.12999 = idx / 256;
  D.13000 = _wapi_private_handles[D.12999];
  D.13001 = idx & 255;
  D.13002 = D.13001 * 144;
  D.13003 = D.13000 + D.13002;
  D.12981 = D.13003->signalled;
  return D.12981;
}


_wapi_handle_type (void * handle)
{
  unsigned int D.13009;
  struct _WapiHandleUnshared * D.13010;
  WapiHandleType D.13011;
  unsigned int D.13012;
  unsigned int D.13013;
  struct _WapiHandleUnshared * D.13014;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.13005>; else goto <D.13007>;
  <D.13007>:
  if (idx > 268435455) goto <D.13005>; else goto <D.13008>;
  <D.13008>:
  D.13009 = idx / 256;
  D.13010 = _wapi_private_handles[D.13009];
  if (D.13010 == 0B) goto <D.13005>; else goto <D.13006>;
  <D.13005>:
  D.13011 = 0;
  return D.13011;
  <D.13006>:
  D.13009 = idx / 256;
  D.13010 = _wapi_private_handles[D.13009];
  D.13012 = idx & 255;
  D.13013 = D.13012 * 144;
  D.13014 = D.13010 + D.13013;
  D.13011 = D.13014->type;
  return D.13011;
}


_wapi_thread_abandon_mutexes (void * handle)
{
  long unsigned int D.13018;
  struct _WapiHandle_thread * thread_handle.5;
  long unsigned int D.13024;
  int D.13025;
  struct GPtrArray * D.13028;
  void * * D.13029;
  unsigned int i.6;
  unsigned int D.13031;
  void * * D.13032;
  unsigned int i.7;
  unsigned int D.13034;
  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.13016>; else goto <D.13017>;
      <D.13016>:
      D.13018 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.13018);
      if (handle == 0B) goto <D.13019>; else goto <D.13020>;
      <D.13019>:
      return;
      <D.13020>:
      <D.13017>:
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.13021>; else goto <D.13022>;
      <D.13021>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      return;
      <D.13022>:
      thread_handle.5 = thread_handle;
      D.13024 = thread_handle.5->id;
      D.13025 = pthread_equal (D.13024, tid);
      if (D.13025 == 0) goto <D.13026>; else goto <D.13027>;
      <D.13026>:
      return;
      <D.13027>:
      i = 0;
      goto <D.12675>;
      <D.12674>:
      {
        void * mutex;

        thread_handle.5 = thread_handle;
        D.13028 = thread_handle.5->owned_mutexes;
        D.13029 = D.13028->pdata;
        i.6 = (unsigned int) i;
        D.13031 = i.6 * 4;
        D.13032 = D.13029 + D.13031;
        mutex = *D.13032;
        _wapi_mutex_abandon (mutex, pid, tid);
        _wapi_thread_disown_mutex (mutex);
      }
      i = i + 1;
      <D.12675>:
      i.7 = (unsigned int) i;
      thread_handle.5 = thread_handle;
      D.13028 = thread_handle.5->owned_mutexes;
      D.13034 = D.13028->len;
      if (i.7 < D.13034) goto <D.12674>; else goto <D.12676>;
      <D.12676>:
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


pthread_equal (pthread_t __thread1, pthread_t __thread2)
{
  int D.13038;
  _Bool D.13039;

  D.13039 = __thread1 == __thread2;
  D.13038 = (int) D.13039;
  return D.13038;
}


_wapi_handle_lock_handle (void * handle)
{
  int D.13043;
  <unnamed type> D.13046;
  <unnamed type> D.13048;
  <unnamed type> D.13050;
  <unnamed type> D.13052;
  unsigned int D.13053;
  struct _WapiHandleUnshared * D.13054;
  unsigned int D.13055;
  unsigned int D.13056;
  struct _WapiHandleUnshared * D.13057;
  union mono_mutex_t * D.13058;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.13041>; else goto <D.13042>;
  <D.13041>:
  D.13043 = 0;
  return D.13043;
  <D.13042>:
  _wapi_handle_ref (handle);
  D.13046 = _wapi_handle_type (handle);
  if (D.13046 == 9) goto <D.13044>; else goto <D.13047>;
  <D.13047>:
  D.13048 = _wapi_handle_type (handle);
  if (D.13048 == 11) goto <D.13044>; else goto <D.13049>;
  <D.13049>:
  D.13050 = _wapi_handle_type (handle);
  if (D.13050 == 12) goto <D.13044>; else goto <D.13051>;
  <D.13051>:
  D.13052 = _wapi_handle_type (handle);
  if (D.13052 == 13) goto <D.13044>; else goto <D.13045>;
  <D.13044>:
  D.13043 = 0;
  return D.13043;
  <D.13045>:
  D.13053 = idx / 256;
  D.13054 = _wapi_private_handles[D.13053];
  D.13055 = idx & 255;
  D.13056 = D.13055 * 144;
  D.13057 = D.13054 + D.13056;
  D.13058 = &D.13057->signal_mutex;
  D.13043 = pthread_mutex_lock (D.13058);
  return D.13043;
}


_wapi_handle_set_signal_state (void * handle, gboolean state, gboolean broadcast)
{
  int iftmp.8;
  <unnamed type> D.13066;
  <unnamed type> D.13068;
  <unnamed type> D.13070;
  <unnamed type> D.13072;
  _Bool D.13073;
  long int D.13074;
  long int D.13075;
  unsigned int D.13078;
  struct _WapiHandleUnshared * D.13079;
  unsigned int D.13080;
  unsigned int D.13081;
  long int D.13084;
  union mono_mutex_t * _wapi_global_signal_mutex.9;
  _Bool D.13090;
  long int D.13091;
  long int D.13092;
  union pthread_cond_t * D.13097;
  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.13060>; else goto <D.13061>;
  <D.13060>:
  return;
  <D.13061>:
  D.13066 = _wapi_handle_type (handle);
  if (D.13066 == 9) goto <D.13063>; else goto <D.13067>;
  <D.13067>:
  D.13068 = _wapi_handle_type (handle);
  if (D.13068 == 11) goto <D.13063>; else goto <D.13069>;
  <D.13069>:
  D.13070 = _wapi_handle_type (handle);
  if (D.13070 == 12) goto <D.13063>; else goto <D.13071>;
  <D.13071>:
  D.13072 = _wapi_handle_type (handle);
  if (D.13072 == 13) goto <D.13063>; else goto <D.13064>;
  <D.13063>:
  iftmp.8 = 1;
  goto <D.13065>;
  <D.13064>:
  iftmp.8 = 0;
  <D.13065>:
  D.13073 = iftmp.8 != 0;
  D.13074 = (long int) D.13073;
  D.13075 = __builtin_expect (D.13074, 0);
  if (D.13075 != 0) goto <D.13076>; else goto <D.13077>;
  <D.13076>:
  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.13077>:
  D.13078 = idx / 256;
  D.13079 = _wapi_private_handles[D.13078];
  D.13080 = idx & 255;
  D.13081 = D.13080 * 144;
  handle_data = D.13079 + D.13081;
  if (state == 1) goto <D.13082>; else goto <D.13083>;
  <D.13082>:
  {
    struct __pthread_unwind_buf_t __cancel_buf;
    void (*<Tc3>) (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.13084 = __builtin_expect (__not_first_call, 0);
        if (D.13084 != 0) goto <D.13085>; else goto <D.13086>;
        <D.13085>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.13086>:
        __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.13088>; else goto <D.13089>;
        <D.13088>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.13089>:
        D.13090 = thr_ret != 0;
        D.13091 = (long int) D.13090;
        D.13092 = __builtin_expect (D.13091, 0);
        if (D.13092 != 0) goto <D.13093>; else goto <D.13094>;
        <D.13093>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 151, "thr_ret == 0");
        <D.13094>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.13095>; else goto <D.13096>;
        <D.13095>:
        D.13097 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.13097);
        if (thr_ret != 0) goto <D.13098>; else goto <D.13099>;
        <D.13098>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.13099>:
        D.13090 = thr_ret != 0;
        D.13091 = (long int) D.13090;
        D.13092 = __builtin_expect (D.13091, 0);
        if (D.13092 != 0) goto <D.13100>; else goto <D.13101>;
        <D.13100>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.13101>:
        goto <D.13102>;
        <D.13096>:
        D.13097 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.13097);
        if (thr_ret != 0) goto <D.13103>; else goto <D.13104>;
        <D.13103>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.13104>:
        D.13090 = thr_ret != 0;
        D.13091 = (long int) D.13090;
        D.13092 = __builtin_expect (D.13091, 0);
        if (D.13092 != 0) goto <D.13105>; else goto <D.13106>;
        <D.13105>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.13106>:
        <D.13102>:
        _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.13108>; else goto <D.13109>;
        <D.13108>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.13109>:
        D.13090 = thr_ret != 0;
        D.13091 = (long int) D.13090;
        D.13092 = __builtin_expect (D.13091, 0);
        if (D.13092 != 0) goto <D.13110>; else goto <D.13111>;
        <D.13110>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.13111>:
        _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.13112>; else goto <D.13113>;
        <D.13112>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.13113>:
        D.13090 = thr_ret != 0;
        D.13091 = (long int) D.13090;
        D.13092 = __builtin_expect (D.13091, 0);
        if (D.13092 != 0) goto <D.13114>; else goto <D.13115>;
        <D.13114>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.13115>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.13116>; else goto <D.13117>;
        <D.13116>:
        __cancel_routine (__cancel_arg);
        <D.13117>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.13118>;
  <D.13083>:
  handle_data->signalled = state;
  <D.13118>:
}


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

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


_wapi_handle_unlock_handle (void * handle)
{
  int D.13133;
  <unnamed type> D.13136;
  <unnamed type> D.13138;
  <unnamed type> D.13140;
  <unnamed type> D.13142;
  unsigned int D.13143;
  struct _WapiHandleUnshared * D.13144;
  unsigned int D.13145;
  unsigned int D.13146;
  struct _WapiHandleUnshared * D.13147;
  union mono_mutex_t * D.13148;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.13131>; else goto <D.13132>;
  <D.13131>:
  D.13133 = 0;
  return D.13133;
  <D.13132>:
  D.13136 = _wapi_handle_type (handle);
  if (D.13136 == 9) goto <D.13134>; else goto <D.13137>;
  <D.13137>:
  D.13138 = _wapi_handle_type (handle);
  if (D.13138 == 11) goto <D.13134>; else goto <D.13139>;
  <D.13139>:
  D.13140 = _wapi_handle_type (handle);
  if (D.13140 == 12) goto <D.13134>; else goto <D.13141>;
  <D.13141>:
  D.13142 = _wapi_handle_type (handle);
  if (D.13142 == 13) goto <D.13134>; else goto <D.13135>;
  <D.13134>:
  _wapi_handle_unref (handle);
  D.13133 = 0;
  return D.13133;
  <D.13135>:
  D.13143 = idx / 256;
  D.13144 = _wapi_private_handles[D.13143];
  D.13145 = idx & 255;
  D.13146 = D.13145 * 144;
  D.13147 = D.13144 + D.13146;
  D.13148 = &D.13147->signal_mutex;
  ret = pthread_mutex_unlock (D.13148);
  _wapi_handle_unref (handle);
  D.13133 = ret;
  return D.13133;
}


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

  D.13150 = pthread_self ();
  handle = _wapi_thread_handle_from_id (D.13150);
  if (handle == 0B) goto <D.13151>; else goto <D.13152>;
  <D.13151>:
  return;
  <D.13152>:
  _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.13156;
  struct GPtrArray * D.13157;
  long int D.13160;
  _Bool D.13163;
  long int D.13164;
  long int D.13165;
  struct _WapiHandle_thread * thread_handle_p.11;
  union MonoSemType * D.13179;
  pthread_t * D.13180;
  char * D.13183;
  long unsigned int D.13186;
  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.13154>; else goto <D.13155>;
      <D.13154>:
      D.13156 = 0B;
      return D.13156;
      <D.13155>:
      thread_handle.state = 0;
      D.13157 = monoeg_g_ptr_array_new ();
      thread_handle.owned_mutexes = D.13157;
      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.13158>; else goto <D.13159>;
      <D.13158>:
      monoeg_g_log (0B, 16, "%s: error creating thread handle", &__func__);
      SetLastError (31);
      D.13156 = 0B;
      return D.13156;
      <D.13159>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (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.13160 = __builtin_expect (__not_first_call, 0);
            if (D.13160 != 0) goto <D.13161>; else goto <D.13162>;
            <D.13161>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.13162>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.13163 = thr_ret != 0;
            D.13164 = (long int) D.13163;
            D.13165 = __builtin_expect (D.13164, 0);
            if (D.13165 != 0) goto <D.13166>; else goto <D.13167>;
            <D.13166>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 360, "thr_ret == 0");
            <D.13167>:
            ok = _wapi_lookup_handle (handle, 3, &thread_handle_p);
            if (ok == 0) goto <D.13168>; else goto <D.13169>;
            <D.13168>:
            monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
            SetLastError (31);
            goto cleanup;
            <D.13169>:
            _wapi_handle_ref (handle);
            thr_ret = pthread_attr_init (&attr);
            D.13163 = thr_ret != 0;
            D.13164 = (long int) D.13163;
            D.13165 = __builtin_expect (D.13164, 0);
            if (D.13165 != 0) goto <D.13170>; else goto <D.13171>;
            <D.13170>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 383, "thr_ret == 0");
            <D.13171>:
            if (stacksize == 0) goto <D.13172>; else goto <D.13173>;
            <D.13172>:
            stacksize = 1048576;
            <D.13173>:
            if (stacksize <= 131071) goto <D.13174>; else goto <D.13175>;
            <D.13174>:
            stacksize = 131072;
            <D.13175>:
            thr_ret = pthread_attr_setstacksize (&attr, stacksize);
            D.13163 = thr_ret != 0;
            D.13164 = (long int) D.13163;
            D.13165 = __builtin_expect (D.13164, 0);
            if (D.13165 != 0) goto <D.13176>; else goto <D.13177>;
            <D.13176>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 409, "thr_ret == 0");
            <D.13177>:
            thread_handle_p.11 = thread_handle_p;
            D.13179 = &thread_handle_p.11->suspend_sem;
            sem_init (D.13179, 0, 0);
            thread_handle_p.11 = thread_handle_p;
            thread_handle_p.11->handle = handle;
            thread_handle_p.11 = thread_handle_p;
            D.13180 = &thread_handle_p.11->id;
            thread_handle_p.11 = thread_handle_p;
            ret = mono_threads_pthread_create (D.13180, &attr, thread_start_routine, thread_handle_p.11);
            if (ret != 0) goto <D.13181>; else goto <D.13182>;
            <D.13181>:
            D.13183 = strerror (ret);
            monoeg_g_log (0B, 16, "%s: Error creating native thread handle %s (%d)", &__func__, D.13183, ret);
            SetLastError (31);
            unrefs = 2;
            goto cleanup;
            <D.13182>:
            ct_ret = handle;
            if (tid != 0B) goto <D.13184>; else goto <D.13185>;
            <D.13184>:
            thread_handle_p.11 = thread_handle_p;
            D.13186 = thread_handle_p.11->id;
            *tid = D.13186;
            <D.13185>:
            cleanup:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.13163 = thr_ret != 0;
            D.13164 = (long int) D.13163;
            D.13165 = __builtin_expect (D.13164, 0);
            if (D.13165 != 0) goto <D.13187>; else goto <D.13188>;
            <D.13187>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 448, "thr_ret == 0");
            <D.13188>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.13189>; else goto <D.13190>;
            <D.13189>:
            __cancel_routine (__cancel_arg);
            <D.13190>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      i = 0;
      goto <D.12752>;
      <D.12751>:
      _wapi_handle_unref (handle);
      i = i + 1;
      <D.12752>:
      if (i < unrefs) goto <D.12751>; else goto <D.12753>;
      <D.12753>:
      D.13156 = ct_ret;
      return D.13156;
    }
  finally
    {
      thread_handle = {CLOBBER};
      thread_handle_p = {CLOBBER};
      attr = {CLOBBER};
    }
}


thread_start_routine (void * args)
{
  unsigned int D.13199;
  unsigned int D.13200;
  long unsigned int D.13203;
  _Bool D.13204;
  long int D.13205;
  long int D.13206;
  unsigned int thread_hash_key.12;
  void * D.13210;
  unsigned int D.13213;
  guint32 (*<T156b>) (void *) D.13216;
  void * D.13217;
  unsigned int D.13218;
  struct _WapiHandle_thread * thread;
  int thr_ret;

  thread = args;
  D.13199 = thread->create_flags;
  D.13200 = D.13199 & 268435456;
  if (D.13200 == 0) goto <D.13201>; else goto <D.13202>;
  <D.13201>:
  D.13203 = pthread_self ();
  thr_ret = mono_gc_pthread_detach (D.13203);
  D.13204 = thr_ret != 0;
  D.13205 = (long int) D.13204;
  D.13206 = __builtin_expect (D.13205, 0);
  if (D.13206 != 0) goto <D.13207>; else goto <D.13208>;
  <D.13207>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 259, "thr_ret == 0");
  <D.13208>:
  <D.13202>:
  thread_hash_key.12 = thread_hash_key;
  D.13210 = thread->handle;
  thr_ret = pthread_setspecific (thread_hash_key.12, D.13210);
  if (thr_ret != 0) goto <D.13211>; else goto <D.13212>;
  <D.13211>:
  mono_gc_pthread_exit (0B);
  <D.13212>:
  D.13203 = pthread_self ();
  thread->id = D.13203;
  D.13199 = thread->create_flags;
  D.13213 = D.13199 & 4;
  if (D.13213 != 0) goto <D.13214>; else goto <D.13215>;
  <D.13214>:
  _wapi_thread_suspend (thread);
  <D.13215>:
  D.13216 = thread->start_routine;
  D.13217 = thread->start_arg;
  D.13218 = D.13216 (D.13217);
  D.13210 = thread->handle;
  thread_exit (D.13218, D.13210);
}


_wapi_thread_suspend (struct _WapiHandle_thread * thread)
{
  long unsigned int D.13219;
  long unsigned int D.13220;
  int D.13221;
  _Bool D.13222;
  long int D.13223;
  long int D.13224;
  union MonoSemType * D.13227;
  int D.13228;
  int * D.13230;
  int D.13231;

  D.13219 = thread->id;
  D.13220 = pthread_self ();
  D.13221 = pthread_equal (D.13219, D.13220);
  D.13222 = D.13221 == 0;
  D.13223 = (long int) D.13222;
  D.13224 = __builtin_expect (D.13223, 0);
  if (D.13224 != 0) goto <D.13225>; else goto <D.13226>;
  <D.13225>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 240, "pthread_equal (thread->id, pthread_self ())");
  <D.13226>:
  goto <D.12713>;
  <D.12712>:
  <D.12713>:
  D.13227 = &thread->suspend_sem;
  D.13228 = mono_sem_wait (D.13227, 0);
  if (D.13228 != 0) goto <D.13229>; else goto <D.12714>;
  <D.13229>:
  D.13230 = __errno_location ();
  D.13231 = *D.13230;
  if (D.13231 == 4) goto <D.12712>; else goto <D.12714>;
  <D.12714>:
}


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.13232;
  long int D.13233;
  long int D.13234;
  int thr_ret;

  thr_ret = pthread_key_create (&thread_hash_key, 0B);
  D.13232 = thr_ret != 0;
  D.13233 = (long int) D.13232;
  D.13234 = __builtin_expect (D.13233, 0);
  if (D.13234 != 0) goto <D.13235>; else goto <D.13236>;
  <D.13235>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 231, "thr_ret == 0");
  <D.13236>:
  thr_ret = pthread_key_create (&thread_attached_key, thread_attached_exit);
  D.13232 = thr_ret != 0;
  D.13233 = (long int) D.13232;
  D.13234 = __builtin_expect (D.13233, 0);
  if (D.13234 != 0) goto <D.13237>; else goto <D.13238>;
  <D.13237>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 235, "thr_ret == 0");
  <D.13238>:
}


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


_wapi_thread_handle_from_id (pthread_t tid)
{
  long unsigned int D.13239;
  int D.13240;
  unsigned int thread_hash_key.13;
  void * D.13246;
  void * ret;

  D.13239 = pthread_self ();
  D.13240 = pthread_equal (tid, D.13239);
  if (D.13240 != 0) goto <D.13241>; else goto <D.13242>;
  <D.13241>:
  thread_hash_key.13 = thread_hash_key;
  ret = pthread_getspecific (thread_hash_key.13);
  if (ret != 0B) goto <D.13244>; else goto <D.13245>;
  <D.13244>:
  D.13246 = ret;
  return D.13246;
  <D.13245>:
  <D.13242>:
  D.13246 = 0B;
  return D.13246;
}


OpenThread (guint32 access, gboolean inherit, gsize tid)
{
  void * tid.14;
  void * D.13252;
  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.13248>; else goto <D.13249>;
  <D.13248>:
  tid.14 = (void *) tid;
  ret = _wapi_search_handle (3, find_thread_by_id, tid.14, 0B, 0);
  goto <D.13251>;
  <D.13249>:
  _wapi_handle_ref (ret);
  <D.13251>:
  D.13252 = ret;
  return D.13252;
}


find_thread_by_id (void * handle, void * user_data)
{
  int D.13254;
  gboolean D.13259;
  struct _WapiHandle_thread * thread_handle.15;
  long unsigned int D.13261;
  int D.13262;
  pthread_t tid;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;

  try
    {
      tid = (pthread_t) user_data;
      D.13254 = _wapi_handle_issignalled (handle);
      if (D.13254 == 0) goto <D.13255>; else goto <D.13256>;
      <D.13255>:
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.13257>; else goto <D.13258>;
      <D.13257>:
      D.13259 = 0;
      return D.13259;
      <D.13258>:
      thread_handle.15 = thread_handle;
      D.13261 = thread_handle.15->id;
      D.13262 = pthread_equal (D.13261, tid);
      if (D.13262 != 0) goto <D.13263>; else goto <D.13264>;
      <D.13263>:
      D.13259 = 1;
      return D.13259;
      <D.13264>:
      <D.13256>:
      D.13259 = 0;
      return D.13259;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


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

  D.13267 = pthread_self ();
  thread = _wapi_thread_handle_from_id (D.13267);
  if (thread != 0B) goto <D.13268>; else goto <D.13269>;
  <D.13268>:
  thread_exit (exitcode, thread);
  <D.13269>:
  mono_gc_pthread_exit (0B);
}


GetExitCodeThread (void * handle, guint32 * exitcode)
{
  gboolean D.13272;
  struct _WapiHandle_thread * thread_handle.16;
  unsigned int D.13276;
  unsigned int D.13277;
  unsigned int D.13280;
  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.13270>; else goto <D.13271>;
      <D.13270>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.13272 = 0;
      return D.13272;
      <D.13271>:
      if (exitcode == 0B) goto <D.13273>; else goto <D.13274>;
      <D.13273>:
      D.13272 = 0;
      return D.13272;
      <D.13274>:
      thread_handle.16 = thread_handle;
      D.13276 = BIT_FIELD_REF <*thread_handle.16, 32, 32>;
      D.13277 = D.13276 & 3;
      if (D.13277 != 1) goto <D.13278>; else goto <D.13279>;
      <D.13278>:
      *exitcode = 259;
      D.13272 = 1;
      return D.13272;
      <D.13279>:
      thread_handle.16 = thread_handle;
      D.13280 = thread_handle.16->exitstatus;
      *exitcode = D.13280;
      D.13272 = 1;
      return D.13272;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


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

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


_wapi_thread_duplicate ()
{
  long unsigned int D.13285;
  void * D.13289;
  void * ret;

  ret = 0B;
  mono_once (&thread_hash_once, thread_hash_init);
  mono_once (&thread_ops_once, thread_ops_init);
  D.13285 = pthread_self ();
  ret = _wapi_thread_handle_from_id (D.13285);
  if (ret == 0B) goto <D.13286>; else goto <D.13287>;
  <D.13286>:
  ret = thread_attach (0B);
  goto <D.13288>;
  <D.13287>:
  _wapi_handle_ref (ret);
  <D.13288>:
  D.13289 = ret;
  return D.13289;
}


thread_attach (gsize * tid)
{
  struct GPtrArray * D.13291;
  void * D.13294;
  long int D.13295;
  _Bool D.13298;
  long int D.13299;
  long int D.13300;
  struct _WapiHandle_thread * thread_handle_p.17;
  union MonoSemType * D.13306;
  long unsigned int D.13307;
  unsigned int thread_hash_key.18;
  unsigned int thread_attached_key.19;
  long unsigned int D.13316;
  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.13291 = monoeg_g_ptr_array_new ();
      thread_handle.owned_mutexes = D.13291;
      handle = _wapi_handle_new (3, &thread_handle);
      if (handle == 4294967295B) goto <D.13292>; else goto <D.13293>;
      <D.13292>:
      monoeg_g_log (0B, 16, "%s: error creating thread handle", &__func__);
      SetLastError (31);
      D.13294 = 0B;
      return D.13294;
      <D.13293>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (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.13295 = __builtin_expect (__not_first_call, 0);
            if (D.13295 != 0) goto <D.13296>; else goto <D.13297>;
            <D.13296>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.13297>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.13298 = thr_ret != 0;
            D.13299 = (long int) D.13298;
            D.13300 = __builtin_expect (D.13299, 0);
            if (D.13300 != 0) goto <D.13301>; else goto <D.13302>;
            <D.13301>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 663, "thr_ret == 0");
            <D.13302>:
            ok = _wapi_lookup_handle (handle, 3, &thread_handle_p);
            if (ok == 0) goto <D.13303>; else goto <D.13304>;
            <D.13303>:
            monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
            SetLastError (31);
            goto cleanup;
            <D.13304>:
            _wapi_handle_ref (handle);
            thread_handle_p.17 = thread_handle_p;
            D.13306 = &thread_handle_p.17->suspend_sem;
            sem_init (D.13306, 0, 0);
            thread_handle_p.17 = thread_handle_p;
            thread_handle_p.17->handle = handle;
            thread_handle_p.17 = thread_handle_p;
            D.13307 = pthread_self ();
            thread_handle_p.17->id = D.13307;
            thread_hash_key.18 = thread_hash_key;
            thr_ret = pthread_setspecific (thread_hash_key.18, handle);
            D.13298 = thr_ret != 0;
            D.13299 = (long int) D.13298;
            D.13300 = __builtin_expect (D.13299, 0);
            if (D.13300 != 0) goto <D.13309>; else goto <D.13310>;
            <D.13309>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 688, "thr_ret == 0");
            <D.13310>:
            thread_attached_key.19 = thread_attached_key;
            thr_ret = pthread_setspecific (thread_attached_key.19, handle);
            D.13298 = thr_ret != 0;
            D.13299 = (long int) D.13298;
            D.13300 = __builtin_expect (D.13299, 0);
            if (D.13300 != 0) goto <D.13312>; else goto <D.13313>;
            <D.13312>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 691, "thr_ret == 0");
            <D.13313>:
            if (tid != 0B) goto <D.13314>; else goto <D.13315>;
            <D.13314>:
            thread_handle_p.17 = thread_handle_p;
            D.13316 = thread_handle_p.17->id;
            *tid = D.13316;
            <D.13315>:
            cleanup:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.13298 = thr_ret != 0;
            D.13299 = (long int) D.13298;
            D.13300 = __builtin_expect (D.13299, 0);
            if (D.13300 != 0) goto <D.13317>; else goto <D.13318>;
            <D.13317>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 710, "thr_ret == 0");
            <D.13318>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.13319>; else goto <D.13320>;
            <D.13319>:
            __cancel_routine (__cancel_arg);
            <D.13320>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.13294 = handle;
      return D.13294;
    }
  finally
    {
      thread_handle = {CLOBBER};
      thread_handle_p = {CLOBBER};
    }
}


GetCurrentThread ()
{
  void * D.13328;

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


ResumeThread (void * handle)
{
  guint32 D.13332;
  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.13330>; else goto <D.13331>;
      <D.13330>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.13332 = 4294967295;
      return D.13332;
      <D.13331>:
      thread_handle.20 = thread_handle;
      _wapi_thread_resume (thread_handle.20);
      D.13332 = 4294967295;
      return D.13332;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


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

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


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

  D.13337 = 4294967295;
  return D.13337;
}


SleepEx (guint32 ms, gboolean alertable)
{
  long unsigned int D.13341;
  guint32 D.13344;
  int D.13345;
  unsigned int D.13350;
  unsigned int D.13351;
  int D.13352;
  int D.13355;
  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.13339>; else goto <D.13340>;
      <D.13339>:
      D.13341 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.13341);
      if (current_thread == 0B) goto <D.13342>; else goto <D.13343>;
      <D.13342>:
      SetLastError (6);
      D.13344 = 4294967295;
      return D.13344;
      <D.13343>:
      D.13345 = _wapi_thread_apc_pending (current_thread);
      if (D.13345 != 0) goto <D.13346>; else goto <D.13347>;
      <D.13346>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.13344 = 192;
      return D.13344;
      <D.13347>:
      <D.13340>:
      if (ms == 0) goto <D.13348>; else goto <D.13349>;
      <D.13348>:
      sched_yield ();
      D.13344 = 0;
      return D.13344;
      <D.13349>:
      D.13350 = ms / 1000;
      ms_quot = (int) D.13350;
      D.13351 = ms % 1000;
      ms_rem = (int) D.13351;
      req.tv_sec = ms_quot;
      D.13352 = ms_rem * 1000000;
      req.tv_nsec = D.13352;
      again:
      memset (&rem, 0, 8);
      ret = nanosleep (&req, &rem);
      if (alertable != 0) goto <D.13353>; else goto <D.13354>;
      <D.13353>:
      D.13355 = _wapi_thread_apc_pending (current_thread);
      if (D.13355 != 0) goto <D.13356>; else goto <D.13357>;
      <D.13356>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.13344 = 192;
      return D.13344;
      <D.13357>:
      <D.13354>:
      if (ret == -1) goto <D.13358>; else goto <D.13359>;
      <D.13358>:
      req = rem;
      goto again;
      <D.13359>:
      D.13344 = 0;
      return D.13344;
    }
  finally
    {
      req = {CLOBBER};
      rem = {CLOBBER};
    }
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.13364;
  int D.13369;
  void * D.13371;
  unsigned int D.13372;

  D.13364 = __builtin_constant_p (__len);
  if (D.13364 != 0) goto <D.13365>; else goto <D.13366>;
  <D.13365>:
  if (__len == 0) goto <D.13367>; else goto <D.13368>;
  <D.13367>:
  D.13369 = __builtin_constant_p (__ch);
  if (D.13369 == 0) goto <D.13362>; else goto <D.13370>;
  <D.13370>:
  if (__ch != 0) goto <D.13362>; else goto <D.13363>;
  <D.13362>:
  __warn_memset_zero_len ();
  D.13371 = __dest;
  return D.13371;
  <D.13363>:
  <D.13368>:
  <D.13366>:
  D.13372 = __builtin_object_size (__dest, 0);
  D.13371 = __builtin___memset_chk (__dest, __ch, __len, D.13372);
  return D.13371;
}


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


_wapi_thread_cur_apc_pending ()
{
  long unsigned int D.13374;
  gboolean D.13377;
  void * thread;

  D.13374 = pthread_self ();
  thread = _wapi_thread_handle_from_id (D.13374);
  if (thread == 0B) goto <D.13375>; else goto <D.13376>;
  <D.13375>:
  SetLastError (6);
  D.13377 = 0;
  return D.13377;
  <D.13376>:
  D.13377 = _wapi_thread_apc_pending (thread);
  return D.13377;
}


_wapi_thread_apc_pending (void * handle)
{
  gboolean D.13381;
  int iftmp.21;
  struct _WapiHandle_thread * thread.22;
  unsigned int D.13387;
  unsigned int D.13388;
  void * D.13390;
  struct _WapiHandle_thread * thread;
  gboolean ok;

  try
    {
      ok = _wapi_lookup_handle (handle, 3, &thread);
      if (ok == 0) goto <D.13379>; else goto <D.13380>;
      <D.13379>:
      D.13381 = 0;
      return D.13381;
      <D.13380>:
      thread.22 = thread;
      D.13387 = BIT_FIELD_REF <*thread.22, 32, 32>;
      D.13388 = D.13387 & 8;
      if (D.13388 != 0) goto <D.13383>; else goto <D.13389>;
      <D.13389>:
      thread.22 = thread;
      D.13390 = thread.22->wait_handle;
      if (D.13390 == 4294967294B) goto <D.13383>; else goto <D.13384>;
      <D.13383>:
      iftmp.21 = 1;
      goto <D.13385>;
      <D.13384>:
      iftmp.21 = 0;
      <D.13385>:
      D.13381 = iftmp.21;
      return D.13381;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


_wapi_thread_dispatch_apc_queue (void * handle)
{
  _Bool D.13393;
  long int D.13394;
  long int D.13395;
  struct _WapiHandle_thread * thread.23;
  gboolean D.13399;
  struct _WapiHandle_thread * thread;
  gboolean ok;

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


QueueUserAPC (guint32 (*WapiApcProc) (void *) apc_callback, void * handle, void * param)
{
  guint32 D.13404;
  struct _WapiHandle_thread * thread_handle.24;
  long unsigned int D.13406;
  unsigned int D.13407;
  _Bool D.13408;
  long int D.13409;
  long int D.13410;
  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.13402>; else goto <D.13403>;
      <D.13402>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.13404 = 0;
      return D.13404;
      <D.13403>:
      thread_handle.24 = thread_handle;
      D.13406 = thread_handle.24->id;
      D.13407 = GetCurrentThreadId ();
      D.13408 = D.13406 != D.13407;
      D.13409 = (long int) D.13408;
      D.13410 = __builtin_expect (D.13409, 0);
      if (D.13410 != 0) goto <D.13411>; else goto <D.13412>;
      <D.13411>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 938, "thread_handle->id == (pthread_t)GetCurrentThreadId ()");
      <D.13412>:
      thread_handle.24 = thread_handle;
      thread_handle.24->has_apc = 1;
      D.13404 = 1;
      return D.13404;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


wapi_interrupt_thread (void * thread_handle)
{
  _Bool D.13415;
  long int D.13416;
  long int D.13417;
  struct _WapiHandle_thread * thread.25;
  void * * D.13421;
  unsigned int D.13427;
  struct _WapiHandleUnshared * D.13428;
  unsigned int D.13429;
  unsigned int D.13430;
  struct _WapiHandleUnshared * D.13431;
  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.13415 = ok == 0;
      D.13416 = (long int) D.13415;
      D.13417 = __builtin_expect (D.13416, 0);
      if (D.13417 != 0) goto <D.13418>; else goto <D.13419>;
      <D.13418>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 969, "ok");
      <D.13419>:
      <D.12864>:
      thread.25 = thread;
      wait_handle = thread.25->wait_handle;
      thread.25 = thread;
      D.13421 = &thread.25->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13421, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto <D.13422>; else goto <D.13423>;
      <D.13422>:
      return;
      <D.13423>:
      if (prev_handle == wait_handle) goto <D.12863>; else goto <D.13424>;
      <D.13424>:
      goto <D.12864>;
      <D.12863>:
      if (wait_handle == 0B) goto <D.13425>; else goto <D.13426>;
      <D.13425>:
      return;
      <D.13426>:
      idx = (guint32) wait_handle;
      D.13427 = idx / 256;
      D.13428 = _wapi_private_handles[D.13427];
      D.13429 = idx & 255;
      D.13430 = D.13429 * 144;
      D.13431 = D.13428 + D.13430;
      cond = &D.13431->signal_cond;
      D.13427 = idx / 256;
      D.13428 = _wapi_private_handles[D.13427];
      D.13429 = idx & 255;
      D.13430 = D.13429 * 144;
      D.13431 = D.13428 + D.13430;
      mutex = &D.13431->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.13435;
  unsigned int comp.26;
  unsigned int exch.27;
  unsigned int D.13438;

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


wapi_prepare_interrupt_thread (void * thread_handle)
{
  _Bool D.13440;
  long int D.13441;
  long int D.13442;
  struct _WapiHandle_thread * thread.28;
  void * * D.13446;
  void * D.13449;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * wait_handle;

  try
    {
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13440 = ok == 0;
      D.13441 = (long int) D.13440;
      D.13442 = __builtin_expect (D.13441, 0);
      if (D.13442 != 0) goto <D.13443>; else goto <D.13444>;
      <D.13443>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1023, "ok");
      <D.13444>:
      <D.12873>:
      thread.28 = thread;
      wait_handle = thread.28->wait_handle;
      thread.28 = thread;
      D.13446 = &thread.28->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13446, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto <D.13447>; else goto <D.13448>;
      <D.13447>:
      D.13449 = 0B;
      return D.13449;
      <D.13448>:
      if (prev_handle == wait_handle) goto <D.12872>; else goto <D.13450>;
      <D.13450>:
      goto <D.12873>;
      <D.12872>:
      D.13449 = wait_handle;
      return D.13449;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_finish_interrupt_thread (void * wait_handle)
{
  unsigned int D.13455;
  struct _WapiHandleUnshared * D.13456;
  unsigned int D.13457;
  unsigned int D.13458;
  struct _WapiHandleUnshared * D.13459;
  union pthread_cond_t * cond;
  union mono_mutex_t * mutex;
  guint32 idx;

  if (wait_handle == 0B) goto <D.13453>; else goto <D.13454>;
  <D.13453>:
  return;
  <D.13454>:
  idx = (guint32) wait_handle;
  D.13455 = idx / 256;
  D.13456 = _wapi_private_handles[D.13455];
  D.13457 = idx & 255;
  D.13458 = D.13457 * 144;
  D.13459 = D.13456 + D.13458;
  cond = &D.13459->signal_cond;
  D.13455 = idx / 256;
  D.13456 = _wapi_private_handles[D.13455];
  D.13457 = idx & 255;
  D.13458 = D.13457 * 144;
  D.13459 = D.13456 + D.13458;
  mutex = &D.13459->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.13461;
  _Bool D.13462;
  long int D.13463;
  long int D.13464;
  struct _WapiHandle_thread * thread.29;
  void * * D.13468;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * wait_handle;
  void * thread_handle;
  void cleanup = <<< error >>>;

  try
    {
      D.13461 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13461);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13462 = ok == 0;
      D.13463 = (long int) D.13462;
      D.13464 = __builtin_expect (D.13463, 0);
      if (D.13464 != 0) goto <D.13465>; else goto <D.13466>;
      <D.13465>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1095, "ok");
      <D.13466>:
      <D.12890>:
      thread.29 = thread;
      wait_handle = thread.29->wait_handle;
      thread.29 = thread;
      D.13468 = &thread.29->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13468, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto cleanup; else goto <D.13469>;
      <D.13469>:
      if (prev_handle == wait_handle) goto <D.12889>; else goto <D.13470>;
      <D.13470>:
      goto <D.12890>;
      <D.12889>:
      if (wait_handle != 0B) goto <D.13471>; else goto <D.13472>;
      <D.13471>:
      _wapi_handle_unref (wait_handle);
      <D.13472>:
      cleanup:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_clear_interruption ()
{
  unsigned int D.13473;
  _Bool D.13474;
  long int D.13475;
  long int D.13476;
  struct _WapiHandle_thread * thread.30;
  void * * D.13480;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.13473 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13473);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13474 = ok == 0;
      D.13475 = (long int) D.13474;
      D.13476 = __builtin_expect (D.13475, 0);
      if (D.13476 != 0) goto <D.13477>; else goto <D.13478>;
      <D.13477>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1142, "ok");
      <D.13478>:
      thread.30 = thread;
      D.13480 = &thread.30->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13480, 0B, 4294967294B);
      if (prev_handle == 4294967294B) goto <D.13481>; else goto <D.13482>;
      <D.13481>:
      <D.13482>:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_current_thread_desc ()
{
  unsigned int D.13483;
  char * D.13486;
  struct _WapiHandle_thread * thread.31;
  <unnamed type> D.13494;
  const char * D.13495;
  struct GPtrArray * D.13496;
  void * * D.13497;
  unsigned int i.32;
  unsigned int D.13499;
  void * * D.13500;
  unsigned int i.33;
  unsigned int D.13505;
  struct _WapiHandle_thread * thread;
  int i;
  gboolean ok;
  void * handle;
  void * thread_handle;
  struct GString * text;
  char * res;

  try
    {
      D.13483 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13483);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      if (ok == 0) goto <D.13484>; else goto <D.13485>;
      <D.13484>:
      D.13486 = monoeg_g_strdup_printf ("thread handle %p state : lookup failure", thread_handle);
      return D.13486;
      <D.13485>:
      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.13488>; else goto <D.13489>;
      <D.13488>:
      monoeg_g_string_append_printf (text, "not waiting");
      goto <D.13490>;
      <D.13489>:
      if (handle == 4294967294B) goto <D.13491>; else goto <D.13492>;
      <D.13491>:
      monoeg_g_string_append_printf (text, "interrupted state");
      goto <D.13493>;
      <D.13492>:
      D.13494 = _wapi_handle_type (handle);
      D.13495 = _wapi_handle_typename[D.13494];
      monoeg_g_string_append_printf (text, "waiting on %p : %s ", handle, D.13495);
      <D.13493>:
      <D.13490>:
      monoeg_g_string_append_printf (text, " owns (");
      i = 0;
      goto <D.12909>;
      <D.12908>:
      {
        void * mutex;

        thread.31 = thread;
        D.13496 = thread.31->owned_mutexes;
        D.13497 = D.13496->pdata;
        i.32 = (unsigned int) i;
        D.13499 = i.32 * 4;
        D.13500 = D.13497 + D.13499;
        mutex = *D.13500;
        if (i > 0) goto <D.13501>; else goto <D.13502>;
        <D.13501>:
        monoeg_g_string_append_printf (text, ", %p", mutex);
        goto <D.13503>;
        <D.13502>:
        monoeg_g_string_append_printf (text, "%p", mutex);
        <D.13503>:
      }
      i = i + 1;
      <D.12909>:
      i.33 = (unsigned int) i;
      thread.31 = thread;
      D.13496 = thread.31->owned_mutexes;
      D.13505 = D.13496->len;
      if (i.33 < D.13505) goto <D.12908>; else goto <D.12910>;
      <D.12910>:
      monoeg_g_string_append_printf (text, ")");
      res = text->str;
      monoeg_g_string_free (text, 0);
      D.13486 = res;
      return D.13486;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_thread_set_wait_handle (void * handle)
{
  unsigned int D.13508;
  _Bool D.13509;
  long int D.13510;
  long int D.13511;
  struct _WapiHandle_thread * thread.34;
  void * * D.13515;
  _Bool D.13519;
  long int D.13520;
  long int D.13521;
  gboolean D.13524;
  _Bool D.13525;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.13508 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13508);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13509 = ok == 0;
      D.13510 = (long int) D.13509;
      D.13511 = __builtin_expect (D.13510, 0);
      if (D.13511 != 0) goto <D.13512>; else goto <D.13513>;
      <D.13512>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1209, "ok");
      <D.13513>:
      thread.34 = thread;
      D.13515 = &thread.34->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13515, handle, 0B);
      _wapi_handle_unref (thread_handle);
      if (prev_handle == 0B) goto <D.13516>; else goto <D.13517>;
      <D.13516>:
      _wapi_handle_ref (handle);
      goto <D.13518>;
      <D.13517>:
      D.13519 = prev_handle != 4294967294B;
      D.13520 = (long int) D.13519;
      D.13521 = __builtin_expect (D.13520, 0);
      if (D.13521 != 0) goto <D.13522>; else goto <D.13523>;
      <D.13522>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1221, "prev_handle == INTERRUPTION_REQUESTED_HANDLE");
      <D.13523>:
      <D.13518>:
      D.13525 = prev_handle == 0B;
      D.13524 = (gboolean) D.13525;
      return D.13524;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_thread_clear_wait_handle (void * handle)
{
  unsigned int D.13528;
  _Bool D.13529;
  long int D.13530;
  long int D.13531;
  struct _WapiHandle_thread * thread.35;
  void * * D.13535;
  int iftmp.36;
  _Bool D.13544;
  long int D.13545;
  long int D.13546;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.13528 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13528);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13529 = ok == 0;
      D.13530 = (long int) D.13529;
      D.13531 = __builtin_expect (D.13530, 0);
      if (D.13531 != 0) goto <D.13532>; else goto <D.13533>;
      <D.13532>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1243, "ok");
      <D.13533>:
      thread.35 = thread;
      D.13535 = &thread.35->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13535, 0B, handle);
      if (prev_handle == handle) goto <D.13536>; else goto <D.13537>;
      <D.13536>:
      _wapi_handle_unref (handle);
      goto <D.13538>;
      <D.13537>:
      if (prev_handle != 4294967294B) goto <D.13542>; else goto <D.13540>;
      <D.13542>:
      if (prev_handle != 0B) goto <D.13543>; else goto <D.13540>;
      <D.13543>:
      iftmp.36 = 1;
      goto <D.13541>;
      <D.13540>:
      iftmp.36 = 0;
      <D.13541>:
      D.13544 = iftmp.36 != 0;
      D.13545 = (long int) D.13544;
      D.13546 = __builtin_expect (D.13545, 0);
      if (D.13546 != 0) goto <D.13547>; else goto <D.13548>;
      <D.13547>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1253, "prev_handle == INTERRUPTION_REQUESTED_HANDLE || prev_handle == NULL");
      <D.13548>:
      <D.13538>:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


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

  try
    {
      D.13549 = pthread_self ();
      thread = _wapi_thread_handle_from_id (D.13549);
      if (thread == 0B) goto <D.13550>; else goto <D.13551>;
      <D.13550>:
      monoeg_g_log (0B, 16, "%s: error looking up thread by ID", &__func__);
      return;
      <D.13551>:
      ok = _wapi_lookup_handle (thread, 3, &thread_handle);
      if (ok == 0) goto <D.13552>; else goto <D.13553>;
      <D.13552>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, thread);
      return;
      <D.13553>:
      _wapi_handle_ref (mutex);
      thread_handle.37 = thread_handle;
      D.13555 = thread_handle.37->owned_mutexes;
      monoeg_g_ptr_array_add (D.13555, mutex);
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


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

  try
    {
      D.13559 = pthread_self ();
      thread = _wapi_thread_handle_from_id (D.13559);
      if (thread == 0B) goto <D.13560>; else goto <D.13561>;
      <D.13560>:
      monoeg_g_log (0B, 16, "%s: error looking up thread by ID", &__func__);
      return;
      <D.13561>:
      ok = _wapi_lookup_handle (thread, 3, &thread_handle);
      if (ok == 0) goto <D.13562>; else goto <D.13563>;
      <D.13562>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, thread);
      return;
      <D.13563>:
      _wapi_handle_unref (mutex);
      thread_handle.38 = thread_handle;
      D.13565 = thread_handle.38->owned_mutexes;
      monoeg_g_ptr_array_remove (D.13565, mutex);
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


