_wapi_collection_init ()
{
  _Bool D.10372;
  long int D.10373;
  long int D.10374;
  const gchar * D.10392;
  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.10372 = ret != 0;
      D.10373 = (long int) D.10372;
      D.10374 = __builtin_expect (D.10373, 0);
      if (D.10374 != 0) goto <D.10375>; else goto <D.10376>;
      <D.10375>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 57, "ret == 0");
      <D.10376>:
      if (set_stacksize == 0) goto <D.10377>; else goto <D.10378>;
      <D.10377>:
      ret = pthread_attr_setstacksize (&attr, 131072);
      D.10372 = ret != 0;
      D.10373 = (long int) D.10372;
      D.10374 = __builtin_expect (D.10373, 0);
      if (D.10374 != 0) goto <D.10379>; else goto <D.10380>;
      <D.10379>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 62, "ret == 0");
      <D.10380>:
      goto <D.10381>;
      <D.10378>:
      if (set_stacksize == 1) goto <D.10382>; else goto <D.10383>;
      <D.10382>:
      ret = pthread_attr_setstacksize (&attr, 131072);
      D.10372 = ret != 0;
      D.10373 = (long int) D.10372;
      D.10374 = __builtin_expect (D.10373, 0);
      if (D.10374 != 0) goto <D.10384>; else goto <D.10385>;
      <D.10384>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 65, "ret == 0");
      <D.10385>:
      <D.10383>:
      <D.10381>:
      ret = pthread_create (&collection_thread_id, &attr, collection_thread, 0B);
      if (ret != 0) goto <D.10386>; else goto <D.10387>;
      <D.10386>:
      if (set_stacksize <= 1) goto <D.10388>; else goto <D.10389>;
      <D.10388>:
      set_stacksize = set_stacksize + 1;
      goto retry;
      <D.10389>:
      <D.10387>:
      if (ret != 0) goto <D.10390>; else goto <D.10391>;
      <D.10390>:
      D.10392 = monoeg_g_strerror (ret);
      monoeg_g_log (0B, 4, "%s: Couldn\'t create handle collection thread: %s", &__func__, D.10392);
      <D.10355>:
      goto <D.10355>;
      <D.10391>:
    }
  finally
    {
      attr = {CLOBBER};
    }
}


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

  try
    {
      sleepytime.tv_sec = 10;
      sleepytime.tv_nsec = 0;
      goto <D.10345>;
      <D.10344>:
      nanosleep (&sleepytime, 0B);
      _wapi_handle_update_refs ();
      <D.10345>:
      _wapi_has_shut_down.0 = _wapi_has_shut_down;
      if (_wapi_has_shut_down.0 == 0) goto <D.10344>; else goto <D.10346>;
      <D.10346>:
      pthread_exit (0B);
      D.10394 = 0B;
      return D.10394;
    }
  finally
    {
      sleepytime = {CLOBBER};
    }
}


_wapi_handle_collect ()
{
  struct _WapiHandleSharedLayout * _wapi_shared_layout.1;
  int D.10398;
  _Bool D.10401;
  long int D.10402;
  long int D.10403;
  unsigned int D.10406;
  long int D.10409;
  unsigned int D.10410;
  unsigned int D.10411;
  struct _WapiHandleShared * D.10414;
  struct _WapiFileShareLayout * _wapi_fileshare_layout.2;
  unsigned int D.10416;
  unsigned int i.3;
  unsigned int D.10420;
  volatile guint32 * D.10421;
  guint32 count;
  int i;
  int thr_ret;

  _wapi_shared_layout.1 = _wapi_shared_layout;
  count = _wapi_shared_layout.1->collection_count;
  D.10398 = _wapi_shm_enabled ();
  if (D.10398 == 0) goto <D.10399>; else goto <D.10400>;
  <D.10399>:
  return;
  <D.10400>:
  thr_ret = _wapi_handle_lock_shared_handles ();
  D.10401 = thr_ret != 0;
  D.10402 = (long int) D.10401;
  D.10403 = __builtin_expect (D.10402, 0);
  if (D.10403 != 0) goto <D.10404>; else goto <D.10405>;
  <D.10404>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 93, "thr_ret == 0");
  <D.10405>:
  _wapi_shared_layout.1 = _wapi_shared_layout;
  D.10406 = _wapi_shared_layout.1->collection_count;
  if (D.10406 == count) goto <D.10407>; else goto <D.10408>;
  <D.10407>:
  {
    guint32 too_old;

    D.10409 = time (0B);
    D.10410 = (unsigned int) D.10409;
    too_old = D.10410 + 4294967236;
    i = 0;
    goto <D.10365>;
    <D.10364>:
    {
      struct _WapiHandleShared * data;

      _wapi_shared_layout.1 = _wapi_shared_layout;
      data = &_wapi_shared_layout.1->handles[i];
      D.10411 = data->timestamp;
      if (D.10411 < too_old) goto <D.10412>; else goto <D.10413>;
      <D.10412>:
      _wapi_shared_layout.1 = _wapi_shared_layout;
      D.10414 = &_wapi_shared_layout.1->handles[i];
      memset (D.10414, 0, 320);
      <D.10413>:
    }
    i = i + 1;
    <D.10365>:
    if (i <= 255) goto <D.10364>; else goto <D.10366>;
    <D.10366>:
    i = 0;
    goto <D.10369>;
    <D.10368>:
    {
      struct _WapiFileShare * file_share;

      _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
      file_share = &_wapi_fileshare_layout.2->share_info[i];
      D.10416 = file_share->timestamp;
      if (D.10416 < too_old) goto <D.10417>; else goto <D.10418>;
      <D.10417>:
      memset (file_share, 0, 40);
      <D.10418>:
    }
    i = i + 1;
    <D.10369>:
    i.3 = (unsigned int) i;
    _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
    D.10420 = _wapi_fileshare_layout.2->hwm;
    if (i.3 < D.10420) goto <D.10368>; else goto <D.10370>;
    <D.10370>:
    _wapi_shared_layout.1 = _wapi_shared_layout;
    D.10421 = &_wapi_shared_layout.1->collection_count;
    InterlockedIncrement (D.10421);
  }
  <D.10408>:
  _wapi_handle_unlock_shared_handles ();
}


_wapi_handle_lock_shared_handles ()
{
  int D.10423;

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


memset (void * __dest, int __ch, size_t __len)
{
  int D.10427;
  int D.10432;
  void * D.10434;
  unsigned int D.10435;

  D.10427 = __builtin_constant_p (__len);
  if (D.10427 != 0) goto <D.10428>; else goto <D.10429>;
  <D.10428>:
  if (__len == 0) goto <D.10430>; else goto <D.10431>;
  <D.10430>:
  D.10432 = __builtin_constant_p (__ch);
  if (D.10432 == 0) goto <D.10425>; else goto <D.10433>;
  <D.10433>:
  if (__ch != 0) goto <D.10425>; else goto <D.10426>;
  <D.10425>:
  __warn_memset_zero_len ();
  D.10434 = __dest;
  return D.10434;
  <D.10426>:
  <D.10431>:
  <D.10429>:
  D.10435 = __builtin_object_size (__dest, 0);
  D.10434 = __builtin___memset_chk (__dest, __ch, __len, D.10435);
  return D.10434;
}


InterlockedIncrement (volatile gint32 * val)
{
  gint32 D.10437;
  unsigned int D.10438;

  D.10438 = __sync_add_and_fetch_4 (val, 1);
  D.10437 = (gint32) D.10438;
  return D.10437;
}


_wapi_handle_unlock_shared_handles ()
{
  int D.10440;

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


