run

decompiled_code:
__int64 __fastcall run(char *arg)
{
__int64 result; // rax
__int64 v2; // rax
void *v3; // rbp
int v4[56]; // [rsp+0h] [rbp-188h] BYREF
struct rusage usage; // [rsp+E0h] [rbp-A8h] BYREF

cpid = fork();
if ( !cpid )
{
limit();
freopen(input, "r", stdin);
freopen(output, "w+", stdout);
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
execl(arg, arg, 0LL);
}
while ( 1 )
{
wait4(cpid, (__WAIT_STATUS)&status, 0, &usage);
if ( (status & 0x7F) == 0 )
break;
if ( (char)((status & 0x7F) + 1) > 1 )
{
printf("%d\n", status & 0x7F);
::result(4);
}
v2 = ptrace(PTRACE_PEEKUSER, (unsigned int)cpid, 120LL, 0LL);
if ( denycall[v2] )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
return ::result(5);
}
if ( v2 == 2 )
{
v3 = malloc(0x400uLL);
ptrace(PTRACE_GETREGS, (unsigned int)cpid, 0LL, v4);
getfile(v4[28], (__int64)v3);
if ( strcmp((const char *)v3, input) || strcmp((const char *)v3, output) )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
free(v3);
::result(5);
}
free(v3);
}
use_time = 1000 * (LODWORD(usage.ru_utime.tv_sec) + LODWORD(usage.ru_stime.tv_sec))
+ (LODWORD(usage.ru_utime.tv_usec) + LODWORD(usage.ru_stime.tv_usec)) / 1000;
if ( use_time > time_limit )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
::result(1);
}
use_mem = musage((unsigned int)cpid);
if ( use_mem > mem_limit )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
::result(2);
}
ptrace(PTRACE_SYSCALL, (unsigned int)cpid, 0LL, 0LL);
}
if ( BYTE1(status) )
result = ::result(4);
else
result = ::result(0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *arg)
{
__int64 result; // rax
__int64 v2; // rax
void *v3; // rbp
int v4[56]; // [rsp+0h] [rbp-188h] BYREF
struct rusage usage; // [rsp+E0h] [rbp-A8h] BYREF

cpid = fork();
if ( !cpid )
{
func9();
freopen(input, "r", stdin);
freopen(output, "w+", stdout);
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
execl(arg, arg, 0LL);
}
while ( 1 )
{
wait4(cpid, (__WAIT_STATUS)&status, 0, &usage);
if ( (status & 0x7F) == 0 )
break;
if ( (char)((status & 0x7F) + 1) > 1 )
{
printf("%d\n", status & 0x7F);
::func7(4);
}
v2 = ptrace(PTRACE_PEEKUSER, (unsigned int)cpid, 120LL, 0LL);
if ( denycall[v2] )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
return ::func7(5);
}
if ( v2 == 2 )
{
v3 = malloc(0x400uLL);
ptrace(PTRACE_GETREGS, (unsigned int)cpid, 0LL, v4);
func10(v4[28], (__int64)v3);
if ( strcmp((const char *)v3, input) || strcmp((const char *)v3, output) )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
free(v3);
::func7(5);
}
free(v3);
}
use_time = 1000 * (LODWORD(usage.ru_utime.tv_sec) + LODWORD(usage.ru_stime.tv_sec))
+ (LODWORD(usage.ru_utime.tv_usec) + LODWORD(usage.ru_stime.tv_usec)) / 1000;
if ( use_time > time_limit )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
::func7(1);
}
use_mem = func8((unsigned int)cpid);
if ( use_mem > mem_limit )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
::func7(2);
}
ptrace(PTRACE_SYSCALL, (unsigned int)cpid, 0LL, 0LL);
}
if ( BYTE1(status) )
result = ::func7(4);
else
result = ::func7(0);
return result;
}

original_code:
void run(char *path) {
    cpid = fork();
    long orig_rax;
    struct rusage used;
    if(cpid == 0) {
        limit();
        freopen(input, "r", stdin);
        freopen(output, "w+", stdout);
        ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
        execl(path, path, ((void *)0));
    }
    while(1) {
        wait4(cpid, &status, 0, &used);
        if((((status) & 0x7f) == 0)) {
            if(!(((status) & 0xff00) >> 8)) {
                result(RS_NML);
            } else {
                result(RS_RE);
            }
            break;
        } else if((((signed char) (((status) & 0x7f) + 1) >> 1) > 0)) {
            printf("%d\n", ((status) & 0x7f));
            result(RS_RE);
        }
        orig_rax = ptrace(PTRACE_PEEKUSER, cpid, 8 * 15, ((void *)0));
        if(denycall[orig_rax]) {
            ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
            kill(cpid, 9);
            result(RS_RF);
            return;
        }
        if(orig_rax == 2) {
            char *filepath = (char *)malloc(1024);
            struct user_regs_struct regs;
            ptrace(PTRACE_GETREGS, cpid, ((void *)0), &regs);
            getfile(regs.rdi, filepath);
            if(strcmp(filepath, input) || strcmp(filepath, output)) {
                ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
                kill(cpid, 9);
                free(filepath);
                result(RS_RF);
            }
            free(filepath);
        }
        use_time = (used.ru_utime.tv_sec + used.ru_stime.tv_sec) * 1000 + (used.ru_utime.tv_usec + used.ru_stime.tv_usec) / 1000;
        if(use_time > time_limit) {
            ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
            kill(cpid, 9);
            result(RS_TLE);
        }
        use_mem = musage(cpid);
        if(use_mem > mem_limit) {
            ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
            kill(cpid, 9);
            result(RS_MLE);
        }
        ptrace(PTRACE_SYSCALL, cpid, ((void *)0), ((void *)0));
    }
}

canonical_original_code:
void run(char *path) {
    cpid = fork();
    long orig_rax;
    struct rusage used;
    if(cpid == 0) {
        limit();
        freopen(input, "r", stdin);
        freopen(output, "w+", stdout);
        ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
        execl(path, path, ((void *)0));
    }
    while(1) {
        wait4(cpid, &status, 0, &used);
        if((((status) & 0x7f) == 0)) {
            if(!(((status) & 0xff00) >> 8)) {
                result(RS_NML);
            } else {
                result(RS_RE);
            }
            break;
        } else if((((char) (((status) & 0x7f) + 1) >> 1) > 0)) {
            printf("%d\n", ((status) & 0x7f));
            result(RS_RE);
        }
        orig_rax = ptrace(PTRACE_PEEKUSER, cpid, 8 * 15, ((void *)0));
        if(denycall[orig_rax]) {
            ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
            kill(cpid, 9);
            result(RS_RF);
            return;
        }
        if(orig_rax == 2) {
            char *filepath = (char *)malloc(1024);
            struct user_regs_struct regs;
            ptrace(PTRACE_GETREGS, cpid, ((void *)0), &regs);
            getfile(regs.rdi, filepath);
            if(strcmp(filepath, input) || strcmp(filepath, output)) {
                ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
                kill(cpid, 9);
                free(filepath);
                result(RS_RF);
            }
            free(filepath);
        }
        use_time = (used.ru_utime.tv_sec + used.ru_stime.tv_sec) * 1000 + (used.ru_utime.tv_usec + used.ru_stime.tv_usec) / 1000;
        if(use_time > time_limit) {
            ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
            kill(cpid, 9);
            result(RS_TLE);
        }
        use_mem = musage(cpid);
        if(use_mem > mem_limit) {
            ptrace(PTRACE_KILL, cpid, ((void *)0), ((void *)0));
            kill(cpid, 9);
            result(RS_MLE);
        }
        ptrace(PTRACE_SYSCALL, cpid, ((void *)0), ((void *)0));
    }
}

variable_types:
path
char *

variable_types: struct rusage { struct timeval { long tv_sec; long tv_usec; } ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }

variable_types:
filepath
char *

variable_types: struct user_regs_struct { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long rbp; unsigned long long rbx; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rax; unsigned long long rcx; unsigned long long rdx; unsigned long long rsi; unsigned long long rdi; unsigned long long orig_rax; unsigned long long rip; unsigned long long cs; unsigned long long eflags; unsigned long long rsp; unsigned long long ss; unsigned long long fs_base; unsigned long long gs_base; unsigned long long ds; unsigned long long es; unsigned long long fs; unsigned long long gs; }

user_defined_types: struct rusage { struct timeval ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }


result

