sema_own (void * handle)
{
  gboolean D.9211;
  struct _WapiHandle_sem * sem_handle.0;
  unsigned int D.9213;
  unsigned int D.9214;
  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.9209>; else goto <D.9210>;
      <D.9209>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9211 = 0;
      return D.9211;
      <D.9210>:
      sem_handle.0 = sem_handle;
      D.9213 = sem_handle.0->val;
      D.9214 = D.9213 + 4294967295;
      sem_handle.0->val = D.9214;
      sem_handle.0 = sem_handle;
      D.9213 = sem_handle.0->val;
      if (D.9213 == 0) goto <D.9215>; else goto <D.9216>;
      <D.9215>:
      _wapi_handle_set_signal_state (handle, 0, 0);
      <D.9216>:
      D.9211 = 1;
      return D.9211;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_set_signal_state (void * handle, gboolean state, gboolean broadcast)
{
  int iftmp.1;
  <unnamed type> D.9225;
  <unnamed type> D.9227;
  <unnamed type> D.9229;
  <unnamed type> D.9231;
  _Bool D.9232;
  long int D.9233;
  long int D.9234;
  unsigned int D.9237;
  struct _WapiHandleUnshared * D.9238;
  unsigned int D.9239;
  unsigned int D.9240;
  long int D.9243;
  union mono_mutex_t * _wapi_global_signal_mutex.2;
  _Bool D.9249;
  long int D.9250;
  long int D.9251;
  union pthread_cond_t * D.9256;
  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.9219>; else goto <D.9220>;
  <D.9219>:
  return;
  <D.9220>:
  D.9225 = _wapi_handle_type (handle);
  if (D.9225 == 9) goto <D.9222>; else goto <D.9226>;
  <D.9226>:
  D.9227 = _wapi_handle_type (handle);
  if (D.9227 == 11) goto <D.9222>; else goto <D.9228>;
  <D.9228>:
  D.9229 = _wapi_handle_type (handle);
  if (D.9229 == 12) goto <D.9222>; else goto <D.9230>;
  <D.9230>:
  D.9231 = _wapi_handle_type (handle);
  if (D.9231 == 13) goto <D.9222>; else goto <D.9223>;
  <D.9222>:
  iftmp.1 = 1;
  goto <D.9224>;
  <D.9223>:
  iftmp.1 = 0;
  <D.9224>:
  D.9232 = iftmp.1 != 0;
  D.9233 = (long int) D.9232;
  D.9234 = __builtin_expect (D.9233, 0);
  if (D.9234 != 0) goto <D.9235>; else goto <D.9236>;
  <D.9235>:
  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.9236>:
  D.9237 = idx / 256;
  D.9238 = _wapi_private_handles[D.9237];
  D.9239 = idx & 255;
  D.9240 = D.9239 * 144;
  handle_data = D.9238 + D.9240;
  if (state == 1) goto <D.9241>; else goto <D.9242>;
  <D.9241>:
  {
    struct __pthread_unwind_buf_t __cancel_buf;
    void (*<Tc3>) (void *) __cancel_routine;
    void * __cancel_arg;
    int __not_first_call;

    try
      {
        __cancel_routine = mono_mutex_unlock_in_cleanup;
        __cancel_arg = _wapi_global_signal_mutex;
        __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
        D.9243 = __builtin_expect (__not_first_call, 0);
        if (D.9243 != 0) goto <D.9244>; else goto <D.9245>;
        <D.9244>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.9245>:
        __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.9247>; else goto <D.9248>;
        <D.9247>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.9248>:
        D.9249 = thr_ret != 0;
        D.9250 = (long int) D.9249;
        D.9251 = __builtin_expect (D.9250, 0);
        if (D.9251 != 0) goto <D.9252>; else goto <D.9253>;
        <D.9252>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 151, "thr_ret == 0");
        <D.9253>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.9254>; else goto <D.9255>;
        <D.9254>:
        D.9256 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.9256);
        if (thr_ret != 0) goto <D.9257>; else goto <D.9258>;
        <D.9257>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.9258>:
        D.9249 = thr_ret != 0;
        D.9250 = (long int) D.9249;
        D.9251 = __builtin_expect (D.9250, 0);
        if (D.9251 != 0) goto <D.9259>; else goto <D.9260>;
        <D.9259>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.9260>:
        goto <D.9261>;
        <D.9255>:
        D.9256 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.9256);
        if (thr_ret != 0) goto <D.9262>; else goto <D.9263>;
        <D.9262>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.9263>:
        D.9249 = thr_ret != 0;
        D.9250 = (long int) D.9249;
        D.9251 = __builtin_expect (D.9250, 0);
        if (D.9251 != 0) goto <D.9264>; else goto <D.9265>;
        <D.9264>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.9265>:
        <D.9261>:
        _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.9267>; else goto <D.9268>;
        <D.9267>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.9268>:
        D.9249 = thr_ret != 0;
        D.9250 = (long int) D.9249;
        D.9251 = __builtin_expect (D.9250, 0);
        if (D.9251 != 0) goto <D.9269>; else goto <D.9270>;
        <D.9269>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.9270>:
        _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.9271>; else goto <D.9272>;
        <D.9271>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.9272>:
        D.9249 = thr_ret != 0;
        D.9250 = (long int) D.9249;
        D.9251 = __builtin_expect (D.9250, 0);
        if (D.9251 != 0) goto <D.9273>; else goto <D.9274>;
        <D.9273>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.9274>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.9275>; else goto <D.9276>;
        <D.9275>:
        __cancel_routine (__cancel_arg);
        <D.9276>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.9277>;
  <D.9242>:
  handle_data->signalled = state;
  <D.9277>:
}


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

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


