_wapi_collection_init ()
{
  _Bool D.11284;
  long int D.11285;
  long int D.11286;
  const gchar * D.11304;
  union pthread_attr_t attr;
  int ret;
  int set_stacksize;
  void retry = <<< error >>>;
  static const char __func__[22] = "_wapi_collection_init";

  try
    {
      set_stacksize = 0;
      retry:
      ret = pthread_attr_init (&attr);
      D.11284 = ret != 0;
      D.11285 = (long int) D.11284;
      D.11286 = __builtin_expect (D.11285, 0);
      if (D.11286 != 0) goto <D.11287>; else goto <D.11288>;
      <D.11287>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 57, "ret == 0");
      <D.11288>:
      if (set_stacksize == 0) goto <D.11289>; else goto <D.11290>;
      <D.11289>:
      ret = pthread_attr_setstacksize (&attr, 131072);
      D.11284 = ret != 0;
      D.11285 = (long int) D.11284;
      D.11286 = __builtin_expect (D.11285, 0);
      if (D.11286 != 0) goto <D.11291>; else goto <D.11292>;
      <D.11291>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 62, "ret == 0");
      <D.11292>:
      goto <D.11293>;
      <D.11290>:
      if (set_stacksize == 1) goto <D.11294>; else goto <D.11295>;
      <D.11294>:
      ret = pthread_attr_setstacksize (&attr, 131072);
      D.11284 = ret != 0;
      D.11285 = (long int) D.11284;
      D.11286 = __builtin_expect (D.11285, 0);
      if (D.11286 != 0) goto <D.11296>; else goto <D.11297>;
      <D.11296>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 65, "ret == 0");
      <D.11297>:
      <D.11295>:
      <D.11293>:
      ret = pthread_create (&collection_thread_id, &attr, collection_thread, 0B);
      if (ret != 0) goto <D.11298>; else goto <D.11299>;
      <D.11298>:
      if (set_stacksize <= 1) goto <D.11300>; else goto <D.11301>;
      <D.11300>:
      set_stacksize = set_stacksize + 1;
      goto retry;
      <D.11301>:
      <D.11299>:
      if (ret != 0) goto <D.11302>; else goto <D.11303>;
      <D.11302>:
      D.11304 = monoeg_g_strerror (ret);
      monoeg_g_log (0B, 4, "%s: Couldn\'t create handle collection thread: %s", &__func__, D.11304);
      <D.11267>:
      goto <D.11267>;
      <D.11303>:
    }
  finally
    {
      attr = {CLOBBER};
    }
}


collection_thread (void * unused)
{
  int _wapi_has_shut_down.0;
  void * D.11306;
  struct timespec sleepytime;

  try
    {
      sleepytime.tv_sec = 10;
      sleepytime.tv_nsec = 0;
      goto <D.11257>;
      <D.11256>:
      nanosleep (&sleepytime, 0B);
      _wapi_handle_update_refs ();
      <D.11257>:
      _wapi_has_shut_down.0 = _wapi_has_shut_down;
      if (_wapi_has_shut_down.0 == 0) goto <D.11256>; else goto <D.11258>;
      <D.11258>:
      pthread_exit (0B);
      D.11306 = 0B;
      return D.11306;
    }
  finally
    {
      sleepytime = {CLOBBER};
    }
}


