sgen_process_togglerefs ()
{
  int toggleref_array_size.0;
  struct FILE * gc_debug_file.1;
  struct MonoGCToggleRef * toggleref_array.2;
  unsigned int i.3;
  unsigned int D.17231;
  struct MonoGCToggleRef * D.17232;
  void * D.17233;
  void * D.17237;
  MonoToggleRefStatus (*<T2e26>) (struct MonoObject *) toggleref_callback.4;
  <unnamed type> D.17242;
  int D.17243;
  int D.17244;
  unsigned int w.5;
  unsigned int D.17246;
  struct MonoGCToggleRef * D.17247;
  int D.17250;
  int D.17251;
  int D.17252;
  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.17225>; else goto <D.17226>;
      <D.17225>:
      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.17226>:
      w = 0;
      i = w;
      goto <D.17193>;
      <D.17192>:
      {
        int res;
        struct MonoGCToggleRef r;
        struct MonoObject * obj;

        try
          {
            toggleref_array.2 = toggleref_array;
            i.3 = (unsigned int) i;
            D.17231 = i.3 * 8;
            D.17232 = toggleref_array.2 + D.17231;
            r = *D.17232;
            D.17233 = r.strong_ref;
            if (D.17233 != 0B) goto <D.17234>; else goto <D.17235>;
            <D.17234>:
            obj = r.strong_ref;
            goto <D.17236>;
            <D.17235>:
            D.17237 = r.weak_ref;
            if (D.17237 != 0B) goto <D.17238>; else goto <D.17239>;
            <D.17238>:
            obj = r.weak_ref;
            goto <D.17240>;
            <D.17239>:
            // predicted unlikely by continue predictor.
            goto <D.17186>;
            <D.17240>:
            <D.17236>:
            toggleref_callback.4 = toggleref_callback;
            D.17242 = toggleref_callback.4 (obj);
            res = (int) D.17242;
            D.17243 = toggle_ref_counts[res];
            D.17244 = D.17243 + 1;
            toggle_ref_counts[res] = D.17244;
            switch (res) <default: <D.17191>, case 0: <D.17187>, case 1: <D.17189>, case 2: <D.17190>>
            <D.17187>:
            goto <D.17188>;
            <D.17189>:
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17246 = w.5 * 8;
            D.17247 = toggleref_array.2 + D.17246;
            D.17247->strong_ref = obj;
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17246 = w.5 * 8;
            D.17247 = toggleref_array.2 + D.17246;
            D.17247->weak_ref = 0B;
            w = w + 1;
            goto <D.17188>;
            <D.17190>:
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17246 = w.5 * 8;
            D.17247 = toggleref_array.2 + D.17246;
            D.17247->strong_ref = 0B;
            toggleref_array.2 = toggleref_array;
            w.5 = (unsigned int) w;
            D.17246 = w.5 * 8;
            D.17247 = toggleref_array.2 + D.17246;
            D.17247->weak_ref = obj;
            w = w + 1;
            goto <D.17188>;
            <D.17191>:
            monoeg_assertion_message ("* Assertion: should not be reached at %s:%d\n", "sgen-toggleref.c", 80);
            <D.17188>:
          }
        finally
          {
            r = {CLOBBER};
          }
      }
      <D.17186>:
      i = i + 1;
      <D.17193>:
      toggleref_array_size.0 = toggleref_array_size;
      if (i < toggleref_array_size.0) goto <D.17192>; else goto <D.17194>;
      <D.17194>:
      toggleref_array_size = w;
      if (0 != 0) goto <D.17248>; else goto <D.17249>;
      <D.17248>:
      D.17250 = toggle_ref_counts[2];
      D.17251 = toggle_ref_counts[1];
      D.17252 = 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.17252, D.17251, D.17250, w);
      gc_debug_file.1 = gc_debug_file;
      fflush (gc_debug_file.1);
      <D.17249>:
    }
  finally
    {
      toggle_ref_counts = {CLOBBER};
    }
}


