repo: aszlig/striptimes

decompiled_code:
__int64 __fastcall patch_gzip(int fd)
{
__int64 result; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 0;
if ( lseek(fd, 4LL, 0) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(write(fd, buf, 4uLL) == -1);
return result;
}

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

buf[0] = 0;
if ( lseek(fd, 4LL, 0) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(write(fd, buf, 4uLL) == -1);
return result;
}

original_code:
int patch_gzip(int fd)
{
    const int32_t ts = 0;
    if (lseek(fd, 4, 0) == -1) return -1;
    if (write(fd, &ts, 4) == -1) return -1;
    return 0;
}

canonical_original_code:
int patch_gzip(int fd)
{
    int ts = 0;
    if (lseek(fd, 4, 0) == -1) return -1;
    if (write(fd, &ts, 4) == -1) return -1;
    return 0;
}

variable_types: fd int

variable_types: ts int


decompiled_code:
__int64 __fastcall patch_ar(int fd)
{
unsigned int v1; // edx
int v2; // eax
unsigned int v3; // eax
char buf[10]; // [rsp+4h] [rbp-14h] BYREF
char v6[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( lseek(fd, 7LL, 0) != -1 )
{
while ( 1 )
{
v3 = read(fd, v6, 1uLL);
v1 = v3;
if ( v3 == 1 )
{
if ( v6[0] != 10 )
goto LABEL_4;
}
else
{
if ( !v3 )
return v1;
LABEL_4:
if ( lseek(fd, 15LL, 1) == -1 )
return (unsigned int)-1;
if ( write(fd, "0 ", 0xCuLL) == -1 )
return (unsigned int)-1;
if ( lseek(fd, 20LL, 1) == -1 )
return (unsigned int)-1;
if ( read(fd, buf, 0xAuLL) != 10 )
return (unsigned int)-1;
if ( read(fd, v6, 2uLL) != 2 )
return (unsigned int)-1;
if ( v6[0] != 96 || v6[1] != 10 )
{
*_errno_location() = 22;
return (unsigned int)-1;
}
v2 = atoi(buf);
if ( lseek(fd, v2, 1) == -1 )
return (unsigned int)-1;
}
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
unsigned int v1; // edx
int v2; // eax
unsigned int v3; // eax
char buf[10]; // [rsp+4h] [rbp-14h] BYREF
char v6[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( lseek(fd, 7LL, 0) != -1 )
{
while ( 1 )
{
v3 = read(fd, v6, 1uLL);
v1 = v3;
if ( v3 == 1 )
{
if ( v6[0] != 10 )
goto LABEL_4;
}
else
{
if ( !v3 )
return v1;
LABEL_4:
if ( lseek(fd, 15LL, 1) == -1 )
return (unsigned int)-1;
if ( write(fd, "0 ", 0xCuLL) == -1 )
return (unsigned int)-1;
if ( lseek(fd, 20LL, 1) == -1 )
return (unsigned int)-1;
if ( read(fd, buf, 0xAuLL) != 10 )
return (unsigned int)-1;
if ( read(fd, v6, 2uLL) != 2 )
return (unsigned int)-1;
if ( v6[0] != 96 || v6[1] != 10 )
{
*_errno_location() = 22;
return (unsigned int)-1;
}
v2 = atoi(buf);
if ( lseek(fd, v2, 1) == -1 )
return (unsigned int)-1;
}
}
}
return (unsigned int)-1;
}

original_code:
int patch_ar(int fd)
{
    int len;
    char buf[2];
    char size[10];
    if (lseek(fd, 7, 0) == -1) return -1;
    for (;;) {
        while ((len = read(fd, buf, 1)) == 1)
            if (*buf != '\n') break;
        if (len == 0)
            break;
        if (lseek(fd, 15, 1) == -1) return -1;
        if (write(fd, "0           ", 12) == -1) return -1;
        if (lseek(fd, 20, 1) == -1) return -1;
        if (read(fd, size, 10) != 10) return -1;
        if (read(fd, buf, 2) != 2) return -1;
        if (buf[0] != '`' || buf[1] != '\n') {
            (*__errno_location ()) = 22;
            return -1;
        }
        if (lseek(fd, atoi(size), 1) == -1) return -1;
    }
    return 0;
}

variable_types: len int

variable_types:
buf
char [2]

variable_types:
size
char [10]

return_type: int


main

canonical_name: main

decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
const char **v3; // rbx
__int64 v4; // rbp
__int64 result; // rax

if ( a1 <= 1 )
{
fprintf(stderr, "Usage: %s FILENAME...\n", *a2);
result = 1LL;
}
else
{
v3 = (const char **)&a2[a1 - 1];
v4 = (__int64)&v3[-(a1 - 2) - 1];
do
sub_4011B2(*v3--);
while ( v3 != (const char **)v4 );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
const char **v3; // rbx
__int64 v4; // rbp
__int64 result; // rax

if ( a1 <= 1 )
{
fprintf(stderr, "Usage: %s FILENAME...\n", *a2);
result = 1LL;
}
else
{
v3 = (const char **)&a2[a1 - 1];
v4 = (__int64)&v3[-(a1 - 2) - 1];
do
func6(*v3--);
while ( v3 != (const char **)v4 );
result = 0LL;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    if (argc <= 1) {
        fprintf(stderr, "Usage: %s FILENAME...\n", argv[0]);
        return 1;
    }
    while (argc-- > 1)
        progress(argv[argc]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


help

repo: atecle/CacheSim

decompiled_code:
void __noreturn help()
{
fwrite("<USAGE>: ", 1uLL, 9uLL, stderr);
fwrite(
"sim [-h] <cache size> <associativity> <block size> <replace alg> <write policy> <trace file>\n",
1uLL,
0x5DuLL,
stderr);
fputc(10, stderr);
fwrite("[-h]: Display usage information \n", 1uLL, 0x21uLL, stderr);
fputc(10, stderr);
fwrite(
"<cache size>: Total size of cache. Must be power of two and must equal to (number of sets x <set size> x <block size>) \n",
1uLL,
0x78uLL,
stderr);
fputc(10, stderr);
fwrite("<associativity>: 'direct', 'assoc', or 'assoc:n' \n", 1uLL, 0x32uLL, stderr);
fputc(10, stderr);
fwrite("\t'direct' simulates direct mapped cache.\n", 1uLL, 0x29uLL, stderr);
fwrite("\t'assoc' simulates a fully associative cache'. \n", 1uLL, 0x30uLL, stderr);
fwrite("\t'assoc:n' simulates an n-way associative cache. n must be a power of two.\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
fwrite("<block size>: Must be power of 2, specifies size of cache block.\n", 1uLL, 0x41uLL, stderr);
fputc(10, stderr);
fwrite("<replace alg> : 'FIFO', 'LRU', or 'Random' \n", 1uLL, 0x2CuLL, stderr);
fputc(10, stderr);
fwrite("\t'FIFO' simulates first in first out replacement algorithm.\n", 1uLL, 0x3CuLL, stderr);
fwrite("\t 'LRU' simulates least recently used replacement algorithm.\n", 1uLL, 0x3DuLL, stderr);
fwrite("\t 'Random' simulates random replacement algorithm.\n", 1uLL, 0x33uLL, stderr);
fputc(10, stderr);
fwrite("<write policy>: 'wt' simulates write through cache. 'wb' simulates write back cache\n", 1uLL, 0x54uLL, stderr);
fputc(10, stderr);
fwrite(
"<trace file>: name of the file that contains memory access traces generated using Pin.\n",
1uLL,
0x57uLL,
stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite("<USAGE>: ", 1uLL, 9uLL, stderr);
fwrite(
"sim [-h] <cache size> <associativity> <block size> <replace alg> <write policy> <trace file>\n",
1uLL,
0x5DuLL,
stderr);
fputc(10, stderr);
fwrite("[-h]: Display usage information \n", 1uLL, 0x21uLL, stderr);
fputc(10, stderr);
fwrite(
"<cache size>: Total size of cache. Must be power of two and must equal to (number of sets x <set size> x <block size>) \n",
1uLL,
0x78uLL,
stderr);
fputc(10, stderr);
fwrite("<associativity>: 'direct', 'assoc', or 'assoc:n' \n", 1uLL, 0x32uLL, stderr);
fputc(10, stderr);
fwrite("\t'direct' simulates direct mapped cache.\n", 1uLL, 0x29uLL, stderr);
fwrite("\t'assoc' simulates a fully associative cache'. \n", 1uLL, 0x30uLL, stderr);
fwrite("\t'assoc:n' simulates an n-way associative cache. n must be a power of two.\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
fwrite("<block size>: Must be power of 2, specifies size of cache block.\n", 1uLL, 0x41uLL, stderr);
fputc(10, stderr);
fwrite("<replace alg> : 'FIFO', 'LRU', or 'Random' \n", 1uLL, 0x2CuLL, stderr);
fputc(10, stderr);
fwrite("\t'FIFO' simulates first in first out replacement algorithm.\n", 1uLL, 0x3CuLL, stderr);
fwrite("\t 'LRU' simulates least recently used replacement algorithm.\n", 1uLL, 0x3DuLL, stderr);
fwrite("\t 'Random' simulates random replacement algorithm.\n", 1uLL, 0x33uLL, stderr);
fputc(10, stderr);
fwrite("<write policy>: 'wt' simulates write through cache. 'wb' simulates write back cache\n", 1uLL, 0x54uLL, stderr);
fputc(10, stderr);
fwrite(
"<trace file>: name of the file that contains memory access traces generated using Pin.\n",
1uLL,
0x57uLL,
stderr);
exit(0);
}

original_code:
void help() {
    fprintf(stderr, "<USAGE>: ");
    fprintf(stderr,"sim [-h] <cache size> <associativity> <block size> <replace alg> <write policy> <trace file>\n");
    fprintf(stderr,"\n");
    fprintf(stderr,"[-h]: Display usage information \n");
    fprintf(stderr,"\n");
    fprintf(stderr, "<cache size>: Total size of cache. Must be power of two and must equal to (number of sets x <set size> x <block size>) \n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<associativity>: 'direct', 'assoc', or 'assoc:n' \n");
    fprintf(stderr, "\n");
    fprintf(stderr, "\t'direct' simulates direct mapped cache.\n");
    fprintf(stderr, "\t'assoc' simulates a fully associative cache'. \n");
    fprintf(stderr, "\t'assoc:n' simulates an n-way associative cache. n must be a power of two.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<block size>: Must be power of 2, specifies size of cache block.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<replace alg> : 'FIFO', 'LRU', or 'Random' \n");
    fprintf(stderr, "\n");
    fprintf(stderr, "\t'FIFO' simulates first in first out replacement algorithm.\n");
    fprintf(stderr, "\t 'LRU' simulates least recently used replacement algorithm.\n");
    fprintf(stderr, "\t 'Random' simulates random replacement algorithm.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<write policy>: 'wt' simulates write through cache. 'wb' simulates write back cache\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<trace file>: name of the file that contains memory access traces generated using Pin.\n");
    exit(0);
}

return_type: void


decompiled_code:
__int64 __fastcall isPower2(int a1)
{
return ((a1 & (a1 - 1)) == 0) & (unsigned __int8)(a1 > 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return ((a1 & (a1 - 1)) == 0) & (unsigned __int8)(a1 > 0);
}

variable_types: x int


getBlock

decompiled_code:
__int64 __fastcall getBlock(int a1, char a2)
{
return a1 & (unsigned int)((1 << a2) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, char a2)
{
return a1 & (unsigned int)((1 << a2) - 1);
}

original_code:
int getBlock(int w, int b) {
    int mask = (1 << b) - 1;
    int block = w & mask;
    return block;
}

variable_types: w int

variable_types: b int

variable_types: mask int

variable_types: block int


getSetIndex

decompiled_code:
__int64 __fastcall getSetIndex(int a1, char a2)
{
return a1 & (unsigned int)((1 << a2) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, char a2)
{
return a1 & (unsigned int)((1 << a2) - 1);
}

original_code:
int getSetIndex(int w, int s) {
    int mask = (1 << s) - 1;
    int set_index = w & mask;
    return set_index;
}

variable_types: s int


isHit

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

v3 = (unsigned int *)(a1 + 16LL * a2);
result = *v3;
if ( (_DWORD)result )
{
result = 1LL;
if ( v3[1] != a3 )
{
v3[1] = a3;
result = 0LL;
}
}
else
{
*v3 = 1;
v3[1] = a3;
}
return result;
}

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

v3 = (unsigned int *)(a1 + 16LL * a2);
result = *v3;
if ( (_DWORD)result )
{
result = 1LL;
if ( v3[1] != a3 )
{
v3[1] = a3;
result = 0LL;
}
}
else
{
*v3 = 1;
v3[1] = a3;
}
return result;
}

original_code:
int isHit(struct Address *cache, int set_index, int tag) {
    if (cache[set_index].valid_bit == 0) {
        cache[set_index].valid_bit = 1;
        cache[set_index].tag = tag;
        return 0;
    }
    else {
        if (cache[set_index].tag == tag)
        {
            return 1;
        }
        cache[set_index].tag = tag;
        return 0;
    }
}

variable_types: struct Address { int valid_bit; int tag; int set_index; int dirty_bit; } *

variable_types: tag int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er14
const char *v5; // r12
int v7; // edi
void *v8; // rsp
__int64 v9; // rax
bool v10; // cl
bool v11; // dl
_BYTE v12[8]; // [rsp+0h] [rbp-40h] BYREF
_BYTE *v13; // [rsp+8h] [rbp-38h]

checkInput(argc, argv);
v3 = atoi(argv[1]);
v4 = atoi(argv[3]);
v5 = argv[2];
if ( v5[5] == 58 )
{
v13 = v12;
v7 = strlen(v5);
v8 = alloca(v7 - 6);
if ( v7 > 6 )
{
v9 = 7LL;
do
{
v12[v9 - 7] = v5[v9 - 1];
v10 = v7 - 6 > (int)v9 - 6;
v11 = v7 > (int)v9++;
}
while ( v11 && v10 );
}
}
direct(argv[6], v3, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er14
const char *v5; // r12
int v7; // edi
void *v8; // rsp
__int64 v9; // rax
bool v10; // cl
bool v11; // dl
_BYTE v12[8]; // [rsp+0h] [rbp-40h] BYREF
_BYTE *v13; // [rsp+8h] [rbp-38h]

checkInput(argc, argv);
v3 = atoi(argv[1]);
v4 = atoi(argv[3]);
v5 = argv[2];
if ( v5[5] == 58 )
{
v13 = v12;
v7 = strlen(v5);
v8 = alloca(v7 - 6);
if ( v7 > 6 )
{
v9 = 7LL;
do
{
v12[v9 - 7] = v5[v9 - 1];
v10 = v7 - 6 > (int)v9 - 6;
v11 = v7 > (int)v9++;
}
while ( v11 && v10 );
}
}
func12(argv[6], v3, v4);
return 0;
}

original_code:
int main (int argc, char **argv)
{
    checkInput(argc, argv);
    int cache_size = atoi(argv[1]);
    int block_size = atoi(argv[3]);
    int num_lines;
    int num_sets;
    char *w_pol = argv[5];
    if (strcmp(argv[2], "direct")) {
        num_lines = 1;
        num_sets = cache_size/(block_size);
    }
    if (strcmp(argv[2], "assoc")) {
        num_sets = 1;
        num_lines = cache_size/block_size;
    }
    if (argv[2][5] == ':') {
        char *input = argv[2];
        int len = strlen(input);
        char n_way[len - 6];
        int i;
        int j;
        for (i = 6, j = 0; i < len && j < (len - 6); i++, j++)
        {
            n_way[j] = argv[2][i];
        }
        num_lines = atoi(n_way);
    }
    direct(argv[6], cache_size, block_size, w_pol);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    checkInput(argc, argv);
    int cache_size = atoi(argv[1]);
    int block_size = atoi(argv[3]);
    int num_lines;
    int num_sets;
    char *w_pol = argv[5];
    if (strcmp(argv[2], "direct")) {
        num_lines = 1;
        num_sets = cache_size/(block_size);
    }
    if (strcmp(argv[2], "assoc")) {
        num_sets = 1;
        num_lines = cache_size/block_size;
    }
    if (argv[2][5] == ':') {
        char *input = argv[2];
        int len = strlen(input);
        char n_way[-1];
        int i;
        int j;
        for (i = 6, j = 0; i < len && j < (len - 6); i++, j++)
        {
            n_way[j] = argv[2][i];
        }
        num_lines = atoi(n_way);
    }
    direct(argv[6], cache_size, block_size, w_pol);
    return 0;
}

variable_types:
argv
char **

variable_types:
input
char *

variable_types: i int

variable_types: j int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rdx
__int64 v5; // rax
char v7[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = my_malloc(4LL, argv, envp);
my_free(v3);
my_free(v3);
my_free(v7);
v5 = my_malloc(4LL, argv, v4);
my_free(v5);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rdx
__int64 v5; // rax
char v7[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = func8(4LL, argv, envp);
func9(v3);
func9(v3);
func9(v7);
v5 = func8(4LL, argv, v4);
func9(v5);
return 1;
}

original_code:
int main(int argc, char **argv) {
    int *x = my_malloc(sizeof(int));
    my_free(x);
    my_free(x);
    int y;
    my_free(&y);
    char *t = my_malloc(4);
    my_free(t);
    return 1;
}

variable_types:
x
int *

variable_types: y int

variable_types:
t
char *


decompiled_code:
void __fastcall remove_from_arr(__int64 a1)
{
__int64 v1; // rax

if ( i > 0 )
{
v1 = 0LL;
while ( arr[v1] != a1 )
{
if ( ++v1 == i )
return;
}
arr[(int)v1] = 0LL;
}
}

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

if ( i > 0 )
{
v1 = 0LL;
while ( arr[v1] != a1 )
{
if ( ++v1 == i )
return;
}
arr[(int)v1] = 0LL;
}
}

original_code:
void remove_from_arr(MemEntry *p){
 int j;
 for(j=0;j<i;j++){
  if(p == arr[j]){
   arr[j]= ((void *)0);
   return;
  }
 }
}

canonical_original_code:
void remove_from_arr(struct MemEntry *p){
 int j;
 for(j=0;j<i;j++){
  if(p == arr[j]){
   arr[j]= ((void *)0);
   return;
  }
 }
}

variable_types: struct MemEntry { struct MemEntry *prev; struct MemEntry *succ; unsigned int size; int isfree; } *


decompiled_code:
char *__fastcall my_malloc(unsigned int a1)
{
__int64 v1; // rbx
_QWORD *v2; // rbx
__int64 v3; // rax
char *result; // rax
unsigned int v5; // eax
unsigned __int64 v6; // rdx
__int64 v7; // rax
__int64 *v8; // rdx
__int64 v9; // rdx

v1 = root;
if ( !root )
{
LABEL_2:
v2 = sbrk(a1 + 24LL);
if ( v2 == (_QWORD *)-1LL )
return 0LL;
if ( last )
{
printf("BKR making another chunk size %d\n", a1);
v3 = last;
*v2 = last;
v2[1] = *(_QWORD *)(v3 + 8);
*((_DWORD *)v2 + 4) = a1;
*((_DWORD *)v2 + 5) = 0;
*(_QWORD *)(v3 + 8) = v2;
last = (__int64)v2;
}
else
{
printf("BKR making first chunk size %d\n", a1);
*v2 = 0LL;
v2[1] = 0LL;
*((_DWORD *)v2 + 4) = a1;
*((_DWORD *)v2 + 5) = 0;
last = (__int64)v2;
root = (__int64)v2;
}
return (char *)(v2 + 3);
}
while ( 1 )
{
v5 = *(_DWORD *)(v1 + 16);
if ( v5 < a1 )
{
v1 = *(_QWORD *)(v1 + 8);
goto LABEL_8;
}
if ( *(_DWORD *)(v1 + 20) )
break;
v1 = *(_QWORD *)(v1 + 8);
LABEL_8:
if ( !v1 )
goto LABEL_2;
}
v6 = a1 + 24LL;
if ( v5 < v6 )
{
*(_DWORD *)(v1 + 20) = 0;
remove_from_arr(v1);
result = (char *)(v1 + 24);
}
else
{
v7 = v1 + v6;
*(_QWORD *)v7 = v1;
v8 = *(__int64 **)(v1 + 8);
*(_QWORD *)(v7 + 8) = v8;
if ( v8 )
*v8 = v7;
*(_QWORD *)(v1 + 8) = v7;
*(_DWORD *)(v7 + 16) = *(_DWORD *)(v1 + 16) + -24 - a1;
*(_DWORD *)(v7 + 20) = 1;
*(_DWORD *)(v1 + 16) = a1;
*(_DWORD *)(v1 + 20) = 0;
v9 = last;
if ( last == v1 )
v9 = v7;
last = v9;
remove_from_arr(v1);
result = (char *)(v1 + 24);
}
return result;
}

original_code:
void *
my_malloc( unsigned int size )
{
 struct MemEntry * p;
 struct MemEntry * succ;
 p = root;
 while ( p != 0 )
 {
  if ( p->size < size )
  {
   p = p->succ;
  }
  else if ( !p->isfree )
  {
   p = p->succ;
  }
  else if ( p->size < (size + sizeof(struct MemEntry)) )
  {
   p->isfree = 0;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
  else
  {
   succ = (struct MemEntry *)((char *)p + sizeof(struct MemEntry) + size);
   succ->prev = p;
   succ->succ = p->succ;
   if(p->succ != 0)
    p->succ->prev = succ;
   p->succ = succ;
   succ->size = p->size - sizeof(struct MemEntry) - size;
   succ->isfree = 1;
   p->size = size;
   p->isfree = 0;
   last = (p == last) ? succ : last;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
 }
 if ( (p = (struct MemEntry *)sbrk( sizeof(struct MemEntry) + size )) == (void *)-1 )
 {
  return 0;
 }
 else if ( last == 0 )
 {
  printf( "BKR making first chunk size %d\n", size );
  p->prev = 0;
  p->succ = 0;
  p->size = size;
  p->isfree = 0;
  root = last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 else
 {
  printf( "BKR making another chunk size %d\n", size );
  p->prev = last;
  p->succ = last->succ;
  p->size = size;
  p->isfree = 0;
  last->succ = p;
  last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 return 0;
}

canonical_original_code:
void *my_malloc(unsigned int size)
{
 struct MemEntry *p;
 struct MemEntry *succ;
 p = root;
 while ( p != 0 )
 {
  if ( p->size < size )
  {
   p = p->succ;
  }
  else if ( !p->isfree )
  {
   p = p->succ;
  }
  else if ( p->size < (size + sizeof(struct MemEntry)) )
  {
   p->isfree = 0;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
  else
  {
   succ = (struct MemEntry *)((char *)p + sizeof(struct MemEntry) + size);
   succ->prev = p;
   succ->succ = p->succ;
   if(p->succ != 0)
    p->succ->prev = succ;
   p->succ = succ;
   succ->size = p->size - sizeof(struct MemEntry) - size;
   succ->isfree = 1;
   p->size = size;
   p->isfree = 0;
   last = (p == last) ? succ : last;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
 }
 if ( (p = (struct MemEntry *)sbrk( sizeof(struct MemEntry) + size )) == (void *)-1 )
 {
  return 0;
 }
 else if ( last == 0 )
 {
  printf( "BKR making first chunk size %d\n", size );
  p->prev = 0;
  p->succ = 0;
  p->size = size;
  p->isfree = 0;
  root = last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 else
 {
  printf( "BKR making another chunk size %d\n", size );
  p->prev = last;
  p->succ = last->succ;
  p->size = size;
  p->isfree = 0;
  last->succ = p;
  last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 return 0;
}

variable_types:
size
unsigned int

return_type: void *

user_defined_types: struct MemEntry { struct MemEntry *prev; struct MemEntry *succ; unsigned int size; int isfree; }


decompiled_code:
int __fastcall my_free(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rax
char v4; // dl
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rax
_QWORD *v9; // rax
int v10; // eax
_QWORD *v11; // rax
int v12; // eax

v1 = a1 - 24;
v2 = root;
v3 = root;
v4 = 0;
while ( v1 != v3 && v3 )
{
v3 = *(_QWORD *)(v3 + 8);
v4 = 1;
if ( !v3 )
{
root = 0LL;
LODWORD(v5) = puts("<ERROR>: Has not been malloc or freed already");
root = v2;
return v5;
}
}
if ( v4 )
root = v3;
if ( i <= 0 )
{
LABEL_12:
root = v2;
v7 = *(_QWORD *)(a1 - 24);
if ( v7 && *(_DWORD *)(v7 + 20) )
{
*(_DWORD *)(v7 + 16) += *(_DWORD *)(a1 - 8) + 24;
v8 = *(_QWORD *)(a1 - 16);
*(_DWORD *)(a1 - 4) = 1;
*(_QWORD *)(v7 + 8) = v8;
v9 = *(_QWORD **)(a1 - 16);
if ( v9 )
*v9 = v7;
printf("BKR freeing block %#x merging with predecessor new size is %d.\n", a1, *(unsigned int *)(v7 + 16));
}
else
{
printf("BKR freeing block %#x.\n", a1);
v10 = i++;
arr[v10] = v1;
*(_DWORD *)(a1 - 4) = 1;
v7 = a1 - 24;
}
v5 = *(_QWORD *)(a1 - 16);
if ( v5 && *(_DWORD *)(v5 + 20) )
{
*(_DWORD *)(v7 + 16) += *(_DWORD *)(v5 + 16) + 24;
*(_QWORD *)(v7 + 8) = *(_QWORD *)(v5 + 8);
*(_DWORD *)(v7 + 20) = 1;
v11 = *(_QWORD **)(v5 + 8);
if ( v11 )
*v11 = v7;
v12 = i++;
arr[v12] = v1;
LODWORD(v5) = printf(
"BKR freeing block %#x merging with successor new size is %d.\n",
a1,
*(unsigned int *)(v7 + 16));
}
}
else
{
v6 = 0LL;
while ( arr[v6] != v1 )
{
if ( ++v6 == i )
goto LABEL_12;
}
LODWORD(v5) = puts("<ERROR>: Has already been freed");
}
return v5;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rax
char v4; // dl
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rax
_QWORD *v9; // rax
int v10; // eax
_QWORD *v11; // rax
int v12; // eax

v1 = a1 - 24;
v2 = root;
v3 = root;
v4 = 0;
while ( v1 != v3 && v3 )
{
v3 = *(_QWORD *)(v3 + 8);
v4 = 1;
if ( !v3 )
{
root = 0LL;
LODWORD(v5) = puts("<ERROR>: Has not been malloc or freed already");
root = v2;
return v5;
}
}
if ( v4 )
root = v3;
if ( i <= 0 )
{
LABEL_12:
root = v2;
v7 = *(_QWORD *)(a1 - 24);
if ( v7 && *(_DWORD *)(v7 + 20) )
{
*(_DWORD *)(v7 + 16) += *(_DWORD *)(a1 - 8) + 24;
v8 = *(_QWORD *)(a1 - 16);
*(_DWORD *)(a1 - 4) = 1;
*(_QWORD *)(v7 + 8) = v8;
v9 = *(_QWORD **)(a1 - 16);
if ( v9 )
*v9 = v7;
printf("BKR freeing block %#x merging with predecessor new size is %d.\n", a1, *(unsigned int *)(v7 + 16));
}
else
{
printf("BKR freeing block %#x.\n", a1);
v10 = i++;
arr[v10] = v1;
*(_DWORD *)(a1 - 4) = 1;
v7 = a1 - 24;
}
v5 = *(_QWORD *)(a1 - 16);
if ( v5 && *(_DWORD *)(v5 + 20) )
{
*(_DWORD *)(v7 + 16) += *(_DWORD *)(v5 + 16) + 24;
*(_QWORD *)(v7 + 8) = *(_QWORD *)(v5 + 8);
*(_DWORD *)(v7 + 20) = 1;
v11 = *(_QWORD **)(v5 + 8);
if ( v11 )
*v11 = v7;
v12 = i++;
arr[v12] = v1;
LODWORD(v5) = printf(
"BKR freeing block %#x merging with successor new size is %d.\n",
a1,
*(unsigned int *)(v7 + 16));
}
}
else
{
v6 = 0LL;
while ( arr[v6] != v1 )
{
if ( ++v6 == i )
goto LABEL_12;
}
LODWORD(v5) = puts("<ERROR>: Has already been freed");
}
return v5;
}

original_code:
void
my_free( void * p )
{
 struct MemEntry * ptr;
 struct MemEntry * pred;
 struct MemEntry * succ;
 ptr = (struct MemEntry *)((char *)p - sizeof(struct MemEntry));
    struct MemEntry *temp = root;
    while (root != 0) {
        if (ptr == root) {
            break;
        }
        root = root->succ;
        if(root == 0){
            printf("<ERROR>: Has not been malloc or freed already\n");
            root = temp;
            return;
        }
    }
    int j;
    for (j = 0; j < i; j++) {
        if (ptr == arr[j]) {
            printf("<ERROR>: Has already been freed\n");
            return;
        }
    }
    root = temp;
 if ( (pred = ptr->prev) != 0 && pred->isfree )
 {
  pred->size += sizeof(struct MemEntry) + ptr->size;
  pred->succ = ptr->succ;
  ptr->isfree=1;
  pred->succ = ptr->succ;
  if(ptr->succ != 0)
   ptr->succ->prev = pred;
  printf( "BKR freeing block %#x merging with predecessor new size is %d.\n", p, pred->size );
 }
 else
 {
  printf( "BKR freeing block %#x.\n", p );
        arr[i++] = ptr;
  ptr->isfree = 1;
  pred = ptr;
 }
 if ( (succ = ptr->succ) != 0 && succ->isfree )
 {
  pred->size += sizeof(struct MemEntry) + succ->size;
  pred->succ = succ->succ;
  pred->isfree = 1;
  if(succ->succ != 0)
   succ->succ->prev=pred;
        arr[i++] = ptr;
  printf( "BKR freeing block %#x merging with successor new size is %d.\n", p, pred->size );
 }
}

canonical_original_code:
void my_free(void *p)
{
 struct MemEntry *ptr;
 struct MemEntry *pred;
 struct MemEntry *succ;
 ptr = (struct MemEntry *)((char *)p - sizeof(struct MemEntry));
    struct MemEntry *temp = root;
    while (root != 0) {
        if (ptr == root) {
            break;
        }
        root = root->succ;
        if(root == 0){
            printf("<ERROR>: Has not been malloc or freed already\n");
            root = temp;
            return;
        }
    }
    int j;
    for (j = 0; j < i; j++) {
        if (ptr == arr[j]) {
            printf("<ERROR>: Has already been freed\n");
            return;
        }
    }
    root = temp;
 if ( (pred = ptr->prev) != 0 && pred->isfree )
 {
  pred->size += sizeof(struct MemEntry) + ptr->size;
  pred->succ = ptr->succ;
  ptr->isfree=1;
  pred->succ = ptr->succ;
  if(ptr->succ != 0)
   ptr->succ->prev = pred;
  printf( "BKR freeing block %#x merging with predecessor new size is %d.\n", p, pred->size );
 }
 else
 {
  printf( "BKR freeing block %#x.\n", p );
        arr[i++] = ptr;
  ptr->isfree = 1;
  pred = ptr;
 }
 if ( (succ = ptr->succ) != 0 && succ->isfree )
 {
  pred->size += sizeof(struct MemEntry) + succ->size;
  pred->succ = succ->succ;
  pred->isfree = 1;
  if(succ->succ != 0)
   succ->succ->prev=pred;
        arr[i++] = ptr;
  printf( "BKR freeing block %#x merging with successor new size is %d.\n", p, pred->size );
 }
}

variable_types:
p
void *


repo: atenart/SimpleDroidRPC

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

result = cur_method;
*(_DWORD *)(cur_method + 24) = 1;
return result;
}

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

result = cur_method;
*(_DWORD *)(cur_method + 24) = 1;
return result;
}

original_code:
void set_async () {
  cur_method->async = 1;
}

canonical_original_code:
void set_async() {
  cur_method->async = 1;
}


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

result = cur_method;
*(_QWORD *)(cur_method + 16) = a1;
return result;
}

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

result = cur_method;
*(_QWORD *)(cur_method + 16) = a1;
return result;
}

original_code:
void set_return (char* type) {
  cur_method->ret_type = type;
}

canonical_original_code:
void set_return(char *type) {
  cur_method->ret_type = type;
}

variable_types:
type
char *


LoadTheme

repo: atextor/blockmaster

decompiled_code:
__int64 __fastcall LoadTheme(const char *a1)
{
__int64 i; // rbx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 j; // rbx
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 k; // rbx
__int64 result; // rax
__int64 v13; // rax
__int64 v14; // rax
char v15[21]; // [rsp+6h] [rbp-F2h] BYREF
char v16[9]; // [rsp+1Bh] [rbp-DDh] BYREF
char v17[12]; // [rsp+24h] [rbp-D4h] BYREF
char v18[86]; // [rsp+30h] [rbp-C8h] BYREF
char v19[20]; // [rsp+86h] [rbp-72h] BYREF
char v20[6]; // [rsp+9Ah] [rbp-5Eh] BYREF
char v21[88]; // [rsp+A0h] [rbp-58h] BYREF

strcpy(v21, "00010202030405060708091011121314151617181920212223");
strcpy(v20, "01234");
strcpy(&v19[14], "01234");
strcpy(&v19[11], "01");
strcpy(v19, "abcdefghij");
strcpy(v17, "blockXX.bmp");
strcpy(v16, "guyX.bmp");
strcpy(&v15[11], "menuX.bmp");
strcpy(v15, "aniXXY.bmp");
printf(" Loading Theme %s...\n", a1);
for ( i = 0LL; i != 50; i += 2LL )
{
v17[5] = v21[i];
v17[6] = v21[i + 1];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, v17);
v2 = SDL_RWFromFile(v18, "rb");
v3 = SDL_LoadBMP_RW(v2, 1LL);
*(_QWORD *)((char *)&block + 4 * i) = v3;
if ( !v3 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(*(_QWORD *)((char *)&block + 4 * i), 4096LL, 0LL);
}
*(_WORD *)&v15[3] = *(_WORD *)&v19[11];
if ( SLODWORD(animation[10]) > 0 )
{
v4 = 0LL;
do
{
v15[5] = v19[v4];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, v15);
v5 = SDL_RWFromFile(v18, "rb");
v6 = SDL_LoadBMP_RW(v5, 1LL);
animation[v4] = v6;
if ( !v6 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(animation[v4], 4096LL, 0LL);
SDL_SetAlpha(animation[v4++], &unk_10000, 100LL);
}
while ( SLODWORD(animation[10]) > (int)v4 );
}
for ( j = 0LL; j != 5; ++j )
{
v16[3] = v20[j];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, v16);
v8 = SDL_RWFromFile(v18, "rb");
v9 = SDL_LoadBMP_RW(v8, 1LL);
characters[j] = v9;
if ( !v9 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(characters[j], 4096LL, 0LL);
}
SDL_SetAlpha(characters[4], &unk_10000, 15LL);
sprintf(v18, "%s%s/font.bmp", (const char *)(unsigned int)((_DWORD)&path + 510), a1);
v10 = SDL_RWFromFile(v18, "rb");
font = SDL_LoadBMP_RW(v10, 1LL);
if ( !font )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(font, 4096LL, 0LL);
InitFont(font);
for ( k = 0LL; k != 5; ++k )
{
v15[15] = v19[k + 14];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, &v15[11]);
v13 = SDL_RWFromFile(v18, "rb");
v14 = SDL_LoadBMP_RW(v13, 1LL);
*((_QWORD *)&menu + k) = v14;
if ( !v14 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
result = SDL_SetColorKey(*((_QWORD *)&menu + k), 4096LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 i; // rbx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 j; // rbx
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 k; // rbx
__int64 result; // rax
__int64 v13; // rax
__int64 v14; // rax
char v15[21]; // [rsp+6h] [rbp-F2h] BYREF
char v16[9]; // [rsp+1Bh] [rbp-DDh] BYREF
char v17[12]; // [rsp+24h] [rbp-D4h] BYREF
char v18[86]; // [rsp+30h] [rbp-C8h] BYREF
char v19[20]; // [rsp+86h] [rbp-72h] BYREF
char v20[6]; // [rsp+9Ah] [rbp-5Eh] BYREF
char v21[88]; // [rsp+A0h] [rbp-58h] BYREF

strcpy(v21, "00010202030405060708091011121314151617181920212223");
strcpy(v20, "01234");
strcpy(&v19[14], "01234");
strcpy(&v19[11], "01");
strcpy(v19, "abcdefghij");
strcpy(v17, "blockXX.bmp");
strcpy(v16, "guyX.bmp");
strcpy(&v15[11], "menuX.bmp");
strcpy(v15, "aniXXY.bmp");
printf(" Loading Theme %s...\n", a1);
for ( i = 0LL; i != 50; i += 2LL )
{
v17[5] = v21[i];
v17[6] = v21[i + 1];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, v17);
v2 = SDL_RWFromFile(v18, "rb");
v3 = SDL_LoadBMP_RW(v2, 1LL);
*(_QWORD *)((char *)&block + 4 * i) = v3;
if ( !v3 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(*(_QWORD *)((char *)&block + 4 * i), 4096LL, 0LL);
}
*(_WORD *)&v15[3] = *(_WORD *)&v19[11];
if ( SLODWORD(animation[10]) > 0 )
{
v4 = 0LL;
do
{
v15[5] = v19[v4];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, v15);
v5 = SDL_RWFromFile(v18, "rb");
v6 = SDL_LoadBMP_RW(v5, 1LL);
animation[v4] = v6;
if ( !v6 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(animation[v4], 4096LL, 0LL);
SDL_SetAlpha(animation[v4++], &unk_10000, 100LL);
}
while ( SLODWORD(animation[10]) > (int)v4 );
}
for ( j = 0LL; j != 5; ++j )
{
v16[3] = v20[j];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, v16);
v8 = SDL_RWFromFile(v18, "rb");
v9 = SDL_LoadBMP_RW(v8, 1LL);
characters[j] = v9;
if ( !v9 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(characters[j], 4096LL, 0LL);
}
SDL_SetAlpha(characters[4], &unk_10000, 15LL);
sprintf(v18, "%s%s/font.bmp", (const char *)(unsigned int)((_DWORD)&path + 510), a1);
v10 = SDL_RWFromFile(v18, "rb");
font = SDL_LoadBMP_RW(v10, 1LL);
if ( !font )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
SDL_SetColorKey(font, 4096LL, 0LL);
InitFont(font);
for ( k = 0LL; k != 5; ++k )
{
v15[15] = v19[k + 14];
sprintf(v18, "%s%s/%s", (const char *)(unsigned int)((_DWORD)&path + 510), a1, &v15[11]);
v13 = SDL_RWFromFile(v18, "rb");
v14 = SDL_LoadBMP_RW(v13, 1LL);
*((_QWORD *)&menu + k) = v14;
if ( !v14 )
{
printf("*** Loading of %s failed.\n", v18);
quit(1LL);
}
result = SDL_SetColorKey(*((_QWORD *)&menu + k), 4096LL, 0LL);
}
return result;
}

original_code:
void LoadTheme(char themename[])
{
 char blockToFile[] = "00010202030405060708091011121314151617181920212223";
 char charToFile[] = "01234";
 char menuToFile[] = "01234";
 char aniToFile[] = "01";
 char aniphaseToFile[] = "abcdefghij";
 char fullpath[80];
    char blockfilename[] = "blockXX.bmp";
 char charfilename[] = "guyX.bmp";
 char menufilename[] = "menuX.bmp";
 char anifilename[] = "aniXXY.bmp";
 int i, j;
 printf (" Loading Theme %s...\n", themename);
    for (i = 0; i<25; i++) {
  blockfilename[5] = blockToFile[(i*2)];
        blockfilename[6] = blockToFile[(i*2)+1];
  sprintf(fullpath, "%s%s/%s", path.themes, themename, blockfilename);
        block[i] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
  if (!block[i]) {
            printf ("*** Loading of %s failed.\n", fullpath);
   quit(1);
  }
  SDL_SetColorKey(block[i], 0x00001000, 0);
    }
 for (i = 0; i<1; i++) {
  anifilename[3] = aniToFile[(i*2)];
  anifilename[4] = aniToFile[(i*2)+1];
  for (j = 0; j<animation[i].numphases; j++) {
   anifilename[5] = aniphaseToFile[j];
   sprintf(fullpath, "%s%s/%s", path.themes, themename, anifilename);
   animation[i].gfx[j] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
   if (!animation[i].gfx[j]) {
    printf ("*** Loading of %s failed.\n", fullpath);
    quit(1);
   }
   SDL_SetColorKey(animation[i].gfx[j], 0x00001000, 0);
   SDL_SetAlpha(animation[0].gfx[j], 0x00010000, 100);
  }
 }
 for (i = 0; i<5; i++) {
  charfilename[3] = charToFile[i];
  sprintf(fullpath, "%s%s/%s", path.themes, themename, charfilename);
  characters[i] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
  if (!characters[i]) {
   printf("*** Loading of %s failed.\n", fullpath);
   quit(1);
  }
  SDL_SetColorKey(characters[i], 0x00001000, 0);
 }
 SDL_SetAlpha(characters[4], 0x00010000, 15);
 sprintf(fullpath, "%s%s/font.bmp", path.themes, themename);
 font[0] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
 if (!font[0]) {
  printf( "*** Loading of %s failed.\n", fullpath);
  quit(1);
 }
 SDL_SetColorKey(font[0], 0x00001000, 0);
 InitFont(font[0]);
 for (i = 0; i<5; i++) {
  menufilename[4] = menuToFile[i];
  sprintf(fullpath, "%s%s/%s", path.themes, themename, menufilename);
  menu[i] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
  if (!menu[i]) {
   printf("*** Loading of %s failed.\n", fullpath);
   quit(1);
  }
  SDL_SetColorKey(menu[i], 0x00001000, 0);
 }
}

canonical_original_code:
void LoadTheme(char themename[])
{
 char blockToFile[] = "00010202030405060708091011121314151617181920212223";
 char charToFile[] = "01234";
 char menuToFile[] = "01234";
 char aniToFile[] = "01";
 char aniphaseToFile[] = "abcdefghij";
 char fullpath[80];
    char blockfilename[] = "blockXX.bmp";
 char charfilename[] = "guyX.bmp";
 char menufilename[] = "menuX.bmp";
 char anifilename[] = "aniXXY.bmp";
 int i; int j;
 printf (" Loading Theme %s...\n", themename);
    for (i = 0; i<25; i++) {
  blockfilename[5] = blockToFile[(i*2)];
        blockfilename[6] = blockToFile[(i*2)+1];
  sprintf(fullpath, "%s%s/%s", path.themes, themename, blockfilename);
        block[i] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
  if (!block[i]) {
            printf ("*** Loading of %s failed.\n", fullpath);
   quit(1);
  }
  SDL_SetColorKey(block[i], 0x00001000, 0);
    }
 for (i = 0; i<1; i++) {
  anifilename[3] = aniToFile[(i*2)];
  anifilename[4] = aniToFile[(i*2)+1];
  for (j = 0; j<animation[i].numphases; j++) {
   anifilename[5] = aniphaseToFile[j];
   sprintf(fullpath, "%s%s/%s", path.themes, themename, anifilename);
   animation[i].gfx[j] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
   if (!animation[i].gfx[j]) {
    printf ("*** Loading of %s failed.\n", fullpath);
    quit(1);
   }
   SDL_SetColorKey(animation[i].gfx[j], 0x00001000, 0);
   SDL_SetAlpha(animation[0].gfx[j], 0x00010000, 100);
  }
 }
 for (i = 0; i<5; i++) {
  charfilename[3] = charToFile[i];
  sprintf(fullpath, "%s%s/%s", path.themes, themename, charfilename);
  characters[i] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
  if (!characters[i]) {
   printf("*** Loading of %s failed.\n", fullpath);
   quit(1);
  }
  SDL_SetColorKey(characters[i], 0x00001000, 0);
 }
 SDL_SetAlpha(characters[4], 0x00010000, 15);
 sprintf(fullpath, "%s%s/font.bmp", path.themes, themename);
 font[0] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
 if (!font[0]) {
  printf( "*** Loading of %s failed.\n", fullpath);
  quit(1);
 }
 SDL_SetColorKey(font[0], 0x00001000, 0);
 InitFont(font[0]);
 for (i = 0; i<5; i++) {
  menufilename[4] = menuToFile[i];
  sprintf(fullpath, "%s%s/%s", path.themes, themename, menufilename);
  menu[i] = SDL_LoadBMP_RW(SDL_RWFromFile(fullpath, "rb"), 1);
  if (!menu[i]) {
   printf("*** Loading of %s failed.\n", fullpath);
   quit(1);
  }
  SDL_SetColorKey(menu[i], 0x00001000, 0);
 }
}

variable_types:
themename
char []

variable_types:
blockToFile
char []

variable_types:
charToFile
char []

variable_types:
menuToFile
char []

variable_types:
aniToFile
char []

variable_types:
aniphaseToFile
char []

variable_types:
fullpath
char [80]

variable_types:
blockfilename
char []

variable_types:
charfilename
char []

variable_types:
menufilename
char []

variable_types:
anifilename
char []


removeBlock

decompiled_code:
void __fastcall removeBlock(int a1, int a2)
{
level[150 * a1 + a2] = 0;
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
level[150 * a1 + a2] = 0;
}

original_code:
void removeBlock(int x, int y)
{
 level.data[x][y] = 0;
}

variable_types: x int

variable_types: y int


takeItem

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

v2 = level[150 * a1 + a2];
if ( v2 == 14 )
{
++*(&inventory + 1);
removeBlock(a1, a2);
result = 1LL;
}
else if ( v2 > 14 )
{
if ( v2 == 15 )
{
++*(&inventory + 3);
removeBlock(a1, a2);
result = 1LL;
}
else
{
result = 0LL;
}
}
else if ( v2 == 12 )
{
++inventory;
removeBlock(a1, a2);
result = 1LL;
}
else if ( v2 == 13 )
{
++*(&inventory + 2);
removeBlock(a1, a2);
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

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

v2 = level[150 * a1 + a2];
if ( v2 == 14 )
{
++*(&inventory + 1);
func0(a1, a2);
result = 1LL;
}
else if ( v2 > 14 )
{
if ( v2 == 15 )
{
++*(&inventory + 3);
func0(a1, a2);
result = 1LL;
}
else
{
result = 0LL;
}
}
else if ( v2 == 12 )
{
++inventory;
func0(a1, a2);
result = 1LL;
}
else if ( v2 == 13 )
{
++*(&inventory + 2);
func0(a1, a2);
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int takeItem(int x, int y)
{
 switch ( level.data[x][y] )
 {
  case 12:
   inventory.redKeys++;
   removeBlock(x, y);
   break;
  case 13:
   inventory.greenKeys++;
   removeBlock(x, y);
   break;
  case 14:
   inventory.blueKeys++;
   removeBlock(x, y);
   break;
  case 15:
   inventory.yellowKeys++;
   removeBlock(x, y);
   break;
  default:
   return 0;
   break;
 }
 return 1;
}


hasBlockBit

decompiled_code:
__int64 __fastcall hasBlockBit(__int64 a1, __int64 a2, int a3)
{
int v4; // ebx

switch ( level[150 * (int)a1 + (int)a2] )
{
case 0:
v4 = a3 == 8 || a3 == 1;
break;
case 2:
v4 = a3 == 8 || a3 == 1;
break;
case 3:
v4 = a3 == 1;
break;
case 4:
v4 = a3 == 8 || a3 == 1;
break;
case 5:
v4 = a3 == 8 || a3 == 1;
break;
case 6:
v4 = a3 == 8 || a3 == 1;
break;
case 7:
v4 = a3 == 8 || a3 == 1;
break;
case 8:
v4 = ((a3 - 8) & 0xFFFFFFF7) == 0;
break;
case 9:
v4 = player[5 * chosenGuy + 2];
if ( v4 == 2 )
{
v4 = 0;
if ( (unsigned int)hasBlockBit(a1, (unsigned int)(a2 - 1), 8LL) == 1 )
v4 = (unsigned int)(a3 - 1) <= 1;
}
else if ( v4 > 2 )
{
if ( v4 == 3 )
{
v4 = 0;
if ( (unsigned int)hasBlockBit((unsigned int)(a1 - 1), a2, 8LL) == 1 )
v4 = (unsigned int)(a3 - 1) <= 1;
}
else
{
v4 = 0;
}
}
else if ( v4 )
{
if ( v4 == 1 )
{
v4 = 0;
if ( (unsigned int)hasBlockBit((unsigned int)(a1 + 1), a2, 8LL) == 1 )
v4 = (unsigned int)(a3 - 1) <= 1;
}
else
{
v4 = 0;
}
}
else if ( (unsigned int)hasBlockBit(a1, (unsigned int)(a2 + 1), 8LL) == 1 )
{
v4 = (unsigned int)(a3 - 1) <= 1;
}
break;
case 10:
v4 = a3 == 8 || a3 == 1;
break;
case 11:
v4 = a3 == 1;
break;
case 12:
v4 = a3 == 4 || a3 == 1;
break;
case 13:
v4 = a3 == 4 || a3 == 1;
break;
case 14:
v4 = a3 == 4 || a3 == 1;
break;
case 15:
v4 = a3 == 4 || a3 == 1;
break;
case 16:
v4 = 0;
if ( inventory > 0 )
v4 = a3 == 32 || a3 == 1;
break;
case 17:
v4 = 0;
if ( *(&inventory + 2) > 0 )
v4 = a3 == 32 || a3 == 1;
break;
case 18:
v4 = 0;
if ( *(&inventory + 1) > 0 )
v4 = a3 == 32 || a3 == 1;
break;
case 19:
v4 = 0;
if ( *(&inventory + 3) > 0 )
v4 = a3 == 32 || a3 == 1;
break;
case 20:
v4 = a3 == 8 || a3 == 1;
break;
case 21:
v4 = 0;
if ( toggleBlocks == 1 )
v4 = a3 == 8 || a3 == 1;
break;
case 22:
v4 = 0;
if ( !toggleBlocks )
v4 = a3 == 8 || a3 == 1;
break;
case 23:
if ( *(&inventory + 4) <= 0 )
v4 = ((a3 - 8) & 0xFFFFFFF7) == 0;
else
v4 = a3 == 1 || ((a3 - 8) & 0xFFFFFFF7) == 0;
break;
case 24:
v4 = *(&inventory + 5) > 0 && a3 == 1;
break;
default:
v4 = 0;
break;
}
return (unsigned int)v4;
}

original_code:
int hasBlockBit(int x, int y, int Bit)
{
 switch( level.data[x][y] )
 {
  case 0:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 1:
   break;
  case 2:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 3:
   if (Bit == 1) return 1;
   break;
  case 4:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 5:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 6:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 7:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 8:
   if ((Bit == 8) || (Bit == 16)) return 1;
   break;
  case 9:
   switch( player[chosenGuy].direction ) {
    case 0:
     if ( hasBlockBit(x, y+1, 8) == 1)
      if ((Bit == 1) || (Bit == 2)) return 1;
     break;
    case 1:
     if ( hasBlockBit(x+1, y, 8) == 1)
      if ((Bit == 1) || (Bit == 2)) return 1;
     break;
    case 2:
     if ( hasBlockBit(x, y-1, 8) == 1)
      if ((Bit == 1) || (Bit == 2)) return 1;
     break;
    case 3:
     if ( hasBlockBit(x-1, y, 8) == 1)
      if ((Bit == 1) || (Bit == 2)) return 1;
     break;
   }
   break;
  case 10:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 11:
   if (Bit == 1) return 1;
   break;
  case 12:
   if ((Bit == 1) || (Bit == 4)) return 1;
   break;
  case 13:
   if ((Bit == 1) || (Bit == 4)) return 1;
   break;
  case 14:
   if ((Bit == 1) || (Bit == 4)) return 1;
   break;
  case 15:
   if ((Bit == 1) || (Bit == 4)) return 1;
   break;
  case 16:
   if (inventory.redKeys > 0)
    if ((Bit == 1) || (Bit == 32)) return 1;
   break;
  case 17:
   if (inventory.greenKeys > 0)
    if ((Bit == 1) || (Bit == 32)) return 1;
   break;
  case 18:
   if (inventory.blueKeys > 0)
    if ((Bit == 1) || (Bit == 32)) return 1;
   break;
  case 19:
   if (inventory.yellowKeys > 0)
    if ((Bit == 1) || (Bit == 32)) return 1;
   break;
  case 20:
   if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 21:
   if (toggleBlocks == 1)
    if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 22:
   if (toggleBlocks == 0)
    if ((Bit == 1) || (Bit == 8)) return 1;
   break;
  case 23:
   if (inventory.flippers > 0) {
    if ((Bit == 1) || (Bit == 8) ||
     (Bit == 16)) return 1;
   } else {
    if ((Bit == 8) || (Bit == 16)) return 1;
   }
   break;
  case 24:
   if (inventory.fireshoes > 0)
    if (Bit == 1) return 1;
   break;
 }
 return 0;
}

variable_types: Bit int


movePlayer

decompiled_code:
__int64 __fastcall movePlayer(int a1, int a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
unsigned int v4; // er13
unsigned int v5; // er14
int v6; // er13
int v7; // er13
int v8; // er14
int v9; // er15
__int64 result; // rax
int v11; // er14

if ( a2 == 2 )
{
v3 = player[5 * a1];
v8 = player[5 * a1 + 1];
v2 = v8 - 1;
v5 = v8 - 2;
v4 = v3;
}
else if ( a2 > 2 )
{
if ( a2 == 3 )
{
v7 = player[5 * a1];
v3 = v7 - 1;
v2 = player[5 * a1 + 1];
v4 = v7 - 2;
v5 = v2;
}
}
else if ( a2 )
{
if ( a2 == 1 )
{
v6 = player[5 * a1];
v3 = v6 + 1;
v2 = player[5 * a1 + 1];
v4 = v6 + 2;
v5 = v2;
}
}
else
{
v3 = player[5 * a1];
v11 = player[5 * a1 + 1];
v2 = v11 + 1;
v5 = v11 + 2;
v4 = v3;
}
v9 = level[150 * v3 + v2];
if ( (unsigned int)hasBlockBit(v3, v2, 4) )
takeItem(v3, v2);
if ( (unsigned int)hasBlockBit(v3, v2, 2) )
{
if ( (unsigned int)hasBlockBit(v4, v5, 16) )
{
removeBlock(v4, v5);
removeBlock(v3, v2);
}
else if ( (unsigned int)hasBlockBit(v4, v5, 8) )
{
level[150 * v4 + v5] = level[150 * v3 + v2];
removeBlock(v3, v2);
addActivity(v3, v2, 0LL);
}
}
if ( (unsigned int)(level[150 * v3 + v2] - 4) <= 3 )
addActivity(v3, v2, 1LL);
switch ( v9 )
{
case 16:
--inventory;
removeBlock(v3, v2);
break;
case 17:
--*(&inventory + 2);
removeBlock(v3, v2);
break;
case 18:
--*(&inventory + 1);
removeBlock(v3, v2);
goto LABEL_20;
case 19:
--*(&inventory + 3);
removeBlock(v3, v2);
goto LABEL_20;
}
if ( v9 == 20 )
toggleBlocks = toggleBlocks == 0;
LABEL_20:
result = hasBlockBit(v3, v2, 1);
if ( (_DWORD)result )
{
result = 5LL * a1;
player[result] = v3;
player[result + 1] = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
unsigned int v4; // er13
unsigned int v5; // er14
int v6; // er13
int v7; // er13
int v8; // er14
int v9; // er15
__int64 result; // rax
int v11; // er14

if ( a2 == 2 )
{
v3 = player[5 * a1];
v8 = player[5 * a1 + 1];
v2 = v8 - 1;
v5 = v8 - 2;
v4 = v3;
}
else if ( a2 > 2 )
{
if ( a2 == 3 )
{
v7 = player[5 * a1];
v3 = v7 - 1;
v2 = player[5 * a1 + 1];
v4 = v7 - 2;
v5 = v2;
}
}
else if ( a2 )
{
if ( a2 == 1 )
{
v6 = player[5 * a1];
v3 = v6 + 1;
v2 = player[5 * a1 + 1];
v4 = v6 + 2;
v5 = v2;
}
}
else
{
v3 = player[5 * a1];
v11 = player[5 * a1 + 1];
v2 = v11 + 1;
v5 = v11 + 2;
v4 = v3;
}
v9 = level[150 * v3 + v2];
if ( (unsigned int)func2(v3, v2, 4) )
func1(v3, v2);
if ( (unsigned int)func2(v3, v2, 2) )
{
if ( (unsigned int)func2(v4, v5, 16) )
{
func0(v4, v5);
func0(v3, v2);
}
else if ( (unsigned int)func2(v4, v5, 8) )
{
level[150 * v4 + v5] = level[150 * v3 + v2];
func0(v3, v2);
addActivity(v3, v2, 0LL);
}
}
if ( (unsigned int)(level[150 * v3 + v2] - 4) <= 3 )
addActivity(v3, v2, 1LL);
switch ( v9 )
{
case 16:
--inventory;
func0(v3, v2);
break;
case 17:
--*(&inventory + 2);
func0(v3, v2);
break;
case 18:
--*(&inventory + 1);
func0(v3, v2);
goto LABEL_20;
case 19:
--*(&inventory + 3);
func0(v3, v2);
goto LABEL_20;
}
if ( v9 == 20 )
toggleBlocks = toggleBlocks == 0;
LABEL_20:
result = func2(v3, v2, 1);
if ( (_DWORD)result )
{
result = 5LL * a1;
player[result] = v3;
player[result + 1] = v2;
}
return result;
}

original_code:
void movePlayer(int whichPlayer, int direction)
{
 int targetBlock, targetX, targetY, targetX2, targetY2;
 switch ( direction )
 {
  case 2:
   targetX = player[whichPlayer].coord_x;
   targetY = player[whichPlayer].coord_y - 1;
   targetX2 = player[whichPlayer].coord_x;
   targetY2 = player[whichPlayer].coord_y - 2;
   break;
  case 0:
   targetX = player[whichPlayer].coord_x;
   targetY = player[whichPlayer].coord_y + 1;
   targetX2 = player[whichPlayer].coord_x;
   targetY2 = player[whichPlayer].coord_y + 2;
   break;
  case 3:
   targetX = player[whichPlayer].coord_x - 1;
   targetY = player[whichPlayer].coord_y;
   targetX2 = player[whichPlayer].coord_x - 2;
   targetY2 = player[whichPlayer].coord_y;
   break;
  case 1:
   targetX = player[whichPlayer].coord_x + 1;
   targetY = player[whichPlayer].coord_y;
   targetX2 = player[whichPlayer].coord_x + 2;
   targetY2 = player[whichPlayer].coord_y;
   break;
 }
 targetBlock = level.data[targetX][targetY];
 if ( hasBlockBit(targetX, targetY, 4) ) {
  takeItem(targetX, targetY);
 }
 if ( hasBlockBit(targetX, targetY, 2) ) {
  if ( hasBlockBit(targetX2, targetY2, 16) ) {
   removeBlock(targetX2, targetY2);
   removeBlock(targetX, targetY);
  } else if ( hasBlockBit(targetX2, targetY2, 8) ) {
   level.data[targetX2][targetY2] = level.data[targetX][targetY];
   removeBlock(targetX, targetY);
   addActivity(targetX, targetY, 0);
  }
 }
 if ( (level.data[targetX][targetY] == 5) ||
   (level.data[targetX][targetY] == 7) ||
   (level.data[targetX][targetY] == 6) ||
   (level.data[targetX][targetY] == 4)) {
  addActivity(targetX, targetY, 1);
 }
 if (targetBlock == 16) {
  inventory.redKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 17) {
  inventory.greenKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 18) {
  inventory.blueKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 19) {
  inventory.yellowKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 20) {
  toggleBlocks = !toggleBlocks;
 }
 if ( hasBlockBit(targetX, targetY, 1) ) {
  player[whichPlayer].coord_x = targetX;
  player[whichPlayer].coord_y = targetY;
 }
 return;
}

canonical_original_code:
void movePlayer(int whichPlayer, int direction)
{
 int targetBlock; int targetX; int targetY; int targetX2; int targetY2;
 switch ( direction )
 {
  case 2:
   targetX = player[whichPlayer].coord_x;
   targetY = player[whichPlayer].coord_y - 1;
   targetX2 = player[whichPlayer].coord_x;
   targetY2 = player[whichPlayer].coord_y - 2;
   break;
  case 0:
   targetX = player[whichPlayer].coord_x;
   targetY = player[whichPlayer].coord_y + 1;
   targetX2 = player[whichPlayer].coord_x;
   targetY2 = player[whichPlayer].coord_y + 2;
   break;
  case 3:
   targetX = player[whichPlayer].coord_x - 1;
   targetY = player[whichPlayer].coord_y;
   targetX2 = player[whichPlayer].coord_x - 2;
   targetY2 = player[whichPlayer].coord_y;
   break;
  case 1:
   targetX = player[whichPlayer].coord_x + 1;
   targetY = player[whichPlayer].coord_y;
   targetX2 = player[whichPlayer].coord_x + 2;
   targetY2 = player[whichPlayer].coord_y;
   break;
 }
 targetBlock = level.data[targetX][targetY];
 if ( hasBlockBit(targetX, targetY, 4) ) {
  takeItem(targetX, targetY);
 }
 if ( hasBlockBit(targetX, targetY, 2) ) {
  if ( hasBlockBit(targetX2, targetY2, 16) ) {
   removeBlock(targetX2, targetY2);
   removeBlock(targetX, targetY);
  } else if ( hasBlockBit(targetX2, targetY2, 8) ) {
   level.data[targetX2][targetY2] = level.data[targetX][targetY];
   removeBlock(targetX, targetY);
   addActivity(targetX, targetY, 0);
  }
 }
 if ( (level.data[targetX][targetY] == 5) ||
   (level.data[targetX][targetY] == 7) ||
   (level.data[targetX][targetY] == 6) ||
   (level.data[targetX][targetY] == 4)) {
  addActivity(targetX, targetY, 1);
 }
 if (targetBlock == 16) {
  inventory.redKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 17) {
  inventory.greenKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 18) {
  inventory.blueKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 19) {
  inventory.yellowKeys--;
  removeBlock(targetX, targetY);
 }
 if (targetBlock == 20) {
  toggleBlocks = !toggleBlocks;
 }
 if ( hasBlockBit(targetX, targetY, 1) ) {
  player[whichPlayer].coord_x = targetX;
  player[whichPlayer].coord_y = targetY;
 }
 return;
}

variable_types: whichPlayer int

variable_types: direction int

variable_types: targetBlock int

variable_types: targetX int

variable_types: targetY int


quit

decompiled_code:
void __fastcall __noreturn quit(int status)
{
puts("Quitting...");
SDL_Quit();
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
puts("Quitting...");
SDL_Quit();
exit(status);
}

original_code:
void quit(int ret_val)
{
    printf ("Quitting...\n");
    SDL_Quit();
    exit(ret_val);
}


addActivity

decompiled_code:
void addActivity()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void addActivity(int x, int y, int activityType)
{
 switch (activityType) {
  case 0:
   break;
  case 1:
   break;
  default:
   break;
 }
 return;
}

variable_types: activityType int


ConfigSetting

decompiled_code:
int __fastcall ConfigSetting(char *s, char *src, unsigned int a3)
{
int result; // eax
size_t i; // rbp
char sa[50]; // [rsp+6h] [rbp-32h] BYREF

if ( a3 == -1 && *s == 45 )
{
for ( i = 0LL; strlen(s) > i; ++i )
s[i] = s[i + 1];
}
if ( !strcmp(s, "vid_fullscreen") )
{
vid = atoi(src);
result = printf("Setting Fullscreen to %s\n", src);
}
else if ( !strcmp(s, "path_data") )
{
strcpy(path, src);
printf("Setting Datapath to %s\n", src);
result = sprintf((char *)(unsigned int)((_DWORD)path + 255), "%s%s", path, "levels/");
}
else if ( a3 == -1 )
{
result = printf("*** Unrecognized Option: '%s' at commandline", s);
}
else
{
sprintf(sa, "%d", a3);
result = printf("*** Unrecognized Option: '%s' in configfile at line %s ", s, sa);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s, char *src, unsigned int a3)
{
int result; // eax
size_t i; // rbp
char sa[50]; // [rsp+6h] [rbp-32h] BYREF

if ( a3 == -1 && *s == 45 )
{
for ( i = 0LL; strlen(s) > i; ++i )
s[i] = s[i + 1];
}
if ( !strcmp(s, "vid_fullscreen") )
{
vid = atoi(src);
result = printf("Setting Fullscreen to %s\n", src);
}
else if ( !strcmp(s, "path_data") )
{
strcpy(path, src);
printf("Setting Datapath to %s\n", src);
result = sprintf((char *)(unsigned int)((_DWORD)path + 255), "%s%s", path, "levels/");
}
else if ( a3 == -1 )
{
result = printf("*** Unrecognized Option: '%s' at commandline", s);
}
else
{
sprintf(sa, "%d", a3);
result = printf("*** Unrecognized Option: '%s' in configfile at line %s ", s, sa);
}
return result;
}

original_code:
void ConfigSetting(char *setting, char *param, int line)
{
    int i;
    char string[10];
    if (line == -1)
        if (*setting == '-') for (i=0; i<(strlen(setting)); i++) setting[i]=setting[i+1];
   if ( strcmp(setting, "vid_fullscreen") == 0) {
        vid.fullscreen = atoi(param);
        printf ("Setting Fullscreen to %s\n", param);
    }
    else if ( strcmp(setting, "path_data") == 0) {
        strcpy(path.data, param);
        printf ("Setting Datapath to %s\n", param);
  sprintf(path.levels, "%s%s", path.data, "levels/");
    }
    else {
        if (line != -1) {
            sprintf(string,"%d",line);
            printf ("*** Unrecognized Option: '%s' in configfile at line %s ", setting, string);
        } else
            printf ("*** Unrecognized Option: '%s' at commandline", setting);
    }
}

variable_types:
setting
char *

variable_types:
param
char *

variable_types: line int

variable_types: i int

variable_types:
string
char [10]


LevelInfo

decompiled_code:
int __fastcall LevelInfo(char *s1, char *src)
{
int v2; // eax
int result; // eax
int v4; // ebx
char nptr[10]; // [rsp+Ch] [rbp-2Ch] BYREF
char s[34]; // [rsp+16h] [rbp-22h] BYREF

if ( !strcmp(s1, "requiredversion") )
{
sprintf(s, "%d%d%d", 0LL, 0LL, 0LL);
sprintf(nptr, "%c%c%c", (unsigned int)*src, (unsigned int)src[2], (unsigned int)src[3]);
v4 = atoi(s);
if ( v4 < atoi(nptr) )
{
printf("*** Engine Version too old. This Level requires a newer Version: %s\n", src);
quit(1LL);
}
result = printf(" Required Version: %s\n", src);
}
else if ( !strcmp(s1, "authorname") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90088), src);
result = printf(" Author: %s\n", src);
}
else if ( !strcmp(s1, "levelname") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90008), src);
result = printf(" Levelname: %s\n", src);
}
else if ( !strcmp(s1, "shortdesc") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90168), src);
result = printf(" Description: %s\n", src);
}
else if ( !strcmp(s1, "difficulty") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90423), src);
result = printf(" Difficulty: %s\n", src);
}
else if ( !strcmp(s1, "playercount") )
{
v2 = atoi(src);
if ( (unsigned int)(v2 - 1) > 2 )
{
playerCount = 1;
printf("*** Playercount out of range (setting to 1)");
}
else
{
playerCount = v2;
}
result = printf(" Number of Players: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_x1") )
{
player = atoi(src);
result = printf(" Player 1 Start X: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_x2") )
{
*(&player + 5) = atoi(src);
result = printf(" Player 2 Start X: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_x3") )
{
*(&player + 10) = atoi(src);
result = printf(" Player 3 Start X: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_y1") )
{
*(&player + 1) = atoi(src);
result = printf(" Player 1 Start Y: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_y2") )
{
*(&player + 6) = atoi(src);
result = printf(" Player 2 Start Y: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_y3") )
{
*(&player + 11) = atoi(src);
result = printf(" Player 3 Start Y: %s\n", src);
}
else if ( !strcmp(s1, "playerdirection_1") )
{
*(&player + 2) = atoi(src);
result = printf(" Player 1 Direction: %s\n", src);
}
else if ( !strcmp(s1, "playerdirection_2") )
{
*(&player + 7) = atoi(src);
result = printf(" Player 2 Direction: %s\n", src);
}
else if ( !strcmp(s1, "playerdirection_3") )
{
*(&player + 12) = atoi(src);
result = printf(" Player 3 Direction: %s\n", src);
}
else if ( !strcmp(s1, "message1") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90583), src);
result = printf(" Message 1: %s\n", src);
}
else if ( !strcmp(s1, "message2") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90838), src);
result = printf(" Message 2: %s\n", src);
}
else if ( !strcmp(s1, "message3") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 91093), src);
result = printf(" Message 3: %s\n", src);
}
else if ( !strcmp(s1, "message4") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 91348), src);
result = printf(" Message 4: %s\n", src);
}
else if ( !strcmp(s1, "message5") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 91603), src);
result = printf(" Message 5: %s\n", src);
}
else if ( !strcmp(s1, "theme") )
{
result = (unsigned int)strcpy((char *)(unsigned int)((_DWORD)level + 90503), src);
}
else
{
result = printf("*** Unrecognized Levelinfo: %s\n", s1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s1, char *src)
{
int v2; // eax
int result; // eax
int v4; // ebx
char nptr[10]; // [rsp+Ch] [rbp-2Ch] BYREF
char s[34]; // [rsp+16h] [rbp-22h] BYREF

if ( !strcmp(s1, "requiredversion") )
{
sprintf(s, "%d%d%d", 0LL, 0LL, 0LL);
sprintf(nptr, "%c%c%c", (unsigned int)*src, (unsigned int)src[2], (unsigned int)src[3]);
v4 = atoi(s);
if ( v4 < atoi(nptr) )
{
printf("*** Engine Version too old. This Level requires a newer Version: %s\n", src);
quit(1LL);
}
result = printf(" Required Version: %s\n", src);
}
else if ( !strcmp(s1, "authorname") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90088), src);
result = printf(" Author: %s\n", src);
}
else if ( !strcmp(s1, "levelname") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90008), src);
result = printf(" Levelname: %s\n", src);
}
else if ( !strcmp(s1, "shortdesc") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90168), src);
result = printf(" Description: %s\n", src);
}
else if ( !strcmp(s1, "difficulty") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90423), src);
result = printf(" Difficulty: %s\n", src);
}
else if ( !strcmp(s1, "playercount") )
{
v2 = atoi(src);
if ( (unsigned int)(v2 - 1) > 2 )
{
playerCount = 1;
printf("*** Playercount out of range (setting to 1)");
}
else
{
playerCount = v2;
}
result = printf(" Number of Players: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_x1") )
{
player = atoi(src);
result = printf(" Player 1 Start X: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_x2") )
{
*(&player + 5) = atoi(src);
result = printf(" Player 2 Start X: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_x3") )
{
*(&player + 10) = atoi(src);
result = printf(" Player 3 Start X: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_y1") )
{
*(&player + 1) = atoi(src);
result = printf(" Player 1 Start Y: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_y2") )
{
*(&player + 6) = atoi(src);
result = printf(" Player 2 Start Y: %s\n", src);
}
else if ( !strcmp(s1, "playerstart_y3") )
{
*(&player + 11) = atoi(src);
result = printf(" Player 3 Start Y: %s\n", src);
}
else if ( !strcmp(s1, "playerdirection_1") )
{
*(&player + 2) = atoi(src);
result = printf(" Player 1 Direction: %s\n", src);
}
else if ( !strcmp(s1, "playerdirection_2") )
{
*(&player + 7) = atoi(src);
result = printf(" Player 2 Direction: %s\n", src);
}
else if ( !strcmp(s1, "playerdirection_3") )
{
*(&player + 12) = atoi(src);
result = printf(" Player 3 Direction: %s\n", src);
}
else if ( !strcmp(s1, "message1") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90583), src);
result = printf(" Message 1: %s\n", src);
}
else if ( !strcmp(s1, "message2") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 90838), src);
result = printf(" Message 2: %s\n", src);
}
else if ( !strcmp(s1, "message3") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 91093), src);
result = printf(" Message 3: %s\n", src);
}
else if ( !strcmp(s1, "message4") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 91348), src);
result = printf(" Message 4: %s\n", src);
}
else if ( !strcmp(s1, "message5") )
{
strcpy((char *)(unsigned int)((_DWORD)level + 91603), src);
result = printf(" Message 5: %s\n", src);
}
else if ( !strcmp(s1, "theme") )
{
result = (unsigned int)strcpy((char *)(unsigned int)((_DWORD)level + 90503), src);
}
else
{
result = printf("*** Unrecognized Levelinfo: %s\n", s1);
}
return result;
}