decompiled_code:
__int64 __fastcall result(int a1)
{
switch ( a1 )
{
case 0:
printf("%d %d %d\n", 0LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 1:
printf("%d %d %d\n", 1LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 2:
printf("%d %d %d\n", 2LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 3:
printf("%d %d %d\n", 3LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 4:
printf("%d %d %d\n", 4LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 5:
printf("%d %d %d\n", 5LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
switch ( a1 )
{
case 0:
printf("%d %d %d\n", 0LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 1:
printf("%d %d %d\n", 1LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 2:
printf("%d %d %d\n", 2LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 3:
printf("%d %d %d\n", 3LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 4:
printf("%d %d %d\n", 4LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
case 5:
printf("%d %d %d\n", 5LL, (unsigned int)use_time, (unsigned int)use_mem);
exit(0);
}
return 0LL;
}

original_code:
int result(int rs) {
    if(rs == RS_NML) {
        printf("%d %d %d\n", RS_NML, use_time, use_mem);
        exit(0);
    } else if(rs == RS_TLE) {
        printf("%d %d %d\n", RS_TLE, use_time, use_mem);
        exit(0);
    } else if(rs == RS_MLE) {
        printf("%d %d %d\n", RS_MLE, use_time, use_mem);
        exit(0);
    } else if(rs == RS_OLE) {
        printf("%d %d %d\n", RS_OLE, use_time, use_mem);
        exit(0);
    } else if(rs == RS_RE) {
        printf("%d %d %d\n", RS_RE, use_time, use_mem);
        exit(0);
    } else if(rs == RS_RF) {
        printf("%d %d %d\n", RS_RF, use_time, use_mem);
        exit(0);
    }
    return 0;
}

variable_types: rs int

return_type: int


binExist

decompiled_code:
__int64 __fastcall binExist(const char *a1)
{
if ( access(a1, 0) )
{
puts("Binary non exist!");
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
if ( access(a1, 0) )
{
puts("Binary non exist!");
exit(1);
}
return 0LL;
}

original_code:
int binExist(char *filename) {
    if(access(filename, 0)) {
        printf("Binary non exist!\n");
        exit(1);
    } else {
        return 0;
    }
}

variable_types:
filename
char *


main

canonical_name: main

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

if ( argc <= 6 )
{
puts("ERROR: Not enough arguments\nFormat: executor [binary] [input] [output] [time] [memory] [output_size]");
result = 1;
}
else
{
binExist(argv[1]);
strcpy(input, argv[2]);
strcpy(output, argv[3]);
time_limit = atoi(argv[4]);
mem_limit = (additional_mem + atoi(argv[5])) << 20;
file_limit = atoi(argv[6]) << 20;
run((char *)argv[1]);
result = 0;
}
return result;
}

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

if ( argc <= 6 )
{
puts("ERROR: Not enough arguments\nFormat: executor [binary] [input] [output] [time] [memory] [output_size]");
result = 1;
}
else
{
func11(argv[1]);
strcpy(input, argv[2]);
strcpy(output, argv[3]);
time_limit = atoi(argv[4]);
mem_limit = (additional_mem + atoi(argv[5])) << 20;
file_limit = atoi(argv[6]) << 20;
func12((char *)argv[1]);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
    if(argc < 7) {
        printf("ERROR: Not enough arguments\n" "Format: executor [binary] [input] [output] [time] [memory] [output_size]\n");
        return 1;
    } else {
        binExist(argv[1]);
        strcpy(input, argv[2]);
        strcpy(output, argv[3]);
        time_limit = atoi(argv[4]);
        mem_limit = (atoi(argv[5]) + additional_mem) * 1024 * 1024;
        file_limit = atoi(argv[6]) * 1024 * 1024;
        run(argv[1]);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


filestatus

decompiled_code:
void filestatus()
{
if ( access(ans_file, 0) )
{
perror("Ans non exist!\n");
result(3);
}
if ( access(out_file, 0) )
{
perror("Output non exist!\n");
result(2);
}
}

canonical_decompiled_code:
void func9()
{
if ( access(ans_file, 0) )
{
perror("Ans non exist!\n");
func7(3);
}
if ( access(out_file, 0) )
{
perror("Output non exist!\n");
func7(2);
}
}

original_code:
void filestatus() {
    if(access(ans_file, 0)) {
        perror("Ans non exist!\n");
        result(RS_NOANS);
    }
    if(access(out_file, 0)) {
        perror("Output non exist!\n");
        result(RS_NOFILE);
    }
}

return_type: void


result

decompiled_code:
void __fastcall result(int a1)
{
switch ( a1 )
{
case 0:
printf("%d\n", 0LL);
exit(0);
case 1:
printf("%d\n", 1LL);
exit(0);
case 2:
printf("%d\n", 2LL);
exit(0);
case 3:
printf("%d\n", 3LL);
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
switch ( a1 )
{
case 0:
printf("%d\n", 0LL);
exit(0);
case 1:
printf("%d\n", 1LL);
exit(0);
case 2:
printf("%d\n", 2LL);
exit(0);
case 3:
printf("%d\n", 3LL);
exit(0);
}
}

original_code:
void result(int res) {
    if(res == RS_AC) {
        printf("%d\n", RS_AC);
        exit(0);
    } else if (res == RS_WA) {
        printf("%d\n", RS_WA);
        exit(0);
    } else if (res == RS_NOFILE) {
        printf("%d\n", RS_NOFILE);
        exit(0);
    } else if (res == RS_NOANS) {
        printf("%d\n", RS_NOANS);
        exit(0);
    }
}

variable_types: res int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
{
puts("ERROR: Not enough arguments\nFormat: checker [answer] [output]");
exit(1);
}
strcpy(ans_file, argv[1]);
strcpy(out_file, argv[2]);
filestatus();
anscmp();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
{
puts("ERROR: Not enough arguments\nFormat: checker [answer] [output]");
exit(1);
}
strcpy(ans_file, argv[1]);
strcpy(out_file, argv[2]);
func9();
func8();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    if(argc < 3) {
        printf("ERROR: Not enough arguments\n" "Format: checker [answer] [output]\n");
        exit(1);
    }
    sprintf(ans_file, "%s", argv[1]);
    sprintf(out_file, "%s", argv[2]);
    filestatus();
    anscmp();
    return 0;
}


show

decompiled_code:
int __fastcall show(char *a1)
{
wmove(_bss_start, 10, 20);
waddnstr(_bss_start, "Hello, world!", -1);
wmove(_bss_start, 11, 20);
waddnstr(_bss_start, "Init:", -1);
waddnstr(_bss_start, a1, -1);
wmove(_bss_start, LINES__NCURSES6_TINFO_5_0_19991023 + 1, 20);
wrefresh(_bss_start);
return usleep(0xF4240u);
}

canonical_decompiled_code:
int __fastcall func7(char *a1)
{
wmove(_bss_start, 10, 20);
waddnstr(_bss_start, "Hello, world!", -1);
wmove(_bss_start, 11, 20);
waddnstr(_bss_start, "Init:", -1);
waddnstr(_bss_start, a1, -1);
wmove(_bss_start, LINES__NCURSES6_TINFO_5_0_19991023 + 1, 20);
wrefresh(_bss_start);
return usleep(0xF4240u);
}

original_code:
void show(char *sign)
{
 wmove(stdscr,(10),(20));
 waddnstr(stdscr,"Hello, world!",-1);
 wmove(stdscr,(10 +1),(20));
 waddnstr(stdscr,("Init:"),-1);
 waddnstr(stdscr,(sign),-1);
 wmove(stdscr,(LINES+1),(20));
 wrefresh(stdscr);
 usleep(1*1000*1000);
}

variable_types:
sign
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
initscr();
wclear(_bss_start);
keypad(_bss_start, 1);
if ( has_colors() )
{
start_color();
init_pair(0, 0, 0);
init_pair(1, 2, 0);
init_pair(2, 1, 0);
init_pair(3, 6, 0);
init_pair(4, 7, 0);
init_pair(5, 5, 0);
init_pair(6, 4, 0);
init_pair(7, 3, 0);
wattr_on(_bss_start, 0x80100uLL, 0LL);
}
while ( 1 )
{
show((char *)L"|/-\\");
show((char *)L"/-\\");
show((char *)L"-\\");
show((char *)L"\\");
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
initscr();
wclear(_bss_start);
keypad(_bss_start, 1);
if ( has_colors() )
{
start_color();
init_pair(0, 0, 0);
init_pair(1, 2, 0);
init_pair(2, 1, 0);
init_pair(3, 6, 0);
init_pair(4, 7, 0);
init_pair(5, 5, 0);
init_pair(6, 4, 0);
init_pair(7, 3, 0);
wattr_on(_bss_start, 0x80100uLL, 0LL);
}
while ( 1 )
{
func7((char *)L"|/-\\");
func7((char *)L"/-\\");
func7((char *)L"-\\");
func7((char *)L"\\");
}
}


repo: zohead/fbvnc

decompiled_code:
__int64 fb_len()
{
return (unsigned int)(dword_6054C * dword_60510);
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)(dword_6054C * dword_60510);
}

original_code:
static int fb_len(void)
{
 return finfo.line_length * vinfo.yres_virtual;
}

canonical_original_code:
static int fb_len()
{
 return finfo.line_length * vinfo.yres_virtual;
}


decompiled_code:
int __fastcall fb_cmap_save(int a1)
{
int result; // eax
int v2[2]; // [rsp+0h] [rbp-38h] BYREF
void *v3; // [rsp+8h] [rbp-30h]
void *v4; // [rsp+10h] [rbp-28h]
void *v5; // [rsp+18h] [rbp-20h]
__int64 v6; // [rsp+20h] [rbp-18h]

if ( dword_60504 != 2 )
{
v2[0] = 0;
v2[1] = (int)&unk_10000;
v3 = &red_3;
v4 = &green_2;
v5 = &blue_1;
v6 = 0LL;
result = ioctl(fd, (a1 == 0) + 17924LL, v2);
}
return result;
}

original_code:
static void fb_cmap_save(int save)
{
 static unsigned short red[(1 << 16)], green[(1 << 16)], blue[(1 << 16)];
 struct fb_cmap cmap;
 if (finfo.visual == 2)
  return;
 cmap.start = 0;
 cmap.len = (1 << 16);
 cmap.red = red;
 cmap.green = green;
 cmap.blue = blue;
 cmap.transp = ((void *)0);
 ioctl(fd, save ? 0x4604 : 0x4605, &cmap);
}

canonical_original_code:
static void fb_cmap_save(int save)
{
 static unsigned short red[-1]; static unsigned short green[-1]; static unsigned short blue[-1];
 struct fb_cmap cmap;
 if (finfo.visual == 2)
  return;
 cmap.start = 0;
 cmap.len = (1 << 16);
 cmap.red = red;
 cmap.green = green;
 cmap.blue = blue;
 cmap.transp = ((void *)0);
 ioctl(fd, save ? 0x4604 : 0x4605, &cmap);
}

variable_types: save int

variable_types:
red
unsigned short [-1]

variable_types:
green
unsigned short [-1]

variable_types:
blue
unsigned short [-1]

variable_types: struct fb_cmap { unsigned int start; unsigned int len; unsigned short *red; unsigned short *green; unsigned short *blue; unsigned short *transp; }


original_code:
void fb_cmap(void)
{
 struct fb_bitfield *color[3] = {
  &vinfo.blue, &vinfo.green, &vinfo.red
 };
 int eye_sensibility[3] = { 2, 0, 1 };
 struct fb_cmap cmap;
 unsigned short map[3][(1 << 16)];
 int i, j, n, offset;
 if (finfo.visual == 2)
  return;
 for (i = 0, n = vinfo.bits_per_pixel; i < 3; i++) {
  n -= color[eye_sensibility[i]]->length = n / (3 - i);
 }
 n = (1 << vinfo.bits_per_pixel);
 if (n > (1 << 16))
  n = (1 << 16);
 for (i = offset = 0; i < 3; i++) {
  int length = color[i]->length;
  color[i]->offset = offset;
  for (j = 0; j < n; j++) {
   int k = (j >> offset) << (16 - length);
   if (k == (0xFFFF << (16 - length)))
    k = 0xFFFF;
   map[i][j] = k;
  }
  offset += length;
 }
 cmap.start = 0;
 cmap.len = n;
 cmap.red = map[2];
 cmap.green = map[1];
 cmap.blue = map[0];
 cmap.transp = ((void *)0);
 ioctl(fd, 0x4605, &cmap);
}

canonical_original_code:
void fb_cmap()
{
 struct fb_bitfield *color[3] = {
  &vinfo.blue, &vinfo.green, &vinfo.red
 };
 int eye_sensibility[3] = { 2, 0, 1 };
 struct fb_cmap cmap;
 unsigned short map[3][-1];
 int i; int j; int n; int offset;
 if (finfo.visual == 2)
  return;
 for (i = 0, n = vinfo.bits_per_pixel; i < 3; i++) {
  n -= color[eye_sensibility[i]]->length = n / (3 - i);
 }
 n = (1 << vinfo.bits_per_pixel);
 if (n > (1 << 16))
  n = (1 << 16);
 for (i = offset = 0; i < 3; i++) {
  int length = color[i]->length;
  color[i]->offset = offset;
  for (j = 0; j < n; j++) {
   int k = (j >> offset) << (16 - length);
   if (k == (0xFFFF << (16 - length)))
    k = 0xFFFF;
   map[i][j] = k;
  }
  offset += length;
 }
 cmap.start = 0;
 cmap.len = n;
 cmap.red = map[2];
 cmap.green = map[1];
 cmap.blue = map[0];
 cmap.transp = ((void *)0);
 ioctl(fd, 0x4605, &cmap);
}

variable_types: struct fb_bitfield { unsigned int offset; unsigned int length; unsigned int msb_right; } *[3]

variable_types:
map
unsigned short [3][-1]

variable_types: i int

variable_types: j int

variable_types: n int

variable_types: offset int

variable_types: length int

variable_types: k int

user_defined_types: struct fb_cmap { unsigned int start; unsigned int len; unsigned short *red; unsigned short *green; unsigned short *blue; unsigned short *transp; }


decompiled_code:
__int64 fb_mode()
{
return (bytes_per_pixel << 16) | dword_6057C | (16 * dword_60570) | (unsigned int)(dword_60564 << 8);
}

canonical_decompiled_code:
__int64 func3()
{
return (bytes_per_pixel << 16) | dword_6057C | (16 * dword_60570) | (unsigned int)(dword_60564 << 8);
}

original_code:
unsigned fb_mode(void)
{
 return (bytes_per_pixel << 16) | (vinfo.red.length << 8) |
  (vinfo.green.length << 4) | (vinfo.blue.length);
}

canonical_original_code:
unsigned int fb_mode()
{
 return (bytes_per_pixel << 16) | (vinfo.red.length << 8) |
  (vinfo.green.length << 4) | (vinfo.blue.length);
}

return_type: unsigned int


decompiled_code:
__int64 fb_init()
{
int v0; // eax
int v1; // ebx
int v2; // eax
int v3; // eax
unsigned int v4; // ebx

v0 = open("/dev/fb0", 2);
fd = v0;
if ( v0 == -1 )
{
v4 = 1;
LABEL_7:
perror("fb_init()");
close(fd);
return v4;
}
v1 = v0;
if ( ioctl(v0, 0x4600uLL, &vinfo) == -1 )
{
v4 = 2;
goto LABEL_7;
}
if ( ioctl(v1, 0x4602uLL, &finfo) == -1 )
{
v4 = 3;
goto LABEL_7;
}
v2 = fcntl(v1, 1);
fcntl(fd, 2, v2 | 1u);
bytes_per_pixel = (unsigned int)(dword_60558 + 7) >> 3;
v3 = fb_len();
fb = mmap(0LL, v3, 3, 1, fd, 0LL);
if ( fb == (void *)-1LL )
{
v4 = 4;
goto LABEL_7;
}
fb_cmap_save(1);
fb_cmap();
return 0;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
int v1; // ebx
int v2; // eax
int v3; // eax
unsigned int v4; // ebx

v0 = open("/dev/fb0", 2);
fd = v0;
if ( v0 == -1 )
{
v4 = 1;
LABEL_7:
perror("fb_init()");
close(fd);
return v4;
}
v1 = v0;
if ( ioctl(v0, 0x4600uLL, &vinfo) == -1 )
{
v4 = 2;
goto LABEL_7;
}
if ( ioctl(v1, 0x4602uLL, &finfo) == -1 )
{
v4 = 3;
goto LABEL_7;
}
v2 = fcntl(v1, 1);
fcntl(fd, 2, v2 | 1u);
bytes_per_pixel = (unsigned int)(dword_60558 + 7) >> 3;
v3 = func0();
fb = mmap(0LL, v3, 3, 1, fd, 0LL);
if ( fb == (void *)-1LL )
{
v4 = 4;
goto LABEL_7;
}
func1(1);
func2();
return 0;
}

original_code:
int fb_init(void)
{
 int err = 1;
 fd = open("/dev/fb0", 02);
 if (fd == -1)
  goto failed;
 err++;
 if (ioctl(fd, 0x4600, &vinfo) == -1)
  goto failed;
 err++;
 if (ioctl(fd, 0x4602, &finfo) == -1)
  goto failed;
 fcntl(fd, 2, fcntl(fd, 1) | 1);
 bytes_per_pixel = (vinfo.bits_per_pixel + 7) >> 3;
 fb = mmap(((void *)0), fb_len(), 0x1 | 0x2, 0x01, fd, 0);
 err++;
 if (fb == ((void *) -1))
  goto failed;
 fb_cmap_save(1);
 fb_cmap();
 return 0;
failed:
 perror("fb_init()");
 close(fd);
 return err;
}

canonical_original_code:
int fb_init()
{
 int err = 1;
 fd = open("/dev/fb0", 02);
 if (fd == -1)
  goto failed;
 err++;
 if (ioctl(fd, 0x4600, &vinfo) == -1)
  goto failed;
 err++;
 if (ioctl(fd, 0x4602, &finfo) == -1)
  goto failed;
 fcntl(fd, 2, fcntl(fd, 1) | 1);
 bytes_per_pixel = (vinfo.bits_per_pixel + 7) >> 3;
 fb = mmap(((void *)0), fb_len(), 0x1 | 0x2, 0x01, fd, 0);
 err++;
 if (fb == ((void *) -1))
  goto failed;
 fb_cmap_save(1);
 fb_cmap();
 return 0;
failed:
 perror("fb_init()");
 close(fd);
 return err;
}

variable_types: err int


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

fb_cmap_save(0);
v0 = fb_len();
munmap(fb, v0);
return close(fd);
}

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

func1(0);
v0 = func0();
munmap(fb, v0);
return close(fd);
}

original_code:
void fb_free(void)
{
 fb_cmap_save(0);
 munmap(fb, fb_len());
 close(fd);
}

canonical_original_code:
void fb_free()
{
 fb_cmap_save(0);
 munmap(fb, fb_len());
 close(fd);
}


decompiled_code:
__int64 fb_rows()
{
return (unsigned int)dword_60544;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)dword_60544;
}

original_code:
int fb_rows(void)
{
 return vinfo.yres;
}

canonical_original_code:
int fb_rows()
{
 return vinfo.yres;
}


decompiled_code:
__int64 fb_cols()
{
return (unsigned int)vinfo;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)vinfo;
}

original_code:
int fb_cols(void)
{
 return vinfo.xres;
}

canonical_original_code:
int fb_cols()
{
 return vinfo.xres;
}


decompiled_code:
char *__fastcall fb_mem(int a1)
{
return (char *)fb + (unsigned int)(dword_60510 * (dword_60554 + a1));
}

canonical_decompiled_code:
char *__fastcall func8(int a1)
{
return (char *)fb + (unsigned int)(dword_60510 * (dword_60554 + a1));
}

original_code:
void *fb_mem(int r)
{
 return fb + (r + vinfo.yoffset) * finfo.line_length;
}

variable_types: r int

return_type: void *


decompiled_code:
void *__fastcall fb_set(int a1, int a2, const void *a3, int a4)
{
int v6; // er12
char *v7; // rax

v6 = bytes_per_pixel;
v7 = fb_mem(a1);
return memcpy(&v7[v6 * (dword_60550 + a2)], a3, a4 * v6);
}

canonical_decompiled_code:
void *__fastcall func9(int a1, int a2, const void *a3, int a4)
{
int v6; // er12
char *v7; // rax

v6 = bytes_per_pixel;
v7 = func8(a1);
return memcpy(&v7[v6 * (dword_60550 + a2)], a3, a4 * v6);
}

original_code:
void fb_set(int r, int c, void *mem, int len)
{
 memcpy(fb_mem(r) + (c + vinfo.xoffset) * bytes_per_pixel,
  mem, len * bytes_per_pixel);
}

variable_types: c int

variable_types:
mem
void *

variable_types: len int


decompiled_code:
__int64 __fastcall fb_val(int a1, int a2, int a3)
{
int v5; // eax

if ( !c_0 )
{
v5 = fb_mode();
fill_rgb_conv(v5, &c_0);
}
return (a1 >> dword_4A8 << c_0) | (a3 >> dword_4B0) | (unsigned int)(a2 >> dword_4AC << dword_4A4);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2, int a3)
{
int v5; // eax

if ( !c_0 )
{
v5 = func3();
func10(v5, &c_0);
}
return (a1 >> dword_4A8 << c_0) | (a3 >> dword_4B0) | (unsigned int)(a2 >> dword_4AC << dword_4A4);
}

original_code:
unsigned fb_val(int r, int g, int b)
{
 static struct rgb_conv c;
 if (c.rshl == 0)
  fill_rgb_conv(fb_mode(), &c);
 return ((r >> c.rskp) << c.rshl) | ((g >> c.gskp) << c.gshl)
      | (b >> c.bskp);
}

canonical_original_code:
unsigned int fb_val(int r, int g, int b)
{
 static struct rgb_conv c;
 if (c.rshl == 0)
  fill_rgb_conv(fb_mode(), &c);
 return ((r >> c.rskp) << c.rshl) | ((g >> c.gskp) << c.gshl)
      | (b >> c.bskp);
}

variable_types: g int

variable_types: b int

variable_types: struct rgb_conv { int rshl; int rskp; int rmax; }


vncEncryptAndStorePasswd

decompiled_code:
_BOOL8 __fastcall vncEncryptAndStorePasswd(char *a1, char *a2)
{
return !vncEncryptAndStorePasswd2(a1, 0LL, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *a1, char *a2)
{
return !func0(a1, 0LL, a2);
}

original_code:
int
vncEncryptAndStorePasswd(char *passwd, char *fname)
{
    return (vncEncryptAndStorePasswd2(passwd, ((void *)0), fname) == 0);
}

variable_types:
passwd
char *

variable_types:
fname
char *


vncDecryptPasswdFromFile

decompiled_code:
void *__fastcall vncDecryptPasswdFromFile(char *filename)
{
void *v1; // rax
void *v2; // rbx

v1 = malloc(9uLL);
v2 = v1;
if ( v1 && !(unsigned int)vncDecryptPasswdFromFile2(filename, (__int64)v1, 0LL) )
{
free(v2);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(char *filename)
{
void *v1; // rax
void *v2; // rbx

v1 = malloc(9uLL);
v2 = v1;
if ( v1 && !(unsigned int)func2(filename, (__int64)v1, 0LL) )
{
free(v2);
v2 = 0LL;
}
return v2;
}

original_code:
char *
vncDecryptPasswdFromFile(char *fname)
{
    char *passwd;
    passwd = malloc(9);
    if (passwd != ((void *)0)) {
 if (vncDecryptPasswdFromFile2(fname, passwd, ((void *)0)) == 0) {
     free(passwd);
     passwd = ((void *)0);
 }
    }
    return passwd;
}

canonical_original_code:
char *vncDecryptPasswdFromFile(char *fname)
{
    char *passwd;
    passwd = malloc(9);
    if (passwd != ((void *)0)) {
 if (vncDecryptPasswdFromFile2(fname, passwd, ((void *)0)) == 0) {
     free(passwd);
     passwd = ((void *)0);
 }
    }
    return passwd;
}

return_type: char *


vncRandomBytes

decompiled_code:
__int64 __fastcall vncRandomBytes(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 result; // rax
int v3; // ebx
__pid_t v4; // eax

if ( !s_srandom_called )
{
v3 = time(0LL);
v4 = getpid();
srandom(v4 ^ v3);
s_srandom_called = 1;
}
v1 = a1;
do
{
result = random();
*v1++ = result;
}
while ( v1 != a1 + 16 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 result; // rax
int v3; // ebx
__pid_t v4; // eax

if ( !s_srandom_called )
{
v3 = time(0LL);
v4 = getpid();
srandom(v4 ^ v3);
s_srandom_called = 1;
}
v1 = a1;
do
{
result = random();
*v1++ = result;
}
while ( v1 != a1 + 16 );
return result;
}

original_code:
void
vncRandomBytes(unsigned char *bytes)
{
    int i;
    unsigned int seed;
    if (!s_srandom_called) {
      seed = (unsigned int)time(0) ^ (unsigned int)getpid();
      srandom(seed);
      s_srandom_called = 1;
    }
    for (i = 0; i < 16; i++) {
 bytes[i] = (unsigned char)(random() & 255);
    }
}

variable_types:
bytes
unsigned char *

variable_types:
seed
unsigned int


vncEncryptBytes

decompiled_code:
__int64 __fastcall vncEncryptBytes(__int64 a1, const char *a2)
{
size_t i; // rbx
size_t v3; // rdx
char v4; // al
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v3 = strlen(a2);
v4 = 0;
if ( v3 > i )
v4 = a2[i];
v6[i] = v4;
}
deskey(v6, 0LL);
des(a1, a1);
return des(a1 + 8, a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
size_t i; // rbx
size_t v3; // rdx
char v4; // al
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v3 = strlen(a2);
v4 = 0;
if ( v3 > i )
v4 = a2[i];
v6[i] = v4;
}
deskey(v6, 0LL);
des(a1, a1);
return des(a1 + 8, a1 + 8);
}

original_code:
void
vncEncryptBytes(unsigned char *bytes, char *passwd)
{
    unsigned char key[8];
    int i;
    for (i = 0; i < 8; i++) {
 if (i < strlen(passwd)) {
     key[i] = passwd[i];
 } else {
     key[i] = 0;
 }
    }
    deskey(key, 0);
    for (i = 0; i < 16; i += 8) {
 des(bytes+i, bytes+i);
    }
}

variable_types:
key
unsigned char [8]

variable_types: i int


repo: zoltanp/xrandr-invert-colors

decompiled_code:
__int64 __fastcall parse_debug_argument(int a1, __int64 a2, _DWORD *a3)
{
const char **v4; // rbx

if ( a1 <= 1 )
return 0LL;
v4 = (const char **)(a2 + 8);
do
{
if ( !strcmp(*v4, "-d") )
{
*a3 = 1;
puts("debug output enabled");
}
++v4;
}
while ( v4 != (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, _DWORD *a3)
{
const char **v4; // rbx

if ( a1 <= 1 )
return 0LL;
v4 = (const char **)(a2 + 8);
do
{
if ( !strcmp(*v4, "-d") )
{
*a3 = 1;
puts("debug output enabled");
}
++v4;
}
while ( v4 != (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
return 0LL;
}

original_code:
int parse_debug_argument(int argc, const char *argv[], int *is_debug_enabled) {
 int current_arg;
 for (current_arg = 1; current_arg < argc; current_arg++) {
  if (strcmp(argv[current_arg], "-d") == 0) {
   *is_debug_enabled = 1;
   if ((is_debug_enabled)) { printf("debug output enabled\n"); };
  }
 }
 return 0;
}

canonical_original_code:
int parse_debug_argument(int argc, char *argv[], int *is_debug_enabled) {
 int current_arg;
 for (current_arg = 1; current_arg < argc; current_arg++) {
  if (strcmp(argv[current_arg], "-d") == 0) {
   *is_debug_enabled = 1;
   if ((is_debug_enabled)) { printf("debug output enabled\n"); };
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall display_usage(const char *a1)
{
printf("Usage: %s [options] [-s screen_number]\n", a1);
printf(" %s -h\n", a1);
printf(" %s --help\n", a1);
printf(" %s --version\n", a1);
puts(" Options:");
puts(" -d enable debug output");
puts("Simple utility that inverts colors on all screens, using XrandR.");
return puts(
"When no parameter is given, it inverts colors on all screens; if the screen_number parameter is given, then i"
"t inverts colors on that particular XRandR screen. See 'xrandr -q' for the list of screens.");
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
printf("Usage: %s [options] [-s screen_number]\n", a1);
printf(" %s -h\n", a1);
printf(" %s --help\n", a1);
printf(" %s --version\n", a1);
puts(" Options:");
puts(" -d enable debug output");
puts("Simple utility that inverts colors on all screens, using XrandR.");
return puts(
"When no parameter is given, it inverts colors on all screens; if the screen_number parameter is given, then i"
"t inverts colors on that particular XRandR screen. See 'xrandr -q' for the list of screens.");
}

original_code:
void display_usage(const char * program_name) {
 printf("Usage: %s [options] [-s screen_number]\n", program_name);
 printf("       %s -h\n", program_name);
 printf("       %s --help\n", program_name);
 printf("       %s --version\n", program_name);
 printf(" Options:\n");
 printf("   -d    enable debug output\n");
 printf("Simple utility that inverts colors on all screens, using XrandR.\n");
 printf("When no parameter is given, it inverts colors on all screens; "
  "if the screen_number parameter is given, then it inverts colors on "
  "that particular XRandR screen. See 'xrandr -q' for the list of screens.\n");
}

canonical_original_code:
void display_usage(char *program_name) {
 printf("Usage: %s [options] [-s screen_number]\n", program_name);
 printf("       %s -h\n", program_name);
 printf("       %s --help\n", program_name);
 printf("       %s --version\n", program_name);
 printf(" Options:\n");
 printf("   -d    enable debug output\n");
 printf("Simple utility that inverts colors on all screens, using XrandR.\n");
 printf("When no parameter is given, it inverts colors on all screens; "
  "if the screen_number parameter is given, then it inverts colors on "
  "that particular XRandR screen. See 'xrandr -q' for the list of screens.\n");
}


decompiled_code:
int __fastcall display_version(const char *a1)
{
return printf("%s: version 0.01\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return printf("%s: version 0.01\n", a1);
}

original_code:
void display_version(const char * program_name) {
 printf("%s: version 0.01\n", program_name);
}

canonical_original_code:
void display_version(char *program_name) {
 printf("%s: version 0.01\n", program_name);
}


decompiled_code:
__int64 __fastcall copy_inverted_ramps(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v7; // er11
unsigned int v8; // edx
__int64 v9; // rcx
int v10; // edx
int v11; // er9
int v12; // edx

result = *(unsigned int *)(a1 + 4);
if ( (_DWORD)result )
{
v7 = result - 1;
v8 = result - 1;
v9 = 0LL;
do
{
*(_WORD *)(a2 + 2LL * v8) = *(_WORD *)(*(_QWORD *)(a1 + 8) + v9);
v9 += 2LL;
--v8;
}
while ( v8 != -1 );
v10 = 2 * result;
v11 = 2 * result - 1;
do
{
*(_WORD *)(a3 + 2LL * (unsigned int)(v11 - result)) = *(_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * (unsigned int)result);
LODWORD(result) = result + 1;
}
while ( (_DWORD)result != v10 );
LODWORD(result) = v7;
v12 = v7 + v10;
do
{
*(_WORD *)(a4 + 2LL * (unsigned int)result) = *(_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * (unsigned int)(v12 - result));
result = (unsigned int)(result - 1);
}
while ( (_DWORD)result != -1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v7; // er11
unsigned int v8; // edx
__int64 v9; // rcx
int v10; // edx
int v11; // er9
int v12; // edx

result = *(unsigned int *)(a1 + 4);
if ( (_DWORD)result )
{
v7 = result - 1;
v8 = result - 1;
v9 = 0LL;
do
{
*(_WORD *)(a2 + 2LL * v8) = *(_WORD *)(*(_QWORD *)(a1 + 8) + v9);
v9 += 2LL;
--v8;
}
while ( v8 != -1 );
v10 = 2 * result;
v11 = 2 * result - 1;
do
{
*(_WORD *)(a3 + 2LL * (unsigned int)(v11 - result)) = *(_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * (unsigned int)result);
LODWORD(result) = result + 1;
}
while ( (_DWORD)result != v10 );
LODWORD(result) = v7;
v12 = v7 + v10;
do
{
*(_WORD *)(a4 + 2LL * (unsigned int)result) = *(_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * (unsigned int)(v12 - result));
result = (unsigned int)(result - 1);
}
while ( (_DWORD)result != -1 );
}
return result;
}

original_code:
void copy_inverted_ramps(const randr_crtc_state_t *crtc_status,
       uint16_t *r, uint16_t *g, uint16_t *b){
 unsigned int ramp_size = crtc_status->ramp_size;
 unsigned i;
 for(i = 0; i < ramp_size; i++){
  r[ramp_size - 1 - i] = crtc_status->saved_ramps[i + 0 * ramp_size];
 }
 for(i = 0; i < ramp_size; i++){
  g[ramp_size - 1 - i] = crtc_status->saved_ramps[i + 1 * ramp_size];
 }
 for(i = 0; i < ramp_size; i++){
  b[ramp_size - 1 - i] = crtc_status->saved_ramps[i + 2 * ramp_size];
 }
}

canonical_original_code:
void copy_inverted_ramps(struct randr_crtc_state_t *crtc_status, unsigned short *r, unsigned short *g, unsigned short *b){
 unsigned int ramp_size = crtc_status->ramp_size;
 unsigned int i;
 for(i = 0; i < ramp_size; i++){
  r[ramp_size - 1 - i] = crtc_status->saved_ramps[i + 0 * ramp_size];
 }
 for(i = 0; i < ramp_size; i++){
  g[ramp_size - 1 - i] = crtc_status->saved_ramps[i + 1 * ramp_size];
 }
 for(i = 0; i < ramp_size; i++){
  b[ramp_size - 1 - i] = crtc_status->saved_ramps[i + 2 * ramp_size];
 }
}

variable_types: struct randr_crtc_state_t { unsigned int crtc; unsigned int ramp_size; unsigned short *saved_ramps; } *

variable_types:
r
unsigned short *

variable_types:
g
unsigned short *

variable_types:
b
unsigned short *

variable_types:
i
unsigned int


clientsock

decompiled_code:
__int64 __fastcall clientsock(char **a1)
{
struct hostent *v1; // rbp
int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-158h] BYREF
char buf[328]; // [rsp+10h] [rbp-148h] BYREF

v1 = gethostbyname("soft.vub.ac.be");
v2 = socket(2, 1, 0);
v4.sa_family = 2;
*(_WORD *)v4.sa_data = _bswap_16(110);
*(_DWORD *)&v4.sa_data[2] = **(_DWORD **)v1->h_addr_list;
*(_QWORD *)&v4.sa_data[6] = 0LL;
connect(v2, &v4, 0x10u);
recv(v2, buf, 0x12BuLL, 0);
send(v2, "USER joe\r\n", 0xFuLL, 0);
recv(v2, buf, 0x12BuLL, 0);
send(v2, "PASS joepass\r\n", 0xFuLL, 0);
recv(v2, buf, 0x12BuLL, 0);
LODWORD(v1) = send(v2, "QUIT\r\n", 6uLL, 0);
strcpy(*a1, buf);
buf[(int)v1] = 0;
close(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char **a1)
{
struct hostent *v1; // rbp
int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-158h] BYREF
char buf[328]; // [rsp+10h] [rbp-148h] BYREF

v1 = gethostbyname("soft.vub.ac.be");
v2 = socket(2, 1, 0);
v4.sa_family = 2;
*(_WORD *)v4.sa_data = func0(110);
*(_DWORD *)&v4.sa_data[2] = **(_DWORD **)v1->h_addr_list;
*(_QWORD *)&v4.sa_data[6] = 0LL;
connect(v2, &v4, 0x10u);
recv(v2, buf, 0x12BuLL, 0);
send(v2, "USER joe\r\n", 0xFuLL, 0);
recv(v2, buf, 0x12BuLL, 0);
send(v2, "PASS joepass\r\n", 0xFuLL, 0);
recv(v2, buf, 0x12BuLL, 0);
LODWORD(v1) = send(v2, "QUIT\r\n", 6uLL, 0);
strcpy(*a1, buf);
buf[(int)v1] = 0;
close(v2);
return 0LL;
}

original_code:
int clientsock(char **buffybuf)
    {
    char *hostname = "soft.vub.ac.be";
    char *user = "USER joe\r\n";
    char *password = "PASS joepass\r\n";
    int sockfd, numbytes;
    char buf[300];
    struct hostent *he;
    struct sockaddr_in their_addr;
    he=gethostbyname(hostname);
    sockfd = socket(2, SOCK_STREAM, 0);
    their_addr.sin_family = 2;
    their_addr.sin_port = htons(110);
    their_addr.sin_addr = *((struct in_addr *)he->h_addr_list[0]);
    memset(&(their_addr.sin_zero), '\0', 8);
    connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr));
    numbytes = recv(sockfd, buf, 300 -1, 0);
    memset(buf, 300, 0);
    numbytes = send(sockfd, user, 15,0);
    numbytes = recv(sockfd, buf, 300 -1, 0);
    memset(buf, 300, 0);
    numbytes = send(sockfd, password, 15,0);
    numbytes = recv(sockfd, buf, 300 -1, 0);
    numbytes = send(sockfd, "QUIT\r\n", 6,0);
    sprintf(*buffybuf, "%s", buf);
    buf[numbytes] = '\0';
    close(sockfd);
    return 0;
}

canonical_original_code:
int clientsock(char **buffybuf)
    {
    char *hostname = "soft.vub.ac.be";
    char *user = "USER joe\r\n";
    char *password = "PASS joepass\r\n";
    int sockfd; int numbytes;
    char buf[300];
    struct hostent *he;
    struct sockaddr_in their_addr;
    he=gethostbyname(hostname);
    sockfd = socket(2, SOCK_STREAM, 0);
    their_addr.sin_family = 2;
    their_addr.sin_port = htons(110);
    their_addr.sin_addr = *((struct in_addr *)he->h_addr_list[0]);
    memset(&(their_addr.sin_zero), '\0', 8);
    connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr));
    numbytes = recv(sockfd, buf, 300 -1, 0);
    memset(buf, 300, 0);
    numbytes = send(sockfd, user, 15,0);
    numbytes = recv(sockfd, buf, 300 -1, 0);
    memset(buf, 300, 0);
    numbytes = send(sockfd, password, 15,0);
    numbytes = recv(sockfd, buf, 300 -1, 0);
    numbytes = send(sockfd, "QUIT\r\n", 6,0);
    sprintf(*buffybuf, "%s", buf);
    buf[numbytes] = '\0';
    close(sockfd);
    return 0;
}

variable_types:
buffybuf
char **

variable_types:
hostname
char *

variable_types:
user
char *

variable_types:
password
char *

variable_types: sockfd int

variable_types: numbytes int

variable_types:
buf
char [300]

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


repo: zouf/dynfixed

decompiled_code:
void dfp_initialize()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
int dfp_initialize( const char * name)
{
}

canonical_original_code:
int dfp_initialize(char *name)
{
}

variable_types:
name
char *


decompiled_code:
void dfp_finalize()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
int dfp_finalize()
{
}

canonical_original_code:
int dfp_finalize()
{
}


getPrecision

decompiled_code:
__int64 getPrecision()
{
return PRECISION;
}

canonical_decompiled_code:
__int64 func8()
{
return PRECISION;
}

original_code:
int getPrecision(int precision)
{
  return PRECISION;
}

variable_types: precision int


dosub

decompiled_code:
__int64 __fastcall dosub(__int64 a1, int a2, int a3, int a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, __int64 a15, int a16, __int128 a17, __int128 a18, long double a19)
{
doadd(
a1,
a2,
a3,
a4,
a5,
a6,
a15,
a16,
a17,
-(__int64)a18,
DWORD2(*(unsigned __int128 *)&_mm_load_si128((const __m128i *)&a18)),
COERCE__INT128(-a19));
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, int a3, int a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, __int64 a15, int a16, __int128 a17, __int128 a18, long double a19)
{
func11(
a1,
a2,
a3,
a4,
a5,
a6,
a15,
a16,
a17,
-(__int64)a18,
DWORD2(*(unsigned __int128 *)&_mm_load_si128((const __m128i *)&a18)),
COERCE__INT128(-a19));
return a1;
}

original_code:
fixed_point_t dosub(fixed_point_t l, fixed_point_t r)
{
  fixed_point_t tmp = r;
  tmp.val = tmp.val * -1;
  tmp.orig = tmp.orig * -1;
  return doadd(l,tmp);
}

canonical_original_code:
struct fixed_point dosub(struct fixed_point l, struct fixed_point r)
{
  struct fixed_point tmp = r;
  tmp.val = tmp.val * -1;
  tmp.orig = tmp.orig * -1;
  return doadd(l,tmp);
}

variable_types:
l
struct fixed_point

variable_types:
r
struct fixed_point

variable_types: struct fixed_point { long val; int expLog; long double orig; }


dofloor

original_code:
fixed_point_t dofloor(fixed_point_t l)
{
  fixed_point_t x;
  x.val = l.val >> l.expLog;
  x.expLog = 0;
  x.orig = floor(l.orig);
  return x;
}

canonical_original_code:
struct fixed_point dofloor(struct fixed_point l)
{
  struct fixed_point x;
  x.val = l.val >> l.expLog;
  x.expLog = 0;
  x.orig = floor(l.orig);
  return x;
}

return_type: struct fixed_point { long val; int expLog; long double orig; }


decompiled_code:
long double __fastcall convert_out(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8)
{
long double v9; // [rsp+10h] [rbp-38h]

printf("exp log is %d\n", a8);
printf("printed as dec %Le\n", v9);
printf("printed as float %Lf\n", (long double)(1 << a8));
printf("val is %Ld\n", a7);
return (long double)a7 / (long double)(1 << a8);
}

canonical_decompiled_code:
long double __fastcall func15(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8)
{
long double v9; // [rsp+10h] [rbp-38h]

printf("exp log is %d\n", a8);
printf("printed as dec %Le\n", v9);
printf("printed as float %Lf\n", (long double)(1 << a8));
printf("val is %Ld\n", a7);
return (long double)a7 / (long double)(1 << a8);
}

original_code:
long double convert_out(fixed_point_t output)
{
  printf("exp log is %d\n", output.expLog);
  printf("printed as dec %Le\n", (__int128_t)(1 << output.expLog));
  printf("printed as float %Lf\n", (long double)(1 << output.expLog));
  printf("val is %Ld\n", (output.val));
  long double rval = (long double)(output.val / (long double)(1 << output.expLog));
  return rval;
}

canonical_original_code:
long double convert_out(struct fixed_point output)
{
  printf("exp log is %d\n", output.expLog);
  printf("printed as dec %Le\n", (__int128_t)(1 << output.expLog));
  printf("printed as float %Lf\n", (long double)(1 << output.expLog));
  printf("val is %Ld\n", (output.val));
  long double rval = (long double)(output.val / (long double)(1 << output.expLog));
  return rval;
}

variable_types:
rval
long double

return_type: long double

user_defined_types: struct fixed_point { long val; int expLog; long double orig; }


printfp

decompiled_code:
int __fastcall printfp(const char *a1, int a2, int a3, int a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, __int64 a15, __int64 a16, long double a17)
{
long double v9; // fst7

convert_out((_DWORD)a1, a2, a3, a4, a5, a6, a15, a16);
printf("FP print in %s = %ld explog is %d as fp %Lf\n", a1, a15, (unsigned int)a16, v9);
return printf("\t\t---orig is %Le\n", a17);
}

canonical_decompiled_code:
int __fastcall func16(const char *a1, int a2, int a3, int a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, __int64 a15, __int64 a16, long double a17)
{
long double v9; // fst7

func15((_DWORD)a1, a2, a3, a4, a5, a6, a15, a16);
printf("FP print in %s = %ld explog is %d as fp %Lf\n", a1, a15, (unsigned int)a16, v9);
return printf("\t\t---orig is %Le\n", a17);
}

original_code:
void printfp(fixed_point_t fp, const char * msg)
{
  printf("FP print  in %s =  %ld explog is %d as fp %Lf\n",
      msg, fp.val, fp.expLog, convert_out(fp) );
  printf("\t\t---orig is %Le\n",fp.orig);
}

canonical_original_code:
void printfp(struct fixed_point fp, char *msg)
{
  printf("FP print  in %s =  %ld explog is %d as fp %Lf\n",
      msg, fp.val, fp.expLog, convert_out(fp) );
  printf("\t\t---orig is %Le\n",fp.orig);
}

variable_types:
msg
char *


decompiled_code:
float __fastcall convert_out_float(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, char a8)
{
return (float)(int)a7 / (float)(1 << a8);
}

canonical_decompiled_code:
float __fastcall func17(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, char a8)
{
return (float)(int)a7 / (float)(1 << a8);
}

original_code:
float convert_out_float(fixed_point_t output)
{
  float rval = (float)(output.val / (float)(1 << output.expLog));
  return rval;
}

canonical_original_code:
float convert_out_float(struct fixed_point output)
{
  float rval = (float)(output.val / (float)(1 << output.expLog));
  return rval;
}

variable_types: rval float

return_type: float


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v4; // rbp
_QWORD *v5; // r12
bool v6; // zf
const char *v7; // rsi
_QWORD *v8; // r13
int result; // eax
_QWORD *v10; // r14
const char *i; // rbp
__int64 v12; // rdx
_QWORD *v13; // rbx
__int64 v14; // rax

if ( argc <= 2 )
{
fwrite("Usage: call pythonfile funcname [args]\n", 1uLL, 0x27uLL, stderr);
return 1;
}
Py_Initialize();
v4 = (_QWORD *)PyString_FromString();
v5 = (_QWORD *)PyImport_Import();
v6 = (*v4)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v4[1] + 48LL))(v4);
if ( !v5 )
{
PyErr_Print();
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
return 1;
}
v7 = argv[2];
v8 = (_QWORD *)PyObject_GetAttrString();
if ( !v8 )
{
if ( !PyErr_Occurred() )
{
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
goto LABEL_11;
}
LABEL_8:
PyErr_Print();
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
if ( v8 )
goto LABEL_9;
LABEL_11:
v6 = (*v5)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v5[1] + 48LL))(v5);
Py_Finalize();
return 0;
}
if ( !(unsigned int)PyCallable_Check() )
{
if ( !PyErr_Occurred() )
{
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
LABEL_9:
v6 = (*v8)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v8[1] + 48LL))(v8);
goto LABEL_11;
}
goto LABEL_8;
}
v10 = (_QWORD *)PyTuple_New();
if ( argc - 3 <= 0 )
{
LABEL_20:
v13 = (_QWORD *)PyObject_CallObject();
v6 = (*v10)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, _QWORD *))(v10[1] + 48LL))(v10, v10);
if ( v13 )
{
v14 = PyInt_AsLong();
printf("Result of call: %ld\n", v14);
v6 = (*v13)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v13[1] + 48LL))(v13);
goto LABEL_9;
}
v6 = (*v8)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, _QWORD *))(v8[1] + 48LL))(v8, v10);
v6 = (*v5)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, _QWORD *))(v5[1] + 48LL))(v5, v10);
PyErr_Print();
fwrite("Call failed\n", 1uLL, 0xCuLL, stderr);
result = 1;
}
else
{
for ( i = 0LL; ; ++i )
{
atoi(argv[(_QWORD)i + 3]);
v12 = PyInt_FromLong();
if ( !v12 )
break;
v7 = i;
PyTuple_SetItem();
if ( i == (const char *)(unsigned int)(argc - 4) )
goto LABEL_20;
}
v6 = (*v10)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, const char *, _QWORD))(v10[1] + 48LL))(v10, v7, 0LL);
v6 = (*v5)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, const char *, __int64))(v5[1] + 48LL))(v5, v7, v12);
fwrite("Cannot convert argument\n", 1uLL, 0x18uLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv)
{
  if( argc == 4 )
  {
    float a = atof(argv[2]);
    float b = atof(argv[3]);
    float resf;
    setPrecision(atoi(argv[1]));
    printf("vals %f %f\n", a, b);
    fixed_point_t fa = convert_in(a);
    fixed_point_t fb = convert_in(b);
    fixed_point_t res;
    printfp(fa, "first");
    printfp(fb, "second");
    res = doadd(fa, fb);
    resf = convert_out(res);
    printf("add ours %f orig %Lf\n", resf, res.orig);
    res = dosub(fa, fb);
    resf = convert_out(res);
    printf("sub ours %f orig %Lf\n", (resf), res.orig);
    res = domult(fa, fb);
    resf = convert_out(res);
    printf("mult ours %f orig %Lf\n", (resf), res.orig);
    res = dofloor(fa);
    resf = convert_out(res);
    printf("floor ours %f orig %Lf\n", (resf), res.orig);
    return 0;
  }
  float l=3.0;
  float r = 2.01;
  int PRECISION = 30;
  setPrecision(PRECISION);
  fixed_point_t lc = convert_in(l);
  fixed_point_t rc= convert_in(r);
  allowDynamic = 1;
  int i;
  fixed_point_t res = doadd(lc,rc);
  long double check = l+r;
  for(i = 0; i < 2; i++)
  {
    check = check*check;
    res = domult(res,res);
  }
  res = dosub(res,convert_in(10.0));
  check -=10.0;
  long double result = convert_out(res);
  printf("Final val is %Lf. Should be %Lf\n", result,check);
  printf("\n Checking very small numbers times whole numbers\n");
  fixed_point_t small = convert_in(1e-12);
  fixed_point_t one = convert_in(1);
  fixed_point_t res2 = domult(small, one);
  printfp( small, "small");
  printfp( one, "one");
  printfp( res2, "res2");
return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  if( argc == 4 )
  {
    float a = atof(argv[2]);
    float b = atof(argv[3]);
    float resf;
    setPrecision(atoi(argv[1]));
    printf("vals %f %f\n", a, b);
    struct fixed_point fa = convert_in(a);
    struct fixed_point fb = convert_in(b);
    struct fixed_point res;
    printfp(fa, "first");
    printfp(fb, "second");
    res = doadd(fa, fb);
    resf = convert_out(res);
    printf("add ours %f orig %Lf\n", resf, res.orig);
    res = dosub(fa, fb);
    resf = convert_out(res);
    printf("sub ours %f orig %Lf\n", (resf), res.orig);
    res = domult(fa, fb);
    resf = convert_out(res);
    printf("mult ours %f orig %Lf\n", (resf), res.orig);
    res = dofloor(fa);
    resf = convert_out(res);
    printf("floor ours %f orig %Lf\n", (resf), res.orig);
    return 0;
  }
  float l = 3.0;
  float r = 2.01;
  int PRECISION = 30;
  setPrecision(PRECISION);
  struct fixed_point lc = convert_in(l);
  struct fixed_point rc = convert_in(r);
  allowDynamic = 1;
  int i;
  struct fixed_point res = doadd(lc,rc);
  long double check = l+r;
  for(i = 0; i < 2; i++)
  {
    check = check*check;
    res = domult(res,res);
  }
  res = dosub(res,convert_in(10.0));
  check -=10.0;
  long double result = convert_out(res);
  printf("Final val is %Lf. Should be %Lf\n", result,check);
  printf("\n Checking very small numbers times whole numbers\n");
  struct fixed_point small = convert_in(1e-12);
  struct fixed_point one = convert_in(1);
  struct fixed_point res2 = domult(small, one);
  printfp( small, "small");
  printfp( one, "one");
  printfp( res2, "res2");
return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: a float

variable_types: b float

variable_types: resf float

variable_types: l float

variable_types: r float

variable_types: PRECISION int

variable_types: i int

variable_types:
check
long double

variable_types:
result
long double


repo: zpconn/Simple

decompiled_code:
__int64 __fastcall stack_pop(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // ebx

v1 = *a1;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
free(v1);
return v2;
}

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

v1 = *a1;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
free(v1);
return v2;
}

