main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rax
double *v6; // r12
double *v7; // r12
double v8; // xmm0_8
__int64 v9; // rsi
int v10; // ebx
int v11; // ebp
int v12; // edi
__int64 v13; // rbp
double v14; // xmm0_8
int v15; // edx
int v16; // ecx
__int64 v17; // rdx
double *v18; // rdi
double v19; // xmm2_8
double *v20; // rsi
__int64 v21; // xmm0_8
__int64 v22; // rdx
double *v23; // rdx
double *v24; // rax
double v25; // xmm1_8
int v26; // edi
int v27; // ebx
int v28; // edi

get_options(argc, argv, &options, help_string);
if ( !psdump )
{
plot_mag = mag;
plot_inverse = invert;
plot_init((unsigned int)width, (unsigned int)height, 2LL, term);
plot_set_all(0LL);
}
v3 = 0LL;
srandom(seed);
*(double *)&angle = *(double *)&angle * 3.141592653589793 / 180.0;
*(double *)&vangle = 3.141592653589793 * *(double *)&vangle / 180.0;
xp = xmalloc(8LL * num);
yp = xmalloc(8LL * num);
xv = xmalloc(8LL * num);
yv = xmalloc(8LL * num);
xnv = xmalloc(8LL * num);
ynv = xmalloc(8LL * num);
if ( num > 0 )
{
do
{
v4 = 8 * v3;
*(double *)(xp + 8 * v3) = (double)(int)(random() % width);
v5 = random();
v6 = (double *)(8 * v3 + xv);
*(double *)(yp + 8 * v3++) = (double)(int)(v5 % height);
*v6 = random_range(-1.0, 1.0);
v7 = (double *)(v4 + yv);
v8 = random_range(-1.0, 1.0);
v9 = yv;
*v7 = v8;
norm((double *)(xv + v4), (double *)(v4 + v9));
}
while ( num > (int)v3 );
}
v10 = 0;
if ( steps <= 0 )
{
LABEL_24:
if ( psdump || (plot_finish(), psdump) )
{
v27 = 0;
plot_inverse = 0;
plot_init((unsigned int)width, (unsigned int)height, 2LL, &unk_14B4);
if ( num > 0 )
{
do
{
v28 = v27++;
draw_boid(v28, 0);
}
while ( num > v27 );
}
plot_finish();
}
exit(0);
}
while ( 1 )
{
v11 = 0;
if ( num > 0 )
{
do
{
v12 = v11++;
compute_new_heading(v12);
}
while ( num > v11 );
if ( num > 0 )
break;
}
LABEL_23:
if ( steps <= ++v10 )
goto LABEL_24;
}
v13 = 0LL;
while ( 1 )
{
v16 = psdump;
if ( !psdump )
{
draw_boid(v13, 0);
v16 = psdump;
}
v17 = ynv;
v18 = (double *)(8 * v13 + xv);
v19 = (double)width;
v20 = (double *)(8 * v13 + yv);
*v18 = *(double *)(xnv + 8 * v13);
v21 = *(_QWORD *)(v17 + 8 * v13);
v22 = xp;
*(_QWORD *)v20 = v21;
v23 = (double *)(8 * v13 + v22);
v24 = (double *)(yp + 8 * v13);
*v23 = *v18 * *(double *)&dt + *v23;
v14 = *v20 * *(double *)&dt + *v24;
*v24 = v14;
v25 = *v23;
if ( *v23 >= 0.0 )
{
if ( v25 >= v19 )
{
*v23 = v25 - v19;
v14 = *v24;
}
v15 = height;
if ( v14 >= 0.0 )
goto LABEL_13;
LABEL_21:
*v24 = v14 + (double)v15;
if ( v16 )
goto LABEL_16;
LABEL_22:
v26 = v13++;
draw_boid(v26, 1u);
if ( num <= (int)v13 )
goto LABEL_23;
}
else
{
*v23 = v25 + v19;
v14 = *v24;
v15 = height;
if ( *v24 < 0.0 )
goto LABEL_21;
LABEL_13:
if ( v14 >= (double)(v15 - 1) )
*v24 = v14 - (double)v15;
if ( !v16 )
goto LABEL_22;
LABEL_16:
if ( num <= (int)++v13 )
goto LABEL_23;
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rax
double *v6; // r12
double *v7; // r12
double v8; // xmm0_8
__int64 v9; // rsi
int v10; // ebx
int v11; // ebp
int v12; // edi
__int64 v13; // rbp
double v14; // xmm0_8
int v15; // edx
int v16; // ecx
__int64 v17; // rdx
double *v18; // rdi
double v19; // xmm2_8
double *v20; // rsi
__int64 v21; // xmm0_8
__int64 v22; // rdx
double *v23; // rdx
double *v24; // rax
double v25; // xmm1_8
int v26; // edi
int v27; // ebx
int v28; // edi

get_options(argc, argv, &options, help_string);
if ( !psdump )
{
plot_mag = mag;
plot_inverse = invert;
plot_init((unsigned int)width, (unsigned int)height, 2LL, term);
plot_set_all(0LL);
}
v3 = 0LL;
srandom(seed);
*(double *)&angle = *(double *)&angle * 3.141592653589793 / 180.0;
*(double *)&vangle = 3.141592653589793 * *(double *)&vangle / 180.0;
xp = xmalloc(8LL * num);
yp = xmalloc(8LL * num);
xv = xmalloc(8LL * num);
yv = xmalloc(8LL * num);
xnv = xmalloc(8LL * num);
ynv = xmalloc(8LL * num);
if ( num > 0 )
{
do
{
v4 = 8 * v3;
*(double *)(xp + 8 * v3) = (double)(int)(random() % width);
v5 = random();
v6 = (double *)(8 * v3 + xv);
*(double *)(yp + 8 * v3++) = (double)(int)(v5 % height);
*v6 = random_range(-1.0, 1.0);
v7 = (double *)(v4 + yv);
v8 = random_range(-1.0, 1.0);
v9 = yv;
*v7 = v8;
func0((double *)(xv + v4), (double *)(v4 + v9));
}
while ( num > (int)v3 );
}
v10 = 0;
if ( steps <= 0 )
{
LABEL_24:
if ( psdump || (plot_finish(), psdump) )
{
v27 = 0;
plot_inverse = 0;
plot_init((unsigned int)width, (unsigned int)height, 2LL, &unk_14B4);
if ( num > 0 )
{
do
{
v28 = v27++;
func2(v28, 0);
}
while ( num > v27 );
}
plot_finish();
}
exit(0);
}
while ( 1 )
{
v11 = 0;
if ( num > 0 )
{
do
{
v12 = v11++;
func1(v12);
}
while ( num > v11 );
if ( num > 0 )
break;
}
LABEL_23:
if ( steps <= ++v10 )
goto LABEL_24;
}
v13 = 0LL;
while ( 1 )
{
v16 = psdump;
if ( !psdump )
{
func2(v13, 0);
v16 = psdump;
}
v17 = ynv;
v18 = (double *)(8 * v13 + xv);
v19 = (double)width;
v20 = (double *)(8 * v13 + yv);
*v18 = *(double *)(xnv + 8 * v13);
v21 = *(_QWORD *)(v17 + 8 * v13);
v22 = xp;
*(_QWORD *)v20 = v21;
v23 = (double *)(8 * v13 + v22);
v24 = (double *)(yp + 8 * v13);
*v23 = *v18 * *(double *)&dt + *v23;
v14 = *v20 * *(double *)&dt + *v24;
*v24 = v14;
v25 = *v23;
if ( *v23 >= 0.0 )
{
if ( v25 >= v19 )
{
*v23 = v25 - v19;
v14 = *v24;
}
v15 = height;
if ( v14 >= 0.0 )
goto LABEL_13;
LABEL_21:
*v24 = v14 + (double)v15;
if ( v16 )
goto LABEL_16;
LABEL_22:
v26 = v13++;
func2(v26, 1u);
if ( num <= (int)v13 )
goto LABEL_23;
}
else
{
*v23 = v25 + v19;
v14 = *v24;
v15 = height;
if ( *v24 < 0.0 )
goto LABEL_21;
LABEL_13:
if ( v14 >= (double)(v15 - 1) )
*v24 = v14 - (double)v15;
if ( !v16 )
goto LABEL_22;
LABEL_16:
if ( num <= (int)++v13 )
goto LABEL_23;
}
}
}

original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int plot_inverse;
  int i, j;
  get_options(argc, argv, options, help_string);
  if(!psdump) {
    plot_mag = mag;
    plot_inverse = invert;
    plot_init(width, height, 2, term);
    plot_set_all(0);
  }
  srandom(seed);
  angle = angle * 3.14159265358979323846 / 180.0;
  vangle = vangle * 3.14159265358979323846 / 180.0;
  xp = xmalloc(sizeof(double) * num);
  yp = xmalloc(sizeof(double) * num);
  xv = xmalloc(sizeof(double) * num);
  yv = xmalloc(sizeof(double) * num);
  xnv = xmalloc(sizeof(double) * num);
  ynv = xmalloc(sizeof(double) * num);
  for(i = 0; i < num; i++) {
    xp[i] = random() % width;
    yp[i] = random() % height;
    xv[i] = random_range(-1.0, 1.0);
    yv[i] = random_range(-1.0, 1.0);
    norm(&xv[i], &yv[i]);
  }
  for(i = 0; i < steps; i++) {
    for(j = 0; j < num; j++)
      compute_new_heading(j);
    for(j = 0; j < num; j++) {
      if(!psdump) draw_boid(j, 0);
      xv[j] = xnv[j];
      yv[j] = ynv[j];
      xp[j] += xv[j] * dt;
      yp[j] += yv[j] * dt;
      if(xp[j] < 0) xp[j] += width;
      else if(xp[j] >= width) xp[j] -= width;
      if(yp[j] < 0) yp[j] += height;
      else if(yp[j] >= height - 1) yp[j] -= height;
      if(!psdump) draw_boid(j, 1);
    }
  }
  if(!psdump) plot_finish();
  if(psdump) {
    plot_inverse = 0;
    plot_init(width, height, 2, "ps");
    for(i = 0; i < num; i++) {
      draw_boid(i, 0);
    }
    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;
  get_options(argc, argv, options, help_string);
  if(!psdump) {
    plot_mag = mag;
    plot_inverse = invert;
    plot_init(width, height, 2, term);
    plot_set_all(0);
  }
  srandom(seed);
  angle = angle * 3.14159265358979323846 / 180.0;
  vangle = vangle * 3.14159265358979323846 / 180.0;
  xp = xmalloc(sizeof(double) * num);
  yp = xmalloc(sizeof(double) * num);
  xv = xmalloc(sizeof(double) * num);
  yv = xmalloc(sizeof(double) * num);
  xnv = xmalloc(sizeof(double) * num);
  ynv = xmalloc(sizeof(double) * num);
  for(i = 0; i < num; i++) {
    xp[i] = random() % width;
    yp[i] = random() % height;
    xv[i] = random_range(-1.0, 1.0);
    yv[i] = random_range(-1.0, 1.0);
    norm(&xv[i], &yv[i]);
  }
  for(i = 0; i < steps; i++) {
    for(j = 0; j < num; j++)
      compute_new_heading(j);
    for(j = 0; j < num; j++) {
      if(!psdump) draw_boid(j, 0);
      xv[j] = xnv[j];
      yv[j] = ynv[j];
      xp[j] += xv[j] * dt;
      yp[j] += yv[j] * dt;
      if(xp[j] < 0) xp[j] += width;
      else if(xp[j] >= width) xp[j] -= width;
      if(yp[j] < 0) yp[j] += height;
      else if(yp[j] >= height - 1) yp[j] -= height;
      if(!psdump) draw_boid(j, 1);
    }
  }
  if(!psdump) plot_finish();
  if(psdump) {
    plot_inverse = 0;
    plot_init(width, height, 2, "ps");
    for(i = 0; i < num; i++) {
      draw_boid(i, 0);
    }
    plot_finish();
  }
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: j int


repo: ramalho/CBofN

decompiled_code:
__int64 init_weights()
{
__int64 v0; // rax
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rdi
__int64 *v6; // r12
__int64 v7; // rax
__int64 v8; // r13
char *v9; // rdi
char *v10; // r12
__int64 result; // rax
__int64 v12; // r13
__int64 v13; // rbx
int v14; // ebx
__int64 v15; // r15
__int64 *v16; // r14
__int64 v17; // rax
__int64 i; // rax
__int64 v19; // [rsp+8h] [rbp-40h]

x = xmalloc(8LL * height);
b = xmalloc(8LL * height);
v0 = height;
if ( height > 0 )
{
v1 = width;
v2 = 0LL;
do
{
v3 = x;
v4 = xmalloc(8LL * v1);
v5 = width;
v6 = (__int64 *)(b + 8 * v2);
*(_QWORD *)(8 * v2 + v3) = v4;
v7 = xmalloc(8 * v5);
v1 = width;
*v6 = v7;
if ( v1 > 0 )
{
v8 = 8LL * v1;
v9 = *(char **)(b + 8 * v2);
v10 = *(char **)(x + 8 * v2);
if ( v9 < &v10[v8] && v10 < &v9[v8] )
{
for ( i = 0LL; i != v1; *(_QWORD *)&v10[8 * i++] = 0LL )
*(_QWORD *)&v9[8 * i] = 0LL;
}
else
{
memset(v9, 0, 8LL * v1);
memset(v10, 0, 8LL * v1);
}
}
v0 = height;
++v2;
}
while ( height > (int)v2 );
}
result = xmalloc(8 * v0);
weight = result;
if ( height > 0 )
{
v19 = 0LL;
while ( 1 )
{
*(_QWORD *)(result + 8 * v19) = xmalloc(8LL * width);
if ( width <= 0 )
{
++v19;
result = (unsigned int)height;
if ( height <= (int)v19 )
return result;
}
else
{
result = height;
v12 = 0LL;
do
{
v13 = *(_QWORD *)(weight + 8 * v19);
*(_QWORD *)(8 * v12 + v13) = xmalloc(8 * result);
result = height;
v14 = width;
if ( height > 0 )
{
v15 = 0LL;
do
{
v16 = (__int64 *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v19) + 8 * v12) + 8 * v15);
v17 = xmalloc(8LL * v14);
v14 = width;
*v16 = v17;
if ( v14 > 0 )
memset(*(void **)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v19) + 8 * v12) + 8 * v15), 0, 8LL * v14);
result = height;
++v15;
}
while ( height > (int)v15 );
}
++v12;
}
while ( v14 > (int)v12 );
if ( (int)result <= (int)++v19 )
return result;
}
result = weight;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rdi
__int64 *v6; // r12
__int64 v7; // rax
__int64 v8; // r13
char *v9; // rdi
char *v10; // r12
__int64 result; // rax
__int64 v12; // r13
__int64 v13; // rbx
int v14; // ebx
__int64 v15; // r15
__int64 *v16; // r14
__int64 v17; // rax
__int64 i; // rax
__int64 v19; // [rsp+8h] [rbp-40h]