_wapi_handle_type (void * handle)
{
  unsigned int D.9294;
  struct _WapiHandleUnshared * D.9295;
  WapiHandleType D.9296;
  unsigned int D.9297;
  unsigned int D.9298;
  struct _WapiHandleUnshared * D.9299;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9290>; else goto <D.9292>;
  <D.9292>:
  if (idx > 268435455) goto <D.9290>; else goto <D.9293>;
  <D.9293>:
  D.9294 = idx / 256;
  D.9295 = _wapi_private_handles[D.9294];
  if (D.9295 == 0B) goto <D.9290>; else goto <D.9291>;
  <D.9290>:
  D.9296 = 0;
  return D.9296;
  <D.9291>:
  D.9294 = idx / 256;
  D.9295 = _wapi_private_handles[D.9294];
  D.9297 = idx & 255;
  D.9298 = D.9297 * 144;
  D.9299 = D.9295 + D.9298;
  D.9296 = D.9299->type;
  return D.9296;
}


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


_wapi_sem_details (void * handle_info)
{
  unsigned int D.9301;
  int D.9302;
  struct _WapiHandle_sem * sem;

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


namedsema_own (void * handle)
{
  gboolean D.9305;
  struct _WapiHandle_namedsem * namedsem_handle.4;
  unsigned int D.9307;
  unsigned int D.9308;
  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.9303>; else goto <D.9304>;
      <D.9303>:
      monoeg_g_log (0B, 16, "%s: error looking up named sem handle %p", &__func__, handle);
      D.9305 = 0;
      return D.9305;
      <D.9304>:
      namedsem_handle.4 = namedsem_handle;
      D.9307 = namedsem_handle.4->val;
      D.9308 = D.9307 + 4294967295;
      namedsem_handle.4->val = D.9308;
      namedsem_handle.4 = namedsem_handle;
      D.9307 = namedsem_handle.4->val;
      if (D.9307 == 0) goto <D.9309>; else goto <D.9310>;
      <D.9309>:
      _wapi_shared_handle_set_signal_state (handle, 0);
      <D.9310>:
      D.9305 = 1;
      return D.9305;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_shared_handle_set_signal_state (void * handle, gboolean state)
{
  int iftmp.5;
  <unnamed type> D.9318;
  <unnamed type> D.9320;
  <unnamed type> D.9322;
  <unnamed type> D.9324;
  _Bool D.9326;
  long int D.9327;
  long int D.9328;
  unsigned int D.9331;
  struct _WapiHandleUnshared * D.9332;
  unsigned int D.9333;
  unsigned int D.9334;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.6;
  unsigned int D.9336;
  guint32 idx;
  struct _WapiHandleUnshared * handle_data;
  struct _WapiHandle_shared_ref * ref;
  struct _WapiHandleShared * shared_data;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9313>; else goto <D.9314>;
  <D.9313>:
  return;
  <D.9314>:
  D.9318 = _wapi_handle_type (handle);
  if (D.9318 != 9) goto <D.9319>; else goto <D.9316>;
  <D.9319>:
  D.9320 = _wapi_handle_type (handle);
  if (D.9320 != 11) goto <D.9321>; else goto <D.9316>;
  <D.9321>:
  D.9322 = _wapi_handle_type (handle);
  if (D.9322 != 12) goto <D.9323>; else goto <D.9316>;
  <D.9323>:
  D.9324 = _wapi_handle_type (handle);
  if (D.9324 != 13) goto <D.9325>; else goto <D.9316>;
  <D.9325>:
  iftmp.5 = 1;
  goto <D.9317>;
  <D.9316>:
  iftmp.5 = 0;
  <D.9317>:
  D.9326 = iftmp.5 != 0;
  D.9327 = (long int) D.9326;
  D.9328 = __builtin_expect (D.9327, 0);
  if (D.9328 != 0) goto <D.9329>; else goto <D.9330>;
  <D.9329>:
  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.9330>:
  D.9331 = idx / 256;
  D.9332 = _wapi_private_handles[D.9331];
  D.9333 = idx & 255;
  D.9334 = D.9333 * 144;
  handle_data = D.9332 + D.9334;
  ref = &handle_data->u.shared;
  _wapi_shared_layout.6 = _wapi_shared_layout;
  D.9336 = ref->offset;
  shared_data = &_wapi_shared_layout.6->handles[D.9336];
  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.9340;

  mono_once (&sem_ops_once, sem_ops_init);
  if (max <= 0) goto <D.9338>; else goto <D.9339>;
  <D.9338>:
  SetLastError (87);
  D.9340 = 0B;
  return D.9340;
  <D.9339>:
  if (initial > max) goto <D.9341>; else goto <D.9343>;
  <D.9343>:
  if (initial < 0) goto <D.9341>; else goto <D.9342>;
  <D.9341>:
  SetLastError (87);
  D.9340 = 0B;
  return D.9340;
  <D.9342>:
  if (name == 0B) goto <D.9344>; else goto <D.9345>;
  <D.9344>:
  D.9340 = sem_create (security, initial, max);
  return D.9340;
  <D.9345>:
  D.9340 = namedsem_create (security, initial, max, name);
  return D.9340;
}


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.9350;
  long int D.9351;
  _Bool D.9354;
  long int D.9355;
  long int D.9356;
  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.9348>; else goto <D.9349>;
      <D.9348>:
      monoeg_g_log (0B, 16, "%s: error creating semaphore handle", &__func__);
      SetLastError (31);
      D.9350 = 0B;
      return D.9350;
      <D.9349>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.9351 = __builtin_expect (__not_first_call, 0);
            if (D.9351 != 0) goto <D.9352>; else goto <D.9353>;
            <D.9352>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9353>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9354 = thr_ret != 0;
            D.9355 = (long int) D.9354;
            D.9356 = __builtin_expect (D.9355, 0);
            if (D.9356 != 0) goto <D.9357>; else goto <D.9358>;
            <D.9357>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 188, "thr_ret == 0");
            <D.9358>:
            if (initial != 0) goto <D.9359>; else goto <D.9360>;
            <D.9359>:
            _wapi_handle_set_signal_state (handle, 1, 0);
            <D.9360>:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9354 = thr_ret != 0;
            D.9355 = (long int) D.9354;
            D.9356 = __builtin_expect (D.9355, 0);
            if (D.9356 != 0) goto <D.9361>; else goto <D.9362>;
            <D.9361>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 198, "thr_ret == 0");
            <D.9362>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9363>; else goto <D.9364>;
            <D.9363>:
            __cancel_routine (__cancel_arg);
            <D.9364>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9350 = handle;
      return D.9350;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  int D.9372;
  <unnamed type> D.9375;
  <unnamed type> D.9377;
  <unnamed type> D.9379;
  <unnamed type> D.9381;
  unsigned int D.9382;
  struct _WapiHandleUnshared * D.9383;
  unsigned int D.9384;
  unsigned int D.9385;
  struct _WapiHandleUnshared * D.9386;
  union mono_mutex_t * D.9387;
  guint32 idx;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9370>; else goto <D.9371>;
  <D.9370>:
  D.9372 = 0;
  return D.9372;
  <D.9371>:
  _wapi_handle_ref (handle);
  D.9375 = _wapi_handle_type (handle);
  if (D.9375 == 9) goto <D.9373>; else goto <D.9376>;
  <D.9376>:
  D.9377 = _wapi_handle_type (handle);
  if (D.9377 == 11) goto <D.9373>; else goto <D.9378>;
  <D.9378>:
  D.9379 = _wapi_handle_type (handle);
  if (D.9379 == 12) goto <D.9373>; else goto <D.9380>;
  <D.9380>:
  D.9381 = _wapi_handle_type (handle);
  if (D.9381 == 13) goto <D.9373>; else goto <D.9374>;
  <D.9373>:
  D.9372 = 0;
  return D.9372;
  <D.9374>:
  D.9382 = idx / 256;
  D.9383 = _wapi_private_handles[D.9382];
  D.9384 = idx & 255;
  D.9385 = D.9384 * 144;
  D.9386 = D.9383 + D.9385;
  D.9387 = &D.9386->signal_mutex;
  D.9372 = pthread_mutex_lock (D.9387);
  return D.9372;
}


