printRosters

original_code:
static void printRosters( const league_s *leagues )
{
     int pitchingHeader = 0;
     int hittingHeader = 0;
     int leag;
     int div;
     int team;
     int plyr;
     for ( leag = 0; leag < 2; ++leag )
     {
   printf( "%s League\n", leagues[leag].name );
   printf( "\n" );
   for ( div = 0; div < 2; ++div )
   {
        printf( "%s\n", leagues[leag].divisions[div].name );
        printf( "\n" );
        for ( team = 0; team < 8; ++team )
        {
      printf( "%s  %3d - %3d\n",
       leagues[leag].divisions[div].teams[team].name,
       leagues[leag].divisions[div].teams[team].wins,
       leagues[leag].divisions[div].teams[team].losses );
      printf( "\n" );
      pitchingHeader = 0;
      hittingHeader = 0;
      for ( plyr = 0; plyr < 25; ++plyr )
      {
    const player_s *pl = &leagues[leag].divisions[div].teams[team].players[plyr];
    if ( pl->type == pt_Pitcher && pitchingHeader == 0 )
    {
         printPitchingHeader();
         pitchingHeader = 1;
    }
    if ( pl->type == pt_Hitter && hittingHeader == 0 )
    {
         printf( "\n" );
         printHittingHeader();
         hittingHeader = 1;
    }
    printPlayer( pl );
      }
      printf( "\n" );
        }
   }
     }
}

canonical_original_code:
static void printRosters(struct league_s *leagues)
{
     int pitchingHeader = 0;
     int hittingHeader = 0;
     int leag;
     int div;
     int team;
     int plyr;
     for ( leag = 0; leag < 2; ++leag )
     {
   printf( "%s League\n", leagues[leag].name );
   printf( "\n" );
   for ( div = 0; div < 2; ++div )
   {
        printf( "%s\n", leagues[leag].divisions[div].name );
        printf( "\n" );
        for ( team = 0; team < 8; ++team )
        {
      printf( "%s  %3d - %3d\n",
       leagues[leag].divisions[div].teams[team].name,
       leagues[leag].divisions[div].teams[team].wins,
       leagues[leag].divisions[div].teams[team].losses );
      printf( "\n" );
      pitchingHeader = 0;
      hittingHeader = 0;
      for ( plyr = 0; plyr < 25; ++plyr )
      {
    struct player_s *pl = &leagues[leag].divisions[div].teams[team].players[plyr];
    if ( pl->type == pt_Pitcher && pitchingHeader == 0 )
    {
         printPitchingHeader();
         pitchingHeader = 1;
    }
    if ( pl->type == pt_Hitter && hittingHeader == 0 )
    {
         printf( "\n" );
         printHittingHeader();
         hittingHeader = 1;
    }
    printPlayer( pl );
      }
      printf( "\n" );
        }
   }
     }
}

variable_types: pitchingHeader int

variable_types: hittingHeader int

user_defined_types: struct league_s { char name[-1]; struct division_s divisions[2]; }

user_defined_types: enum playertype_e { pt_Pitcher=0, pt_Hitter=1, pt_None=2 }

user_defined_types: struct division_s { char name[-1]; struct team_s teams[8]; }

user_defined_types: enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 }

user_defined_types: struct pitching_s { int wins; int losses; int games; int games_started; int games_completed; int saves; float innings; int at_bats; int hits; int earned_runs; int home_runs; int walks; int strike_outs; }

user_defined_types: struct hitting_s { int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int rbi; int walks; int strike_outs; int stolen_bases; int errors; }

user_defined_types: struct fielding_s { int put_outs; int assists; int errors; float secondary_avg; }

user_defined_types: struct team_s { char name[-1]; int wins; int losses; enum color_e color; struct player_s players[25]; }

user_defined_types: enum color_e { cl_LtBlue=0, cl_Blue=1, cl_DkRed=2, cl_Red=3, cl_Gold=4, cl_Black=5, cl_Brown=6, cl_Green=7 }


genCmd

