sema_own (void * handle)
{
  gboolean D.10033;
  struct _WapiHandle_sem * sem_handle.0;
  unsigned int D.10035;
  unsigned int D.10036;
  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.10031>; else goto <D.10032>;
      <D.10031>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.10033 = 0;
      return D.10033;
      <D.10032>:
      sem_handle.0 = sem_handle;
      D.10035 = sem_handle.0->val;
      D.10036 = D.10035 + 4294967295;
      sem_handle.0->val = D.10036;
      sem_handle.0 = sem_handle;
      D.10035 = sem_handle.0->val;
      if (D.10035 == 0) goto <D.10037>; else goto <D.10038>;
      <D.10037>:
      _wapi_handle_set_signal_state (handle, 0, 0);
      <D.10038>:
      D.10033 = 1;
      return D.10033;
    }
  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.10048;
  <unnamed type> D.10050;
  <unnamed type> D.10052;
  <unnamed type> D.10054;
  _Bool D.10055;
  long int D.10056;
  long int D.10057;
  unsigned int D.10060;
  struct _WapiHandleUnshared * D.10061;
  long unsigned int D.10062;
  long unsigned int D.10063;
  long unsigned int D.10064;
  long int D.10067;
  long int D.10068;
  union mono_mutex_t * _wapi_global_signal_mutex.3;
  _Bool D.10074;
  long int D.10075;
  long int D.10076;
  union pthread_cond_t * D.10081;
  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.10042>; else goto <D.10043>;
  <D.10042>:
  return;
  <D.10043>:
  D.10048 = _wapi_handle_type (handle);
  if (D.10048 == 9) goto <D.10045>; else goto <D.10049>;
  <D.10049>:
  D.10050 = _wapi_handle_type (handle);
  if (D.10050 == 11) goto <D.10045>; else goto <D.10051>;
  <D.10051>:
  D.10052 = _wapi_handle_type (handle);
  if (D.10052 == 12) goto <D.10045>; else goto <D.10053>;
  <D.10053>:
  D.10054 = _wapi_handle_type (handle);
  if (D.10054 == 13) goto <D.10045>; else goto <D.10046>;
  <D.10045>:
  iftmp.2 = 1;
  goto <D.10047>;
  <D.10046>:
  iftmp.2 = 0;
  <D.10047>:
  D.10055 = iftmp.2 != 0;
  D.10056 = (long int) D.10055;
  D.10057 = __builtin_expect (D.10056, 0);
  if (D.10057 != 0) goto <D.10058>; else goto <D.10059>;
  <D.10058>:
  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.10059>:
  D.10060 = idx / 256;
  D.10061 = _wapi_private_handles[D.10060];
  D.10062 = (long unsigned int) idx;
  D.10063 = D.10062 & 255;
  D.10064 = D.10063 * 200;
  handle_data = D.10061 + D.10064;
  if (state == 1) goto <D.10065>; else goto <D.10066>;
  <D.10065>:
  {
    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.10067 = (long int) __not_first_call;
        D.10068 = __builtin_expect (D.10067, 0);
        if (D.10068 != 0) goto <D.10069>; else goto <D.10070>;
        <D.10069>:
        __cancel_routine (__cancel_arg);
        __pthread_unwind_next (&__cancel_buf);
        <D.10070>:
        __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.10072>; else goto <D.10073>;
        <D.10072>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
        <D.10073>:
        D.10074 = thr_ret != 0;
        D.10075 = (long int) D.10074;
        D.10076 = __builtin_expect (D.10075, 0);
        if (D.10076 != 0) goto <D.10077>; else goto <D.10078>;
        <D.10077>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 151, "thr_ret == 0");
        <D.10078>:
        handle_data->signalled = state;
        if (broadcast == 1) goto <D.10079>; else goto <D.10080>;
        <D.10079>:
        D.10081 = &handle_data->signal_cond;
        thr_ret = pthread_cond_broadcast (D.10081);
        if (thr_ret != 0) goto <D.10082>; else goto <D.10083>;
        <D.10082>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.10083>:
        D.10074 = thr_ret != 0;
        D.10075 = (long int) D.10074;
        D.10076 = __builtin_expect (D.10075, 0);
        if (D.10076 != 0) goto <D.10084>; else goto <D.10085>;
        <D.10084>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 162, "thr_ret == 0");
        <D.10085>:
        goto <D.10086>;
        <D.10080>:
        D.10081 = &handle_data->signal_cond;
        thr_ret = pthread_cond_signal (D.10081);
        if (thr_ret != 0) goto <D.10087>; else goto <D.10088>;
        <D.10087>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
        <D.10088>:
        D.10074 = thr_ret != 0;
        D.10075 = (long int) D.10074;
        D.10076 = __builtin_expect (D.10075, 0);
        if (D.10076 != 0) goto <D.10089>; else goto <D.10090>;
        <D.10089>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 167, "thr_ret == 0");
        <D.10090>:
        <D.10086>:
        _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.10092>; else goto <D.10093>;
        <D.10092>:
        monoeg_g_log (0B, 16, "Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
        <D.10093>:
        D.10074 = thr_ret != 0;
        D.10075 = (long int) D.10074;
        D.10076 = __builtin_expect (D.10075, 0);
        if (D.10076 != 0) goto <D.10094>; else goto <D.10095>;
        <D.10094>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 176, "thr_ret == 0");
        <D.10095>:
        _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.10096>; else goto <D.10097>;
        <D.10096>:
        monoeg_g_log (0B, 16, "Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
        <D.10097>:
        D.10074 = thr_ret != 0;
        D.10075 = (long int) D.10074;
        D.10076 = __builtin_expect (D.10075, 0);
        if (D.10076 != 0) goto <D.10098>; else goto <D.10099>;
        <D.10098>:
        monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "../../mono/io-layer/handles-private.h", 181, "thr_ret == 0");
        <D.10099>:
        __pthread_unregister_cancel (&__cancel_buf);
        if (0 != 0) goto <D.10100>; else goto <D.10101>;
        <D.10100>:
        __cancel_routine (__cancel_arg);
        <D.10101>:
      }
    finally
      {
        __cancel_buf = {CLOBBER};
      }
  }
  goto <D.10102>;
  <D.10066>:
  handle_data->signalled = state;
  <D.10102>:
}


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

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


