decompiled_code:
__int64 __fastcall stride_scheduling(int a1)
{
float v1; // xmm0_4
float *v2; // rcx
float *v3; // r10
float v4; // xmm1_4
int v5; // esi
double v6; // xmm3_8
int v7; // ebp
unsigned int v8; // er12
const char *v9; // rsi
__int64 result; // rax
int v11; // edx
__int64 v12; // rbx
int v13; // er14
float v14; // xmm2_4
float *v15; // rax
float v16; // xmm0_4
__int64 v17; // rbx
FILE *v18; // rcx
float v19; // xmm1_4
float *v20; // rbx
float v21; // xmm1_4
bool v22; // cf
float v23; // xmm0_4
FILE *v24; // rdi
float v25; // xmm3_4
float v26; // [rsp+Ch] [rbp-5Ch]
float v27; // [rsp+10h] [rbp-58h]
float i; // [rsp+20h] [rbp-48h]
int v30; // [rsp+24h] [rbp-44h]
float v31; // [rsp+28h] [rbp-40h]
float v32; // [rsp+2Ch] [rbp-3Ch]

if ( num_tasks <= 0 )
{
v6 = 0.0;
v1 = 0.0;
}
else
{
v1 = 0.0;
v2 = (float *)((char *)tasks + 8);
v3 = (float *)((char *)tasks + 36 * (unsigned int)(num_tasks - 1) + 44);
do
{
v4 = (float)(11 - *(_DWORD *)v2);
v5 = 4 - *(_DWORD *)v2;
v2[5] = 0.0;
v2 += 9;
v1 = v1 + v4;
*(v2 - 5) = (float)(1 / v5);
}
while ( v3 != v2 );
v6 = v1;
}
v7 = -1;
v8 = 1;
fprintf(stderr, "Bribes: %4.2f, Rate: %4.2f\n", v6, (float)(1.0 / v1));
v30 = 0;
v31 = (float)a1;
v32 = (float)(1.0 / v1) * (float)a1;
for ( i = v32; ; i = i + v32 )
{
v9 = "Processing tick %d\n";
fprintf(stderr, "Processing tick %d\n", v8);
result = (unsigned int)num_tasks;
v27 = v31;
v11 = num_tasks;
while ( v27 > 0.0 )
{
if ( v11 <= 0 )
goto LABEL_31;
v12 = 0LL;
v13 = -1;
v14 = (float)(int)(v8 + a1) - v27;
do
{
v15 = (float *)((char *)tasks + 36 * v12);
v16 = (float)*(int *)v15;
if ( v15[5] < v15[1] )
{
LOBYTE(v9) = v14 < v16;
if ( v14 >= v16 )
{
LOBYTE(v11) = 1;
if ( v15[7] != 0.0 )
v11 = (int)v9;
if ( (_BYTE)v11 )
{
LOBYTE(v11) = 1;
if ( v16 == v14 )
LODWORD(v9) = v11;
if ( (_BYTE)v9 )
{
v23 = i + v15[6];
v9 = "Task[%d] arrived and got a meter of %4.2f\n";
v24 = stderr;
v15[7] = v23;
fprintf(v24, "Task[%d] arrived and got a meter of %4.2f\n", (unsigned int)v12, v23);
}
}
if ( v13 == -1 || (v11 = num_tasks, *((float *)tasks + 9 * v13 + 7) > *((float *)tasks + 9 * v12 + 7)) )
{
v13 = v12;
v9 = "Setting target to %d\n";
fprintf(stderr, "Setting target to %d\n", (unsigned int)v12);
v11 = num_tasks;
}
}
}
++v12;
result = (unsigned int)v11;
}
while ( v11 > (int)v12 );
if ( v13 == -1 )
{
LABEL_31:
v25 = v27 - 0.1;
v27 = v25;
}
else
{
v17 = 36LL * v13;
if ( v13 != v7 )
{
v18 = stderr;
++*(_DWORD *)((char *)tasks + v17 + 16);
fwrite(" This is a new scheduling\n!", 1uLL, 0x1FuLL, v18);
}
fprintf(stderr, " Task is %d, priority %d\n", (unsigned int)v13, *(unsigned int *)((char *)tasks + v17 + 8));
v9 = " Consuming %4.2f, has %4.2f\n";
v19 = *(float *)((char *)tasks + v17 + 20);
v26 = fminf(v27, *(float *)((char *)tasks + v17 + 4) - v19);
fprintf(stderr, " Consuming %4.2f, has %4.2f\n", v26, v19);
v20 = (float *)((char *)tasks + v17);
v21 = v20[5] + v26;
v22 = v21 < v20[1];
v20[7] = v20[7] + v20[6];
v20[5] = v21;
v27 = v27 - v26;
if ( !v22 )
{
++v30;
v20[3] = (float)(int)(v8 + a1) - v27;
}
v11 = num_tasks;
v7 = v13;
result = (unsigned int)num_tasks;
}
}
if ( v30 >= (int)result )
break;
v8 += a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
float v1; // xmm0_4
float *v2; // rcx
float *v3; // r10
float v4; // xmm1_4
int v5; // esi
double v6; // xmm3_8
int v7; // ebp
unsigned int v8; // er12
const char *v9; // rsi
__int64 result; // rax
int v11; // edx
__int64 v12; // rbx
int v13; // er14
float v14; // xmm2_4
float *v15; // rax
float v16; // xmm0_4
__int64 v17; // rbx
FILE *v18; // rcx
float v19; // xmm1_4
float *v20; // rbx
float v21; // xmm1_4
bool v22; // cf
float v23; // xmm0_4
FILE *v24; // rdi
float v25; // xmm3_4
float v26; // [rsp+Ch] [rbp-5Ch]
float v27; // [rsp+10h] [rbp-58h]
float i; // [rsp+20h] [rbp-48h]
int v30; // [rsp+24h] [rbp-44h]
float v31; // [rsp+28h] [rbp-40h]
float v32; // [rsp+2Ch] [rbp-3Ch]

if ( num_tasks <= 0 )
{
v6 = 0.0;
v1 = 0.0;
}
else
{
v1 = 0.0;
v2 = (float *)((char *)tasks + 8);
v3 = (float *)((char *)tasks + 36 * (unsigned int)(num_tasks - 1) + 44);
do
{
v4 = (float)(11 - *(_DWORD *)v2);
v5 = 4 - *(_DWORD *)v2;
v2[5] = 0.0;
v2 += 9;
v1 = v1 + v4;
*(v2 - 5) = (float)(1 / v5);
}
while ( v3 != v2 );
v6 = v1;
}
v7 = -1;
v8 = 1;
fprintf(stderr, "Bribes: %4.2f, Rate: %4.2f\n", v6, (float)(1.0 / v1));
v30 = 0;
v31 = (float)a1;
v32 = (float)(1.0 / v1) * (float)a1;
for ( i = v32; ; i = i + v32 )
{
v9 = "Processing tick %d\n";
fprintf(stderr, "Processing tick %d\n", v8);
result = (unsigned int)num_tasks;
v27 = v31;
v11 = num_tasks;
while ( v27 > 0.0 )
{
if ( v11 <= 0 )
goto LABEL_31;
v12 = 0LL;
v13 = -1;
v14 = (float)(int)(v8 + a1) - v27;
do
{
v15 = (float *)((char *)tasks + 36 * v12);
v16 = (float)*(int *)v15;
if ( v15[5] < v15[1] )
{
LOBYTE(v9) = v14 < v16;
if ( v14 >= v16 )
{
LOBYTE(v11) = 1;
if ( v15[7] != 0.0 )
v11 = (int)v9;
if ( (_BYTE)v11 )
{
LOBYTE(v11) = 1;
if ( v16 == v14 )
LODWORD(v9) = v11;
if ( (_BYTE)v9 )
{
v23 = i + v15[6];
v9 = "Task[%d] arrived and got a meter of %4.2f\n";
v24 = stderr;
v15[7] = v23;
fprintf(v24, "Task[%d] arrived and got a meter of %4.2f\n", (unsigned int)v12, v23);
}
}
if ( v13 == -1 || (v11 = num_tasks, *((float *)tasks + 9 * v13 + 7) > *((float *)tasks + 9 * v12 + 7)) )
{
v13 = v12;
v9 = "Setting target to %d\n";
fprintf(stderr, "Setting target to %d\n", (unsigned int)v12);
v11 = num_tasks;
}
}
}
++v12;
result = (unsigned int)v11;
}
while ( v11 > (int)v12 );
if ( v13 == -1 )
{
LABEL_31:
v25 = v27 - 0.1;
v27 = v25;
}
else
{
v17 = 36LL * v13;
if ( v13 != v7 )
{
v18 = stderr;
++*(_DWORD *)((char *)tasks + v17 + 16);
fwrite(" This is a new scheduling\n!", 1uLL, 0x1FuLL, v18);
}
fprintf(stderr, " Task is %d, priority %d\n", (unsigned int)v13, *(unsigned int *)((char *)tasks + v17 + 8));
v9 = " Consuming %4.2f, has %4.2f\n";
v19 = *(float *)((char *)tasks + v17 + 20);
v26 = fminf(v27, *(float *)((char *)tasks + v17 + 4) - v19);
fprintf(stderr, " Consuming %4.2f, has %4.2f\n", v26, v19);
v20 = (float *)((char *)tasks + v17);
v21 = v20[5] + v26;
v22 = v21 < v20[1];
v20[7] = v20[7] + v20[6];
v20[5] = v21;
v27 = v27 - v26;
if ( !v22 )
{
++v30;
v20[3] = (float)(int)(v8 + a1) - v27;
}
v11 = num_tasks;
v7 = v13;
result = (unsigned int)num_tasks;
}
}
if ( v30 >= (int)result )
break;
v8 += a1;
}
return result;
}

original_code:
void stride_scheduling(int quantum)
{
  int done_tasks = 0;
  int current_tick = 1;
  float total_bribes = 0;
  for (int i=0; i < num_tasks; i++) {
    total_bribes += 11 - tasks[i].priority;
    tasks[i].meter_rate = 1 / (4 - tasks[i].priority);
    tasks[i].metered_time = 0;
  }
  float total_rate = 1 / total_bribes;
  fprintf(stderr, "Bribes: %4.2f, Rate: %4.2f\n", total_bribes, total_rate);
  float total_meter = total_rate * quantum;
  int last_task = -1;
  for (;;) {
    fprintf(stderr, "Processing tick %d\n", current_tick);
    float tick_left = quantum;
    while (tick_left > 0.0) {
      int target_task = -1;
      for (int i = 0; i < num_tasks; i++) {
        int arrived = (tasks[i].arrival_time <= current_tick + quantum - tick_left);
        int done = tasks[i].cpu_cycles >= tasks[i].length;
        if (!arrived || done) {
          continue;
        }
        if (arrived && tasks[i].metered_time == 0 && tasks[i].arrival_time == current_tick + quantum - tick_left) {
          tasks[i].metered_time = total_meter + tasks[i].meter_rate;
          fprintf(stderr, "Task[%d] arrived and got a meter of %4.2f\n", i, tasks[i].metered_time);
        }
        if (target_task == -1 || tasks[target_task].metered_time > tasks[i].metered_time) {
          fprintf(stderr, "Setting target to %d\n", i);
          target_task = i;
        }
      }
      if (target_task == -1) { tick_left -= 0.1; continue; } else if (target_task != last_task) {
        tasks[target_task].schedulings++;
        last_task = target_task;
        fprintf(stderr, "     This is a new scheduling\n!");
      }
      fprintf(stderr, " Task is %d, priority %d\n", target_task, tasks[target_task].priority);
      float desired_time = tasks[target_task].length - tasks[target_task].cpu_cycles;
      if (desired_time > tick_left) {
        desired_time = tick_left;
      }
      fprintf(stderr, "   Consuming %4.2f, has %4.2f\n", desired_time, tasks[target_task].cpu_cycles);
      tasks[target_task].cpu_cycles += desired_time;
      tick_left -= desired_time;
      tasks[target_task].metered_time += tasks[target_task].meter_rate;
      if (tasks[target_task].cpu_cycles >= tasks[target_task].length) {
        done_tasks++;
        tasks[target_task].finish_time = current_tick + quantum - tick_left;
      }
    }
    if (done_tasks >= num_tasks) {
      break;
    }
    current_tick += quantum;
    total_meter += (total_rate * quantum);
  }
}

canonical_original_code:
void stride_scheduling(int quantum)
{
  int done_tasks = 0;
  int current_tick = 1;
  float total_bribes = 0;
  for (int i = 0; i < num_tasks; i++) {
    total_bribes += 11 - tasks[i].priority;
    tasks[i].meter_rate = 1 / (4 - tasks[i].priority);
    tasks[i].metered_time = 0;
  }
  float total_rate = 1 / total_bribes;
  fprintf(stderr, "Bribes: %4.2f, Rate: %4.2f\n", total_bribes, total_rate);
  float total_meter = total_rate * quantum;
  int last_task = -1;
  for (;;) {
    fprintf(stderr, "Processing tick %d\n", current_tick);
    float tick_left = quantum;
    while (tick_left > 0.0) {
      int target_task = -1;
      for (int i = 0; i < num_tasks; i++) {
        int arrived = (tasks[i].arrival_time <= current_tick + quantum - tick_left);
        int done = tasks[i].cpu_cycles >= tasks[i].length;
        if (!arrived || done) {
          continue;
        }
        if (arrived && tasks[i].metered_time == 0 && tasks[i].arrival_time == current_tick + quantum - tick_left) {
          tasks[i].metered_time = total_meter + tasks[i].meter_rate;
          fprintf(stderr, "Task[%d] arrived and got a meter of %4.2f\n", i, tasks[i].metered_time);
        }
        if (target_task == -1 || tasks[target_task].metered_time > tasks[i].metered_time) {
          fprintf(stderr, "Setting target to %d\n", i);
          target_task = i;
        }
      }
      if (target_task == -1) { tick_left -= 0.1; continue; } else if (target_task != last_task) {
        tasks[target_task].schedulings++;
        last_task = target_task;
        fprintf(stderr, "     This is a new scheduling\n!");
      }
      fprintf(stderr, " Task is %d, priority %d\n", target_task, tasks[target_task].priority);
      float desired_time = tasks[target_task].length - tasks[target_task].cpu_cycles;
      if (desired_time > tick_left) {
        desired_time = tick_left;
      }
      fprintf(stderr, "   Consuming %4.2f, has %4.2f\n", desired_time, tasks[target_task].cpu_cycles);
      tasks[target_task].cpu_cycles += desired_time;
      tick_left -= desired_time;
      tasks[target_task].metered_time += tasks[target_task].meter_rate;
      if (tasks[target_task].cpu_cycles >= tasks[target_task].length) {
        done_tasks++;
        tasks[target_task].finish_time = current_tick + quantum - tick_left;
      }
    }
    if (done_tasks >= num_tasks) {
      break;
    }
    current_tick += quantum;
    total_meter += (total_rate * quantum);
  }
}

variable_types: quantum int

variable_types: arrived int

variable_types: done int


decompiled_code:
int priority_scheduling()
{
int v0; // er14
int v1; // er12
int v2; // ebp
float *v3; // rax
int v4; // esi
float v5; // xmm2_4
int v6; // ebx
int v7; // edi
unsigned int v8; // er15
char *v9; // rax
unsigned __int8 v10; // al
__int64 v11; // rbx
FILE *v12; // rdi
float v13; // xmm1_4
float v14; // xmm0_4
float v15; // xmm3_4
float v16; // xmm0_4
float v17; // xmm0_4
float v18; // xmm0_4

v0 = 2;
v1 = 0;
v2 = -1;
LABEL_2:
LODWORD(v3) = fprintf(stderr, "Processing tick %d\n", (unsigned int)(v0 - 1));
v4 = num_tasks;
if ( num_tasks > v1 )
{
v5 = *(float *)&LC6;
while ( 1 )
{
v6 = 0;
v7 = 0;
v8 = 0;
while ( v4 > v6 )
{
v9 = (char *)tasks + 36 * v6;
if ( (float)((float)v0 - v5) >= (float)*(int *)v9 && *((float *)v9 + 5) < *((float *)v9 + 1) )
{
if ( *((_DWORD *)v9 + 2) <= *((_DWORD *)tasks + 9 * (int)v8 + 2) || (v10 = v7, v7 = 1, v10 ^ 1) )
{
v8 = v6;
fprintf(stderr, " Setting %d to active task\n", (unsigned int)v6);
v4 = num_tasks;
v7 = 1;
}
}
++v6;
}
if ( !v7 )
{
LODWORD(v3) = fwrite(" Found nothing...\n", 1uLL, 0x12uLL, stderr);
++v0;
if ( v1 != num_tasks )
goto LABEL_2;
return (int)v3;
}
fprintf(stderr, " %d is consuming tick %4.2f is left.\n", v8, v5);
v11 = 36LL * (int)v8;
if ( v8 != v2 )
{
v12 = stderr;
++*(_DWORD *)((char *)tasks + v11 + 16);
fprintf(v12, " Increasing the number of scheddulings for %d\n", v8);
}
v3 = (float *)((char *)tasks + v11);
v13 = *(float *)((char *)tasks + v11 + 4);
v14 = *(float *)((char *)tasks + v11 + 20);
v15 = v13 - v14;
if ( (float)(v13 - v14) < 1.0 )
{
v17 = v14 + v15;
v5 = v5 - v15;
v3[5] = v17;
if ( v17 >= v13 )
{
LABEL_21:
++v1;
fprintf(stderr, " !!Task %d is done at %4.2f\n", v8, (float)((float)v0 - v5));
LODWORD(v3) = (_DWORD)tasks;
v18 = (double)(v0 - 1) + 1.0 - v5;
*(float *)((char *)tasks + v11 + 12) = v18;
goto LABEL_16;
}
}
else
{
v16 = v14 + 1.0;
v5 = 0.0;
v3[5] = v16;
if ( v16 >= v13 )
goto LABEL_21;
}
LABEL_16:
v4 = num_tasks;
v2 = v8;
if ( v5 == 0.0 )
{
++v0;
if ( v1 != num_tasks )
goto LABEL_2;
return (int)v3;
}
}
}
return (int)v3;
}

canonical_decompiled_code:
int func4()
{
int v0; // er14
int v1; // er12
int v2; // ebp
float *v3; // rax
int v4; // esi
float v5; // xmm2_4
int v6; // ebx
int v7; // edi
unsigned int v8; // er15
char *v9; // rax
unsigned __int8 v10; // al
__int64 v11; // rbx
FILE *v12; // rdi
float v13; // xmm1_4
float v14; // xmm0_4
float v15; // xmm3_4
float v16; // xmm0_4
float v17; // xmm0_4
float v18; // xmm0_4

v0 = 2;
v1 = 0;
v2 = -1;
LABEL_2:
LODWORD(v3) = fprintf(stderr, "Processing tick %d\n", (unsigned int)(v0 - 1));
v4 = num_tasks;
if ( num_tasks > v1 )
{
v5 = *(float *)&LC6;
while ( 1 )
{
v6 = 0;
v7 = 0;
v8 = 0;
while ( v4 > v6 )
{
v9 = (char *)tasks + 36 * v6;
if ( (float)((float)v0 - v5) >= (float)*(int *)v9 && *((float *)v9 + 5) < *((float *)v9 + 1) )
{
if ( *((_DWORD *)v9 + 2) <= *((_DWORD *)tasks + 9 * (int)v8 + 2) || (v10 = v7, v7 = 1, v10 ^ 1) )
{
v8 = v6;
fprintf(stderr, " Setting %d to active task\n", (unsigned int)v6);
v4 = num_tasks;
v7 = 1;
}
}
++v6;
}
if ( !v7 )
{
LODWORD(v3) = fwrite(" Found nothing...\n", 1uLL, 0x12uLL, stderr);
++v0;
if ( v1 != num_tasks )
goto LABEL_2;
return (int)v3;
}
fprintf(stderr, " %d is consuming tick %4.2f is left.\n", v8, v5);
v11 = 36LL * (int)v8;
if ( v8 != v2 )
{
v12 = stderr;
++*(_DWORD *)((char *)tasks + v11 + 16);
fprintf(v12, " Increasing the number of scheddulings for %d\n", v8);
}
v3 = (float *)((char *)tasks + v11);
v13 = *(float *)((char *)tasks + v11 + 4);
v14 = *(float *)((char *)tasks + v11 + 20);
v15 = v13 - v14;
if ( (float)(v13 - v14) < 1.0 )
{
v17 = v14 + v15;
v5 = v5 - v15;
v3[5] = v17;
if ( v17 >= v13 )
{
LABEL_21:
++v1;
fprintf(stderr, " !!Task %d is done at %4.2f\n", v8, (float)((float)v0 - v5));
LODWORD(v3) = (_DWORD)tasks;
v18 = (double)(v0 - 1) + 1.0 - v5;
*(float *)((char *)tasks + v11 + 12) = v18;
goto LABEL_16;
}
}
else
{
v16 = v14 + 1.0;
v5 = 0.0;
v3[5] = v16;
if ( v16 >= v13 )
goto LABEL_21;
}
LABEL_16:
v4 = num_tasks;
v2 = v8;
if ( v5 == 0.0 )
{
++v0;
if ( v1 != num_tasks )
goto LABEL_2;
return (int)v3;
}
}
}
return (int)v3;
}

original_code:
void priority_scheduling()
{
  int current_tick = 0;
  int last_task = -1;
  int done_tasks = 0;
  for (;;) {
    current_tick++;
    fprintf(stderr, "Processing tick %d\n", current_tick);
    if (done_tasks >= num_tasks) {
      break;
    }
    float tick_left = 1.0;
    while (tick_left != 0.0) {
      int target_task = 0;
      int found = 0;
      for (int i=0; i < num_tasks; i++) {
        int arrived = (tasks[i].arrival_time <= current_tick + 1 - tick_left);
        int done = (tasks[i].cpu_cycles >= tasks[i].length);
        int higher_priority = (tasks[i].priority <= tasks[target_task].priority);
        if (arrived && !done && (higher_priority || !found)) {
          target_task = i;
          found = 1;
          fprintf(stderr, " Setting %d to active task\n", target_task);
        }
      }
      if (!found) { fprintf(stderr, " Found nothing...\n"); break; }
      fprintf(stderr, " %d is consuming tick %4.2f is left.\n", target_task, tick_left);
      if (target_task != last_task) {
        tasks[target_task].schedulings++;
        fprintf(stderr, "   Increasing the number of scheddulings for %d\n", target_task);
      }
      last_task = target_task;
      float desired_time = (tasks[target_task].length - tasks[target_task].cpu_cycles);
      if (desired_time >= 1.0) {
        tasks[target_task].cpu_cycles += 1.0;
        tick_left = 0.0;
      } else {
        tasks[target_task].cpu_cycles += desired_time;
        tick_left -= desired_time;
      }
      if (tasks[target_task].cpu_cycles >= tasks[target_task].length) {
        fprintf(stderr, "   !!Task %d is done at %4.2f\n", target_task, current_tick + 1 - tick_left);
        tasks[target_task].finish_time = current_tick + 1.0 - tick_left;
        done_tasks++;
      }
    }
    if (done_tasks == num_tasks) {
      break;
    }
  }
}

canonical_original_code:
void priority_scheduling()
{
  int current_tick = 0;
  int last_task = -1;
  int done_tasks = 0;
  for (;;) {
    current_tick++;
    fprintf(stderr, "Processing tick %d\n", current_tick);
    if (done_tasks >= num_tasks) {
      break;
    }
    float tick_left = 1.0;
    while (tick_left != 0.0) {
      int target_task = 0;
      int found = 0;
      for (int i = 0; i < num_tasks; i++) {
        int arrived = (tasks[i].arrival_time <= current_tick + 1 - tick_left);
        int done = (tasks[i].cpu_cycles >= tasks[i].length);
        int higher_priority = (tasks[i].priority <= tasks[target_task].priority);
        if (arrived && !done && (higher_priority || !found)) {
          target_task = i;
          found = 1;
          fprintf(stderr, " Setting %d to active task\n", target_task);
        }
      }
      if (!found) { fprintf(stderr, " Found nothing...\n"); break; }
      fprintf(stderr, " %d is consuming tick %4.2f is left.\n", target_task, tick_left);
      if (target_task != last_task) {
        tasks[target_task].schedulings++;
        fprintf(stderr, "   Increasing the number of scheddulings for %d\n", target_task);
      }
      last_task = target_task;
      float desired_time = (tasks[target_task].length - tasks[target_task].cpu_cycles);
      if (desired_time >= 1.0) {
        tasks[target_task].cpu_cycles += 1.0;
        tick_left = 0.0;
      } else {
        tasks[target_task].cpu_cycles += desired_time;
        tick_left -= desired_time;
      }
      if (tasks[target_task].cpu_cycles >= tasks[target_task].length) {
        fprintf(stderr, "   !!Task %d is done at %4.2f\n", target_task, current_tick + 1 - tick_left);
        tasks[target_task].finish_time = current_tick + 1.0 - tick_left;
        done_tasks++;
      }
    }
    if (done_tasks == num_tasks) {
      break;
    }
  }
}

variable_types: found int

variable_types: i int

return_type: void


decompiled_code:
int __fastcall rr_scheduling(int a1)
{
int v1; // er13
unsigned int v2; // er12
int v3; // ebp
float v4; // xmm3_4
int result; // eax
__int64 v6; // r14
int v7; // er9
int v8; // ecx
int v9; // edx
__int64 v10; // rbx
FILE *v11; // rcx
unsigned int v12; // er15
float v13; // xmm1_4
float *v14; // rbx
float v15; // xmm0_4
bool v16; // cf
FILE *v17; // rcx
float v18; // [rsp+0h] [rbp-5Ch]
float v19; // [rsp+4h] [rbp-58h]
__int64 v20[9]; // [rsp+14h] [rbp-48h]

v1 = 0;
v2 = -1;
v3 = 1;
v20[0] = 0LL;
v20[1] = 0LL;
v18 = (float)a1;
while ( 1 )
{
fprintf(stderr, "Processing tick %d\n", (unsigned int)v3);
v4 = (float)a1;
result = v3 + a1;
if ( v18 > 0.0 )
break;
LABEL_13:
if ( num_tasks <= v1 )
return result;
LABEL_14:
v3 += a1;
}
do
{
v6 = 0LL;
while ( 1 )
{
if ( num_tasks >= 0 )
{
v7 = *((_DWORD *)v20 + v6);
v8 = 0;
while ( 1 )
{
v9 = (v8 + v7) % num_tasks;
v10 = 36LL * v9;
if ( (float)((float)v3 - (float)(v18 - v4)) >= (float)*(int *)((char *)tasks + v10)
&& *(float *)((char *)tasks + v10 + 20) < *(float *)((char *)tasks + v10 + 4)
&& *(_DWORD *)((char *)tasks + v10 + 8) == (_DWORD)v6 )
{
break;
}
if ( num_tasks < ++v8 )
goto LABEL_9;
}
v12 = (v8 + v7) % num_tasks;
fprintf(stderr, " Found a task at priority %d, task is %d. Selecting...\n", (unsigned int)v6, (unsigned int)v9);
*((_DWORD *)v20 + v6) = v12;
if ( v12 != -1 )
break;
}
LABEL_9:
if ( ++v6 == 4 )
{
if ( v2 != -1 )
{
v11 = stderr;
++*((_DWORD *)tasks - 5);
fwrite(" This is a new scheduling.\n", 1uLL, 0x1CuLL, v11);
}
result = fprintf(stderr, " Task is %d\n", 0xFFFFFFFFLL);
goto LABEL_13;
}
}
if ( v12 == v2 )
{
fprintf(stderr, " Task is %d\n", v2);
}
else
{
v17 = stderr;
v2 = v12;
++*(_DWORD *)((char *)tasks + v10 + 16);
fwrite(" This is a new scheduling.\n", 1uLL, 0x1CuLL, v17);
fprintf(stderr, " Task is %d\n", v12);
}
v13 = *(float *)((char *)tasks + v10 + 20);
v19 = fminf(v4, *(float *)((char *)tasks + v10 + 4) - v13);
result = fprintf(stderr, " Consuming %4.2f, has %4.2f\n", v19, v13);
v14 = (float *)((char *)tasks + v10);
v15 = v14[5] + v19;
v16 = v15 < v14[1];
v4 = v4 - v19;
v14[5] = v15;
if ( !v16 )
{
++v1;
v14[3] = (float)(v3 + a1) - v4;
}
}
while ( v4 > 0.0 );
if ( num_tasks > v1 )
goto LABEL_14;
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int v1; // er13
unsigned int v2; // er12
int v3; // ebp
float v4; // xmm3_4
int result; // eax
__int64 v6; // r14
int v7; // er9
int v8; // ecx
int v9; // edx
__int64 v10; // rbx
FILE *v11; // rcx
unsigned int v12; // er15
float v13; // xmm1_4
float *v14; // rbx
float v15; // xmm0_4
bool v16; // cf
FILE *v17; // rcx
float v18; // [rsp+0h] [rbp-5Ch]
float v19; // [rsp+4h] [rbp-58h]
__int64 v20[9]; // [rsp+14h] [rbp-48h]

v1 = 0;
v2 = -1;
v3 = 1;
v20[0] = 0LL;
v20[1] = 0LL;
v18 = (float)a1;
while ( 1 )
{
fprintf(stderr, "Processing tick %d\n", (unsigned int)v3);
v4 = (float)a1;
result = v3 + a1;
if ( v18 > 0.0 )
break;
LABEL_13:
if ( num_tasks <= v1 )
return result;
LABEL_14:
v3 += a1;
}
do
{
v6 = 0LL;
while ( 1 )
{
if ( num_tasks >= 0 )
{
v7 = *((_DWORD *)v20 + v6);
v8 = 0;
while ( 1 )
{
v9 = (v8 + v7) % num_tasks;
v10 = 36LL * v9;
if ( (float)((float)v3 - (float)(v18 - v4)) >= (float)*(int *)((char *)tasks + v10)
&& *(float *)((char *)tasks + v10 + 20) < *(float *)((char *)tasks + v10 + 4)
&& *(_DWORD *)((char *)tasks + v10 + 8) == (_DWORD)v6 )
{
break;
}
if ( num_tasks < ++v8 )
goto LABEL_9;
}
v12 = (v8 + v7) % num_tasks;
fprintf(stderr, " Found a task at priority %d, task is %d. Selecting...\n", (unsigned int)v6, (unsigned int)v9);
*((_DWORD *)v20 + v6) = v12;
if ( v12 != -1 )
break;
}
LABEL_9:
if ( ++v6 == 4 )
{
if ( v2 != -1 )
{
v11 = stderr;
++*((_DWORD *)tasks - 5);
fwrite(" This is a new scheduling.\n", 1uLL, 0x1CuLL, v11);
}
result = fprintf(stderr, " Task is %d\n", 0xFFFFFFFFLL);
goto LABEL_13;
}
}
if ( v12 == v2 )
{
fprintf(stderr, " Task is %d\n", v2);
}
else
{
v17 = stderr;
v2 = v12;
++*(_DWORD *)((char *)tasks + v10 + 16);
fwrite(" This is a new scheduling.\n", 1uLL, 0x1CuLL, v17);
fprintf(stderr, " Task is %d\n", v12);
}
v13 = *(float *)((char *)tasks + v10 + 20);
v19 = fminf(v4, *(float *)((char *)tasks + v10 + 4) - v13);
result = fprintf(stderr, " Consuming %4.2f, has %4.2f\n", v19, v13);
v14 = (float *)((char *)tasks + v10);
v15 = v14[5] + v19;
v16 = v15 < v14[1];
v4 = v4 - v19;
v14[5] = v15;
if ( !v16 )
{
++v1;
v14[3] = (float)(v3 + a1) - v4;
}
}
while ( v4 > 0.0 );
if ( num_tasks > v1 )
goto LABEL_14;
return result;
}

original_code:
void rr_scheduling(int quantum)
{
  int done_tasks = 0;
  int current_tick = 1;
  int last_task = -1;
  int positions[4] = {0, 0, 0, 0};
  for (;;) {
    fprintf(stderr, "Processing tick %d\n", current_tick);
    float tick_left = quantum;
    int target_task = -1;
    while (tick_left > 0.0) {
      int i;
      target_task = -1;
      for (i=0; i<4; i++) {
        int step = 0;
        while (step <= num_tasks) {
          int this_spot = (positions[i] + step) % num_tasks;
          int arrived = (tasks[this_spot].arrival_time <= current_tick - (quantum - tick_left));
          int done = tasks[this_spot].cpu_cycles >= tasks[this_spot].length;
          int is_this_priority = tasks[this_spot].priority == i;
          if (arrived && !done && is_this_priority) {
            fprintf(stderr, "  Found a task at priority %d, task is %d. Selecting...\n", i, this_spot);
            target_task = this_spot;
            positions[i] = target_task;
            break;
          }
          step++;
        }
        if (target_task != -1) {
          break;
        }
      }
      if (target_task != last_task) {
        tasks[target_task].schedulings++;
        fprintf(stderr, "  This is a new scheduling.\n");
      }
      fprintf(stderr, " Task is %d\n", target_task);
      if (target_task == -1) { break; }
      float desired_time = tasks[target_task].length - tasks[target_task].cpu_cycles;
      if (desired_time > tick_left) {
        desired_time = tick_left;
      }
      fprintf(stderr, "   Consuming %4.2f, has %4.2f\n", desired_time, tasks[target_task].cpu_cycles);
      tasks[target_task].cpu_cycles += desired_time;
      tick_left -= desired_time;
      if (tasks[target_task].cpu_cycles >= tasks[target_task].length) {
        done_tasks++;
        tasks[target_task].finish_time = current_tick + quantum - tick_left;
      }
      last_task = target_task;
    }
    if (done_tasks >= num_tasks) {
      break;
    }
    current_tick += quantum;
  }
}

variable_types:
positions
int [4]

variable_types: step int


decompiled_code:
void __fastcall run_simulation(int a1, int a2)
{
switch ( a1 )
{
case 2:
rr_scheduling(a2);
break;
case 3:
stride_scheduling(a2);
break;
case 1:
priority_scheduling();
break;
default:
first_come_first_serve();
break;
}
}

canonical_decompiled_code:
void __fastcall func6(int a1, int a2)
{
switch ( a1 )
{
case 2:
func5(a2);
break;
case 3:
func3(a2);
break;
case 1:
func4();
break;
default:
func2();
break;
}
}

original_code:
void run_simulation(int algorithm, int quantum)
{
  switch(algorithm) {
    case 3:
      stride_scheduling(quantum);
      break;
    case 1:
      priority_scheduling();
      break;
    case 2:
      rr_scheduling(quantum);
      break;
    case 0:
    default:
      first_come_first_serve();
      break;
  }
}

variable_types: algorithm int


decompiled_code:
int compute_and_print_stats()
{
__int64 v0; // rbx
unsigned int v1; // ebp
__int64 v2; // rdx
__int64 v3; // rsi
float *v4; // rax
double v5; // xmm2_8
float v6; // xmm1_4
__int64 v7; // rdx
float v8; // xmm0_4
__int64 v9; // rdx
__int64 v10; // rbx
int v11; // eax
float v12; // xmm0_4
double v13; // xmm1_8
__int128 v15; // [rsp+0h] [rbp-38h]
__int128 v16[2]; // [rsp+10h] [rbp-28h]

v15 = 0LL;
v16[0] = 0LL;
if ( num_tasks <= 0 )
{
v1 = 0;
}
else
{
v0 = 0LL;
v1 = 0;
do
{
v2 = 9 * v0;
v3 = (unsigned int)v0++;
v4 = (float *)((char *)tasks + 4 * v2);
v5 = (double)*(int *)v4;
v6 = v4[3];
v7 = *((int *)v4 + 2);
++*((_DWORD *)&v15 + v7);
v8 = v6 - v5 + *((float *)v16 + v7);
*((float *)v16 + v7) = v8;
v9 = *((unsigned int *)v4 + 4);
v1 += v9;
printf(
"Task %3d: cpu time (%4.1f), response time (%4.1f), waiting (%4.1f), schedulings (%5d)\n",
v3,
v4[1],
(float)(v6 - (float)*(int *)v4),
(float)((float)(v6 - (float)*(int *)v4) - v4[5]),
v9);
}
while ( num_tasks > (int)v0 );
}
v10 = 0LL;
putchar(10);
if ( num_tasks > 0 )
{
do
{
v11 = *((_DWORD *)&v15 + v10);
if ( v11 )
{
v12 = *((float *)v16 + v10) / (float)v11;
v13 = v12;
}
else
{
v13 = 0.0;
v12 = 0.0;
}
*((float *)v16 + v10) = v12;
printf("Priority level %d: average response time (%4.1f)\n", (unsigned int)v10++, v13);
}
while ( v10 != 4 );
}
return printf("Total number of scheduling events: %d\n", v1);
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbx
unsigned int v1; // ebp
__int64 v2; // rdx
__int64 v3; // rsi
float *v4; // rax
double v5; // xmm2_8
float v6; // xmm1_4
__int64 v7; // rdx
float v8; // xmm0_4
__int64 v9; // rdx
__int64 v10; // rbx
int v11; // eax
float v12; // xmm0_4
double v13; // xmm1_8
__int128 v15; // [rsp+0h] [rbp-38h]
__int128 v16[2]; // [rsp+10h] [rbp-28h]

v15 = 0LL;
v16[0] = 0LL;
if ( num_tasks <= 0 )
{
v1 = 0;
}
else
{
v0 = 0LL;
v1 = 0;
do
{
v2 = 9 * v0;
v3 = (unsigned int)v0++;
v4 = (float *)((char *)tasks + 4 * v2);
v5 = (double)*(int *)v4;
v6 = v4[3];
v7 = *((int *)v4 + 2);
++*((_DWORD *)&v15 + v7);
v8 = v6 - v5 + *((float *)v16 + v7);
*((float *)v16 + v7) = v8;
v9 = *((unsigned int *)v4 + 4);
v1 += v9;
printf(
"Task %3d: cpu time (%4.1f), response time (%4.1f), waiting (%4.1f), schedulings (%5d)\n",
v3,
v4[1],
(float)(v6 - (float)*(int *)v4),
(float)((float)(v6 - (float)*(int *)v4) - v4[5]),
v9);
}
while ( num_tasks > (int)v0 );
}
v10 = 0LL;
putchar(10);
if ( num_tasks > 0 )
{
do
{
v11 = *((_DWORD *)&v15 + v10);
if ( v11 )
{
v12 = *((float *)v16 + v10) / (float)v11;
v13 = v12;
}
else
{
v13 = 0.0;
v12 = 0.0;
}
*((float *)v16 + v10) = v12;
printf("Priority level %d: average response time (%4.1f)\n", (unsigned int)v10++, v13);
}
while ( v10 != 4 );
}
return printf("Total number of scheduling events: %d\n", v1);
}

original_code:
void compute_and_print_stats()
{
  int tasks_at_level[4] = {0,};
  float response_at_level[4] = {0.0, };
  int scheduling_events = 0;
  int i;
  for (i = 0; i < num_tasks; i++) {
    tasks_at_level[tasks[i].priority]++;
    response_at_level[tasks[i].priority] +=
      tasks[i].finish_time - (tasks[i].arrival_time * 1.0);
    scheduling_events += tasks[i].schedulings;
    printf("Task %3d: cpu time (%4.1f), response time (%4.1f), waiting (%4.1f), schedulings (%5d)\n",
        i, tasks[i].length,
        tasks[i].finish_time - tasks[i].arrival_time,
        tasks[i].finish_time - tasks[i].arrival_time - tasks[i].cpu_cycles,
        tasks[i].schedulings);
  }
  printf("\n");
  if (num_tasks > 0) {
    for (i = 0; i < 4; i++) {
      if (tasks_at_level[i] == 0) {
        response_at_level[i] = 0.0;
      } else {
        response_at_level[i] /= tasks_at_level[i];
      }
      printf("Priority level %d: average response time (%4.1f)\n",
          i, response_at_level[i]);
    }
  }
  printf ("Total number of scheduling events: %d\n", scheduling_events);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v5; // er14
int v6; // ebp
int v7; // eax
const char *v8; // rsi
__int64 v9; // rdi
int v10; // edx
int v11; // er15
const char *v12; // r8
char *s1; // [rsp+8h] [rbp-40h]

if ( argc <= 1 )
{
v5 = 1;
v6 = 0;
LABEL_20:
read_task_data();
if ( !num_tasks )
{
fprintf(stderr, "%s: no tasks for the simulation\n", *argv);
exit(1);
}
init_simulation_data();
run_simulation(v6, v5);
compute_and_print_stats();
exit(0);
}
v5 = 1;
v6 = 0;
v7 = 1;
while ( 1 )
{
while ( 1 )
{
v8 = argv[v7];
v9 = v7;
v10 = *(unsigned __int8 *)v8 - 45;
if ( *v8 == 45 )
{
v10 = *((unsigned __int8 *)v8 + 1) - 113;
if ( v8[1] == 113 )
v10 = *((unsigned __int8 *)v8 + 2);
}
v11 = v7 + 1;
if ( v10 )
break;
v5 = atoi(argv[v9 + 1]);
LABEL_4:
v7 = v11 + 1;
if ( argc <= v11 + 1 )
goto LABEL_20;
}
if ( *v8 == 45 && v8[1] == 97 && !v8[2] )
{
v12 = argv[v9 + 1];
if ( !strcmp(v12, "FCFS") )
{
v6 = 0;
}
else if ( *v12 == 80 && v12[1] == 83 && !v12[2] )
{
v6 = 1;
}
else
{
s1 = (char *)argv[v9 + 1];
if ( !strcmp(v12, "RR") )
{
v6 = 2;
}
else if ( !strcmp(s1, "STRIDE") )
{
v6 = 3;
}
}
goto LABEL_4;
}
if ( argc <= ++v7 )
goto LABEL_20;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v5; // er14
int v6; // ebp
int v7; // eax
const char *v8; // rsi
__int64 v9; // rdi
int v10; // edx
int v11; // er15
const char *v12; // r8
char *s1; // [rsp+8h] [rbp-40h]

if ( argc <= 1 )
{
v5 = 1;
v6 = 0;
LABEL_20:
func0();
if ( !num_tasks )
{
fprintf(stderr, "%s: no tasks for the simulation\n", *argv);
exit(1);
}
func1();
func6(v6, v5);
func7();
exit(0);
}
v5 = 1;
v6 = 0;
v7 = 1;
while ( 1 )
{
while ( 1 )
{
v8 = argv[v7];
v9 = v7;
v10 = *(unsigned __int8 *)v8 - 45;
if ( *v8 == 45 )
{
v10 = *((unsigned __int8 *)v8 + 1) - 113;
if ( v8[1] == 113 )
v10 = *((unsigned __int8 *)v8 + 2);
}
v11 = v7 + 1;
if ( v10 )
break;
v5 = atoi(argv[v9 + 1]);
LABEL_4:
v7 = v11 + 1;
if ( argc <= v11 + 1 )
goto LABEL_20;
}
if ( *v8 == 45 && v8[1] == 97 && !v8[2] )
{
v12 = argv[v9 + 1];
if ( !strcmp(v12, "FCFS") )
{
v6 = 0;
}
else if ( *v12 == 80 && v12[1] == 83 && !v12[2] )
{
v6 = 1;
}
else
{
s1 = (char *)argv[v9 + 1];
if ( !strcmp(v12, "RR") )
{
v6 = 2;
}
else if ( !strcmp(s1, "STRIDE") )
{
v6 = 3;
}
}
goto LABEL_4;
}
if ( argc <= ++v7 )
goto LABEL_20;
}
}

original_code:
int main(int argc, char *argv[])
{
  int i = 0;
  int algorithm = 0;
  int quantum = 1;
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "-q") == 0) {
      i++;
      quantum = atoi(argv[i]);
    } else if (strcmp(argv[i], "-a") == 0) {
      i++;
      if (strcmp(argv[i], "FCFS") == 0) {
        algorithm = 0;
      } else if (strcmp(argv[i], "PS") == 0) {
        algorithm = 1;
      } else if (strcmp(argv[i], "RR") == 0) {
        algorithm = 2;
      } else if (strcmp(argv[i], "STRIDE") == 0) {
        algorithm = 3;
      }
    }
  }
  read_task_data();
  if (num_tasks == 0) {
    fprintf(stderr,"%s: no tasks for the simulation\n", argv[0]);
    exit(1);
  }
  init_simulation_data(algorithm);
  run_simulation(algorithm, quantum);
  compute_and_print_stats();
  exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