sgen_scan_togglerefs (char * start, char * end, struct ScanCopyContext ctx)
{
  int toggleref_array_size.6;
  struct FILE * gc_debug_file.7;
  struct MonoGCToggleRef * toggleref_array.8;
  unsigned int i.9;
  unsigned int D.17262;
  struct MonoGCToggleRef * D.17263;
  void * D.17264;
  _Bool D.17267;
  _Bool D.17268;
  _Bool D.17269;
  void * * D.17274;
  void * D.17276;
  _Bool D.17279;
  _Bool D.17280;
  _Bool D.17281;
  int D.17284;
  void * * D.17292;
  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.17256>; else goto <D.17257>;
  <D.17256>:
  toggleref_array_size.6 = toggleref_array_size;
  gc_debug_file.7 = gc_debug_file;
  fprintf (gc_debug_file.7, "Scanning ToggleRefs %d\n", toggleref_array_size.6);
  gc_debug_file.7 = gc_debug_file;
  fflush (gc_debug_file.7);
  <D.17257>:
  i = 0;
  goto <D.17206>;
  <D.17205>:
  toggleref_array.8 = toggleref_array;
  i.9 = (unsigned int) i;
  D.17262 = i.9 * 8;
  D.17263 = toggleref_array.8 + D.17262;
  D.17264 = D.17263->strong_ref;
  if (D.17264 != 0B) goto <D.17265>; else goto <D.17266>;
  <D.17265>:
  {
    char * object;

    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17262 = i.9 * 8;
    D.17263 = toggleref_array.8 + D.17262;
    object = D.17263->strong_ref;
    D.17267 = object >= start;
    D.17268 = object < end;
    D.17269 = D.17267 & D.17268;
    if (D.17269 != 0) goto <D.17270>; else goto <D.17271>;
    <D.17270>:
    if (0 != 0) goto <D.17272>; else goto <D.17273>;
    <D.17272>:
    gc_debug_file.7 = gc_debug_file;
    fprintf (gc_debug_file.7, "\tcopying strong slot %d\n", i);
    gc_debug_file.7 = gc_debug_file;
    fflush (gc_debug_file.7);
    <D.17273>:
    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17262 = i.9 * 8;
    D.17263 = toggleref_array.8 + D.17262;
    D.17274 = &D.17263->strong_ref;
    copy_func (D.17274, queue);
    <D.17271>:
  }
  goto <D.17275>;
  <D.17266>:
  toggleref_array.8 = toggleref_array;
  i.9 = (unsigned int) i;
  D.17262 = i.9 * 8;
  D.17263 = toggleref_array.8 + D.17262;
  D.17276 = D.17263->weak_ref;
  if (D.17276 != 0B) goto <D.17277>; else goto <D.17278>;
  <D.17277>:
  {
    char * object;

    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17262 = i.9 * 8;
    D.17263 = toggleref_array.8 + D.17262;
    object = D.17263->weak_ref;
    D.17279 = object >= start;
    D.17280 = object < end;
    D.17281 = D.17279 & D.17280;
    if (D.17281 != 0) goto <D.17282>; else goto <D.17283>;
    <D.17282>:
    D.17284 = sgen_gc_is_object_ready_for_finalization (object);
    if (D.17284 != 0) goto <D.17285>; else goto <D.17286>;
    <D.17285>:
    if (0 != 0) goto <D.17287>; else goto <D.17288>;
    <D.17287>:
    gc_debug_file.7 = gc_debug_file;
    fprintf (gc_debug_file.7, "\tcleaning weak slot %d\n", i);
    gc_debug_file.7 = gc_debug_file;
    fflush (gc_debug_file.7);
    <D.17288>:
    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17262 = i.9 * 8;
    D.17263 = toggleref_array.8 + D.17262;
    D.17263->weak_ref = 0B;
    goto <D.17289>;
    <D.17286>:
    if (0 != 0) goto <D.17290>; else goto <D.17291>;
    <D.17290>:
    gc_debug_file.7 = gc_debug_file;
    fprintf (gc_debug_file.7, "\tkeeping weak slot %d\n", i);
    gc_debug_file.7 = gc_debug_file;
    fflush (gc_debug_file.7);
    <D.17291>:
    toggleref_array.8 = toggleref_array;
    i.9 = (unsigned int) i;
    D.17262 = i.9 * 8;
    D.17263 = toggleref_array.8 + D.17262;
    D.17292 = &D.17263->weak_ref;
    copy_func (D.17292, queue);
    <D.17289>:
    <D.17283>:
  }
  <D.17278>:
  <D.17275>:
  i = i + 1;
  <D.17206>:
  toggleref_array_size.6 = toggleref_array_size;
  if (i < toggleref_array_size.6) goto <D.17205>; else goto <D.17207>;
  <D.17207>:
}


