decompiled_code:
void __fastcall get_options(int a1, const char **a2, const char **a3, char *a4)
{
int *v4; // rbx
double *v5; // rbx
__int64 v6; // r15
const char *v7; // r12
const char **v8; // rbx
unsigned int v9; // er13
int v10; // [rsp+Ch] [rbp-5Ch]
int v13[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v13[0] = 1;
while ( v13[0] < a1 )
{
v10 = v13[0];
v6 = v13[0];
v7 = a2[v6];
v8 = a3;
v9 = 0;
while ( strcmp(v7, "-help") )
{
if ( !*v8 )
goto LABEL_4;
if ( !strcmp(v7, *v8) )
{
switch ( *((_DWORD *)v8 + 2) )
{
case 0:
goto LABEL_5;
case 1:
goto LABEL_8;
case 2:
goto LABEL_11;
case 3:
goto LABEL_14;
case 4:
if ( !((unsigned int (__fastcall *)(const char **, _QWORD, const char **, int *, _QWORD))v8[2])(
a2,
(unsigned int)a1,
a3,
v13,
v9) )
goto LABEL_15;
bad_option(a2, v13[0]);
display_options(a2, a3, a4);
break;
default:
goto LABEL_15;
}
}
++v9;
v8 += 4;
}
display_options(a2, a3, a4);
LABEL_4:
bad_option(a2, v10);
display_options(a2, a3, a4);
LABEL_5:
if ( v10 + 1 >= a1 )
{
bad_option(a2, v10);
display_options(a2, a3, a4);
LABEL_8:
if ( v10 + 1 >= a1 )
{
bad_option(a2, v10);
display_options(a2, a3, a4);
LABEL_11:
if ( v10 + 1 >= a1 )
{
bad_option(a2, v10);
display_options(a2, a3, a4);
LABEL_14:
*(_DWORD *)v8[2] = *(_DWORD *)v8[2] == 0;
++v13[0];
}
else
{
*(_QWORD *)v8[2] = a2[v6 + 1];
v13[0] += 2;
}
}
else
{
v5 = (double *)v8[2];
*v5 = atof(a2[v6 + 1]);
v13[0] += 2;
}
}
else
{
v4 = (int *)v8[2];
*v4 = atoi(a2[v6 + 1]);
v13[0] += 2;
}
LABEL_15:
;
}
}

original_code:
void get_options(int argc, char **argv, OPTION *options, char *help)
{
  int i, j, found;
  i = 1;
  while(i < argc) {
    found = 0, j = 0;
    while(!found) {
      if(strcmp(argv[i], "-help") == 0) {
        display_options(argv, options, help);
      }
      else if(options[j].name == ((void *)0)) {
        bad_option(argv, i);
        display_options(argv, options, help);
      }
      else if(strcmp(argv[i], options[j].name) == 0) {
        found = 1;
        switch(options[j].type) {
          case OPT_INT:
            if(i + 1 >= argc) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            *(int *)options[j].ptr = atoi(argv[i + 1]);
            i += 2;
            break;
          case OPT_DOUBLE:
            if(i + 1 >= argc) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            *(double *)options[j].ptr = atof(argv[i + 1]);
            i += 2;
            break;
          case OPT_STRING:
            if(i + 1 >= argc) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            *(char **)options[j].ptr = argv[i + 1];
            i += 2;
            break;
          case OPT_SWITCH:
            *(int *)options[j].ptr = !*(int *)options[j].ptr;
            i += 1;
            break;
          case OPT_OTHER:
            if(((int (*)())options[j].ptr)(argv, argc, options, &i, j)) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            break;
          default:
            break;
        }
      }
      j++;
    }
  }
}

canonical_original_code:
void get_options(int argc, char **argv, struct OPTION *options, char *help)
{
  int i; int j; int found;
  i = 1;
  while(i < argc) {
    found = 0, j = 0;
    while(!found) {
      if(strcmp(argv[i], "-help") == 0) {
        display_options(argv, options, help);
      }
      else if(options[j].name == ((void *)0)) {
        bad_option(argv, i);
        display_options(argv, options, help);
      }
      else if(strcmp(argv[i], options[j].name) == 0) {
        found = 1;
        switch(options[j].type) {
          case OPT_INT:
            if(i + 1 >= argc) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            *(int *)options[j].ptr = atoi(argv[i + 1]);
            i += 2;
            break;
          case OPT_DOUBLE:
            if(i + 1 >= argc) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            *(double *)options[j].ptr = atof(argv[i + 1]);
            i += 2;
            break;
          case OPT_STRING:
            if(i + 1 >= argc) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            *(char **)options[j].ptr = argv[i + 1];
            i += 2;
            break;
          case OPT_SWITCH:
            *(int *)options[j].ptr = !*(int *)options[j].ptr;
            i += 1;
            break;
          case OPT_OTHER:
            if(((int (*)())options[j].ptr)(argv, argc, options, &i, j)) {
              bad_option(argv, i);
              display_options(argv, options, help);
            }
            break;
          default:
            break;
        }
      }
      j++;
    }
  }
}

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:
help
char *

variable_types: i int

variable_types: j int

variable_types: found int


repo: ramalho/CBofN

decompiled_code:
double __fastcall random_range(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)(int)random() * 4.656612873077393e-10) & LC11) * (a2 - a1) + a1;
}

canonical_decompiled_code:
double __fastcall func9(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)(int)random() * 4.656612873077393e-10) & LC11) * (a2 - a1) + a1;
}

original_code:
double random_range(double low, double high)
{
  double tmp;
  tmp = fabs((double)(random()) / ((double) 2147483647 + 1));
  tmp = tmp * (high - low) + low;
  return(tmp);
}

variable_types: low double

variable_types: high double

variable_types: tmp double

return_type: double


decompiled_code:
double random_gauss()
{
double result; // xmm0_8
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // [rsp+0h] [rbp-20h]
double v5; // [rsp+10h] [rbp-10h]

if ( holding_1 )
{
holding_1 = 0;
result = *(double *)&hold_0;
}
else
{
do
{
v4 = random_range(-1.0, 1.0);
v5 = random_range(-1.0, 1.0);
v2 = v4 * v4 + v5 * v5;
}
while ( v2 >= 1.0 );
v3 = log(v2) * -2.0 / v2;
if ( v3 < 0.0 )
v1 = sqrt(v3);
else
v1 = sqrt(v3);
*(double *)&hold_0 = v4 * v1;
holding_1 = 1;
result = v1 * v5;
}
return result;
}

canonical_decompiled_code:
double func10()
{
double result; // xmm0_8
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // [rsp+0h] [rbp-20h]
double v5; // [rsp+10h] [rbp-10h]

if ( holding_1 )
{
holding_1 = 0;
result = *(double *)&hold_0;
}
else
{
do
{
v4 = func9(-1.0, 1.0);
v5 = func9(-1.0, 1.0);
v2 = v4 * v4 + v5 * v5;
}
while ( v2 >= 1.0 );
v3 = log(v2) * -2.0 / v2;
if ( v3 < 0.0 )
v1 = sqrt(v3);
else
v1 = sqrt(v3);
*(double *)&hold_0 = v4 * v1;
holding_1 = 1;
result = v1 * v5;
}
return result;
}

original_code:
double random_gauss(void)
{
  static int holding = 0;
  static double hold;
  double factor, r, v1, v2;
  if(holding) {
    holding = 0;
    return(hold);
  }
  else {
    do {
      v1 = random_range(-1.0, 1.0);
      v2 = random_range(-1.0, 1.0);
      r = v1 * v1 + v2 * v2;
    } while(r >= 1.0);
    factor = sqrt(-2.0 * log(r) / r);
    hold = v1 * factor;
    holding = 1;
    return(v2 * factor);
  }
}

canonical_original_code:
double random_gauss()
{
  static int holding = 0;
  static double hold;
  double factor; double r; double v1; double v2;
  if(holding) {
    holding = 0;
    return(hold);
  }
  else {
    do {
      v1 = random_range(-1.0, 1.0);
      v2 = random_range(-1.0, 1.0);
      r = v1 * v1 + v2 * v2;
    } while(r >= 1.0);
    factor = sqrt(-2.0 * log(r) / r);
    hold = v1 * factor;
    holding = 1;
    return(v2 * factor);
  }
}

variable_types: holding int

variable_types: hold double

variable_types: factor double

variable_types: r double


decompiled_code:
int __fastcall int_to_hexstr(unsigned int a1, char *a2)
{
int result; // eax

result = sprintf(a2, "%2x", a1);
if ( *a2 == 32 )
*a2 = 48;
if ( a2[1] == 32 )
a2[1] = 48;
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, char *a2)
{
int result; // eax

result = sprintf(a2, "%2x", a1);
if ( *a2 == 32 )
*a2 = 48;
if ( a2[1] == 32 )
a2[1] = 48;
return result;
}

original_code:
static void int_to_hexstr(int i, char *str)
{
   sprintf(str, "%2x", i);
   for(i = 0; i < 2; i++)
     if(str[i] == ' ') str[i] = '0';
}

variable_types:
str
char *

return_type: void


decompiled_code:
Window __fastcall x11plot_init(int a1, int a2, int a3)
{
char *v4; // rbx
Display *v5; // rax
__int64 v6; // rbx
unsigned __int64 v7; // rcx
__int64 *v8; // rax
unsigned __int64 v9; // rcx
unsigned __int64 *v10; // rax
Window result; // rax
char *v12; // rax
__int64 v13; // rax
char v14[24]; // [rsp+0h] [rbp-58h] BYREF
char v15[8]; // [rsp+18h] [rbp-40h] BYREF
XColor v16; // [rsp+20h] [rbp-38h] BYREF

v4 = getenv("DISPLAY");
v5 = XOpenDisplay(v4);
x_display = v5;
if ( !v5 )
{
v12 = XDisplayName(v4);
fprintf(stderr, "x11plot_init: could not open display %s.\n", v12);
exit(1);
}
x_screen = XDefaultScreen(v5);
x_depth = XDefaultDepth(x_display, x_screen);
x_whitepixel = XWhitePixel(x_display, x_screen);
x_blackpixel = XBlackPixel(x_display, x_screen);
x_colormap = XDefaultColormap(x_display, x_screen);
if ( x_depth == 1 || (v6 = 0LL, a3 == 2) )
{
v7 = x_blackpixel;
v8 = x_grays;
do
*v8++ = v7;
while ( v8 != (__int64 *)&unk_980 );
v9 = x_whitepixel;
v10 = (unsigned __int64 *)&unk_980;
do
*v10++ = v9;
while ( v10 != &x_whitepixel );
}
else
{
do
{
int_to_hexstr(2 * v6, v15);
sprintf(v14, "#%s%s%s", v15, v15, v15);
if ( XParseColor(x_display, x_colormap, v14, &v16) )
{
if ( XAllocColor(x_display, x_colormap, &v16) )
{
x_grays[v6] = v16.pixel;
}
else
{
v13 = x_blackpixel;
if ( (int)v6 >= 64 )
v13 = x_whitepixel;
x_grays[v6] = v13;
}
}
else
{
fprintf(stderr, "No such color %s\n", v14);
}
++v6;
}
while ( v6 != 128 );
}
x11plot_levels = a3;
result = open_window(a1 * plot_mag, plot_mag * a2);
x_window = result;
return result;
}

