main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
unsigned int v4; // ebp
int v5; // er12
int v6; // eax
int v8; // eax
double v9; // xmm0_8
double v10; // r15
double v11; // xmm0_8
double v12; // xmm0_8
__int64 v13; // r14
__int64 v14; // r15
int v15; // er12
int v16; // ebx
double v17; // xmm0_8
void *v18; // rax
void *v19; // rbp
int *v20; // rsi
double *v21; // rdx
__int64 v22; // rdi
__int64 v23; // rax
int v24; // ebx
__int64 v25; // rax
__int64 v26; // rcx
__int64 v27; // rdx
double *v28; // rax
double *v29; // r12
double v30; // r14
double v31; // xmm0_8
double *v32; // rbx
__int64 v33; // [rsp+8h] [rbp-C0h]
int v34; // [rsp+10h] [rbp-B8h]
void *v35; // [rsp+10h] [rbp-B8h]
__int16 ptr; // [rsp+18h] [rbp-B0h]
void *ptra; // [rsp+18h] [rbp-B0h]
double v38; // [rsp+20h] [rbp-A8h]
double v39; // [rsp+20h] [rbp-A8h]
double x; // [rsp+28h] [rbp-A0h]
unsigned int xa; // [rsp+28h] [rbp-A0h]
const char *v42; // [rsp+30h] [rbp-98h]
int v43; // [rsp+38h] [rbp-90h]
int v44; // [rsp+3Ch] [rbp-8Ch]
const char *v45; // [rsp+40h] [rbp-88h]
const char *v46; // [rsp+48h] [rbp-80h]
double v47; // [rsp+50h] [rbp-78h] BYREF
double v48; // [rsp+58h] [rbp-70h] BYREF
double v49; // [rsp+60h] [rbp-68h] BYREF
char v50[8]; // [rsp+68h] [rbp-60h] BYREF
double v51; // [rsp+70h] [rbp-58h] BYREF
double v52; // [rsp+78h] [rbp-50h] BYREF
void *v53; // [rsp+80h] [rbp-48h] BYREF
void *v54; // [rsp+88h] [rbp-40h] BYREF

