sema_own (void * handle)
{
  gboolean D.9167;
  struct _WapiHandle_sem * sem_handle.0;
  unsigned int D.9169;
  unsigned int D.9170;
  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.9165>; else goto <D.9166>;
      <D.9165>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9167 = 0;
      return D.9167;
      <D.9166>:
      sem_handle.0 = sem_handle;
      D.9169 = sem_handle.0->val;
      D.9170 = D.9169 + 4294967295;
      sem_handle.0->val = D.9170;
      sem_handle.0 = sem_handle;
      D.9169 = sem_handle.0->val;
      if (D.9169 == 0) goto <D.9171>; else goto <D.9172>;
      <D.9171>:
      _wapi_handle_set_signal_state (handle, 0, 0);
      <D.9172>:
      D.9167 = 1;
      return D.9167;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_set_signal_state (void * handle, gboolean state, gboolean broadcast)
{
  int iftmp.1;
  <unnamed type> D.9181;
  <unnamed type> D.9183;
  <unnamed type> D.9185;
  <unnamed type> D.9187;
  _Bool D.9188;
  long int D.9189;
  long int D.9190;
  unsigned int D.9193;
  struct _WapiHandleUnshared * D.9194;
  unsigned int D.9195;
  unsigned int D.9196;
  long int D.9199;
  union mono_mutex_t * _wapi_global_signal_mutex.2;
  _Bool D.9205;
  long int D.9206;
  long int D.9207;
  union pthread_cond_t * D.9212;
  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.9175>; else goto <D.9176>;
  <D.9175>:
  return;
  <D.9176>:
  D.9181 = _wapi_handle_type (handle);
  if (D.9181 == 9) goto <D.9178>; else goto <D.9182>;
  <D.9182>:
  D.9183 = _wapi_handle_type (handle);
  if (D.9183 == 11) goto <D.9178>; else goto <D.9184>;
  <D.9184>:
  D.9185 = _wapi_handle_type (handle);
  if (D.9185 == 12) goto <D.9178>; else goto <D.9186>;
  <D.9186>:
  D.9187 = _wapi_handle_type (handle);
  if (D.9187 == 13) goto <D.9178>; else goto <D.9179>;
  <D.9178>:
  iftmp.1 = 1;
  goto <D.9180>;
  <D.9179>:
  iftmp.1 = 0;
  <D.9180>:
  D.9188 = iftmp.1 != 0;
  D.9189 = (long int) D.9188;
  D.9190 = __builtin_expect (D.9189, 0);
  if (D.9190 != 0) goto <D.9191>; else goto <D.9192>;
  <D.9191>:
  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.9192>:
  D.9193 = idx / 256;
  D.9194 = _wapi_private_handles[D.9193];
  D.9195 = idx & 255;
  D.9196 = D.9195 * 136;
  handle_data = D.9194 + D.9196;
  if (state == 1) goto <D.9197>; else goto <D.9198>;
  <D.9197>:
  {
    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.9199 = __builtin_expect (__not_first_call, 0);
        if (D.9199 != 0) goto <D.9200>; else goto <D.9201>;
        <D.9200>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.9201>:
        __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.9203>; else goto <D.9204>;
        <D.9203>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.9204>:
        D.9205 = thr_ret != 0;
        D.9206 = (long int) D.9205;
        D.9207 = __builtin_expect (D.9206, 0);
        if (D.9207 != 0) goto <D.9208>; else goto <D.9209>;
        <D.9208>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 151, "thr_ret == 0");
        <D.9209>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.9210>; else goto <D.9211>;
        <D.9210>:
        D.9212 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.9212);
        if (thr_ret != 0) goto <D.9213>; else goto <D.9214>;
        <D.9213>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.9214>:
        D.9205 = thr_ret != 0;
        D.9206 = (long int) D.9205;
        D.9207 = __builtin_expect (D.9206, 0);
        if (D.9207 != 0) goto <D.9215>; else goto <D.9216>;
        <D.9215>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.9216>:
        goto <D.9217>;
        <D.9211>:
        D.9212 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.9212);
        if (thr_ret != 0) goto <D.9218>; else goto <D.9219>;
        <D.9218>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.9219>:
        D.9205 = thr_ret != 0;
        D.9206 = (long int) D.9205;
        D.9207 = __builtin_expect (D.9206, 0);
        if (D.9207 != 0) goto <D.9220>; else goto <D.9221>;
        <D.9220>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.9221>:
        <D.9217>:
        _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.9223>; else goto <D.9224>;
        <D.9223>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.9224>:
        D.9205 = thr_ret != 0;
        D.9206 = (long int) D.9205;
        D.9207 = __builtin_expect (D.9206, 0);
        if (D.9207 != 0) goto <D.9225>; else goto <D.9226>;
        <D.9225>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.9226>:
        _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.9227>; else goto <D.9228>;
        <D.9227>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.9228>:
        D.9205 = thr_ret != 0;
        D.9206 = (long int) D.9205;
        D.9207 = __builtin_expect (D.9206, 0);
        if (D.9207 != 0) goto <D.9229>; else goto <D.9230>;
        <D.9229>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.9230>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.9231>; else goto <D.9232>;
        <D.9231>:
        __cancel_routine (__cancel_arg);
        <D.9232>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.9233>;
  <D.9198>:
  handle_data->signalled = state;
  <D.9233>:
}


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

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


