decompiled_code:
__int64 next_sample()
{
int v0; // ebx
char v1; // al
char v2; // dl
char v3; // r12
char v4; // r13
char v5; // al
int v6; // ebp
char v7; // cl
unsigned int v8; // edx
unsigned int v9; // er14
__int16 v11; // ax
__int16 v12; // ax

v0 = (unsigned __int16)t_16;
if ( (t_16 & 0x7F) != 0 )
{
barevent_14 = 0;
v4 = 0;
v3 = 0;
goto LABEL_22;
}
if ( !t_16 )
{
timer_15 = 0;
v2 = barevent_14;
v1 = 0;
goto LABEL_48;
}
v1 = timer_15 + 1;
timer_15 = v1;
v2 = barevent_14;
barevent_14 |= 0x40u;
if ( (v1 & 1) == 0 )
LABEL_48:
barevent_14 = v2 | 0x60;
if ( (v1 & 3) == 0 )
barevent_14 |= 0x10u;
if ( (v1 & 7) == 0 )
barevent_14 |= 8u;
if ( (v1 & 0xF) == 0 )
barevent_14 |= 4u;
if ( (v1 & 0x1F) == 0 )
barevent_14 |= 2u;
if ( (v1 & 0x3F) == 0 )
barevent_14 |= 1u;
v3 = barevent_14;
v4 = barevent_14 & 8;
if ( (barevent_14 & 8) != 0 )
{
if ( (unsigned __int8)current_tone_13 >> 5 == note_rep_cnt_12 )
{
note_rep_cnt_12 = 0;
current_tone_13 = next_note();
}
else
{
++note_rep_cnt_12;
}
if ( (current_tone_13 & 1) != 0 )
next_sin_time_10 = v0 + (unsigned __int8)octave_delay[current_tone_13 & 0x3F];
else
next_sin_time_10 = 0;
}
if ( (v3 & 1) != 0 )
++bars_9;
LABEL_22:
if ( (bars_9 & 0xF) == 0 )
{
v5 = pc_8 + 1;
if ( pc_8 == 3 )
v5 = 0;
pc_8 = v5;
}
synthold1_7 = synth1_5;
v6 = (unsigned __int8)pc_8;
v7 = synth[2 * (unsigned __int8)pc_8];
v8 = ((((int)(unsigned __int16)v0 >> synth[2 * (unsigned __int8)pc_8 + 1]) & ~v0)
+ (v0 & ((int)(unsigned __int16)v0 >> v7))) & 0xFFFFFFF0;
synth1_5 = ((((int)(unsigned __int16)v0 >> synth[2 * (unsigned __int8)pc_8 + 1]) & ~(_BYTE)v0)
+ (v0 & ((int)(unsigned __int16)v0 >> v7))) & 0xF0;
if ( (_WORD)v0 == next_sin_time_10 )
{
if ( (current_tone_13 & 0x3F) == 25 )
{
synth2_4 = 0;
}
else
{
next_sin_time_10 += (unsigned __int8)octave_delay[current_tone_13 & 0x3F];
synth2_4 = ~synth2_4;
}
}
v9 = ((unsigned __int8)v8 >> 1) + ((unsigned __int8)synth2_4 >> 1);
if ( v4 && snare[(unsigned __int8)pc_8] )
{
snaredelay_3 = 200;
LABEL_30:
v9 ^= (8 * (unsigned __int8)next_rnd()) & 0x38;
goto LABEL_31;
}
v11 = snaredelay_3;
if ( snaredelay_3 )
{
--snaredelay_3;
if ( v11 != 1 )
goto LABEL_30;
}
LABEL_31:
if ( (v3 & 4) != 0 && bassdrum[v6] )
{
bassdelay_2 = 800;
LABEL_34:
v9 = (unsigned __int8)get_sin((unsigned __int16)v0 >> 7);
goto LABEL_35;
}
v12 = bassdelay_2;
if ( bassdelay_2 )
{
--bassdelay_2;
if ( v12 != 1 )
goto LABEL_34;
}
LABEL_35:
t_16 = v0 + 1;
return v9;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
char v1; // al
char v2; // dl
char v3; // r12
char v4; // r13
char v5; // al
int v6; // ebp
char v7; // cl
unsigned int v8; // edx
unsigned int v9; // er14
__int16 v11; // ax
__int16 v12; // ax

v0 = (unsigned __int16)t_16;
if ( (t_16 & 0x7F) != 0 )
{
barevent_14 = 0;
v4 = 0;
v3 = 0;
goto LABEL_22;
}
if ( !t_16 )
{
timer_15 = 0;
v2 = barevent_14;
v1 = 0;
goto LABEL_48;
}
v1 = timer_15 + 1;
timer_15 = v1;
v2 = barevent_14;
barevent_14 |= 0x40u;
if ( (v1 & 1) == 0 )
LABEL_48:
barevent_14 = v2 | 0x60;
if ( (v1 & 3) == 0 )
barevent_14 |= 0x10u;
if ( (v1 & 7) == 0 )
barevent_14 |= 8u;
if ( (v1 & 0xF) == 0 )
barevent_14 |= 4u;
if ( (v1 & 0x1F) == 0 )
barevent_14 |= 2u;
if ( (v1 & 0x3F) == 0 )
barevent_14 |= 1u;
v3 = barevent_14;
v4 = barevent_14 & 8;
if ( (barevent_14 & 8) != 0 )
{
if ( (unsigned __int8)current_tone_13 >> 5 == note_rep_cnt_12 )
{
note_rep_cnt_12 = 0;
current_tone_13 = func7();
}
else
{
++note_rep_cnt_12;
}
if ( (current_tone_13 & 1) != 0 )
next_sin_time_10 = v0 + (unsigned __int8)octave_delay[current_tone_13 & 0x3F];
else
next_sin_time_10 = 0;
}
if ( (v3 & 1) != 0 )
++bars_9;
LABEL_22:
if ( (bars_9 & 0xF) == 0 )
{
v5 = pc_8 + 1;
if ( pc_8 == 3 )
v5 = 0;
pc_8 = v5;
}
synthold1_7 = synth1_5;
v6 = (unsigned __int8)pc_8;
v7 = synth[2 * (unsigned __int8)pc_8];
v8 = ((((int)(unsigned __int16)v0 >> synth[2 * (unsigned __int8)pc_8 + 1]) & ~v0)
+ (v0 & ((int)(unsigned __int16)v0 >> v7))) & 0xFFFFFFF0;
synth1_5 = ((((int)(unsigned __int16)v0 >> synth[2 * (unsigned __int8)pc_8 + 1]) & ~(_BYTE)v0)
+ (v0 & ((int)(unsigned __int16)v0 >> v7))) & 0xF0;
if ( (_WORD)v0 == next_sin_time_10 )
{
if ( (current_tone_13 & 0x3F) == 25 )
{
synth2_4 = 0;
}
else
{
next_sin_time_10 += (unsigned __int8)octave_delay[current_tone_13 & 0x3F];
synth2_4 = ~synth2_4;
}
}
v9 = ((unsigned __int8)v8 >> 1) + ((unsigned __int8)synth2_4 >> 1);
if ( v4 && snare[(unsigned __int8)pc_8] )
{
snaredelay_3 = 200;
LABEL_30:
v9 ^= (8 * (unsigned __int8)func9()) & 0x38;
goto LABEL_31;
}
v11 = snaredelay_3;
if ( snaredelay_3 )
{
--snaredelay_3;
if ( v11 != 1 )
goto LABEL_30;
}
LABEL_31:
if ( (v3 & 4) != 0 && bassdrum[v6] )
{
bassdelay_2 = 800;
LABEL_34:
v9 = (unsigned __int8)func8((unsigned __int16)v0 >> 7);
goto LABEL_35;
}
v12 = bassdelay_2;
if ( bassdelay_2 )
{
--bassdelay_2;
if ( v12 != 1 )
goto LABEL_34;
}
LABEL_35:
t_16 = v0 + 1;
return v9;
}

original_code:
uint8_t next_sample()
{
static uint16_t t=0;
static uint8_t timer =0;
static uint8_t barevent=0;
static uint8_t bars=0;
static uint8_t pc = 0;
static uint8_t arpeggiocnt = 1;
static uint16_t next_sin_time = 0;
static uint8_t current_tone = 25;
static uint8_t current_tone_base = 25;
static unsigned short snaredelay = 0;
static unsigned short bassdelay = 0;
static uint8_t synth1 = 0;
static uint8_t synth2 = 0;
static uint8_t sin_speed = 4;
static uint8_t note_rep_cnt = 0;
if(t%128 == 0)
{
 if(t==0) timer = 0;
 else ++timer;
 barevent |= 64;
 if(timer%2 == 0) barevent |= 32;
 if(timer%4 == 0) barevent |= 16;
 if(timer%8 == 0) barevent |= 8;
 if(timer%16 == 0) barevent |= 4;
 if(timer%32 == 0) barevent |= 2;
 if(timer%64 == 0) barevent |= 1;
}
else barevent = 0;
if(barevent & 8)
{
 if(note_rep_cnt == (current_tone>>5))
 {
  note_rep_cnt = 0;
  current_tone = current_tone_base = next_note();
 }
 else ++note_rep_cnt;
 if(current_tone&~((0x40)|(0x80)) != 25)
  next_sin_time = t + octave_delay[current_tone&~((0x40)|(0x80))];
 else
  next_sin_time = 0;
}
if(barevent & 1) ++bars;
if(bars % 16 == 0)
{
 ++pc;
 if(pc == (4))
  pc = 0;
}
static uint8_t synthold1 = 0;
static uint8_t synthold2 = 0;
synthold2 = synthold1;
synthold1 = synth1;
synth1 = 0xfff0 & ( (t&t>>(synth[pc].a)) + (~t&t>>(synth[pc].b)) );
if(t == next_sin_time)
{
 if((current_tone&~((0x40)|(0x80))) != 25)
 {
   next_sin_time += octave_delay[current_tone&~((0x40)|(0x80))];
  synth2 = ~synth2;
 }
 else synth2 = 0;
}
unsigned int mix = (synth1>>1) + (synth2>>1);
if(barevent & 8 && snare[pc]) snaredelay = 200;
else if(snaredelay > 0) --snaredelay;
if(snaredelay>0) mix ^= (next_rnd() & 7) << 3;
if(barevent & 4 && bassdrum[pc]) bassdelay = 800;
else if(bassdelay > 0) --bassdelay;
if(bassdelay>0) mix = get_sin(t>>7);
++t;
return mix;
}

canonical_original_code:
unsigned char next_sample()
{
static unsigned short t = 0;
static unsigned char timer = 0;
static unsigned char barevent = 0;
static unsigned char bars = 0;
static unsigned char pc = 0;
static unsigned char arpeggiocnt = 1;
static unsigned short next_sin_time = 0;
static unsigned char current_tone = 25;
static unsigned char current_tone_base = 25;
static unsigned short snaredelay = 0;
static unsigned short bassdelay = 0;
static unsigned char synth1 = 0;
static unsigned char synth2 = 0;
static unsigned char sin_speed = 4;
static unsigned char note_rep_cnt = 0;
if(t%128 == 0)
{
 if(t==0) timer = 0;
 else ++timer;
 barevent |= 64;
 if(timer%2 == 0) barevent |= 32;
 if(timer%4 == 0) barevent |= 16;
 if(timer%8 == 0) barevent |= 8;
 if(timer%16 == 0) barevent |= 4;
 if(timer%32 == 0) barevent |= 2;
 if(timer%64 == 0) barevent |= 1;
}
else barevent = 0;
if(barevent & 8)
{
 if(note_rep_cnt == (current_tone>>5))
 {
  note_rep_cnt = 0;
  current_tone = current_tone_base = next_note();
 }
 else ++note_rep_cnt;
 if(current_tone&~((0x40)|(0x80)) != 25)
  next_sin_time = t + octave_delay[current_tone&~((0x40)|(0x80))];
 else
  next_sin_time = 0;
}
if(barevent & 1) ++bars;
if(bars % 16 == 0)
{
 ++pc;
 if(pc == (4))
  pc = 0;
}
static unsigned char synthold1 = 0;
static unsigned char synthold2 = 0;
synthold2 = synthold1;
synthold1 = synth1;
synth1 = 0xfff0 & ( (t&t>>(synth[pc].a)) + (~t&t>>(synth[pc].b)) );
if(t == next_sin_time)
{
 if((current_tone&~((0x40)|(0x80))) != 25)
 {
   next_sin_time += octave_delay[current_tone&~((0x40)|(0x80))];
  synth2 = ~synth2;
 }
 else synth2 = 0;
}
unsigned int mix = (synth1>>1) + (synth2>>1);
if(barevent & 8 && snare[pc]) snaredelay = 200;
else if(snaredelay > 0) --snaredelay;
if(snaredelay>0) mix ^= (next_rnd() & 7) << 3;
if(barevent & 4 && bassdrum[pc]) bassdelay = 800;
else if(bassdelay > 0) --bassdelay;
if(bassdelay>0) mix = get_sin(t>>7);
++t;
return mix;
}

