sgen_process_togglerefs ()
{
  int toggleref_array_size.0;
  struct FILE * gc_debug_file.1;
  struct MonoGCToggleRef * toggleref_array.2;
  long unsigned int D.17593;
  long unsigned int D.17594;
  struct MonoGCToggleRef * D.17595;
  void * D.17596;
  void * D.17600;
  MonoToggleRefStatus (*<T2ed3>) (struct MonoObject *) toggleref_callback.3;
  <unnamed type> D.17605;
  int D.17606;
  int D.17607;
  long unsigned int D.17608;
  long unsigned int D.17609;
  struct MonoGCToggleRef * D.17610;
  int D.17613;
  int D.17614;
  int D.17615;
  int i;
  int w;
  int toggle_ref_counts[3];

  try
    {
      toggle_ref_counts[0] = 0;
      toggle_ref_counts[1] = 0;
      toggle_ref_counts[2] = 0;
      if (0 != 0) goto <D.17588>; else goto <D.17589>;
      <D.17588>:
      toggleref_array_size.0 = toggleref_array_size;
      gc_debug_file.1 = gc_debug_file;
      fprintf (gc_debug_file.1, "Proccessing ToggleRefs %d\n", toggleref_array_size.0);
      gc_debug_file.1 = gc_debug_file;
      fflush (gc_debug_file.1);
      <D.17589>:
      w = 0;
      i = w;
      goto <D.17556>;
      <D.17555>:
      {
        int res;
        struct MonoGCToggleRef r;
        struct MonoObject * obj;

        try
          {
            toggleref_array.2 = toggleref_array;
            D.17593 = (long unsigned int) i;
            D.17594 = D.17593 * 16;
            D.17595 = toggleref_array.2 + D.17594;
            r = *D.17595;
            D.17596 = r.strong_ref;
            if (D.17596 != 0B) goto <D.17597>; else goto <D.17598>;
            <D.17597>:
            obj = r.strong_ref;
            goto <D.17599>;
            <D.17598>:
            D.17600 = r.weak_ref;
            if (D.17600 != 0B) goto <D.17601>; else goto <D.17602>;
            <D.17601>:
            obj = r.weak_ref;
            goto <D.17603>;
            <D.17602>:
            // predicted unlikely by continue predictor.
            goto <D.17549>;
            <D.17603>:
            <D.17599>:
            toggleref_callback.3 = toggleref_callback;
            D.17605 = toggleref_callback.3 (obj);
            res = (int) D.17605;
            D.17606 = toggle_ref_counts[res];
            D.17607 = D.17606 + 1;
            toggle_ref_counts[res] = D.17607;
            switch (res) <default: <D.17554>, case 0: <D.17550>, case 1: <D.17552>, case 2: <D.17553>>
            <D.17550>:
            goto <D.17551>;
            <D.17552>:
            toggleref_array.2 = toggleref_array;
            D.17608 = (long unsigned int) w;
            D.17609 = D.17608 * 16;
            D.17610 = toggleref_array.2 + D.17609;
            D.17610->strong_ref = obj;
            toggleref_array.2 = toggleref_array;
            D.17608 = (long unsigned int) w;
            D.17609 = D.17608 * 16;
            D.17610 = toggleref_array.2 + D.17609;
            D.17610->weak_ref = 0B;
            w = w + 1;
            goto <D.17551>;
            <D.17553>:
            toggleref_array.2 = toggleref_array;
            D.17608 = (long unsigned int) w;
            D.17609 = D.17608 * 16;
            D.17610 = toggleref_array.2 + D.17609;
            D.17610->strong_ref = 0B;
            toggleref_array.2 = toggleref_array;
            D.17608 = (long unsigned int) w;
            D.17609 = D.17608 * 16;
            D.17610 = toggleref_array.2 + D.17609;
            D.17610->weak_ref = obj;
            w = w + 1;
            goto <D.17551>;
            <D.17554>:
            monoeg_assertion_message ("* Assertion: should not be reached at %s:%d\n", "sgen-toggleref.c", 80);
            <D.17551>:
          }
        finally
          {
            r = {CLOBBER};
          }
      }
      <D.17549>:
      i = i + 1;
      <D.17556>:
      toggleref_array_size.0 = toggleref_array_size;
      if (i < toggleref_array_size.0) goto <D.17555>; else goto <D.17557>;
      <D.17557>:
      toggleref_array_size = w;
      if (0 != 0) goto <D.17611>; else goto <D.17612>;
      <D.17611>:
      D.17613 = toggle_ref_counts[2];
      D.17614 = toggle_ref_counts[1];
      D.17615 = toggle_ref_counts[0];
      gc_debug_file.1 = gc_debug_file;
      fprintf (gc_debug_file.1, "Done Proccessing ToggleRefs dropped %d strong %d weak %d final size %d\n", D.17615, D.17614, D.17613, w);
      gc_debug_file.1 = gc_debug_file;
      fflush (gc_debug_file.1);
      <D.17612>:
    }
  finally
    {
      toggle_ref_counts = {CLOBBER};
    }
}