decompiled_code:
void __fastcall __noreturn add_worker(void *a1)
{
int v1; // er12
__int64 v3; // r13
sem_t **v4; // rax
sem_t **v5; // rbp
sem_t **v6; // rdi
sem_t *v7; // rax

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 <= *((_DWORD *)a1 + 1) )
{
v3 = 8LL * v1;
do
{
v4 = (sem_t **)calloc(1uLL, 0x18uLL);
v5 = v4;
if ( !v4 )
{
fwrite("Error allocating thread request.\n", 1uLL, 0x21uLL, stderr);
exit(-1);
}
v6 = v4;
++v1;
*v4 = (sem_t *)**((_QWORD **)a1 + 1);
v7 = *(sem_t **)(*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL) + v3);
*((_DWORD *)v5 + 4) = 0;
v3 += 8LL;
v5[1] = v7;
trie_add(v6);
free(v5);
}
while ( *((_DWORD *)a1 + 1) >= v1 );
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
int v1; // er12
__int64 v3; // r13
sem_t **v4; // rax
sem_t **v5; // rbp
sem_t **v6; // rdi
sem_t *v7; // rax

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 <= *((_DWORD *)a1 + 1) )
{
v3 = 8LL * v1;
do
{
v4 = (sem_t **)calloc(1uLL, 0x18uLL);
v5 = v4;
if ( !v4 )
{
fwrite("Error allocating thread request.\n", 1uLL, 0x21uLL, stderr);
exit(-1);
}
v6 = v4;
++v1;
*v4 = (sem_t *)**((_QWORD **)a1 + 1);
v7 = *(sem_t **)(*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL) + v3);
*((_DWORD *)v5 + 4) = 0;
v3 += 8LL;
v5[1] = v7;
func8(v6);
free(v5);
}
while ( *((_DWORD *)a1 + 1) >= v1 );
}
pthread_exit(0LL);
}

