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

  fn = "/tmp/minidtree.graph";
  fp = fopen (fn, "w+");
  D.22392 = fp == 0B;
  D.22393 = (long int) D.22392;
  D.22394 = __builtin_expect (D.22393, 0);
  if (D.22394 != 0) goto <D.22395>; else goto <D.22396>;
  <D.22395>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 321, "fp");
  <D.22396>:
  switch (draw_options) <default: <D.22397>, case 1: <D.22387>, case 2: <D.22385>, case 4: <D.22388>, case 8: <D.22390>, case 16: <D.22389>>
  <D.22385>:
  mono_draw_dtree (cfg, fp);
  goto <D.22386>;
  <D.22387>:
  mono_draw_cfg (cfg, fp);
  goto <D.22386>;
  <D.22388>:
  <D.22389>:
  <D.22390>:
  mono_draw_code_cfg (cfg, fp);
  goto <D.22386>;
  <D.22397>:
  <D.22386>:
  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.22398;
  unsigned int D.22399;
  _Bool D.22400;
  long int D.22401;
  long int D.22402;
  struct MonoMethod * D.22405;
  const char * D.22406;
  char * D.22407;
  char * D.22408;

  D.22398 = cfg->comp_done;
  D.22399 = D.22398 & 2;
  D.22400 = D.22399 == 0;
  D.22401 = (long int) D.22400;
  D.22402 = __builtin_expect (D.22401, 0);
  if (D.22402 != 0) goto <D.22403>; else goto <D.22404>;
  <D.22403>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 128, "(cfg->comp_done & MONO_COMP_IDOM)");
  <D.22404>:
  D.22405 = cfg->method;
  D.22406 = D.22405->name;
  D.22407 = convert_name (D.22406);
  fprintf (fp, "digraph %s {\n", D.22407);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.22405 = cfg->method;
  D.22408 = mono_method_full_name (D.22405, 1);
  fprintf (fp, "label=\"Dominator tree for %s\";\n", D.22408);
  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)
{
  long unsigned int D.22409;
  int D.22410;
  long unsigned int D.22411;
  sizetype D.22412;
  const char * D.22413;
  int D.22414;
  int j.0;
  sizetype D.22416;
  char * D.22417;
  int j.1;
  sizetype D.22419;
  char * D.22420;
  sizetype D.22421;
  char * D.22422;
  char * D.22423;
  int i;
  int j;
  int len;
  char * res;

  D.22409 = strlen (str);
  len = (int) D.22409;
  D.22410 = len * 2;
  D.22411 = (long unsigned int) D.22410;
  res = monoeg_malloc (D.22411);
  j = 0;
  i = 0;
  goto <D.22319>;
  <D.22318>:
  {
    char c;

    D.22412 = (sizetype) i;
    D.22413 = str + D.22412;
    c = *D.22413;
    D.22414 = (int) c;
    switch (D.22414) <default: <D.22317>, case 46: <D.22315>>
    <D.22315>:
    j.0 = j;
    j = j.0 + 1;
    D.22416 = (sizetype) j.0;
    D.22417 = res + D.22416;
    *D.22417 = 95;
    goto <D.22316>;
    <D.22317>:
    j.1 = j;
    j = j.1 + 1;
    D.22419 = (sizetype) j.1;
    D.22420 = res + D.22419;
    *D.22420 = c;
    <D.22316>:
  }
  i = i + 1;
  <D.22319>:
  if (i < len) goto <D.22318>; else goto <D.22320>;
  <D.22320>:
  D.22421 = (sizetype) j;
  D.22422 = res + D.22421;
  *D.22422 = 0;
  D.22423 = res;
  return D.22423;
}