sgen_scan_togglerefs (char * start, char * end, struct ScanCopyContext ctx)
{
  int toggleref_array_size.4;
  struct FILE * gc_debug_file.5;
  struct MonoGCToggleRef * toggleref_array.6;
  long unsigned int D.17624;
  long unsigned int D.17625;
  struct MonoGCToggleRef * D.17626;
  void * D.17627;
  _Bool D.17630;
  _Bool D.17631;
  _Bool D.17632;
  void * * D.17637;
  void * D.17639;
  _Bool D.17642;
  _Bool D.17643;
  _Bool D.17644;
  int D.17647;
  void * * D.17655;
  void (*CopyOrMarkObjectFunc) (void * *, struct SgenGrayQueue *) copy_func;
  struct SgenGrayQueue * queue;
  int i;

  copy_func = ctx.copy_func;
  queue = ctx.queue;
  if (0 != 0) goto <D.17619>; else goto <D.17620>;
  <D.17619>:
  toggleref_array_size.4 = toggleref_array_size;
  gc_debug_file.5 = gc_debug_file;
  fprintf (gc_debug_file.5, "Scanning ToggleRefs %d\n", toggleref_array_size.4);
  gc_debug_file.5 = gc_debug_file;
  fflush (gc_debug_file.5);
  <D.17620>:
  i = 0;
  goto <D.17569>;
  <D.17568>:
  toggleref_array.6 = toggleref_array;
  D.17624 = (long unsigned int) i;
  D.17625 = D.17624 * 16;
  D.17626 = toggleref_array.6 + D.17625;
  D.17627 = D.17626->strong_ref;
  if (D.17627 != 0B) goto <D.17628>; else goto <D.17629>;
  <D.17628>:
  {
    char * object;

    toggleref_array.6 = toggleref_array;
    D.17624 = (long unsigned int) i;
    D.17625 = D.17624 * 16;
    D.17626 = toggleref_array.6 + D.17625;
    object = D.17626->strong_ref;
    D.17630 = object >= start;
    D.17631 = object < end;
    D.17632 = D.17630 & D.17631;
    if (D.17632 != 0) goto <D.17633>; else goto <D.17634>;
    <D.17633>:
    if (0 != 0) goto <D.17635>; else goto <D.17636>;
    <D.17635>:
    gc_debug_file.5 = gc_debug_file;
    fprintf (gc_debug_file.5, "\tcopying strong slot %d\n", i);
    gc_debug_file.5 = gc_debug_file;
    fflush (gc_debug_file.5);
    <D.17636>:
    toggleref_array.6 = toggleref_array;
    D.17624 = (long unsigned int) i;
    D.17625 = D.17624 * 16;
    D.17626 = toggleref_array.6 + D.17625;
    D.17637 = &D.17626->strong_ref;
    copy_func (D.17637, queue);
    <D.17634>:
  }
  goto <D.17638>;
  <D.17629>:
  toggleref_array.6 = toggleref_array;
  D.17624 = (long unsigned int) i;
  D.17625 = D.17624 * 16;
  D.17626 = toggleref_array.6 + D.17625;
  D.17639 = D.17626->weak_ref;
  if (D.17639 != 0B) goto <D.17640>; else goto <D.17641>;
  <D.17640>:
  {
    char * object;

    toggleref_array.6 = toggleref_array;
    D.17624 = (long unsigned int) i;
    D.17625 = D.17624 * 16;
    D.17626 = toggleref_array.6 + D.17625;
    object = D.17626->weak_ref;
    D.17642 = object >= start;
    D.17643 = object < end;
    D.17644 = D.17642 & D.17643;
    if (D.17644 != 0) goto <D.17645>; else goto <D.17646>;
    <D.17645>:
    D.17647 = sgen_gc_is_object_ready_for_finalization (object);
    if (D.17647 != 0) goto <D.17648>; else goto <D.17649>;
    <D.17648>:
    if (0 != 0) goto <D.17650>; else goto <D.17651>;
    <D.17650>:
    gc_debug_file.5 = gc_debug_file;
    fprintf (gc_debug_file.5, "\tcleaning weak slot %d\n", i);
    gc_debug_file.5 = gc_debug_file;
    fflush (gc_debug_file.5);
    <D.17651>:
    toggleref_array.6 = toggleref_array;
    D.17624 = (long unsigned int) i;
    D.17625 = D.17624 * 16;
    D.17626 = toggleref_array.6 + D.17625;
    D.17626->weak_ref = 0B;
    goto <D.17652>;
    <D.17649>:
    if (0 != 0) goto <D.17653>; else goto <D.17654>;
    <D.17653>:
    gc_debug_file.5 = gc_debug_file;
    fprintf (gc_debug_file.5, "\tkeeping weak slot %d\n", i);
    gc_debug_file.5 = gc_debug_file;
    fflush (gc_debug_file.5);
    <D.17654>:
    toggleref_array.6 = toggleref_array;
    D.17624 = (long unsigned int) i;
    D.17625 = D.17624 * 16;
    D.17626 = toggleref_array.6 + D.17625;
    D.17655 = &D.17626->weak_ref;
    copy_func (D.17655, queue);
    <D.17652>:
    <D.17646>:
  }
  <D.17641>:
  <D.17638>:
  i = i + 1;
  <D.17569>:
  toggleref_array_size.4 = toggleref_array_size;
  if (i < toggleref_array_size.4) goto <D.17568>; else goto <D.17570>;
  <D.17570>:
}


