decompiled_code:
__int64 print_inv_nine()
{
int v0; // edx

v0 = (int)((double)rand() * 4.656612873077393e-10 * 9.0);
if ( v0 )
{
switch ( v0 )
{
case 1:
if ( puts(aTefldu) >= 0
&& puts(aTeitirV) >= 0
&& puts(aVar) >= 0
&& puts(aVant) >= 0
&& puts(aUns) >= 0
&& puts(&byte_CBE) >= 0
&& puts(&byte_CCC) >= 0 )
{
puts(&byte_CDD);
}
break;
case 2:
if ( puts(aTaflEmk) >= 0
&& puts(&byte_D06) >= 0
&& puts(aT) >= 0
&& puts(aT_0) >= 0
&& puts(aSkr) >= 0
&& puts(aSk) >= 0
&& puts(aHv) >= 0 )
{
puts(aHarpsl);
}
break;
case 3:
if ( puts("Burr var inn ellsti,") >= 0
&& puts("en Barn annat,") >= 0
&& puts(aJ) >= 0
&& puts(aArfiM) >= 0
&& puts(aNi) >= 0
&& puts(aN) >= 0
&& puts("Sonr ok Sveinn,") >= 0
&& puts("- sund ok tafl, -") >= 0
&& puts(aKundrH) >= 0 )
{
puts("Konr var inn yngsti.");
}
break;
case 4:
if ( puts(aMj) >= 0
&& puts(aR_0) >= 0
&& puts(&byte_E8D) >= 0
&& puts(asc_EA5) >= 0
&& puts(asc_EB3) >= 0
&& puts(aOkF) >= 0
&& puts(aM) >= 0 )
{
puts(aOkManiAustr);
}
break;
case 5:
if ( puts(aGestumblindiM) >= 0
&& puts(aHverjarEru) >= 0
&& puts(aErUmSinnDr) >= 0
&& puts(aV_0) >= 0
&& puts(aInarJ) >= 0
&& puts("um alla daga,") >= 0
&& puts(aEnInarFegriFr) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_10F0, stdout) >= 0 )
{
puts(aUmHnefannOkFyl);
}
break;
case 6:
if ( puts(aGestumblindiM) >= 0
&& puts(aHvatEr) >= 0
&& puts(aErDreprF) >= 0
&& puts(aOkErJ) >= 0
&& puts(aHornHefir) >= 0
&& puts(aEnH) >= 0
&& puts(aOkRennrSemRenn) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG_0) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_1150, stdout) >= 0 )
{
puts(aBj);
}
break;
case 7:
if ( fputs(aJafnanSkemmtu, stdout) >= 0
&& fputs(aGunnlaugrLag, stdout) >= 0
&& fputs(aAnnarsBr, stdout) >= 0
&& fputs(aV, stdout) >= 0
&& fputs(aHelgaVarSv, stdout) >= 0
&& fputs(aMannaAtHonHafi, stdout) >= 0
&& fputs(asc_12C0, stdout) >= 0
&& fputs(aHanaAllaOkSv, stdout) >= 0
&& fputs(aEngiKostr, stdout) >= 0 )
{
fwrite(&unk_1360, 1uLL, 0x33uLL, stdout);
}
break;
default:
if ( fputs(s, stdout) >= 0
&& fputs(aLi, stdout) >= 0
&& fputs(aEnHannSatAtTaf, stdout) >= 0
&& fputs(&byte_1440, stdout) >= 0
&& fputs(aOkVildu, stdout) >= 0
&& fputs(aHannSvaradeEng, stdout) >= 0
&& fputs(aR, stdout) >= 0 )
{
fwrite(&unk_10A1, 1uLL, 0x19uLL, stdout);
}
break;
}
}
else if ( puts(&byte_C07) >= 0
&& puts("undrsamligar") >= 0
&& puts(aGullnarT) >= 0
&& puts(&byte_C34) >= 0
&& puts(&byte_C46) >= 0 )
{
puts(&byte_C58);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx

v0 = (int)((double)rand() * 4.656612873077393e-10 * 9.0);
if ( v0 )
{
switch ( v0 )
{
case 1:
if ( puts(aTefldu) >= 0
&& puts(aTeitirV) >= 0
&& puts(aVar) >= 0
&& puts(aVant) >= 0
&& puts(aUns) >= 0
&& puts(&byte_CBE) >= 0
&& puts(&byte_CCC) >= 0 )
{
puts(&byte_CDD);
}
break;
case 2:
if ( puts(aTaflEmk) >= 0
&& puts(&byte_D06) >= 0
&& puts(aT) >= 0
&& puts(aT_0) >= 0
&& puts(aSkr) >= 0
&& puts(aSk) >= 0
&& puts(aHv) >= 0 )
{
puts(aHarpsl);
}
break;
case 3:
if ( puts("Burr var inn ellsti,") >= 0
&& puts("en Barn annat,") >= 0
&& puts(aJ) >= 0
&& puts(aArfiM) >= 0
&& puts(aNi) >= 0
&& puts(aN) >= 0
&& puts("Sonr ok Sveinn,") >= 0
&& puts("- sund ok tafl, -") >= 0
&& puts(aKundrH) >= 0 )
{
puts("Konr var inn yngsti.");
}
break;
case 4:
if ( puts(aMj) >= 0
&& puts(aR_0) >= 0
&& puts(&byte_E8D) >= 0
&& puts(asc_EA5) >= 0
&& puts(asc_EB3) >= 0
&& puts(aOkF) >= 0
&& puts(aM) >= 0 )
{
puts(aOkManiAustr);
}
break;
case 5:
if ( puts(aGestumblindiM) >= 0
&& puts(aHverjarEru) >= 0
&& puts(aErUmSinnDr) >= 0
&& puts(aV_0) >= 0
&& puts(aInarJ) >= 0
&& puts("um alla daga,") >= 0
&& puts(aEnInarFegriFr) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_10F0, stdout) >= 0 )
{
puts(aUmHnefannOkFyl);
}
break;
case 6:
if ( puts(aGestumblindiM) >= 0
&& puts(aHvatEr) >= 0
&& puts(aErDreprF) >= 0
&& puts(aOkErJ) >= 0
&& puts(aHornHefir) >= 0
&& puts(aEnH) >= 0
&& puts(aOkRennrSemRenn) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG_0) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_1150, stdout) >= 0 )
{
puts(aBj);
}
break;
case 7:
if ( fputs(aJafnanSkemmtu, stdout) >= 0
&& fputs(aGunnlaugrLag, stdout) >= 0
&& fputs(aAnnarsBr, stdout) >= 0
&& fputs(aV, stdout) >= 0
&& fputs(aHelgaVarSv, stdout) >= 0
&& fputs(aMannaAtHonHafi, stdout) >= 0
&& fputs(asc_12C0, stdout) >= 0
&& fputs(aHanaAllaOkSv, stdout) >= 0
&& fputs(aEngiKostr, stdout) >= 0 )
{
fwrite(&unk_1360, 1uLL, 0x33uLL, stdout);
}
break;
default:
if ( fputs(s, stdout) >= 0
&& fputs(aLi, stdout) >= 0
&& fputs(aEnHannSatAtTaf, stdout) >= 0
&& fputs(&byte_1440, stdout) >= 0
&& fputs(aOkVildu, stdout) >= 0
&& fputs(aHannSvaradeEng, stdout) >= 0
&& fputs(aR, stdout) >= 0 )
{
fwrite(&unk_10A1, 1uLL, 0x19uLL, stdout);
}
break;
}
}
else if ( puts(&byte_C07) >= 0
&& puts("undrsamligar") >= 0
&& puts(aGullnarT) >= 0
&& puts(&byte_C34) >= 0
&& puts(&byte_C46) >= 0 )
{
puts(&byte_C58);
}
return 0LL;
}