original_code:
void LevelInfo(char *info, char *param)
{
    char string1[10];
    char string2[10];
   if ( strcmp(info, "requiredversion") == 0) {
        sprintf(string1, "%d%d%d", 0, 0, 0);
        sprintf(string2, "%c%c%c", param[0], param[2], param[3]);
        if (atoi(string1) < atoi(string2)) {
            printf ("*** Engine Version too old. This Level requires a newer Version: %s\n", param);
            quit(1);
        }
        printf (" Required Version: %s\n", param);
    } else if ( strcmp(info, "authorname") == 0) {
        strcpy(level.author, param);
        printf (" Author: %s\n", param);
    } else if ( strcmp(info, "levelname") == 0) {
        strcpy(level.title, param);
        printf (" Levelname: %s\n", param);
    } else if ( strcmp(info, "shortdesc") == 0) {
        strcpy(level.desc, param);
        printf (" Description: %s\n", param);
    } else if ( strcmp(info, "difficulty") == 0) {
        strcpy(level.difficulty, param);
        printf (" Difficulty: %s\n", param);
    }
 else if ( strcmp(info, "playercount") == 0) {
        playerCount = atoi(param);
  if ((playerCount > 3) || (playerCount < 1)) {
   playerCount = 1;
   printf ("*** Playercount out of range (setting to 1)");
  }
        printf(" Number of Players: %s\n", param);
    } else if ( strcmp(info, "playerstart_x1") == 0) {
        player[0].coord_x = atoi(param);
        printf(" Player 1 Start X: %s\n", param);
    } else if ( strcmp(info, "playerstart_x2") == 0) {
        player[1].coord_x = atoi(param);
        printf(" Player 2 Start X: %s\n", param);
    } else if ( strcmp(info, "playerstart_x3") == 0) {
        player[2].coord_x = atoi(param);
        printf(" Player 3 Start X: %s\n", param);
    } else if ( strcmp(info, "playerstart_y1") == 0) {
        player[0].coord_y = atoi(param);
        printf(" Player 1 Start Y: %s\n", param);
    } else if ( strcmp(info, "playerstart_y2") == 0) {
        player[1].coord_y = atoi(param);
        printf(" Player 2 Start Y: %s\n", param);
    } else if ( strcmp(info, "playerstart_y3") == 0) {
        player[2].coord_y = atoi(param);
        printf(" Player 3 Start Y: %s\n", param);
 } else if ( strcmp(info, "playerdirection_1") == 0) {
  player[0].direction = atoi(param);
  printf(" Player 1 Direction: %s\n", param);
 } else if ( strcmp(info, "playerdirection_2") == 0) {
  player[1].direction = atoi(param);
  printf(" Player 2 Direction: %s\n", param);
 } else if ( strcmp(info, "playerdirection_3") == 0) {
  player[2].direction = atoi(param);
  printf(" Player 3 Direction: %s\n", param);
    }
    else if ( strcmp(info, "message1") == 0) {
        strcpy(level.message1, param);
        printf(" Message 1: %s\n", param);
    } else if ( strcmp(info, "message2") == 0) {
        strcpy(level.message2, param);
        printf(" Message 2: %s\n", param);
    } else if ( strcmp(info, "message3") == 0) {
        strcpy(level.message3, param);
        printf(" Message 3: %s\n", param);
    } else if ( strcmp(info, "message4") == 0) {
        strcpy(level.message4, param);
        printf(" Message 4: %s\n", param);
    } else if ( strcmp(info, "message5") == 0) {
        strcpy(level.message5, param);
        printf(" Message 5: %s\n", param);
    }
    else if ( strcmp(info, "theme") == 0) {
  strcpy(level.theme, param);
    }
    else {
        printf ("*** Unrecognized Levelinfo: %s\n", info);
    }
}

