decompiled_code:
int set_units()
{
double v0; // xmm2_8
double v1; // xmm0_8
double v2; // xmm2_8
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8

v0 = *((double *)&All + 6);
v1 = v0 / *((double *)&All + 5);
*((double *)&All + 3) = v1;
*((double *)&All + 7) = v1 / 3.155e13;
v2 = pow(v0, 3.0);
v3 = *((double *)&All + 3);
v4 = 6.673e-11 / v2;
v5 = v3 * v3;
*(float *)&v3 = v3 * 3.2407789e-18;
*((_DWORD *)&All + 16) = LODWORD(v3);
*((double *)&All + 2) = v4 * *((double *)&All + 4) * v5;
printf("Hubble (internal units) = %g\n", *(float *)&v3);
printf("G (internal units) = %g\n", *((double *)&All + 2));
printf("UnitMass_in_kg = %g\n", *((double *)&All + 4));
printf("UnitTime_in_s = %g\n", *((double *)&All + 3));
return printf("UnitVelocity_in_m_per_s = %g\n", *((double *)&All + 5));
}

canonical_decompiled_code:
int func0()
{
double v0; // xmm2_8
double v1; // xmm0_8
double v2; // xmm2_8
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8

v0 = *((double *)&All + 6);
v1 = v0 / *((double *)&All + 5);
*((double *)&All + 3) = v1;
*((double *)&All + 7) = v1 / 3.155e13;
v2 = pow(v0, 3.0);
v3 = *((double *)&All + 3);
v4 = 6.673e-11 / v2;
v5 = v3 * v3;
*(float *)&v3 = v3 * 3.2407789e-18;
*((_DWORD *)&All + 16) = LODWORD(v3);
*((double *)&All + 2) = v4 * *((double *)&All + 4) * v5;
printf("Hubble (internal units) = %g\n", *(float *)&v3);
printf("G (internal units) = %g\n", *((double *)&All + 2));
printf("UnitMass_in_kg = %g\n", *((double *)&All + 4));
printf("UnitTime_in_s = %g\n", *((double *)&All + 3));
return printf("UnitVelocity_in_m_per_s = %g\n", *((double *)&All + 5));
}

original_code:
void set_units(void){
 All.UnitTime_in_s = All.UnitLength_in_m / All.UnitVelocity_in_m_per_s;
 All.UnitTime_in_Megayears = All.UnitTime_in_s / 3.155e13;
 All.G = 6.673e-11 / pow(All.UnitLength_in_m, 3) * All.UnitMass_in_kg * pow(All.UnitTime_in_s, 2);
 All.Hubble = 3.2407789e-18 * All.UnitTime_in_s;
 printf("Hubble (internal units) = %g\n", All.Hubble);
 printf("G (internal units) = %g\n", All.G);
 printf("UnitMass_in_kg = %g\n", All.UnitMass_in_kg);
 printf("UnitTime_in_s = %g\n", All.UnitTime_in_s);
 printf("UnitVelocity_in_m_per_s = %g\n",All.UnitVelocity_in_m_per_s);
}

canonical_original_code:
void set_units(){
 All.UnitTime_in_s = All.UnitLength_in_m / All.UnitVelocity_in_m_per_s;
 All.UnitTime_in_Megayears = All.UnitTime_in_s / 3.155e13;
 All.G = 6.673e-11 / pow(All.UnitLength_in_m, 3) * All.UnitMass_in_kg * pow(All.UnitTime_in_s, 2);
 All.Hubble = 3.2407789e-18 * All.UnitTime_in_s;
 printf("Hubble (internal units) = %g\n", All.Hubble);
 printf("G (internal units) = %g\n", All.G);
 printf("UnitMass_in_kg = %g\n", All.UnitMass_in_kg);
 printf("UnitTime_in_s = %g\n", All.UnitTime_in_s);
 printf("UnitVelocity_in_m_per_s = %g\n",All.UnitVelocity_in_m_per_s);
}


repo: liulei/cuco

original_code:
void read_parameter_file(void){
 All.UnitLength_in_m = 3.085678e19;
 All.UnitMass_in_kg = 1.98892e40;
 All.UnitVelocity_in_m_per_s = 1e3;
 All.Omega0 = 0.3;
 All.OmegaLambda = 0.7;
 All.OmegaBaryon = 0.04;
 All.HubbleParam = 0.7;
 All.BoxSize = 10000.0;
 All.ErrTolIntAccuracy = 0.025;
 All.MaxSizeTimestep = 0.03;
 All.MinSizeTimestep = 0.0;
 All.SofteningHalo = 18.0;
 All.SofteningHaloMaxPhys = 1.8;
 All.TimeBegin = 0.0909;
 All.TimeMax = 1.0;
 strcpy(All.InitCondFile, "/home/liulei/program/N-body/ic/ic_32.cuco");
 strcpy(All.OutputDir, "output_32");
 strcpy(All.SnapshotFileBase, "cuda_32");
 strcpy(All.OutputListFilename, "output_32/list_32.txt");
 read_outputlist(All.OutputListFilename);
}

canonical_original_code:
void read_parameter_file(){
 All.UnitLength_in_m = 3.085678e19;
 All.UnitMass_in_kg = 1.98892e40;
 All.UnitVelocity_in_m_per_s = 1e3;
 All.Omega0 = 0.3;
 All.OmegaLambda = 0.7;
 All.OmegaBaryon = 0.04;
 All.HubbleParam = 0.7;
 All.BoxSize = 10000.0;
 All.ErrTolIntAccuracy = 0.025;
 All.MaxSizeTimestep = 0.03;
 All.MinSizeTimestep = 0.0;
 All.SofteningHalo = 18.0;
 All.SofteningHaloMaxPhys = 1.8;
 All.TimeBegin = 0.0909;
 All.TimeMax = 1.0;
 strcpy(All.InitCondFile, "/home/liulei/program/N-body/ic/ic_32.cuco");
 strcpy(All.OutputDir, "output_32");
 strcpy(All.SnapshotFileBase, "cuda_32");
 strcpy(All.OutputListFilename, "output_32/list_32.txt");
 read_outputlist(All.OutputListFilename);
}

return_type: void


begrun

decompiled_code:
__int64 begrun()
{
__int64 result; // rax

read_parameter_file();
set_units();
(*(void (**)(void))&init)();
cudaInit();
long_range_init();
linklist_init();
init_drift_table();
result = find_next_outputtime(All[28]);
All[29] = result;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

func2();
func0();
(*(void (**)(void))&init)();
cudaInit();
long_range_init();
linklist_init();
init_drift_table();
result = find_next_outputtime(All[28]);
All[29] = result;
return result;
}

original_code:
void begrun(void){
 read_parameter_file();
 set_units();
 init();
 cudaInit();
 long_range_init();
 linklist_init();
 init_drift_table();
 All.Ti_nextoutput = find_next_outputtime(All.Ti_Current);
}

canonical_original_code:
void begrun(){
 read_parameter_file();
 set_units();
 init();
 cudaInit();
 long_range_init();
 linklist_init();
 init_drift_table();
 All.Ti_nextoutput = find_next_outputtime(All.Ti_Current);
}


decompiled_code:
__int64 __fastcall check_omega()
{
__int64 result; // rax
double v1; // xmm0_8
double v2; // xmm0_8
double v3; // xmm1_8

if ( NumPart )
{
v1 = 0.0;
result = P + 12LL;
do
{
result += 60LL;
v1 = v1 + *(float *)(result - 60);
}
while ( P + 60LL * (unsigned int)(NumPart - 1) + 72 != result );
}
else
{
v1 = 0.0;
}
v2 = v1
/ (float)((float)(*((float *)&All + 1) * *((float *)&All + 1)) * *((float *)&All + 1))
/ ((float)((float)(3.0 * *((float *)&All + 16)) * *((float *)&All + 16))
/ (25.13274122871834
* *((double *)&All + 2)));
v3 = *((float *)&All + 17);
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v2 - v3) & LC3) > 0.001 )
{
printf("The mass in ic file accounts for Omega = %g, but you specified Omega = %g in parameter file!\n", v2, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0()
{
__int64 result; // rax
double v1; // xmm0_8
double v2; // xmm0_8
double v3; // xmm1_8

if ( NumPart )
{
v1 = 0.0;
result = P + 12LL;
do
{
result += 60LL;
v1 = v1 + *(float *)(result - 60);
}
while ( P + 60LL * (unsigned int)(NumPart - 1) + 72 != result );
}
else
{
v1 = 0.0;
}
v2 = v1
/ (float)((float)(*((float *)&All + 1) * *((float *)&All + 1)) * *((float *)&All + 1))
/ ((float)((float)(3.0 * *((float *)&All + 16)) * *((float *)&All + 16))
/ (25.13274122871834
* *((double *)&All + 2)));
v3 = *((float *)&All + 17);
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v2 - v3) & LC3) > 0.001 )
{
printf("The mass in ic file accounts for Omega = %g, but you specified Omega = %g in parameter file!\n", v2, v3);
exit(1);
}
return result;
}

original_code:
void check_omega(void){
 double mass, omega;
 int i;
 mass = 0.0;
 for(i = 0; i < NumPart; ++i){
  mass += P[i].Mass;
 }
 omega = mass / (All.BoxSize * All.BoxSize * All.BoxSize) / (3 * All.Hubble * All.Hubble / (8 * 3.14159265358979323846 * All.G));
 if(fabs(omega - All.Omega0) > 0.001){
  printf("The mass in ic file accounts for Omega = %g, but you specified Omega = %g in parameter file!\n", omega, All.Omega0);
  exit(1);
 }
}

canonical_original_code:
void check_omega(){
 double mass; double omega;
 int i;
 mass = 0.0;
 for(i = 0; i < NumPart; ++i){
  mass += P[i].Mass;
 }
 omega = mass / (All.BoxSize * All.BoxSize * All.BoxSize) / (3 * All.Hubble * All.Hubble / (8 * 3.14159265358979323846 * All.G));
 if(fabs(omega - All.Omega0) > 0.001){
  printf("The mass in ic file accounts for Omega = %g, but you specified Omega = %g in parameter file!\n", omega, All.Omega0);
  exit(1);
 }
}

variable_types: mass double

variable_types: omega double

variable_types: i int


init

original_code:
void init(void){
 double a3;
 int i,j;
 read_ic(All.InitCondFile);
 All.Time = All.TimeBegin;
 All.Ti_Current = 0;
 All.Timebase_interval = (log(All.TimeMax)-log(All.TimeBegin)) / (1<<28);
 a3 = All.Time * All.Time * All.Time;
 set_softenings();
 All.NumCurrentTiStep = 0;
 All.SnapshotFileCount = 0;
 check_omega();
 for(i = 0; i < NumPart; ++i){
  for(j = 0; j < 3; ++j){
   P[i].Vel[j] *= sqrt(All.Time)*All.Time;
   P[i].GravAccel[j] = 0;
   P[i].GravPM[j] = 0;
  }
  P[i].Ti_endstep = 0;
  P[i].Ti_begstep = 0;
 }
 All.PM_Ti_endstep = All.PM_Ti_begstep = 0;
}

canonical_original_code:
void init(){
 double a3;
 int i; int j;
 read_ic(All.InitCondFile);
 All.Time = All.TimeBegin;
 All.Ti_Current = 0;
 All.Timebase_interval = (log(All.TimeMax)-log(All.TimeBegin)) / (1<<28);
 a3 = All.Time * All.Time * All.Time;
 set_softenings();
 All.NumCurrentTiStep = 0;
 All.SnapshotFileCount = 0;
 check_omega();
 for(i = 0; i < NumPart; ++i){
  for(j = 0; j < 3; ++j){
   P[i].Vel[j] *= sqrt(All.Time)*All.Time;
   P[i].GravAccel[j] = 0;
   P[i].GravPM[j] = 0;
  }
  P[i].Ti_endstep = 0;
  P[i].Ti_begstep = 0;
 }
 All.PM_Ti_endstep = All.PM_Ti_begstep = 0;
}

variable_types: j int


