sema_own (void * handle)
{
  gboolean D.11790;
  struct _WapiHandle_sem * sem_handle.0;
  unsigned int D.11792;
  unsigned int D.11793;
  struct _WapiHandle_sem * sem_handle;
  gboolean ok;
  static const char __func__[9] = "sema_own";

  try
    {
      ok = _wapi_lookup_handle (handle, 4, &sem_handle);
      if (ok == 0) goto <D.11788>; else goto <D.11789>;
      <D.11788>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.11790 = 0;
      return D.11790;
      <D.11789>:
      sem_handle.0 = sem_handle;
      D.11792 = sem_handle.0->val;
      D.11793 = D.11792 + 4294967295;
      sem_handle.0->val = D.11793;
      sem_handle.0 = sem_handle;
      D.11792 = sem_handle.0->val;
      if (D.11792 == 0) goto <D.11794>; else goto <D.11795>;
      <D.11794>:
      _wapi_handle_set_signal_state (handle, 0, 0);
      <D.11795>:
      D.11790 = 1;
      return D.11790;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_set_signal_state (void * handle, gboolean state, gboolean broadcast)
{
  int iftmp.1;
  <unnamed type> D.11804;
  <unnamed type> D.11806;
  <unnamed type> D.11808;
  <unnamed type> D.11810;
  _Bool D.11811;
  long int D.11812;
  long int D.11813;
  unsigned int D.11816;
  struct _WapiHandleUnshared * D.11817;
  unsigned int D.11818;
  unsigned int D.11819;
  long int D.11822;
  union mono_mutex_t * _wapi_global_signal_mutex.2;
  _Bool D.11828;
  long int D.11829;
  long int D.11830;
  union pthread_cond_t * D.11835;
  union pthread_cond_t * _wapi_global_signal_cond.3;
  guint32 idx;
  struct _WapiHandleUnshared * handle_data;
  int thr_ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11798>; else goto <D.11799>;
  <D.11798>:
  return;
  <D.11799>:
  D.11804 = _wapi_handle_type (handle);
  if (D.11804 == 9) goto <D.11801>; else goto <D.11805>;
  <D.11805>:
  D.11806 = _wapi_handle_type (handle);
  if (D.11806 == 11) goto <D.11801>; else goto <D.11807>;
  <D.11807>:
  D.11808 = _wapi_handle_type (handle);
  if (D.11808 == 12) goto <D.11801>; else goto <D.11809>;
  <D.11809>:
  D.11810 = _wapi_handle_type (handle);
  if (D.11810 == 13) goto <D.11801>; else goto <D.11802>;
  <D.11801>:
  iftmp.1 = 1;
  goto <D.11803>;
  <D.11802>:
  iftmp.1 = 0;
  <D.11803>:
  D.11811 = iftmp.1 != 0;
  D.11812 = (long int) D.11811;
  D.11813 = __builtin_expect (D.11812, 0);
  if (D.11813 != 0) goto <D.11814>; else goto <D.11815>;
  <D.11814>:
  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.11815>:
  D.11816 = idx / 256;
  D.11817 = _wapi_private_handles[D.11816];
  D.11818 = idx & 255;
  D.11819 = D.11818 * 144;
  handle_data = D.11817 + D.11819;
  if (state == 1) goto <D.11820>; else goto <D.11821>;
  <D.11820>:
  {
    struct __pthread_unwind_buf_t __cancel_buf;
    void (*<Tc1>) (void *) __cancel_routine;
    void * __cancel_arg;
    int __not_first_call;

    try
      {
        __cancel_routine = mono_mutex_unlock_in_cleanup;
        __cancel_arg = _wapi_global_signal_mutex;
        __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
        D.11822 = __builtin_expect (__not_first_call, 0);
        if (D.11822 != 0) goto <D.11823>; else goto <D.11824>;
        <D.11823>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.11824>:
        __pthread_register_cancel (&__cancel_buf);
        _wapi_global_signal_mutex.2 = _wapi_global_signal_mutex;
        thr_ret = pthread_mutex_lock (_wapi_global_signal_mutex.2);
        if (thr_ret != 0) goto <D.11826>; else goto <D.11827>;
        <D.11826>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.11827>:
        D.11828 = thr_ret != 0;
        D.11829 = (long int) D.11828;
        D.11830 = __builtin_expect (D.11829, 0);
        if (D.11830 != 0) goto <D.11831>; else goto <D.11832>;
        <D.11831>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 151, "thr_ret == 0");
        <D.11832>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.11833>; else goto <D.11834>;
        <D.11833>:
        D.11835 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.11835);
        if (thr_ret != 0) goto <D.11836>; else goto <D.11837>;
        <D.11836>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.11837>:
        D.11828 = thr_ret != 0;
        D.11829 = (long int) D.11828;
        D.11830 = __builtin_expect (D.11829, 0);
        if (D.11830 != 0) goto <D.11838>; else goto <D.11839>;
        <D.11838>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.11839>:
        goto <D.11840>;
        <D.11834>:
        D.11835 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.11835);
        if (thr_ret != 0) goto <D.11841>; else goto <D.11842>;
        <D.11841>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.11842>:
        D.11828 = thr_ret != 0;
        D.11829 = (long int) D.11828;
        D.11830 = __builtin_expect (D.11829, 0);
        if (D.11830 != 0) goto <D.11843>; else goto <D.11844>;
        <D.11843>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.11844>:
        <D.11840>:
        _wapi_global_signal_cond.3 = _wapi_global_signal_cond;
        thr_ret = pthread_cond_broadcast (_wapi_global_signal_cond.3);
        if (thr_ret != 0) goto <D.11846>; else goto <D.11847>;
        <D.11846>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.11847>:
        D.11828 = thr_ret != 0;
        D.11829 = (long int) D.11828;
        D.11830 = __builtin_expect (D.11829, 0);
        if (D.11830 != 0) goto <D.11848>; else goto <D.11849>;
        <D.11848>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.11849>:
        _wapi_global_signal_mutex.2 = _wapi_global_signal_mutex;
        thr_ret = pthread_mutex_unlock (_wapi_global_signal_mutex.2);
        if (thr_ret != 0) goto <D.11850>; else goto <D.11851>;
        <D.11850>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.11851>:
        D.11828 = thr_ret != 0;
        D.11829 = (long int) D.11828;
        D.11830 = __builtin_expect (D.11829, 0);
        if (D.11830 != 0) goto <D.11852>; else goto <D.11853>;
        <D.11852>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.11853>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.11854>; else goto <D.11855>;
        <D.11854>:
        __cancel_routine (__cancel_arg);
        <D.11855>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.11856>;
  <D.11821>:
  handle_data->signalled = state;
  <D.11856>:
}


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

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


_wapi_handle_type (void * handle)
{
  unsigned int D.11872;
  struct _WapiHandleUnshared * D.11873;
  WapiHandleType D.11874;
  unsigned int D.11875;
  unsigned int D.11876;
  struct _WapiHandleUnshared * D.11877;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11869>; else goto <D.11871>;
  <D.11871>:
  D.11872 = idx / 256;
  D.11873 = _wapi_private_handles[D.11872];
  if (D.11873 == 0B) goto <D.11869>; else goto <D.11870>;
  <D.11869>:
  D.11874 = 0;
  return D.11874;
  <D.11870>:
  D.11872 = idx / 256;
  D.11873 = _wapi_private_handles[D.11872];
  D.11875 = idx & 255;
  D.11876 = D.11875 * 144;
  D.11877 = D.11873 + D.11876;
  D.11874 = D.11877->type;
  return D.11874;
}


sema_signal (void * handle)
{
  ReleaseSemaphore (handle, 1, 0B);
}


_wapi_sem_details (void * handle_info)
{
  unsigned int D.11879;
  int D.11880;
  struct _WapiHandle_sem * sem;

  sem = handle_info;
  D.11879 = sem->val;
  D.11880 = sem->max;
  monoeg_g_print ("val: %5u, max: %5d", D.11879, D.11880);
}


namedsema_own (void * handle)
{
  gboolean D.11883;
  struct _WapiHandle_namedsem * namedsem_handle.4;
  unsigned int D.11885;
  unsigned int D.11886;
  struct _WapiHandle_namedsem * namedsem_handle;
  gboolean ok;
  static const char __func__[14] = "namedsema_own";

  try
    {
      ok = _wapi_lookup_handle (handle, 12, &namedsem_handle);
      if (ok == 0) goto <D.11881>; else goto <D.11882>;
      <D.11881>:
      monoeg_g_log (0B, 16, "%s: error looking up named sem handle %p", &__func__, handle);
      D.11883 = 0;
      return D.11883;
      <D.11882>:
      namedsem_handle.4 = namedsem_handle;
      D.11885 = namedsem_handle.4->val;
      D.11886 = D.11885 + 4294967295;
      namedsem_handle.4->val = D.11886;
      namedsem_handle.4 = namedsem_handle;
      D.11885 = namedsem_handle.4->val;
      if (D.11885 == 0) goto <D.11887>; else goto <D.11888>;
      <D.11887>:
      _wapi_shared_handle_set_signal_state (handle, 0);
      <D.11888>:
      D.11883 = 1;
      return D.11883;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_shared_handle_set_signal_state (void * handle, gboolean state)
{
  int iftmp.5;
  <unnamed type> D.11896;
  <unnamed type> D.11898;
  <unnamed type> D.11900;
  <unnamed type> D.11902;
  _Bool D.11904;
  long int D.11905;
  long int D.11906;
  unsigned int D.11909;
  struct _WapiHandleUnshared * D.11910;
  unsigned int D.11911;
  unsigned int D.11912;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.6;
  unsigned int D.11914;
  guint32 idx;
  struct _WapiHandleUnshared * handle_data;
  struct _WapiHandle_shared_ref * ref;
  struct _WapiHandleShared * shared_data;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11891>; else goto <D.11892>;
  <D.11891>:
  return;
  <D.11892>:
  D.11896 = _wapi_handle_type (handle);
  if (D.11896 != 9) goto <D.11897>; else goto <D.11894>;
  <D.11897>:
  D.11898 = _wapi_handle_type (handle);
  if (D.11898 != 11) goto <D.11899>; else goto <D.11894>;
  <D.11899>:
  D.11900 = _wapi_handle_type (handle);
  if (D.11900 != 12) goto <D.11901>; else goto <D.11894>;
  <D.11901>:
  D.11902 = _wapi_handle_type (handle);
  if (D.11902 != 13) goto <D.11903>; else goto <D.11894>;
  <D.11903>:
  iftmp.5 = 1;
  goto <D.11895>;
  <D.11894>:
  iftmp.5 = 0;
  <D.11895>:
  D.11904 = iftmp.5 != 0;
  D.11905 = (long int) D.11904;
  D.11906 = __builtin_expect (D.11905, 0);
  if (D.11906 != 0) goto <D.11907>; else goto <D.11908>;
  <D.11907>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 201, "_WAPI_SHARED_HANDLE(_wapi_handle_type (handle))");
  <D.11908>:
  D.11909 = idx / 256;
  D.11910 = _wapi_private_handles[D.11909];
  D.11911 = idx & 255;
  D.11912 = D.11911 * 144;
  handle_data = D.11910 + D.11912;
  ref = &handle_data->u.shared;
  _wapi_shared_layout.6 = _wapi_shared_layout;
  D.11914 = ref->offset;
  shared_data = &_wapi_shared_layout.6->handles[D.11914];
  shared_data->signalled = state;
}


namedsema_signal (void * handle)
{
  ReleaseSemaphore (handle, 1, 0B);
}


CreateSemaphore (struct WapiSecurityAttributes * security, gint32 initial, gint32 max, const gunichar2 * name)
{
  void * D.11918;
  _Bool D.11919;
  _Bool D.11920;
  _Bool D.11921;

  mono_once (&sem_ops_once, sem_ops_init);
  if (max <= 0) goto <D.11916>; else goto <D.11917>;
  <D.11916>:
  SetLastError (87);
  D.11918 = 0B;
  return D.11918;
  <D.11917>:
  D.11919 = initial > max;
  D.11920 = initial < 0;
  D.11921 = D.11919 | D.11920;
  if (D.11921 != 0) goto <D.11922>; else goto <D.11923>;
  <D.11922>:
  SetLastError (87);
  D.11918 = 0B;
  return D.11918;
  <D.11923>:
  if (name == 0B) goto <D.11924>; else goto <D.11925>;
  <D.11924>:
  D.11918 = sem_create (security, initial, max);
  return D.11918;
  <D.11925>:
  D.11918 = namedsem_create (security, initial, max, name);
  return D.11918;
}


sem_ops_init ()
{
  _wapi_handle_register_capabilities (4, 3);
  _wapi_handle_register_capabilities (12, 3);
}


sem_create (struct WapiSecurityAttributes * security, gint32 initial, gint32 max)
{
  unsigned int initial.7;
  void * D.11930;
  long int D.11931;
  _Bool D.11934;
  long int D.11935;
  long int D.11936;
  struct _WapiHandle_sem sem_handle;
  void * handle;
  int thr_ret;
  static const char __func__[11] = "sem_create";

  try
    {
      sem_handle = {};
      SetLastError (0);
      initial.7 = (unsigned int) initial;
      sem_handle.val = initial.7;
      sem_handle.max = max;
      handle = _wapi_handle_new (4, &sem_handle);
      if (handle == 4294967295B) goto <D.11928>; else goto <D.11929>;
      <D.11928>:
      monoeg_g_log (0B, 16, "%s: error creating semaphore handle", &__func__);
      SetLastError (31);
      D.11930 = 0B;
      return D.11930;
      <D.11929>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc1>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.11931 = __builtin_expect (__not_first_call, 0);
            if (D.11931 != 0) goto <D.11932>; else goto <D.11933>;
            <D.11932>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.11933>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.11934 = thr_ret != 0;
            D.11935 = (long int) D.11934;
            D.11936 = __builtin_expect (D.11935, 0);
            if (D.11936 != 0) goto <D.11937>; else goto <D.11938>;
            <D.11937>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 188, "thr_ret == 0");
            <D.11938>:
            if (initial != 0) goto <D.11939>; else goto <D.11940>;
            <D.11939>:
            _wapi_handle_set_signal_state (handle, 1, 0);
            <D.11940>:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.11934 = thr_ret != 0;
            D.11935 = (long int) D.11934;
            D.11936 = __builtin_expect (D.11935, 0);
            if (D.11936 != 0) goto <D.11941>; else goto <D.11942>;
            <D.11941>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 198, "thr_ret == 0");
            <D.11942>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.11943>; else goto <D.11944>;
            <D.11943>:
            __cancel_routine (__cancel_arg);
            <D.11944>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.11930 = handle;
      return D.11930;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  int D.11952;
  <unnamed type> D.11955;
  <unnamed type> D.11957;
  <unnamed type> D.11959;
  <unnamed type> D.11961;
  unsigned int D.11962;
  struct _WapiHandleUnshared * D.11963;
  unsigned int D.11964;
  unsigned int D.11965;
  struct _WapiHandleUnshared * D.11966;
  union mono_mutex_t * D.11967;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11950>; else goto <D.11951>;
  <D.11950>:
  D.11952 = 0;
  return D.11952;
  <D.11951>:
  _wapi_handle_ref (handle);
  D.11955 = _wapi_handle_type (handle);
  if (D.11955 == 9) goto <D.11953>; else goto <D.11956>;
  <D.11956>:
  D.11957 = _wapi_handle_type (handle);
  if (D.11957 == 11) goto <D.11953>; else goto <D.11958>;
  <D.11958>:
  D.11959 = _wapi_handle_type (handle);
  if (D.11959 == 12) goto <D.11953>; else goto <D.11960>;
  <D.11960>:
  D.11961 = _wapi_handle_type (handle);
  if (D.11961 == 13) goto <D.11953>; else goto <D.11954>;
  <D.11953>:
  D.11952 = 0;
  return D.11952;
  <D.11954>:
  D.11962 = idx / 256;
  D.11963 = _wapi_private_handles[D.11962];
  D.11964 = idx & 255;
  D.11965 = D.11964 * 144;
  D.11966 = D.11963 + D.11965;
  D.11967 = &D.11966->signal_mutex;
  D.11952 = pthread_mutex_lock (D.11967);
  return D.11952;
}


_wapi_handle_unlock_handle (void * handle)
{
  int D.11971;
  <unnamed type> D.11974;
  <unnamed type> D.11976;
  <unnamed type> D.11978;
  <unnamed type> D.11980;
  unsigned int D.11981;
  struct _WapiHandleUnshared * D.11982;
  unsigned int D.11983;
  unsigned int D.11984;
  struct _WapiHandleUnshared * D.11985;
  union mono_mutex_t * D.11986;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.11969>; else goto <D.11970>;
  <D.11969>:
  D.11971 = 0;
  return D.11971;
  <D.11970>:
  D.11974 = _wapi_handle_type (handle);
  if (D.11974 == 9) goto <D.11972>; else goto <D.11975>;
  <D.11975>:
  D.11976 = _wapi_handle_type (handle);
  if (D.11976 == 11) goto <D.11972>; else goto <D.11977>;
  <D.11977>:
  D.11978 = _wapi_handle_type (handle);
  if (D.11978 == 12) goto <D.11972>; else goto <D.11979>;
  <D.11979>:
  D.11980 = _wapi_handle_type (handle);
  if (D.11980 == 13) goto <D.11972>; else goto <D.11973>;
  <D.11972>:
  _wapi_handle_unref (handle);
  D.11971 = 0;
  return D.11971;
  <D.11973>:
  D.11981 = idx / 256;
  D.11982 = _wapi_private_handles[D.11981];
  D.11983 = idx & 255;
  D.11984 = D.11983 * 144;
  D.11985 = D.11982 + D.11984;
  D.11986 = &D.11985->signal_mutex;
  ret = pthread_mutex_unlock (D.11986);
  _wapi_handle_unref (handle);
  D.11971 = ret;
  return D.11971;
}


namedsem_create (struct WapiSecurityAttributes * security, gint32 initial, gint32 max, const gunichar2 * name)
{
  _Bool D.11988;
  long int D.11989;
  long int D.11990;
  unsigned int D.11999;
  unsigned int initial.8;
  unsigned int offset.9;
  void * D.12014;
  struct _WapiHandle_namedsem namedsem_handle;
  void * handle;
  gchar * utf8_name;
  int thr_ret;
  void * ret;
  guint32 namelen;
  gint32 offset;
  void cleanup = <<< error >>>;
  static const char __func__[16] = "namedsem_create";

  try
    {
      namedsem_handle = {};
      ret = 0B;
      thr_ret = _wapi_namespace_lock ();
      D.11988 = thr_ret != 0;
      D.11989 = (long int) D.11988;
      D.11990 = __builtin_expect (D.11989, 0);
      if (D.11990 != 0) goto <D.11991>; else goto <D.11992>;
      <D.11991>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 218, "thr_ret == 0");
      <D.11992>:
      SetLastError (0);
      utf8_name = monoeg_g_utf16_to_utf8 (name, -1, 0B, 0B, 0B);
      offset = _wapi_search_handle_namespace (12, utf8_name);
      if (offset == -1) goto <D.11993>; else goto <D.11994>;
      <D.11993>:
      SetLastError (6);
      goto cleanup;
      <D.11994>:
      if (offset != 0) goto <D.11995>; else goto <D.11996>;
      <D.11995>:
      SetLastError (183);
      <D.11996>:
      if (offset == 0) goto <D.11997>; else goto <D.11998>;
      <D.11997>:
      D.11999 = strlen (utf8_name);
      if (D.11999 <= 259) goto <D.12000>; else goto <D.12001>;
      <D.12000>:
      namelen = strlen (utf8_name);
      goto <D.12002>;
      <D.12001>:
      namelen = 260;
      <D.12002>:
      memcpy (&namedsem_handle.sharedns.name, utf8_name, namelen);
      initial.8 = (unsigned int) initial;
      namedsem_handle.val = initial.8;
      namedsem_handle.max = max;
      handle = _wapi_handle_new (12, &namedsem_handle);
      goto <D.12004>;
      <D.11998>:
      offset.9 = (unsigned int) offset;
      handle = _wapi_handle_new_from_offset (12, offset.9, 1);
      <D.12004>:
      if (handle == 4294967295B) goto <D.12006>; else goto <D.12007>;
      <D.12006>:
      monoeg_g_log (0B, 16, "%s: error creating named sem handle", &__func__);
      SetLastError (31);
      goto cleanup;
      <D.12007>:
      ret = handle;
      if (offset == 0) goto <D.12008>; else goto <D.12009>;
      <D.12008>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.11988 = thr_ret != 0;
      D.11989 = (long int) D.11988;
      D.11990 = __builtin_expect (D.11989, 0);
      if (D.11990 != 0) goto <D.12010>; else goto <D.12011>;
      <D.12010>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 283, "thr_ret == 0");
      <D.12011>:
      if (initial != 0) goto <D.12012>; else goto <D.12013>;
      <D.12012>:
      _wapi_shared_handle_set_signal_state (handle, 1);
      <D.12013>:
      _wapi_handle_unlock_shared_handles ();
      <D.12009>:
      cleanup:
      monoeg_g_free (utf8_name);
      _wapi_namespace_unlock (0B);
      D.12014 = ret;
      return D.12014;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_namespace_lock ()
{
  int D.12017;

  D.12017 = _wapi_shm_sem_lock (0);
  return D.12017;
}


memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.12019;
  unsigned int D.12020;

  D.12020 = __builtin_object_size (__dest, 0);
  D.12019 = __builtin___memcpy_chk (__dest, __src, __len, D.12020);
  return D.12019;
}


