main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[32]; // [rsp+0h] [rbp-D0h] BYREF
char v5[32]; // [rsp+20h] [rbp-B0h] BYREF
char v6[32]; // [rsp+40h] [rbp-90h] BYREF
__int64 v7[4]; // [rsp+60h] [rbp-70h] BYREF
__int64 v8[4]; // [rsp+80h] [rbp-50h] BYREF
char v9[48]; // [rsp+A0h] [rbp-30h] BYREF

result = configure(argc, (char **)argv);
if ( result != -1 )
{
fwrite("Using single point data-type\n", 1uLL, 0x1DuLL, stdout);
fprintf(stdout, "input image: %s\n", inputfilename);
fprintf(stdout, "output image: %s\n", outputfilename);
Array3D_malloc(v5, 128LL, 128LL, 128LL);
Array3D_malloc(v6, 128LL, 128LL, 128LL);
Array3D_malloc(v7, 128LL, 128LL, 128LL);
Array3D_initialize_value(v7[0], 128LL, 128LL, 128LL, 1.0);
Array3D_malloc(v8, 301LL, 257LL, 36LL);
Array3D_initialize_value(v8[0], 301LL, 257LL, 36LL, 1.0);
readImgArray3D(inputfilename, (__int64)v5);
util_start_papi((unsigned int)batch_id, v4);
CPU_Routine(v5, v6, v7, v8);
util_stop_papi((unsigned int)batch_id, v9);
util_print_papi((unsigned int)batch_id, v9, batch_id == 0);
writeImgArray3D(outputfilename, (__int64)v5);
Array3D_free(v5);
Array3D_free(v6);
Array3D_free(v7);
Array3D_free(v8);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[32]; // [rsp+0h] [rbp-D0h] BYREF
char v5[32]; // [rsp+20h] [rbp-B0h] BYREF
char v6[32]; // [rsp+40h] [rbp-90h] BYREF
__int64 v7[4]; // [rsp+60h] [rbp-70h] BYREF
__int64 v8[4]; // [rsp+80h] [rbp-50h] BYREF
char v9[48]; // [rsp+A0h] [rbp-30h] BYREF

result = func7(argc, (char **)argv);
if ( result != -1 )
{
fwrite("Using single point data-type\n", 1uLL, 0x1DuLL, stdout);
fprintf(stdout, "input image: %s\n", inputfilename);
fprintf(stdout, "output image: %s\n", outputfilename);
Array3D_malloc(v5, 128LL, 128LL, 128LL);
Array3D_malloc(v6, 128LL, 128LL, 128LL);
Array3D_malloc(v7, 128LL, 128LL, 128LL);
Array3D_initialize_value(v7[0], 128LL, 128LL, 128LL, 1.0);
Array3D_malloc(v8, 301LL, 257LL, 36LL);
Array3D_initialize_value(v8[0], 301LL, 257LL, 36LL, 1.0);
func2(inputfilename, (__int64)v5);
util_start_papi((unsigned int)batch_id, v4);
CPU_Routine(v5, v6, v7, v8);
util_stop_papi((unsigned int)batch_id, v9);
util_print_papi((unsigned int)batch_id, v9, batch_id == 0);
func3(outputfilename, (__int64)v5);
Array3D_free(v5);
Array3D_free(v6);
Array3D_free(v7);
Array3D_free(v8);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int N_x = 128, N_y = 128, N_z = 128;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 Array3D cpu_image;
 Array3D cpu_sumA;
 Array3D cpu_image_denote;
 Array3D cpu_sino;
 if (configure(argc, argv) == -1)
  return -1;
 fprintf(stdout, "Using single point data-type\n");
 fprintf(stdout, "input image: %s\n", inputfilename);
 fprintf(stdout, "output image: %s\n", outputfilename);
 Array3D_malloc(&cpu_image, N_x, N_y, N_z);
 Array3D_malloc(&cpu_sumA, N_x, N_y, N_z);
 Array3D_malloc(&cpu_image_denote, N_x, N_y, N_z);
 Array3D_initialize_value((cpu_image_denote.dataPtr), 1.0, N_x, N_y,
     N_z);
 Array3D_malloc(&cpu_sino, 2 * q + 1, 2 * qz + 1,
         (int)floorf(359. / theta) + 1);
 Array3D_initialize_value((cpu_sino.dataPtr), 1.0, 2 * q + 1,
     2 * qz + 1, (int)floorf(359. / theta) + 1);
 readImgArray3D(inputfilename, &(cpu_image));
 int Events[5];
 unsigned long long papi_values[5];
 util_start_papi(batch_id, Events);
 CPU_Routine(&cpu_image, &cpu_sumA, &cpu_image_denote, &cpu_sino);
 util_stop_papi(batch_id, papi_values);
 util_print_papi(batch_id, papi_values, (batch_id == 0));
 writeImgArray3D(outputfilename, &cpu_image);
 Array3D_free(&cpu_image);
 Array3D_free(&cpu_sumA);
 Array3D_free(&cpu_image_denote);
 Array3D_free(&cpu_sino);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int N_x = 128; int N_y = 128; int N_z = 128;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 struct _Array3D cpu_image;
 struct _Array3D cpu_sumA;
 struct _Array3D cpu_image_denote;
 struct _Array3D cpu_sino;
 if (configure(argc, argv) == -1)
  return -1;
 fprintf(stdout, "Using single point data-type\n");
 fprintf(stdout, "input image: %s\n", inputfilename);
 fprintf(stdout, "output image: %s\n", outputfilename);
 Array3D_malloc(&cpu_image, N_x, N_y, N_z);
 Array3D_malloc(&cpu_sumA, N_x, N_y, N_z);
 Array3D_malloc(&cpu_image_denote, N_x, N_y, N_z);
 Array3D_initialize_value((cpu_image_denote.dataPtr), 1.0, N_x, N_y,
     N_z);
 Array3D_malloc(&cpu_sino, 2 * q + 1, 2 * qz + 1,
         (int)floorf(359. / theta) + 1);
 Array3D_initialize_value((cpu_sino.dataPtr), 1.0, 2 * q + 1,
     2 * qz + 1, (int)floorf(359. / theta) + 1);
 readImgArray3D(inputfilename, &(cpu_image));
 int Events[5];
 unsigned long long papi_values[5];
 util_start_papi(batch_id, Events);
 CPU_Routine(&cpu_image, &cpu_sumA, &cpu_image_denote, &cpu_sino);
 util_stop_papi(batch_id, papi_values);
 util_print_papi(batch_id, papi_values, (batch_id == 0));
 writeImgArray3D(outputfilename, &cpu_image);
 Array3D_free(&cpu_image);
 Array3D_free(&cpu_sumA);
 Array3D_free(&cpu_image_denote);
 Array3D_free(&cpu_sino);
 return 0;
}

variable_types:
argv
char **

variable_types: theta float

variable_types: q int

variable_types: qz int

variable_types: struct _Array3D { float *dataPtr; int index1Size; int index2Size; int index3Size; }

variable_types:
Events
int [5]


TVupdate

original_code:
void TVupdate(Array3D * image, Array3D * sumA, float alpha, int max_iter)
{
 int N_x = image->index1Size - 1;
 int N_y = image->index2Size - 1;
 int N_z = image->index3Size - 1;
 float c1, c2, c3, c4;
 float eps = (float) (1e-6);
 int i, j, k, l;
 for (i = 0; i < max_iter; i++) {
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++)
    for (l = 1; l < N_z; l++) {
     float data000;
     float data100, data010, data001;
     float datan100, datan110, datan101;
     float data1n10, data0n10, data0n11;
     float data10n1, data00n1, data01n1;
     float sum;
     float sub100, sub010, sub001;
     float sub000, subn110, subn101;
     float sub1n10, sub0002, sub0n11;
     float sub10n1, sub01n1, sub0003;
     float temp;
     data000 = (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)));
     if (data000 > 1e-6) {
      data100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size)));
      data010 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size)));
      data001 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size)));
      datan100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)));
      datan110 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + (j - 1) * image->index2Size)));
      datan101 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + (j - 1) * image->index2Size)));
      data1n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + (j + 1) * image->index2Size)));
      data0n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)));
      data0n11 =
          (*(image->dataPtr + (l + 1) + image->index3Size *((k - 1) + j * image->index2Size)));
      data10n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + (j + 1) * image->index2Size)));
      data00n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      data01n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *((k + 1) + j * image->index2Size)));
      sum =
          (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
      sub100 = data100 - data000;
      sub010 = data010 - data000;
      sub001 = data001 - data000;
      sub000 = data000 - datan100;
      subn110 = datan110 - datan100;
      subn101 = datan101 - datan100;
      sub1n10 = data1n10 - data0n10;
      sub0002 = data000 - data0n10;
      sub0n11 = data0n11 - data0n10;
      sub10n1 = data10n1 - data00n1;
      sub01n1 = data01n1 - data00n1;
      sub0003 = data000 - data00n1;
      c1 = data000 / sqrtf(eps +
            sub100 *
            sub100 +
            sub010 *
            sub010 +
            sub001 *
            sub001) /
          sum;
      c2 = data000 / sqrtf(eps +
            sub000 *
            sub000 +
            subn110 *
            subn110 +
            subn101 *
            subn101) /
          sum;
      c3 = data000 / sqrtf(eps +
            sub1n10 *
            sub1n10 +
            sub0002 *
            sub0002 +
            sub0n11 *
            sub0n11) /
          sum;
      c4 = data000 / sqrtf(eps +
            sub10n1 *
            sub10n1 +
            sub01n1 *
            sub01n1 +
            sub0003 *
            sub0003) /
          sum;
      temp =
          alpha * (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)))
          +
          c1 *
          ((*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size))) + (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size))) +
           (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size))))
          + c2 * (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)))
          + c3 * (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)))
          + c4 * (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
          (float) (temp /
        (alpha +
         3.0 * c1 + c2 +
         c3 + c4));
     }
    };
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++) {
    (*(image->dataPtr + 0 + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + 1 + image->index3Size *(k + j * image->index2Size)));
    (*(image->dataPtr + N_z + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + (N_z - 1) + image->index3Size *(k + j * image->index2Size)));
   }
 }
}

canonical_original_code:
void TVupdate(struct _Array3D *image, struct _Array3D *sumA, float alpha, int max_iter)
{
 int N_x = image->index1Size - 1;
 int N_y = image->index2Size - 1;
 int N_z = image->index3Size - 1;
 float c1; float c2; float c3; float c4;
 float eps = (float) (1e-6);
 int i; int j; int k; int l;
 for (i = 0; i < max_iter; i++) {
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++)
    for (l = 1; l < N_z; l++) {
     float data000;
     float data100; float data010; float data001;
     float datan100; float datan110; float datan101;
     float data1n10; float data0n10; float data0n11;
     float data10n1; float data00n1; float data01n1;
     float sum;
     float sub100; float sub010; float sub001;
     float sub000; float subn110; float subn101;
     float sub1n10; float sub0002; float sub0n11;
     float sub10n1; float sub01n1; float sub0003;
     float temp;
     data000 = (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)));
     if (data000 > 1e-6) {
      data100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size)));
      data010 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size)));
      data001 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size)));
      datan100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)));
      datan110 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + (j - 1) * image->index2Size)));
      datan101 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + (j - 1) * image->index2Size)));
      data1n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + (j + 1) * image->index2Size)));
      data0n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)));
      data0n11 =
          (*(image->dataPtr + (l + 1) + image->index3Size *((k - 1) + j * image->index2Size)));
      data10n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + (j + 1) * image->index2Size)));
      data00n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      data01n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *((k + 1) + j * image->index2Size)));
      sum =
          (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
      sub100 = data100 - data000;
      sub010 = data010 - data000;
      sub001 = data001 - data000;
      sub000 = data000 - datan100;
      subn110 = datan110 - datan100;
      subn101 = datan101 - datan100;
      sub1n10 = data1n10 - data0n10;
      sub0002 = data000 - data0n10;
      sub0n11 = data0n11 - data0n10;
      sub10n1 = data10n1 - data00n1;
      sub01n1 = data01n1 - data00n1;
      sub0003 = data000 - data00n1;
      c1 = data000 / sqrtf(eps +
            sub100 *
            sub100 +
            sub010 *
            sub010 +
            sub001 *
            sub001) /
          sum;
      c2 = data000 / sqrtf(eps +
            sub000 *
            sub000 +
            subn110 *
            subn110 +
            subn101 *
            subn101) /
          sum;
      c3 = data000 / sqrtf(eps +
            sub1n10 *
            sub1n10 +
            sub0002 *
            sub0002 +
            sub0n11 *
            sub0n11) /
          sum;
      c4 = data000 / sqrtf(eps +
            sub10n1 *
            sub10n1 +
            sub01n1 *
            sub01n1 +
            sub0003 *
            sub0003) /
          sum;
      temp =
          alpha * (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)))
          +
          c1 *
          ((*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size))) + (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size))) +
           (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size))))
          + c2 * (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)))
          + c3 * (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)))
          + c4 * (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
          (float) (temp /
        (alpha +
         3.0 * c1 + c2 +
         c3 + c4));
     }
    };
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++) {
    (*(image->dataPtr + 0 + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + 1 + image->index3Size *(k + j * image->index2Size)));
    (*(image->dataPtr + N_z + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + (N_z - 1) + image->index3Size *(k + j * image->index2Size)));
   }
 }
}

variable_types: struct _Array3D { float *dataPtr; int index1Size; int index2Size; int index3Size; } *

variable_types:
sumA
struct _Array3D *

variable_types: alpha float

variable_types: eps float

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: sum float

variable_types: temp float

return_type: void


EMupdate

