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

  fn = "/tmp/minidtree.graph";
  fp = fopen (fn, "w+");
  D.22302 = fp == 0B;
  D.22303 = (long int) D.22302;
  D.22304 = __builtin_expect (D.22303, 0);
  if (D.22304 != 0) goto <D.22305>; else goto <D.22306>;
  <D.22305>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 321, "fp");
  <D.22306>:
  switch (draw_options) <default: <D.22307>, case 1: <D.22297>, case 2: <D.22295>, case 4: <D.22298>, case 8: <D.22300>, case 16: <D.22299>>
  <D.22295>:
  mono_draw_dtree (cfg, fp);
  goto <D.22296>;
  <D.22297>:
  mono_draw_cfg (cfg, fp);
  goto <D.22296>;
  <D.22298>:
  <D.22299>:
  <D.22300>:
  mono_draw_code_cfg (cfg, fp);
  goto <D.22296>;
  <D.22307>:
  <D.22296>:
  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.22308;
  unsigned int D.22309;
  _Bool D.22310;
  long int D.22311;
  long int D.22312;
  struct MonoMethod * D.22315;
  const char * D.22316;
  char * D.22317;
  char * D.22318;

  D.22308 = cfg->comp_done;
  D.22309 = D.22308 & 2;
  D.22310 = D.22309 == 0;
  D.22311 = (long int) D.22310;
  D.22312 = __builtin_expect (D.22311, 0);
  if (D.22312 != 0) goto <D.22313>; else goto <D.22314>;
  <D.22313>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 128, "(cfg->comp_done & MONO_COMP_IDOM)");
  <D.22314>:
  D.22315 = cfg->method;
  D.22316 = D.22315->name;
  D.22317 = convert_name (D.22316);
  fprintf (fp, "digraph %s {\n", D.22317);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.22315 = cfg->method;
  D.22318 = mono_method_full_name (D.22315, 1);
  fprintf (fp, "label=\"Dominator tree for %s\";\n", D.22318);
  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.22319;
  int D.22320;
  long unsigned int D.22321;
  sizetype D.22322;
  const char * D.22323;
  int D.22324;
  int j.0;
  sizetype D.22326;
  char * D.22327;
  int j.1;
  sizetype D.22329;
  char * D.22330;
  sizetype D.22331;
  char * D.22332;
  char * D.22333;
  int i;
  int j;
  int len;
  char * res;

  D.22319 = strlen (str);
  len = (int) D.22319;
  D.22320 = len * 2;
  D.22321 = (long unsigned int) D.22320;
  res = monoeg_malloc (D.22321);
  j = 0;
  i = 0;
  goto <D.22229>;
  <D.22228>:
  {
    char c;

    D.22322 = (sizetype) i;
    D.22323 = str + D.22322;
    c = *D.22323;
    D.22324 = (int) c;
    switch (D.22324) <default: <D.22227>, case 46: <D.22225>>
    <D.22225>:
    j.0 = j;
    j = j.0 + 1;
    D.22326 = (sizetype) j.0;
    D.22327 = res + D.22326;
    *D.22327 = 95;
    goto <D.22226>;
    <D.22227>:
    j.1 = j;
    j = j.1 + 1;
    D.22329 = (sizetype) j.1;
    D.22330 = res + D.22329;
    *D.22330 = c;
    <D.22226>:
  }
  i = i + 1;
  <D.22229>:
  if (i < len) goto <D.22228>; else goto <D.22230>;
  <D.22230>:
  D.22331 = (sizetype) j;
  D.22332 = res + D.22331;
  *D.22332 = 0;
  D.22333 = res;
  return D.22333;
}