canonical_decompiled_code:
Window __fastcall func4(int a1, int a2, int a3)
{
char *v4; // rbx
Display *v5; // rax
__int64 v6; // rbx
unsigned __int64 v7; // rcx
__int64 *v8; // rax
unsigned __int64 v9; // rcx
unsigned __int64 *v10; // rax
Window result; // rax
char *v12; // rax
__int64 v13; // rax
char v14[24]; // [rsp+0h] [rbp-58h] BYREF
char v15[8]; // [rsp+18h] [rbp-40h] BYREF
XColor v16; // [rsp+20h] [rbp-38h] BYREF

v4 = getenv("DISPLAY");
v5 = XOpenDisplay(v4);
x_display = v5;
if ( !v5 )
{
v12 = XDisplayName(v4);
fprintf(stderr, "x11plot_init: could not open display %s.\n", v12);
exit(1);
}
x_screen = XDefaultScreen(v5);
x_depth = XDefaultDepth(x_display, x_screen);
x_whitepixel = XWhitePixel(x_display, x_screen);
x_blackpixel = XBlackPixel(x_display, x_screen);
x_colormap = XDefaultColormap(x_display, x_screen);
if ( x_depth == 1 || (v6 = 0LL, a3 == 2) )
{
v7 = x_blackpixel;
v8 = x_grays;
do
*v8++ = v7;
while ( v8 != (__int64 *)&unk_980 );
v9 = x_whitepixel;
v10 = (unsigned __int64 *)&unk_980;
do
*v10++ = v9;
while ( v10 != &x_whitepixel );
}
else
{
do
{
func1(2 * v6, v15);
sprintf(v14, "#%s%s%s", v15, v15, v15);
if ( XParseColor(x_display, x_colormap, v14, &v16) )
{
if ( XAllocColor(x_display, x_colormap, &v16) )
{
x_grays[v6] = v16.pixel;
}
else
{
v13 = x_blackpixel;
if ( (int)v6 >= 64 )
v13 = x_whitepixel;
x_grays[v6] = v13;
}
}
else
{
fprintf(stderr, "No such color %s\n", v14);
}
++v6;
}
while ( v6 != 128 );
}
x11plot_levels = a3;
result = func3(a1 * plot_mag, plot_mag * a2);
x_window = result;
return result;
}

original_code:
void x11plot_init(int width, int height, int levels)
{
  XColor x_hardwarecolor;
  char hex[8], name[16], *display;
  int status, i;
  display = getenv("DISPLAY");
  if((x_display = XOpenDisplay(display)) == ((void *)0)) {
    fprintf(stderr, "x11plot_init: could not open display %s.\n",
            XDisplayName(display));
    exit(1);
  }
  x_screen = XDefaultScreen(x_display);
  x_depth = XDefaultDepth(x_display, x_screen);
  x_whitepixel = XWhitePixel(x_display, x_screen);
  x_blackpixel = XBlackPixel(x_display, x_screen);
  x_colormap = XDefaultColormap(x_display, x_screen);
  if(x_depth == 1 || levels == 2) {
    for(i = 0; i < 128 / 2; i++) x_grays[i] = x_blackpixel;
    for(i = 128 / 2; i < 128; i++) x_grays[i] = x_whitepixel;
  }
  else {
    for(i = 0; i < 128; i++) {
      int_to_hexstr(i<<1, hex);
      sprintf(name,"#%s%s%s",hex,hex,hex);
      status = XParseColor(x_display, x_colormap, name, &x_hardwarecolor);
      if (status != 0) {
        status = XAllocColor(x_display, x_colormap, &x_hardwarecolor);
        if (status != 0)
          x_grays[i] = x_hardwarecolor.pixel;
        else {
          x_grays[i] = (i < 128 / 2) ? x_blackpixel :
            x_whitepixel;
        }
      }
      else
        fprintf(stderr, "No such color %s\n", name);
    }
  }
  x11plot_width = width;
  x11plot_height = height;
  x11plot_levels = levels;
  x_window = open_window(width * plot_mag, height * plot_mag);
}

canonical_original_code:
void x11plot_init(int width, int height, int levels)
{
  struct XColor x_hardwarecolor;
  char hex[8]; char name[16]; char *display;
  int status; int i;
  display = getenv("DISPLAY");
  if((x_display = XOpenDisplay(display)) == ((void *)0)) {
    fprintf(stderr, "x11plot_init: could not open display %s.\n",
            XDisplayName(display));
    exit(1);
  }
  x_screen = XDefaultScreen(x_display);
  x_depth = XDefaultDepth(x_display, x_screen);
  x_whitepixel = XWhitePixel(x_display, x_screen);
  x_blackpixel = XBlackPixel(x_display, x_screen);
  x_colormap = XDefaultColormap(x_display, x_screen);
  if(x_depth == 1 || levels == 2) {
    for(i = 0; i < 128 / 2; i++) x_grays[i] = x_blackpixel;
    for(i = 128 / 2; i < 128; i++) x_grays[i] = x_whitepixel;
  }
  else {
    for(i = 0; i < 128; i++) {
      int_to_hexstr(i<<1, hex);
      sprintf(name,"#%s%s%s",hex,hex,hex);
      status = XParseColor(x_display, x_colormap, name, &x_hardwarecolor);
      if (status != 0) {
        status = XAllocColor(x_display, x_colormap, &x_hardwarecolor);
        if (status != 0)
          x_grays[i] = x_hardwarecolor.pixel;
        else {
          x_grays[i] = (i < 128 / 2) ? x_blackpixel :
            x_whitepixel;
        }
      }
      else
        fprintf(stderr, "No such color %s\n", name);
    }
  }
  x11plot_width = width;
  x11plot_height = height;
  x11plot_levels = levels;
  x_window = open_window(width * plot_mag, height * plot_mag);
}

variable_types: width int

variable_types: height int

variable_types: levels int

variable_types: struct XColor { unsigned long pixel; unsigned short red; char flags; char pad; }

variable_types:
hex
char [8]

variable_types:
name
char [16]

variable_types:
display
char *

variable_types: status int


decompiled_code:
int __fastcall x11plot_point(int a1, int a2, int a3)
{
int result; // eax
int i; // ebp
int j; // ebx
int v6; // ecx

if ( a3 < 0 )
{
a3 = 0;
}
else if ( x11plot_levels <= a3 )
{
a3 = x11plot_levels - 1;
}
result = XSetForeground(x_display, x_gc, x_grays[(int)((double)a3 / (double)(x11plot_levels - 1) * 127.0 + 0.5)]);
for ( i = 0; plot_mag > i; ++i )
{
v6 = plot_mag;
for ( j = 0; plot_mag > j; v6 = plot_mag )
result = XDrawPoint(x_display, x_window, x_gc, i + a1 * v6, v6 * a2 + j++);
}
if ( x11_force_flush )
result = XFlush(x_display);
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, int a2, int a3)
{
int result; // eax
int i; // ebp
int j; // ebx
int v6; // ecx

if ( a3 < 0 )
{
a3 = 0;
}
else if ( x11plot_levels <= a3 )
{
a3 = x11plot_levels - 1;
}
result = XSetForeground(x_display, x_gc, x_grays[(int)((double)a3 / (double)(x11plot_levels - 1) * 127.0 + 0.5)]);
for ( i = 0; plot_mag > i; ++i )
{
v6 = plot_mag;
for ( j = 0; plot_mag > j; v6 = plot_mag )
result = XDrawPoint(x_display, x_window, x_gc, i + a1 * v6, v6 * a2 + j++);
}
if ( x11_force_flush )
result = XFlush(x_display);
return result;
}

original_code:
void x11plot_point(int i, int j, int val)
{
  int grayval, ii, jj;
  val = (val < 0) ? 0 : (val >= x11plot_levels) ? x11plot_levels - 1: val;
  grayval = ((double)val / (x11plot_levels - 1)) * (128 - 1) + 0.5;
  XSetForeground(x_display, x_gc, x_grays[grayval]);
  for(ii = 0; ii < plot_mag; ii++)
    for(jj = 0; jj < plot_mag; jj++)
      XDrawPoint(x_display, x_window, x_gc, i * plot_mag + ii,
                 j * plot_mag + jj);
  if(x11_force_flush) XFlush(x_display);
}

canonical_original_code:
void x11plot_point(int i, int j, int val)
{
  int grayval; int ii; int jj;
  val = (val < 0) ? 0 : (val >= x11plot_levels) ? x11plot_levels - 1: val;
  grayval = ((double)val / (x11plot_levels - 1)) * (128 - 1) + 0.5;
  XSetForeground(x_display, x_gc, x_grays[grayval]);
  for(ii = 0; ii < plot_mag; ii++)
    for(jj = 0; jj < plot_mag; jj++)
      XDrawPoint(x_display, x_window, x_gc, i * plot_mag + ii,
                 j * plot_mag + jj);
  if(x11_force_flush) XFlush(x_display);
}

variable_types: i int

variable_types: j int

variable_types: val int

variable_types: grayval int

variable_types: ii int

variable_types: jj int


decompiled_code:
int __fastcall x11plot_line(int a1, int a2, int a3, int a4, int a5)
{
int v6; // er15
int v7; // ebp
signed int v8; // eax
int v9; // ebx
int result; // eax
double v11; // [rsp+8h] [rbp-50h]

v6 = 0;
if ( a5 >= 0 )
{
if ( x11plot_levels <= a5 )
a5 = x11plot_levels;
v6 = a5;
}
XSetForeground(x_display, x_gc, x_grays[(int)((double)v6 / (double)x11plot_levels * 127.0 + 0.5)]);
if ( plot_mag == 1 )
return XDrawLine(x_display, x_window, x_gc, a1, a2, a3, a4);
if ( a1 == a3 && a2 == a4 )
return x11plot_point(a1, a2, v6);
v7 = abs32(a2 - a4);
v8 = abs32(a1 - a3);
if ( v7 < v8 )
v7 = v8;
v11 = 0.0;
v9 = 0;
do
{
result = x11plot_point(
(int)((double)a1 * v11 + (double)a3 * (1.0 - v11) + 0.5),
(int)((double)a4 * (1.0 - v11) + (double)a2 * v11 + 0.5),
v6);
++v9;
v11 = v11 + 1.0 / (double)v7;
}
while ( v7 >= v9 );
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1, int a2, int a3, int a4, int a5)
{
int v6; // er15
int v7; // ebp
signed int v8; // eax
int v9; // ebx
int result; // eax
double v11; // [rsp+8h] [rbp-50h]

v6 = 0;
if ( a5 >= 0 )
{
if ( x11plot_levels <= a5 )
a5 = x11plot_levels;
v6 = a5;
}
XSetForeground(x_display, x_gc, x_grays[(int)((double)v6 / (double)x11plot_levels * 127.0 + 0.5)]);
if ( plot_mag == 1 )
return XDrawLine(x_display, x_window, x_gc, a1, a2, a3, a4);
if ( a1 == a3 && a2 == a4 )
return func5(a1, a2, v6);
v7 = abs32(a2 - a4);
v8 = abs32(a1 - a3);
if ( v7 < v8 )
v7 = v8;
v11 = 0.0;
v9 = 0;
do
{
result = func5(
(int)((double)a1 * v11 + (double)a3 * (1.0 - v11) + 0.5),
(int)((double)a4 * (1.0 - v11) + (double)a2 * v11 + 0.5),
v6);
++v9;
v11 = v11 + 1.0 / (double)v7;
}
while ( v7 >= v9 );
return result;
}