original_code:
void EMupdate(Array3D * sino,
       Array3D * image,
       Array3D * image_denote,
       Array3D * sumA,
       int max_iter,
       float D,
       int q,
       float ss, float d, float dtheta, float ssz, int qz)
{
 int M_x = sino->index1Size;
 int M_y = sino->index2Size;
 int M_z = sino->index3Size;
 int N_x = image->index1Size;
 int N_y = image->index2Size;
 int N_z = image->index3Size;
 int i, j, k, l;
 Array3D Af;
 Array3D gAf;
 Array3D AtAf;
 Array3D_malloc(&Af, M_x, M_y, M_z);
 Array3D_malloc(&gAf, M_x, M_y, M_z);
 Array3D_malloc(&AtAf, N_x, N_y, N_z);
 for (i = 0; i < max_iter; i++) {
  Forward_Projection(image, D, q, ss, d, dtheta, ssz, qz, &Af);
  for (j = 0; j < M_x; j++)
   for (k = 0; k < M_y; k++)
    for (l = 0; l < M_z; l++)
     if ((*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size))) > 1.e-6) {
      (*((&gAf)->dataPtr + l + (&gAf)->index3Size *(k + j * (&gAf)->index2Size))) =
          (*(sino->dataPtr + l + sino->index3Size *(k + j * sino->index2Size))) /
          (*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size)));
     }
  fprintf(stderr, "\n");
      Backward_Projection(&AtAf, image_denote, D, q, ss, d,
     dtheta, ssz, qz, &gAf);
  fprintf(stderr, "\n");
      for (j = 0; j < N_x; j++)
   for (k = 0; k < N_y; k++)
    for (l = 0; l < N_z; l++) {
     (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
         (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) *
         (*((&AtAf)->dataPtr + l + (&AtAf)->index3Size *(k + j * (&AtAf)->index2Size))) / (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
    }
 }
 Array3D_free(&Af);
 Array3D_free(&gAf);
 Array3D_free(&AtAf);
}

canonical_original_code:
void EMupdate(struct _Array3D *sino, struct _Array3D *image, struct _Array3D *image_denote, struct _Array3D *sumA, int max_iter, float D, int q, float ss, float d, float dtheta, float ssz, int qz)
{
 int M_x = sino->index1Size;
 int M_y = sino->index2Size;
 int M_z = sino->index3Size;
 int N_x = image->index1Size;
 int N_y = image->index2Size;
 int N_z = image->index3Size;
 int i; int j; int k; int l;
 struct _Array3D Af;
 struct _Array3D gAf;
 struct _Array3D AtAf;
 Array3D_malloc(&Af, M_x, M_y, M_z);
 Array3D_malloc(&gAf, M_x, M_y, M_z);
 Array3D_malloc(&AtAf, N_x, N_y, N_z);
 for (i = 0; i < max_iter; i++) {
  Forward_Projection(image, D, q, ss, d, dtheta, ssz, qz, &Af);
  for (j = 0; j < M_x; j++)
   for (k = 0; k < M_y; k++)
    for (l = 0; l < M_z; l++)
     if ((*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size))) > 1.e-6) {
      (*((&gAf)->dataPtr + l + (&gAf)->index3Size *(k + j * (&gAf)->index2Size))) =
          (*(sino->dataPtr + l + sino->index3Size *(k + j * sino->index2Size))) /
          (*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size)));
     }
  fprintf(stderr, "\n");
      Backward_Projection(&AtAf, image_denote, D, q, ss, d,
     dtheta, ssz, qz, &gAf);
  fprintf(stderr, "\n");
      for (j = 0; j < N_x; j++)
   for (k = 0; k < N_y; k++)
    for (l = 0; l < N_z; l++) {
     (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
         (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) *
         (*((&AtAf)->dataPtr + l + (&AtAf)->index3Size *(k + j * (&AtAf)->index2Size))) / (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
    }
 }
 Array3D_free(&Af);
 Array3D_free(&gAf);
 Array3D_free(&AtAf);
}

variable_types:
image
struct _Array3D *

variable_types: D float

variable_types: ss float

variable_types: d float

variable_types: dtheta float

variable_types: ssz float

user_defined_types: struct _Array3D { float *dataPtr; int index1Size; int index2Size; int index3Size; }


