_wapi_collection_init ()
{
  _Bool D.12956;
  long int D.12957;
  long int D.12958;
  _Bool D.12970;
  _Bool D.12971;
  const gchar * D.12976;
  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.12956 = ret != 0;
      D.12957 = (long int) D.12956;
      D.12958 = __builtin_expect (D.12957, 0);
      if (D.12958 != 0) goto <D.12959>; else goto <D.12960>;
      <D.12959>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 57, "ret == 0");
      <D.12960>:
      if (set_stacksize == 0) goto <D.12961>; else goto <D.12962>;
      <D.12961>:
      ret = pthread_attr_setstacksize (&attr, 65536);
      D.12956 = ret != 0;
      D.12957 = (long int) D.12956;
      D.12958 = __builtin_expect (D.12957, 0);
      if (D.12958 != 0) goto <D.12963>; else goto <D.12964>;
      <D.12963>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 62, "ret == 0");
      <D.12964>:
      goto <D.12965>;
      <D.12962>:
      if (set_stacksize == 1) goto <D.12966>; else goto <D.12967>;
      <D.12966>:
      ret = pthread_attr_setstacksize (&attr, 131072);
      D.12956 = ret != 0;
      D.12957 = (long int) D.12956;
      D.12958 = __builtin_expect (D.12957, 0);
      if (D.12958 != 0) goto <D.12968>; else goto <D.12969>;
      <D.12968>:
      monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 65, "ret == 0");
      <D.12969>:
      <D.12967>:
      <D.12965>:
      ret = pthread_create (&collection_thread_id, &attr, collection_thread, 0B);
      D.12956 = ret != 0;
      D.12970 = set_stacksize <= 1;
      D.12971 = D.12956 & D.12970;
      if (D.12971 != 0) goto <D.12972>; else goto <D.12973>;
      <D.12972>:
      set_stacksize = set_stacksize + 1;
      goto retry;
      <D.12973>:
      if (ret != 0) goto <D.12974>; else goto <D.12975>;
      <D.12974>:
      D.12976 = monoeg_g_strerror (ret);
      monoeg_g_log (0B, 4, "%s: Couldn\'t create handle collection thread: %s", &__func__, D.12976);
      <D.12937>:
      goto <D.12937>;
      <D.12975>:
    }
  finally
    {
      attr = {CLOBBER};
    }
}


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

  try
    {
      sleepytime.tv_sec = 10;
      sleepytime.tv_nsec = 0;
      goto <D.12927>;
      <D.12926>:
      nanosleep (&sleepytime, 0B);
      _wapi_handle_update_refs ();
      <D.12927>:
      _wapi_has_shut_down.0 = _wapi_has_shut_down;
      if (_wapi_has_shut_down.0 == 0) goto <D.12926>; else goto <D.12928>;
      <D.12928>:
      pthread_exit (0B);
      D.12978 = 0B;
      return D.12978;
    }
  finally
    {
      sleepytime = {CLOBBER};
    }
}