variable_types:
info
char *


RenderLevel

decompiled_code:
__int64 RenderLevel()
{
int v0; // er14
int v1; // edx
int v2; // ecx
int v3; // ecx
int *v4; // rbx
int v5; // ebp
int v6; // ecx
__int64 v7; // r12
int v8; // edx
int v9; // er13
__int64 result; // rax
int v11; // [rsp+14h] [rbp-54h]
__int64 v12; // [rsp+18h] [rbp-50h]
int v13; // [rsp+24h] [rbp-44h]
int v14; // [rsp+28h] [rbp-40h]
int v15; // [rsp+2Ch] [rbp-3Ch]

beginX = player[5 * chosenGuy] - viewX / 2;
v0 = viewY;
beginY = player[5 * chosenGuy + 1] - viewY / 2;
v15 = 0;
v11 = -1;
v14 = 0;
do
{
v9 = viewX + beginX;
if ( beginX <= viewX + beginX )
{
v13 = -22 * v9;
v12 = 150LL * v9;
while ( 1 )
{
v6 = beginY;
if ( v0 >= 0 )
break;
LABEL_39:
--v9;
v13 += 22;
v12 -= 150LL;
if ( beginX > v9 )
goto LABEL_42;
}
v7 = beginY;
while ( 1 )
{
if ( levelsizeX <= v9 || levelsizeY <= (int)v7 || v9 < 0 || (int)v7 < 0 )
{
blitMe = 0;
}
else
{
v8 = level[v7 + v12];
switch ( v8 )
{
case 22:
if ( toggleBlocks == 1 )
{
blitMe = 21;
blockHeight[21] = 1;
}
else
{
blitMe = 22;
blockHeight[22] = 0;
}
break;
case 24:
v11 = 1;
LABEL_38:
blitMe = level[v7 + v12];
break;
case 21:
if ( toggleBlocks )
{
blitMe = 22;
blockHeight[22] = 0;
}
else
{
blitMe = 21;
blockHeight[21] = 1;
}
break;
default:
goto LABEL_38;
}
}
v1 = -22 * player[5 * chosenGuy + 1] + 22 * v7 + 22 * (v9 - beginX) - viewStartX;
renderX = v1;
if ( blockHeight[blitMe] )
v2 = v13 + 22 * (v7 - v6) - viewStartY + 22 * player[5 * chosenGuy] - 25;
else
v2 = 22 * player[5 * chosenGuy] + v13 + 22 * (v7 - v6) - viewStartY;
v3 = v15 + v2;
renderY = v3;
if ( v1 <= 539 && v3 <= 479 || v1 >= -59 && v3 >= -39 )
{
if ( v11 == -1 )
{
BlitImage(*((_QWORD *)&block + blitMe), screen, v1, v3);
}
else
{
if ( *((_DWORD *)&animation + 23) == 1 )
*((_DWORD *)&animation + 21) = rand() % *((_DWORD *)&animation + 20);
BlitImage(*((_QWORD *)&animation + *((int *)&animation + 21)), screen, renderX, renderY);
v11 = -1;
}
}
if ( playerCount > 0 )
{
v4 = player;
v5 = 0;
do
{
if ( *v4 == v9 && v4[1] == (_DWORD)v7 )
{
if ( blockHeight[blitMe] )
BlitImage(characters[v4[2]], screen, renderX + 15, renderY + 5);
else
BlitImage(characters[v4[2]], screen, renderX + 15, renderY - 25);
}
++v5;
v4 += 5;
}
while ( playerCount > v5 );
}
BlitImage(characters[4], screen, 327, 193);
v6 = beginY;
if ( v0 + beginY < (int)++v7 )
goto LABEL_39;
}
}
LABEL_42:
result = (unsigned int)++v14;
v15 += 25;
}
while ( v14 != 2 );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er14
int v1; // edx
int v2; // ecx
int v3; // ecx
int *v4; // rbx
int v5; // ebp
int v6; // ecx
__int64 v7; // r12
int v8; // edx
int v9; // er13
__int64 result; // rax
int v11; // [rsp+14h] [rbp-54h]
__int64 v12; // [rsp+18h] [rbp-50h]
int v13; // [rsp+24h] [rbp-44h]
int v14; // [rsp+28h] [rbp-40h]
int v15; // [rsp+2Ch] [rbp-3Ch]

beginX = player[5 * chosenGuy] - viewX / 2;
v0 = viewY;
beginY = player[5 * chosenGuy + 1] - viewY / 2;
v15 = 0;
v11 = -1;
v14 = 0;
do
{
v9 = viewX + beginX;
if ( beginX <= viewX + beginX )
{
v13 = -22 * v9;
v12 = 150LL * v9;
while ( 1 )
{
v6 = beginY;
if ( v0 >= 0 )
break;
LABEL_39:
--v9;
v13 += 22;
v12 -= 150LL;
if ( beginX > v9 )
goto LABEL_42;
}
v7 = beginY;
while ( 1 )
{
if ( levelsizeX <= v9 || levelsizeY <= (int)v7 || v9 < 0 || (int)v7 < 0 )
{
blitMe = 0;
}
else
{
v8 = level[v7 + v12];
switch ( v8 )
{
case 22:
if ( toggleBlocks == 1 )
{
blitMe = 21;
blockHeight[21] = 1;
}
else
{
blitMe = 22;
blockHeight[22] = 0;
}
break;
case 24:
v11 = 1;
LABEL_38:
blitMe = level[v7 + v12];
break;
case 21:
if ( toggleBlocks )
{
blitMe = 22;
blockHeight[22] = 0;
}
else
{
blitMe = 21;
blockHeight[21] = 1;
}
break;
default:
goto LABEL_38;
}
}
v1 = -22 * player[5 * chosenGuy + 1] + 22 * v7 + 22 * (v9 - beginX) - viewStartX;
renderX = v1;
if ( blockHeight[blitMe] )
v2 = v13 + 22 * (v7 - v6) - viewStartY + 22 * player[5 * chosenGuy] - 25;
else
v2 = 22 * player[5 * chosenGuy] + v13 + 22 * (v7 - v6) - viewStartY;
v3 = v15 + v2;
renderY = v3;
if ( v1 <= 539 && v3 <= 479 || v1 >= -59 && v3 >= -39 )
{
if ( v11 == -1 )
{
func0(*((_QWORD *)&block + blitMe), screen, v1, v3);
}
else
{
if ( *((_DWORD *)&animation + 23) == 1 )
*((_DWORD *)&animation + 21) = rand() % *((_DWORD *)&animation + 20);
func0(*((_QWORD *)&animation + *((int *)&animation + 21)), screen, renderX, renderY);
v11 = -1;
}
}
if ( playerCount > 0 )
{
v4 = player;
v5 = 0;
do
{
if ( *v4 == v9 && v4[1] == (_DWORD)v7 )
{
if ( blockHeight[blitMe] )
func0(characters[v4[2]], screen, renderX + 15, renderY + 5);
else
func0(characters[v4[2]], screen, renderX + 15, renderY - 25);
}
++v5;
v4 += 5;
}
while ( playerCount > v5 );
}
func0(characters[4], screen, 327, 193);
v6 = beginY;
if ( v0 + beginY < (int)++v7 )
goto LABEL_39;
}
}
LABEL_42:
result = (unsigned int)++v14;
v15 += 25;
}
while ( v14 != 2 );
return result;
}