_wapi_handle_type (void * handle)
{
  unsigned int D.9249;
  struct _WapiHandleUnshared * D.9250;
  WapiHandleType D.9251;
  unsigned int D.9252;
  unsigned int D.9253;
  struct _WapiHandleUnshared * D.9254;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9246>; else goto <D.9248>;
  <D.9248>:
  D.9249 = idx / 256;
  D.9250 = _wapi_private_handles[D.9249];
  if (D.9250 == 0B) goto <D.9246>; else goto <D.9247>;
  <D.9246>:
  D.9251 = 0;
  return D.9251;
  <D.9247>:
  D.9249 = idx / 256;
  D.9250 = _wapi_private_handles[D.9249];
  D.9252 = idx & 255;
  D.9253 = D.9252 * 136;
  D.9254 = D.9250 + D.9253;
  D.9251 = D.9254->type;
  return D.9251;
}


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


_wapi_sem_details (void * handle_info)
{
  int D.9256;
  unsigned int D.9257;
  struct _WapiHandle_sem * sem;

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


namedsema_own (void * handle)
{
  gboolean D.9260;
  struct _WapiHandle_namedsem * namedsem_handle.4;
  unsigned int D.9262;
  unsigned int D.9263;
  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.9258>; else goto <D.9259>;
      <D.9258>:
      monoeg_g_log (0B, 16, "%s: error looking up named sem handle %p", &__func__, handle);
      D.9260 = 0;
      return D.9260;
      <D.9259>:
      namedsem_handle.4 = namedsem_handle;
      D.9262 = namedsem_handle.4->val;
      D.9263 = D.9262 + 4294967295;
      namedsem_handle.4->val = D.9263;
      namedsem_handle.4 = namedsem_handle;
      D.9262 = namedsem_handle.4->val;
      if (D.9262 == 0) goto <D.9264>; else goto <D.9265>;
      <D.9264>:
      _wapi_shared_handle_set_signal_state (handle, 0);
      <D.9265>:
      D.9260 = 1;
      return D.9260;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_shared_handle_set_signal_state (void * handle, gboolean state)
{
  int iftmp.5;
  <unnamed type> D.9273;
  <unnamed type> D.9275;
  <unnamed type> D.9277;
  <unnamed type> D.9279;
  _Bool D.9281;
  long int D.9282;
  long int D.9283;
  unsigned int D.9286;
  struct _WapiHandleUnshared * D.9287;
  unsigned int D.9288;
  unsigned int D.9289;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.6;
  unsigned int D.9291;
  guint32 idx;
  struct _WapiHandleUnshared * handle_data;
  struct _WapiHandle_shared_ref * ref;
  struct _WapiHandleShared * shared_data;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9268>; else goto <D.9269>;
  <D.9268>:
  return;
  <D.9269>:
  D.9273 = _wapi_handle_type (handle);
  if (D.9273 != 9) goto <D.9274>; else goto <D.9271>;
  <D.9274>:
  D.9275 = _wapi_handle_type (handle);
  if (D.9275 != 11) goto <D.9276>; else goto <D.9271>;
  <D.9276>:
  D.9277 = _wapi_handle_type (handle);
  if (D.9277 != 12) goto <D.9278>; else goto <D.9271>;
  <D.9278>:
  D.9279 = _wapi_handle_type (handle);
  if (D.9279 != 13) goto <D.9280>; else goto <D.9271>;
  <D.9280>:
  iftmp.5 = 1;
  goto <D.9272>;
  <D.9271>:
  iftmp.5 = 0;
  <D.9272>:
  D.9281 = iftmp.5 != 0;
  D.9282 = (long int) D.9281;
  D.9283 = __builtin_expect (D.9282, 0);
  if (D.9283 != 0) goto <D.9284>; else goto <D.9285>;
  <D.9284>:
  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.9285>:
  D.9286 = idx / 256;
  D.9287 = _wapi_private_handles[D.9286];
  D.9288 = idx & 255;
  D.9289 = D.9288 * 136;
  handle_data = D.9287 + D.9289;
  ref = &handle_data->u.shared;
  _wapi_shared_layout.6 = _wapi_shared_layout;
  D.9291 = ref->offset;
  shared_data = &_wapi_shared_layout.6->handles[D.9291];
  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.9295;
  _Bool D.9296;
  _Bool D.9297;
  _Bool D.9298;

  mono_once (&sem_ops_once, sem_ops_init);
  if (max <= 0) goto <D.9293>; else goto <D.9294>;
  <D.9293>:
  SetLastError (87);
  D.9295 = 0B;
  return D.9295;
  <D.9294>:
  D.9296 = initial > max;
  D.9297 = initial < 0;
  D.9298 = D.9296 | D.9297;
  if (D.9298 != 0) goto <D.9299>; else goto <D.9300>;
  <D.9299>:
  SetLastError (87);
  D.9295 = 0B;
  return D.9295;
  <D.9300>:
  if (name == 0B) goto <D.9301>; else goto <D.9302>;
  <D.9301>:
  D.9295 = sem_create (security, initial, max);
  return D.9295;
  <D.9302>:
  D.9295 = namedsem_create (security, initial, max, name);
  return D.9295;
}


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.9307;
  long int D.9308;
  _Bool D.9311;
  long int D.9312;
  long int D.9313;
  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.9305>; else goto <D.9306>;
      <D.9305>:
      monoeg_g_log (0B, 16, "%s: error creating semaphore handle", &__func__);
      SetLastError (31);
      D.9307 = 0B;
      return D.9307;
      <D.9306>:
      {
        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.9308 = __builtin_expect (__not_first_call, 0);
            if (D.9308 != 0) goto <D.9309>; else goto <D.9310>;
            <D.9309>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9310>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9311 = thr_ret != 0;
            D.9312 = (long int) D.9311;
            D.9313 = __builtin_expect (D.9312, 0);
            if (D.9313 != 0) goto <D.9314>; else goto <D.9315>;
            <D.9314>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 188, "thr_ret == 0");
            <D.9315>:
            if (initial != 0) goto <D.9316>; else goto <D.9317>;
            <D.9316>:
            _wapi_handle_set_signal_state (handle, 1, 0);
            <D.9317>:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9311 = thr_ret != 0;
            D.9312 = (long int) D.9311;
            D.9313 = __builtin_expect (D.9312, 0);
            if (D.9313 != 0) goto <D.9318>; else goto <D.9319>;
            <D.9318>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 198, "thr_ret == 0");
            <D.9319>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9320>; else goto <D.9321>;
            <D.9320>:
            __cancel_routine (__cancel_arg);
            <D.9321>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9307 = handle;
      return D.9307;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  int D.9329;
  <unnamed type> D.9332;
  <unnamed type> D.9334;
  <unnamed type> D.9336;
  <unnamed type> D.9338;
  unsigned int D.9339;
  struct _WapiHandleUnshared * D.9340;
  unsigned int D.9341;
  unsigned int D.9342;
  struct _WapiHandleUnshared * D.9343;
  union mono_mutex_t * D.9344;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9327>; else goto <D.9328>;
  <D.9327>:
  D.9329 = 0;
  return D.9329;
  <D.9328>:
  _wapi_handle_ref (handle);
  D.9332 = _wapi_handle_type (handle);
  if (D.9332 == 9) goto <D.9330>; else goto <D.9333>;
  <D.9333>:
  D.9334 = _wapi_handle_type (handle);
  if (D.9334 == 11) goto <D.9330>; else goto <D.9335>;
  <D.9335>:
  D.9336 = _wapi_handle_type (handle);
  if (D.9336 == 12) goto <D.9330>; else goto <D.9337>;
  <D.9337>:
  D.9338 = _wapi_handle_type (handle);
  if (D.9338 == 13) goto <D.9330>; else goto <D.9331>;
  <D.9330>:
  D.9329 = 0;
  return D.9329;
  <D.9331>:
  D.9339 = idx / 256;
  D.9340 = _wapi_private_handles[D.9339];
  D.9341 = idx & 255;
  D.9342 = D.9341 * 136;
  D.9343 = D.9340 + D.9342;
  D.9344 = &D.9343->signal_mutex;
  D.9329 = pthread_mutex_lock (D.9344);
  return D.9329;
}


