decompiled_code:
__int64 __fastcall get_item_by_id(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)a1 != a2 )
{
a1 = *(_QWORD *)(a1 + 48);
if ( !a1 )
return 0LL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)a1 != a2 )
{
a1 = *(_QWORD *)(a1 + 48);
if ( !a1 )
return 0LL;
}
return a1;
}

original_code:
menu_entry *get_item_by_id(menu_entry *list, int id)
{
 for(;list;list=list->next)
  if(list->id == id)
   return list;
 return ((void *)0);
}

canonical_original_code:
struct _menu_entry *get_item_by_id(struct _menu_entry *list, int id)
{
 for(;list;list=list->next)
  if(list->id == id)
   return list;
 return ((void *)0);
}

variable_types:
list
struct _menu_entry *

variable_types: id int

return_type: struct _menu_entry { unsigned int id; char *name; struct _menu_entry *next; } *


decompiled_code:
void __fastcall free_list(void *ptr)
{
_QWORD *v1; // rbx

v1 = ptr;
if ( ptr )
{
do
{
free_entry(v1);
v1 = (_QWORD *)v1[6];
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v1; // rbx

v1 = ptr;
if ( ptr )
{
do
{
func0(v1);
v1 = (_QWORD *)v1[6];
}
while ( v1 );
}
}

original_code:
void free_list(menu_entry *list)
{
 menu_entry *current;
 for(current=list;current;current=current->next)
  free_entry(current);
}

canonical_original_code:
void free_list(struct _menu_entry *list)
{
 struct _menu_entry *current;
 for(current=list;current;current=current->next)
  free_entry(current);
}

variable_types: struct _menu_entry { unsigned int id; char *name; struct _menu_entry *next; } *

return_type: void


decompiled_code:
__int64 __fastcall get_le_short(unsigned __int8 *a1)
{
return *a1 + (a1[1] << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
return *a1 + (a1[1] << 8);
}

original_code:
u2 get_le_short(void *from)
{
  u1 *p = from;
  return ((u2)(p[1]) << 8) +
    (u2)p[0];
}

canonical_original_code:
unsigned short get_le_short(void *from)
{
  unsigned char *p = from;
  return ((u2)(p[1]) << 8) +
    (unsigned short)p[0];
}

variable_types:
from
void *

variable_types:
p
unsigned char *

return_type: unsigned short


decompiled_code:
unsigned __int64 __fastcall get_le_long(unsigned __int8 *a1)
{
return ((unsigned __int64)a1[3] << 24) + ((unsigned __int64)a1[2] << 16) + *a1 + ((unsigned __int64)a1[1] << 8);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int8 *a1)
{
return ((unsigned __int64)a1[3] << 24) + ((unsigned __int64)a1[2] << 16) + *a1 + ((unsigned __int64)a1[1] << 8);
}

canonical_original_code:
unsigned long get_le_long(void *from)
{
  unsigned char *p = from;
  return ((u4)(p[3]) << 24) +
    ((u4)(p[2]) << 16) +
    ((u4)(p[1]) << 8) +
    (unsigned long)p[0];
}

return_type: unsigned long


decompiled_code:
const char *__fastcall find_filesystem(const char *a1)
{
int v1; // ebx
const char *result; // rax
char v3; // dl
unsigned __int64 v4; // rdx
bool v5; // cc
__int64 v6; // [rsp+0h] [rbp-4B8h] BYREF
unsigned __int8 v7[36]; // [rsp+438h] [rbp-80h] BYREF
unsigned __int8 v8[4]; // [rsp+45Ch] [rbp-5Ch] BYREF
unsigned __int8 v9[4]; // [rsp+460h] [rbp-58h] BYREF
unsigned __int8 v10[84]; // [rsp+464h] [rbp-54h] BYREF

v1 = open(a1, 0);
result = 0LL;
if ( v1 >= 0 )
{
if ( read(v1, &v6, 0x4B0uLL) < 0 )
{
close(v1);
result = 0LL;
}
else
{
close(v1);
if ( (unsigned __int16)get_le_short(v7) == 0xEF53 )
{
v3 = get_le_long(v8);
result = "ext2";
if ( (v3 & 4) != 0 )
{
v4 = get_le_long(v9);
result = "ext4";
if ( v4 <= 0x3F )
{
v5 = get_le_long(v10) <= 7;
result = "ext4";
if ( v5 )
result = "ext3";
}
}
}
else
{
*_errno_location() = 95;
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
int v1; // ebx
const char *result; // rax
char v3; // dl
unsigned __int64 v4; // rdx
bool v5; // cc
__int64 v6; // [rsp+0h] [rbp-4B8h] BYREF
unsigned __int8 v7[36]; // [rsp+438h] [rbp-80h] BYREF
unsigned __int8 v8[4]; // [rsp+45Ch] [rbp-5Ch] BYREF
unsigned __int8 v9[4]; // [rsp+460h] [rbp-58h] BYREF
unsigned __int8 v10[84]; // [rsp+464h] [rbp-54h] BYREF

v1 = open(a1, 0);
result = 0LL;
if ( v1 >= 0 )
{
if ( read(v1, &v6, 0x4B0uLL) < 0 )
{
close(v1);
result = 0LL;
}
else
{
close(v1);
if ( (unsigned __int16)func0(v7) == 0xEF53 )
{
v3 = func1(v8);
result = "ext2";
if ( (v3 & 4) != 0 )
{
v4 = func1(v9);
result = "ext4";
if ( v4 <= 0x3F )
{
v5 = func1(v10) <= 7;
result = "ext4";
if ( v5 )
result = "ext3";
}
}
}
else
{
*_errno_location() = 95;
result = 0LL;
}
}
}
return result;
}

original_code:
const char *find_filesystem(char *file)
{
 char buffer[1200];
 int fd,len,clustersize;
 if((fd = open(file,00)) < 0)
   return ((void *)0);
 if(read(fd,buffer,1200) < 0)
 {
   close(fd);
   return ((void *)0);
 }
 close(fd);
 if((get_le_short(buffer+0x438) == 0xEF53))
 {
  if(!(get_le_long(buffer+0x45c) & 0x4))
   return "ext2";
  else if ((get_le_long(buffer+0x460) < 0x40) && (get_le_long(buffer+0x464) < 0x8))
   return "ext3";
  else
   return "ext4";
 }
 (*__errno_location ())=95;
 return ((void *)0);
}

canonical_original_code:
char *find_filesystem(char *file)
{
 char buffer[1200];
 int fd; int len; int clustersize;
 if((fd = open(file,00)) < 0)
   return ((void *)0);
 if(read(fd,buffer,1200) < 0)
 {
   close(fd);
   return ((void *)0);
 }
 close(fd);
 if((get_le_short(buffer+0x438) == 0xEF53))
 {
  if(!(get_le_long(buffer+0x45c) & 0x4))
   return "ext2";
  else if ((get_le_long(buffer+0x460) < 0x40) && (get_le_long(buffer+0x464) < 0x8))
   return "ext3";
  else
   return "ext4";
 }
 (*__errno_location ())=95;
 return ((void *)0);
}

variable_types:
file
char *

variable_types:
buffer
char [1200]

variable_types: fd int

variable_types: len int

variable_types: clustersize int

return_type: char *


decompiled_code:
void __fastcall free_mountpoint(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void free_mountpoint(mountpoint *item)
{
  if(item->mountpoint)
    free(item->mountpoint);
  if(item->blkdev)
    free(item->blkdev);
  free(item);
}

canonical_original_code:
void free_mountpoint(struct _mountpoint *item)
{
  if(item->mountpoint)
    free(item->mountpoint);
  if(item->blkdev)
    free(item->blkdev);
  free(item);
}

variable_types: struct _mountpoint { char *mountpoint; char *filesystem; enum _options { WAIT=1, BIND=2 } options; int processed; enum source_type { NONE=0, BLKDEV=1, IMAGE_FILE=2, DIRECTORY=3 } s_type; struct _mountpoint *next; } *

user_defined_types: struct _mountpoint { char *mountpoint; char *filesystem; enum _options options; int processed; enum source_type s_type; struct _mountpoint *next; }


decompiled_code:
void __fastcall free_list(void *ptr)
{
_QWORD *v1; // rbx

v1 = ptr;
if ( ptr )
{
do
{
free_mountpoint(v1);
v1 = (_QWORD *)v1[5];
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v1; // rbx

v1 = ptr;
if ( ptr )
{
do
{
func0(v1);
v1 = (_QWORD *)v1[5];
}
while ( v1 );
}
}

original_code:
void free_list(mountpoint *list)
{
 mountpoint *current;
 for(current=list;current;current=current->next)
  free_mountpoint(current);
}

canonical_original_code:
void free_list(struct _mountpoint *list)
{
 struct _mountpoint *current;
 for(current=list;current;current=current->next)
  free_mountpoint(current);
}

user_defined_types: enum source_type { NONE=0, BLKDEV=1, IMAGE_FILE=2, DIRECTORY=3 }


repo: tuxera/macfuse

decompiled_code:
char *__fastcall unixfs_inodelayer_firstfromhash(__int64 a1)
{
return (char *)ihash_table + 8 * (ihash_mask & a1);
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
return (char *)ihash_table + 8 * (ihash_mask & a1);
}

original_code:
static ihash_head*
unixfs_inodelayer_firstfromhash(ino_t ino)
{
    return (ihash_head*)&ihash_table[ino & ihash_mask];
}

canonical_original_code:
static struct ihash_head *unixfs_inodelayer_firstfromhash(unsigned long ino)
{
    return (struct ihash_head *)&ihash_table[ino & ihash_mask];
}

variable_types:
ino
unsigned long

return_type: struct ihash_head { struct inode { struct { struct inode *le_next; struct inode **le_prev; } I_hashlink; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } I_state_cond; unsigned int I_initialized; unsigned int I_attachoutstanding; unsigned int I_waiting; unsigned int I_count; unsigned int I_blkbits; struct super_block { unsigned long s_magic; unsigned long s_flags; unsigned long s_blocksize; unsigned char s_blocksize_bits; unsigned char s_dirt; enum fs_endian_t { UNIXFS_FS_PDP=0, UNIXFS_FS_LITTLE=1, UNIXFS_FS_BIG=2, UNIXFS_FS_INVALID=3 } s_endian; void *s_fs_info; int s_bdev; int s_kdev; unsigned int s_dentsize; char s_fsname[90]; char s_volname[255]; struct statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; unsigned long f_favail; unsigned long f_fsid; unsigned long f_flag; unsigned long f_namemax; int __f_spare[6]; } s_statvfs; } *I_sb; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } I_stat; union { unsigned int I_daddr[13]; unsigned char I_addr[13]; } I_addr_un; void *I_private; } *lh_first; } *

user_defined_types: struct ihash_head { struct inode *lh_first; }

user_defined_types: struct inode { struct { struct inode *le_next; struct inode **le_prev; } I_hashlink; union pthread_cond_t I_state_cond; unsigned int I_initialized; unsigned int I_attachoutstanding; unsigned int I_waiting; unsigned int I_count; unsigned int I_blkbits; struct super_block *I_sb; struct stat I_stat; union { unsigned int I_daddr[13]; unsigned char I_addr[13]; } I_addr_un; void *I_private; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct super_block { unsigned long s_magic; unsigned long s_flags; unsigned long s_blocksize; unsigned char s_blocksize_bits; unsigned char s_dirt; enum fs_endian_t s_endian; void *s_fs_info; int s_bdev; int s_kdev; unsigned int s_dentsize; char s_fsname[90]; char s_volname[255]; struct statvfs s_statvfs; }


decompiled_code:
__int64 __fastcall unixfs_inodelayer_init(__int64 a1)
{
unsigned int v1; // ebp
int v2; // eax
__int64 i; // rdx
__int64 v4; // r12
__int64 v5; // rbx
_QWORD *v6; // rax
void *v7; // rcx
_QWORD *v8; // rdx

if ( pthread_mutex_init(&ihash_lock, 0LL) )
{
fwrite("failed to initialize the inode layer lock\n", 1uLL, 0x2AuLL, stderr);
v1 = -1;
}
else
{
v1 = 0;
iprivsize = a1;
v2 = 17;
for ( i = 1LL; --v2; i *= 2LL )
;
v4 = i & 0x7FFFFFFFFFFFFFFFLL;
v5 = i;
v6 = malloc(8 * i);
v7 = v6;
if ( v6 )
{
v8 = &v6[v5];
do
*v6++ = 0LL;
while ( v8 != v6 );
ihash_mask = v4 - 1;
ihash_table = v7;
}
else if ( !ihash_table )
{
pthread_mutex_destroy(&ihash_lock);
v1 = -1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebp
int v2; // eax
__int64 i; // rdx
__int64 v4; // r12
__int64 v5; // rbx
_QWORD *v6; // rax
void *v7; // rcx
_QWORD *v8; // rdx

if ( pthread_mutex_init(&ihash_lock, 0LL) )
{
fwrite("failed to initialize the inode layer lock\n", 1uLL, 0x2AuLL, stderr);
v1 = -1;
}
else
{
v1 = 0;
iprivsize = a1;
v2 = 17;
for ( i = 1LL; --v2; i *= 2LL )
;
v4 = i & 0x7FFFFFFFFFFFFFFFLL;
v5 = i;
v6 = malloc(8 * i);
v7 = v6;
if ( v6 )
{
v8 = &v6[v5];
do
*v6++ = 0LL;
while ( v8 != v6 );
ihash_mask = v4 - 1;
ihash_table = v7;
}
else if ( !ihash_table )
{
pthread_mutex_destroy(&ihash_lock);
v1 = -1;
}
}
return v1;
}

original_code:
int
unixfs_inodelayer_init(size_t privsize)
{
    if (!1)
        return 0;
    if (pthread_mutex_init(&ihash_lock, (const pthread_mutexattr_t*)0)) {
        fprintf(stderr, "failed to initialize the inode layer lock\n");
        return -1;
    }
    iprivsize = privsize;
    int i;
    u_long hashsize;
    struct generic { struct generic *lh_first; } *hashtbl;
    for (hashsize = 1; hashsize <= desirednodes; hashsize <<= 1)
            continue;
    hashsize >>= 1;
    hashtbl = (struct generic *)malloc(hashsize * sizeof(*hashtbl));
    if (hashtbl != ((void *)0)) {
        for (i = 0; i < hashsize; i++)
            do { (((&hashtbl[i]))->lh_first) = ((void *)0); } while (0);
         ihash_mask = hashsize - 1;
         ihash_table = (struct ihash_head *)hashtbl;
    }
    if (ihash_table == ((void *)0)) {
        (void)pthread_mutex_destroy(&ihash_lock);
        return -1;
    }
    return 0;
}

canonical_original_code:
int unixfs_inodelayer_init(unsigned long privsize)
{
    if (!1)
        return 0;
    if (pthread_mutex_init(&ihash_lock, (union pthread_mutexattr_t *)0)) {
        fprintf(stderr, "failed to initialize the inode layer lock\n");
        return -1;
    }
    iprivsize = privsize;
    int i;
    unsigned long hashsize;
    struct generic *hashtbl;
    for (hashsize = 1; hashsize <= desirednodes; hashsize <<= 1)
            continue;
    hashsize >>= 1;
    hashtbl = (struct generic *)malloc(hashsize * sizeof(*hashtbl));
    if (hashtbl != ((void *)0)) {
        for (i = 0; i < hashsize; i++)
            do { (((&hashtbl[i]))->lh_first) = ((void *)0); } while (0);
         ihash_mask = hashsize - 1;
         ihash_table = (struct ihash_head *)hashtbl;
    }
    if (ihash_table == ((void *)0)) {
        (void)pthread_mutex_destroy(&ihash_lock);
        return -1;
    }
    return 0;
}

variable_types:
privsize
unsigned long

variable_types: i int

variable_types:
hashsize
unsigned long

return_type: int

user_defined_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: enum fs_endian_t { UNIXFS_FS_PDP=0, UNIXFS_FS_LITTLE=1, UNIXFS_FS_BIG=2, UNIXFS_FS_INVALID=3 }

user_defined_types: struct statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; unsigned long f_favail; unsigned long f_fsid; unsigned long f_flag; unsigned long f_namemax; int __f_spare[6]; }


decompiled_code:
int unixfs_inodelayer_fini()
{
unsigned __int64 v0; // rbx
unsigned __int64 v1; // rbp
_QWORD *i; // rbx
const void *v3; // rcx

if ( ihash_table )
{
if ( ihash_count )
{
fprintf(stderr, "*** warning: ihash terminated when not empty (%lu)\n", ihash_count);
if ( !ihash_mask )
goto LABEL_4;
v1 = 0LL;
do
{
for ( i = (_QWORD *)*((_QWORD *)ihash_table + v1); i; i = (_QWORD *)*i )
fprintf(stderr, "*** warning: inode %llu still present\n", i[13]);
++v1;
}
while ( ihash_mask > v1 );
}
if ( ihash_mask == -1 )
{
LABEL_14:
free(ihash_table);
ihash_table = 0LL;
return pthread_mutex_destroy(&ihash_lock);
}
LABEL_4:
v0 = 0LL;
do
{
v3 = (const void *)*((_QWORD *)ihash_table + v0);
if ( v3 )
fprintf(stderr, "*** warning: found ihash_table[%lu].lh_first = %p\n", v0, v3);
++v0;
}
while ( ihash_mask + 1 > v0 );
goto LABEL_14;
}
return pthread_mutex_destroy(&ihash_lock);
}

canonical_decompiled_code:
int func2()
{
unsigned __int64 v0; // rbx
unsigned __int64 v1; // rbp
_QWORD *i; // rbx
const void *v3; // rcx

if ( ihash_table )
{
if ( ihash_count )
{
fprintf(stderr, "*** warning: ihash terminated when not empty (%lu)\n", ihash_count);
if ( !ihash_mask )
goto LABEL_4;
v1 = 0LL;
do
{
for ( i = (_QWORD *)*((_QWORD *)ihash_table + v1); i; i = (_QWORD *)*i )
fprintf(stderr, "*** warning: inode %llu still present\n", i[13]);
++v1;
}
while ( ihash_mask > v1 );
}
if ( ihash_mask == -1 )
{
LABEL_14:
free(ihash_table);
ihash_table = 0LL;
return pthread_mutex_destroy(&ihash_lock);
}
LABEL_4:
v0 = 0LL;
do
{
v3 = (const void *)*((_QWORD *)ihash_table + v0);
if ( v3 )
fprintf(stderr, "*** warning: found ihash_table[%lu].lh_first = %p\n", v0, v3);
++v0;
}
while ( ihash_mask + 1 > v0 );
goto LABEL_14;
}
return pthread_mutex_destroy(&ihash_lock);
}

original_code:
void
unixfs_inodelayer_fini(void)
{
    if (!1)
        return;
    if (ihash_table != ((void *)0)) {
        if (ihash_count != 0) {
            fprintf(stderr,
                    "*** warning: ihash terminated when not empty (%lu)\n",
                    (unsigned long)ihash_count);
            int node_index = 0;
            u_long ihash_index = 0;
            for (; ihash_index < ihash_mask; ihash_index++) {
                struct inode* ip;
                for ((ip) = (((&ihash_table[ihash_index]))->lh_first); (ip); (ip) = (((ip))->I_hashlink.le_next)) {
                    fprintf(stderr, "*** warning: inode %llu still present\n",
                            (ino_t)ip->I_stat.st_ino);
                    node_index++;
                }
            }
        }
        u_long i;
        for (i = 0; i < (ihash_mask + 1); i++) {
            if (ihash_table[i].lh_first != ((void *)0))
                fprintf(stderr,
                        "*** warning: found ihash_table[%lu].lh_first = %p\n",
                        i, ihash_table[i].lh_first);
        }
        free(ihash_table);
        ihash_table = ((void *)0);
    }
    (void)pthread_mutex_destroy(&ihash_lock);
}

canonical_original_code:
void unixfs_inodelayer_fini()
{
    if (!1)
        return;
    if (ihash_table != ((void *)0)) {
        if (ihash_count != 0) {
            fprintf(stderr,
                    "*** warning: ihash terminated when not empty (%lu)\n",
                    (unsigned long)ihash_count);
            int node_index = 0;
            unsigned long ihash_index = 0;
            for (; ihash_index < ihash_mask; ihash_index++) {
                struct inode *ip;
                for ((ip) = (((&ihash_table[ihash_index]))->lh_first); (ip); (ip) = (((ip))->I_hashlink.le_next)) {
                    fprintf(stderr, "*** warning: inode %llu still present\n",
                            (unsigned long)ip->I_stat.st_ino);
                    node_index++;
                }
            }
        }
        unsigned long i;
        for (i = 0; i < (ihash_mask + 1); i++) {
            if (ihash_table[i].lh_first != ((void *)0))
                fprintf(stderr,
                        "*** warning: found ihash_table[%lu].lh_first = %p\n",
                        i, ihash_table[i].lh_first);
        }
        free(ihash_table);
        ihash_table = ((void *)0);
    }
    (void)pthread_mutex_destroy(&ihash_lock);
}

variable_types: struct inode { struct { struct inode *le_next; struct inode **le_prev; } I_hashlink; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } I_state_cond; unsigned int I_initialized; unsigned int I_attachoutstanding; unsigned int I_waiting; unsigned int I_count; unsigned int I_blkbits; struct super_block { unsigned long s_magic; unsigned long s_flags; unsigned long s_blocksize; unsigned char s_blocksize_bits; unsigned char s_dirt; enum fs_endian_t { UNIXFS_FS_PDP=0, UNIXFS_FS_LITTLE=1, UNIXFS_FS_BIG=2, UNIXFS_FS_INVALID=3 } s_endian; void *s_fs_info; int s_bdev; int s_kdev; unsigned int s_dentsize; char s_fsname[90]; char s_volname[255]; struct statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; unsigned long f_favail; unsigned long f_fsid; unsigned long f_flag; unsigned long f_namemax; int __f_spare[6]; } s_statvfs; } *I_sb; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } I_stat; union { unsigned int I_daddr[13]; unsigned char I_addr[13]; } I_addr_un; void *I_private; } *

variable_types:
i
unsigned long


decompiled_code:
int __fastcall unixfs_inodelayer_isucceeded(__int64 a1)
{
pthread_mutex_lock(&ihash_lock);
*(_DWORD *)(a1 + 64) = 1;
*(_DWORD *)(a1 + 68) = 0;
if ( *(_DWORD *)(a1 + 72) )
{
*(_DWORD *)(a1 + 72) = 0;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 16));
}
return pthread_mutex_unlock(&ihash_lock);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
pthread_mutex_lock(&ihash_lock);
*(_DWORD *)(a1 + 64) = 1;
*(_DWORD *)(a1 + 68) = 0;
if ( *(_DWORD *)(a1 + 72) )
{
*(_DWORD *)(a1 + 72) = 0;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 16));
}
return pthread_mutex_unlock(&ihash_lock);
}

original_code:
void
unixfs_inodelayer_isucceeded(struct inode* ip)
{
    if (!1)
        return;
    pthread_mutex_lock(&ihash_lock);
    ip->I_initialized = 1;
    ip->I_attachoutstanding = 0;
    if (ip->I_waiting) {
        ip->I_waiting = 0;
        pthread_cond_broadcast(&ip->I_state_cond);
    }
    pthread_mutex_unlock(&ihash_lock);
}

canonical_original_code:
void unixfs_inodelayer_isucceeded(struct inode *ip)
{
    if (!1)
        return;
    pthread_mutex_lock(&ihash_lock);
    ip->I_initialized = 1;
    ip->I_attachoutstanding = 0;
    if (ip->I_waiting) {
        ip->I_waiting = 0;
        pthread_cond_broadcast(&ip->I_state_cond);
    }
    pthread_mutex_unlock(&ihash_lock);
}


decompiled_code:
void __fastcall unixfs_inodelayer_ifailed(void *ptr)
{
pthread_mutex_lock(&ihash_lock);
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
*((_DWORD *)ptr + 16) = 0;
*((_DWORD *)ptr + 17) = 0;
if ( *((_DWORD *)ptr + 18) )
{
*((_DWORD *)ptr + 18) = 0;
pthread_cond_broadcast((pthread_cond_t *)((char *)ptr + 16));
}
--ihash_count;
pthread_mutex_unlock(&ihash_lock);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 16));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
pthread_mutex_lock(&ihash_lock);
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
*((_DWORD *)ptr + 16) = 0;
*((_DWORD *)ptr + 17) = 0;
if ( *((_DWORD *)ptr + 18) )
{
*((_DWORD *)ptr + 18) = 0;
pthread_cond_broadcast((pthread_cond_t *)((char *)ptr + 16));
}
--ihash_count;
pthread_mutex_unlock(&ihash_lock);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 16));
free(ptr);
}