x = xmalloc(8LL * height);
b = xmalloc(8LL * height);
v0 = height;
if ( height > 0 )
{
v1 = width;
v2 = 0LL;
do
{
v3 = x;
v4 = xmalloc(8LL * v1);
v5 = width;
v6 = (__int64 *)(b + 8 * v2);
*(_QWORD *)(8 * v2 + v3) = v4;
v7 = xmalloc(8 * v5);
v1 = width;
*v6 = v7;
if ( v1 > 0 )
{
v8 = 8LL * v1;
v9 = *(char **)(b + 8 * v2);
v10 = *(char **)(x + 8 * v2);
if ( v9 < &v10[v8] && v10 < &v9[v8] )
{
for ( i = 0LL; i != v1; *(_QWORD *)&v10[8 * i++] = 0LL )
*(_QWORD *)&v9[8 * i] = 0LL;
}
else
{
memset(v9, 0, 8LL * v1);
memset(v10, 0, 8LL * v1);
}
}
v0 = height;
++v2;
}
while ( height > (int)v2 );
}
result = xmalloc(8 * v0);
weight = result;
if ( height > 0 )
{
v19 = 0LL;
while ( 1 )
{
*(_QWORD *)(result + 8 * v19) = xmalloc(8LL * width);
if ( width <= 0 )
{
++v19;
result = (unsigned int)height;
if ( height <= (int)v19 )
return result;
}
else
{
result = height;
v12 = 0LL;
do
{
v13 = *(_QWORD *)(weight + 8 * v19);
*(_QWORD *)(8 * v12 + v13) = xmalloc(8 * result);
result = height;
v14 = width;
if ( height > 0 )
{
v15 = 0LL;
do
{
v16 = (__int64 *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v19) + 8 * v12) + 8 * v15);
v17 = xmalloc(8LL * v14);
v14 = width;
*v16 = v17;
if ( v14 > 0 )
memset(*(void **)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v19) + 8 * v12) + 8 * v15), 0, 8LL * v14);
result = height;
++v15;
}
while ( height > (int)v15 );
}
++v12;
}
while ( v14 > (int)v12 );
if ( (int)result <= (int)++v19 )
return result;
}
result = weight;
}
}
return result;
}

original_code:
void init_weights(void)
{
  int i, j, k, l;
  x = xmalloc(sizeof(double *) * height);
  b = xmalloc(sizeof(double *) * height);
  for(i = 0; i < height; i++) {
    x[i] = xmalloc(sizeof(double) * width);
    b[i] = xmalloc(sizeof(double) * width);
    for(j = 0; j < width; j++)
      x[i][j] = b[i][j] = 0;
  }
  weight = xmalloc(sizeof(double ***) * height);
  for(i = 0; i < height; i++) {
    weight[i] = xmalloc(sizeof(double **) * width);
    for(j = 0; j < width; j++) {
      weight[i][j] = xmalloc(sizeof(double *) * height);
      for(k = 0; k < height; k++) {
        weight[i][j][k] = xmalloc(sizeof(double) * width);
        for(l = 0; l < width; l++)
          weight[i][j][k][l] = 0;
      }
    }
  }
}

