decompiled_code:
void *__fastcall my_malloc(size_t size)
{
printf("%s called, requesting %zd bytes\n", "my_malloc", size);
return malloc(size);
}

canonical_decompiled_code:
void *__fastcall func0(size_t size)
{
printf("%s called, requesting %zd bytes\n", "my_malloc", size);
return malloc(size);
}

original_code:
static void*
my_malloc(size_t len)
{
 printf("%s called, requesting %zd bytes\n", __func__, len);
 return malloc(len);
}

canonical_original_code:
static void *my_malloc(unsigned long len)
{
 printf("%s called, requesting %zd bytes\n", __func__, len);
 return malloc(len);
}

variable_types:
len
unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 (__fastcall *v5)(__int64); // rax
char *v6; // rbp
int result; // eax

add_fixup_anchor(&a, argv, envp);
v3 = elf_dlopen("./malloc_lib.so");
if ( v3 )
{
v4 = v3;
v5 = (__int64 (__fastcall *)(__int64))elf_dlsym(v3, "create_string");
if ( v5 )
{
v6 = (char *)v5(52LL);
printf("create_string returned: %s\n", v6);
if ( v6 )
free(v6);
elf_dlclose(v4);
result = 0;
}
else
{
fwrite("elf_dlsym('create_string') failed\n", 1uLL, 0x22uLL, stderr);
elf_dlclose(v4);
result = 1;
}
}
else
{
fwrite("elf_dlopen failed\n", 1uLL, 0x12uLL, stderr);
result = 1;
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 char *s;
 elf_object *elf;
 create_string cs;
 add_fixup_anchor(&a);
 elf = elf_dlopen("./malloc_lib.so");
 if (elf == ((void *)0)) {
  fprintf(stderr, "elf_dlopen failed\n");
  return 1;
 }
 cs = (create_string)elf_dlsym(elf, "create_string");
 if (cs == ((void *)0)) {
  fprintf(stderr, "elf_dlsym('create_string') failed\n");
  elf_dlclose(elf);
  return 1;
 }
 s = cs(52);
 printf("create_string returned: %s\n", s);
 if (s != ((void *)0))
  free(s);
 elf_dlclose(elf);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *s;
 struct _elf_object *elf;
 char *(*cs)(unsigned long);
 add_fixup_anchor(&a);
 elf = elf_dlopen("./malloc_lib.so");
 if (elf == ((void *)0)) {
  fprintf(stderr, "elf_dlopen failed\n");
  return 1;
 }
 cs = (char *(*)(unsigned long))elf_dlsym(elf, "create_string");
 if (cs == ((void *)0)) {
  fprintf(stderr, "elf_dlsym('create_string') failed\n");
  elf_dlclose(elf);
  return 1;
 }
 s = cs(52);
 printf("create_string returned: %s\n", s);
 if (s != ((void *)0))
  free(s);
 elf_dlclose(elf);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
s
char *

variable_types: struct _elf_object { unsigned long flags; unsigned long *pltgot; struct Elf64_Rel { unsigned long r_offset; unsigned long r_info; } *rel; unsigned long relsize; struct Elf64_Rela { unsigned long r_offset; unsigned long r_info; long r_addend; } *rela; unsigned long relasize; struct Elf64_Rel *pltrel; unsigned long pltrelsize; struct Elf64_Rela *pltrela; unsigned long pltrelasize; struct Elf64_Sym { unsigned int st_name; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; unsigned long st_value; unsigned long st_size; } *symtab; char *strtab; unsigned long strsize; unsigned int *buckets; unsigned long nbuckets; unsigned int *chains; unsigned long nchains; unsigned long init; unsigned long fini; unsigned long preinit_array; unsigned long preinit_array_len; unsigned long init_array; unsigned long init_array_len; unsigned long fini_array; unsigned long fini_array_len; struct Elf64_Dyn { long d_tag; union { unsigned long d_val; unsigned long d_ptr; } d_un; } *dynamic; unsigned long dynsymcount; unsigned char *relocbase; unsigned long relocsize; unsigned long dl_count; void **dl_handles; unsigned long nbuckets_gnu; unsigned long symndx_gnu; unsigned long maskwords_bm_gnu; unsigned long shift2_gnu; unsigned long *bloom_gnu; unsigned int *buckets_gnu; unsigned int *chain_zero_gnu; } *

variable_types:
cs
char *(*)(unsigned long)

return_type: int

user_defined_types: struct _elf_object { unsigned long flags; unsigned long *pltgot; struct Elf64_Rel *rel; unsigned long relsize; struct Elf64_Rela *rela; unsigned long relasize; struct Elf64_Rel *pltrel; unsigned long pltrelsize; struct Elf64_Rela *pltrela; unsigned long pltrelasize; struct Elf64_Sym *symtab; char *strtab; unsigned long strsize; unsigned int *buckets; unsigned long nbuckets; unsigned int *chains; unsigned long nchains; unsigned long init; unsigned long fini; unsigned long preinit_array; unsigned long preinit_array_len; unsigned long init_array; unsigned long init_array_len; unsigned long fini_array; unsigned long fini_array_len; struct Elf64_Dyn *dynamic; unsigned long dynsymcount; unsigned char *relocbase; unsigned long relocsize; unsigned long dl_count; void **dl_handles; unsigned long nbuckets_gnu; unsigned long symndx_gnu; unsigned long maskwords_bm_gnu; unsigned long shift2_gnu; unsigned long *bloom_gnu; unsigned int *buckets_gnu; unsigned int *chain_zero_gnu; }


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
if ( libc_elf )
elf_dlclose();
if ( ld_elf )
elf_dlclose();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
if ( libc_elf )
elf_dlclose();
if ( ld_elf )
elf_dlclose();
exit(1);
}

original_code:
static void
die(const char *fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
 if (libc_elf)
  elf_dlclose(libc_elf);
 if (ld_elf)
  elf_dlclose(ld_elf);
 exit(1);
}

canonical_original_code:
static void die(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
 if (libc_elf)
  elf_dlclose(libc_elf);
 if (ld_elf)
  elf_dlclose(ld_elf);
 exit(1);
}

variable_types:
fmt
char *

return_type: void


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

result = elf_dlopen();
if ( !result )
die("elf_dlopen(%s) failed\n", a1);
return result;
}

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

result = elf_dlopen();
if ( !result )
func0("elf_dlopen(%s) failed\n", a1);
return result;
}

original_code:
static elf_object*
xelf_dlopen(char *path)
{
 elf_object *ret;
 ret = elf_dlopen(path);
 if (ret == ((void *)0))
  die("elf_dlopen(%s) failed\n", path);
 do{}while(0);
 return ret;
}

canonical_original_code:
static struct _elf_object *xelf_dlopen(char *path)
{
 struct _elf_object *ret;
 ret = elf_dlopen(path);
 if (ret == ((void *)0))
  die("elf_dlopen(%s) failed\n", path);
 do{}while(0);
 return ret;
}

variable_types:
path
char *

return_type: struct _elf_object { unsigned long flags; unsigned long *pltgot; struct Elf64_Rel { unsigned long r_offset; unsigned long r_info; } *rel; unsigned long relsize; struct Elf64_Rela { unsigned long r_offset; unsigned long r_info; long r_addend; } *rela; unsigned long relasize; struct Elf64_Rel *pltrel; unsigned long pltrelsize; struct Elf64_Rela *pltrela; unsigned long pltrelasize; struct Elf64_Sym { unsigned int st_name; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; unsigned long st_value; unsigned long st_size; } *symtab; char *strtab; unsigned long strsize; unsigned int *buckets; unsigned long nbuckets; unsigned int *chains; unsigned long nchains; unsigned long init; unsigned long fini; unsigned long preinit_array; unsigned long preinit_array_len; unsigned long init_array; unsigned long init_array_len; unsigned long fini_array; unsigned long fini_array_len; struct Elf64_Dyn { long d_tag; union { unsigned long d_val; unsigned long d_ptr; } d_un; } *dynamic; unsigned long dynsymcount; unsigned char *relocbase; unsigned long relocsize; unsigned long dl_count; void **dl_handles; unsigned long nbuckets_gnu; unsigned long symndx_gnu; unsigned long maskwords_bm_gnu; unsigned long shift2_gnu; unsigned long *bloom_gnu; unsigned int *buckets_gnu; unsigned int *chain_zero_gnu; } *


main

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

ld_elf = xelf_dlopen("/lib64/ld-linux-x86-64.so.2");
libc_elf = xelf_dlopen("/lib/x86_64-linux-gnu/libc.so.6");
v3 = (void (__fastcall *)(const char *))xelf_dlsym(libc_elf, "printf");
v3("Hello World\n");
elf_dlclose(libc_elf);
elf_dlclose(ld_elf);
return 0;
}

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

ld_elf = func1("/lib64/ld-linux-x86-64.so.2");
libc_elf = func1("/lib/x86_64-linux-gnu/libc.so.6");
v3 = (void (__fastcall *)(const char *))func2(libc_elf, "printf");
v3("Hello World\n");
elf_dlclose(libc_elf);
elf_dlclose(ld_elf);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 printf_fn pf;
 ld_elf = xelf_dlopen(ldso);
 libc_elf = xelf_dlopen(libc);
 pf = (printf_fn)xelf_dlsym(libc_elf, "printf");
 pf("Hello World\n");
 elf_dlclose(libc_elf);
 elf_dlclose(ld_elf);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int (*pf)(char *, ...);
 ld_elf = xelf_dlopen(ldso);
 libc_elf = xelf_dlopen(libc);
 pf = (int (*)(char *, ...))xelf_dlsym(libc_elf, "printf");
 pf("Hello World\n");
 elf_dlclose(libc_elf);
 elf_dlclose(ld_elf);
 return 0;
}


getRandomNumber

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

result = (unsigned int)(c + 2);
c += 2;
return result;
}

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

result = (unsigned int)(c + 2);
c += 2;
return result;
}

original_code:
int getRandomNumber(void)
{
 c += 2;
 return c;
}

canonical_original_code:
int getRandomNumber()
{
 c += 2;
 return c;
}


getString

decompiled_code:
_BYTE *getString()
{
_BYTE *result; // rax

result = malloc(2uLL);
*result = 72;
result[1] = 0;
return result;
}

canonical_decompiled_code:
_BYTE *func5()
{
_BYTE *result; // rax

result = malloc(2uLL);
*result = 72;
result[1] = 0;
return result;
}

original_code:
char* getString(void)
{
 char* s = (char*)malloc(2);
 s[0] = 'H'; s[1] = '\0';
 return s;
}

canonical_original_code:
char *getString()
{
 char *s = (char*)malloc(2);
 s[0] = 'H'; s[1] = '\0';
 return s;
}

return_type: char *


decompiled_code:
__int64 __fastcall convert_prot(unsigned int a1)
{
return (a1 >> 2) & 1 | a1 & 2 | (4 * (_BYTE)a1) & 4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return (a1 >> 2) & 1 | a1 & 2 | (4 * (_BYTE)a1) & 4;
}

original_code:
int
convert_prot(int flags)
{
 int prot = 0;
 prot |= 0x1 * !!(flags & (1 << 2));
 prot |= 0x2 * !!(flags & (1 << 1));
 prot |= 0x4 * !!(flags & (1 << 0));
 return prot;
}

variable_types: flags int

variable_types: prot int


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

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

original_code:
void
bintree_delete_node(BinTree *node)
{
 if (node == ((void *)0))
  return;
 free(node);
}

canonical_original_code:
void bintree_delete_node(struct _bintree *node)
{
 if (node == ((void *)0))
  return;
 free(node);
}

variable_types: struct _bintree { struct _anchor { char *name; void *symbol; } anchor; struct _bintree *left; struct _bintree *right; } *

user_defined_types: struct _bintree { struct _anchor anchor; struct _bintree *left; struct _bintree *right; }


repo: cradu/clex

decompiled_code:
void *prepare_value_table()
{
void *result; // rax

vt_len = 0;
result = malloc(0LL);
value_table = result;
return result;
}

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

vt_len = 0;
result = malloc(0LL);
value_table = result;
return result;
}

original_code:
void prepare_value_table() {
    vt_len = 0;
    value_table = (char**)malloc(vt_len * sizeof(char*));
}

canonical_original_code:
void prepare_value_table() {
    vt_len = 0;
    value_table = (char **)malloc(vt_len * sizeof(char *));
}


decompiled_code:
void free_value_table()
{
__int64 v0; // rbx
unsigned __int64 v1; // rbp

if ( vt_len - 1 >= 0 )
{
v0 = 8LL * (vt_len - 1);
v1 = 8 * (vt_len - (unsigned __int64)(unsigned int)(vt_len - 1)) - 16;
do
{
free(*(void **)((char *)value_table + v0));
v0 -= 8LL;
}
while ( v0 != v1 );
}
free(value_table);
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbx
unsigned __int64 v1; // rbp

if ( vt_len - 1 >= 0 )
{
v0 = 8LL * (vt_len - 1);
v1 = 8 * (vt_len - (unsigned __int64)(unsigned int)(vt_len - 1)) - 16;
do
{
free(*(void **)((char *)value_table + v0));
v0 -= 8LL;
}
while ( v0 != v1 );
}
free(value_table);
}

original_code:
void free_value_table() {
    int i;
    for (i = vt_len - 1; i >= 0; --i) {
        free(value_table[i]);
    }
    free(value_table);
}

variable_types: i int