original_code:
void
unixfs_inodelayer_ifailed(struct inode* ip)
{
    if (!1)
        return;
    pthread_mutex_lock(&ihash_lock);
    do { ; ; if ((((ip))->I_hashlink.le_next) != ((void *)0)) (((ip))->I_hashlink.le_next)->I_hashlink.le_prev = (ip)->I_hashlink.le_prev; *(ip)->I_hashlink.le_prev = (((ip))->I_hashlink.le_next); ; ; } while (0);
    ip->I_initialized = 0;
    ip->I_attachoutstanding = 0;
    if (ip->I_waiting) {
        ip->I_waiting = 0;
        pthread_cond_broadcast(&ip->I_state_cond);
    }
    ihash_count--;
    pthread_mutex_unlock(&ihash_lock);
    (void)pthread_cond_destroy(&ip->I_state_cond);
    free(ip);
}

canonical_original_code:
void unixfs_inodelayer_ifailed(struct inode *ip)
{
    if (!1)
        return;
    pthread_mutex_lock(&ihash_lock);
    do { ; ; if ((((ip))->I_hashlink.le_next) != ((void *)0)) (((ip))->I_hashlink.le_next)->I_hashlink.le_prev = (ip)->I_hashlink.le_prev; *(ip)->I_hashlink.le_prev = (((ip))->I_hashlink.le_next); ; ; } while (0);
    ip->I_initialized = 0;
    ip->I_attachoutstanding = 0;
    if (ip->I_waiting) {
        ip->I_waiting = 0;
        pthread_cond_broadcast(&ip->I_state_cond);
    }
    ihash_count--;
    pthread_mutex_unlock(&ihash_lock);
    (void)pthread_cond_destroy(&ip->I_state_cond);
    free(ip);
}


decompiled_code:
void __fastcall unixfs_inodelayer_iput(void *ptr)
{
int v1; // eax

pthread_mutex_lock(&ihash_lock);
v1 = *((_DWORD *)ptr + 19) - 1;
*((_DWORD *)ptr + 19) = v1;
if ( v1 )
{
pthread_mutex_unlock(&ihash_lock);
}
else
{
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
--ihash_count;
pthread_mutex_unlock(&ihash_lock);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 16));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
int v1; // eax