canonical_original_code:
void init_weights()
{
  int i; int j; int k; int l;
  x = xmalloc(sizeof(double *) * height);
  b = xmalloc(sizeof(double *) * height);
  for(i = 0; i < height; i++) {
    x[i] = xmalloc(sizeof(double) * width);
    b[i] = xmalloc(sizeof(double) * width);
    for(j = 0; j < width; j++)
      x[i][j] = b[i][j] = 0;
  }
  weight = xmalloc(sizeof(double ***) * height);
  for(i = 0; i < height; i++) {
    weight[i] = xmalloc(sizeof(double **) * width);
    for(j = 0; j < width; j++) {
      weight[i][j] = xmalloc(sizeof(double *) * height);
      for(k = 0; k < height; k++) {
        weight[i][j][k] = xmalloc(sizeof(double) * width);
        for(l = 0; l < width; l++)
          weight[i][j][k][l] = 0;
      }
    }
  }
}

variable_types: i int

variable_types: k int

variable_types: l int

return_type: void


myparse

original_code:
int myparse(char **argv, int argc, OPTION *options, int *cargc, int opt)
{
  int w, h, **data, i, j, k, l;
  if(argc == *cargc) return(1);
  data = read_pbm_file(argv[*cargc + 1], &w, &h);
  if(file_count == 0) {
    width = w; height = h;
  }
  if(w != width || h != height) {
    fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n",
            w, h, argv[*cargc + 1]);
    exit(1);
  }
  if(weight == ((void *)0)) init_weights();
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++)
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++)
          weight[i][j][k][l] += (2 * data[i][j] - 1) * (2 * data[k][l] - 1);
  for(i = 0; i < height; i++)
    free(data[i]);
  free(data);
  *cargc += 2;
  file_count++;
  return(0);
}

canonical_original_code:
int myparse(char **argv, int argc, struct OPTION *options, int *cargc, int opt)
{
  int w; int h; int **data; int i; int j; int k; int l;
  if(argc == *cargc) return(1);
  data = read_pbm_file(argv[*cargc + 1], &w, &h);
  if(file_count == 0) {
    width = w; height = h;
  }
  if(w != width || h != height) {
    fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n",
            w, h, argv[*cargc + 1]);
    exit(1);
  }
  if(weight == ((void *)0)) init_weights();
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++)
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++)
          weight[i][j][k][l] += (2 * data[i][j] - 1) * (2 * data[k][l] - 1);
  for(i = 0; i < height; i++)
    free(data[i]);
  free(data);
  *cargc += 2;
  file_count++;
  return(0);
}

variable_types: struct OPTION { char *name; enum OPT_TYPE { OPT_INT=0, OPT_DOUBLE=1, OPT_STRING=2, OPT_SWITCH=3, OPT_OTHER=4, OPT_NULL=5 } type; void *ptr; char *help; } *

variable_types:
cargc
int *

variable_types: opt int

variable_types: w int

variable_types: h int

variable_types:
data
int **

return_type: int

user_defined_types: struct OPTION { char *name; enum OPT_TYPE type; void *ptr; char *help; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
double ****v4; // rdx
__int64 v5; // rax
double v6; // xmm1_8
double v7; // xmm2_8
int v8; // ebp
__int64 v9; // r11
__int64 v10; // r12
__int64 v11; // rdi
__int64 v12; // r9
double ***v13; // r8
double ***v14; // r10
double **v15; // rcx
double **v16; // rsi
double *v17; // rax
double *v18; // rdx
double v19; // xmm0_8
double v20; // xmm0_8
int v21; // edx
int v22; // eax
unsigned int v23; // er15
__int64 v24; // xmm2_8
__int64 v25; // rbp
__int64 v26; // rcx
int v27; // edi
__int64 v28; // rbx
_QWORD *v29; // rsi
unsigned __int64 v30; // rdi
__int64 v31; // rbx
const char *v32; // rsi
__int64 v33; // rdx
__int64 v34; // rbp
double v35; // xmm0_8
const char *v36; // rdi
__int64 v37; // rax
double v38; // xmm0_8
_DWORD *v39; // rax
int v40; // ebx
__int64 v41; // r12
__int64 v42; // rax
__int64 v43; // r10
__int64 v44; // r11
__int64 v45; // rdx
double *v46; // rdi
bool v47; // cc
__int64 v48; // r8
__int64 v49; // r10
__int64 v50; // r9
double v51; // xmm1_8
_QWORD *v52; // r13
int v53; // ebp
__int64 v54; // rcx
__int64 v55; // rax
double v56; // xmm0_8
double v57; // xmm0_8
double v58; // xmm0_8
__int64 i; // rbp
__int64 v60; // rbx
__int64 v61; // [rsp+0h] [rbp-68h]
__int64 v62; // [rsp+10h] [rbp-58h]
__int64 v63; // [rsp+18h] [rbp-50h]
unsigned int v64; // [rsp+28h] [rbp-40h] BYREF
unsigned int v65[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

get_options(argc, argv, &options, help_string);
if ( !file_count )
{
fwrite("No stored files. Use -pfile option.\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
srandom(seed);
plot_mag = mag;
plot_inverse = invert;
plot_init((unsigned int)width, (unsigned int)height, 2LL, term);
plot_set_all(0LL);
y = read_pbm_file(tfile, &v64, v65);
if ( v64 != width || v65[0] != height )
{
fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n", v64, v65[0], tfile);
exit(1);
}
if ( *(double *)&noise > 0.0 && *(double *)&noise < 1.0 )
{
for ( i = 0LL; height > (int)i; ++i )
{
if ( width > 0 )
{
v60 = 0LL;
do
{
if ( *(double *)&noise > random_range(0.0, 1.0) )
*(_DWORD *)(*(_QWORD *)(y + 8 * i) + 4 * v60) = random() % 2;
++v60;
}
while ( width > (int)v60 );
}
}
}
if ( height <= 0 )
{
v6 = *(double *)&LC2;
v7 = 0.0;
}
else
{
v3 = width;
v4 = (double ****)weight;
v5 = 8LL * (unsigned int)(height - 1);
v6 = *(double *)&LC2;
v7 = 0.0;
v8 = width * height;
v9 = weight + 8;
v10 = weight + 8 + v5;
v11 = 8LL * (unsigned int)(width - 1) + 8;
v12 = v5 + 8;
while ( 1 )
{
if ( v3 > 0 )
{
v13 = *v4;
v14 = (double ***)((char *)*v4 + v11);
do
{
v15 = *v13;
v16 = (double **)((char *)*v13 + v12);
do
{
v17 = *v15;
v18 = (double *)((char *)*v15 + v11);
do
{
v19 = *v17++;
v20 = v19 / (double)v8;
*(v17 - 1) = v20;
v6 = fmin(COERCE_DOUBLE(*(_QWORD *)&v20 & LC5), v6);
v7 = fmax(COERCE_DOUBLE(*(_QWORD *)&v20 & LC5), v7);
}
while ( v18 != v17 );
++v15;
}
while ( v16 != v15 );
++v13;
}
while ( v14 != v13 );
}
v4 = (double ****)v9;
if ( v10 == v9 )
break;
v9 += 8LL;
}
}
fprintf(stderr, "|largest weight| = %f\n", v7);
fprintf(stderr, "|smallest weight| = %f\n", v6);
v21 = width;
v22 = height;
v63 = 0LL;
v23 = height * width * height * width;
if ( height <= 0 )
{
LABEL_39:
v30 = (unsigned __int64)stderr;
v31 = 0LL;
v32 = "total used weights = %d\n";
fprintf(stderr, "total used weights = %d\n", v23);
v33 = (unsigned int)width;
if ( height > 0 )
{
do
{
if ( (int)v33 > 0 )
{
v34 = 0LL;
do
{
v35 = 0.0;
if ( height > 0 )
{
v35 = 0.0;
v32 = *(const char **)(*(_QWORD *)(weight + 8 * v31) + 8 * v34);
v36 = &v32[8 * height];
do
{
v37 = 0LL;
do
v35 = v35 + *(double *)(*(_QWORD *)v32 + 8 * v37++);
while ( (int)v33 > (int)v37 );
v32 += 8;
}
while ( v36 != v32 );
}
*(double *)(*(_QWORD *)(b + 8 * v31) + 8 * v34) = v35 * -0.5;
v38 = (double)(int)v34;
v39 = (_DWORD *)(*(_QWORD *)(y + 8 * v31) + 4 * v34++);
v30 = (unsigned int)(2 * *v39 - 1);
*v39 = v30;
plot_point(v38);
v33 = (unsigned int)width;
}
while ( width > (int)v34 );
}
++v31;
}
while ( height > (int)v31 );
}
v40 = 0;
while ( steps > v40 )
{
v41 = random() % width;
v42 = random();
v43 = height;
v44 = y;
v45 = v42 % height;
v46 = (double *)(8 * v45 + *(_QWORD *)(x + 8 * v41));
v47 = height <= 0;
*v46 = 0.0;
if ( !v47 )
{
v48 = width;
v49 = 8 * v43;
v50 = 0LL;
v51 = 0.0;
v44 = y;
v52 = (_QWORD *)(weight + 8 * v41);
v53 = width;
do
{
if ( v53 > 0 )
{
v32 = *(const char **)(v44 + v50);
v54 = *(_QWORD *)(*(_QWORD *)(*v52 + 8 * v45) + v50);
v55 = 0LL;
do
{
v56 = (double)*(int *)&v32[4 * v55] * *(double *)(v54 + 8 * v55);
++v55;
v51 = v51 + v56;
*v46 = v51;
}
while ( v48 != v55 );
}
v50 += 8LL;
}
while ( v49 != v50 );
}
v57 = *v46 - *(double *)(*(_QWORD *)(b + 8 * v41) + 8 * v45);
++v40;
*(_DWORD *)(*(_QWORD *)(v44 + 8 * v41) + 4 * v45) = 2 * (v57 > 0.0) - 1;
v30 = (unsigned int)((2 * (v57 > 0.0)) >> 1);
plot_point((double)(int)v45);
}
plot_finish(v30, v32, v33);
exit(0);
}
v24 = LC5;
while ( v21 <= 0 )
{
LABEL_38:
if ( height <= (int)++v63 )
goto LABEL_39;
}
v62 = 0LL;
while ( v22 <= 0 )
{
LABEL_37:
if ( v21 <= (int)++v62 )
goto LABEL_38;
}
v25 = 0LL;
v26 = 8 * v62;
v27 = v63;
while ( 1 )
{
v28 = 0LL;
if ( v21 > 0 )
break;
LABEL_36:
++v25;
--v27;
if ( v22 <= (int)v25 )
goto LABEL_37;
}
while ( 1 )
{
while ( local
&& (COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)v27) & v24) > (double)local
|| COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)((int)v62 - (int)v28)) & v24) > (double)local) )
{
--v23;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v63) + v26) + 8 * v25) + 8 * v28) = 0LL;
LABEL_29:
if ( v21 <= (int)++v28 )
goto LABEL_35;
}
v29 = (_QWORD *)(8 * v28 + *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v63) + v26) + 8 * v25));
if ( *(double *)&cutoff <= COERCE_DOUBLE(*v29 & v24) )
{
if ( *(double *)&pprob > 0.0 )
{
v61 = v26;
v58 = random_range(0.0, 1.0);
v26 = v61;
v24 = LC5;
if ( *(double *)&pprob > v58 )
{
--v23;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v63) + v61) + 8 * v25) + 8 * v28) = 0LL;
}
v21 = width;
}
goto LABEL_29;
}
++v28;
*v29 = 0LL;
--v23;
if ( v21 <= (int)v28 )
{
LABEL_35:
v22 = height;
goto LABEL_36;
}
}
}