_wapi_handle_unlock_handle (void * handle)
{
  int D.9391;
  <unnamed type> D.9394;
  <unnamed type> D.9396;
  <unnamed type> D.9398;
  <unnamed type> D.9400;
  unsigned int D.9401;
  struct _WapiHandleUnshared * D.9402;
  unsigned int D.9403;
  unsigned int D.9404;
  struct _WapiHandleUnshared * D.9405;
  union mono_mutex_t * D.9406;
  guint32 idx;
  int ret;

  idx = (guint32) handle;
  if (idx > 4194303) goto <D.9389>; else goto <D.9390>;
  <D.9389>:
  D.9391 = 0;
  return D.9391;
  <D.9390>:
  D.9394 = _wapi_handle_type (handle);
  if (D.9394 == 9) goto <D.9392>; else goto <D.9395>;
  <D.9395>:
  D.9396 = _wapi_handle_type (handle);
  if (D.9396 == 11) goto <D.9392>; else goto <D.9397>;
  <D.9397>:
  D.9398 = _wapi_handle_type (handle);
  if (D.9398 == 12) goto <D.9392>; else goto <D.9399>;
  <D.9399>:
  D.9400 = _wapi_handle_type (handle);
  if (D.9400 == 13) goto <D.9392>; else goto <D.9393>;
  <D.9392>:
  _wapi_handle_unref (handle);
  D.9391 = 0;
  return D.9391;
  <D.9393>:
  D.9401 = idx / 256;
  D.9402 = _wapi_private_handles[D.9401];
  D.9403 = idx & 255;
  D.9404 = D.9403 * 144;
  D.9405 = D.9402 + D.9404;
  D.9406 = &D.9405->signal_mutex;
  ret = pthread_mutex_unlock (D.9406);
  _wapi_handle_unref (handle);
  D.9391 = ret;
  return D.9391;
}


