decompiled_code:
void __fastcall set_node_addr(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 24) = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 24) = a2;
}

original_code:
void set_node_addr(symnode node, int addr)
{
  node->varaddr = addr;
}

canonical_original_code:
void set_node_addr(struct symnode *node, int addr)
{
  node->varaddr = addr;
}

variable_types: addr int

user_defined_types: enum vartype { inttype=0, doubletype=1, voidtype=2 }


repo: jakeleichtling/Compiler

decompiled_code:
_BOOL8 __fastcall name_is_equal(const char **a1, const char *a2)
{
return strcmp(*a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char **a1, const char *a2)
{
return strcmp(*a1, a2) == 0;
}

original_code:
int name_is_equal(symnode node, char *name) {
  return !strcmp(node->name, name);
}

canonical_original_code:
int name_is_equal(struct symnode *node, char *name) {
  return !strcmp(node->name, name);
}

variable_types: struct symnode { char *name; struct symnode *next; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } var_type; int var_addr; enum memaddrtype { off_fp=0, global=1 } mem_addr_type; enum nodetype { func_node=0, val_node=1, array_node=2 } node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; } *

variable_types:
name
char *

return_type: int

user_defined_types: struct symnode { char *name; struct symnode *next; enum vartype var_type; int var_addr; enum memaddrtype mem_addr_type; enum nodetype node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; }


decompiled_code:
void __fastcall destroy_symboltable(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // rdi

v1 = *a1;
while ( v1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
destroy_symhashtable(v2);
}
}

original_code:
void destroy_symboltable(symboltable symtab) {
  symhashtable table, outer;
  for (table = symtab->inner_scope; table != ((void *)0); table = outer) {
    outer = table->outer_scope;
    destroy_symhashtable(table);
  }
}

canonical_original_code:
void destroy_symboltable(struct symboltable *symtab) {
  struct symhashtable *table; struct symhashtable *outer;
  for (table = symtab->inner_scope; table != ((void *)0); table = outer) {
    outer = table->outer_scope;
    destroy_symhashtable(table);
  }
}

variable_types: struct symboltable { struct symhashtable { int size; struct symnode { char *name; struct symnode *next; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } var_type; int var_addr; enum memaddrtype { off_fp=0, global=1 } mem_addr_type; enum nodetype { func_node=0, val_node=1, array_node=2 } node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; } **table; struct symhashtable *outer_scope; int level; } *inner_scope; int num_nodes; } *

return_type: void

user_defined_types: struct symboltable { struct symhashtable *inner_scope; int num_nodes; }

user_defined_types: struct symhashtable { int size; struct symnode **table; struct symhashtable *outer_scope; int level; }


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

v1 = *a1;
*a1 = *(_QWORD *)(*a1 + 16);
destroy_symhashtable(v1);
}

original_code:
void leave_scope(symboltable symtab) {
  symhashtable hashtable = symtab->inner_scope;
  symtab->inner_scope = hashtable->outer_scope;
  destroy_symhashtable(hashtable);
}

canonical_original_code:
void leave_scope(struct symboltable *symtab) {
  struct symhashtable *hashtable = symtab->inner_scope;
  symtab->inner_scope = hashtable->outer_scope;
  destroy_symhashtable(hashtable);
}

variable_types: struct symhashtable { int size; struct symnode { char *name; struct symnode *next; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } var_type; int var_addr; enum memaddrtype { off_fp=0, global=1 } mem_addr_type; enum nodetype { func_node=0, val_node=1, array_node=2 } node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; } **table; struct symhashtable *outer_scope; int level; } *


decompiled_code:
const char *__fastcall lookup_string(__int64 a1, const char *a2)
{
int v2; // eax
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // rbp

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( 1 )
{
v5 = *v3;
if ( *v3 )
{
if ( !strcmp(*v3, a2) )
break;
}
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1, const char *a2)
{
int v2; // eax
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // rbp

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( 1 )
{
v5 = *v3;
if ( *v3 )
{
if ( !strcmp(*v3, a2) )
break;
}
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return v5;
}

original_code:
char *lookup_string(Sst sst, char *str)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        char *str_bucket = *(sst->table_ptr + i);
        if (str_bucket != ((void *)0) && strcmp(str_bucket, str) == 0)
            return str_bucket;
    }
    return ((void *)0);
}

canonical_original_code:
char *lookup_string(struct simple_string_table_struct *sst, char *str)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        char *str_bucket = *(sst->table_ptr + i);
        if (str_bucket != ((void *)0) && strcmp(str_bucket, str) == 0)
            return str_bucket;
    }
    return ((void *)0);
}

variable_types: struct simple_string_table_struct { char **table_ptr; int size; } *

variable_types:
str
char *

variable_types: i int

return_type: char *


original_code:
void expand_sst(Sst sst)
{
    int double_size = sst->size * 2;
    char **double_table_ptr = calloc(double_size, sizeof(char *));
    int i;
    for (i = 0; i < sst->size; i++)
        *(double_table_ptr + i) = *(sst->table_ptr + i);
    sst->size = double_size;
    free(sst->table_ptr);
    sst->table_ptr = double_table_ptr;
}

canonical_original_code:
void expand_sst(struct simple_string_table_struct *sst)
{
    int double_size = sst->size * 2;
    char **double_table_ptr = calloc(double_size, sizeof(char *));
    int i;
    for (i = 0; i < sst->size; i++)
        *(double_table_ptr + i) = *(sst->table_ptr + i);
    sst->size = double_size;
    free(sst->table_ptr);
    sst->table_ptr = double_table_ptr;
}

user_defined_types: struct simple_string_table_struct { char **table_ptr; int size; }


decompiled_code:
const char *__fastcall add_string(__int64 a1, const char *a2)
{
const char *result; // rax
size_t v3; // rax
int v4; // edx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rbx
void **v8; // r13

result = lookup_string(a1, a2);
if ( !result )
{
while ( 1 )
{
v4 = *(_DWORD *)(a1 + 8);
if ( v4 > 0 )
break;
LABEL_4:
expand_sst(a1);
}
v5 = *(_QWORD *)a1;
v6 = 8LL * (unsigned int)v4;
v7 = 0LL;
while ( 1 )
{
v8 = (void **)(v5 + v7);
if ( !*(_QWORD *)(v5 + v7) )
break;
v7 += 8LL;
if ( v7 == v6 )
goto LABEL_4;
}
v3 = strlen(a2);
*v8 = malloc(v3 + 1);
strcpy(*(char **)(*(_QWORD *)a1 + v7), a2);
result = *(const char **)(*(_QWORD *)a1 + v7);
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(__int64 a1, const char *a2)
{
const char *result; // rax
size_t v3; // rax
int v4; // edx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rbx
void **v8; // r13

result = func0(a1, a2);
if ( !result )
{
while ( 1 )
{
v4 = *(_DWORD *)(a1 + 8);
if ( v4 > 0 )
break;
LABEL_4:
func1(a1);
}
v5 = *(_QWORD *)a1;
v6 = 8LL * (unsigned int)v4;
v7 = 0LL;
while ( 1 )
{
v8 = (void **)(v5 + v7);
if ( !*(_QWORD *)(v5 + v7) )
break;
v7 += 8LL;
if ( v7 == v6 )
goto LABEL_4;
}
v3 = strlen(a2);
*v8 = malloc(v3 + 1);
strcpy(*(char **)(*(_QWORD *)a1 + v7), a2);
result = *(const char **)(*(_QWORD *)a1 + v7);
}
return result;
}

original_code:
char *add_string(Sst sst, char *str)
{
    char *str_ptr = lookup_string(sst, str);
    if (str_ptr == ((void *)0))
    {
        while (1)
        {
            int i;
            for (i = 0; i < sst->size; i++)
            {
                if (*(sst->table_ptr + i) == ((void *)0))
                {
                    *(sst->table_ptr + i) = malloc(strlen(str) + 1);
                    strcpy(*(sst->table_ptr + i), str);
                    return *(sst->table_ptr + i);
                }
            }
            expand_sst(sst);
        }
    } else
        return str_ptr;
}

canonical_original_code:
char *add_string(struct simple_string_table_struct *sst, char *str)
{
    char *str_ptr = lookup_string(sst, str);
    if (str_ptr == ((void *)0))
    {
        while (1)
        {
            int i;
            for (i = 0; i < sst->size; i++)
            {
                if (*(sst->table_ptr + i) == ((void *)0))
                {
                    *(sst->table_ptr + i) = malloc(strlen(str) + 1);
                    strcpy(*(sst->table_ptr + i), str);
                    return *(sst->table_ptr + i);
                }
            }
            expand_sst(sst);
        }
    } else
        return str_ptr;
}


decompiled_code:
int __fastcall print_sst(__int64 a1)
{
__int64 v1; // rbx
const char *v2; // rdx

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
v2 = *(const char **)(*(_QWORD *)a1 + 8 * v1);
if ( v2 )
printf("%d: %s\n", (unsigned int)v1, v2);
else
printf("%d: NULL\n", (unsigned int)v1);
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
const char *v2; // rdx

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
v2 = *(const char **)(*(_QWORD *)a1 + 8 * v1);
if ( v2 )
printf("%d: %s\n", (unsigned int)v1, v2);
else
printf("%d: NULL\n", (unsigned int)v1);
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return putchar(10);
}

original_code:
void print_sst(Sst sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) == ((void *)0))
            printf("%d: NULL\n", i);
        else
            printf("%d: %s\n", i, *(sst->table_ptr + i));
    }
    printf("\n");
}

canonical_original_code:
void print_sst(struct simple_string_table_struct *sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) == ((void *)0))
            printf("%d: NULL\n", i);
        else
            printf("%d: %s\n", i, *(sst->table_ptr + i));
    }
    printf("\n");
}


decompiled_code:
void __fastcall destroy_sst(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_sst(Sst sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) != ((void *)0))
            free(*(sst->table_ptr + i));
    }
    free(sst->table_ptr);
    free(sst);
}

canonical_original_code:
void destroy_sst(struct simple_string_table_struct *sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) != ((void *)0))
            free(*(sst->table_ptr + i));
    }
    free(sst->table_ptr);
    free(sst);
}


hashPJW

original_code:
static int hashPJW(char *s, int size) {
  unsigned h = 0, g;
  char *p;
  for (p = s; *p != '\0'; p++) {
      h = (h << 4) + *p;
      if ((g = (h & 0xf0000000)) != 0)
 h ^= (g >> 24) ^ g;
    }
  return h % size;
}

canonical_original_code:
static int hashPJW(char *s, int size) {
  unsigned int h = 0; unsigned int g;
  char *p;
  for (p = s; *p != '\0'; p++) {
      h = (h << 4) + *p;
      if ((g = (h & 0xf0000000)) != 0)
 h ^= (g >> 24) ^ g;
    }
  return h % size;
}

variable_types:
s
char *

variable_types: size int

variable_types:
h
unsigned int

variable_types:
g
unsigned int

variable_types:
p
char *


decompiled_code:
void __fastcall destroy_symnode(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

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

original_code:
static void destroy_symnode(symnode node) {
  free(node->name);
  free(node);
}

canonical_original_code:
static void destroy_symnode(struct symnode *node) {
  free(node->name);
  free(node);
}

user_defined_types: enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 }

user_defined_types: enum nodetype { func_node=0, val_node=1, array_node=2 }


decompiled_code:
void __fastcall destroy_symhashtable(__int64 a1)
{
__int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
destroy_symnode(v4);
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
}

original_code:
static void destroy_symhashtable(symhashtable hashtable) {
  int i;
  for (i = 0; i < hashtable->size; i++) {
    symnode node, next;
    for (node = hashtable->table[i]; node != ((void *)0); node = next) {
      next = node->next;
      destroy_symnode(node);
    }
  }
}

canonical_original_code:
static void destroy_symhashtable(struct symhashtable *hashtable) {
  int i;
  for (i = 0; i < hashtable->size; i++) {
    struct symnode *node; struct symnode *next;
    for (node = hashtable->table[i]; node != ((void *)0); node = next) {
      next = node->next;
      destroy_symnode(node);
    }
  }
}


canonical_decompiled_code:
_BOOL8 __fastcall func3(const char **a1, const char *a2)
{
return strcmp(*a1, a2) == 0;
}


decompiled_code:
int __fastcall print_symnode(const char **a1)
{
int result; // eax

if ( a1 )
result = printf(
"Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n",
*a1,
node_type_string[*((unsigned int *)a1 + 7)],
(&var_type_string)[*((unsigned int *)a1 + 4)],
*((unsigned int *)a1 + 5),
mem_addr_type_string[*((unsigned int *)a1 + 6)],
a1);
else
result = puts("Node is null");
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char **a1)
{
int result; // eax

if ( a1 )
result = printf(
"Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n",
*a1,
node_type_string[*((unsigned int *)a1 + 7)],
(&var_type_string)[*((unsigned int *)a1 + 4)],
*((unsigned int *)a1 + 5),
mem_addr_type_string[*((unsigned int *)a1 + 6)],
a1);
else
result = puts("Node is null");
return result;
}