dtree_emit_one_loop_level (struct MonoCompile * cfg, struct FILE * fp, struct MonoBasicBlock * h)
{
  signed char D.22337;
  int D.22338;
  struct MonoBasicBlock * * D.22339;
  long unsigned int D.22340;
  long unsigned int D.22341;
  struct MonoBasicBlock * * D.22342;
  struct GList * D.22346;
  struct GList * D.22347;
  signed char D.22349;
  int D.22350;
  int D.22353;
  struct MonoBasicBlock * D.22354;
  int D.22355;
  int D.22356;
  struct GList * D.22359;
  unsigned int i.2;
  unsigned int D.22363;
  struct MonoBasicBlock * bb;
  int i;
  int level;

  level = 0;
  if (h != 0B) goto <D.22335>; else goto <D.22336>;
  <D.22335>:
  D.22337 = h->nesting;
  level = (int) D.22337;
  D.22338 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.22338);
  D.22338 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.22338);
  <D.22336>:
  i = 1;
  goto <D.22240>;
  <D.22239>:
  D.22339 = cfg->bblocks;
  D.22340 = (long unsigned int) i;
  D.22341 = D.22340 * 8;
  D.22342 = D.22339 + D.22341;
  bb = *D.22342;
  if (h == 0B) goto <D.22343>; else goto <D.22345>;
  <D.22345>:
  D.22346 = h->loop_blocks;
  D.22347 = monoeg_g_list_find (D.22346, bb);
  if (D.22347 != 0B) goto <D.22348>; else goto <D.22344>;
  <D.22348>:
  if (bb != h) goto <D.22343>; else goto <D.22344>;
  <D.22343>:
  D.22349 = bb->nesting;
  D.22350 = (int) D.22349;
  if (D.22350 == level) goto <D.22351>; else goto <D.22352>;
  <D.22351>:
  D.22353 = bb->block_num;
  D.22354 = bb->idom;
  D.22355 = D.22354->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22355, D.22353);
  <D.22352>:
  D.22349 = bb->nesting;
  D.22350 = (int) D.22349;
  D.22356 = level + 1;
  if (D.22350 == D.22356) goto <D.22357>; else goto <D.22358>;
  <D.22357>:
  D.22359 = bb->loop_blocks;
  if (D.22359 != 0B) goto <D.22360>; else goto <D.22361>;
  <D.22360>:
  D.22353 = bb->block_num;
  D.22354 = bb->idom;
  D.22355 = D.22354->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22355, D.22353);
  dtree_emit_one_loop_level (cfg, fp, bb);
  <D.22361>:
  <D.22358>:
  <D.22344>:
  i = i + 1;
  <D.22240>:
  i.2 = (unsigned int) i;
  D.22363 = cfg->num_bblocks;
  if (i.2 < D.22363) goto <D.22239>; else goto <D.22241>;
  <D.22241>:
  if (h != 0B) goto <D.22364>; else goto <D.22365>;
  <D.22364>:
  fprintf (fp, "}\n");
  <D.22365>:
}


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

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


mono_draw_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.22368;
  const char * D.22369;
  char * D.22370;
  char * D.22371;

  D.22368 = cfg->method;
  D.22369 = D.22368->name;
  D.22370 = convert_name (D.22369);
  fprintf (fp, "digraph %s {\n", D.22370);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.22368 = cfg->method;
  D.22371 = mono_method_full_name (D.22368, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.22371);
  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.22374;
  int D.22375;
  struct MonoBasicBlock * D.22376;
  unsigned int D.22377;
  unsigned int D.22380;
  int D.22381;
  struct GList * D.22385;
  struct GList * D.22386;
  signed char D.22388;
  int D.22389;
  struct MonoBasicBlock * * D.22392;
  long unsigned int D.22393;
  long unsigned int D.22394;
  struct MonoBasicBlock * * D.22395;
  struct MonoBasicBlock * D.22396;
  int D.22397;
  short int D.22398;
  int D.22399;
  int D.22400;
  struct GList * D.22403;
  struct MonoBasicBlock * bb;
  int j;
  int level;

  level = 0;
  if (h != 0B) goto <D.22372>; else goto <D.22373>;
  <D.22372>:
  D.22374 = h->nesting;
  level = (int) D.22374;
  D.22375 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.22375);
  D.22375 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.22375);
  <D.22373>:
  D.22376 = cfg->bb_entry;
  bb = D.22376->next_bb;
  goto <D.22263>;
  <D.22262>:
  D.22377 = bb->region;
  if (D.22377 != 4294967295) goto <D.22378>; else goto <D.22379>;
  <D.22378>:
  D.22377 = bb->region;
  D.22380 = D.22377 & 240;
  switch (D.22380) <default: <D.22255>, case 16: <D.22252>, case 32: <D.22250>, case 64: <D.22253>, case 128: <D.22254>>
  <D.22250>:
  D.22381 = bb->block_num;
  fprintf (fp, "BB%d [color=blue];\n", D.22381);
  goto <D.22251>;
  <D.22252>:
  D.22381 = bb->block_num;
  fprintf (fp, "BB%d [color=green];\n", D.22381);
  goto <D.22251>;
  <D.22253>:
  <D.22254>:
  D.22381 = bb->block_num;
  fprintf (fp, "BB%d [color=yellow];\n", D.22381);
  goto <D.22251>;
  <D.22255>:
  goto <D.22251>;
  <D.22251>:
  <D.22379>:
  if (h == 0B) goto <D.22382>; else goto <D.22384>;
  <D.22384>:
  D.22385 = h->loop_blocks;
  D.22386 = monoeg_g_list_find (D.22385, bb);
  if (D.22386 != 0B) goto <D.22387>; else goto <D.22383>;
  <D.22387>:
  if (bb != h) goto <D.22382>; else goto <D.22383>;
  <D.22382>:
  D.22388 = bb->nesting;
  D.22389 = (int) D.22388;
  if (D.22389 == level) goto <D.22390>; else goto <D.22391>;
  <D.22390>:
  j = 0;
  goto <D.22257>;
  <D.22256>:
  D.22381 = bb->block_num;
  D.22392 = bb->in_bb;
  D.22393 = (long unsigned int) j;
  D.22394 = D.22393 * 8;
  D.22395 = D.22392 + D.22394;
  D.22396 = *D.22395;
  D.22397 = D.22396->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22397, D.22381);
  j = j + 1;
  <D.22257>:
  D.22398 = bb->in_count;
  D.22399 = (int) D.22398;
  if (D.22399 > j) goto <D.22256>; else goto <D.22258>;
  <D.22258>:
  <D.22391>:
  D.22388 = bb->nesting;
  D.22389 = (int) D.22388;
  D.22400 = level + 1;
  if (D.22389 == D.22400) goto <D.22401>; else goto <D.22402>;
  <D.22401>:
  D.22403 = bb->loop_blocks;
  if (D.22403 != 0B) goto <D.22404>; else goto <D.22405>;
  <D.22404>:
  j = 0;
  goto <D.22260>;
  <D.22259>:
  D.22381 = bb->block_num;
  D.22392 = bb->in_bb;
  D.22393 = (long unsigned int) j;
  D.22394 = D.22393 * 8;
  D.22395 = D.22392 + D.22394;
  D.22396 = *D.22395;
  D.22397 = D.22396->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.22397, D.22381);
  j = j + 1;
  <D.22260>:
  D.22398 = bb->in_count;
  D.22399 = (int) D.22398;
  if (D.22399 > j) goto <D.22259>; else goto <D.22261>;
  <D.22261>:
  cfg_emit_one_loop_level (cfg, fp, bb);
  <D.22405>:
  <D.22402>:
  <D.22383>:
  bb = bb->next_bb;
  <D.22263>:
  if (bb != 0B) goto <D.22262>; else goto <D.22264>;
  <D.22264>:
  if (h != 0B) goto <D.22406>; else goto <D.22407>;
  <D.22406>:
  fprintf (fp, "}\n");
  <D.22407>:
}