variable_types:
t
unsigned short

variable_types:
timer
unsigned char

variable_types:
barevent
unsigned char

variable_types:
bars
unsigned char

variable_types:
pc
unsigned char

variable_types:
arpeggiocnt
unsigned char

variable_types:
snaredelay
unsigned short

variable_types:
bassdelay
unsigned short

variable_types:
mix
unsigned int


main

canonical_name: main

repo: hdznrrd/noiseplug

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
while ( 1 )
{
argc = (unsigned __int8)next_sample(argc, argv, envp);
putchar(argc);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
while ( 1 )
{
argc = (unsigned __int8)func10(argc, argv, envp);
putchar(argc);
}
}

original_code:
int main()
{
 while(1) putchar(next_sample());
}

return_type: int


receiveData

decompiled_code:
unsigned int __fastcall receiveData(unsigned int a1)
{
unsigned int v1; // ebx
unsigned int result; // eax

printf("Wakeup by signal: %d from kernel\n", a1);
puts("Process will exit after 5 seconds...");
v1 = 5;
do
{
printf("%d\n", v1);
result = sleep(1u);
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func7(unsigned int a1)
{
unsigned int v1; // ebx
unsigned int result; // eax

printf("Wakeup by signal: %d from kernel\n", a1);
puts("Process will exit after 5 seconds...");
v1 = 5;
do
{
printf("%d\n", v1);
result = sleep(1u);
--v1;
}
while ( v1 );
return result;
}

original_code:
void receiveData(int n, siginfo_t *info, void* unused) {
    printf("Wakeup by signal: %d from kernel\n", n);
    printf("Process will exit after 5 seconds...\n");
    int i = 5;
    for(i = 5; i > 0; --i) {
        printf("%d\n", i);
        sleep(1);
    }
}

canonical_original_code:
void receiveData(int n, struct siginfo_t *info, void *unused) {
    printf("Wakeup by signal: %d from kernel\n", n);
    printf("Process will exit after 5 seconds...\n");
    int i = 5;
    for(i = 5; i > 0; --i) {
        printf("%d\n", i);
        sleep(1);
    }
}

variable_types: n int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
unused
void *

variable_types: i int

return_type: void

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct sigaction v4; // [rsp+0h] [rbp-A8h] BYREF

v4.sa_handler = (__sighandler_t)receiveData;
v4.sa_flags = 4;
sigaction(10, &v4, 0LL);
puts("Start to wait a signal...");
sleep(0x258u);
return 0;
}

original_code:
int main() {
    struct sigaction sig;
    sig.__sigaction_handler.sa_sigaction = receiveData;
    sig.sa_flags = 4;
    sigaction(10, &sig, ((void *)0));
    printf("Start to wait a signal...\n");
    sleep(600);
 return 0;
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }


repo: heckendorfc/cobra

decompiled_code:
__int64 __fastcall run_test(__int64 a1)
{
int v1; // ebp
void (__fastcall *v2)(_QWORD); // rax
void (__fastcall *v3)(_QWORD); // rax
unsigned int v4; // eax
unsigned int v5; // edx
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

*(_DWORD *)(a1 + 48) = -1;
*(_DWORD *)(a1 + 52) = 0;
*(_DWORD *)(a1 + 56) = 0;
v1 = 10;
do
{
v2 = *(void (__fastcall **)(_QWORD))(a1 + 16);
if ( v2 )
v2(*(_QWORD *)(a1 + 40));
gettimeofday(&tv, 0LL);
(*(void (__fastcall **)(_QWORD))(a1 + 24))(*(_QWORD *)(a1 + 40));
gettimeofday(&v7, 0LL);
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(*(_QWORD *)(a1 + 40));
v4 = get_runtime(&tv, &v7);
v5 = *(_DWORD *)(a1 + 56) + v4;
*(_DWORD *)(a1 + 56) = v5;
if ( *(_DWORD *)(a1 + 52) < v4 )
*(_DWORD *)(a1 + 52) = v4;
if ( *(_DWORD *)(a1 + 48) > v4 )
*(_DWORD *)(a1 + 48) = v4;
--v1;
}
while ( v1 );
result = 3435973837LL;
*(_DWORD *)(a1 + 56) = v5 / 0xA;
return result;
}

original_code:
void run_test(struct test *t){
 const int numruns=10;
 struct timeval start;
 struct timeval end;
 int i;
 unsigned int runtime;
 t->min=(0x7fffffff * 2U + 1U);
 t->max=0;
 t->avg=0;
 for(i=0;i<numruns;i++){
  if(t->pref)
   t->pref(t->arg);
  gettimeofday(&start,((void *)0));
  t->f(t->arg);
  gettimeofday(&end,((void *)0));
  if(t->postf)
   t->postf(t->arg);
  runtime=get_runtime(&start,&end);
  t->avg+=runtime;
  if(runtime>t->max)
   t->max=runtime;
  if(runtime<t->min)
   t->min=runtime;
 }
 t->avg/=numruns;
}

canonical_original_code:
void run_test(struct test *t){
 int numruns = 10;
 struct timeval start;
 struct timeval end;
 int i;
 unsigned int runtime;
 t->min=(0x7fffffff * 2U + 1U);
 t->max=0;
 t->avg=0;
 for(i=0;i<numruns;i++){
  if(t->pref)
   t->pref(t->arg);
  gettimeofday(&start,((void *)0));
  t->f(t->arg);
  gettimeofday(&end,((void *)0));
  if(t->postf)
   t->postf(t->arg);
  runtime=get_runtime(&start,&end);
  t->avg+=runtime;
  if(runtime>t->max)
   t->max=runtime;
  if(runtime<t->min)
   t->min=runtime;
 }
 t->avg/=numruns;
}

variable_types: struct test { struct test *next; char *name; void (*pref)(void *); void (*f)(void *); void (*postf)(void *); void *arg; unsigned int min; unsigned int max; unsigned int avg; } *

variable_types: numruns int

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
runtime
unsigned int


decompiled_code:
__int64 __fastcall bench_run(__int64 ***a1)
{
__int64 **i; // rbp
__int64 **j; // rbx

for ( i = *a1; i; i = (__int64 **)*i )
{
printf("Running group: %s\n", (const char *)i[1]);
for ( j = (__int64 **)i[2]; j; j = (__int64 **)*j )
{
printf("\tRunning test: %s\n", (const char *)j[1]);
run_test(j);
}
}
puts("\n");
return print_table(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 ***a1)
{
__int64 **i; // rbp
__int64 **j; // rbx

for ( i = *a1; i; i = (__int64 **)*i )
{
printf("Running group: %s\n", (const char *)i[1]);
for ( j = (__int64 **)i[2]; j; j = (__int64 **)*j )
{
printf("\tRunning test: %s\n", (const char *)j[1]);
run_test(j);
}
}
puts("\n");
return print_table(a1);
}

original_code:
void bench_run(BenchSet *bs){
 struct testgroup *tgp;
 struct test *tp;
 for(tgp=bs->list;tgp;tgp=tgp->next){
  printf("Running group: %s\n",tgp->name);
  for(tp=tgp->list;tp;tp=tp->next){
   printf("\tRunning test: %s\n",tp->name);
   run_test(tp);
  }
 }
 printf("\n\n");
 print_table(bs);
}

canonical_original_code:
void bench_run(struct BenchSet *bs){
 struct testgroup *tgp;
 struct test *tp;
 for(tgp=bs->list;tgp;tgp=tgp->next){
  printf("Running group: %s\n",tgp->name);
  for(tp=tgp->list;tp;tp=tp->next){
   printf("\tRunning test: %s\n",tp->name);
   run_test(tp);
  }
 }
 printf("\n\n");
 print_table(bs);
}

variable_types: struct BenchSet { struct testgroup { struct testgroup *next; char *name; struct test { struct test *next; char *name; void (*pref)(void *); void (*f)(void *); void (*postf)(void *); void *arg; unsigned int min; unsigned int max; unsigned int avg; } *list; } *list; } *

user_defined_types: struct BenchSet { struct testgroup *list; }

user_defined_types: struct testgroup { struct testgroup *next; char *name; struct test *list; }


decompiled_code:
void bench_free()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void bench_free(BenchSet *bs){
}

canonical_original_code:
void bench_free(struct BenchSet *bs){
}

user_defined_types: struct test { struct test *next; char *name; void (*pref)(void *); void (*f)(void *); void (*postf)(void *); void *arg; unsigned int min; unsigned int max; unsigned int avg; }


decompiled_code:
void __fastcall Token_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void Token_destroy(Token *token)
{
    if (token != ((void *)0)) {
        if (token->value != ((void *)0)) {
            free(token->value);
            token->value = ((void *)0);
        }
        free(token);
        token = ((void *)0);
    }
}

canonical_original_code:
void Token_destroy(struct Token *token)
{
    if (token != ((void *)0)) {
        if (token->value != ((void *)0)) {
            free(token->value);
            token->value = ((void *)0);
        }
        free(token);
        token = ((void *)0);
    }
}

variable_types: struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *

user_defined_types: struct Token { char *value; unsigned int begin; enum TOKEN_TYPE type; }


decompiled_code:
int init_terminal()
{
int v0; // eax
int v1; // eax

v0 = fileno(stdin);
tcgetattr(v0, &orig_term_attr);
*(__m128i *)&raw_term_attr.c_iflag = _mm_load_si128((const __m128i *)&orig_term_attr);
*(__m128i *)&raw_term_attr.c_line = _mm_load_si128((const __m128i *)&orig_term_attr.c_line);
*(__m128i *)&raw_term_attr.c_cc[15] = _mm_load_si128((const __m128i *)&orig_term_attr.c_cc[15]);
*(_QWORD *)&raw_term_attr.c_cc[31] = *(_QWORD *)&orig_term_attr.c_cc[31];
raw_term_attr.c_ospeed = orig_term_attr.c_ospeed;
raw_term_attr.c_lflag &= 0xFFFFFDFF;
v1 = fileno(stdin);
return tcsetattr(v1, 0, &raw_term_attr);
}

canonical_decompiled_code:
int func1()
{
int v0; // eax
int v1; // eax

v0 = fileno(stdin);
tcgetattr(v0, &orig_term_attr);
*(__m128i *)&raw_term_attr.c_iflag = _mm_load_si128((const __m128i *)&orig_term_attr);
*(__m128i *)&raw_term_attr.c_line = _mm_load_si128((const __m128i *)&orig_term_attr.c_line);
*(__m128i *)&raw_term_attr.c_cc[15] = _mm_load_si128((const __m128i *)&orig_term_attr.c_cc[15]);
*(_QWORD *)&raw_term_attr.c_cc[31] = *(_QWORD *)&orig_term_attr.c_cc[31];
raw_term_attr.c_ospeed = orig_term_attr.c_ospeed;
raw_term_attr.c_lflag &= 0xFFFFFDFF;
v1 = fileno(stdin);
return tcsetattr(v1, 0, &raw_term_attr);
}

original_code:
static void init_terminal(void)
{
    tcgetattr(fileno(stdin), &orig_term_attr);
    raw_term_attr = orig_term_attr;
    raw_term_attr.c_lflag &= (unsigned int) ~(0001000);
    tcsetattr(fileno(stdin), 0, &raw_term_attr);
}

canonical_original_code:
static void init_terminal()
{
    tcgetattr(fileno(stdin), &orig_term_attr);
    raw_term_attr = orig_term_attr;
    raw_term_attr.c_lflag &= (unsigned int) ~(0001000);
    tcsetattr(fileno(stdin), 0, &raw_term_attr);
}


decompiled_code:
int reset_terminal()
{
int v0; // eax

v0 = fileno(stdin);
return tcsetattr(v0, 0, &orig_term_attr);
}

canonical_decompiled_code:
int func2()
{
int v0; // eax

v0 = fileno(stdin);
return tcsetattr(v0, 0, &orig_term_attr);
}

original_code:
static void reset_terminal(void)
{
    tcsetattr(fileno(stdin), 0, &orig_term_attr);
}

canonical_original_code:
static void reset_terminal()
{
    tcsetattr(fileno(stdin), 0, &orig_term_attr);
}


decompiled_code:
__int64 command_unknown()
{
return IO_write("command not found\n");
}

canonical_decompiled_code:
__int64 func4()
{
return IO_write("command not found\n");
}

original_code:
static void command_unknown(void)
{
    IO_write("command not found\n");
}

canonical_original_code:
static void command_unknown()
{
    IO_write("command not found\n");
}


decompiled_code:
void __fastcall State_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void State_destroy(State *state)
{
    if (state != ((void *)0)) {
        if (state->transitions != ((void *)0)) {
            free(state->transitions);
            state->transitions = ((void *)0);
        }
        free(state);
        state = ((void *)0);
    }
}

canonical_original_code:
void State_destroy(struct State *state)
{
    if (state != ((void *)0)) {
        if (state->transitions != ((void *)0)) {
            free(state->transitions);
            state->transitions = ((void *)0);
        }
        free(state);
        state = ((void *)0);
    }
}

variable_types: struct State { unsigned long transition_count; unsigned int *transitions; } *


decompiled_code:
void __fastcall DFA_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void DFA_destroy(DFA *dfa)
{
    if (dfa != ((void *)0)) {
        if (dfa->states != ((void *)0)) {
            free(dfa->states);
            dfa->states = ((void *)0);
        }
        free(dfa);
        dfa = ((void *)0);
    }
}

canonical_original_code:
void DFA_destroy(struct DFA *dfa)
{
    if (dfa != ((void *)0)) {
        if (dfa->states != ((void *)0)) {
            free(dfa->states);
            dfa->states = ((void *)0);
        }
        free(dfa);
        dfa = ((void *)0);
    }
}

variable_types: struct DFA { unsigned long symbol_count; char **symbols; struct State { unsigned long transition_count; unsigned int *transitions; } *states; unsigned int *terminal_states; } *

user_defined_types: struct DFA { unsigned long symbol_count; char **symbols; struct State *states; unsigned int *terminal_states; }


decompiled_code:
__int64 __fastcall DFA_set_state(__int64 a1, unsigned int a2, _QWORD *a3)
{
__int64 v3; // rsi
__int64 result; // rax

if ( a1 && (unsigned __int64)a2 < *(_QWORD *)(a1 + 8) && a3 )
{
if ( a3[1] )
{
v3 = 16LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 32) + v3) = *a3;
result = *(_QWORD *)(a1 + 32);
*(_QWORD *)(result + v3 + 8) = a3[1];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, _QWORD *a3)
{
__int64 v3; // rsi
__int64 result; // rax

if ( a1 && (unsigned __int64)a2 < *(_QWORD *)(a1 + 8) && a3 )
{
if ( a3[1] )
{
v3 = 16LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 32) + v3) = *a3;
result = *(_QWORD *)(a1 + 32);
*(_QWORD *)(result + v3 + 8) = a3[1];
}
}
return result;
}

