sgen_process_togglerefs ()
{
  struct FILE * gc_debug_file.0;
  int toggleref_array_size.1;
  struct MonoGCToggleRef * toggleref_array.2;
  unsigned int i.3;
  unsigned int D.17211;
  struct MonoGCToggleRef * D.17212;
  void * D.17213;
  void * D.17217;
  MonoToggleRefStatus (*<T2e20>) (struct MonoObject *) toggleref_callback.4;
  <unnamed type> D.17222;
  int D.17223;
  int D.17224;
  unsigned int w.5;
  unsigned int D.17226;
  struct MonoGCToggleRef * D.17227;
  int D.17230;
  int D.17231;
  int D.17232;
  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.17205>; else goto <D.17206>;
      <D.17205>:
      gc_debug_file.0 = gc_debug_file;
      toggleref_array_size.1 = toggleref_array_size;
      fprintf (gc_debug_file.0, "Proccessing ToggleRefs %d\n", toggleref_array_size.1);
      gc_debug_file.0 = gc_debug_file;
      fflush (gc_debug_file.0);
      <D.17206>:
      w = 0;
      i = w;
      goto <D.17173>;
      <D.17172>:
      {
        int res;
        struct MonoGCToggleRef r;
        struct MonoObject * obj;

        try
          {
            toggleref_array.2 = toggleref_array;
            i.3 = (unsigned int) i;
            D.17211 = i.3 * 8;
            D.17212 = toggleref_array.2 + D.17211;
            r = *D.17212;
            D.17213 = r.strong_ref;
            if (D.17213 != 0B) goto <D.17214>; else goto <D.17215>;
            <D.17214>:
            obj = r.strong_ref;
            goto <D.17216>;
            <D.17215>:
            D.17217 = r.weak_ref;
            if (D.17217 != 0B) goto <D.17218>; else goto <D.17219>;
            <D.17218>:
            obj = r.weak_ref;
            goto <D.17220>;
            <D.17219>:
            // predicted unlikely by continue predictor.
            goto <D.17166>;
            <D.17220>:
            <D.17216>:
            toggleref_callback.4 = toggleref_callback;
            D.17222 = toggleref_callback.4 (obj);
            res = (int) D.17222;
            D.17223 = toggle_ref_counts[res];
            D.17224 = D.17223 + 1;
            toggle_ref_counts[res] = D.17224;
            switch (res) <default: <D.17171>, case 0: <D.17167>, case 1: <D.17169>, case 2: <D.17170>>
            <D.17167>:
            goto <D.17168>;
            <D.17169>:
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17226 = w.5 * 8;
            D.17227 = toggleref_array.2 + D.17226;
            D.17227->strong_ref = obj;
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17226 = w.5 * 8;
            D.17227 = toggleref_array.2 + D.17226;
            D.17227->weak_ref = 0B;
            w = w + 1;
            goto <D.17168>;
            <D.17170>:
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17226 = w.5 * 8;
            D.17227 = toggleref_array.2 + D.17226;
            D.17227->strong_ref = 0B;
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17226 = w.5 * 8;
            D.17227 = toggleref_array.2 + D.17226;
            D.17227->weak_ref = obj;
            w = w + 1;
            goto <D.17168>;
            <D.17171>:
            monoeg_assertion_message ("* Assertion: should not be reached at %s:%d\n", "sgen-toggleref.c", 80);
            <D.17168>:
          }
        finally
          {
            r = {CLOBBER};
          }
      }
      <D.17166>:
      i = i + 1;
      <D.17173>:
      toggleref_array_size.1 = toggleref_array_size;
      if (i < toggleref_array_size.1) goto <D.17172>; else goto <D.17174>;
      <D.17174>:
      toggleref_array_size = w;
      if (0 != 0) goto <D.17228>; else goto <D.17229>;
      <D.17228>:
      gc_debug_file.0 = gc_debug_file;
      D.17230 = toggle_ref_counts[0];
      D.17231 = toggle_ref_counts[1];
      D.17232 = toggle_ref_counts[2];
      fprintf (gc_debug_file.0, "Done Proccessing ToggleRefs dropped %d strong %d weak %d final size %d\n", D.17230, D.17231, D.17232, w);
      gc_debug_file.0 = gc_debug_file;
      fflush (gc_debug_file.0);
      <D.17229>:
    }
  finally
    {
      toggle_ref_counts = {CLOBBER};
    }
}