decompiled_code:
int genCmd()
{
const char *v0; // rcx
char **i; // rbx
const char *v3; // rcx
char **v4; // rbx

if ( lang )
{
if ( lang == 1 )
{
v0 = CMD_CXX[0];
for ( i = off_4040A8; v0; v0 = *(i - 1) )
{
++i;
sprintf(compile_command, "%s %s", compile_command, v0);
}
}
}
else
{
v3 = CMD_C[0];
if ( CMD_C[0] )
{
v4 = off_4040E8;
do
{
++v4;
sprintf(compile_command, "%s %s", compile_command, v3);
v3 = *(v4 - 1);
}
while ( v3 );
}
}
return sprintf(compile_command, "%s %s %s", compile_command, binary, source);
}

canonical_decompiled_code:
int func8()
{
const char *v0; // rcx
char **i; // rbx
const char *v3; // rcx
char **v4; // rbx

if ( lang )
{
if ( lang == 1 )
{
v0 = CMD_CXX[0];
for ( i = off_4040A8; v0; v0 = *(i - 1) )
{
++i;
sprintf(compile_command, "%s %s", compile_command, v0);
}
}
}
else
{
v3 = CMD_C[0];
if ( CMD_C[0] )
{
v4 = off_4040E8;
do
{
++v4;
sprintf(compile_command, "%s %s", compile_command, v3);
v3 = *(v4 - 1);
}
while ( v3 );
}
}
return sprintf(compile_command, "%s %s %s", compile_command, binary, source);
}

original_code:
void genCmd() {
    int i;
    switch(lang) {
    case(LANG_C):
        for(i = 0; CMD_C[i] != ((void *)0); i++)
            sprintf(compile_command, "%s %s", compile_command, CMD_C[i]);
        break;
    case(LANG_CXX):
        for(i = 0; CMD_CXX[i] != ((void *)0); i++)
            sprintf(compile_command, "%s %s", compile_command, CMD_CXX[i]);
        break;
    }
    sprintf(compile_command, "%s %s %s", compile_command, binary, source);
}

variable_types: i int

return_type: void


doCompile

decompiled_code:
int doCompile()
{
return execl("/bin/sh", "sh", "-c", compile_command, 0LL);
}

canonical_decompiled_code:
int func9()
{
return execl("/bin/sh", "sh", "-c", compile_command, 0LL);
}

original_code:
void doCompile() {
    execl("/bin/sh", "sh", "-c", compile_command, ((void *)0));
}


compile

decompiled_code:
int compile()
{
int v0; // eax
unsigned int v1; // esi
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v0 = fork();
cpid = v0;
if ( v0 < 0 )
{
perror("Compile Fork Error");
exit(1);
}
if ( v0 )
{
stat_loc = 0;
waitpid(v0, &stat_loc, 0);
v1 = 0;
if ( (stat_loc & 0x7F) != 0 || !BYTE1(stat_loc) )
{
if ( access(binary, 0) != -1 )
result(0, 0);
v1 = 2;
}
result(1u, v1);
}
return doCompile();
}

canonical_decompiled_code:
int func10()
{
int v0; // eax
unsigned int v1; // esi
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v0 = fork();
cpid = v0;
if ( v0 < 0 )
{
perror("Compile Fork Error");
exit(1);
}
if ( v0 )
{
stat_loc = 0;
waitpid(v0, &stat_loc, 0);
v1 = 0;
if ( (stat_loc & 0x7F) != 0 || !BYTE1(stat_loc) )
{
if ( access(binary, 0) != -1 )
func7(0, 0);
v1 = 2;
}
func7(1u, v1);
}
return func9();
}

original_code:
void compile() {
    cpid = fork();
    if(cpid < 0) {
        perror("Compile Fork Error");
        exit(1);
    } else if(cpid == 0) {
        doCompile();
    } else {
        int status = 0;
        waitpid(cpid, &status, 0);
        if((((status) & 0x7f) == 0) && (((status) & 0xff00) >> 8)) {
            result(CP_CE, CE_SIG);
        }
        if(access(binary, 0) == -1) {
            result(CP_CE, CE_NOBIN);
        }
        result(CP_NML);
    }
}

variable_types: status int


srcExist

decompiled_code:
int srcExist()
{
int result; // eax

result = access(source, 0);
if ( result == -1 )
::result(1u, 1u);
return result;
}