decompiled_code:
__int64 __fastcall get_or_create_entry(char *i, int a2)
{
char *v2; // rbx
unsigned int v4; // er8
char *v5; // rsi
char v6; // dl
__int64 v7; // rax
char v8; // cl
char *v9; // rax
void **v10; // r12
char v11; // dl
__int64 v12; // rax

v2 = i;
LODWORD(i) = vt_len - 1;
if ( vt_len - 1 >= 0 )
{
for ( i = (char *)(int)i; (int)i >= 0; --i )
{
v4 = (unsigned int)i;
v5 = (char *)*((_QWORD *)value_table + (_QWORD)i);
v6 = *v5;
v7 = 0LL;
if ( !*v5 )
goto LABEL_9;
while ( 1 )
{
v8 = v2[v7];
if ( v8 != v6 || !v8 )
break;
v6 = v5[++v7];
if ( !v6 )
goto LABEL_9;
}
if ( !v6 )
{
LABEL_9:
if ( !v2[v7] )
return v4;
}
}
}
v9 = (char *)realloc(value_table, 8LL * (vt_len + 1));
if ( !v9 )
{
puts("Could not reallocate memory for value_table");
exit(15);
}
value_table = v9;
v10 = (void **)&v9[8 * vt_len];
*v10 = malloc(a2);
v11 = *v2;
if ( *v2 )
{
v12 = 0LL;
do
{
*(_BYTE *)(*((_QWORD *)value_table + vt_len) + v12++) = v11;
v11 = v2[v12];
}
while ( v11 );
}
else
{
v12 = 0LL;
}
*(_BYTE *)(*((_QWORD *)value_table + vt_len) + v12) = 0;
return (unsigned int)vt_len++;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *i, int a2)
{
char *v2; // rbx
unsigned int v4; // er8
char *v5; // rsi
char v6; // dl
__int64 v7; // rax
char v8; // cl
char *v9; // rax
void **v10; // r12
char v11; // dl
__int64 v12; // rax

v2 = i;
LODWORD(i) = vt_len - 1;
if ( vt_len - 1 >= 0 )
{
for ( i = (char *)(int)i; (int)i >= 0; --i )
{
v4 = (unsigned int)i;
v5 = (char *)*((_QWORD *)value_table + (_QWORD)i);
v6 = *v5;
v7 = 0LL;
if ( !*v5 )
goto LABEL_9;
while ( 1 )
{
v8 = v2[v7];
if ( v8 != v6 || !v8 )
break;
v6 = v5[++v7];
if ( !v6 )
goto LABEL_9;
}
if ( !v6 )
{
LABEL_9:
if ( !v2[v7] )
return v4;
}
}
}
v9 = (char *)realloc(value_table, 8LL * (vt_len + 1));
if ( !v9 )
{
puts("Could not reallocate memory for value_table");
exit(15);
}
value_table = v9;
v10 = (void **)&v9[8 * vt_len];
*v10 = malloc(a2);
v11 = *v2;
if ( *v2 )
{
v12 = 0LL;
do
{
*(_BYTE *)(*((_QWORD *)value_table + vt_len) + v12++) = v11;
v11 = v2[v12];
}
while ( v11 );
}
else
{
v12 = 0LL;
}
*(_BYTE *)(*((_QWORD *)value_table + vt_len) + v12) = 0;
return (unsigned int)vt_len++;
}

original_code:
int get_or_create_entry(char *o, int len) {
    char **temp;
    int i, j;
    for (i = vt_len - 1; i >= 0 ; --i) {
        j = 0;
        while(value_table[i][j] != '\0' && o[j] != '\0') {
            if (value_table[i][j] == o[j]) j++;
            else break;
        }
        if (value_table[i][j] == '\0' && o[j] == '\0') return i;
    }
    temp = (char**) realloc(value_table, (vt_len + 1) * sizeof(char*));
    if (!temp) {
        printf("Could not reallocate memory for value_table\n");
        exit(15);
    }
    value_table = temp;
    value_table[vt_len] = (char*)malloc(len * sizeof(char));
    i = 0;
    while (o[i] != '\0') {
        value_table[vt_len][i] = o[i];
        i++;
    }
    value_table[vt_len][i] = '\0';
    vt_len ++;
    return vt_len - 1;
}

canonical_original_code:
int get_or_create_entry(char *o, int len) {
    char **temp;
    int i; int j;
    for (i = vt_len - 1; i >= 0 ; --i) {
        j = 0;
        while(value_table[i][j] != '\0' && o[j] != '\0') {
            if (value_table[i][j] == o[j]) j++;
            else break;
        }
        if (value_table[i][j] == '\0' && o[j] == '\0') return i;
    }
    temp = (char **) realloc(value_table, (vt_len + 1) * sizeof(char *));
    if (!temp) {
        printf("Could not reallocate memory for value_table\n");
        exit(15);
    }
    value_table = temp;
    value_table[vt_len] = (char *)malloc(len * sizeof(char));
    i = 0;
    while (o[i] != '\0') {
        value_table[vt_len][i] = o[i];
        i++;
    }
    value_table[vt_len][i] = '\0';
    vt_len ++;
    return vt_len - 1;
}

variable_types:
o
char *

variable_types: len int

variable_types:
temp
char **

variable_types: j int


decompiled_code:
char *__fastcall get_token_type(int a1)
{
return (&types_array)[a1];
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
return (&types_array)[a1];
}

original_code:
char *get_token_type(token_type_t t) {
    return types_array[t];
}

canonical_original_code:
char *get_token_type(enum token_type_t t) {
    return types_array[t];
}

variable_types: enum token_type_t { ROOT=0, BLANK=1, IDENTIFIER=2, KEYWORD=3, OPERATOR=4, COMMENT=5, VALUE=6, STRING=7, CHAR=8 }


decompiled_code:
void open_file()
{
if ( !source_file )
{
source_file = fopen(file_path, "r");
if ( !source_file )
{
printf("could not open file '%s'\n", file_path);
puts("please chect that it exits or is not being opened by orther process (reader.c)");
exit(1);
}
row_number = 1;
column_number = 0;
}
}

canonical_decompiled_code:
void func0()
{
if ( !source_file )
{
source_file = fopen(file_path, "r");
if ( !source_file )
{
printf("could not open file '%s'\n", file_path);
puts("please chect that it exits or is not being opened by orther process (reader.c)");
exit(1);
}
row_number = 1;
column_number = 0;
}
}

original_code:
void open_file() {
    if (_source_file) {
        return;
    }
    _source_file = fopen(_file_path, "r");
    if (!_source_file) {
        printf("could not open file '%s'\n", _file_path);
        printf("please chect that it exits or is not being opened by orther process (reader.c)\n");
        exit(1);
    }
    row_number = 1;
    column_number = 0;
}


decompiled_code:
char *__fastcall set_source(char *src)
{
size_t v2; // rax
char *v3; // rdi

if ( source_file )
fclose(source_file);
v2 = strlen(src);
v3 = (char *)malloc(v2);
file_path = v3;
if ( !v3 )
{
puts("could not allocate memory for _file_path (reader.c)");
exit(2);
}
return strcpy(v3, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v2; // rax
char *v3; // rdi

if ( source_file )
fclose(source_file);
v2 = strlen(src);
v3 = (char *)malloc(v2);
file_path = v3;
if ( !v3 )
{
puts("could not allocate memory for _file_path (reader.c)");
exit(2);
}
return strcpy(v3, src);
}

original_code:
void set_source(char *file) {
    if (!_file_path) {
        free(_file_path);
    }
    if (_source_file) {
        fclose(_source_file);
    }
    _file_path = (char*)malloc( strlen(file) * sizeof(char) );
    if (!_file_path) {
        printf("could not allocate memory for _file_path (reader.c)\n");
        exit(2);
    }
    strcpy(_file_path, file);
}

canonical_original_code:
void set_source(char *file) {
    if (!_file_path) {
        free(_file_path);
    }
    if (_source_file) {
        fclose(_source_file);
    }
    _file_path = (char *)malloc( strlen(file) * sizeof(char) );
    if (!_file_path) {
        printf("could not allocate memory for _file_path (reader.c)\n");
        exit(2);
    }
    strcpy(_file_path, file);
}

variable_types:
file
char *


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

if ( !source_file )
open_file();
result = fgetc(source_file);
if ( (_BYTE)result == 10 )
{
++row_number;
column_number = 0;
}
else
{
++column_number;
}
return result;
}

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

if ( !source_file )
func0();
result = fgetc(source_file);
if ( (_BYTE)result == 10 )
{
++row_number;
column_number = 0;
}
else
{
++column_number;
}
return result;
}

original_code:
char get_char() {
    char c;
    if (!_source_file) {
        open_file();
    }
    c = fgetc(_source_file);
    if (c == '\n') {
        row_number++;
        column_number = 0;
    } else {
        column_number++;
    }
    return c;
}

variable_types: c char

return_type: char


original_code:
void add_transition(int state, char c, int next) {
    int i, j;
    int next_index = (int)c % 11;
    node_t *n = nodes[state];
    int fuck_fix[11];
    if (n->next[next_index] == ((void *)0)) {
        n->next[next_index] = (int*)malloc(1 * sizeof(int));
        if (n->next[next_index] == ((void *)0)) {
            printf("Failed to allocate memory for transition: %d %c -> %d", n->index, c, next);
            exit(11);
        }
        n->next[next_index][0] = next;
        n->sizes[next_index] = 1;
    } else {
        if (nodes[next]->reachers_count == 200) {
            exit(10);
        }
        int nodes_size = n->sizes[next_index] + 1;
        int *temp = (int*)realloc(n->next[next_index], nodes_size * sizeof(int));
        if (temp) {
            n->next[next_index] = temp;
            n->next[next_index][nodes_size - 1] = next;
            n->sizes[next_index] = nodes_size;
        } else {
            printf("Failed to reallocate memory for transition: %d %c -> %d", n->index, c, next);
            exit(12);
        }
    }
    for (i = 0; i < nodes[next]->reachers_count; ++i) {
        if (nodes[next]->reachers[i].node_index == n->index && nodes[next]->reachers[i].c == c) {
            return;
        }
    }
    for (j = 0; j < 11; ++j) {
        fuck_fix[j] = nodes[next]->sizes[j];
    }
    nodes[next]->reachers[i].node_index = n->index;
    nodes[next]->reachers[i].c = c;;
    nodes[next]->reachers_count++;
    for (j = 0; j < 11; ++j) {
        nodes[next]->sizes[j] = fuck_fix[j];
    }
}

canonical_original_code:
void add_transition(int state, char c, int next) {
    int i; int j;
    int next_index = (int)c % 11;
    struct node *n = nodes[state];
    int fuck_fix[11];
    if (n->next[next_index] == ((void *)0)) {
        n->next[next_index] = (int *)malloc(1 * sizeof(int));
        if (n->next[next_index] == ((void *)0)) {
            printf("Failed to allocate memory for transition: %d %c -> %d", n->index, c, next);
            exit(11);
        }
        n->next[next_index][0] = next;
        n->sizes[next_index] = 1;
    } else {
        if (nodes[next]->reachers_count == 200) {
            exit(10);
        }
        int nodes_size = n->sizes[next_index] + 1;
        int *temp = (int*)realloc(n->next[next_index], nodes_size * sizeof(int));
        if (temp) {
            n->next[next_index] = temp;
            n->next[next_index][nodes_size - 1] = next;
            n->sizes[next_index] = nodes_size;
        } else {
            printf("Failed to reallocate memory for transition: %d %c -> %d", n->index, c, next);
            exit(12);
        }
    }
    for (i = 0; i < nodes[next]->reachers_count; ++i) {
        if (nodes[next]->reachers[i].node_index == n->index && nodes[next]->reachers[i].c == c) {
            return;
        }
    }
    for (j = 0; j < 11; ++j) {
        fuck_fix[j] = nodes[next]->sizes[j];
    }
    nodes[next]->reachers[i].node_index = n->index;
    nodes[next]->reachers[i].c = c;;
    nodes[next]->reachers_count++;
    for (j = 0; j < 11; ++j) {
        nodes[next]->sizes[j] = fuck_fix[j];
    }
}

variable_types: state int

variable_types: next int

variable_types: struct node { int index; int *next[11]; enum token_type_t { ROOT=0, BLANK=1, IDENTIFIER=2, KEYWORD=3, OPERATOR=4, COMMENT=5, VALUE=6, STRING=7, CHAR=8 } type; int reachers_count; struct reach { char c; int node_index; } reachers[200]; int sizes[11]; } *

variable_types:
temp
int *

user_defined_types: struct node { int index; int *next[11]; enum token_type_t type; int reachers_count; struct reach reachers[200]; int sizes[11]; }


decompiled_code:
__int64 __fastcall get_next(_DWORD *a1, char a2)
{
char v3; // si
int v4; // er13
__int64 v5; // r13
__int64 v6; // rbp
int v7; // er14
unsigned int v8; // eax
__int64 v9; // rsi
int v10; // ecx
__int64 v11; // rax
__int64 v12; // rcx

v3 = a2 % 11;
v4 = a1[v3 + 426];
if ( v4 <= 0 )
return *(_QWORD *)nodes;
v5 = 4LL * (unsigned int)v4;
v6 = 0LL;
v7 = v3;
while ( 1 )
{
v8 = *(_DWORD *)(*(_QWORD *)&a1[2 * v7 + 2] + v6);
v9 = *(_QWORD *)(nodes + 8LL * (int)v8);
v10 = *(_DWORD *)(v9 + 100);
if ( !v8 || v10 )
break;
printf("Unreachable node: %d\n", v8);
LABEL_4:
v6 += 4LL;
if ( v6 == v5 )
return *(_QWORD *)nodes;
}
if ( v10 <= 0 )
goto LABEL_4;
v11 = v9 + 104;
v12 = v9 + 8LL * (unsigned int)(v10 - 1) + 112;
while ( *(_DWORD *)(v11 + 4) != *a1 || *(_BYTE *)v11 != a2 )
{
v11 += 8LL;
if ( v11 == v12 )
goto LABEL_4;
}
return v9;
}

original_code:
node_t* get_next(node_t *current_node, char c) {
    int i, j, k;
    int rc_size;
    int next_index = (int)c % 11;
    for (i = 0, k = current_node->sizes[next_index]; i < k; ++i) {
        rc_size = nodes[current_node->next[next_index][i]]->reachers_count;
        if (rc_size == 0 && current_node->next[next_index][i] != 0) {
            printf("Unreachable node: %d\n", current_node->next[next_index][i]);
        }
        for (j = 0; j < rc_size; ++j) {
            if (nodes[current_node->next[next_index][i]]->reachers[j].node_index == current_node->index
                && nodes[current_node->next[next_index][i]]->reachers[j].c == c) {
                return nodes[current_node->next[next_index][i]];
            }
        }
    }
    return nodes[0];
}

canonical_original_code:
struct node *get_next(struct node *current_node, char c) {
    int i; int j; int k;
    int rc_size;
    int next_index = (int)c % 11;
    for (i = 0, k = current_node->sizes[next_index]; i < k; ++i) {
        rc_size = nodes[current_node->next[next_index][i]]->reachers_count;
        if (rc_size == 0 && current_node->next[next_index][i] != 0) {
            printf("Unreachable node: %d\n", current_node->next[next_index][i]);
        }
        for (j = 0; j < rc_size; ++j) {
            if (nodes[current_node->next[next_index][i]]->reachers[j].node_index == current_node->index
                && nodes[current_node->next[next_index][i]]->reachers[j].c == c) {
                return nodes[current_node->next[next_index][i]];
            }
        }
    }
    return nodes[0];
}