decompiled_code:
__int64 __fastcall CPU_Routine(_QWORD *a1, __int64 a2, _QWORD *a3, __int64 a4)
{
__int64 v6; // r15
__int64 v7; // rax
__int64 v8; // r15
__int64 v9; // rax
unsigned int v10; // er15
__int64 v11; // rdx
__int64 v12; // r12
__int64 v13; // rdx
__int64 v14; // rbx
__int64 v16; // [rsp+0h] [rbp-B0h]
__int64 v17; // [rsp+8h] [rbp-A8h]
char s[160]; // [rsp+10h] [rbp-A0h] BYREF

writeImgArray3D("../data/cpu_readinput.dat", a1);
v17 = ((__int64 (*)(void))emtv3d_timer_s)();
fwrite("CPU Backward_Projection begins \n", 1uLL, 0x20uLL, stderr);
v6 = emtv3d_timer_us();
Backward_Projection(a2, a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v7 = emtv3d_timer_us();
fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n", v7 - v6);
writeImgArray3D("../data/cpu_sumA.dat", a2);
fwrite("CPU Forward_Projection begins \n", 1uLL, 0x1FuLL, stderr);
v8 = emtv3d_timer_us();
Forward_Projection(a1, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v9 = emtv3d_timer_us() - v8;
v10 = 0;
fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n", v9);
writeImgArray3D("../data/cpu_sino.dat", a4);
fwrite("CPU Initialization\n", 1uLL, 0x13uLL, stderr);
Initialization(a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
Array3D_copy(*a1, *a3, 128LL, 128LL, 128LL);
writeImgArray3D("../data/cpu_initialization.dat", a1);
fputc(10, stderr);
v16 = ((__int64 (*)(void))emtv3d_timer_s)();
do
{
fprintf(stderr, "CPU EMupdate %d \n", v10);
EMupdate(a4, a1, a3, a2, 3LL, 150LL, 125.0, 0.5, 64.0, 10.0, 1.0, 128LL);
sprintf(s, "../data/cpu_EMupdate%d.dat", v10);
writeImgArray3D(s, a1);
fprintf(stderr, "CPU TVupdate %d \n", v10);
TVupdate(a1, a2, 10LL, 5.0);
v11 = v10++;
sprintf(s, "../data/cpu_TVupdate%d.dat", v11);
writeImgArray3D(s, a1);
}
while ( v10 != 100 );
v12 = ((__int64 (__fastcall *)(char *, _QWORD *))emtv3d_timer_s)(s, a1);
v14 = emtv3d_timer_s(s, a1, v13);
fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n", v12 - v16);
fprintf(stderr, "CPU total using %lld seconds\n", v14 - v17);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, _QWORD *a3, __int64 a4)
{
__int64 v6; // r15
__int64 v7; // rax
__int64 v8; // r15
__int64 v9; // rax
unsigned int v10; // er15
__int64 v11; // rdx
__int64 v12; // r12
__int64 v13; // rdx
__int64 v14; // rbx
__int64 v16; // [rsp+0h] [rbp-B0h]
__int64 v17; // [rsp+8h] [rbp-A8h]
char s[160]; // [rsp+10h] [rbp-A0h] BYREF

writeImgArray3D("../data/cpu_readinput.dat", a1);
v17 = ((__int64 (*)(void))emtv3d_timer_s)();
fwrite("CPU Backward_Projection begins \n", 1uLL, 0x20uLL, stderr);
v6 = emtv3d_timer_us();
Backward_Projection(a2, a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v7 = emtv3d_timer_us();
fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n", v7 - v6);
writeImgArray3D("../data/cpu_sumA.dat", a2);
fwrite("CPU Forward_Projection begins \n", 1uLL, 0x1FuLL, stderr);
v8 = emtv3d_timer_us();
Forward_Projection(a1, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v9 = emtv3d_timer_us() - v8;
v10 = 0;
fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n", v9);
writeImgArray3D("../data/cpu_sino.dat", a4);
fwrite("CPU Initialization\n", 1uLL, 0x13uLL, stderr);
Initialization(a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
Array3D_copy(*a1, *a3, 128LL, 128LL, 128LL);
writeImgArray3D("../data/cpu_initialization.dat", a1);
fputc(10, stderr);
v16 = ((__int64 (*)(void))emtv3d_timer_s)();
do
{
fprintf(stderr, "CPU EMupdate %d \n", v10);
EMupdate(a4, a1, a3, a2, 3LL, 150LL, 125.0, 0.5, 64.0, 10.0, 1.0, 128LL);
sprintf(s, "../data/cpu_EMupdate%d.dat", v10);
writeImgArray3D(s, a1);
fprintf(stderr, "CPU TVupdate %d \n", v10);
TVupdate(a1, a2, 10LL, 5.0);
v11 = v10++;
sprintf(s, "../data/cpu_TVupdate%d.dat", v11);
writeImgArray3D(s, a1);
}
while ( v10 != 100 );
v12 = ((__int64 (__fastcall *)(char *, _QWORD *))emtv3d_timer_s)(s, a1);
v14 = emtv3d_timer_s(s, a1, v13);
fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n", v12 - v16);
fprintf(stderr, "CPU total using %lld seconds\n", v14 - v17);
return 0LL;
}

original_code:
int CPU_Routine(Array3D * image, Array3D * sumA, Array3D * image_denote,
  Array3D * sino)
{
 int N_x = 128, N_y = 128, N_z = 128;
 float D = 125, d = 64;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 float ss = 0.5;
 float ssz = 1.0;
 int max_iter_EM = 3;
 int max_iter_TV = 10;
 float alpha = 5;
 int iter;
 int64_t i_start_whole, i_end_whole;
 int64_t i_start, i_end;
 char filename[100];
 writeImgArray3D("../data/cpu_readinput.dat", image);
 i_start_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU Backward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Backward_Projection(sumA, image_denote, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sumA.dat", sumA);
 fprintf(stderr, "CPU Forward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Forward_Projection(image, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sino.dat", sino);
 fprintf(stderr, "CPU Initialization\n");
 Initialization(image_denote, D, q, ss, d, theta, ssz, qz, sino);
 Array3D_copy(image->dataPtr, image_denote->dataPtr, N_x, N_y, N_z);
 writeImgArray3D("../data/cpu_initialization.dat", image);
 fprintf(stderr, "\n");
 i_start = emtv3d_timer_s();
 for (iter = 0; iter < 100; iter++) {
  fprintf(stderr, "CPU EMupdate %d \n", iter);
  EMupdate(sino, image, image_denote, sumA, max_iter_EM, D, q, ss, d, theta, ssz, qz);
  sprintf(filename, "../data/cpu_EMupdate%d.dat", iter);
  writeImgArray3D(filename, image);
  fprintf(stderr, "CPU TVupdate %d \n", iter);
  TVupdate(image, sumA, alpha, max_iter_TV);
  sprintf(filename, "../data/cpu_TVupdate%d.dat", iter);
  writeImgArray3D(filename, image);
 }
 i_end = emtv3d_timer_s();
 i_end_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n",
  (i_end - i_start));
 fprintf(stderr, "CPU total using %lld seconds\n",
  (i_end_whole - i_start_whole));
 return 0;
}

canonical_original_code:
int CPU_Routine(struct _Array3D *image, struct _Array3D *sumA, struct _Array3D *image_denote, struct _Array3D *sino)
{
 int N_x = 128; int N_y = 128; int N_z = 128;
 float D = 125; float d = 64;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 float ss = 0.5;
 float ssz = 1.0;
 int max_iter_EM = 3;
 int max_iter_TV = 10;
 float alpha = 5;
 int iter;
 long i_start_whole; long i_end_whole;
 long i_start; long i_end;
 char filename[100];
 writeImgArray3D("../data/cpu_readinput.dat", image);
 i_start_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU Backward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Backward_Projection(sumA, image_denote, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sumA.dat", sumA);
 fprintf(stderr, "CPU Forward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Forward_Projection(image, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sino.dat", sino);
 fprintf(stderr, "CPU Initialization\n");
 Initialization(image_denote, D, q, ss, d, theta, ssz, qz, sino);
 Array3D_copy(image->dataPtr, image_denote->dataPtr, N_x, N_y, N_z);
 writeImgArray3D("../data/cpu_initialization.dat", image);
 fprintf(stderr, "\n");
 i_start = emtv3d_timer_s();
 for (iter = 0; iter < 100; iter++) {
  fprintf(stderr, "CPU EMupdate %d \n", iter);
  EMupdate(sino, image, image_denote, sumA, max_iter_EM, D, q, ss, d, theta, ssz, qz);
  sprintf(filename, "../data/cpu_EMupdate%d.dat", iter);
  writeImgArray3D(filename, image);
  fprintf(stderr, "CPU TVupdate %d \n", iter);
  TVupdate(image, sumA, alpha, max_iter_TV);
  sprintf(filename, "../data/cpu_TVupdate%d.dat", iter);
  writeImgArray3D(filename, image);
 }
 i_end = emtv3d_timer_s();
 i_end_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n",
  (i_end - i_start));
 fprintf(stderr, "CPU total using %lld seconds\n",
  (i_end_whole - i_start_whole));
 return 0;
}

variable_types:
sino
struct _Array3D *

variable_types: theta float

variable_types: q int

variable_types: qz int

variable_types: iter int

variable_types:
filename
char [100]

return_type: int


compf

repo: intijk/triangulation

decompiled_code:
__int64 __fastcall compf(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
int compf(const void *p1, const void *p2){
 return (*((int*)p1))-(*((int*)p2));
}

canonical_original_code:
int compf(void *p1, void *p2){
 return (*((int *)p1))-(*((int *)p2));
}


insertEdge

original_code:
void insertEdge(int a, int b){
 adjNode *np=(adjNode*)malloc(sizeof(adjNode)), *npt;
 np->n=b;
 np->next=((void *)0);
 if(adjList[a]==((void *)0)) adjList[a]=np;
 else{
  int existed=0;
  npt=adjList[a];
  while(1){
   if(npt->n==b){
      existed=1;
      break;
   }
   if(npt->next==((void *)0)){
    break;
   }
   npt=npt->next;
  }
  if(!existed){
   npt->next=np;
  }else{
   free(np);
  }
 }
}

canonical_original_code:
void insertEdge(int a, int b){
 struct adjNode *np = (adjNode*)malloc(sizeof(adjNode)); struct adjNode *npt;
 np->n=b;
 np->next=((void *)0);
 if(adjList[a]==((void *)0)) adjList[a]=np;
 else{
  int existed = 0;
  npt=adjList[a];
  while(1){
   if(npt->n==b){
      existed=1;
      break;
   }
   if(npt->next==((void *)0)){
    break;
   }
   npt=npt->next;
  }
  if(!existed){
   npt->next=np;
  }else{
   free(np);
  }
 }
}

variable_types: a int

variable_types: b int

variable_types: struct adjNode { int n; struct adjNode *next; } *

variable_types: existed int


recordEdge

decompiled_code:
void __fastcall recordEdge(int a1, int a2)
{
if ( a1 >= 0 && a1 != a2 && a2 >= 0 )
{
if ( !adjList )
adjList = (__int64)calloc(8LL * N, 1uLL);
insertEdge(a1, a2);
insertEdge(a2, a1);
}
}

canonical_decompiled_code:
void __fastcall func9(int a1, int a2)
{
if ( a1 >= 0 && a1 != a2 && a2 >= 0 )
{
if ( !adjList )
adjList = (__int64)calloc(8LL * N, 1uLL);
func8(a1, a2);
func8(a2, a1);
}
}

original_code:
void recordEdge(int a, int b){
 if(a<0 || b<0 || a==b) return;
 if(adjList==((void *)0)){
  adjList=(adjNode**)malloc(sizeof(adjNode*)*N);
  memset(adjList,0,sizeof(adjNode*)*N);
 }
 insertEdge(a,b);
 insertEdge(b,a);
}

canonical_original_code:
void recordEdge(int a, int b){
 if(a<0 || b<0 || a==b) return;
 if(adjList==((void *)0)){
  adjList=(struct adjNode **)malloc(sizeof(struct adjNode *)*N);
  memset(adjList,0,sizeof(struct adjNode *)*N);
 }
 insertEdge(a,b);
 insertEdge(b,a);
}

user_defined_types: struct adjNode { int n; struct adjNode *next; }


cdis

original_code:
double cdis(int a, int b){
 if((a+1)%N==b)return 0;
 if((b+1)%N==a)return 0;
 return sqrt((vlist[a].x-vlist[b].x)*(vlist[a].x-vlist[b].x)+(vlist[a].y-vlist[b].y)*(vlist[a].y-vlist[b].y));
}

return_type: double


dps

decompiled_code:
double __fastcall dps(int a1, int a2)
{
return *(double *)(dpstatus + 8LL * (a2 + a1 * (N + 1)));
}

canonical_decompiled_code:
double __fastcall func11(int a1, int a2)
{
return *(double *)(dpstatus + 8LL * (a2 + a1 * (N + 1)));
}

original_code:
double dps(int s, int n){
 return dpstatus[s*(N+1)+n];
}

variable_types: s int

variable_types: n int


setdps

decompiled_code:
__int64 __fastcall setdps(int a1, int a2, double a3)
{
int v4; // ecx
__int64 result; // rax

if ( dps(a1, a2) >= 0.1 )
{
puts("Status rewrite! Should not be here");
exit(-1);
}
result = dpstatus;
*(double *)(dpstatus + 8LL * (v4 + a1 * (N + 1))) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2, double a3)
{
int v4; // ecx
__int64 result; // rax

if ( func11(a1, a2) >= 0.1 )
{
puts("Status rewrite! Should not be here");
exit(-1);
}
result = dpstatus;
*(double *)(dpstatus + 8LL * (v4 + a1 * (N + 1))) = a3;
return result;
}

original_code:
void setdps(int s,int n,double mindis){
 if(dps(s,n)<0.1){
  dpstatus[s*(N+1)+n]=mindis;
 }else{
  printf("Status rewrite! Should not be here\n");
  exit(-1);
 }
}

canonical_original_code:
void setdps(int s, int n, double mindis){
 if(dps(s,n)<0.1){
  dpstatus[s*(N+1)+n]=mindis;
 }else{
  printf("Status rewrite! Should not be here\n");
  exit(-1);
 }
}

variable_types: mindis double


setdpind

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

result = a2 + a1 * (N + 1);
*(_DWORD *)(dpind + 4 * result) = a3;
return result;
}

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

result = a2 + a1 * (N + 1);
*(_DWORD *)(dpind + 4 * result) = a3;
return result;
}

original_code:
void setdpind(int s, int n, int mini){
 dpind[s*(N+1)+n]=mini;
}

variable_types: mini int


getdpind

decompiled_code:
__int64 __fastcall getdpind(int a1, int a2)
{
return *(unsigned int *)(dpind + 4LL * (a2 + a1 * (N + 1)));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2)
{
return *(unsigned int *)(dpind + 4LL * (a2 + a1 * (N + 1)));
}

original_code:
int getdpind(int s, int n){
 return dpind[s*(N+1)+n];
}


dp

original_code:
double dp(int s, int n){
 if(n<=3)return 0;
 double mindis=((double)1.79769313486231570814527423731704357e+308L);
 int mini=-1;
 if(dps(s,n)>0.0000001){
  return dps(s,n);
 }
 int k;
 for(k=1;k<=n-2;k++){
  double currentdis=cdis(s,(s+k)%N)+cdis((s+k)%N,(s+n-1)%N)+dp(s,k+1)+dp((s+k)%N,n-k);
  if(mindis>currentdis){
   mini=k;
   mindis=currentdis;
  }
 }
 setdpind(s,n,mini);
 setdps(s,n,mindis);
 return mindis;
}

canonical_original_code:
double dp(int s, int n){
 if(n<=3)return 0;
 double mindis = ((double)1.79769313486231570814527423731704357e+308L);
 int mini = -1;
 if(dps(s,n)>0.0000001){
  return dps(s,n);
 }
 int k;
 for(k=1;k<=n-2;k++){
  double currentdis = cdis(s,(s+k)%N)+cdis((s+k)%N,(s+n-1)%N)+dp(s,k+1)+dp((s+k)%N,n-k);
  if(mindis>currentdis){
   mini=k;
   mindis=currentdis;
  }
 }
 setdpind(s,n,mini);
 setdps(s,n,mindis);
 return mindis;
}

variable_types: k int

variable_types: currentdis double


recurRecordEdge

decompiled_code:
int __fastcall recurRecordEdge(unsigned int a1, int a2)
{
int result; // eax
int v5; // eax
int v6; // ebx
int v7; // er13
int v8; // eax

while ( 1 )
{
result = printf("s=%d n=%d\n", a1, (unsigned int)a2);
if ( a2 <= 3 )
break;
v5 = getdpind(a1, a2);
v6 = a1 + v5;
v7 = v5;
recordEdge(a1, (int)(a1 + v5) % N);
v8 = a1 + a2 - 1;
a2 -= v7;
recordEdge(v6 % N, v8 % N);
recurRecordEdge(a1, (unsigned int)(v7 + 1));
a1 = v6 % N;
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(unsigned int a1, int a2)
{
int result; // eax
int v5; // eax
int v6; // ebx
int v7; // er13
int v8; // eax

while ( 1 )
{
result = printf("s=%d n=%d\n", a1, (unsigned int)a2);
if ( a2 <= 3 )
break;
v5 = func14(a1, a2);
v6 = a1 + v5;
v7 = v5;
func9(a1, (int)(a1 + v5) % N);
v8 = a1 + a2 - 1;
a2 -= v7;
func9(v6 % N, v8 % N);
func16(a1, (unsigned int)(v7 + 1));
a1 = v6 % N;
}
return result;
}

original_code:
void recurRecordEdge(int s,int n){
 printf("s=%d n=%d\n", s, n);
 if(n<=3)return ;
 int mini=getdpind(s,n);
 recordEdge(s, (s+mini)%N);
 recordEdge((s+mini)%N, (s+n-1)%N);
 recurRecordEdge(s,mini+1);
 recurRecordEdge((s+mini)%N, n-mini);
}

canonical_original_code:
void recurRecordEdge(int s, int n){
 printf("s=%d n=%d\n", s, n);
 if(n<=3)return ;
 int mini = getdpind(s,n);
 recordEdge(s, (s+mini)%N);
 recordEdge((s+mini)%N, (s+n-1)%N);
 recurRecordEdge(s,mini+1);
 recurRecordEdge((s+mini)%N, n-mini);
}


outputEdge

decompiled_code:
int outputEdge()
{
int v0; // ebx
unsigned int *v1; // rax
unsigned int *v2; // r15
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rax
unsigned int *v6; // rdx
unsigned int v7; // er13
unsigned int v8; // ecx
unsigned int v9; // er14
double *v10; // rbx
double v11; // xmm1_8
double v12; // xmm0_8
__int64 v13; // rbx
__int64 v14; // rdx
__int64 v15; // rsi

printf("%d\n", (unsigned int)N);
v0 = N;
v1 = (unsigned int *)malloc(4LL * N);
if ( v0 > 0 )
{
v2 = v1;
v3 = 0LL;
do
{
while ( 1 )
{
v4 = 24 * v3;
v5 = *(_QWORD *)(adjList + 8 * v3);
if ( v5 )
break;
qsort(v2, 0LL, 4uLL, (__compar_fn_t)compf);
++v3;
printf("%f %f ", *(double *)((char *)vlist + v4), *(double *)((char *)vlist + v4 + 8));
LODWORD(v1) = printf("%d%s", 0LL, "\n");
if ( N <= (int)v3 )
return (int)v1;
}
v6 = v2;
v7 = 0;
do
{
v8 = *(_DWORD *)v5;
v5 = *(_QWORD *)(v5 + 8);
v9 = v7;
++v6;
++v7;
*(v6 - 1) = v8;
}
while ( v5 );
qsort(v2, (int)v7, 4uLL, (__compar_fn_t)compf);
v10 = (double *)((char *)vlist + v4);
v11 = v10[1];
v12 = *v10;
v13 = 0LL;
printf("%f %f ", v12, v11);
printf("%d%s", v7, " ");
do
{
v14 = 4202553LL;
v15 = v2[v13];
if ( v9 != (_DWORD)v13 )
v14 = 4202565LL;
++v13;
LODWORD(v1) = printf("%d%s", v15, v14);
}
while ( v7 != v13 );
++v3;
}
while ( N > (int)v3 );
}
return (int)v1;
}

canonical_decompiled_code:
int func17()
{
int v0; // ebx
unsigned int *v1; // rax
unsigned int *v2; // r15
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rax
unsigned int *v6; // rdx
unsigned int v7; // er13
unsigned int v8; // ecx
unsigned int v9; // er14
double *v10; // rbx
double v11; // xmm1_8
double v12; // xmm0_8
__int64 v13; // rbx
__int64 v14; // rdx
__int64 v15; // rsi

printf("%d\n", (unsigned int)N);
v0 = N;
v1 = (unsigned int *)malloc(4LL * N);
if ( v0 > 0 )
{
v2 = v1;
v3 = 0LL;
do
{
while ( 1 )
{
v4 = 24 * v3;
v5 = *(_QWORD *)(adjList + 8 * v3);
if ( v5 )
break;
qsort(v2, 0LL, 4uLL, (__compar_fn_t)compf);
++v3;
printf("%f %f ", *(double *)((char *)vlist + v4), *(double *)((char *)vlist + v4 + 8));
LODWORD(v1) = printf("%d%s", 0LL, "\n");
if ( N <= (int)v3 )
return (int)v1;
}
v6 = v2;
v7 = 0;
do
{
v8 = *(_DWORD *)v5;
v5 = *(_QWORD *)(v5 + 8);
v9 = v7;
++v6;
++v7;
*(v6 - 1) = v8;
}
while ( v5 );
qsort(v2, (int)v7, 4uLL, (__compar_fn_t)compf);
v10 = (double *)((char *)vlist + v4);
v11 = v10[1];
v12 = *v10;
v13 = 0LL;
printf("%f %f ", v12, v11);
printf("%d%s", v7, " ");
do
{
v14 = 4202553LL;
v15 = v2[v13];
if ( v9 != (_DWORD)v13 )
v14 = 4202565LL;
++v13;
LODWORD(v1) = printf("%d%s", v15, v14);
}
while ( v7 != v13 );
++v3;
}
while ( N > (int)v3 );
}
return (int)v1;
}

original_code:
void outputEdge()
{
 printf("%d\n", N);
 int *sortSpace=(int*)malloc(sizeof(int)*N);
 adjNode *npt;
 int i,j,c;
 for(i=0;i<N;i++){
  c=0;
  npt=adjList[i];
  while(npt!=((void *)0)){
   sortSpace[c++]=npt->n;
   npt=npt->next;
  }
  qsort(sortSpace,c,sizeof(int),compf);
  printf("%f %f ", vlist[i].x,vlist[i].y);
  printf("%d%s",c,c==0?"\n":" ");
  for(j=0;j<c;j++){
   printf("%d%s",sortSpace[j], j==c-1?"\n":" ");
  }
 }
}

canonical_original_code:
void outputEdge()
{
 printf("%d\n", N);
 int *sortSpace = (int*)malloc(sizeof(int)*N);
 struct adjNode *npt;
 int i; int j; int c;
 for(i=0;i<N;i++){
  c=0;
  npt=adjList[i];
  while(npt!=((void *)0)){
   sortSpace[c++]=npt->n;
   npt=npt->next;
  }
  qsort(sortSpace,c,sizeof(int),compf);
  printf("%f %f ", vlist[i].x,vlist[i].y);
  printf("%d%s",c,c==0?"\n":" ");
  for(j=0;j<c;j++){
   printf("%d%s",sortSpace[j], j==c-1?"\n":" ");
  }
 }
}

variable_types:
sortSpace
int *

variable_types: i int

variable_types: j int

variable_types: c int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
double *v4; // rbx
double v5; // xmm0_8
double *v6; // rax
double *v7; // rbp
char *v8; // rax
__int64 v9; // rbx
double *v10; // rax
double *v11; // r12
int v12; // ebp
int v13; // ebx
__int64 v14; // rdi
__int64 v15; // rbx
__int64 v17; // [rsp+0h] [rbp-28h]
double v18; // [rsp+8h] [rbp-20h]

__isoc99_scanf();
v3 = malloc(0x18uLL);
N = 1;
vlist = v3;
v4 = (double *)v3;
*v3 = v17;
v5 = v18;
*(_OWORD *)(v3 + 1) = *(unsigned __int64 *)&v18;
while ( (unsigned int)__isoc99_scanf() == 2 )
{
v6 = (double *)malloc(0x18uLL);
++N;
v6[2] = 0.0;
*(_QWORD *)v6 = v17;
v5 = v18;
v6[1] = v18;
*((_QWORD *)v4 + 2) = v6;
v4 = v6;
}
v7 = (double *)vlist;
v8 = (char *)calloc(24LL * N, 1uLL);
vlist = v8;
if ( v7 )
{
v9 = 0LL;
while ( 1 )
{
v10 = (double *)&v8[v9];
v11 = (double *)*((_QWORD *)v7 + 2);
v9 += 24LL;
*v10 = *v7;
v5 = v7[1];
v10[1] = v5;
free(v7);
if ( !v11 )
break;
v8 = (char *)vlist;
v7 = v11;
}
}
v12 = N;
if ( N > 0 )
{
v13 = 0;
do
{
v14 = (unsigned int)v13++;
recordEdge(v14, (unsigned int)(v13 % v12));
v12 = N;
}
while ( v13 < N );
}
v15 = v12 * (__int64)(v12 + 1);
dpstatus = (__int64)calloc(8 * v15, 1uLL);
dpind = (__int64)calloc(4 * v15, 1uLL);
dp(0LL, (unsigned int)v12);
printf("%f\n", v5);
recurRecordEdge(0LL, (unsigned int)N);
outputEdge();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
double *v4; // rbx
double v5; // xmm0_8
double *v6; // rax
double *v7; // rbp
char *v8; // rax
__int64 v9; // rbx
double *v10; // rax
double *v11; // r12
int v12; // ebp
int v13; // ebx
__int64 v14; // rdi
__int64 v15; // rbx
__int64 v17; // [rsp+0h] [rbp-28h]
double v18; // [rsp+8h] [rbp-20h]

__isoc99_scanf();
v3 = malloc(0x18uLL);
N = 1;
vlist = v3;
v4 = (double *)v3;
*v3 = v17;
v5 = v18;
*(_OWORD *)(v3 + 1) = *(unsigned __int64 *)&v18;
while ( (unsigned int)__isoc99_scanf() == 2 )
{
v6 = (double *)malloc(0x18uLL);
++N;
v6[2] = 0.0;
*(_QWORD *)v6 = v17;
v5 = v18;
v6[1] = v18;
*((_QWORD *)v4 + 2) = v6;
v4 = v6;
}
v7 = (double *)vlist;
v8 = (char *)calloc(24LL * N, 1uLL);
vlist = v8;
if ( v7 )
{
v9 = 0LL;
while ( 1 )
{
v10 = (double *)&v8[v9];
v11 = (double *)*((_QWORD *)v7 + 2);
v9 += 24LL;
*v10 = *v7;
v5 = v7[1];
v10[1] = v5;
free(v7);
if ( !v11 )
break;
v8 = (char *)vlist;
v7 = v11;
}
}
v12 = N;
if ( N > 0 )
{
v13 = 0;
do
{
v14 = (unsigned int)v13++;
func9(v14, (unsigned int)(v13 % v12));
v12 = N;
}
while ( v13 < N );
}
v15 = v12 * (__int64)(v12 + 1);
dpstatus = (__int64)calloc(8 * v15, 1uLL);
dpind = (__int64)calloc(4 * v15, 1uLL);
func15(0LL, (unsigned int)v12);
printf("%f\n", v5);
func16(0LL, (unsigned int)N);
func17();
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
 double x,y;
 vertex *last;
 scanf("%lf%lf", &x,&y);
 last=vlist=(vertex*)malloc(sizeof(vertex));
 vlist->x=x;
 vlist->y=y;
 vlist->next=((void *)0);
 N=1;
 while(scanf("%lf%lf", &x,&y)==2){
  vertex *v=(vertex*)malloc(sizeof(vertex));
  v->x=x,v->y=y;
  v->next=((void *)0);
  last->next=v;
  last=v;
  N++;
 }
 last=vlist;
 vlist=(vertex*)malloc(sizeof(vertex)*N);
 memset(vlist,0,sizeof(vertex)*N);
 vertex *llast;
 int i=0;
 while(last){
  llast=last;
  vlist[i].x=last->x;
  vlist[i].y=last->y;
  last=last->next;
  free(llast);
  i++;
 }
 for(i=0;i<N;i++){
  recordEdge(i,(i+1)%N);
 }
 dpstatus=(double*)malloc(sizeof(double)*(N+1)*N);
 dpind=(int*)malloc(sizeof(int)*(N+1)*N);
 memset(dpstatus,0,sizeof(double)*(N+1)*N);
 memset(dpind,0,sizeof(int)*(N+1)*N);
 printf("%f\n",dp(0, N));
 recurRecordEdge(0,N);
 outputEdge();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 double x; double y;
 struct vertex *last;
 scanf("%lf%lf", &x,&y);
 last=vlist=(struct vertex *)malloc(sizeof(vertex));
 vlist->x=x;
 vlist->y=y;
 vlist->next=((void *)0);
 N=1;
 while(scanf("%lf%lf", &x,&y)==2){
  struct vertex *v = (vertex*)malloc(sizeof(vertex));
  v->x=x,v->y=y;
  v->next=((void *)0);
  last->next=v;
  last=v;
  N++;
 }
 last=vlist;
 vlist=(struct vertex *)malloc(sizeof(vertex)*N);
 memset(vlist,0,sizeof(vertex)*N);
 struct vertex *llast;
 int i = 0;
 while(last){
  llast=last;
  vlist[i].x=last->x;
  vlist[i].y=last->y;
  last=last->next;
  free(llast);
  i++;
 }
 for(i=0;i<N;i++){
  recordEdge(i,(i+1)%N);
 }
 dpstatus=(double *)malloc(sizeof(double)*(N+1)*N);
 dpind=(int *)malloc(sizeof(int)*(N+1)*N);
 memset(dpstatus,0,sizeof(double)*(N+1)*N);
 memset(dpind,0,sizeof(int)*(N+1)*N);
 printf("%f\n",dp(0, N));
 recurRecordEdge(0,N);
 outputEdge();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x double

variable_types: y double

variable_types: struct vertex { double x; struct vertex *next; } *


comp

decompiled_code:
__int64 __fastcall comp(const void *a1, const void *a2)
{
__int64 result; // rax
double v3; // xmm0_8

result = 0xFFFFFFFFLL;
v3 = (*(double *)a1 - *(double *)vlist) * (*((double *)a2 + 1) - *((double *)vlist + 1))
- (*(double *)a2 - *(double *)vlist) * (*((double *)a1 + 1) - *((double *)vlist + 1));
if ( v3 <= 0.0 )
result = v3 != 0.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
__int64 result; // rax
double v3; // xmm0_8

result = 0xFFFFFFFFLL;
v3 = (*(double *)a1 - *(double *)vlist) * (*((double *)a2 + 1) - *((double *)vlist + 1))
- (*(double *)a2 - *(double *)vlist) * (*((double *)a1 + 1) - *((double *)vlist + 1));
if ( v3 <= 0.0 )
result = v3 != 0.0;
return result;
}

original_code:
int comp(const void *a, const void *b)
{
 vertex p1,p2;
 p1.x=((vertex*)a)->x-vlist[0].x;
 p1.y=((vertex*)a)->y-vlist[0].y;
 p2.x=((vertex*)b)->x-vlist[0].x;
 p2.y=((vertex*)b)->y-vlist[0].y;
 if(p1.x*p2.y-p1.y*p2.x>0)return -1;
 if(p1.x*p2.y-p1.y*p2.x==0)return 0;
 if(p1.x*p2.y-p1.y*p2.x<0)return 1;
}

canonical_original_code:
int comp(void *a, void *b)
{
 struct vertex p1; struct vertex p2;
 p1.x=((struct vertex *)a)->x-vlist[0].x;
 p1.y=((struct vertex *)a)->y-vlist[0].y;
 p2.x=((struct vertex *)b)->x-vlist[0].x;
 p2.y=((struct vertex *)b)->y-vlist[0].y;
 if(p1.x*p2.y-p1.y*p2.x>0)return -1;
 if(p1.x*p2.y-p1.y*p2.x==0)return 0;
 if(p1.x*p2.y-p1.y*p2.x<0)return 1;
}

variable_types:
a
void *

variable_types:
b
void *


main

original_code:
int main(int argc, const char *argv[])
{
 double x, y, miny=((double)1.79769313486231570814527423731704357e+308L), minp_x=((double)1.79769313486231570814527423731704357e+308L);
 vlist=(vertex*)malloc(sizeof(vertex));
 int i;
 while(scanf("%lf%lf",&x,&y)==2){
  N++;
  vlist=(vertex*)realloc(vlist, sizeof(vertex)*N);
  vlist[N-1].x=x,vlist[N-1].y=y;
  if(y<miny || y==miny && x<minp_x)
  {
   p0=N-1;
   miny=y;
   minp_x=x;
  }
 }
 vertex tmp=vlist[0];
 vlist[0]=vlist[p0];
 vlist[p0]=tmp;
 qsort(vlist+1, N-1, sizeof(vertex), comp);
 hlist=(vertex*)malloc(sizeof(vertex)*3);
 hlist[0]=vlist[0];
 hlist[1]=vlist[1];
 hlist[2]=vlist[2];
 int hi=2;
 for(i=3;i<N;i++){
  if(turnNonLeft(hlist[hi-1],hlist[hi],vlist[i])){
   hlist[hi]=vlist[i];
   while(turnNonLeft(hlist[hi-2],hlist[hi-1],hlist[hi])){
    hi--;
    hlist[hi]=hlist[hi+1];
   }
  }else{
   hi++;
   hlist=realloc(hlist,sizeof(vertex)*(hi+1));
   hlist[hi]=vlist[i];
  }
 }
 for(i=0;i<=hi;i++){
  printf("%f %f\n", hlist[i]);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 double x; double y; double miny = ((double)1.79769313486231570814527423731704357e+308L); double minp_x = ((double)1.79769313486231570814527423731704357e+308L);
 vlist=(struct vertex *)malloc(sizeof(vertex));
 int i;
 while(scanf("%lf%lf",&x,&y)==2){
  N++;
  vlist=(struct vertex *)realloc(vlist, sizeof(vertex)*N);
  vlist[N-1].x=x,vlist[N-1].y=y;
  if(y<miny || y==miny && x<minp_x)
  {
   p0=N-1;
   miny=y;
   minp_x=x;
  }
 }
 struct vertex tmp = vlist[0];
 vlist[0]=vlist[p0];
 vlist[p0]=tmp;
 qsort(vlist+1, N-1, sizeof(vertex), comp);
 hlist=(struct vertex *)malloc(sizeof(vertex)*3);
 hlist[0]=vlist[0];
 hlist[1]=vlist[1];
 hlist[2]=vlist[2];
 int hi = 2;
 for(i=3;i<N;i++){
  if(turnNonLeft(hlist[hi-1],hlist[hi],vlist[i])){
   hlist[hi]=vlist[i];
   while(turnNonLeft(hlist[hi-2],hlist[hi-1],hlist[hi])){
    hi--;
    hlist[hi]=hlist[hi+1];
   }
  }else{
   hi++;
   hlist=realloc(hlist,sizeof(vertex)*(hi+1));
   hlist[hi]=vlist[i];
  }
 }
 for(i=0;i<=hi;i++){
  printf("%f %f\n", hlist[i]);
 }
 return 0;
}

variable_types: miny double

variable_types:
tmp
struct vertex { double x; }

variable_types: hi int


finishDraw

decompiled_code:
__int64 finishDraw()
{
cairo_show_page();
cairo_destroy();
cairo_surface_flush();
return cairo_surface_destroy();
}

canonical_decompiled_code:
__int64 func8()
{
cairo_show_page();
cairo_destroy();
cairo_surface_flush();
return cairo_surface_destroy();
}

original_code:
void finishDraw(){
 cairo_show_page(cr);
 cairo_destroy(cr);
 cairo_surface_flush(cs);
 cairo_surface_destroy(cs);
}


drawLine

decompiled_code:
__int64 drawLine()
{
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
return cairo_stroke();
}

canonical_decompiled_code:
__int64 func9()
{
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
return cairo_stroke();
}

original_code:
void drawLine(int a, int b){
 cairo_set_source_rgb (cr, 0, 0, 0);
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_stroke(cr);
}

variable_types: a int

variable_types: b int


drawTri

decompiled_code:
__int64 __fastcall drawTri(unsigned int a1, unsigned int a2, int a3)
{
printf(
"draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
a1,
a2,
a3,
*((double *)vlist + 2 * (int)a1),
*((double *)vlist + 2 * (int)a1 + 1),
*((double *)vlist + 2 * (int)a2),
*((double *)vlist + 2 * (int)a2 + 1),
*((double *)vlist + 2 * a3),
*((double *)vlist + 2 * a3 + 1));
cairo_set_source_rgb();
currentColor_0 = (currentColor_0 + 1) % palletSize;
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
cairo_fill();
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
return cairo_stroke();
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, unsigned int a2, int a3)
{
printf(
"draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
a1,
a2,
a3,
*((double *)vlist + 2 * (int)a1),
*((double *)vlist + 2 * (int)a1 + 1),
*((double *)vlist + 2 * (int)a2),
*((double *)vlist + 2 * (int)a2 + 1),
*((double *)vlist + 2 * a3),
*((double *)vlist + 2 * a3 + 1));
cairo_set_source_rgb();
currentColor_0 = (currentColor_0 + 1) % palletSize;
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
cairo_fill();
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
return cairo_stroke();
}

original_code:
void drawTri(int a,int b,int c){
 printf("draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
   a,b,c,vlist[a].x,vlist[a].y,vlist[b].x,vlist[b].y,vlist[c].x,vlist[c].y);
 static int currentColor=0;
 cairo_set_source_rgb (cr, pallet[currentColor][0]/255.0, pallet[currentColor][1]/255.0, pallet[currentColor][2]/255.0);
 currentColor=(currentColor+1)%palletSize;
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_fill(cr);
 cairo_set_source_rgb (cr, 0, 0, 0);
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_stroke(cr);
}

canonical_original_code:
void drawTri(int a, int b, int c){
 printf("draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
   a,b,c,vlist[a].x,vlist[a].y,vlist[b].x,vlist[b].y,vlist[c].x,vlist[c].y);
 static int currentColor = 0;
 cairo_set_source_rgb (cr, pallet[currentColor][0]/255.0, pallet[currentColor][1]/255.0, pallet[currentColor][2]/255.0);
 currentColor=(currentColor+1)%palletSize;
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_fill(cr);
 cairo_set_source_rgb (cr, 0, 0, 0);
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_stroke(cr);
}

variable_types: currentColor int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double *v3; // rax
int v4; // ecx
int v5; // ebx
__int64 v6; // rdi
double v8; // [rsp+0h] [rbp-18h] BYREF
double v9; // [rsp+8h] [rbp-10h]

vlist = malloc(0x10uLL);
maxx = 0x10000000000000LL;
maxy = 0x10000000000000LL;
minx = 0x7FEFFFFFFFFFFFFFLL;
miny = 0x7FEFFFFFFFFFFFFFLL;
while ( (unsigned int)__isoc99_scanf() == 2 )
{
printf("x=%f y=%f\n", v8, v9);
++N;
minx = fmin(v8, *(double *)&minx);
maxx = fmax(v8, *(double *)&maxx);
miny = fmin(v9, *(double *)&miny);
maxy = fmax(v9, *(double *)&maxy);
vlist = realloc(vlist, 16LL * N);
v3 = (double *)((char *)vlist + 16 * N - 16);
*v3 = v8;
v3[1] = v9;
}
printf("minx=%f miny=%f maxx=%f maxy=%f\n", *(double *)&minx, *(double *)&miny, *(double *)&maxx, *(double *)&maxy);
initDraw("minx=%f miny=%f maxx=%f maxy=%f\n", &v8);
v4 = N;
if ( N > 0 )
{
v5 = 0;
do
{
v6 = (unsigned int)v5++;
drawLine(v6, (unsigned int)(v5 % v4));
v4 = N;
}
while ( v5 < N );
}
finishDraw();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double *v3; // rax
int v4; // ecx
int v5; // ebx
__int64 v6; // rdi
double v8; // [rsp+0h] [rbp-18h] BYREF
double v9; // [rsp+8h] [rbp-10h]

vlist = malloc(0x10uLL);
maxx = 0x10000000000000LL;
maxy = 0x10000000000000LL;
minx = 0x7FEFFFFFFFFFFFFFLL;
miny = 0x7FEFFFFFFFFFFFFFLL;
while ( (unsigned int)__isoc99_scanf() == 2 )
{
printf("x=%f y=%f\n", v8, v9);
++N;
minx = fmin(v8, *(double *)&minx);
maxx = fmax(v8, *(double *)&maxx);
miny = fmin(v9, *(double *)&miny);
maxy = fmax(v9, *(double *)&maxy);
vlist = realloc(vlist, 16LL * N);
v3 = (double *)((char *)vlist + 16 * N - 16);
*v3 = v8;
v3[1] = v9;
}
printf("minx=%f miny=%f maxx=%f maxy=%f\n", *(double *)&minx, *(double *)&miny, *(double *)&maxx, *(double *)&maxy);
func7("minx=%f miny=%f maxx=%f maxy=%f\n", &v8);
v4 = N;
if ( N > 0 )
{
v5 = 0;
do
{
v6 = (unsigned int)v5++;
func9(v6, (unsigned int)(v5 % v4));
v4 = N;
}
while ( v5 < N );
}
func8();
return 0;
}

variable_types: n int

variable_types: p int


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int mystrlen(char *str)
{
    int len = 0;
    while(str[len] != '\0')
    {
       len++;
    }
    return len;
}

variable_types:
str
char *

variable_types: len int


mystrcmp

decompiled_code:
__int64 __fastcall mystrcmp(char *a1, _BYTE *a2)
{
char v2; // dl
int v3; // ecx
__int64 v4; // rax

v2 = *a1;
v3 = (char)*a2;
v4 = 1LL;
if ( *a2 != *a1 )
return (unsigned int)(v2 - v3);
while ( v2 )
{
v2 = a1[v4++];
v3 = (char)a2[v4 - 1];
if ( v2 != a2[v4 - 1] )
return (unsigned int)(v2 - v3);
}
return (unsigned int)-v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, _BYTE *a2)
{
char v2; // dl
int v3; // ecx
__int64 v4; // rax

v2 = *a1;
v3 = (char)*a2;
v4 = 1LL;
if ( *a2 != *a1 )
return (unsigned int)(v2 - v3);
while ( v2 )
{
v2 = a1[v4++];
v3 = (char)a2[v4 - 1];
if ( v2 != a2[v4 - 1] )
return (unsigned int)(v2 - v3);
}
return (unsigned int)-v3;
}

original_code:
int mystrcmp(char *str1, char *str2)
{
    while(*str1 == *str2 && *str1 != '\0')
    {
        str1++;
        str2++;
    }
    return (*str1 - *str2);
}


mystrstr

decompiled_code:
_BOOL8 __fastcall mystrstr(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax

v2 = *a1;
if ( *a1 == *a2 )
{
v3 = 1LL;
do
v2 = a1[v3++];
while ( v2 == a2[v3 - 1] );
}
return v2 == 0;
}

original_code:
int mystrstr(char *str1, char *str2)
{
    while(*str1 == *str2)
    {
        str1++;
        str2++;
    }
    if(*str1 == '\0')
    {
        return 1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall custom_printstring(_BYTE *a1)
{
_BYTE *v1; // rbx

v1 = a1;
if ( *a1 )
{
do
custom_iowrite();
while ( *++v1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1)
{
_BYTE *v1; // rbx

v1 = a1;
if ( *a1 )
{
do
custom_iowrite();
while ( *++v1 );
}
return 0LL;
}

original_code:
int custom_printstring(char *str)
{
    while(*str != '\0')
    {
      custom_iowrite(*str++);
    }
    return 0;
}


clearscreen

decompiled_code:
__int64 clearscreen()
{
char v1[16]; // [rsp+8h] [rbp-10h] BYREF

strcpy(v1, "\x1B[H\x1B[2J");
custom_printstring(&v1[3]);
return custom_printstring(v1);
}

canonical_decompiled_code:
__int64 func4()
{
char v1[16]; // [rsp+8h] [rbp-10h] BYREF

strcpy(v1, "\x1B[H\x1B[2J");
func3(&v1[3]);
return func3(v1);
}

original_code:
void clearscreen(void)
{
    char clearScreenSeq[] = {0x1B, '[', '2', 'J', 0x00};
    char cursorHomeSeq[] = {0x1B, '[', 'H'};
    custom_printstring(clearScreenSeq);
    custom_printstring(cursorHomeSeq);
    return;
}

canonical_original_code:
void clearscreen()
{
    char clearScreenSeq[] = {0x1B, '[', '2', 'J', 0x00};
    char cursorHomeSeq[] = {0x1B, '[', 'H'};
    custom_printstring(clearScreenSeq);
    custom_printstring(cursorHomeSeq);
    return;
}

variable_types:
clearScreenSeq
char []

variable_types:
cursorHomeSeq
char []


myprintinteger

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

if ( a1 )
{
myprintinteger((unsigned int)(a1 / 10), 0LL);
result = custom_iowrite((unsigned __int8)(a1 % 10 + 48));
}
else if ( a2 )
{
result = custom_iowrite(48LL);
}
return result;
}

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

if ( a1 )
{
func5((unsigned int)(a1 / 10), 0LL);
result = custom_iowrite((unsigned __int8)(a1 % 10 + 48));
}
else if ( a2 )
{
result = custom_iowrite(48LL);
}
return result;
}

original_code:
void myprintinteger(int number, unsigned char iStart)
{
    unsigned char digit;
    if(number == 0)
    {
        if(iStart)
        {
            custom_iowrite('0');
        }
        return;
    }
    digit = (number % 10) + 0x30;
    myprintinteger(number/10, 0);
    custom_iowrite(digit);
    return;
}

variable_types: number int

variable_types:
iStart
unsigned char

variable_types:
digit
unsigned char


mypower

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

for ( result = 1LL; a2; --a2 )
result = (unsigned int)(a1 * result);
return result;
}

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

for ( result = 1LL; a2; --a2 )
result = (unsigned int)(a1 * result);
return result;
}

original_code:
int mypower(int x, int y)
{
    if(y == 0)
    {
        return 1;
    }
    return (x*mypower(x, y-1));
}

variable_types: x int

variable_types: y int


myatoi

decompiled_code:
__int64 __fastcall myatoi(char *a1, int a2)
{
int v2; // eax
char *v3; // rcx
_DWORD *v4; // rdx
int v5; // edx
__int64 result; // rax
char v7; // al
int v8; // er10
int v9; // eax
char v10; // dl
_DWORD *v11; // r9
char v12; // al
int v13; // er8
int v14; // eax
int v15; // edx
_DWORD *v16; // r9
unsigned __int8 v17; // si

v2 = mystrlen(a1);
LODWORD(v3) = (_DWORD)a1;
*v4 = 0;
v5 = v2;
if ( a2 == 16 )
{
v12 = *a1;
if ( *a1 )
{
v13 = v5 + (_DWORD)a1 - 1;
while ( 1 )
{
v17 = v12 - 48;
if ( (unsigned __int8)(v12 - 65) <= 0x19u || v17 <= 9u )
{
if ( (unsigned __int8)(v12 - 65) > 5u && v17 > 9u )
return 6LL;
}
else if ( (unsigned __int8)(v12 - 97) > 5u )
{
return 6LL;
}
v14 = mypower(16, v13 - (int)v3);
*v16 += v15 * v14;
v12 = *v3;
if ( !*v3 )
return 0LL;
}
}
return 0LL;
}
result = 4LL;
if ( a2 != 10 )
return result;
v7 = *a1;
if ( !*a1 )
return 0LL;
v8 = v5 + (_DWORD)a1 - 1;
while ( (unsigned __int8)(v7 - 48) <= 9u )
{
v9 = mypower(10, v8 - (int)v3);
*v11 += v9 * v10;
v7 = *v3;
if ( !*v3 )
return 0LL;
}
return 6LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, int a2)
{
int v2; // eax
char *v3; // rcx
_DWORD *v4; // rdx
int v5; // edx
__int64 result; // rax
char v7; // al
int v8; // er10
int v9; // eax
char v10; // dl
_DWORD *v11; // r9
char v12; // al
int v13; // er8
int v14; // eax
int v15; // edx
_DWORD *v16; // r9
unsigned __int8 v17; // si

v2 = func0(a1);
LODWORD(v3) = (_DWORD)a1;
*v4 = 0;
v5 = v2;
if ( a2 == 16 )
{
v12 = *a1;
if ( *a1 )
{
v13 = v5 + (_DWORD)a1 - 1;
while ( 1 )
{
v17 = v12 - 48;
if ( (unsigned __int8)(v12 - 65) <= 0x19u || v17 <= 9u )
{
if ( (unsigned __int8)(v12 - 65) > 5u && v17 > 9u )
return 6LL;
}
else if ( (unsigned __int8)(v12 - 97) > 5u )
{
return 6LL;
}
v14 = func6(16, v13 - (int)v3);
*v16 += v15 * v14;
v12 = *v3;
if ( !*v3 )
return 0LL;
}
}
return 0LL;
}
result = 4LL;
if ( a2 != 10 )
return result;
v7 = *a1;
if ( !*a1 )
return 0LL;
v8 = v5 + (_DWORD)a1 - 1;
while ( (unsigned __int8)(v7 - 48) <= 9u )
{
v9 = func6(10, v8 - (int)v3);
*v11 += v9 * v10;
v7 = *v3;
if ( !*v3 )
return 0LL;
}
return 6LL;
}

variable_types: base int

variable_types:
result
int *

variable_types: iVal int

return_type: enum RET_CODE { SUCCESS=0, CMD_FAIL=1, CMD_FAILQUIET=2, NULL_ERR=3, BASE_ERR=4, PARSE_ERR=5, PARAM_ERR=6, PARAM1_ERR=7, PARAM2_ERR=8, PARAM3_ERR=9, PARAM4_ERR=10, EXIT_CODE=11 }


disableEchoCanonMode

decompiled_code:
int __fastcall disableEchoCanonMode(struct termios *termios_p)
{
__m128i v1; // xmm0
__m128i v2; // xmm1
__m128i v3; // xmm2
speed_t v4; // eax
struct termios v6; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, termios_p);
v1 = _mm_loadu_si128((const __m128i *)termios_p);
v2 = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
v3 = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&v6.c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v4 = termios_p->c_ospeed;
*(__m128i *)&v6.c_iflag = v1;
v6.c_ospeed = v4;
v6.c_lflag = v1.m128i_i32[3] & 0xFFFFFFF5;
*(__m128i *)&v6.c_line = v2;
*(__m128i *)&v6.c_cc[15] = v3;
return tcsetattr(0, 0, &v6);
}

canonical_decompiled_code:
int __fastcall func8(struct termios *termios_p)
{
__m128i v1; // xmm0
__m128i v2; // xmm1
__m128i v3; // xmm2
speed_t v4; // eax
struct termios v6; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, termios_p);
v1 = _mm_loadu_si128((const __m128i *)termios_p);
v2 = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
v3 = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&v6.c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v4 = termios_p->c_ospeed;
*(__m128i *)&v6.c_iflag = v1;
v6.c_ospeed = v4;
v6.c_lflag = v1.m128i_i32[3] & 0xFFFFFFF5;
*(__m128i *)&v6.c_line = v2;
*(__m128i *)&v6.c_cc[15] = v3;
return tcsetattr(0, 0, &v6);
}

original_code:
void disableEchoCanonMode(struct termios *oldSettings)
{
    struct termios newSettings;
    tcgetattr(0, oldSettings);
    newSettings = *oldSettings;
    newSettings.c_lflag &= ~(0000002 | 0000010);
    tcsetattr(0, 0, &newSettings);
    return;
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *


restoreTerminalMode

decompiled_code:
int __fastcall restoreTerminalMode(struct termios *termios_p)
{
return tcsetattr(0, 0, termios_p);
}

canonical_decompiled_code:
int __fastcall func9(struct termios *termios_p)
{
return tcsetattr(0, 0, termios_p);
}

original_code:
void restoreTerminalMode(struct termios *oldSettings)
{
    tcsetattr(0, 0, oldSettings);
    return;
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall stack_initialize(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 5LL;
*(_QWORD *)(a1 + 32) = 0LL;
result = 0LL;
*(_DWORD *)(a1 + 200) = 0;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
return result;
}

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

if ( !a1 )
return 5LL;
*(_QWORD *)(a1 + 32) = 0LL;
result = 0LL;
*(_DWORD *)(a1 + 200) = 0;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
return result;
}

original_code:
STACK_RET_CODE stack_initialize(HIST_STACK *histStack)
{
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    histStack->stackSize = 0;
    memset(histStack->stackBuffer, 0, 40);
    return STACK_SUCCESS;
}

canonical_original_code:
enum STACK_RET_CODE stack_initialize(struct HIST_STACK *histStack)
{
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    histStack->stackSize = 0;
    memset(histStack->stackBuffer, 0, 40);
    return STACK_SUCCESS;
}

variable_types: struct HIST_STACK { char stackBuffer[5][40]; int stackSize; int accessIndex; enum STACK_POP_STATE { STACK_IDLE=0, STACK_UP=1, STACK_DOWN=2 } stack_pop_state; } *

return_type: enum STACK_RET_CODE { STACK_SUCCESS=0, STACK_FAILURE=1, STACK_UNDERFLOW=2, STACK_OVERFLOW=3, STACK_ERROR=4, STACK_NULL_ERR=5 }

user_defined_types: struct HIST_STACK { char stackBuffer[5][40]; int stackSize; int accessIndex; enum STACK_POP_STATE stack_pop_state; }


decompiled_code:
__int64 __fastcall stack_push(void *dest, void *src)
{
int v4; // er8
__int64 result; // rax
char *v6; // rbx
void *v7; // r13
int v8; // eax
void *v9; // rdi
const void *v10; // rsi
int v11; // eax
int v12; // eax

if ( !dest )
return 5LL;
v4 = mystrlen(src);
result = 0LL;
if ( v4 )
{
v6 = (char *)dest + 120;
do
{
v7 = v6;
v8 = mystrlen(v6);
v9 = v6 + 40;
v10 = v6;
v6 -= 40;
memcpy(v9, v10, v8 + 1);
}
while ( v7 != dest );
v11 = *((_DWORD *)dest + 50);
if ( v11 <= 4 )
*((_DWORD *)dest + 50) = v11 + 1;
v12 = mystrlen(src);
memcpy(dest, src, v12 + 1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *dest, void *src)
{
int v4; // er8
__int64 result; // rax
char *v6; // rbx
void *v7; // r13
int v8; // eax
void *v9; // rdi
const void *v10; // rsi
int v11; // eax
int v12; // eax

if ( !dest )
return 5LL;
v4 = mystrlen(src);
result = 0LL;
if ( v4 )
{
v6 = (char *)dest + 120;
do
{
v7 = v6;
v8 = mystrlen(v6);
v9 = v6 + 40;
v10 = v6;
v6 -= 40;
memcpy(v9, v10, v8 + 1);
}
while ( v7 != dest );
v11 = *((_DWORD *)dest + 50);
if ( v11 <= 4 )
*((_DWORD *)dest + 50) = v11 + 1;
v12 = mystrlen(src);
memcpy(dest, src, v12 + 1);
result = 0LL;
}
return result;
}

original_code:
STACK_RET_CODE stack_push(HIST_STACK *histStack, char *entry)
{
    int index = 0;
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    if(mystrlen(entry) == 0)
    {
        return STACK_SUCCESS;
    }
    for(index = 5 - 1; index > 0; index--)
    {
        memcpy(histStack->stackBuffer[index],
             histStack->stackBuffer[index - 1], mystrlen(histStack->stackBuffer[index - 1]) + 1);
    }
    if(histStack->stackSize < 5)
    {
        histStack->stackSize++;
    }
    memcpy(histStack->stackBuffer[0], entry, mystrlen(entry) + 1);
    return STACK_SUCCESS;
}

canonical_original_code:
enum STACK_RET_CODE stack_push(struct HIST_STACK *histStack, char *entry)
{
    int index = 0;
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    if(mystrlen(entry) == 0)
    {
        return STACK_SUCCESS;
    }
    for(index = 5 - 1; index > 0; index--)
    {
        memcpy(histStack->stackBuffer[index],
             histStack->stackBuffer[index - 1], mystrlen(histStack->stackBuffer[index - 1]) + 1);
    }
    if(histStack->stackSize < 5)
    {
        histStack->stackSize++;
    }
    memcpy(histStack->stackBuffer[0], entry, mystrlen(entry) + 1);
    return STACK_SUCCESS;
}

variable_types:
entry
char *

variable_types: index int

user_defined_types: enum STACK_RET_CODE { STACK_SUCCESS=0, STACK_FAILURE=1, STACK_UNDERFLOW=2, STACK_OVERFLOW=3, STACK_ERROR=4, STACK_NULL_ERR=5 }

user_defined_types: enum STACK_POP_STATE { STACK_IDLE=0, STACK_UP=1, STACK_DOWN=2 }


original_code:
STACK_RET_CODE stack_pop_up(HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_DOWN)
    {
        histStack->accessIndex++;
    }
    if(histStack->accessIndex < histStack->stackSize)
    {
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                        , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        histStack->accessIndex++;
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}

canonical_original_code:
enum STACK_RET_CODE stack_pop_up(struct HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_DOWN)
    {
        histStack->accessIndex++;
    }
    if(histStack->accessIndex < histStack->stackSize)
    {
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                        , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        histStack->accessIndex++;
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}

variable_types: prevaccessIndex int


original_code:
STACK_RET_CODE stack_pop_down(HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_UP)
    {
        histStack->accessIndex--;
    }
    if(histStack->accessIndex > 0)
    {
        histStack->accessIndex--;
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}

canonical_original_code:
enum STACK_RET_CODE stack_pop_down(struct HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_UP)
    {
        histStack->accessIndex--;
    }
    if(histStack->accessIndex > 0)
    {
        histStack->accessIndex--;
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}


checkIfElementExists

decompiled_code:
__int64 __fastcall checkIfElementExists(__int64 a1, __int64 a2)
{
int v2; // ebp
__int64 v3; // rbx

if ( *(int *)(a1 + 200) <= 0 )
return 1LL;
v2 = 0;
v3 = a1;
do
{
if ( !(unsigned int)mystrcmp(v3, a2) )
return 0LL;
++v2;
v3 += 40LL;
}
while ( *(_DWORD *)(a1 + 200) > v2 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebp
__int64 v3; // rbx

if ( *(int *)(a1 + 200) <= 0 )
return 1LL;
v2 = 0;
v3 = a1;
do
{
if ( !(unsigned int)mystrcmp(v3, a2) )
return 0LL;
++v2;
v3 += 40LL;
}
while ( *(_DWORD *)(a1 + 200) > v2 );
return 1LL;
}

original_code:
STACK_RET_CODE checkIfElementExists(HIST_STACK *histStack, char *entry)
{
    int iVal;
    for(iVal = 0; iVal < histStack->stackSize; iVal++)
    {
        if(mystrcmp(histStack->stackBuffer[iVal], entry) == 0)
        {
            return STACK_SUCCESS;
        }
    }
    return STACK_FAILURE;
}

canonical_original_code:
enum STACK_RET_CODE checkIfElementExists(struct HIST_STACK *histStack, char *entry)
{
    int iVal;
    for(iVal = 0; iVal < histStack->stackSize; iVal++)
    {
        if(mystrcmp(histStack->stackBuffer[iVal], entry) == 0)
        {
            return STACK_SUCCESS;
        }
    }
    return STACK_FAILURE;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)stack_initialize(&g_histstack, argv, envp) )
return -1;
disableEchoCanonMode(&g_OldSettings);
custom_printstring(" _______________________________________________________ \n\r");
custom_printstring("/ \\\n\r");
custom_printstring("| Welcome to CLI |\n\r");
custom_printstring("\\_________ _______________________________/ \n\r");
custom_printstring(" \\_ __/ ___---------__ \n\r");
custom_printstring(" \\ _/ / \\_ \n\r");
custom_printstring(" \\ / / \\ \n\r");
custom_printstring(" | / | _ _ \\ \\ \n\r");
custom_printstring(" | | / / \\ / \\ | \\ \n\r");
custom_printstring(" | | || || || | \n\r");
custom_printstring(" | | | \\_//\\\\_/ | | \n\r");
custom_printstring(" | | | || | _ / / | \n\r");
custom_printstring(" \\ \\ |_________|| \\/ / / \n\r");
custom_printstring(" \\ \\_ |_|_|_|_|/| _/___/ \n\r");
custom_printstring(" \\__> _ _/_ _ / | \n\r");
custom_printstring(" .|_|_|_|_| | \n\r");
custom_printstring(" | / \n\r");
custom_printstring(" |__________/ \n\r");
custom_printstring("Welcome to CLI");
custom_printstring("\r\n");
custom_printstring("Type \"help\" for list of commands");
custom_printstring("\r\n");
custom_printstring("\r\n");
custom_printstring("Hit <TAB> for autocomplete");
custom_printstring("\r\n");
custom_printstring("Hit <UP>/<DOWN> for command history");
custom_printstring("\r\n");
custom_printstring("Hit <LEFT/RIGHT> for line editing");
while ( (unsigned int)CLILoop() != 11 )
;
restoreTerminalMode(&g_OldSettings);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    if(stack_initialize(&g_histstack) != STACK_SUCCESS)
    {
      return -1;
    }
    disableEchoCanonMode(&g_OldSettings);
    custom_printstring(" _______________________________________________________ \n\r");
    custom_printstring("/                                                       \\\n\r");
    custom_printstring("|               Welcome to CLI                          |\n\r");
    custom_printstring("\\_________              _______________________________/ \n\r");
    custom_printstring("          \\_         __/    ___---------__               \n\r");
    custom_printstring("            \\      _/      /              \\_             \n\r");
    custom_printstring("             \\    /       /                 \\            \n\r");
    custom_printstring("              |  /       | _    _ \\          \\           \n\r");
    custom_printstring("              | |       / / \\  / \\ |          \\          \n\r");
    custom_printstring("              | |       ||   ||   ||           |         \n\r");
    custom_printstring("              | |       | \\_//\\\\_/ |           |         \n\r");
    custom_printstring("              | |         |  ||     | _  / /   |         \n\r");
    custom_printstring("               \\ \\        |_________|| \\/ /   /          \n\r");
    custom_printstring("                \\ \\_       |_|_|_|_|/|  _/___/           \n\r");
    custom_printstring("                 \\__>       _ _/_ _ /  |                 \n\r");
    custom_printstring("                          .|_|_|_|_|   |                 \n\r");
    custom_printstring("                          |           /                  \n\r");
    custom_printstring("                          |__________/                   \n\r");
    custom_printstring("Welcome to CLI");
    custom_printstring("\r\n");
    custom_printstring("Type \"help\" for list of commands");
    custom_printstring("\r\n");
    custom_printstring("\r\n");
    custom_printstring("Hit    <TAB>     for autocomplete");
    custom_printstring("\r\n");
    custom_printstring("Hit <UP>/<DOWN>  for command history");
    custom_printstring("\r\n");
    custom_printstring("Hit <LEFT/RIGHT> for line editing");
    while(1)
    {
       if(CLILoop() == EXIT_CODE)
       {
         restoreTerminalMode(&g_OldSettings);
         break;
       }
    }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


help

original_code:
RET_CODE help(PMSG *pmsg)
{
    int numCmds, iVal;
    numCmds = g_CmdTblSize;
    custom_printstring("----------------------------------------------------------------\n\r");
    custom_printstring("Command Name\n\r");
    custom_printstring("----------------------------------------------------------------\n\r");
    for(iVal = 0; iVal < numCmds; iVal++)
    {
        custom_printstring(cmdTable[iVal].cmdName);
        custom_printstring("\n\r");
    }
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE help(struct PMSG *pmsg)
{
    int numCmds; int iVal;
    numCmds = g_CmdTblSize;
    custom_printstring("----------------------------------------------------------------\n\r");
    custom_printstring("Command Name\n\r");
    custom_printstring("----------------------------------------------------------------\n\r");
    for(iVal = 0; iVal < numCmds; iVal++)
    {
        custom_printstring(cmdTable[iVal].cmdName);
        custom_printstring("\n\r");
    }
    return SUCCESS;
}

variable_types: struct PMSG { char cmdBuff[40]; int argc; char argv[4][10]; enum PARSE_STATE { INSIDE_WORD=0, OUTSIDE_WORD=1 } parse_state; enum LEFT_RIGHT_STATE { LEFT_RIGHT_ACTIVE=0, LEFT_RIGHT_IDLE=1 } left_right_state; } *

variable_types: numCmds int

user_defined_types: enum RET_CODE { SUCCESS=0, CMD_FAIL=1, CMD_FAILQUIET=2, NULL_ERR=3, BASE_ERR=4, PARSE_ERR=5, PARAM_ERR=6, PARAM1_ERR=7, PARAM2_ERR=8, PARAM3_ERR=9, PARAM4_ERR=10, EXIT_CODE=11 }

user_defined_types: struct PMSG { char cmdBuff[40]; int argc; char argv[4][10]; enum PARSE_STATE parse_state; enum LEFT_RIGHT_STATE left_right_state; }


echo

decompiled_code:
__int64 __fastcall echo(__int64 a1)
{
custom_printstring(a1 + 54);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
custom_printstring(a1 + 54);
return 0LL;
}

original_code:
RET_CODE echo(PMSG *pmsg)
{
    custom_printstring(pmsg->argv[1]);
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE echo(struct PMSG *pmsg)
{
    custom_printstring(pmsg->argv[1]);
    return SUCCESS;
}

user_defined_types: enum PARSE_STATE { INSIDE_WORD=0, OUTSIDE_WORD=1 }

user_defined_types: enum LEFT_RIGHT_STATE { LEFT_RIGHT_ACTIVE=0, LEFT_RIGHT_IDLE=1 }


history

decompiled_code:
__int64 history()
{
char *v0; // rbp
int v1; // ebx
char *v2; // rdi

if ( g_histstack[50] <= 0 )
return 0LL;
v0 = (char *)g_histstack;
v1 = 0;
do
{
v2 = v0;
++v1;
v0 += 40;
custom_printstring(v2);
custom_printstring(&unk_F40);
}
while ( g_histstack[50] > v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rbp
int v1; // ebx
char *v2; // rdi

if ( g_histstack[50] <= 0 )
return 0LL;
v0 = (char *)g_histstack;
v1 = 0;
do
{
v2 = v0;
++v1;
v0 += 40;
custom_printstring(v2);
custom_printstring(&unk_F40);
}
while ( g_histstack[50] > v1 );
return 0LL;
}

original_code:
RET_CODE history(PMSG *pmsg)
{
    int iVal = 0;
    for(iVal = 0; iVal < g_histstack.stackSize; iVal++)
    {
        custom_printstring(g_histstack.stackBuffer[iVal]);
        custom_printstring("\r\n");
    }
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE history(struct PMSG *pmsg)
{
    int iVal = 0;
    for(iVal = 0; iVal < g_histstack.stackSize; iVal++)
    {
        custom_printstring(g_histstack.stackBuffer[iVal]);
        custom_printstring("\r\n");
    }
    return SUCCESS;
}


myexit

decompiled_code:
__int64 myexit()
{
custom_printstring("****** Exiting ******\n\r");
return 11LL;
}

canonical_decompiled_code:
__int64 func3()
{
custom_printstring("****** Exiting ******\n\r");
return 11LL;
}

original_code:
RET_CODE myexit(PMSG *pmsg)
{
    custom_printstring("******"" ""Exiting"" ""******""\n\r");
    return EXIT_CODE;
}

canonical_original_code:
enum RET_CODE myexit(struct PMSG *pmsg)
{
    custom_printstring("******"" ""Exiting"" ""******""\n\r");
    return EXIT_CODE;
}


clear

decompiled_code:
__int64 clear()
{
clearscreen();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
clearscreen();
return 0LL;
}

original_code:
RET_CODE clear(PMSG *pmsg)
{
    clearscreen();
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE clear(struct PMSG *pmsg)
{
    clearscreen();
    return SUCCESS;
}


CLILoop

decompiled_code:
__int64 CLILoop()
{
SMHandler_1 = (__int64 (__fastcall *)(_QWORD))SMHandler_1(&g_pmsg);
return SMHandler_1 == 0LL ? 0xB : 0;
}

canonical_decompiled_code:
__int64 func5()
{
SMHandler_1 = (__int64 (__fastcall *)(_QWORD))SMHandler_1(&g_pmsg);
return SMHandler_1 == 0LL ? 0xB : 0;
}

original_code:
RET_CODE CLILoop(void)
{
    static pFuncPtr SMHandler = (pFuncPtr)InitState;
    SMHandler = (pFuncPtr)SMHandler((void *)&g_pmsg);
    if(SMHandler == ((void *)0))
    {
        return EXIT_CODE;
    }
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE CLILoop()
{
    static int (*(*SMHandler)(void *))(void *) = (pFuncPtr)InitState;
    SMHandler = (int (*(*)(void *))(void *))SMHandler((void *)&g_pmsg);
    if(SMHandler == ((void *)0))
    {
        return EXIT_CODE;
    }
    return SUCCESS;
}

variable_types:
SMHandler
int (*(*)(void *))(void *)


convertArgumentsIntoInteger

decompiled_code:
__int64 __fastcall convertArgumentsIntoInteger(int a1)
{
unsigned __int64 v1; // rbp
unsigned __int64 v2; // rbx

if ( a1 <= 1 )
return 0LL;
v1 = (unsigned int)((_DWORD)&g_CmdArgs + 4);
v2 = (unsigned int)((_DWORD)&g_pmsg + 54);
do
{
if ( *(_BYTE *)v2 == 48 && (*(_BYTE *)(v2 + 1) & 0xDF) == 88 )
{
if ( (unsigned int)myatoi(v2 + 2, 16LL, v1) == 6 )
return 6LL;
}
else if ( (unsigned int)myatoi(v2, 10LL, v1) == 6 )
{
return 6LL;
}
v1 += 4LL;
v2 += 10LL;
}
while ( (_UNKNOWN *)v1 != (_UNKNOWN *)((char *)&g_CmdArgs + 4 * (unsigned int)(a1 - 2) + 8) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned __int64 v1; // rbp
unsigned __int64 v2; // rbx

if ( a1 <= 1 )
return 0LL;
v1 = (unsigned int)((_DWORD)&g_CmdArgs + 4);
v2 = (unsigned int)((_DWORD)&g_pmsg + 54);
do
{
if ( *(_BYTE *)v2 == 48 && (*(_BYTE *)(v2 + 1) & 0xDF) == 88 )
{
if ( (unsigned int)myatoi(v2 + 2, 16LL, v1) == 6 )
return 6LL;
}
else if ( (unsigned int)myatoi(v2, 10LL, v1) == 6 )
{
return 6LL;
}
v1 += 4LL;
v2 += 10LL;
}
while ( (_UNKNOWN *)v1 != (_UNKNOWN *)((char *)&g_CmdArgs + 4 * (unsigned int)(a1 - 2) + 8) );
return 0LL;
}

canonical_original_code:
enum RET_CODE convertArgumentsIntoInteger(int nArgs)
{
    int iVal;
    for(iVal = 1; iVal < nArgs; iVal++)
    {
        if(((((g_pmsg.argv[iVal][0]) == '0') && (((g_pmsg.argv[iVal][1]) == 'x') || ((g_pmsg.argv[iVal][1]) == 'X'))) ? 1 : 0))
        {
            if(myatoi(&g_pmsg.argv[iVal][2], 16, (int *)&g_CmdArgs[iVal]) == PARAM_ERR)
            {
                return PARAM_ERR;
            }
        }
        else
        {
            if(myatoi(&g_pmsg.argv[iVal][0], 10, (int *)&g_CmdArgs[iVal]) == PARAM_ERR)
            {
                return PARAM_ERR;
            }
        }
    }
    return SUCCESS;
}

variable_types: nArgs int


add

decompiled_code:
__int64 __fastcall add(__int64 a1)
{
unsigned int v1; // er12

v1 = 6;
if ( !(unsigned int)convertArgumentsIntoInteger(*(_DWORD *)(a1 + 40)) )
{
v1 = 0;
myprintinteger(g_CmdArgs[1], 1LL);
custom_printstring(" + ");
myprintinteger(g_CmdArgs[2], 1LL);
custom_printstring(" = ");
myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1LL);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // er12

v1 = 6;
if ( !(unsigned int)func6(*(_DWORD *)(a1 + 40)) )
{
v1 = 0;
myprintinteger(g_CmdArgs[1], 1LL);
custom_printstring(" + ");
myprintinteger(g_CmdArgs[2], 1LL);
custom_printstring(" = ");
myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1LL);
}
return v1;
}

original_code:
RET_CODE add(PMSG *pmsg)
{
    if(convertArgumentsIntoInteger(pmsg->argc) != SUCCESS)
    {
        return PARAM_ERR;
    }
    myprintinteger(g_CmdArgs[1], 1);
    custom_printstring(" + ");
    myprintinteger(g_CmdArgs[2], 1);
    custom_printstring(" = ");
    myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1);
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE add(struct PMSG *pmsg)
{
    if(convertArgumentsIntoInteger(pmsg->argc) != SUCCESS)
    {
        return PARAM_ERR;
    }
    myprintinteger(g_CmdArgs[1], 1);
    custom_printstring(" + ");
    myprintinteger(g_CmdArgs[2], 1);
    custom_printstring(" = ");
    myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1);
    return SUCCESS;
}


decompiled_code:
int custom_ioread()
{
return getchar();
}

canonical_decompiled_code:
int func0()
{
return getchar();
}

original_code:
char custom_ioread()
{
    char ch;
    ch = getchar();
    return ch;
}

variable_types: ch char

return_type: char


decompiled_code:
int __fastcall custom_iowrite(char a1)
{
return putchar(a1);
}

canonical_decompiled_code:
int __fastcall func1(char a1)
{
return putchar(a1);
}

original_code:
void custom_iowrite(char ch)
{
    putchar(ch);
    return;
}


initializeAutoCompl

decompiled_code:
__int64 __fastcall initializeAutoCompl(__int64 a1)
{
__int64 result; // rax

result = 1LL;
if ( a1 )
{
*(_QWORD *)(a1 + 400) = 0LL;
result = 3LL;
*(_DWORD *)(a1 + 408) = 0;
}
return result;
}

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

result = 1LL;
if ( a1 )
{
*(_QWORD *)(a1 + 400) = 0LL;
result = 3LL;
*(_DWORD *)(a1 + 408) = 0;
}
return result;
}

original_code:
AUTOCOMPL_RET_CODE initializeAutoCompl(AUTOCOMPL_STRUCT *autoComplStruct)
{
    if(autoComplStruct == ((void *)0))
    {
      return AUTOCOMPL_NULL_ERR;
    }
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    autoComplStruct->autoComplState = AUTO_IDLE;
    return AUTOCOMPL_SUCCESS;
}

canonical_original_code:
enum AUTOCOMPL_RET_CODE initializeAutoCompl(struct AUTOCOMPL_STRUCT *autoComplStruct)
{
    if(autoComplStruct == ((void *)0))
    {
      return AUTOCOMPL_NULL_ERR;
    }
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    autoComplStruct->autoComplState = AUTO_IDLE;
    return AUTOCOMPL_SUCCESS;
}

variable_types: struct AUTOCOMPL_STRUCT { char matchList[20][20]; int matchIndex; int totalHits; enum AUTOCOMPL_STATE { AUTO_IDLE=0, AUTO_ACTIVE=1 } autoComplState; } *

return_type: enum AUTOCOMPL_RET_CODE { AUTOCOMPL_NOHITS=0, AUTOCOMPL_NULL_ERR=1, AUTOCOMPL_ERR=2, AUTOCOMPL_SUCCESS=3 }

user_defined_types: struct AUTOCOMPL_STRUCT { char matchList[20][20]; int matchIndex; int totalHits; enum AUTOCOMPL_STATE autoComplState; }


buildMatchList

decompiled_code:
__int64 __fastcall buildMatchList(__int64 a1, __int64 a2, char *a3, int a4)
{
unsigned __int64 v4; // r13
char *v6; // rbx
int v7; // eax
__int64 v8; // rdx
char *v9; // rsi
__int64 result; // rax

*(_QWORD *)(a1 + 400) = 0LL;
if ( a4 <= 0 )
return 0LL;
v4 = (unsigned __int64)&a3[64 * (unsigned __int64)(unsigned int)(a4 - 1) + 64];
v6 = a3;
do
{
while ( (unsigned int)mystrstr(a2, v6) != 1 )
{
v6 += 64;
if ( v6 == (char *)v4 )
goto LABEL_6;
}
v7 = mystrlen(v6);
v8 = *(int *)(a1 + 404);
v9 = v6;
v6 += 64;
*(_DWORD *)(a1 + 404) = v8 + 1;
memcpy((void *)(a1 + 20 * v8), v9, v7 + 1);
}
while ( v6 != (char *)v4 );
LABEL_6:
result = 3LL;
if ( !*(_DWORD *)(a1 + 404) )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, char *a3, int a4)
{
unsigned __int64 v4; // r13
char *v6; // rbx
int v7; // eax
__int64 v8; // rdx
char *v9; // rsi
__int64 result; // rax

*(_QWORD *)(a1 + 400) = 0LL;
if ( a4 <= 0 )
return 0LL;
v4 = (unsigned __int64)&a3[64 * (unsigned __int64)(unsigned int)(a4 - 1) + 64];
v6 = a3;
do
{
while ( (unsigned int)mystrstr(a2, v6) != 1 )
{
v6 += 64;
if ( v6 == (char *)v4 )
goto LABEL_6;
}
v7 = mystrlen(v6);
v8 = *(int *)(a1 + 404);
v9 = v6;
v6 += 64;
*(_DWORD *)(a1 + 404) = v8 + 1;
memcpy((void *)(a1 + 20 * v8), v9, v7 + 1);
}
while ( v6 != (char *)v4 );
LABEL_6:
result = 3LL;
if ( !*(_DWORD *)(a1 + 404) )
result = 0LL;
return result;
}

original_code:
AUTOCOMPL_RET_CODE buildMatchList(AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, CMD_TABLE *cmdTable, int cmdTableSize)
{
    int index = 0;
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    for(index = 0; index < cmdTableSize; index++)
    {
        if(mystrstr(searchStr, cmdTable[index].cmdName) == 1)
        {
            memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
                , cmdTable[index].cmdName, mystrlen(cmdTable[index].cmdName) +1);
        }
    }
    if(autoComplStruct->totalHits == 0)
    {
        return AUTOCOMPL_NOHITS;
    }
    return AUTOCOMPL_SUCCESS;
}

canonical_original_code:
enum AUTOCOMPL_RET_CODE buildMatchList(struct AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, struct CMD_TABLE *cmdTable, int cmdTableSize)
{
    int index = 0;
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    for(index = 0; index < cmdTableSize; index++)
    {
        if(mystrstr(searchStr, cmdTable[index].cmdName) == 1)
        {
            memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
                , cmdTable[index].cmdName, mystrlen(cmdTable[index].cmdName) +1);
        }
    }
    if(autoComplStruct->totalHits == 0)
    {
        return AUTOCOMPL_NOHITS;
    }
    return AUTOCOMPL_SUCCESS;
}

variable_types:
searchStr
char *

variable_types: struct CMD_TABLE { char cmdName[10]; enum RET_CODE { SUCCESS=0, CMD_FAIL=1, CMD_FAILQUIET=2, NULL_ERR=3, BASE_ERR=4, PARSE_ERR=5, PARAM_ERR=6, PARAM1_ERR=7, PARAM2_ERR=8, PARAM3_ERR=9, PARAM4_ERR=10, EXIT_CODE=11 } (*cmdFuncPtr)(struct PMSG { char cmdBuff[40]; int argc; char argv[4][10]; enum PARSE_STATE { INSIDE_WORD=0, OUTSIDE_WORD=1 } parse_state; enum LEFT_RIGHT_STATE { LEFT_RIGHT_ACTIVE=0, LEFT_RIGHT_IDLE=1 } left_right_state; } *); int argNum; char cmdUsage[30]; } *

variable_types: cmdTableSize int

user_defined_types: enum AUTOCOMPL_RET_CODE { AUTOCOMPL_NOHITS=0, AUTOCOMPL_NULL_ERR=1, AUTOCOMPL_ERR=2, AUTOCOMPL_SUCCESS=3 }

user_defined_types: struct CMD_TABLE { char cmdName[10]; enum RET_CODE (*cmdFuncPtr)(struct PMSG *); int argNum; char cmdUsage[30]; }

user_defined_types: enum AUTOCOMPL_STATE { AUTO_IDLE=0, AUTO_ACTIVE=1 }


findMatch

original_code:
AUTOCOMPL_RET_CODE findMatch(AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, CMD_TABLE *cmdTable, int cmdTableSize)
{
    AUTOCOMPL_RET_CODE retCode;
    if(autoComplStruct->autoComplState == AUTO_IDLE)
    {
        if((retCode = buildMatchList(autoComplStruct, searchStr, cmdTable, cmdTableSize)) != AUTOCOMPL_SUCCESS)
        {
            return retCode;
        }
        autoComplStruct->autoComplState = AUTO_ACTIVE;
        memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
            , searchStr, mystrlen(searchStr) +1);
    }
    memcpy(searchStr, autoComplStruct->matchList[autoComplStruct->matchIndex]
            , mystrlen(autoComplStruct->matchList[autoComplStruct->matchIndex]) + 1);
    autoComplStruct->matchIndex = (++autoComplStruct->matchIndex) % autoComplStruct->totalHits;
    return AUTOCOMPL_SUCCESS;
}

canonical_original_code:
enum AUTOCOMPL_RET_CODE findMatch(struct AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, struct CMD_TABLE *cmdTable, int cmdTableSize)
{
    enum AUTOCOMPL_RET_CODE retCode;
    if(autoComplStruct->autoComplState == AUTO_IDLE)
    {
        if((retCode = buildMatchList(autoComplStruct, searchStr, cmdTable, cmdTableSize)) != AUTOCOMPL_SUCCESS)
        {
            return retCode;
        }
        autoComplStruct->autoComplState = AUTO_ACTIVE;
        memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
            , searchStr, mystrlen(searchStr) +1);
    }
    memcpy(searchStr, autoComplStruct->matchList[autoComplStruct->matchIndex]
            , mystrlen(autoComplStruct->matchList[autoComplStruct->matchIndex]) + 1);
    autoComplStruct->matchIndex = (++autoComplStruct->matchIndex) % autoComplStruct->totalHits;
    return AUTOCOMPL_SUCCESS;
}

variable_types: enum AUTOCOMPL_RET_CODE { AUTOCOMPL_NOHITS=0, AUTOCOMPL_NULL_ERR=1, AUTOCOMPL_ERR=2, AUTOCOMPL_SUCCESS=3 }


A

decompiled_code:
_BOOL8 __fastcall A(int a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
return a1 != 0;
}

original_code:
int A(int x) {
    return x != 0;
}

canonical_original_code:
int A(int x) {
    return x != 0;
}

variable_types: x int


B

decompiled_code:
_BOOL8 __fastcall B(int a1)
{
return a1 != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
return a1 != -1;
}

original_code:
int B(int x) {
    return x != ~0;
}

canonical_original_code:
int B(int x) {
    return x != ~0;
}


decompiled_code:
int __fastcall print_good(const char *a1)
{
return printf("%s %s %s", "\x1B[1m\x1B[32m", a1, "\x1B[0m");
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
return printf("%s %s %s", "\x1B[1m\x1B[32m", a1, "\x1B[0m");
}

original_code:
void print_good(char * string) {
    printf("%s %s %s", "\033[1m\033[32m", string, "\033[0m");
}

canonical_original_code:
void print_good(char *string) {
    printf("%s %s %s", "\033[1m\033[32m", string, "\033[0m");
}

variable_types:
string
char *


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

if ( a2 > 0 && a1 > 0 )
{
result = 0x7FFFFFFFLL;
if ( 0x7FFFFFFF - a2 < a1 )
return result;
return (unsigned int)(a2 + a1);
}
if ( a2 >= 0 || a1 >= 0 || (int)(0x80000000 - a2) <= a1 )
return (unsigned int)(a2 + a1);
return 0x80000000LL;
}

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

if ( a2 > 0 && a1 > 0 )
{
result = 0x7FFFFFFFLL;
if ( 0x7FFFFFFF - a2 < a1 )
return result;
return (unsigned int)(a2 + a1);
}
if ( a2 >= 0 || a1 >= 0 || (int)(0x80000000 - a2) <= a1 )
return (unsigned int)(a2 + a1);
return 0x80000000LL;
}

original_code:
int saturating_add(int x, int y) {
    int TMin = (-0x7fffffff - 1);
    int TMax = ~TMin;
    if (y>0 && x>0 && (TMax - y < x)) {
            return TMax;
    } else if (y<0 && x<0 && (TMin - y > x)) {
            return TMin;
    } else {
        return x + y;
    }
}

variable_types: y int

variable_types: TMin int

variable_types: TMax int


canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return printf("%s %s %s", "\x1B[1m\x1B[32m", a1, "\x1B[0m");
}


decompiled_code:
__int64 __fastcall rotate_left(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

original_code:
unsigned rotate_left(unsigned x, int n) {
    unsigned a = x;
    a = a << n;
    x = x >> (((sizeof(int) << 3) - n) & (~(sizeof(int) << 3)));
    return a | x;
}

canonical_original_code:
unsigned int rotate_left(unsigned int x, int n) {
    unsigned int a = x;
    a = a << n;
    x = x >> (((sizeof(int) << 3) - n) & (~(sizeof(int) << 3)));
    return a | x;
}

variable_types:
x
unsigned int

variable_types: n int

variable_types:
a
unsigned int

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall any_odd_one(int a1)
{
return (a1 & 0xAAAAAAAA) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
return (a1 & 0xAAAAAAAA) != 0;
}

original_code:
int any_odd_one(unsigned x) {
        unsigned mask = 0xAAAAAAAA;
        return (x & mask) != 0;
    }

canonical_original_code:
int any_odd_one(unsigned int x) {
        unsigned int mask = 0xAAAAAAAA;
        return (x & mask) != 0;
    }

variable_types:
mask
unsigned int


decompiled_code:
_BOOL8 __fastcall iposix_gid_compare(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1, int a2)
{
return a1 == a2;
}

original_code:
static int
iposix_gid_compare (group_id_t a, group_id_t b)
{
  return a.value == b.value;
}

canonical_original_code:
static int iposix_gid_compare(struct group_id_t a, struct group_id_t b)
{
  return a.value == b.value;
}

variable_types:
a
struct group_id_t { int value; }

variable_types:
b
struct group_id_t


decompiled_code:
_BOOL8 __fastcall iposix_gid_valid(int a1)
{
return a1 != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
return a1 != -1;
}

original_code:
static int
iposix_gid_valid (group_id_t gid)
{
  return gid.value != -1;
}

canonical_original_code:
static int iposix_gid_valid(struct group_id_t gid)
{
  return gid.value != -1;
}

variable_types:
gid
struct group_id_t { int value; }


decompiled_code:
_BOOL8 __fastcall iposix_uid_compare(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, int a2)
{
return a1 == a2;
}

original_code:
static int
iposix_uid_compare (user_id_t a, user_id_t b)
{
  return a.value == b.value;
}

canonical_original_code:
static int iposix_uid_compare(struct user_id_t a, struct user_id_t b)
{
  return a.value == b.value;
}

variable_types:
a
struct user_id_t { int value; }

variable_types:
b
struct user_id_t


decompiled_code:
_BOOL8 __fastcall iposix_uid_valid(int a1)
{
return a1 != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1)
{
return a1 != -1;
}

original_code:
static int
iposix_uid_valid (user_id_t uid)
{
  return uid.value != -1;
}

canonical_original_code:
static int iposix_uid_valid(struct user_id_t uid)
{
  return uid.value != -1;
}

variable_types:
uid
struct user_id_t { int value; }


decompiled_code:
__int64 iposix_supports_symlinks()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 1LL;
}

original_code:
static int
iposix_supports_symlinks (void)
{
  return 1;
}

canonical_original_code:
static int iposix_supports_symlinks()
{
  return 1;
}


decompiled_code:
// attributes: thunk
__int64 iposix_supports_posix_modes()
{
return iposix_supports_symlinks();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

original_code:
static int
iposix_supports_posix_modes (void)
{
  return 1;
}

canonical_original_code:
static int iposix_supports_posix_modes()
{
  return 1;
}


decompiled_code:
// attributes: thunk
char *iposix_user_name_current(void)
{
return getlogin();
}

canonical_decompiled_code:
char *func7(void)
{
return getlogin();
}

original_code:
const char *
iposix_user_name_current (void)
{
  return getlogin ();
}

canonical_original_code:
char *iposix_user_name_current()
{
  return getlogin ();
}

return_type: char *


decompiled_code:
// attributes: thunk
__mode_t iposix_umask(__mode_t mask)
{
return umask(mask);
}

canonical_decompiled_code:
__mode_t func8(__mode_t mask)
{
return umask(mask);
}

original_code:
static unsigned int
iposix_umask (unsigned int m)
{
  return umask (m);
}

canonical_original_code:
static unsigned int iposix_umask(unsigned int m)
{
  return umask (m);
}

variable_types:
m
unsigned int


decompiled_code:
_BOOL8 __fastcall iposix_can_set_ownership(int a1)
{
if ( a1 == -1 )
_assert_fail("uid.value != -1", "install-posix.c", 0x126u, "iposix_can_set_ownership");
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1)
{
if ( a1 == -1 )
_assert_fail("uid.value != -1", "install-posix.c", 0x126u, "iposix_can_set_ownership");
return a1 == 0;
}

original_code:
static int
iposix_can_set_ownership (user_id_t uid)
{
  ((void) sizeof ((uid.value != -1) ? 1 : 0), __extension__ ({ if (uid.value != -1) ; else __assert_fail ("uid.value != -1", "install-posix.c", 294, __extension__ __PRETTY_FUNCTION__); }));
  return uid.value == 0;
}

canonical_original_code:
static int iposix_can_set_ownership(struct user_id_t uid)
{
  ((void) sizeof ((uid.value != -1) ? 1 : 0), __extension__ ({ if (uid.value != -1) ; else __assert_fail ("uid.value != -1", "install-posix.c", 294, __extension__ __PRETTY_FUNCTION__); }));
  return uid.value == 0;
}


decompiled_code:
void __fastcall iposix_uid_free(__int64 a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0xB7u, "iposix_uid_free");
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0xB7u, "iposix_uid_free");
}

original_code:
static void
iposix_uid_free (user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 183, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void iposix_uid_free(struct user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 183, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
uid
struct user_id_t { int value; } *