DoFit

decompiled_code:
__int64 __fastcall DoFit(int a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 v8; // rax
__int64 v11; // rbx
__int64 v12; // rdi
double v13; // xmm0_8
__int64 v14; // rdx
__int64 result; // rax
double v16; // xmm2_8
double v17; // xmm1_8
__int64 i; // rax
double v19; // [rsp+0h] [rbp-138A8h] BYREF
double v20; // [rsp+8h] [rbp-138A0h] BYREF
double v21[5000]; // [rsp+10h] [rbp-13898h] BYREF
__int64 v22[5003]; // [rsp+9C50h] [rbp-9C58h] BYREF

if ( a1 <= 0 )
return 1LL;
v8 = 0LL;
v11 = a1;
v12 = 0LL;
do
{
v13 = *(double *)(a2 + 8 * v8);
if ( v13 > a5 && a6 > v13 )
{
v14 = (int)v12;
v12 = (unsigned int)(v12 + 1);
v21[v14] = v13;
v22[v14] = *(_QWORD *)(a3 + 8 * v8);
}
++v8;
}
while ( v11 != v8 );
result = 1LL;
if ( (int)v12 > 2 )
{
if ( (unsigned int)linear_fit(v12, v21, v22, &v19, &v20) )
puts("Error in linear regression routine");
v16 = v20;
v17 = v19;
for ( i = 0LL; i != v11; ++i )
*(double *)(a4 + 8 * i) = *(double *)(a2 + 8 * i) * v16 + v17;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 v8; // rax
__int64 v11; // rbx
__int64 v12; // rdi
double v13; // xmm0_8
__int64 v14; // rdx
__int64 result; // rax
double v16; // xmm2_8
double v17; // xmm1_8
__int64 i; // rax
double v19; // [rsp+0h] [rbp-138A8h] BYREF
double v20; // [rsp+8h] [rbp-138A0h] BYREF
double v21[5000]; // [rsp+10h] [rbp-13898h] BYREF
__int64 v22[5003]; // [rsp+9C50h] [rbp-9C58h] BYREF

if ( a1 <= 0 )
return 1LL;
v8 = 0LL;
v11 = a1;
v12 = 0LL;
do
{
v13 = *(double *)(a2 + 8 * v8);
if ( v13 > a5 && a6 > v13 )
{
v14 = (int)v12;
v12 = (unsigned int)(v12 + 1);
v21[v14] = v13;
v22[v14] = *(_QWORD *)(a3 + 8 * v8);
}
++v8;
}
while ( v11 != v8 );
result = 1LL;
if ( (int)v12 > 2 )
{
if ( (unsigned int)linear_fit(v12, v21, v22, &v19, &v20) )
puts("Error in linear regression routine");
v16 = v20;
v17 = v19;
for ( i = 0LL; i != v11; ++i )
*(double *)(a4 + 8 * i) = *(double *)(a2 + 8 * i) * v16 + v17;
result = 0LL;
}
return result;
}

original_code:
int DoFit(int nDataPoints, double *fX, double *fY, double *fFit, double x1, double x2 )
{
  double fXtemp[5000], fYtemp[5000];
  double fC, fM;
  int err, i, j = 0;
  for (i = 0; i < nDataPoints; i++) {
     if(fX[i] > x1 && fX[i] < x2) {
 fXtemp[j] = fX[i];
 fYtemp[j] = fY[i];
  j++;
     }
  }
  if(j < 3){
     return 1;
  }
  if(linear_fit(j, fXtemp, fYtemp, &fC, &fM) != 0){
     printf("Error in linear regression routine\n");
  }
  for (i = 0; i < nDataPoints; i++) {
     fFit[i] = fC + fM * fX[i];
  }
  return 0;
}

canonical_original_code:
int DoFit(int nDataPoints, double *fX, double *fY, double *fFit, double x1, double x2)
{
  double fXtemp[5000]; double fYtemp[5000];
  double fC; double fM;
  int err; int i; int j = 0;
  for (i = 0; i < nDataPoints; i++) {
     if(fX[i] > x1 && fX[i] < x2) {
 fXtemp[j] = fX[i];
 fYtemp[j] = fY[i];
  j++;
     }
  }
  if(j < 3){
     return 1;
  }
  if(linear_fit(j, fXtemp, fYtemp, &fC, &fM) != 0){
     printf("Error in linear regression routine\n");
  }
  for (i = 0; i < nDataPoints; i++) {
     fFit[i] = fC + fM * fX[i];
  }
  return 0;
}

variable_types: nDataPoints int

variable_types:
fX
double *

variable_types:
fY
double *

variable_types:
fFit
double *

variable_types:
fXtemp
double [5000]

variable_types:
fYtemp
double [5000]

variable_types: fC double

variable_types: fM double

variable_types: err int

variable_types: j int


normalize

repo: mxcube/pychooch

decompiled_code:
__int64 __fastcall normalize(int a1, double *a2, double *a3, __int64 a4, unsigned int a5, double *a6, double a7, double *a8)
{
double v8; // xmm2_8
double v12; // xmm3_8
double v13; // xmm1_8
__int64 v14; // rax
double v16; // [rsp+0h] [rbp-40h]

v8 = a7;
if ( verbose > 0 )
{
printf(" Plot switch: %d\n", a5);
v8 = a7;
}
v12 = fE1;
if ( fE1 == 0.0 )
{
v12 = *a2;
fE1 = *(_QWORD *)a2;
}
if ( fE2 == 0.0 )
fE2 = v8 - 20.0;
if ( fE3 == 0.0 )
fE3 = v8 + 25.0;
if ( fE4 == 0.0 )
fE4 = *(_QWORD *)&a2[a1 - 1];
if ( v8 - v12 <= 30.0 )
{
v16 = v8;
LABEL_24:
SetConst(a1, a8, *a3);
v8 = v16;
goto LABEL_15;
}
if ( verbose > 1 )
{
puts("Using linear fit to below edge region");
v12 = fE1;
}
v16 = v8;
if ( (unsigned int)DoFit(a1, (__int64)a2, (__int64)a3, (__int64)a8, v12, fE2) == 1 )
goto LABEL_24;
LABEL_15:
v13 = fE4;
if ( fE4 - v8 <= 30.0 )
goto LABEL_22;
if ( verbose > 1 )
{
puts("Using linear fit to above edge region");
v13 = fE4;
}
if ( (unsigned int)DoFit(a1, (__int64)a2, (__int64)a3, (__int64)a6, fE3, v13) == 1 )
LABEL_22:
SetConst(a1, a6, a3[a1 - 1]);
v14 = 0LL;
if ( a1 > 0 )
{
do
{
*(double *)(a4 + 8 * v14) = (a3[v14] - a8[v14]) / (a6[v14] - a8[v14]);
++v14;
}
while ( a1 != v14 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, double *a2, double *a3, __int64 a4, unsigned int a5, double *a6, double a7, double *a8)
{
double v8; // xmm2_8
double v12; // xmm3_8
double v13; // xmm1_8
__int64 v14; // rax
double v16; // [rsp+0h] [rbp-40h]

v8 = a7;
if ( verbose > 0 )
{
printf(" Plot switch: %d\n", a5);
v8 = a7;
}
v12 = fE1;
if ( fE1 == 0.0 )
{
v12 = *a2;
fE1 = *(_QWORD *)a2;
}
if ( fE2 == 0.0 )
fE2 = v8 - 20.0;
if ( fE3 == 0.0 )
fE3 = v8 + 25.0;
if ( fE4 == 0.0 )
fE4 = *(_QWORD *)&a2[a1 - 1];
if ( v8 - v12 <= 30.0 )
{
v16 = v8;
LABEL_24:
func0(a1, a8, *a3);
v8 = v16;
goto LABEL_15;
}
if ( verbose > 1 )
{
puts("Using linear fit to below edge region");
v12 = fE1;
}
v16 = v8;
if ( (unsigned int)func1(a1, (__int64)a2, (__int64)a3, (__int64)a8, v12, fE2) == 1 )
goto LABEL_24;
LABEL_15:
v13 = fE4;
if ( fE4 - v8 <= 30.0 )
goto LABEL_22;
if ( verbose > 1 )
{
puts("Using linear fit to above edge region");
v13 = fE4;
}
if ( (unsigned int)func1(a1, (__int64)a2, (__int64)a3, (__int64)a6, fE3, v13) == 1 )
LABEL_22:
func0(a1, a6, a3[a1 - 1]);
v14 = 0LL;
if ( a1 > 0 )
{
do
{
*(double *)(a4 + 8 * v14) = (a3[v14] - a8[v14]) / (a6[v14] - a8[v14]);
++v14;
}
while ( a1 != v14 );
}
return 0LL;
}

original_code:
int normalize(int nDataPoints, double fEdge, double *fXraw, double *fYraw, double *fYnorm, int plotX, double *fYfita, double *fYfitb)
{
  extern int verbose;
  int i, j, nFit, err;
  double fXtemp[5000], fYtemp[5000];
  double fC, fM;
  char label[10];
  if(verbose>0)printf(" Plot switch:   %d\n", plotX);
  if(fE1==0.0)fE1=fXraw[0];
  if(fE2==0.0)fE2=fEdge-20.0;
  if(fE3==0.0)fE3=fEdge+25.0;
  if(fE4==0.0)fE4=fXraw[nDataPoints-1];
  if((fEdge-fE1) > 30.0) {
     if(verbose>1)printf("Using linear fit to below edge region\n");
     if(DoFit(nDataPoints, fXraw, fYraw, fYfitb, fE1, fE2) == 1){
 SetConst(nDataPoints, fYraw[0], fYfitb);
     }
  } else {
     SetConst(nDataPoints, fYraw[0], fYfitb);
  }
  if((fE4-fEdge) > 30.0) {
     if(verbose>1)printf("Using linear fit to above edge region\n");
     if(DoFit(nDataPoints, fXraw, fYraw, fYfita, fE3, fE4) == 1){
 SetConst(nDataPoints, fYraw[nDataPoints-1], fYfita);
     }
  } else {
     SetConst(nDataPoints, fYraw[nDataPoints-1], fYfita);
  }
  for (i = 0; i < nDataPoints; i++) {
     fYnorm[i] = (fYraw[i] - fYfitb[i]) / (fYfita[i] - fYfitb[i]);
  }
  return 0;
}

canonical_original_code:
int normalize(int nDataPoints, double fEdge, double *fXraw, double *fYraw, double *fYnorm, int plotX, double *fYfita, double *fYfitb)
{
  extern int verbose;
  int i; int j; int nFit; int err;
  double fXtemp[5000]; double fYtemp[5000];
  double fC; double fM;
  char label[10];
  if(verbose>0)printf(" Plot switch:   %d\n", plotX);
  if(fE1==0.0)fE1=fXraw[0];
  if(fE2==0.0)fE2=fEdge-20.0;
  if(fE3==0.0)fE3=fEdge+25.0;
  if(fE4==0.0)fE4=fXraw[nDataPoints-1];
  if((fEdge-fE1) > 30.0) {
     if(verbose>1)printf("Using linear fit to below edge region\n");
     if(DoFit(nDataPoints, fXraw, fYraw, fYfitb, fE1, fE2) == 1){
 SetConst(nDataPoints, fYraw[0], fYfitb);
     }
  } else {
     SetConst(nDataPoints, fYraw[0], fYfitb);
  }
  if((fE4-fEdge) > 30.0) {
     if(verbose>1)printf("Using linear fit to above edge region\n");
     if(DoFit(nDataPoints, fXraw, fYraw, fYfita, fE3, fE4) == 1){
 SetConst(nDataPoints, fYraw[nDataPoints-1], fYfita);
     }
  } else {
     SetConst(nDataPoints, fYraw[nDataPoints-1], fYfita);
  }
  for (i = 0; i < nDataPoints; i++) {
     fYnorm[i] = (fYraw[i] - fYfitb[i]) / (fYfita[i] - fYfitb[i]);
  }
  return 0;
}

variable_types: fEdge double

variable_types:
fXraw
double *

variable_types:
fYraw
double *

variable_types:
fYnorm
double *

variable_types: plotX int

variable_types:
fYfita
double *

variable_types:
fYfitb
double *

variable_types: verbose int

variable_types: i int

variable_types: nFit int

variable_types:
label
char [10]

return_type: int


impose

original_code:
int impose(int nDataPoints, double fEdge, double *fXraw, double *fYnorm, double *fYfpp)
{
  extern int verbose;
  int i, nFit, err;
  double fXtemp[5000], fYtemp[5000];
  double fYfita[5000], fYfitb[5000];
  double C[3];
  char label[10];
  for(i=0; i<50; i++){
    fXtemp[i] = fEdge-60+(float)i;
    fYtemp[i] = get_fpp(sElement, fXtemp[i]/1000.0);
  }
  nFit = i-2;
  err = quadfit(nFit, fXtemp, fYtemp, C);
  if(verbose>1)printf("# best qaud fit: Y = %g + %g X + %g X^2\n", C[0], C[1], C[2]);
  for (i = 0; i < nDataPoints; i++) {
    fYfitb[i] = C[0] + C[1] * fXraw[i] + C[2] * fXraw[i] * fXraw[i];
  }
  for (i = 0; i < 50; i++) {
     fXtemp[i] = fEdge+10+(float)i;
     fYtemp[i] = get_fpp(sElement, fXtemp[i]/1000.0);
  }
  nFit = i-2;
  err = quadfit(nFit, fXtemp, fYtemp, C);
  if(verbose>1)printf("# best quad fit: Y = %g + %g X + %g X^2\n", C[0], C[1], C[2]);
  for (i = 0; i < nDataPoints; i++) {
    fYfita[i] = C[0] + C[1] * fXraw[i] + C[2] * fXraw[i] * fXraw[i];
  }
  for (i = 0; i < nDataPoints; i++) {
    fYfpp[i] = (fYnorm[i] * (fYfita[i] - fYfitb[i])) + fYfitb[i];
    if(verbose>1) printf("%d %10.4f %10.4f %10.4f %10.4f \n", i, fYfpp[i], fYnorm[i], fYfita[i], fYfitb[i]);
  }
  return 0;
}

canonical_original_code:
int impose(int nDataPoints, double fEdge, double *fXraw, double *fYnorm, double *fYfpp)
{
  extern int verbose;
  int i; int nFit; int err;
  double fXtemp[5000]; double fYtemp[5000];
  double fYfita[5000]; double fYfitb[5000];
  double C[3];
  char label[10];
  for(i=0; i<50; i++){
    fXtemp[i] = fEdge-60+(float)i;
    fYtemp[i] = get_fpp(sElement, fXtemp[i]/1000.0);
  }
  nFit = i-2;
  err = quadfit(nFit, fXtemp, fYtemp, C);
  if(verbose>1)printf("# best qaud fit: Y = %g + %g X + %g X^2\n", C[0], C[1], C[2]);
  for (i = 0; i < nDataPoints; i++) {
    fYfitb[i] = C[0] + C[1] * fXraw[i] + C[2] * fXraw[i] * fXraw[i];
  }
  for (i = 0; i < 50; i++) {
     fXtemp[i] = fEdge+10+(float)i;
     fYtemp[i] = get_fpp(sElement, fXtemp[i]/1000.0);
  }
  nFit = i-2;
  err = quadfit(nFit, fXtemp, fYtemp, C);
  if(verbose>1)printf("# best quad fit: Y = %g + %g X + %g X^2\n", C[0], C[1], C[2]);
  for (i = 0; i < nDataPoints; i++) {
    fYfita[i] = C[0] + C[1] * fXraw[i] + C[2] * fXraw[i] * fXraw[i];
  }
  for (i = 0; i < nDataPoints; i++) {
    fYfpp[i] = (fYnorm[i] * (fYfita[i] - fYfitb[i])) + fYfitb[i];
    if(verbose>1) printf("%d %10.4f %10.4f %10.4f %10.4f \n", i, fYfpp[i], fYnorm[i], fYfita[i], fYfitb[i]);
  }
  return 0;
}

variable_types: nDataPoints int

variable_types:
fYfpp
double *

variable_types:
fXtemp
double [5000]

variable_types:
fYfita
double [5000]

variable_types:
fYfitb
double [5000]

variable_types:
C
double [3]


pad

decompiled_code:
float *__fastcall pad(int a1, __int64 a2, int a3, double *a4, float *a5)
{
int v8; // ebx
float *v9; // rax
float v10; // xmm0_4
float *result; // rax
float v12; // xmm0_4
__int64 v13; // rdx
float v14; // xmm0_4
__int64 v15; // rdx

v8 = a2;
if ( verbose > 0 )
puts("Padding input spectrum");
if ( (int)a2 > 0 )
{
v9 = a5;
v10 = *a4;
do
*v9++ = v10;
while ( v9 != &a5[(unsigned int)(a2 - 1) + 1] );
}
result = (float *)(unsigned int)(a2 + a1);
if ( (int)result > (int)a2 )
{
a2 = (int)a2;
do
{
v12 = a4[a2 - v8];
a5[a2++] = v12;
}
while ( (int)result > (int)a2 );
}
if ( (int)result < (int)result + a3 )
{
v13 = (int)result;
result = &a5[(int)result];
v14 = a4[a1 - 1];
v15 = (__int64)&a5[(unsigned int)(a3 - 1) + 1 + v13];
do
*result++ = v14;
while ( (float *)v15 != result );
}
return result;
}

canonical_decompiled_code:
float *__fastcall func0(int a1, __int64 a2, int a3, double *a4, float *a5)
{
int v8; // ebx
float *v9; // rax
float v10; // xmm0_4
float *result; // rax
float v12; // xmm0_4
__int64 v13; // rdx
float v14; // xmm0_4
__int64 v15; // rdx

v8 = a2;
if ( verbose > 0 )
puts("Padding input spectrum");
if ( (int)a2 > 0 )
{
v9 = a5;
v10 = *a4;
do
*v9++ = v10;
while ( v9 != &a5[(unsigned int)(a2 - 1) + 1] );
}
result = (float *)(unsigned int)(a2 + a1);
if ( (int)result > (int)a2 )
{
a2 = (int)a2;
do
{
v12 = a4[a2 - v8];
a5[a2++] = v12;
}
while ( (int)result > (int)a2 );
}
if ( (int)result < (int)result + a3 )
{
v13 = (int)result;
result = &a5[(int)result];
v14 = a4[a1 - 1];
v15 = (__int64)&a5[(unsigned int)(a3 - 1) + 1 + v13];
do
*result++ = v14;
while ( (float *)v15 != result );
}
return result;
}

original_code:
void pad(int np, int nl, int nr, double *fin, float *fout) {
  extern int verbose;
  int i;
  if(verbose>0)printf("Padding input spectrum\n");
  for (i = 0; i < nl; i++) {
    fout[i] = (float) fin[0];
  }
  for (i = nl; i < (np+nl); i++) {
    fout[i] = (float) fin[i-nl];
  }
  for (i = (np+nl); i < (nl+np+nr); i++) {
    fout[i] = (float) fin[np-1];
  }
}

variable_types: np int

variable_types: nl int

variable_types: nr int

variable_types:
fin
double *

variable_types:
fout
float *

return_type: void


original_code:
int apply_coeffs(float *fpad, double *g, float *cn, int nl, int nr, int np) {
  extern int verbose;
  int i, n;
  if(verbose>0)printf("Applying SavGol coeffs\n");
  for (i = 0; i < np; i++) {
    g[i] = 0.0;
    for (n = 0; n < (nl+nr+1); n++) {
      g[i] += (double) (cn[n] * fpad[i+n]);
    }
    if(verbose>1){
      printf("%d  %10.4f\n",i,g[i]);
    }
  }
  return 0;
}

canonical_original_code:
int apply_coeffs(float *fpad, double *g, float *cn, int nl, int nr, int np) {
  extern int verbose;
  int i; int n;
  if(verbose>0)printf("Applying SavGol coeffs\n");
  for (i = 0; i < np; i++) {
    g[i] = 0.0;
    for (n = 0; n < (nl+nr+1); n++) {
      g[i] += (double) (cn[n] * fpad[i+n]);
    }
    if(verbose>1){
      printf("%d  %10.4f\n",i,g[i]);
    }
  }
  return 0;
}

variable_types:
fpad
float *

variable_types:
g
double *

variable_types:
cn
float *

variable_types: n int


smooth

decompiled_code:
__int64 __fastcall smooth(int a1, double *a2, __int64 a3, unsigned int a4, int a5, unsigned int a6, unsigned int a7)
{
int v10; // eax
int v11; // edx
int v12; // eax
int v13; // edx
int v14; // eax
__int64 v15; // r14
_DWORD *v16; // r13
float v17; // xmm0_4
float v20[52]; // [rsp+10h] [rbp-8728h] BYREF
_DWORD dest[3584]; // [rsp+E0h] [rbp-8658h] BYREF
float v22[5014]; // [rsp+38E0h] [rbp-4E58h] BYREF

memcpy(dest, &unk_3A0, sizeof(dest));
if ( verbose > 1 )
printf("nl = %d nr = %d ld = %d m = %d\n", a4, (unsigned int)a5, a7, a6);
pad(a1, a4, a5, a2, v22);
if ( a5 <= 2 )
{
v12 = 5;
v11 = 0;
}
else
{
v10 = 20;
v11 = 0;
do
{
v11 += v10;
v10 += 8;
}
while ( 8 * a5 + 4 != v10 );
v12 = 2 * a5 + 1;
}
v13 = a7 * v12 + v11;
v14 = verbose;
if ( (int)(a5 + a4) >= 0 )
{
v15 = 0LL;
v16 = &dest[v13];
do
{
v17 = *(float *)&v16[v15];
v20[v15] = v17;
if ( v14 > 1 )
{
printf(" %5.2f", v17);
v14 = verbose;
}
++v15;
}
while ( (int)(a5 + a4) >= (int)v15 );
}
if ( v14 > 1 )
putchar(10);
apply_coeffs((__int64)v22, a3, (__int64)v20, a4, a5, a1);
if ( verbose > 0 )
puts("Done smoothing");
return 0LL;
}

variable_types:
f
double *

variable_types: m int

variable_types: ld int

variable_types: verbose int

variable_types: i int

variable_types: err int

variable_types: nc int

variable_types: index int

variable_types:
fpad
float [5000]

variable_types:
cn
float [50]

variable_types:
cdata
float []


minmax

original_code:
int minmax(int n, float *fArray, float *fMin, float *fMax)
{
   extern int verbose;
   int i;
   *fMin = 10000000;
   *fMax = -10000000;
   for (i = 0; i < n; i++) {
      *fMin = (fArray[i] < *fMin) ? fArray[i] : *fMin;
      *fMax = (fArray[i] > *fMax) ? fArray[i] : *fMax;
   }
   if(verbose>2)printf("In minmax:  %f %f\n", *fMin, *fMax);
   return 0;
}

variable_types:
fArray
float *

variable_types:
fMin
float *

variable_types:
fMax
float *


decompiled_code:
__int64 __fastcall linear_fit(int a1, __int64 a2, __int64 a3, double *a4, double *a5)
{
char *v8; // rax
double v9; // xmm0_8
double v10; // xmm1_8
bool v11; // cc
double v13; // [rsp+0h] [rbp-9CA8h] BYREF
double v14; // [rsp+8h] [rbp-9CA0h] BYREF
double v15; // [rsp+10h] [rbp-9C98h] BYREF
double v16; // [rsp+18h] [rbp-9C90h] BYREF
double v17; // [rsp+20h] [rbp-9C88h] BYREF
double v18; // [rsp+28h] [rbp-9C80h] BYREF
char v19[40056]; // [rsp+30h] [rbp-9C78h] BYREF

if ( a1 > 0 )
{
v8 = v19;
do
{
*(_QWORD *)v8 = LC0;
v8 += 8;
}
while ( v8 != &v19[8 * (a1 - 1) + 8] );
}
if ( verbose > 1 )
puts("Fitting ....");
gsl_fit_wlinear(a2, 1LL, v19, 1LL, a3, 1LL, a1, &v13, &v14, &v15, &v16, &v17, &v18);
v9 = v13;
v10 = v14;
v11 = verbose <= 1;
*a4 = v13;
*a5 = v10;
if ( !v11 )
{
printf("# best fit: Y = %g + %g X\n", v9, v10);
puts("# covariance matrix:");
printf("# [ %g, %g\n# %g, %g]\n", v15, v16, v16, v17);
printf("# chisq = %g\n", v18);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3, double *a4, double *a5)
{
char *v8; // rax
double v9; // xmm0_8
double v10; // xmm1_8
bool v11; // cc
double v13; // [rsp+0h] [rbp-9CA8h] BYREF
double v14; // [rsp+8h] [rbp-9CA0h] BYREF
double v15; // [rsp+10h] [rbp-9C98h] BYREF
double v16; // [rsp+18h] [rbp-9C90h] BYREF
double v17; // [rsp+20h] [rbp-9C88h] BYREF
double v18; // [rsp+28h] [rbp-9C80h] BYREF
char v19[40056]; // [rsp+30h] [rbp-9C78h] BYREF

if ( a1 > 0 )
{
v8 = v19;
do
{
*(_QWORD *)v8 = LC0;
v8 += 8;
}
while ( v8 != &v19[8 * (a1 - 1) + 8] );
}
if ( verbose > 1 )
puts("Fitting ....");
gsl_fit_wlinear(a2, 1LL, v19, 1LL, a3, 1LL, a1, &v13, &v14, &v15, &v16, &v17, &v18);
v9 = v13;
v10 = v14;
v11 = verbose <= 1;
*a4 = v13;
*a5 = v10;
if ( !v11 )
{
printf("# best fit: Y = %g + %g X\n", v9, v10);
puts("# covariance matrix:");
printf("# [ %g, %g\n# %g, %g]\n", v15, v16, v16, v17);
printf("# chisq = %g\n", v18);
}
return 0LL;
}

original_code:
int linear_fit(int n, double *x, double *y, double *c, double *m)
{
  extern int verbose;
  int i;
  double w[5000];
  double c0, c1, cov00, cov01, cov11, chisq;
  for (i = 0; i < n; i++) {
    w[i] = 1.0;
  }
  if(verbose>1)printf("Fitting ....\n");
  gsl_fit_wlinear (x, 1, w, 1, y, 1, n,
                   &c0, &c1, &cov00, &cov01, &cov11,
                   &chisq);
  *c = c0;
  *m = c1;
  if(verbose>1){
     printf("# best fit: Y = %g + %g X\n", c0, c1);
     printf("# covariance matrix:\n");
     printf("# [ %g, %g\n#   %g, %g]\n", cov00, cov01, cov01, cov11);
     printf("# chisq = %g\n", chisq);
  }
  return 0;
}

canonical_original_code:
int linear_fit(int n, double *x, double *y, double *c, double *m)
{
  extern int verbose;
  int i;
  double w[5000];
  double c0; double c1; double cov00; double cov01; double cov11; double chisq;
  for (i = 0; i < n; i++) {
    w[i] = 1.0;
  }
  if(verbose>1)printf("Fitting ....\n");
  gsl_fit_wlinear (x, 1, w, 1, y, 1, n,
                   &c0, &c1, &cov00, &cov01, &cov11,
                   &chisq);
  *c = c0;
  *m = c1;
  if(verbose>1){
     printf("# best fit: Y = %g + %g X\n", c0, c1);
     printf("# covariance matrix:\n");
     printf("# [ %g, %g\n#   %g, %g]\n", cov00, cov01, cov01, cov11);
     printf("# chisq = %g\n", chisq);
  }
  return 0;
}

variable_types:
x
double *

variable_types:
y
double *

variable_types:
c
double *

variable_types:
m
double *

variable_types:
w
double [5000]

variable_types: chisq double


quadfit

decompiled_code:
__int64 __fastcall quadfit(int a1, __int64 a2, __int64 a3, double *a4)
{
__int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // r13
__int64 v7; // r15
__int64 v8; // rbx
__int64 v9; // rsi
__int64 v10; // r12
double v11; // xmm0_8
bool v12; // cc
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v18; // [rsp+0h] [rbp-78h]
double v19; // [rsp+0h] [rbp-78h]
double v20; // [rsp+0h] [rbp-78h]
double v21; // [rsp+0h] [rbp-78h]
double v22; // [rsp+0h] [rbp-78h]
double v23; // [rsp+8h] [rbp-70h]
double v24; // [rsp+8h] [rbp-70h]
double v25; // [rsp+8h] [rbp-70h]
double v26; // [rsp+8h] [rbp-70h]
double v27; // [rsp+8h] [rbp-70h]
__int64 v30; // [rsp+20h] [rbp-58h]
double v32[8]; // [rsp+38h] [rbp-40h] BYREF

v4 = gsl_matrix_alloc(a1, 3LL);
v5 = gsl_vector_alloc(a1);
v6 = gsl_vector_alloc(a1);
v7 = gsl_vector_alloc(3LL);
v30 = gsl_matrix_alloc(3LL, 3LL);
if ( a1 > 0 )
{
v8 = 0LL;
do
{
v18 = *(double *)(a2 + 8 * v8);
v23 = *(double *)(a3 + 8 * v8);
gsl_matrix_set(v4, v8, 0LL, 1.0);
gsl_matrix_set(v4, v8, 1LL, v18);
gsl_matrix_set(v4, v8, 2LL, v18 * v18);
gsl_vector_set(v5, v8, v23);
v9 = v8++;
gsl_vector_set(v6, v9, 1.0);
}
while ( v8 != a1 );
}
v10 = gsl_multifit_linear_alloc(a1, 3LL);
gsl_multifit_wlinear(v4, v6, v5, v7, v30, v32);
gsl_multifit_linear_free(v10);
*a4 = gsl_vector_get(v7, 0LL);
a4[1] = gsl_vector_get(v7, 1LL);
v11 = gsl_vector_get(v7, 2LL);
v12 = verbose <= 1;
a4[2] = v11;
if ( !v12 )
{
v24 = gsl_vector_get(v7, 2LL);
v19 = gsl_vector_get(v7, 1LL);
v13 = gsl_vector_get(v7, 0LL);
printf("# best fit: Y = %g + %g X + %g X^2\n", v13, v19, v24);
puts("# covariance matrix:");
v25 = gsl_matrix_get(v30, 0LL, 2LL);
v20 = gsl_matrix_get(v30, 0LL, 1LL);
v14 = gsl_matrix_get(v30, 0LL, 0LL);
printf("[ %+.5e, %+.5e, %+.5e \n", v14, v20, v25);
v26 = gsl_matrix_get(v30, 1LL, 2LL);
v21 = gsl_matrix_get(v30, 1LL, 1LL);
v15 = gsl_matrix_get(v30, 1LL, 0LL);
printf(" %+.5e, %+.5e, %+.5e \n", v15, v21, v26);
v27 = gsl_matrix_get(v30, 2LL, 2LL);
v22 = gsl_matrix_get(v30, 2LL, 1LL);
v16 = gsl_matrix_get(v30, 2LL, 0LL);
printf(" %+.5e, %+.5e, %+.5e ]\n", v16, v22, v27);
printf("# chisq = %g\n", v32[0]);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3, double *a4)
{
__int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // r13
__int64 v7; // r15
__int64 v8; // rbx
__int64 v9; // rsi
__int64 v10; // r12
double v11; // xmm0_8
bool v12; // cc
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v18; // [rsp+0h] [rbp-78h]
double v19; // [rsp+0h] [rbp-78h]
double v20; // [rsp+0h] [rbp-78h]
double v21; // [rsp+0h] [rbp-78h]
double v22; // [rsp+0h] [rbp-78h]
double v23; // [rsp+8h] [rbp-70h]
double v24; // [rsp+8h] [rbp-70h]
double v25; // [rsp+8h] [rbp-70h]
double v26; // [rsp+8h] [rbp-70h]
double v27; // [rsp+8h] [rbp-70h]
__int64 v30; // [rsp+20h] [rbp-58h]
double v32[8]; // [rsp+38h] [rbp-40h] BYREF

v4 = gsl_matrix_alloc(a1, 3LL);
v5 = gsl_vector_alloc(a1);
v6 = gsl_vector_alloc(a1);
v7 = gsl_vector_alloc(3LL);
v30 = gsl_matrix_alloc(3LL, 3LL);
if ( a1 > 0 )
{
v8 = 0LL;
do
{
v18 = *(double *)(a2 + 8 * v8);
v23 = *(double *)(a3 + 8 * v8);
gsl_matrix_set(v4, v8, 0LL, 1.0);
gsl_matrix_set(v4, v8, 1LL, v18);
gsl_matrix_set(v4, v8, 2LL, v18 * v18);
gsl_vector_set(v5, v8, v23);
v9 = v8++;
gsl_vector_set(v6, v9, 1.0);
}
while ( v8 != a1 );
}
v10 = gsl_multifit_linear_alloc(a1, 3LL);
gsl_multifit_wlinear(v4, v6, v5, v7, v30, v32);
gsl_multifit_linear_free(v10);
*a4 = gsl_vector_get(v7, 0LL);
a4[1] = gsl_vector_get(v7, 1LL);
v11 = gsl_vector_get(v7, 2LL);
v12 = verbose <= 1;
a4[2] = v11;
if ( !v12 )
{
v24 = gsl_vector_get(v7, 2LL);
v19 = gsl_vector_get(v7, 1LL);
v13 = gsl_vector_get(v7, 0LL);
printf("# best fit: Y = %g + %g X + %g X^2\n", v13, v19, v24);
puts("# covariance matrix:");
v25 = gsl_matrix_get(v30, 0LL, 2LL);
v20 = gsl_matrix_get(v30, 0LL, 1LL);
v14 = gsl_matrix_get(v30, 0LL, 0LL);
printf("[ %+.5e, %+.5e, %+.5e \n", v14, v20, v25);
v26 = gsl_matrix_get(v30, 1LL, 2LL);
v21 = gsl_matrix_get(v30, 1LL, 1LL);
v15 = gsl_matrix_get(v30, 1LL, 0LL);
printf(" %+.5e, %+.5e, %+.5e \n", v15, v21, v26);
v27 = gsl_matrix_get(v30, 2LL, 2LL);
v22 = gsl_matrix_get(v30, 2LL, 1LL);
v16 = gsl_matrix_get(v30, 2LL, 0LL);
printf(" %+.5e, %+.5e, %+.5e ]\n", v16, v22, v27);
printf("# chisq = %g\n", v32[0]);
}
return 0LL;
}

original_code:
int quadfit (int n, double *fX, double *fY, double *fCoef)
{
  extern int verbose;
  int i;
  double xi, yi, ei, chisq;
  gsl_matrix *X, *cov;
  gsl_vector *y, *w, *c;
  X = gsl_matrix_alloc (n, 3);
  y = gsl_vector_alloc (n);
  w = gsl_vector_alloc (n);
  c = gsl_vector_alloc (3);
  cov = gsl_matrix_alloc (3, 3);
  for (i = 0; i < n; i++)
    {
      xi = fX[i];
      yi = fY[i];
      ei = 1.0;
      gsl_matrix_set (X, i, 0, 1.0);
      gsl_matrix_set (X, i, 1, xi);
      gsl_matrix_set (X, i, 2, xi*xi);
      gsl_vector_set (y, i, yi);
      gsl_vector_set (w, i, 1.0/(ei*ei));
    }
  {
    gsl_multifit_linear_workspace * work
      = gsl_multifit_linear_alloc (n, 3);
    gsl_multifit_wlinear (X, w, y, c, cov,
                          &chisq, work);
    gsl_multifit_linear_free (work);
  }
  {
    fCoef[0] = (gsl_vector_get(c,(0)));
    fCoef[1] = (gsl_vector_get(c,(1)));
    fCoef[2] = (gsl_vector_get(c,(2)));
  }
  if(verbose>1)
  {
    printf("# best fit: Y = %g + %g X + %g X^2\n",
           (gsl_vector_get(c,(0))), (gsl_vector_get(c,(1))), (gsl_vector_get(c,(2))));
    printf("# covariance matrix:\n");
    printf("[ %+.5e, %+.5e, %+.5e  \n",
              (gsl_matrix_get(cov,(0),(0))), (gsl_matrix_get(cov,(0),(1))), (gsl_matrix_get(cov,(0),(2))));
    printf("  %+.5e, %+.5e, %+.5e  \n",
              (gsl_matrix_get(cov,(1),(0))), (gsl_matrix_get(cov,(1),(1))), (gsl_matrix_get(cov,(1),(2))));
    printf("  %+.5e, %+.5e, %+.5e ]\n",
              (gsl_matrix_get(cov,(2),(0))), (gsl_matrix_get(cov,(2),(1))), (gsl_matrix_get(cov,(2),(2))));
    printf("# chisq = %g\n", chisq);
  }
  return 0;
}

canonical_original_code:
int quadfit(int n, double *fX, double *fY, double *fCoef)
{
  extern int verbose;
  int i;
  double xi; double yi; double ei; double chisq;
  struct gsl_matrix *X; struct gsl_matrix *cov;
  struct gsl_vector *y; struct gsl_vector *w; struct gsl_vector *c;
  X = gsl_matrix_alloc (n, 3);
  y = gsl_vector_alloc (n);
  w = gsl_vector_alloc (n);
  c = gsl_vector_alloc (3);
  cov = gsl_matrix_alloc (3, 3);
  for (i = 0; i < n; i++)
    {
      xi = fX[i];
      yi = fY[i];
      ei = 1.0;
      gsl_matrix_set (X, i, 0, 1.0);
      gsl_matrix_set (X, i, 1, xi);
      gsl_matrix_set (X, i, 2, xi*xi);
      gsl_vector_set (y, i, yi);
      gsl_vector_set (w, i, 1.0/(ei*ei));
    }
  {
    struct gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, 3);
    gsl_multifit_wlinear (X, w, y, c, cov,
                          &chisq, work);
    gsl_multifit_linear_free (work);
  }
  {
    fCoef[0] = (gsl_vector_get(c,(0)));
    fCoef[1] = (gsl_vector_get(c,(1)));
    fCoef[2] = (gsl_vector_get(c,(2)));
  }
  if(verbose>1)
  {
    printf("# best fit: Y = %g + %g X + %g X^2\n",
           (gsl_vector_get(c,(0))), (gsl_vector_get(c,(1))), (gsl_vector_get(c,(2))));
    printf("# covariance matrix:\n");
    printf("[ %+.5e, %+.5e, %+.5e  \n",
              (gsl_matrix_get(cov,(0),(0))), (gsl_matrix_get(cov,(0),(1))), (gsl_matrix_get(cov,(0),(2))));
    printf("  %+.5e, %+.5e, %+.5e  \n",
              (gsl_matrix_get(cov,(1),(0))), (gsl_matrix_get(cov,(1),(1))), (gsl_matrix_get(cov,(1),(2))));
    printf("  %+.5e, %+.5e, %+.5e ]\n",
              (gsl_matrix_get(cov,(2),(0))), (gsl_matrix_get(cov,(2),(1))), (gsl_matrix_get(cov,(2),(2))));
    printf("# chisq = %g\n", chisq);
  }
  return 0;
}

variable_types: n int

variable_types:
fX
double *

variable_types:
fY
double *

variable_types:
fCoef
double *

variable_types: verbose int

variable_types: xi double

variable_types: yi double

variable_types: ei double

variable_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: struct gsl_multifit_linear_workspace { unsigned long nmax; unsigned long pmax; unsigned long n; unsigned long p; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *A; struct gsl_matrix *Q; struct gsl_matrix *QSI; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *S; struct gsl_vector *t; struct gsl_vector *xt; struct gsl_vector *D; double rcond; } *

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }

user_defined_types: struct gsl_multifit_linear_workspace { unsigned long nmax; unsigned long pmax; unsigned long n; unsigned long p; struct gsl_matrix *A; struct gsl_matrix *Q; struct gsl_matrix *QSI; struct gsl_vector *S; struct gsl_vector *t; struct gsl_vector *xt; struct gsl_vector *D; double rcond; }


DoSpline

decompiled_code:
__int64 __fastcall DoSpline(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v6; // rbp
__int64 v7; // r13
__int64 i; // rbx

puts("#m=0,S=2");
puts("#m=1,S=0");
v6 = gsl_interp_accel_alloc();
v7 = gsl_spline_alloc(gsl_interp_akima, a1);
gsl_spline_init(v7, a2, a3, a1);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
*(double *)(a4 + 8 * i) = *(double *)(a2 + 8 * i) - 5.0;
*(double *)(a5 + 8 * i) = gsl_spline_eval(v7, v6, *(double *)(a2 + 8 * i));
}
}
gsl_spline_free(v7);
gsl_interp_accel_free(v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v6; // rbp
__int64 v7; // r13
__int64 i; // rbx

puts("#m=0,S=2");
puts("#m=1,S=0");
v6 = gsl_interp_accel_alloc();
v7 = gsl_spline_alloc(gsl_interp_akima, a1);
gsl_spline_init(v7, a2, a3, a1);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
*(double *)(a4 + 8 * i) = *(double *)(a2 + 8 * i) - 5.0;
*(double *)(a5 + 8 * i) = gsl_spline_eval(v7, v6, *(double *)(a2 + 8 * i));
}
}
gsl_spline_free(v7);
gsl_interp_accel_free(v6);
return 0LL;
}

