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

  fn = "/tmp/minidtree.graph";
  fp = fopen (fn, "w+");
  D.21864 = fp == 0B;
  D.21865 = (long int) D.21864;
  D.21866 = __builtin_expect (D.21865, 0);
  if (D.21866 != 0) goto <D.21867>; else goto <D.21868>;
  <D.21867>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 321, "fp");
  <D.21868>:
  switch (draw_options) <default: <D.21869>, case 1: <D.21859>, case 2: <D.21857>, case 4: <D.21860>, case 8: <D.21862>, case 16: <D.21861>>
  <D.21857>:
  mono_draw_dtree (cfg, fp);
  goto <D.21858>;
  <D.21859>:
  mono_draw_cfg (cfg, fp);
  goto <D.21858>;
  <D.21860>:
  <D.21861>:
  <D.21862>:
  mono_draw_code_cfg (cfg, fp);
  goto <D.21858>;
  <D.21869>:
  <D.21858>:
  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.21870;
  unsigned int D.21871;
  _Bool D.21872;
  long int D.21873;
  long int D.21874;
  struct MonoMethod * D.21877;
  const char * D.21878;
  char * D.21879;
  char * D.21880;

  D.21870 = cfg->comp_done;
  D.21871 = D.21870 & 2;
  D.21872 = D.21871 == 0;
  D.21873 = (long int) D.21872;
  D.21874 = __builtin_expect (D.21873, 0);
  if (D.21874 != 0) goto <D.21875>; else goto <D.21876>;
  <D.21875>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "graph.c", 128, "(cfg->comp_done & MONO_COMP_IDOM)");
  <D.21876>:
  D.21877 = cfg->method;
  D.21878 = D.21877->name;
  D.21879 = convert_name (D.21878);
  fprintf (fp, "digraph %s {\n", D.21879);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.21877 = cfg->method;
  D.21880 = mono_method_full_name (D.21877, 1);
  fprintf (fp, "label=\"Dominator tree for %s\";\n", D.21880);
  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.21881;
  int D.21882;
  unsigned int D.21883;
  sizetype i.0;
  const char * D.21885;
  int D.21886;
  int j.1;
  sizetype j.2;
  char * D.21889;
  int j.3;
  sizetype j.4;
  char * D.21892;
  sizetype j.5;
  char * D.21894;
  char * D.21895;
  int i;
  int j;
  int len;
  char * res;

  D.21881 = strlen (str);
  len = (int) D.21881;
  D.21882 = len * 2;
  D.21883 = (unsigned int) D.21882;
  res = monoeg_malloc (D.21883);
  j = 0;
  i = 0;
  goto <D.21791>;
  <D.21790>:
  {
    char c;

    i.0 = (sizetype) i;
    D.21885 = str + i.0;
    c = *D.21885;
    D.21886 = (int) c;
    switch (D.21886) <default: <D.21789>, case 46: <D.21787>>
    <D.21787>:
    j.1 = j;
    j = j.1 + 1;
    j.2 = (sizetype) j.1;
    D.21889 = res + j.2;
    *D.21889 = 95;
    goto <D.21788>;
    <D.21789>:
    j.3 = j;
    j = j.3 + 1;
    j.4 = (sizetype) j.3;
    D.21892 = res + j.4;
    *D.21892 = c;
    <D.21788>:
  }
  i = i + 1;
  <D.21791>:
  if (i < len) goto <D.21790>; else goto <D.21792>;
  <D.21792>:
  j.5 = (sizetype) j;
  D.21894 = res + j.5;
  *D.21894 = 0;
  D.21895 = res;
  return D.21895;
}


