original_code:
long
mk_order(long long int index, order_t * o, long upd_num)
{
 long long int lcnt;
 long long int rprice;
 long ocnt;
 long long int tmp_date;
 long long int s_date;
 long long int r_date;
 long long int c_date;
 long long int clk_num;
 long long int supp_num;
 static char **asc_date = ((void *)0);
 char tmp_str[2];
 char **mk_ascdate (void);
 int delta = 1;
 static int bInit = 0;
 static char szFormat[100];
 if (!bInit)
 {
  sprintf(szFormat, "%%s%%0%d%s", 9, "%lld" + 1);
  bInit = 1;
 }
 if (asc_date == ((void *)0))
  asc_date = mk_ascdate();
 mk_sparse(index, &o->okey,
    (upd_num == 0) ? 0 : 1 + upd_num / (10000 / 10));
 if (scale >= 30000)
  dss_random64(&o->custkey, 1, (tdefs[3].base * scale), 40);
 else
  dss_random(&o->custkey, 1, (tdefs[3].base * scale), 40);
 while (o->custkey % 3 == 0)
 {
  o->custkey += delta;
  o->custkey = ( (o->custkey) < ((tdefs[3].base * scale)) ? (o->custkey) : ((tdefs[3].base * scale)));
  delta *= -1;
 }
 dss_random(&tmp_date, 92001, (92001 + 2557 - (121 + 30) - 1), 13);
 strcpy(o->odate, asc_date[tmp_date - 92001]);
 pick_str(&o_priority_set, 38, o->opriority);
 dss_random(&clk_num, 1, (((scale * 1000) > 1000 )?(scale * 1000):1000), 11);
 sprintf(o->clerk, szFormat, "Clerk#", clk_num);
 dbg_text(o->comment, (int)(49 * 0.4),(int)(49 * 1.6), 12);
 o->clen = (int)strlen(o->comment);
 o->spriority = 0;
 o->totalprice = 0;
 o->orderstatus = 'O';
 ocnt = 0;
 dss_random(&o->lines, 1, 7, 43);
 for (lcnt = 0; lcnt < o->lines; lcnt++)
 {
  o->l[lcnt].okey = o->okey;;
  o->l[lcnt].lcnt = lcnt + 1;
  dss_random(&o->l[lcnt].quantity, 1, 50, 14);
  dss_random(&o->l[lcnt].discount, 0, 10, 15);
  dss_random(&o->l[lcnt].tax, 0, 8, 16);
  pick_str(&l_instruct_set, 17, o->l[lcnt].shipinstruct);
  pick_str(&l_smode_set, 18, o->l[lcnt].shipmode);
  dbg_text(o->l[lcnt].comment, (int)(27 * 0.4),(int)(27 * 1.6), 25);
  o->l[lcnt].clen = (int)strlen(o->l[lcnt].comment);
  if (scale >= 30000)
   dss_random64(&o->l[lcnt].partkey, 1, (tdefs[0].base * scale), 19);
  else
   dss_random(&o->l[lcnt].partkey, 1, (tdefs[0].base * scale), 19);
  rprice = rpb_routine(o->l[lcnt].partkey);
  dss_random(&supp_num, 0, 3, 20);
  { long long int tot_scnt = tdefs[2].base * scale; o->l[lcnt].suppkey = (o->l[lcnt].partkey + supp_num * (tot_scnt / 4 + (long) ((o->l[lcnt].partkey - 1) / tot_scnt))) % tot_scnt + 1; };
  o->l[lcnt].eprice = rprice * o->l[lcnt].quantity;
  o->totalprice +=
   ((o->l[lcnt].eprice *
       ((long) 100 - o->l[lcnt].discount)) / (long) 100) *
   ((long) 100 + o->l[lcnt].tax)
   / (long) 100;
  dss_random(&s_date, 1, 121, 21);
  s_date += tmp_date;
  dss_random(&c_date, 30, 90, 22);
  c_date += tmp_date;
  dss_random(&r_date, 1, 30, 23);
  r_date += s_date;
  strcpy(o->l[lcnt].sdate, asc_date[s_date - 92001]);
  strcpy(o->l[lcnt].cdate, asc_date[c_date - 92001]);
  strcpy(o->l[lcnt].rdate, asc_date[r_date - 92001]);
  if (julian(r_date) <= 95168)
  {
   pick_str(&l_rflag_set, 24, tmp_str);
   o->l[lcnt].rflag[0] = *tmp_str;
  }
  else
   o->l[lcnt].rflag[0] = 'N';
  if (julian(s_date) <= 95168)
  {
   ocnt++;
   o->l[lcnt].lstatus[0] = 'F';
  }
  else
   o->l[lcnt].lstatus[0] = 'O';
 }
 if (ocnt > 0)
  o->orderstatus = 'P';
 if (ocnt == o->lines)
  o->orderstatus = 'F';
 return (0);
}

canonical_original_code:
long mk_order(long long index, struct order_t *o, long upd_num)
{
 long long lcnt;
 long long rprice;
 long ocnt;
 long long tmp_date;
 long long s_date;
 long long r_date;
 long long c_date;
 long long clk_num;
 long long supp_num;
 static char **asc_date = ((void *)0);
 char tmp_str[2];
 char **mk_ascdate();
 int delta = 1;
 static int bInit = 0;
 static char szFormat[100];
 if (!bInit)
 {
  sprintf(szFormat, "%%s%%0%d%s", 9, "%lld" + 1);
  bInit = 1;
 }
 if (asc_date == ((void *)0))
  asc_date = mk_ascdate();
 mk_sparse(index, &o->okey,
    (upd_num == 0) ? 0 : 1 + upd_num / (10000 / 10));
 if (scale >= 30000)
  dss_random64(&o->custkey, 1, (tdefs[3].base * scale), 40);
 else
  dss_random(&o->custkey, 1, (tdefs[3].base * scale), 40);
 while (o->custkey % 3 == 0)
 {
  o->custkey += delta;
  o->custkey = ( (o->custkey) < ((tdefs[3].base * scale)) ? (o->custkey) : ((tdefs[3].base * scale)));
  delta *= -1;
 }
 dss_random(&tmp_date, 92001, (92001 + 2557 - (121 + 30) - 1), 13);
 strcpy(o->odate, asc_date[tmp_date - 92001]);
 pick_str(&o_priority_set, 38, o->opriority);
 dss_random(&clk_num, 1, (((scale * 1000) > 1000 )?(scale * 1000):1000), 11);
 sprintf(o->clerk, szFormat, "Clerk#", clk_num);
 dbg_text(o->comment, (int)(49 * 0.4),(int)(49 * 1.6), 12);
 o->clen = (int)strlen(o->comment);
 o->spriority = 0;
 o->totalprice = 0;
 o->orderstatus = 'O';
 ocnt = 0;
 dss_random(&o->lines, 1, 7, 43);
 for (lcnt = 0; lcnt < o->lines; lcnt++)
 {
  o->l[lcnt].okey = o->okey;;
  o->l[lcnt].lcnt = lcnt + 1;
  dss_random(&o->l[lcnt].quantity, 1, 50, 14);
  dss_random(&o->l[lcnt].discount, 0, 10, 15);
  dss_random(&o->l[lcnt].tax, 0, 8, 16);
  pick_str(&l_instruct_set, 17, o->l[lcnt].shipinstruct);
  pick_str(&l_smode_set, 18, o->l[lcnt].shipmode);
  dbg_text(o->l[lcnt].comment, (int)(27 * 0.4),(int)(27 * 1.6), 25);
  o->l[lcnt].clen = (int)strlen(o->l[lcnt].comment);
  if (scale >= 30000)
   dss_random64(&o->l[lcnt].partkey, 1, (tdefs[0].base * scale), 19);
  else
   dss_random(&o->l[lcnt].partkey, 1, (tdefs[0].base * scale), 19);
  rprice = rpb_routine(o->l[lcnt].partkey);
  dss_random(&supp_num, 0, 3, 20);
  { long long tot_scnt = tdefs[2].base * scale; o->l[lcnt].suppkey = (o->l[lcnt].partkey + supp_num * (tot_scnt / 4 + (long) ((o->l[lcnt].partkey - 1) / tot_scnt))) % tot_scnt + 1; };
  o->l[lcnt].eprice = rprice * o->l[lcnt].quantity;
  o->totalprice +=
   ((o->l[lcnt].eprice *
       ((long) 100 - o->l[lcnt].discount)) / (long) 100) *
   ((long) 100 + o->l[lcnt].tax)
   / (long) 100;
  dss_random(&s_date, 1, 121, 21);
  s_date += tmp_date;
  dss_random(&c_date, 30, 90, 22);
  c_date += tmp_date;
  dss_random(&r_date, 1, 30, 23);
  r_date += s_date;
  strcpy(o->l[lcnt].sdate, asc_date[s_date - 92001]);
  strcpy(o->l[lcnt].cdate, asc_date[c_date - 92001]);
  strcpy(o->l[lcnt].rdate, asc_date[r_date - 92001]);
  if (julian(r_date) <= 95168)
  {
   pick_str(&l_rflag_set, 24, tmp_str);
   o->l[lcnt].rflag[0] = *tmp_str;
  }
  else
   o->l[lcnt].rflag[0] = 'N';
  if (julian(s_date) <= 95168)
  {
   ocnt++;
   o->l[lcnt].lstatus[0] = 'F';
  }
  else
   o->l[lcnt].lstatus[0] = 'O';
 }
 if (ocnt > 0)
  o->orderstatus = 'P';
 if (ocnt == o->lines)
  o->orderstatus = 'F';
 return (0);
}

variable_types:
index
long long

variable_types: struct order_t { long long okey; long long custkey; char orderstatus; long long totalprice; char odate[13]; char opriority[-1]; char clerk[-1]; long spriority; long long lines; char comment[-1]; int clen; struct line_t { long long okey; long long partkey; long long suppkey; long long lcnt; long long quantity; long long eprice; long long discount; long long tax; char rflag[1]; char lstatus[1]; char cdate[13]; char sdate[13]; char rdate[13]; char shipinstruct[-1]; char shipmode[-1]; char comment[-1]; int clen; } l[7]; } *

variable_types:
lcnt
long long

variable_types:
rprice
long long

variable_types: ocnt long

variable_types: delta int


repo: dragansah/tpch-dbgen

original_code:
long
mk_part(long long int index, part_t * p)
{
 long long int temp;
 long snum;
 long long int brnd;
 static int bInit = 0;
 static char szFormat[100];
 static char szBrandFormat[100];
 if (!bInit)
 {
  sprintf(szFormat, "%%s%%0%d%s", 1, "%lld" + 1);
  sprintf(szBrandFormat, "%%s%%0%d%s", 2, "%lld" + 1);
  bInit = 1;
 }
 p->partkey = index;
 agg_str(&colors, (long) 5, (long) 37, p->name);
 dss_random(&temp, 1, 5, 0);
 sprintf(p->mfgr, szFormat, "Manufacturer#", temp);
 dss_random(&brnd, 1, 5, 1);
 sprintf(p->brand, szBrandFormat, "Brand#", (temp * 10 + brnd));
 p->tlen = pick_str(&p_types_set, 2, p->type);
 p->tlen = (int)strlen(p_types_set.list[p->tlen].text);
 dss_random(&p->size, 1, 50, 3);
 pick_str(&p_cntr_set, 4, p->container);
 p->retailprice = rpb_routine(index);
 dbg_text(p->comment, (int)(14 * 0.4),(int)(14 * 1.6), 6);
 p->clen = (int)strlen(p->comment);
 for (snum = 0; snum < 4; snum++)
 {
  p->s[snum].partkey = p->partkey;
  { long long int tot_scnt = tdefs[2].base * scale; p->s[snum].suppkey = (index + snum * (tot_scnt / 4 + (long) ((index - 1) / tot_scnt))) % tot_scnt + 1; };
  dss_random(&p->s[snum].qty, 1, 9999, 7);
  dss_random(&p->s[snum].scost, 100, 100000, 8);
  dbg_text(p->s[snum].comment, (int)(124 * 0.4),(int)(124 * 1.6), 9);
  p->s[snum].clen = (int)strlen(p->s[snum].comment);
 }
 return (0);
}

canonical_original_code:
long mk_part(long long index, struct part_t *p)
{
 long long temp;
 long snum;
 long long brnd;
 static int bInit = 0;
 static char szFormat[100];
 static char szBrandFormat[100];
 if (!bInit)
 {
  sprintf(szFormat, "%%s%%0%d%s", 1, "%lld" + 1);
  sprintf(szBrandFormat, "%%s%%0%d%s", 2, "%lld" + 1);
  bInit = 1;
 }
 p->partkey = index;
 agg_str(&colors, (long) 5, (long) 37, p->name);
 dss_random(&temp, 1, 5, 0);
 sprintf(p->mfgr, szFormat, "Manufacturer#", temp);
 dss_random(&brnd, 1, 5, 1);
 sprintf(p->brand, szBrandFormat, "Brand#", (temp * 10 + brnd));
 p->tlen = pick_str(&p_types_set, 2, p->type);
 p->tlen = (int)strlen(p_types_set.list[p->tlen].text);
 dss_random(&p->size, 1, 50, 3);
 pick_str(&p_cntr_set, 4, p->container);
 p->retailprice = rpb_routine(index);
 dbg_text(p->comment, (int)(14 * 0.4),(int)(14 * 1.6), 6);
 p->clen = (int)strlen(p->comment);
 for (snum = 0; snum < 4; snum++)
 {
  p->s[snum].partkey = p->partkey;
  { long long tot_scnt = tdefs[2].base * scale; p->s[snum].suppkey = (index + snum * (tot_scnt / 4 + (long) ((index - 1) / tot_scnt))) % tot_scnt + 1; };
  dss_random(&p->s[snum].qty, 1, 9999, 7);
  dss_random(&p->s[snum].scost, 100, 100000, 8);
  dbg_text(p->s[snum].comment, (int)(124 * 0.4),(int)(124 * 1.6), 9);
  p->s[snum].clen = (int)strlen(p->s[snum].comment);
 }
 return (0);
}