dtree_emit_one_loop_level (struct MonoCompile * cfg, struct FILE * fp, struct MonoBasicBlock * h)
{
  signed char D.22427;
  int D.22428;
  struct MonoBasicBlock * * D.22429;
  long unsigned int D.22430;
  long unsigned int D.22431;
  struct MonoBasicBlock * * D.22432;
  struct GList * D.22436;
  struct GList * D.22437;
  signed char D.22439;
  int D.22440;
  struct MonoBasicBlock * D.22443;
  int D.22444;
  int D.22445;
  int D.22446;
  struct GList * D.22449;
  unsigned int i.2;
  unsigned int D.22453;
  struct MonoBasicBlock * bb;
  int i;
  int level;

  level = 0;
  if (h != 0B) goto <D.22425>; else goto <D.22426>;
  <D.22425>:
  D.22427 = h->nesting;
  level = (int) D.22427;
  D.22428 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.22428);
  D.22428 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.22428);
  <D.22426>:
  i = 1;
  goto <D.22330>;
  <D.22329>:
  D.22429 = cfg->bblocks;
  D.22430 = (long unsigned int) i;
  D.22431 = D.22430 * 8;
  D.22432 = D.22429 + D.22431;
  bb = *D.22432;
  if (h == 0B) goto <D.22433>; else goto <D.22435>;
  <D.22435>:
  D.22436 = h->loop_blocks;
  D.22437 = monoeg_g_list_find (D.22436, bb);
  if (D.22437 != 0B) goto <D.22438>; else goto <D.22434>;
  <D.22438>:
  if (bb != h) goto <D.22433>; else goto <D.22434>;
  <D.22433>:
  D.22439 = bb->nesting;
  D.22440 = (int) D.22439;
  if (D.22440 == level) goto <D.22441>; else goto <D.22442>;
  <D.22441>:
  D.22443 = bb->idom;
  D.22444 = D.22443->block_num;
  D.22445 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22444, D.22445);
  <D.22442>:
  D.22439 = bb->nesting;
  D.22440 = (int) D.22439;
  D.22446 = level + 1;
  if (D.22440 == D.22446) goto <D.22447>; else goto <D.22448>;
  <D.22447>:
  D.22449 = bb->loop_blocks;
  if (D.22449 != 0B) goto <D.22450>; else goto <D.22451>;
  <D.22450>:
  D.22443 = bb->idom;
  D.22444 = D.22443->block_num;
  D.22445 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22444, D.22445);
  dtree_emit_one_loop_level (cfg, fp, bb);
  <D.22451>:
  <D.22448>:
  <D.22434>:
  i = i + 1;
  <D.22330>:
  i.2 = (unsigned int) i;
  D.22453 = cfg->num_bblocks;
  if (i.2 < D.22453) goto <D.22329>; else goto <D.22331>;
  <D.22331>:
  if (h != 0B) goto <D.22454>; else goto <D.22455>;
  <D.22454>:
  fprintf (fp, "}\n");
  <D.22455>:
}


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

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


mono_draw_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.22458;
  const char * D.22459;
  char * D.22460;
  char * D.22461;

  D.22458 = cfg->method;
  D.22459 = D.22458->name;
  D.22460 = convert_name (D.22459);
  fprintf (fp, "digraph %s {\n", D.22460);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.22458 = cfg->method;
  D.22461 = mono_method_full_name (D.22458, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.22461);
  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.22464;
  int D.22465;
  struct MonoBasicBlock * D.22466;
  unsigned int D.22467;
  unsigned int D.22470;
  int D.22471;
  struct GList * D.22475;
  struct GList * D.22476;
  signed char D.22478;
  int D.22479;
  struct MonoBasicBlock * * D.22482;
  long unsigned int D.22483;
  long unsigned int D.22484;
  struct MonoBasicBlock * * D.22485;
  struct MonoBasicBlock * D.22486;
  int D.22487;
  short int D.22488;
  int D.22489;
  int D.22490;
  struct GList * D.22493;
  struct MonoBasicBlock * bb;
  int j;
  int level;

  level = 0;
  if (h != 0B) goto <D.22462>; else goto <D.22463>;
  <D.22462>:
  D.22464 = h->nesting;
  level = (int) D.22464;
  D.22465 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.22465);
  D.22465 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.22465);
  <D.22463>:
  D.22466 = cfg->bb_entry;
  bb = D.22466->next_bb;
  goto <D.22353>;
  <D.22352>:
  D.22467 = bb->region;
  if (D.22467 != 4294967295) goto <D.22468>; else goto <D.22469>;
  <D.22468>:
  D.22467 = bb->region;
  D.22470 = D.22467 & 240;
  switch (D.22470) <default: <D.22345>, case 16: <D.22342>, case 32: <D.22340>, case 64: <D.22343>, case 128: <D.22344>>
  <D.22340>:
  D.22471 = bb->block_num;
  fprintf (fp, "BB%d [color=blue];\n", D.22471);
  goto <D.22341>;
  <D.22342>:
  D.22471 = bb->block_num;
  fprintf (fp, "BB%d [color=green];\n", D.22471);
  goto <D.22341>;
  <D.22343>:
  <D.22344>:
  D.22471 = bb->block_num;
  fprintf (fp, "BB%d [color=yellow];\n", D.22471);
  goto <D.22341>;
  <D.22345>:
  goto <D.22341>;
  <D.22341>:
  <D.22469>:
  if (h == 0B) goto <D.22472>; else goto <D.22474>;
  <D.22474>:
  D.22475 = h->loop_blocks;
  D.22476 = monoeg_g_list_find (D.22475, bb);
  if (D.22476 != 0B) goto <D.22477>; else goto <D.22473>;
  <D.22477>:
  if (bb != h) goto <D.22472>; else goto <D.22473>;
  <D.22472>:
  D.22478 = bb->nesting;
  D.22479 = (int) D.22478;
  if (D.22479 == level) goto <D.22480>; else goto <D.22481>;
  <D.22480>:
  j = 0;
  goto <D.22347>;
  <D.22346>:
  D.22482 = bb->in_bb;
  D.22483 = (long unsigned int) j;
  D.22484 = D.22483 * 8;
  D.22485 = D.22482 + D.22484;
  D.22486 = *D.22485;
  D.22487 = D.22486->block_num;
  D.22471 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22487, D.22471);
  j = j + 1;
  <D.22347>:
  D.22488 = bb->in_count;
  D.22489 = (int) D.22488;
  if (D.22489 > j) goto <D.22346>; else goto <D.22348>;
  <D.22348>:
  <D.22481>:
  D.22478 = bb->nesting;
  D.22479 = (int) D.22478;
  D.22490 = level + 1;
  if (D.22479 == D.22490) goto <D.22491>; else goto <D.22492>;
  <D.22491>:
  D.22493 = bb->loop_blocks;
  if (D.22493 != 0B) goto <D.22494>; else goto <D.22495>;
  <D.22494>:
  j = 0;
  goto <D.22350>;
  <D.22349>:
  D.22482 = bb->in_bb;
  D.22483 = (long unsigned int) j;
  D.22484 = D.22483 * 8;
  D.22485 = D.22482 + D.22484;
  D.22486 = *D.22485;
  D.22487 = D.22486->block_num;
  D.22471 = bb->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22487, D.22471);
  j = j + 1;
  <D.22350>:
  D.22488 = bb->in_count;
  D.22489 = (int) D.22488;
  if (D.22489 > j) goto <D.22349>; else goto <D.22351>;
  <D.22351>:
  cfg_emit_one_loop_level (cfg, fp, bb);
  <D.22495>:
  <D.22492>:
  <D.22473>:
  bb = bb->next_bb;
  <D.22353>:
  if (bb != 0B) goto <D.22352>; else goto <D.22354>;
  <D.22354>:
  if (h != 0B) goto <D.22496>; else goto <D.22497>;
  <D.22496>:
  fprintf (fp, "}\n");
  <D.22497>:
}


