main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rbx
_QWORD *v7; // rbx
int v8; // eax
int v9; // ebp
__int64 v10; // rax
int v11; // ebx
int v12; // er15
int v13; // eax
int v14; // ebx
int v15; // ebp
int *v16; // r14
int *v17; // r15
int v18; // eax
int v19; // esi
int v20; // edi
int v21; // eax
int v22; // ecx
int i; // eax
int v24; // ecx
double v25; // xmm0_8
int v26; // eax
int v27; // ecx
int v28; // edx
int v29; // [rsp+4h] [rbp-94h]
int v30; // [rsp+8h] [rbp-90h]
int v31; // [rsp+Ch] [rbp-8Ch]
int v32; // [rsp+10h] [rbp-88h]
int v33; // [rsp+14h] [rbp-84h]
__int64 v34; // [rsp+18h] [rbp-80h]
int v35; // [rsp+20h] [rbp-78h]
int v36; // [rsp+28h] [rbp-70h]
int v37; // [rsp+2Ch] [rbp-6Ch]
unsigned int v38; // [rsp+30h] [rbp-68h]
int v39; // [rsp+34h] [rbp-64h]
int v40; // [rsp+38h] [rbp-60h]
int v41; // [rsp+3Ch] [rbp-5Ch]
int *v42; // [rsp+40h] [rbp-58h]
int *v43; // [rsp+48h] [rbp-50h]
double cosx; // [rsp+50h] [rbp-48h] BYREF
double sinx[8]; // [rsp+58h] [rbp-40h] BYREF

get_options(argc, argv, &options, help_string);
x11_force_flush = invis;
plot_mag = mag;
plot_inverse = invert;
plot_init((unsigned int)width, (unsigned int)height, (unsigned int)levels, term);
plot_set_all(0LL);
srandom(seed);
v3 = xmalloc(4LL * num);
v42 = (int *)v3;
v4 = xmalloc(4LL * num);
v43 = (int *)v4;
if ( num > 0 )
{
v5 = v4;
v6 = 0LL;
do
{
*(_DWORD *)(v3 + 4 * v6) = (int)((double)(width / 2) + random_range((double)(width / -10), (double)(width / 10)));
*(_DWORD *)(v5 + 4 * v6++) = (int)((double)(height / 2)
+ random_range((double)(height / -10), (double)(height / 10)));
}
while ( num > (int)v6 );
}
v7 = (_QWORD *)xmalloc(8LL * width);
v34 = (__int64)v7;
v8 = width;
if ( width > 0 )
{
v9 = 0;
do
{
*v7 = xmalloc(height);
if ( height > 0 )
{
v10 = 0LL;
do
*(_BYTE *)(*v7 + v10++) = 0;
while ( height > (int)v10 );
}
++v9;
v8 = width;
++v7;
}
while ( width > v9 );
}
v11 = (int)((double)v8 * 0.5 + 0.5);
v29 = v11;
v12 = (int)((double)height * 0.5 + 0.5);
v30 = v12;
*(_BYTE *)(*(_QWORD *)(v34 + 8LL * v11) + v12) = 1;
plot_point(1LL, (double)v11, (double)v12);
v13 = 1;
if ( steps > 0 )
v13 = steps;
v41 = v13;
v33 = v12;
v32 = v11;
v38 = 1;
v37 = 0;
v40 = 0;
while ( 1 )
{
if ( num <= 0 )
{
v39 = 0;
}
else
{
v16 = v42;
v17 = v43;
v39 = 0;
v31 = 0;
do
{
v15 = *v16;
v14 = *v17;
if ( random_range(0.0, 1.0) >= 0.5 )
v14 = v14 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
else
v15 = v15 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
if ( v29 - 5 <= v15 )
{
if ( v32 + 5 < v15 )
v15 = v29 - 5;
}
else
{
v15 = v32 + 5;
}
if ( v30 - 5 <= v14 )
{
if ( v33 + 5 < v14 )
v14 = v30 - 5;
}
else
{
v14 = v33 + 5;
}
if ( v15 < 0 )
{
v15 = width - 1;
}
else if ( width <= v15 )
{
v15 = 0;
}
if ( v14 < 0 )
{
v14 = height - 1;
}
else if ( height <= v14 )
{
v14 = 0;
}
if ( !invis )
plot_point(0LL, (double)*v16, (double)*v17);
*v16 = v15;
*v17 = v14;
if ( !invis )
plot_point(v38, (double)*v16, (double)v14);
v35 = *v17;
v36 = *v16;
if ( (unsigned int)nearanother(*v16, *v17, v34) )
{
*(_BYTE *)(*(_QWORD *)(v34 + 8LL * v36) + v35) = 1;
v18 = v29;
if ( v29 > v15 )
v18 = v15;
v29 = v18;
v19 = v15;
if ( v32 >= v15 )
v19 = v32;
v32 = v19;
v20 = v30;
if ( v30 > v14 )
v20 = v14;
v30 = v20;
if ( v33 >= v14 )
v14 = v33;
v33 = v14;
if ( v18 <= 4 || v20 <= 4 )
{
v39 = 1;
}
else if ( width + 4 < v19 )
{
v39 = 1;
}
else
{
v21 = 1;
if ( height + 4 >= v14 )
v21 = v39;
v39 = v21;
}
if ( invis )
plot_point(v38, (double)*v16, (double)*v17);
v22 = *v16;
for ( i = *v17; *(_BYTE *)(*(_QWORD *)(v34 + 8LL * *v16) + i); v22 = *v16 )
{
v25 = random_range(0.0, 6.283185307179586);
sincos(v25, sinx, &cosx);
v26 = height / 2;
v27 = v19 - width / 2;
if ( v27 < width / 2 - v29 )
v27 = width / 2 - v29;
v24 = (int)((double)(v27 + 5) * cosx + (double)(width / 2));
v28 = v14 - v26;
if ( v14 - v26 < v26 - v20 )
v28 = v26 - v20;
i = (int)((double)(v28 + 5) * sinx[0] + (double)v26);
if ( v24 >= 0 )
{
if ( width <= v24 )
v24 = width - 1;
}
else
{
v24 = 0;
}
if ( i < 0 )
{
i = 0;
}
else if ( height <= i )
{
i = height - 1;
}
*v16 = v24;
*v17 = i;
}
if ( !invis )
plot_point(v38, (double)v22, (double)i);
if ( ++v37 > 10 )
{
v38 = (int)v38 % 255 + 1;
v37 = 0;
}
}
++v31;
++v16;
++v17;
}
while ( num > v31 );
}
v40 += (unsigned int)steps < 0x80000000;
if ( v41 <= v40 || v39 )
{
plot_finish();
exit(0);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rbx
_QWORD *v7; // rbx
int v8; // eax
int v9; // ebp
__int64 v10; // rax
int v11; // ebx
int v12; // er15
int v13; // eax
int v14; // ebx
int v15; // ebp
int *v16; // r14
int *v17; // r15
int v18; // eax
int v19; // esi
int v20; // edi
int v21; // eax
int v22; // ecx
int i; // eax
int v24; // ecx
double v25; // xmm0_8
int v26; // eax
int v27; // ecx
int v28; // edx
int v29; // [rsp+4h] [rbp-94h]
int v30; // [rsp+8h] [rbp-90h]
int v31; // [rsp+Ch] [rbp-8Ch]
int v32; // [rsp+10h] [rbp-88h]
int v33; // [rsp+14h] [rbp-84h]
__int64 v34; // [rsp+18h] [rbp-80h]
int v35; // [rsp+20h] [rbp-78h]
int v36; // [rsp+28h] [rbp-70h]
int v37; // [rsp+2Ch] [rbp-6Ch]
unsigned int v38; // [rsp+30h] [rbp-68h]
int v39; // [rsp+34h] [rbp-64h]
int v40; // [rsp+38h] [rbp-60h]
int v41; // [rsp+3Ch] [rbp-5Ch]
int *v42; // [rsp+40h] [rbp-58h]
int *v43; // [rsp+48h] [rbp-50h]
double cosx; // [rsp+50h] [rbp-48h] BYREF
double sinx[8]; // [rsp+58h] [rbp-40h] BYREF

get_options(argc, argv, &options, help_string);
x11_force_flush = invis;
plot_mag = mag;
plot_inverse = invert;
plot_init((unsigned int)width, (unsigned int)height, (unsigned int)levels, term);
plot_set_all(0LL);
srandom(seed);
v3 = xmalloc(4LL * num);
v42 = (int *)v3;
v4 = xmalloc(4LL * num);
v43 = (int *)v4;
if ( num > 0 )
{
v5 = v4;
v6 = 0LL;
do
{
*(_DWORD *)(v3 + 4 * v6) = (int)((double)(width / 2) + random_range((double)(width / -10), (double)(width / 10)));
*(_DWORD *)(v5 + 4 * v6++) = (int)((double)(height / 2)
+ random_range((double)(height / -10), (double)(height / 10)));
}
while ( num > (int)v6 );
}
v7 = (_QWORD *)xmalloc(8LL * width);
v34 = (__int64)v7;
v8 = width;
if ( width > 0 )
{
v9 = 0;
do
{
*v7 = xmalloc(height);
if ( height > 0 )
{
v10 = 0LL;
do
*(_BYTE *)(*v7 + v10++) = 0;
while ( height > (int)v10 );
}
++v9;
v8 = width;
++v7;
}
while ( width > v9 );
}
v11 = (int)((double)v8 * 0.5 + 0.5);
v29 = v11;
v12 = (int)((double)height * 0.5 + 0.5);
v30 = v12;
*(_BYTE *)(*(_QWORD *)(v34 + 8LL * v11) + v12) = 1;
plot_point(1LL, (double)v11, (double)v12);
v13 = 1;
if ( steps > 0 )
v13 = steps;
v41 = v13;
v33 = v12;
v32 = v11;
v38 = 1;
v37 = 0;
v40 = 0;
while ( 1 )
{
if ( num <= 0 )
{
v39 = 0;
}
else
{
v16 = v42;
v17 = v43;
v39 = 0;
v31 = 0;
do
{
v15 = *v16;
v14 = *v17;
if ( random_range(0.0, 1.0) >= 0.5 )
v14 = v14 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
else
v15 = v15 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
if ( v29 - 5 <= v15 )
{
if ( v32 + 5 < v15 )
v15 = v29 - 5;
}
else
{
v15 = v32 + 5;
}
if ( v30 - 5 <= v14 )
{
if ( v33 + 5 < v14 )
v14 = v30 - 5;
}
else
{
v14 = v33 + 5;
}
if ( v15 < 0 )
{
v15 = width - 1;
}
else if ( width <= v15 )
{
v15 = 0;
}
if ( v14 < 0 )
{
v14 = height - 1;
}
else if ( height <= v14 )
{
v14 = 0;
}
if ( !invis )
plot_point(0LL, (double)*v16, (double)*v17);
*v16 = v15;
*v17 = v14;
if ( !invis )
plot_point(v38, (double)*v16, (double)v14);
v35 = *v17;
v36 = *v16;
if ( (unsigned int)func0(*v16, *v17, v34) )
{
*(_BYTE *)(*(_QWORD *)(v34 + 8LL * v36) + v35) = 1;
v18 = v29;
if ( v29 > v15 )
v18 = v15;
v29 = v18;
v19 = v15;
if ( v32 >= v15 )
v19 = v32;
v32 = v19;
v20 = v30;
if ( v30 > v14 )
v20 = v14;
v30 = v20;
if ( v33 >= v14 )
v14 = v33;
v33 = v14;
if ( v18 <= 4 || v20 <= 4 )
{
v39 = 1;
}
else if ( width + 4 < v19 )
{
v39 = 1;
}
else
{
v21 = 1;
if ( height + 4 >= v14 )
v21 = v39;
v39 = v21;
}
if ( invis )
plot_point(v38, (double)*v16, (double)*v17);
v22 = *v16;
for ( i = *v17; *(_BYTE *)(*(_QWORD *)(v34 + 8LL * *v16) + i); v22 = *v16 )
{
v25 = random_range(0.0, 6.283185307179586);
sincos(v25, sinx, &cosx);
v26 = height / 2;
v27 = v19 - width / 2;
if ( v27 < width / 2 - v29 )
v27 = width / 2 - v29;
v24 = (int)((double)(v27 + 5) * cosx + (double)(width / 2));
v28 = v14 - v26;
if ( v14 - v26 < v26 - v20 )
v28 = v26 - v20;
i = (int)((double)(v28 + 5) * sinx[0] + (double)v26);
if ( v24 >= 0 )
{
if ( width <= v24 )
v24 = width - 1;
}
else
{
v24 = 0;
}
if ( i < 0 )
{
i = 0;
}
else if ( height <= i )
{
i = height - 1;
}
*v16 = v24;
*v17 = i;
}
if ( !invis )
plot_point(v38, (double)v22, (double)i);
if ( ++v37 > 10 )
{
v38 = (int)v38 % 255 + 1;
v37 = 0;
}
}
++v31;
++v16;
++v17;
}
while ( num > v31 );
}
v40 += (unsigned int)steps < 0x80000000;
if ( v41 <= v40 || v39 )
{
plot_finish();
exit(0);
}
}
}

original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int x11_force_flush;
  extern int plot_inverse;
  int i, j, lim, *xb, *yb, nx, ny, minx, miny, maxx, maxy;
  int cinc, color, cincfreq, done = 0;
  double ang;
  char **grid;
  get_options(argc, argv, options, help_string);
  x11_force_flush = invis;
  plot_mag = mag;
  plot_inverse = invert;
  plot_init(width, height, levels, term);
  plot_set_all(0);
  srandom(seed);
  cinc = 0;
  color = 1;
  cincfreq = 10;
  xb = xmalloc(sizeof(int) * num);
  yb = xmalloc(sizeof(int) * num);
  for(i = 0; i < num; i++) {
    xb[i] = random_range(-width / 10, width / 10) + width / 2;
    yb[i] = random_range(-height / 10, height / 10) + height / 2;
  }
  grid = xmalloc(sizeof(char *) * width);
  for(i = 0; i < width; i++) {
    grid[i] = xmalloc(sizeof(char) * height);
    for(j = 0; j < height; j++) {
      grid[i][j] = 0;
    }
  }
  minx = maxx = width / 2.0 + 0.5;
  miny = maxy = height / 2.0 + 0.5;
  grid[minx][miny] = 1;
  plot_point(minx, miny, 1);
  lim = (steps > 0) ? steps : 1;
  for(i = 0; i < lim && !done; i++) {
    for(j = 0; j < num; j++) {
      nx = xb[j]; ny = yb[j];
      if(random_range(0.0, 1.0) < 0.5)
        nx += random_range(0.0, 1.0) < 0.5 ? 1 : -1;
      else
        ny += random_range(0.0, 1.0) < 0.5 ? 1 : -1;
      nx = (nx < minx - 5) ? maxx + 5 : (nx > maxx + 5) ? minx - 5 : nx;
      ny = (ny < miny - 5) ? maxy + 5 : (ny > maxy + 5) ? miny - 5 : ny;
      nx = (nx < 0) ? width - 1 : (nx > width - 1) ? 0 : nx;
      ny = (ny < 0) ? height - 1 : (ny > height - 1) ? 0 : ny;
      if(!invis) plot_point(xb[j], yb[j], 0);
      xb[j] = nx; yb[j] = ny;
      if(!invis) plot_point(xb[j], yb[j], color);
      if(nearanother(xb[j], yb[j], grid)) {
        grid[xb[j]][yb[j]] = 1;
        minx = (nx < minx) ? nx : minx;
        maxx = (nx > maxx) ? nx : maxx;
        miny = (ny < miny) ? ny : miny;
        maxy = (ny > maxy) ? ny : maxy;
        if(minx < 5 || miny < 5 || maxx > width - 1 + 5 ||
           maxy > height - 1 + 5)
          done = 1;
        if(invis) plot_point(xb[j], yb[j], color);
        while(grid[xb[j]][yb[j]]) {
          ang = random_range(0, 3.14159265358979323846 * 2);
          nx = ((width / 2 - minx) > (maxx - width / 2) ? (width / 2 - minx) : (maxx - width / 2)) + 5;
          ny = ((height / 2 - miny) > (maxy - height / 2) ? (height / 2 - miny) : (maxy - height / 2)) + 5;
          nx = cos(ang) * nx + width / 2;
          ny = sin(ang) * ny + height / 2;
          nx = (nx < 0) ? 0 : (nx > width - 1) ? width - 1 : nx;
          ny = (ny < 0) ? 0 : (ny > height - 1) ? height - 1 : ny;
          xb[j] = nx; yb[j] = ny;
        }
        if(!invis) plot_point(xb[j], yb[j], color);
        cinc++;
        if (cinc > cincfreq) {
          color = color % 255 + 1;
          cinc = 0;
        }
      }
    }
    if(steps < 0) i--;
  }
  plot_finish();
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int x11_force_flush;
  extern int plot_inverse;
  int i; int j; int lim; int *xb; int *yb; int nx; int ny; int minx; int miny; int maxx; int maxy;
  int cinc; int color; int cincfreq; int done = 0;
  double ang;
  char **grid;
  get_options(argc, argv, options, help_string);
  x11_force_flush = invis;
  plot_mag = mag;
  plot_inverse = invert;
  plot_init(width, height, levels, term);
  plot_set_all(0);
  srandom(seed);
  cinc = 0;
  color = 1;
  cincfreq = 10;
  xb = xmalloc(sizeof(int) * num);
  yb = xmalloc(sizeof(int) * num);
  for(i = 0; i < num; i++) {
    xb[i] = random_range(-width / 10, width / 10) + width / 2;
    yb[i] = random_range(-height / 10, height / 10) + height / 2;
  }
  grid = xmalloc(sizeof(char *) * width);
  for(i = 0; i < width; i++) {
    grid[i] = xmalloc(sizeof(char) * height);
    for(j = 0; j < height; j++) {
      grid[i][j] = 0;
    }
  }
  minx = maxx = width / 2.0 + 0.5;
  miny = maxy = height / 2.0 + 0.5;
  grid[minx][miny] = 1;
  plot_point(minx, miny, 1);
  lim = (steps > 0) ? steps : 1;
  for(i = 0; i < lim && !done; i++) {
    for(j = 0; j < num; j++) {
      nx = xb[j]; ny = yb[j];
      if(random_range(0.0, 1.0) < 0.5)
        nx += random_range(0.0, 1.0) < 0.5 ? 1 : -1;
      else
        ny += random_range(0.0, 1.0) < 0.5 ? 1 : -1;
      nx = (nx < minx - 5) ? maxx + 5 : (nx > maxx + 5) ? minx - 5 : nx;
      ny = (ny < miny - 5) ? maxy + 5 : (ny > maxy + 5) ? miny - 5 : ny;
      nx = (nx < 0) ? width - 1 : (nx > width - 1) ? 0 : nx;
      ny = (ny < 0) ? height - 1 : (ny > height - 1) ? 0 : ny;
      if(!invis) plot_point(xb[j], yb[j], 0);
      xb[j] = nx; yb[j] = ny;
      if(!invis) plot_point(xb[j], yb[j], color);
      if(nearanother(xb[j], yb[j], grid)) {
        grid[xb[j]][yb[j]] = 1;
        minx = (nx < minx) ? nx : minx;
        maxx = (nx > maxx) ? nx : maxx;
        miny = (ny < miny) ? ny : miny;
        maxy = (ny > maxy) ? ny : maxy;
        if(minx < 5 || miny < 5 || maxx > width - 1 + 5 ||
           maxy > height - 1 + 5)
          done = 1;
        if(invis) plot_point(xb[j], yb[j], color);
        while(grid[xb[j]][yb[j]]) {
          ang = random_range(0, 3.14159265358979323846 * 2);
          nx = ((width / 2 - minx) > (maxx - width / 2) ? (width / 2 - minx) : (maxx - width / 2)) + 5;
          ny = ((height / 2 - miny) > (maxy - height / 2) ? (height / 2 - miny) : (maxy - height / 2)) + 5;
          nx = cos(ang) * nx + width / 2;
          ny = sin(ang) * ny + height / 2;
          nx = (nx < 0) ? 0 : (nx > width - 1) ? width - 1 : nx;
          ny = (ny < 0) ? 0 : (ny > height - 1) ? height - 1 : ny;
          xb[j] = nx; yb[j] = ny;
        }
        if(!invis) plot_point(xb[j], yb[j], color);
        cinc++;
        if (cinc > cincfreq) {
          color = color % 255 + 1;
          cinc = 0;
        }
      }
    }
    if(steps < 0) i--;
  }
  plot_finish();
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: j int

variable_types: lim int

variable_types:
xb
int *

variable_types:
yb
int *

variable_types: minx int

variable_types: miny int

variable_types: maxx int

variable_types: maxy int

variable_types: cinc int

variable_types: color int

variable_types: cincfreq int

variable_types: done int

variable_types: ang double


pay

repo: ramalho/CBofN

decompiled_code:
double __fastcall pay(int a1, int a2)
{
double result; // xmm0_8

if ( a1 )
{
result = *(double *)&DC;
if ( a2 )
result = *(double *)ⅅ
}
else
{
result = *(double *)&CC;
if ( a2 )
result = *(double *)&CD;
}
return result;
}

canonical_decompiled_code:
double __fastcall func1(int a1, int a2)
{
double result; // xmm0_8

if ( a1 )
{
result = *(double *)&DC;
if ( a2 )
result = *(double *)ⅅ
}
else
{
result = *(double *)&CC;
if ( a2 )
result = *(double *)&CD;
}
return result;
}

original_code:
double pay(int s1, int s2)
{
  if(s1) {
    if(s2) return(DD);
    else return(DC);
  }
  else {
    if(s2) return(CD);
    else return(CC);
  }
}

return_type: double


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

result = (unsigned int)(random() % 27) + 97;
if ( (int)result >= 123 )
result = 32LL;
return result;
}

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

