decompiled_code:
void __fastcall eigen_mr3(int a1, __int64 a2, __int64 a3, __int64 a4)
{
void *v6; // rbp
void *v7; // rbx
void *v8; // r15
int v9; // [rsp+Ch] [rbp-5Ch] BYREF
__int64 v10; // [rsp+10h] [rbp-58h] BYREF
int v11; // [rsp+1Ch] [rbp-4Ch] BYREF
int v12; // [rsp+20h] [rbp-48h] BYREF
int v13; // [rsp+24h] [rbp-44h] BYREF
char v14[4]; // [rsp+28h] [rbp-40h] BYREF
char v15[60]; // [rsp+2Ch] [rbp-3Ch] BYREF

v9 = a1;
v12 = 198 * a1;
v11 = 10 * a1;
v10 = LC0;
v6 = (void *)fgls_malloc_impl("src/REML.c", 264LL, 1584LL * a1);
v7 = (void *)fgls_malloc_impl("src/REML.c", 265LL, 40LL * a1);
v8 = (void *)fgls_malloc_impl("src/REML.c", 266LL, 8LL * a1);
dsyevr_("V", "A", "L", &v9, a2, &v9, &v10, &v10, v15, v15, &v10, v14, a4, a3, &v9, v8, v6, &v12, v7, &v11, &v13);
if ( v13 )
{
fwrite("Error factoring Phi\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
free(v6);
free(v7);
free(v8);
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2, __int64 a3, __int64 a4)
{
void *v6; // rbp
void *v7; // rbx
void *v8; // r15
int v9; // [rsp+Ch] [rbp-5Ch] BYREF
__int64 v10; // [rsp+10h] [rbp-58h] BYREF
int v11; // [rsp+1Ch] [rbp-4Ch] BYREF
int v12; // [rsp+20h] [rbp-48h] BYREF
int v13; // [rsp+24h] [rbp-44h] BYREF
char v14[4]; // [rsp+28h] [rbp-40h] BYREF
char v15[60]; // [rsp+2Ch] [rbp-3Ch] BYREF

v9 = a1;
v12 = 198 * a1;
v11 = 10 * a1;
v10 = LC0;
v6 = (void *)fgls_malloc_impl("src/REML.c", 264LL, 1584LL * a1);
v7 = (void *)fgls_malloc_impl("src/REML.c", 265LL, 40LL * a1);
v8 = (void *)fgls_malloc_impl("src/REML.c", 266LL, 8LL * a1);
dsyevr_("V", "A", "L", &v9, a2, &v9, &v10, &v10, v15, v15, &v10, v14, a4, a3, &v9, v8, v6, &v12, v7, &v11, &v13);
if ( v13 )
{
fwrite("Error factoring Phi\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
free(v6);
free(v7);
free(v8);
}

original_code:
void eigen_mr3(int n, double *Phi, double *Z, double *W)
{
    int nb = 192;
    int idummy, nCompPairs, *isuppz, *iwork, info,
        lwork = n * (nb + 6),
        liwork = 10 * n;
    double ddummy = -1.0, *work;
    work = (double *) fgls_malloc_impl("src/REML.c", 264, lwork * sizeof(double));
    iwork = (int *) fgls_malloc_impl("src/REML.c", 265, liwork * sizeof(int));
    isuppz = (int *) fgls_malloc_impl("src/REML.c", 266, 2 * n * sizeof(int));
    dsyevr_("V", "A", "L", &n, Phi, &n,
   &ddummy, &ddummy, &idummy, &idummy, &ddummy,
   &nCompPairs, W, Z, &n, isuppz,
   work, &lwork, iwork, &liwork, &info);
    if (info != 0)
    {
        fprintf(stderr, "Error factoring Phi\n");
        exit(-1);
    }
 free( work );
 free( iwork );
 free( isuppz );
}

canonical_original_code:
void eigen_mr3(int n, double *Phi, double *Z, double *W)
{
    int nb = 192;
    int idummy; int nCompPairs; int *isuppz; int *iwork; int info; int lwork = n * (nb + 6); int liwork = 10 * n;
    double ddummy = -1.0; double *work;
    work = (double *) fgls_malloc_impl("src/REML.c", 264, lwork * sizeof(double));
    iwork = (int *) fgls_malloc_impl("src/REML.c", 265, liwork * sizeof(int));
    isuppz = (int *) fgls_malloc_impl("src/REML.c", 266, 2 * n * sizeof(int));
    dsyevr_("V", "A", "L", &n, Phi, &n,
   &ddummy, &ddummy, &idummy, &idummy, &ddummy,
   &nCompPairs, W, Z, &n, isuppz,
   work, &lwork, iwork, &liwork, &info);
    if (info != 0)
    {
        fprintf(stderr, "Error factoring Phi\n");
        exit(-1);
    }
 free( work );
 free( iwork );
 free( isuppz );
}

variable_types:
Phi
double *

variable_types:
Z
double *

variable_types:
W
double *

variable_types: nb int

variable_types: idummy int

variable_types: nCompPairs int

variable_types:
isuppz
int *

variable_types:
iwork
int *

variable_types: info int

variable_types: lwork int

variable_types: liwork int

variable_types: ddummy double

variable_types:
work
double *


premultiplyXL

repo: lucasb-eyer/OmicABEL

original_code:
void premultiplyXL(
  int n, int wXL,
  double *Z,
  double *XL,
  double *ZtXL
)
{
 int ldZ, ldXL, ldZtXL;
 double ZERO = 0.0,
        ONE = 1.0;
 ldZ = ldXL = ldZtXL = n;
 dgemm_(
   "T", "N",
   &n, &wXL, &n,
   &ONE, Z, &ldZ, XL, &ldXL,
   &ZERO, ZtXL, &ldZtXL
 );
}

canonical_original_code:
void premultiplyXL(int n, int wXL, double *Z, double *XL, double *ZtXL)
{
 int ldZ; int ldXL; int ldZtXL;
 double ZERO = 0.0; double ONE = 1.0;
 ldZ = ldXL = ldZtXL = n;
 dgemm_(
   "T", "N",
   &n, &wXL, &n,
   &ONE, Z, &ldZ, XL, &ldXL,
   &ZERO, ZtXL, &ldZtXL
 );
}

variable_types: n int

variable_types: wXL int

variable_types:
XL
double *

variable_types:
ZtXL
double *

variable_types: ldZ int

variable_types: ldXL int

variable_types: ldZtXL int

variable_types: ZERO double

variable_types: ONE double

return_type: void


original_code:
double polygenic_REML_logLik_eig (
        int n, int widthXL,
  double *X, double *Y,
        double *Z, double *W, double *ZtX, double *ZtY,
  double sigma, double h2,
        double *loglik, double *res_sigma, double *beta
)
{
    double alpha, gamma,
           *ZtY_upd, *ZtX_upd, *YmXB, *V, *D, det,
           ZERO = 0.0,
           ONE = 1.0,
           MINUS_ONE = -1.0;
    int wXL = widthXL,
           iONE = 1, info,
           i, j;
    V = (double *) fgls_malloc_impl("src/REML.c", 139, wXL * wXL * sizeof(double));
 ZtY_upd = (double *) fgls_malloc_impl("src/REML.c", 140, n * sizeof(double));
 ZtX_upd = (double *) fgls_malloc_impl("src/REML.c", 141, n * wXL * sizeof(double));
 D = (double *) fgls_malloc_impl("src/REML.c", 142, n * sizeof(double));
 YmXB = (double *) fgls_malloc_impl("src/REML.c", 143, n * sizeof(double));
    alpha = h2;
    gamma = (1 - h2);
 det = 0.0;
 for ( i = 0; i < n; i++ )
 {
  D[i] = alpha * W[i] + gamma;
  det += log( D[i] );
  D[i] = sqrt( 1.0 / D[i] );
 }
 for (i = 0; i < n; i++ )
 {
  for (j = 0; j < wXL; j++ )
   ZtX_upd[j*n + i] = ZtX[j*n + i] * D[i];
  ZtY_upd[i] = ZtY[i] * D[i];
 }
    dgemv_("T", &n, &widthXL, &ONE, ZtX_upd, &n, ZtY_upd, &iONE, &ZERO, beta, &iONE);
 dsyrk_("L", "T", &wXL, &n, &ONE, ZtX_upd, &n, &ZERO, V, &wXL);
 dpotrf_("L", &wXL, V, &wXL, &info);
    if (info != 0)
    {
        fprintf(stderr, "src/REML.c" ": [ERROR] inv(V) y failed - info: %d\n", info);
        exit(-1);
    }
 dtrsv_("L", "N", "N", &wXL, V, &wXL, beta, &iONE);
 dtrsv_("L", "T", "N", &wXL, V, &wXL, beta, &iONE);
 memcpy( YmXB, Y, n * sizeof(double) );
    dgemv_( "N",
            &n, &wXL,
            &MINUS_ONE, X, &n, beta, &iONE,
            &ONE, YmXB, &iONE );
 *res_sigma = variance( YmXB, n );
    dgemv_("T",
            &n, &n,
            &ONE, Z, &n, YmXB, &iONE,
            &ZERO, ZtY_upd, &iONE);
 *loglik = 0.0;
 for (i = 0; i < n; i++ )
  *loglik += ZtY_upd[i] * D[i] * D[i] * ZtY_upd[i];
 *loglik = (*loglik) / (*res_sigma);
    *loglik = det + n * log(*res_sigma) + (*loglik) ;
 free( V );
 free( ZtY_upd );
 free( ZtX_upd );
 free( YmXB );
 free( D );
 return *loglik;
}

canonical_original_code:
double polygenic_REML_logLik_eig(int n, int widthXL, double *X, double *Y, double *Z, double *W, double *ZtX, double *ZtY, double sigma, double h2, double *loglik, double *res_sigma, double *beta)
{
    double alpha; double gamma; double *ZtY_upd; double *ZtX_upd; double *YmXB; double *V; double *D; double det; double ZERO = 0.0; double ONE = 1.0; double MINUS_ONE = -1.0;
    int wXL = widthXL; int iONE = 1; int info; int i; int j;
    V = (double *) fgls_malloc_impl("src/REML.c", 139, wXL * wXL * sizeof(double));
 ZtY_upd = (double *) fgls_malloc_impl("src/REML.c", 140, n * sizeof(double));
 ZtX_upd = (double *) fgls_malloc_impl("src/REML.c", 141, n * wXL * sizeof(double));
 D = (double *) fgls_malloc_impl("src/REML.c", 142, n * sizeof(double));
 YmXB = (double *) fgls_malloc_impl("src/REML.c", 143, n * sizeof(double));
    alpha = h2;
    gamma = (1 - h2);
 det = 0.0;
 for ( i = 0; i < n; i++ )
 {
  D[i] = alpha * W[i] + gamma;
  det += log( D[i] );
  D[i] = sqrt( 1.0 / D[i] );
 }
 for (i = 0; i < n; i++ )
 {
  for (j = 0; j < wXL; j++ )
   ZtX_upd[j*n + i] = ZtX[j*n + i] * D[i];
  ZtY_upd[i] = ZtY[i] * D[i];
 }
    dgemv_("T", &n, &widthXL, &ONE, ZtX_upd, &n, ZtY_upd, &iONE, &ZERO, beta, &iONE);
 dsyrk_("L", "T", &wXL, &n, &ONE, ZtX_upd, &n, &ZERO, V, &wXL);
 dpotrf_("L", &wXL, V, &wXL, &info);
    if (info != 0)
    {
        fprintf(stderr, "src/REML.c" ": [ERROR] inv(V) y failed - info: %d\n", info);
        exit(-1);
    }
 dtrsv_("L", "N", "N", &wXL, V, &wXL, beta, &iONE);
 dtrsv_("L", "T", "N", &wXL, V, &wXL, beta, &iONE);
 memcpy( YmXB, Y, n * sizeof(double) );
    dgemv_( "N",
            &n, &wXL,
            &MINUS_ONE, X, &n, beta, &iONE,
            &ONE, YmXB, &iONE );
 *res_sigma = variance( YmXB, n );
    dgemv_("T",
            &n, &n,
            &ONE, Z, &n, YmXB, &iONE,
            &ZERO, ZtY_upd, &iONE);
 *loglik = 0.0;
 for (i = 0; i < n; i++ )
  *loglik += ZtY_upd[i] * D[i] * D[i] * ZtY_upd[i];
 *loglik = (*loglik) / (*res_sigma);
    *loglik = det + n * log(*res_sigma) + (*loglik) ;
 free( V );
 free( ZtY_upd );
 free( ZtX_upd );
 free( YmXB );
 free( D );
 return *loglik;
}

variable_types: widthXL int

variable_types:
X
double *

variable_types:
Y
double *

variable_types:
Z
double *

variable_types:
W
double *

variable_types:
ZtX
double *

variable_types:
ZtY
double *

variable_types: sigma double

variable_types:
loglik
double *

variable_types:
beta
double *

variable_types: alpha double

variable_types: gamma double

variable_types:
YmXB
double *

variable_types:
V
double *

variable_types:
D
double *

variable_types: det double

variable_types: iONE int

variable_types: i int

variable_types: j int

return_type: double


original_code:
double polygenic_REML_logLik_eig_wrapper ( double h, void *data )
{
 estimates_eig_t *eig_t = (estimates_eig_t*)data;
 size_t n = eig_t->n,
        wXL = eig_t->wXL;
 double *X = eig_t->X,
     *Y = eig_t->Y,
        *Z = eig_t->Z,
     *W = eig_t->W,
        *ZtX = eig_t->ZtX,
     *ZtY = eig_t->ZtY;
 double sigma = eig_t->sigma;
 double loglik;
 polygenic_REML_logLik_eig (
         n, wXL,
         X, Y, Z, W, ZtX, ZtY,
            sigma, h,
         &loglik, &eig_t->res_sigma, eig_t->beta
 );
 eig_t->h = h;
 return loglik;
}

canonical_original_code:
double polygenic_REML_logLik_eig_wrapper(double h, void *data)
{
 struct estimates_eig_t *eig_t = (estimates_eig_t*)data;
 unsigned long n = eig_t->n; unsigned long wXL = eig_t->wXL;
 double *X = eig_t->X; double *Y = eig_t->Y; double *Z = eig_t->Z; double *W = eig_t->W; double *ZtX = eig_t->ZtX; double *ZtY = eig_t->ZtY;
 double sigma = eig_t->sigma;
 double loglik;
 polygenic_REML_logLik_eig (
         n, wXL,
         X, Y, Z, W, ZtX, ZtY,
            sigma, h,
         &loglik, &eig_t->res_sigma, eig_t->beta
 );
 eig_t->h = h;
 return loglik;
}

variable_types: h double

variable_types:
data
void *

variable_types: struct estimates_eig_t { unsigned long n; unsigned long wXL; double *Phi; double *X; double *Y; double sigma; double *Z; double *W; double *ZtX; double *ZtY; double h; double res_sigma; double *beta; } *

variable_types:
n
unsigned long

variable_types:
wXL
unsigned long

variable_types:
X
double *

variable_types:
Y
double *

variable_types: loglik double


decompiled_code:
void __fastcall free_and_nullify(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

original_code:
static void free_and_nullify( double **p )
{
 if ( *p )
 {
  free( *p );
  *p = ((void *)0);
 }
}

canonical_original_code:
static void free_and_nullify(double **p)
{
 if ( *p )
 {
  free( *p );
  *p = ((void *)0);
 }
}

variable_types:
p
double **


decompiled_code:
void __fastcall free_databel_fvi(void **a1)
{
free(*((void **)*a1 + 6));
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
free(*((void **)*a1 + 6));
free(*a1);
*a1 = 0LL;
}

original_code:
void free_databel_fvi( struct databel_fvi **fvi )
{
 free ((*fvi)->fvi_data);
 free (*fvi);
 *fvi = ((void *)0);
}

canonical_original_code:
void free_databel_fvi(struct databel_fvi **fvi)
{
 free ((*fvi)->fvi_data);
 free (*fvi);
 *fvi = ((void *)0);
}

variable_types: struct databel_fvi { struct databel_fvi_header { unsigned short type; unsigned int nelements; unsigned int numObservations; unsigned int numVariables; unsigned int bytesPerRecord; unsigned int bitsPerRecord; unsigned int namelength; unsigned int reserved[5]; } fvi_header; char *fvi_data; } **

user_defined_types: struct databel_fvi { struct databel_fvi_header fvi_header; char *fvi_data; }


decompiled_code:
int __fastcall set_multi_threaded_BLAS(unsigned int a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "%d", a1);
setenv("GOTO_NUM_THREADS", v2, 1);
return setenv("OMP_NUM_THREADS", "1", 1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "%d", a1);
setenv("GOTO_NUM_THREADS", v2, 1);
return setenv("OMP_NUM_THREADS", "1", 1);
}

original_code:
void set_multi_threaded_BLAS( int nths )
{
    char nths_str[256];
    snprintf( nths_str, 256, "%d", nths );
    setenv("GOTO_NUM_THREADS", nths_str, 1);
    setenv("OMP_NUM_THREADS", "1", 1);
}

canonical_original_code:
void set_multi_threaded_BLAS(int nths)
{
    char nths_str[256];
    snprintf( nths_str, 256, "%d", nths );
    setenv("GOTO_NUM_THREADS", nths_str, 1);
    setenv("OMP_NUM_THREADS", "1", 1);
}

variable_types: nths int


decompiled_code:
int set_single_threaded_BLAS()
{
return setenv("GOTO_NUM_THREADS", "1", 1);
}

canonical_decompiled_code:
int func1()
{
return setenv("GOTO_NUM_THREADS", "1", 1);
}

original_code:
void set_single_threaded_BLAS( void )
{
    setenv("GOTO_NUM_THREADS", "1", 1);
}

canonical_original_code:
void set_single_threaded_BLAS()
{
    setenv("GOTO_NUM_THREADS", "1", 1);
}


decompiled_code:
int print_timestamp()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return printf("%lld:%lld seconds\n", v1.tv_sec, v1.tv_usec);
}

canonical_decompiled_code:
int func5()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return printf("%lld:%lld seconds\n", v1.tv_sec, v1.tv_usec);
}

original_code:
void print_timestamp( void )
{
 struct timeval t;
 gettimeofday( &t, ((void *)0) );
 printf( "%lld:%lld seconds\n", (long long)t.tv_sec, (long long)t.tv_usec );
}

canonical_original_code:
void print_timestamp()
{
 struct timeval t;
 gettimeofday( &t, ((void *)0) );
 printf( "%lld:%lld seconds\n", (long long)t.tv_sec, (long long)t.tv_usec );
}

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


average

decompiled_code:
__int64 __fastcall average(__int64 a1, int a2, int a3, int a4, const char *a5, __int64 a6, int a7, int a8)
{
int v8; // er13
double *v9; // rbp
double *v10; // rbx
__int64 result; // rax
unsigned __int64 v12; // r12
double v13; // [rsp+8h] [rbp-70h]
int v14; // [rsp+14h] [rbp-64h]
int v16; // [rsp+20h] [rbp-58h]
int v17; // [rsp+24h] [rbp-54h]
int v19; // [rsp+30h] [rbp-48h]

if ( a3 > 0 )
{
v17 = 0;
v16 = 0;
v14 = 0;
v19 = 100 - a4;
do
{
if ( a2 > 0 )
{
v10 = (double *)(a1 + 8LL * v17);
v12 = a1 + 8 * (v17 + (unsigned __int64)(unsigned int)(a2 - 1)) + 8;
v9 = v10;
v8 = 0;
v13 = 0.0;
do
{
if ( COERCE_DOUBLE(*(_QWORD *)v9 & LC25) > 1.797693134862316e308 )
{
fprintf(stderr, "[WARNING] Infinity found in %s %s\n", a5, (const char *)(a6 + v16));
++v8;
}
else
{
v13 = *v9 + v13;
}
++v9;
}
while ( v9 != (double *)v12 );
do
{
if ( COERCE_DOUBLE(*(_QWORD *)v10 & LC25) > 1.797693134862316e308 )
*v10 = v13 / (double)(a2 - v8);
++v10;
}
while ( v10 != (double *)v12 );
}
if ( (float)((float)0 / (float)a2) > (float)((float)v19 / 100.0) )
{
if ( a8 )
fprintf(
stderr,
"\n[WARNING] %.1f%% of NaNs in %s %s exceeds threshold (%d%%)\n",
(float)((float)((float)0 * 100.0) / (float)a2),
a5,
(const char *)(a6 + v16),
(unsigned int)v19);
}
result = (unsigned int)++v14;
v16 += a7;
v17 += a2;
}
while ( a3 != v14 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3, int a4, const char *a5, __int64 a6, int a7, int a8)
{
int v8; // er13
double *v9; // rbp
double *v10; // rbx
__int64 result; // rax
unsigned __int64 v12; // r12
double v13; // [rsp+8h] [rbp-70h]
int v14; // [rsp+14h] [rbp-64h]
int v16; // [rsp+20h] [rbp-58h]
int v17; // [rsp+24h] [rbp-54h]
int v19; // [rsp+30h] [rbp-48h]

if ( a3 > 0 )
{
v17 = 0;
v16 = 0;
v14 = 0;
v19 = 100 - a4;
do
{
if ( a2 > 0 )
{
v10 = (double *)(a1 + 8LL * v17);
v12 = a1 + 8 * (v17 + (unsigned __int64)(unsigned int)(a2 - 1)) + 8;
v9 = v10;
v8 = 0;
v13 = 0.0;
do
{
if ( COERCE_DOUBLE(*(_QWORD *)v9 & LC25) > 1.797693134862316e308 )
{
fprintf(stderr, "[WARNING] Infinity found in %s %s\n", a5, (const char *)(a6 + v16));
++v8;
}
else
{
v13 = *v9 + v13;
}
++v9;
}
while ( v9 != (double *)v12 );
do
{
if ( COERCE_DOUBLE(*(_QWORD *)v10 & LC25) > 1.797693134862316e308 )
*v10 = v13 / (double)(a2 - v8);
++v10;
}
while ( v10 != (double *)v12 );
}
if ( (float)((float)0 / (float)a2) > (float)((float)v19 / 100.0) )
{
if ( a8 )
fprintf(
stderr,
"\n[WARNING] %.1f%% of NaNs in %s %s exceeds threshold (%d%%)\n",
(float)((float)((float)0 * 100.0) / (float)a2),
a5,
(const char *)(a6 + v16),
(unsigned int)v19);
}
result = (unsigned int)++v14;
v16 += a7;
v17 += a2;
}
while ( a3 != v14 );
}
return result;
}

original_code:
void average( double *data, int n, int ncols, int threshold, const char *obj_type, char *obj_name, int namelength, int verbose )
{
 int i, j;
 double sum, avg;
 int nans, infs;
 for ( j = 0; j < ncols; j++ )
 {
  sum = 0.0;
  nans = 0;
  infs = 0;
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) )
    nans++;
   else if ( __builtin_isinf_sign (data[j*n + i]) )
   {
    fprintf(stderr, "[WARNING] Infinity found in %s %s\n", obj_type, &obj_name[j*namelength]);
    infs++;
   }
   else
    sum += data[j*n + i];
  }
  avg = sum / (n-nans-infs);
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) || __builtin_isinf_sign (data[j*n + i]) )
    data[j*n + i] = avg;
  }
  if ( ((float)nans / n) > (100 - threshold)/(float)100 && verbose )
   fprintf(stderr, "\n[WARNING] %.1f%% of NaNs in %s %s exceeds threshold (%d%%)\n",
     100*(float)nans/n, obj_type, &obj_name[j*namelength], 100-threshold);
 }
}