_wapi_handle_collect ()
{
  struct _WapiHandleSharedLayout * _wapi_shared_layout.1;
  int D.12982;
  _Bool D.12985;
  long int D.12986;
  long int D.12987;
  unsigned int D.12990;
  long int D.12993;
  unsigned int D.12994;
  unsigned int D.12995;
  struct _WapiHandleShared * D.12998;
  struct _WapiFileShareLayout * _wapi_fileshare_layout.2;
  unsigned int D.13000;
  unsigned int i.3;
  unsigned int D.13004;
  volatile guint32 * D.13005;
  guint32 count;
  int i;
  int thr_ret;

  _wapi_shared_layout.1 = _wapi_shared_layout;
  count = _wapi_shared_layout.1->collection_count;
  D.12982 = _wapi_shm_enabled ();
  if (D.12982 == 0) goto <D.12983>; else goto <D.12984>;
  <D.12983>:
  return;
  <D.12984>:
  thr_ret = _wapi_handle_lock_shared_handles ();
  D.12985 = thr_ret != 0;
  D.12986 = (long int) D.12985;
  D.12987 = __builtin_expect (D.12986, 0);
  if (D.12987 != 0) goto <D.12988>; else goto <D.12989>;
  <D.12988>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "collection.c", 93, "thr_ret == 0");
  <D.12989>:
  _wapi_shared_layout.1 = _wapi_shared_layout;
  D.12990 = _wapi_shared_layout.1->collection_count;
  if (D.12990 == count) goto <D.12991>; else goto <D.12992>;
  <D.12991>:
  {
    guint32 too_old;

    D.12993 = time (0B);
    D.12994 = (unsigned int) D.12993;
    too_old = D.12994 + 4294967236;
    i = 0;
    goto <D.12947>;
    <D.12946>:
    {
      struct _WapiHandleShared * data;

      _wapi_shared_layout.1 = _wapi_shared_layout;
      data = &_wapi_shared_layout.1->handles[i];
      D.12995 = data->timestamp;
      if (D.12995 < too_old) goto <D.12996>; else goto <D.12997>;
      <D.12996>:
      _wapi_shared_layout.1 = _wapi_shared_layout;
      D.12998 = &_wapi_shared_layout.1->handles[i];
      memset (D.12998, 0, 320);
      <D.12997>:
    }
    i = i + 1;
    <D.12947>:
    if (i <= 255) goto <D.12946>; else goto <D.12948>;
    <D.12948>:
    i = 0;
    goto <D.12951>;
    <D.12950>:
    {
      struct _WapiFileShare * file_share;

      _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
      file_share = &_wapi_fileshare_layout.2->share_info[i];
      D.13000 = file_share->timestamp;
      if (D.13000 < too_old) goto <D.13001>; else goto <D.13002>;
      <D.13001>:
      memset (file_share, 0, 40);
      <D.13002>:
    }
    i = i + 1;
    <D.12951>:
    i.3 = (unsigned int) i;
    _wapi_fileshare_layout.2 = _wapi_fileshare_layout;
    D.13004 = _wapi_fileshare_layout.2->hwm;
    if (i.3 < D.13004) goto <D.12950>; else goto <D.12952>;
    <D.12952>:
    _wapi_shared_layout.1 = _wapi_shared_layout;
    D.13005 = &_wapi_shared_layout.1->collection_count;
    InterlockedIncrement (D.13005);
  }
  <D.12992>:
  _wapi_handle_unlock_shared_handles ();
}


_wapi_handle_lock_shared_handles ()
{
  int D.13007;

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


memset (void * __dest, int __ch, size_t __len)
{
  int D.13011;
  int D.13016;
  void * D.13018;
  unsigned int D.13019;

  D.13011 = __builtin_constant_p (__len);
  if (D.13011 != 0) goto <D.13012>; else goto <D.13013>;
  <D.13012>:
  if (__len == 0) goto <D.13014>; else goto <D.13015>;
  <D.13014>:
  D.13016 = __builtin_constant_p (__ch);
  if (D.13016 == 0) goto <D.13009>; else goto <D.13017>;
  <D.13017>:
  if (__ch != 0) goto <D.13009>; else goto <D.13010>;
  <D.13009>:
  __warn_memset_zero_len ();
  D.13018 = __dest;
  return D.13018;
  <D.13010>:
  <D.13015>:
  <D.13013>:
  D.13019 = __builtin_object_size (__dest, 0);
  D.13018 = __builtin___memset_chk (__dest, __ch, __len, D.13019);
  return D.13018;
}


InterlockedIncrement (volatile gint32 * val)
{
  gint32 D.13021;
  unsigned int D.13022;

  D.13022 = __sync_add_and_fetch_4 (val, 1);
  D.13021 = (gint32) D.13022;
  return D.13021;
}


_wapi_handle_unlock_shared_handles ()
{
  int D.13024;

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


