decompiled_code:
__int64 __fastcall compile_format(int a1, char *a2)
{
_QWORD *v2; // r12
char *v3; // rbp
__int64 v4; // r13
char v5; // al
int v6; // edx
char v7; // bl
_QWORD *v8; // rax
int v9; // eax
char v10; // dl
__int64 v11; // rax
char *v12; // rcx
int v13; // esi
int v14; // eax
char v16[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = (_QWORD *)fmt;
if ( a1 <= 0 )
{
LABEL_23:
v14 = stamp_len;
stamp[stamp_len] = 32;
stamp_len = v14 + 2;
stamp[v14 + 1] = 0;
return 0LL;
}
v3 = a2;
v4 = (__int64)&a2[a1 - 1 + 1];
v5 = 0;
while ( 1 )
{
v7 = *v3;
if ( *v3 == 37 )
{
v5 = 1;
goto LABEL_4;
}
if ( v5 )
break;
v6 = stamp_len++;
stamp[v6] = v7;
LABEL_4:
if ( ++v3 == (char *)v4 )
goto LABEL_23;
}
if ( v7 == 104 )
{
gethostname(v16, 0x400uLL);
v10 = v16[0];
if ( v16[0] )
{
v11 = stamp_len + 1;
v12 = &v16[-stamp_len];
do
{
v13 = v11;
byte_4040BF[v11++] = v10;
v10 = v12[v11 - 1];
}
while ( v10 );
stamp_len = v13;
}
v5 = 0;
goto LABEL_4;
}
if ( v2 )
{
v8 = malloc(0x18uLL);
v2[2] = v8;
v2 = v8;
}
else
{
v2 = malloc(0x18uLL);
fmt = (__int64)v2;
}
v9 = stamp_len;
*(_DWORD *)v2 = stamp_len;
v2[2] = 0LL;
switch ( v7 )
{
case 'd':
v2[1] = format_utc_date;
stamp_len = v9 + 19;
v5 = 0;
goto LABEL_4;
case 'D':
v2[1] = format_local_date;
stamp_len = v9 + 19;
v5 = 0;
goto LABEL_4;
case 'l':
v2[1] = format_line_count;
stamp_len = v9 + 5;
v5 = 0;
goto LABEL_4;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, char *a2)
{
_QWORD *v2; // r12
char *v3; // rbp
__int64 v4; // r13
char v5; // al
int v6; // edx
char v7; // bl
_QWORD *v8; // rax
int v9; // eax
char v10; // dl
__int64 v11; // rax
char *v12; // rcx
int v13; // esi
int v14; // eax
char v16[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = (_QWORD *)fmt;
if ( a1 <= 0 )
{
LABEL_23:
v14 = stamp_len;
stamp[stamp_len] = 32;
stamp_len = v14 + 2;
stamp[v14 + 1] = 0;
return 0LL;
}
v3 = a2;
v4 = (__int64)&a2[a1 - 1 + 1];
v5 = 0;
while ( 1 )
{
v7 = *v3;
if ( *v3 == 37 )
{
v5 = 1;
goto LABEL_4;
}
if ( v5 )
break;
v6 = stamp_len++;
stamp[v6] = v7;
LABEL_4:
if ( ++v3 == (char *)v4 )
goto LABEL_23;
}
if ( v7 == 104 )
{
gethostname(v16, 0x400uLL);
v10 = v16[0];
if ( v16[0] )
{
v11 = stamp_len + 1;
v12 = &v16[-stamp_len];
do
{
v13 = v11;
byte_4040BF[v11++] = v10;
v10 = v12[v11 - 1];
}
while ( v10 );
stamp_len = v13;
}
v5 = 0;
goto LABEL_4;
}
if ( v2 )
{
v8 = malloc(0x18uLL);
v2[2] = v8;
v2 = v8;
}
else
{
v2 = malloc(0x18uLL);
fmt = (__int64)v2;
}
v9 = stamp_len;
*(_DWORD *)v2 = stamp_len;
v2[2] = 0LL;
switch ( v7 )
{
case 'd':
v2[1] = format_utc_date;
stamp_len = v9 + 19;
v5 = 0;
goto LABEL_4;
case 'D':
v2[1] = format_local_date;
stamp_len = v9 + 19;
v5 = 0;
goto LABEL_4;
case 'l':
v2[1] = format_line_count;
stamp_len = v9 + 5;
v5 = 0;
goto LABEL_4;
}
return 0xFFFFFFFFLL;
}

original_code:
int
compile_format (int len, char format[]) {
 _Bool formatting = 0;
 struct format *next = fmt;
 for (int i = 0; i < len; i++) {
  char ch = format[i];
  if (ch == '%') {
   formatting = 1;
   continue;
  }
  if (!formatting) {
   stamp[stamp_len++] = ch;
   continue;
  }
  formatting = 0;
  if (ch == 'h') {
   char hostname[1024];
   gethostname(hostname, 1024);
   for (int j = 0; hostname[j] != '\0'; j++) stamp[stamp_len++] = hostname[j];
   continue;
  }
  if (next) next = next->next = malloc(sizeof(struct format));
  else fmt = next = malloc(sizeof(struct format));
  next->offset = stamp_len;
  next->next = ((void *)0);
  if (ch == 'd') {
   next->format = format_utc_date;
   stamp_len += 19;
   continue;
  }
  if (ch == 'D') {
   next->format = format_local_date;
   stamp_len += 19;
   continue;
  }
  if (ch == 'l') {
   next->format = format_line_count;
   stamp_len += 5;
   continue;
  }
  return -1;
 }
 stamp[stamp_len++] = ' ';
 stamp[stamp_len++] = '\0';
 return 0;
}

canonical_original_code:
int compile_format(int len, char format[]) {
 _Bool formatting = 0;
 struct format *next = fmt;
 for (int i = 0; i < len; i++) {
  char ch = format[i];
  if (ch == '%') {
   formatting = 1;
   continue;
  }
  if (!formatting) {
   stamp[stamp_len++] = ch;
   continue;
  }
  formatting = 0;
  if (ch == 'h') {
   char hostname[1024];
   gethostname(hostname, 1024);
   for (int j = 0; hostname[j] != '\0'; j++) stamp[stamp_len++] = hostname[j];
   continue;
  }
  if (next) next = next->next = malloc(sizeof(struct format));
  else fmt = next = malloc(sizeof(struct format));
  next->offset = stamp_len;
  next->next = ((void *)0);
  if (ch == 'd') {
   next->format = format_utc_date;
   stamp_len += 19;
   continue;
  }
  if (ch == 'D') {
   next->format = format_local_date;
   stamp_len += 19;
   continue;
  }
  if (ch == 'l') {
   next->format = format_line_count;
   stamp_len += 5;
   continue;
  }
  return -1;
 }
 stamp[stamp_len++] = ' ';
 stamp[stamp_len++] = '\0';
 return 0;
}

variable_types:
format
char []

variable_types: i int

variable_types: ch char

variable_types:
hostname
char [1024]

variable_types: j int

user_defined_types: struct format { int offset; void (*format)(int offset); struct format *next; }


error

repo: mafintosh/tag

decompiled_code:
void __fastcall __noreturn error(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
write(2, buf, v1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func13(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
write(2, buf, v1);
exit(1);
}

original_code:
void
error(char *msg) {
 write(2, msg, strlen(msg));
 exit(1);
}

variable_types:
msg
char *

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
char *v4; // rbp
int v5; // eax
char v6; // r12
__int64 v7; // rbx
int v8; // er13
int v9; // eax
__int64 v10; // r15
int v12; // [rsp+8h] [rbp-440h]
char buf[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( argc <= 1 )
error(
"\n"
" Usage: tag [tags]\n"
" - tag all lines piped to stdin with a message\n"
"\n"
" Examples:\n"
" tag hello-world # -> hello-world\n"
" tag %h [%d] # -> hostname [YYYY-MM-DD HH:mm:ss UTC]\n"
" tag %D # -> YYYY-MM-DD HH:mm:ss in local time\n"
" tag %l test # -> line-number test\n"
"\n");
v3 = argv + 1;
do
{
v4 = (char *)*v3;
v5 = strlen(*v3);
if ( (int)compile_format(v5, v4) < 0 )
error("Invalid format\n");
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
v6 = 10;
while ( 1 )
{
v9 = read(0, buf, 0x400uLL);
v12 = v9;
if ( v9 <= 0 )
break;
v10 = (unsigned int)(v9 - 1);
v7 = 0LL;
v8 = 0;
while ( 1 )
{
if ( v6 == 10 )
{
apply_format();
if ( write(1, stamp, stamp_len) < 0 )
exit(1);
}
if ( buf[v7] == 10 )
{
if ( write(1, &buf[v8], (int)v7 - v8 + 1) < 0 )
exit(1);
v8 = v7 + 1;
}
v6 = buf[v7];
if ( v10 == v7 )
break;
++v7;
}
if ( v8 < v12 && write(1, &buf[v8], v12 - v8) < 0 )
exit(1);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
char *v4; // rbp
int v5; // eax
char v6; // r12
__int64 v7; // rbx
int v8; // er13
int v9; // eax
__int64 v10; // r15
int v12; // [rsp+8h] [rbp-440h]
char buf[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( argc <= 1 )
func13(
"\n"
" Usage: tag [tags]\n"
" - tag all lines piped to stdin with a message\n"
"\n"
" Examples:\n"
" tag hello-world # -> hello-world\n"
" tag %h [%d] # -> hostname [YYYY-MM-DD HH:mm:ss UTC]\n"
" tag %D # -> YYYY-MM-DD HH:mm:ss in local time\n"
" tag %l test # -> line-number test\n"
"\n");
v3 = argv + 1;
do
{
v4 = (char *)*v3;
v5 = strlen(*v3);
if ( (int)func12(v5, v4) < 0 )
func13("Invalid format\n");
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
v6 = 10;
while ( 1 )
{
v9 = read(0, buf, 0x400uLL);
v12 = v9;
if ( v9 <= 0 )
break;
v10 = (unsigned int)(v9 - 1);
v7 = 0LL;
v8 = 0;
while ( 1 )
{
if ( v6 == 10 )
{
func11();
if ( write(1, stamp, stamp_len) < 0 )
exit(1);
}
if ( buf[v7] == 10 )
{
if ( write(1, &buf[v8], (int)v7 - v8 + 1) < 0 )
exit(1);
v8 = v7 + 1;
}
v6 = buf[v7];
if ( v10 == v7 )
break;
++v7;
}
if ( v8 < v12 && write(1, &buf[v8], v12 - v8) < 0 )
exit(1);
}
return 0;
}

original_code:
int
main(int argc, char *argv[]) {
 if (argc < 2) {
  error(
   "\n"
   "  Usage: tag [tags]\n"
   "  - tag all lines piped to stdin with a message\n"
   "\n"
   "  Examples:\n"
   "    tag hello-world  # -> hello-world\n"
   "    tag %h [%d]      # -> hostname [YYYY-MM-DD HH:mm:ss UTC]\n"
   "    tag %D           # -> YYYY-MM-DD HH:mm:ss in local time\n"
   "    tag %l test      # -> line-number test\n"
   "\n"
  );
 }
 for (int i = 1; i < argc; i++) {
  if (compile_format(strlen(argv[i]), argv[i]) < 0) error("Invalid format\n");
 }
 char prev = '\n';
 char buf[1024];
 int len;
 while ((len = read(0, &buf, 1024)) > 0) {
  int offset = 0;
  for (int i = 0; i < len; i++) {
   if (prev == '\n') {
    apply_format();
    if (write(1, stamp, stamp_len) < 0) exit(1);
   }
   if (buf[i] == '\n') {
    if (write(1, buf+offset, i-offset+1) < 0) exit(1);
    offset = i+1;
   }
   prev = buf[i];
  }
  if (offset < len) {
   if (write(1, buf+offset, len-offset) < 0) exit(1);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: prev char

variable_types:
buf
char [1024]

variable_types: len int

variable_types: offset int

return_type: int


repo: magcius/cargovfs

decompiled_code:
_QWORD *cargo_vfs_file_entry_new()
{
_QWORD *result; // rax

result = malloc(0x28uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = malloc(0x28uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

original_code:
CargoVFSFileEntry *
cargo_vfs_file_entry_new (void)
{
  CargoVFSFileEntry *entry;
  entry = malloc (sizeof (CargoVFSFileEntry));
  memset (entry, 0, sizeof (CargoVFSFileEntry));
  return entry;
}

canonical_original_code:
struct _CargoVFSFileEntry *cargo_vfs_file_entry_new()
{
  struct _CargoVFSFileEntry *entry;
  entry = malloc (sizeof (CargoVFSFileEntry));
  memset (entry, 0, sizeof (CargoVFSFileEntry));
  return entry;
}

variable_types: struct _CargoVFSFileEntry { struct _CargoVFSDirectoryEntry { struct _CargoVFSDirectoryEntry *parent; char *name; int subdir_count; int file_count; struct _CargoVFSFileEntry *files; struct _CargoVFSDirectoryEntry *subdirs; struct _CargoVFSDirectoryEntry *next; } *parent; char *name; int offset; int unknown_1; int length; struct _CargoVFSFileEntry *next; } *

user_defined_types: struct _CargoVFSFileEntry { struct _CargoVFSDirectoryEntry *parent; char *name; int offset; int unknown_1; int length; struct _CargoVFSFileEntry *next; }


decompiled_code:
_QWORD *cargo_vfs_directory_entry_new()
{
_QWORD *result; // rax

result = malloc(0x30uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

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

result = malloc(0x30uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

original_code:
CargoVFSDirectoryEntry *
cargo_vfs_directory_entry_new (void)
{
  CargoVFSDirectoryEntry *entry;
  entry = malloc (sizeof (CargoVFSDirectoryEntry));
  memset (entry, 0, sizeof (CargoVFSDirectoryEntry));
  return entry;
}

canonical_original_code:
struct _CargoVFSDirectoryEntry *cargo_vfs_directory_entry_new()
{
  struct _CargoVFSDirectoryEntry *entry;
  entry = malloc (sizeof (CargoVFSDirectoryEntry));
  memset (entry, 0, sizeof (CargoVFSDirectoryEntry));
  return entry;
}

variable_types: struct _CargoVFSDirectoryEntry { struct _CargoVFSDirectoryEntry *parent; char *name; int subdir_count; int file_count; struct _CargoVFSFileEntry { struct _CargoVFSDirectoryEntry *parent; char *name; int offset; int unknown_1; int length; struct _CargoVFSFileEntry *next; } *files; struct _CargoVFSDirectoryEntry *subdirs; struct _CargoVFSDirectoryEntry *next; } *

user_defined_types: struct _CargoVFSDirectoryEntry { struct _CargoVFSDirectoryEntry *parent; char *name; int subdir_count; int file_count; struct _CargoVFSFileEntry *files; struct _CargoVFSDirectoryEntry *subdirs; struct _CargoVFSDirectoryEntry *next; }


decompiled_code:
__int64 __fastcall cargo_vfs_directory_entry_get_file(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 24); i; i = *(_QWORD *)(i + 32) )
{
if ( !strcmp(a2, *(const char **)(i + 8)) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 24); i; i = *(_QWORD *)(i + 32) )
{
if ( !strcmp(a2, *(const char **)(i + 8)) )
break;
}
return i;
}

original_code:
CargoVFSFileEntry *
cargo_vfs_directory_entry_get_file (CargoVFSDirectoryEntry *entry,
                                    char *filename)
{
  CargoVFSFileEntry *file;
  for (file = entry->files; file != ((void *)0); file = file->next)
    if (strcmp (filename, file->name) == 0)
      return file;
  return ((void *)0);
}

canonical_original_code:
struct _CargoVFSFileEntry *cargo_vfs_directory_entry_get_file(struct _CargoVFSDirectoryEntry *entry, char *filename)
{
  struct _CargoVFSFileEntry *file;
  for (file = entry->files; file != ((void *)0); file = file->next)
    if (strcmp (filename, file->name) == 0)
      return file;
  return ((void *)0);
}

variable_types:
entry
struct _CargoVFSDirectoryEntry *

variable_types:
filename
char *

return_type: struct _CargoVFSFileEntry { struct _CargoVFSDirectoryEntry { struct _CargoVFSDirectoryEntry *parent; char *name; int subdir_count; int file_count; struct _CargoVFSFileEntry *files; struct _CargoVFSDirectoryEntry *subdirs; struct _CargoVFSDirectoryEntry *next; } *parent; char *name; int offset; int unknown_1; int length; struct _CargoVFSFileEntry *next; } *


decompiled_code:
__int64 __fastcall cargo_vfs_directory_entry_append_file(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 24);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 32);
}
while ( result );
*(_QWORD *)(v3 + 32) = a2;
}
else
{
*(_QWORD *)(a1 + 24) = a2;
}
*a2 = a1;
++*(_DWORD *)(a1 + 20);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 24);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 32);
}
while ( result );
*(_QWORD *)(v3 + 32) = a2;
}
else
{
*(_QWORD *)(a1 + 24) = a2;
}
*a2 = a1;
++*(_DWORD *)(a1 + 20);
return result;
}

original_code:
void
cargo_vfs_directory_entry_append_file (CargoVFSDirectoryEntry *entry,
                                       CargoVFSFileEntry *file)
{
  if (entry->files != ((void *)0))
    {
      CargoVFSFileEntry *curr;
      curr = entry->files;
      while (curr->next != ((void *)0))
        curr = curr->next;
      curr->next = file;
    }
  else
    entry->files = file;
  file->parent = entry;
  entry->file_count ++;
}

canonical_original_code:
void cargo_vfs_directory_entry_append_file(struct _CargoVFSDirectoryEntry *entry, struct _CargoVFSFileEntry *file)
{
  if (entry->files != ((void *)0))
    {
      struct _CargoVFSFileEntry *curr;
      curr = entry->files;
      while (curr->next != ((void *)0))
        curr = curr->next;
      curr->next = file;
    }
  else
    entry->files = file;
  file->parent = entry;
  entry->file_count ++;
}

variable_types:
file
struct _CargoVFSFileEntry *


decompiled_code:
__int64 __fastcall cargo_vfs_directory_entry_append_subdir(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 32);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 40);
}
while ( result );
*(_QWORD *)(v3 + 40) = a2;
}
else
{
*(_QWORD *)(a1 + 32) = a2;
}
*a2 = a1;
++*(_DWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 32);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 40);
}
while ( result );
*(_QWORD *)(v3 + 40) = a2;
}
else
{
*(_QWORD *)(a1 + 32) = a2;
}
*a2 = a1;
++*(_DWORD *)(a1 + 16);
return result;
}

original_code:
void
cargo_vfs_directory_entry_append_subdir (CargoVFSDirectoryEntry *entry,
                                         CargoVFSDirectoryEntry *subdir)
{
  if (entry->subdirs != ((void *)0))
    {
      CargoVFSDirectoryEntry *curr;
      curr = entry->subdirs;
      while (curr->next != ((void *)0))
        curr = curr->next;
      curr->next = subdir;
    }
  else
    entry->subdirs = subdir;
  subdir->parent = entry;
  entry->subdir_count ++;
}

canonical_original_code:
void cargo_vfs_directory_entry_append_subdir(struct _CargoVFSDirectoryEntry *entry, struct _CargoVFSDirectoryEntry *subdir)
{
  if (entry->subdirs != ((void *)0))
    {
      struct _CargoVFSDirectoryEntry *curr;
      curr = entry->subdirs;
      while (curr->next != ((void *)0))
        curr = curr->next;
      curr->next = subdir;
    }
  else
    entry->subdirs = subdir;
  subdir->parent = entry;
  entry->subdir_count ++;
}

variable_types:
subdir
struct _CargoVFSDirectoryEntry *


decompiled_code:
__int64 __fastcall cargo_vfs_directory_entry_get_path(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // r13
size_t v4; // r12
__int64 v5; // rbx

v2 = strchr(a2, 47);
if ( !v2 )
return cargo_vfs_directory_entry_get_file(a1, a2);
v3 = v2;
v4 = v2 - a2;
v5 = *(_QWORD *)(a1 + 32);
if ( v5 )
{
while ( strncmp(a2, *(const char **)(v5 + 8), v4) )
{
v5 = *(_QWORD *)(v5 + 40);
if ( !v5 )
return v5;
}
v5 = cargo_vfs_directory_entry_get_path(v5, v3 + 1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // r13
size_t v4; // r12
__int64 v5; // rbx

v2 = strchr(a2, 47);
if ( !v2 )
return func8(a1, a2);
v3 = v2;
v4 = v2 - a2;
v5 = *(_QWORD *)(a1 + 32);
if ( v5 )
{
while ( strncmp(a2, *(const char **)(v5 + 8), v4) )
{
v5 = *(_QWORD *)(v5 + 40);
if ( !v5 )
return v5;
}
v5 = func11(v5, v3 + 1);
}
return v5;
}

original_code:
CargoVFSFileEntry *
cargo_vfs_directory_entry_get_path (CargoVFSDirectoryEntry *entry,
                                    char *path)
{
  CargoVFSDirectoryEntry *subdir;
  size_t len;
  char *slash;
  slash = strstr (path, "/");
  if (slash == ((void *)0))
    return cargo_vfs_directory_entry_get_file (entry, path);
  len = slash - path;
  for (subdir = entry->subdirs; subdir != ((void *)0); subdir = subdir->next)
    if (strncmp (path, subdir->name, len) == 0)
      return cargo_vfs_directory_entry_get_path (subdir, slash + 1);
  return ((void *)0);
}

canonical_original_code:
struct _CargoVFSFileEntry *cargo_vfs_directory_entry_get_path(struct _CargoVFSDirectoryEntry *entry, char *path)
{
  struct _CargoVFSDirectoryEntry *subdir;
  unsigned long len;
  char *slash;
  slash = strstr (path, "/");
  if (slash == ((void *)0))
    return cargo_vfs_directory_entry_get_file (entry, path);
  len = slash - path;
  for (subdir = entry->subdirs; subdir != ((void *)0); subdir = subdir->next)
    if (strncmp (path, subdir->name, len) == 0)
      return cargo_vfs_directory_entry_get_path (subdir, slash + 1);
  return ((void *)0);
}

variable_types:
path
char *

variable_types:
len
unsigned long

variable_types:
slash
char *


decompiled_code:
char *__fastcall cargo_vfs_directory_entry_path(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
char *result; // rax

if ( *(_QWORD *)a1 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = cargo_vfs_directory_entry_path(*(_QWORD *)a1);
result = (char *)cargo_util_build_path(v2, v1);
}
else
{
result = *(char **)(a1 + 8);
if ( result )
result = strdup(*(const char **)(a1 + 8));
}
return result;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
char *result; // rax

if ( *(_QWORD *)a1 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = func12(*(_QWORD *)a1);
result = (char *)cargo_util_build_path(v2, v1);
}
else
{
result = *(char **)(a1 + 8);
if ( result )
result = strdup(*(const char **)(a1 + 8));
}
return result;
}

original_code:
char *
cargo_vfs_directory_entry_path (CargoVFSDirectoryEntry *entry)
{
  if (entry->parent == ((void *)0))
    return (entry->name != ((void *)0)) ? strdup (entry->name) : ((void *)0);
  return cargo_util_build_path (cargo_vfs_directory_entry_path (entry->parent),
                                entry->name);
}

canonical_original_code:
char *cargo_vfs_directory_entry_path(struct _CargoVFSDirectoryEntry *entry)
{
  if (entry->parent == ((void *)0))
    return (entry->name != ((void *)0)) ? strdup (entry->name) : ((void *)0);
  return cargo_util_build_path (cargo_vfs_directory_entry_path (entry->parent),
                                entry->name);
}

return_type: char *


decompiled_code:
__int64 __fastcall cargo_vfs_file_entry_path(__int64 *a1)
{
__int64 v1; // rbx
char *v2; // rax

v1 = a1[1];
v2 = cargo_vfs_directory_entry_path(*a1);
return cargo_util_build_path(v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 *a1)
{
__int64 v1; // rbx
char *v2; // rax

v1 = a1[1];
v2 = func12(*a1);
return cargo_util_build_path(v2, v1);
}

original_code:
char *
cargo_vfs_file_entry_path (CargoVFSFileEntry *entry)
{
  return cargo_util_build_path (cargo_vfs_directory_entry_path (entry->parent),
                                entry->name);
}

canonical_original_code:
char *cargo_vfs_file_entry_path(struct _CargoVFSFileEntry *entry)
{
  return cargo_util_build_path (cargo_vfs_directory_entry_path (entry->parent),
                                entry->name);
}


decompiled_code:
char *__fastcall cargo_util_build_path(char *s, char *a2)
{
char *v2; // r12
size_t v4; // r13
size_t v5; // r14

if ( !s || !*s )
return strdup(a2);
if ( !a2 || !*a2 )
return strdup(s);
v4 = strlen(s);
v5 = v4 + strlen(a2);
v2 = (char *)malloc(v5 + 2);
strcpy(v2, s);
v2[v4] = 47;
strcpy(&v2[v4 + 1], a2);
v2[v5 + 1] = 0;
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *s, char *a2)
{
char *v2; // r12
size_t v4; // r13
size_t v5; // r14

if ( !s || !*s )
return strdup(a2);
if ( !a2 || !*a2 )
return strdup(s);
v4 = strlen(s);
v5 = v4 + strlen(a2);
v2 = (char *)malloc(v5 + 2);
strcpy(v2, s);
v2[v4] = 47;
strcpy(&v2[v4 + 1], a2);
v2[v5 + 1] = 0;
return v2;
}

original_code:
char *
cargo_util_build_path (char *s1, char *s2)
{
  char *destination;
  size_t s1_len, s2_len;
  if (s1 == ((void *)0) || *s1 == '\0')
      return strdup (s2);
  if (s2 == ((void *)0) || *s2 == '\0')
      return strdup (s1);
  s1_len = strlen (s1); s2_len = strlen (s2);
  destination = malloc (s1_len + 1 + s2_len + 1);
  strcpy (destination, s1);
  destination[s1_len] = '/';
  strcpy (destination + s1_len + 1, s2);
  destination[s1_len + 1 + s2_len] = '\0';
  return destination;
}

canonical_original_code:
char *cargo_util_build_path(char *s1, char *s2)
{
  char *destination;
  unsigned long s1_len; unsigned long s2_len;
  if (s1 == ((void *)0) || *s1 == '\0')
      return strdup (s2);
  if (s2 == ((void *)0) || *s2 == '\0')
      return strdup (s1);
  s1_len = strlen (s1); s2_len = strlen (s2);
  destination = malloc (s1_len + 1 + s2_len + 1);
  strcpy (destination, s1);
  destination[s1_len] = '/';
  strcpy (destination + s1_len + 1, s2);
  destination[s1_len + 1 + s2_len] = '\0';
  return destination;
}

variable_types:
destination
char *


decompiled_code:
__int64 __fastcall cargo_util_ensure_directory_exists(const char *a1)
{
int v1; // edx
__int64 result; // rax

v1 = mkdir(a1, 0x1FDu);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)-(*_errno_location() != 17);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
int v1; // edx
__int64 result; // rax

v1 = mkdir(a1, 0x1FDu);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)-(*_errno_location() != 17);
return result;
}

original_code:
int
cargo_util_ensure_directory_exists (char *directory)
{
  if (mkdir (directory, 0775) == -1)
    {
      if ((*__errno_location ()) != 17)
        {
          return -1;
        }
    }
  return 0;
}

canonical_original_code:
int cargo_util_ensure_directory_exists(char *directory)
{
  if (mkdir (directory, 0775) == -1)
    {
      if ((*__errno_location ()) != 17)
        {
          return -1;
        }
    }
  return 0;
}

variable_types:
directory
char *


decompiled_code:
void file_extracted_callback()
{
char *v0; // rbx

v0 = (char *)cargo_vfs_file_entry_path();
printf("Unpacked '%s'...\n", v0);
free(v0);
}

canonical_decompiled_code:
void func0()
{
char *v0; // rbx

v0 = (char *)cargo_vfs_file_entry_path();
printf("Unpacked '%s'...\n", v0);
free(v0);
}

original_code:
static void
file_extracted_callback (CargoVFSFileEntry *file)
{
  char *path;
  path = cargo_vfs_file_entry_path (file);
  printf ("Unpacked '%s'...\n", path);
  free (path);
}

canonical_original_code:
static void file_extracted_callback(struct _CargoVFSFileEntry *file)
{
  char *path;
  path = cargo_vfs_file_entry_path (file);
  printf ("Unpacked '%s'...\n", path);
  free (path);
}


decompiled_code:
int __fastcall print_indent(int a1)
{
int i; // ebx
int result; // eax

for ( i = a1; i; --i )
result = putchar(32);
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int i; // ebx
int result; // eax

for ( i = a1; i; --i )
result = putchar(32);
return result;
}

original_code:
static inline void
print_indent (int indent)
{
  while (indent --)
    printf (" ");
}

canonical_original_code:
static inline void print_indent(int indent)
{
  while (indent --)
    printf (" ");
}

variable_types: indent int


decompiled_code:
int __fastcall list_directory(__int64 a1, int a2)
{
__int64 i; // rbx
int result; // eax
__int64 j; // rbx

for ( i = *(_QWORD *)(a1 + 32); i; i = *(_QWORD *)(i + 40) )
{
print_indent(a2);
printf("+ %s\n", *(const char **)(i + 8));
result = list_directory(i, (unsigned int)(a2 + 2));
}
for ( j = *(_QWORD *)(a1 + 24); j; j = *(_QWORD *)(j + 32) )
{
print_indent(a2);
result = printf("- %s\n", *(const char **)(j + 8));
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
__int64 i; // rbx
int result; // eax
__int64 j; // rbx

for ( i = *(_QWORD *)(a1 + 32); i; i = *(_QWORD *)(i + 40) )
{
func0(a2);
printf("+ %s\n", *(const char **)(i + 8));
result = func1(i, (unsigned int)(a2 + 2));
}
for ( j = *(_QWORD *)(a1 + 24); j; j = *(_QWORD *)(j + 32) )
{
func0(a2);
result = printf("- %s\n", *(const char **)(j + 8));
}
return result;
}

original_code:
static void
list_directory (CargoVFSDirectoryEntry *entry,
                int indent)
{
  CargoVFSDirectoryEntry *subdir;
  CargoVFSFileEntry *file;
  for (subdir = entry->subdirs; subdir != ((void *)0); subdir = subdir->next)
    {
      print_indent (indent);
      printf ("+ %s\n", subdir->name);
      list_directory (subdir, indent + 2);
    }
  for (file = entry->files; file != ((void *)0); file = file->next)
    {
      print_indent (indent);
      printf ("- %s\n", file->name);
    }
}

canonical_original_code:
static void list_directory(struct _CargoVFSDirectoryEntry *entry, int indent)
{
  struct _CargoVFSDirectoryEntry *subdir;
  struct _CargoVFSFileEntry *file;
  for (subdir = entry->subdirs; subdir != ((void *)0); subdir = subdir->next)
    {
      print_indent (indent);
      printf ("+ %s\n", subdir->name);
      list_directory (subdir, indent + 2);
    }
  for (file = entry->files; file != ((void *)0); file = file->next)
    {
      print_indent (indent);
      printf ("- %s\n", file->name);
    }
}


repo: magical/dvdtools

decompiled_code:
int __fastcall print_layer(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned int a9)
{
printf("book_version: %d\n", a7 & 0xF);
printf("book_type: %d\n", (unsigned __int8)a7 >> 4);
printf("min_rate: %d\n", BYTE1(a7) & 0xF);
printf("disc_size: %d\n", BYTE1(a7) >> 4);
printf("layer_type: %d\n", BYTE2(a7) & 0xF);
printf("track_path: %d\n", (a7 & 0x100000) != 0);
printf("nlayers: %d\n", (BYTE2(a7) >> 5) & 3);
printf("track_density: %d\n", BYTE3(a7) & 0xF);
printf("bca: %d\n", BYTE4(a7) & 1);
printf("start_sector: 0x%X\n", (unsigned int)a8);
printf("end_sector: 0x%X\n", HIDWORD(a8));
return printf("end_sector_l0: 0x%X\n", a9);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned int a9)
{
printf("book_version: %d\n", a7 & 0xF);
printf("book_type: %d\n", (unsigned __int8)a7 >> 4);
printf("min_rate: %d\n", BYTE1(a7) & 0xF);
printf("disc_size: %d\n", BYTE1(a7) >> 4);
printf("layer_type: %d\n", BYTE2(a7) & 0xF);
printf("track_path: %d\n", (a7 & 0x100000) != 0);
printf("nlayers: %d\n", (BYTE2(a7) >> 5) & 3);
printf("track_density: %d\n", BYTE3(a7) & 0xF);
printf("bca: %d\n", BYTE4(a7) & 1);
printf("start_sector: 0x%X\n", (unsigned int)a8);
printf("end_sector: 0x%X\n", HIDWORD(a8));
return printf("end_sector_l0: 0x%X\n", a9);
}

original_code:
void print_layer(struct dvd_layer layer, unsigned i)
{
 (void)i;
 printf("book_version: %d\n", layer.book_version);
 printf("book_type: %d\n", layer.book_type);
 printf("min_rate: %d\n", layer.min_rate);
 printf("disc_size: %d\n", layer.disc_size);
 printf("layer_type: %d\n", layer.layer_type);
 printf("track_path: %d\n", layer.track_path);
 printf("nlayers: %d\n", layer.nlayers);
 printf("track_density: %d\n", layer.track_density);
 printf("bca: %d\n", layer.bca);
 printf("start_sector: 0x%X\n", layer.start_sector);
 printf("end_sector: 0x%X\n", layer.end_sector);
 printf("end_sector_l0: 0x%X\n", layer.end_sector_l0);
}

canonical_original_code:
void print_layer(struct dvd_layer layer, unsigned int i)
{
 (void)i;
 printf("book_version: %d\n", layer.book_version);
 printf("book_type: %d\n", layer.book_type);
 printf("min_rate: %d\n", layer.min_rate);
 printf("disc_size: %d\n", layer.disc_size);
 printf("layer_type: %d\n", layer.layer_type);
 printf("track_path: %d\n", layer.track_path);
 printf("nlayers: %d\n", layer.nlayers);
 printf("track_density: %d\n", layer.track_density);
 printf("bca: %d\n", layer.bca);
 printf("start_sector: 0x%X\n", layer.start_sector);
 printf("end_sector: 0x%X\n", layer.end_sector);
 printf("end_sector_l0: 0x%X\n", layer.end_sector_l0);
}

variable_types: struct dvd_layer { unsigned char book_version; unsigned char book_type; unsigned char min_rate; unsigned char disc_size; unsigned char layer_type; unsigned char track_path; unsigned char nlayers; unsigned char track_density; unsigned char linear_density; unsigned char bca; unsigned int start_sector; unsigned int end_sector; unsigned int end_sector_l0; }

variable_types:
i
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // ebp
unsigned int v5; // ebx
int *v6; // rax
char *v7; // rax
int result; // eax
int *v9; // rax
char *v10; // rax
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // r8
__int64 v14; // r9
_DWORD *v15; // rax
__m128i v16; // xmm0
_DWORD v17[526]; // [rsp+20h] [rbp-838h] BYREF

v3 = "/dev/dvd";
if ( argc == 2 )
v3 = argv[1];
v4 = open(v3, 0, envp);
v5 = 0;
if ( v4 >= 0 )
{
do
{
memset(v17, 0, 0x808uLL);
BYTE1(v17[0]) = v5;
if ( ioctl(v4, 0x5390uLL, v17) < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "Couldn't get layer %d info: %s\n", v5, v10);
}
else
{
v15 = &v17[5 * v5];
v16 = _mm_loadu_si128((const __m128i *)(v15 + 1));
print_layer(v5, 21392LL, v11, v12, v13, v14, v16.m128i_i64[0], v16.m128i_i64[1], v15[5]);
putc(10, _bss_start);
}
++v5;
}
while ( v5 != 4 );
result = 0;
}
else
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Couldn't open %s: %s\n", v3, v7);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // ebp
unsigned int v5; // ebx
int *v6; // rax
char *v7; // rax
int result; // eax
int *v9; // rax
char *v10; // rax
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // r8
__int64 v14; // r9
_DWORD *v15; // rax
__m128i v16; // xmm0
_DWORD v17[526]; // [rsp+20h] [rbp-838h] BYREF

v3 = "/dev/dvd";
if ( argc == 2 )
v3 = argv[1];
v4 = open(v3, 0, envp);
v5 = 0;
if ( v4 >= 0 )
{
do
{
memset(v17, 0, 0x808uLL);
BYTE1(v17[0]) = v5;
if ( ioctl(v4, 0x5390uLL, v17) < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "Couldn't get layer %d info: %s\n", v5, v10);
}
else
{
v15 = &v17[5 * v5];
v16 = _mm_loadu_si128((const __m128i *)(v15 + 1));
func7(v5, 21392LL, v11, v12, v13, v14, v16.m128i_i64[0], v16.m128i_i64[1], v15[5]);
putc(10, _bss_start);
}
++v5;
}
while ( v5 != 4 );
result = 0;
}
else
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Couldn't open %s: %s\n", v3, v7);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 char *dvd_filename = "/dev/dvd";
 if (argc == 1) {
 } else if (argc == 2) {
  dvd_filename = argv[1];
 }
 int fd = open(dvd_filename, 00);
 if (fd < 0) {
  fprintf(stderr, "Couldn't open %s: %s\n", dvd_filename, strerror((*__errno_location ())));
  return 1;
 }
 for (unsigned i = 0; i < 4; i++) {
  dvd_struct dvd = {0};
  dvd.type = 0x00;
  dvd.physical.layer_num = (__u8)i;
  int e = ioctl(fd, 0x5390, &dvd);
  if (e < 0) {
   fprintf(stderr, "Couldn't get layer %d info: %s\n", i, strerror((*__errno_location ())));
   continue;
  }
  print_layer(dvd.physical.layer[i], i);
  putc('\n', stdout);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *dvd_filename = "/dev/dvd";
 if (argc == 1) {
 } else if (argc == 2) {
  dvd_filename = argv[1];
 }
 int fd = open(dvd_filename, 00);
 if (fd < 0) {
  fprintf(stderr, "Couldn't open %s: %s\n", dvd_filename, strerror((*__errno_location ())));
  return 1;
 }
 for (unsigned int i = 0; i < 4; i++) {
  union dvd_struct dvd = {0};
  dvd.type = 0x00;
  dvd.physical.layer_num = (unsigned char)i;
  int e = ioctl(fd, 0x5390, &dvd);
  if (e < 0) {
   fprintf(stderr, "Couldn't get layer %d info: %s\n", i, strerror((*__errno_location ())));
   continue;
  }
  print_layer(dvd.physical.layer[i], i);
  putc('\n', stdout);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fd int

variable_types: union dvd_struct { unsigned char type; struct dvd_physical { unsigned char type; unsigned char layer_num; struct dvd_layer { unsigned char book_version; unsigned char book_type; unsigned char min_rate; unsigned char disc_size; unsigned char layer_type; unsigned char track_path; unsigned char nlayers; unsigned char track_density; unsigned char linear_density; unsigned char bca; unsigned int start_sector; unsigned int end_sector; unsigned int end_sector_l0; } layer[4]; } physical; struct dvd_copyright { unsigned char type; unsigned char layer_num; unsigned char cpst; unsigned char rmi; } copyright; struct dvd_disckey { unsigned char type; unsigned int agid; unsigned char value[2048]; } disckey; struct dvd_bca { unsigned char type; int len; unsigned char value[188]; } bca; struct dvd_manufact { unsigned char type; unsigned char layer_num; int len; unsigned char value[2048]; } manufact; }

variable_types: e int

user_defined_types: union dvd_struct { unsigned char type; struct dvd_physical physical; struct dvd_copyright copyright; struct dvd_disckey disckey; struct dvd_bca bca; struct dvd_manufact manufact; }

user_defined_types: struct dvd_physical { unsigned char type; unsigned char layer_num; struct dvd_layer layer[4]; }


repo: magical/ndsfuse

original_code:
int ndsfuse_getattr(const char *path, struct stat *stbuf)
{
 nds_file *ndsfile;
 tree_node *node;
 memset(stbuf, 0, sizeof(struct stat));
 ndsfile = (nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if(node == ((void *)0)) return -2;
 stbuf->st_nlink = 1;
 stbuf->st_mtim.tv_sec = ndsfile->mtime;
 stbuf->st_ctim.tv_sec = ndsfile->mtime;
 stbuf->st_atim.tv_sec = ndsfile->mtime;
 if(node->type == 1)
 {
  stbuf->st_mode = 0040000 | 0400 | (0400 >> 3) | ((0400 >> 3) >> 3) | 0100 | (0100 >> 3) | ((0100 >> 3) >> 3);
 }
 else if(node->type == 2)
 {
  stbuf->st_mode = 0100000 | 0400 | (0400 >> 3) | ((0400 >> 3) >> 3);
  stbuf->st_size = node->virtFileSize;
 }
 else if(node->type == 0)
 {
  stbuf->st_mode = 0100000 | 0400 | (0400 >> 3) | ((0400 >> 3) >> 3);
  if((node->id*2+1) < (ndsfile->fatsize/4))
   stbuf->st_size = ndsfile->fat[node->id*2+1] - ndsfile->fat[node->id*2];
  else return -2;
 }
 else return -2;
 return 0;
}

canonical_original_code:
int ndsfuse_getattr(char *path, struct stat *stbuf)
{
 struct nds_file *ndsfile;
 struct _tree_node *node;
 memset(stbuf, 0, sizeof(struct stat));
 ndsfile = (struct nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if(node == ((void *)0)) return -2;
 stbuf->st_nlink = 1;
 stbuf->st_mtim.tv_sec = ndsfile->mtime;
 stbuf->st_ctim.tv_sec = ndsfile->mtime;
 stbuf->st_atim.tv_sec = ndsfile->mtime;
 if(node->type == 1)
 {
  stbuf->st_mode = 0040000 | 0400 | (0400 >> 3) | ((0400 >> 3) >> 3) | 0100 | (0100 >> 3) | ((0100 >> 3) >> 3);
 }
 else if(node->type == 2)
 {
  stbuf->st_mode = 0100000 | 0400 | (0400 >> 3) | ((0400 >> 3) >> 3);
  stbuf->st_size = node->virtFileSize;
 }
 else if(node->type == 0)
 {
  stbuf->st_mode = 0100000 | 0400 | (0400 >> 3) | ((0400 >> 3) >> 3);
  if((node->id*2+1) < (ndsfile->fatsize/4))
   stbuf->st_size = ndsfile->fat[node->id*2+1] - ndsfile->fat[node->id*2];
  else return -2;
 }
 else return -2;
 return 0;
}

variable_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 { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

variable_types: struct nds_file { struct _tree_node { char name[128]; unsigned short id; char *virtFileData; unsigned int virtFileSize; int type; struct _tree_node *children; struct _tree_node *next; } *filetree; unsigned int *fat; unsigned int fatsize; int fd; long mtime; } *

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 nds_file { struct _tree_node *filetree; unsigned int *fat; unsigned int fatsize; int fd; long mtime; }


decompiled_code:
__int64 __fastcall ndsfuse_opendir(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
bool v3; // zf
__int64 result; // rax

v1 = fuse_get_context();
v2 = tree_find_node(**(_QWORD **)(v1 + 24), a1);
if ( !v2 )
return 4294967294LL;
v3 = *(_DWORD *)(v2 + 148) == 1;
result = 0LL;
if ( !v3 )
result = 4294967276LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
bool v3; // zf
__int64 result; // rax

v1 = fuse_get_context();
v2 = tree_find_node(**(_QWORD **)(v1 + 24), a1);
if ( !v2 )
return 4294967294LL;
v3 = *(_DWORD *)(v2 + 148) == 1;
result = 0LL;
if ( !v3 )
result = 4294967276LL;
return result;
}

original_code:
int ndsfuse_opendir(const char *path, struct fuse_file_info *fi)
{
 nds_file *ndsfile;
 tree_node *node;
 ndsfile = (nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if(node == ((void *)0)) return -2;
 if(node->type != 1) return -20;
 return 0;
}

canonical_original_code:
int ndsfuse_opendir(char *path, struct fuse_file_info *fi)
{
 struct nds_file *ndsfile;
 struct _tree_node *node;
 ndsfile = (struct nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if(node == ((void *)0)) return -2;
 if(node->type != 1) return -20;
 return 0;
}

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *

variable_types: struct _tree_node { char name[128]; unsigned short id; char *virtFileData; unsigned int virtFileSize; int type; struct _tree_node *children; struct _tree_node *next; } *


original_code:
int ndsfuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
 nds_file *ndsfile;
 tree_node *node;
 ndsfile = (nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if(node == ((void *)0)) return -2;
 if(node->type != 1) return -20;
 filler(buf, ".", ((void *)0), 0);
 filler(buf, "..", ((void *)0), 0);
 node = node->children;
 while(node != ((void *)0))
 {
  filler(buf, node->name, ((void *)0), 0);
  node = node->next;
 }
 return 0;
}

canonical_original_code:
int ndsfuse_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *fi)
{
 struct nds_file *ndsfile;
 struct _tree_node *node;
 ndsfile = (struct nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if(node == ((void *)0)) return -2;
 if(node->type != 1) return -20;
 filler(buf, ".", ((void *)0), 0);
 filler(buf, "..", ((void *)0), 0);
 node = node->children;
 while(node != ((void *)0))
 {
  filler(buf, node->name, ((void *)0), 0);
  node = node->next;
 }
 return 0;
}

variable_types:
path
char *

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, 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]; } *stbuf, long off)

variable_types: offset long

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }

user_defined_types: struct _tree_node { char name[128]; unsigned short id; char *virtFileData; unsigned int virtFileSize; int type; struct _tree_node *children; struct _tree_node *next; }


decompiled_code:
__int64 __fastcall ndsfuse_open(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = fuse_get_context();
v3 = tree_find_node(**(_QWORD **)(v2 + 24), a1);
result = *a2 & 1;
if ( (*a2 & 1) != 0 )
return 4294967266LL;
if ( !v3 )
return 4294967294LL;
if ( *(_DWORD *)(v3 + 148) == 1 )
result = 4294967275LL;
return result;
}

original_code:
int ndsfuse_open(const char *path, struct fuse_file_info *fi)
{
 nds_file *ndsfile;
 tree_node *node;
 ndsfile = (nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if (fi->flags & 01)
  return -30;
 if(node == ((void *)0)) return -2;
 if(node->type == 1) return -21;
 return 0;
}

canonical_original_code:
int ndsfuse_open(char *path, struct fuse_file_info *fi)
{
 struct nds_file *ndsfile;
 struct _tree_node *node;
 ndsfile = (struct nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if (fi->flags & 01)
  return -30;
 if(node == ((void *)0)) return -2;
 if(node->type == 1) return -21;
 return 0;
}


decompiled_code:
__int64 __fastcall ndsfuse_read(__int64 a1, void *a2, size_t a3, size_t a4, _BYTE *a5)
{
__int64 v8; // r13
__int64 v9; // rax
int v10; // edx
int v11; // edi
unsigned int v12; // ecx
size_t v13; // rcx

v8 = *(_QWORD *)(fuse_get_context() + 24);
v9 = tree_find_node(*(_QWORD *)v8, a1);
if ( (*a5 & 1) != 0 )
return (unsigned int)-30;
if ( !v9 )
return (unsigned int)-2;
v10 = *(_DWORD *)(v9 + 148);
if ( v10 == 1 )
return (unsigned int)-21;
if ( v10 )
{
if ( v10 != 2 )
return (unsigned int)-2;
v13 = *(unsigned int *)(v9 + 144);
}
else
{
v11 = 2 * *(unsigned __int16 *)(v9 + 128) + 1;
v12 = -2;
if ( (unsigned int)v11 >= *(_DWORD *)(v8 + 16) >> 2 )
return v12;
v13 = *(unsigned int *)(*(_QWORD *)(v8 + 8) + 4LL * v11);
}
if ( a4 >= v13 )
{
LODWORD(a3) = 0;
}
else
{
if ( a4 + a3 > v13 )
a3 = v13 - a4;
if ( v10 )
memcpy(a2, (const void *)(*(_QWORD *)(v9 + 136) + a4), a3);
else
LODWORD(a3) = pread64(
*(_DWORD *)(v8 + 20),
a2,
a3,
a4 + *(unsigned int *)(*(_QWORD *)(v8 + 8) + 8LL * *(unsigned __int16 *)(v9 + 128)));
}
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, void *a2, size_t a3, size_t a4, _BYTE *a5)
{
__int64 v8; // r13
__int64 v9; // rax
int v10; // edx
int v11; // edi
unsigned int v12; // ecx
size_t v13; // rcx

v8 = *(_QWORD *)(fuse_get_context() + 24);
v9 = tree_find_node(*(_QWORD *)v8, a1);
if ( (*a5 & 1) != 0 )
return (unsigned int)-30;
if ( !v9 )
return (unsigned int)-2;
v10 = *(_DWORD *)(v9 + 148);
if ( v10 == 1 )
return (unsigned int)-21;
if ( v10 )
{
if ( v10 != 2 )
return (unsigned int)-2;
v13 = *(unsigned int *)(v9 + 144);
}
else
{
v11 = 2 * *(unsigned __int16 *)(v9 + 128) + 1;
v12 = -2;
if ( (unsigned int)v11 >= *(_DWORD *)(v8 + 16) >> 2 )
return v12;
v13 = *(unsigned int *)(*(_QWORD *)(v8 + 8) + 4LL * v11);
}
if ( a4 >= v13 )
{
LODWORD(a3) = 0;
}
else
{
if ( a4 + a3 > v13 )
a3 = v13 - a4;
if ( v10 )
memcpy(a2, (const void *)(*(_QWORD *)(v9 + 136) + a4), a3);
else
LODWORD(a3) = pread64(
*(_DWORD *)(v8 + 20),
a2,
a3,
a4 + *(unsigned int *)(*(_QWORD *)(v8 + 8) + 8LL * *(unsigned __int16 *)(v9 + 128)));
}
return (unsigned int)a3;
}

original_code:
static int ndsfuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
 size_t len;
 nds_file *ndsfile;
 tree_node *node;
 ndsfile = (nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if (fi->flags & 01)
  return -30;
 if(node == ((void *)0)) return -2;
 if(node->type == 1) return -21;
 if(node->type == 0 && ((node->id*2+1) < (ndsfile->fatsize/4))) len = ndsfile->fat[node->id*2+1];
 else if(node->type == 2) len = node->virtFileSize;
 else return -2;
 if(offset < len)
 {
  if(offset + size > len)
   size = len - offset;
  if(node->type == 0)
  {
   size = pread(ndsfile->fd, buf, size, ndsfile->fat[node->id*2]+offset);
  }
  else if(node->type == 2)
  {
   memcpy(buf, node->virtFileData+offset, size);
  }
 }
 else size = 0;
 return size;
}

canonical_original_code:
static int ndsfuse_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
 unsigned long len;
 struct nds_file *ndsfile;
 struct _tree_node *node;
 ndsfile = (struct nds_file *)(fuse_get_context()->private_data);
 node = tree_find_node(ndsfile->filetree, path);
 if (fi->flags & 01)
  return -30;
 if(node == ((void *)0)) return -2;
 if(node->type == 1) return -21;
 if(node->type == 0 && ((node->id*2+1) < (ndsfile->fatsize/4))) len = ndsfile->fat[node->id*2+1];
 else if(node->type == 2) len = node->virtFileSize;
 else return -2;
 if(offset < len)
 {
  if(offset + size > len)
   size = len - offset;
  if(node->type == 0)
  {
   size = pread(ndsfile->fd, buf, size, ndsfile->fat[node->id*2]+offset);
  }
  else if(node->type == 2)
  {
   memcpy(buf, node->virtFileData+offset, size);
  }
 }
 else size = 0;
 return size;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types:
len
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
__int64 v4; // r13
int i; // ebx
int v6; // ebx
unsigned int v8; // [rsp+0h] [rbp-48h] BYREF
__int64 v9; // [rsp+8h] [rbp-40h]
int v10; // [rsp+10h] [rbp-38h]

v3 = argv;
v8 = 0;
v9 = 0LL;
v10 = 0;
if ( argc <= 2 )
{
printf("Usage: %s file.nds mount_point [fuse_options]\n", *argv);
v6 = 1;
}
else
{
v4 = nds_do_magic(argv[1]);
if ( v4 )
{
for ( i = 1; ; ++i )
{
if ( i != 2 )
{
fuse_opt_add_arg(&v8, *v3);
if ( argc <= i )
break;
}
++v3;
}
v6 = fuse_main_real(v8, v9, fuse_ops, 360LL, v4);
fuse_opt_free_args(&v8);
free_nds_file(v4);
}
else
{
puts("Some error occured!");
v6 = 1;
}
}
return v6;
}

original_code:
int main(int argc, char **argv)
{
 nds_file *ndsfile;
 struct fuse_args args = { 0, ((void *)0), 0 };
 int i, ret;
 char *filename;
 if(argc < 3)
 {
  printf("Usage: %s file.nds mount_point [fuse_options]\n",argv[0]);
  return 1;
 }
 filename = argv[1];
 ndsfile = nds_do_magic(filename);
 if(ndsfile == ((void *)0))
 {
  printf("Some error occured!\n");
  return 1;
 }
 for(i=0;i<argc;i++)
 {
  if(i != 1) fuse_opt_add_arg(&args, argv[i]);
 }
 ret = fuse_main_real(args.argc, args.argv, &fuse_ops, sizeof(*(&fuse_ops)), ndsfile);
 fuse_opt_free_args(&args);
 free_nds_file(ndsfile);
 return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct nds_file *ndsfile;
 struct fuse_args args = { 0, ((void *)0), 0 };
 int i; int ret;
 char *filename;
 if(argc < 3)
 {
  printf("Usage: %s file.nds mount_point [fuse_options]\n",argv[0]);
  return 1;
 }
 filename = argv[1];
 ndsfile = nds_do_magic(filename);
 if(ndsfile == ((void *)0))
 {
  printf("Some error occured!\n");
  return 1;
 }
 for(i=0;i<argc;i++)
 {
  if(i != 1) fuse_opt_add_arg(&args, argv[i]);
 }
 ret = fuse_main_real(args.argc, args.argv, &fuse_ops, sizeof(*(&fuse_ops)), ndsfile);
 fuse_opt_free_args(&args);
 free_nds_file(ndsfile);
 return ret;
}

variable_types:
argv
char **

variable_types: struct fuse_args { int argc; char **argv; int allocated; }

variable_types: i int

variable_types: ret int

variable_types:
filename
char *


decompiled_code:
char *__fastcall nds_prepare_virtual_file(int fd, __off64_t offset, size_t nbytes, char *src)
{
int v4; // er12
size_t v6; // r15
void *v7; // rbp
char *v8; // rbx
char *v9; // rax

v4 = nbytes;
v6 = (unsigned int)nbytes;
v7 = malloc((unsigned int)nbytes);
if ( !v7 )
return 0LL;
v8 = 0LL;
if ( lseek64(fd, (unsigned int)offset, 0) >= 0 && read(fd, v7, v6) == v4 )
{
v9 = (char *)malloc(0xA8uLL);
v8 = v9;
if ( v9 )
{
v9[127] = 0;
strncpy(v9, src, 0x7FuLL);
*((_QWORD *)v8 + 17) = v7;
*((_DWORD *)v8 + 36) = v4;
*((_DWORD *)v8 + 37) = 2;
*((_QWORD *)v8 + 19) = 0LL;
*((_QWORD *)v8 + 20) = 0LL;
}
}
return v8;
}

canonical_decompiled_code:
char *__fastcall func0(int fd, __off64_t offset, size_t nbytes, char *src)
{
int v4; // er12
size_t v6; // r15
void *v7; // rbp
char *v8; // rbx
char *v9; // rax

v4 = nbytes;
v6 = (unsigned int)nbytes;
v7 = malloc((unsigned int)nbytes);
if ( !v7 )
return 0LL;
v8 = 0LL;
if ( lseek64(fd, (unsigned int)offset, 0) >= 0 && read(fd, v7, v6) == v4 )
{
v9 = (char *)malloc(0xA8uLL);
v8 = v9;
if ( v9 )
{
v9[127] = 0;
strncpy(v9, src, 0x7FuLL);
*((_QWORD *)v8 + 17) = v7;
*((_DWORD *)v8 + 36) = v4;
*((_DWORD *)v8 + 37) = 2;
*((_QWORD *)v8 + 19) = 0LL;
*((_QWORD *)v8 + 20) = 0LL;
}
}
return v8;
}

original_code:
static tree_node *nds_prepare_virtual_file(int fd, uint32_t offset, uint32_t size, const char *name)
{
 char *tmp;
 tree_node *tmpnode;
 tmp = (char *)(malloc(size));
 if(tmp == ((void *)0)) return ((void *)0);
 if(lseek(fd, offset, 0) < 0) return ((void *)0);
 if(read(fd, tmp, size) != size) return ((void *)0);
 tmpnode = (tree_node *)(malloc(sizeof(tree_node)));
 if(tmpnode == ((void *)0)) return ((void *)0);
 memset(tmpnode->name, 0, sizeof(tmpnode->name));
 strncpy(tmpnode->name, name, sizeof(tmpnode->name) - 1);
 tmpnode->virtFileData = tmp;
 tmpnode->virtFileSize = size;
 tmpnode->type = 2;
 tmpnode->children = ((void *)0);
 tmpnode->next = ((void *)0);
 return tmpnode;
}

canonical_original_code:
static struct _tree_node *nds_prepare_virtual_file(int fd, unsigned int offset, unsigned int size, char *name)
{
 char *tmp;
 struct _tree_node *tmpnode;
 tmp = (char *)(malloc(size));
 if(tmp == ((void *)0)) return ((void *)0);
 if(lseek(fd, offset, 0) < 0) return ((void *)0);
 if(read(fd, tmp, size) != size) return ((void *)0);
 tmpnode = (struct _tree_node *)(malloc(sizeof(tree_node)));
 if(tmpnode == ((void *)0)) return ((void *)0);
 memset(tmpnode->name, 0, sizeof(tmpnode->name));
 strncpy(tmpnode->name, name, sizeof(tmpnode->name) - 1);
 tmpnode->virtFileData = tmp;
 tmpnode->virtFileSize = size;
 tmpnode->type = 2;
 tmpnode->children = ((void *)0);
 tmpnode->next = ((void *)0);
 return tmpnode;
}

variable_types: fd int

variable_types:
offset
unsigned int

variable_types:
size
unsigned int

variable_types:
name
char *

variable_types:
tmp
char *

return_type: struct _tree_node { char name[128]; unsigned short id; char *virtFileData; unsigned int virtFileSize; int type; struct _tree_node *children; struct _tree_node *next; } *


decompiled_code:
char *__fastcall nds_do_overlay(int fd, __off64_t offset, size_t nbytes, char *src)
{
unsigned int v4; // ebx
char *v6; // rax
char *v7; // r12
unsigned int *v8; // r13
unsigned int *v9; // rbp
unsigned int *v10; // r13
void *v11; // rbx

v4 = nbytes;
v6 = (char *)malloc(0xA8uLL);
v7 = v6;
if ( v6 )
{
v6[127] = 0;
strncpy(v6, src, 0x7FuLL);
*((_DWORD *)v7 + 37) = 1;
*((_QWORD *)v7 + 19) = 0LL;
*((_QWORD *)v7 + 20) = 0LL;
v8 = (unsigned int *)malloc(v4);
if ( v8 )
{
if ( lseek64(fd, (unsigned int)offset, 0) < 0 )
{
v7 = 0LL;
}
else if ( read(fd, v8, v4) == v4 )
{
v9 = v8;
v10 = (unsigned int *)((char *)v8 + v4);
while ( v9 < v10 )
{
v11 = malloc(0xA8uLL);
if ( !v11 )
return 0LL;
memset(v11, 0, 0x80uLL);
snprintf((char *)v11, 0x80uLL, "overlay_%08X.bin", *v9);
*((_DWORD *)v11 + 37) = 0;
*((_WORD *)v11 + 64) = v9[6];
*((_QWORD *)v11 + 19) = 0LL;
*((_QWORD *)v11 + 20) = 0LL;
v9 += 8;
if ( !(unsigned int)tree_add_node(v7, &unk_7F7, v11) )
return 0LL;
}
}
else
{
v7 = 0LL;
}
}
else
{
v7 = 0LL;
}
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func2(int fd, __off64_t offset, size_t nbytes, char *src)
{
unsigned int v4; // ebx
char *v6; // rax
char *v7; // r12
unsigned int *v8; // r13
unsigned int *v9; // rbp
unsigned int *v10; // r13
void *v11; // rbx

v4 = nbytes;
v6 = (char *)malloc(0xA8uLL);
v7 = v6;
if ( v6 )
{
v6[127] = 0;
strncpy(v6, src, 0x7FuLL);
*((_DWORD *)v7 + 37) = 1;
*((_QWORD *)v7 + 19) = 0LL;
*((_QWORD *)v7 + 20) = 0LL;
v8 = (unsigned int *)malloc(v4);
if ( v8 )
{
if ( lseek64(fd, (unsigned int)offset, 0) < 0 )
{
v7 = 0LL;
}
else if ( read(fd, v8, v4) == v4 )
{
v9 = v8;
v10 = (unsigned int *)((char *)v8 + v4);
while ( v9 < v10 )
{
v11 = malloc(0xA8uLL);
if ( !v11 )
return 0LL;
memset(v11, 0, 0x80uLL);
snprintf((char *)v11, 0x80uLL, "overlay_%08X.bin", *v9);
*((_DWORD *)v11 + 37) = 0;
*((_WORD *)v11 + 64) = v9[6];
*((_QWORD *)v11 + 19) = 0LL;
*((_QWORD *)v11 + 20) = 0LL;
v9 += 8;
if ( !(unsigned int)tree_add_node(v7, &unk_7F7, v11) )
return 0LL;
}
}
else
{
v7 = 0LL;
}
}
else
{
v7 = 0LL;
}
}
return v7;
}

original_code:
static tree_node *nds_do_overlay(int fd, uint32_t offset, uint32_t size, const char *name)
{
 char *tmp;
 nds_overlay_entry *overlay;
 tree_node *tmpnode, *tmpnode2;
 tmpnode = (tree_node *)(malloc(sizeof(tree_node)));
 if(tmpnode == ((void *)0)) return ((void *)0);
 memset(tmpnode->name, 0, sizeof(tmpnode->name));
 strncpy(tmpnode->name, name, sizeof(tmpnode->name) - 1);
 tmpnode->type = 1;
 tmpnode->children = ((void *)0);
 tmpnode->next = ((void *)0);
 tmp = (char *)(malloc(size));
 if(tmp == ((void *)0)) return ((void *)0);
 if(lseek(fd, offset, 0) < 0) return ((void *)0);
 if(read(fd, tmp, size) != size) return ((void *)0);
 overlay = (nds_overlay_entry *)(tmp);
 while(overlay < (nds_overlay_entry *)(tmp + size))
 {
  tmpnode2 = (tree_node *)(malloc(sizeof(tree_node)));
  if(tmpnode2 == ((void *)0)) return ((void *)0);
  memset(tmpnode2->name, 0, sizeof(tmpnode2->name));
  snprintf(tmpnode2->name, sizeof(tmpnode2->name), "overlay_%08X.bin", overlay->overlayid);
  tmpnode2->type = 0;
  tmpnode2->id = overlay->fileid;
  tmpnode2->children = ((void *)0);
  tmpnode2->next = ((void *)0);
  overlay++;
  if(!tree_add_node(tmpnode, "/", tmpnode2)) return ((void *)0);
 }
 return tmpnode;
}

canonical_original_code:
static struct _tree_node *nds_do_overlay(int fd, unsigned int offset, unsigned int size, char *name)
{
 char *tmp;
 struct nds_overlay_entry *overlay;
 struct _tree_node *tmpnode; struct _tree_node *tmpnode2;
 tmpnode = (struct _tree_node *)(malloc(sizeof(tree_node)));
 if(tmpnode == ((void *)0)) return ((void *)0);
 memset(tmpnode->name, 0, sizeof(tmpnode->name));
 strncpy(tmpnode->name, name, sizeof(tmpnode->name) - 1);
 tmpnode->type = 1;
 tmpnode->children = ((void *)0);
 tmpnode->next = ((void *)0);
 tmp = (char *)(malloc(size));
 if(tmp == ((void *)0)) return ((void *)0);
 if(lseek(fd, offset, 0) < 0) return ((void *)0);
 if(read(fd, tmp, size) != size) return ((void *)0);
 overlay = (struct nds_overlay_entry *)(tmp);
 while(overlay < (struct nds_overlay_entry *)(tmp + size))
 {
  tmpnode2 = (struct _tree_node *)(malloc(sizeof(tree_node)));
  if(tmpnode2 == ((void *)0)) return ((void *)0);
  memset(tmpnode2->name, 0, sizeof(tmpnode2->name));
  snprintf(tmpnode2->name, sizeof(tmpnode2->name), "overlay_%08X.bin", overlay->overlayid);
  tmpnode2->type = 0;
  tmpnode2->id = overlay->fileid;
  tmpnode2->children = ((void *)0);
  tmpnode2->next = ((void *)0);
  overlay++;
  if(!tree_add_node(tmpnode, "/", tmpnode2)) return ((void *)0);
 }
 return tmpnode;
}

variable_types: struct nds_overlay_entry { unsigned int overlayid; unsigned int ramaddr; unsigned int ramsize; unsigned int bsssize; unsigned int staticinitstart; unsigned int staticinitend; unsigned int fileid; unsigned int reserved; } *

variable_types: struct _tree_node { char name[128]; unsigned short id; char *virtFileData; unsigned int virtFileSize; int type; struct _tree_node *children; struct _tree_node *next; } *


decompiled_code:
void __fastcall free_nds_file(void *ptr)
{
close(*((_DWORD *)ptr + 5));
free_entire_tree(*(_QWORD *)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
close(*((_DWORD *)ptr + 5));
free_entire_tree(*(_QWORD *)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void free_nds_file(nds_file *file)
{
 close(file->fd);
 free_entire_tree(file->filetree);
 free(file->fat);
 free(file);
}

canonical_original_code:
void free_nds_file(struct nds_file *file)
{
 close(file->fd);
 free_entire_tree(file->filetree);
 free(file->fat);
 free(file);
}

variable_types: struct nds_file { struct _tree_node { char name[128]; unsigned short id; char *virtFileData; unsigned int virtFileSize; int type; struct _tree_node *children; struct _tree_node *next; } *filetree; unsigned int *fat; unsigned int fatsize; int fd; long mtime; } *


OriginHash

repo: magiczhao/devlib

decompiled_code:
__int64 __fastcall OriginHash(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
static inline unsigned int OriginHash(const char* str, unsigned int len)
{
    unsigned int ptr = (unsigned int) str;
    return ptr;
}

canonical_original_code:
static inline unsigned int OriginHash(char *str, unsigned int len)
{
    unsigned int ptr = (unsigned int) str;
    return ptr;
}

variable_types:
str
char *

variable_types:
len
unsigned int

variable_types:
ptr
unsigned int

return_type: unsigned int


comp

decompiled_code:
_BOOL8 __fastcall comp(__int64 a1, int a2, __int64 a3, int a4)
{
return a2 != a4 || a3 != a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, int a2, __int64 a3, int a4)
{
return a2 != a4 || a3 != a1;
}

original_code:
int comp(char* p1, int l1, char* p2, int l2)
{
    if(p1 == p2 && l1 == l2) return 0;
    return 1;
}

canonical_original_code:
int comp(char *p1, int l1, char *p2, int l2)
{
    if(p1 == p2 && l1 == l2) return 0;
    return 1;
}


decompiled_code:
__int64 test_ht_remove()
{
return tcase_fn_start("test_ht_remove", "test_hash_table.c", 43LL);
}

canonical_decompiled_code:
__int64 func2()
{
return tcase_fn_start("test_ht_remove", "test_hash_table.c", 43LL);
}

original_code:
static void test_ht_remove (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_ht_remove", "test_hash_table.c", 43);
{
}
}

canonical_original_code:
static void test_ht_remove(int _i){ tcase_fn_start ("""test_ht_remove", "test_hash_table.c", 43);
{
}
}


decompiled_code:
__int64 test_ht_insert()
{
__int64 i; // rbx
__int64 result; // rax
int *v2; // rax
char *v3; // rax
char v4[8]; // [rsp+8h] [rbp-70h] BYREF
char v5[104]; // [rsp+10h] [rbp-68h] BYREF

tcase_fn_start("test_ht_insert", "test_hash_table.c", 21LL);
dhash_table_init(v5, 0x100000LL, OriginHash, comp);
for ( i = 0LL; i != 100002; i += 3LL )
{
if ( (unsigned int)dhash_table_add(v5, i, 4LL, "this is test") )
{
v2 = _errno_location();
v3 = strerror(*v2);
ck_assert_failed(
"test_hash_table.c",
30LL,
"Assertion 'ret == 0' failed",
"insert hash table failed i=%d, %s",
(unsigned int)i,
v3);
goto LABEL_12;
}
mark_point("test_hash_table.c", 30LL);
}
i = 0LL;
while ( (unsigned int)dhash_table_find(v5, i, 4LL, v4) == 1 )
{
mark_point("test_hash_table.c", 34LL);
i += 3LL;
if ( i == 100002 )
{
i = 1LL;
while ( !(unsigned int)dhash_table_find(v5, i, 4LL, v4) )
{
result = mark_point("test_hash_table.c", 38LL);
i += 3LL;
if ( i == 100000 )
return result;
}
goto LABEL_13;
}
}
LABEL_12:
ck_assert_failed(
"test_hash_table.c",
34LL,
"Assertion 'ret == true' failed",
"find hash table failed i=%d",
(unsigned int)i);
LABEL_13:
ck_assert_failed(
"test_hash_table.c",
38LL,
"Assertion 'ret == false' failed",
"find hash table failed i=%d",
(unsigned int)i);
return test_ht_init();
}

canonical_decompiled_code:
__int64 func3()
{
__int64 i; // rbx
__int64 result; // rax
int *v2; // rax
char *v3; // rax
char v4[8]; // [rsp+8h] [rbp-70h] BYREF
char v5[104]; // [rsp+10h] [rbp-68h] BYREF

tcase_fn_start("test_ht_insert", "test_hash_table.c", 21LL);
dhash_table_init(v5, 0x100000LL, OriginHash, comp);
for ( i = 0LL; i != 100002; i += 3LL )
{
if ( (unsigned int)dhash_table_add(v5, i, 4LL, "this is test") )
{
v2 = _errno_location();
v3 = strerror(*v2);
ck_assert_failed(
"test_hash_table.c",
30LL,
"Assertion 'ret == 0' failed",
"insert hash table failed i=%d, %s",
(unsigned int)i,
v3);
goto LABEL_12;
}
mark_point("test_hash_table.c", 30LL);
}
i = 0LL;
while ( (unsigned int)dhash_table_find(v5, i, 4LL, v4) == 1 )
{
mark_point("test_hash_table.c", 34LL);
i += 3LL;
if ( i == 100002 )
{
i = 1LL;
while ( !(unsigned int)dhash_table_find(v5, i, 4LL, v4) )
{
result = mark_point("test_hash_table.c", 38LL);
i += 3LL;
if ( i == 100000 )
return result;
}
goto LABEL_13;
}
}
LABEL_12:
ck_assert_failed(
"test_hash_table.c",
34LL,
"Assertion 'ret == true' failed",
"find hash table failed i=%d",
(unsigned int)i);
LABEL_13:
ck_assert_failed(
"test_hash_table.c",
38LL,
"Assertion 'ret == false' failed",
"find hash table failed i=%d",
(unsigned int)i);
return func4();
}

original_code:
static void test_ht_insert (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_ht_insert", "test_hash_table.c", 21);
{
    struct dhash_table ht;
    int ret;
    void* value;
    char* buffer = "this is test";
    dhash_table_init(&ht, 1024 * 1024, OriginHash, comp);
    for(int i = 0; i < 100000; i+=3){
        ret = dhash_table_add(&ht, (char*)i, sizeof(i), buffer);
        (ret == 0) ? _mark_point("test_hash_table.c", 30) : _ck_assert_failed("test_hash_table.c", 30, "Assertion '""ret == 0""' failed" , "insert hash table failed i=%d, %s", i, strerror((*__errno_location ())), ((void *)0));
    }
    for(int i = 0; i < 100000; i+= 3){
        ret = dhash_table_find(&ht, (char*)i, sizeof(i), &value);
        (ret == 1) ? _mark_point("test_hash_table.c", 34) : _ck_assert_failed("test_hash_table.c", 34, "Assertion '""ret == true""' failed" , "find hash table failed i=%d", i, ((void *)0));
    }
    for(int i = 1; i < 100000; i+= 3){
        ret = dhash_table_find(&ht, (char*)i, sizeof(i), &value);
        (ret == 0) ? _mark_point("test_hash_table.c", 38) : _ck_assert_failed("test_hash_table.c", 38, "Assertion '""ret == false""' failed" , "find hash table failed i=%d", i, ((void *)0));
    }
}
}

canonical_original_code:
static void test_ht_insert(int _i){ tcase_fn_start ("""test_ht_insert", "test_hash_table.c", 21);
{
    struct dhash_table ht;
    int ret;
    void *value;
    char *buffer = "this is test";
    dhash_table_init(&ht, 1024 * 1024, OriginHash, comp);
    for(int i = 0; i < 100000; i+=3){
        ret = dhash_table_add(&ht, (char *)i, sizeof(i), buffer);
        (ret == 0) ? _mark_point("test_hash_table.c", 30) : _ck_assert_failed("test_hash_table.c", 30, "Assertion '""ret == 0""' failed" , "insert hash table failed i=%d, %s", i, strerror((*__errno_location ())), ((void *)0));
    }
    for(int i = 0; i < 100000; i+= 3){
        ret = dhash_table_find(&ht, (char *)i, sizeof(i), &value);
        (ret == 1) ? _mark_point("test_hash_table.c", 34) : _ck_assert_failed("test_hash_table.c", 34, "Assertion '""ret == true""' failed" , "find hash table failed i=%d", i, ((void *)0));
    }
    for(int i = 1; i < 100000; i+= 3){
        ret = dhash_table_find(&ht, (char *)i, sizeof(i), &value);
        (ret == 0) ? _mark_point("test_hash_table.c", 38) : _ck_assert_failed("test_hash_table.c", 38, "Assertion '""ret == false""' failed" , "find hash table failed i=%d", i, ((void *)0));
    }
}
}

variable_types: struct dhash_table { int capacity; unsigned int (*hash)(char *, unsigned int); int (*compare)(char *, int, char *, int); struct dlist_node { struct dlist_node *prev; struct dlist_node *next; } *buckets; struct fixed_dmem_pool { struct dlist_node head; int item_size; int total_size; char *buffer; char *position; } allocator; }

variable_types:
value
void *

variable_types:
buffer
char *

user_defined_types: struct dhash_table { int capacity; unsigned int (*hash)(char *, unsigned int); int (*compare)(char *, int, char *, int); struct dlist_node *buckets; struct fixed_dmem_pool allocator; }


decompiled_code:
__int64 test_ht_init()
{
__int64 result; // rax
_BYTE v1[88]; // [rsp+0h] [rbp-58h] BYREF

tcase_fn_start("test_ht_init", "test_hash_table.c", 11LL);
if ( (unsigned int)dhash_table_init(v1, 0x100000LL, OriginHash, comp) )
{
ck_assert_failed("test_hash_table.c", 16LL, "Assertion 'ret == 0' failed", "init hash table failed", 0LL);
result = ht_suite();
}
else
{
mark_point("test_hash_table.c", 16LL);
result = dhash_table_fini(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
_BYTE v1[88]; // [rsp+0h] [rbp-58h] BYREF

tcase_fn_start("test_ht_init", "test_hash_table.c", 11LL);
if ( (unsigned int)dhash_table_init(v1, 0x100000LL, OriginHash, comp) )
{
ck_assert_failed("test_hash_table.c", 16LL, "Assertion 'ret == 0' failed", "init hash table failed", 0LL);
result = func5();
}
else
{
mark_point("test_hash_table.c", 16LL);
result = dhash_table_fini(v1);
}
return result;
}

original_code:
static void test_ht_init (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_ht_init", "test_hash_table.c", 11);
{
    struct dhash_table ht;
    int ret;
    ret = dhash_table_init(&ht, 1024 * 1024, OriginHash, comp);
    (ret == 0) ? _mark_point("test_hash_table.c", 16) : _ck_assert_failed("test_hash_table.c", 16, "Assertion '""ret == 0""' failed" , "init hash table failed", ((void *)0));
    dhash_table_fini(&ht);
}
}

canonical_original_code:
static void test_ht_init(int _i){ tcase_fn_start ("""test_ht_init", "test_hash_table.c", 11);
{
    struct dhash_table ht;
    int ret;
    ret = dhash_table_init(&ht, 1024 * 1024, OriginHash, comp);
    (ret == 0) ? _mark_point("test_hash_table.c", 16) : _ck_assert_failed("test_hash_table.c", 16, "Assertion '""ret == 0""' failed" , "init hash table failed", ((void *)0));
    dhash_table_fini(&ht);
}
}

user_defined_types: struct fixed_dmem_pool { struct dlist_node head; int item_size; int total_size; char *buffer; char *position; }

user_defined_types: struct dlist_node { struct dlist_node *prev; struct dlist_node *next; }


RSHash

decompiled_code:
__int64 __fastcall RSHash(char *a1, int a2)
{
char *v2; // rcx
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
v4 = 63689;
do
{
result = (unsigned int)(*a1 + v4 * result);
v4 *= 378551;
++a1;
}
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2)
{
char *v2; // rcx
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
v4 = 63689;
do
{
result = (unsigned int)(*a1 + v4 * result);
v4 *= 378551;
++a1;
}
while ( a1 != v2 );
return result;
}

original_code:
static inline unsigned int RSHash(const char* str, unsigned int len)
{
   unsigned int b = 378551;
   unsigned int a = 63689;
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = hash * a + (*str);
      a = a * b;
   }
   return hash;
}

canonical_original_code:
static inline unsigned int RSHash(char *str, unsigned int len)
{
   unsigned int b = 378551;
   unsigned int a = 63689;
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = hash * a + (*str);
      a = a * b;
   }
   return hash;
}

variable_types:
b
unsigned int

variable_types:
a
unsigned int

variable_types:
hash
unsigned int

variable_types:
i
unsigned int


JSHash

original_code:
static inline unsigned int JSHash(const char* str, unsigned int len)
{
   unsigned int hash = 1315423911;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash ^= ((hash << 5) + (*str) + (hash >> 2));
   }
   return hash;
}

canonical_original_code:
static inline unsigned int JSHash(char *str, unsigned int len)
{
   unsigned int hash = 1315423911;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash ^= ((hash << 5) + (*str) + (hash >> 2));
   }
   return hash;
}


PJWHash

decompiled_code:
__int64 __fastcall PJWHash(char *a1, int a2)
{
char *v2; // rcx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
result = (unsigned int)(*a1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result) & 0xFFFFFFF;
++a1;
}
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
char *v2; // rcx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
result = (unsigned int)(*a1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result) & 0xFFFFFFF;
++a1;
}
while ( a1 != v2 );
return result;
}

original_code:
static inline unsigned int PJWHash(const char* str, unsigned int len)
{
   const unsigned int BitsInUnsignedInt = (unsigned int)(sizeof(unsigned int) * 8);
   const unsigned int ThreeQuarters = (unsigned int)((BitsInUnsignedInt * 3) / 4);
   const unsigned int OneEighth = (unsigned int)(BitsInUnsignedInt / 8);
   const unsigned int HighBits = (unsigned int)(0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth);
   unsigned int hash = 0;
   unsigned int test = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (hash << OneEighth) + (*str);
      if((test = hash & HighBits) != 0)
      {
         hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits));
      }
   }
   return hash;
}

canonical_original_code:
static inline unsigned int PJWHash(char *str, unsigned int len)
{
   unsigned int BitsInUnsignedInt = (unsigned int)(sizeof(unsigned int) * 8);
   unsigned int ThreeQuarters = (unsigned int)((BitsInUnsignedInt * 3) / 4);
   unsigned int OneEighth = (unsigned int)(BitsInUnsignedInt / 8);
   unsigned int HighBits = (unsigned int)(0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth);
   unsigned int hash = 0;
   unsigned int test = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (hash << OneEighth) + (*str);
      if((test = hash & HighBits) != 0)
      {
         hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits));
      }
   }
   return hash;
}

variable_types:
BitsInUnsignedInt
unsigned int

variable_types:
ThreeQuarters
unsigned int

variable_types:
OneEighth
unsigned int

variable_types:
HighBits
unsigned int

variable_types:
test
unsigned int


ELFHash

decompiled_code:
__int64 __fastcall ELFHash(char *a1, int a2)
{
char *v2; // rcx
__int64 result; // rax
int v4; // esi
unsigned int v5; // eax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = 16 * result + *a1;
v5 = v4 & 0xF0000000;
if ( (v4 & 0xF0000000) != 0 )
v4 ^= HIBYTE(v5);
result = v4 & ~v5;
++a1;
}
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int a2)
{
char *v2; // rcx
__int64 result; // rax
int v4; // esi
unsigned int v5; // eax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = 16 * result + *a1;
v5 = v4 & 0xF0000000;
if ( (v4 & 0xF0000000) != 0 )
v4 ^= HIBYTE(v5);
result = v4 & ~v5;
++a1;
}
while ( a1 != v2 );
return result;
}

original_code:
static inline unsigned int ELFHash(const char* str, unsigned int len)
{
   unsigned int hash = 0;
   unsigned int x = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (hash << 4) + (*str);
      if((x = hash & 0xF0000000L) != 0)
      {
         hash ^= (x >> 24);
      }
      hash &= ~x;
   }
   return hash;
}

canonical_original_code:
static inline unsigned int ELFHash(char *str, unsigned int len)
{
   unsigned int hash = 0;
   unsigned int x = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (hash << 4) + (*str);
      if((x = hash & 0xF0000000L) != 0)
      {
         hash ^= (x >> 24);
      }
      hash &= ~x;
   }
   return hash;
}

variable_types:
x
unsigned int


BKDRHash

decompiled_code:
__int64 __fastcall BKDRHash(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = (unsigned int)(*a1++ + 131 * result);
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = (unsigned int)(*a1++ + 131 * result);
while ( a1 != v2 );
return result;
}

original_code:
static inline unsigned int BKDRHash(const char* str, unsigned int len)
{
   unsigned int seed = 131;
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (hash * seed) + (*str);
   }
   return hash;
}

canonical_original_code:
static inline unsigned int BKDRHash(char *str, unsigned int len)
{
   unsigned int seed = 131;
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (hash * seed) + (*str);
   }
   return hash;
}

variable_types:
seed
unsigned int


SDBMHash

decompiled_code:
__int64 __fastcall SDBMHash(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = (unsigned int)(*a1++ + 65599 * result);
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = (unsigned int)(*a1++ + 65599 * result);
while ( a1 != v2 );
return result;
}

original_code:
static inline unsigned int SDBMHash(const char* str, unsigned int len)
{
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (*str) + (hash << 6) + (hash << 16) - hash;
   }
   return hash;
}

canonical_original_code:
static inline unsigned int SDBMHash(char *str, unsigned int len)
{
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = (*str) + (hash << 6) + (hash << 16) - hash;
   }
   return hash;
}

variable_types:
str
char *


DJBHash

decompiled_code:
__int64 __fastcall DJBHash(char *a1, int a2)
{
char *v2; // rsi
unsigned int v3; // edx

if ( !a2 )
return 5381;
v2 = &a1[a2];
v3 = 5381;
do
v3 += *a1++ + 32 * v3;
while ( a1 != v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, int a2)
{
char *v2; // rsi
unsigned int v3; // edx

if ( !a2 )
return 5381;
v2 = &a1[a2];
v3 = 5381;
do
v3 += *a1++ + 32 * v3;
while ( a1 != v2 );
return v3;
}

original_code:
static inline unsigned int DJBHash(const char* str, unsigned int len)
{
   unsigned int hash = 5381;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = ((hash << 5) + hash) + (*str);
   }
   return hash;
}

canonical_original_code:
static inline unsigned int DJBHash(char *str, unsigned int len)
{
   unsigned int hash = 5381;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = ((hash << 5) + hash) + (*str);
   }
   return hash;
}

variable_types:
len
unsigned int


DEKHash

decompiled_code:
__int64 __fastcall DEKHash(char *a1, unsigned int a2)
{
__int64 result; // rax
char *v3; // rdx

result = a2;
if ( a2 )
{
v3 = &a1[a2];
do
result = (unsigned int)*a1++ ^ __ROL4__(result, 5);
while ( a1 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, unsigned int a2)
{
__int64 result; // rax
char *v3; // rdx

result = a2;
if ( a2 )
{
v3 = &a1[a2];
do
result = (unsigned int)*a1++ ^ __ROL4__(result, 5);
while ( a1 != v3 );
}
return result;
}

original_code:
static inline unsigned int DEKHash(const char* str, unsigned int len)
{
   unsigned int hash = len;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = ((hash << 5) ^ (hash >> 27)) ^ (*str);
   }
   return hash;
}

canonical_original_code:
static inline unsigned int DEKHash(char *str, unsigned int len)
{
   unsigned int hash = len;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = ((hash << 5) ^ (hash >> 27)) ^ (*str);
   }
   return hash;
}


BPHash

decompiled_code:
__int64 __fastcall BPHash(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = (unsigned int)*a1++ ^ ((_DWORD)result << 7);
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = (unsigned int)*a1++ ^ ((_DWORD)result << 7);
while ( a1 != v2 );
return result;
}

original_code:
static inline unsigned int BPHash(const char* str, unsigned int len)
{
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = hash << 7 ^ (*str);
   }
   return hash;
}

canonical_original_code:
static inline unsigned int BPHash(char *str, unsigned int len)
{
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash = hash << 7 ^ (*str);
   }
   return hash;
}


FNVHash

decompiled_code:
__int64 __fastcall FNVHash(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = *a1++ ^ (unsigned int)(-2128831035 * result);
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, int a2)
{
char *v2; // rdx
__int64 result; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
result = *a1++ ^ (unsigned int)(-2128831035 * result);
while ( a1 != v2 );
return result;
}

original_code:
static inline unsigned int FNVHash(const char* str, unsigned int len)
{
   const unsigned int fnv_prime = 0x811C9DC5;
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash *= fnv_prime;
      hash ^= (*str);
   }
   return hash;
}

canonical_original_code:
static inline unsigned int FNVHash(char *str, unsigned int len)
{
   unsigned int fnv_prime = 0x811C9DC5;
   unsigned int hash = 0;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash *= fnv_prime;
      hash ^= (*str);
   }
   return hash;
}


APHash

original_code:
static inline unsigned int APHash(const char* str, unsigned int len)
{
   unsigned int hash = 0xAAAAAAAA;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash ^= ((i & 1) == 0) ? ( (hash << 7) ^ (*str) * (hash >> 3)) :
                               (~((hash << 11) + ((*str) ^ (hash >> 5))));
   }
   return hash;
}

canonical_original_code:
static inline unsigned int APHash(char *str, unsigned int len)
{
   unsigned int hash = 0xAAAAAAAA;
   unsigned int i = 0;
   for(i = 0; i < len; str++, i++)
   {
      hash ^= ((i & 1) == 0) ? ( (hash << 7) ^ (*str) * (hash >> 3)) :
                               (~((hash << 11) + ((*str) ^ (hash >> 5))));
   }
   return hash;
}


original_code:
int dbloom_filter_init(struct dbloom_filter* dbf, int capacity, int hash_count)
{
    memcpy(dbf->hash, hfuncs, sizeof(dbf->hash));
    dbf->capacity = capacity;
    dbf->func_count = hash_count < (sizeof(hfuncs) / sizeof(*(hfuncs))) ? hash_count : (sizeof(hfuncs) / sizeof(*(hfuncs)));
    dbf->fail_count = 0;
    dbf->buffer = (char*) malloc((capacity >> 3) + 1);
    if(!dbf->buffer){
        (*__errno_location ()) = 12;
        return -1;
    }
    return 0;
}

canonical_original_code:
int dbloom_filter_init(struct dbloom_filter *dbf, int capacity, int hash_count)
{
    memcpy(dbf->hash, hfuncs, sizeof(dbf->hash));
    dbf->capacity = capacity;
    dbf->func_count = hash_count < (sizeof(hfuncs) / sizeof(*(hfuncs))) ? hash_count : (sizeof(hfuncs) / sizeof(*(hfuncs)));
    dbf->fail_count = 0;
    dbf->buffer = (char *) malloc((capacity >> 3) + 1);
    if(!dbf->buffer){
        (*__errno_location ()) = 12;
        return -1;
    }
    return 0;
}

variable_types: struct dbloom_filter { unsigned int (*hash[-1])(char *, unsigned int); int capacity; int func_count; unsigned int fail_count; char *buffer; } *

variable_types: capacity int


decompiled_code:
void __fastcall dbloom_filter_fini(__int64 a1)
{
free(*(void **)(a1 + 104));
*(_QWORD *)(a1 + 104) = 0LL;
}

original_code:
void dbloom_filter_fini(struct dbloom_filter* dbf)
{
    free(dbf->buffer);
    dbf->buffer = ((void *)0);
}

canonical_original_code:
void dbloom_filter_fini(struct dbloom_filter *dbf)
{
    free(dbf->buffer);
    dbf->buffer = ((void *)0);
}

user_defined_types: struct dbloom_filter { unsigned int (*hash[-1])(char *, unsigned int); int capacity; int func_count; unsigned int fail_count; char *buffer; }


original_code:
int dbloom_filter_find(struct dbloom_filter* dbf, const char* value, unsigned int size)
{
    for(int i = 0; i < dbf->func_count; ++i){
        unsigned int hval = dbf->hash[i](value, size);
        unsigned int hpos = hval % (dbf->capacity);
        int byte = hpos >> 3;
        int bit = hpos - (byte << 3);
        if(!(*((dbf->buffer + byte)) & (1 << bit))){
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int dbloom_filter_find(struct dbloom_filter *dbf, char *value, unsigned int size)
{
    for(int i = 0; i < dbf->func_count; ++i){
        unsigned int hval = dbf->hash[i](value, size);
        unsigned int hpos = hval % (dbf->capacity);
        int byte = hpos >> 3;
        int bit = hpos - (byte << 3);
        if(!(*((dbf->buffer + byte)) & (1 << bit))){
            return 0;
        }
    }
    return 1;
}

variable_types:
value
char *

variable_types:
size
unsigned int

variable_types: i int

variable_types:
hval
unsigned int

variable_types:
hpos
unsigned int

variable_types: byte int

variable_types: bit int


decompiled_code:
__int64 test_fini()
{
tcase_fn_start("test_fini", "test_fixed_alloc.c", 26LL);
return fixed_pool_fini(&pool);
}

canonical_decompiled_code:
__int64 func0()
{
tcase_fn_start("test_fini", "test_fixed_alloc.c", 26LL);
return fixed_pool_fini(&pool);
}

original_code:
static void test_fini (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_fini", "test_fixed_alloc.c", 26);
{
    fixed_pool_fini(&pool);
}
}

canonical_original_code:
static void test_fini(int _i){ tcase_fn_start ("""test_fini", "test_fixed_alloc.c", 26);
{
    fixed_pool_fini(&pool);
}
}


decompiled_code:
char *test_malloc()
{
int v0; // er12
char *v1; // rbx
char *v2; // rbx
char *result; // rax
_BYTE v4[79992]; // [rsp+0h] [rbp-138A8h] BYREF
char v5; // [rsp+13878h] [rbp-30h] BYREF
char v6; // [rsp+13880h] [rbp-28h] BYREF

tcase_fn_start("test_malloc", "test_fixed_alloc.c", 12LL);
v0 = 1000;
do
{
v1 = v4;
do
{
*(_QWORD *)v1 = d_fp_malloc(&pool, 100LL);
v1 += 8;
}
while ( v1 != &v6 );
v2 = &v5;
do
{
d_fp_free(&pool, *(_QWORD *)v2);
result = v2;
v2 -= 8;
}
while ( result != v4 );
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
char *func1()
{
int v0; // er12
char *v1; // rbx
char *v2; // rbx
char *result; // rax
_BYTE v4[79992]; // [rsp+0h] [rbp-138A8h] BYREF
char v5; // [rsp+13878h] [rbp-30h] BYREF
char v6; // [rsp+13880h] [rbp-28h] BYREF

tcase_fn_start("test_malloc", "test_fixed_alloc.c", 12LL);
v0 = 1000;
do
{
v1 = v4;
do
{
*(_QWORD *)v1 = d_fp_malloc(&pool, 100LL);
v1 += 8;
}
while ( v1 != &v6 );
v2 = &v5;
do
{
d_fp_free(&pool, *(_QWORD *)v2);
result = v2;
v2 -= 8;
}
while ( result != v4 );
--v0;
}
while ( v0 );
return result;
}

original_code:
static void test_malloc (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_malloc", "test_fixed_alloc.c", 12);
{
    void* ptr[10000];
    for(int i = 0; i < 1000; ++i){
        for(int j = 0; j < 10000; ++j){
            ptr[j] = d_fp_malloc(&pool, 100);
        }
        for(int j = 9999; j >= 0; --j){
            d_fp_free(&pool, ptr[j]);
        }
    }
}
}

canonical_original_code:
static void test_malloc(int _i){ tcase_fn_start ("""test_malloc", "test_fixed_alloc.c", 12);
{
    void *ptr[10000];
    for(int i = 0; i < 1000; ++i){
        for(int j = 0; j < 10000; ++j){
            ptr[j] = d_fp_malloc(&pool, 100);
        }
        for(int j = 9999; j >= 0; --j){
            d_fp_free(&pool, ptr[j]);
        }
    }
}
}

variable_types: j int


setup

decompiled_code:
__int64 setup()
{
return fixed_pool_init(&pool, 1000000LL, 128LL);
}

canonical_decompiled_code:
__int64 func2()
{
return fixed_pool_init(&pool, 1000000LL, 128LL);
}

original_code:
void setup()
{
    int ret = fixed_pool_init(&pool, 1000000, 128);
}

variable_types: ret int


original_code:
inline int fixed_pool_init(struct fixed_dmem_pool* pool, int capacity, int item_size)
{
    do{ (&(pool->head))->prev = (&(pool->head)); (&(pool->head))->next = (&(pool->head)); }while(0);
    pool->item_size = item_size;
    pool->total_size = (pool->item_size > sizeof(struct dmem_node) ? pool->item_size : sizeof(struct dmem_node)) * capacity;
    pool->buffer = (char*)malloc(pool->total_size);
    pool->position = pool->buffer;
    if(pool->buffer){
        return 0;
    }
    return -1;
}

canonical_original_code:
inline int fixed_pool_init(struct fixed_dmem_pool *pool, int capacity, int item_size)
{
    do{ (&(pool->head))->prev = (&(pool->head)); (&(pool->head))->next = (&(pool->head)); }while(0);
    pool->item_size = item_size;
    pool->total_size = (pool->item_size > sizeof(struct dmem_node) ? pool->item_size : sizeof(struct dmem_node)) * capacity;
    pool->buffer = (char *)malloc(pool->total_size);
    pool->position = pool->buffer;
    if(pool->buffer){
        return 0;
    }
    return -1;
}

variable_types: struct fixed_dmem_pool { struct dlist_node { struct dlist_node *prev; struct dlist_node *next; } head; int item_size; int total_size; char *buffer; char *position; } *

user_defined_types: struct dmem_node { struct dlist_node node; }


original_code:
inline void fixed_pool_fini(struct fixed_dmem_pool* pool)
{
    do{ (&(pool->head))->prev = (&(pool->head)); (&(pool->head))->next = (&(pool->head)); }while(0);
    free(pool->buffer);
    pool->buffer = ((void *)0);
    pool->position = ((void *)0);
    return;
}

canonical_original_code:
inline void fixed_pool_fini(struct fixed_dmem_pool *pool)
{
    do{ (&(pool->head))->prev = (&(pool->head)); (&(pool->head))->next = (&(pool->head)); }while(0);
    free(pool->buffer);
    pool->buffer = ((void *)0);
    pool->position = ((void *)0);
    return;
}


decompiled_code:
__int64 test_del_list()
{
__int64 *i; // rdi
_QWORD *v1; // rax

tcase_fn_start("test_del_list", "test_list.c", 41LL);
for ( i = (__int64 *)*(&ghead + 1); i != &ghead; i = (__int64 *)*(&ghead + 1) )
{
v1 = dlist_del(i);
free(v1);
}
return mark_point("test_list.c", 48LL);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 *i; // rdi
_QWORD *v1; // rax

tcase_fn_start("test_del_list", "test_list.c", 41LL);
for ( i = (__int64 *)*(&ghead + 1); i != &ghead; i = (__int64 *)*(&ghead + 1) )
{
v1 = dlist_del(i);
free(v1);
}
return mark_point("test_list.c", 48LL);
}

original_code:
static void test_del_list (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_del_list", "test_list.c", 41);
{
    while(!((&ghead)->next == (&ghead))){
        struct dlist_node* lnode = dlist_del(ghead.next);
        struct list_int* node = ((struct list_int*)(((char*)lnode) - ((int)(&((struct list_int*)0)->node))));
        free(node);
    }
    (((&ghead)->next == (&ghead))) ? _mark_point("test_list.c", 48) : _ck_assert_failed("test_list.c", 48, "Assertion '""DLIST_EMPTY(&ghead)""' failed" , "list del not empty", ((void *)0));
}
}

canonical_original_code:
static void test_del_list(int _i){ tcase_fn_start ("""test_del_list", "test_list.c", 41);
{
    while(!((&ghead)->next == (&ghead))){
        struct dlist_node *lnode = dlist_del(ghead.next);
        struct list_int *node = ((struct list_int*)(((char*)lnode) - ((int)(&((struct list_int*)0)->node))));
        free(node);
    }
    (((&ghead)->next == (&ghead))) ? _mark_point("test_list.c", 48) : _ck_assert_failed("test_list.c", 48, "Assertion '""DLIST_EMPTY(&ghead)""' failed" , "list del not empty", ((void *)0));
}
}

variable_types: struct dlist_node { struct dlist_node *prev; struct dlist_node *next; } *

variable_types: struct list_int { struct dlist_node { struct dlist_node *prev; struct dlist_node *next; } node; int value; } *

user_defined_types: struct list_int { struct dlist_node node; int value; }


decompiled_code:
__int64 test_init_list()
{
tcase_fn_start("test_init_list", "test_list.c", 16LL);
return mark_point("test_list.c", 20LL);
}

canonical_decompiled_code:
__int64 func1()
{
tcase_fn_start("test_init_list", "test_list.c", 16LL);
return mark_point("test_list.c", 20LL);
}

original_code:
static void test_init_list (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_init_list", "test_list.c", 16);
{
    struct dlist_node head;
    do{ (&head)->prev = (&head); (&head)->next = (&head); }while(0);
    (((&head)->next == (&head))) ? _mark_point("test_list.c", 20) : _ck_assert_failed("test_list.c", 20, "Assertion '""DLIST_EMPTY(&head)""' failed" , "list init failed!", ((void *)0));
}
}

canonical_original_code:
static void test_init_list(int _i){ tcase_fn_start ("""test_init_list", "test_list.c", 16);
{
    struct dlist_node head;
    do{ (&head)->prev = (&head); (&head)->next = (&head); }while(0);
    (((&head)->next == (&head))) ? _mark_point("test_list.c", 20) : _ck_assert_failed("test_list.c", 20, "Assertion '""DLIST_EMPTY(&head)""' failed" , "list init failed!", ((void *)0));
}
}

variable_types: struct dlist_node { struct dlist_node *prev; struct dlist_node *next; }


decompiled_code:
_QWORD *test_add_list()
{
int i; // ebx
_DWORD *v1; // rax
_QWORD *result; // rax
__int64 v3; // rbx
unsigned int j; // ebp

tcase_fn_start("test_add_list", "test_list.c", 24LL);
for ( i = 0; i != 10000000; ++i )
{
v1 = malloc(0x18uLL);
v1[4] = i;
result = dlist_add((__int64)&ghead, v1);
}
v3 = *(&ghead + 1);
if ( (__int64 *)v3 != &ghead )
{
for ( j = 9999999; *(_DWORD *)(v3 + 16) == j; --j )
{
result = (_QWORD *)mark_point("test_list.c", 35LL);
v3 = *(_QWORD *)(v3 + 8);
if ( (__int64 *)v3 == &ghead )
return result;
}
ck_assert_failed(
"test_list.c",
35LL,
"Assertion 'value == node->value' failed",
"value failed, expected:%d, value:%d",
j);
result = (_QWORD *)setup();
}
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
int i; // ebx
_DWORD *v1; // rax
_QWORD *result; // rax
__int64 v3; // rbx
unsigned int j; // ebp

tcase_fn_start("test_add_list", "test_list.c", 24LL);
for ( i = 0; i != 10000000; ++i )
{
v1 = malloc(0x18uLL);
v1[4] = i;
result = dlist_add((__int64)&ghead, v1);
}
v3 = *(&ghead + 1);
if ( (__int64 *)v3 != &ghead )
{
for ( j = 9999999; *(_DWORD *)(v3 + 16) == j; --j )
{
result = (_QWORD *)mark_point("test_list.c", 35LL);
v3 = *(_QWORD *)(v3 + 8);
if ( (__int64 *)v3 == &ghead )
return result;
}
ck_assert_failed(
"test_list.c",
35LL,
"Assertion 'value == node->value' failed",
"value failed, expected:%d, value:%d",
j);
result = (_QWORD *)func3();
}
return result;
}

original_code:
static void test_add_list (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_add_list", "test_list.c", 24);
{
    for(int i = 0; i < 10000000; ++i){
        struct list_int* node = (struct list_int*)malloc(sizeof(struct list_int));
        node->value = i;
        dlist_add(&ghead, &node->node);
    }
    struct dlist_node* n;
    int value = 10000000 - 1;
    for(n = (&ghead)->next; n != (&ghead); n = n->next){
        struct list_int* node = ((struct list_int*)(((char*)n) - ((int)(&((struct list_int*)0)->node))));
        (value == node->value) ? _mark_point("test_list.c", 35) : _ck_assert_failed("test_list.c", 35, "Assertion '""value == node->value""' failed" , "value failed, expected:%d, value:%d", value, node->value, ((void *)0));
        value -= 1;
    }
}
}

canonical_original_code:
static void test_add_list(int _i){ tcase_fn_start ("""test_add_list", "test_list.c", 24);
{
    for(int i = 0; i < 10000000; ++i){
        struct list_int *node = (struct list_int*)malloc(sizeof(struct list_int));
        node->value = i;
        dlist_add(&ghead, &node->node);
    }
    struct dlist_node *n;
    int value = 10000000 - 1;
    for(n = (&ghead)->next; n != (&ghead); n = n->next){
        struct list_int *node = ((struct list_int*)(((char*)n) - ((int)(&((struct list_int*)0)->node))));
        (value == node->value) ? _mark_point("test_list.c", 35) : _ck_assert_failed("test_list.c", 35, "Assertion '""value == node->value""' failed" , "value failed, expected:%d, value:%d", value, node->value, ((void *)0));
        value -= 1;
    }
}
}

variable_types: value int


teardown

decompiled_code:
__int64 teardown()
{
return dbloom_filter_fini(&gbfilter);
}

canonical_decompiled_code:
__int64 func1()
{
return dbloom_filter_fini(&gbfilter);
}

original_code:
void teardown(void)
{
    dbloom_filter_fini(&gbfilter);
}

canonical_original_code:
void teardown()
{
    dbloom_filter_fini(&gbfilter);
}