original_code:
void *add_worker(void *job_req) {
  job *job = job_req;
  int pos;
  for (pos = job->start; pos <= job->stop; pos++) {
    trie_request *request = calloc(1, sizeof(trie_request));
    if (request == ((void *)0)) {
      fprintf(stderr, "Error allocating thread request.\n");
      exit(-1);
    }
    request->node = *job->root;
    request->item = job->input->words[pos];
    request->position = 0;
    trie_add(request);
    free(request);
  }
  pthread_exit(((void *)0));
  return((void *) 0);
}

canonical_original_code:
void *add_worker(void *job_req) {
  struct job *job = job_req;
  int pos;
  for (pos = job->start; pos <= job->stop; pos++) {
    struct trie_request *request = calloc(1, sizeof(trie_request));
    if (request == ((void *)0)) {
      fprintf(stderr, "Error allocating thread request.\n");
      exit(-1);
    }
    request->node = *job->root;
    request->item = job->input->words[pos];
    request->position = 0;
    trie_add(request);
    free(request);
  }
  pthread_exit(((void *)0));
  return((void *) 0);
}

variable_types: struct job { int start; int stop; struct trie_node { int words; struct trie_node *links[27]; union sem_t { char __size[32]; long __align; } lock; } **root; struct stdin_dictionary { int size; char **words; } *input; char **output; } *