original_code:
void RenderLevel()
{
 int x, y, i, j;
 int animated = -1;
 int whichani;
 beginX = player[chosenGuy].coord_x - (viewX/2);
 beginY = player[chosenGuy].coord_y - (viewY/2);
 for (j=0; j<2; j++) {
  for (x=(viewX+beginX); x>=beginX; x--) {
   for (y=beginY; y<=(viewY+beginY); y++) {
    if ((( x <= levelsizeX-1 ) && ( y <= levelsizeY-1 )) && (( x >= 0 ) && ( y >= 0)))
     switch ( level.data[x][y] )
     {
      case 21:
       if ( toggleBlocks == 0)
       {
        blitMe = 21;
        blockHeight[blitMe] = 1;
       } else {
        blitMe = 22;
        blockHeight[blitMe] = 0;
       }
       break;
      case 22:
       if ( toggleBlocks == 1)
       {
        blitMe = 21;
        blockHeight[blitMe] = 1;
       } else {
        blitMe = 22;
        blockHeight[blitMe] = 0;
       }
       break;
      case 24:
       whichani = 0;
       animated = 1;
      default:
       blitMe = level.data[x][y];
       break;
     }
    else
     blitMe = 0;
    renderX = ((x-beginX)*22) - viewStartX + (y*22) - (player[chosenGuy].coord_y*22);
    if ( (blockHeight[blitMe] == 0))
     renderY = ((y-beginY)*22) - viewStartY - (x*22) + (player[chosenGuy].coord_x*22) + (25*j);
    else
     renderY = ((y-beginY)*22) - viewStartY - (x*22) + (player[chosenGuy].coord_x*22) - 25 + (25*j);
    if (( renderX < 540 && renderY < 480 ) || ( renderX > -60 && renderY > -40))
    {
     if ( animated == -1 )
      if (j==0)
       BlitImage(block[blitMe], screen, renderX, renderY);
      else
       BlitImage(block[blitMe], screen, renderX, renderY);
     else {
      if (animation[whichani].random == 1) animation[whichani].currentphase = rand() % animation[whichani].numphases;
      BlitImage(animation[whichani].gfx[animation[whichani].currentphase], screen, renderX, renderY);
      animated = -1;
     }
    }
    for (i=0; i<playerCount; i++) {
     if ((player[i].coord_x == x) && (player[i].coord_y == y))
     {
      if ( blockHeight[blitMe] == 0)
      {
       BlitImage(characters[player[i].direction], screen, renderX + 15, renderY - 25);
      } else {
       BlitImage(characters[player[i].direction], screen, renderX + 15, renderY + 5);
      }
     }
    }
    BlitImage(characters[4], screen, 327, 193);
   }
  }
 }
}