original_code:
void print_symnode(symnode node)
{
    if (node) {
      printf("Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n", node->name,
      node_type_string[node->node_type],
      var_type_string[node->var_type],
      node->var_addr,
      mem_addr_type_string[node->mem_addr_type],
            node
            );
    } else {
        printf("Node is null\n");
    }
}

canonical_original_code:
void print_symnode(struct symnode *node)
{
    if (node) {
      printf("Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n", node->name,
      node_type_string[node->node_type],
      var_type_string[node->var_type],
      node->var_addr,
      mem_addr_type_string[node->mem_addr_type],
            node
            );
    } else {
        printf("Node is null\n");
    }
}


decompiled_code:
int __fastcall print_symhashtable(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 i; // rbx

if ( *(int *)a1 > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(a1 + 8);
for ( i = *(_QWORD *)(v2 + 8 * v1); i; i = *(_QWORD *)(i + 8) )
LODWORD(v2) = print_symnode((const char **)i);
++v1;
}
while ( *(_DWORD *)a1 > (int)v1 );
}
return v2;
}

original_code:
void print_symhashtable(symhashtable hashtable)
{
  int i;
  for (i = 0; i < hashtable->size; i++) {
    symnode node;
    for (node = hashtable->table[i]; node != ((void *)0); node = node->next) {
      print_symnode(node);
    }
  }
}

canonical_original_code:
void print_symhashtable(struct symhashtable *hashtable)
{
  int i;
  for (i = 0; i < hashtable->size; i++) {
    struct symnode *node;
    for (node = hashtable->table[i]; node != ((void *)0); node = node->next) {
      print_symnode(node);
    }
  }
}


decompiled_code:
int __fastcall print_symboltable(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
printf("Table at level %d contains:\n", *(unsigned int *)(i + 24));
result = print_symhashtable(i);
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
printf("Table at level %d contains:\n", *(unsigned int *)(i + 24));
result = func12(i);
}
return result;
}

original_code:
void print_symboltable(symboltable symtab)
{
  symhashtable table;
  for (table = symtab->inner_scope; table != ((void *)0); table = table->outer_scope) {
    printf("Table at level %d contains:\n", table->level);
    print_symhashtable(table);
  }
}

canonical_original_code:
void print_symboltable(struct symboltable *symtab)
{
  struct symhashtable *table;
  for (table = symtab->inner_scope; table != ((void *)0); table = table->outer_scope) {
    printf("Table at level %d contains:\n", table->level);
    print_symhashtable(table);
  }
}


decompiled_code:
int __fastcall print_ast_node(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int *v2; // rax

printf("%s ", (&token_table)[2 * *a1]);
v1 = *a1;
if ( *a1 == 37 )
{
printf("%d", a1[6]);
}
else if ( v1 > 0x25 )
{
if ( v1 == 38 )
printf("%f", *((double *)a1 + 3));
}
else if ( v1 == 1 )
{
v2 = (unsigned int *)*((_QWORD *)a1 + 3);
printf(
"%s (%p), node type: %s, var type: %s, address: %d (%s), num vars: %d",
*(const char **)v2,
v2,
*((const char **)&node_type_string + v2[7]),
*((const char **)&var_type_string + v2[4]),
v2[5],
*((const char **)&mem_addr_type_string + v2[6]),
v2[12]);
}
else if ( v1 == 36 )
{
printf("%s (%p)", **((const char ***)a1 + 3), *((const void **)a1 + 3));
}
return printf(
"\t--> data type: %s, return type: %s",
*((const char **)&var_type_string + a1[9]),
*((const char **)&var_type_string + a1[10]));
}

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

printf("%s ", (&token_table)[2 * *a1]);
v1 = *a1;
if ( *a1 == 37 )
{
printf("%d", a1[6]);
}
else if ( v1 > 0x25 )
{
if ( v1 == 38 )
printf("%f", *((double *)a1 + 3));
}
else if ( v1 == 1 )
{
v2 = (unsigned int *)*((_QWORD *)a1 + 3);
printf(
"%s (%p), node type: %s, var type: %s, address: %d (%s), num vars: %d",
*(const char **)v2,
v2,
*((const char **)&node_type_string + v2[7]),
*((const char **)&var_type_string + v2[4]),
v2[5],
*((const char **)&mem_addr_type_string + v2[6]),
v2[12]);
}
else if ( v1 == 36 )
{
printf("%s (%p)", **((const char ***)a1 + 3), *((const void **)a1 + 3));
}
return printf(
"\t--> data type: %s, return type: %s",
*((const char **)&var_type_string + a1[9]),
*((const char **)&var_type_string + a1[10]));
}

original_code:
void print_ast_node(ast_node node)
{
  printf("%s ", token_table[node->node_type].token);
  switch (node->node_type) {
  case ID:
  {
    symnode sym_node = node->value.sym_node;
    printf("%s (%p), node type: %s, var type: %s, address: %d (%s), num vars: %d",
      sym_node->name,
      sym_node,
      node_type_string[sym_node->node_type],
      var_type_string[sym_node->var_type],
      sym_node->var_addr,
      mem_addr_type_string[sym_node->mem_addr_type],
      sym_node->num_vars);
    break;
  }
  case INT_LITERAL:
    printf("%d", node->value.int_value);
    break;
  case DOUBLE_LITERAL:
    printf("%f", node->value.double_value);
    break;
  case STRING_LITERAL:
    printf("%s (%p)", node->value.sym_node->name, node->value.sym_node);
    break;
  default:
    break;
  }
  printf("\t--> data type: %s, return type: %s", var_type_string[node->data_type], var_type_string[node->return_type]);
}

canonical_original_code:
void print_ast_node(struct ast_node_struct *node)
{
  printf("%s ", token_table[node->node_type].token);
  switch (node->node_type) {
  case ID:
  {
    struct symnode *sym_node = node->value.sym_node;
    printf("%s (%p), node type: %s, var type: %s, address: %d (%s), num vars: %d",
      sym_node->name,
      sym_node,
      node_type_string[sym_node->node_type],
      var_type_string[sym_node->var_type],
      sym_node->var_addr,
      mem_addr_type_string[sym_node->mem_addr_type],
      sym_node->num_vars);
    break;
  }
  case INT_LITERAL:
    printf("%d", node->value.int_value);
    break;
  case DOUBLE_LITERAL:
    printf("%f", node->value.double_value);
    break;
  case STRING_LITERAL:
    printf("%s (%p)", node->value.sym_node->name, node->value.sym_node);
    break;
  default:
    break;
  }
  printf("\t--> data type: %s, return type: %s", var_type_string[node->data_type], var_type_string[node->return_type]);
}

variable_types: struct ast_node_struct { enum ast_node_type { ROOT=0, ID=1, INT_TYPE=2, DBL_TYPE=3, VOID_TYPE=4, ARRAY_SUB=5, ARRAY_NONSUB=6, OP_ASSIGN=7, OP_ADD=8, OP_SUB=9, OP_MULT=10, OP_DIV=11, OP_MOD=12, OP_LT=13, OP_LEQ=14, OP_GT=15, OP_GEQ=16, OP_EQ=17, OP_NEQ=18, OP_AND=19, OP_OR=20, OP_BANG=21, OP_NEG=22, OP_INC=23, OP_DEC=24, FUNC_DECL=25, VAR_DECL=26, FORMAL_PARAM=27, SEQ=28, IF_STMT=29, WHILE_LOOP=30, DO_WHILE_LOOP=31, FOR_STMT=32, RETURN_STMT=33, READ_STMT=34, PRINT_STMT=35, STRING_LITERAL=36, INT_LITERAL=37, DOUBLE_LITERAL=38, FUNC_CALL=39, EMPTY_EXPR=40 } node_type; struct ast_node_struct *left_child; union { struct symnode { char *name; struct symnode *next; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } var_type; int var_addr; enum memaddrtype { off_fp=0, global=1 } mem_addr_type; enum nodetype { func_node=0, val_node=1, array_node=2 } node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; } *sym_node; int int_value; double double_value; } value; int line_num; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } data_type; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } return_type; } *

user_defined_types: struct ast_node_struct { enum ast_node_type node_type; struct ast_node_struct *left_child; union { struct symnode *sym_node; int int_value; double double_value; } value; int line_num; enum vartype data_type; enum vartype return_type; }


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
ast_node rightmost_sibling(ast_node t)
{
  for (; t->right_sibling != ((void *)0); t = t->right_sibling);
  return t;
}

canonical_original_code:
struct ast_node_struct *rightmost_sibling(struct ast_node_struct *t)
{
  for (; t->right_sibling != ((void *)0); t = t->right_sibling);
  return t;
}

variable_types:
t
struct ast_node_struct *

return_type: struct ast_node_struct { enum ast_node_type { ROOT=0, ID=1, INT_TYPE=2, DBL_TYPE=3, VOID_TYPE=4, ARRAY_SUB=5, ARRAY_NONSUB=6, OP_ASSIGN=7, OP_ADD=8, OP_SUB=9, OP_MULT=10, OP_DIV=11, OP_MOD=12, OP_LT=13, OP_LEQ=14, OP_GT=15, OP_GEQ=16, OP_EQ=17, OP_NEQ=18, OP_AND=19, OP_OR=20, OP_BANG=21, OP_NEG=22, OP_INC=23, OP_DEC=24, FUNC_DECL=25, VAR_DECL=26, FORMAL_PARAM=27, SEQ=28, IF_STMT=29, WHILE_LOOP=30, DO_WHILE_LOOP=31, FOR_STMT=32, RETURN_STMT=33, READ_STMT=34, PRINT_STMT=35, STRING_LITERAL=36, INT_LITERAL=37, DOUBLE_LITERAL=38, FUNC_CALL=39, EMPTY_EXPR=40 } node_type; struct ast_node_struct *left_child; union { char *string; int int_value; double double_value; } value; } *

user_defined_types: struct ast_node_struct { enum ast_node_type node_type; struct ast_node_struct *left_child; union { char *string; int int_value; double double_value; } value; }


arriveBridge

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

printf("%d: I want to go on the bridge with direction: %d\n", a2, a1);
if ( pthread_mutex_lock(&mutex) )
{
fwrite("Mutex lock failed.\n", 1uLL, 0x13uLL, _bss_start);
exit(-1);
}
++num_cars_waiting[a1];
v2 = (unsigned int)num_cars_on_bridge;
if ( num_cars_on_bridge )
{
while ( (int)v2 > 2 || bridge_direction != a1 )
{
printf(
"%d: I can't get on the bridge with direction %d. The bridge has %d cars and is in direction %d.\n",
(unsigned int)a2,
a1,
v2,
(unsigned int)bridge_direction);
pthread_cond_wait((pthread_cond_t *)(48LL * (int)a1 + 4210976), &mutex);
v2 = (unsigned int)num_cars_on_bridge;
if ( !num_cars_on_bridge )
goto LABEL_5;
}
num_cars_on_bridge = v2 + 1;
printf("%d: I'm car #%d on the bridge going in direction: %d.\n", (unsigned int)a2, (unsigned int)(v2 + 1), a1);
}
else
{
LABEL_5:
printf("%d: I'm the first car on the bridge going in direction: %d.\n", (unsigned int)a2, a1);
++num_cars_on_bridge;
bridge_direction = a1;
}
--num_cars_waiting[a1];
result = pthread_mutex_unlock(&mutex);
if ( result )
{
fwrite("Mutex release failed.\n", 1uLL, 0x16uLL, _bss_start);
exit(-1);
}
return result;
}

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

printf("%d: I want to go on the bridge with direction: %d\n", a2, a1);
if ( pthread_mutex_lock(&mutex) )
{
fwrite("Mutex lock failed.\n", 1uLL, 0x13uLL, _bss_start);
exit(-1);
}
++num_cars_waiting[a1];
v2 = (unsigned int)num_cars_on_bridge;
if ( num_cars_on_bridge )
{
while ( (int)v2 > 2 || bridge_direction != a1 )
{
printf(
"%d: I can't get on the bridge with direction %d. The bridge has %d cars and is in direction %d.\n",
(unsigned int)a2,
a1,
v2,
(unsigned int)bridge_direction);
pthread_cond_wait((pthread_cond_t *)(48LL * (int)a1 + 4210976), &mutex);
v2 = (unsigned int)num_cars_on_bridge;
if ( !num_cars_on_bridge )
goto LABEL_5;
}
num_cars_on_bridge = v2 + 1;
printf("%d: I'm car #%d on the bridge going in direction: %d.\n", (unsigned int)a2, (unsigned int)(v2 + 1), a1);
}
else
{
LABEL_5:
printf("%d: I'm the first car on the bridge going in direction: %d.\n", (unsigned int)a2, a1);
++num_cars_on_bridge;
bridge_direction = a1;
}
--num_cars_waiting[a1];
result = pthread_mutex_unlock(&mutex);
if ( result )
{
fwrite("Mutex release failed.\n", 1uLL, 0x16uLL, _bss_start);
exit(-1);
}
return result;
}

