dfft

decompiled_code:
__int64 __fastcall dfft(__int64 a1, __int64 a2, int a3)
{
int i; // er13
int v6; // eax
__int64 v7; // rax
int v8; // ecx
__int64 v9; // rdx
__int64 v10; // rdi
__int64 v11; // rsi
void *v12; // rbp
void *v13; // rdi
__int64 v14; // rcx
size_t v15; // r12
int v16; // er15
int v17; // eax
int v18; // er12
int v19; // er10
double v20; // xmm0_8
int v21; // edi
double v22; // xmm5_8
int v23; // er12
double v24; // xmm3_8
__int64 v25; // rbp
__int64 v26; // r13
__int64 v27; // rbp
double v28; // xmm6_8
double v29; // xmm4_8
__int64 v30; // rax
__int64 v31; // r14
int v32; // ebx
__int64 v33; // r15
int v34; // edi
__int64 v35; // rax
double v36; // xmm8_8
__int64 v37; // rdx
double v38; // xmm1_8
double v39; // xmm2_8
double v40; // xmm0_8
double v41; // xmm2_8
double v42; // xmm9_8
double v43; // xmm0_8
double v44; // xmm1_8
double v45; // xmm0_8
double v46; // xmm9_8
double v47; // xmm10_8
double v48; // xmm1_8
double v49; // xmm10_8
double v50; // xmm9_8
double v51; // xmm11_8
double v52; // xmm1_8
double v53; // xmm11_8
double v54; // xmm9_8
double v55; // xmm1_8
double v56; // xmm0_8
double v57; // xmm1_8
double v58; // xmm2_8
double v59; // xmm9_8
int v60; // eax
__int64 v61; // rax
int v62; // ecx
__int64 v63; // rax
double v64; // xmm0_8
double v65; // xmm2_8
double v66; // xmm0_8
double v67; // xmm0_8
double v68; // xmm2_8
double v69; // xmm0_8
__int64 v70; // rcx
int v71; // edx
__int64 v72; // rax
__int64 *v73; // rdi
__int64 *v74; // rax
__int64 v75; // xmm0_8
__int64 v76; // xmm0_8
int j; // eax
double v79; // [rsp+0h] [rbp-88h]
double v80; // [rsp+8h] [rbp-80h]
double v81; // [rsp+18h] [rbp-70h]
int v82; // [rsp+20h] [rbp-68h]
int v83; // [rsp+24h] [rbp-64h]
__int64 v84; // [rsp+28h] [rbp-60h]
int v85; // [rsp+30h] [rbp-58h]
int v86; // [rsp+34h] [rbp-54h]
int v87; // [rsp+38h] [rbp-50h]
int v88; // [rsp+3Ch] [rbp-4Ch]
double cosx; // [rsp+40h] [rbp-48h] BYREF
double sinx[8]; // [rsp+48h] [rbp-40h] BYREF

if ( a3 > 2 )
{
v86 = 1;
for ( i = 2; i < a3; i *= 2 )
{
v6 = i;
++v86;
}
if ( a3 == i )
{
v87 = 4 * v6;
goto LABEL_11;
}
v87 = 4 * v6;
LABEL_6:
LODWORD(v7) = a3 + 1;
if ( i >= a3 + 1 )
{
v7 = (int)v7;
v8 = i - a3;
v9 = (int)v7 + 1LL;
v10 = 8LL * (int)v7 - 8;
v11 = (unsigned int)(v8 - 1);
v12 = (void *)(a2 + v10);
v13 = (void *)(a1 + v10);
v14 = 8 * (v9 + v11) - 8;
if ( (unsigned __int64)v13 < a2 + v14 && (unsigned __int64)v12 < a1 + v14 )
{
while ( 1 )
{
*(_QWORD *)(a1 + 8 * v7 - 8) = 0LL;
*(_QWORD *)(a2 + 8 * v7 - 8) = 0LL;
v7 = v9;
if ( i < (int)v9 )
break;
++v9;
}
}
else
{
v15 = 8 * v11 + 8;
memset(v13, 0, v15);
memset(v12, 0, v15);
}
}
printf("\nuse %d point fft", (unsigned int)i);
if ( v86 == 1 )
{
LABEL_25:
if ( i <= 1 )
return (unsigned int)i;
goto LABEL_26;
}
LABEL_11:
v88 = 1;
v16 = i;
do
{
v17 = v87;
v18 = v87 + 7;
v19 = v87 / 2;
v20 = (double)(v87 / 2);
if ( v87 >= 0 )
v18 = v87;
v87 /= 2;
v21 = v18 >> 3;
v85 = v18 >> 3;
v81 = 6.283185307179586 / v20;
if ( v17 > 7 )
{
v22 = 0.0;
v23 = 1;
v83 = 2 * v19;
v24 = 0.0;
v25 = 8LL * v21;
v84 = v21;
v26 = a1 + v25;
v27 = a2 + v25;
v28 = 1.0;
v29 = 1.0;
v30 = a2;
v31 = a1;
v32 = v16;
v33 = v30;
while ( 1 )
{
v34 = v83;
LODWORD(v35) = v23;
v36 = (double)v23 * v81;
if ( v32 > v23 )
{
do
{
v35 = (int)v35;
v37 = 8 * (2 * v84 + (int)v35) - 8;
do
{
v38 = *(double *)(v31 + v37);
v39 = *(double *)(v31 + 8 * v35 - 8);
v40 = v39 + v38;
v41 = v39 - v38;
*(double *)(v31 + 8 * v35 - 8) = v40;
v42 = *(double *)(v26 + v37);
v43 = *(double *)(v26 + 8 * v35 - 8);
v44 = v43 + v42;
v45 = v43 - v42;
*(double *)(v26 + 8 * v35 - 8) = v44;
v46 = *(double *)(v33 + v37);
v47 = *(double *)(v33 + 8 * v35 - 8);
v48 = v47 + v46;
v49 = v47 - v46;
*(double *)(v33 + 8 * v35 - 8) = v48;
v50 = *(double *)(v27 + v37);
v51 = *(double *)(v27 + 8 * v35 - 8);
v52 = v51 + v50;
v53 = v51 - v50;
v54 = v41;
*(double *)(v27 + 8 * v35 - 8) = v52;
v55 = v45;
v56 = v45 + v49;
v35 += v34;
v57 = v55 - v49;
v58 = v41 + v53;
v59 = v54 - v53;
*(double *)(v31 + v37) = v29 * v58 - v24 * v57;
*(double *)(v33 + v37) = -v57 * v29 - v58 * v24;
*(double *)(v26 + v37) = v28 * v59 + v22 * v56;
*(double *)(v27 + v37) = v56 * v28 - v59 * v22;
v37 += 8LL * v34;
}
while ( v32 > (int)v35 );
v60 = v23 + 2 * v34;
v34 *= 4;
LODWORD(v35) = v60 - v19;
}
while ( v32 > (int)v35 );
}
if ( v85 < ++v23 )
break;
v82 = v19;
sincos(v36, sinx, &cosx);
v80 = cosx;
v79 = sinx[0];
sincos(3.0 * v36, sinx, &cosx);
v28 = cosx;
v24 = v79;
v22 = sinx[0];
v29 = v80;
v19 = v82;
}
v61 = v33;
v16 = v32;
a1 = v31;
a2 = v61;
}
++v88;
}
while ( v86 > v88 );
i = v16;
goto LABEL_25;
}
if ( a3 != 2 )
{
v87 = 4;
i = 2;
v86 = 1;
goto LABEL_6;
}
i = 2;
LABEL_26:
v62 = 4;
LODWORD(v63) = 1;
do
{
v63 = (int)v63;
do
{
v64 = *(double *)(a1 + 8 * v63 - 8);
v65 = *(double *)(a1 + 8 * v63) + v64;
v66 = v64 - *(double *)(a1 + 8 * v63);
*(double *)(a1 + 8 * v63 - 8) = v65;
*(double *)(a1 + 8 * v63) = v66;
v67 = *(double *)(a2 + 8 * v63 - 8);
v68 = *(double *)(a2 + 8 * v63) + v67;
v69 = v67 - *(double *)(a2 + 8 * v63);
*(double *)(a2 + 8 * v63 - 8) = v68;
*(double *)(a2 + 8 * v63) = v69;
v63 += v62;
}
while ( i >= (int)v63 );
LODWORD(v63) = 2 * v62 - 1;
v62 *= 4;
}
while ( (int)v63 < i );
v70 = 1LL;
v71 = 1;
do
{
if ( v71 > (int)v70 )
{
v72 = 8LL * v71 - 8;
v73 = (__int64 *)(a1 + v72);
v74 = (__int64 *)(a2 + v72);
v75 = *v73;
*v73 = *(_QWORD *)(a1 + 8 * v70 - 8);
*(_QWORD *)(a1 + 8 * v70 - 8) = v75;
v76 = *v74;
*v74 = *(_QWORD *)(a2 + 8 * v70 - 8);
*(_QWORD *)(a2 + 8 * v70 - 8) = v76;
}
for ( j = i >> 1; v71 > j; j >>= 1 )
v71 -= j;
++v70;
v71 += j;
}
while ( i != v70 );
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
int i; // er13
int v6; // eax
__int64 v7; // rax
int v8; // ecx
__int64 v9; // rdx
__int64 v10; // rdi
__int64 v11; // rsi
void *v12; // rbp
void *v13; // rdi
__int64 v14; // rcx
size_t v15; // r12
int v16; // er15
int v17; // eax
int v18; // er12
int v19; // er10
double v20; // xmm0_8
int v21; // edi
double v22; // xmm5_8
int v23; // er12
double v24; // xmm3_8
__int64 v25; // rbp
__int64 v26; // r13
__int64 v27; // rbp
double v28; // xmm6_8
double v29; // xmm4_8
__int64 v30; // rax
__int64 v31; // r14
int v32; // ebx
__int64 v33; // r15
int v34; // edi
__int64 v35; // rax
double v36; // xmm8_8
__int64 v37; // rdx
double v38; // xmm1_8
double v39; // xmm2_8
double v40; // xmm0_8
double v41; // xmm2_8
double v42; // xmm9_8
double v43; // xmm0_8
double v44; // xmm1_8
double v45; // xmm0_8
double v46; // xmm9_8
double v47; // xmm10_8
double v48; // xmm1_8
double v49; // xmm10_8
double v50; // xmm9_8
double v51; // xmm11_8
double v52; // xmm1_8
double v53; // xmm11_8
double v54; // xmm9_8
double v55; // xmm1_8
double v56; // xmm0_8
double v57; // xmm1_8
double v58; // xmm2_8
double v59; // xmm9_8
int v60; // eax
__int64 v61; // rax
int v62; // ecx
__int64 v63; // rax
double v64; // xmm0_8
double v65; // xmm2_8
double v66; // xmm0_8
double v67; // xmm0_8
double v68; // xmm2_8
double v69; // xmm0_8
__int64 v70; // rcx
int v71; // edx
__int64 v72; // rax
__int64 *v73; // rdi
__int64 *v74; // rax
__int64 v75; // xmm0_8
__int64 v76; // xmm0_8
int j; // eax
double v79; // [rsp+0h] [rbp-88h]
double v80; // [rsp+8h] [rbp-80h]
double v81; // [rsp+18h] [rbp-70h]
int v82; // [rsp+20h] [rbp-68h]
int v83; // [rsp+24h] [rbp-64h]
__int64 v84; // [rsp+28h] [rbp-60h]
int v85; // [rsp+30h] [rbp-58h]
int v86; // [rsp+34h] [rbp-54h]
int v87; // [rsp+38h] [rbp-50h]
int v88; // [rsp+3Ch] [rbp-4Ch]
double cosx; // [rsp+40h] [rbp-48h] BYREF
double sinx[8]; // [rsp+48h] [rbp-40h] BYREF

if ( a3 > 2 )
{
v86 = 1;
for ( i = 2; i < a3; i *= 2 )
{
v6 = i;
++v86;
}
if ( a3 == i )
{
v87 = 4 * v6;
goto LABEL_11;
}
v87 = 4 * v6;
LABEL_6:
LODWORD(v7) = a3 + 1;
if ( i >= a3 + 1 )
{
v7 = (int)v7;
v8 = i - a3;
v9 = (int)v7 + 1LL;
v10 = 8LL * (int)v7 - 8;
v11 = (unsigned int)(v8 - 1);
v12 = (void *)(a2 + v10);
v13 = (void *)(a1 + v10);
v14 = 8 * (v9 + v11) - 8;
if ( (unsigned __int64)v13 < a2 + v14 && (unsigned __int64)v12 < a1 + v14 )
{
while ( 1 )
{
*(_QWORD *)(a1 + 8 * v7 - 8) = 0LL;
*(_QWORD *)(a2 + 8 * v7 - 8) = 0LL;
v7 = v9;
if ( i < (int)v9 )
break;
++v9;
}
}
else
{
v15 = 8 * v11 + 8;
memset(v13, 0, v15);
memset(v12, 0, v15);
}
}
printf("\nuse %d point fft", (unsigned int)i);
if ( v86 == 1 )
{
LABEL_25:
if ( i <= 1 )
return (unsigned int)i;
goto LABEL_26;
}
LABEL_11:
v88 = 1;
v16 = i;
do
{
v17 = v87;
v18 = v87 + 7;
v19 = v87 / 2;
v20 = (double)(v87 / 2);
if ( v87 >= 0 )
v18 = v87;
v87 /= 2;
v21 = v18 >> 3;
v85 = v18 >> 3;
v81 = 6.283185307179586 / v20;
if ( v17 > 7 )
{
v22 = 0.0;
v23 = 1;
v83 = 2 * v19;
v24 = 0.0;
v25 = 8LL * v21;
v84 = v21;
v26 = a1 + v25;
v27 = a2 + v25;
v28 = 1.0;
v29 = 1.0;
v30 = a2;
v31 = a1;
v32 = v16;
v33 = v30;
while ( 1 )
{
v34 = v83;
LODWORD(v35) = v23;
v36 = (double)v23 * v81;
if ( v32 > v23 )
{
do
{
v35 = (int)v35;
v37 = 8 * (2 * v84 + (int)v35) - 8;
do
{
v38 = *(double *)(v31 + v37);
v39 = *(double *)(v31 + 8 * v35 - 8);
v40 = v39 + v38;
v41 = v39 - v38;
*(double *)(v31 + 8 * v35 - 8) = v40;
v42 = *(double *)(v26 + v37);
v43 = *(double *)(v26 + 8 * v35 - 8);
v44 = v43 + v42;
v45 = v43 - v42;
*(double *)(v26 + 8 * v35 - 8) = v44;
v46 = *(double *)(v33 + v37);
v47 = *(double *)(v33 + 8 * v35 - 8);
v48 = v47 + v46;
v49 = v47 - v46;
*(double *)(v33 + 8 * v35 - 8) = v48;
v50 = *(double *)(v27 + v37);
v51 = *(double *)(v27 + 8 * v35 - 8);
v52 = v51 + v50;
v53 = v51 - v50;
v54 = v41;
*(double *)(v27 + 8 * v35 - 8) = v52;
v55 = v45;
v56 = v45 + v49;
v35 += v34;
v57 = v55 - v49;
v58 = v41 + v53;
v59 = v54 - v53;
*(double *)(v31 + v37) = v29 * v58 - v24 * v57;
*(double *)(v33 + v37) = -v57 * v29 - v58 * v24;
*(double *)(v26 + v37) = v28 * v59 + v22 * v56;
*(double *)(v27 + v37) = v56 * v28 - v59 * v22;
v37 += 8LL * v34;
}
while ( v32 > (int)v35 );
v60 = v23 + 2 * v34;
v34 *= 4;
LODWORD(v35) = v60 - v19;
}
while ( v32 > (int)v35 );
}
if ( v85 < ++v23 )
break;
v82 = v19;
sincos(v36, sinx, &cosx);
v80 = cosx;
v79 = sinx[0];
sincos(3.0 * v36, sinx, &cosx);
v28 = cosx;
v24 = v79;
v22 = sinx[0];
v29 = v80;
v19 = v82;
}
v61 = v33;
v16 = v32;
a1 = v31;
a2 = v61;
}
++v88;
}
while ( v86 > v88 );
i = v16;
goto LABEL_25;
}
if ( a3 != 2 )
{
v87 = 4;
i = 2;
v86 = 1;
goto LABEL_6;
}
i = 2;
LABEL_26:
v62 = 4;
LODWORD(v63) = 1;
do
{
v63 = (int)v63;
do
{
v64 = *(double *)(a1 + 8 * v63 - 8);
v65 = *(double *)(a1 + 8 * v63) + v64;
v66 = v64 - *(double *)(a1 + 8 * v63);
*(double *)(a1 + 8 * v63 - 8) = v65;
*(double *)(a1 + 8 * v63) = v66;
v67 = *(double *)(a2 + 8 * v63 - 8);
v68 = *(double *)(a2 + 8 * v63) + v67;
v69 = v67 - *(double *)(a2 + 8 * v63);
*(double *)(a2 + 8 * v63 - 8) = v68;
*(double *)(a2 + 8 * v63) = v69;
v63 += v62;
}
while ( i >= (int)v63 );
LODWORD(v63) = 2 * v62 - 1;
v62 *= 4;
}
while ( (int)v63 < i );
v70 = 1LL;
v71 = 1;
do
{
if ( v71 > (int)v70 )
{
v72 = 8LL * v71 - 8;
v73 = (__int64 *)(a1 + v72);
v74 = (__int64 *)(a2 + v72);
v75 = *v73;
*v73 = *(_QWORD *)(a1 + 8 * v70 - 8);
*(_QWORD *)(a1 + 8 * v70 - 8) = v75;
v76 = *v74;
*v74 = *(_QWORD *)(a2 + 8 * v70 - 8);
*(_QWORD *)(a2 + 8 * v70 - 8) = v76;
}
for ( j = i >> 1; v71 > j; j >>= 1 )
v71 -= j;
++v70;
v71 += j;
}
while ( i != v70 );
return (unsigned int)i;
}