original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int plot_inverse;
  int i, j, k, l, w, h, t, n;
  double sum, big = 0, small = 10e10;
  get_options(argc, argv, options, help_string);
  if(file_count == 0) {
    fprintf(stderr, "No stored files.  Use -pfile option.\n");
    exit(1);
  }
  srandom(seed);
  plot_mag = mag;
  plot_inverse = invert;
  plot_init(width, height, 2, term);
  plot_set_all(0);
  y = read_pbm_file(tfile, &w, &h);
  if(w != width || h != height) {
    fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n",
            w, h, tfile);
    exit(1);
  }
  if(noise > 0 && noise < 1)
    for(i = 0; i < height; i++)
      for(j = 0; j < width; j++)
        if(random_range(0, 1) < noise)
          y[i][j] = random() % 2;
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++)
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++) {
          weight[i][j][k][l] /= (width * height);
          if(fabs(weight[i][j][k][l]) > big)
            big = fabs(weight[i][j][k][l]);
          if(fabs(weight[i][j][k][l]) < small)
            small = fabs(weight[i][j][k][l]);
        }
  fprintf(stderr, "|largest weight| = %f\n", big);
  fprintf(stderr, "|smallest weight| = %f\n", small);
  n = width * height * width * height;;
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++)
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++) {
          if(local && (fabs(i - k) > local || fabs(j - l) > local)) {
            weight[i][j][k][l] = 0.0;
            n--;
            continue;
          }
          if(fabs(weight[i][j][k][l]) < cutoff) {
            weight[i][j][k][l] = 0.0;
            n--;
            continue;
          }
          if(pprob > 0 && (random_range(0, 1) < pprob)) {
            weight[i][j][k][l] = 0.0;
            n--;
            continue;
          }
        }
  fprintf(stderr, "total used weights = %d\n", n);
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++) {
      sum = 0.0;
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++)
          sum += weight[i][j][k][l];
      b[i][j] = -0.5 * sum;
      y[i][j] = y[i][j] * 2 - 1;
      plot_point(j, i, y[i][j]);
    }
  for(t = 0; t < steps; t++) {
    i = random() % width; j = random() % height;
    x[i][j] = 0;
    for(k = 0; k < height; k++)
      for(l = 0; l < width; l++)
        x[i][j] += y[k][l] * weight[i][j][k][l];
    y[i][j] = x[i][j] - b[i][j] > 0 ? 1 : -1;
    plot_point(j, i, (y[i][j] + 1) / 2);
  }
  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 k; int l; int w; int h; int t; int n;
  double sum; double big = 0; double small = 10e10;
  get_options(argc, argv, options, help_string);
  if(file_count == 0) {
    fprintf(stderr, "No stored files.  Use -pfile option.\n");
    exit(1);
  }
  srandom(seed);
  plot_mag = mag;
  plot_inverse = invert;
  plot_init(width, height, 2, term);
  plot_set_all(0);
  y = read_pbm_file(tfile, &w, &h);
  if(w != width || h != height) {
    fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n",
            w, h, tfile);
    exit(1);
  }
  if(noise > 0 && noise < 1)
    for(i = 0; i < height; i++)
      for(j = 0; j < width; j++)
        if(random_range(0, 1) < noise)
          y[i][j] = random() % 2;
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++)
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++) {
          weight[i][j][k][l] /= (width * height);
          if(fabs(weight[i][j][k][l]) > big)
            big = fabs(weight[i][j][k][l]);
          if(fabs(weight[i][j][k][l]) < small)
            small = fabs(weight[i][j][k][l]);
        }
  fprintf(stderr, "|largest weight| = %f\n", big);
  fprintf(stderr, "|smallest weight| = %f\n", small);
  n = width * height * width * height;;
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++)
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++) {
          if(local && (fabs(i - k) > local || fabs(j - l) > local)) {
            weight[i][j][k][l] = 0.0;
            n--;
            continue;
          }
          if(fabs(weight[i][j][k][l]) < cutoff) {
            weight[i][j][k][l] = 0.0;
            n--;
            continue;
          }
          if(pprob > 0 && (random_range(0, 1) < pprob)) {
            weight[i][j][k][l] = 0.0;
            n--;
            continue;
          }
        }
  fprintf(stderr, "total used weights = %d\n", n);
  for(i = 0; i < height; i++)
    for(j = 0; j < width; j++) {
      sum = 0.0;
      for(k = 0; k < height; k++)
        for(l = 0; l < width; l++)
          sum += weight[i][j][k][l];
      b[i][j] = -0.5 * sum;
      y[i][j] = y[i][j] * 2 - 1;
      plot_point(j, i, y[i][j]);
    }
  for(t = 0; t < steps; t++) {
    i = random() % width; j = random() % height;
    x[i][j] = 0;
    for(k = 0; k < height; k++)
      for(l = 0; l < width; l++)
        x[i][j] += y[k][l] * weight[i][j][k][l];
    y[i][j] = x[i][j] - b[i][j] > 0 ? 1 : -1;
    plot_point(j, i, (y[i][j] + 1) / 2);
  }
  plot_finish();
  exit(0);
}

variable_types: t int

variable_types: n int

variable_types: sum double

variable_types: big double

variable_types: small double


nearanother

original_code:
int nearanother(int x, int y, char **grid)
{
  int nx, ny, i, j;
  for(i = -1; i <= 1; i++)
    for(j = -1; j <= 1; j++) {
      if(i == 0 && j == 0) continue;
      nx = x + i; ny = y + j;
      nx = (nx < 0) ? width - 1 : (nx > width - 1) ? 0 : nx;
      ny = (ny < 0) ? height - 1 : (ny > height - 1) ? 0 : ny;
      if(grid[nx][ny]) return(1);
    }
  return(0);
}

canonical_original_code:
int nearanother(int x, int y, char **grid)
{
  int nx; int ny; int i; int j;
  for(i = -1; i <= 1; i++)
    for(j = -1; j <= 1; j++) {
      if(i == 0 && j == 0) continue;
      nx = x + i; ny = y + j;
      nx = (nx < 0) ? width - 1 : (nx > width - 1) ? 0 : nx;
      ny = (ny < 0) ? height - 1 : (ny > height - 1) ? 0 : ny;
      if(grid[nx][ny]) return(1);
    }
  return(0);
}