_wapi_handle_lock_shared_handles ()
{
  int D.12022;

  D.12022 = _wapi_shm_sem_lock (3);
  return D.12022;
}


_wapi_handle_unlock_shared_handles ()
{
  int D.12024;

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


_wapi_namespace_unlock (void * data)
{
  int D.12026;

  D.12026 = _wapi_shm_sem_unlock (0);
  return D.12026;
}


ReleaseSemaphore (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.12030;
  gboolean (*<T204a>) (void *, gint32, gint32 *) D.12031;
  WapiHandleType type;

  if (handle == 0B) goto <D.12028>; else goto <D.12029>;
  <D.12028>:
  SetLastError (6);
  D.12030 = 0;
  return D.12030;
  <D.12029>:
  type = _wapi_handle_type (handle);
  D.12031 = sem_ops[type].release;
  if (D.12031 == 0B) goto <D.12032>; else goto <D.12033>;
  <D.12032>:
  SetLastError (6);
  D.12030 = 0;
  return D.12030;
  <D.12033>:
  D.12031 = sem_ops[type].release;
  D.12030 = D.12031 (handle, count, prevcount);
  return D.12030;
}


namedsem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.12037;
  _Bool D.12038;
  long int D.12039;
  long int D.12040;
  struct _WapiHandle_namedsem * sem_handle.10;
  unsigned int D.12046;
  int D.12047;
  unsigned int count.11;
  unsigned int D.12049;
  int D.12050;
  unsigned int D.12051;
  struct _WapiHandle_namedsem * sem_handle;
  gboolean ok;
  gboolean ret;
  int thr_ret;
  static const char __func__[17] = "namedsem_release";
  void end = <<< error >>>;

  try
    {
      ret = 0;
      ok = _wapi_lookup_handle (handle, 12, &sem_handle);
      if (ok == 0) goto <D.12035>; else goto <D.12036>;
      <D.12035>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.12037 = 0;
      return D.12037;
      <D.12036>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.12038 = thr_ret != 0;
      D.12039 = (long int) D.12038;
      D.12040 = __builtin_expect (D.12039, 0);
      if (D.12040 != 0) goto <D.12041>; else goto <D.12042>;
      <D.12041>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 415, "thr_ret == 0");
      <D.12042>:
      if (prevcount != 0B) goto <D.12043>; else goto <D.12044>;
      <D.12043>:
      sem_handle.10 = sem_handle;
      D.12046 = sem_handle.10->val;
      D.12047 = (int) D.12046;
      *prevcount = D.12047;
      <D.12044>:
      sem_handle.10 = sem_handle;
      D.12046 = sem_handle.10->val;
      count.11 = (unsigned int) count;
      D.12049 = D.12046 + count.11;
      sem_handle.10 = sem_handle;
      D.12050 = sem_handle.10->max;
      D.12051 = (unsigned int) D.12050;
      if (D.12049 > D.12051) goto end; else goto <D.12052>;
      <D.12052>:
      sem_handle.10 = sem_handle;
      sem_handle.10 = sem_handle;
      D.12046 = sem_handle.10->val;
      count.11 = (unsigned int) count;
      D.12049 = D.12046 + count.11;
      sem_handle.10->val = D.12049;
      _wapi_shared_handle_set_signal_state (handle, 1);
      ret = 1;
      end:
      _wapi_handle_unlock_shared_handles ();
      D.12037 = ret;
      return D.12037;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


sem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.12057;
  long int D.12058;
  _Bool D.12061;
  long int D.12062;
  long int D.12063;
  struct _WapiHandle_sem * sem_handle.12;
  unsigned int D.12069;
  int D.12070;
  unsigned int count.13;
  unsigned int D.12072;
  int D.12073;
  unsigned int D.12074;
  struct _WapiHandle_sem * sem_handle;
  gboolean ok;
  gboolean ret;
  int thr_ret;
  static const char __func__[12] = "sem_release";
  void end = <<< error >>>;

  try
    {
      ret = 0;
      ok = _wapi_lookup_handle (handle, 4, &sem_handle);
      if (ok == 0) goto <D.12055>; else goto <D.12056>;
      <D.12055>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.12057 = 0;
      return D.12057;
      <D.12056>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc1>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.12058 = __builtin_expect (__not_first_call, 0);
            if (D.12058 != 0) goto <D.12059>; else goto <D.12060>;
            <D.12059>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.12060>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.12061 = thr_ret != 0;
            D.12062 = (long int) D.12061;
            D.12063 = __builtin_expect (D.12062, 0);
            if (D.12063 != 0) goto <D.12064>; else goto <D.12065>;
            <D.12064>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 364, "thr_ret == 0");
            <D.12065>:
            if (prevcount != 0B) goto <D.12066>; else goto <D.12067>;
            <D.12066>:
            sem_handle.12 = sem_handle;
            D.12069 = sem_handle.12->val;
            D.12070 = (int) D.12069;
            *prevcount = D.12070;
            <D.12067>:
            sem_handle.12 = sem_handle;
            D.12069 = sem_handle.12->val;
            count.13 = (unsigned int) count;
            D.12072 = D.12069 + count.13;
            sem_handle.12 = sem_handle;
            D.12073 = sem_handle.12->max;
            D.12074 = (unsigned int) D.12073;
            if (D.12072 > D.12074) goto end; else goto <D.12075>;
            <D.12075>:
            sem_handle.12 = sem_handle;
            sem_handle.12 = sem_handle;
            D.12069 = sem_handle.12->val;
            count.13 = (unsigned int) count;
            D.12072 = D.12069 + count.13;
            sem_handle.12->val = D.12072;
            _wapi_handle_set_signal_state (handle, 1, 1);
            ret = 1;
            end:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.12061 = thr_ret != 0;
            D.12062 = (long int) D.12061;
            D.12063 = __builtin_expect (D.12062, 0);
            if (D.12063 != 0) goto <D.12076>; else goto <D.12077>;
            <D.12076>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 392, "thr_ret == 0");
            <D.12077>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.12078>; else goto <D.12079>;
            <D.12078>:
            __cancel_routine (__cancel_arg);
            <D.12079>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.12057 = ret;
      return D.12057;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