canonical_original_code:
void average(double *data, int n, int ncols, int threshold, char *obj_type, char *obj_name, int namelength, int verbose)
{
 int i; int j;
 double sum; double avg;
 int nans; int infs;
 for ( j = 0; j < ncols; j++ )
 {
  sum = 0.0;
  nans = 0;
  infs = 0;
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) )
    nans++;
   else if ( __builtin_isinf_sign (data[j*n + i]) )
   {
    fprintf(stderr, "[WARNING] Infinity found in %s %s\n", obj_type, &obj_name[j*namelength]);
    infs++;
   }
   else
    sum += data[j*n + i];
  }
  avg = sum / (n-nans-infs);
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) || __builtin_isinf_sign (data[j*n + i]) )
    data[j*n + i] = avg;
  }
  if ( ((float)nans / n) > (100 - threshold)/(float)100 && verbose )
   fprintf(stderr, "\n[WARNING] %.1f%% of NaNs in %s %s exceeds threshold (%d%%)\n",
     100*(float)nans/n, obj_type, &obj_name[j*namelength], 100-threshold);
 }
}

variable_types:
data
double *

variable_types: n int

variable_types: ncols int

variable_types: threshold int

variable_types: namelength int

variable_types: verbose int

variable_types: sum double

variable_types: avg double

variable_types: nans int

variable_types: infs int


checkNoNans

decompiled_code:
void __fastcall checkNoNans(__int64 a1, __int64 a2, const char *a3)
{
__int64 i; // rax

if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( COERCE_DOUBLE(*(_QWORD *)(a2 + 8 * i) & LC25) > 1.797693134862316e308 )
{
fprintf(stderr, a3);
exit(1);
}
}
}
}

original_code:
void checkNoNans( size_t n, double *buff, const char* err_msg)
{
 size_t i;
 for ( i = 0; i < n; i++ )
  if ( __builtin_isnan (buff[i]) || __builtin_isinf_sign (buff[i]) )
  {
   fprintf( stderr, err_msg );
   exit( 1 );
  }
}

canonical_original_code:
void checkNoNans(unsigned long n, double *buff, char *err_msg)
{
 unsigned long i;
 for ( i = 0; i < n; i++ )
  if ( __builtin_isnan (buff[i]) || __builtin_isinf_sign (buff[i]) )
  {
   fprintf( stderr, err_msg );
   exit( 1 );
  }
}

variable_types:
n
unsigned long

variable_types:
buff
double *

variable_types:
i
unsigned long


dsign

decompiled_code:
__m128d __fastcall dsign(__m128d a1, double a2)
{
__m128d result; // xmm0

if ( a2 < 0.0 )
result = _mm_or_pd(a1, (__m128d)LC2);
else
result = _mm_and_pd(a1, (__m128d)LC1);
return result;
}