original_code:
int stack_pop(stack_struct_t ** top)
{
 stack_struct_t * temp;
 int pop_value;
 temp = *top;
 pop_value = (*top)->data;
 *top = (*top)->next;
 free(temp);
 return pop_value;
}

canonical_original_code:
int stack_pop(struct stack **top)
{
 struct stack *temp;
 int pop_value;
 temp = *top;
 pop_value = (*top)->data;
 *top = (*top)->next;
 free(temp);
 return pop_value;
}

variable_types: struct stack { int data; struct stack *next; } **


decompiled_code:
_BOOL8 __fastcall stack_empty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return a1 == 0;
}

original_code:
int stack_empty(stack_struct_t * top)
{
 return top == ((void *)0);
}

canonical_original_code:
int stack_empty(struct stack *top)
{
 return top == ((void *)0);
}

variable_types: struct stack { int data; struct stack *next; } *


dequeue

decompiled_code:
__int64 __fastcall dequeue(unsigned int **a1, _QWORD *a2)
{
unsigned int *v2; // rax
unsigned int v3; // ebx
unsigned int *v4; // rdx

v2 = *a1;
v3 = **a1;
v4 = (unsigned int *)*((_QWORD *)*a1 + 1);
*a1 = v4;
if ( !v4 )
*a2 = 0LL;
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int **a1, _QWORD *a2)
{
unsigned int *v2; // rax
unsigned int v3; // ebx
unsigned int *v4; // rdx

v2 = *a1;
v3 = **a1;
v4 = (unsigned int *)*((_QWORD *)*a1 + 1);
*a1 = v4;
if ( !v4 )
*a2 = 0LL;
free(v2);
return v3;
}

