mono_draw_graph (struct MonoCompile * cfg, MonoGraphOptions draw_options)
{
  _Bool D.21543;
  long int D.21544;
  long int D.21545;
  char * com;
  const char * fn;
  struct FILE * fp;
  int _i;

  fn = "/tmp/minidtree.graph";
  fp = fopen (fn, "w+");
  D.21543 = fp == 0B;
  D.21544 = (long int) D.21543;
  D.21545 = __builtin_expect (D.21544, 0);
  if (D.21545 != 0) goto <D.21546>; else goto <D.21547>;
  <D.21546>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 321, "fp");
  <D.21547>:
  switch (draw_options) <default: <D.21548>, case 1: <D.21538>, case 2: <D.21536>, case 4: <D.21539>, case 8: <D.21541>, case 16: <D.21540>>
  <D.21536>:
  mono_draw_dtree (cfg, fp);
  goto <D.21537>;
  <D.21538>:
  mono_draw_cfg (cfg, fp);
  goto <D.21537>;
  <D.21539>:
  <D.21540>:
  <D.21541>:
  mono_draw_code_cfg (cfg, fp);
  goto <D.21537>;
  <D.21548>:
  <D.21537>:
  fclose (fp);
  com = monoeg_g_strdup_printf ("dot %s -Tps -o %s.ps;gv %s.ps", fn, fn, fn);
  _i = system (com);
  monoeg_g_free (com);
}


mono_draw_dtree (struct MonoCompile * cfg, struct FILE * fp)
{
  unsigned int D.21549;
  unsigned int D.21550;
  _Bool D.21551;
  long int D.21552;
  long int D.21553;
  struct MonoMethod * D.21556;
  const char * D.21557;
  char * D.21558;
  char * D.21559;

  D.21549 = cfg->comp_done;
  D.21550 = D.21549 & 2;
  D.21551 = D.21550 == 0;
  D.21552 = (long int) D.21551;
  D.21553 = __builtin_expect (D.21552, 0);
  if (D.21553 != 0) goto <D.21554>; else goto <D.21555>;
  <D.21554>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 128, "(cfg->comp_done & MONO_COMP_IDOM)");
  <D.21555>:
  D.21556 = cfg->method;
  D.21557 = D.21556->name;
  D.21558 = convert_name (D.21557);
  fprintf (fp, "digraph %s {\n", D.21558);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.21556 = cfg->method;
  D.21559 = mono_method_full_name (D.21556, 1);
  fprintf (fp, "label=\"Dominator tree for %s\";\n", D.21559);
  fprintf (fp, "BB0 [shape=doublecircle];\n");
  fprintf (fp, "BB1 [color=red];\n");
  dtree_emit_one_loop_level (cfg, fp, 0B);
  fprintf (fp, "}\n");
}


convert_name (const char * str)
{
  unsigned int D.21560;
  int D.21561;
  unsigned int D.21562;
  sizetype i.0;
  const char * D.21564;
  int D.21565;
  int j.1;
  sizetype j.2;
  char * D.21568;
  int j.3;
  sizetype j.4;
  char * D.21571;
  sizetype j.5;
  char * D.21573;
  char * D.21574;
  int i;
  int j;
  int len;
  char * res;

  D.21560 = strlen (str);
  len = (int) D.21560;
  D.21561 = len * 2;
  D.21562 = (unsigned int) D.21561;
  res = monoeg_malloc (D.21562);
  j = 0;
  i = 0;
  goto <D.21470>;
  <D.21469>:
  {
    char c;

    i.0 = (sizetype) i;
    D.21564 = str + i.0;
    c = *D.21564;
    D.21565 = (int) c;
    switch (D.21565) <default: <D.21468>, case 46: <D.21466>>
    <D.21466>:
    j.1 = j;
    j = j.1 + 1;
    j.2 = (sizetype) j.1;
    D.21568 = res + j.2;
    *D.21568 = 95;
    goto <D.21467>;
    <D.21468>:
    j.3 = j;
    j = j.3 + 1;
    j.4 = (sizetype) j.3;
    D.21571 = res + j.4;
    *D.21571 = c;
    <D.21467>:
  }
  i = i + 1;
  <D.21470>:
  if (i < len) goto <D.21469>; else goto <D.21471>;
  <D.21471>:
  j.5 = (sizetype) j;
  D.21573 = res + j.5;
  *D.21573 = 0;
  D.21574 = res;
  return D.21574;
}


