_wapi_thread_cleanup ()
{
  unsigned int thread_hash_key.0;
  _Bool D.12959;
  long int D.12960;
  long int D.12961;
  unsigned int thread_attached_key.1;
  int ret;

  thread_hash_key.0 = thread_hash_key;
  ret = pthread_key_delete (thread_hash_key.0);
  D.12959 = 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", 86, "ret == 0");
  <D.12963>:
  thread_attached_key.1 = thread_attached_key;
  ret = pthread_key_delete (thread_attached_key.1);
  D.12959 = ret != 0;
  D.12960 = (long int) D.12959;
  D.12961 = __builtin_expect (D.12960, 0);
  if (D.12961 != 0) goto <D.12965>; else goto <D.12966>;
  <D.12965>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 89, "ret == 0");
  <D.12966>:
}


_wapi_thread_set_termination_details (void * handle, guint32 exitstatus)
{
  int D.12969;
  <unnamed type> D.12971;
  long int D.12974;
  _Bool D.12977;
  long int D.12978;
  long int D.12979;
  struct _WapiHandle_thread * thread_handle.2;
  union MonoSemType * D.12983;
  struct GPtrArray * D.12984;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;
  int thr_ret;
  static const char __func__[37] = "_wapi_thread_set_termination_details";

  try
    {
      D.12969 = _wapi_handle_issignalled (handle);
      if (D.12969 != 0) goto <D.12967>; else goto <D.12970>;
      <D.12970>:
      D.12971 = _wapi_handle_type (handle);
      if (D.12971 == 0) goto <D.12967>; else goto <D.12968>;
      <D.12967>:
      return;
      <D.12968>:
      _wapi_thread_abandon_mutexes (handle);
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.12972>; else goto <D.12973>;
      <D.12972>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      return;
      <D.12973>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tbf>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.12974 = __builtin_expect (__not_first_call, 0);
            if (D.12974 != 0) goto <D.12975>; else goto <D.12976>;
            <D.12975>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.12976>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.12977 = thr_ret != 0;
            D.12978 = (long int) D.12977;
            D.12979 = __builtin_expect (D.12978, 0);
            if (D.12979 != 0) goto <D.12980>; else goto <D.12981>;
            <D.12980>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 164, "thr_ret == 0");
            <D.12981>:
            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.12983 = &thread_handle.2->suspend_sem;
            sem_destroy (D.12983);
            thread_handle.2 = thread_handle;
            D.12984 = thread_handle.2->owned_mutexes;
            monoeg_g_ptr_array_free (D.12984, 1);
            _wapi_handle_set_signal_state (handle, 1, 1);
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.12977 = thr_ret != 0;
            D.12978 = (long int) D.12977;
            D.12979 = __builtin_expect (D.12978, 0);
            if (D.12979 != 0) goto <D.12985>; else goto <D.12986>;
            <D.12985>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 174, "thr_ret == 0");
            <D.12986>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.12987>; else goto <D.12988>;
            <D.12987>:
            __cancel_routine (__cancel_arg);
            <D.12988>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      _wapi_handle_unref (handle);
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


_wapi_handle_issignalled (void * handle)
{
  gboolean D.12999;
  <unnamed type> D.13002;
  <unnamed type> D.13004;
  <unnamed type> D.13006;
  <unnamed type> D.13008;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.3;
  unsigned int handle.4;
  unsigned int D.13011;
  struct _WapiHandleUnshared * D.13012;
  unsigned int D.13013;
  unsigned int D.13014;
  struct _WapiHandleUnshared * D.13015;
  unsigned int D.13016;
  unsigned int D.13017;
  struct _WapiHandleUnshared * D.13018;
  unsigned int D.13019;
  unsigned int D.13020;
  struct _WapiHandleUnshared * D.13021;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.12997>; else goto <D.12998>;
  <D.12997>:
  D.12999 = 0;
  return D.12999;
  <D.12998>:
  D.13002 = _wapi_handle_type (handle);
  if (D.13002 == 9) goto <D.13000>; else goto <D.13003>;
  <D.13003>:
  D.13004 = _wapi_handle_type (handle);
  if (D.13004 == 11) goto <D.13000>; else goto <D.13005>;
  <D.13005>:
  D.13006 = _wapi_handle_type (handle);
  if (D.13006 == 12) goto <D.13000>; else goto <D.13007>;
  <D.13007>:
  D.13008 = _wapi_handle_type (handle);
  if (D.13008 == 13) goto <D.13000>; else goto <D.13001>;
  <D.13000>:
  _wapi_shared_layout.3 = _wapi_shared_layout;
  handle.4 = (unsigned int) handle;
  D.13011 = handle.4 / 256;
  D.13012 = _wapi_private_handles[D.13011];
  handle.4 = (unsigned int) handle;
  D.13013 = handle.4 & 255;
  D.13014 = D.13013 * 136;
  D.13015 = D.13012 + D.13014;
  D.13016 = D.13015->u.shared.offset;
  D.12999 = _wapi_shared_layout.3->handles[D.13016].signalled;
  return D.12999;
  <D.13001>:
  D.13017 = idx / 256;
  D.13018 = _wapi_private_handles[D.13017];
  D.13019 = idx & 255;
  D.13020 = D.13019 * 136;
  D.13021 = D.13018 + D.13020;
  D.12999 = D.13021->signalled;
  return D.12999;
}


_wapi_handle_type (void * handle)
{
  unsigned int D.13026;
  struct _WapiHandleUnshared * D.13027;
  WapiHandleType D.13028;
  unsigned int D.13029;
  unsigned int D.13030;
  struct _WapiHandleUnshared * D.13031;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.13023>; else goto <D.13025>;
  <D.13025>:
  D.13026 = idx / 256;
  D.13027 = _wapi_private_handles[D.13026];
  if (D.13027 == 0B) goto <D.13023>; else goto <D.13024>;
  <D.13023>:
  D.13028 = 0;
  return D.13028;
  <D.13024>:
  D.13026 = idx / 256;
  D.13027 = _wapi_private_handles[D.13026];
  D.13029 = idx & 255;
  D.13030 = D.13029 * 136;
  D.13031 = D.13027 + D.13030;
  D.13028 = D.13031->type;
  return D.13028;
}