variable_types: struct part_t { long long partkey; char name[-1]; int nlen; char mfgr[-1]; char brand[-1]; char type[-1]; int tlen; long long size; char container[-1]; long long retailprice; char comment[-1]; int clen; struct partsupp_t { long long partkey; long long suppkey; long long qty; long long scost; char comment[-1]; int clen; } s[4]; } *

variable_types:
temp
long long

variable_types: snum long

variable_types:
brnd
long long

variable_types: bInit int

variable_types:
szFormat
char [100]

variable_types:
szBrandFormat
char [100]

return_type: long

user_defined_types: struct part_t { long long partkey; char name[-1]; int nlen; char mfgr[-1]; char brand[-1]; char type[-1]; int tlen; long long size; char container[-1]; long long retailprice; char comment[-1]; int clen; struct partsupp_t s[4]; }


original_code:
long
mk_supp(long long int index, supplier_t * s)
{
 long long int i, bad_press, noise, offset, type;
 static int bInit = 0;
 static char szFormat[100];
 if (!bInit)
 {
  sprintf(szFormat, "%%s%%0%d%s", 9, "%lld" + 1);
  bInit = 1;
 }
 s->suppkey = index;
 sprintf(s->name, szFormat, "Supplier#", index);
 a_rnd((int)(25 * 0.4),(int)(25 * 1.6), 32, s->address);
 s->alen = (int)strlen(s->address);
 dss_random(&i, 0, nations.count - 1, 33);
 s->nation_code = i;
 gen_phone(i, s->phone, 34);
 dss_random(&s->acctbal, -99999, 999999, 35);
 dbg_text(s->comment, (int)(63 * 0.4),(int)(63 * 1.6), 36);
 s->clen = (int)strlen(s->comment);
 dss_random(&bad_press, 1, 10000, 46);
 dss_random(&type, 0, 100, 45);
 dss_random(&noise, 0, (s->clen - 19), 44);
 dss_random(&offset, 0, (s->clen - (19 + noise)), 47);
 if (bad_press <= 10)
 {
  type = (type < 50) ? 0 : 1;
  memcpy(s->comment + offset, "Customer ", 9);
  if (type == 0)
   memcpy(s->comment + 9 + offset + noise,
          "Complaints", 10);
  else
   memcpy(s->comment + 9 + offset + noise,
          "Recommends", 10);
 }
 return (0);
}

canonical_original_code:
long mk_supp(long long index, struct supplier_t *s)
{
 long long i; long long bad_press; long long noise; long long offset; long long type;
 static int bInit = 0;
 static char szFormat[100];
 if (!bInit)
 {
  sprintf(szFormat, "%%s%%0%d%s", 9, "%lld" + 1);
  bInit = 1;
 }
 s->suppkey = index;
 sprintf(s->name, szFormat, "Supplier#", index);
 a_rnd((int)(25 * 0.4),(int)(25 * 1.6), 32, s->address);
 s->alen = (int)strlen(s->address);
 dss_random(&i, 0, nations.count - 1, 33);
 s->nation_code = i;
 gen_phone(i, s->phone, 34);
 dss_random(&s->acctbal, -99999, 999999, 35);
 dbg_text(s->comment, (int)(63 * 0.4),(int)(63 * 1.6), 36);
 s->clen = (int)strlen(s->comment);
 dss_random(&bad_press, 1, 10000, 46);
 dss_random(&type, 0, 100, 45);
 dss_random(&noise, 0, (s->clen - 19), 44);
 dss_random(&offset, 0, (s->clen - (19 + noise)), 47);
 if (bad_press <= 10)
 {
  type = (type < 50) ? 0 : 1;
  memcpy(s->comment + offset, "Customer ", 9);
  if (type == 0)
   memcpy(s->comment + 9 + offset + noise,
          "Complaints", 10);
  else
   memcpy(s->comment + 9 + offset + noise,
          "Recommends", 10);
 }
 return (0);
}

variable_types: struct supplier_t { long long suppkey; char name[-1]; char address[-1]; int alen; long long nation_code; char phone[-1]; long long acctbal; char comment[-1]; int clen; } *

variable_types:
i
long long

variable_types:
noise
long long

variable_types:
offset
long long

variable_types:
type
long long


variable_types:
index
long long

variable_types: struct dss_time_t { long long timekey; char alpha[13]; long year; long month; long week; long day; } *

variable_types: m long

variable_types: y long

variable_types: d long


original_code:
int
mk_nation(long long int index, code_t * c)
{
 c->code = index - 1;
 c->text = nations.list[index - 1].text;
 c->join = nations.list[index - 1].weight;
 dbg_text(c->comment, (int)(72 * 0.4),(int)(72 * 1.6), 41);
 c->clen = (int)strlen(c->comment);
 return (0);
}

canonical_original_code:
int mk_nation(long long index, struct code_t *c)
{
 c->code = index - 1;
 c->text = nations.list[index - 1].text;
 c->join = nations.list[index - 1].weight;
 dbg_text(c->comment, (int)(72 * 0.4),(int)(72 * 1.6), 41);
 c->clen = (int)strlen(c->comment);
 return (0);
}

variable_types: struct code_t { long long code; char *text; long join; char comment[-1]; int clen; } *

return_type: int


original_code:
int
mk_region(long long int index, code_t * c)
{
 c->code = index - 1;
 c->text = regions.list[index - 1].text;
 c->join = 0;
 dbg_text(c->comment, (int)(72 * 0.4),(int)(72 * 1.6), 42);
 c->clen = (int)strlen(c->comment);
 return (0);
}

canonical_original_code:
int mk_region(long long index, struct code_t *c)
{
 c->code = index - 1;
 c->text = regions.list[index - 1].text;
 c->join = 0;
 dbg_text(c->comment, (int)(72 * 0.4),(int)(72 * 1.6), 42);
 c->clen = (int)strlen(c->comment);
 return (0);
}

user_defined_types: struct code_t { long long code; char *text; long join; char comment[-1]; int clen; }


decompiled_code:
char *__fastcall dbg_text(char *a1, int a2, int a3, int a4)
{
int v4; // er12
__int64 v5; // r14
char *v6; // rbp
__int64 v7; // rbx
int v8; // eax
__int64 v9; // r15
__int64 v10; // rbx
char *result; // rax
char *v12; // rdi
__int64 v16; // [rsp+20h] [rbp-158h] BYREF
__int64 v17; // [rsp+28h] [rbp-150h] BYREF
char src[328]; // [rsp+30h] [rbp-148h] BYREF

v4 = bInit_1;
v16 = 0LL;
if ( !bInit_1 )
{
v5 = verbose;
if ( verbose > 0 )
{
fwrite("\nPreloading text ... ", 1uLL, 0x15uLL, stderr);
v5 = verbose;
}
v6 = szTextPool_0;
v7 = 0LL;
while ( 1 )
{
if ( v5 > 0 && v4 < v7 )
{
v4 += 200000;
fprintf(stderr, "%3.0f%%\b\b\b\b", (double)(int)v7 * 100.0 / 314572800.0);
}
v8 = txt_sentence_constprop_0(src);
v9 = v8;
if ( v8 < 0LL )
{
fwrite("Bad sentence formation", 1uLL, 0x16uLL, stderr);
abort();
}
v5 = verbose;
if ( v8 >= (__int64)&unk_12C00000 - v7 )
break;
v7 += v8 + 1LL;
strcpy(v6, src);
v6[v9] = 32;
v6 += v9 + 1;
if ( v7 > (__int64)&unk_12BFFFFF )
goto LABEL_11;
}
v12 = v6;
src[(_QWORD)&unk_12C00000 - v7] = 0;
v6 = &v6[(_QWORD)&unk_12C00000 - v7];
strcpy(v12, src);
LABEL_11:
*v6 = 0;
bInit_1 = 1;
if ( v5 > 0 )
fputc(10, stderr);
}
dss_random(&v17, 0LL, (int)&unk_12C00000 - a3, a4);
dss_random(&v16, a2, a3, a4);
v10 = v16;
result = strncpy(a1, &szTextPool_0[v17], (int)v16);
a1[v10] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1, int a2, int a3, int a4)
{
int v4; // er12
__int64 v5; // r14
char *v6; // rbp
__int64 v7; // rbx
int v8; // eax
__int64 v9; // r15
__int64 v10; // rbx
char *result; // rax
char *v12; // rdi
__int64 v16; // [rsp+20h] [rbp-158h] BYREF
__int64 v17; // [rsp+28h] [rbp-150h] BYREF
char src[328]; // [rsp+30h] [rbp-148h] BYREF

v4 = bInit_1;
v16 = 0LL;
if ( !bInit_1 )
{
v5 = verbose;
if ( verbose > 0 )
{
fwrite("\nPreloading text ... ", 1uLL, 0x15uLL, stderr);
v5 = verbose;
}
v6 = szTextPool_0;
v7 = 0LL;
while ( 1 )
{
if ( v5 > 0 && v4 < v7 )
{
v4 += 200000;
fprintf(stderr, "%3.0f%%\b\b\b\b", (double)(int)v7 * 100.0 / 314572800.0);
}
v8 = func2(src);
v9 = v8;
if ( v8 < 0LL )
{
fwrite("Bad sentence formation", 1uLL, 0x16uLL, stderr);
abort();
}
v5 = verbose;
if ( v8 >= (__int64)&unk_12C00000 - v7 )
break;
v7 += v8 + 1LL;
strcpy(v6, src);
v6[v9] = 32;
v6 += v9 + 1;
if ( v7 > (__int64)&unk_12BFFFFF )
goto LABEL_11;
}
v12 = v6;
src[(_QWORD)&unk_12C00000 - v7] = 0;
v6 = &v6[(_QWORD)&unk_12C00000 - v7];
strcpy(v12, src);
LABEL_11:
*v6 = 0;
bInit_1 = 1;
if ( v5 > 0 )
fputc(10, stderr);
}
dss_random(&v17, 0LL, (int)&unk_12C00000 - a3, a4);
dss_random(&v16, a2, a3, a4);
v10 = v16;
result = strncpy(a1, &szTextPool_0[v17], (int)v16);
a1[v10] = 0;
return result;
}

original_code:
void
dbg_text(char *tgt, int min, int max, int sd)
{
   long long int hgLength = 0,
      hgOffset,
      wordlen = 0,
      s_len,
      needed;
   char sentence[256 + 1],
      *cp;
   static char szTextPool[(300 * 1024 * 1024) + 1];
   static int bInit = 0;
   int nLifeNoise = 0;
   if (!bInit)
   {
      cp = &szTextPool[0];
      if (verbose > 0)
         fprintf(stderr, "\nPreloading text ... ");
      while (wordlen < (300 * 1024 * 1024))
      {
         if ((verbose > 0) && (wordlen > nLifeNoise))
         {
            nLifeNoise += 200000;
            fprintf(stderr, "%3.0f%%\b\b\b\b", (100.0 * wordlen)/(300 * 1024 * 1024));
         }
         s_len = txt_sentence(sentence, 5);
         if ( s_len < 0)
            {fprintf(stderr,"%s", "Bad sentence formation");abort();};
         needed = (300 * 1024 * 1024) - wordlen;
         if (needed >= (s_len + 1))
         {
            strcpy(cp, sentence);
            cp += s_len;
            wordlen += s_len + 1;
            *(cp++) = ' ';
         }
         else
         {
            sentence[needed] = '\0';
            strcpy(cp, sentence);
            wordlen += needed;
            cp += needed;
         }
      }
      *cp = '\0';
      bInit = 1;
      if (verbose > 0)
         fprintf(stderr, "\n");
   }
   dss_random(&hgOffset, 0, (300 * 1024 * 1024) - max, sd);
   dss_random(&hgLength, min, max, sd);
   strncpy(&tgt[0], &szTextPool[hgOffset], (int)hgLength);
   tgt[hgLength] = '\0';
 return;
}

canonical_original_code:
void dbg_text(char *tgt, int min, int max, int sd)
{
   long long hgLength = 0; long long hgOffset; long long wordlen = 0; long long s_len; long long needed;
   char sentence[-1]; char *cp;
   static char szTextPool[-1];
   static int bInit = 0;
   int nLifeNoise = 0;
   if (!bInit)
   {
      cp = &szTextPool[0];
      if (verbose > 0)
         fprintf(stderr, "\nPreloading text ... ");
      while (wordlen < (300 * 1024 * 1024))
      {
         if ((verbose > 0) && (wordlen > nLifeNoise))
         {
            nLifeNoise += 200000;
            fprintf(stderr, "%3.0f%%\b\b\b\b", (100.0 * wordlen)/(300 * 1024 * 1024));
         }
         s_len = txt_sentence(sentence, 5);
         if ( s_len < 0)
            {fprintf(stderr,"%s", "Bad sentence formation");abort();};
         needed = (300 * 1024 * 1024) - wordlen;
         if (needed >= (s_len + 1))
         {
            strcpy(cp, sentence);
            cp += s_len;
            wordlen += s_len + 1;
            *(cp++) = ' ';
         }
         else
         {
            sentence[needed] = '\0';
            strcpy(cp, sentence);
            wordlen += needed;
            cp += needed;
         }
      }
      *cp = '\0';
      bInit = 1;
      if (verbose > 0)
         fprintf(stderr, "\n");
   }
   dss_random(&hgOffset, 0, (300 * 1024 * 1024) - max, sd);
   dss_random(&hgLength, min, max, sd);
   strncpy(&tgt[0], &szTextPool[hgOffset], (int)hgLength);
   tgt[hgLength] = '\0';
 return;
}

variable_types:
tgt
char *

variable_types: min int

variable_types: max int

variable_types: sd int

variable_types:
hgLength
long long

variable_types:
hgOffset
long long

variable_types:
wordlen
long long

variable_types:
needed
long long

variable_types:
sentence
char [-1]

variable_types:
cp
char *

variable_types:
szTextPool
char [-1]

variable_types: nLifeNoise int

return_type: void


repo: dramesh/GTThreads

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

if ( a1 == 27 )
result = swapcontext((ucontext_t *)(current + 24), &sched_context);
return result;
}

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

if ( a1 == 27 )
result = swapcontext((ucontext_t *)(current + 24), &sched_context);
return result;
}

original_code:
static void signal_handler (int sig_id) {
        if (sig_id == 27) {
  swapcontext(&current->tContext, &sched_context);
        }
        else return;
}