_wapi_handle_unlock_handle (void * handle)
{
  int D.9348;
  <unnamed type> D.9351;
  <unnamed type> D.9353;
  <unnamed type> D.9355;
  <unnamed type> D.9357;
  unsigned int D.9358;
  struct _WapiHandleUnshared * D.9359;
  unsigned int D.9360;
  unsigned int D.9361;
  struct _WapiHandleUnshared * D.9362;
  union mono_mutex_t * D.9363;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9346>; else goto <D.9347>;
  <D.9346>:
  D.9348 = 0;
  return D.9348;
  <D.9347>:
  D.9351 = _wapi_handle_type (handle);
  if (D.9351 == 9) goto <D.9349>; else goto <D.9352>;
  <D.9352>:
  D.9353 = _wapi_handle_type (handle);
  if (D.9353 == 11) goto <D.9349>; else goto <D.9354>;
  <D.9354>:
  D.9355 = _wapi_handle_type (handle);
  if (D.9355 == 12) goto <D.9349>; else goto <D.9356>;
  <D.9356>:
  D.9357 = _wapi_handle_type (handle);
  if (D.9357 == 13) goto <D.9349>; else goto <D.9350>;
  <D.9349>:
  _wapi_handle_unref (handle);
  D.9348 = 0;
  return D.9348;
  <D.9350>:
  D.9358 = idx / 256;
  D.9359 = _wapi_private_handles[D.9358];
  D.9360 = idx & 255;
  D.9361 = D.9360 * 136;
  D.9362 = D.9359 + D.9361;
  D.9363 = &D.9362->signal_mutex;
  ret = pthread_mutex_unlock (D.9363);
  _wapi_handle_unref (handle);
  D.9348 = ret;
  return D.9348;
}