variable_types: x int

variable_types: y int

variable_types:
grid
char **

variable_types: nx int

variable_types: ny int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rbx
int v5; // ebp
__int64 v6; // rax
int v7; // edx
__int64 *v8; // r15
int v9; // eax
__int64 *i; // rbx
__int64 v11; // rax
__int64 v12; // rcx
__int64 v13; // rax
__int64 v14; // rdi
int v15; // er14
int v16; // er12
__int64 v17; // rdx
__int64 v18; // rcx
int v19; // eax
int *v20; // rbx
int *v21; // rbp
int v22; // er14
int v23; // eax
int v24; // ecx
int v25; // eax
int v26; // er14
__int64 v27; // r13
int v28; // eax
int v29; // er13
int v30; // esi
int v31; // eax
int v32; // eax
__int64 v33; // rax
double v34; // xmm0_8
int v35; // eax
int v36; // ecx
int v37; // edx
int v38; // ecx
int v39; // ecx
char v40; // al
int v41; // [rsp+4h] [rbp-84h]
int v42; // [rsp+8h] [rbp-80h]
int v43; // [rsp+Ch] [rbp-7Ch]
int v44; // [rsp+Ch] [rbp-7Ch]
int v45; // [rsp+Ch] [rbp-7Ch]
int v46; // [rsp+10h] [rbp-78h]
int v47; // [rsp+14h] [rbp-74h]
int v48; // [rsp+18h] [rbp-70h]
int v49; // [rsp+1Ch] [rbp-6Ch]
unsigned int v50; // [rsp+20h] [rbp-68h]
int v51; // [rsp+24h] [rbp-64h]
int v52; // [rsp+28h] [rbp-60h]
int v53; // [rsp+2Ch] [rbp-5Ch]
__int64 v54; // [rsp+30h] [rbp-58h]
__int64 v55; // [rsp+38h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-48h] BYREF
double sinx[8]; // [rsp+48h] [rbp-40h] BYREF

get_options(argc, argv, &options, help_string);
v3 = (unsigned int)height;
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);
v54 = xmalloc(4LL * num);
v55 = xmalloc(4LL * num);
if ( num > 0 )
{
v4 = 0LL;
do
{
*(_DWORD *)(v54 + 4 * v4) = (int)((double)(width / 2) + random_range((double)(width / -10), (double)(width / 10)));
*(_DWORD *)(v55 + 4 * v4++) = (int)((double)(height / 2)
+ random_range((double)(height / -10), (double)(height / 10)));
}
while ( num > (int)v4 );
}
v5 = 0;
v6 = xmalloc(8LL * width);
v7 = height;
v8 = (__int64 *)v6;
v9 = width;
for ( i = v8; width > v5; ++i )
{
v11 = xmalloc(v7);
v7 = height;
*i = v11;
v12 = v11;
if ( v7 > 0 )
{
v13 = 0LL;
while ( 1 )
{
*(_BYTE *)(v12 + v13) = 0;
v7 = height;
if ( height <= (int)++v13 )
break;
v12 = *i;
}
}
v9 = width;
++v5;
}
v14 = 1LL;
v15 = (int)((double)v9 * 0.5 + 0.5);
v16 = v15;
v47 = (int)((double)v7 * 0.5 + 0.5);
*(_BYTE *)(v8[v15] + v47) = 1;
plot_point(1LL, (double)v15, (double)v47);
v19 = 1;
v41 = v47;
v48 = v15;
if ( steps > 0 )
v19 = steps;
v50 = 1;
v49 = 0;
v53 = v19;
v52 = 0;
while ( num <= 0 )
{
v40 = 1;
LABEL_77:
v52 += (unsigned int)steps < 0x80000000;
if ( v53 <= v52 || !v40 )
{
plot_finish(v14, v3, v17, v18);
exit(0);
}
}
v51 = 0;
v20 = (int *)v54;
v42 = 0;
v21 = (int *)v55;
while ( 1 )
{
v22 = *v20;
v29 = *v21;
if ( random_range(0.0, 1.0) < 0.5 )
v22 = v22 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
else
v29 = v29 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
v23 = v16 - 5;
v24 = v48 + 5;
if ( v16 - 5 <= v22 )
{
if ( v22 <= v24 )
v23 = v22;
v24 = v23;
}
v25 = v47 - 5;
v26 = v41 + 5;
if ( v47 - 5 <= v29 )
{
if ( v29 <= v26 )
v25 = v29;
v26 = v25;
}
if ( v24 < 0 )
{
v24 = width - 1;
}
else if ( width <= v24 )
{
v24 = 0;
}
if ( v26 < 0 )
break;
if ( height <= v26 )
v26 = 0;
if ( !invis )
goto LABEL_38;
LABEL_31:
*v20 = v24;
v27 = v26;
*v21 = v26;
if ( !invis )
{
v45 = v24;
plot_point(v50, (double)*v20, (double)v26);
v27 = *v21;
v24 = v45;
}
v3 = (unsigned int)v27;
v46 = v24;
v43 = *v20;
v28 = nearanother(*v20, v27, v8);
v14 = v43;
v18 = (unsigned int)v46;
if ( !v28 )
goto LABEL_34;
v30 = v46;
v14 = (unsigned int)v26;
if ( v16 > v46 )
v16 = v46;
*(_BYTE *)(v8[v43] + v27) = 1;
if ( v48 >= v46 )
v30 = v48;
v31 = v47;
v48 = v30;
if ( v47 > v26 )
v31 = v26;
if ( v41 >= v26 )
v14 = (unsigned int)v41;
v47 = v31;
v41 = v14;
if ( v16 > 4 && v31 > 4 && width + 4 >= v30 )
{
v32 = 1;
if ( height + 4 >= (int)v14 )
v32 = v51;
v51 = v32;
if ( !invis )
goto LABEL_54;
LABEL_75:
v14 = v50;
plot_point(v50, (double)*v20, (double)*v21);
goto LABEL_54;
}
v51 = 1;
if ( invis )
goto LABEL_75;
LABEL_54:
v17 = *v20;
v3 = v8[v17];
v33 = *v21;
if ( *(_BYTE *)(v3 + v33) )
{
do
{
v34 = random_range(0.0, 6.283185307179586);
sincos(v34, sinx, &cosx);
v14 = (unsigned int)height;
v35 = height / 2;
v36 = v48 - width / 2;
if ( v36 < width / 2 - v16 )
v36 = width / 2 - v16;
v37 = v41 - v35;
v38 = v36 + 5;
if ( v41 - v35 < v35 - v47 )
v37 = v35 - v47;
v39 = (int)((double)v38 * cosx + (double)(width / 2));
LODWORD(v33) = (int)((double)(v37 + 5) * sinx[0] + (double)v35);
if ( v39 < 0 )
{
v39 = 0;
}
else if ( width <= v39 )
{
v39 = width - 1;
}
if ( (int)v33 >= 0 )
{
if ( height <= (int)v33 )
LODWORD(v33) = height - 1;
v3 = (int)v33;
}
else
{
v3 = 0LL;
LODWORD(v33) = 0;
}
*v20 = v39;
*v21 = v33;
v17 = *v20;
}
while ( *(_BYTE *)(v8[v17] + v3) );
}
v18 = (unsigned int)invis;
if ( !invis )
{
v14 = v50;
plot_point(v50, (double)(int)v17, (double)(int)v33);
}
if ( ++v49 > 10 )
{
v14 = 2155905153LL;
v49 = 0;
v3 = v50;
v17 = 255 * (v50 / 0xFF);
v50 = v50 % 0xFF + 1;
}
LABEL_34:
++v42;
++v20;
++v21;
if ( num <= v42 )
{
v40 = (v51 ^ 1) & 1;
goto LABEL_77;
}
}
v26 = height - 1;
if ( invis )
goto LABEL_31;
LABEL_38:
v44 = v24;
plot_point(0LL, (double)*v20, (double)*v21);
v24 = v44;
goto LABEL_31;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rbx
int v5; // ebp
__int64 v6; // rax
int v7; // edx
__int64 *v8; // r15
int v9; // eax
__int64 *i; // rbx
__int64 v11; // rax
__int64 v12; // rcx
__int64 v13; // rax
__int64 v14; // rdi
int v15; // er14
int v16; // er12
__int64 v17; // rdx
__int64 v18; // rcx
int v19; // eax
int *v20; // rbx
int *v21; // rbp
int v22; // er14
int v23; // eax
int v24; // ecx
int v25; // eax
int v26; // er14
__int64 v27; // r13
int v28; // eax
int v29; // er13
int v30; // esi
int v31; // eax
int v32; // eax
__int64 v33; // rax
double v34; // xmm0_8
int v35; // eax
int v36; // ecx
int v37; // edx
int v38; // ecx
int v39; // ecx
char v40; // al
int v41; // [rsp+4h] [rbp-84h]
int v42; // [rsp+8h] [rbp-80h]
int v43; // [rsp+Ch] [rbp-7Ch]
int v44; // [rsp+Ch] [rbp-7Ch]
int v45; // [rsp+Ch] [rbp-7Ch]
int v46; // [rsp+10h] [rbp-78h]
int v47; // [rsp+14h] [rbp-74h]
int v48; // [rsp+18h] [rbp-70h]
int v49; // [rsp+1Ch] [rbp-6Ch]
unsigned int v50; // [rsp+20h] [rbp-68h]
int v51; // [rsp+24h] [rbp-64h]
int v52; // [rsp+28h] [rbp-60h]
int v53; // [rsp+2Ch] [rbp-5Ch]
__int64 v54; // [rsp+30h] [rbp-58h]
__int64 v55; // [rsp+38h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-48h] BYREF
double sinx[8]; // [rsp+48h] [rbp-40h] BYREF