mono_gc_toggleref_add (struct MonoObject * object, mono_bool strong_ref)
{
  MonoToggleRefStatus (*<T2e26>) (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.17302;
  struct MonoGCToggleRef * D.17303;
  void * iftmp.15;
  void * iftmp.16;
  int toggleref_array_size.17;

  toggleref_callback.10 = toggleref_callback;
  if (toggleref_callback.10 == 0B) goto <D.17294>; else goto <D.17295>;
  <D.17294>:
  return;
  <D.17295>:
  if (0 != 0) goto <D.17296>; else goto <D.17297>;
  <D.17296>:
  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.17297>:
  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.17302 = toggleref_array_size.14 * 8;
  D.17303 = toggleref_array.12 + D.17302;
  if (strong_ref != 0) goto <D.17305>; else goto <D.17306>;
  <D.17305>:
  iftmp.15 = object;
  goto <D.17307>;
  <D.17306>:
  iftmp.15 = 0B;
  <D.17307>:
  D.17303->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.17302 = toggleref_array_size.14 * 8;
  D.17303 = toggleref_array.12 + D.17302;
  if (strong_ref == 0) goto <D.17309>; else goto <D.17310>;
  <D.17309>:
  iftmp.16 = object;
  goto <D.17311>;
  <D.17310>:
  iftmp.16 = 0B;
  <D.17311>:
  D.17303->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.17319;
  void * toggleref_array.21;
  int toggleref_array_size.22;
  int D.17322;
  int toggleref_array_capacity.23;
  unsigned int toggleref_array_size.24;
  unsigned int D.17327;
  unsigned int old_capacity.25;
  unsigned int D.17329;

  toggleref_array.18 = toggleref_array;
  if (toggleref_array.18 == 0B) goto <D.17315>; else goto <D.17316>;
  <D.17315>:
  toggleref_array_capacity = 32;
  toggleref_array_capacity.19 = toggleref_array_capacity;
  toggleref_array_capacity.20 = (unsigned int) toggleref_array_capacity.19;
  D.17319 = toggleref_array_capacity.20 * 8;
  toggleref_array.21 = sgen_alloc_internal_dynamic (D.17319, 27, 1);
  toggleref_array = toggleref_array.21;
  <D.17316>:
  toggleref_array_size.22 = toggleref_array_size;
  D.17322 = toggleref_array_size.22 + capacity;
  toggleref_array_capacity.19 = toggleref_array_capacity;
  if (D.17322 >= toggleref_array_capacity.19) goto <D.17323>; else goto <D.17324>;
  <D.17323>:
  {
    struct MonoGCToggleRef * tmp;
    int old_capacity;

    old_capacity = toggleref_array_capacity;
    goto <D.17214>;
    <D.17213>:
    toggleref_array_capacity.19 = toggleref_array_capacity;
    toggleref_array_capacity.23 = toggleref_array_capacity.19 * 2;
    toggleref_array_capacity = toggleref_array_capacity.23;
    <D.17214>:
    toggleref_array_size.22 = toggleref_array_size;
    D.17322 = toggleref_array_size.22 + capacity;
    toggleref_array_capacity.19 = toggleref_array_capacity;
    if (D.17322 > toggleref_array_capacity.19) goto <D.17213>; else goto <D.17215>;
    <D.17215>:
    toggleref_array_capacity.19 = toggleref_array_capacity;
    toggleref_array_capacity.20 = (unsigned int) toggleref_array_capacity.19;
    D.17319 = toggleref_array_capacity.20 * 8;
    tmp = sgen_alloc_internal_dynamic (D.17319, 27, 1);
    toggleref_array_size.22 = toggleref_array_size;
    toggleref_array_size.24 = (unsigned int) toggleref_array_size.22;
    D.17327 = toggleref_array_size.24 * 8;
    toggleref_array.18 = toggleref_array;
    memcpy (tmp, toggleref_array.18, D.17327);
    old_capacity.25 = (unsigned int) old_capacity;
    D.17329 = old_capacity.25 * 8;
    toggleref_array.18 = toggleref_array;
    sgen_free_internal_dynamic (toggleref_array.18, D.17329, 27);
    toggleref_array = tmp;
  }
  <D.17324>:
}


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

  D.17331 = __builtin_object_size (__dest, 0);
  D.17330 = __builtin___memcpy_chk (__dest, __src, __len, D.17331);
  return D.17330;
}


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