result = (unsigned int)(random() % 27) + 97;
if ( (int)result >= 123 )
result = 32LL;
return result;
}

original_code:
int random_letter_or_space(void)
{
  int letter;
  letter = (random() % ('z' - 'a' + 2)) + 'a';
  if(letter > 'z')
    letter = ' ';
  return(letter);
}

canonical_original_code:
int random_letter_or_space()
{
  int letter;
  letter = (random() % ('z' - 'a' + 2)) + 'a';
  if(letter > 'z')
    letter = ' ';
  return(letter);
}

variable_types: letter int

return_type: int


original_code:
void compute_fitness(int tlen, char **pop, int *correct, double *fit)
{
  int i, j, count;
  double sum;
  sum = 0;
  for(i = 0; i < size; i++) {
    count = 0;
    for(j = 0; j < tlen; j++)
      if(pop[i][j] == target[j]) count++;
    correct[i] = count;
    fit[i] = pow(pbase, correct[i] - tlen);
    sum += fit[i];
  }
  for(i = 0; i < size; i++)
    fit[i] /= sum;
}

canonical_original_code:
void compute_fitness(int tlen, char **pop, int *correct, double *fit)
{
  int i; int j; int count;
  double sum;
  sum = 0;
  for(i = 0; i < size; i++) {
    count = 0;
    for(j = 0; j < tlen; j++)
      if(pop[i][j] == target[j]) count++;
    correct[i] = count;
    fit[i] = pow(pbase, correct[i] - tlen);
    sum += fit[i];
  }
  for(i = 0; i < size; i++)
    fit[i] /= sum;
}

variable_types: tlen int

variable_types:
pop
char **

variable_types:
correct
int *

variable_types:
fit
double *

variable_types: count int

variable_types: sum double

return_type: void