OpenSemaphore (guint32 access, gboolean inherit, const gunichar2 * name)
{
  _Bool D.12085;
  long int D.12086;
  long int D.12087;
  unsigned int offset.14;
  void * D.12097;
  void * handle;
  gchar * utf8_name;
  int thr_ret;
  void * ret;
  gint32 offset;
  void cleanup = <<< error >>>;
  static const char __func__[14] = "OpenSemaphore";

  ret = 0B;
  mono_once (&sem_ops_once, sem_ops_init);
  thr_ret = _wapi_namespace_lock ();
  D.12085 = thr_ret != 0;
  D.12086 = (long int) D.12085;
  D.12087 = __builtin_expect (D.12086, 0);
  if (D.12087 != 0) goto <D.12088>; else goto <D.12089>;
  <D.12088>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 494, "thr_ret == 0");
  <D.12089>:
  utf8_name = monoeg_g_utf16_to_utf8 (name, -1, 0B, 0B, 0B);
  offset = _wapi_search_handle_namespace (12, utf8_name);
  if (offset == -1) goto <D.12090>; else goto <D.12091>;
  <D.12090>:
  SetLastError (6);
  goto cleanup;
  <D.12091>:
  if (offset == 0) goto <D.12092>; else goto <D.12093>;
  <D.12092>:
  SetLastError (2);
  goto cleanup;
  <D.12093>:
  offset.14 = (unsigned int) offset;
  handle = _wapi_handle_new_from_offset (12, offset.14, 1);
  if (handle == 4294967295B) goto <D.12095>; else goto <D.12096>;
  <D.12095>:
  monoeg_g_log (0B, 16, "%s: error opening named sem handle", &__func__);
  SetLastError (31);
  goto cleanup;
  <D.12096>:
  ret = handle;
  cleanup:
  monoeg_g_free (utf8_name);
  _wapi_namespace_unlock (0B);
  D.12097 = ret;
  return D.12097;
}