original_code:
int dequeue(queue_t ** head, queue_t ** tail)
{
 int value;
 queue_t * temp;
 value = (*head)->data;
 temp = *head;
 *head = (*head)->next;
 if (*head == ((void *)0))
 {
  *tail = ((void *)0);
 }
 free(temp);
 return value;
}

canonical_original_code:
int dequeue(struct queue **head, struct queue **tail)
{
 int value;
 struct queue *temp;
 value = (*head)->data;
 temp = *head;
 *head = (*head)->next;
 if (*head == ((void *)0))
 {
  *tail = ((void *)0);
 }
 free(temp);
 return value;
}

variable_types: struct queue { int data; enum QUEUE_DATA_TYPE { NUMBER=0, OPERATOR=1 } type; struct queue *next; } **

variable_types:
tail
struct queue **

variable_types: value int

user_defined_types: struct queue { int data; enum QUEUE_DATA_TYPE type; struct queue *next; }


decompiled_code:
_BOOL8 __fastcall queue_empty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return a1 == 0;
}

original_code:
int queue_empty(queue_t * head)
{
 return head == ((void *)0);
}

canonical_original_code:
int queue_empty(struct queue *head)
{
 return head == ((void *)0);
}

variable_types: struct queue { int data; enum QUEUE_DATA_TYPE { NUMBER=0, OPERATOR=1 } type; struct queue *next; } *