canonical_original_code:
void RenderLevel()
{
 int x; int y; int i; int j;
 int animated = -1;
 int whichani;
 beginX = player[chosenGuy].coord_x - (viewX/2);
 beginY = player[chosenGuy].coord_y - (viewY/2);
 for (j=0; j<2; j++) {
  for (x=(viewX+beginX); x>=beginX; x--) {
   for (y=beginY; y<=(viewY+beginY); y++) {
    if ((( x <= levelsizeX-1 ) && ( y <= levelsizeY-1 )) && (( x >= 0 ) && ( y >= 0)))
     switch ( level.data[x][y] )
     {
      case 21:
       if ( toggleBlocks == 0)
       {
        blitMe = 21;
        blockHeight[blitMe] = 1;
       } else {
        blitMe = 22;
        blockHeight[blitMe] = 0;
       }
       break;
      case 22:
       if ( toggleBlocks == 1)
       {
        blitMe = 21;
        blockHeight[blitMe] = 1;
       } else {
        blitMe = 22;
        blockHeight[blitMe] = 0;
       }
       break;
      case 24:
       whichani = 0;
       animated = 1;
      default:
       blitMe = level.data[x][y];
       break;
     }
    else
     blitMe = 0;
    renderX = ((x-beginX)*22) - viewStartX + (y*22) - (player[chosenGuy].coord_y*22);
    if ( (blockHeight[blitMe] == 0))
     renderY = ((y-beginY)*22) - viewStartY - (x*22) + (player[chosenGuy].coord_x*22) + (25*j);
    else
     renderY = ((y-beginY)*22) - viewStartY - (x*22) + (player[chosenGuy].coord_x*22) - 25 + (25*j);
    if (( renderX < 540 && renderY < 480 ) || ( renderX > -60 && renderY > -40))
    {
     if ( animated == -1 )
      if (j==0)
       BlitImage(block[blitMe], screen, renderX, renderY);
      else
       BlitImage(block[blitMe], screen, renderX, renderY);
     else {
      if (animation[whichani].random == 1) animation[whichani].currentphase = rand() % animation[whichani].numphases;
      BlitImage(animation[whichani].gfx[animation[whichani].currentphase], screen, renderX, renderY);
      animated = -1;
     }
    }
    for (i=0; i<playerCount; i++) {
     if ((player[i].coord_x == x) && (player[i].coord_y == y))
     {
      if ( blockHeight[blitMe] == 0)
      {
       BlitImage(characters[player[i].direction], screen, renderX + 15, renderY - 25);
      } else {
       BlitImage(characters[player[i].direction], screen, renderX + 15, renderY + 5);
      }
     }
    }
    BlitImage(characters[4], screen, 327, 193);
   }
  }
 }
}