namedsem_create (struct WapiSecurityAttributes * security, gint32 initial, gint32 max, const gunichar2 * name)
{
  _Bool D.9365;
  long int D.9366;
  long int D.9367;
  unsigned int D.9376;
  unsigned int initial.8;
  unsigned int offset.9;
  void * D.9391;
  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.9365 = thr_ret != 0;
      D.9366 = (long int) D.9365;
      D.9367 = __builtin_expect (D.9366, 0);
      if (D.9367 != 0) goto <D.9368>; else goto <D.9369>;
      <D.9368>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 218, "thr_ret == 0");
      <D.9369>:
      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.9370>; else goto <D.9371>;
      <D.9370>:
      SetLastError (6);
      goto cleanup;
      <D.9371>:
      if (offset != 0) goto <D.9372>; else goto <D.9373>;
      <D.9372>:
      SetLastError (183);
      <D.9373>:
      if (offset == 0) goto <D.9374>; else goto <D.9375>;
      <D.9374>:
      D.9376 = strlen (utf8_name);
      if (D.9376 <= 259) goto <D.9377>; else goto <D.9378>;
      <D.9377>:
      namelen = strlen (utf8_name);
      goto <D.9379>;
      <D.9378>:
      namelen = 260;
      <D.9379>:
      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.9381>;
      <D.9375>:
      offset.9 = (unsigned int) offset;
      handle = _wapi_handle_new_from_offset (12, offset.9, 1);
      <D.9381>:
      if (handle == 4294967295B) goto <D.9383>; else goto <D.9384>;
      <D.9383>:
      monoeg_g_log (0B, 16, "%s: error creating named sem handle", &__func__);
      SetLastError (31);
      goto cleanup;
      <D.9384>:
      ret = handle;
      if (offset == 0) goto <D.9385>; else goto <D.9386>;
      <D.9385>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.9365 = thr_ret != 0;
      D.9366 = (long int) D.9365;
      D.9367 = __builtin_expect (D.9366, 0);
      if (D.9367 != 0) goto <D.9387>; else goto <D.9388>;
      <D.9387>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 283, "thr_ret == 0");
      <D.9388>:
      if (initial != 0) goto <D.9389>; else goto <D.9390>;
      <D.9389>:
      _wapi_shared_handle_set_signal_state (handle, 1);
      <D.9390>:
      _wapi_handle_unlock_shared_handles ();
      <D.9386>:
      cleanup:
      monoeg_g_free (utf8_name);
      _wapi_namespace_unlock (0B);
      D.9391 = ret;
      return D.9391;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_namespace_lock ()
{
  int D.9394;

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


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

  D.9397 = __builtin_object_size (__dest, 0);
  D.9396 = __builtin___memcpy_chk (__dest, __src, __len, D.9397);
  return D.9396;
}