original_code:
void DFA_set_state(DFA *dfa,
                   const unsigned int state_index,
                   const State *state)
{
    if (dfa == ((void *)0)
        || state_index >= dfa->state_count
        || state == ((void *)0)
        || state->transitions == ((void *)0)
    ) {
        return;
    }
    dfa->states[state_index].transition_count = state->transition_count;
    dfa->states[state_index].transitions = state->transitions;
}

canonical_original_code:
void DFA_set_state(struct DFA *dfa, unsigned int state_index, struct State *state)
{
    if (dfa == ((void *)0)
        || state_index >= dfa->state_count
        || state == ((void *)0)
        || state->transitions == ((void *)0)
    ) {
        return;
    }
    dfa->states[state_index].transition_count = state->transition_count;
    dfa->states[state_index].transitions = state->transitions;
}

variable_types:
state
struct State *

user_defined_types: struct State { unsigned long transition_count; unsigned int *transitions; }


original_code:
void DFA_to_string(DFA *dfa)
{
    char temp[128];
    temp[0] = '\0';
    sprintf(temp, "%-2u", dfa->state_count);
    size_t row_length, column_offset;
    row_length = 0;
    column_offset = strlen(temp) + 1;
    printf("%*s| ",
           column_offset,
           "");
    unsigned int i;
    for (i = 0; i < dfa->symbol_count; ++i) {
        printf("%s   ", dfa->symbols[i]);
        size_t padding;
        padding = (i != (dfa->symbol_count - 1)) ? 3 : 1;
        row_length += strlen(dfa->symbols[i]) + padding;
    }
    printf("\n");
    for (i = 0; i < column_offset; ++i) {
        printf("-");
    }
    printf("+-");
    for (i = 0; i < row_length; ++i) {
        printf("-");
    }
    printf("\n");
    if (dfa->states == ((void *)0)) {
        return;
    }
    for (i = 0; i < dfa->state_count; ++i) {
        printf("%-*u| ",
               column_offset,
               i);
        unsigned int j;
        for (j = 0; j < dfa->states[i].transition_count; ++j) {
            if (dfa->states[i].transitions != ((void *)0) && dfa->symbols[j] != ((void *)0)) {
                printf("%u %*s",
                       dfa->states[i].transitions[j],
                       strlen(dfa->symbols[j]) + 1,
                       "");
            }
        }
        printf("\n");
    }
    printf("\n");
}

canonical_original_code:
void DFA_to_string(struct DFA *dfa)
{
    char temp[128];
    temp[0] = '\0';
    sprintf(temp, "%-2u", dfa->state_count);
    unsigned long row_length; unsigned long column_offset;
    row_length = 0;
    column_offset = strlen(temp) + 1;
    printf("%*s| ",
           column_offset,
           "");
    unsigned int i;
    for (i = 0; i < dfa->symbol_count; ++i) {
        printf("%s   ", dfa->symbols[i]);
        unsigned long padding;
        padding = (i != (dfa->symbol_count - 1)) ? 3 : 1;
        row_length += strlen(dfa->symbols[i]) + padding;
    }
    printf("\n");
    for (i = 0; i < column_offset; ++i) {
        printf("-");
    }
    printf("+-");
    for (i = 0; i < row_length; ++i) {
        printf("-");
    }
    printf("\n");
    if (dfa->states == ((void *)0)) {
        return;
    }
    for (i = 0; i < dfa->state_count; ++i) {
        printf("%-*u| ",
               column_offset,
               i);
        unsigned int j;
        for (j = 0; j < dfa->states[i].transition_count; ++j) {
            if (dfa->states[i].transitions != ((void *)0) && dfa->symbols[j] != ((void *)0)) {
                printf("%u %*s",
                       dfa->states[i].transitions[j],
                       strlen(dfa->symbols[j]) + 1,
                       "");
            }
        }
        printf("\n");
    }
    printf("\n");
}

variable_types:
temp
char [128]

variable_types:
i
unsigned int

variable_types:
padding
unsigned long

variable_types:
j
unsigned int


original_code:
static void clear_data(Lexer *lexer)
{
    if (lexer == ((void *)0) || lexer->tokens == ((void *)0)) {
        return;
    }
    unsigned int i;
    for (i = 0; i < lexer->token_count; ++i) {
        if (lexer->tokens[i].value != ((void *)0)) {
            free(lexer->tokens[i].value);
            lexer->tokens[i].value = ((void *)0);
        }
    }
    free(lexer->tokens);
    lexer->tokens = ((void *)0);
    lexer->token_count = 0;
}

canonical_original_code:
static void clear_data(struct Lexer *lexer)
{
    if (lexer == ((void *)0) || lexer->tokens == ((void *)0)) {
        return;
    }
    unsigned int i;
    for (i = 0; i < lexer->token_count; ++i) {
        if (lexer->tokens[i].value != ((void *)0)) {
            free(lexer->tokens[i].value);
            lexer->tokens[i].value = ((void *)0);
        }
    }
    free(lexer->tokens);
    lexer->tokens = ((void *)0);
    lexer->token_count = 0;
}

variable_types: struct Lexer { struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *tokens; unsigned long token_count; } *

user_defined_types: struct Lexer { struct Token *tokens; unsigned long token_count; }


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

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

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

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

original_code:
Lexer *Lexer_create(void)
{
    Lexer *lexer = malloc(sizeof(Lexer));
    if (lexer != ((void *)0)) {
        lexer->tokens = ((void *)0);
        lexer->token_count = 0;
    }
    return lexer;
}

canonical_original_code:
struct Lexer *Lexer_create()
{
    struct Lexer *lexer = malloc(sizeof(Lexer));
    if (lexer != ((void *)0)) {
        lexer->tokens = ((void *)0);
        lexer->token_count = 0;
    }
    return lexer;
}

return_type: struct Lexer { struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *tokens; unsigned long token_count; } *


decompiled_code:
void __fastcall Lexer_destroy(void *ptr)
{
if ( ptr )
{
clear_data((__int64)ptr);
free(ptr);
}
}

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

original_code:
void Lexer_destroy(Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return;
    }
    clear_data(lexer);
    free(lexer);
    lexer = ((void *)0);
}

canonical_original_code:
void Lexer_destroy(struct Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return;
    }
    clear_data(lexer);
    free(lexer);
    lexer = ((void *)0);
}

user_defined_types: enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 }


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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
Token *Lexer_get_tokens(Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return ((void *)0);
    }
    return lexer->tokens;
}

canonical_original_code:
struct Token *Lexer_get_tokens(struct Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return ((void *)0);
    }
    return lexer->tokens;
}

variable_types: struct Lexer { struct Token *tokens; unsigned long token_count; } *

return_type: struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *


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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
size_t Lexer_get_token_count(Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return 0;
    }
    return lexer->token_count;
}

canonical_original_code:
unsigned long Lexer_get_token_count(struct Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return 0;
    }
    return lexer->token_count;
}

return_type: unsigned long


decompiled_code:
void __fastcall Node_destroy(void *ptr, void (*a2)(void))
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
a2();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, void (*a2)(void))
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
a2();
free(ptr);
}
}

original_code:
void Node_destroy(Node *node, Destructor destructor)
{
    if (node != ((void *)0)) {
        if (node->data != ((void *)0)) {
            destructor(node->data);
        }
        free(node);
        node = ((void *)0);
    }
}

canonical_original_code:
void Node_destroy(struct Node *node, void (*destructor)(void *object))
{
    if (node != ((void *)0)) {
        if (node->data != ((void *)0)) {
            destructor(node->data);
        }
        free(node);
        node = ((void *)0);
    }
}

variable_types: struct Node { struct Node *next; void *data; } *

variable_types:
destructor
void (*)(void *object)


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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

original_code:
List *List_create(void)
{
    List *list = malloc(sizeof(List));
    if (list != ((void *)0)) {
        list->head = ((void *)0);
    }
    return list;
}

canonical_original_code:
struct List *List_create()
{
    struct List *list = malloc(sizeof(List));
    if (list != ((void *)0)) {
        list->head = ((void *)0);
    }
    return list;
}

variable_types: struct List { struct Node { struct Node *next; void *data; } *head; } *


decompiled_code:
void __fastcall List_destroy(void *ptr, void (*a2)(void))
{
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
v3 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
Node_destroy(v4, a2);
*(_QWORD *)ptr = v3;
}
while ( v3 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, void (*a2)(void))
{
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
v3 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
func0(v4, a2);
*(_QWORD *)ptr = v3;
}
while ( v3 );
}
free(ptr);
}
}

original_code:
void List_destroy(List *list, Destructor destructor)
{
    if (list != ((void *)0)) {
        while (list->head != ((void *)0)) {
            Node *n = list->head->next;
            Node_destroy(list->head, destructor);
            list->head = n;
        }
        free(list);
        list = ((void *)0);
    }
}

canonical_original_code:
void List_destroy(struct List *list, void (*destructor)(void *object))
{
    if (list != ((void *)0)) {
        while (list->head != ((void *)0)) {
            struct Node *n = list->head->next;
            Node_destroy(list->head, destructor);
            list->head = n;
        }
        free(list);
        list = ((void *)0);
    }
}

user_defined_types: struct Node { struct Node *next; void *data; }