variable_types: k int

return_type: struct node { int index; int *next[11]; enum token_type_t { ROOT=0, BLANK=1, IDENTIFIER=2, KEYWORD=3, OPERATOR=4, COMMENT=5, VALUE=6, STRING=7, CHAR=8 } type; int reachers_count; struct reach { char c; int node_index; } reachers[200]; int sizes[11]; } *


decompiled_code:
__int64 __fastcall is_keyword(__int64 a1)
{
unsigned __int64 i; // r8
char v2; // dl
__int64 v3; // rax
char v4; // cl

for ( i = (unsigned int)((_DWORD)&C_keywords + 248); ; i -= 8LL )
{
v2 = **(_BYTE **)i;
v3 = 0LL;
if ( v2 )
{
while ( 1 )
{
v4 = *(_BYTE *)(a1 + v3);
if ( v4 != v2 || !v4 )
break;
++v3;
v2 = *(_BYTE *)(*(_QWORD *)i + v3);
if ( !v2 )
goto LABEL_8;
}
}
else
{
LABEL_8:
if ( !*(_BYTE *)(a1 + v3) )
return 1LL;
}
if ( (char **)i == &C_keywords )
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned __int64 i; // r8
char v2; // dl
__int64 v3; // rax
char v4; // cl

for ( i = (unsigned int)((_DWORD)&C_keywords + 248); ; i -= 8LL )
{
v2 = **(_BYTE **)i;
v3 = 0LL;
if ( v2 )
{
while ( 1 )
{
v4 = *(_BYTE *)(a1 + v3);
if ( v4 != v2 || !v4 )
break;
++v3;
v2 = *(_BYTE *)(*(_QWORD *)i + v3);
if ( !v2 )
goto LABEL_8;
}
}
else
{
LABEL_8:
if ( !*(_BYTE *)(a1 + v3) )
return 1LL;
}
if ( (char **)i == &C_keywords )
break;
}
return 0LL;
}

original_code:
int is_keyword(char *o) {
    int i, j;
    for (i = 32 - 1; i >= 0 ; --i) {
        j = 0;
        while(C_keywords[i][j] != '\0' && o[j] != '\0') {
            if (C_keywords[i][j] == o[j]) j++;
            else break;
        }
        if (C_keywords[i][j] == '\0' && o[j] == '\0') return 1;
    }
    return 0;
}

canonical_original_code:
int is_keyword(char *o) {
    int i; int j;
    for (i = 32 - 1; i >= 0 ; --i) {
        j = 0;
        while(C_keywords[i][j] != '\0' && o[j] != '\0') {
            if (C_keywords[i][j] == o[j]) j++;
            else break;
        }
        if (C_keywords[i][j] == '\0' && o[j] == '\0') return 1;
    }
    return 0;
}


decompiled_code:
__int64 prepare_lexer()
{
set_source();
open_file();
current_state = *nodes;
previous_state = 0LL;
val = (__int64)malloc(0x40uLL);
read_next = 1;
return prepare_value_table();
}

canonical_decompiled_code:
__int64 func0()
{
set_source();
open_file();
current_state = *nodes;
previous_state = 0LL;
val = (__int64)malloc(0x40uLL);
read_next = 1;
return prepare_value_table();
}

original_code:
void prepare_lexer(char* file_name) {
    set_source(file_name);
    open_file();
    current_state = nodes[0];
    previous_state = ((void *)0);
    val = (char*) malloc(64 * sizeof(char));
    read_next = 1;
    prepare_value_table();
}

canonical_original_code:
void prepare_lexer(char *file_name) {
    set_source(file_name);
    open_file();
    current_state = nodes[0];
    previous_state = ((void *)0);
    val = (char *) malloc(64 * sizeof(char));
    read_next = 1;
    prepare_value_table();
}


decompiled_code:
__int64 __fastcall get_token(_DWORD *a1)
{
char v1; // al
unsigned int v2; // ebx
__int64 v3; // r12
_DWORD *v4; // rax

v1 = c;
if ( c == -1 )
return 0LL;
v2 = 0;
v3 = 0x100002400LL;
do
{
prev_c = v1;
if ( !v1 || read_next == 1 )
{
c = get_char();
*(_BYTE *)(val + (int)v2++) = c;
}
else
{
*(_BYTE *)(val + (int)v2) = v1;
read_next = 1;
++v2;
}
previous_state = current_state;
v4 = (_DWORD *)get_next(current_state, (unsigned int)c);
current_state = (__int64)v4;
if ( !*v4 && !v4[24] )
{
*a1 = *(_DWORD *)(previous_state + 96);
*(_BYTE *)(val + (int)v2 - 1) = 0;
if ( *(_DWORD *)(previous_state + 96) != 1 )
read_next = 0;
if ( *a1 == 5 )
{
read_next = 0;
v2 = 0;
}
else
{
if ( (unsigned __int8)c <= 0x20u )
{
if ( _bittest64(&v3, (unsigned __int8)c) )
read_next = 1;
}
if ( *a1 )
{
a1[1] = get_or_create_entry(val, v2);
return 1LL;
}
v2 = 0;
}
}
v1 = c;
}
while ( c != -1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
char v1; // al
unsigned int v2; // ebx
__int64 v3; // r12
_DWORD *v4; // rax

v1 = c;
if ( c == -1 )
return 0LL;
v2 = 0;
v3 = 0x100002400LL;
do
{
prev_c = v1;
if ( !v1 || read_next == 1 )
{
c = get_char();
*(_BYTE *)(val + (int)v2++) = c;
}
else
{
*(_BYTE *)(val + (int)v2) = v1;
read_next = 1;
++v2;
}
previous_state = current_state;
v4 = (_DWORD *)get_next(current_state, (unsigned int)c);
current_state = (__int64)v4;
if ( !*v4 && !v4[24] )
{
*a1 = *(_DWORD *)(previous_state + 96);
*(_BYTE *)(val + (int)v2 - 1) = 0;
if ( *(_DWORD *)(previous_state + 96) != 1 )
read_next = 0;
if ( *a1 == 5 )
{
read_next = 0;
v2 = 0;
}
else
{
if ( (unsigned __int8)c <= 0x20u )
{
if ( _bittest64(&v3, (unsigned __int8)c) )
read_next = 1;
}
if ( *a1 )
{
a1[1] = get_or_create_entry(val, v2);
return 1LL;
}
v2 = 0;
}
}
v1 = c;
}
while ( c != -1 );
return 0LL;
}

original_code:
int get_token(token_t *tok) {
int i = 0;
int val_id;
    while (c != (-1)) {
        prev_c = c;
        if (c == '\0' || read_next == 1) {
            c = get_char();
            val[i++] = c;
        } else {
            val[i++] = prev_c;
            read_next = 1;
        }
        previous_state = current_state;
        current_state = get_next(current_state, c);
        if (current_state->index == 0 && current_state->type == 0) {
            tok->type = previous_state->type;
            val[i - 1] = '\0';
            if (previous_state->type != 1) {
                read_next = 0;
            }
            if (tok->type == 5) {
                i = 0;
                read_next = 0;
                continue;
            }
            if (c == ' ' || c == '\r' || c == '\n') {
                read_next = 1;
            }
            if (tok->type == 0) {
                i = 0;
                continue;
            }
            val_id = get_or_create_entry(val, i);
            tok->value = val_id;
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int get_token(struct token_struct *tok) {
int i = 0;
int val_id;
    while (c != (-1)) {
        prev_c = c;
        if (c == '\0' || read_next == 1) {
            c = get_char();
            val[i++] = c;
        } else {
            val[i++] = prev_c;
            read_next = 1;
        }
        previous_state = current_state;
        current_state = get_next(current_state, c);
        if (current_state->index == 0 && current_state->type == 0) {
            tok->type = previous_state->type;
            val[i - 1] = '\0';
            if (previous_state->type != 1) {
                read_next = 0;
            }
            if (tok->type == 5) {
                i = 0;
                read_next = 0;
                continue;
            }
            if (c == ' ' || c == '\r' || c == '\n') {
                read_next = 1;
            }
            if (tok->type == 0) {
                i = 0;
                continue;
            }
            val_id = get_or_create_entry(val, i);
            tok->value = val_id;
            return 1;
        }
    }
    return 0;
}

variable_types: struct token_struct { enum token_type_t { ROOT=0, BLANK=1, IDENTIFIER=2, KEYWORD=3, OPERATOR=4, COMMENT=5, VALUE=6, STRING=7, CHAR=8 } type; int value; } *

user_defined_types: struct token_struct { enum token_type_t type; int value; }


decode

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

result = a1;
switch ( (_BYTE)a1 )
{
case 'r':
return 13LL;
case 's':
return 32LL;
case 'n':
result = 10LL;
break;
}
return result;
}

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

result = a1;
switch ( (_BYTE)a1 )
{
case 'r':
return 13LL;
case 's':
return 32LL;
case 'n':
result = 10LL;
break;
}
return result;
}

original_code:
char decode(char c) {
    switch (c) {
        case 'n': return '\n';
        case 'r': return '\r';
        case 's': return ' ';
        default: return c;
    }
}


expand

decompiled_code:
__int64 __fastcall expand(char a1, unsigned int a2, unsigned int a3)
{
unsigned int ii; // er12
__int64 result; // rax
unsigned int k; // er12
unsigned int l; // er12
unsigned int m; // er12
unsigned int n; // er12
unsigned int i; // er12
unsigned int j; // er12
char *v12; // r12
char *v13; // rax
char v14[72]; // [rsp+0h] [rbp-48h] BYREF

strcpy(v14, "~!@#$%^&()_+[{]}\\|;:,<.>/?");
switch ( a1 )
{
case 'c':
for ( i = 122; i != 96; --i )
add_transition(a2, i, a3);
for ( j = 90; j != 64; --j )
add_transition(a2, j, a3);
result = 1LL;
break;
case 'd':
for ( k = 57; k != 47; --k )
add_transition(a2, k, a3);
result = 1LL;
break;
case 'h':
for ( l = 57; l != 47; --l )
add_transition(a2, l, a3);
for ( m = 102; m != 96; --m )
add_transition(a2, m, a3);
for ( n = 70; n != 64; --n )
add_transition(a2, n, a3);
result = 1LL;
break;
case 'o':
for ( ii = 55; ii != 47; --ii )
add_transition(a2, ii, a3);
result = 1LL;
break;
case 'w':
v12 = &v14[27];
do
{
add_transition(a2, (unsigned int)*v12, a3);
v13 = v12--;
}
while ( v13 != v14 );
result = 0LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, unsigned int a2, unsigned int a3)
{
unsigned int ii; // er12
__int64 result; // rax
unsigned int k; // er12
unsigned int l; // er12
unsigned int m; // er12
unsigned int n; // er12
unsigned int i; // er12
unsigned int j; // er12
char *v12; // r12
char *v13; // rax
char v14[72]; // [rsp+0h] [rbp-48h] BYREF

strcpy(v14, "~!@#$%^&()_+[{]}\\|;:,<.>/?");
switch ( a1 )
{
case 'c':
for ( i = 122; i != 96; --i )
add_transition(a2, i, a3);
for ( j = 90; j != 64; --j )
add_transition(a2, j, a3);
result = 1LL;
break;
case 'd':
for ( k = 57; k != 47; --k )
add_transition(a2, k, a3);
result = 1LL;
break;
case 'h':
for ( l = 57; l != 47; --l )
add_transition(a2, l, a3);
for ( m = 102; m != 96; --m )
add_transition(a2, m, a3);
for ( n = 70; n != 64; --n )
add_transition(a2, n, a3);
result = 1LL;
break;
case 'o':
for ( ii = 55; ii != 47; --ii )
add_transition(a2, ii, a3);
result = 1LL;
break;
case 'w':
v12 = &v14[27];
do
{
add_transition(a2, (unsigned int)*v12, a3);
v13 = v12--;
}
while ( v13 != v14 );
result = 0LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int expand(char c, int from_state, int to_state) {
    int i;
    char weird[] = "~!@#$%^&()_+[{]}\\|;:,<.>/?";
    int W_L = 27;
    switch (c) {
        case 'o':
            for (i = '7'; i >= '0'; --i) {
                add_transition(from_state, i, to_state);
            }
            return 1;
        case 'd':
            for (i = '9'; i >= '0'; --i) {
                add_transition(from_state, i, to_state);
            }
            return 1;
        case 'h':
            for (i = '9'; i >= '0'; --i) {
                add_transition(from_state, i, to_state);
            }
            for (i = 'f'; i >= 'a'; --i) {
                add_transition(from_state, i, to_state);
            }
            for (i = 'F'; i >= 'A'; --i) {
                add_transition(from_state, i, to_state);
            }
            return 1;
        case 'c':
            for (i = 'z'; i >= 'a'; --i) {
                add_transition(from_state, i, to_state);
            }
            for (i = 'Z'; i >= 'A'; --i) {
                add_transition(from_state, i, to_state);
            }
            return 1;
        case 'w':
            for (i = W_L; i >= 0; i --) {
                add_transition(from_state, weird[i], to_state);
            }
        default:
            return 0;
    }
}

variable_types:
weird
char []


keyboard

repo: craigpemberton/python-opengl-redbook

decompiled_code:
void __fastcall keyboard(char a1)
{
if ( a1 == 27 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func8(char a1)
{
if ( a1 == 27 )
exit(0);
}

original_code:
void keyboard(unsigned char key, int x, int y)
{
 switch(key)
 {
  case 27:
   exit(0);
   break;
 }
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


drawSquares

decompiled_code:
__int64 __fastcall drawSquares(int a1)
{
__int64 v1; // r14
int v2; // er13
int i; // er12
__int64 result; // rax
int v5; // ebp
__int64 j; // rbx

v1 = 0LL;
v2 = 1;
for ( i = 0; i != 3; ++i )
{
if ( a1 == 7170 )
glLoadName();
v5 = 1;
for ( j = 0LL; j != 3; ++j )
{
if ( a1 == 7170 )
{
glPushName();
glColor3f();
glRecti();
result = glPopName();
}
else
{
glColor3f();
result = glRecti();
}
++v5;
}
++v2;
v1 += 12LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int64 v1; // r14
int v2; // er13
int i; // er12
__int64 result; // rax
int v5; // ebp
__int64 j; // rbx

v1 = 0LL;
v2 = 1;
for ( i = 0; i != 3; ++i )
{
if ( a1 == 7170 )
glLoadName();
v5 = 1;
for ( j = 0LL; j != 3; ++j )
{
if ( a1 == 7170 )
{
glPushName();
glColor3f();
glRecti();
result = glPopName();
}
else
{
glColor3f();
result = glRecti();
}
++v5;
}
++v2;
v1 += 12LL;
}
return result;
}

original_code:
void drawSquares(GLenum mode)
{
 GLuint i, j;
 for(i = 0; i < 3; i++)
 {
  if(mode == 0x1C02)
  {
   glLoadName(i);
  }
  for(j = 0; j < 3; j ++)
  {
   if(mode == 0x1C02)
   {
    glPushName(j);
   }
   glColor3f((GLfloat) i/3.0, (GLfloat) j/3.0,
       (GLfloat) board[i][j]/3.0);
   glRecti(i, j, i+1, j+1);
   if(mode == 0x1C02)
   {
    glPopName();
   }
  }
 }
}

canonical_original_code:
void drawSquares(unsigned int mode)
{
 unsigned int i; unsigned int j;
 for(i = 0; i < 3; i++)
 {
  if(mode == 0x1C02)
  {
   glLoadName(i);
  }
  for(j = 0; j < 3; j ++)
  {
   if(mode == 0x1C02)
   {
    glPushName(j);
   }
   glColor3f((float) i/3.0, (float) j/3.0,
       (float) board[i][j]/3.0);
   glRecti(i, j, i+1, j+1);
   if(mode == 0x1C02)
   {
    glPopName();
   }
  }
 }
}

variable_types:
mode
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int


processHits

decompiled_code:
int __fastcall processHits(unsigned int a1, unsigned int *a2)
{
unsigned int v2; // er13
int result; // eax
int i; // er14
__int64 j; // rbx
__int64 v7; // rcx
int v8; // edx
unsigned int v9; // er12
unsigned int v10; // [rsp+8h] [rbp-40h]

result = printf("hits = %d\n", a1);
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v9 = *a2;
printf(" number of names for this hit = %d\n", *a2);
printf(" z1 is %g;", (float)((float)(int)a2[1] * 4.6566129e-10));
printf(" z2 is %g\n", (float)((float)(int)a2[2] * 4.6566129e-10));
printf(" names are ");
if ( v9 )
{
for ( j = 0LL; j != v9; ++j )
{
printf("%d ", a2[j + 3]);
if ( (_DWORD)j )
{
if ( (_DWORD)j == 1 )
v10 = a2[j + 3];
}
else
{
v2 = a2[j + 3];
}
}
a2 += v9 + 3;
}
else
{
a2 += 3;
}
putchar(10);
v7 = 3LL * v2 + v10;
v8 = board[v7] + 1;
result = 3 * (v8 / 3);
board[v7] = v8 % 3;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1, unsigned int *a2)
{
unsigned int v2; // er13
int result; // eax
int i; // er14
__int64 j; // rbx
__int64 v7; // rcx
int v8; // edx
unsigned int v9; // er12
unsigned int v10; // [rsp+8h] [rbp-40h]

result = printf("hits = %d\n", a1);
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v9 = *a2;
printf(" number of names for this hit = %d\n", *a2);
printf(" z1 is %g;", (float)((float)(int)a2[1] * 4.6566129e-10));
printf(" z2 is %g\n", (float)((float)(int)a2[2] * 4.6566129e-10));
printf(" names are ");
if ( v9 )
{
for ( j = 0LL; j != v9; ++j )
{
printf("%d ", a2[j + 3]);
if ( (_DWORD)j )
{
if ( (_DWORD)j == 1 )
v10 = a2[j + 3];
}
else
{
v2 = a2[j + 3];
}
}
a2 += v9 + 3;
}
else
{
a2 += 3;
}
putchar(10);
v7 = 3LL * v2 + v10;
v8 = board[v7] + 1;
result = 3 * (v8 / 3);
board[v7] = v8 % 3;
}
}
return result;
}

original_code:
void processHits(GLint hits, GLuint buffer[])
{
 unsigned int i, j;
 GLuint ii, jj, names, *ptr;
 printf("hits = %d\n", hits);
 ptr = (GLuint *) buffer;
 for(i = 0; i < hits; i++)
 {
  names = *ptr;
  printf(" number of names for this hit = %d\n", names);
  ptr++;
  printf("  z1 is %g;", (float) *ptr/0x7fffffff);
  ptr++;
  printf(" z2 is %g\n", (float) *ptr/0x7fffffff);
  ptr++;
  printf("   names are ");
  for(j = 0; j < names; j++)
  {
   printf("%d ", *ptr);
   if(j == 0)
   {
    ii = *ptr;
   }
   else if(j == 1)
   {
    jj = *ptr;
   }
   ptr++;
  }
  printf("\n");
  board[ii][jj] = (board[ii][jj] + 1) % 3;
 }
}

canonical_original_code:
void processHits(int hits, unsigned int buffer[])
{
 unsigned int i; unsigned int j;
 unsigned int ii; unsigned int jj; unsigned int names; unsigned int *ptr;
 printf("hits = %d\n", hits);
 ptr = (unsigned int *) buffer;
 for(i = 0; i < hits; i++)
 {
  names = *ptr;
  printf(" number of names for this hit = %d\n", names);
  ptr++;
  printf("  z1 is %g;", (float) *ptr/0x7fffffff);
  ptr++;
  printf(" z2 is %g\n", (float) *ptr/0x7fffffff);
  ptr++;
  printf("   names are ");
  for(j = 0; j < names; j++)
  {
   printf("%d ", *ptr);
   if(j == 0)
   {
    ii = *ptr;
   }
   else if(j == 1)
   {
    jj = *ptr;
   }
   ptr++;
  }
  printf("\n");
  board[ii][jj] = (board[ii][jj] + 1) % 3;
 }
}

variable_types: hits int

variable_types:
buffer
unsigned int []

variable_types:
ii
unsigned int

variable_types:
jj
unsigned int

variable_types:
names
unsigned int

variable_types:
ptr
unsigned int *


pickSquares

decompiled_code:
void __fastcall pickSquares(int a1, int a2)
{
unsigned int v2; // eax
unsigned int v3[518]; // [rsp+4h] [rbp-818h] BYREF

if ( !(a2 | a1) )
{
glGetIntegerv();
glSelectBuffer();
glRenderMode();
glInitNames();
glPushName();
glMatrixMode();
glPushMatrix();
glLoadIdentity();
gluPickMatrix();
gluOrtho2D();
drawSquares(7170);
glMatrixMode();
glPopMatrix();
glFlush();
v2 = glRenderMode();
processHits(v2, v3);
glutPostRedisplay();
}
}

canonical_decompiled_code:
void __fastcall func13(int a1, int a2)
{
unsigned int v2; // eax
unsigned int v3[518]; // [rsp+4h] [rbp-818h] BYREF

if ( !(a2 | a1) )
{
glGetIntegerv();
glSelectBuffer();
glRenderMode();
glInitNames();
glPushName();
glMatrixMode();
glPushMatrix();
glLoadIdentity();
gluPickMatrix();
gluOrtho2D();
func10(7170);
glMatrixMode();
glPopMatrix();
glFlush();
v2 = glRenderMode();
func12(v2, v3);
glutPostRedisplay();
}
}

original_code:
void pickSquares(int button, int state, int x, int y)
{
 GLuint selectBuf[512];
 GLint hits;
 GLint viewport[4];
 if(button != 0x0000 || state != 0x0000)
 {
  return;
 }
 glGetIntegerv(0x0BA2, viewport);
 glSelectBuffer(512, selectBuf);
 (void) glRenderMode(0x1C02);
 glInitNames();
 glPushName(0);
 glMatrixMode(0x1701);
 glPushMatrix();
 glLoadIdentity();
 gluPickMatrix((GLdouble) x, (GLdouble)(viewport[3] - y), 5.0, 5.0, viewport);
 gluOrtho2D(0.0, 3.0, 0.0, 3.0);
 drawSquares(0x1C02);
 glMatrixMode(0x1701);
 glPopMatrix();
 glFlush();
 hits = glRenderMode(0x1C00);
 processHits(hits, selectBuf);
 glutPostRedisplay();
}

canonical_original_code:
void pickSquares(int button, int state, int x, int y)
{
 unsigned int selectBuf[512];
 int hits;
 int viewport[4];
 if(button != 0x0000 || state != 0x0000)
 {
  return;
 }
 glGetIntegerv(0x0BA2, viewport);
 glSelectBuffer(512, selectBuf);
 (void) glRenderMode(0x1C02);
 glInitNames();
 glPushName(0);
 glMatrixMode(0x1701);
 glPushMatrix();
 glLoadIdentity();
 gluPickMatrix((double) x, (GLdouble)(viewport[3] - y), 5.0, 5.0, viewport);
 gluOrtho2D(0.0, 3.0, 0.0, 3.0);
 drawSquares(0x1C02);
 glMatrixMode(0x1701);
 glPopMatrix();
 glFlush();
 hits = glRenderMode(0x1C00);
 processHits(hits, selectBuf);
 glutPostRedisplay();
}

variable_types: button int

variable_types: state int

variable_types:
selectBuf
unsigned int [512]

variable_types:
viewport
int [4]


keyboard

canonical_decompiled_code:
void __fastcall func9(char a1)
{
if ( a1 == 27 )
exit(0);
}

canonical_original_code:
void keyboard(unsigned char key, int x, int y)
{
 switch(key)
 {
  case 27:
   exit(0);
   break;
 }
}


makeImage

variable_types: i int

variable_types: j int

variable_types: ti float

variable_types: tj float


keyboard

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


initlights

decompiled_code:
__int64 initlights()
{
glEnable();
glEnable();
glLightfv();
glLightfv();
glMaterialfv();
glMaterialfv();
return glMaterialfv();
}

canonical_decompiled_code:
__int64 func10()
{
glEnable();
glEnable();
glLightfv();
glLightfv();
glMaterialfv();
glMaterialfv();
return glMaterialfv();
}

original_code:
void initlights(void)
{
 GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
 GLfloat position[] = {0.0, 0.0, 2.0, 1.0};
 GLfloat mat_diffuse[] = {0.6, 0.6, 0.6, 1.0};
 GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
 GLfloat mat_shininess[] = {50.0};
 glEnable(0x0B50);
 glEnable(0x4000);
 glLightfv(0x4000, 0x1200, ambient);
 glLightfv(0x4000, 0x1203, position);
 glMaterialfv(0x0404, 0x1201, mat_diffuse);
 glMaterialfv(0x0404, 0x1202, mat_specular);
 glMaterialfv(0x0404, 0x1601, mat_shininess);
}

canonical_original_code:
void initlights()
{
 float ambient[] = {0.2, 0.2, 0.2, 1.0};
 float position[] = {0.0, 0.0, 2.0, 1.0};
 float mat_diffuse[] = {0.6, 0.6, 0.6, 1.0};
 float mat_specular[] = {1.0, 1.0, 1.0, 1.0};
 float mat_shininess[] = {50.0};
 glEnable(0x0B50);
 glEnable(0x4000);
 glLightfv(0x4000, 0x1200, ambient);
 glLightfv(0x4000, 0x1203, position);
 glMaterialfv(0x0404, 0x1201, mat_diffuse);
 glMaterialfv(0x0404, 0x1202, mat_specular);
 glMaterialfv(0x0404, 0x1601, mat_shininess);
}

variable_types:
ambient
float []

variable_types:
position
float []


nurbsError

decompiled_code:
void __noreturn nurbsError()
{
const char *v0; // rax

v0 = (const char *)gluErrorString();
fprintf(stderr, "Nurbs Error: %s\n", v0);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
const char *v0; // rax

v0 = (const char *)gluErrorString();
fprintf(stderr, "Nurbs Error: %s\n", v0);
exit(0);
}

original_code:
void nurbsError(GLenum errorCode)
{
 const GLubyte *estring;
 estring = gluErrorString(errorCode);
 fprintf(stderr, "Nurbs Error: %s\n", estring);
 exit(0);
}

canonical_original_code:
void nurbsError(unsigned int errorCode)
{
 unsigned char *estring;
 estring = gluErrorString(errorCode);
 fprintf(stderr, "Nurbs Error: %s\n", estring);
 exit(0);
}

variable_types:
errorCode
unsigned int

variable_types:
estring
unsigned char *


decompiled_code:
float *init_surface()
{
float *v0; // r8
int v1; // esi
unsigned int v2; // edi
float v3; // xmm1_4
float *result; // rax
int i; // edx
float v6; // xmm0_4
int v7; // xmm0_4

v0 = (float *)&ctlpoints;
v1 = -1;
do
{
v2 = v1++;
result = v0;
for ( i = 0; i != 4; ++i )
{
v3 = (float)v1 - 1.5 + (float)v1 - 1.5;
*result = v3;
v6 = (float)i - 1.5 + (float)i - 1.5;
result[1] = v6;
if ( v2 <= 1 )
{
v7 = -1069547520;
if ( (unsigned int)(i - 1) <= 1 )
v7 = 1077936128;
}
else
{
v7 = -1069547520;
}
*((_DWORD *)result + 2) = v7;
result += 3;
}
v0 += 12;
}
while ( v1 != 3 );
return result;
}

variable_types: u int

variable_types: v int


renderTeapot

decompiled_code:
__int64 renderTeapot()
{
glPushMatrix();
glTranslatef();
glMaterialfv();
glMaterialfv();
glMaterialfv();
glMaterialf();
glCallList();
return glPopMatrix();
}

canonical_decompiled_code:
__int64 func12()
{
glPushMatrix();
glTranslatef();
glMaterialfv();
glMaterialfv();
glMaterialfv();
glMaterialf();
glCallList();
return glPopMatrix();
}

original_code:
void renderTeapot(GLfloat x, GLfloat y, GLfloat ambr, GLfloat ambg, GLfloat ambb, GLfloat difr, GLfloat difg, GLfloat difb,
 GLfloat specr, GLfloat specg, GLfloat specb, GLfloat shine)
{
 GLfloat mat[4];
 glPushMatrix();
 glTranslatef(x, y, 0.0);
 mat[0] = ambr;
 mat[1] = ambg;
 mat[2] = ambb;
 mat[3] = 1.0;
 glMaterialfv(0x0404, 0x1200, mat);
 mat[0] = difr;
 mat[1] = difg;
 mat[2] = difb;
 glMaterialfv(0x0404, 0x1201, mat);
 mat[0] = specr;
 mat[1] = specg;
 mat[2] = specb;
 glMaterialfv(0x0404, 0x1202, mat);
 glMaterialf(0x0404, 0x1601, shine * 128.0);
 glCallList(teapotList);
 glPopMatrix();
}

canonical_original_code:
void renderTeapot(float x, float y, float ambr, float ambg, float ambb, float difr, float difg, float difb, float specr, float specg, float specb, float shine)
{
 float mat[4];
 glPushMatrix();
 glTranslatef(x, y, 0.0);
 mat[0] = ambr;
 mat[1] = ambg;
 mat[2] = ambb;
 mat[3] = 1.0;
 glMaterialfv(0x0404, 0x1200, mat);
 mat[0] = difr;
 mat[1] = difg;
 mat[2] = difb;
 glMaterialfv(0x0404, 0x1201, mat);
 mat[0] = specr;
 mat[1] = specg;
 mat[2] = specb;
 glMaterialfv(0x0404, 0x1202, mat);
 glMaterialf(0x0404, 0x1601, shine * 128.0);
 glCallList(teapotList);
 glPopMatrix();
}

variable_types: x float

variable_types: y float

variable_types: ambr float

variable_types: ambg float

variable_types: ambb float

variable_types: difr float

variable_types: difg float

variable_types: difb float

variable_types: specr float

variable_types: specg float

variable_types: specb float

variable_types: shine float

variable_types:
mat
float [4]


keyboard

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


processHits

decompiled_code:
int __fastcall processHits(unsigned int a1, unsigned int *a2)
{
int result; // eax
int i; // er13
unsigned int v5; // er12
unsigned int *v6; // r14
__int64 v7; // rbp
unsigned int *v8; // rbx

result = printf("hits = %d\n", a1);
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v5 = *a2;
printf(" number of names for hit = %d\n", *a2);
printf(" z1 is %g;", (float)((float)(int)a2[1] * 4.6566129e-10));
printf(" z2 is %g\n", (float)((float)(int)a2[2] * 4.6566129e-10));
v6 = a2 + 3;
printf(" the name is ");
if ( v5 )
{
v7 = (__int64)&a2[v5 + 3];
v8 = a2 + 3;
do
printf("%d ", *v8++);
while ( v8 != (unsigned int *)v7 );
a2 = &v6[v5];
}
else
{
a2 += 3;
}
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1, unsigned int *a2)
{
int result; // eax
int i; // er13
unsigned int v5; // er12
unsigned int *v6; // r14
__int64 v7; // rbp
unsigned int *v8; // rbx

result = printf("hits = %d\n", a1);
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v5 = *a2;
printf(" number of names for hit = %d\n", *a2);
printf(" z1 is %g;", (float)((float)(int)a2[1] * 4.6566129e-10));
printf(" z2 is %g\n", (float)((float)(int)a2[2] * 4.6566129e-10));
v6 = a2 + 3;
printf(" the name is ");
if ( v5 )
{
v7 = (__int64)&a2[v5 + 3];
v8 = a2 + 3;
do
printf("%d ", *v8++);
while ( v8 != (unsigned int *)v7 );
a2 = &v6[v5];
}
else
{
a2 += 3;
}
result = putchar(10);
}
}
return result;
}

variable_types: hits int

variable_types:
buffer
unsigned int []

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
ii
unsigned int

variable_types:
jj
unsigned int

variable_types:
names
unsigned int

variable_types:
ptr
unsigned int *


keyboard

canonical_decompiled_code:
void __fastcall func7(char a1)
{
if ( a1 == 27 )
exit(0);
}


processHits

canonical_decompiled_code:
int __fastcall func11(unsigned int a1, unsigned int *a2)
{
int result; // eax
int i; // er13
unsigned int v5; // er12
unsigned int *v6; // r14
__int64 v7; // rbp
unsigned int *v8; // rbx

result = printf("hits = %d\n", a1);
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v5 = *a2;
printf(" number of names for hit = %d\n", *a2);
printf(" z1 is %g;", (float)((float)(int)a2[1] * 4.6566129e-10));
printf(" z2 is %g\n", (float)((float)(int)a2[2] * 4.6566129e-10));
v6 = a2 + 3;
printf(" the name is ");
if ( v5 )
{
v7 = (__int64)&a2[v5 + 3];
v8 = a2 + 3;
do
printf("%d ", *v8++);
while ( v8 != (unsigned int *)v7 );
a2 = &v6[v5];
}
else
{
a2 += 3;
}
result = putchar(10);
}
}
return result;
}


keyboard

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

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 84 )
{
polySmooth = polySmooth == 0;
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}

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

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 84 )
{
polySmooth = polySmooth == 0;
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}


decompiled_code:
__int64 __fastcall keyboard(int a1)
{
__int64 result; // rax
double v2; // xmm0_8

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 87 )
{
v2 = *(double *)&currentWinding;
if ( *(double *)&currentWinding == 100130.0 )
{
currentWinding = 0x40F8723000000000LL;
}
else if ( *(double *)&currentWinding == 100131.0 )
{
currentWinding = 0x40F8724000000000LL;
}
else if ( *(double *)&currentWinding == 100132.0 )
{
currentWinding = 0x40F8725000000000LL;
}
else if ( *(double *)&currentWinding == 100133.0 )
{
currentWinding = 0x40F8726000000000LL;
}
else if ( *(double *)&currentWinding == 100134.0 )
{
currentWinding = 0x40F8722000000000LL;
}
makeNewLists(v2);
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
__int64 result; // rax
double v2; // xmm0_8

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 87 )
{
v2 = *(double *)&currentWinding;
if ( *(double *)&currentWinding == 100130.0 )
{
currentWinding = 0x40F8723000000000LL;
}
else if ( *(double *)&currentWinding == 100131.0 )
{
currentWinding = 0x40F8724000000000LL;
}
else if ( *(double *)&currentWinding == 100132.0 )
{
currentWinding = 0x40F8725000000000LL;
}
else if ( *(double *)&currentWinding == 100133.0 )
{
currentWinding = 0x40F8726000000000LL;
}
else if ( *(double *)&currentWinding == 100134.0 )
{
currentWinding = 0x40F8722000000000LL;
}
func12(v2);
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}


decompiled_code:
__int64 __fastcall keyboard(char a1)
{
__int64 result; // rax
int v2; // xmm0_4
int v3; // xmm0_4

switch ( a1 )
{
case 'F':
*(float *)&v2 = *(float *)&polyfactor + 0.1;
polyfactor = v2;
printf("polyfactor is %f\n", *(float *)&v2);
result = glutPostRedisplay();
break;
case 'T':
if ( *(float *)&tdist > -5.0 )
{
*(float *)&tdist = *(float *)&tdist - 0.5;
result = glutPostRedisplay();
}
break;
case 'U':
*(float *)&polyunits = *(float *)&polyunits + 1.0;
printf("polyunits is %f\n", *(float *)&polyunits);
result = glutPostRedisplay();
break;
case 'f':
*(float *)&v3 = *(float *)&polyfactor - 0.1;
polyfactor = v3;
printf("polyfactor is %f\n", *(float *)&v3);
result = glutPostRedisplay();
break;
case 't':
if ( *(float *)&tdist < 4.0 )
{
*(float *)&tdist = *(float *)&tdist + 0.5;
result = glutPostRedisplay();
}
break;
case 'u':
*(float *)&polyunits = *(float *)&polyunits - 1.0;
printf("polyunits is %f\n", *(float *)&polyunits);
result = glutPostRedisplay();
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
__int64 result; // rax
int v2; // xmm0_4
int v3; // xmm0_4

switch ( a1 )
{
case 'F':
*(float *)&v2 = *(float *)&polyfactor + 0.1;
polyfactor = v2;
printf("polyfactor is %f\n", *(float *)&v2);
result = glutPostRedisplay();
break;
case 'T':
if ( *(float *)&tdist > -5.0 )
{
*(float *)&tdist = *(float *)&tdist - 0.5;
result = glutPostRedisplay();
}
break;
case 'U':
*(float *)&polyunits = *(float *)&polyunits + 1.0;
printf("polyunits is %f\n", *(float *)&polyunits);
result = glutPostRedisplay();
break;
case 'f':
*(float *)&v3 = *(float *)&polyfactor - 0.1;
polyfactor = v3;
printf("polyfactor is %f\n", *(float *)&v3);
result = glutPostRedisplay();
break;
case 't':
if ( *(float *)&tdist < 4.0 )
{
*(float *)&tdist = *(float *)&tdist + 0.5;
result = glutPostRedisplay();
}
break;
case 'u':
*(float *)&polyunits = *(float *)&polyunits - 1.0;
printf("polyunits is %f\n", *(float *)&polyunits);
result = glutPostRedisplay();
break;
default:
return result;
}
return result;
}


decompiled_code:
__int64 __fastcall keyboard(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 <= 0x79u )
{
if ( a1 <= 0x57u )
{
if ( a1 == 27 )
exit(0);
if ( a1 == 73 )
{
LABEL_6:
glLoadIdentity();
gluLookAt();
result = glutPostRedisplay();
}
}
else
{
switch ( a1 )
{
case 'X':
case 'Y':
case 'x':
case 'y':
glRotatef();
result = glutPostRedisplay();
break;
case 'i':
goto LABEL_6;
default:
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 <= 0x79u )
{
if ( a1 <= 0x57u )
{
if ( a1 == 27 )
exit(0);
if ( a1 == 73 )
{
LABEL_6:
glLoadIdentity();
gluLookAt();
result = glutPostRedisplay();
}
}
else
{
switch ( a1 )
{
case 'X':
case 'Y':
case 'x':
case 'y':
glRotatef();
result = glutPostRedisplay();
break;
case 'i':
goto LABEL_6;
default:
return result;
}
}
}
return result;
}


decompiled_code:
int __fastcall keyboard(unsigned __int8 a1)
{
int result; // eax
__m128d v2; // xmm1
__m128d v3; // xmm0
__m128d v4; // xmm0

if ( a1 == 90 )
{
v4.m128d_f64[0] = *(double *)&zoomFactor - 0.5;
v4.m128d_f64[0] = _mm_cmple_sd(v4, (__m128d)0x3FE0000000000000uLL).m128d_f64[0];
zoomFactor = ~*(_QWORD *)&v4.m128d_f64[0] & COERCE_UNSIGNED_INT64(*(double *)&zoomFactor - 0.5) | *(_QWORD *)&v4.m128d_f64[0] & 0x3FE0000000000000LL;
return printf("zoomFactor is now %4.1f\n", *(double *)&zoomFactor);
}
if ( a1 > 0x5Au )
{
if ( a1 == 114 )
{
LABEL_5:
zoomFactor = 0x3FF0000000000000LL;
glutPostRedisplay();
return puts("zoomFactor reset to 1.0");
}
if ( a1 == 122 )
{
v2.m128d_f64[0] = *(double *)&zoomFactor + 0.5;
v3.m128d_f64[0] = 3.0;
v3.m128d_f64[0] = _mm_cmple_sd(v3, v2).m128d_f64[0];
zoomFactor = ~*(_QWORD *)&v3.m128d_f64[0] & COERCE_UNSIGNED_INT64(*(double *)&zoomFactor + 0.5) | *(_QWORD *)&v3.m128d_f64[0] & 0x4008000000000000LL;
result = printf("zoomFactor is now %4.1f\n", *(double *)&zoomFactor);
}
}
else
{
if ( a1 == 27 )
exit(0);
if ( a1 == 82 )
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int8 a1)
{
int result; // eax
__m128d v2; // xmm1
__m128d v3; // xmm0
__m128d v4; // xmm0

if ( a1 == 90 )
{
v4.m128d_f64[0] = *(double *)&zoomFactor - 0.5;
v4.m128d_f64[0] = _mm_cmple_sd(v4, (__m128d)0x3FE0000000000000uLL).m128d_f64[0];
zoomFactor = ~*(_QWORD *)&v4.m128d_f64[0] & COERCE_UNSIGNED_INT64(*(double *)&zoomFactor - 0.5) | *(_QWORD *)&v4.m128d_f64[0] & 0x3FE0000000000000LL;
return printf("zoomFactor is now %4.1f\n", *(double *)&zoomFactor);
}
if ( a1 > 0x5Au )
{
if ( a1 == 114 )
{
LABEL_5:
zoomFactor = 0x3FF0000000000000LL;
glutPostRedisplay();
return puts("zoomFactor reset to 1.0");
}
if ( a1 == 122 )
{
v2.m128d_f64[0] = *(double *)&zoomFactor + 0.5;
v3.m128d_f64[0] = 3.0;
v3.m128d_f64[0] = _mm_cmple_sd(v3, v2).m128d_f64[0];
zoomFactor = ~*(_QWORD *)&v3.m128d_f64[0] & COERCE_UNSIGNED_INT64(*(double *)&zoomFactor + 0.5) | *(_QWORD *)&v3.m128d_f64[0] & 0x4008000000000000LL;
result = printf("zoomFactor is now %4.1f\n", *(double *)&zoomFactor);
}
}
else
{
if ( a1 == 27 )
exit(0);
if ( a1 == 82 )
goto LABEL_5;
}
return result;
}


decompiled_code:
__int64 __fastcall keyboard(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 == 83 )
goto LABEL_8;
if ( a1 <= 0x53u )
{
if ( a1 == 27 )
exit(0);
if ( a1 == 82 )
goto LABEL_5;
return result;
}
if ( a1 == 114 )
{
LABEL_5:
glBindTexture();
glTexImage2D();
return glutPostRedisplay();
}
if ( a1 == 115 )
{
LABEL_8:
glBindTexture();
glTexSubImage2D();
result = glutPostRedisplay();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 == 83 )
goto LABEL_8;
if ( a1 <= 0x53u )
{
if ( a1 == 27 )
exit(0);
if ( a1 == 82 )
goto LABEL_5;
return result;
}
if ( a1 == 114 )
{
LABEL_5:
glBindTexture();
glTexImage2D();
return glutPostRedisplay();
}
if ( a1 == 115 )
{
LABEL_8:
glBindTexture();
glTexSubImage2D();
result = glutPostRedisplay();
}
return result;
}


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

if ( a1 == 27 )
exit(0);
if ( a1 == 32 )
result = glutPostRedisplay();
return result;
}

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

if ( a1 == 27 )
exit(0);
if ( a1 == 32 )
result = glutPostRedisplay();
return result;
}


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

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 84 )
{
leftFirst = leftFirst == 0;
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}

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

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 84 )
{
leftFirst = leftFirst == 0;
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}


