phafac

decompiled_code:
void __fastcall phafac(int a1, float *a2, int a3, float *a4, float *a5, float *a6, float a7, float *a8)
{
int v8; // ebx
__int64 v10; // r13
float *v12; // r15
float v13; // xmm0_4
float v14; // xmm2_4
float v15; // xmm1_4
float *v16; // rax
__int64 v17; // r9
int v18; // er10
char *v19; // r8
float *v20; // rax
int v21; // er9
float v22; // xmm0_4
float v23; // xmm2_4
float v24; // xmm1_4
float v25; // xmm2_4
float v26; // xmm0_4
float v27; // xmm6_4
float v28; // xmm0_4
float v29; // xmm4_4
float v30; // xmm3_4
float v31; // xmm3_4
float *v32; // rax
int v33; // edi
float v34; // xmm0_4
float v35; // xmm1_4
int v36; // edi
__int64 v37; // r8
float v38; // [rsp+10h] [rbp-98h]
float v39; // [rsp+18h] [rbp-90h]
float v41; // [rsp+20h] [rbp-88h]
float v42; // [rsp+24h] [rbp-84h]
float *v43; // [rsp+28h] [rbp-80h]
float v44; // [rsp+30h] [rbp-78h]
int v45; // [rsp+34h] [rbp-74h]
int v46; // [rsp+38h] [rbp-70h]
__int64 v48; // [rsp+40h] [rbp-68h]
__int64 v49; // [rsp+48h] [rbp-60h]
int v51; // [rsp+54h] [rbp-54h]
float *v52; // [rsp+58h] [rbp-50h]
double cosx; // [rsp+60h] [rbp-48h] BYREF
double sinx[8]; // [rsp+68h] [rbp-40h] BYREF

v52 = a6;
v8 = a1 / 2;
if ( a3 > 0 )
{
v10 = a1;
v49 = 4LL * a1 + 8;
v51 = 2 * a1;
v48 = 8LL * a1;
v43 = a6;
v12 = a8;
v46 = 2 * a1;
v45 = 1;
do
{
v41 = *a4;
v42 = a4[1];
v44 = a4[2];
sincos(
(float)((float)((float)((float)(*a4 * *a2) + (float)(v42 * a2[1])) + (float)(v44 * a2[2])) + a7),
sinx,
&cosx);
v25 = cosx;
v26 = sinx[0];
LODWORD(v38) = LODWORD(v26) ^ LC0;
sincos(
(float)((float)((float)((float)(v41 * a2[3]) + (float)(v42 * a2[4])) + (float)(v44 * a2[5])) + a7),
sinx,
&cosx);
v27 = cosx;
v28 = sinx[0];
LODWORD(v39) = LODWORD(v28) ^ LC0;
sincos(
(float)((float)((float)((float)(v41 * a2[6]) + (float)(v42 * a2[7])) + (float)(v44 * a2[8])) + a7),
sinx,
&cosx);
v29 = cosx;
v30 = sinx[0];
LODWORD(v31) = LODWORD(v30) ^ LC0;
*(_QWORD *)a5 = (unsigned int)LC1;
*(_QWORD *)v43 = (unsigned int)LC1;
*(_QWORD *)v12 = (unsigned int)LC1;
if ( a1 <= 1 )
{
v36 = v45;
}
else
{
v32 = a5;
v33 = 1;
do
{
v34 = *v32;
v35 = v32[1];
v32[2] = (float)(v25 * *v32) - (float)(v38 * v35);
v32[3] = (float)(v34 * v38) + (float)(v35 * v25);
v32 += 2;
++v33;
}
while ( v8 >= v33 );
v36 = v45;
v37 = 4LL * v46 - 8;
v17 = (__int64)v52 + v37;
v16 = v43;
v18 = 1;
do
{
v13 = *v16;
v14 = v16[1];
v15 = (float)(v27 * *v16) - (float)(v39 * v14);
v16[2] = v15;
v16[3] = (float)(v13 * v39) + (float)(v14 * v27);
*(float *)v17 = v15;
*(_DWORD *)(v17 + 4) = *((_DWORD *)v16 + 3) ^ LC0;
v16 += 2;
v17 -= 8LL;
++v18;
}
while ( v8 >= v18 );
v19 = (char *)a8 + v37;
v20 = v12;
v21 = 1;
do
{
v22 = *v20;
v23 = v20[1];
v24 = (float)(v29 * *v20) - (float)(v31 * v23);
v20[2] = v24;
v20[3] = (float)(v22 * v31) + (float)(v23 * v29);
*(float *)v19 = v24;
*((_DWORD *)v19 + 1) = *((_DWORD *)v20 + 3) ^ LC0;
v20 += 2;
v19 -= 8;
++v21;
}
while ( v8 >= v21 );
}
a5[v10] = 0.0;
a5[v10 + 1] = 0.0;
v43[v10] = 0.0;
v43[v10 + 1] = 0.0;
v12[v10] = 0.0;
v12[v10 + 1] = 0.0;
a4 += 3;
a5 = (float *)((char *)a5 + v49);
v43 = (float *)((char *)v43 + v48);
v12 = (float *)((char *)v12 + v48);
++v45;
v46 += v51;
}
while ( a3 > v36 );
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, float *a2, int a3, float *a4, float *a5, float *a6, float a7, float *a8)
{
int v8; // ebx
__int64 v10; // r13
float *v12; // r15
float v13; // xmm0_4
float v14; // xmm2_4
float v15; // xmm1_4
float *v16; // rax
__int64 v17; // r9
int v18; // er10
char *v19; // r8
float *v20; // rax
int v21; // er9
float v22; // xmm0_4
float v23; // xmm2_4
float v24; // xmm1_4
float v25; // xmm2_4
float v26; // xmm0_4
float v27; // xmm6_4
float v28; // xmm0_4
float v29; // xmm4_4
float v30; // xmm3_4
float v31; // xmm3_4
float *v32; // rax
int v33; // edi
float v34; // xmm0_4
float v35; // xmm1_4
int v36; // edi
__int64 v37; // r8
float v38; // [rsp+10h] [rbp-98h]
float v39; // [rsp+18h] [rbp-90h]
float v41; // [rsp+20h] [rbp-88h]
float v42; // [rsp+24h] [rbp-84h]
float *v43; // [rsp+28h] [rbp-80h]
float v44; // [rsp+30h] [rbp-78h]
int v45; // [rsp+34h] [rbp-74h]
int v46; // [rsp+38h] [rbp-70h]
__int64 v48; // [rsp+40h] [rbp-68h]
__int64 v49; // [rsp+48h] [rbp-60h]
int v51; // [rsp+54h] [rbp-54h]
float *v52; // [rsp+58h] [rbp-50h]
double cosx; // [rsp+60h] [rbp-48h] BYREF
double sinx[8]; // [rsp+68h] [rbp-40h] BYREF

v52 = a6;
v8 = a1 / 2;
if ( a3 > 0 )
{
v10 = a1;
v49 = 4LL * a1 + 8;
v51 = 2 * a1;
v48 = 8LL * a1;
v43 = a6;
v12 = a8;
v46 = 2 * a1;
v45 = 1;
do
{
v41 = *a4;
v42 = a4[1];
v44 = a4[2];
sincos(
(float)((float)((float)((float)(*a4 * *a2) + (float)(v42 * a2[1])) + (float)(v44 * a2[2])) + a7),
sinx,
&cosx);
v25 = cosx;
v26 = sinx[0];
LODWORD(v38) = LODWORD(v26) ^ LC0;
sincos(
(float)((float)((float)((float)(v41 * a2[3]) + (float)(v42 * a2[4])) + (float)(v44 * a2[5])) + a7),
sinx,
&cosx);
v27 = cosx;
v28 = sinx[0];
LODWORD(v39) = LODWORD(v28) ^ LC0;
sincos(
(float)((float)((float)((float)(v41 * a2[6]) + (float)(v42 * a2[7])) + (float)(v44 * a2[8])) + a7),
sinx,
&cosx);
v29 = cosx;
v30 = sinx[0];
LODWORD(v31) = LODWORD(v30) ^ LC0;
*(_QWORD *)a5 = (unsigned int)LC1;
*(_QWORD *)v43 = (unsigned int)LC1;
*(_QWORD *)v12 = (unsigned int)LC1;
if ( a1 <= 1 )
{
v36 = v45;
}
else
{
v32 = a5;
v33 = 1;
do
{
v34 = *v32;
v35 = v32[1];
v32[2] = (float)(v25 * *v32) - (float)(v38 * v35);
v32[3] = (float)(v34 * v38) + (float)(v35 * v25);
v32 += 2;
++v33;
}
while ( v8 >= v33 );
v36 = v45;
v37 = 4LL * v46 - 8;
v17 = (__int64)v52 + v37;
v16 = v43;
v18 = 1;
do
{
v13 = *v16;
v14 = v16[1];
v15 = (float)(v27 * *v16) - (float)(v39 * v14);
v16[2] = v15;
v16[3] = (float)(v13 * v39) + (float)(v14 * v27);
*(float *)v17 = v15;
*(_DWORD *)(v17 + 4) = *((_DWORD *)v16 + 3) ^ LC0;
v16 += 2;
v17 -= 8LL;
++v18;
}
while ( v8 >= v18 );
v19 = (char *)a8 + v37;
v20 = v12;
v21 = 1;
do
{
v22 = *v20;
v23 = v20[1];
v24 = (float)(v29 * *v20) - (float)(v31 * v23);
v20[2] = v24;
v20[3] = (float)(v22 * v31) + (float)(v23 * v29);
*(float *)v19 = v24;
*((_DWORD *)v19 + 1) = *((_DWORD *)v20 + 3) ^ LC0;
v20 += 2;
v19 -= 8;
++v21;
}
while ( v8 >= v21 );
}
a5[v10] = 0.0;
a5[v10 + 1] = 0.0;
v43[v10] = 0.0;
v43[v10 + 1] = 0.0;
v12[v10] = 0.0;
v12[v10 + 1] = 0.0;
a4 += 3;
a5 = (float *)((char *)a5 + v49);
v43 = (float *)((char *)v43 + v48);
v12 = (float *)((char *)v12 + v48);
++v45;
v46 += v51;
}
while ( a3 > v36 );
}
}

variable_types: nfft int

variable_types: pi float

variable_types:
unitg
float *

variable_types: nion int

variable_types: ii int

variable_types: k int

variable_types: nffth int

variable_types:
rex
float *

variable_types:
qex
float *


strfac

repo: ebylaska/Simple-CPSD

original_code:
void strfac(const int nfft,
               const float *ex1,
               const float *ex2,
               const float *ex3,
               float *exi)
{
   int i,j,k,ir,jr,kr,kk,nffth;
   nffth = nfft/2;
   kk = 0;
   kr = 0;
   for (k=0; k<nfft; ++k)
   {
      jr = 0;
      for (j=0; j<nfft; ++j)
      {
         ir = 0;
         for (i=0; i<=nffth; ++i)
         {
            exi[kk] = ex1[ir] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      - ex1[ir+1] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            exi[kk+1] = ex1[ir+1] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      + ex1[ir] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            kk += 2;
            ir +=2;
         }
         jr += 2;
      }
      kr +=2;
   }
}

canonical_original_code:
void strfac(int nfft, float *ex1, float *ex2, float *ex3, float *exi)
{
   int i; int j; int k; int ir; int jr; int kr; int kk; int nffth;
   nffth = nfft/2;
   kk = 0;
   kr = 0;
   for (k=0; k<nfft; ++k)
   {
      jr = 0;
      for (j=0; j<nfft; ++j)
      {
         ir = 0;
         for (i=0; i<=nffth; ++i)
         {
            exi[kk] = ex1[ir] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      - ex1[ir+1] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            exi[kk+1] = ex1[ir+1] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      + ex1[ir] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            kk += 2;
            ir +=2;
         }
         jr += 2;
      }
      kr +=2;
   }
}

variable_types:
exi
float *

variable_types: i int

variable_types: j int

variable_types: ir int

variable_types: jr int

variable_types: kr int

variable_types: kk int

return_type: void


original_code:
void get_masker(const int nfft, const float ggcut, const float *unitg, int *masker1)
{
   int i,j,k,k1,k2,k3,nffth,nfft3d,indx;
   float gx,gy,gz,gg;
   nfft3d = (nfft/2+1)*nfft*nfft;
   nffth = nfft/2;
   for (k=0; k<nfft3d; ++k) masker1[k] = 0;
   for (k3=(-nffth+1); k3<nffth; ++k3)
   for (k2=(-nffth+1); k2<nffth; ++k2)
   for (k1=0; k1<nffth; ++k1)
   {
     gx = k1*unitg[0] + k2*unitg[3] + k3*unitg[6];
     gy = k1*unitg[1] + k2*unitg[4] + k3*unitg[7];
     gz = k1*unitg[2] + k2*unitg[5] + k3*unitg[8];
     gg = gx*gx + gy*gy + gz*gz;
     i=k1; if (i<0) i += nfft;
     j=k2; if (j<0) j += nfft;
     k=k3; if (k<0) k += nfft;
     indx = i + j*(nffth+1) + k*(nffth+1)*nfft;
     if (gg < ggcut) masker1[indx] = 1;
   }
}

canonical_original_code:
void get_masker(int nfft, float ggcut, float *unitg, int *masker1)
{
   int i; int j; int k; int k1; int k2; int k3; int nffth; int nfft3d; int indx;
   float gx; float gy; float gz; float gg;
   nfft3d = (nfft/2+1)*nfft*nfft;
   nffth = nfft/2;
   for (k=0; k<nfft3d; ++k) masker1[k] = 0;
   for (k3=(-nffth+1); k3<nffth; ++k3)
   for (k2=(-nffth+1); k2<nffth; ++k2)
   for (k1=0; k1<nffth; ++k1)
   {
     gx = k1*unitg[0] + k2*unitg[3] + k3*unitg[6];
     gy = k1*unitg[1] + k2*unitg[4] + k3*unitg[7];
     gz = k1*unitg[2] + k2*unitg[5] + k3*unitg[8];
     gg = gx*gx + gy*gy + gz*gz;
     i=k1; if (i<0) i += nfft;
     j=k2; if (j<0) j += nfft;
     k=k3; if (k<0) k += nfft;
     indx = i + j*(nffth+1) + k*(nffth+1)*nfft;
     if (gg < ggcut) masker1[indx] = 1;
   }
}

variable_types: ggcut float

variable_types: indx int

variable_types: gx float

variable_types: gy float

variable_types: gz float

variable_types: gg float


eigsrt

canonical_original_code:
void eigsrt(float *D, float *V, int n)
{
   int i; int j; int k;
   float p;
   for (i=0; i<(n-1); ++i)
   {
      k = i;
      p = D[i];
      for(j=i+1; j<n; ++j)
         if (D[j]>=p)
         {
            k = j;
            p = D[j];
         }
      if (k!=i)
      {
         D[k] = D[i];
         D[i] = p;
         for (j=0; j<n; ++j)
         {
            p = V[j+i*n];
            V[j+i*n] = V[j+k*n];
            V[j+k*n] = p;
         }
      }
   }
}

variable_types:
D
float *

variable_types:
V
float *

variable_types: n int

variable_types: k int

variable_types: p float


gsdot

decompiled_code:
float __fastcall gsdot(int a1, __int64 a2, __int64 a3)
{
float v5; // [rsp+Ch] [rbp-2Ch]
int v6; // [rsp+10h] [rbp-28h] BYREF
int v7; // [rsp+14h] [rbp-24h] BYREF
int v8; // [rsp+18h] [rbp-20h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v6 = 1;
v7 = a1 / 2 + 1;
v9[0] = a1 * a1;
v8 = a1 * a1 * v7;
v5 = sdot_(&v8, a2, &v6, a3);
return v5 + v5 - sdot_(v9, a2, &v7, a3);
}

canonical_decompiled_code:
float __fastcall func0(int a1, __int64 a2, __int64 a3)
{
float v5; // [rsp+Ch] [rbp-2Ch]
int v6; // [rsp+10h] [rbp-28h] BYREF
int v7; // [rsp+14h] [rbp-24h] BYREF
int v8; // [rsp+18h] [rbp-20h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v6 = 1;
v7 = a1 / 2 + 1;
v9[0] = a1 * a1;
v8 = a1 * a1 * v7;
v5 = sdot_(&v8, a2, &v6, a3);
return v5 + v5 - sdot_(v9, a2, &v7, a3);
}

original_code:
float gsdot(const int nfft, const float *psi1, const float *psi2)
{
   int nfft2,nfft3,nffth2;
   int one=1;
   nffth2 = (nfft/2+1);
   nfft2 = nfft*nfft;
   nfft3 = (nfft/2+1)*nfft*nfft;
   return( 2.0*sdot_(&nfft3,psi1,&one,psi2,&one)
           - sdot_(&nfft2,psi1,&nffth2,psi2,&nffth2) );
}

canonical_original_code:
float gsdot(int nfft, float *psi1, float *psi2)
{
   int nfft2; int nfft3; int nffth2;
   int one = 1;
   nffth2 = (nfft/2+1);
   nfft2 = nfft*nfft;
   nfft3 = (nfft/2+1)*nfft*nfft;
   return( 2.0*sdot_(&nfft3,psi1,&one,psi2,&one)
           - sdot_(&nfft2,psi1,&nffth2,psi2,&nffth2) );
}

variable_types: nfft int

variable_types: one int

return_type: float


decompiled_code:
void __fastcall set_Vosko_beta(float a1)
{
beta = LODWORD(a1);
}

canonical_decompiled_code:
void __fastcall func0(float a1)
{
beta = LODWORD(a1);
}

original_code:
void set_Vosko_beta(float bb)
{
   beta = bb;
}

variable_types: bb float


Vosko

variable_types: ispin int

variable_types:
dn
float []

variable_types:
xcp
float []

variable_types:
xce
float *

variable_types: i int

variable_types: rs float

variable_types: nup float

variable_types: ndown float

variable_types: n float

variable_types: xi float

variable_types: x float

variable_types: xxp float

variable_types: dxxp float

variable_types: xxf float

variable_types: dxxf float

variable_types: f float

variable_types: df float

variable_types: denominator float


decompiled_code:
float current_second()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
return (double)SLODWORD(tv.tv_usec) * 0.000001 + (double)(LODWORD(tv.tv_sec) - 1236025000);
}