canonical_decompiled_code:
__m128d __fastcall func0(__m128d a1, double a2)
{
__m128d result; // xmm0

if ( a2 < 0.0 )
result = _mm_or_pd(a1, (__m128d)LC2);
else
result = _mm_and_pd(a1, (__m128d)LC1);
return result;
}

original_code:
static double dsign( double a, double b )
{
 return b >= 0.0 ? fabs(a) : -fabs(a);
}

canonical_original_code:
static double dsign(double a, double b)
{
 return b >= 0.0 ? fabs(a) : -fabs(a);
}

variable_types: a double

variable_types: b double


minimize

original_code:
double minimize( double ax, double bx, double tol, double (*f)(double, void *), void *data )
{
      double a, b, c, d, e,
    eps, xm, p, q, r,
    tol1, tol2, u, v, w;
      double fu, fv, fw, fx, x;
      c = 0.5 * ( 3.0 - sqrt(5.0) );
      eps = 1.0;
mach: eps = eps / 2.0;
      tol1 = 1.0 + eps;
      if ( tol1 > 1.0)
    goto mach;
      eps = sqrt( eps );
      a = ax;
      b = bx;
      v = a + c*(b - a);
      w = v;
      x = v;
      e = 0.0;
      fx = f( x, data );
      fv = fx;
      fw = fx;
loop:
   xm = 0.5 * (a + b);
      tol1 = eps * fabs(x) + tol / 3.0;
      tol2 = 2.0 * tol1;
      if (fabs(x - xm) <= (tol2 - 0.5 * (b - a)))
    goto end;
      if (fabs(e) <= tol1)
    goto golden;
      r = (x - w)*(fx - fv);
      q = (x - v)*(fx - fw);
      p = (x - v)*q - (x - w)*r;
      q = 2.0*(q - r);
      if (q > 0.0) p = -p;
      q = fabs(q);
      r = e;
      e = d;
      if (fabs(p) >= fabs(0.5*q*r))
    goto golden;
      if (p <= q*(a - x))
    goto golden;
      if (p >= q*(b - x))
    goto golden;
      d = p/q;
      u = x + d;
      if ((u - a) < tol2) d = dsign(tol1, xm - x);
      if ((b - u) < tol2) d = dsign(tol1, xm - x);
      goto fnotclose;
golden:
   if (x >= xm) e = a - x;
      if (x < xm) e = b - x;
      d = c*e;
fnotclose: if (fabs(d) >= tol1) u = x + d;
      if (fabs(d) < tol1) u = x + dsign(tol1, d);
      fu = f( u, data );
      if (fu > fx)
    goto sixty;
      if (u >= x)
    a = x;
      if (u < x)
    b = x;
      v = w;
      fv = fw;
      w = x;
      fw = fx;
      x = u;
      fx = fu;
      goto loop;
sixty: if (u < x) a = u;
      if (u >= x) b = u;
      if (fu <= fw)
    goto sevty;
      if (w == x)
    goto sevty;
      if (fu <= fv)
    goto eigty;
      if (v == x)
    goto eigty;
      if (v == w)
    goto eigty;
      goto loop;
sevty: v = w;
      fv = fw;
      w = u;
      fw = fu;
      goto loop;
eigty: v = u;
      fv = fu;
      goto loop;
end:
      return x;
}

canonical_original_code:
double minimize(double ax, double bx, double tol, double (*f)(double, void *), void *data)
{
      double a; double b; double c; double d; double e; double eps; double xm; double p; double q; double r; double tol1; double tol2; double u; double v; double w;
      double fu; double fv; double fw; double fx; double x;
      c = 0.5 * ( 3.0 - sqrt(5.0) );
      eps = 1.0;
mach: eps = eps / 2.0;
      tol1 = 1.0 + eps;
      if ( tol1 > 1.0)
    goto mach;
      eps = sqrt( eps );
      a = ax;
      b = bx;
      v = a + c*(b - a);
      w = v;
      x = v;
      e = 0.0;
      fx = f( x, data );
      fv = fx;
      fw = fx;
loop:
   xm = 0.5 * (a + b);
      tol1 = eps * fabs(x) + tol / 3.0;
      tol2 = 2.0 * tol1;
      if (fabs(x - xm) <= (tol2 - 0.5 * (b - a)))
    goto end;
      if (fabs(e) <= tol1)
    goto golden;
      r = (x - w)*(fx - fv);
      q = (x - v)*(fx - fw);
      p = (x - v)*q - (x - w)*r;
      q = 2.0*(q - r);
      if (q > 0.0) p = -p;
      q = fabs(q);
      r = e;
      e = d;
      if (fabs(p) >= fabs(0.5*q*r))
    goto golden;
      if (p <= q*(a - x))
    goto golden;
      if (p >= q*(b - x))
    goto golden;
      d = p/q;
      u = x + d;
      if ((u - a) < tol2) d = dsign(tol1, xm - x);
      if ((b - u) < tol2) d = dsign(tol1, xm - x);
      goto fnotclose;
golden:
   if (x >= xm) e = a - x;
      if (x < xm) e = b - x;
      d = c*e;
fnotclose: if (fabs(d) >= tol1) u = x + d;
      if (fabs(d) < tol1) u = x + dsign(tol1, d);
      fu = f( u, data );
      if (fu > fx)
    goto sixty;
      if (u >= x)
    a = x;
      if (u < x)
    b = x;
      v = w;
      fv = fw;
      w = x;
      fw = fx;
      x = u;
      fx = fu;
      goto loop;
sixty: if (u < x) a = u;
      if (u >= x) b = u;
      if (fu <= fw)
    goto sevty;
      if (w == x)
    goto sevty;
      if (fu <= fv)
    goto eigty;
      if (v == x)
    goto eigty;
      if (v == w)
    goto eigty;
      goto loop;
sevty: v = w;
      fv = fw;
      w = u;
      fw = fu;
      goto loop;
eigty: v = u;
      fv = fu;
      goto loop;
end:
      return x;
}

variable_types: ax double

variable_types: bx double

variable_types: tol double

variable_types:
f
double (*)(double, void *)

variable_types:
data
void *

variable_types: c double

variable_types: d double

variable_types: e double

variable_types: eps double

variable_types: xm double

variable_types: p double

variable_types: q double

variable_types: r double

variable_types: u double

variable_types: v double

variable_types: w double

variable_types: fu double

variable_types: fv double

variable_types: fw double

variable_types: fx double

variable_types: x double


original_code:
void aiocb_list_destroy( aiocb_list *b )
{
 int i;
 struct aiocb *tmp_cb;
 for ( i = 0; i < b->n; i++ )
 {
  tmp_cb = (struct aiocb *)b->aiocb_l[i];
  free( tmp_cb );
 }
 free( b->aiocb_l );
 b->n = 0;
 b->issued = 0;
 b->aiocb_l = ((void *)0);
 free( b->aux_l );
 b->aux_l = ((void *)0);
}

canonical_original_code:
void aiocb_list_destroy(struct aiocb_list *b)
{
 int i;
 struct aiocb *tmp_cb;
 for ( i = 0; i < b->n; i++ )
 {
  tmp_cb = (struct aiocb *)b->aiocb_l[i];
  free( tmp_cb );
 }
 free( b->aiocb_l );
 b->n = 0;
 b->issued = 0;
 b->aiocb_l = ((void *)0);
 free( b->aux_l );
 b->aux_l = ((void *)0);
}

variable_types: struct aiocb_list { int n; struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __glibc_reserved[32]; } **aiocb_l; int issued; struct aiocb **aux_l; } *

variable_types: i int

user_defined_types: struct aiocb_list { int n; struct aiocb **aiocb_l; int issued; struct aiocb **aux_l; }

user_defined_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __glibc_reserved[32]; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


decompiled_code:
__int64 __fastcall get_diff_ms(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(int)((double)(a2[2] - a1[2]) / 1000.0 + (double)(1000 * (*a2 - *a1)) + 0.5);
}

original_code:
long get_diff_ms(struct timeval *start_time, struct timeval *end_time) {
    long seconds = end_time->tv_sec - start_time->tv_sec;
    long useconds = end_time->tv_usec - start_time->tv_usec;
    return ((seconds) * 1000 + useconds/1000.0) +0.5;
}

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

variable_types: seconds long

variable_types: useconds long

return_type: long


decompiled_code:
int __fastcall read_clock(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
int read_clock(struct timeval *t)
{
    return gettimeofday(t, ((void *)0));
}

return_type: int

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


decompiled_code:
__int64 __fastcall elapsed_time(_DWORD *a1, _QWORD *a2)
{
return (unsigned int)(int)((double)(int)(*a2 - *a1) * 1000000.0 + (double)(int)(a2[1] - a1[2]));
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _QWORD *a2)
{
return (unsigned int)(int)((double)(int)(*a2 - *a1) * 1000000.0 + (double)(int)(a2[1] - a1[2]));
}

original_code:
int elapsed_time(struct timeval *start, struct timeval *end)
{
    return (int)(end->tv_sec - start->tv_sec) * 1e6 +
     (int)(end->tv_usec - start->tv_usec);
}

variable_types:
end
struct timeval *


decompiled_code:
void *__fastcall fgls_malloc_impl(const char *a1, __int64 a2, size_t a3)
{
void *result; // rax

result = malloc(a3);
if ( !result )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(const char *a1, __int64 a2, size_t a3)
{
void *result; // rax

result = malloc(a3);
if ( !result )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return result;
}

original_code:
void * fgls_malloc_impl( const char* file, long line, size_t size )
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    return buf;
}

canonical_original_code:
void *fgls_malloc_impl(char *file, long line, unsigned long size)
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    return buf;
}

variable_types:
file
char *

variable_types: line long

variable_types:
size
unsigned long

variable_types:
buf
void *

return_type: void *


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

result = fprintf(stderr, "[Error]: %s\n", a1);
if ( a2 )
exit(1);
return result;
}

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

result = fprintf(stderr, "[Error]: %s\n", a1);
if ( a2 )
exit(1);
return result;
}

original_code:
void error_msg(char *msg, int abort)
{
    fprintf(stderr, "[Error]: %s\n", msg);
    if (abort)
        exit( 1 );
}

variable_types:
msg
char *

variable_types: abort int


main

canonical_name: main

repo: lucasb-eyer/cuGWAS-proto

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r14
const char *v4; // rbx
int v5; // er13
int i; // ebp
__int64 v7; // rax
struct timeval v9; // [rsp+0h] [rbp-B78h] BYREF
struct timeval tv; // [rsp+10h] [rbp-B68h] BYREF
char v11[256]; // [rsp+20h] [rbp-B58h] BYREF
char v12[256]; // [rsp+120h] [rbp-A58h] BYREF
char v13[256]; // [rsp+220h] [rbp-958h] BYREF
char s[256]; // [rsp+320h] [rbp-858h] BYREF
char v15[768]; // [rsp+420h] [rbp-758h] BYREF
char v16[256]; // [rsp+720h] [rbp-458h] BYREF
char v17[256]; // [rsp+820h] [rbp-358h] BYREF
char v18[256]; // [rsp+920h] [rbp-258h] BYREF
char v19[256]; // [rsp+A20h] [rbp-158h] BYREF
unsigned int v20; // [rsp+B20h] [rbp-58h] BYREF
unsigned int v21; // [rsp+B24h] [rbp-54h] BYREF
unsigned int v22; // [rsp+B28h] [rbp-50h] BYREF
unsigned int v23; // [rsp+B2Ch] [rbp-4Ch] BYREF
unsigned int v24; // [rsp+B30h] [rbp-48h] BYREF
unsigned int v25; // [rsp+B34h] [rbp-44h]
unsigned int v26; // [rsp+B38h] [rbp-40h] BYREF
unsigned int v27; // [rsp+B3Ch] [rbp-3Ch] BYREF
unsigned int v28[14]; // [rsp+B40h] [rbp-38h] BYREF