decompiled_code:
__int64 __fastcall keyboard(int a1)
{
if ( (_BYTE)a1 == 27 )
exit(0);
return (unsigned int)(a1 - 69);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
if ( (_BYTE)a1 == 27 )
exit(0);
return (unsigned int)(a1 - 69);
}


decompiled_code:
__int64 __fastcall keyboard(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 == 82 )
goto LABEL_9;
if ( a1 <= 0x52u )
{
if ( a1 == 27 )
exit(0);
if ( a1 == 65 )
goto LABEL_5;
return result;
}
if ( a1 == 97 )
{
LABEL_5:
solidZ = 1090519040;
transparentZ = -1056964608;
return glutIdleFunc();
}
if ( a1 == 114 )
{
LABEL_9:
solidZ = 1090519040;
transparentZ = -1056964608;
result = glutPostRedisplay();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 == 82 )
goto LABEL_9;
if ( a1 <= 0x52u )
{
if ( a1 == 27 )
exit(0);
if ( a1 == 65 )
goto LABEL_5;
return result;
}
if ( a1 == 97 )
{
LABEL_5:
solidZ = 1090519040;
transparentZ = -1056964608;
return glutIdleFunc();
}
if ( a1 == 114 )
{
LABEL_9:
solidZ = 1090519040;
transparentZ = -1056964608;
result = glutPostRedisplay();
}
return result;
}


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

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 70 )
{
switch ( fogMode )
{
case 2048:
fogMode = 2049;
puts("Fog mode is GL_EXP2");
break;
case 2049:
fogMode = 9729;
puts("Fog mode is GL_LINEAR");
break;
case 9729:
fogMode = 2048;
puts("Fog mode is GL_EXP");
break;
}
glFogi();
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}

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