dtree_emit_one_loop_level (struct MonoCompile * cfg, struct FILE * fp, struct MonoBasicBlock * h)
{
  signed char D.21899;
  int D.21900;
  struct MonoBasicBlock * * D.21901;
  unsigned int i.6;
  unsigned int D.21903;
  struct MonoBasicBlock * * D.21904;
  struct GList * D.21908;
  struct GList * D.21909;
  signed char D.21911;
  int D.21912;
  int D.21915;
  struct MonoBasicBlock * D.21916;
  int D.21917;
  int D.21918;
  struct GList * D.21921;
  unsigned int i.7;
  unsigned int D.21925;
  struct MonoBasicBlock * bb;
  int i;
  int level;

  level = 0;
  if (h != 0B) goto <D.21897>; else goto <D.21898>;
  <D.21897>:
  D.21899 = h->nesting;
  level = (int) D.21899;
  D.21900 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.21900);
  D.21900 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.21900);
  <D.21898>:
  i = 1;
  goto <D.21802>;
  <D.21801>:
  D.21901 = cfg->bblocks;
  i.6 = (unsigned int) i;
  D.21903 = i.6 * 4;
  D.21904 = D.21901 + D.21903;
  bb = *D.21904;
  if (h == 0B) goto <D.21905>; else goto <D.21907>;
  <D.21907>:
  D.21908 = h->loop_blocks;
  D.21909 = monoeg_g_list_find (D.21908, bb);
  if (D.21909 != 0B) goto <D.21910>; else goto <D.21906>;
  <D.21910>:
  if (bb != h) goto <D.21905>; else goto <D.21906>;
  <D.21905>:
  D.21911 = bb->nesting;
  D.21912 = (int) D.21911;
  if (D.21912 == level) goto <D.21913>; else goto <D.21914>;
  <D.21913>:
  D.21915 = bb->block_num;
  D.21916 = bb->idom;
  D.21917 = D.21916->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21917, D.21915);
  <D.21914>:
  D.21911 = bb->nesting;
  D.21912 = (int) D.21911;
  D.21918 = level + 1;
  if (D.21912 == D.21918) goto <D.21919>; else goto <D.21920>;
  <D.21919>:
  D.21921 = bb->loop_blocks;
  if (D.21921 != 0B) goto <D.21922>; else goto <D.21923>;
  <D.21922>:
  D.21915 = bb->block_num;
  D.21916 = bb->idom;
  D.21917 = D.21916->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21917, D.21915);
  dtree_emit_one_loop_level (cfg, fp, bb);
  <D.21923>:
  <D.21920>:
  <D.21906>:
  i = i + 1;
  <D.21802>:
  i.7 = (unsigned int) i;
  D.21925 = cfg->num_bblocks;
  if (i.7 < D.21925) goto <D.21801>; else goto <D.21803>;
  <D.21803>:
  if (h != 0B) goto <D.21926>; else goto <D.21927>;
  <D.21926>:
  fprintf (fp, "}\n");
  <D.21927>:
}


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

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


mono_draw_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.21930;
  const char * D.21931;
  char * D.21932;
  char * D.21933;

  D.21930 = cfg->method;
  D.21931 = D.21930->name;
  D.21932 = convert_name (D.21931);
  fprintf (fp, "digraph %s {\n", D.21932);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.21930 = cfg->method;
  D.21933 = mono_method_full_name (D.21930, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.21933);
  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.21936;
  int D.21937;
  struct MonoBasicBlock * D.21938;
  unsigned int D.21939;
  unsigned int D.21942;
  int D.21943;
  struct GList * D.21947;
  struct GList * D.21948;
  signed char D.21950;
  int D.21951;
  struct MonoBasicBlock * * D.21954;
  unsigned int j.8;
  unsigned int D.21956;
  struct MonoBasicBlock * * D.21957;
  struct MonoBasicBlock * D.21958;
  int D.21959;
  short int D.21960;
  int D.21961;
  int D.21962;
  struct GList * D.21965;
  struct MonoBasicBlock * bb;
  int j;
  int level;

  level = 0;
  if (h != 0B) goto <D.21934>; else goto <D.21935>;
  <D.21934>:
  D.21936 = h->nesting;
  level = (int) D.21936;
  D.21937 = h->block_num;
  fprintf (fp, "subgraph cluster_%d {\n", D.21937);
  D.21937 = h->block_num;
  fprintf (fp, "label=\"loop_%d\"\n", D.21937);
  <D.21935>:
  D.21938 = cfg->bb_entry;
  bb = D.21938->next_bb;
  goto <D.21825>;
  <D.21824>:
  D.21939 = bb->region;
  if (D.21939 != 4294967295) goto <D.21940>; else goto <D.21941>;
  <D.21940>:
  D.21939 = bb->region;
  D.21942 = D.21939 & 240;
  switch (D.21942) <default: <D.21817>, case 16: <D.21814>, case 32: <D.21812>, case 64: <D.21815>, case 128: <D.21816>>
  <D.21812>:
  D.21943 = bb->block_num;
  fprintf (fp, "BB%d [color=blue];\n", D.21943);
  goto <D.21813>;
  <D.21814>:
  D.21943 = bb->block_num;
  fprintf (fp, "BB%d [color=green];\n", D.21943);
  goto <D.21813>;
  <D.21815>:
  <D.21816>:
  D.21943 = bb->block_num;
  fprintf (fp, "BB%d [color=yellow];\n", D.21943);
  goto <D.21813>;
  <D.21817>:
  goto <D.21813>;
  <D.21813>:
  <D.21941>:
  if (h == 0B) goto <D.21944>; else goto <D.21946>;
  <D.21946>:
  D.21947 = h->loop_blocks;
  D.21948 = monoeg_g_list_find (D.21947, bb);
  if (D.21948 != 0B) goto <D.21949>; else goto <D.21945>;
  <D.21949>:
  if (bb != h) goto <D.21944>; else goto <D.21945>;
  <D.21944>:
  D.21950 = bb->nesting;
  D.21951 = (int) D.21950;
  if (D.21951 == level) goto <D.21952>; else goto <D.21953>;
  <D.21952>:
  j = 0;
  goto <D.21819>;
  <D.21818>:
  D.21943 = bb->block_num;
  D.21954 = bb->in_bb;
  j.8 = (unsigned int) j;
  D.21956 = j.8 * 4;
  D.21957 = D.21954 + D.21956;
  D.21958 = *D.21957;
  D.21959 = D.21958->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21959, D.21943);
  j = j + 1;
  <D.21819>:
  D.21960 = bb->in_count;
  D.21961 = (int) D.21960;
  if (D.21961 > j) goto <D.21818>; else goto <D.21820>;
  <D.21820>:
  <D.21953>:
  D.21950 = bb->nesting;
  D.21951 = (int) D.21950;
  D.21962 = level + 1;
  if (D.21951 == D.21962) goto <D.21963>; else goto <D.21964>;
  <D.21963>:
  D.21965 = bb->loop_blocks;
  if (D.21965 != 0B) goto <D.21966>; else goto <D.21967>;
  <D.21966>:
  j = 0;
  goto <D.21822>;
  <D.21821>:
  D.21943 = bb->block_num;
  D.21954 = bb->in_bb;
  j.8 = (unsigned int) j;
  D.21956 = j.8 * 4;
  D.21957 = D.21954 + D.21956;
  D.21958 = *D.21957;
  D.21959 = D.21958->block_num;
  fprintf (fp, "BB%d -> BB%d;\n", D.21959, D.21943);
  j = j + 1;
  <D.21822>:
  D.21960 = bb->in_count;
  D.21961 = (int) D.21960;
  if (D.21961 > j) goto <D.21821>; else goto <D.21823>;
  <D.21823>:
  cfg_emit_one_loop_level (cfg, fp, bb);
  <D.21967>:
  <D.21964>:
  <D.21945>:
  bb = bb->next_bb;
  <D.21825>:
  if (bb != 0B) goto <D.21824>; else goto <D.21826>;
  <D.21826>:
  if (h != 0B) goto <D.21968>; else goto <D.21969>;
  <D.21968>:
  fprintf (fp, "}\n");
  <D.21969>:
}