original_code:
void arriveBridge(int direction, int name) {
  printf("%d: I want to go on the bridge with direction: %d\n", name, direction);
  int rc;
  rc = pthread_mutex_lock(&mutex);
  if (rc) {
    fprintf(stderr, "Mutex lock failed.\n");
    exit(-1);
  }
  num_cars_waiting[direction]++;
  while (1) {
    if (0 == num_cars_on_bridge) {
      printf("%d: I'm the first car on the bridge going in direction: %d.\n", name, direction);
      num_cars_on_bridge++;
      bridge_direction = direction;
      break;
    } else if (direction == bridge_direction && num_cars_on_bridge < 3) {
      num_cars_on_bridge++;
      printf("%d: I'm car #%d on the bridge going in direction: %d.\n", name, num_cars_on_bridge, direction);
      break;
    } else {
      printf("%d: I can't get on the bridge with direction %d. The bridge has %d cars and is in direction %d.\n", name, direction, num_cars_on_bridge, bridge_direction);
      pthread_cond_wait(&cvar[direction], &mutex);
    }
  }
  num_cars_waiting[direction]--;
  rc = pthread_mutex_unlock(&mutex);
  if (rc) {
    fprintf(stderr, "Mutex release failed.\n");
    exit(-1);
  }
}

variable_types: direction int

variable_types: name int

variable_types: rc int


onBridge

decompiled_code:
int __fastcall onBridge(unsigned int a1, unsigned int a2)
{
int result; // eax

if ( pthread_mutex_lock(&mutex) )
{
fwrite("Mutex lock failed.\n", 1uLL, 0x13uLL, _bss_start);
exit(-1);
}
printf("%d: I'm on the bridge, yo, going in direction %d.\n", a2, a1);
printf(
"\tThere are %d cars waiting to go to Hanover and %d cars waiting to go to Norwich.\n",
(unsigned int)dword_4040CC,
(unsigned int)num_cars_waiting[0]);
result = pthread_mutex_unlock(&mutex);
if ( result )
{
fwrite("Mutex release failed.\n", 1uLL, 0x16uLL, _bss_start);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2)
{
int result; // eax

if ( pthread_mutex_lock(&mutex) )
{
fwrite("Mutex lock failed.\n", 1uLL, 0x13uLL, _bss_start);
exit(-1);
}
printf("%d: I'm on the bridge, yo, going in direction %d.\n", a2, a1);
printf(
"\tThere are %d cars waiting to go to Hanover and %d cars waiting to go to Norwich.\n",
(unsigned int)dword_4040CC,
(unsigned int)num_cars_waiting[0]);
result = pthread_mutex_unlock(&mutex);
if ( result )
{
fwrite("Mutex release failed.\n", 1uLL, 0x16uLL, _bss_start);
exit(-1);
}
return result;
}

original_code:
void onBridge(int direction, int name) {
  int rc;
  rc = pthread_mutex_lock(&mutex);
  if (rc) {
    fprintf(stderr, "Mutex lock failed.\n");
    exit(-1);
  }
  printf("%d: I'm on the bridge, yo, going in direction %d.\n", name, direction);
  printf("\tThere are %d cars waiting to go to Hanover and %d cars waiting to go to Norwich.\n", num_cars_waiting[1], num_cars_waiting[0]);
  rc = pthread_mutex_unlock(&mutex);
  if (rc) {
    fprintf(stderr, "Mutex release failed.\n");
    exit(-1);
  }
}


exitBridge

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

printf("%d: I want to get off the bridge with direction: %d.\n", a2, a1);
if ( pthread_mutex_lock(&mutex) )
{
fwrite("Mutex lock failed.\n", 1uLL, 0x13uLL, _bss_start);
exit(-1);
}
v2 = num_cars_on_bridge--;
printf(
"%d: I got off the bridge going in direction %d. There are now %d cars on the bridge.\n",
(unsigned int)a2,
a1,
(unsigned int)num_cars_on_bridge);
if ( pthread_mutex_unlock(&mutex) )
{
fwrite("Mutex release failed.\n", 1uLL, 0x16uLL, _bss_start);
exit(-1);
}
result = pthread_cond_broadcast((pthread_cond_t *)(48LL * (int)a1 + 4210976));
if ( v2 == 1 )
result = pthread_cond_broadcast((pthread_cond_t *)(48LL * (a1 == 0) + 4210976));
return result;
}

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

printf("%d: I want to get off the bridge with direction: %d.\n", a2, a1);
if ( pthread_mutex_lock(&mutex) )
{
fwrite("Mutex lock failed.\n", 1uLL, 0x13uLL, _bss_start);
exit(-1);
}
v2 = num_cars_on_bridge--;
printf(
"%d: I got off the bridge going in direction %d. There are now %d cars on the bridge.\n",
(unsigned int)a2,
a1,
(unsigned int)num_cars_on_bridge);
if ( pthread_mutex_unlock(&mutex) )
{
fwrite("Mutex release failed.\n", 1uLL, 0x16uLL, _bss_start);
exit(-1);
}
result = pthread_cond_broadcast((pthread_cond_t *)(48LL * (int)a1 + 4210976));
if ( v2 == 1 )
result = pthread_cond_broadcast((pthread_cond_t *)(48LL * (a1 == 0) + 4210976));
return result;
}

original_code:
void exitBridge(int direction, int name) {
  printf("%d: I want to get off the bridge with direction: %d.\n", name, direction);
  int rc;
  rc = pthread_mutex_lock(&mutex);
  if (rc) {
    fprintf(stderr, "Mutex lock failed.\n");
    exit(-1);
  }
  _Bool last_car_on_bridge = (num_cars_on_bridge == 1);
  num_cars_on_bridge--;
  printf("%d: I got off the bridge going in direction %d. There are now %d cars on the bridge.\n",
  name, direction, num_cars_on_bridge);
  rc = pthread_mutex_unlock(&mutex);
  if (rc) {
    fprintf(stderr, "Mutex release failed.\n");
    exit(-1);
  }
  pthread_cond_broadcast(&cvar[direction]);
  if (last_car_on_bridge) {
    int opposite_direction = direction == 0 ? 1 : 0;
    pthread_cond_broadcast(&cvar[opposite_direction]);
  }
}


oneCar

decompiled_code:
void *__fastcall oneCar(void *a1)
{
unsigned int v1; // ebx
unsigned int v2; // ebp
float v4; // [rsp+Ch] [rbp-1Ch]

v1 = *(_DWORD *)a1;
v2 = *((_DWORD *)a1 + 1);
v4 = (float)*((int *)a1 + 2);
arriveBridge(*(_DWORD *)a1, v2);
sleep((int)v4);
onBridge(v1, v2);
sleep((int)v4);
exitBridge(v1, v2);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
unsigned int v1; // ebx
unsigned int v2; // ebp
float v4; // [rsp+Ch] [rbp-1Ch]

v1 = *(_DWORD *)a1;
v2 = *((_DWORD *)a1 + 1);
v4 = (float)*((int *)a1 + 2);
func7(*(_DWORD *)a1, v2);
sleep((int)v4);
func8(v1, v2);
sleep((int)v4);
func9(v1, v2);
return 0LL;
}

original_code:
void *oneCar(void *direction_name_sleep_void_pointer) {
  DirectionNameSleep *direction_name_sleep = (DirectionNameSleep *)direction_name_sleep_void_pointer;
  int direction = direction_name_sleep->direction;
  int name = direction_name_sleep->name;
  float sleep_duration = direction_name_sleep->sleep_duration;
  arriveBridge(direction, name);
  sleep(sleep_duration);
  onBridge(direction, name);
  sleep(sleep_duration);
  exitBridge(direction, name);
  return ((void *)0);
}

canonical_original_code:
void *oneCar(void *direction_name_sleep_void_pointer) {
  struct DirectionNameSleep *direction_name_sleep = (DirectionNameSleep *)direction_name_sleep_void_pointer;
  int direction = direction_name_sleep->direction;
  int name = direction_name_sleep->name;
  float sleep_duration = direction_name_sleep->sleep_duration;
  arriveBridge(direction, name);
  sleep(sleep_duration);
  onBridge(direction, name);
  sleep(sleep_duration);
  exitBridge(direction, name);
  return ((void *)0);
}

variable_types: struct DirectionNameSleep { int direction; int name; int sleep_duration; } *

return_type: void *


original_code:
void testCase0() {
  printf("---------------------------------------------------------------------------------------\n");
  printf("5 cars going in each direction, all released at the same time,\n");
  printf("\tsleeping for 1 second after getting on, and another second before getting off:\n");
  printf("---------------------------------------------------------------------------------------\n");
  int num_cars_to_hanover = 5;
  int num_cars_to_norwich = 5;
  DirectionNameSleep *direction_names[num_cars_to_hanover + num_cars_to_norwich];
  pthread_t car_threads[num_cars_to_hanover + num_cars_to_norwich];
  int rc;
  int i;
  for (i = 0; i < num_cars_to_hanover; i++) {
    direction_names[i] = (DirectionNameSleep *)malloc(sizeof(DirectionNameSleep));
    direction_names[i]->direction = 1;
    direction_names[i]->name = i;
    direction_names[i]->sleep_duration = 1;
    rc = pthread_create(&car_threads[i], ((void *)0), oneCar, (void *)direction_names[i]);
    if (rc) {
      fprintf(stderr, "pthread_create failed at i = %d\n", i);
      exit(-1);
    }
  }
  for (; i < num_cars_to_hanover + num_cars_to_norwich; i++) {
    direction_names[i] = malloc(sizeof(DirectionNameSleep));
    direction_names[i]->direction = 0;
    direction_names[i]->name = i;
    rc = pthread_create(&car_threads[i], ((void *)0), oneCar, (void *)direction_names[i]);
    if (rc) {
      fprintf(stderr, "pthread_create failed at i = %d\n", i);
      exit(-1);
    }
  }
  for (i = 0; i < num_cars_to_hanover + num_cars_to_norwich; i++) {
    rc = pthread_join(car_threads[i], ((void *)0));
    if (rc) {
      fprintf(stderr, "pthread_join failed at i = %d\n", i);
      exit(-1);
    }
    free(direction_names[i]);
  }
  printf("---------------------------------------------------------------------------------------\n");
}

canonical_original_code:
void testCase0() {
  printf("---------------------------------------------------------------------------------------\n");
  printf("5 cars going in each direction, all released at the same time,\n");
  printf("\tsleeping for 1 second after getting on, and another second before getting off:\n");
  printf("---------------------------------------------------------------------------------------\n");
  int num_cars_to_hanover = 5;
  int num_cars_to_norwich = 5;
  struct DirectionNameSleep *direction_names[-1];
  unsigned long car_threads[-1];
  int rc;
  int i;
  for (i = 0; i < num_cars_to_hanover; i++) {
    direction_names[i] = (struct DirectionNameSleep *)malloc(sizeof(DirectionNameSleep));
    direction_names[i]->direction = 1;
    direction_names[i]->name = i;
    direction_names[i]->sleep_duration = 1;
    rc = pthread_create(&car_threads[i], ((void *)0), oneCar, (void *)direction_names[i]);
    if (rc) {
      fprintf(stderr, "pthread_create failed at i = %d\n", i);
      exit(-1);
    }
  }
  for (; i < num_cars_to_hanover + num_cars_to_norwich; i++) {
    direction_names[i] = malloc(sizeof(DirectionNameSleep));
    direction_names[i]->direction = 0;
    direction_names[i]->name = i;
    rc = pthread_create(&car_threads[i], ((void *)0), oneCar, (void *)direction_names[i]);
    if (rc) {
      fprintf(stderr, "pthread_create failed at i = %d\n", i);
      exit(-1);
    }
  }
  for (i = 0; i < num_cars_to_hanover + num_cars_to_norwich; i++) {
    rc = pthread_join(car_threads[i], ((void *)0));
    if (rc) {
      fprintf(stderr, "pthread_join failed at i = %d\n", i);
      exit(-1);
    }
    free(direction_names[i]);
  }
  printf("---------------------------------------------------------------------------------------\n");
}

variable_types: struct DirectionNameSleep { int direction; int name; int sleep_duration; } *[-1]