enqueue

decompiled_code:
__int64 __fastcall enqueue(__int64 *a1, __int64 *a2, int a3, int a4)
{
_DWORD *v6; // rax
__int64 v7; // rbx
__int64 result; // rax

v6 = malloc(0x10uLL);
if ( !v6 )
return simple_error(5LL, 0LL, "failed to allocate memory to enqueue a new node onto a queue");
v7 = (__int64)v6;
*v6 = a3;
v6[1] = a4;
*((_QWORD *)v6 + 1) = 0LL;
result = queue_empty(*a1);
if ( (_DWORD)result )
{
*a1 = v7;
}
else
{
result = *a2;
*(_QWORD *)(*a2 + 8) = v7;
}
*a2 = v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, __int64 *a2, int a3, int a4)
{
_DWORD *v6; // rax
__int64 v7; // rbx
__int64 result; // rax

v6 = malloc(0x10uLL);
if ( !v6 )
return simple_error(5LL, 0LL, "failed to allocate memory to enqueue a new node onto a queue");
v7 = (__int64)v6;
*v6 = a3;
v6[1] = a4;
*((_QWORD *)v6 + 1) = 0LL;
result = func3(*a1);
if ( (_DWORD)result )
{
*a1 = v7;
}
else
{
result = *a2;
*(_QWORD *)(*a2 + 8) = v7;
}
*a2 = v7;
return result;
}

original_code:
void enqueue(queue_t ** head, queue_t ** tail, int data, enum QUEUE_DATA_TYPE type)
{
 queue_t * new_node = malloc(sizeof(queue_t));
 if (new_node)
 {
  new_node->data = data;
  new_node->type = type;
  new_node->next = ((void *)0);
  if (queue_empty(*head))
  {
   *head = new_node;
  }
  else
  {
   (*tail)->next = new_node;
  }
  *tail = new_node;
 }
 else
 {
  simple_error(MYSTERY, ((void *)0), "failed to allocate memory to enqueue a new node onto a queue");
 }
}

canonical_original_code:
void enqueue(struct queue **head, struct queue **tail, int data, enum QUEUE_DATA_TYPE type)
{
 struct queue *new_node = malloc(sizeof(queue_t));
 if (new_node)
 {
  new_node->data = data;
  new_node->type = type;
  new_node->next = ((void *)0);
  if (queue_empty(*head))
  {
   *head = new_node;
  }
  else
  {
   (*tail)->next = new_node;
  }
  *tail = new_node;
 }
 else
 {
  simple_error(MYSTERY, ((void *)0), "failed to allocate memory to enqueue a new node onto a queue");
 }
}

variable_types: data int

variable_types: enum QUEUE_DATA_TYPE { NUMBER=0, OPERATOR=1 }


decompiled_code:
__int64 __fastcall is_number(char *a1)
{
char v1; // al

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

original_code:
int is_number(char * str)
{
 for (; *str != '\0'; ++str)
 {
  if (*str < '0' || *str > '9')
   return 0;
 }
 return 1;
}

canonical_original_code:
int is_number(char *str)
{
 for (; *str != '\0'; ++str)
 {
  if (*str < '0' || *str > '9')
   return 0;
 }
 return 1;
}

variable_types:
str
char *


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

if ( *a1 == 45 && strlen(a1) > 1 )
result = is_number(a1 + 1);
else
result = is_number(a1);
return result;
}

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

if ( *a1 == 45 && strlen(a1) > 1 )
result = func0(a1 + 1);
else
result = func0(a1);
return result;
}

original_code:
int is_integer(char * str)
{
 if (*str == '-' && strlen(str) > 1)
 {
  return is_number(str + 1);
 }
 else
 {
  return is_number(str);
 }
}

canonical_original_code:
int is_integer(char *str)
{
 if (*str == '-' && strlen(str) > 1)
 {
  return is_number(str + 1);
 }
 else
 {
  return is_number(str);
 }
}