get_options(argc, argv, &options, help_string);
v3 = (unsigned int)height;
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);
v54 = xmalloc(4LL * num);
v55 = xmalloc(4LL * num);
if ( num > 0 )
{
v4 = 0LL;
do
{
*(_DWORD *)(v54 + 4 * v4) = (int)((double)(width / 2) + random_range((double)(width / -10), (double)(width / 10)));
*(_DWORD *)(v55 + 4 * v4++) = (int)((double)(height / 2)
+ random_range((double)(height / -10), (double)(height / 10)));
}
while ( num > (int)v4 );
}
v5 = 0;
v6 = xmalloc(8LL * width);
v7 = height;
v8 = (__int64 *)v6;
v9 = width;
for ( i = v8; width > v5; ++i )
{
v11 = xmalloc(v7);
v7 = height;
*i = v11;
v12 = v11;
if ( v7 > 0 )
{
v13 = 0LL;
while ( 1 )
{
*(_BYTE *)(v12 + v13) = 0;
v7 = height;
if ( height <= (int)++v13 )
break;
v12 = *i;
}
}
v9 = width;
++v5;
}
v14 = 1LL;
v15 = (int)((double)v9 * 0.5 + 0.5);
v16 = v15;
v47 = (int)((double)v7 * 0.5 + 0.5);
*(_BYTE *)(v8[v15] + v47) = 1;
plot_point(1LL, (double)v15, (double)v47);
v19 = 1;
v41 = v47;
v48 = v15;
if ( steps > 0 )
v19 = steps;
v50 = 1;
v49 = 0;
v53 = v19;
v52 = 0;
while ( num <= 0 )
{
v40 = 1;
LABEL_77:
v52 += (unsigned int)steps < 0x80000000;
if ( v53 <= v52 || !v40 )
{
plot_finish(v14, v3, v17, v18);
exit(0);
}
}
v51 = 0;
v20 = (int *)v54;
v42 = 0;
v21 = (int *)v55;
while ( 1 )
{
v22 = *v20;
v29 = *v21;
if ( random_range(0.0, 1.0) < 0.5 )
v22 = v22 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
else
v29 = v29 + 2 * (random_range(0.0, 1.0) < 0.5) - 1;
v23 = v16 - 5;
v24 = v48 + 5;
if ( v16 - 5 <= v22 )
{
if ( v22 <= v24 )
v23 = v22;
v24 = v23;
}
v25 = v47 - 5;
v26 = v41 + 5;
if ( v47 - 5 <= v29 )
{
if ( v29 <= v26 )
v25 = v29;
v26 = v25;
}
if ( v24 < 0 )
{
v24 = width - 1;
}
else if ( width <= v24 )
{
v24 = 0;
}
if ( v26 < 0 )
break;
if ( height <= v26 )
v26 = 0;
if ( !invis )
goto LABEL_38;
LABEL_31:
*v20 = v24;
v27 = v26;
*v21 = v26;
if ( !invis )
{
v45 = v24;
plot_point(v50, (double)*v20, (double)v26);
v27 = *v21;
v24 = v45;
}
v3 = (unsigned int)v27;
v46 = v24;
v43 = *v20;
v28 = func0(*v20, v27, v8);
v14 = v43;
v18 = (unsigned int)v46;
if ( !v28 )
goto LABEL_34;
v30 = v46;
v14 = (unsigned int)v26;
if ( v16 > v46 )
v16 = v46;
*(_BYTE *)(v8[v43] + v27) = 1;
if ( v48 >= v46 )
v30 = v48;
v31 = v47;
v48 = v30;
if ( v47 > v26 )
v31 = v26;
if ( v41 >= v26 )
v14 = (unsigned int)v41;
v47 = v31;
v41 = v14;
if ( v16 > 4 && v31 > 4 && width + 4 >= v30 )
{
v32 = 1;
if ( height + 4 >= (int)v14 )
v32 = v51;
v51 = v32;
if ( !invis )
goto LABEL_54;
LABEL_75:
v14 = v50;
plot_point(v50, (double)*v20, (double)*v21);
goto LABEL_54;
}
v51 = 1;
if ( invis )
goto LABEL_75;
LABEL_54:
v17 = *v20;
v3 = v8[v17];
v33 = *v21;
if ( *(_BYTE *)(v3 + v33) )
{
do
{
v34 = random_range(0.0, 6.283185307179586);
sincos(v34, sinx, &cosx);
v14 = (unsigned int)height;
v35 = height / 2;
v36 = v48 - width / 2;
if ( v36 < width / 2 - v16 )
v36 = width / 2 - v16;
v37 = v41 - v35;
v38 = v36 + 5;
if ( v41 - v35 < v35 - v47 )
v37 = v35 - v47;
v39 = (int)((double)v38 * cosx + (double)(width / 2));
LODWORD(v33) = (int)((double)(v37 + 5) * sinx[0] + (double)v35);
if ( v39 < 0 )
{
v39 = 0;
}
else if ( width <= v39 )
{
v39 = width - 1;
}
if ( (int)v33 >= 0 )
{
if ( height <= (int)v33 )
LODWORD(v33) = height - 1;
v3 = (int)v33;
}
else
{
v3 = 0LL;
LODWORD(v33) = 0;
}
*v20 = v39;
*v21 = v33;
v17 = *v20;
}
while ( *(_BYTE *)(v8[v17] + v3) );
}
v18 = (unsigned int)invis;
if ( !invis )
{
v14 = v50;
plot_point(v50, (double)(int)v17, (double)(int)v33);
}
if ( ++v49 > 10 )
{
v14 = 2155905153LL;
v49 = 0;
v3 = v50;
v17 = 255 * (v50 / 0xFF);
v50 = v50 % 0xFF + 1;
}
LABEL_34:
++v42;
++v20;
++v21;
if ( num <= v42 )
{
v40 = (v51 ^ 1) & 1;
goto LABEL_77;
}
}
v26 = height - 1;
if ( invis )
goto LABEL_31;
LABEL_38:
v44 = v24;
plot_point(0LL, (double)*v20, (double)*v21);
v24 = v44;
goto LABEL_31;
}

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

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 v0; // rax
bool v1; // zf
__int64 result; // rax

v0 = random();
v1 = (unsigned int)(v0 % 27) == 26;
result = (unsigned int)(v0 % 27) + 97;
if ( v1 )
result = 32LL;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
bool v1; // zf
__int64 result; // rax

v0 = random();
v1 = (unsigned int)(v0 % 27) == 26;
result = (unsigned int)(v0 % 27) + 97;
if ( v1 )
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