_wapi_thread_abandon_mutexes (void * handle)
{
  long unsigned int D.13035;
  struct _WapiHandle_thread * thread_handle.5;
  long unsigned int D.13041;
  int D.13042;
  struct GPtrArray * D.13045;
  void * * D.13046;
  unsigned int i.6;
  unsigned int D.13048;
  void * * D.13049;
  unsigned int i.7;
  unsigned int D.13051;
  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.13033>; else goto <D.13034>;
      <D.13033>:
      D.13035 = pthread_self ();
      handle = _wapi_thread_handle_from_id (D.13035);
      if (handle == 0B) goto <D.13036>; else goto <D.13037>;
      <D.13036>:
      return;
      <D.13037>:
      <D.13034>:
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.13038>; else goto <D.13039>;
      <D.13038>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      return;
      <D.13039>:
      thread_handle.5 = thread_handle;
      D.13041 = thread_handle.5->id;
      D.13042 = pthread_equal (D.13041, tid);
      if (D.13042 == 0) goto <D.13043>; else goto <D.13044>;
      <D.13043>:
      return;
      <D.13044>:
      i = 0;
      goto <D.12693>;
      <D.12692>:
      {
        void * mutex;

        thread_handle.5 = thread_handle;
        D.13045 = thread_handle.5->owned_mutexes;
        D.13046 = D.13045->pdata;
        i.6 = (unsigned int) i;
        D.13048 = i.6 * 4;
        D.13049 = D.13046 + D.13048;
        mutex = *D.13049;
        _wapi_mutex_abandon (mutex, pid, tid);
        _wapi_thread_disown_mutex (mutex);
      }
      i = i + 1;
      <D.12693>:
      i.7 = (unsigned int) i;
      thread_handle.5 = thread_handle;
      D.13045 = thread_handle.5->owned_mutexes;
      D.13051 = D.13045->len;
      if (i.7 < D.13051) goto <D.12692>; else goto <D.12694>;
      <D.12694>:
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


pthread_equal (pthread_t __thread1, pthread_t __thread2)
{
  int D.13055;
  _Bool D.13056;

  D.13056 = __thread1 == __thread2;
  D.13055 = (int) D.13056;
  return D.13055;
}


_wapi_handle_lock_handle (void * handle)
{
  int D.13060;
  <unnamed type> D.13063;
  <unnamed type> D.13065;
  <unnamed type> D.13067;
  <unnamed type> D.13069;
  unsigned int D.13070;
  struct _WapiHandleUnshared * D.13071;
  unsigned int D.13072;
  unsigned int D.13073;
  struct _WapiHandleUnshared * D.13074;
  union mono_mutex_t * D.13075;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.13058>; else goto <D.13059>;
  <D.13058>:
  D.13060 = 0;
  return D.13060;
  <D.13059>:
  _wapi_handle_ref (handle);
  D.13063 = _wapi_handle_type (handle);
  if (D.13063 == 9) goto <D.13061>; else goto <D.13064>;
  <D.13064>:
  D.13065 = _wapi_handle_type (handle);
  if (D.13065 == 11) goto <D.13061>; else goto <D.13066>;
  <D.13066>:
  D.13067 = _wapi_handle_type (handle);
  if (D.13067 == 12) goto <D.13061>; else goto <D.13068>;
  <D.13068>:
  D.13069 = _wapi_handle_type (handle);
  if (D.13069 == 13) goto <D.13061>; else goto <D.13062>;
  <D.13061>:
  D.13060 = 0;
  return D.13060;
  <D.13062>:
  D.13070 = idx / 256;
  D.13071 = _wapi_private_handles[D.13070];
  D.13072 = idx & 255;
  D.13073 = D.13072 * 136;
  D.13074 = D.13071 + D.13073;
  D.13075 = &D.13074->signal_mutex;
  D.13060 = pthread_mutex_lock (D.13075);
  return D.13060;
}


_wapi_handle_set_signal_state (void * handle, gboolean state, gboolean broadcast)
{
  int iftmp.8;
  <unnamed type> D.13083;
  <unnamed type> D.13085;
  <unnamed type> D.13087;
  <unnamed type> D.13089;
  _Bool D.13090;
  long int D.13091;
  long int D.13092;
  unsigned int D.13095;
  struct _WapiHandleUnshared * D.13096;
  unsigned int D.13097;
  unsigned int D.13098;
  long int D.13101;
  union mono_mutex_t * _wapi_global_signal_mutex.9;
  _Bool D.13107;
  long int D.13108;
  long int D.13109;
  union pthread_cond_t * D.13114;
  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.13077>; else goto <D.13078>;
  <D.13077>:
  return;
  <D.13078>:
  D.13083 = _wapi_handle_type (handle);
  if (D.13083 == 9) goto <D.13080>; else goto <D.13084>;
  <D.13084>:
  D.13085 = _wapi_handle_type (handle);
  if (D.13085 == 11) goto <D.13080>; else goto <D.13086>;
  <D.13086>:
  D.13087 = _wapi_handle_type (handle);
  if (D.13087 == 12) goto <D.13080>; else goto <D.13088>;
  <D.13088>:
  D.13089 = _wapi_handle_type (handle);
  if (D.13089 == 13) goto <D.13080>; else goto <D.13081>;
  <D.13080>:
  iftmp.8 = 1;
  goto <D.13082>;
  <D.13081>:
  iftmp.8 = 0;
  <D.13082>:
  D.13090 = iftmp.8 != 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", 132, "!_WAPI_SHARED_HANDLE(_wapi_handle_type (handle))");
  <D.13094>:
  D.13095 = idx / 256;
  D.13096 = _wapi_private_handles[D.13095];
  D.13097 = idx & 255;
  D.13098 = D.13097 * 136;
  handle_data = D.13096 + D.13098;
  if (state == 1) goto <D.13099>; else goto <D.13100>;
  <D.13099>:
  {
    struct __pthread_unwind_buf_t __cancel_buf;
    void (*<Tbf>) (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.13101 = __builtin_expect (__not_first_call, 0);
        if (D.13101 != 0) goto <D.13102>; else goto <D.13103>;
        <D.13102>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.13103>:
        __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.13105>; else goto <D.13106>;
        <D.13105>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.13106>:
        D.13107 = thr_ret != 0;
        D.13108 = (long int) D.13107;
        D.13109 = __builtin_expect (D.13108, 0);
        if (D.13109 != 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", 151, "thr_ret == 0");
        <D.13111>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.13112>; else goto <D.13113>;
        <D.13112>:
        D.13114 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.13114);
        if (thr_ret != 0) goto <D.13115>; else goto <D.13116>;
        <D.13115>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.13116>:
        D.13107 = thr_ret != 0;
        D.13108 = (long int) D.13107;
        D.13109 = __builtin_expect (D.13108, 0);
        if (D.13109 != 0) goto <D.13117>; else goto <D.13118>;
        <D.13117>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.13118>:
        goto <D.13119>;
        <D.13113>:
        D.13114 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.13114);
        if (thr_ret != 0) goto <D.13120>; else goto <D.13121>;
        <D.13120>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.13121>:
        D.13107 = thr_ret != 0;
        D.13108 = (long int) D.13107;
        D.13109 = __builtin_expect (D.13108, 0);
        if (D.13109 != 0) goto <D.13122>; else goto <D.13123>;
        <D.13122>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.13123>:
        <D.13119>:
        _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.13125>; else goto <D.13126>;
        <D.13125>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.13126>:
        D.13107 = thr_ret != 0;
        D.13108 = (long int) D.13107;
        D.13109 = __builtin_expect (D.13108, 0);
        if (D.13109 != 0) goto <D.13127>; else goto <D.13128>;
        <D.13127>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.13128>:
        _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.13129>; else goto <D.13130>;
        <D.13129>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.13130>:
        D.13107 = thr_ret != 0;
        D.13108 = (long int) D.13107;
        D.13109 = __builtin_expect (D.13108, 0);
        if (D.13109 != 0) goto <D.13131>; else goto <D.13132>;
        <D.13131>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.13132>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.13133>; else goto <D.13134>;
        <D.13133>:
        __cancel_routine (__cancel_arg);
        <D.13134>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.13135>;
  <D.13100>:
  handle_data->signalled = state;
  <D.13135>:
}


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

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


_wapi_handle_unlock_handle (void * handle)
{
  int D.13150;
  <unnamed type> D.13153;
  <unnamed type> D.13155;
  <unnamed type> D.13157;
  <unnamed type> D.13159;
  unsigned int D.13160;
  struct _WapiHandleUnshared * D.13161;
  unsigned int D.13162;
  unsigned int D.13163;
  struct _WapiHandleUnshared * D.13164;
  union mono_mutex_t * D.13165;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.13148>; else goto <D.13149>;
  <D.13148>:
  D.13150 = 0;
  return D.13150;
  <D.13149>:
  D.13153 = _wapi_handle_type (handle);
  if (D.13153 == 9) goto <D.13151>; else goto <D.13154>;
  <D.13154>:
  D.13155 = _wapi_handle_type (handle);
  if (D.13155 == 11) goto <D.13151>; else goto <D.13156>;
  <D.13156>:
  D.13157 = _wapi_handle_type (handle);
  if (D.13157 == 12) goto <D.13151>; else goto <D.13158>;
  <D.13158>:
  D.13159 = _wapi_handle_type (handle);
  if (D.13159 == 13) goto <D.13151>; else goto <D.13152>;
  <D.13151>:
  _wapi_handle_unref (handle);
  D.13150 = 0;
  return D.13150;
  <D.13152>:
  D.13160 = idx / 256;
  D.13161 = _wapi_private_handles[D.13160];
  D.13162 = idx & 255;
  D.13163 = D.13162 * 136;
  D.13164 = D.13161 + D.13163;
  D.13165 = &D.13164->signal_mutex;
  ret = pthread_mutex_unlock (D.13165);
  _wapi_handle_unref (handle);
  D.13150 = ret;
  return D.13150;
}


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

  D.13167 = pthread_self ();
  handle = _wapi_thread_handle_from_id (D.13167);
  if (handle == 0B) goto <D.13168>; else goto <D.13169>;
  <D.13168>:
  return;
  <D.13169>:
  _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.13173;
  struct GPtrArray * D.13174;
  long int D.13177;
  _Bool D.13180;
  long int D.13181;
  long int D.13182;
  struct _WapiHandle_thread * thread_handle_p.11;
  union MonoSemType * D.13196;
  pthread_t * D.13197;
  char * D.13200;
  long unsigned int D.13203;
  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.13171>; else goto <D.13172>;
      <D.13171>:
      D.13173 = 0B;
      return D.13173;
      <D.13172>:
      thread_handle.state = 0;
      D.13174 = monoeg_g_ptr_array_new ();
      thread_handle.owned_mutexes = D.13174;
      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.13175>; else goto <D.13176>;
      <D.13175>:
      monoeg_g_log (0B, 16, "%s: error creating thread handle", &__func__);
      SetLastError (31);
      D.13173 = 0B;
      return D.13173;
      <D.13176>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tbf>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.13177 = __builtin_expect (__not_first_call, 0);
            if (D.13177 != 0) goto <D.13178>; else goto <D.13179>;
            <D.13178>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.13179>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.13180 = thr_ret != 0;
            D.13181 = (long int) D.13180;
            D.13182 = __builtin_expect (D.13181, 0);
            if (D.13182 != 0) goto <D.13183>; else goto <D.13184>;
            <D.13183>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 360, "thr_ret == 0");
            <D.13184>:
            ok = _wapi_lookup_handle (handle, 3, &thread_handle_p);
            if (ok == 0) goto <D.13185>; else goto <D.13186>;
            <D.13185>:
            monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
            SetLastError (31);
            goto cleanup;
            <D.13186>:
            _wapi_handle_ref (handle);
            thr_ret = pthread_attr_init (&attr);
            D.13180 = thr_ret != 0;
            D.13181 = (long int) D.13180;
            D.13182 = __builtin_expect (D.13181, 0);
            if (D.13182 != 0) goto <D.13187>; else goto <D.13188>;
            <D.13187>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 383, "thr_ret == 0");
            <D.13188>:
            if (stacksize == 0) goto <D.13189>; else goto <D.13190>;
            <D.13189>:
            stacksize = 1048576;
            <D.13190>:
            if (stacksize <= 16383) goto <D.13191>; else goto <D.13192>;
            <D.13191>:
            stacksize = 16384;
            <D.13192>:
            thr_ret = pthread_attr_setstacksize (&attr, stacksize);
            D.13180 = thr_ret != 0;
            D.13181 = (long int) D.13180;
            D.13182 = __builtin_expect (D.13181, 0);
            if (D.13182 != 0) goto <D.13193>; else goto <D.13194>;
            <D.13193>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 409, "thr_ret == 0");
            <D.13194>:
            thread_handle_p.11 = thread_handle_p;
            D.13196 = &thread_handle_p.11->suspend_sem;
            sem_init (D.13196, 0, 0);
            thread_handle_p.11 = thread_handle_p;
            thread_handle_p.11->handle = handle;
            thread_handle_p.11 = thread_handle_p;
            thread_handle_p.11 = thread_handle_p;
            D.13197 = &thread_handle_p.11->id;
            ret = mono_threads_pthread_create (D.13197, &attr, thread_start_routine, thread_handle_p.11);
            if (ret != 0) goto <D.13198>; else goto <D.13199>;
            <D.13198>:
            D.13200 = strerror (ret);
            monoeg_g_log (0B, 16, "%s: Error creating native thread handle %s (%d)", &__func__, D.13200, ret);
            SetLastError (31);
            unrefs = 2;
            goto cleanup;
            <D.13199>:
            ct_ret = handle;
            if (tid != 0B) goto <D.13201>; else goto <D.13202>;
            <D.13201>:
            thread_handle_p.11 = thread_handle_p;
            D.13203 = thread_handle_p.11->id;
            *tid = D.13203;
            <D.13202>:
            cleanup:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.13180 = thr_ret != 0;
            D.13181 = (long int) D.13180;
            D.13182 = __builtin_expect (D.13181, 0);
            if (D.13182 != 0) goto <D.13204>; else goto <D.13205>;
            <D.13204>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 448, "thr_ret == 0");
            <D.13205>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.13206>; else goto <D.13207>;
            <D.13206>:
            __cancel_routine (__cancel_arg);
            <D.13207>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      i = 0;
      goto <D.12770>;
      <D.12769>:
      _wapi_handle_unref (handle);
      i = i + 1;
      <D.12770>:
      if (i < unrefs) goto <D.12769>; else goto <D.12771>;
      <D.12771>:
      D.13173 = ct_ret;
      return D.13173;
    }
  finally
    {
      thread_handle = {CLOBBER};
      thread_handle_p = {CLOBBER};
      attr = {CLOBBER};
    }
}