original_code:
static
enum HT_FR
print_inv_nine (void)
{
 int r = 0;
 int random = 1 + (int)(9.0 * (rand() / (2147483647 + 1.0)));
 if (1 == random)
 {
  r = r < 0 ? r : puts("Þar munu eftir");
  r = r < 0 ? r : puts("undrsamligar");
  r = r < 0 ? r : puts("gullnar tǫflur");
  r = r < 0 ? r : puts("í grasi finnask,");
  r = r < 0 ? r : puts("þærs í árdaga");
  r = r < 0 ? r : puts("áttar hǫfðu.");
 }
 else if (2 == random)
 {
  r = r < 0 ? r : puts("Tefldu í túni,");
  r = r < 0 ? r : puts("teitir váru,");
  r = r < 0 ? r : puts("var þeim vettergis");
  r = r < 0 ? r : puts("vant ór gulli,");
  r = r < 0 ? r : puts("uns þrjár kvámu");
  r = r < 0 ? r : puts("þursa meyjar");
  r = r < 0 ? r : puts("ámáttkar mjǫk");
  r = r < 0 ? r : puts("ór Jǫtunheimum.");
 }
 else if (3 == random)
 {
  r = r < 0 ? r : puts("Tafl emk ǫrr at efla,");
  r = r < 0 ? r : puts("íþróttir kank níu,");
  r = r < 0 ? r : puts("týnik trauðla rúnum,");
  r = r < 0 ? r : puts("tíð er bók ok smíðir,");
  r = r < 0 ? r : puts("skríða kank á skíðum,");
  r = r < 0 ? r : puts("skýtk ok rœk, svát nýtir;");
  r = r < 0 ? r : puts("hvártveggja kank hyggja:");
  r = r < 0 ? r : puts("harpslótt ok bragþóttu.");
 }
 else if (4 == random)
 {
  r = r < 0 ? r : puts("Burr var inn ellsti,");
  r = r < 0 ? r : puts("en Barn annat,");
  r = r < 0 ? r : puts("Jóð ok Aðal,");
  r = r < 0 ? r : puts("Arfi, Mǫgr,");
  r = r < 0 ? r : puts("Niðr ok Niðjungr,");
  r = r < 0 ? r : puts("- námu leika, -");
  r = r < 0 ? r : puts("Sonr ok Sveinn,");
  r = r < 0 ? r : puts("- sund ok tafl, -");
  r = r < 0 ? r : puts("Kundr hét enn,");
  r = r < 0 ? r : puts("Konr var inn yngsti.");
 }
 else if (5 == random)
 {
  r = r < 0 ? r : puts("Mjǫk eru reifðir");
  r = r < 0 ? r : puts("rógbirtingar,");
  r = r < 0 ? r : puts("þeirs í Haralds túni");
  r = r < 0 ? r : puts("húnum verpa;");
  r = r < 0 ? r : puts("féi eru þeir gœddir");
  r = r < 0 ? r : puts("ok fǫgrum mækum,");
  r = r < 0 ? r : puts("málmi húnlenzkum");
  r = r < 0 ? r : puts("ok mani austrœnu.");
 }
 else if (6 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hverjar eru þær snótir,");
  r = r < 0 ? r : puts("er um sinn dróttin");
  r = r < 0 ? r : puts("vápnlausar vega,");
  r = r < 0 ? r : puts("inar jǫrpu hlífa");
  r = r < 0 ? r : puts("um alla daga,");
  r = r < 0 ? r : puts("en inar fegri frýja?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Góð er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er hneftafl. Tǫflur drepast vápnlausar ", stdout);
  r = r < 0 ? r : puts(
   "um hnefann, ok fylgja honum inar rauðu.\"");
 }
 else if (7 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hvat er þat dýra,");
  r = r < 0 ? r : puts("er drepr fé manna");
  r = r < 0 ? r : puts("ok er járni kringt útan,");
  r = r < 0 ? r : puts("horn hefir átta,");
  r = r < 0 ? r : puts("en hǫfuð ekki");
  r = r < 0 ? r : puts("ok rennr, sem renna má?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Gód er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er húnn í hneftafli; hann heitir som ", stdout);
  r = r < 0 ? r : puts(
   "bjǫrn; hann rennr, þegar honum er kastat.\"");
 }
 else if (8 == random)
 {
  r = r < 0 ? r :
  fputs("Jafnan skemmtu þau Helga sér at tafli ok ",
   stdout);
  r = r < 0 ? r :
  fputs("Gunnlaugr. Lagði hvárt þeira góðan þokka til ",
   stdout);
  r = r < 0 ? r :
  fputs("annars bráðliga, sem raunir bar á síðan. Þau ",
   stdout);
  r = r < 0 ? r : fputs("váru mjǫk jafnaldrar.\n\n",
   stdout);
  r = r < 0 ? r :
  fputs("Helga var svá fǫgr, at þat er sǫgn fróðra ",
   stdout);
  r = r < 0 ? r :
  fputs("manna, at hon hafi fegrst kona verit á Íslandi.",
   stdout);
  r = r < 0 ? r :
  fputs(" Hár hennar var svá mikit, at þat mátti hylja ",
   stdout);
  r = r < 0 ? r :
  fputs("hana alla, ok svá fagrt sem gull barit, ok ",
   stdout);
  r = r < 0 ? r :
  fputs("engi kostr þótti þá þvílíkr sem Helga in fagra ",
   stdout);
  r = r < 0 ? r :
  fputs("í ǫllum Borgarfirði ok víðara annars staðar.\n",
   stdout);
 }
 else
 {
  r = r < 0 ? r :
  fputs("En konungs synir sǫfnuðu liði ok fengu lítit ",
   stdout);
  r = r < 0 ? r :
  fputs("lið ok sendu orð Friðþjófi ok báðu hann liðs, ",
   stdout);
  r = r < 0 ? r :
  fputs("en hann sat at tafli, er sendimenn kómu til "
   "hans.\n\n", stdout);
  r = r < 0 ? r :
  fputs("Þeir mæltu: \"Konungar várar sendu þér kvedju ",
   stdout);
  r = r < 0 ? r :
  fputs("ok vildu þiggja liðsinni þitt til orrostu með "
   "sér.\"\n\n", stdout);
  r = r < 0 ? r :
  fputs("Hann svarade engu ok mælti við Bjǫrn: \"Leita ",
   stdout);
  r = r < 0 ? r :
  fputs("ráðs fyrir at tefla, því at tvíkostr er þér á ",
   stdout);
  r = r < 0 ? r :
  fputs("tvá vega,\" sagði hann.\n", stdout);
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR print_inv_nine()
{
 int r = 0;
 int random = 1 + (int)(9.0 * (rand() / (2147483647 + 1.0)));
 if (1 == random)
 {
  r = r < 0 ? r : puts("Þar munu eftir");
  r = r < 0 ? r : puts("undrsamligar");
  r = r < 0 ? r : puts("gullnar tǫflur");
  r = r < 0 ? r : puts("í grasi finnask,");
  r = r < 0 ? r : puts("þærs í árdaga");
  r = r < 0 ? r : puts("áttar hǫfðu.");
 }
 else if (2 == random)
 {
  r = r < 0 ? r : puts("Tefldu í túni,");
  r = r < 0 ? r : puts("teitir váru,");
  r = r < 0 ? r : puts("var þeim vettergis");
  r = r < 0 ? r : puts("vant ór gulli,");
  r = r < 0 ? r : puts("uns þrjár kvámu");
  r = r < 0 ? r : puts("þursa meyjar");
  r = r < 0 ? r : puts("ámáttkar mjǫk");
  r = r < 0 ? r : puts("ór Jǫtunheimum.");
 }
 else if (3 == random)
 {
  r = r < 0 ? r : puts("Tafl emk ǫrr at efla,");
  r = r < 0 ? r : puts("íþróttir kank níu,");
  r = r < 0 ? r : puts("týnik trauðla rúnum,");
  r = r < 0 ? r : puts("tíð er bók ok smíðir,");
  r = r < 0 ? r : puts("skríða kank á skíðum,");
  r = r < 0 ? r : puts("skýtk ok rœk, svát nýtir;");
  r = r < 0 ? r : puts("hvártveggja kank hyggja:");
  r = r < 0 ? r : puts("harpslótt ok bragþóttu.");
 }
 else if (4 == random)
 {
  r = r < 0 ? r : puts("Burr var inn ellsti,");
  r = r < 0 ? r : puts("en Barn annat,");
  r = r < 0 ? r : puts("Jóð ok Aðal,");
  r = r < 0 ? r : puts("Arfi, Mǫgr,");
  r = r < 0 ? r : puts("Niðr ok Niðjungr,");
  r = r < 0 ? r : puts("- námu leika, -");
  r = r < 0 ? r : puts("Sonr ok Sveinn,");
  r = r < 0 ? r : puts("- sund ok tafl, -");
  r = r < 0 ? r : puts("Kundr hét enn,");
  r = r < 0 ? r : puts("Konr var inn yngsti.");
 }
 else if (5 == random)
 {
  r = r < 0 ? r : puts("Mjǫk eru reifðir");
  r = r < 0 ? r : puts("rógbirtingar,");
  r = r < 0 ? r : puts("þeirs í Haralds túni");
  r = r < 0 ? r : puts("húnum verpa;");
  r = r < 0 ? r : puts("féi eru þeir gœddir");
  r = r < 0 ? r : puts("ok fǫgrum mækum,");
  r = r < 0 ? r : puts("málmi húnlenzkum");
  r = r < 0 ? r : puts("ok mani austrœnu.");
 }
 else if (6 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hverjar eru þær snótir,");
  r = r < 0 ? r : puts("er um sinn dróttin");
  r = r < 0 ? r : puts("vápnlausar vega,");
  r = r < 0 ? r : puts("inar jǫrpu hlífa");
  r = r < 0 ? r : puts("um alla daga,");
  r = r < 0 ? r : puts("en inar fegri frýja?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Góð er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er hneftafl. Tǫflur drepast vápnlausar ", stdout);
  r = r < 0 ? r : puts(
   "um hnefann, ok fylgja honum inar rauðu.\"");
 }
 else if (7 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hvat er þat dýra,");
  r = r < 0 ? r : puts("er drepr fé manna");
  r = r < 0 ? r : puts("ok er járni kringt útan,");
  r = r < 0 ? r : puts("horn hefir átta,");
  r = r < 0 ? r : puts("en hǫfuð ekki");
  r = r < 0 ? r : puts("ok rennr, sem renna má?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Gód er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er húnn í hneftafli; hann heitir som ", stdout);
  r = r < 0 ? r : puts(
   "bjǫrn; hann rennr, þegar honum er kastat.\"");
 }
 else if (8 == random)
 {
  r = r < 0 ? r :
  fputs("Jafnan skemmtu þau Helga sér at tafli ok ",
   stdout);
  r = r < 0 ? r :
  fputs("Gunnlaugr. Lagði hvárt þeira góðan þokka til ",
   stdout);
  r = r < 0 ? r :
  fputs("annars bráðliga, sem raunir bar á síðan. Þau ",
   stdout);
  r = r < 0 ? r : fputs("váru mjǫk jafnaldrar.\n\n",
   stdout);
  r = r < 0 ? r :
  fputs("Helga var svá fǫgr, at þat er sǫgn fróðra ",
   stdout);
  r = r < 0 ? r :
  fputs("manna, at hon hafi fegrst kona verit á Íslandi.",
   stdout);
  r = r < 0 ? r :
  fputs(" Hár hennar var svá mikit, at þat mátti hylja ",
   stdout);
  r = r < 0 ? r :
  fputs("hana alla, ok svá fagrt sem gull barit, ok ",
   stdout);
  r = r < 0 ? r :
  fputs("engi kostr þótti þá þvílíkr sem Helga in fagra ",
   stdout);
  r = r < 0 ? r :
  fputs("í ǫllum Borgarfirði ok víðara annars staðar.\n",
   stdout);
 }
 else
 {
  r = r < 0 ? r :
  fputs("En konungs synir sǫfnuðu liði ok fengu lítit ",
   stdout);
  r = r < 0 ? r :
  fputs("lið ok sendu orð Friðþjófi ok báðu hann liðs, ",
   stdout);
  r = r < 0 ? r :
  fputs("en hann sat at tafli, er sendimenn kómu til "
   "hans.\n\n", stdout);
  r = r < 0 ? r :
  fputs("Þeir mæltu: \"Konungar várar sendu þér kvedju ",
   stdout);
  r = r < 0 ? r :
  fputs("ok vildu þiggja liðsinni þitt til orrostu með "
   "sér.\"\n\n", stdout);
  r = r < 0 ? r :
  fputs("Hann svarade engu ok mælti við Bjǫrn: \"Leita ",
   stdout);
  r = r < 0 ? r :
  fputs("ráðs fyrir at tefla, því at tvíkostr er þér á ",
   stdout);
  r = r < 0 ? r :
  fputs("tvá vega,\" sagði hann.\n", stdout);
 }
 return HT_FR_SUCCESS;
}

variable_types: r int

variable_types: random int


repo: adolg/worldots

decompiled_code:
__int64 print_inv_version()
{
__int64 result; // rax

if ( fputs(HT_PROGNAME, stdout) < 0 || fputc(9, stdout) < 0 || printf("%d\t\t%s\n", 131214LL, HT_PREPROC) < 0 )
result = 9LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

if ( fputs(HT_PROGNAME, stdout) < 0 || fputc(9, stdout) < 0 || printf("%d\t\t%s\n", 131214LL, HT_PREPROC) < 0 )
result = 9LL;
else
result = 0LL;
return result;
}

original_code:
static
enum HT_FR
print_inv_version (void)
{
 int rv;
 rv = fputs(HT_PROGNAME, stdout);
 rv = rv < 0 ? rv : fputc('\t', stdout);
 rv = rv < 0 ? rv : printf("%d\t\t%s\n", 131214, HT_PREPROC);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR print_inv_version()
{
 int rv;
 rv = fputs(HT_PROGNAME, stdout);
 rv = rv < 0 ? rv : fputc('\t', stdout);
 rv = rv < 0 ? rv : printf("%d\t\t%s\n", 131214, HT_PREPROC);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

variable_types: rv int

return_type: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }


decompiled_code:
__int64 __fastcall print_err_fail_invoc(unsigned int a1)
{
const char *v1; // rax
__int64 result; // rax

v1 = (const char *)fail_invoc_what();
if ( fprintf(stderr, "[%d:%d]: %s\n", 12LL, a1, v1) < 0 || print_errno(stderr) < 0 )
result = 9LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
const char *v1; // rax
__int64 result; // rax

v1 = (const char *)fail_invoc_what();
if ( fprintf(stderr, "[%d:%d]: %s\n", 12LL, a1, v1) < 0 || func2(stderr) < 0 )
result = 9LL;
else
result = 0LL;
return result;
}

original_code:
static
enum HT_FR
print_err_fail_invoc (
 const enum HT_FAIL_INVOC code
 )
{
 const char * msg = fail_invoc_what(code);
 int rv = fprintf(stderr, "[%d:%d]: %s\n",
   (int)HT_FR_FAIL_INVOC, (int)code, msg);
 rv = rv < 0 ? rv : print_errno(stderr);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR print_err_fail_invoc(enum HT_FAIL_INVOC code)
{
 char *msg = fail_invoc_what(code);
 int rv = fprintf(stderr, "[%d:%d]: %s\n",
   (int)HT_FR_FAIL_INVOC, (int)code, msg);
 rv = rv < 0 ? rv : print_errno(stderr);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

variable_types: enum HT_FAIL_INVOC { HT_FAIL_INVOC_NONE=0, HT_FAIL_INVOC_UNK=1, HT_FAIL_INVOC_UI_NONE=2, HT_FAIL_INVOC_UI_UNK=3, HT_FAIL_INVOC_RC_NONE=4 }

variable_types:
msg
char *

user_defined_types: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }


decompiled_code:
__int64 __fastcall print_inv(int a1)
{
if ( a1 == 1 )
return print_inv_nine();
if ( a1 == 2 )
return print_inv_version();
if ( a1 )
return 4LL;
return print_inv_help(0);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
if ( a1 == 1 )
return func0();
if ( a1 == 2 )
return func1();
if ( a1 )
return 4LL;
return func5(0);
}

original_code:
enum HT_FR
print_inv (
 const enum HT_INV_PRINT nplay_print
 )
{
 switch (nplay_print)
 {
  case HT_INV_PRINT_HELP:
   return print_inv_help(HT_FALSE);
  case HT_INV_PRINT_NINE:
   return print_inv_nine();
  case HT_INV_PRINT_VERSION:
   return print_inv_version();
  default:
   return HT_FR_FAIL_ENUM_UNK;
 }
}

canonical_original_code:
enum HT_FR print_inv(enum HT_INV_PRINT nplay_print)
{
 switch (nplay_print)
 {
  case HT_INV_PRINT_HELP:
   return print_inv_help(HT_FALSE);
  case HT_INV_PRINT_NINE:
   return print_inv_nine();
  case HT_INV_PRINT_VERSION:
   return print_inv_version();
  default:
   return HT_FR_FAIL_ENUM_UNK;
 }
}

variable_types: enum HT_INV_PRINT { HT_INV_PRINT_HELP=0, HT_INV_PRINT_NINE=1, HT_INV_PRINT_VERSION=2 }


decompiled_code:
__int64 __fastcall print_err_fr_invoc(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

if ( (unsigned int)fr_fail_invoc() )
result = print_err_fail_invoc(a2);
else
result = print_err_fr(stderr, a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

if ( (unsigned int)fr_fail_invoc() )
result = func3(a2);
else
result = func7(stderr, a1);
return result;
}

original_code:
enum HT_FR
print_err_fr_invoc (
 const enum HT_FR code,
 const enum HT_FAIL_INVOC code_inv
 )
{
 if (fr_fail_invoc(code))
 {
  return print_err_fail_invoc (code_inv);
 }
 else
 {
  return print_err_fr (stderr,code);
 }
}

canonical_original_code:
enum HT_FR print_err_fr_invoc(enum HT_FR code, enum HT_FAIL_INVOC code_inv)
{
 if (fr_fail_invoc(code))
 {
  return print_err_fail_invoc (code_inv);
 }
 else
 {
  return print_err_fr (stderr,code);
 }
}

variable_types: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }

user_defined_types: enum HT_FAIL_INVOC { HT_FAIL_INVOC_NONE=0, HT_FAIL_INVOC_UNK=1, HT_FAIL_INVOC_UI_NONE=2, HT_FAIL_INVOC_UI_UNK=3, HT_FAIL_INVOC_RC_NONE=4 }


decompiled_code:
__int64 __fastcall ht_isblank(char a1)
{
return (a1 == 9) | (unsigned __int8)(a1 == 32);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (a1 == 9) | (unsigned __int8)(a1 == 32);
}

original_code:
static
HT_BOOL
ht_isblank (
 const char ch
 )
{
 return ' ' == ch || '\t' == ch;
}

canonical_original_code:
static enum HT_BOOL_ ht_isblank(char ch)
{
 return ' ' == ch || '\t' == ch;
}

variable_types: ch char

return_type: enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 }


decompiled_code:
void __fastcall ht_line_clear(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
static
void
ht_line_clear (
 struct ht_line * const l
 )
{
 l->wordc = (size_t)0;
}

canonical_original_code:
static void ht_line_clear(struct ht_line *l)
{
 l->wordc = (unsigned long)0;
}

variable_types: struct ht_line { struct ht_str { char *chars; unsigned long capc; } *words; unsigned long wordc; unsigned long capc; } *

return_type: void

user_defined_types: struct ht_line { struct ht_str *words; unsigned long wordc; unsigned long capc; }


original_code:
static
enum HT_FR
ht_str_grow (
 struct ht_str * s,
 const size_t capc_req
 )
{
 const size_t capc_old = s->capc;
 char * chars_new;
 size_t capc_new = (size_t)((float)capc_old
  * HT_STR_MEMC_GROWF);
 if (capc_new <= capc_req)
 {
  capc_new = capc_req + 1;
 }
 chars_new = realloc(s->chars, sizeof(* s->chars) * capc_new);
 if (((void *)0) == chars_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 s->chars = chars_new;
 s->capc = capc_new;
 {
  size_t i;
  for (i = capc_old; i < capc_new; i++)
  {
   s->chars[i] = '\0';
  }
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR ht_str_grow(struct ht_str *s, unsigned long capc_req)
{
 unsigned long capc_old = s->capc;
 char *chars_new;
 unsigned long capc_new = (size_t)((float)capc_old
  * HT_STR_MEMC_GROWF);
 if (capc_new <= capc_req)
 {
  capc_new = capc_req + 1;
 }
 chars_new = realloc(s->chars, sizeof(* s->chars) * capc_new);
 if (((void *)0) == chars_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 s->chars = chars_new;
 s->capc = capc_new;
 {
  unsigned long i;
  for (i = capc_old; i < capc_new; i++)
  {
   s->chars[i] = '\0';
  }
 }
 return HT_FR_SUCCESS;
}

variable_types: struct ht_str { char *chars; unsigned long capc; } *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall ht_str_addchar(__int64 *a1, char a2, unsigned __int64 *a3)
{
__int64 result; // rax
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rdx
_BYTE *v8; // rcx
unsigned __int64 v9; // rsi
unsigned __int64 v10; // rax
__int64 v11; // rsi

result = 5LL;
v6 = *a3;
v7 = a1[1];
if ( v6 < v7 )
{
v8 = (_BYTE *)(v6 + *a1);
if ( !*v8 )
{
v9 = v6 + 1;
if ( v7 > v9 )
{
LABEL_4:
*v8 = a2;
v10 = *a3;
v11 = *a1;
++*a3;
*(_BYTE *)(v11 + v10 + 1) = 0;
return 0LL;
}
result = ht_str_grow((__int64)a1, v9);
if ( !(_DWORD)result )
{
v8 = (_BYTE *)(*a1 + *a3);
goto LABEL_4;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, char a2, unsigned __int64 *a3)
{
__int64 result; // rax
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rdx
_BYTE *v8; // rcx
unsigned __int64 v9; // rsi
unsigned __int64 v10; // rax
__int64 v11; // rsi

result = 5LL;
v6 = *a3;
v7 = a1[1];
if ( v6 < v7 )
{
v8 = (_BYTE *)(v6 + *a1);
if ( !*v8 )
{
v9 = v6 + 1;
if ( v7 > v9 )
{
LABEL_4:
*v8 = a2;
v10 = *a3;
v11 = *a1;
++*a3;
*(_BYTE *)(v11 + v10 + 1) = 0;
return 0LL;
}
result = func2((__int64)a1, v9);
if ( !(_DWORD)result )
{
v8 = (_BYTE *)(*a1 + *a3);
goto LABEL_4;
}
}
}
return result;
}

original_code:
static
enum HT_FR
ht_str_addchar (
 struct ht_str * s,
 const char ch,
 size_t * const charc
 )
{
 if (* charc >= s->capc || '\0' != s->chars[* charc])
 {
  return HT_FR_FAIL_ILL_ARG;
 }
 if (* charc + 1 >= s->capc)
 {
  const enum HT_FR fr = ht_str_grow(s, * charc + 1);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 s->chars[* charc] = ch;
 s->chars[++(* charc)] = '\0';
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR ht_str_addchar(struct ht_str *s, char ch, unsigned long *charc)
{
 if (* charc >= s->capc || '\0' != s->chars[* charc])
 {
  return HT_FR_FAIL_ILL_ARG;
 }
 if (* charc + 1 >= s->capc)
 {
  enum HT_FR fr = ht_str_grow(s, * charc + 1);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 s->chars[* charc] = ch;
 s->chars[++(* charc)] = '\0';
 return HT_FR_SUCCESS;
}

variable_types:
charc
unsigned long *

user_defined_types: struct ht_str { char *chars; unsigned long capc; }


original_code:
static
enum HT_FR
alloc_ht_str_chars (
 struct ht_line * const l,
 const size_t cap,
 const size_t it
 )
{
 size_t i = it;
 for (; i < l->capc; i++)
 {
  struct ht_str * const s = & l->words[i];
  s->capc = cap;
  s->chars = malloc(sizeof(* s->chars) * s->capc);
  if (((void *)0) == s->chars)
  {
   size_t j;
   for (j = it; j < i; j++)
   {
    free (l->words[j].chars);
    l->words[j].chars = ((void *)0);
   }
   return HT_FR_FAIL_ALLOC;
  }
  ht_str_clear(s);
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR alloc_ht_str_chars(struct ht_line *l, unsigned long cap, unsigned long it)
{
 unsigned long i = it;
 for (; i < l->capc; i++)
 {
  struct ht_str *s = & l->words[i];
  s->capc = cap;
  s->chars = malloc(sizeof(* s->chars) * s->capc);
  if (((void *)0) == s->chars)
  {
   unsigned long j;
   for (j = it; j < i; j++)
   {
    free (l->words[j].chars);
    l->words[j].chars = ((void *)0);
   }
   return HT_FR_FAIL_ALLOC;
  }
  ht_str_clear(s);
 }
 return HT_FR_SUCCESS;
}

variable_types:
cap
unsigned long

variable_types:
it
unsigned long

variable_types:
j
unsigned long


original_code:
static
enum HT_FR
ht_line_grow (
 struct ht_line * const l
 )
{
 struct ht_str * words_new;
 const size_t capc_old = l->capc;
 size_t capc_new = (size_t)((float)capc_old
  * HT_LINE_MEMC_GROWF);
 if (capc_new <= capc_old)
 {
  capc_new = capc_old + 1;
 }
 words_new = realloc(l->words, sizeof(* l->words) * capc_new);
 if (((void *)0) == words_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->words = words_new;
 l->capc = capc_new;
 return alloc_ht_str_chars(l, HT_STR_MEMC_DEF, capc_old);
}

canonical_original_code:
static enum HT_FR ht_line_grow(struct ht_line *l)
{
 struct ht_str *words_new;
 unsigned long capc_old = l->capc;
 unsigned long capc_new = (size_t)((float)capc_old
  * HT_LINE_MEMC_GROWF);
 if (capc_new <= capc_old)
 {
  capc_new = capc_old + 1;
 }
 words_new = realloc(l->words, sizeof(* l->words) * capc_new);
 if (((void *)0) == words_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->words = words_new;
 l->capc = capc_new;
 return alloc_ht_str_chars(l, HT_STR_MEMC_DEF, capc_old);
}


decompiled_code:
void __fastcall free_ht_line(void *ptr)
{
_QWORD *v2; // r8
unsigned __int64 v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v3 = 0LL;
do
{
v4 = (void *)v2[2 * v3];
if ( v4 )
{
free(v4);
v2 = *(_QWORD **)ptr;
}
++v3;
}
while ( *((_QWORD *)ptr + 2) > v3 );
}
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
_QWORD *v2; // r8
unsigned __int64 v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v3 = 0LL;
do
{
v4 = (void *)v2[2 * v3];
if ( v4 )
{
free(v4);
v2 = *(_QWORD **)ptr;
}
++v3;
}
while ( *((_QWORD *)ptr + 2) > v3 );
}
free(v2);
}
free(ptr);
}

original_code:
void
free_ht_line (
 struct ht_line * const l
 )
{
 if (((void *)0) != l->words)
 {
  size_t i;
  for (i = 0; i < l->capc; i++)
  {
   if (((void *)0) != l->words[i].chars)
   {
    free (l->words[i].chars);
   }
  }
  free (l->words);
 }
 free (l);
}

canonical_original_code:
void free_ht_line(struct ht_line *l)
{
 if (((void *)0) != l->words)
 {
  unsigned long i;
  for (i = 0; i < l->capc; i++)
  {
   if (((void *)0) != l->words[i].chars)
   {
    free (l->words[i].chars);
   }
  }
  free (l->words);
 }
 free (l);
}


decompiled_code:
_BOOL8 __fastcall ht_line_empty(__int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)(a1 + 8) == 1LL )
result = ***(_BYTE ***)a1 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)(a1 + 8) == 1LL )
result = ***(_BYTE ***)a1 == 0;
return result;
}

original_code:
HT_BOOL
ht_line_empty (
 const struct ht_line * const l
 )
{
 return (size_t)1 == l->wordc
 && strlen(l->words[0].chars) < (size_t)1 ? HT_TRUE : HT_FALSE;
}

canonical_original_code:
enum HT_BOOL_ ht_line_empty(struct ht_line *l)
{
 return (unsigned long)1 == l->wordc
 && strlen(l->words[0].chars) < (unsigned long)1 ? HT_TRUE : HT_FALSE;
}


decompiled_code:
_BOOL8 __fastcall player_index_valid(unsigned __int16 a1)
{
return HT_PLAYERS_MAX > a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int16 a1)
{
return HT_PLAYERS_MAX > a1;
}

original_code:
HT_BOOL
player_index_valid (
 const unsigned short index
 )
{
 return index < HT_PLAYERS_MAX ? HT_TRUE : HT_FALSE;
}

canonical_original_code:
enum HT_BOOL_ player_index_valid(unsigned short index)
{
 return index < HT_PLAYERS_MAX ? HT_TRUE : HT_FALSE;
}

variable_types:
index
unsigned short


decompiled_code:
__int64 __fastcall ui_action_init(__int64 a1)
{
__int64 result; // rax
__int16 v2; // dx

result = HT_PLAYER_UNINIT;
v2 = HT_AIM_DEPTHMAX_UNINIT;
*(_DWORD *)(a1 + 12) = 1;
*(_DWORD *)(a1 + 4) = 1;
*(_WORD *)(a1 + 8) = result;
*(_WORD *)a1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
__int16 v2; // dx

result = HT_PLAYER_UNINIT;
v2 = HT_AIM_DEPTHMAX_UNINIT;
*(_DWORD *)(a1 + 12) = 1;
*(_DWORD *)(a1 + 4) = 1;
*(_WORD *)(a1 + 8) = result;
*(_WORD *)a1 = v2;
return result;
}

original_code:
void
ui_action_init (
 struct ui_action * const act
 )
{
 act->type = HT_UI_ACT_UNK;
 act->info.contr.type = HT_AIT_UNK;
 act->info.contr.p_index = HT_PLAYER_UNINIT;
 act->info.contr.args.minimax.depth_max = HT_AIM_DEPTHMAX_UNINIT;
}

canonical_original_code:
void ui_action_init(struct ui_action *act)
{
 act->type = HT_UI_ACT_UNK;
 act->info.contr.type = HT_AIT_UNK;
 act->info.contr.p_index = HT_PLAYER_UNINIT;
 act->info.contr.args.minimax.depth_max = HT_AIM_DEPTHMAX_UNINIT;
}

variable_types: struct ui_action { union { struct ui_action_contr { union { struct ai_minimax_args { unsigned short depth_max; } minimax; } args; enum AITYPE { HT_AIT_NONE=0, HT_AIT_UNK=1, HT_AIT_MINIMAX=2 } type; unsigned short p_index; } contr; struct move { unsigned short pos; } mov; } info; enum HT_UI_ACTT { HT_UI_ACT_NONE=0, HT_UI_ACT_UNK=1, HT_UI_ACT_SPECIAL=2, HT_UI_ACT_CONTR=3, HT_UI_ACT_MOVE=4, HT_UI_ACT_QUIT=5 } type; } *

user_defined_types: struct ui_action { union { struct ui_action_contr contr; struct move mov; } info; enum HT_UI_ACTT type; }

user_defined_types: struct ui_action_contr { union { struct ai_minimax_args minimax; } args; enum AITYPE type; unsigned short p_index; }


decompiled_code:
__int64 ui_def()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 1LL;
}

original_code:
enum HT_UIT
ui_def (void)
{
 return HT_UIT_MSQU;
}

canonical_original_code:
enum HT_UIT ui_def()
{
 return HT_UIT_MSQU;
}

return_type: enum HT_UIT { HT_UIT_NONE=0, HT_UIT_MSQU=1 }


IsQueueEmpty

decompiled_code:
_BOOL8 IsQueueEmpty()
{
return g_queue_size == 0;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return g_queue_size == 0;
}

original_code: static int IsQueueEmpty() { return g_queue_size == 0; }

return_type: int


IsQueueFull

decompiled_code:
_BOOL8 IsQueueFull()
{
return g_queue_size == 16;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return g_queue_size == 16;
}

original_code: static int IsQueueFull() { return g_queue_size == 16; }


InitializeMessageQueue

decompiled_code:
int InitializeMessageQueue()
{
pthread_mutex_init(&g_queue_mutex, 0LL);
return pthread_cond_init(&g_queue_not_empty_cond, 0LL);
}

canonical_decompiled_code:
int func2()
{
pthread_mutex_init(&g_queue_mutex, 0LL);
return pthread_cond_init(&g_queue_not_empty_cond, 0LL);
}

original_code:
void InitializeMessageQueue() {
  pthread_mutex_init(&g_queue_mutex, ((void *)0));
  pthread_cond_init(&g_queue_not_empty_cond, ((void *)0));
}


EnqueueMessage

decompiled_code:
__int64 __fastcall EnqueueMessage(void *ptr)
{
int v1; // eax
__int64 result; // rax

pthread_mutex_lock(&g_queue_mutex);
if ( IsQueueFull() )
{
pthread_mutex_unlock(&g_queue_mutex);
free(ptr);
result = 0LL;
}
else
{
++g_queue_size;
v1 = g_queue_end;
g_queue[g_queue_end] = (__int64)ptr;
g_queue_end = (v1 + 1) % 16;
pthread_cond_signal(&g_queue_not_empty_cond);
pthread_mutex_unlock(&g_queue_mutex);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
int v1; // eax
__int64 result; // rax

pthread_mutex_lock(&g_queue_mutex);
if ( func1() )
{
pthread_mutex_unlock(&g_queue_mutex);
free(ptr);
result = 0LL;
}
else
{
++g_queue_size;
v1 = g_queue_end;
g_queue[g_queue_end] = (__int64)ptr;
g_queue_end = (v1 + 1) % 16;
pthread_cond_signal(&g_queue_not_empty_cond);
pthread_mutex_unlock(&g_queue_mutex);
result = 1LL;
}
return result;
}

original_code:
int EnqueueMessage(char* message) {
  pthread_mutex_lock(&g_queue_mutex);
  if (IsQueueFull()) {
    pthread_mutex_unlock(&g_queue_mutex);
    free(message);
    return 0;
  }
  g_queue[g_queue_end] = message;
  g_queue_end = (g_queue_end + 1) % 16;
  g_queue_size++;
  pthread_cond_signal(&g_queue_not_empty_cond);
  pthread_mutex_unlock(&g_queue_mutex);
  return 1;
}

canonical_original_code:
int EnqueueMessage(char *message) {
  pthread_mutex_lock(&g_queue_mutex);
  if (IsQueueFull()) {
    pthread_mutex_unlock(&g_queue_mutex);
    free(message);
    return 0;
  }
  g_queue[g_queue_end] = message;
  g_queue_end = (g_queue_end + 1) % 16;
  g_queue_size++;
  pthread_cond_signal(&g_queue_not_empty_cond);
  pthread_mutex_unlock(&g_queue_mutex);
  return 1;
}

variable_types:
message
char *


DequeueMessage

decompiled_code:
__int64 DequeueMessage()
{
__int64 v0; // r12

pthread_mutex_lock(&g_queue_mutex);
while ( IsQueueEmpty() )
pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
--g_queue_size;
v0 = g_queue[g_queue_start];
g_queue_start = (g_queue_start + 1) % 16;
pthread_mutex_unlock(&g_queue_mutex);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // r12

pthread_mutex_lock(&g_queue_mutex);
while ( func0() )
pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
--g_queue_size;
v0 = g_queue[g_queue_start];
g_queue_start = (g_queue_start + 1) % 16;
pthread_mutex_unlock(&g_queue_mutex);
return v0;
}

original_code:
char* DequeueMessage() {
  char* message = ((void *)0);
  pthread_mutex_lock(&g_queue_mutex);
  while (IsQueueEmpty()) {
    pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
  }
  message = g_queue[g_queue_start];
  g_queue_start = (g_queue_start + 1) % 16;
  g_queue_size--;
  pthread_mutex_unlock(&g_queue_mutex);
  return message;
}

canonical_original_code:
char *DequeueMessage() {
  char *message = ((void *)0);
  pthread_mutex_lock(&g_queue_mutex);
  while (IsQueueEmpty()) {
    pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
  }
  message = g_queue[g_queue_start];
  g_queue_start = (g_queue_start + 1) % 16;
  g_queue_size--;
  pthread_mutex_unlock(&g_queue_mutex);
  return message;
}

return_type: char *


decompiled_code:
__int64 __fastcall aiminimax_depth_max_valid(unsigned __int16 a1)
{
return (HT_AIM_DEPTHMAX_MIN <= a1) & (unsigned __int8)(a1 <= 0x3E8u);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1)
{
return (HT_AIM_DEPTHMAX_MIN <= a1) & (unsigned __int8)(a1 <= 0x3E8u);
}

original_code:
HT_BOOL
aiminimax_depth_max_valid (
 const unsigned short depth_max
 )
{
 return depth_max >= HT_AIM_DEPTHMAX_MIN
 && depth_max <= (unsigned short)1000 ? HT_TRUE : HT_FALSE;
}

canonical_original_code:
enum HT_BOOL_ aiminimax_depth_max_valid(unsigned short depth_max)
{
 return depth_max >= HT_AIM_DEPTHMAX_MIN
 && depth_max <= (unsigned short)1000 ? HT_TRUE : HT_FALSE;
}


decompiled_code:
void __fastcall free_aiminimax(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rdi
int v4; // ebx
__int64 v5; // rax
_QWORD *v6; // rdi
int v7; // ebx
__int64 v8; // rcx
__int64 v9; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (_QWORD *)*((_QWORD *)ptr + 5);
if ( v3 )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v4 = 0;
do
{
v5 = (unsigned __int16)v4++;
free_board(v3[v5]);
v3 = (_QWORD *)*((_QWORD *)ptr + 5);
}
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v4 );
}
free(v3);
}
v6 = (_QWORD *)*((_QWORD *)ptr + 4);
if ( v6 )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v7 = 0;
do
{
v8 = (unsigned __int16)v7++;
free_listm(v6[v8]);
v6 = (_QWORD *)*((_QWORD *)ptr + 4);
}
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v7 );
}
free(v6);
}
v9 = *((_QWORD *)ptr + 2);
if ( v9 )
free_listm(v9);
if ( *((_QWORD *)ptr + 3) )
free_listmh();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rdi
int v4; // ebx
__int64 v5; // rax
_QWORD *v6; // rdi
int v7; // ebx
__int64 v8; // rcx
__int64 v9; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (_QWORD *)*((_QWORD *)ptr + 5);
if ( v3 )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v4 = 0;
do
{
v5 = (unsigned __int16)v4++;
free_board(v3[v5]);
v3 = (_QWORD *)*((_QWORD *)ptr + 5);
}
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v4 );
}
free(v3);
}
v6 = (_QWORD *)*((_QWORD *)ptr + 4);
if ( v6 )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v7 = 0;
do
{
v8 = (unsigned __int16)v7++;
free_listm(v6[v8]);
v6 = (_QWORD *)*((_QWORD *)ptr + 4);
}
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v7 );
}
free(v6);
}
v9 = *((_QWORD *)ptr + 2);
if ( v9 )
free_listm(v9);
if ( *((_QWORD *)ptr + 3) )
free_listmh();
free(ptr);
}