canonical_decompiled_code:
int func11()
{
int result; // eax

result = access(source, 0);
if ( result == -1 )
::func7(1u, 1u);
return result;
}

original_code:
void srcExist() {
    if(access(source, 0) == -1) {
        result(CP_CE, CE_NOSRC);
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9
int result; // eax

if ( argc <= 3 )
{
puts("ERROR: Not enough arguments\nFormat: compiler [source] [binary] [lang]");
result = 1;
}
else
{
strcpy(source, argv[1]);
strcpy(binary, argv[2]);
lang = atoi(argv[3]);
if ( lang > 1 )
::result(1, 3, v3, v4, v5, v6);
srcExist();
binExist();
genCmd();
compile();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9
int result; // eax

if ( argc <= 3 )
{
puts("ERROR: Not enough arguments\nFormat: compiler [source] [binary] [lang]");
result = 1;
}
else
{
strcpy(source, argv[1]);
strcpy(binary, argv[2]);
lang = atoi(argv[3]);
if ( lang > 1 )
::func7(1, 3, v3, v4, v5, v6);
func11();
func12();
func8();
func10();
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
    if(argc < 4) {
        printf("ERROR: Not enough arguments\n" "Format: compiler [source] [binary] [lang]\n");
        return 1;
    } else {
        strcpy(source, argv[1]);
        strcpy(binary, argv[2]);
        lang = atoi(argv[3]);
        if(lang > 1)
            result(CP_CE, CE_NOLANG);
    }
    srcExist();
    binExist();
    genCmd();
    compile();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


result

decompiled_code:
void __fastcall __noreturn result(unsigned int a1, unsigned int a2)
{
if ( a1 )
{
if ( a2 )
{
switch ( a2 )
{
case 1u:
perror("Source Not Exist\n");
break;
case 2u:
perror("Binary Not Exist\n");
break;
case 3u:
perror("No Such LANG\n");
break;
default:
perror("Unexpected Error\n");
break;
}
}
else
{
perror("Compile Error\n");
}
}
else
{
perror("Compiled\n");
}
printf("%d %d\n", a1, a2);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(unsigned int a1, unsigned int a2)
{
if ( a1 )
{
if ( a2 )
{
switch ( a2 )
{
case 1u:
perror("Source Not Exist\n");
break;
case 2u:
perror("Binary Not Exist\n");
break;
case 3u:
perror("No Such LANG\n");
break;
default:
perror("Unexpected Error\n");
break;
}
}
else
{
perror("Compile Error\n");
}
}
else
{
perror("Compiled\n");
}
printf("%d %d\n", a1, a2);
exit(0);
}

original_code:
void result(int rs, ...) {
    va_list tmp;
    int arg;
    __builtin_va_start(tmp,rs);
    arg = __builtin_va_arg(tmp,int);
    __builtin_va_end(tmp);
    if(rs == CP_NML) {
        perror("Compiled\n");
    } else {
        if(arg == CE_SIG) {
            perror("Compile Error\n");
        } else if(arg == CE_NOSRC) {
            perror("Source Not Exist\n");
        } else if(arg == CE_NOBIN) {
            perror("Binary Not Exist\n");
        } else if(arg == CE_NOLANG) {
            perror("No Such LANG\n");
        } else {
            perror("Unexpected Error\n");
        }
    }
    printf("%d %d\n", rs, arg);
    exit(0);
}

canonical_original_code:
void result(int rs, ...) {
    __builtin_va_list tmp;
    int arg;
    __builtin_va_start(tmp,rs);
    arg = __builtin_va_arg(tmp,int);
    __builtin_va_end(tmp);
    if(rs == CP_NML) {
        perror("Compiled\n");
    } else {
        if(arg == CE_SIG) {
            perror("Compile Error\n");
        } else if(arg == CE_NOSRC) {
            perror("Source Not Exist\n");
        } else if(arg == CE_NOBIN) {
            perror("Binary Not Exist\n");
        } else if(arg == CE_NOLANG) {
            perror("No Such LANG\n");
        } else {
            perror("Unexpected Error\n");
        }
    }
    printf("%d %d\n", rs, arg);
    exit(0);
}

variable_types: rs int

variable_types: arg int


binExist

decompiled_code:
int binExist()
{
int result; // eax

result = access(binary, 0);
if ( !result )
result = remove(binary);
return result;
}

canonical_decompiled_code:
int func12()
{
int result; // eax

result = access(binary, 0);
if ( !result )
result = remove(binary);
return result;
}

original_code:
void binExist() {
    if(access(binary, 0) == 0) {
        remove(binary);
    }
}


limit

decompiled_code:
int limit()
{
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = time_limit;
v1.rlim_max = time_limit + 2LL;
setrlimit(RLIMIT_CPU, &v1);
v1.rlim_max = mem_limit;
v1.rlim_cur = mem_limit;
setrlimit(RLIMIT_AS, &v1);
v1.rlim_max = file_limit;
v1.rlim_cur = file_limit;
return setrlimit(RLIMIT_FSIZE, &v1);
}

canonical_decompiled_code:
int func9()
{
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = time_limit;
v1.rlim_max = time_limit + 2LL;
setrlimit(RLIMIT_CPU, &v1);
v1.rlim_max = mem_limit;
v1.rlim_cur = mem_limit;
setrlimit(RLIMIT_AS, &v1);
v1.rlim_max = file_limit;
v1.rlim_cur = file_limit;
return setrlimit(RLIMIT_FSIZE, &v1);
}

original_code:
void limit() {
    struct rlimit limit;
    limit.rlim_cur = limit.rlim_max = time_limit;
    limit.rlim_max += 2;
    setrlimit(RLIMIT_CPU, &limit);
    limit.rlim_cur = limit.rlim_max = mem_limit;
    setrlimit(RLIMIT_AS, &limit);
    limit.rlim_cur = limit.rlim_max = file_limit;
    setrlimit(RLIMIT_FSIZE, &limit);
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


run

decompiled_code:
__int64 __fastcall run(char *path)
{
__pid_t v2; // edi
__int64 v3; // rsi
__int64 v4; // rax
unsigned int v5; // er12
void *v6; // rbp
__int64 result; // rax
struct rusage v8; // [rsp+0h] [rbp-188h] BYREF
char v9[112]; // [rsp+90h] [rbp-F8h] BYREF
int v10; // [rsp+100h] [rbp-88h]

cpid = fork();
v2 = cpid;
if ( !cpid )
{
limit();
freopen(input, "r", stdin);
freopen(output, "w+", stdout);
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
execl(path, path, 0LL);
v2 = cpid;
}
while ( 1 )
{
wait4(v2, (__WAIT_STATUS)&status, 0, &v8);
v3 = status & 0x7F;
if ( (status & 0x7F) == 0 )
break;
if ( (char)(v3 + 1) > 1 )
{
printf("%d\n", v3);
::result(4);
}
v4 = ptrace(PTRACE_PEEKUSER, (unsigned int)cpid, 120LL, 0LL);
if ( denycall[v4] )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
return ::result(5);
}
if ( v4 == 2 )
{
v5 = cpid;
v6 = malloc(0x400uLL);
ptrace(PTRACE_GETREGS, v5, 0LL, v9);
getfile(v10, (__int64)v6);
if ( strcmp((const char *)v6, input) || strcmp((const char *)v6, output) )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
free(v6);
::result(5);
}
free(v6);
}
use_time = 1000 * (LODWORD(v8.ru_utime.tv_sec) + LODWORD(v8.ru_stime.tv_sec))
+ (LODWORD(v8.ru_utime.tv_usec) + LODWORD(v8.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);
v2 = cpid;
}
if ( BYTE1(status) )
result = ::result(4);
else
result = ::result(0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *path)
{
__pid_t v2; // edi
__int64 v3; // rsi
__int64 v4; // rax
unsigned int v5; // er12
void *v6; // rbp
__int64 result; // rax
struct rusage v8; // [rsp+0h] [rbp-188h] BYREF
char v9[112]; // [rsp+90h] [rbp-F8h] BYREF
int v10; // [rsp+100h] [rbp-88h]

cpid = fork();
v2 = cpid;
if ( !cpid )
{
func9();
freopen(input, "r", stdin);
freopen(output, "w+", stdout);
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
execl(path, path, 0LL);
v2 = cpid;
}
while ( 1 )
{
wait4(v2, (__WAIT_STATUS)&status, 0, &v8);
v3 = status & 0x7F;
if ( (status & 0x7F) == 0 )
break;
if ( (char)(v3 + 1) > 1 )
{
printf("%d\n", v3);
::func7(4);
}
v4 = ptrace(PTRACE_PEEKUSER, (unsigned int)cpid, 120LL, 0LL);
if ( denycall[v4] )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
return ::func7(5);
}
if ( v4 == 2 )
{
v5 = cpid;
v6 = malloc(0x400uLL);
ptrace(PTRACE_GETREGS, v5, 0LL, v9);
func10(v10, (__int64)v6);
if ( strcmp((const char *)v6, input) || strcmp((const char *)v6, output) )
{
ptrace(PTRACE_KILL, (unsigned int)cpid, 0LL, 0LL);
kill(cpid, 9);
free(v6);
::func7(5);
}
free(v6);
}
use_time = 1000 * (LODWORD(v8.ru_utime.tv_sec) + LODWORD(v8.ru_stime.tv_sec))
+ (LODWORD(v8.ru_utime.tv_usec) + LODWORD(v8.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);
v2 = cpid;
}
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; }; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
int v5; // eax
const char *v6; // rdi
int v7; // eax
char *v8; // rdi
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], argv, envp);
strcpy(input, argv[2]);
strcpy(output, argv[3]);
v3 = atoi(argv[4]);
v4 = argv[5];
time_limit = v3;
v5 = atoi(v4);
v6 = argv[6];
mem_limit = (additional_mem + v5) << 20;
v7 = atoi(v6);
v8 = (char *)argv[1];
file_limit = v7 << 20;
run(v8);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
int v5; // eax
const char *v6; // rdi
int v7; // eax
char *v8; // rdi
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], argv, envp);
strcpy(input, argv[2]);
strcpy(output, argv[3]);
v3 = atoi(argv[4]);
v4 = argv[5];
time_limit = v3;
v5 = atoi(v4);
v6 = argv[6];
mem_limit = (additional_mem + v5) << 20;
v7 = atoi(v6);
v8 = (char *)argv[1];
file_limit = v7 << 20;
func12(v8);
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;
}


result

decompiled_code:
__int64 __fastcall result(int a1)
{
__int64 v2; // rcx
__int64 v3; // rdx
__int64 v4; // rsi

switch ( a1 )
{
case 0:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 0LL;
goto LABEL_9;
case 1:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 1LL;
goto LABEL_9;
case 2:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 2LL;
goto LABEL_9;
case 3:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 3LL;
goto LABEL_9;
case 4:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 4LL;
goto LABEL_9;
case 5:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 5LL;
LABEL_9:
printf("%d %d %d\n", v4, v3, v2);
exit(0);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 v2; // rcx
__int64 v3; // rdx
__int64 v4; // rsi

switch ( a1 )
{
case 0:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 0LL;
goto LABEL_9;
case 1:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 1LL;
goto LABEL_9;
case 2:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 2LL;
goto LABEL_9;
case 3:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 3LL;
goto LABEL_9;
case 4:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 4LL;
goto LABEL_9;
case 5:
v2 = (unsigned int)use_mem;
v3 = (unsigned int)use_time;
v4 = 5LL;
LABEL_9:
printf("%d %d %d\n", v4, v3, v2);
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;
}


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 *


filestatus

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

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

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);
    }
}


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;
}


