decompiled_code:
__int64 __fastcall plot_box(int a1, double a2, double a3, double a4, double a5)
{
unsigned int v5; // er15
unsigned int v6; // er14
unsigned int v7; // er13
int v8; // eax
__int64 v9; // r8
__int64 v10; // r8
__int64 v11; // r8
__int64 v12; // r8
int v13; // ebx
__int64 v14; // r8
unsigned int v15; // er14
unsigned int v16; // er15
unsigned int v17; // ebp
__int64 v18; // r8
unsigned int v19; // er12
__int64 v20; // r8
__int64 v21; // r8
__int64 v22; // r8
unsigned int v23; // er13
unsigned int v24; // er12
__int64 v25; // r8
__int64 v26; // r8
__int64 v27; // r8
int v29; // [rsp+0h] [rbp-48h]
unsigned int v30; // [rsp+0h] [rbp-48h]
int v31; // [rsp+4h] [rbp-44h]
unsigned int v32; // [rsp+4h] [rbp-44h]
unsigned int v33; // [rsp+8h] [rbp-40h]

v5 = plot_width;
if ( *(double *)&plot_xmax == *(double *)&plot_xmin )
v29 = (int)*(double *)&plot_xmin;
else
v29 = (int)((a2 - *(double *)&plot_xmin) / (*(double *)&plot_xmax - *(double *)&plot_xmin) * (double)plot_width);
v6 = plot_height;
v30 = v29 - (v29 == plot_width);
if ( *(double *)&plot_ymax == *(double *)&plot_ymin )
v31 = (int)*(double *)&plot_ymin;
else
v31 = (int)(((*(double *)&plot_ymin - a3) / (*(double *)&plot_ymax - *(double *)&plot_ymin) + 1.0)
* (double)plot_height);
v32 = v31 - (v31 == plot_height);
if ( *(double *)&plot_xmax == *(double *)&plot_xmin )
{
v7 = (int)*(double *)&plot_xmin;
if ( (int)*(double *)&plot_xmin != plot_width )
{
LABEL_7:
v5 = v7 + 1;
goto LABEL_8;
}
}
else
{
v7 = (int)((a4 - *(double *)&plot_xmin) / (*(double *)&plot_xmax - *(double *)&plot_xmin) * (double)plot_width);
if ( v7 != plot_width )
goto LABEL_7;
}
--v7;
LABEL_8:
if ( *(double *)&plot_ymax == *(double *)&plot_ymin )
{
v33 = (int)*(double *)&plot_ymin;
v8 = (int)*(double *)&plot_ymin;
if ( (int)*(double *)&plot_ymin != plot_height )
{
LABEL_10:
v6 = v8 + 1;
goto LABEL_11;
}
}
else
{
v33 = (int)(((*(double *)&plot_ymin - a5) / (*(double *)&plot_ymax - *(double *)&plot_ymin) + 1.0)
* (double)plot_height);
v8 = v33;
if ( v33 != plot_height )
goto LABEL_10;
}
--v33;
LABEL_11:
v9 = 0LL;
if ( !plot_inverse )
v9 = (unsigned int)(plot_levels - 1);
plot_line(v30, v32, v7, v32, v9);
v10 = 0LL;
if ( !plot_inverse )
v10 = (unsigned int)(plot_levels - 1);
plot_line(v7, v32, v7, v33, v10);
v11 = 0LL;
if ( !plot_inverse )
v11 = (unsigned int)(plot_levels - 1);
plot_line(v7, v33, v30, v33, v11);
v12 = 0LL;
if ( !plot_inverse )
v12 = (unsigned int)(plot_levels - 1);
v13 = 1;
plot_line(v30, v33, v30, v32, v12);
if ( a1 > 0 )
{
do
{
v14 = (unsigned int)plot_inverse;
if ( plot_inverse )
v14 = (unsigned int)(plot_levels - 1);
v15 = v7 + v13;
v16 = v32 - v13;
v17 = v30 - v13;
plot_line(v30 - v13, v32 - v13, v7 + v13, v32 - v13, v14);
v18 = (unsigned int)plot_inverse;
if ( plot_inverse )
v18 = (unsigned int)(plot_levels - 1);
v19 = v33 + v13;
plot_line(v15, v16, v15, v33 + v13, v18);
v20 = (unsigned int)plot_inverse;
if ( plot_inverse )
v20 = (unsigned int)(plot_levels - 1);
plot_line(v15, v19, v17, v19, v20);
v21 = (unsigned int)plot_inverse;
if ( plot_inverse )
v21 = (unsigned int)(plot_levels - 1);
plot_line(v17, v19, v17, v16, v21);
++v13;
}
while ( a1 >= v13 );
v5 = v7 + v13;
v6 = v13 + v33;
}
v22 = 0LL;
if ( !plot_inverse )
v22 = (unsigned int)(plot_levels - 1);
v23 = v32 - v13;
v24 = v30 - v13;
plot_line(v30 - v13, v32 - v13, v5, v32 - v13, v22);
v25 = 0LL;
if ( !plot_inverse )
v25 = (unsigned int)(plot_levels - 1);
plot_line(v5, v23, v5, v6, v25);
v26 = 0LL;
if ( !plot_inverse )
v26 = (unsigned int)(plot_levels - 1);
plot_line(v5, v6, v24, v6, v26);
v27 = 0LL;
if ( !plot_inverse )
v27 = (unsigned int)(plot_levels - 1);
return plot_line(v24, v6, v24, v23, v27);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, double a2, double a3, double a4, double a5)
{
unsigned int v5; // er15
unsigned int v6; // er14
unsigned int v7; // er13
int v8; // eax
__int64 v9; // r8
__int64 v10; // r8
__int64 v11; // r8
__int64 v12; // r8
int v13; // ebx
__int64 v14; // r8
unsigned int v15; // er14
unsigned int v16; // er15
unsigned int v17; // ebp
__int64 v18; // r8
unsigned int v19; // er12
__int64 v20; // r8
__int64 v21; // r8
__int64 v22; // r8
unsigned int v23; // er13
unsigned int v24; // er12
__int64 v25; // r8
__int64 v26; // r8
__int64 v27; // r8
int v29; // [rsp+0h] [rbp-48h]
unsigned int v30; // [rsp+0h] [rbp-48h]
int v31; // [rsp+4h] [rbp-44h]
unsigned int v32; // [rsp+4h] [rbp-44h]
unsigned int v33; // [rsp+8h] [rbp-40h]

v5 = plot_width;
if ( *(double *)&plot_xmax == *(double *)&plot_xmin )
v29 = (int)*(double *)&plot_xmin;
else
v29 = (int)((a2 - *(double *)&plot_xmin) / (*(double *)&plot_xmax - *(double *)&plot_xmin) * (double)plot_width);
v6 = plot_height;
v30 = v29 - (v29 == plot_width);
if ( *(double *)&plot_ymax == *(double *)&plot_ymin )
v31 = (int)*(double *)&plot_ymin;
else
v31 = (int)(((*(double *)&plot_ymin - a3) / (*(double *)&plot_ymax - *(double *)&plot_ymin) + 1.0)
* (double)plot_height);
v32 = v31 - (v31 == plot_height);
if ( *(double *)&plot_xmax == *(double *)&plot_xmin )
{
v7 = (int)*(double *)&plot_xmin;
if ( (int)*(double *)&plot_xmin != plot_width )
{
LABEL_7:
v5 = v7 + 1;
goto LABEL_8;
}
}
else
{
v7 = (int)((a4 - *(double *)&plot_xmin) / (*(double *)&plot_xmax - *(double *)&plot_xmin) * (double)plot_width);
if ( v7 != plot_width )
goto LABEL_7;
}
--v7;
LABEL_8:
if ( *(double *)&plot_ymax == *(double *)&plot_ymin )
{
v33 = (int)*(double *)&plot_ymin;
v8 = (int)*(double *)&plot_ymin;
if ( (int)*(double *)&plot_ymin != plot_height )
{
LABEL_10:
v6 = v8 + 1;
goto LABEL_11;
}
}
else
{
v33 = (int)(((*(double *)&plot_ymin - a5) / (*(double *)&plot_ymax - *(double *)&plot_ymin) + 1.0)
* (double)plot_height);
v8 = v33;
if ( v33 != plot_height )
goto LABEL_10;
}
--v33;
LABEL_11:
v9 = 0LL;
if ( !plot_inverse )
v9 = (unsigned int)(plot_levels - 1);
func10(v30, v32, v7, v32, v9);
v10 = 0LL;
if ( !plot_inverse )
v10 = (unsigned int)(plot_levels - 1);
func10(v7, v32, v7, v33, v10);
v11 = 0LL;
if ( !plot_inverse )
v11 = (unsigned int)(plot_levels - 1);
func10(v7, v33, v30, v33, v11);
v12 = 0LL;
if ( !plot_inverse )
v12 = (unsigned int)(plot_levels - 1);
v13 = 1;
func10(v30, v33, v30, v32, v12);
if ( a1 > 0 )
{
do
{
v14 = (unsigned int)plot_inverse;
if ( plot_inverse )
v14 = (unsigned int)(plot_levels - 1);
v15 = v7 + v13;
v16 = v32 - v13;
v17 = v30 - v13;
func10(v30 - v13, v32 - v13, v7 + v13, v32 - v13, v14);
v18 = (unsigned int)plot_inverse;
if ( plot_inverse )
v18 = (unsigned int)(plot_levels - 1);
v19 = v33 + v13;
func10(v15, v16, v15, v33 + v13, v18);
v20 = (unsigned int)plot_inverse;
if ( plot_inverse )
v20 = (unsigned int)(plot_levels - 1);
func10(v15, v19, v17, v19, v20);
v21 = (unsigned int)plot_inverse;
if ( plot_inverse )
v21 = (unsigned int)(plot_levels - 1);
func10(v17, v19, v17, v16, v21);
++v13;
}
while ( a1 >= v13 );
v5 = v7 + v13;
v6 = v13 + v33;
}
v22 = 0LL;
if ( !plot_inverse )
v22 = (unsigned int)(plot_levels - 1);
v23 = v32 - v13;
v24 = v30 - v13;
func10(v30 - v13, v32 - v13, v5, v32 - v13, v22);
v25 = 0LL;
if ( !plot_inverse )
v25 = (unsigned int)(plot_levels - 1);
func10(v5, v23, v5, v6, v25);
v26 = 0LL;
if ( !plot_inverse )
v26 = (unsigned int)(plot_levels - 1);
func10(v5, v6, v24, v6, v26);
v27 = 0LL;
if ( !plot_inverse )
v27 = (unsigned int)(plot_levels - 1);
return func10(v24, v6, v24, v23, v27);
}