if ( argc != 4 )
{
fprintf(stderr, "Usage: %s <variant - [e|m]> <data_set_directory> <#repetitions>\n", *argv);
fwrite("\tnote: data_set_directory must contain files:\n", 1uLL, 0x2EuLL, stderr);
fwrite("- Phi.in\n- H.in\n- Sig.in\n- XL.in\n- XR.in\n- Y.in\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
v3 = *argv[1];
v4 = argv[2];
v5 = atoi(argv[3]);
_isoc99_scanf("%d", &v20);
_isoc99_scanf("%d", &v21);
_isoc99_scanf("%d", &v22);
_isoc99_scanf("%d", &v23);
_isoc99_scanf("%d", &v24);
_isoc99_scanf("%d", &v26);
_isoc99_scanf("%d", &v27);
_isoc99_scanf("%d", v28);
v25 = v21 - v24;
gettimeofday(&tv, 0LL);
if ( v5 > 0 )
{
for ( i = 0; i != v5; ++i )
{
sprintf(s, "%s/XL.in", v4);
sprintf(v15, "%s/XR.in", v4);
sprintf(v16, "%s/Y.in", v4);
sprintf(v17, "%s/Y.tmp", v4);
sprintf(v11, "%s/Phi.in", v4);
sprintf(v12, "%s/H.in", v4);
sprintf(v13, "%s/Sig.in", v4);
sprintf(v18, "%s/B.out", v4);
sprintf(v19, "%s/V.out", v4);
if ( v3 == 101 )
fgls_eigen(v20, v21, v22, v23, v24, v25, v26, v27, v28[0], v11, v12, v13, s, v15, v16, v18, v19);
else
fgls_chol(v20, v21, v22, v23, v24, v25, v26, v27, v28[0], v11, v12, v13, s, v15, v16, v18, v19);
}
}
gettimeofday(&v9, 0LL);
v7 = get_diff_ms(&tv, &v9);
printf("%ld\n", v7 / v5);
return 0;
}

original_code:
int main( int argc, char *argv[] )
{
  char *dir, var;
  int i, nrep;
  FGLS_config_t cf;
  struct timeval start, end;
  if (argc != 4)
  {
    fprintf(stderr, "Usage: %s <variant - [e|m]> <data_set_directory> <#repetitions>\n", argv[0]);
    fprintf(stderr, "\tnote: data_set_directory must contain files:\n");
    fprintf(stderr, "- Phi.in\n- H.in\n- Sig.in\n- XL.in\n- XR.in\n- Y.in\n");
    exit(1);
  }
  var = argv[1][0];
  dir = argv[2];
  nrep = atoi(argv[3]);
  scanf("%d", &cf.n);
  scanf("%d", &cf.p);
  scanf("%d", &cf.m);
  scanf("%d", &cf.t);
  scanf("%d", &cf.wXL);
  scanf("%d", &cf.x_b);
  scanf("%d", &cf.y_b);
  scanf("%d", &cf.NUM_COMPUTE_THREADS);
  cf.wXR = cf.p - cf.wXL;
  gettimeofday(&start, ((void *)0));
  for ( i = 0; i < nrep; i++ )
  {
      sprintf(cf.XL_path, "%s/XL.in", dir);
      sprintf(cf.XR_path, "%s/XR.in", dir);
      sprintf(cf.Y_path, "%s/Y.in", dir);
      sprintf(cf.ZtY_path, "%s/Y.tmp", dir);
      sprintf(cf.Phi_path, "%s/Phi.in", dir);
      sprintf(cf.h_path, "%s/H.in", dir);
      sprintf(cf.sigma_path,"%s/Sig.in", dir);
      sprintf(cf.B_path, "%s/B.out", dir);
      sprintf(cf.V_path, "%s/V.out", dir);
      if ( var == 'e' )
          fgls_eigen(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
      else
          fgls_chol(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
  }
  gettimeofday(&end, ((void *)0));
  long total = get_diff_ms(&start, &end) / nrep;
  printf("%ld\n", total);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *dir; char var;
  int i; int nrep;
  struct FGLS_config_t cf;
  struct timeval start; struct timeval end;
  if (argc != 4)
  {
    fprintf(stderr, "Usage: %s <variant - [e|m]> <data_set_directory> <#repetitions>\n", argv[0]);
    fprintf(stderr, "\tnote: data_set_directory must contain files:\n");
    fprintf(stderr, "- Phi.in\n- H.in\n- Sig.in\n- XL.in\n- XR.in\n- Y.in\n");
    exit(1);
  }
  var = argv[1][0];
  dir = argv[2];
  nrep = atoi(argv[3]);
  scanf("%d", &cf.n);
  scanf("%d", &cf.p);
  scanf("%d", &cf.m);
  scanf("%d", &cf.t);
  scanf("%d", &cf.wXL);
  scanf("%d", &cf.x_b);
  scanf("%d", &cf.y_b);
  scanf("%d", &cf.NUM_COMPUTE_THREADS);
  cf.wXR = cf.p - cf.wXL;
  gettimeofday(&start, ((void *)0));
  for ( i = 0; i < nrep; i++ )
  {
      sprintf(cf.XL_path, "%s/XL.in", dir);
      sprintf(cf.XR_path, "%s/XR.in", dir);
      sprintf(cf.Y_path, "%s/Y.in", dir);
      sprintf(cf.ZtY_path, "%s/Y.tmp", dir);
      sprintf(cf.Phi_path, "%s/Phi.in", dir);
      sprintf(cf.h_path, "%s/H.in", dir);
      sprintf(cf.sigma_path,"%s/Sig.in", dir);
      sprintf(cf.B_path, "%s/B.out", dir);
      sprintf(cf.V_path, "%s/V.out", dir);
      if ( var == 'e' )
          fgls_eigen(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
      else
          fgls_chol(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
  }
  gettimeofday(&end, ((void *)0));
  long total = get_diff_ms(&start, &end) / nrep;
  printf("%ld\n", total);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
dir
char *

variable_types: var char

variable_types: nrep int

variable_types: struct FGLS_config_t { char Phi_path[256]; char h_path[256]; char sigma_path[256]; char XL_path[256]; char XR_path[256]; char ZtXL_path[256]; char ZtXR_path[256]; char Y_path[256]; char ZtY_path[256]; char B_path[256]; char V_path[256]; int n; int p; int m; int t; int wXL; int wXR; int x_b; int y_b; int NUM_COMPUTE_THREADS; }

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

variable_types: total long


compare

decompiled_code:
double __fastcall compare(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
__int64 v4; // rax
double v5; // xmm0_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-10h]

if ( a3 <= 0 )
return 0.0;
v4 = 0LL;
v8 = 0.0;
do
{
*(_QWORD *)&v5 = COERCE_UNSIGNED_INT64((*(double *)(a1 + 8 * v4) - *(double *)(a2 + 8 * v4)) / *(double *)(a2 + 8 * v4)) & LC15;
if ( v5 > v8 )
a4 = v4;
v6 = fmax(v5, v8);
v8 = v6;
++v4;
}
while ( v4 != a3 );
if ( v6 > 1.0e-15 )
printf(
"max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n",
v6,
a4,
*(double *)(a1 + 8LL * (int)a4) - *(double *)(a2 + 8LL * (int)a4),
*(double *)(a1 + 8LL * (int)a4),
*(double *)(a2 + 8LL * (int)a4));
return v8;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
__int64 v4; // rax
double v5; // xmm0_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-10h]

if ( a3 <= 0 )
return 0.0;
v4 = 0LL;
v8 = 0.0;
do
{
*(_QWORD *)&v5 = COERCE_UNSIGNED_INT64((*(double *)(a1 + 8 * v4) - *(double *)(a2 + 8 * v4)) / *(double *)(a2 + 8 * v4)) & LC15;
if ( v5 > v8 )
a4 = v4;
v6 = fmax(v5, v8);
v8 = v6;
++v4;
}
while ( v4 != a3 );
if ( v6 > 1.0e-15 )
printf(
"max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n",
v6,
a4,
*(double *)(a1 + 8LL * (int)a4) - *(double *)(a2 + 8LL * (int)a4),
*(double *)(a1 + 8LL * (int)a4),
*(double *)(a2 + 8LL * (int)a4));
return v8;
}

original_code:
double compare(double* a, double* b, int size) {
  double maxerr = 0.0, relerr = 0.0;
  int i, maxerr_i;
  for (i = 0; i < size; i++) {
    relerr = fabs((a[i]-b[i])/b[i]);
    if(relerr > maxerr) {
      maxerr = relerr;
      maxerr_i = i;
    }
  }
  if(maxerr > 1e-15)
    printf("max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n", maxerr, maxerr_i, a[maxerr_i]-b[maxerr_i], a[maxerr_i], b[maxerr_i]);
  return maxerr;
}

canonical_original_code:
double compare(double *a, double *b, int size) {
  double maxerr = 0.0; double relerr = 0.0;
  int i; int maxerr_i;
  for (i = 0; i < size; i++) {
    relerr = fabs((a[i]-b[i])/b[i]);
    if(relerr > maxerr) {
      maxerr = relerr;
      maxerr_i = i;
    }
  }
  if(maxerr > 1e-15)
    printf("max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n", maxerr, maxerr_i, a[maxerr_i]-b[maxerr_i], a[maxerr_i], b[maxerr_i]);
  return maxerr;
}

variable_types:
a
double *

variable_types:
b
double *

variable_types: size int

variable_types: maxerr double

variable_types: relerr double

variable_types: i int


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

result = fprintf(stderr, "[Error]: %s\n", a1);
if ( a2 )
exit(1);
return result;
}

original_code:
void error_msg(char *msg, int abort)
{
    fprintf(stderr, "[Error]: %s\n", msg);
    if (abort)
        exit(1);
}


decompiled_code:
void *__fastcall fgls_malloc_impl(const char *a1, __int64 a2, size_t a3)
{
void *v4; // rax

v4 = malloc(a3);
if ( !v4 )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return memset(v4, 0, a3);
}

canonical_decompiled_code:
void *__fastcall func1(const char *a1, __int64 a2, size_t a3)
{
void *v4; // rax

v4 = malloc(a3);
if ( !v4 )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return memset(v4, 0, a3);
}

original_code:
void * fgls_malloc_impl( const char* file, long line, size_t size )
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    memset(buf, 0, size);
    return buf;
}

canonical_original_code:
void *fgls_malloc_impl(char *file, long line, unsigned long size)
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    memset(buf, 0, size);
    return buf;
}

variable_types:
file
char *

variable_types: line long

variable_types:
size
unsigned long

variable_types:
buf
void *


canonical_decompiled_code:
int __fastcall func2(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_original_code:
int read_clock(struct timeval *t)
{
    return gettimeofday(t, ((void *)0));
}

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


canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, _QWORD *a2)
{
return (unsigned int)(int)((double)(int)(*a2 - *a1) * 1000000.0 + (double)(int)(a2[1] - a1[2]));
}

original_code:
int elapsed_time(struct timeval *start, struct timeval *end)
{
    return (int)(end->tv_sec - start->tv_sec)*1e6 + (int)(end->tv_usec - start->tv_usec);
}

variable_types:
end
struct timeval *


decompiled_code:
int __fastcall sleep_seconds(double a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
double iptr[2]; // [rsp+18h] [rbp-10h] BYREF

iptr[0] = 0.0;
v2.tv_nsec = (unsigned int)(int)(modf(a1, iptr) * 1000000.0);
v2.tv_sec = (unsigned int)(int)iptr[0];
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func4(double a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
double iptr[2]; // [rsp+18h] [rbp-10h] BYREF

iptr[0] = 0.0;
v2.tv_nsec = (unsigned int)(int)(modf(a1, iptr) * 1000000.0);
v2.tv_sec = (unsigned int)(int)iptr[0];
return nanosleep(&v2, 0LL);
}

original_code:
void sleep_seconds(double seconds)
{
    double real = 0;
    struct timespec ts;
    ts.tv_nsec = (long)(modf(seconds, &real) * 1000000.0);
    ts.tv_sec = (time_t)real;
    nanosleep(&ts, 0);
}

canonical_original_code:
void sleep_seconds(double seconds)
{
    double real = 0;
    struct timespec ts;
    ts.tv_nsec = (long)(modf(seconds, &real) * 1000000.0);
    ts.tv_sec = (long)real;
    nanosleep(&ts, 0);
}

variable_types: seconds double

variable_types: real double

variable_types: struct timespec { long tv_sec; long tv_nsec; }


original_code:
void initialize_config(
        FGLS_config_t *cf,
        int n, int p, int m, int t, int wXL, int wXR,
        int x_b, int y_b, int num_threads,
        char *Phi_path, char *h2_path, char *sigma2_path,
        char *XL_path, char *XR_path, char *Y_path,
        char *B_path, char *V_path
)
{
    cf->n = n;
    cf->p = p;
    cf->m = m;
    cf->t = t;
    cf->wXR = wXR;
    cf->wXL = wXL;
    cf->x_b = x_b;
    cf->y_b = y_b;
    cf->NUM_COMPUTE_THREADS = num_threads;
    sprintf( cf->Phi_path, "%s", Phi_path );
    sprintf( cf->h_path, "%s", h2_path );
    sprintf( cf->sigma_path , "%s", sigma2_path );
    sprintf( cf->XL_path, "%s", XL_path );
    sprintf( cf->XR_path, "%s", XR_path );
    sprintf( cf->Y_path, "%s", Y_path );
    sprintf( cf->B_path, "%s", B_path );
    sprintf( cf->V_path, "%s", V_path );
    snprintf( cf->ZtXL_path, 256, "%s.tmp", XL_path );
    snprintf( cf->ZtXR_path, 256, "%s.tmp", XR_path );
    snprintf( cf->ZtY_path, 256, "%s.tmp", Y_path );
    return;
}

canonical_original_code:
void initialize_config(struct FGLS_config_t *cf, int n, int p, int m, int t, int wXL, int wXR, int x_b, int y_b, int num_threads, char *Phi_path, char *h2_path, char *sigma2_path, char *XL_path, char *XR_path, char *Y_path, char *B_path, char *V_path)
{
    cf->n = n;
    cf->p = p;
    cf->m = m;
    cf->t = t;
    cf->wXR = wXR;
    cf->wXL = wXL;
    cf->x_b = x_b;
    cf->y_b = y_b;
    cf->NUM_COMPUTE_THREADS = num_threads;
    sprintf( cf->Phi_path, "%s", Phi_path );
    sprintf( cf->h_path, "%s", h2_path );
    sprintf( cf->sigma_path , "%s", sigma2_path );
    sprintf( cf->XL_path, "%s", XL_path );
    sprintf( cf->XR_path, "%s", XR_path );
    sprintf( cf->Y_path, "%s", Y_path );
    sprintf( cf->B_path, "%s", B_path );
    sprintf( cf->V_path, "%s", V_path );
    snprintf( cf->ZtXL_path, 256, "%s.tmp", XL_path );
    snprintf( cf->ZtXR_path, 256, "%s.tmp", XR_path );
    snprintf( cf->ZtY_path, 256, "%s.tmp", Y_path );
    return;
}

variable_types: struct FGLS_config_t { char Phi_path[256]; char h_path[256]; char sigma_path[256]; char XL_path[256]; char XR_path[256]; char ZtXL_path[256]; char ZtXR_path[256]; char Y_path[256]; char ZtY_path[256]; char B_path[256]; char V_path[256]; int n; int p; int m; int t; int wXL; int wXR; int x_b; int y_b; int NUM_COMPUTE_THREADS; } *

variable_types: n int

variable_types: p int

variable_types: m int

variable_types: t int

variable_types: wXL int

variable_types: wXR int


canonical_original_code:
long get_diff_ms(struct timeval *start_time, struct timeval *end_time) {
    long seconds = end_time->tv_sec - start_time->tv_sec;
    long useconds = end_time->tv_usec - start_time->tv_usec;
    return ((seconds) * 1000 + useconds/1000.0) +0.5;
}

variable_types: seconds long

variable_types: useconds long


original_code:
long get_diff_us(struct timeval *start_time, struct timeval *end_time) {
    long seconds = end_time->tv_sec - start_time->tv_sec;
    long useconds = end_time->tv_usec - start_time->tv_usec;
    return ((seconds) * 1000000 + useconds);
}


original_code:
long get_diff_ns(struct timespec *start, struct timespec *end)
{
    long seconds, nseconds;
    long nsecs_in_sec = 1e9;
    if ( (end->tv_nsec - start->tv_nsec) < 0 )
    {
        seconds = end->tv_sec - start->tv_sec - 1;
        nseconds = nsecs_in_sec - (end->tv_nsec - start->tv_nsec);
        return nsecs_in_sec * seconds + nseconds;
    }
    else
    {
        seconds = end->tv_sec - start->tv_sec;
        nseconds = end->tv_nsec - start->tv_nsec;
        return nsecs_in_sec * seconds + nseconds;
    }
}

canonical_original_code:
long get_diff_ns(struct timespec *start, struct timespec *end)
{
    long seconds; long nseconds;
    long nsecs_in_sec = 1e9;
    if ( (end->tv_nsec - start->tv_nsec) < 0 )
    {
        seconds = end->tv_sec - start->tv_sec - 1;
        nseconds = nsecs_in_sec - (end->tv_nsec - start->tv_nsec);
        return nsecs_in_sec * seconds + nseconds;
    }
    else
    {
        seconds = end->tv_sec - start->tv_sec;
        nseconds = end->tv_nsec - start->tv_nsec;
        return nsecs_in_sec * seconds + nseconds;
    }
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types:
end
struct timespec *

variable_types: nseconds long


decompiled_code:
int __fastcall fgls_aio_read(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_read(aiocbp);
if ( result )
{
perror("aio_read error");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_read(aiocbp);
if ( result )
{
perror("aio_read error");
exit(1);
}
return result;
}

original_code:
void fgls_aio_read(struct aiocb *aiocb, int fildes, void *buf, size_t nbytes, off_t offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_read( aiocb ) != 0 )
    {
        perror("aio_read error");
        exit( 1 );
    }
    return;
}

canonical_original_code:
void fgls_aio_read(struct aiocb *aiocb, int fildes, void *buf, unsigned long nbytes, long offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_read( aiocb ) != 0 )
    {
        perror("aio_read error");
        exit( 1 );
    }
    return;
}

variable_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __pad[-1]; char __glibc_reserved[32]; } *

variable_types: fildes int

variable_types:
buf
void *

variable_types:
nbytes
unsigned long

variable_types: offset long

user_defined_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __pad[-1]; char __glibc_reserved[32]; }


decompiled_code:
int __fastcall fgls_aio_write(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_write(aiocbp);
if ( result )
{
perror("aio_write error");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_write(aiocbp);
if ( result )
{
perror("aio_write error");
exit(1);
}
return result;
}

original_code:
void fgls_aio_write(struct aiocb *aiocb, int fildes, void *buf, size_t nbytes, off_t offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_write( aiocb ) != 0 )
    {
        perror("aio_write error");
        exit( 1 );
    }
    return;
}

canonical_original_code:
void fgls_aio_write(struct aiocb *aiocb, int fildes, void *buf, unsigned long nbytes, long offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_write( aiocb ) != 0 )
    {
        perror("aio_write error");
        exit( 1 );
    }
    return;
}

user_defined_types: union sigval { int sival_int; void *sival_ptr; }

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
int __fastcall fgls_aio_suspend(const struct aiocb *const *a1, int a2, const struct timespec *a3)
{
__ssize_t v3; // rax
struct aiocb **v4; // rbx

LODWORD(v3) = aio_suspend(a1, a2, a3);
if ( (_DWORD)v3 )
{
perror("aio_suspend error");
exit(1);
}
if ( a2 > 0 )
{
v4 = (struct aiocb **)a1;
do
{
v3 = aio_return(*v4);
if ( (*v4)->aio_nbytes != v3 )
{
perror("aio_suspend error - data not read completely");
exit(1);
}
++v4;
}
while ( v4 != (struct aiocb **)&a1[(unsigned int)(a2 - 1) + 1] );
}
return v3;
}

canonical_decompiled_code:
int __fastcall func4(const struct aiocb *const *a1, int a2, const struct timespec *a3)
{
__ssize_t v3; // rax
struct aiocb **v4; // rbx

LODWORD(v3) = aio_suspend(a1, a2, a3);
if ( (_DWORD)v3 )
{
perror("aio_suspend error");
exit(1);
}
if ( a2 > 0 )
{
v4 = (struct aiocb **)a1;
do
{
v3 = aio_return(*v4);
if ( (*v4)->aio_nbytes != v3 )
{
perror("aio_suspend error - data not read completely");
exit(1);
}
++v4;
}
while ( v4 != (struct aiocb **)&a1[(unsigned int)(a2 - 1) + 1] );
}
return v3;
}

original_code:
void fgls_aio_suspend(const struct aiocb * const cblist[],
                      int n, const struct timespec *timeout)
{
    if ( aio_suspend( cblist, n, timeout ) != 0 )
    {
        perror("aio_suspend error");
        exit( 1 );
    }
    int i = 0;
    for(i = 0 ; i < n ; ++i) {
        size_t gotten = aio_return( (struct aiocb *)cblist[i] );
        if(gotten != cblist[i]->aio_nbytes) {
            perror("aio_suspend error - data not read completely");
            exit( 1 );
        }
    }
}

canonical_original_code:
void fgls_aio_suspend(struct aiocb *cblist[], int n, struct timespec *timeout)
{
    if ( aio_suspend( cblist, n, timeout ) != 0 )
    {
        perror("aio_suspend error");
        exit( 1 );
    }
    int i = 0;
    for(i = 0 ; i < n ; ++i) {
        unsigned long gotten = aio_return( (struct aiocb *)cblist[i] );
        if(gotten != cblist[i]->aio_nbytes) {
            perror("aio_suspend error - data not read completely");
            exit( 1 );
        }
    }
}

variable_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __pad[-1]; char __glibc_reserved[32]; } *[]