_wapi_handle_lock_shared_handles ()
{
  int D.9399;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.9401;

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


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

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


ReleaseSemaphore (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9407;
  gboolean (*<T15b3>) (void *, gint32, gint32 *) D.9408;
  WapiHandleType type;

  if (handle == 0B) goto <D.9405>; else goto <D.9406>;
  <D.9405>:
  SetLastError (6);
  D.9407 = 0;
  return D.9407;
  <D.9406>:
  type = _wapi_handle_type (handle);
  D.9408 = sem_ops[type].release;
  if (D.9408 == 0B) goto <D.9409>; else goto <D.9410>;
  <D.9409>:
  SetLastError (6);
  D.9407 = 0;
  return D.9407;
  <D.9410>:
  D.9408 = sem_ops[type].release;
  D.9407 = D.9408 (handle, count, prevcount);
  return D.9407;
}


namedsem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9414;
  _Bool D.9415;
  long int D.9416;
  long int D.9417;
  struct _WapiHandle_namedsem * sem_handle.10;
  unsigned int D.9423;
  int D.9424;
  unsigned int count.11;
  unsigned int D.9426;
  int D.9427;
  unsigned int D.9428;
  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.9412>; else goto <D.9413>;
      <D.9412>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9414 = 0;
      return D.9414;
      <D.9413>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.9415 = thr_ret != 0;
      D.9416 = (long int) D.9415;
      D.9417 = __builtin_expect (D.9416, 0);
      if (D.9417 != 0) goto <D.9418>; else goto <D.9419>;
      <D.9418>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 415, "thr_ret == 0");
      <D.9419>:
      if (prevcount != 0B) goto <D.9420>; else goto <D.9421>;
      <D.9420>:
      sem_handle.10 = sem_handle;
      D.9423 = sem_handle.10->val;
      D.9424 = (int) D.9423;
      *prevcount = D.9424;
      <D.9421>:
      sem_handle.10 = sem_handle;
      D.9423 = sem_handle.10->val;
      count.11 = (unsigned int) count;
      D.9426 = D.9423 + count.11;
      sem_handle.10 = sem_handle;
      D.9427 = sem_handle.10->max;
      D.9428 = (unsigned int) D.9427;
      if (D.9426 > D.9428) goto end; else goto <D.9429>;
      <D.9429>:
      sem_handle.10 = sem_handle;
      sem_handle.10 = sem_handle;
      D.9423 = sem_handle.10->val;
      count.11 = (unsigned int) count;
      D.9426 = D.9423 + count.11;
      sem_handle.10->val = D.9426;
      _wapi_shared_handle_set_signal_state (handle, 1);
      ret = 1;
      end:
      _wapi_handle_unlock_shared_handles ();
      D.9414 = ret;
      return D.9414;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