original_code:
void plot_box(double ulx, double uly, double lrx, double lry, int lwidth)
{
  int i, ulxi, ulyi, lrxi, lryi;
  ulxi = ((int) (plot_xmax == plot_xmin) ? plot_xmin : ((((ulx) - plot_xmin) / (plot_xmax - plot_xmin)) * plot_width)); ulxi = (((ulxi) == plot_width) ? ((ulxi) - 1) : (ulxi));
  ulyi = ((int) (plot_ymax == plot_ymin) ? plot_ymin : (((plot_ymin - (uly)) / (plot_ymax - plot_ymin) + 1.0) * plot_height)); ulyi = (((ulyi) == plot_height) ? ((ulyi) - 1) : (ulyi));
  lrxi = ((int) (plot_xmax == plot_xmin) ? plot_xmin : ((((lrx) - plot_xmin) / (plot_xmax - plot_xmin)) * plot_width)); lrxi = (((lrxi) == plot_width) ? ((lrxi) - 1) : (lrxi));
  lryi = ((int) (plot_ymax == plot_ymin) ? plot_ymin : (((plot_ymin - (lry)) / (plot_ymax - plot_ymin) + 1.0) * plot_height)); lryi = (((lryi) == plot_height) ? ((lryi) - 1) : (lryi));
  _plot_line(ulxi, ulyi, lrxi, ulyi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi, ulyi, lrxi, lryi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi, lryi, ulxi, lryi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(ulxi, lryi, ulxi, ulyi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  for(i = 1; i < lwidth + 1; i++) {
    _plot_line(ulxi - i, ulyi - i, lrxi + i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
    _plot_line(lrxi + i, ulyi - i, lrxi + i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
    _plot_line(lrxi + i, lryi + i, ulxi - i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
    _plot_line(ulxi - i, lryi + i, ulxi - i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
  }
  _plot_line(ulxi - i, ulyi - i, lrxi + i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi + i, ulyi - i, lrxi + i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi + i, lryi + i, ulxi - i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(ulxi - i, lryi + i, ulxi - i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
}

canonical_original_code:
void plot_box(double ulx, double uly, double lrx, double lry, int lwidth)
{
  int i; int ulxi; int ulyi; int lrxi; int lryi;
  ulxi = ((int) (plot_xmax == plot_xmin) ? plot_xmin : ((((ulx) - plot_xmin) / (plot_xmax - plot_xmin)) * plot_width)); ulxi = (((ulxi) == plot_width) ? ((ulxi) - 1) : (ulxi));
  ulyi = ((int) (plot_ymax == plot_ymin) ? plot_ymin : (((plot_ymin - (uly)) / (plot_ymax - plot_ymin) + 1.0) * plot_height)); ulyi = (((ulyi) == plot_height) ? ((ulyi) - 1) : (ulyi));
  lrxi = ((int) (plot_xmax == plot_xmin) ? plot_xmin : ((((lrx) - plot_xmin) / (plot_xmax - plot_xmin)) * plot_width)); lrxi = (((lrxi) == plot_width) ? ((lrxi) - 1) : (lrxi));
  lryi = ((int) (plot_ymax == plot_ymin) ? plot_ymin : (((plot_ymin - (lry)) / (plot_ymax - plot_ymin) + 1.0) * plot_height)); lryi = (((lryi) == plot_height) ? ((lryi) - 1) : (lryi));
  _plot_line(ulxi, ulyi, lrxi, ulyi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi, ulyi, lrxi, lryi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi, lryi, ulxi, lryi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(ulxi, lryi, ulxi, ulyi, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  for(i = 1; i < lwidth + 1; i++) {
    _plot_line(ulxi - i, ulyi - i, lrxi + i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
    _plot_line(lrxi + i, ulyi - i, lrxi + i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
    _plot_line(lrxi + i, lryi + i, ulxi - i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
    _plot_line(ulxi - i, lryi + i, ulxi - i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (0)) : (0)));
  }
  _plot_line(ulxi - i, ulyi - i, lrxi + i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi + i, ulyi - i, lrxi + i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(lrxi + i, lryi + i, ulxi - i, lryi + i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
  _plot_line(ulxi - i, lryi + i, ulxi - i, ulyi - i, (plot_inverse ? ((plot_levels - 1) - (plot_levels - 1)) : (plot_levels - 1)));
}

variable_types: ulx double

variable_types: uly double

variable_types: lrx double

variable_types: lry double

variable_types: lwidth int

variable_types: i int

variable_types: ulxi int

variable_types: ulyi int

variable_types: lrxi int

variable_types: lryi int


flog

repo: ramalho/CBofN

decompiled_code:
double __fastcall flog(double a1, double a2)
{
return a2 * 4.0 * a1 * (1.0 - a1);
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2)
{
return a2 * 4.0 * a1 * (1.0 - a1);
}

original_code:
double flog(double x, double r)
{
  return(4.0 * r * x * (1.0 - x));
}

variable_types: x double

variable_types: r double

return_type: double


fgauss

decompiled_code:
double __fastcall fgauss(double a1, double a2)
{
return exp(COERCE_DOUBLE(aux ^ LC4) * (a1 - 0.5) * (a1 - 0.5)) * a2;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
return exp(COERCE_DOUBLE(aux ^ LC4) * (a1 - 0.5) * (a1 - 0.5)) * a2;
}

original_code:
double fgauss(double x, double r)
{
  return(r * exp(-aux * (x - 0.5) * (x - 0.5)));
}


decompiled_code:
__int64 __fastcall plot_arrow(double a1, double a2, double a3, double a4)
{
double v4; // xmm4_8
double v5; // xmm7_8
double v6; // xmm6_8
double v7; // xmm2_8
__int64 result; // rax
double v9; // xmm3_8
double v10; // xmm0_8
double v11; // [rsp+10h] [rbp-20h]
double v12; // [rsp+18h] [rbp-18h]

v4 = (a1 + a3) * 0.5;
v5 = (a2 + a4) * 0.5;
if ( a1 == a3 && COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a2 - a4) & LC5) > 0.01 )
{
if ( a4 > a2 )
{
v9 = v5 - 0.01;
}
else
{
if ( a2 <= a4 )
goto LABEL_5;
v9 = v5 + 0.01;
}
v12 = v4 - 0.01;
plot_line(1LL, v4, v5, v4 - 0.01);
v10 = (a1 + a3) * 0.5;
plot_line(1LL, v10, v5, v10 + 0.01);
return plot_line(1LL, v12, v9, v10 + 0.01);
}
LABEL_5:
if ( a2 == a4 && COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a3) & LC5) > 0.01 )
{
if ( a3 > a1 )
{
v6 = v5 - 0.01;
v7 = v4 - 0.01;
goto LABEL_10;
}
if ( a1 > a3 )
{
v6 = v5 - 0.01;
v7 = v4 + 0.01;
LABEL_10:
v11 = v4;
plot_line(1LL, v4, v5, v7);
plot_line(1LL, v11, v5, v7);
return plot_line(1LL, v7, v6, v7);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(double a1, double a2, double a3, double a4)
{
double v4; // xmm4_8
double v5; // xmm7_8
double v6; // xmm6_8
double v7; // xmm2_8
__int64 result; // rax
double v9; // xmm3_8
double v10; // xmm0_8
double v11; // [rsp+10h] [rbp-20h]
double v12; // [rsp+18h] [rbp-18h]

v4 = (a1 + a3) * 0.5;
v5 = (a2 + a4) * 0.5;
if ( a1 == a3 && COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a2 - a4) & LC5) > 0.01 )
{
if ( a4 > a2 )
{
v9 = v5 - 0.01;
}
else
{
if ( a2 <= a4 )
goto LABEL_5;
v9 = v5 + 0.01;
}
v12 = v4 - 0.01;
plot_line(1LL, v4, v5, v4 - 0.01);
v10 = (a1 + a3) * 0.5;
plot_line(1LL, v10, v5, v10 + 0.01);
return plot_line(1LL, v12, v9, v10 + 0.01);
}
LABEL_5:
if ( a2 == a4 && COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a3) & LC5) > 0.01 )
{
if ( a3 > a1 )
{
v6 = v5 - 0.01;
v7 = v4 - 0.01;
goto LABEL_10;
}
if ( a1 > a3 )
{
v6 = v5 - 0.01;
v7 = v4 + 0.01;
LABEL_10:
v11 = v4;
plot_line(1LL, v4, v5, v7);
plot_line(1LL, v11, v5, v7);
return plot_line(1LL, v7, v6, v7);
}
}
return result;
}

original_code:
void plot_arrow(double x1, double y1, double x2, double y2)
{
  double xm, ym, off;
  off = 0.01;
  xm = (x1 + x2) / 2.0; ym = (y1 + y2) / 2.0;
  if(x1 == x2 && fabs(y1 - y2) > off && y2 > y1) {
    plot_line(xm, ym, xm - off, ym - off, 1);
    plot_line(xm, ym, xm + off, ym - off, 1);
    plot_line(xm - off, ym - off, xm + off, ym - off, 1);
  }
  else if(x1 == x2 && fabs(y1 - y2) > off && y1 > y2) {
    plot_line(xm, ym, xm - off, ym + off, 1);
    plot_line(xm, ym, xm + off, ym + off, 1);
    plot_line(xm - off, ym + off, xm + off, ym + off, 1);
  }
  else if(y1 == y2 && fabs(x1 - x2) > off && x2 > x1) {
    plot_line(xm, ym, xm - off, ym - off, 1);
    plot_line(xm, ym, xm - off, ym + off, 1);
    plot_line(xm - off, ym - off, xm - off, ym + off, 1);
  }
  else if(y1 == y2 && fabs(x1 - x2) > off && x1 > x2) {
    plot_line(xm, ym, xm + off, ym - off, 1);
    plot_line(xm, ym, xm + off, ym + off, 1);
    plot_line(xm + off, ym - off, xm + off, ym + off, 1);
  }
}

canonical_original_code:
void plot_arrow(double x1, double y1, double x2, double y2)
{
  double xm; double ym; double off;
  off = 0.01;
  xm = (x1 + x2) / 2.0; ym = (y1 + y2) / 2.0;
  if(x1 == x2 && fabs(y1 - y2) > off && y2 > y1) {
    plot_line(xm, ym, xm - off, ym - off, 1);
    plot_line(xm, ym, xm + off, ym - off, 1);
    plot_line(xm - off, ym - off, xm + off, ym - off, 1);
  }
  else if(x1 == x2 && fabs(y1 - y2) > off && y1 > y2) {
    plot_line(xm, ym, xm - off, ym + off, 1);
    plot_line(xm, ym, xm + off, ym + off, 1);
    plot_line(xm - off, ym + off, xm + off, ym + off, 1);
  }
  else if(y1 == y2 && fabs(x1 - x2) > off && x2 > x1) {
    plot_line(xm, ym, xm - off, ym - off, 1);
    plot_line(xm, ym, xm - off, ym + off, 1);
    plot_line(xm - off, ym - off, xm - off, ym + off, 1);
  }
  else if(y1 == y2 && fabs(x1 - x2) > off && x1 > x2) {
    plot_line(xm, ym, xm + off, ym - off, 1);
    plot_line(xm, ym, xm + off, ym + off, 1);
    plot_line(xm + off, ym - off, xm + off, ym + off, 1);
  }
}

variable_types: xm double

variable_types: ym double

variable_types: off double

return_type: void


rparse

original_code:
int rparse(char **argv, int argc, OPTION *options, int *cargc, int opt)
{
  int i, len;
  char letter;
  if(argc == *cargc) return(1);
  len = strlen(argv[*cargc + 1]);
  for(i = 0; i < len; i++)
    if(argv[*cargc + 1][i] >= 'A' && argv[*cargc + 1][i] <= 'Z')
      argv[*cargc + 1][i] = argv[*cargc + 1][i] - 'A' + 'a';
  letter = argv[*cargc + 1][0];
  if(letter < 'a' || letter > 'z' || argv[*cargc + 1][1] != '=')
    return(1);
  rules[letter - 'a'] = &argv[*cargc + 1][2];
  *cargc += 2;
  return(0);
}

canonical_original_code:
int rparse(char **argv, int argc, struct OPTION *options, int *cargc, int opt)
{
  int i; int len;
  char letter;
  if(argc == *cargc) return(1);
  len = strlen(argv[*cargc + 1]);
  for(i = 0; i < len; i++)
    if(argv[*cargc + 1][i] >= 'A' && argv[*cargc + 1][i] <= 'Z')
      argv[*cargc + 1][i] = argv[*cargc + 1][i] - 'A' + 'a';
  letter = argv[*cargc + 1][0];
  if(letter < 'a' || letter > 'z' || argv[*cargc + 1][1] != '=')
    return(1);
  rules[letter - 'a'] = &argv[*cargc + 1][2];
  *cargc += 2;
  return(0);
}

variable_types:
argv
char **

variable_types: argc int

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

variable_types: letter char

return_type: int

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


original_code:
void compute_figure(char *rule, int d, int calcbounds)
{
  double sx, sy, sa, ss;
  int len, i, ax, ay, bx, by, num;
  num = 0;
  len = (rule != ((void *)0)) ? strlen(rule) : 0;
  for(i = 0; i < len; i++) {
    if((rule[i] >= 'a' && rule[i] <= 'z') || rule[i] == '|') {
      if(d > 0 && rule[i] != '|') {
        ss = s; s *= ds;
        compute_figure(rules[rule[i] - 'a'], d - 1, calcbounds);
        s = ss;
      }
      else if(rule[i] == 'f' || rule[i] == 'g' || rule[i] == '|') {
        sx = x + sin(a + unoise * random_range(-1.0, 1.0)) * s;
        sy = y + cos(a + unoise * random_range(-1.0, 1.0)) * s;
        if(rule[i] == 'f' || rule[i] == '|') {
          ax = width * x + 0.5;
          ay = height * y + 0.5;
          bx = width * sx + 0.5;
          by = height * sy + 0.5;
          if(calcbounds) {
            maxx = ((maxx) > (((ax) > (bx) ? (ax) : (bx))) ? (maxx) : (((ax) > (bx) ? (ax) : (bx))));
            maxy = ((maxy) > (((height - ay) > (height - by) ? (height - ay) : (height - by))) ? (maxy) : (((height - ay) > (height - by) ? (height - ay) : (height - by))));
            minx = ((minx) < (((ax) < (bx) ? (ax) : (bx))) ? (minx) : (((ax) < (bx) ? (ax) : (bx))));
            miny = ((miny) < (((height - ay) < (height - by) ? (height - ay) : (height - by))) ? (miny) : (((height - ay) < (height - by) ? (height - ay) : (height - by))));
          }
          else
            plot_line(ax, height - ay, bx, height - by, 1);
        }
        x = sx; y = sy;
      }
    }
    else if(rule[i] >= '0' && rule[i] <= '9')
      num = num * 10 + (rule[i] - '0');
    else if(rule[i] == '+' || rule[i] == '-') {
      num = (num == 0) ? 1 : num;
      a += (rule[i] == '+') ? num * da : num * -da;
      num = 0;
    }
    else if(rule[i] == '[') {
      sx = x; sy = y; sa = a, ss = s;
      compute_figure(rule + i + 1, d, calcbounds);
      x = sx; y = sy; a = sa; s = ss; num = 1;
      do {
        i++;
        num = num + ((rule[i] == '[') ? 1 : (rule[i] == ']') ? -1 : 0);
      } while(num != 0);
    }
    else if(rule[i] == ']') return;
  }
}

canonical_original_code:
void compute_figure(char *rule, int d, int calcbounds)
{
  double sx; double sy; double sa; double ss;
  int len; int i; int ax; int ay; int bx; int by; int num;
  num = 0;
  len = (rule != ((void *)0)) ? strlen(rule) : 0;
  for(i = 0; i < len; i++) {
    if((rule[i] >= 'a' && rule[i] <= 'z') || rule[i] == '|') {
      if(d > 0 && rule[i] != '|') {
        ss = s; s *= ds;
        compute_figure(rules[rule[i] - 'a'], d - 1, calcbounds);
        s = ss;
      }
      else if(rule[i] == 'f' || rule[i] == 'g' || rule[i] == '|') {
        sx = x + sin(a + unoise * random_range(-1.0, 1.0)) * s;
        sy = y + cos(a + unoise * random_range(-1.0, 1.0)) * s;
        if(rule[i] == 'f' || rule[i] == '|') {
          ax = width * x + 0.5;
          ay = height * y + 0.5;
          bx = width * sx + 0.5;
          by = height * sy + 0.5;
          if(calcbounds) {
            maxx = ((maxx) > (((ax) > (bx) ? (ax) : (bx))) ? (maxx) : (((ax) > (bx) ? (ax) : (bx))));
            maxy = ((maxy) > (((height - ay) > (height - by) ? (height - ay) : (height - by))) ? (maxy) : (((height - ay) > (height - by) ? (height - ay) : (height - by))));
            minx = ((minx) < (((ax) < (bx) ? (ax) : (bx))) ? (minx) : (((ax) < (bx) ? (ax) : (bx))));
            miny = ((miny) < (((height - ay) < (height - by) ? (height - ay) : (height - by))) ? (miny) : (((height - ay) < (height - by) ? (height - ay) : (height - by))));
          }
          else
            plot_line(ax, height - ay, bx, height - by, 1);
        }
        x = sx; y = sy;
      }
    }
    else if(rule[i] >= '0' && rule[i] <= '9')
      num = num * 10 + (rule[i] - '0');
    else if(rule[i] == '+' || rule[i] == '-') {
      num = (num == 0) ? 1 : num;
      a += (rule[i] == '+') ? num * da : num * -da;
      num = 0;
    }
    else if(rule[i] == '[') {
      sx = x; sy = y; sa = a, ss = s;
      compute_figure(rule + i + 1, d, calcbounds);
      x = sx; y = sy; a = sa; s = ss; num = 1;
      do {
        i++;
        num = num + ((rule[i] == '[') ? 1 : (rule[i] == ']') ? -1 : 0);
      } while(num != 0);
    }
    else if(rule[i] == ']') return;
  }
}

variable_types:
rule
char *

variable_types: d int

variable_types: calcbounds int

variable_types: sx double

variable_types: sy double

variable_types: sa double

variable_types: ss double

variable_types: i int

variable_types: ax int

variable_types: ay int

variable_types: bx int

variable_types: by int

variable_types: num int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_WORD *v3; // rdx
__int64 i; // rax
unsigned __int8 v5; // cl
char *v6; // rbx
int v7; // eax
__int64 j; // rdx
char v9; // cl
double v10; // xmm0_8
double v11; // xmm5_8
double v12; // xmm3_8
double v13; // xmm7_8

v3 = &stubs;
for ( i = 0LL; i != 26; ++i )
{
rules[i] = (__int64)v3;
v5 = i + 97;
*v3++ = v5;
}
get_options(argc, argv, &options, help_string);
v6 = axiom;
plot_mag = mag;
plot_inverse = invert;
v7 = strlen(axiom);
if ( v7 > 0 )
{
for ( j = 0LL; ; ++j )
{
v9 = v6[j];
if ( (unsigned __int8)(v9 - 65) <= 0x19u )
v6[j] = v9 + 32;
if ( v7 - 1 == j )
break;
v6 = axiom;
}
}
*(double *)&aa0 = *(double *)&aa0 * 3.141592653589793 / 180.0;
*(double *)&da = 3.141592653589793 * *(double *)&da / 180.0;
plot_init((unsigned int)width, (unsigned int)height, 2LL, term);
plot_set_all(0LL);
x = 0LL;
s = LC0;
a = aa0;
y = 0LL;
srandom(0);
compute_figure((__int64)axiom, (unsigned int)depth, 1u);
v10 = fmax((double)(maxy - miny) / (double)height, (double)(maxx - minx) / (double)width);
v11 = (double)(-2 * border) * v10;
v12 = (double)(2 * border) * v10;
if ( maxx - minx <= maxy - miny )
{
v13 = (double)(-2 * border) * v10;
v11 = (double)(minx + maxy - miny - maxx) - v12;
}
else
{
v13 = (double)(miny + maxx - minx - maxy) - v12;
}
plot_set_range(
v10 * (double)width + (double)minx - v11 * 0.5 - 0.5,
(double)maxx - v10 * (double)width + v11 * 0.5 + 0.5,
(double)miny + (double)height * v10 - v13 * 0.5 - 0.5,
(double)maxy - (double)height * v10 + v13 * 0.5 + 0.5);
x = 0LL;
s = LC0;
a = aa0;
y = 0LL;
srandom(0);
compute_figure((__int64)axiom, (unsigned int)depth, 0);
plot_finish();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_WORD *v3; // rdx
__int64 i; // rax
unsigned __int8 v5; // cl
char *v6; // rbx
int v7; // eax
__int64 j; // rdx
char v9; // cl
double v10; // xmm0_8
double v11; // xmm5_8
double v12; // xmm3_8
double v13; // xmm7_8

v3 = &stubs;
for ( i = 0LL; i != 26; ++i )
{
rules[i] = (__int64)v3;
v5 = i + 97;
*v3++ = v5;
}
get_options(argc, argv, &options, help_string);
v6 = axiom;
plot_mag = mag;
plot_inverse = invert;
v7 = strlen(axiom);
if ( v7 > 0 )
{
for ( j = 0LL; ; ++j )
{
v9 = v6[j];
if ( (unsigned __int8)(v9 - 65) <= 0x19u )
v6[j] = v9 + 32;
if ( v7 - 1 == j )
break;
v6 = axiom;
}
}
*(double *)&aa0 = *(double *)&aa0 * 3.141592653589793 / 180.0;
*(double *)&da = 3.141592653589793 * *(double *)&da / 180.0;
plot_init((unsigned int)width, (unsigned int)height, 2LL, term);
plot_set_all(0LL);
x = 0LL;
s = LC0;
a = aa0;
y = 0LL;
srandom(0);
func1((__int64)axiom, (unsigned int)depth, 1u);
v10 = fmax((double)(maxy - miny) / (double)height, (double)(maxx - minx) / (double)width);
v11 = (double)(-2 * border) * v10;
v12 = (double)(2 * border) * v10;
if ( maxx - minx <= maxy - miny )
{
v13 = (double)(-2 * border) * v10;
v11 = (double)(minx + maxy - miny - maxx) - v12;
}
else
{
v13 = (double)(miny + maxx - minx - maxy) - v12;
}
plot_set_range(
v10 * (double)width + (double)minx - v11 * 0.5 - 0.5,
(double)maxx - v10 * (double)width + v11 * 0.5 + 0.5,
(double)miny + (double)height * v10 - v13 * 0.5 - 0.5,
(double)maxy - (double)height * v10 + v13 * 0.5 + 0.5);
x = 0LL;
s = LC0;
a = aa0;
y = 0LL;
srandom(0);
func1((__int64)axiom, (unsigned int)depth, 0);
plot_finish();
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int plot_inverse;
  double xs, ys, xo, yo;
  int i, len;
  for(i = 0; i < ('z' - 'a' + 1); i++) {
    stubs[i * 2] = i + 'a';
    stubs[i * 2 + 1] = 0;
    rules[i] = &stubs[i * 2];
  }
  get_options(argc, argv, options, help_string);
  plot_mag = mag;
  plot_inverse = invert;
  len = strlen(axiom);
  for(i = 0; i < len; i++)
    if(axiom[i] >= 'A' && axiom[i] <= 'Z')
      axiom[i] = axiom[i] - 'A' + 'a';
  aa0 = aa0 * 3.14159265358979323846 / 180.0;
  da = da * 3.14159265358979323846 / 180.0;
  plot_init(width, height, 2, term);
  plot_set_all(0);
  x = 0; y = 0; a = aa0; s = 1;
  srandom(0);
  compute_figure(axiom, depth, 1);
  xs = (maxx - minx) / (double) width;
  ys = (maxy - miny) / (double) height;
  if(ys > xs) xs = ys; else ys = xs;
  if((maxx - minx) > (maxy - miny)) {
    yo = (maxx - minx - maxy + miny) - 2 * border * ys;
    xo = -2 * border * xs;
  }
  else {
    xo = (maxy - miny - maxx + minx) - 2 * border * xs;
    yo = -2 * border * ys;
  }
  plot_set_range(xs * width + minx - xo / 2 - 0.5,
                 maxx - xs * width + xo / 2 + 0.5,
                 ys * height + miny - yo / 2 - 0.5,
                 maxy - ys * height + yo / 2 + 0.5);
  x = 0; y = 0; a = aa0; s = 1;
  srandom(0);
  compute_figure(axiom, depth, 0);
  plot_finish();
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int plot_inverse;
  double xs; double ys; double xo; double yo;
  int i; int len;
  for(i = 0; i < ('z' - 'a' + 1); i++) {
    stubs[i * 2] = i + 'a';
    stubs[i * 2 + 1] = 0;
    rules[i] = &stubs[i * 2];
  }
  get_options(argc, argv, options, help_string);
  plot_mag = mag;
  plot_inverse = invert;
  len = strlen(axiom);
  for(i = 0; i < len; i++)
    if(axiom[i] >= 'A' && axiom[i] <= 'Z')
      axiom[i] = axiom[i] - 'A' + 'a';
  aa0 = aa0 * 3.14159265358979323846 / 180.0;
  da = da * 3.14159265358979323846 / 180.0;
  plot_init(width, height, 2, term);
  plot_set_all(0);
  x = 0; y = 0; a = aa0; s = 1;
  srandom(0);
  compute_figure(axiom, depth, 1);
  xs = (maxx - minx) / (double) width;
  ys = (maxy - miny) / (double) height;
  if(ys > xs) xs = ys; else ys = xs;
  if((maxx - minx) > (maxy - miny)) {
    yo = (maxx - minx - maxy + miny) - 2 * border * ys;
    xo = -2 * border * xs;
  }
  else {
    xo = (maxy - miny - maxx + minx) - 2 * border * xs;
    yo = -2 * border * ys;
  }
  plot_set_range(xs * width + minx - xo / 2 - 0.5,
                 maxx - xs * width + xo / 2 + 0.5,
                 ys * height + miny - yo / 2 - 0.5,
                 maxy - ys * height + yo / 2 + 0.5);
  x = 0; y = 0; a = aa0; s = 1;
  srandom(0);
  compute_figure(axiom, depth, 0);
  plot_finish();
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: xs double

variable_types: ys double

variable_types: xo double

variable_types: yo double


decompiled_code:
int __fastcall bad_option(const char **a1, int a2)
{
return fprintf(stderr, "%s: unknown or incorrectly used option \"%s\".\n", *a1, a1[a2]);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, int a2)
{
return fprintf(stderr, "%s: unknown or incorrectly used option \"%s\".\n", *a1, a1[a2]);
}

original_code:
void bad_option(char **argv, int badopt)
{
  fprintf(stderr, "%s: unknown or incorrectly used option \"%s\".\n",
          argv[0], argv[badopt]);
}

variable_types: badopt int


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "malloc failed to get %d bytes.\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "malloc failed to get %d bytes.\n", a1);
exit(1);
}
return result;
}

original_code:
void *xmalloc(size_t bytes)
{
  void *ptr;
  if((ptr = malloc(bytes)) == ((void *)0)) {
    fprintf(stderr, "malloc failed to get %d bytes.\n", bytes);
    exit(1);
  }
  return(ptr);
}

canonical_original_code:
void *xmalloc(unsigned long bytes)
{
  void *ptr;
  if((ptr = malloc(bytes)) == ((void *)0)) {
    fprintf(stderr, "malloc failed to get %d bytes.\n", bytes);
    exit(1);
  }
  return(ptr);
}

variable_types:
bytes
unsigned long

variable_types:
ptr
void *

return_type: void *


decompiled_code:
void __fastcall get_options(int a1, const char **a2, const char **a3, char *a4)
{
int v4; // ebp
__int64 v5; // rbx
const char *v6; // r14
const char **v7; // rax
bool v8; // zf
unsigned int v9; // er13
_BOOL4 v10; // er12
const char **v11; // r15
int v12; // er8
int v13; // esi
const char **v15; // [rsp+10h] [rbp-68h]
int v18[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v4 = 1;
v18[0] = 1;
while ( 2 )
{
v5 = v4;
v15 = &a2[v5];
LABEL_3:
if ( a1 <= v4 )
return;
v6 = *v15;
v7 = a3;
v8 = strcmp(*v15, "-help") == 0;
v9 = 0;
v10 = !v8;
if ( v8 )
{
LABEL_18:
display_options_isra_0(*a2, a3, a4);
LABEL_19:
v13 = v4;
goto LABEL_20;
}
while ( 1 )
{
v11 = v7;
if ( !*v7 )
goto LABEL_19;
v12 = strcmp(v6, *v7);
v7 = v11 + 4;
if ( !v12 )
break;
++v9;
if ( !v10 )
goto LABEL_18;
}
switch ( *((_DWORD *)v11 + 2) )
{
case 0:
if ( v4 + 1 >= a1 )
goto LABEL_19;
*(_DWORD *)v11[2] = atoi(a2[v5 + 1]);
v4 = v18[0] + 2;
v18[0] += 2;
continue;
case 1:
if ( v4 + 1 >= a1 )
goto LABEL_19;
v4 += 2;
*(double *)v11[2] = atof(a2[v5 + 1]);
v18[0] = v4;
continue;
case 2:
if ( v4 + 1 >= a1 )
goto LABEL_19;
v4 += 2;
*(_QWORD *)v11[2] = a2[v5 + 1];
v18[0] = v4;
continue;
case 3:
*(_DWORD *)v11[2] = *(_DWORD *)v11[2] == 0;
v4 = ++v18[0];
continue;
case 4:
if ( !((unsigned int (__fastcall *)(const char **, _QWORD, const char **, int *, _QWORD))v11[2])(
a2,
(unsigned int)a1,
a3,
v18,
v9) )
{
v4 = v18[0];
continue;
}
v13 = v18[0];
LABEL_20:
bad_option(a2, v13);
display_options_isra_0(*a2, a3, a4);
return;
default:
goto LABEL_3;
}
}
}

canonical_decompiled_code:
void __fastcall func8(int a1, const char **a2, const char **a3, char *a4)
{
int v4; // ebp
__int64 v5; // rbx
const char *v6; // r14
const char **v7; // rax
bool v8; // zf
unsigned int v9; // er13
_BOOL4 v10; // er12
const char **v11; // r15
int v12; // er8
int v13; // esi
const char **v15; // [rsp+10h] [rbp-68h]
int v18[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v4 = 1;
v18[0] = 1;
while ( 2 )
{
v5 = v4;
v15 = &a2[v5];
LABEL_3:
if ( a1 <= v4 )
return;
v6 = *v15;
v7 = a3;
v8 = strcmp(*v15, "-help") == 0;
v9 = 0;
v10 = !v8;
if ( v8 )
{
LABEL_18:
func7(*a2, a3, a4);
LABEL_19:
v13 = v4;
goto LABEL_20;
}
while ( 1 )
{
v11 = v7;
if ( !*v7 )
goto LABEL_19;
v12 = strcmp(v6, *v7);
v7 = v11 + 4;
if ( !v12 )
break;
++v9;
if ( !v10 )
goto LABEL_18;
}
switch ( *((_DWORD *)v11 + 2) )
{
case 0:
if ( v4 + 1 >= a1 )
goto LABEL_19;
*(_DWORD *)v11[2] = atoi(a2[v5 + 1]);
v4 = v18[0] + 2;
v18[0] += 2;
continue;
case 1:
if ( v4 + 1 >= a1 )
goto LABEL_19;
v4 += 2;
*(double *)v11[2] = atof(a2[v5 + 1]);
v18[0] = v4;
continue;
case 2:
if ( v4 + 1 >= a1 )
goto LABEL_19;
v4 += 2;
*(_QWORD *)v11[2] = a2[v5 + 1];
v18[0] = v4;
continue;
case 3:
*(_DWORD *)v11[2] = *(_DWORD *)v11[2] == 0;
v4 = ++v18[0];
continue;
case 4:
if ( !((unsigned int (__fastcall *)(const char **, _QWORD, const char **, int *, _QWORD))v11[2])(
a2,
(unsigned int)a1,
a3,
v18,
v9) )
{
v4 = v18[0];
continue;
}
v13 = v18[0];
LABEL_20:
func1(a2, v13);
func7(*a2, a3, a4);
return;
default:
goto LABEL_3;
}
}
}

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

variable_types: found int


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

canonical_decompiled_code:
double __fastcall func9(double a1, double a2)
{
return (a2 - a1) * COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)(int)random() * 4.656612873077393e-10) & LC11) + 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


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

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

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

if ( holding_1 )
{
holding_1 = 0;
result = *(double *)&hold_0;
}
else
{
v0 = *(double *)&LC12;
do
{
v7 = func9(-1.0, v0);
v1 = func9(-1.0, 1.0);
v0 = *(double *)&LC12;
v2 = v7 * v7 + v1 * v1;
}
while ( v2 >= 1.0 );
v3 = log(v2) * -2.0 / v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
holding_1 = 1;
v5 = v7 * v4;
result = v4 * v1;
hold_0 = *(_QWORD *)&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: i int

variable_types:
str
char *


decompiled_code:
__int64 __fastcall x11plot_init(int a1, int a2, int a3)
{
char *v4; // r14
Display *v5; // rax
unsigned __int64 v6; // rbx
unsigned __int64 v7; // rcx
__int64 *v8; // rax
unsigned __int64 v9; // rdx
unsigned __int64 *v10; // rax
__int64 result; // rax
__int64 v12; // rax
char *v13; // rax
char v14[8]; // [rsp+8h] [rbp-50h] BYREF
XColor v15; // [rsp+10h] [rbp-48h] BYREF
char s[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = getenv("DISPLAY");
v5 = XOpenDisplay(v4);
x_display = v5;
if ( !v5 )
{
v13 = XDisplayName(v4);
fprintf(stderr, "x11plot_init: could not open display %s.\n", v13);
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 ( &unk_9E0 != (_UNKNOWN *)v8 );
v9 = x_whitepixel;
v10 = (unsigned __int64 *)&unk_9E0;
do
*v10++ = v9;
while ( v10 != &x_whitepixel );
}
else
{
do
{
int_to_hexstr(2 * v6, v14);
sprintf(s, "#%s%s%s", v14, v14, v14);
if ( XParseColor(x_display, x_colormap, s, &v15) )
{
if ( XAllocColor(x_display, x_colormap, &v15) )
{
x_grays[v6] = v15.pixel;
}
else
{
v12 = x_blackpixel;
if ( v6 >= 0x40 )
v12 = x_whitepixel;
x_grays[v6] = v12;
}
}
else
{
fprintf(stderr, "No such color %s\n", s);
}
++v6;
}
while ( v6 != 128 );
}
x11plot_levels = a3;
result = open_window(a1 * plot_mag, plot_mag * a2);
x_window = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, int a3)
{
char *v4; // r14
Display *v5; // rax
unsigned __int64 v6; // rbx
unsigned __int64 v7; // rcx
__int64 *v8; // rax
unsigned __int64 v9; // rdx
unsigned __int64 *v10; // rax
__int64 result; // rax
__int64 v12; // rax
char *v13; // rax
char v14[8]; // [rsp+8h] [rbp-50h] BYREF
XColor v15; // [rsp+10h] [rbp-48h] BYREF
char s[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = getenv("DISPLAY");
v5 = XOpenDisplay(v4);
x_display = v5;
if ( !v5 )
{
v13 = XDisplayName(v4);
fprintf(stderr, "x11plot_init: could not open display %s.\n", v13);
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 ( &unk_9E0 != (_UNKNOWN *)v8 );
v9 = x_whitepixel;
v10 = (unsigned __int64 *)&unk_9E0;
do
*v10++ = v9;
while ( v10 != &x_whitepixel );
}
else
{
do
{
func1(2 * v6, v14);
sprintf(s, "#%s%s%s", v14, v14, v14);
if ( XParseColor(x_display, x_colormap, s, &v15) )
{
if ( XAllocColor(x_display, x_colormap, &v15) )
{
x_grays[v6] = v15.pixel;
}
else
{
v12 = x_blackpixel;
if ( v6 >= 0x40 )
v12 = x_whitepixel;
x_grays[v6] = v12;
}
}
else
{
fprintf(stderr, "No such color %s\n", s);
}
++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)
{
double v3; // xmm0_8
int v4; // ecx
int v5; // ebx
int v6; // er13
int v7; // er8
int result; // eax

v3 = 0.0;
if ( a3 >= 0 )
{
v3 = (double)(x11plot_levels - 1);
if ( a3 < x11plot_levels )
v3 = (double)a3;
}
XSetForeground(x_display, x_gc, x_grays[(int)(v3 / (double)(x11plot_levels - 1) * 127.0 + 0.5)]);
v4 = plot_mag;
if ( plot_mag > 0 )
{
v5 = 0;
do
{
v6 = 0;
do
{
v7 = v4 * a2 + v6++;
XDrawPoint(x_display, x_window, x_gc, v5 + a1 * v4, v7);
v4 = plot_mag;
}
while ( plot_mag > v6 );
++v5;
}
while ( plot_mag > v5 && plot_mag > 0 );
}
result = x11_force_flush;
if ( x11_force_flush )
result = XFlush(x_display);
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, int a2, int a3)
{
double v3; // xmm0_8
int v4; // ecx
int v5; // ebx
int v6; // er13
int v7; // er8
int result; // eax

v3 = 0.0;
if ( a3 >= 0 )
{
v3 = (double)(x11plot_levels - 1);
if ( a3 < x11plot_levels )
v3 = (double)a3;
}
XSetForeground(x_display, x_gc, x_grays[(int)(v3 / (double)(x11plot_levels - 1) * 127.0 + 0.5)]);
v4 = plot_mag;
if ( plot_mag > 0 )
{
v5 = 0;
do
{
v6 = 0;
do
{
v7 = v4 * a2 + v6++;
XDrawPoint(x_display, x_window, x_gc, v5 + a1 * v4, v7);
v4 = plot_mag;
}
while ( plot_mag > v6 );
++v5;
}
while ( plot_mag > v5 && plot_mag > 0 );
}
result = x11_force_flush;
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: 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)
{
double v7; // xmm0_8
int v8; // er12
double v9; // xmm2_8
int v10; // ebp
signed int v11; // eax
int v12; // ebx
int result; // eax
int v14; // [rsp-10h] [rbp-78h]
double v15; // [rsp+18h] [rbp-50h]

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

canonical_decompiled_code:
int __fastcall func6(int a1, int a2, int a3, int a4, int a5)
{
double v7; // xmm0_8
int v8; // er12
double v9; // xmm2_8
int v10; // ebp
signed int v11; // eax
int v12; // ebx
int result; // eax
int v14; // [rsp-10h] [rbp-78h]
double v15; // [rsp+18h] [rbp-50h]

if ( a5 < 0 )
{
v7 = 0.0;
v8 = 0;
}
else
{
if ( a5 > x11plot_levels )
a5 = x11plot_levels;
v7 = (double)a5;
v8 = a5;
}
XSetForeground(x_display, x_gc, x_grays[(int)(v7 / (double)x11plot_levels * 127.0 + 0.5)]);
if ( plot_mag == 1 )
{
XDrawLine(x_display, x_window, x_gc, a1, a2, a3, a4);
result = v14;
}
else if ( a1 == a3 && a2 == a4 )
{
result = func5(a1, a2, v8);
}
else
{
v9 = 0.0;
v10 = abs32(a2 - a4);
v11 = abs32(a1 - a3);
v15 = (double)a3;
if ( v10 < v11 )
v10 = v11;
v12 = 0;
do
{
++v12;
result = func5(
(int)((double)a1 * v9 + (1.0 - v9) * v15 + 0.5),
(int)((double)a2 * v9 + (double)a4 * (1.0 - v9) + 0.5),
v8);
v9 = v9 + 1.0 / (double)v10;
}
while ( v10 >= v12 );
}
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


decompiled_code:
__int64 __fastcall random_solution(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
int v4; // esi
_DWORD *v5; // rax

result = (unsigned int)len;
if ( len > 0 )
{
result = 0LL;
do
{
*(_DWORD *)(a1 + 4 * result) = result;
++result;
}
while ( len > (int)result );
if ( len > 1 )
{
v2 = 0LL;
do
{
v3 = random();
v4 = *(_DWORD *)(a1 + 4 * v2);
v5 = (_DWORD *)(a1 + 4LL * (int)(v2 + v3 % (len - (int)v2)));
*(_DWORD *)(a1 + 4 * v2++) = *v5;
*v5 = v4;
result = (unsigned int)(len - 1);
}
while ( (int)result > (int)v2 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
int v4; // esi
_DWORD *v5; // rax

result = (unsigned int)len;
if ( len > 0 )
{
result = 0LL;
do
{
*(_DWORD *)(a1 + 4 * result) = result;
++result;
}
while ( len > (int)result );
if ( len > 1 )
{
v2 = 0LL;
do
{
v3 = random();
v4 = *(_DWORD *)(a1 + 4 * v2);
v5 = (_DWORD *)(a1 + 4LL * (int)(v2 + v3 % (len - (int)v2)));
*(_DWORD *)(a1 + 4 * v2++) = *v5;
*v5 = v4;
result = (unsigned int)(len - 1);
}
while ( (int)result > (int)v2 );
}
}
return result;
}

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

variable_types: t int


decompiled_code:
__int64 __fastcall task_cost(__int64 a1)
{
__int64 v1; // rax
int v2; // er8
__int64 v3; // rcx
__int64 v4; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
int v2; // er8
__int64 v3; // rcx
__int64 v4; // rdx

if ( len <= 0 )
return 0LL;
v1 = 0LL;
v2 = 0;
do
{
v3 = *(int *)(a1 + 4 * v1);
v4 = *(_QWORD *)(cost + 8 * v1++);
v2 = (int)((double)v2 + *(double *)(v4 + 8 * v3));
}
while ( len != v1 );
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


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: sum double

variable_types: min 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 func4(__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: 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, double a4, double a5)
{
int v5; // er13
__int64 v6; // rax
double v7; // xmm2_8
int v8; // ebx
double v9; // xmm0_8
double v10; // xmm3_8
unsigned int v11; // er12
double v12; // xmm2_8
int v13; // eax
_QWORD *v14; // r13
__int64 v15; // rbx
const char *v16; // rdi
__int64 v17; // rsi

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

canonical_decompiled_code:
int __fastcall func6(unsigned int a1, __int64 a2, __int64 a3, double a4, double a5)
{
int v5; // er13
__int64 v6; // rax
double v7; // xmm2_8
int v8; // ebx
double v9; // xmm0_8
double v10; // xmm3_8
unsigned int v11; // er12
double v12; // xmm2_8
int v13; // eax
_QWORD *v14; // r13
__int64 v15; // rbx
const char *v16; // rdi
__int64 v17; // rsi

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

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: i 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)
{
double v3; // xmm0_8
double v4; // xmm1_8
__int64 v5; // r14
__int64 v6; // r13
__int64 v7; // r12
__int64 *v8; // rbx
double *v9; // rbp
__int64 v10; // rax
__int64 v11; // rdi
__int64 v12; // rax
int v13; // edx
__int64 v14; // rdi
int v15; // er15
signed int v16; // er14
int i; // ebx
int v18; // er15
int v19; // eax
int v20; // er8
__int64 v21; // rax
__int64 v22; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
double v4; // xmm1_8
__int64 v5; // r14
__int64 v6; // r13
__int64 v7; // r12
__int64 *v8; // rbx
double *v9; // rbp
__int64 v10; // rax
__int64 v11; // rdi
__int64 v12; // rax
int v13; // edx
__int64 v14; // rdi
int v15; // er15
signed int v16; // er14
int i; // ebx
int v18; // er15
int v19; // eax
int v20; // er8
__int64 v21; // rax
__int64 v22; // [rsp+8h] [rbp-40h]

get_options(argc, argv, &options, help_string);
srandom(seed);
func0(specs);
v5 = 0LL;
size += ((size + ((unsigned int)size >> 31)) & 0xFFFFFFFE) != size;
v6 = xmalloc(8LL * size);
v7 = xmalloc(8LL * size);
v8 = (__int64 *)v7;
v22 = xmalloc(8LL * size);
v9 = (double *)xmalloc(8LL * size);
if ( size > 0 )
{
do
{
v10 = xmalloc(4LL * len);
v11 = len;
*(_QWORD *)(v6 + 8 * v5) = v10;
v12 = xmalloc(4 * v11);
v13 = len;
*v8 = v12;
v14 = v12;
if ( v13 > 0 )
{
v15 = 0;
while ( 1 )
{
func1(v14);
if ( 2 * len <= ++v15 )
break;
v14 = *v8;
}
}
++v5;
++v8;
}
while ( size > (int)v5 );
}
v16 = 0;
if ( gens > 0 )
{
while ( 1 )
{
func3(v7, v22, v9);
func6(v16, v7, v22, v3, v4);
for ( i = 0; size > i; i += 2 )
{
v18 = func4((__int64)v9);
v19 = func4((__int64)v9);
v20 = i;
func5(v7, v6, v18, v19, v20);
}
++v16;
v21 = v7;
v7 = v6;
if ( gens <= v16 )
break;
v6 = v21;
}
}
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: t int

variable_types:
swap
int **

variable_types:
fit
double *

variable_types:
normfit
double *


decompiled_code:
double __fastcall str2num(char *a1)
{
double v1; // xmm2_8
char *v2; // rdx
double v3; // xmm0_8
char *v4; // rax

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

canonical_decompiled_code:
double __fastcall func1(char *a1)
{
double v1; // xmm2_8
char *v2; // rdx
double v3; // xmm0_8
char *v4; // rax

if ( len <= 0 )
{
v1 = 0.0;
}
else
{
v1 = 0.0;
v2 = &a1[len - 1];
do
{
v3 = (double)(*a1 - 48);
v4 = a1++;
v1 = v1 + v1 + v3;
}
while ( v2 != v4 );
}
return v1 / 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


decompiled_code:
__int64 __fastcall compute_fitness(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
double v4; // xmm2_8
__int64 v6; // rbx
double v7; // xmm0_8
double v8; // xmm0_8
__int64 v9; // rdx
double v10; // [rsp+0h] [rbp-38h]

result = (unsigned int)size;
if ( size > 0 )
{
v4 = 0.0;
v6 = 0LL;
do
{
v10 = str2num((char *)(*(_QWORD *)(a1 + 8 * v6) + len));
v7 = str2num(*(char **)(a1 + 8 * v6));
v8 = surface(v7, v10);
result = (unsigned int)size;
*(double *)(a2 + 8 * v6++) = v8;
v4 = v4 + v8;
}
while ( (int)result > (int)v6 );
if ( (int)result > 0 )
{
v9 = (int)result;
for ( result = 0LL; result != v9; ++result )
*(double *)(a3 + 8 * result) = *(double *)(a2 + 8 * result) / v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
double v4; // xmm2_8
__int64 v6; // rbx
double v7; // xmm0_8
double v8; // xmm0_8
__int64 v9; // rdx
double v10; // [rsp+0h] [rbp-38h]

result = (unsigned int)size;
if ( size > 0 )
{
v4 = 0.0;
v6 = 0LL;
do
{
v10 = func1((char *)(*(_QWORD *)(a1 + 8 * v6) + len));
v7 = func1(*(char **)(a1 + 8 * v6));
v8 = func0(v7, v10);
result = (unsigned int)size;
*(double *)(a2 + 8 * v6++) = v8;
v4 = v4 + v8;
}
while ( (int)result > (int)v6 );
if ( (int)result > 0 )
{
v9 = (int)result;
for ( result = 0LL; result != v9; ++result )
*(double *)(a3 + 8 * result) = *(double *)(a2 + 8 * result) / v4;
}
}
return result;
}

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)
{
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;
}


reproduce

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
double v4; // xmm2_8
__int64 v6; // rax
double v7; // xmm1_8
int v8; // edx
double v9; // xmm0_8
double v10; // xmm3_8
__int64 v11; // rbx
char **v12; // rbx
double v13; // xmm0_8
double v15; // [rsp+0h] [rbp-28h]

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

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, __int64 a2, __int64 a3)
{
int v3; // er12
double v4; // xmm2_8
__int64 v6; // rax
double v7; // xmm1_8
int v8; // edx
double v9; // xmm0_8
double v10; // xmm3_8
__int64 v11; // rbx
char **v12; // rbx
double v13; // xmm0_8
double v15; // [rsp+0h] [rbp-28h]

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

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: i 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
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // rdx
int v10; // eax
__int64 v11; // r14
__int64 v12; // rdx
signed int v13; // er15
int v14; // er13
int v15; // er14
int v16; // eax
int v17; // er8
__int64 v18; // rax
__int64 v19; // [rsp+8h] [rbp-40h]

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

variable_types: t int

variable_types:
swap
char **

variable_types:
fit
double *


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;
}

variable_types: i int


decompiled_code:
int pgmplot_finish()
{
__int64 v0; // rbp
int result; // eax
__int64 i; // rbx
__int64 v3; // rax

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

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbp
int result; // eax
__int64 i; // rbx
__int64 v3; // rax

if ( pgmplot_height > 0 )
{
v0 = 0LL;
do
{
result = pgmplot_width;
for ( i = 0LL; pgmplot_width > (int)i; result = fputc(*(unsigned __int8 *)(v3 + v0), stdout) )
v3 = *(_QWORD *)(pgmplot_data + 8 * i++);
++v0;
}
while ( pgmplot_height > (int)v0 );
}
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; // xmm0_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm4_8
double v7; // xmm5_8
double v9; // [rsp+0h] [rbp-58h]
double v10; // [rsp+0h] [rbp-58h]
double v11; // [rsp+8h] [rbp-50h]
double v12; // [rsp+8h] [rbp-50h]
double v13; // [rsp+10h] [rbp-48h]
double v14; // [rsp+10h] [rbp-48h]
double v15; // [rsp+18h] [rbp-40h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx; // [rsp+28h] [rbp-30h] BYREF
double v18; // [rsp+30h] [rbp-28h] BYREF
double v19[4]; // [rsp+38h] [rbp-20h] BYREF

v18 = *(double *)(xv + 8LL * a1);
v19[0] = *(double *)(yv + 8LL * a1);
norm(&v18, v19);
v11 = *(double *)(xp + 8LL * a1);
v13 = *(double *)(yp + 8LL * a1);
v15 = v11 - v18 * (double)len;
v9 = v13 - (double)len * v19[0];
plot_line(a2, v11, v13, v15, v9);
v2 = (v11 - v15) / (double)len;
v3 = *(double *)&LC5;
if ( v2 >= -1.0 )
v3 = fmin(1.0, v2);
v4 = acos(v3);
v5 = v13;
v6 = v11;
v7 = v4;
if ( v13 - v9 < 0.0 )
*(_QWORD *)&v7 = *(_QWORD *)&v4 ^ LC4;
v14 = v7;
v12 = v5;
v10 = v6;
sincos(0.5 * *(double *)&angle + v7, &sinx, &cosx);
v18 = cosx * (double)len / 3.0 + v10;
v19[0] = (double)len * sinx / 3.0 + v5;
plot_line(a2, v10, v12, v18, (double)len * sinx / 3.0 + v12);
sincos(v14 - 0.5 * *(double *)&angle, &sinx, &cosx);
v18 = cosx * (double)len / 3.0 + v10;
v19[0] = (double)len * sinx / 3.0 + v5;
return plot_line(a2, v10, v12, v18, (double)len * sinx / 3.0 + v12);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, unsigned int a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm4_8
double v7; // xmm5_8
double v9; // [rsp+0h] [rbp-58h]
double v10; // [rsp+0h] [rbp-58h]
double v11; // [rsp+8h] [rbp-50h]
double v12; // [rsp+8h] [rbp-50h]
double v13; // [rsp+10h] [rbp-48h]
double v14; // [rsp+10h] [rbp-48h]
double v15; // [rsp+18h] [rbp-40h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx; // [rsp+28h] [rbp-30h] BYREF
double v18; // [rsp+30h] [rbp-28h] BYREF
double v19[4]; // [rsp+38h] [rbp-20h] BYREF

v18 = *(double *)(xv + 8LL * a1);
v19[0] = *(double *)(yv + 8LL * a1);
func0(&v18, v19);
v11 = *(double *)(xp + 8LL * a1);
v13 = *(double *)(yp + 8LL * a1);
v15 = v11 - v18 * (double)len;
v9 = v13 - (double)len * v19[0];
plot_line(a2, v11, v13, v15, v9);
v2 = (v11 - v15) / (double)len;
v3 = *(double *)&LC5;
if ( v2 >= -1.0 )
v3 = fmin(1.0, v2);
v4 = acos(v3);
v5 = v13;
v6 = v11;
v7 = v4;
if ( v13 - v9 < 0.0 )
*(_QWORD *)&v7 = *(_QWORD *)&v4 ^ LC4;
v14 = v7;
v12 = v5;
v10 = v6;
sincos(0.5 * *(double *)&angle + v7, &sinx, &cosx);
v18 = cosx * (double)len / 3.0 + v10;
v19[0] = (double)len * sinx / 3.0 + v5;
plot_line(a2, v10, v12, v18, (double)len * sinx / 3.0 + v12);
sincos(v14 - 0.5 * *(double *)&angle, &sinx, &cosx);
v18 = cosx * (double)len / 3.0 + v10;
v19[0] = (double)len * sinx / 3.0 + v5;
return plot_line(a2, v10, v12, v18, (double)len * sinx / 3.0 + v12);
}

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