decompiled_code:
void __fastcall List_push_back(_QWORD **a1, __int64 a2)
{
_QWORD *v3; // rax
_QWORD *v4; // rdi

if ( a1 )
{
if ( a2 )
{
v3 = Node_create(a2);
if ( v3 )
{
v4 = *a1;
if ( *a1 )
*end(v4) = v3;
else
*a1 = v3;
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD **a1, __int64 a2)
{
_QWORD *v3; // rax
_QWORD *v4; // rdi

if ( a1 )
{
if ( a2 )
{
v3 = Node_create(a2);
if ( v3 )
{
v4 = *a1;
if ( *a1 )
*end(v4) = v3;
else
*a1 = v3;
}
}
}
}

original_code:
void List_push_back(List *l, void *data)
{
    if (l == ((void *)0) || data == ((void *)0)) {
        return;
    }
    Node *n;
    n = Node_create(data);
    if (n == ((void *)0)) {
        return;
    }
    if (l->head == ((void *)0)) {
        l->head = n;
        return;
    }
    end(l->head)->next = n;
}

canonical_original_code:
void List_push_back(struct List *l, void *data)
{
    if (l == ((void *)0) || data == ((void *)0)) {
        return;
    }
    struct Node *n;
    n = Node_create(data);
    if (n == ((void *)0)) {
        return;
    }
    if (l->head == ((void *)0)) {
        l->head = n;
        return;
    }
    end(l->head)->next = n;
}

variable_types:
data
void *


decompiled_code:
void __fastcall clear_buffer(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
static void clear_buffer(char *buffer)
{
    if (buffer != ((void *)0)) {
        free(buffer);
        buffer = ((void *)0);
    }
}

variable_types:
buffer
char *


decompiled_code:
void __fastcall IO_destroy(void *ptr)
{
if ( ptr )
{
clear_buffer(*(void **)ptr);
free(ptr);
}
}

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

original_code:
void IO_destroy(IO *io)
{
    if (io != ((void *)0)) {
        clear_buffer(io->buffer);
        free(io);
        io = ((void *)0);
    }
}

canonical_original_code:
void IO_destroy(struct IO *io)
{
    if (io != ((void *)0)) {
        clear_buffer(io->buffer);
        free(io);
        io = ((void *)0);
    }
}

variable_types: struct IO { char *buffer; char *prompt; } *


decompiled_code:
char *__fastcall IO_read(char **lineptr, const char *a2)
{
char *v2; // rbp
char *v3; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !lineptr )
return 0LL;
if ( a2 )
printf("%s", a2);
else
printf("%s", lineptr[1]);
clear_buffer(*lineptr);
n[0] = 0LL;
if ( getline(lineptr, n, stdin) == -1 )
return 0LL;
v2 = *lineptr;
v3 = &v2[strlen(*lineptr) - 1];
if ( *v3 == 10 )
*v3 = 0;
return *lineptr;
}

canonical_decompiled_code:
char *__fastcall func2(char **lineptr, const char *a2)
{
char *v2; // rbp
char *v3; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !lineptr )
return 0LL;
if ( a2 )
printf("%s", a2);
else
printf("%s", lineptr[1]);
func0(*lineptr);
n[0] = 0LL;
if ( getline(lineptr, n, stdin) == -1 )
return 0LL;
v2 = *lineptr;
v3 = &v2[strlen(*lineptr) - 1];
if ( *v3 == 10 )
*v3 = 0;
return *lineptr;
}

original_code:
const char *IO_read(IO *io, const char *prompt)
{
    if (io == ((void *)0)) {
        return ((void *)0);
    }
    if (prompt != ((void *)0)) {
        printf("%s", prompt);
    }
    else {
        printf("%s", io->prompt);
    }
    clear_buffer(io->buffer);
    size_t size;
    size = 0;
    if (getline(&io->buffer, &size, stdin) == -1) {
        return ((void *)0);
    }
    size_t buffer_length = strlen(io->buffer);
    if (io->buffer[buffer_length - 1] == '\n') {
        io->buffer[buffer_length - 1] = '\0';
    }
    return io->buffer;
}

canonical_original_code:
char *IO_read(struct IO *io, char *prompt)
{
    if (io == ((void *)0)) {
        return ((void *)0);
    }
    if (prompt != ((void *)0)) {
        printf("%s", prompt);
    }
    else {
        printf("%s", io->prompt);
    }
    clear_buffer(io->buffer);
    unsigned long size;
    size = 0;
    if (getline(&io->buffer, &size, stdin) == -1) {
        return ((void *)0);
    }
    unsigned long buffer_length = strlen(io->buffer);
    if (io->buffer[buffer_length - 1] == '\n') {
        io->buffer[buffer_length - 1] = '\0';
    }
    return io->buffer;
}

variable_types:
prompt
char *

variable_types:
size
unsigned long

return_type: char *

user_defined_types: struct IO { char *buffer; char *prompt; }


decompiled_code:
int IO_write(const char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 )
{
va_start(arg, a1);
result = vprintf(a1, arg);
}
return result;
}

canonical_decompiled_code:
int func3(const char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 )
{
va_start(arg, a1);
result = vprintf(a1, arg);
}
return result;
}

original_code:
void IO_write(const char *format, ...)
{
    if (format == ((void *)0)) {
        return;
    }
    va_list args;
    __builtin_va_start(args,format);
    vprintf(format, args);
    __builtin_va_end(args);
}

canonical_original_code:
void IO_write(char *format, ...)
{
    if (format == ((void *)0)) {
        return;
    }
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vprintf(format, args);
    __builtin_va_end(args);
}

variable_types:
format
char *


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


decompiled_code:
size_t __fastcall write_response(void *src, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // er12
__int64 v6; // rdi
size_t v7; // r13

v5 = a3;
v6 = *(int *)(a4 + 8);
v7 = a3 * a2;
if ( (unsigned __int64)(v6 + a3 * a2) > 0x3FFFE )
{
fwrite("error: too small buffer\n", 1uLL, 0x18uLL, stderr);
v7 = 0LL;
}
else
{
memcpy((void *)(*(_QWORD *)a4 + v6), src, v7);
*(_DWORD *)(a4 + 8) += v5 * a2;
}
return v7;
}

canonical_decompiled_code:
size_t __fastcall func1(void *src, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // er12
__int64 v6; // rdi
size_t v7; // r13

v5 = a3;
v6 = *(int *)(a4 + 8);
v7 = a3 * a2;
if ( (unsigned __int64)(v6 + a3 * a2) > 0x3FFFE )
{
fwrite("error: too small buffer\n", 1uLL, 0x18uLL, stderr);
v7 = 0LL;
}
else
{
memcpy((void *)(*(_QWORD *)a4 + v6), src, v7);
*(_DWORD *)(a4 + 8) += v5 * a2;
}
return v7;
}

original_code:
static size_t write_response(void *ptr, size_t size, size_t nmemb, void *stream)
{
 struct write_result *result = (struct write_result *)stream;
 if(result->pos + size * nmemb >= (256 * 1024) - 1)
 {
  fprintf(stderr, "error: too small buffer\n");
  return 0;
 }
 memcpy(result->data + result->pos, ptr, size * nmemb);
 result->pos += size * nmemb;
 return size * nmemb;
}

canonical_original_code:
static unsigned long write_response(void *ptr, unsigned long size, unsigned long nmemb, void *stream)
{
 struct write_result *result = (struct write_result *)stream;
 if(result->pos + size * nmemb >= (256 * 1024) - 1)
 {
  fprintf(stderr, "error: too small buffer\n");
  return 0;
 }
 memcpy(result->data + result->pos, ptr, size * nmemb);
 result->pos += size * nmemb;
 return size * nmemb;
}

variable_types:
ptr
void *

variable_types:
nmemb
unsigned long

variable_types:
stream
void *

variable_types: struct write_result { char *data; int pos; } *


decompiled_code:
void topology_discovery()
{
_BYTE *v0; // rax
void *v1; // rbx
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v2, "http://localhost:8080/wm/topology/links/json");
v0 = request(v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)parse_topology((__int64)v0) )
{
puts("\n Error in parsing topology");
exit(0);
}
free(v1);
}

canonical_decompiled_code:
void func4()
{
_BYTE *v0; // rax
void *v1; // rbx
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v2, "http://localhost:8080/wm/topology/links/json");
v0 = request(v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)func2((__int64)v0) )
{
puts("\n Error in parsing topology");
exit(0);
}
free(v1);
}

original_code:
void topology_discovery(void) {
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/topology/links/json");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_topology(text);
 if(result != 0){
  printf("\n Error in parsing topology\n");
  exit(0);
 }
 free(text);
}

canonical_original_code:
void topology_discovery() {
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/topology/links/json");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_topology(text);
 if(result != 0){
  printf("\n Error in parsing topology\n");
  exit(0);
 }
 free(text);
}

variable_types: result int

variable_types:
text
char *

variable_types:
url
char [256]


decompiled_code:
void device_discovery()
{
_BYTE *v0; // rax
void *v1; // rbx
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v2, "http://localhost:8080/wm/device/");
v0 = request(v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)parse_device((__int64)v0) )
{
puts("\n Error in parsing device attachment point ");
exit(0);
}
free(v1);
}

canonical_decompiled_code:
void func5()
{
_BYTE *v0; // rax
void *v1; // rbx
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v2, "http://localhost:8080/wm/device/");
v0 = request(v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)func3((__int64)v0) )
{
puts("\n Error in parsing device attachment point ");
exit(0);
}
free(v1);
}

original_code:
void device_discovery(void){
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/device/");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_device(text);
 if(result != 0){
  printf("\n Error in parsing device attachment point \n");
  exit(0);
 }
 free(text);
}

canonical_original_code:
void device_discovery(){
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/device/");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_device(text);
 if(result != 0){
  printf("\n Error in parsing device attachment point \n");
  exit(0);
 }
 free(text);
}


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

topology_discovery();
device_discovery();
dijkstra(0LL, argv);
v3 = (const char *)find_dpid(0LL);
printf(" DPID for ipv4: %s dpid - %s", 0LL, v3);
print_dijkstra(v3);
return 0;
}

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

func4();
func5();
dijkstra(0LL, argv);
v3 = (const char *)find_dpid(0LL);
printf(" DPID for ipv4: %s dpid - %s", 0LL, v3);
print_dijkstra(v3);
return 0;
}