result = a1 & 0xFFFFFFDF;
if ( (a1 & 0xDF) == 70 )
{
switch ( fogMode )
{
case 2048:
fogMode = 2049;
puts("Fog mode is GL_EXP2");
break;
case 2049:
fogMode = 9729;
puts("Fog mode is GL_LINEAR");
break;
case 9729:
fogMode = 2048;
puts("Fog mode is GL_EXP");
break;
}
glFogi();
result = glutPostRedisplay();
}
else if ( (_BYTE)a1 == 27 )
{
exit(0);
}
return result;
}


decompiled_code:
void __fastcall keyboard(char a1)
{
if ( a1 == 27 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func10(char a1)
{
if ( a1 == 27 )
exit(0);
}


printSymbol

decompiled_code:
__int64 __fastcall printSymbol(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v7; // er13
int v8; // er12
__int64 result; // rax
unsigned int v10; // er15
char *v11; // rax
int v12; // ebp
unsigned int *v13; // rbx
char dest[4]; // [rsp+Ah] [rbp-3Eh] BYREF
__int16 v15; // [rsp+Eh] [rbp-3Ah] BYREF

v7 = *(_DWORD *)(a4 + 4LL * (int)a1);
v8 = *(_DWORD *)(a4 + 4LL * (int)a1 + 4) - v7;
if ( debugQ )
printf("@ VECTOR_BYTE_COUNT:\t%d = %d - %d\n", (unsigned int)v8, *(unsigned int *)(a4 + 4LL * (int)a1 + 4), v7);
result = 0LL;
if ( v8 > 0 )
{
v10 = a1 + 10 * a2;
*(_DWORD *)dest = 0;
v15 = 0;
strncpy(dest, (const char *)(a3 + (int)(5 * a1)), 5uLL);
v11 = (char *)&v15;
do
{
if ( *v11 != 32 )
break;
*v11-- = 0;
}
while ( v11 != dest );
v12 = v8 % 3;
if ( v8 % 3 )
{
printf("Error: vector byte count is not a multiple of 3: %d\n", (unsigned int)v8);
printf("\tsymbol name: %s\n", dest);
printf("\tfile index: %d\n", a1);
printf("\tsymbol index: %d\n", v10);
exit(1);
}
puts("\n@@BEGIN: SYMBOL");
printf("@LABEL:\t\t%s\n", dest);
printf("@LIBINDEX:\t%d\n", v10);
puts("@DEFINITION:");
v13 = (unsigned int *)(a5 + 4LL * (int)(v7 - 1));
do
{
printf("\t%d %d %d\n", *v13, v13[1], v13[2]);
v12 += 3;
v13 += 3;
}
while ( v8 > v12 );
puts("@@END: SYMBOL\n");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v7; // er13
int v8; // er12
__int64 result; // rax
unsigned int v10; // er15
char *v11; // rax
int v12; // ebp
unsigned int *v13; // rbx
char dest[4]; // [rsp+Ah] [rbp-3Eh] BYREF
__int16 v15; // [rsp+Eh] [rbp-3Ah] BYREF

v7 = *(_DWORD *)(a4 + 4LL * (int)a1);
v8 = *(_DWORD *)(a4 + 4LL * (int)a1 + 4) - v7;
if ( debugQ )
printf("@ VECTOR_BYTE_COUNT:\t%d = %d - %d\n", (unsigned int)v8, *(unsigned int *)(a4 + 4LL * (int)a1 + 4), v7);
result = 0LL;
if ( v8 > 0 )
{
v10 = a1 + 10 * a2;
*(_DWORD *)dest = 0;
v15 = 0;
strncpy(dest, (const char *)(a3 + (int)(5 * a1)), 5uLL);
v11 = (char *)&v15;
do
{
if ( *v11 != 32 )
break;
*v11-- = 0;
}
while ( v11 != dest );
v12 = v8 % 3;
if ( v8 % 3 )
{
printf("Error: vector byte count is not a multiple of 3: %d\n", (unsigned int)v8);
printf("\tsymbol name: %s\n", dest);
printf("\tfile index: %d\n", a1);
printf("\tsymbol index: %d\n", v10);
exit(1);
}
puts("\n@@BEGIN: SYMBOL");
printf("@LABEL:\t\t%s\n", dest);
printf("@LIBINDEX:\t%d\n", v10);
puts("@DEFINITION:");
v13 = (unsigned int *)(a5 + 4LL * (int)(v7 - 1));
do
{
printf("\t%d %d %d\n", *v13, v13[1], v13[2]);
v12 += 3;
v13 += 3;
}
while ( v8 > v12 );
puts("@@END: SYMBOL\n");
result = 1LL;
}
return result;
}

original_code:
int printSymbol(int index, int symbolOffset, char* fontNames,
      int* vectorOffsets, int* vectors) {
   int vectorStart = vectorOffsets[index] - 1;
   int vectorByteCount = vectorOffsets[index+1] - vectorOffsets[index];
   if (debugQ) {
      printf("@ VECTOR_BYTE_COUNT:\t%d = %d - %d\n", vectorByteCount,
         vectorOffsets[index+1], vectorOffsets[index]
      );
   }
   if (vectorByteCount == 0) {
      return 0;
   }
   if (vectorByteCount < 0) {
      return 0;
   }
   int symbolIndex = symbolOffset * 10 + index;
   char symbolName [6] = {0};
   int i;
   strncpy(symbolName, &fontNames[index * 5], 5);
   for (i=4; i>0; i--) {
      if (symbolName[i] == ' ') {
         symbolName[i] = '\0';
      } else {
         break;
      }
   }
   if (vectorByteCount % 3 != 0) {
      printf("Error: vector byte count is not a multiple of 3: %d\n",
         vectorByteCount);
      printf("\tsymbol name: %s\n", symbolName);
      printf("\tfile index: %d\n", index);
      printf("\tsymbol index: %d\n", symbolIndex);
      exit(1);
   }
   printf("\n@@BEGIN: SYMBOL\n");
   printf("@LABEL:\t\t%s\n", symbolName);
   printf("@LIBINDEX:\t%d\n", symbolIndex);
   printf("@DEFINITION:\n");
   for (i=0; i<vectorByteCount; i+=3) {
      printf("\t%d %d %d\n",
            vectors[vectorStart + i],
            vectors[vectorStart + i + 1],
            vectors[vectorStart + i + 2]);
   }
   printf("@@END: SYMBOL\n\n");
   return 1;
}

canonical_original_code:
int printSymbol(int index, int symbolOffset, char *fontNames, int *vectorOffsets, int *vectors) {
   int vectorStart = vectorOffsets[index] - 1;
   int vectorByteCount = vectorOffsets[index+1] - vectorOffsets[index];
   if (debugQ) {
      printf("@ VECTOR_BYTE_COUNT:\t%d = %d - %d\n", vectorByteCount,
         vectorOffsets[index+1], vectorOffsets[index]
      );
   }
   if (vectorByteCount == 0) {
      return 0;
   }
   if (vectorByteCount < 0) {
      return 0;
   }
   int symbolIndex = symbolOffset * 10 + index;
   char symbolName[6] = {0};
   int i;
   strncpy(symbolName, &fontNames[index * 5], 5);
   for (i=4; i>0; i--) {
      if (symbolName[i] == ' ') {
         symbolName[i] = '\0';
      } else {
         break;
      }
   }
   if (vectorByteCount % 3 != 0) {
      printf("Error: vector byte count is not a multiple of 3: %d\n",
         vectorByteCount);
      printf("\tsymbol name: %s\n", symbolName);
      printf("\tfile index: %d\n", index);
      printf("\tsymbol index: %d\n", symbolIndex);
      exit(1);
   }
   printf("\n@@BEGIN: SYMBOL\n");
   printf("@LABEL:\t\t%s\n", symbolName);
   printf("@LIBINDEX:\t%d\n", symbolIndex);
   printf("@DEFINITION:\n");
   for (i=0; i<vectorByteCount; i+=3) {
      printf("\t%d %d %d\n",
            vectors[vectorStart + i],
            vectors[vectorStart + i + 1],
            vectors[vectorStart + i + 2]);
   }
   printf("@@END: SYMBOL\n\n");
   return 1;
}

variable_types: index int

variable_types: symbolOffset int

variable_types:
fontNames
char *

variable_types:
vectorOffsets
int *

variable_types:
vectors
int *

variable_types: vectorStart int

variable_types: vectorByteCount int

variable_types: symbolIndex int

variable_types:
symbolName
char [6]

variable_types: i int


getSymbolLibraryOffset

decompiled_code:
__int64 __fastcall getSymbolLibraryOffset(char *s)
{
int v1; // ebx
char *v2; // rax
int v3; // er13
const __int32_t **v4; // rax
const __int32_t *v5; // r12
const unsigned __int16 **v6; // rax
__int64 v7; // rdx
const unsigned __int16 *v8; // rcx
__int64 result; // rax

v1 = strlen(s);
v2 = strrchr(s, 46);
v3 = 0;
if ( v2 )
v3 = strlen(v2);
v4 = __ctype_tolower_loc();
v5 = *v4;
if ( (*v4)[s[v1 - 3 - v3]] == 98 && v5[s[v1 - 4 - v3]] == 105 && v5[s[v1 - 5 - v3]] == 108 )
return (unsigned int)(26 * (v5[s[v1 - 2 - v3]] - 114) + v5[s[v1 - 1 - v3]] - 97);
v6 = __ctype_b_loc();
v7 = s[v1 - 1 - v3];
v8 = *v6;
result = 0LL;
if ( (v8[v7] & 0x800) != 0 )
result = (unsigned int)(v5[v7] - 48);
return result;
}

original_code:
int getSymbolLibraryOffset(const char* filename) {
   int length = strlen(filename);
   char* extension = strrchr(filename, '.');
   int xlen = 0;
   if (extension != ((void *)0)) {
      xlen = strlen(extension);
   }
   int char1;
   int char2;
   if ((tolower(filename[length-3-xlen]) == 'b') &&
       (tolower(filename[length-4-xlen]) == 'i') &&
       (tolower(filename[length-5-xlen]) == 'l')) {
      char1 = tolower(filename[length-2-xlen]) - 'r';
      char2 = tolower(filename[length-1-xlen]) - 'a';
      return char1 * 26 + char2;
   }
   if (((*__ctype_b_loc ())[(int) ((filename[length-1-xlen]))] & (unsigned short int) _ISdigit)) {
      char1 = tolower(filename[length-1-xlen]) - '0';
      return char1;
   }
   return 0;
}

canonical_original_code:
int getSymbolLibraryOffset(char *filename) {
   int length = strlen(filename);
   char *extension = strrchr(filename, '.');
   int xlen = 0;
   if (extension != ((void *)0)) {
      xlen = strlen(extension);
   }
   int char1;
   int char2;
   if ((tolower(filename[length-3-xlen]) == 'b') &&
       (tolower(filename[length-4-xlen]) == 'i') &&
       (tolower(filename[length-5-xlen]) == 'l')) {
      char1 = tolower(filename[length-2-xlen]) - 'r';
      char2 = tolower(filename[length-1-xlen]) - 'a';
      return char1 * 26 + char2;
   }
   if (((*__ctype_b_loc ())[(int) ((filename[length-1-xlen]))] & (unsigned short) _ISdigit)) {
      char1 = tolower(filename[length-1-xlen]) - '0';
      return char1;
   }
   return 0;
}

variable_types:
filename
char *

variable_types: length int

variable_types:
extension
char *

variable_types: xlen int


printDrawData

decompiled_code:
__int64 __fastcall printDrawData(char *a1, __int64 a2, __int64 a3, __int64 a4)
{
int v6; // ebp
unsigned int i; // ebx
__int64 result; // rax

v6 = getSymbolLibraryOffset(a1);
for ( i = 0; i != 10; ++i )
{
result = printSymbol(i, v6, a2, a3, a4);
if ( !(_DWORD)result )
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, __int64 a2, __int64 a3, __int64 a4)
{
int v6; // ebp
unsigned int i; // ebx
__int64 result; // rax

v6 = func8(a1);
for ( i = 0; i != 10; ++i )
{
result = func7(i, v6, a2, a3, a4);
if ( !(_DWORD)result )
break;
}
return result;
}

original_code:
void printDrawData(const char* filename, char* fontNames, int* vectorOffsets,
      int* vectors) {
   int symbolOffset = getSymbolLibraryOffset(filename);
   int i;
   int flag;
   for (i=0; i<10; i++) {
      flag = printSymbol(i, symbolOffset, fontNames, vectorOffsets, vectors);
      if (!flag) {
         break;
      }
   }
}

canonical_original_code:
void printDrawData(char *filename, char *fontNames, int *vectorOffsets, int *vectors) {
   int symbolOffset = getSymbolLibraryOffset(filename);
   int i;
   int flag;
   for (i=0; i<10; i++) {
      flag = printSymbol(i, symbolOffset, fontNames, vectorOffsets, vectors);
      if (!flag) {
         break;
      }
   }
}

variable_types: flag int


main

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

puts("@@BEGIN: FONT_LIBRARY");
if ( argc > 1 )
{
v3 = (char **)(argv + 1);
do
printBinaryDrawFileAsAscii(*v3++);
while ( v3 != (char **)&argv[(unsigned int)(argc - 2) + 2] );
}
puts("@@END: FONT_LIBRARY");
return 0;
}

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

puts("@@BEGIN: FONT_LIBRARY");
if ( argc > 1 )
{
v3 = (char **)(argv + 1);
do
func13(*v3++);
while ( v3 != (char **)&argv[(unsigned int)(argc - 2) + 2] );
}
puts("@@END: FONT_LIBRARY");
return 0;
}

original_code:
int main(int argc, char** argv) {
   int i;
   printf("@@BEGIN: FONT_LIBRARY\n");
   for (i=1; i<argc; i++) {
      printBinaryDrawFileAsAscii(argv[i]);
   }
   printf("@@END: FONT_LIBRARY\n");
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   int i;
   printf("@@BEGIN: FONT_LIBRARY\n");
   for (i=1; i<argc; i++) {
      printBinaryDrawFileAsAscii(argv[i]);
   }
   printf("@@END: FONT_LIBRARY\n");
   return 0;
}

variable_types: argc int

variable_types:
argv
char **


removeNewline

decompiled_code:
const char *__fastcall removeNewline(const char *a1)
{
int v1; // edx
const char *v2; // rax

v1 = strlen(a1);
if ( v1 - 1 >= 0 )
{
v2 = &a1[v1 - 1];
do
{
if ( *v2 != 10 && *v2 != 13 )
break;
*v2-- = 0;
}
while ( v2 != &a1[v1 - 2 - (v1 - 1)] );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
int v1; // edx
const char *v2; // rax

v1 = strlen(a1);
if ( v1 - 1 >= 0 )
{
v2 = &a1[v1 - 1];
do
{
if ( *v2 != 10 && *v2 != 13 )
break;
*v2-- = 0;
}
while ( v2 != &a1[v1 - 2 - (v1 - 1)] );
}
return a1;
}

original_code:
char* removeNewline(char* buffer) {
 int len = strlen(buffer);
 int i;
 for (i=len-1; i>=0; i--) {
  if ((buffer[i] == 0x0a) || (buffer[i] == 0x0d)) {
   buffer[i] = '\0';
  } else {
   return buffer;
  }
 }
 return buffer;
}

canonical_original_code:
char *removeNewline(char *buffer) {
 int len = strlen(buffer);
 int i;
 for (i=len-1; i>=0; i--) {
  if ((buffer[i] == 0x0a) || (buffer[i] == 0x0d)) {
   buffer[i] = '\0';
  } else {
   return buffer;
  }
 }
 return buffer;
}

variable_types:
buffer
char *

variable_types: len int


readAsciiNumberLine

decompiled_code:
__int64 __fastcall readAsciiNumberLine(__int64 a1, int a2, const char *a3)
{
int v4; // ebx
char *v5; // rax
char *v6; // rdi
float *v7; // rbp
double v8; // xmm0_8
float v9; // xmm0_4
__int64 v11[2]; // [rsp+0h] [rbp-418h] BYREF
char v12[1008]; // [rsp+10h] [rbp-408h] BYREF

v4 = a2;
v11[0] = 0LL;
v11[1] = 0LL;
memset(v12, 0, sizeof(v12));
strcpy((char *)v11, a3);
v5 = strtok((char *)v11, "\n\t ");
if ( v5 )
{
v6 = v5;
v7 = (float *)(a1 + 4LL * a2);
do
{
v8 = strtod(v6, 0LL);
if ( v4 > 100 )
{
puts("Error: item parameter count is too large");
exit(1);
}
++v4;
v9 = v8;
*v7 = v9;
v6 = strtok(0LL, "\n\t ");
++v7;
}
while ( v6 );
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, const char *a3)
{
int v4; // ebx
char *v5; // rax
char *v6; // rdi
float *v7; // rbp
double v8; // xmm0_8
float v9; // xmm0_4
__int64 v11[2]; // [rsp+0h] [rbp-418h] BYREF
char v12[1008]; // [rsp+10h] [rbp-408h] BYREF

v4 = a2;
v11[0] = 0LL;
v11[1] = 0LL;
memset(v12, 0, sizeof(v12));
strcpy((char *)v11, a3);
v5 = strtok((char *)v11, "\n\t ");
if ( v5 )
{
v6 = v5;
v7 = (float *)(a1 + 4LL * a2);
do
{
v8 = strtod(v6, 0LL);
if ( v4 > 100 )
{
puts("Error: item parameter count is too large");
exit(1);
}
++v4;
v9 = v8;
*v7 = v9;
v6 = strtok(0LL, "\n\t ");
++v7;
}
while ( v6 );
}
return (unsigned int)v4;
}

original_code:
int readAsciiNumberLine(float* param, int index, const char* string) {
 char buffer[1024] = {0};
 strcpy(buffer, string);
 char* ptr = strtok(buffer, "\n\t ");
 double number = 0.0;
 int counter = index;
 while (ptr != ((void *)0)) {
  number = strtod(ptr, ((void *)0));
  if (counter > 100) {
   printf("Error: item parameter count is too large\n");
   exit(1);
  }
  param[counter++] = number;
  ptr = strtok(((void *)0), "\n\t ");
 }
 return counter;
}

canonical_original_code:
int readAsciiNumberLine(float *param, int index, char *string) {
 char buffer[1024] = {0};
 strcpy(buffer, string);
 char *ptr = strtok(buffer, "\n\t ");
 double number = 0.0;
 int counter = index;
 while (ptr != ((void *)0)) {
  number = strtod(ptr, ((void *)0));
  if (counter > 100) {
   printf("Error: item parameter count is too large\n");
   exit(1);
  }
  param[counter++] = number;
  ptr = strtok(((void *)0), "\n\t ");
 }
 return counter;
}

variable_types:
param
float *

variable_types: index int

variable_types:
string
char *

variable_types:
buffer
char [1024]

variable_types:
ptr
char *

variable_types: number double

variable_types: counter int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc != 3 )
{
printf("Usage: %s input.pmx output.mus\n", *argv);
exit(1);
}
printAsciiFileAsBinary(argv[1], argv[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc != 3 )
{
printf("Usage: %s input.pmx output.mus\n", *argv);
exit(1);
}
func13(argv[1], argv[2]);
return 0;
}

original_code:
int main(int argc, char** argv) {
 if (argc != 3) {
  printf("Usage: %s input.pmx output.mus\n", argv[0]);
  exit(1);
 }
 printAsciiFileAsBinary(argv[1], argv[2]);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc != 3) {
  printf("Usage: %s input.pmx output.mus\n", argv[0]);
  exit(1);
 }
 printAsciiFileAsBinary(argv[1], argv[2]);
 return 0;
}


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

if ( argc <= 1 )
return 0;
for ( i = 1LL; i != argc; ++i )
{
if ( argc > 2 )
{
printf("##FILE:\t%s\n", argv[i]);
printBinaryPageFileAsAscii(argv[i]);
if ( argc - 1 > (int)i )
puts("##PAGEBREAK");
}
else
{
printBinaryPageFileAsAscii(argv[i]);
}
}
return 0;
}

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

if ( argc <= 1 )
return 0;
for ( i = 1LL; i != argc; ++i )
{
if ( argc > 2 )
{
printf("##FILE:\t%s\n", argv[i]);
func14(argv[i]);
if ( argc - 1 > (int)i )
puts("##PAGEBREAK");
}
else
{
func14(argv[i]);
}
}
return 0;
}