sgen_scan_togglerefs (char * start, char * end, struct ScanCopyContext ctx)
{
  struct FILE * gc_debug_file.6;
  int toggleref_array_size.7;
  struct MonoGCToggleRef * toggleref_array.8;
  unsigned int i.9;
  unsigned int D.17242;
  struct MonoGCToggleRef * D.17243;
  void * D.17244;
  void * * D.17253;
  void * D.17255;
  int D.17262;
  void * * D.17270;
  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.17236>; else goto <D.17237>;
  <D.17236>:
  gc_debug_file.6 = gc_debug_file;
  toggleref_array_size.7 = toggleref_array_size;
  fprintf (gc_debug_file.6, "Scanning ToggleRefs %d\n", toggleref_array_size.7);
  gc_debug_file.6 = gc_debug_file;
  fflush (gc_debug_file.6);
  <D.17237>:
  i = 0;
  goto <D.17186>;
  <D.17185>:
  toggleref_array.8 = toggleref_array;
  i.9 = (unsigned int) i;
  D.17242 = i.9 * 8;
  D.17243 = toggleref_array.8 + D.17242;
  D.17244 = D.17243->strong_ref;
  if (D.17244 != 0B) goto <D.17245>; else goto <D.17246>;
  <D.17245>:
  {
    char * object;

    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17242 = i.9 * 8;
    D.17243 = toggleref_array.8 + D.17242;
    object = D.17243->strong_ref;
    if (object >= start) goto <D.17247>; else goto <D.17248>;
    <D.17247>:
    if (object < end) goto <D.17249>; else goto <D.17250>;
    <D.17249>:
    if (0 != 0) goto <D.17251>; else goto <D.17252>;
    <D.17251>:
    gc_debug_file.6 = gc_debug_file;
    fprintf (gc_debug_file.6, "\tcopying strong slot %d\n", i);
    gc_debug_file.6 = gc_debug_file;
    fflush (gc_debug_file.6);
    <D.17252>:
    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17242 = i.9 * 8;
    D.17243 = toggleref_array.8 + D.17242;
    D.17253 = &D.17243->strong_ref;
    copy_func (D.17253, queue);
    <D.17250>:
    <D.17248>:
  }
  goto <D.17254>;
  <D.17246>:
  toggleref_array.8 = toggleref_array;
  i.9 = (unsigned int) i;
  D.17242 = i.9 * 8;
  D.17243 = toggleref_array.8 + D.17242;
  D.17255 = D.17243->weak_ref;
  if (D.17255 != 0B) goto <D.17256>; else goto <D.17257>;
  <D.17256>:
  {
    char * object;

    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17242 = i.9 * 8;
    D.17243 = toggleref_array.8 + D.17242;
    object = D.17243->weak_ref;
    if (object >= start) goto <D.17258>; else goto <D.17259>;
    <D.17258>:
    if (object < end) goto <D.17260>; else goto <D.17261>;
    <D.17260>:
    D.17262 = sgen_gc_is_object_ready_for_finalization (object);
    if (D.17262 != 0) goto <D.17263>; else goto <D.17264>;
    <D.17263>:
    if (0 != 0) goto <D.17265>; else goto <D.17266>;
    <D.17265>:
    gc_debug_file.6 = gc_debug_file;
    fprintf (gc_debug_file.6, "\tcleaning weak slot %d\n", i);
    gc_debug_file.6 = gc_debug_file;
    fflush (gc_debug_file.6);
    <D.17266>:
    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17242 = i.9 * 8;
    D.17243 = toggleref_array.8 + D.17242;
    D.17243->weak_ref = 0B;
    goto <D.17267>;
    <D.17264>:
    if (0 != 0) goto <D.17268>; else goto <D.17269>;
    <D.17268>:
    gc_debug_file.6 = gc_debug_file;
    fprintf (gc_debug_file.6, "\tkeeping weak slot %d\n", i);
    gc_debug_file.6 = gc_debug_file;
    fflush (gc_debug_file.6);
    <D.17269>:
    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17242 = i.9 * 8;
    D.17243 = toggleref_array.8 + D.17242;
    D.17270 = &D.17243->weak_ref;
    copy_func (D.17270, queue);
    <D.17267>:
    <D.17261>:
    <D.17259>:
  }
  <D.17257>:
  <D.17254>:
  i = i + 1;
  <D.17186>:
  toggleref_array_size.7 = toggleref_array_size;
  if (i < toggleref_array_size.7) goto <D.17185>; else goto <D.17187>;
  <D.17187>:
}