original_code:
void testCase1() {
  printf("---------------------------------------------------------------------------------------\n");
  printf("10 cars going in random directions, all released at the same time,\n");
  printf("\tsleeping for 0 <= t <= 5 seconds after getting on, and another t seconds before getting off:\n");
  printf("---------------------------------------------------------------------------------------\n");
  int num_cars = 10;
  DirectionNameSleep *direction_names[num_cars];
  pthread_t car_threads[num_cars];
  int min_sleep_duration = 0;
  int max_sleep_duration = 5;
  int rc;
  int i;
  for (i = 0; i < num_cars; i++) {
    direction_names[i] = (DirectionNameSleep *)malloc(sizeof(DirectionNameSleep));
    direction_names[i]->direction = rand() % 2;
    direction_names[i]->name = i;
    direction_names[i]->sleep_duration = rand() % (max_sleep_duration + 1 - min_sleep_duration) + min_sleep_duration;
    rc = pthread_create(&car_threads[i], ((void *)0), oneCar, (void *)direction_names[i]);
    if (rc) {
      fprintf(stderr, "pthread_create failed at i = %d\n", i);
      exit(-1);
    }
  }
  for (i = 0; i < num_cars; i++) {
    rc = pthread_join(car_threads[i], ((void *)0));
    if (rc) {
      fprintf(stderr, "pthread_join failed at i = %d\n", i);
      exit(-1);
    }
    free(direction_names[i]);
  }
  printf("---------------------------------------------------------------------------------------\n");
}

canonical_original_code:
void testCase1() {
  printf("---------------------------------------------------------------------------------------\n");
  printf("10 cars going in random directions, all released at the same time,\n");
  printf("\tsleeping for 0 <= t <= 5 seconds after getting on, and another t seconds before getting off:\n");
  printf("---------------------------------------------------------------------------------------\n");
  int num_cars = 10;
  struct DirectionNameSleep *direction_names[-1];
  unsigned long car_threads[-1];
  int min_sleep_duration = 0;
  int max_sleep_duration = 5;
  int rc;
  int i;
  for (i = 0; i < num_cars; i++) {
    direction_names[i] = (struct DirectionNameSleep *)malloc(sizeof(DirectionNameSleep));
    direction_names[i]->direction = rand() % 2;
    direction_names[i]->name = i;
    direction_names[i]->sleep_duration = rand() % (max_sleep_duration + 1 - min_sleep_duration) + min_sleep_duration;
    rc = pthread_create(&car_threads[i], ((void *)0), oneCar, (void *)direction_names[i]);
    if (rc) {
      fprintf(stderr, "pthread_create failed at i = %d\n", i);
      exit(-1);
    }
  }
  for (i = 0; i < num_cars; i++) {
    rc = pthread_join(car_threads[i], ((void *)0));
    if (rc) {
      fprintf(stderr, "pthread_join failed at i = %d\n", i);
      exit(-1);
    }
    free(direction_names[i]);
  }
  printf("---------------------------------------------------------------------------------------\n");
}

user_defined_types: struct DirectionNameSleep { int direction; int name; int sleep_duration; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
testCase0();
testCase1();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func11();
func12();
return 0;
}

original_code:
int main(int argc, char **argv) {
  testCase0();
  testCase1();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __fastcall generate_scaled_rotated_image(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
int v8; // edx
int v9; // ecx
int v10; // edi
void *v11; // rsp
int result; // eax
char v13[12]; // [rsp+0h] [rbp-40h] BYREF
char s[52]; // [rsp+Ch] [rbp-34h] BYREF

v8 = a3 / 10;
if ( a3 <= 9 )
{
v9 = 1;
}
else
{
v9 = 1;
do
{
++v9;
v10 = v8;
v8 /= 10;
}
while ( v10 > 9 );
}
v11 = alloca(v9 + 2);
sprintf(v13, "%d%%", (unsigned int)a3);
sprintf(s, "%d", a4);
result = execlp("convert", "convert", a1, "-geometry", v13, "-rotate", s, a2, 0LL);
if ( result < 0 )
{
fwrite("generate_scaled_rotated_image exec failed\n", 1uLL, 0x2AuLL, stderr);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
int v8; // edx
int v9; // ecx
int v10; // edi
void *v11; // rsp
int result; // eax
char v13[12]; // [rsp+0h] [rbp-40h] BYREF
char s[52]; // [rsp+Ch] [rbp-34h] BYREF

v8 = a3 / 10;
if ( a3 <= 9 )
{
v9 = 1;
}
else
{
v9 = 1;
do
{
++v9;
v10 = v8;
v8 /= 10;
}
while ( v10 > 9 );
}
v11 = alloca(v9 + 2);
sprintf(v13, "%d%%", (unsigned int)a3);
sprintf(s, "%d", a4);
result = execlp("convert", "convert", a1, "-geometry", v13, "-rotate", s, a2, 0LL);
if ( result < 0 )
{
fwrite("generate_scaled_rotated_image exec failed\n", 1uLL, 0x2AuLL, stderr);
exit(-1);
}
return result;
}

original_code:
void generate_scaled_rotated_image(char *source_file_path, char *destination_file_path,
        int scale_percent, int rotate_degrees) {
    int scale_percent_digits = 1;
    int x = scale_percent / 10;
    while (x > 0) {
        scale_percent_digits++;
        x /= 10;
    }
    char scale_percent_string[scale_percent_digits + 2];
    sprintf(scale_percent_string, "%d%%", scale_percent);
    char rotate_degrees_string[4];
    sprintf(rotate_degrees_string, "%d", rotate_degrees);
    int convert_exec_result = execlp("convert", "convert", source_file_path,
            "-geometry", scale_percent_string,
            "-rotate", rotate_degrees_string,
            destination_file_path,
            ((void *)0));
    if (convert_exec_result < 0) {
        fprintf(stderr, "generate_scaled_rotated_image exec failed\n");
        exit(-1);
    }
}

canonical_original_code:
void generate_scaled_rotated_image(char *source_file_path, char *destination_file_path, int scale_percent, int rotate_degrees) {
    int scale_percent_digits = 1;
    int x = scale_percent / 10;
    while (x > 0) {
        scale_percent_digits++;
        x /= 10;
    }
    char scale_percent_string[-1];
    sprintf(scale_percent_string, "%d%%", scale_percent);
    char rotate_degrees_string[4];
    sprintf(rotate_degrees_string, "%d", rotate_degrees);
    int convert_exec_result = execlp("convert", "convert", source_file_path,
            "-geometry", scale_percent_string,
            "-rotate", rotate_degrees_string,
            destination_file_path,
            ((void *)0));
    if (convert_exec_result < 0) {
        fprintf(stderr, "generate_scaled_rotated_image exec failed\n");
        exit(-1);
    }
}

variable_types: x int


decompiled_code:
int __fastcall display_image(__int64 a1)
{
int result; // eax

result = execlp("display", "display", a1, 0LL);
if ( result < 0 )
{
fwrite("display_image exec failed\n", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
return result;
}

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

result = execlp("display", "display", a1, 0LL);
if ( result < 0 )
{
fwrite("display_image exec failed\n", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
return result;
}

original_code:
void display_image(char *file_path) {
    int display_exec_result = execlp("display", "display", file_path, ((void *)0));
    if (display_exec_result < 0) {
        fprintf(stderr, "display_image exec failed\n");
        exit(-1);
    }
}


decompiled_code:
__int64 prompt_rotation_degrees()
{
unsigned int i; // eax
char v2[268]; // [rsp+0h] [rbp-128h] BYREF
unsigned int v3; // [rsp+10Ch] [rbp-1Ch]
int v4[6]; // [rsp+110h] [rbp-18h]

v4[0] = 0;
v4[1] = 90;
v4[2] = 270;
v4[3] = 180;
puts("Would you like to rotate the image? Enter the integer corresponding to your choice:");
puts("\t 0: No rotation");
puts("\t 1: 90 degrees clockwise ");
puts("\t 2: 90 degrees counterclockwise ");
puts("\t 3: 180 degrees ");
fgets(v2, 256, _bss_start);
v3 = -1;
__isoc99_sscanf();
for ( i = v3; v3 > 3; i = v3 )
{
puts("Invalid input. Please try again.");
fgets(v2, 256, _bss_start);
__isoc99_sscanf();
}
return (unsigned int)v4[i];
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int i; // eax
char v2[268]; // [rsp+0h] [rbp-128h] BYREF
unsigned int v3; // [rsp+10Ch] [rbp-1Ch]
int v4[6]; // [rsp+110h] [rbp-18h]

v4[0] = 0;
v4[1] = 90;
v4[2] = 270;
v4[3] = 180;
puts("Would you like to rotate the image? Enter the integer corresponding to your choice:");
puts("\t 0: No rotation");
puts("\t 1: 90 degrees clockwise ");
puts("\t 2: 90 degrees counterclockwise ");
puts("\t 3: 180 degrees ");
fgets(v2, 256, _bss_start);
v3 = -1;
__isoc99_sscanf();
for ( i = v3; v3 > 3; i = v3 )
{
puts("Invalid input. Please try again.");
fgets(v2, 256, _bss_start);
__isoc99_sscanf();
}
return (unsigned int)v4[i];
}

original_code:
int prompt_rotation_degrees() {
    char input_buffer[INPUT_BUFFER_SIZE];
    int degrees_options[] = { 0, 90, 270, 180 };
    int num_degrees_options = 4;
    printf("Would you like to rotate the image? Enter the integer corresponding to your choice:\n");
    printf("\t 0: No rotation\n");
    printf("\t 1: 90 degrees clockwise \n");
    printf("\t 2: 90 degrees counterclockwise \n");
    printf("\t 3: 180 degrees \n");
    fgets(input_buffer, INPUT_BUFFER_SIZE, stdin);
    int selection_response = -1;
    sscanf(input_buffer, "%d", &selection_response);
    while (selection_response < 0 || selection_response >= num_degrees_options) {
        printf("Invalid input. Please try again.\n");
        fgets(input_buffer, INPUT_BUFFER_SIZE, stdin);
        sscanf(input_buffer, "%d", &selection_response);
    }
    return degrees_options[selection_response];
}

canonical_original_code:
int prompt_rotation_degrees() {
    char input_buffer[-1];
    int degrees_options[] = { 0, 90, 270, 180 };
    int num_degrees_options = 4;
    printf("Would you like to rotate the image? Enter the integer corresponding to your choice:\n");
    printf("\t 0: No rotation\n");
    printf("\t 1: 90 degrees clockwise \n");
    printf("\t 2: 90 degrees counterclockwise \n");
    printf("\t 3: 180 degrees \n");
    fgets(input_buffer, INPUT_BUFFER_SIZE, stdin);
    int selection_response = -1;
    sscanf(input_buffer, "%d", &selection_response);
    while (selection_response < 0 || selection_response >= num_degrees_options) {
        printf("Invalid input. Please try again.\n");
        fgets(input_buffer, INPUT_BUFFER_SIZE, stdin);
        sscanf(input_buffer, "%d", &selection_response);
    }
    return degrees_options[selection_response];
}


canonical_original_code:
int main(int argc, char **argv) {
  testCase0();
  testCase1();
  return 0;
}


decompiled_code:
void rand_seed()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

original_code:
void rand_seed()
{
    srand( time( 0 ) );
}


decompiled_code:
double rand_double()
{
return (double)rand() * 4.656612873077393e-10;
}

original_code:
double rand_double()
{
    return ( (double)rand() / ( (double)(2147483647) + (double)(1) ) );
}

return_type: double


decompiled_code:
double __fastcall rand_double_between(int a1, int a2)
{
return (double)(a2 - a1 + 1) * rand_double() + (double)a1;
}

canonical_decompiled_code:
double __fastcall func2(int a1, int a2)
{
return (double)(a2 - a1 + 1) * func1() + (double)a1;
}

original_code:
double rand_double_between( int start, int end )
{
    return ( ( rand_double() * (double)( end - start + 1 ) ) + (double)(start) );
}

canonical_original_code:
double rand_double_between(int start, int end)
{
    return ( ( rand_double() * (double)( end - start + 1 ) ) + (double)(start) );
}

variable_types: start int

variable_types: end int


decompiled_code:
__int64 __fastcall rand_between(int a1, int a2)
{
return (unsigned int)(int)rand_double_between(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
return (unsigned int)(int)func2(a1, a2);
}

original_code:
int rand_between( int start, int end )
{
    int randval = (int)(rand_double_between( start, end ));
    return randval;
}

canonical_original_code:
int rand_between(int start, int end)
{
    int randval = (int)(rand_double_between( start, end ));
    return randval;
}

variable_types: randval int


mytimerhandler

decompiled_code:
__int64 mytimerhandler()
{
++frame;
return (unsigned int)++fcounter;
}

canonical_decompiled_code:
__int64 func1()
{
++frame;
return (unsigned int)++fcounter;
}

original_code:
void mytimerhandler()
{
 frame++;
 fcounter++;
}


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

audbuf = play_audio_stream(2048LL, 8LL, 0LL, 21280LL, (unsigned int)sound_vol, 128LL);
if ( audbuf )
{
puts("Audio stream created and started.");
result = 0LL;
}
else
{
puts("ERROR: audio stream open failed!");
result = 1LL;
}
return result;
}

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

audbuf = play_audio_stream(2048LL, 8LL, 0LL, 21280LL, (unsigned int)sound_vol, 128LL);
if ( audbuf )
{
puts("Audio stream created and started.");
result = 0LL;
}
else
{
puts("ERROR: audio stream open failed!");
result = 1LL;
}
return result;
}

original_code:
int start5200sound(void) {
 audbuf = play_audio_stream(2048, 8, 0, 21280, sound_vol, 128);
 if(audbuf == ((void *)0)) {
  printf("ERROR: audio stream open failed!\n");
  return 1;
 }
    else {
        printf("Audio stream created and started.\n");
        return 0;
 }
}

canonical_original_code:
int start5200sound() {
 audbuf = play_audio_stream(2048, 8, 0, 21280, sound_vol, 128);
 if(audbuf == ((void *)0)) {
  printf("ERROR: audio stream open failed!\n");
  return 1;
 }
    else {
        printf("Audio stream created and started.\n");
        return 0;
 }
}


decompiled_code:
__int64 init5200sound()
{
puts("Initialising POKEY emulation...");
Pokey_sound_init(1787520LL, 21280LL, 1LL);
puts("Initialising audio stream...");
return start5200sound();
}

canonical_decompiled_code:
__int64 func3()
{
puts("Initialising POKEY emulation...");
Pokey_sound_init(1787520LL, 21280LL, 1LL);
puts("Initialising audio stream...");
return func2();
}

original_code:
int init5200sound(void) {
 int i;
 printf("Initialising POKEY emulation...\n");
 Pokey_sound_init(1787520, 21280, 1);
 printf("Initialising audio stream...\n");
 i = start5200sound();
    return i;
}

canonical_original_code:
int init5200sound() {
 int i;
 printf("Initialising POKEY emulation...\n");
 Pokey_sound_init(1787520, 21280, 1);
 printf("Initialising audio stream...\n");
 i = start5200sound();
    return i;
}

variable_types: i int


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

if ( audbuf )
{
stop_audio_stream();
result = puts("Audio stream stopped and destroyed.");
}
return result;
}

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

if ( audbuf )
{
stop_audio_stream();
result = puts("Audio stream stopped and destroyed.");
}
return result;
}

original_code:
void stop5200sound(void) {
 if(audbuf != ((void *)0)) {
  stop_audio_stream(audbuf);
  printf("Audio stream stopped and destroyed.\n");
 }
}

canonical_original_code:
void stop5200sound() {
 if(audbuf != ((void *)0)) {
  stop_audio_stream(audbuf);
  printf("Audio stream stopped and destroyed.\n");
 }
}


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

if ( audbuf )
{
stop_audio_stream();
result = puts("Audio stream stopped and destroyed.");
}
return result;
}

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

if ( audbuf )
{
stop_audio_stream();
result = puts("Audio stream stopped and destroyed.");
}
return result;
}