result

decompiled_code:
void __fastcall result(int a1)
{
__int64 v1; // rsi

v1 = 0LL;
if ( !a1 )
goto LABEL_7;
if ( a1 == 1 )
{
v1 = 1LL;
goto LABEL_7;
}
v1 = 2LL;
if ( a1 == 2 || (v1 = 3LL, a1 == 3) )
{
LABEL_7:
printf("%d\n", v1);
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
__int64 v1; // rsi

v1 = 0LL;
if ( !a1 )
goto LABEL_7;
if ( a1 == 1 )
{
v1 = 1LL;
goto LABEL_7;
}
v1 = 2LL;
if ( a1 == 2 || (v1 = 3LL, a1 == 3) )
{
LABEL_7:
printf("%d\n", v1);
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


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_605AC * dword_60570);
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)(dword_605AC * dword_60570);
}

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;
}


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_605DC | (16 * dword_605D0) | (unsigned int)(dword_605C4 << 8);
}

canonical_decompiled_code:
__int64 func3()
{
return (bytes_per_pixel << 16) | dword_605DC | (16 * dword_605D0) | (unsigned int)(dword_605C4 << 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; // ebp
int v2; // eax
__int64 v3; // r8
int v4; // eax
int v5; // edx
int v6; // ecx
__off_t v7; // r9
unsigned int v9; // er12

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

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
int v1; // ebp
int v2; // eax
__int64 v3; // r8
int v4; // eax
int v5; // edx
int v6; // ecx
__off_t v7; // r9
unsigned int v9; // er12

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

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 __fastcall fb_free(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
int v6; // eax

fb_cmap_save(0);
v6 = fb_len(0LL, a2, v2, v3, v4, v5);
munmap(fb, v6);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
int v6; // eax

func1(0);
v6 = func0(0LL, a2, v2, v3, v4, v5);
munmap(fb, v6);
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_605A4;
}

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

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_60570 * (a1 + dword_605B4));
}

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

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)
{
char *v2; // rax
int v3; // edx
int v4; // ecx
const void *v5; // r8

v2 = fb_mem(a1);
return memcpy(&v2[v3 * (dword_605B0 + a2)], v5, v4 * v3);
}