canonical_original_code:
static void signal_handler(int sig_id) {
        if (sig_id == 27) {
  swapcontext(&current->tContext, &sched_context);
        }
        else return;
}


schedule

decompiled_code:
__int64 schedule()
{
__int64 result; // rax
__int64 i; // rsi

result = (unsigned int)thread_count;
for ( i = current; thread_count; current = i )
{
if ( *(_DWORD *)(i + 4) != 1 && *(_DWORD *)(i + 8) != 1 )
swapcontext(&sched_context, (const ucontext_t *)(i + 24));
result = (unsigned int)thread_count;
if ( thread_count == 1 && *(_DWORD *)(main_thread + 8) == 1 )
exit(0);
i = first;
if ( current != end )
i = *(_QWORD *)(current + 1000);
}
return result;
}

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

result = (unsigned int)thread_count;
for ( i = current; thread_count; current = i )
{
if ( *(_DWORD *)(i + 4) != 1 && *(_DWORD *)(i + 8) != 1 )
swapcontext(&sched_context, (const ucontext_t *)(i + 24));
result = (unsigned int)thread_count;
if ( thread_count == 1 && *(_DWORD *)(main_thread + 8) == 1 )
exit(0);
i = first;
if ( current != end )
i = *(_QWORD *)(current + 1000);
}
return result;
}

original_code:
static void schedule () {
        while (thread_count != 0) {
                if (current->complete != 1 && current->exited != 1) {
                        swapcontext(&sched_context, &current->tContext);
                }
                if (thread_count == 1 && main_thread->exited == 1) {
                        exit(0);
                }
  if (current == end) {
   current = first;
  } else {
          current = current->next;
  }
         }
}

canonical_original_code:
static void schedule() {
        while (thread_count != 0) {
                if (current->complete != 1 && current->exited != 1) {
                        swapcontext(&sched_context, &current->tContext);
                }
                if (thread_count == 1 && main_thread->exited == 1) {
                        exit(0);
                }
  if (current == end) {
   current = first;
  } else {
          current = current->next;
  }
         }
}