original_code:
void kill5200sound(void) {
 if(audbuf != ((void *)0)) {
  stop_audio_stream(audbuf);
  printf("Audio stream stopped and destroyed.\n");
 }
}

canonical_original_code:
void kill5200sound() {
 if(audbuf != ((void *)0)) {
  stop_audio_stream(audbuf);
  printf("Audio stream stopped and destroyed.\n");
 }
}


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

result = get_audio_stream_buffer(audbuf);
if ( result )
{
Pokey_process(result, 2048LL);
result = free_audio_stream_buffer(audbuf);
}
return result;
}

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

result = get_audio_stream_buffer(audbuf);
if ( result )
{
Pokey_process(result, 2048LL);
result = free_audio_stream_buffer(audbuf);
}
return result;
}

original_code:
void stream_pokey(void) {
 int i;
 unsigned char *pbuf, *pbufgfx;
 pbuf = get_audio_stream_buffer(audbuf);
    pbufgfx = pbuf;
 if(pbuf != ((void *)0)) {
  Pokey_process(pbuf, 2048);
  free_audio_stream_buffer(audbuf);
 }
}

canonical_original_code:
void stream_pokey() {
 int i;
 unsigned char *pbuf; unsigned char *pbufgfx;
 pbuf = get_audio_stream_buffer(audbuf);
    pbufgfx = pbuf;
 if(pbuf != ((void *)0)) {
  Pokey_process(pbuf, 2048);
  free_audio_stream_buffer(audbuf);
 }
}

variable_types:
pbuf
unsigned char *

variable_types:
pbufgfx
unsigned char *


HostDoEvents

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

cont1[6] = 0;
cont2[6] = 0;
cont1[7] = 0;
cont2[7] = 0;
cont1[4] = 0;
cont1[3] = 0;
cont1[2] = 0;
cont1[1] = 0;
cont2[4] = 0;
cont2[3] = 0;
cont2[2] = 0;
cont2[1] = 0;
if ( key[82] )
{
cont1[1] = 1;
}
else if ( key[83] )
{
cont1[2] = 1;
}
if ( key[84] )
{
cont1[3] = 1;
}
else if ( key[85] )
{
cont1[4] = 1;
}
if ( key[75] )
cont1[6] = 1;
if ( key[117] )
cont1[7] = 1;
if ( key[55] )
{
SaveState("state");
rest(1000LL);
}
if ( key[56] )
{
LoadState("state");
rest(1000LL);
}
if ( key[16] )
{
textout(screen, font, "*PAUSED*", 128LL, 100LL, 15LL);
rest(500LL);
while ( !key[16] && !key[67] && !key[75] )
;
rest(200LL);
}
result = keypressed();
if ( (_DWORD)result )
{
result = (unsigned __int8)(((unsigned __int16)readkey() >> 8) - 26);
switch ( (char)result )
{
case 0:
irqst &= 0x7Fu;
if ( irqen < 0 )
result = irq6502();
break;
case 1:
cont1[10] = 1;
break;
case 2:
cont1[23] = 1;
break;
case 3:
cont1[22] = 1;
break;
case 4:
cont1[21] = 1;
break;
case 5:
cont1[19] = 1;
break;
case 6:
cont1[18] = 1;
break;
case 7:
cont1[17] = 1;
break;
case 8:
cont1[15] = 1;
break;
case 9:
cont1[14] = 1;
break;
case 10:
cont1[13] = 1;
break;
case 21:
cont1[20] = 1;
break;
case 22:
case 67:
cont1[16] = 1;
break;
case 23:
cont1[12] = 1;
break;
case 24:
case 33:
result = 0x65727020746C6148LL;
*(_QWORD *)errormsg = 0x65727020746C6148LL;
strcpy(&errormsg[8], "ssed!\n");
running = 0;
break;
case 25:
case 35:
cont1[11] = 1;
break;
case 26:
case 36:
cont1[9] = 1;
break;
case 31:
fps_on = fps_on == 0;
result = rest(500LL);
break;
case 34:
result = put6502memory(2LL, 253LL);
break;
case 41:
cont2[11] = 1;
break;
case 48:
cont2[20] = 1;
break;
case 51:
cont2[11] = 1;
break;
case 61:
cont2[16] = 1;
break;
case 62:
cont2[12] = 1;
break;
default:
return result;
}
}
return result;
}

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

cont1[6] = 0;
cont2[6] = 0;
cont1[7] = 0;
cont2[7] = 0;
cont1[4] = 0;
cont1[3] = 0;
cont1[2] = 0;
cont1[1] = 0;
cont2[4] = 0;
cont2[3] = 0;
cont2[2] = 0;
cont2[1] = 0;
if ( key[82] )
{
cont1[1] = 1;
}
else if ( key[83] )
{
cont1[2] = 1;
}
if ( key[84] )
{
cont1[3] = 1;
}
else if ( key[85] )
{
cont1[4] = 1;
}
if ( key[75] )
cont1[6] = 1;
if ( key[117] )
cont1[7] = 1;
if ( key[55] )
{
SaveState("state");
rest(1000LL);
}
if ( key[56] )
{
LoadState("state");
rest(1000LL);
}
if ( key[16] )
{
textout(screen, font, "*PAUSED*", 128LL, 100LL, 15LL);
rest(500LL);
while ( !key[16] && !key[67] && !key[75] )
;
rest(200LL);
}
result = keypressed();
if ( (_DWORD)result )
{
result = (unsigned __int8)(((unsigned __int16)readkey() >> 8) - 26);
switch ( (char)result )
{
case 0:
irqst &= 0x7Fu;
if ( irqen < 0 )
result = irq6502();
break;
case 1:
cont1[10] = 1;
break;
case 2:
cont1[23] = 1;
break;
case 3:
cont1[22] = 1;
break;
case 4:
cont1[21] = 1;
break;
case 5:
cont1[19] = 1;
break;
case 6:
cont1[18] = 1;
break;
case 7:
cont1[17] = 1;
break;
case 8:
cont1[15] = 1;
break;
case 9:
cont1[14] = 1;
break;
case 10:
cont1[13] = 1;
break;
case 21:
cont1[20] = 1;
break;
case 22:
case 67:
cont1[16] = 1;
break;
case 23:
cont1[12] = 1;
break;
case 24:
case 33:
result = 0x65727020746C6148LL;
*(_QWORD *)errormsg = 0x65727020746C6148LL;
strcpy(&errormsg[8], "ssed!\n");
running = 0;
break;
case 25:
case 35:
cont1[11] = 1;
break;
case 26:
case 36:
cont1[9] = 1;
break;
case 31:
fps_on = fps_on == 0;
result = rest(500LL);
break;
case 34:
result = put6502memory(2LL, 253LL);
break;
case 41:
cont2[11] = 1;
break;
case 48:
cont2[20] = 1;
break;
case 51:
cont2[11] = 1;
break;
case 61:
cont2[16] = 1;
break;
case 62:
cont2[12] = 1;
break;
default:
return result;
}
}
return result;
}

original_code:
void HostDoEvents(void) {
 char pckey;
 cont1.trig = 0;
 cont2.trig = 0;
    cont1.side_button = 0;
    cont2.side_button = 0;
 cont1.left = cont1.right = cont1.up = cont1.down = 0;
 cont2.left = cont2.right = cont2.up = cont2.down = 0;
 if(key[__allegro_KEY_LEFT]) cont1.left = 1;
 else if(key[__allegro_KEY_RIGHT]) cont1.right = 1;
 if(key[__allegro_KEY_UP]) cont1.up = 1;
 else if(key[__allegro_KEY_DOWN]) cont1.down = 1;
 if(key[__allegro_KEY_SPACE]) cont1.trig = 1;
    if(key[__allegro_KEY_LCONTROL]) cont1.side_button = 1;
 if(key[__allegro_KEY_F9]) {
  SaveState("state");
  rest(1000);
 }
 if(key[__allegro_KEY_F10]) {
  LoadState("state");
  rest(1000);
 }
 if(key[__allegro_KEY_P]) {
  textout(screen, font, "*PAUSED*", 128, 100, 15);
  rest(500);
  while(!key[__allegro_KEY_P] && !key[__allegro_KEY_ENTER] && !key[__allegro_KEY_SPACE]);
  rest(200);
 }
 if(keypressed()) {
  pckey = readkey() >> 8;
  switch(pckey) {
  case __allegro_KEY_TILDE :
            put6502memory(0x02, 253);
            break;
  case __allegro_KEY_F1 :
   cont1.key[12] = 1;
   break;
  case __allegro_KEY_SLASH :
   cont2.key[12] = 1;
   break;
  case __allegro_KEY_F2 :
  case __allegro_KEY_PAUSE :
   cont1.key[8] = 1;
   break;
  case __allegro_KEY_ASTERISK :
   cont2.key[8] = 1;
   break;
  case __allegro_KEY_F3 :
   cont1.key[4] = 1;
   break;
  case __allegro_KEY_MINUS_PAD :
   cont2.key[4] = 1;
   break;
  case __allegro_KEY_ESC :
  case __allegro_KEY_F4 :
   sprintf(errormsg, "Halt pressed!\n");
   running = 0;
   break;
  case __allegro_KEY_F5 :
  case __allegro_KEY_MINUS :
   cont1.key[3] = 1;
   break;
  case __allegro_KEY_F6 :
  case __allegro_KEY_EQUALS :
   cont1.key[1] = 1;
   break;
  case __allegro_KEY_DEL :
   cont2.key[3] = 1;
   break;
  case __allegro_KEY_ENTER :
   cont2.key[3] = 1;
   break;
  case __allegro_KEY_F7 :
   break;
  case __allegro_KEY_F8 :
   break;
  case __allegro_KEY_F11 :
   if(fps_on) fps_on = 0;
   else fps_on = 1;
   rest(500);
   break;
  case __allegro_KEY_F12 :
   break;
  case __allegro_KEY_0 :
   cont1.key[2] = 1;
   break;
  case __allegro_KEY_1 :
   cont1.key[15] = 1;
   break;
  case __allegro_KEY_2 :
   cont1.key[14] = 1;
   break;
  case __allegro_KEY_3 :
   cont1.key[13] = 1;
   break;
  case __allegro_KEY_4 :
   cont1.key[11] = 1;
   break;
  case __allegro_KEY_5 :
   cont1.key[10] = 1;
   break;
  case __allegro_KEY_6 :
   cont1.key[9] = 1;
   break;
  case __allegro_KEY_7 :
   cont1.key[7] = 1;
   break;
  case __allegro_KEY_8 :
   cont1.key[6] = 1;
   break;
  case __allegro_KEY_9 :
   cont1.key[5] = 1;
   break;
  case __allegro_KEY_Z :
   irqst &= 0x7F;
   if(irqen & 0x80) irq6502();
   break;
  }
 }
}