mono_draw_code_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.22499;
  const char * D.22500;
  char * D.22501;
  char * D.22502;
  struct MonoBasicBlock * D.22503;
  struct MonoBasicBlock * D.22504;
  unsigned int D.22509;
  unsigned int D.22510;
  unsigned int D.22512;
  unsigned int D.22513;
  int D.22515;
  struct MonoBasicBlock * bb;

  D.22499 = cfg->method;
  D.22500 = D.22499->name;
  D.22501 = convert_name (D.22500);
  fprintf (fp, "digraph %s {\n", D.22501);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.22499 = cfg->method;
  D.22502 = mono_method_full_name (D.22499, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.22502);
  fprintf (fp, "BB0 [shape=doublecircle];\n");
  fprintf (fp, "BB1 [color=red];\n");
  D.22503 = cfg->bb_entry;
  bb = D.22503->next_bb;
  goto <D.22375>;
  <D.22374>:
  {
    struct MonoInst * inst;
    const char * color;

    D.22504 = cfg->bb_exit;
    if (D.22504 == bb) goto <D.22505>; else goto <D.22506>;
    <D.22505>:
    // predicted unlikely by continue predictor.
    goto <D.22370>;
    <D.22506>:
    D.22509 = cfg->comp_done;
    D.22510 = D.22509 & 128;
    if (D.22510 != 0) goto <D.22511>; else goto <D.22507>;
    <D.22511>:
    D.22512 = bb->flags;
    D.22513 = D.22512 & 2;
    if (D.22513 != 0) goto <D.22514>; else goto <D.22507>;
    <D.22514>:
    color = "color=red,";
    goto <D.22508>;
    <D.22507>:
    color = "";
    <D.22508>:
    D.22515 = bb->block_num;
    D.22515 = bb->block_num;
    fprintf (fp, "BB%d [%sshape=record,labeljust=l,label=\"{BB%d|", D.22515, color, D.22515);
    inst = bb->code;
    goto <D.22372>;
    <D.22371>:
    fprintf (fp, "\\n");
    inst = inst->next;
    <D.22372>:
    if (inst != 0B) goto <D.22371>; else goto <D.22373>;
    <D.22373>:
    fprintf (fp, "}\"];\n");
  }
  <D.22370>:
  bb = bb->next_bb;
  <D.22375>:
  if (bb != 0B) goto <D.22374>; else goto <D.22376>;
  <D.22376>:
  cfg_emit_one_loop_level (cfg, fp, 0B);
  fprintf (fp, "}\n");
}