variable_types: pos int

variable_types: struct trie_request { struct trie_node { int words; struct trie_node *links[27]; union sem_t { char __size[32]; long __align; } lock; } *node; char *item; int position; } *

return_type: void *

user_defined_types: struct job { int start; int stop; struct trie_node **root; struct stdin_dictionary *input; char **output; }

user_defined_types: struct trie_request { struct trie_node *node; char *item; int position; }

user_defined_types: struct trie_node { int words; struct trie_node *links[27]; union sem_t lock; }


original_code:
int trie_find(trie_request* request) {
  if (request->position == strlen(request->item)) {
    if (request->node->words >= 1) {
      return 1;
    } else {
      return 0;
    }
  } else {
    int links_index = request->item[request->position] - 97;
    if ((links_index < 0) || (links_index > 97)) {
      links_index = 26;
    }
    if (request->node->links[links_index] != ((void *)0)) {
      request->position += 1;
      request->node = request->node->links[links_index];
      return trie_find(request);
    } else {
      return 0;
    }
  }
  return 0;
}

canonical_original_code:
int trie_find(struct trie_request *request) {
  if (request->position == strlen(request->item)) {
    if (request->node->words >= 1) {
      return 1;
    } else {
      return 0;
    }
  } else {
    int links_index = request->item[request->position] - 97;
    if ((links_index < 0) || (links_index > 97)) {
      links_index = 26;
    }
    if (request->node->links[links_index] != ((void *)0)) {
      request->position += 1;
      request->node = request->node->links[links_index];
      return trie_find(request);
    } else {
      return 0;
    }
  }
  return 0;
}

user_defined_types: union sem_t { char __size[32]; long __align; }


decompiled_code:
void __fastcall __noreturn find_worker(void *a1)
{
int v1; // er13
__int64 v2; // r12
_QWORD *v3; // rax
__int64 v4; // rbp
char *v5; // rax

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 <= *((_DWORD *)a1 + 1) )
{
v2 = 8LL * v1;
do
{
v3 = calloc(1uLL, 0x18uLL);
v4 = (__int64)v3;
if ( !v3 )
{
fwrite("Error allocating thread request.\n", 1uLL, 0x21uLL, stderr);
exit(-1);
}
*v3 = **((_QWORD **)a1 + 1);
v5 = reverse(*(const char **)(*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL) + v2));
*(_DWORD *)(v4 + 16) = 0;
*(_QWORD *)(v4 + 8) = v5;
if ( trie_find(v4) )
*(_QWORD *)(*((_QWORD *)a1 + 3) + v2) = *(_QWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL) + v2);
++v1;
v2 += 8LL;
free((void *)v4);
}
while ( *((_DWORD *)a1 + 1) >= v1 );
}
pthread_exit(0LL);
}

original_code:
void *find_worker(void *job_req) {
  job *job = job_req;
  int pos;
  for (pos = job->start; pos <= job->stop; pos++) {
    trie_request *request = calloc(1, sizeof(trie_request));
    if (request == ((void *)0)) {
      fprintf(stderr, "Error allocating thread request.\n");
      exit(-1);
    }
    request->node = *job->root;
    request->item = reverse(job->input->words[pos]);
    request->position = 0;
    int success = trie_find(request);
    if (success == 1) {
      job->output[pos] = job->input->words[pos];
    }
    free(request);
  }
  pthread_exit(((void *)0));
  return((void *) 0);
}

canonical_original_code:
void *find_worker(void *job_req) {
  struct job *job = job_req;
  int pos;
  for (pos = job->start; pos <= job->stop; pos++) {
    struct trie_request *request = calloc(1, sizeof(trie_request));
    if (request == ((void *)0)) {
      fprintf(stderr, "Error allocating thread request.\n");
      exit(-1);
    }
    request->node = *job->root;
    request->item = reverse(job->input->words[pos]);
    request->position = 0;
    int success = trie_find(request);
    if (success == 1) {
      job->output[pos] = job->input->words[pos];
    }
    free(request);
  }
  pthread_exit(((void *)0));
  return((void *) 0);
}

variable_types: success int

user_defined_types: struct stdin_dictionary { int size; char **words; }