mono_draw_code_cfg (struct MonoCompile * cfg, struct FILE * fp)
{
  struct MonoMethod * D.21971;
  const char * D.21972;
  char * D.21973;
  char * D.21974;
  struct MonoBasicBlock * D.21975;
  struct MonoBasicBlock * D.21976;
  unsigned int D.21981;
  unsigned int D.21982;
  unsigned int D.21984;
  unsigned int D.21985;
  int D.21987;
  struct MonoBasicBlock * bb;

  D.21971 = cfg->method;
  D.21972 = D.21971->name;
  D.21973 = convert_name (D.21972);
  fprintf (fp, "digraph %s {\n", D.21973);
  fprintf (fp, "node [fontsize=12.0]\nedge [len=1,color=red]\n");
  D.21971 = cfg->method;
  D.21974 = mono_method_full_name (D.21971, 1);
  fprintf (fp, "label=\"CFG for %s\";\n", D.21974);
  fprintf (fp, "BB0 [shape=doublecircle];\n");
  fprintf (fp, "BB1 [color=red];\n");
  D.21975 = cfg->bb_entry;
  bb = D.21975->next_bb;
  goto <D.21847>;
  <D.21846>:
  {
    struct MonoInst * inst;
    const char * color;

    D.21976 = cfg->bb_exit;
    if (D.21976 == bb) goto <D.21977>; else goto <D.21978>;
    <D.21977>:
    // predicted unlikely by continue predictor.
    goto <D.21842>;
    <D.21978>:
    D.21981 = cfg->comp_done;
    D.21982 = D.21981 & 128;
    if (D.21982 != 0) goto <D.21983>; else goto <D.21979>;
    <D.21983>:
    D.21984 = bb->flags;
    D.21985 = D.21984 & 2;
    if (D.21985 != 0) goto <D.21986>; else goto <D.21979>;
    <D.21986>:
    color = "color=red,";
    goto <D.21980>;
    <D.21979>:
    color = "";
    <D.21980>:
    D.21987 = bb->block_num;
    D.21987 = bb->block_num;
    fprintf (fp, "BB%d [%sshape=record,labeljust=l,label=\"{BB%d|", D.21987, color, D.21987);
    inst = bb->code;
    goto <D.21844>;
    <D.21843>:
    fprintf (fp, "\\n");
    inst = inst->next;
    <D.21844>:
    if (inst != 0B) goto <D.21843>; else goto <D.21845>;
    <D.21845>:
    fprintf (fp, "}\"];\n");
  }
  <D.21842>:
  bb = bb->next_bb;
  <D.21847>:
  if (bb != 0B) goto <D.21846>; else goto <D.21848>;
  <D.21848>:
  cfg_emit_one_loop_level (cfg, fp, 0B);
  fprintf (fp, "}\n");
}