pthread_mutex_lock(&ihash_lock);
v1 = *((_DWORD *)ptr + 19) - 1;
*((_DWORD *)ptr + 19) = v1;
if ( v1 )
{
pthread_mutex_unlock(&ihash_lock);
}
else
{
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
--ihash_count;
pthread_mutex_unlock(&ihash_lock);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 16));
free(ptr);
}
}

original_code:
void
unixfs_inodelayer_iput(struct inode* ip)
{
    if (!1) {
        free(ip);
        return;
    }
    pthread_mutex_lock(&ihash_lock);
    ip->I_count--;
    if (ip->I_count == 0) {
        do { ; ; if ((((ip))->I_hashlink.le_next) != ((void *)0)) (((ip))->I_hashlink.le_next)->I_hashlink.le_prev = (ip)->I_hashlink.le_prev; *(ip)->I_hashlink.le_prev = (((ip))->I_hashlink.le_next); ; ; } while (0);
        ihash_count--;
        pthread_mutex_unlock(&ihash_lock);
        (void)pthread_cond_destroy(&ip->I_state_cond);
        free(ip);
    } else
        pthread_mutex_unlock(&ihash_lock);
}

canonical_original_code:
void unixfs_inodelayer_iput(struct inode *ip)
{
    if (!1) {
        free(ip);
        return;
    }
    pthread_mutex_lock(&ihash_lock);
    ip->I_count--;
    if (ip->I_count == 0) {
        do { ; ; if ((((ip))->I_hashlink.le_next) != ((void *)0)) (((ip))->I_hashlink.le_next)->I_hashlink.le_prev = (ip)->I_hashlink.le_prev; *(ip)->I_hashlink.le_prev = (((ip))->I_hashlink.le_next); ; ; } while (0);
        ihash_count--;
        pthread_mutex_unlock(&ihash_lock);
        (void)pthread_cond_destroy(&ip->I_state_cond);
        free(ip);
    } else
        pthread_mutex_unlock(&ihash_lock);
}


decompiled_code:
int __fastcall unixfs_inodelayer_dump(unsigned int (__fastcall *a1)(_QWORD *, _QWORD))
{
__int64 v1; // r12
_QWORD *v2; // rbx

pthread_mutex_lock(&ihash_lock);
if ( ihash_mask )
{
v1 = 0LL;
while ( 1 )
{
v2 = (_QWORD *)*((_QWORD *)ihash_table + v1);
if ( v2 )
break;
LABEL_6:
if ( ihash_mask <= (unsigned __int64)++v1 )
return pthread_mutex_unlock(&ihash_lock);
}
while ( !a1(v2, v2[37]) )
{
v2 = (_QWORD *)*v2;
if ( !v2 )
goto LABEL_6;
}
}
return pthread_mutex_unlock(&ihash_lock);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int (__fastcall *a1)(_QWORD *, _QWORD))
{
__int64 v1; // r12
_QWORD *v2; // rbx

pthread_mutex_lock(&ihash_lock);
if ( ihash_mask )
{
v1 = 0LL;
while ( 1 )
{
v2 = (_QWORD *)*((_QWORD *)ihash_table + v1);
if ( v2 )
break;
LABEL_6:
if ( ihash_mask <= (unsigned __int64)++v1 )
return pthread_mutex_unlock(&ihash_lock);
}
while ( !a1(v2, v2[37]) )
{
v2 = (_QWORD *)*v2;
if ( !v2 )
goto LABEL_6;
}
}
return pthread_mutex_unlock(&ihash_lock);
}

original_code:
void
unixfs_inodelayer_dump(unixfs_inodelayer_iterator_t it)
{
    pthread_mutex_lock(&ihash_lock);
    int node_index = 0;
    u_long ihash_index = 0;
    for (; ihash_index < ihash_mask; ihash_index++) {
        struct inode* ip;
        for ((ip) = (((&ihash_table[ihash_index]))->lh_first); (ip); (ip) = (((ip))->I_hashlink.le_next)) {
            if (it(ip, ip->I_private) != 0)
                goto out;
            node_index++;
        }
    }
out:
    pthread_mutex_unlock(&ihash_lock);
}

canonical_original_code:
void unixfs_inodelayer_dump(int (*it)(struct inode *, void *))
{
    pthread_mutex_lock(&ihash_lock);
    int node_index = 0;
    unsigned long ihash_index = 0;
    for (; ihash_index < ihash_mask; ihash_index++) {
        struct inode *ip;
        for ((ip) = (((&ihash_table[ihash_index]))->lh_first); (ip); (ip) = (((ip))->I_hashlink.le_next)) {
            if (it(ip, ip->I_private) != 0)
                goto out;
            node_index++;
        }
    }
out:
    pthread_mutex_unlock(&ihash_lock);
}

variable_types: int (*)(struct inode { struct { struct inode *le_next; struct inode **le_prev; } I_hashlink; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } I_state_cond; unsigned int I_initialized; unsigned int I_attachoutstanding; unsigned int I_waiting; unsigned int I_count; unsigned int I_blkbits; struct super_block { unsigned long s_magic; unsigned long s_flags; unsigned long s_blocksize; unsigned char s_blocksize_bits; unsigned char s_dirt; enum fs_endian_t { UNIXFS_FS_PDP=0, UNIXFS_FS_LITTLE=1, UNIXFS_FS_BIG=2, UNIXFS_FS_INVALID=3 } s_endian; void *s_fs_info; int s_bdev; int s_kdev; unsigned int s_dentsize; char s_fsname[90]; char s_volname[255]; struct statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; unsigned long f_favail; unsigned long f_fsid; unsigned long f_flag; unsigned long f_namemax; int __f_spare[6]; } s_statvfs; } *I_sb; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } I_stat; union { unsigned int I_daddr[13]; unsigned char I_addr[13]; } I_addr_un; void *I_private; } *, void *)


decompiled_code:
size_t unixfs_usage()
{
const char *v0; // rdx
const char **v1; // rbx

fprintf(
stderr,
"AncientFS (%s): a MacFUSE file system to mount ancient Unix disks and tapes\n"
"Amit Singh <http://osxbook.com>\n"
"usage:\n"
" %s [--force] [--fsendian pdp|big|little] --dmg DMG --type TYPE MOUNTPOINT [MacFUSE args...]\n"
"where:\n"
" . DMG is an ancient Unix disk or tape image of a valid type\n"
" . TYPE is one of the following:\n"
"\n",
"1.0",
"ancientfs");
v0 = off_288[0];
if ( off_288[0] )
{
v1 = (const char **)&filesystems;
do
{
if ( !*(_DWORD *)v1 )
fprintf(stderr, " %-11s %s\n", v0, v1[4]);
v1 += 10;
v0 = v1[1];
}
while ( v0 );
}
fputc(10, stderr);
return fwrite(" . --force attempts mounting even if there are warnings or errors\n", 1uLL, 0x46uLL, stderr);
}

canonical_decompiled_code:
size_t func0()
{
const char *v0; // rdx
const char **v1; // rbx

fprintf(
stderr,
"AncientFS (%s): a MacFUSE file system to mount ancient Unix disks and tapes\n"
"Amit Singh <http://osxbook.com>\n"
"usage:\n"
" %s [--force] [--fsendian pdp|big|little] --dmg DMG --type TYPE MOUNTPOINT [MacFUSE args...]\n"
"where:\n"
" . DMG is an ancient Unix disk or tape image of a valid type\n"
" . TYPE is one of the following:\n"
"\n",
"1.0",
"ancientfs");
v0 = off_288[0];
if ( off_288[0] )
{
v1 = (const char **)&filesystems;
do
{
if ( !*(_DWORD *)v1 )
fprintf(stderr, " %-11s %s\n", v0, v1[4]);
v1 += 10;
v0 = v1[1];
}
while ( v0 );
}
fputc(10, stderr);
return fwrite(" . --force attempts mounting even if there are warnings or errors\n", 1uLL, 0x46uLL, stderr);
}

original_code:
void
unixfs_usage(void)
{
    fprintf(stderr,
"AncientFS (%s): a MacFUSE file system to mount ancient Unix disks and tapes\n"
"Amit Singh <http://osxbook.com>\n"
"usage:\n"
"      %s [--force] [--fsendian pdp|big|little] --dmg DMG --type TYPE MOUNTPOINT [MacFUSE args...]\n"
"where:\n"
"     . DMG is an ancient Unix disk or tape image of a valid type\n"
"     . TYPE is one of the following:\n\n",
PROGVERS, PROGNAME);
    int i;
    for (i = 0; filesystems[i].fstypename != ((void *)0); i++) {
        if (!filesystems[i].isalias)
            fprintf(stderr, "         %-11s %s\n", filesystems[i].fstypename,
                    filesystems[i].description);
    }
    fprintf(stderr, "\n");
    fprintf(stderr, "%s",
    "     . --force attempts mounting even if there are warnings or errors\n"
    );
}

canonical_original_code:
void unixfs_usage()
{
    fprintf(stderr,
"AncientFS (%s): a MacFUSE file system to mount ancient Unix disks and tapes\n"
"Amit Singh <http://osxbook.com>\n"
"usage:\n"
"      %s [--force] [--fsendian pdp|big|little] --dmg DMG --type TYPE MOUNTPOINT [MacFUSE args...]\n"
"where:\n"
"     . DMG is an ancient Unix disk or tape image of a valid type\n"
"     . TYPE is one of the following:\n\n",
PROGVERS, PROGNAME);
    int i;
    for (i = 0; filesystems[i].fstypename != ((void *)0); i++) {
        if (!filesystems[i].isalias)
            fprintf(stderr, "         %-11s %s\n", filesystems[i].fstypename,
                    filesystems[i].description);
    }
    fprintf(stderr, "\n");
    fprintf(stderr, "%s",
    "     . --force attempts mounting even if there are warnings or errors\n"
    );
}


decompiled_code:
void __fastcall unixfs_postflight(__int64 a1, __int64 a2, char *a3)
{
strcpy(a3, "-oro");
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2, char *a3)
{
strcpy(a3, "-oro");
}

original_code:
void
unixfs_postflight(char* fsname, char* volname, char* extra_args)
{
    snprintf(extra_args, 1024, "-oro");
}

canonical_original_code:
void unixfs_postflight(char *fsname, char *volname, char *extra_args)
{
    snprintf(extra_args, 1024, "-oro");
}

variable_types:
fsname
char *

variable_types:
volname
char *


decompiled_code:
__int64 unixfs_ll_destroy()
{
return (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)unixfs + 8LL))(*(_QWORD *)(unixfs + 8));
}

canonical_decompiled_code:
__int64 func0()
{
return (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)unixfs + 8LL))(*(_QWORD *)(unixfs + 8));
}

original_code:
static void
unixfs_ll_destroy(void* data)
{
    unixfs->ops->fini(unixfs->filsys);
}

canonical_original_code:
static void unixfs_ll_destroy(void *data)
{
    unixfs->ops->fini(unixfs->filsys);
}

variable_types:
data
void *


repo: tuxme/tuxbrio

decompiled_code:
__int64 pause_all()
{
sound_pause();
game_sel_pause();
game_list_pause();
snap_pause();
submenu_pause();
platform_pause();
menu_pause();
hint_pause();
font_pause();
bg_pause();
return event_pause();
}

canonical_decompiled_code:
__int64 func0()
{
sound_pause();
game_sel_pause();
game_list_pause();
snap_pause();
submenu_pause();
platform_pause();
menu_pause();
hint_pause();
font_pause();
bg_pause();
return event_pause();
}

original_code:
void pause_all( void ) {
 sound_pause();
 game_sel_pause();
 game_list_pause();
 snap_pause();
 submenu_pause();
 platform_pause();
 menu_pause();
 hint_pause();
 font_pause();
 bg_pause();
 event_pause();
}

canonical_original_code:
void pause_all() {
 sound_pause();
 game_sel_pause();
 game_list_pause();
 snap_pause();
 submenu_pause();
 platform_pause();
 menu_pause();
 hint_pause();
 font_pause();
 bg_pause();
 event_pause();
}


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

if ( (unsigned int)event_resume() )
return 0xFFFFFFFFLL;
bg_resume();
if ( (unsigned int)font_resume() )
return 4294967293LL;
if ( (unsigned int)hint_resume() )
return 4294967292LL;
if ( (unsigned int)menu_resume() )
return 4294967291LL;
if ( (unsigned int)platform_resume() )
return 4294967290LL;
if ( (unsigned int)submenu_resume() )
return 4294967289LL;
if ( (unsigned int)game_list_resume() )
return 4294967288LL;
sound_resume();
if ( (unsigned int)snap_resume() )
return 4294967287LL;
result = game_sel_resume();
if ( (_DWORD)result )
result = 4294967286LL;
return result;
}

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

if ( (unsigned int)event_resume() )
return 0xFFFFFFFFLL;
bg_resume();
if ( (unsigned int)font_resume() )
return 4294967293LL;
if ( (unsigned int)hint_resume() )
return 4294967292LL;
if ( (unsigned int)menu_resume() )
return 4294967291LL;
if ( (unsigned int)platform_resume() )
return 4294967290LL;
if ( (unsigned int)submenu_resume() )
return 4294967289LL;
if ( (unsigned int)game_list_resume() )
return 4294967288LL;
sound_resume();
if ( (unsigned int)snap_resume() )
return 4294967287LL;
result = game_sel_resume();
if ( (_DWORD)result )
result = 4294967286LL;
return result;
}