variable_types: j int

variable_types: animated int

variable_types: whichani int


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

now = SDL_GetTicks();
result = 0LL;
if ( now < (unsigned int)next_time )
result = (unsigned int)(next_time - now);
return result;
}

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

now = SDL_GetTicks();
result = 0LL;
if ( now < (unsigned int)next_time )
result = (unsigned int)(next_time - now);
return result;
}

original_code:
Uint32 time_left(void)
{
 now = SDL_GetTicks();
    if(next_time <= now)
        return 0;
    else
        return next_time - now;
}

canonical_original_code:
unsigned int time_left()
{
 now = SDL_GetTicks();
    if(next_time <= now)
        return 0;
    else
        return next_time - now;
}

return_type: unsigned int


HandleAfterWalk

decompiled_code:
__int64 __fastcall HandleAfterWalk(int a1, int a2)
{
__int64 v2; // rax

v2 = a2 + 150LL * a1;
if ( level[v2] == 10 )
level[v2] = 8;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 v2; // rax

v2 = a2 + 150LL * a1;
if ( level[v2] == 10 )
level[v2] = 8;
return 1LL;
}

original_code:
int HandleAfterWalk(int x, int y)
{
 switch( level.data[x][y] )
 {
  case 10 :
   level.data[x][y] = 8;
   return 1;
   break;
  default:
   return 1;
   break;
 }
}