original_code:
void x11plot_line(int i, int j, int k, int l, int val)
{
  int grayval, ii, jj;
  val = (val < 0) ? 0 : (val >= x11plot_levels) ? x11plot_levels : val;
  grayval = ((double)val / x11plot_levels) * (128 - 1) + 0.5;
  XSetForeground(x_display, x_gc, x_grays[grayval]);
  if(plot_mag == 1)
    XDrawLine(x_display, x_window, x_gc, i, j, k, l);
  else {
    double tx, ty, t, dt;
    int len;
    if(i == k && j == l)
      x11plot_point(i, j, val);
    else {
      len = ((((i - k) >= 0 ? (i - k) : -(i - k))) > (((j - l) >= 0 ? (j - l) : -(j - l))) ? (((i - k) >= 0 ? (i - k) : -(i - k))) : (((j - l) >= 0 ? (j - l) : -(j - l))));
      dt = 1.0 / len;
      for(ii = 0, t = 0.0; ii < len + 1; ii++, t += dt) {
        tx = t * i + (1.0 - t) * k + 0.5;
        ty = t * j + (1.0 - t) * l + 0.5;
        x11plot_point(tx, ty, val);
      }
    }
  }
}

canonical_original_code:
void x11plot_line(int i, int j, int k, int l, int val)
{
  int grayval; int ii; int jj;
  val = (val < 0) ? 0 : (val >= x11plot_levels) ? x11plot_levels : val;
  grayval = ((double)val / x11plot_levels) * (128 - 1) + 0.5;
  XSetForeground(x_display, x_gc, x_grays[grayval]);
  if(plot_mag == 1)
    XDrawLine(x_display, x_window, x_gc, i, j, k, l);
  else {
    double tx; double ty; double t; double dt;
    int len;
    if(i == k && j == l)
      x11plot_point(i, j, val);
    else {
      len = ((((i - k) >= 0 ? (i - k) : -(i - k))) > (((j - l) >= 0 ? (j - l) : -(j - l))) ? (((i - k) >= 0 ? (i - k) : -(i - k))) : (((j - l) >= 0 ? (j - l) : -(j - l))));
      dt = 1.0 / len;
      for(ii = 0, t = 0.0; ii < len + 1; ii++, t += dt) {
        tx = t * i + (1.0 - t) * k + 0.5;
        ty = t * j + (1.0 - t) * l + 0.5;
        x11plot_point(tx, ty, val);
      }
    }
  }
}

variable_types: k int

variable_types: l int

variable_types: tx double

variable_types: ty double

variable_types: t double

variable_types: dt double

variable_types: len int


original_code:
void random_solution(int *x)
{
  int i, j, t;
  for(i = 0; i < len; i++)
    x[i] = i;
  for(i = 0; i < len - 1; i++) {
    j = (random() % (len - i)) + i;
    t = x[i]; x[i] = x[j]; x[j] = t;
  }
}

canonical_original_code:
void random_solution(int *x)
{
  int i; int j; int t;
  for(i = 0; i < len; i++)
    x[i] = i;
  for(i = 0; i < len - 1; i++) {
    j = (random() % (len - i)) + i;
    t = x[i]; x[i] = x[j]; x[j] = t;
  }
}

variable_types:
x
int *

variable_types: t int


decompiled_code:
__int64 __fastcall task_cost(__int64 a1)
{
__int64 v1; // rax
int v2; // edx

if ( len <= 0 )
{
v2 = 0;
}
else
{
v1 = 0LL;
v2 = 0;
do
{
v2 = (int)((double)v2 + *(double *)(*(_QWORD *)(cost + 8 * v1) + 8LL * *(int *)(a1 + 4 * v1)));
++v1;
}
while ( v1 != len );
}
return (unsigned int)v2;
}

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

if ( len <= 0 )
{
v2 = 0;
}
else
{
v1 = 0LL;
v2 = 0;
do
{
v2 = (int)((double)v2 + *(double *)(*(_QWORD *)(cost + 8 * v1) + 8LL * *(int *)(a1 + 4 * v1)));
++v1;
}
while ( v1 != len );
}
return (unsigned int)v2;
}

original_code:
int task_cost(int *solution)
{
  int i, sum = 0;
  for(i = 0; i < len; i++)
    sum += cost[i][solution[i]];
  return(sum);
}

canonical_original_code:
int task_cost(int *solution)
{
  int i; int sum = 0;
  for(i = 0; i < len; i++)
    sum += cost[i][solution[i]];
  return(sum);
}

variable_types:
solution
int *

variable_types: sum int

return_type: int


original_code:
void compute_fitness(int **pop, double *fit, double *normfit)
{
  int i;
  double sum, min = 10e10;
  sum = 0;
  for(i = 0; i < size; i++) {
    fit[i] = task_cost(pop[i]);
    if(fit[i] < min) min = fit[i];
  }
  for(i = 0; i < size; i++) {
    normfit[i] = pow(pbase, fit[i] - min);
    sum += normfit[i];
  }
  for(i = 0; i < size; i++)
    normfit[i] /= sum;
}

canonical_original_code:
void compute_fitness(int **pop, double *fit, double *normfit)
{
  int i;
  double sum; double min = 10e10;
  sum = 0;
  for(i = 0; i < size; i++) {
    fit[i] = task_cost(pop[i]);
    if(fit[i] < min) min = fit[i];
  }
  for(i = 0; i < size; i++) {
    normfit[i] = pow(pbase, fit[i] - min);
    sum += normfit[i];
  }
  for(i = 0; i < size; i++)
    normfit[i] /= sum;
}

variable_types:
pop
int **

variable_types:
fit
double *

variable_types:
normfit
double *

variable_types: i int

variable_types: sum double

variable_types: min double


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

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

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

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

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

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

variable_types: x double


reproduce

original_code:
void reproduce(int **oldpop, int **newpop, int pa, int pb,int index)
{
  int i, j, a, b, ai, bi = 0;
  for(i = 0; i < len; i++) {
    newpop[index][i] = oldpop[pa][i];
    newpop[index + 1][i] = oldpop[pb][i];
  }
  if(random_range(0, 1) < crate) {
    ai = random() % len;
    a = newpop[index][ai];
    b = newpop[index + 1][ai];
    for(i = 0; i < len; i++)
      if(newpop[index][i] == b) {
        bi = i; break;
      }
    newpop[index][ai] = b;
    newpop[index][bi] = a;
    a = newpop[index + 1][bi];
    newpop[index + 1][ai] = a;
    newpop[index + 1][bi] = b;
  }
  for(i = 0; i < len; i++) {
    if(random_range(0, 1) < mrate) {
      j = random() % len;
      a = newpop[index][i];
      newpop[index][i] = newpop[index][j];
      newpop[index][j] = a;
    }
    if(random_range(0, 1) < mrate) {
      j = random() % len;
      a = newpop[index + 1][i];
      newpop[index + 1][i] = newpop[index + 1][j];
      newpop[index + 1][j] = a;
    }
  }
}

canonical_original_code:
void reproduce(int **oldpop, int **newpop, int pa, int pb, int index)
{
  int i; int j; int a; int b; int ai; int bi = 0;
  for(i = 0; i < len; i++) {
    newpop[index][i] = oldpop[pa][i];
    newpop[index + 1][i] = oldpop[pb][i];
  }
  if(random_range(0, 1) < crate) {
    ai = random() % len;
    a = newpop[index][ai];
    b = newpop[index + 1][ai];
    for(i = 0; i < len; i++)
      if(newpop[index][i] == b) {
        bi = i; break;
      }
    newpop[index][ai] = b;
    newpop[index][bi] = a;
    a = newpop[index + 1][bi];
    newpop[index + 1][ai] = a;
    newpop[index + 1][bi] = b;
  }
  for(i = 0; i < len; i++) {
    if(random_range(0, 1) < mrate) {
      j = random() % len;
      a = newpop[index][i];
      newpop[index][i] = newpop[index][j];
      newpop[index][j] = a;
    }
    if(random_range(0, 1) < mrate) {
      j = random() % len;
      a = newpop[index + 1][i];
      newpop[index + 1][i] = newpop[index + 1][j];
      newpop[index + 1][j] = a;
    }
  }
}

variable_types:
oldpop
int **

variable_types:
newpop
int **

variable_types: pa int

variable_types: pb int

variable_types: index int

variable_types: j int

variable_types: a int

variable_types: b int

variable_types: ai int

variable_types: bi int


