sema_own (void * handle)
{
  gboolean D.9688;
  struct _WapiHandle_sem * sem_handle.0;
  unsigned int D.9690;
  unsigned int D.9691;
  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.9686>; else goto <D.9687>;
      <D.9686>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9688 = 0;
      return D.9688;
      <D.9687>:
      sem_handle.0 = sem_handle;
      D.9690 = sem_handle.0->val;
      D.9691 = D.9690 + 4294967295;
      sem_handle.0->val = D.9691;
      sem_handle.0 = sem_handle;
      D.9690 = sem_handle.0->val;
      if (D.9690 == 0) goto <D.9692>; else goto <D.9693>;
      <D.9692>:
      _wapi_handle_set_signal_state (handle, 0, 0);
      <D.9693>:
      D.9688 = 1;
      return D.9688;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_set_signal_state (void * handle, gboolean state, gboolean broadcast)
{
  long int handle.1;
  int iftmp.2;
  <unnamed type> D.9703;
  <unnamed type> D.9705;
  <unnamed type> D.9707;
  <unnamed type> D.9709;
  _Bool D.9710;
  long int D.9711;
  long int D.9712;
  unsigned int D.9715;
  struct _WapiHandleUnshared * D.9716;
  long unsigned int D.9717;
  long unsigned int D.9718;
  long unsigned int D.9719;
  long int D.9722;
  long int D.9723;
  union mono_mutex_t * _wapi_global_signal_mutex.3;
  _Bool D.9729;
  long int D.9730;
  long int D.9731;
  union pthread_cond_t * D.9736;
  union pthread_cond_t * _wapi_global_signal_cond.4;
  guint32 idx;
  struct _WapiHandleUnshared * handle_data;
  int thr_ret;

  handle.1 = (long int) handle;
  idx = (guint32) handle.1;
  if (idx > 4194303) goto <D.9697>; else goto <D.9698>;
  <D.9697>:
  return;
  <D.9698>:
  D.9703 = _wapi_handle_type (handle);
  if (D.9703 == 9) goto <D.9700>; else goto <D.9704>;
  <D.9704>:
  D.9705 = _wapi_handle_type (handle);
  if (D.9705 == 11) goto <D.9700>; else goto <D.9706>;
  <D.9706>:
  D.9707 = _wapi_handle_type (handle);
  if (D.9707 == 12) goto <D.9700>; else goto <D.9708>;
  <D.9708>:
  D.9709 = _wapi_handle_type (handle);
  if (D.9709 == 13) goto <D.9700>; else goto <D.9701>;
  <D.9700>:
  iftmp.2 = 1;
  goto <D.9702>;
  <D.9701>:
  iftmp.2 = 0;
  <D.9702>:
  D.9710 = iftmp.2 != 0;
  D.9711 = (long int) D.9710;
  D.9712 = __builtin_expect (D.9711, 0);
  if (D.9712 != 0) goto <D.9713>; else goto <D.9714>;
  <D.9713>:
  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.9714>:
  D.9715 = idx / 256;
  D.9716 = _wapi_private_handles[D.9715];
  D.9717 = (long unsigned int) idx;
  D.9718 = D.9717 & 255;
  D.9719 = D.9718 * 200;
  handle_data = D.9716 + D.9719;
  if (state == 1) goto <D.9720>; else goto <D.9721>;
  <D.9720>:
  {
    struct __pthread_unwind_buf_t __cancel_buf;
    void (*<Tc6>) (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.9722 = (long int) __not_first_call;
        D.9723 = __builtin_expect (D.9722, 0);
        if (D.9723 != 0) goto <D.9724>; else goto <D.9725>;
        <D.9724>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.9725>:
        __pthread_register_cancel (&__cancel_buf);
        _wapi_global_signal_mutex.3 = _wapi_global_signal_mutex;
        thr_ret = pthread_mutex_lock (_wapi_global_signal_mutex.3);
        if (thr_ret != 0) goto <D.9727>; else goto <D.9728>;
        <D.9727>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.9728>:
        D.9729 = thr_ret != 0;
        D.9730 = (long int) D.9729;
        D.9731 = __builtin_expect (D.9730, 0);
        if (D.9731 != 0) goto <D.9732>; else goto <D.9733>;
        <D.9732>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 151, "thr_ret == 0");
        <D.9733>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.9734>; else goto <D.9735>;
        <D.9734>:
        D.9736 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.9736);
        if (thr_ret != 0) goto <D.9737>; else goto <D.9738>;
        <D.9737>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.9738>:
        D.9729 = thr_ret != 0;
        D.9730 = (long int) D.9729;
        D.9731 = __builtin_expect (D.9730, 0);
        if (D.9731 != 0) goto <D.9739>; else goto <D.9740>;
        <D.9739>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.9740>:
        goto <D.9741>;
        <D.9735>:
        D.9736 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.9736);
        if (thr_ret != 0) goto <D.9742>; else goto <D.9743>;
        <D.9742>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.9743>:
        D.9729 = thr_ret != 0;
        D.9730 = (long int) D.9729;
        D.9731 = __builtin_expect (D.9730, 0);
        if (D.9731 != 0) goto <D.9744>; else goto <D.9745>;
        <D.9744>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.9745>:
        <D.9741>:
        _wapi_global_signal_cond.4 = _wapi_global_signal_cond;
        thr_ret = pthread_cond_broadcast (_wapi_global_signal_cond.4);
        if (thr_ret != 0) goto <D.9747>; else goto <D.9748>;
        <D.9747>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.9748>:
        D.9729 = thr_ret != 0;
        D.9730 = (long int) D.9729;
        D.9731 = __builtin_expect (D.9730, 0);
        if (D.9731 != 0) goto <D.9749>; else goto <D.9750>;
        <D.9749>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.9750>:
        _wapi_global_signal_mutex.3 = _wapi_global_signal_mutex;
        thr_ret = pthread_mutex_unlock (_wapi_global_signal_mutex.3);
        if (thr_ret != 0) goto <D.9751>; else goto <D.9752>;
        <D.9751>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.9752>:
        D.9729 = thr_ret != 0;
        D.9730 = (long int) D.9729;
        D.9731 = __builtin_expect (D.9730, 0);
        if (D.9731 != 0) goto <D.9753>; else goto <D.9754>;
        <D.9753>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.9754>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.9755>; else goto <D.9756>;
        <D.9755>:
        __cancel_routine (__cancel_arg);
        <D.9756>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.9757>;
  <D.9721>:
  handle_data->signalled = state;
  <D.9757>:
}