decompiled_code:
__int64 __fastcall count_occurrences(_BYTE *a1, unsigned __int8 a2, __int64 a3)
{
_BYTE *v3; // rcx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
v3 = &a1[a3];
result = 0LL;
do
result += *a1++ == a2;
while ( v3 != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, unsigned __int8 a2, __int64 a3)
{
_BYTE *v3; // rcx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
v3 = &a1[a3];
result = 0LL;
do
result += *a1++ == a2;
while ( v3 != a1 );
return result;
}

original_code:
long count_occurrences(char * buffer, char target, long size)
{
 long count = 0;
 long i = 0;
 for (; i < size; ++i, ++buffer)
 {
  if (*buffer == target)
   ++count;
 }
 return count;
}

canonical_original_code:
long count_occurrences(char *buffer, char target, long size)
{
 long count = 0;
 long i = 0;
 for (; i < size; ++i, ++buffer)
 {
  if (*buffer == target)
   ++count;
 }
 return count;
}

variable_types:
buffer
char *

variable_types: target char

variable_types: size long

variable_types: count long

variable_types: i long

return_type: long


decompiled_code:
void __fastcall change_occurrences(_BYTE *a1, char a2, char a3, __int64 a4)
{
_BYTE *v4; // rcx

if ( a4 > 0 )
{
v4 = &a1[a4];
do
{
if ( *a1 == a2 )
*a1 = a3;
++a1;
}
while ( v4 != a1 );
}
}

original_code:
void change_occurrences(char * buffer, char start, char end, long size)
{
 long i = 0;
 for (; i < size; ++i, ++buffer)
 {
  if (*buffer == start)
   *buffer = end;
 }
}

canonical_original_code:
void change_occurrences(char *buffer, char start, char end, long size)
{
 long i = 0;
 for (; i < size; ++i, ++buffer)
 {
  if (*buffer == start)
   *buffer = end;
 }
}

variable_types: start char

variable_types: end char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__m128i v4; // [rsp+0h] [rbp-118h] BYREF
__int64 v5; // [rsp+10h] [rbp-108h]
char v6[208]; // [rsp+20h] [rbp-F8h] BYREF
__m128i v7; // [rsp+F0h] [rbp-28h] BYREF
__int64 v8; // [rsp+100h] [rbp-18h]

if ( argc == 2 )
{
simple_initialize_variable_map(v6, argv, envp);
simple_load_file(&v4, argv[1]);
v7 = _mm_loadu_si128(&v4);
v8 = v5;
simple_execute(&v7, v6);
result = 0;
}
else
{
puts("Please re-run the program and provide the name of the file to execute as a command-line argument.");
result = 1;
}
return result;
}

original_code:
int main(int argc, char * argv[])
{
 simple_file_t source;
 simple_variable_t variable_map[26];
 if (argc != 2)
 {
  printf("Please re-run the program and provide the name of the file to execute as a command-line argument.\n");
  return 1;
 }
 simple_initialize_variable_map(variable_map);
 source = simple_load_file(argv[1]);
 simple_execute(&source, variable_map);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct simple_file source;
 struct simple_variable variable_map[26];
 if (argc != 2)
 {
  printf("Please re-run the program and provide the name of the file to execute as a command-line argument.\n");
  return 1;
 }
 simple_initialize_variable_map(variable_map);
 source = simple_load_file(argv[1]);
 simple_execute(&source, variable_map);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct simple_file { struct simple_line { int number; enum SIMPLE_COMMAND { REM=0, INPUT=1, LET=2, PRINT=3, GOTO=4, IF=5, END=6, NO_MATCH=7 } command; char *rest; } **lines; long line_count; int next_line; }

variable_types: struct simple_variable { int initialized; int value; } [26]

user_defined_types: struct simple_file { struct simple_line **lines; long line_count; int next_line; }

user_defined_types: struct simple_line { int number; enum SIMPLE_COMMAND command; char *rest; }


decompiled_code:
void __fastcall simple_error(int a1, unsigned int *a2, const char *a3)
{
fwrite("--ERROR--\n", 1uLL, 0xAuLL, stderr);
fwrite("Type: ", 1uLL, 6uLL, stderr);
switch ( a1 )
{
case 0:
fwrite("syntax error.\n", 1uLL, 0xEuLL, stderr);
break;
case 1:
fwrite(
"invalid line numbering (line numbers should form an increasing sequence of positive integers).\n",
1uLL,
0x5FuLL,
stderr);
break;
case 2:
fwrite("unrecognized command.\n", 1uLL, 0x16uLL, stderr);
break;
case 3:
fwrite(
"invalid variable name (variable names must consist of precisely one lower-case letter).\n",
1uLL,
0x58uLL,
stderr);
break;
case 4:
fwrite("encountered an undeclared/uninitialized variable.\n", 1uLL, 0x32uLL, stderr);
break;
default:
fwrite("an error of mysterious and unidentifiable origin has occurred.\n", 1uLL, 0x3FuLL, stderr);
break;
}
if ( a2 )
fprintf(stderr, "Line number: %d\n", *a2);
if ( a3 )
fprintf(stderr, "Details: %s\n", a3);
exit(1);
}

canonical_decompiled_code:
void __fastcall func0(int a1, unsigned int *a2, const char *a3)
{
fwrite("--ERROR--\n", 1uLL, 0xAuLL, stderr);
fwrite("Type: ", 1uLL, 6uLL, stderr);
switch ( a1 )
{
case 0:
fwrite("syntax error.\n", 1uLL, 0xEuLL, stderr);
break;
case 1:
fwrite(
"invalid line numbering (line numbers should form an increasing sequence of positive integers).\n",
1uLL,
0x5FuLL,
stderr);
break;
case 2:
fwrite("unrecognized command.\n", 1uLL, 0x16uLL, stderr);
break;
case 3:
fwrite(
"invalid variable name (variable names must consist of precisely one lower-case letter).\n",
1uLL,
0x58uLL,
stderr);
break;
case 4:
fwrite("encountered an undeclared/uninitialized variable.\n", 1uLL, 0x32uLL, stderr);
break;
default:
fwrite("an error of mysterious and unidentifiable origin has occurred.\n", 1uLL, 0x3FuLL, stderr);
break;
}
if ( a2 )
fprintf(stderr, "Line number: %d\n", *a2);
if ( a3 )
fprintf(stderr, "Details: %s\n", a3);
exit(1);
}

original_code:
void simple_error(enum SIMPLE_ERROR type, simple_line_t * line, const char * details)
{
 fprintf(stderr, "--ERROR--\n");
 fprintf(stderr, "Type: ");
 switch(type)
 {
  case SYNTAX_ERROR:
   fprintf(stderr, "syntax error.\n");
   break;
  case INVALID_LINE_NUMBERING:
   fprintf(stderr, "invalid line numbering (line numbers should form an increasing sequence of positive integers).\n");
   break;
  case UNRECOGNIZED_COMMAND:
   fprintf(stderr, "unrecognized command.\n");
   break;
  case INVALID_VARIABLE_NAME:
   fprintf(stderr, "invalid variable name (variable names must consist of precisely one lower-case letter).\n");
   break;
  case UNDECLARED_VARIABLE:
   fprintf(stderr, "encountered an undeclared/uninitialized variable.\n");
   break;
  default:
  case MYSTERY:
   fprintf(stderr, "an error of mysterious and unidentifiable origin has occurred.\n");
   break;
 }
 if (line != ((void *)0))
 {
  fprintf(stderr, "Line number: %d\n", line->number);
 }
 if (details != ((void *)0))
 {
  fprintf(stderr, "Details: %s\n", details);
 }
 exit(1);
}

canonical_original_code:
void simple_error(enum SIMPLE_ERROR type, struct simple_line *line, char *details)
{
 fprintf(stderr, "--ERROR--\n");
 fprintf(stderr, "Type: ");
 switch(type)
 {
  case SYNTAX_ERROR:
   fprintf(stderr, "syntax error.\n");
   break;
  case INVALID_LINE_NUMBERING:
   fprintf(stderr, "invalid line numbering (line numbers should form an increasing sequence of positive integers).\n");
   break;
  case UNRECOGNIZED_COMMAND:
   fprintf(stderr, "unrecognized command.\n");
   break;
  case INVALID_VARIABLE_NAME:
   fprintf(stderr, "invalid variable name (variable names must consist of precisely one lower-case letter).\n");
   break;
  case UNDECLARED_VARIABLE:
   fprintf(stderr, "encountered an undeclared/uninitialized variable.\n");
   break;
  default:
  case MYSTERY:
   fprintf(stderr, "an error of mysterious and unidentifiable origin has occurred.\n");
   break;
 }
 if (line != ((void *)0))
 {
  fprintf(stderr, "Line number: %d\n", line->number);
 }
 if (details != ((void *)0))
 {
  fprintf(stderr, "Details: %s\n", details);
 }
 exit(1);
}

variable_types: enum SIMPLE_ERROR { SYNTAX_ERROR=0, INVALID_LINE_NUMBERING=1, UNRECOGNIZED_COMMAND=2, INVALID_VARIABLE_NAME=3, UNDECLARED_VARIABLE=4, MYSTERY=5 }

variable_types: struct simple_line { int number; enum SIMPLE_COMMAND { REM=0, INPUT=1, LET=2, PRINT=3, GOTO=4, IF=5, END=6, NO_MATCH=7 } command; char *rest; } *

variable_types:
details
char *


decompiled_code:
const __int32_t *__fastcall check_variable_name(const char *a1, __int64 a2)
{
char v2; // bp
const __int32_t *result; // rax

if ( strlen(a1) != 1 )
simple_error(3LL, a2, a1);
v2 = *a1;
if ( ((*_ctype_b_loc())[v2] & 0x400) == 0 )
simple_error(3LL, a2, a1);
result = *_ctype_tolower_loc();
if ( v2 != result[v2] )
result = (const __int32_t *)simple_error(3LL, a2, a1);
return result;
}

canonical_decompiled_code:
const __int32_t *__fastcall func0(const char *a1, __int64 a2)
{
char v2; // bp
const __int32_t *result; // rax

if ( strlen(a1) != 1 )
simple_error(3LL, a2, a1);
v2 = *a1;
if ( ((*_ctype_b_loc())[v2] & 0x400) == 0 )
simple_error(3LL, a2, a1);
result = *_ctype_tolower_loc();
if ( v2 != result[v2] )
result = (const __int32_t *)simple_error(3LL, a2, a1);
return result;
}

original_code:
void check_variable_name(char * name, simple_line_t * line)
{
 char c;
 if (strlen(name) != 1)
 {
  simple_error(INVALID_VARIABLE_NAME, line, name);
 }
 c = *name;
 if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha))
 {
  simple_error(INVALID_VARIABLE_NAME, line, name);
 }
 if (c != tolower(c))
 {
  simple_error(INVALID_VARIABLE_NAME, line, name);
 }
}

canonical_original_code:
void check_variable_name(char *name, struct simple_line *line)
{
 char c;
 if (strlen(name) != 1)
 {
  simple_error(INVALID_VARIABLE_NAME, line, name);
 }
 c = *name;
 if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha))
 {
  simple_error(INVALID_VARIABLE_NAME, line, name);
 }
 if (c != tolower(c))
 {
  simple_error(INVALID_VARIABLE_NAME, line, name);
 }
}

variable_types:
name
char *

variable_types: c char

user_defined_types: enum SIMPLE_COMMAND { REM=0, INPUT=1, LET=2, PRINT=3, GOTO=4, IF=5, END=6, NO_MATCH=7 }