decompiled_code:
int __fastcall dump_stats(unsigned int a1, __int64 a2, __int64 a3)
{
int v3; // er12
__int64 v4; // rax
int v5; // ebx
double v6; // xmm0_8
bool v7; // cc
int v8; // eax
_QWORD *v9; // r12
__int64 v10; // rbx
const char *v11; // rdi
double v13; // [rsp+0h] [rbp-28h]
double v14; // [rsp+8h] [rbp-20h]

v3 = size;
if ( size <= 0 )
{
v14 = 0.0;
v13 = *(double *)&LC9;
v5 = -1;
}
else
{
v4 = 0LL;
v14 = 0.0;
v13 = *(double *)&LC9;
v5 = -1;
do
{
v6 = *(double *)(a3 + 8 * v4);
v7 = v6 <= v13;
v13 = fmax(v6, v13);
if ( !v7 )
v5 = v4;
v14 = v6 + v14;
++v4;
}
while ( v4 != size );
}
printf("---\ntime = %d\n", a1);
printf("average value = %f\n", v14 / (double)v3);
printf("best DNA = ");
v8 = len;
if ( len > 0 )
{
v9 = (_QWORD *)(a2 + 8LL * v5);
v10 = 0LL;
do
{
v11 = "%d\n";
if ( v8 - 1 > (int)v10 )
v11 = "%d, ";
printf(v11, (unsigned int)(*(_DWORD *)(*v9 + 4 * v10) + 1));
v8 = len;
++v10;
}
while ( len > (int)v10 );
}
return printf("best score = %d\n", (unsigned int)(int)v13);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1, __int64 a2, __int64 a3)
{
int v3; // er12
__int64 v4; // rax
int v5; // ebx
double v6; // xmm0_8
bool v7; // cc
int v8; // eax
_QWORD *v9; // r12
__int64 v10; // rbx
const char *v11; // rdi
double v13; // [rsp+0h] [rbp-28h]
double v14; // [rsp+8h] [rbp-20h]

v3 = size;
if ( size <= 0 )
{
v14 = 0.0;
v13 = *(double *)&LC9;
v5 = -1;
}
else
{
v4 = 0LL;
v14 = 0.0;
v13 = *(double *)&LC9;
v5 = -1;
do
{
v6 = *(double *)(a3 + 8 * v4);
v7 = v6 <= v13;
v13 = fmax(v6, v13);
if ( !v7 )
v5 = v4;
v14 = v6 + v14;
++v4;
}
while ( v4 != size );
}
printf("---\ntime = %d\n", a1);
printf("average value = %f\n", v14 / (double)v3);
printf("best DNA = ");
v8 = len;
if ( len > 0 )
{
v9 = (_QWORD *)(a2 + 8LL * v5);
v10 = 0LL;
do
{
v11 = "%d\n";
if ( v8 - 1 > (int)v10 )
v11 = "%d, ";
printf(v11, (unsigned int)(*(_DWORD *)(*v9 + 4 * v10) + 1));
v8 = len;
++v10;
}
while ( len > (int)v10 );
}
return printf("best score = %d\n", (unsigned int)(int)v13);
}

original_code:
void dump_stats(int time, int **pop, double *fit)
{
  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 += fit[i];
  }
  ave /= size;
  printf("---\ntime = %d\n", time);
  printf("average value = %f\n", ave);
  printf("best DNA      = ");
  for(i = 0; i < len; i++)
    printf((i < len - 1) ? "%d, " : "%d\n", pop[besti][i] + 1);
  printf("best score    = %d\n", (int)best);
}

canonical_original_code:
void dump_stats(int time, int **pop, double *fit)
{
  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 += fit[i];
  }
  ave /= size;
  printf("---\ntime = %d\n", time);
  printf("average value = %f\n", ave);
  printf("best DNA      = ");
  for(i = 0; i < len; i++)
    printf((i < len - 1) ? "%d, " : "%d\n", pop[besti][i] + 1);
  printf("best score    = %d\n", (int)best);
}

variable_types: time int

variable_types:
pop
int **

variable_types: besti int

variable_types: best double

variable_types: ave double


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // r15
int v7; // ebx
signed int v8; // er15
int v9; // ebx
int v10; // er14
int v11; // eax
__int64 v12; // rax
__int64 *v13; // [rsp+0h] [rbp-48h]
__int64 v14; // [rsp+8h] [rbp-40h]

get_options(argc, argv, &options, help_string);
srandom(seed);
read_specs(specs);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v3 = xmalloc(8LL * size);
v4 = xmalloc(8LL * size);
v14 = xmalloc(8LL * size);
v5 = xmalloc(8LL * size);
if ( size > 0 )
{
v13 = (__int64 *)v4;
v6 = 0LL;
do
{
*(_QWORD *)(v3 + 8 * v6) = xmalloc(4LL * len);
*v13 = xmalloc(4LL * len);
if ( len > 0 )
{
v7 = 0;
do
{
random_solution(*v13);
++v7;
}
while ( 2 * len > v7 );
}
++v6;
++v13;
}
while ( size > (int)v6 );
}
if ( gens > 0 )
{
v8 = 0;
while ( 1 )
{
compute_fitness(v4, v14, v5);
dump_stats(v8, v4, v14);
if ( size > 0 )
{
v9 = 0;
do
{
v10 = select_one(v5);
v11 = select_one(v5);
reproduce(v4, v3, v10, v11, v9);
v9 += 2;
}
while ( size > v9 );
}
++v8;
v12 = v4;
v4 = v3;
if ( gens <= v8 )
break;
v3 = v12;
}
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // r15
int v7; // ebx
signed int v8; // er15
int v9; // ebx
int v10; // er14
int v11; // eax
__int64 v12; // rax
__int64 *v13; // [rsp+0h] [rbp-48h]
__int64 v14; // [rsp+8h] [rbp-40h]

get_options(argc, argv, &options, help_string);
srandom(seed);
func0(specs);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v3 = xmalloc(8LL * size);
v4 = xmalloc(8LL * size);
v14 = xmalloc(8LL * size);
v5 = xmalloc(8LL * size);
if ( size > 0 )
{
v13 = (__int64 *)v4;
v6 = 0LL;
do
{
*(_QWORD *)(v3 + 8 * v6) = xmalloc(4LL * len);
*v13 = xmalloc(4LL * len);
if ( len > 0 )
{
v7 = 0;
do
{
func1(*v13);
++v7;
}
while ( 2 * len > v7 );
}
++v6;
++v13;
}
while ( size > (int)v6 );
}
if ( gens > 0 )
{
v8 = 0;
while ( 1 )
{
func3(v4, v14, v5);
func6(v8, v4, v14);
if ( size > 0 )
{
v9 = 0;
do
{
v10 = func4(v5);
v11 = func4(v5);
func5(v4, v3, v10, v11, v9);
v9 += 2;
}
while ( size > v9 );
}
++v8;
v12 = v4;
v4 = v3;
if ( gens <= v8 )
break;
v3 = v12;
}
}
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  int i, j, t, parent_a, parent_b;
  int **swap, **newpop, **oldpop;
  double *fit, *normfit;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  read_specs(specs);
  size += (size / 2 * 2 != size);
  newpop = xmalloc(sizeof(int *) * size);
  oldpop = xmalloc(sizeof(int *) * size);
  fit = xmalloc(sizeof(double) * size);
  normfit = xmalloc(sizeof(double) * size);
  for(i = 0; i < size; i++) {
    newpop[i] = xmalloc(sizeof(int) * len);
    oldpop[i] = xmalloc(sizeof(int) * len);
    for(j = 0; j < len * 2; j++)
      random_solution(oldpop[i]);
  }
  for(t = 0; t < gens; t++) {
    compute_fitness(oldpop, fit, normfit);
    dump_stats(t, oldpop, fit);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      reproduce(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 parent_a; int parent_b;
  int **swap; int **newpop; int **oldpop;
  double *fit; double *normfit;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  read_specs(specs);
  size += (size / 2 * 2 != size);
  newpop = xmalloc(sizeof(int *) * size);
  oldpop = xmalloc(sizeof(int *) * size);
  fit = xmalloc(sizeof(double) * size);
  normfit = xmalloc(sizeof(double) * size);
  for(i = 0; i < size; i++) {
    newpop[i] = xmalloc(sizeof(int) * len);
    oldpop[i] = xmalloc(sizeof(int) * len);
    for(j = 0; j < len * 2; j++)
      random_solution(oldpop[i]);
  }
  for(t = 0; t < gens; t++) {
    compute_fitness(oldpop, fit, normfit);
    dump_stats(t, oldpop, fit);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      reproduce(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: i int

variable_types: t int

variable_types:
swap
int **

variable_types:
fit
double *

variable_types:
normfit
double *


decompiled_code:
double __fastcall str2num(char *a1)
{
char *v1; // rax
char *v2; // rdi
char *v3; // rdx
double v5; // [rsp+8h] [rbp-10h]

if ( len <= 0 )
{
v5 = 0.0;
}
else
{
v1 = a1;
v2 = &a1[len - 1];
v5 = 0.0;
do
{
v5 = (double)(*v1 - 48) + v5 + v5;
v3 = v1++;
}
while ( v3 != v2 );
}
return v5 / pow(2.0, (double)len) * 8.0 - 4.0;
}

original_code:
double str2num(char *str)
{
  int i;
  double x = 0;
  for(i = 0; i < len; i++)
    x = x * 2 + (str[i] - '0');
  return((x / pow(2, len)) * 8 - 4);
}

variable_types:
str
char *

variable_types: x double


original_code:
void compute_fitness(char **pop, double *fit, double *normfit)
{
  int i;
  double sum;
  sum = 0;
  for(i = 0; i < size; i++) {
    fit[i] = surface(str2num(&pop[i][0]), str2num(&pop[i][len]));
    sum += fit[i];
  }
  for(i = 0; i < size; i++)
    normfit[i] = fit[i] / sum;
}

variable_types:
pop
char **

variable_types: sum double


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

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


reproduce

decompiled_code:
__int64 __fastcall reproduce(__int64 a1, __int64 a2, int a3, int a4, int a5)
{
int v9; // ecx
_QWORD *v10; // r10
__int64 i; // rax
__int64 result; // rax
_QWORD *v13; // rdi
_QWORD *v14; // r12
__int64 v15; // rbx

if ( *(double *)&crate > random_range(0.0, 1.0) )
v9 = random() % (2 * len - 1) + 1;
else
v9 = 2 * len;
if ( v9 > 0 )
{
v10 = (_QWORD *)(a2 + 8LL * a5);
for ( i = 0LL; i != v9; ++i )
{
*(_BYTE *)(*v10 + i) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a3) + i);
*(_BYTE *)(v10[1] + i) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a4) + i);
}
}
result = (unsigned int)(2 * len);
if ( v9 < (int)result )
{
v13 = (_QWORD *)(a2 + 8LL * a5);
result = v9;
do
{
*(_BYTE *)(*v13 + result) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a4) + result);
*(_BYTE *)(v13[1] + result) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a3) + result);
++result;
}
while ( 2 * len > (int)result );
}
if ( len > 0 )
{
v14 = (_QWORD *)(a2 + 8LL * a5);
v15 = 0LL;
do
{
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(*v14 + v15) = random() % 2 + 48;
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(v14[1] + v15) = random() % 2 + 48;
++v15;
result = (unsigned int)(2 * len);
}
while ( (int)result > (int)v15 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3, int a4, int a5)
{
int v9; // ecx
_QWORD *v10; // r10
__int64 i; // rax
__int64 result; // rax
_QWORD *v13; // rdi
_QWORD *v14; // r12
__int64 v15; // rbx

if ( *(double *)&crate > random_range(0.0, 1.0) )
v9 = random() % (2 * len - 1) + 1;
else
v9 = 2 * len;
if ( v9 > 0 )
{
v10 = (_QWORD *)(a2 + 8LL * a5);
for ( i = 0LL; i != v9; ++i )
{
*(_BYTE *)(*v10 + i) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a3) + i);
*(_BYTE *)(v10[1] + i) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a4) + i);
}
}
result = (unsigned int)(2 * len);
if ( v9 < (int)result )
{
v13 = (_QWORD *)(a2 + 8LL * a5);
result = v9;
do
{
*(_BYTE *)(*v13 + result) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a4) + result);
*(_BYTE *)(v13[1] + result) = *(_BYTE *)(*(_QWORD *)(a1 + 8LL * a3) + result);
++result;
}
while ( 2 * len > (int)result );
}
if ( len > 0 )
{
v14 = (_QWORD *)(a2 + 8LL * a5);
v15 = 0LL;
do
{
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(*v14 + v15) = random() % 2 + 48;
if ( *(double *)&mrate > random_range(0.0, 1.0) )
*(_BYTE *)(v14[1] + v15) = random() % 2 + 48;
++v15;
result = (unsigned int)(2 * len);
}
while ( (int)result > (int)v15 );
}
return result;
}

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

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

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, __int64 a2, __int64 a3)
{
int v3; // er12
__int64 v4; // rax
int v5; // ebx
double v6; // xmm0_8
bool v7; // cc
char **v8; // rbx
double v9; // rbp
double v10; // xmm0_8
double v12; // [rsp+0h] [rbp-28h]
double v13; // [rsp+8h] [rbp-20h]

v3 = size;
if ( size <= 0 )
{
v13 = 0.0;
v12 = *(double *)&LC11;
v5 = -1;
}
else
{
v4 = 0LL;
v13 = 0.0;
v12 = *(double *)&LC11;
v5 = -1;
do
{
v6 = *(double *)(a3 + 8 * v4);
v7 = v6 <= v12;
v12 = fmax(v6, v12);
if ( !v7 )
v5 = v4;
v13 = v6 + v13;
++v4;
}
while ( v4 != size );
}
printf("---\ntime = %d\n", a1);
printf("average value = %f\n", v13 / (double)v3);
v8 = (char **)(a2 + 8LL * v5);
v9 = str2num(&(*v8)[len]);
v10 = str2num(*v8);
printf("best (x, y) = (%f, %f)\n", v10, v9);
printf("best DNA = \"%s\"\n", *v8);
return printf("best value = %f\n", v12);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, __int64 a2, __int64 a3)
{
int v3; // er12
__int64 v4; // rax
int v5; // ebx
double v6; // xmm0_8
bool v7; // cc
char **v8; // rbx
double v9; // rbp
double v10; // xmm0_8
double v12; // [rsp+0h] [rbp-28h]
double v13; // [rsp+8h] [rbp-20h]

v3 = size;
if ( size <= 0 )
{
v13 = 0.0;
v12 = *(double *)&LC11;
v5 = -1;
}
else
{
v4 = 0LL;
v13 = 0.0;
v12 = *(double *)&LC11;
v5 = -1;
do
{
v6 = *(double *)(a3 + 8 * v4);
v7 = v6 <= v12;
v12 = fmax(v6, v12);
if ( !v7 )
v5 = v4;
v13 = v6 + v13;
++v4;
}
while ( v4 != size );
}
printf("---\ntime = %d\n", a1);
printf("average value = %f\n", v13 / (double)v3);
v8 = (char **)(a2 + 8LL * v5);
v9 = func1(&(*v8)[len]);
v10 = func1(*v8);
printf("best (x, y) = (%f, %f)\n", v10, v9);
printf("best DNA = \"%s\"\n", *v8);
return printf("best value = %f\n", v12);
}