namedsem_create (struct WapiSecurityAttributes * security, gint32 initial, gint32 max, const gunichar2 * name)
{
  _Bool D.9408;
  long int D.9409;
  long int D.9410;
  unsigned int D.9419;
  unsigned int initial.8;
  unsigned int offset.9;
  void * D.9434;
  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.9408 = thr_ret != 0;
      D.9409 = (long int) D.9408;
      D.9410 = __builtin_expect (D.9409, 0);
      if (D.9410 != 0) goto <D.9411>; else goto <D.9412>;
      <D.9411>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 218, "thr_ret == 0");
      <D.9412>:
      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.9413>; else goto <D.9414>;
      <D.9413>:
      SetLastError (6);
      goto cleanup;
      <D.9414>:
      if (offset != 0) goto <D.9415>; else goto <D.9416>;
      <D.9415>:
      SetLastError (183);
      <D.9416>:
      if (offset == 0) goto <D.9417>; else goto <D.9418>;
      <D.9417>:
      D.9419 = strlen (utf8_name);
      if (D.9419 <= 259) goto <D.9420>; else goto <D.9421>;
      <D.9420>:
      namelen = strlen (utf8_name);
      goto <D.9422>;
      <D.9421>:
      namelen = 260;
      <D.9422>:
      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.9424>;
      <D.9418>:
      offset.9 = (unsigned int) offset;
      handle = _wapi_handle_new_from_offset (12, offset.9, 1);
      <D.9424>:
      if (handle == 4294967295B) goto <D.9426>; else goto <D.9427>;
      <D.9426>:
      monoeg_g_log (0B, 16, "%s: error creating named sem handle", &__func__);
      SetLastError (31);
      goto cleanup;
      <D.9427>:
      ret = handle;
      if (offset == 0) goto <D.9428>; else goto <D.9429>;
      <D.9428>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.9408 = thr_ret != 0;
      D.9409 = (long int) D.9408;
      D.9410 = __builtin_expect (D.9409, 0);
      if (D.9410 != 0) goto <D.9430>; else goto <D.9431>;
      <D.9430>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 283, "thr_ret == 0");
      <D.9431>:
      if (initial != 0) goto <D.9432>; else goto <D.9433>;
      <D.9432>:
      _wapi_shared_handle_set_signal_state (handle, 1);
      <D.9433>:
      _wapi_handle_unlock_shared_handles ();
      <D.9429>:
      cleanup:
      monoeg_g_free (utf8_name);
      _wapi_namespace_unlock (0B);
      D.9434 = ret;
      return D.9434;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_namespace_lock ()
{
  int D.9437;

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


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

  D.9440 = __builtin_object_size (__dest, 0);
  D.9439 = __builtin___memcpy_chk (__dest, __src, __len, D.9440);
  return D.9439;
}