thread_start_routine (void * args)
{
  unsigned int D.13216;
  unsigned int D.13217;
  long unsigned int D.13220;
  _Bool D.13221;
  long int D.13222;
  long int D.13223;
  void * D.13226;
  unsigned int thread_hash_key.12;
  unsigned int D.13230;
  guint32 (*<T1587>) (void *) D.13233;
  void * D.13234;
  unsigned int D.13235;
  struct _WapiHandle_thread * thread;
  int thr_ret;

  thread = args;
  D.13216 = thread->create_flags;
  D.13217 = D.13216 & 268435456;
  if (D.13217 == 0) goto <D.13218>; else goto <D.13219>;
  <D.13218>:
  D.13220 = pthread_self ();
  thr_ret = mono_gc_pthread_detach (D.13220);
  D.13221 = thr_ret != 0;
  D.13222 = (long int) D.13221;
  D.13223 = __builtin_expect (D.13222, 0);
  if (D.13223 != 0) goto <D.13224>; else goto <D.13225>;
  <D.13224>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 259, "thr_ret == 0");
  <D.13225>:
  <D.13219>:
  D.13226 = thread->handle;
  thread_hash_key.12 = thread_hash_key;
  thr_ret = pthread_setspecific (thread_hash_key.12, D.13226);
  if (thr_ret != 0) goto <D.13228>; else goto <D.13229>;
  <D.13228>:
  mono_gc_pthread_exit (0B);
  <D.13229>:
  D.13220 = pthread_self ();
  thread->id = D.13220;
  D.13216 = thread->create_flags;
  D.13230 = D.13216 & 4;
  if (D.13230 != 0) goto <D.13231>; else goto <D.13232>;
  <D.13231>:
  _wapi_thread_suspend (thread);
  <D.13232>:
  D.13226 = thread->handle;
  D.13233 = thread->start_routine;
  D.13234 = thread->start_arg;
  D.13235 = D.13233 (D.13234);
  thread_exit (D.13235, D.13226);
}