canonical_original_code:
void HostDoEvents() {
 char pckey;
 cont1.trig = 0;
 cont2.trig = 0;
    cont1.side_button = 0;
    cont2.side_button = 0;
 cont1.left = cont1.right = cont1.up = cont1.down = 0;
 cont2.left = cont2.right = cont2.up = cont2.down = 0;
 if(key[__allegro_KEY_LEFT]) cont1.left = 1;
 else if(key[__allegro_KEY_RIGHT]) cont1.right = 1;
 if(key[__allegro_KEY_UP]) cont1.up = 1;
 else if(key[__allegro_KEY_DOWN]) cont1.down = 1;
 if(key[__allegro_KEY_SPACE]) cont1.trig = 1;
    if(key[__allegro_KEY_LCONTROL]) cont1.side_button = 1;
 if(key[__allegro_KEY_F9]) {
  SaveState("state");
  rest(1000);
 }
 if(key[__allegro_KEY_F10]) {
  LoadState("state");
  rest(1000);
 }
 if(key[__allegro_KEY_P]) {
  textout(screen, font, "*PAUSED*", 128, 100, 15);
  rest(500);
  while(!key[__allegro_KEY_P] && !key[__allegro_KEY_ENTER] && !key[__allegro_KEY_SPACE]);
  rest(200);
 }
 if(keypressed()) {
  pckey = readkey() >> 8;
  switch(pckey) {
  case __allegro_KEY_TILDE :
            put6502memory(0x02, 253);
            break;
  case __allegro_KEY_F1 :
   cont1.key[12] = 1;
   break;
  case __allegro_KEY_SLASH :
   cont2.key[12] = 1;
   break;
  case __allegro_KEY_F2 :
  case __allegro_KEY_PAUSE :
   cont1.key[8] = 1;
   break;
  case __allegro_KEY_ASTERISK :
   cont2.key[8] = 1;
   break;
  case __allegro_KEY_F3 :
   cont1.key[4] = 1;
   break;
  case __allegro_KEY_MINUS_PAD :
   cont2.key[4] = 1;
   break;
  case __allegro_KEY_ESC :
  case __allegro_KEY_F4 :
   sprintf(errormsg, "Halt pressed!\n");
   running = 0;
   break;
  case __allegro_KEY_F5 :
  case __allegro_KEY_MINUS :
   cont1.key[3] = 1;
   break;
  case __allegro_KEY_F6 :
  case __allegro_KEY_EQUALS :
   cont1.key[1] = 1;
   break;
  case __allegro_KEY_DEL :
   cont2.key[3] = 1;
   break;
  case __allegro_KEY_ENTER :
   cont2.key[3] = 1;
   break;
  case __allegro_KEY_F7 :
   break;
  case __allegro_KEY_F8 :
   break;
  case __allegro_KEY_F11 :
   if(fps_on) fps_on = 0;
   else fps_on = 1;
   rest(500);
   break;
  case __allegro_KEY_F12 :
   break;
  case __allegro_KEY_0 :
   cont1.key[2] = 1;
   break;
  case __allegro_KEY_1 :
   cont1.key[15] = 1;
   break;
  case __allegro_KEY_2 :
   cont1.key[14] = 1;
   break;
  case __allegro_KEY_3 :
   cont1.key[13] = 1;
   break;
  case __allegro_KEY_4 :
   cont1.key[11] = 1;
   break;
  case __allegro_KEY_5 :
   cont1.key[10] = 1;
   break;
  case __allegro_KEY_6 :
   cont1.key[9] = 1;
   break;
  case __allegro_KEY_7 :
   cont1.key[7] = 1;
   break;
  case __allegro_KEY_8 :
   cont1.key[6] = 1;
   break;
  case __allegro_KEY_9 :
   cont1.key[5] = 1;
   break;
  case __allegro_KEY_Z :
   irqst &= 0x7F;
   if(irqen & 0x80) irq6502();
   break;
  }
 }
}

variable_types: pckey char


HostPrepareForPaletteSet

decompiled_code:
void HostPrepareForPaletteSet()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void HostPrepareForPaletteSet(void) {
}

canonical_original_code:
void HostPrepareForPaletteSet() {
}


HostSetPaletteEntry

decompiled_code:
__int64 __fastcall HostSetPaletteEntry(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned int i; // ebx
__int64 result; // rax
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a2 >> 2;
v6[1] = a3 >> 2;
v6[2] = a4 >> 2;
set_color(a1, v6);
for ( i = 0; i != 256; ++i )
result = vline(screen, i, 256LL, 264LL, i);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned int i; // ebx
__int64 result; // rax
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a2 >> 2;
v6[1] = a3 >> 2;
v6[2] = a4 >> 2;
set_color(a1, v6);
for ( i = 0; i != 256; ++i )
result = func0(screen, i, 256LL, 264LL, i);
return result;
}

original_code:
void HostSetPaletteEntry(unsigned char entry, unsigned char red, unsigned char green, unsigned char blue) {
 int i;
 RGB col;
 col.r = red >> 2;
 col.g = green >> 2;
 col.b = blue >> 2;
 set_color(entry, &col);
    for(i=0; i<256; i++) {
  vline(screen, i, 256, 264, i);
    }
}

canonical_original_code:
void HostSetPaletteEntry(unsigned char entry, unsigned char red, unsigned char green, unsigned char blue) {
 int i;
 struct RGB col;
 col.r = red >> 2;
 col.g = green >> 2;
 col.b = blue >> 2;
 set_color(entry, &col);
    for(i=0; i<256; i++) {
  vline(screen, i, 256, 264, i);
    }
}

variable_types:
entry
unsigned char

variable_types:
red
unsigned char

variable_types:
green
unsigned char

variable_types:
blue
unsigned char

variable_types: struct RGB { unsigned char r; unsigned char filler; }


HostRefreshPalette

decompiled_code:
void HostRefreshPalette()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void HostRefreshPalette(void) {
}

canonical_original_code:
void HostRefreshPalette() {
}


HostBlitVideo

decompiled_code:
__int64 HostBlitVideo()
{
while ( frame < framespeed )
vsync();
frame = 0;
if ( videomode == 15 )
{
if ( fcounter > 59 )
{
fps = framesdrawn;
framesdrawn = 0;
fcounter = 0;
}
}
else if ( fcounter > 49 )
{
fps = framesdrawn;
framesdrawn = 0;
fcounter = 0;
}
if ( fps_on )
textprintf(gfxdest, font, 8LL, 0LL, 15LL, "fps: %d\n", (unsigned int)fps);
return blit(gfxdest, screen, 0LL, 0LL, 0LL, 0LL, 384LL, 240LL);
}

canonical_decompiled_code:
__int64 func10()
{
while ( frame < framespeed )
vsync();
frame = 0;
if ( videomode == 15 )
{
if ( fcounter > 59 )
{
fps = framesdrawn;
framesdrawn = 0;
fcounter = 0;
}
}
else if ( fcounter > 49 )
{
fps = framesdrawn;
framesdrawn = 0;
fcounter = 0;
}
if ( fps_on )
textprintf(gfxdest, font, 8LL, 0LL, 15LL, "fps: %d\n", (unsigned int)fps);
return blit(gfxdest, screen, 0LL, 0LL, 0LL, 0LL, 384LL, 240LL);
}

original_code:
void HostBlitVideo(void) {
    while(frame < framespeed) vsync();
    frame = 0;
    if(videomode == 0x0F) {
        if(fcounter > 59) {
            fps = framesdrawn;
            framesdrawn = 0;
            fcounter = 0;
        }
    }
    else {
        if(fcounter > 49) {
            fps = framesdrawn;
            framesdrawn = 0;
            fcounter = 0;
        }
    }
 if(fps_on) textprintf(gfxdest, font, 8, 0, 15, "fps: %d\n", fps);
 blit(gfxdest, screen, 0, 0, 0, 0, 384, 240);
}

canonical_original_code:
void HostBlitVideo() {
    while(frame < framespeed) vsync();
    frame = 0;
    if(videomode == 0x0F) {
        if(fcounter > 59) {
            fps = framesdrawn;
            framesdrawn = 0;
            fcounter = 0;
        }
    }
    else {
        if(fcounter > 49) {
            fps = framesdrawn;
            framesdrawn = 0;
            fcounter = 0;
        }
    }
 if(fps_on) textprintf(gfxdest, font, 8, 0, 15, "fps: %d\n", fps);
 blit(gfxdest, screen, 0, 0, 0, 0, 384, 240);
}


HostEnableInterrupts

decompiled_code:
void HostEnableInterrupts()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void HostEnableInterrupts(void) {
}

canonical_original_code:
void HostEnableInterrupts() {
}


HostDisableInterrupts

decompiled_code:
void HostDisableInterrupts()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void HostDisableInterrupts(void) {
}

canonical_original_code:
void HostDisableInterrupts() {
}


HostProcessSoundBuffer

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

if ( sound_on )
result = stream_pokey();
return result;
}

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

if ( sound_on )
result = func6();
return result;
}

original_code:
void HostProcessSoundBuffer(void) {
 if(sound_on) stream_pokey();
}

