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

  fn = "/tmp/minidtree.graph";
  fp = fopen (fn, "w+");
  D.24378 = fp == 0B;
  D.24379 = (long int) D.24378;
  D.24380 = __builtin_expect (D.24379, 0);
  if (D.24380 != 0) goto <D.24381>; else goto <D.24382>;
  <D.24381>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 321, "fp");
  <D.24382>:
  switch (draw_options) <default: <D.24383>, case 1: <D.24371>, case 2: <D.24369>, case 4: <D.24372>, case 8: <D.24374>, case 16: <D.24373>>
  <D.24369>:
  mono_draw_dtree (cfg, fp);
  goto <D.24370>;
  <D.24371>:
  mono_draw_cfg (cfg, fp);
  goto <D.24370>;
  <D.24372>:
  <D.24373>:
  <D.24374>:
  mono_draw_code_cfg (cfg, fp);
  goto <D.24370>;
  <D.24383>:
  <D.24370>:
  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.24384;
  unsigned int D.24385;
  _Bool D.24386;
  long int D.24387;
  long int D.24388;
  struct MonoMethod * D.24391;
  const char * D.24392;
  char * D.24393;
  char * D.24394;

  D.24384 = cfg->comp_done;
  D.24385 = D.24384 & 2;
  D.24386 = D.24385 == 0;
  D.24387 = (long int) D.24386;
  D.24388 = __builtin_expect (D.24387, 0);
  if (D.24388 != 0) goto <D.24389>; else goto <D.24390>;
  <D.24389>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 128, "(cfg->comp_done & MONO_COMP_IDOM)");
  <D.24390>:
  D.24391 = cfg->method;
  D.24392 = D.24391->name;
  D.24393 = convert_name (D.24392);
  fprintf (fp, "digraph %s {\n", D.24393);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.24391 = cfg->method;
  D.24394 = mono_method_full_name (D.24391, 1);
  fprintf (fp, "label=\"Dominator tree for %s\";\n", D.24394);
  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.24395;
  int D.24396;
  unsigned int D.24397;
  sizetype i.0;
  const char * D.24399;
  int D.24400;
  int j.1;
  sizetype j.2;
  char * D.24403;
  int j.3;
  sizetype j.4;
  char * D.24406;
  sizetype j.5;
  char * D.24408;
  char * D.24409;
  int i;
  int j;
  int len;
  char * res;

  D.24395 = strlen (str);
  len = (int) D.24395;
  D.24396 = len * 2;
  D.24397 = (unsigned int) D.24396;
  res = monoeg_malloc (D.24397);
  j = 0;
  i = 0;
  goto <D.24303>;
  <D.24302>:
  {
    char c;

    i.0 = (sizetype) i;
    D.24399 = str + i.0;
    c = *D.24399;
    D.24400 = (int) c;
    switch (D.24400) <default: <D.24301>, case 46: <D.24299>>
    <D.24299>:
    j.1 = j;
    j = j.1 + 1;
    j.2 = (sizetype) j.1;
    D.24403 = res + j.2;
    *D.24403 = 95;
    goto <D.24300>;
    <D.24301>:
    j.3 = j;
    j = j.3 + 1;
    j.4 = (sizetype) j.3;
    D.24406 = res + j.4;
    *D.24406 = c;
    <D.24300>:
  }
  i = i + 1;
  <D.24303>:
  if (i < len) goto <D.24302>; else goto <D.24304>;
  <D.24304>:
  j.5 = (sizetype) j;
  D.24408 = res + j.5;
  *D.24408 = 0;
  D.24409 = res;
  return D.24409;
}