original_code:
void dump_stats(int time, char **pop, double *fit)
{
  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 += fit[i];
  }
  ave /= size;
  printf("---\ntime = %d\n", time);
  printf("average value = %f\n", ave);
  printf("best (x, y) = (%f, %f)\n", str2num(&pop[besti][0]),
         str2num(&pop[besti][len]));
  printf("best DNA = \"%s\"\n", pop[besti]);
  printf("best value = %f\n", best);
}

canonical_original_code:
void dump_stats(int time, char **pop, double *fit)
{
  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 += fit[i];
  }
  ave /= size;
  printf("---\ntime = %d\n", time);
  printf("average value = %f\n", ave);
  printf("best (x, y) = (%f, %f)\n", str2num(&pop[besti][0]),
         str2num(&pop[besti][len]));
  printf("best DNA = \"%s\"\n", pop[besti]);
  printf("best value = %f\n", best);
}

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)
{
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // r15
int v7; // eax
__int64 v8; // rbx
signed int v9; // er15
int v10; // ebx
int v11; // er14
int v12; // eax
__int64 v13; // rax
_QWORD *v14; // [rsp+0h] [rbp-48h]
__int64 v15; // [rsp+8h] [rbp-40h]

get_options(argc, argv, &options, help_string);
srandom(seed);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v3 = xmalloc(8LL * size);
v4 = xmalloc(8LL * size);
v15 = xmalloc(8LL * size);
v5 = xmalloc(8LL * size);
if ( size > 0 )
{
v14 = (_QWORD *)v4;
v6 = 0LL;
do
{
*(_QWORD *)(v3 + 8 * v6) = xmalloc(2LL * len + 1);
*v14 = xmalloc(2LL * len + 1);
v7 = 2 * len;
if ( 2 * len > 0 )
{
v8 = 0LL;
do
{
*(_BYTE *)(*v14 + v8) = random() % 2 + 48;
v7 = 2 * len;
++v8;
}
while ( 2 * len > (int)v8 );
}
*(_BYTE *)(*v14 + v7) = 0;
*(_BYTE *)(*(_QWORD *)(v3 + 8 * v6++) + 2 * len) = 0;
++v14;
}
while ( size > (int)v6 );
}
if ( gens > 0 )
{
v9 = 0;
while ( 1 )
{
compute_fitness(v4, v15, v5);
dump_stats(v9, v4, v15);
if ( size > 0 )
{
v10 = 0;
do
{
v11 = select_one(v5);
v12 = select_one(v5);
reproduce(v4, v3, v11, v12, v10);
v10 += 2;
}
while ( size > v10 );
}
++v9;
v13 = v4;
v4 = v3;
if ( gens <= v9 )
break;
v3 = v13;
}
}
exit(0);
}

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