v34 = 10;
v38 = *(double *)&LC1;
v33 = LC2;
v43 = 8;
ptr = 0;
v3 = 0LL;
v4 = 1;
v5 = 0;
while ( 2 )
{
v6 = getopt(argc, (char *const *)argv, "c:d:i:m:n:s:t:h");
if ( v6 != -1 )
{
switch ( v6 )
{
case '?':
if ( ((*_ctype_b_loc())[optopt] & 0x4000) != 0 )
fprintf(stderr, "Unknown argument '%c'\n", (unsigned int)optopt);
else
fprintf(stderr, "Unknown option character `\\x%x'.\n", (unsigned int)optopt);
exit(1);
case 'c':
v8 = atoi(optarg);
v4 = 0;
if ( v8 >= 0 )
v4 = v8;
continue;
case 'd':
*(double *)&v33 = atof(optarg);
if ( *(double *)&v33 < 1.0 )
v33 = LC0;
continue;
case 'h':
puts(kHelpMessage);
return 0;
case 'i':
v3 = optarg;
ptr = 1;
continue;
case 'm':
v38 = atof(optarg);
continue;
case 'n':
v34 = atoi(optarg);
continue;
case 's':
v43 = atoi(optarg);
x = (double)v43;
v9 = log2((double)v43);
v10 = v9;
if ( COERCE_DOUBLE(*(_QWORD *)&v9 & LC4) < 4.503599627370496e15 )
*(_QWORD *)&v10 = COERCE_UNSIGNED_INT64((double)(int)v9) | ~LC4 & *(_QWORD *)&v9;
if ( v10 - log2(x) > 1.0e-16 )
{
v11 = log2(x);
v12 = trunc(v11);
v43 = (int)gsl_pow_int((unsigned int)(int)v12, 2.0);
}
continue;
case 't':
v5 = atoi(optarg);
if ( v5 < 0 )
v5 = 1;
continue;
default:
abort();
}
}
break;
}
if ( argc - optind <= 5 )
{
fwrite("Not enough arguments\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v13 = optind;
v45 = argv[v13];
xa = atoi(argv[v13 + 1]);
v14 = (unsigned int)atoi(argv[v13 + 2]);
v42 = argv[v13 + 3];
v44 = atoi(argv[v13 + 4]);
v46 = argv[v13 + 5];
if ( !ptr )
v3 = (char *)v42;
ptra = malloc(8LL * (int)(v14 * xa));
checkPtr(ptra, "out of memory");
readToDoubleMatrix(v45, xa, (unsigned int)v14, ptra);
v54 = malloc(8LL * v44);
if ( !v54 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v15 = readToDoubleVectorDynamic(v42, (unsigned int)v44, (unsigned int)v5, &v54);
v53 = malloc(8LL * v44);
if ( !v53 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v16 = readToDoubleVectorDynamic(v42, (unsigned int)v44, v4, &v53);
v17 = *(double *)v53;
if ( v15 != v16 )
{
fwrite("Error -- differing number of entries ", 1uLL, 0x25uLL, stderr);
fwrite("in time and data columns\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v18 = malloc(8LL * ((int)v14 - 1));
v19 = v18;
if ( !v18 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
readToDoubleVector(v46, (unsigned int)(v14 - 1), 0LL, v18, v17);
v20 = (int *)calloc(4uLL, v16);
if ( v16 <= 0 )
{
if ( v34 <= 0 )
{
v24 = 0;
goto LABEL_48;
}
v24 = 0;
LABEL_55:
fprintf(stderr, "Error -- read %d obs, minimum to process is %d\n", (unsigned int)v24, (unsigned int)v34);
exit(1);
}
v21 = (double *)v53;
v22 = (unsigned int)(v16 - 1);
v23 = 0LL;
v24 = 0;
while ( 1 )
{
if ( v38 != v21[v23] )
v20[v24++] = v23;
if ( v23 == v22 )
break;
++v23;
}
if ( v34 > v24 )
goto LABEL_55;
if ( v24 > 0 )
{
v25 = 0LL;
do
{
v26 = v20[v25];
*((_QWORD *)v53 + v25) = *((_QWORD *)v53 + v26);
*((_QWORD *)v54 + v25) = *((_QWORD *)v54 + v26);
v27 = v25++;
}
while ( v27 != v24 - 1 );
}
LABEL_48:
v35 = malloc(8LL * v43);
if ( !v35 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v28 = (double *)malloc(8LL * ((int)v14 - 1) + 8);
v29 = v28;
if ( !v28 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
lmT(
ptra,
xa,
(unsigned int)v14,
v53,
(unsigned int)v24,
v54,
*(double *)&v33,
0.000000001,
v19,
v14,
1000LL,
&v49,
&v48,
v28,
&v47);
lmT(
ptra,
xa,
(unsigned int)v14,
v53,
(unsigned int)v24,
v54,
*(double *)&v33,
0.000000001,
v19,
(unsigned int)v43,
1000LL,
&v52,
&v51,
v35,
v50);
v39 = v48 - v51;
v30 = v49 - v52;
fprintf(stdout, "%s %d %d %d %g ", v3, (unsigned int)v24, (unsigned int)v14, (unsigned int)v43, *(double *)&v33);
fprintf(stdout, "%g %g ", v39 + v39, v30);
v31 = sqrt(v47);
fprintf(stdout, "%g ", v31);
if ( (int)v14 > 0 )
{
v32 = v29;
do
fprintf(stdout, "%g ", *v32++);
while ( v32 != &v29[(unsigned int)v14] );
}
fputc(10, stdout);
free(ptra);
free(v54);
free(v53);
free(v35);
free(v29);
free(v19);
return 0;
}

original_code:
int main(int argc, char * argv[]) {
  const int nArgs = 6;
  int c, timeCol=0, valueCol=1;
  extern char *optarg;
  char * dataFile, * basisFile, * priorFile, * idString=((void *)0);
  short readID = 0;
  int kSmooth = 8;
  int maxIter = 1e3;
  double nu=5;
  double tol=1e-9;
  double missingCode = 99.999;
  int minObs = 10;
  int basisRows, basisCols, dataRows;
  int i;
  while ( (c=getopt(argc, argv, "c:d:i:m:n:s:t:h")) != -1 ) {
    switch(c) {
      case 'h':
        puts(kHelpMessage);
        return 0;
      case 'c':
        valueCol = atoi(optarg);
        valueCol = (valueCol < 0) ? 0 : valueCol;
        break;
      case 'd':
        nu = atof(optarg);
        nu = (nu < 1) ? 1 : nu;
        break;
      case 'i':
        idString = optarg;
        readID = 1;
        break;
      case 'm':
        missingCode = atof(optarg);
        break;
      case 'n':
        minObs = atoi(optarg);
        break;
      case 's':
        kSmooth = atoi(optarg);
        kSmooth = (trunc(log2(kSmooth))-log2(kSmooth) > 1e-16) ?
          (int) gsl_pow_int(2, trunc(log2(kSmooth))) : kSmooth;
        break;
      case 't':
        timeCol = atoi(optarg);
        timeCol = (timeCol < 0) ? 1 : timeCol;
        break;
      case '?':
        if ( ((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint) )
          fprintf(stderr, "Unknown argument '%c'\n", optopt);
        else
          fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
        exit(1);
        break;
      default:
        abort();
    }
  }
  if (argc-optind < nArgs) {
    fprintf(stderr, "Not enough arguments\n");
    exit(1);
  }
  basisFile = argv[optind];
  basisRows = atoi( argv[optind+1] );
  basisCols = atoi( argv[optind+2] );
  dataFile = argv[optind+3];
  dataRows = atoi( argv[optind+4] );
  priorFile = argv[optind + 5];
  if (readID == 0)
  {
    idString = dataFile;
  }
  double* basisMat;
  basisMat = malloc(basisCols * basisRows * sizeof(double));
  checkPtr(basisMat, "out of memory");
  readToDoubleMatrix(basisFile, basisRows, basisCols, basisMat);
  double* timeVec;
  timeVec = malloc(dataRows * sizeof(double));
  if (timeVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int timesRead = readToDoubleVectorDynamic(dataFile, dataRows,
      timeCol, &timeVec);
  if (__builtin_isnan (timeVec[0]))
  {
    fprintf(stderr, "Error -- NaN at first time; aborting\n");
    exit(1);
  }
  double* yVec;
  yVec = malloc(dataRows * sizeof(double));
  if (yVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int obsRead = readToDoubleVectorDynamic(dataFile, dataRows,
      valueCol, &yVec);
  if (__builtin_isnan (yVec[0]))
  {
    fprintf(stderr, "Error -- NaN at first observation; aborting\n");
    exit(1);
  }
  if (timesRead != obsRead)
  {
    fprintf(stderr, "Error -- differing number of entries ");
    fprintf(stderr, "in time and data columns\n");
    exit(1);
  }
  double * priorVec;
  priorVec = malloc( (basisCols-1) * sizeof(double));
  if (priorVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  readToDoubleVector(priorFile, basisCols-1, 0, priorVec);
  int nObs = 0;
  int * validInd;
  validInd = calloc(sizeof(int), obsRead);
  for (i=0; i<obsRead; i++)
  {
    if (yVec[i] != missingCode)
    {
      validInd[nObs]=i;
      nObs++;
    }
  }
  if (nObs < minObs)
  {
    fprintf(stderr, "Error -- read %d obs, minimum to process is %d\n",
        nObs, minObs);
    exit(1);
  }
  for (i=0; i<nObs; i++)
  {
    yVec[i] = yVec[validInd[i]];
    timeVec[i] = timeVec[validInd[i]];
  }
  double logPosterior_l, logLikelihood_l, tau_l;
  double logPosterior_m, logLikelihood_m, tau_m;
  double * coef_l, * coef_m;
  coef_l = malloc(kSmooth * sizeof(double));
  if (coef_l==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  coef_m = malloc(basisCols * sizeof(double));
  if (coef_m==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int iter_m;
  iter_m = lmT(basisMat, basisRows, basisCols,
      yVec, nObs,
      timeVec,
      priorVec,
      nu, basisCols,
      maxIter, tol,
      &logPosterior_m,
      &logLikelihood_m,
      coef_m,
      &tau_m);
  int iter_l;
  iter_l = lmT(basisMat, basisRows, basisCols,
      yVec, nObs,
      timeVec,
      priorVec,
      nu, kSmooth,
      maxIter, tol,
      &logPosterior_l,
      &logLikelihood_l,
      coef_l,
      &tau_l);
  double llr, lpr;
  llr = logLikelihood_m - logLikelihood_l;
  llr *= 2;
  lpr = logPosterior_m - logPosterior_l;
  fprintf(stdout, "%s %d %d %d %g ", idString, nObs, basisCols, kSmooth, nu);
  fprintf(stdout, "%g %g ", llr, lpr);
  fprintf(stdout, "%g ", sqrt(tau_m));
  for (i=0; i<basisCols; i++) fprintf(stdout, "%g ", coef_m[i]);
  fprintf(stdout, "\n");
  free(basisMat);
  basisMat = ((void *)0);
  free(timeVec);
  timeVec=((void *)0);
  free(yVec);
  yVec=((void *)0);
  free(coef_l);
  coef_l=((void *)0);
  free(coef_m);
  coef_m=((void *)0);
  free(priorVec);
  priorVec=((void *)0);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int nArgs = 6;
  int c; int timeCol = 0; int valueCol = 1;
  extern char *optarg;
  char *dataFile; char *basisFile; char *priorFile; char *idString = ((void *)0);
  short readID = 0;
  int kSmooth = 8;
  int maxIter = 1e3;
  double nu = 5;
  double tol = 1e-9;
  double missingCode = 99.999;
  int minObs = 10;
  int basisRows; int basisCols; int dataRows;
  int i;
  while ( (c=getopt(argc, argv, "c:d:i:m:n:s:t:h")) != -1 ) {
    switch(c) {
      case 'h':
        puts(kHelpMessage);
        return 0;
      case 'c':
        valueCol = atoi(optarg);
        valueCol = (valueCol < 0) ? 0 : valueCol;
        break;
      case 'd':
        nu = atof(optarg);
        nu = (nu < 1) ? 1 : nu;
        break;
      case 'i':
        idString = optarg;
        readID = 1;
        break;
      case 'm':
        missingCode = atof(optarg);
        break;
      case 'n':
        minObs = atoi(optarg);
        break;
      case 's':
        kSmooth = atoi(optarg);
        kSmooth = (trunc(log2(kSmooth))-log2(kSmooth) > 1e-16) ?
          (int) gsl_pow_int(2, trunc(log2(kSmooth))) : kSmooth;
        break;
      case 't':
        timeCol = atoi(optarg);
        timeCol = (timeCol < 0) ? 1 : timeCol;
        break;
      case '?':
        if ( ((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint) )
          fprintf(stderr, "Unknown argument '%c'\n", optopt);
        else
          fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
        exit(1);
        break;
      default:
        abort();
    }
  }
  if (argc-optind < nArgs) {
    fprintf(stderr, "Not enough arguments\n");
    exit(1);
  }
  basisFile = argv[optind];
  basisRows = atoi( argv[optind+1] );
  basisCols = atoi( argv[optind+2] );
  dataFile = argv[optind+3];
  dataRows = atoi( argv[optind+4] );
  priorFile = argv[optind + 5];
  if (readID == 0)
  {
    idString = dataFile;
  }
  double *basisMat;
  basisMat = malloc(basisCols * basisRows * sizeof(double));
  checkPtr(basisMat, "out of memory");
  readToDoubleMatrix(basisFile, basisRows, basisCols, basisMat);
  double *timeVec;
  timeVec = malloc(dataRows * sizeof(double));
  if (timeVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int timesRead = readToDoubleVectorDynamic(dataFile, dataRows,
      timeCol, &timeVec);
  if (__builtin_isnan (timeVec[0]))
  {
    fprintf(stderr, "Error -- NaN at first time; aborting\n");
    exit(1);
  }
  double *yVec;
  yVec = malloc(dataRows * sizeof(double));
  if (yVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int obsRead = readToDoubleVectorDynamic(dataFile, dataRows,
      valueCol, &yVec);
  if (__builtin_isnan (yVec[0]))
  {
    fprintf(stderr, "Error -- NaN at first observation; aborting\n");
    exit(1);
  }
  if (timesRead != obsRead)
  {
    fprintf(stderr, "Error -- differing number of entries ");
    fprintf(stderr, "in time and data columns\n");
    exit(1);
  }
  double *priorVec;
  priorVec = malloc( (basisCols-1) * sizeof(double));
  if (priorVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  readToDoubleVector(priorFile, basisCols-1, 0, priorVec);
  int nObs = 0;
  int *validInd;
  validInd = calloc(sizeof(int), obsRead);
  for (i=0; i<obsRead; i++)
  {
    if (yVec[i] != missingCode)
    {
      validInd[nObs]=i;
      nObs++;
    }
  }
  if (nObs < minObs)
  {
    fprintf(stderr, "Error -- read %d obs, minimum to process is %d\n",
        nObs, minObs);
    exit(1);
  }
  for (i=0; i<nObs; i++)
  {
    yVec[i] = yVec[validInd[i]];
    timeVec[i] = timeVec[validInd[i]];
  }
  double logPosterior_l; double logLikelihood_l; double tau_l;
  double logPosterior_m; double logLikelihood_m; double tau_m;
  double *coef_l; double *coef_m;
  coef_l = malloc(kSmooth * sizeof(double));
  if (coef_l==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  coef_m = malloc(basisCols * sizeof(double));
  if (coef_m==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int iter_m;
  iter_m = lmT(basisMat, basisRows, basisCols,
      yVec, nObs,
      timeVec,
      priorVec,
      nu, basisCols,
      maxIter, tol,
      &logPosterior_m,
      &logLikelihood_m,
      coef_m,
      &tau_m);
  int iter_l;
  iter_l = lmT(basisMat, basisRows, basisCols,
      yVec, nObs,
      timeVec,
      priorVec,
      nu, kSmooth,
      maxIter, tol,
      &logPosterior_l,
      &logLikelihood_l,
      coef_l,
      &tau_l);
  double llr; double lpr;
  llr = logLikelihood_m - logLikelihood_l;
  llr *= 2;
  lpr = logPosterior_m - logPosterior_l;
  fprintf(stdout, "%s %d %d %d %g ", idString, nObs, basisCols, kSmooth, nu);
  fprintf(stdout, "%g %g ", llr, lpr);
  fprintf(stdout, "%g ", sqrt(tau_m));
  for (i=0; i<basisCols; i++) fprintf(stdout, "%g ", coef_m[i]);
  fprintf(stdout, "\n");
  free(basisMat);
  basisMat = ((void *)0);
  free(timeVec);
  timeVec=((void *)0);
  free(yVec);
  yVec=((void *)0);
  free(coef_l);
  coef_l=((void *)0);
  free(coef_m);
  coef_m=((void *)0);
  free(priorVec);
  priorVec=((void *)0);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nArgs int

variable_types: c int

variable_types: timeCol int

variable_types: valueCol int

variable_types:
optarg
char *

variable_types:
dataFile
char *

variable_types:
basisFile
char *

variable_types:
priorFile
char *

variable_types:
idString
char *

variable_types: readID short

variable_types: kSmooth int

variable_types: maxIter int

variable_types: nu double

variable_types: tol double

variable_types: missingCode double

variable_types: minObs int

variable_types: basisRows int

variable_types: basisCols int

variable_types: dataRows int

variable_types:
basisMat
double *

variable_types:
timeVec
double *

variable_types: timesRead int

variable_types:
yVec
double *

variable_types: obsRead int

variable_types:
priorVec
double *

variable_types: nObs int

variable_types:
validInd
int *

variable_types: llr double

variable_types: lpr double


dscal

repo: awblocker/rowavedt

decompiled_code:
__int64 __fastcall dscal(int a1, __int64 a2, int a3, double a4)
{
double v5; // [rsp+0h] [rbp-18h] BYREF
int v6; // [rsp+8h] [rbp-10h] BYREF
int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v7[0] = a1;
v5 = a4;
v6 = a3;
return dscal_(v7, &v5, a2, &v6);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3, double a4)
{
double v5; // [rsp+0h] [rbp-18h] BYREF
int v6; // [rsp+8h] [rbp-10h] BYREF
int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v7[0] = a1;
v5 = a4;
v6 = a3;
return dscal_(v7, &v5, a2, &v6);
}

original_code:
void dscal(int N, double ALPHA, double * X, int INCX)
{
  dscal_(&N, &ALPHA, X, &INCX);
}

canonical_original_code:
void dscal(int N, double ALPHA, double *X, int INCX)
{
  dscal_(&N, &ALPHA, X, &INCX);
}

variable_types: N int

variable_types: ALPHA double

variable_types:
X
double *

variable_types: INCX int

return_type: void


dasum

decompiled_code:
__int64 __fastcall dasum(int a1, __int64 a2, int a3)
{
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a1;
v4 = a3;
return dasum_(v5, a2, &v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, int a3)
{
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a1;
v4 = a3;
return dasum_(v5, a2, &v4);
}

original_code:
double dasum(int N, double * X, int INCX)
{
  return dasum_(&N, X, &INCX);
}

canonical_original_code:
double dasum(int N, double *X, int INCX)
{
  return dasum_(&N, X, &INCX);
}

return_type: double


dcopy

decompiled_code:
__int64 __fastcall dcopy(int a1, __int64 a2, int a3, __int64 a4, int a5)
{
int v6; // [rsp+4h] [rbp-14h] BYREF
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8[0] = a1;
v7 = a3;
v6 = a5;
return dcopy_(v8, a2, &v7, a4, &v6);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2, int a3, __int64 a4, int a5)
{
int v6; // [rsp+4h] [rbp-14h] BYREF
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8[0] = a1;
v7 = a3;
v6 = a5;
return dcopy_(v8, a2, &v7, a4, &v6);
}

original_code:
void dcopy(int N, double * X, int INCX, double * Y, int INCY)
{
  dcopy_(&N, X, &INCX, Y, &INCY);
}

canonical_original_code:
void dcopy(int N, double *X, int INCX, double *Y, int INCY)
{
  dcopy_(&N, X, &INCX, Y, &INCY);
}

variable_types:
Y
double *

variable_types: INCY int


daxpy

decompiled_code:
__int64 __fastcall daxpy(int a1, __int64 a2, int a3, __int64 a4, int a5, double a6)
{
int v7; // [rsp+Ch] [rbp-1Ch] BYREF
double v8; // [rsp+10h] [rbp-18h] BYREF
int v9; // [rsp+18h] [rbp-10h] BYREF
int v10[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v10[0] = a1;
v8 = a6;
v9 = a3;
v7 = a5;
return daxpy_(v10, &v8, a2, &v9, a4, &v7);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2, int a3, __int64 a4, int a5, double a6)
{
int v7; // [rsp+Ch] [rbp-1Ch] BYREF
double v8; // [rsp+10h] [rbp-18h] BYREF
int v9; // [rsp+18h] [rbp-10h] BYREF
int v10[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v10[0] = a1;
v8 = a6;
v9 = a3;
v7 = a5;
return daxpy_(v10, &v8, a2, &v9, a4, &v7);
}

original_code:
void daxpy(int N, double ALPHA, double * X, int INCX, double * Y, int INCY)
{
  daxpy_(&N, &ALPHA, X, &INCX, Y, &INCY);
}

canonical_original_code:
void daxpy(int N, double ALPHA, double *X, int INCX, double *Y, int INCY)
{
  daxpy_(&N, &ALPHA, X, &INCX, Y, &INCY);
}


dgemv

decompiled_code:
__int64 __fastcall dgemv(char a1, int a2, int a3, __int64 a4, int a5, __int64 a6, double a7, double a8, char a9, __int64 a10, char a11)
{
double v12; // [rsp+8h] [rbp-28h] BYREF
double v13; // [rsp+10h] [rbp-20h] BYREF
int v14; // [rsp+18h] [rbp-18h] BYREF
int v15; // [rsp+1Ch] [rbp-14h] BYREF
int v16; // [rsp+20h] [rbp-10h] BYREF
char v17[12]; // [rsp+24h] [rbp-Ch] BYREF

v16 = a2;
v15 = a3;
v13 = a7;
v14 = a5;
v12 = a8;
v17[0] = a1;
return dgemv_(v17, &v16, &v15, &v13, a4, &v14, a6, &a9, &v12, a10, &a11);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, int a2, int a3, __int64 a4, int a5, __int64 a6, double a7, double a8, char a9, __int64 a10, char a11)
{
double v12; // [rsp+8h] [rbp-28h] BYREF
double v13; // [rsp+10h] [rbp-20h] BYREF
int v14; // [rsp+18h] [rbp-18h] BYREF
int v15; // [rsp+1Ch] [rbp-14h] BYREF
int v16; // [rsp+20h] [rbp-10h] BYREF
char v17[12]; // [rsp+24h] [rbp-Ch] BYREF

v16 = a2;
v15 = a3;
v13 = a7;
v14 = a5;
v12 = a8;
v17[0] = a1;
return dgemv_(v17, &v16, &v15, &v13, a4, &v14, a6, &a9, &v12, a10, &a11);
}

original_code:
void dgemv(char TRANS, int M, int N, double ALPHA, double * A, int LDA,
    double * X, int INCX, double BETA, double * Y, int INCY)
{
  dgemv_(&TRANS, &M, &N, &ALPHA, A, &LDA, X, &INCX, &BETA, Y, &INCY);
}

canonical_original_code:
void dgemv(char TRANS, int M, int N, double ALPHA, double *A, int LDA, double *X, int INCX, double BETA, double *Y, int INCY)
{
  dgemv_(&TRANS, &M, &N, &ALPHA, A, &LDA, X, &INCX, &BETA, Y, &INCY);
}

variable_types: TRANS char

variable_types: M int

variable_types:
A
double *

variable_types: LDA int

variable_types: BETA double


dsyrk

decompiled_code:
__int64 __fastcall dsyrk(char a1, char a2, int a3, int a4, __int64 a5, int a6, double a7, double a8, __int64 a9, char a10)
{
double v11; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+14h] [rbp-24h] BYREF
double v13; // [rsp+18h] [rbp-20h] BYREF
int v14; // [rsp+20h] [rbp-18h] BYREF
int v15; // [rsp+24h] [rbp-14h] BYREF
char v16[4]; // [rsp+28h] [rbp-10h] BYREF
char v17[12]; // [rsp+2Ch] [rbp-Ch] BYREF

v15 = a3;
v14 = a4;
v13 = a7;
v12 = a6;
v11 = a8;
v17[0] = a1;
v16[0] = a2;
return dsyrk_(v17, v16, &v15, &v14, &v13, a5, &v12, &v11, a9, &a10);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, char a2, int a3, int a4, __int64 a5, int a6, double a7, double a8, __int64 a9, char a10)
{
double v11; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+14h] [rbp-24h] BYREF
double v13; // [rsp+18h] [rbp-20h] BYREF
int v14; // [rsp+20h] [rbp-18h] BYREF
int v15; // [rsp+24h] [rbp-14h] BYREF
char v16[4]; // [rsp+28h] [rbp-10h] BYREF
char v17[12]; // [rsp+2Ch] [rbp-Ch] BYREF

v15 = a3;
v14 = a4;
v13 = a7;
v12 = a6;
v11 = a8;
v17[0] = a1;
v16[0] = a2;
return dsyrk_(v17, v16, &v15, &v14, &v13, a5, &v12, &v11, a9, &a10);
}

original_code:
void dsyrk(char UPLO, char TRANS, int N, int K, double ALPHA,
    double* A, int LDA, double BETA, double* C, int LDC)
{
  dsyrk_(&UPLO, &TRANS, &N, &K, &ALPHA, A, &LDA, &BETA, C, &LDC);
}

canonical_original_code:
void dsyrk(char UPLO, char TRANS, int N, int K, double ALPHA, double *A, int LDA, double BETA, double *C, int LDC)
{
  dsyrk_(&UPLO, &TRANS, &N, &K, &ALPHA, A, &LDA, &BETA, C, &LDC);
}

variable_types: UPLO char

variable_types: K int

variable_types:
C
double *

variable_types: LDC int


dposv

decompiled_code:
__int64 __fastcall dposv(char a1, int a2, int a3, __int64 a4, int a5)
{
int v6; // [rsp+0h] [rbp-28h] BYREF
int v7; // [rsp+4h] [rbp-24h] BYREF
int v8; // [rsp+8h] [rbp-20h] BYREF
char v9[16]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v10; // [rsp+1Ch] [rbp-Ch]

v8 = a2;
v7 = a3;
v6 = a5;
v9[0] = a1;
dposv_(v9, &v8, &v7, a4, &v6);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, int a2, int a3, __int64 a4, int a5)
{
int v6; // [rsp+0h] [rbp-28h] BYREF
int v7; // [rsp+4h] [rbp-24h] BYREF
int v8; // [rsp+8h] [rbp-20h] BYREF
char v9[16]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v10; // [rsp+1Ch] [rbp-Ch]

v8 = a2;
v7 = a3;
v6 = a5;
v9[0] = a1;
dposv_(v9, &v8, &v7, a4, &v6);
return v10;
}

original_code:
int dposv(char UPLO, int N, int NRHS, double * A, int LDA,
    double * B, int LDB)
{
  int INFO;
  dposv_(&UPLO, &N, &NRHS, A, &LDA, B, &LDB, &INFO);
  return INFO;
}

canonical_original_code:
int dposv(char UPLO, int N, int NRHS, double *A, int LDA, double *B, int LDB)
{
  int INFO;
  dposv_(&UPLO, &N, &NRHS, A, &LDA, B, &LDB, &INFO);
  return INFO;
}

variable_types: NRHS int

variable_types:
B
double *

variable_types: LDB int

variable_types: INFO int

return_type: int


dgels

decompiled_code:
__int64 __fastcall dgels(char a1, int a2, int a3, unsigned int a4, __int64 a5, int a6, __int64 a7, char a8)
{
void *v9; // rax
int v11; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v12; // [rsp+10h] [rbp-38h] BYREF
int v13; // [rsp+14h] [rbp-34h] BYREF
int v14; // [rsp+18h] [rbp-30h] BYREF
char v15[12]; // [rsp+1Ch] [rbp-2Ch] BYREF
unsigned int v16; // [rsp+28h] [rbp-20h] BYREF
unsigned int v17[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v14 = a2;
v13 = a3;
v12 = a4;
v11 = a6;
v15[0] = a1;
v17[0] = a2 * a3 + ((unsigned int)max((unsigned int)(a2 * a3), a4) << 10);
v9 = malloc(8LL * (int)v17[0]);
if ( !v9 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
dgels_(v15, &v14, &v13, &v12, a5, &v11, a7, &a8, v9, v17, &v16);
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, int a2, int a3, unsigned int a4, __int64 a5, int a6, __int64 a7, char a8)
{
void *v9; // rax
int v11; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v12; // [rsp+10h] [rbp-38h] BYREF
int v13; // [rsp+14h] [rbp-34h] BYREF
int v14; // [rsp+18h] [rbp-30h] BYREF
char v15[12]; // [rsp+1Ch] [rbp-2Ch] BYREF
unsigned int v16; // [rsp+28h] [rbp-20h] BYREF
unsigned int v17[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v14 = a2;
v13 = a3;
v12 = a4;
v11 = a6;
v15[0] = a1;
v17[0] = a2 * a3 + ((unsigned int)max((unsigned int)(a2 * a3), a4) << 10);
v9 = malloc(8LL * (int)v17[0]);
if ( !v9 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
dgels_(v15, &v14, &v13, &v12, a5, &v11, a7, &a8, v9, v17, &v16);
return v16;
}

original_code:
int dgels(char TRANS, int M, int N, int NRHS, double * A, int LDA,
    double * B, int LDB)
{
  const int NB=1024;
  int LWORK;
  LWORK = M*N + max(M*N, NRHS)*NB;
  double * WORK;
  WORK = malloc(LWORK * sizeof(double));
  if (WORK==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int INFO;
  dgels_(&TRANS, &M, &N, &NRHS, A, &LDA, B, &LDB, WORK, &LWORK, &INFO);
  return INFO;
}

canonical_original_code:
int dgels(char TRANS, int M, int N, int NRHS, double *A, int LDA, double *B, int LDB)
{
  int NB = 1024;
  int LWORK;
  LWORK = M*N + max(M*N, NRHS)*NB;
  double *WORK;
  WORK = malloc(LWORK * sizeof(double));
  if (WORK==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int INFO;
  dgels_(&TRANS, &M, &N, &NRHS, A, &LDA, B, &LDB, WORK, &LWORK, &INFO);
  return INFO;
}

variable_types: N int

variable_types: NB int

variable_types: LWORK int

variable_types:
WORK
double *


wls

original_code:
int wls(double* X, int n, int k,
    double* y, double* w,
    double* XTX, double *sqw, double* sqwX, double* sqwy,
    double* coef) {
  int i, j;
  for (i=0; i<n; i++)
  {
    sqw[i] = sqrt(w[i]);
    for (j=0; j<k; j++) {
      sqwX[i + j*n] = X[i + j*n] * sqw[i];
    }
    sqwy[i] = sqw[i] * y[i];
  }
  dsyrk('u', 't', k, n, 1, sqwX, n, 0, XTX, k);
  dgemv('t', n, k, 1, sqwX, n, sqwy, 1, 0, coef, 1);
  int info;
  info = dposv('u', k, 1, XTX, k, coef, k);
  return info;
}

canonical_original_code:
int wls(double *X, int n, int k, double *y, double *w, double *XTX, double *sqw, double *sqwX, double *sqwy, double *coef) {
  int i; int j;
  for (i=0; i<n; i++)
  {
    sqw[i] = sqrt(w[i]);
    for (j=0; j<k; j++) {
      sqwX[i + j*n] = X[i + j*n] * sqw[i];
    }
    sqwy[i] = sqw[i] * y[i];
  }
  dsyrk('u', 't', k, n, 1, sqwX, n, 0, XTX, k);
  dgemv('t', n, k, 1, sqwX, n, sqwy, 1, 0, coef, 1);
  int info;
  info = dposv('u', k, 1, XTX, k, coef, k);
  return info;
}

variable_types:
X
double *

variable_types: n int

variable_types: k int

variable_types:
y
double *

variable_types:
w
double *

variable_types:
XTX
double *

variable_types:
sqw
double *

variable_types:
sqwX
double *

variable_types:
sqwy
double *

variable_types:
coef
double *

variable_types: i int

variable_types: j int

variable_types: info int


calcFitted

decompiled_code:
__int64 __fastcall calcFitted(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
dgemv(110LL, a2, a3, a1, (unsigned int)a2, a5, 1.0, 0.0, 1LL, a6, 1);
return 0LL;
}

original_code:
int calcFitted(double* X, int n, int k,
    double* y,
    double* coef,
    double* fitted)
{
  dgemv('n', n, k, 1, X, n, coef, 1, 0, fitted, 1);
  return 0;
}

canonical_original_code:
int calcFitted(double *X, int n, int k, double *y, double *coef, double *fitted)
{
  dgemv('n', n, k, 1, X, n, coef, 1, 0, fitted, 1);
  return 0;
}

variable_types:
fitted
double *


calcResid

decompiled_code:
__int64 __fastcall calcResid(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
dgemv(110LL, a2, a3, a1, (unsigned int)a2, a5, 1.0, 0.0, 1LL, a6, 1);
dscal((unsigned int)a2, a6, 1LL, -1.0);
daxpy((unsigned int)a2, a4, 1LL, a6, 1LL, 1.0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
dgemv(110LL, a2, a3, a1, (unsigned int)a2, a5, 1.0, 0.0, 1LL, a6, 1);
dscal((unsigned int)a2, a6, 1LL, -1.0);
daxpy((unsigned int)a2, a4, 1LL, a6, 1LL, 1.0);
return 0LL;
}

original_code:
int calcResid(double* X, int n, int k,
    double* y,
    double* coef,
    double* resid)
{
  dgemv('n', n, k, 1, X, n, coef, 1, 0, resid, 1);
  dscal(n, -1, resid, 1);
  daxpy(n, 1, y, 1, resid, 1);
  return 0;
}

canonical_original_code:
int calcResid(double *X, int n, int k, double *y, double *coef, double *resid)
{
  dgemv('n', n, k, 1, X, n, coef, 1, 0, resid, 1);
  dscal(n, -1, resid, 1);
  daxpy(n, 1, y, 1, resid, 1);
  return 0;
}

variable_types:
resid
double *


decompiled_code:
double __fastcall dt_log(double *a1, int a2, double a3, double a4, double a5)
{
double *v5; // rbx
double v7; // [rsp+0h] [rbp-48h]
double v9; // [rsp+10h] [rbp-38h]

v9 = log(a5);
if ( a2 <= 0 )
return 0.0;
v5 = a1;
v7 = 0.0;
do
{
v7 = log((*v5 - a4) / a5 * ((*v5 - a4) / a5) / a3 + 1.0)
* (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a3 + 1.0) ^ LC3)
* 0.5)
- v9
+ v7;
++v5;
}
while ( v5 != &a1[(unsigned int)(a2 - 1) + 1] );
return v7;
}

canonical_decompiled_code:
double __fastcall func0(double *a1, int a2, double a3, double a4, double a5)
{
double *v5; // rbx
double v7; // [rsp+0h] [rbp-48h]
double v9; // [rsp+10h] [rbp-38h]

v9 = log(a5);
if ( a2 <= 0 )
return 0.0;
v5 = a1;
v7 = 0.0;
do
{
v7 = log((*v5 - a4) / a5 * ((*v5 - a4) / a5) / a3 + 1.0)
* (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a3 + 1.0) ^ LC3)
* 0.5)
- v9
+ v7;
++v5;
}
while ( v5 != &a1[(unsigned int)(a2 - 1) + 1] );
return v7;
}

original_code:
double dt_log(double * x, int n, double df, double location, double scale)
{
  int i;
  double logDensity = 0, z, logScale;
  logScale = log(scale);
  for (i=0; i<n; i++)
  {
    z = (x[i] - location) / scale;
    logDensity += -(df+1)/2 * log(1 + z*z/df) - logScale;
  }
  return logDensity;
}

canonical_original_code:
double dt_log(double *x, int n, double df, double location, double scale)
{
  int i;
  double logDensity = 0; double z; double logScale;
  logScale = log(scale);
  for (i=0; i<n; i++)
  {
    z = (x[i] - location) / scale;
    logDensity += -(df+1)/2 * log(1 + z*z/df) - logScale;
  }
  return logDensity;
}

variable_types:
x
double *

variable_types: df double

variable_types: location double

variable_types: scale double

variable_types: logDensity double

variable_types: z double

variable_types: logScale double


lmT

decompiled_code:
__int64 __fastcall lmT(__int64 a1, int a2, double a3, double a4, __int64 a5, __int64 a6, int a7, double *a8, double *a9, unsigned int a10, int a11, double *a12, double *a13, __int64 a14, double *a15)
{
int v15; // er15
int v17; // er14
double v18; // xmm2_8
double v19; // xmm1_8
double *v20; // rax
__int64 v21; // rsi
__int64 v22; // r8
_QWORD *v23; // rcx
char *v24; // rdx
int i; // eax
__m128d v26; // xmm0
double v27; // xmm2_8
__m128d v28; // xmm2
char *v29; // rdx
int v30; // eax
_QWORD *v31; // rbx
double *v32; // rbp
_QWORD *v33; // rax
__int64 v34; // r15
__int64 v35; // rax
double v36; // xmm1_8
__int64 v37; // rdx
double v38; // xmm2_8
double v39; // xmm2_8
double v40; // xmm1_8
double v41; // xmm1_8
unsigned int v42; // er15
double v43; // xmm3_8
__int64 v44; // rax
__int64 v45; // rax
double v46; // xmm1_8
__int64 v47; // rdx
double v48; // xmm2_8
double v49; // xmm2_8
double v50; // xmm1_8
double v51; // xmm1_8
double v52; // xmm2_8
char *ptr; // [rsp+10h] [rbp-98h]
void *v57; // [rsp+18h] [rbp-90h]
double v58; // [rsp+20h] [rbp-88h]
void *v59; // [rsp+28h] [rbp-80h]
void *v61; // [rsp+30h] [rbp-78h]
void *v62; // [rsp+38h] [rbp-70h]
void *v63; // [rsp+40h] [rbp-68h]
unsigned int v64; // [rsp+48h] [rbp-60h]
signed int v65; // [rsp+4Ch] [rbp-5Ch]
double *v66; // [rsp+50h] [rbp-58h]
double v68; // [rsp+60h] [rbp-48h] BYREF
double v69[8]; // [rsp+68h] [rbp-40h] BYREF

v15 = a7;
v65 = a7 + a10;
v17 = a7 + a10 - 1;
arrayMinMax(a8, (unsigned int)a7, v69, &v68);
if ( v15 > 0 )
{
v18 = v69[0];
v19 = v68 - v69[0];
v20 = a8;
do
{
*v20 = (*v20 - v18) / v19 * (double)(a2 - 1);
++v20;
}
while ( v20 != &a8[(unsigned int)(v15 - 1) + 1] );
}
ptr = (char *)calloc((int)(v17 * a10), 8uLL);
if ( !ptr )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v57 = calloc(v17, 8uLL);
if ( !v57 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
dcopy((unsigned int)a7, a6, 1LL, v57, 1LL);
if ( a7 > 0 )
{
v21 = 8LL * a2;
v22 = 0LL;
do
{
v26.m128d_f64[0] = a8[v22] + 0.5;
v27 = v26.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&v26.m128d_f64[0] & LC4) < 4.503599627370496e15 )
{
v28.m128d_f64[0] = (double)(int)v26.m128d_f64[0];
*(_QWORD *)&v27 = ~(_QWORD)LC4 & *(_QWORD *)&v26.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v28.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v28, v26) & LC5));
}
if ( (int)a10 > 0 )
{
v23 = (_QWORD *)(a1 + 8LL * (int)v27);
v24 = &ptr[8 * v22];
for ( i = 0; i != a10; ++i )
{
*(_QWORD *)v24 = *v23;
v23 = (_QWORD *)((char *)v23 + v21);
v24 += 8 * v17;
}
}
++v22;
}
while ( v22 != a7 );
}
if ( a7 < v17 )
{
v29 = &ptr[8 * v17 + 8 * (__int64)a7];
v30 = a7;
do
{
*(_QWORD *)v29 = LC5;
++v30;
v29 += 8 * v65;
}
while ( v30 != v65 - 1 );
}
v59 = malloc(8LL * (int)(v17 * a10));
if ( !v59 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v61 = malloc(8LL * (int)(a10 * a10));
if ( !v61 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v31 = calloc(v17, 8uLL);
if ( !v31 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v62 = calloc(v17, 8uLL);
if ( !v62 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v63 = calloc(v17, 8uLL);
if ( !v63 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v32 = (double *)calloc(v17, 8uLL);
if ( !v32 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
if ( a7 > 0 )
{
v33 = v31;
do
*v33++ = LC5;
while ( v33 != &v31[a7] );
}
v34 = a7;
v64 = a10 - 1;
dcopy(a10 - 1, a9, 1LL, &v31[v34], 1LL);
wls(ptr, (unsigned int)v17, a10, v57, v31, v61, v62, v59, v63, a14);
calcResid(ptr, (unsigned int)v17, a10, v57, a14, v32);
*a15 = 0.0;
if ( v17 > 0 )
{
v35 = 0LL;
v36 = 0.0;
do
{
v36 = v36 + v32[v35] * v32[v35] * *(double *)&v31[v35];
v37 = v35++;
}
while ( v37 != v65 - 2 );
*a15 = v36;
}
v38 = *a15 / dasum((unsigned int)v17, v31, 1LL);
*a15 = v38;
if ( v38 < 0.0 )
v39 = sqrt(v38);
else
v39 = sqrt(v38);
*a13 = dt_log(v32, (unsigned int)a7, a3, 0.0, v39);
v40 = *a15 / *a9;
if ( v40 < 0.0 )
v41 = sqrt(v40);
else
v41 = sqrt(v40);
v66 = &v32[v34];
v58 = dnorm_log(&v32[v34], v64, 0.0, v41) + *a13;
*a12 = v58;
v42 = 0;
if ( a11 > 0 )
{
while ( 1 )
{
if ( a7 > 0 )
{
v43 = *a15;
v44 = 0LL;
do
{
*(double *)&v31[v44] = (a3 + 1.0) / (v32[v44] * v32[v44] / v43 + a3);
++v44;
}
while ( a7 != v44 );
}
wls(ptr, (unsigned int)v17, a10, v57, v31, v61, v62, v59, v63, a14);
calcResid(ptr, (unsigned int)v17, a10, v57, a14, v32);
*a15 = 0.0;
if ( v17 > 0 )
{
v45 = 0LL;
v46 = 0.0;
do
{
v46 = v46 + v32[v45] * v32[v45] * *(double *)&v31[v45];
v47 = v45++;
}
while ( v47 != v65 - 2 );
*a15 = v46;
}
v48 = *a15 / dasum((unsigned int)v17, v31, 1LL);
*a15 = v48;
v49 = v48 < 0.0 ? sqrt(v48) : sqrt(v48);
*a13 = dt_log(v32, (unsigned int)a7, a3, 0.0, v49);
v50 = *a15 / *a9;
v51 = v50 < 0.0 ? sqrt(v50) : sqrt(v50);
v52 = dnorm_log(v66, v64, 0.0, v51) + *a13;
*a12 = v52;
if ( a4 > (v52 - v58) / COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v58 + v52) & LC4)
+ (v52 - v58) / COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v58 + v52) & LC4) )
break;
if ( a11 == ++v42 )
break;
v58 = v52;
}
}
free(ptr);
free(v57);
free(v59);
free(v61);
free(v31);
free(v62);
free(v63);
free(v32);
return v42;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, double a3, double a4, __int64 a5, __int64 a6, int a7, double *a8, double *a9, unsigned int a10, int a11, double *a12, double *a13, __int64 a14, double *a15)
{
int v15; // er15
int v17; // er14
double v18; // xmm2_8
double v19; // xmm1_8
double *v20; // rax
__int64 v21; // rsi
__int64 v22; // r8
_QWORD *v23; // rcx
char *v24; // rdx
int i; // eax
__m128d v26; // xmm0
double v27; // xmm2_8
__m128d v28; // xmm2
char *v29; // rdx
int v30; // eax
_QWORD *v31; // rbx
double *v32; // rbp
_QWORD *v33; // rax
__int64 v34; // r15
__int64 v35; // rax
double v36; // xmm1_8
__int64 v37; // rdx
double v38; // xmm2_8
double v39; // xmm2_8
double v40; // xmm1_8
double v41; // xmm1_8
unsigned int v42; // er15
double v43; // xmm3_8
__int64 v44; // rax
__int64 v45; // rax
double v46; // xmm1_8
__int64 v47; // rdx
double v48; // xmm2_8
double v49; // xmm2_8
double v50; // xmm1_8
double v51; // xmm1_8
double v52; // xmm2_8
char *ptr; // [rsp+10h] [rbp-98h]
void *v57; // [rsp+18h] [rbp-90h]
double v58; // [rsp+20h] [rbp-88h]
void *v59; // [rsp+28h] [rbp-80h]
void *v61; // [rsp+30h] [rbp-78h]
void *v62; // [rsp+38h] [rbp-70h]
void *v63; // [rsp+40h] [rbp-68h]
unsigned int v64; // [rsp+48h] [rbp-60h]
signed int v65; // [rsp+4Ch] [rbp-5Ch]
double *v66; // [rsp+50h] [rbp-58h]
double v68; // [rsp+60h] [rbp-48h] BYREF
double v69[8]; // [rsp+68h] [rbp-40h] BYREF

v15 = a7;
v65 = a7 + a10;
v17 = a7 + a10 - 1;
arrayMinMax(a8, (unsigned int)a7, v69, &v68);
if ( v15 > 0 )
{
v18 = v69[0];
v19 = v68 - v69[0];
v20 = a8;
do
{
*v20 = (*v20 - v18) / v19 * (double)(a2 - 1);
++v20;
}
while ( v20 != &a8[(unsigned int)(v15 - 1) + 1] );
}
ptr = (char *)calloc((int)(v17 * a10), 8uLL);
if ( !ptr )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v57 = calloc(v17, 8uLL);
if ( !v57 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
dcopy((unsigned int)a7, a6, 1LL, v57, 1LL);
if ( a7 > 0 )
{
v21 = 8LL * a2;
v22 = 0LL;
do
{
v26.m128d_f64[0] = a8[v22] + 0.5;
v27 = v26.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&v26.m128d_f64[0] & LC4) < 4.503599627370496e15 )
{
v28.m128d_f64[0] = (double)(int)v26.m128d_f64[0];
*(_QWORD *)&v27 = ~(_QWORD)LC4 & *(_QWORD *)&v26.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v28.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v28, v26) & LC5));
}
if ( (int)a10 > 0 )
{
v23 = (_QWORD *)(a1 + 8LL * (int)v27);
v24 = &ptr[8 * v22];
for ( i = 0; i != a10; ++i )
{
*(_QWORD *)v24 = *v23;
v23 = (_QWORD *)((char *)v23 + v21);
v24 += 8 * v17;
}
}
++v22;
}
while ( v22 != a7 );
}
if ( a7 < v17 )
{
v29 = &ptr[8 * v17 + 8 * (__int64)a7];
v30 = a7;
do
{
*(_QWORD *)v29 = LC5;
++v30;
v29 += 8 * v65;
}
while ( v30 != v65 - 1 );
}
v59 = malloc(8LL * (int)(v17 * a10));
if ( !v59 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v61 = malloc(8LL * (int)(a10 * a10));
if ( !v61 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v31 = calloc(v17, 8uLL);
if ( !v31 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v62 = calloc(v17, 8uLL);
if ( !v62 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v63 = calloc(v17, 8uLL);
if ( !v63 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v32 = (double *)calloc(v17, 8uLL);
if ( !v32 )
{
fwrite("Error -- out of memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
if ( a7 > 0 )
{
v33 = v31;
do
*v33++ = LC5;
while ( v33 != &v31[a7] );
}
v34 = a7;
v64 = a10 - 1;
dcopy(a10 - 1, a9, 1LL, &v31[v34], 1LL);
wls(ptr, (unsigned int)v17, a10, v57, v31, v61, v62, v59, v63, a14);
calcResid(ptr, (unsigned int)v17, a10, v57, a14, v32);
*a15 = 0.0;
if ( v17 > 0 )
{
v35 = 0LL;
v36 = 0.0;
do
{
v36 = v36 + v32[v35] * v32[v35] * *(double *)&v31[v35];
v37 = v35++;
}
while ( v37 != v65 - 2 );
*a15 = v36;
}
v38 = *a15 / dasum((unsigned int)v17, v31, 1LL);
*a15 = v38;
if ( v38 < 0.0 )
v39 = sqrt(v38);
else
v39 = sqrt(v38);
*a13 = dt_log(v32, (unsigned int)a7, a3, 0.0, v39);
v40 = *a15 / *a9;
if ( v40 < 0.0 )
v41 = sqrt(v40);
else
v41 = sqrt(v40);
v66 = &v32[v34];
v58 = dnorm_log(&v32[v34], v64, 0.0, v41) + *a13;
*a12 = v58;
v42 = 0;
if ( a11 > 0 )
{
while ( 1 )
{
if ( a7 > 0 )
{
v43 = *a15;
v44 = 0LL;
do
{
*(double *)&v31[v44] = (a3 + 1.0) / (v32[v44] * v32[v44] / v43 + a3);
++v44;
}
while ( a7 != v44 );
}
wls(ptr, (unsigned int)v17, a10, v57, v31, v61, v62, v59, v63, a14);
calcResid(ptr, (unsigned int)v17, a10, v57, a14, v32);
*a15 = 0.0;
if ( v17 > 0 )
{
v45 = 0LL;
v46 = 0.0;
do
{
v46 = v46 + v32[v45] * v32[v45] * *(double *)&v31[v45];
v47 = v45++;
}
while ( v47 != v65 - 2 );
*a15 = v46;
}
v48 = *a15 / dasum((unsigned int)v17, v31, 1LL);
*a15 = v48;
v49 = v48 < 0.0 ? sqrt(v48) : sqrt(v48);
*a13 = dt_log(v32, (unsigned int)a7, a3, 0.0, v49);
v50 = *a15 / *a9;
v51 = v50 < 0.0 ? sqrt(v50) : sqrt(v50);
v52 = dnorm_log(v66, v64, 0.0, v51) + *a13;
*a12 = v52;
if ( a4 > (v52 - v58) / COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v58 + v52) & LC4)
+ (v52 - v58) / COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v58 + v52) & LC4) )
break;
if ( a11 == ++v42 )
break;
v58 = v52;
}
}
free(ptr);
free(v57);
free(v59);
free(v61);
free(v31);
free(v62);
free(v63);
free(v32);
return v42;
}

original_code:
int lmT(double * basisMat, int basisRows, int basisCols,
    double * yVec, int n,
    double * timeVec,
    double * priorVec,
    double nu, int k,
    int maxIter, double tol,
    double * logPosterior,
    double * logLikelihood,
    double * coef,
    double * tau)
{
  int iter, i, j, m, tme;
  double logPosterior_tm1, logPrior, delta;
  m = n + k - 1;
  double minTime, maxTime;
  arrayMinMax(timeVec, n, &minTime, &maxTime);
  for (i=0; i<n; i++)
  {
    timeVec[i] = (timeVec[i] - minTime) / (maxTime - minTime);
    timeVec[i] = timeVec[i] * (basisRows-1);
  }
  double * dMat, * dVec;
  dMat = calloc( m * k, sizeof(double));
  if (dMat==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  dVec = calloc( m, sizeof(double) );
  if (dVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  dcopy(n, yVec, 1, dVec, 1);
  for (i=0; i<n; i++)
  {
    tme = (int) floor( timeVec[i] + 0.5 );
    for (j=0; j<k; j++)
    {
      dMat[i + j*m] = basisMat[tme + j*basisRows];
    }
  }
  for (i=n; i<m; i++)
  {
    j = i - n + 1;
    dMat[i + j*m] = 1;
  }
  double * sqwX, * XTX;
  sqwX = malloc(m * k * sizeof(double));
  if (sqwX==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  XTX = malloc(k * k * sizeof(double));
  if (XTX==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  double * w, * sqw, * sqwy, * resid;
  w = calloc(m, sizeof(double));
  if (w==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  sqw = calloc(m, sizeof(double));
  if (sqw==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  sqwy = calloc(m, sizeof(double));
  if (sqwy==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  resid = calloc(m, sizeof(double));
  if (resid==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  for (i=0; i<n; i++)
  {
    w[i] = 1;
  }
  dcopy(k-1, priorVec, 1, &w[n], 1);
  wls(dMat, m, k, dVec, w, XTX, sqw, sqwX, sqwy, coef);
  calcResid(dMat, m, k, dVec, coef, resid);
  (*tau) = 0;
  for (i=0; i<m; i++)
  {
    (*tau) += resid[i] * resid[i] * w[i];
  }
  (*tau) /= dasum(m, w, 1);
  (*logLikelihood) = dt_log(resid, n, nu, 0, sqrt(*tau));
  logPrior = dnorm_log(&resid[n], k-1, 0, sqrt((*tau)/priorVec[0]));
  (*logPosterior) = (*logLikelihood) + logPrior;
  logPosterior_tm1 = (*logPosterior);
  for (iter=0; iter<maxIter; iter++)
  {
    for (i=0; i<n; i++)
    {
      w[i] = (nu + 1) / (nu + resid[i]*resid[i]/(*tau));
    }
    wls(dMat, m, k, dVec, w, XTX, sqw, sqwX, sqwy, coef);
    calcResid(dMat, m, k, dVec, coef, resid);
    (*tau) = 0;
    for (i=0; i<m; i++)
    {
      (*tau) += resid[i] * resid[i] * w[i];
    }
    (*tau) /= dasum(m, w, 1);
    (*logLikelihood) = dt_log(resid, n, nu, 0, sqrt(*tau));
    logPrior = dnorm_log(&resid[n], k-1, 0, sqrt((*tau)/priorVec[0]));
    (*logPosterior) = (*logLikelihood) + logPrior;
    delta = ((*logPosterior) - logPosterior_tm1) /
      fabs((*logPosterior) + logPosterior_tm1) * 2;
    if (delta < tol)
    {
      logPosterior_tm1 = (*logPosterior);
      break;
    }
    logPosterior_tm1 = (*logPosterior);
  }
  free(dMat);
  dMat = ((void *)0);
  free(dVec);
  dVec = ((void *)0);
  free(sqwX);
  sqwX = ((void *)0);
  free(XTX);
  XTX = ((void *)0);
  free(w);
  w=((void *)0);
  free(sqw);
  sqw=((void *)0);
  free(sqwy);
  sqw=((void *)0);
  free(resid);
  resid=((void *)0);
  return iter;
}

canonical_original_code:
int lmT(double *basisMat, int basisRows, int basisCols, double *yVec, int n, double *timeVec, double *priorVec, double nu, int k, int maxIter, double tol, double *logPosterior, double *logLikelihood, double *coef, double *tau)
{
  int iter; int i; int j; int m; int tme;
  double logPosterior_tm1; double logPrior; double delta;
  m = n + k - 1;
  double minTime; double maxTime;
  arrayMinMax(timeVec, n, &minTime, &maxTime);
  for (i=0; i<n; i++)
  {
    timeVec[i] = (timeVec[i] - minTime) / (maxTime - minTime);
    timeVec[i] = timeVec[i] * (basisRows-1);
  }
  double *dMat; double *dVec;
  dMat = calloc( m * k, sizeof(double));
  if (dMat==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  dVec = calloc( m, sizeof(double) );
  if (dVec==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  dcopy(n, yVec, 1, dVec, 1);
  for (i=0; i<n; i++)
  {
    tme = (int) floor( timeVec[i] + 0.5 );
    for (j=0; j<k; j++)
    {
      dMat[i + j*m] = basisMat[tme + j*basisRows];
    }
  }
  for (i=n; i<m; i++)
  {
    j = i - n + 1;
    dMat[i + j*m] = 1;
  }
  double *sqwX; double *XTX;
  sqwX = malloc(m * k * sizeof(double));
  if (sqwX==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  XTX = malloc(k * k * sizeof(double));
  if (XTX==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  double *w; double *sqw; double *sqwy; double *resid;
  w = calloc(m, sizeof(double));
  if (w==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  sqw = calloc(m, sizeof(double));
  if (sqw==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  sqwy = calloc(m, sizeof(double));
  if (sqwy==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  resid = calloc(m, sizeof(double));
  if (resid==((void *)0))
  {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  for (i=0; i<n; i++)
  {
    w[i] = 1;
  }
  dcopy(k-1, priorVec, 1, &w[n], 1);
  wls(dMat, m, k, dVec, w, XTX, sqw, sqwX, sqwy, coef);
  calcResid(dMat, m, k, dVec, coef, resid);
  (*tau) = 0;
  for (i=0; i<m; i++)
  {
    (*tau) += resid[i] * resid[i] * w[i];
  }
  (*tau) /= dasum(m, w, 1);
  (*logLikelihood) = dt_log(resid, n, nu, 0, sqrt(*tau));
  logPrior = dnorm_log(&resid[n], k-1, 0, sqrt((*tau)/priorVec[0]));
  (*logPosterior) = (*logLikelihood) + logPrior;
  logPosterior_tm1 = (*logPosterior);
  for (iter=0; iter<maxIter; iter++)
  {
    for (i=0; i<n; i++)
    {
      w[i] = (nu + 1) / (nu + resid[i]*resid[i]/(*tau));
    }
    wls(dMat, m, k, dVec, w, XTX, sqw, sqwX, sqwy, coef);
    calcResid(dMat, m, k, dVec, coef, resid);
    (*tau) = 0;
    for (i=0; i<m; i++)
    {
      (*tau) += resid[i] * resid[i] * w[i];
    }
    (*tau) /= dasum(m, w, 1);
    (*logLikelihood) = dt_log(resid, n, nu, 0, sqrt(*tau));
    logPrior = dnorm_log(&resid[n], k-1, 0, sqrt((*tau)/priorVec[0]));
    (*logPosterior) = (*logLikelihood) + logPrior;
    delta = ((*logPosterior) - logPosterior_tm1) /
      fabs((*logPosterior) + logPosterior_tm1) * 2;
    if (delta < tol)
    {
      logPosterior_tm1 = (*logPosterior);
      break;
    }
    logPosterior_tm1 = (*logPosterior);
  }
  free(dMat);
  dMat = ((void *)0);
  free(dVec);
  dVec = ((void *)0);
  free(sqwX);
  sqwX = ((void *)0);
  free(XTX);
  XTX = ((void *)0);
  free(w);
  w=((void *)0);
  free(sqw);
  sqw=((void *)0);
  free(sqwy);
  sqw=((void *)0);
  free(resid);
  resid=((void *)0);
  return iter;
}

variable_types:
basisMat
double *

variable_types: basisRows int

variable_types: basisCols int

variable_types:
yVec
double *

variable_types: n int

variable_types:
timeVec
double *

variable_types:
priorVec
double *

variable_types: nu double

variable_types: k int

variable_types: maxIter int

variable_types: tol double

variable_types:
logPosterior
double *

variable_types:
logLikelihood
double *

variable_types:
tau
double *

variable_types: iter int

variable_types: m int

variable_types: tme int

variable_types: logPrior double

variable_types: delta double

variable_types: minTime double

variable_types: maxTime double

variable_types:
dMat
double *

variable_types:
dVec
double *

variable_types:
XTX
double *

variable_types:
w
double *


tokenize

repo: awdavies/crumbshell

decompiled_code:
void __fastcall tokenize(__int64 a1, const char *a2, char a3)
{
const char *v3; // rbx
char v5; // al
int v6; // er13
char v7[184]; // [rsp-B8h] [rbp-B8h] BYREF

if ( a2 )
{
v3 = a2;
if ( a1 )
{
memset(v7, 0, 0x80uLL);
v5 = *a2;
if ( *a2 )
{
v6 = 0;
do
{
if ( a3 == v5 )
{
*(_QWORD *)(a1 + 8LL * v6) = alloc_str(*(_QWORD *)(a1 + 8LL * v6), v7);
memset(v7, 0, 0x80uLL);
++v6;
}
else
{
strncat(v7, v3, 1uLL);
}
v5 = *++v3;
}
while ( *v3 );
}
else
{
v6 = 0;
}
*(_QWORD *)(a1 + 8LL * v6) = alloc_str(*(_QWORD *)(a1 + 8LL * v6), v7);
}
}
}

original_code:
static void tokenize(char ** str_arr, char * buf, char delim) {
  int i = 0;
  char token[128];
  if (!buf || !str_arr) {
    return;
  }
  bzero(token, 128);
  for (i = 0; *buf; buf++) {
    if (*buf == delim) {
      str_arr[i] = alloc_str(str_arr[i], token);
      bzero(token, 128);
      ++i;
    } else {
      strncat(token, buf, 1);
    }
  }
  str_arr[i] = alloc_str(str_arr[i], token);
}

canonical_original_code:
static void tokenize(char **str_arr, char *buf, char delim) {
  int i = 0;
  char token[128];
  if (!buf || !str_arr) {
    return;
  }
  bzero(token, 128);
  for (i = 0; *buf; buf++) {
    if (*buf == delim) {
      str_arr[i] = alloc_str(str_arr[i], token);
      bzero(token, 128);
      ++i;
    } else {
      strncat(token, buf, 1);
    }
  }
  str_arr[i] = alloc_str(str_arr[i], token);
}

variable_types:
buf
char *

variable_types: delim char

variable_types: i int

variable_types:
token
char [128]


decompiled_code:
void __fastcall clear_str_arr(void **a1)
{
void **v1; // rbx
void *v2; // rdi

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
free(v2);
*v1++ = 0LL;
v2 = *v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void __fastcall func10(void **a1)
{
void **v1; // rbx
void *v2; // rdi

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
free(v2);
*v1++ = 0LL;
v2 = *v1;
}
while ( *v1 );
}
}

original_code:
static void clear_str_arr(char ** str_arr) {
  int i;
  for (i = 0; str_arr[i]; i++) {
    free(str_arr[i]);
    str_arr[i] = ((void *)0);
  }
}

canonical_original_code:
static void clear_str_arr(char **str_arr) {
  int i;
  for (i = 0; str_arr[i]; i++) {
    free(str_arr[i]);
    str_arr[i] = ((void *)0);
  }
}


decompiled_code:
int run_child_proc()
{
int result; // eax

if ( fork() )
return wait(0LL);
result = execv(arg_buf, &arg_buf);
if ( result < 0 )
{
printf("%s: no such command\n", arg_buf);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func11()
{
int result; // eax

if ( fork() )
return wait(0LL);
result = execv(arg_buf, &arg_buf);
if ( result < 0 )
{
printf("%s: no such command\n", arg_buf);
exit(1);
}
return result;
}

original_code:
static void run_child_proc() {
  int status;
  pid_t ret = fork();
  if (ret == 0) {
    status= execv(arg_buf[0], arg_buf);
    if (status < 0) {
      printf("%s: no such command\n", arg_buf[0]);
      exit(1);
    }
  } else {
    wait(((void *)0));
  }
}

canonical_original_code:
static void run_child_proc() {
  int status;
  int ret = fork();
  if (ret == 0) {
    status= execv(arg_buf[0], arg_buf);
    if (status < 0) {
      printf("%s: no such command\n", arg_buf[0]);
      exit(1);
    }
  } else {
    wait(((void *)0));
  }
}

variable_types: status int

variable_types: ret int


decompiled_code:
void __fastcall run_cmd_str(const char *a1)
{
if ( *a1 )
{
tokenize((__int64)&arg_buf, a1, 32);
if ( !(unsigned __int8)run_builtin() )
{
if ( !index(arg_buf, 47) )
concat_path((const char **)&path, (const char **)&arg_buf);
run_child_proc();
}
clear_str_arr((void **)&arg_buf);
}
}

canonical_decompiled_code:
void __fastcall func12(const char *a1)
{
if ( *a1 )
{
func8((__int64)&arg_buf, a1, 32);
if ( !(unsigned __int8)func14() )
{
if ( !index(arg_buf, 47) )
func9((const char **)&path, (const char **)&arg_buf);
func11();
}
func10((void **)&arg_buf);
}
}

original_code:
static void run_cmd_str(char * str) {
  if (str[0] != '\0') {
    tokenize(arg_buf, str, ' ');
    if (!run_builtin()) {
      if (!index(arg_buf[0], '/'))
        concat_path(path, arg_buf);
      run_child_proc();
    }
    clear_str_arr(arg_buf);
  }
}

canonical_original_code:
static void run_cmd_str(char *str) {
  if (str[0] != '\0') {
    tokenize(arg_buf, str, ' ');
    if (!run_builtin()) {
      if (!index(arg_buf[0], '/'))
        concat_path(path, arg_buf);
      run_child_proc();
    }
    clear_str_arr(arg_buf);
  }
}

variable_types:
str
char *


decompiled_code:
int run_from_file()
{
int v0; // er14
unsigned int v1; // er13
int v2; // eax
int v4; // er12
char v5; // dl
__int64 v6; // rax
unsigned int v7; // ebx
char v8[129]; // [rsp+1h] [rbp-129h]
char v9[128]; // [rsp+2h] [rbp-128h] BYREF
char buf[168]; // [rsp+82h] [rbp-A8h] BYREF

v0 = open(file, 0);
v1 = 0;
if ( v0 < 0 )
{
v2 = *__errno_location();
switch ( v2 )
{
case 17:
return printf("%s: no such file.\n", file);
case 21:
return printf("%s: is a directory.\n", file);
case 13:
return printf("%s: read access denied.\n", file);
}
return printf("%s: read access error.\n", file);
}
while ( 1 )
{
memset(buf, 0, 0x80uLL);
memset(v9, 0, sizeof(v9));
v4 = pread(v0, buf, 0x80uLL, v1);
if ( v4 < 0 )
{
puts("error while reading file.");
return close(v0);
}
v5 = buf[0];
if ( (unsigned __int8)(buf[0] + 1) > 1u )
{
v6 = 1LL;
if ( buf[0] != 10 )
{
do
{
v8[v6] = v5;
v7 = v6;
v5 = buf[v6++];
}
while ( v7 <= 0x7F && v5 != 10 && (unsigned __int8)(v5 + 1) > 1u );
if ( v5 != 10 )
goto LABEL_12;
goto LABEL_21;
}
}
if ( buf[0] != 10 )
break;
v7 = 0;
LABEL_21:
++v7;
LABEL_12:
v1 += v7;
clear_str_arr((void **)&arg_buf);
run_cmd_str(v9);
if ( !v4 || !v7 )
return close(v0);
}
clear_str_arr((void **)&arg_buf);
run_cmd_str(v9);
return close(v0);
}

canonical_decompiled_code:
int func13()
{
int v0; // er14
unsigned int v1; // er13
int v2; // eax
int v4; // er12
char v5; // dl
__int64 v6; // rax
unsigned int v7; // ebx
char v8[129]; // [rsp+1h] [rbp-129h]
char v9[128]; // [rsp+2h] [rbp-128h] BYREF
char buf[168]; // [rsp+82h] [rbp-A8h] BYREF

v0 = open(file, 0);
v1 = 0;
if ( v0 < 0 )
{
v2 = *__errno_location();
switch ( v2 )
{
case 17:
return printf("%s: no such file.\n", file);
case 21:
return printf("%s: is a directory.\n", file);
case 13:
return printf("%s: read access denied.\n", file);
}
return printf("%s: read access error.\n", file);
}
while ( 1 )
{
memset(buf, 0, 0x80uLL);
memset(v9, 0, sizeof(v9));
v4 = pread(v0, buf, 0x80uLL, v1);
if ( v4 < 0 )
{
puts("error while reading file.");
return close(v0);
}
v5 = buf[0];
if ( (unsigned __int8)(buf[0] + 1) > 1u )
{
v6 = 1LL;
if ( buf[0] != 10 )
{
do
{
v8[v6] = v5;
v7 = v6;
v5 = buf[v6++];
}
while ( v7 <= 0x7F && v5 != 10 && (unsigned __int8)(v5 + 1) > 1u );
if ( v5 != 10 )
goto LABEL_12;
goto LABEL_21;
}
}
if ( buf[0] != 10 )
break;
v7 = 0;
LABEL_21:
++v7;
LABEL_12:
v1 += v7;
func10((void **)&arg_buf);
func12(v9);
if ( !v4 || !v7 )
return close(v0);
}
func10((void **)&arg_buf);
func12(v9);
return close(v0);
}

original_code:
static void run_from_file() {
  int fd;
  unsigned int file_offset = 0;
  int file_status = 0;
  unsigned int i;
  char rbuf[128];
  char cbuf[128];
  fd = open(arg_buf[1], 00);
  if (fd < 0) {
    switch((*__errno_location ())) {
      case 13:
        printf("%s: read access denied.\n", arg_buf[1]);
        break;
      case 17:
        printf("%s: no such file.\n", arg_buf[1]);
        break;
      case 21:
        printf("%s: is a directory.\n", arg_buf[1]);
        break;
      default:
        printf("%s: read access error.\n", arg_buf[1]);
    }
  } else {
    do {
      bzero(rbuf, 128);
      bzero(cbuf, 128);
      file_status = pread(fd, rbuf, 128, file_offset);
      if (file_status < 0) {
        printf("error while reading file.\n");
        break;
      }
      for(i = 0; rbuf[i] != (-1) && rbuf[i] != '\0' && rbuf[i] != '\n' && i < 128; i++) {
        cbuf[i] = rbuf[i];
      }
      if (rbuf[i] == '\n')
        i++;
      file_offset += i;
      clear_str_arr(arg_buf);
      run_cmd_str(cbuf);
    } while (file_status != 0 && i != 0);
    close(fd);
  }
}

variable_types: fd int

variable_types:
i
unsigned int

variable_types:
rbuf
char [128]

variable_types:
cbuf
char [128]


decompiled_code:
__int64 run_builtin()
{
__int64 result; // rax
int v1; // edx
int v2; // eax
char *v3; // rax

if ( !strcmp(arg_buf, "cd") )
{
if ( file )
{
v1 = chdir(file);
}
else
{
v3 = getenv("HOME");
v1 = chdir(v3);
}
result = 1LL;
if ( v1 < 0 )
{
v2 = *__errno_location();
if ( v2 == 20 )
{
printf("%s: not a directory\n", file);
result = 1LL;
}
else if ( v2 == 40 )
{
printf("%s: symbolic loop encountered\n", file);
result = 1LL;
}
else
{
if ( v2 == 2 )
printf("%s: no such directory\n", file);
else
printf("%s: error encountered\n", file);
result = 1LL;
}
}
}
else
{
if ( !strcmp(arg_buf, "exit") )
{
clear_str_arr((void **)&arg_buf);
clear_str_arr((void **)&path);
exit(0);
}
result = 0LL;
if ( !memcmp(arg_buf, ".", 2uLL) )
{
run_from_file();
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax
int v1; // edx
int v2; // eax
char *v3; // rax

if ( !strcmp(arg_buf, "cd") )
{
if ( file )
{
v1 = chdir(file);
}
else
{
v3 = getenv("HOME");
v1 = chdir(v3);
}
result = 1LL;
if ( v1 < 0 )
{
v2 = *__errno_location();
if ( v2 == 20 )
{
printf("%s: not a directory\n", file);
result = 1LL;
}
else if ( v2 == 40 )
{
printf("%s: symbolic loop encountered\n", file);
result = 1LL;
}
else
{
if ( v2 == 2 )
printf("%s: no such directory\n", file);
else
printf("%s: error encountered\n", file);
result = 1LL;
}
}
}
else
{
if ( !strcmp(arg_buf, "exit") )
{
func10((void **)&arg_buf);
func10((void **)&path);
exit(0);
}
result = 0LL;
if ( !memcmp(arg_buf, ".", 2uLL) )
{
func13();
result = 1LL;
}
}
return result;
}

original_code:
static _Bool run_builtin() {
  int ret;
  if (strncmp(arg_buf[0], "cd", 3) == 0) {
    if (arg_buf[1])
      ret = chdir(arg_buf[1]);
    else
      ret = chdir(getenv("HOME"));
    if (ret < 0) {
      switch ((*__errno_location ())) {
        case 2:
          printf("%s: no such directory\n", arg_buf[1]);
          break;
        case 20:
          printf("%s: not a directory\n", arg_buf[1]);
          break;
        case 40:
          printf("%s: symbolic loop encountered\n", arg_buf[1]);
          break;
        default:
          printf("%s: error encountered\n", arg_buf[1]);
          break;
      }
    }
    return 1;
  }
  if (strncmp(arg_buf[0], "exit", 5) == 0) {
    clear_str_arr(arg_buf);
    clear_str_arr(path);
    exit(0);
  }
  if (strncmp(arg_buf[0], ".", 128) == 0) {
    run_from_file();
    return 1;
  }
  return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rsi
char v4; // bl
char src; // [rsp+Fh] [rbp-89h] BYREF
char dest[136]; // [rsp+10h] [rbp-88h] BYREF

v3 = getenv("PATH");
tokenize((__int64)&path, v3, 58);
printf("crsh> ");
memset(dest, 0, 0x80uLL);
do
{
while ( 1 )
{
v4 = getchar();
src = v4;
if ( v4 != 10 )
break;
run_cmd_str(dest);
memset(dest, 0, 0x80uLL);
printf("crsh> ");
}
strncat(dest, &src, 1uLL);
}
while ( v4 != -1 );
clear_str_arr((void **)&path);
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rsi
char v4; // bl
char src; // [rsp+Fh] [rbp-89h] BYREF
char dest[136]; // [rsp+10h] [rbp-88h] BYREF

v3 = getenv("PATH");
func8((__int64)&path, v3, 58);
printf("crsh> ");
memset(dest, 0, 0x80uLL);
do
{
while ( 1 )
{
v4 = getchar();
src = v4;
if ( v4 != 10 )
break;
func12(dest);
memset(dest, 0, 0x80uLL);
printf("crsh> ");
}
strncat(dest, &src, 1uLL);
}
while ( v4 != -1 );
func10((void **)&path);
putchar(10);
return 0;
}

original_code:
int main(int argc, char ** argv, char ** envp) {
  char buf[128];
  char input = '\0';
  tokenize(path, getenv("PATH"), ':');
  printf(PS1);
  bzero(buf, 128);
  while (input != (-1)) {
    input = getchar();
    switch (input) {
      case '\n':
        run_cmd_str(buf);
        bzero(buf, 128);
        printf(PS1);
        break;
      default:
        strncat(buf, &input, 1);
        break;
    }
  }
  clear_str_arr(path);
  printf("\n");
  return 0;
}

canonical_original_code:
int main(int argc, char **argv, char **envp) {
  char buf[128];
  char input = '\0';
  tokenize(path, getenv("PATH"), ':');
  printf(PS1);
  bzero(buf, 128);
  while (input != (-1)) {
    input = getchar();
    switch (input) {
      case '\n':
        run_cmd_str(buf);
        bzero(buf, 128);
        printf(PS1);
        break;
      default:
        strncat(buf, &input, 1);
        break;
    }
  }
  clear_str_arr(path);
  printf("\n");
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
envp
char **

variable_types:
buf
char [128]

variable_types: input char


decompiled_code:
bool __fastcall prime_test(__int64 a1)
{
bool result; // al
__int64 v2; // rcx
__int64 v3; // rsi

result = 0;
if ( a1 > 1 )
{
if ( (a1 & 1) != 0 )
{
if ( a1 == 3 * (a1 / 3) )
{
result = a1 == 3;
}
else if ( a1 <= 24 )
{
result = 1;
}
else if ( a1 == 5 * (a1 / 5) )
{
result = 0;
}
else if ( a1 == 7 * (a1 / 7) )
{
result = 0;
}
else
{
v2 = 5LL;
while ( 1 )
{
v3 = v2;
v2 += 6LL;
if ( v2 * v2 > a1 )
return 1;
if ( !(a1 % v2) )
break;
if ( !(a1 % (v3 + 8)) )
return 0;
}
result = 0;
}
}
else
{
result = a1 == 2;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func7(__int64 a1)
{
bool result; // al
__int64 v2; // rcx
__int64 v3; // rsi

result = 0;
if ( a1 > 1 )
{
if ( (a1 & 1) != 0 )
{
if ( a1 == 3 * (a1 / 3) )
{
result = a1 == 3;
}
else if ( a1 <= 24 )
{
result = 1;
}
else if ( a1 == 5 * (a1 / 5) )
{
result = 0;
}
else if ( a1 == 7 * (a1 / 7) )
{
result = 0;
}
else
{
v2 = 5LL;
while ( 1 )
{
v3 = v2;
v2 += 6LL;
if ( v2 * v2 > a1 )
return 1;
if ( !(a1 % v2) )
break;
if ( !(a1 % (v3 + 8)) )
return 0;
}
result = 0;
}
}
else
{
result = a1 == 2;
}
}
return result;
}

original_code:
static inline _Bool prime_test(long n) {
  if (n <= 1L) {
    return 0;
  }
  if (n % 2L == 0) {
    return 2L == n;
  }
  if (n % 3L == 0) {
    return 3L == n;
  }
  for (long i = 5L; i * i <= n; i += 6L) {
    if (n % i == 0L)
      return 0;
    if (n % (i + 2) == 0L)
      return 0;
  }
  return 1;
}

variable_types: n long

variable_types: i long


decompiled_code:
void __fastcall __noreturn prime_tester(void *a1)
{
__int64 v1; // rbx
char *v2; // rbp

v1 = 1000000LL * (_QWORD)a1;
v2 = 0LL;
while ( 1 )
{
if ( prime_test(v1) )
v2 += v1;
if ( 1000000LL * (_QWORD)a1 + 1000000 == ++v1 )
pthread_exit(v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
__int64 v1; // rbx
char *v2; // rbp

v1 = 1000000LL * (_QWORD)a1;
v2 = 0LL;
while ( 1 )
{
if ( func7(v1) )
v2 += v1;
if ( 1000000LL * (_QWORD)a1 + 1000000 == ++v1 )
pthread_exit(v2);
}
}

original_code:
void *prime_tester(void *thread_num) {
  const long range = 2000000 / DEFAULT_THREADS;
  long thread_id = (long) thread_num;
  long accumulator = 0;
  for (long i = range * thread_id; i < (thread_id * range) + range; ++i) {
    if (prime_test(i)) {
      accumulator += i;
    }
  }
  pthread_exit((void *)accumulator);
}

canonical_original_code:
void *prime_tester(void *thread_num) {
  long range = 2000000 / DEFAULT_THREADS;
  long thread_id = (long) thread_num;
  long accumulator = 0;
  for (long i = range * thread_id; i < (thread_id * range) + range; ++i) {
    if (prime_test(i)) {
      accumulator += i;
    }
  }
  pthread_exit((void *)accumulator);
}

variable_types: range long

variable_types: accumulator long

return_type: void *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // rbx
void *thread_return[2]; // [rsp+8h] [rbp-10h] BYREF

thread_pool = malloc(0x10uLL);
v3 = pthread_create((pthread_t *)thread_pool, 0LL, (void *(*)(void *))prime_tester, 0LL);
if ( !v3 )
{
v3 = pthread_create((pthread_t *)thread_pool + 1, 0LL, (void *(*)(void *))prime_tester, (void *)1);
if ( !v3 )
{
pthread_join(*(_QWORD *)thread_pool, thread_return);
v4 = thread_return[0];
pthread_join(*((_QWORD *)thread_pool + 1), thread_return);
printf("The sum is %ld\n", (char *)thread_return[0] + (unsigned __int64)v4);
free(thread_pool);
pthread_exit(0LL);
}
}
printf("ERR! return code from pthread_create() is %d\n", v3);
return 1;
}

original_code:
int main(int argc, char **argv) {
  uint32_t nthreads = DEFAULT_THREADS;
  thread_pool = malloc(nthreads * sizeof(thread_pool));
  int res;
  for (long i = 0; i < nthreads; ++i) {
    res = pthread_create(&thread_pool[i], ((void *)0), prime_tester,
        (void *)i);
    if (res) {
      printf("ERR!  return code from pthread_create() is %d\n", res);
      return 1;
    }
  }
  long accumulator = 0;
  long join_res;
  for (long i = 0; i < nthreads; ++i) {
    pthread_join(thread_pool[i], (void **)&join_res);
    accumulator += join_res;
  }
  printf("The sum is %ld\n", accumulator);
  free(thread_pool);
  pthread_exit(((void *)0));
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  unsigned int nthreads = DEFAULT_THREADS;
  thread_pool = malloc(nthreads * sizeof(thread_pool));
  int res;
  for (long i = 0; i < nthreads; ++i) {
    res = pthread_create(&thread_pool[i], ((void *)0), prime_tester,
        (void *)i);
    if (res) {
      printf("ERR!  return code from pthread_create() is %d\n", res);
      return 1;
    }
  }
  long accumulator = 0;
  long join_res;
  for (long i = 0; i < nthreads; ++i) {
    pthread_join(thread_pool[i], (void **)&join_res);
    accumulator += join_res;
  }
  printf("The sum is %ld\n", accumulator);
  free(thread_pool);
  pthread_exit(((void *)0));
  return 0;
}

variable_types:
nthreads
unsigned int

variable_types: res int


usage

repo: awilliam/tests

decompiled_code:
int __fastcall usage(const char *a1)
{
printf("usage: %s ssss:bb:dd.f\n", a1);
puts("\tssss: PCI segment, ex. 0000");
puts("\tbb: PCI bus, ex. 01");
puts("\tdd: PCI device, ex. 06");
return puts("\tf: PCI function, ex. 0");
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
printf("usage: %s ssss:bb:dd.f\n", a1);
puts("\tssss: PCI segment, ex. 0000");
puts("\tbb: PCI bus, ex. 01");
puts("\tdd: PCI device, ex. 06");
return puts("\tf: PCI function, ex. 0");
}

original_code:
void usage(char *name)
{
 printf("usage: %s ssss:bb:dd.f\n", name);
 printf("\tssss: PCI segment, ex. 0000\n");
 printf("\tbb:   PCI bus, ex. 01\n");
 printf("\tdd:   PCI device, ex. 06\n");
 printf("\tf:    PCI function, ex. 0\n");
}

variable_types:
name
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
size_t v4; // rax
ssize_t v5; // rax
int v6; // eax
int v7; // ebp
int v8; // ebp
int v9; // ebp
int *v10; // rax
char *v11; // rax
int *v13; // rax
char *v14; // rax
int v15; // ebp
int v16; // [rsp+8h] [rbp-140h] BYREF
int v17; // [rsp+Ch] [rbp-13Ch]
struct stat v18; // [rsp+10h] [rbp-138h] BYREF
char buf[64]; // [rsp+A0h] [rbp-A8h] BYREF
char s[56]; // [rsp+E0h] [rbp-68h] BYREF
unsigned int v21; // [rsp+118h] [rbp-30h]
int fd[11]; // [rsp+11Ch] [rbp-2Ch] BYREF

v17 = 0;
v16 = 8;
if ( argc == 2 && (unsigned int)__isoc99_sscanf() == 4 )
{
fd[0] = open("/dev/vfio/vfio", 2);
if ( fd[0] < 0 )
{
v10 = __errno_location();
v11 = strerror(*v10);
printf("Failed to open /dev/vfio/vfio, %d (%s)\n", (unsigned int)fd[0], v11);
v3 = fd[0];
}
else
{
snprintf(
s,
0x32uLL,
"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/",
(unsigned int)fd[4],
(unsigned int)fd[3],
(unsigned int)fd[2],
(unsigned int)fd[1]);
v3 = stat(s, &v18);
if ( v3 < 0 )
{
puts("No such device");
}
else
{
v4 = strlen(s);
strncat(s, "iommu_group", 49 - v4);
v5 = readlink(s, buf, 0x32uLL);
if ( v5 <= 0 )
{
puts("No iommu_group for device");
v3 = -1;
}
else
{
buf[v5] = 0;
__xpg_basename(buf);
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
snprintf(s, 0x32uLL, "/dev/vfio/%d", v21);
v6 = open(s, 2);
v3 = v6;
if ( v6 < 0 )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("Failed to open %s, %d (%s)\n", s, (unsigned int)v3, v14);
}
else
{
v7 = ioctl(v6, 0x3B67uLL, &v16);
if ( v7 )
{
puts("ioctl(VFIO_GROUP_GET_STATUS) failed");
v3 = v7;
}
else if ( (v17 & 1) != 0 )
{
v8 = ioctl(v3, 0x3B68uLL, fd);
if ( v8 )
{
puts("Failed to set group container");
v3 = v8;
}
else
{
v9 = ioctl(fd[0], 0x3B66uLL, 1LL);
if ( v9 )
{
puts("Failed to set IOMMU");
v3 = v9;
}
else
{
close(fd[0]);
strcpy(s, "THIS-IS-NOT-THE-RIGHT-NAME");
do
v15 = ioctl(v3, 0x3B6AuLL, s);
while ( v15 < 0 );
printf("Got a device named \"%s\"???\n", s);
close(v3);
close(v15);
v3 = -1;
}
}
}
else
{
puts("Group not viable, are all devices attached to vfio?");
v3 = -1;
}
}
}
else
{
puts("Unknown group");
v3 = -1;
}
}
}
}
}
else
{
usage(*argv);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
size_t v4; // rax
ssize_t v5; // rax
int v6; // eax
int v7; // ebp
int v8; // ebp
int v9; // ebp
int *v10; // rax
char *v11; // rax
int *v13; // rax
char *v14; // rax
int v15; // ebp
int v16; // [rsp+8h] [rbp-140h] BYREF
int v17; // [rsp+Ch] [rbp-13Ch]
struct stat v18; // [rsp+10h] [rbp-138h] BYREF
char buf[64]; // [rsp+A0h] [rbp-A8h] BYREF
char s[56]; // [rsp+E0h] [rbp-68h] BYREF
unsigned int v21; // [rsp+118h] [rbp-30h]
int fd[11]; // [rsp+11Ch] [rbp-2Ch] BYREF

v17 = 0;
v16 = 8;
if ( argc == 2 && (unsigned int)__isoc99_sscanf() == 4 )
{
fd[0] = open("/dev/vfio/vfio", 2);
if ( fd[0] < 0 )
{
v10 = __errno_location();
v11 = strerror(*v10);
printf("Failed to open /dev/vfio/vfio, %d (%s)\n", (unsigned int)fd[0], v11);
v3 = fd[0];
}
else
{
snprintf(
s,
0x32uLL,
"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/",
(unsigned int)fd[4],
(unsigned int)fd[3],
(unsigned int)fd[2],
(unsigned int)fd[1]);
v3 = func10(s, &v18);
if ( v3 < 0 )
{
puts("No such device");
}
else
{
v4 = strlen(s);
strncat(s, "iommu_group", 49 - v4);
v5 = readlink(s, buf, 0x32uLL);
if ( v5 <= 0 )
{
puts("No iommu_group for device");
v3 = -1;
}
else
{
buf[v5] = 0;
__xpg_basename(buf);
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
snprintf(s, 0x32uLL, "/dev/vfio/%d", v21);
v6 = open(s, 2);
v3 = v6;
if ( v6 < 0 )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("Failed to open %s, %d (%s)\n", s, (unsigned int)v3, v14);
}
else
{
v7 = ioctl(v6, 0x3B67uLL, &v16);
if ( v7 )
{
puts("ioctl(VFIO_GROUP_GET_STATUS) failed");
v3 = v7;
}
else if ( (v17 & 1) != 0 )
{
v8 = ioctl(v3, 0x3B68uLL, fd);
if ( v8 )
{
puts("Failed to set group container");
v3 = v8;
}
else
{
v9 = ioctl(fd[0], 0x3B66uLL, 1LL);
if ( v9 )
{
puts("Failed to set IOMMU");
v3 = v9;
}
else
{
close(fd[0]);
strcpy(s, "THIS-IS-NOT-THE-RIGHT-NAME");
do
v15 = ioctl(v3, 0x3B6AuLL, s);
while ( v15 < 0 );
printf("Got a device named \"%s\"???\n", s);
close(v3);
close(v15);
v3 = -1;
}
}
}
else
{
puts("Group not viable, are all devices attached to vfio?");
v3 = -1;
}
}
}
else
{
puts("Unknown group");
v3 = -1;
}
}
}
}
}
else
{
func7(*argv);
v3 = -1;
}
return v3;
}

original_code:
int main(int argc, char **argv)
{
 int seg, bus, slot, func;
 int ret, container, group, device, groupid, intx, unmask;
 char path[50], iommu_group_path[50], *group_name;
 struct stat st;
 ssize_t len;
 struct vfio_group_status group_status = {
  .argsz = sizeof(group_status)
 };
 struct vfio_device_info device_info = {
  .argsz = sizeof(device_info)
 };
 struct vfio_irq_info irq_info = {
  .argsz = sizeof(irq_info),
  .index = VFIO_PCI_INTX_IRQ_INDEX
 };
 struct vfio_irq_set *irq_set;
 int32_t *pfd;
 if (argc != 2) {
  usage(argv[0]);
  return -1;
 }
 ret = sscanf(argv[1], "%04x:%02x:%02x.%d", &seg, &bus, &slot, &func);
 if (ret != 4) {
  usage(argv[0]);
  return -1;
 }
 container = open("/dev/vfio/vfio", 02);
 if (container < 0) {
  printf("Failed to open /dev/vfio/vfio, %d (%s)\n",
         container, strerror((*__errno_location ())));
  return container;
 }
 snprintf(path, sizeof(path),
   "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/",
   seg, bus, slot, func);
 ret = stat(path, &st);
 if (ret < 0) {
  printf("No such device\n");
  return ret;
 }
 strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1);
 len = readlink(path, iommu_group_path, sizeof(iommu_group_path));
 if (len <= 0) {
  printf("No iommu_group for device\n");
  return -1;
 }
 iommu_group_path[len] = 0;
 group_name = __xpg_basename(iommu_group_path);
 if (sscanf(group_name, "%d", &groupid) != 1) {
  printf("Unknown group\n");
  return -1;
 }
 snprintf(path, sizeof(path), "/dev/vfio/%d", groupid);
 group = open(path, 02);
 if (group < 0) {
  printf("Failed to open %s, %d (%s)\n",
         path, group, strerror((*__errno_location ())));
  return group;
 }
 ret = ioctl(group, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 3)) << 0) | ((0) << ((0 +8)+8))), &group_status);
 if (ret) {
  printf("ioctl(VFIO_GROUP_GET_STATUS) failed\n");
  return ret;
 }
 if (!(group_status.flags & (1 << 0))) {
  printf("Group not viable, are all devices attached to vfio?\n");
  return -1;
 }
 ret = ioctl(group, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 4)) << 0) | ((0) << ((0 +8)+8))), &container);
 if (ret) {
  printf("Failed to set group container\n");
  return ret;
 }
 ret = ioctl(container, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 2)) << 0) | ((0) << ((0 +8)+8))), 1);
 if (ret) {
  printf("Failed to set IOMMU\n");
  return ret;
 }
 close(container);
 snprintf(path, sizeof(path), "THIS-IS-NOT-THE-RIGHT-NAME");
        for (;;) {
  device = ioctl(group, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 6)) << 0) | ((0) << ((0 +8)+8))), path);
  if (device >= 0) {
   printf("Got a device named \"%s\"???\n", path);
   break;
  }
 }
 close(group);
 close(device);
 return -1;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int seg; int bus; int slot; int func;
 int ret; int container; int group; int device; int groupid; int intx; int unmask;
 char path[50]; char iommu_group_path[50]; char *group_name;
 struct stat st;
 long len;
 struct vfio_group_status group_status = {
  .argsz = sizeof(group_status)
 };
 struct vfio_device_info device_info = {
  .argsz = sizeof(device_info)
 };
 struct vfio_irq_info irq_info = {
  .argsz = sizeof(irq_info),
  .index = VFIO_PCI_INTX_IRQ_INDEX
 };
 struct vfio_irq_set *irq_set;
 int *pfd;
 if (argc != 2) {
  usage(argv[0]);
  return -1;
 }
 ret = sscanf(argv[1], "%04x:%02x:%02x.%d", &seg, &bus, &slot, &func);
 if (ret != 4) {
  usage(argv[0]);
  return -1;
 }
 container = open("/dev/vfio/vfio", 02);
 if (container < 0) {
  printf("Failed to open /dev/vfio/vfio, %d (%s)\n",
         container, strerror((*__errno_location ())));
  return container;
 }
 snprintf(path, sizeof(path),
   "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/",
   seg, bus, slot, func);
 ret = stat(path, &st);
 if (ret < 0) {
  printf("No such device\n");
  return ret;
 }
 strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1);
 len = readlink(path, iommu_group_path, sizeof(iommu_group_path));
 if (len <= 0) {
  printf("No iommu_group for device\n");
  return -1;
 }
 iommu_group_path[len] = 0;
 group_name = __xpg_basename(iommu_group_path);
 if (sscanf(group_name, "%d", &groupid) != 1) {
  printf("Unknown group\n");
  return -1;
 }
 snprintf(path, sizeof(path), "/dev/vfio/%d", groupid);
 group = open(path, 02);
 if (group < 0) {
  printf("Failed to open %s, %d (%s)\n",
         path, group, strerror((*__errno_location ())));
  return group;
 }
 ret = ioctl(group, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 3)) << 0) | ((0) << ((0 +8)+8))), &group_status);
 if (ret) {
  printf("ioctl(VFIO_GROUP_GET_STATUS) failed\n");
  return ret;
 }
 if (!(group_status.flags & (1 << 0))) {
  printf("Group not viable, are all devices attached to vfio?\n");
  return -1;
 }
 ret = ioctl(group, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 4)) << 0) | ((0) << ((0 +8)+8))), &container);
 if (ret) {
  printf("Failed to set group container\n");
  return ret;
 }
 ret = ioctl(container, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 2)) << 0) | ((0) << ((0 +8)+8))), 1);
 if (ret) {
  printf("Failed to set IOMMU\n");
  return ret;
 }
 close(container);
 snprintf(path, sizeof(path), "THIS-IS-NOT-THE-RIGHT-NAME");
        for (;;) {
  device = ioctl(group, (((0U) << (((0 +8)+8)+14)) | ((((';'))) << (0 +8)) | (((100 + 6)) << 0) | ((0) << ((0 +8)+8))), path);
  if (device >= 0) {
   printf("Got a device named \"%s\"???\n", path);
   break;
  }
 }
 close(group);
 close(device);
 return -1;
}

variable_types: seg int

variable_types: bus int

variable_types: slot int

variable_types: func int

variable_types: ret int

variable_types: container int

variable_types: group int

variable_types: device int

variable_types: groupid int

variable_types: intx int

variable_types: unmask int

variable_types:
path
char [50]

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

variable_types: len long

variable_types: struct vfio_group_status { unsigned int argsz; unsigned int flags; }

variable_types: struct vfio_device_info { unsigned int argsz; unsigned int flags; unsigned int num_regions; unsigned int num_irqs; }

variable_types: struct vfio_irq_info { unsigned int argsz; unsigned int flags; unsigned int index; unsigned int count; }

variable_types: struct vfio_irq_set { unsigned int argsz; unsigned int flags; unsigned int index; unsigned int start; unsigned int count; unsigned char data[]; } *

variable_types:
pfd
int *

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
const char *v4; // rbx
char *const *v5; // r12
__int64 j; // rax
int v7; // er13
int k; // ebx
int *v10; // rax
char *v11; // rax
int fd; // [rsp+4h] [rbp-34h]
int v13; // [rsp+8h] [rbp-30h]
int v14; // [rsp+Ch] [rbp-2Ch]

v13 = -1;
v14 = -1;
if ( argc <= 5 )
{
fprintf(stderr, "Usage: %s stdin# stdout# stderr# chdir program [argv0 ... ]\n", *argv);
}
else
{
fd = atoi(argv[1]);
v13 = atoi(argv[2]);
v14 = atoi(argv[3]);
for ( i = 0LL; i != 3; ++i )
{
if ( dup2(*(&fd + i), i) == -1 )
{
fwrite("Error in dup2\n", 1uLL, 0xEuLL, stderr);
return -1;
}
}
v4 = argv[4];
if ( strlen(v4) == 1 && *v4 == 46 || !chdir(v4) )
{
v5 = (char *const *)malloc(8LL * (argc - 4));
for ( j = 5LL; j != argc; ++j )
v5[j - 5] = (char *const)argv[j];
v5[argc - 5] = 0LL;
v7 = sysconf(4);
if ( v7 > 3 )
{
for ( k = 3; k != v7; ++k )
fcntl(k, 2, 1LL);
}
if ( execvp(argv[5], v5) == -1 )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Error: %s\n", v11);
}
}
else
{
fwrite("Error in chdir()\n", 1uLL, 0x11uLL, stderr);
}
}
return -1;
}

original_code:
int main(int argc, char ** argv)
{
    int fds_map[3] = {-1, -1, -1};
    int i;
    char ** new_argv;
    int open_max;
    int open_index;
    if (argc < 6) {
        fprintf(stderr, "Usage: %s stdin# stdout# stderr# chdir program [argv0 ... ]\n",
                argv[0]);
        return -1;
    }
    fds_map[0] = atoi(argv[1]);
    fds_map[1] = atoi(argv[2]);
    fds_map[2] = atoi(argv[3]);
    for (i = 0; i < 3; i++) {
        if (dup2(fds_map[i], i) == -1) {
            fprintf(stderr, "Error in dup2\n");
            return -1;
        }
    }
    if (!(strlen(argv[4]) == 1 && strncmp(argv[4], ".", 1) == 0)) {
        if (chdir(argv[4]) != 0) {
            fprintf(stderr, "Error in chdir()\n");
            return -1;
        }
    }
    new_argv = (char **)malloc(sizeof(char *) * (argc - 4));
    for (i = 5; i < argc; i++) {
        new_argv[i - 5] = argv[i];
    }
    new_argv[argc - 5] = ((void *)0);
    open_max = sysconf(_SC_OPEN_MAX);
    for(open_index=3;open_index < open_max; open_index++) {
     fcntl(open_index, 2, 1);
    }
    if (execvp(argv[5], new_argv) == -1) {
        fprintf(stderr, "Error: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return -1;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int fds_map[3] = {-1, -1, -1};
    int i;
    char **new_argv;
    int open_max;
    int open_index;
    if (argc < 6) {
        fprintf(stderr, "Usage: %s stdin# stdout# stderr# chdir program [argv0 ... ]\n",
                argv[0]);
        return -1;
    }
    fds_map[0] = atoi(argv[1]);
    fds_map[1] = atoi(argv[2]);
    fds_map[2] = atoi(argv[3]);
    for (i = 0; i < 3; i++) {
        if (dup2(fds_map[i], i) == -1) {
            fprintf(stderr, "Error in dup2\n");
            return -1;
        }
    }
    if (!(strlen(argv[4]) == 1 && strncmp(argv[4], ".", 1) == 0)) {
        if (chdir(argv[4]) != 0) {
            fprintf(stderr, "Error in chdir()\n");
            return -1;
        }
    }
    new_argv = (char **)malloc(sizeof(char *) * (argc - 4));
    for (i = 5; i < argc; i++) {
        new_argv[i - 5] = argv[i];
    }
    new_argv[argc - 5] = ((void *)0);
    open_max = sysconf(_SC_OPEN_MAX);
    for(open_index=3;open_index < open_max; open_index++) {
     fcntl(open_index, 2, 1);
    }
    if (execvp(argv[5], new_argv) == -1) {
        fprintf(stderr, "Error: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return -1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int


repo: azat/chunkfs

decompiled_code:
__int64 __fastcall create_pool_summary(char *src, __int64 a2)
{
__int64 result; // rax

strcpy((char *)(a2 + 16), src);
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 1040) = 0LL;
result = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 1048) >> 3));
*(_DWORD *)a2 = 1526618878;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *src, __int64 a2)
{
__int64 result; // rax

strcpy((char *)(a2 + 16), src);
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 1040) = 0LL;
result = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 1048) >> 3));
*(_DWORD *)a2 = 1526618878;
return result;
}

original_code:
static void create_pool_summary(char *dev_name, struct chunkfs_pool *pool)
{
 struct chunkfs_dev_desc *dev_desc = &pool->p_root_desc;
 strcpy(dev_desc->d_hint, dev_name);
 dev_desc->d_uuid = ((__le64)(__u64)(0x001d001d));
 bzero(pool, sizeof(*pool));
 pool->p_magic = ((__le32)(__u32)(0x5afe5afe));
}

variable_types: struct chunkfs_pool { unsigned int p_magic; unsigned int p_chksum; unsigned long long p_flags; struct chunkfs_dev_desc { char d_hint[1024]; unsigned long long d_uuid; } p_root_desc; } *

variable_types: struct chunkfs_dev_desc { char d_hint[1024]; unsigned long long d_uuid; } *

user_defined_types: struct chunkfs_pool { unsigned int p_magic; unsigned int p_chksum; unsigned long long p_flags; struct chunkfs_dev_desc p_root_desc; }


decompiled_code:
ssize_t __fastcall write_block(void *src, int a2, int a3, __off_t a4)
{
ssize_t result; // rax
int *v7; // rax
int *v8; // rax
int vars0[1034]; // [rsp+0h] [rbp+0h] BYREF

memset(vars0, 0, 0x1000uLL);
memcpy(vars0, src, a2);
write_chksum((__int64)vars0);
printf("Writing magic %0x chksum %0x to offset %llu\n", (unsigned int)vars0[0], (unsigned int)vars0[1], a4);
if ( lseek(a3, a4, 0) < 0 )
{
v7 = __errno_location();
error(1, *v7, "Cannot seek");
goto LABEL_5;
}
result = write(a3, vars0, 0x1000uLL);
if ( result <= 4095 )
{
LABEL_5:
v8 = __errno_location();
error(1, *v8, "Cannot write metadata at offset %llu", a4);
result = write_chunk_summaries();
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func12(void *src, int a2, int a3, __off_t a4)
{
ssize_t result; // rax
int *v7; // rax
int *v8; // rax
int vars0[1034]; // [rsp+0h] [rbp+0h] BYREF

memset(vars0, 0, 0x1000uLL);
memcpy(vars0, src, a2);
func7((__int64)vars0);
printf("Writing magic %0x chksum %0x to offset %llu\n", (unsigned int)vars0[0], (unsigned int)vars0[1], a4);
if ( lseek(a3, a4, 0) < 0 )
{
v7 = __errno_location();
error(1, *v7, "Cannot seek");
goto LABEL_5;
}
result = write(a3, vars0, 0x1000uLL);
if ( result <= 4095 )
{
LABEL_5:
v8 = __errno_location();
error(1, *v8, "Cannot write metadata at offset %llu", a4);
result = func13();
}
return result;
}

original_code:
static void write_block(void *metadata, int size, int fd, __u64 offset)
{
 char buf[4096];
 int buf_size = sizeof (buf);
 struct chunkfs_chkmagic *x = (struct chunkfs_chkmagic *) buf;
 bzero(buf, buf_size);
 memcpy(buf, metadata, size);
 write_chksum(buf, size);
 printf("Writing magic %0x chksum %0x to offset %llu\n",
        ((__u32)(__le32)(x->x_magic)), ((__u32)(__le32)(x->x_chksum)),
        offset);
 if (lseek(fd, offset, 0) < 0)
  error(1, (*__errno_location ()), "Cannot seek");
 if (write(fd, buf, buf_size) < buf_size)
  error(1, (*__errno_location ()), "Cannot write metadata at offset %llu",
        (unsigned long long) offset);
}

canonical_original_code:
static void write_block(void *metadata, int size, int fd, unsigned long long offset)
{
 char buf[4096];
 int buf_size = sizeof (buf);
 struct chunkfs_chkmagic *x = (struct chunkfs_chkmagic *) buf;
 bzero(buf, buf_size);
 memcpy(buf, metadata, size);
 write_chksum(buf, size);
 printf("Writing magic %0x chksum %0x to offset %llu\n",
        ((__u32)(__le32)(x->x_magic)), ((__u32)(__le32)(x->x_chksum)),
        offset);
 if (lseek(fd, offset, 0) < 0)
  error(1, (*__errno_location ()), "Cannot seek");
 if (write(fd, buf, buf_size) < buf_size)
  error(1, (*__errno_location ()), "Cannot write metadata at offset %llu",
        (unsigned long long) offset);
}

variable_types:
metadata
void *

variable_types: size int

variable_types: fd int

variable_types:
offset
unsigned long long

variable_types:
buf
char [4096]

variable_types: struct chunkfs_chkmagic { unsigned int x_magic; unsigned int x_chksum; } *


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "Usage: %s <device>\n", (const char *)cmd);
_exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
fprintf(stderr, "Usage: %s <device>\n", (const char *)cmd);
_exit(1);
}

original_code:
static void usage (void)
{
 fprintf(stderr, "Usage: %s <device>\n", cmd);
 _exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "Usage: %s <device>\n", cmd);
 _exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
int v5; // ebx
__off_t v6; // rbp
int result; // eax
int *v8; // rax
int *v9; // rax
_QWORD v10[12]; // [rsp+0h] [rbp-978h] BYREF
_QWORD v11[138]; // [rsp+60h] [rbp-918h] BYREF
char src[1056]; // [rsp+4B0h] [rbp-4C8h] BYREF
struct stat stat_buf; // [rsp+8D0h] [rbp-A8h] BYREF

memset(src, 0, 0x418uLL);
memset(v11, 0, 0x448uLL);
memset(v10, 0, sizeof(v10));
cmd = (__int64)*argv;
if ( argc != 2 )
usage();
v3 = (char *)argv[1];
v4 = open(v3, 2);
v5 = v4;
if ( v4 < 0 )
{
v8 = __errno_location();
error(1, *v8, "Cannot open device %s", v3);
}
else if ( !(unsigned int)fstat(v4, &stat_buf) )
{
v6 = stat_buf.st_size;
create_pool_summary(v3, (__int64)src);
write_block(src, 1048, v5, 0x8000LL);
create_dev_summary((__int64)src, v11, 36864LL, v6 - 36865);
write_block(v11, 1096, v5, 36864LL);
write_chunk_summaries((__int64)v11, v10, v5);
close(v5);
return 0;
}
v9 = __errno_location();
error(1, *v9, "Cannot stat device %s", v3);
_libc_csu_init();
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
int v5; // ebx
__off_t v6; // rbp
int result; // eax
int *v8; // rax
int *v9; // rax
_QWORD v10[12]; // [rsp+0h] [rbp-978h] BYREF
_QWORD v11[138]; // [rsp+60h] [rbp-918h] BYREF
char src[1056]; // [rsp+4B0h] [rbp-4C8h] BYREF
struct stat stat_buf; // [rsp+8D0h] [rbp-A8h] BYREF

memset(src, 0, 0x418uLL);
memset(v11, 0, 0x448uLL);
memset(v10, 0, sizeof(v10));
cmd = (__int64)*argv;
if ( argc != 2 )
func8();
v3 = (char *)argv[1];
v4 = open(v3, 2);
v5 = v4;
if ( v4 < 0 )
{
v8 = __errno_location();
error(1, *v8, "Cannot open device %s", v3);
}
else if ( !(unsigned int)func16(v4, &stat_buf) )
{
v6 = stat_buf.st_size;
func9(v3, (__int64)src);
func12(src, 1048, v5, 0x8000LL);
func10((__int64)src, v11, 36864LL, v6 - 36865);
func12(v11, 1096, v5, 36864LL);
func13((__int64)v11, v10, v5);
close(v5);
return 0;
}
v9 = __errno_location();
error(1, *v9, "Cannot stat device %s", v3);
func14();
return result;
}

original_code:
int main (int argc, char * argv[])
{
 int fd;
 char * dev_name;
 struct stat stat_buf;
 off_t raw_dev_size;
 struct chunkfs_pool pool = { 0 };
 struct chunkfs_dev root_dev = { 0 };
 struct chunkfs_chunk root_chunk = { 0 };
 cmd = argv[0];
 if (argc != 2)
  usage();
 dev_name = argv[1];
 if ((fd = open(dev_name, 02)) < 0)
  error(1, (*__errno_location ()), "Cannot open device %s", dev_name);
 if (fstat(fd, &stat_buf) != 0)
  error(1, (*__errno_location ()), "Cannot stat device %s", dev_name);
 raw_dev_size = stat_buf.st_size;
 create_pool_summary(dev_name, &pool);
 write_block(&pool, sizeof(pool), fd, (8 * 4096));
 create_dev_summary(&pool, &root_dev, ((8 + 1) * 4096),
      raw_dev_size - ((8 + 1) * 4096) - 1);
 write_block(&root_dev, sizeof(root_dev), fd, ((8 + 1) * 4096));
 write_chunk_summaries(&root_dev, &root_chunk, fd);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd;
 char *dev_name;
 struct stat stat_buf;
 long raw_dev_size;
 struct chunkfs_pool pool = { 0 };
 struct chunkfs_dev root_dev = { 0 };
 struct chunkfs_chunk root_chunk = { 0 };
 cmd = argv[0];
 if (argc != 2)
  usage();
 dev_name = argv[1];
 if ((fd = open(dev_name, 02)) < 0)
  error(1, (*__errno_location ()), "Cannot open device %s", dev_name);
 if (fstat(fd, &stat_buf) != 0)
  error(1, (*__errno_location ()), "Cannot stat device %s", dev_name);
 raw_dev_size = stat_buf.st_size;
 create_pool_summary(dev_name, &pool);
 write_block(&pool, sizeof(pool), fd, (8 * 4096));
 create_dev_summary(&pool, &root_dev, ((8 + 1) * 4096),
      raw_dev_size - ((8 + 1) * 4096) - 1);
 write_block(&root_dev, sizeof(root_dev), fd, ((8 + 1) * 4096));
 write_chunk_summaries(&root_dev, &root_chunk, fd);
 close(fd);
 return 0;
}

variable_types:
argv
char *[]

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

variable_types: struct chunkfs_pool { unsigned int p_magic; unsigned int p_chksum; unsigned long long p_flags; struct chunkfs_dev_desc { char d_hint[1024]; unsigned long long d_uuid; } p_root_desc; }

variable_types: struct chunkfs_dev { unsigned int d_magic; unsigned int d_chksum; unsigned long long d_flags; unsigned long long d_uuid; unsigned long long d_begin; unsigned long long d_end; unsigned long long d_innards_begin; unsigned long long d_innards_end; unsigned long long d_root_chunk; struct chunkfs_dev_desc { char d_hint[1024]; unsigned long long d_uuid; } d_next_dev; }

variable_types: struct chunkfs_chunk { unsigned int c_magic; unsigned int c_chksum; unsigned long long c_flags; unsigned long long c_chunk_id; unsigned long long c_begin; unsigned long long c_end; unsigned long long c_innards_begin; unsigned long long c_innards_end; unsigned long long c_next_chunk; char c_client_fs[32]; }

user_defined_types: struct chunkfs_dev { unsigned int d_magic; unsigned int d_chksum; unsigned long long d_flags; unsigned long long d_uuid; unsigned long long d_begin; unsigned long long d_end; unsigned long long d_innards_begin; unsigned long long d_innards_end; unsigned long long d_root_chunk; struct chunkfs_dev_desc d_next_dev; }


SigCatcher

decompiled_code:
void SigCatcher()
{
kill(readPid, 15);
kill(writePid, 15);
wait3(0LL, 1, 0LL);
signal(17, SigCatcher);
}

canonical_decompiled_code:
void func7()
{
kill(readPid, 15);
kill(writePid, 15);
wait3(0LL, 1, 0LL);
signal(17, SigCatcher);
}

original_code:
void
SigCatcher (int n)
{
 kill( readPid, 15 );
 kill( writePid, 15 );
 wait3 (((void *)0), 1, ((void *)0));
 signal (17, SigCatcher);
}

canonical_original_code:
void SigCatcher(int n)
{
 kill( readPid, 15 );
 kill( writePid, 15 );
 wait3 (((void *)0), 1, ((void *)0));
 signal (17, SigCatcher);
}

variable_types: n int