decompiled_code:
__int64 __fastcall select_one(__int64 a1)
{
__int64 v1; // rax
double v2; // xmm0_8
unsigned int v3; // edx

random_range(0.0, 1.0);
if ( size <= 0 )
return (unsigned int)(size - 1);
v1 = 0LL;
v2 = 0.0;
while ( 1 )
{
v3 = v1;
v2 = v2 + *(double *)(a1 + 8 * v1);
if ( v2 >= 0.0 )
break;
if ( ++v1 == size )
return (unsigned int)(size - 1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
double v2; // xmm0_8
unsigned int v3; // edx

random_range(0.0, 1.0);
if ( size <= 0 )
return (unsigned int)(size - 1);
v1 = 0LL;
v2 = 0.0;
while ( 1 )
{
v3 = v1;
v2 = v2 + *(double *)(a1 + 8 * v1);
if ( v2 >= 0.0 )
break;
if ( ++v1 == size )
return (unsigned int)(size - 1);
}
return v3;
}

original_code:
int select_one(double *normfit)
{
  int i;
  double x, sum;
  sum = 0;
  x = random_range(0, 1);
  for(i = 0; i < size; i++) {
    sum += normfit[i];
    if(x <= sum)
      return(i);
  }
  return(size - 1);
}

canonical_original_code:
int select_one(double *normfit)
{
  int i;
  double x; double sum;
  sum = 0;
  x = random_range(0, 1);
  for(i = 0; i < size; i++) {
    sum += normfit[i];
    if(x <= sum)
      return(i);
  }
  return(size - 1);
}

variable_types:
normfit
double *

variable_types: i int

variable_types: x double


reproduce

original_code:
void reproduce(int tlen, char **oldpop, char **newpop, int pa, int pb,
               int index)
{
  int i, cpoint;
  cpoint = (random_range(0, 1) < crate) ?
    (random() % (tlen - 1)) + 1 : tlen;
  for(i = 0; i < cpoint; i++) {
    newpop[index][i] = oldpop[pa][i];
    newpop[index + 1][i] = oldpop[pb][i];
  }
  for(i = cpoint; i < tlen; i++) {
    newpop[index][i] = oldpop[pb][i];
    newpop[index + 1][i] = oldpop[pa][i];
  }
  for(i = 0; i < tlen; i++) {
    if(random_range(0, 1) < mrate)
      newpop[index][i] = random_letter_or_space();
    if(random_range(0, 1) < mrate)
      newpop[index + 1][i] = random_letter_or_space();
  }
}

canonical_original_code:
void reproduce(int tlen, char **oldpop, char **newpop, int pa, int pb, int index)
{
  int i; int cpoint;
  cpoint = (random_range(0, 1) < crate) ?
    (random() % (tlen - 1)) + 1 : tlen;
  for(i = 0; i < cpoint; i++) {
    newpop[index][i] = oldpop[pa][i];
    newpop[index + 1][i] = oldpop[pb][i];
  }
  for(i = cpoint; i < tlen; i++) {
    newpop[index][i] = oldpop[pb][i];
    newpop[index + 1][i] = oldpop[pa][i];
  }
  for(i = 0; i < tlen; i++) {
    if(random_range(0, 1) < mrate)
      newpop[index][i] = random_letter_or_space();
    if(random_range(0, 1) < mrate)
      newpop[index + 1][i] = random_letter_or_space();
  }
}

variable_types:
oldpop
char **

variable_types:
newpop
char **

variable_types: pa int

variable_types: pb int

variable_types: index int

variable_types: cpoint int


decompiled_code:
int __fastcall dump_stats(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v7; // rax
double v8; // xmm2_8
double v9; // xmm0_8
int v10; // ebx
double v11; // xmm1_8
bool v12; // cc
double v14; // [rsp+8h] [rbp-20h]

if ( size <= 0 )
{
v8 = 0.0;
v10 = -1;
}
else
{
v7 = 0LL;
v8 = 0.0;
v9 = *(double *)&LC2;
v10 = -1;
do
{
v11 = *(double *)(a3 + 8 * v7);
v12 = v11 <= v9;
v9 = fmax(v11, v9);
if ( !v12 )
v10 = v7;
v8 = v8 + (double)*(int *)(a4 + 4 * v7++);
}
while ( v7 != size );
}
v14 = v8 / (double)size;
printf("---\ntime = %d\n", a1);
printf("average %% letters correct = %f\n", v14 / (double)a2);
printf("best %% letters correct = %f\n", (double)*(int *)(a4 + 4LL * v10) / (double)a2);
return printf("best = \"%s\"\n", *(const char **)(a5 + 8LL * v10));
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v7; // rax
double v8; // xmm2_8
double v9; // xmm0_8
int v10; // ebx
double v11; // xmm1_8
bool v12; // cc
double v14; // [rsp+8h] [rbp-20h]

if ( size <= 0 )
{
v8 = 0.0;
v10 = -1;
}
else
{
v7 = 0LL;
v8 = 0.0;
v9 = *(double *)&LC2;
v10 = -1;
do
{
v11 = *(double *)(a3 + 8 * v7);
v12 = v11 <= v9;
v9 = fmax(v11, v9);
if ( !v12 )
v10 = v7;
v8 = v8 + (double)*(int *)(a4 + 4 * v7++);
}
while ( v7 != size );
}
v14 = v8 / (double)size;
printf("---\ntime = %d\n", a1);
printf("average %% letters correct = %f\n", v14 / (double)a2);
printf("best %% letters correct = %f\n", (double)*(int *)(a4 + 4LL * v10) / (double)a2);
return printf("best = \"%s\"\n", *(const char **)(a5 + 8LL * v10));
}

original_code:
void dump_stats(int time, int tlen, double *fit, int *correct, char **pop)
{
  int i, besti = -1;
  double best = -1, ave = 0;
  for(i = 0; i < size; i++) {
    if(fit[i] > best) {
      besti = i; best = fit[i];
    }
    ave += correct[i];
  }
  ave /= size;
  ave /= tlen;
  printf("---\ntime = %d\n", time);
  printf("average %% letters correct = %f\n", ave);
  printf("best %% letters correct = %f\n", correct[besti] / (double)tlen);
  printf("best = \"%s\"\n", pop[besti]);
}

canonical_original_code:
void dump_stats(int time, int tlen, double *fit, int *correct, char **pop)
{
  int i; int besti = -1;
  double best = -1; double ave = 0;
  for(i = 0; i < size; i++) {
    if(fit[i] > best) {
      besti = i; best = fit[i];
    }
    ave += correct[i];
  }
  ave /= size;
  ave /= tlen;
  printf("---\ntime = %d\n", time);
  printf("average %% letters correct = %f\n", ave);
  printf("best %% letters correct = %f\n", correct[besti] / (double)tlen);
  printf("best = \"%s\"\n", pop[besti]);
}

variable_types: time int

variable_types: besti int

variable_types: best double

variable_types: ave double


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rax
int v9; // esi
int v10; // ebx
int v11; // er15
int v12; // eax
__int64 v13; // rax
signed int v14; // [rsp+0h] [rbp-68h]
__int64 v15; // [rsp+8h] [rbp-60h]
_QWORD *v16; // [rsp+18h] [rbp-50h]
__int64 v17; // [rsp+20h] [rbp-48h]
int v18; // [rsp+28h] [rbp-40h]

get_options(argc, argv, &options, help_string);
srandom(seed);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v3 = size;
v18 = strlen(target);
v4 = xmalloc(8LL * v3);
v5 = xmalloc(8LL * size);
v17 = xmalloc(4LL * size);
v6 = xmalloc(8LL * size);
if ( size > 0 )
{
v16 = (_QWORD *)v5;
v15 = 0LL;
do
{
*(_QWORD *)(v4 + 8 * v15) = xmalloc(v18 + 1LL);
*v16 = xmalloc(v18 + 1LL);
if ( v18 > 0 )
{
v7 = 0LL;
do
{
*(_BYTE *)(*v16 + v7) = random_letter_or_space();
v8 = v7++;
}
while ( v18 - 1 != v8 );
}
*(_BYTE *)(*v16 + v18) = 0;
v9 = v15;
*(_BYTE *)(*(_QWORD *)(v4 + 8 * v15++) + v18) = 0;
++v16;
}
while ( size > v9 + 1 );
}
if ( steps > 0 )
{
v14 = 0;
while ( 1 )
{
compute_fitness(v18, v5, v17, v6);
dump_stats(v14, v18, v6, v17, v5);
if ( size > 0 )
{
v10 = 0;
do
{
v11 = select_one(v6);
v12 = select_one(v6);
reproduce(v18, v5, v4, v11, v12, v10);
v10 += 2;
}
while ( size > v10 );
}
++v14;
v13 = v5;
v5 = v4;
if ( steps <= v14 )
break;
v4 = v13;
}
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rax
int v9; // esi
int v10; // ebx
int v11; // er15
int v12; // eax
__int64 v13; // rax
signed int v14; // [rsp+0h] [rbp-68h]
__int64 v15; // [rsp+8h] [rbp-60h]
_QWORD *v16; // [rsp+18h] [rbp-50h]
__int64 v17; // [rsp+20h] [rbp-48h]
int v18; // [rsp+28h] [rbp-40h]

get_options(argc, argv, &options, help_string);
srandom(seed);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v3 = size;
v18 = strlen(target);
v4 = xmalloc(8LL * v3);
v5 = xmalloc(8LL * size);
v17 = xmalloc(4LL * size);
v6 = xmalloc(8LL * size);
if ( size > 0 )
{
v16 = (_QWORD *)v5;
v15 = 0LL;
do
{
*(_QWORD *)(v4 + 8 * v15) = xmalloc(v18 + 1LL);
*v16 = xmalloc(v18 + 1LL);
if ( v18 > 0 )
{
v7 = 0LL;
do
{
*(_BYTE *)(*v16 + v7) = func0();
v8 = v7++;
}
while ( v18 - 1 != v8 );
}
*(_BYTE *)(*v16 + v18) = 0;
v9 = v15;
*(_BYTE *)(*(_QWORD *)(v4 + 8 * v15++) + v18) = 0;
++v16;
}
while ( size > v9 + 1 );
}
if ( steps > 0 )
{
v14 = 0;
while ( 1 )
{
func1(v18, v5, v17, v6);
func4(v14, v18, v6, v17, v5);
if ( size > 0 )
{
v10 = 0;
do
{
v11 = func2(v6);
v12 = func2(v6);
func3(v18, v5, v4, v11, v12, v10);
v10 += 2;
}
while ( size > v10 );
}
++v14;
v13 = v5;
v5 = v4;
if ( steps <= v14 )
break;
v4 = v13;
}
}
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  int i, j, t, targetlen, parent_a, parent_b, *numcorrect;
  char **swap, **newpop, **oldpop;
  double *normfit;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  size += (size / 2 * 2 != size);
  targetlen = strlen(target);
  newpop = xmalloc(sizeof(char *) * size);
  oldpop = xmalloc(sizeof(char *) * size);
  numcorrect = xmalloc(sizeof(int) * size);
  normfit = xmalloc(sizeof(double) * size);
  for(i = 0; i < size; i++) {
    newpop[i] = xmalloc(sizeof(char) * targetlen + 1);
    oldpop[i] = xmalloc(sizeof(char) * targetlen + 1);
    for(j = 0; j < targetlen; j++)
      oldpop[i][j] = random_letter_or_space();
    oldpop[i][targetlen] = 0;
    newpop[i][targetlen] = 0;
  }
  for(t = 0; t < steps; t++) {
    compute_fitness(targetlen, oldpop, numcorrect, normfit);
    dump_stats(t, targetlen, normfit, numcorrect, oldpop);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      reproduce(targetlen, oldpop, newpop, parent_a, parent_b, i);
    }
    swap = newpop; newpop = oldpop; oldpop = swap;
  }
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  int i; int j; int t; int targetlen; int parent_a; int parent_b; int *numcorrect;
  char **swap; char **newpop; char **oldpop;
  double *normfit;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  size += (size / 2 * 2 != size);
  targetlen = strlen(target);
  newpop = xmalloc(sizeof(char *) * size);
  oldpop = xmalloc(sizeof(char *) * size);
  numcorrect = xmalloc(sizeof(int) * size);
  normfit = xmalloc(sizeof(double) * size);
  for(i = 0; i < size; i++) {
    newpop[i] = xmalloc(sizeof(char) * targetlen + 1);
    oldpop[i] = xmalloc(sizeof(char) * targetlen + 1);
    for(j = 0; j < targetlen; j++)
      oldpop[i][j] = random_letter_or_space();
    oldpop[i][targetlen] = 0;
    newpop[i][targetlen] = 0;
  }
  for(t = 0; t < steps; t++) {
    compute_fitness(targetlen, oldpop, numcorrect, normfit);
    dump_stats(t, targetlen, normfit, numcorrect, oldpop);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      reproduce(targetlen, oldpop, newpop, parent_a, parent_b, i);
    }
    swap = newpop; newpop = oldpop; oldpop = swap;
  }
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: j int

variable_types: t int

variable_types: targetlen int

variable_types:
numcorrect
int *

variable_types:
swap
char **


newstep

decompiled_code:
__int64 __fastcall newstep(int *a1, int *a2, int *a3)
{
__int64 v4; // r13
__int64 v5; // rax
__int64 result; // rax

v4 = *a3;
v5 = (v4 + random() % 3 + 7) % 8;
*a3 = v5;
*a1 = (width + *a1 + dir[2 * v5]) % width;
result = (unsigned int)((height + dir[2 * *a3 + 1] + *a2) / height);
*a2 = (height + dir[2 * *a3 + 1] + *a2) % height;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int *a2, int *a3)
{
__int64 v4; // r13
__int64 v5; // rax
__int64 result; // rax

v4 = *a3;
v5 = (v4 + random() % 3 + 7) % 8;
*a3 = v5;
*a1 = (width + *a1 + dir[2 * v5]) % width;
result = (unsigned int)((height + dir[2 * *a3 + 1] + *a2) / height);
*a2 = (height + dir[2 * *a3 + 1] + *a2) % height;
return result;
}

original_code:
void newstep(int *a, int *b, int *d)
{
  *d = (*d + ((random() % 3) - 1) + 8) % 8;
  *a = (*a + dir[*d][0] + width) % width;
  *b = (*b + dir[*d][1] + height) % height;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types:
d
int *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
_QWORD *v5; // r13
int v6; // er12
__int64 v7; // rbx
int v8; // eax
int v9; // er13
int *v10; // rbp
int *v11; // rbx
int *v12; // r12
_BYTE *v13; // rax
int v14; // eax
__int64 v15; // [rsp+8h] [rbp-70h]
int i; // [rsp+14h] [rbp-64h]
__int64 v17; // [rsp+18h] [rbp-60h]
__int64 v18; // [rsp+20h] [rbp-58h]
__int64 v19; // [rsp+28h] [rbp-50h]
int v20; // [rsp+38h] [rbp-40h] BYREF
int v21[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

get_options(argc, argv, &options, help_string);
plot_mag = mag;
plot_inverse = invert;
plot_init((unsigned int)width, (unsigned int)height, 2LL, term);
plot_set_all(0LL);
srandom(seed);
v17 = xmalloc(4LL * num);
v18 = xmalloc(4LL * num);
v19 = xmalloc(4LL * num);
if ( num > 0 )
{
v3 = 0LL;
do
{
*(_DWORD *)(v17 + 4 * v3) = (int)random_range(0.0, (double)width);
*(_DWORD *)(v18 + 4 * v3) = (int)random_range(0.0, (double)height);
*(_DWORD *)(v19 + 4 * v3++) = (int)random_range(0.0, 8.0);
}
while ( num > (int)v3 );
}
v4 = xmalloc(8LL * width);
v15 = v4;
if ( width > 0 )
{
v5 = (_QWORD *)v4;
v6 = 0;
do
{
*v5 = xmalloc(height);
if ( height > 0 )
{
v7 = 0LL;
do
{
*(_BYTE *)(*v5 + v7) = *(double *)&dense > random_range(0.0, 1.0);
if ( *(_BYTE *)(*v5 + v7) )
plot_point(1LL, (double)v6, (double)(int)v7);
++v7;
}
while ( height > (int)v7 );
}
++v6;
++v5;
}
while ( width > v6 );
}
for ( i = 0; steps > i; ++i )
{
if ( num > 0 )
{
v10 = (int *)v17;
v11 = (int *)v18;
v12 = (int *)v19;
v9 = 0;
do
{
v21[0] = *v10;
v20 = *v11;
newstep(v21, &v20, v12);
v13 = (_BYTE *)(*(_QWORD *)(v15 + 8LL * *v10) + *v11);
if ( *v13 )
{
if ( *(_BYTE *)(*(_QWORD *)(v15 + 8LL * v21[0]) + v20) )
{
v14 = (*v12 + 4) % 8;
*v12 = v14;
*v10 = (width + *v10 + dir[2 * v14]) % width;
*v11 = (height + dir[2 * *v12 + 1] + *v11) % height;
}
else
{
*v13 = 0;
plot_point(0LL, (double)*v10, (double)*v11);
*v10 = v21[0];
v8 = v20;
*v11 = v20;
*(_BYTE *)(*(_QWORD *)(v15 + 8LL * *v10) + v8) = 1;
plot_point(1LL, (double)*v10, (double)*v11);
}
}
else
{
*v10 = v21[0];
*v11 = v20;
}
++v9;
++v10;
++v11;
++v12;
}
while ( num > v9 );
}
}
plot_finish();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
_QWORD *v5; // r13
int v6; // er12
__int64 v7; // rbx
int v8; // eax
int v9; // er13
int *v10; // rbp
int *v11; // rbx
int *v12; // r12
_BYTE *v13; // rax
int v14; // eax
__int64 v15; // [rsp+8h] [rbp-70h]
int i; // [rsp+14h] [rbp-64h]
__int64 v17; // [rsp+18h] [rbp-60h]
__int64 v18; // [rsp+20h] [rbp-58h]
__int64 v19; // [rsp+28h] [rbp-50h]
int v20; // [rsp+38h] [rbp-40h] BYREF
int v21[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

get_options(argc, argv, &options, help_string);
plot_mag = mag;
plot_inverse = invert;
plot_init((unsigned int)width, (unsigned int)height, 2LL, term);
plot_set_all(0LL);
srandom(seed);
v17 = xmalloc(4LL * num);
v18 = xmalloc(4LL * num);
v19 = xmalloc(4LL * num);
if ( num > 0 )
{
v3 = 0LL;
do
{
*(_DWORD *)(v17 + 4 * v3) = (int)random_range(0.0, (double)width);
*(_DWORD *)(v18 + 4 * v3) = (int)random_range(0.0, (double)height);
*(_DWORD *)(v19 + 4 * v3++) = (int)random_range(0.0, 8.0);
}
while ( num > (int)v3 );
}
v4 = xmalloc(8LL * width);
v15 = v4;
if ( width > 0 )
{
v5 = (_QWORD *)v4;
v6 = 0;
do
{
*v5 = xmalloc(height);
if ( height > 0 )
{
v7 = 0LL;
do
{
*(_BYTE *)(*v5 + v7) = *(double *)&dense > random_range(0.0, 1.0);
if ( *(_BYTE *)(*v5 + v7) )
plot_point(1LL, (double)v6, (double)(int)v7);
++v7;
}
while ( height > (int)v7 );
}
++v6;
++v5;
}
while ( width > v6 );
}
for ( i = 0; steps > i; ++i )
{
if ( num > 0 )
{
v10 = (int *)v17;
v11 = (int *)v18;
v12 = (int *)v19;
v9 = 0;
do
{
v21[0] = *v10;
v20 = *v11;
func0(v21, &v20, v12);
v13 = (_BYTE *)(*(_QWORD *)(v15 + 8LL * *v10) + *v11);
if ( *v13 )
{
if ( *(_BYTE *)(*(_QWORD *)(v15 + 8LL * v21[0]) + v20) )
{
v14 = (*v12 + 4) % 8;
*v12 = v14;
*v10 = (width + *v10 + dir[2 * v14]) % width;
*v11 = (height + dir[2 * *v12 + 1] + *v11) % height;
}
else
{
*v13 = 0;
plot_point(0LL, (double)*v10, (double)*v11);
*v10 = v21[0];
v8 = v20;
*v11 = v20;
*(_BYTE *)(*(_QWORD *)(v15 + 8LL * *v10) + v8) = 1;
plot_point(1LL, (double)*v10, (double)*v11);
}
}
else
{
*v10 = v21[0];
*v11 = v20;
}
++v9;
++v10;
++v11;
++v12;
}
while ( num > v9 );
}
}
plot_finish();
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int plot_inverse;
  int i, j, *tx, *ty, *td, nx, ny;
  char **chips;
  get_options(argc, argv, options, help_string);
  plot_mag = mag;
  plot_inverse = invert;
  plot_init(width, height, 2, term);
  plot_set_all(0);
  srandom(seed);
  tx = xmalloc(sizeof(int) * num);
  ty = xmalloc(sizeof(int) * num);
  td = xmalloc(sizeof(int) * num);
  for(i = 0; i < num; i++) {
    tx[i] = (int) random_range(0, width);
    ty[i] = (int) random_range(0, height);
    td[i] = (int) random_range(0, 8);
  }
  chips = xmalloc(sizeof(char *) * width);
  for(i = 0; i < width; i++) {
    chips[i] = xmalloc(sizeof(char) * height);
    for(j = 0; j < height; j++) {
      chips[i][j] = (random_range(0.0, 1.0) < dense) ? 1 : 0;
      if(chips[i][j])
        plot_point(i, j, 1);
    }
  }
  for(i = 0; i < steps; i++) {
    for(j = 0; j < num; j++) {
      nx = tx[j]; ny = ty[j];
      newstep(&nx, &ny, &td[j]);
      if(chips[tx[j]][ty[j]] && !chips[nx][ny]) {
        chips[tx[j]][ty[j]] = 0;
        plot_point(tx[j], ty[j], 0);
        tx[j] = nx; ty[j] = ny;
        chips[tx[j]][ty[j]] = 1;
        plot_point(tx[j], ty[j], 1);
      }
      else if(chips[tx[j]][ty[j]] && chips[nx][ny]) {
        td[j] = (td[j] + 4) % 8;
        tx[j] = (tx[j] + dir[td[j]][0] + width) % width;
        ty[j] = (ty[j] + dir[td[j]][1] + height) % height;
      }
      else {
        tx[j] = nx; ty[j] = ny;
      }
    }
  }
  plot_finish();
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int plot_inverse;
  int i; int j; int *tx; int *ty; int *td; int nx; int ny;
  char **chips;
  get_options(argc, argv, options, help_string);
  plot_mag = mag;
  plot_inverse = invert;
  plot_init(width, height, 2, term);
  plot_set_all(0);
  srandom(seed);
  tx = xmalloc(sizeof(int) * num);
  ty = xmalloc(sizeof(int) * num);
  td = xmalloc(sizeof(int) * num);
  for(i = 0; i < num; i++) {
    tx[i] = (int) random_range(0, width);
    ty[i] = (int) random_range(0, height);
    td[i] = (int) random_range(0, 8);
  }
  chips = xmalloc(sizeof(char *) * width);
  for(i = 0; i < width; i++) {
    chips[i] = xmalloc(sizeof(char) * height);
    for(j = 0; j < height; j++) {
      chips[i][j] = (random_range(0.0, 1.0) < dense) ? 1 : 0;
      if(chips[i][j])
        plot_point(i, j, 1);
    }
  }
  for(i = 0; i < steps; i++) {
    for(j = 0; j < num; j++) {
      nx = tx[j]; ny = ty[j];
      newstep(&nx, &ny, &td[j]);
      if(chips[tx[j]][ty[j]] && !chips[nx][ny]) {
        chips[tx[j]][ty[j]] = 0;
        plot_point(tx[j], ty[j], 0);
        tx[j] = nx; ty[j] = ny;
        chips[tx[j]][ty[j]] = 1;
        plot_point(tx[j], ty[j], 1);
      }
      else if(chips[tx[j]][ty[j]] && chips[nx][ny]) {
        td[j] = (td[j] + 4) % 8;
        tx[j] = (tx[j] + dir[td[j]][0] + width) % width;
        ty[j] = (ty[j] + dir[td[j]][1] + height) % height;
      }
      else {
        tx[j] = nx; ty[j] = ny;
      }
    }
  }
  plot_finish();
  exit(0);
}

variable_types: i int

variable_types:
tx
int *

variable_types:
ty
int *

variable_types:
td
int *

variable_types: nx int

variable_types: ny int

variable_types:
chips
char **


ipd

original_code:
void ipd(int strata, int stratb, int time, int *scorea, int *scoreb)
{
  int i, movea, moveb, indexa, indexb, hindex, h, t;
  t = (time > hlen) ? hlen : time;
  hindex = time % hlen;
  indexa = indexb = 0;
  for(i = 0; i < t; i++) {
    h = (hindex - i - 1 + hlen) % hlen;
    indexa = indexa * 2 + hista[h]; indexa = indexa * 2 + histb[h];
    indexb = indexb * 2 + histb[h]; indexb = indexb * 2 + hista[h];
  }
  movea = oldpop[strata][dnaindex[t] + indexa];
  moveb = oldpop[stratb][dnaindex[t] + indexb];
  if(random_range(0,1) < noise) movea = random() % 2;
  if(random_range(0,1) < noise) moveb = random() % 2;
  pd(movea, moveb, scorea, scoreb);
  hista[hindex] = movea; histb[hindex] = moveb;
}

canonical_original_code:
void ipd(int strata, int stratb, int time, int *scorea, int *scoreb)
{
  int i; int movea; int moveb; int indexa; int indexb; int hindex; int h; int t;
  t = (time > hlen) ? hlen : time;
  hindex = time % hlen;
  indexa = indexb = 0;
  for(i = 0; i < t; i++) {
    h = (hindex - i - 1 + hlen) % hlen;
    indexa = indexa * 2 + hista[h]; indexa = indexa * 2 + histb[h];
    indexb = indexb * 2 + histb[h]; indexb = indexb * 2 + hista[h];
  }
  movea = oldpop[strata][dnaindex[t] + indexa];
  moveb = oldpop[stratb][dnaindex[t] + indexb];
  if(random_range(0,1) < noise) movea = random() % 2;
  if(random_range(0,1) < noise) moveb = random() % 2;
  pd(movea, moveb, scorea, scoreb);
  hista[hindex] = movea; histb[hindex] = moveb;
}

variable_types: strata int

variable_types: stratb int

variable_types: time int

variable_types:
scorea
int *

variable_types:
scoreb
int *

variable_types: movea int

variable_types: moveb int

variable_types: indexa int

variable_types: indexb int

variable_types: hindex int

variable_types: h int


decompiled_code:
__int64 inititalize_population()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r12
_QWORD *v5; // rbx
_QWORD *v6; // rbx
__int64 v7; // rbx
double v8; // [rsp+8h] [rbp-20h]

score = xmalloc(4LL * size);
roundbout = xmalloc(4LL * size);
fitness = xmalloc(8LL * size);
hista = xmalloc(4LL * hlen);
histb = xmalloc(4LL * hlen);
dnaindex = xmalloc(4LL * (hlen + 2));
*(_DWORD *)dnaindex = 0;
if ( hlen >= 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
v2 = v0;
v0 += 4LL;
v8 = (double)*(int *)(dnaindex + v2);
*(_DWORD *)(dnaindex + v0) = (int)(pow(2.0, (double)(2 * (int)v1++)) + v8);
}
while ( hlen >= (int)v1 );
}
oldpop = xmalloc(8LL * size);
result = xmalloc(8LL * size);
newpop = result;
if ( size > 0 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)(oldpop + 8 * v4);
*v5 = xmalloc(*(int *)(dnaindex + 4LL * hlen + 4));
v6 = (_QWORD *)(newpop + 8 * v4);
*v6 = xmalloc(*(int *)(dnaindex + 4LL * hlen + 4));
result = dnaindex;
if ( *(int *)(dnaindex + 4LL * hlen + 4) > 0 )
{
v7 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(oldpop + 8 * v4) + v7++) = random() % 2;
result = dnaindex;
}
while ( *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)v7 );
}
++v4;
}
while ( size > (int)v4 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r12
_QWORD *v5; // rbx
_QWORD *v6; // rbx
__int64 v7; // rbx
double v8; // [rsp+8h] [rbp-20h]

score = xmalloc(4LL * size);
roundbout = xmalloc(4LL * size);
fitness = xmalloc(8LL * size);
hista = xmalloc(4LL * hlen);
histb = xmalloc(4LL * hlen);
dnaindex = xmalloc(4LL * (hlen + 2));
*(_DWORD *)dnaindex = 0;
if ( hlen >= 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
v2 = v0;
v0 += 4LL;
v8 = (double)*(int *)(dnaindex + v2);
*(_DWORD *)(dnaindex + v0) = (int)(pow(2.0, (double)(2 * (int)v1++)) + v8);
}
while ( hlen >= (int)v1 );
}
oldpop = xmalloc(8LL * size);
result = xmalloc(8LL * size);
newpop = result;
if ( size > 0 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)(oldpop + 8 * v4);
*v5 = xmalloc(*(int *)(dnaindex + 4LL * hlen + 4));
v6 = (_QWORD *)(newpop + 8 * v4);
*v6 = xmalloc(*(int *)(dnaindex + 4LL * hlen + 4));
result = dnaindex;
if ( *(int *)(dnaindex + 4LL * hlen + 4) > 0 )
{
v7 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(oldpop + 8 * v4) + v7++) = random() % 2;
result = dnaindex;
}
while ( *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)v7 );
}
++v4;
}
while ( size > (int)v4 );
}
return result;
}

