_wapi_collection_init ()
{
  _Bool D.10396;
  long int D.10397;
  long int D.10398;
  _Bool D.10410;
  _Bool D.10411;
  const gchar * D.10416;
  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.10396 = ret != 0;
      D.10397 = (long int) D.10396;
      D.10398 = __builtin_expect (D.10397, 0);
      if (D.10398 != 0) goto <D.10399>; else goto <D.10400>;
      <D.10399>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 57, "ret == 0");
      <D.10400>:
      if (set_stacksize == 0) goto <D.10401>; else goto <D.10402>;
      <D.10401>:
      ret = pthread_attr_setstacksize (&attr, 65536);
      D.10396 = ret != 0;
      D.10397 = (long int) D.10396;
      D.10398 = __builtin_expect (D.10397, 0);
      if (D.10398 != 0) goto <D.10403>; else goto <D.10404>;
      <D.10403>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 62, "ret == 0");
      <D.10404>:
      goto <D.10405>;
      <D.10402>:
      if (set_stacksize == 1) goto <D.10406>; else goto <D.10407>;
      <D.10406>:
      ret = pthread_attr_setstacksize (&attr, 131072);
      D.10396 = ret != 0;
      D.10397 = (long int) D.10396;
      D.10398 = __builtin_expect (D.10397, 0);
      if (D.10398 != 0) goto <D.10408>; else goto <D.10409>;
      <D.10408>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 65, "ret == 0");
      <D.10409>:
      <D.10407>:
      <D.10405>:
      ret = pthread_create (&collection_thread_id, &attr, collection_thread, 0B);
      D.10396 = ret != 0;
      D.10410 = set_stacksize <= 1;
      D.10411 = D.10396 & D.10410;
      if (D.10411 != 0) goto <D.10412>; else goto <D.10413>;
      <D.10412>:
      set_stacksize = set_stacksize + 1;
      goto retry;
      <D.10413>:
      if (ret != 0) goto <D.10414>; else goto <D.10415>;
      <D.10414>:
      D.10416 = monoeg_g_strerror (ret);
      monoeg_g_log (0B, 4, "%s: Couldn\'t create handle collection thread: %s", &__func__, D.10416);
      <D.10379>:
      goto <D.10379>;
      <D.10415>:
    }
  finally
    {
      attr = {CLOBBER};
    }
}


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

  try
    {
      sleepytime.tv_sec = 10;
      sleepytime.tv_nsec = 0;
      goto <D.10369>;
      <D.10368>:
      nanosleep (&sleepytime, 0B);
      _wapi_handle_update_refs ();
      <D.10369>:
      _wapi_has_shut_down.0 = _wapi_has_shut_down;
      if (_wapi_has_shut_down.0 == 0) goto <D.10368>; else goto <D.10370>;
      <D.10370>:
      pthread_exit (0B);
      D.10418 = 0B;
      return D.10418;
    }
  finally
    {
      sleepytime = {CLOBBER};
    }
}