decompiled_code:
__int64 __fastcall compute_fitness(int a1, __int64 a2, __int64 a3, double *a4)
{
__int64 result; // rax
double v5; // xmm2_8
__int64 v6; // r14
int v9; // edx
__int64 v10; // rax
bool v11; // cl
double v12; // xmm0_8
double v13; // xmm0_8

result = (unsigned int)size;
if ( size > 0 )
{
v5 = 0.0;
v6 = 0LL;
do
{
v9 = 0;
if ( a1 > 0 )
{
v10 = 0LL;
v9 = 0;
do
{
v11 = *(_BYTE *)(*(_QWORD *)(a2 + 8 * v6) + v10) == (unsigned __int8)target[v10];
++v10;
v9 += v11;
}
while ( a1 != v10 );
}
*(_DWORD *)(a3 + 4 * v6) = v9;
v12 = pow(pbase, (double)(v9 - a1));
result = (unsigned int)size;
a4[v6++] = v12;
v5 = v5 + v12;
}
while ( (int)result > (int)v6 );
if ( (int)result > 0 )
{
result = (__int64)&a4[(unsigned int)(result - 1) + 1];
do
{
v13 = *a4++;
*(a4 - 1) = v13 / v5;
}
while ( (double *)result != a4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3, double *a4)
{
__int64 result; // rax
double v5; // xmm2_8
__int64 v6; // r14
int v9; // edx
__int64 v10; // rax
bool v11; // cl
double v12; // xmm0_8
double v13; // xmm0_8

result = (unsigned int)size;
if ( size > 0 )
{
v5 = 0.0;
v6 = 0LL;
do
{
v9 = 0;
if ( a1 > 0 )
{
v10 = 0LL;
v9 = 0;
do
{
v11 = *(_BYTE *)(*(_QWORD *)(a2 + 8 * v6) + v10) == (unsigned __int8)target[v10];
++v10;
v9 += v11;
}
while ( a1 != v10 );
}
*(_DWORD *)(a3 + 4 * v6) = v9;
v12 = pow(pbase, (double)(v9 - a1));
result = (unsigned int)size;
a4[v6++] = v12;
v5 = v5 + v12;
}
while ( (int)result > (int)v6 );
if ( (int)result > 0 )
{
result = (__int64)&a4[(unsigned int)(result - 1) + 1];
do
{
v13 = *a4++;
*(a4 - 1) = v13 / v5;
}
while ( (double *)result != a4 );
}
}
return result;
}

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


decompiled_code:
__int64 __fastcall select_one(__int64 a1)
{
double v1; // xmm0_8
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
double v1; // xmm0_8
__int64 result; // rax

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

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)
{
double v9; // xmm0_8
__int64 v11; // rax
double v12; // xmm2_8
int v13; // edx
double v14; // xmm1_8
bool v15; // cc
double v16; // xmm1_8
__int64 v17; // r12
__int64 v18; // rbx
double v20; // [rsp+8h] [rbp-30h]

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

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
double v9; // xmm0_8
__int64 v11; // rax
double v12; // xmm2_8
int v13; // edx
double v14; // xmm1_8
bool v15; // cc
double v16; // xmm1_8
__int64 v17; // r12
__int64 v18; // rbx
double v20; // [rsp+8h] [rbp-30h]

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

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

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er14
int v5; // er13
__int64 v6; // r12
__int64 v7; // rbp
double *v8; // rbx
__int64 *v9; // r15
__int64 v10; // rax
__int64 v11; // r14
__int64 v12; // rax
__int64 v13; // rax
int v14; // er15
int v15; // er14
int v16; // eax
int v17; // er9
__int64 v18; // rax
signed int v19; // [rsp+0h] [rbp-68h]
__int64 v20; // [rsp+8h] [rbp-60h]
__int64 v21; // [rsp+10h] [rbp-58h]
__int64 v22; // [rsp+18h] [rbp-50h]
__int64 v23; // [rsp+20h] [rbp-48h]
int v24; // [rsp+2Ch] [rbp-3Ch]

get_options(argc, argv, &options, help_string);
srandom(seed);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v3 = size;
v4 = strlen(target);
v5 = v4;
v6 = xmalloc(8LL * v3);
v7 = xmalloc(8LL * size);
v21 = xmalloc(4LL * size);
v8 = (double *)xmalloc(8LL * size);
if ( size > 0 )
{
v20 = 0LL;
v9 = (__int64 *)v7;
v23 = v4;
v22 = v4 + 1LL;
v24 = v4 - 1;
do
{
*(_QWORD *)(v6 + 8 * v20) = xmalloc(v22);
v10 = xmalloc(v22);
*v9 = v10;
if ( v5 > 0 )
{
v11 = 0LL;
do
{
*(_BYTE *)(*v9 + v11) = random_letter_or_space();
v12 = v11++;
}
while ( v24 != v12 );
v10 = *v9;
}
++v9;
*(_BYTE *)(v10 + v23) = 0;
v13 = *(_QWORD *)(v6 + 8 * v20++);
*(_BYTE *)(v13 + v23) = 0;
}
while ( size > (int)v20 );
}
v19 = 0;
if ( steps > 0 )
{
while ( 1 )
{
compute_fitness(v5, v7, v21, v8);
v14 = 0;
dump_stats(v19, v5, (__int64)v8, v21, v7);
if ( size > 0 )
{
do
{
v15 = select_one((__int64)v8);
v16 = select_one((__int64)v8);
v17 = v14;
v14 += 2;
reproduce(v5, v7, v6, v15, v16, v17);
}
while ( size > v14 );
}
++v19;
v18 = v7;
v7 = v6;
if ( steps <= v19 )
break;
v6 = v18;
}
}
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
__int64 v5; // rbp
_QWORD *v6; // r13
int v7; // er12
__int64 v8; // rax
int v9; // ecx
__int64 v10; // rbx
double v11; // xmm1_8
int i; // er12
int *v13; // rbx
int *v14; // r15
int v15; // er13
int *v16; // r14
int v17; // eax
_BYTE *v18; // rax
__int64 v19; // rax
__int64 v20; // [rsp+8h] [rbp-60h]
__int64 v21; // [rsp+10h] [rbp-58h]
__int64 v22; // [rsp+18h] [rbp-50h]
int v23; // [rsp+28h] [rbp-40h] BYREF
int v24[15]; // [rsp+2Ch] [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);
v20 = xmalloc(4LL * num);
v21 = xmalloc(4LL * num);
v22 = xmalloc(4LL * num);
if ( num > 0 )
{
v3 = 0LL;
do
{
*(_DWORD *)(v20 + 4 * v3) = (int)random_range(0.0, (double)width);
*(_DWORD *)(v21 + 4 * v3) = (int)random_range(0.0, (double)height);
*(_DWORD *)(v22 + 4 * v3++) = (int)random_range(0.0, 8.0);
}
while ( num > (int)v3 );
}
v4 = xmalloc(8LL * width);
v5 = v4;
if ( width > 0 )
{
v6 = (_QWORD *)v4;
v7 = 0;
do
{
v8 = xmalloc(height);
v9 = height;
*v6 = v8;
if ( v9 > 0 )
{
v10 = 0LL;
do
{
while ( 1 )
{
*(_BYTE *)(*v6 + v10) = *(double *)&dense > random_range(0.0, 1.0);
if ( *(_BYTE *)(*v6 + v10) )
break;
if ( height <= (int)++v10 )
goto LABEL_11;
}
v11 = (double)(int)v10++;
plot_point(1LL, (double)v7, v11);
}
while ( height > (int)v10 );
}
LABEL_11:
++v7;
++v6;
}
while ( width > v7 );
}
for ( i = 0; steps > i; ++i )
{
if ( num > 0 )
{
v13 = (int *)v20;
v14 = (int *)v21;
v15 = 0;
v16 = (int *)v22;
do
{
v23 = *v13;
v24[0] = *v14;
newstep(&v23, v24, v16);
v18 = (_BYTE *)(*(_QWORD *)(v5 + 8LL * *v13) + *v14);
if ( *v18 )
{
if ( *(_BYTE *)(*(_QWORD *)(v5 + 8LL * v23) + v24[0]) )
{
v17 = (*v16 + 4) % 8;
*v16 = v17;
*v13 = (width + *v13 + dir[2 * v17]) % width;
*v14 = (height + dir[2 * *v16 + 1] + *v14) % height;
}
else
{
*v18 = 0;
plot_point(0LL, (double)*v13, (double)*v14);
*v13 = v23;
v19 = v24[0];
*v14 = v24[0];
*(_BYTE *)(*(_QWORD *)(v5 + 8LL * *v13) + v19) = 1;
plot_point(1LL, (double)*v13, (double)*v14);
}
}
else
{
*v13 = v23;
*v14 = v24[0];
}
++v15;
++v13;
++v14;
++v16;
}
while ( num > v15 );
}
}
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
__int64 v5; // rbp
_QWORD *v6; // r13
int v7; // er12
__int64 v8; // rax
int v9; // ecx
__int64 v10; // rbx
double v11; // xmm1_8
int i; // er12
int *v13; // rbx
int *v14; // r15
int v15; // er13
int *v16; // r14
int v17; // eax
_BYTE *v18; // rax
__int64 v19; // rax
__int64 v20; // [rsp+8h] [rbp-60h]
__int64 v21; // [rsp+10h] [rbp-58h]
__int64 v22; // [rsp+18h] [rbp-50h]
int v23; // [rsp+28h] [rbp-40h] BYREF
int v24[15]; // [rsp+2Ch] [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);
v20 = xmalloc(4LL * num);
v21 = xmalloc(4LL * num);
v22 = xmalloc(4LL * num);
if ( num > 0 )
{
v3 = 0LL;
do
{
*(_DWORD *)(v20 + 4 * v3) = (int)random_range(0.0, (double)width);
*(_DWORD *)(v21 + 4 * v3) = (int)random_range(0.0, (double)height);
*(_DWORD *)(v22 + 4 * v3++) = (int)random_range(0.0, 8.0);
}
while ( num > (int)v3 );
}
v4 = xmalloc(8LL * width);
v5 = v4;
if ( width > 0 )
{
v6 = (_QWORD *)v4;
v7 = 0;
do
{
v8 = xmalloc(height);
v9 = height;
*v6 = v8;
if ( v9 > 0 )
{
v10 = 0LL;
do
{
while ( 1 )
{
*(_BYTE *)(*v6 + v10) = *(double *)&dense > random_range(0.0, 1.0);
if ( *(_BYTE *)(*v6 + v10) )
break;
if ( height <= (int)++v10 )
goto LABEL_11;
}
v11 = (double)(int)v10++;
plot_point(1LL, (double)v7, v11);
}
while ( height > (int)v10 );
}
LABEL_11:
++v7;
++v6;
}
while ( width > v7 );
}
for ( i = 0; steps > i; ++i )
{
if ( num > 0 )
{
v13 = (int *)v20;
v14 = (int *)v21;
v15 = 0;
v16 = (int *)v22;
do
{
v23 = *v13;
v24[0] = *v14;
func0(&v23, v24, v16);
v18 = (_BYTE *)(*(_QWORD *)(v5 + 8LL * *v13) + *v14);
if ( *v18 )
{
if ( *(_BYTE *)(*(_QWORD *)(v5 + 8LL * v23) + v24[0]) )
{
v17 = (*v16 + 4) % 8;
*v16 = v17;
*v13 = (width + *v13 + dir[2 * v17]) % width;
*v14 = (height + dir[2 * *v16 + 1] + *v14) % height;
}
else
{
*v18 = 0;
plot_point(0LL, (double)*v13, (double)*v14);
*v13 = v23;
v19 = v24[0];
*v14 = v24[0];
*(_BYTE *)(*(_QWORD *)(v5 + 8LL * *v13) + v19) = 1;
plot_point(1LL, (double)*v13, (double)*v14);
}
}
else
{
*v13 = v23;
*v14 = v24[0];
}
++v15;
++v13;
++v14;
++v16;
}
while ( num > v15 );
}
}
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; // rbx
int v1; // ebp
int v2; // eax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // r12
__int64 v8; // rax
__int64 v9; // rdx
__int64 *v10; // r12
__int64 v11; // rax
__int64 v12; // r12

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 = 0;
do
{
v2 = 2 * v0++;
v1 = (int)((double)v1 + pow(2.0, (double)v2));
*(_DWORD *)(dnaindex + 4 * v0) = v1;
}
while ( hlen >= (int)v0 );
}
v3 = 0LL;
oldpop = xmalloc(8LL * size);
v4 = xmalloc(8LL * size);
v5 = dnaindex;
newpop = v4;
for ( result = hlen; size > (int)v3; ++v3 )
{
v7 = oldpop;
v8 = xmalloc(*(int *)(v5 + 4 * result + 4));
v9 = hlen;
*(_QWORD *)(8 * v3 + v7) = v8;
v10 = (__int64 *)(8 * v3 + newpop);
v11 = xmalloc(*(int *)(dnaindex + 4 * v9 + 4));
v5 = dnaindex;
*v10 = v11;
result = hlen;
v12 = 0LL;
if ( *(int *)(v5 + 4LL * hlen + 4) > 0 )
{
do
{
*(_BYTE *)(*(_QWORD *)(oldpop + 8 * v3) + v12) = random() % 2;
result = hlen;
++v12;
v5 = dnaindex;
}
while ( *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)v12 );
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // eax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // r12
__int64 v8; // rax
__int64 v9; // rdx
__int64 *v10; // r12
__int64 v11; // rax
__int64 v12; // r12

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 = 0;
do
{
v2 = 2 * v0++;
v1 = (int)((double)v1 + pow(2.0, (double)v2));
*(_DWORD *)(dnaindex + 4 * v0) = v1;
}
while ( hlen >= (int)v0 );
}
v3 = 0LL;
oldpop = xmalloc(8LL * size);
v4 = xmalloc(8LL * size);
v5 = dnaindex;
newpop = v4;
for ( result = hlen; size > (int)v3; ++v3 )
{
v7 = oldpop;
v8 = xmalloc(*(int *)(v5 + 4 * result + 4));
v9 = hlen;
*(_QWORD *)(8 * v3 + v7) = v8;
v10 = (__int64 *)(8 * v3 + newpop);
v11 = xmalloc(*(int *)(dnaindex + 4 * v9 + 4));
v5 = dnaindex;
*v10 = v11;
result = hlen;
v12 = 0LL;
if ( *(int *)(v5 + 4LL * hlen + 4) > 0 )
{
do
{
*(_BYTE *)(*(_QWORD *)(oldpop + 8 * v3) + v12) = random() % 2;
result = hlen;
++v12;
v5 = dnaindex;
}
while ( *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)v12 );
}
}
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


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
double v3; // xmm0_8
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
__int64 result; // rax

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

variable_types:
normfit
double *

variable_types: x double


reproduce

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; // ebx
__int64 v2; // rax
double v3; // xmm2_8
int v4; // edx
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm3_8
bool v8; // cc
double v9; // xmm0_8
__int64 v10; // rbp
__int64 v11; // r12
__int64 v12; // rbp
double v13; // xmm0_8
__int64 v14; // rbx
int v15; // edi

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

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
int v1; // ebx
__int64 v2; // rax
double v3; // xmm2_8
int v4; // edx
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm3_8
bool v8; // cc
double v9; // xmm0_8
__int64 v10; // rbp
__int64 v11; // r12
__int64 v12; // rbp
double v13; // xmm0_8
__int64 v14; // rbx
int v15; // edi

v1 = size;
if ( size <= 0 )
{
v11 = -4LL;
v10 = -1LL;
v3 = 0.0;
}
else
{
v2 = 0LL;
v3 = 0.0;
v4 = -1;
v5 = *(double *)&LC2;
do
{
v6 = *(double *)(fitness + 8 * v2);
v7 = (double)*(int *)(roundbout + 4 * v2);
v8 = v6 <= v5;
v5 = fmax(v6, v5);
if ( !v8 )
v4 = v2;
v9 = (double)*(int *)(score + 4 * v2++);
v3 = v3 + v9 / v7;
}
while ( size != v2 );
v10 = v4;
v11 = 4LL * v4;
}
v12 = 8 * v10;
fprintf(stderr, "---\ntime = %d\n", a1);
v13 = (double)v1;
v14 = 0LL;
fprintf(stderr, "average score = %f\n", v3 / v13);
fprintf(stderr, "best average score = %f\n", (double)*(int *)(score + v11) / (double)*(int *)(roundbout + v11));
fwrite("best = ", 1uLL, 7uLL, stderr);
if ( *(int *)(dnaindex + 4LL * hlen + 4) > 0 )
{
do
{
v15 = *(char *)(*(_QWORD *)(oldpop + v12) + v14++);
fputc(v15 + 67, stderr);
}
while ( *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)v14 );
}
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
int v7; // edx
__int64 v8; // rax
__int64 i; // r12
__int64 j; // rbx
int v11; // edi

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);
v7 = v4;
v4 += 2;
reproduce(v5, v6, v7);
}
while ( size > v4 );
}
v8 = newpop;
++v3;
newpop = oldpop;
oldpop = v8;
}
while ( gens > v3 );
}
if ( dump )
{
for ( i = 0LL; size > (int)i; ++i )
{
for ( j = 0LL; *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)j; ++j )
{
v11 = *(char *)(*(_QWORD *)(oldpop + 8 * i) + j);
fputc(v11 + 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
int v7; // edx
__int64 v8; // rax
__int64 i; // r12
__int64 j; // rbx
int v11; // edi

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);
v7 = v4;
v4 += 2;
func4(v5, v6, v7);
}
while ( size > v4 );
}
v8 = newpop;
++v3;
newpop = oldpop;
oldpop = v8;
}
while ( gens > v3 );
}
if ( dump )
{
for ( i = 0LL; size > (int)i; ++i )
{
for ( j = 0LL; *(_DWORD *)(dnaindex + 4LL * hlen + 4) > (int)j; ++j )
{
v11 = *(char *)(*(_QWORD *)(oldpop + 8 * i) + j);
fputc(v11 + 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; }


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, int a2)
{
return interleave_d_array(a1, 1024, a2, 0);
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, int a2)
{
return func4(a1, 1024, 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, int a2)
{
return interleave_d_array(a1, 1024, a2, 1);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
return func4(a1, 1024, 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)
{
__int64 result; // rax

if ( strstr(haystack, "plus") )
{
*((_DWORD *)wmark + 3) = 0;
result = 0LL;
}
else if ( strstr(haystack, "mult") )
{
*((_DWORD *)wmark + 3) = 1;
result = 1LL;
}
else if ( strstr(haystack, "powr") )
{
*((_DWORD *)wmark + 3) = 2;
result = 2LL;
}
else
{
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);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *haystack)
{
__int64 result; // rax

if ( strstr(haystack, "plus") )
{
*((_DWORD *)wmark + 3) = 0;
result = 0LL;
}
else if ( strstr(haystack, "mult") )
{
*((_DWORD *)wmark + 3) = 1;
result = 1LL;
}
else if ( strstr(haystack, "powr") )
{
*((_DWORD *)wmark + 3) = 2;
result = 2LL;
}
else
{
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);
result = 0xFFFFFFFFLL;
}
return result;
}

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(__int64 a1, int a2)
{
__int64 v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
v2 += 8LL;
*(double *)(v2 - 8) = norm_double();
}
while ( v2 != a1 + 8LL * (unsigned int)(a2 - 1) + 8 );
}
}

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

if ( a2 > 0 )
{
v2 = a1;
do
{
v2 += 8LL;
*(double *)(v2 - 8) = norm_double();
}
while ( v2 != a1 + 8LL * (unsigned int)(a2 - 1) + 8 );
}
}

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 *


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


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 *