canonical_original_code:
void HostProcessSoundBuffer() {
 if(sound_on) stream_pokey();
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v4; // rax
__int64 v5; // rbp
__int64 v6; // rbp
unsigned int v7; // eax
__int64 v9; // rdx
__int64 v10; // rsi
__int64 v11; // rax
_QWORD *v12; // rdx

puts("Main!");
puts("Initialising Allegro...");
puts(&allegro_id);
v4 = _errno_location();
v5 = (unsigned int)install_allegro_version_check(0LL, v4, &atexit, 263170LL);
printf("allegro_init() returned %d\n", v5);
if ( (_DWORD)v5 )
{
puts("Error initialising Allegro!");
exit(1);
}
install_timer();
install_keyboard();
install_mouse();
puts("Initialising sound...");
v6 = (unsigned int)install_sound(0xFFFFFFFFLL, 0LL, 0LL);
printf("install_sound() returned %d\n", v6);
if ( (_DWORD)v6 )
{
puts("Error initialising sound!");
exit(2);
}
puts("Setting up GFX mode...");
set_color_depth(8LL);
v7 = set_gfx_mode(0LL, 320LL, 240LL, 0LL, 0LL);
sprintf(errormsg, "set_gfx_mode() returned %d\n", v7);
if ( !(unsigned int)Jum52_Initialise() )
{
printf("vid address: %8X\n", vid);
v9 = create_bitmap(384LL, 270LL);
gfxdest = v9;
v10 = vid;
*(_QWORD *)(v9 + 56) = vid;
v11 = v10;
v12 = (_QWORD *)(v9 + 96);
do
{
*v12 = v11;
v11 += 384LL;
++v12;
}
while ( v11 != v10 + 103680 );
printf("gfxdest.dat address: %8X\n", v10);
printf("gfxdest.line[0] address: %8X\n", *(_QWORD *)(gfxdest + 96));
videomode = 15;
if ( (*argv[2] & 0xDF) == 80 )
{
videomode = 1;
puts("PAL mode (50 Hz)");
install_int(mytimerhandler, 20LL);
}
else
{
puts("NTSC mode (60 Hz)");
install_int(mytimerhandler, 16LL);
}
frame = 0;
framespeed = 1;
fps = 0;
fps_on = 0;
if ( (unsigned int)Jum52_LoadROM(argv[1]) )
{
puts("Could not load ROM!");
goto LABEL_19;
}
sound_on = 1;
sound_vol = 240;
if ( (unsigned int)init5200sound() )
{
puts("init5200sound() failed.");
sound_on = 0;
}
else if ( sound_on )
{
goto LABEL_14;
}
puts("Sound disabled - POKEY emulation not started.");
LABEL_14:
Jum52_Emulate();
if ( sound_on )
kill5200sound();
LABEL_19:
exit(0);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v4; // rax
__int64 v5; // rbp
__int64 v6; // rbp
unsigned int v7; // eax
__int64 v9; // rdx
__int64 v10; // rsi
__int64 v11; // rax
_QWORD *v12; // rdx

puts("Main!");
puts("Initialising Allegro...");
puts(&allegro_id);
v4 = _errno_location();
v5 = (unsigned int)install_allegro_version_check(0LL, v4, &atexit, 263170LL);
printf("allegro_init() returned %d\n", v5);
if ( (_DWORD)v5 )
{
puts("Error initialising Allegro!");
exit(1);
}
install_timer();
install_keyboard();
install_mouse();
puts("Initialising sound...");
v6 = (unsigned int)install_sound(0xFFFFFFFFLL, 0LL, 0LL);
printf("install_sound() returned %d\n", v6);
if ( (_DWORD)v6 )
{
puts("Error initialising sound!");
exit(2);
}
puts("Setting up GFX mode...");
set_color_depth(8LL);
v7 = set_gfx_mode(0LL, 320LL, 240LL, 0LL, 0LL);
sprintf(errormsg, "set_gfx_mode() returned %d\n", v7);
if ( !(unsigned int)Jum52_Initialise() )
{
printf("vid address: %8X\n", vid);
v9 = create_bitmap(384LL, 270LL);
gfxdest = v9;
v10 = vid;
*(_QWORD *)(v9 + 56) = vid;
v11 = v10;
v12 = (_QWORD *)(v9 + 96);
do
{
*v12 = v11;
v11 += 384LL;
++v12;
}
while ( v11 != v10 + 103680 );
printf("gfxdest.dat address: %8X\n", v10);
printf("gfxdest.line[0] address: %8X\n", *(_QWORD *)(gfxdest + 96));
videomode = 15;
if ( (*argv[2] & 0xDF) == 80 )
{
videomode = 1;
puts("PAL mode (50 Hz)");
install_int(mytimerhandler, 20LL);
}
else
{
puts("NTSC mode (60 Hz)");
install_int(mytimerhandler, 16LL);
}
frame = 0;
framespeed = 1;
fps = 0;
fps_on = 0;
if ( (unsigned int)Jum52_LoadROM(argv[1]) )
{
puts("Could not load ROM!");
goto LABEL_19;
}
sound_on = 1;
sound_vol = 240;
if ( (unsigned int)func3() )
{
puts("init5200sound() failed.");
sound_on = 0;
}
else if ( sound_on )
{
goto LABEL_14;
}
puts("Sound disabled - POKEY emulation not started.");
LABEL_14:
Jum52_Emulate();
if ( sound_on )
func5();
LABEL_19:
exit(0);
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int i;
 printf("Main!\n");
 printf("Initialising Allegro...\n");
    printf("%s\n", allegro_id);
 i = _install_allegro_version_check(0, &(*__errno_location ()), (int (*)(void (*)(void)))atexit, (((4)<<16)|((4)<<8)|(2)));
 printf("allegro_init() returned %d\n", i);
 if(i) {
  printf("Error initialising Allegro!\n");
  exit(1);
 }
 install_timer();
 install_keyboard();
 install_mouse();
 printf("Initialising sound...\n");
 i = install_sound(-1, 0, ((void *)0));
 printf("install_sound() returned %d\n", i);
 if(i) {
  printf("Error initialising sound!\n");
  exit(2);
 }
 printf("Setting up GFX mode...\n");
 set_color_depth(8);
 i = set_gfx_mode(0, 320, 240, 0, 0);
 sprintf(errormsg, "set_gfx_mode() returned %d\n", i);
 if (Jum52_Initialise() == 0)
 {
  printf("vid address: %8X\n", vid);
  gfxdest = create_bitmap(384, 270);
  gfxdest->dat = (void *)vid;
  for(i=0; i<270; i++) {
   gfxdest->line[i] = vid + (i * 384);
  }
  printf("gfxdest.dat address: %8X\n", gfxdest->dat);
  printf("gfxdest.line[0] address: %8X\n", gfxdest->line[0]);
  videomode = 0x0F;
  if((*argv[2] == 'P') || (*argv[2] == 'p')) videomode = 0x01;
  ;
  ;
  ;
  if(videomode == 0x0F) {
   printf("NTSC mode (60 Hz)\n");
   i = install_int(mytimerhandler, 16);
  }
  else {
   printf("PAL mode (50 Hz)\n");
   i = install_int(mytimerhandler, 20);
  }
  frame = 0;
  framespeed = 1;
  fps = 0;
  fps_on = 0;
  if (Jum52_LoadROM(argv[1]) == 0)
  {
   sound_on = 1;
   sound_vol = 240;
      if(sound_on) {
       if(init5200sound()) {
           printf("init5200sound() failed.\n");
                    sound_on = 0;
    }
      }
            if(!sound_on) printf("Sound disabled - POKEY emulation not started.\n");
   Jum52_Emulate();
   if(sound_on) kill5200sound();
  }
  else {
   printf("Could not load ROM!\n");
  }
  exit(0);
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int i;
 printf("Main!\n");
 printf("Initialising Allegro...\n");
    printf("%s\n", allegro_id);
 i = _install_allegro_version_check(0, &(*__errno_location ()), (int (*)(void (*)()))atexit, (((4)<<16)|((4)<<8)|(2)));
 printf("allegro_init() returned %d\n", i);
 if(i) {
  printf("Error initialising Allegro!\n");
  exit(1);
 }
 install_timer();
 install_keyboard();
 install_mouse();
 printf("Initialising sound...\n");
 i = install_sound(-1, 0, ((void *)0));
 printf("install_sound() returned %d\n", i);
 if(i) {
  printf("Error initialising sound!\n");
  exit(2);
 }
 printf("Setting up GFX mode...\n");
 set_color_depth(8);
 i = set_gfx_mode(0, 320, 240, 0, 0);
 sprintf(errormsg, "set_gfx_mode() returned %d\n", i);
 if (Jum52_Initialise() == 0)
 {
  printf("vid address: %8X\n", vid);
  gfxdest = create_bitmap(384, 270);
  gfxdest->dat = (void *)vid;
  for(i=0; i<270; i++) {
   gfxdest->line[i] = vid + (i * 384);
  }
  printf("gfxdest.dat address: %8X\n", gfxdest->dat);
  printf("gfxdest.line[0] address: %8X\n", gfxdest->line[0]);
  videomode = 0x0F;
  if((*argv[2] == 'P') || (*argv[2] == 'p')) videomode = 0x01;
  ;
  ;
  ;
  if(videomode == 0x0F) {
   printf("NTSC mode (60 Hz)\n");
   i = install_int(mytimerhandler, 16);
  }
  else {
   printf("PAL mode (50 Hz)\n");
   i = install_int(mytimerhandler, 20);
  }
  frame = 0;
  framespeed = 1;
  fps = 0;
  fps_on = 0;
  if (Jum52_LoadROM(argv[1]) == 0)
  {
   sound_on = 1;
   sound_vol = 240;
      if(sound_on) {
       if(init5200sound()) {
           printf("init5200sound() failed.\n");
                    sound_on = 0;
    }
      }
            if(!sound_on) printf("Sound disabled - POKEY emulation not started.\n");
   Jum52_Emulate();
   if(sound_on) kill5200sound();
  }
  else {
   printf("Could not load ROM!\n");
  }
  exit(0);
 }
}

variable_types:
argv
char *[]


decompiled_code:
char *__fastcall check_for_hwaddr(__int16 a1)
{
unsigned __int64 v1; // rdx
int v2; // eax

v1 = (unsigned int)((_DWORD)hwtable + 20);
v2 = 0;
while ( *(_WORD *)v1 != a1 )
{
++v2;
v1 += 22LL;
if ( v2 == 103 )
return 0LL;
}
return &hwtable[22 * v2];
}

canonical_decompiled_code:
char *__fastcall func0(__int16 a1)
{
unsigned __int64 v1; // rdx
int v2; // eax

v1 = (unsigned int)((_DWORD)hwtable + 20);
v2 = 0;
while ( *(_WORD *)v1 != a1 )
{
++v2;
v1 += 22LL;
if ( v2 == 103 )
return 0LL;
}
return &hwtable[22 * v2];
}

original_code:
char *check_for_hwaddr(uint16 thisaddr) {
     int i;
     for(i=0; i<103; i++) {
         if(thisaddr == hwtable[i].hwaddr) return hwtable[i].name;
     }
     return (char *)((void *)0);
}

canonical_original_code:
char *check_for_hwaddr(unsigned short thisaddr) {
     int i;
     for(i=0; i<103; i++) {
         if(thisaddr == hwtable[i].hwaddr) return hwtable[i].name;
     }
     return (char *)((void *)0);
}

variable_types:
thisaddr
unsigned short


decompiled_code:
char *__fastcall add_hw_tag(char *dest, __int16 a2)
{
char *result; // rax
const char *v3; // r13
int v4; // er12
int i; // ebx

result = check_for_hwaddr(a2);
if ( result )
{
v3 = result;
v4 = 12 - strlen(dest);
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
*(_WORD *)&dest[strlen(dest)] = 32;
}
result = strcat(dest, v3);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *dest, __int16 a2)
{
char *result; // rax
const char *v3; // r13
int v4; // er12
int i; // ebx

result = func0(a2);
if ( result )
{
v3 = result;
v4 = 12 - strlen(dest);
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
*(_WORD *)&dest[strlen(dest)] = 32;
}
result = strcat(dest, v3);
}
return result;
}

original_code:
void add_hw_tag(char *s, uint16 addr) {
 int i, len;
 char *hwname;
    hwname = check_for_hwaddr(addr);
    if(hwname) {
  len = strlen(s);
  for(i=0; i<12-len; i++)
   strcat(s, " ");
  strcat(s, hwname);
 }
}

canonical_original_code:
void add_hw_tag(char *s, unsigned short addr) {
 int i; int len;
 char *hwname;
    hwname = check_for_hwaddr(addr);
    if(hwname) {
  len = strlen(s);
  for(i=0; i<12-len; i++)
   strcat(s, " ");
  strcat(s, hwname);
 }
}

variable_types:
s
char *

variable_types:
addr
unsigned short

variable_types: len int

variable_types:
hwname
char *


hexview

decompiled_code:
__int64 __fastcall hexview(unsigned __int16 a1)
{
__int64 v1; // rbp
int i; // ebx
int v3; // edx
int v4; // edx

memory = memory5200;
clrEmuScreen(0LL);
v1 = a1;
for ( i = 0; i != 160; ++i )
{
if ( (i & 7) == 0 )
{
sprintf(msg, "%4X: ", (unsigned int)v1);
v4 = i + 7;
if ( i >= 0 )
v4 = i;
printXY(msg, 0LL, v4 & 0xFFFFFFF8, 14LL);
}
sprintf(msg, "%02X", *(unsigned __int8 *)(memory + v1));
v3 = i + 7;
if ( i >= 0 )
v3 = i;
printXY(msg, (unsigned int)(32 * (i % 8) + 48), v3 & 0xFFFFFFF8, 14LL);
++v1;
}
printXY("Press any key to continue...", 0LL, 230LL, 15LL);
return BlitBuffer(0LL, 240LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1)
{
__int64 v1; // rbp
int i; // ebx
int v3; // edx
int v4; // edx

memory = memory5200;
clrEmuScreen(0LL);
v1 = a1;
for ( i = 0; i != 160; ++i )
{
if ( (i & 7) == 0 )
{
sprintf(msg, "%4X: ", (unsigned int)v1);
v4 = i + 7;
if ( i >= 0 )
v4 = i;
printXY(msg, 0LL, v4 & 0xFFFFFFF8, 14LL);
}
sprintf(msg, "%02X", *(unsigned __int8 *)(memory + v1));
v3 = i + 7;
if ( i >= 0 )
v3 = i;
printXY(msg, (unsigned int)(32 * (i % 8) + 48), v3 & 0xFFFFFFF8, 14LL);
++v1;
}
printXY("Press any key to continue...", 0LL, 230LL, 15LL);
return BlitBuffer(0LL, 240LL);
}

original_code:
void hexview(uint16 viewaddr) {
     int i, count;
     count = 0;
     memory = memory5200;
     clrEmuScreen(0x00);
     for(i=viewaddr; i < viewaddr + 160; i++) {
         if((count % 8) == 0) {
    sprintf(msg, "%4X: ", i);
    printXY(msg, 0, (count / 8) * 8, 14);
   }
   sprintf(msg, "%02X", memory[i]);
         printXY(msg, 48 + 32 * (count % 8), (count / 8) * 8, 14);
         count++;
     }
  printXY("Press any key to continue...", 0, 230, 15);
  BlitBuffer(0, 240);
}

canonical_original_code:
void hexview(unsigned short viewaddr) {
     int i; int count;
     count = 0;
     memory = memory5200;
     clrEmuScreen(0x00);
     for(i=viewaddr; i < viewaddr + 160; i++) {
         if((count % 8) == 0) {
    sprintf(msg, "%4X: ", i);
    printXY(msg, 0, (count / 8) * 8, 14);
   }
   sprintf(msg, "%02X", memory[i]);
         printXY(msg, 48 + 32 * (count % 8), (count / 8) * 8, 14);
         count++;
     }
  printXY("Press any key to continue...", 0, 230, 15);
  BlitBuffer(0, 240);
}

variable_types:
viewaddr
unsigned short

variable_types: count int


listvectors

decompiled_code:
__int64 listvectors()
{
memory = memory5200;
clrEmuScreen(0LL);
printXY("Page Two IRQ Vectors:", 8LL, 0LL, 15LL);
sprintf(msg, "$200 Imm IRQ: %02X%02X", *(unsigned __int8 *)(memory + 513), *(unsigned __int8 *)(memory + 512));
printXY(msg, 8LL, 16LL, 15LL);
sprintf(msg, "$202 Imm VBI: %02X%02X", *(unsigned __int8 *)(memory + 515), *(unsigned __int8 *)(memory + 514));
printXY(msg, 8LL, 24LL, 15LL);
sprintf(msg, "$204 Def VBI: %02X%02X", *(unsigned __int8 *)(memory + 517), *(unsigned __int8 *)(memory + 516));
printXY(msg, 8LL, 32LL, 15LL);
sprintf(msg, "$206 DLI Vec: %02X%02X", *(unsigned __int8 *)(memory + 519), *(unsigned __int8 *)(memory + 518));
printXY(msg, 8LL, 40LL, 15LL);
sprintf(msg, "$208 Key IRQ: %02X%02X", *(unsigned __int8 *)(memory + 521), *(unsigned __int8 *)(memory + 520));
printXY(msg, 8LL, 48LL, 15LL);
sprintf(msg, "$20A Key cont: %02X%02X", *(unsigned __int8 *)(memory + 523), *(unsigned __int8 *)(memory + 522));
printXY(msg, 8LL, 56LL, 15LL);
sprintf(msg, "$20C BREAK Key IRQ: %02X%02X", *(unsigned __int8 *)(memory + 525), *(unsigned __int8 *)(memory + 524));
printXY(msg, 8LL, 64LL, 15LL);
sprintf(msg, "$20E BRK instr IRQ: %02X%02X", *(unsigned __int8 *)(memory + 527), *(unsigned __int8 *)(memory + 526));
printXY(msg, 8LL, 72LL, 15LL);
printXY("Press any key to continue...", 0LL, 230LL, 15LL);
return BlitBuffer(0LL, 240LL);
}

canonical_decompiled_code:
__int64 func3()
{
memory = memory5200;
clrEmuScreen(0LL);
printXY("Page Two IRQ Vectors:", 8LL, 0LL, 15LL);
sprintf(msg, "$200 Imm IRQ: %02X%02X", *(unsigned __int8 *)(memory + 513), *(unsigned __int8 *)(memory + 512));
printXY(msg, 8LL, 16LL, 15LL);
sprintf(msg, "$202 Imm VBI: %02X%02X", *(unsigned __int8 *)(memory + 515), *(unsigned __int8 *)(memory + 514));
printXY(msg, 8LL, 24LL, 15LL);
sprintf(msg, "$204 Def VBI: %02X%02X", *(unsigned __int8 *)(memory + 517), *(unsigned __int8 *)(memory + 516));
printXY(msg, 8LL, 32LL, 15LL);
sprintf(msg, "$206 DLI Vec: %02X%02X", *(unsigned __int8 *)(memory + 519), *(unsigned __int8 *)(memory + 518));
printXY(msg, 8LL, 40LL, 15LL);
sprintf(msg, "$208 Key IRQ: %02X%02X", *(unsigned __int8 *)(memory + 521), *(unsigned __int8 *)(memory + 520));
printXY(msg, 8LL, 48LL, 15LL);
sprintf(msg, "$20A Key cont: %02X%02X", *(unsigned __int8 *)(memory + 523), *(unsigned __int8 *)(memory + 522));
printXY(msg, 8LL, 56LL, 15LL);
sprintf(msg, "$20C BREAK Key IRQ: %02X%02X", *(unsigned __int8 *)(memory + 525), *(unsigned __int8 *)(memory + 524));
printXY(msg, 8LL, 64LL, 15LL);
sprintf(msg, "$20E BRK instr IRQ: %02X%02X", *(unsigned __int8 *)(memory + 527), *(unsigned __int8 *)(memory + 526));
printXY(msg, 8LL, 72LL, 15LL);
printXY("Press any key to continue...", 0LL, 230LL, 15LL);
return BlitBuffer(0LL, 240LL);
}

original_code:
void listvectors(void) {
 memory = memory5200;
 clrEmuScreen(0x00);
 printXY("Page Two IRQ Vectors:", 8, 0, 15);
 sprintf(msg, "$200 Imm IRQ: %02X%02X", memory[0x201], memory[0x200]);
 printXY(msg, 8, 16, 15);
 sprintf(msg, "$202 Imm VBI: %02X%02X", memory[0x203], memory[0x202]);
 printXY(msg, 8, 24, 15);
 sprintf(msg, "$204 Def VBI: %02X%02X", memory[0x205], memory[0x204]);
 printXY(msg, 8, 32, 15);
 sprintf(msg, "$206 DLI Vec: %02X%02X", memory[0x207], memory[0x206]);
 printXY(msg, 8, 40, 15);
 sprintf(msg, "$208 Key IRQ:  %02X%02X", memory[0x209], memory[0x208]);
 printXY(msg, 8, 48, 15);
 sprintf(msg, "$20A Key cont: %02X%02X", memory[0x20B], memory[0x20A]);
 printXY(msg, 8, 56, 15);
 sprintf(msg, "$20C BREAK Key IRQ: %02X%02X", memory[0x20D], memory[0x20C]);
 printXY(msg, 8, 64, 15);
 sprintf(msg, "$20E BRK instr IRQ: %02X%02X", memory[0x20F], memory[0x20E]);
 printXY(msg, 8, 72, 15);
 printXY("Press any key to continue...", 0, 230, 15);
 BlitBuffer(0, 240);
}

canonical_original_code:
void listvectors() {
 memory = memory5200;
 clrEmuScreen(0x00);
 printXY("Page Two IRQ Vectors:", 8, 0, 15);
 sprintf(msg, "$200 Imm IRQ: %02X%02X", memory[0x201], memory[0x200]);
 printXY(msg, 8, 16, 15);
 sprintf(msg, "$202 Imm VBI: %02X%02X", memory[0x203], memory[0x202]);
 printXY(msg, 8, 24, 15);
 sprintf(msg, "$204 Def VBI: %02X%02X", memory[0x205], memory[0x204]);
 printXY(msg, 8, 32, 15);
 sprintf(msg, "$206 DLI Vec: %02X%02X", memory[0x207], memory[0x206]);
 printXY(msg, 8, 40, 15);
 sprintf(msg, "$208 Key IRQ:  %02X%02X", memory[0x209], memory[0x208]);
 printXY(msg, 8, 48, 15);
 sprintf(msg, "$20A Key cont: %02X%02X", memory[0x20B], memory[0x20A]);
 printXY(msg, 8, 56, 15);
 sprintf(msg, "$20C BREAK Key IRQ: %02X%02X", memory[0x20D], memory[0x20C]);
 printXY(msg, 8, 64, 15);
 sprintf(msg, "$20E BRK instr IRQ: %02X%02X", memory[0x20F], memory[0x20E]);
 printXY(msg, 8, 72, 15);
 printXY("Press any key to continue...", 0, 230, 15);
 BlitBuffer(0, 240);
}


printhelp

decompiled_code:
__int64 printhelp()
{
clrEmuScreen(0LL);
printXY("AVAILABLE COMMANDS:", 0LL, 0LL, 13LL);
printXY("<Enter> Disassemble at current address.", 16LL, 8LL, 13LL);
printXY("s Step thru current instruction.", 16LL, 16LL, 13LL);
printXY("S Step thru current scanline.", 16LL, 24LL, 13LL);
printXY("f run till next frame / VBI", 16LL, 32LL, 13LL);
printXY("r Run / Resume", 16LL, 40LL, 13LL);
printXY("D <addr> disassemble address <addr>", 16LL, 48LL, 13LL);
printXY("v View hexdump at current address", 16LL, 56LL, 13LL);
printXY("V <addr> View hexdump at address <addr>", 16LL, 64LL, 13LL);
printXY("l View display list data", 16LL, 72LL, 13LL);
printXY("c View character set", 16LL, 80LL, 13LL);
printXY("p View player/missile data", 16LL, 88LL, 13LL);
printXY("1 Show collision registers", 16LL, 96LL, 13LL);
printXY("i List interrupt vectors", 16LL, 104LL, 13LL);
printXY("T <addr> run to <addr>", 16LL, 112LL, 13LL);
printXY("K trigger Keyboard interrupt", 16LL, 120LL, 13LL);
printXY("B trigger Break interrupt", 16LL, 128LL, 13LL);
printXY("0 Set TRIG0 to 0", 16LL, 136LL, 13LL);
printXY("Q or quit Quit / Exit", 16LL, 144LL, 13LL);
printXY("Press any key to continue...", 0LL, 230LL, 15LL);
return BlitBuffer(0LL, 240LL);
}

canonical_decompiled_code:
__int64 func4()
{
clrEmuScreen(0LL);
printXY("AVAILABLE COMMANDS:", 0LL, 0LL, 13LL);
printXY("<Enter> Disassemble at current address.", 16LL, 8LL, 13LL);
printXY("s Step thru current instruction.", 16LL, 16LL, 13LL);
printXY("S Step thru current scanline.", 16LL, 24LL, 13LL);
printXY("f run till next frame / VBI", 16LL, 32LL, 13LL);
printXY("r Run / Resume", 16LL, 40LL, 13LL);
printXY("D <addr> disassemble address <addr>", 16LL, 48LL, 13LL);
printXY("v View hexdump at current address", 16LL, 56LL, 13LL);
printXY("V <addr> View hexdump at address <addr>", 16LL, 64LL, 13LL);
printXY("l View display list data", 16LL, 72LL, 13LL);
printXY("c View character set", 16LL, 80LL, 13LL);
printXY("p View player/missile data", 16LL, 88LL, 13LL);
printXY("1 Show collision registers", 16LL, 96LL, 13LL);
printXY("i List interrupt vectors", 16LL, 104LL, 13LL);
printXY("T <addr> run to <addr>", 16LL, 112LL, 13LL);
printXY("K trigger Keyboard interrupt", 16LL, 120LL, 13LL);
printXY("B trigger Break interrupt", 16LL, 128LL, 13LL);
printXY("0 Set TRIG0 to 0", 16LL, 136LL, 13LL);
printXY("Q or quit Quit / Exit", 16LL, 144LL, 13LL);
printXY("Press any key to continue...", 0LL, 230LL, 15LL);
return BlitBuffer(0LL, 240LL);
}

original_code:
void printhelp(void) {
 clrEmuScreen(0x00);
 printXY("AVAILABLE COMMANDS:", 0, 0, 13);
 printXY("<Enter>     Disassemble at current address.", 16, 8, 13);
 printXY("s           Step thru current instruction.", 16, 16, 13);
 printXY("S           Step thru current scanline.", 16, 24, 13);
 printXY("f           run till next frame / VBI", 16, 32, 13);
 printXY("r           Run / Resume", 16, 40, 13);
 printXY("D <addr>    disassemble address <addr>", 16, 48, 13);
 printXY("v           View hexdump at current address", 16, 56, 13);
 printXY("V <addr>    View hexdump at address <addr>", 16, 64, 13);
 printXY("l           View display list data", 16, 72, 13);
 printXY("c           View character set", 16, 80, 13);
 printXY("p           View player/missile data", 16, 88, 13);
 printXY("1           Show collision registers", 16, 96, 13);
 printXY("i           List interrupt vectors", 16, 104, 13);
 printXY("T <addr>    run to <addr>", 16, 112, 13);
 printXY("K           trigger Keyboard interrupt", 16, 120, 13);
 printXY("B           trigger Break interrupt", 16, 128, 13);
 printXY("0           Set TRIG0 to 0", 16, 136, 13);
 printXY("Q or quit   Quit / Exit", 16, 144, 13);
 printXY("Press any key to continue...", 0, 230, 15);
 BlitBuffer(0, 240);
}

canonical_original_code:
void printhelp() {
 clrEmuScreen(0x00);
 printXY("AVAILABLE COMMANDS:", 0, 0, 13);
 printXY("<Enter>     Disassemble at current address.", 16, 8, 13);
 printXY("s           Step thru current instruction.", 16, 16, 13);
 printXY("S           Step thru current scanline.", 16, 24, 13);
 printXY("f           run till next frame / VBI", 16, 32, 13);
 printXY("r           Run / Resume", 16, 40, 13);
 printXY("D <addr>    disassemble address <addr>", 16, 48, 13);
 printXY("v           View hexdump at current address", 16, 56, 13);
 printXY("V <addr>    View hexdump at address <addr>", 16, 64, 13);
 printXY("l           View display list data", 16, 72, 13);
 printXY("c           View character set", 16, 80, 13);
 printXY("p           View player/missile data", 16, 88, 13);
 printXY("1           Show collision registers", 16, 96, 13);
 printXY("i           List interrupt vectors", 16, 104, 13);
 printXY("T <addr>    run to <addr>", 16, 112, 13);
 printXY("K           trigger Keyboard interrupt", 16, 120, 13);
 printXY("B           trigger Break interrupt", 16, 128, 13);
 printXY("0           Set TRIG0 to 0", 16, 136, 13);
 printXY("Q or quit   Quit / Exit", 16, 144, 13);
 printXY("Press any key to continue...", 0, 230, 15);
 BlitBuffer(0, 240);
}