decompiled_code:
_BOOL8 __fastcall check_variable_name_no_error(const char *a1)
{
size_t v1; // rdx
_BOOL8 result; // rax
char v3; // bl
const unsigned __int16 *v4; // rdx

v1 = strlen(a1);
result = 0LL;
if ( v1 == 1 )
{
v3 = *a1;
v4 = *_ctype_b_loc();
result = 0LL;
if ( (v4[v3] & 0x400) != 0 )
result = (*_ctype_tolower_loc())[v3] == v3;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
size_t v1; // rdx
_BOOL8 result; // rax
char v3; // bl
const unsigned __int16 *v4; // rdx

v1 = strlen(a1);
result = 0LL;
if ( v1 == 1 )
{
v3 = *a1;
v4 = *_ctype_b_loc();
result = 0LL;
if ( (v4[v3] & 0x400) != 0 )
result = (*_ctype_tolower_loc())[v3] == v3;
}
return result;
}

original_code:
int check_variable_name_no_error(char * name)
{
 char c;
 if (strlen(name) != 1)
 {
  return 0;
 }
 c = *name;
 if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) || c != tolower(c))
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int check_variable_name_no_error(char *name)
{
 char c;
 if (strlen(name) != 1)
 {
  return 0;
 }
 c = *name;
 if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) || c != tolower(c))
 {
  return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall simple_lookup_variable(__int64 a1, const char *a2, __int64 a3)
{
check_variable_name(a2, a3);
return *(unsigned int *)(a1 + 8LL * *a2 - 772);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int64 a3)
{
func0(a2, a3);
return *(unsigned int *)(a1 + 8LL * *a2 - 772);
}

original_code:
int simple_lookup_variable(simple_variable_t variable_map[26], char * name, simple_line_t * line)
{
 char c;
 check_variable_name(name, line);
 c = *name;
 return variable_map[c - 'a'].value;
}

canonical_original_code:
int simple_lookup_variable(struct simple_variable variable_map[26], char *name, struct simple_line *line)
{
 char c;
 check_variable_name(name, line);
 c = *name;
 return variable_map[c - 'a'].value;
}

user_defined_types: struct simple_variable { int initialized; int value; }


decompiled_code:
__int64 __fastcall find_line_index(__int64 *a1, int a2)
{
int v4; // ecx
__int64 v5; // r9
int v6; // esi
int v7; // eax
unsigned int v8; // er8
int v9; // edx

v4 = *((_DWORD *)a1 + 2) - 1;
if ( v4 < 0 )
return (unsigned int)-1;
v5 = *a1;
v6 = 0;
while ( 1 )
{
v7 = (v6 + v4) / 2;
v8 = v7;
v9 = **(_DWORD **)(v5 + 8LL * v7);
if ( v9 == a2 )
break;
if ( v9 <= a2 )
v6 = v7 + 1;
else
v4 = v7 - 1;
if ( v6 > v4 )
return (unsigned int)-1;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, int a2)
{
int v4; // ecx
__int64 v5; // r9
int v6; // esi
int v7; // eax
unsigned int v8; // er8
int v9; // edx

v4 = *((_DWORD *)a1 + 2) - 1;
if ( v4 < 0 )
return (unsigned int)-1;
v5 = *a1;
v6 = 0;
while ( 1 )
{
v7 = (v6 + v4) / 2;
v8 = v7;
v9 = **(_DWORD **)(v5 + 8LL * v7);
if ( v9 == a2 )
break;
if ( v9 <= a2 )
v6 = v7 + 1;
else
v4 = v7 - 1;
if ( v6 > v4 )
return (unsigned int)-1;
}
return v8;
}

original_code:
int find_line_index(simple_file_t * file, int line_number)
{
 int low = 0;
 int high = file->line_count - 1;
 int middle;
 int compare_result;
 while (low <= high)
 {
  middle = (low + high) / 2;
  compare_result = line_number < file->lines[middle]->number;
  if (line_number == file->lines[middle]->number)
   return middle;
  else if (line_number < file->lines[middle]->number)
   high = middle - 1;
  else
   low = middle + 1;
 }
 return -1;
}

canonical_original_code:
int find_line_index(struct simple_file *file, int line_number)
{
 int low = 0;
 int high = file->line_count - 1;
 int middle;
 int compare_result;
 while (low <= high)
 {
  middle = (low + high) / 2;
  compare_result = line_number < file->lines[middle]->number;
  if (line_number == file->lines[middle]->number)
   return middle;
  else if (line_number < file->lines[middle]->number)
   high = middle - 1;
  else
   low = middle + 1;
 }
 return -1;
}

variable_types: struct simple_file { struct simple_line { int number; enum SIMPLE_COMMAND { REM=0, INPUT=1, LET=2, PRINT=3, GOTO=4, IF=5, END=6, NO_MATCH=7 } command; char *rest; } **lines; long line_count; int next_line; } *

variable_types: low int

variable_types: high int

variable_types: middle int


decompiled_code:
__int64 __fastcall determine_conditional(const char *a1)
{
unsigned int v1; // edx

v1 = 0;
if ( strcmp(a1, "<") )
{
v1 = 1;
if ( strcmp(a1, "<=") )
{
v1 = 2;
if ( strcmp(a1, "==") )
{
v1 = 3;
if ( strcmp(a1, ">=") )
v1 = 4 - ((strcmp(a1, ">") == 0) - 1);
}
}
}
return v1;
}

original_code:
enum SIMPLE_CONDITIONAL determine_conditional(char * string)
{
 if (strcmp(string, "<") == 0)
  return LESS_THAN_STRICT;
 else if (strcmp(string, "<=") == 0)
  return LESS_THAN;
 else if (strcmp(string, "==") == 0)
  return EQUALS;
 else if (strcmp(string, ">=") == 0)
  return GREATER_THAN;
 else if (strcmp(string, ">") == 0)
  return GREATER_THAN_STRICT;
 else
  return INVALID_CONDITIONAL;
}

canonical_original_code:
enum SIMPLE_CONDITIONAL determine_conditional(char *string)
{
 if (strcmp(string, "<") == 0)
  return LESS_THAN_STRICT;
 else if (strcmp(string, "<=") == 0)
  return LESS_THAN;
 else if (strcmp(string, "==") == 0)
  return EQUALS;
 else if (strcmp(string, ">=") == 0)
  return GREATER_THAN;
 else if (strcmp(string, ">") == 0)
  return GREATER_THAN_STRICT;
 else
  return INVALID_CONDITIONAL;
}

variable_types:
string
char *

return_type: enum SIMPLE_CONDITIONAL { LESS_THAN_STRICT=0, LESS_THAN=1, EQUALS=2, GREATER_THAN=3, GREATER_THAN_STRICT=4, INVALID_CONDITIONAL=5 }


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

switch ( a4 )
{
case 0:
result = a2 < a3;
break;
case 1:
result = a2 <= a3;
break;
case 2:
result = a2 == a3;
break;
case 3:
result = a2 >= a3;
break;
case 4:
result = a2 > a3;
break;
default:
simple_error(5LL, a1, "somehow tried to evaluate an INVALID_CONDITIONAL comparison");
result = 0LL;
break;
}
return result;
}

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

switch ( a4 )
{
case 0:
result = a2 < a3;
break;
case 1:
result = a2 <= a3;
break;
case 2:
result = a2 == a3;
break;
case 3:
result = a2 >= a3;
break;
case 4:
result = a2 > a3;
break;
default:
simple_error(5LL, a1, "somehow tried to evaluate an INVALID_CONDITIONAL comparison");
result = 0LL;
break;
}
return result;
}

original_code:
int perform_comparison(simple_line_t * line, int a, int b, enum SIMPLE_CONDITIONAL conditional)
{
 switch (conditional)
 {
  case LESS_THAN_STRICT:
   return a < b;
  case LESS_THAN:
   return a <= b;
  case EQUALS:
   return a == b;
  case GREATER_THAN:
   return a >= b;
  case GREATER_THAN_STRICT:
   return a > b;
  default:
  case INVALID_CONDITIONAL:
   simple_error(MYSTERY, line, "somehow tried to evaluate an INVALID_CONDITIONAL comparison");
   return 0;
 }
}

canonical_original_code:
int perform_comparison(struct simple_line *line, int a, int b, enum SIMPLE_CONDITIONAL conditional)
{
 switch (conditional)
 {
  case LESS_THAN_STRICT:
   return a < b;
  case LESS_THAN:
   return a <= b;
  case EQUALS:
   return a == b;
  case GREATER_THAN:
   return a >= b;
  case GREATER_THAN_STRICT:
   return a > b;
  default:
  case INVALID_CONDITIONAL:
   simple_error(MYSTERY, line, "somehow tried to evaluate an INVALID_CONDITIONAL comparison");
   return 0;
 }
}

variable_types: a int

variable_types: b int

variable_types: enum SIMPLE_CONDITIONAL { LESS_THAN_STRICT=0, LESS_THAN=1, EQUALS=2, GREATER_THAN=3, GREATER_THAN_STRICT=4, INVALID_CONDITIONAL=5 }