variable_types: i int

variable_types:
gotten
unsigned long

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


repo: lucasb-eyer/heatmap

decompiled_code:
void linear_dist()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static float linear_dist(float dist)
{
    return dist;
}

variable_types: dist float

return_type: float


decompiled_code:
void __fastcall heatmap_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void heatmap_free(heatmap_t* h)
{
    free(h->buf);
    free(h);
}

canonical_original_code:
void heatmap_free(struct heatmap_t *h)
{
    free(h->buf);
    free(h);
}

variable_types: struct heatmap_t { float *buf; float max; unsigned int w; } *


original_code:
void heatmap_add_point_with_stamp(heatmap_t* h, unsigned x, unsigned y, const heatmap_stamp_t* stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    {
        const unsigned x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        const unsigned y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        const unsigned x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        const unsigned y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float* line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            const float* stampline = stamp->buf + iy*stamp->w + x0;
            unsigned ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

canonical_original_code:
void heatmap_add_point_with_stamp(struct heatmap_t *h, unsigned int x, unsigned int y, struct heatmap_stamp_t *stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    {
        unsigned int x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        unsigned int y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        unsigned int x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        unsigned int y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned int iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float *line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            float *stampline = stamp->buf + iy*stamp->w + x0;
            unsigned int ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types: struct heatmap_stamp_t { float *buf; unsigned int w; } *

variable_types:
iy
unsigned int

variable_types:
line
float *

variable_types:
stampline
float *

variable_types:
ix
unsigned int

user_defined_types: struct heatmap_t { float *buf; float max; unsigned int w; }


decompiled_code:
void __fastcall heatmap_add_point(__int64 a1, unsigned int a2, unsigned int a3)
{
heatmap_add_point_with_stamp(a1, a2, a3, (__int64)&stamp_default_4);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3)
{
func4(a1, a2, a3, (__int64)&stamp_default_4);
}

original_code:
void heatmap_add_point(heatmap_t* h, unsigned x, unsigned y)
{
    heatmap_add_point_with_stamp(h, x, y, &stamp_default_4);
}

canonical_original_code:
void heatmap_add_point(struct heatmap_t *h, unsigned int x, unsigned int y)
{
    heatmap_add_point_with_stamp(h, x, y, &stamp_default_4);
}


original_code:
void heatmap_add_weighted_point_with_stamp(heatmap_t* h, unsigned x, unsigned y, float w, const heatmap_stamp_t* stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    ((void) (0));
    {
        const unsigned x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        const unsigned y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        const unsigned x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        const unsigned y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float* line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            const float* stampline = stamp->buf + iy*stamp->w + x0;
            unsigned ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline * w;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

canonical_original_code:
void heatmap_add_weighted_point_with_stamp(struct heatmap_t *h, unsigned int x, unsigned int y, float w, struct heatmap_stamp_t *stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    ((void) (0));
    {
        unsigned int x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        unsigned int y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        unsigned int x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        unsigned int y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned int iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float *line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            float *stampline = stamp->buf + iy*stamp->w + x0;
            unsigned int ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline * w;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

variable_types: w float

user_defined_types: struct heatmap_stamp_t { float *buf; unsigned int w; }


decompiled_code:
void __fastcall heatmap_add_weighted_point(__int64 a1, unsigned int a2, unsigned int a3, float a4)
{
heatmap_add_weighted_point_with_stamp(a1, a2, a3, (__int64)&stamp_default_4, a4);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, unsigned int a2, unsigned int a3, float a4)
{
func6(a1, a2, a3, (__int64)&stamp_default_4, a4);
}

original_code:
void heatmap_add_weighted_point(heatmap_t* h, unsigned x, unsigned y, float w)
{
    heatmap_add_weighted_point_with_stamp(h, x, y, w, &stamp_default_4);
}

canonical_original_code:
void heatmap_add_weighted_point(struct heatmap_t *h, unsigned int x, unsigned int y, float w)
{
    heatmap_add_weighted_point_with_stamp(h, x, y, w, &stamp_default_4);
}


original_code:
unsigned char* heatmap_render_saturated_to(const heatmap_t* h, const heatmap_colorscheme_t* colorscheme, float saturation, unsigned char* colorbuf)
{
    unsigned y;
    ((void) (0));
    if(!colorbuf) {
        colorbuf = (unsigned char*)malloc(h->w*h->h*4);
        if(!colorbuf) {
            return 0;
        }
    }
    for(y = 0 ; y < h->h ; ++y) {
        float* bufline = h->buf + y*h->w;
        unsigned char* colorline = colorbuf + 4*y*h->w;
        unsigned x;
        for(x = 0 ; x < h->w ; ++x, ++bufline) {
            const float val = (*bufline > saturation ? saturation : *bufline)/saturation;
            const size_t idx = (size_t)((float)(colorscheme->ncolors-1)*val + 0.5f);
            ((void) (0));
            ((void) (0));
            memcpy(colorline, colorscheme->colors + idx*4, 4);
            colorline += 4;
        }
    }
    return colorbuf;
}

canonical_original_code:
unsigned char *heatmap_render_saturated_to(struct heatmap_t *h, struct heatmap_colorscheme_t *colorscheme, float saturation, unsigned char *colorbuf)
{
    unsigned int y;
    ((void) (0));
    if(!colorbuf) {
        colorbuf = (unsigned char *)malloc(h->w*h->h*4);
        if(!colorbuf) {
            return 0;
        }
    }
    for(y = 0 ; y < h->h ; ++y) {
        float *bufline = h->buf + y*h->w;
        unsigned char *colorline = colorbuf + 4*y*h->w;
        unsigned int x;
        for(x = 0 ; x < h->w ; ++x, ++bufline) {
            float val = (*bufline > saturation ? saturation : *bufline)/saturation;
            unsigned long idx = (size_t)((float)(colorscheme->ncolors-1)*val + 0.5f);
            ((void) (0));
            ((void) (0));
            memcpy(colorline, colorscheme->colors + idx*4, 4);
            colorline += 4;
        }
    }
    return colorbuf;
}

variable_types: struct heatmap_colorscheme_t { unsigned char *colors; unsigned long ncolors; } *

variable_types: saturation float

variable_types:
colorbuf
unsigned char *

variable_types:
bufline
float *

variable_types:
colorline
unsigned char *

variable_types: val float

variable_types:
idx
unsigned long

return_type: unsigned char *


decompiled_code:
char *__fastcall heatmap_render_to(__int64 a1, _QWORD *a2, char *a3)
{
float v3; // xmm0_4

v3 = *(float *)(a1 + 8);
if ( v3 <= 0.0 )
v3 = *(float *)&LC2;
return heatmap_render_saturated_to(a1, a2, a3, v3);
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1, _QWORD *a2, char *a3)
{
float v3; // xmm0_4

v3 = *(float *)(a1 + 8);
if ( v3 <= 0.0 )
v3 = *(float *)&LC2;
return func8(a1, a2, a3, v3);
}

original_code:
unsigned char* heatmap_render_to(const heatmap_t* h, const heatmap_colorscheme_t* colorscheme, unsigned char* colorbuf)
{
    return heatmap_render_saturated_to(h, colorscheme, h->max > 0.0f ? h->max : 1.0f, colorbuf);
}

canonical_original_code:
unsigned char *heatmap_render_to(struct heatmap_t *h, struct heatmap_colorscheme_t *colorscheme, unsigned char *colorbuf)
{
    return heatmap_render_saturated_to(h, colorscheme, h->max > 0.0f ? h->max : 1.0f, colorbuf);
}

user_defined_types: struct heatmap_colorscheme_t { unsigned char *colors; unsigned long ncolors; }


decompiled_code:
char *__fastcall heatmap_render_default_to(__int64 a1, char *a2)
{
return heatmap_render_to(a1, heatmap_cs_default, a2);
}

canonical_decompiled_code:
char *__fastcall func10(__int64 a1, char *a2)
{
return func9(a1, heatmap_cs_default, a2);
}

original_code:
unsigned char* heatmap_render_default_to(const heatmap_t* h, unsigned char* colorbuf)
{
    return heatmap_render_to(h, heatmap_cs_default, colorbuf);
}

canonical_original_code:
unsigned char *heatmap_render_default_to(struct heatmap_t *h, unsigned char *colorbuf)
{
    return heatmap_render_to(h, heatmap_cs_default, colorbuf);
}


decompiled_code:
void __fastcall heatmap_stamp_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void heatmap_stamp_free(heatmap_stamp_t* s)
{
    free(s->buf);
    free(s);
}

canonical_original_code:
void heatmap_stamp_free(struct heatmap_stamp_t *s)
{
    free(s->buf);
    free(s);
}


decompiled_code:
void __fastcall heatmap_colorscheme_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void heatmap_colorscheme_free(heatmap_colorscheme_t* cs)
{
    free((void*)cs->colors);
    free(cs);
}

canonical_original_code:
void heatmap_colorscheme_free(struct heatmap_colorscheme_t *cs)
{
    free((void *)cs->colors);
    free(cs);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
__int64 v4; // r15
unsigned __int64 v5; // rcx
__int64 v6; // rdx
int v7; // ebx
float v8; // xmm0_4
char *v9; // rbx
void *v10; // rax
__m128i *v11; // rax
void *v12; // rdx
unsigned int v13; // ebp
int v14; // er12
__int64 v16; // r12
__int64 v17; // rax
std::ostream *v18; // rax
float v19; // [rsp+4h] [rbp-27D4h]
void *v20; // [rsp+18h] [rbp-27C0h] BYREF
__int64 v21; // [rsp+20h] [rbp-27B8h] BYREF
int v22; // [rsp+28h] [rbp-27B0h]
char v23; // [rsp+2Ch] [rbp-27ACh]
__int64 v24; // [rsp+30h] [rbp-27A8h] BYREF
int v25; // [rsp+38h] [rbp-27A0h]
char v26; // [rsp+3Ch] [rbp-279Ch]
void *v27[2]; // [rsp+40h] [rbp-2798h] BYREF
__int64 v28; // [rsp+50h] [rbp-2788h]
void *v29[2]; // [rsp+60h] [rbp-2778h] BYREF
__int64 v30[2]; // [rsp+70h] [rbp-2768h] BYREF
char v31[5008]; // [rsp+80h] [rbp-2758h] BYREF
unsigned __int64 v32[633]; // [rsp+1410h] [rbp-13C8h] BYREF

std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[0/3] Initializing.", 19LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v3 = heatmap_new(0x4000LL, 0x4000LL);
v4 = heatmap_stamp_gen(128LL);
std::random_device::random_device((std::random_device *)v31);
v5 = (unsigned int)std::random_device::_M_getval((std::random_device *)v31);
v6 = 1LL;
v32[0] = v5;
do
{
v5 = 1812433253 * ((unsigned int)v5 ^ (unsigned int)(v5 >> 30)) + (unsigned int)v6;
v32[v6++] = v5;
}
while ( v6 != 624 );
v23 = 0;
v7 = 1000;
v21 = 0x452AAAAB46000000LL;
v32[624] = 624LL;
v22 = 0;
v24 = 0x4580000046000000LL;
v25 = 0;
v26 = 0;
do
{
v19 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v24,
v32,
(float *)&v24);
v8 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v21,
v32,
(float *)&v21);
heatmap_add_point_with_stamp(v3, (unsigned int)(int)v8, (unsigned int)(int)v19, v4);
--v7;
}
while ( v7 );
heatmap_stamp_free(v4);
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[1/3] All points added to the heatmap.", 38LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v28 = 0LL;
*(_OWORD *)v27 = 0LL;
v27[0] = (void *)operator new(0x40000000uLL);
v9 = (char *)v27[0] + 0x40000000;
v28 = (__int64)v27[0] + 0x40000000;
v10 = memset(v27[0], 0, 0x40000000uLL);
v27[1] = v9;
heatmap_render_default_to(v3, v10);
heatmap_free(v3);
std::__ostream_insert<char,std::char_traits<char>>(
&std::cout,
"[2/3] Heatmap done rendering. (Saving to PNG will take some time...)",
68LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v20 = &loc_E + 3;
v29[0] = v30;
v11 = (__m128i *)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::_M_create(
v29,
&v20,
0LL);
v29[0] = v11;
v30[0] = (__int64)v20;
*v11 = _mm_load_si128((const __m128i *)&LC12);
v12 = v29[0];
v11[1].m128i_i8[0] = 103;
v29[1] = v20;
*((_BYTE *)v20 + (_QWORD)v12) = 0;
v13 = lodepng::encode(v29, v27, 0x4000LL, 0x4000LL, 6LL, 8LL);
if ( v29[0] != v30 )
operator delete(v29[0]);
if ( v13 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "encoder error ", 14LL);
v16 = std::ostream::_M_insert<unsigned long>(&std::cerr, v13);
std::__ostream_insert<char,std::char_traits<char>>(v16, ": ", 2LL);
v17 = lodepng_error_text(v13);
v18 = (std::ostream *)std::operator<<<std::char_traits<char>>(v16, v17);
std::endl<char,std::char_traits<char>>(v18);
v14 = 1;
}
else
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[3/3] All done, T. Hanks for your patience.", 43LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v14 = 0;
}
if ( v27[0] )
operator delete(v27[0]);
std::random_device::_M_fini((std::random_device *)v31);
return v14;
}

original_code:
int main()
{
    static const size_t w = 256, h = 512, npoints = 1000;
    unsigned char image[256*512*4];
    unsigned i;
    heatmap_t* hm = heatmap_new(w, h);
    srand(time(((void *)0)));
    for(i = 0 ; i < npoints ; ++i) {
        unsigned x = rand() % w/3 + rand() % w/3 + rand() % w/3;
        unsigned y = rand() % h/3 + rand() % h/3 + rand() % h/3;
        heatmap_add_point(hm, x, y);
    }
    heatmap_render_default_to(hm, image);
    heatmap_free(hm);
    {
        unsigned error = lodepng_encode32_file("heatmap.png", image, w, h);
        if(error)
            fprintf(stderr, "Error (%u) creating PNG file: %s\n",
                    error, lodepng_error_text(error));
    }
    return 0;
}

canonical_original_code:
int main()
{
    static unsigned long w = 256; static unsigned long h = 512; static unsigned long npoints = 1000;
    unsigned char image[-1];
    unsigned int i;
    struct heatmap_t *hm = heatmap_new(w, h);
    srand(time(((void *)0)));
    for(i = 0 ; i < npoints ; ++i) {
        unsigned int x = rand() % w/3 + rand() % w/3 + rand() % w/3;
        unsigned int y = rand() % h/3 + rand() % h/3 + rand() % h/3;
        heatmap_add_point(hm, x, y);
    }
    heatmap_render_default_to(hm, image);
    heatmap_free(hm);
    {
        unsigned int error = lodepng_encode32_file("heatmap.png", image, w, h);
        if(error)
            fprintf(stderr, "Error (%u) creating PNG file: %s\n",
                    error, lodepng_error_text(error));
    }
    return 0;
}

variable_types:
w
unsigned long

variable_types:
h
unsigned long

variable_types:
npoints
unsigned long

variable_types:
image
unsigned char [-1]

variable_types:
i
unsigned int

variable_types:
error
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned __int64 v4; // rcx
__int64 v5; // rdx
int v6; // er13
float v7; // xmm0_4
char *v8; // rbx
void *v9; // rax
unsigned int v10; // ebp
int v11; // er13
__int64 v13; // r13
__int64 v14; // rax
std::ostream *v15; // rbp
__int64 v16; // rax
_BYTE *v17; // r13
char v18; // si
std::ostream *v19; // rax
float v20; // [rsp+Ch] [rbp-27BCh]
__int64 v21; // [rsp+10h] [rbp-27B8h] BYREF
int v22; // [rsp+18h] [rbp-27B0h]
char v23; // [rsp+1Ch] [rbp-27ACh]
__int64 v24; // [rsp+20h] [rbp-27A8h] BYREF
int v25; // [rsp+28h] [rbp-27A0h]
char v26; // [rsp+2Ch] [rbp-279Ch]
void *v27[2]; // [rsp+30h] [rbp-2798h] BYREF
__int64 v28; // [rsp+40h] [rbp-2788h]
void *v29[2]; // [rsp+50h] [rbp-2778h] BYREF
char v30[16]; // [rsp+60h] [rbp-2768h] BYREF
char v31[5008]; // [rsp+70h] [rbp-2758h] BYREF
unsigned __int64 v32[633]; // [rsp+1400h] [rbp-13C8h] BYREF

v3 = heatmap_new(256LL, 512LL, envp);
std::random_device::random_device((std::random_device *)v31);
v4 = (unsigned int)std::random_device::_M_getval((std::random_device *)v31);
v5 = 1LL;
v32[0] = v4;
do
{
v4 = 1812433253 * ((unsigned int)v4 ^ (unsigned int)(v4 >> 30)) + (unsigned int)v5;
v32[v5++] = v4;
}
while ( v5 != 624 );
v23 = 0;
v6 = 1000;
v21 = 0x422AAAAB43000000LL;
v32[624] = 624LL;
v22 = 0;
v24 = 0x4300000043800000LL;
v25 = 0;
v26 = 0;
do
{
v20 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v24,
v32,
(float *)&v24);
v7 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v21,
v32,
(float *)&v21);
heatmap_add_point(v3, (unsigned int)(int)v7, (unsigned int)(int)v20);
--v6;
}
while ( v6 );
v28 = 0LL;
*(_OWORD *)v27 = 0LL;
v27[0] = (void *)operator new(0x80000uLL);
v8 = (char *)v27[0] + 0x80000;
v28 = (__int64)v27[0] + 0x80000;
v9 = memset(v27[0], 0, 0x80000uLL);
v27[1] = v8;
heatmap_render_default_to(v3, v9);
heatmap_free(v3);
strcpy(v30, "heatmap.png");
v29[0] = v30;
v29[1] = (void *)11;
v10 = lodepng::encode(v29, v27, 256LL, 512LL, 6LL, 8LL);
if ( v29[0] != v30 )
operator delete(v29[0]);
v11 = 0;
if ( v10 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "encoder error ", 14LL);
v13 = std::ostream::_M_insert<unsigned long>(&std::cerr, v10);
std::__ostream_insert<char,std::char_traits<char>>(v13, ": ", 2LL);
v14 = lodepng_error_text(v10);
v15 = (std::ostream *)std::operator<<<std::char_traits<char>>(v13, v14);
v16 = *(_QWORD *)(*(_QWORD *)v15 - 24LL);
v17 = *(_BYTE **)((char *)v15 + v16 + 240);
if ( !v17 )
std::__throw_bad_cast();
if ( v17[56] )
{
v18 = v17[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v15 + v16 + 240));
v18 = (*(__int64 (__fastcall **)(_BYTE *, __int64))(*(_QWORD *)v17 + 48LL))(v17, 10LL);
}
v19 = (std::ostream *)std::ostream::put(v15, v18);
std::ostream::flush(v19);
v11 = 1;
}
if ( v27[0] )
operator delete(v27[0]);
std::random_device::_M_fini((std::random_device *)v31);
return v11;
}