get_options(argc, argv, &options, help_string);
srandom(seed);
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v3 = xmalloc(8LL * size);
v4 = xmalloc(8LL * size);
v15 = xmalloc(8LL * size);
v5 = xmalloc(8LL * size);
if ( size > 0 )
{
v14 = (_QWORD *)v4;
v6 = 0LL;
do
{
*(_QWORD *)(v3 + 8 * v6) = xmalloc(2LL * len + 1);
*v14 = xmalloc(2LL * len + 1);
v7 = 2 * len;
if ( 2 * len > 0 )
{
v8 = 0LL;
do
{
*(_BYTE *)(*v14 + v8) = random() % 2 + 48;
v7 = 2 * len;
++v8;
}
while ( 2 * len > (int)v8 );
}
*(_BYTE *)(*v14 + v7) = 0;
*(_BYTE *)(*(_QWORD *)(v3 + 8 * v6++) + 2 * len) = 0;
++v14;
}
while ( size > (int)v6 );
}
if ( gens > 0 )
{
v9 = 0;
while ( 1 )
{
func2(v4, v15, v5);
func5(v9, v4, v15);
if ( size > 0 )
{
v10 = 0;
do
{
v11 = func3(v5);
v12 = func3(v5);
func4(v4, v3, v11, v12, v10);
v10 += 2;
}
while ( size > v10 );
}
++v9;
v13 = v4;
v4 = v3;
if ( gens <= v9 )
break;
v3 = v13;
}
}
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  int i, j, t, parent_a, parent_b;
  char **swap, **newpop, **oldpop;
  double *fit, *normfit;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  size += (size / 2 * 2 != size);
  newpop = xmalloc(sizeof(char *) * size);
  oldpop = xmalloc(sizeof(char *) * size);
  fit = xmalloc(sizeof(double) * size);
  normfit = xmalloc(sizeof(double) * size);
  for(i = 0; i < size; i++) {
    newpop[i] = xmalloc(sizeof(char) * len * 2 + 1);
    oldpop[i] = xmalloc(sizeof(char) * len * 2 + 1);
    for(j = 0; j < len * 2; j++)
      oldpop[i][j] = random() % 2 + '0';
    oldpop[i][len * 2] = 0;
    newpop[i][len * 2] = 0;
  }
  for(t = 0; t < gens; t++) {
    compute_fitness(oldpop, fit, normfit);
    dump_stats(t, oldpop, fit);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      reproduce(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 parent_a; int parent_b;
  char **swap; char **newpop; char **oldpop;
  double *fit; double *normfit;
  get_options(argc, argv, options, help_string);
  srandom(seed);
  size += (size / 2 * 2 != size);
  newpop = xmalloc(sizeof(char *) * size);
  oldpop = xmalloc(sizeof(char *) * size);
  fit = xmalloc(sizeof(double) * size);
  normfit = xmalloc(sizeof(double) * size);
  for(i = 0; i < size; i++) {
    newpop[i] = xmalloc(sizeof(char) * len * 2 + 1);
    oldpop[i] = xmalloc(sizeof(char) * len * 2 + 1);
    for(j = 0; j < len * 2; j++)
      oldpop[i][j] = random() % 2 + '0';
    oldpop[i][len * 2] = 0;
    newpop[i][len * 2] = 0;
  }
  for(t = 0; t < gens; t++) {
    compute_fitness(oldpop, fit, normfit);
    dump_stats(t, oldpop, fit);
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      reproduce(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: i int

variable_types: j int

variable_types: t int

variable_types:
swap
char **


decompiled_code:
int __fastcall psplot_init(unsigned int a1, unsigned int a2, int a3)
{
psplot_levels = a3;
psplot_width = a1;
psplot_height = a2;
return printf(
"%%!PS-Adobe-2.0 EPSF-2.0\n"
"%%%%Creator: psplot\n"
"%%%%DocumentFonts: \n"
"%%%%BoundingBox: 0 0 %d %d\n"
"%%%%EndComments\n"
"/gnudict 40 dict def\n"
"gnudict begin\n"
"/gnulinewidth 1.000 def\n"
"/M {moveto} bind def\n"
"/L {lineto} bind def\n"
"/V {rlineto} bind def\n"
"/P { stroke [] 0 setdash\n"
" currentlinewidth 2 div sub M\n"
" 0 currentlinewidth V stroke } def\n"
"/dl {10 mul} def\n"
"/AL { stroke gnulinewidth 2 div setlinewidth } def\n"
"end\n"
"%%%%EndProlog\n"
"gnudict begin\n"
"gsave\n"
"newpath\n",
a1,
a2);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, unsigned int a2, int a3)
{
psplot_levels = a3;
psplot_width = a1;
psplot_height = a2;
return printf(
"%%!PS-Adobe-2.0 EPSF-2.0\n"
"%%%%Creator: psplot\n"
"%%%%DocumentFonts: \n"
"%%%%BoundingBox: 0 0 %d %d\n"
"%%%%EndComments\n"
"/gnudict 40 dict def\n"
"gnudict begin\n"
"/gnulinewidth 1.000 def\n"
"/M {moveto} bind def\n"
"/L {lineto} bind def\n"
"/V {rlineto} bind def\n"
"/P { stroke [] 0 setdash\n"
" currentlinewidth 2 div sub M\n"
" 0 currentlinewidth V stroke } def\n"
"/dl {10 mul} def\n"
"/AL { stroke gnulinewidth 2 div setlinewidth } def\n"
"end\n"
"%%%%EndProlog\n"
"gnudict begin\n"
"gsave\n"
"newpath\n",
a1,
a2);
}

original_code:
void psplot_init(int width, int height, int levels)
{
  char *psheader =
    "%%!PS-Adobe-2.0 EPSF-2.0\n%%%%Creator: psplot\n%%%%DocumentFonts: \n%%%%BoundingBox: 0 0 %d %d\n%%%%EndComments\n/gnudict 40 dict def\ngnudict begin\n/gnulinewidth 1.000 def\n/M {moveto} bind def\n/L {lineto} bind def\n/V {rlineto} bind def\n/P { stroke [] 0 setdash\n  currentlinewidth 2 div sub M\n  0 currentlinewidth V stroke } def\n/dl {10 mul} def\n/AL { stroke gnulinewidth 2 div setlinewidth } def\nend\n%%%%EndProlog\ngnudict begin\ngsave\nnewpath\n";
  psplot_levels = levels;
  psplot_width = width;
  psplot_height = height;
  printf(psheader, width, height);
}

variable_types: width int

variable_types: height int

variable_types: levels int

variable_types:
psheader
char *


decompiled_code:
int __fastcall psplot_point(unsigned int a1, int a2)
{
int result; // eax

result = printf("%d %d P\n", a1, (unsigned int)(psplot_height - a2));
oldy = -1;
oldx = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, int a2)
{
int result; // eax

result = printf("%d %d P\n", a1, (unsigned int)(psplot_height - a2));
oldy = -1;
oldx = -1;
return result;
}

original_code:
void psplot_point(int i, int j, int val)
{
  printf("%d %d P\n", i, psplot_height - j);
  oldx = oldy = -1;
}

variable_types: val int


decompiled_code:
int __fastcall psplot_line(unsigned int a1, int a2, unsigned int a3, int a4)
{
int result; // eax

if ( oldx != a1 || oldy != a2 )
printf("%d %d M\n", a1, (unsigned int)(psplot_height - a2));
result = printf("%d %d L\n", a3, (unsigned int)(psplot_height - a4));
oldx = a3;
oldy = a4;
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, int a2, unsigned int a3, int a4)
{
int result; // eax

if ( oldx != a1 || oldy != a2 )
printf("%d %d M\n", a1, (unsigned int)(psplot_height - a2));
result = printf("%d %d L\n", a3, (unsigned int)(psplot_height - a4));
oldx = a3;
oldy = a4;
return result;
}

original_code:
void psplot_line(int i, int j, int k, int l, int val)
{
  if(oldx != i || oldy != j)
    printf("%d %d M\n", i, psplot_height - j);
  printf("%d %d L\n", k, psplot_height - l);
  oldx = k; oldy = l;
}

variable_types: k int

variable_types: l int


decompiled_code:
int psplot_finish()
{
puts("stroke\ngrestore\nend\nshowpage");
return printf("%%%%Trailer\n");
}

canonical_decompiled_code:
int func3()
{
puts("stroke\ngrestore\nend\nshowpage");
return printf("%%%%Trailer\n");
}

original_code:
void psplot_finish(void)
{
  printf("stroke\ngrestore\nend\nshowpage\n");
  printf("%%%%Trailer\n");
}

canonical_original_code:
void psplot_finish()
{
  printf("stroke\ngrestore\nend\nshowpage\n");
  printf("%%%%Trailer\n");
}


decompiled_code:
__int64 __fastcall pgmplot_point(int a1, int a2, char a3)
{
__int64 result; // rax

if ( a1 >= 0 && pgmplot_width > a1 && a2 >= 0 && pgmplot_height >= a2 )
{
result = *(_QWORD *)(pgmplot_data + 8LL * a1);
*(_BYTE *)(result + a2) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, char a3)
{
__int64 result; // rax

if ( a1 >= 0 && pgmplot_width > a1 && a2 >= 0 && pgmplot_height >= a2 )
{
result = *(_QWORD *)(pgmplot_data + 8LL * a1);
*(_BYTE *)(result + a2) = a3;
}
return result;
}

original_code:
void pgmplot_point(int i, int j, int val)
{
  if(i < 0 || i >= pgmplot_width || j < 0 || j > pgmplot_height)
    return;
  pgmplot_data[i][j] = val;
}


decompiled_code:
int pgmplot_finish()
{
__int64 i; // rbp
int result; // eax
__int64 j; // rbx

for ( i = 0LL; pgmplot_height > (int)i; ++i )
{
for ( j = 0LL; pgmplot_width > (int)j; ++j )
result = fputc(*(unsigned __int8 *)(*(_QWORD *)(pgmplot_data + 8 * j) + i), stdout);
}
return result;
}

canonical_decompiled_code:
int func1()
{
__int64 i; // rbp
int result; // eax
__int64 j; // rbx

for ( i = 0LL; pgmplot_height > (int)i; ++i )
{
for ( j = 0LL; pgmplot_width > (int)j; ++j )
result = fputc(*(unsigned __int8 *)(*(_QWORD *)(pgmplot_data + 8 * j) + i), stdout);
}
return result;
}

original_code:
void pgmplot_finish(void)
{
  int i, j;
  for(j = 0; j < pgmplot_height; j++)
    for(i = 0; i < pgmplot_width; i++)
      fputc(pgmplot_data[i][j], stdout);
}

canonical_original_code:
void pgmplot_finish()
{
  int i; int j;
  for(j = 0; j < pgmplot_height; j++)
    for(i = 0; i < pgmplot_width; i++)
      fputc(pgmplot_data[i][j], stdout);
}


norm

original_code:
void norm(double *x, double *y)
{
  double len;
  len = sqrt(((*x)*(*x)) + ((*y)*(*y)));
  if(len != 0.0) {
    *x /= len;
    *y /= len;
  }
}

variable_types:
x
double *

variable_types:
y
double *

variable_types: len double


decompiled_code:
__int64 __fastcall draw_boid(int a1, unsigned int a2)
{
double v2; // rbx
double v3; // rbp
double v4; // xmm0_8
double v6; // [rsp+0h] [rbp-48h]
double v7; // [rsp+0h] [rbp-48h]
double v8; // [rsp+8h] [rbp-40h]
double cosx; // [rsp+10h] [rbp-38h] BYREF
double sinx; // [rsp+18h] [rbp-30h] BYREF
double v11; // [rsp+20h] [rbp-28h] BYREF
double v12[4]; // [rsp+28h] [rbp-20h] BYREF

v12[0] = *(double *)(xv + 8LL * a1);
v11 = *(double *)(yv + 8LL * a1);
norm(v12, &v11);
v2 = *(double *)(xp + 8LL * a1);
v3 = *(double *)(yp + 8LL * a1);
v8 = v3 - (double)len * v11;
v6 = v2 - (double)len * v12[0];
plot_line(a2, v2, v3, v6, v8);
v4 = (v2 - v6) / (double)len;
if ( v4 < -1.0 )
{
v4 = LC5;
}
else if ( v4 > 1.0 )
{
v4 = *(double *)&LC2;
}
v7 = acos(v4);
if ( v3 - v8 < 0.0 )
*(_QWORD *)&v7 ^= LC4;
sincos(0.5 * *(double *)&angle + v7, &sinx, &cosx);
v12[0] = (double)len * cosx / 3.0 + v2;
v11 = (double)len * sinx / 3.0 + v3;
plot_line(a2, v2, v3, v12[0], v11);
sincos(v7 - 0.5 * *(double *)&angle, &sinx, &cosx);
v12[0] = (double)len * cosx / 3.0 + v2;
v11 = (double)len * sinx / 3.0 + v3;
return plot_line(a2, v2, v3, v12[0], v11);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, unsigned int a2)
{
double v2; // rbx
double v3; // rbp
double v4; // xmm0_8
double v6; // [rsp+0h] [rbp-48h]
double v7; // [rsp+0h] [rbp-48h]
double v8; // [rsp+8h] [rbp-40h]
double cosx; // [rsp+10h] [rbp-38h] BYREF
double sinx; // [rsp+18h] [rbp-30h] BYREF
double v11; // [rsp+20h] [rbp-28h] BYREF
double v12[4]; // [rsp+28h] [rbp-20h] BYREF

v12[0] = *(double *)(xv + 8LL * a1);
v11 = *(double *)(yv + 8LL * a1);
func0(v12, &v11);
v2 = *(double *)(xp + 8LL * a1);
v3 = *(double *)(yp + 8LL * a1);
v8 = v3 - (double)len * v11;
v6 = v2 - (double)len * v12[0];
plot_line(a2, v2, v3, v6, v8);
v4 = (v2 - v6) / (double)len;
if ( v4 < -1.0 )
{
v4 = LC5;
}
else if ( v4 > 1.0 )
{
v4 = *(double *)&LC2;
}
v7 = acos(v4);
if ( v3 - v8 < 0.0 )
*(_QWORD *)&v7 ^= LC4;
sincos(0.5 * *(double *)&angle + v7, &sinx, &cosx);
v12[0] = (double)len * cosx / 3.0 + v2;
v11 = (double)len * sinx / 3.0 + v3;
plot_line(a2, v2, v3, v12[0], v11);
sincos(v7 - 0.5 * *(double *)&angle, &sinx, &cosx);
v12[0] = (double)len * cosx / 3.0 + v2;
v11 = (double)len * sinx / 3.0 + v3;
return plot_line(a2, v2, v3, v12[0], v11);
}

original_code:
void draw_boid(int which, int color)
{
  double x1, x2, x3, y1, y2, y3, a, t;
  x3 = xv[which]; y3 = yv[which];
  norm(&x3, &y3);
  x1 = xp[which]; y1 = yp[which];
  x2 = x1 - x3 * len;
  y2 = y1 - y3 * len;
  plot_line(x1, y1, x2, y2, color);
  t = (x1 - x2) / len;
  t = (t < -1) ? -1 : (t > 1) ? 1 : t;
  a = acos(t);
  a = (y1 - y2) < 0 ? -a : a;
  x3 = x1 + cos(a + angle / 2) * len / 3.0;
  y3 = y1 + sin(a + angle / 2) * len / 3.0;
  plot_line(x1, y1, x3, y3, color);
  x3 = x1 + cos(a - angle / 2) * len / 3.0;
  y3 = y1 + sin(a - angle / 2) * len / 3.0;
  plot_line(x1, y1, x3, y3, color);
}

canonical_original_code:
void draw_boid(int which, int color)
{
  double x1; double x2; double x3; double y1; double y2; double y3; double a; double t;
  x3 = xv[which]; y3 = yv[which];
  norm(&x3, &y3);
  x1 = xp[which]; y1 = yp[which];
  x2 = x1 - x3 * len;
  y2 = y1 - y3 * len;
  plot_line(x1, y1, x2, y2, color);
  t = (x1 - x2) / len;
  t = (t < -1) ? -1 : (t > 1) ? 1 : t;
  a = acos(t);
  a = (y1 - y2) < 0 ? -a : a;
  x3 = x1 + cos(a + angle / 2) * len / 3.0;
  y3 = y1 + sin(a + angle / 2) * len / 3.0;
  plot_line(x1, y1, x3, y3, color);
  x3 = x1 + cos(a - angle / 2) * len / 3.0;
  y3 = y1 + sin(a - angle / 2) * len / 3.0;
  plot_line(x1, y1, x3, y3, color);
}

variable_types: which int

variable_types: color int

variable_types: a double

variable_types: t double


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
double *v4; // r12
double *v5; // r12
int i; // er12
int v7; // ebx
double *v8; // rax
double v9; // xmm0_8
__int64 v10; // rbx
double *v11; // rdx
double v12; // xmm0_8
int v13; // ebx

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);
}
srandom(seed);
*(double *)&angle = 3.141592653589793 * *(double *)&angle / 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 )
{
v3 = 0LL;
do
{
*(double *)(xp + 8 * v3) = (double)(int)(random() % width);
*(double *)(yp + 8 * v3) = (double)(int)(random() % height);
v4 = (double *)(xv + 8 * v3);
*v4 = random_range(-1.0, 1.0);
v5 = (double *)(yv + 8 * v3);
*v5 = random_range(-1.0, 1.0);
norm((double *)(xv + 8 * v3), (double *)(yv + 8 * v3));
++v3;
}
while ( num > (int)v3 );
}
for ( i = 0; steps > i; ++i )
{
v13 = 0;
if ( num > 0 )
{
do
compute_new_heading(v13++);
while ( num > v13 );
if ( num > 0 )
{
v10 = 0LL;
do
{
if ( !psdump )
draw_boid(v10, 0);
*(_QWORD *)(xv + 8 * v10) = *(_QWORD *)(xnv + 8 * v10);
*(_QWORD *)(yv + 8 * v10) = *(_QWORD *)(ynv + 8 * v10);
*(double *)(xp + 8 * v10) = *(double *)(xv + 8 * v10) * *(double *)&dt + *(double *)(xp + 8 * v10);
*(double *)(yp + 8 * v10) = *(double *)(yv + 8 * v10) * *(double *)&dt + *(double *)(yp + 8 * v10);
v11 = (double *)(xp + 8 * v10);
v12 = *v11;
if ( *v11 < 0.0 )
{
*v11 = v12 + (double)width;
}
else if ( v12 >= (double)width )
{
*v11 = v12 - (double)width;
}
v8 = (double *)(yp + 8 * v10);
v9 = *v8;
if ( *v8 < 0.0 )
{
*v8 = v9 + (double)height;
}
else if ( v9 >= (double)(height - 1) )
{
*v8 = v9 - (double)height;
}
if ( !psdump )
draw_boid(v10, 1u);
++v10;
}
while ( num > (int)v10 );
}
}
}
if ( psdump || (plot_finish(), psdump) )
{
plot_inverse = 0;
plot_init((unsigned int)width, (unsigned int)height, 2LL, &unk_1814);
if ( num > 0 )
{
v7 = 0;
do
draw_boid(v7++, 0);
while ( num > v7 );
}
plot_finish();
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
double *v4; // r12
double *v5; // r12
int i; // er12
int v7; // ebx
double *v8; // rax
double v9; // xmm0_8
__int64 v10; // rbx
double *v11; // rdx
double v12; // xmm0_8
int v13; // ebx

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);
}
srandom(seed);
*(double *)&angle = 3.141592653589793 * *(double *)&angle / 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 )
{
v3 = 0LL;
do
{
*(double *)(xp + 8 * v3) = (double)(int)(random() % width);
*(double *)(yp + 8 * v3) = (double)(int)(random() % height);
v4 = (double *)(xv + 8 * v3);
*v4 = random_range(-1.0, 1.0);
v5 = (double *)(yv + 8 * v3);
*v5 = random_range(-1.0, 1.0);
func0((double *)(xv + 8 * v3), (double *)(yv + 8 * v3));
++v3;
}
while ( num > (int)v3 );
}
for ( i = 0; steps > i; ++i )
{
v13 = 0;
if ( num > 0 )
{
do
func1(v13++);
while ( num > v13 );
if ( num > 0 )
{
v10 = 0LL;
do
{
if ( !psdump )
func2(v10, 0);
*(_QWORD *)(xv + 8 * v10) = *(_QWORD *)(xnv + 8 * v10);
*(_QWORD *)(yv + 8 * v10) = *(_QWORD *)(ynv + 8 * v10);
*(double *)(xp + 8 * v10) = *(double *)(xv + 8 * v10) * *(double *)&dt + *(double *)(xp + 8 * v10);
*(double *)(yp + 8 * v10) = *(double *)(yv + 8 * v10) * *(double *)&dt + *(double *)(yp + 8 * v10);
v11 = (double *)(xp + 8 * v10);
v12 = *v11;
if ( *v11 < 0.0 )
{
*v11 = v12 + (double)width;
}
else if ( v12 >= (double)width )
{
*v11 = v12 - (double)width;
}
v8 = (double *)(yp + 8 * v10);
v9 = *v8;
if ( *v8 < 0.0 )
{
*v8 = v9 + (double)height;
}
else if ( v9 >= (double)(height - 1) )
{
*v8 = v9 - (double)height;
}
if ( !psdump )
func2(v10, 1u);
++v10;
}
while ( num > (int)v10 );
}
}
}
if ( psdump || (plot_finish(), psdump) )
{
plot_inverse = 0;
plot_init((unsigned int)width, (unsigned int)height, 2LL, &unk_1814);
if ( num > 0 )
{
v7 = 0;
do
func2(v7++, 0);
while ( num > v7 );
}
plot_finish();
}
exit(0);
}

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: i int