__attribute__((__unused__))
mono_mutex_unlock_in_cleanup (union mono_mutex_t * mutex)
{
  int D.9768;

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


_wapi_handle_type (void * handle)
{
  long int handle.5;
  unsigned int D.9775;
  struct _WapiHandleUnshared * D.9776;
  WapiHandleType D.9777;
  unsigned int D.9778;
  struct _WapiHandleUnshared * D.9779;
  long unsigned int D.9780;
  long unsigned int D.9781;
  long unsigned int D.9782;
  struct _WapiHandleUnshared * D.9783;
  guint32 idx;

  handle.5 = (long int) handle;
  idx = (guint32) handle.5;
  if (idx > 4194303) goto <D.9771>; else goto <D.9773>;
  <D.9773>:
  if (idx > 268435455) goto <D.9771>; else goto <D.9774>;
  <D.9774>:
  D.9775 = idx / 256;
  D.9776 = _wapi_private_handles[D.9775];
  if (D.9776 == 0B) goto <D.9771>; else goto <D.9772>;
  <D.9771>:
  D.9777 = 0;
  return D.9777;
  <D.9772>:
  D.9778 = idx / 256;
  D.9779 = _wapi_private_handles[D.9778];
  D.9780 = (long unsigned int) idx;
  D.9781 = D.9780 & 255;
  D.9782 = D.9781 * 200;
  D.9783 = D.9779 + D.9782;
  D.9777 = D.9783->type;
  return D.9777;
}


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


_wapi_sem_details (void * handle_info)
{
  unsigned int D.9785;
  int D.9786;
  struct _WapiHandle_sem * sem;

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


namedsema_own (void * handle)
{
  gboolean D.9789;
  struct _WapiHandle_namedsem * namedsem_handle.6;
  unsigned int D.9791;
  unsigned int D.9792;
  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.9787>; else goto <D.9788>;
      <D.9787>:
      monoeg_g_log (0B, 16, "%s: error looking up named sem handle %p", &__func__, handle);
      D.9789 = 0;
      return D.9789;
      <D.9788>:
      namedsem_handle.6 = namedsem_handle;
      D.9791 = namedsem_handle.6->val;
      D.9792 = D.9791 + 4294967295;
      namedsem_handle.6->val = D.9792;
      namedsem_handle.6 = namedsem_handle;
      D.9791 = namedsem_handle.6->val;
      if (D.9791 == 0) goto <D.9793>; else goto <D.9794>;
      <D.9793>:
      _wapi_shared_handle_set_signal_state (handle, 0);
      <D.9794>:
      D.9789 = 1;
      return D.9789;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_shared_handle_set_signal_state (void * handle, gboolean state)
{
  long int handle.7;
  int iftmp.8;
  <unnamed type> D.9803;
  <unnamed type> D.9805;
  <unnamed type> D.9807;
  <unnamed type> D.9809;
  _Bool D.9811;
  long int D.9812;
  long int D.9813;
  unsigned int D.9816;
  struct _WapiHandleUnshared * D.9817;
  long unsigned int D.9818;
  long unsigned int D.9819;
  long unsigned int D.9820;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.9;
  unsigned int D.9822;
  guint32 idx;
  struct _WapiHandleUnshared * handle_data;
  struct _WapiHandle_shared_ref * ref;
  struct _WapiHandleShared * shared_data;

  handle.7 = (long int) handle;
  idx = (guint32) handle.7;
  if (idx > 4194303) goto <D.9798>; else goto <D.9799>;
  <D.9798>:
  return;
  <D.9799>:
  D.9803 = _wapi_handle_type (handle);
  if (D.9803 != 9) goto <D.9804>; else goto <D.9801>;
  <D.9804>:
  D.9805 = _wapi_handle_type (handle);
  if (D.9805 != 11) goto <D.9806>; else goto <D.9801>;
  <D.9806>:
  D.9807 = _wapi_handle_type (handle);
  if (D.9807 != 12) goto <D.9808>; else goto <D.9801>;
  <D.9808>:
  D.9809 = _wapi_handle_type (handle);
  if (D.9809 != 13) goto <D.9810>; else goto <D.9801>;
  <D.9810>:
  iftmp.8 = 1;
  goto <D.9802>;
  <D.9801>:
  iftmp.8 = 0;
  <D.9802>:
  D.9811 = iftmp.8 != 0;
  D.9812 = (long int) D.9811;
  D.9813 = __builtin_expect (D.9812, 0);
  if (D.9813 != 0) goto <D.9814>; else goto <D.9815>;
  <D.9814>:
  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.9815>:
  D.9816 = idx / 256;
  D.9817 = _wapi_private_handles[D.9816];
  D.9818 = (long unsigned int) idx;
  D.9819 = D.9818 & 255;
  D.9820 = D.9819 * 200;
  handle_data = D.9817 + D.9820;
  ref = &handle_data->u.shared;
  _wapi_shared_layout.9 = _wapi_shared_layout;
  D.9822 = ref->offset;
  shared_data = &_wapi_shared_layout.9->handles[D.9822];
  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.9826;

  mono_once (&sem_ops_once, sem_ops_init);
  if (max <= 0) goto <D.9824>; else goto <D.9825>;
  <D.9824>:
  SetLastError (87);
  D.9826 = 0B;
  return D.9826;
  <D.9825>:
  if (initial > max) goto <D.9827>; else goto <D.9829>;
  <D.9829>:
  if (initial < 0) goto <D.9827>; else goto <D.9828>;
  <D.9827>:
  SetLastError (87);
  D.9826 = 0B;
  return D.9826;
  <D.9828>:
  if (name == 0B) goto <D.9830>; else goto <D.9831>;
  <D.9830>:
  D.9826 = sem_create (security, initial, max);
  return D.9826;
  <D.9831>:
  D.9826 = namedsem_create (security, initial, max, name);
  return D.9826;
}


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.10;
  void * D.9836;
  long int D.9837;
  long int D.9838;
  _Bool D.9841;
  long int D.9842;
  long int D.9843;
  struct _WapiHandle_sem sem_handle;
  void * handle;
  int thr_ret;
  static const char __func__[11] = "sem_create";

  try
    {
      sem_handle = {};
      SetLastError (0);
      initial.10 = (unsigned int) initial;
      sem_handle.val = initial.10;
      sem_handle.max = max;
      handle = _wapi_handle_new (4, &sem_handle);
      if (handle == -1B) goto <D.9834>; else goto <D.9835>;
      <D.9834>:
      monoeg_g_log (0B, 16, "%s: error creating semaphore handle", &__func__);
      SetLastError (31);
      D.9836 = 0B;
      return D.9836;
      <D.9835>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc6>) (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.9837 = (long int) __not_first_call;
            D.9838 = __builtin_expect (D.9837, 0);
            if (D.9838 != 0) goto <D.9839>; else goto <D.9840>;
            <D.9839>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9840>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9841 = thr_ret != 0;
            D.9842 = (long int) D.9841;
            D.9843 = __builtin_expect (D.9842, 0);
            if (D.9843 != 0) goto <D.9844>; else goto <D.9845>;
            <D.9844>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 188, "thr_ret == 0");
            <D.9845>:
            if (initial != 0) goto <D.9846>; else goto <D.9847>;
            <D.9846>:
            _wapi_handle_set_signal_state (handle, 1, 0);
            <D.9847>:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9841 = thr_ret != 0;
            D.9842 = (long int) D.9841;
            D.9843 = __builtin_expect (D.9842, 0);
            if (D.9843 != 0) goto <D.9848>; else goto <D.9849>;
            <D.9848>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 198, "thr_ret == 0");
            <D.9849>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9850>; else goto <D.9851>;
            <D.9850>:
            __cancel_routine (__cancel_arg);
            <D.9851>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9836 = handle;
      return D.9836;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  long int handle.11;
  int D.9860;
  <unnamed type> D.9863;
  <unnamed type> D.9865;
  <unnamed type> D.9867;
  <unnamed type> D.9869;
  unsigned int D.9870;
  struct _WapiHandleUnshared * D.9871;
  long unsigned int D.9872;
  long unsigned int D.9873;
  long unsigned int D.9874;
  struct _WapiHandleUnshared * D.9875;
  union mono_mutex_t * D.9876;
  guint32 idx;

  handle.11 = (long int) handle;
  idx = (guint32) handle.11;
  if (idx > 4194303) goto <D.9858>; else goto <D.9859>;
  <D.9858>:
  D.9860 = 0;
  return D.9860;
  <D.9859>:
  _wapi_handle_ref (handle);
  D.9863 = _wapi_handle_type (handle);
  if (D.9863 == 9) goto <D.9861>; else goto <D.9864>;
  <D.9864>:
  D.9865 = _wapi_handle_type (handle);
  if (D.9865 == 11) goto <D.9861>; else goto <D.9866>;
  <D.9866>:
  D.9867 = _wapi_handle_type (handle);
  if (D.9867 == 12) goto <D.9861>; else goto <D.9868>;
  <D.9868>:
  D.9869 = _wapi_handle_type (handle);
  if (D.9869 == 13) goto <D.9861>; else goto <D.9862>;
  <D.9861>:
  D.9860 = 0;
  return D.9860;
  <D.9862>:
  D.9870 = idx / 256;
  D.9871 = _wapi_private_handles[D.9870];
  D.9872 = (long unsigned int) idx;
  D.9873 = D.9872 & 255;
  D.9874 = D.9873 * 200;
  D.9875 = D.9871 + D.9874;
  D.9876 = &D.9875->signal_mutex;
  D.9860 = pthread_mutex_lock (D.9876);
  return D.9860;
}


_wapi_handle_unlock_handle (void * handle)
{
  long int handle.12;
  int D.9881;
  <unnamed type> D.9884;
  <unnamed type> D.9886;
  <unnamed type> D.9888;
  <unnamed type> D.9890;
  unsigned int D.9891;
  struct _WapiHandleUnshared * D.9892;
  long unsigned int D.9893;
  long unsigned int D.9894;
  long unsigned int D.9895;
  struct _WapiHandleUnshared * D.9896;
  union mono_mutex_t * D.9897;
  guint32 idx;
  int ret;

  handle.12 = (long int) handle;
  idx = (guint32) handle.12;
  if (idx > 4194303) goto <D.9879>; else goto <D.9880>;
  <D.9879>:
  D.9881 = 0;
  return D.9881;
  <D.9880>:
  D.9884 = _wapi_handle_type (handle);
  if (D.9884 == 9) goto <D.9882>; else goto <D.9885>;
  <D.9885>:
  D.9886 = _wapi_handle_type (handle);
  if (D.9886 == 11) goto <D.9882>; else goto <D.9887>;
  <D.9887>:
  D.9888 = _wapi_handle_type (handle);
  if (D.9888 == 12) goto <D.9882>; else goto <D.9889>;
  <D.9889>:
  D.9890 = _wapi_handle_type (handle);
  if (D.9890 == 13) goto <D.9882>; else goto <D.9883>;
  <D.9882>:
  _wapi_handle_unref (handle);
  D.9881 = 0;
  return D.9881;
  <D.9883>:
  D.9891 = idx / 256;
  D.9892 = _wapi_private_handles[D.9891];
  D.9893 = (long unsigned int) idx;
  D.9894 = D.9893 & 255;
  D.9895 = D.9894 * 200;
  D.9896 = D.9892 + D.9895;
  D.9897 = &D.9896->signal_mutex;
  ret = pthread_mutex_unlock (D.9897);
  _wapi_handle_unref (handle);
  D.9881 = ret;
  return D.9881;
}


namedsem_create (struct WapiSecurityAttributes * security, gint32 initial, gint32 max, const gunichar2 * name)
{
  _Bool D.9899;
  long int D.9900;
  long int D.9901;
  long unsigned int D.9910;
  long unsigned int D.9913;
  long unsigned int D.9915;
  unsigned int initial.13;
  unsigned int offset.14;
  void * D.9927;
  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.9899 = thr_ret != 0;
      D.9900 = (long int) D.9899;
      D.9901 = __builtin_expect (D.9900, 0);
      if (D.9901 != 0) goto <D.9902>; else goto <D.9903>;
      <D.9902>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 218, "thr_ret == 0");
      <D.9903>:
      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.9904>; else goto <D.9905>;
      <D.9904>:
      SetLastError (6);
      goto cleanup;
      <D.9905>:
      if (offset != 0) goto <D.9906>; else goto <D.9907>;
      <D.9906>:
      SetLastError (183);
      <D.9907>:
      if (offset == 0) goto <D.9908>; else goto <D.9909>;
      <D.9908>:
      D.9910 = __strlen_g (utf8_name);
      if (D.9910 <= 259) goto <D.9911>; else goto <D.9912>;
      <D.9911>:
      D.9913 = __strlen_g (utf8_name);
      namelen = (guint32) D.9913;
      goto <D.9914>;
      <D.9912>:
      namelen = 260;
      <D.9914>:
      D.9915 = (long unsigned int) namelen;
      memcpy (&namedsem_handle.sharedns.name, utf8_name, D.9915);
      initial.13 = (unsigned int) initial;
      namedsem_handle.val = initial.13;
      namedsem_handle.max = max;
      handle = _wapi_handle_new (12, &namedsem_handle);
      goto <D.9917>;
      <D.9909>:
      offset.14 = (unsigned int) offset;
      handle = _wapi_handle_new_from_offset (12, offset.14, 1);
      <D.9917>:
      if (handle == -1B) goto <D.9919>; else goto <D.9920>;
      <D.9919>:
      monoeg_g_log (0B, 16, "%s: error creating named sem handle", &__func__);
      SetLastError (31);
      goto cleanup;
      <D.9920>:
      ret = handle;
      if (offset == 0) goto <D.9921>; else goto <D.9922>;
      <D.9921>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.9899 = thr_ret != 0;
      D.9900 = (long int) D.9899;
      D.9901 = __builtin_expect (D.9900, 0);
      if (D.9901 != 0) goto <D.9923>; else goto <D.9924>;
      <D.9923>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 283, "thr_ret == 0");
      <D.9924>:
      if (initial != 0) goto <D.9925>; else goto <D.9926>;
      <D.9925>:
      _wapi_shared_handle_set_signal_state (handle, 1);
      <D.9926>:
      _wapi_handle_unlock_shared_handles ();
      <D.9922>:
      cleanup:
      monoeg_g_free (utf8_name);
      _wapi_namespace_unlock (0B);
      D.9927 = ret;
      return D.9927;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_namespace_lock ()
{
  int D.9930;

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


__attribute__((__gnu_inline__))
__strlen_g (const char * __str)
{
  size_t D.9932;
  long int __ptr.15;
  long int __str.16;
  long int D.9935;
  char * __ptr;
  char * __tmp;

  __ptr = 0B;
  __tmp = __str;
  __asm__ __volatile__("   la    0,0
0: srst  %0,%1
   jo    0b
" : "=&a" __ptr, "=&a" __tmp : "0" __ptr, "1" __tmp : "0", "memory", "cc");
  __ptr.15 = (long int) __ptr;
  __str.16 = (long int) __str;
  D.9935 = __ptr.15 - __str.16;
  D.9932 = (size_t) D.9935;
  return D.9932;
}


__attribute__((__artificial__, __gnu_inline__, __always_inline__, __nothrow__, __leaf__))
memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.9937;
  long unsigned int D.9938;

  D.9938 = __builtin_object_size (__dest, 0);
  D.9937 = __builtin___memcpy_chk (__dest, __src, __len, D.9938);
  return D.9937;
}


_wapi_handle_lock_shared_handles ()
{
  int D.9940;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.9942;

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


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

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


ReleaseSemaphore (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9948;
  gboolean (*<T1758>) (void *, gint32, gint32 *) D.9949;
  WapiHandleType type;

  if (handle == 0B) goto <D.9946>; else goto <D.9947>;
  <D.9946>:
  SetLastError (6);
  D.9948 = 0;
  return D.9948;
  <D.9947>:
  type = _wapi_handle_type (handle);
  D.9949 = sem_ops[type].release;
  if (D.9949 == 0B) goto <D.9950>; else goto <D.9951>;
  <D.9950>:
  SetLastError (6);
  D.9948 = 0;
  return D.9948;
  <D.9951>:
  D.9949 = sem_ops[type].release;
  D.9948 = D.9949 (handle, count, prevcount);
  return D.9948;
}


namedsem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9955;
  _Bool D.9956;
  long int D.9957;
  long int D.9958;
  struct _WapiHandle_namedsem * sem_handle.17;
  unsigned int D.9964;
  int D.9965;
  unsigned int count.18;
  unsigned int D.9967;
  int D.9968;
  unsigned int D.9969;
  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.9953>; else goto <D.9954>;
      <D.9953>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9955 = 0;
      return D.9955;
      <D.9954>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.9956 = thr_ret != 0;
      D.9957 = (long int) D.9956;
      D.9958 = __builtin_expect (D.9957, 0);
      if (D.9958 != 0) goto <D.9959>; else goto <D.9960>;
      <D.9959>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 415, "thr_ret == 0");
      <D.9960>:
      if (prevcount != 0B) goto <D.9961>; else goto <D.9962>;
      <D.9961>:
      sem_handle.17 = sem_handle;
      D.9964 = sem_handle.17->val;
      D.9965 = (int) D.9964;
      *prevcount = D.9965;
      <D.9962>:
      sem_handle.17 = sem_handle;
      D.9964 = sem_handle.17->val;
      count.18 = (unsigned int) count;
      D.9967 = D.9964 + count.18;
      sem_handle.17 = sem_handle;
      D.9968 = sem_handle.17->max;
      D.9969 = (unsigned int) D.9968;
      if (D.9967 > D.9969) goto end; else goto <D.9970>;
      <D.9970>:
      sem_handle.17 = sem_handle;
      sem_handle.17 = sem_handle;
      D.9964 = sem_handle.17->val;
      count.18 = (unsigned int) count;
      D.9967 = D.9964 + count.18;
      sem_handle.17->val = D.9967;
      _wapi_shared_handle_set_signal_state (handle, 1);
      ret = 1;
      end:
      _wapi_handle_unlock_shared_handles ();
      D.9955 = ret;
      return D.9955;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


sem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.9975;
  long int D.9976;
  long int D.9977;
  _Bool D.9980;
  long int D.9981;
  long int D.9982;
  struct _WapiHandle_sem * sem_handle.19;
  unsigned int D.9988;
  int D.9989;
  unsigned int count.20;
  unsigned int D.9991;
  int D.9992;
  unsigned int D.9993;
  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.9973>; else goto <D.9974>;
      <D.9973>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.9975 = 0;
      return D.9975;
      <D.9974>:
      {
        struct __pthread_unwind_buf_t __cancel_buf;
        void (*<Tc6>) (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.9976 = (long int) __not_first_call;
            D.9977 = __builtin_expect (D.9976, 0);
            if (D.9977 != 0) goto <D.9978>; else goto <D.9979>;
            <D.9978>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.9979>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.9980 = thr_ret != 0;
            D.9981 = (long int) D.9980;
            D.9982 = __builtin_expect (D.9981, 0);
            if (D.9982 != 0) goto <D.9983>; else goto <D.9984>;
            <D.9983>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 364, "thr_ret == 0");
            <D.9984>:
            if (prevcount != 0B) goto <D.9985>; else goto <D.9986>;
            <D.9985>:
            sem_handle.19 = sem_handle;
            D.9988 = sem_handle.19->val;
            D.9989 = (int) D.9988;
            *prevcount = D.9989;
            <D.9986>:
            sem_handle.19 = sem_handle;
            D.9988 = sem_handle.19->val;
            count.20 = (unsigned int) count;
            D.9991 = D.9988 + count.20;
            sem_handle.19 = sem_handle;
            D.9992 = sem_handle.19->max;
            D.9993 = (unsigned int) D.9992;
            if (D.9991 > D.9993) goto end; else goto <D.9994>;
            <D.9994>:
            sem_handle.19 = sem_handle;
            sem_handle.19 = sem_handle;
            D.9988 = sem_handle.19->val;
            count.20 = (unsigned int) count;
            D.9991 = D.9988 + count.20;
            sem_handle.19->val = D.9991;
            _wapi_handle_set_signal_state (handle, 1, 1);
            ret = 1;
            end:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.9980 = thr_ret != 0;
            D.9981 = (long int) D.9980;
            D.9982 = __builtin_expect (D.9981, 0);
            if (D.9982 != 0) goto <D.9995>; else goto <D.9996>;
            <D.9995>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 392, "thr_ret == 0");
            <D.9996>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.9997>; else goto <D.9998>;
            <D.9997>:
            __cancel_routine (__cancel_arg);
            <D.9998>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.9975 = ret;
      return D.9975;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


OpenSemaphore (guint32 access, gboolean inherit, const gunichar2 * name)
{
  _Bool D.10004;
  long int D.10005;
  long int D.10006;
  unsigned int offset.21;
  void * D.10016;
  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.10004 = thr_ret != 0;
  D.10005 = (long int) D.10004;
  D.10006 = __builtin_expect (D.10005, 0);
  if (D.10006 != 0) goto <D.10007>; else goto <D.10008>;
  <D.10007>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 494, "thr_ret == 0");
  <D.10008>:
  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.10009>; else goto <D.10010>;
  <D.10009>:
  SetLastError (6);
  goto cleanup;
  <D.10010>:
  if (offset == 0) goto <D.10011>; else goto <D.10012>;
  <D.10011>:
  SetLastError (2);
  goto cleanup;
  <D.10012>:
  offset.21 = (unsigned int) offset;
  handle = _wapi_handle_new_from_offset (12, offset.21, 1);
  if (handle == -1B) goto <D.10014>; else goto <D.10015>;
  <D.10014>:
  monoeg_g_log (0B, 16, "%s: error opening named sem handle", &__func__);
  SetLastError (31);
  goto cleanup;
  <D.10015>:
  ret = handle;
  cleanup:
  monoeg_g_free (utf8_name);
  _wapi_namespace_unlock (0B);
  D.10016 = ret;
  return D.10016;
}