_wapi_handle_lock_shared_handles ()
{
  int D.9442;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.9444;

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


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

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


ReleaseSemaphore (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9450;
  gboolean (*<T15cd>) (void *, gint32, gint32 *) D.9451;
  WapiHandleType type;

  if (handle == 0B) goto <D.9448>; else goto <D.9449>;
  <D.9448>:
  SetLastError (6);
  D.9450 = 0;
  return D.9450;
  <D.9449>:
  type = _wapi_handle_type (handle);
  D.9451 = sem_ops[type].release;
  if (D.9451 == 0B) goto <D.9452>; else goto <D.9453>;
  <D.9452>:
  SetLastError (6);
  D.9450 = 0;
  return D.9450;
  <D.9453>:
  D.9451 = sem_ops[type].release;
  D.9450 = D.9451 (handle, count, prevcount);
  return D.9450;
}


namedsem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9457;
  _Bool D.9458;
  long int D.9459;
  long int D.9460;
  struct _WapiHandle_namedsem * sem_handle.10;
  unsigned int D.9466;
  int D.9467;
  unsigned int count.11;
  unsigned int D.9469;
  int D.9470;
  unsigned int D.9471;
  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.9455>; else goto <D.9456>;
      <D.9455>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9457 = 0;
      return D.9457;
      <D.9456>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.9458 = thr_ret != 0;
      D.9459 = (long int) D.9458;
      D.9460 = __builtin_expect (D.9459, 0);
      if (D.9460 != 0) goto <D.9461>; else goto <D.9462>;
      <D.9461>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 415, "thr_ret == 0");
      <D.9462>:
      if (prevcount != 0B) goto <D.9463>; else goto <D.9464>;
      <D.9463>:
      sem_handle.10 = sem_handle;
      D.9466 = sem_handle.10->val;
      D.9467 = (int) D.9466;
      *prevcount = D.9467;
      <D.9464>:
      sem_handle.10 = sem_handle;
      D.9466 = sem_handle.10->val;
      count.11 = (unsigned int) count;
      D.9469 = D.9466 + count.11;
      sem_handle.10 = sem_handle;
      D.9470 = sem_handle.10->max;
      D.9471 = (unsigned int) D.9470;
      if (D.9469 > D.9471) goto end; else goto <D.9472>;
      <D.9472>:
      sem_handle.10 = sem_handle;
      sem_handle.10 = sem_handle;
      D.9466 = sem_handle.10->val;
      count.11 = (unsigned int) count;
      D.9469 = D.9466 + count.11;
      sem_handle.10->val = D.9469;
      _wapi_shared_handle_set_signal_state (handle, 1);
      ret = 1;
      end:
      _wapi_handle_unlock_shared_handles ();
      D.9457 = ret;
      return D.9457;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