_wapi_thread_suspend (struct _WapiHandle_thread * thread)
{
  long unsigned int D.13236;
  long unsigned int D.13237;
  int D.13238;
  _Bool D.13239;
  long int D.13240;
  long int D.13241;
  union MonoSemType * D.13244;
  int D.13245;
  int * D.13247;
  int D.13248;

  D.13236 = pthread_self ();
  D.13237 = thread->id;
  D.13238 = pthread_equal (D.13237, D.13236);
  D.13239 = D.13238 == 0;
  D.13240 = (long int) D.13239;
  D.13241 = __builtin_expect (D.13240, 0);
  if (D.13241 != 0) goto <D.13242>; else goto <D.13243>;
  <D.13242>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 240, "pthread_equal (thread->id, pthread_self ())");
  <D.13243>:
  goto <D.12731>;
  <D.12730>:
  <D.12731>:
  D.13244 = &thread->suspend_sem;
  D.13245 = mono_sem_wait (D.13244, 0);
  if (D.13245 != 0) goto <D.13246>; else goto <D.12732>;
  <D.13246>:
  D.13247 = __errno_location ();
  D.13248 = *D.13247;
  if (D.13248 == 4) goto <D.12730>; else goto <D.12732>;
  <D.12732>:
}


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.13249;
  long int D.13250;
  long int D.13251;
  int thr_ret;

  thr_ret = pthread_key_create (&thread_hash_key, 0B);
  D.13249 = thr_ret != 0;
  D.13250 = (long int) D.13249;
  D.13251 = __builtin_expect (D.13250, 0);
  if (D.13251 != 0) goto <D.13252>; else goto <D.13253>;
  <D.13252>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 231, "thr_ret == 0");
  <D.13253>:
  thr_ret = pthread_key_create (&thread_attached_key, thread_attached_exit);
  D.13249 = thr_ret != 0;
  D.13250 = (long int) D.13249;
  D.13251 = __builtin_expect (D.13250, 0);
  if (D.13251 != 0) goto <D.13254>; else goto <D.13255>;
  <D.13254>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 235, "thr_ret == 0");
  <D.13255>:
}


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


_wapi_thread_handle_from_id (pthread_t tid)
{
  long unsigned int D.13256;
  int D.13257;
  unsigned int thread_hash_key.13;
  void * D.13263;
  void * ret;

  D.13256 = pthread_self ();
  D.13257 = pthread_equal (tid, D.13256);
  if (D.13257 != 0) goto <D.13258>; else goto <D.13259>;
  <D.13258>:
  thread_hash_key.13 = thread_hash_key;
  ret = pthread_getspecific (thread_hash_key.13);
  if (ret != 0B) goto <D.13261>; else goto <D.13262>;
  <D.13261>:
  D.13263 = ret;
  return D.13263;
  <D.13262>:
  <D.13259>:
  D.13263 = 0B;
  return D.13263;
}


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