dtree_emit_one_loop_level (struct MonoCompile * cfg, struct FILE * fp, struct MonoBasicBlock * h)
{
  signed char D.24413;
  int D.24414;
  struct MonoBasicBlock * * D.24415;
  unsigned int i.6;
  unsigned int D.24417;
  struct MonoBasicBlock * * D.24418;
  struct GList * D.24422;
  struct GList * D.24423;
  signed char D.24425;
  int D.24426;
  struct MonoBasicBlock * D.24429;
  int D.24430;
  int D.24431;
  int D.24432;
  struct GList * D.24435;
  unsigned int i.7;
  unsigned int D.24439;
  struct MonoBasicBlock * bb;
  int i;
  int level;

  level = 0;
  if (h != 0B) goto <D.24411>; else goto <D.24412>;
  <D.24411>:
  D.24413 = h->nesting;
  level = (int) D.24413;
  D.24414 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.24414);
  D.24414 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.24414);
  <D.24412>:
  i = 1;
  goto <D.24314>;
  <D.24313>:
  D.24415 = cfg->bblocks;
  i.6 = (unsigned int) i;
  D.24417 = i.6 * 4;
  D.24418 = D.24415 + D.24417;
  bb = *D.24418;
  if (h == 0B) goto <D.24419>; else goto <D.24421>;
  <D.24421>:
  D.24422 = h->loop_blocks;
  D.24423 = monoeg_g_list_find (D.24422, bb);
  if (D.24423 != 0B) goto <D.24424>; else goto <D.24420>;
  <D.24424>:
  if (bb != h) goto <D.24419>; else goto <D.24420>;
  <D.24419>:
  D.24425 = bb->nesting;
  D.24426 = (int) D.24425;
  if (D.24426 == level) goto <D.24427>; else goto <D.24428>;
  <D.24427>:
  D.24429 = bb->idom;
  D.24430 = D.24429->block_num;
  D.24431 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.24430, D.24431);
  <D.24428>:
  D.24425 = bb->nesting;
  D.24426 = (int) D.24425;
  D.24432 = level + 1;
  if (D.24426 == D.24432) goto <D.24433>; else goto <D.24434>;
  <D.24433>:
  D.24435 = bb->loop_blocks;
  if (D.24435 != 0B) goto <D.24436>; else goto <D.24437>;
  <D.24436>:
  D.24429 = bb->idom;
  D.24430 = D.24429->block_num;
  D.24431 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.24430, D.24431);
  dtree_emit_one_loop_level (cfg, fp, bb);
  <D.24437>:
  <D.24434>:
  <D.24420>:
  i = i + 1;
  <D.24314>:
  i.7 = (unsigned int) i;
  D.24439 = cfg->num_bblocks;
  if (i.7 < D.24439) goto <D.24313>; else goto <D.24315>;
  <D.24315>:
  if (h != 0B) goto <D.24440>; else goto <D.24441>;
  <D.24440>:
  fprintf (fp, "}\n");
  <D.24441>:
}


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

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


mono_draw_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.24444;
  const char * D.24445;
  char * D.24446;
  char * D.24447;

  D.24444 = cfg->method;
  D.24445 = D.24444->name;
  D.24446 = convert_name (D.24445);
  fprintf (fp, "digraph %s {\n", D.24446);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.24444 = cfg->method;
  D.24447 = mono_method_full_name (D.24444, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.24447);
  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.24450;
  int D.24451;
  struct MonoBasicBlock * D.24452;
  unsigned int D.24453;
  unsigned int D.24456;
  int D.24457;
  struct GList * D.24461;
  struct GList * D.24462;
  signed char D.24464;
  int D.24465;
  struct MonoBasicBlock * * D.24468;
  unsigned int j.8;
  unsigned int D.24470;
  struct MonoBasicBlock * * D.24471;
  struct MonoBasicBlock * D.24472;
  int D.24473;
  short int D.24474;
  int D.24475;
  int D.24476;
  struct GList * D.24479;
  struct MonoBasicBlock * bb;
  int j;
  int level;

  level = 0;
  if (h != 0B) goto <D.24448>; else goto <D.24449>;
  <D.24448>:
  D.24450 = h->nesting;
  level = (int) D.24450;
  D.24451 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.24451);
  D.24451 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.24451);
  <D.24449>:
  D.24452 = cfg->bb_entry;
  bb = D.24452->next_bb;
  goto <D.24337>;
  <D.24336>:
  D.24453 = bb->region;
  if (D.24453 != 4294967295) goto <D.24454>; else goto <D.24455>;
  <D.24454>:
  D.24453 = bb->region;
  D.24456 = D.24453 & 240;
  switch (D.24456) <default: <D.24329>, case 16: <D.24326>, case 32: <D.24324>, case 64: <D.24327>, case 128: <D.24328>>
  <D.24324>:
  D.24457 = bb->block_num;
  fprintf (fp, "BB%d [color=blue];\n", D.24457);
  goto <D.24325>;
  <D.24326>:
  D.24457 = bb->block_num;
  fprintf (fp, "BB%d [color=green];\n", D.24457);
  goto <D.24325>;
  <D.24327>:
  <D.24328>:
  D.24457 = bb->block_num;
  fprintf (fp, "BB%d [color=yellow];\n", D.24457);
  goto <D.24325>;
  <D.24329>:
  goto <D.24325>;
  <D.24325>:
  <D.24455>:
  if (h == 0B) goto <D.24458>; else goto <D.24460>;
  <D.24460>:
  D.24461 = h->loop_blocks;
  D.24462 = monoeg_g_list_find (D.24461, bb);
  if (D.24462 != 0B) goto <D.24463>; else goto <D.24459>;
  <D.24463>:
  if (bb != h) goto <D.24458>; else goto <D.24459>;
  <D.24458>:
  D.24464 = bb->nesting;
  D.24465 = (int) D.24464;
  if (D.24465 == level) goto <D.24466>; else goto <D.24467>;
  <D.24466>:
  j = 0;
  goto <D.24331>;
  <D.24330>:
  D.24468 = bb->in_bb;
  j.8 = (unsigned int) j;
  D.24470 = j.8 * 4;
  D.24471 = D.24468 + D.24470;
  D.24472 = *D.24471;
  D.24473 = D.24472->block_num;
  D.24457 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.24473, D.24457);
  j = j + 1;
  <D.24331>:
  D.24474 = bb->in_count;
  D.24475 = (int) D.24474;
  if (D.24475 > j) goto <D.24330>; else goto <D.24332>;
  <D.24332>:
  <D.24467>:
  D.24464 = bb->nesting;
  D.24465 = (int) D.24464;
  D.24476 = level + 1;
  if (D.24465 == D.24476) goto <D.24477>; else goto <D.24478>;
  <D.24477>:
  D.24479 = bb->loop_blocks;
  if (D.24479 != 0B) goto <D.24480>; else goto <D.24481>;
  <D.24480>:
  j = 0;
  goto <D.24334>;
  <D.24333>:
  D.24468 = bb->in_bb;
  j.8 = (unsigned int) j;
  D.24470 = j.8 * 4;
  D.24471 = D.24468 + D.24470;
  D.24472 = *D.24471;
  D.24473 = D.24472->block_num;
  D.24457 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.24473, D.24457);
  j = j + 1;
  <D.24334>:
  D.24474 = bb->in_count;
  D.24475 = (int) D.24474;
  if (D.24475 > j) goto <D.24333>; else goto <D.24335>;
  <D.24335>:
  cfg_emit_one_loop_level (cfg, fp, bb);
  <D.24481>:
  <D.24478>:
  <D.24459>:
  bb = bb->next_bb;
  <D.24337>:
  if (bb != 0B) goto <D.24336>; else goto <D.24338>;
  <D.24338>:
  if (h != 0B) goto <D.24482>; else goto <D.24483>;
  <D.24482>:
  fprintf (fp, "}\n");
  <D.24483>:
}