sem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9477;
  long int D.9478;
  _Bool D.9481;
  long int D.9482;
  long int D.9483;
  struct _WapiHandle_sem * sem_handle.12;
  unsigned int D.9489;
  int D.9490;
  unsigned int count.13;
  unsigned int D.9492;
  int D.9493;
  unsigned int D.9494;
  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.9475>; else goto <D.9476>;
      <D.9475>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9477 = 0;
      return D.9477;
      <D.9476>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc3>) (void *) __cancel_routine;
        void * __cancel_arg;
        int __not_first_call;

        try
          {
            __cancel_routine = _wapi_handle_unlock_handle;
            __cancel_arg = handle;
            __not_first_call = __sigsetjmp (&__cancel_buf.__cancel_jmp_buf, 0);
            D.9478 = __builtin_expect (__not_first_call, 0);
            if (D.9478 != 0) goto <D.9479>; else goto <D.9480>;
            <D.9479>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9480>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9481 = thr_ret != 0;
            D.9482 = (long int) D.9481;
            D.9483 = __builtin_expect (D.9482, 0);
            if (D.9483 != 0) goto <D.9484>; else goto <D.9485>;
            <D.9484>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 364, "thr_ret == 0");
            <D.9485>:
            if (prevcount != 0B) goto <D.9486>; else goto <D.9487>;
            <D.9486>:
            sem_handle.12 = sem_handle;
            D.9489 = sem_handle.12->val;
            D.9490 = (int) D.9489;
            *prevcount = D.9490;
            <D.9487>:
            sem_handle.12 = sem_handle;
            D.9489 = sem_handle.12->val;
            count.13 = (unsigned int) count;
            D.9492 = D.9489 + count.13;
            sem_handle.12 = sem_handle;
            D.9493 = sem_handle.12->max;
            D.9494 = (unsigned int) D.9493;
            if (D.9492 > D.9494) goto end; else goto <D.9495>;
            <D.9495>:
            sem_handle.12 = sem_handle;
            sem_handle.12 = sem_handle;
            D.9489 = sem_handle.12->val;
            count.13 = (unsigned int) count;
            D.9492 = D.9489 + count.13;
            sem_handle.12->val = D.9492;
            _wapi_handle_set_signal_state (handle, 1, 1);
            ret = 1;
            end:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9481 = thr_ret != 0;
            D.9482 = (long int) D.9481;
            D.9483 = __builtin_expect (D.9482, 0);
            if (D.9483 != 0) goto <D.9496>; else goto <D.9497>;
            <D.9496>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 392, "thr_ret == 0");
            <D.9497>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9498>; else goto <D.9499>;
            <D.9498>:
            __cancel_routine (__cancel_arg);
            <D.9499>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9477 = ret;
      return D.9477;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


OpenSemaphore (guint32 access, gboolean inherit, const gunichar2 * name)
{
  _Bool D.9505;
  long int D.9506;
  long int D.9507;
  unsigned int offset.14;
  void * D.9517;
  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.9505 = thr_ret != 0;
  D.9506 = (long int) D.9505;
  D.9507 = __builtin_expect (D.9506, 0);
  if (D.9507 != 0) goto <D.9508>; else goto <D.9509>;
  <D.9508>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 494, "thr_ret == 0");
  <D.9509>:
  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.9510>; else goto <D.9511>;
  <D.9510>:
  SetLastError (6);
  goto cleanup;
  <D.9511>:
  if (offset == 0) goto <D.9512>; else goto <D.9513>;
  <D.9512>:
  SetLastError (2);
  goto cleanup;
  <D.9513>:
  offset.14 = (unsigned int) offset;
  handle = _wapi_handle_new_from_offset (12, offset.14, 1);
  if (handle == 4294967295B) goto <D.9515>; else goto <D.9516>;
  <D.9515>:
  monoeg_g_log (0B, 16, "%s: error opening named sem handle", &__func__);
  SetLastError (31);
  goto cleanup;
  <D.9516>:
  ret = handle;
  cleanup:
  monoeg_g_free (utf8_name);
  _wapi_namespace_unlock (0B);
  D.9517 = ret;
  return D.9517;
}