original_code:
int DoSpline(int nDataPoints, double *x, double *y, double *xi, double *yi)
{
  int i;
  printf ("#m=0,S=2\n");
  printf ("#m=1,S=0\n");
  {
    gsl_interp_accel *acc
      = gsl_interp_accel_alloc ();
    gsl_spline *spline
      = gsl_spline_alloc (gsl_interp_akima, nDataPoints);
    gsl_spline_init (spline, x, y, nDataPoints);
    for (i = 0; i < nDataPoints; i++)
      {
 xi[i]=x[i]-5;
 yi[i] = gsl_spline_eval (spline, x[i], acc);
      }
    gsl_spline_free (spline);
    gsl_interp_accel_free(acc);
  }
  return 0;
}

canonical_original_code:
int DoSpline(int nDataPoints, double *x, double *y, double *xi, double *yi)
{
  int i;
  printf ("#m=0,S=2\n");
  printf ("#m=1,S=0\n");
  {
    struct gsl_interp_accel *acc = gsl_interp_accel_alloc ();
    struct gsl_spline *spline = gsl_spline_alloc (gsl_interp_akima, nDataPoints);
    gsl_spline_init (spline, x, y, nDataPoints);
    for (i = 0; i < nDataPoints; i++)
      {
 xi[i]=x[i]-5;
 yi[i] = gsl_spline_eval (spline, x[i], acc);
      }
    gsl_spline_free (spline);
    gsl_interp_accel_free(acc);
  }
  return 0;
}