mono_draw_code_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.24485;
  const char * D.24486;
  char * D.24487;
  char * D.24488;
  struct MonoBasicBlock * D.24489;
  struct MonoBasicBlock * D.24490;
  unsigned int D.24495;
  unsigned int D.24496;
  unsigned int D.24498;
  unsigned int D.24499;
  int D.24501;
  struct MonoBasicBlock * bb;

  D.24485 = cfg->method;
  D.24486 = D.24485->name;
  D.24487 = convert_name (D.24486);
  fprintf (fp, "digraph %s {\n", D.24487);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.24485 = cfg->method;
  D.24488 = mono_method_full_name (D.24485, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.24488);
  fprintf (fp, "BB0 [shape=doublecircle];\n");
  fprintf (fp, "BB1 [color=red];\n");
  D.24489 = cfg->bb_entry;
  bb = D.24489->next_bb;
  goto <D.24359>;
  <D.24358>:
  {
    struct MonoInst * inst;
    const char * color;

    D.24490 = cfg->bb_exit;
    if (D.24490 == bb) goto <D.24491>; else goto <D.24492>;
    <D.24491>:
    // predicted unlikely by continue predictor.
    goto <D.24354>;
    <D.24492>:
    D.24495 = cfg->comp_done;
    D.24496 = D.24495 & 128;
    if (D.24496 != 0) goto <D.24497>; else goto <D.24493>;
    <D.24497>:
    D.24498 = bb->flags;
    D.24499 = D.24498 & 2;
    if (D.24499 != 0) goto <D.24500>; else goto <D.24493>;
    <D.24500>:
    color = "color=red,";
    goto <D.24494>;
    <D.24493>:
    color = "";
    <D.24494>:
    D.24501 = bb->block_num;
    D.24501 = bb->block_num;
    fprintf (fp, "BB%d [%sshape=record,labeljust=l,label=\"{BB%d|", D.24501, color, D.24501);
    inst = bb->code;
    goto <D.24356>;
    <D.24355>:
    fprintf (fp, "\\n");
    inst = inst->next;
    <D.24356>:
    if (inst != 0B) goto <D.24355>; else goto <D.24357>;
    <D.24357>:
    fprintf (fp, "}\"];\n");
  }
  <D.24354>:
  bb = bb->next_bb;
  <D.24359>:
  if (bb != 0B) goto <D.24358>; else goto <D.24360>;
  <D.24360>:
  cfg_emit_one_loop_level (cfg, fp, 0B);
  fprintf (fp, "}\n");
}