canonical_decompiled_code:
void *__fastcall func9(int a1, int a2)
{
char *v2; // rax
int v3; // edx
int v4; // ecx
const void *v5; // r8

v2 = func8(a1);
return memcpy(&v2[v3 * (dword_605B0 + a2)], v5, v4 * v3);
}

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)
{
char v4; // dl
int v8; // eax

v4 = c_0;
if ( !c_0 )
{
v8 = fb_mode();
fill_rgb_conv(v8, &c_0);
v4 = c_0;
}
return (a1 >> dword_508 << v4) | (a3 >> dword_510) | (unsigned int)(a2 >> dword_50C << dword_504);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2, int a3)
{
char v4; // dl
int v8; // eax

v4 = c_0;
if ( !c_0 )
{
v8 = func3();
func10(v8, &c_0);
v4 = c_0;
}
return (a1 >> dword_508 << v4) | (a3 >> dword_510) | (unsigned int)(a2 >> dword_50C << dword_504);
}

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(__int64 a1)
{
void *v1; // rax
void *v2; // r12

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

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
void *v1; // rax
void *v2; // r12

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

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; // ebp
__pid_t v4; // eax

v1 = a1;
if ( !s_srandom_called )
{
v3 = time(0LL);
v4 = getpid();
srandom(v4 ^ v3);
s_srandom_called = 1;
}
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; // ebp
__pid_t v4; // eax

v1 = a1;
if ( !s_srandom_called )
{
v3 = time(0LL);
v4 = getpid();
srandom(v4 ^ v3);
s_srandom_called = 1;
}
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; // r8
char v4; // al
char v6[32]; // [rsp+8h] [rbp-20h] 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; // r8
char v4; // al
char v6[32]; // [rsp+8h] [rbp-20h] 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)
{
_QWORD *v4; // rbx
_BYTE *v5; // rax

if ( a1 <= 1 )
return 0LL;
v4 = (_QWORD *)(a2 + 8);
do
{
v5 = (_BYTE *)*v4;
if ( *(_BYTE *)*v4 == 45 && v5[1] == 100 && !v5[2] )
{
*a3 = 1;
puts("debug output enabled");
}
++v4;
}
while ( v4 != (_QWORD *)(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);
}


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 *v2; // rbx
__int64 v3; // rdi
int v4; // eax
socklen_t v5; // edx
struct sockaddr v7; // [rsp+0h] [rbp-158h] BYREF
char buf[328]; // [rsp+10h] [rbp-148h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(char **a1)
{
struct hostent *v2; // rbx
__int64 v3; // rdi
int v4; // eax
socklen_t v5; // edx
struct sockaddr v7; // [rsp+0h] [rbp-158h] BYREF
char buf[328]; // [rsp+10h] [rbp-148h] BYREF

v2 = gethostbyname("soft.vub.ac.be");
v7.sa_family = 2;
v3 = (unsigned int)socket(2, 1, 0);
*(_WORD *)v7.sa_data = func0(v3, &v7, 16LL);
v4 = **(_DWORD **)v2->h_addr_list;
*(_QWORD *)&v7.sa_data[6] = 0LL;
*(_DWORD *)&v7.sa_data[2] = v4;
connect(v3, &v7, v5);
recv(v3, buf, 0x12BuLL, 0);
send(v3, "USER joe\r\n", 0xFuLL, 0);
recv(v3, buf, 0x12BuLL, 0);
send(v3, "PASS joepass\r\n", 0xFuLL, 0);
recv(v3, buf, 0x12BuLL, 0);
LODWORD(v2) = send(v3, "QUIT\r\n", 6uLL, 0);
strcpy(*a1, buf);
buf[(int)v2] = 0;
close(v3);
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, __int128 a15, long double a16)
{
long double v8; // fst7

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

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, __int128 a15, long double a16)
{
long double v8; // fst7

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

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; // r12
__int64 v5; // rax
bool v6; // zf
_QWORD *v7; // rbp
const char *v8; // rsi
_QWORD *v9; // r12
int result; // eax
_QWORD *v11; // r13
const char *i; // r15
__int64 v13; // rdx
__int64 v14; // rax
_QWORD *v15; // r14
__int64 v16; // rax

if ( argc <= 2 )
{
fwrite("Usage: call pythonfile funcname [args]\n", 1uLL, 0x27uLL, stderr);
return 1;
}
Py_Initialize();
v4 = (_QWORD *)PyString_FromString();
v5 = PyImport_Import();
v6 = (*v4)-- == 1LL;
v7 = (_QWORD *)v5;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v4[1] + 48LL))(v4);
if ( !v7 )
{
PyErr_Print();
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
return 1;
}
v8 = argv[2];
v9 = (_QWORD *)PyObject_GetAttrString();
if ( !v9 )
{
if ( PyErr_Occurred() )
PyErr_Print();
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
goto LABEL_12;
}
if ( !(unsigned int)PyCallable_Check() )
{
if ( PyErr_Occurred() )
PyErr_Print();
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
LABEL_10:
v6 = (*v9)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v9[1] + 48LL))(v9);
LABEL_12:
v6 = (*v7)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v7[1] + 48LL))(v7);
Py_Finalize();
return 0;
}
v11 = (_QWORD *)PyTuple_New();
if ( argc == 3 )
{
LABEL_30:
v14 = PyObject_CallObject();
v6 = (*v11)-- == 1LL;
v15 = (_QWORD *)v14;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, _QWORD *))(v11[1] + 48LL))(v11, v11);
if ( v15 )
{
v16 = PyInt_AsLong();
printf("Result of call: %ld\n", v16);
v6 = (*v15)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *))(v15[1] + 48LL))(v15);
goto LABEL_10;
}
v6 = (*v9)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, _QWORD *))(v9[1] + 48LL))(v9, v11);
v6 = (*v7)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, _QWORD *))(v7[1] + 48LL))(v7, v11);
PyErr_Print();
fwrite("Call failed\n", 1uLL, 0xCuLL, stderr);
result = 1;
}
else
{
for ( i = 0LL; ; ++i )
{
atoi(argv[(_QWORD)i + 3]);
v13 = PyInt_FromLong();
if ( !v13 )
break;
v8 = i;
PyTuple_SetItem();
if ( i == (const char *)(unsigned int)(argc - 4) )
goto LABEL_30;
}
v6 = (*v11)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, const char *, _QWORD))(v11[1] + 48LL))(v11, v8, 0LL);
v6 = (*v7)-- == 1LL;
if ( v6 )
(*(void (__fastcall **)(_QWORD *, const char *, __int64))(v7[1] + 48LL))(v7, v8, v13);
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; // r8
unsigned int v2; // er12

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; // r8
unsigned int v2; // er12

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; } *