decompiled_code:
int *parse_input()
{
int *v0; // rax
int *v1; // r12
void *v2; // rax
void *v3; // rbp
__int64 v4; // rbx
int v5; // esi
const char *v6; // r13
const char *v7; // rax
int v8; // esi
void *v9; // rax
char *v10; // rax
char *v11; // rdi
void *v12; // rax

v0 = (int *)calloc(1uLL, 0x10uLL);
if ( !v0 || (*v0 = 1, v1 = v0, v2 = malloc(8uLL), *((_QWORD *)v1 + 1) = v2, (v3 = v2) == 0LL) )
{
fwrite("Error allocating memory for words.\n", 1uLL, 0x23uLL, stderr);
exit(-1);
}
v4 = 0LL;
v5 = 1;
while ( 1 )
{
if ( v5 - 1 <= (int)v4 )
{
v8 = 2 * v5;
*v1 = v8;
v9 = realloc(v3, 8LL * v8);
*((_QWORD *)v1 + 1) = v9;
v3 = v9;
if ( !v9 )
{
fwrite("Error reallocating memory for words.\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
}
v10 = (char *)calloc(0x100uLL, 8uLL);
*((_QWORD *)v3 + v4) = v10;
v11 = v10;
if ( !v10 )
{
fwrite("Error allocating memory for fgets.\n", 1uLL, 0x23uLL, stderr);
v11 = *(char **)(*((_QWORD *)v1 + 1) + 8 * v4);
}
if ( !fgets(v11, 256, stdin) )
break;
v3 = (void *)*((_QWORD *)v1 + 1);
v6 = (const char *)*((_QWORD *)v3 + v4);
v7 = &v6[strlen(v6) - 1];
if ( *v7 == 10 )
{
*v7 = 0;
v3 = (void *)*((_QWORD *)v1 + 1);
}
v5 = *v1;
++v4;
}
*v1 = v4;
v12 = realloc(*((void **)v1 + 1), 8 * v4);
*((_QWORD *)v1 + 1) = v12;
if ( !v12 )
{
fwrite("Error reallocating memory for words after the loop.\n", 1uLL, 0x34uLL, stderr);
exit(-1);
}
return v1;
}

canonical_decompiled_code:
int *func12()
{
int *v0; // rax
int *v1; // r12
void *v2; // rax
void *v3; // rbp
__int64 v4; // rbx
int v5; // esi
const char *v6; // r13
const char *v7; // rax
int v8; // esi
void *v9; // rax
char *v10; // rax
char *v11; // rdi
void *v12; // rax

v0 = (int *)calloc(1uLL, 0x10uLL);
if ( !v0 || (*v0 = 1, v1 = v0, v2 = malloc(8uLL), *((_QWORD *)v1 + 1) = v2, (v3 = v2) == 0LL) )
{
fwrite("Error allocating memory for words.\n", 1uLL, 0x23uLL, stderr);
exit(-1);
}
v4 = 0LL;
v5 = 1;
while ( 1 )
{
if ( v5 - 1 <= (int)v4 )
{
v8 = 2 * v5;
*v1 = v8;
v9 = realloc(v3, 8LL * v8);
*((_QWORD *)v1 + 1) = v9;
v3 = v9;
if ( !v9 )
{
fwrite("Error reallocating memory for words.\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
}
v10 = (char *)calloc(0x100uLL, 8uLL);
*((_QWORD *)v3 + v4) = v10;
v11 = v10;
if ( !v10 )
{
fwrite("Error allocating memory for fgets.\n", 1uLL, 0x23uLL, stderr);
v11 = *(char **)(*((_QWORD *)v1 + 1) + 8 * v4);
}
if ( !fgets(v11, 256, stdin) )
break;
v3 = (void *)*((_QWORD *)v1 + 1);
v6 = (const char *)*((_QWORD *)v3 + v4);
v7 = &v6[strlen(v6) - 1];
if ( *v7 == 10 )
{
*v7 = 0;
v3 = (void *)*((_QWORD *)v1 + 1);
}
v5 = *v1;
++v4;
}
*v1 = v4;
v12 = realloc(*((void **)v1 + 1), 8 * v4);
*((_QWORD *)v1 + 1) = v12;
if ( !v12 )
{
fwrite("Error reallocating memory for words after the loop.\n", 1uLL, 0x34uLL, stderr);
exit(-1);
}
return v1;
}

original_code:
stdin_dictionary* parse_input() {
  stdin_dictionary *dict = calloc(1, sizeof(stdin_dictionary));
  if (dict == ((void *)0)) {
    fprintf(stderr, "Error allocating memory for words.\n");
    exit(-1);
  }
  dict->size = 1;
  dict->words = malloc(dict->size * sizeof(char*));
  int stdin_position = 0;
  if (dict->words == ((void *)0)) {
    fprintf(stderr, "Error allocating memory for words.\n");
    exit(-1);
  }
  for (;;) {
    if (stdin_position >= dict->size - 1) {
      dict->size *= 2;
      dict->words = realloc (dict->words, dict->size * sizeof(char*));
      if (dict->words == ((void *)0)) {
        fprintf(stderr, "Error reallocating memory for words.\n");
        exit(-1);
      }
    }
    dict->words[stdin_position] = calloc(256, sizeof(char*));
    if (dict->words[stdin_position] == ((void *)0)) {
      fprintf(stderr, "Error allocating memory for fgets.\n");
    }
    void* status = fgets(dict->words[stdin_position], 256, stdin);
    if (status == ((void *)0)) {
      break;
    } else {
      if (dict->words[stdin_position][strlen(dict->words[stdin_position])-1] == '\n') {
        dict->words[stdin_position][strlen(dict->words[stdin_position])-1] = 0;
      }
    }
    stdin_position++;
  }
  dict->size = stdin_position;
  dict->words = realloc(dict->words, stdin_position * sizeof(char*));
  if (dict->words == ((void *)0)) {
    fprintf(stderr, "Error reallocating memory for words after the loop.\n");
    exit(-1);
  }
  return dict;
}

canonical_original_code:
struct stdin_dictionary *parse_input() {
  struct stdin_dictionary *dict = calloc(1, sizeof(stdin_dictionary));
  if (dict == ((void *)0)) {
    fprintf(stderr, "Error allocating memory for words.\n");
    exit(-1);
  }
  dict->size = 1;
  dict->words = malloc(dict->size * sizeof(char *));
  int stdin_position = 0;
  if (dict->words == ((void *)0)) {
    fprintf(stderr, "Error allocating memory for words.\n");
    exit(-1);
  }
  for (;;) {
    if (stdin_position >= dict->size - 1) {
      dict->size *= 2;
      dict->words = realloc (dict->words, dict->size * sizeof(char *));
      if (dict->words == ((void *)0)) {
        fprintf(stderr, "Error reallocating memory for words.\n");
        exit(-1);
      }
    }
    dict->words[stdin_position] = calloc(256, sizeof(char *));
    if (dict->words[stdin_position] == ((void *)0)) {
      fprintf(stderr, "Error allocating memory for fgets.\n");
    }
    void *status = fgets(dict->words[stdin_position], 256, stdin);
    if (status == ((void *)0)) {
      break;
    } else {
      if (dict->words[stdin_position][strlen(dict->words[stdin_position])-1] == '\n') {
        dict->words[stdin_position][strlen(dict->words[stdin_position])-1] = 0;
      }
    }
    stdin_position++;
  }
  dict->size = stdin_position;
  dict->words = realloc(dict->words, stdin_position * sizeof(char *));
  if (dict->words == ((void *)0)) {
    fprintf(stderr, "Error reallocating memory for words after the loop.\n");
    exit(-1);
  }
  return dict;
}

variable_types: struct stdin_dictionary { int size; char **words; } *

variable_types:
status
void *


decompiled_code:
float generate_task_length()
{
int v0; // ebx
float v1; // xmm0_4
float result; // xmm0_4

v0 = rand();
v1 = (float)rand() * 4.6566129e-10;
if ( (float)((float)v0 * 4.6566129e-10) <= 0.8 )
result = (float)(v1 * 17.0) + 3.0;
else
result = (float)(v1 * 150.0) + 100.0;
return result;
}

original_code:
float generate_task_length()
{
    float short_long_choice = rand();
    float length = rand();
    if ((short_long_choice / 2147483647) > 0.8) {
        return (length / 2147483647 * (250 - 100) + 100);
    } else {
        return (length / 2147483647 * (20 - 3) + 3);
    }
}

variable_types: length float

return_type: float


decompiled_code:
__int64 __fastcall generate_priority(float a1)
{
float v2; // xmm0_4

v2 = (float)rand() * 4.6566129e-10;
if ( a1 <= 20.0 )
return v2 >= 0.3;
if ( a1 < 100.0 )
__assert_fail("0", "gentasks.c", 0x48u, "generate_priority");
return (unsigned int)(v2 < 0.9) + 2;
}

canonical_decompiled_code:
__int64 __fastcall func8(float a1)
{
float v2; // xmm0_4

v2 = (float)rand() * 4.6566129e-10;
if ( a1 <= 20.0 )
return v2 >= 0.3;
if ( a1 < 100.0 )
__assert_fail("0", "gentasks.c", 0x48u, "generate_priority");
return (unsigned int)(v2 < 0.9) + 2;
}

original_code:
int generate_priority(float length)
{
    float high_low_choice = rand();
    high_low_choice /= 2147483647;
    if (length <= 20) {
        if (high_low_choice < 0.3) {
            return 0;
        } else {
            return 1;
        }
    }
    if (length >= 100) {
        if (high_low_choice < 0.9) {
            return 3;
        } else {
            return 2;
        }
    }
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "gentasks.c", 72, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
__int64 generate_arrival_interval()
{
float v0; // xmm0_4
float v1; // xmm0_4
float v3; // [rsp+Ch] [rbp-Ch]

v3 = (float)rand();
v0 = (float)rand() * 4.6566129e-10;
if ( (float)(v3 * 4.6566129e-10) >= 0.5 )
v1 = (float)(v0 * 14.0) + 1.0;
else
v1 = (float)(v0 * 4.0) + 1.0;
return (unsigned int)(int)v1;
}

original_code:
int generate_arrival_interval()
{
    float large_small_choice = rand();
    large_small_choice /= 2147483647;
    float length = rand();
    if (large_small_choice < 0.5) {
        return (int)(length / 2147483647 * (5 - 1) + 1);
    } else {
        return (int)(length / 2147483647 * (15 - 1) + 1);
    }
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
unsigned int v5; // ebp
unsigned int i; // ebx
unsigned int v7; // eax
__int64 v8; // rsi
float v9; // [rsp+Ch] [rbp-1Ch]

if ( argc <= 2 )
{
fprintf(_bss_start, "usage: %s <number of tasks> <random seed>\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
srand(v4);
if ( v3 > 0 )
{
v5 = 0;
for ( i = 0; i != v3; ++i )
{
v5 += generate_arrival_interval();
v9 = generate_task_length();
v7 = generate_priority();
v8 = i;
printf("%d %d %.1f %d\n", v8, v5, v9, v7);
}
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
unsigned int v5; // ebp
unsigned int i; // ebx
unsigned int v7; // eax
__int64 v8; // rsi
float v9; // [rsp+Ch] [rbp-1Ch]

if ( argc <= 2 )
{
fprintf(_bss_start, "usage: %s <number of tasks> <random seed>\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
srand(v4);
if ( v3 > 0 )
{
v5 = 0;
for ( i = 0; i != v3; ++i )
{
v5 += func9();
v9 = func7();
v7 = func8();
v8 = i;
printf("%d %d %.1f %d\n", v8, v5, v9, v7);
}
}
exit(0);
}

original_code:
int main(int argc, char *argv[]) {
    int i;
    if (argc < 3) {
        fprintf(stderr, "usage: %s <number of tasks> <random seed>\n", argv[0]);
        exit(1);
    }
    int num_tasks = atoi(argv[1]);
    int random_seed = atoi(argv[2]);
    srand(random_seed);
    int task_arrival_time = 0;
    float task_length = 0.0;
    int task_priority = 0;
    for (i = 0; i < num_tasks; i++) {
        task_arrival_time += generate_arrival_interval();
        task_length = generate_task_length();
        task_priority = generate_priority(task_length);
        printf("%d %d %.1f %d\n", i, task_arrival_time, task_length, task_priority);
    }
    exit(0);
}


repo: HsuBokai/cmdline

original_code:
void init_cmdline(Cmdline* re, char input[], char cut_point)
{
 char* pch, *src;
 src = input;
 pch=strchr(src, cut_point);
 re->len = 0;
 while (pch!=((void *)0)) {
  size_t len = pch-src;
  if(len>0) {
   char* newline = (char*)calloc(len+1, sizeof(char));
   memcpy(newline, src, len);
   newline[len]='\0';
   re->_cmds[re->len++] = newline;
  }
  src = pch+1;
  pch=strchr(src, cut_point);
 }
 if(src!=((void *)0)) {
  size_t len = strlen(src);
  char* newline = (char*)calloc(len+1, sizeof(char));
  memcpy(newline, src, len);
  newline[len]='\0';
  re->_cmds[re->len++] = newline;
 }
}

canonical_original_code:
void init_cmdline(struct _Cmdline *re, char input[], char cut_point)
{
 char *pch; char *src;
 src = input;
 pch=strchr(src, cut_point);
 re->len = 0;
 while (pch!=((void *)0)) {
  unsigned long len = pch-src;
  if(len>0) {
   char *newline = (char*)calloc(len+1, sizeof(char));
   memcpy(newline, src, len);
   newline[len]='\0';
   re->_cmds[re->len++] = newline;
  }
  src = pch+1;
  pch=strchr(src, cut_point);
 }
 if(src!=((void *)0)) {
  unsigned long len = strlen(src);
  char *newline = (char*)calloc(len+1, sizeof(char));
  memcpy(newline, src, len);
  newline[len]='\0';
  re->_cmds[re->len++] = newline;
 }
}

variable_types: struct _Cmdline { char *_cmds[64]; int len; } *

variable_types:
input
char []

variable_types:
pch
char *

variable_types:
src
char *

variable_types:
len
unsigned long

variable_types:
newline
char *


decompiled_code:
void *__fastcall new_Cmdline(const char *a1, char a2)
{
void *v2; // r12

v2 = malloc(0x208uLL);
init_cmdline((__int64)v2, a1, a2);
return v2;
}

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

v2 = malloc(0x208uLL);
func0((__int64)v2, a1, a2);
return v2;
}

original_code:
Cmdline* new_Cmdline(char input[], char cut_point) {
 Cmdline* re = (Cmdline*) malloc(sizeof(Cmdline));
 init_cmdline(re, input, cut_point);
 return re;
}

canonical_original_code:
struct _Cmdline *new_Cmdline(char input[], char cut_point) {
 struct _Cmdline *re = (Cmdline*) malloc(sizeof(Cmdline));
 init_cmdline(re, input, cut_point);
 return re;
}

return_type: struct _Cmdline { char *_cmds[64]; int len; } *


reset

original_code:
void reset(Cmdline* obj)
{
 int i;
 for (i = 0; i < obj->len; ++i) {
  if(obj->_cmds[i] != ((void *)0)) {
   free(obj->_cmds[i]);
   obj->_cmds[i] = ((void *)0);
  }
 }
}

canonical_original_code:
void reset(struct _Cmdline *obj)
{
 int i;
 for (i = 0; i < obj->len; ++i) {
  if(obj->_cmds[i] != ((void *)0)) {
   free(obj->_cmds[i]);
   obj->_cmds[i] = ((void *)0);
  }
 }
}

variable_types: i int

user_defined_types: struct _Cmdline { char *_cmds[64]; int len; }


decompiled_code:
void __fastcall delete_Cmdline(void *ptr)
{
reset((__int64)ptr);
free(ptr);
}

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

original_code:
void delete_Cmdline(Cmdline* obj) {
 reset(obj);
 free(obj);
 obj = ((void *)0);
}

canonical_original_code:
void delete_Cmdline(struct _Cmdline *obj) {
 reset(obj);
 free(obj);
 obj = ((void *)0);
}


decompiled_code:
__int64 __fastcall get_cmd(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

original_code:
char* get_cmd(Cmdline* obj, int index) {
 return obj->_cmds[index];
}

canonical_original_code:
char *get_cmd(struct _Cmdline *obj, int index) {
 return obj->_cmds[index];
}

variable_types: index int

return_type: char *


decompiled_code:
__int64 __fastcall get_size(__int64 a1)
{
return *(unsigned int *)(a1 + 512);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 512);
}

original_code:
int get_size(Cmdline* obj) {
 return obj->len;
}

canonical_original_code:
int get_size(struct _Cmdline *obj) {
 return obj->len;
}


decompiled_code:
int __fastcall exec_cmd(__int64 a1, int a2)
{
*(_QWORD *)(a1 + 8LL * *(int *)(a1 + 512)) = 0LL;
return execv(*(const char **)(a1 + 8LL * a2), (char *const *)(a1 + 8LL * a2));
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, int a2)
{
*(_QWORD *)(a1 + 8LL * *(int *)(a1 + 512)) = 0LL;
return execv(*(const char **)(a1 + 8LL * a2), (char *const *)(a1 + 8LL * a2));
}

original_code:
void exec_cmd(Cmdline* obj, int index) {
 obj->_cmds[obj->len] = 0;
 execv(obj->_cmds[index], obj->_cmds+index);
 return;
}

canonical_original_code:
void exec_cmd(struct _Cmdline *obj, int index) {
 obj->_cmds[obj->len] = 0;
 execv(obj->_cmds[index], obj->_cmds+index);
 return;
}


decompiled_code:
__int64 __fastcall str2num(char *a1)
{
char *v1; // rcx
unsigned int v2; // er8
unsigned int v3; // eax

v1 = a1 + 10;
v2 = 0;
do
{
v3 = *a1 - 48;
if ( v3 > 9 )
break;
++a1;
v2 = v3 + 10 * v2;
}
while ( a1 != v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char *v1; // rcx
unsigned int v2; // er8
unsigned int v3; // eax

v1 = a1 + 10;
v2 = 0;
do
{
v3 = *a1 - 48;
if ( v3 > 9 )
break;
++a1;
v2 = v3 + 10 * v2;
}
while ( a1 != v1 );
return v2;
}

original_code:
unsigned str2num(const char* buf) {
 int i = 0;
 unsigned re = 0;
 for(; i<10; ++i) {
  unsigned digit = buf[i]-'0';
  if(0 <= digit && digit < 10) {
   re = re*10 + digit;
  }
  else break;
 }
 return re;
}

canonical_original_code:
unsigned int str2num(char *buf) {
 int i = 0;
 unsigned int re = 0;
 for(; i<10; ++i) {
  unsigned int digit = buf[i]-'0';
  if(0 <= digit && digit < 10) {
   re = re*10 + digit;
  }
  else break;
 }
 return re;
}

variable_types:
buf
char *

variable_types:
re
unsigned int

variable_types:
digit
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall num2str(unsigned int a1, char *a2)
{
return sprintf(a2, "%u", a1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, char *a2)
{
return sprintf(a2, "%u", a1);
}

original_code:
void num2str(unsigned num, char ret[]) {
 sprintf(ret, "%u", num);
}

canonical_original_code:
void num2str(unsigned int num, char ret[]) {
 sprintf(ret, "%u", num);
}

variable_types:
num
unsigned int

variable_types:
ret
char []


decompiled_code:
int __fastcall my_copy(char *file, char *a2)
{
int v2; // ebp
int v3; // eax
int v4; // er12
int v5; // eax
_BYTE v7[1048]; // [rsp+0h] [rbp-418h] BYREF

printf("src = %s -> dst = %s\n", file, a2);
v2 = open(file, 0, 493LL);
v3 = open(a2, 578, 493LL);
v4 = v3;
if ( v2 >= 0 && v3 >= 0 )
{
while ( 1 )
{
v5 = read(v2, v7, 0x400uLL);
if ( v5 <= 0 )
break;
write(v4, v7, v5);
}
}
else
{
puts("Open Error!Check if the file is exist and you have the permission!");
}
close(v2);
return close(v4);
}

canonical_decompiled_code:
int __fastcall func2(char *file, char *a2)
{
int v2; // ebp
int v3; // eax
int v4; // er12
int v5; // eax
_BYTE v7[1048]; // [rsp+0h] [rbp-418h] BYREF

printf("src = %s -> dst = %s\n", file, a2);
v2 = open(file, 0, 493LL);
v3 = open(a2, 578, 493LL);
v4 = v3;
if ( v2 >= 0 && v3 >= 0 )
{
while ( 1 )
{
v5 = read(v2, v7, 0x400uLL);
if ( v5 <= 0 )
break;
write(v4, v7, v5);
}
}
else
{
puts("Open Error!Check if the file is exist and you have the permission!");
}
close(v2);
return close(v4);
}

original_code:
void my_copy(const char* src, const char *bakfile) {
 printf("src = %s -> dst = %s\n", src, bakfile);
 char buff[1024];
 int fd1,fd2,i;
 fd1 = open(src, 00, 0755);
 fd2 = open(bakfile, 02|0100|01000, 0755);
 if((fd1 < 0)||(fd2 < 0))
  printf("Open Error!Check if the file is exist and you have the permission!\n");
 else{
  while((i = read(fd1,buff,sizeof(buff))) > 0) {
   write(fd2,buff,i);
  }
 }
 close(fd1);
 close(fd2);
}

canonical_original_code:
void my_copy(char *src, char *bakfile) {
 printf("src = %s -> dst = %s\n", src, bakfile);
 char buff[1024];
 int fd1; int fd2; int i;
 fd1 = open(src, 00, 0755);
 fd2 = open(bakfile, 02|0100|01000, 0755);
 if((fd1 < 0)||(fd2 < 0))
  printf("Open Error!Check if the file is exist and you have the permission!\n");
 else{
  while((i = read(fd1,buff,sizeof(buff))) > 0) {
   write(fd2,buff,i);
  }
 }
 close(fd1);
 close(fd2);
}

variable_types:
bakfile
char *

variable_types:
buff
char [1024]


decompiled_code:
int __fastcall my_touch(const char *a1)
{
int v1; // eax
int v2; // ebp
int result; // eax
__int64 buf[2]; // [rsp+1h] [rbp-17h] BYREF

v1 = open(a1, 578, 420LL);
v2 = v1;
if ( v1 < 0 )
{
puts("create error!");
result = close(v2);
}
else
{
strcpy((char *)buf, "helloworld!!!\n");
write(v1, buf, 0xEuLL);
result = close(v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
int v1; // eax
int v2; // ebp
int result; // eax
__int64 buf[2]; // [rsp+1h] [rbp-17h] BYREF

v1 = open(a1, 578, 420LL);
v2 = v1;
if ( v1 < 0 )
{
puts("create error!");
result = close(v2);
}
else
{
strcpy((char *)buf, "helloworld!!!\n");
write(v1, buf, 0xEuLL);
result = close(v2);
}
return result;
}

original_code:
void my_touch(const char* src) {
 int fd2;
 fd2 = open(src, 02|0100|01000, 0644);
 if(fd2 < 0)
  printf("create error!\n");
 else {
  char content[] = "helloworld!!!\n";
  write(fd2, content, strlen(content));
 }
 close(fd2);
}

canonical_original_code:
void my_touch(char *src) {
 int fd2;
 fd2 = open(src, 02|0100|01000, 0644);
 if(fd2 < 0)
  printf("create error!\n");
 else {
  char content[] = "helloworld!!!\n";
  write(fd2, content, strlen(content));
 }
 close(fd2);
}

variable_types:
content
char []


decompiled_code:
int __fastcall my_cat(const char *a1)
{
int v1; // ebp
int v2; // eax
int result; // eax
_BYTE v4[1032]; // [rsp+0h] [rbp-408h] BYREF

v1 = open(a1, 0, 493LL);
if ( v1 >= 0 )
{
while ( 1 )
{
v2 = read(v1, v4, 0x400uLL);
if ( v2 <= 0 )
break;
write(1, v4, v2);
}
result = close(v1);
}
else
{
puts("Open Error!Check if the file is exist and you have the permission!");
result = close(v1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
int v1; // ebp
int v2; // eax
int result; // eax
_BYTE v4[1032]; // [rsp+0h] [rbp-408h] BYREF

v1 = open(a1, 0, 493LL);
if ( v1 >= 0 )
{
while ( 1 )
{
v2 = read(v1, v4, 0x400uLL);
if ( v2 <= 0 )
break;
write(1, v4, v2);
}
result = close(v1);
}
else
{
puts("Open Error!Check if the file is exist and you have the permission!");
result = close(v1);
}
return result;
}

original_code:
void my_cat(const char* src) {
 char buff[1024];
 int fd1, i;
 fd1 = open(src, 00, 0755);
 if((fd1 < 0))
  printf("Open Error!Check if the file is exist and you have the permission!\n");
 else{
  while((i = read(fd1,buff,sizeof(buff))) > 0) {
   write(1,buff,i);
  }
 }
 close(fd1);
}

canonical_original_code:
void my_cat(char *src) {
 char buff[1024];
 int fd1; int i;
 fd1 = open(src, 00, 0755);
 if((fd1 < 0))
  printf("Open Error!Check if the file is exist and you have the permission!\n");
 else{
  while((i = read(fd1,buff,sizeof(buff))) > 0) {
   write(1,buff,i);
  }
 }
 close(fd1);
}


decompiled_code:
__int64 __fastcall print_array(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rdx

if ( a2 )
{
v2 = a1;
do
{
v3 = *v2++;
fprintf(stderr, "%02x", v3);
}
while ( v2 != &a1[a2 - 1 + 1] );
}
fputc(10, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rdx

if ( a2 )
{
v2 = a1;
do
{
v3 = *v2++;
fprintf(stderr, "%02x", v3);
}
while ( v2 != &a1[a2 - 1 + 1] );
}
fputc(10, stderr);
return 0LL;
}

original_code:
int print_array(unsigned char* buf, unsigned len) {
 int i = 0;
 for(i = 0; i < len; ++i){
  fprintf(stderr, "%02x", buf[i]);
 }
 fprintf(stderr, "\n");
 return 0;
}

canonical_original_code:
int print_array(unsigned char *buf, unsigned int len) {
 int i = 0;
 for(i = 0; i < len; ++i){
  fprintf(stderr, "%02x", buf[i]);
 }
 fprintf(stderr, "\n");
 return 0;
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int


diep

decompiled_code:
void __fastcall __noreturn diep(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void diep(char *s)
{
        perror(s);
        exit(1);
}

variable_types:
s
char *


recvloop

decompiled_code:
void __fastcall __noreturn recvloop(int fd)
{
void *v1; // r13
char *v2; // rbp
char *v3; // r15
double v4; // xmm1_8
int v5; // [rsp+Ch] [rbp-14CCh]
const char *nptr; // [rsp+10h] [rbp-14C8h]
double v7; // [rsp+18h] [rbp-14C0h]
socklen_t addr_len; // [rsp+24h] [rbp-14B4h] BYREF
char *stringp; // [rsp+28h] [rbp-14B0h] BYREF
struct sockaddr addr[8]; // [rsp+30h] [rbp-14A8h] BYREF
char buf[1008]; // [rsp+B0h] [rbp-1428h] BYREF
char s1[4152]; // [rsp+4A0h] [rbp-1038h] BYREF

v1 = malloc(0x2710uLL);
memset(s1, 0, 0x1000uLL);
printf("msg pointer is 0x%p\n", stringp);
v5 = 0;
while ( 1 )
{
memset(addr, 0, sizeof(addr));
addr_len = 128;
printf("param recvfrom (%d, %p, %d, %d, %p, %p)\n", (unsigned int)fd, stringp, 10000LL, 0LL, addr, &addr_len);
if ( (int)recvfrom(fd, v1, 0x2710uLL, 0, addr, &addr_len) <= 0 )
{
perror("recvfrom\n");
_exit(-1);
}
inet_ntop(10, addr, buf, 0x3E8u);
stringp = (char *)v1;
printf("From: %s msg: %.*s\n", buf, 16, (const char *)v1);
v2 = strsep(&stringp, ":");
nptr = strsep(&stringp, ":");
if ( v5 )
{
v3 = s1;
while ( strcmp(v3, v2) )
{
v3 += 128;
if ( v3 == &s1[128 * (unsigned __int64)(unsigned int)(v5 - 1) + 128] )
goto LABEL_9;
}
printf("Key: %s Value %s\n", v3, v3 + 64);
v7 = strtod(nptr, 0LL);
v4 = strtod(v3 + 64, 0LL);
if ( v7 - v4 > 1.0 )
{
printf("ERROR - missed packet from: %s - current %f previous %f \n", v3, v7, v4);
exit(1);
}
printf(" Update Key:%s old Value=%s, new Value=%s\n", v3, v3 + 64, nptr);
strcpy(v3 + 64, nptr);
}
else
{
LABEL_9:
printf("add new entry with key %s to list\n", v2);
strncpy(&s1[128 * (__int64)v5++], v2, 0x3FuLL);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func10(int fd)
{
void *v1; // r13
char *v2; // rbp
char *v3; // r15
double v4; // xmm1_8
int v5; // [rsp+Ch] [rbp-14CCh]
const char *nptr; // [rsp+10h] [rbp-14C8h]
double v7; // [rsp+18h] [rbp-14C0h]
socklen_t addr_len; // [rsp+24h] [rbp-14B4h] BYREF
char *stringp; // [rsp+28h] [rbp-14B0h] BYREF
struct sockaddr addr[8]; // [rsp+30h] [rbp-14A8h] BYREF
char buf[1008]; // [rsp+B0h] [rbp-1428h] BYREF
char s1[4152]; // [rsp+4A0h] [rbp-1038h] BYREF

v1 = malloc(0x2710uLL);
memset(s1, 0, 0x1000uLL);
printf("msg pointer is 0x%p\n", stringp);
v5 = 0;
while ( 1 )
{
memset(addr, 0, sizeof(addr));
addr_len = 128;
printf("param recvfrom (%d, %p, %d, %d, %p, %p)\n", (unsigned int)fd, stringp, 10000LL, 0LL, addr, &addr_len);
if ( (int)recvfrom(fd, v1, 0x2710uLL, 0, addr, &addr_len) <= 0 )
{
perror("recvfrom\n");
_exit(-1);
}
inet_ntop(10, addr, buf, 0x3E8u);
stringp = (char *)v1;
printf("From: %s msg: %.*s\n", buf, 16, (const char *)v1);
v2 = strsep(&stringp, ":");
nptr = strsep(&stringp, ":");
if ( v5 )
{
v3 = s1;
while ( strcmp(v3, v2) )
{
v3 += 128;
if ( v3 == &s1[128 * (unsigned __int64)(unsigned int)(v5 - 1) + 128] )
goto LABEL_9;
}
printf("Key: %s Value %s\n", v3, v3 + 64);
v7 = strtod(nptr, 0LL);
v4 = strtod(v3 + 64, 0LL);
if ( v7 - v4 > 1.0 )
{
printf("ERROR - missed packet from: %s - current %f previous %f \n", v3, v7, v4);
exit(1);
}
printf(" Update Key:%s old Value=%s, new Value=%s\n", v3, v3 + 64, nptr);
strcpy(v3 + 64, nptr);
}
else
{
LABEL_9:
printf("add new entry with key %s to list\n", v2);
strncpy(&s1[128 * (__int64)v5++], v2, 0x3FuLL);
}
}
}

original_code:
void recvloop(uint32_t s)
{
 int i;
        struct sockaddr_storage sender;
 char *buf = (char *)malloc(10000);
 char *message;
 char name[1000];
        char *key;
        char *viewId;
 struct entry {
  char key[64];
  char value[64];
 };
 struct entry dumblist[32];
 memset(dumblist,0,sizeof(struct entry)*32);
 int nextfree = 0;
 struct entry *e = ((void *)0);
 printf ("msg pointer is 0x%p\n",message);
 while(1) {
  memset(&sender,0,sizeof(struct sockaddr_storage));
         socklen_t sendsize = sizeof(sender);
  printf("param recvfrom (%d, %p, %d, %d, %p, %p)\n",
   s, message, 10000, 0, &sender, &sendsize);
  int recvSize = recvfrom(s, buf, 10000, 0, (struct sockaddr *)&sender, &sendsize);
  if (recvSize <= 0){
   perror("recvfrom\n");
   _exit(-1);
  }
  inet_ntop(10, &sender, name, 1000);
  message = buf;
  printf("From: %s msg: %.*s\n", name,16, message);
                for (i=0; i < 2; i++) {
                    if (i == 0) {
                       key = strsep(&message, ":");
                    } else if (i == 1) {
                       viewId = strsep(&message, ":");
                    }
                }
  e = ((void *)0);
  for(i=0;i<nextfree;i++){
   if(strcmp(dumblist[i].key, key) == 0){
    e = &dumblist[i];
    break;
   }
  }
  if (e != ((void *)0)) {
                    printf("Key: %s Value %s\n", e->key, e->value);
                    double current_val = strtod(viewId, ((void *)0));
                    double previous_val = strtod(e->value, ((void *)0));
                    if ((current_val - previous_val) > 1 ) {
   printf("ERROR - missed packet from: %s - current %f previous %f \n",
    e->key, current_val, previous_val);
   exit(1);
                    } else {
   printf(" Update Key:%s old Value=%s, new Value=%s\n",e->key, e->value, viewId);
   strcpy(e->value, viewId);
   continue;
   }
  }else {
  printf("add new entry with key %s to list\n", key);
  strncpy(dumblist[nextfree].key,key,63);
  nextfree++;
  }
 }
}

canonical_original_code:
void recvloop(unsigned int s)
{
 int i;
        struct sockaddr_storage sender;
 char *buf = (char *)malloc(10000);
 char *message;
 char name[1000];
        char *key;
        char *viewId;
 struct entry {
  char key[64];
  char value[64];
 };
 struct entry dumblist[32];
 memset(dumblist,0,sizeof(struct entry)*32);
 int nextfree = 0;
 struct entry *e = ((void *)0);
 printf ("msg pointer is 0x%p\n",message);
 while(1) {
  memset(&sender,0,sizeof(struct sockaddr_storage));
         unsigned int sendsize = sizeof(sender);
  printf("param recvfrom (%d, %p, %d, %d, %p, %p)\n",
   s, message, 10000, 0, &sender, &sendsize);
  int recvSize = recvfrom(s, buf, 10000, 0, (struct sockaddr *)&sender, &sendsize);
  if (recvSize <= 0){
   perror("recvfrom\n");
   _exit(-1);
  }
  inet_ntop(10, &sender, name, 1000);
  message = buf;
  printf("From: %s msg: %.*s\n", name,16, message);
                for (i=0; i < 2; i++) {
                    if (i == 0) {
                       key = strsep(&message, ":");
                    } else if (i == 1) {
                       viewId = strsep(&message, ":");
                    }
                }
  e = ((void *)0);
  for(i=0;i<nextfree;i++){
   if(strcmp(dumblist[i].key, key) == 0){
    e = &dumblist[i];
    break;
   }
  }
  if (e != ((void *)0)) {
                    printf("Key: %s Value %s\n", e->key, e->value);
                    double current_val = strtod(viewId, ((void *)0));
                    double previous_val = strtod(e->value, ((void *)0));
                    if ((current_val - previous_val) > 1 ) {
   printf("ERROR - missed packet from: %s - current %f previous %f \n",
    e->key, current_val, previous_val);
   exit(1);
                    } else {
   printf(" Update Key:%s old Value=%s, new Value=%s\n",e->key, e->value, viewId);
   strcpy(e->value, viewId);
   continue;
   }
  }else {
  printf("add new entry with key %s to list\n", key);
  strncpy(dumblist[nextfree].key,key,63);
  nextfree++;
  }
 }
}

variable_types:
s
unsigned int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
message
char *

variable_types:
name
char [1000]

variable_types:
key
char *

variable_types:
viewId
char *

variable_types: struct entry { char *key; void *data; } [32]

variable_types: nextfree int

variable_types: struct entry { char *key; void *data; } *

variable_types:
sendsize
unsigned int

variable_types: recvSize int


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

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

original_code:
void interrupts_end(interrupts *ir) {
 free(ir);
}

canonical_original_code:
void interrupts_end(struct interrupts *ir) {
 free(ir);
}

variable_types: struct interrupts { struct { unsigned char flags; unsigned char enable; } reg; } *


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

*a1 |= a2;
result = activate_debug;
if ( activate_debug )
{
fprintf(stdout, "Raising %X\n", (unsigned __int8)a1[1]);
result = fflush(stdout);
}
return result;
}

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

*a1 |= a2;
result = activate_debug;
if ( activate_debug )
{
fprintf(stdout, "Raising %X\n", (unsigned __int8)a1[1]);
result = fflush(stdout);
}
return result;
}

original_code:
void interrupts_raise(interrupts *ir, IRQ_FLAGS num) {
 ir->reg.flags |= num;
 do { if (activate_debug) { fprintf(stdout, "Raising %X\n", ir->reg.enable); fflush(stdout); } } while (0);
}

canonical_original_code:
void interrupts_raise(struct interrupts *ir, enum IRQ_FLAGS num) {
 ir->reg.flags |= num;
 do { if (activate_debug) { fprintf(stdout, "Raising %X\n", ir->reg.enable); fflush(stdout); } } while (0);
}

variable_types: enum IRQ_FLAGS { IRQ_NONE=0, IRQ_VBLANK=expr, IRQ_LCD=expr, IRQ_TIMER=expr, IRQ_SERIAL=expr, IRQ_JOYPAD=expr }

user_defined_types: struct interrupts { struct { unsigned char flags; unsigned char enable; } reg; }


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

if ( a1 == 273 )
return 36LL;
if ( a1 > 0x111 )
{
result = 33LL;
if ( a1 != 275 )
{
if ( a1 == 276 )
{
result = 34LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 274 )
result = 40LL;
}
}
}
else
{
result = 20LL;
if ( a1 != 108 )
{
if ( a1 <= 0x6C )
{
result = 17LL;
if ( a1 != 97 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 98 )
result = 18LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 115 )
result = 24LL;
}
}
}
return result;
}

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

if ( a1 == 273 )
return 36LL;
if ( a1 > 0x111 )
{
result = 33LL;
if ( a1 != 275 )
{
if ( a1 == 276 )
{
result = 34LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 274 )
result = 40LL;
}
}
}
else
{
result = 20LL;
if ( a1 != 108 )
{
if ( a1 <= 0x6C )
{
result = 17LL;
if ( a1 != 97 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 98 )
result = 18LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 115 )
result = 24LL;
}
}
}
return result;
}

original_code:
static keyboard_key sdl_to_key(SDLKey key) {
 switch(key) {
 case SDLK_a:
  return KEY_A;
 case SDLK_b:
  return KEY_B;
 case SDLK_l:
  return KEY_SELECT;
 case SDLK_s:
  return KEY_START;
 case SDLK_RIGHT:
  return KEY_RIGHT;
 case SDLK_LEFT:
  return KEY_LEFT;
 case SDLK_UP:
  return KEY_UP;
 case SDLK_DOWN:
  return KEY_DOWN;
 default:
  return KEY_UNKNOWN;
 }
}

canonical_original_code:
static enum keyboard_key sdl_to_key(enum SDLKey key) {
 switch(key) {
 case SDLK_a:
  return KEY_A;
 case SDLK_b:
  return KEY_B;
 case SDLK_l:
  return KEY_SELECT;
 case SDLK_s:
  return KEY_START;
 case SDLK_RIGHT:
  return KEY_RIGHT;
 case SDLK_LEFT:
  return KEY_LEFT;
 case SDLK_UP:
  return KEY_UP;
 case SDLK_DOWN:
  return KEY_DOWN;
 default:
  return KEY_UNKNOWN;
 }
}

variable_types: enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 }

return_type: enum keyboard_key { KEY_UNKNOWN=-1, FIRST_COL=16, KEY_A=expr, KEY_B=expr, KEY_SELECT=expr, KEY_START=expr, SECOND_COL=32, KEY_RIGHT=expr, KEY_LEFT=expr, KEY_UP=expr, KEY_DOWN=expr }


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

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

original_code:
void keyboard_end(keyboard *kb) {
 free(kb);
}

canonical_original_code:
void keyboard_end(struct keyboard *kb) {
 free(kb);
}

variable_types: struct keyboard { struct { unsigned char joyp_first; unsigned char joyp_second; unsigned char active; } reg; } *


decompiled_code:
int __fastcall keyboard_pressed(unsigned __int8 *a1, unsigned int a2, __int64 a3)
{
int result; // eax

if ( (a2 & 0x10) != 0 )
{
*a1 &= ~(a2 - 16);
if ( ((unsigned __int8)a2 & a1[2]) == 0 )
goto LABEL_3;
}
else
{
if ( (a2 & 0x20) == 0 )
{
fprintf(stderr, "Unknown pressed key %X\n", a2);
_assert_fail("0", "src/keyboard.c", 0x1Fu, "keyboard_pressed");
}
a1[1] &= ~(a2 - 32);
if ( ((unsigned __int8)a2 & a1[2]) == 0 )
{
LABEL_3:
result = activate_debug;
if ( !activate_debug )
return result;
LABEL_8:
fprintf(stdout, "Key down %d -- %X - %X\n", a2, *a1, a1[1]);
return fflush(stdout);
}
}
interrupts_raise(a3, 16LL);
result = activate_debug;
if ( activate_debug )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int8 *a1, unsigned int a2, __int64 a3)
{
int result; // eax

if ( (a2 & 0x10) != 0 )
{
*a1 &= ~(a2 - 16);
if ( ((unsigned __int8)a2 & a1[2]) == 0 )
goto LABEL_3;
}
else
{
if ( (a2 & 0x20) == 0 )
{
fprintf(stderr, "Unknown pressed key %X\n", a2);
_assert_fail("0", "src/keyboard.c", 0x1Fu, "keyboard_pressed");
}
a1[1] &= ~(a2 - 32);
if ( ((unsigned __int8)a2 & a1[2]) == 0 )
{
LABEL_3:
result = activate_debug;
if ( !activate_debug )
return result;
LABEL_8:
fprintf(stdout, "Key down %d -- %X - %X\n", a2, *a1, a1[1]);
return fflush(stdout);
}
}
interrupts_raise(a3, 16LL);
result = activate_debug;
if ( activate_debug )
goto LABEL_8;
return result;
}

original_code:
void keyboard_pressed(keyboard* kb, keyboard_key key, interrupts *ir) {
 if (key & FIRST_COL)
  kb->reg.joyp_first = kb->reg.joyp_first & ~(key - FIRST_COL);
 else if (key & SECOND_COL)
  kb->reg.joyp_second = kb->reg.joyp_second & ~(key - SECOND_COL);
 else
  do { fprintf(stderr, "Unknown pressed key %X\n", key); ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/keyboard.c", 31, __extension__ __PRETTY_FUNCTION__); })); } while (0);
 if (key & kb->reg.active)
  interrupts_raise(ir, IRQ_JOYPAD);
 do { if (activate_debug) { fprintf(stdout, "Key down %d -- %X - %X\n", key, kb->reg.joyp_first, kb->reg.joyp_second); fflush(stdout); } } while (0);
}

canonical_original_code:
void keyboard_pressed(struct keyboard *kb, enum keyboard_key key, struct interrupts *ir) {
 if (key & FIRST_COL)
  kb->reg.joyp_first = kb->reg.joyp_first & ~(key - FIRST_COL);
 else if (key & SECOND_COL)
  kb->reg.joyp_second = kb->reg.joyp_second & ~(key - SECOND_COL);
 else
  do { fprintf(stderr, "Unknown pressed key %X\n", key); ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/keyboard.c", 31, __extension__ __PRETTY_FUNCTION__); })); } while (0);
 if (key & kb->reg.active)
  interrupts_raise(ir, IRQ_JOYPAD);
 do { if (activate_debug) { fprintf(stdout, "Key down %d -- %X - %X\n", key, kb->reg.joyp_first, kb->reg.joyp_second); fflush(stdout); } } while (0);
}

variable_types: enum keyboard_key { KEY_UNKNOWN=-1, FIRST_COL=16, KEY_A=expr, KEY_B=expr, KEY_SELECT=expr, KEY_START=expr, SECOND_COL=32, KEY_RIGHT=expr, KEY_LEFT=expr, KEY_UP=expr, KEY_DOWN=expr }

user_defined_types: struct keyboard { struct { unsigned char joyp_first; unsigned char joyp_second; unsigned char active; } reg; }


decompiled_code:
int __fastcall keyboard_released(unsigned __int8 *a1, unsigned int a2)
{
int result; // eax

if ( (a2 & 0x10) != 0 )
{
*a1 |= (_BYTE)a2 - 16;
result = activate_debug;
if ( !activate_debug )
return result;
LABEL_6:
fprintf(stdout, "Key up %d -- %X - %X\n", a2, *a1, a1[1]);
return fflush(stdout);
}
if ( (a2 & 0x20) == 0 )
{
fprintf(stderr, "Unknown released key %X\n", a2);
_assert_fail("0", "src/keyboard.c", 0x2Eu, "keyboard_released");
}
a1[1] |= (_BYTE)a2 - 32;
result = activate_debug;
if ( activate_debug )
goto LABEL_6;
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 *a1, unsigned int a2)
{
int result; // eax

if ( (a2 & 0x10) != 0 )
{
*a1 |= (_BYTE)a2 - 16;
result = activate_debug;
if ( !activate_debug )
return result;
LABEL_6:
fprintf(stdout, "Key up %d -- %X - %X\n", a2, *a1, a1[1]);
return fflush(stdout);
}
if ( (a2 & 0x20) == 0 )
{
fprintf(stderr, "Unknown released key %X\n", a2);
_assert_fail("0", "src/keyboard.c", 0x2Eu, "keyboard_released");
}
a1[1] |= (_BYTE)a2 - 32;
result = activate_debug;
if ( activate_debug )
goto LABEL_6;
return result;
}

original_code:
void keyboard_released(keyboard* kb, keyboard_key key, interrupts *ir) {
 if (key & FIRST_COL)
  kb->reg.joyp_first = kb->reg.joyp_first | (key - FIRST_COL);
 else if (key & SECOND_COL)
  kb->reg.joyp_second = kb->reg.joyp_second | (key - SECOND_COL);
 else
  do { fprintf(stderr, "Unknown released key %X\n", key); ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/keyboard.c", 46, __extension__ __PRETTY_FUNCTION__); })); } while (0);
 do { if (activate_debug) { fprintf(stdout, "Key up %d -- %X - %X\n", key, kb->reg.joyp_first, kb->reg.joyp_second); fflush(stdout); } } while (0);
}

canonical_original_code:
void keyboard_released(struct keyboard *kb, enum keyboard_key key, struct interrupts *ir) {
 if (key & FIRST_COL)
  kb->reg.joyp_first = kb->reg.joyp_first | (key - FIRST_COL);
 else if (key & SECOND_COL)
  kb->reg.joyp_second = kb->reg.joyp_second | (key - SECOND_COL);
 else
  do { fprintf(stderr, "Unknown released key %X\n", key); ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/keyboard.c", 46, __extension__ __PRETTY_FUNCTION__); })); } while (0);
 do { if (activate_debug) { fprintf(stdout, "Key up %d -- %X - %X\n", key, kb->reg.joyp_first, kb->reg.joyp_second); fflush(stdout); } } while (0);
}

user_defined_types: enum keyboard_key { KEY_UNKNOWN=-1, FIRST_COL=16, KEY_A=expr, KEY_B=expr, KEY_SELECT=expr, KEY_START=expr, SECOND_COL=32, KEY_RIGHT=expr, KEY_LEFT=expr, KEY_UP=expr, KEY_DOWN=expr }


decompiled_code:
void __fastcall sig_handler(int a1)
{
if ( a1 == 2 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
exit(0);
}

original_code:
void sig_handler(int signo)
{
 if (signo == 2)
  exit(0);
}

variable_types: signo int


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

original_code:
void timer_end(timer* t) {
 free(t);
}

canonical_original_code:
void timer_end(struct timer *t) {
 free(t);
}

variable_types: struct timer { struct { unsigned char divider; unsigned char counter; unsigned char modulo; unsigned char control; unsigned char tick_divider; unsigned char tick_counter; } reg; } *


decompiled_code:
__int64 __fastcall timer_process(_BYTE *a1, __int64 a2, char a3)
{
__int64 result; // rax
unsigned __int8 v4; // cl
unsigned __int8 v5; // dl
__int16 v6; // cx
bool v7; // zf
int v8; // eax

result = a1[3] & 3;
if ( (a1[3] & 3) != 0 )
{
v4 = a3 + a1[4];
v5 = a1[5] + a3;
a1[4] = v4;
a1[5] = v5;
if ( v4 > 0x3Fu )
{
++*a1;
a1[4] = v4 - 64;
}
v6 = 16;
if ( (_BYTE)result != 2 )
{
v7 = (_BYTE)result == 3;
v6 = 4;
result = 64LL;
if ( v7 )
v6 = 64;
}
if ( v5 >= (unsigned __int16)v6 )
{
v8 = (unsigned __int8)a1[1];
if ( (_BYTE)v8 == 0xFF )
{
a1[1] = a1[2];
result = interrupts_raise(a2, 4LL);
}
else
{
result = (unsigned int)(v8 + 1);
a1[1] = result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2, char a3)
{
__int64 result; // rax
unsigned __int8 v4; // cl
unsigned __int8 v5; // dl
__int16 v6; // cx
bool v7; // zf
int v8; // eax

result = a1[3] & 3;
if ( (a1[3] & 3) != 0 )
{
v4 = a3 + a1[4];
v5 = a1[5] + a3;
a1[4] = v4;
a1[5] = v5;
if ( v4 > 0x3Fu )
{
++*a1;
a1[4] = v4 - 64;
}
v6 = 16;
if ( (_BYTE)result != 2 )
{
v7 = (_BYTE)result == 3;
v6 = 4;
result = 64LL;
if ( v7 )
v6 = 64;
}
if ( v5 >= (unsigned __int16)v6 )
{
v8 = (unsigned __int8)a1[1];
if ( (_BYTE)v8 == 0xFF )
{
a1[1] = a1[2];
result = interrupts_raise(a2, 4LL);
}
else
{
result = (unsigned int)(v8 + 1);
a1[1] = result;
}
}
}
return result;
}

original_code:
void timer_process(timer* t, interrupts *ir , uint16_t clk) {
 if ((t->reg.control & 0x3) == 0)
  return;
 t->reg.tick_divider += clk;
 t->reg.tick_counter += clk;
 if (t->reg.tick_divider >= 64) {
  t->reg.tick_divider -= 64;
  t->reg.divider++;
 }
 uint16_t threshold = 0;
 switch(t->reg.control & 0x3) {
 case 0:
  threshold = 64 * 4;
  break;
 case 1:
  threshold = 1 * 4;
  break;
 case 2:
  threshold = 4 * 4;
  break;
 case 3:
  threshold = 16 * 4;
  break;
 }
 if (t->reg.tick_counter >= threshold) {
  if (t->reg.counter == 0xFF) {
   t->reg.counter = t->reg.modulo;
   interrupts_raise(ir, IRQ_TIMER);
  } else {
   t->reg.counter++;
  }
 }
}

canonical_original_code:
void timer_process(struct timer *t, struct interrupts *ir, unsigned short clk) {
 if ((t->reg.control & 0x3) == 0)
  return;
 t->reg.tick_divider += clk;
 t->reg.tick_counter += clk;
 if (t->reg.tick_divider >= 64) {
  t->reg.tick_divider -= 64;
  t->reg.divider++;
 }
 unsigned short threshold = 0;
 switch(t->reg.control & 0x3) {
 case 0:
  threshold = 64 * 4;
  break;
 case 1:
  threshold = 1 * 4;
  break;
 case 2:
  threshold = 4 * 4;
  break;
 case 3:
  threshold = 16 * 4;
  break;
 }
 if (t->reg.tick_counter >= threshold) {
  if (t->reg.counter == 0xFF) {
   t->reg.counter = t->reg.modulo;
   interrupts_raise(ir, IRQ_TIMER);
  } else {
   t->reg.counter++;
  }
 }
}

variable_types:
clk
unsigned short

variable_types:
threshold
unsigned short

user_defined_types: struct timer { struct { unsigned char divider; unsigned char counter; unsigned char modulo; unsigned char control; unsigned char tick_divider; unsigned char tick_counter; } reg; }


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
printf("Usage : %s [ -logo ] <rom_filename>\n", a1);
return puts("\t-logo (optional) : print logo");
}

canonical_decompiled_code:
int __fastcall func12(const char *a1)
{
printf("Usage : %s [ -logo ] <rom_filename>\n", a1);
return puts("\t-logo (optional) : print logo");
}

original_code:
void usage(const char* program_name)
{
 printf("Usage : %s [ -logo ] <rom_filename>\n", program_name);
 printf("\t-logo (optional) : print logo\n");
}

canonical_original_code:
void usage(char *program_name)
{
 printf("Usage : %s [ -logo ] <rom_filename>\n", program_name);
 printf("\t-logo (optional) : print logo\n");
}


zerr

decompiled_code:
unsigned int __fastcall zerr(unsigned int a1)
{
unsigned int result; // eax

result = fwrite("zpipe: ", 1uLL, 7uLL, stderr);
if ( a1 >= 0xFFFFFFFA )
{
result = a1 + 6;
switch ( a1 )
{
case 0xFFFFFFFA:
result = fwrite("zlib version mismatch!\n", 1uLL, 0x17uLL, stderr);
break;
case 0xFFFFFFFB:
return result;
case 0xFFFFFFFC:
result = fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
break;
case 0xFFFFFFFD:
result = fwrite("invalid or incomplete deflate data\n", 1uLL, 0x23uLL, stderr);
break;
case 0xFFFFFFFE:
result = fwrite("invalid compression level\n", 1uLL, 0x1AuLL, stderr);
break;
case 0xFFFFFFFF:
if ( ferror(stdin) )
fwrite("error reading stdin\n", 1uLL, 0x14uLL, stderr);
result = ferror(stdout);
if ( result )
result = fwrite("error writing stdout\n", 1uLL, 0x15uLL, stderr);
break;
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func0(unsigned int a1)
{
unsigned int result; // eax

result = fwrite("zpipe: ", 1uLL, 7uLL, stderr);
if ( a1 >= 0xFFFFFFFA )
{
result = a1 + 6;
switch ( a1 )
{
case 0xFFFFFFFA:
result = fwrite("zlib version mismatch!\n", 1uLL, 0x17uLL, stderr);
break;
case 0xFFFFFFFB:
return result;
case 0xFFFFFFFC:
result = fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
break;
case 0xFFFFFFFD:
result = fwrite("invalid or incomplete deflate data\n", 1uLL, 0x23uLL, stderr);
break;
case 0xFFFFFFFE:
result = fwrite("invalid compression level\n", 1uLL, 0x1AuLL, stderr);
break;
case 0xFFFFFFFF:
if ( ferror(stdin) )
fwrite("error reading stdin\n", 1uLL, 0x14uLL, stderr);
result = ferror(stdout);
if ( result )
result = fwrite("error writing stdout\n", 1uLL, 0x15uLL, stderr);
break;
}
}
return result;
}

original_code:
void zerr(int ret)
{
    fputs("zpipe: ", stderr);
    switch (ret) {
    case (-1):
        if (ferror(stdin))
            fputs("error reading stdin\n", stderr);
        if (ferror(stdout))
            fputs("error writing stdout\n", stderr);
        break;
    case (-2):
        fputs("invalid compression level\n", stderr);
        break;
    case (-3):
        fputs("invalid or incomplete deflate data\n", stderr);
        break;
    case (-4):
        fputs("out of memory\n", stderr);
        break;
    case (-6):
        fputs("zlib version mismatch!\n", stderr);
    }
}

variable_types: ret int


escape

repo: Hypersonic/boash

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

result = 92LL;
if ( a1 != 92 )
result = 0LL;
return result;
}

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

result = 92LL;
if ( a1 != 92 )
result = 0LL;
return result;
}

original_code:
char escape(char c) {
 switch (c) {
  case '\\': return '\\';
  default : return '\0';
 }
 return 0;
}

variable_types: c char

return_type: char


tabcomplete

decompiled_code:
void tabcomplete()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void tabcomplete(char * line, int n, int i) {
}

canonical_original_code:
void tabcomplete(char *line, int n, int i) {
}

variable_types:
line
char *

variable_types: n int

variable_types: i int


destroyTokenList

decompiled_code:
void __fastcall destroyTokenList(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
free(ptr);
}

original_code:
void destroyTokenList(char ** tokenList) {
 int i;
 for (i = 0; tokenList[i]; i++)
  free(tokenList[i]);
 tokenList[0] = 0;
 free(tokenList);
}

canonical_original_code:
void destroyTokenList(char **tokenList) {
 int i;
 for (i = 0; tokenList[i]; i++)
  free(tokenList[i]);
 tokenList[0] = 0;
 free(tokenList);
}

variable_types:
tokenList
char **


sigHandler

decompiled_code:
void __fastcall sigHandler(int a1)
{
if ( a1 == 2 )
{
printf("^C");
}
else if ( a1 == 3 )
{
fwrite("Finally!\n", 1uLL, 9uLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
{
printf("^C");
}
else if ( a1 == 3 )
{
fwrite("Finally!\n", 1uLL, 9uLL, stderr);
}
}

original_code:
void sigHandler(int signum) {
 int reading;
 if (signum == 2) {
  printf("^C");
 }
 if (signum == 3) {
  fprintf(stderr, "Finally!\n");
 }
}

variable_types: signum int

variable_types: reading int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
bool v4; // cf
bool v5; // zf
const char **v6; // rax
__int64 v7; // rcx
const char *v8; // rdi
const char **v9; // rbp
const char *v10; // rax
const char *v11; // rsi
const char *v12; // rdi
__pid_t v13; // eax
char *v14; // rax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-81Ch] BYREF
char buf[1048]; // [rsp+410h] [rbp-418h] BYREF

if ( signal(2, sigHandler) != (__sighandler_t)-1LL )
{
if ( signal(3, sigHandler) != (__sighandler_t)-1LL )
{
while ( 1 )
{
getcwd(buf, 0x400uLL);
printf("%s %% ", buf);
getNextLine((char *)&stat_loc.__iptr + 4, 1024LL);
*((_BYTE *)&stat_loc.__iptr + strlen((const char *)&stat_loc.__iptr + 4) + 4) = 0;
v3 = getTokens((char *)&stat_loc.__iptr + 4);
v6 = (const char **)cleanTokenList(v3);
v7 = 5LL;
v8 = "exit";
v9 = v6;
v10 = *v6;
v11 = v10;
do
{
if ( !v7 )
break;
v4 = *v11 < (unsigned int)*v8;
v5 = *v11++ == *v8++;
--v7;
}
while ( v5 );
if ( (!v4 && !v5) == v4 )
break;
if ( *v10 == 99 && v10[1] == 100 && !v10[2] )
{
v12 = v9[1];
if ( v12 )
{
if ( chdir(v12) )
printf("cd: %s: no such directory", v11);
}
else
{
v14 = getenv("HOME");
chdir(v14);
}
}
else
{
if ( *v10 )
{
v13 = fork();
if ( !v13 )
{
execvp(*v9, (char *const *)v9);
printf("boash: no such command: %s\n", *v9);
exit(-1);
}
if ( v13 == -1 )
printf("Aw, shit.");
wait((__WAIT_STATUS)&stat_loc);
}
destroyTokenList(v9, v11);
BYTE4(stat_loc.__iptr) = 0;
}
}
exit(0);
}
printf("SIGQUITE handler failed");
exit(-1);
}
printf("SIGINT handler failed");
exit(-1);
}

original_code:
int main() {
 char ** tokenList, line[1024], cwd[1024];
 int pid, s;
 if (signal(2, sigHandler) == ((__sighandler_t) -1)) {
  printf("SIGINT handler failed");
  exit(-1);
 }
 if (signal(3, sigHandler) == ((__sighandler_t) -1)) {
  printf("SIGQUITE handler failed");
  exit(-1);
 }
 while (1) {
  getcwd(cwd, sizeof(cwd));
  printf("%s %% ", cwd);
  getNextLine(line, 1024);
  line[strlen(line)] = 0;
  tokenList = getTokens(line);
  tokenList = cleanTokenList(tokenList);
  if (!strcmp(tokenList[0], "exit")) {
   exit(0);
  }
  if (!strcmp(tokenList[0], "cd")) {
   if (tokenList[1]) {
    if (chdir(tokenList[1])) {
     printf("cd: %s: no such directory");
    }
   } else {
    chdir(getenv("HOME"));
   }
   continue;
  }
  if (tokenList[0][0]) {
   pid = fork();
   if (pid) {
    if (pid == -1)
     printf("Aw, shit.");
    wait(&s);
   } else {
    execvp(tokenList[0], tokenList);
    printf("boash: no such command: %s\n", tokenList[0]);
    exit(-1);
   }
  }
  destroyTokenList(tokenList);
  line[0] = 0;
 }
 return 0;
}

canonical_original_code:
int main() {
 char **tokenList; char line[1024]; char cwd[1024];
 int pid; int s;
 if (signal(2, sigHandler) == ((__sighandler_t) -1)) {
  printf("SIGINT handler failed");
  exit(-1);
 }
 if (signal(3, sigHandler) == ((__sighandler_t) -1)) {
  printf("SIGQUITE handler failed");
  exit(-1);
 }
 while (1) {
  getcwd(cwd, sizeof(cwd));
  printf("%s %% ", cwd);
  getNextLine(line, 1024);
  line[strlen(line)] = 0;
  tokenList = getTokens(line);
  tokenList = cleanTokenList(tokenList);
  if (!strcmp(tokenList[0], "exit")) {
   exit(0);
  }
  if (!strcmp(tokenList[0], "cd")) {
   if (tokenList[1]) {
    if (chdir(tokenList[1])) {
     printf("cd: %s: no such directory");
    }
   } else {
    chdir(getenv("HOME"));
   }
   continue;
  }
  if (tokenList[0][0]) {
   pid = fork();
   if (pid) {
    if (pid == -1)
     printf("Aw, shit.");
    wait(&s);
   } else {
    execvp(tokenList[0], tokenList);
    printf("boash: no such command: %s\n", tokenList[0]);
    exit(-1);
   }
  }
  destroyTokenList(tokenList);
  line[0] = 0;
 }
 return 0;
}

variable_types:
line
char [1024]

variable_types:
cwd
char [1024]

variable_types: pid int

variable_types: s int


similarity

decompiled_code:
__int64 __fastcall similarity(char *haystack, char *needle)
{
unsigned int v2; // er12
char *v3; // r13
signed int v4; // ebx

v2 = 0;
v3 = strstr(haystack, needle);
v4 = (unsigned int)strcasestr(haystack, needle);
if ( v3 )
v2 = 2 * strlen(v3);
if ( v4 )
v2 += strlen((const char *)v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *haystack, char *needle)
{
unsigned int v2; // er12
char *v3; // r13
signed int v4; // ebx

v2 = 0;
v3 = strstr(haystack, needle);
v4 = (unsigned int)strcasestr(haystack, needle);
if ( v3 )
v2 = 2 * strlen(v3);
if ( v4 )
v2 += strlen((const char *)v4);
return v2;
}

original_code:
int similarity(char* s1, char* s2) {
    int i;
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    int score = 0;
    char* withcase = strstr(s1, s2);
    char* non_case = strcasestr(s1, s2);
    score += strlen(withcase!=((void *)0) ? withcase : "") * 2;
    score += strlen(non_case!=((void *)0) ? non_case : "");
    return score;
}

canonical_original_code:
int similarity(char *s1, char *s2) {
    int i;
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    int score = 0;
    char *withcase = strstr(s1, s2);
    char *non_case = strcasestr(s1, s2);
    score += strlen(withcase!=((void *)0) ? withcase : "") * 2;
    score += strlen(non_case!=((void *)0) ? non_case : "");
    return score;
}

variable_types: score int

variable_types:
withcase
char *