find_thread_by_id (void * handle, void * user_data)
{
  int D.13271;
  gboolean D.13276;
  struct _WapiHandle_thread * thread_handle.15;
  long unsigned int D.13278;
  int D.13279;
  pthread_t tid;
  struct _WapiHandle_thread * thread_handle;
  gboolean ok;

  try
    {
      tid = (pthread_t) user_data;
      D.13271 = _wapi_handle_issignalled (handle);
      if (D.13271 == 0) goto <D.13272>; else goto <D.13273>;
      <D.13272>:
      ok = _wapi_lookup_handle (handle, 3, &thread_handle);
      if (ok == 0) goto <D.13274>; else goto <D.13275>;
      <D.13274>:
      D.13276 = 0;
      return D.13276;
      <D.13275>:
      thread_handle.15 = thread_handle;
      D.13278 = thread_handle.15->id;
      D.13279 = pthread_equal (D.13278, tid);
      if (D.13279 != 0) goto <D.13280>; else goto <D.13281>;
      <D.13280>:
      D.13276 = 1;
      return D.13276;
      <D.13281>:
      <D.13273>:
      D.13276 = 0;
      return D.13276;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


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

  D.13284 = pthread_self ();
  thread = _wapi_thread_handle_from_id (D.13284);
  if (thread != 0B) goto <D.13285>; else goto <D.13286>;
  <D.13285>:
  thread_exit (exitcode, thread);
  <D.13286>:
  mono_gc_pthread_exit (0B);
}


GetExitCodeThread (void * handle, guint32 * exitcode)
{
  gboolean D.13289;
  struct _WapiHandle_thread * thread_handle.16;
  unsigned char D.13293;
  unsigned char D.13294;
  unsigned int D.13297;
  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.13287>; else goto <D.13288>;
      <D.13287>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.13289 = 0;
      return D.13289;
      <D.13288>:
      if (exitcode == 0B) goto <D.13290>; else goto <D.13291>;
      <D.13290>:
      D.13289 = 0;
      return D.13289;
      <D.13291>:
      thread_handle.16 = thread_handle;
      D.13293 = BIT_FIELD_REF <*thread_handle.16, 8, 32>;
      D.13294 = D.13293 & 3;
      if (D.13294 != 1) goto <D.13295>; else goto <D.13296>;
      <D.13295>:
      *exitcode = 259;
      D.13289 = 1;
      return D.13289;
      <D.13296>:
      thread_handle.16 = thread_handle;
      D.13297 = thread_handle.16->exitstatus;
      *exitcode = D.13297;
      D.13289 = 1;
      return D.13289;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


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

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


_wapi_thread_duplicate ()
{
  long unsigned int D.13302;
  void * D.13306;
  void * ret;

  ret = 0B;
  mono_once (&thread_hash_once, thread_hash_init);
  mono_once (&thread_ops_once, thread_ops_init);
  D.13302 = pthread_self ();
  ret = _wapi_thread_handle_from_id (D.13302);
  if (ret == 0B) goto <D.13303>; else goto <D.13304>;
  <D.13303>:
  ret = thread_attach (0B);
  goto <D.13305>;
  <D.13304>:
  _wapi_handle_ref (ret);
  <D.13305>:
  D.13306 = ret;
  return D.13306;
}


thread_attach (gsize * tid)
{
  struct GPtrArray * D.13308;
  void * D.13311;
  long int D.13312;
  _Bool D.13315;
  long int D.13316;
  long int D.13317;
  struct _WapiHandle_thread * thread_handle_p.17;
  union MonoSemType * D.13323;
  long unsigned int D.13324;
  unsigned int thread_hash_key.18;
  unsigned int thread_attached_key.19;
  long unsigned int D.13333;
  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.13308 = monoeg_g_ptr_array_new ();
      thread_handle.owned_mutexes = D.13308;
      handle = _wapi_handle_new (3, &thread_handle);
      if (handle == 4294967295B) goto <D.13309>; else goto <D.13310>;
      <D.13309>:
      monoeg_g_log (0B, 16, "%s: error creating thread handle", &__func__);
      SetLastError (31);
      D.13311 = 0B;
      return D.13311;
      <D.13310>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tbf>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.13312 = __builtin_expect (__not_first_call, 0);
            if (D.13312 != 0) goto <D.13313>; else goto <D.13314>;
            <D.13313>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.13314>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.13315 = thr_ret != 0;
            D.13316 = (long int) D.13315;
            D.13317 = __builtin_expect (D.13316, 0);
            if (D.13317 != 0) goto <D.13318>; else goto <D.13319>;
            <D.13318>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 663, "thr_ret == 0");
            <D.13319>:
            ok = _wapi_lookup_handle (handle, 3, &thread_handle_p);
            if (ok == 0) goto <D.13320>; else goto <D.13321>;
            <D.13320>:
            monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
            SetLastError (31);
            goto cleanup;
            <D.13321>:
            _wapi_handle_ref (handle);
            thread_handle_p.17 = thread_handle_p;
            D.13323 = &thread_handle_p.17->suspend_sem;
            sem_init (D.13323, 0, 0);
            thread_handle_p.17 = thread_handle_p;
            thread_handle_p.17->handle = handle;
            thread_handle_p.17 = thread_handle_p;
            D.13324 = pthread_self ();
            thread_handle_p.17->id = D.13324;
            thread_hash_key.18 = thread_hash_key;
            thr_ret = pthread_setspecific (thread_hash_key.18, handle);
            D.13315 = thr_ret != 0;
            D.13316 = (long int) D.13315;
            D.13317 = __builtin_expect (D.13316, 0);
            if (D.13317 != 0) goto <D.13326>; else goto <D.13327>;
            <D.13326>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 688, "thr_ret == 0");
            <D.13327>:
            thread_attached_key.19 = thread_attached_key;
            thr_ret = pthread_setspecific (thread_attached_key.19, handle);
            D.13315 = thr_ret != 0;
            D.13316 = (long int) D.13315;
            D.13317 = __builtin_expect (D.13316, 0);
            if (D.13317 != 0) goto <D.13329>; else goto <D.13330>;
            <D.13329>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 691, "thr_ret == 0");
            <D.13330>:
            if (tid != 0B) goto <D.13331>; else goto <D.13332>;
            <D.13331>:
            thread_handle_p.17 = thread_handle_p;
            D.13333 = thread_handle_p.17->id;
            *tid = D.13333;
            <D.13332>:
            cleanup:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.13315 = thr_ret != 0;
            D.13316 = (long int) D.13315;
            D.13317 = __builtin_expect (D.13316, 0);
            if (D.13317 != 0) goto <D.13334>; else goto <D.13335>;
            <D.13334>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 710, "thr_ret == 0");
            <D.13335>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.13336>; else goto <D.13337>;
            <D.13336>:
            __cancel_routine (__cancel_arg);
            <D.13337>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.13311 = handle;
      return D.13311;
    }
  finally
    {
      thread_handle = {CLOBBER};
      thread_handle_p = {CLOBBER};
    }
}