original_code:
int main(int argc, char **argv){
 char *dp;
 char *ip;
 char *source;
 topology_discovery();
  device_discovery();
 dijkstra(source);
 dp = find_dpid(ip);
 printf(" DPID for ipv4: %s  dpid - %s",ip,dp);
 print_dijkstra(dp);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
dp
char *

variable_types:
ip
char *

variable_types:
source
char *


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

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

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

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

original_code:
topo_graph* graph_instance(void) {
        topo_graph *temp = (topo_graph *)malloc(sizeof(topo_graph));
        temp->sdpid = ((void *)0);
        temp->next_element = ((void *)0);
        temp->adjnode = ((void *)0);
        return temp;
}

canonical_original_code:
struct topo_graph *graph_instance() {
        struct topo_graph *temp = (topo_graph *)malloc(sizeof(topo_graph));
        temp->sdpid = ((void *)0);
        temp->next_element = ((void *)0);
        temp->adjnode = ((void *)0);
        return temp;
}

variable_types: struct topo_graph { char *sdpid; struct topo_graph *next_element; struct adj_node { char *ddpid; int w; int min; struct adj_node *next_adjnode; } *adjnode; } *

user_defined_types: struct topo_graph { char *sdpid; struct topo_graph *next_element; struct adj_node *adjnode; }


decompiled_code:
__int64 __fastcall print_graph(const char **a1)
{
const char **v1; // rbp
const char *i; // rbx
__int64 result; // rax

v1 = a1;
if ( *a1 )
{
do
{
for ( i = v1[2]; i; i = (const char *)*((_QWORD *)i + 2) )
printf("source - %s\tdestination - %s\tweight - %d\n", *v1, *(const char **)i, *((unsigned int *)i + 2));
v1 = (const char **)v1[1];
}
while ( v1 );
result = 0LL;
}
else
{
puts("\n GRAPH is EMPTY");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char **a1)
{
const char **v1; // rbp
const char *i; // rbx
__int64 result; // rax

v1 = a1;
if ( *a1 )
{
do
{
for ( i = v1[2]; i; i = (const char *)*((_QWORD *)i + 2) )
printf("source - %s\tdestination - %s\tweight - %d\n", *v1, *(const char **)i, *((unsigned int *)i + 2));
v1 = (const char **)v1[1];
}
while ( v1 );
result = 0LL;
}
else
{
puts("\n GRAPH is EMPTY");
result = 1LL;
}
return result;
}

original_code:
int print_graph(topo_graph *graph){
 topo_graph *temp1;
 temp1 = graph;
 if(temp1->sdpid == ((void *)0)) {
  printf("\n GRAPH is EMPTY\n");
  return 1;
 }
 else {
  while(temp1 != ((void *)0)){
   adj_node* temp2 = temp1->adjnode;
   while(temp2 != ((void *)0)){
    printf("source - %s	destination - %s	weight - %d\n",temp1->sdpid,temp2->ddpid,temp2->w);
    temp2= temp2->next_adjnode;
   }
   temp1 = temp1->next_element;
  }
 }
 return 0;
}

canonical_original_code:
int print_graph(struct topo_graph *graph){
 struct topo_graph *temp1;
 temp1 = graph;
 if(temp1->sdpid == ((void *)0)) {
  printf("\n GRAPH is EMPTY\n");
  return 1;
 }
 else {
  while(temp1 != ((void *)0)){
   struct adj_node *temp2 = temp1->adjnode;
   while(temp2 != ((void *)0)){
    printf("source - %s	destination - %s	weight - %d\n",temp1->sdpid,temp2->ddpid,temp2->w);
    temp2= temp2->next_adjnode;
   }
   temp1 = temp1->next_element;
  }
 }
 return 0;
}

variable_types: struct adj_node { char *ddpid; int w; int min; struct adj_node *next_adjnode; } *


decompiled_code:
void free_graph()
{
free(*((void **)graph + 2));
free(graph);
}

canonical_decompiled_code:
void func3()
{
free(*((void **)graph + 2));
free(graph);
}

original_code:
void free_graph(void){
 free(graph->adjnode);
 free(graph);
}

canonical_original_code:
void free_graph(){
 free(graph->adjnode);
 free(graph);
}


decompiled_code:
__int64 __fastcall num_switches(__int64 a1)
{
int v1; // eax
int v2; // edx

if ( a1 )
{
v1 = count + 1;
do
{
v2 = v1;
a1 = *(_QWORD *)(a1 + 8);
++v1;
}
while ( a1 );
count = v2;
}
return (unsigned int)count;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
int v2; // edx

if ( a1 )
{
v1 = count + 1;
do
{
v2 = v1;
a1 = *(_QWORD *)(a1 + 8);
++v1;
}
while ( a1 );
count = v2;
}
return (unsigned int)count;
}

original_code:
int num_switches(topo_graph *graph) {
 topo_graph *temp;
 temp = graph;
 while(temp != ((void *)0)) {
  count++;
  temp = temp->next_element;
 }
 return count;
}

canonical_original_code:
int num_switches(struct topo_graph *graph) {
 struct topo_graph *temp;
 temp = graph;
 while(temp != ((void *)0)) {
  count++;
  temp = temp->next_element;
 }
 return count;
}

user_defined_types: struct adj_node { char *ddpid; int w; int min; struct adj_node *next_adjnode; }


decompiled_code:
_QWORD *init_prev_path()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void **v2; // rbp
void **v3; // rbx

v0 = malloc(16LL * count);
if ( !v0 )
{
puts("\n Error in one of list array malloc");
exit(0);
}
v1 = v0;
v2 = (void **)graph;
if ( graph )
{
v3 = (void **)v0;
do
{
*v3 = malloc(0x30uLL);
v3[1] = malloc(0x30uLL);
*v3 = *v2;
v3[1] = 0LL;
v2 = (void **)v2[1];
v3 += 2;
}
while ( v2 );
}
return v1;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void **v2; // rbp
void **v3; // rbx

v0 = malloc(16LL * count);
if ( !v0 )
{
puts("\n Error in one of list array malloc");
exit(0);
}
v1 = v0;
v2 = (void **)graph;
if ( graph )
{
v3 = (void **)v0;
do
{
*v3 = malloc(0x30uLL);
v3[1] = malloc(0x30uLL);
*v3 = *v2;
v3[1] = 0LL;
v2 = (void **)v2[1];
v3 += 2;
}
while ( v2 );
}
return v1;
}

original_code:
prev_path *init_prev_path(void){
 prev_path *a;
 topo_graph *temp;
 int i = 0;
 a = (prev_path *)malloc(count*sizeof(prev_path));
 if(!a){
                printf("\n Error in one of list array malloc\n");
                exit(0);
        }
 temp = graph;
 while(temp != ((void *)0)){
                a[i].dpid = (char *)malloc(48*sizeof(char));
  a[i].path_dpid = (char *)malloc(48*sizeof(char));
                a[i].dpid = temp->sdpid;
                a[i].path_dpid = ((void *)0);
                temp = temp->next_element;
                i++;
        }
        return a;
}

canonical_original_code:
struct prev_path *init_prev_path(){
 struct prev_path *a;
 struct topo_graph *temp;
 int i = 0;
 a = (struct prev_path *)malloc(count*sizeof(prev_path));
 if(!a){
                printf("\n Error in one of list array malloc\n");
                exit(0);
        }
 temp = graph;
 while(temp != ((void *)0)){
                a[i].dpid = (char *)malloc(48*sizeof(char));
  a[i].path_dpid = (char *)malloc(48*sizeof(char));
                a[i].dpid = temp->sdpid;
                a[i].path_dpid = ((void *)0);
                temp = temp->next_element;
                i++;
        }
        return a;
}

variable_types: struct prev_path { char *dpid; char *path_dpid; } *

variable_types: i int


decompiled_code:
__int64 __fastcall set_val_list_array(__int64 a1, const char *a2, int a3)
{
__int64 v4; // rbx
__int64 v5; // rbp

if ( count > 0 )
{
v4 = a1;
v5 = a1 + 16LL * (unsigned int)count;
while ( strcmp(*(const char **)v4, a2) )
{
v4 += 16LL;
if ( v4 == v5 )
return 0LL;
}
*(_DWORD *)(v4 + 8) = a3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, int a3)
{
__int64 v4; // rbx
__int64 v5; // rbp

if ( count > 0 )
{
v4 = a1;
v5 = a1 + 16LL * (unsigned int)count;
while ( strcmp(*(const char **)v4, a2) )
{
v4 += 16LL;
if ( v4 == v5 )
return 0LL;
}
*(_DWORD *)(v4 + 8) = a3;
}
return 0LL;
}

original_code:
int set_val_list_array(list_array *a, char *dpid, int value) {
 int i;
 for(i = 0; i < count; i++){
  if(strcmp(a[i].dpid,dpid) == 0){
   a[i].w = value;
   return 0;
  }
 }
 return 0;
}

canonical_original_code:
int set_val_list_array(struct list *a, char *dpid, int value) {
 int i;
 for(i = 0; i < count; i++){
  if(strcmp(a[i].dpid,dpid) == 0){
   a[i].w = value;
   return 0;
  }
 }
 return 0;
}

variable_types:
a
struct list { char *dpid; int w; } *

variable_types:
dpid
char *

variable_types: value int


decompiled_code:
__int64 __fastcall get_val_list_array(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

if ( count <= 0 )
return 0xFFFFFFFFLL;
v2 = a1;
v3 = a1 + 16LL * (unsigned int)(count - 1);
while ( strcmp(*(const char **)v2, a2) )
{
if ( v2 == v3 )
return 0xFFFFFFFFLL;
v2 += 16LL;
}
return *(unsigned int *)(v2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

if ( count <= 0 )
return 0xFFFFFFFFLL;
v2 = a1;
v3 = a1 + 16LL * (unsigned int)(count - 1);
while ( strcmp(*(const char **)v2, a2) )
{
if ( v2 == v3 )
return 0xFFFFFFFFLL;
v2 += 16LL;
}
return *(unsigned int *)(v2 + 8);
}

original_code:
int get_val_list_array(list_array *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return a[i].w;
  }
 }
 return -1;
}

canonical_original_code:
int get_val_list_array(struct list *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return a[i].w;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall get_index_prev_path(const char **a1, const char *a2)
{
int v2; // er13
unsigned int v4; // ebp

v2 = count;
if ( count <= 0 )
return (unsigned int)-1;
v4 = 0;
while ( strcmp(*a1, a2) )
{
++v4;
a1 += 2;
if ( v4 == v2 )
return (unsigned int)-1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1, const char *a2)
{
int v2; // er13
unsigned int v4; // ebp

v2 = count;
if ( count <= 0 )
return (unsigned int)-1;
v4 = 0;
while ( strcmp(*a1, a2) )
{
++v4;
a1 += 2;
if ( v4 == v2 )
return (unsigned int)-1;
}
return v4;
}

original_code:
int get_index_prev_path(prev_path *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int get_index_prev_path(struct prev_path *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return i;
  }
 }
 return -1;
}

user_defined_types: struct prev_path { char *dpid; char *path_dpid; }


decompiled_code:
int print_init_djk()
{
int result; // eax
__int64 v1; // rbp

puts("\n STRUCT ARRAY VALUES: ");
result = printf("\n Count value in print - %d", (unsigned int)count);
if ( count > 0 )
{
v1 = 0LL;
do
{
printf("PREV dpid - %s\tW - %s\n", *(const char **)(prev + 16 * v1), *(const char **)(prev + 16 * v1 + 8));
printf("DONE dpid - %s W - %d\n", *(const char **)(done + 16 * v1), *(unsigned int *)(done + 16 * v1 + 8));
result = printf(
"DIST dpid - %s W - %d\n",
*(const char **)(dist + 16 * v1),
*(unsigned int *)(dist + 16 * v1 + 8));
++v1;
}
while ( count > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
__int64 v1; // rbp

puts("\n STRUCT ARRAY VALUES: ");
result = printf("\n Count value in print - %d", (unsigned int)count);
if ( count > 0 )
{
v1 = 0LL;
do
{
printf("PREV dpid - %s\tW - %s\n", *(const char **)(prev + 16 * v1), *(const char **)(prev + 16 * v1 + 8));
printf("DONE dpid - %s W - %d\n", *(const char **)(done + 16 * v1), *(unsigned int *)(done + 16 * v1 + 8));
result = printf(
"DIST dpid - %s W - %d\n",
*(const char **)(dist + 16 * v1),
*(unsigned int *)(dist + 16 * v1 + 8));
++v1;
}
while ( count > (int)v1 );
}
return result;
}

original_code:
void print_init_djk(void){
 int i;
 printf("\n STRUCT ARRAY VALUES: \n");
 printf("\n Count value in print - %d",count);
 for(i = 0; i < count; i++) {
  printf("PREV dpid - %s	W - %s\n",prev[i].dpid,prev[i].path_dpid);
  printf("DONE dpid - %s  W - %d\n",done[i].dpid,done[i].w);
  printf("DIST dpid - %s  W - %d\n",dist[i].dpid,dist[i].w);
 }
}

canonical_original_code:
void print_init_djk(){
 int i;
 printf("\n STRUCT ARRAY VALUES: \n");
 printf("\n Count value in print - %d",count);
 for(i = 0; i < count; i++) {
  printf("PREV dpid - %s	W - %s\n",prev[i].dpid,prev[i].path_dpid);
  printf("DONE dpid - %s  W - %d\n",done[i].dpid,done[i].w);
  printf("DIST dpid - %s  W - %d\n",dist[i].dpid,dist[i].w);
 }
}


decompiled_code:
int print_array_list()
{
__int64 v0; // rbx
int result; // eax

if ( count > 0 )
{
v0 = 0LL;
do
{
result = printf("dpid - %s w - %d\n", *(const char **)(dist + 16 * v0), *(unsigned int *)(dist + 16 * v0 + 8));
++v0;
}
while ( count > (int)v0 );
}
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbx
int result; // eax

if ( count > 0 )
{
v0 = 0LL;
do
{
result = printf("dpid - %s w - %d\n", *(const char **)(dist + 16 * v0), *(unsigned int *)(dist + 16 * v0 + 8));
++v0;
}
while ( count > (int)v0 );
}
return result;
}

original_code:
void print_array_list(list_array *a){
 int i = 0;
 for(i = 0; i < count; i++)
  printf("dpid - %s w - %d\n",dist[i].dpid,dist[i].w);
}

canonical_original_code:
void print_array_list(struct list *a){
 int i = 0;
 for(i = 0; i < count; i++)
  printf("dpid - %s w - %d\n",dist[i].dpid,dist[i].w);
}


dijkstra

decompiled_code:
__int64 __fastcall dijkstra(const char *a1)
{
__int64 result; // rax
__int64 v2; // rax
int v3; // er15
__int64 i; // r14
__int64 v5; // rcx
__int64 v6; // rbp
__int64 j; // rbx
const char *v8; // rbp
int v9; // er13
__int64 v10; // r12
char *s2; // [rsp+0h] [rbp-48h]
int v12; // [rsp+Ch] [rbp-3Ch]

s2 = (char *)malloc(0x30uLL);
count = num_switches(graph);
prev = (__int64)init_prev_path();
done = (__int64)init_list_array(0);
dist = (__int64)init_list_array(9999);
v12 = set_val_list_array(dist, a1, 0);
if ( v12 )
{
printf("\n Error in setting dist list array value to - %d\n", 0LL);
exit(0);
}
result = (unsigned int)count;
if ( count > 1 )
{
do
{
v3 = 9999;
if ( (int)result > 0 )
{
v5 = 16LL * (unsigned int)(result - 1) + 24;
v2 = 8LL;
v3 = 9999;
do
{
if ( *(_DWORD *)(dist + v2) < v3 && !*(_DWORD *)(done + v2) )
{
s2 = *(char **)(dist + v2 - 8);
v3 = *(_DWORD *)(dist + v2);
}
v2 += 16LL;
}
while ( v5 != v2 );
}
set_val_list_array(done, s2, 1);
for ( i = graph; i; i = *(_QWORD *)(i + 8) )
{
if ( !strcmp(*(const char **)i, s2) )
{
for ( j = *(_QWORD *)(i + 16); j; j = *(_QWORD *)(j + 16) )
{
v8 = *(const char **)j;
if ( !(unsigned int)get_val_list_array(done, *(const char **)j) )
{
v9 = *(_DWORD *)(j + 8) + v3;
v10 = dist;
if ( v9 < (int)get_val_list_array(dist, v8) )
{
if ( (unsigned int)set_val_list_array(v10, v8, v9) )
{
puts("\n Error in setting dist value");
exit(0);
}
*(_DWORD *)(j + 12) = *(_DWORD *)(j + 8);
v6 = prev;
*(_QWORD *)(v6 + 16LL * (int)get_index_prev_path((const char **)prev, *(const char **)j) + 8) = s2;
}
}
}
}
}
++v12;
result = (unsigned int)count;
}
while ( count - 1 > v12 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
__int64 result; // rax
__int64 v2; // rax
int v3; // er15
__int64 i; // r14
__int64 v5; // rcx
__int64 v6; // rbp
__int64 j; // rbx
const char *v8; // rbp
int v9; // er13
__int64 v10; // r12
char *s2; // [rsp+0h] [rbp-48h]
int v12; // [rsp+Ch] [rbp-3Ch]

s2 = (char *)malloc(0x30uLL);
count = func0(graph);
prev = (__int64)func2();
done = (__int64)func1(0);
dist = (__int64)func1(9999);
v12 = func3(dist, a1, 0);
if ( v12 )
{
printf("\n Error in setting dist list array value to - %d\n", 0LL);
exit(0);
}
result = (unsigned int)count;
if ( count > 1 )
{
do
{
v3 = 9999;
if ( (int)result > 0 )
{
v5 = 16LL * (unsigned int)(result - 1) + 24;
v2 = 8LL;
v3 = 9999;
do
{
if ( *(_DWORD *)(dist + v2) < v3 && !*(_DWORD *)(done + v2) )
{
s2 = *(char **)(dist + v2 - 8);
v3 = *(_DWORD *)(dist + v2);
}
v2 += 16LL;
}
while ( v5 != v2 );
}
func3(done, s2, 1);
for ( i = graph; i; i = *(_QWORD *)(i + 8) )
{
if ( !strcmp(*(const char **)i, s2) )
{
for ( j = *(_QWORD *)(i + 16); j; j = *(_QWORD *)(j + 16) )
{
v8 = *(const char **)j;
if ( !(unsigned int)func4(done, *(const char **)j) )
{
v9 = *(_DWORD *)(j + 8) + v3;
v10 = dist;
if ( v9 < (int)func4(dist, v8) )
{
if ( (unsigned int)func3(v10, v8, v9) )
{
puts("\n Error in setting dist value");
exit(0);
}
*(_DWORD *)(j + 12) = *(_DWORD *)(j + 8);
v6 = prev;
*(_QWORD *)(v6 + 16LL * (int)func5((const char **)prev, *(const char **)j) + 8) = s2;
}
}
}
}
}
++v12;
result = (unsigned int)count;
}
while ( count - 1 > v12 );
}
return result;
}

original_code:
void dijkstra(char *dpid){
 int cnt,inter_dist,i;
 int result;
 topo_graph *temp;
 char *element = (char *)malloc(48*sizeof(char));
 count = num_switches(graph);
 prev = init_prev_path();
 done = init_list_array(0);
 dist = init_list_array(9999);
 int value = 0;
 cnt = 0;
 result = set_val_list_array(dist,dpid,value);
 if(result != 0){
                 printf("\n Error in setting dist list array value to - %d\n",value);
                 exit(0);
         }
 while(cnt < count-1){
  inter_dist = 9999;
  for(i = 0; i < count; i++){
   if(dist[i].w < inter_dist && !done[i].w){
    inter_dist = dist[i].w;
    element = dist[i].dpid;
   }
  }
  set_val_list_array(done,element,1);
  if(result != 0){
                   printf("\n Error in setting done list array value to - 1\n");
                   exit(0);
           }
  temp = graph;
  while(temp != ((void *)0)){
   if(strcmp(temp->sdpid,element) == 0){
    adj_node *iter_adjnodes;
    iter_adjnodes = temp->adjnode;
    while(iter_adjnodes != ((void *)0)){
     if(!get_val_list_array(done,iter_adjnodes->ddpid)){
      if((inter_dist + iter_adjnodes->w) < get_val_list_array(dist,iter_adjnodes->ddpid)){
       value = inter_dist + iter_adjnodes->w;
       if(set_val_list_array(dist,iter_adjnodes->ddpid,value)){
        printf("\n Error in setting dist value\n");
        exit(0);
       }
       iter_adjnodes->min = iter_adjnodes->w;
       int prev_index = get_index_prev_path(prev,iter_adjnodes->ddpid);
       prev[prev_index].path_dpid = element;
      }
     }
     iter_adjnodes = iter_adjnodes->next_adjnode;
    }
   }
   temp = temp->next_element;
  }
  cnt++;
 }
}

canonical_original_code:
void dijkstra(char *dpid){
 int cnt; int inter_dist; int i;
 int result;
 struct topo_graph *temp;
 char *element = (char *)malloc(48*sizeof(char));
 count = num_switches(graph);
 prev = init_prev_path();
 done = init_list_array(0);
 dist = init_list_array(9999);
 int value = 0;
 cnt = 0;
 result = set_val_list_array(dist,dpid,value);
 if(result != 0){
                 printf("\n Error in setting dist list array value to - %d\n",value);
                 exit(0);
         }
 while(cnt < count-1){
  inter_dist = 9999;
  for(i = 0; i < count; i++){
   if(dist[i].w < inter_dist && !done[i].w){
    inter_dist = dist[i].w;
    element = dist[i].dpid;
   }
  }
  set_val_list_array(done,element,1);
  if(result != 0){
                   printf("\n Error in setting done list array value to - 1\n");
                   exit(0);
           }
  temp = graph;
  while(temp != ((void *)0)){
   if(strcmp(temp->sdpid,element) == 0){
    struct adj_node *iter_adjnodes;
    iter_adjnodes = temp->adjnode;
    while(iter_adjnodes != ((void *)0)){
     if(!get_val_list_array(done,iter_adjnodes->ddpid)){
      if((inter_dist + iter_adjnodes->w) < get_val_list_array(dist,iter_adjnodes->ddpid)){
       value = inter_dist + iter_adjnodes->w;
       if(set_val_list_array(dist,iter_adjnodes->ddpid,value)){
        printf("\n Error in setting dist value\n");
        exit(0);
       }
       iter_adjnodes->min = iter_adjnodes->w;
       int prev_index = get_index_prev_path(prev,iter_adjnodes->ddpid);
       prev[prev_index].path_dpid = element;
      }
     }
     iter_adjnodes = iter_adjnodes->next_adjnode;
    }
   }
   temp = temp->next_element;
  }
  cnt++;
 }
}

variable_types: cnt int

variable_types:
element
char *


decompiled_code:
int __fastcall print_dijkstra(const char *a1)
{
__int64 v1; // r12
int result; // eax
__int64 v3; // rbx
const char *v4; // rsi

v1 = prev;
result = get_index_prev_path((const char **)prev, a1);
v3 = 16LL * result;
if ( *(_QWORD *)(v1 + v3 + 8) )
{
print_dijkstra();
result = prev;
v4 = *(const char **)(prev + v3 + 8);
if ( v4 )
result = printf("%s -> %s", v4, a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
__int64 v1; // r12
int result; // eax
__int64 v3; // rbx
const char *v4; // rsi

v1 = prev;
result = func5((const char **)prev, a1);
v3 = 16LL * result;
if ( *(_QWORD *)(v1 + v3 + 8) )
{
func9();
result = prev;
v4 = *(const char **)(prev + v3 + 8);
if ( v4 )
result = printf("%s -> %s", v4, a1);
}
return result;
}

original_code:
void print_dijkstra(char *dpid){
 int prev_index = get_index_prev_path(prev,dpid);
 if(prev[prev_index].path_dpid != ((void *)0)){
  print_dijkstra(prev[prev_index].path_dpid);
 }
 if(prev[prev_index].path_dpid != ((void *)0)){
  printf("%s -> %s",prev[prev_index].path_dpid,dpid);
 }
}


decompiled_code:
__int64 __fastcall add_entry(char *a1, const char *a2, const char *a3, int a4)
{
__int64 v4; // rbx
_QWORD *v5; // rdx
__int64 v6; // rax

v4 = att_point;
if ( att_point )
{
v5 = create_att_point_element(a1, a2, a3, a4);
do
{
v6 = v4;
v4 = *(_QWORD *)(v4 + 32);
}
while ( v4 );
*(_QWORD *)(v6 + 32) = v5;
}
else
{
att_point = (__int64)create_att_point_element(a1, a2, a3, a4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, const char *a2, const char *a3, int a4)
{
__int64 v4; // rbx
_QWORD *v5; // rdx
__int64 v6; // rax

v4 = att_point;
if ( att_point )
{
v5 = create_att_point_element(a1, a2, a3, a4);
do
{
v6 = v4;
v4 = *(_QWORD *)(v4 + 32);
}
while ( v4 );
*(_QWORD *)(v6 + 32) = v5;
}
else
{
att_point = (__int64)create_att_point_element(a1, a2, a3, a4);
}
return 0LL;
}

original_code:
int add_entry(char *ipv4, char *mac, char *dpid, int port){
 if(att_point == ((void *)0)){
  attachment_point *temp = create_att_point_element(ipv4,mac,dpid,port);
  att_point = temp;
  return 0;
 }
 else {
  attachment_point *current, *temp1;
  current = att_point;
  temp1 = create_att_point_element(ipv4,mac,dpid,port);
  while(current->next_attachment_point != ((void *)0)){
   current = current->next_attachment_point;
  }
  current->next_attachment_point = temp1;
  return 0;
 }
}

canonical_original_code:
int add_entry(char *ipv4, char *mac, char *dpid, int port){
 if(att_point == ((void *)0)){
  struct attachment_point *temp = create_att_point_element(ipv4,mac,dpid,port);
  att_point = temp;
  return 0;
 }
 else {
  struct attachment_point *current; struct attachment_point *temp1;
  current = att_point;
  temp1 = create_att_point_element(ipv4,mac,dpid,port);
  while(current->next_attachment_point != ((void *)0)){
   current = current->next_attachment_point;
  }
  current->next_attachment_point = temp1;
  return 0;
 }
}

variable_types:
mac
char *

variable_types: port int

variable_types: struct attachment_point { char *ipv4; char *mac; char *dpid; int port; struct attachment_point *next_attachment_point; } *


decompiled_code:
__int64 __fastcall find_dpid(char *s2)
{
__int64 v1; // rbx

v1 = att_point;
if ( att_point )
{
while ( strcmp(*(const char **)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 16);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
__int64 v1; // rbx

v1 = att_point;
if ( att_point )
{
while ( strcmp(*(const char **)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 16);
}
return v1;
}

original_code:
char *find_dpid(char *ipv4){
 attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  if(strcmp(temp->ipv4,ipv4) == 0){
   return temp->dpid;
  }
  temp = temp->next_attachment_point;
 }
 return ((void *)0);
}

canonical_original_code:
char *find_dpid(char *ipv4){
 struct attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  if(strcmp(temp->ipv4,ipv4) == 0){
   return temp->dpid;
  }
  temp = temp->next_attachment_point;
 }
 return ((void *)0);
}

user_defined_types: struct attachment_point { char *ipv4; char *mac; char *dpid; int port; struct attachment_point *next_attachment_point; }


decompiled_code:
__int64 print_att_point()
{
__int64 i; // rbx

for ( i = att_point; i; i = *(_QWORD *)(i + 32) )
printf(
"IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",
*(const char **)i,
*(const char **)(i + 8),
*(const char **)(i + 16),
*(unsigned int *)(i + 24));
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 i; // rbx

for ( i = att_point; i; i = *(_QWORD *)(i + 32) )
printf(
"IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",
*(const char **)i,
*(const char **)(i + 8),
*(const char **)(i + 16),
*(unsigned int *)(i + 24));
return 0LL;
}

original_code:
int print_att_point(void){
 attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  printf("IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",temp->ipv4,temp->mac,temp->dpid,temp->port);
  temp = temp->next_attachment_point;
 }
 return 0;
}

canonical_original_code:
int print_att_point(){
 struct attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  printf("IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",temp->ipv4,temp->mac,temp->dpid,temp->port);
  temp = temp->next_attachment_point;
 }
 return 0;
}


a

repo: mbolewar/csource

decompiled_code:
int a()
{
return puts("function a");
}

canonical_decompiled_code:
int func7()
{
return puts("function a");
}

original_code:
void
a() {
 printf("function a\n");
}

canonical_original_code:
void a() {
 printf("function a\n");
}


b

decompiled_code:
int b()
{
return puts("function b");
}

canonical_decompiled_code:
int func8()
{
return puts("function b");
}

original_code:
void
b() {
 printf("function b\n");
}

canonical_original_code:
void b() {
 printf("function b\n");
}


c

decompiled_code:
int c()
{
return puts("function c");
}

canonical_decompiled_code:
int func9()
{
return puts("function c");
}

original_code:
void
c() {
 printf("function c\n");
}

canonical_original_code:
void c() {
 printf("function c\n");
}


decompiled_code:
__int64 __fastcall Camera_Basic_map(__int64 a1, __int64 a2, double a3, double a4)
{
double v4; // xmm1_8
__int64 v5; // rbx
double v6; // xmm1_8
double v8; // [rsp+0h] [rbp-78h]
double v9; // [rsp+8h] [rbp-70h]
char v10[32]; // [rsp+10h] [rbp-68h] BYREF
char v11[72]; // [rsp+30h] [rbp-48h] BYREF

Vector_cross(v11, a1 + 56, a1 + 32);
Vector_normalize(a1 + 56);
Vector_normalize(a1 + 32);
Vector_normalize(v11);
v8 = a3 + a3;
v9 = a4 + a4;
Vector_assign(a2, a1 + 8);
v4 = tan(0.5 * *(double *)(a1 + 80));
v5 = a2 + 24;
Vector_scalar_mult(a2 + 24, v11, (v8 - 1.0) * v4);
v6 = tan(0.5 * *(double *)(a1 + 88));
Vector_scalar_mult(v10, a1 + 32, (v9 - 1.0) * v6);
Vector_add(v5, v5, v10);
return Vector_add(v5, v5, a1 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, double a3, double a4)
{
double v4; // xmm1_8
__int64 v5; // rbx
double v6; // xmm1_8
double v8; // [rsp+0h] [rbp-78h]
double v9; // [rsp+8h] [rbp-70h]
char v10[32]; // [rsp+10h] [rbp-68h] BYREF
char v11[72]; // [rsp+30h] [rbp-48h] BYREF

Vector_cross(v11, a1 + 56, a1 + 32);
Vector_normalize(a1 + 56);
Vector_normalize(a1 + 32);
Vector_normalize(v11);
v8 = a3 + a3;
v9 = a4 + a4;
Vector_assign(a2, a1 + 8);
v4 = tan(0.5 * *(double *)(a1 + 80));
v5 = a2 + 24;
Vector_scalar_mult(a2 + 24, v11, (v8 - 1.0) * v4);
v6 = tan(0.5 * *(double *)(a1 + 88));
Vector_scalar_mult(v10, a1 + 32, (v9 - 1.0) * v6);
Vector_add(v5, v5, v10);
return Vector_add(v5, v5, a1 + 56);
}

original_code:
void Camera_Basic_map(const Camera* _cam, double x, double y, Ray* ray) {
    Camera_Basic* cam = (Camera_Basic*) _cam;
    Vector right;
    Vector tmp;
    Vector_cross(&right, &cam->forward, &cam->up);
    Vector_normalize(&cam->forward);
    Vector_normalize(&cam->up);
    Vector_normalize(&right);
    x = x*2 - 1;
    y = y*2 - 1;
    Vector_assign(&ray->o, &cam->pos);
    Vector_scalar_mult(&ray->d, &right, x*tan(cam->fov_x/2));
    Vector_scalar_mult(&tmp, &cam->up, y*tan(cam->fov_y/2));
    Vector_add(&ray->d, &ray->d, &tmp);
    Vector_add(&ray->d, &ray->d, &cam->forward);
}

canonical_original_code:
void Camera_Basic_map(struct Camera_struct *_cam, double x, double y, struct Ray *ray) {
    struct Camera_Basic *cam = (Camera_Basic*) _cam;
    struct Vector right;
    struct Vector tmp;
    Vector_cross(&right, &cam->forward, &cam->up);
    Vector_normalize(&cam->forward);
    Vector_normalize(&cam->up);
    Vector_normalize(&right);
    x = x*2 - 1;
    y = y*2 - 1;
    Vector_assign(&ray->o, &cam->pos);
    Vector_scalar_mult(&ray->d, &right, x*tan(cam->fov_x/2));
    Vector_scalar_mult(&tmp, &cam->up, y*tan(cam->fov_y/2));
    Vector_add(&ray->d, &ray->d, &tmp);
    Vector_add(&ray->d, &ray->d, &cam->forward);
}

variable_types: struct Camera_struct { struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray { struct Vector { double x; } o; struct Vector d; } *r); } func; struct Vector pos; } *

variable_types: x double

variable_types: y double

variable_types:
ray
struct Ray *

variable_types: struct Camera_Basic { struct camera_func_table { void (*map)(struct Camera_struct { struct camera_func_table func; struct Vector { double x; } pos; } *cam, double x, double y, struct Ray { struct Vector o; struct Vector d; } *r); } func; struct Vector pos; struct Vector up; struct Vector forward; double fov_x; } *

variable_types:
right
struct Vector { double x; }

variable_types:
tmp
struct Vector { double x; }

user_defined_types: struct Camera_struct { struct camera_func_table func; struct Vector pos; }

user_defined_types: struct Camera_Basic { struct camera_func_table func; struct Vector pos; struct Vector up; struct Vector forward; double fov_x; }

user_defined_types: struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray *r); }


original_code:
void Camera_Basic_zoom(Camera* _cam, double x, double y, double zoom_factor) {
    Camera_Basic* cam = (Camera_Basic*) _cam;
    Ray ray;
    const Vector const_up = (Vector) {0, 0, 1};
    (cam)->func.map((Camera*) cam, x, y, &ray);
    cam->forward = ray.d;
    Vector_cross(&cam->up, &const_up, &cam->forward);
    Vector_cross(&cam->up, &cam->forward, &cam->up);
    cam->fov_x /= zoom_factor;
    cam->fov_y /= zoom_factor;
    if (cam->fov_x >= 3.141592653589793238462643383279 -0.5) cam->fov_x = 3.141592653589793238462643383279 -0.5;
    if (cam->fov_y >= 3.141592653589793238462643383279 -0.5) cam->fov_y = 3.141592653589793238462643383279 -0.5;
}

canonical_original_code:
void Camera_Basic_zoom(struct Camera_struct *_cam, double x, double y, double zoom_factor) {
    struct Camera_Basic *cam = (Camera_Basic*) _cam;
    struct Ray ray;
    struct Vector const_up = (Vector) {0, 0, 1};
    (cam)->func.map((struct Camera_struct *) cam, x, y, &ray);
    cam->forward = ray.d;
    Vector_cross(&cam->up, &const_up, &cam->forward);
    Vector_cross(&cam->up, &cam->forward, &cam->up);
    cam->fov_x /= zoom_factor;
    cam->fov_y /= zoom_factor;
    if (cam->fov_x >= 3.141592653589793238462643383279 -0.5) cam->fov_x = 3.141592653589793238462643383279 -0.5;
    if (cam->fov_y >= 3.141592653589793238462643383279 -0.5) cam->fov_y = 3.141592653589793238462643383279 -0.5;
}

variable_types: struct Ray { struct Vector { double x; } o; struct Vector d; }

user_defined_types: struct Ray { struct Vector o; struct Vector d; }


decompiled_code:
_QWORD *Scene_new()
{
_QWORD *v0; // rbx

v0 = malloc(8uLL);
*v0 = List_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = malloc(8uLL);
*v0 = List_new();
return v0;
}

original_code:
Scene* Scene_new() {
    Scene* s = (Scene*) malloc(sizeof(Scene));
    s->objects = List_new();
    return s;
}

canonical_original_code:
struct Scene *Scene_new() {
    struct Scene *s = (Scene*) malloc(sizeof(Scene));
    s->objects = List_new();
    return s;
}

variable_types: struct Scene { struct List { struct ListNode_struct { void *data; struct ListNode_struct *next; } *head; struct ListNode_struct *tail; unsigned int length; } *objects; } *

user_defined_types: struct List { struct ListNode_struct *head; struct ListNode_struct *tail; unsigned int length; }


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

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

original_code:
void Scene_add_object(Scene* scene, Object* obj) {
    List_append(scene->objects, (void*) obj);
}

canonical_original_code:
void Scene_add_object(struct Scene *scene, struct Object_struct *obj) {
    List_append(scene->objects, (void *) obj);
}

variable_types: struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect); } func; } *mat; } *

user_defined_types: struct Object_struct { struct object_func_table func; struct Material_struct *mat; }

user_defined_types: struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); }