original_code:
void inititalize_population(void)
{
  int i, j;
  score = xmalloc(sizeof(int) * size);
  roundbout = xmalloc(sizeof(int) * size);
  fitness = xmalloc(sizeof(double) * size);
  hista = xmalloc(sizeof(int) * hlen);
  histb = xmalloc(sizeof(int) * hlen);
  dnaindex = xmalloc(sizeof(int) * (hlen + 2));
  dnaindex[0] = 0;
  for(i = 1; i < hlen + 2; i++)
    dnaindex[i] = dnaindex[i - 1] + pow(2, (i - 1) * 2);
  oldpop = xmalloc(sizeof(char *) * size);
  newpop = xmalloc(sizeof(char *) * size);
  for(i = 0; i < size; i++) {
    oldpop[i] = xmalloc(sizeof(char) * dnaindex[hlen + 1]);
    newpop[i] = xmalloc(sizeof(char) * dnaindex[hlen + 1]);
    for(j = 0; j < dnaindex[hlen + 1]; j++)
      oldpop[i][j] = random() % 2;
  }
}

canonical_original_code:
void inititalize_population()
{
  int i; int j;
  score = xmalloc(sizeof(int) * size);
  roundbout = xmalloc(sizeof(int) * size);
  fitness = xmalloc(sizeof(double) * size);
  hista = xmalloc(sizeof(int) * hlen);
  histb = xmalloc(sizeof(int) * hlen);
  dnaindex = xmalloc(sizeof(int) * (hlen + 2));
  dnaindex[0] = 0;
  for(i = 1; i < hlen + 2; i++)
    dnaindex[i] = dnaindex[i - 1] + pow(2, (i - 1) * 2);
  oldpop = xmalloc(sizeof(char *) * size);
  newpop = xmalloc(sizeof(char *) * size);
  for(i = 0; i < size; i++) {
    oldpop[i] = xmalloc(sizeof(char) * dnaindex[hlen + 1]);
    newpop[i] = xmalloc(sizeof(char) * dnaindex[hlen + 1]);
    for(j = 0; j < dnaindex[hlen + 1]; j++)
      oldpop[i][j] = random() % 2;
  }
}

variable_types: i int

variable_types: j int


decompiled_code:
void compute_fitness()
{
__int64 v0; // rax
int v1; // edx
int v2; // er13
__int64 v3; // rbp
int v4; // ebx
int i; // er15
__int64 v6; // rax
double v7; // xmm1_8
__int64 v8; // rax
__int64 v9; // [rsp+0h] [rbp-50h]
int v10; // [rsp+10h] [rbp-40h] BYREF
int v11[15]; // [rsp+14h] [rbp-3Ch] BYREF

if ( size > 0 )
{
v0 = 0LL;
do
{
*(_DWORD *)(score + 4 * v0) = 0;
*(_DWORD *)(roundbout + 4 * v0++) = 0;
}
while ( size > (int)v0 );
if ( size > 0 )
{
v9 = 0LL;
do
{
for ( i = 0; bouts > i; ++i )
{
v1 = random() % size;
v2 = v1;
v10 = 0;
v11[0] = 0;
if ( rounds > 0 )
{
v3 = 4LL * v1;
v4 = 0;
do
{
ipd(v9, v2, v4, v11, &v10);
*(_DWORD *)(score + 4 * v9) += v11[0];
*(_DWORD *)(score + v3) += v10;
++*(_DWORD *)(roundbout + 4 * v9);
++*(_DWORD *)(roundbout + v3);
++v4;
}
while ( rounds > v4 );
}
}
++v9;
}
while ( size > (int)v9 );
if ( size > 0 )
{
v6 = 0LL;
v7 = 0.0;
do
{
*(double *)(fitness + 8 * v6) = (double)*(int *)(score + 4 * v6) / (double)*(int *)(roundbout + 4 * v6);
v7 = v7 + *(double *)(fitness + 8 * v6++);
}
while ( size > (int)v6 );
if ( size > 0 )
{
v8 = 0LL;
do
{
*(double *)(fitness + 8 * v8) = *(double *)(fitness + 8 * v8) / v7;
++v8;
}
while ( size > (int)v8 );
}
}
}
}
}

canonical_decompiled_code:
void func2()
{
__int64 v0; // rax
int v1; // edx
int v2; // er13
__int64 v3; // rbp
int v4; // ebx
int i; // er15
__int64 v6; // rax
double v7; // xmm1_8
__int64 v8; // rax
__int64 v9; // [rsp+0h] [rbp-50h]
int v10; // [rsp+10h] [rbp-40h] BYREF
int v11[15]; // [rsp+14h] [rbp-3Ch] BYREF

if ( size > 0 )
{
v0 = 0LL;
do
{
*(_DWORD *)(score + 4 * v0) = 0;
*(_DWORD *)(roundbout + 4 * v0++) = 0;
}
while ( size > (int)v0 );
if ( size > 0 )
{
v9 = 0LL;
do
{
for ( i = 0; bouts > i; ++i )
{
v1 = random() % size;
v2 = v1;
v10 = 0;
v11[0] = 0;
if ( rounds > 0 )
{
v3 = 4LL * v1;
v4 = 0;
do
{
func1(v9, v2, v4, v11, &v10);
*(_DWORD *)(score + 4 * v9) += v11[0];
*(_DWORD *)(score + v3) += v10;
++*(_DWORD *)(roundbout + 4 * v9);
++*(_DWORD *)(roundbout + v3);
++v4;
}
while ( rounds > v4 );
}
}
++v9;
}
while ( size > (int)v9 );
if ( size > 0 )
{
v6 = 0LL;
v7 = 0.0;
do
{
*(double *)(fitness + 8 * v6) = (double)*(int *)(score + 4 * v6) / (double)*(int *)(roundbout + 4 * v6);
v7 = v7 + *(double *)(fitness + 8 * v6++);
}
while ( size > (int)v6 );
if ( size > 0 )
{
v8 = 0LL;
do
{
*(double *)(fitness + 8 * v8) = *(double *)(fitness + 8 * v8) / v7;
++v8;
}
while ( size > (int)v8 );
}
}
}
}
}