_wapi_handle_type (void * handle)
{
  long int handle.5;
  unsigned int D.10120;
  struct _WapiHandleUnshared * D.10121;
  WapiHandleType D.10122;
  unsigned int D.10123;
  struct _WapiHandleUnshared * D.10124;
  long unsigned int D.10125;
  long unsigned int D.10126;
  long unsigned int D.10127;
  struct _WapiHandleUnshared * D.10128;
  guint32 idx;

  handle.5 = (long int) handle;
  idx = (guint32) handle.5;
  if (idx > 4194303) goto <D.10116>; else goto <D.10118>;
  <D.10118>:
  if (idx > 268435455) goto <D.10116>; else goto <D.10119>;
  <D.10119>:
  D.10120 = idx / 256;
  D.10121 = _wapi_private_handles[D.10120];
  if (D.10121 == 0B) goto <D.10116>; else goto <D.10117>;
  <D.10116>:
  D.10122 = 0;
  return D.10122;
  <D.10117>:
  D.10123 = idx / 256;
  D.10124 = _wapi_private_handles[D.10123];
  D.10125 = (long unsigned int) idx;
  D.10126 = D.10125 & 255;
  D.10127 = D.10126 * 200;
  D.10128 = D.10124 + D.10127;
  D.10122 = D.10128->type;
  return D.10122;
}


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