_wapi_handle_collect ()
{
  struct _WapiHandleSharedLayout * _wapi_shared_layout.1;
  int D.11310;
  _Bool D.11313;
  long int D.11314;
  long int D.11315;
  unsigned int D.11318;
  long int D.11321;
  unsigned int D.11322;
  unsigned int D.11323;
  struct _WapiHandleShared * D.11326;
  struct _WapiFileShareLayout * _wapi_fileshare_layout.2;
  unsigned int D.11328;
  unsigned int i.3;
  unsigned int D.11332;
  volatile guint32 * D.11333;
  guint32 count;
  int i;
  int thr_ret;

  _wapi_shared_layout.1 = _wapi_shared_layout;
  count = _wapi_shared_layout.1->collection_count;
  D.11310 = _wapi_shm_enabled ();
  if (D.11310 == 0) goto <D.11311>; else goto <D.11312>;
  <D.11311>:
  return;
  <D.11312>:
  thr_ret = _wapi_handle_lock_shared_handles ();
  D.11313 = thr_ret != 0;
  D.11314 = (long int) D.11313;
  D.11315 = __builtin_expect (D.11314, 0);
  if (D.11315 != 0) goto <D.11316>; else goto <D.11317>;
  <D.11316>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 93, "thr_ret == 0");
  <D.11317>:
  _wapi_shared_layout.1 = _wapi_shared_layout;
  D.11318 = _wapi_shared_layout.1->collection_count;
  if (D.11318 == count) goto <D.11319>; else goto <D.11320>;
  <D.11319>:
  {
    guint32 too_old;

    D.11321 = time (0B);
    D.11322 = (unsigned int) D.11321;
    too_old = D.11322 + 4294967236;
    i = 0;
    goto <D.11277>;
    <D.11276>:
    {
      struct _WapiHandleShared * data;

      _wapi_shared_layout.1 = _wapi_shared_layout;
      data = &_wapi_shared_layout.1->handles[i];
      D.11323 = data->timestamp;
      if (D.11323 < too_old) goto <D.11324>; else goto <D.11325>;
      <D.11324>:
      _wapi_shared_layout.1 = _wapi_shared_layout;
      D.11326 = &_wapi_shared_layout.1->handles[i];
      memset (D.11326, 0, 336);
      <D.11325>:
    }
    i = i + 1;
    <D.11277>:
    if (i <= 255) goto <D.11276>; else goto <D.11278>;
    <D.11278>:
    i = 0;
    goto <D.11281>;
    <D.11280>:
    {
      struct _WapiFileShare * file_share;

      _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
      file_share = &_wapi_fileshare_layout.2->share_info[i];
      D.11328 = file_share->timestamp;
      if (D.11328 < too_old) goto <D.11329>; else goto <D.11330>;
      <D.11329>:
      memset (file_share, 0, 40);
      <D.11330>:
    }
    i = i + 1;
    <D.11281>:
    i.3 = (unsigned int) i;
    _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
    D.11332 = _wapi_fileshare_layout.2->hwm;
    if (i.3 < D.11332) goto <D.11280>; else goto <D.11282>;
    <D.11282>:
    _wapi_shared_layout.1 = _wapi_shared_layout;
    D.11333 = &_wapi_shared_layout.1->collection_count;
    InterlockedIncrement (D.11333);
  }
  <D.11320>:
  _wapi_handle_unlock_shared_handles ();
}


_wapi_handle_lock_shared_handles ()
{
  int D.11335;

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


memset (void * __dest, int __ch, size_t __len)
{
  int D.11339;
  int D.11344;
  void * D.11346;
  long unsigned int D.11347;

  D.11339 = __builtin_constant_p (__len);
  if (D.11339 != 0) goto <D.11340>; else goto <D.11341>;
  <D.11340>:
  if (__len == 0) goto <D.11342>; else goto <D.11343>;
  <D.11342>:
  D.11344 = __builtin_constant_p (__ch);
  if (D.11344 == 0) goto <D.11337>; else goto <D.11345>;
  <D.11345>:
  if (__ch != 0) goto <D.11337>; else goto <D.11338>;
  <D.11337>:
  __warn_memset_zero_len ();
  D.11346 = __dest;
  return D.11346;
  <D.11338>:
  <D.11343>:
  <D.11341>:
  D.11347 = __builtin_object_size (__dest, 0);
  D.11346 = __builtin___memset_chk (__dest, __ch, __len, D.11347);
  return D.11346;
}


InterlockedIncrement (volatile gint32 * val)
{
  gint32 D.11349;
  unsigned int D.11350;

  D.11350 = __sync_add_and_fetch_4 (val, 1);
  D.11349 = (gint32) D.11350;
  return D.11349;
}


_wapi_handle_unlock_shared_handles ()
{
  int D.11352;

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