dtree_emit_one_loop_level (struct MonoCompile * cfg, struct FILE * fp, struct MonoBasicBlock * h)
{
  signed char D.21578;
  int D.21579;
  struct MonoBasicBlock * * D.21580;
  unsigned int i.6;
  unsigned int D.21582;
  struct MonoBasicBlock * * D.21583;
  struct GList * D.21587;
  struct GList * D.21588;
  signed char D.21590;
  int D.21591;
  struct MonoBasicBlock * D.21594;
  int D.21595;
  int D.21596;
  int D.21597;
  struct GList * D.21600;
  unsigned int i.7;
  unsigned int D.21604;
  struct MonoBasicBlock * bb;
  int i;
  int level;

  level = 0;
  if (h != 0B) goto <D.21576>; else goto <D.21577>;
  <D.21576>:
  D.21578 = h->nesting;
  level = (int) D.21578;
  D.21579 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.21579);
  D.21579 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.21579);
  <D.21577>:
  i = 1;
  goto <D.21481>;
  <D.21480>:
  D.21580 = cfg->bblocks;
  i.6 = (unsigned int) i;
  D.21582 = i.6 * 4;
  D.21583 = D.21580 + D.21582;
  bb = *D.21583;
  if (h == 0B) goto <D.21584>; else goto <D.21586>;
  <D.21586>:
  D.21587 = h->loop_blocks;
  D.21588 = monoeg_g_list_find (D.21587, bb);
  if (D.21588 != 0B) goto <D.21589>; else goto <D.21585>;
  <D.21589>:
  if (bb != h) goto <D.21584>; else goto <D.21585>;
  <D.21584>:
  D.21590 = bb->nesting;
  D.21591 = (int) D.21590;
  if (D.21591 == level) goto <D.21592>; else goto <D.21593>;
  <D.21592>:
  D.21594 = bb->idom;
  D.21595 = D.21594->block_num;
  D.21596 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21595, D.21596);
  <D.21593>:
  D.21590 = bb->nesting;
  D.21591 = (int) D.21590;
  D.21597 = level + 1;
  if (D.21591 == D.21597) goto <D.21598>; else goto <D.21599>;
  <D.21598>:
  D.21600 = bb->loop_blocks;
  if (D.21600 != 0B) goto <D.21601>; else goto <D.21602>;
  <D.21601>:
  D.21594 = bb->idom;
  D.21595 = D.21594->block_num;
  D.21596 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21595, D.21596);
  dtree_emit_one_loop_level (cfg, fp, bb);
  <D.21602>:
  <D.21599>:
  <D.21585>:
  i = i + 1;
  <D.21481>:
  i.7 = (unsigned int) i;
  D.21604 = cfg->num_bblocks;
  if (i.7 < D.21604) goto <D.21480>; else goto <D.21482>;
  <D.21482>:
  if (h != 0B) goto <D.21605>; else goto <D.21606>;
  <D.21605>:
  fprintf (fp, "}\n");
  <D.21606>:
}


fprintf (struct FILE * restrict __stream, const char * restrict __fmt)
{
  int D.21607;

  D.21607 = __fprintf_chk (__stream, 1, __fmt, __builtin_va_arg_pack ());
  return D.21607;
}