original_code:
void
free_aiminimax (
 struct aiminimax * const aim
 )
{
 if (((void *)0) != aim->board_escval)
 {
  free (aim->board_escval);
 }
 if (((void *)0) != aim->opt_buf_board)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_board (aim->opt_buf_board[i]);
  }
  free (aim->opt_buf_board);
 }
 if (((void *)0) != aim->opt_buf_moves)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_listm (aim->opt_buf_moves[i]);
  }
  free (aim->opt_buf_moves);
 }
 if (((void *)0) != aim->opt_moves)
 {
  free_listm (aim->opt_moves);
 }
 if (((void *)0) != aim->opt_movehist)
 {
  free_listmh (aim->opt_movehist);
 }
 free(aim);
}

canonical_original_code:
void free_aiminimax(struct aiminimax *aim)
{
 if (((void *)0) != aim->board_escval)
 {
  free (aim->board_escval);
 }
 if (((void *)0) != aim->opt_buf_board)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_board (aim->opt_buf_board[i]);
  }
  free (aim->opt_buf_board);
 }
 if (((void *)0) != aim->opt_buf_moves)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_listm (aim->opt_buf_moves[i]);
  }
  free (aim->opt_buf_moves);
 }
 if (((void *)0) != aim->opt_moves)
 {
  free_listm (aim->opt_moves);
 }
 if (((void *)0) != aim->opt_movehist)
 {
  free_listmh (aim->opt_movehist);
 }
 free(aim);
}