variable_types: x int

variable_types: y int


TextWidth

decompiled_code:
__int64 __fastcall TextWidth(char *a1)
{
return TextWidth2((__int64)InternalFont, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
return func5((__int64)InternalFont, a1);
}

original_code:
int TextWidth(char *text)
{
    return TextWidth2(&InternalFont, text);
}

variable_types:
text
char *


unitPathAddNode

repo: atextor/demon-defense

decompiled_code:
__int64 __fastcall unitPathAddNode(__int64 a1, __int16 a2, __int16 a3)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 16);
if ( (int)result < *(_DWORD *)(a1 + 20) )
{
*(_WORD *)(*(_QWORD *)a1 + 2LL * (int)result) = a2;
*(_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * *(int *)(a1 + 16)) = a3;
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 24) = result;
if ( (int)result < *(_DWORD *)(a1 + 20) )
{
result = (unsigned int)(result + 1);
*(_DWORD *)(a1 + 16) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int16 a2, __int16 a3)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 16);
if ( (int)result < *(_DWORD *)(a1 + 20) )
{
*(_WORD *)(*(_QWORD *)a1 + 2LL * (int)result) = a2;
*(_WORD *)(*(_QWORD *)(a1 + 8) + 2LL * *(int *)(a1 + 16)) = a3;
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 24) = result;
if ( (int)result < *(_DWORD *)(a1 + 20) )
{
result = (unsigned int)(result + 1);
*(_DWORD *)(a1 + 16) = result;
}
}
return result;
}

original_code:
static void unitPathAddNode(UnitPath *path, int x, int y) {
 if (path->numNodes < path->maxNodes) {
  path->xCoords[path->numNodes] = x;
  path->yCoords[path->numNodes] = y;
  path->currentPath = path->numNodes;
  if (path->numNodes < path->maxNodes) {
   path->numNodes++;
  }
 }
}

canonical_original_code:
static void unitPathAddNode(struct UnitPath *path, int x, int y) {
 if (path->numNodes < path->maxNodes) {
  path->xCoords[path->numNodes] = x;
  path->yCoords[path->numNodes] = y;
  path->currentPath = path->numNodes;
  if (path->numNodes < path->maxNodes) {
   path->numNodes++;
  }
 }
}

variable_types: struct UnitPath { unsigned short *xCoords; unsigned short *yCoords; int numNodes; int maxNodes; int currentPath; } *


lumpName

decompiled_code:
char *__fastcall lumpName(char *a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 v4; // r8
const char *v5; // rdx
__int64 v7; // rcx
bool v8; // zf
const char *v9; // rsi

v4 = a3;
v5 = (&off_7C8)[3 * a2];
switch ( (int)v4 )
{
case 1:
case 5:
sprintf(a1, "%s%c%d", v5, (unsigned int)a4, v4);
return a1;
case 2:
case 8:
v7 = (unsigned int)a4;
v8 = a2 == 5;
v9 = "%s%c8%c2";
if ( !v8 )
v9 = "%s%c2%c8";
goto LABEL_12;
case 3:
case 7:
v7 = (unsigned int)a4;
v8 = a2 == 5;
v9 = "%s%c7%c3";
if ( !v8 )
v9 = "%s%c3%c7";
goto LABEL_12;
case 4:
case 6:
v7 = (unsigned int)a4;
v8 = a2 == 5;
v9 = "%s%c6%c4";
if ( !v8 )
v9 = "%s%c4%c6";
LABEL_12:
sprintf(a1, v9, v5, v7, (unsigned int)v7);
break;
default:
return a1;
}
return a1;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 v4; // r8
const char *v5; // rdx
__int64 v7; // rcx
bool v8; // zf
const char *v9; // rsi

v4 = a3;
v5 = (&off_7C8)[3 * a2];
switch ( (int)v4 )
{
case 1:
case 5:
sprintf(a1, "%s%c%d", v5, (unsigned int)a4, v4);
return a1;
case 2:
case 8:
v7 = (unsigned int)a4;
v8 = a2 == 5;
v9 = "%s%c8%c2";
if ( !v8 )
v9 = "%s%c2%c8";
goto LABEL_12;
case 3:
case 7:
v7 = (unsigned int)a4;
v8 = a2 == 5;
v9 = "%s%c7%c3";
if ( !v8 )
v9 = "%s%c3%c7";
goto LABEL_12;
case 4:
case 6:
v7 = (unsigned int)a4;
v8 = a2 == 5;
v9 = "%s%c6%c4";
if ( !v8 )
v9 = "%s%c4%c6";
LABEL_12:
sprintf(a1, v9, v5, v7, (unsigned int)v7);
break;
default:
return a1;
}
return a1;
}

original_code:
static char *lumpName(char *buf, UnitTypes unitType, int direction,
 char frame) {
 char *unitName = unitDefinitions[unitType].lumpName;
 switch (direction) {
  case 1:
  case 5: sprintf(buf, "%s%c%d", unitName, frame, direction);
   break;
  case 2:
  case 8: sprintf(buf, unitType == LOSTSOUL ? "%s%c8%c2" : "%s%c2%c8",
    unitName, frame, frame);
   break;
  case 3:
  case 7: sprintf(buf, unitType == LOSTSOUL ? "%s%c7%c3" : "%s%c3%c7",
    unitName, frame, frame);
   break;
  case 4:
  case 6: sprintf(buf, unitType == LOSTSOUL ? "%s%c6%c4" : "%s%c4%c6",
    unitName, frame, frame);
   break;
 }
 return buf;
}

canonical_original_code:
static char *lumpName(char *buf, enum UnitTypes unitType, int direction, char frame) {
 char *unitName = unitDefinitions[unitType].lumpName;
 switch (direction) {
  case 1:
  case 5: sprintf(buf, "%s%c%d", unitName, frame, direction);
   break;
  case 2:
  case 8: sprintf(buf, unitType == LOSTSOUL ? "%s%c8%c2" : "%s%c2%c8",
    unitName, frame, frame);
   break;
  case 3:
  case 7: sprintf(buf, unitType == LOSTSOUL ? "%s%c7%c3" : "%s%c3%c7",
    unitName, frame, frame);
   break;
  case 4:
  case 6: sprintf(buf, unitType == LOSTSOUL ? "%s%c6%c4" : "%s%c4%c6",
    unitName, frame, frame);
   break;
 }
 return buf;
}

variable_types:
buf
char *

variable_types: enum UnitTypes { PLAYER=0, IMP=1, SOLDIER=2, SHOTGUNNER=3, PINKY=4, LOSTSOUL=5, CACODEMON=6, HELLKNIGHT=7, BARONOFHELL=8, ARACHNOTRON=9, CYBERDEMON=10 }

variable_types: direction int

variable_types: frame char

variable_types:
unitName
char *

return_type: char *


sgInit

decompiled_code:
__int64 __fastcall sgInit(char a1)
{
__int64 result; // rax
const char *v2; // rax
const char *v3; // rax

if ( (int)SDL_Init(32LL) < 0 )
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't initialize SDL: %s\n", v2);
result = 1LL;
}
else
{
screen = SDL_SetVideoMode(800LL, 600LL, 0LL, a1 != 0 ? 0x80000000 : 0);
if ( screen )
{
colorSource = sgCreateSurface(1u, 1u);
result = 0LL;
}
else
{
v3 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't set video mode: %s\n", v3);
result = 1LL;
}
}
return result;
}

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

if ( (int)SDL_Init(32LL) < 0 )
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't initialize SDL: %s\n", v2);
result = 1LL;
}
else
{
screen = SDL_SetVideoMode(800LL, 600LL, 0LL, a1 != 0 ? 0x80000000 : 0);
if ( screen )
{
colorSource = func0(1u, 1u);
result = 0LL;
}
else
{
v3 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't set video mode: %s\n", v3);
result = 1LL;
}
}
return result;
}

original_code:
int sgInit(_Bool fullscreen) {
 Uint32 videoflags;
 if (SDL_Init(0x00000020) < 0) {
  fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
  return 1;
 }
 videoflags = 0x00000000;
 if (fullscreen)
  videoflags |= 0x80000000;
 screen = SDL_SetVideoMode(800, 600, 0, videoflags);
 if (screen == ((void *)0)) {
  fprintf(stderr, "Couldn't set video mode: %s\n",
   SDL_GetError());
  return 1;
 }
 colorSource = sgCreateSurface(1, 1);
 return 0;
}

canonical_original_code:
int sgInit(_Bool fullscreen) {
 unsigned int videoflags;
 if (SDL_Init(0x00000020) < 0) {
  fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
  return 1;
 }
 videoflags = 0x00000000;
 if (fullscreen)
  videoflags |= 0x80000000;
 screen = SDL_SetVideoMode(800, 600, 0, videoflags);
 if (screen == ((void *)0)) {
  fprintf(stderr, "Couldn't set video mode: %s\n",
   SDL_GetError());
  return 1;
 }
 colorSource = sgCreateSurface(1, 1);
 return 0;
}

variable_types:
videoflags
unsigned int


sgCreateColor

decompiled_code:
__int64 __fastcall sgCreateColor(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
__int64 result; // rax

result = 0LL;
if ( colorSource )
result = SDL_MapRGB(*(_QWORD *)(colorSource + 8), a1, a2, a3);
return result;
}

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

result = 0LL;
if ( colorSource )
result = SDL_MapRGB(*(_QWORD *)(colorSource + 8), a1, a2, a3);
return result;
}

original_code:
Uint32 sgCreateColor(Uint8 r, Uint8 g, Uint8 b) {
 Uint32 result;
 if (colorSource != ((void *)0)) {
  result = SDL_MapRGB(colorSource->format, r, g, b);
 } else {
  result = 0;
 }
 return result;
}

canonical_original_code:
unsigned int sgCreateColor(unsigned char r, unsigned char g, unsigned char b) {
 unsigned int result;
 if (colorSource != ((void *)0)) {
  result = SDL_MapRGB(colorSource->format, r, g, b);
 } else {
  result = 0;
 }
 return result;
}

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types:
result
unsigned int


sgDrawText

decompiled_code:
int __fastcall sgDrawText(const char *a1, int a2, int a3, int a4)
{
return sgDrawUTF8Text(screen, a2, a3, a4, a1);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, int a2, int a3, int a4)
{
return func5(screen, a2, a3, a4, a1);
}

original_code:
void sgDrawText(char *text, int x, int y, Uint32 color) {
 sgDrawUTF8Text(screen, x, y, color, text);
}

canonical_original_code:
void sgDrawText(char *text, int x, int y, unsigned int color) {
 sgDrawUTF8Text(screen, x, y, color, text);
}

variable_types:
color
unsigned int


sgClearScreen