original_code:
int main(int argc, char** argv) {
 int i;
 for (i=1; i<argc; i++) {
  if (argc > 2) {
   printf("##FILE:\t%s\n", argv[i]);
  }
  printBinaryPageFileAsAscii(argv[i]);
  if ((i < argc-1) && (argc > 2)) {
   printf("##PAGEBREAK\n");
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int i;
 for (i=1; i<argc; i++) {
  if (argc > 2) {
   printf("##FILE:\t%s\n", argv[i]);
  }
  printBinaryPageFileAsAscii(argv[i]);
  if ((i < argc-1) && (argc > 2)) {
   printf("##PAGEBREAK\n");
  }
 }
 return 0;
}

variable_types: i int


decompiled_code:
int print_help()
{
puts("usage: yac8e [-h] [-s SCALE] [-d OP_DELAY] [-t] rom\n");
printf("Starts a simple Chip 8 emulator. See README.md for more ");
puts("information, and\n LICENSE for terms of use.\n");
puts("positional arguments:");
puts(" rom the ROM file to load on startup\n");
puts("optional arguments:");
puts(" -h show this help message and exit");
printf(" -s SCALE the scale factor to apply to the display ");
puts("(default is 5)");
printf(" -d OP_DELAY sets the CPU operation to take at least the ");
puts("specified number of milliseconds to execute (default is 1)");
return puts(" -t starts the CPU up in trace mode");
}

canonical_decompiled_code:
int func1()
{
puts("usage: yac8e [-h] [-s SCALE] [-d OP_DELAY] [-t] rom\n");
printf("Starts a simple Chip 8 emulator. See README.md for more ");
puts("information, and\n LICENSE for terms of use.\n");
puts("positional arguments:");
puts(" rom the ROM file to load on startup\n");
puts("optional arguments:");
puts(" -h show this help message and exit");
printf(" -s SCALE the scale factor to apply to the display ");
puts("(default is 5)");
printf(" -d OP_DELAY sets the CPU operation to take at least the ");
puts("specified number of milliseconds to execute (default is 1)");
return puts(" -t starts the CPU up in trace mode");
}

original_code:
void
print_help(void)
{
    printf("usage: yac8e [-h] [-s SCALE] [-d OP_DELAY] [-t] rom\n\n");
    printf("Starts a simple Chip 8 emulator. See README.md for more ");
    printf("information, and\n LICENSE for terms of use.\n\n");
    printf("positional arguments:\n");
    printf("  rom          the ROM file to load on startup\n\n");
    printf("optional arguments:\n");
    printf("  -h           show this help message and exit\n");
    printf("  -s SCALE     the scale factor to apply to the display ");
    printf("(default is 5)\n");
    printf("  -d OP_DELAY  sets the CPU operation to take at least the ");
    printf("specified number of milliseconds to execute (default is 1)\n");
    printf("  -t           starts the CPU up in trace mode\n");
}

canonical_original_code:
void print_help()
{
    printf("usage: yac8e [-h] [-s SCALE] [-d OP_DELAY] [-t] rom\n\n");
    printf("Starts a simple Chip 8 emulator. See README.md for more ");
    printf("information, and\n LICENSE for terms of use.\n\n");
    printf("positional arguments:\n");
    printf("  rom          the ROM file to load on startup\n\n");
    printf("optional arguments:\n");
    printf("  -h           show this help message and exit\n");
    printf("  -s SCALE     the scale factor to apply to the display ");
    printf("(default is 5)\n");
    printf("  -d OP_DELAY  sets the CPU operation to take at least the ");
    printf("specified number of milliseconds to execute (default is 1)\n");
    printf("  -t           starts the CPU up in trace mode\n");
}


decompiled_code:
__int64 __fastcall parse_options(int a1, __int64 a2)
{
__int64 v2; // r12
int i; // ebx
__int64 v4; // r15
__int64 v5; // rbp
char v6; // al

if ( a1 <= 1 )
goto LABEL_24;
v2 = 0LL;
for ( i = 1; i < a1; ++i )
{
v4 = 8LL * i;
v5 = *(_QWORD *)(a2 + v4);
if ( *(_BYTE *)v5 == 45 )
{
if ( strlen(*(const char **)(a2 + 8LL * i)) != 2 )
{
printf("Unrecognized option: %s\n", (const char *)v5);
print_help();
exit(1);
}
v6 = *(_BYTE *)(v5 + 1);
if ( v6 == 115 )
{
if ( a1 > ++i )
scale_factor = atoi(*(const char **)(a2 + v4 + 8));
}
else if ( v6 > 115 )
{
if ( v6 != 116 )
goto LABEL_10;
cpu[10] = 3;
}
else
{
if ( v6 != 100 )
{
if ( v6 == 104 )
{
print_help();
exit(0);
}
LABEL_10:
printf("Unrecognized option: %s\n", (const char *)v5);
print_help();
exit(1);
}
if ( a1 > ++i )
op_delay = atoi(*(const char **)(a2 + v4 + 8));
}
}
else
{
if ( v2 )
{
printf("Unrecognized parameter: %s\n", *(const char **)(a2 + 8LL * i));
print_help();
exit(1);
}
v2 = *(_QWORD *)(a2 + 8LL * i);
}
}
if ( !v2 )
{
LABEL_24:
puts("ROM file not specified");
print_help();
exit(1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 v2; // r12
int i; // ebx
__int64 v4; // r15
__int64 v5; // rbp
char v6; // al

if ( a1 <= 1 )
goto LABEL_24;
v2 = 0LL;
for ( i = 1; i < a1; ++i )
{
v4 = 8LL * i;
v5 = *(_QWORD *)(a2 + v4);
if ( *(_BYTE *)v5 == 45 )
{
if ( strlen(*(const char **)(a2 + 8LL * i)) != 2 )
{
printf("Unrecognized option: %s\n", (const char *)v5);
func1();
exit(1);
}
v6 = *(_BYTE *)(v5 + 1);
if ( v6 == 115 )
{
if ( a1 > ++i )
scale_factor = atoi(*(const char **)(a2 + v4 + 8));
}
else if ( v6 > 115 )
{
if ( v6 != 116 )
goto LABEL_10;
cpu[10] = 3;
}
else
{
if ( v6 != 100 )
{
if ( v6 == 104 )
{
func1();
exit(0);
}
LABEL_10:
printf("Unrecognized option: %s\n", (const char *)v5);
func1();
exit(1);
}
if ( a1 > ++i )
op_delay = atoi(*(const char **)(a2 + v4 + 8));
}
}
else
{
if ( v2 )
{
printf("Unrecognized parameter: %s\n", *(const char **)(a2 + 8LL * i));
func1();
exit(1);
}
v2 = *(_QWORD *)(a2 + 8LL * i);
}
}
if ( !v2 )
{
LABEL_24:
puts("ROM file not specified");
func1();
exit(1);
}
return v2;
}

original_code:
char *
parse_options(int argc, char **argv)
{
    int arg;
    char *filename = ((void *)0);
    for (arg = 1; arg < argc; arg++) {
        if ((argv[arg][0] == '-') && (strlen(argv[arg]) != 2)) {
            printf("Unrecognized option: %s\n", argv[arg]);
            print_help();
            exit(1);
        }
        else if ((argv[arg][0] == '-') && (strlen (argv[arg]) == 2)) {
            switch (argv[arg][1]) {
                case ('h'):
                    print_help();
                    exit(0);
                    break;
                case ('s'):
                    arg++;
                    if (arg < argc) {
                        scale_factor = atoi(argv[arg]);
                    }
                    break;
                case ('d'):
                    arg++;
                    if (arg < argc) {
                        op_delay = atoi(argv[arg]);
                    }
                    break;
                case ('t'):
                    cpu.state = 3;
                    break;
                default:
                    printf("Unrecognized option: %s\n", argv[arg]);
                    print_help();
                    exit(1);
                    break;
            }
        }
        else {
            if (filename == ((void *)0)) {
                filename = argv[arg];
            }
            else {
                printf("Unrecognized parameter: %s\n", argv[arg]);
                print_help();
                exit(1);
            }
        }
    }
    if (filename == ((void *)0)) {
        printf("ROM file not specified\n");
        print_help();
        exit(1);
    }
    return filename;
}

canonical_original_code:
char *parse_options(int argc, char **argv)
{
    int arg;
    char *filename = ((void *)0);
    for (arg = 1; arg < argc; arg++) {
        if ((argv[arg][0] == '-') && (strlen(argv[arg]) != 2)) {
            printf("Unrecognized option: %s\n", argv[arg]);
            print_help();
            exit(1);
        }
        else if ((argv[arg][0] == '-') && (strlen (argv[arg]) == 2)) {
            switch (argv[arg][1]) {
                case ('h'):
                    print_help();
                    exit(0);
                    break;
                case ('s'):
                    arg++;
                    if (arg < argc) {
                        scale_factor = atoi(argv[arg]);
                    }
                    break;
                case ('d'):
                    arg++;
                    if (arg < argc) {
                        op_delay = atoi(argv[arg]);
                    }
                    break;
                case ('t'):
                    cpu.state = 3;
                    break;
                default:
                    printf("Unrecognized option: %s\n", argv[arg]);
                    print_help();
                    exit(1);
                    break;
            }
        }
        else {
            if (filename == ((void *)0)) {
                filename = argv[arg];
            }
            else {
                printf("Unrecognized parameter: %s\n", argv[arg]);
                print_help();
                exit(1);
            }
        }
    }
    if (filename == ((void *)0)) {
        printf("ROM file not specified\n");
        print_help();
        exit(1);
    }
    return filename;
}

variable_types: arg int

variable_types:
filename
char *


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

scale_factor = 5;
cpu_reset(argc, argv, envp);
cpu[10] = 1;
v3 = (const char *)parse_options(argc, (__int64)argv);
if ( (int)SDL_Init(32LL) < 0 )
{
v4 = (const char *)SDL_GetError();
printf("Fatal: Unable to initialize SDL\n%s\n", v4);
exit(1);
}
if ( !(unsigned int)memory_init(4096LL) )
{
puts("Fatal: Unable to allocate emulator memory");
SDL_Quit();
exit(1);
}
if ( !(unsigned int)loadrom("FONTS.chip8", 0) )
{
puts("Fatal: Could not load FONTS.chip8");
memory_destroy();
SDL_Quit();
exit(1);
}
if ( !(unsigned int)loadrom(v3, 512) )
{
puts("Fatal: Emulator shutdown due to errors");
memory_destroy();
SDL_Quit();
exit(1);
}
if ( !(unsigned int)screen_init() )
{
puts("Fatal: Emulator shutdown due to errors");
memory_destroy();
SDL_Quit();
exit(0);
}
if ( !(unsigned int)cpu_timerinit() )
{
puts("Fatal: emulator shutdown due to errors");
memory_destroy();
SDL_Quit();
exit(1);
}
cpu_execute();
memory_destroy();
screen_destroy();
SDL_Quit();
return 0;
}

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

scale_factor = 5;
cpu_reset(argc, argv, envp);
cpu[10] = 1;
v3 = (const char *)func2(argc, (__int64)argv);
if ( (int)SDL_Init(32LL) < 0 )
{
v4 = (const char *)SDL_GetError();
printf("Fatal: Unable to initialize SDL\n%s\n", v4);
exit(1);
}
if ( !(unsigned int)memory_init(4096LL) )
{
puts("Fatal: Unable to allocate emulator memory");
SDL_Quit();
exit(1);
}
if ( !(unsigned int)func0("FONTS.chip8", 0) )
{
puts("Fatal: Could not load FONTS.chip8");
memory_destroy();
SDL_Quit();
exit(1);
}
if ( !(unsigned int)func0(v3, 512) )
{
puts("Fatal: Emulator shutdown due to errors");
memory_destroy();
SDL_Quit();
exit(1);
}
if ( !(unsigned int)screen_init() )
{
puts("Fatal: Emulator shutdown due to errors");
memory_destroy();
SDL_Quit();
exit(0);
}
if ( !(unsigned int)cpu_timerinit() )
{
puts("Fatal: emulator shutdown due to errors");
memory_destroy();
SDL_Quit();
exit(1);
}
cpu_execute();
memory_destroy();
screen_destroy();
SDL_Quit();
return 0;
}

original_code:
int
main(int argc, char **argv)
{
    char *filename;
    scale_factor = 5;
    cpu_reset();
    cpu.state = 1;
    filename = parse_options(argc, argv);
    if (SDL_Init(0x00000020) < 0) {
        printf("Fatal: Unable to initialize SDL\n%s\n", SDL_GetError());
        exit(1);
    }
    if (!memory_init(0x1000)) {
        printf ("Fatal: Unable to allocate emulator memory\n");
        SDL_Quit ();
        exit (1);
    }
    if (!loadrom("FONTS.chip8", 0)) {
        printf("Fatal: Could not load FONTS.chip8\n");
        memory_destroy();
        SDL_Quit();
        exit(1);
    }
    if (!loadrom(filename, 0x200)) {
        printf("Fatal: Emulator shutdown due to errors\n");
        memory_destroy();
        SDL_Quit();
        exit(1);
    }
    if (!screen_init()) {
        printf("Fatal: Emulator shutdown due to errors\n");
        memory_destroy();
        SDL_Quit();
        exit(0);
    }
    if (!cpu_timerinit()) {
        printf("Fatal: emulator shutdown due to errors\n");
        memory_destroy();
        SDL_Quit();
        exit(1);
    }
    cpu_execute();
    memory_destroy();
    screen_destroy();
    SDL_Quit();
    return 0;
}


decompiled_code:
_BOOL8 __fastcall screen_getpixel(int a1, int a2)
{
unsigned __int8 v3; // [rsp+Dh] [rbp-Bh] BYREF
unsigned __int8 v4; // [rsp+Eh] [rbp-Ah] BYREF
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

SDL_GetRGB(
*(unsigned int *)(*(_QWORD *)(virtscreen + 32)
+ 4LL * (a1 * scale_factor + *(_DWORD *)(virtscreen + 16) * scale_factor * a2)),
*(_QWORD *)(virtscreen + 8),
v5,
&v4,
&v3);
return COLOR_WHITE == (unsigned int)SDL_MapRGB(*(_QWORD *)(virtscreen + 8), (unsigned __int8)v5[0], v4, v3);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1, int a2)
{
unsigned __int8 v3; // [rsp+Dh] [rbp-Bh] BYREF
unsigned __int8 v4; // [rsp+Eh] [rbp-Ah] BYREF
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

SDL_GetRGB(
*(unsigned int *)(*(_QWORD *)(virtscreen + 32)
+ 4LL * (a1 * scale_factor + *(_DWORD *)(virtscreen + 16) * scale_factor * a2)),
*(_QWORD *)(virtscreen + 8),
v5,
&v4,
&v3);
return COLOR_WHITE == (unsigned int)SDL_MapRGB(*(_QWORD *)(virtscreen + 8), (unsigned __int8)v5[0], v4, v3);
}

original_code:
int
screen_getpixel(int x, int y)
{
    Uint8 r, g, b;
    Uint32 color = 0;
    int pixelcolor = 0;
    x = x * scale_factor;
    y = y * scale_factor;
    Uint32 *pixels = (Uint32 *)virtscreen->pixels;
    Uint32 pixel = pixels[(virtscreen->w * y) + x];
    SDL_GetRGB(pixel, virtscreen->format, &r, &g, &b);
    color = SDL_MapRGB(virtscreen->format, r, g, b);
    if (color == COLOR_WHITE) {
        pixelcolor = 1;
    }
    return pixelcolor;
}

canonical_original_code:
int screen_getpixel(int x, int y)
{
    unsigned char r; unsigned char g; unsigned char b;
    unsigned int color = 0;
    int pixelcolor = 0;
    x = x * scale_factor;
    y = y * scale_factor;
    unsigned int *pixels = (Uint32 *)virtscreen->pixels;
    unsigned int pixel = pixels[(virtscreen->w * y) + x];
    SDL_GetRGB(pixel, virtscreen->format, &r, &g, &b);
    color = SDL_MapRGB(virtscreen->format, r, g, b);
    if (color == COLOR_WHITE) {
        pixelcolor = 1;
    }
    return pixelcolor;
}

variable_types: x int

variable_types: y int

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types:
color
unsigned int

variable_types: pixelcolor int

variable_types:
pixels
unsigned int *

variable_types:
pixel
unsigned int


decompiled_code:
__int64 screen_blank()
{
return screen_clear(virtscreen, COLOR_BLACK);
}

canonical_decompiled_code:
__int64 func6()
{
return func5(virtscreen, COLOR_BLACK);
}

original_code:
void
screen_blank(void)
{
    screen_clear(virtscreen, COLOR_BLACK);
}

canonical_original_code:
void screen_blank()
{
    screen_clear(virtscreen, COLOR_BLACK);
}


decompiled_code:
__int64 __fastcall screen_refresh(int a1)
{
screen_blit_surface(virtscreen, screen, 0, 0);
if ( a1 )
{
screen_trace_message();
screen_blit_surface(overlay, screen, 0, 0);
}
screen_clear(overlay, COLOR_BLACK);
return SDL_UpdateRect(screen, 0LL, 0LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
func2(virtscreen, screen, 0, 0);
if ( a1 )
{
func4();
func2(overlay, screen, 0, 0);
}
func5(overlay, COLOR_BLACK);
return SDL_UpdateRect(screen, 0LL, 0LL, 0LL, 0LL);
}

original_code:
void
screen_refresh(int overlay_on)
{
    screen_blit_surface(virtscreen, screen, 0, 0);
    if (overlay_on) {
        screen_trace_message();
        screen_blit_surface(overlay, screen, 0, 0);
    }
    screen_clear(overlay, COLOR_BLACK);
    SDL_UpdateRect(screen, 0, 0, 0, 0);
}


decompiled_code:
__int64 __fastcall screen_draw(__int16 a1, __int16 a2, int a3)
{
bool v3; // zf
__int64 v4; // rdx
__int16 v6[8]; // [rsp+8h] [rbp-10h] BYREF

v6[0] = scale_factor * a1;
v6[1] = scale_factor * a2;
v6[2] = scale_factor;
v6[3] = scale_factor;
v3 = a3 == 0;
v4 = (unsigned int)COLOR_WHITE;
if ( v3 )
v4 = (unsigned int)COLOR_BLACK;
return SDL_FillRect(virtscreen, v6, v4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int16 a1, __int16 a2, int a3)
{
bool v3; // zf
__int64 v4; // rdx
__int16 v6[8]; // [rsp+8h] [rbp-10h] BYREF

v6[0] = scale_factor * a1;
v6[1] = scale_factor * a2;
v6[2] = scale_factor;
v6[3] = scale_factor;
v3 = a3 == 0;
v4 = (unsigned int)COLOR_WHITE;
if ( v3 )
v4 = (unsigned int)COLOR_BLACK;
return SDL_FillRect(virtscreen, v6, v4);
}

original_code:
void
screen_draw(int x, int y, int color)
{
    SDL_Rect pixel;
    Uint32 pixelcolor = COLOR_BLACK;
    pixel.x = x * scale_factor;
    pixel.y = y * scale_factor;
    pixel.w = scale_factor;
    pixel.h = scale_factor;
    if (color) {
        pixelcolor = COLOR_WHITE;
    }
    SDL_FillRect(virtscreen, &pixel, pixelcolor);
}

canonical_original_code:
void screen_draw(int x, int y, int color)
{
    struct SDL_Rect pixel;
    unsigned int pixelcolor = COLOR_BLACK;
    pixel.x = x * scale_factor;
    pixel.y = y * scale_factor;
    pixel.w = scale_factor;
    pixel.h = scale_factor;
    if (color) {
        pixelcolor = COLOR_WHITE;
    }
    SDL_FillRect(virtscreen, &pixel, pixelcolor);
}

variable_types: color int

variable_types: struct SDL_Rect { short x; unsigned short w; }

variable_types:
pixelcolor
unsigned int