decompiled_code:
__int64 __fastcall get_timestep(unsigned int a1)
{
float *v1; // rax
double v2; // xmm3_8
double v3; // xmm4_8
double v4; // xmm2_8
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm0_8
__m128d v8; // xmm0
__m128d v9; // xmm5
__int64 v10; // xmm0_8
unsigned int v11; // er12
double v13; // [rsp+8h] [rbp-38h]
double v14; // [rsp+8h] [rbp-38h]
double v15; // [rsp+10h] [rbp-30h]
double v16; // [rsp+10h] [rbp-30h]
double v17; // [rsp+18h] [rbp-28h]

v1 = (float *)(P + 60LL * (int)a1);
v2 = v1[10] * *(double *)&fac1 + v1[7] * *(double *)&fac1;
v3 = v1[11] * *(double *)&fac1 + v1[8] * *(double *)&fac1;
v4 = v1[12] * *(double *)&fac1 + v1[9] * *(double *)&fac1;
v5 = v2 * v2 + v3 * v3 + v4 * v4;
if ( v5 < 0.0 )
{
v16 = v1[12] * *(double *)&fac1 + v1[9] * *(double *)&fac1;
v13 = v1[11] * *(double *)&fac1 + v1[8] * *(double *)&fac1;
sqrt(v5);
v4 = v16;
v3 = v13;
}
else
{
v5 = sqrt(v5);
}
if ( v5 == 0.0 )
v5 = *(double *)&LC0;
v6 = (float)(*((float *)&All + 34) + *((float *)&All + 34)) * *(double *)&atime * *((float *)&All + 39) / v5;
if ( v6 < 0.0 )
{
v15 = v3;
v7 = sqrt(v6);
v3 = v15;
}
else
{
v7 = sqrt(v6);
}
v8.m128d_f64[0] = v7 * *(double *)&hubble_a;
*(_QWORD *)&v9.m128d_f64[0] = dt_displacement;
v9.m128d_f64[0] = _mm_cmpgt_sd(v9, v8).m128d_f64[0];
v10 = *(_QWORD *)&v8.m128d_f64[0] & *(_QWORD *)&v9.m128d_f64[0] | ~*(_QWORD *)&v9.m128d_f64[0] & dt_displacement;
if ( *((float *)&All + 36) > *(double *)&v10 )
{
v17 = v3;
puts("warning: Timestep will be below the limit of MinSizeTimestep!");
printf("Part ID: %d\tdt: %g\tac: %g\n", a1, *(double *)&v10, v5);
v3 = v17;
*(double *)&v10 = *((float *)&All + 36);
}
v11 = (int)(*(double *)&v10 / *((double *)&All + 13));
if ( v11 - 1 > 0xFFFFFFE )
{
v14 = v3;
puts("Error: a timestep of size zero was assigned on the integer timeline!");
printf("ti_step: %d\n", v11);
printf("timebase interval: %g\n", *((double *)&All + 13));
printf("ax|ay|az: %g|%g|%g\n", v2, v14, v4);
exit(1);
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
float *v1; // rax
double v2; // xmm3_8
double v3; // xmm4_8
double v4; // xmm2_8
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm0_8
__m128d v8; // xmm0
__m128d v9; // xmm5
__int64 v10; // xmm0_8
unsigned int v11; // er12
double v13; // [rsp+8h] [rbp-38h]
double v14; // [rsp+8h] [rbp-38h]
double v15; // [rsp+10h] [rbp-30h]
double v16; // [rsp+10h] [rbp-30h]
double v17; // [rsp+18h] [rbp-28h]

v1 = (float *)(P + 60LL * (int)a1);
v2 = v1[10] * *(double *)&fac1 + v1[7] * *(double *)&fac1;
v3 = v1[11] * *(double *)&fac1 + v1[8] * *(double *)&fac1;
v4 = v1[12] * *(double *)&fac1 + v1[9] * *(double *)&fac1;
v5 = v2 * v2 + v3 * v3 + v4 * v4;
if ( v5 < 0.0 )
{
v16 = v1[12] * *(double *)&fac1 + v1[9] * *(double *)&fac1;
v13 = v1[11] * *(double *)&fac1 + v1[8] * *(double *)&fac1;
sqrt(v5);
v4 = v16;
v3 = v13;
}
else
{
v5 = sqrt(v5);
}
if ( v5 == 0.0 )
v5 = *(double *)&LC0;
v6 = (float)(*((float *)&All + 34) + *((float *)&All + 34)) * *(double *)&atime * *((float *)&All + 39) / v5;
if ( v6 < 0.0 )
{
v15 = v3;
v7 = sqrt(v6);
v3 = v15;
}
else
{
v7 = sqrt(v6);
}
v8.m128d_f64[0] = v7 * *(double *)&hubble_a;
*(_QWORD *)&v9.m128d_f64[0] = dt_displacement;
v9.m128d_f64[0] = _mm_cmpgt_sd(v9, v8).m128d_f64[0];
v10 = *(_QWORD *)&v8.m128d_f64[0] & *(_QWORD *)&v9.m128d_f64[0] | ~*(_QWORD *)&v9.m128d_f64[0] & dt_displacement;
if ( *((float *)&All + 36) > *(double *)&v10 )
{
v17 = v3;
puts("warning: Timestep will be below the limit of MinSizeTimestep!");
printf("Part ID: %d\tdt: %g\tac: %g\n", a1, *(double *)&v10, v5);
v3 = v17;
*(double *)&v10 = *((float *)&All + 36);
}
v11 = (int)(*(double *)&v10 / *((double *)&All + 13));
if ( v11 - 1 > 0xFFFFFFE )
{
v14 = v3;
puts("Error: a timestep of size zero was assigned on the integer timeline!");
printf("ti_step: %d\n", v11);
printf("timebase interval: %g\n", *((double *)&All + 13));
printf("ax|ay|az: %g|%g|%g\n", v2, v14, v4);
exit(1);
}
return v11;
}

original_code:
int get_timestep(int p){
 double ax, ay, az, ac;
 double dt;
 int ti_step;
 ax = fac1 * P[p].GravAccel[0];
 ay = fac1 * P[p].GravAccel[1];
 az = fac1 * P[p].GravAccel[2];
 ax += fac1 * P[p].GravPM[0];
 ay += fac1 * P[p].GravPM[1];
 az += fac1 * P[p].GravPM[2];
 ac = sqrt(ax * ax + ay * ay + az * az);
 if(ac == 0)
  ac = 1.0e-30;
 dt = sqrt(2 * All.ErrTolIntAccuracy * atime * All.SofteningTable / ac);
 dt *= hubble_a;
 if(dt >= dt_displacement)
  dt = dt_displacement;
 if(dt < All.MinSizeTimestep){
  printf("warning: Timestep will be below the limit of MinSizeTimestep!\n");
  printf("Part ID: %d	dt: %g	ac: %g\n", p, dt, ac);
  dt = All.MinSizeTimestep;
 }
 ti_step = dt / All.Timebase_interval;
 if(!(ti_step > 0 && ti_step < (1<<28))){
  printf("Error: a timestep of size zero was assigned on the integer timeline!\n");
  printf("ti_step: %d\n", ti_step);
  printf("timebase interval: %g\n", All.Timebase_interval);
  printf("ax|ay|az: %g|%g|%g\n", ax, ay, az);
  exit(1);
 }
 return ti_step;
}

canonical_original_code:
int get_timestep(int p){
 double ax; double ay; double az; double ac;
 double dt;
 int ti_step;
 ax = fac1 * P[p].GravAccel[0];
 ay = fac1 * P[p].GravAccel[1];
 az = fac1 * P[p].GravAccel[2];
 ax += fac1 * P[p].GravPM[0];
 ay += fac1 * P[p].GravPM[1];
 az += fac1 * P[p].GravPM[2];
 ac = sqrt(ax * ax + ay * ay + az * az);
 if(ac == 0)
  ac = 1.0e-30;
 dt = sqrt(2 * All.ErrTolIntAccuracy * atime * All.SofteningTable / ac);
 dt *= hubble_a;
 if(dt >= dt_displacement)
  dt = dt_displacement;
 if(dt < All.MinSizeTimestep){
  printf("warning: Timestep will be below the limit of MinSizeTimestep!\n");
  printf("Part ID: %d	dt: %g	ac: %g\n", p, dt, ac);
  dt = All.MinSizeTimestep;
 }
 ti_step = dt / All.Timebase_interval;
 if(!(ti_step > 0 && ti_step < (1<<28))){
  printf("Error: a timestep of size zero was assigned on the integer timeline!\n");
  printf("ti_step: %d\n", ti_step);
  printf("timebase interval: %g\n", All.Timebase_interval);
  printf("ax|ay|az: %g|%g|%g\n", ax, ay, az);
  exit(1);
 }
 return ti_step;
}

variable_types: p int

variable_types: ax double

variable_types: ay double

variable_types: az double

variable_types: ac double

variable_types: dt double

return_type: int


original_code:
void advance_and_find_timesteps(void){
 int i, j, ti_step, ti_min, tend, tstart;
 double dt_gravkick;
 float dv[3];
 fac1 = 1 / (All.Time * All.Time);
 atime = All.Time;
 hubble_a= All.Omega0 / (atime * atime * atime)
    + (1 - All.Omega0 - All.OmegaLambda)
    / (atime * atime) + All.OmegaLambda;
 hubble_a = All.Hubble * sqrt(hubble_a);
 dt_displacement = All.MaxSizeTimestep;
 for(i = 0; i < NumPart; ++i){
  if(P[i].Ti_endstep == All.Ti_Current){
   ti_step = get_timestep(i);
   ti_min = (1<<28);
   while(ti_min > ti_step)
    ti_min >>= 1;
   ti_step = ti_min;
   if(ti_step > (P[i].Ti_endstep - P[i].Ti_begstep)){
    if((((1<<28) - P[i].Ti_endstep) % ti_step) > 0)
     ti_step = P[i].Ti_endstep - P[i].Ti_begstep;
   }
   if(All.Ti_Current == (1<<28))
    ti_step = 0;
   if(((1<<28) - All.Ti_Current) < ti_step)
    ti_step = (1<<28) - All.Ti_Current;
   tstart = (P[i].Ti_begstep + P[i].Ti_endstep) / 2;
   tend = P[i].Ti_endstep + ti_step / 2;
   dt_gravkick = get_gravkick_factor(tstart, tend);
   P[i].Ti_begstep = P[i].Ti_endstep;
   P[i].Ti_endstep = P[i].Ti_begstep + ti_step;
   for(j = 0; j < 3; ++j){
    dv[j] = P[i].GravAccel[j] * dt_gravkick;
    P[i].Vel[j] += dv[j];
   }
  }
 }
 if(All.PM_Ti_endstep == All.Ti_Current){
  ti_step = (1<<28);
  while(ti_step > (dt_displacement / All.Timebase_interval))
   ti_step >>= 1;
  if(ti_step > (All.PM_Ti_endstep - All.PM_Ti_begstep)){
   if((((1<<28) - All.PM_Ti_endstep) % ti_step) > 0)
    ti_step = All.PM_Ti_endstep - All.PM_Ti_begstep;
  }
  if(All.Ti_Current == (1<<28))
   ti_step = 0;
  tstart = (All.PM_Ti_begstep + All.PM_Ti_endstep) / 2;
  tend = All.PM_Ti_endstep + ti_step / 2;
  dt_gravkick = get_gravkick_factor(tstart, tend);
  All.PM_Ti_begstep = All.PM_Ti_endstep;
  All.PM_Ti_endstep = All.PM_Ti_begstep + ti_step;
  for(i = 0; i < NumPart; ++i){
   for(j = 0; j < 3; ++j){
    P[i].Vel[j] += P[i].GravPM[j] * dt_gravkick;
   }
  }
 }
}

canonical_original_code:
void advance_and_find_timesteps(){
 int i; int j; int ti_step; int ti_min; int tend; int tstart;
 double dt_gravkick;
 float dv[3];
 fac1 = 1 / (All.Time * All.Time);
 atime = All.Time;
 hubble_a= All.Omega0 / (atime * atime * atime)
    + (1 - All.Omega0 - All.OmegaLambda)
    / (atime * atime) + All.OmegaLambda;
 hubble_a = All.Hubble * sqrt(hubble_a);
 dt_displacement = All.MaxSizeTimestep;
 for(i = 0; i < NumPart; ++i){
  if(P[i].Ti_endstep == All.Ti_Current){
   ti_step = get_timestep(i);
   ti_min = (1<<28);
   while(ti_min > ti_step)
    ti_min >>= 1;
   ti_step = ti_min;
   if(ti_step > (P[i].Ti_endstep - P[i].Ti_begstep)){
    if((((1<<28) - P[i].Ti_endstep) % ti_step) > 0)
     ti_step = P[i].Ti_endstep - P[i].Ti_begstep;
   }
   if(All.Ti_Current == (1<<28))
    ti_step = 0;
   if(((1<<28) - All.Ti_Current) < ti_step)
    ti_step = (1<<28) - All.Ti_Current;
   tstart = (P[i].Ti_begstep + P[i].Ti_endstep) / 2;
   tend = P[i].Ti_endstep + ti_step / 2;
   dt_gravkick = get_gravkick_factor(tstart, tend);
   P[i].Ti_begstep = P[i].Ti_endstep;
   P[i].Ti_endstep = P[i].Ti_begstep + ti_step;
   for(j = 0; j < 3; ++j){
    dv[j] = P[i].GravAccel[j] * dt_gravkick;
    P[i].Vel[j] += dv[j];
   }
  }
 }
 if(All.PM_Ti_endstep == All.Ti_Current){
  ti_step = (1<<28);
  while(ti_step > (dt_displacement / All.Timebase_interval))
   ti_step >>= 1;
  if(ti_step > (All.PM_Ti_endstep - All.PM_Ti_begstep)){
   if((((1<<28) - All.PM_Ti_endstep) % ti_step) > 0)
    ti_step = All.PM_Ti_endstep - All.PM_Ti_begstep;
  }
  if(All.Ti_Current == (1<<28))
   ti_step = 0;
  tstart = (All.PM_Ti_begstep + All.PM_Ti_endstep) / 2;
  tend = All.PM_Ti_endstep + ti_step / 2;
  dt_gravkick = get_gravkick_factor(tstart, tend);
  All.PM_Ti_begstep = All.PM_Ti_endstep;
  All.PM_Ti_endstep = All.PM_Ti_begstep + ti_step;
  for(i = 0; i < NumPart; ++i){
   for(j = 0; j < 3; ++j){
    P[i].Vel[j] += P[i].GravPM[j] * dt_gravkick;
   }
  }
 }
}

variable_types: tend int

variable_types: tstart int

variable_types:
dv
float [3]


decompiled_code:
// attributes: thunk
__int64 long_range_init()
{
return pm_init_periodic();
}

canonical_decompiled_code:
__int64 func0()
{
return pm_init_periodic();
}

original_code:
void long_range_init(void){
 pm_init_periodic();
}

canonical_original_code:
void long_range_init(){
 pm_init_periodic();
}


decompiled_code:
__int64 long_range_force()
{
__int64 v0; // rax
__int64 v1; // rdx

if ( NumPart )
{
v0 = P + 40LL;
v1 = P + 60LL * (unsigned int)(NumPart - 1) + 100;
do
{
*(_DWORD *)(v0 + 8) = 0;
v0 += 60LL;
*(_DWORD *)(v0 - 56) = 0;
*(_DWORD *)(v0 - 60) = 0;
}
while ( v0 != v1 );
}
return pmforce_periodic();
}

original_code:
void long_range_force(void){
 int i;
 for(i = 0; i < NumPart; ++i){
  P[i].GravPM[0] = P[i].GravPM[1] = P[i].GravPM[2] = 0;
 }
 pmforce_periodic();
}

canonical_original_code:
void long_range_force(){
 int i;
 for(i = 0; i < NumPart; ++i){
  P[i].GravPM[0] = P[i].GravPM[1] = P[i].GravPM[2] = 0;
 }
 pmforce_periodic();
}


decompiled_code:
__int64 __fastcall move_particles(double a1)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx
float v5; // xmm0_4

get_drift_factor();
result = NumPart;
if ( NumPart )
{
v3 = P + 12LL;
v4 = P + 60LL * (unsigned int)(NumPart - 1) + 72;
do
{
result = v3 - 12;
do
{
result += 4LL;
v5 = *(float *)(result + 12) * a1 + *(float *)(result - 4);
*(float *)(result - 4) = v5;
}
while ( v3 != result );
v3 += 60LL;
}
while ( v4 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx
float v5; // xmm0_4

get_drift_factor();
result = NumPart;
if ( NumPart )
{
v3 = P + 12LL;
v4 = P + 60LL * (unsigned int)(NumPart - 1) + 72;
do
{
result = v3 - 12;
do
{
result += 4LL;
v5 = *(float *)(result + 12) * a1 + *(float *)(result - 4);
*(float *)(result - 4) = v5;
}
while ( v3 != result );
v3 += 60LL;
}
while ( v4 != v3 );
}
return result;
}

original_code:
void move_particles(int time0, int time1){
 int i, j;
 double dt_drift;
 dt_drift = get_drift_factor(time0, time1);
 for(i = 0; i < NumPart; ++i){
  for(j = 0; j < 3; ++j){
   P[i].Pos[j] += P[i].Vel[j] * dt_drift;
  }
 }
}

canonical_original_code:
void move_particles(int time0, int time1){
 int i; int j;
 double dt_drift;
 dt_drift = get_drift_factor(time0, time1);
 for(i = 0; i < NumPart; ++i){
  for(j = 0; j < 3; ++j){
   P[i].Pos[j] += P[i].Vel[j] * dt_drift;
  }
 }
}


decompiled_code:
float *do_box_wrapping()
{
float *result; // rax
float v1; // xmm1_4
__int64 v2; // rdx
__int64 v3; // rcx
float v4; // xmm0_4

result = (float *)NumPart;
v1 = All[1];
if ( NumPart )
{
v2 = P + 12LL;
v3 = P + 60LL * (unsigned int)(NumPart - 1) + 72;
do
{
result = (float *)(v2 - 12);
do
{
v4 = *result;
if ( *result < 0.0 )
{
do
v4 = v4 + v1;
while ( v4 < 0.0 );
*result = v4;
}
if ( v4 >= v1 )
{
do
v4 = v4 - v1;
while ( v4 >= v1 );
*result = v4;
}
++result;
}
while ( (float *)v2 != result );
v2 += 60LL;
}
while ( v2 != v3 );
}
return result;
}

canonical_decompiled_code:
float *func1()
{
float *result; // rax
float v1; // xmm1_4
__int64 v2; // rdx
__int64 v3; // rcx
float v4; // xmm0_4

result = (float *)NumPart;
v1 = All[1];
if ( NumPart )
{
v2 = P + 12LL;
v3 = P + 60LL * (unsigned int)(NumPart - 1) + 72;
do
{
result = (float *)(v2 - 12);
do
{
v4 = *result;
if ( *result < 0.0 )
{
do
v4 = v4 + v1;
while ( v4 < 0.0 );
*result = v4;
}
if ( v4 >= v1 )
{
do
v4 = v4 - v1;
while ( v4 >= v1 );
*result = v4;
}
++result;
}
while ( (float *)v2 != result );
v2 += 60LL;
}
while ( v2 != v3 );
}
return result;
}

original_code:
void do_box_wrapping(void){
 int i, j;
 double boxsize;
 boxsize = All.BoxSize;
 for(i = 0; i < NumPart; ++i){
  for(j = 0; j < 3; ++j){
   while(P[i].Pos[j] < 0)
    P[i].Pos[j] += boxsize;
   while(P[i].Pos[j] >= boxsize)
    P[i].Pos[j] -= boxsize;
  }
 }
}

canonical_original_code:
void do_box_wrapping(){
 int i; int j;
 double boxsize;
 boxsize = All.BoxSize;
 for(i = 0; i < NumPart; ++i){
  for(j = 0; j < 3; ++j){
   while(P[i].Pos[j] < 0)
    P[i].Pos[j] += boxsize;
   while(P[i].Pos[j] >= boxsize)
    P[i].Pos[j] -= boxsize;
  }
 }
}

variable_types: boxsize double


decompiled_code:
__int64 compute_accelerations()
{
do_box_wrapping();
if ( All[30] == All[28] )
long_range_force();
return gravity_linklist_cuda();
}

canonical_decompiled_code:
__int64 func0()
{
do_box_wrapping();
if ( All[30] == All[28] )
long_range_force();
return gravity_linklist_cuda();
}

original_code:
void compute_accelerations(void){
 do_box_wrapping();
 if(All.PM_Ti_endstep == All.Ti_Current){
  long_range_force();
 }
 gravity_linklist_cuda();
}

canonical_original_code:
void compute_accelerations(){
 do_box_wrapping();
 if(All.PM_Ti_endstep == All.Ti_Current){
  long_range_force();
 }
 gravity_linklist_cuda();
}


main

canonical_name: main

repo: liushizhe/ini-parse

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
int result; // eax

v3 = (char *)malloc(6uLL);
v4 = ini_get_int("sect1", "key1", 0LL, "test.ini");
printf("sect1,key1 = %d\n", v4);
v5 = ini_get_int("sect1", "key2", 0LL, "test.ini");
printf("sect1,key2 = %d\n", v5);
v6 = ini_get_int("sect1", "key3", 0LL, "test.ini");
printf("sect1,key3 = %d\n", v6);
v7 = ini_get_int("sect1", "key4", 0LL, "test.ini");
printf("sect1,key4 = %d\n", v7);
v8 = ini_get_int("sect1", "key5", 0LL, "test.ini");
printf("sect1,key5 = %d\n", v8);
v9 = ini_get_int("sect1", "key6", 0LL, "test.ini");
printf("sect1,key6 = %d\n", v9);
v10 = ini_get_int("sect1", "key7", 0LL, "test.ini");
printf("sect1,key7 = %d\n", v10);
v11 = ini_get_int("sect2", "key1", 0LL, "test.ini");
printf("sect2,key1 = %d\n", v11);
v12 = ini_get_int("sect2", "key2", 0LL, "test.ini");
printf("sect2,key2 = %d\n", v12);
v13 = ini_get_int("sect2", "key3", 0LL, "test.ini");
printf("sect2,key3 = %d\n", v13);
v14 = ini_get_int("sect3", "key1", 0LL, "test.ini");
printf("sect3,key1 = %d\n", v14);
v15 = ini_get_int("sect3", "key2", 0LL, "test.ini");
printf("sect3,key2 = %d\n", v15);
v16 = ini_get_int("sect3", "key3", 0LL, "test.ini");
printf("sect3,key3 = %d\n", v16);
putchar(10);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
ini_get_string("sect4", "key1", 4202521LL, v3, 6LL, "test.ini");
printf("sect4,key1 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
ini_get_string("sect4", "key2", 4202676LL, v3, 6LL, "test.ini");
printf("sect4,key2 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
ini_get_string("sect4", "key3", 4202733LL, v3, 6LL, "test.ini");
printf("sect4,key3 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
ini_get_string("sect4", "key4", 4202790LL, v3, 6LL, "test.ini");
printf("sect4,key4 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
ini_get_string("sect4", "key5", 4202609LL, v3, 6LL, "test.ini");
printf("sect4,key5 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
ini_get_string("sect4", "key6", 4202631LL, v3, 6LL, "test.ini");
printf("sect4,key6 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
ini_get_string("sect4", "key7", 4202653LL, v3, 6LL, "test.ini");
printf("sect4,key7 = %s\n", v3);
free(v3);
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
int result; // eax

v3 = (char *)malloc(6uLL);
v4 = func9("sect1", "key1", 0LL, "test.ini");
printf("sect1,key1 = %d\n", v4);
v5 = func9("sect1", "key2", 0LL, "test.ini");
printf("sect1,key2 = %d\n", v5);
v6 = func9("sect1", "key3", 0LL, "test.ini");
printf("sect1,key3 = %d\n", v6);
v7 = func9("sect1", "key4", 0LL, "test.ini");
printf("sect1,key4 = %d\n", v7);
v8 = func9("sect1", "key5", 0LL, "test.ini");
printf("sect1,key5 = %d\n", v8);
v9 = func9("sect1", "key6", 0LL, "test.ini");
printf("sect1,key6 = %d\n", v9);
v10 = func9("sect1", "key7", 0LL, "test.ini");
printf("sect1,key7 = %d\n", v10);
v11 = func9("sect2", "key1", 0LL, "test.ini");
printf("sect2,key1 = %d\n", v11);
v12 = func9("sect2", "key2", 0LL, "test.ini");
printf("sect2,key2 = %d\n", v12);
v13 = func9("sect2", "key3", 0LL, "test.ini");
printf("sect2,key3 = %d\n", v13);
v14 = func9("sect3", "key1", 0LL, "test.ini");
printf("sect3,key1 = %d\n", v14);
v15 = func9("sect3", "key2", 0LL, "test.ini");
printf("sect3,key2 = %d\n", v15);
v16 = func9("sect3", "key3", 0LL, "test.ini");
printf("sect3,key3 = %d\n", v16);
putchar(10);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
func10("sect4", "key1", 4202521LL, v3, 6LL, "test.ini");
printf("sect4,key1 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
func10("sect4", "key2", 4202676LL, v3, 6LL, "test.ini");
printf("sect4,key2 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
func10("sect4", "key3", 4202733LL, v3, 6LL, "test.ini");
printf("sect4,key3 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
func10("sect4", "key4", 4202790LL, v3, 6LL, "test.ini");
printf("sect4,key4 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
func10("sect4", "key5", 4202609LL, v3, 6LL, "test.ini");
printf("sect4,key5 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
func10("sect4", "key6", 4202631LL, v3, 6LL, "test.ini");
printf("sect4,key6 = %s\n", v3);
*((_WORD *)v3 + 2) = 0;
*(_DWORD *)v3 = 0;
func10("sect4", "key7", 4202653LL, v3, 6LL, "test.ini");
printf("sect4,key7 = %s\n", v3);
free(v3);
return result;
}

original_code:
void main()
{
 char *buf = (char*)malloc(6);
 printf("sect1,key1 = %d\n", ini_get_int("sect1", "key1", 0, "test.ini"));
 printf("sect1,key2 = %d\n", ini_get_int("sect1", "key2", 0, "test.ini"));
 printf("sect1,key3 = %d\n", ini_get_int("sect1", "key3", 0, "test.ini"));
 printf("sect1,key4 = %d\n", ini_get_int("sect1", "key4", 0, "test.ini"));
 printf("sect1,key5 = %d\n", ini_get_int("sect1", "key5", 0, "test.ini"));
 printf("sect1,key6 = %d\n", ini_get_int("sect1", "key6", 0, "test.ini"));
 printf("sect1,key7 = %d\n", ini_get_int("sect1", "key7", 0, "test.ini"));
 printf("sect2,key1 = %d\n", ini_get_int("sect2", "key1", 0, "test.ini"));
 printf("sect2,key2 = %d\n", ini_get_int("sect2", "key2", 0, "test.ini"));
 printf("sect2,key3 = %d\n", ini_get_int("sect2", "key3", 0, "test.ini"));
 printf("sect3,key1 = %d\n", ini_get_int("sect3", "key1", 0, "test.ini"));
 printf("sect3,key2 = %d\n", ini_get_int("sect3", "key2", 0, "test.ini"));
 printf("sect3,key3 = %d\n", ini_get_int("sect3", "key3", 0, "test.ini"));
 printf("\n");
 memset(buf, 0, 6);
 ini_get_string("sect4", "key1", "1", buf, 6, "test.ini");
 printf("sect4,key1 = %s\n", buf);
 memset(buf, 0, 6);
 ini_get_string("sect4", "key2", "2", buf, 6, "test.ini");
 printf("sect4,key2 = %s\n", buf);
 memset(buf, 0, 6);
 ini_get_string("sect4", "key3", "3", buf, 6, "test.ini");
 printf("sect4,key3 = %s\n", buf);
 memset(buf, 0, 6);
 ini_get_string("sect4", "key4", "4", buf, 6, "test.ini");
 printf("sect4,key4 = %s\n", buf);
 memset(buf, 0, 6);
 ini_get_string("sect4", "key5", "5", buf, 6, "test.ini");
 printf("sect4,key5 = %s\n", buf);
 memset(buf, 0, 6);
 ini_get_string("sect4", "key6", "6", buf, 6, "test.ini");
 printf("sect4,key6 = %s\n", buf);
 memset(buf, 0, 6);
 ini_get_string("sect4", "key7", "7", buf, 6, "test.ini");
 printf("sect4,key7 = %s\n", buf);
 free(buf);
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall ini_get_int(const char *a1, const char *a2, unsigned int a3, const char *a4)
{
char *v6; // rbp

v6 = (char *)calloc(0x20uLL, 1uLL);
if ( !(unsigned int)find_string(v6, a1, a2, a4) )
a3 = atoi(v6);
free(v6);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, const char *a2, unsigned int a3, const char *a4)
{
char *v6; // rbp

v6 = (char *)calloc(0x20uLL, 1uLL);
if ( !(unsigned int)func8(v6, a1, a2, a4) )
a3 = atoi(v6);
free(v6);
return a3;
}

original_code:
int ini_get_int(const char* sect, const char *key, int defa, const char *file)
{
 int ret;
 char *buf = malloc(32);
 memset(buf, 0, 32);
 if(find_string(buf, sect, key, file))
 {
  ret = defa;
 }
 else
 {
  ret = atoi(buf);
 }
 free(buf);
 return ret;
}

canonical_original_code:
int ini_get_int(char *sect, char *key, int defa, char *file)
{
 int ret;
 char *buf = malloc(32);
 memset(buf, 0, 32);
 if(find_string(buf, sect, key, file))
 {
  ret = defa;
 }
 else
 {
  ret = atoi(buf);
 }
 free(buf);
 return ret;
}

variable_types:
sect
char *

variable_types:
key
char *

variable_types: defa int

variable_types:
file
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall ini_get_string(const char *a1, const char *a2, const char *a3, char *a4, int a5, const char *a6)
{
char *v9; // rbp
const char *v10; // rsi
char *v11; // rdi
int v12; // er12

v9 = (char *)calloc(0x20uLL, 1uLL);
if ( (unsigned int)find_string(v9, a1, a2, a6) )
{
v10 = a3;
v11 = a4;
v12 = strlen(a3);
if ( a5 < v12 )
v12 = a5;
}
else
{
v12 = 32;
v10 = v9;
v11 = a4;
if ( a5 <= 32 )
v12 = a5;
}
strncpy(v11, v10, v12);
a4[v12] = 0;
free(v9);
return (unsigned int)v12;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, const char *a2, const char *a3, char *a4, int a5, const char *a6)
{
char *v9; // rbp
const char *v10; // rsi
char *v11; // rdi
int v12; // er12

v9 = (char *)calloc(0x20uLL, 1uLL);
if ( (unsigned int)func8(v9, a1, a2, a6) )
{
v10 = a3;
v11 = a4;
v12 = strlen(a3);
if ( a5 < v12 )
v12 = a5;
}
else
{
v12 = 32;
v10 = v9;
v11 = a4;
if ( a5 <= 32 )
v12 = a5;
}
strncpy(v11, v10, v12);
a4[v12] = 0;
free(v9);
return (unsigned int)v12;
}

original_code:
int ini_get_string(const char* sect, const char *key, char *strdefa, char * buf, int size, const char *file)
{
 char * tempbuf = malloc(32);
 int lendefa,retlen;
 memset(tempbuf, 0, 32);
 if(find_string(tempbuf, sect, key, file))
 {
  lendefa = strlen(strdefa);
  retlen = lendefa < size ? lendefa:size;
  strncpy(buf,strdefa,retlen);
 }
 else
 {
  retlen = 32 < size ? 32:size;
  strncpy(buf,tempbuf,retlen);
 }
 *(buf+retlen) = '\0';
 free(tempbuf);
 return retlen;
}

canonical_original_code:
int ini_get_string(char *sect, char *key, char *strdefa, char *buf, int size, char *file)
{
 char *tempbuf = malloc(32);
 int lendefa; int retlen;
 memset(tempbuf, 0, 32);
 if(find_string(tempbuf, sect, key, file))
 {
  lendefa = strlen(strdefa);
  retlen = lendefa < size ? lendefa:size;
  strncpy(buf,strdefa,retlen);
 }
 else
 {
  retlen = 32 < size ? 32:size;
  strncpy(buf,tempbuf,retlen);
 }
 *(buf+retlen) = '\0';
 free(tempbuf);
 return retlen;
}

variable_types:
strdefa
char *

variable_types: size int

variable_types:
tempbuf
char *

variable_types: lendefa int

variable_types: retlen int


login

repo: liuweicong/train

decompiled_code:
__int64 login()
{
__int64 result; // rax
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0;
system("clear");
puts("-------------------------------------------");
putchar(10);
puts(asc_240);
putchar(10);
puts(asc_14E);
puts(a1);
puts(a2);
puts(a3);
puts(a4);
putchar(10);
puts(asc_278);
puts(asc_2B0);
putchar(10);
while ( 1 )
{
_isoc99_scanf(&unk_1A1, v1);
my_getchar();
result = v1[0];
if ( v1[0] - 1 <= 3 )
break;
puts(&byte_1A4);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0;
system("clear");
puts("-------------------------------------------");
putchar(10);
puts(asc_240);
putchar(10);
puts(asc_14E);
puts(a1);
puts(a2);
puts(a3);
puts(a4);
putchar(10);
puts(asc_278);
puts(asc_2B0);
putchar(10);
while ( 1 )
{
_isoc99_scanf(&unk_1A1, v1);
my_getchar();
result = v1[0];
if ( v1[0] - 1 <= 3 )
break;
puts(&byte_1A4);
}
return result;
}

original_code:
int login()
{
 int log_flag = 0;
 system("clear");
 printf("-------------------------------------------\n");
 printf("\n");
 printf("*******欢迎使用火车票订票系统 0.9版********\n");
 printf("\n");
 printf("\t请选择\n");
 printf("\t\t1  用户登录\n");
 printf("\t\t2  新用户注册\n");
 printf("\t\t3  管理员登录\n");
 printf("\t\t4  退出\n");
 printf("\n");
 printf("----------------中国铁道部-----------------\n");
 printf("---------如有任何疑问请拨12306垂询---------\n");
 printf("\n");
 scanf("%d",&log_flag);
 my_getchar();
 while(log_flag>4||log_flag<1)
 {
  printf("输入错误，请重试。\n");
  scanf("%d",&log_flag);
  my_getchar();
 }
 return log_flag;
}


decompiled_code:
__int64 __fastcall hide_password(_BYTE *a1)
{
_BYTE *v2; // r12
char v3; // bl

puts(asc_1DA);
setbuf(stdin, 0LL);
system("stty -echo raw");
do
{
v2 = a1++;
v3 = getchar();
putchar(42);
*(a1 - 1) = v3;
}
while ( v3 != 13 );
system("stty echo -raw");
*v2 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
_BYTE *v2; // r12
char v3; // bl

puts(asc_1DA);
setbuf(stdin, 0LL);
system("stty -echo raw");
do
{
v2 = a1++;
v3 = getchar();
putchar(42);
*(a1 - 1) = v3;
}
while ( v3 != 13 );
system("stty echo -raw");
*v2 = 0;
return 0LL;
}

original_code:
int hide_password(char passwd[])
{
 printf("\t请输入密码\n");
 char ch;
 int i = 0;
 setbuf(stdin,((void *)0));
 system("stty -echo raw");
 while(1)
 {
  ch=getchar();
  putchar('*');
  passwd[i] = ch;
  if('\r'==ch)
  {
   break;
  }
  i++;
 }
 system("stty echo -raw");
 passwd[i] = '\0';
 return 0;
}

variable_types:
passwd
char []

variable_types: ch char

variable_types: i int


main

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

while ( 2 )
{
v3 = login(argc, argv, envp);
LABEL_2:
switch ( v3 )
{
case -2:
case 4:
return 0;
case -1:
case 0:
continue;
case 1:
v3 = user();
goto LABEL_2;
case 2:
v3 = add_user();
goto LABEL_2;
case 3:
v3 = admin();
goto LABEL_2;
default:
puts("error menu return message");
break;
}
return 0;
}
}

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

while ( 2 )
{
v3 = func0(argc, argv, envp);
LABEL_2:
switch ( v3 )
{
case -2:
case 4:
return 0;
case -1:
case 0:
continue;
case 1:
v3 = user();
goto LABEL_2;
case 2:
v3 = add_user();
goto LABEL_2;
case 3:
v3 = admin();
goto LABEL_2;
default:
puts("error menu return message");
break;
}
return 0;
}
}

original_code:
int main()
{
 int flag = login();
 while(1)
 {
  switch(flag)
  {
   case 0:flag = login();break;
   case 1:flag = user();break;
   case 2:flag = add_user();break;
   case 3:flag = admin();break;
   case 4:return 0;
   case -2:return 0;
   case -1:flag = 0;break;
   default:printf("error menu return message\n");return 0;
  }
 }
 return 0;
}

variable_types: flag int


repo: liuxiaoxuan/Slab-Allocator

original_code:
void *
kmem_cache_alloc(struct kmem_cache *cp, int flags)
{
 struct kmem_slab *sp;
 if(!cp -> sp_part){
  if(cp -> sp_empt){
   sp = cp -> sp_empt;
   __rem_slab(&(cp -> sp_empt), sp);
   __add_slab(&(cp -> sp_part), sp);
  }else{
   cp -> sp_part = __create_slab(cp);
  }
 }
 sp = cp -> sp_part;
 sp -> refcnt++;
 void *object = sp -> fl_head;
 if( sp -> refcnt == cp -> buf_amt){
  sp -> fl_head = sp -> fl_tail = ((void *)0);
  __rem_slab(&(cp -> sp_part), sp);
  __add_slab(&(cp -> sp_full), sp);
 }else{
  void **next = object + cp -> buf_sz - void_sz;
  sp -> fl_head = *next;
 }
 return object;
}

canonical_original_code:
void *kmem_cache_alloc(struct kmem_cache *cp, int flags)
{
 struct kmem_slab *sp;
 if(!cp -> sp_part){
  if(cp -> sp_empt){
   sp = cp -> sp_empt;
   __rem_slab(&(cp -> sp_empt), sp);
   __add_slab(&(cp -> sp_part), sp);
  }else{
   cp -> sp_part = __create_slab(cp);
  }
 }
 sp = cp -> sp_part;
 sp -> refcnt++;
 void *object = sp -> fl_head;
 if( sp -> refcnt == cp -> buf_amt){
  sp -> fl_head = sp -> fl_tail = ((void *)0);
  __rem_slab(&(cp -> sp_part), sp);
  __add_slab(&(cp -> sp_full), sp);
 }else{
  void **next = object + cp -> buf_sz - void_sz;
  sp -> fl_head = *next;
 }
 return object;
}

variable_types: struct kmem_cache { char *name; int slab_sz; int buf_sz; int buf_amt; int align; void (*constructor)(void *, unsigned long); void (*destructor)(void *, unsigned long); struct kmem_slab { void *slab; struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl { struct kmem_bufctl *next; struct kmem_bufctl *prev; void *buffer; void *sp; } *bp_head; struct kmem_bufctl *bp_tail; void *fl_head; void *fl_tail; int refcnt; void *bufstart; } *sp_full; struct kmem_slab *sp_part; struct kmem_slab *sp_empt; } *

variable_types: flags int

variable_types:
object
void *

variable_types:
next
void **

return_type: void *

user_defined_types: struct kmem_cache { char *name; int slab_sz; int buf_sz; int buf_amt; int align; void (*constructor)(void *, unsigned long); void (*destructor)(void *, unsigned long); struct kmem_slab *sp_full; struct kmem_slab *sp_part; struct kmem_slab *sp_empt; }

user_defined_types: struct kmem_slab { void *slab; struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl *bp_head; struct kmem_bufctl *bp_tail; void *fl_head; void *fl_tail; int refcnt; void *bufstart; }


original_code:
void
kmem_cache_free(struct kmem_cache *cp, void *buf)
{
 struct kmem_slab *sp;
 if(cp -> slab_sz == 4096){
  int offset = cp -> buf_sz * ( cp -> buf_amt - ( (int)buf % 4096) / cp -> buf_sz);
  sp = buf + offset;
 }else{
  void **temp = buf + cp -> buf_sz - void_sz * 2;
  sp = *temp;
 }
 if( sp -> refcnt == cp -> buf_amt){
  sp -> fl_head = sp -> fl_tail = buf;
  __rem_slab(&(cp -> sp_full), sp);
  __add_slab(&(cp -> sp_part), sp);
 }else{
  void **next = sp -> fl_tail + cp -> buf_sz - void_sz;
  *next = buf;
  sp -> fl_tail = buf;
 }
 sp -> refcnt--;
 if(sp -> refcnt == 0){
  __rem_slab(&(cp -> sp_part), sp);
  __add_slab(&(cp -> sp_empt), sp);
 }
}

variable_types:
buf
void *

variable_types: struct kmem_slab { void *slab; struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl { struct kmem_bufctl *next; struct kmem_bufctl *prev; void *buffer; void *sp; } *bp_head; struct kmem_bufctl *bp_tail; void *fl_head; void *fl_tail; int refcnt; void *bufstart; } *

variable_types: offset int

variable_types:
temp
void **


decompiled_code:
void __fastcall kmem_cache_destroy(void *ptr)
{
_free_slab(*((_QWORD *)ptr + 5));
_free_slab(*((_QWORD *)ptr + 6));
_free_slab(*((_QWORD *)ptr + 7));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
func9(*((_QWORD *)ptr + 5));
func9(*((_QWORD *)ptr + 6));
func9(*((_QWORD *)ptr + 7));
free(ptr);
}

original_code:
void
kmem_cache_destroy(struct kmem_cache *cp)
{
 __free_slab(cp -> sp_full);
 __free_slab(cp -> sp_part);
 __free_slab(cp -> sp_empt);
 free(cp);
}

user_defined_types: struct kmem_bufctl { struct kmem_bufctl *next; struct kmem_bufctl *prev; void *buffer; void *sp; }


decompiled_code:
__int64 __fastcall choose_sort(__int64 a1, int a2)
{
__int64 i; // r8
int v3; // edx
__int64 v4; // rax
int v5; // ecx
_DWORD *v6; // rax
__int64 result; // rax

if ( a1 && a2 > 0 )
{
if ( a2 != 1 )
{
for ( i = 0LL; ; ++i )
{
v3 = i;
v4 = i;
if ( (int)i < a2 )
{
do
{
if ( *(_DWORD *)(a1 + 4 * v4) < *(_DWORD *)(a1 + 4LL * v3) )
v3 = v4;
++v4;
}
while ( a2 > (int)v4 );
if ( (_DWORD)i != v3 )
{
v5 = *(_DWORD *)(a1 + 4 * i);
v6 = (_DWORD *)(a1 + 4LL * v3);
*(_DWORD *)(a1 + 4 * i) = *v6;
*v6 = v5;
}
}
if ( i == a2 - 2 )
break;
}
}
result = 0LL;
}
else
{
puts("ilegal array!");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 i; // r8
int v3; // edx
__int64 v4; // rax
int v5; // ecx
_DWORD *v6; // rax
__int64 result; // rax

if ( a1 && a2 > 0 )
{
if ( a2 != 1 )
{
for ( i = 0LL; ; ++i )
{
v3 = i;
v4 = i;
if ( (int)i < a2 )
{
do
{
if ( *(_DWORD *)(a1 + 4 * v4) < *(_DWORD *)(a1 + 4LL * v3) )
v3 = v4;
++v4;
}
while ( a2 > (int)v4 );
if ( (_DWORD)i != v3 )
{
v5 = *(_DWORD *)(a1 + 4 * i);
v6 = (_DWORD *)(a1 + 4LL * v3);
*(_DWORD *)(a1 + 4 * i) = *v6;
*v6 = v5;
}
}
if ( i == a2 - 2 )
break;
}
}
result = 0LL;
}
else
{
puts("ilegal array!");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int choose_sort(int *array, int len)
{
 int i, j, min_idx;
 int tmp;
 if (!array || len <= 0) {
  printf("ilegal array!\n");
  return -1;
 }
 for (i = 0; i < len - 1; i++) {
  for (min_idx = j = i; j < len; j++) {
   if (array[j] < array[min_idx])
    min_idx = j;
  }
  if (i == min_idx)
   continue;
  tmp = array[i];
  array[i] = array[min_idx];
  array[min_idx] = tmp;
 }
 return 0;
}

canonical_original_code:
int choose_sort(int *array, int len)
{
 int i; int j; int min_idx;
 int tmp;
 if (!array || len <= 0) {
  printf("ilegal array!\n");
  return -1;
 }
 for (i = 0; i < len - 1; i++) {
  for (min_idx = j = i; j < len; j++) {
   if (array[j] < array[min_idx])
    min_idx = j;
  }
  if (i == min_idx)
   continue;
  tmp = array[i];
  array[i] = array[min_idx];
  array[min_idx] = tmp;
 }
 return 0;
}

variable_types:
array
int *

variable_types: len int

variable_types: j int

variable_types: tmp int


original_code:
int bubble_sort(int *array, int len)
{
 int i, j;
 int tmp;
 if (!array || len <=0)
  return -1;
 for (i = 0; i < len - 1; i++) {
  for (j = len - 1; j > i; j--) {
   if (array[j] < array[j - 1]) {
    tmp = array[j];
    array[j] = array[j - 1];
    array[j - 1] = tmp;
   }
  }
 }
 return 0;
}

canonical_original_code:
int bubble_sort(int *array, int len)
{
 int i; int j;
 int tmp;
 if (!array || len <=0)
  return -1;
 for (i = 0; i < len - 1; i++) {
  for (j = len - 1; j > i; j--) {
   if (array[j] < array[j - 1]) {
    tmp = array[j];
    array[j] = array[j - 1];
    array[j - 1] = tmp;
   }
  }
 }
 return 0;
}


merge

original_code:
int merge(int *array, int start, int mid, int end)
{
 int left_len, right_len;
 int i, j, k;
 int n;
 if (start < 0 || mid < 0 || end < 0 || !array) {
  printf("%s: invalid arguments\n", __func__);
  return -1;
 }
 if ((end - start + 1) > 512) {
  printf("%s: too long\n", __func__);
  return -1;
 }
 left_len = mid - start + 1;
 right_len = end - mid;
 for (i = 0; i < left_len; i++) {
  left[i] = array[start + i];
 }
 for (i = 0; i < right_len; i++) {
  right[i] = array[mid + i + 1];
 }
 i = 0;
 j = 0;
 for (k = start; k <= end; k++) {
  if (left[i] < right[j]) {
   array[k] = left[i];
   i++;
  } else {
   array[k] = right[j];
   j++;
  }
  if ((i >= left_len) || (j >= right_len))
   break;
 }
 if (i >= left_len)
  for (; j < right_len; j++)
   array[++k] = right[j];
 else if (j >= right_len)
  for (; i < left_len; i++)
   array[++k] = left[i];
 return 0;
}

canonical_original_code:
int merge(int *array, int start, int mid, int end)
{
 int left_len; int right_len;
 int i; int j; int k;
 int n;
 if (start < 0 || mid < 0 || end < 0 || !array) {
  printf("%s: invalid arguments\n", __func__);
  return -1;
 }
 if ((end - start + 1) > 512) {
  printf("%s: too long\n", __func__);
  return -1;
 }
 left_len = mid - start + 1;
 right_len = end - mid;
 for (i = 0; i < left_len; i++) {
  left[i] = array[start + i];
 }
 for (i = 0; i < right_len; i++) {
  right[i] = array[mid + i + 1];
 }
 i = 0;
 j = 0;
 for (k = start; k <= end; k++) {
  if (left[i] < right[j]) {
   array[k] = left[i];
   i++;
  } else {
   array[k] = right[j];
   j++;
  }
  if ((i >= left_len) || (j >= right_len))
   break;
 }
 if (i >= left_len)
  for (; j < right_len; j++)
   array[++k] = right[j];
 else if (j >= right_len)
  for (; i < left_len; i++)
   array[++k] = left[i];
 return 0;
}

variable_types: start int

variable_types: mid int

variable_types: end int

variable_types: k int

variable_types: n int


decompiled_code:
__int64 __fastcall merge_sort(__int64 a1, int a2)
{
return _merge_sort(a1, 0LL, a2 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return func1(a1, 0LL, a2 - 1);
}

original_code:
int merge_sort(int *array, int len)
{
 return __merge_sort(array, 0, len - 1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts(">>>>");
insert_sort(10LL, argv);
puts(">>>>");
insert_sort(0LL, argv);
puts(">>>>");
insert_sort(1LL, argv);
puts(">>>>");
insert_sort(2LL, argv);
puts(">>>>");
insert_sort(3LL, argv);
puts(">>>>");
insert_sort(4LL, argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts(">>>>");
func14(10LL, argv);
puts(">>>>");
func14(0LL, argv);
puts(">>>>");
func14(1LL, argv);
puts(">>>>");
func14(2LL, argv);
puts(">>>>");
func14(3LL, argv);
puts(">>>>");
func14(4LL, argv);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int *p = data;
 int (*q)[3];
 int i, j;
 for(i = 0; i <= 3 * 2; i++)
  p[i] = i + 1;
 q = (int (*)[3])p;
 printf("the two dimension array:\n");
 for(i = 0; i < 2; i++)
 {
  for(j = 0; j < 3; j++)
   printf("%d ",q[i][j]);
  printf("\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int *p = data;
 int (*q)[3];
 int i; int j;
 for(i = 0; i <= 3 * 2; i++)
  p[i] = i + 1;
 q = (int (*)[3])p;
 printf("the two dimension array:\n");
 for(i = 0; i < 2; i++)
 {
  for(j = 0; j < 3; j++)
   printf("%d ",q[i][j]);
  printf("\n");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
p
int *

variable_types: i int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx
__int64 *v7; // rax
__int64 v8; // rbx
__int64 v9; // rbx
__int64 v10; // rbx
__int64 v12; // [rsp+0h] [rbp-110h] BYREF
__int64 v13; // [rsp+8h] [rbp-108h]
__int64 v14; // [rsp+10h] [rbp-100h]
__int64 v15; // [rsp+18h] [rbp-F8h]
__int64 v16; // [rsp+20h] [rbp-F0h]
__int64 v17; // [rsp+28h] [rbp-E8h]
__int64 v18; // [rsp+30h] [rbp-E0h]
__int64 v19[8]; // [rsp+40h] [rbp-D0h] BYREF
__int64 v20; // [rsp+80h] [rbp-90h] BYREF
__int64 v21; // [rsp+88h] [rbp-88h]
__int64 v22; // [rsp+90h] [rbp-80h]
__int64 v23; // [rsp+98h] [rbp-78h]
__int64 v24; // [rsp+A0h] [rbp-70h]
__int64 v25; // [rsp+A8h] [rbp-68h]
__int64 v26; // [rsp+B0h] [rbp-60h]
__int64 v27[9]; // [rsp+C0h] [rbp-50h] BYREF

std::ios_base::precision((std::ios_base *)&unk_404088, 2LL);
std::ios_base::setf(&unk_404088, 4LL, 260LL);
std::ios_base::setf(&unk_404088, 1024LL);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::Stock((Stock *)&v20, "NanoSmart", 12, 20.0);
Stock::show((Stock *)&v20);
Stock::Stock((Stock *)v19, "Boffo Objects", 2, 2.0);
Stock::show((Stock *)v19);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
v19[0] = v20;
v19[1] = v21;
v19[2] = v22;
v19[3] = v23;
v19[4] = v24;
v19[5] = v25;
v19[6] = v26;
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::show((Stock *)&v20);
Stock::show((Stock *)v19);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::Stock((Stock *)v27, "Nifty Foods", 10, 50.0);
v20 = v27[0];
v21 = v27[1];
v22 = v27[2];
v23 = v27[3];
v24 = v27[4];
v25 = v27[5];
v26 = v27[6];
Stock::~Stock((Stock *)v27);
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::show((Stock *)&v20);
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::Stock((Stock *)&v12);
v3 = (__int64 *)Stock::topval((Stock *)&v20, (const Stock *)v19);
v4 = v3[1];
v12 = *v3;
v13 = v4;
v5 = v3[3];
v14 = v3[2];
v15 = v5;
v6 = v3[5];
v16 = v3[4];
v17 = v6;
v18 = v3[6];
Stock::show((Stock *)&v12);
std::ostream::operator<<();
v7 = (__int64 *)Stock::topval((Stock *)v19, (const Stock *)&v20);
v8 = v7[1];
v12 = *v7;
v13 = v8;
v9 = v7[3];
v14 = v7[2];
v15 = v9;
v10 = v7[5];
v16 = v7[4];
v17 = v10;
v18 = v7[6];
Stock::show((Stock *)&v12);
std::operator<<<std::char_traits<char>>();
Stock::~Stock((Stock *)&v12);
Stock::~Stock((Stock *)v19);
Stock::~Stock((Stock *)&v20);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx
__int64 *v7; // rax
__int64 v8; // rbx
__int64 v9; // rbx
__int64 v10; // rbx
__int64 v12; // [rsp+0h] [rbp-110h] BYREF
__int64 v13; // [rsp+8h] [rbp-108h]
__int64 v14; // [rsp+10h] [rbp-100h]
__int64 v15; // [rsp+18h] [rbp-F8h]
__int64 v16; // [rsp+20h] [rbp-F0h]
__int64 v17; // [rsp+28h] [rbp-E8h]
__int64 v18; // [rsp+30h] [rbp-E0h]
__int64 v19[8]; // [rsp+40h] [rbp-D0h] BYREF
__int64 v20; // [rsp+80h] [rbp-90h] BYREF
__int64 v21; // [rsp+88h] [rbp-88h]
__int64 v22; // [rsp+90h] [rbp-80h]
__int64 v23; // [rsp+98h] [rbp-78h]
__int64 v24; // [rsp+A0h] [rbp-70h]
__int64 v25; // [rsp+A8h] [rbp-68h]
__int64 v26; // [rsp+B0h] [rbp-60h]
__int64 v27[9]; // [rsp+C0h] [rbp-50h] BYREF

std::ios_base::precision((std::ios_base *)&unk_404088, 2LL);
std::ios_base::func9(&unk_404088, 4LL, 260LL);
std::ios_base::func9(&unk_404088, 1024LL);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::func11((Stock *)&v20, "NanoSmart", 12, 20.0);
Stock::func15((Stock *)&v20);
Stock::func11((Stock *)v19, "Boffo Objects", 2, 2.0);
Stock::func15((Stock *)v19);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
v19[0] = v20;
v19[1] = v21;
v19[2] = v22;
v19[3] = v23;
v19[4] = v24;
v19[5] = v25;
v19[6] = v26;
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::func15((Stock *)&v20);
Stock::func15((Stock *)v19);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::func11((Stock *)v27, "Nifty Foods", 10, 50.0);
v20 = v27[0];
v21 = v27[1];
v22 = v27[2];
v23 = v27[3];
v24 = v27[4];
v25 = v27[5];
v26 = v27[6];
Stock::~func11((Stock *)v27);
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::func15((Stock *)&v20);
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
Stock::func11((Stock *)&v12);
v3 = (__int64 *)Stock::topval((Stock *)&v20, (const Stock *)v19);
v4 = v3[1];
v12 = *v3;
v13 = v4;
v5 = v3[3];
v14 = v3[2];
v15 = v5;
v6 = v3[5];
v16 = v3[4];
v17 = v6;
v18 = v3[6];
Stock::func15((Stock *)&v12);
std::ostream::operator<<();
v7 = (__int64 *)Stock::topval((Stock *)v19, (const Stock *)&v20);
v8 = v7[1];
v12 = *v7;
v13 = v8;
v9 = v7[3];
v14 = v7[2];
v15 = v9;
v10 = v7[5];
v16 = v7[4];
v17 = v10;
v18 = v7[6];
Stock::func15((Stock *)&v12);
std::operator<<<std::char_traits<char>>();
Stock::~func11((Stock *)&v12);
Stock::~func11((Stock *)v19);
Stock::~func11((Stock *)&v20);
return 0;
}


decompiled_code:
void create_node()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
Node* create_node(int nl, Node_type t,
        char* lexeme, ...) {
}

canonical_original_code:
struct _node *create_node(int nl, int t, char *lexeme, ...) {
}

variable_types: nl int

variable_types: t int

variable_types:
lexeme
char *

return_type: struct _node { int line_num; char *lexeme; int type; void *attribute; } *


cmp

decompiled_code:
__int64 __fastcall cmp(double *a1, double *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a2 <= *a1 )
result = *a1 > *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, double *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a2 <= *a1 )
result = *a1 > *a2;
return result;
}

original_code:
int cmp(double *x, double *y) {
  if (*x < *y) return -1;
  if (*x > *y) return 1;
  return 0;
}

variable_types:
x
double *

variable_types:
y
double *


decompiled_code:
void __fastcall __noreturn exit_now(int status)
{
fclose(in_points);
fclose(in_wind);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int status)
{
fclose(in_points);
fclose(in_wind);
exit(status);
}

original_code:
void exit_now(int e) {
  (void) fclose(in_points);
  (void) fclose(in_wind);
  exit(e);
}

variable_types: e int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rsi
int i; // eax
int v6; // ebx
__int64 v7; // r12
int v8; // ebx
__int64 v9; // rdx
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
double v16; // [rsp+8h] [rbp-50h]
__int64 v17[2]; // [rsp+10h] [rbp-48h] BYREF
char filename[56]; // [rsp+20h] [rbp-38h] BYREF

if ( argc != 4 )
{
fwrite(
"Missing comand line arguments,\nUSAGE: <program name> <config file> <points file> <wind file>\n\n",
1uLL,
0x5EuLL,
stderr);
exit(1);
}
strcpy(filename, "node_");
fprintf(stderr, "%s\n", filename);
log_file = fopen(filename, "w+");
if ( log_file )
{
if ( !(unsigned int)init_globals(argv[1]) )
{
in_points = fopen(argv[2], "r");
if ( in_points )
{
if ( !(unsigned int)get_points(in_points) )
{
in_wind = fopen(argv[3], "r");
if ( in_wind )
{
if ( !(unsigned int)get_wind(in_wind) )
{
v3 = 0LL;
set_global_values(log_file);
set_eruption_values(&e, *(_QWORD *)W);
while ( num_pts > (int)v3 )
{
v4 = pt + 1648 * v3++;
tephra_calc(&e, v4, *(_QWORD *)W, v17);
}
fprintf(
stderr,
"\nMin Particle Fall Time = %gs\nMax Particle Fall Time = %gs\n",
*(double *)v17,
*(double *)&v17[1]);
v16 = (*(double *)&qword_FC8 - *(double *)&qword_FC0) / (double)PART_STEPS;
printf("#EAST NORTH ELEV Kg/m^2 ");
for ( i = 0; PART_STEPS > i; i = v6 )
{
v6 = i + 1;
printf(
"[%g->%g) ",
(double)i * v16 + *(double *)&qword_FC0,
(double)(i + 1) * v16 + *(double *)&qword_FC0);
}
v7 = 0LL;
puts("(percent)");
fprintf(stderr, "PART_STEPS=%d bin_width=%g\n", (unsigned int)PART_STEPS, v16);
while ( num_pts > (int)v7 )
{
printf(
"%.0f %.0f %.0f %g ",
*(double *)(1648 * v7 + pt),
*(double *)(1648 * v7 + pt + 8),
*(double *)(1648 * v7 + pt + 16),
*(double *)(1648 * v7 + pt + 40));
if ( PART_STEPS > 0 )
{
v8 = 0;
do
{
v9 = v8++;
printf("%g ", *(double *)(1648 * v7 + pt + 8 * v9 + 848) / *(double *)(1648 * v7 + pt + 40) * 100.0);
}
while ( PART_STEPS > v8 );
}
++v7;
putchar(10);
}
print_for_stats();
fwrite("Finished.\n", 1uLL, 0xAuLL, log_file);
exit_now(0);
}
}
else
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Cannot open wind file=[%s]:[%s]. Exiting.\n", argv[3], v15);
}
}
}
else
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Cannot open points file=[%s]:[%s]. Exiting.\n", argv[2], v11);
}
exit_now(1);
}
exit(1);
}
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Cannot open LOG file=[%s]:[%s]. Exiting.\n", filename, v13);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rsi
int i; // eax
int v6; // ebx
__int64 v7; // r12
int v8; // ebx
__int64 v9; // rdx
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
double v16; // [rsp+8h] [rbp-50h]
__int64 v17[2]; // [rsp+10h] [rbp-48h] BYREF
char filename[56]; // [rsp+20h] [rbp-38h] BYREF

if ( argc != 4 )
{
fwrite(
"Missing comand line arguments,\nUSAGE: <program name> <config file> <points file> <wind file>\n\n",
1uLL,
0x5EuLL,
stderr);
exit(1);
}
strcpy(filename, "node_");
fprintf(stderr, "%s\n", filename);
log_file = fopen(filename, "w+");
if ( log_file )
{
if ( !(unsigned int)func5(argv[1]) )
{
in_points = fopen(argv[2], "r");
if ( in_points )
{
if ( !(unsigned int)func3(in_points) )
{
in_wind = fopen(argv[3], "r");
if ( in_wind )
{
if ( !(unsigned int)func4(in_wind) )
{
v3 = 0LL;
set_global_values(log_file);
set_eruption_values(&e, *(_QWORD *)W);
while ( num_pts > (int)v3 )
{
v4 = pt + 1648 * v3++;
tephra_calc(&e, v4, *(_QWORD *)W, v17);
}
fprintf(
stderr,
"\nMin Particle Fall Time = %gs\nMax Particle Fall Time = %gs\n",
*(double *)v17,
*(double *)&v17[1]);
v16 = (*(double *)&qword_FC8 - *(double *)&qword_FC0) / (double)PART_STEPS;
printf("#EAST NORTH ELEV Kg/m^2 ");
for ( i = 0; PART_STEPS > i; i = v6 )
{
v6 = i + 1;
printf(
"[%g->%g) ",
(double)i * v16 + *(double *)&qword_FC0,
(double)(i + 1) * v16 + *(double *)&qword_FC0);
}
v7 = 0LL;
puts("(percent)");
fprintf(stderr, "PART_STEPS=%d bin_width=%g\n", (unsigned int)PART_STEPS, v16);
while ( num_pts > (int)v7 )
{
printf(
"%.0f %.0f %.0f %g ",
*(double *)(1648 * v7 + pt),
*(double *)(1648 * v7 + pt + 8),
*(double *)(1648 * v7 + pt + 16),
*(double *)(1648 * v7 + pt + 40));
if ( PART_STEPS > 0 )
{
v8 = 0;
do
{
v9 = v8++;
printf("%g ", *(double *)(1648 * v7 + pt + 8 * v9 + 848) / *(double *)(1648 * v7 + pt + 40) * 100.0);
}
while ( PART_STEPS > v8 );
}
++v7;
putchar(10);
}
func2();
fwrite("Finished.\n", 1uLL, 0xAuLL, log_file);
func1(0);
}
}
else
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Cannot open wind file=[%s]:[%s]. Exiting.\n", argv[3], v15);
}
}
}
else
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Cannot open points file=[%s]:[%s]. Exiting.\n", argv[2], v11);
}
func1(1);
}
exit(1);
}
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Cannot open LOG file=[%s]:[%s]. Exiting.\n", filename, v13);
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
  int i, bin;
  double val, bin_width;
  STATS stats;
  char log_name[25];
  if (argc != 4) {
      fprintf(stderr,
       "Missing comand line arguments,\nUSAGE: <program name> <config file> <points file> <wind file>\n\n");
    exit(1);
  }
  sprintf(log_name, "%s", "node_");
  fprintf(stderr, "%s\n", log_name);
  log_file = fopen(log_name, "w+");
  if (log_file == ((void *)0)) {
    fprintf(stderr, "Cannot open LOG file=[%s]:[%s]. Exiting.\n",
     log_name, strerror((*__errno_location ())));
    exit(1);
  }
  if ( init_globals(argv[1]) ) {
    exit(1);
  }
  in_points= fopen(argv[2], "r");
  if (in_points == ((void *)0)) {
    fprintf(stderr, "Cannot open points  file=[%s]:[%s]. Exiting.\n",
     argv[2], strerror((*__errno_location ())));
    exit_now(1);
  }
  if (get_points(in_points) ) {
    exit_now(1);
  }
  in_wind= fopen(argv[3], "r");
  if (in_wind == ((void *)0)) {
    fprintf(stderr, "Cannot open wind file=[%s]:[%s]. Exiting.\n",
     argv[3], strerror((*__errno_location ())));
    exit_now(1);
  }
  if (get_wind(in_wind) ) {
    exit_now(1);
  }
  set_global_values(log_file);
  set_eruption_values(&e, W[0]);
  for (i = 0; i < num_pts; i++)
     tephra_calc(&e, pt+i, W[0], &stats);
    fprintf(stderr,"\nMin Particle Fall Time = %gs\nMax Particle Fall Time = %gs\n",stats.min_falltime, stats.max_falltime);
 bin_width = (e.max_phi - e.min_phi)/PART_STEPS;
 printf("#EAST NORTH ELEV Kg/m^2 ");
 for (bin = 0; bin < PART_STEPS; bin++)
   printf("[%g->%g) ",
  e.min_phi + bin_width*bin,
  e.min_phi + bin_width*(bin+1));
 printf("(percent)\n");
 fprintf(stderr, "PART_STEPS=%d bin_width=%g\n", PART_STEPS, bin_width);
 for (i=0; i < num_pts; i++) {
   printf("%.0f %.0f %.0f %g ",
  (pt+i)->easting,
  (pt+i)->northing,
  (pt+i)->elevation,
  (pt+i)->calculated_mass);
   for (bin=0; bin < PART_STEPS; bin++) {
    val = ((pt+i)->calculated_phi[bin]/(pt+i)->calculated_mass) * 100.0;
     printf("%g ", val);
   }
   printf("\n");
 }
  print_for_stats(0);
  fprintf(log_file, "Finished.\n");
  exit_now(0);
  return 1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i; int bin;
  double val; double bin_width;
  struct STATS stats;
  char log_name[25];
  if (argc != 4) {
      fprintf(stderr,
       "Missing comand line arguments,\nUSAGE: <program name> <config file> <points file> <wind file>\n\n");
    exit(1);
  }
  sprintf(log_name, "%s", "node_");
  fprintf(stderr, "%s\n", log_name);
  log_file = fopen(log_name, "w+");
  if (log_file == ((void *)0)) {
    fprintf(stderr, "Cannot open LOG file=[%s]:[%s]. Exiting.\n",
     log_name, strerror((*__errno_location ())));
    exit(1);
  }
  if ( init_globals(argv[1]) ) {
    exit(1);
  }
  in_points= fopen(argv[2], "r");
  if (in_points == ((void *)0)) {
    fprintf(stderr, "Cannot open points  file=[%s]:[%s]. Exiting.\n",
     argv[2], strerror((*__errno_location ())));
    exit_now(1);
  }
  if (get_points(in_points) ) {
    exit_now(1);
  }
  in_wind= fopen(argv[3], "r");
  if (in_wind == ((void *)0)) {
    fprintf(stderr, "Cannot open wind file=[%s]:[%s]. Exiting.\n",
     argv[3], strerror((*__errno_location ())));
    exit_now(1);
  }
  if (get_wind(in_wind) ) {
    exit_now(1);
  }
  set_global_values(log_file);
  set_eruption_values(&e, W[0]);
  for (i = 0; i < num_pts; i++)
     tephra_calc(&e, pt+i, W[0], &stats);
    fprintf(stderr,"\nMin Particle Fall Time = %gs\nMax Particle Fall Time = %gs\n",stats.min_falltime, stats.max_falltime);
 bin_width = (e.max_phi - e.min_phi)/PART_STEPS;
 printf("#EAST NORTH ELEV Kg/m^2 ");
 for (bin = 0; bin < PART_STEPS; bin++)
   printf("[%g->%g) ",
  e.min_phi + bin_width*bin,
  e.min_phi + bin_width*(bin+1));
 printf("(percent)\n");
 fprintf(stderr, "PART_STEPS=%d bin_width=%g\n", PART_STEPS, bin_width);
 for (i=0; i < num_pts; i++) {
   printf("%.0f %.0f %.0f %g ",
  (pt+i)->easting,
  (pt+i)->northing,
  (pt+i)->elevation,
  (pt+i)->calculated_mass);
   for (bin=0; bin < PART_STEPS; bin++) {
    val = ((pt+i)->calculated_phi[bin]/(pt+i)->calculated_mass) * 100.0;
     printf("%g ", val);
   }
   printf("\n");
 }
  print_for_stats(0);
  fprintf(log_file, "Finished.\n");
  exit_now(0);
  return 1;
}

variable_types:
argv
char *[]

variable_types: bin int

variable_types: val double

variable_types: struct STATS { double min_falltime; double max_falltime; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp

v3 = (void *)create_hash(argc, argv, envp);
hash_insert(1LL, 10LL, v3);
hash_insert(2LL, 20LL, v3);
hash_insert(3LL, 30LL, v3);
hash_insert(4LL, 40LL, v3);
hash_insert(104LL, 140LL, v3);
hash_find(3LL, v3);
hash_find(1LL, v3);
hash_modify(4LL, 400LL, v3);
hash_modify(2LL, 200LL, v3);
display(v3);
destroy_hash(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp

v3 = (void *)func9(argc, argv, envp);
func10(1LL, 10LL, v3);
func10(2LL, 20LL, v3);
func10(3LL, 30LL, v3);
func10(4LL, 40LL, v3);
func10(104LL, 140LL, v3);
func12(3LL, v3);
func12(1LL, v3);
func11(4LL, 400LL, v3);
func11(2LL, 200LL, v3);
func14(v3);
func13(v3);
return 0;
}

original_code:
int
main()
{
 hash_t *hash = create_hash();
 hash_insert(1, 10, hash);
 hash_insert(2, 20, hash);
 hash_insert(3, 30, hash);
 hash_insert(4, 40, hash);
 hash_insert(100 + 4, 100 + 40, hash);
 hash_find(3, hash);
 hash_find(1, hash);
 hash_modify(4, 400, hash);
 hash_modify(2, 200, hash);
 display(hash);
 destroy_hash(hash);
 return 0;
}

canonical_original_code:
int main()
{
 struct hash_s *hash = create_hash();
 hash_insert(1, 10, hash);
 hash_insert(2, 20, hash);
 hash_insert(3, 30, hash);
 hash_insert(4, 40, hash);
 hash_insert(100 + 4, 100 + 40, hash);
 hash_find(3, hash);
 hash_find(1, hash);
 hash_modify(4, 400, hash);
 hash_modify(2, 200, hash);
 display(hash);
 destroy_hash(hash);
 return 0;
}

variable_types:
hash
struct hash_s { void **hash; } *


Hash

decompiled_code:
__int64 __fastcall Hash(int a1)
{
return (unsigned int)(a1 % 100);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)(a1 % 100);
}

original_code:
unsigned int Hash(int key)
{
 return key % 100;
}

variable_types: key int

return_type: unsigned int


decompiled_code:
_QWORD *init_hash_item()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
__int64 v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
__assert_fail("NULL != p", "hash.c", 0xFu, "init_hash_item");
v1 = v0;
v2 = create_link();
*(_DWORD *)v1 = -1;
v1[1] = v2;
return v1;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
__int64 v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
__assert_fail("NULL != p", "hash.c", 0xFu, "init_hash_item");
v1 = v0;
v2 = func15();
*(_DWORD *)v1 = -1;
v1[1] = v2;
return v1;
}

original_code:
void *init_hash_item()
{
 hash_link_t *p = malloc(sizeof(struct hash_link_s));
 ((void) sizeof ((((void *)0) != p) ? 1 : 0), __extension__ ({ if (((void *)0) != p) ; else __assert_fail ("NULL != p", "hash.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 p->link = create_link();
 p->key = -1;
 return p;
}

canonical_original_code:
void *init_hash_item()
{
 struct hash_link_s *p = malloc(sizeof(struct hash_link_s));
 ((void) sizeof ((((void *)0) != p) ? 1 : 0), __extension__ ({ if (((void *)0) != p) ; else __assert_fail ("NULL != p", "hash.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 p->link = create_link();
 p->key = -1;
 return p;
}

variable_types: struct hash_link_s { unsigned int key; struct db_link_s { struct link_s { void *key; void *data; struct link_s *prev; struct link_s *next; } *head; struct link_s *tail; } *link; } *

user_defined_types: struct hash_link_s { unsigned int key; struct db_link_s *link; }

user_defined_types: struct db_link_s { struct link_s *head; struct link_s *tail; }


decompiled_code:
char **create_hash()
{
char **v0; // rax
char **v1; // r12
char *v2; // rax
__int64 v3; // rbp
char *v4; // rbx

v0 = (char **)malloc(8uLL);
if ( !v0 )
__assert_fail("NULL != new", "hash.c", 0x1Eu, "create_hash");
v1 = v0;
v2 = (char *)malloc(0x320uLL);
*v1 = v2;
if ( !v2 )
__assert_fail("NULL != new->hash", "hash.c", 0x20u, "create_hash");
v3 = 0LL;
while ( 1 )
{
v4 = &v2[v3];
v3 += 8LL;
*(_QWORD *)v4 = init_hash_item();
if ( v3 == 800 )
break;
v2 = *v1;
}
return v1;
}

canonical_decompiled_code:
char **func9()
{
char **v0; // rax
char **v1; // r12
char *v2; // rax
__int64 v3; // rbp
char *v4; // rbx

v0 = (char **)malloc(8uLL);
if ( !v0 )
__assert_fail("NULL != new", "hash.c", 0x1Eu, "create_hash");
v1 = v0;
v2 = (char *)malloc(0x320uLL);
*v1 = v2;
if ( !v2 )
__assert_fail("NULL != new->hash", "hash.c", 0x20u, "create_hash");
v3 = 0LL;
while ( 1 )
{
v4 = &v2[v3];
v3 += 8LL;
*(_QWORD *)v4 = func8();
if ( v3 == 800 )
break;
v2 = *v1;
}
return v1;
}

original_code:
hash_t *create_hash()
{
 int i;
 hash_t *new = malloc(sizeof(struct hash_s));
 ((void) sizeof ((((void *)0) != new) ? 1 : 0), __extension__ ({ if (((void *)0) != new) ; else __assert_fail ("NULL != new", "hash.c", 30, __extension__ __PRETTY_FUNCTION__); }));
 new->hash = malloc(sizeof(void *) * 100);
 ((void) sizeof ((((void *)0) != new->hash) ? 1 : 0), __extension__ ({ if (((void *)0) != new->hash) ; else __assert_fail ("NULL != new->hash", "hash.c", 32, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < 100; ++i) {
  new->hash[i] = init_hash_item();
 }
 return new;
}

canonical_original_code:
struct hash_s *create_hash()
{
 int i;
 struct hash_s *new = malloc(sizeof(struct hash_s));
 ((void) sizeof ((((void *)0) != new) ? 1 : 0), __extension__ ({ if (((void *)0) != new) ; else __assert_fail ("NULL != new", "hash.c", 30, __extension__ __PRETTY_FUNCTION__); }));
 new->hash = malloc(sizeof(void *) * 100);
 ((void) sizeof ((((void *)0) != new->hash) ? 1 : 0), __extension__ ({ if (((void *)0) != new->hash) ; else __assert_fail ("NULL != new->hash", "hash.c", 32, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < 100; ++i) {
  new->hash[i] = init_hash_item();
 }
 return new;
}

variable_types:
new
struct hash_s { void **hash; } *

return_type: struct hash_s { void **hash; } *


decompiled_code:
__int64 __fastcall hash_insert(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
_QWORD *v3; // rcx

v2 = Hash(a1);
return insert_item(a1, a2, *(_QWORD *)(*(_QWORD *)(*v3 + 8LL * v2) + 8LL));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
_QWORD *v3; // rcx

v2 = func7(a1);
return insert_item(a1, a2, *(_QWORD *)(*(_QWORD *)(*v3 + 8LL * v2) + 8LL));
}

original_code:
void hash_insert(int key, int value, hash_t *p)
{
 unsigned int k = Hash(key);
 hash_link_t *t = p->hash[k];
 insert_item(key, value, t->link);
}

canonical_original_code:
void hash_insert(int key, int value, struct hash_s *p)
{
 unsigned int k = Hash(key);
 struct hash_link_s *t = p->hash[k];
 insert_item(key, value, t->link);
}

variable_types: value int

variable_types:
p
struct hash_s { void **hash; } *

variable_types:
k
unsigned int

user_defined_types: struct link_s { void *key; void *data; struct link_s *prev; struct link_s *next; }


decompiled_code:
__int64 __fastcall hash_modify(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
_QWORD *v3; // rcx

v2 = Hash(a1);
return modify_item(a1, a2, *(_QWORD *)(*(_QWORD *)(*v3 + 8LL * v2) + 8LL));
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
_QWORD *v3; // rcx

v2 = func7(a1);
return func17(a1, a2, *(_QWORD *)(*(_QWORD *)(*v3 + 8LL * v2) + 8LL));
}

original_code:
void hash_modify(int key, int value, hash_t *p)
{
 unsigned int k = Hash(key);
 hash_link_t *t = p->hash[k];
 modify_item(key, value, t->link);
}

canonical_original_code:
void hash_modify(int key, int value, struct hash_s *p)
{
 unsigned int k = Hash(key);
 struct hash_link_s *t = p->hash[k];
 modify_item(key, value, t->link);
}


decompiled_code:
__int64 __fastcall hash_find(__int64 a1, _QWORD *a2)
{
unsigned int v2; // eax

v2 = Hash(a1);
return find_item(a1, *(_QWORD *)(*(_QWORD *)(*a2 + 8LL * v2) + 8LL));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, _QWORD *a2)
{
unsigned int v2; // eax

v2 = func7(a1);
return func16(a1, *(_QWORD *)(*(_QWORD *)(*a2 + 8LL * v2) + 8LL));
}

original_code:
void *hash_find(int key, hash_t *p)
{
 unsigned int k = Hash(key);
 hash_link_t *t = p->hash[k];
 return find_item(key, t->link);
}

canonical_original_code:
void *hash_find(int key, struct hash_s *p)
{
 unsigned int k = Hash(key);
 struct hash_link_s *t = p->hash[k];
 return find_item(key, t->link);
}


decompiled_code:
void __fastcall destroy_hash(void *ptr)
{
__int64 i; // rbx
_QWORD *v2; // rbp

for ( i = 0LL; i != 800; i += 8LL )
{
v2 = *(_QWORD **)(*(_QWORD *)ptr + i);
destroy_link(v2[1]);
free(v2);
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
__int64 i; // rbx
_QWORD *v2; // rbp

for ( i = 0LL; i != 800; i += 8LL )
{
v2 = *(_QWORD **)(*(_QWORD *)ptr + i);
func18(v2[1]);
free(v2);
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_hash(hash_t *p)
{
 int i;
 for (i = 0; i < 100; ++i) {
  hash_link_t *tmp = p->hash[i];
  db_link_t *link = tmp->link;
  destroy_link(link);
  free(tmp);
  tmp = ((void *)0);
 }
 free(p->hash);
 free(p);
}

canonical_original_code:
void destroy_hash(struct hash_s *p)
{
 int i;
 for (i = 0; i < 100; ++i) {
  struct hash_link_s *tmp = p->hash[i];
  struct db_link_s *link = tmp->link;
  destroy_link(link);
  free(tmp);
  tmp = ((void *)0);
 }
 free(p->hash);
 free(p);
}

variable_types: i int

variable_types: struct db_link_s { struct link_s { void *key; void *data; struct link_s *prev; struct link_s *next; } *head; struct link_s *tail; } *


display

decompiled_code:
int __fastcall display(_QWORD *a1)
{
__int64 i; // rbp
__int64 v2; // rax
unsigned int **j; // rbx

for ( i = 0LL; i != 800; i += 8LL )
{
v2 = *(_QWORD *)(*(_QWORD *)(*a1 + i) + 8LL);
for ( j = *(unsigned int ***)(v2 + 8); j; j = (unsigned int **)j[2] )
LODWORD(v2) = printf("(key = %d, value = %d)\n", **j, *j[1]);
}
return v2;
}

canonical_decompiled_code:
int __fastcall func14(_QWORD *a1)
{
__int64 i; // rbp
__int64 v2; // rax
unsigned int **j; // rbx

for ( i = 0LL; i != 800; i += 8LL )
{
v2 = *(_QWORD *)(*(_QWORD *)(*a1 + i) + 8LL);
for ( j = *(unsigned int ***)(v2 + 8); j; j = (unsigned int **)j[2] )
LODWORD(v2) = printf("(key = %d, value = %d)\n", **j, *j[1]);
}
return v2;
}

original_code:
void display(hash_t *p)
{
 int i;
 for (i = 0; i < 100; ++i) {
  hash_link_t *tmp = p->hash[i];
  db_link_t *link = tmp->link;
  link_t *cur = link->tail;
  while (((void *)0) != cur) {
   printf("(key = %d, value = %d)\n", *(int *)cur->key, *(int *)cur->data);
   cur = cur->prev;
  }
 }
}

canonical_original_code:
void display(struct hash_s *p)
{
 int i;
 for (i = 0; i < 100; ++i) {
  struct hash_link_s *tmp = p->hash[i];
  struct db_link_s *link = tmp->link;
  struct link_s *cur = link->tail;
  while (((void *)0) != cur) {
   printf("(key = %d, value = %d)\n", *(int *)cur->key, *(int *)cur->data);
   cur = cur->prev;
  }
 }
}

variable_types: struct link_s { void *key; void *data; struct link_s *prev; struct link_s *next; } *


decompiled_code:
_QWORD *create_link()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
__assert_fail("NULL != new", "link.c", 0xAu, "create_link");
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func15()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
__assert_fail("NULL != new", "link.c", 0xAu, "create_link");
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
db_link_t *create_link(void)
{
 db_link_t *new = malloc(sizeof(struct db_link_s));
 ((void) sizeof ((((void *)0) != new) ? 1 : 0), __extension__ ({ if (((void *)0) != new) ; else __assert_fail ("NULL != new", "link.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 new->head = ((void *)0);
 new->tail = ((void *)0);
 return new;
}

canonical_original_code:
struct db_link_s *create_link()
{
 struct db_link_s *new = malloc(sizeof(struct db_link_s));
 ((void) sizeof ((((void *)0) != new) ? 1 : 0), __extension__ ({ if (((void *)0) != new) ; else __assert_fail ("NULL != new", "link.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 new->head = ((void *)0);
 new->tail = ((void *)0);
 return new;
}

return_type: struct db_link_s { struct link_s { void *key; void *data; struct link_s *prev; struct link_s *next; } *head; struct link_s *tail; } *


decompiled_code:
__int64 __fastcall find_item(int a1, __int64 *a2)
{
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // r8
__int64 v6; // rdi

v2 = *a2;
if ( !*a2 )
return 0LL;
result = *a2;
while ( **(_DWORD **)result != a1 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
v4 = *(_QWORD *)(result + 16);
v5 = *(_QWORD *)(result + 8);
if ( v4 )
{
v6 = *(_QWORD *)(result + 24);
if ( v6 )
{
*(_QWORD *)(v4 + 24) = v6;
*(_QWORD *)(v6 + 16) = v4;
}
else
{
a2[1] = v4;
*(_QWORD *)(v4 + 24) = 0LL;
}
*(_QWORD *)(result + 24) = v2;
*(_QWORD *)(v2 + 16) = result;
*a2 = result;
*(_QWORD *)(result + 16) = 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, __int64 *a2)
{
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // r8
__int64 v6; // rdi

v2 = *a2;
if ( !*a2 )
return 0LL;
result = *a2;
while ( **(_DWORD **)result != a1 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
v4 = *(_QWORD *)(result + 16);
v5 = *(_QWORD *)(result + 8);
if ( v4 )
{
v6 = *(_QWORD *)(result + 24);
if ( v6 )
{
*(_QWORD *)(v4 + 24) = v6;
*(_QWORD *)(v6 + 16) = v4;
}
else
{
a2[1] = v4;
*(_QWORD *)(v4 + 24) = 0LL;
}
*(_QWORD *)(result + 24) = v2;
*(_QWORD *)(v2 + 16) = result;
*a2 = result;
*(_QWORD *)(result + 16) = 0LL;
}
return v5;
}

original_code:
void * find_item(int key, db_link_t *h)
{
 link_t *p = h->head;
 while (((void *)0) != p) {
  if (*(int *)(p->key) == key) {
   if (((void *)0) == p->prev) {
    return p->data;
   }
   if (((void *)0) == p->next) {
    h->tail = p->prev;
    h->tail->next = ((void *)0);
    p->next = h->head;
    h->head->prev = p;
    h->head = p;
    h->head->prev = ((void *)0);
    return p->data;
   }
   p->prev->next = p->next;
   p->next->prev = p->prev;
   p->next = h->head;
   h->head->prev = p;
   h->head = p;
   h->head->prev = ((void *)0);
   return p->data;
  }
  p = p->next;
 }
 return ((void *)0);
}

canonical_original_code:
void *find_item(int key, struct db_link_s *h)
{
 struct link_s *p = h->head;
 while (((void *)0) != p) {
  if (*(int *)(p->key) == key) {
   if (((void *)0) == p->prev) {
    return p->data;
   }
   if (((void *)0) == p->next) {
    h->tail = p->prev;
    h->tail->next = ((void *)0);
    p->next = h->head;
    h->head->prev = p;
    h->head = p;
    h->head->prev = ((void *)0);
    return p->data;
   }
   p->prev->next = p->next;
   p->next->prev = p->prev;
   p->next = h->head;
   h->head->prev = p;
   h->head = p;
   h->head->prev = ((void *)0);
   return p->data;
  }
  p = p->next;
 }
 return ((void *)0);
}


original_code:
void modify_item(int key, int data, db_link_t *h)
{
 link_t *p = h->head;
 while (((void *)0) != p) {
  if (*(int *)p->key == key) {
   *(int *)p->data = data;
   if (((void *)0) == p->prev) {
    return;
   }
   if (((void *)0) == p->next) {
    h->tail = p->prev;
    h->tail->next = ((void *)0);
    p->next = h->head;
    h->head->prev = p;
    h->head = p;
    h->head->prev = ((void *)0);
    return;
   }
   p->prev->next = p->next;
   p->next->prev = p->prev;
   p->next = h->head;
   h->head->prev = p;
   h->head = p;
   h->head->prev = ((void *)0);
   return;
  }
  p = p->next;
 }
}

canonical_original_code:
void modify_item(int key, int data, struct db_link_s *h)
{
 struct link_s *p = h->head;
 while (((void *)0) != p) {
  if (*(int *)p->key == key) {
   *(int *)p->data = data;
   if (((void *)0) == p->prev) {
    return;
   }
   if (((void *)0) == p->next) {
    h->tail = p->prev;
    h->tail->next = ((void *)0);
    p->next = h->head;
    h->head->prev = p;
    h->head = p;
    h->head->prev = ((void *)0);
    return;
   }
   p->prev->next = p->next;
   p->next->prev = p->prev;
   p->next = h->head;
   h->head->prev = p;
   h->head = p;
   h->head->prev = ((void *)0);
   return;
  }
  p = p->next;
 }
}

variable_types: data int


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

v1 = *a1;
while ( v1 )
{
free(*(void **)v1);
free(*(void **)(v1 + 8));
v2 = (void *)v1;
v1 = *(_QWORD *)(v1 + 24);
free(v2);
}
}

original_code:
void destroy_link(db_link_t *h)
{
 link_t *p = h->head;
 while (((void *)0) != p) {
  link_t *pCur = p;
  free(pCur->key);
  free(pCur->data);
  p = p->next;
  free(pCur);
 }
}

canonical_original_code:
void destroy_link(struct db_link_s *h)
{
 struct link_s *p = h->head;
 while (((void *)0) != p) {
  struct link_s *pCur = p;
  free(pCur->key);
  free(pCur->data);
  p = p->next;
  free(pCur);
 }
}


repo: ljr-ifsp/simos

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

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( **(_DWORD **)result == a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( **(_DWORD **)result == a2 )
break;
}
return result;
}

original_code:
simos_list_node_t *get_elem(simos_list_t *l, int d)
{
 simos_list_node_t *n;
 for ((n) = ((l)->head); (n); (n) = ((n)->next)) {
  if (d == *((int *) (n->data))) {
   return n;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct simos_list_node *get_elem(struct simos_list *l, int d)
{
 struct simos_list_node *n;
 for ((n) = ((l)->head); (n); (n) = ((n)->next)) {
  if (d == *((int *) (n->data))) {
   return n;
  }
 }
 return ((void *)0);
}

variable_types: struct simos_list { struct simos_list_node *head; struct simos_list_node *tail; } *

variable_types: d int

variable_types: struct simos_list_node { void *data; struct simos_list_node *next; struct simos_list_node *prev; } *


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

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

original_code:
int get_data(simos_list_node_t *n)
{
 return *((int *) n->data);
}

canonical_original_code:
int get_data(struct simos_list_node *n)
{
 return *((int *) n->data);
}

user_defined_types: struct simos_list_node { void *data; struct simos_list_node *next; struct simos_list_node *prev; }


decompiled_code:
_BOOL8 __fastcall simos_list_empty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int simos_list_empty(simos_list_t *list)
{
 return list->head == ((void *)0);
}

canonical_original_code:
int simos_list_empty(struct simos_list *list)
{
 return list->head == ((void *)0);
}

variable_types: struct simos_list { struct simos_list_node { void *data; struct simos_list_node *next; struct simos_list_node *prev; } *head; struct simos_list_node *tail; } *

user_defined_types: struct simos_list { struct simos_list_node *head; struct simos_list_node *tail; }


decompiled_code:
_QWORD *simos_list_new()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func11()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
simos_list_t *simos_list_new()
{
 simos_list_t *l = malloc(sizeof(simos_list_t));
 l->head = ((void *)0);
 l->tail = ((void *)0);
 return l;
}

canonical_original_code:
struct simos_list *simos_list_new()
{
 struct simos_list *l = malloc(sizeof(simos_list_t));
 l->head = ((void *)0);
 l->tail = ((void *)0);
 return l;
}

return_type: struct simos_list { struct simos_list_node { void *data; struct simos_list_node *next; struct simos_list_node *prev; } *head; struct simos_list_node *tail; } *


decompiled_code:
__int64 __fastcall simos_list_del_head(_QWORD *a1)
{
__int64 v1; // r8
__int64 v2; // rax
__int64 result; // rax

if ( simos_list_empty(a1) )
return 0LL;
if ( a1[1] == v1 )
{
*a1 = 0LL;
result = v1;
a1[1] = 0LL;
}
else
{
v2 = *(_QWORD *)(v1 + 8);
*(_QWORD *)(v2 + 16) = 0LL;
*a1 = v2;
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
__int64 v1; // r8
__int64 v2; // rax
__int64 result; // rax

if ( func10(a1) )
return 0LL;
if ( a1[1] == v1 )
{
*a1 = 0LL;
result = v1;
a1[1] = 0LL;
}
else
{
v2 = *(_QWORD *)(v1 + 8);
*(_QWORD *)(v2 + 16) = 0LL;
*a1 = v2;
result = v1;
}
return result;
}

original_code:
simos_list_node_t *simos_list_del_head(simos_list_t *list)
{
 simos_list_node_t *n = list->head;
 if (simos_list_empty(list)) {
  return ((void *)0);
 }
 if (list->head == list->tail) {
  list->head = ((void *)0);
  list->tail = ((void *)0);
 } else {
  list->head->next->prev = ((void *)0);
  list->head = list->head->next;
 }
 return n;
}

canonical_original_code:
struct simos_list_node *simos_list_del_head(struct simos_list *list)
{
 struct simos_list_node *n = list->head;
 if (simos_list_empty(list)) {
  return ((void *)0);
 }
 if (list->head == list->tail) {
  list->head = ((void *)0);
  list->tail = ((void *)0);
 } else {
  list->head->next->prev = ((void *)0);
  list->head = list->head->next;
 }
 return n;
}

return_type: struct simos_list_node { void *data; struct simos_list_node *next; struct simos_list_node *prev; } *


decompiled_code:
__int64 __fastcall simos_list_del_tail(_QWORD *a1)
{
__int64 v1; // r8
__int64 v2; // rax
__int64 result; // rax

if ( simos_list_empty(a1) )
return 0LL;
if ( *a1 == v1 )
{
*a1 = 0LL;
result = v1;
a1[1] = 0LL;
}
else
{
v2 = *(_QWORD *)(v1 + 16);
*(_QWORD *)(v2 + 8) = 0LL;
a1[1] = v2;
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1)
{
__int64 v1; // r8
__int64 v2; // rax
__int64 result; // rax

if ( func10(a1) )
return 0LL;
if ( *a1 == v1 )
{
*a1 = 0LL;
result = v1;
a1[1] = 0LL;
}
else
{
v2 = *(_QWORD *)(v1 + 16);
*(_QWORD *)(v2 + 8) = 0LL;
a1[1] = v2;
result = v1;
}
return result;
}

original_code:
simos_list_node_t *simos_list_del_tail(simos_list_t *list)
{
 simos_list_node_t *n = list->tail;
 if (simos_list_empty(list)) {
  return ((void *)0);
 }
 if (list->head == list->tail) {
  list->head = ((void *)0);
  list->tail = ((void *)0);
 } else {
  list->tail->prev->next = ((void *)0);
  list->tail = list->tail->prev;
 }
 return n;
}

canonical_original_code:
struct simos_list_node *simos_list_del_tail(struct simos_list *list)
{
 struct simos_list_node *n = list->tail;
 if (simos_list_empty(list)) {
  return ((void *)0);
 }
 if (list->head == list->tail) {
  list->head = ((void *)0);
  list->tail = ((void *)0);
 } else {
  list->tail->prev->next = ((void *)0);
  list->tail = list->tail->prev;
 }
 return n;
}


original_code:
int simos_list_del(simos_list_t *list, simos_list_node_t *node)
{
 simos_list_node_t *n;
 if (simos_list_empty(list)) {
  return 0;
 }
 for ((n) = ((list)->head); (n); (n) = ((n)->next)) {
  if (n->next == node->next && n->prev == node->prev) {
   if (n == list->head) {
    simos_list_del_head(list);
   } else if (n == list->tail) {
    simos_list_del_tail(list);
   } else {
    n->prev->next = n->next;
    n->next->prev = n->prev;
   }
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int simos_list_del(struct simos_list *list, struct simos_list_node *node)
{
 struct simos_list_node *n;
 if (simos_list_empty(list)) {
  return 0;
 }
 for ((n) = ((list)->head); (n); (n) = ((n)->next)) {
  if (n->next == node->next && n->prev == node->prev) {
   if (n == list->head) {
    simos_list_del_head(list);
   } else if (n == list->tail) {
    simos_list_del_tail(list);
   } else {
    n->prev->next = n->next;
    n->next->prev = n->prev;
   }
   return 1;
  }
 }
 return 0;
}

variable_types:
node
struct simos_list_node *


decompiled_code:
void __fastcall simos_list_free(__int64 *a1)
{
__int64 i; // rbx

for ( i = *a1; i; i = *(_QWORD *)(i + 8) )
{
free(*(void **)i);
free((void *)i);
}
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void simos_list_free(simos_list_t *list)
{
 simos_list_node_t *n;
 for ((n) = ((list)->head); (n); (n) = ((n)->next)) {
  free(n->data);
  free(n);
 }
 list->head = ((void *)0);
 list->tail = ((void *)0);
}

canonical_original_code:
void simos_list_free(struct simos_list *list)
{
 struct simos_list_node *n;
 for ((n) = ((list)->head); (n); (n) = ((n)->next)) {
  free(n->data);
  free(n);
 }
 list->head = ((void *)0);
 list->tail = ((void *)0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
unsigned int v9; // eax
__int64 v10; // rdi
unsigned int v11; // eax
__int64 v12; // rdi
unsigned int v13; // eax
__int64 v14; // rax
__int64 v15; // r12
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v20; // eax
unsigned int v21; // eax
unsigned int v22; // eax
unsigned int v23; // eax
unsigned int v24; // eax

v3 = simos_list_new(argc, argv, envp);
v4 = new_node(1LL);
simos_list_add(v3, v4);
v5 = new_node(2LL);
simos_list_add(v3, v5);
v6 = new_node(3LL);
simos_list_add(v3, v6);
v7 = new_node(4LL);
simos_list_add(v3, v7);
v8 = get_elem(v3, 2LL);
v9 = get_data(v8);
printf("%d\n", v9);
print_list(v3);
v10 = get_elem(v3, 2LL);
if ( (unsigned int)simos_list_del(v3, v10) )
{
v11 = get_data(v10);
printf("%d deleted.\n", v11);
}
else
{
v20 = get_data(v10);
printf("error deleting %d.\n", v20);
}
print_list(v3);
v12 = simos_list_del_head(v3);
if ( v12 )
{
v13 = get_data(v12);
printf("head %d deleted.\n", v13);
}
else
{
v23 = get_data(0LL);
printf("error deleting head %d.\n", v23);
}
print_list(v3);
v14 = simos_list_del_tail(v3);
v15 = v14;
if ( v14 )
{
v16 = get_data(v14);
printf("tail %d deleted.\n", v16);
}
else
{
v24 = get_data(0LL);
printf("error deleting tail %d.\n", v24);
}
print_list(v3);
if ( (unsigned int)simos_list_del(v3, v15) )
{
v17 = get_data(v15);
printf("%d deleted.\n", v17);
}
else
{
v22 = get_data(v15);
printf("error deleting %d.\n", v22);
}
print_list(v3);
if ( (unsigned int)simos_list_del(v3, v15) )
{
v18 = get_data(v15);
printf("%d deleted.\n", v18);
}
else
{
v21 = get_data(v15);
printf("error deleting %d.\n", v21);
}
print_list(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
unsigned int v9; // eax
__int64 v10; // rdi
unsigned int v11; // eax
__int64 v12; // rdi
unsigned int v13; // eax
__int64 v14; // rax
__int64 v15; // r12
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v20; // eax
unsigned int v21; // eax
unsigned int v22; // eax
unsigned int v23; // eax
unsigned int v24; // eax

v3 = func11(argc, argv, envp);
v4 = new_node(1LL);
func12(v3, v4);
v5 = new_node(2LL);
func12(v3, v5);
v6 = new_node(3LL);
func12(v3, v6);
v7 = new_node(4LL);
func12(v3, v7);
v8 = func7(v3, 2LL);
v9 = func8(v8);
printf("%d\n", v9);
func9(v3);
v10 = func7(v3, 2LL);
if ( (unsigned int)func15(v3, v10) )
{
v11 = func8(v10);
printf("%d deleted.\n", v11);
}
else
{
v20 = func8(v10);
printf("error deleting %d.\n", v20);
}
func9(v3);
v12 = func13(v3);
if ( v12 )
{
v13 = func8(v12);
printf("head %d deleted.\n", v13);
}
else
{
v23 = func8(0LL);
printf("error deleting head %d.\n", v23);
}
func9(v3);
v14 = func14(v3);
v15 = v14;
if ( v14 )
{
v16 = func8(v14);
printf("tail %d deleted.\n", v16);
}
else
{
v24 = func8(0LL);
printf("error deleting tail %d.\n", v24);
}
func9(v3);
if ( (unsigned int)func15(v3, v15) )
{
v17 = func8(v15);
printf("%d deleted.\n", v17);
}
else
{
v22 = func8(v15);
printf("error deleting %d.\n", v22);
}
func9(v3);
if ( (unsigned int)func15(v3, v15) )
{
v18 = func8(v15);
printf("%d deleted.\n", v18);
}
else
{
v21 = func8(v15);
printf("error deleting %d.\n", v21);
}
func9(v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 simos_list_t *l;
 simos_list_node_t *n;
 l = simos_list_new();
 simos_list_add(l, new_node(1));
 simos_list_add(l, new_node(2));
 simos_list_add(l, new_node(3));
 simos_list_add(l, new_node(4));
 n = get_elem(l, 2);
 printf("%d\n", get_data(n));
 print_list(l);
 n = get_elem(l, 2);
 if (simos_list_del(l, n)) {
  printf("%d deleted.\n", get_data(n));
 } else {
  printf("error deleting %d.\n", get_data(n));
 }
 print_list(l);
 if ((n = simos_list_del_head(l)) != ((void *)0)) {
  printf("head %d deleted.\n", get_data(n));
 } else {
  printf("error deleting head %d.\n", get_data(n));
 }
 print_list(l);
 if ((n = simos_list_del_tail(l)) != ((void *)0)) {
  printf("tail %d deleted.\n", get_data(n));
 } else {
  printf("error deleting tail %d.\n", get_data(n));
 }
 print_list(l);
 if (simos_list_del(l, n)) {
  printf("%d deleted.\n", get_data(n));
 } else {
  printf("error deleting %d.\n", get_data(n));
 }
 print_list(l);
 if (simos_list_del(l, n)) {
  printf("%d deleted.\n", get_data(n));
 } else {
  printf("error deleting %d.\n", get_data(n));
 }
 print_list(l);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct simos_list *l;
 struct simos_list_node *n;
 l = simos_list_new();
 simos_list_add(l, new_node(1));
 simos_list_add(l, new_node(2));
 simos_list_add(l, new_node(3));
 simos_list_add(l, new_node(4));
 n = get_elem(l, 2);
 printf("%d\n", get_data(n));
 print_list(l);
 n = get_elem(l, 2);
 if (simos_list_del(l, n)) {
  printf("%d deleted.\n", get_data(n));
 } else {
  printf("error deleting %d.\n", get_data(n));
 }
 print_list(l);
 if ((n = simos_list_del_head(l)) != ((void *)0)) {
  printf("head %d deleted.\n", get_data(n));
 } else {
  printf("error deleting head %d.\n", get_data(n));
 }
 print_list(l);
 if ((n = simos_list_del_tail(l)) != ((void *)0)) {
  printf("tail %d deleted.\n", get_data(n));
 } else {
  printf("error deleting tail %d.\n", get_data(n));
 }
 print_list(l);
 if (simos_list_del(l, n)) {
  printf("%d deleted.\n", get_data(n));
 } else {
  printf("error deleting %d.\n", get_data(n));
 }
 print_list(l);
 if (simos_list_del(l, n)) {
  printf("%d deleted.\n", get_data(n));
 } else {
  printf("error deleting %d.\n", get_data(n));
 }
 print_list(l);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall print_list(unsigned int ***a1)
{
unsigned int **i; // rbx

printf("[LIST]: ");
for ( i = *a1; i; i = (unsigned int **)i[1] )
printf("%d ", **i);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int ***a1)
{
unsigned int **i; // rbx

printf("[LIST]: ");
for ( i = *a1; i; i = (unsigned int **)i[1] )
printf("%d ", **i);
return putchar(10);
}

original_code:
void print_list(simos_list_t *list)
{
 simos_list_node_t *n;
 printf("[LIST]: ");
 for ((n) = ((list)->head); (n); (n) = ((n)->next)) {
  printf("%d ", *((int *) n->data));
 }
 printf("\n");
}

canonical_original_code:
void print_list(struct simos_list *list)
{
 struct simos_list_node *n;
 printf("[LIST]: ");
 for ((n) = ((list)->head); (n); (n) = ((n)->next)) {
  printf("%d ", *((int *) n->data));
 }
 printf("\n");
}


decompiled_code:
// attributes: thunk
void simos_process_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func7(void *ptr)
{
free(ptr);
}

original_code:
void simos_process_destroy(simos_process_t *proc)
{
 free(proc);
}

canonical_original_code:
void simos_process_destroy(struct simos_process_t *proc)
{
 free(proc);
}

variable_types: struct simos_process_t { int pid; unsigned long required_execution_time; unsigned long turnaround_time; unsigned long required_memory; unsigned long memory_pointer; unsigned long entry_time; unsigned long out_time; } *


decompiled_code:
__int64 __fastcall simos_node_to_process(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
simos_process_t *simos_node_to_process(simos_list_node_t *node)
{
 return ((simos_process_t *) node->data);
}

canonical_original_code:
struct simos_process_t *simos_node_to_process(struct simos_list_node *node)
{
 return ((struct simos_process_t *) node->data);
}

return_type: struct simos_process_t { int pid; unsigned long required_execution_time; unsigned long turnaround_time; unsigned long required_memory; unsigned long memory_pointer; unsigned long entry_time; unsigned long out_time; } *


decompiled_code:
__int64 __fastcall simos_add_process(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er8

v2 = simos_memory_alloc(*(_QWORD *)(a1 + 8), *(_QWORD *)(a2 + 24));
v5 = 0;
if ( v2 != -1 )
{
*(_QWORD *)(a2 + 32) = v2;
simos_process_list_add(**(_QWORD **)a1, a2, v3, v4, 0LL);
v5 = 1;
}
return v5;
}

original_code:
int simos_add_process(simos_t *simos, simos_process_t *proc)
{
 size_t pointer = simos_memory_alloc(simos->mem, proc->required_memory);
 if (pointer == -1) {
  return 0;
 }
 proc->memory_pointer = pointer;
 simos_process_list_add(simos->sched->ready, proc);
 return 1;
}

canonical_original_code:
int simos_add_process(struct simos_t *simos, struct simos_process_t *proc)
{
 unsigned long pointer = simos_memory_alloc(simos->mem, proc->required_memory);
 if (pointer == -1) {
  return 0;
 }
 proc->memory_pointer = pointer;
 simos_process_list_add(simos->sched->ready, proc);
 return 1;
}

variable_types: struct simos_t { struct simos_scheduler_t { struct simos_list { struct simos_list_node { void *data; struct simos_list_node *next; struct simos_list_node *prev; } *head; struct simos_list_node *tail; } *ready; } *sched; struct simos_memory_t { unsigned long size; unsigned char *cells; } *mem; } *

variable_types:
pointer
unsigned long

user_defined_types: struct simos_t { struct simos_scheduler_t *sched; struct simos_memory_t *mem; }

user_defined_types: struct simos_process_t { int pid; unsigned long required_execution_time; unsigned long turnaround_time; unsigned long required_memory; unsigned long memory_pointer; unsigned long entry_time; unsigned long out_time; }

user_defined_types: struct simos_scheduler_t { struct simos_list *ready; }