mono_draw_code_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.22409;
  const char * D.22410;
  char * D.22411;
  char * D.22412;
  struct MonoBasicBlock * D.22413;
  struct MonoBasicBlock * D.22414;
  unsigned int D.22419;
  unsigned int D.22420;
  unsigned int D.22422;
  unsigned int D.22423;
  int D.22425;
  struct MonoBasicBlock * bb;

  D.22409 = cfg->method;
  D.22410 = D.22409->name;
  D.22411 = convert_name (D.22410);
  fprintf (fp, "digraph %s {\n", D.22411);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.22409 = cfg->method;
  D.22412 = mono_method_full_name (D.22409, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.22412);
  fprintf (fp, "BB0 [shape=doublecircle];\n");
  fprintf (fp, "BB1 [color=red];\n");
  D.22413 = cfg->bb_entry;
  bb = D.22413->next_bb;
  goto <D.22285>;
  <D.22284>:
  {
    struct MonoInst * inst;
    const char * color;

    D.22414 = cfg->bb_exit;
    if (D.22414 == bb) goto <D.22415>; else goto <D.22416>;
    <D.22415>:
    // predicted unlikely by continue predictor.
    goto <D.22280>;
    <D.22416>:
    D.22419 = cfg->comp_done;
    D.22420 = D.22419 & 128;
    if (D.22420 != 0) goto <D.22421>; else goto <D.22417>;
    <D.22421>:
    D.22422 = bb->flags;
    D.22423 = D.22422 & 2;
    if (D.22423 != 0) goto <D.22424>; else goto <D.22417>;
    <D.22424>:
    color = "color=red,";
    goto <D.22418>;
    <D.22417>:
    color = "";
    <D.22418>:
    D.22425 = bb->block_num;
    D.22425 = bb->block_num;
    fprintf (fp, "BB%d [%sshape=record,labeljust=l,label=\"{BB%d|", D.22425, color, D.22425);
    inst = bb->code;
    goto <D.22282>;
    <D.22281>:
    fprintf (fp, "\\n");
    inst = inst->next;
    <D.22282>:
    if (inst != 0B) goto <D.22281>; else goto <D.22283>;
    <D.22283>:
    fprintf (fp, "}\"];\n");
  }
  <D.22280>:
  bb = bb->next_bb;
  <D.22285>:
  if (bb != 0B) goto <D.22284>; else goto <D.22286>;
  <D.22286>:
  cfg_emit_one_loop_level (cfg, fp, 0B);
  fprintf (fp, "}\n");
}