canonical_original_code:
int dfft(double x[], double y[], int np)
{
double *px; double *py;
int i; int j; int k; int m; int n; int i0; int i1; int i2; int i3; int is; int id; int n1; int n2; int n4;
double a; double e; double a3; double cc1; double ss1; double cc3; double ss3; double r1; double r2; double s1; double s2; double s3; double xt; double tpi;
  px = x - 1;
  py = y - 1;
  i = 2;
  m = 1;
  while (i < np)
  {
  i = i+i;
  m = m+1;
  }
  n = i;
  if (n != np)
  {
     for (i = np+1; i <= n; i++)
     {
     px[i] = 0.0;
     py[i] = 0.0;
     }
     printf("\nuse %d point fft",n);
  }
  n2 = n+n;
  tpi = 2.0 * 3.14159265358979323846;
  for (k = 1; k <= m-1; k++ )
  {
    n2 = n2 / 2;
    n4 = n2 / 4;
    e = tpi / (double)n2;
    a = 0.0;
    for (j = 1; j<= n4 ; j++)
    {
 a3 = 3.0 * a;
 cc1 = cos(a);
 ss1 = sin(a);
 cc3 = cos(a3);
 ss3 = sin(a3);
 a = e * (double)j;
 is = j;
 id = 2 * n2;
   while ( is < n )
   {
      for (i0 = is; i0 <= n-1; i0 = i0 + id)
      {
      i1 = i0 + n4;
      i2 = i1 + n4;
      i3 = i2 + n4;
      r1 = px[i0] - px[i2];
      px[i0] = px[i0] + px[i2];
      r2 = px[i1] - px[i3];
      px[i1] = px[i1] + px[i3];
      s1 = py[i0] - py[i2];
      py[i0] = py[i0] + py[i2];
      s2 = py[i1] - py[i3];
      py[i1] = py[i1] + py[i3];
      s3 = r1 - s2; r1 = r1 + s2;
      s2 = r2 - s1; r2 = r2 + s1;
      px[i2] = r1*cc1 - s2*ss1;
      py[i2] = -s2*cc1 - r1*ss1;
      px[i3] = s3*cc3 + r2*ss3;
      py[i3] = r2*cc3 - s3*ss3;
      }
   is = 2 * id - n2 + j;
   id = 4 * id;
   }
    }
  }
  is = 1;
  id = 4;
  while ( is < n)
  {
     for (i0 = is; i0 <= n; i0 = i0 + id)
     {
 i1 = i0 + 1;
 r1 = px[i0];
 px[i0] = r1 + px[i1];
 px[i1] = r1 - px[i1];
 r1 = py[i0];
 py[i0] = r1 + py[i1];
 py[i1] = r1 - py[i1];
     }
  is = 2*id - 1;
  id = 4 * id;
  }
  j = 1;
  n1 = n - 1;
  for (i = 1; i <= n1; i++)
  {
    if (i < j)
    {
    xt = px[j];
    px[j] = px[i];
    px[i] = xt;
    xt = py[j];
    py[j] = py[i];
    py[i] = xt;
    }
    k = n / 2;
    while (k < j)
    {
    j = j - k;
    k = k / 2;
    }
    j = j + k;
  }
  return(n);
}

variable_types:
x
double []

variable_types:
y
double []

variable_types: np int

variable_types:
px
double *

variable_types:
py
double *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: m int

variable_types: n int

variable_types: is int

variable_types: id int

variable_types: a double

variable_types: e double

variable_types: xt double

variable_types: tpi double


main

canonical_name: main

repo: dagit/Cyclone-Language