decompiled_code:
__int64 sgClearScreen()
{
return SDL_FillRect(screen, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
return SDL_FillRect(screen, 0LL, 0LL);
}

original_code:
void sgClearScreen() {
 SDL_FillRect(screen, 0, 0);
}


sgUpdateScreen

decompiled_code:
__int64 sgUpdateScreen()
{
return SDL_UpdateRect(screen, 0LL, 0LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
return SDL_UpdateRect(screen, 0LL, 0LL, 0LL, 0LL);
}

original_code:
void sgUpdateScreen() {
 SDL_UpdateRect(screen, 0, 0, 0, 0);
}


wadLumpNameToOffset

decompiled_code:
__int64 __fastcall wadLumpNameToOffset(char *src)
{
const char *v1; // r13
const char *v2; // r14
int v3; // ebx
size_t v4; // r12
char *v5; // rbx
char *v6; // rbx
char *v7; // r14

v1 = cache_2;
v2 = cache_2;
v3 = 0;
v4 = (int)strlen(src);
do
{
if ( !strncmp(v2, src, v4) )
return qword_7B0[4 * v3];
++v3;
v2 += 32;
}
while ( v3 != 5 );
do
{
v5 = (char *)v1;
v1 += 32;
strncpy(v5, v1, 8uLL);
*((_QWORD *)v5 + 2) = *((_QWORD *)v5 + 6);
*((_QWORD *)v5 + 3) = *((_QWORD *)v5 + 7);
}
while ( v1 != dest );
if ( lumpMapLength <= 0 )
{
LABEL_9:
fprintf(stderr, "Lump Name '%s' not found in WAD, aborting\n", src);
exit(1);
}
v6 = lumpMap;
v7 = &lumpMap[32 * (lumpMapLength - 1) + 32];
while ( strncmp(v6, src, v4) )
{
v6 += 32;
if ( v6 == v7 )
goto LABEL_9;
}
strncpy(dest, src, 8uLL);
qword_830 = *((_QWORD *)v6 + 2);
qword_838 = *((_QWORD *)v6 + 3);
return *((_QWORD *)v6 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
const char *v1; // r13
const char *v2; // r14
int v3; // ebx
size_t v4; // r12
char *v5; // rbx
char *v6; // rbx
char *v7; // r14

v1 = cache_2;
v2 = cache_2;
v3 = 0;
v4 = (int)strlen(src);
do
{
if ( !strncmp(v2, src, v4) )
return qword_7B0[4 * v3];
++v3;
v2 += 32;
}
while ( v3 != 5 );
do
{
v5 = (char *)v1;
v1 += 32;
strncpy(v5, v1, 8uLL);
*((_QWORD *)v5 + 2) = *((_QWORD *)v5 + 6);
*((_QWORD *)v5 + 3) = *((_QWORD *)v5 + 7);
}
while ( v1 != dest );
if ( lumpMapLength <= 0 )
{
LABEL_9:
fprintf(stderr, "Lump Name '%s' not found in WAD, aborting\n", src);
exit(1);
}
v6 = lumpMap;
v7 = &lumpMap[32 * (lumpMapLength - 1) + 32];
while ( strncmp(v6, src, v4) )
{
v6 += 32;
if ( v6 == v7 )
goto LABEL_9;
}
strncpy(dest, src, 8uLL);
qword_830 = *((_QWORD *)v6 + 2);
qword_838 = *((_QWORD *)v6 + 3);
return *((_QWORD *)v6 + 2);
}

original_code:
static long wadLumpNameToOffset(char *lumpName) {
 int i;
 int stringLength;
 static LumpMap cache[5];
 stringLength = strlen(lumpName);
 for (i = 0; i < 5; i++) {
  if (strncmp(cache[i].lumpName, lumpName, stringLength) == 0) {
   return cache[i].lumpOffset;
  }
 }
 for (i = 0; i < 5 - 1; i++) {
  strncpy(cache[i].lumpName, cache[i + 1].lumpName, 8);
  cache[i].lumpOffset = cache[i + 1].lumpOffset;
  cache[i].lumpSize = cache[i + 1].lumpSize;
 }
 for (i = 0; i < lumpMapLength; i++) {
  if (strncmp(lumpMap[i].lumpName, lumpName, stringLength) == 0) {
   strncpy(cache[5 - 1].lumpName, lumpName, 8);
   cache[5 - 1].lumpOffset = lumpMap[i].lumpOffset;
   cache[5 -1 ].lumpSize = lumpMap[i].lumpSize;
   return lumpMap[i].lumpOffset;
  }
 }
 fprintf(stderr, "Lump Name '%s' not found in WAD, aborting\n", lumpName);
 exit(1);
 return 0;
}

canonical_original_code:
static long wadLumpNameToOffset(char *lumpName) {
 int i;
 int stringLength;
 static struct LumpMap cache[5];
 stringLength = strlen(lumpName);
 for (i = 0; i < 5; i++) {
  if (strncmp(cache[i].lumpName, lumpName, stringLength) == 0) {
   return cache[i].lumpOffset;
  }
 }
 for (i = 0; i < 5 - 1; i++) {
  strncpy(cache[i].lumpName, cache[i + 1].lumpName, 8);
  cache[i].lumpOffset = cache[i + 1].lumpOffset;
  cache[i].lumpSize = cache[i + 1].lumpSize;
 }
 for (i = 0; i < lumpMapLength; i++) {
  if (strncmp(lumpMap[i].lumpName, lumpName, stringLength) == 0) {
   strncpy(cache[5 - 1].lumpName, lumpName, 8);
   cache[5 - 1].lumpOffset = lumpMap[i].lumpOffset;
   cache[5 -1 ].lumpSize = lumpMap[i].lumpSize;
   return lumpMap[i].lumpOffset;
  }
 }
 fprintf(stderr, "Lump Name '%s' not found in WAD, aborting\n", lumpName);
 exit(1);
 return 0;
}

variable_types:
lumpName
char *

variable_types: i int

variable_types: stringLength int

variable_types: struct LumpMap { char lumpName[9]; long lumpOffset; long lumpSize; } [5]

return_type: long


wadReadShort

decompiled_code:
_BOOL8 __fastcall wadReadShort(_WORD *a1)
{
__int16 v1; // bp
FILE *v2; // rbx
int v3; // edx
_BOOL8 result; // rax

v1 = getc(wadFile);
*a1 = v1 | ((unsigned __int16)getc(wadFile) << 8);
v2 = wadFile;
v3 = feof(wadFile);
result = 1LL;
if ( !v3 )
result = ferror(v2) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_WORD *a1)
{
__int16 v1; // bp
FILE *v2; // rbx
int v3; // edx
_BOOL8 result; // rax

v1 = getc(wadFile);
*a1 = v1 | ((unsigned __int16)getc(wadFile) << 8);
v2 = wadFile;
v3 = feof(wadFile);
result = 1LL;
if ( !v3 )
result = ferror(v2) != 0;
return result;
}

original_code:
static short wadReadShort(short *value) {
 *value = getc(wadFile)
  | (getc(wadFile) << 8);
 return feof(wadFile) || ferror(wadFile);
}

variable_types:
value
short *

return_type: short


wadReadLong

decompiled_code:
_BOOL8 __fastcall wadReadLong(_QWORD *a1)
{
int v1; // ebx
int v2; // ebp
int v3; // ebx
FILE *v4; // rbx
int v5; // edx
_BOOL8 result; // rax

v1 = getc(wadFile);
v2 = getc(wadFile);
v3 = (getc(wadFile) << 16) | (v2 << 8) | v1;
*a1 = (getc(wadFile) << 24) | v3;
v4 = wadFile;
v5 = feof(wadFile);
result = 1LL;
if ( !v5 )
result = ferror(v4) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
int v1; // ebx
int v2; // ebp
int v3; // ebx
FILE *v4; // rbx
int v5; // edx
_BOOL8 result; // rax

v1 = getc(wadFile);
v2 = getc(wadFile);
v3 = (getc(wadFile) << 16) | (v2 << 8) | v1;
*a1 = (getc(wadFile) << 24) | v3;
v4 = wadFile;
v5 = feof(wadFile);
result = 1LL;
if ( !v5 )
result = ferror(v4) != 0;
return result;
}

original_code:
static int wadReadLong(long *value) {
 *value = getc(wadFile)
  | (getc(wadFile) << 8)
  | (getc(wadFile) << 16)
  | (getc(wadFile) << 24);
 return feof(wadFile) || ferror(wadFile);
}

variable_types:
value
long *


wadReadLumpPalette

decompiled_code:
__int64 __fastcall wadReadLumpPalette(__int64 off)
{
char *v1; // r12
unsigned __int8 v2; // bl
unsigned __int8 v3; // bp
unsigned __int8 v4; // al
__int64 result; // rax

fseek(wadFile, off, 0);
v1 = (char *)&palette;
do
{
v2 = getc(wadFile);
v3 = getc(wadFile);
v4 = getc(wadFile);
result = sgCreateColor(v2, v3, v4);
*(_DWORD *)v1 = result;
v1 += 4;
}
while ( v1 != "Lump Name '%s' not found in WAD, aborting\n" );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 off)
{
char *v1; // r12
unsigned __int8 v2; // bl
unsigned __int8 v3; // bp
unsigned __int8 v4; // al
__int64 result; // rax

fseek(wadFile, off, 0);
v1 = (char *)&palette;
do
{
v2 = getc(wadFile);
v3 = getc(wadFile);
v4 = getc(wadFile);
result = sgCreateColor(v2, v3, v4);
*(_DWORD *)v1 = result;
v1 += 4;
}
while ( v1 != "Lump Name '%s' not found in WAD, aborting\n" );
return result;
}

original_code:
static void wadReadLumpPalette(long offset) {
 int i;
 Uint8 red;
 Uint8 green;
 Uint8 blue;
 fseek(wadFile, offset, 0);
 for (i = 0; i < 256; i++) {
  red = (Uint8)getc(wadFile);
  green = (Uint8)getc(wadFile);
  blue = (Uint8)getc(wadFile);
  palette[i] = sgCreateColor(red, green, blue);
 }
}

canonical_original_code:
static void wadReadLumpPalette(long offset) {
 int i;
 unsigned char red;
 unsigned char green;
 unsigned char blue;
 fseek(wadFile, offset, 0);
 for (i = 0; i < 256; i++) {
  red = (unsigned char)getc(wadFile);
  green = (unsigned char)getc(wadFile);
  blue = (unsigned char)getc(wadFile);
  palette[i] = sgCreateColor(red, green, blue);
 }
}

variable_types: offset long

variable_types:
red
unsigned char

variable_types:
green
unsigned char

variable_types:
blue
unsigned char


wadReadDir

decompiled_code:
void __fastcall wadReadDir(__int64 a1, __int64 a2)
{
void *v2; // r12
__int64 i; // rbp
char *v4; // rbx
fpos_t v5; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+10h] [rbp-38h] BYREF
__int64 off[6]; // [rsp+18h] [rbp-30h] BYREF

v2 = calloc(1uLL, 9uLL);
lumpMap = (char *)malloc(32 * a1);
lumpMapLength = a1;
fseek(wadFile, a2, 0);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( wadReadLong(off) )
_assert_fail("result == 0", "wadread.c", 0x39u, "wadReadDir");
if ( wadReadLong(&v6) )
_assert_fail("result == 0", "wadread.c", 0x3Bu, "wadReadDir");
if ( (unsigned int)fread(v2, 8uLL, 1uLL, wadFile) != 1 )
_assert_fail("result == 1", "wadread.c", 0x3Du, "wadReadDir");
v4 = &lumpMap[32 * i];
strncpy(v4, (const char *)v2, 8uLL);
v4[8] = 0;
*((_QWORD *)v4 + 2) = off[0];
*((_QWORD *)v4 + 3) = v6;
if ( !strcmp((const char *)v2, "PLAYPAL") )
{
fgetpos(wadFile, &v5);
wadReadLumpPalette(off[0]);
fsetpos(wadFile, &v5);
}
}
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
void *v2; // r12
__int64 i; // rbp
char *v4; // rbx
fpos_t v5; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+10h] [rbp-38h] BYREF
__int64 off[6]; // [rsp+18h] [rbp-30h] BYREF

v2 = calloc(1uLL, 9uLL);
lumpMap = (char *)malloc(32 * a1);
lumpMapLength = a1;
fseek(wadFile, a2, 0);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( func2(off) )
_assert_fail("result == 0", "wadread.c", 0x39u, "wadReadDir");
if ( func2(&v6) )
_assert_fail("result == 0", "wadread.c", 0x3Bu, "wadReadDir");
if ( (unsigned int)fread(v2, 8uLL, 1uLL, wadFile) != 1 )
_assert_fail("result == 1", "wadread.c", 0x3Du, "wadReadDir");
v4 = &lumpMap[32 * i];
strncpy(v4, (const char *)v2, 8uLL);
v4[8] = 0;
*((_QWORD *)v4 + 2) = off[0];
*((_QWORD *)v4 + 3) = v6;
if ( !strcmp((const char *)v2, "PLAYPAL") )
{
fgetpos(wadFile, &v5);
func3(off[0]);
fsetpos(wadFile, &v5);
}
}
}
free(v2);
}

original_code:
static void wadReadDir(long numLumps, long dirOffset) {
 int i;
 int result;
 long lumpOffset;
 long lumpSize;
 char *lumpName;
 fpos_t filepos;
 lumpName = (char*)calloc(1, 9);
 lumpMap = (LumpMap*)malloc(sizeof(LumpMap) * numLumps);
 lumpMapLength = numLumps;
 fseek(wadFile, dirOffset, 0);
 for (i = 0; i < numLumps; i++) {
  result = wadReadLong(&lumpOffset);
  ((result == 0) ? (void) (0) : __assert_fail ("result == 0", "wadread.c", 57, __extension__ __PRETTY_FUNCTION__));
  result = wadReadLong(&lumpSize);
  ((result == 0) ? (void) (0) : __assert_fail ("result == 0", "wadread.c", 59, __extension__ __PRETTY_FUNCTION__));
  result = fread(lumpName, 8, 1, wadFile);
  ((result == 1) ? (void) (0) : __assert_fail ("result == 1", "wadread.c", 61, __extension__ __PRETTY_FUNCTION__));
  strncpy(lumpMap[i].lumpName, lumpName, 8);
  lumpMap[i].lumpName[8] = 0;
  lumpMap[i].lumpOffset = lumpOffset;
  lumpMap[i].lumpSize = lumpSize;
  if (strcmp(lumpName, "PLAYPAL") == 0) {
   fgetpos(wadFile, &filepos);
   wadReadLumpPalette(lumpOffset);
   fsetpos(wadFile, &filepos);
  }
 }
 free(lumpName);
}

canonical_original_code:
static void wadReadDir(long numLumps, long dirOffset) {
 int i;
 int result;
 long lumpOffset;
 long lumpSize;
 char *lumpName;
 struct _G_fpos_t filepos;
 lumpName = (char *)calloc(1, 9);
 lumpMap = (struct LumpMap *)malloc(sizeof(LumpMap) * numLumps);
 lumpMapLength = numLumps;
 fseek(wadFile, dirOffset, 0);
 for (i = 0; i < numLumps; i++) {
  result = wadReadLong(&lumpOffset);
  ((result == 0) ? (void) (0) : __assert_fail ("result == 0", "wadread.c", 57, __extension__ __PRETTY_FUNCTION__));
  result = wadReadLong(&lumpSize);
  ((result == 0) ? (void) (0) : __assert_fail ("result == 0", "wadread.c", 59, __extension__ __PRETTY_FUNCTION__));
  result = fread(lumpName, 8, 1, wadFile);
  ((result == 1) ? (void) (0) : __assert_fail ("result == 1", "wadread.c", 61, __extension__ __PRETTY_FUNCTION__));
  strncpy(lumpMap[i].lumpName, lumpName, 8);
  lumpMap[i].lumpName[8] = 0;
  lumpMap[i].lumpOffset = lumpOffset;
  lumpMap[i].lumpSize = lumpSize;
  if (strcmp(lumpName, "PLAYPAL") == 0) {
   fgetpos(wadFile, &filepos);
   wadReadLumpPalette(lumpOffset);
   fsetpos(wadFile, &filepos);
  }
 }
 free(lumpName);
}

variable_types: numLumps long

variable_types: dirOffset long

variable_types: result int

variable_types: lumpOffset long

variable_types: lumpSize long

variable_types: struct _G_fpos_t { long __pos; struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __state; }

user_defined_types: struct _G_fpos_t { long __pos; struct __mbstate_t __state; }

user_defined_types: struct LumpMap { char lumpName[9]; long lumpOffset; long lumpSize; }