mono_gc_toggleref_add (struct MonoObject * object, mono_bool strong_ref)
{
  MonoToggleRefStatus (*<T2e20>) (struct MonoObject *) toggleref_callback.10;
  struct FILE * gc_debug_file.11;
  struct MonoGCToggleRef * toggleref_array.12;
  int toggleref_array_size.13;
  unsigned int toggleref_array_size.14;
  unsigned int D.17280;
  struct MonoGCToggleRef * D.17281;
  void * iftmp.15;
  void * iftmp.16;
  int toggleref_array_size.17;

  toggleref_callback.10 = toggleref_callback;
  if (toggleref_callback.10 == 0B) goto <D.17272>; else goto <D.17273>;
  <D.17272>:
  return;
  <D.17273>:
  if (0 != 0) goto <D.17274>; else goto <D.17275>;
  <D.17274>:
  gc_debug_file.11 = gc_debug_file;
  fprintf (gc_debug_file.11, "Adding toggleref %p %d\n", object, strong_ref);
  gc_debug_file.11 = gc_debug_file;
  fflush (gc_debug_file.11);
  <D.17275>:
  sgen_gc_lock ();
  ensure_toggleref_capacity (1);
  toggleref_array.12 = toggleref_array;
  toggleref_array_size.13 = toggleref_array_size;
  toggleref_array_size.14 = (unsigned int) toggleref_array_size.13;
  D.17280 = toggleref_array_size.14 * 8;
  D.17281 = toggleref_array.12 + D.17280;
  if (strong_ref != 0) goto <D.17283>; else goto <D.17284>;
  <D.17283>:
  iftmp.15 = object;
  goto <D.17285>;
  <D.17284>:
  iftmp.15 = 0B;
  <D.17285>:
  D.17281->strong_ref = iftmp.15;
  toggleref_array.12 = toggleref_array;
  toggleref_array_size.13 = toggleref_array_size;
  toggleref_array_size.14 = (unsigned int) toggleref_array_size.13;
  D.17280 = toggleref_array_size.14 * 8;
  D.17281 = toggleref_array.12 + D.17280;
  if (strong_ref == 0) goto <D.17287>; else goto <D.17288>;
  <D.17287>:
  iftmp.16 = object;
  goto <D.17289>;
  <D.17288>:
  iftmp.16 = 0B;
  <D.17289>:
  D.17281->weak_ref = iftmp.16;
  toggleref_array_size.13 = toggleref_array_size;
  toggleref_array_size.17 = toggleref_array_size.13 + 1;
  toggleref_array_size = toggleref_array_size.17;
  sgen_gc_unlock ();
}


ensure_toggleref_capacity (int capacity)
{
  struct MonoGCToggleRef * toggleref_array.18;
  int toggleref_array_capacity.19;
  unsigned int toggleref_array_capacity.20;
  unsigned int D.17297;
  void * toggleref_array.21;
  int toggleref_array_size.22;
  int D.17300;
  int toggleref_array_capacity.23;
  unsigned int toggleref_array_size.24;
  unsigned int D.17305;
  unsigned int old_capacity.25;
  unsigned int D.17307;

  toggleref_array.18 = toggleref_array;
  if (toggleref_array.18 == 0B) goto <D.17293>; else goto <D.17294>;
  <D.17293>:
  toggleref_array_capacity = 32;
  toggleref_array_capacity.19 = toggleref_array_capacity;
  toggleref_array_capacity.20 = (unsigned int) toggleref_array_capacity.19;
  D.17297 = toggleref_array_capacity.20 * 8;
  toggleref_array.21 = sgen_alloc_internal_dynamic (D.17297, 27, 1);
  toggleref_array = toggleref_array.21;
  <D.17294>:
  toggleref_array_size.22 = toggleref_array_size;
  D.17300 = toggleref_array_size.22 + capacity;
  toggleref_array_capacity.19 = toggleref_array_capacity;
  if (D.17300 >= toggleref_array_capacity.19) goto <D.17301>; else goto <D.17302>;
  <D.17301>:
  {
    struct MonoGCToggleRef * tmp;
    int old_capacity;

    old_capacity = toggleref_array_capacity;
    goto <D.17194>;
    <D.17193>:
    toggleref_array_capacity.19 = toggleref_array_capacity;
    toggleref_array_capacity.23 = toggleref_array_capacity.19 * 2;
    toggleref_array_capacity = toggleref_array_capacity.23;
    <D.17194>:
    toggleref_array_size.22 = toggleref_array_size;
    D.17300 = toggleref_array_size.22 + capacity;
    toggleref_array_capacity.19 = toggleref_array_capacity;
    if (D.17300 > toggleref_array_capacity.19) goto <D.17193>; else goto <D.17195>;
    <D.17195>:
    toggleref_array_capacity.19 = toggleref_array_capacity;
    toggleref_array_capacity.20 = (unsigned int) toggleref_array_capacity.19;
    D.17297 = toggleref_array_capacity.20 * 8;
    tmp = sgen_alloc_internal_dynamic (D.17297, 27, 1);
    toggleref_array.18 = toggleref_array;
    toggleref_array_size.22 = toggleref_array_size;
    toggleref_array_size.24 = (unsigned int) toggleref_array_size.22;
    D.17305 = toggleref_array_size.24 * 8;
    memcpy (tmp, toggleref_array.18, D.17305);
    toggleref_array.18 = toggleref_array;
    old_capacity.25 = (unsigned int) old_capacity;
    D.17307 = old_capacity.25 * 8;
    sgen_free_internal_dynamic (toggleref_array.18, D.17307, 27);
    toggleref_array = tmp;
  }
  <D.17302>:
}


memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.17308;
  unsigned int D.17309;

  D.17309 = __builtin_object_size (__dest, 0);
  D.17308 = __builtin___memcpy_chk (__dest, __src, __len, D.17309);
  return D.17308;
}


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