GetCurrentThread ()
{
  void * D.13345;

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


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


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

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


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

  D.13354 = 4294967295;
  return D.13354;
}


SleepEx (guint32 ms, gboolean alertable)
{
  long unsigned int D.13358;
  guint32 D.13361;
  int D.13362;
  unsigned int D.13367;
  unsigned int D.13368;
  int D.13369;
  int D.13372;
  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.13356>; else goto <D.13357>;
      <D.13356>:
      D.13358 = pthread_self ();
      current_thread = _wapi_thread_handle_from_id (D.13358);
      if (current_thread == 0B) goto <D.13359>; else goto <D.13360>;
      <D.13359>:
      SetLastError (6);
      D.13361 = 4294967295;
      return D.13361;
      <D.13360>:
      D.13362 = _wapi_thread_apc_pending (current_thread);
      if (D.13362 != 0) goto <D.13363>; else goto <D.13364>;
      <D.13363>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.13361 = 192;
      return D.13361;
      <D.13364>:
      <D.13357>:
      if (ms == 0) goto <D.13365>; else goto <D.13366>;
      <D.13365>:
      sched_yield ();
      D.13361 = 0;
      return D.13361;
      <D.13366>:
      D.13367 = ms / 1000;
      ms_quot = (int) D.13367;
      D.13368 = ms % 1000;
      ms_rem = (int) D.13368;
      req.tv_sec = ms_quot;
      D.13369 = ms_rem * 1000000;
      req.tv_nsec = D.13369;
      again:
      memset (&rem, 0, 8);
      ret = nanosleep (&req, &rem);
      if (alertable != 0) goto <D.13370>; else goto <D.13371>;
      <D.13370>:
      D.13372 = _wapi_thread_apc_pending (current_thread);
      if (D.13372 != 0) goto <D.13373>; else goto <D.13374>;
      <D.13373>:
      _wapi_thread_dispatch_apc_queue (current_thread);
      D.13361 = 192;
      return D.13361;
      <D.13374>:
      <D.13371>:
      if (ret == -1) goto <D.13375>; else goto <D.13376>;
      <D.13375>:
      req = rem;
      goto again;
      <D.13376>:
      D.13361 = 0;
      return D.13361;
    }
  finally
    {
      req = {CLOBBER};
      rem = {CLOBBER};
    }
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.13381;
  int D.13386;
  void * D.13388;
  unsigned int D.13389;

  D.13381 = __builtin_constant_p (__len);
  if (D.13381 != 0) goto <D.13382>; else goto <D.13383>;
  <D.13382>:
  if (__len == 0) goto <D.13384>; else goto <D.13385>;
  <D.13384>:
  D.13386 = __builtin_constant_p (__ch);
  if (D.13386 == 0) goto <D.13379>; else goto <D.13387>;
  <D.13387>:
  if (__ch != 0) goto <D.13379>; else goto <D.13380>;
  <D.13379>:
  __warn_memset_zero_len ();
  D.13388 = __dest;
  return D.13388;
  <D.13380>:
  <D.13385>:
  <D.13383>:
  D.13389 = __builtin_object_size (__dest, 0);
  D.13388 = __builtin___memset_chk (__dest, __ch, __len, D.13389);
  return D.13388;
}


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


_wapi_thread_cur_apc_pending ()
{
  long unsigned int D.13391;
  gboolean D.13394;
  void * thread;

  D.13391 = pthread_self ();
  thread = _wapi_thread_handle_from_id (D.13391);
  if (thread == 0B) goto <D.13392>; else goto <D.13393>;
  <D.13392>:
  SetLastError (6);
  D.13394 = 0;
  return D.13394;
  <D.13393>:
  D.13394 = _wapi_thread_apc_pending (thread);
  return D.13394;
}