mono_draw_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.21609;
  const char * D.21610;
  char * D.21611;
  char * D.21612;

  D.21609 = cfg->method;
  D.21610 = D.21609->name;
  D.21611 = convert_name (D.21610);
  fprintf (fp, "digraph %s {\n", D.21611);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.21609 = cfg->method;
  D.21612 = mono_method_full_name (D.21609, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.21612);
  fprintf (fp, "BB0 [shape=doublecircle];\n");
  fprintf (fp, "BB1 [color=red];\n");
  cfg_emit_one_loop_level (cfg, fp, 0B);
  fprintf (fp, "}\n");
}


cfg_emit_one_loop_level (struct MonoCompile * cfg, struct FILE * fp, struct MonoBasicBlock * h)
{
  signed char D.21615;
  int D.21616;
  struct MonoBasicBlock * D.21617;
  unsigned int D.21618;
  unsigned int D.21621;
  int D.21622;
  struct GList * D.21626;
  struct GList * D.21627;
  signed char D.21629;
  int D.21630;
  struct MonoBasicBlock * * D.21633;
  unsigned int j.8;
  unsigned int D.21635;
  struct MonoBasicBlock * * D.21636;
  struct MonoBasicBlock * D.21637;
  int D.21638;
  short int D.21639;
  int D.21640;
  int D.21641;
  struct GList * D.21644;
  struct MonoBasicBlock * bb;
  int j;
  int level;

  level = 0;
  if (h != 0B) goto <D.21613>; else goto <D.21614>;
  <D.21613>:
  D.21615 = h->nesting;
  level = (int) D.21615;
  D.21616 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.21616);
  D.21616 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.21616);
  <D.21614>:
  D.21617 = cfg->bb_entry;
  bb = D.21617->next_bb;
  goto <D.21504>;
  <D.21503>:
  D.21618 = bb->region;
  if (D.21618 != 4294967295) goto <D.21619>; else goto <D.21620>;
  <D.21619>:
  D.21618 = bb->region;
  D.21621 = D.21618 & 240;
  switch (D.21621) <default: <D.21496>, case 16: <D.21493>, case 32: <D.21491>, case 64: <D.21494>, case 128: <D.21495>>
  <D.21491>:
  D.21622 = bb->block_num;
  fprintf (fp, "BB%d [color=blue];\n", D.21622);
  goto <D.21492>;
  <D.21493>:
  D.21622 = bb->block_num;
  fprintf (fp, "BB%d [color=green];\n", D.21622);
  goto <D.21492>;
  <D.21494>:
  <D.21495>:
  D.21622 = bb->block_num;
  fprintf (fp, "BB%d [color=yellow];\n", D.21622);
  goto <D.21492>;
  <D.21496>:
  goto <D.21492>;
  <D.21492>:
  <D.21620>:
  if (h == 0B) goto <D.21623>; else goto <D.21625>;
  <D.21625>:
  D.21626 = h->loop_blocks;
  D.21627 = monoeg_g_list_find (D.21626, bb);
  if (D.21627 != 0B) goto <D.21628>; else goto <D.21624>;
  <D.21628>:
  if (bb != h) goto <D.21623>; else goto <D.21624>;
  <D.21623>:
  D.21629 = bb->nesting;
  D.21630 = (int) D.21629;
  if (D.21630 == level) goto <D.21631>; else goto <D.21632>;
  <D.21631>:
  j = 0;
  goto <D.21498>;
  <D.21497>:
  D.21633 = bb->in_bb;
  j.8 = (unsigned int) j;
  D.21635 = j.8 * 4;
  D.21636 = D.21633 + D.21635;
  D.21637 = *D.21636;
  D.21638 = D.21637->block_num;
  D.21622 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21638, D.21622);
  j = j + 1;
  <D.21498>:
  D.21639 = bb->in_count;
  D.21640 = (int) D.21639;
  if (D.21640 > j) goto <D.21497>; else goto <D.21499>;
  <D.21499>:
  <D.21632>:
  D.21629 = bb->nesting;
  D.21630 = (int) D.21629;
  D.21641 = level + 1;
  if (D.21630 == D.21641) goto <D.21642>; else goto <D.21643>;
  <D.21642>:
  D.21644 = bb->loop_blocks;
  if (D.21644 != 0B) goto <D.21645>; else goto <D.21646>;
  <D.21645>:
  j = 0;
  goto <D.21501>;
  <D.21500>:
  D.21633 = bb->in_bb;
  j.8 = (unsigned int) j;
  D.21635 = j.8 * 4;
  D.21636 = D.21633 + D.21635;
  D.21637 = *D.21636;
  D.21638 = D.21637->block_num;
  D.21622 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21638, D.21622);
  j = j + 1;
  <D.21501>:
  D.21639 = bb->in_count;
  D.21640 = (int) D.21639;
  if (D.21640 > j) goto <D.21500>; else goto <D.21502>;
  <D.21502>:
  cfg_emit_one_loop_level (cfg, fp, bb);
  <D.21646>:
  <D.21643>:
  <D.21624>:
  bb = bb->next_bb;
  <D.21504>:
  if (bb != 0B) goto <D.21503>; else goto <D.21505>;
  <D.21505>:
  if (h != 0B) goto <D.21647>; else goto <D.21648>;
  <D.21647>:
  fprintf (fp, "}\n");
  <D.21648>:
}