variable_types: j int


decompiled_code:
__int64 init_weights()
{
int v0; // eax
__int64 v1; // rbp
_QWORD *v2; // r12
_QWORD *v3; // r12
__int64 v4; // rax
__int64 result; // rax
_QWORD *v6; // rbx
__int64 v7; // r15
_QWORD *v8; // rbx
__int64 v9; // r13
_QWORD *v10; // r14
__int64 v11; // rax
__int64 v12; // [rsp+8h] [rbp-40h]

x = xmalloc(8LL * height);
b = xmalloc(8LL * height);
v0 = height;
if ( height > 0 )
{
v1 = 0LL;
do
{
v2 = (_QWORD *)(x + 8 * v1);
*v2 = xmalloc(8LL * width);
v3 = (_QWORD *)(b + 8 * v1);
*v3 = xmalloc(8LL * width);
if ( width > 0 )
{
v4 = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)(b + 8 * v1) + 8 * v4) = 0LL;
*(_QWORD *)(*(_QWORD *)(x + 8 * v1) + 8 * v4++) = 0LL;
}
while ( width > (int)v4 );
}
v0 = height;
++v1;
}
while ( height > (int)v1 );
}
result = xmalloc(8LL * v0);
weight = result;
if ( height > 0 )
{
v12 = 0LL;
do
{
v6 = (_QWORD *)(weight + 8 * v12);
*v6 = xmalloc(8LL * width);
if ( width > 0 )
{
v7 = 0LL;
do
{
v8 = (_QWORD *)(*(_QWORD *)(weight + 8 * v12) + 8 * v7);
*v8 = xmalloc(8LL * height);
if ( height > 0 )
{
v9 = 0LL;
do
{
v10 = (_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v12) + 8 * v7) + 8 * v9);
*v10 = xmalloc(8LL * width);
if ( width > 0 )
{
v11 = 0LL;
do
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v12) + 8 * v7) + 8 * v9) + 8 * v11++) = 0LL;
while ( width > (int)v11 );
}
++v9;
}
while ( height > (int)v9 );
}
++v7;
}
while ( width > (int)v7 );
}
result = ++v12;
}
while ( height > (int)v12 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 v1; // rbp
_QWORD *v2; // r12
_QWORD *v3; // r12
__int64 v4; // rax
__int64 result; // rax
_QWORD *v6; // rbx
__int64 v7; // r15
_QWORD *v8; // rbx
__int64 v9; // r13
_QWORD *v10; // r14
__int64 v11; // rax
__int64 v12; // [rsp+8h] [rbp-40h]

x = xmalloc(8LL * height);
b = xmalloc(8LL * height);
v0 = height;
if ( height > 0 )
{
v1 = 0LL;
do
{
v2 = (_QWORD *)(x + 8 * v1);
*v2 = xmalloc(8LL * width);
v3 = (_QWORD *)(b + 8 * v1);
*v3 = xmalloc(8LL * width);
if ( width > 0 )
{
v4 = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)(b + 8 * v1) + 8 * v4) = 0LL;
*(_QWORD *)(*(_QWORD *)(x + 8 * v1) + 8 * v4++) = 0LL;
}
while ( width > (int)v4 );
}
v0 = height;
++v1;
}
while ( height > (int)v1 );
}
result = xmalloc(8LL * v0);
weight = result;
if ( height > 0 )
{
v12 = 0LL;
do
{
v6 = (_QWORD *)(weight + 8 * v12);
*v6 = xmalloc(8LL * width);
if ( width > 0 )
{
v7 = 0LL;
do
{
v8 = (_QWORD *)(*(_QWORD *)(weight + 8 * v12) + 8 * v7);
*v8 = xmalloc(8LL * height);
if ( height > 0 )
{
v9 = 0LL;
do
{
v10 = (_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v12) + 8 * v7) + 8 * v9);
*v10 = xmalloc(8LL * width);
if ( width > 0 )
{
v11 = 0LL;
do
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v12) + 8 * v7) + 8 * v9) + 8 * v11++) = 0LL;
while ( width > (int)v11 );
}
++v9;
}
while ( height > (int)v9 );
}
++v7;
}
while ( width > (int)v7 );
}
result = ++v12;
}
while ( height > (int)v12 );
}
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;
      }
    }
  }
}


myparse