mono_gc_toggleref_add (struct MonoObject * object, mono_bool strong_ref)
{
  MonoToggleRefStatus (*<T2ed3>) (struct MonoObject *) toggleref_callback.7;
  struct FILE * gc_debug_file.8;
  struct MonoGCToggleRef * toggleref_array.9;
  int toggleref_array_size.10;
  long unsigned int D.17664;
  long unsigned int D.17665;
  struct MonoGCToggleRef * D.17666;
  void * iftmp.11;
  void * iftmp.12;
  int toggleref_array_size.13;

  toggleref_callback.7 = toggleref_callback;
  if (toggleref_callback.7 == 0B) goto <D.17657>; else goto <D.17658>;
  <D.17657>:
  return;
  <D.17658>:
  if (0 != 0) goto <D.17659>; else goto <D.17660>;
  <D.17659>:
  gc_debug_file.8 = gc_debug_file;
  fprintf (gc_debug_file.8, "Adding toggleref %p %d\n", object, strong_ref);
  gc_debug_file.8 = gc_debug_file;
  fflush (gc_debug_file.8);
  <D.17660>:
  sgen_gc_lock ();
  ensure_toggleref_capacity (1);
  toggleref_array.9 = toggleref_array;
  toggleref_array_size.10 = toggleref_array_size;
  D.17664 = (long unsigned int) toggleref_array_size.10;
  D.17665 = D.17664 * 16;
  D.17666 = toggleref_array.9 + D.17665;
  if (strong_ref != 0) goto <D.17668>; else goto <D.17669>;
  <D.17668>:
  iftmp.11 = object;
  goto <D.17670>;
  <D.17669>:
  iftmp.11 = 0B;
  <D.17670>:
  D.17666->strong_ref = iftmp.11;
  toggleref_array.9 = toggleref_array;
  toggleref_array_size.10 = toggleref_array_size;
  D.17664 = (long unsigned int) toggleref_array_size.10;
  D.17665 = D.17664 * 16;
  D.17666 = toggleref_array.9 + D.17665;
  if (strong_ref == 0) goto <D.17672>; else goto <D.17673>;
  <D.17672>:
  iftmp.12 = object;
  goto <D.17674>;
  <D.17673>:
  iftmp.12 = 0B;
  <D.17674>:
  D.17666->weak_ref = iftmp.12;
  toggleref_array_size.10 = toggleref_array_size;
  toggleref_array_size.13 = toggleref_array_size.10 + 1;
  toggleref_array_size = toggleref_array_size.13;
  sgen_gc_unlock ();
}