original_code:
int resume_all( void ) {
 if( event_resume() != 0 )
  return -1;
 bg_resume();
 if( font_resume() != 0 )
  return -3;
 if( hint_resume() != 0 )
  return -4;
 if( menu_resume() != 0 )
  return -5;
 if( platform_resume() != 0 )
  return -6;
 if( submenu_resume() != 0 )
  return -7;
 if( game_list_resume() != 0 )
  return -8;
 sound_resume();
 if( snap_resume() != 0 )
  return -9;
 if( game_sel_resume() != 0 )
  return -10;
 return 0;
}

canonical_original_code:
int resume_all() {
 if( event_resume() != 0 )
  return -1;
 bg_resume();
 if( font_resume() != 0 )
  return -3;
 if( hint_resume() != 0 )
  return -4;
 if( menu_resume() != 0 )
  return -5;
 if( platform_resume() != 0 )
  return -6;
 if( submenu_resume() != 0 )
  return -7;
 if( game_list_resume() != 0 )
  return -8;
 sound_resume();
 if( snap_resume() != 0 )
  return -9;
 if( game_sel_resume() != 0 )
  return -10;
 return 0;
}


decompiled_code:
__int64 __fastcall emulator_exec(_QWORD *a1)
{
__int64 v1; // rdx
__int64 *v2; // rax
int v3; // ebx
__int64 *i; // rax
char *v5; // rax
int v6; // ebp
char **v7; // rbp
char **v8; // rbx
__pid_t v9; // eax
__int64 result; // rax
int *v11; // rax
char *v12; // rax
char v13[256]; // [rsp+0h] [rbp-218h] BYREF
char *argv[35]; // [rsp+100h] [rbp-118h] BYREF

v1 = a1[9];
argv[0] = (char *)(v1 + 268);
if ( !v1 )
{
fwrite("Error: No suitable emulator found in configuration\n", 1uLL, 0x33uLL, stderr);
return 0xFFFFFFFFLL;
}
v2 = *(__int64 **)(v1 + 784);
if ( v2 )
{
v3 = 1;
do
{
if ( *((_BYTE *)v2 + 8) && v3 <= 29 )
argv[v3++] = (char *)(v2 + 1);
if ( *((_BYTE *)v2 + 72) && v3 <= 29 )
argv[v3++] = (char *)(v2 + 9);
v2 = (__int64 *)*v2;
}
while ( v2 );
}
else
{
v3 = 1;
}
for ( i = (__int64 *)a1[7]; i; i = (__int64 *)*i )
{
if ( *((_BYTE *)i + 8) && v3 <= 29 )
argv[v3++] = (char *)(i + 1);
if ( *((_BYTE *)i + 72) && v3 <= 29 )
argv[v3++] = (char *)(i + 9);
}
v5 = (char *)a1[11];
if ( !v5 || !*v5 )
{
fwrite("Error: No ROM image specified for game\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}
v6 = v3 + 1;
argv[v3] = v5;
if ( *(_BYTE *)(v1 + 524) )
{
getcwd(v13, 0xFFuLL);
chdir((const char *)(a1[9] + 524LL));
}
argv[v6] = 0LL;
printf("Executing: %s", (const char *)(a1[9] + 268LL));
if ( v6 > 0 )
{
v7 = argv;
v8 = &argv[(unsigned int)v3 + 1];
do
printf(" %s", *v7++);
while ( v7 != v8 );
}
putchar(10);
v9 = fork();
if ( v9 )
{
if ( v9 < 0 )
{
fwrite("Error: failed to fork\n", 1uLL, 0x16uLL, stderr);
return 0xFFFFFFFFLL;
}
}
else if ( execvp((const char *)(a1[9] + 268LL), argv) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "Error: Couldn't execute emulator '%s': %s\n", (const char *)(a1[9] + 268LL), v12);
exit(1);
}
wait(0LL);
result = 0LL;
if ( *(_BYTE *)(a1[9] + 524LL) )
{
chdir(v13);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rdx
__int64 *v2; // rax
int v3; // ebx
__int64 *i; // rax
char *v5; // rax
int v6; // ebp
char **v7; // rbp
char **v8; // rbx
__pid_t v9; // eax
__int64 result; // rax
int *v11; // rax
char *v12; // rax
char v13[256]; // [rsp+0h] [rbp-218h] BYREF
char *argv[35]; // [rsp+100h] [rbp-118h] BYREF

v1 = a1[9];
argv[0] = (char *)(v1 + 268);
if ( !v1 )
{
fwrite("Error: No suitable emulator found in configuration\n", 1uLL, 0x33uLL, stderr);
return 0xFFFFFFFFLL;
}
v2 = *(__int64 **)(v1 + 784);
if ( v2 )
{
v3 = 1;
do
{
if ( *((_BYTE *)v2 + 8) && v3 <= 29 )
argv[v3++] = (char *)(v2 + 1);
if ( *((_BYTE *)v2 + 72) && v3 <= 29 )
argv[v3++] = (char *)(v2 + 9);
v2 = (__int64 *)*v2;
}
while ( v2 );
}
else
{
v3 = 1;
}
for ( i = (__int64 *)a1[7]; i; i = (__int64 *)*i )
{
if ( *((_BYTE *)i + 8) && v3 <= 29 )
argv[v3++] = (char *)(i + 1);
if ( *((_BYTE *)i + 72) && v3 <= 29 )
argv[v3++] = (char *)(i + 9);
}
v5 = (char *)a1[11];
if ( !v5 || !*v5 )
{
fwrite("Error: No ROM image specified for game\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}
v6 = v3 + 1;
argv[v3] = v5;
if ( *(_BYTE *)(v1 + 524) )
{
getcwd(v13, 0xFFuLL);
chdir((const char *)(a1[9] + 524LL));
}
argv[v6] = 0LL;
printf("Executing: %s", (const char *)(a1[9] + 268LL));
if ( v6 > 0 )
{
v7 = argv;
v8 = &argv[(unsigned int)v3 + 1];
do
printf(" %s", *v7++);
while ( v7 != v8 );
}
putchar(10);
v9 = fork();
if ( v9 )
{
if ( v9 < 0 )
{
fwrite("Error: failed to fork\n", 1uLL, 0x16uLL, stderr);
return 0xFFFFFFFFLL;
}
}
else if ( execvp((const char *)(a1[9] + 268LL), argv) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "Error: Couldn't execute emulator '%s': %s\n", (const char *)(a1[9] + 268LL), v12);
exit(1);
}
wait(0LL);
result = 0LL;
if ( *(_BYTE *)(a1[9] + 524LL) )
{
chdir(v13);
result = 0LL;
}
return result;
}

original_code:
int emulator_exec( struct game *game ) {
 char *params[32];
 struct config_param *param = ((void *)0);
 int i = 0;
 int count = 0;
 char current_dir[256];
 params[count++] = game->emulator->executable;
 if( game->emulator && game->emulator->executable ) {
  param = game->emulator->params;
  while( param ) {
   if( param->name && *param->name && count < 32 - 2 )
    params[count++] = param->name;
   if( param->value && *param->value && count < 32 - 2 )
    params[count++] = param->value;
   param = param->next;
  }
  param = game->params;
  while( param ) {
   if( param->name && *param->name && count < 32 - 2 )
    params[count++] = param->name;
   if( param->value && *param->value && count < 32 - 2 )
    params[count++] = param->value;
   param = param->next;
  }
 }
 else {
  fprintf(stderr, "Error: No suitable emulator found in configuration\n");
  return -1;
 }
 if( game && game->rom_path && game->rom_path[0] ) {
  params[count++] = game->rom_path;
 }
 else {
  fprintf(stderr, "Error: No ROM image specified for game\n");
  return -1;
 }
 if( game->emulator->directory[0] ) {
  getcwd( current_dir, 256 -1 );
  chdir( game->emulator->directory );
 }
 params[count] = ((void *)0);
 printf( "Executing: %s", game->emulator->executable );
 for( i = 0 ; i < count ; i++ ) {
  printf( " %s", params[i] );
 }
 printf( "\n" );
 pid_t pid = fork();
 if (pid == 0) {
  if( execvp( game->emulator->executable, params ) != 0 ) {
   fprintf( stderr, "Error: Couldn't execute emulator '%s': %s\n", game->emulator->executable, strerror((*__errno_location ())) );
   exit( 1 );
  }
 }
 else if (pid < 0) {
  fprintf(stderr, "Error: failed to fork\n");
  return -1;
 }
 wait( ((void *)0) );
 if( game->emulator->directory[0] )
  chdir( current_dir );
 return 0;
}

canonical_original_code:
int emulator_exec(struct game *game) {
 char *params[32];
 struct config_param *param = ((void *)0);
 int i = 0;
 int count = 0;
 char current_dir[256];
 params[count++] = game->emulator->executable;
 if( game->emulator && game->emulator->executable ) {
  param = game->emulator->params;
  while( param ) {
   if( param->name && *param->name && count < 32 - 2 )
    params[count++] = param->name;
   if( param->value && *param->value && count < 32 - 2 )
    params[count++] = param->value;
   param = param->next;
  }
  param = game->params;
  while( param ) {
   if( param->name && *param->name && count < 32 - 2 )
    params[count++] = param->name;
   if( param->value && *param->value && count < 32 - 2 )
    params[count++] = param->value;
   param = param->next;
  }
 }
 else {
  fprintf(stderr, "Error: No suitable emulator found in configuration\n");
  return -1;
 }
 if( game && game->rom_path && game->rom_path[0] ) {
  params[count++] = game->rom_path;
 }
 else {
  fprintf(stderr, "Error: No ROM image specified for game\n");
  return -1;
 }
 if( game->emulator->directory[0] ) {
  getcwd( current_dir, 256 -1 );
  chdir( game->emulator->directory );
 }
 params[count] = ((void *)0);
 printf( "Executing: %s", game->emulator->executable );
 for( i = 0 ; i < count ; i++ ) {
  printf( " %s", params[i] );
 }
 printf( "\n" );
 int pid = fork();
 if (pid == 0) {
  if( execvp( game->emulator->executable, params ) != 0 ) {
   fprintf( stderr, "Error: Couldn't execute emulator '%s': %s\n", game->emulator->executable, strerror((*__errno_location ())) );
   exit( 1 );
  }
 }
 else if (pid < 0) {
  fprintf(stderr, "Error: failed to fork\n");
  return -1;
 }
 wait( ((void *)0) );
 if( game->emulator->directory[0] )
  chdir( current_dir );
 return 0;
}

variable_types: struct game { struct game *next; struct game *prev; struct game *all_next; struct game *all_prev; struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture { unsigned int id; int width; int height; } *texture; } *platform; struct game_category { struct game_category *next; char *name; char *value; } *categories; struct texture *texture; struct config_param { struct config_param *next; char name[64]; char value[64]; } *params; struct game_media { struct game_media *next; int type; char *subtype; char file_name[256]; } *media; struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param *params; struct config_platform { struct config_platform *next; char name[128]; } *platform; } *emulator; char *name; char *rom_path; } *

variable_types:
params
char *[32]

variable_types: count int

variable_types: pid int

user_defined_types: struct game { struct game *next; struct game *prev; struct game *all_next; struct game *all_prev; struct platform *platform; struct game_category *categories; struct texture *texture; struct config_param *params; struct game_media *media; struct config_emulator *emulator; char *name; char *rom_path; }

user_defined_types: struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture *texture; }

user_defined_types: struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param *params; struct config_platform *platform; }