decompiled_code:
__int64 __fastcall myparse(__int64 a1, int a2, __int64 a3, int *a4)
{
_QWORD *v5; // rbx
_QWORD *v6; // r9
__int64 v7; // r13
__int64 v8; // rdx
double *v9; // rdx
__int64 i; // rax
__int64 v11; // r11
_QWORD *v12; // rcx
__int64 v13; // r12
__int64 v14; // r12
unsigned int v16; // [rsp+0h] [rbp-40h] BYREF
unsigned int v17[15]; // [rsp+4h] [rbp-3Ch] BYREF

if ( *a4 == a2 )
return 1LL;
v5 = (_QWORD *)read_pbm_file(*(_QWORD *)(a1 + 8LL * *a4 + 8), v17, &v16);
if ( file_count )
{
v8 = v17[0];
if ( v17[0] == width )
{
if ( v16 == height )
goto LABEL_4;
v8 = (unsigned int)width;
}
fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n", v8, v16, *(const char **)(a1 + 8LL * *a4 + 8));
exit(1);
}
width = v17[0];
height = v16;
LABEL_4:
if ( !weight )
init_weights();
if ( height > 0 )
{
v6 = v5;
v7 = 0LL;
do
{
if ( width > 0 )
{
v13 = 0LL;
do
{
if ( height > 0 )
{
v12 = v5;
v11 = 0LL;
do
{
for ( i = 0LL; width > (int)i; ++i )
{
v9 = (double *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v7) + 8 * v13) + 8 * v11) + 8 * i);
*v9 = (double)((2 * *(_DWORD *)(*v6 + 4 * v13) - 1) * (2 * *(_DWORD *)(*v12 + 4 * i) - 1)) + *v9;
}
++v11;
++v12;
}
while ( height > (int)v11 );
}
++v13;
}
while ( width > (int)v13 );
}
++v7;
++v6;
}
while ( height > (int)v7 );
if ( height > 0 )
{
v14 = 0LL;
do
free((void *)v5[v14++]);
while ( height > (int)v14 );
}
}
free(v5);
*a4 += 2;
++file_count;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3, int *a4)
{
_QWORD *v5; // rbx
_QWORD *v6; // r9
__int64 v7; // r13
__int64 v8; // rdx
double *v9; // rdx
__int64 i; // rax
__int64 v11; // r11
_QWORD *v12; // rcx
__int64 v13; // r12
__int64 v14; // r12
unsigned int v16; // [rsp+0h] [rbp-40h] BYREF
unsigned int v17[15]; // [rsp+4h] [rbp-3Ch] BYREF

if ( *a4 == a2 )
return 1LL;
v5 = (_QWORD *)read_pbm_file(*(_QWORD *)(a1 + 8LL * *a4 + 8), v17, &v16);
if ( file_count )
{
v8 = v17[0];
if ( v17[0] == width )
{
if ( v16 == height )
goto LABEL_4;
v8 = (unsigned int)width;
}
fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n", v8, v16, *(const char **)(a1 + 8LL * *a4 + 8));
exit(1);
}
width = v17[0];
height = v16;
LABEL_4:
if ( !weight )
func0();
if ( height > 0 )
{
v6 = v5;
v7 = 0LL;
do
{
if ( width > 0 )
{
v13 = 0LL;
do
{
if ( height > 0 )
{
v12 = v5;
v11 = 0LL;
do
{
for ( i = 0LL; width > (int)i; ++i )
{
v9 = (double *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v7) + 8 * v13) + 8 * v11) + 8 * i);
*v9 = (double)((2 * *(_DWORD *)(*v6 + 4 * v13) - 1) * (2 * *(_DWORD *)(*v12 + 4 * i) - 1)) + *v9;
}
++v11;
++v12;
}
while ( height > (int)v11 );
}
++v13;
}
while ( width > (int)v13 );
}
++v7;
++v6;
}
while ( height > (int)v7 );
if ( height > 0 )
{
v14 = 0LL;
do
free((void *)v5[v14++]);
while ( height > (int)v14 );
}
}
free(v5);
*a4 += 2;
++file_count;
return 0LL;
}

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 **

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


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r11
double v4; // xmm1_8
unsigned int v5; // er13
__int64 v6; // rbp
int m; // er12
int v8; // ebx
__int64 v9; // rbx
__int64 i; // rbp
double *v11; // rcx
double v12; // xmm0_8
int v13; // eax
__int64 j; // rdx
__int64 v15; // r9
__int64 v16; // r10
_QWORD *v17; // rdi
__int64 l; // rbx
double *v19; // rax
double *v20; // rdx
double v21; // xmm0_8
__int64 v22; // rcx
int v23; // edi
__int64 n; // rbx
double *v25; // r15
__int64 jj; // rax
__int64 ii; // r10
__int64 v28; // rbp
__int64 v29; // rdx
double v30; // [rsp+0h] [rbp-68h]
int v31; // [rsp+0h] [rbp-68h]
__int64 v32; // [rsp+8h] [rbp-60h]
__int64 v33; // [rsp+10h] [rbp-58h]
__int64 k; // [rsp+18h] [rbp-50h]
unsigned int v35; // [rsp+28h] [rbp-40h] BYREF
unsigned int v36[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, v36, &v35);
if ( v36[0] != width || v35 != height )
{
fprintf(stderr, "Bad width (%d) or height (%d) in PPM file (%s).\n", v36[0], v35, tfile);
exit(1);
}
if ( *(double *)&noise > 0.0 && *(double *)&noise < 1.0 )
{
for ( i = 0LL; height > (int)i; ++i )
{
if ( width > 0 )
{
v9 = 0LL;
do
{
if ( *(double *)&noise > random_range(0.0, 1.0) )
*(_DWORD *)(*(_QWORD *)(y + 8 * i) + 4 * v9) = random() % 2;
++v9;
}
while ( width > (int)v9 );
}
}
}
if ( height <= 0 )
{
v30 = *(double *)&LC2;
v4 = 0.0;
}
else
{
v3 = 0LL;
v30 = *(double *)&LC2;
v4 = 0.0;
do
{
if ( width > 0 )
{
v16 = 0LL;
do
{
if ( height > 0 )
{
v15 = 0LL;
do
{
v13 = width;
for ( j = 0LL; width > (int)j; ++j )
{
v11 = (double *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v3) + 8 * v16) + 8 * v15) + 8 * j);
*v11 = *v11 / (double)(height * v13);
*(_QWORD *)&v12 = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * v3) + 8 * v16) + 8 * v15)
+ 8 * j) & LC5;
v4 = fmax(v12, v4);
v30 = fmin(v12, v30);
v13 = width;
}
++v15;
}
while ( height > (int)v15 );
}
++v16;
}
while ( width > (int)v16 );
}
++v3;
}
while ( height > (int)v3 );
}
fprintf(stderr, "|largest weight| = %f\n", v4);
fprintf(stderr, "|smallest weight| = %f\n", v30);
v5 = width * height * width * height;
for ( k = 0LL; height > (int)k; ++k )
{
if ( width > 0 )
{
v33 = 0LL;
do
{
if ( height > 0 )
{
v31 = k;
v32 = 0LL;
do
{
for ( l = 0LL; width > (int)l; ++l )
{
if ( local
&& (COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)v31) & LC5) > (double)local
|| COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)((int)v33 - (int)l)) & LC5) > (double)local) )
{
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * k) + 8 * v33) + 8 * v32) + 8 * l) = 0LL;
--v5;
}
else
{
v17 = (_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * k) + 8 * v33) + 8 * v32) + 8 * l);
if ( *(double *)&cutoff > COERCE_DOUBLE(*v17 & LC5) )
{
*v17 = 0LL;
--v5;
}
else if ( *(double *)&pprob > 0.0 && *(double *)&pprob > random_range(0.0, 1.0) )
{
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8 * k) + 8 * v33) + 8 * v32) + 8 * l) = 0LL;
--v5;
}
}
}
++v32;
--v31;
}
while ( height > (int)v32 );
}
++v33;
}
while ( width > (int)v33 );
}
}
fprintf(stderr, "total used weights = %d\n", v5);
v6 = 0LL;
for ( m = 0; height > m; v6 += 8LL )
{
v23 = width;
for ( n = 0LL; width > (int)n; ++n )
{
if ( height <= 0 )
{
v21 = 0.0;
}
else
{
v22 = 0LL;
v21 = 0.0;
do
{
if ( v23 > 0 )
{
v19 = *(double **)(*(_QWORD *)(*(_QWORD *)(weight + v6) + 8 * n) + v22);
v20 = &v19[(unsigned int)(v23 - 1) + 1];
do
v21 = v21 + *v19++;
while ( v20 != v19 );
}
v22 += 8LL;
}
while ( v22 != 8LL * (unsigned int)height );
}
*(double *)(*(_QWORD *)(b + v6) + 8 * n) = v21 * -0.5;
*(_DWORD *)(*(_QWORD *)(y + v6) + 4 * n) = 2 * *(_DWORD *)(*(_QWORD *)(y + v6) + 4 * n) - 1;
plot_point(*(unsigned int *)(*(_QWORD *)(y + v6) + 4 * n), (double)(int)n, (double)m);
v23 = width;
}
++m;
}
if ( steps > 0 )
{
v8 = 0;
do
{
v28 = random() % width;
v29 = random() % height;
*(_QWORD *)(*(_QWORD *)(x + 8LL * (int)v28) + 8LL * (int)v29) = 0LL;
for ( ii = 0LL; height > (int)ii; ++ii )
{
for ( jj = 0LL; width > (int)jj; ++jj )
{
v25 = (double *)(*(_QWORD *)(x + 8LL * (int)v28) + 8LL * (int)v29);
*v25 = (double)*(int *)(*(_QWORD *)(y + 8 * ii) + 4 * jj)
* *(double *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(weight + 8LL * (int)v28) + 8LL * (int)v29) + 8 * ii)
+ 8 * jj)
+ *v25;
}
}
*(_DWORD *)(*(_QWORD *)(y + 8LL * (int)v28) + 4LL * (int)v29) = 2
* (*(double *)(*(_QWORD *)(x + 8LL * (int)v28)
+ 8LL * (int)v29)
- *(double *)(*(_QWORD *)(b + 8LL * (int)v28)
+ 8LL * (int)v29) > 0.0)
- 1;
plot_point(
(unsigned int)((*(_DWORD *)(*(_QWORD *)(y + 8LL * (int)v28) + 4LL * (int)v29) + 1) / 2),
(double)(int)v29,
(double)(int)v28);
++v8;
}
while ( steps > v8 );
}
plot_finish();
exit(0);
}

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: k int

variable_types: l int

variable_types: t int

variable_types: n int

variable_types: sum double

variable_types: big double

variable_types: small double


nearanother

decompiled_code:
__int64 __fastcall nearanother(int a1, int a2, __int64 a3)
{
int v5; // edi
int v6; // er8
int i; // ecx
int v8; // esi
int v9; // edx
int v10; // eax

v5 = a1 - 1;
v6 = -1;
while ( 2 )
{
v8 = a2 - 1;
for ( i = 0; ; ++i )
{
if ( v6 | (i - 1) )
{
v9 = v5;
v10 = v8;
if ( v5 < 0 )
{
v9 = width - 1;
}
else if ( width <= v5 )
{
v9 = 0;
}
if ( v8 < 0 )
{
v10 = height - 1;
}
else if ( height <= v8 )
{
v10 = 0;
}
if ( *(_BYTE *)(*(_QWORD *)(a3 + 8LL * v9) + v10) )
return 1LL;
if ( i > 1 )
break;
}
++v8;
}
++v6;
++v5;
if ( v6 != 2 )
continue;
break;
}
return 0LL;
}

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