sem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9434;
  long int D.9435;
  _Bool D.9438;
  long int D.9439;
  long int D.9440;
  struct _WapiHandle_sem * sem_handle.12;
  unsigned int D.9446;
  int D.9447;
  unsigned int count.13;
  unsigned int D.9449;
  int D.9450;
  unsigned int D.9451;
  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.9432>; else goto <D.9433>;
      <D.9432>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9434 = 0;
      return D.9434;
      <D.9433>:
      {
        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.9435 = __builtin_expect (__not_first_call, 0);
            if (D.9435 != 0) goto <D.9436>; else goto <D.9437>;
            <D.9436>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9437>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9438 = thr_ret != 0;
            D.9439 = (long int) D.9438;
            D.9440 = __builtin_expect (D.9439, 0);
            if (D.9440 != 0) goto <D.9441>; else goto <D.9442>;
            <D.9441>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 364, "thr_ret == 0");
            <D.9442>:
            if (prevcount != 0B) goto <D.9443>; else goto <D.9444>;
            <D.9443>:
            sem_handle.12 = sem_handle;
            D.9446 = sem_handle.12->val;
            D.9447 = (int) D.9446;
            *prevcount = D.9447;
            <D.9444>:
            sem_handle.12 = sem_handle;
            D.9446 = sem_handle.12->val;
            count.13 = (unsigned int) count;
            D.9449 = D.9446 + count.13;
            sem_handle.12 = sem_handle;
            D.9450 = sem_handle.12->max;
            D.9451 = (unsigned int) D.9450;
            if (D.9449 > D.9451) goto end; else goto <D.9452>;
            <D.9452>:
            sem_handle.12 = sem_handle;
            sem_handle.12 = sem_handle;
            D.9446 = sem_handle.12->val;
            count.13 = (unsigned int) count;
            D.9449 = D.9446 + count.13;
            sem_handle.12->val = D.9449;
            _wapi_handle_set_signal_state (handle, 1, 1);
            ret = 1;
            end:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9438 = thr_ret != 0;
            D.9439 = (long int) D.9438;
            D.9440 = __builtin_expect (D.9439, 0);
            if (D.9440 != 0) goto <D.9453>; else goto <D.9454>;
            <D.9453>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 392, "thr_ret == 0");
            <D.9454>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9455>; else goto <D.9456>;
            <D.9455>:
            __cancel_routine (__cancel_arg);
            <D.9456>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9434 = ret;
      return D.9434;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


OpenSemaphore (guint32 access, gboolean inherit, const gunichar2 * name)
{
  _Bool D.9462;
  long int D.9463;
  long int D.9464;
  unsigned int offset.14;
  void * D.9474;
  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.9462 = thr_ret != 0;
  D.9463 = (long int) D.9462;
  D.9464 = __builtin_expect (D.9463, 0);
  if (D.9464 != 0) goto <D.9465>; else goto <D.9466>;
  <D.9465>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 494, "thr_ret == 0");
  <D.9466>:
  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.9467>; else goto <D.9468>;
  <D.9467>:
  SetLastError (6);
  goto cleanup;
  <D.9468>:
  if (offset == 0) goto <D.9469>; else goto <D.9470>;
  <D.9469>:
  SetLastError (2);
  goto cleanup;
  <D.9470>:
  offset.14 = (unsigned int) offset;
  handle = _wapi_handle_new_from_offset (12, offset.14, 1);
  if (handle == 4294967295B) goto <D.9472>; else goto <D.9473>;
  <D.9472>:
  monoeg_g_log (0B, 16, "%s: error opening named sem handle", &__func__);
  SetLastError (31);
  goto cleanup;
  <D.9473>:
  ret = handle;
  cleanup:
  monoeg_g_free (utf8_name);
  _wapi_namespace_unlock (0B);
  D.9474 = ret;
  return D.9474;
}