decompiled_code:
__int64 __fastcall emulator_run(_QWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx

pause_all();
sdl_free();
emulator_exec(a1);
if ( (unsigned int)sdl_init() )
return (unsigned int)-1;
if ( (unsigned int)ogl_init() )
return (unsigned int)-1;
v1 = resume_all();
v2 = v1;
if ( v1 )
fprintf(stderr, "Warning: resume_all() failed: %d\n", v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx

func0();
sdl_free();
func2(a1);
if ( (unsigned int)sdl_init() )
return (unsigned int)-1;
if ( (unsigned int)ogl_init() )
return (unsigned int)-1;
v1 = func1();
v2 = v1;
if ( v1 )
fprintf(stderr, "Warning: resume_all() failed: %d\n", v1);
return v2;
}

original_code:
int emulator_run( struct game *game ) {
 int ret = 0;
 pause_all();
 sdl_free();
 emulator_exec( game );
 if( sdl_init() != 0 )
  return -1;
 if( ogl_init() != 0 )
  return -1;
 ret = resume_all();
 if( ret != 0 )
  fprintf( stderr, "Warning: resume_all() failed: %d\n", ret );
 return ret;
}

canonical_original_code:
int emulator_run(struct game *game) {
 int ret = 0;
 pause_all();
 sdl_free();
 emulator_exec( game );
 if( sdl_init() != 0 )
  return -1;
 if( ogl_init() != 0 )
  return -1;
 ret = resume_all();
 if( ret != 0 )
  fprintf( stderr, "Warning: resume_all() failed: %d\n", ret );
 return ret;
}

variable_types: ret int

user_defined_types: struct game_category { struct game_category *next; char *name; char *value; }

user_defined_types: struct config_param { struct config_param *next; char name[64]; char value[64]; }

user_defined_types: struct game_media { struct game_media *next; int type; char *subtype; char file_name[256]; }

user_defined_types: struct texture { unsigned int id; int width; int height; }

user_defined_types: struct config_platform { struct config_platform *next; char name[128]; }


decompiled_code:
const char *__fastcall emulator_get_by_name(char *s2)
{
const char *v1; // rbx

v1 = *(const char **)config_get();
if ( s2 && *s2 && v1 )
{
do
{
if ( !strcasecmp(v1 + 12, s2) )
break;
v1 = *(const char **)v1;
}
while ( v1 );
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func4(char *s2)
{
const char *v1; // rbx

v1 = *(const char **)config_get();
if ( s2 && *s2 && v1 )
{
do
{
if ( !strcasecmp(v1 + 12, s2) )
break;
v1 = *(const char **)v1;
}
while ( v1 );
}
return v1;
}

original_code:
struct config_emulator *emulator_get_by_name( const char *name ) {
 struct config_emulator *e = config_get()->emulators;
 if( name && name[0] ) {
  while( e ) {
   if( strcasecmp( e->name, name ) == 0 )
    break;
   e = e->next;
  }
 }
 return e;
}

canonical_original_code:
struct config_emulator *emulator_get_by_name(char *name) {
 struct config_emulator *e = config_get()->emulators;
 if( name && name[0] ) {
  while( e ) {
   if( strcasecmp( e->name, name ) == 0 )
    break;
   e = e->next;
  }
 }
 return e;
}

variable_types:
name
char *

variable_types: struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param { struct config_param *next; char name[64]; char value[64]; } *params; struct config_platform { struct config_platform *next; char name[128]; } *platform; } *


decompiled_code:
__int64 *emulator_get_default()
{
__int64 *result; // rax

result = *(__int64 **)config_get();
if ( !result )
return *(__int64 **)config_get();
while ( !*((_DWORD *)result + 195) )
{
result = (__int64 *)*result;
if ( !result )
return *(__int64 **)config_get();
}
return result;
}

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

result = *(__int64 **)config_get();
if ( !result )
return *(__int64 **)config_get();
while ( !*((_DWORD *)result + 195) )
{
result = (__int64 *)*result;
if ( !result )
return *(__int64 **)config_get();
}
return result;
}

original_code:
struct config_emulator *emulator_get_default( void ) {
 struct config_emulator *e = config_get()->emulators;
 while( e ) {
  if( e->is_default )
   break;
  e = e->next;
 }
 if( !e )
  e = config_get()->emulators;
 return e;
}

canonical_original_code:
struct config_emulator *emulator_get_default() {
 struct config_emulator *e = config_get()->emulators;
 while( e ) {
  if( e->is_default )
   break;
  e = e->next;
 }
 if( !e )
  e = config_get()->emulators;
 return e;
}

return_type: struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param { struct config_param *next; char name[64]; char value[64]; } *params; struct config_platform { struct config_platform *next; char name[128]; } *platform; } *


decompiled_code:
__int64 menu_selected()
{
return *(_QWORD *)(selected + 16);
}

canonical_decompiled_code:
__int64 func0()
{
return *(_QWORD *)(selected + 16);
}

original_code:
struct menu_item *menu_selected( void ) {
 return selected->item;
}

canonical_original_code:
struct menu_item *menu_selected() {
 return selected->item;
}

return_type: struct menu_item { int type; struct menu_item *next; struct menu_item *prev; struct texture { unsigned int id; int width; int height; } *message; struct category { struct category *next; struct category *prev; struct category_value { struct category_value *next; struct category_value *prev; char *name; } *values; int id; char *name; int value_count; int has_unknowns; } *category; char *text; } *

user_defined_types: struct menu_item { int type; struct menu_item *next; struct menu_item *prev; struct texture *message; struct category *category; char *text; }

user_defined_types: struct category { struct category *next; struct category *prev; struct category_value *values; int id; char *name; int value_count; int has_unknowns; }


decompiled_code:
__int64 menu_tile_selected()
{
return selected;
}

canonical_decompiled_code:
__int64 func1()
{
return selected;
}

original_code:
struct menu_tile *menu_tile_selected( void ) {
 return selected;
}

canonical_original_code:
struct menu_tile *menu_tile_selected() {
 return selected;
}

return_type: struct menu_tile { struct menu_tile *next; struct menu_tile *prev; struct menu_item { int type; struct menu_item *next; struct menu_item *prev; struct texture { unsigned int id; int width; int height; } *message; struct category { struct category *next; struct category *prev; struct category_value { struct category_value *next; struct category_value *prev; char *name; } *values; int id; char *name; int value_count; int has_unknowns; } *category; char *text; } *item; float x; float y; float zoom; float alpha; } *

user_defined_types: struct menu_tile { struct menu_tile *next; struct menu_tile *prev; struct menu_item *item; float x; float y; float zoom; float alpha; }


decompiled_code:
__int64 menu_item_count()
{
return (unsigned int)menu_items;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)menu_items;
}

original_code:
int menu_item_count( void ) {
 return menu_items;
}

canonical_original_code:
int menu_item_count() {
 return menu_items;
}