_wapi_sem_details (void * handle_info)
{
  unsigned int D.10130;
  int D.10131;
  struct _WapiHandle_sem * sem;

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


namedsema_own (void * handle)
{
  gboolean D.10134;
  struct _WapiHandle_namedsem * namedsem_handle.6;
  unsigned int D.10136;
  unsigned int D.10137;
  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.10132>; else goto <D.10133>;
      <D.10132>:
      monoeg_g_log (0B, 16, "%s: error looking up named sem handle %p", &__func__, handle);
      D.10134 = 0;
      return D.10134;
      <D.10133>:
      namedsem_handle.6 = namedsem_handle;
      D.10136 = namedsem_handle.6->val;
      D.10137 = D.10136 + 4294967295;
      namedsem_handle.6->val = D.10137;
      namedsem_handle.6 = namedsem_handle;
      D.10136 = namedsem_handle.6->val;
      if (D.10136 == 0) goto <D.10138>; else goto <D.10139>;
      <D.10138>:
      _wapi_shared_handle_set_signal_state (handle, 0);
      <D.10139>:
      D.10134 = 1;
      return D.10134;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_shared_handle_set_signal_state (void * handle, gboolean state)
{
  long int handle.7;
  int iftmp.8;
  <unnamed type> D.10148;
  <unnamed type> D.10150;
  <unnamed type> D.10152;
  <unnamed type> D.10154;
  _Bool D.10156;
  long int D.10157;
  long int D.10158;
  unsigned int D.10161;
  struct _WapiHandleUnshared * D.10162;
  long unsigned int D.10163;
  long unsigned int D.10164;
  long unsigned int D.10165;
  struct _WapiHandleSharedLayout * _wapi_shared_layout.9;
  unsigned int D.10167;
  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.10143>; else goto <D.10144>;
  <D.10143>:
  return;
  <D.10144>:
  D.10148 = _wapi_handle_type (handle);
  if (D.10148 != 9) goto <D.10149>; else goto <D.10146>;
  <D.10149>:
  D.10150 = _wapi_handle_type (handle);
  if (D.10150 != 11) goto <D.10151>; else goto <D.10146>;
  <D.10151>:
  D.10152 = _wapi_handle_type (handle);
  if (D.10152 != 12) goto <D.10153>; else goto <D.10146>;
  <D.10153>:
  D.10154 = _wapi_handle_type (handle);
  if (D.10154 != 13) goto <D.10155>; else goto <D.10146>;
  <D.10155>:
  iftmp.8 = 1;
  goto <D.10147>;
  <D.10146>:
  iftmp.8 = 0;
  <D.10147>:
  D.10156 = iftmp.8 != 0;
  D.10157 = (long int) D.10156;
  D.10158 = __builtin_expect (D.10157, 0);
  if (D.10158 != 0) goto <D.10159>; else goto <D.10160>;
  <D.10159>:
  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.10160>:
  D.10161 = idx / 256;
  D.10162 = _wapi_private_handles[D.10161];
  D.10163 = (long unsigned int) idx;
  D.10164 = D.10163 & 255;
  D.10165 = D.10164 * 200;
  handle_data = D.10162 + D.10165;
  ref = &handle_data->u.shared;
  _wapi_shared_layout.9 = _wapi_shared_layout;
  D.10167 = ref->offset;
  shared_data = &_wapi_shared_layout.9->handles[D.10167];
  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.10171;

  mono_once (&sem_ops_once, sem_ops_init);
  if (max <= 0) goto <D.10169>; else goto <D.10170>;
  <D.10169>:
  SetLastError (87);
  D.10171 = 0B;
  return D.10171;
  <D.10170>:
  if (initial > max) goto <D.10172>; else goto <D.10174>;
  <D.10174>:
  if (initial < 0) goto <D.10172>; else goto <D.10173>;
  <D.10172>:
  SetLastError (87);
  D.10171 = 0B;
  return D.10171;
  <D.10173>:
  if (name == 0B) goto <D.10175>; else goto <D.10176>;
  <D.10175>:
  D.10171 = sem_create (security, initial, max);
  return D.10171;
  <D.10176>:
  D.10171 = namedsem_create (security, initial, max, name);
  return D.10171;
}


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.10181;
  long int D.10182;
  long int D.10183;
  _Bool D.10186;
  long int D.10187;
  long int D.10188;
  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.10179>; else goto <D.10180>;
      <D.10179>:
      monoeg_g_log (0B, 16, "%s: error creating semaphore handle", &__func__);
      SetLastError (31);
      D.10181 = 0B;
      return D.10181;
      <D.10180>:
      {
        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.10182 = (long int) __not_first_call;
            D.10183 = __builtin_expect (D.10182, 0);
            if (D.10183 != 0) goto <D.10184>; else goto <D.10185>;
            <D.10184>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10185>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.10186 = thr_ret != 0;
            D.10187 = (long int) D.10186;
            D.10188 = __builtin_expect (D.10187, 0);
            if (D.10188 != 0) goto <D.10189>; else goto <D.10190>;
            <D.10189>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 188, "thr_ret == 0");
            <D.10190>:
            if (initial != 0) goto <D.10191>; else goto <D.10192>;
            <D.10191>:
            _wapi_handle_set_signal_state (handle, 1, 0);
            <D.10192>:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.10186 = thr_ret != 0;
            D.10187 = (long int) D.10186;
            D.10188 = __builtin_expect (D.10187, 0);
            if (D.10188 != 0) goto <D.10193>; else goto <D.10194>;
            <D.10193>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 198, "thr_ret == 0");
            <D.10194>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.10195>; else goto <D.10196>;
            <D.10195>:
            __cancel_routine (__cancel_arg);
            <D.10196>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.10181 = handle;
      return D.10181;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


_wapi_handle_lock_handle (void * handle)
{
  long int handle.11;
  int D.10205;
  <unnamed type> D.10208;
  <unnamed type> D.10210;
  <unnamed type> D.10212;
  <unnamed type> D.10214;
  unsigned int D.10215;
  struct _WapiHandleUnshared * D.10216;
  long unsigned int D.10217;
  long unsigned int D.10218;
  long unsigned int D.10219;
  struct _WapiHandleUnshared * D.10220;
  union mono_mutex_t * D.10221;
  guint32 idx;

  handle.11 = (long int) handle;
  idx = (guint32) handle.11;
  if (idx > 4194303) goto <D.10203>; else goto <D.10204>;
  <D.10203>:
  D.10205 = 0;
  return D.10205;
  <D.10204>:
  _wapi_handle_ref (handle);
  D.10208 = _wapi_handle_type (handle);
  if (D.10208 == 9) goto <D.10206>; else goto <D.10209>;
  <D.10209>:
  D.10210 = _wapi_handle_type (handle);
  if (D.10210 == 11) goto <D.10206>; else goto <D.10211>;
  <D.10211>:
  D.10212 = _wapi_handle_type (handle);
  if (D.10212 == 12) goto <D.10206>; else goto <D.10213>;
  <D.10213>:
  D.10214 = _wapi_handle_type (handle);
  if (D.10214 == 13) goto <D.10206>; else goto <D.10207>;
  <D.10206>:
  D.10205 = 0;
  return D.10205;
  <D.10207>:
  D.10215 = idx / 256;
  D.10216 = _wapi_private_handles[D.10215];
  D.10217 = (long unsigned int) idx;
  D.10218 = D.10217 & 255;
  D.10219 = D.10218 * 200;
  D.10220 = D.10216 + D.10219;
  D.10221 = &D.10220->signal_mutex;
  D.10205 = pthread_mutex_lock (D.10221);
  return D.10205;
}


_wapi_handle_unlock_handle (void * handle)
{
  long int handle.12;
  int D.10226;
  <unnamed type> D.10229;
  <unnamed type> D.10231;
  <unnamed type> D.10233;
  <unnamed type> D.10235;
  unsigned int D.10236;
  struct _WapiHandleUnshared * D.10237;
  long unsigned int D.10238;
  long unsigned int D.10239;
  long unsigned int D.10240;
  struct _WapiHandleUnshared * D.10241;
  union mono_mutex_t * D.10242;
  guint32 idx;
  int ret;

  handle.12 = (long int) handle;
  idx = (guint32) handle.12;
  if (idx > 4194303) goto <D.10224>; else goto <D.10225>;
  <D.10224>:
  D.10226 = 0;
  return D.10226;
  <D.10225>:
  D.10229 = _wapi_handle_type (handle);
  if (D.10229 == 9) goto <D.10227>; else goto <D.10230>;
  <D.10230>:
  D.10231 = _wapi_handle_type (handle);
  if (D.10231 == 11) goto <D.10227>; else goto <D.10232>;
  <D.10232>:
  D.10233 = _wapi_handle_type (handle);
  if (D.10233 == 12) goto <D.10227>; else goto <D.10234>;
  <D.10234>:
  D.10235 = _wapi_handle_type (handle);
  if (D.10235 == 13) goto <D.10227>; else goto <D.10228>;
  <D.10227>:
  _wapi_handle_unref (handle);
  D.10226 = 0;
  return D.10226;
  <D.10228>:
  D.10236 = idx / 256;
  D.10237 = _wapi_private_handles[D.10236];
  D.10238 = (long unsigned int) idx;
  D.10239 = D.10238 & 255;
  D.10240 = D.10239 * 200;
  D.10241 = D.10237 + D.10240;
  D.10242 = &D.10241->signal_mutex;
  ret = pthread_mutex_unlock (D.10242);
  _wapi_handle_unref (handle);
  D.10226 = ret;
  return D.10226;
}


namedsem_create (struct WapiSecurityAttributes * security, gint32 initial, gint32 max, const gunichar2 * name)
{
  _Bool D.10244;
  long int D.10245;
  long int D.10246;
  long unsigned int D.10255;
  long unsigned int D.10258;
  long unsigned int D.10260;
  unsigned int initial.13;
  unsigned int offset.14;
  void * D.10272;
  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.10244 = thr_ret != 0;
      D.10245 = (long int) D.10244;
      D.10246 = __builtin_expect (D.10245, 0);
      if (D.10246 != 0) goto <D.10247>; else goto <D.10248>;
      <D.10247>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 218, "thr_ret == 0");
      <D.10248>:
      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.10249>; else goto <D.10250>;
      <D.10249>:
      SetLastError (6);
      goto cleanup;
      <D.10250>:
      if (offset != 0) goto <D.10251>; else goto <D.10252>;
      <D.10251>:
      SetLastError (183);
      <D.10252>:
      if (offset == 0) goto <D.10253>; else goto <D.10254>;
      <D.10253>:
      D.10255 = strlen (utf8_name);
      if (D.10255 <= 259) goto <D.10256>; else goto <D.10257>;
      <D.10256>:
      D.10258 = strlen (utf8_name);
      namelen = (guint32) D.10258;
      goto <D.10259>;
      <D.10257>:
      namelen = 260;
      <D.10259>:
      D.10260 = (long unsigned int) namelen;
      memcpy (&namedsem_handle.sharedns.name, utf8_name, D.10260);
      initial.13 = (unsigned int) initial;
      namedsem_handle.val = initial.13;
      namedsem_handle.max = max;
      handle = _wapi_handle_new (12, &namedsem_handle);
      goto <D.10262>;
      <D.10254>:
      offset.14 = (unsigned int) offset;
      handle = _wapi_handle_new_from_offset (12, offset.14, 1);
      <D.10262>:
      if (handle == -1B) goto <D.10264>; else goto <D.10265>;
      <D.10264>:
      monoeg_g_log (0B, 16, "%s: error creating named sem handle", &__func__);
      SetLastError (31);
      goto cleanup;
      <D.10265>:
      ret = handle;
      if (offset == 0) goto <D.10266>; else goto <D.10267>;
      <D.10266>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.10244 = thr_ret != 0;
      D.10245 = (long int) D.10244;
      D.10246 = __builtin_expect (D.10245, 0);
      if (D.10246 != 0) goto <D.10268>; else goto <D.10269>;
      <D.10268>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 283, "thr_ret == 0");
      <D.10269>:
      if (initial != 0) goto <D.10270>; else goto <D.10271>;
      <D.10270>:
      _wapi_shared_handle_set_signal_state (handle, 1);
      <D.10271>:
      _wapi_handle_unlock_shared_handles ();
      <D.10267>:
      cleanup:
      monoeg_g_free (utf8_name);
      _wapi_namespace_unlock (0B);
      D.10272 = ret;
      return D.10272;
    }
  finally
    {
      namedsem_handle = {CLOBBER};
    }
}