variable_types: nDataPoints int

variable_types:
xi
double *

variable_types:
yi
double *

variable_types: i int

variable_types: struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } *

user_defined_types: struct gsl_spline { struct gsl_interp *interp; double *x; double *y; unsigned long size; }

user_defined_types: struct gsl_interp { struct gsl_interp_type *type; double xmin; double xmax; unsigned long size; void *state; }

user_defined_types: struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); }


savwin

decompiled_code:
int __fastcall savwin(int *a1, double a2, double a3, double a4)
{
double v4; // xmm1_8
int result; // eax

v4 = a3 * a2;
result = (int)(v4 / a4);
if ( result > 29 )
{
result = 29;
*a1 = 29;
if ( verbose <= 0 )
return result;
goto LABEL_7;
}
*a1 = result;
if ( result <= 1 )
result = 2;
*a1 = result;
if ( verbose > 0 )
{
LABEL_7:
printf("dE = %f Resol = %f\n", a4, v4);
result = verbose;
if ( verbose > 0 )
result = printf("Savitsky-Golay window value = %d\n", a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int *a1, double a2, double a3, double a4)
{
double v4; // xmm1_8
int result; // eax

v4 = a3 * a2;
result = (int)(v4 / a4);
if ( result > 29 )
{
result = 29;
*a1 = 29;
if ( verbose <= 0 )
return result;
goto LABEL_7;
}
*a1 = result;
if ( result <= 1 )
result = 2;
*a1 = result;
if ( verbose > 0 )
{
LABEL_7:
printf("dE = %f Resol = %f\n", a4, v4);
result = verbose;
if ( verbose > 0 )
result = printf("Savitsky-Golay window value = %d\n", a1);
}
return result;
}

original_code:
void savwin(double fEres, double fEdge, double dE, int *nSavWin) {
  double fMonoRes;
  extern int verbose;
  fMonoRes = fEres * fEdge;
  *nSavWin = (int) (fMonoRes / dE);
  if(*nSavWin > 29){
    *nSavWin=29;
  }
  if(*nSavWin < 2){
     *nSavWin=2;
  }
  if(verbose>0)printf("dE = %f Resol = %f\n", dE, fMonoRes);
  if(verbose>0)printf("Savitsky-Golay window value = %d\n", nSavWin);
}

variable_types: fEres double

variable_types: fEdge double

variable_types: dE double

variable_types:
nSavWin
int *

variable_types: fMonoRes double


decompiled_code:
double __fastcall get_CrossSection(__int64 a1)
{
char v2[32]; // [rsp+0h] [rbp-4D8h] BYREF
char v3[80]; // [rsp+20h] [rbp-4B8h] BYREF
double v4[12]; // [rsp+70h] [rbp-468h] BYREF
char v5[1032]; // [rsp+D0h] [rbp-408h] BYREF

mucal(a1, 0LL, 97LL, 0LL, v3, v4, v2, v5);
return v4[0];
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
char v2[32]; // [rsp+0h] [rbp-4D8h] BYREF
char v3[80]; // [rsp+20h] [rbp-4B8h] BYREF
double v4[12]; // [rsp+70h] [rbp-468h] BYREF
char v5[1032]; // [rsp+D0h] [rbp-408h] BYREF

mucal(a1, 0LL, 97LL, 0LL, v3, v4, v2, v5);
return v4[0];
}

original_code:
double get_CrossSection(char *sElement, double dEnergyKeV)
{
  double dEnergy[9], dXsec[11], dFluo[4];
  double dXsection;
  int iZZ = 0, iPflag=0;
  int err;
  char sUnit='a', sErrmsg[1024];
  if((err=mucal(sElement, iZZ, dEnergyKeV, sUnit, iPflag, dEnergy, dXsec, dFluo, &sErrmsg[0])) != 0) {
  }
  dXsection = dXsec[0];
  return dXsection;
}

canonical_original_code:
double get_CrossSection(char *sElement, double dEnergyKeV)
{
  double dEnergy[9]; double dXsec[11]; double dFluo[4];
  double dXsection;
  int iZZ = 0; int iPflag = 0;
  int err;
  char sUnit = 'a'; char sErrmsg[1024];
  if((err=mucal(sElement, iZZ, dEnergyKeV, sUnit, iPflag, dEnergy, dXsec, dFluo, &sErrmsg[0])) != 0) {
  }
  dXsection = dXsec[0];
  return dXsection;
}

variable_types:
sElement
char *

variable_types: dEnergyKeV double

variable_types:
dEnergy
double [9]

variable_types:
dXsec
double [11]

variable_types:
dFluo
double [4]

variable_types: dXsection double

variable_types: iZZ int

variable_types: iPflag int

variable_types: err int

variable_types: sUnit char

variable_types:
sErrmsg
char [1024]

return_type: double


decompiled_code:
const char *__fastcall edge_name(unsigned int a1)
{
const char *result; // rax

result = "Bad edge";
if ( a1 <= 4 )
result = name_0[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned int a1)
{
const char *result; // rax

result = "Bad edge";
if ( a1 <= 4 )
result = name_0[a1];
return result;
}

original_code:
char *edge_name(int n)
{
   static char *name[] = {
      "K", "L1", "L2", "L3", "M", "Bad edge"
   };
   return (n < 0 || n > 4) ? name[5] : name[n];
}

variable_types: n int

variable_types:
name
char *[]

return_type: char *


decompiled_code:
const char *__fastcall get_Edge(__int64 a1, double *a2, double a3)
{
unsigned int v3; // er12
double v4; // r14
int v5; // eax
unsigned __int64 v6; // xmm2_8
__int64 v7; // xmm3_8
__int64 v8; // rbx
double v9; // xmm0_8
double v10; // xmm1_8
char v12[32]; // [rsp+10h] [rbp-148h] BYREF
double v13[10]; // [rsp+30h] [rbp-128h] BYREF
char v14[80]; // [rsp+80h] [rbp-D8h] BYREF
char v15[136]; // [rsp+D0h] [rbp-88h] BYREF

v4 = a3 / 1000.0;
if ( (unsigned int)mucal(a1, 0LL, 97LL, 0LL, v13, v15, v12, v14) )
printf("WARNING: Problem getting edge energy from mucal");
v5 = verbose;
if ( verbose > 0 )
{
printf(" Mid point of spectrum = %f\n", v4);
v5 = verbose;
if ( verbose > 0 )
{
puts(" E edge E diff");
v5 = verbose;
}
}
v6 = LC1;
v7 = LC7;
v8 = 0LL;
while ( 1 )
{
v9 = v13[v8];
*(_QWORD *)&v10 = COERCE_UNSIGNED_INT64(v4 - v9) & v7;
if ( *(double *)&v6 > v10 )
{
v3 = v8;
*a2 = 1000.0 * v9;
v6 = COERCE_UNSIGNED_INT64(v4 - v9) & v7;
}
if ( v5 > 0 )
{
printf(" %8.4f %8.4f\n", v9, v10);
v7 = LC7;
}
if ( ++v8 == 5 )
break;
v5 = verbose;
}
return edge_name(v3);
}

canonical_decompiled_code:
const char *__fastcall func2(__int64 a1, double *a2, double a3)
{
unsigned int v3; // er12
double v4; // r14
int v5; // eax
unsigned __int64 v6; // xmm2_8
__int64 v7; // xmm3_8
__int64 v8; // rbx
double v9; // xmm0_8
double v10; // xmm1_8
char v12[32]; // [rsp+10h] [rbp-148h] BYREF
double v13[10]; // [rsp+30h] [rbp-128h] BYREF
char v14[80]; // [rsp+80h] [rbp-D8h] BYREF
char v15[136]; // [rsp+D0h] [rbp-88h] BYREF

v4 = a3 / 1000.0;
if ( (unsigned int)mucal(a1, 0LL, 97LL, 0LL, v13, v15, v12, v14) )
printf("WARNING: Problem getting edge energy from mucal");
v5 = verbose;
if ( verbose > 0 )
{
printf(" Mid point of spectrum = %f\n", v4);
v5 = verbose;
if ( verbose > 0 )
{
puts(" E edge E diff");
v5 = verbose;
}
}
v6 = LC1;
v7 = LC7;
v8 = 0LL;
while ( 1 )
{
v9 = v13[v8];
*(_QWORD *)&v10 = COERCE_UNSIGNED_INT64(v4 - v9) & v7;
if ( *(double *)&v6 > v10 )
{
v3 = v8;
*a2 = 1000.0 * v9;
v6 = COERCE_UNSIGNED_INT64(v4 - v9) & v7;
}
if ( v5 > 0 )
{
printf(" %8.4f %8.4f\n", v9, v10);
v7 = LC7;
}
if ( ++v8 == 5 )
break;
v5 = verbose;
}
return func1(v3);
}

original_code:
char *get_Edge(char *sElement, double fMidE, double *fE)
{
  extern int verbose;
  double dEnergy[9], dXsec[11], dFluo[4];
  double diff, mindiff=1e10, E;
  int i, iE, iZZ = 0, iPflag=0;
  int err;
  char sUnit='a', sErrmsg[80];
  fMidE/=1000.0;
  if((err=mucal(sElement, iZZ, 0.0, sUnit, iPflag, dEnergy, dXsec, dFluo, &sErrmsg[0])) != 0) {
    printf("WARNING: Problem  getting edge energy from mucal");
  }
  if(verbose>0)printf(" Mid point of spectrum = %f\n", fMidE);
  if(verbose>0)printf(" E edge      E diff\n");
  for(i=0; i<5; i++){
     diff=fabs(fMidE-dEnergy[i]);
     if(diff < mindiff){
 mindiff=diff;
 iE=i;
 *fE=dEnergy[i]*1000.0;
     }
     if(verbose>0)printf(" %8.4f       %8.4f\n", dEnergy[i], diff);
  }
  return edge_name(iE);
}

canonical_original_code:
char *get_Edge(char *sElement, double fMidE, double *fE)
{
  extern int verbose;
  double dEnergy[9]; double dXsec[11]; double dFluo[4];
  double diff; double mindiff = 1e10; double E;
  int i; int iE; int iZZ = 0; int iPflag = 0;
  int err;
  char sUnit = 'a'; char sErrmsg[80];
  fMidE/=1000.0;
  if((err=mucal(sElement, iZZ, 0.0, sUnit, iPflag, dEnergy, dXsec, dFluo, &sErrmsg[0])) != 0) {
    printf("WARNING: Problem  getting edge energy from mucal");
  }
  if(verbose>0)printf(" Mid point of spectrum = %f\n", fMidE);
  if(verbose>0)printf(" E edge      E diff\n");
  for(i=0; i<5; i++){
     diff=fabs(fMidE-dEnergy[i]);
     if(diff < mindiff){
 mindiff=diff;
 iE=i;
 *fE=dEnergy[i]*1000.0;
     }
     if(verbose>0)printf(" %8.4f       %8.4f\n", dEnergy[i], diff);
  }
  return edge_name(iE);
}

variable_types: fMidE double

variable_types:
fE
double *

variable_types: verbose int

variable_types: diff double

variable_types: mindiff double

variable_types: E double

variable_types: i int

variable_types: iE int

variable_types:
sErrmsg
char [80]


decompiled_code:
double __fastcall get_fpp(__int64 a1, double a2)
{
return get_CrossSection(a1) * (a2 * 0.000000014310935 * 1000.0);
}

original_code:
double get_fpp (char *sElement, double dEnergyKeV)
{
  double dFdprime;
  dFdprime = 143.10935e-10 * dEnergyKeV * 1000.0 * get_CrossSection(sElement, dEnergyKeV);
  return dFdprime;
}

canonical_original_code:
double get_fpp(char *sElement, double dEnergyKeV)
{
  double dFdprime;
  dFdprime = 143.10935e-10 * dEnergyKeV * 1000.0 * get_CrossSection(sElement, dEnergyKeV);
  return dFdprime;
}

variable_types:
sElement
char *

variable_types: dEnergyKeV double

variable_types: dFdprime double


printbanner

original_code:
void printbanner()
{
  printf("==========================\n");
  printf("chooch                  \n");
  printf("Gwyndaf Evans              \n");
  printf("gwyndaf@gwyndafevans.co.uk       \n");
  printf("==========================\n");
}


selwavel

decompiled_code:
__int64 __fastcall selwavel(int a1, __int64 a2, __int64 a3, __int64 a4)
{
double v4; // xmm1_8
double v5; // xmm2_8
__int64 v6; // rax
__int64 v7; // rdi

v4 = *(double *)&LC1;
v5 = *(double *)&LC0;
fpInfl = LC1;
fppPeak = LC0;
if ( a1 > 0 )
{
v6 = 0LL;
v7 = 8LL * (unsigned int)(a1 - 1);
while ( 1 )
{
if ( v4 > *(double *)(a4 + v6) )
{
fpInfl = *(_QWORD *)(a4 + v6);
fppInfl = *(_QWORD *)(a3 + v6);
EInfl = *(_QWORD *)(a2 + v6);
}
if ( *(double *)(a3 + v6) > v5 )
{
fpPeak = *(_QWORD *)(a4 + v6);
fppPeak = *(_QWORD *)(a3 + v6);
EPeak = *(_QWORD *)(a2 + v6);
}
if ( v7 == v6 )
break;
v4 = fpInfl;
v5 = fppPeak;
v6 += 8LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3, __int64 a4)
{
double v4; // xmm1_8
double v5; // xmm2_8
__int64 v6; // rax
__int64 v7; // rdi

v4 = *(double *)&LC1;
v5 = *(double *)&LC0;
fpInfl = LC1;
fppPeak = LC0;
if ( a1 > 0 )
{
v6 = 0LL;
v7 = 8LL * (unsigned int)(a1 - 1);
while ( 1 )
{
if ( v4 > *(double *)(a4 + v6) )
{
fpInfl = *(_QWORD *)(a4 + v6);
fppInfl = *(_QWORD *)(a3 + v6);
EInfl = *(_QWORD *)(a2 + v6);
}
if ( *(double *)(a3 + v6) > v5 )
{
fpPeak = *(_QWORD *)(a4 + v6);
fppPeak = *(_QWORD *)(a3 + v6);
EPeak = *(_QWORD *)(a2 + v6);
}
if ( v7 == v6 )
break;
v4 = fpInfl;
v5 = fppPeak;
v6 += 8LL;
}
}
return 0LL;
}

original_code:
int selwavel(int n, double *fXfpp, double *fpp, double *fp)
{
   extern double fpInfl, fppInfl, fpPeak, fppPeak, EInfl, EPeak;
   int i;
   fpInfl = 10000000;
   fppPeak = -10000000;
   for (i = 0; i < n; i++) {
      if(fp[i] < fpInfl){
  fpInfl = fp[i];
  fppInfl = fpp[i];
  EInfl = fXfpp[i];
      }
      if(fpp[i] > fppPeak){
  fpPeak = fp[i];
  fppPeak = fpp[i];
  EPeak = fXfpp[i];
      }
   }
   return 0;
}

canonical_original_code:
int selwavel(int n, double *fXfpp, double *fpp, double *fp)
{
   extern double fpInfl; extern double fppInfl; extern double fpPeak; extern double fppPeak; extern double EInfl; extern double EPeak;
   int i;
   fpInfl = 10000000;
   fppPeak = -10000000;
   for (i = 0; i < n; i++) {
      if(fp[i] < fpInfl){
  fpInfl = fp[i];
  fppInfl = fpp[i];
  EInfl = fXfpp[i];
      }
      if(fpp[i] > fppPeak){
  fpPeak = fp[i];
  fppPeak = fpp[i];
  EPeak = fXfpp[i];
      }
   }
   return 0;
}

variable_types:
fXfpp
double *

variable_types:
fpp
double *

variable_types:
fp
double *

variable_types: fpInfl double

variable_types: fppInfl double

variable_types: fpPeak double

variable_types: fppPeak double

variable_types: EInfl double

variable_types: EPeak double


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
fwrite(
" chooch -e <element> [-a <edge>] [-r <resol>] [-1 <e1>] [-2 <e2>] [-3 <e3>] [-4 <e4>] [-x] [-p] [-o <efs filename>] "
"[-v <verbose level>] [FILE]\n"
"\n",
1uLL,
0x91uLL,
stderr);
fwrite("-h print this message\n", 1uLL, 0x29uLL, stderr);
fwrite("-s run silently\n", 1uLL, 0x23uLL, stderr);
fwrite("-e <element> element symbol (default Se)\n", 1uLL, 0x32uLL, stderr);
fwrite("-a <edge> absorption edge (K, L1, L2, L3, M) (default is auto detect)\n", 1uLL, 0x52uLL, stderr);
fwrite("-r <resol> energy resolution (dE/E) (default is Si(111) 1.4x10-4)\n", 1uLL, 0x4DuLL, stderr);
fwrite("-1 <e1> Below edge fit lower energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-2 <e2> Below edge fit upper energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-3 <e3> Above edge fit lower energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-4 <e4> Above edge fit upper energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-p <PS file> output to PostScript file\n", 1uLL, 0x30uLL, stderr);
fwrite("-g <PNG file> output to Portable Network Graphics (PNG) file\n", 1uLL, 0x45uLL, stderr);
fwrite("-o <efs file> filename for efs output (default output.efs\n", 1uLL, 0x42uLL, stderr);
fwrite("-d dump intermediate data for use with pUI\n", 1uLL, 0x3EuLL, stderr);
fwrite("-v <level> verbosity level (0 -- 3) (default 0)\n", 1uLL, 0x3BuLL, stderr);
fwrite("-w show warranty information\n", 1uLL, 0x30uLL, stderr);
fwrite("-c show redistribution information\n", 1uLL, 0x36uLL, stderr);
fwrite("-l show license information\n", 1uLL, 0x2FuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
fwrite(
" chooch -e <element> [-a <edge>] [-r <resol>] [-1 <e1>] [-2 <e2>] [-3 <e3>] [-4 <e4>] [-x] [-p] [-o <efs filename>] "
"[-v <verbose level>] [FILE]\n"
"\n",
1uLL,
0x91uLL,
stderr);
fwrite("-h print this message\n", 1uLL, 0x29uLL, stderr);
fwrite("-s run silently\n", 1uLL, 0x23uLL, stderr);
fwrite("-e <element> element symbol (default Se)\n", 1uLL, 0x32uLL, stderr);
fwrite("-a <edge> absorption edge (K, L1, L2, L3, M) (default is auto detect)\n", 1uLL, 0x52uLL, stderr);
fwrite("-r <resol> energy resolution (dE/E) (default is Si(111) 1.4x10-4)\n", 1uLL, 0x4DuLL, stderr);
fwrite("-1 <e1> Below edge fit lower energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-2 <e2> Below edge fit upper energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-3 <e3> Above edge fit lower energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-4 <e4> Above edge fit upper energy limit (eV)\n", 1uLL, 0x3DuLL, stderr);
fwrite("-p <PS file> output to PostScript file\n", 1uLL, 0x30uLL, stderr);
fwrite("-g <PNG file> output to Portable Network Graphics (PNG) file\n", 1uLL, 0x45uLL, stderr);
fwrite("-o <efs file> filename for efs output (default output.efs\n", 1uLL, 0x42uLL, stderr);
fwrite("-d dump intermediate data for use with pUI\n", 1uLL, 0x3EuLL, stderr);
fwrite("-v <level> verbosity level (0 -- 3) (default 0)\n", 1uLL, 0x3BuLL, stderr);
fwrite("-w show warranty information\n", 1uLL, 0x30uLL, stderr);
fwrite("-c show redistribution information\n", 1uLL, 0x36uLL, stderr);
fwrite("-l show license information\n", 1uLL, 0x2FuLL, stderr);
exit(1);
}

original_code:
void usage()
{
  (void)fprintf( stderr, "Usage:\n" );
  (void)fprintf( stderr, " chooch -e <element> [-a <edge>] [-r <resol>] [-1 <e1>] [-2 <e2>] [-3 <e3>] [-4 <e4>] [-x] [-p] [-o <efs filename>] [-v <verbose level>] [FILE]\n\n");
  (void)fprintf( stderr, "-h                    print this message\n");
  (void)fprintf( stderr, "-s                    run silently\n");
  (void)fprintf( stderr, "-e <element>          element symbol (default Se)\n");
  (void)fprintf( stderr, "-a <edge>             absorption edge (K, L1, L2, L3, M) (default is auto detect)\n");
  (void)fprintf( stderr, "-r <resol>            energy resolution (dE/E) (default is Si(111) 1.4x10-4)\n");
  (void)fprintf( stderr, "-1 <e1>               Below edge fit lower energy limit (eV)\n");
  (void)fprintf( stderr, "-2 <e2>               Below edge fit upper energy limit (eV)\n");
  (void)fprintf( stderr, "-3 <e3>               Above edge fit lower energy limit (eV)\n");
  (void)fprintf( stderr, "-4 <e4>               Above edge fit upper energy limit (eV)\n");
  (void)fprintf( stderr, "-p <PS file>          output to PostScript file\n");
  (void)fprintf( stderr, "-g <PNG file>         output to Portable Network Graphics (PNG) file\n");
  (void)fprintf( stderr, "-o <efs file>         filename for efs output (default output.efs\n");
  (void)fprintf( stderr, "-d                    dump intermediate data for use with pUI\n");
  (void)fprintf( stderr, "-v <level>            verbosity level (0 -- 3) (default 0)\n");
  (void)fprintf( stderr, "-w                    show warranty information\n");
  (void)fprintf( stderr, "-c                    show redistribution information\n");
  (void)fprintf( stderr, "-l                    show license information\n");
  exit( 1 );
}


copyright

decompiled_code:
size_t copyright()
{
fwrite("==================================================\n", 1uLL, 0x33uLL, stderr);
fwrite(" chooch-5.0.6 \n", 1uLL, 0x33uLL, stderr);
fwrite(" by Gwyndaf Evans Copyright (C) 1994--2007 \n", 1uLL, 0x33uLL, stderr);
fwrite(" gwyndaf@gwyndafevans.co.uk\n\n", 1uLL, 0x29uLL, stderr);
fwrite(" G. Evans & R. F. Pettifer (2001)\n", 1uLL, 0x29uLL, stderr);
fwrite(" J. Appl. Cryst. 34, 82-86.\n", 1uLL, 0x26uLL, stderr);
return fwrite("==================================================\n\n", 1uLL, 0x34uLL, stderr);
}

original_code:
void copyright()
{
  (void)fprintf( stderr, "==================================================\n" );
  (void)fprintf( stderr, "                     chooch-5.0.6                 \n");
  (void)fprintf( stderr, "      by Gwyndaf Evans Copyright (C) 1994--2007   \n" );
  (void)fprintf( stderr, "             gwyndaf@gwyndafevans.co.uk\n\n" );
  (void)fprintf( stderr, "        G. Evans & R. F. Pettifer (2001)\n");
  (void)fprintf( stderr, "           J. Appl. Cryst. 34, 82-86.\n");
  (void)fprintf( stderr, "==================================================\n\n" );
}


checks

decompiled_code:
__int64 __fastcall checks(int a1, double *a2, double a3, double a4, __int64 a5, double *a6)
{
bool v7; // zf
__int64 v8; // xmm2_8
__int64 v9; // rbx
bool v10; // cc
double v11; // xmm0_8
double v12; // xmm0_8
unsigned __int64 i; // rbx
double v14; // xmm0_8
double v15; // xmm0_8
double v17[2]; // [rsp+0h] [rbp-9C88h]
double v18; // [rsp+10h] [rbp-9C78h]
double v19[5006]; // [rsp+18h] [rbp-9C70h]

v7 = kev == 1;
v8 = LC0;
*(_QWORD *)a6 = LC2;
if ( v7 )
v8 = LC1;
if ( a1 > 0 )
{
v9 = 1LL;
*a2 = *a2 * *(double *)&v8;
while ( v9 != a1 )
{
v10 = verbose <= 1;
v11 = a2[v9] * *(double *)&v8;
a2[v9] = v11;
v12 = v11 - a2[v9 - 1];
v19[v9] = v12;
if ( !v10 )
{
*(_QWORD *)&v19[0] = v8;
v18 = a4;
printf("points %d and %d : Energy step %8.4f\n", (unsigned int)(v9 - 1), (unsigned int)v9, v12);
v8 = *(__int64 *)&v19[0];
}
++v9;
}
if ( a1 > 1 )
{
for ( i = 1LL; i != a1; ++i )
{
v15 = v19[i];
if ( v15 < 0.0 )
{
printf("Error in input data: energy does not increase monotonically");
exit(0);
}
a4 = a4 + v15;
if ( i > 3 )
{
v14 = a4 / 5.0;
if ( verbose > 1 )
{
v19[0] = a4;
v18 = a4 / 5.0;
printf("average no. %d : avstep %8.4f\n", (unsigned int)i, v14);
a4 = v19[0];
v14 = v18;
}
a4 = a4 - v17[i];
*a6 = fmin(v14, *a6);
}
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double *a2, double a3, double a4, __int64 a5, double *a6)
{
bool v7; // zf
__int64 v8; // xmm2_8
__int64 v9; // rbx
bool v10; // cc
double v11; // xmm0_8
double v12; // xmm0_8
unsigned __int64 i; // rbx
double v14; // xmm0_8
double v15; // xmm0_8
double v17[2]; // [rsp+0h] [rbp-9C88h]
double v18; // [rsp+10h] [rbp-9C78h]
double v19[5006]; // [rsp+18h] [rbp-9C70h]

v7 = kev == 1;
v8 = LC0;
*(_QWORD *)a6 = LC2;
if ( v7 )
v8 = LC1;
if ( a1 > 0 )
{
v9 = 1LL;
*a2 = *a2 * *(double *)&v8;
while ( v9 != a1 )
{
v10 = verbose <= 1;
v11 = a2[v9] * *(double *)&v8;
a2[v9] = v11;
v12 = v11 - a2[v9 - 1];
v19[v9] = v12;
if ( !v10 )
{
*(_QWORD *)&v19[0] = v8;
v18 = a4;
printf("points %d and %d : Energy step %8.4f\n", (unsigned int)(v9 - 1), (unsigned int)v9, v12);
v8 = *(__int64 *)&v19[0];
}
++v9;
}
if ( a1 > 1 )
{
for ( i = 1LL; i != a1; ++i )
{
v15 = v19[i];
if ( v15 < 0.0 )
{
printf("Error in input data: energy does not increase monotonically");
exit(0);
}
a4 = a4 + v15;
if ( i > 3 )
{
v14 = a4 / 5.0;
if ( verbose > 1 )
{
v19[0] = a4;
v18 = a4 / 5.0;
printf("average no. %d : avstep %8.4f\n", (unsigned int)i, v14);
a4 = v19[0];
v14 = v18;
}
a4 = a4 - v17[i];
*a6 = fmin(v14, *a6);
}
}
}
}
return 0LL;
}

original_code:
int checks (int nDataPoints, double *fXraw, double *fYraw, double *dStep)
{
  extern int verbose, kev;
  int i, err=0;
  double Steps[20];
  double runtot, avstep, conv=1.0;
  double tmp[5000];
  *dStep=100000;
  if(kev==1) {
    conv=1000.0;
  }
  for (i = 0; i < nDataPoints; i++) {
    fXraw[i] *= conv;
    if(i != 0) {
      tmp[i-1] = fXraw[i] - fXraw[i-1];
      if(verbose>1)printf("points %d and %d : Energy step  %8.4f\n", i-1, i, tmp[i-1]);
    }
  }
  for(i = 1; i < nDataPoints; i++) {
    if (tmp[i-1] < 0.0) {
      err = 1;
      printf("Error in input data: energy does not increase monotonically");
      exit(0);
    }
    runtot+=tmp[i-1];
    if(i > 3){
      avstep=runtot/5.0;
      if(verbose>1)printf("average no. %d : avstep  %8.4f\n", i, avstep);
      *dStep = (avstep < *dStep) ? avstep : *dStep;
      runtot-=tmp[i-4];
    }
  }
  return err;
}

canonical_original_code:
int checks(int nDataPoints, double *fXraw, double *fYraw, double *dStep)
{
  extern int verbose; extern int kev;
  int i; int err = 0;
  double Steps[20];
  double runtot; double avstep; double conv = 1.0;
  double tmp[5000];
  *dStep=100000;
  if(kev==1) {
    conv=1000.0;
  }
  for (i = 0; i < nDataPoints; i++) {
    fXraw[i] *= conv;
    if(i != 0) {
      tmp[i-1] = fXraw[i] - fXraw[i-1];
      if(verbose>1)printf("points %d and %d : Energy step  %8.4f\n", i-1, i, tmp[i-1]);
    }
  }
  for(i = 1; i < nDataPoints; i++) {
    if (tmp[i-1] < 0.0) {
      err = 1;
      printf("Error in input data: energy does not increase monotonically");
      exit(0);
    }
    runtot+=tmp[i-1];
    if(i > 3){
      avstep=runtot/5.0;
      if(verbose>1)printf("average no. %d : avstep  %8.4f\n", i, avstep);
      *dStep = (avstep < *dStep) ? avstep : *dStep;
      runtot-=tmp[i-4];
    }
  }
  return err;
}

variable_types: nDataPoints int

variable_types:
fXraw
double *

variable_types:
fYraw
double *

variable_types:
dStep
double *

variable_types: verbose int

variable_types: kev int

variable_types: err int

variable_types:
Steps
double [20]

variable_types: runtot double

variable_types: avstep double

variable_types: conv double

variable_types:
tmp
double [5000]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
__int64 v5[2]; // [rsp+8h] [rbp-10h] BYREF

v5[0] = 1LL;
if ( sched_setaffinity(0, 8uLL, (const cpu_set_t *)v5) < 0 )
perror("sched_setaffinity");
waste_time(2000LL);
printf("result: %f\n", v3);
v5[0] = 2LL;
if ( sched_setaffinity(0, 8uLL, (const cpu_set_t *)v5) < 0 )
perror("sched_setaffinity");
waste_time(2000LL);
printf("result: %f\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
__int64 v5[2]; // [rsp+8h] [rbp-10h] BYREF

v5[0] = 1LL;
if ( sched_setaffinity(0, 8uLL, (const cpu_set_t *)v5) < 0 )
perror("sched_setaffinity");
func7(2000LL);
printf("result: %f\n", v3);
v5[0] = 2LL;
if ( sched_setaffinity(0, 8uLL, (const cpu_set_t *)v5) < 0 )
perror("sched_setaffinity");
func7(2000LL);
printf("result: %f\n", v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    unsigned long mask = 1;
    if (sched_setaffinity(0, sizeof(mask), &mask) <0) {
        perror("sched_setaffinity");
    }
    printf ("result: %f\n", waste_time (2000));
    mask = 2;
    if (sched_setaffinity(0, sizeof(mask), &mask) <0) {
        perror("sched_setaffinity");
    }
    printf ("result: %f\n", waste_time (2000));
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
mask
unsigned long


decompiled_code:
double __fastcall waste_time(__int64 a1)
{
__int64 v1; // rdi
__int64 v2; // rbx
double v3; // xmm1_8
double v4; // xmm0_8
double v5; // xmm0_8

v1 = 200000 * a1;
if ( v1 <= 0 )
return 0.0;
v2 = 0LL;
v3 = 0.0;
do
{
v4 = (double)(int)++v2;
if ( (double)(int)v2 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
v3 = v3 + v5;
}
while ( v2 != v1 );
return v3;
}

canonical_decompiled_code:
double __fastcall func7(__int64 a1)
{
__int64 v1; // rdi
__int64 v2; // rbx
double v3; // xmm1_8
double v4; // xmm0_8
double v5; // xmm0_8

v1 = 200000 * a1;
if ( v1 <= 0 )
return 0.0;
v2 = 0LL;
v3 = 0.0;
do
{
v4 = (double)(int)++v2;
if ( (double)(int)v2 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
v3 = v3 + v5;
}
while ( v2 != v1 );
return v3;
}

original_code:
double waste_time(long n)
{
    double res = 0;
    long i = 0;
    while(i <n * 200000) {
        i++;
        res += sqrt (i);
    }
    return res;
}

variable_types: n long

variable_types: res double

variable_types: i long


decompiled_code:
char *__fastcall add_to_queue(char *src, char *a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // r8
char *v5; // rax
char *v6; // rdx

v2 = (char *)malloc(0x1008uLL);
if ( v2 )
{
v3 = strcpy(v2, src);
*((_QWORD *)v3 + 512) = 0LL;
v4 = v3;
if ( a2 )
{
v5 = a2;
do
{
v6 = v5;
v5 = (char *)*((_QWORD *)v5 + 512);
}
while ( v5 );
*((_QWORD *)v6 + 512) = v4;
v4 = a2;
}
}
else
{
fprintf(stderr, "%s: malloc of %lu bytes failed\n", "add_to_queue", 4104LL);
v4 = a2;
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char *src, char *a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // r8
char *v5; // rax
char *v6; // rdx

v2 = (char *)malloc(0x1008uLL);
if ( v2 )
{
v3 = strcpy(v2, src);
*((_QWORD *)v3 + 512) = 0LL;
v4 = v3;
if ( a2 )
{
v5 = a2;
do
{
v6 = v5;
v5 = (char *)*((_QWORD *)v5 + 512);
}
while ( v5 );
*((_QWORD *)v6 + 512) = v4;
v4 = a2;
}
}
else
{
fprintf(stderr, "%s: malloc of %lu bytes failed\n", "add_to_queue", 4104LL);
v4 = a2;
}
return v4;
}

original_code:
queue* add_to_queue (char *commandstr, queue *cmdQueuePtr)
{
  queue *temp;
  queue *newptr = malloc (sizeof (queue));
  if (!newptr) {
    fprintf (stderr, "%s: malloc of %lu bytes failed\n", __FUNCTION__, sizeof(queue));
    return cmdQueuePtr;
  }
  strcpy (newptr->cmd, commandstr);
  newptr->next = ((void *)0);
  if (cmdQueuePtr) {
    temp = cmdQueuePtr;
    while(temp->next)
      temp = temp->next;
    temp->next = newptr;
  } else {
    cmdQueuePtr = newptr;
  }
  return cmdQueuePtr;
}

canonical_original_code:
struct node *add_to_queue(char *commandstr, struct node *cmdQueuePtr)
{
  struct node *temp;
  struct node *newptr = malloc (sizeof (queue));
  if (!newptr) {
    fprintf (stderr, "%s: malloc of %lu bytes failed\n", __FUNCTION__, sizeof(queue));
    return cmdQueuePtr;
  }
  strcpy (newptr->cmd, commandstr);
  newptr->next = ((void *)0);
  if (cmdQueuePtr) {
    temp = cmdQueuePtr;
    while(temp->next)
      temp = temp->next;
    temp->next = newptr;
  } else {
    cmdQueuePtr = newptr;
  }
  return cmdQueuePtr;
}

variable_types:
commandstr
char *

variable_types:
cmdQueuePtr
struct node *

variable_types: struct node { char cmd[4096]; struct node *next; } *


decompiled_code:
__int64 __fastcall pull_from_queue(char *a1, __int64 a2)
{
__int64 v2; // r12

v2 = 0LL;
if ( a2 )
{
v2 = *(_QWORD *)(a2 + 4096);
strcpy(a1, (const char *)a2);
free((void *)a2);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, __int64 a2)
{
__int64 v2; // r12

v2 = 0LL;
if ( a2 )
{
v2 = *(_QWORD *)(a2 + 4096);
strcpy(a1, (const char *)a2);
free((void *)a2);
}
return v2;
}

original_code:
queue* pull_from_queue (char *commandstr, queue *cmdQueuePtr)
{
  queue *tempptr;
  if (cmdQueuePtr) {
    tempptr = cmdQueuePtr->next;
    strcpy (commandstr, cmdQueuePtr->cmd);
    free (cmdQueuePtr);
    return tempptr;
  } else {
    return ((void *)0);
  }
}

canonical_original_code:
struct node *pull_from_queue(char *commandstr, struct node *cmdQueuePtr)
{
  struct node *tempptr;
  if (cmdQueuePtr) {
    tempptr = cmdQueuePtr->next;
    strcpy (commandstr, cmdQueuePtr->cmd);
    free (cmdQueuePtr);
    return tempptr;
  } else {
    return ((void *)0);
  }
}

return_type: struct node { char cmd[4096]; struct node *next; } *


decompiled_code:
void __fastcall free_queue(_QWORD *a1)
{
if ( a1 )
{
if ( a1[512] )
free_queue();
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
if ( a1 )
{
if ( a1[512] )
func2();
free(a1);
}
}

original_code:
void free_queue (queue *cmdQueuePtr) {
  if (cmdQueuePtr) {
    if (cmdQueuePtr->next) {
      free_queue (cmdQueuePtr->next);
      cmdQueuePtr->next = ((void *)0);
    }
    free (cmdQueuePtr);
  }
  return;
}

canonical_original_code:
void free_queue(struct node *cmdQueuePtr) {
  if (cmdQueuePtr) {
    if (cmdQueuePtr->next) {
      free_queue (cmdQueuePtr->next);
      cmdQueuePtr->next = ((void *)0);
    }
    free (cmdQueuePtr);
  }
  return;
}

user_defined_types: struct node { char cmd[4096]; struct node *next; }


decompiled_code:
char *__fastcall get_config_path(char *src)
{
char *v1; // r12
int v2; // er13
int v3; // ebx
char *v4; // rax
int *v6; // rax
char *v7; // rax

v1 = getcwd(0LL, 0LL);
if ( v1 )
{
v2 = strlen(src);
v3 = strlen(v1);
v4 = (char *)realloc(v1, v2 + v3 + 2);
v1 = v4;
if ( v4 )
{
v4[v3] = 47;
strncpy(&v4[v3 + 1], src, v2 + 1);
}
else
{
fprintf(stderr, "%s: realloc: could not allocate required space\n", "get_config_path");
}
}
else
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s: getcwd: %s\n", "get_config_path", v7);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
char *v1; // r12
int v2; // er13
int v3; // ebx
char *v4; // rax
int *v6; // rax
char *v7; // rax

v1 = getcwd(0LL, 0LL);
if ( v1 )
{
v2 = strlen(src);
v3 = strlen(v1);
v4 = (char *)realloc(v1, v2 + v3 + 2);
v1 = v4;
if ( v4 )
{
v4[v3] = 47;
strncpy(&v4[v3 + 1], src, v2 + 1);
}
else
{
fprintf(stderr, "%s: realloc: could not allocate required space\n", "get_config_path");
}
}
else
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s: getcwd: %s\n", "get_config_path", v7);
}
return v1;
}

original_code:
char *get_config_path (const char *filename)
{
  int filenameSize, pathSize, absPathSize;
  char *path;
  if ((path = getcwd (((void *)0), 0)) == ((void *)0)) {
    fprintf (stderr, "%s: getcwd: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
    return ((void *)0);
  }
  filenameSize = strlen (filename);
  pathSize = strlen (path);
  absPathSize = (filenameSize + 1) + (pathSize + 1);
  if ((path = realloc (path, absPathSize)) == ((void *)0)) {
    fprintf (stderr, "%s: realloc: could not allocate required space\n",
      __FUNCTION__);
    return ((void *)0);
  }
  path[pathSize] = '/';
  strncpy ((path + pathSize + 1), filename, (filenameSize + 1));
  return path;
}

canonical_original_code:
char *get_config_path(char *filename)
{
  int filenameSize; int pathSize; int absPathSize;
  char *path;
  if ((path = getcwd (((void *)0), 0)) == ((void *)0)) {
    fprintf (stderr, "%s: getcwd: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
    return ((void *)0);
  }
  filenameSize = strlen (filename);
  pathSize = strlen (path);
  absPathSize = (filenameSize + 1) + (pathSize + 1);
  if ((path = realloc (path, absPathSize)) == ((void *)0)) {
    fprintf (stderr, "%s: realloc: could not allocate required space\n",
      __FUNCTION__);
    return ((void *)0);
  }
  path[pathSize] = '/';
  strncpy ((path + pathSize + 1), filename, (filenameSize + 1));
  return path;
}

variable_types:
filename
char *

variable_types: filenameSize int

variable_types: pathSize int

variable_types: absPathSize int

variable_types:
path
char *


decompiled_code:
__int64 __fastcall within_rootdir(char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbp
__int64 result; // rax
int *v5; // rax
char *v6; // rax

v2 = canonicalize_file_name(a1);
if ( v2 )
{
v3 = v2;
if ( strstr(v2, rootdir) )
{
LABEL_3:
free(v3);
return 1LL;
}
if ( a2 )
{
strcat(a1, a2);
if ( (unsigned __int8)within_rootdir(a1, 0LL) )
{
*a1 = 0;
goto LABEL_3;
}
*a1 = 0;
free(v3);
result = 0LL;
}
else
{
fprintf(stderr, "%s: pathname out of rootdir scope\n", "within_rootdir");
free(v3);
result = 0LL;
}
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s: canonicalize_file_name: %s\n", "within_rootdir", v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbp
__int64 result; // rax
int *v5; // rax
char *v6; // rax

v2 = canonicalize_file_name(a1);
if ( v2 )
{
v3 = v2;
if ( strstr(v2, rootdir) )
{
LABEL_3:
free(v3);
return 1LL;
}
if ( a2 )
{
strcat(a1, a2);
if ( (unsigned __int8)func0(a1, 0LL) )
{
*a1 = 0;
goto LABEL_3;
}
*a1 = 0;
free(v3);
result = 0LL;
}
else
{
fprintf(stderr, "%s: pathname out of rootdir scope\n", "within_rootdir");
free(v3);
result = 0LL;
}
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s: canonicalize_file_name: %s\n", "within_rootdir", v6);
result = 0LL;
}
return result;
}

original_code:
static _Bool within_rootdir (char *fullpath, const char *trimmed)
{
  char *canon;
  char *str;
  if ((canon = canonicalize_file_name (fullpath)) == ((void *)0)) {
    fprintf (stderr, "%s: canonicalize_file_name: %s\n", __FUNCTION__,
      strerror ((*__errno_location ())));
    return 0;
  }
  if (strstr (canon, rootdir) == ((void *)0)) {
    if (trimmed != ((void *)0)) {
      str = strcat (fullpath, trimmed);
      if (!within_rootdir (fullpath, ((void *)0))) {
 *str = '\0';
 free (canon);
 return 0;
      }
      *str = '\0';
    } else {
      fprintf (stderr, "%s: pathname out of rootdir scope\n", __FUNCTION__);
      free (canon);
      return 0;
    }
  }
  free (canon);
  return 1;
}

canonical_original_code:
static _Bool within_rootdir(char *fullpath, char *trimmed)
{
  char *canon;
  char *str;
  if ((canon = canonicalize_file_name (fullpath)) == ((void *)0)) {
    fprintf (stderr, "%s: canonicalize_file_name: %s\n", __FUNCTION__,
      strerror ((*__errno_location ())));
    return 0;
  }
  if (strstr (canon, rootdir) == ((void *)0)) {
    if (trimmed != ((void *)0)) {
      str = strcat (fullpath, trimmed);
      if (!within_rootdir (fullpath, ((void *)0))) {
 *str = '\0';
 free (canon);
 return 0;
      }
      *str = '\0';
    } else {
      fprintf (stderr, "%s: pathname out of rootdir scope\n", __FUNCTION__);
      free (canon);
      return 0;
    }
  }
  free (canon);
  return 1;
}

variable_types:
fullpath
char *

variable_types:
trimmed
char *

variable_types:
canon
char *

variable_types:
str
char *


decompiled_code:
__int64 __fastcall is_a_dir(const char *a1)
{
int v1; // er8
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 != -1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // er8
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 != -1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

original_code:
_Bool is_a_dir (const char *fullpath)
{
  struct stat st;
  if (stat (fullpath, &st) == -1) {
    return 0;
  }
  if (!(st.st_mode & 0040000)) {
    return 0;
  }
  return 1;
}

canonical_original_code:
_Bool is_a_dir(char *fullpath)
{
  struct stat st;
  if (stat (fullpath, &st) == -1) {
    return 0;
  }
  if (!(st.st_mode & 0040000)) {
    return 0;
  }
  return 1;
}

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

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


decompiled_code:
__int64 __fastcall is_unique(const char *a1)
{
unsigned int v1; // er12
int v2; // edi
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v5) == -1 )
{
v1 = -1;
v2 = *_errno_location();
if ( v2 == 2 )
{
v1 = 0;
}
else
{
v4 = strerror(v2);
fprintf(stderr, "%s: stat: %s\n", "is_unique", v4);
}
}
else
{
v1 = -2;
fprintf(stderr, "%s: stat: FUTURE_UNIQ file exists\n", "is_unique");
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // er12
int v2; // edi
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v5) == -1 )
{
v1 = -1;
v2 = *_errno_location();
if ( v2 == 2 )
{
v1 = 0;
}
else
{
v4 = strerror(v2);
fprintf(stderr, "%s: stat: %s\n", "is_unique", v4);
}
}
else
{
v1 = -2;
fprintf(stderr, "%s: stat: FUTURE_UNIQ file exists\n", "is_unique");
}
return v1;
}

original_code:
static int is_unique (const char *fullpath)
{
  struct stat st;
  if (stat (fullpath, &st) == -1) {
    if ((*__errno_location ()) == 2) {
      return 0;
    } else {
      fprintf (stderr, "%s: stat: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      return -1;
    }
  } else {
    fprintf (stderr, "%s: stat: FUTURE_UNIQ file exists\n", __FUNCTION__);
    return -2;
  }
}

canonical_original_code:
static int is_unique(char *fullpath)
{
  struct stat st;
  if (stat (fullpath, &st) == -1) {
    if ((*__errno_location ()) == 2) {
      return 0;
    } else {
      fprintf (stderr, "%s: stat: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      return -1;
    }
  } else {
    fprintf (stderr, "%s: stat: FUTURE_UNIQ file exists\n", __FUNCTION__);
    return -2;
  }
}

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


decompiled_code:
char *__fastcall merge_absolute(char *s, _DWORD *a2)
{
char *v2; // r12
const char *v3; // r13
int v4; // er12
int v5; // eax
char *v6; // rax

if ( !s )
return 0LL;
v2 = 0LL;
if ( *s == 47 )
{
v3 = rootdir;
v4 = strlen(rootdir);
v5 = strlen(s) + 1;
if ( a2 )
v5 += *a2;
v6 = (char *)malloc(v5 + v4 + 1);
v2 = v6;
if ( v6 )
{
strcpy(v6, v3);
strcat(v2, s);
}
else
{
fprintf(stderr, "%s: malloc: could not allocate the required space\n", "merge_absolute");
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, _DWORD *a2)
{
char *v2; // r12
const char *v3; // r13
int v4; // er12
int v5; // eax
char *v6; // rax

if ( !s )
return 0LL;
v2 = 0LL;
if ( *s == 47 )
{
v3 = rootdir;
v4 = strlen(rootdir);
v5 = strlen(s) + 1;
if ( a2 )
v5 += *a2;
v6 = (char *)malloc(v5 + v4 + 1);
v2 = v6;
if ( v6 )
{
strcpy(v6, v3);
strcat(v2, s);
}
else
{
fprintf(stderr, "%s: malloc: could not allocate the required space\n", "merge_absolute");
}
}
return v2;
}

original_code:
static char *merge_absolute (const char *argpath, const int *reserve)
{
  char *fullpath;
  int rootdirStrlen;
  int argpathStrlen;
  int pathSize;
  if (argpath == ((void *)0))
    return ((void *)0);
  if (argpath[0] != '/')
    return ((void *)0);
  rootdirStrlen = strlen (rootdir);
  argpathStrlen = strlen (argpath) + 1;
  if (reserve != ((void *)0))
    argpathStrlen += *reserve;
  pathSize = argpathStrlen + rootdirStrlen + 1;
  if ((fullpath = malloc (pathSize * sizeof (*fullpath))) == ((void *)0)) {
    fprintf (stderr, "%s: malloc: could not allocate the required space\n",
      __FUNCTION__);
    return ((void *)0);
  }
  *fullpath = '\0';
  strcat (fullpath, rootdir);
  strcat (fullpath, argpath);
  return fullpath;
}

canonical_original_code:
static char *merge_absolute(char *argpath, int *reserve)
{
  char *fullpath;
  int rootdirStrlen;
  int argpathStrlen;
  int pathSize;
  if (argpath == ((void *)0))
    return ((void *)0);
  if (argpath[0] != '/')
    return ((void *)0);
  rootdirStrlen = strlen (rootdir);
  argpathStrlen = strlen (argpath) + 1;
  if (reserve != ((void *)0))
    argpathStrlen += *reserve;
  pathSize = argpathStrlen + rootdirStrlen + 1;
  if ((fullpath = malloc (pathSize * sizeof (*fullpath))) == ((void *)0)) {
    fprintf (stderr, "%s: malloc: could not allocate the required space\n",
      __FUNCTION__);
    return ((void *)0);
  }
  *fullpath = '\0';
  strcat (fullpath, rootdir);
  strcat (fullpath, argpath);
  return fullpath;
}

variable_types:
argpath
char *

variable_types:
reserve
int *

variable_types: rootdirStrlen int

variable_types: argpathStrlen int


decompiled_code:
char *__fastcall merge_paths(void *src, char *s, int *a3)
{
char *v4; // r12
void *v5; // rsp
char v6; // al
char *v7; // rdx
int v8; // ecx
__int64 v9; // rsi
char *v10; // r15
char *v12; // r14
int v13; // er15
int v14; // eax
int v15; // edx
int v16; // eax
int v17; // ecx
char *v18; // rax
size_t v19; // r12
size_t v20; // rax
char *v21; // rax
size_t v22; // rbx
char *v23; // rax
char v24[8]; // [rsp+0h] [rbp-50h] BYREF
size_t v25; // [rsp+8h] [rbp-48h]
size_t n; // [rsp+10h] [rbp-40h]
size_t v27; // [rsp+18h] [rbp-38h]

if ( s )
{
v4 = s;
v5 = alloca(strlen(s) + 1);
v6 = *s;
if ( *s )
{
v7 = s;
v8 = 0;
do
{
++v7;
if ( v6 != 32 )
{
v9 = v8++;
v24[v9] = v6;
}
v6 = *v7;
}
while ( *v7 );
}
else
{
v8 = 0;
}
v24[v8] = 0;
strcpy(v4, v24);
v10 = merge_absolute(v4, a3);
if ( v10 || *v4 == 47 )
return v10;
v12 = rootdir;
n = strlen(rootdir);
v13 = n + 1;
v25 = strlen((const char *)src);
LODWORD(v27) = v25 + 1;
v14 = strlen(v4);
v15 = v27;
v16 = v14 + 1;
if ( a3 )
{
v17 = *a3;
goto LABEL_12;
}
v21 = (char *)malloc(v16 + v13 + (int)v27);
v10 = v21;
if ( v21 )
{
v22 = n;
memcpy(v21, v12, n);
memcpy(&v10[v22], src, v25 + 1);
goto LABEL_14;
}
LABEL_23:
v10 = 0LL;
fprintf(stderr, "%s: malloc: could not allocate required space\n", "merge_paths");
return v10;
}
v10 = merge_absolute(0LL, a3);
if ( v10 )
return v10;
v12 = rootdir;
v19 = strlen(rootdir);
v13 = v19 + 1;
v20 = strlen((const char *)src);
v15 = v20 + 1;
if ( !a3 )
{
v27 = v20;
v23 = (char *)malloc(v13 + v15);
v10 = v23;
if ( v23 )
{
memcpy(v23, v12, v19);
memcpy(&v10[v19], src, v27 + 1);
return v10;
}
goto LABEL_23;
}
v16 = *a3;
v4 = 0LL;
v17 = *a3;
LABEL_12:
v18 = (char *)malloc(v17 + v16 + v13 + v15);
v10 = v18;
if ( !v18 )
goto LABEL_23;
strcpy(v18, v12);
strcat(v10, (const char *)src);
if ( v4 )
LABEL_14:
strcat(v10, v4);
return v10;
}

canonical_decompiled_code:
char *__fastcall func6(void *src, char *s, int *a3)
{
char *v4; // r12
void *v5; // rsp
char v6; // al
char *v7; // rdx
int v8; // ecx
__int64 v9; // rsi
char *v10; // r15
char *v12; // r14
int v13; // er15
int v14; // eax
int v15; // edx
int v16; // eax
int v17; // ecx
char *v18; // rax
size_t v19; // r12
size_t v20; // rax
char *v21; // rax
size_t v22; // rbx
char *v23; // rax
char v24[8]; // [rsp+0h] [rbp-50h] BYREF
size_t v25; // [rsp+8h] [rbp-48h]
size_t n; // [rsp+10h] [rbp-40h]
size_t v27; // [rsp+18h] [rbp-38h]

if ( s )
{
v4 = s;
v5 = alloca(strlen(s) + 1);
v6 = *s;
if ( *s )
{
v7 = s;
v8 = 0;
do
{
++v7;
if ( v6 != 32 )
{
v9 = v8++;
v24[v9] = v6;
}
v6 = *v7;
}
while ( *v7 );
}
else
{
v8 = 0;
}
v24[v8] = 0;
strcpy(v4, v24);
v10 = func3(v4, a3);
if ( v10 || *v4 == 47 )
return v10;
v12 = rootdir;
n = strlen(rootdir);
v13 = n + 1;
v25 = strlen((const char *)src);
LODWORD(v27) = v25 + 1;
v14 = strlen(v4);
v15 = v27;
v16 = v14 + 1;
if ( a3 )
{
v17 = *a3;
goto LABEL_12;
}
v21 = (char *)malloc(v16 + v13 + (int)v27);
v10 = v21;
if ( v21 )
{
v22 = n;
memcpy(v21, v12, n);
memcpy(&v10[v22], src, v25 + 1);
goto LABEL_14;
}
LABEL_23:
v10 = 0LL;
fprintf(stderr, "%s: malloc: could not allocate required space\n", "merge_paths");
return v10;
}
v10 = func3(0LL, a3);
if ( v10 )
return v10;
v12 = rootdir;
v19 = strlen(rootdir);
v13 = v19 + 1;
v20 = strlen((const char *)src);
v15 = v20 + 1;
if ( !a3 )
{
v27 = v20;
v23 = (char *)malloc(v13 + v15);
v10 = v23;
if ( v23 )
{
memcpy(v23, v12, v19);
memcpy(&v10[v19], src, v27 + 1);
return v10;
}
goto LABEL_23;
}
v16 = *a3;
v4 = 0LL;
v17 = *a3;
LABEL_12:
v18 = (char *)malloc(v17 + v16 + v13 + v15);
v10 = v18;
if ( !v18 )
goto LABEL_23;
strcpy(v18, v12);
strcat(v10, (const char *)src);
if ( v4 )
LABEL_14:
strcat(v10, v4);
return v10;
}

original_code:
char *merge_paths (const char *cwd, char *argpath, const int *reserve)
{
  char *fullpath;
  char *start;
  int rootdirStrlen;
  int cwdStrlen;
  int argStrlen;
  int i = 0;
  if (argpath != ((void *)0)) {
    start = argpath;
    char argTemp[strlen (argpath) + 1];
    while (*argpath != '\0') {
      if (*argpath != ' ')
 argTemp[i++] = *argpath++;
      else
 argpath++;
    }
    argTemp[i] = '\0';
    argpath = strcpy (start, argTemp);
  }
  if ((fullpath = merge_absolute (argpath, reserve)) != ((void *)0))
    return fullpath;
  if (fullpath == ((void *)0)) {
    if ((argpath != ((void *)0)) && (argpath[0] == '/'))
      return ((void *)0);
  }
  rootdirStrlen = strlen (rootdir) + 1;
  cwdStrlen = strlen (cwd) + 1;
  if (argpath == ((void *)0)) {
    if (reserve == ((void *)0)) {
      argStrlen = 0;
    } else {
      argStrlen = 0 + *reserve;
    }
  } else {
    argStrlen = strlen (argpath) + 1;
  }
  if (reserve != ((void *)0))
    argStrlen += *reserve;
  if ((fullpath = malloc ((rootdirStrlen + cwdStrlen + argStrlen)
     * sizeof (*fullpath))) == ((void *)0)) {
    fprintf (stderr, "%s: malloc: could not allocate required space\n",
      __FUNCTION__);
    return ((void *)0);
  }
  strcpy (fullpath, rootdir);
  strcat (fullpath, cwd);
  if (argpath != ((void *)0))
    strcat (fullpath, argpath);
  return fullpath;
}

canonical_original_code:
char *merge_paths(char *cwd, char *argpath, int *reserve)
{
  char *fullpath;
  char *start;
  int rootdirStrlen;
  int cwdStrlen;
  int argStrlen;
  int i = 0;
  if (argpath != ((void *)0)) {
    start = argpath;
    char argTemp[-1];
    while (*argpath != '\0') {
      if (*argpath != ' ')
 argTemp[i++] = *argpath++;
      else
 argpath++;
    }
    argTemp[i] = '\0';
    argpath = strcpy (start, argTemp);
  }
  if ((fullpath = merge_absolute (argpath, reserve)) != ((void *)0))
    return fullpath;
  if (fullpath == ((void *)0)) {
    if ((argpath != ((void *)0)) && (argpath[0] == '/'))
      return ((void *)0);
  }
  rootdirStrlen = strlen (rootdir) + 1;
  cwdStrlen = strlen (cwd) + 1;
  if (argpath == ((void *)0)) {
    if (reserve == ((void *)0)) {
      argStrlen = 0;
    } else {
      argStrlen = 0 + *reserve;
    }
  } else {
    argStrlen = strlen (argpath) + 1;
  }
  if (reserve != ((void *)0))
    argStrlen += *reserve;
  if ((fullpath = malloc ((rootdirStrlen + cwdStrlen + argStrlen)
     * sizeof (*fullpath))) == ((void *)0)) {
    fprintf (stderr, "%s: malloc: could not allocate required space\n",
      __FUNCTION__);
    return ((void *)0);
  }
  strcpy (fullpath, rootdir);
  strcat (fullpath, cwd);
  if (argpath != ((void *)0))
    strcat (fullpath, argpath);
  return fullpath;
}

variable_types:
cwd
char *

variable_types:
start
char *

variable_types: cwdStrlen int

variable_types: argStrlen int

variable_types: i int

variable_types:
argTemp
char [-1]


decompiled_code:
__int64 __fastcall check_file_exist(void *a1, char *a2)
{
unsigned int v2; // er12
char *v3; // rax
char *v4; // rbp

v2 = 0;
v3 = merge_paths(a1, a2, 0LL);
if ( v3 )
{
v4 = v3;
v2 = within_rootdir(v3, 0LL);
free(v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *a1, char *a2)
{
unsigned int v2; // er12
char *v3; // rax
char *v4; // rbp

v2 = 0;
v3 = func6(a1, a2, 0LL);
if ( v3 )
{
v4 = v3;
v2 = func0(v3, 0LL);
free(v4);
}
return v2;
}

original_code:
_Bool check_file_exist (const char *cwd, char *argpath)
{
  char *fullpath;
  if ((fullpath = merge_paths (cwd, argpath, ((void *)0))) == ((void *)0))
    return 0;
  if (!within_rootdir (fullpath, ((void *)0))) {
    free (fullpath);
    return 0;
  }
  free (fullpath);
  return 1;
}

canonical_original_code:
_Bool check_file_exist(char *cwd, char *argpath)
{
  char *fullpath;
  if ((fullpath = merge_paths (cwd, argpath, ((void *)0))) == ((void *)0))
    return 0;
  if (!within_rootdir (fullpath, ((void *)0))) {
    free (fullpath);
    return 0;
  }
  free (fullpath);
  return 1;
}


decompiled_code:
__int64 __fastcall check_dir_exist(void *a1, char *a2)
{
unsigned int v2; // er12
char *v3; // rax
char *v4; // rbp
char *v5; // rdi
unsigned int v6; // eax

v2 = 0;
v3 = merge_paths(a1, a2, 0LL);
if ( v3 )
{
v4 = v3;
v5 = v3;
v2 = within_rootdir(v3, 0LL);
if ( (_BYTE)v2 )
{
v6 = is_a_dir(v5);
v5 = v4;
v2 = v6;
}
free(v5);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *a1, char *a2)
{
unsigned int v2; // er12
char *v3; // rax
char *v4; // rbp
char *v5; // rdi
unsigned int v6; // eax

v2 = 0;
v3 = func6(a1, a2, 0LL);
if ( v3 )
{
v4 = v3;
v5 = v3;
v2 = func0(v3, 0LL);
if ( (_BYTE)v2 )
{
v6 = func1(v5);
v5 = v4;
v2 = v6;
}
free(v5);
}
return v2;
}

original_code:
_Bool check_dir_exist (const char *cwd, char *argpath)
{
  char *fullpath;
  if ((fullpath = merge_paths (cwd, argpath, ((void *)0))) == ((void *)0))
    return 0;
  if (!within_rootdir (fullpath, ((void *)0))) {
    free (fullpath);
    return 0;
  }
  if (!is_a_dir (fullpath)) {
    free (fullpath);
    return 0;
  }
  free (fullpath);
  return 1;
}

canonical_original_code:
_Bool check_dir_exist(char *cwd, char *argpath)
{
  char *fullpath;
  if ((fullpath = merge_paths (cwd, argpath, ((void *)0))) == ((void *)0))
    return 0;
  if (!within_rootdir (fullpath, ((void *)0))) {
    free (fullpath);
    return 0;
  }
  if (!is_a_dir (fullpath)) {
    free (fullpath);
    return 0;
  }
  free (fullpath);
  return 1;
}


decompiled_code:
__int64 __fastcall check_future_file(void *src, char *s, char a3)
{
__int64 v4; // rax
char *v5; // r12
void *v6; // rdi
int v7; // eax
char v8; // al
__int64 result; // rax
int v10; // [rsp+14h] [rbp-34h] BYREF
void *ptr; // [rsp+18h] [rbp-30h] BYREF

v4 = trim_arg_path_isra_0(s, &v10);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = (char *)v4;
ptr = merge_paths(src, s, &v10);
if ( !ptr )
return 0xFFFFFFFFLL;
if ( (unsigned __int8)within_rootdir((char *)ptr, v5) )
{
restore_trimmed_isra_0(s, (char **)&ptr, v5);
v6 = ptr;
if ( !a3 )
goto LABEL_8;
v7 = is_unique((const char *)ptr);
if ( !v7 )
goto LABEL_9;
v6 = ptr;
if ( v7 != -1 )
{
if ( v7 == -2 )
{
LABEL_11:
free(v6);
return 4294967293LL;
}
LABEL_8:
v8 = is_a_dir((const char *)v6);
v6 = ptr;
if ( !v8 )
{
LABEL_9:
free(ptr);
return 0LL;
}
goto LABEL_11;
}
free(ptr);
result = 0xFFFFFFFFLL;
}
else
{
free(ptr);
free(v5);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *src, char *s, char a3)
{
__int64 v4; // rax
char *v5; // r12
void *v6; // rdi
int v7; // eax
char v8; // al
__int64 result; // rax
int v10; // [rsp+14h] [rbp-34h] BYREF
void *ptr; // [rsp+18h] [rbp-30h] BYREF

v4 = func5(s, &v10);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = (char *)v4;
ptr = func6(src, s, &v10);
if ( !ptr )
return 0xFFFFFFFFLL;
if ( (unsigned __int8)func0((char *)ptr, v5) )
{
func4(s, (char **)&ptr, v5);
v6 = ptr;
if ( !a3 )
goto LABEL_8;
v7 = func2((const char *)ptr);
if ( !v7 )
goto LABEL_9;
v6 = ptr;
if ( v7 != -1 )
{
if ( v7 == -2 )
{
LABEL_11:
free(v6);
return 4294967293LL;
}
LABEL_8:
v8 = func1((const char *)v6);
v6 = ptr;
if ( !v8 )
{
LABEL_9:
free(ptr);
return 0LL;
}
goto LABEL_11;
}
free(ptr);
result = 0xFFFFFFFFLL;
}
else
{
free(ptr);
free(v5);
result = 4294967294LL;
}
return result;
}

original_code:
int check_future_file (const char *cwd, char *argpath, _Bool unique)
{
  char *fullpath;
  char *trimmed;
  int reserve;
  int uniqRet;
  if ((trimmed = trim_arg_path (&argpath, &reserve)) == ((void *)0))
    return -1;
  if ((fullpath = merge_paths (cwd, argpath, &reserve)) == ((void *)0))
    return -1;
  if (!within_rootdir (fullpath, trimmed)) {
    free (fullpath);
    free (trimmed);
    return -2;
  }
  restore_trimmed (&argpath, &fullpath, trimmed);
  if (unique) {
    if ((uniqRet = is_unique (fullpath)) == 0) {
      free (fullpath);
      return 0;
    } else if (uniqRet == -1) {
      free (fullpath);
      return -1;
    } else if (uniqRet == -2) {
      free (fullpath);
      return -3;
    }
  }
  if (is_a_dir (fullpath)) {
    free (fullpath);
    return -3;
  }
  free (fullpath);
  return 0;
}

canonical_original_code:
int check_future_file(char *cwd, char *argpath, _Bool unique)
{
  char *fullpath;
  char *trimmed;
  int reserve;
  int uniqRet;
  if ((trimmed = trim_arg_path (&argpath, &reserve)) == ((void *)0))
    return -1;
  if ((fullpath = merge_paths (cwd, argpath, &reserve)) == ((void *)0))
    return -1;
  if (!within_rootdir (fullpath, trimmed)) {
    free (fullpath);
    free (trimmed);
    return -2;
  }
  restore_trimmed (&argpath, &fullpath, trimmed);
  if (unique) {
    if ((uniqRet = is_unique (fullpath)) == 0) {
      free (fullpath);
      return 0;
    } else if (uniqRet == -1) {
      free (fullpath);
      return -1;
    } else if (uniqRet == -2) {
      free (fullpath);
      return -3;
    }
  }
  if (is_a_dir (fullpath)) {
    free (fullpath);
    return -3;
  }
  free (fullpath);
  return 0;
}

variable_types: reserve int

variable_types: uniqRet int


decompiled_code:
__int64 __fastcall cmd_type(unsigned int *a1, char *a2)
{
unsigned int v2; // er12
size_t v3; // rax
__int64 result; // rax
__int32_t v5; // eax

v2 = *a1;
if ( !*((_BYTE *)a1 + 4168) )
return send_mesg_530(v2, 114LL);
if ( !a2 )
return send_mesg_501(v2);
v3 = strlen(a2);
if ( v3 != 1 )
{
if ( v3 != 3 || strcasecmp(a2, "a n") )
return send_mesg_504(v2);
goto LABEL_8;
}
v5 = (*_ctype_tolower_loc())[*a2];
*a2 = v5;
if ( (_BYTE)v5 == 97 )
{
LABEL_8:
result = send_mesg_200(v2, 97LL);
*((_BYTE *)a1 + 8268) = 97;
return result;
}
if ( (_BYTE)v5 != 105 )
return send_mesg_504(v2);
result = send_mesg_200(v2, 105LL);
*((_BYTE *)a1 + 8268) = 105;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, char *a2)
{
unsigned int v2; // er12
size_t v3; // rax
__int64 result; // rax
__int32_t v5; // eax

v2 = *a1;
if ( !*((_BYTE *)a1 + 4168) )
return send_mesg_530(v2, 114LL);
if ( !a2 )
return send_mesg_501(v2);
v3 = strlen(a2);
if ( v3 != 1 )
{
if ( v3 != 3 || strcasecmp(a2, "a n") )
return send_mesg_504(v2);
goto LABEL_8;
}
v5 = (*_ctype_tolower_loc())[*a2];
*a2 = v5;
if ( (_BYTE)v5 == 97 )
{
LABEL_8:
result = send_mesg_200(v2, 97LL);
*((_BYTE *)a1 + 8268) = 97;
return result;
}
if ( (_BYTE)v5 != 105 )
return send_mesg_504(v2);
result = send_mesg_200(v2, 105LL);
*((_BYTE *)a1 + 8268) = 105;
return result;
}

original_code:
void cmd_type (session_info_t *si, char *arg)
{
  int csfd = si->csfd;
  if (!si->loggedin) {
    send_mesg_530 (csfd, 'r');
    return;
  }
  if (!arg) {
    send_mesg_501 (csfd);
    return;
  }
  if (strlen (arg) == 1) {
    arg[0] = tolower (arg[0]);
    if (arg[0] == 'a') {
      send_mesg_200 (csfd, 'a');
      si->type = 'a';
    } else if (arg[0] == 'i') {
      send_mesg_200 (csfd, 'i');
      si->type = 'i';
    } else {
      send_mesg_504 (csfd);
    }
    return;
  }
  if (strlen (arg) == 3) {
    if (strcasecmp (arg, "a n") == 0) {
      send_mesg_200 (csfd, 'a');
      si->type ='a';
      return;
    }
  }
  send_mesg_504 (csfd);
  return;
}

canonical_original_code:
void cmd_type(struct session_info_t *si, char *arg)
{
  int csfd = si->csfd;
  if (!si->loggedin) {
    send_mesg_530 (csfd, 'r');
    return;
  }
  if (!arg) {
    send_mesg_501 (csfd);
    return;
  }
  if (strlen (arg) == 1) {
    arg[0] = tolower (arg[0]);
    if (arg[0] == 'a') {
      send_mesg_200 (csfd, 'a');
      si->type = 'a';
    } else if (arg[0] == 'i') {
      send_mesg_200 (csfd, 'i');
      si->type = 'i';
    } else {
      send_mesg_504 (csfd);
    }
    return;
  }
  if (strlen (arg) == 3) {
    if (strcasecmp (arg, "a n") == 0) {
      send_mesg_200 (csfd, 'a');
      si->type ='a';
      return;
    }
  }
  send_mesg_504 (csfd);
  return;
}

variable_types: struct session_info_t { int csfd; int dsfd; char cwd[4096]; char user[64]; _Bool loggedin; _Bool cmdComplete; _Bool cmdAbort; _Bool cmdQuit; char cmdString[4096]; char type; } *

variable_types:
arg
char *

variable_types: csfd int


decompiled_code:
__int64 __fastcall cmd_mode(unsigned int *a1, char *a2)
{
unsigned int v2; // ebp
__int64 result; // rax
__int32_t v4; // eax

v2 = *a1;
if ( a2 && strlen(a2) == 1 && (v4 = (*_ctype_tolower_loc())[*a2], *a2 = v4, (_BYTE)v4 == 115) )
result = send_mesg_200(v2, 115LL);
else
result = send_mesg_504(v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, char *a2)
{
unsigned int v2; // ebp
__int64 result; // rax
__int32_t v4; // eax

v2 = *a1;
if ( a2 && strlen(a2) == 1 && (v4 = (*_ctype_tolower_loc())[*a2], *a2 = v4, (_BYTE)v4 == 115) )
result = send_mesg_200(v2, 115LL);
else
result = send_mesg_504(v2);
return result;
}

original_code:
void cmd_mode (session_info_t *si, char *arg)
{
  int csfd = si->csfd;
  if (arg) {
    if (strlen (arg) == 1) {
      arg[0] = tolower (arg[0]);
      if (arg[0] == 's') {
 send_mesg_200 (csfd, 's');
 return;
      }
    }
  }
  send_mesg_504 (csfd);
  return;
}

canonical_original_code:
void cmd_mode(struct session_info_t *si, char *arg)
{
  int csfd = si->csfd;
  if (arg) {
    if (strlen (arg) == 1) {
      arg[0] = tolower (arg[0]);
      if (arg[0] == 's') {
 send_mesg_200 (csfd, 's');
 return;
      }
    }
  }
  send_mesg_504 (csfd);
  return;
}

user_defined_types: struct session_info_t { int csfd; int dsfd; char cwd[4096]; char user[64]; _Bool loggedin; _Bool cmdComplete; _Bool cmdAbort; _Bool cmdQuit; char cmdString[4096]; char type; }


decompiled_code:
__int64 __fastcall cmd_syst(unsigned int *a1)
{
return send_mesg_215(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
return send_mesg_215(*a1);
}

original_code:
void cmd_syst (session_info_t *si)
{
  send_mesg_215 (si->csfd);
}

canonical_original_code:
void cmd_syst(struct session_info_t *si)
{
  send_mesg_215 (si->csfd);
}


decompiled_code:
__int64 __fastcall cmd_stru(unsigned int *a1, _BYTE *a2, int a3)
{
__int64 v3; // rdi

v3 = *a1;
if ( a3 > 1 || !a2 )
return send_mesg_501(v3);
if ( *a2 != 70 || a2[1] )
return send_mesg_504(v3);
return send_mesg_200(v3, 102LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, _BYTE *a2, int a3)
{
__int64 v3; // rdi

v3 = *a1;
if ( a3 > 1 || !a2 )
return send_mesg_501(v3);
if ( *a2 != 70 || a2[1] )
return send_mesg_504(v3);
return send_mesg_200(v3, 102LL);
}

original_code:
void cmd_stru (session_info_t *si, char *arg, int numArgs)
{
  int csfd = si->csfd;
  if ((numArgs > 1) || (arg == ((void *)0))) {
    send_mesg_501 (csfd);
    return;
  }
  if (strcmp (arg, "F") == 0) {
    send_mesg_200 (csfd, 'f');
  } else {
    send_mesg_504 (csfd);
  }
}

canonical_original_code:
void cmd_stru(struct session_info_t *si, char *arg, int numArgs)
{
  int csfd = si->csfd;
  if ((numArgs > 1) || (arg == ((void *)0))) {
    send_mesg_501 (csfd);
    return;
  }
  if (strcmp (arg, "F") == 0) {
    send_mesg_200 (csfd, 'f');
  } else {
    send_mesg_504 (csfd);
  }
}

variable_types: numArgs int


decompiled_code:
__int64 __fastcall cmd_quit(unsigned int *a1)
{
__int64 result; // rax

result = send_mesg_221(*a1);
*((_BYTE *)a1 + 4171) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 result; // rax

result = send_mesg_221(*a1);
*((_BYTE *)a1 + 4171) = 1;
return result;
}

original_code:
void cmd_quit (session_info_t *si)
{
  send_mesg_221 (si->csfd);
  si->cmdQuit = 1;
}

canonical_original_code:
void cmd_quit(struct session_info_t *si)
{
  send_mesg_221 (si->csfd);
  si->cmdQuit = 1;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
void *v4; // rdi
char *v5; // rbp
int v6; // er12
unsigned int v7; // ebx
_DWORD *v8; // rbp
int v9; // eax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-58h] BYREF

v3 = get_config_value("ROOT_PATH_CONFIG", "../conf/ftp.conf", envp);
if ( !v3 )
return -1;
v4 = (void *)v3;
rootdir = (char *)get_config_path(v3);
if ( !rootdir )
{
free(v4);
return -1;
}
free(v4);
v5 = rootdir;
rootdir = canonicalize_file_name(rootdir);
if ( !rootdir )
{
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "%s: canonicalize_file_name: %s\n", "main", v16);
}
free(v5);
if ( pthread_attr_init(&attr) || (v6 = pthread_attr_setdetachstate(&attr, 1)) != 0 )
{
v17 = _errno_location();
v18 = strerror(*v17);
fprintf(stderr, "%s: pthread_attr_init: %s\n", "main", v18);
return -1;
}
v7 = get_control_sock();
if ( v7 == -1 || (unsigned int)welcome_message() == -1 )
return -1;
while ( 1 )
{
v8 = malloc(4uLL);
if ( !v8 )
break;
v9 = accept_connection(v7, 1LL, 0LL);
*v8 = v9;
if ( v9 == -1 )
goto LABEL_19;
if ( v9 == -999 )
{
if ( (unsigned int)read_server_cmd() == -999 )
{
shutdownServer = 1;
free(v8);
goto LABEL_14;
}
LABEL_19:
free(v8);
}
else
{
if ( pthread_create(&newthread, &attr, (void *(*)(void *))&control_thread, v8) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s: pthread_create: %s\n", "main", v12);
goto LABEL_19;
}
if ( (unsigned int)modify_cthread_count(1LL) == -1 )
goto LABEL_14;
}
}
fprintf(stderr, "%s: malloc of %lu bytes failed\n", "main", 4LL);
LABEL_14:
free(rootdir);
if ( activeControlThreads <= 0 || (puts("waiting on threads to resolve..."), activeControlThreads <= 0) )
{
if ( pthread_attr_destroy(&attr) == -1 )
goto LABEL_25;
}
else
{
do
sleep(1u);
while ( activeControlThreads > 0 );
if ( pthread_attr_destroy(&attr) == -1 )
{
LABEL_25:
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "%s: pthread_attr_destroy: %s\n", "main", v14);
}
}
puts("All threads have terminated, exiting the program.");
return v6;
}

original_code:
int main (int argc, char *argv[])
{
  int listenSfd;
  int *csfd;
  pthread_t thread;
  pthread_attr_t attr;
  char *rootTemp;
  if ((rootTemp = get_config_value ("ROOT_PATH_CONFIG", "../conf/ftp.conf")) == ((void *)0))
    return -1;
  if ((rootdir = get_config_path (rootTemp)) == ((void *)0)) {
    free (rootTemp);
    return -1;
  }
  free (rootTemp);
  rootTemp = rootdir;
  if ((rootdir = canonicalize_file_name (rootTemp)) == ((void *)0)) {
    fprintf (stderr, "%s: canonicalize_file_name: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
  }
  free (rootTemp);
  if (pthread_attr_init (&attr) != 0) {
    fprintf (stderr, "%s: pthread_attr_init: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
    return -1;
  }
  if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0) {
    fprintf (stderr, "%s: pthread_attr_init: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
    return -1;
  }
  if ((listenSfd = get_control_sock ()) == -1)
    return -1;
  if (welcome_message() == -1) {
    return -1;
  }
  while (1) {
    if ((csfd = malloc (sizeof(*csfd))) == ((void *)0)) {
      fprintf (stderr, "%s: malloc of %lu bytes failed\n", __FUNCTION__, sizeof(*csfd));
      break;
    }
    if ((*csfd = accept_connection (listenSfd, 1, ((void *)0))) == -1) {
      free (csfd);
      continue;
    } else if (*csfd == -999) {
      if (read_server_cmd () == -999) {
 shutdownServer = 1;
 free (csfd);
 break;
      } else {
 free (csfd);
 continue;
      }
    }
    if (pthread_create (&thread, &attr, &control_thread, csfd) != 0) {
      fprintf (stderr, "%s: pthread_create: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      free (csfd);
      continue;
    }
    if (modify_cthread_count (1) == -1)
      break;
  }
  free (rootdir);
  if (activeControlThreads > 0)
    printf ("waiting on threads to resolve...\n");
  while (activeControlThreads > 0) {
    sleep (1);
  }
  if (pthread_attr_destroy (&attr) == -1)
    fprintf (stderr, "%s: pthread_attr_destroy: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
  printf ("All threads have terminated, exiting the program.\n");
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int listenSfd;
  int *csfd;
  unsigned long thread;
  union pthread_attr_t attr;
  char *rootTemp;
  if ((rootTemp = get_config_value ("ROOT_PATH_CONFIG", "../conf/ftp.conf")) == ((void *)0))
    return -1;
  if ((rootdir = get_config_path (rootTemp)) == ((void *)0)) {
    free (rootTemp);
    return -1;
  }
  free (rootTemp);
  rootTemp = rootdir;
  if ((rootdir = canonicalize_file_name (rootTemp)) == ((void *)0)) {
    fprintf (stderr, "%s: canonicalize_file_name: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
  }
  free (rootTemp);
  if (pthread_attr_init (&attr) != 0) {
    fprintf (stderr, "%s: pthread_attr_init: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
    return -1;
  }
  if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0) {
    fprintf (stderr, "%s: pthread_attr_init: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
    return -1;
  }
  if ((listenSfd = get_control_sock ()) == -1)
    return -1;
  if (welcome_message() == -1) {
    return -1;
  }
  while (1) {
    if ((csfd = malloc (sizeof(*csfd))) == ((void *)0)) {
      fprintf (stderr, "%s: malloc of %lu bytes failed\n", __FUNCTION__, sizeof(*csfd));
      break;
    }
    if ((*csfd = accept_connection (listenSfd, 1, ((void *)0))) == -1) {
      free (csfd);
      continue;
    } else if (*csfd == -999) {
      if (read_server_cmd () == -999) {
 shutdownServer = 1;
 free (csfd);
 break;
      } else {
 free (csfd);
 continue;
      }
    }
    if (pthread_create (&thread, &attr, &control_thread, csfd) != 0) {
      fprintf (stderr, "%s: pthread_create: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      free (csfd);
      continue;
    }
    if (modify_cthread_count (1) == -1)
      break;
  }
  free (rootdir);
  if (activeControlThreads > 0)
    printf ("waiting on threads to resolve...\n");
  while (activeControlThreads > 0) {
    sleep (1);
  }
  if (pthread_attr_destroy (&attr) == -1)
    fprintf (stderr, "%s: pthread_attr_destroy: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
  printf ("All threads have terminated, exiting the program.\n");
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: listenSfd int

variable_types:
csfd
int *

variable_types:
thread
unsigned long

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

variable_types:
rootTemp
char *