decompiled_code:
int __fastcall gtthread_init(__suseconds_t a1)
{
void *v1; // rax
timeval v2; // xmm0
char *v3; // rax
int result; // eax

if ( getcontext(&sched_context) )
{
puts("Error - Initialization of scheduler context failed");
goto LABEL_8;
}
v1 = malloc(0x9C40uLL);
time_slice.it_value.tv_sec = 0LL;
sched_context.uc_stack.ss_sp = v1;
sched_context.uc_stack.ss_size = 40000LL;
time_slice.it_value.tv_usec = a1;
v2 = (timeval)_mm_load_si128((const __m128i *)&time_slice.it_value);
sched_context.uc_stack.ss_flags = 0;
sched_context.uc_link = 0LL;
preempt.__val[0] = (unsigned __int64)signal_handler;
*((_DWORD *)&preempt + 34) = 268435460;
time_slice.it_interval = v2;
sigemptyset((sigset_t *)(unsigned int)((_DWORD)&preempt + 8));
if ( sigaction(27, (const struct sigaction *)&preempt, 0LL) == -1 )
{
puts("Error - Initialization of signal handler failed");
goto LABEL_8;
}
v3 = (char *)malloc(0x3F0uLL);
*((_QWORD *)v3 + 2) = 0LL;
*(_QWORD *)v3 = 0LL;
*((_DWORD *)v3 + 3) = 0;
*((_QWORD *)v3 + 125) = 0LL;
main_thread = (__int64)v3;
getcontext((ucontext_t *)(v3 + 24));
result = setitimer(ITIMER_PROF, &time_slice, 0LL);
if ( result )
{
puts("Error - Initialization of Timer failed");
LABEL_8:
exit(-1);
}
if ( init != 1 )
{
result = main_thread;
++thread_count;
first = main_thread;
current = main_thread;
end = main_thread;
}
init = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(__suseconds_t a1)
{
void *v1; // rax
timeval v2; // xmm0
char *v3; // rax
int result; // eax

if ( getcontext(&sched_context) )
{
puts("Error - Initialization of scheduler context failed");
goto LABEL_8;
}
v1 = malloc(0x9C40uLL);
time_slice.it_value.tv_sec = 0LL;
sched_context.uc_stack.ss_sp = v1;
sched_context.uc_stack.ss_size = 40000LL;
time_slice.it_value.tv_usec = a1;
v2 = (timeval)_mm_load_si128((const __m128i *)&time_slice.it_value);
sched_context.uc_stack.ss_flags = 0;
sched_context.uc_link = 0LL;
preempt.__val[0] = (unsigned __int64)signal_handler;
*((_DWORD *)&preempt + 34) = 268435460;
time_slice.it_interval = v2;
sigemptyset((sigset_t *)(unsigned int)((_DWORD)&preempt + 8));
if ( sigaction(27, (const struct sigaction *)&preempt, 0LL) == -1 )
{
puts("Error - Initialization of signal handler failed");
goto LABEL_8;
}
v3 = (char *)malloc(0x3F0uLL);
*((_QWORD *)v3 + 2) = 0LL;
*(_QWORD *)v3 = 0LL;
*((_DWORD *)v3 + 3) = 0;
*((_QWORD *)v3 + 125) = 0LL;
main_thread = (__int64)v3;
getcontext((ucontext_t *)(v3 + 24));
result = setitimer(ITIMER_PROF, &time_slice, 0LL);
if ( result )
{
puts("Error - Initialization of Timer failed");
LABEL_8:
exit(-1);
}
if ( init != 1 )
{
result = main_thread;
++thread_count;
first = main_thread;
current = main_thread;
end = main_thread;
}
init = 1;
return result;
}

original_code:
void gtthread_init (long period) {
 if (getcontext(&sched_context) == 0) {
  sched_context.uc_stack.ss_sp = malloc(40000);
  sched_context.uc_stack.ss_size = 40000;
  sched_context.uc_stack.ss_flags = 0;
  sched_context.uc_link = ((void *)0);
 } else {
  printf("Error - Initialization of scheduler context failed\n");
  exit(-1);
 }
 time_slice.it_value.tv_sec = 0;
 time_slice.it_value.tv_usec = (long) period;
        time_slice.it_interval = time_slice.it_value;
 preempt.__sigaction_handler.sa_handler = signal_handler;
        preempt.sa_flags = 0x10000000 | 4;
        sigemptyset(&preempt.sa_mask);
        if (sigaction(27, &preempt, ((void *)0)) == -1) {
                printf("Error - Initialization of signal handler failed\n");
                exit(-1);
        }
 main_thread = (struct gtthread*) malloc (sizeof(struct gtthread));
 main_thread->tID = 0;
 main_thread->running = 0;
        main_thread->complete = 0;
        main_thread->cancel = 0;
        main_thread->next = ((void *)0);
 getcontext(&main_thread->tContext);
 if (setitimer(ITIMER_PROF, &time_slice, ((void *)0)) != 0) {
         printf("Error - Initialization of Timer failed\n");
  exit(-1);
 }
 if (init != 1) {
  first = main_thread;
  current = main_thread;
  end = main_thread;
         thread_count++;
 }
 init = 1;
        return;
}

canonical_original_code:
void gtthread_init(long period) {
 if (getcontext(&sched_context) == 0) {
  sched_context.uc_stack.ss_sp = malloc(40000);
  sched_context.uc_stack.ss_size = 40000;
  sched_context.uc_stack.ss_flags = 0;
  sched_context.uc_link = ((void *)0);
 } else {
  printf("Error - Initialization of scheduler context failed\n");
  exit(-1);
 }
 time_slice.it_value.tv_sec = 0;
 time_slice.it_value.tv_usec = (long) period;
        time_slice.it_interval = time_slice.it_value;
 preempt.__sigaction_handler.sa_handler = signal_handler;
        preempt.sa_flags = 0x10000000 | 4;
        sigemptyset(&preempt.sa_mask);
        if (sigaction(27, &preempt, ((void *)0)) == -1) {
                printf("Error - Initialization of signal handler failed\n");
                exit(-1);
        }
 main_thread = (struct gtthread *) malloc (sizeof(struct gtthread));
 main_thread->tID = 0;
 main_thread->running = 0;
        main_thread->complete = 0;
        main_thread->cancel = 0;
        main_thread->next = ((void *)0);
 getcontext(&main_thread->tContext);
 if (setitimer(ITIMER_PROF, &time_slice, ((void *)0)) != 0) {
         printf("Error - Initialization of Timer failed\n");
  exit(-1);
 }
 if (init != 1) {
  first = main_thread;
  current = main_thread;
  end = main_thread;
         thread_count++;
 }
 init = 1;
        return;
}

variable_types: period long

user_defined_types: struct gtthread { int running; int complete; int exited; int cancel; unsigned long tID; struct ucontext_t tContext; void *retval; struct gtthread *next; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


decompiled_code:
__int64 __fastcall gtthread_create(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbx
char *v4; // rax
void *v5; // rax
__int64 v6; // rax
__int64 v9; // [rsp+18h] [rbp-10h]

if ( init != 1 )
{
puts("Error - GTThread not initialized");
exit(-1);
}
v3 = thread_num;
*a1 = thread_num;
v4 = (char *)malloc(0x3F0uLL);
*((_QWORD *)v4 + 2) = v3;
*(_QWORD *)v4 = 0LL;
*((_DWORD *)v4 + 3) = 0;
*((_QWORD *)v4 + 125) = 0LL;
v9 = (__int64)v4;
getcontext((ucontext_t *)(v4 + 24));
*(_QWORD *)(v9 + 32) = &sched_context;
v5 = malloc(0x9C40uLL);
*(_QWORD *)(v9 + 56) = 40000LL;
*(_QWORD *)(v9 + 40) = v5;
*(_DWORD *)(v9 + 48) = 0;
if ( !v5 )
return 0xFFFFFFFFLL;
makecontext((ucontext_t *)(v9 + 24), run_thread, 2, a2, a3);
v6 = end;
++thread_count;
end = v9;
*(_QWORD *)(v6 + 1000) = v9;
LODWORD(v6) = thread_num++;
if ( (_DWORD)v6 == 1 )
{
current = v9;
schedule();
}
else
{
swapcontext((ucontext_t *)(current + 24), &sched_context);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbx
char *v4; // rax
void *v5; // rax
__int64 v6; // rax
__int64 v9; // [rsp+18h] [rbp-10h]

if ( init != 1 )
{
puts("Error - GTThread not initialized");
exit(-1);
}
v3 = thread_num;
*a1 = thread_num;
v4 = (char *)malloc(0x3F0uLL);
*((_QWORD *)v4 + 2) = v3;
*(_QWORD *)v4 = 0LL;
*((_DWORD *)v4 + 3) = 0;
*((_QWORD *)v4 + 125) = 0LL;
v9 = (__int64)v4;
getcontext((ucontext_t *)(v4 + 24));
*(_QWORD *)(v9 + 32) = &sched_context;
v5 = malloc(0x9C40uLL);
*(_QWORD *)(v9 + 56) = 40000LL;
*(_QWORD *)(v9 + 40) = v5;
*(_DWORD *)(v9 + 48) = 0;
if ( !v5 )
return 0xFFFFFFFFLL;
makecontext((ucontext_t *)(v9 + 24), run_thread, 2, a2, a3);
v6 = end;
++thread_count;
end = v9;
*(_QWORD *)(v6 + 1000) = v9;
LODWORD(v6) = thread_num++;
if ( (_DWORD)v6 == 1 )
{
current = v9;
func1();
}
else
{
swapcontext((ucontext_t *)(current + 24), &sched_context);
}
return 0LL;
}

original_code:
int gtthread_create (unsigned long int *thread, void *(*start_routine)(void *), void *arg) {
 if (init != 1) {
  printf("Error - GTThread not initialized\n");
  exit(-1);
 }
 *thread = thread_num;
 struct gtthread *new_thread = (struct gtthread*) malloc (sizeof(struct gtthread));
 new_thread->tID = *thread;
 new_thread->running = 0;
 new_thread->complete = 0;
 new_thread->cancel = 0;
 new_thread->next = ((void *)0);
 getcontext(&new_thread->tContext);
 new_thread->tContext.uc_link = &sched_context;
 new_thread->tContext.uc_stack.ss_sp = malloc(40000);
 new_thread->tContext.uc_stack.ss_size = 40000;
 new_thread->tContext.uc_stack.ss_flags = 0;
 if (new_thread->tContext.uc_stack.ss_sp == 0) {
                return -1;
        }
 makecontext(&new_thread->tContext, (void(*)(void)) run_thread, 2, start_routine, arg);
 end->next = new_thread;
 end = new_thread;
        thread_count++;
 if (thread_num++ == 1) {
  current = new_thread;
  schedule();
 } else {
  swapcontext(&current->tContext, &sched_context);
 }
 return 0;
}

canonical_original_code:
int gtthread_create(unsigned long *thread, void *(*start_routine)(void *), void *arg) {
 if (init != 1) {
  printf("Error - GTThread not initialized\n");
  exit(-1);
 }
 *thread = thread_num;
 struct gtthread *new_thread = (struct gtthread*) malloc (sizeof(struct gtthread));
 new_thread->tID = *thread;
 new_thread->running = 0;
 new_thread->complete = 0;
 new_thread->cancel = 0;
 new_thread->next = ((void *)0);
 getcontext(&new_thread->tContext);
 new_thread->tContext.uc_link = &sched_context;
 new_thread->tContext.uc_stack.ss_sp = malloc(40000);
 new_thread->tContext.uc_stack.ss_size = 40000;
 new_thread->tContext.uc_stack.ss_flags = 0;
 if (new_thread->tContext.uc_stack.ss_sp == 0) {
                return -1;
        }
 makecontext(&new_thread->tContext, (void (*)()) run_thread, 2, start_routine, arg);
 end->next = new_thread;
 end = new_thread;
        thread_count++;
 if (thread_num++ == 1) {
  current = new_thread;
  schedule();
 } else {
  swapcontext(&current->tContext, &sched_context);
 }
 return 0;
}

variable_types:
thread
unsigned long *

variable_types:
arg
void *

variable_types: struct gtthread { int running; int complete; int exited; int cancel; unsigned long tID; struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } tContext; void *retval; struct gtthread *next; } *


decompiled_code:
__int64 __fastcall gtthread_cancel(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = first;
if ( !first )
return 0xFFFFFFFFLL;
do
{
if ( *(_QWORD *)(v1 + 16) == a1 && *(_DWORD *)(v1 + 12) != 1 )
{
free(*(void **)(v1 + 40));
*(_DWORD *)v1 = 0;
result = 0LL;
*(_DWORD *)(v1 + 12) = 1;
--thread_count;
return result;
}
v1 = *(_QWORD *)(v1 + 1000);
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = first;
if ( !first )
return 0xFFFFFFFFLL;
do
{
if ( *(_QWORD *)(v1 + 16) == a1 && *(_DWORD *)(v1 + 12) != 1 )
{
free(*(void **)(v1 + 40));
*(_DWORD *)v1 = 0;
result = 0LL;
*(_DWORD *)(v1 + 12) = 1;
--thread_count;
return result;
}
v1 = *(_QWORD *)(v1 + 1000);
}
while ( v1 );
return 0LL;
}

original_code:
int gtthread_cancel(unsigned long int thread) {
 if (first == ((void *)0)) {
  return -1;
 }
 struct gtthread *temp = first;
 for (temp = first; temp != ((void *)0); temp = temp->next) {
  if (temp->tID == thread && temp->cancel != 1) {
   free(temp->tContext.uc_stack.ss_sp);
   temp->running = 0;
   temp->cancel = 1;
          thread_count--;
   break;
  }
 }
        return 0;
}

canonical_original_code:
int gtthread_cancel(unsigned long thread) {
 if (first == ((void *)0)) {
  return -1;
 }
 struct gtthread *temp = first;
 for (temp = first; temp != ((void *)0); temp = temp->next) {
  if (temp->tID == thread && temp->cancel != 1) {
   free(temp->tContext.uc_stack.ss_sp);
   temp->running = 0;
   temp->cancel = 1;
          thread_count--;
   break;
  }
 }
        return 0;
}

variable_types:
thread
unsigned long


decompiled_code:
void __fastcall run_thread(__int64 (__fastcall *a1)(__int64), __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rdi

v2 = current;
*(_DWORD *)current = 1;
v3 = a1(a2);
v4 = current;
*(_QWORD *)(v2 + 992) = v3;
if ( *(_DWORD *)(v4 + 8) )
{
swapcontext((ucontext_t *)(v4 + 24), &sched_context);
}
else
{
*(_DWORD *)(v4 + 4) = 1;
gtthread_cancel(*(_QWORD *)(v4 + 16));
swapcontext((ucontext_t *)(current + 24), &sched_context);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 (__fastcall *a1)(__int64), __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rdi

v2 = current;
*(_DWORD *)current = 1;
v3 = a1(a2);
v4 = current;
*(_QWORD *)(v2 + 992) = v3;
if ( *(_DWORD *)(v4 + 8) )
{
swapcontext((ucontext_t *)(v4 + 24), &sched_context);
}
else
{
*(_DWORD *)(v4 + 4) = 1;
func4(*(_QWORD *)(v4 + 16));
swapcontext((ucontext_t *)(current + 24), &sched_context);
}
}

original_code:
static void run_thread(void *thread_function(), void *arg) {
 current->running = 1;
 current->retval = thread_function(arg);
        if (!current->exited) {
                current->complete = 1;
                gtthread_cancel(current->tID);
        }
        swapcontext(&current->tContext, &sched_context);
        return;
}


original_code:
int gtthread_join(unsigned long int thread, void **status) {
 struct gtthread *temp = first;
 for (temp = first; temp != ((void *)0); temp = temp->next)
                if (temp->tID == thread) break;
 while (temp->exited != 1 && temp->complete != 1 && temp->cancel != 1) {}
        if ((temp->exited || temp->complete || temp->cancel) && status != ((void *)0)) {
                *status = (void *)temp->retval;
                return 0;
        }
        return -1;
}

canonical_original_code:
int gtthread_join(unsigned long thread, void **status) {
 struct gtthread *temp = first;
 for (temp = first; temp != ((void *)0); temp = temp->next)
                if (temp->tID == thread) break;
 while (temp->exited != 1 && temp->complete != 1 && temp->cancel != 1) {}
        if ((temp->exited || temp->complete || temp->cancel) && status != ((void *)0)) {
                *status = (void *)temp->retval;
                return 0;
        }
        return -1;
}

variable_types:
status
void **


decompiled_code:
int __fastcall gtthread_exit(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdi

v1 = current;
*(_QWORD *)(current + 992) = a1;
v2 = main_thread;
*(_DWORD *)(v1 + 8) = 1;
if ( v1 == v2 )
return swapcontext((ucontext_t *)(v2 + 24), &sched_context);
gtthread_cancel(*(_QWORD *)(v1 + 16));
return swapcontext((ucontext_t *)(current + 24), &sched_context);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdi

v1 = current;
*(_QWORD *)(current + 992) = a1;
v2 = main_thread;
*(_DWORD *)(v1 + 8) = 1;
if ( v1 == v2 )
return swapcontext((ucontext_t *)(v2 + 24), &sched_context);
func4(*(_QWORD *)(v1 + 16));
return swapcontext((ucontext_t *)(current + 24), &sched_context);
}

original_code:
void gtthread_exit(void *retval) {
 current->retval = retval;
        current->exited = 1;
        if (current != main_thread) gtthread_cancel(current->tID);
        swapcontext(&current->tContext, &sched_context);
        return;
}

variable_types:
retval
void *


decompiled_code:
int gtthread_yield()
{
getcontext((ucontext_t *)(current + 24));
return setcontext(&sched_context);
}

canonical_decompiled_code:
int func8()
{
getcontext((ucontext_t *)(current + 24));
return setcontext(&sched_context);
}

original_code:
void gtthread_yield(void) {
 int flag = 0;
        getcontext(&current->tContext);
        if (flag == 0) {
                flag = 1;
                setcontext(&sched_context);
        }
}

canonical_original_code:
void gtthread_yield() {
 int flag = 0;
        getcontext(&current->tContext);
        if (flag == 0) {
                flag = 1;
                setcontext(&sched_context);
        }
}

variable_types: flag int


decompiled_code:
_BOOL8 __fastcall gtthread_equal(__int64 a1, __int64 a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1, __int64 a2)
{
return a1 == a2;
}

original_code:
int gtthread_equal(unsigned long int t1, unsigned long int t2) {
 if (t1 == t2) return 1;
        else return 0;
}

canonical_original_code:
int gtthread_equal(unsigned long t1, unsigned long t2) {
 if (t1 == t2) return 1;
        else return 0;
}


decompiled_code:
__int64 gtthread_self()
{
return *(_QWORD *)(current + 16);
}

canonical_decompiled_code:
__int64 func10()
{
return *(_QWORD *)(current + 16);
}

original_code:
unsigned long int gtthread_self(void) {
 return current->tID;
}

canonical_original_code:
unsigned long gtthread_self() {
 return current->tID;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall gtthread_mutex_init(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 == 1LL )
return 0xFFFFFFFFLL;
*a1 = 0LL;
result = 0LL;
a1[1] = -1LL;
return result;
}

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

if ( *a1 == 1LL )
return 0xFFFFFFFFLL;
*a1 = 0LL;
result = 0LL;
a1[1] = -1LL;
return result;
}

original_code:
int gtthread_mutex_init(gtthread_mutex_t *mutex) {
 if (mutex->lock == 1) return -1;
        mutex->lock = 0;
        mutex->owner = -1;
        return 0;
}

canonical_original_code:
int gtthread_mutex_init(struct gtthread_mutex_t *mutex) {
 if (mutex->lock == 1) return -1;
        mutex->lock = 0;
        mutex->owner = -1;
        return 0;
}

variable_types: struct gtthread_mutex_t { long lock; unsigned long owner; } *


decompiled_code:
__int64 __fastcall gtthread_mutex_lock(_QWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = *(_QWORD *)(current + 16);
if ( a1[1] == v1 )
return 0xFFFFFFFFLL;
if ( *a1 )
{
do
{
gtthread_yield();
v1 = *(_QWORD *)(current + 16);
}
while ( *a1 && a1[1] != v1 );
}
a1[1] = v1;
result = 0LL;
*a1 = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = *(_QWORD *)(current + 16);
if ( a1[1] == v1 )
return 0xFFFFFFFFLL;
if ( *a1 )
{
do
{
func8();
v1 = *(_QWORD *)(current + 16);
}
while ( *a1 && a1[1] != v1 );
}
a1[1] = v1;
result = 0LL;
*a1 = 1LL;
return result;
}

original_code:
int gtthread_mutex_lock(gtthread_mutex_t *mutex) {
 if ((mutex->owner) == current->tID) {
                return -1;
        }
        while (mutex->lock != 0 && mutex->owner != current->tID) gtthread_yield();
        mutex->lock = 1;
        mutex->owner = current->tID;
        return 0;
}

canonical_original_code:
int gtthread_mutex_lock(struct gtthread_mutex_t *mutex) {
 if ((mutex->owner) == current->tID) {
                return -1;
        }
        while (mutex->lock != 0 && mutex->owner != current->tID) gtthread_yield();
        mutex->lock = 1;
        mutex->owner = current->tID;
        return 0;
}

user_defined_types: struct gtthread_mutex_t { long lock; unsigned long owner; }


decompiled_code:
__int64 __fastcall gtthread_mutex_unlock(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 != 1LL || a1[1] != *(_QWORD *)(current + 16) )
return 0xFFFFFFFFLL;
*a1 = 0LL;
result = 0LL;
a1[1] = -1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 != 1LL || a1[1] != *(_QWORD *)(current + 16) )
return 0xFFFFFFFFLL;
*a1 = 0LL;
result = 0LL;
a1[1] = -1LL;
return result;
}

original_code:
int gtthread_mutex_unlock(gtthread_mutex_t *mutex) {
 if (mutex->lock == 1 && mutex->owner == current->tID) {
                mutex->lock = 0;
                mutex->owner = -1;
                return 0;
        }
        return -1;
}

canonical_original_code:
int gtthread_mutex_unlock(struct gtthread_mutex_t *mutex) {
 if (mutex->lock == 1 && mutex->owner == current->tID) {
                mutex->lock = 0;
                mutex->owner = -1;
                return 0;
        }
        return -1;
}


decompiled_code:
__int64 __fastcall match_length(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // er8

v2 = *a1;
if ( *a1 != *a2 )
return 0;
v3 = 1LL;
do
{
v4 = v3;
if ( !v2 )
break;
v2 = a1[v3++];
}
while ( v2 == a2[v3 - 1] );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // er8

v2 = *a1;
if ( *a1 != *a2 )
return 0;
v3 = 1LL;
do
{
v4 = v3;
if ( !v2 )
break;
v2 = a1[v3++];
}
while ( v2 == a2[v3 - 1] );
return v4;
}

original_code:
static int match_length(char *s, char *t)
{
  int result = 0;
  while (*s == *t) {
    result ++;
    if (*s == '\0')
      break;
    s++; t++;
  }
  return result;
}

variable_types:
s
char *

variable_types:
t
char *

variable_types: result int


strsave

decompiled_code:
void *__fastcall strsave(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func1(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

original_code:
static char *strsave(char *s)
{
  char *result = (char *) malloc(strlen(s)+1);
  strcpy (result, s);
  return result;
}

variable_types:
result
char *

return_type: char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
int v1; // ebp
const char **v2; // rbx
int v3; // eax
const char **v4; // rax
const char *v5; // rdx

v1 = 0;
v2 = (const char **)&options;
fprintf(stderr, "Usage: %s", a1);
if ( option_count <= 0 )
{
LABEL_9:
fputc(10, stderr);
exit(1);
}
while ( 1 )
{
while ( 1 )
{
v3 = *((_DWORD *)v2 + 2);
if ( v3 != 1 )
break;
fprintf(stderr, " [-%s (%.2f)]", *v2, *(double *)v2[2]);
LABEL_5:
++v1;
v2 += 3;
if ( option_count <= v1 )
goto LABEL_9;
}
if ( v3 != 2 )
{
if ( !v3 )
fprintf(stderr, " [-%s (%d)]", *v2, *(unsigned int *)v2[2]);
goto LABEL_5;
}
v4 = (const char **)v2[2];
v5 = *v2;
++v1;
v2 += 3;
fprintf(stderr, " [-%s (%s)]", v5, *v4);
if ( option_count <= v1 )
goto LABEL_9;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
int v1; // ebp
const char **v2; // rbx
int v3; // eax
const char **v4; // rax
const char *v5; // rdx

v1 = 0;
v2 = (const char **)&options;
fprintf(stderr, "Usage: %s", a1);
if ( option_count <= 0 )
{
LABEL_9:
fputc(10, stderr);
exit(1);
}
while ( 1 )
{
while ( 1 )
{
v3 = *((_DWORD *)v2 + 2);
if ( v3 != 1 )
break;
fprintf(stderr, " [-%s (%.2f)]", *v2, *(double *)v2[2]);
LABEL_5:
++v1;
v2 += 3;
if ( option_count <= v1 )
goto LABEL_9;
}
if ( v3 != 2 )
{
if ( !v3 )
fprintf(stderr, " [-%s (%d)]", *v2, *(unsigned int *)v2[2]);
goto LABEL_5;
}
v4 = (const char **)v2[2];
v5 = *v2;
++v1;
v2 += 3;
fprintf(stderr, " [-%s (%s)]", v5, *v4);
if ( option_count <= v1 )
goto LABEL_9;
}
}

original_code:
void usage(char *prog)
{
  int j;
  fprintf(stderr, "Usage: %s", prog);
  for (j = 0; j < option_count; j++) {
    switch(options[j].type) {
    case INT_OPTION:
      fprintf(stderr, " [-%s (%d)]", options[j].name, *(options[j].valp.i));
      break;
    case DOUBLE_OPTION:
      fprintf(stderr, " [-%s (%.2f)]", options[j].name, *(options[j].valp.d));
      break;
    case STRING_OPTION:
      fprintf(stderr, " [-%s (%s)]", options[j].name, *(options[j].valp.s));
      break;
    }
  }
  fprintf(stderr, "\n");
  exit(1);
}

variable_types:
prog
char *

variable_types: j int


decompiled_code:
__int64 __fastcall find_option(const char *a1, _BYTE *a2)
{
__int64 v2; // rcx
unsigned int v3; // er12
int v4; // er10
int v5; // eax
__int64 v6; // rcx
int v7; // er9
__int64 v8; // r11

if ( option_count <= 0 )
goto LABEL_12;
v2 = 0LL;
v3 = -1;
do
{
while ( 1 )
{
v5 = match_length((char *)options[3 * v2], a2);
if ( v5 <= v7 )
break;
v3 = v6;
v2 = v6 + 1;
v7 = v5;
v4 = 0;
if ( v8 == v2 )
goto LABEL_9;
}
if ( v5 > 0 && v5 == v7 )
v4 = 1;
v2 = v6 + 1;
}
while ( v8 != v2 );
LABEL_9:
if ( !v7 )
{
LABEL_12:
fprintf(stderr, "No match found to option '%s'\n", a2);
goto LABEL_13;
}
if ( v4 )
{
fprintf(stderr, "Ambiguous option: '%s'\n", a2);
LABEL_13:
usage(a1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, _BYTE *a2)
{
__int64 v2; // rcx
unsigned int v3; // er12
int v4; // er10
int v5; // eax
__int64 v6; // rcx
int v7; // er9
__int64 v8; // r11

if ( option_count <= 0 )
goto LABEL_12;
v2 = 0LL;
v3 = -1;
do
{
while ( 1 )
{
v5 = func0((char *)options[3 * v2], a2);
if ( v5 <= v7 )
break;
v3 = v6;
v2 = v6 + 1;
v7 = v5;
v4 = 0;
if ( v8 == v2 )
goto LABEL_9;
}
if ( v5 > 0 && v5 == v7 )
v4 = 1;
v2 = v6 + 1;
}
while ( v8 != v2 );
LABEL_9:
if ( !v7 )
{
LABEL_12:
fprintf(stderr, "No match found to option '%s'\n", a2);
goto LABEL_13;
}
if ( v4 )
{
fprintf(stderr, "Ambiguous option: '%s'\n", a2);
LABEL_13:
func2(a1);
}
return v3;
}

original_code:
static int find_option(char *prog, char *name)
{
  int sofar = -1;
  int sofar_length = 0;
  int i;
  int ambiguous = 0;
  for (i = 0; i < option_count; i++) {
    int length = match_length(options[i].name, name);
    if (length > sofar_length) {
      sofar = i;
      sofar_length = length;
      ambiguous = 0;
    } else if (length > 0 && length == sofar_length) {
      ambiguous = 1;
    }
  }
  if (sofar_length == 0) {
    fprintf(stderr, "No match found to option '%s'\n", name);
    usage(prog);
  } else if (ambiguous) {
    fprintf(stderr, "Ambiguous option: '%s'\n", name);
    usage(prog);
  }
  return sofar;
}

variable_types:
name
char *

variable_types: sofar int

variable_types: i int

variable_types: ambiguous int

variable_types: length int


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

result = 24LL * option_count;
v3 = option_count + 1;
options[result / 8] = a1;
dword_6A8[result / 4] = 0;
qword_6B0[result / 8] = a2;
option_count = v3;
return result;
}

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

result = 24LL * option_count;
v3 = option_count + 1;
options[result / 8] = a1;
dword_6A8[result / 4] = 0;
qword_6B0[result / 8] = a2;
option_count = v3;
return result;
}

original_code:
void add_int_option(char *name, int *var)
{
  options[option_count].name = name;
  options[option_count].type = INT_OPTION;
  options[option_count].valp.i = var;
  option_count++;
}

variable_types:
var
int *


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

result = 24LL * option_count;
v3 = option_count + 1;
options[result / 8] = a1;
dword_6A8[result / 4] = 1;
qword_6B0[result / 8] = a2;
option_count = v3;
return result;
}

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

result = 24LL * option_count;
v3 = option_count + 1;
options[result / 8] = a1;
dword_6A8[result / 4] = 1;
qword_6B0[result / 8] = a2;
option_count = v3;
return result;
}

original_code:
void add_double_option(char *name, double *var)
{
  options[option_count].name = name;
  options[option_count].type = DOUBLE_OPTION;
  options[option_count].valp.d = var;
  option_count++;
}

variable_types:
var
double *


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

result = 24LL * option_count;
v3 = option_count + 1;
options[result / 8] = a1;
dword_6A8[result / 4] = 2;
qword_6B0[result / 8] = a2;
option_count = v3;
return result;
}

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