original_code:
void compute_fitness(void)
{
  int i, j, k, opponent, scorea, scoreb;
  double sum;
  for(i = 0; i < size; i++)
    roundbout[i] = score[i] = 0;
  for(i = 0; i < size; i++)
    for(j = 0; j < bouts; j++) {
      opponent = random() % size;
      scorea = scoreb = 0;
      for(k = 0; k < rounds; k++) {
        ipd(i, opponent, k, &scorea, &scoreb);
        score[i] += scorea;
        score[opponent] += scoreb;
        roundbout[i]++;
        roundbout[opponent]++;
      }
    }
  sum = 0;
  for(i = 0; i < size; i++) {
    fitness[i] = score[i] / (double) roundbout[i];
    sum += fitness[i];
  }
  for(i = 0; i < size; i++)
    fitness[i] /= sum;
}

canonical_original_code:
void compute_fitness()
{
  int i; int j; int k; int opponent; int scorea; int scoreb;
  double sum;
  for(i = 0; i < size; i++)
    roundbout[i] = score[i] = 0;
  for(i = 0; i < size; i++)
    for(j = 0; j < bouts; j++) {
      opponent = random() % size;
      scorea = scoreb = 0;
      for(k = 0; k < rounds; k++) {
        ipd(i, opponent, k, &scorea, &scoreb);
        score[i] += scorea;
        score[opponent] += scoreb;
        roundbout[i]++;
        roundbout[opponent]++;
      }
    }
  sum = 0;
  for(i = 0; i < size; i++) {
    fitness[i] = score[i] / (double) roundbout[i];
    sum += fitness[i];
  }
  for(i = 0; i < size; i++)
    fitness[i] /= sum;
}

variable_types: k int

variable_types: opponent int

variable_types: scorea int

variable_types: scoreb int

variable_types: sum double


decompiled_code:
__int64 __fastcall select_one(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
__int64 v3; // rax
double v4; // xmm0_8
unsigned int v5; // edx

v1 = random_range(0.0, 1.0);
if ( size <= 0 )
return (unsigned int)(size - 1);
v2 = v1;
v3 = 0LL;
v4 = 0.0;
while ( 1 )
{
v5 = v3;
v4 = v4 + *(double *)(a1 + 8 * v3);
if ( v4 >= v2 )
break;
if ( ++v3 == size )
return (unsigned int)(size - 1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
__int64 v3; // rax
double v4; // xmm0_8
unsigned int v5; // edx

v1 = random_range(0.0, 1.0);
if ( size <= 0 )
return (unsigned int)(size - 1);
v2 = v1;
v3 = 0LL;
v4 = 0.0;
while ( 1 )
{
v5 = v3;
v4 = v4 + *(double *)(a1 + 8 * v3);
if ( v4 >= v2 )
break;
if ( ++v3 == size )
return (unsigned int)(size - 1);
}
return v5;
}

variable_types:
normfit
double *

variable_types: x double


reproduce

decompiled_code:
void __fastcall reproduce(int a1, int a2, int a3)
{
int v4; // ebp
int v5; // edx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // r12
__int64 i; // rbx

v4 = *(_DWORD *)(dnaindex + 4LL * hlen + 4);
if ( *(double *)&crate > random_range(0.0, 1.0) )
{
v5 = random() % (v4 - 1) + 1;
if ( v5 <= 0 )
goto LABEL_5;
}
else
{
v5 = v4;
if ( v4 <= 0 )
goto LABEL_8;
}
v6 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3) + v6) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a1) + v6);
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3 + 8) + v6) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a2) + v6);
++v6;
}
while ( v6 != v5 );
LABEL_5:
if ( v4 > v5 )
{
v7 = v5;
do
{
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3) + v7) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a2) + v7);
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3 + 8) + v7) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a1) + v7);
++v7;
}
while ( v7 != v5 + (unsigned __int64)(unsigned int)(v4 - 1 - v5) + 1 );
}
LABEL_8:
if ( v4 > 0 )
{
v8 = 8LL * a3;
for ( i = 0LL; i != v4; ++i )
{
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(*(_QWORD *)(newpop + v8) + i) = random() % 2;
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(*(_QWORD *)(newpop + v8 + 8) + i) = random() % 2;
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, int a2, int a3)
{
int v4; // ebp
int v5; // edx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // r12
__int64 i; // rbx

v4 = *(_DWORD *)(dnaindex + 4LL * hlen + 4);
if ( *(double *)&crate > random_range(0.0, 1.0) )
{
v5 = random() % (v4 - 1) + 1;
if ( v5 <= 0 )
goto LABEL_5;
}
else
{
v5 = v4;
if ( v4 <= 0 )
goto LABEL_8;
}
v6 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3) + v6) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a1) + v6);
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3 + 8) + v6) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a2) + v6);
++v6;
}
while ( v6 != v5 );
LABEL_5:
if ( v4 > v5 )
{
v7 = v5;
do
{
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3) + v7) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a2) + v7);
*(_BYTE *)(*(_QWORD *)(newpop + 8LL * a3 + 8) + v7) = *(_BYTE *)(*(_QWORD *)(oldpop + 8LL * a1) + v7);
++v7;
}
while ( v7 != v5 + (unsigned __int64)(unsigned int)(v4 - 1 - v5) + 1 );
}
LABEL_8:
if ( v4 > 0 )
{
v8 = 8LL * a3;
for ( i = 0LL; i != v4; ++i )
{
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(*(_QWORD *)(newpop + v8) + i) = random() % 2;
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(*(_QWORD *)(newpop + v8 + 8) + i) = random() % 2;
}
}
}

original_code:
void reproduce(int parenta, int parentb, int childindex)
{
  int i, cpoint, dnalen;
  dnalen = dnaindex[hlen + 1];
  cpoint = (random_range(0, 1) < crate) ?
    (random() % (dnalen - 1)) + 1 : dnalen;
  for(i = 0; i < cpoint; i++) {
    newpop[childindex][i] = oldpop[parenta][i];
    newpop[childindex + 1][i] = oldpop[parentb][i];
  }
  for(i = cpoint; i < dnalen; i++) {
    newpop[childindex][i] = oldpop[parentb][i];
    newpop[childindex + 1][i] = oldpop[parenta][i];
  }
  for(i = 0; i < dnalen; i++) {
    if(random_range(0, 1) < mrate)
      newpop[childindex][i] = random() % 2;
    if(random_range(0, 1) < mrate)
      newpop[childindex + 1][i] = random() % 2;
  }
}

canonical_original_code:
void reproduce(int parenta, int parentb, int childindex)
{
  int i; int cpoint; int dnalen;
  dnalen = dnaindex[hlen + 1];
  cpoint = (random_range(0, 1) < crate) ?
    (random() % (dnalen - 1)) + 1 : dnalen;
  for(i = 0; i < cpoint; i++) {
    newpop[childindex][i] = oldpop[parenta][i];
    newpop[childindex + 1][i] = oldpop[parentb][i];
  }
  for(i = cpoint; i < dnalen; i++) {
    newpop[childindex][i] = oldpop[parentb][i];
    newpop[childindex + 1][i] = oldpop[parenta][i];
  }
  for(i = 0; i < dnalen; i++) {
    if(random_range(0, 1) < mrate)
      newpop[childindex][i] = random() % 2;
    if(random_range(0, 1) < mrate)
      newpop[childindex + 1][i] = random() % 2;
  }
}

variable_types: parenta int

variable_types: parentb int

variable_types: childindex int

variable_types: cpoint int

variable_types: dnalen int


decompiled_code:
int __fastcall dump_stats(unsigned int a1)
{
int v1; // ebp
__int64 v2; // rax
double v3; // xmm1_8
int v4; // ebx
double v5; // xmm0_8
bool v6; // cc
__int64 v7; // rbp
__int64 v8; // rbx
double v10; // [rsp+8h] [rbp-20h]

v1 = size;
if ( size <= 0 )
{
v10 = 0.0;
v4 = -1;
}
else
{
v2 = 0LL;
v10 = 0.0;
v3 = *(double *)&LC2;
v4 = -1;
do
{
v5 = *(double *)(fitness + 8 * v2);
v6 = v5 <= v3;
v3 = fmax(v5, v3);
if ( !v6 )
v4 = v2;
v10 = (double)*(int *)(score + 4 * v2) / (double)*(int *)(roundbout + 4 * v2) + v10;
++v2;
}
while ( v2 != size );
}
fprintf(stderr, "---\ntime = %d\n", a1);
fprintf(stderr, "average score = %f\n", v10 / (double)v1);
fprintf(
stderr,
"best average score = %f\n",
(double)*(int *)(score + 4LL * v4) / (double)*(int *)(roundbout + 4LL * v4));
fwrite("best = ", 1uLL, 7uLL, stderr);
if ( *(int *)(dnaindex + 4LL * hlen + 4) > 0 )
{
v7 = 8LL * v4;
v8 = 0LL;
do
fputc(*(char *)(*(_QWORD *)(oldpop + v7) + v8++) + 67, stderr);
while ( *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)v8 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
int v1; // ebp
__int64 v2; // rax
double v3; // xmm1_8
int v4; // ebx
double v5; // xmm0_8
bool v6; // cc
__int64 v7; // rbp
__int64 v8; // rbx
double v10; // [rsp+8h] [rbp-20h]

v1 = size;
if ( size <= 0 )
{
v10 = 0.0;
v4 = -1;
}
else
{
v2 = 0LL;
v10 = 0.0;
v3 = *(double *)&LC2;
v4 = -1;
do
{
v5 = *(double *)(fitness + 8 * v2);
v6 = v5 <= v3;
v3 = fmax(v5, v3);
if ( !v6 )
v4 = v2;
v10 = (double)*(int *)(score + 4 * v2) / (double)*(int *)(roundbout + 4 * v2) + v10;
++v2;
}
while ( v2 != size );
}
fprintf(stderr, "---\ntime = %d\n", a1);
fprintf(stderr, "average score = %f\n", v10 / (double)v1);
fprintf(
stderr,
"best average score = %f\n",
(double)*(int *)(score + 4LL * v4) / (double)*(int *)(roundbout + 4LL * v4));
fwrite("best = ", 1uLL, 7uLL, stderr);
if ( *(int *)(dnaindex + 4LL * hlen + 4) > 0 )
{
v7 = 8LL * v4;
v8 = 0LL;
do
fputc(*(char *)(*(_QWORD *)(oldpop + v7) + v8++) + 67, stderr);
while ( *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)v8 );
}
return fputc(10, stderr);
}

original_code:
void dump_stats(int time)
{
  int i, besti = -1;
  double best = -1, ave = 0;
  for(i = 0; i < size; i++) {
    if(fitness[i] > best) {
      besti = i; best = fitness[i];
    }
    ave += score[i] / (double) roundbout[i];
  }
  ave /= size;
  fprintf(stderr, "---\ntime = %d\n", time);
  fprintf(stderr, "average score = %f\n", ave);
  fprintf(stderr, "best average score = %f\n", score[besti] /
         (double)roundbout[besti]);
  fprintf(stderr, "best = ");
  for(i = 0; i < dnaindex[hlen + 1]; i++)
    fputc(oldpop[besti][i] + 'C', stderr);
  fputc('\n', stderr);
}

canonical_original_code:
void dump_stats(int time)
{
  int i; int besti = -1;
  double best = -1; double ave = 0;
  for(i = 0; i < size; i++) {
    if(fitness[i] > best) {
      besti = i; best = fitness[i];
    }
    ave += score[i] / (double) roundbout[i];
  }
  ave /= size;
  fprintf(stderr, "---\ntime = %d\n", time);
  fprintf(stderr, "average score = %f\n", ave);
  fprintf(stderr, "best average score = %f\n", score[besti] /
         (double)roundbout[besti]);
  fprintf(stderr, "best = ");
  for(i = 0; i < dnaindex[hlen + 1]; i++)
    fputc(oldpop[besti][i] + 'C', stderr);
  fputc('\n', stderr);
}

variable_types: time int

variable_types: besti int

variable_types: best double

variable_types: ave double


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
signed int v3; // er12
int v4; // ebx
int v5; // ebp
int v6; // eax
__int64 v7; // rax
__int64 i; // r12
__int64 j; // rbx

get_options(argc, argv, &options, help_string);
srandom(seed);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
inititalize_population();
if ( gens > 0 )
{
v3 = 0;
do
{
compute_fitness();
dump_stats(v3);
if ( size > 0 )
{
v4 = 0;
do
{
v5 = select_one(fitness);
v6 = select_one(fitness);
reproduce(v5, v6, v4);
v4 += 2;
}
while ( size > v4 );
}
v7 = newpop;
newpop = oldpop;
oldpop = v7;
++v3;
}
while ( gens > v3 );
}
if ( dump )
{
for ( i = 0LL; size > (int)i; ++i )
{
for ( j = 0LL; *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)j; ++j )
fputc(*(char *)(*(_QWORD *)(oldpop + 8 * i) + j) + 67, stdout);
fputc(10, stdout);
}
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
signed int v3; // er12
int v4; // ebx
int v5; // ebp
int v6; // eax
__int64 v7; // rax
__int64 i; // r12
__int64 j; // rbx

get_options(argc, argv, &options, help_string);
srandom(seed);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
func6();
if ( gens > 0 )
{
v3 = 0;
do
{
func2();
func5(v3);
if ( size > 0 )
{
v4 = 0;
do
{
v5 = func3(fitness);
v6 = func3(fitness);
func4(v5, v6, v4);
v4 += 2;
}
while ( size > v4 );
}
v7 = newpop;
newpop = oldpop;
oldpop = v7;
++v3;
}
while ( gens > v3 );
}
if ( dump )
{
for ( i = 0LL; size > (int)i; ++i )
{
for ( j = 0LL; *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)j; ++j )
fputc(*(char *)(*(_QWORD *)(oldpop + 8 * i) + j) + 67, stdout);
fputc(10, stdout);
}
}
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  int t, i, j, parent_a, parent_b;
  char **swap;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  size += (size / 2 * 2 != size);
  inititalize_population();
  for(t = 0; t < gens; t++) {
    compute_fitness();
    dump_stats(t);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(fitness);
      parent_b = select_one(fitness);
      reproduce(parent_a, parent_b, i);
    }
    swap = newpop; newpop = oldpop; oldpop = swap;
  }
  if(dump)
    for(j = 0; j < size; j++) {
      for(i = 0; i < dnaindex[hlen + 1]; i++)
        fputc(oldpop[j][i] + 'C', stdout);
      fputc('\n', stdout);
    }
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  int t; int i; int j; int parent_a; int parent_b;
  char **swap;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  size += (size / 2 * 2 != size);
  inititalize_population();
  for(t = 0; t < gens; t++) {
    compute_fitness();
    dump_stats(t);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(fitness);
      parent_b = select_one(fitness);
      reproduce(parent_a, parent_b, i);
    }
    swap = newpop; newpop = oldpop; oldpop = swap;
  }
  if(dump)
    for(j = 0; j < size; j++) {
      for(i = 0; i < dnaindex[hlen + 1]; i++)
        fputc(oldpop[j][i] + 'C', stdout);
      fputc('\n', stdout);
    }
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: t int