ensure_toggleref_capacity (int capacity)
{
  struct MonoGCToggleRef * toggleref_array.14;
  int toggleref_array_capacity.15;
  long unsigned int D.17681;
  long unsigned int D.17682;
  void * toggleref_array.16;
  int toggleref_array_size.17;
  int D.17685;
  int toggleref_array_capacity.18;
  long unsigned int D.17689;
  long unsigned int D.17690;
  long unsigned int D.17691;
  long unsigned int D.17692;

  toggleref_array.14 = toggleref_array;
  if (toggleref_array.14 == 0B) goto <D.17678>; else goto <D.17679>;
  <D.17678>:
  toggleref_array_capacity = 32;
  toggleref_array_capacity.15 = toggleref_array_capacity;
  D.17681 = (long unsigned int) toggleref_array_capacity.15;
  D.17682 = D.17681 * 16;
  toggleref_array.16 = sgen_alloc_internal_dynamic (D.17682, 27, 1);
  toggleref_array = toggleref_array.16;
  <D.17679>:
  toggleref_array_size.17 = toggleref_array_size;
  D.17685 = toggleref_array_size.17 + capacity;
  toggleref_array_capacity.15 = toggleref_array_capacity;
  if (D.17685 >= toggleref_array_capacity.15) goto <D.17686>; else goto <D.17687>;
  <D.17686>:
  {
    struct MonoGCToggleRef * tmp;
    int old_capacity;

    old_capacity = toggleref_array_capacity;
    goto <D.17577>;
    <D.17576>:
    toggleref_array_capacity.15 = toggleref_array_capacity;
    toggleref_array_capacity.18 = toggleref_array_capacity.15 * 2;
    toggleref_array_capacity = toggleref_array_capacity.18;
    <D.17577>:
    toggleref_array_size.17 = toggleref_array_size;
    D.17685 = toggleref_array_size.17 + capacity;
    toggleref_array_capacity.15 = toggleref_array_capacity;
    if (D.17685 > toggleref_array_capacity.15) goto <D.17576>; else goto <D.17578>;
    <D.17578>:
    toggleref_array_capacity.15 = toggleref_array_capacity;
    D.17681 = (long unsigned int) toggleref_array_capacity.15;
    D.17682 = D.17681 * 16;
    tmp = sgen_alloc_internal_dynamic (D.17682, 27, 1);
    toggleref_array_size.17 = toggleref_array_size;
    D.17689 = (long unsigned int) toggleref_array_size.17;
    D.17690 = D.17689 * 16;
    toggleref_array.14 = toggleref_array;
    memcpy (tmp, toggleref_array.14, D.17690);
    D.17691 = (long unsigned int) old_capacity;
    D.17692 = D.17691 * 16;
    toggleref_array.14 = toggleref_array;
    sgen_free_internal_dynamic (toggleref_array.14, D.17692, 27);
    toggleref_array = tmp;
  }
  <D.17687>:
}


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

  D.17694 = __builtin_object_size (__dest, 0);
  D.17693 = __builtin___memcpy_chk (__dest, __src, __len, D.17694);
  return D.17693;
}


mono_gc_toggleref_register_callback (MonoToggleRefStatus (*<T2ed3>) (struct MonoObject *) proccess_toggleref)
{
  toggleref_callback = proccess_toggleref;
}