enqueue

decompiled_code:
__int64 __fastcall enqueue(__int64 *a1, __int64 *a2, int a3, int a4)
{
_DWORD *v7; // rax
__int64 v8; // rdi
__int64 result; // rax
__int64 v10; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 *a2, int a3, int a4)
{
_DWORD *v7; // rax
__int64 v8; // rdi
__int64 result; // rax
__int64 v10; // rdx

v7 = malloc(0x10uLL);
if ( !v7 )
return simple_error(5LL, 0LL, "failed to allocate memory to enqueue a new node onto a queue");
*v7 = a3;
v8 = *a1;
v7[1] = a4;
*((_QWORD *)v7 + 1) = 0LL;
result = func1(v8);
if ( (_DWORD)result )
{
*a1 = v10;
}
else
{
result = *a2;
*(_QWORD *)(*a2 + 8) = v10;
}
*a2 = v10;
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: struct queue { int data; enum QUEUE_DATA_TYPE { NUMBER=0, OPERATOR=1 } type; struct queue *next; } **

variable_types:
tail
struct queue **

variable_types: data int

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


dequeue

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

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

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int **a1, _QWORD *a2)
{
unsigned int *v2; // r8
unsigned int *v3; // rax
unsigned int v4; // er12

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

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: value int

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


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall queue_empty(__int64 a1)
{
return stack_empty(a1);
}

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

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);
}

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