canonical_decompiled_code:
float func0()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
return (double)SLODWORD(tv.tv_usec) * 0.000001 + (double)(LODWORD(tv.tv_sec) - 1236025000);
}

original_code:
float current_second()
{
  struct timeval tp;
  struct timezone tz;
  double t0,t1,t2;
  gettimeofday(&tp,&tz);
  t0 = ((double) (tp.tv_sec-((long) 1236025000)));
  t0 += ((double) tp.tv_usec)*1e-6;
  return ((float) t0);
}

canonical_original_code:
float current_second()
{
  struct timeval tp;
  struct timezone tz;
  double t0; double t1; double t2;
  gettimeofday(&tp,&tz);
  t0 = ((double) (tp.tv_sec-((long) 1236025000)));
  t0 += ((double) tp.tv_usec)*1e-6;
  return ((float) t0);
}

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


message

decompiled_code:
int __fastcall message(int a1)
{
char *v1; // rsi
__int64 i; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

time(&timer);
v1 = ctime(&timer);
for ( i = 0LL; i != 25; ++i )
v5[i] = v1[i];
v5[24] = 0;
v5[25] = 0;
if ( a1 == 1 )
{
v1 = "job started";
LABEL_12:
if ( a1 == 4 )
{
v1 = "job completed";
return printf(" >>> %s on %s <<<\n", v1, v5);
}
goto LABEL_6;
}
if ( a1 != 2 )
{
if ( a1 == 3 )
{
v1 = "iteration ended";
return printf(" >>> %s on %s <<<\n", v1, v5);
}
goto LABEL_12;
}
v1 = "iteration started";
LABEL_6:
if ( a1 == 5 )
v1 = "job terminated";
return printf(" >>> %s on %s <<<\n", v1, v5);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
char *v1; // rsi
__int64 i; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

time(&timer);
v1 = ctime(&timer);
for ( i = 0LL; i != 25; ++i )
v5[i] = v1[i];
v5[24] = 0;
v5[25] = 0;
if ( a1 == 1 )
{
v1 = "job started";
LABEL_12:
if ( a1 == 4 )
{
v1 = "job completed";
return printf(" >>> %s on %s <<<\n", v1, v5);
}
goto LABEL_6;
}
if ( a1 != 2 )
{
if ( a1 == 3 )
{
v1 = "iteration ended";
return printf(" >>> %s on %s <<<\n", v1, v5);
}
goto LABEL_12;
}
v1 = "iteration started";
LABEL_6:
if ( a1 == 5 )
v1 = "job terminated";
return printf(" >>> %s on %s <<<\n", v1, v5);
}

original_code:
void message(const int n)
{
   int i;
   char *msg,date[26];
   time_t t0,t1;
   t1 = time(&t0);
   msg = ctime(&t0);
   for (i=0; i<25; ++i)
      date[i] = msg[i];
   date[24] = '\0';
   date[25] = '\0';
   if (n==1) msg = "job started";
   if (n==2) msg = "iteration started";
   if (n==3) msg = "iteration ended";
   if (n==4) msg = "job completed";
   if (n==5) msg = "job terminated";
   printf("          >>>   %s on %s    <<<\n",msg,date);
}

canonical_original_code:
void message(int n)
{
   int i;
   char *msg; char date[26];
   long t0; long t1;
   t1 = time(&t0);
   msg = ctime(&t0);
   for (i=0; i<25; ++i)
      date[i] = msg[i];
   date[24] = '\0';
   date[25] = '\0';
   if (n==1) msg = "job started";
   if (n==2) msg = "iteration started";
   if (n==3) msg = "iteration ended";
   if (n==4) msg = "job completed";
   if (n==5) msg = "job terminated";
   printf("          >>>   %s on %s    <<<\n",msg,date);
}

variable_types: n int

variable_types:
msg
char *

variable_types:
date
char [26]


dowork

repo: ecashin/low

decompiled_code:
void *__fastcall dowork(void *a1)
{
__int64 k; // rbp
int v2; // ecx
int v3; // eax
int v4; // ecx
int v5; // edx
__int64 i; // rax
__int64 j; // rax

switch ( type )
{
case 2:
for ( i = 0LL; niters > i; ++i )
_InterlockedAdd64((volatile signed __int64 *)a1 + 1, 1uLL);
break;
case 3:
if ( niters > 0 )
{
v2 = *((_DWORD *)a1 + 2);
v3 = v2 + 1;
v4 = v2 + niters + 1;
do
v5 = v3++;
while ( v3 != v4 );
*((_DWORD *)a1 + 2) = v5;
}
break;
case 1:
for ( j = 0LL; niters > j; ++j )
_InterlockedAdd64((volatile signed __int64 *)&count, 1uLL);
break;
default:
for ( k = 0LL; niters > k; ++k )
{
pthread_mutex_lock(&mutex);
++count;
pthread_mutex_unlock(&mutex);
}
break;
}
return a1;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
__int64 k; // rbp
int v2; // ecx
int v3; // eax
int v4; // ecx
int v5; // edx
__int64 i; // rax
__int64 j; // rax

switch ( type )
{
case 2:
for ( i = 0LL; niters > i; ++i )
_InterlockedAdd64((volatile signed __int64 *)a1 + 1, 1uLL);
break;
case 3:
if ( niters > 0 )
{
v2 = *((_DWORD *)a1 + 2);
v3 = v2 + 1;
v4 = v2 + niters + 1;
do
v5 = v3++;
while ( v3 != v4 );
*((_DWORD *)a1 + 2) = v5;
}
break;
case 1:
for ( j = 0LL; niters > j; ++j )
_InterlockedAdd64((volatile signed __int64 *)&count, 1uLL);
break;
default:
for ( k = 0LL; niters > k; ++k )
{
pthread_mutex_lock(&mutex);
++count;
pthread_mutex_unlock(&mutex);
}
break;
}
return a1;
}

original_code:
static void *
dowork(void *data)
{
 int i;
 struct tinfo *ti = (struct tinfo *) data;
 switch (type) {
 case LKADDSH:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (count)
         : "m" (count));
  break;
 case LKADDNO:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (ti->t.count)
         : "m" (ti->t.count));
  break;
 case ADDNO:
  for (i = 0; i < niters; ++i)
   ti->t.count += 1;
  break;
 case MUTEX:
 default:
  for (i = 0; i < niters; ++i) {
   pthread_mutex_lock(&mutex);
   count++;
   pthread_mutex_unlock(&mutex);
  }
  break;
 }
 return data;
}

canonical_original_code:
static void *dowork(void *data)
{
 int i;
 struct tinfo *ti = (struct tinfo *) data;
 switch (type) {
 case LKADDSH:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (count)
         : "m" (count));
  break;
 case LKADDNO:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (ti->t.count)
         : "m" (ti->t.count));
  break;
 case ADDNO:
  for (i = 0; i < niters; ++i)
   ti->t.count += 1;
  break;
 case MUTEX:
 default:
  for (i = 0; i < niters; ++i) {
   pthread_mutex_lock(&mutex);
   count++;
   pthread_mutex_unlock(&mutex);
  }
  break;
 }
 return data;
}

variable_types:
data
void *

variable_types: i int

variable_types: struct tinfo { union { struct perthread { unsigned long tinfo; unsigned int count; } t; char pad[64]; }; } *

return_type: void *