mono_draw_code_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.21650;
  const char * D.21651;
  char * D.21652;
  char * D.21653;
  struct MonoBasicBlock * D.21654;
  struct MonoBasicBlock * D.21655;
  unsigned int D.21660;
  unsigned int D.21661;
  unsigned int D.21663;
  unsigned int D.21664;
  int D.21666;
  struct MonoBasicBlock * bb;

  D.21650 = cfg->method;
  D.21651 = D.21650->name;
  D.21652 = convert_name (D.21651);
  fprintf (fp, "digraph %s {\n", D.21652);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.21650 = cfg->method;
  D.21653 = mono_method_full_name (D.21650, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.21653);
  fprintf (fp, "BB0 [shape=doublecircle];\n");
  fprintf (fp, "BB1 [color=red];\n");
  D.21654 = cfg->bb_entry;
  bb = D.21654->next_bb;
  goto <D.21526>;
  <D.21525>:
  {
    struct MonoInst * inst;
    const char * color;

    D.21655 = cfg->bb_exit;
    if (D.21655 == bb) goto <D.21656>; else goto <D.21657>;
    <D.21656>:
    // predicted unlikely by continue predictor.
    goto <D.21521>;
    <D.21657>:
    D.21660 = cfg->comp_done;
    D.21661 = D.21660 & 128;
    if (D.21661 != 0) goto <D.21662>; else goto <D.21658>;
    <D.21662>:
    D.21663 = bb->flags;
    D.21664 = D.21663 & 2;
    if (D.21664 != 0) goto <D.21665>; else goto <D.21658>;
    <D.21665>:
    color = "color=red,";
    goto <D.21659>;
    <D.21658>:
    color = "";
    <D.21659>:
    D.21666 = bb->block_num;
    D.21666 = bb->block_num;
    fprintf (fp, "BB%d [%sshape=record,labeljust=l,label=\"{BB%d|", D.21666, color, D.21666);
    inst = bb->code;
    goto <D.21523>;
    <D.21522>:
    fprintf (fp, "\\n");
    inst = inst->next;
    <D.21523>:
    if (inst != 0B) goto <D.21522>; else goto <D.21524>;
    <D.21524>:
    fprintf (fp, "}\"];\n");
  }
  <D.21521>:
  bb = bb->next_bb;
  <D.21526>:
  if (bb != 0B) goto <D.21525>; else goto <D.21527>;
  <D.21527>:
  cfg_emit_one_loop_level (cfg, fp, 0B);
  fprintf (fp, "}\n");
}