original_code:
int main(int argc, char* argv[])
{
int i,j,np,npm,lp,n2,kr,ki;
double *pxr,*pxi;
double a,enp,t,y,zr,zi,zm;
np = 8;
pxr = xr;
pxi = xi;
 printf("\nFFT benchmark - Double Precision - V1.0 -  05 Jan 1993\n\n");
 printf("FFT size   max error\n");
 for (lp = 1; lp <= 15; lp++ )
 {
   np = np * 2;
   printf(" %7d ",np);
   enp = np;
   npm = np / 2 - 1;
   t = 3.14159265358979323846 / enp;
   pxr[0] = (enp - 1.0) * 0.5;
   pxi[0] = 0.0;
   n2 = np / 2;
   pxr[n2] = -0.5;
   pxi[n2] = 0.0;
   for (i = 1; i <= npm; i++)
   {
  j = np - i;
  pxr[i] = -0.5;
  pxr[j] = -0.5;
  y = t * (double)i;
  y = -0.5*(cos(y)/sin(y));
  pxi[i] = y;
  pxi[j] = -y;
   }
   dfft(xr,xi,np);
   zr = 0.0;
   zi = 0.0;
   kr = 0;
   ki = 0;
   npm = np-1;
   for (i = 0; i <= npm; i++ )
   {
  a = fabs( xr[i] - i );
  if (zr < a)
  {
   zr = a;
   kr = i;
  }
  a = fabs(xi[i]);
  if (zi < a)
  {
   zi = a;
   ki = i;
  }
   }
   zm = zr;
   if ( fabs(zr) < fabs(zi) ) zm = zi;
   printf(" %10.2g\n",zm);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
int i; int j; int np; int npm; int lp; int n2; int kr; int ki;
double *pxr; double *pxi;
double a; double enp; double t; double y; double zr; double zi; double zm;
np = 8;
pxr = xr;
pxi = xi;
 printf("\nFFT benchmark - Double Precision - V1.0 -  05 Jan 1993\n\n");
 printf("FFT size   max error\n");
 for (lp = 1; lp <= 15; lp++ )
 {
   np = np * 2;
   printf(" %7d ",np);
   enp = np;
   npm = np / 2 - 1;
   t = 3.14159265358979323846 / enp;
   pxr[0] = (enp - 1.0) * 0.5;
   pxi[0] = 0.0;
   n2 = np / 2;
   pxr[n2] = -0.5;
   pxi[n2] = 0.0;
   for (i = 1; i <= npm; i++)
   {
  j = np - i;
  pxr[i] = -0.5;
  pxr[j] = -0.5;
  y = t * (double)i;
  y = -0.5*(cos(y)/sin(y));
  pxi[i] = y;
  pxi[j] = -y;
   }
   dfft(xr,xi,np);
   zr = 0.0;
   zi = 0.0;
   kr = 0;
   ki = 0;
   npm = np-1;
   for (i = 0; i <= npm; i++ )
   {
  a = fabs( xr[i] - i );
  if (zr < a)
  {
   zr = a;
   kr = i;
  }
  a = fabs(xi[i]);
  if (zi < a)
  {
   zi = a;
   ki = i;
  }
   }
   zm = zr;
   if ( fabs(zr) < fabs(zi) ) zm = zi;
   printf(" %10.2g\n",zm);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: npm int

variable_types: lp int

variable_types: kr int

variable_types: ki int

variable_types:
pxr
double *

variable_types:
pxi
double *

variable_types: enp double

variable_types: t double

variable_types: y double

variable_types: zr double

variable_types: zi double

variable_types: zm double

return_type: int


original_code:
int decode_symbol()
{
    int pContext;
    int symbol;
    startContext();
    pContext = predict();
    symbol = decode_context( pContext );
    Input [inputPos] = symbol;
    update( symbol );
    if (debugLevel > 2)
        dumpRoot( stderr );
    return( symbol );
}

variable_types: pContext int

variable_types: symbol int


SIEVE

original_code:
void SIEVE(long m,long n,long p)
{
char *flags;
long i,prime = -1,k,ci;
long count,size;
long iter,j;
char *ptr;
size = m - 1;
ptr = malloc(m);
   ErrorFlag = 0L;
   N_Prime = 0L;
   L_Prime = 0L;
   if( !ptr )
     {
     ErrorFlag = 2L;
     return;
     }
   flags = ptr;
   j = 0;
   for(iter=1 ; iter<=n ; iter++)
   {
   count = 0;
   for(i=0 ; i<=size ; i++)
   {
   *(flags+i) = 1;
   }
   ci = 0;
     for(i=0 ; i<=size ; i++)
     {
 if(*(flags+i))
 {
 count++;
 prime = i + i + 3;
 for(k = i + prime ; k<=size ; k+=prime)
 {
 ci++;
 *(flags+k)=0;
 }
 }
     }
   j = j + count;
   }
   free(ptr);
   N_Prime = j / n;
   L_Prime = prime;
   if ( p != 0L )
   {
   printf("  %9ld   %8ld     %8ld\n",m,N_Prime,L_Prime);
   }
}

canonical_original_code:
void SIEVE(long m, long n, long p)
{
char *flags;
long i; long prime = -1; long k; long ci;
long count; long size;
long iter; long j;
char *ptr;
size = m - 1;
ptr = malloc(m);
   ErrorFlag = 0L;
   N_Prime = 0L;
   L_Prime = 0L;
   if( !ptr )
     {
     ErrorFlag = 2L;
     return;
     }
   flags = ptr;
   j = 0;
   for(iter=1 ; iter<=n ; iter++)
   {
   count = 0;
   for(i=0 ; i<=size ; i++)
   {
   *(flags+i) = 1;
   }
   ci = 0;
     for(i=0 ; i<=size ; i++)
     {
 if(*(flags+i))
 {
 count++;
 prime = i + i + 3;
 for(k = i + prime ; k<=size ; k+=prime)
 {
 ci++;
 *(flags+k)=0;
 }
 }
     }
   j = j + count;
   }
   free(ptr);
   N_Prime = j / n;
   L_Prime = prime;
   if ( p != 0L )
   {
   printf("  %9ld   %8ld     %8ld\n",m,N_Prime,L_Prime);
   }
}

variable_types: m long

variable_types: n long

variable_types: p long

variable_types:
flags
char *

variable_types: i long

variable_types: prime long

variable_types: k long

variable_types: ci long

variable_types: count long

variable_types: size long

variable_types: iter long

variable_types: j long

variable_types:
ptr
char *

return_type: void


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
size_t v4; // rbp
__int64 v5; // rbx

if ( argc > 1 )
LIMIT = atoi(argv[1]);
puts("\n Sieve of Eratosthenes (Scaled to 10 Iterations)");
puts(" Version 1.2b, 26 Sep 1992\n");
puts(" Array Size Number Last Prime");
puts(" (Bytes) of Primes");
Number_Of_Primes[0] = 1899LL;
qword_404148 = 2261LL;
qword_404150 = 4202LL;
qword_404158 = 7836LL;
qword_404160 = 14683LL;
qword_404168 = 27607LL;
qword_404170 = 52073LL;
qword_404178 = 98609LL;
qword_404180 = 187133LL;
qword_404188 = 356243LL;
qword_404190 = 679460LL;
qword_404198 = 1299068LL;
qword_4041A0 = 2488465LL;
qword_4041A8 = 4774994LL;
qword_4041B0 = 0LL;
qword_4041B8 = 0LL;
SIEVE(0x1FFFuLL);
for ( i = 1LL; i != 21; ++i )
NLoops[i] = 1LL;
NLoops[0] = 2048LL;
qword_404088 = 2048LL;
qword_404090 = 1024LL;
qword_404098 = 512LL;
qword_4040A0 = 256LL;
qword_4040A8 = 128LL;
qword_4040B0 = 64LL;
qword_4040B8 = 32LL;
qword_4040C0 = 16LL;
qword_4040C8 = 8LL;
qword_4040D0 = 4LL;
qword_4040D8 = 2LL;
SIEVE(0x1FFFuLL);
ErrorFlag = 0LL;
if ( LIMIT <= 0 )
return 0;
v4 = 5000LL;
v5 = 1LL;
while ( 1 )
{
v4 *= 2LL;
SIEVE(v4);
if ( ErrorFlag )
break;
if ( Number_Of_Primes[v5] != N_Prime )
{
printf("\n Error --- Incorrect Number of Primes for Array: %ld\n", v4);
printf(" Number of Primes Found is: %ld\n", N_Prime);
printf(" Correct Number of Primes is: %ld\n", Number_Of_Primes[v5]);
ErrorFlag = 1LL;
return 0;
}
LABEL_12:
if ( LIMIT < ++v5 )
return 0;
}
if ( ErrorFlag <= 0 )
goto LABEL_12;
if ( ErrorFlag != 2 )
return 0;
printf("\n Could Not Allocate Memory for Array Size: %ld\n", v4);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
size_t v4; // rbp
__int64 v5; // rbx

if ( argc > 1 )
LIMIT = atoi(argv[1]);
puts("\n Sieve of Eratosthenes (Scaled to 10 Iterations)");
puts(" Version 1.2b, 26 Sep 1992\n");
puts(" Array Size Number Last Prime");
puts(" (Bytes) of Primes");
Number_Of_Primes[0] = 1899LL;
qword_404148 = 2261LL;
qword_404150 = 4202LL;
qword_404158 = 7836LL;
qword_404160 = 14683LL;
qword_404168 = 27607LL;
qword_404170 = 52073LL;
qword_404178 = 98609LL;
qword_404180 = 187133LL;
qword_404188 = 356243LL;
qword_404190 = 679460LL;
qword_404198 = 1299068LL;
qword_4041A0 = 2488465LL;
qword_4041A8 = 4774994LL;
qword_4041B0 = 0LL;
qword_4041B8 = 0LL;
func7(0x1FFFuLL);
for ( i = 1LL; i != 21; ++i )
NLoops[i] = 1LL;
NLoops[0] = 2048LL;
qword_404088 = 2048LL;
qword_404090 = 1024LL;
qword_404098 = 512LL;
qword_4040A0 = 256LL;
qword_4040A8 = 128LL;
qword_4040B0 = 64LL;
qword_4040B8 = 32LL;
qword_4040C0 = 16LL;
qword_4040C8 = 8LL;
qword_4040D0 = 4LL;
qword_4040D8 = 2LL;
func7(0x1FFFuLL);
ErrorFlag = 0LL;
if ( LIMIT <= 0 )
return 0;
v4 = 5000LL;
v5 = 1LL;
while ( 1 )
{
v4 *= 2LL;
func7(v4);
if ( ErrorFlag )
break;
if ( Number_Of_Primes[v5] != N_Prime )
{
printf("\n Error --- Incorrect Number of Primes for Array: %ld\n", v4);
printf(" Number of Primes Found is: %ld\n", N_Prime);
printf(" Correct Number of Primes is: %ld\n", Number_Of_Primes[v5]);
ErrorFlag = 1LL;
return 0;
}
LABEL_12:
if ( LIMIT < ++v5 )
return 0;
}
if ( ErrorFlag <= 0 )
goto LABEL_12;
if ( ErrorFlag != 2 )
return 0;
printf("\n Could Not Allocate Memory for Array Size: %ld\n", v4);
return -1;
}

original_code:
int main(int argc, char* argv[])
{
long i,j,k,p;
if(argc > 1)
  LIMIT = atoi(argv[1]);
printf("\n   Sieve of Eratosthenes (Scaled to 10 Iterations)\n");
printf("   Version 1.2b, 26 Sep 1992\n\n");
printf("   Array Size   Number   Last Prime\n");
printf("    (Bytes)   of Primes\n");
Number_Of_Primes[0] = 1899;
Number_Of_Primes[1] = 2261;
Number_Of_Primes[2] = 4202;
Number_Of_Primes[3] = 7836;
Number_Of_Primes[4] = 14683;
Number_Of_Primes[5] = 27607;
Number_Of_Primes[6] = 52073;
Number_Of_Primes[7] = 98609;
Number_Of_Primes[8] = 187133;
Number_Of_Primes[9] = 356243;
Number_Of_Primes[10]= 679460;
Number_Of_Primes[11]= 1299068;
Number_Of_Primes[12]= 2488465;
Number_Of_Primes[13]= 4774994;
Number_Of_Primes[14]= 0;
Number_Of_Primes[15]= 0;
j = 8191;
k = 256;
p = 0;
SIEVE(j,k,p);
for( i=1 ; i<= 20 ; i++)
{
 NLoops[i] = 1;
}
p = 8;
NLoops[0] = 256 * p;
NLoops[1] = 256 * p;
NLoops[2] = 128 * p;
NLoops[3] = 64 * p;
NLoops[4] = 32 * p;
NLoops[5] = 16 * p;
NLoops[6] = 8 * p;
NLoops[7] = 4 * p;
NLoops[8] = 2 * p;
NLoops[9] = p;
NLoops[10] = p / 2;
NLoops[11] = p / 4;
i = 0;
j = 8191;
k = NLoops[0];
SIEVE(j,k,p);
j = 5000;
ErrorFlag = 0;
for( i=1 ; i<= LIMIT ; i++)
{
   j = 2 * j;
   k = NLoops[i];
   SIEVE(j,k,p);
   if( ErrorFlag == 0L )
   {
   if( N_Prime != Number_Of_Primes[i] )
   {
   printf("\n   Error --- Incorrect Number of Primes for Array: %ld\n",j);
   printf("   Number of  Primes  Found is: %ld\n",N_Prime);
   printf("   Correct Number of Primes is: %ld\n",Number_Of_Primes[i]);
   ErrorFlag = 1L;
   }
   }
   if( ErrorFlag > 0L ) break;
}
if( ErrorFlag == 2L )
{
printf("\n   Could Not Allocate Memory for Array Size: %ld\n",j);
return(-1);
}
return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
long i; long j; long k; long p;
if(argc > 1)
  LIMIT = atoi(argv[1]);
printf("\n   Sieve of Eratosthenes (Scaled to 10 Iterations)\n");
printf("   Version 1.2b, 26 Sep 1992\n\n");
printf("   Array Size   Number   Last Prime\n");
printf("    (Bytes)   of Primes\n");
Number_Of_Primes[0] = 1899;
Number_Of_Primes[1] = 2261;
Number_Of_Primes[2] = 4202;
Number_Of_Primes[3] = 7836;
Number_Of_Primes[4] = 14683;
Number_Of_Primes[5] = 27607;
Number_Of_Primes[6] = 52073;
Number_Of_Primes[7] = 98609;
Number_Of_Primes[8] = 187133;
Number_Of_Primes[9] = 356243;
Number_Of_Primes[10]= 679460;
Number_Of_Primes[11]= 1299068;
Number_Of_Primes[12]= 2488465;
Number_Of_Primes[13]= 4774994;
Number_Of_Primes[14]= 0;
Number_Of_Primes[15]= 0;
j = 8191;
k = 256;
p = 0;
SIEVE(j,k,p);
for( i=1 ; i<= 20 ; i++)
{
 NLoops[i] = 1;
}
p = 8;
NLoops[0] = 256 * p;
NLoops[1] = 256 * p;
NLoops[2] = 128 * p;
NLoops[3] = 64 * p;
NLoops[4] = 32 * p;
NLoops[5] = 16 * p;
NLoops[6] = 8 * p;
NLoops[7] = 4 * p;
NLoops[8] = 2 * p;
NLoops[9] = p;
NLoops[10] = p / 2;
NLoops[11] = p / 4;
i = 0;
j = 8191;
k = NLoops[0];
SIEVE(j,k,p);
j = 5000;
ErrorFlag = 0;
for( i=1 ; i<= LIMIT ; i++)
{
   j = 2 * j;
   k = NLoops[i];
   SIEVE(j,k,p);
   if( ErrorFlag == 0L )
   {
   if( N_Prime != Number_Of_Primes[i] )
   {
   printf("\n   Error --- Incorrect Number of Primes for Array: %ld\n",j);
   printf("   Number of  Primes  Found is: %ld\n",N_Prime);
   printf("   Correct Number of Primes is: %ld\n",Number_Of_Primes[i]);
   ErrorFlag = 1L;
   }
   }
   if( ErrorFlag > 0L ) break;
}
if( ErrorFlag == 2L )
{
printf("\n   Could Not Allocate Memory for Array Size: %ld\n",j);
return(-1);
}
return(0);
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void start_inputing_bits()
{
bits_to_go = 0;
}

canonical_decompiled_code:
void func0()
{
bits_to_go = 0;
}


decompiled_code:
__int64 input_bit()
{
__int64 result; // rax
int v1; // eax
int v2; // edx

if ( --bits_to_go < 0 )
{
v1 = getc(stdin);
bits_to_go = 7;
v2 = v1;
result = v1 & 1;
buffer = v2 >> 1;
}
else
{
result = buffer & 1;
buffer >>= 1;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // eax
int v2; // edx

if ( --bits_to_go < 0 )
{
v1 = getc(stdin);
bits_to_go = 7;
v2 = v1;
result = v1 & 1;
buffer = v2 >> 1;
}
else
{
result = buffer & 1;
buffer >>= 1;
}
return result;
}

original_code:
int input_bit()
{
  int t;
  bits_to_go -= 1;
  if (bits_to_go<0) {
    buffer = getc(stdin);
    bits_to_go = 7;
  }
  t = buffer&1;
  buffer >>= 1;
  return t;
}

variable_types: t int


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

region_init();
banshee_ptr_region = newregion();
banshee_nonptr_region = newregion();
result = make_hash_table(permanent, 32LL, &ptr_hash, &ptr_eq);
extra_regions = result;
return result;
}

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

region_init();
banshee_ptr_region = newregion();
banshee_nonptr_region = newregion();
result = make_hash_table(permanent, 32LL, &ptr_hash, &ptr_eq);
extra_regions = result;
return result;
}

original_code:
void banshee_region_persistence_init()
{
  region_init();
  banshee_ptr_region = newregion();
  banshee_nonptr_region = newregion();
  extra_regions = make_hash_table(permanent, 32, ptr_hash, ptr_eq);
}


Ack

decompiled_code:
__int64 __fastcall Ack(unsigned int a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // ebx
unsigned int v4; // eax

result = (unsigned int)(a2 + 1);
if ( a1 )
{
while ( 1 )
{
v3 = a1 - 1;
if ( (_DWORD)a2 )
{
a2 = (unsigned int)(a2 - 1);
v3 = a1;
}
else if ( a1 == 1 )
{
return 2LL;
}
v4 = Ack(v3, a2);
a2 = v4;
a1 = v3 - 1;
if ( v3 == 1 )
return v4 + 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // ebx
unsigned int v4; // eax

result = (unsigned int)(a2 + 1);
if ( a1 )
{
while ( 1 )
{
v3 = a1 - 1;
if ( (_DWORD)a2 )
{
a2 = (unsigned int)(a2 - 1);
v3 = a1;
}
else if ( a1 == 1 )
{
return 2LL;
}
v4 = func7(v3, a2);
a2 = v4;
a1 = v3 - 1;
if ( v3 == 1 )
return v4 + 1;
}
}
return result;
}

original_code: int Ack(int M, int N) { return(M ? (Ack(M-1,N ? Ack(M,(N-1)) : 1)) : N+1); }

variable_types: M int

variable_types: N int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
__time_t v5; // rdx
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v3 = 1;
if ( argc == 2 )
v3 = atoi(argv[1]);
v7.tv_sec = 0LL;
v7.tv_usec = 0LL;
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
gettimeofday(&v7, 0LL);
v4 = Ack(3LL, v3);
printf("Ack(3,%d): %d\n", v3, v4);
gettimeofday(&tv, 0LL);
v5 = tv.tv_sec - v7.tv_sec;
v7.tv_sec = tv.tv_sec - v7.tv_sec;
if ( tv.tv_usec - v7.tv_usec < 0 )
{
v7.tv_usec = tv.tv_usec - v7.tv_usec + 1000000;
v7.tv_sec = v5 - 1;
}
else
{
v7.tv_usec = tv.tv_usec - v7.tv_usec;
}
fprintf(stderr, "%d.%06d\n", v7.tv_sec, v7.tv_usec);
fflush(stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
__time_t v5; // rdx
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v3 = 1;
if ( argc == 2 )
v3 = atoi(argv[1]);
v7.tv_sec = 0LL;
v7.tv_usec = 0LL;
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
gettimeofday(&v7, 0LL);
v4 = func7(3LL, v3);
printf("Ack(3,%d): %d\n", v3, v4);
gettimeofday(&tv, 0LL);
v5 = tv.tv_sec - v7.tv_sec;
v7.tv_sec = tv.tv_sec - v7.tv_sec;
if ( tv.tv_usec - v7.tv_usec < 0 )
{
v7.tv_usec = tv.tv_usec - v7.tv_usec + 1000000;
v7.tv_sec = v5 - 1;
}
else
{
v7.tv_usec = tv.tv_usec - v7.tv_usec;
}
fprintf(stderr, "%d.%06d\n", v7.tv_sec, v7.tv_usec);
fflush(stderr);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    int n = ((argc == 2) ? atoi(argv[1]) : 1);
    { struct timeval __start = { 0, 0 }; struct timeval __end = { 0, 0 }; gettimeofday(&__start,((void *)0));
    printf("Ack(3,%d): %d\n", n, Ack(3, n));
    gettimeofday(&__end,((void *)0)); __start.tv_sec = __end.tv_sec - __start.tv_sec; __start.tv_usec = __end.tv_usec - __start.tv_usec; if(__start.tv_usec < 0) { __start.tv_usec += 1000000; __start.tv_sec --; } fprintf(stderr, "%d.%06d\n",__start.tv_sec, __start.tv_usec); fflush(stderr); }
    return(0);
}

variable_types: n int

variable_types: struct timeval { long tv_sec; long tv_usec; }


kmedian

original_code:
void kmedian(double *a, int n, int k)
{
 while (1){
  int j=random()%n;
  double b = a[j];
  int i=0;
         j = n-1;
         while(1) {
             while( a[i]<b ) i++;
             while( a[j]>b ) j--;
             if(i<j) {
                 double tmp=a[i];
                 a[i]=a[j];
                 a[j]=tmp;
                 i++;
                 j--;
             } else {
                 if(a[j]<b) j++;
                 if(a[i]>b) i--;
   break;
             }
         }
  if(i<k) {
   k-=i+1;
   n-=i+1;
   a+=i+1;
  } else if (j>k) {
   n=j;
  } else return;
 }
}

canonical_original_code:
void kmedian(double *a, int n, int k)
{
 while (1){
  int j = random()%n;
  double b = a[j];
  int i = 0;
         j = n-1;
         while(1) {
             while( a[i]<b ) i++;
             while( a[j]>b ) j--;
             if(i<j) {
                 double tmp = a[i];
                 a[i]=a[j];
                 a[j]=tmp;
                 i++;
                 j--;
             } else {
                 if(a[j]<b) j++;
                 if(a[i]>b) i--;
   break;
             }
         }
  if(i<k) {
   k-=i+1;
   n-=i+1;
   a+=i+1;
  } else if (j>k) {
   n=j;
  } else return;
 }
}

variable_types:
a
double *

variable_types: k int

variable_types: j int

variable_types: b double

variable_types: i int

variable_types: tmp double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
__int64 v4; // rbx
double *v5; // r12
char v6; // r14
int v7; // ebp
double v8; // xmm0_8
double v9; // xmm4_8
double v10; // xmm3_8
double v11; // xmm2_8
double *v12; // rax
__int64 v13; // rcx
double v14; // xmm6_8
double v15; // xmm1_8
double v16; // xmm7_8
int v17; // ebx
double v18; // xmm2_8
double v19; // xmm0_8
double v20; // xmm11_8
double v21; // xmm11_8
double v22; // xmm12_8
double v23; // xmm13_8
double v24; // xmm13_8
double v25; // xmm15_8
double v26; // xmm11_8
double v27; // xmm15_8
double v28; // xmm11_8
double v29; // xmm15_8
double v30; // xmm7_8
double v31; // xmm8_8
double v32; // xmm1_8
double v33; // xmm9_8
double v34; // xmm11_8
double v35; // xmm2_8
double v36; // xmm10_8
double v37; // xmm14_8
double v38; // xmm1_8
double v39; // xmm11_8
double v40; // xmm2_8
double v41; // xmm13_8
double v42; // xmm1_8
double v43; // rbx
__int64 v44; // rdx
__int64 v45; // rcx
double v46; // xmm9_8
double *v47; // r9
double v48; // xmm0_8
__time_t v49; // r10
double v51; // xmm4_8
double v52; // xmm0_8
double *v53; // r9
double v54; // xmm0_8
double v55; // [rsp+0h] [rbp-F8h]
double v56; // [rsp+0h] [rbp-F8h]
double v57; // [rsp+10h] [rbp-E8h]
struct timeval tv; // [rsp+30h] [rbp-C8h] BYREF
struct timeval v59; // [rsp+40h] [rbp-B8h] BYREF
char s[168]; // [rsp+50h] [rbp-A8h] BYREF

v3 = 4096;
v4 = 0LL;
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v59.tv_sec = 0LL;
v59.tv_usec = 0LL;
gettimeofday(&tv, 0LL);
v55 = 0.0;
v5 = (double *)malloc(0x8000uLL);
while ( 1 )
{
v6 = v4;
v7 = v4;
if ( !fgets(s, 128, _bss_start) )
break;
v8 = atof(s);
v5[v4] = v8;
v55 = v8 + v55;
if ( (_DWORD)v4 + 1 == v3 )
{
v3 *= 2;
v5 = (double *)realloc(v5, 8LL * v3);
}
++v4;
}
v9 = (double)(int)v4;
v10 = v55 / (double)(int)v4;
if ( (_DWORD)v4 )
{
v11 = 0.0;
v12 = v5;
v13 = (__int64)&v5[(unsigned int)(v4 - 1) + 1];
v14 = 0.0;
v15 = 0.0;
v16 = 0.0;
v17 = v4 & 3;
if ( !v17 )
goto LABEL_29;
if ( v17 != 1LL )
{
if ( v17 != 2LL )
{
v12 = v5 + 1;
v18 = *v5 - v10;
v16 = fabs(v18) + 0.0;
v19 = v18 * (v18 * v18);
v15 = v18 * v18 + 0.0;
v14 = v19 + 0.0;
v11 = v18 * v19 + 0.0;
}
v20 = *v12++;
v21 = v20 - v10;
v16 = v16 + fabs(v21);
v22 = v21 * (v21 * v21);
v15 = v15 + v21 * v21;
v14 = v14 + v22;
v11 = v11 + v21 * v22;
}
v23 = *v12++;
v24 = v23 - v10;
v16 = v16 + fabs(v24);
v25 = v24 * (v24 * v24);
v15 = v15 + v24 * v24;
v14 = v14 + v25;
v11 = v11 + v24 * v25;
if ( (double *)v13 != v12 )
{
LABEL_29:
do
{
v26 = *v12;
v27 = v12[2];
v12 += 4;
v28 = v26 - v10;
v29 = v27 - v10;
v30 = v16 + COERCE_DOUBLE(*(_QWORD *)&v28 & 0x7FFFFFFFFFFFFFFFLL);
v31 = v28 * (v28 * v28);
v32 = v15 + v28 * v28;
v33 = v29 * (v29 * v29);
v34 = v28 * v31 + v11;
v35 = *(v12 - 3) - v10;
v36 = fabs(v35);
v37 = v35 * (v35 * v35);
v38 = v32 + v35 * v35 + v29 * v29;
v39 = v34 + v35 * v37;
v40 = *(v12 - 1) - v10;
v16 = v30 + v36 + COERCE_DOUBLE(*(_QWORD *)&v29 & 0x7FFFFFFFFFFFFFFFLL) + fabs(v40);
v41 = v40 * (v40 * v40);
v15 = v38 + v40 * v40;
v14 = v14 + v31 + v37 + v33 + v41;
v11 = v40 * v41 + v39 + v29 * v33;
}
while ( (double *)v13 != v12 );
}
}
else
{
v11 = 0.0;
v14 = 0.0;
v15 = 0.0;
v16 = 0.0;
}
v42 = v15 / (double)(v7 - 1);
v43 = v16 / v9;
if ( v42 < 0.0 )
{
v57 = v9;
v54 = sqrt(v42);
v9 = v57;
v56 = v54;
}
else
{
v56 = sqrt(v42);
}
if ( v42 != 0.0 )
{
v51 = v9 * v42;
v14 = v14 / (v56 * v51);
v11 = v11 / (v51 * v42) - 3.0;
}
kmedian(v5, (unsigned int)v7, (unsigned int)(v7 >> 1));
v46 = v10;
v47 = &v5[v7 >> 1];
if ( (v6 & 1) != 0 )
{
v48 = *v47;
}
else
{
v52 = max(v5, (unsigned int)(v7 >> 1), v44, v45, v7 >> 1, v47);
v48 = (v52 + *v53) * 0.5;
v46 = v10;
}
free(v5);
printf("n: %d\n", (unsigned int)v7);
printf("median: %f\n", v48);
printf("mean: %f\n", v46);
printf("average_deviation: %f\n", v43);
printf("standard_deviation: %f\n", v56);
printf("variance: %f\n", v42);
printf("skew: %f\n", v14);
printf("kurtosis: %f\n", v11);
gettimeofday(&v59, 0LL);
v49 = v59.tv_sec - tv.tv_sec;
tv.tv_sec = v59.tv_sec - tv.tv_sec;
if ( v59.tv_usec - tv.tv_usec < 0 )
{
tv.tv_usec = v59.tv_usec - tv.tv_usec + 1000000;
tv.tv_sec = v49 - 1;
}
else
{
tv.tv_usec = v59.tv_usec - tv.tv_usec;
}
fprintf(stderr, "%d.%06d\n", tv.tv_sec, tv.tv_usec);
fflush(stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
__int64 v4; // rbx
double *v5; // r12
char v6; // r14
int v7; // ebp
double v8; // xmm0_8
double v9; // xmm4_8
double v10; // xmm3_8
double v11; // xmm2_8
double *v12; // rax
__int64 v13; // rcx
double v14; // xmm6_8
double v15; // xmm1_8
double v16; // xmm7_8
int v17; // ebx
double v18; // xmm2_8
double v19; // xmm0_8
double v20; // xmm11_8
double v21; // xmm11_8
double v22; // xmm12_8
double v23; // xmm13_8
double v24; // xmm13_8
double v25; // xmm15_8
double v26; // xmm11_8
double v27; // xmm15_8
double v28; // xmm11_8
double v29; // xmm15_8
double v30; // xmm7_8
double v31; // xmm8_8
double v32; // xmm1_8
double v33; // xmm9_8
double v34; // xmm11_8
double v35; // xmm2_8
double v36; // xmm10_8
double v37; // xmm14_8
double v38; // xmm1_8
double v39; // xmm11_8
double v40; // xmm2_8
double v41; // xmm13_8
double v42; // xmm1_8
double v43; // rbx
__int64 v44; // rdx
__int64 v45; // rcx
double v46; // xmm9_8
double *v47; // r9
double v48; // xmm0_8
__time_t v49; // r10
double v51; // xmm4_8
double v52; // xmm0_8
double *v53; // r9
double v54; // xmm0_8
double v55; // [rsp+0h] [rbp-F8h]
double v56; // [rsp+0h] [rbp-F8h]
double v57; // [rsp+10h] [rbp-E8h]
struct timeval tv; // [rsp+30h] [rbp-C8h] BYREF
struct timeval v59; // [rsp+40h] [rbp-B8h] BYREF
char s[168]; // [rsp+50h] [rbp-A8h] BYREF

v3 = 4096;
v4 = 0LL;
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v59.tv_sec = 0LL;
v59.tv_usec = 0LL;
gettimeofday(&tv, 0LL);
v55 = 0.0;
v5 = (double *)malloc(0x8000uLL);
while ( 1 )
{
v6 = v4;
v7 = v4;
if ( !fgets(s, 128, _bss_start) )
break;
v8 = atof(s);
v5[v4] = v8;
v55 = v8 + v55;
if ( (_DWORD)v4 + 1 == v3 )
{
v3 *= 2;
v5 = (double *)realloc(v5, 8LL * v3);
}
++v4;
}
v9 = (double)(int)v4;
v10 = v55 / (double)(int)v4;
if ( (_DWORD)v4 )
{
v11 = 0.0;
v12 = v5;
v13 = (__int64)&v5[(unsigned int)(v4 - 1) + 1];
v14 = 0.0;
v15 = 0.0;
v16 = 0.0;
v17 = v4 & 3;
if ( !v17 )
goto LABEL_29;
if ( v17 != 1LL )
{
if ( v17 != 2LL )
{
v12 = v5 + 1;
v18 = *v5 - v10;
v16 = fabs(v18) + 0.0;
v19 = v18 * (v18 * v18);
v15 = v18 * v18 + 0.0;
v14 = v19 + 0.0;
v11 = v18 * v19 + 0.0;
}
v20 = *v12++;
v21 = v20 - v10;
v16 = v16 + fabs(v21);
v22 = v21 * (v21 * v21);
v15 = v15 + v21 * v21;
v14 = v14 + v22;
v11 = v11 + v21 * v22;
}
v23 = *v12++;
v24 = v23 - v10;
v16 = v16 + fabs(v24);
v25 = v24 * (v24 * v24);
v15 = v15 + v24 * v24;
v14 = v14 + v25;
v11 = v11 + v24 * v25;
if ( (double *)v13 != v12 )
{
LABEL_29:
do
{
v26 = *v12;
v27 = v12[2];
v12 += 4;
v28 = v26 - v10;
v29 = v27 - v10;
v30 = v16 + COERCE_DOUBLE(*(_QWORD *)&v28 & 0x7FFFFFFFFFFFFFFFLL);
v31 = v28 * (v28 * v28);
v32 = v15 + v28 * v28;
v33 = v29 * (v29 * v29);
v34 = v28 * v31 + v11;
v35 = *(v12 - 3) - v10;
v36 = fabs(v35);
v37 = v35 * (v35 * v35);
v38 = v32 + v35 * v35 + v29 * v29;
v39 = v34 + v35 * v37;
v40 = *(v12 - 1) - v10;
v16 = v30 + v36 + COERCE_DOUBLE(*(_QWORD *)&v29 & 0x7FFFFFFFFFFFFFFFLL) + fabs(v40);
v41 = v40 * (v40 * v40);
v15 = v38 + v40 * v40;
v14 = v14 + v31 + v37 + v33 + v41;
v11 = v40 * v41 + v39 + v29 * v33;
}
while ( (double *)v13 != v12 );
}
}
else
{
v11 = 0.0;
v14 = 0.0;
v15 = 0.0;
v16 = 0.0;
}
v42 = v15 / (double)(v7 - 1);
v43 = v16 / v9;
if ( v42 < 0.0 )
{
v57 = v9;
v54 = sqrt(v42);
v9 = v57;
v56 = v54;
}
else
{
v56 = sqrt(v42);
}
if ( v42 != 0.0 )
{
v51 = v9 * v42;
v14 = v14 / (v56 * v51);
v11 = v11 / (v51 * v42) - 3.0;
}
func7(v5, (unsigned int)v7, (unsigned int)(v7 >> 1));
v46 = v10;
v47 = &v5[v7 >> 1];
if ( (v6 & 1) != 0 )
{
v48 = *v47;
}
else
{
v52 = func8(v5, (unsigned int)(v7 >> 1), v44, v45, v7 >> 1, v47);
v48 = (v52 + *v53) * 0.5;
v46 = v10;
}
free(v5);
printf("n: %d\n", (unsigned int)v7);
printf("median: %f\n", v48);
printf("mean: %f\n", v46);
printf("average_deviation: %f\n", v43);
printf("standard_deviation: %f\n", v56);
printf("variance: %f\n", v42);
printf("skew: %f\n", v14);
printf("kurtosis: %f\n", v11);
gettimeofday(&v59, 0LL);
v49 = v59.tv_sec - tv.tv_sec;
tv.tv_sec = v59.tv_sec - tv.tv_sec;
if ( v59.tv_usec - tv.tv_usec < 0 )
{
tv.tv_usec = v59.tv_usec - tv.tv_usec + 1000000;
tv.tv_sec = v49 - 1;
}
else
{
tv.tv_usec = v59.tv_usec - tv.tv_usec;
}
fprintf(stderr, "%d.%06d\n", tv.tv_sec, tv.tv_usec);
fflush(stderr);
return 0;
}

original_code:
int
main() {
    char line[128];
    int i, n = 0, mid = 0;
    double sum = 0.0;
    double mean = 0.0;
    double average_deviation = 0.0;
    double standard_deviation = 0.0;
    double variance = 0.0;
    double skew = 0.0;
    double kurtosis = 0.0;
    double median = 0.0;
    double deviation = 0.0;
    int array_size = 4096;
    double *nums;
    { struct timeval __start = { 0, 0 }; struct timeval __end = { 0, 0 }; gettimeofday(&__start,((void *)0));
    nums = (double *)malloc(array_size * sizeof(double));
    while (fgets(line, 128, stdin)) {
 sum += (nums[n++] = atof(line));
 if (n == array_size) {
     array_size *= 2;
     nums = (double *)realloc(nums, array_size * sizeof(double));
 }
    }
    mean = sum/n;
    for (i=0; i<n; i++) {
 double dev = nums[i] - mean;
 double dev2=dev*dev;
 double dev3=dev2*dev;
 double dev4=dev3*dev;
 average_deviation += fabs(dev);
 variance += dev2 ;
 skew += dev3 ;
 kurtosis += dev4 ;
    }
    average_deviation /= n;
    variance /= (n - 1);
    standard_deviation = sqrt(variance);
    if (variance) {
 skew /= (n * variance * standard_deviation);
 kurtosis = (kurtosis/(n * variance * variance)) - 3.0;
    }
    mid = (n/2);
    kmedian(nums, n, mid);
    median = n % 2 ? nums[mid] : (nums[mid] + max(nums,mid))/2;
    free(nums);
    printf("n:                  %d\n", n);
    printf("median:             %f\n", median);
    printf("mean:               %f\n", mean);
    printf("average_deviation:  %f\n", average_deviation);
    printf("standard_deviation: %f\n", standard_deviation);
    printf("variance:           %f\n", variance);
    printf("skew:               %f\n", skew);
    printf("kurtosis:           %f\n", kurtosis);
    gettimeofday(&__end,((void *)0)); __start.tv_sec = __end.tv_sec - __start.tv_sec; __start.tv_usec = __end.tv_usec - __start.tv_usec; if(__start.tv_usec < 0) { __start.tv_usec += 1000000; __start.tv_sec --; } fprintf(stderr, "%d.%06d\n",__start.tv_sec, __start.tv_usec); fflush(stderr); }
    return(0);
}

canonical_original_code:
int main() {
    char line[128];
    int i; int n = 0; int mid = 0;
    double sum = 0.0;
    double mean = 0.0;
    double average_deviation = 0.0;
    double standard_deviation = 0.0;
    double variance = 0.0;
    double skew = 0.0;
    double kurtosis = 0.0;
    double median = 0.0;
    double deviation = 0.0;
    int array_size = 4096;
    double *nums;
    { struct timeval __start = { 0, 0 }; struct timeval __end = { 0, 0 }; gettimeofday(&__start,((void *)0));
    nums = (double *)malloc(array_size * sizeof(double));
    while (fgets(line, 128, stdin)) {
 sum += (nums[n++] = atof(line));
 if (n == array_size) {
     array_size *= 2;
     nums = (double *)realloc(nums, array_size * sizeof(double));
 }
    }
    mean = sum/n;
    for (i=0; i<n; i++) {
 double dev = nums[i] - mean;
 double dev2 = dev*dev;
 double dev3 = dev2*dev;
 double dev4 = dev3*dev;
 average_deviation += fabs(dev);
 variance += dev2 ;
 skew += dev3 ;
 kurtosis += dev4 ;
    }
    average_deviation /= n;
    variance /= (n - 1);
    standard_deviation = sqrt(variance);
    if (variance) {
 skew /= (n * variance * standard_deviation);
 kurtosis = (kurtosis/(n * variance * variance)) - 3.0;
    }
    mid = (n/2);
    kmedian(nums, n, mid);
    median = n % 2 ? nums[mid] : (nums[mid] + max(nums,mid))/2;
    free(nums);
    printf("n:                  %d\n", n);
    printf("median:             %f\n", median);
    printf("mean:               %f\n", mean);
    printf("average_deviation:  %f\n", average_deviation);
    printf("standard_deviation: %f\n", standard_deviation);
    printf("variance:           %f\n", variance);
    printf("skew:               %f\n", skew);
    printf("kurtosis:           %f\n", kurtosis);
    gettimeofday(&__end,((void *)0)); __start.tv_sec = __end.tv_sec - __start.tv_sec; __start.tv_usec = __end.tv_usec - __start.tv_usec; if(__start.tv_usec < 0) { __start.tv_usec += 1000000; __start.tv_sec --; } fprintf(stderr, "%d.%06d\n",__start.tv_sec, __start.tv_usec); fflush(stderr); }
    return(0);
}

variable_types:
line
char [128]

variable_types: mid int

variable_types: sum double

variable_types: mean double

variable_types: variance double

variable_types: skew double

variable_types: kurtosis double

variable_types: median double

variable_types: deviation double

variable_types:
nums
double *

variable_types: dev double

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


max

decompiled_code:
double __fastcall max(double *a1, int a2)
{
double result; // xmm0_8
double *v3; // rax
__int64 v4; // rcx
int v5; // esi
double v6; // xmm2_8
double v7; // xmm3_8
double v8; // xmm4_8
double v9; // xmm5_8
double v10; // xmm6_8
double v11; // xmm7_8
double v12; // xmm8_8
double v13; // xmm9_8
double v14; // xmm1_8

result = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
v4 = (__int64)&a1[(unsigned int)(a2 - 2) + 2];
v5 = ((_BYTE)a2 - 2 + 1) & 7;
if ( !v5 )
goto LABEL_19;
if ( v5 != 1LL )
{
if ( v5 != 2LL )
{
if ( v5 != 3LL )
{
if ( v5 != 4LL )
{
if ( v5 != 5LL )
{
if ( v5 != 6LL )
{
v14 = *v3;
v3 = a1 + 2;
result = fmax(v14, result);
}
v6 = *v3++;
result = fmax(v6, result);
}
v7 = *v3++;
result = fmax(v7, result);
}
v8 = *v3++;
result = fmax(v8, result);
}
v9 = *v3++;
result = fmax(v9, result);
}
v10 = *v3++;
result = fmax(v10, result);
}
v11 = *v3++;
result = fmax(v11, result);
if ( v3 != (double *)v4 )
{
LABEL_19:
do
{
v12 = *v3;
v13 = v3[2];
v3 += 8;
result = fmax(
*(v3 - 1),
fmax(
*(v3 - 2),
fmax(*(v3 - 3), fmax(*(v3 - 4), fmax(*(v3 - 5), fmax(v13, fmax(*(v3 - 7), fmax(v12, result))))))));
}
while ( v3 != (double *)v4 );
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func8(double *a1, int a2)
{
double result; // xmm0_8
double *v3; // rax
__int64 v4; // rcx
int v5; // esi
double v6; // xmm2_8
double v7; // xmm3_8
double v8; // xmm4_8
double v9; // xmm5_8
double v10; // xmm6_8
double v11; // xmm7_8
double v12; // xmm8_8
double v13; // xmm9_8
double v14; // xmm1_8

result = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
v4 = (__int64)&a1[(unsigned int)(a2 - 2) + 2];
v5 = ((_BYTE)a2 - 2 + 1) & 7;
if ( !v5 )
goto LABEL_19;
if ( v5 != 1LL )
{
if ( v5 != 2LL )
{
if ( v5 != 3LL )
{
if ( v5 != 4LL )
{
if ( v5 != 5LL )
{
if ( v5 != 6LL )
{
v14 = *v3;
v3 = a1 + 2;
result = fmax(v14, result);
}
v6 = *v3++;
result = fmax(v6, result);
}
v7 = *v3++;
result = fmax(v7, result);
}
v8 = *v3++;
result = fmax(v8, result);
}
v9 = *v3++;
result = fmax(v9, result);
}
v10 = *v3++;
result = fmax(v10, result);
}
v11 = *v3++;
result = fmax(v11, result);
if ( v3 != (double *)v4 )
{
LABEL_19:
do
{
v12 = *v3;
v13 = v3[2];
v3 += 8;
result = fmax(
*(v3 - 1),
fmax(
*(v3 - 2),
fmax(*(v3 - 3), fmax(*(v3 - 4), fmax(*(v3 - 5), fmax(v13, fmax(*(v3 - 7), fmax(v12, result))))))));
}
while ( v3 != (double *)v4 );
}
}
return result;
}

original_code:
double max(double *a, int n)
{
 int j;
 double temp=a[0];
 for(j=1;j<n;j++) {
  if(a[j]>temp) {
   temp=a[j];
  }
 }
 return temp;
}

canonical_original_code:
double max(double *a, int n)
{
 int j;
 double temp = a[0];
 for(j=1;j<n;j++) {
  if(a[j]>temp) {
   temp=a[j];
  }
 }
 return temp;
}

variable_types:
a
double *

variable_types: n int

variable_types: temp double

return_type: double


mov

decompiled_code:
__int64 __fastcall mov(unsigned int a1, int a2, int a3)
{
__int64 v3; // r13
__int64 v4; // rbp
unsigned int i; // ebx
unsigned int v6; // er12
__int64 result; // rax

v3 = a3;
LODWORD(v4) = a2;
for ( i = a1; i != 1; result = mov(1LL, v6, (unsigned int)v3) )
{
v6 = v4;
--i;
v4 = (unsigned int)(6 - (v3 + v4));
mov(i, v6, v4);
}
++count;
--num[(int)v4];
++num[v3];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2, int a3)
{
__int64 v3; // r13
__int64 v4; // rbp
unsigned int i; // ebx
unsigned int v6; // er12
__int64 result; // rax

v3 = a3;
LODWORD(v4) = a2;
for ( i = a1; i != 1; result = func7(1LL, v6, (unsigned int)v3) )
{
v6 = v4;
--i;
v4 = (unsigned int)(6 - (v3 + v4));
func7(i, v6, v4);
}
++count;
--num[(int)v4];
++num[v3];
return result;
}

original_code:
void mov(int n,int f,int t)
{
   int o;
   if(n == 1)
   {
 num[f]--;
 num[t]++;
 count++;
 return;
   }
   o = (6-(f+t));
   mov(n-1,f,o);
   mov(1,f,t);
   mov(n-1,o,t);
   return;
}

canonical_original_code:
void mov(int n, int f, int t)
{
   int o;
   if(n == 1)
   {
 num[f]--;
 num[t]++;
 count++;
 return;
   }
   o = (6-(f+t));
   mov(n-1,f,o);
   mov(1,f,t);
   mov(n-1,o,t);
   return;
}

variable_types: f int

variable_types: t int

variable_types: o int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int i; // ebx
__int64 v5; // rsi

if ( argc <= 1 )
{
v3 = 30;
puts("Disks Moves");
}
else
{
v3 = atoi(argv[1]);
puts("Disks Moves");
if ( v3 <= 0 )
return 0;
}
for ( i = 1; (int)i <= v3; ++i )
{
dword_404064 = i;
num = 0;
qword_404068 = 0LL;
count = 0LL;
mov(i, 1LL, 3LL);
v5 = i;
printf("%3d %10ld\n", v5, count);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int i; // ebx
__int64 v5; // rsi

if ( argc <= 1 )
{
v3 = 30;
puts("Disks Moves");
}
else
{
v3 = atoi(argv[1]);
puts("Disks Moves");
if ( v3 <= 0 )
return 0;
}
for ( i = 1; (int)i <= v3; ++i )
{
dword_404064 = i;
num = 0;
qword_404068 = 0LL;
count = 0LL;
func7(i, 1LL, 3LL);
v5 = i;
printf("%3d %10ld\n", v5, count);
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 int disk;
 int max = 30;
 if(argc > 1)
  max = atoi(argv[1]);
 printf("Disks     Moves\n");
 for(disk = 1; disk <= max; disk++)
 {
  num[0] = 0;
  num[1] = disk;
  num[2] = 0;
  num[3] = 0;
  count = 0;
  mov(disk,1,3);
  printf("%3d  %10ld\n",disk,count);
 }
 return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int disk;
 int max = 30;
 if(argc > 1)
  max = atoi(argv[1]);
 printf("Disks     Moves\n");
 for(disk = 1; disk <= max; disk++)
 {
  num[0] = 0;
  num[1] = disk;
  num[2] = 0;
  num[3] = 0;
  count = 0;
  mov(disk,1,3);
  printf("%3d  %10ld\n",disk,count);
 }
 return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: disk int

variable_types: max int


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

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

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

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

original_code:
void fill_array(double *array, int length, double value)
{
 int a;
 for (a = 0; a < length; a++)
  array[a] = value;
}

variable_types:
array
double *

variable_types: length int

variable_types: value double

variable_types: a int


original_code:
int main()
{
 struct bio_params *bio_info;
 bio_info = malloc(sizeof(*bio_info));
 bio_info->explicit_scheme = 0;
 bio_info->subs_inh = 1;
 bio_info->prod_inh = 1;
 bio_info->k2 = 1;
 bio_info->km = 0.01 * 1e-3;
 bio_info->ks = 0.001 * 1e-3;
 bio_info->kp = 0.001 * 1e-3;
 bio_info->dt = 1e-3;
 bio_info->n = 200;
 bio_info->resp_t_meth = MIN_TIME;
 bio_info->min_t = 200;
 bio_info->resp_t = 0;
 bio_info->out_file_name = "output.dat";
 bio_info->ne = 1;
 bio_info->s0 = 0.04 * 1e-3;
 bio_info->p0 = 0 * 1e-3;
 bio_info->layer_count = 2;
 bio_info->layers = malloc(sizeof(*(bio_info->layers)) * bio_info->layer_count);
 bio_info->layers[0].enz_layer = 1;
 bio_info->layers[0].Ds = 100 * 1e-8;
 bio_info->layers[0].Dp = 100 * 1e-8;
 bio_info->layers[0].d = 10 * 1e-4;
 bio_info->layers[0].e0 = 0.01 * 1e-3;
 bio_info->layers[1].enz_layer = 0;
 bio_info->layers[1].Ds = 200 * 1e-8;
 bio_info->layers[1].Dp = 200 * 1e-8;
 bio_info->layers[1].d = 300 * 1e-4;
 bio_info->layers[1].e0 = 0 * 1e-3;
 calculate(bio_info, ((void *)0), &callback_crunched);
 free(bio_info->layers);
 free(bio_info);
 return 0;
}

variable_types: struct bio_params { int explicit_scheme; int subs_inh; int prod_inh; double k2; double km; double ks; double kp; double dt; int n; enum resp_method { DEFAULT_TIME=0, MIN_TIME=1, FIXED_TIME=2 } resp_t_meth; double min_t; double resp_t; char *out_file_name; int ne; double s0; double p0; int layer_count; struct layer_params { int enz_layer; double Ds; double Dp; double d; double e0; } *layers; } *

user_defined_types: struct bio_params { int explicit_scheme; int subs_inh; int prod_inh; double k2; double km; double ks; double kp; double dt; int n; enum resp_method resp_t_meth; double min_t; double resp_t; char *out_file_name; int ne; double s0; double p0; int layer_count; struct layer_params *layers; }


decompiled_code:
int __fastcall callback_crunched(__int64 a1, __int64 a2)
{
return printf("%ds simulated\n", a2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2)
{
return printf("%ds simulated\n", a2);
}

original_code:
void callback_crunched(void *ptr, int time)
{
 printf("%ds simulated\n", time);
}

variable_types:
ptr
void *

variable_types: time int


calculate

decompiled_code:
__int64 __fastcall calculate(_DWORD *a1)
{
__int64 result; // rax

if ( *a1 )
result = calculate_explicitly();
else
result = calculate_implicitly();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 result; // rax

if ( *a1 )
result = calculate_explicitly();
else
result = calculate_implicitly();
return result;
}

original_code:
void calculate(struct bio_params *bio_info, void *ptr, void (*callback_crunched)(void *, int))
{
 if (bio_info->explicit_scheme)
  calculate_explicitly(bio_info, ptr, callback_crunched);
 else
  calculate_implicitly(bio_info, ptr, callback_crunched);
}

user_defined_types: enum resp_method { DEFAULT_TIME=0, MIN_TIME=1, FIXED_TIME=2 }

user_defined_types: struct layer_params { int enz_layer; double Ds; double Dp; double d; double e0; }


canonical_original_code:
void fill_array(double *array, int length, double value)
{
 int a;
 for (a = 0; a < length; a++)
  array[a] = value;
}


canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
return printf("%ds simulated\n", a2);
}

canonical_original_code:
void callback_crunched(void *ptr, int time)
{
 printf("%ds simulated\n", time);
}


main

original_code:
int main()
{
 int i;
 struct universal_bio_params *bio_params;
 bio_params = malloc(sizeof(*bio_params));
 bio_params->substance_count = 8;
 bio_params->init_concs = malloc(sizeof(*(bio_params->init_concs)) * bio_params->substance_count);
 bio_params->init_concs[0] = 0;
 bio_params->init_concs[1] = 0;
 bio_params->init_concs[2] = 40e-6;
 bio_params->init_concs[3] = 0;
 bio_params->init_concs[4] = 8e-6;
 bio_params->init_concs[5] = 0;
 bio_params->init_concs[6] = 4e-7;
 bio_params->init_concs[7] = 0;
 bio_params->reaction_count = 4;
 bio_params->reactions = malloc(sizeof(*(bio_params->reactions)) * bio_params->reaction_count);
 bio_params->reactions[0].k = 1.25e7;
 bio_params->reactions[0].reactant_count = 2;
 bio_params->reactions[0].reactants = malloc(sizeof(*(bio_params->reactions[0].reactants)) * bio_params->reactions[0].reactant_count);
 bio_params->reactions[0].reactants[0] = 0;
 bio_params->reactions[0].reactants[1] = 2;
 bio_params->reactions[0].react_stoichs = malloc(sizeof(*(bio_params->reactions[0].react_stoichs)) * bio_params->reactions[0].reactant_count);
 bio_params->reactions[0].react_stoichs[0] = 1;
 bio_params->reactions[0].react_stoichs[1] = 1;
 bio_params->reactions[0].react_orders = malloc(sizeof(*(bio_params->reactions[0].react_orders)) * bio_params->reactions[0].reactant_count);
 bio_params->reactions[0].react_orders[0] = 1;
 bio_params->reactions[0].react_orders[1] = 1;
 bio_params->reactions[0].product_count = 2;
 bio_params->reactions[0].products = malloc(sizeof(*(bio_params->reactions[0].products)) * bio_params->reactions[0].product_count);
 bio_params->reactions[0].products[0] = 1;
 bio_params->reactions[0].products[1] = 3;
 bio_params->reactions[0].prod_stoichs = malloc(sizeof(*(bio_params->reactions[0].prod_stoichs)) * bio_params->reactions[0].product_count);
 bio_params->reactions[0].prod_stoichs[0] = 1;
 bio_params->reactions[0].prod_stoichs[1] = 1;
 bio_params->reactions[1].k = 1.2e5;
 bio_params->reactions[1].reactant_count = 2;
 bio_params->reactions[1].reactants = malloc(sizeof(*(bio_params->reactions[1].reactants)) * bio_params->reactions[1].reactant_count);
 bio_params->reactions[1].reactants[0] = 1;
 bio_params->reactions[1].reactants[1] = 4;
 bio_params->reactions[1].react_stoichs = malloc(sizeof(*(bio_params->reactions[1].react_stoichs)) * bio_params->reactions[1].reactant_count);
 bio_params->reactions[1].react_stoichs[0] = 1;
 bio_params->reactions[1].react_stoichs[1] = 1;
 bio_params->reactions[1].react_orders = malloc(sizeof(*(bio_params->reactions[1].react_orders)) * bio_params->reactions[1].reactant_count);
 bio_params->reactions[1].react_orders[0] = 1;
 bio_params->reactions[1].react_orders[1] = 1;
 bio_params->reactions[1].product_count = 2;
 bio_params->reactions[1].products = malloc(sizeof(*(bio_params->reactions[1].products)) * bio_params->reactions[1].product_count);
 bio_params->reactions[1].products[0] = 0;
 bio_params->reactions[1].products[1] = 5;
 bio_params->reactions[1].prod_stoichs = malloc(sizeof(*(bio_params->reactions[1].prod_stoichs)) * bio_params->reactions[1].product_count);
 bio_params->reactions[1].prod_stoichs[0] = 1;
 bio_params->reactions[1].prod_stoichs[1] = 1;
 bio_params->reactions[2].k = 1.4e9;
 bio_params->reactions[2].reactant_count = 2;
 bio_params->reactions[2].reactants = malloc(sizeof(*(bio_params->reactions[2].reactants)) * bio_params->reactions[2].reactant_count);
 bio_params->reactions[2].reactants[0] = 1;
 bio_params->reactions[2].reactants[1] = 6;
 bio_params->reactions[2].react_stoichs = malloc(sizeof(*(bio_params->reactions[2].react_stoichs)) * bio_params->reactions[2].reactant_count);
 bio_params->reactions[2].react_stoichs[0] = 1;
 bio_params->reactions[2].react_stoichs[1] = 1;
 bio_params->reactions[2].react_orders = malloc(sizeof(*(bio_params->reactions[2].react_orders)) * bio_params->reactions[2].reactant_count);
 bio_params->reactions[2].react_orders[0] = 1;
 bio_params->reactions[2].react_orders[1] = 1;
 bio_params->reactions[2].product_count = 2;
 bio_params->reactions[2].products = malloc(sizeof(*(bio_params->reactions[2].products)) * bio_params->reactions[2].product_count);
 bio_params->reactions[2].products[0] = 0;
 bio_params->reactions[2].products[1] = 7;
 bio_params->reactions[2].prod_stoichs = malloc(sizeof(*(bio_params->reactions[2].prod_stoichs)) * bio_params->reactions[2].product_count);
 bio_params->reactions[2].prod_stoichs[0] = 1;
 bio_params->reactions[2].prod_stoichs[1] = 1;
 bio_params->reactions[3].k = 1.4e9;
 bio_params->reactions[3].reactant_count = 2;
 bio_params->reactions[3].reactants = malloc(sizeof(*(bio_params->reactions[3].reactants)) * bio_params->reactions[3].reactant_count);
 bio_params->reactions[3].reactants[0] = 4;
 bio_params->reactions[3].reactants[1] = 7;
 bio_params->reactions[3].react_stoichs = malloc(sizeof(*(bio_params->reactions[3].react_stoichs)) * bio_params->reactions[3].reactant_count);
 bio_params->reactions[3].react_stoichs[0] = 1;
 bio_params->reactions[3].react_stoichs[1] = 1;
 bio_params->reactions[3].react_orders = malloc(sizeof(*(bio_params->reactions[3].react_orders)) * bio_params->reactions[3].reactant_count);
 bio_params->reactions[3].react_orders[0] = 1;
 bio_params->reactions[3].react_orders[1] = 1;
 bio_params->reactions[3].product_count = 2;
 bio_params->reactions[3].products = malloc(sizeof(*(bio_params->reactions[3].products)) * bio_params->reactions[3].product_count);
 bio_params->reactions[3].products[0] = 5;
 bio_params->reactions[3].products[1] = 6;
 bio_params->reactions[3].prod_stoichs = malloc(sizeof(*(bio_params->reactions[3].prod_stoichs)) * bio_params->reactions[3].product_count);
 bio_params->reactions[3].prod_stoichs[0] = 1;
 bio_params->reactions[3].prod_stoichs[1] = 1;
 bio_params->electrochem_count = 2;
 bio_params->electrochems = malloc(sizeof(*(bio_params->electrochems)) * bio_params->electrochem_count);
 bio_params->electrochems[0].ne = 1;
 bio_params->electrochems[0].reactant_count = 1;
 bio_params->electrochems[0].reactants = malloc(sizeof(*(bio_params->electrochems[0].reactants)) * bio_params->electrochems[0].reactant_count);
 bio_params->electrochems[0].reactants[0] = 5;
 bio_params->electrochems[0].react_stoichs = malloc(sizeof(*(bio_params->electrochems[0].react_stoichs)) * bio_params->electrochems[0].reactant_count);
 bio_params->electrochems[0].react_stoichs[0] = 1;
 bio_params->electrochems[0].product_count = 1;
 bio_params->electrochems[0].products = malloc(sizeof(*(bio_params->electrochems[0].products)) * bio_params->electrochems[0].product_count);
 bio_params->electrochems[0].products[0] = 4;
 bio_params->electrochems[0].prod_stoichs = malloc(sizeof(*(bio_params->electrochems[0].prod_stoichs)) * bio_params->electrochems[0].product_count);
 bio_params->electrochems[0].prod_stoichs[0] = 1;
 bio_params->electrochems[1].ne = 1;
 bio_params->electrochems[1].reactant_count = 1;
 bio_params->electrochems[1].reactants = malloc(sizeof(*(bio_params->electrochems[1].reactants)) * bio_params->electrochems[1].reactant_count);
 bio_params->electrochems[1].reactants[0] = 7;
 bio_params->electrochems[1].react_stoichs = malloc(sizeof(*(bio_params->electrochems[1].react_stoichs)) * bio_params->electrochems[1].reactant_count);
 bio_params->electrochems[1].react_stoichs[0] = 1;
 bio_params->electrochems[1].product_count = 1;
 bio_params->electrochems[1].products = malloc(sizeof(*(bio_params->electrochems[1].products)) * bio_params->electrochems[1].product_count);
 bio_params->electrochems[1].products[0] = 6;
 bio_params->electrochems[1].prod_stoichs = malloc(sizeof(*(bio_params->electrochems[1].prod_stoichs)) * bio_params->electrochems[1].product_count);
 bio_params->electrochems[1].prod_stoichs[0] = 1;
 bio_params->layer_count = 3;
 bio_params->layers = malloc(sizeof(*(bio_params->layers)) * bio_params->layer_count);
 bio_params->layers[0].d = 23.3e-4;
 bio_params->layers[0].reaction_count = 4;
 bio_params->layers[0].reactions = malloc(sizeof(*(bio_params->layers[0].reactions)) * bio_params->layers[0].reaction_count);
 bio_params->layers[0].reactions[0] = 0;
 bio_params->layers[0].reactions[1] = 1;
 bio_params->layers[0].reactions[2] = 2;
 bio_params->layers[0].reactions[3] = 3;
 bio_params->layers[0].diff_coefs = malloc(sizeof(*(bio_params->layers[0].diff_coefs)) * bio_params->substance_count);
 bio_params->layers[0].diff_coefs[0] = 0;
 bio_params->layers[0].diff_coefs[1] = 0;
 bio_params->layers[0].diff_coefs[2] = 3.15e-6;
 bio_params->layers[0].diff_coefs[3] = 3.15e-6;
 bio_params->layers[0].diff_coefs[4] = 3.15e-6;
 bio_params->layers[0].diff_coefs[5] = 3.15e-6;
 bio_params->layers[0].diff_coefs[6] = 3.15e-6;
 bio_params->layers[0].diff_coefs[7] = 3.15e-6;
 bio_params->layers[0].init_concs = malloc(sizeof(*(bio_params->layers[0].init_concs)) * bio_params->substance_count);
 bio_params->layers[0].init_concs[0] = 4e-8;
 bio_params->layers[0].init_concs[1] = 0;
 bio_params->layers[0].init_concs[2] = 0;
 bio_params->layers[0].init_concs[3] = 0;
 bio_params->layers[0].init_concs[4] = 0;
 bio_params->layers[0].init_concs[5] = 0;
 bio_params->layers[0].init_concs[6] = 0;
 bio_params->layers[0].init_concs[7] = 0;
 bio_params->layers[1].d = 18.6e-4;
 bio_params->layers[1].reaction_count = 1;
 bio_params->layers[1].reactions = malloc(sizeof(*(bio_params->layers[1].reactions)) * bio_params->layers[1].reaction_count);
 bio_params->layers[1].reactions[0] = 3;
 bio_params->layers[1].diff_coefs = malloc(sizeof(*(bio_params->layers[1].diff_coefs)) * bio_params->substance_count);
 bio_params->layers[1].diff_coefs[0] = 0;
 bio_params->layers[1].diff_coefs[1] = 0;
 bio_params->layers[1].diff_coefs[2] = 4.2e-7;
 bio_params->layers[1].diff_coefs[3] = 4.2e-7;
 bio_params->layers[1].diff_coefs[4] = 4.2e-7;
 bio_params->layers[1].diff_coefs[5] = 4.2e-7;
 bio_params->layers[1].diff_coefs[6] = 4.2e-7;
 bio_params->layers[1].diff_coefs[7] = 4.2e-7;
 bio_params->layers[1].init_concs = malloc(sizeof(*(bio_params->layers[1].init_concs)) * bio_params->substance_count);
 bio_params->layers[1].init_concs[0] = 0;
 bio_params->layers[1].init_concs[1] = 0;
 bio_params->layers[1].init_concs[2] = 0;
 bio_params->layers[1].init_concs[3] = 0;
 bio_params->layers[1].init_concs[4] = 0;
 bio_params->layers[1].init_concs[5] = 0;
 bio_params->layers[1].init_concs[6] = 0;
 bio_params->layers[1].init_concs[7] = 0;
 bio_params->layers[2].d = 116.5e-4;
 bio_params->layers[2].reaction_count = 1;
 bio_params->layers[2].reactions = malloc(sizeof(*(bio_params->layers[2].reactions)) * bio_params->layers[2].reaction_count);
 bio_params->layers[2].reactions[0] = 3;
 bio_params->layers[2].diff_coefs = malloc(sizeof(*(bio_params->layers[2].diff_coefs)) * bio_params->substance_count);
 bio_params->layers[2].diff_coefs[0] = 0;
 bio_params->layers[2].diff_coefs[1] = 0;
 bio_params->layers[2].diff_coefs[2] = 6.3e-6;
 bio_params->layers[2].diff_coefs[3] = 6.3e-6;
 bio_params->layers[2].diff_coefs[4] = 6.3e-6;
 bio_params->layers[2].diff_coefs[5] = 6.3e-6;
 bio_params->layers[2].diff_coefs[6] = 6.3e-6;
 bio_params->layers[2].diff_coefs[7] = 6.3e-6;
 bio_params->layers[2].init_concs = malloc(sizeof(*(bio_params->layers[2].init_concs)) * bio_params->substance_count);
 bio_params->layers[2].init_concs[0] = 0;
 bio_params->layers[2].init_concs[1] = 0;
 bio_params->layers[2].init_concs[2] = 0;
 bio_params->layers[2].init_concs[3] = 0;
 bio_params->layers[2].init_concs[4] = 0;
 bio_params->layers[2].init_concs[5] = 0;
 bio_params->layers[2].init_concs[6] = 0;
 bio_params->layers[2].init_concs[7] = 0;
 bio_params->electrode_neutral_count = 1;
 bio_params->electrode_neutrals = malloc(sizeof(*(bio_params->electrode_neutrals)) * bio_params->electrode_neutral_count);
 bio_params->electrode_neutrals[0] = 2;
 bio_params->n = 200;
 double dt0 = pow(bio_params->layers[0].d / bio_params->n, 2) / (2 * bio_params->layers[0].diff_coefs[2]);
 double dt1 = pow(bio_params->layers[1].d / bio_params->n, 2) / (2 * bio_params->layers[1].diff_coefs[2]);
 double dt2 = pow(bio_params->layers[2].d / bio_params->n, 2) / (2 * bio_params->layers[2].diff_coefs[2]);
 bio_params->dt = 0.9 * fmin(dt0, fmin(dt1, dt2));
 bio_params->resp_t_meth = MIN_TIME;
 bio_params->min_t = 100;
 bio_params->resp_t = 0;
 bio_params->out_file_name = "output.dat";
 calculate(bio_params, ((void *)0), &callback_crunched);
 free(bio_params->electrode_neutrals);
 for (i = 0; i < bio_params->layer_count; i++) {
  free(bio_params->layers[i].reactions);
  free(bio_params->layers[i].diff_coefs);
  free(bio_params->layers[i].init_concs);
 }
 free(bio_params->layers);
 for (i = 0; i < bio_params->electrochem_count; i++) {
  free(bio_params->electrochems[i].reactants);
  free(bio_params->electrochems[i].react_stoichs);
  free(bio_params->electrochems[i].products);
  free(bio_params->electrochems[i].prod_stoichs);
 }
 free(bio_params->electrochems);
 for (i = 0; i < bio_params->reaction_count; i++) {
  free(bio_params->reactions[i].reactants);
  free(bio_params->reactions[i].react_stoichs);
  free(bio_params->reactions[i].react_orders);
  free(bio_params->reactions[i].products);
  free(bio_params->reactions[i].prod_stoichs);
 }
 free(bio_params->reactions);
 free(bio_params->init_concs);
 free(bio_params);
 return 0;
}

variable_types: i int

variable_types: struct universal_bio_params { int substance_count; int reaction_count; struct reaction { int reactant_count; int *reactants; int *react_stoichs; double *react_orders; int product_count; int *products; int *prod_stoichs; double k; } *reactions; int electrochem_count; struct electrochem { int ne; int reactant_count; int *reactants; int *react_stoichs; int product_count; int *products; int *prod_stoichs; } *electrochems; int layer_count; struct layer { double *diff_coefs; double *init_concs; int reaction_count; int *reactions; double d; } *layers; int electrode_neutral_count; int *electrode_neutrals; double *init_concs; double dt; int n; enum resp_method { DEFAULT_TIME=0, MIN_TIME=1, FIXED_TIME=2 } resp_t_meth; double min_t; double resp_t; char *out_file_name; } *

user_defined_types: struct universal_bio_params { int substance_count; int reaction_count; struct reaction *reactions; int electrochem_count; struct electrochem *electrochems; int layer_count; struct layer *layers; int electrode_neutral_count; int *electrode_neutrals; double *init_concs; double dt; int n; enum resp_method resp_t_meth; double min_t; double resp_t; char *out_file_name; }


repo: dakk/mandelbrot-fractal

original_code:
int main(int argc, char **argv)
{
 int x,y;
 request_t req;
 req.dx = 640;
 req.dy = 480;
 req.cl_start = -1431749881;
 req.cl_end = 0x00FFFF00;
 req.levels = 90;
 req.reg_x0 = -2;
 req.reg_x1 = 2;
 req.reg_y0 = -2;
 req.reg_y1 = 2;
 req.data = (int *) malloc(sizeof(int) * req.dx * req.dy);
 zoom(0.1, &req);
 for(x = 0; x < req.dx; x++)
  for(y = 0; y < req.dy; y++)
   req.data[y * req.dx + x] = 0;
 sdlrender(req);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int x; int y;
 struct request_t req;
 req.dx = 640;
 req.dy = 480;
 req.cl_start = -1431749881;
 req.cl_end = 0x00FFFF00;
 req.levels = 90;
 req.reg_x0 = -2;
 req.reg_x1 = 2;
 req.reg_y0 = -2;
 req.reg_y1 = 2;
 req.data = (int *) malloc(sizeof(int) * req.dx * req.dy);
 zoom(0.1, &req);
 for(x = 0; x < req.dx; x++)
  for(y = 0; y < req.dy; y++)
   req.data[y * req.dx + x] = 0;
 sdlrender(req);
 return 0;
}

variable_types:
argv
char **

variable_types: x int

variable_types: y int

variable_types: struct request_t { int algorithm; int *data; int dx; int dy; unsigned int cl_start; int cl_end; int levels; double reg_x0; double reg_x1; double reg_y0; double reg_y1; }


decompiled_code:
int __fastcall render_big(const char *a1, unsigned int a2, unsigned int a3, double a4)
{
unsigned int v5; // er14
unsigned int v6; // er13
double v8; // xmm4_8
double v9; // xmm0_8
double v10; // r15
int result; // eax
double v12; // [rsp+0h] [rbp-4B0h]
double v13; // [rsp+8h] [rbp-4A8h]
double v14; // [rsp+20h] [rbp-490h]
char s[1080]; // [rsp+78h] [rbp-438h] BYREF

v5 = 0;
v6 = 0;
v8 = a4 - 2.0;
v12 = *(double *)&LC0;
v9 = *(double *)&LC0;
v10 = v8;
v14 = v8;
v13 = v8;
do
{
while ( 1 )
{
sprintf(s, "%s_%d_%d.bmp", a1, v5, v6);
fract2bmp(s, a2, a3);
result = printf("writed %s\n", s);
v9 = v9 + a4;
if ( v9 >= 2.0 )
break;
++v6;
v13 = v13 + a4;
if ( v12 >= 2.0 )
return result;
}
++v5;
v6 = 0;
result = LC0;
v13 = v14;
v9 = *(double *)&LC0;
v12 = v12 + a4;
v10 = v10 + a4;
}
while ( v12 < 2.0 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, unsigned int a2, unsigned int a3, double a4)
{
unsigned int v5; // er14
unsigned int v6; // er13
double v8; // xmm4_8
double v9; // xmm0_8
double v10; // r15
int result; // eax
double v12; // [rsp+0h] [rbp-4B0h]
double v13; // [rsp+8h] [rbp-4A8h]
double v14; // [rsp+20h] [rbp-490h]
char s[1080]; // [rsp+78h] [rbp-438h] BYREF

v5 = 0;
v6 = 0;
v8 = a4 - 2.0;
v12 = *(double *)&LC0;
v9 = *(double *)&LC0;
v10 = v8;
v14 = v8;
v13 = v8;
do
{
while ( 1 )
{
sprintf(s, "%s_%d_%d.bmp", a1, v5, v6);
fract2bmp(s, a2, a3);
result = printf("writed %s\n", s);
v9 = v9 + a4;
if ( v9 >= 2.0 )
break;
++v6;
v13 = v13 + a4;
if ( v12 >= 2.0 )
return result;
}
++v5;
v6 = 0;
result = LC0;
v13 = v14;
v9 = *(double *)&LC0;
v12 = v12 + a4;
v10 = v10 + a4;
}
while ( v12 < 2.0 );
return result;
}

original_code:
void render_big(char *name, int x, int y, double step, request_t req)
{
 char nf[1024];
 request_t current = req;
 current.reg_x0 = -2;
 current.reg_y0 = -2;
 current.reg_x1 = -2 + step;
 current.reg_y1 = -2 + step;
 int l = 0;
 int c = 0;
 while(current.reg_y0 < 2)
 {
  sprintf(nf, "%s_%d_%d.bmp", name, l, c);
  fract2bmp(nf, current, x, y);
  printf("writed %s\n", nf);
  current.reg_x0 += step;
  current.reg_x1 += step;
  c++;
  if(current.reg_x0 >= 2)
  {
   l++; c = 0;
   current.reg_x0 = -2;
   current.reg_x1 = -2 + step;
   current.reg_y0 += step;
   current.reg_y1 += step;
  }
 }
}

canonical_original_code:
void render_big(char *name, int x, int y, double step, struct request_t req)
{
 char nf[1024];
 struct request_t current = req;
 current.reg_x0 = -2;
 current.reg_y0 = -2;
 current.reg_x1 = -2 + step;
 current.reg_y1 = -2 + step;
 int l = 0;
 int c = 0;
 while(current.reg_y0 < 2)
 {
  sprintf(nf, "%s_%d_%d.bmp", name, l, c);
  fract2bmp(nf, current, x, y);
  printf("writed %s\n", nf);
  current.reg_x0 += step;
  current.reg_x1 += step;
  c++;
  if(current.reg_x0 >= 2)
  {
   l++; c = 0;
   current.reg_x0 = -2;
   current.reg_x1 = -2 + step;
   current.reg_y0 += step;
   current.reg_y1 += step;
  }
 }
}

variable_types:
name
char *

variable_types: step double

variable_types:
nf
char [1024]

variable_types: l int

variable_types: c int

user_defined_types: struct request_t { int algorithm; int *data; int dx; int dy; unsigned int cl_start; int cl_end; int levels; double reg_x0; double reg_x1; double reg_y0; double reg_y1; }


clear

decompiled_code:
__int64 __fastcall clear(__int64 a1)
{
__int64 result; // rax
int i; // ecx
__int64 v3; // rsi
int v4; // edx
int v5; // eax

result = *(unsigned int *)(a1 + 16);
for ( i = 0; i < (int)result; ++i )
{
if ( *(int *)(a1 + 20) > 0 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = 0;
do
{
v5 = v4 * result;
++v4;
*(_DWORD *)(v3 + 4LL * (i + v5)) = 0;
result = *(unsigned int *)(a1 + 16);
}
while ( *(_DWORD *)(a1 + 20) > v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int i; // ecx
__int64 v3; // rsi
int v4; // edx
int v5; // eax

result = *(unsigned int *)(a1 + 16);
for ( i = 0; i < (int)result; ++i )
{
if ( *(int *)(a1 + 20) > 0 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = 0;
do
{
v5 = v4 * result;
++v4;
*(_DWORD *)(v3 + 4LL * (i + v5)) = 0;
result = *(unsigned int *)(a1 + 16);
}
while ( *(_DWORD *)(a1 + 20) > v4 );
}
}
return result;
}

original_code:
void clear(request_t *req)
{
 int x,y;
 for(x = 0; x < req->dx; x++)
  for(y = 0; y < req->dy; y++)
   req->data[y * req->dx + x] = 0;
}

canonical_original_code:
void clear(struct request_t *req)
{
 int x; int y;
 for(x = 0; x < req->dx; x++)
  for(y = 0; y < req->dy; y++)
   req->data[y * req->dx + x] = 0;
}

variable_types: struct request_t { int algorithm; int *data; int dx; int dy; unsigned int cl_start; int cl_end; int levels; double reg_x0; double reg_x1; double reg_y0; double reg_y1; } *


zoom

original_code:
void zoom(double value, request_t *req)
{
 double v = value;
  req->reg_x0 = req->reg_x0 + v;
  req->reg_y0 = req->reg_y0 + v;
  req->reg_x1 = req->reg_x1 - v;
  req->reg_y1 = req->reg_y1 - v;
}

canonical_original_code:
void zoom(double value, struct request_t *req)
{
 double v = value;
  req->reg_x0 = req->reg_x0 + v;
  req->reg_y0 = req->reg_y0 + v;
  req->reg_x1 = req->reg_x1 - v;
  req->reg_y1 = req->reg_y1 - v;
}

variable_types: value double

variable_types: v double


move

original_code:
void move(double x, double y, request_t *req)
{
 req->reg_x0 = req->reg_x0 + x;
 req->reg_y0 = req->reg_y0 + y;
 req->reg_x1 = req->reg_x1 + x;
 req->reg_y1 = req->reg_y1 + y;
}

canonical_original_code:
void move(double x, double y, struct request_t *req)
{
 req->reg_x0 = req->reg_x0 + x;
 req->reg_y0 = req->reg_y0 + y;
 req->reg_x1 = req->reg_x1 + x;
 req->reg_y1 = req->reg_y1 + y;
}

variable_types: x double

variable_types: y double


setpos

original_code:
void setpos(int x, int y, request_t *req)
{
 double dif = req->reg_x1 - req->reg_x0;
 double newx = x * 4 / req->dx - dif / 2;
 double newy = y * 4 / req->dy - dif / 2;
 req->reg_x0 = newx;
 req->reg_y0 = newy;
 req->reg_x1 = newx + dif;
 req->reg_y1 = newy + dif;
}

canonical_original_code:
void setpos(int x, int y, struct request_t *req)
{
 double dif = req->reg_x1 - req->reg_x0;
 double newx = x * 4 / req->dx - dif / 2;
 double newy = y * 4 / req->dy - dif / 2;
 req->reg_x0 = newx;
 req->reg_y0 = newy;
 req->reg_x1 = newx + dif;
 req->reg_y1 = newy + dif;
}

variable_types: dif double

variable_types: newx double

variable_types: newy double


original_code:
void mandelbrot_fract_algorithm(request_t req)
{
 clear(&req);
    long x,y,d,i;
    double real_x,real_y;
    complex_t z,c,temp;
 double agg_temp;
    agg_temp=req.reg_y1;
    req.reg_y1=req.reg_y0*(-1);
    req.reg_y0=agg_temp*(-1);
    for(x=0; x < req.dx; x++)
    {
        real_x = ((req.reg_x1-req.reg_x0)/req.dx)*x+req.reg_x0;
        for(y=0;y<req.dy;y++)
        {
            real_y = ((req.reg_y1 - req.reg_y0) / req.dy) * y + req.reg_y0;
            c.real = real_x;
            c.imaginary = real_y;
            z.real = 0;
            z.imaginary = 0;
            d = 0;
            for(i=0;i<req.levels;i++)
            {
                if((z.real*z.real)+(z.imaginary*z.imaginary) > 4)
                {
                    d = i;
                    break;
                }
                temp.real = z.real;
                temp.imaginary = z.imaginary;
                z.real = (temp.real*temp.real) - (temp.imaginary*temp.imaginary) + c.real;
                z.imaginary = (temp.real*temp.imaginary)*2 + c.imaginary;
            }
            if(d == 0) req.data[y * req.dx + x] = 0;
            else req.data[y * req.dx + x] = req.cl_start + (char) d * 0x100 + (char) d * 0x10000+ (char) d * 0x1000000;
        }
    }
}

canonical_original_code:
void mandelbrot_fract_algorithm(struct request_t req)
{
 clear(&req);
    long x; long y; long d; long i;
    double real_x; double real_y;
    struct complex_t z; struct complex_t c; struct complex_t temp;
 double agg_temp;
    agg_temp=req.reg_y1;
    req.reg_y1=req.reg_y0*(-1);
    req.reg_y0=agg_temp*(-1);
    for(x=0; x < req.dx; x++)
    {
        real_x = ((req.reg_x1-req.reg_x0)/req.dx)*x+req.reg_x0;
        for(y=0;y<req.dy;y++)
        {
            real_y = ((req.reg_y1 - req.reg_y0) / req.dy) * y + req.reg_y0;
            c.real = real_x;
            c.imaginary = real_y;
            z.real = 0;
            z.imaginary = 0;
            d = 0;
            for(i=0;i<req.levels;i++)
            {
                if((z.real*z.real)+(z.imaginary*z.imaginary) > 4)
                {
                    d = i;
                    break;
                }
                temp.real = z.real;
                temp.imaginary = z.imaginary;
                z.real = (temp.real*temp.real) - (temp.imaginary*temp.imaginary) + c.real;
                z.imaginary = (temp.real*temp.imaginary)*2 + c.imaginary;
            }
            if(d == 0) req.data[y * req.dx + x] = 0;
            else req.data[y * req.dx + x] = req.cl_start + (char) d * 0x100 + (char) d * 0x10000+ (char) d * 0x1000000;
        }
    }
}

variable_types: x long

variable_types: y long

variable_types: d long

variable_types: i long

variable_types: struct complex_t { double real; double imaginary; }


repo: dakk/sirbonville

original_code:
void sv_recompact(Porcile *p)
{
 int i, k;
 int n_mai = 0;
 for(i = 0; i < 10; i++)
 {
  if(p->maiali[i].eta < 0)
  {
   for(k = i + 1; k < 10; k++)
   {
    if(p->maiali[k].eta >= 0)
    {
     p->maiali[i] = p->maiali[k];
     p->maiali[k].eta = -1;
     k = 10;
    }
   }
  }
 }
}

canonical_original_code:
void sv_recompact(struct Porcile *p)
{
 int i; int k;
 int n_mai = 0;
 for(i = 0; i < 10; i++)
 {
  if(p->maiali[i].eta < 0)
  {
   for(k = i + 1; k < 10; k++)
   {
    if(p->maiali[k].eta >= 0)
    {
     p->maiali[i] = p->maiali[k];
     p->maiali[k].eta = -1;
     k = 10;
    }
   }
  }
 }
}

variable_types: struct Porcile { unsigned int letame; unsigned int monete; unsigned int cibo; unsigned int tempo; unsigned int n_maiali; struct maiale_t { int eta; int peso; int salute; unsigned int fame; unsigned int bisogni; } maiali[10]; unsigned int sec4unit; } *

variable_types: i int

variable_types: k int

user_defined_types: struct Porcile { unsigned int letame; unsigned int monete; unsigned int cibo; unsigned int tempo; unsigned int n_maiali; struct maiale_t maiali[10]; unsigned int sec4unit; }


original_code:
int sv_update(Porcile *p)
{
 int morti = 0;
 int i;
 int nmai = p->n_maiali;
 p->tempo++;
 for(i = 0; i < nmai; i++)
 {
  if((p->tempo % 4) == 0)
   p->maiali[i].fame = (p->maiali[i].fame + 1) % 100;
  if((p->tempo % 5) == 0)
   p->maiali[i].bisogni++;
  if(p->maiali[i].fame == 100)
   p->maiali[i].salute -= 2;
  if(p->maiali[i].peso > 200)
   p->maiali[i].salute -= 1;
  if(p->letame > 300)
   p->maiali[i].salute -= 1;
  if(p->maiali[i].fame >= 60)
   p->maiali[i].peso -= 1;
  if(p->maiali[i].bisogni == 100)
  {
   p->letame += ((p->maiali[i].peso / 10));
   p->maiali[i].bisogni = 0;
  }
  p->maiali[i].eta += 1;
  if( ((p->maiali[i].eta < 2 * 500 / 3) && (p->maiali[i].salute <= 30)) ||
   ((p->maiali[i].eta >= 2 * 500 / 3) && (p->maiali[i].salute < 60)) ||
   (p->maiali[i].eta >= 500) || (p->maiali[i].peso <= 0))
  {
   p->maiali[i].eta = -1;
   p->n_maiali--;
   morti++;
  }
 }
 sv_recompact(p);
 if((p->tempo % 150) == 0)
 {
  int nascite = (rand() % (p->n_maiali / 2)) + 1;
  if(nascite > 0)
  {
   for(i = 0; (i < nascite) && ((i + p->n_maiali) < 10); i++)
    sv_new_default_maial(p, i + p->n_maiali);
   p->n_maiali += i;
   p->monete += (nascite - i) * 50;
   sv_recompact(p);
  }
 }
 return morti;
}

canonical_original_code:
int sv_update(struct Porcile *p)
{
 int morti = 0;
 int i;
 int nmai = p->n_maiali;
 p->tempo++;
 for(i = 0; i < nmai; i++)
 {
  if((p->tempo % 4) == 0)
   p->maiali[i].fame = (p->maiali[i].fame + 1) % 100;
  if((p->tempo % 5) == 0)
   p->maiali[i].bisogni++;
  if(p->maiali[i].fame == 100)
   p->maiali[i].salute -= 2;
  if(p->maiali[i].peso > 200)
   p->maiali[i].salute -= 1;
  if(p->letame > 300)
   p->maiali[i].salute -= 1;
  if(p->maiali[i].fame >= 60)
   p->maiali[i].peso -= 1;
  if(p->maiali[i].bisogni == 100)
  {
   p->letame += ((p->maiali[i].peso / 10));
   p->maiali[i].bisogni = 0;
  }
  p->maiali[i].eta += 1;
  if( ((p->maiali[i].eta < 2 * 500 / 3) && (p->maiali[i].salute <= 30)) ||
   ((p->maiali[i].eta >= 2 * 500 / 3) && (p->maiali[i].salute < 60)) ||
   (p->maiali[i].eta >= 500) || (p->maiali[i].peso <= 0))
  {
   p->maiali[i].eta = -1;
   p->n_maiali--;
   morti++;
  }
 }
 sv_recompact(p);
 if((p->tempo % 150) == 0)
 {
  int nascite = (rand() % (p->n_maiali / 2)) + 1;
  if(nascite > 0)
  {
   for(i = 0; (i < nascite) && ((i + p->n_maiali) < 10); i++)
    sv_new_default_maial(p, i + p->n_maiali);
   p->n_maiali += i;
   p->monete += (nascite - i) * 50;
   sv_recompact(p);
  }
 }
 return morti;
}

variable_types: morti int

variable_types: nmai int

variable_types: nascite int

user_defined_types: struct maiale_t { int eta; int peso; int salute; unsigned int fame; unsigned int bisogni; }


decompiled_code:
__int64 __fastcall sv_feed(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // eax
unsigned int v4; // er8
unsigned int v5; // er9
unsigned int v6; // ecx
unsigned int v7; // ecx
unsigned int v8; // eax
__int64 v9; // rdx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 16) >= (unsigned int)a3 )
{
if ( a2 )
{
v3 = *(_DWORD *)(a1 + 8);
if ( v3 )
{
if ( v3 < a2 )
{
a3 = (int)a3;
v4 = *(_DWORD *)(a1 + 8);
v5 = 0;
v6 = *(_DWORD *)(a1 + 20LL * (int)a3 + 32);
if ( v6 >= v3 )
goto LABEL_6;
}
else
{
a3 = (int)a3;
v4 = a2;
v5 = v3 - a2;
v3 = a2;
v6 = *(_DWORD *)(a1 + 20LL * (int)a3 + 32);
if ( v6 >= a2 )
{
LABEL_6:
v7 = v6 - v3;
v8 = 0;
LABEL_7:
v9 = a1 + 20 * a3;
*(_DWORD *)(v9 + 24) += v8;
result = v4;
*(_DWORD *)(v9 + 32) = v7;
*(_DWORD *)(a1 + 8) = v5;
return result;
}
}
v8 = v3 - v6;
v7 = 0;
goto LABEL_7;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // eax
unsigned int v4; // er8
unsigned int v5; // er9
unsigned int v6; // ecx
unsigned int v7; // ecx
unsigned int v8; // eax
__int64 v9; // rdx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 16) >= (unsigned int)a3 )
{
if ( a2 )
{
v3 = *(_DWORD *)(a1 + 8);
if ( v3 )
{
if ( v3 < a2 )
{
a3 = (int)a3;
v4 = *(_DWORD *)(a1 + 8);
v5 = 0;
v6 = *(_DWORD *)(a1 + 20LL * (int)a3 + 32);
if ( v6 >= v3 )
goto LABEL_6;
}
else
{
a3 = (int)a3;
v4 = a2;
v5 = v3 - a2;
v3 = a2;
v6 = *(_DWORD *)(a1 + 20LL * (int)a3 + 32);
if ( v6 >= a2 )
{
LABEL_6:
v7 = v6 - v3;
v8 = 0;
LABEL_7:
v9 = a1 + 20 * a3;
*(_DWORD *)(v9 + 24) += v8;
result = v4;
*(_DWORD *)(v9 + 32) = v7;
*(_DWORD *)(a1 + 8) = v5;
return result;
}
}
v8 = v3 - v6;
v7 = 0;
goto LABEL_7;
}
}
}
return 0LL;
}

original_code:
int sv_feed(Porcile *p, int quant, int who)
{
 unsigned peso = 0;
 if((who > p->n_maiali) || (quant == 0) || (p->cibo == 0))
  return 0;
 if(quant > p->cibo)
  quant = p->cibo;
 if(quant > p->maiali[who].fame)
 {
  peso = quant - p->maiali[who].fame;
  quant = p->maiali[who].fame;
 }
 p->maiali[who].fame -= quant;
 p->maiali[who].peso += peso;
 p->cibo -= (quant + peso);
 return (quant + peso);
}

canonical_original_code:
int sv_feed(struct Porcile *p, int quant, int who)
{
 unsigned int peso = 0;
 if((who > p->n_maiali) || (quant == 0) || (p->cibo == 0))
  return 0;
 if(quant > p->cibo)
  quant = p->cibo;
 if(quant > p->maiali[who].fame)
 {
  peso = quant - p->maiali[who].fame;
  quant = p->maiali[who].fame;
 }
 p->maiali[who].fame -= quant;
 p->maiali[who].peso += peso;
 p->cibo -= (quant + peso);
 return (quant + peso);
}

variable_types: quant int

variable_types: who int

variable_types:
peso
unsigned int


decompiled_code:
__int64 __fastcall sv_feed_all(__int64 a1, unsigned int a2)
{
unsigned int v2; // er11
unsigned int v3; // er10
int v4; // eax
int v5; // er11

v2 = 0;
if ( *(_DWORD *)(a1 + 16) )
{
v3 = 0;
do
{
v4 = sv_feed(a1, a2, v3);
v2 = v4 + v5;
}
while ( *(_DWORD *)(a1 + 16) > v3 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
unsigned int v2; // er11
unsigned int v3; // er10
int v4; // eax
int v5; // er11

v2 = 0;
if ( *(_DWORD *)(a1 + 16) )
{
v3 = 0;
do
{
v4 = func6(a1, a2, v3);
v2 = v4 + v5;
}
while ( *(_DWORD *)(a1 + 16) > v3 );
}
return v2;
}

original_code:
int sv_feed_all(Porcile *p, int quant)
{
 int i;
 int kg = 0;
 for(i = 0; i < p->n_maiali; i++)
  kg += sv_feed(p, quant, i);
 return kg;
}

canonical_original_code:
int sv_feed_all(struct Porcile *p, int quant)
{
 int i;
 int kg = 0;
 for(i = 0; i < p->n_maiali; i++)
  kg += sv_feed(p, quant, i);
 return kg;
}

variable_types: kg int


decompiled_code:
__int64 __fastcall sv_sell(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
_DWORD *v4; // rcx
int v5; // edx
unsigned int v6; // er10

v2 = *(_DWORD *)(a1 + 16);
if ( v2 < a2 )
return 0LL;
v4 = (_DWORD *)(a1 + 20LL * (int)a2);
v5 = v4[6] * v4[7];
v4[5] = -1;
*(_DWORD *)(a1 + 16) = v2 - 1;
*(_DWORD *)(a1 + 4) += v5 / 100;
sv_recompact(a1);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
_DWORD *v4; // rcx
int v5; // edx
unsigned int v6; // er10

v2 = *(_DWORD *)(a1 + 16);
if ( v2 < a2 )
return 0LL;
v4 = (_DWORD *)(a1 + 20LL * (int)a2);
v5 = v4[6] * v4[7];
v4[5] = -1;
*(_DWORD *)(a1 + 16) = v2 - 1;
*(_DWORD *)(a1 + 4) += v5 / 100;
func0(a1);
return v6;
}

original_code:
int sv_sell(Porcile *p, int who)
{
 int money;
 if(who > p->n_maiali)
  return 0;
 p->maiali[who].eta = -1;
 money = p->maiali[who].salute * p->maiali[who].peso / 100;
 p->monete += money;
 p->n_maiali--;
 sv_recompact(p);
 return money;
}

canonical_original_code:
int sv_sell(struct Porcile *p, int who)
{
 int money;
 if(who > p->n_maiali)
  return 0;
 p->maiali[who].eta = -1;
 money = p->maiali[who].salute * p->maiali[who].peso / 100;
 p->monete += money;
 p->n_maiali--;
 sv_recompact(p);
 return money;
}

variable_types: money int


decompiled_code:
__int64 __fastcall sv_clear(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // edx
unsigned int v3; // eax
unsigned int v4; // ecx
unsigned int v5; // er8
unsigned int v6; // ecx
__int64 result; // rax

v2 = *a1;
v3 = a2;
if ( *a1 < a2 )
{
a2 = *a1;
v3 = *a1;
}
v4 = a1[1];
if ( v4 < v3 )
{
result = v4;
*(_QWORD *)a1 = v2 - v4;
}
else
{
v5 = v4 - v3;
v6 = v3;
result = a2;
a1[1] = v5;
*a1 = v2 - v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // edx
unsigned int v3; // eax
unsigned int v4; // ecx
unsigned int v5; // er8
unsigned int v6; // ecx
__int64 result; // rax

v2 = *a1;
v3 = a2;
if ( *a1 < a2 )
{
a2 = *a1;
v3 = *a1;
}
v4 = a1[1];
if ( v4 < v3 )
{
result = v4;
*(_QWORD *)a1 = v2 - v4;
}
else
{
v5 = v4 - v3;
v6 = v3;
result = a2;
a1[1] = v5;
*a1 = v2 - v6;
}
return result;
}

original_code:
int sv_clear(Porcile *p, int quant)
{
 if(quant > p->letame)
  quant = p->letame;
 if((quant * 1) > p->monete)
  quant = p->monete / 1;
 p->letame -= quant;
 p->monete -= quant * 1;
 return (quant * 1);
}

canonical_original_code:
int sv_clear(struct Porcile *p, int quant)
{
 if(quant > p->letame)
  quant = p->letame;
 if((quant * 1) > p->monete)
  quant = p->monete / 1;
 p->letame -= quant;
 p->monete -= quant * 1;
 return (quant * 1);
}


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

v2 = *(_DWORD *)(a1 + 4);
result = a2;
if ( a2 > v2 )
result = v2;
*(_DWORD *)(a1 + 8) += result;
*(_DWORD *)(a1 + 4) = v2 - result;
return result;
}

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

v2 = *(_DWORD *)(a1 + 4);
result = a2;
if ( a2 > v2 )
result = v2;
*(_DWORD *)(a1 + 8) += result;
*(_DWORD *)(a1 + 4) = v2 - result;
return result;
}

original_code:
int sv_buy_food(Porcile *p, int quant)
{
 quant = quant > p->monete ? p->monete : quant;
 p->monete -= quant;
 p->cibo += quant * 1;
 return quant;
}

canonical_original_code:
int sv_buy_food(struct Porcile *p, int quant)
{
 quant = quant > p->monete ? p->monete : quant;
 p->monete -= quant;
 p->cibo += quant * 1;
 return quant;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5; // eax
const char *v6; // rsi
const char **v7; // [rsp+0h] [rbp-F8h] BYREF
int v8; // [rsp+Ch] [rbp-ECh] BYREF
char v9[232]; // [rsp+10h] [rbp-E8h] BYREF

v8 = argc;
v7 = argv;
v3 = time(0LL);
srand(v3);
puts("SirbonVille 1.0");
if ( argc == 2 )
{
v5 = sv_load(v9, v7[1]);
v6 = v7[1];
if ( v5 )
printf("Stato del gioco caricato dal file %s\n", v6);
else
printf("Impossibile caricare lo stato del gioco dal file %s.\n", v6);
}
gtk_init(&v8, &v7);
if ( (unsigned int)gui_create(v9) )
gtk_main();
else
printf("Errore durante il caricamento della gui. Uscita");
return 0;
}

original_code:
int main(int argc, char **argv)
{
 Porcile porcile;
 srand(time(((void *)0)));
 printf("%s\n", "SirbonVille " "1.0");
 if(argc == 2)
 {
  if(!sv_load(&porcile, argv[1]))
  {
   printf("Impossibile caricare lo stato del gioco dal file %s.\n", argv[1]);
  }
  else
   printf("Stato del gioco caricato dal file %s\n", argv[1]);
 }
 gtk_init (&argc, &argv);
 if(!gui_create(&porcile))
 {
  printf("Errore durante il caricamento della gui. Uscita");
  return 0;
 }
 gtk_main();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct Porcile porcile;
 srand(time(((void *)0)));
 printf("%s\n", "SirbonVille " "1.0");
 if(argc == 2)
 {
  if(!sv_load(&porcile, argv[1]))
  {
   printf("Impossibile caricare lo stato del gioco dal file %s.\n", argv[1]);
  }
  else
   printf("Stato del gioco caricato dal file %s\n", argv[1]);
 }
 gtk_init (&argc, &argv);
 if(!gui_create(&porcile))
 {
  printf("Errore durante il caricamento della gui. Uscita");
  return 0;
 }
 gtk_main();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct Porcile { unsigned int letame; unsigned int monete; unsigned int cibo; unsigned int tempo; unsigned int n_maiali; struct maiale_t { int eta; int peso; int salute; unsigned int fame; unsigned int bisogni; } maiali[10]; unsigned int sec4unit; }


repo: dakk/spiderpig-os

decompiled_code:
__int64 __fastcall network_iface_add(__int64 a1)
{
__int64 result; // rax
char *v2; // rax

debug_puts("network_iface_add()\n");
result = 1LL;
if ( a1 )
{
v2 = network_ifaces;
*(_BYTE *)(a1 + 50) = 0;
*(_QWORD *)(a1 + 56) = 0LL;
network_ifaces = (char *)a1;
*(_QWORD *)(a1 + 88) = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
char *v2; // rax

debug_puts("network_iface_add()\n");
result = 1LL;
if ( a1 )
{
v2 = network_ifaces;
*(_BYTE *)(a1 + 50) = 0;
*(_QWORD *)(a1 + 56) = 0LL;
network_ifaces = (char *)a1;
*(_QWORD *)(a1 + 88) = v2;
result = 0LL;
}
return result;
}

original_code:
uint32_t network_iface_add(network_iface_t *iface)
{
 debug_puts("network_iface_add()\n");
 if(iface != 0)
 {
  iface->next = network_ifaces;
  iface->if_up = 0;
  iface->tx_bytes = 0;
  iface->rx_bytes = 0;
  network_ifaces = iface;
  return 0;
 }
 return 1;
}

canonical_original_code:
unsigned int network_iface_add(struct network_iface_p *iface)
{
 debug_puts("network_iface_add()\n");
 if(iface != 0)
 {
  iface->next = network_ifaces;
  iface->if_up = 0;
  iface->tx_bytes = 0;
  iface->rx_bytes = 0;
  network_ifaces = iface;
  return 0;
 }
 return 1;
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *

return_type: unsigned int

user_defined_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; }

user_defined_types: struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t fs; struct driver_video_t video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; }

user_defined_types: struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; }