variable_types: struct aiminimax { unsigned short p_index; unsigned short depth_max; int *board_escval; struct listm { struct move { unsigned short pos; } *elems; unsigned long elemc; unsigned long capc; } *opt_moves; struct listmh { struct moveh { enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 } irrev; unsigned short pos; } *elems; unsigned long elemc; unsigned long capc; } *opt_movehist; struct listm **opt_buf_moves; struct board { unsigned char *pieces; unsigned short turn; } **opt_buf_board; unsigned short opt_buf_len; } *

variable_types:
i
unsigned short

user_defined_types: struct aiminimax { unsigned short p_index; unsigned short depth_max; int *board_escval; struct listm *opt_moves; struct listmh *opt_movehist; struct listm **opt_buf_moves; struct board **opt_buf_board; unsigned short opt_buf_len; }

user_defined_types: struct listm { struct move *elems; unsigned long elemc; unsigned long capc; }

user_defined_types: struct listmh { struct moveh *elems; unsigned long elemc; unsigned long capc; }

user_defined_types: struct moveh { enum HT_BOOL_ irrev; unsigned short pos; }


startStdinThread

decompiled_code:
void startStdinThread()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void startStdinThread() {
}

canonical_original_code:
void startStdinThread() {
}


decompiled_code:
__int64 __fastcall listmh_grow(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v3; // rax
void *v4; // rdi
unsigned __int64 v5; // rbp
void *v6; // rax

v3 = *(_QWORD *)(a1 + 16);
v4 = *(void **)a1;
v5 = v3 + 1;
if ( v3 < a2 )
v5 = a2;
v6 = realloc(v4, 8 * v5);
if ( !v6 )
return 3LL;
*(_QWORD *)(a1 + 16) = v5;
*(_QWORD *)a1 = v6;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v3; // rax
void *v4; // rdi
unsigned __int64 v5; // rbp
void *v6; // rax

v3 = *(_QWORD *)(a1 + 16);
v4 = *(void **)a1;
v5 = v3 + 1;
if ( v3 < a2 )
v5 = a2;
v6 = realloc(v4, 8 * v5);
if ( !v6 )
return 3LL;
*(_QWORD *)(a1 + 16) = v5;
*(_QWORD *)a1 = v6;
return 0LL;
}