user_defined_types: struct Material_struct { struct material_func_table func; }

user_defined_types: struct material_func_table { struct material_transmit (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect); }

user_defined_types: struct ListNode_struct { void *data; struct ListNode_struct *next; }

user_defined_types: struct material_transmit { struct Color diffuse; struct Color ambient; struct Color reflect; struct Color refract; }


decompiled_code:
void __fastcall Scene_free(void *ptr)
{
_QWORD *i; // rbx

for ( i = **(_QWORD ***)ptr; i; i = (_QWORD *)i[1] )
Object_free(*i);
List_free(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *i; // rbx

for ( i = **(_QWORD ***)ptr; i; i = (_QWORD *)i[1] )
Object_free(*i);
List_free(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void Scene_free(Scene* s) {
    Object* obj;
    ListNode* node = s->objects->head;
    while (node) {
        obj = (Object*) node->data;
        Object_free(obj);
        node = node->next;
    }
    List_free(s->objects);
    free(s);
}

canonical_original_code:
void Scene_free(struct Scene *s) {
    struct Object_struct *obj;
    struct ListNode_struct *node = s->objects->head;
    while (node) {
        obj = (struct Object_struct *) node->data;
        Object_free(obj);
        node = node->next;
    }
    List_free(s->objects);
    free(s);
}

variable_types: struct ListNode_struct { void *data; struct ListNode_struct *next; } *

user_defined_types: struct Color { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
__int64 __fastcall Object_Sphere_normal(__int64 a1, __int64 a2, __int64 a3)
{
return Vector_subtract(a3, a2, a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return Vector_subtract(a3, a2, a1 + 32);
}

original_code:
void Object_Sphere_normal(const Object* obj, const Point* intersect, Vector* normal) {
    Object_Sphere* s = (Object_Sphere*) obj;
    Vector_subtract(normal, intersect, &s->pos);
}

canonical_original_code:
void Object_Sphere_normal(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal) {
    struct Object_Sphere *s = (Object_Sphere*) obj;
    Vector_subtract(normal, intersect, &s->pos);
}

variable_types:
intersect
struct Vector *

variable_types:
normal
struct Vector *

variable_types: struct Object_Sphere { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct { struct object_func_table func; struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector { double x; } *intersect); } func; } *mat; } *obj, struct Ray { struct Vector o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; struct Vector pos; double r; } *

user_defined_types: struct Object_Sphere { struct object_func_table func; struct Material_struct *mat; struct Vector pos; double r; }


original_code:
_Bool Object_Sphere_ray_intersect(const Object* obj, const Ray* r, Point* intersect) {
    const Object_Sphere* s = (Object_Sphere*) obj;
    Vector ray_origin;
    Vector_subtract(&ray_origin, &r->o, &s->pos);
    double a = Vector_mag(&r->d) * Vector_mag(&r->d);
    double b = -2 * Vector_dot(&ray_origin, &r->d);
    double c = Vector_mag(&ray_origin) * Vector_mag(&ray_origin) - (s->r * s->r);
    double det = b*b - 4*a*c;
    if (det < 0) {
        return 0;
    }
    double t1 = ( b + sqrt(det) ) / (2*a);
    double t2 = ( b - sqrt(det) ) / (2*a);
    double t;
    if (t1 <= 10*( 1.0e-5 )) {
        t = t2;
    } else if (t2 <= 10*( 1.0e-5 )) {
        t = t1;
    } else {
        t = t1<t2 ? t1 : t2;
    }
    if (t <= 10*( 1.0e-5 )) {
        return 0;
    }
    if (t < 10*( 1.0e-5 )) {
        return 0;
    }
    intersect->x = r->o.x + t*r->d.x;
    intersect->y = r->o.y + t*r->d.y;
    intersect->z = r->o.z + t*r->d.z;
    if (fabs(intersect->x - r->o.x) < 10*( 1.0e-5 ) && fabs(intersect->y - r->o.y) < 10*( 1.0e-5 ) && fabs(intersect->z - r->o.z) < 10*( 1.0e-5 ))
    {
        return 0;
    }
    return 1;
}

canonical_original_code:
_Bool Object_Sphere_ray_intersect(struct Object_struct *obj, struct Ray *r, struct Vector *intersect) {
    struct Object_Sphere *s = (Object_Sphere*) obj;
    struct Vector ray_origin;
    Vector_subtract(&ray_origin, &r->o, &s->pos);
    double a = Vector_mag(&r->d) * Vector_mag(&r->d);
    double b = -2 * Vector_dot(&ray_origin, &r->d);
    double c = Vector_mag(&ray_origin) * Vector_mag(&ray_origin) - (s->r * s->r);
    double det = b*b - 4*a*c;
    if (det < 0) {
        return 0;
    }
    double t1 = ( b + sqrt(det) ) / (2*a);
    double t2 = ( b - sqrt(det) ) / (2*a);
    double t;
    if (t1 <= 10*( 1.0e-5 )) {
        t = t2;
    } else if (t2 <= 10*( 1.0e-5 )) {
        t = t1;
    } else {
        t = t1<t2 ? t1 : t2;
    }
    if (t <= 10*( 1.0e-5 )) {
        return 0;
    }
    if (t < 10*( 1.0e-5 )) {
        return 0;
    }
    intersect->x = r->o.x + t*r->d.x;
    intersect->y = r->o.y + t*r->d.y;
    intersect->z = r->o.z + t*r->d.z;
    if (fabs(intersect->x - r->o.x) < 10*( 1.0e-5 ) && fabs(intersect->y - r->o.y) < 10*( 1.0e-5 ) && fabs(intersect->z - r->o.z) < 10*( 1.0e-5 ))
    {
        return 0;
    }
    return 1;
}

variable_types:
r
struct Ray *

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: det double

variable_types: t double


decompiled_code:
bool __fastcall Object_Sphere_inside(__int64 a1)
{
return *(double *)(a1 + 56) * *(double *)(a1 + 56) + 0.00001 >= Vector_dist_squared(a1 + 32);
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1)
{
return *(double *)(a1 + 56) * *(double *)(a1 + 56) + 0.00001 >= Vector_dist_squared(a1 + 32);
}

original_code:
_Bool Object_Sphere_inside(const Object* obj, const Point* point) {
    Object_Sphere* s = (Object_Sphere*) obj;
    return Vector_dist_squared(&s->pos, point) <= s->r * s->r + ( 1.0e-5 );
}

canonical_original_code:
_Bool Object_Sphere_inside(struct Object_struct *obj, struct Vector *point) {
    struct Object_Sphere *s = (Object_Sphere*) obj;
    return Vector_dist_squared(&s->pos, point) <= s->r * s->r + ( 1.0e-5 );
}

variable_types:
point
struct Vector *


decompiled_code:
void __fastcall Object_set_material(__int64 a1, __int64 a2)
{
free(*(void **)(a1 + 24));
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void Object_set_material(Object* obj, Material* mat) {
    free(obj->mat);
    obj->mat = mat;
}

canonical_original_code:
void Object_set_material(struct Object_struct *obj, struct Material_struct *mat) {
    free(obj->mat);
    obj->mat = mat;
}

variable_types:
mat
struct Material_struct *


decompiled_code:
void __fastcall Object_free(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

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

original_code:
void Object_free(Object* obj) {
    free(obj->mat);
    free(obj);
}

canonical_original_code:
void Object_free(struct Object_struct *obj) {
    free(obj->mat);
    free(obj);
}


original_code:
void Vector_cross(Vector* result, const Vector* a, const Vector* b) {
    Vector tmp;
    tmp.x = a->y*b->z - a->z*b->y;
    tmp.y = a->z*b->x - a->x*b->z;
    tmp.z = a->x*b->y - a->y*b->x;
    result->x = tmp.x;
    result->y = tmp.y;
    result->z = tmp.z;
}

canonical_original_code:
void Vector_cross(struct Vector *result, struct Vector *a, struct Vector *b) {
    struct Vector tmp;
    tmp.x = a->y*b->z - a->z*b->y;
    tmp.y = a->z*b->x - a->x*b->z;
    tmp.z = a->x*b->y - a->y*b->x;
    result->x = tmp.x;
    result->y = tmp.y;
    result->z = tmp.z;
}

variable_types:
result
struct Vector { double x; } *

variable_types:
a
struct Vector *

variable_types:
b
struct Vector *


decompiled_code:
double __fastcall Vector_mag(double *a1)
{
double v1; // xmm0_8
double result; // xmm0_8

v1 = a1[2] * a1[2] + *a1 * *a1 + a1[1] * a1[1];
if ( v1 < 0.0 )
result = sqrt(v1);
else
result = sqrt(v1);
return result;
}

canonical_decompiled_code:
double __fastcall func1(double *a1)
{
double v1; // xmm0_8
double result; // xmm0_8

v1 = a1[2] * a1[2] + *a1 * *a1 + a1[1] * a1[1];
if ( v1 < 0.0 )
result = sqrt(v1);
else
result = sqrt(v1);
return result;
}

original_code:
double Vector_mag(const Vector* v) {
    return sqrt( (v->x * v->x) + (v->y * v->y) + (v->z * v->z) );
}

canonical_original_code:
double Vector_mag(struct Vector *v) {
    return sqrt( (v->x * v->x) + (v->y * v->y) + (v->z * v->z) );
}

variable_types:
v
struct Vector { double x; } *

return_type: double


decompiled_code:
void __fastcall Vector_normalize(double *a1)
{
double v1; // xmm0_8

v1 = Vector_mag(a1);
*a1 = *a1 / v1;
a1[1] = a1[1] / v1;
a1[2] = a1[2] / v1;
}

original_code:
void Vector_normalize(Vector* v) {
    double mag = Vector_mag(v);
    v->x /= mag;
    v->y /= mag;
    v->z /= mag;
}

canonical_original_code:
void Vector_normalize(struct Vector *v) {
    double mag = Vector_mag(v);
    v->x /= mag;
    v->y /= mag;
    v->z /= mag;
}

variable_types: mag double


decompiled_code:
void __fastcall Vector_scalar_mult(double *a1, double *a2, double a3)
{
*a1 = a3 * *a2;
a1[1] = a3 * a2[1];
a1[2] = a3 * a2[2];
}

canonical_decompiled_code:
void __fastcall func3(double *a1, double *a2, double a3)
{
*a1 = a3 * *a2;
a1[1] = a3 * a2[1];
a1[2] = a3 * a2[2];
}

original_code:
void Vector_scalar_mult(Vector* result, const Vector* v, double s) {
    result->x = v->x * s;
    result->y = v->y * s;
    result->z = v->z * s;
}

canonical_original_code:
void Vector_scalar_mult(struct Vector *result, struct Vector *v, double s) {
    result->x = v->x * s;
    result->y = v->y * s;
    result->z = v->z * s;
}

variable_types:
v
struct Vector *

variable_types: s double


decompiled_code:
double __fastcall Vector_dot(double *a1, double *a2)
{
return *a1 * *a2 + a1[1] * a2[1] + a1[2] * a2[2];
}

canonical_decompiled_code:
double __fastcall func4(double *a1, double *a2)
{
return *a1 * *a2 + a1[1] * a2[1] + a1[2] * a2[2];
}

original_code:
double Vector_dot(const Vector* a, const Vector* b) {
    return (a->x * b->x) + (a->y * b->y) + (a->z * b->z);
}

canonical_original_code:
double Vector_dot(struct Vector *a, struct Vector *b) {
    return (a->x * b->x) + (a->y * b->y) + (a->z * b->z);
}

variable_types:
a
struct Vector { double x; } *


original_code:
void Vector_add(Vector* result, const Vector* a, const Vector* b) {
    result->x = a->x + b->x;
    result->y = a->y + b->y;
    result->z = a->z + b->z;
}

canonical_original_code:
void Vector_add(struct Vector *result, struct Vector *a, struct Vector *b) {
    result->x = a->x + b->x;
    result->y = a->y + b->y;
    result->z = a->z + b->z;
}


decompiled_code:
void __fastcall Vector_subtract(double *a1, double *a2, double *a3)
{
*a1 = *a2 - *a3;
a1[1] = a2[1] - a3[1];
a1[2] = a2[2] - a3[2];
}

original_code:
void Vector_subtract(Vector* result, const Vector* a, const Vector* b) {
    result->x = a->x - b->x;
    result->y = a->y - b->y;
    result->z = a->z - b->z;
}

canonical_original_code:
void Vector_subtract(struct Vector *result, struct Vector *a, struct Vector *b) {
    result->x = a->x - b->x;
    result->y = a->y - b->y;
    result->z = a->z - b->z;
}


original_code:
double Vector_dist_squared(const Vector* a, const Vector* b) {
    return (a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y) + (a->z - b->z) * (a->z - b->z);
}

canonical_original_code:
double Vector_dist_squared(struct Vector *a, struct Vector *b) {
    return (a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y) + (a->z - b->z) * (a->z - b->z);
}


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

result = malloc(0x18uLL);
if ( !result )
{
puts("Could not allocate memory!");
puts(" In List_new()");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

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

result = malloc(0x18uLL);
if ( !result )
{
puts("Could not allocate memory!");
puts(" In List_new()");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
List* List_new() {
    List* l = (List*) malloc(sizeof(List));
    if (!l) {
        printf("Could not allocate memory!\n");
        printf("    In List_new()\n");
        exit(1);
    }
    l->head = ((void *)0);
    l->tail = ((void *)0);
    l->length = 0;
    return l;
}

canonical_original_code:
struct List *List_new() {
    struct List *l = (List*) malloc(sizeof(List));
    if (!l) {
        printf("Could not allocate memory!\n");
        printf("    In List_new()\n");
        exit(1);
    }
    l->head = ((void *)0);
    l->tail = ((void *)0);
    l->length = 0;
    return l;
}

variable_types: struct List { struct ListNode_struct { void *data; struct ListNode_struct *next; } *head; struct ListNode_struct *tail; unsigned int length; } *


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

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

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

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void List_free(List* l) {
    ListNode* node = l->head;
    ListNode* next;
    while (node != ((void *)0)) {
        next = node->next;
        free(node);
        node = next;
    }
    free(l);
}

canonical_original_code:
void List_free(struct List *l) {
    struct ListNode_struct *node = l->head;
    struct ListNode_struct *next;
    while (node != ((void *)0)) {
        next = node->next;
        free(node);
        node = next;
    }
    free(l);
}

variable_types: struct ListNode_struct { void *data; struct ListNode_struct *next; } *


decompiled_code:
__int64 __fastcall Material_Solid_get_transmit(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
struct material_transmit Material_Solid_get_transmit(const Material* mat, const Object* object, const Point* intersect) {
    Material_Solid* m = (Material_Solid*) mat;
    return m->transmit;
}

canonical_original_code:
struct material_transmit Material_Solid_get_transmit(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect) {
    struct Material_Solid *m = (Material_Solid*) mat;
    return m->transmit;
}

variable_types: struct Material_struct { struct material_func_table { struct material_transmit (*get_transmit)(struct Material_struct *mat, struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; } *object, struct Vector *intersect); } func; } *

variable_types:
object
struct Object_struct *

variable_types:
intersect
struct Vector *

variable_types: struct Material_Solid { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct { struct material_func_table func; } *mat, struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; } *object, struct Vector *intersect); } func; struct material_transmit transmit; } *

user_defined_types: struct Material_Solid { struct material_func_table func; struct material_transmit transmit; }