_wapi_thread_apc_pending (void * handle)
{
  gboolean D.13398;
  int iftmp.21;
  struct _WapiHandle_thread * thread.22;
  unsigned char D.13404;
  unsigned char D.13405;
  void * D.13407;
  struct _WapiHandle_thread * thread;
  gboolean ok;

  try
    {
      ok = _wapi_lookup_handle (handle, 3, &thread);
      if (ok == 0) goto <D.13396>; else goto <D.13397>;
      <D.13396>:
      D.13398 = 0;
      return D.13398;
      <D.13397>:
      thread.22 = thread;
      D.13404 = BIT_FIELD_REF <*thread.22, 8, 32>;
      D.13405 = D.13404 & 8;
      if (D.13405 != 0) goto <D.13400>; else goto <D.13406>;
      <D.13406>:
      thread.22 = thread;
      D.13407 = thread.22->wait_handle;
      if (D.13407 == 4294967294B) goto <D.13400>; else goto <D.13401>;
      <D.13400>:
      iftmp.21 = 1;
      goto <D.13402>;
      <D.13401>:
      iftmp.21 = 0;
      <D.13402>:
      D.13398 = iftmp.21;
      return D.13398;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


_wapi_thread_dispatch_apc_queue (void * handle)
{
  _Bool D.13410;
  long int D.13411;
  long int D.13412;
  struct _WapiHandle_thread * thread.23;
  gboolean D.13416;
  struct _WapiHandle_thread * thread;
  gboolean ok;

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


QueueUserAPC (guint32 (*WapiApcProc) (void *) apc_callback, void * handle, void * param)
{
  guint32 D.13421;
  struct _WapiHandle_thread * thread_handle.24;
  long unsigned int D.13423;
  unsigned int D.13424;
  _Bool D.13425;
  long int D.13426;
  long int D.13427;
  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.13419>; else goto <D.13420>;
      <D.13419>:
      monoeg_g_log (0B, 16, "%s: error looking up thread handle %p", &__func__, handle);
      D.13421 = 0;
      return D.13421;
      <D.13420>:
      thread_handle.24 = thread_handle;
      D.13423 = thread_handle.24->id;
      D.13424 = GetCurrentThreadId ();
      D.13425 = D.13423 != D.13424;
      D.13426 = (long int) D.13425;
      D.13427 = __builtin_expect (D.13426, 0);
      if (D.13427 != 0) goto <D.13428>; else goto <D.13429>;
      <D.13428>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 938, "thread_handle->id == (pthread_t)GetCurrentThreadId ()");
      <D.13429>:
      thread_handle.24 = thread_handle;
      thread_handle.24->has_apc = 1;
      D.13421 = 1;
      return D.13421;
    }
  finally
    {
      thread_handle = {CLOBBER};
    }
}


wapi_interrupt_thread (void * thread_handle)
{
  _Bool D.13432;
  long int D.13433;
  long int D.13434;
  struct _WapiHandle_thread * thread.25;
  void * * D.13438;
  unsigned int D.13444;
  struct _WapiHandleUnshared * D.13445;
  unsigned int D.13446;
  unsigned int D.13447;
  struct _WapiHandleUnshared * D.13448;
  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.13432 = ok == 0;
      D.13433 = (long int) D.13432;
      D.13434 = __builtin_expect (D.13433, 0);
      if (D.13434 != 0) goto <D.13435>; else goto <D.13436>;
      <D.13435>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 969, "ok");
      <D.13436>:
      <D.12882>:
      thread.25 = thread;
      wait_handle = thread.25->wait_handle;
      thread.25 = thread;
      D.13438 = &thread.25->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13438, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto <D.13439>; else goto <D.13440>;
      <D.13439>:
      return;
      <D.13440>:
      if (prev_handle == wait_handle) goto <D.12881>; else goto <D.13441>;
      <D.13441>:
      goto <D.12882>;
      <D.12881>:
      if (wait_handle == 0B) goto <D.13442>; else goto <D.13443>;
      <D.13442>:
      return;
      <D.13443>:
      idx = (guint32) wait_handle;
      D.13444 = idx / 256;
      D.13445 = _wapi_private_handles[D.13444];
      D.13446 = idx & 255;
      D.13447 = D.13446 * 136;
      D.13448 = D.13445 + D.13447;
      cond = &D.13448->signal_cond;
      D.13444 = idx / 256;
      D.13445 = _wapi_private_handles[D.13444];
      D.13446 = idx & 255;
      D.13447 = D.13446 * 136;
      D.13448 = D.13445 + D.13447;
      mutex = &D.13448->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.13452;
  unsigned int exch.26;
  unsigned int comp.27;
  unsigned int D.13455;

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


wapi_prepare_interrupt_thread (void * thread_handle)
{
  _Bool D.13457;
  long int D.13458;
  long int D.13459;
  struct _WapiHandle_thread * thread.28;
  void * * D.13463;
  void * D.13466;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * wait_handle;

  try
    {
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13457 = ok == 0;
      D.13458 = (long int) D.13457;
      D.13459 = __builtin_expect (D.13458, 0);
      if (D.13459 != 0) goto <D.13460>; else goto <D.13461>;
      <D.13460>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1023, "ok");
      <D.13461>:
      <D.12891>:
      thread.28 = thread;
      wait_handle = thread.28->wait_handle;
      thread.28 = thread;
      D.13463 = &thread.28->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13463, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto <D.13464>; else goto <D.13465>;
      <D.13464>:
      D.13466 = 0B;
      return D.13466;
      <D.13465>:
      if (prev_handle == wait_handle) goto <D.12890>; else goto <D.13467>;
      <D.13467>:
      goto <D.12891>;
      <D.12890>:
      D.13466 = wait_handle;
      return D.13466;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_finish_interrupt_thread (void * wait_handle)
{
  unsigned int D.13472;
  struct _WapiHandleUnshared * D.13473;
  unsigned int D.13474;
  unsigned int D.13475;
  struct _WapiHandleUnshared * D.13476;
  union pthread_cond_t * cond;
  union mono_mutex_t * mutex;
  guint32 idx;

  if (wait_handle == 0B) goto <D.13470>; else goto <D.13471>;
  <D.13470>:
  return;
  <D.13471>:
  idx = (guint32) wait_handle;
  D.13472 = idx / 256;
  D.13473 = _wapi_private_handles[D.13472];
  D.13474 = idx & 255;
  D.13475 = D.13474 * 136;
  D.13476 = D.13473 + D.13475;
  cond = &D.13476->signal_cond;
  D.13472 = idx / 256;
  D.13473 = _wapi_private_handles[D.13472];
  D.13474 = idx & 255;
  D.13475 = D.13474 * 136;
  D.13476 = D.13473 + D.13475;
  mutex = &D.13476->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.13478;
  _Bool D.13479;
  long int D.13480;
  long int D.13481;
  struct _WapiHandle_thread * thread.29;
  void * * D.13485;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * wait_handle;
  void * thread_handle;
  void cleanup = <<< error >>>;

  try
    {
      D.13478 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13478);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13479 = ok == 0;
      D.13480 = (long int) D.13479;
      D.13481 = __builtin_expect (D.13480, 0);
      if (D.13481 != 0) goto <D.13482>; else goto <D.13483>;
      <D.13482>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1095, "ok");
      <D.13483>:
      <D.12908>:
      thread.29 = thread;
      wait_handle = thread.29->wait_handle;
      thread.29 = thread;
      D.13485 = &thread.29->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13485, 4294967294B, wait_handle);
      if (prev_handle == 4294967294B) goto cleanup; else goto <D.13486>;
      <D.13486>:
      if (prev_handle == wait_handle) goto <D.12907>; else goto <D.13487>;
      <D.13487>:
      goto <D.12908>;
      <D.12907>:
      if (wait_handle != 0B) goto <D.13488>; else goto <D.13489>;
      <D.13488>:
      _wapi_handle_unref (wait_handle);
      <D.13489>:
      cleanup:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_clear_interruption ()
{
  unsigned int D.13490;
  _Bool D.13491;
  long int D.13492;
  long int D.13493;
  struct _WapiHandle_thread * thread.30;
  void * * D.13497;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.13490 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13490);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13491 = ok == 0;
      D.13492 = (long int) D.13491;
      D.13493 = __builtin_expect (D.13492, 0);
      if (D.13493 != 0) goto <D.13494>; else goto <D.13495>;
      <D.13494>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1142, "ok");
      <D.13495>:
      thread.30 = thread;
      D.13497 = &thread.30->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13497, 0B, 4294967294B);
      if (prev_handle == 4294967294B) goto <D.13498>; else goto <D.13499>;
      <D.13498>:
      <D.13499>:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_current_thread_desc ()
{
  unsigned int D.13500;
  char * D.13503;
  struct _WapiHandle_thread * thread.31;
  <unnamed type> D.13511;
  const char * D.13512;
  struct GPtrArray * D.13513;
  void * * D.13514;
  unsigned int i.32;
  unsigned int D.13516;
  void * * D.13517;
  unsigned int i.33;
  unsigned int D.13522;
  struct _WapiHandle_thread * thread;
  int i;
  gboolean ok;
  void * handle;
  void * thread_handle;
  struct GString * text;
  char * res;

  try
    {
      D.13500 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13500);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      if (ok == 0) goto <D.13501>; else goto <D.13502>;
      <D.13501>:
      D.13503 = monoeg_g_strdup_printf ("thread handle %p state : lookup failure", thread_handle);
      return D.13503;
      <D.13502>:
      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.13505>; else goto <D.13506>;
      <D.13505>:
      monoeg_g_string_append_printf (text, "not waiting");
      goto <D.13507>;
      <D.13506>:
      if (handle == 4294967294B) goto <D.13508>; else goto <D.13509>;
      <D.13508>:
      monoeg_g_string_append_printf (text, "interrupted state");
      goto <D.13510>;
      <D.13509>:
      D.13511 = _wapi_handle_type (handle);
      D.13512 = _wapi_handle_typename[D.13511];
      monoeg_g_string_append_printf (text, "waiting on %p : %s ", handle, D.13512);
      <D.13510>:
      <D.13507>:
      monoeg_g_string_append_printf (text, " owns (");
      i = 0;
      goto <D.12927>;
      <D.12926>:
      {
        void * mutex;

        thread.31 = thread;
        D.13513 = thread.31->owned_mutexes;
        D.13514 = D.13513->pdata;
        i.32 = (unsigned int) i;
        D.13516 = i.32 * 4;
        D.13517 = D.13514 + D.13516;
        mutex = *D.13517;
        if (i > 0) goto <D.13518>; else goto <D.13519>;
        <D.13518>:
        monoeg_g_string_append_printf (text, ", %p", mutex);
        goto <D.13520>;
        <D.13519>:
        monoeg_g_string_append_printf (text, "%p", mutex);
        <D.13520>:
      }
      i = i + 1;
      <D.12927>:
      i.33 = (unsigned int) i;
      thread.31 = thread;
      D.13513 = thread.31->owned_mutexes;
      D.13522 = D.13513->len;
      if (i.33 < D.13522) goto <D.12926>; else goto <D.12928>;
      <D.12928>:
      monoeg_g_string_append_printf (text, ")");
      res = text->str;
      monoeg_g_string_free (text, 0);
      D.13503 = res;
      return D.13503;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_thread_set_wait_handle (void * handle)
{
  unsigned int D.13525;
  _Bool D.13526;
  long int D.13527;
  long int D.13528;
  struct _WapiHandle_thread * thread.34;
  void * * D.13532;
  _Bool D.13536;
  long int D.13537;
  long int D.13538;
  gboolean D.13541;
  _Bool D.13542;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.13525 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13525);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13526 = ok == 0;
      D.13527 = (long int) D.13526;
      D.13528 = __builtin_expect (D.13527, 0);
      if (D.13528 != 0) goto <D.13529>; else goto <D.13530>;
      <D.13529>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1209, "ok");
      <D.13530>:
      thread.34 = thread;
      D.13532 = &thread.34->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13532, handle, 0B);
      _wapi_handle_unref (thread_handle);
      if (prev_handle == 0B) goto <D.13533>; else goto <D.13534>;
      <D.13533>:
      _wapi_handle_ref (handle);
      goto <D.13535>;
      <D.13534>:
      D.13536 = prev_handle != 4294967294B;
      D.13537 = (long int) D.13536;
      D.13538 = __builtin_expect (D.13537, 0);
      if (D.13538 != 0) goto <D.13539>; else goto <D.13540>;
      <D.13539>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1221, "prev_handle == INTERRUPTION_REQUESTED_HANDLE");
      <D.13540>:
      <D.13535>:
      D.13542 = prev_handle == 0B;
      D.13541 = (gboolean) D.13542;
      return D.13541;
    }
  finally
    {
      thread = {CLOBBER};
    }
}