_wapi_handle_collect ()
{
  struct _WapiHandleSharedLayout * _wapi_shared_layout.1;
  int D.10422;
  _Bool D.10425;
  long int D.10426;
  long int D.10427;
  unsigned int D.10430;
  long int D.10433;
  unsigned int D.10434;
  unsigned int D.10435;
  struct _WapiHandleShared * D.10438;
  struct _WapiFileShareLayout * _wapi_fileshare_layout.2;
  unsigned int D.10440;
  unsigned int i.3;
  unsigned int D.10444;
  volatile guint32 * D.10445;
  guint32 count;
  int i;
  int thr_ret;

  _wapi_shared_layout.1 = _wapi_shared_layout;
  count = _wapi_shared_layout.1->collection_count;
  D.10422 = _wapi_shm_enabled ();
  if (D.10422 == 0) goto <D.10423>; else goto <D.10424>;
  <D.10423>:
  return;
  <D.10424>:
  thr_ret = _wapi_handle_lock_shared_handles ();
  D.10425 = thr_ret != 0;
  D.10426 = (long int) D.10425;
  D.10427 = __builtin_expect (D.10426, 0);
  if (D.10427 != 0) goto <D.10428>; else goto <D.10429>;
  <D.10428>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 93, "thr_ret == 0");
  <D.10429>:
  _wapi_shared_layout.1 = _wapi_shared_layout;
  D.10430 = _wapi_shared_layout.1->collection_count;
  if (D.10430 == count) goto <D.10431>; else goto <D.10432>;
  <D.10431>:
  {
    guint32 too_old;

    D.10433 = time (0B);
    D.10434 = (unsigned int) D.10433;
    too_old = D.10434 + 4294967236;
    i = 0;
    goto <D.10389>;
    <D.10388>:
    {
      struct _WapiHandleShared * data;

      _wapi_shared_layout.1 = _wapi_shared_layout;
      data = &_wapi_shared_layout.1->handles[i];
      D.10435 = data->timestamp;
      if (D.10435 < too_old) goto <D.10436>; else goto <D.10437>;
      <D.10436>:
      _wapi_shared_layout.1 = _wapi_shared_layout;
      D.10438 = &_wapi_shared_layout.1->handles[i];
      memset (D.10438, 0, 320);
      <D.10437>:
    }
    i = i + 1;
    <D.10389>:
    if (i <= 255) goto <D.10388>; else goto <D.10390>;
    <D.10390>:
    i = 0;
    goto <D.10393>;
    <D.10392>:
    {
      struct _WapiFileShare * file_share;

      _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
      file_share = &_wapi_fileshare_layout.2->share_info[i];
      D.10440 = file_share->timestamp;
      if (D.10440 < too_old) goto <D.10441>; else goto <D.10442>;
      <D.10441>:
      memset (file_share, 0, 36);
      <D.10442>:
    }
    i = i + 1;
    <D.10393>:
    i.3 = (unsigned int) i;
    _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
    D.10444 = _wapi_fileshare_layout.2->hwm;
    if (i.3 < D.10444) goto <D.10392>; else goto <D.10394>;
    <D.10394>:
    _wapi_shared_layout.1 = _wapi_shared_layout;
    D.10445 = &_wapi_shared_layout.1->collection_count;
    InterlockedIncrement (D.10445);
  }
  <D.10432>:
  _wapi_handle_unlock_shared_handles ();
}


_wapi_handle_lock_shared_handles ()
{
  int D.10447;

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


memset (void * __dest, int __ch, size_t __len)
{
  int D.10451;
  int D.10456;
  void * D.10458;
  unsigned int D.10459;

  D.10451 = __builtin_constant_p (__len);
  if (D.10451 != 0) goto <D.10452>; else goto <D.10453>;
  <D.10452>:
  if (__len == 0) goto <D.10454>; else goto <D.10455>;
  <D.10454>:
  D.10456 = __builtin_constant_p (__ch);
  if (D.10456 == 0) goto <D.10449>; else goto <D.10457>;
  <D.10457>:
  if (__ch != 0) goto <D.10449>; else goto <D.10450>;
  <D.10449>:
  __warn_memset_zero_len ();
  D.10458 = __dest;
  return D.10458;
  <D.10450>:
  <D.10455>:
  <D.10453>:
  D.10459 = __builtin_object_size (__dest, 0);
  D.10458 = __builtin___memset_chk (__dest, __ch, __len, D.10459);
  return D.10458;
}


InterlockedIncrement (volatile gint32 * val)
{
  gint32 D.10461;
  unsigned int D.10462;

  D.10462 = __sync_add_and_fetch_4 (val, 1);
  D.10461 = (gint32) D.10462;
  return D.10461;
}


_wapi_handle_unlock_shared_handles ()
{
  int D.10464;

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