decompiled_code:
__int64 menu_load_texture()
{
__int64 v0; // rax
_BYTE v2[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = config_get();
location_get_theme_path(v0 + 2504, v2);
menu_texture = sdl_create_texture(v2);
if ( menu_texture )
return 0LL;
fwrite("Warning: Couldn't create texture for menu items\n", 1uLL, 0x30uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
_BYTE v2[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = config_get();
location_get_theme_path(v0 + 2504, v2);
menu_texture = sdl_create_texture(v2);
if ( menu_texture )
return 0LL;
fwrite("Warning: Couldn't create texture for menu items\n", 1uLL, 0x30uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int menu_load_texture( void ) {
 char filename[256];
 location_get_theme_path( config_get()->iface.theme.menu.texture, filename );
 menu_texture = sdl_create_texture( filename );
 if( menu_texture == 0 ) {
  fprintf( stderr, "Warning: Couldn't create texture for menu items\n" );
  return -1;
 }
 return 0;
}

canonical_original_code:
int menu_load_texture() {
 char filename[256];
 location_get_theme_path( config_get()->iface.theme.menu.texture, filename );
 menu_texture = sdl_create_texture( filename );
 if( menu_texture == 0 ) {
  fprintf( stderr, "Warning: Couldn't create texture for menu items\n" );
  return -1;
 }
 return 0;
}

variable_types:
filename
char [256]


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

if ( menu_texture )
result = ogl_free_texture();
return result;
}

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

if ( menu_texture )
result = ogl_free_texture();
return result;
}

original_code:
void menu_free_texture( void ) {
 if( menu_texture ) {
  ogl_free_texture( menu_texture );
 }
}

canonical_original_code:
void menu_free_texture() {
 if( menu_texture ) {
  ogl_free_texture( menu_texture );
 }
}


decompiled_code:
__int64 menu_pause()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = menu_start;
step = 0;
result = menu_free_texture();
if ( v0 )
{
do
{
result = ogl_free_texture(*(_QWORD *)(v0 + 24));
v0 = *(_QWORD *)(v0 + 8);
}
while ( menu_start != v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = menu_start;
step = 0;
result = func4();
if ( v0 )
{
do
{
result = ogl_free_texture(*(_QWORD *)(v0 + 24));
v0 = *(_QWORD *)(v0 + 8);
}
while ( menu_start != v0 );
}
return result;
}

original_code:
void menu_pause( void ) {
 struct menu_item *item = menu_start;
 step = 0;
 menu_free_texture();
 if( item ) {
  do {
   ogl_free_texture( item->message );
   item = item->next;
  } while( item != menu_start );
 }
}

canonical_original_code:
void menu_pause() {
 struct menu_item *item = menu_start;
 step = 0;
 menu_free_texture();
 if( item ) {
  do {
   ogl_free_texture( item->message );
   item = item->next;
  } while( item != menu_start );
 }
}

variable_types: struct menu_item { int type; struct menu_item *next; struct menu_item *prev; struct texture { unsigned int id; int width; int height; } *message; struct category { struct category *next; struct category *prev; struct category_value { struct category_value *next; struct category_value *prev; char *name; } *values; int id; char *name; int value_count; int has_unknowns; } *category; char *text; } *


decompiled_code:
__int64 menu_resume()
{
_QWORD *v0; // rbx
unsigned int v1; // ebp
__int64 v2; // rax

v0 = (_QWORD *)menu_start;
if ( (unsigned int)menu_load_texture() )
return (unsigned int)-1;
v1 = 0;
if ( v0 )
{
while ( 1 )
{
v2 = font_create_texture(v0[5]);
v0[3] = v2;
if ( !v2 )
break;
v0 = (_QWORD *)v0[1];
if ( (_QWORD *)menu_start == v0 )
return v1;
}
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
_QWORD *v0; // rbx
unsigned int v1; // ebp
__int64 v2; // rax

v0 = (_QWORD *)menu_start;
if ( (unsigned int)func3() )
return (unsigned int)-1;
v1 = 0;
if ( v0 )
{
while ( 1 )
{
v2 = font_create_texture(v0[5]);
v0[3] = v2;
if ( !v2 )
break;
v0 = (_QWORD *)v0[1];
if ( (_QWORD *)menu_start == v0 )
return v1;
}
v1 = -1;
}
return v1;
}

original_code:
int menu_resume( void ) {
 struct menu_item *item = menu_start;
 int i = 0;
 if( menu_load_texture() != 0 )
  return -1;
 if( item ) {
  do {
   item->message = font_create_texture( item->text );
   if( item->message == ((void *)0) )
    return -1;
   item = item->next;
   i++;
  } while( item != menu_start );
 }
 return 0;
}

canonical_original_code:
int menu_resume() {
 struct menu_item *item = menu_start;
 int i = 0;
 if( menu_load_texture() != 0 )
  return -1;
 if( item ) {
  do {
   item->message = font_create_texture( item->text );
   if( item->message == ((void *)0) )
    return -1;
   item = item->next;
   i++;
  } while( item != menu_start );
 }
 return 0;
}

variable_types: i int

user_defined_types: struct category_value { struct category_value *next; struct category_value *prev; char *name; }


decompiled_code:
__int64 __fastcall menu_item_add(const char *a1, int a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 result; // rax

v4 = malloc(0x30uLL);
if ( v4 )
{
v5 = (__int64)v4;
v4[5] = a1;
v6 = font_create_texture(a1);
*(_QWORD *)(v5 + 24) = v6;
if ( v6 )
{
*(_DWORD *)v5 = a2;
*(_QWORD *)(v5 + 32) = a3;
v7 = menu_start;
if ( menu_start )
{
*(_QWORD *)(*(_QWORD *)(menu_start + 8) + 16LL) = v5;
*(_QWORD *)(v5 + 8) = *(_QWORD *)(v7 + 8);
*(_QWORD *)(v7 + 8) = v5;
*(_QWORD *)(v5 + 16) = v7;
}
else
{
*(_QWORD *)(v5 + 8) = v5;
*(_QWORD *)(v5 + 16) = v5;
menu_start = v5;
}
++menu_items;
result = 0LL;
}
else
{
fprintf(stderr, "Error: Couldn't create message for menu item '%s'\n", a1);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Warning: Couldn't allocate memory for menu item '%s'\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 result; // rax

v4 = malloc(0x30uLL);
if ( v4 )
{
v5 = (__int64)v4;
v4[5] = a1;
v6 = font_create_texture(a1);
*(_QWORD *)(v5 + 24) = v6;
if ( v6 )
{
*(_DWORD *)v5 = a2;
*(_QWORD *)(v5 + 32) = a3;
v7 = menu_start;
if ( menu_start )
{
*(_QWORD *)(*(_QWORD *)(menu_start + 8) + 16LL) = v5;
*(_QWORD *)(v5 + 8) = *(_QWORD *)(v7 + 8);
*(_QWORD *)(v7 + 8) = v5;
*(_QWORD *)(v5 + 16) = v7;
}
else
{
*(_QWORD *)(v5 + 8) = v5;
*(_QWORD *)(v5 + 16) = v5;
menu_start = v5;
}
++menu_items;
result = 0LL;
}
else
{
fprintf(stderr, "Error: Couldn't create message for menu item '%s'\n", a1);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Warning: Couldn't allocate memory for menu item '%s'\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int menu_item_add( const char *text, int type, struct category *category ) {
 struct menu_item *item = malloc( sizeof(struct menu_item) );
 if( item ) {
  item->text = (char*)text;
  item->message = font_create_texture( text );
  if( item->message == ((void *)0) ) {
   fprintf( stderr, "Error: Couldn't create message for menu item '%s'\n", text );
   return -1;
  }
  item->type = type;
  item->category = category;
  if( menu_start == ((void *)0) ) {
   item->next = item;
   item->prev = item;
   menu_start = item;
  }
  else {
   menu_start->next->prev = item;
   item->next = menu_start->next;
   menu_start->next = item;
   item->prev = menu_start;
  }
  menu_items++;
 }
 else {
  fprintf( stderr, "Warning: Couldn't allocate memory for menu item '%s'\n", text );
  return -1;
 }
 return 0;
}

canonical_original_code:
int menu_item_add(char *text, int type, struct category *category) {
 struct menu_item *item = malloc( sizeof(struct menu_item) );
 if( item ) {
  item->text = (char *)text;
  item->message = font_create_texture( text );
  if( item->message == ((void *)0) ) {
   fprintf( stderr, "Error: Couldn't create message for menu item '%s'\n", text );
   return -1;
  }
  item->type = type;
  item->category = category;
  if( menu_start == ((void *)0) ) {
   item->next = item;
   item->prev = item;
   menu_start = item;
  }
  else {
   menu_start->next->prev = item;
   item->next = menu_start->next;
   menu_start->next = item;
   item->prev = menu_start;
  }
  menu_items++;
 }
 else {
  fprintf( stderr, "Warning: Couldn't allocate memory for menu item '%s'\n", text );
  return -1;
 }
 return 0;
}

variable_types:
text
char *

variable_types: type int

variable_types: struct category { struct category *next; struct category *prev; struct category_value { struct category_value *next; struct category_value *prev; char *name; } *values; int id; char *name; int value_count; int has_unknowns; } *


decompiled_code:
__int64 menu_init()
{
__int64 v0; // rbx
__int64 v1; // rbp
int v2; // eax
unsigned int v3; // er12
int v4; // er15
__int64 v5; // r14
int i; // er13
__int64 *v7; // rax
float *v8; // rax
__int64 v9; // rbx
__m128i v10; // xmm0
__m128i v11; // xmm4
float v12; // er15
_DWORD *v13; // rsi
int v14; // eax
int v15; // ecx
_QWORD *v16; // rdx
int v17; // eax
__int64 v18; // rcx
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rdx
float v22; // xmm2_4
float v23; // xmm1_4
float v24; // xmm0_4
__int64 result; // rax
float v26; // xmm0_4
_QWORD *v27; // rax
float v28; // [rsp+Ch] [rbp-3Ch]

v0 = category_first();
v1 = config_get();
v2 = *(_DWORD *)(v1 + 88);
if ( !v2 )
v2 = 100;
steps = v2;
zoom = *(_DWORD *)(v1 + 2772);
if ( *(float *)&zoom < 1.0 )
{
fwrite("Warning: Menu zoom parameter less than 1 - setting to 1\n", 1uLL, 0x38uLL, stderr);
zoom = 1065353216;
}
spacing = *(_DWORD *)(v1 + 2792);
if ( *(float *)&spacing < 0.0 )
{
if ( *(_DWORD *)(v1 + 2796) )
*(float *)&spacing = (float)((float)(0.80000001 * *(float *)(v1 + 2764)) * *(float *)&zoom) * 1.1;
else
*(float *)&spacing = (float)((float)(0.80000001 * *(float *)(v1 + 2760)) * *(float *)&zoom) * 1.1;
}
*(float *)&min_alpha = 1.0 - (float)((float)*(int *)(v1 + 2776) / 100.0);
v3 = menu_load_texture();
if ( v3 )
return 0xFFFFFFFFLL;
menu_item_add((const char *)(v1 + 108), 0, 0LL);
if ( (int)platform_count() > 1 || !*(_DWORD *)(v1 + 104) )
menu_item_add((const char *)(v1 + 140), 1, 0LL);
if ( v0 )
{
do
{
if ( *(int *)(v0 + 40) > 1 || !*(_DWORD *)(v1 + 104) )
menu_item_add(*(const char **)(v0 + 32), 2, v0);
v0 = *(_QWORD *)v0;
}
while ( v0 != category_first() );
}
v4 = menu_items;
if ( menu_items > *(_DWORD *)(v1 + 2788) )
v4 = *(_DWORD *)(v1 + 2788);
items_visible = v4;
if ( v4 )
{
if ( menu_start )
{
v5 = *(_QWORD *)(menu_start + 8);
if ( v4 >= -1 )
{
for ( i = v3; ; ++i )
{
v8 = (float *)malloc(0x28uLL);
v9 = (__int64)v8;
if ( v8 )
{
v10 = 0LL;
*(float *)v10.m128i_i32 = (float)i - (float)((float)((float)v4 + 1.0) * 0.5);
v11 = v10;
*(float *)v11.m128i_i32 = *(float *)v10.m128i_i32 * *(float *)&spacing;
v12 = COERCE_FLOAT(_mm_cvtsi128_si32(v11));
if ( *(_DWORD *)(v1 + 2796) )
{
LODWORD(v28) = *(_DWORD *)(v1 + 2784) ^ LC10;
v8[6] = ogl_aspect_ratio() * v28;
*(_DWORD *)(v9 + 28) = COERCE_UNSIGNED_INT(v12 + *(float *)(v1 + 2780)) ^ LC10;
}
else
{
v8[6] = *(float *)v11.m128i_i32 + *(float *)(v1 + 2780);
v8[7] = *(float *)(v1 + 2784);
}
*(_DWORD *)(v9 + 32) = 1065353216;
*(_DWORD *)(v9 + 36) = min_alpha;
*(_QWORD *)(v9 + 16) = v5;
v5 = *(_QWORD *)(v5 + 8);
*(_QWORD *)v9 = 0LL;
v7 = (__int64 *)tile_end;
*(_QWORD *)(v9 + 8) = tile_end;
if ( v7 )
*v7 = v9;
else
tile_start = v9;
tile_end = v9;
}
else
{
fprintf(stderr, "Warning: Couldn't allocate memeory for menu tile %d\n", (unsigned int)i);
}
v4 = items_visible;
if ( items_visible < i )
break;
}
}
}
}
v13 = (_DWORD *)tile_start;
selected = tile_start;
v14 = *(_DWORD *)(v1 + 2788);
v15 = (v14 + 1) / 2;
if ( v14 > 0 )
{
v16 = (_QWORD *)tile_start;
v17 = v3;
do
{
v16 = (_QWORD *)*v16;
++v17;
}
while ( v17 < v15 );
selected = (__int64)v16;
}
if ( !selected )
selected = tile_start;
v18 = selected;
*(_DWORD *)(selected + 32) = zoom;
*(_DWORD *)(v18 + 36) = 1065353216;
while ( **(_DWORD **)(v18 + 16) )
{
v27 = v13;
if ( v13 )
{
do
{
v27[2] = *(_QWORD *)(v27[2] + 8LL);
v27 = (_QWORD *)*v27;
}
while ( v27 );
}
}
v13[8] = 0;
v13[9] = 0;
v19 = *(_QWORD *)v13;
v13[6] = *(_DWORD *)(*(_QWORD *)v13 + 24LL);
v13[7] = *(_DWORD *)(v19 + 28);
v20 = tile_end;
*(_DWORD *)(tile_end + 32) = 0;
*(_DWORD *)(v20 + 36) = 0;
v21 = *(_QWORD *)(v20 + 8);
v22 = *(float *)(v21 + 24);
*(float *)(v20 + 24) = v22;
v23 = *(float *)(v21 + 28);
*(float *)(v20 + 28) = v23;
v24 = 0.80000001 * *(float *)(v1 + 2764);
*(float *)&dword_E28 = v24 * 1.5;
*(float *)&dword_E38 = v24 * 1.5;
result = *(unsigned int *)(v1 + 2796);
if ( (_DWORD)result )
{
arrow_retreat = v13[6];
*(float *)&dword_E24 = v24 + *((float *)v13 + 7);
arrow_advance = LODWORD(v22);
*(float *)&dword_E34 = v23 - v24;
dword_E2C = 0;
dword_E3C = 1127481344;
result = v3;
}
else
{
v26 = 0.80000001 * *(float *)(v1 + 2760);
*(float *)&arrow_retreat = *((float *)v13 + 6) - v26;
dword_E24 = v13[7];
*(float *)&arrow_advance = v22 + v26;
dword_E34 = LODWORD(v23);
dword_E2C = 1119092736;
dword_E3C = -1028390912;
}
return result;
}

original_code:
int menu_init( void ) {
 struct category *category = category_first();
 const struct config *config = config_get();
 int i;
 if( config->iface.frame_rate )
  steps = config->iface.frame_rate;
 else
  steps = MAX_STEPS;
 zoom = (GLfloat)config->iface.theme.menu.zoom;
 if( zoom < 1 ) {
  fprintf( stderr, "Warning: Menu zoom parameter less than 1 - setting to 1\n" );
  zoom = 1;
 }
 spacing = (GLfloat)config->iface.theme.menu.spacing;
 if( spacing < 0 ) {
  if( config->iface.theme.menu.orientation == CONFIG_LANDSCAPE )
   spacing = (GLfloat)config->iface.theme.menu.item_width * ITEM_SCALE * zoom * SPACING_FACTOR;
  else
   spacing = (GLfloat)config->iface.theme.menu.item_height * ITEM_SCALE * zoom * SPACING_FACTOR;
 }
 min_alpha = 1.0 - (GLfloat)(config->iface.theme.menu.transparency)/100;
 if( menu_load_texture() != 0 ) {
  return -1;
 }
 menu_item_add( config->iface.labels.label_all, MENU_ALL, ((void *)0) );
 if( platform_count() > 1 || config->iface.prune_menus == 0 ) {
  menu_item_add( config->iface.labels.label_platform, MENU_PLATFORM, ((void *)0) );
 }
 if( category ) {
  do {
   if( category->value_count > 1 || config->iface.prune_menus == 0 )
    menu_item_add( category->name, MENU_CATEGORY, category );
   category = category->next;
  } while( category != category_first() );
 }
 items_visible = menu_items;
 if( menu_items > config->iface.theme.menu.max_visible )
  items_visible = config->iface.theme.menu.max_visible;
 if( items_visible ) {
  struct menu_item *item = menu_start;
  if( item ) {
   item = item->next;
   for( i = 0 ; i < items_visible + 2 ; i++ ) {
    struct menu_tile *tile = malloc( sizeof(struct menu_tile) );
    if( tile ) {
     GLfloat offset = (((GLfloat)(i) - (((GLfloat)items_visible+1)/2 )) * spacing);
     if( config->iface.theme.menu.orientation == CONFIG_LANDSCAPE ) {
      tile->x = (offset + config->iface.theme.menu.offset1);
      tile->y = config->iface.theme.menu.offset2;
     }
     else {
      tile->x = -config->iface.theme.menu.offset2 * ogl_aspect_ratio();
      tile->y = -(offset + config->iface.theme.menu.offset1);
     }
     tile->zoom = 1;
     tile->alpha = min_alpha;
     tile->item = item;
     item = item->next;
     tile->next = ((void *)0);
     tile->prev = tile_end;
     if( tile_end )
      tile_end->next = tile;
     else
      tile_start = tile;
     tile_end = tile;
    }
    else {
     fprintf( stderr, "Warning: Couldn't allocate memeory for menu tile %d\n", i );
    }
   }
  }
 }
 selected = tile_start;
 for( i = 0 ; i < ((config->iface.theme.menu.max_visible+1)/2) ; i++ ) {
  selected = selected->next;
 }
 if( !selected )
  selected = tile_start;
 selected->zoom = zoom;
 selected->alpha = 1;
 while( selected->item->type != MENU_ALL ) {
  struct menu_tile *skip = tile_start;
  while( skip ) {
   skip->item = skip->item->next;
   skip = skip->next;
  }
 }
 tile_start->zoom = 0;
 tile_start->alpha = 0;
 tile_start->x = tile_start->next->x;
 tile_start->y = tile_start->next->y;
 tile_end->zoom = 0;
 tile_end->alpha = 0;
 tile_end->x = tile_end->prev->x;
 tile_end->y = tile_end->prev->y;
 arrow_retreat.size = config->iface.theme.menu.item_height * ITEM_SCALE * 1.5;
 arrow_advance.size = config->iface.theme.menu.item_height * ITEM_SCALE * 1.5;
 if( config->iface.theme.menu.orientation == CONFIG_LANDSCAPE ) {
  arrow_retreat.x = tile_start->x - (config->iface.theme.menu.item_width * ITEM_SCALE);
  arrow_retreat.y = tile_start->y;
  arrow_advance.x = tile_end->x + (config->iface.theme.menu.item_width * ITEM_SCALE);
  arrow_advance.y = tile_end->y;
  arrow_retreat.angle = 90;
  arrow_advance.angle = -90;
 }
 else {
  arrow_retreat.x = tile_start->x;
  arrow_retreat.y = tile_start->y + (config->iface.theme.menu.item_height * ITEM_SCALE);
  arrow_advance.x = tile_end->x;
  arrow_advance.y = tile_end->y - (config->iface.theme.menu.item_height * ITEM_SCALE);
  arrow_retreat.angle = 0;
  arrow_advance.angle = 180;
 }
 return 0;
}

canonical_original_code:
int menu_init() {
 struct category *category = category_first();
 struct config *config = config_get();
 int i;
 if( config->iface.frame_rate )
  steps = config->iface.frame_rate;
 else
  steps = MAX_STEPS;
 zoom = (float)config->iface.theme.menu.zoom;
 if( zoom < 1 ) {
  fprintf( stderr, "Warning: Menu zoom parameter less than 1 - setting to 1\n" );
  zoom = 1;
 }
 spacing = (float)config->iface.theme.menu.spacing;
 if( spacing < 0 ) {
  if( config->iface.theme.menu.orientation == CONFIG_LANDSCAPE )
   spacing = (float)config->iface.theme.menu.item_width * ITEM_SCALE * zoom * SPACING_FACTOR;
  else
   spacing = (float)config->iface.theme.menu.item_height * ITEM_SCALE * zoom * SPACING_FACTOR;
 }
 min_alpha = 1.0 - (GLfloat)(config->iface.theme.menu.transparency)/100;
 if( menu_load_texture() != 0 ) {
  return -1;
 }
 menu_item_add( config->iface.labels.label_all, MENU_ALL, ((void *)0) );
 if( platform_count() > 1 || config->iface.prune_menus == 0 ) {
  menu_item_add( config->iface.labels.label_platform, MENU_PLATFORM, ((void *)0) );
 }
 if( category ) {
  do {
   if( category->value_count > 1 || config->iface.prune_menus == 0 )
    menu_item_add( category->name, MENU_CATEGORY, category );
   category = category->next;
  } while( category != category_first() );
 }
 items_visible = menu_items;
 if( menu_items > config->iface.theme.menu.max_visible )
  items_visible = config->iface.theme.menu.max_visible;
 if( items_visible ) {
  struct menu_item *item = menu_start;
  if( item ) {
   item = item->next;
   for( i = 0 ; i < items_visible + 2 ; i++ ) {
    struct menu_tile *tile = malloc( sizeof(struct menu_tile) );
    if( tile ) {
     float offset = (((GLfloat)(i) - (((GLfloat)items_visible+1)/2 )) * spacing);
     if( config->iface.theme.menu.orientation == CONFIG_LANDSCAPE ) {
      tile->x = (offset + config->iface.theme.menu.offset1);
      tile->y = config->iface.theme.menu.offset2;
     }
     else {
      tile->x = -config->iface.theme.menu.offset2 * ogl_aspect_ratio();
      tile->y = -(offset + config->iface.theme.menu.offset1);
     }
     tile->zoom = 1;
     tile->alpha = min_alpha;
     tile->item = item;
     item = item->next;
     tile->next = ((void *)0);
     tile->prev = tile_end;
     if( tile_end )
      tile_end->next = tile;
     else
      tile_start = tile;
     tile_end = tile;
    }
    else {
     fprintf( stderr, "Warning: Couldn't allocate memeory for menu tile %d\n", i );
    }
   }
  }
 }
 selected = tile_start;
 for( i = 0 ; i < ((config->iface.theme.menu.max_visible+1)/2) ; i++ ) {
  selected = selected->next;
 }
 if( !selected )
  selected = tile_start;
 selected->zoom = zoom;
 selected->alpha = 1;
 while( selected->item->type != MENU_ALL ) {
  struct menu_tile *skip = tile_start;
  while( skip ) {
   skip->item = skip->item->next;
   skip = skip->next;
  }
 }
 tile_start->zoom = 0;
 tile_start->alpha = 0;
 tile_start->x = tile_start->next->x;
 tile_start->y = tile_start->next->y;
 tile_end->zoom = 0;
 tile_end->alpha = 0;
 tile_end->x = tile_end->prev->x;
 tile_end->y = tile_end->prev->y;
 arrow_retreat.size = config->iface.theme.menu.item_height * ITEM_SCALE * 1.5;
 arrow_advance.size = config->iface.theme.menu.item_height * ITEM_SCALE * 1.5;
 if( config->iface.theme.menu.orientation == CONFIG_LANDSCAPE ) {
  arrow_retreat.x = tile_start->x - (config->iface.theme.menu.item_width * ITEM_SCALE);
  arrow_retreat.y = tile_start->y;
  arrow_advance.x = tile_end->x + (config->iface.theme.menu.item_width * ITEM_SCALE);
  arrow_advance.y = tile_end->y;
  arrow_retreat.angle = 90;
  arrow_advance.angle = -90;
 }
 else {
  arrow_retreat.x = tile_start->x;
  arrow_retreat.y = tile_start->y + (config->iface.theme.menu.item_height * ITEM_SCALE);
  arrow_advance.x = tile_end->x;
  arrow_advance.y = tile_end->y - (config->iface.theme.menu.item_height * ITEM_SCALE);
  arrow_retreat.angle = 0;
  arrow_advance.angle = 180;
 }
 return 0;
}

variable_types: struct config { struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param { struct config_param *next; char name[64]; char value[64]; } *params; struct config_platform { struct config_platform *next; char name[128]; } *platform; } *emulators; struct config_platform *platforms; struct config_category { struct config_category *next; int id; char name[128]; struct config_category_value { struct config_category_value *next; char name[128]; } *values; struct config_lookup { struct config_lookup *next; char match[32]; char value[32]; } *lookups; } *categories; struct config_game { struct config_game *next; char name[128]; char rom_image[256]; char video[256]; char emulator[128]; struct config_game_category { struct config_game_category *next; struct config_category *category; struct config_category_value *value; } *categories; struct config_param *params; struct config_platform *platform; struct config_image { struct config_image *next; struct config_image_type { struct config_image_type *next; char name[128]; } *type; char file_name[256]; } *images; } *games; struct config_theme { struct config_theme *next; char name[128]; char directory[256]; char background_image[256]; int background_rotation; int background_transparency; char sounds[-1][256]; char font_file[256]; int font_size; struct config_rgb { unsigned char red; unsigned char green; unsigned char blue; } font_rgb; struct config_menu { char texture[256]; float item_width; float item_height; float font_scale; float zoom; int transparency; float offset1; float offset2; int max_visible; float spacing; int orientation; int auto_hide; int border; } menu; struct config_submenu { char texture[256]; float item_width; float item_height; float font_scale; float offset1; float offset2; } submenu; struct config_game_sel { float offset1; float offset2; float size_x; float size_y; float tile_size; int orientation; int selected; struct config_game_sel_tile { struct config_game_sel_tile *next; int order; float pos[3]; float angle[3]; int transparency; } *tiles; } game_sel; struct config_snap { float offset1; float offset2; float angle_x; float angle_y; float angle_z; float size; int fix_aspect_ratio; int auto_hide; int platform_icons; } snap; struct config_hints { float offset1; float offset2; float size; float spacing; int pulse; char image_back[256]; char image_select[256]; char image_arrow[256]; } hints; } *themes; struct config_image_type *image_types; struct config_location { struct config_location *next; struct config_location_type { struct config_location_type *next; char name[128]; } *type; char directory[256]; } *locations; struct config_location_type *location_types; struct config_iface { int full_screen; int screen_width; int screen_height; int screen_rotation; int screen_hflip; int screen_vflip; int frame_rate; int gfx_quality; int gfx_max_width; int gfx_max_height; int prune_menus; struct config_labels { char label_all[32]; char label_platform[32]; char label_back[32]; char label_select[32]; char label_lists[32]; } labels; struct config_control { int device_type; int device_id; int control_type; int control_id; int value; } controls[-1]; char theme_name[128]; struct config_theme theme; } iface; } *

variable_types: struct menu_tile { struct menu_tile *next; struct menu_tile *prev; struct menu_item { int type; struct menu_item *next; struct menu_item *prev; struct texture { unsigned int id; int width; int height; } *message; struct category { struct category *next; struct category *prev; struct category_value { struct category_value *next; struct category_value *prev; char *name; } *values; int id; char *name; int value_count; int has_unknowns; } *category; char *text; } *item; float x; float y; float zoom; float alpha; } *

variable_types: offset float

user_defined_types: struct config { struct config_emulator *emulators; struct config_platform *platforms; struct config_category *categories; struct config_game *games; struct config_theme *themes; struct config_image_type *image_types; struct config_location *locations; struct config_location_type *location_types; struct config_iface iface; }

user_defined_types: struct config_iface { int full_screen; int screen_width; int screen_height; int screen_rotation; int screen_hflip; int screen_vflip; int frame_rate; int gfx_quality; int gfx_max_width; int gfx_max_height; int prune_menus; struct config_labels labels; struct config_control controls[-1]; char theme_name[128]; struct config_theme theme; }

user_defined_types: struct config_category { struct config_category *next; int id; char name[128]; struct config_category_value *values; struct config_lookup *lookups; }

user_defined_types: struct config_game { struct config_game *next; char name[128]; char rom_image[256]; char video[256]; char emulator[128]; struct config_game_category *categories; struct config_param *params; struct config_platform *platform; struct config_image *images; }

user_defined_types: struct config_theme { struct config_theme *next; char name[128]; char directory[256]; char background_image[256]; int background_rotation; int background_transparency; char sounds[-1][256]; char font_file[256]; int font_size; struct config_rgb font_rgb; struct config_menu menu; struct config_submenu submenu; struct config_game_sel game_sel; struct config_snap snap; struct config_hints hints; }

user_defined_types: struct config_location { struct config_location *next; struct config_location_type *type; char directory[256]; }

user_defined_types: struct config_game_sel { float offset1; float offset2; float size_x; float size_y; float tile_size; int orientation; int selected; struct config_game_sel_tile *tiles; }

user_defined_types: struct config_image { struct config_image *next; struct config_image_type *type; char file_name[256]; }


original_code:
void menu_draw( void ) {
 if( visible ) {
  struct menu_tile *tile = tile_start;
  GLfloat item_zoom,tx,ty,mx,my = 0;
  GLfloat xfactor = ogl_xfactor();
  GLfloat yfactor = ogl_yfactor();
  const struct config_menu *config = &config_get()->iface.theme.menu;
  while( tile ) {
   struct menu_tile *dest = tile;
   if( direction ) {
    if( direction > 0 )
     dest = tile->next;
    else
     dest = tile->prev;
    if( step-- == 0 ) {
     direction = 0;
    }
   }
   if( dest ) {
    item_zoom = tile->zoom + (((dest->zoom-tile->zoom)/steps) * step);
    if( hide_direction ) {
     if( hide_direction == 1 )
      item_zoom = item_zoom - ((item_zoom / steps) * (steps - step));
     else
      item_zoom = (item_zoom / steps) * (steps - step);
     if( step-- == 1 ) {
      if( hide_direction == -1 )
       visible = 1;
      else
       visible = 0;
      hide_direction = 0;
     }
    }
    mx = ((config->item_width * ITEM_SCALE)/2) * xfactor * item_zoom;
    my = ((config->item_height * ITEM_SCALE)/2) * xfactor * item_zoom;
    tx = ((GLfloat)tile->item->message->width * (config->font_scale * FONT_SCALE)) * xfactor * item_zoom;
    if( tx > mx * (1.0 - ((GLfloat)config->border/100)) )
     tx = mx * (1.0 - ((GLfloat)config->border/100));
    ty = ((GLfloat)tile->item->message->height * (config->font_scale * FONT_SCALE)) * xfactor * item_zoom;
    if( ty > my * (1.0 - ((GLfloat)config->border/100)) )
     ty = my * (1.0 - ((GLfloat)config->border/100));
    ogl_load_alterego();
    glTranslatef( (tile->x + (((dest->x-tile->x)/steps) * step)) * xfactor,
          (tile->y + (((dest->y-tile->y)/steps) * step)) * yfactor,
          MENU_DEPTH );
    glColor4f( 1.0, 1.0, 1.0, tile->alpha + (((dest->alpha-tile->alpha)/steps) * step) );
    glBlendFunc(0x0302,0x0303);
    glEnable(0x0DE1);
    glTexEnvf(0x2300, 0x2200, 0x2100 );
    glBindTexture( 0x0DE1, menu_texture->id );
    glBegin( 0x0007 );
     glTexCoord2f(0.0, 0.0); glVertex3f(-mx, my, 0.0);
     glTexCoord2f(0.0, 1.0); glVertex3f(-mx, -my, 0.0);
     glTexCoord2f(1.0, 1.0); glVertex3f( mx, -my, 0.0);
     glTexCoord2f(1.0, 0.0); glVertex3f( mx, my, 0.0);
    glEnd();
    glBindTexture( 0x0DE1, tile->item->message->id );
    glBegin( 0x0007 );
     glTexCoord2f(0.0, 0.0); glVertex3f( -tx, ty, 0.0);
     glTexCoord2f(0.0, 1.0); glVertex3f( -tx, -ty, 0.0);
     glTexCoord2f(1.0, 1.0); glVertex3f( tx, -ty, 0.0);
     glTexCoord2f(1.0, 0.0); glVertex3f( tx, ty, 0.0);
    glEnd();
   }
   tile = tile->next;
  }
  if( focus_has() == FOCUS_MENU ) {
   hint_draw_arrow( &arrow_retreat );
   hint_draw_arrow( &arrow_advance );
  }
 }
}

canonical_original_code:
void menu_draw() {
 if( visible ) {
  struct menu_tile *tile = tile_start;
  float item_zoom; float tx; float ty; float mx; float my = 0;
  float xfactor = ogl_xfactor();
  float yfactor = ogl_yfactor();
  struct config_menu *config = &config_get()->iface.theme.menu;
  while( tile ) {
   struct menu_tile *dest = tile;
   if( direction ) {
    if( direction > 0 )
     dest = tile->next;
    else
     dest = tile->prev;
    if( step-- == 0 ) {
     direction = 0;
    }
   }
   if( dest ) {
    item_zoom = tile->zoom + (((dest->zoom-tile->zoom)/steps) * step);
    if( hide_direction ) {
     if( hide_direction == 1 )
      item_zoom = item_zoom - ((item_zoom / steps) * (steps - step));
     else
      item_zoom = (item_zoom / steps) * (steps - step);
     if( step-- == 1 ) {
      if( hide_direction == -1 )
       visible = 1;
      else
       visible = 0;
      hide_direction = 0;
     }
    }
    mx = ((config->item_width * ITEM_SCALE)/2) * xfactor * item_zoom;
    my = ((config->item_height * ITEM_SCALE)/2) * xfactor * item_zoom;
    tx = ((float)tile->item->message->width * (config->font_scale * FONT_SCALE)) * xfactor * item_zoom;
    if( tx > mx * (1.0 - ((float)config->border/100)) )
     tx = mx * (1.0 - ((float)config->border/100));
    ty = ((float)tile->item->message->height * (config->font_scale * FONT_SCALE)) * xfactor * item_zoom;
    if( ty > my * (1.0 - ((float)config->border/100)) )
     ty = my * (1.0 - ((float)config->border/100));
    ogl_load_alterego();
    glTranslatef( (tile->x + (((dest->x-tile->x)/steps) * step)) * xfactor,
          (tile->y + (((dest->y-tile->y)/steps) * step)) * yfactor,
          MENU_DEPTH );
    glColor4f( 1.0, 1.0, 1.0, tile->alpha + (((dest->alpha-tile->alpha)/steps) * step) );
    glBlendFunc(0x0302,0x0303);
    glEnable(0x0DE1);
    glTexEnvf(0x2300, 0x2200, 0x2100 );
    glBindTexture( 0x0DE1, menu_texture->id );
    glBegin( 0x0007 );
     glTexCoord2f(0.0, 0.0); glVertex3f(-mx, my, 0.0);
     glTexCoord2f(0.0, 1.0); glVertex3f(-mx, -my, 0.0);
     glTexCoord2f(1.0, 1.0); glVertex3f( mx, -my, 0.0);
     glTexCoord2f(1.0, 0.0); glVertex3f( mx, my, 0.0);
    glEnd();
    glBindTexture( 0x0DE1, tile->item->message->id );
    glBegin( 0x0007 );
     glTexCoord2f(0.0, 0.0); glVertex3f( -tx, ty, 0.0);
     glTexCoord2f(0.0, 1.0); glVertex3f( -tx, -ty, 0.0);
     glTexCoord2f(1.0, 1.0); glVertex3f( tx, -ty, 0.0);
     glTexCoord2f(1.0, 0.0); glVertex3f( tx, ty, 0.0);
    glEnd();
   }
   tile = tile->next;
  }
  if( focus_has() == FOCUS_MENU ) {
   hint_draw_arrow( &arrow_retreat );
   hint_draw_arrow( &arrow_advance );
  }
 }
}

variable_types: tx float

variable_types: ty float

variable_types: mx float

variable_types: my float

variable_types: xfactor float

variable_types: yfactor float

variable_types: struct config_menu { char texture[256]; float item_width; float item_height; float font_scale; float zoom; int transparency; float offset1; float offset2; int max_visible; float spacing; int orientation; int auto_hide; int border; } *


decompiled_code:
void menu_advance()
{
_QWORD *v0; // rax

if ( !direction )
{
v0 = (_QWORD *)tile_start;
direction = 1;
step = steps;
if ( tile_start )
{
do
{
v0[2] = *(_QWORD *)(v0[2] + 8LL);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
}
}

canonical_decompiled_code:
void func10()
{
_QWORD *v0; // rax

if ( !direction )
{
v0 = (_QWORD *)tile_start;
direction = 1;
step = steps;
if ( tile_start )
{
do
{
v0[2] = *(_QWORD *)(v0[2] + 8LL);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
}
}

original_code:
void menu_advance( void ) {
 struct menu_tile *t = tile_start;
 if( direction == 0 ) {
  direction = 1;
  step = steps;
  while( t ) {
   t->item = t->item->next;
   t = t->next;
  }
 }
}

canonical_original_code:
void menu_advance() {
 struct menu_tile *t = tile_start;
 if( direction == 0 ) {
  direction = 1;
  step = steps;
  while( t ) {
   t->item = t->item->next;
   t = t->next;
  }
 }
}


decompiled_code:
void menu_retreat()
{
_QWORD *v0; // rax

if ( !direction )
{
v0 = (_QWORD *)tile_start;
direction = -1;
step = steps;
if ( tile_start )
{
do
{
v0[2] = *(_QWORD *)(v0[2] + 16LL);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
}
}

canonical_decompiled_code:
void func11()
{
_QWORD *v0; // rax

if ( !direction )
{
v0 = (_QWORD *)tile_start;
direction = -1;
step = steps;
if ( tile_start )
{
do
{
v0[2] = *(_QWORD *)(v0[2] + 16LL);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
}
}

original_code:
void menu_retreat( void ) {
 struct menu_tile *t = tile_start;
 if( direction == 0 ) {
  direction = -1;
  step = steps;
  while( t ) {
   t->item = t->item->prev;
   t = t->next;
  }
 }
}

canonical_original_code:
void menu_retreat() {
 struct menu_tile *t = tile_start;
 if( direction == 0 ) {
  direction = -1;
  step = steps;
  while( t ) {
   t->item = t->item->prev;
   t = t->next;
  }
 }
}


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

if ( !hide_direction && visible == 1 )
{
hide_direction = 1;
result = (unsigned int)steps;
step = steps;
}
return result;
}

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

if ( !hide_direction && visible == 1 )
{
hide_direction = 1;
result = (unsigned int)steps;
step = steps;
}
return result;
}

original_code:
void menu_hide( void ) {
 if( hide_direction == 0 && visible == 1 ) {
  hide_direction = 1;
  step = steps;
 }
}

canonical_original_code:
void menu_hide() {
 if( hide_direction == 0 && visible == 1 ) {
  hide_direction = 1;
  step = steps;
 }
}


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

result = visible | (unsigned int)hide_direction;
if ( !__PAIR64__(hide_direction, visible) )
{
visible = 1;
hide_direction = -1;
result = (unsigned int)steps;
step = steps;
}
return result;
}

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

result = visible | (unsigned int)hide_direction;
if ( !__PAIR64__(hide_direction, visible) )
{
visible = 1;
hide_direction = -1;
result = (unsigned int)steps;
step = steps;
}
return result;
}

original_code:
void menu_show( void ) {
 if( hide_direction == 0 && visible == 0 ) {
  visible = 1;
  hide_direction = -1;
  step = steps;
 }
}

canonical_original_code:
void menu_show() {
 if( hide_direction == 0 && visible == 0 ) {
  visible = 1;
  hide_direction = -1;
  step = steps;
 }
}


decompiled_code:
__int64 __fastcall menu_event(int a1)
{
int v1; // eax

v1 = *(_DWORD *)(config_get() + 2796);
switch ( a1 )
{
case 1:
if ( v1 != 1 )
goto LABEL_3;
sound_play(1LL);
menu_retreat();
return 0LL;
case 2:
if ( v1 != 1 )
goto LABEL_3;
goto LABEL_12;
case 3:
if ( v1 )
{
sound_play(2LL);
LABEL_3:
sound_play(2LL);
}
else
{
sound_play(1LL);
menu_retreat();
LABEL_12:
sound_play(1LL);
menu_advance();
}
return 0LL;
case 4:
if ( !v1 )
goto LABEL_12;
goto LABEL_3;
case 5:
sound_play(3LL);
focus_set(1LL);
return 0LL;
default:
return 0LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
int v1; // eax

v1 = *(_DWORD *)(config_get() + 2796);
switch ( a1 )
{
case 1:
if ( v1 != 1 )
goto LABEL_3;
sound_play(1LL);
func11();
return 0LL;
case 2:
if ( v1 != 1 )
goto LABEL_3;
goto LABEL_12;
case 3:
if ( v1 )
{
sound_play(2LL);
LABEL_3:
sound_play(2LL);
}
else
{
sound_play(1LL);
func11();
LABEL_12:
sound_play(1LL);
func10();
}
return 0LL;
case 4:
if ( !v1 )
goto LABEL_12;
goto LABEL_3;
case 5:
sound_play(3LL);
focus_set(1LL);
return 0LL;
default:
return 0LL;
}
}

original_code:
int menu_event( int event ) {
 int o = config_get()->iface.theme.menu.orientation;
 switch( event ) {
  case EVENT_UP:
   if( o == CONFIG_PORTRAIT ) {
    sound_play( SOUND_BLIP );
    menu_retreat();
   }
   else {
    sound_play( SOUND_NO );
   }
   break;
  case EVENT_DOWN:
   if( o == CONFIG_PORTRAIT ) {
    sound_play( SOUND_BLIP );
    menu_advance();
   }
   else {
    sound_play( SOUND_NO );
   }
   break;
  case EVENT_LEFT:
   if( o == CONFIG_LANDSCAPE ) {
    sound_play( SOUND_BLIP );
    menu_retreat();
   }
   else {
    sound_play( SOUND_NO );
   }
  case EVENT_RIGHT:
   if( o == CONFIG_LANDSCAPE ) {
    sound_play( SOUND_BLIP );
    menu_advance();
   }
   else {
    sound_play( SOUND_NO );
   }
   break;
  case EVENT_SELECT:
   sound_play( SOUND_SELECT );
   focus_set( FOCUS_SUBMENU );
   break;
  default:
   break;
 }
 return 0;
}

canonical_original_code:
int menu_event(int event) {
 int o = config_get()->iface.theme.menu.orientation;
 switch( event ) {
  case EVENT_UP:
   if( o == CONFIG_PORTRAIT ) {
    sound_play( SOUND_BLIP );
    menu_retreat();
   }
   else {
    sound_play( SOUND_NO );
   }
   break;
  case EVENT_DOWN:
   if( o == CONFIG_PORTRAIT ) {
    sound_play( SOUND_BLIP );
    menu_advance();
   }
   else {
    sound_play( SOUND_NO );
   }
   break;
  case EVENT_LEFT:
   if( o == CONFIG_LANDSCAPE ) {
    sound_play( SOUND_BLIP );
    menu_retreat();
   }
   else {
    sound_play( SOUND_NO );
   }
  case EVENT_RIGHT:
   if( o == CONFIG_LANDSCAPE ) {
    sound_play( SOUND_BLIP );
    menu_advance();
   }
   else {
    sound_play( SOUND_NO );
   }
   break;
  case EVENT_SELECT:
   sound_play( SOUND_SELECT );
   focus_set( FOCUS_SUBMENU );
   break;
  default:
   break;
 }
 return 0;
}

variable_types: event int

variable_types: o int


decompiled_code:
__int64 menu_got_focus()
{
submenu_hide();
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
submenu_hide();
return 0LL;
}

original_code:
int menu_got_focus( void ) {
 submenu_hide();
 return 0;
}

canonical_original_code:
int menu_got_focus() {
 submenu_hide();
 return 0;
}


decompiled_code:
__int64 menu_lost_focus()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func16()
{
return 0LL;
}

original_code:
int menu_lost_focus( void ) {
 return 0;
}

canonical_original_code:
int menu_lost_focus() {
 return 0;
}


decompiled_code:
__int64 menu_free()
{
__int64 v0; // rbx
__int64 v2; // rdi

v0 = menu_start;
if ( menu_start )
{
do
{
v2 = *(_QWORD *)(v0 + 24);
if ( v2 )
ogl_free_texture(v2);
v0 = *(_QWORD *)(v0 + 8);
}
while ( menu_start != v0 );
}
return menu_free_texture();
}

canonical_decompiled_code:
__int64 func17()
{
__int64 v0; // rbx
__int64 v2; // rdi

v0 = menu_start;
if ( menu_start )
{
do
{
v2 = *(_QWORD *)(v0 + 24);
if ( v2 )
ogl_free_texture(v2);
v0 = *(_QWORD *)(v0 + 8);
}
while ( menu_start != v0 );
}
return func4();
}

original_code:
void menu_free( void ) {
 struct menu_item *item = menu_start;
 if( item ) {
  do {
   if( item->message ) {
    ogl_free_texture( item->message );
   }
   item = item->next;
  } while( item != menu_start );
 }
 menu_free_texture();
}

canonical_original_code:
void menu_free() {
 struct menu_item *item = menu_start;
 if( item ) {
  do {
   if( item->message ) {
    ogl_free_texture( item->message );
   }
   item = item->next;
  } while( item != menu_start );
 }
 menu_free_texture();
}

variable_types: struct menu_item { int type; struct menu_item *next; struct menu_item *prev; struct texture { unsigned int id; int width; int height; } *message; struct category { struct category *next; struct category *prev; struct category_value { struct category_value *next; struct category_value *prev; char *name; } *values; int id; char *name; int value_count; int has_unknowns; } *category; char *text; } *


decompiled_code:
__int64 game_first()
{
return game_filter_start;
}

canonical_decompiled_code:
__int64 func0()
{
return game_filter_start;
}

original_code:
struct game *game_first( void ) {
 return game_filter_start;
}

canonical_original_code:
struct game *game_first() {
 return game_filter_start;
}

return_type: struct game { struct game *next; struct game *prev; struct game *all_next; struct game *all_prev; struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture { unsigned int id; int width; int height; } *texture; } *platform; struct game_category { struct game_category *next; char *name; char *value; } *categories; struct texture *texture; struct config_param { struct config_param *next; char name[64]; char value[64]; } *params; struct game_media { struct game_media *next; int type; char *subtype; char file_name[256]; } *media; struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param *params; struct config_platform { struct config_platform *next; char name[128]; } *platform; } *emulator; char *name; char *rom_path; } *

user_defined_types: struct game { struct game *next; struct game *prev; struct game *all_next; struct game *all_prev; struct platform *platform; struct game_category *categories; struct texture *texture; struct config_param *params; struct game_media *media; struct config_emulator *emulator; char *name; char *rom_path; }

user_defined_types: struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture *texture; }

user_defined_types: struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param *params; struct config_platform *platform; }


original_code:
void game_add( struct game *game, struct game *after ) {
 if( after == ((void *)0) ) {
  game->all_prev = game;
  game->all_next = game;
 }
 else {
  after->all_next->all_prev = game;
  game->all_next = after->all_next;
  after->all_next = game;
  game->all_prev = after;
 }
}

canonical_original_code:
void game_add(struct game *game, struct game *after) {
 if( after == ((void *)0) ) {
  game->all_prev = game;
  game->all_next = game;
 }
 else {
  after->all_next->all_prev = game;
  game->all_next = after->all_next;
  after->all_next = game;
  game->all_prev = after;
 }
}

variable_types: struct game { struct game *next; struct game *prev; struct game *all_next; struct game *all_prev; struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture { unsigned int id; int width; int height; } *texture; } *platform; struct game_category { struct game_category *next; char *name; char *value; } *categories; struct texture *texture; struct config_param { struct config_param *next; char name[64]; char value[64]; } *params; struct game_media { struct game_media *next; int type; char *subtype; char file_name[256]; } *media; struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param *params; struct config_platform { struct config_platform *next; char name[128]; } *platform; } *emulator; char *name; char *rom_path; } *

variable_types:
after
struct game *