decompiled_code:
__int64 __fastcall is_number(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 1LL;
if ( (unsigned __int8)(*a1 - 48) > 9u )
break;
++a1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 1LL;
if ( (unsigned __int8)(*a1 - 48) > 9u )
break;
++a1;
}
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
__int64 v5; // rdx

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

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

if ( a3 <= 0 )
return 0LL;
v3 = &a1[a3];
result = 0LL;
do
{
v5 = *a1++ == a2;
result += v5;
}
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; // xmm0
__m128i v5; // [rsp+0h] [rbp-118h] BYREF
__int64 v6; // [rsp+10h] [rbp-108h]
__m128i v7; // [rsp+20h] [rbp-F8h] BYREF
__int64 v8; // [rsp+30h] [rbp-E8h]
char v9[216]; // [rsp+40h] [rbp-D8h] BYREF

if ( argc == 2 )
{
simple_initialize_variable_map(v9, argv, envp);
simple_load_file(&v5, argv[1]);
v4 = _mm_loadu_si128(&v5);
v8 = v6;
v7 = v4;
simple_execute(&v7, v9);
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)
{
const unsigned __int16 **v2; // rax
__int64 v3; // r13
const __int32_t *result; // rax

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

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

if ( strlen(a1) != 1 )
simple_error(3LL, a2, a1);
v2 = _ctype_b_loc();
v3 = *a1;
if ( ((*v2)[v3] & 0x400) == 0 )
simple_error(3LL, a2, a1);
result = *_ctype_tolower_loc();
if ( (_DWORD)v3 != result[v3] )
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)
{
_BOOL4 v1; // er12
const unsigned __int16 **v2; // rax
__int64 v3; // rbp

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

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
_BOOL4 v1; // er12
const unsigned __int16 **v2; // rax
__int64 v3; // rbp

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

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; // edx
__int64 v5; // r8
int v6; // ecx
__int64 result; // rax
_DWORD *v8; // rsi

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

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

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

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(unsigned __int8 *a1)
{
int v1; // eax
unsigned int v2; // er8
__int64 result; // rax
int v4; // edx

v1 = *a1;
if ( v1 == 60 )
{
v2 = 0;
if ( !a1[1] )
return v2;
}
v4 = *a1;
if ( v4 == 60 && a1[1] == 61 && !a1[2] )
return 1LL;
if ( v4 == 61 && a1[1] == 61 )
{
v2 = 2;
if ( !a1[2] )
return v2;
}
if ( v4 == 62 && a1[1] == 61 )
{
v2 = 3;
if ( !a1[2] )
return v2;
}
if ( v1 != 62 || a1[1] )
result = 5LL;
else
result = 4LL;
return result;
}

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)
{
__int64 v2; // r12
__int64 v5; // rdi
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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

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

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);
}