decompiled_code:
__int64 __fastcall input_command(__int64 a1, __int64 a2)
{
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3[0] = 0;
check_variable_name(*(_QWORD *)(a1 + 8), a1);
printf("? ");
scanf("%d", v3);
return simple_assign_variable(a2, *(_QWORD *)(a1 + 8), v3[0], a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3[0] = 0;
check_variable_name(*(_QWORD *)(a1 + 8), a1);
printf("? ");
scanf("%d", v3);
return simple_assign_variable(a2, *(_QWORD *)(a1 + 8), v3[0], a1);
}

original_code:
void input_command(simple_line_t * line, simple_variable_t variable_map[26])
{
 int new_value = 0;
 check_variable_name(line->rest, line);
 printf("? ");
 scanf("%d", &new_value);
 simple_assign_variable(variable_map, line->rest, new_value, line);
}

canonical_original_code:
void input_command(struct simple_line *line, struct simple_variable variable_map[26])
{
 int new_value = 0;
 check_variable_name(line->rest, line);
 printf("? ");
 scanf("%d", &new_value);
 simple_assign_variable(variable_map, line->rest, new_value, line);
}


decompiled_code:
__int64 __fastcall conditional_command(__int64 a1, __int64 a2, __int64 a3)
{
const char *v6; // r13
size_t v7; // rax
char *v8; // rbp
char *v9; // rbp
__int64 v10; // rbp
char *v11; // rax
bool v12; // dl
char *v13; // r13
int v14; // er13
char *v15; // r15
bool v16; // cf
bool v17; // zf
int v18; // er14
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
__int64 result; // rax
int v23; // eax
int v24; // ebp
__int64 v25; // [rsp+8h] [rbp-70h]
char *nptr; // [rsp+10h] [rbp-68h]
const char *v27; // [rsp+18h] [rbp-60h]
char *v28; // [rsp+20h] [rbp-58h]
const char *v29; // [rsp+28h] [rbp-50h]
char *v30; // [rsp+30h] [rbp-48h]

v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
v6 = *(const char **)(a2 + 8);
v7 = strlen(v6);
v8 = (char *)malloc(v7 + 1);
strcpy(v8, v6);
v9 = strtok(v8, " ");
nptr = v9;
if ( !v9 )
goto LABEL_6;
v10 = 2LL;
do
{
v11 = strtok(0LL, " ");
*(&v25 + v10) = (__int64)v11;
v12 = (int)v10++ <= 4;
}
while ( v11 != 0LL && v12 );
v9 = v30;
if ( !v30 || strtok(0LL, " ") )
LABEL_6:
simple_error(0LL, a2, "the conditional statement isn't well-formed");
v13 = nptr;
if ( (unsigned int)check_variable_name_no_error(nptr) )
{
HIDWORD(v25) = simple_lookup_variable(a3, v13, a2);
}
else
{
if ( !(unsigned int)is_integer(v13) )
simple_error(0LL, a2, "the operands of the comparison should be variable names or integer literals");
HIDWORD(v25) = atoi(v13);
}
v14 = determine_conditional(v27);
if ( v14 == 5 )
simple_error(0LL, a2, "invalid or unrecognizable conditional provided; valid choices are <, <=, ==, >=, and >");
v15 = v28;
if ( (unsigned int)check_variable_name_no_error(v28) )
{
v18 = simple_lookup_variable(a3, v15, a2);
}
else
{
if ( !(unsigned int)is_integer(v15) )
simple_error(0LL, a2, "the operands of the comparison should be variable names or integer literals");
v18 = atoi(v15);
}
v19 = "goto";
v20 = 5LL;
v21 = v29;
do
{
if ( !v20 )
break;
v16 = *v21 < (unsigned int)*v19;
v17 = *v21++ == *v19++;
--v20;
}
while ( v17 );
if ( (!v16 && !v17) != v16 )
{
v21 = (const char *)a2;
simple_error(0LL, a2, "the conditional statement isn't well-formed; is there a typo in the 'goto' token?");
}
if ( !(unsigned int)is_number(v9, v21) )
simple_error(
0LL,
a2,
"the final token of the conditional should be a positive integer indicating the line number to jump to");
result = perform_comparison(a2, SHIDWORD(v25), v18, v14);
if ( (_DWORD)result )
{
v23 = atoi(v9);
result = find_line_index((__int64 *)a1, v23);
v24 = result;
if ( (int)result < 0 )
result = simple_error(0LL, a2, "no line with the provided number is present in the file");
*(_DWORD *)(a1 + 16) = v24;
}
else
{
++*(_DWORD *)(a1 + 16);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
const char *v6; // r13
size_t v7; // rax
char *v8; // rbp
char *v9; // rbp
__int64 v10; // rbp
char *v11; // rax
bool v12; // dl
char *v13; // r13
int v14; // er13
char *v15; // r15
bool v16; // cf
bool v17; // zf
int v18; // er14
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
__int64 result; // rax
int v23; // eax
int v24; // ebp
__int64 v25; // [rsp+8h] [rbp-70h]
char *nptr; // [rsp+10h] [rbp-68h]
const char *v27; // [rsp+18h] [rbp-60h]
char *v28; // [rsp+20h] [rbp-58h]
const char *v29; // [rsp+28h] [rbp-50h]
char *v30; // [rsp+30h] [rbp-48h]

v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
v6 = *(const char **)(a2 + 8);
v7 = strlen(v6);
v8 = (char *)malloc(v7 + 1);
strcpy(v8, v6);
v9 = strtok(v8, " ");
nptr = v9;
if ( !v9 )
goto LABEL_6;
v10 = 2LL;
do
{
v11 = strtok(0LL, " ");
*(&v25 + v10) = (__int64)v11;
v12 = (int)v10++ <= 4;
}
while ( v11 != 0LL && v12 );
v9 = v30;
if ( !v30 || strtok(0LL, " ") )
LABEL_6:
simple_error(0LL, a2, "the conditional statement isn't well-formed");
v13 = nptr;
if ( (unsigned int)check_variable_name_no_error(nptr) )
{
HIDWORD(v25) = simple_lookup_variable(a3, v13, a2);
}
else
{
if ( !(unsigned int)is_integer(v13) )
simple_error(0LL, a2, "the operands of the comparison should be variable names or integer literals");
HIDWORD(v25) = atoi(v13);
}
v14 = func1(v27);
if ( v14 == 5 )
simple_error(0LL, a2, "invalid or unrecognizable conditional provided; valid choices are <, <=, ==, >=, and >");
v15 = v28;
if ( (unsigned int)check_variable_name_no_error(v28) )
{
v18 = simple_lookup_variable(a3, v15, a2);
}
else
{
if ( !(unsigned int)is_integer(v15) )
simple_error(0LL, a2, "the operands of the comparison should be variable names or integer literals");
v18 = atoi(v15);
}
v19 = "goto";
v20 = 5LL;
v21 = v29;
do
{
if ( !v20 )
break;
v16 = *v21 < (unsigned int)*v19;
v17 = *v21++ == *v19++;
--v20;
}
while ( v17 );
if ( (!v16 && !v17) != v16 )
{
v21 = (const char *)a2;
simple_error(0LL, a2, "the conditional statement isn't well-formed; is there a typo in the 'goto' token?");
}
if ( !(unsigned int)is_number(v9, v21) )
simple_error(
0LL,
a2,
"the final token of the conditional should be a positive integer indicating the line number to jump to");
result = func2(a2, SHIDWORD(v25), v18, v14);
if ( (_DWORD)result )
{
v23 = atoi(v9);
result = func0((__int64 *)a1, v23);
v24 = result;
if ( (int)result < 0 )
result = simple_error(0LL, a2, "no line with the provided number is present in the file");
*(_DWORD *)(a1 + 16) = v24;
}
else
{
++*(_DWORD *)(a1 + 16);
}
return result;
}

original_code:
void conditional_command(simple_file_t * file, simple_line_t * line, simple_variable_t variable_map[26])
{
 int a, b;
 int i = 0;
 char * token = ((void *)0);
 char * tokens[5] = {((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
 enum SIMPLE_CONDITIONAL conditional = NO_MATCH;
 int comparison_value = 0;
 int goto_destination = -1;
 char * copy = malloc(strlen(line->rest) + 1);
 strcpy(copy, line->rest);
 token = strtok(copy, " ");
 tokens[0] = token;
 ++i;
 while (i < 5 && token != ((void *)0))
 {
  token = strtok(((void *)0), " ");
  tokens[i] = token;
  ++i;
 }
 if (tokens[4] == ((void *)0) || strtok(((void *)0), " ") != ((void *)0))
 {
  simple_error(SYNTAX_ERROR, line, "the conditional statement isn't well-formed");
 }
 if (check_variable_name_no_error(tokens[0]))
 {
  a = simple_lookup_variable(variable_map, tokens[0], line);
 }
 else
 {
  if (!is_integer(tokens[0]))
  {
   simple_error(SYNTAX_ERROR, line, "the operands of the comparison should be variable names or integer literals");
  }
  a = atoi(tokens[0]);
 }
 conditional = determine_conditional(tokens[1]);
 if (conditional == INVALID_CONDITIONAL)
 {
  simple_error(SYNTAX_ERROR, line, "invalid or unrecognizable conditional provided; valid choices are <, <=, ==, >=, and >");
 }
 if (check_variable_name_no_error(tokens[2]))
 {
  b = simple_lookup_variable(variable_map, tokens[2], line);
 }
 else
 {
  if (!is_integer(tokens[2]))
  {
   simple_error(SYNTAX_ERROR, line, "the operands of the comparison should be variable names or integer literals");
  }
  b = atoi(tokens[2]);
 }
 if (strcmp(tokens[3], "goto") != 0)
 {
  simple_error(SYNTAX_ERROR, line, "the conditional statement isn't well-formed; is there a typo in the 'goto' token?");
 }
 if (!is_number(tokens[4]))
 {
  simple_error(SYNTAX_ERROR, line, "the final token of the conditional should be a positive integer indicating the line number to jump to");
 }
 comparison_value = perform_comparison(line, a, b, conditional);
 if (comparison_value)
 {
  goto_destination = find_line_index(file, atoi(tokens[4]));
  if (goto_destination < 0)
  {
   simple_error(SYNTAX_ERROR, line, "no line with the provided number is present in the file");
  }
  file->next_line = goto_destination;
 }
 else
 {
  ++file->next_line;
 }
}

canonical_original_code:
void conditional_command(struct simple_file *file, struct simple_line *line, struct simple_variable variable_map[26])
{
 int a; int b;
 int i = 0;
 char *token = ((void *)0);
 char *tokens[5] = {((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
 enum SIMPLE_CONDITIONAL conditional = NO_MATCH;
 int comparison_value = 0;
 int goto_destination = -1;
 char *copy = malloc(strlen(line->rest) + 1);
 strcpy(copy, line->rest);
 token = strtok(copy, " ");
 tokens[0] = token;
 ++i;
 while (i < 5 && token != ((void *)0))
 {
  token = strtok(((void *)0), " ");
  tokens[i] = token;
  ++i;
 }
 if (tokens[4] == ((void *)0) || strtok(((void *)0), " ") != ((void *)0))
 {
  simple_error(SYNTAX_ERROR, line, "the conditional statement isn't well-formed");
 }
 if (check_variable_name_no_error(tokens[0]))
 {
  a = simple_lookup_variable(variable_map, tokens[0], line);
 }
 else
 {
  if (!is_integer(tokens[0]))
  {
   simple_error(SYNTAX_ERROR, line, "the operands of the comparison should be variable names or integer literals");
  }
  a = atoi(tokens[0]);
 }
 conditional = determine_conditional(tokens[1]);
 if (conditional == INVALID_CONDITIONAL)
 {
  simple_error(SYNTAX_ERROR, line, "invalid or unrecognizable conditional provided; valid choices are <, <=, ==, >=, and >");
 }
 if (check_variable_name_no_error(tokens[2]))
 {
  b = simple_lookup_variable(variable_map, tokens[2], line);
 }
 else
 {
  if (!is_integer(tokens[2]))
  {
   simple_error(SYNTAX_ERROR, line, "the operands of the comparison should be variable names or integer literals");
  }
  b = atoi(tokens[2]);
 }
 if (strcmp(tokens[3], "goto") != 0)
 {
  simple_error(SYNTAX_ERROR, line, "the conditional statement isn't well-formed; is there a typo in the 'goto' token?");
 }
 if (!is_number(tokens[4]))
 {
  simple_error(SYNTAX_ERROR, line, "the final token of the conditional should be a positive integer indicating the line number to jump to");
 }
 comparison_value = perform_comparison(line, a, b, conditional);
 if (comparison_value)
 {
  goto_destination = find_line_index(file, atoi(tokens[4]));
  if (goto_destination < 0)
  {
   simple_error(SYNTAX_ERROR, line, "no line with the provided number is present in the file");
  }
  file->next_line = goto_destination;
 }
 else
 {
  ++file->next_line;
 }
}

variable_types:
line
struct simple_line *

variable_types: i int

variable_types:
token
char *

variable_types:
tokens
char *[5]

variable_types:
copy
char *

user_defined_types: enum SIMPLE_CONDITIONAL { LESS_THAN_STRICT=0, LESS_THAN=1, EQUALS=2, GREATER_THAN=3, GREATER_THAN_STRICT=4, INVALID_CONDITIONAL=5 }


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

v2 = simple_lookup_variable(a2, *(_QWORD *)(a1 + 8), a1);
return printf("%s = %d\n", *(const char **)(a1 + 8), v2);
}

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

v2 = simple_lookup_variable(a2, *(_QWORD *)(a1 + 8), a1);
return printf("%s = %d\n", *(const char **)(a1 + 8), v2);
}

original_code:
void print_command(simple_line_t * line, simple_variable_t variable_map[26])
{
 printf("%s = %d\n", line->rest, simple_lookup_variable(variable_map, line->rest, line));
}

canonical_original_code:
void print_command(struct simple_line *line, struct simple_variable variable_map[26])
{
 printf("%s = %d\n", line->rest, simple_lookup_variable(variable_map, line->rest, line));
}

variable_types: struct simple_line { int number; enum SIMPLE_COMMAND { REM=0, INPUT=1, LET=2, PRINT=3, GOTO=4, IF=5, END=6, NO_MATCH=7 } command; char *rest; } *

variable_types: struct simple_variable { int initialized; int value; } [26]


decompiled_code:
__int64 __fastcall goto_command(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
int v4; // er12

if ( !(unsigned int)is_number(*(_QWORD *)(a2 + 8), a2) )
simple_error(0LL, a2, "the goto destination is not a positive integer");
v2 = atoi(*(const char **)(a2 + 8));
result = find_line_index((__int64 *)a1, v2);
v4 = result;
if ( (int)result < 0 )
result = simple_error(0LL, a2, "no line with the provided number is present in the file");
*(_DWORD *)(a1 + 16) = v4;
return result;
}

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

if ( !(unsigned int)is_number(*(_QWORD *)(a2 + 8), a2) )
simple_error(0LL, a2, "the goto destination is not a positive integer");
v2 = atoi(*(const char **)(a2 + 8));
result = func0((__int64 *)a1, v2);
v4 = result;
if ( (int)result < 0 )
result = simple_error(0LL, a2, "no line with the provided number is present in the file");
*(_DWORD *)(a1 + 16) = v4;
return result;
}

original_code:
void goto_command(simple_file_t * file, simple_line_t * line, simple_variable_t variable_map[26])
{
 int goto_destination = -1;
 if (!is_number(line->rest))
 {
  simple_error(SYNTAX_ERROR, line, "the goto destination is not a positive integer");
 }
 goto_destination = find_line_index(file, atoi(line->rest));
 if (goto_destination < 0)
 {
  simple_error(SYNTAX_ERROR, line, "no line with the provided number is present in the file");
 }
 file->next_line = goto_destination;
}

canonical_original_code:
void goto_command(struct simple_file *file, struct simple_line *line, struct simple_variable variable_map[26])
{
 int goto_destination = -1;
 if (!is_number(line->rest))
 {
  simple_error(SYNTAX_ERROR, line, "the goto destination is not a positive integer");
 }
 goto_destination = find_line_index(file, atoi(line->rest));
 if (goto_destination < 0)
 {
  simple_error(SYNTAX_ERROR, line, "no line with the provided number is present in the file");
 }
 file->next_line = goto_destination;
}


decompiled_code:
__int64 __fastcall let_command(__int64 a1, __int64 a2)
{
const char *v2; // r13
size_t v3; // rax
char *v4; // rbp
char *v5; // r13
const char *v6; // rbp
const char *v7; // rbp
unsigned int v8; // eax

v2 = *(const char **)(a1 + 8);
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 1);
strcpy(v4, v2);
v5 = strtok(v4, " ");
check_variable_name(v5, a1);
if ( strcmp(strtok(0LL, " "), "=") )
simple_error(0LL, a1, "invalid syntax for assignment statement; are you missing an = sign?");
v6 = &v4[strlen(v4) + 1];
v7 = &v6[strlen(v6) + 1];
if ( !strcmp(v7, "\n") || !*v7 )
simple_error(0LL, a1, "it appears you're missing an expression to assign to the provided variable");
v8 = exp_evaluate(a1, v7, a2);
return simple_assign_variable(a2, v5, v8, a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
const char *v2; // r13
size_t v3; // rax
char *v4; // rbp
char *v5; // r13
const char *v6; // rbp
const char *v7; // rbp
unsigned int v8; // eax

v2 = *(const char **)(a1 + 8);
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 1);
strcpy(v4, v2);
v5 = strtok(v4, " ");
check_variable_name(v5, a1);
if ( strcmp(strtok(0LL, " "), "=") )
simple_error(0LL, a1, "invalid syntax for assignment statement; are you missing an = sign?");
v6 = &v4[strlen(v4) + 1];
v7 = &v6[strlen(v6) + 1];
if ( !strcmp(v7, "\n") || !*v7 )
simple_error(0LL, a1, "it appears you're missing an expression to assign to the provided variable");
v8 = exp_evaluate(a1, v7, a2);
return simple_assign_variable(a2, v5, v8, a1);
}

original_code:
void let_command(simple_line_t * line, simple_variable_t variable_map[26])
{
 char * tokens[3] = {((void *)0), ((void *)0), ((void *)0)};
 int result = 0;
 char * str = malloc(strlen(line->rest) + 1);
 strcpy(str, line->rest);
 tokens[0] = strtok(str, " ");
 check_variable_name(tokens[0], line);
 tokens[1] = strtok(((void *)0), " ");
 if (strcmp(tokens[1], "=") != 0)
 {
  simple_error(SYNTAX_ERROR, line, "invalid syntax for assignment statement; are you missing an = sign?");
 }
 tokens[2] = strchr(strchr(str, 0) + 1, 0) + 1;
 if (tokens[2] == ((void *)0) || strcmp(tokens[2], "\n") == 0 || strcmp(tokens[2], "\0") == 0)
 {
  simple_error(SYNTAX_ERROR, line, "it appears you're missing an expression to assign to the provided variable");
 }
 result = exp_evaluate(line, tokens[2], variable_map);
 simple_assign_variable(variable_map, tokens[0], result, line);
}

canonical_original_code:
void let_command(struct simple_line *line, struct simple_variable variable_map[26])
{
 char *tokens[3] = {((void *)0), ((void *)0), ((void *)0)};
 int result = 0;
 char *str = malloc(strlen(line->rest) + 1);
 strcpy(str, line->rest);
 tokens[0] = strtok(str, " ");
 check_variable_name(tokens[0], line);
 tokens[1] = strtok(((void *)0), " ");
 if (strcmp(tokens[1], "=") != 0)
 {
  simple_error(SYNTAX_ERROR, line, "invalid syntax for assignment statement; are you missing an = sign?");
 }
 tokens[2] = strchr(strchr(str, 0) + 1, 0) + 1;
 if (tokens[2] == ((void *)0) || strcmp(tokens[2], "\n") == 0 || strcmp(tokens[2], "\0") == 0)
 {
  simple_error(SYNTAX_ERROR, line, "it appears you're missing an expression to assign to the provided variable");
 }
 result = exp_evaluate(line, tokens[2], variable_map);
 simple_assign_variable(variable_map, tokens[0], result, line);
}

variable_types:
tokens
char *[3]

variable_types: result int

variable_types:
str
char *


original_code:
enum SIMPLE_OPERATOR token_determine_op(char * token)
{
 if (strcmp(token, "(") == 0)
 {
  return LEFT_PARENTHESIS;
 }
 else if (strcmp(token, ")") == 0)
 {
  return RIGHT_PARENTHESIS;
 }
 else if (strcmp(token, "+") == 0)
 {
  return PLUS;
 }
 else if (strcmp(token, "-") == 0)
 {
  return MINUS;
 }
 else if (strcmp(token, "*") == 0)
 {
  return TIMES;
 }
 else if (strcmp(token, "/") == 0)
 {
  return DIVIDE;
 }
 else if (strcmp(token, "%") == 0)
 {
  return MODULUS;
 }
 else
 {
  return OP_NO_MATCH;
 }
}

canonical_original_code:
enum SIMPLE_OPERATOR token_determine_op(char *token)
{
 if (strcmp(token, "(") == 0)
 {
  return LEFT_PARENTHESIS;
 }
 else if (strcmp(token, ")") == 0)
 {
  return RIGHT_PARENTHESIS;
 }
 else if (strcmp(token, "+") == 0)
 {
  return PLUS;
 }
 else if (strcmp(token, "-") == 0)
 {
  return MINUS;
 }
 else if (strcmp(token, "*") == 0)
 {
  return TIMES;
 }
 else if (strcmp(token, "/") == 0)
 {
  return DIVIDE;
 }
 else if (strcmp(token, "%") == 0)
 {
  return MODULUS;
 }
 else
 {
  return OP_NO_MATCH;
 }
}

return_type: enum SIMPLE_OPERATOR { LEFT_PARENTHESIS=0, RIGHT_PARENTHESIS=1, PLUS=2, MINUS=3, TIMES=4, DIVIDE=5, MODULUS=6, OP_NO_MATCH=7 }