user_defined_types: struct tinfo { union { struct perthread t; char pad[64]; }; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
void *v4; // rax
void *v5; // r14
pthread_t *v6; // rbp
pthread_t *v7; // rbx
__int64 v8; // r12
const char *v9; // rsi
__int64 i; // rbx
char *endptr[8]; // [rsp+8h] [rbp-40h] BYREF

v3 = 10LL;
if ( argc > 1 )
{
v3 = strtol(argv[1], endptr, 0);
if ( argv[1] == endptr[0] )
exit(1);
}
niters = 10000LL;
if ( argc > 2 )
{
niters = strtol(argv[2], endptr, 0);
if ( argv[2] == endptr[0] )
exit(1);
}
type = 0;
if ( argc > 3 )
{
type = strtol(argv[3], endptr, 0);
if ( argv[3] == endptr[0] )
exit(1);
}
printf("%ld threads for %ld iterations, test type %d\n", v3, niters, (unsigned int)type);
if ( pthread_mutex_init(&mutex, 0LL) )
{
perror("pthread_mutex_init");
exit(1);
}
v4 = malloc(v3 << 6);
v5 = v4;
if ( !v4 )
{
perror("malloc");
exit(1);
}
v6 = (pthread_t *)v4;
v7 = (pthread_t *)v4;
v8 = 0LL;
if ( v3 > 0 )
{
while ( 1 )
{
if ( pthread_create(v7, 0LL, dowork, v7) )
{
perror("pthread_create");
exit(1);
}
v7 += 8;
if ( v3 == v8 + 1 )
break;
++v8;
}
for ( i = 0LL; ; ++i )
{
if ( pthread_join(*v6, 0LL) )
{
perror("pthead_join");
exit(1);
}
if ( (unsigned int)(type - 2) <= 1 )
count += *((_DWORD *)v6 + 2);
v6 += 8;
if ( i == v8 )
break;
}
}
pthread_mutex_destroy(&mutex);
free(v5);
v9 = (const char *)&unk_402004;
if ( niters * v3 != count )
v9 = "WRONG";
printf("%s: resulting count is %lu\n", v9, (unsigned int)count);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct tinfo *a;
 long int n;
 int i;
 char *end;
 n = 10;
 if (argc > 1) {
  n = strtol(argv[1], &end, 0);
  if (end == argv[1])
   exit(1);
 }
 niters = 10000;
 if (argc > 2) {
  niters = strtol(argv[2], &end, 0);
  if (end == argv[2])
   exit(1);
 }
 type = MUTEX;
 if (argc > 3) {
  type = (int) strtol(argv[3], &end, 0);
  if (end == argv[3])
   exit(1);
 }
 printf("%ld threads for %ld iterations, test type %d\n",
        n, niters, type);
 if (pthread_mutex_init(&mutex, ((void *)0))) {
  perror("pthread_mutex_init");
  exit(1);
 }
 a = malloc(n * sizeof *a);
 if (!a) {
  perror("malloc");
  exit(1);
 }
 for (i = 0; i < n; ++i)
  if (pthread_create(&a[i].t.tinfo, ((void *)0), dowork, &a[i])) {
   perror("pthread_create");
   exit(1);
  }
 for (i = 0; i < n; ++i) {
  if (pthread_join(a[i].t.tinfo, ((void *)0))) {
   perror("pthead_join");
   exit(1);
  }
  if (type == LKADDNO || type == ADDNO)
   count += a[i].t.count;
 }
 pthread_mutex_destroy(&mutex);
 free(a);
 printf("%s: resulting count is %lu\n",
        (n * niters) == count ? "OK" : "WRONG",
        (unsigned long) count);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct tinfo *a;
 long n;
 int i;
 char *end;
 n = 10;
 if (argc > 1) {
  n = strtol(argv[1], &end, 0);
  if (end == argv[1])
   exit(1);
 }
 niters = 10000;
 if (argc > 2) {
  niters = strtol(argv[2], &end, 0);
  if (end == argv[2])
   exit(1);
 }
 type = MUTEX;
 if (argc > 3) {
  type = (int) strtol(argv[3], &end, 0);
  if (end == argv[3])
   exit(1);
 }
 printf("%ld threads for %ld iterations, test type %d\n",
        n, niters, type);
 if (pthread_mutex_init(&mutex, ((void *)0))) {
  perror("pthread_mutex_init");
  exit(1);
 }
 a = malloc(n * sizeof *a);
 if (!a) {
  perror("malloc");
  exit(1);
 }
 for (i = 0; i < n; ++i)
  if (pthread_create(&a[i].t.tinfo, ((void *)0), dowork, &a[i])) {
   perror("pthread_create");
   exit(1);
  }
 for (i = 0; i < n; ++i) {
  if (pthread_join(a[i].t.tinfo, ((void *)0))) {
   perror("pthead_join");
   exit(1);
  }
  if (type == LKADDNO || type == ADDNO)
   count += a[i].t.count;
 }
 pthread_mutex_destroy(&mutex);
 free(a);
 printf("%s: resulting count is %lu\n",
        (n * niters) == count ? "OK" : "WRONG",
        (unsigned long) count);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n long

variable_types:
end
char *

return_type: int

user_defined_types: struct perthread { unsigned long tinfo; unsigned int count; }


pr

decompiled_code:
int __fastcall pr(_BYTE *a1)
{
_BYTE *v1; // rbx
_BYTE *v2; // rax

v1 = a1 + 9;
do
{
printf("%d%d", *v1 >> 4, *v1 & 0xF);
v2 = v1--;
}
while ( v2 != a1 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(_BYTE *a1)
{
_BYTE *v1; // rbx
_BYTE *v2; // rax

v1 = a1 + 9;
do
{
printf("%d%d", *v1 >> 4, *v1 & 0xF);
v2 = v1--;
}
while ( v2 != a1 );
return putchar(10);
}

original_code:
void pr(unsigned char *bcd)
{
 int i;
 for (i = 9; i >= 0; --i)
  printf("%d%d", bcd[i] >> 4 & 0xf, bcd[i] & 0xf);
 putchar('\n');
}

variable_types:
bcd
unsigned char *


main

original_code:
int main(void)
{
 float a = 0.1;
 float b = 0.2;
 unsigned char bcda[10] = {
  9<<4|9, 0,
 };
 unsigned char bcdb[10] = {
  1, 1, 0,
 };
 long double aa = 0.1, bb = 0.2;
 printf("sizeof long double: %lu\n", sizeof aa);
 printf("%g + %g = %g\n", a, b, a + b);
 printf("%Lg + %Lg = %Lg\n", aa, bb, aa + bb);
 pr(bcda);
 pr(bcdb);
 bcddemo(bcda, bcdb);
 pr(bcda);
 return 0;
}

canonical_original_code:
int main()
{
 float a = 0.1;
 float b = 0.2;
 unsigned char bcda[10] = {
  9<<4|9, 0,
 };
 unsigned char bcdb[10] = {
  1, 1, 0,
 };
 long double aa = 0.1; long double bb = 0.2;
 printf("sizeof long double: %lu\n", sizeof aa);
 printf("%g + %g = %g\n", a, b, a + b);
 printf("%Lg + %Lg = %Lg\n", aa, bb, aa + bb);
 pr(bcda);
 pr(bcdb);
 bcddemo(bcda, bcdb);
 pr(bcda);
 return 0;
}

variable_types: a float

variable_types: b float

variable_types:
bcda
unsigned char [10]

variable_types:
bcdb
unsigned char [10]

variable_types:
aa
long double

variable_types:
bb
long double


cbchar

decompiled_code:
__int64 __fastcall cbchar(unsigned __int8 a1)
{
unsigned __int8 v1; // al
unsigned int v2; // edx

v1 = a1;
if ( !a1 )
return 0;
v2 = 0;
do
{
v2 += v1 & 1;
v1 >>= 1;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
unsigned __int8 v1; // al
unsigned int v2; // edx

v1 = a1;
if ( !a1 )
return 0;
v2 = 0;
do
{
v2 += v1 & 1;
v1 >>= 1;
}
while ( v1 );
return v2;
}

original_code:
static inline int cbchar(unsigned char c)
{
 int b;
 for (b = 0; c; c >>= 1)
  b += c & 1;
 return b;
}

variable_types:
c
unsigned char

variable_types: b int


cntbits

decompiled_code:
__int64 __fastcall cntbits(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rbp
int v4; // er12
unsigned __int8 *v5; // r13
unsigned __int64 v6; // r14
unsigned int v7; // er12
unsigned __int8 *v8; // rbx

v2 = a1;
v3 = a2;
if ( a2 )
{
if ( ((unsigned __int8)a1 & 7) != 0 )
{
v4 = 0;
do
{
v4 += cbchar(*v2++);
--v3;
}
while ( v3 && ((unsigned __int8)v2 & 7) != 0 );
}
else
{
v4 = 0;
}
}
else
{
v4 = 0;
}
v5 = &v2[v3];
v6 = (int)ifloor(v3, 8);
v7 = countbits((unsigned __int64 *)v2, v6) + v4;
v8 = &v2[v6];
if ( v5 > v8 )
{
do
v7 += cbchar(*v8++);
while ( v5 != v8 );
}
return v7;
}

original_code:
static inline int cntbits(uint16_t *a, size_t n)
{
 int b = 0;
 unsigned char *p = (unsigned char *) a;
 unsigned char *e;
 const int blksiz = 8;
 for (; n > 0 && ((unsigned long) p) % blksiz; ++p, --n)
  b += cbchar(*p);
 e = &p[n];
 n = ifloor(e - p, blksiz);
 b += countbits((uint16_t *) p, n);
 for (p += n; p < e; ++p)
  b += cbchar(*p);
 return b;
}

canonical_original_code:
static inline int cntbits(unsigned short *a, unsigned long n)
{
 int b = 0;
 unsigned char *p = (unsigned char *) a;
 unsigned char *e;
 int blksiz = 8;
 for (; n > 0 && ((unsigned long) p) % blksiz; ++p, --n)
  b += cbchar(*p);
 e = &p[n];
 n = ifloor(e - p, blksiz);
 b += countbits((unsigned short *) p, n);
 for (p += n; p < e; ++p)
  b += cbchar(*p);
 return b;
}

variable_types:
a
unsigned short *

variable_types:
n
unsigned long

variable_types:
p
unsigned char *

variable_types:
e
unsigned char *

variable_types: blksiz int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rcx
__int64 v5; // rbx
int v6; // ebx
unsigned int v7; // eax
int v8; // ebp
__int64 v9; // rbx
__int16 v11; // [rsp+0h] [rbp-4E3Ah]
unsigned __int8 v12; // [rsp+2h] [rbp-4E38h] BYREF
unsigned __int8 v13[20023]; // [rsp+3h] [rbp-4E37h] BYREF

v3 = canpopcnt(argc, argv, envp);
v4 = 1LL;
v5 = 0LL;
if ( v3 )
{
while ( 1 )
{
*(&v11 + v4) = v4;
if ( (_DWORD)v4 )
{
v7 = v4;
do
{
v5 += v7 & 1;
v7 >>= 1;
}
while ( v7 );
if ( (unsigned int)v4 > 0x270F )
break;
}
++v4;
}
printf("initialized array with total of %lu bits set\n", v5);
printf("countbits with %lu bits set ... ", v5);
fflush(stdout);
if ( (int)cntbits(&v12, 20000LL) != v5 )
__assert_fail("n == m", "main.c", 0x45u, "main");
puts("ok.");
v8 = cbchar(v12);
v9 = v5 - ((int)cbchar(v13[19998]) + (__int64)v8);
printf("countbits on unaligned sub-array with %lu bits set ... ", v9);
fflush(stdout);
if ( v9 != (int)cntbits(v13, 19998LL) )
__assert_fail("n == m", "main.c", 0x4Eu, "main");
puts("ok.");
fwrite("zero-length input ... ", 1uLL, 0x16uLL, stdout);
fflush(stdout);
v6 = cntbits(&v12, 0LL);
if ( v6 )
__assert_fail("cntbits(a, 0) == 0", "main.c", 0x53u, "main");
puts("ok.");
}
else
{
fwrite("no POPCNT support in CPU\n", 1uLL, 0x19uLL, stderr);
v6 = 1;
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rcx
__int64 v5; // rbx
int v6; // ebx
unsigned int v7; // eax
int v8; // ebp
__int64 v9; // rbx
__int16 v11; // [rsp+0h] [rbp-4E3Ah]
unsigned __int8 v12; // [rsp+2h] [rbp-4E38h] BYREF
unsigned __int8 v13[20023]; // [rsp+3h] [rbp-4E37h] BYREF

v3 = func8(argc, argv, envp);
v4 = 1LL;
v5 = 0LL;
if ( v3 )
{
while ( 1 )
{
*(&v11 + v4) = v4;
if ( (_DWORD)v4 )
{
v7 = v4;
do
{
v5 += v7 & 1;
v7 >>= 1;
}
while ( v7 );
if ( (unsigned int)v4 > 0x270F )
break;
}
++v4;
}
printf("initialized array with total of %lu bits set\n", v5);
printf("countbits with %lu bits set ... ", v5);
fflush(stdout);
if ( (int)func11(&v12, 20000LL) != v5 )
__assert_fail("n == m", "main.c", 0x45u, "main");
puts("ok.");
v8 = func10(v12);
v9 = v5 - ((int)func10(v13[19998]) + (__int64)v8);
printf("countbits on unaligned sub-array with %lu bits set ... ", v9);
fflush(stdout);
if ( v9 != (int)func11(v13, 19998LL) )
__assert_fail("n == m", "main.c", 0x4Eu, "main");
puts("ok.");
fwrite("zero-length input ... ", 1uLL, 0x16uLL, stdout);
fflush(stdout);
v6 = func11(&v12, 0LL);
if ( v6 )
__assert_fail("cntbits(a, 0) == 0", "main.c", 0x53u, "main");
puts("ok.");
}
else
{
fwrite("no POPCNT support in CPU\n", 1uLL, 0x19uLL, stderr);
v6 = 1;
}
return v6;
}

original_code:
int main(void)
{
 int i;
 unsigned j;
 unsigned long n;
 unsigned long m;
 uint16_t a[10000];
 unsigned char *p;
 if (!canpopcnt()) {
  fprintf(stderr, "no POPCNT support in CPU\n");
  return 1;
 }
 for (i = 0, n = 0; i < sizeof a / sizeof a[0]; ++i) {
  j = i + 1;
  a[i] = j;
  while (j) {
   n += j & 1;
   j >>= 1;
  }
 }
 printf("initialized array with total of %lu bits set\n", n);
 m = n;
 printf("countbits with %lu bits set ... ", n);
 fflush(stdout);
 n = cntbits(a, sizeof a);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 p = (unsigned char *) a;
 m = n - cbchar(p[0]) - cbchar(p[(sizeof a) - 1]);
 printf("countbits on unaligned sub-array with %lu bits set ... ", m);
 fflush(stdout);
 n = cntbits((uint16_t *)(p+1), (sizeof a) - 2);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 fputs("zero-length input ... ", stdout);
 fflush(stdout);
 ((void) sizeof ((cntbits(a, 0) == 0) ? 1 : 0), __extension__ ({ if (cntbits(a, 0) == 0) ; else __assert_fail ("cntbits(a, 0) == 0", "main.c", 83, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 unsigned int j;
 unsigned long n;
 unsigned long m;
 unsigned short a[10000];
 unsigned char *p;
 if (!canpopcnt()) {
  fprintf(stderr, "no POPCNT support in CPU\n");
  return 1;
 }
 for (i = 0, n = 0; i < sizeof a / sizeof a[0]; ++i) {
  j = i + 1;
  a[i] = j;
  while (j) {
   n += j & 1;
   j >>= 1;
  }
 }
 printf("initialized array with total of %lu bits set\n", n);
 m = n;
 printf("countbits with %lu bits set ... ", n);
 fflush(stdout);
 n = cntbits(a, sizeof a);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 p = (unsigned char *) a;
 m = n - cbchar(p[0]) - cbchar(p[(sizeof a) - 1]);
 printf("countbits on unaligned sub-array with %lu bits set ... ", m);
 fflush(stdout);
 n = cntbits((unsigned short *)(p+1), (sizeof a) - 2);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 fputs("zero-length input ... ", stdout);
 fflush(stdout);
 ((void) sizeof ((cntbits(a, 0) == 0) ? 1 : 0), __extension__ ({ if (cntbits(a, 0) == 0) ; else __assert_fail ("cntbits(a, 0) == 0", "main.c", 83, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 return 0;
}

variable_types: i int

variable_types:
j
unsigned int

variable_types:
m
unsigned long

variable_types:
a
unsigned short [10000]


prfeature

decompiled_code:
int __fastcall prfeature(unsigned int a1, unsigned int a2)
{
const char *v2; // rcx

v2 = (const char *)&unk_402004;
if ( ((a1 >> a2) & 1) == 0 )
v2 = (const char *)&unk_402008;
return printf(" %46s (bit %2d): %s\n", features[a2], a2, v2);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2)
{
const char *v2; // rcx

v2 = (const char *)&unk_402004;
if ( ((a1 >> a2) & 1) == 0 )
v2 = (const char *)&unk_402008;
return printf(" %46s (bit %2d): %s\n", features[a2], a2, v2);
}

original_code:
void prfeature(unsigned int cpuid, int i)
{
 char *yes = cpuid >> i & 1 ? "yes" : "no";
 printf("  %46s (bit %2d): %s\n", features[i], i, yes);
}

variable_types:
cpuid
unsigned int

variable_types:
yes
char *


main

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

v3 = (unsigned int)cpuidfn(1LL);
printf("%016lx\n", v3);
v4 = (const char *)&unk_402004;
if ( (v3 & 0x80000) == 0 )
v4 = (const char *)&unk_402008;
printf("sse4.1: %s\n", v4);
v5 = (const char *)&unk_402004;
if ( (v3 & 0x100000) == 0 )
v5 = (const char *)&unk_402008;
printf("sse4.2: %s\n", v5);
v6 = (const char *)&unk_402004;
if ( (v3 & 0x800000) == 0 )
v6 = (const char *)&unk_402008;
printf("popcnt: %s\n", v6);
for ( i = 0; i != 31; ++i )
prfeature(v3, i);
return 0;
}

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

v3 = (unsigned int)func7(1LL);
printf("%016lx\n", v3);
v4 = (const char *)&unk_402004;
if ( (v3 & 0x80000) == 0 )
v4 = (const char *)&unk_402008;
printf("sse4.1: %s\n", v4);
v5 = (const char *)&unk_402004;
if ( (v3 & 0x100000) == 0 )
v5 = (const char *)&unk_402008;
printf("sse4.2: %s\n", v5);
v6 = (const char *)&unk_402004;
if ( (v3 & 0x800000) == 0 )
v6 = (const char *)&unk_402008;
printf("popcnt: %s\n", v6);
for ( i = 0; i != 31; ++i )
func8(v3, i);
return 0;
}

original_code:
int main(void)
{
 int i;
 unsigned long n = (unsigned long) cpuidfn(1);
 printf("%016lx\n", n);
 printf("sse4.1: %s\n", (n >> (19) & 1) ? "yes" : "no");
 printf("sse4.2: %s\n", (n >> (20) & 1) ? "yes" : "no");
 printf("popcnt: %s\n", (n >> (23) & 1) ? "yes" : "no");
 for (i = 0; i < sizeof features / sizeof features[0]; ++i)
  prfeature(n, i);
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 unsigned long n = (unsigned long) cpuidfn(1);
 printf("%016lx\n", n);
 printf("sse4.1: %s\n", (n >> (19) & 1) ? "yes" : "no");
 printf("sse4.2: %s\n", (n >> (20) & 1) ? "yes" : "no");
 printf("popcnt: %s\n", (n >> (23) & 1) ? "yes" : "no");
 for (i = 0; i < sizeof features / sizeof features[0]; ++i)
  prfeature(n, i);
 return 0;
}


loadstr

decompiled_code:
void *__fastcall loadstr(void *dest, void *src, size_t n)
{
size_t v4; // rax

memset(dest, 0, n);
v4 = strlen((const char *)src);
if ( n <= v4 )
v4 = n;
return memmove(dest, src, v4);
}

canonical_decompiled_code:
void *__fastcall func9(void *dest, void *src, size_t n)
{
size_t v4; // rax

memset(dest, 0, n);
v4 = strlen((const char *)src);
if ( n <= v4 )
v4 = n;
return memmove(dest, src, v4);
}

original_code:
void loadstr(char *buf, char *s, size_t m)
{
 size_t n;
 memset(buf, 0, m);
 n = strlen(s);
 if (n > m)
  n = m;
 memmove(buf, s, n);
}

canonical_original_code:
void loadstr(char *buf, char *s, unsigned long m)
{
 unsigned long n;
 memset(buf, 0, m);
 n = strlen(s);
 if (n > m)
  n = m;
 memmove(buf, s, n);
}

variable_types:
buf
char *

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
size_t v4; // rax
size_t v5; // rbx
size_t v6; // rbp
__int64 v7; // rdx
__int64 v8; // rax
char v10[24]; // [rsp+0h] [rbp-428h] BYREF
__int64 v11; // [rsp+18h] [rbp-410h]
char v12[480]; // [rsp+20h] [rbp-408h] BYREF
char s[17]; // [rsp+200h] [rbp-228h] BYREF
__int64 v14; // [rsp+218h] [rbp-210h]
char v15[480]; // [rsp+220h] [rbp-208h] BYREF

v3 = cpuidfn(1LL);
strcpy(s, "0123456789abcdef");
v14 = 0LL;
memset(v15, 0, sizeof(v15));
strcpy(v10, "01c3456789abCdef");
v11 = 0LL;
memset(v12, 0, sizeof(v12));
v4 = strlen(v10);
if ( (v3 & 0x100000) == 0 )
{
fwrite("cpuid says this CPU hasn't SSE 4.2\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v5 = v4;
if ( argc > 1 )
{
loadstr(s, (void *)argv[1], 0x1FFuLL);
v6 = strlen(s);
if ( argc > 2 )
{
loadstr(v10, (void *)argv[2], 0x1FFuLL);
v5 = strlen(v10);
}
}
else
{
v6 = strlen(s);
}
v7 = v6;
if ( v5 <= v6 )
v7 = v5;
v8 = diffidx((const __m128i *)s, (const __m128i *)v10, v7);
printf("\"%s\" and \"%s\" differ at byte index %lu\n", s, v10, v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
size_t v4; // rax
size_t v5; // rbx
size_t v6; // rbp
__int64 v7; // rdx
__int64 v8; // rax
char v10[24]; // [rsp+0h] [rbp-428h] BYREF
__int64 v11; // [rsp+18h] [rbp-410h]
char v12[480]; // [rsp+20h] [rbp-408h] BYREF
char s[17]; // [rsp+200h] [rbp-228h] BYREF
__int64 v14; // [rsp+218h] [rbp-210h]
char v15[480]; // [rsp+220h] [rbp-208h] BYREF

v3 = func8(1LL);
strcpy(s, "0123456789abcdef");
v14 = 0LL;
memset(v15, 0, sizeof(v15));
strcpy(v10, "01c3456789abCdef");
v11 = 0LL;
memset(v12, 0, sizeof(v12));
v4 = strlen(v10);
if ( (v3 & 0x100000) == 0 )
{
fwrite("cpuid says this CPU hasn't SSE 4.2\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v5 = v4;
if ( argc > 1 )
{
func9(s, (void *)argv[1], 0x1FFuLL);
v6 = strlen(s);
if ( argc > 2 )
{
func9(v10, (void *)argv[2], 0x1FFuLL);
v5 = strlen(v10);
}
}
else
{
v6 = strlen(s);
}
v7 = v6;
if ( v5 <= v6 )
v7 = v5;
v8 = func7((const __m128i *)s, (const __m128i *)v10, v7);
printf("\"%s\" and \"%s\" differ at byte index %lu\n", s, v10, v8);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 unsigned long n = (unsigned long) cpuidfn(1);
 char a[512] = "0123456789abcdef";
 char b[512] = "01c3456789abCdef";
 size_t alen = strlen(a);
 size_t blen = strlen(b);
 if ((n >> (20) & 1) == 0) {
  fputs("cpuid says this CPU hasn't SSE 4.2\n", stderr);
  exit(1);
 }
 if (argc > 1) {
  loadstr(a, argv[1], sizeof a - 1);
  alen = strlen(a);
 }
 if (argc > 2) {
  loadstr(b, argv[2], sizeof b - 1);
  blen = strlen(b);
 }
 printf("\"%s\" and \"%s\" differ at byte index %lu\n",
        a, b, diffidx(a, b, alen > blen ? blen : alen));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long n = (unsigned long) cpuidfn(1);
 char a[512] = "0123456789abcdef";
 char b[512] = "01c3456789abCdef";
 unsigned long alen = strlen(a);
 unsigned long blen = strlen(b);
 if ((n >> (20) & 1) == 0) {
  fputs("cpuid says this CPU hasn't SSE 4.2\n", stderr);
  exit(1);
 }
 if (argc > 1) {
  loadstr(a, argv[1], sizeof a - 1);
  alen = strlen(a);
 }
 if (argc > 2) {
  loadstr(b, argv[2], sizeof b - 1);
  blen = strlen(b);
 }
 printf("\"%s\" and \"%s\" differ at byte index %lu\n",
        a, b, diffidx(a, b, alen > blen ? blen : alen));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
char [512]

variable_types:
b
char [512]

variable_types:
alen
unsigned long

variable_types:
blen
unsigned long


repo: eceforge/vitasign

decompiled_code:
__int64 __fastcall int64_lo(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code: static inline uint32_t int64_lo(int64_t x) { return (x & ((1ULL << 32) - 1)); }

canonical_original_code: static inline unsigned int int64_lo(long x) { return (x & ((1ULL << 32) - 1)); }

variable_types: x long

return_type: unsigned int


decompiled_code:
__int64 __fastcall int64_add(__int64 a1, __int64 a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return a1 + a2;
}

original_code: static inline int64_t int64_add(int64_t x, int64_t y) { return (x + y); }

canonical_original_code: static inline long int64_add(long x, long y) { return (x + y); }

variable_types: y long

return_type: long


decompiled_code:
__int64 __fastcall int64_mul_i32_i32(int a1, int a2)
{
return a2 * a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
return a2 * a1;
}

original_code: static inline int64_t int64_mul_i32_i32(int32_t x, int32_t y) { return (x * y); }

canonical_original_code: static inline long int64_mul_i32_i32(int x, int y) { return (x * y); }

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall fix16_add(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 + a2);
if ( (a1 ^ a2) >= 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 + a2);
if ( (a1 ^ a2) >= 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

canonical_original_code:
int fix16_add(int a, int b)
{
  unsigned int _a = a; unsigned int _b = b;
  unsigned int sum = _a + _b;
  if (!((_a ^ _b) & 0x80000000) && ((_a ^ sum) & 0x80000000))
    return fix16_overflow;
  return sum;
}

variable_types: a int

variable_types: b int

variable_types:
sum
unsigned int


decompiled_code:
__int64 __fastcall fix16_sub(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 - a2);
if ( (a1 ^ a2) < 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 - a2);
if ( (a1 ^ a2) < 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

original_code:
fix16_t fix16_sub(fix16_t a, fix16_t b)
{
  uint32_t _a = a, _b = b;
  uint32_t diff = _a - _b;
  if (((_a ^ _b) & 0x80000000) && ((_a ^ diff) & 0x80000000))
    return fix16_overflow;
  return diff;
}

canonical_original_code:
int fix16_sub(int a, int b)
{
  unsigned int _a = a; unsigned int _b = b;
  unsigned int diff = _a - _b;
  if (((_a ^ _b) & 0x80000000) && ((_a ^ diff) & 0x80000000))
    return fix16_overflow;
  return diff;
}

variable_types:
diff
unsigned int


decompiled_code:
__int64 __fastcall fix16_sadd(int a1, int a2)
{
__int64 result; // rax

result = fix16_add(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
__int64 result; // rax

result = func4(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_sadd(fix16_t a, fix16_t b)
{
  fix16_t result = fix16_add(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}

canonical_original_code:
int fix16_sadd(int a, int b)
{
  int result = fix16_add(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}

variable_types: result int


decompiled_code:
__int64 __fastcall fix16_ssub(int a1, int a2)
{
__int64 result; // rax

result = fix16_sub(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
__int64 result; // rax

result = func5(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_ssub(fix16_t a, fix16_t b)
{
  fix16_t result = fix16_sub(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}

canonical_original_code:
int fix16_ssub(int a, int b)
{
  int result = fix16_sub(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}


original_code:
fix16_t fix16_mul(fix16_t inArg0, fix16_t inArg1)
{
  int64_t product = (int64_t)inArg0 * inArg1;
  uint32_t upper = (product >> 47);
  if (product < 0)
  {
    if (~upper)
        return fix16_overflow;
    product--;
  }
  else
  {
    if (upper)
        return fix16_overflow;
  }
  fix16_t result = product >> 16;
  result += (product & 0x8000) >> 15;
  return result;
}

canonical_original_code:
int fix16_mul(int inArg0, int inArg1)
{
  long product = (int64_t)inArg0 * inArg1;
  unsigned int upper = (product >> 47);
  if (product < 0)
  {
    if (~upper)
        return fix16_overflow;
    product--;
  }
  else
  {
    if (upper)
        return fix16_overflow;
  }
  int result = product >> 16;
  result += (product & 0x8000) >> 15;
  return result;
}

variable_types: product long

variable_types:
upper
unsigned int


decompiled_code:
__int64 __fastcall fix16_smul(int a1, int a2)
{
__int64 result; // rax

result = fix16_mul(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
__int64 result; // rax

result = func8(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_smul(fix16_t inArg0, fix16_t inArg1) {
  fix16_t result = fix16_mul(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}

canonical_original_code:
int fix16_smul(int inArg0, int inArg1) {
  int result = fix16_mul(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}


original_code:
fix16_t fix16_div(fix16_t a, fix16_t b)
{
  if (b == 0)
      return fix16_min;
  uint32_t remainder = (a >= 0) ? a : (-a);
  uint32_t divider = (b >= 0) ? b : (-b);
  uint32_t quotient = 0;
  int bit_pos = 17;
  if (divider & 0xFFF00000)
  {
    uint32_t shifted_div = ((divider >> 17) + 1);
    quotient = remainder / shifted_div;
    remainder -= ((uint64_t)quotient * divider) >> 17;
  }
  while (!(divider & 0xF) && bit_pos >= 4)
  {
    divider >>= 4;
    bit_pos -= 4;
  }
  while (remainder && bit_pos >= 0)
  {
    int shift = __builtin_clzl(remainder);
    if (shift > bit_pos) shift = bit_pos;
    remainder <<= shift;
    bit_pos -= shift;
    uint32_t div = remainder / divider;
    remainder = remainder % divider;
    quotient += div << bit_pos;
    if (div & ~(0xFFFFFFFF >> bit_pos))
        return fix16_overflow;
    remainder <<= 1;
    bit_pos--;
  }
  quotient++;
  fix16_t result = quotient >> 1;
  if ((a ^ b) & 0x80000000)
  {
    if (result == fix16_min)
        return fix16_overflow;
    result = -result;
  }
  return result;
}

canonical_original_code:
int fix16_div(int a, int b)
{
  if (b == 0)
      return fix16_min;
  unsigned int remainder = (a >= 0) ? a : (-a);
  unsigned int divider = (b >= 0) ? b : (-b);
  unsigned int quotient = 0;
  int bit_pos = 17;
  if (divider & 0xFFF00000)
  {
    unsigned int shifted_div = ((divider >> 17) + 1);
    quotient = remainder / shifted_div;
    remainder -= ((unsigned long)quotient * divider) >> 17;
  }
  while (!(divider & 0xF) && bit_pos >= 4)
  {
    divider >>= 4;
    bit_pos -= 4;
  }
  while (remainder && bit_pos >= 0)
  {
    int shift = __builtin_clzl(remainder);
    if (shift > bit_pos) shift = bit_pos;
    remainder <<= shift;
    bit_pos -= shift;
    unsigned int div = remainder / divider;
    remainder = remainder % divider;
    quotient += div << bit_pos;
    if (div & ~(0xFFFFFFFF >> bit_pos))
        return fix16_overflow;
    remainder <<= 1;
    bit_pos--;
  }
  quotient++;
  int result = quotient >> 1;
  if ((a ^ b) & 0x80000000)
  {
    if (result == fix16_min)
        return fix16_overflow;
    result = -result;
  }
  return result;
}

variable_types:
remainder
unsigned int

variable_types:
divider
unsigned int

variable_types:
quotient
unsigned int

variable_types: shift int

variable_types:
div
unsigned int


decompiled_code:
__int64 __fastcall fix16_sdiv(int a1, int a2)
{
__int64 result; // rax

result = fix16_div(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

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

result = func10(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1) {
  fix16_t result = fix16_div(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}

canonical_original_code:
int fix16_sdiv(int inArg0, int inArg1) {
  int result = fix16_div(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}


decompiled_code:
__int64 __fastcall fix16_lerp8(int a1, int a2, unsigned __int8 a3)
{
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = a3;
v4 = int64_mul_i32_i32(a1, 256 - (unsigned int)a3);
v5 = int64_mul_i32_i32(a2, v3);
v6 = int64_add(v4, v5);
v7 = int64_shift(v6, -8);
return int64_lo(v7);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2, unsigned __int8 a3)
{
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = a3;
v4 = func3(a1, 256 - (unsigned int)a3);
v5 = func3(a2, v3);
v6 = func1(v4, v5);
v7 = func2(v6, -8);
return func0(v7);
}

original_code:
fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract) {
 int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -8);
 return (fix16_t)int64_lo(tempOut);
}

canonical_original_code:
int fix16_lerp8(int inArg0, int inArg1, unsigned char inFract) {
 long tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -8);
 return (int)int64_lo(tempOut);
}

variable_types:
inFract
unsigned char

variable_types: tempOut long


decompiled_code:
__int64 __fastcall fix16_lerp16(int a1, int a2, unsigned __int16 a3)
{
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = a3;
v4 = int64_mul_i32_i32(a1, 0x10000 - (unsigned int)a3);
v5 = int64_mul_i32_i32(a2, v3);
v6 = int64_add(v4, v5);
v7 = int64_shift(v6, -16);
return int64_lo(v7);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2, unsigned __int16 a3)
{
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = a3;
v4 = func3(a1, 0x10000 - (unsigned int)a3);
v5 = func3(a2, v3);
v6 = func1(v4, v5);
v7 = func2(v6, -16);
return func0(v7);
}

original_code:
fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract) {
 int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -16);
 return (fix16_t)int64_lo(tempOut);
}

canonical_original_code:
int fix16_lerp16(int inArg0, int inArg1, unsigned short inFract) {
 long tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -16);
 return (int)int64_lo(tempOut);
}

variable_types:
inFract
unsigned short


decompiled_code:
__int64 __fastcall fix16_lerp32(int a1, int a2, unsigned int a3)
{
return (__int64)(a2 * (unsigned __int64)a3 + -a3 * (__int64)a1) >> 32;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, unsigned int a3)
{
return (__int64)(a2 * (unsigned __int64)a3 + -a3 * (__int64)a1) >> 32;
}

original_code:
fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract) {
 int64_t tempOut;
 tempOut = ((int64_t)inArg0 * (0 - inFract));
 tempOut += ((int64_t)inArg1 * inFract);
 tempOut >>= 32;
 return (fix16_t)tempOut;
}

canonical_original_code:
int fix16_lerp32(int inArg0, int inArg1, unsigned int inFract) {
 long tempOut;
 tempOut = ((long)inArg0 * (0 - inFract));
 tempOut += ((long)inArg1 * inFract);
 tempOut >>= 32;
 return (int)tempOut;
}

variable_types:
inFract
unsigned int


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

result = 0xFFFFFFFFLL;
if ( a2 > a1 )
result = a1 % a2 * (0xFFFFFFFF / (a2 - 1));
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a2 > a1 )
result = a1 % a2 * (0xFFFFFFFF / (a2 - 1));
return result;
}

original_code:
fract32_t fract32_create(uint32_t inNumerator, uint32_t inDenominator) {
 if(inDenominator <= inNumerator)
  return 0xFFFFFFFF;
 uint32_t tempMod = (inNumerator % inDenominator);
 uint32_t tempDiv = (0xFFFFFFFF / (inDenominator - 1));
 return (tempMod * tempDiv);
}

canonical_original_code:
unsigned int fract32_create(unsigned int inNumerator, unsigned int inDenominator) {
 if(inDenominator <= inNumerator)
  return 0xFFFFFFFF;
 unsigned int tempMod = (inNumerator % inDenominator);
 unsigned int tempDiv = (0xFFFFFFFF / (inDenominator - 1));
 return (tempMod * tempDiv);
}

variable_types:
inNumerator
unsigned int

variable_types:
inDenominator
unsigned int

variable_types:
tempMod
unsigned int

variable_types:
tempDiv
unsigned int


decompiled_code:
__int64 __fastcall fract32_invert(int a1)
{
return (unsigned int)~a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)~a1;
}

original_code:
fract32_t fract32_invert(fract32_t inFract) {
 return (0xFFFFFFFF - inFract);
}

canonical_original_code:
unsigned int fract32_invert(unsigned int inFract) {
 return (0xFFFFFFFF - inFract);
}


decompiled_code:
unsigned __int64 __fastcall fract32_usmul(unsigned int a1, unsigned int a2)
{
return (a2 * (unsigned __int64)a1) >> 32;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return (a2 * (unsigned __int64)a1) >> 32;
}

original_code:
uint32_t fract32_usmul(uint32_t inVal, fract32_t inFract) {
 return (uint32_t)(((uint64_t)inVal * (uint64_t)inFract) >> 32);
}

canonical_original_code:
unsigned int fract32_usmul(unsigned int inVal, unsigned int inFract) {
 return (unsigned int)(((unsigned long)inVal * (unsigned long)inFract) >> 32);
}

variable_types:
inVal
unsigned int


decompiled_code:
unsigned __int64 __fastcall fract32_smul(signed int a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
result = (unsigned int)-(__int64)fract32_usmul(-a1, a2);
else
result = fract32_usmul(a1, a2);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(signed int a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
result = (unsigned int)-(__int64)func2(-a1, a2);
else
result = func2(a1, a2);
return result;
}

original_code:
int32_t fract32_smul(int32_t inVal, fract32_t inFract) {
 if(inVal < 0)
  return -fract32_usmul(-inVal, inFract);
 return fract32_usmul(inVal, inFract);
}

canonical_original_code:
int fract32_smul(int inVal, unsigned int inFract) {
 if(inVal < 0)
  return -fract32_usmul(-inVal, inFract);
 return fract32_usmul(inVal, inFract);
}

variable_types: inVal int


decompiled_code:
__int64 __fastcall fix16_sin_parabola(int a1)
{
int v1; // ebx
unsigned int v2; // eax
int v3; // ebx
int v4; // eax

v1 = fix16_mul(83443LL, (unsigned int)a1);
v2 = fix16_mul(4294940736LL, (unsigned int)a1);
v3 = fix16_mul(v2, (a1 >> 31) ^ (unsigned int)(a1 + (a1 >> 31))) + v1;
v4 = fix16_mul((unsigned int)v3, (v3 >> 31) ^ (unsigned int)(v3 + (v3 >> 31)));
return v3 + (unsigned int)fix16_mul(14746LL, (unsigned int)(v4 - v3));
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebx
unsigned int v2; // eax
int v3; // ebx
int v4; // eax

v1 = fix16_mul(83443LL, (unsigned int)a1);
v2 = fix16_mul(4294940736LL, (unsigned int)a1);
v3 = fix16_mul(v2, (a1 >> 31) ^ (unsigned int)(a1 + (a1 >> 31))) + v1;
v4 = fix16_mul((unsigned int)v3, (v3 >> 31) ^ (unsigned int)(v3 + (v3 >> 31)));
return v3 + (unsigned int)fix16_mul(14746LL, (unsigned int)(v4 - v3));
}

original_code:
fix16_t fix16_sin_parabola(fix16_t inAngle)
{
 fix16_t abs_inAngle, abs_retval, retval;
 fix16_t mask;
 mask = (inAngle >> (sizeof(fix16_t)*8 -1));
 abs_inAngle = (inAngle + mask) ^ mask;
 retval = fix16_mul(FOUR_DIV_PI, inAngle) + fix16_mul( fix16_mul(_FOUR_DIV_PI2, inAngle), abs_inAngle );
 mask = (retval >> (sizeof(fix16_t)*8 -1));
 abs_retval = (retval + mask) ^ mask;
 retval += fix16_mul(X4_CORRECTION_COMPONENT, fix16_mul(retval, abs_retval) - retval );
 return retval;
}

canonical_original_code:
int fix16_sin_parabola(int inAngle)
{
 int abs_inAngle; int abs_retval; int retval;
 int mask;
 mask = (inAngle >> (sizeof(fix16_t)*8 -1));
 abs_inAngle = (inAngle + mask) ^ mask;
 retval = fix16_mul(FOUR_DIV_PI, inAngle) + fix16_mul( fix16_mul(_FOUR_DIV_PI2, inAngle), abs_inAngle );
 mask = (retval >> (sizeof(fix16_t)*8 -1));
 abs_retval = (retval + mask) ^ mask;
 retval += fix16_mul(X4_CORRECTION_COMPONENT, fix16_mul(retval, abs_retval) - retval );
 return retval;
}

variable_types: inAngle int

variable_types: retval int

variable_types: mask int


decompiled_code:
__int64 __fastcall fix16_sin(int a1)
{
unsigned int v1; // ebx
int v2; // er12
unsigned int v3; // er13
unsigned int v4; // eax
unsigned int v5; // er14
unsigned int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // eax
unsigned int v9; // er14
unsigned int v10; // eax
__int64 result; // rax

v1 = a1 % 411774;
if ( a1 % 411774 <= 205887 )
{
if ( (int)v1 < -205887 )
v1 += 411774;
}
else
{
v1 -= 411774;
}
v2 = (a1 >> 5) & 0xFFF;
if ( fix16_sin_cache_index[v2] == a1 )
return (unsigned int)fix16_sin_cache_value[v2];
v3 = fix16_mul(v1, v1);
v4 = fix16_mul(v1, v3);
v5 = v1 + (int)v4 / -6;
v6 = fix16_mul(v4, v3);
v7 = v5 + (int)v6 / 120;
v8 = fix16_mul(v6, v3);
v9 = v7 + (int)v8 / -5040;
v10 = fix16_mul(v8, v3);
result = (int)v10 / 362880 + v9 + (int)fix16_mul(v10, v3) / -39916800;
fix16_sin_cache_index[v2] = a1;
fix16_sin_cache_value[v2] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // ebx
int v2; // er12
unsigned int v3; // er13
unsigned int v4; // eax
unsigned int v5; // er14
unsigned int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // eax
unsigned int v9; // er14
unsigned int v10; // eax
__int64 result; // rax

v1 = a1 % 411774;
if ( a1 % 411774 <= 205887 )
{
if ( (int)v1 < -205887 )
v1 += 411774;
}
else
{
v1 -= 411774;
}
v2 = (a1 >> 5) & 0xFFF;
if ( fix16_sin_cache_index[v2] == a1 )
return (unsigned int)fix16_sin_cache_value[v2];
v3 = fix16_mul(v1, v1);
v4 = fix16_mul(v1, v3);
v5 = v1 + (int)v4 / -6;
v6 = fix16_mul(v4, v3);
v7 = v5 + (int)v6 / 120;
v8 = fix16_mul(v6, v3);
v9 = v7 + (int)v8 / -5040;
v10 = fix16_mul(v8, v3);
result = (int)v10 / 362880 + v9 + (int)fix16_mul(v10, v3) / -39916800;
fix16_sin_cache_index[v2] = a1;
fix16_sin_cache_value[v2] = result;
return result;
}

original_code:
fix16_t fix16_sin(fix16_t inAngle) {
 fix16_t tempAngle = inAngle % (fix16_pi << 1);
 if(tempAngle > fix16_pi)
  tempAngle -= (fix16_pi << 1);
 else if(tempAngle < -fix16_pi)
  tempAngle += (fix16_pi << 1);
 fix16_t tempIndex = ((inAngle >> 5) & 0x00000FFF);
 if(_fix16_sin_cache_index[tempIndex] == inAngle)
  return _fix16_sin_cache_value[tempIndex];
 fix16_t tempAngleSq = fix16_mul(tempAngle, tempAngle);
 fix16_t tempOut = tempAngle;
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut -= (tempAngle / 6);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut += (tempAngle / 120);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut -= (tempAngle / 5040);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut += (tempAngle / 362880);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut -= (tempAngle / 39916800);
 _fix16_sin_cache_index[tempIndex] = inAngle;
 _fix16_sin_cache_value[tempIndex] = tempOut;
 return tempOut;
}

canonical_original_code:
int fix16_sin(int inAngle) {
 int tempAngle = inAngle % (fix16_pi << 1);
 if(tempAngle > fix16_pi)
  tempAngle -= (fix16_pi << 1);
 else if(tempAngle < -fix16_pi)
  tempAngle += (fix16_pi << 1);
 int tempIndex = ((inAngle >> 5) & 0x00000FFF);
 if(_fix16_sin_cache_index[tempIndex] == inAngle)
  return _fix16_sin_cache_value[tempIndex];
 int tempAngleSq = fix16_mul(tempAngle, tempAngle);
 int tempOut = tempAngle;
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut -= (tempAngle / 6);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut += (tempAngle / 120);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut -= (tempAngle / 5040);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut += (tempAngle / 362880);
 tempAngle = fix16_mul(tempAngle, tempAngleSq);
 tempOut -= (tempAngle / 39916800);
 _fix16_sin_cache_index[tempIndex] = inAngle;
 _fix16_sin_cache_value[tempIndex] = tempOut;
 return tempOut;
}

variable_types: tempAngle int

variable_types: tempIndex int

variable_types: tempAngleSq int

variable_types: tempOut int


decompiled_code:
__int64 __fastcall fix16_cos(int a1)
{
return fix16_sin(a1 + 102943);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return func1(a1 + 102943);
}

original_code:
fix16_t fix16_cos(fix16_t inAngle) {
 return fix16_sin(inAngle + (fix16_pi >> 1));
}

canonical_original_code:
int fix16_cos(int inAngle) {
 return fix16_sin(inAngle + (fix16_pi >> 1));
}


decompiled_code:
__int64 __fastcall fix16_tan(int a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

v1 = fix16_cos(a1);
v2 = fix16_sin(a1);
return fix16_sdiv(v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

v1 = func2(a1);
v2 = func1(a1);
return fix16_sdiv(v2, v1);
}

original_code:
fix16_t fix16_tan(fix16_t inAngle) {
 return fix16_sdiv(fix16_sin(inAngle), fix16_cos(inAngle));
}

canonical_original_code:
int fix16_tan(int inAngle) {
 return fix16_sdiv(fix16_sin(inAngle), fix16_cos(inAngle));
}


decompiled_code:
__int64 __fastcall fix16_atan2(int a1, int a2)
{
__int64 v3; // rbp
int v4; // edi
unsigned int v5; // er14
unsigned int v6; // eax
unsigned int v7; // eax
int v8; // ebx
__int64 result; // rax
unsigned int v10; // er14
unsigned int v11; // eax
unsigned int v12; // eax
int v13; // ebx

v3 = ((unsigned __int16)(a1 ^ a2) ^ (unsigned __int16)((unsigned __int64)(a1 ^ a2) >> 20)) & 0xFFF;
if ( fix16_atan_cache_index[v3] == a2 && dword_8380[v3] == a1 )
return (unsigned int)fix16_atan_cache_value[v3];
v4 = (a1 >> 31) ^ (a1 + (a1 >> 31));
if ( a2 < 0 )
{
v10 = fix16_div((unsigned int)(a2 + v4), (unsigned int)(v4 - a2));
v11 = fix16_mul(v10, v10);
v12 = fix16_mul(v11, v10);
v13 = fix16_mul(12864LL, v12);
result = v13 - (unsigned int)fix16_mul(64336LL, v10) + 154415;
}
else
{
v5 = fix16_div((unsigned int)(a2 - v4), (unsigned int)(a2 + v4));
v6 = fix16_mul(v5, v5);
v7 = fix16_mul(v6, v5);
v8 = fix16_mul(12864LL, v7);
result = v8 - (unsigned int)fix16_mul(64336LL, v5) + 51471;
}
if ( a1 < 0 )
result = (unsigned int)-(int)result;
fix16_atan_cache_index[v3] = a2;
dword_8380[v3] = a1;
fix16_atan_cache_value[v3] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
__int64 v3; // rbp
int v4; // edi
unsigned int v5; // er14
unsigned int v6; // eax
unsigned int v7; // eax
int v8; // ebx
__int64 result; // rax
unsigned int v10; // er14
unsigned int v11; // eax
unsigned int v12; // eax
int v13; // ebx

v3 = ((unsigned __int16)(a1 ^ a2) ^ (unsigned __int16)((unsigned __int64)(a1 ^ a2) >> 20)) & 0xFFF;
if ( fix16_atan_cache_index[v3] == a2 && dword_8380[v3] == a1 )
return (unsigned int)fix16_atan_cache_value[v3];
v4 = (a1 >> 31) ^ (a1 + (a1 >> 31));
if ( a2 < 0 )
{
v10 = fix16_div((unsigned int)(a2 + v4), (unsigned int)(v4 - a2));
v11 = fix16_mul(v10, v10);
v12 = fix16_mul(v11, v10);
v13 = fix16_mul(12864LL, v12);
result = v13 - (unsigned int)fix16_mul(64336LL, v10) + 154415;
}
else
{
v5 = fix16_div((unsigned int)(a2 - v4), (unsigned int)(a2 + v4));
v6 = fix16_mul(v5, v5);
v7 = fix16_mul(v6, v5);
v8 = fix16_mul(12864LL, v7);
result = v8 - (unsigned int)fix16_mul(64336LL, v5) + 51471;
}
if ( a1 < 0 )
result = (unsigned int)-(int)result;
fix16_atan_cache_index[v3] = a2;
dword_8380[v3] = a1;
fix16_atan_cache_value[v3] = result;
return result;
}

original_code:
fix16_t fix16_atan2(fix16_t inY , fix16_t inX) {
 fix16_t abs_inY, mask, angle, r, r_3;
 uintptr_t hash = (inX ^ inY);
 hash ^= hash >> 20;
 hash &= 0x0FFF;
 if((_fix16_atan_cache_index[0][hash] == inX) && (_fix16_atan_cache_index[1][hash] == inY))
  return _fix16_atan_cache_value[hash];
 mask = (inY >> (sizeof(fix16_t)*8 -1));
 abs_inY = (inY + mask) ^ mask;
 if (inX >= 0)
 {
  r = fix16_div( (inX - abs_inY), (inX + abs_inY));
  r_3 = fix16_mul(fix16_mul(r, r),r);
  angle = fix16_mul(0x00003240 , r_3) - fix16_mul(0x0000FB50,r) + PI_DIV_4;
 } else {
  r = fix16_div( (inX + abs_inY), (abs_inY - inX));
  r_3 = fix16_mul(fix16_mul(r, r),r);
  angle = fix16_mul(0x00003240 , r_3) - fix16_mul(0x0000FB50,r) + THREE_PI_DIV_4;
 }
 if (inY < 0)
 {
  angle = -angle;
 }
 _fix16_atan_cache_index[0][hash] = inX;
 _fix16_atan_cache_index[1][hash] = inY;
 _fix16_atan_cache_value[hash] = angle;
 return angle;
}

canonical_original_code:
int fix16_atan2(int inY, int inX) {
 int abs_inY; int mask; int angle; int r; int r_3;
 unsigned long hash = (inX ^ inY);
 hash ^= hash >> 20;
 hash &= 0x0FFF;
 if((_fix16_atan_cache_index[0][hash] == inX) && (_fix16_atan_cache_index[1][hash] == inY))
  return _fix16_atan_cache_value[hash];
 mask = (inY >> (sizeof(fix16_t)*8 -1));
 abs_inY = (inY + mask) ^ mask;
 if (inX >= 0)
 {
  r = fix16_div( (inX - abs_inY), (inX + abs_inY));
  r_3 = fix16_mul(fix16_mul(r, r),r);
  angle = fix16_mul(0x00003240 , r_3) - fix16_mul(0x0000FB50,r) + PI_DIV_4;
 } else {
  r = fix16_div( (inX + abs_inY), (abs_inY - inX));
  r_3 = fix16_mul(fix16_mul(r, r),r);
  angle = fix16_mul(0x00003240 , r_3) - fix16_mul(0x0000FB50,r) + THREE_PI_DIV_4;
 }
 if (inY < 0)
 {
  angle = -angle;
 }
 _fix16_atan_cache_index[0][hash] = inX;
 _fix16_atan_cache_index[1][hash] = inY;
 _fix16_atan_cache_value[hash] = angle;
 return angle;
}

variable_types: inY int

variable_types: inX int

variable_types: angle int

variable_types: r int

variable_types:
hash
unsigned long


decompiled_code:
__int64 __fastcall fix16_atan(int a1)
{
return fix16_atan2(a1, (int)&unk_10000);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return func4(a1, (int)&unk_10000);
}

original_code:
fix16_t fix16_atan(fix16_t inValue) {
 return fix16_atan2(inValue, fix16_one);
}

canonical_original_code:
int fix16_atan(int inValue) {
 return fix16_atan2(inValue, fix16_one);
}

variable_types: inValue int


decompiled_code:
__int64 __fastcall fix16_asin(__int64 a1)
{
__int64 result; // rax
int v2; // eax
unsigned int v3; // eax
int v4; // eax

result = 0LL;
if ( (unsigned int)((unsigned int)&unk_10000 + a1) <= 0x20000 )
{
v2 = fix16_mul(a1, (unsigned int)a1);
v3 = fix16_sqrt((unsigned int)((_DWORD)&unk_10000 - v2));
v4 = fix16_div((unsigned int)a1, v3);
result = fix16_atan(v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
int v2; // eax
unsigned int v3; // eax
int v4; // eax

result = 0LL;
if ( (unsigned int)((unsigned int)&unk_10000 + a1) <= 0x20000 )
{
v2 = fix16_mul(a1, (unsigned int)a1);
v3 = fix16_sqrt((unsigned int)((_DWORD)&unk_10000 - v2));
v4 = fix16_div((unsigned int)a1, v3);
result = func5(v4);
}
return result;
}

original_code:
fix16_t fix16_asin(fix16_t inValue) {
 if((inValue > fix16_one) || (inValue < -fix16_one))
  return 0;
 fix16_t tempOut;
 tempOut = (fix16_one - fix16_mul(inValue, inValue));
 tempOut = fix16_div(inValue, fix16_sqrt(tempOut));
 tempOut = fix16_atan(tempOut);
 return tempOut;
}

canonical_original_code:
int fix16_asin(int inValue) {
 if((inValue > fix16_one) || (inValue < -fix16_one))
  return 0;
 int tempOut;
 tempOut = (fix16_one - fix16_mul(inValue, inValue));
 tempOut = fix16_div(inValue, fix16_sqrt(tempOut));
 tempOut = fix16_atan(tempOut);
 return tempOut;
}


decompiled_code:
__int64 __fastcall fix16_acos(__int64 a1)
{
return 102943 - (unsigned int)fix16_asin(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return 102943 - (unsigned int)func6(a1);
}

original_code:
fix16_t fix16_acos(fix16_t inValue) {
 return ((fix16_pi >> 1) - fix16_asin(inValue));
}

canonical_original_code:
int fix16_acos(int inValue) {
 return ((fix16_pi >> 1) - fix16_asin(inValue));
}


original_code:
uint32_t uint32_log2(uint32_t inVal) {
 if(inVal == 0)
  return 0;
 uint32_t tempOut = 0;
 if(inVal >= (1 << 16)) { inVal >>= 16; tempOut += 16; }
 if(inVal >= (1 << 8)) { inVal >>= 8; tempOut += 8; }
 if(inVal >= (1 << 4)) { inVal >>= 4; tempOut += 4; }
 if(inVal >= (1 << 2)) { inVal >>= 2; tempOut += 2; }
 if(inVal >= (1 << 1)) { tempOut += 1; }
 return tempOut;
}

canonical_original_code:
unsigned int uint32_log2(unsigned int inVal) {
 if(inVal == 0)
  return 0;
 unsigned int tempOut = 0;
 if(inVal >= (1 << 16)) { inVal >>= 16; tempOut += 16; }
 if(inVal >= (1 << 8)) { inVal >>= 8; tempOut += 8; }
 if(inVal >= (1 << 4)) { inVal >>= 4; tempOut += 4; }
 if(inVal >= (1 << 2)) { inVal >>= 2; tempOut += 2; }
 if(inVal >= (1 << 1)) { tempOut += 1; }
 return tempOut;
}

variable_types:
tempOut
unsigned int


original_code:
fix16_t fix16_sqrt(fix16_t inValue) {
  uint8_t neg = (inValue < 0);
  uint32_t num = (neg ? -inValue : inValue);
  uint32_t result = 0;
  uint32_t bit;
  uint8_t n;
  if (num & 0xFFF00000)
    bit = (uint32_t)1 << 30;
  else
    bit = (uint32_t)1 << 18;
  while (bit > num) bit >>= 2;
  for (n = 0; n < 2; n++)
  {
    while (bit)
    {
      if (num >= result + bit)
      {
        num -= result + bit;
        result = (result >> 1) + bit;
      }
      else
      {
        result = (result >> 1);
      }
      bit >>= 2;
    }
    if (n == 0)
    {
      if (num > 65535)
      {
        num -= result;
        num = (num << 16) - 0x8000;
        result = (result << 16) + 0x8000;
      }
      else
      {
        num <<= 16;
        result <<= 16;
      }
      bit = 1 << 14;
    }
  }
  if (num > result)
  {
    result++;
  }
  return (neg ? -result : result);
}

canonical_original_code:
int fix16_sqrt(int inValue) {
  unsigned char neg = (inValue < 0);
  unsigned int num = (neg ? -inValue : inValue);
  unsigned int result = 0;
  unsigned int bit;
  unsigned char n;
  if (num & 0xFFF00000)
    bit = (unsigned int)1 << 30;
  else
    bit = (unsigned int)1 << 18;
  while (bit > num) bit >>= 2;
  for (n = 0; n < 2; n++)
  {
    while (bit)
    {
      if (num >= result + bit)
      {
        num -= result + bit;
        result = (result >> 1) + bit;
      }
      else
      {
        result = (result >> 1);
      }
      bit >>= 2;
    }
    if (n == 0)
    {
      if (num > 65535)
      {
        num -= result;
        num = (num << 16) - 0x8000;
        result = (result << 16) + 0x8000;
      }
      else
      {
        num <<= 16;
        result <<= 16;
      }
      bit = 1 << 14;
    }
  }
  if (num > result)
  {
    result++;
  }
  return (neg ? -result : result);
}

variable_types:
neg
unsigned char

variable_types:
num
unsigned int

variable_types:
result
unsigned int

variable_types:
bit
unsigned int

variable_types:
n
unsigned char


decompiled_code:
__int64 __fastcall int64_from_int32(int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return a1;
}

original_code: static inline int64_t int64_from_int32(int32_t x) { return (int64_t)x; }

canonical_original_code: static inline long int64_from_int32(int x) { return (long)x; }

variable_types: x int


decompiled_code:
__int64 __fastcall int64_lo(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1;
}

original_code: static inline uint32_t int64_lo(int64_t x) { return (x & ((1ULL << 32) - 1)); }

canonical_original_code: static inline unsigned int int64_lo(long x) { return (x & ((1ULL << 32) - 1)); }

variable_types: x long


decompiled_code:
__int64 __fastcall int64_add(__int64 a1, __int64 a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return a1 + a2;
}

original_code: static inline int64_t int64_add(int64_t x, int64_t y) { return (x + y); }

canonical_original_code: static inline long int64_add(long x, long y) { return (x + y); }

variable_types: y long


decompiled_code:
__int64 __fastcall int64_mul_i64_i32(__int64 a1, int a2)
{
return a1 * a2;
}

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

original_code: static inline int64_t int64_mul_i64_i32(int64_t x, int32_t y) { return (x * y); }

canonical_original_code: static inline long int64_mul_i64_i32(long x, int y) { return (x * y); }

variable_types: y int


decompiled_code:
__int64 __fastcall int64_div_i64_i32(__int64 a1, int a2)
{
return a1 / a2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
return a1 / a2;
}

original_code: static inline int64_t int64_div_i64_i32(int64_t x, int32_t y) { return (x / y); }

canonical_original_code: static inline long int64_div_i64_i32(long x, int y) { return (x / y); }


decompiled_code:
__int64 __fastcall fix16_exp(int a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // r15
int v6; // er14
int i; // er12
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax

result = 0x10000LL;
if ( a1 )
{
if ( a1 == 0x10000 )
{
result = 178145LL;
}
else
{
result = 0x7FFFFFFFLL;
if ( a1 <= 681391 )
{
result = 0LL;
if ( a1 >= -726817 )
{
if ( fix16_exp_cache_index[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF] == a1 )
{
result = (unsigned int)fix16_exp_cache_value[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF];
}
else
{
v2 = int64_from_int32(a1);
v3 = int64_from_int32(0x10000);
v4 = int64_add(v3, v2);
v5 = int64_from_int32(0x8000);
v6 = 2;
for ( i = 3; i != 13; ++i )
{
v8 = int64_mul_i64_i32(v2, a1);
v9 = int64_add(v8, v5);
v2 = int64_shift(v9, -16);
v10 = int64_div_i64_i32(v2, v6);
v11 = int64_add(v4, v10);
v4 = v11;
v6 *= i;
}
fix16_exp_cache_index[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF] = a1;
result = int64_lo(v11);
fix16_exp_cache_value[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF] = result;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // r15
int v6; // er14
int i; // er12
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax

result = 0x10000LL;
if ( a1 )
{
if ( a1 == 0x10000 )
{
result = 178145LL;
}
else
{
result = 0x7FFFFFFFLL;
if ( a1 <= 681391 )
{
result = 0LL;
if ( a1 >= -726817 )
{
if ( fix16_exp_cache_index[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF] == a1 )
{
result = (unsigned int)fix16_exp_cache_value[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF];
}
else
{
v2 = func0(a1);
v3 = func0(0x10000);
v4 = func2(v3, v2);
v5 = func0(0x8000);
v6 = 2;
for ( i = 3; i != 13; ++i )
{
v8 = func4(v2, a1);
v9 = func2(v8, v5);
v2 = func3(v9, -16);
v10 = func5(v2, v6);
v11 = func2(v4, v10);
v4 = v11;
v6 *= i;
}
fix16_exp_cache_index[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF] = a1;
result = func1(v11);
fix16_exp_cache_value[((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF] = result;
}
}
}
}
}
return result;
}

original_code:
fix16_t fix16_exp(fix16_t inValue) {
 if(inValue == 0)
  return fix16_one;
 if(inValue == fix16_one)
  return fix16_e;
 if(inValue > 681391)
  return fix16_max;
 if(inValue < -726817)
  return 0;
 fix16_t tempIndex = (inValue ^ (inValue >> 16));
 tempIndex = (inValue ^ (inValue >> 4)) & 0x0FFF;
 if(_fix16_exp_cache_index[tempIndex] == inValue)
  return _fix16_exp_cache_value[tempIndex];
 int64_t tempOut = int64_add(int64_from_int32(fix16_one), int64_from_int32(inValue));
 int64_t tempValue = int64_from_int32(inValue);
 uint32_t i, n;
 for(i = 3, n = 2; i < 13; n *= i, i++) {
  tempValue = int64_mul_i64_i32(tempValue, inValue);
  tempValue = int64_add(tempValue, int64_from_int32(fix16_one >> 1));
  tempValue = int64_shift(tempValue, -16);
  tempOut = int64_add(tempOut, int64_div_i64_i32(tempValue, n));
 }
 _fix16_exp_cache_index[tempIndex] = inValue;
 _fix16_exp_cache_value[tempIndex] = int64_lo(tempOut);
 return int64_lo(tempOut);
}

canonical_original_code:
int fix16_exp(int inValue) {
 if(inValue == 0)
  return fix16_one;
 if(inValue == fix16_one)
  return fix16_e;
 if(inValue > 681391)
  return fix16_max;
 if(inValue < -726817)
  return 0;
 int tempIndex = (inValue ^ (inValue >> 16));
 tempIndex = (inValue ^ (inValue >> 4)) & 0x0FFF;
 if(_fix16_exp_cache_index[tempIndex] == inValue)
  return _fix16_exp_cache_value[tempIndex];
 long tempOut = int64_add(int64_from_int32(fix16_one), int64_from_int32(inValue));
 long tempValue = int64_from_int32(inValue);
 unsigned int i; unsigned int n;
 for(i = 3, n = 2; i < 13; n *= i, i++) {
  tempValue = int64_mul_i64_i32(tempValue, inValue);
  tempValue = int64_add(tempValue, int64_from_int32(fix16_one >> 1));
  tempValue = int64_shift(tempValue, -16);
  tempOut = int64_add(tempOut, int64_div_i64_i32(tempValue, n));
 }
 _fix16_exp_cache_index[tempIndex] = inValue;
 _fix16_exp_cache_value[tempIndex] = int64_lo(tempOut);
 return int64_lo(tempOut);
}

variable_types: tempIndex int

variable_types: tempOut long

variable_types: tempValue long

variable_types:
i
unsigned int

variable_types:
n
unsigned int


avlcmp

repo: echoline/NeoIRCD

decompiled_code:
__int64 avlcmp()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
int avlcmp(Avl *l, Avl *r) {
 return 0;
}

canonical_original_code:
int avlcmp(struct Avl *l, struct Avl *r) {
 return 0;
}

variable_types: struct Avl { struct Avl *p; struct Avl *n[2]; int bal; } *

variable_types:
r
struct Avl *


hashf

decompiled_code:
__int64 __fastcall hashf(__int64 a1, char a2)
{
return a1 & ((1 << a2) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
return a1 & ((1 << a2) - 1);
}

original_code:
unsigned long hashf(Avl *k, unsigned int order) {
 return ((unsigned long int)k & ((1 << order) - 1));
}

canonical_original_code:
unsigned long hashf(struct Avl *k, unsigned int order) {
 return ((unsigned long)k & ((1 << order) - 1));
}

variable_types:
order
unsigned int

return_type: unsigned long

user_defined_types: struct Avl { struct Avl *p; struct Avl *n[2]; int bal; }


main

repo: echoline/kinectfs

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
int v5; // eax
int v6; // eax
int v7; // ebp
struct stat v8; // [rsp+0h] [rbp-A8h] BYREF

v3 = malloc(0x12C000uLL);
if ( argc == 2 )
{
while ( 1 )
{
v6 = open(argv[1], 0);
v7 = v6;
if ( v6 < 0 || (unsigned int)fstat(v6, &v8) )
break;
printf("--ffserver\r\nContent-Type: image/jpeg\r\nContent-Length: %ld\r\n\r\n", v8.st_size);
fflush(stdout);
while ( 1 )
{
v5 = read(v7, v3, 0x12C000uLL);
if ( v5 <= 0 )
break;
write(1, v3, v5);
}
fflush(stdout);
close(v7);
}
}
else
{
fprintf(stderr, "usage:\n\t%s /path/to/jpg\n", *argv);
}
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
int v5; // eax
int v6; // eax
int v7; // ebp
struct stat v8; // [rsp+0h] [rbp-A8h] BYREF

v3 = malloc(0x12C000uLL);
if ( argc == 2 )
{
while ( 1 )
{
v6 = open(argv[1], 0);
v7 = v6;
if ( v6 < 0 || (unsigned int)func9(v6, &v8) )
break;
printf("--ffserver\r\nContent-Type: image/jpeg\r\nContent-Length: %ld\r\n\r\n", v8.st_size);
fflush(stdout);
while ( 1 )
{
v5 = read(v7, v3, 0x12C000uLL);
if ( v5 <= 0 )
break;
write(1, v3, v5);
}
fflush(stdout);
close(v7);
}
}
else
{
fprintf(stderr, "usage:\n\t%s /path/to/jpg\n", *argv);
}
return -1;
}

original_code:
int
main(int argc, char **argv) {
 int o;
 int rc;
 unsigned char *bbuf = malloc(640*480*4);
 struct stat statbuf;
 if (argc != 2) {
  fprintf(stderr, "usage:\n\t%s /path/to/jpg\n", argv[0]);
  return -1;
 }
 while (1) {
  o = open(argv[1], 00);
  if (o < 0)
   return -1;
  if (fstat(o, &statbuf) != 0)
   return -1;
  printf("--ffserver\r\nContent-Type: image/jpeg\r\nContent-Length: %ld\r\n\r\n", statbuf.st_size);
  fflush(stdout);
  while ((rc = read(o, bbuf, 640*480*4)) > 0)
   write(1, bbuf, rc);
  fflush(stdout);
  close(o);
 }
 free(bbuf);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: o int

variable_types: rc int

variable_types:
bbuf
unsigned char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


usage

repo: eclesh/slowtail

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "usage: %s <filename>\n", a1);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
return fprintf(stderr, "usage: %s <filename>\n", a1);
}

original_code:
void usage(char *progname)
{
 fprintf(stderr, "usage: %s <filename>\n", progname);
}

variable_types:
progname
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char *v4; // r12
size_t v5; // rax
size_t v6; // rax
int result; // eax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
__int64 v14; // [rsp+0h] [rbp-428h] BYREF
__int64 v15; // [rsp+8h] [rbp-420h] BYREF
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

v3 = *argv;
if ( argc == 2 )
{
v4 = (char *)argv[1];
if ( strlen(v4) + 8 > 0x400 )
{
fprintf(stderr, "%s: filename too long (max is %ld)\n", v3, 1016LL);
result = 1;
}
else
{
v5 = strlen(s);
strncat(s, v4, 1023 - v5);
v6 = strlen(s);
strncat(s, ".offset", 1023 - v6);
if ( (unsigned int)read_offset(s, &v15, &v14) )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s: can't open offset file: %s\n", v3, v11);
result = 1;
}
else if ( print_logs(v4, (__ino_t *)&v15, &v14) )
{
v12 = __errno_location();
v13 = strerror(*v12);
fprintf(stderr, "%s: can't read '%s': %s\n", v3, v4, v13);
result = 1;
}
else
{
result = write_offset(s, v15, v14);
if ( result )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "%s: can't write offset file: %s\n", v3, v9);
result = 1;
}
}
}
}
else
{
fwrite("no filename specified\n", 1uLL, 0x16uLL, stderr);
usage(v3);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char *v4; // r12
size_t v5; // rax
size_t v6; // rax
int result; // eax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
__int64 v14; // [rsp+0h] [rbp-428h] BYREF
__int64 v15; // [rsp+8h] [rbp-420h] BYREF
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

v3 = *argv;
if ( argc == 2 )
{
v4 = (char *)argv[1];
if ( strlen(v4) + 8 > 0x400 )
{
fprintf(stderr, "%s: filename too long (max is %ld)\n", v3, 1016LL);
result = 1;
}
else
{
v5 = strlen(s);
strncat(s, v4, 1023 - v5);
v6 = strlen(s);
strncat(s, ".offset", 1023 - v6);
if ( (unsigned int)func7(s, &v15, &v14) )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s: can't open offset file: %s\n", v3, v11);
result = 1;
}
else if ( func9(v4, (__ino_t *)&v15, &v14) )
{
v12 = __errno_location();
v13 = strerror(*v12);
fprintf(stderr, "%s: can't read '%s': %s\n", v3, v4, v13);
result = 1;
}
else
{
result = func8(s, v15, v14);
if ( result )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "%s: can't write offset file: %s\n", v3, v9);
result = 1;
}
}
}
}
else
{
fwrite("no filename specified\n", 1uLL, 0x16uLL, stderr);
func10(v3);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 char offset_file[1024];
 char *file_name, *prog;
 ino_t inode;
 off_t offset;
 prog = argv[0];
 if (argc != 2) {
  fprintf(stderr, "no filename specified\n");
  usage(prog);
  return 1;
 }
 file_name = argv[1];
 if (strlen(".offset") + strlen(file_name) + 1 > 1024) {
  fprintf(stderr, "%s: filename too long (max is %ld)\n",
   prog, 1024 - strlen(".offset") - 1);
  return 1;
 }
 strncat(offset_file, file_name,
  sizeof(offset_file) - strlen(offset_file) - 1);
 strncat(offset_file, ".offset",
  sizeof(offset_file) - strlen(offset_file) - 1);
 if (read_offset(offset_file, &inode, &offset) != 0) {
  fprintf(stderr, "%s: can't open offset file: %s\n",
   prog, strerror((*__errno_location ())));
  return 1;
 }
 if (print_logs(file_name, &inode, &offset) != 0) {
  fprintf(stderr, "%s: can't read '%s': %s\n",
   prog, file_name, strerror((*__errno_location ())));
  return 1;
 }
 if (write_offset(offset_file, inode, offset) != 0) {
  fprintf(stderr, "%s: can't write offset file: %s\n",
   prog, strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char offset_file[1024];
 char *file_name; char *prog;
 unsigned long inode;
 long offset;
 prog = argv[0];
 if (argc != 2) {
  fprintf(stderr, "no filename specified\n");
  usage(prog);
  return 1;
 }
 file_name = argv[1];
 if (strlen(".offset") + strlen(file_name) + 1 > 1024) {
  fprintf(stderr, "%s: filename too long (max is %ld)\n",
   prog, 1024 - strlen(".offset") - 1);
  return 1;
 }
 strncat(offset_file, file_name,
  sizeof(offset_file) - strlen(offset_file) - 1);
 strncat(offset_file, ".offset",
  sizeof(offset_file) - strlen(offset_file) - 1);
 if (read_offset(offset_file, &inode, &offset) != 0) {
  fprintf(stderr, "%s: can't open offset file: %s\n",
   prog, strerror((*__errno_location ())));
  return 1;
 }
 if (print_logs(file_name, &inode, &offset) != 0) {
  fprintf(stderr, "%s: can't read '%s': %s\n",
   prog, file_name, strerror((*__errno_location ())));
  return 1;
 }
 if (write_offset(offset_file, inode, offset) != 0) {
  fprintf(stderr, "%s: can't write offset file: %s\n",
   prog, strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}

variable_types:
prog
char *

variable_types:
inode
unsigned long

variable_types: offset long


parent

decompiled_code:
void __fastcall __noreturn parent(void *a1)
{
while ( 1 )
{
pthread_mutex_lock(&mutex_cond);
if ( !pthread_cond_wait(&var_cond, &mutex_cond) )
{
worms = rand() % 7 + 1;
printf("\nParent %s put %d worms on plate.\n", (const char *)a1 + 4, (unsigned int)worms);
}
pthread_mutex_unlock(&mutex_cond);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
while ( 1 )
{
pthread_mutex_lock(&mutex_cond);
if ( !pthread_cond_wait(&var_cond, &mutex_cond) )
{
worms = rand() % 7 + 1;
printf("\nParent %s put %d worms on plate.\n", (const char *)a1 + 4, (unsigned int)worms);
}
pthread_mutex_unlock(&mutex_cond);
}
}

original_code:
void *parent(void *dad){
    struct DATA *aa = (struct DATA *)dad ;
    while(1){
        pthread_mutex_lock(&mutex_cond);
        if(pthread_cond_wait(&var_cond, &mutex_cond) == 0){
            worms = (rand()%7)+1;
            printf("\nParent %s put %d worms on plate.\n", aa->name, worms);
        }
        pthread_mutex_unlock(&mutex_cond);
    }
}

canonical_original_code:
void *parent(void *dad){
    struct DATA *aa = (struct DATA *)dad;
    while(1){
        pthread_mutex_lock(&mutex_cond);
        if(pthread_cond_wait(&var_cond, &mutex_cond) == 0){
            worms = (rand()%7)+1;
            printf("\nParent %s put %d worms on plate.\n", aa->name, worms);
        }
        pthread_mutex_unlock(&mutex_cond);
    }
}

variable_types:
dad
void *

variable_types: struct DATA { int num; char name[10]; } *


decompiled_code:
void __fastcall __noreturn child_handler(void *a1)
{
int v1; // eax

while ( 1 )
{
do
{
v1 = rand();
sleep(v1 % 4);
}
while ( worms <= 0 );
pthread_mutex_lock(&mutex_cond);
if ( !--worms )
pthread_cond_signal(&var_cond);
printf("Bird N:%d take a worm. Remain %d worms\n", *(unsigned int *)a1, (unsigned int)worms);
pthread_mutex_unlock(&mutex_cond);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
int v1; // eax

while ( 1 )
{
do
{
v1 = rand();
sleep(v1 % 4);
}
while ( worms <= 0 );
pthread_mutex_lock(&mutex_cond);
if ( !--worms )
pthread_cond_signal(&var_cond);
printf("Bird N:%d take a worm. Remain %d worms\n", *(unsigned int *)a1, (unsigned int)worms);
pthread_mutex_unlock(&mutex_cond);
}
}

original_code:
void *child_handler(void *data){
    struct DATA *aa = (struct DATA *)data ;
    while(1){
        sleep(rand()%4);
        if(worms > 0){
                pthread_mutex_lock(&mutex_cond);
            worms-- ;
            if(worms == 0){
                pthread_cond_signal(&var_cond);
            }
            printf("Bird N:%d take a worm. Remain %d worms\n",aa->num, worms);
                pthread_mutex_unlock(&mutex_cond);
        }
    }
}

canonical_original_code:
void *child_handler(void *data){
    struct DATA *aa = (struct DATA *)data;
    while(1){
        sleep(rand()%4);
        if(worms > 0){
                pthread_mutex_lock(&mutex_cond);
            worms-- ;
            if(worms == 0){
                pthread_cond_signal(&var_cond);
            }
            printf("Bird N:%d take a worm. Remain %d worms\n",aa->num, worms);
                pthread_mutex_unlock(&mutex_cond);
        }
    }
}

variable_types:
data
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // r12
__int64 i; // rbp
pthread_t *v5; // rbx
int v7; // [rsp+0h] [rbp-138h] BYREF
__int64 v8; // [rsp+4h] [rbp-134h]
__int16 v9; // [rsp+Ch] [rbp-12Ch]
unsigned int arg[40]; // [rsp+10h] [rbp-128h] BYREF
pthread_t v11[10]; // [rsp+B0h] [rbp-88h] BYREF
__int64 v12; // [rsp+100h] [rbp-38h] BYREF
pthread_t newthread[6]; // [rsp+108h] [rbp-30h] BYREF

pthread_mutex_init(&sem, 0LL);
pthread_mutex_init(&mutex_cond, 0LL);
if ( !(worms | scream) )
scream = 1;
if ( pthread_cond_init(&var_cond, 0LL) < 0 )
{
fwrite("variabile condition error.\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v7 = 0;
v8 = 0x6F42426142LL;
v9 = 0;
if ( pthread_create(newthread, 0LL, (void *(*)(void *))parent, &v7) < 0 )
{
fwrite("create error for PARENT.\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v3 = arg;
for ( i = 0LL; i != 10; ++i )
{
*v3 = i;
v5 = v11;
if ( pthread_create(&v11[i], 0LL, (void *(*)(void *))child_handler, v3) < 0 )
{
fprintf(stderr, "create error for BIRD N%d.\n", arg[4 * (int)i]);
exit(1);
}
v3 += 4;
}
pthread_join(newthread[0], 0LL);
do
pthread_join(*v5++, 0LL);
while ( v5 != (pthread_t *)&v12 );
return 0;
}

original_code:
int main (int argc, char* argv[]){
    int i = 0;
    pthread_mutex_init (&sem, ((void *)0));
    pthread_mutex_init (&mutex_cond, ((void *)0));
    pthread_t thread_parent;
    pthread_t thread_bird[10];
    struct DATA data[10];
    if(scream == 0 && worms == 0){
        scream = 1 ;
    }
    if (pthread_cond_init(&var_cond, ((void *)0)) < 0)
        { fprintf (stderr, "variabile condition error.\n");
            exit (1);
        }
    struct DATA dad = {0, "BaBBo"} ;
    if (pthread_create(&thread_parent, ((void *)0), parent, (void *)&dad ) < 0)
        { fprintf (stderr, "create error for PARENT.\n");
            exit (1);
        }
    for ( i = 0 ; i < 10 ; i++){
        data[i].num = i ;
        if (pthread_create(&thread_bird[i], ((void *)0), child_handler, (void *)&data[i] ) < 0)
            { fprintf (stderr, "create error for BIRD N%d.\n", data[i].num);
                exit (1);
            }
    }
    pthread_join (thread_parent, ((void *)0));
    for ( i = 0 ; i < 10 ; i++)
        { pthread_join (thread_bird[i], ((void *)0));
        }
    return 0 ;
}

canonical_original_code:
int main(int argc, char *argv[]){
    int i = 0;
    pthread_mutex_init (&sem, ((void *)0));
    pthread_mutex_init (&mutex_cond, ((void *)0));
    unsigned long thread_parent;
    unsigned long thread_bird[10];
    struct DATA data[10];
    if(scream == 0 && worms == 0){
        scream = 1 ;
    }
    if (pthread_cond_init(&var_cond, ((void *)0)) < 0)
        { fprintf (stderr, "variabile condition error.\n");
            exit (1);
        }
    struct DATA dad = {0, "BaBBo"};
    if (pthread_create(&thread_parent, ((void *)0), parent, (void *)&dad ) < 0)
        { fprintf (stderr, "create error for PARENT.\n");
            exit (1);
        }
    for ( i = 0 ; i < 10 ; i++){
        data[i].num = i ;
        if (pthread_create(&thread_bird[i], ((void *)0), child_handler, (void *)&data[i] ) < 0)
            { fprintf (stderr, "create error for BIRD N%d.\n", data[i].num);
                exit (1);
            }
    }
    pthread_join (thread_parent, ((void *)0));
    for ( i = 0 ; i < 10 ; i++)
        { pthread_join (thread_bird[i], ((void *)0));
        }
    return 0 ;
}

variable_types:
argv
char *[]

variable_types: i int

variable_types: struct DATA { int num; char name[10]; } [10]

variable_types:
dad
struct DATA { int num; char name[10]; }


decompiled_code:
void sigchld_handler()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) > 0 )
;
}

canonical_decompiled_code:
void func7()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) > 0 )
;
}

original_code:
static void
sigchld_handler(int signal)
{
 pid_t pid;
 int status;
 do {
  pid = waitpid(-1, &status, 1);
 } while (pid > 0);
}

canonical_original_code:
static void sigchld_handler(int signal)
{
 int pid;
 int status;
 do {
  pid = waitpid(-1, &status, 1);
 } while (pid > 0);
}

variable_types: signal int

variable_types: pid int

variable_types: status int


decompiled_code:
void __noreturn sigterm_handler()
{
if ( shm_unlink("MY_SHARED_MEMORY") != -1 )
{
if ( sem_unlink("SEM_PARENT") )
exit(1);
if ( sem_unlink("SEM_MUTEX") )
exit(1);
if ( sem_unlink("SEM_BIRD") )
exit(1);
exit(0);
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
if ( shm_unlink("MY_SHARED_MEMORY") != -1 )
{
if ( sem_unlink("SEM_PARENT") )
exit(1);
if ( sem_unlink("SEM_MUTEX") )
exit(1);
if ( sem_unlink("SEM_BIRD") )
exit(1);
exit(0);
}
exit(1);
}

original_code:
static void
sigterm_handler(int signal)
{
    if( shm_unlink("MY_SHARED_MEMORY") == -1 )
        exit(1);
    if(sem_unlink("SEM_PARENT"))
        exit(1);
    if(sem_unlink("SEM_MUTEX"))
        exit(1);
    if(sem_unlink("SEM_BIRD"))
        exit(1);
    exit(0);
}


decompiled_code:
void __noreturn parent_create()
{
unsigned int v0; // eax
unsigned int v1; // ebx
unsigned int v2; // eax
int v3; // ebx
unsigned int v4; // eax

v0 = getpid();
printf("[PID %d ] I am DAD\n", v0);
while ( 1 )
{
sem_wait(sem_parent);
sem_wait(sem);
v3 = *(_DWORD *)shm_addr;
if ( *(_DWORD *)shm_addr )
{
if ( v3 <= 0 )
{
perror("Acces Plate: ");
exit(1);
}
v4 = getpid();
printf("[PID %d ] I am DAD... On plate there are %d worms. I'm Waiting ...\n", v4, (unsigned int)v3);
}
else
{
*(_DWORD *)shm_addr = 7;
v1 = *(_DWORD *)shm_addr;
v2 = getpid();
printf("[PID %d ] I am DAD!!! Now there are %d worms on plates\n", v2, v1);
}
sem_post(sem);
sem_post(sem_bird);
}
}

canonical_decompiled_code:
void __noreturn func9()
{
unsigned int v0; // eax
unsigned int v1; // ebx
unsigned int v2; // eax
int v3; // ebx
unsigned int v4; // eax

v0 = getpid();
printf("[PID %d ] I am DAD\n", v0);
while ( 1 )
{
sem_wait(sem_parent);
sem_wait(sem);
v3 = *(_DWORD *)shm_addr;
if ( *(_DWORD *)shm_addr )
{
if ( v3 <= 0 )
{
perror("Acces Plate: ");
exit(1);
}
v4 = getpid();
printf("[PID %d ] I am DAD... On plate there are %d worms. I'm Waiting ...\n", v4, (unsigned int)v3);
}
else
{
*(_DWORD *)shm_addr = 7;
v1 = *(_DWORD *)shm_addr;
v2 = getpid();
printf("[PID %d ] I am DAD!!! Now there are %d worms on plates\n", v2, v1);
}
sem_post(sem);
sem_post(sem_bird);
}
}

original_code:
void
parent_create(void)
{
    printf("[PID %d ] I am DAD\n", getpid());
    while(1) {
        sem_wait(sem_parent);
         sem_wait(sem);
         if(*shm_addr == 0) {
            *shm_addr = *shm_addr + 7 ;
            printf("[PID %d ] I am DAD!!!  Now there are %d worms on plates\n", getpid(), *shm_addr);
             } else if(*shm_addr > 0){
            printf("[PID %d ] I am DAD... On plate there are %d worms. "
                   "I'm Waiting ...\n", getpid(), *shm_addr);
            } else {
            perror("Acces Plate: ");
            exit(1);
         }
         sem_post(sem);
         sem_post(sem_bird);
    }
    perror("Parent");
    exit(1);
}

canonical_original_code:
void parent_create()
{
    printf("[PID %d ] I am DAD\n", getpid());
    while(1) {
        sem_wait(sem_parent);
         sem_wait(sem);
         if(*shm_addr == 0) {
            *shm_addr = *shm_addr + 7 ;
            printf("[PID %d ] I am DAD!!!  Now there are %d worms on plates\n", getpid(), *shm_addr);
             } else if(*shm_addr > 0){
            printf("[PID %d ] I am DAD... On plate there are %d worms. "
                   "I'm Waiting ...\n", getpid(), *shm_addr);
            } else {
            perror("Acces Plate: ");
            exit(1);
         }
         sem_post(sem);
         sem_post(sem_bird);
    }
    perror("Parent");
    exit(1);
}