_wapi_namespace_lock ()
{
  int D.10275;

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


memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.10277;
  long unsigned int D.10278;

  D.10278 = __builtin_object_size (__dest, 0);
  D.10277 = __builtin___memcpy_chk (__dest, __src, __len, D.10278);
  return D.10277;
}


_wapi_handle_lock_shared_handles ()
{
  int D.10280;

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


_wapi_handle_unlock_shared_handles ()
{
  int D.10282;

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


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

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


ReleaseSemaphore (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.10288;
  gboolean (*<T1677>) (void *, gint32, gint32 *) D.10289;
  WapiHandleType type;

  if (handle == 0B) goto <D.10286>; else goto <D.10287>;
  <D.10286>:
  SetLastError (6);
  D.10288 = 0;
  return D.10288;
  <D.10287>:
  type = _wapi_handle_type (handle);
  D.10289 = sem_ops[type].release;
  if (D.10289 == 0B) goto <D.10290>; else goto <D.10291>;
  <D.10290>:
  SetLastError (6);
  D.10288 = 0;
  return D.10288;
  <D.10291>:
  D.10289 = sem_ops[type].release;
  D.10288 = D.10289 (handle, count, prevcount);
  return D.10288;
}


namedsem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.10295;
  _Bool D.10296;
  long int D.10297;
  long int D.10298;
  struct _WapiHandle_namedsem * sem_handle.15;
  unsigned int D.10304;
  int D.10305;
  unsigned int count.16;
  unsigned int D.10307;
  int D.10308;
  unsigned int D.10309;
  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.10293>; else goto <D.10294>;
      <D.10293>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.10295 = 0;
      return D.10295;
      <D.10294>:
      thr_ret = _wapi_handle_lock_shared_handles ();
      D.10296 = thr_ret != 0;
      D.10297 = (long int) D.10296;
      D.10298 = __builtin_expect (D.10297, 0);
      if (D.10298 != 0) goto <D.10299>; else goto <D.10300>;
      <D.10299>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 415, "thr_ret == 0");
      <D.10300>:
      if (prevcount != 0B) goto <D.10301>; else goto <D.10302>;
      <D.10301>:
      sem_handle.15 = sem_handle;
      D.10304 = sem_handle.15->val;
      D.10305 = (int) D.10304;
      *prevcount = D.10305;
      <D.10302>:
      sem_handle.15 = sem_handle;
      D.10304 = sem_handle.15->val;
      count.16 = (unsigned int) count;
      D.10307 = D.10304 + count.16;
      sem_handle.15 = sem_handle;
      D.10308 = sem_handle.15->max;
      D.10309 = (unsigned int) D.10308;
      if (D.10307 > D.10309) goto end; else goto <D.10310>;
      <D.10310>:
      sem_handle.15 = sem_handle;
      sem_handle.15 = sem_handle;
      D.10304 = sem_handle.15->val;
      count.16 = (unsigned int) count;
      D.10307 = D.10304 + count.16;
      sem_handle.15->val = D.10307;
      _wapi_shared_handle_set_signal_state (handle, 1);
      ret = 1;
      end:
      _wapi_handle_unlock_shared_handles ();
      D.10295 = ret;
      return D.10295;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


sem_release (void * handle, gint32 count, gint32 * prevcount)
{
  gboolean D.10315;
  long int D.10316;
  long int D.10317;
  _Bool D.10320;
  long int D.10321;
  long int D.10322;
  struct _WapiHandle_sem * sem_handle.17;
  unsigned int D.10328;
  int D.10329;
  unsigned int count.18;
  unsigned int D.10331;
  int D.10332;
  unsigned int D.10333;
  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.10313>; else goto <D.10314>;
      <D.10313>:
      monoeg_g_log (0B, 16, "%s: error looking up sem handle %p", &__func__, handle);
      D.10315 = 0;
      return D.10315;
      <D.10314>:
      {
        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.10316 = (long int) __not_first_call;
            D.10317 = __builtin_expect (D.10316, 0);
            if (D.10317 != 0) goto <D.10318>; else goto <D.10319>;
            <D.10318>:
            __cancel_routine (__cancel_arg);
            __pthread_unwind_next (&__cancel_buf);
            <D.10319>:
            __pthread_register_cancel (&__cancel_buf);
            thr_ret = _wapi_handle_lock_handle (handle);
            D.10320 = thr_ret != 0;
            D.10321 = (long int) D.10320;
            D.10322 = __builtin_expect (D.10321, 0);
            if (D.10322 != 0) goto <D.10323>; else goto <D.10324>;
            <D.10323>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 364, "thr_ret == 0");
            <D.10324>:
            if (prevcount != 0B) goto <D.10325>; else goto <D.10326>;
            <D.10325>:
            sem_handle.17 = sem_handle;
            D.10328 = sem_handle.17->val;
            D.10329 = (int) D.10328;
            *prevcount = D.10329;
            <D.10326>:
            sem_handle.17 = sem_handle;
            D.10328 = sem_handle.17->val;
            count.18 = (unsigned int) count;
            D.10331 = D.10328 + count.18;
            sem_handle.17 = sem_handle;
            D.10332 = sem_handle.17->max;
            D.10333 = (unsigned int) D.10332;
            if (D.10331 > D.10333) goto end; else goto <D.10334>;
            <D.10334>:
            sem_handle.17 = sem_handle;
            sem_handle.17 = sem_handle;
            D.10328 = sem_handle.17->val;
            count.18 = (unsigned int) count;
            D.10331 = D.10328 + count.18;
            sem_handle.17->val = D.10331;
            _wapi_handle_set_signal_state (handle, 1, 1);
            ret = 1;
            end:
            thr_ret = _wapi_handle_unlock_handle (handle);
            D.10320 = thr_ret != 0;
            D.10321 = (long int) D.10320;
            D.10322 = __builtin_expect (D.10321, 0);
            if (D.10322 != 0) goto <D.10335>; else goto <D.10336>;
            <D.10335>:
            monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 392, "thr_ret == 0");
            <D.10336>:
            __pthread_unregister_cancel (&__cancel_buf);
            if (0 != 0) goto <D.10337>; else goto <D.10338>;
            <D.10337>:
            __cancel_routine (__cancel_arg);
            <D.10338>:
          }
        finally
          {
            __cancel_buf = {CLOBBER};
          }
      }
      D.10315 = ret;
      return D.10315;
    }
  finally
    {
      sem_handle = {CLOBBER};
    }
}