original_code:
static
enum HT_FR
listmh_grow (
 struct listmh * const l,
 size_t capc_new
 )
{
 struct moveh * elems_new = ((void *)0);
 if (capc_new <= l->capc)
 {
  capc_new = l->capc + 1;
 }
 elems_new = realloc(l->elems, sizeof(* l->elems) * capc_new);
 if (((void *)0) == elems_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->elems = elems_new;
 l->capc = capc_new;
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR listmh_grow(struct listmh *l, unsigned long capc_new)
{
 struct moveh *elems_new = ((void *)0);
 if (capc_new <= l->capc)
 {
  capc_new = l->capc + 1;
 }
 elems_new = realloc(l->elems, sizeof(* l->elems) * capc_new);
 if (((void *)0) == elems_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->elems = elems_new;
 l->capc = capc_new;
 return HT_FR_SUCCESS;
}

variable_types: struct listmh { struct moveh { enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 } irrev; unsigned short pos; } *elems; unsigned long elemc; unsigned long capc; } *


decompiled_code:
void __fastcall free_listmh(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void
free_listmh (
 struct listmh * const l
 )
{
 if (((void *)0) != l->elems)
 {
  free (l->elems);
 }
 free (l);
}

canonical_original_code:
void free_listmh(struct listmh *l)
{
 if (((void *)0) != l->elems)
 {
  free (l->elems);
 }
 free (l);
}


original_code:
enum HT_FR
listmh_add (
 struct listmh * const l,
 const unsigned short pos,
 const unsigned short dest,
 const HT_BOOL irrev
 )
{
 if (((void *)0) == l->elems)
 {
  return HT_FR_FAIL_NULLPTR;
 }
 if (l->elemc + 1 > l->capc)
 {
  const enum HT_FR fr = listmh_grow(l, (size_t)
   ((float)l->capc * HT_LISTMH_MEMC_GROWF));
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 l->elems[l->elemc].irrev = irrev;
 l->elems[l->elemc].pos = pos;
 l->elems[l->elemc].dest = dest;
 l->elemc++;
 return HT_FR_SUCCESS;
}

canonical_original_code:
enum HT_FR listmh_add(struct listmh *l, unsigned short pos, unsigned short dest, enum HT_BOOL_ irrev)
{
 if (((void *)0) == l->elems)
 {
  return HT_FR_FAIL_NULLPTR;
 }
 if (l->elemc + 1 > l->capc)
 {
  enum HT_FR fr = listmh_grow(l, (size_t)
   ((float)l->capc * HT_LISTMH_MEMC_GROWF));
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 l->elems[l->elemc].irrev = irrev;
 l->elems[l->elemc].pos = pos;
 l->elems[l->elemc].dest = dest;
 l->elemc++;
 return HT_FR_SUCCESS;
}

variable_types:
pos
unsigned short

variable_types:
dest
unsigned short

variable_types:
irrev
enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 }


original_code:
enum HT_FR
listmh_copy (
 const struct listmh * const src,
  struct listmh * const dest
 )
{
 size_t i;
 if (src->elemc > dest->capc)
 {
  const enum HT_FR fr = listmh_grow(dest, src->elemc);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 dest->elemc = src->elemc;
 for (i = (size_t)0; i < src->elemc; i++)
 {
  dest->elems[i].pos = src->elems[i].pos;
  dest->elems[i].dest = src->elems[i].dest;
  dest->elems[i].irrev = src->elems[i].irrev;
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
enum HT_FR listmh_copy(struct listmh *src, struct listmh *dest)
{
 unsigned long i;
 if (src->elemc > dest->capc)
 {
  enum HT_FR fr = listmh_grow(dest, src->elemc);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 dest->elemc = src->elemc;
 for (i = (unsigned long)0; i < src->elemc; i++)
 {
  dest->elems[i].pos = src->elems[i].pos;
  dest->elems[i].dest = src->elems[i].dest;
  dest->elems[i].irrev = src->elems[i].irrev;
 }
 return HT_FR_SUCCESS;
}

variable_types:
dest
struct listmh *

variable_types: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }


decompiled_code:
_BOOL8 __fastcall type_square_can_capture(__int64 a1, unsigned __int8 a2)
{
return (a2 & *(_BYTE *)(a1 + 1)) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, unsigned __int8 a2)
{
return (a2 & *(_BYTE *)(a1 + 1)) == a2;
}

original_code:
HT_BOOL
type_square_can_capture (
 const struct type_square * const ts,
 const HT_BIT_U8 pbit
 )
{
 return ((unsigned int)pbit & (unsigned int)ts->captures)
  == (unsigned int)pbit;
}

canonical_original_code:
enum HT_BOOL_ type_square_can_capture(struct type_square *ts, unsigned char pbit)
{
 return ((unsigned int)pbit & (unsigned int)ts->captures)
  == (unsigned int)pbit;
}

variable_types: struct type_square { unsigned char bit; unsigned char captures; unsigned short capt_sides; enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 } escape; } *

variable_types:
pbit
unsigned char

user_defined_types: struct type_square { unsigned char bit; unsigned char captures; unsigned short capt_sides; enum HT_BOOL_ escape; }


decompiled_code:
__int64 __fastcall type_square_init(__int64 a1)
{
__int64 result; // rax

result = HT_BIT_U8_EMPTY;
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)a1 = result;
*(_BYTE *)(a1 + 1) = result;
*(_WORD *)(a1 + 2) = HT_TSQUARE_CAPT_SIDES_NONE;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

result = HT_BIT_U8_EMPTY;
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)a1 = result;
*(_BYTE *)(a1 + 1) = result;
*(_WORD *)(a1 + 2) = HT_TSQUARE_CAPT_SIDES_NONE;
return result;
}

original_code:
void
type_square_init (
 struct type_square * const ts
 )
{
 ts->bit = HT_BIT_U8_EMPTY;
 ts->captures = HT_BIT_U8_EMPTY;
 ts->capt_sides = HT_TSQUARE_CAPT_SIDES_NONE;
 ts->escape = HT_FALSE;
}

canonical_original_code:
void type_square_init(struct type_square *ts)
{
 ts->bit = HT_BIT_U8_EMPTY;
 ts->captures = HT_BIT_U8_EMPTY;
 ts->capt_sides = HT_TSQUARE_CAPT_SIDES_NONE;
 ts->escape = HT_FALSE;
}


decompiled_code:
__int64 __fastcall type_index_get(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 > 0x20u )
{
result = 6LL;
if ( a1 != 64 )
result = (unsigned int)(a1 != 0x80) + 7;
}
else
{
result = 8LL;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 0LL;
break;
case 2u:
result = 1LL;
break;
case 4u:
result = 2LL;
break;
case 8u:
result = 3LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
result = 8LL;
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 > 0x20u )
{
result = 6LL;
if ( a1 != 64 )
result = (unsigned int)(a1 != 0x80) + 7;
}
else
{
result = 8LL;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 0LL;
break;
case 2u:
result = 1LL;
break;
case 4u:
result = 2LL;
break;
case 8u:
result = 3LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
result = 8LL;
break;
}
}
}
return result;
}

original_code:
unsigned short
type_index_get (
 const HT_BIT_U8 bit
 )
{
 switch (bit)
 {
  case 1:
   return (unsigned short)0;
  case 2:
   return (unsigned short)1;
  case 4:
   return (unsigned short)2;
  case 8:
   return (unsigned short)3;
  case 16:
   return (unsigned short)4;
  case 32:
   return (unsigned short)5;
  case 64:
   return (unsigned short)6;
  case 128:
   return (unsigned short)7;
  default:
   return (unsigned short)8;
 }
}

canonical_original_code:
unsigned short type_index_get(unsigned char bit)
{
 switch (bit)
 {
  case 1:
   return (unsigned short)0;
  case 2:
   return (unsigned short)1;
  case 4:
   return (unsigned short)2;
  case 8:
   return (unsigned short)3;
  case 16:
   return (unsigned short)4;
  case 32:
   return (unsigned short)5;
  case 64:
   return (unsigned short)6;
  case 128:
   return (unsigned short)7;
  default:
   return (unsigned short)8;
 }
}

variable_types:
bit
unsigned char

return_type: unsigned short


decompiled_code:
_BOOL8 __fastcall valid_size(__int16 a1)
{
return (unsigned __int16)(a1 - 1) <= 0x1Eu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int16 a1)
{
return (unsigned __int16)(a1 - 1) <= 0x1Eu;
}

original_code:
HT_BOOL
valid_size (
 const unsigned short w_or_h
 )
{
 return w_or_h >= SIZE_BOARD_MIN && w_or_h <= SIZE_BOARD_MAX;
}

canonical_original_code:
enum HT_BOOL_ valid_size(unsigned short w_or_h)
{
 return w_or_h >= SIZE_BOARD_MIN && w_or_h <= SIZE_BOARD_MAX;
}


repo: adovzh/dna-search

decompiled_code:
int __fastcall print_current_time(time_t *timer)
{
struct tm v2; // [rsp+0h] [rbp-98h] BYREF
char s[88]; // [rsp+40h] [rbp-58h] BYREF

gettimeofday((struct timeval *)timer, 0LL);
localtime_r(timer, &v2);
strftime(s, 0x4EuLL, "%b%e %H:%M:%S", &v2);
return printf("%s.%03d", s, timer[1] / 1000);
}

canonical_decompiled_code:
int __fastcall func0(time_t *timer)
{
struct tm v2; // [rsp+0h] [rbp-98h] BYREF
char s[88]; // [rsp+40h] [rbp-58h] BYREF

gettimeofday((struct timeval *)timer, 0LL);
localtime_r(timer, &v2);
strftime(s, 0x4EuLL, "%b%e %H:%M:%S", &v2);
return printf("%s.%03d", s, timer[1] / 1000);
}

original_code:
void print_current_time(struct timeval *tv) {
 struct tm time_tm;
 char formatted[78];
 gettimeofday(tv, ((void *)0));
 localtime_r(&tv->tv_sec, &time_tm);
 strftime(formatted, sizeof formatted, "%b%e %H:%M:%S", &time_tm);
 printf("%s.%03d", formatted, (int)(tv->tv_usec / 1000));
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types:
formatted
char [78]


decompiled_code:
int __fastcall print_elapsed_time(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
unsigned int v4; // er9

v2 = *a2 - *(_DWORD *)a1;
v3 = (a2[1] - *(_QWORD *)(a1 + 8)) / 1000LL;
v4 = v3;
if ( (int)v3 < 0 )
{
--v2;
v4 = v3 + 1000;
}
return printf("Elapsed: %d.%03d\n", v2, v4);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
unsigned int v4; // er9

v2 = *a2 - *(_DWORD *)a1;
v3 = (a2[1] - *(_QWORD *)(a1 + 8)) / 1000LL;
v4 = v3;
if ( (int)v3 < 0 )
{
--v2;
v4 = v3 + 1000;
}
return printf("Elapsed: %d.%03d\n", v2, v4);
}

original_code:
void print_elapsed_time(struct timeval *start_time, struct timeval *end_time) {
 int seconds = end_time->tv_sec - start_time->tv_sec;
 int millis = (end_time->tv_usec - start_time->tv_usec) / 1000;
 if (millis < 0) {
  seconds--;
  millis += 1000;
 }
 printf("Elapsed: %d.%03d\n", seconds, millis);
}

variable_types: seconds int

variable_types: millis int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall calc_elapsed_time(_QWORD *a1, _QWORD *a2)
{
return a2[1] + 1000000LL * (*a2 - *a1) - a1[1];
}

original_code:
long calc_elapsed_time(struct timeval *start_time, struct timeval *end_time) {
 return (end_time->tv_sec - start_time->tv_sec) * 1000000 + end_time->tv_usec - start_time->tv_usec;
}

return_type: long


decompiled_code:
int __fastcall found_handler(unsigned int a1)
{
time_t v2[3]; // [rsp+0h] [rbp-18h] BYREF

print_current_time(v2);
return printf(" FOUND SEQUENCE STARTING AT %u\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
time_t v2[3]; // [rsp+0h] [rbp-18h] BYREF

func0(v2);
return printf(" FOUND SEQUENCE STARTING AT %u\n", a1);
}

original_code:
void found_handler(bufindex_t pos) {
 struct timeval tv;
 print_current_time(&tv);
 printf(" FOUND SEQUENCE STARTING AT %u\n", pos);
}

canonical_original_code:
void found_handler(unsigned int pos) {
 struct timeval tv;
 print_current_time(&tv);
 printf(" FOUND SEQUENCE STARTING AT %u\n", pos);
}

variable_types:
pos
unsigned int

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int __fastcall submit_job(__int64 a1)
{
int v1; // edx
int result; // eax

pthread_mutex_lock(&queue_lock);
v1 = tail + 1;
job_queue[tail] = a1;
tail = v1;
pthread_cond_broadcast(&read_cond);
result = pthread_mutex_unlock(&queue_lock);
++jobs_posted;
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int v1; // edx
int result; // eax

pthread_mutex_lock(&queue_lock);
v1 = tail + 1;
job_queue[tail] = a1;
tail = v1;
pthread_cond_broadcast(&read_cond);
result = pthread_mutex_unlock(&queue_lock);
++jobs_posted;
return result;
}

original_code:
void submit_job(job_t *buf) {
 pthread_mutex_lock(&queue_lock);
 job_queue[tail++] = buf;
 pthread_cond_broadcast(&read_cond);
 pthread_mutex_unlock(&queue_lock);
 jobs_posted++;
}

canonical_original_code:
void submit_job(struct _job_t *buf) {
 pthread_mutex_lock(&queue_lock);
 job_queue[tail++] = buf;
 pthread_cond_broadcast(&read_cond);
 pthread_mutex_unlock(&queue_lock);
 jobs_posted++;
}

variable_types: struct _job_t { char *buf; unsigned int len; unsigned int offset; } *


decompiled_code:
__int64 request_job()
{
__int64 i; // rax
__int64 v1; // r12

pthread_mutex_lock(&queue_lock);
for ( i = head; head == tail; i = head )
pthread_cond_wait(&read_cond, &queue_lock);
v1 = job_queue[i];
head = i + 1;
pthread_mutex_unlock(&queue_lock);
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // rax
__int64 v1; // r12

pthread_mutex_lock(&queue_lock);
for ( i = head; head == tail; i = head )
pthread_cond_wait(&read_cond, &queue_lock);
v1 = job_queue[i];
head = i + 1;
pthread_mutex_unlock(&queue_lock);
return v1;
}

original_code:
job_t *request_job() {
 pthread_mutex_lock(&queue_lock);
 while (head == tail)
  pthread_cond_wait(&read_cond, &queue_lock);
 job_t *job = job_queue[head++];
 pthread_mutex_unlock(&queue_lock);
 return job;
}

canonical_original_code:
struct _job_t *request_job() {
 pthread_mutex_lock(&queue_lock);
 while (head == tail)
  pthread_cond_wait(&read_cond, &queue_lock);
 struct _job_t *job = job_queue[head++];
 pthread_mutex_unlock(&queue_lock);
 return job;
}

return_type: struct _job_t { char *buf; unsigned int len; unsigned int offset; } *


decompiled_code:
int complete_job()
{
pthread_mutex_lock(&jobs_completed_lock);
++jobs_completed;
pthread_cond_broadcast(&jobs_completed_cond);
return pthread_mutex_unlock(&jobs_completed_lock);
}

canonical_decompiled_code:
int func2()
{
pthread_mutex_lock(&jobs_completed_lock);
++jobs_completed;
pthread_cond_broadcast(&jobs_completed_cond);
return pthread_mutex_unlock(&jobs_completed_lock);
}

original_code:
void complete_job() {
 pthread_mutex_lock(&jobs_completed_lock);
 jobs_completed++;
 pthread_cond_broadcast(&jobs_completed_cond);
 pthread_mutex_unlock(&jobs_completed_lock);
}


decompiled_code:
int wait_jobs_completed()
{
int v0; // eax
unsigned int v1; // ebp
char *v2; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
struct timespec abstime; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
abstime.tv_nsec = 0LL;
abstime.tv_sec = v4.tv_sec + 90;
pthread_mutex_lock(&jobs_completed_lock);
while ( jobs_posted > jobs_completed )
{
v0 = pthread_cond_timedwait(&jobs_completed_cond, &jobs_completed_lock, &abstime);
v1 = v0;
if ( v0 )
{
v2 = strerror(v0);
printf("Timed wait: %d, %s\n", v1, v2);
return pthread_mutex_unlock(&jobs_completed_lock);
}
}
return pthread_mutex_unlock(&jobs_completed_lock);
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
unsigned int v1; // ebp
char *v2; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
struct timespec abstime; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
abstime.tv_nsec = 0LL;
abstime.tv_sec = v4.tv_sec + 90;
pthread_mutex_lock(&jobs_completed_lock);
while ( jobs_posted > jobs_completed )
{
v0 = pthread_cond_timedwait(&jobs_completed_cond, &jobs_completed_lock, &abstime);
v1 = v0;
if ( v0 )
{
v2 = strerror(v0);
printf("Timed wait: %d, %s\n", v1, v2);
return pthread_mutex_unlock(&jobs_completed_lock);
}
}
return pthread_mutex_unlock(&jobs_completed_lock);
}

original_code:
void wait_jobs_completed() {
 int errorno = 0;
 struct timeval tv;
 struct timespec timeout;
 gettimeofday(&tv, ((void *)0));
 timeout.tv_sec = tv.tv_sec + 90;
    timeout.tv_nsec = 0;
 pthread_mutex_lock(&jobs_completed_lock);
 while (!errorno && jobs_posted > jobs_completed)
  errorno = pthread_cond_timedwait(&jobs_completed_cond, &jobs_completed_lock, &timeout);
 if (errorno){
  printf("Timed wait: %d, %s\n", errorno, strerror(errorno));
 }
 pthread_mutex_unlock(&jobs_completed_lock);
}

variable_types: errorno int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
void __fastcall __noreturn handle_job(void *a1)
{
unsigned int *v1; // rbp

while ( 1 )
{
v1 = (unsigned int *)request_job(a1);
search(*(_QWORD *)v1, 0LL, v1[2], v1[3], &found_handler);
a1 = v1;
free(v1);
complete_job();
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
unsigned int *v1; // rbp

while ( 1 )
{
v1 = (unsigned int *)request_job(a1);
search(*(_QWORD *)v1, 0LL, v1[2], v1[3], &found_handler);
a1 = v1;
free(v1);
complete_job();
}
}

original_code:
void *handle_job(void *arg) {
 while (1) {
  job_t *job = request_job();
  search(job->buf, 0, job->len, job->offset, found_handler);
  free(job);
  complete_job();
 }
}

canonical_original_code:
void *handle_job(void *arg) {
 while (1) {
  struct _job_t *job = request_job();
  search(job->buf, 0, job->len, job->offset, found_handler);
  free(job);
  complete_job();
 }
}

variable_types:
arg
void *

return_type: void *

user_defined_types: struct _job_t { char *buf; unsigned int len; unsigned int offset; }


decompiled_code:
int init_threads()
{
pthread_t *v0; // rbx
int result; // eax

v0 = &threads;
pthread_mutex_init(&queue_lock, 0LL);
pthread_cond_init(&read_cond, 0LL);
pthread_mutex_init(&jobs_completed_lock, 0LL);
pthread_cond_init(&jobs_completed_cond, 0LL);
do
result = pthread_create(v0++, 0LL, (void *(*)(void *))handle_job, 0LL);
while ( v0 != (pthread_t *)&unk_188 );
return result;
}

canonical_decompiled_code:
int func1()
{
pthread_t *v0; // rbx
int result; // eax

v0 = &threads;
pthread_mutex_init(&queue_lock, 0LL);
pthread_cond_init(&read_cond, 0LL);
pthread_mutex_init(&jobs_completed_lock, 0LL);
pthread_cond_init(&jobs_completed_cond, 0LL);
do
result = pthread_create(v0++, 0LL, (void *(*)(void *))handle_job, 0LL);
while ( v0 != (pthread_t *)&unk_188 );
return result;
}

original_code:
void init_threads() {
 int i;
 pthread_t *p = threads;
 pthread_mutex_init(&queue_lock, ((void *)0));
 pthread_cond_init(&read_cond, ((void *)0));
 pthread_mutex_init(&jobs_completed_lock, ((void *)0));
 pthread_cond_init(&jobs_completed_cond, ((void *)0));
 for (i = 0; i < 17; i++, p++)
  pthread_create(p, ((void *)0), handle_job, ((void *)0));
}

canonical_original_code:
void init_threads() {
 int i;
 unsigned long *p = threads;
 pthread_mutex_init(&queue_lock, ((void *)0));
 pthread_cond_init(&read_cond, ((void *)0));
 pthread_mutex_init(&jobs_completed_lock, ((void *)0));
 pthread_cond_init(&jobs_completed_cond, ((void *)0));
 for (i = 0; i < 17; i++, p++)
  pthread_create(p, ((void *)0), handle_job, ((void *)0));
}

variable_types: i int

variable_types:
p
unsigned long *


decompiled_code:
int destroy_threads()
{
pthread_t *v0; // rbx
pthread_t v1; // rdi

v0 = &threads;
do
{
v1 = *v0++;
pthread_cancel(v1);
}
while ( v0 != (pthread_t *)&unk_188 );
pthread_cond_destroy(&jobs_completed_cond);
pthread_mutex_destroy(&jobs_completed_lock);
pthread_cond_destroy(&read_cond);
return pthread_mutex_destroy(&queue_lock);
}

canonical_decompiled_code:
int func2()
{
pthread_t *v0; // rbx
pthread_t v1; // rdi

v0 = &threads;
do
{
v1 = *v0++;
pthread_cancel(v1);
}
while ( v0 != (pthread_t *)&unk_188 );
pthread_cond_destroy(&jobs_completed_cond);
pthread_mutex_destroy(&jobs_completed_lock);
pthread_cond_destroy(&read_cond);
return pthread_mutex_destroy(&queue_lock);
}

original_code:
void destroy_threads() {
 int i;
 pthread_t *p = threads;
 for (i = 0; i < 17; i++, p++)
  pthread_cancel(*p);
 pthread_cond_destroy(&jobs_completed_cond);
 pthread_mutex_destroy(&jobs_completed_lock);
 pthread_cond_destroy(&read_cond);
 pthread_mutex_destroy(&queue_lock);
}

canonical_original_code:
void destroy_threads() {
 int i;
 unsigned long *p = threads;
 for (i = 0; i < 17; i++, p++)
  pthread_cancel(*p);
 pthread_cond_destroy(&jobs_completed_cond);
 pthread_mutex_destroy(&jobs_completed_lock);
 pthread_cond_destroy(&read_cond);
 pthread_mutex_destroy(&queue_lock);
}


decompiled_code:
size_t __fastcall init_needle(const char *a1)
{
size_t result; // rax

needle = (__int64)a1;
result = strlen(a1);
needle_len = result;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
size_t result; // rax

needle = (__int64)a1;
result = strlen(a1);
needle_len = result;
return result;
}

original_code:
void init_needle(char *s) {
 needle = s;
 needle_len = strlen(s);
}

variable_types:
s
char *


decompiled_code:
void __fastcall brute_force(__int64 a1, unsigned int a2, int a3, unsigned int a4, void (__fastcall *a5)(_QWORD))
{
char *v5; // rbp
unsigned int v6; // ebx
int v8; // er13

v5 = (char *)(a1 + a2);
if ( a3 )
{
v6 = a4;
v8 = a3 + a4;
do
{
if ( !memcmp(v5, needle, needle_len) )
a5(v6);
++v6;
++v5;
}
while ( v8 != v6 );
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, unsigned int a2, int a3, unsigned int a4, void (__fastcall *a5)(_QWORD))
{
char *v5; // rbp
unsigned int v6; // ebx
int v8; // er13

v5 = (char *)(a1 + a2);
if ( a3 )
{
v6 = a4;
v8 = a3 + a4;
do
{
if ( !memcmp(v5, needle, needle_len) )
a5(v6);
++v6;
++v5;
}
while ( v8 != v6 );
}
}

original_code:
void brute_force(char *buffer, bufindex_t start, buflen_t len, bufindex_t offset, P_LISTENER listener) {
 char *p;
 buflen_t countdown = len;
 for (p = buffer + start; countdown; p++, countdown--)
  if (!memcmp(p, needle, needle_len))
   listener(len - countdown + offset);
}

canonical_original_code:
void brute_force(char *buffer, unsigned int start, unsigned int len, unsigned int offset, void (*listener)(unsigned int)) {
 char *p;
 unsigned int countdown = len;
 for (p = buffer + start; countdown; p++, countdown--)
  if (!memcmp(p, needle, needle_len))
   listener(len - countdown + offset);
}

variable_types:
buffer
char *

variable_types:
start
unsigned int

variable_types:
len
unsigned int

variable_types:
offset
unsigned int

variable_types:
listener
void (*)(unsigned int)

variable_types:
p
char *

variable_types:
countdown
unsigned int


repo: adrian-bl/bbjobs

decompiled_code:
void __fastcall pr_lhand(void *src)
{
size_t v1; // rax
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
char v3[8]; // [rsp+10h] [rbp-18h] BYREF

if ( src )
{
strcpy(v3, " ");
v2 = _mm_load_si128((const __m128i *)&LC2);
v1 = strlen((const char *)src);
memcpy(&v2, src, v1);
if ( pr_pmode )
printf("%llu ", pr_pfx);
printf(" %s : ", v2.m128i_i8);
}
}

canonical_decompiled_code:
void __fastcall func0(void *src)
{
size_t v1; // rax
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
char v3[8]; // [rsp+10h] [rbp-18h] BYREF

if ( src )
{
strcpy(v3, " ");
v2 = _mm_load_si128((const __m128i *)&LC2);
v1 = strlen((const char *)src);
memcpy(&v2, src, v1);
if ( pr_pmode )
printf("%llu ", pr_pfx);
printf(" %s : ", v2.m128i_i8);
}
}

original_code:
void pr_lhand(char *lhand) {
 char xbuff[20];
 if(lhand != ((void *)0)) {
  memset(xbuff, ' ', 20);
  xbuff[20 -1] = '\0';
  memcpy(xbuff, lhand, strlen(lhand));
  if(_pr_pmode) printf("%llu ", _pr_pfx);
  printf("  %s : ", xbuff);
 }
}

variable_types:
lhand
char *

variable_types:
xbuff
char [20]


decompiled_code:
int __fastcall pr_duration(void *a1, __int64 a2)
{
int result; // eax
int v4; // edi
__int64 v5; // rsi

pr_lhand(a1);
if ( a2 <= 300 || pr_pmode )
{
printf("%d sec", (unsigned int)a2);
result = putchar(10);
}
else
{
v4 = (int)a2 >> 31;
v5 = (unsigned int)((int)a2 / 60);
if ( a2 > 3600 )
printf(
"%d h %d min",
(unsigned int)(((int)((unsigned __int64)(2443359173LL * (int)a2) >> 32) >> 11) - v4),
(unsigned int)((int)v5 % 60));
else
printf("%d min", v5);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(void *a1, __int64 a2)
{
int result; // eax
int v4; // edi
__int64 v5; // rsi

func0(a1);
if ( a2 <= 300 || pr_pmode )
{
printf("%d sec", (unsigned int)a2);
result = putchar(10);
}
else
{
v4 = (int)a2 >> 31;
v5 = (unsigned int)((int)a2 / 60);
if ( a2 > 3600 )
printf(
"%d h %d min",
(unsigned int)(((int)((unsigned __int64)(2443359173LL * (int)a2) >> 32) >> 11) - v4),
(unsigned int)((int)v5 % 60));
else
printf("%d min", v5);
result = putchar(10);
}
return result;
}

original_code:
void pr_duration(char *lhand, time_t sec) {
 pr_lhand(lhand);
 if(sec <= 300 || _pr_pmode) {
  printf("%d sec", (int)sec);
 }
 else if(sec <= 60*60) {
  printf("%d min", (int)sec/60);
 }
 else {
  printf("%d h %d min", (int)sec/60/60, (int)sec/60%60);
 }
 printf("\n");
}

canonical_original_code:
void pr_duration(char *lhand, long sec) {
 pr_lhand(lhand);
 if(sec <= 300 || _pr_pmode) {
  printf("%d sec", (int)sec);
 }
 else if(sec <= 60*60) {
  printf("%d min", (int)sec/60);
 }
 else {
  printf("%d h %d min", (int)sec/60/60, (int)sec/60%60);
 }
 printf("\n");
}

variable_types: sec long


decompiled_code:
int __fastcall pr_int(void *a1, unsigned int a2)
{
pr_lhand(a1);
return printf("%d\n", a2);
}

canonical_decompiled_code:
int __fastcall func2(void *a1, unsigned int a2)
{
func0(a1);
return printf("%d\n", a2);
}

original_code:
void pr_int(char *lhand, int value) {
 pr_lhand(lhand);
 printf("%d\n", value);
}

variable_types: value int


decompiled_code:
int __fastcall pr_str(void *a1, const char *a2)
{
const char *v2; // rbp

v2 = a2;
pr_lhand(a1);
if ( !*a2 )
v2 = "-";
return puts(v2);
}

canonical_decompiled_code:
int __fastcall func3(void *a1, const char *a2)
{
const char *v2; // rbp

v2 = a2;
func0(a1);
if ( !*a2 )
v2 = "-";
return puts(v2);
}

original_code:
void pr_str(char *lhand, char *str) {
 pr_lhand(lhand);
 printf("%s\n", ( strlen(str) == 0 ? "-" : str ) );
}

variable_types:
str
char *


decompiled_code:
int __fastcall pr_ts(void *a1, time_t a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

timer = a2;
v2 = localtime(&timer);
strftime(s, 0x64uLL, "%R %F", v2);
return pr_str(a1, s);
}

canonical_decompiled_code:
int __fastcall func4(void *a1, time_t a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

timer = a2;
v2 = localtime(&timer);
strftime(s, 0x64uLL, "%R %F", v2);
return func3(a1, s);
}

original_code:
void pr_ts(char *lhand, time_t ts) {
 char dst[100];
 struct tm *tmp;
 tmp = localtime(&ts);
 strftime(dst, sizeof(dst), "%R %F", tmp);
 pr_str(lhand, dst);
}

canonical_original_code:
void pr_ts(char *lhand, long ts) {
 char dst[100];
 struct tm *tmp;
 tmp = localtime(&ts);
 strftime(dst, sizeof(dst), "%R %F", tmp);
 pr_str(lhand, dst);
}

variable_types: ts long

variable_types:
dst
char [100]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
int __fastcall pr_stn(void *a1, const char *a2, int a3)
{
const char *v3; // rbp
size_t v4; // r14
char *v7; // rax
char v8[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = a2;
if ( (unsigned int)a3 > 0x64 )
{
v4 = 100LL;
snprintf(v8, 0x64uLL, "%s", a2);
}
else
{
v4 = a3;
snprintf(v8, a3, "%s", a2);
if ( a3 <= 5 )
goto LABEL_3;
}
if ( strlen(a2) > v4 )
{
v7 = &v8[v4 - 6];
*(_DWORD *)v7 = 774778459;
v7[4] = 93;
}
LABEL_3:
if ( !pr_pmode )
v3 = v8;
return pr_str(a1, v3);
}

canonical_decompiled_code:
int __fastcall func5(void *a1, const char *a2, int a3)
{
const char *v3; // rbp
size_t v4; // r14
char *v7; // rax
char v8[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = a2;
if ( (unsigned int)a3 > 0x64 )
{
v4 = 100LL;
snprintf(v8, 0x64uLL, "%s", a2);
}
else
{
v4 = a3;
snprintf(v8, a3, "%s", a2);
if ( a3 <= 5 )
goto LABEL_3;
}
if ( strlen(a2) > v4 )
{
v7 = &v8[v4 - 6];
*(_DWORD *)v7 = 774778459;
v7[4] = 93;
}
LABEL_3:
if ( !pr_pmode )
v3 = v8;
return func3(a1, v3);
}

original_code:
void pr_stn(char *lhand, char *str, int limit) {
 char dst[100];
 if(limit > sizeof(dst))
  limit = sizeof(dst);
 snprintf(dst, limit, "%s", str);
 if(limit > strlen("[...]") && strlen(str) > limit) {
  memcpy(&dst[limit-1-strlen("[...]")], "[...]", strlen("[...]"));
 }
 pr_str(lhand, (_pr_pmode ? str : dst ) );
}

variable_types: limit int


decompiled_code:
int __fastcall pr_prct(void *a1, double a2)
{
pr_lhand(a1);
return printf("%.1f %%\n", a2);
}

canonical_decompiled_code:
int __fastcall func6(void *a1, double a2)
{
func0(a1);
return printf("%.1f %%\n", a2);
}

original_code:
void pr_prct(char *lhand, double num) {
 pr_lhand(lhand);
 printf("%.1f %%\n", num);
}

variable_types: num double


decompiled_code:
int __fastcall pr_fancy(char *s)
{
int v1; // eax
int result; // eax

v1 = fileno(stdout);
if ( isatty(v1) )
result = printf("\x1B[1;32m%s\x1B[0m\n", s);
else
result = puts(s);
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *s)
{
int v1; // eax
int result; // eax

v1 = fileno(stdout);
if ( isatty(v1) )
result = printf("\x1B[1;32m%s\x1B[0m\n", s);
else
result = puts(s);
return result;
}

original_code:
void pr_fancy(char *lhand) {
 if(isatty(fileno(stdout))) {
  printf("\x1b[1;32m%s\x1b[0m\n",lhand);
 }
 else {
  printf("%s\n", lhand);
 }
}


decompiled_code:
void __fastcall pr_set_output_parseable(int a1)
{
pr_pmode = a1;
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
pr_pmode = a1;
}

original_code:
void pr_set_output_parseable(int x) {
 _pr_pmode = x;
}

variable_types: x int


decompiled_code:
void __fastcall pr_set_prefix(__int64 a1)
{
pr_pfx = a1;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
pr_pfx = a1;
}

original_code:
void pr_set_prefix(long long unsigned jid) {
 _pr_pfx = jid;
}

canonical_original_code:
void pr_set_prefix(unsigned long long jid) {
 _pr_pfx = jid;
}

variable_types:
jid
unsigned long long


repo: adsgray/CServer

decompiled_code:
__int64 __fastcall get_rq_type(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8

v1 = strncasecmp(s1, "GET", 3uLL);
result = 1LL;
if ( v1 )
{
v3 = strncasecmp(s1, "POST", 4uLL);
result = 2LL;
if ( v3 )
{
v4 = strncasecmp(s1, "HEAD", 4uLL);
result = 0LL;
if ( v4 )
result = 3 - ((unsigned int)(strncasecmp(s1, "PUT", 3uLL) == 0) - 1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8

v1 = strncasecmp(s1, "GET", 3uLL);
result = 1LL;
if ( v1 )
{
v3 = strncasecmp(s1, "POST", 4uLL);
result = 2LL;
if ( v3 )
{
v4 = strncasecmp(s1, "HEAD", 4uLL);
result = 0LL;
if ( v4 )
result = 3 - ((unsigned int)(strncasecmp(s1, "PUT", 3uLL) == 0) - 1);
}
}
return result;
}

original_code:
static RQ_TYPE get_rq_type(char *raw)
{
 if (!strncasecmp(raw, "GET", strlen("GET"))) return GET;
 if (!strncasecmp(raw, "POST", strlen("POST"))) return POST;
 if (!strncasecmp(raw, "HEAD", strlen("HEAD"))) return HEAD;
 if (!strncasecmp(raw, "PUT", strlen("PUT"))) return PUT;
 return RQ_UNKNOWN;
}

canonical_original_code:
static enum RQ_TYPE get_rq_type(char *raw)
{
 if (!strncasecmp(raw, "GET", strlen("GET"))) return GET;
 if (!strncasecmp(raw, "POST", strlen("POST"))) return POST;
 if (!strncasecmp(raw, "HEAD", strlen("HEAD"))) return HEAD;
 if (!strncasecmp(raw, "PUT", strlen("PUT"))) return PUT;
 return RQ_UNKNOWN;
}

variable_types:
raw
char *

return_type: enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 }


decompiled_code:
char *__fastcall get_path(const char *a1)
{
char *v1; // rax
char *v2; // r8
const char *v3; // rbp
char *v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
int v7; // ebx
char *v8; // rax

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = v1 + 1;
v4 = strchr(v1 + 1, 32);
v2 = v4;
if ( v4 )
{
v7 = (_DWORD)v4 - 1 - (_DWORD)v3;
v8 = (char *)ag_malloc(v7 + 2, 32LL, v5, v6, v4);
v2 = strncpy(v8, v3, v7 + 1);
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char *v1; // rax
char *v2; // r8
const char *v3; // rbp
char *v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
int v7; // ebx
char *v8; // rax

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = v1 + 1;
v4 = strchr(v1 + 1, 32);
v2 = v4;
if ( v4 )
{
v7 = (_DWORD)v4 - 1 - (_DWORD)v3;
v8 = (char *)ag_malloc(v7 + 2, 32LL, v5, v6, v4);
v2 = strncpy(v8, v3, v7 + 1);
}
}
return v2;
}

original_code:
static char *get_path(char *raw)
{
 char *start_path;
 char *end_path;
 char *rval;
 int plength;
 start_path = strstr(raw, " ");;
 if (!start_path) return ((void *)0);
 start_path++;
 end_path = strstr(start_path, " ");
 if (!end_path) return ((void *)0);
 end_path--;
 plength = end_path - start_path + 1;
 rval = ag_malloc(plength + 1);
 strncpy(rval, start_path, plength);
 return rval;
}

variable_types:
rval
char *

variable_types: plength int


decompiled_code:
char *__fastcall get_prot(const char *a1)
{
char *v1; // rax
char *v2; // r8
char *v3; // rax
const char *v4; // rbp
char *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
int v8; // ebx
char *v9; // rax

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = strchr(v1 + 1, 32);
v2 = v3;
if ( v3 )
{
v4 = v3 + 1;
v5 = strstr(v3 + 1, "\r\n");
v2 = v5;
if ( v5 )
{
v8 = (_DWORD)v5 - 1 - (_DWORD)v4;
v9 = (char *)ag_malloc(v8 + 2, "\r\n", v6, v7, v5);
v2 = strncpy(v9, v4, v8 + 1);
}
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1)
{
char *v1; // rax
char *v2; // r8
char *v3; // rax
const char *v4; // rbp
char *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
int v8; // ebx
char *v9; // rax

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = strchr(v1 + 1, 32);
v2 = v3;
if ( v3 )
{
v4 = v3 + 1;
v5 = strstr(v3 + 1, "\r\n");
v2 = v5;
if ( v5 )
{
v8 = (_DWORD)v5 - 1 - (_DWORD)v4;
v9 = (char *)ag_malloc(v8 + 2, "\r\n", v6, v7, v5);
v2 = strncpy(v9, v4, v8 + 1);
}
}
}
return v2;
}

original_code:
static char *get_prot(char *raw)
{
 char *start_prot;
 char *end_prot;
 char *rval;
 int plength;
 start_prot = strstr(raw, " ");
 if (!start_prot) return ((void *)0);
 start_prot++;
 start_prot = strstr(start_prot, " ");
 if (!start_prot) return ((void *)0);
 start_prot++;
 end_prot = strstr(start_prot, "\r\n");
 if (!end_prot) return ((void *)0);
 end_prot--;
 plength = end_prot - start_prot + 1;
 rval = ag_malloc(plength + 1);
 strncpy(rval, start_prot, plength);
 return rval;
}


decompiled_code:
__int64 __fastcall destroy_request(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = (void *)*((_QWORD *)ptr + 11);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 13);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 8);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 88) );
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = (void *)*((_QWORD *)ptr + 11);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 13);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 8);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 88) );
free(ptr);
return 1LL;
}

original_code:
int destroy_request(void *arg)
{
 request_t rq = arg;
 int i;
 if (rq->prot) free(rq->prot);
 if (rq->path) free(rq->path);
 if (rq->body) free(rq->body);
 for (i = 0; i < H_MAX; i++) {
  if (rq->headers[i]) free(rq->headers[i]);
 }
 free(rq);
 rq = ((void *)0);
 return 1;
}

canonical_original_code:
int destroy_request(void *arg)
{
 struct _http_request *rq = arg;
 int i;
 if (rq->prot) free(rq->prot);
 if (rq->path) free(rq->path);
 if (rq->body) free(rq->body);
 for (i = 0; i < H_MAX; i++) {
  if (rq->headers[i]) free(rq->headers[i]);
 }
 free(rq);
 rq = ((void *)0);
 return 1;
}

variable_types:
arg
void *

variable_types: struct _http_request { enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 } rtype; char *headers[-1]; char *prot; char *path; char *body; char *content_type; char *raw; int (*destroy)(void *); } *

variable_types: i int

user_defined_types: struct _http_request { enum RQ_TYPE rtype; char *headers[-1]; char *prot; char *path; char *body; char *content_type; char *raw; int (*destroy)(void *); }


decompiled_code:
char *__fastcall str_toupper(const char *a1)
{
size_t v1; // rbx
char *v2; // r12
size_t v3; // rbp
const unsigned __int16 **v4; // rax
__int64 v5; // r13

v1 = 0LL;
v2 = strdup(a1);
v3 = strlen(v2);
while ( v1 < v3 )
{
v4 = _ctype_b_loc();
v5 = v2[v1];
if ( ((*v4)[v5] & 0x200) != 0 )
{
v2[v1] = (*_ctype_toupper_loc())[v5];
v3 = strlen(v2);
}
++v1;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1)
{
size_t v1; // rbx
char *v2; // r12
size_t v3; // rbp
const unsigned __int16 **v4; // rax
__int64 v5; // r13

v1 = 0LL;
v2 = strdup(a1);
v3 = strlen(v2);
while ( v1 < v3 )
{
v4 = _ctype_b_loc();
v5 = v2[v1];
if ( ((*v4)[v5] & 0x200) != 0 )
{
v2[v1] = (*_ctype_toupper_loc())[v5];
v3 = strlen(v2);
}
++v1;
}
return v2;
}

original_code:
static char *str_toupper(char *fr)
{
 char *rval;
 int i;
 rval = strdup(fr);
 for (i = 0; i < strlen(rval); i++) {
  if (((*__ctype_b_loc ())[(int) ((rval[i]))] & (unsigned short int) _ISlower))
   rval[i] = toupper(rval[i]);
 }
 return rval;
}

canonical_original_code:
static char *str_toupper(char *fr)
{
 char *rval;
 int i;
 rval = strdup(fr);
 for (i = 0; i < strlen(rval); i++) {
  if (((*__ctype_b_loc ())[(int) ((rval[i]))] & (unsigned short) _ISlower))
   rval[i] = toupper(rval[i]);
 }
 return rval;
}

variable_types:
fr
char *


decompiled_code:
const char *__fastcall get_content_type(const char *a1)
{
const char *v1; // r12
char *v2; // rbp

v1 = "image/gif";
v2 = str_toupper(a1);
if ( !strstr(v2, ".GIF") )
{
v1 = "image/jpeg";
if ( !strstr(v2, ".JPEG") && !strstr(v2, ".JPG") )
{
v1 = "image/png";
if ( !strstr(v2, ".PNG") )
{
v1 = "image/x-xbitmap";
if ( !strstr(v2, ".BMP") )
{
v1 = "text/plain";
if ( !strstr(v2, ".TXT") )
v1 = "text/html";
}
}
}
}
free(v2);
return v1;
}

canonical_decompiled_code:
const char *__fastcall func5(const char *a1)
{
const char *v1; // r12
char *v2; // rbp

v1 = "image/gif";
v2 = func4(a1);
if ( !strstr(v2, ".GIF") )
{
v1 = "image/jpeg";
if ( !strstr(v2, ".JPEG") && !strstr(v2, ".JPG") )
{
v1 = "image/png";
if ( !strstr(v2, ".PNG") )
{
v1 = "image/x-xbitmap";
if ( !strstr(v2, ".BMP") )
{
v1 = "text/plain";
if ( !strstr(v2, ".TXT") )
v1 = "text/html";
}
}
}
}
free(v2);
return v1;
}

original_code:
static char *get_content_type(char *path)
{
 char *up_path;
 char *rval;
 up_path = str_toupper(path);
 if (strstr(up_path,".GIF")) rval = CT_IMGGIF;
 else if (strstr(up_path,".JPEG") ||
   strstr(up_path,".JPG")) rval = CT_IMGJPEG;
 else if (strstr(up_path,".PNG")) rval = CT_IMGPNG;
 else if (strstr(up_path,".BMP")) rval = CT_IMGBMP;
 else if (strstr(up_path,".TXT")) rval = CT_TEXTPLAIN;
 else rval = CT_TEXTHTML;
 free(up_path);
 return rval;
}

variable_types:
path
char *


decompiled_code:
char *__fastcall get_headers(__int64 a1, const char *a2)
{
const char *v2; // r12
char *v3; // r13
char *result; // rax
__int64 v5; // rbx
size_t v6; // rbp
const char *i; // r14
__int64 v8; // r15
const char *v9; // rbp
char *v10; // rax
char *v11; // rbx

v2 = a2 + 2;
v3 = strstr(a2, "\r\n\r\n");
LABEL_2:
while ( 1 )
{
result = strstr(v2, "\r\n");
if ( !result || v3 == result )
return result;
v2 = result + 2;
v5 = 0LL;
v6 = 8LL;
for ( i = "Referer:"; ; v6 = strlen(i) )
{
v8 = (int)v5;
if ( !strncmp(v2, i, v6) )
break;
if ( ++v5 == 10 )
goto LABEL_2;
i = header_names[v5];
}
v9 = &v2[v6];
v10 = strstr(v9, "\r\n");
*v10 = 0;
v11 = v10;
*(_QWORD *)(a1 + 8 * v8 + 8) = strdup(v9);
*v11 = 13;
}
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, const char *a2)
{
const char *v2; // r12
char *v3; // r13
char *result; // rax
__int64 v5; // rbx
size_t v6; // rbp
const char *i; // r14
__int64 v8; // r15
const char *v9; // rbp
char *v10; // rax
char *v11; // rbx

v2 = a2 + 2;
v3 = strstr(a2, "\r\n\r\n");
LABEL_2:
while ( 1 )
{
result = strstr(v2, "\r\n");
if ( !result || v3 == result )
return result;
v2 = result + 2;
v5 = 0LL;
v6 = 8LL;
for ( i = "Referer:"; ; v6 = strlen(i) )
{
v8 = (int)v5;
if ( !strncmp(v2, i, v6) )
break;
if ( ++v5 == 10 )
goto LABEL_2;
i = header_names[v5];
}
v9 = &v2[v6];
v10 = strstr(v9, "\r\n");
*v10 = 0;
v11 = v10;
*(_QWORD *)(a1 + 8 * v8 + 8) = strdup(v9);
*v11 = 13;
}
}

original_code:
static void get_headers(request_t rq, char *raw) {
 int i;
 char *pos = raw;
 char *end_headers;
 end_headers = strstr(raw, "\r\n\r\n");
 pos += 2;
 for (;;) {
  pos = strstr(pos, "\r\n");
  if (!pos || pos == end_headers) return;
  pos += 2;
  for (i = 0; i < H_MAX; i++) {
   if (!strncmp(pos,
    header_names[i],
    strlen(header_names[i])))
   {
    char *tmp1, *tmp2;
    tmp1 = pos + strlen(header_names[i]);
    tmp2 = strstr(tmp1,"\r\n");
    *tmp2 = '\0';
    rq->headers[i] = strdup(tmp1);
    *tmp2 = '\r';
    break;
   }
  }
 }
}

canonical_original_code:
static void get_headers(struct _http_request *rq, char *raw) {
 int i;
 char *pos = raw;
 char *end_headers;
 end_headers = strstr(raw, "\r\n\r\n");
 pos += 2;
 for (;;) {
  pos = strstr(pos, "\r\n");
  if (!pos || pos == end_headers) return;
  pos += 2;
  for (i = 0; i < H_MAX; i++) {
   if (!strncmp(pos,
    header_names[i],
    strlen(header_names[i])))
   {
    char *tmp1; char *tmp2;
    tmp1 = pos + strlen(header_names[i]);
    tmp2 = strstr(tmp1,"\r\n");
    *tmp2 = '\0';
    rq->headers[i] = strdup(tmp1);
    *tmp2 = '\r';
    break;
   }
  }
 }
}

variable_types:
pos
char *

user_defined_types: enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 }


decompiled_code:
__int64 __fastcall new_request(char *haystack, __int64 a2)
{
__int64 v2; // rbx
int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
int v7; // er12
char *v8; // rax
char *v9; // rax
char *v10; // rax

v2 = a2;
v3 = get_rq_type(haystack);
if ( v3 == 4 )
return 0LL;
v7 = v3;
if ( !a2 )
v2 = ag_malloc(136LL, 0LL, v4, v5, v6);
*(_QWORD *)(v2 + 128) = destroy_request;
*(_DWORD *)v2 = v7;
v8 = get_path(haystack);
*(_QWORD *)(v2 + 96) = v8;
*(_QWORD *)(v2 + 112) = get_content_type(v8);
v9 = get_prot(haystack);
*(_QWORD *)(v2 + 104) = haystack;
*(_QWORD *)(v2 + 88) = v9;
get_headers(v2, haystack);
v10 = strstr(haystack, "\r\n\r\n");
*(_QWORD *)(v2 + 104) = strdup(v10 + 4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *haystack, __int64 a2)
{
__int64 v2; // rbx
int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
int v7; // er12
char *v8; // rax
char *v9; // rax
char *v10; // rax

v2 = a2;
v3 = func0(haystack);
if ( v3 == 4 )
return 0LL;
v7 = v3;
if ( !a2 )
v2 = ag_malloc(136LL, 0LL, v4, v5, v6);
*(_QWORD *)(v2 + 128) = destroy_request;
*(_DWORD *)v2 = v7;
v8 = func1(haystack);
*(_QWORD *)(v2 + 96) = v8;
*(_QWORD *)(v2 + 112) = func5(v8);
v9 = func2(haystack);
*(_QWORD *)(v2 + 104) = haystack;
*(_QWORD *)(v2 + 88) = v9;
func6(v2, haystack);
v10 = strstr(haystack, "\r\n\r\n");
*(_QWORD *)(v2 + 104) = strdup(v10 + 4);
return v2;
}

original_code:
request_t new_request(char *raw, request_t rq)
{
 RQ_TYPE rqt;
 char *end_headers;
 rqt = get_rq_type(raw);
 if (rqt == RQ_UNKNOWN) return ((void *)0);
 if (!rq) rq = ag_malloc(sizeof(struct _http_request));
 rq->destroy = destroy_request;
 rq->rtype = rqt;
 rq->path = get_path(raw);
 rq->content_type = get_content_type(rq->path);
 rq->prot = get_prot(raw);
 rq->body = raw;
 get_headers(rq, raw);
 end_headers = strstr(raw, "\r\n\r\n");
 end_headers += 4;
 rq->body = strdup(end_headers);
 return rq;
}

canonical_original_code:
struct _http_request *new_request(char *raw, struct _http_request *rq)
{
 enum RQ_TYPE rqt;
 char *end_headers;
 rqt = get_rq_type(raw);
 if (rqt == RQ_UNKNOWN) return ((void *)0);
 if (!rq) rq = ag_malloc(sizeof(struct _http_request));
 rq->destroy = destroy_request;
 rq->rtype = rqt;
 rq->path = get_path(raw);
 rq->content_type = get_content_type(rq->path);
 rq->prot = get_prot(raw);
 rq->body = raw;
 get_headers(rq, raw);
 end_headers = strstr(raw, "\r\n\r\n");
 end_headers += 4;
 rq->body = strdup(end_headers);
 return rq;
}

variable_types:
rq
struct _http_request *

return_type: struct _http_request { enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 } rtype; char *headers[-1]; char *prot; char *path; char *body; char *content_type; char *raw; int (*destroy)(void *); } *


decompiled_code:
int __fastcall gr_printstats(__int64 a1)
{
int result; // eax

do
{
result = fprintf(
stderr,
"n=%d m=%d usage=%.2f%%\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
(float)((float)(100 * *(_DWORD *)(a1 + 8)) / (float)*(int *)(a1 + 12)));
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int result; // eax

do
{
result = fprintf(
stderr,
"n=%d m=%d usage=%.2f%%\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
(float)((float)(100 * *(_DWORD *)(a1 + 8)) / (float)*(int *)(a1 + 12)));
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

original_code:
static void gr_printstats(gr_t gr)
{
 fprintf(stderr, "n=%d m=%d usage=%.2f%%\n",
         gr->num, gr->max,
  100*gr->num/(float)gr->max);
 if (gr->chain) gr_printstats(gr->chain);
}

canonical_original_code:
static void gr_printstats(struct genresource *gr)
{
 fprintf(stderr, "n=%d m=%d usage=%.2f%%\n",
         gr->num, gr->max,
  100*gr->num/(float)gr->max);
 if (gr->chain) gr_printstats(gr->chain);
}

variable_types: struct genresource { struct resource_t { void *data; int (*ff)(void *); } *ptrs; int num; int max; struct genresource *next; struct genresource *chain; } *

user_defined_types: struct genresource { struct resource_t *ptrs; int num; int max; struct genresource *next; struct genresource *chain; }


decompiled_code:
__int64 __fastcall gr_clear(__int64 *a1)
{
void *v2; // rdi
unsigned int v3; // er13
unsigned int v4; // eax
__int64 v5; // rdx
__int64 v6; // rbx
__int64 v7; // rax
void *v8; // rdi
__int64 (*v9)(void); // rax

if ( !a1 )
_assert_fail("gr", "libserver/gr.c", 0x38u, "gr_clear");
if ( !*a1 )
_assert_fail("gr->ptrs", "libserver/gr.c", 0x39u, "gr_clear");
v2 = (void *)a1[3];
v3 = 0;
if ( v2 )
{
if ( destroy_chains_on_clear )
{
v4 = gr_destroy(v2);
a1[3] = 0LL;
v3 = v4;
}
else
{
v3 = gr_clear();
}
}
if ( *((int *)a1 + 2) > 0 )
{
v5 = *a1;
v6 = 0LL;
do
{
v7 = v5 + 16 * v6;
v8 = *(void **)v7;
if ( *(_QWORD *)v7 )
{
v9 = *(__int64 (**)(void))(v7 + 8);
if ( v9 )
v3 += v9();
else
free(v8);
v5 = *a1;
*(_QWORD *)(*a1 + 16 * v6) = 0LL;
}
++v6;
}
while ( *((_DWORD *)a1 + 2) > (int)v6 );
}
*((_DWORD *)a1 + 2) = 0;
return v3;
}

original_code:
int gr_clear(gr_t gr)
{
 int i;
 int ret_val = 0;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 if (gr->chain) {
  if (dbg) fprintf(stderr, "gr_clear: clearing chain\n");
  if (destroy_chains_on_clear) {
   ret_val += gr_destroy(gr->chain);
   gr->chain = ((void *)0);
  } else {
   ret_val += gr_clear(gr->chain);
  }
 }
 for (i = 0; i < gr->num; i++) {
  if (gr->ptrs[i].data) {
   if (gr->ptrs[i].ff)
    ret_val += (*gr->ptrs[i].ff)(gr->ptrs[i].data);
   else
    free(gr->ptrs[i].data);
   gr->ptrs[i].data = ((void *)0);
  }
 }
 if (dbg) fprintf(stderr, "gr_clear: cleared %d\n", i);
 gr->num = 0;
 return ret_val;
}

canonical_original_code:
int gr_clear(struct genresource *gr)
{
 int i;
 int ret_val = 0;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 if (gr->chain) {
  if (dbg) fprintf(stderr, "gr_clear: clearing chain\n");
  if (destroy_chains_on_clear) {
   ret_val += gr_destroy(gr->chain);
   gr->chain = ((void *)0);
  } else {
   ret_val += gr_clear(gr->chain);
  }
 }
 for (i = 0; i < gr->num; i++) {
  if (gr->ptrs[i].data) {
   if (gr->ptrs[i].ff)
    ret_val += (*gr->ptrs[i].ff)(gr->ptrs[i].data);
   else
    free(gr->ptrs[i].data);
   gr->ptrs[i].data = ((void *)0);
  }
 }
 if (dbg) fprintf(stderr, "gr_clear: cleared %d\n", i);
 gr->num = 0;
 return ret_val;
}

user_defined_types: struct resource_t { void *data; int (*ff)(void *); }


decompiled_code:
__int64 __fastcall gr_destroy(void *ptr)
{
unsigned int v1; // er12

v1 = 0;
if ( ptr )
{
v1 = gr_clear((__int64 *)ptr);
free(*(void **)ptr);
free(ptr);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
unsigned int v1; // er12

v1 = 0;
if ( ptr )
{
v1 = func1((__int64 *)ptr);
free(*(void **)ptr);
free(ptr);
}
return v1;
}

original_code:
int gr_destroy(gr_t gr)
{
 int ret_val;
 if (!gr) return 0;
 ret_val = gr_clear(gr);
 free(gr->ptrs);
 free(gr);
 return ret_val;
}

canonical_original_code:
int gr_destroy(struct genresource *gr)
{
 int ret_val;
 if (!gr) return 0;
 ret_val = gr_clear(gr);
 free(gr->ptrs);
 free(gr);
 return ret_val;
}


original_code:
int gr_track(gr_t gr, void *ptr, free_func ff)
{
 recurse:
 if (gr->num == gr->max) {
  if (!gr->chain) {
   if (dbg) fprintf(stderr, "gr_track: chaining %d\n",
                   gr->max);
   gr->chain = gr_init(2*gr->max);
  }
  gr = gr->chain;
  goto recurse;
 }
 gr->ptrs[gr->num].data = ptr;
 gr->ptrs[gr->num++].ff = ff;
 return 1;
}

canonical_original_code:
int gr_track(struct genresource *gr, void *ptr, int (*ff)(void *))
{
 recurse:
 if (gr->num == gr->max) {
  if (!gr->chain) {
   if (dbg) fprintf(stderr, "gr_track: chaining %d\n",
                   gr->max);
   gr->chain = gr_init(2*gr->max);
  }
  gr = gr->chain;
  goto recurse;
 }
 gr->ptrs[gr->num].data = ptr;
 gr->ptrs[gr->num++].ff = ff;
 return 1;
}

variable_types:
ptr
void *

variable_types:
ff
int (*)(void *)


decompiled_code:
void *__fastcall gr_malloc(_DWORD *a1, size_t a2)
{
void *v2; // rax
void *v3; // r12

if ( !a1 )
_assert_fail("gr", "libserver/gr.c", 0x5Eu, "gr_malloc");
if ( !*(_QWORD *)a1 )
_assert_fail("gr->ptrs", "libserver/gr.c", 0x5Fu, "gr_malloc");
v2 = calloc(1uLL, a2);
v3 = v2;
if ( !v2 || (unsigned int)gr_track(a1, (__int64)v2, 0LL) )
return v3;
free(v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(_DWORD *a1, size_t a2)
{
void *v2; // rax
void *v3; // r12

if ( !a1 )
_assert_fail("gr", "libserver/gr.c", 0x5Eu, "gr_malloc");
if ( !*(_QWORD *)a1 )
_assert_fail("gr->ptrs", "libserver/gr.c", 0x5Fu, "gr_malloc");
v2 = calloc(1uLL, a2);
v3 = v2;
if ( !v2 || (unsigned int)func3(a1, (__int64)v2, 0LL) )
return v3;
free(v3);
return 0LL;
}

original_code:
void *gr_malloc(gr_t gr, size_t size)
{
 void *r;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 r = calloc(1, size);
 if (!r) {
  if (dbg) fprintf(stderr, "gr_malloc: calloc failed\n");
  return r;
 }
 if (!gr_track(gr, r, ((void *)0))) {
  if (dbg) fprintf(stderr, "gr_malloc: gr_track failed\n");
  free(r);
  return ((void *)0);
 }
 return r;
}

canonical_original_code:
void *gr_malloc(struct genresource *gr, unsigned long size)
{
 void *r;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 r = calloc(1, size);
 if (!r) {
  if (dbg) fprintf(stderr, "gr_malloc: calloc failed\n");
  return r;
 }
 if (!gr_track(gr, r, ((void *)0))) {
  if (dbg) fprintf(stderr, "gr_malloc: gr_track failed\n");
  free(r);
  return ((void *)0);
 }
 return r;
}

variable_types:
size
unsigned long

variable_types:
r
void *


decompiled_code:
__int64 gr_finish()
{
unsigned int v0; // er12
int v1; // ebp
void *v2; // rbx
void *v3; // rdi
__int64 result; // rax

v0 = 0;
v1 = destroy_chains_on_clear;
v2 = gr_List;
destroy_chains_on_clear = 1;
for ( gr_List = 0LL; v2; v0 += gr_destroy(v3) )
{
v3 = v2;
v2 = (void *)*((_QWORD *)v2 + 2);
}
result = v0;
destroy_chains_on_clear = v1;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // er12
int v1; // ebp
void *v2; // rbx
void *v3; // rdi
__int64 result; // rax

v0 = 0;
v1 = destroy_chains_on_clear;
v2 = gr_List;
destroy_chains_on_clear = 1;
for ( gr_List = 0LL; v2; v0 += func2(v3) )
{
v3 = v2;
v2 = (void *)*((_QWORD *)v2 + 2);
}
result = v0;
destroy_chains_on_clear = v1;
return result;
}

original_code:
int gr_finish()
{
 gr_t cur;
 gr_t prev = ((void *)0);
 int ret_val = 0;
 int save = destroy_chains_on_clear;
 destroy_chains_on_clear = 1;
 cur = gr_List;
 gr_List = ((void *)0);
 while (cur) {
  prev = cur;
  cur = cur->next;
  ret_val += gr_destroy(prev);
 }
 destroy_chains_on_clear = save;
 return ret_val;
}

canonical_original_code:
int gr_finish()
{
 struct genresource *cur;
 struct genresource *prev = ((void *)0);
 int ret_val = 0;
 int save = destroy_chains_on_clear;
 destroy_chains_on_clear = 1;
 cur = gr_List;
 gr_List = ((void *)0);
 while (cur) {
  prev = cur;
  cur = cur->next;
  ret_val += gr_destroy(prev);
 }
 destroy_chains_on_clear = save;
 return ret_val;
}

variable_types: save int


decompiled_code:
size_t __fastcall gr_stats(_QWORD *a1)
{
_QWORD *v1; // rbx
size_t result; // rax

v1 = a1;
if ( a1 || (v1 = gr_List) != 0LL )
{
do
{
gr_printstats((__int64)v1);
result = fwrite("----------------------\n", 1uLL, 0x17uLL, stderr);
v1 = (_QWORD *)v1[2];
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func6(_QWORD *a1)
{
_QWORD *v1; // rbx
size_t result; // rax

v1 = a1;
if ( a1 || (v1 = gr_List) != 0LL )
{
do
{
func0((__int64)v1);
result = fwrite("----------------------\n", 1uLL, 0x17uLL, stderr);
v1 = (_QWORD *)v1[2];
}
while ( v1 );
}
return result;
}

original_code:
void gr_stats(gr_t gr)
{
 gr_t cur = gr;
 if (!cur) cur = gr_List;
 while (cur) {
  gr_printstats(cur);
  fprintf(stderr, "----------------------\n");
  cur = cur->next;
 }
}

canonical_original_code:
void gr_stats(struct genresource *gr)
{
 struct genresource *cur = gr;
 if (!cur) cur = gr_List;
 while (cur) {
  gr_printstats(cur);
  fprintf(stderr, "----------------------\n");
  cur = cur->next;
 }
}