wapi_thread_clear_wait_handle (void * handle)
{
  unsigned int D.13545;
  _Bool D.13546;
  long int D.13547;
  long int D.13548;
  struct _WapiHandle_thread * thread.35;
  void * * D.13552;
  _Bool D.13556;
  _Bool D.13557;
  _Bool D.13558;
  int D.13559;
  _Bool D.13560;
  long int D.13561;
  long int D.13562;
  struct _WapiHandle_thread * thread;
  gboolean ok;
  void * prev_handle;
  void * thread_handle;

  try
    {
      D.13545 = GetCurrentThreadId ();
      thread_handle = OpenThread (0, 0, D.13545);
      ok = _wapi_lookup_handle (thread_handle, 3, &thread);
      D.13546 = ok == 0;
      D.13547 = (long int) D.13546;
      D.13548 = __builtin_expect (D.13547, 0);
      if (D.13548 != 0) goto <D.13549>; else goto <D.13550>;
      <D.13549>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1243, "ok");
      <D.13550>:
      thread.35 = thread;
      D.13552 = &thread.35->wait_handle;
      prev_handle = InterlockedCompareExchangePointer (D.13552, 0B, handle);
      if (prev_handle == handle) goto <D.13553>; else goto <D.13554>;
      <D.13553>:
      _wapi_handle_unref (handle);
      goto <D.13555>;
      <D.13554>:
      D.13556 = prev_handle != 4294967294B;
      D.13557 = prev_handle != 0B;
      D.13558 = D.13556 & D.13557;
      D.13559 = (int) D.13558;
      D.13560 = D.13559 != 0;
      D.13561 = (long int) D.13560;
      D.13562 = __builtin_expect (D.13561, 0);
      if (D.13562 != 0) goto <D.13563>; else goto <D.13564>;
      <D.13563>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "wthreads.c", 1253, "prev_handle == INTERRUPTION_REQUESTED_HANDLE || prev_handle == NULL");
      <D.13564>:
      <D.13555>:
      _wapi_handle_unref (thread_handle);
    }
  finally
    {
      thread = {CLOBBER};
    }
}


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

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


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

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