variable_types: struct heatmap_t { float *buf; float max; unsigned int w; } *

variable_types:
x
unsigned int

variable_types:
y
unsigned int


decompiled_code:
const char *test_cache_create()
{
__int64 v0; // rax
const char *v1; // rdx

v0 = kmem_cache_create("test", 12LL, 0LL, 0LL, 0LL);
if ( !v0 )
return "cache creation returned null?";
v1 = "effective size miscalculated";
if ( *(_QWORD *)(v0 + 16) == 16LL )
{
kmem_cache_destroy(v0, 12LL, "effective size miscalculated");
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
const char *func0()
{
__int64 v0; // rax
const char *v1; // rdx

v0 = kmem_cache_create("test", 12LL, 0LL, 0LL, 0LL);
if ( !v0 )
return "cache creation returned null?";
v1 = "effective size miscalculated";
if ( *(_QWORD *)(v0 + 16) == 16LL )
{
kmem_cache_destroy(v0, 12LL, "effective size miscalculated");
v1 = 0LL;
}
return v1;
}

original_code:
static char *
test_cache_create() {
    kmem_cache_t cp = kmem_cache_create("test", 12, 0, ((void *)0), ((void *)0));
    do { if (!(cp)) return "cache creation returned null?"; } while (0);
    do { if (!(cp->effsize == 16)) return "effective size miscalculated"; } while (0);
    kmem_cache_destroy(cp);
    return 0;
}

canonical_original_code:
static char *test_cache_create() {
    struct kmem_cache *cp = kmem_cache_create("test", 12, 0, ((void *)0), ((void *)0));
    do { if (!(cp)) return "cache creation returned null?"; } while (0);
    do { if (!(cp->effsize == 16)) return "effective size miscalculated"; } while (0);
    kmem_cache_destroy(cp);
    return 0;
}

variable_types: struct kmem_cache { char *name; unsigned long size; unsigned long effsize; int slab_maxbuf; void (*constructor)(void *, unsigned long); void (*destructor)(void *, unsigned long); struct kmem_slab { struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl { void *buf; struct kmem_bufctl *next; struct kmem_slab *slab; } *start; void *free_list; int bufcount; } *slabs; struct kmem_slab *slabs_back; } *

return_type: char *

user_defined_types: struct kmem_cache { char *name; unsigned long size; unsigned long effsize; int slab_maxbuf; void (*constructor)(void *, unsigned long); void (*destructor)(void *, unsigned long); struct kmem_slab *slabs; struct kmem_slab *slabs_back; }

user_defined_types: struct kmem_slab { struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl *start; void *free_list; int bufcount; }


decompiled_code:
__int64 test_cache_grow()
{
__int64 v0; // rbx
__int64 v1; // rdx

v0 = kmem_cache_create("test", 12LL, 0LL, 0LL, 0LL);
kmem_cache_grow(v0);
kmem_cache_destroy(v0, 12LL, v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
__int64 v1; // rdx

v0 = kmem_cache_create("test", 12LL, 0LL, 0LL, 0LL);
kmem_cache_grow(v0);
kmem_cache_destroy(v0, 12LL, v1);
return 0LL;
}

original_code:
static char *
test_cache_grow() {
    kmem_cache_t cp = kmem_cache_create("test", 12, 0, ((void *)0), ((void *)0));
    kmem_cache_grow(cp);
    kmem_cache_destroy(cp);
    return 0;
}

canonical_original_code:
static char *test_cache_grow() {
    struct kmem_cache *cp = kmem_cache_create("test", 12, 0, ((void *)0), ((void *)0));
    kmem_cache_grow(cp);
    kmem_cache_destroy(cp);
    return 0;
}

user_defined_types: struct kmem_bufctl { void *buf; struct kmem_bufctl *next; struct kmem_slab *slab; }


decompiled_code:
__int64 test_big_object()
{
__int64 v0; // rbp
int v1; // ebx
__int64 v2; // rdx

v0 = kmem_cache_create("test", 1000LL, 0LL, 0LL, 0LL);
v1 = 9;
do
{
kmem_cache_alloc(v0, 1LL);
--v1;
}
while ( v1 );
kmem_cache_destroy(v0, 1LL, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
int v1; // ebx
__int64 v2; // rdx

v0 = kmem_cache_create("test", 1000LL, 0LL, 0LL, 0LL);
v1 = 9;
do
{
kmem_cache_alloc(v0, 1LL);
--v1;
}
while ( v1 );
kmem_cache_destroy(v0, 1LL, v2);
return 0LL;
}

original_code:
static char *
test_big_object() {
    int i;
    void * pos;
    kmem_cache_t cp = kmem_cache_create("test", 1000, 0, ((void *)0), ((void *)0));
    for (i = 0; i < 9; i++) {
        pos = kmem_cache_alloc(cp, 0x01);
    }
    kmem_cache_destroy(cp);
    return 0;
}

canonical_original_code:
static char *test_big_object() {
    int i;
    void *pos;
    struct kmem_cache *cp = kmem_cache_create("test", 1000, 0, ((void *)0), ((void *)0));
    for (i = 0; i < 9; i++) {
        pos = kmem_cache_alloc(cp, 0x01);
    }
    kmem_cache_destroy(cp);
    return 0;
}

variable_types: i int

variable_types:
pos
void *


decompiled_code:
const char *test_all()
{
const char *result; // rax

result = test_cache_create();
++tests_run;
if ( !result )
{
result = (const char *)test_cache_grow();
++tests_run;
if ( !result )
{
result = (const char *)test_cache_alloc();
++tests_run;
if ( !result )
{
result = (const char *)test_cache_free();
++tests_run;
if ( !result )
{
result = (const char *)test_big_object();
++tests_run;
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *func5()
{
const char *result; // rax

result = func0();
++tests_run;
if ( !result )
{
result = (const char *)func1();
++tests_run;
if ( !result )
{
result = (const char *)func2();
++tests_run;
if ( !result )
{
result = (const char *)func4();
++tests_run;
if ( !result )
{
result = (const char *)func3();
++tests_run;
}
}
}
}
return result;
}

original_code:
static char *
test_all () {
    do { char *message = test_cache_create(); tests_run++; if (message) return (char*)message; } while (0);
    do { char *message = test_cache_grow(); tests_run++; if (message) return (char*)message; } while (0);
    do { char *message = test_cache_alloc(); tests_run++; if (message) return (char*)message; } while (0);
    do { char *message = test_cache_free(); tests_run++; if (message) return (char*)message; } while (0);
    do { char *message = test_big_object(); tests_run++; if (message) return (char*)message; } while (0);
    return 0;
}

canonical_original_code:
static char *test_all() {
    do { char *message = test_cache_create(); tests_run++; if (message) return (char *)message; } while (0);
    do { char *message = test_cache_grow(); tests_run++; if (message) return (char *)message; } while (0);
    do { char *message = test_cache_alloc(); tests_run++; if (message) return (char *)message; } while (0);
    do { char *message = test_cache_free(); tests_run++; if (message) return (char *)message; } while (0);
    do { char *message = test_big_object(); tests_run++; if (message) return (char *)message; } while (0);
    return 0;
}

variable_types:
message
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rbx

v3 = test_all();
v4 = v3;
if ( v3 )
printf("Test failed: %s\n", v3);
else
puts("ALL TESTS PASSED!");
printf("=====================\nTOTAL TESTS:\t%04d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rbx

v3 = func5();
v4 = v3;
if ( v3 )
printf("Test failed: %s\n", v3);
else
puts("ALL TESTS PASSED!");
printf("=====================\nTOTAL TESTS:\t%04d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

original_code:
int
main(void) {
    char * result = test_all();
    if (result)
        printf("Test failed: %s\n", result);
    else
        printf("ALL TESTS PASSED!\n");
    printf("=====================\nTOTAL TESTS:\t%04d\n", tests_run);
    return (result != 0);
}

canonical_original_code:
int main() {
    char *result = test_all();
    if (result)
        printf("Test failed: %s\n", result);
    else
        printf("ALL TESTS PASSED!\n");
    printf("=====================\nTOTAL TESTS:\t%04d\n", tests_run);
    return (result != 0);
}

variable_types:
result
char *


original_code:
void
kmem_cache_grow(kmem_cache_t cp) {
    void *mem;
    kmem_slab_t slab;
    void *p, *lastbuf;
    int i;
    kmem_bufctl_t bufctl;
    if (cp->size <= (size_t)sysconf(_SC_PAGESIZE)/8) {
        if (0 != posix_memalign(&mem, (size_t)sysconf(_SC_PAGESIZE), (size_t)sysconf(_SC_PAGESIZE)))
            return;
        slab = mem + (size_t)sysconf(_SC_PAGESIZE) - sizeof(struct kmem_slab);
        slab->next = slab->prev = slab;
        slab->bufcount = 0;
        slab->free_list = mem;
        lastbuf = mem + (cp->effsize * (cp->slab_maxbuf-1));
        for (p=mem; p < lastbuf; p+=cp->effsize)
             *((void **)p) = p + cp->effsize;
        __slab_move_to_front(cp, slab);
        ((void) sizeof ((cp->slabs == slab) ? 1 : 0), __extension__ ({ if (cp->slabs == slab) ; else __assert_fail ("cp->slabs == slab", "slab.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    }
    else {
        if (0 != posix_memalign(&mem, (size_t)sysconf(_SC_PAGESIZE), (cp->slab_maxbuf * cp->effsize)/(size_t)sysconf(_SC_PAGESIZE)))
            return;
        slab = (kmem_slab_t)malloc(sizeof(struct kmem_slab));
        slab->next = slab->prev = slab;
        slab->bufcount = 0;
        bufctl = (kmem_bufctl_t)malloc(sizeof(struct kmem_bufctl) * cp->slab_maxbuf);
        bufctl[0].next = ((void *)0);
        bufctl[0].buf = mem;
        bufctl[0].slab = slab;
        slab->start = &bufctl[0];
        slab->free_list = &bufctl[0];
        for (i=1; i < cp->slab_maxbuf; i++) {
            bufctl[i].next = slab->free_list;
            bufctl[i].buf = mem + (i*cp->effsize + ((size_t)sysconf(_SC_PAGESIZE)%cp->effsize * (((i+1)*cp->effsize)/(size_t)sysconf(_SC_PAGESIZE))));
            bufctl[i].slab = slab;
            slab->free_list = &bufctl[i];
        }
        __slab_move_to_front(cp, slab);
    }
}

canonical_original_code:
void kmem_cache_grow(struct kmem_cache *cp) {
    void *mem;
    struct kmem_slab *slab;
    void *p; void *lastbuf;
    int i;
    struct kmem_bufctl *bufctl;
    if (cp->size <= (unsigned long)sysconf(_SC_PAGESIZE)/8) {
        if (0 != posix_memalign(&mem, (unsigned long)sysconf(_SC_PAGESIZE), (unsigned long)sysconf(_SC_PAGESIZE)))
            return;
        slab = mem + (unsigned long)sysconf(_SC_PAGESIZE) - sizeof(struct kmem_slab);
        slab->next = slab->prev = slab;
        slab->bufcount = 0;
        slab->free_list = mem;
        lastbuf = mem + (cp->effsize * (cp->slab_maxbuf-1));
        for (p=mem; p < lastbuf; p+=cp->effsize)
             *((void **)p) = p + cp->effsize;
        __slab_move_to_front(cp, slab);
        ((void) sizeof ((cp->slabs == slab) ? 1 : 0), __extension__ ({ if (cp->slabs == slab) ; else __assert_fail ("cp->slabs == slab", "slab.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    }
    else {
        if (0 != posix_memalign(&mem, (unsigned long)sysconf(_SC_PAGESIZE), (cp->slab_maxbuf * cp->effsize)/(unsigned long)sysconf(_SC_PAGESIZE)))
            return;
        slab = (struct kmem_slab *)malloc(sizeof(struct kmem_slab));
        slab->next = slab->prev = slab;
        slab->bufcount = 0;
        bufctl = (struct kmem_bufctl *)malloc(sizeof(struct kmem_bufctl) * cp->slab_maxbuf);
        bufctl[0].next = ((void *)0);
        bufctl[0].buf = mem;
        bufctl[0].slab = slab;
        slab->start = &bufctl[0];
        slab->free_list = &bufctl[0];
        for (i=1; i < cp->slab_maxbuf; i++) {
            bufctl[i].next = slab->free_list;
            bufctl[i].buf = mem + (i*cp->effsize + ((unsigned long)sysconf(_SC_PAGESIZE)%cp->effsize * (((i+1)*cp->effsize)/(unsigned long)sysconf(_SC_PAGESIZE))));
            bufctl[i].slab = slab;
            slab->free_list = &bufctl[i];
        }
        __slab_move_to_front(cp, slab);
    }
}

variable_types:
mem
void *

variable_types: struct kmem_slab { struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl { void *buf; struct kmem_bufctl *next; struct kmem_slab *slab; } *start; void *free_list; int bufcount; } *

variable_types:
p
void *

variable_types:
lastbuf
void *

variable_types: struct kmem_bufctl { void *buf; struct kmem_bufctl *next; struct kmem_slab { struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl *start; void *free_list; int bufcount; } *slab; } *


decompiled_code:
unsigned __int64 __fastcall kmem_cache_free(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbp
unsigned __int64 result; // rax
__int64 v4; // rdx
unsigned __int64 v5; // rbp
int v6; // eax

v2 = *(_QWORD *)(a1 + 8);
result = (unsigned __int64)sysconf(30) >> 3;
if ( v2 <= result )
{
v5 = (a2 & 0xFFFFFFFFFFFFF000LL) + sysconf(30) - 40;
*(_QWORD *)a2 = *(_QWORD *)(v5 + 24);
*(_QWORD *)(v5 + 24) = a2;
v6 = *(_DWORD *)(v5 + 32) - 1;
*(_DWORD *)(v5 + 32) = v6;
if ( !v6 )
{
_slab_remove(a1, v5);
free((void *)(a2 & 0xFFFFFFFFFFFFF000LL));
}
result = (unsigned int)(*(_DWORD *)(a1 + 24) - 1);
if ( *(_DWORD *)(v5 + 32) == (_DWORD)result )
result = _slab_move_to_front(a1, v5, v4);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbp
unsigned __int64 result; // rax
__int64 v4; // rdx
unsigned __int64 v5; // rbp
int v6; // eax

v2 = *(_QWORD *)(a1 + 8);
result = (unsigned __int64)sysconf(30) >> 3;
if ( v2 <= result )
{
v5 = (a2 & 0xFFFFFFFFFFFFF000LL) + sysconf(30) - 40;
*(_QWORD *)a2 = *(_QWORD *)(v5 + 24);
*(_QWORD *)(v5 + 24) = a2;
v6 = *(_DWORD *)(v5 + 32) - 1;
*(_DWORD *)(v5 + 32) = v6;
if ( !v6 )
{
_slab_remove(a1, v5);
free((void *)(a2 & 0xFFFFFFFFFFFFF000LL));
}
result = (unsigned int)(*(_DWORD *)(a1 + 24) - 1);
if ( *(_DWORD *)(v5 + 32) == (_DWORD)result )
result = _slab_move_to_front(a1, v5, v4);
}
return result;
}

original_code:
void
kmem_cache_free(kmem_cache_t cp, void *buf) {
    void * mem;
    kmem_slab_t slab;
    if (cp->size <= (size_t)sysconf(_SC_PAGESIZE)/8) {
        mem = (void*)((long)buf >> 12 << 12);
        slab = mem + (size_t)sysconf(_SC_PAGESIZE) - sizeof(struct kmem_slab);
        *((void **)buf) = slab->free_list;
        slab->free_list = buf;
        slab->bufcount--;
        if (slab->bufcount == 0) {
            __slab_remove(cp, slab);
            free(mem);
        }
        if (slab->bufcount == cp->slab_maxbuf-1)
            __slab_move_to_front(cp, slab);
    }
    else {
    }
}

canonical_original_code:
void kmem_cache_free(struct kmem_cache *cp, void *buf) {
    void *mem;
    struct kmem_slab *slab;
    if (cp->size <= (unsigned long)sysconf(_SC_PAGESIZE)/8) {
        mem = (void *)((long)buf >> 12 << 12);
        slab = mem + (unsigned long)sysconf(_SC_PAGESIZE) - sizeof(struct kmem_slab);
        *((void **)buf) = slab->free_list;
        slab->free_list = buf;
        slab->bufcount--;
        if (slab->bufcount == 0) {
            __slab_remove(cp, slab);
            free(mem);
        }
        if (slab->bufcount == cp->slab_maxbuf-1)
            __slab_move_to_front(cp, slab);
    }
    else {
    }
}

variable_types:
buf
void *


decompiled_code:
void __fastcall kmem_cache_destroy(void *ptr)
{
unsigned __int64 v1; // rbx
void ***j; // rbx
__int64 i; // rbx
__int64 v4; // rax

v1 = *((_QWORD *)ptr + 1);
if ( v1 <= (unsigned __int64)sysconf(30) >> 3 )
{
for ( i = *((_QWORD *)ptr + 6); i; i = *((_QWORD *)ptr + 6) )
{
_slab_remove(ptr, i);
v4 = sysconf(30);
free((void *)(i + 40 - v4));
}
}
else
{
for ( j = (void ***)*((_QWORD *)ptr + 6); j; j = (void ***)*((_QWORD *)ptr + 6) )
{
_slab_remove(ptr, j);
free(*j[2]);
free(j[2]);
free(j);
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
unsigned __int64 v1; // rbx
void ***j; // rbx
__int64 i; // rbx
__int64 v4; // rax

v1 = *((_QWORD *)ptr + 1);
if ( v1 <= (unsigned __int64)sysconf(30) >> 3 )
{
for ( i = *((_QWORD *)ptr + 6); i; i = *((_QWORD *)ptr + 6) )
{
_slab_remove(ptr, i);
v4 = sysconf(30);
free((void *)(i + 40 - v4));
}
}
else
{
for ( j = (void ***)*((_QWORD *)ptr + 6); j; j = (void ***)*((_QWORD *)ptr + 6) )
{
_slab_remove(ptr, j);
free(*j[2]);
free(j[2]);
free(j);
}
}
free(ptr);
}

original_code:
void
kmem_cache_destroy(kmem_cache_t cp) {
    kmem_slab_t slab;
    void * mem;
    if (cp->size <= (size_t)sysconf(_SC_PAGESIZE)/8) {
        while (cp->slabs) {
            slab = cp->slabs;
            __slab_remove(cp, slab);
            mem = (void*)slab - (size_t)sysconf(_SC_PAGESIZE) + sizeof(struct kmem_slab);
            free(mem);
        }
    }
    else {
        while (cp->slabs) {
            slab = cp->slabs;
            __slab_remove(cp, slab);
            free(slab->start->buf);
            free(slab->start);
            free(slab);
        }
    }
    free(cp);
}

canonical_original_code:
void kmem_cache_destroy(struct kmem_cache *cp) {
    struct kmem_slab *slab;
    void *mem;
    if (cp->size <= (unsigned long)sysconf(_SC_PAGESIZE)/8) {
        while (cp->slabs) {
            slab = cp->slabs;
            __slab_remove(cp, slab);
            mem = (void *)slab - (unsigned long)sysconf(_SC_PAGESIZE) + sizeof(struct kmem_slab);
            free(mem);
        }
    }
    else {
        while (cp->slabs) {
            slab = cp->slabs;
            __slab_remove(cp, slab);
            free(slab->start->buf);
            free(slab->start);
            free(slab);
        }
    }
    free(cp);
}


decompiled_code:
void __fastcall read_vars(int a1)
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( ioctl(a1, 0x80086C03uLL, v1) == -1 )
perror("ioctl Read");
else
printf("Leds set to : %x\n", (unsigned __int8)v1[0]);
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( ioctl(a1, 0x80086C03uLL, v1) == -1 )
perror("ioctl Read");
else
printf("Leds set to : %x\n", (unsigned __int8)v1[0]);
}

variable_types: fd int

variable_types: struct leds_arg_t { unsigned char leds_set; }


decompiled_code:
void __fastcall off_vars(int a1)
{
if ( ioctl(a1, 0x6C02uLL) == -1 )
perror("ioctl OFF");
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
if ( ioctl(a1, 0x6C02uLL) == -1 )
perror("ioctl OFF");
}


decompiled_code:
void __fastcall on_vars(int a1)
{
if ( ioctl(a1, 0x6C01uLL) == -1 )
perror("ioctl ON");
}

canonical_decompiled_code:
void __fastcall func9(int a1)
{
if ( ioctl(a1, 0x6C01uLL) == -1 )
perror("ioctl ON");
}


decompiled_code:
void __fastcall blink_vars(int a1)
{
if ( ioctl(a1, 0x6C00uLL) == -1 )
perror("ioctl BLINK");
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
if ( ioctl(a1, 0x6C00uLL) == -1 )
perror("ioctl BLINK");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // ebx
int v7; // eax
int v8; // eax
int v9; // eax

if ( argc != 1 )
{
if ( argc != 2 )
goto LABEL_9;
v3 = argv[1];
if ( !strcmp(v3, "-on") )
{
v8 = open("/dev/EddyLED", 2);
v5 = v8;
if ( v8 != -1 )
{
on_vars(v8);
goto LABEL_18;
}
}
else if ( !strcmp(v3, "-off") )
{
v7 = open("/dev/EddyLED", 2);
v5 = v7;
if ( v7 != -1 )
{
off_vars(v7);
goto LABEL_18;
}
}
else
{
if ( strcmp(v3, "-read") )
{
if ( !strcmp(v3, "-blink") )
goto LABEL_7;
LABEL_9:
fprintf(_bss_start, "Usage: %s [-on | -off | -read | -blink]\n", *argv);
return 1;
}
v9 = open("/dev/EddyLED", 2);
v5 = v9;
if ( v9 != -1 )
{
read_vars(v9);
goto LABEL_18;
}
}
LABEL_11:
perror("Leds open");
return 2;
}
LABEL_7:
v4 = open("/dev/EddyLED", 2, envp);
v5 = v4;
if ( v4 == -1 )
goto LABEL_11;
blink_vars(v4);
LABEL_18:
close(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // ebx
int v7; // eax
int v8; // eax
int v9; // eax

if ( argc != 1 )
{
if ( argc != 2 )
goto LABEL_9;
v3 = argv[1];
if ( !strcmp(v3, "-on") )
{
v8 = open("/dev/EddyLED", 2);
v5 = v8;
if ( v8 != -1 )
{
func9(v8);
goto LABEL_18;
}
}
else if ( !strcmp(v3, "-off") )
{
v7 = open("/dev/EddyLED", 2);
v5 = v7;
if ( v7 != -1 )
{
func8(v7);
goto LABEL_18;
}
}
else
{
if ( strcmp(v3, "-read") )
{
if ( !strcmp(v3, "-blink") )
goto LABEL_7;
LABEL_9:
fprintf(_bss_start, "Usage: %s [-on | -off | -read | -blink]\n", *argv);
return 1;
}
v9 = open("/dev/EddyLED", 2);
v5 = v9;
if ( v9 != -1 )
{
func7(v9);
goto LABEL_18;
}
}
LABEL_11:
perror("Leds open");
return 2;
}
LABEL_7:
v4 = open("/dev/EddyLED", 2, envp);
v5 = v4;
if ( v4 == -1 )
goto LABEL_11;
func10(v4);
LABEL_18:
close(v5);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    char *file_name = "/dev/EddyLED";
    int fd;
    enum
    {
        e_read,
        e_on,
        e_off,
 e_blink
    } option;
    if (argc == 1)
    {
        option = e_blink;
    }
    else if (argc == 2)
    {
        if (strcmp(argv[1], "-on") == 0)
        {
            option = e_on;
        }
        else if (strcmp(argv[1], "-off") == 0)
        {
            option = e_off;
        }
        else if (strcmp(argv[1], "-read") == 0)
        {
            option = e_read;
        }
        else if (strcmp(argv[1], "-blink") == 0)
        {
            option = e_blink;
        }
        else
        {
            fprintf(stderr, "Usage: %s [-on | -off | -read | -blink]\n", argv[0]);
            return 1;
        }
    }
    else
    {
        fprintf(stderr, "Usage: %s [-on | -off | -read | -blink]\n", argv[0]);
        return 1;
    }
    fd = open(file_name, 02);
    if (fd == -1)
    {
        perror("Leds open");
        return 2;
    }
    switch (option)
    {
        case e_read:
            read_vars(fd);
            break;
        case e_off:
            off_vars(fd);
            break;
        case e_on:
            on_vars(fd);
            break;
        case e_blink:
            blink_vars(fd);
            break;
        default:
            break;
    }
    close (fd);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *file_name = "/dev/EddyLED";
    int fd;
    enum { e_read=0, e_on=1, e_off=2, e_blink=3 } option;
    if (argc == 1)
    {
        option = e_blink;
    }
    else if (argc == 2)
    {
        if (strcmp(argv[1], "-on") == 0)
        {
            option = e_on;
        }
        else if (strcmp(argv[1], "-off") == 0)
        {
            option = e_off;
        }
        else if (strcmp(argv[1], "-read") == 0)
        {
            option = e_read;
        }
        else if (strcmp(argv[1], "-blink") == 0)
        {
            option = e_blink;
        }
        else
        {
            fprintf(stderr, "Usage: %s [-on | -off | -read | -blink]\n", argv[0]);
            return 1;
        }
    }
    else
    {
        fprintf(stderr, "Usage: %s [-on | -off | -read | -blink]\n", argv[0]);
        return 1;
    }
    fd = open(file_name, 02);
    if (fd == -1)
    {
        perror("Leds open");
        return 2;
    }
    switch (option)
    {
        case e_read:
            read_vars(fd);
            break;
        case e_off:
            off_vars(fd);
            break;
        case e_on:
            on_vars(fd);
            break;
        case e_blink:
            blink_vars(fd);
            break;
        default:
            break;
    }
    close (fd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]