result = 24LL * option_count;
v3 = option_count + 1;
options[result / 8] = a1;
dword_6A8[result / 4] = 2;
qword_6B0[result / 8] = a2;
option_count = v3;
return result;
}

original_code:
void add_string_option(char *name, char **var)
{
  options[option_count].name = name;
  options[option_count].type = STRING_OPTION;
  options[option_count].valp.s = var;
  option_count++;
}

variable_types:
var
char **


decompiled_code:
__int64 __fastcall parse_options(int a1, const char **a2, __int64 a3)
{
const char *v3; // rbp
unsigned int v7; // er12
int v8; // ebx
const char *v9; // rsi
__int64 v10; // rax
__int64 *v11; // rcx
unsigned int v12; // er8
const char *v14; // rdi
const char *v15; // rdi
__int64 v16; // [rsp+0h] [rbp-58h]
const char **v17; // [rsp+0h] [rbp-58h]
const char **v18; // [rsp+0h] [rbp-58h]
__int64 *v19; // [rsp+8h] [rbp-50h]
float v20; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = *a2;
if ( a1 > 1 )
{
v7 = 0;
v8 = 1;
while ( 1 )
{
while ( 1 )
{
v9 = a2[v8];
if ( *v9 != 45 )
{
if ( a3 )
*(_QWORD *)(a3 + 8LL * (int)v7) = v9;
++v7;
goto LABEL_6;
}
v16 = v8++;
v10 = 3LL * (int)find_option(v3, (_BYTE *)v9 + 1);
if ( a1 <= v8 )
{
fprintf(stderr, "Missing value for option %s\n", options[v10]);
goto LABEL_21;
}
v11 = &options[v10];
v12 = *((_DWORD *)v11 + 2);
if ( v12 != 1 )
break;
v14 = a2[v16 + 1];
v19 = &options[v10];
v17 = &a2[v16 + 1];
if ( (unsigned int)_isoc99_sscanf(v14, "%f", &v20) != 1 )
{
fprintf(stderr, "Can't parse argument '%s' as double\n", *v17);
LABEL_21:
usage(v3);
}
*(double *)v19[2] = v20;
LABEL_6:
if ( a1 <= ++v8 )
return v7;
}
if ( v12 != 2 )
{
if ( v12 )
{
fprintf(stderr, "Internal error. Don't know option type %d\n", v12);
exit(1);
}
v15 = a2[v16 + 1];
v18 = &a2[v16 + 1];
if ( (unsigned int)_isoc99_sscanf(v15, "%d", v11[2]) != 1 )
{
fprintf(stderr, "Can't parse argument '%s' as integer\n", *v18);
goto LABEL_21;
}
goto LABEL_6;
}
++v8;
*(_QWORD *)v11[2] = a2[v16 + 1];
if ( a1 <= v8 )
return v7;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, const char **a2, __int64 a3)
{
const char *v3; // rbp
unsigned int v7; // er12
int v8; // ebx
const char *v9; // rsi
__int64 v10; // rax
__int64 *v11; // rcx
unsigned int v12; // er8
const char *v14; // rdi
const char *v15; // rdi
__int64 v16; // [rsp+0h] [rbp-58h]
const char **v17; // [rsp+0h] [rbp-58h]
const char **v18; // [rsp+0h] [rbp-58h]
__int64 *v19; // [rsp+8h] [rbp-50h]
float v20; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = *a2;
if ( a1 > 1 )
{
v7 = 0;
v8 = 1;
while ( 1 )
{
while ( 1 )
{
v9 = a2[v8];
if ( *v9 != 45 )
{
if ( a3 )
*(_QWORD *)(a3 + 8LL * (int)v7) = v9;
++v7;
goto LABEL_6;
}
v16 = v8++;
v10 = 3LL * (int)func3(v3, (_BYTE *)v9 + 1);
if ( a1 <= v8 )
{
fprintf(stderr, "Missing value for option %s\n", options[v10]);
goto LABEL_21;
}
v11 = &options[v10];
v12 = *((_DWORD *)v11 + 2);
if ( v12 != 1 )
break;
v14 = a2[v16 + 1];
v19 = &options[v10];
v17 = &a2[v16 + 1];
if ( (unsigned int)_isoc99_sscanf(v14, "%f", &v20) != 1 )
{
fprintf(stderr, "Can't parse argument '%s' as double\n", *v17);
LABEL_21:
func2(v3);
}
*(double *)v19[2] = v20;
LABEL_6:
if ( a1 <= ++v8 )
return v7;
}
if ( v12 != 2 )
{
if ( v12 )
{
fprintf(stderr, "Internal error. Don't know option type %d\n", v12);
exit(1);
}
v15 = a2[v16 + 1];
v18 = &a2[v16 + 1];
if ( (unsigned int)_isoc99_sscanf(v15, "%d", v11[2]) != 1 )
{
fprintf(stderr, "Can't parse argument '%s' as integer\n", *v18);
goto LABEL_21;
}
goto LABEL_6;
}
++v8;
*(_QWORD *)v11[2] = a2[v16 + 1];
if ( a1 <= v8 )
return v7;
}
}
return 0;
}

original_code:
int parse_options(int argc, char *argv[], char *otherargs[])
{
  int i, j;
  int ocount = 0;
  float f;
  char *prog = argv[0];
  for (i = 1; i < argc; i++) {
    if (*argv[i] != '-') {
      if (otherargs)
 otherargs[ocount] = argv[i];
      ocount++;
      continue;
    }
    j = find_option(prog, argv[i]+1);
    i++;
    if (i >= argc) {
      fprintf(stderr, "Missing value for option %s\n", options[j].name);
      usage(prog);
    }
    switch(options[j].type) {
    case INT_OPTION:
      if (sscanf(argv[i], "%d", options[j].valp.i) != 1) {
 fprintf(stderr, "Can't parse argument '%s' as integer\n", argv[i]);
 usage(prog);
      }
      break;
    case DOUBLE_OPTION:
      if (sscanf(argv[i], "%f", &f) != 1) {
 fprintf(stderr, "Can't parse argument '%s' as double\n", argv[i]);
 usage(prog);
      }
      *options[j].valp.d = f;
      break;
    case STRING_OPTION:
      *(options[j].valp.s) = argv[i];
      break;
    default:
      fprintf(stderr,
       "Internal error.  Don't know option type %d\n", options[j].type);
      exit(1);
    }
  }
  return ocount;
}

canonical_original_code:
int parse_options(int argc, char *argv[], char *otherargs[])
{
  int i; int j;
  int ocount = 0;
  float f;
  char *prog = argv[0];
  for (i = 1; i < argc; i++) {
    if (*argv[i] != '-') {
      if (otherargs)
 otherargs[ocount] = argv[i];
      ocount++;
      continue;
    }
    j = find_option(prog, argv[i]+1);
    i++;
    if (i >= argc) {
      fprintf(stderr, "Missing value for option %s\n", options[j].name);
      usage(prog);
    }
    switch(options[j].type) {
    case INT_OPTION:
      if (sscanf(argv[i], "%d", options[j].valp.i) != 1) {
 fprintf(stderr, "Can't parse argument '%s' as integer\n", argv[i]);
 usage(prog);
      }
      break;
    case DOUBLE_OPTION:
      if (sscanf(argv[i], "%f", &f) != 1) {
 fprintf(stderr, "Can't parse argument '%s' as double\n", argv[i]);
 usage(prog);
      }
      *options[j].valp.d = f;
      break;
    case STRING_OPTION:
      *(options[j].valp.s) = argv[i];
      break;
    default:
      fprintf(stderr,
       "Internal error.  Don't know option type %d\n", options[j].type);
      exit(1);
    }
  }
  return ocount;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
otherargs
char *[]

variable_types: ocount int

variable_types: f float


freeHashTable

decompiled_code:
void freeHashTable()
{
if ( htable )
{
free(htable);
htable = 0LL;
lcnt = 0;
lstring = 0LL;
mcnt = 0;
mstring = 0LL;
scnt = 0;
tsize = 0;
wcnt = 0;
ucnt = 0;
}
}

canonical_decompiled_code:
void func2()
{
if ( htable )
{
free(htable);
htable = 0LL;
lcnt = 0;
lstring = 0LL;
mcnt = 0;
mstring = 0LL;
scnt = 0;
tsize = 0;
wcnt = 0;
ucnt = 0;
}
}

original_code:
static void freeHashTable(void)
{
    if (htable != 0)
    {
        free(htable);
        htable = 0;
        lcnt = 0;
        lstring = 0;
        mcnt = 0;
        mstring = 0;
        scnt = 0;
        tsize = 0;
        wcnt = 0;
        ucnt = 0;
    }
}

canonical_original_code:
static void freeHashTable()
{
    if (htable != 0)
    {
        free(htable);
        htable = 0;
        lcnt = 0;
        lstring = 0;
        mcnt = 0;
        mstring = 0;
        scnt = 0;
        tsize = 0;
        wcnt = 0;
        ucnt = 0;
    }
}


lowercase

decompiled_code:
size_t __fastcall lowercase(char *a1)
{
size_t result; // rax
__int64 v2; // rcx

result = strlen(a1);
if ( (int)result > 0 )
{
v2 = (__int64)&a1[(unsigned int)(result - 1) + 1];
do
{
result = (unsigned __int8)*a1;
if ( (unsigned __int8)(result - 65) <= 0x19u )
{
result = (unsigned int)(result + 32);
*a1 = result;
}
++a1;
}
while ( a1 != (char *)v2 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(char *a1)
{
size_t result; // rax
__int64 v2; // rcx

result = strlen(a1);
if ( (int)result > 0 )
{
v2 = (__int64)&a1[(unsigned int)(result - 1) + 1];
do
{
result = (unsigned __int8)*a1;
if ( (unsigned __int8)(result - 65) <= 0x19u )
{
result = (unsigned int)(result + 32);
*a1 = result;
}
++a1;
}
while ( a1 != (char *)v2 );
}
return result;
}

original_code:
void lowercase(char *s)
{
  int i;
  int len = strlen(s);
  for (i = 0; i < len; i++)
    {
      if (s[i] >= 'A' && s[i] <= 'Z')
 s[i] -= ('A' - 'a');
    }
}

variable_types:
s
char *

variable_types: len int


decompiled_code:
__int64 __fastcall hash_function(_BYTE *a1)
{
int v1; // edx
unsigned int i; // eax

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i += v1;
}
return i % tsize;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
int v1; // edx
unsigned int i; // eax

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i += v1;
}
return i % tsize;
}

original_code:
unsigned hash_function(char *s)
{
  unsigned val = 0;
  int c;
  c = *s;
  while(c != '\0')
    {
      val = val + c;
      s++;
      c = *s;
    }
  return val % tsize;
}

canonical_original_code:
unsigned int hash_function(char *s)
{
  unsigned int val = 0;
  int c;
  c = *s;
  while(c != '\0')
    {
      val = val + c;
      s++;
      c = *s;
    }
  return val % tsize;
}

variable_types:
val
unsigned int

variable_types: c int

return_type: unsigned int


decompiled_code:
void *__fastcall save_string(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
if ( !v2 )
{
fwrite("Couldn't allocate space for string, exiting\n", 1uLL, 0x2CuLL, stderr);
exit(1);
}
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func6(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
if ( !v2 )
{
fwrite("Couldn't allocate space for string, exiting\n", 1uLL, 0x2CuLL, stderr);
exit(1);
}
return memcpy(v2, src, v1);
}

original_code:
char *save_string(char *s)
{
  char *result = (char *) malloc(strlen(s)+1);
  if (!result)
    {
      fprintf(stderr, "Couldn't allocate space for string, exiting\n");
      exit(1);
    }
  strcpy(result,s);
  return result;
}

variable_types:
result
char *


decompiled_code:
char *get_word()
{
char *result; // rax

do
{
if ( bufvalid )
{
result = strtok(0LL, " \t\n\r.,:;/<>()[]{}?!\"-'");
if ( result )
break;
}
result = fgets(buf, 1024, infile);
if ( !result )
return result;
bufvalid = 1;
result = strtok(buf, " \t\n\r.,:;/<>()[]{}?!\"-'");
}
while ( !result );
++wcnt;
return result;
}

canonical_decompiled_code:
char *func9()
{
char *result; // rax

do
{
if ( bufvalid )
{
result = strtok(0LL, " \t\n\r.,:;/<>()[]{}?!\"-'");
if ( result )
break;
}
result = fgets(buf, 1024, infile);
if ( !result )
return result;
bufvalid = 1;
result = strtok(buf, " \t\n\r.,:;/<>()[]{}?!\"-'");
}
while ( !result );
++wcnt;
return result;
}

original_code:
char *get_word()
{
    char *s = ((void *)0);
    while (1) {
 if (bufvalid) {
     s = strtok(((void *)0), skipchar);
     if (s)
  break;
 }
 if (!fgets(buf, 1024, infile))
     return ((void *)0);
 bufvalid = 1;
 s = strtok(buf, skipchar);
 if (s)
     break;
    }
    wcnt++;
    return s;
}


original_code:
char *get_token(int ngram)
{
    static char token_buf[10][1024];
    static int first = 1;
    static int bindex = 0;
    static char sbuf[1024];
    char *nextpos = sbuf;
    int i; int index;
    if (ngram == 1)
 return get_word();
    if (first) {
 while (bindex < ngram-1) {
     char *word = get_word();
     if (!word) {
  return ((void *)0);
     }
     strcpy(token_buf[bindex++], word);
 }
 first = 0;
    }
    char *word = get_word();
    if (!word) {
 return ((void *)0);
    }
    strcpy (token_buf[bindex++], word);
    if (bindex >= 10)
 bindex = 0;
    index = bindex - ngram;
    if (index < 0)
 index += 10;
    for (i = 0; i < ngram; i++) {
 if (i != 0)
     *nextpos++ = ' ';
 word = token_buf[index];
 strcpy(nextpos, word);
 nextpos += strlen(word);
 index++;
 if (index >= 10)
     index = 0;
    }
    return sbuf;
}

variable_types: ngram int

variable_types: first int

variable_types: bindex int

variable_types:
sbuf
char [1024]

variable_types:
nextpos
char *

variable_types: index int

variable_types:
word
char *


fileOpen

repo: drencrom/context

decompiled_code:
__int64 __fastcall fileOpen(const char *a1, __off_t *a2, char a3)
{
int v3; // eax
unsigned int v4; // er12
__int64 v6; // rcx
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v3 = open(a1, 2 * (a3 != 0));
v4 = v3;
if ( v3 == -1 )
{
fprintf(stderr, "fileOpen: Cannot open \"%s\"", a1);
}
else if ( fstat(v3, &v7) == -1 )
{
v6 = v4;
v4 = -2;
fprintf(stderr, "file \"%s\": fstat(fd = %d) failed", a1, v6);
}
else
{
*a2 = v7.st_size;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __off_t *a2, char a3)
{
int v3; // eax
unsigned int v4; // er12
__int64 v6; // rcx
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v3 = open(a1, 2 * (a3 != 0));
v4 = v3;
if ( v3 == -1 )
{
fprintf(stderr, "fileOpen: Cannot open \"%s\"", a1);
}
else if ( fstat(v3, &v7) == -1 )
{
v6 = v4;
v4 = -2;
fprintf(stderr, "file \"%s\": fstat(fd = %d) failed", a1, v6);
}
else
{
*a2 = v7.st_size;
}
return v4;
}

original_code:
static int fileOpen(char *name, Uint *textlen, unsigned char writefile)
{
  int fd;
  struct stat buf;
  if((fd = open(name,(writefile) ? 02 : 00)) == -1)
  {
     fprintf(stderr,"fileOpen: Cannot open \"%s\"",name);
     return -1;
  }
  if(fstat(fd,&buf) == -1)
  {
     fprintf(stderr, "file \"%s\": fstat(fd = %d) failed",name,fd);
     return -2;
  }
  *textlen = (Uint) buf.st_size;
  return fd;
}

canonical_original_code:
static int fileOpen(char *name, unsigned long *textlen, unsigned char writefile)
{
  int fd;
  struct stat buf;
  if((fd = open(name,(writefile) ? 02 : 00)) == -1)
  {
     fprintf(stderr,"fileOpen: Cannot open \"%s\"",name);
     return -1;
  }
  if(fstat(fd,&buf) == -1)
  {
     fprintf(stderr, "file \"%s\": fstat(fd = %d) failed",name,fd);
     return -2;
  }
  *textlen = (unsigned long) buf.st_size;
  return fd;
}

variable_types:
name
char *

variable_types:
textlen
unsigned long *

variable_types:
writefile
unsigned char

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


freetextspace

decompiled_code:
int __fastcall freetextspace(void *a1, size_t a2)
{
int result; // eax

result = munmap(a1, a2);
if ( result == -1 )
result = fwrite("Unable to unmap file", 1uLL, 0x14uLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func3(void *a1, size_t a2)
{
int result; // eax

result = munmap(a1, a2);
if ( result == -1 )
result = fwrite("Unable to unmap file", 1uLL, 0x14uLL, stderr);
return result;
}

original_code:
void freetextspace(Uchar *text, Uint textlen) {
  if (munmap((void *) text, (size_t) textlen) == -1) {
    fprintf(stderr, "Unable to unmap file");
  }
}

canonical_original_code:
void freetextspace(unsigned char *text, unsigned long textlen) {
  if (munmap((void *) text, (unsigned long) textlen) == -1) {
    fprintf(stderr, "Unable to unmap file");
  }
}

variable_types:
text
unsigned char *

variable_types:
textlen
unsigned long


decompiled_code:
// attributes: thunk
void *__fastcall file2String(const char *a1, __off_t *a2)
{
return genfile2String_constprop_0(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func4(const char *a1, __off_t *a2)
{
return func2(a1, a2);
}

original_code:
void * file2String(char *name, Uint *textlen) {
  return genfile2String(name, textlen, ((unsigned char) 0), ((unsigned char) 0));
}

canonical_original_code:
void *file2String(char *name, unsigned long *textlen) {
  return genfile2String(name, textlen, ((unsigned char) 0), ((unsigned char) 0));
}

return_type: void *


allocStatistics

decompiled_code:
_QWORD *allocStatistics()
{
_QWORD *v0; // rax
size_t v1; // rbx
_QWORD *v2; // r12
void *v3; // rax
void *v4; // rax
__int64 v6; // r8
__int64 v7; // rcx

v0 = calloc(0x20uLL, 1uLL);
if ( !v0 )
{
fprintf(stderr, "file %s, line %lu: calloc(%lu) failed\n", "statistics.c", 32LL, 32LL);
exit(1);
}
v1 = alphasize;
v2 = v0;
v3 = calloc(8uLL, alphasize);
*v2 = v3;
if ( !v3 )
{
v6 = 8 * v1;
v7 = 33LL;
LABEL_7:
fprintf(stderr, "file %s, line %lu: calloc(%lu) failed\n", "statistics.c", v7, v6);
exit(1);
}
v4 = calloc(1uLL, v1);
v2[1] = v4;
if ( !v4 )
{
v6 = v1;
v7 = 34LL;
goto LABEL_7;
}
return v2;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
size_t v1; // rbx
_QWORD *v2; // r12
void *v3; // rax
void *v4; // rax
__int64 v6; // r8
__int64 v7; // rcx

v0 = calloc(0x20uLL, 1uLL);
if ( !v0 )
{
fprintf(stderr, "file %s, line %lu: calloc(%lu) failed\n", "statistics.c", 32LL, 32LL);
exit(1);
}
v1 = alphasize;
v2 = v0;
v3 = calloc(8uLL, alphasize);
*v2 = v3;
if ( !v3 )
{
v6 = 8 * v1;
v7 = 33LL;
LABEL_7:
fprintf(stderr, "file %s, line %lu: calloc(%lu) failed\n", "statistics.c", v7, v6);
exit(1);
}
v4 = calloc(1uLL, v1);
v2[1] = v4;
if ( !v4 )
{
v6 = v1;
v7 = 34LL;
goto LABEL_7;
}
return v2;
}

original_code:
statistics_t allocStatistics() {
  statistics_t st;
  st = calloc(sizeof(struct statistics), 1); if ((st) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n", "statistics.c",(Showuint) 32, (Showuint) (sizeof(struct statistics) * (size_t) (1))); exit(1); };
  st->count = calloc(sizeof(Uint), alphasize); if ((st->count) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n", "statistics.c",(Showuint) 33, (Showuint) (sizeof(Uint) * (size_t) (alphasize))); exit(1); };
  st->symbols = calloc(sizeof(Uchar), alphasize); if ((st->symbols) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n", "statistics.c",(Showuint) 34, (Showuint) (sizeof(Uchar) * (size_t) (alphasize))); exit(1); };
  return st;
}

canonical_original_code:
struct statistics *allocStatistics() {
  struct statistics *st;
  st = calloc(sizeof(struct statistics), 1); if ((st) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n", "statistics.c",(unsigned long) 32, (Showuint) (sizeof(struct statistics) * (unsigned long) (1))); exit(1); };
  st->count = calloc(sizeof(Uint), alphasize); if ((st->count) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n", "statistics.c",(unsigned long) 33, (Showuint) (sizeof(Uint) * (unsigned long) (alphasize))); exit(1); };
  st->symbols = calloc(sizeof(Uchar), alphasize); if ((st->symbols) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n", "statistics.c",(unsigned long) 34, (Showuint) (sizeof(Uchar) * (unsigned long) (alphasize))); exit(1); };
  return st;
}

variable_types: struct statistics { unsigned long *count; unsigned char *symbols; unsigned long symbolCount; double cost; } *


freeStatistics

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

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

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

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void freeStatistics(statistics_t st) {
  if((st->count) != ((void *)0)) { free(st->count); st->count = ((void *)0); };
  if((st->symbols) != ((void *)0)) { free(st->symbols); st->symbols = ((void *)0); };
  if((st) != ((void *)0)) { free(st); st = ((void *)0); };
}

canonical_original_code:
void freeStatistics(struct statistics *st) {
  if((st->count) != ((void *)0)) { free(st->count); st->count = ((void *)0); };
  if((st->symbols) != ((void *)0)) { free(st->symbols); st->symbols = ((void *)0); };
  if((st) != ((void *)0)) { free(st); st = ((void *)0); };
}

user_defined_types: struct statistics { unsigned long *count; unsigned char *symbols; unsigned long symbolCount; double cost; }


getStatistics

decompiled_code:
_QWORD *getStatistics()
{
if ( !stacktop )
return allocStatistics();
--stacktop;
return (_QWORD *)*((_QWORD *)stack + stacktop);
}

canonical_decompiled_code:
_QWORD *func2()
{
if ( !stacktop )
return func0();
--stacktop;
return (_QWORD *)*((_QWORD *)stack + stacktop);
}

original_code:
statistics_t getStatistics() {
  Uint statsPtr;
  if ((stacktop > 0)) {
    statsPtr = stack[--stacktop];
    return (statistics_t)statsPtr;
  }
  else {
    return allocStatistics();
  }
}

canonical_original_code:
struct statistics *getStatistics() {
  unsigned long statsPtr;
  if ((stacktop > 0)) {
    statsPtr = stack[--stacktop];
    return (struct statistics *)statsPtr;
  }
  else {
    return allocStatistics();
  }
}

variable_types:
statsPtr
unsigned long

return_type: struct statistics { unsigned long *count; unsigned char *symbols; unsigned long symbolCount; double cost; } *


returnStatistics

decompiled_code:
unsigned __int64 __fastcall returnStatistics(__int64 a1)
{
unsigned __int64 v2; // rbp
unsigned __int64 v3; // r8
_QWORD *v4; // rdi
unsigned __int64 result; // rax
__int64 v6; // r8
__int64 v7; // r12

memset(*(void **)a1, 0, 8 * alphasize);
memset(*(void **)(a1 + 8), 0, alphasize);
v2 = stacktop;
v3 = stackalloc;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
v4 = stack;
if ( v2 >= v3 )
{
v6 = v3 + 100;
v7 = 8 * v6;
stackalloc = v6;
stack = realloc(stack, 8 * v6);
v4 = stack;
if ( !stack )
{
fprintf(stderr, "file %s, line %lu: realloc(%lu) failed\n", "statistics.c", 71LL, v7);
exit(1);
}
}
else if ( !stack )
{
_assert_fail("stack != NULL", "statistics.c", 0x47u, "returnStatistics");
}
result = v2 + 1;
v4[v2] = a1;
stacktop = v2 + 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v2; // rbp
unsigned __int64 v3; // r8
_QWORD *v4; // rdi
unsigned __int64 result; // rax
__int64 v6; // r8
__int64 v7; // r12

memset(*(void **)a1, 0, 8 * alphasize);
memset(*(void **)(a1 + 8), 0, alphasize);
v2 = stacktop;
v3 = stackalloc;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
v4 = stack;
if ( v2 >= v3 )
{
v6 = v3 + 100;
v7 = 8 * v6;
stackalloc = v6;
stack = realloc(stack, 8 * v6);
v4 = stack;
if ( !stack )
{
fprintf(stderr, "file %s, line %lu: realloc(%lu) failed\n", "statistics.c", 71LL, v7);
exit(1);
}
}
else if ( !stack )
{
_assert_fail("stack != NULL", "statistics.c", 0x47u, "returnStatistics");
}
result = v2 + 1;
v4[v2] = a1;
stacktop = v2 + 1;
return result;
}

original_code:
void returnStatistics(statistics_t st) {
  memset(st->count, 0, alphasize * sizeof(Uint));
  memset(st->symbols, 0, alphasize * sizeof(Uchar));
  st->symbolCount = 0;
  st->cost = 0;
  if(stacktop >= stackalloc) { stackalloc += 100; stack = (Uint *) realloc(stack,sizeof(Uint) * (size_t) (stackalloc)); if((stack) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: realloc(%lu) failed\n", "statistics.c",(Showuint) 71, (Showuint) (sizeof(Uint) * (size_t) (stackalloc))); exit(1); }; } ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "statistics.c", 71, __extension__ __PRETTY_FUNCTION__)); stack[stacktop++] = (Uint)st;
}

canonical_original_code:
void returnStatistics(struct statistics *st) {
  memset(st->count, 0, alphasize * sizeof(Uint));
  memset(st->symbols, 0, alphasize * sizeof(Uchar));
  st->symbolCount = 0;
  st->cost = 0;
  if(stacktop >= stackalloc) { stackalloc += 100; stack = (unsigned long *) realloc(stack,sizeof(Uint) * (unsigned long) (stackalloc)); if((stack) == ((void *)0)) { fprintf(stderr,"file %s, line %lu: realloc(%lu) failed\n", "statistics.c",(unsigned long) 71, (Showuint) (sizeof(Uint) * (unsigned long) (stackalloc))); exit(1); }; } ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "statistics.c", 71, __extension__ __PRETTY_FUNCTION__)); stack[stacktop++] = (unsigned long)st;
}


freeBuffer

decompiled_code:
void freeBuffer()
{
__int64 v0; // rbx
_QWORD *v1; // rbp
void *v2; // rdi

v0 = stacktop;
v1 = stack;
if ( stacktop )
{
do
{
v2 = (void *)v1[--v0];
stacktop = v0;
freeStatistics(v2);
}
while ( v0 );
}
else if ( !stack )
{
goto LABEL_4;
}
free(v1);
stack = 0LL;
LABEL_4:
stackalloc = 0LL;
stacktop = 0LL;
}

canonical_decompiled_code:
void func4()
{
__int64 v0; // rbx
_QWORD *v1; // rbp
void *v2; // rdi

v0 = stacktop;
v1 = stack;
if ( stacktop )
{
do
{
v2 = (void *)v1[--v0];
stacktop = v0;
func1(v2);
}
while ( v0 );
}
else if ( !stack )
{
goto LABEL_4;
}
free(v1);
stack = 0LL;
LABEL_4:
stackalloc = 0LL;
stacktop = 0LL;
}

original_code:
void freeBuffer() {
  Uint statsPtr;
  while ((stacktop > 0)) {
    statsPtr = stack[--stacktop];
    freeStatistics((statistics_t)statsPtr);
  }
  if((stack) != ((void *)0)) { free(stack); stack = ((void *)0); };
  stacktop = stackalloc = 0;
}

canonical_original_code:
void freeBuffer() {
  unsigned long statsPtr;
  while ((stacktop > 0)) {
    statsPtr = stack[--stacktop];
    freeStatistics((struct statistics *)statsPtr);
  }
  if((stack) != ((void *)0)) { free(stack); stack = ((void *)0); };
  stacktop = stackalloc = 0;
}


original_code:
void reverseString2Binary(Uchar *s, Uint len, Uchar *sreverse, Uint revLength) {
  char ch;
  int pos, i;
  for(pos = 0, sreverse += revLength-1; pos != len; s++, pos++){
    ch = *s;
    for (i = 0; i < 8; i++) {
      *sreverse-- = ((ch & 0x80) >> 7 ? '1' : '0');
      ch = ch << 1;
    }
  }
}

canonical_original_code:
void reverseString2Binary(unsigned char *s, unsigned long len, unsigned char *sreverse, unsigned long revLength) {
  char ch;
  int pos; int i;
  for(pos = 0, sreverse += revLength-1; pos != len; s++, pos++){
    ch = *s;
    for (i = 0; i < 8; i++) {
      *sreverse-- = ((ch & 0x80) >> 7 ? '1' : '0');
      ch = ch << 1;
    }
  }
}

variable_types:
s
unsigned char *

variable_types:
len
unsigned long

variable_types:
sreverse
unsigned char *

variable_types:
revLength
unsigned long

variable_types: ch char

variable_types: pos int

variable_types: i int


decompiled_code:
void initialize_output_bitstream()
{
current_byte = (__int64)&buffer;
buffer = 0;
output_mask = 128;
}

canonical_decompiled_code:
void func0()
{
current_byte = (__int64)&buffer;
buffer = 0;
output_mask = 128;
}

original_code:
void initialize_output_bitstream()
{
    current_byte = buffer;
    *current_byte = 0;
    output_mask = 0x80;
}


decompiled_code:
void initialize_input_bitstream()
{
input_bits_left = 0;
input_bytes_left = 1;
past_eof = 0;
}

canonical_decompiled_code:
void func3()
{
input_bits_left = 0;
input_bytes_left = 1;
past_eof = 0;
}


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

result = 0LL;
if ( a1 )
{
result = 1LL;
if ( a1 != 1 )
{
if ( a1 == 2 )
{
result = 2LL;
}
else
{
result = 3LL;
if ( a1 > 4 )
{
result = 4LL;
if ( (-(__int64)(a2 < 0x96) & 0xFFFFFFFFFFFFFFFELL) + 8 < a1 )
{
result = 5LL;
if ( a1 > 9 )
result = (unsigned int)((-(__int64)(a2 < 0x96) & 0xFFFFFFFFFFFFFFF6LL) + 25 < a1) + 6;
}
}
}
}
}
return result;
}

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

result = 0LL;
if ( a1 )
{
result = 1LL;
if ( a1 != 1 )
{
if ( a1 == 2 )
{
result = 2LL;
}
else
{
result = 3LL;
if ( a1 > 4 )
{
result = 4LL;
if ( (-(__int64)(a2 < 0x96) & 0xFFFFFFFFFFFFFFFELL) + 8 < a1 )
{
result = 5LL;
if ( a1 > 9 )
result = (unsigned int)((-(__int64)(a2 < 0x96) & 0xFFFFFFFFFFFFFFF6LL) + 25 < a1) + 6;
}
}
}
}
}
return result;
}

original_code:
static int get3ByteRepresentation (const Uint num, const Uint alphasize) {
  if (num <= 0) return 0;
  else if (num <= 1) return 1;
  else if (num <= 2) return 2;
  else if (num <= 4) return 3;
  else if (num <= (alphasize >= 150 ? 8 : 6)) return 4;
  else if (num <= 9) return 5;
  else if (num <= (alphasize >= 150 ? 25 : 15)) return 6;
  else return 7;
}

canonical_original_code:
static int get3ByteRepresentation(unsigned long num, unsigned long alphasize) {
  if (num <= 0) return 0;
  else if (num <= 1) return 1;
  else if (num <= 2) return 2;
  else if (num <= 4) return 3;
  else if (num <= (alphasize >= 150 ? 8 : 6)) return 4;
  else if (num <= 9) return 5;
  else if (num <= (alphasize >= 150 ? 25 : 15)) return 6;
  else return 7;
}

variable_types:
num
unsigned long

variable_types:
alphasize
unsigned long


getSeeStateEncoder

decompiled_code:
__int64 __fastcall getSeeStateEncoder(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4, __int64 a5, unsigned __int64 a6)
{
__int64 v8; // rbx
unsigned __int64 v9; // rdi
unsigned __int64 v11; // r11
int v12; // ebp
unsigned __int64 v13; // r10
int v14; // eax
int v15; // ecx
int v16; // ebp
unsigned __int64 v17; // r9
__int64 v18; // r12
char v19; // al
unsigned __int64 v20; // rdx
int v21; // eax
int v22; // eax
unsigned int v23; // ebp
int v24; // eax
__int64 result; // rax

if ( (-(__int64)(a6 < 0x96) & 0xFFFFFFFFFFFFFF9ELL) + 128 <= a2 )
return 0xFFFFFFFFLL;
v8 = a1;
v9 = *(_QWORD *)(a1 + 40) - a2;
get3ByteRepresentation(v9, a6);
v12 = get3ByteRepresentation(v11, a6);
v14 = get3ByteRepresentation(v13, a6);
v16 = (8 * (v15 | v12)) | v14;
if ( v17 <= 0x95 )
{
v18 = *(_QWORD *)(v8 + 32);
while ( 1 )
{
v19 = isRootFsmTree(v8);
v20 = *(_QWORD *)(v8 + 32);
if ( v19 || v20 != v18 )
break;
v8 = *(_QWORD *)(*(_QWORD *)(v8 + 72) + 64LL);
}
v21 = 4 * v16;
v16 = v20 | (4 * v16);
v22 = v21 | 3;
if ( v20 >= 4 )
v16 = v22;
}
v23 = 8 * v16;
if ( a3 && (v24 = *(unsigned __int8 *)(a5 + a3 - 1), (_BYTE)v24) )
result = (int)(log((double)v24) + 0.5) | v23;
else
result = v23;
return result;
}

original_code:
int getSeeStateEncoder (fsmTree_t tree, Uint allCount, Uint pos, Uint numMasked, const Uchar * text, Uint alphasize) {
  Uint state, syms;
  if (allCount >= (alphasize >= 150 ? 128 : 30)) {
    return -1;
  }
  state = get3ByteRepresentation(tree->totalCount - allCount, alphasize);
  state <<= 3;
  state |= get3ByteRepresentation(allCount, alphasize);
  state <<= 3;
  state |= get3ByteRepresentation(numMasked, alphasize);
  syms = tree->totalSyms;
  if (alphasize < 150) {
    while (!isRootFsmTree(tree) && tree->totalSyms == syms) {
      tree = tree->parent->origin;
    }
    state <<=2;
    if (tree->totalSyms > 3) {
      state |= 3;
    }
    else {
      state |= tree->totalSyms;
    }
  }
  state <<=3;
  if ((pos > 0) && (text[pos-1] > 0)) {
    state |= (int)(log(text[pos-1])+0.5);
  }
  return state;
}

canonical_original_code:
int getSeeStateEncoder(struct fsmTree *tree, unsigned long allCount, unsigned long pos, unsigned long numMasked, unsigned char *text, unsigned long alphasize) {
  unsigned long state; unsigned long syms;
  if (allCount >= (alphasize >= 150 ? 128 : 30)) {
    return -1;
  }
  state = get3ByteRepresentation(tree->totalCount - allCount, alphasize);
  state <<= 3;
  state |= get3ByteRepresentation(allCount, alphasize);
  state <<= 3;
  state |= get3ByteRepresentation(numMasked, alphasize);
  syms = tree->totalSyms;
  if (alphasize < 150) {
    while (!isRootFsmTree(tree) && tree->totalSyms == syms) {
      tree = tree->parent->origin;
    }
    state <<=2;
    if (tree->totalSyms > 3) {
      state |= 3;
    }
    else {
      state |= tree->totalSyms;
    }
  }
  state <<=3;
  if ((pos > 0) && (text[pos-1] > 0)) {
    state |= (int)(log(text[pos-1])+0.5);
  }
  return state;
}

variable_types: struct fsmTree { unsigned long left; unsigned char *symbols; struct fsmTree *tail; unsigned char *traversed; struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } nodeStack; } *

variable_types:
allCount
unsigned long

variable_types:
pos
unsigned long

variable_types:
numMasked
unsigned long

variable_types:
state
unsigned long

variable_types:
syms
unsigned long

user_defined_types: struct fsmTree { unsigned long left; unsigned char *symbols; struct fsmTree *tail; unsigned char *traversed; struct obstack nodeStack; }

user_defined_types: struct obstack { long chunk_size; struct _obstack_chunk *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; }


getSeeStateDecoder

decompiled_code:
__int64 __fastcall getSeeStateDecoder(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4, __int64 a5, unsigned __int64 a6)
{
__int64 v8; // rbx
unsigned __int64 v9; // rdi
unsigned __int64 v11; // r11
int v12; // ebp
unsigned __int64 v13; // r10
int v14; // eax
int v15; // ecx
int v16; // ebp
unsigned __int64 v17; // r9
__int64 v18; // r12
char v19; // al
unsigned __int64 v20; // rdx
int v21; // eax
int v22; // eax
unsigned int v23; // ebp
int v24; // eax
__int64 result; // rax

if ( (-(__int64)(a6 < 0x96) & 0xFFFFFFFFFFFFFF9ELL) + 128 <= a2 )
return 0xFFFFFFFFLL;
v8 = a1;
v9 = *(_QWORD *)(a1 + 32) - a2;
get3ByteRepresentation(v9, a6);
v12 = get3ByteRepresentation(v11, a6);
v14 = get3ByteRepresentation(v13, a6);
v16 = (8 * (v15 | v12)) | v14;
if ( v17 <= 0x95 )
{
v18 = *(_QWORD *)(v8 + 24);
while ( 1 )
{
v19 = isRootDecoderTree(v8);
v20 = *(_QWORD *)(v8 + 24);
if ( v19 || v20 != v18 )
break;
v8 = *(_QWORD *)(*(_QWORD *)(v8 + 56) + 48LL);
}
v21 = 4 * v16;
v16 = v20 | (4 * v16);
v22 = v21 | 3;
if ( v20 >= 4 )
v16 = v22;
}
v23 = 8 * v16;
if ( a3 && (v24 = *(unsigned __int8 *)(a5 + a3 - 1), (_BYTE)v24) )
result = (int)(log((double)v24) + 0.5) | v23;
else
result = v23;
return result;
}

original_code:
int getSeeStateDecoder (decoderTree_t tree, Uint allCount, Uint pos, Uint numMasked, const Uchar * text, Uint alphasize) {
  Uint state, syms;
  if (allCount >= (alphasize >= 150 ? 128 : 30)) {
    return -1;
  }
  state = get3ByteRepresentation(tree->totalCount - allCount, alphasize);
  state <<= 3;
  state |= get3ByteRepresentation(allCount, alphasize);
  state <<=3;
  state |= get3ByteRepresentation(numMasked, alphasize);
  syms = tree->totalSyms;
  if (alphasize < 150) {
    while (!isRootDecoderTree(tree) && tree->totalSyms == syms) {
      tree = tree->parent->origin;
    }
    state <<=2;
    if (tree->totalSyms > 3) {
      state |= 3;
    }
    else {
      state |= tree->totalSyms;
    }
  }
  state <<=3;
  if ((pos > 0) && (text[pos-1] > 0)) {
    state |= (int)(log(text[pos-1])+0.5);
  }
  return state;
}

canonical_original_code:
int getSeeStateDecoder(struct decoderTree *tree, unsigned long allCount, unsigned long pos, unsigned long numMasked, unsigned char *text, unsigned long alphasize) {
  unsigned long state; unsigned long syms;
  if (allCount >= (alphasize >= 150 ? 128 : 30)) {
    return -1;
  }
  state = get3ByteRepresentation(tree->totalCount - allCount, alphasize);
  state <<= 3;
  state |= get3ByteRepresentation(allCount, alphasize);
  state <<=3;
  state |= get3ByteRepresentation(numMasked, alphasize);
  syms = tree->totalSyms;
  if (alphasize < 150) {
    while (!isRootDecoderTree(tree) && tree->totalSyms == syms) {
      tree = tree->parent->origin;
    }
    state <<=2;
    if (tree->totalSyms > 3) {
      state |= 3;
    }
    else {
      state |= tree->totalSyms;
    }
  }
  state <<=3;
  if ((pos > 0) && (text[pos-1] > 0)) {
    state |= (int)(log(text[pos-1])+0.5);
  }
  return state;
}

variable_types: struct decoderTree { unsigned long left; struct decoderTree *tail; unsigned char *traversed; unsigned char **text; unsigned char *symbols; } *

variable_types:
text
unsigned char *


initSee

decompiled_code:
__int64 *initSee()
{
__int64 *result; // rax

result = See;
do
{
*result = 20LL;
result += 2;
*(result - 1) = 50LL;
}
while ( result != &See[0x8000] );
return result;
}

canonical_decompiled_code:
__int64 *func4()
{
__int64 *result; // rax

result = See;
do
{
*result = 20LL;
result += 2;
*(result - 1) = 50LL;
}
while ( result != &See[0x8000] );
return result;
}


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

result = 0LL;
underflow_bits = 0LL;
low = 0;
high = -1;
return result;
}

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

result = 0LL;
underflow_bits = 0LL;
low = 0;
high = -1;
return result;
}

original_code:
void initialize_arithmetic_encoder()
{
    low = 0;
    high = 0xffff;
    underflow_bits = 0;
}


decompiled_code:
__int64 __fastcall get_current_count(__int64 a1)
{
return (*(unsigned __int16 *)(a1 + 4) * (__int64)((unsigned __int16)code - (unsigned __int16)low + 1) - 1)
/ ((unsigned __int16)high - (unsigned __int16)low + 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (*(unsigned __int16 *)(a1 + 4) * (__int64)((unsigned __int16)code - (unsigned __int16)low + 1) - 1)
/ ((unsigned __int16)high - (unsigned __int16)low + 1);
}

original_code:
short int get_current_count( SYMBOL *s )
{
    long range;
    short int count;
    range = (long) ( high - low ) + 1;
    count = (short int)
            ((((long) ( code - low ) + 1 ) * s->scale-1 ) / range );
    return( count );
}

canonical_original_code:
short get_current_count(struct SYMBOL *s)
{
    long range;
    short count;
    range = (long) ( high - low ) + 1;
    count = (short)
            ((((long) ( code - low ) + 1 ) * s->scale-1 ) / range );
    return( count );
}

variable_types: struct SYMBOL { unsigned short low_count; unsigned short high_count; unsigned short scale; } *

variable_types: range long

variable_types: count short

return_type: short


setMaxCount

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

result = (unsigned __int64)alphasize < 0x65 ? 450LL : 200LL;
MAX_COUNT = result;
return result;
}

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

result = (unsigned __int64)alphasize < 0x65 ? 450LL : 200LL;
MAX_COUNT = result;
return result;
}

original_code:
void setMaxCount() {
  MAX_COUNT = (alphasize <= 100 ? 450 : 200);
}


buildAlpha

decompiled_code:
__int64 __fastcall buildAlpha(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 i; // rax
__int64 result; // rax
__int64 v8[256]; // [rsp+0h] [rbp-800h] BYREF

v2 = a1;
memset(v8, 0, sizeof(v8));
if ( &v2[a2] <= v2 )
{
v4 = 0LL;
}
else
{
do
{
v3 = *v2++;
++v8[v3];
}
while ( &a1[a2] != v2 );
v4 = v8[0];
}
v5 = 0LL;
for ( i = 0LL; ; v4 = v8[i] )
{
if ( v4 )
characters[v5++] = i;
if ( ++i == 256 )
break;
}
alphasize = v5;
result = 0LL;
if ( v5 )
{
do
{
alphaindex[(unsigned __int8)characters[result]] = result;
++result;
}
while ( v5 != result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 i; // rax
__int64 result; // rax
__int64 v8[256]; // [rsp+0h] [rbp-800h] BYREF

v2 = a1;
memset(v8, 0, sizeof(v8));
if ( &v2[a2] <= v2 )
{
v4 = 0LL;
}
else
{
do
{
v3 = *v2++;
++v8[v3];
}
while ( &a1[a2] != v2 );
v4 = v8[0];
}
v5 = 0LL;
for ( i = 0LL; ; v4 = v8[i] )
{
if ( v4 )
characters[v5++] = i;
if ( ++i == 256 )
break;
}
alphasize = v5;
result = 0LL;
if ( v5 )
{
do
{
alphaindex[(unsigned __int8)characters[result]] = result;
++result;
}
while ( v5 != result );
}
return result;
}

original_code:
void buildAlpha(Uchar *text, const Uint textlen) {
  Uint occ[(0x7f * 2 + 1)+1] = {0}, i, j;
  Uchar *tptr;
  for (tptr = text; tptr < text+textlen; tptr++)
  {
    occ[(Uint) *tptr]++;
  }
  for (j=0, i=0; i<=(0x7f * 2 + 1); i++)
  {
    if(occ[i] > 0)
    {
      characters[j++] = (Uchar) i;
    }
  }
  alphasize = j;
  for(i=0; i<alphasize; i++)
  {
    alphaindex[(Uint) characters[i]] = i;
  }
}

canonical_original_code:
void buildAlpha(unsigned char *text, unsigned long textlen) {
  unsigned long occ[-1] = {0}; unsigned long i; unsigned long j;
  unsigned char *tptr;
  for (tptr = text; tptr < text+textlen; tptr++)
  {
    occ[(Uint) *tptr]++;
  }
  for (j=0, i=0; i<=(0x7f * 2 + 1); i++)
  {
    if(occ[i] > 0)
    {
      characters[j++] = (unsigned char) i;
    }
  }
  alphasize = j;
  for(i=0; i<alphasize; i++)
  {
    alphaindex[(unsigned long) characters[i]] = i;
  }
}

variable_types:
textlen
unsigned long

variable_types:
occ
unsigned long [-1]

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
tptr
unsigned char *


decompiled_code:
int __fastcall register_process(unsigned int a1, unsigned int a2, unsigned int a3)
{
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

printf("%d: registering...\n", a1);
sprintf(v5, "echo 'R:%d:%u:%u' > /proc/mp2/status", a1, a2, a3);
puts(v5);
return system(v5);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3)
{
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

printf("%d: registering...\n", a1);
sprintf(v5, "echo 'R:%d:%u:%u' > /proc/mp2/status", a1, a2, a3);
puts(v5);
return system(v5);
}

original_code:
void register_process(int my_pid, unsigned int period, unsigned int computation_time)
{
    printf("%d: registering...\n", my_pid);
    char string[100];
    sprintf(string, "echo \'R:%d:%u:%u\' > /proc/mp2/status", my_pid, period, computation_time);
    printf("%s\n", string);
    system(string);
}

variable_types:
period
unsigned int

variable_types:
string
char [100]


yield

decompiled_code:
int __fastcall yield(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

printf("%d: yielding...\n", a1);
sprintf(v2, "echo 'Y:%d' > /proc/mp2/status", a1);
return system(v2);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

printf("%d: yielding...\n", a1);
sprintf(v2, "echo 'Y:%d' > /proc/mp2/status", a1);
return system(v2);
}

original_code:
void yield(int my_pid){
    printf("%d: yielding...\n", my_pid);
    char string[100];
    sprintf(string, "echo \'Y:%d\' > /proc/mp2/status", my_pid);
    system(string);
}


unregister

decompiled_code:
int __fastcall unregister(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

printf("%d: unregistering...\n", a1);
sprintf(v2, "echo 'D:%d' > /proc/mp2/status", a1);
return system(v2);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

printf("%d: unregistering...\n", a1);
sprintf(v2, "echo 'D:%d' > /proc/mp2/status", a1);
return system(v2);
}

original_code:
void unregister(int my_pid){
    printf("%d: unregistering...\n", my_pid);
    char string[100];
    sprintf(string, "echo \'D:%d\' > /proc/mp2/status", my_pid);
    system(string);
}


decompiled_code:
__int64 __fastcall rand_in_range(int a1, int a2)
{
return rand() % (unsigned int)(a2 - a1 + 1) + a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
return rand() % (unsigned int)(a2 - a1 + 1) + a1;
}

original_code:
unsigned int rand_in_range(unsigned int min, unsigned int max)
{
    unsigned int range = max - min + 1;
    unsigned int random_value = rand() % range;
    return random_value + min;
}

variable_types:
min
unsigned int

variable_types:
max
unsigned int

variable_types:
range
unsigned int


decompiled_code:
__int64 get_period()
{
return rand_in_range(100, 500);
}

original_code:
unsigned int get_period()
{
    return rand_in_range(100, 500);
}


decompiled_code:
__int64 __fastcall get_comp_time(int a1)
{
unsigned int v1; // esi

v1 = (int)((double)a1 * 0.2);
if ( v1 < 0xA )
v1 = 10;
return rand_in_range(10, v1);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
unsigned int v1; // esi

v1 = (int)((double)a1 * 0.2);
if ( v1 < 0xA )
v1 = 10;
return func11(10, v1);
}

original_code:
unsigned int get_comp_time(int period)
{
    unsigned int max_comp_time = (unsigned int)(period * .2);
    if(max_comp_time < 10)
    {
        max_comp_time = 10;
    }
    return rand_in_range(10, max_comp_time);
}

variable_types: period int


decompiled_code:
__int64 get_iterations()
{
return rand_in_range(50, 100);
}

original_code:
unsigned int get_iterations()
{
    return rand_in_range(50, 100);
}


factorial

decompiled_code:
__int64 __fastcall factorial(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

for ( result = 1LL; a1 != 1; result *= v2 )
v2 = a1--;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

for ( result = 1LL; a1 != 1; result *= v2 )
v2 = a1--;
return result;
}

original_code:
long int factorial(unsigned long int num)
{
    if(num == 1)
        return 1;
    else return num * factorial(num-1);
}

canonical_original_code:
long factorial(unsigned long num)
{
    if(num == 1)
        return 1;
    else return num * factorial(num-1);
}

variable_types:
num
unsigned long


decompiled_code:
__int64 rand_access()
{
int v0; // eax
__int64 v1; // rdx
__int64 result; // rax

v0 = abs32(rand() % (msize << 20));
v1 = v0 & 0xFFFFF;
result = (__int64)*(&buffer + (v0 >> 20));
*(_BYTE *)(result + v1) = 42;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
__int64 v1; // rdx
__int64 result; // rax

v0 = abs32(rand() % (msize << 20));
v1 = v0 & 0xFFFFF;
result = (__int64)*(&buffer + (v0 >> 20));
*(_BYTE *)(result + v1) = 42;
return result;
}

original_code:
void rand_access()
{
  int target;
  int blk;
  target = rand() % (msize * 1024*1024);
  if(target<0)
    target *= -1;
  blk = target / 1024/1024;
  buffer[blk][target-blk*1024*1024] = '*';
}

variable_types: target int

variable_types: blk int


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

if ( rand() >= 0 )
result = (unsigned int)(rand() % 300 + a1);
else
result = (unsigned int)(a1 + 1);
return result;
}

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

if ( rand() >= 0 )
result = (unsigned int)(rand() % 300 + a1);
else
result = (unsigned int)(a1 + 1);
return result;
}

original_code:
int local_access(int addr)
{
  if(rand() < 0){
    return addr + 1;
  }
  else{
    return addr + rand() % 300;
  }
}

variable_types: addr int