OpenSemaphore (guint32 access, gboolean inherit, const gunichar2 * name)
{
  _Bool D.10344;
  long int D.10345;
  long int D.10346;
  unsigned int offset.19;
  void * D.10356;
  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.10344 = thr_ret != 0;
  D.10345 = (long int) D.10344;
  D.10346 = __builtin_expect (D.10345, 0);
  if (D.10346 != 0) goto <D.10347>; else goto <D.10348>;
  <D.10347>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "semaphores.c", 494, "thr_ret == 0");
  <D.10348>:
  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.10349>; else goto <D.10350>;
  <D.10349>:
  SetLastError (6);
  goto cleanup;
  <D.10350>:
  if (offset == 0) goto <D.10351>; else goto <D.10352>;
  <D.10351>:
  SetLastError (2);
  goto cleanup;
  <D.10352>:
  offset.19 = (unsigned int) offset;
  handle = _wapi_handle_new_from_offset (12, offset.19, 1);
  if (handle == -1B) goto <D.10354>; else goto <D.10355>;
  <D.10354>:
  monoeg_g_log (0B, 16, "%s: error opening named sem handle", &__func__);
  SetLastError (31);
  goto cleanup;
  <D.10355>:
  ret = handle;
  cleanup:
  monoeg_g_free (utf8_name);
  _wapi_namespace_unlock (0B);
  D.10356 = ret;
  return D.10356;
}