variable_types: i int

variable_types: j int

variable_types:
swap
char **


repo: ramfjord/audiomark

decompiled_code:
__int64 __fastcall get_deinterleave_i(int a1, int a2, int a3)
{
return (unsigned int)(a2 * (a1 % a3) + a1 / a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
return (unsigned int)(a2 * (a1 % a3) + a1 / a3);
}

original_code:
int get_deinterleave_i(int i, int size, int channels)
{
 int c = i % channels;
 int new_i = i / channels;
 return size*c + new_i;
}

variable_types: size int

variable_types: channels int

variable_types: c int


decompiled_code:
__int64 __fastcall get_interleave_i(int a1, int a2, int a3)
{
return (unsigned int)(a3 * (a1 % a2) + a1 / a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3)
{
return (unsigned int)(a3 * (a1 % a2) + a1 / a2);
}

original_code:
int get_interleave_i(int i, int size, int channels)
{
 int c = i / size;
 int new_i = i % size;
 return new_i * channels + c;
}


original_code:
void gen_default_wmark()
{
  wmark = (watermark *)malloc(sizeof(watermark));
 wmark->len = 500;
  wmark->message = malloc(wmark->len);
  wmark->alpha = .1;
  wmark->schema = 1;
 wmark->type = 1;
 wmark->processing_gain = 10;
  wmark->key_seed = 15;
 wmark->bpf = 20;
}

canonical_original_code:
void gen_default_wmark()
{
  wmark = (struct watermark *)malloc(sizeof(watermark));
 wmark->len = 500;
  wmark->message = malloc(wmark->len);
  wmark->alpha = .1;
  wmark->schema = 1;
 wmark->type = 1;
 wmark->processing_gain = 10;
  wmark->key_seed = 15;
 wmark->bpf = 20;
}

user_defined_types: struct watermark { char *message; int len; int schema; double alpha; unsigned int key_seed; int processing_gain; int type; int bpf; }


decompiled_code:
void *__fastcall interleave_d_array(__int64 a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 (__fastcall *v4)(int, int, int); // rax
int v5; // ebx
void *v6; // rsp
void *result; // rax
__int64 v8; // r13
int v9; // ebx
__int64 *v10; // [rsp+0h] [rbp-60h] BYREF
void *v11; // [rsp+8h] [rbp-58h]
unsigned int v12; // [rsp+10h] [rbp-50h]
unsigned int v13; // [rsp+14h] [rbp-4Ch]
__int64 (__fastcall *v14)(int, int, int); // [rsp+18h] [rbp-48h]
__int64 v15[7]; // [rsp+28h] [rbp-38h] BYREF

v13 = a2;
v12 = a3;
v4 = get_deinterleave_i;
if ( a4 )
v4 = get_interleave_i;
v14 = v4;
v5 = a3 * a2;
v6 = alloca((int)(a3 * a2));
result = memset(&v10, 0, (int)(a3 * a2));
if ( v5 > 2 )
{
result = (void *)((unsigned int)(v5 - 3) + 2LL);
v11 = result;
v8 = 1LL;
do
{
if ( !*((_BYTE *)&v10 + v8) )
{
v10 = (__int64 *)(a1 + 8 * v8);
v15[0] = *v10;
v9 = v14(v8, v13, v12);
*((_BYTE *)&v10 + v8) = 1;
while ( v9 != (_DWORD)v8 )
{
swap_d(v15, a1 + 8LL * v9);
*((_BYTE *)&v10 + v9) = 1;
v9 = v14(v9, v13, v12);
if ( !v9 )
exit(1);
}
result = (void *)swap_d(v15, v10);
}
++v8;
}
while ( (void *)v8 != v11 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 (__fastcall *v4)(int, int, int); // rax
int v5; // ebx
void *v6; // rsp
void *result; // rax
__int64 v8; // r13
int v9; // ebx
__int64 *v10; // [rsp+0h] [rbp-60h] BYREF
void *v11; // [rsp+8h] [rbp-58h]
unsigned int v12; // [rsp+10h] [rbp-50h]
unsigned int v13; // [rsp+14h] [rbp-4Ch]
__int64 (__fastcall *v14)(int, int, int); // [rsp+18h] [rbp-48h]
__int64 v15[7]; // [rsp+28h] [rbp-38h] BYREF

v13 = a2;
v12 = a3;
v4 = get_deinterleave_i;
if ( a4 )
v4 = get_interleave_i;
v14 = v4;
v5 = a3 * a2;
v6 = alloca((int)(a3 * a2));
result = memset(&v10, 0, (int)(a3 * a2));
if ( v5 > 2 )
{
result = (void *)((unsigned int)(v5 - 3) + 2LL);
v11 = result;
v8 = 1LL;
do
{
if ( !*((_BYTE *)&v10 + v8) )
{
v10 = (__int64 *)(a1 + 8 * v8);
v15[0] = *v10;
v9 = v14(v8, v13, v12);
*((_BYTE *)&v10 + v8) = 1;
while ( v9 != (_DWORD)v8 )
{
swap_d(v15, a1 + 8LL * v9);
*((_BYTE *)&v10 + v9) = 1;
v9 = v14(v9, v13, v12);
if ( !v9 )
exit(1);
}
result = (void *)swap_d(v15, v10);
}
++v8;
}
while ( (void *)v8 != v11 );
}
return result;
}

original_code:
void interleave_d_array(double *buff, int size, int channels, int fwd)
{
 int (*interleave_i)(int,int,int) = (fwd) ? &get_interleave_i : &get_deinterleave_i;
 int n = size*channels;
 char inplace[n];
 memset(inplace,0,n);
 for(int i = 1; i < n-1; i++){
  if(inplace[i]) continue;
  double swp = buff[i];
  int j = interleave_i(i,size,channels);
  inplace[i] = 1;
  while(j != i){
   swap_d(&swp, &buff[j]);
   inplace[j] = 1;
   j = interleave_i(j,size,channels);
   if(j == 0) exit(1);
  }
  swap_d(&swp, &buff[i]);
 }
}

canonical_original_code:
void interleave_d_array(double *buff, int size, int channels, int fwd)
{
 int (*interleave_i)(int, int, int) = (fwd) ? &get_interleave_i : &get_deinterleave_i;
 int n = size*channels;
 char inplace[-1];
 memset(inplace,0,n);
 for(int i = 1; i < n-1; i++){
  if(inplace[i]) continue;
  double swp = buff[i];
  int j = interleave_i(i,size,channels);
  inplace[i] = 1;
  while(j != i){
   swap_d(&swp, &buff[j]);
   inplace[j] = 1;
   j = interleave_i(j,size,channels);
   if(j == 0) exit(1);
  }
  swap_d(&swp, &buff[i]);
 }
}

variable_types:
buff
double *

variable_types: fwd int

variable_types: n int

variable_types:
inplace
char [-1]

variable_types: swp double


decompiled_code:
void *__fastcall deinterleave_channels(__int64 a1, unsigned int a2)
{
return interleave_d_array(a1, 0x400u, a2, 0);
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, unsigned int a2)
{
return func4(a1, 0x400u, a2, 0);
}

original_code:
void deinterleave_channels(double *time_buff, int channels){
 interleave_d_array(time_buff, 1024, channels, 0);
}


decompiled_code:
void *__fastcall interleave_channels(__int64 a1, unsigned int a2)
{
return interleave_d_array(a1, 0x400u, a2, 1);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, unsigned int a2)
{
return func4(a1, 0x400u, a2, 1);
}

original_code:
void interleave_channels(double *time_buff, int channels){
 interleave_d_array(time_buff, 1024, channels, 1);
}


decompiled_code:
void free_wmark()
{
free(*(void **)wmark);
free(wmark);
}

canonical_decompiled_code:
void func7()
{
free(*(void **)wmark);
free(wmark);
}

original_code:
void free_wmark()
{
 free(wmark->message);
 free(wmark);
}


decompiled_code:
__int64 __fastcall get_schema(char *haystack)
{
if ( strstr(haystack, "plus") )
{
*((_DWORD *)wmark + 3) = 0;
return *((unsigned int *)wmark + 3);
}
if ( strstr(haystack, "mult") )
{
*((_DWORD *)wmark + 3) = 1;
return *((unsigned int *)wmark + 3);
}
if ( strstr(haystack, "powr") )
{
*((_DWORD *)wmark + 3) = 2;
return *((unsigned int *)wmark + 3);
}
fwrite("Invalid Schema: the valid schemas are plus, mult, and powr. \n", 1uLL, 0x3DuLL, stderr);
fwrite("plus: v'_i = v_i+aw_i\n", 1uLL, 0x16uLL, stderr);
fwrite("mult: v'_i = v_i(1+aw_i)\n", 1uLL, 0x19uLL, stderr);
fwrite("powr: v'_i = v_i(e*a^w_i)\n", 1uLL, 0x1AuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *haystack)
{
if ( strstr(haystack, "plus") )
{
*((_DWORD *)wmark + 3) = 0;
return *((unsigned int *)wmark + 3);
}
if ( strstr(haystack, "mult") )
{
*((_DWORD *)wmark + 3) = 1;
return *((unsigned int *)wmark + 3);
}
if ( strstr(haystack, "powr") )
{
*((_DWORD *)wmark + 3) = 2;
return *((unsigned int *)wmark + 3);
}
fwrite("Invalid Schema: the valid schemas are plus, mult, and powr. \n", 1uLL, 0x3DuLL, stderr);
fwrite("plus: v'_i = v_i+aw_i\n", 1uLL, 0x16uLL, stderr);
fwrite("mult: v'_i = v_i(1+aw_i)\n", 1uLL, 0x19uLL, stderr);
fwrite("powr: v'_i = v_i(e*a^w_i)\n", 1uLL, 0x1AuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int get_schema(char *s)
{
  if(strstr(s, "plus"))
    wmark->schema = 0;
  else if(strstr(s, "mult"))
    wmark->schema = 1;
  else if(strstr(s, "powr"))
    wmark->schema = 2;
  else{
    fprintf(stderr, "Invalid Schema: the valid schemas are plus, mult, and powr. \n");
    fprintf(stderr, "plus: v'_i = v_i+aw_i\n");
    fprintf(stderr, "mult: v'_i = v_i(1+aw_i)\n");
    fprintf(stderr, "powr: v'_i = v_i(e*a^w_i)\n");
    return (-1);
  }
  return wmark->schema;
}

variable_types:
s
char *


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

if ( a1 == 1 )
{
*((_DWORD *)wmark + 3) = 1;
result = 1LL;
}
else if ( a1 == 2 )
{
*((_DWORD *)wmark + 3) = 2;
result = 2LL;
}
else if ( a1 )
{
puts("The valid schemas are plus, mult, and powr. ");
puts("plus: v'_i = v_i+aw_i");
puts("mult: v'_i = v_i(1+aw_i)");
puts("powr: v'_i = v_i(e*a^w_i)");
result = 0xFFFFFFFFLL;
}
else
{
*((_DWORD *)wmark + 3) = 0;
result = 0LL;
}
return result;
}

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

if ( a1 == 1 )
{
*((_DWORD *)wmark + 3) = 1;
result = 1LL;
}
else if ( a1 == 2 )
{
*((_DWORD *)wmark + 3) = 2;
result = 2LL;
}
else if ( a1 )
{
puts("The valid schemas are plus, mult, and powr. ");
puts("plus: v'_i = v_i+aw_i");
puts("mult: v'_i = v_i(1+aw_i)");
puts("powr: v'_i = v_i(e*a^w_i)");
result = 0xFFFFFFFFLL;
}
else
{
*((_DWORD *)wmark + 3) = 0;
result = 0LL;
}
return result;
}

original_code:
int set_schema(int s)
{
  switch (s) {
    case 0: wmark->schema = 0; return 0;
    case 1: wmark->schema = 1; return 1;
    case 2: wmark->schema = 2; return 2;
    default:
      printf("The valid schemas are plus, mult, and powr. \n");
      printf("plus: v'_i = v_i+aw_i\n");
      printf("mult: v'_i = v_i(1+aw_i)\n");
      printf("powr: v'_i = v_i(e*a^w_i)\n");
  }
  return -1;
}

variable_types: s int


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

result = (unsigned int)a1;
*((double *)wmark + 2) = (double)a1;
return result;
}

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

result = (unsigned int)a1;
*((double *)wmark + 2) = (double)a1;
return result;
}

original_code:
int set_alpha(int a){
  wmark->alpha = a;
  return a;
}

variable_types: a int


decompiled_code:
int print_watermark_info()
{
unsigned int *v0; // rbx
size_t v1; // rax
const char *v2; // rsi

puts("watermark info:");
printf("\twatermark: >%s<\n", *(const char **)wmark);
v0 = (unsigned int *)wmark;
v1 = strlen(*(const char **)wmark);
printf("\tlen (real %d), %d\n", v1, v0[2]);
printf("\talpha: %lf\n", *((double *)wmark + 2));
printf("\tschema: %d\n", *((unsigned int *)wmark + 3));
printf("\tkey_seed: %u\n", *((unsigned int *)wmark + 6));
printf("\tprocessing_gain: %d\n", *((unsigned int *)wmark + 7));
v2 = "fh";
if ( *((_DWORD *)wmark + 8) != 2 )
v2 = "ss";
printf("\ttype = %s\n", v2);
return printf("\tbpf = %d\n", *((unsigned int *)wmark + 9));
}

canonical_decompiled_code:
int func12()
{
unsigned int *v0; // rbx
size_t v1; // rax
const char *v2; // rsi

puts("watermark info:");
printf("\twatermark: >%s<\n", *(const char **)wmark);
v0 = (unsigned int *)wmark;
v1 = strlen(*(const char **)wmark);
printf("\tlen (real %d), %d\n", v1, v0[2]);
printf("\talpha: %lf\n", *((double *)wmark + 2));
printf("\tschema: %d\n", *((unsigned int *)wmark + 3));
printf("\tkey_seed: %u\n", *((unsigned int *)wmark + 6));
printf("\tprocessing_gain: %d\n", *((unsigned int *)wmark + 7));
v2 = "fh";
if ( *((_DWORD *)wmark + 8) != 2 )
v2 = "ss";
printf("\ttype = %s\n", v2);
return printf("\tbpf = %d\n", *((unsigned int *)wmark + 9));
}

original_code:
void print_watermark_info()
{
  printf("watermark info:\n");
  printf("\twatermark: >%s<\n",wmark->message);
  printf("\tlen (real %d), %d\n", strlen(wmark->message), wmark->len);
  printf("\talpha: %lf\n",wmark->alpha);
  printf("\tschema: %d\n",wmark->schema);
  printf("\tkey_seed: %u\n",wmark->key_seed);
  printf("\tprocessing_gain: %d\n", wmark->processing_gain);
  printf("\ttype = %s\n", (wmark->type == 2) ? "fh" : "ss");
  printf("\tbpf = %d\n", wmark->bpf);
}


decompiled_code:
int __fastcall print_sfile_info(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, unsigned int a10)
{
puts("sound file info:");
printf("\tsamplerate: %d\n", (unsigned int)a8);
printf("\tchannels: %d\n", HIDWORD(a8));
printf("\tsections: %d\n", HIDWORD(a9));
printf("\tformat: %x\n", (unsigned int)a9);
printf("\tframes: %ld\n", a7);
return printf("\tseekable: %d\n", a10);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, unsigned int a10)
{
puts("sound file info:");
printf("\tsamplerate: %d\n", (unsigned int)a8);
printf("\tchannels: %d\n", HIDWORD(a8));
printf("\tsections: %d\n", HIDWORD(a9));
printf("\tformat: %x\n", (unsigned int)a9);
printf("\tframes: %ld\n", a7);
return printf("\tseekable: %d\n", a10);
}

original_code:
void print_sfile_info(SF_INFO sfinfo)
{
  printf("sound file info:\n");
  printf("\tsamplerate: %d\n", sfinfo.samplerate);
  printf("\tchannels: %d\n", sfinfo.channels);
  printf("\tsections: %d\n", sfinfo.sections);
  printf("\tformat: %x\n", sfinfo.format);
  printf("\tframes: %ld\n", (long)sfinfo.frames);
  printf("\tseekable: %d\n", sfinfo.seekable);
}

canonical_original_code:
void print_sfile_info(struct SF_INFO sfinfo)
{
  printf("sound file info:\n");
  printf("\tsamplerate: %d\n", sfinfo.samplerate);
  printf("\tchannels: %d\n", sfinfo.channels);
  printf("\tsections: %d\n", sfinfo.sections);
  printf("\tformat: %x\n", sfinfo.format);
  printf("\tframes: %ld\n", (long)sfinfo.frames);
  printf("\tseekable: %d\n", sfinfo.seekable);
}

variable_types: struct SF_INFO { long frames; int samplerate; int channels; int format; int sections; int seekable; }


decompiled_code:
double __fastcall c_to_d(char a1)
{
return (double)(2 * (a1 % 2) - 1);
}

canonical_decompiled_code:
double __fastcall func14(char a1)
{
return (double)(2 * (a1 % 2) - 1);
}

original_code:
double c_to_d(char a)
{
  return (double) (((a%2)*2) - 1);
}

variable_types: a char


decompiled_code:
void __fastcall generate_noise(double *a1, int a2)
{
double *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = norm_double();
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func16(double *a1, int a2)
{
double *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = norm_double();
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

original_code:
void generate_noise(double *buffer, int buffer_len)
{
  for(int i = 0; i < buffer_len; i++)
  buffer[i] = norm_double();
}

variable_types:
buffer
double *


decompiled_code:
__int64 __fastcall embed_to_noise(_QWORD *a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
int v5; // ecx
_QWORD *v6; // rdx
__int64 v7; // r8
char v8; // r9

result = (__int64)wmark;
v4 = *(_QWORD *)wmark;
if ( a2 > 0 )
{
v5 = index_1;
LODWORD(result) = bit_mask_0;
v6 = a1;
v7 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v8 = 0;
do
{
if ( ((unsigned int)result & *(char *)(v4 + v5)) != 0 )
*v6 ^= LC44;
result = (unsigned int)(2 * result);
if ( !(_BYTE)result )
{
if ( ++v5 >= *((_DWORD *)wmark + 2) )
v5 = (unsigned __int8)result;
result = 1LL;
v8 = 1;
}
++v6;
}
while ( v6 != (_QWORD *)v7 );
bit_mask_0 = result;
if ( v8 )
index_1 = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
int v5; // ecx
_QWORD *v6; // rdx
__int64 v7; // r8
char v8; // r9

result = (__int64)wmark;
v4 = *(_QWORD *)wmark;
if ( a2 > 0 )
{
v5 = index_1;
LODWORD(result) = bit_mask_0;
v6 = a1;
v7 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v8 = 0;
do
{
if ( ((unsigned int)result & *(char *)(v4 + v5)) != 0 )
*v6 ^= LC44;
result = (unsigned int)(2 * result);
if ( !(_BYTE)result )
{
if ( ++v5 >= *((_DWORD *)wmark + 2) )
v5 = (unsigned __int8)result;
result = 1LL;
v8 = 1;
}
++v6;
}
while ( v6 != (_QWORD *)v7 );
bit_mask_0 = result;
if ( v8 )
index_1 = v5;
}
return result;
}

original_code:
void embed_to_noise(double *noise_seq, int noise_len)
{
 static int index = 0;
 static int bit_mask = 1;
 char *message = wmark->message;
 for(int i = 0; i < noise_len; i++){
  if(message[index] & bit_mask)
   noise_seq[i] *= -1;
  bit_mask <<= 1;
  if(! (bit_mask & 0xff)){
   bit_mask = 1;
   index++;
   if(index >= wmark->len)
    index = 0;
  }
 }
}

variable_types: index int

variable_types:
message
char *

variable_types: i int


decompiled_code:
int __fastcall print_array(__int64 a1, int a2, int a3, void (__fastcall *a4)(__int64))
{
__int64 v6; // rbx
int i; // ebp

putchar(91);
a4(a1);
if ( a2 > 1 )
{
v6 = a3 + a1;
for ( i = 1; i != a2; ++i )
{
printf(", ");
a4(v6);
v6 += a3;
}
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, int a2, int a3, void (__fastcall *a4)(__int64))
{
__int64 v6; // rbx
int i; // ebp

putchar(91);
a4(a1);
if ( a2 > 1 )
{
v6 = a3 + a1;
for ( i = 1; i != a2; ++i )
{
printf(", ");
a4(v6);
v6 += a3;
}
}
return puts("]");
}

original_code:
void print_array(char *array, int n, int eltsize, void (*print)(void *))
{
 printf("[");
 print(array);
 for(int i = 1; i < n; i++){
  printf(", ");
  print(&array[i*eltsize]);
 }
 printf("]\n");
}

variable_types:
array
char *

variable_types: eltsize int

variable_types:
print
void (*)(void *)


decompiled_code:
int __fastcall print_d_array(__int64 a1, int a2)
{
return print_array(a1, a2, 8, (void (__fastcall *)(__int64))print_double);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, int a2)
{
return func4(a1, a2, 8, (void (__fastcall *)(__int64))print_double);
}

original_code:
void print_d_array(double *array, int n){
 print_array((char *)array, n, sizeof(double), &_print_double);
}

variable_types:
array
double *


decompiled_code:
int __fastcall print_i_array(__int64 a1, int a2)
{
return print_array(a1, a2, 4, (void (__fastcall *)(__int64))print_int);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2)
{
return func4(a1, a2, 4, (void (__fastcall *)(__int64))print_int);
}

original_code:
void print_i_array(int *array, int n){
 print_array((char *)array, n, sizeof(int), &_print_int);
}

variable_types:
array
int *


decompiled_code:
void __fastcall array_div(int a1, double *a2, int a3)
{
double *v3; // rax
__int64 v4; // rdx

if ( a3 > 0 )
{
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
*v3 = *v3 / (double)a1;
++v3;
}
while ( v3 != (double *)v4 );
}
}

canonical_decompiled_code:
void __fastcall func13(int a1, double *a2, int a3)
{
double *v3; // rax
__int64 v4; // rdx

if ( a3 > 0 )
{
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
*v3 = *v3 / (double)a1;
++v3;
}
while ( v3 != (double *)v4 );
}
}

original_code:
void array_div(int n, double *array, int size){
  for(int i = 0; i < size; i++)
    array[i] /= n;
}

variable_types: n int

variable_types: size int


original_code:
void array_add(double *array, double *addition, int size){
  for(int i = 0; i < size; i++)
    array[i] += addition[i];
}

variable_types:
addition
double *


original_code:
void dub_x_dub_e_dub(double *a, double *b, double *c, int len){
 for(int i = 0; i < len; i++)
  c[i] = a[i] * b[i];
}

variable_types:
a
double *

variable_types:
b
double *

variable_types:
c
double *

variable_types: len int


decompiled_code:
__int64 __fastcall seed_rand(__int64 seedval)
{
srand(seedval);
srand48((unsigned int)seedval);
return (unsigned int)seedval;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 seedval)
{
srand(seedval);
srand48((unsigned int)seedval);
return (unsigned int)seedval;
}

original_code:
unsigned seed_rand(unsigned seed){
  srand(seed);
 srand48((long)seed);
  return seed;
}

canonical_original_code:
unsigned int seed_rand(unsigned int seed){
  srand(seed);
 srand48((long)seed);
  return seed;
}

variable_types:
seed
unsigned int

return_type: unsigned int


decompiled_code:
void free_rand()
{
free(my_random);
}

canonical_decompiled_code:
void func1()
{
free(my_random);
}

original_code:
void free_rand(){
  free(my_random);
}

canonical_original_code:
void free_rand(){
  free(my_random);
}


decompiled_code:
char *__fastcall set_rand(int a1)
{
char *result; // rax

if ( my_random )
free_rand();
random_size = a1;
result = (char *)malloc(4LL * a1);
my_random = result;
if ( a1 > 0 )
{
result = 0LL;
do
{
*((_DWORD *)my_random + (_QWORD)result) = (_DWORD)result;
++result;
}
while ( random_size > (int)result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *result; // rax

if ( my_random )
func1();
random_size = a1;
result = (char *)malloc(4LL * a1);
my_random = result;
if ( a1 > 0 )
{
result = 0LL;
do
{
*((_DWORD *)my_random + (_QWORD)result) = (_DWORD)result;
++result;
}
while ( random_size > (int)result );
}
return result;
}

original_code:
void set_rand(int size){
  if(my_random)
    free_rand();
  random_size = size;
  my_random = (int *)malloc(sizeof(int) * random_size);
  for(int i = 0; i < random_size; i++)
    my_random[i] = i;
}


decompiled_code:
__int64 __fastcall next_rand(unsigned int a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx

if ( (int)(random_size - a1) <= 0 )
{
fprintf(stderr, "n_chosen (%d) is greater than random_size (%d)!!\n", a1, (unsigned int)random_size);
v2 = -1;
}
else
{
v1 = (unsigned int *)((char *)my_random + 4 * (rand() % (int)(random_size - a1)));
v2 = *v1;
*v1 = *((_DWORD *)my_random + (int)(random_size - a1) - 1);
*((_DWORD *)my_random + (int)(random_size - a1) - 1) = v2;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx

if ( (int)(random_size - a1) <= 0 )
{
fprintf(stderr, "n_chosen (%d) is greater than random_size (%d)!!\n", a1, (unsigned int)random_size);
v2 = -1;
}
else
{
v1 = (unsigned int *)((char *)my_random + 4 * (rand() % (int)(random_size - a1)));
v2 = *v1;
*v1 = *((_DWORD *)my_random + (int)(random_size - a1) - 1);
*((_DWORD *)my_random + (int)(random_size - a1) - 1) = v2;
}
return v2;
}

original_code:
int next_rand(int n_chosen){
  if(random_size - n_chosen <= 0){
    fprintf(stderr,"n_chosen (%d) is greater than random_size (%d)!!\n",n_chosen, random_size);
    return -1;
  }
  int i = rand() % (random_size - n_chosen);
  int temp = my_random[i];
  my_random[i] = my_random[random_size - n_chosen - 1];
  my_random[random_size - n_chosen - 1] = temp;
  return temp;
}

variable_types: temp int


decompiled_code:
double rand_double()
{
return drand48();
}

canonical_decompiled_code:
double func4()
{
return drand48();
}

original_code:
double rand_double(){
  return drand48();
}


decompiled_code:
void norm_double()
{
double v0; // rbp
double v1; // xmm0_8
double v2; // rbx
double v3; // xmm0_8
double v4; // r12
double v5; // xmm0_8
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

if ( Z2_def_1 )
{
Z2_def_1 = 0;
return;
}
v0 = rand_double();
v1 = rand_double();
v2 = v1;
if ( v0 == 0.0 )
{
Z2_def_1 = 1;
if ( v1 == 0.0 )
v2 = LC1;
v0 = LC1;
v3 = *(double *)&LC2;
LABEL_10:
v4 = sqrt(v3);
goto LABEL_11;
}
if ( v1 == 0.0 )
v2 = LC1;
Z2_def_1 = 1;
v3 = log(v0) * -2.0;
if ( v3 >= 0.0 )
goto LABEL_10;
v4 = sqrt(v3);
LABEL_11:
sincos(v2 * 6.283185307179586, sinx, (double *)&v6);
*(double *)&Z2_0 = v4 * sinx[0];
v5 = log(v0) * -2.0;
if ( v5 < 0.0 )
sqrt(v5);
}


original_code:
int shuffle_d_arr(double *buffer, int n){
 for(int i = n-1; i >= 0; i--){
  int j = rand() % i;
  double tmp = buffer[i];
  buffer[i] = buffer[j];
  buffer[j] = tmp;
 }
}

variable_types:
buffer
double *

variable_types: j int

variable_types: tmp double


repo: ramfjord/ctrie

decompiled_code:
__int64 __fastcall int_indexer(int *a1)
{
int v1; // edx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)(v1 % 10);
*a1 = v1 / 10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
int v1; // edx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)(v1 % 10);
*a1 = v1 / 10;
return result;
}

original_code:
int int_indexer(void *my_int){
  int *my_real_int = (int *)my_int;
  if(*my_real_int == 0)
    return -1;
  int ret = *my_real_int % 10;
  *my_real_int /= 10;
  return ret;
}

variable_types: ret int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
const char *v6; // rax
const char *v7; // rax
char v9[17]; // [rsp+7h] [rbp-21h] BYREF
__int64 v10; // [rsp+18h] [rbp-10h] BYREF

v3 = init_trymap(int_indexer, 10LL, envp);
v10 = 0x21216F6C6C6568LL;
*(_DWORD *)&v9[13] = 17;
iput_try(v3, &v9[13], &v10);
v4 = size_try(v3);
printf("num elts in mytry: %d\n", v4);
*(_DWORD *)&v9[9] = 23;
strcpy(v9, "goodbye!");
iput_try(v3, &v9[9], v9);
v5 = size_try(v3);
printf("added another, now we have %d elts\n", v5);
*(_DWORD *)&v9[13] = 17;
v6 = (const char *)iget_try(v3, &v9[13]);
printf("found: %s\n", v6);
*(_DWORD *)&v9[9] = 23;
v7 = (const char *)iget_try(v3, &v9[9]);
printf("also found: %s\n", v7);
free_try(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
const char *v6; // rax
const char *v7; // rax
char v9[17]; // [rsp+7h] [rbp-21h] BYREF
__int64 v10; // [rsp+18h] [rbp-10h] BYREF

v3 = init_trymap(int_indexer, 10LL, envp);
v10 = 0x21216F6C6C6568LL;
*(_DWORD *)&v9[13] = 17;
func12(v3, &v9[13], &v10);
v4 = func16(v3);
printf("num elts in mytry: %d\n", v4);
*(_DWORD *)&v9[9] = 23;
strcpy(v9, "goodbye!");
func12(v3, &v9[9], v9);
v5 = func16(v3);
printf("added another, now we have %d elts\n", v5);
*(_DWORD *)&v9[13] = 17;
v6 = (const char *)func15(v3, &v9[13]);
printf("found: %s\n", v6);
*(_DWORD *)&v9[9] = 23;
v7 = (const char *)func15(v3, &v9[9]);
printf("also found: %s\n", v7);
func9(v3);
return 0;
}

original_code:
int main(){
  trynode *mytry = init_trymap(&int_indexer, 10);
  char hello[] = "hello!!";
  int blah = 17;
  iput_try(mytry,&blah,(void *)hello);
  printf("num elts in mytry: %d\n", size_try(mytry));
  int blah2 = 23;
  char hello2[] = "goodbye!";
  iput_try(mytry,&blah2,(void *)hello2);
  printf("added another, now we have %d elts\n", size_try(mytry));
  blah = 17;
  char *ret = (char *)iget_try(mytry, &blah);
  printf("found: %s\n", ret);
  blah2 = 23;
  ret = (char *)iget_try(mytry, &blah2);
  printf("also found: %s\n", ret);
  free_try(mytry);
}

canonical_original_code:
int main(){
  struct trynode *mytry = init_trymap(&int_indexer, 10);
  char hello[] = "hello!!";
  int blah = 17;
  iput_try(mytry,&blah,(void *)hello);
  printf("num elts in mytry: %d\n", size_try(mytry));
  int blah2 = 23;
  char hello2[] = "goodbye!";
  iput_try(mytry,&blah2,(void *)hello2);
  printf("added another, now we have %d elts\n", size_try(mytry));
  blah = 17;
  char *ret = (char *)iget_try(mytry, &blah);
  printf("found: %s\n", ret);
  blah2 = 23;
  ret = (char *)iget_try(mytry, &blah2);
  printf("also found: %s\n", ret);
  free_try(mytry);
}

variable_types: struct trynode { void *payload; int nchildren; struct trynode **children; int nbelow; int (*get_index)(void *); int cur_i; } *

variable_types:
hello
char []

variable_types: blah int

variable_types:
ret
char *


decompiled_code:
void __fastcall my_bzero(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi

if ( a2 )
{
v2 = &a1[a2];
do
*a1++ = 0;
while ( v2 != a1 );
}
}

canonical_decompiled_code:
void __fastcall func8(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi

if ( a2 )
{
v2 = &a1[a2];
do
*a1++ = 0;
while ( v2 != a1 );
}
}

original_code:
void my_bzero(void *array, size_t size)
{
  char *cur = (char *)array;
  for(int i = 0; i < size; i++)
    *(cur++) = (char)0;
}

canonical_original_code:
void my_bzero(void *array, unsigned long size)
{
  char *cur = (char *)array;
  for(int i = 0; i < size; i++)
    *(cur++) = (char)0;
}

variable_types:
array
void *

variable_types:
size
unsigned long

variable_types:
cur
char *

variable_types: i int


original_code:
int free_try(trynode *root)
{
  if(root == ((void *)0))
    return 0;
  for(int i = 0; i < root->nchildren; i++){
    free_try(root->children[i]);
  }
  free(root->children);
  free(root);
  return 0;
}

canonical_original_code:
int free_try(struct trynode *root)
{
  if(root == ((void *)0))
    return 0;
  for(int i = 0; i < root->nchildren; i++){
    free_try(root->children[i]);
  }
  free(root->children);
  free(root);
  return 0;
}

user_defined_types: struct trynode { void *payload; int nchildren; struct trynode **children; int nbelow; int (*get_index)(void *); int cur_i; }


original_code:
int put_try(trynode *root, void *key, void *val)
{
  int next_index = root->get_index(key);
  if(next_index == -1){
    int nadded = (root->payload) ? 0 : 1;
    root->nbelow += nadded;
    root->payload = val;
    return nadded;
  }
  if(root->children[next_index] == ((void *)0))
    newchild_try(root,next_index);
  int nadded = put_try(root->children[next_index], key, val);
  root->nbelow += nadded;
  return nadded;
}

canonical_original_code:
int put_try(struct trynode *root, void *key, void *val)
{
  int next_index = root->get_index(key);
  if(next_index == -1){
    int nadded = (root->payload) ? 0 : 1;
    root->nbelow += nadded;
    root->payload = val;
    return nadded;
  }
  if(root->children[next_index] == ((void *)0))
    newchild_try(root,next_index);
  int nadded = put_try(root->children[next_index], key, val);
  root->nbelow += nadded;
  return nadded;
}

variable_types:
key
void *

variable_types:
val
void *

variable_types: nadded int


decompiled_code:
__int64 __fastcall sput_try(__int64 a1, __int64 a2, __int64 a3)
{
return put_try(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
return func10(a1, a2, a3);
}

original_code:
int sput_try(trynode *root, char *key, void *val)
{
  return put_try(root, (void *)key, val);
}

canonical_original_code:
int sput_try(struct trynode *root, char *key, void *val)
{
  return put_try(root, (void *)key, val);
}

variable_types:
key
char *


decompiled_code:
__int64 __fastcall iput_try(__int64 a1, __int64 a2, __int64 a3)
{
return put_try(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3)
{
return func10(a1, a2, a3);
}

original_code:
int iput_try(trynode *root, int *key, void *val)
{
  return put_try(root, (void *)key, val);
}

canonical_original_code:
int iput_try(struct trynode *root, int *key, void *val)
{
  return put_try(root, (void *)key, val);
}

variable_types:
key
int *


decompiled_code:
__int64 __fastcall get_try(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = (*(__int64 (__fastcall **)(__int64))(a1 + 32))(a2);
if ( v2 == -1 )
return *(_QWORD *)a1;
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v2);
if ( result )
result = get_try(result, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = (*(__int64 (__fastcall **)(__int64))(a1 + 32))(a2);
if ( v2 == -1 )
return *(_QWORD *)a1;
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v2);
if ( result )
result = func13(result, a2);
return result;
}

original_code:
void *get_try(trynode *root, void *key)
{
  int next_index = root->get_index(key);
  if(next_index == -1)
    return root->payload;
  if(root->children[next_index])
    return get_try(root->children[next_index], key);
  return ((void *)0);
}

canonical_original_code:
void *get_try(struct trynode *root, void *key)
{
  int next_index = root->get_index(key);
  if(next_index == -1)
    return root->payload;
  if(root->children[next_index])
    return get_try(root->children[next_index], key);
  return ((void *)0);
}

return_type: void *


decompiled_code:
__int64 __fastcall sget_try(__int64 a1, __int64 a2)
{
return get_try(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
return func13(a1, a2);
}

original_code:
void *sget_try(trynode *root, char *key)
{
  return get_try(root, (void *)key);
}

canonical_original_code:
void *sget_try(struct trynode *root, char *key)
{
  return get_try(root, (void *)key);
}


decompiled_code:
__int64 __fastcall iget_try(__int64 a1, __int64 a2)
{
return get_try(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return func13(a1, a2);
}

original_code:
void *iget_try(trynode *root, int *key)
{
  return get_try(root, (void *)key);
}

canonical_original_code:
void *iget_try(struct trynode *root, int *key)
{
  return get_try(root, (void *)key);
}


decompiled_code:
__int64 __fastcall size_try(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
int size_try(trynode *root)
{
  return root->nbelow;
}

canonical_original_code:
int size_try(struct trynode *root)
{
  return root->nbelow;
}


decompiled_code:
__int64 traverse_from_0()
{
fwrite("traverse_from_0 UNIMPLEMENTED\n", 1uLL, 0x1EuLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func17()
{
fwrite("traverse_from_0 UNIMPLEMENTED\n", 1uLL, 0x1EuLL, stderr);
return 0LL;
}

original_code:
int traverse_from_0(trynode *root)
{
  fprintf(stderr, "traverse_from_0 UNIMPLEMENTED\n");
  return 0;
}

canonical_original_code:
int traverse_from_0(struct trynode *root)
{
  fprintf(stderr, "traverse_from_0 UNIMPLEMENTED\n");
  return 0;
}


decompiled_code:
__int64 __fastcall hex_to_u16(char *src)
{
size_t v1; // rax
__int64 result; // rax
unsigned __int64 v3; // rbp
size_t v4; // r13
char v5[8]; // [rsp+0h] [rbp-58h]
__int64 v6; // [rsp+8h] [rbp-50h] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

v1 = strlen(src);
if ( v1 > 0x10 )
{
v3 = v1;
v4 = v1 - 16;
strncpy(dest, &src[v1 - 16], 0x10uLL);
_isoc99_sscanf(dest, "%llx", &v6);
if ( v3 > 0x20 )
{
strncpy(dest, &src[v3 - 32], 0x10uLL);
_isoc99_sscanf(dest, "%llx", &v6);
}
else
{
strncpy(dest, src, v4);
v5[v3] = 0;
_isoc99_sscanf(dest, "%llx", &v6);
}
result = v6;
}
else
{
_isoc99_sscanf(src, "%llx", &v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
size_t v1; // rax
__int64 result; // rax
unsigned __int64 v3; // rbp
size_t v4; // r13
char v5[8]; // [rsp+0h] [rbp-58h]
__int64 v6; // [rsp+8h] [rbp-50h] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

v1 = strlen(src);
if ( v1 > 0x10 )
{
v3 = v1;
v4 = v1 - 16;
strncpy(dest, &src[v1 - 16], 0x10uLL);
_isoc99_sscanf(dest, "%llx", &v6);
if ( v3 > 0x20 )
{
strncpy(dest, &src[v3 - 32], 0x10uLL);
_isoc99_sscanf(dest, "%llx", &v6);
}
else
{
strncpy(dest, src, v4);
v5[v3] = 0;
_isoc99_sscanf(dest, "%llx", &v6);
}
result = v6;
}
else
{
_isoc99_sscanf(src, "%llx", &v6);
result = 0LL;
}
return result;
}

original_code:
u16 hex_to_u16(const char *s)
{
    u16 result;
    size_t len;
    char sub[16 + 1];
    u8 temp;
    result.hi8 = 0;
    result.lo8 = 0;
    len = strlen(s);
    if (len <= 16)
    {
        sscanf(s, "%llx", &temp);
        result.lo8 = temp;
    }
    else
    {
        strncpy(sub, s + len - 16, 16);
        sscanf(sub, "%llx", &temp);
        result.lo8 = temp;
        if (len <= 32)
        {
            strncpy(sub, s, len - 16);
            sub[len - 16] = '\0';
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
        else
        {
            strncpy(sub, s + len - 32, 16);
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
    }
    return (result);
}

canonical_original_code:
struct u16 hex_to_u16(char *s)
{
    struct u16 result;
    unsigned long len;
    char sub[-1];
    unsigned long long temp;
    result.hi8 = 0;
    result.lo8 = 0;
    len = strlen(s);
    if (len <= 16)
    {
        sscanf(s, "%llx", &temp);
        result.lo8 = temp;
    }
    else
    {
        strncpy(sub, s + len - 16, 16);
        sscanf(sub, "%llx", &temp);
        result.lo8 = temp;
        if (len <= 32)
        {
            strncpy(sub, s, len - 16);
            sub[len - 16] = '\0';
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
        else
        {
            strncpy(sub, s + len - 32, 16);
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
    }
    return (result);
}

variable_types:
s
char *

variable_types: struct u16 { unsigned long long hi8; unsigned long long lo8; }

variable_types:
len
unsigned long

variable_types:
sub
char [-1]

variable_types:
temp
unsigned long long


decompiled_code:
char *__fastcall u16_to_hex(__int64 a1, __int64 a2, char *a3)
{
size_t v5; // rax

if ( a1 )
{
sprintf(a3, "%llx", a1);
v5 = strlen(a3);
sprintf(&a3[v5], "%016llx", a2);
}
else
{
sprintf(a3, "%llx", a2);
}
return a3;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2, char *a3)
{
size_t v5; // rax

if ( a1 )
{
sprintf(a3, "%llx", a1);
v5 = strlen(a3);
sprintf(&a3[v5], "%016llx", a2);
}
else
{
sprintf(a3, "%llx", a2);
}
return a3;
}

original_code:
char *u16_to_hex(u16 k, char *buf)
{
    char *p;
    if (k.hi8 == 0)
        sprintf(buf, "%llx", k.lo8);
    else
    {
        sprintf(buf, "%llx", k.hi8);
        p = buf + strlen(buf);
        sprintf(p, "%016llx", k.lo8);
    }
    return (buf);
}

canonical_original_code:
char *u16_to_hex(struct u16 k, char *buf)
{
    char *p;
    if (k.hi8 == 0)
        sprintf(buf, "%llx", k.lo8);
    else
    {
        sprintf(buf, "%llx", k.hi8);
        p = buf + strlen(buf);
        sprintf(p, "%016llx", k.lo8);
    }
    return (buf);
}

variable_types:
buf
char *

variable_types:
p
char *

return_type: char *

user_defined_types: struct u16 { unsigned long long hi8; unsigned long long lo8; }


original_code:
char *u16_to_dec(u16 k, char *buf)
{
    u8 hi8 = k.hi8;
    u8 lo8 = k.lo8;
    int himod;
    int lomod;
    char temp[(39 + 1)];
    char *digit = temp;
    char *tail;
    while (hi8)
    {
        himod = (int)(hi8 % 10);
        hi8 /= 10;
        lomod = (int)(lo8 % 10);
        lo8 /= 10;
        lo8 += hi2loQuot[himod] ;
        lomod += (int)hi2loMod[himod];
        if (lomod >= 10)
        {
            lomod -= 10;
            lo8 += 1;
        }
        *digit++ = '0' + lomod;
    }
    sprintf(buf, "%llu", lo8);
    tail = buf + strlen(buf);
    while (digit > temp)
        *tail++ = *--digit;
    *tail = '\0';
    return (buf);
}

canonical_original_code:
char *u16_to_dec(struct u16 k, char *buf)
{
    unsigned long long hi8 = k.hi8;
    unsigned long long lo8 = k.lo8;
    int himod;
    int lomod;
    char temp[-1];
    char *digit = temp;
    char *tail;
    while (hi8)
    {
        himod = (int)(hi8 % 10);
        hi8 /= 10;
        lomod = (int)(lo8 % 10);
        lo8 /= 10;
        lo8 += hi2loQuot[himod] ;
        lomod += (int)hi2loMod[himod];
        if (lomod >= 10)
        {
            lomod -= 10;
            lo8 += 1;
        }
        *digit++ = '0' + lomod;
    }
    sprintf(buf, "%llu", lo8);
    tail = buf + strlen(buf);
    while (digit > temp)
        *tail++ = *--digit;
    *tail = '\0';
    return (buf);
}

variable_types: himod int

variable_types: lomod int

variable_types:
temp
char [-1]

variable_types:
digit
char *

variable_types:
tail
char *