fdfind

repo: Siriuscoder/nanokernel

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

if ( (unsigned int)qword_368 <= a1 )
result = 0LL;
else
result = *(_QWORD *)(fdt + 8LL * a1);
return result;
}

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

if ( (unsigned int)qword_368 <= a1 )
result = 0LL;
else
result = *(_QWORD *)(fdt + 8LL * a1);
return result;
}

original_code:
static file_t *fdfind(uint32_t fd)
{
 if(fd >= fdt.fdlen)
  return ((ptr_t)0x0);
 return fdt.fdarray[fd];
}

canonical_original_code:
static struct file_t *fdfind(unsigned int fd)
{
 if(fd >= fdt.fdlen)
  return ((void *)0x0);
 return fdt.fdarray[fd];
}

variable_types:
fd
unsigned int

return_type: struct file_t { char name[50]; unsigned int flags; unsigned int fd; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); void *internal; struct list_link { unsigned int poison; struct list { struct list_link l; } *list; struct list_link *next; } l; } *

user_defined_types: struct file_t { char name[50]; unsigned int flags; unsigned int fd; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); void *internal; struct list_link l; }

user_defined_types: struct list_link { unsigned int poison; struct list *list; struct list_link *next; }


decompiled_code:
__int64 fdfind_first()
{
__int64 v0; // rax

if ( (unsigned int)qword_368 <= 1 )
return 0LL;
v0 = 1LL;
while ( *(_QWORD *)(fdt + 8 * v0) )
{
if ( ++v0 == (unsigned int)qword_368 )
return 0LL;
}
HIDWORD(qword_368) = v0;
return 1LL;
}

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

if ( (unsigned int)qword_368 <= 1 )
return 0LL;
v0 = 1LL;
while ( *(_QWORD *)(fdt + 8 * v0) )
{
if ( ++v0 == (unsigned int)qword_368 )
return 0LL;
}
HIDWORD(qword_368) = v0;
return 1LL;
}

original_code:
static bool fdfind_first()
{
 int i = 1;
 for(; i < fdt.fdlen; i++)
 {
  if(fdt.fdarray[i] == ((ptr_t)0x0))
  {
   fdt.fdcounter = i;
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
static int fdfind_first()
{
 int i = 1;
 for(; i < fdt.fdlen; i++)
 {
  if(fdt.fdarray[i] == ((void *)0x0))
  {
   fdt.fdcounter = i;
   return 1;
  }
 }
 return 0;
}

variable_types: i int

return_type: int


fdexpand

decompiled_code:
__int64 fdexpand()
{
__int64 result; // rax
__int64 v1; // rax

if ( fdt )
{
fdt = k_realloc(fdt, 8LL * (unsigned int)(qword_368 + 100));
if ( fdt )
{
LODWORD(qword_368) = qword_368 + 100;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
v1 = k_malloc(800LL);
LODWORD(qword_368) = 100;
fdt = v1;
result = 1LL;
}
return result;
}

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

if ( fdt )
{
fdt = k_realloc(fdt, 8LL * (unsigned int)(qword_368 + 100));
if ( fdt )
{
LODWORD(qword_368) = qword_368 + 100;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
v1 = k_malloc(800LL);
LODWORD(qword_368) = 100;
fdt = v1;
result = 1LL;
}
return result;
}

original_code:
static bool fdexpand()
{
 if(fdt.fdarray == ((ptr_t)0x0))
 {
  fdt.fdarray = k_malloc(sizeof(ptr_t) * 100);
  fdt.fdlen = 100;
  return 1;
 }
 fdt.fdarray = k_realloc(fdt.fdarray, sizeof(ptr_t) * (fdt.fdlen + 100));
 if(fdt.fdarray == ((ptr_t)0x0))
  return 0;
 fdt.fdlen += 100;
 return 1;
}

canonical_original_code:
static int fdexpand()
{
 if(fdt.fdarray == ((void *)0x0))
 {
  fdt.fdarray = k_malloc(sizeof(ptr_t) * 100);
  fdt.fdlen = 100;
  return 1;
 }
 fdt.fdarray = k_realloc(fdt.fdarray, sizeof(ptr_t) * (fdt.fdlen + 100));
 if(fdt.fdarray == ((void *)0x0))
  return 0;
 fdt.fdlen += 100;
 return 1;
}


fdcheck

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

while ( !(unsigned int)fdfind_first() )
{
result = fdexpand();
if ( !(_DWORD)result )
return result;
}
return 1LL;
}

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

while ( !(unsigned int)func1() )
{
result = func2();
if ( !(_DWORD)result )
return result;
}
return 1LL;
}

original_code:
static bool fdcheck()
{
 if(!fdfind_first())
 {
  if(fdexpand())
  {
   return fdcheck();
  }
  return 0;
 }
 return 1;
}

canonical_original_code:
static int fdcheck()
{
 if(!fdfind_first())
 {
  if(fdexpand())
  {
   return fdcheck();
  }
  return 0;
 }
 return 1;
}


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

fdt = 0LL;
result = 1LL;
qword_368 = 0LL;
return result;
}

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

fdt = 0LL;
result = 1LL;
qword_368 = 0LL;
return result;
}

original_code:
bool k_finit()
{
 fdt.fdarray = ((ptr_t)0x0);
 fdt.fdlen = 0;
 fdt.fdcounter = 0;
 return 1;
}

canonical_original_code:
int k_finit()
{
 fdt.fdarray = ((void *)0x0);
 fdt.fdlen = 0;
 fdt.fdcounter = 0;
 return 1;
}


decompiled_code:
__int64 __fastcall k_fopen(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 (__fastcall *v3)(__int64, _QWORD, __int64); // rax
__int64 result; // rax

v2 = k_malloc(152LL);
k_memset(v2, 0LL, 152LL);
if ( !v2 )
return 0LL;
if ( ((a2 & 1) == 0 || k_vfs_open_file(v2, a1, a2))
&& (v3 = *(__int64 (__fastcall **)(__int64, _QWORD, __int64))(v2 + 64)) != 0LL
&& v3(a1, a2, v2)
&& (*(_DWORD *)(v2 + 52) = a2, (unsigned int)fdcheck()) )
{
result = HIDWORD(qword_368);
*(_QWORD *)(fdt + 8LL * HIDWORD(qword_368)) = v2;
*(_DWORD *)(v2 + 56) = result;
}
else
{
k_free(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 (__fastcall *v3)(__int64, _QWORD, __int64); // rax
__int64 result; // rax

v2 = k_malloc(152LL);
k_memset(v2, 0LL, 152LL);
if ( !v2 )
return 0LL;
if ( ((a2 & 1) == 0 || k_vfs_open_file(v2, a1, a2))
&& (v3 = *(__int64 (__fastcall **)(__int64, _QWORD, __int64))(v2 + 64)) != 0LL
&& v3(a1, a2, v2)
&& (*(_DWORD *)(v2 + 52) = a2, (unsigned int)func3()) )
{
result = HIDWORD(qword_368);
*(_QWORD *)(fdt + 8LL * HIDWORD(qword_368)) = v2;
*(_DWORD *)(v2 + 56) = result;
}
else
{
k_free(v2);
result = 0LL;
}
return result;
}

original_code:
uint32_t k_fopen(const char *path, uint32_t mode)
{
 file_t *file = ((ptr_t)0x0);
 file = k_malloc(sizeof(file_t));
 k_memset(file, 0, sizeof(file_t));
 if(!file)
  return 0;
 if(mode & (1))
 {
  if(!k_vfs_open_file(file, path, mode))
   goto failed;
 }
 if(!file->open)
  goto failed;
 if(!file->open(path, mode, file))
  goto failed;
 file->flags = mode;
 if(!fdcheck())
  goto failed;
 fdt.fdarray[fdt.fdcounter] = file;
 file->fd = fdt.fdcounter;
 return fdt.fdcounter;
failed:
 k_free(file);
 return 0;
}

canonical_original_code:
unsigned int k_fopen(char *path, unsigned int mode)
{
 struct file_t *file = ((ptr_t)0x0);
 file = k_malloc(sizeof(file_t));
 k_memset(file, 0, sizeof(file_t));
 if(!file)
  return 0;
 if(mode & (1))
 {
  if(!k_vfs_open_file(file, path, mode))
   goto failed;
 }
 if(!file->open)
  goto failed;
 if(!file->open(path, mode, file))
  goto failed;
 file->flags = mode;
 if(!fdcheck())
  goto failed;
 fdt.fdarray[fdt.fdcounter] = file;
 file->fd = fdt.fdcounter;
 return fdt.fdcounter;
failed:
 k_free(file);
 return 0;
}

variable_types:
path
char *

variable_types:
mode
unsigned int

variable_types: struct file_t { char name[50]; unsigned int flags; unsigned int fd; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); void *internal; struct list_link { unsigned int poison; struct list { struct list_link l; } *list; struct list_link *next; } l; } *

return_type: unsigned int


decompiled_code:
__int64 __fastcall k_fclose(unsigned int a1)
{
__int64 v1; // rbp
__int64 result; // rax
void (__fastcall *v3)(__int64); // rax

v1 = fdfind(a1);
result = 0LL;
if ( v1 )
{
v3 = *(void (__fastcall **)(__int64))(v1 + 72);
if ( v3 )
v3(v1);
k_vfs_close_file(v1);
k_free(v1);
*(_QWORD *)(fdt + 8LL * a1) = 0LL;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 v1; // rbp
__int64 result; // rax
void (__fastcall *v3)(__int64); // rax

v1 = func0(a1);
result = 0LL;
if ( v1 )
{
v3 = *(void (__fastcall **)(__int64))(v1 + 72);
if ( v3 )
v3(v1);
k_vfs_close_file(v1);
k_free(v1);
*(_QWORD *)(fdt + 8LL * a1) = 0LL;
result = 1LL;
}
return result;
}

original_code:
bool k_fclose(uint32_t fd)
{
 file_t *file = ((ptr_t)0x0);
 if( (file = fdfind(fd)) != ((ptr_t)0x0))
 {
  if(file->close)
   file->close(file);
  k_vfs_close_file(file);
  k_free(file);
  fdt.fdarray[fd] = ((ptr_t)0x0);
  return 1;
 }
 return 0;
}

canonical_original_code:
int k_fclose(unsigned int fd)
{
 struct file_t *file = ((ptr_t)0x0);
 if( (file = fdfind(fd)) != ((void *)0x0))
 {
  if(file->close)
   file->close(file);
  k_vfs_close_file(file);
  k_free(file);
  fdt.fdarray[fd] = ((void *)0x0);
  return 1;
 }
 return 0;
}


original_code:
long k_fread(uint32_t fd, ptr_t buf, size_t size, size_t count)
{
 file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((ptr_t)0x0))
 {
  if(file->read && (file->flags & (1<<3)))
   return file->read(buf, size, count, file);
 }
 return -1;
}

canonical_original_code:
long k_fread(unsigned int fd, void *buf, unsigned long size, unsigned long count)
{
 struct file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((void *)0x0))
 {
  if(file->read && (file->flags & (1<<3)))
   return file->read(buf, size, count, file);
 }
 return -1;
}

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types:
count
unsigned long

return_type: long


original_code:
long k_fwrite(uint32_t fd, const ptr_t buf, size_t size, size_t count)
{
 file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((ptr_t)0x0))
 {
  if(file->write && (file->flags & (1<<2)))
   return file->write(buf, size, count, file);
 }
 return -1;
}

canonical_original_code:
long k_fwrite(unsigned int fd, void *buf, unsigned long size, unsigned long count)
{
 struct file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((void *)0x0))
 {
  if(file->write && (file->flags & (1<<2)))
   return file->write(buf, size, count, file);
 }
 return -1;
}


decompiled_code:
__int64 __fastcall k_fseek(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
unsigned int v3; // edx
__int64 v5; // rsi
__int64 v6; // rdx
__int64 (__fastcall *v7)(_QWORD, __int64, __int64); // rax
__int64 result; // rax

v2 = fdfind(a1);
if ( v2 && (v5 = v3, v6 = v2, (v7 = *(__int64 (__fastcall **)(_QWORD, __int64, __int64))(v2 + 96)) != 0LL) )
result = v7(a2, v5, v6);
else
result = -1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
unsigned int v3; // edx
__int64 v5; // rsi
__int64 v6; // rdx
__int64 (__fastcall *v7)(_QWORD, __int64, __int64); // rax
__int64 result; // rax

v2 = func0(a1);
if ( v2 && (v5 = v3, v6 = v2, (v7 = *(__int64 (__fastcall **)(_QWORD, __int64, __int64))(v2 + 96)) != 0LL) )
result = v7(a2, v5, v6);
else
result = -1LL;
return result;
}

original_code:
long k_fseek(uint32_t fd, uint32_t offset, uint32_t whence)
{
 file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((ptr_t)0x0))
 {
  if(file->seek)
   return file->seek(offset, whence, file);
 }
 return -1;
}

canonical_original_code:
long k_fseek(unsigned int fd, unsigned int offset, unsigned int whence)
{
 struct file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((void *)0x0))
 {
  if(file->seek)
   return file->seek(offset, whence, file);
 }
 return -1;
}

variable_types:
offset
unsigned int

variable_types:
whence
unsigned int


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

result = fdfind(a1);
if ( result )
result = (*(__int64 (__fastcall **)(__int64))(result + 104))(result);
return result;
}

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

result = func0(a1);
if ( result )
result = (*(__int64 (__fastcall **)(__int64))(result + 104))(result);
return result;
}

original_code:
void k_fflush(uint32_t fd)
{
 file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((ptr_t)0x0))
  file->flush(file);
}

canonical_original_code:
void k_fflush(unsigned int fd)
{
 struct file_t *file = ((ptr_t)0x0);
 if((file = fdfind(fd)) != ((void *)0x0))
  file->flush(file);
}

return_type: void


decompiled_code:
__int64 __fastcall iterate_file_node_in_list(__int64 a1, __int64 a2)
{
if ( *(_QWORD *)a2 )
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))a2)(
a1 - 184,
*(unsigned int *)(a1 - 184 + 104),
*(_QWORD *)(a2 + 8));
return 0LL;
}

original_code:
static bool iterate_file_node_in_list(struct list_link *link, void *arg)
{
 iterate_helper_t *itHelper = (iterate_helper_t *)arg;
 struct tree_link *cur = ((struct tree_link*)((size_t)link - ( (size_t) &((struct tree_link*)0x0)->listLink )));
 fsnode_t *curNode = ((fsnode_t*)((size_t)cur - ( (size_t) &((fsnode_t*)0x0)->link )));
 if(itHelper->callback)
  itHelper->callback(curNode->node.name, curNode->flags,
    itHelper->arg);
 return 0;
}

canonical_original_code:
static int iterate_file_node_in_list(struct list_link *link, void *arg)
{
 struct iterate_helper_t *itHelper = (iterate_helper_t *)arg;
 struct tree_link *cur = ((struct tree_link*)((size_t)link - ( (size_t) &((struct tree_link*)0x0)->listLink )));
 struct fsnode_t *curNode = ((fsnode_t*)((size_t)cur - ( (size_t) &((fsnode_t*)0x0)->link )));
 if(itHelper->callback)
  itHelper->callback(curNode->node.name, curNode->flags,
    itHelper->arg);
 return 0;
}

variable_types: struct list_link { unsigned int poison; struct list { struct list_link l; } *list; struct list_link *next; } *

variable_types:
arg
void *

variable_types: struct iterate_helper_t { void (*callback)(char *name, unsigned int flags, void *arg); void *arg; } *

variable_types: struct tree_link { struct tree_link *par; struct list { struct list_link { unsigned int poison; struct list *list; struct list_link *next; } l; } children; struct list_link listLink; } *

variable_types: struct fsnode_t { struct node_t { char name[50]; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); } node; unsigned int flags; struct list { struct list_link { unsigned int poison; struct list *list; struct list_link *next; } l; } openFiles; struct tree_link { struct tree_link *par; struct list children; struct list_link listLink; } link; } *

user_defined_types: struct fsnode_t { struct node_t node; unsigned int flags; struct list openFiles; struct tree_link link; }


decompiled_code:
__int64 __fastcall k_vfs_find_node_by_full_path(__int64 a1)
{
char *v1; // rbp
_BYTE *v2; // r12
__int64 result; // rax
_BYTE *v4; // rax
_BYTE *v5; // rbx
_BYTE v6[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = (char *)&unk_5D0;
v2 = v6;
k_strncpy(v6, a1, 255LL);
k_strncat(v6, &unk_618, 255LL);
while ( 1 )
{
v4 = (_BYTE *)k_strchr(v2, 47LL);
v5 = v4;
if ( !v4 )
break;
*v4 = 0;
if ( k_strlen(v2) )
{
result = list_find_arg(v1 + 8, find_file_node_in_list, v2);
if ( !result )
return result;
v1 = (char *)(result - 40);
}
v2 = v5 + 1;
}
return (__int64)(v1 - 144);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v1; // rbp
_BYTE *v2; // r12
__int64 result; // rax
_BYTE *v4; // rax
_BYTE *v5; // rbx
_BYTE v6[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = (char *)&unk_5D0;
v2 = v6;
k_strncpy(v6, a1, 255LL);
k_strncat(v6, &unk_618, 255LL);
while ( 1 )
{
v4 = (_BYTE *)k_strchr(v2, 47LL);
v5 = v4;
if ( !v4 )
break;
*v4 = 0;
if ( k_strlen(v2) )
{
result = list_find_arg(v1 + 8, find_file_node_in_list, v2);
if ( !result )
return result;
v1 = (char *)(result - 40);
}
v2 = v5 + 1;
}
return (__int64)(v1 - 144);
}

original_code:
static fsnode_t *k_vfs_find_node_by_full_path(const char *path)
{
 char tmp[255];
 char *ps = tmp;
 struct tree_link *searchTreeNode = &vfs_root.link;
 struct list_link *searchLink;
 k_strncpy(tmp, path, 255);
 k_strncat(tmp, "/", 255);
 while(1)
 {
  char *s = k_strchr(ps, '/');
  if(s == ((ptr_t)0x0))
   break;
  *s = 0;
  if(k_strlen(ps) == 0)
   goto to_next;
  searchLink = list_find_arg(&searchTreeNode->children, find_file_node_in_list, ps);
  if(!searchLink)
   return ((ptr_t)0x0);
  searchTreeNode = ((struct tree_link*)((size_t)searchLink - ( (size_t) &((struct tree_link*)0x0)->listLink )));
to_next:
  ps = s+1;
 }
 return ((fsnode_t*)((size_t)searchTreeNode - ( (size_t) &((fsnode_t*)0x0)->link )));
}

canonical_original_code:
static struct fsnode_t *k_vfs_find_node_by_full_path(char *path)
{
 char tmp[255];
 char *ps = tmp;
 struct tree_link *searchTreeNode = &vfs_root.link;
 struct list_link *searchLink;
 k_strncpy(tmp, path, 255);
 k_strncat(tmp, "/", 255);
 while(1)
 {
  char *s = k_strchr(ps, '/');
  if(s == ((void *)0x0))
   break;
  *s = 0;
  if(k_strlen(ps) == 0)
   goto to_next;
  searchLink = list_find_arg(&searchTreeNode->children, find_file_node_in_list, ps);
  if(!searchLink)
   return ((void *)0x0);
  searchTreeNode = ((struct tree_link *)((unsigned long)searchLink - ( (unsigned long) &((struct tree_link *)0x0)->listLink )));
to_next:
  ps = s+1;
 }
 return ((struct fsnode_t *)((unsigned long)searchTreeNode - ( (unsigned long) &((struct fsnode_t *)0x0)->link )));
}

variable_types:
tmp
char [255]

variable_types:
ps
char *

variable_types:
s
char *

return_type: struct fsnode_t { struct node_t { char name[50]; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); } node; unsigned int flags; struct list { struct list_link { unsigned int poison; struct list *list; struct list_link *next; } l; } openFiles; struct tree_link { struct tree_link *par; struct list children; struct list_link listLink; } link; } *


decompiled_code:
_BOOL8 __fastcall find_file_node_in_list(__int64 a1)
{
return (unsigned int)k_strcmp(a1 - 184) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return (unsigned int)k_strcmp(a1 - 184) == 0;
}

original_code:
static bool find_file_node_in_list(struct list_link *link, void *arg)
{
 struct tree_link *cur = ((struct tree_link*)((size_t)link - ( (size_t) &((struct tree_link*)0x0)->listLink )));
 fsnode_t *curNode = ((fsnode_t*)((size_t)cur - ( (size_t) &((fsnode_t*)0x0)->link )));
 if(k_strcmp(curNode->node.name, (char *)arg) == 0)
  return 1;
 return 0;
}

canonical_original_code:
static int find_file_node_in_list(struct list_link *link, void *arg)
{
 struct tree_link *cur = ((struct tree_link*)((size_t)link - ( (size_t) &((struct tree_link*)0x0)->listLink )));
 struct fsnode_t *curNode = ((fsnode_t*)((size_t)cur - ( (size_t) &((fsnode_t*)0x0)->link )));
 if(k_strcmp(curNode->node.name, (char *)arg) == 0)
  return 1;
 return 0;
}

user_defined_types: struct tree_link { struct tree_link *par; struct list children; struct list_link listLink; }

user_defined_types: struct node_t { char name[50]; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); }


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

k_memset(&vfs_root, 0LL, 216LL);
tree_link_init(&unk_5D0);
vfs_root = 47;
result = 1LL;
dword_5A8 = 1;
return result;
}

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

k_memset(&vfs_root, 0LL, 216LL);
tree_link_init(&unk_5D0);
vfs_root = 47;
result = 1LL;
dword_5A8 = 1;
return result;
}

original_code:
bool k_vfs_init()
{
 k_memset(&vfs_root, 0, sizeof(fsnode_t));
 tree_link_init(&vfs_root.link);
 vfs_root.flags = (1);
 vfs_root.node.name[0] = '/';
 return 1;
}

canonical_original_code:
int k_vfs_init()
{
 k_memset(&vfs_root, 0, sizeof(fsnode_t));
 tree_link_init(&vfs_root.link);
 vfs_root.flags = (1);
 vfs_root.node.name[0] = '/';
 return 1;
}


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

list_unlink_link(a1 + 120);
list_link_init(a1 + 120);
v1 = *(void (__fastcall **)(__int64))(a1 + 104);
if ( v1 )
v1(a1);
return a1;
}

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

list_unlink_link(a1 + 120);
list_link_init(a1 + 120);
v1 = *(void (__fastcall **)(__int64))(a1 + 104);
if ( v1 )
v1(a1);
return a1;
}

original_code:
file_t *k_vfs_close_file(file_t *file)
{
 list_unlink_link(&file->l);
 list_link_init(&file->l);
 if(file->flush)
  file->flush(file);
 return file;
}

canonical_original_code:
struct file_t *k_vfs_close_file(struct file_t *file)
{
 list_unlink_link(&file->l);
 list_link_init(&file->l);
 if(file->flush)
  file->flush(file);
 return file;
}

variable_types:
file
struct file_t *


decompiled_code:
__int64 __fastcall k_vfs_rmnode(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = k_vfs_find_node_by_full_path(a1);
if ( !v1 )
return 0LL;
v2 = v1;
if ( !(unsigned int)list_is_empty(v1 + 152) )
return 0LL;
tree_unlink_link(v2 + 144);
k_free(v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = func1(a1);
if ( !v1 )
return 0LL;
v2 = v1;
if ( !(unsigned int)list_is_empty(v1 + 152) )
return 0LL;
tree_unlink_link(v2 + 144);
k_free(v2);
return 1LL;
}

original_code:
bool k_vfs_rmnode(const char *path)
{
 fsnode_t *fsNode;
 if((fsNode = k_vfs_find_node_by_full_path(path)) == ((ptr_t)0x0))
  return 0;
 if(!list_is_empty(&fsNode->link.children))
  return 0;
 tree_unlink_link(&fsNode->link);
 k_free(fsNode);
 return 1;
}

canonical_original_code:
int k_vfs_rmnode(char *path)
{
 struct fsnode_t *fsNode;
 if((fsNode = k_vfs_find_node_by_full_path(path)) == ((void *)0x0))
  return 0;
 if(!list_is_empty(&fsNode->link.children))
  return 0;
 tree_unlink_link(&fsNode->link);
 k_free(fsNode);
 return 1;
}

variable_types:
path
char *


decompiled_code:
// attributes: thunk
__int64 __fastcall k_vfs_rmdir(__int64 a1)
{
return k_vfs_rmnode(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return func5(a1);
}

original_code:
bool k_vfs_rmdir(const char *path)
{
 return k_vfs_rmnode(path);
}

canonical_original_code:
int k_vfs_rmdir(char *path)
{
 return k_vfs_rmnode(path);
}


decompiled_code:
__int64 __fastcall k_vfs_mvnode(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rbp

v2 = k_vfs_find_node_by_full_path(a1);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = k_vfs_find_node_by_full_path(a2);
v5 = v4;
if ( !v4 || list_find_arg(v4 + 152, find_file_node_in_list, v3) )
return 0LL;
tree_move_link(v5 + 144, v3 + 144);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rbp

v2 = func1(a1);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = func1(a2);
v5 = v4;
if ( !v4 || list_find_arg(v4 + 152, find_file_node_in_list, v3) )
return 0LL;
tree_move_link(v5 + 144, v3 + 144);
return 1LL;
}

original_code:
bool k_vfs_mvnode(const char *path, const char *newPath)
{
 fsnode_t *fsNode, *dstNode;
 if((fsNode = k_vfs_find_node_by_full_path(path)) == ((ptr_t)0x0))
  return 0;
 if((dstNode = k_vfs_find_node_by_full_path(newPath)) == ((ptr_t)0x0))
  return 0;
 if(list_find_arg(&dstNode->link.children,
  find_file_node_in_list, fsNode->node.name))
  return 0;
 tree_move_link(&dstNode->link, &fsNode->link);
 return 1;
}

canonical_original_code:
int k_vfs_mvnode(char *path, char *newPath)
{
 struct fsnode_t *fsNode; struct fsnode_t *dstNode;
 if((fsNode = k_vfs_find_node_by_full_path(path)) == ((void *)0x0))
  return 0;
 if((dstNode = k_vfs_find_node_by_full_path(newPath)) == ((void *)0x0))
  return 0;
 if(list_find_arg(&dstNode->link.children,
  find_file_node_in_list, fsNode->node.name))
  return 0;
 tree_move_link(&dstNode->link, &fsNode->link);
 return 1;
}

variable_types:
newPath
char *


decompiled_code:
_BOOL8 __fastcall k_vfs_path_is_exist(__int64 a1)
{
return k_vfs_find_node_by_full_path(a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1)
{
return func1(a1) != 0;
}

original_code:
bool k_vfs_path_is_exist(const char *path)
{
 return k_vfs_find_node_by_full_path(path) != ((ptr_t)0x0);
}

canonical_original_code:
int k_vfs_path_is_exist(char *path)
{
 return k_vfs_find_node_by_full_path(path) != ((void *)0x0);
}


original_code:
bool k_vfs_mknode(const char *path, const node_t *node, uint32_t flags)
{
    fsnode_t *fsNode, *dstNode;
    char fullName[255] = { '\0' };
 if(!k_strlen(path) || !k_strlen(node->name))
  return 0;
 fsNode = k_malloc(sizeof(fsnode_t));
 if(!fsNode)
  goto failed_exit;
 k_memset(fsNode, 0, sizeof(fsnode_t));
 tree_link_init(&fsNode->link);
 list_init(&fsNode->openFiles);
 fsNode->node = *node;
 fsNode->flags = flags;
 if((dstNode = k_vfs_find_node_by_full_path(path)) == ((ptr_t)0x0))
  goto failed;
 if(!(dstNode->flags & (1)))
  goto failed;
 k_strncat(fullName, path, 255);
 if(path[k_strlen(path)-1] != '/')
  k_strncat(fullName, "/", 255);
 k_strncat(fullName, node->name, 255);
 if(k_vfs_path_is_exist(fullName))
  goto failed;
 tree_add_link(&dstNode->link, &fsNode->link);
 return 1;
failed:
 k_free(fsNode);
failed_exit:
 return 0;
}

canonical_original_code:
int k_vfs_mknode(char *path, struct node_t *node, unsigned int flags)
{
    struct fsnode_t *fsNode; struct fsnode_t *dstNode;
    char fullName[255] = { '\0' };
 if(!k_strlen(path) || !k_strlen(node->name))
  return 0;
 fsNode = k_malloc(sizeof(fsnode_t));
 if(!fsNode)
  goto failed_exit;
 k_memset(fsNode, 0, sizeof(fsnode_t));
 tree_link_init(&fsNode->link);
 list_init(&fsNode->openFiles);
 fsNode->node = *node;
 fsNode->flags = flags;
 if((dstNode = k_vfs_find_node_by_full_path(path)) == ((void *)0x0))
  goto failed;
 if(!(dstNode->flags & (1)))
  goto failed;
 k_strncat(fullName, path, 255);
 if(path[k_strlen(path)-1] != '/')
  k_strncat(fullName, "/", 255);
 k_strncat(fullName, node->name, 255);
 if(k_vfs_path_is_exist(fullName))
  goto failed;
 tree_add_link(&dstNode->link, &fsNode->link);
 return 1;
failed:
 k_free(fsNode);
failed_exit:
 return 0;
}

variable_types: struct node_t { char name[50]; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); } *

variable_types:
flags
unsigned int

variable_types:
fullName
char [255]


decompiled_code:
__int64 __fastcall k_vfs_mkdir(__int64 a1, __int64 a2)
{
__m128i v3[8]; // [rsp+0h] [rbp-88h] BYREF

k_memset(v3, 0LL, 104LL);
k_strcpy(v3, a2);
return k_vfs_mknode(a1, v3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__m128i v3[8]; // [rsp+0h] [rbp-88h] BYREF

k_memset(v3, 0LL, 104LL);
k_strcpy(v3, a2);
return func9(a1, v3, 1);
}

original_code:
bool k_vfs_mkdir(const char *path, const char *name)
{
 node_t dirNode;
 k_memset(&dirNode, 0, sizeof(dirNode));
 k_strcpy(dirNode.name, name);
 return k_vfs_mknode(path, &dirNode, (1));
}

canonical_original_code:
int k_vfs_mkdir(char *path, char *name)
{
 struct node_t dirNode;
 k_memset(&dirNode, 0, sizeof(dirNode));
 k_strcpy(dirNode.name, name);
 return k_vfs_mknode(path, &dirNode, (1));
}

variable_types:
name
char *

variable_types: struct node_t { char name[50]; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); }


decompiled_code:
__int64 __fastcall k_vfs_iterate_directory(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
__int64 v6[5]; // [rsp+0h] [rbp-28h] BYREF

v4 = k_vfs_find_node_by_full_path(a1);
if ( !v4 || (*(_BYTE *)(v4 + 104) & 1) == 0 )
return 0LL;
v6[0] = a2;
v6[1] = a3;
list_find_arg(v4 + 152, iterate_file_node_in_list, v6);
return 1LL;
}

original_code:
bool k_vfs_iterate_directory(const char *path,
 each_file_in_dir_t callback, void *arg)
{
 fsnode_t *fsNode;
 iterate_helper_t itHelper;
 if((fsNode = k_vfs_find_node_by_full_path(path)) == ((ptr_t)0x0))
  return 0;
 if(!(fsNode->flags & (1)))
  return 0;
 itHelper.callback = callback;
 itHelper.arg = arg;
 list_find_arg(&fsNode->link.children, iterate_file_node_in_list,
  &itHelper);
 return 1;
}

canonical_original_code:
int k_vfs_iterate_directory(char *path, void (*callback)(char *name, unsigned int flags, void *arg), void *arg)
{
 struct fsnode_t *fsNode;
 struct iterate_helper_t itHelper;
 if((fsNode = k_vfs_find_node_by_full_path(path)) == ((void *)0x0))
  return 0;
 if(!(fsNode->flags & (1)))
  return 0;
 itHelper.callback = callback;
 itHelper.arg = arg;
 list_find_arg(&fsNode->link.children, iterate_file_node_in_list,
  &itHelper);
 return 1;
}

variable_types: void (*)(char *name, unsigned int flags, void *arg)

variable_types: struct iterate_helper_t { void (*callback)(char *name, unsigned int flags, void *arg); void *arg; }


decompiled_code:
void __fastcall list_link_init(__int64 a1)
{
*(_DWORD *)a1 = 2827;
*(_QWORD *)(a1 + 8) = 0LL;
_list_link_init(a1);
}

original_code:
struct list_link *
list_link_init(struct list_link *link)
{
 link->poison = 0x0b0b;
 link->list = ((ptr_t)0x0);
 __list_link_init(link);
 return link;
}

canonical_original_code:
struct list_link *list_link_init(struct list_link *link)
{
 link->poison = 0x0b0b;
 link->list = ((void *)0x0);
 __list_link_init(link);
 return link;
}

variable_types:
link
struct list_link *

return_type: struct list_link { unsigned int poison; struct list { struct list_link l; } *list; struct list_link *next; } *


decompiled_code:
void __fastcall list_init(__int64 a1)
{
_list_link_init(a1);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
func2(a1);
}

original_code:
struct list *
list_init(struct list *list)
{
 __list_link_init(&list->l);
 return list;
}

canonical_original_code:
struct list *list_init(struct list *list)
{
 __list_link_init(&list->l);
 return list;
}

variable_types:
list
struct list *

return_type: struct list { struct list_link { unsigned int poison; struct list *list; struct list_link *next; } l; } *


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall list_alone_link(__int64 a1)
{
return _list_link_alone(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return func1(a1);
}

original_code:
bool
list_alone_link(struct list_link *link)
{
 return __list_link_alone(link);
}

canonical_original_code:
int list_alone_link(struct list_link *link)
{
 return __list_link_alone(link);
}

variable_types: struct list_link { unsigned int poison; struct list { struct list_link l; } *list; struct list_link *next; } *


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall list_is_empty(__int64 a1)
{
return _list_link_alone(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1)
{
return func1(a1);
}

original_code:
int
list_is_empty(struct list *list)
{
 return __list_link_alone(&list->l);
}

variable_types: struct list { struct list_link { unsigned int poison; struct list *list; struct list_link *next; } l; } *


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

result = *(_QWORD *)(a1 + 16);
if ( a1 == result )
result = 0LL;
return result;
}

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

result = *(_QWORD *)(a1 + 16);
if ( a1 == result )
result = 0LL;
return result;
}

original_code:
struct list_link *
list_first_link(struct list *list)
{
 struct list_link *l, *first;
 l = &list->l;
 first = l->next;
 return first != l ? first : ((ptr_t)0x0);
}

canonical_original_code:
struct list_link *list_first_link(struct list *list)
{
 struct list_link *l; struct list_link *first;
 l = &list->l;
 first = l->next;
 return first != l ? first : ((void *)0x0);
}


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

result = *(_QWORD *)(a1 + 24);
if ( a1 == result )
result = 0LL;
return result;
}

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

result = *(_QWORD *)(a1 + 24);
if ( a1 == result )
result = 0LL;
return result;
}

original_code:
struct list_link *
list_last_link(struct list *list)
{
 struct list_link *l, *last;
 l = &list->l;
 last = l->prev;
 return last != l ? last : ((ptr_t)0x0);
}

canonical_original_code:
struct list_link *list_last_link(struct list *list)
{
 struct list_link *l; struct list_link *last;
 l = &list->l;
 last = l->prev;
 return last != l ? last : ((void *)0x0);
}


decompiled_code:
void __fastcall list_add_first_link(__int64 a1, __int64 a2)
{
_list_insert_link(a1, a2);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2)
{
func4(a1, a2);
}

original_code:
void
list_add_first_link(struct list_link *new_link, struct list *list)
{
 struct list_link *l;
 l = &list->l;
 __list_insert_link(new_link, l, l->next);
}


decompiled_code:
void __fastcall list_add_last_link(__int64 a1, __int64 a2)
{
_list_insert_link(a1, *(_QWORD *)(a2 + 24));
}

original_code:
void
list_add_last_link(struct list_link *new_link, struct list *list)
{
 struct list_link *l;
 l = &list->l;
 __list_insert_link(new_link, l->prev, l);
}


decompiled_code:
void __fastcall list_insert_before_link(__int64 a1, __int64 a2)
{
_list_insert_link(a1, *(_QWORD *)(a2 + 24));
}

original_code:
void
list_insert_before_link(struct list_link *new_link, struct list_link *link)
{
 __list_insert_link(new_link, link->prev, link);
}


decompiled_code:
void __fastcall list_insert_after_link(__int64 a1, __int64 a2)
{
_list_insert_link(a1, a2);
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2)
{
func4(a1, a2);
}

original_code:
void
list_insert_after_link(struct list_link *new_link, struct list_link *link)
{
 __list_insert_link(new_link, link, link->next);
}


decompiled_code:
void __fastcall list_bulk_add_first(__int64 a1, __int64 a2)
{
__int64 v2; // r9

if ( !list_is_empty(a1) )
{
_list_insert_chain(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2);
_list_link_init(v2);
}
}

original_code:
void
list_bulk_add_first(struct list *from_list, struct list *to_list)
{
 struct list_link *from, *to;
 if (!list_is_empty(from_list))
 {
  from = &from_list->l;
  to = &to_list->l;
  __list_insert_chain(from->next, from->prev, to, to->next);
  __list_link_init(from);
 }
}

canonical_original_code:
void list_bulk_add_first(struct list *from_list, struct list *to_list)
{
 struct list_link *from; struct list_link *to;
 if (!list_is_empty(from_list))
 {
  from = &from_list->l;
  to = &to_list->l;
  __list_insert_chain(from->next, from->prev, to, to->next);
  __list_link_init(from);
 }
}


decompiled_code:
void __fastcall list_bulk_add_last(__int64 a1, __int64 a2)
{
__int64 v2; // r9

if ( !list_is_empty(a1) )
{
_list_insert_chain(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), *(_QWORD *)(a2 + 24));
_list_link_init(v2);
}
}

original_code:
void
list_bulk_add_last(struct list *from_list, struct list *to_list)
{
 struct list_link *from, *to;
 if (!list_is_empty(from_list))
 {
  from = &from_list->l;
  to = &to_list->l;
  __list_insert_chain(from->next, from->prev, to->prev, to);
  __list_link_init(from);
 }
}

canonical_original_code:
void list_bulk_add_last(struct list *from_list, struct list *to_list)
{
 struct list_link *from; struct list_link *to;
 if (!list_is_empty(from_list))
 {
  from = &from_list->l;
  to = &to_list->l;
  __list_insert_chain(from->next, from->prev, to->prev, to);
  __list_link_init(from);
 }
}


decompiled_code:
void __fastcall list_bulk_insert_before_link(__int64 a1, __int64 a2)
{
__int64 v2; // r9

if ( !list_is_empty(a1) )
{
_list_insert_chain(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), *(_QWORD *)(a2 + 24));
_list_link_init(v2);
}
}

original_code:
void
list_bulk_insert_before_link(struct list *from_list, struct list_link *link)
{
 struct list_link *from;
 if (!list_is_empty(from_list))
 {
  from = &from_list->l;
  __list_insert_chain(from->next, from->prev, link->prev, link);
  __list_link_init(from);
 }
}


decompiled_code:
void __fastcall list_bulk_insert_after_link(__int64 a1, __int64 a2)
{
__int64 v2; // r9

if ( !list_is_empty(a1) )
{
_list_insert_chain(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2);
_list_link_init(v2);
}
}

original_code:
void
list_bulk_insert_after_link(struct list *from_list, struct list_link *link)
{
 struct list_link *from;
 if (!list_is_empty(from_list))
 {
  from = &from_list->l;
  __list_insert_chain(from->next, from->prev, link, link->next);
  __list_link_init(from);
 }
}


decompiled_code:
void __fastcall list_unlink_link(__int64 a1)
{
__int64 v1; // r8

_list_bind(*(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 16));
_list_link_init(v1);
}

original_code:
void
list_unlink_link(struct list_link *link)
{
 __list_bind(link->prev, link->next);
 __list_link_init(link);
}


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

v1 = list_first_link(a1);
if ( v1 )
list_unlink_link(v1);
}

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

v1 = func9(a1);
if ( v1 )
func19(v1);
}

original_code:
struct list_link *
list_remove_first_link(struct list *list)
{
 struct list_link *ret;
 if ((ret = list_first_link(list)))
 {
  list_unlink_link(ret);
 }
 return ret;
}

canonical_original_code:
struct list_link *list_remove_first_link(struct list *list)
{
 struct list_link *ret;
 if ((ret = list_first_link(list)))
 {
  list_unlink_link(ret);
 }
 return ret;
}


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

v1 = list_last_link(a1);
if ( v1 )
list_unlink_link(v1);
}

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

v1 = func10(a1);
if ( v1 )
func19(v1);
}

original_code:
struct list_link *
list_remove_last_link(struct list *list)
{
 struct list_link *ret;
 if ((ret = list_last_link(list)))
 {
  list_unlink_link(ret);
 }
 return ret;
}

canonical_original_code:
struct list_link *list_remove_last_link(struct list *list)
{
 struct list_link *ret;
 if ((ret = list_last_link(list)))
 {
  list_unlink_link(ret);
 }
 return ret;
}


decompiled_code:
__int64 __fastcall list_next(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
struct list_link *
list_next(struct list_link *link)
{
 return link->next;
}

canonical_original_code:
struct list_link *list_next(struct list_link *link)
{
 return link->next;
}


decompiled_code:
__int64 __fastcall list_prev(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
struct list_link *
list_prev(struct list_link *link)
{
 return link->prev;
}

canonical_original_code:
struct list_link *list_prev(struct list_link *link)
{
 return link->prev;
}


decompiled_code:
__int64 __fastcall list_find_arg(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 v3; // rbp
int i; // eax

v3 = *(_QWORD *)(a1 + 16);
if ( v3 == a1 )
return 0LL;
for ( i = a2(v3, a3); !i; i = a2(v3, a3) )
{
v3 = list_next(v3);
if ( v3 == a1 )
return 0LL;
}
return v3;
}

original_code:
struct list_link *
list_find_arg(struct list *in_list, list_link_arg_predicate_t predicate, void *arg)
{
 struct list_link *it;
 for(it = in_list->l.next; it != &(in_list->l); it = list_next(it))
 {
  if(predicate(it, arg))
   return it;
 }
 return ((ptr_t)0x0);
}

canonical_original_code:
struct list_link *list_find_arg(struct list *in_list, int (*predicate)(struct list_link *link, void *arg), void *arg)
{
 struct list_link *it;
 for(it = in_list->l.next; it != &(in_list->l); it = list_next(it))
 {
  if(predicate(it, arg))
   return it;
 }
 return ((void *)0x0);
}

variable_types: int (*)(struct list_link *link, void *arg)

variable_types:
arg
void *


canonical_original_code:
char *k_strncpy(char *s1, char *s2, unsigned long n)
{
 char c;
 char *s = s1;
 --s1;
 if (n >= 4)
 {
  unsigned long n4 = n >> 2;
  for (;;)
  {
   c = *s2++;
   *++s1 = c;
   if (c == '\0')
    break;
   c = *s2++;
   *++s1 = c;
   if (c == '\0')
    break;
   c = *s2++;
   *++s1 = c;
   if (c == '\0')
    break;
   c = *s2++;
   *++s1 = c;
   if (c == '\0')
    break;
   if (--n4 == 0)
    goto last_chars;
  }
  n = n - (s1 - s) - 1;
  if (n == 0)
   return s;
  goto zero_fill;
 }
 last_chars: n &= 3;
 if (n == 0)
  return s;
 do
 {
  c = *s2++;
  *++s1 = c;
  if (--n == 0)
   return s;
 }
 while (c != '\0');
 zero_fill: do
  *++s1 = '\0';
 while (--n > 0);
 return s;
}

variable_types:
n
unsigned long

variable_types: c char

variable_types:
s
char *

return_type: char *


decompiled_code:
__int64 __fastcall k_strncmp(unsigned __int8 *a1, unsigned __int8 *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r8
unsigned __int8 *v4; // r9
int v5; // eax
int v6; // edx
int v7; // eax
int v8; // ecx
__int64 i; // rdx
__int64 result; // rax

v3 = a3;
if ( a3 <= 3 )
{
v8 = 0;
v7 = 0;
LABEL_14:
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
v7 = a1[i];
v8 = a2[i];
if ( !(_BYTE)v7 )
break;
if ( (_BYTE)v7 != (_BYTE)v8 )
break;
}
}
LABEL_19:
result = (unsigned int)(v7 - v8);
}
else
{
v4 = &a1[a3 & 0xFFFFFFFFFFFFFFFCLL];
while ( 1 )
{
v5 = *a1;
v6 = *a2;
if ( !(_BYTE)v5 )
break;
if ( (_BYTE)v5 != (_BYTE)v6 )
break;
v5 = a1[1];
v6 = a2[1];
if ( !(_BYTE)v5 )
break;
if ( (_BYTE)v5 != (_BYTE)v6 )
break;
v5 = a1[2];
v6 = a2[2];
if ( !(_BYTE)v5 || (_BYTE)v5 != (_BYTE)v6 )
break;
v7 = a1[3];
a1 += 4;
a2 += 4;
v8 = *(a2 - 1);
if ( !(_BYTE)v7 || (_BYTE)v7 != (_BYTE)v8 )
goto LABEL_19;
if ( v4 == a1 )
{
v3 &= 3u;
goto LABEL_14;
}
}
result = (unsigned int)(v5 - v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, unsigned __int8 *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r8
unsigned __int8 *v4; // r9
int v5; // eax
int v6; // edx
int v7; // eax
int v8; // ecx
__int64 i; // rdx
__int64 result; // rax

v3 = a3;
if ( a3 <= 3 )
{
v8 = 0;
v7 = 0;
LABEL_14:
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
v7 = a1[i];
v8 = a2[i];
if ( !(_BYTE)v7 )
break;
if ( (_BYTE)v7 != (_BYTE)v8 )
break;
}
}
LABEL_19:
result = (unsigned int)(v7 - v8);
}
else
{
v4 = &a1[a3 & 0xFFFFFFFFFFFFFFFCLL];
while ( 1 )
{
v5 = *a1;
v6 = *a2;
if ( !(_BYTE)v5 )
break;
if ( (_BYTE)v5 != (_BYTE)v6 )
break;
v5 = a1[1];
v6 = a2[1];
if ( !(_BYTE)v5 )
break;
if ( (_BYTE)v5 != (_BYTE)v6 )
break;
v5 = a1[2];
v6 = a2[2];
if ( !(_BYTE)v5 || (_BYTE)v5 != (_BYTE)v6 )
break;
v7 = a1[3];
a1 += 4;
a2 += 4;
v8 = *(a2 - 1);
if ( !(_BYTE)v7 || (_BYTE)v7 != (_BYTE)v8 )
goto LABEL_19;
if ( v4 == a1 )
{
v3 &= 3u;
goto LABEL_14;
}
}
result = (unsigned int)(v5 - v6);
}
return result;
}

original_code:
int
k_strncmp(const char *s1, const char *s2, size_t n)
{
 unsigned char c1 = '\0';
 unsigned char c2 = '\0';
 if (n >= 4)
 {
  size_t n4 = n >> 2;
  do
  {
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
  }
  while (--n4 > 0);
  n &= 3;
 }
 while (n > 0)
 {
  c1 = (unsigned char) *s1++;
  c2 = (unsigned char) *s2++;
  if (c1 == '\0' || c1 != c2)
   return c1 - c2;
  n--;
 }
 return c1 - c2;
}

canonical_original_code:
int k_strncmp(char *s1, char *s2, unsigned long n)
{
 unsigned char c1 = '\0';
 unsigned char c2 = '\0';
 if (n >= 4)
 {
  unsigned long n4 = n >> 2;
  do
  {
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
   c1 = (unsigned char) *s1++;
   c2 = (unsigned char) *s2++;
   if (c1 == '\0' || c1 != c2)
    return c1 - c2;
  }
  while (--n4 > 0);
  n &= 3;
 }
 while (n > 0)
 {
  c1 = (unsigned char) *s1++;
  c2 = (unsigned char) *s2++;
  if (c1 == '\0' || c1 != c2)
   return c1 - c2;
  n--;
 }
 return c1 - c2;
}


original_code:
size_t
k_strlen(const char *str)
{
 const char *char_ptr;
 const unsigned long int *longword_ptr;
 unsigned long int longword, himagic, lomagic;
 for (char_ptr = str;
   ((unsigned long int) char_ptr & (sizeof(longword) - 1)) != 0;
   ++char_ptr)
  if (*char_ptr == '\0')
   return char_ptr - str;
 longword_ptr = (unsigned long int *) char_ptr;
 himagic = 0x80808080L;
 lomagic = 0x01010101L;
 for (;;)
 {
  longword = *longword_ptr++;
  if (
  ((longword - lomagic) & himagic)
    != 0)
  {
   const char *cp = (const char *) (longword_ptr - 1);
   if (cp[0] == 0)
    return cp - str;
   if (cp[1] == 0)
    return cp - str + 1;
   if (cp[2] == 0)
    return cp - str + 2;
   if (cp[3] == 0)
    return cp - str + 3;
   if (sizeof(longword) > 4)
   {
    if (cp[4] == 0)
     return cp - str + 4;
    if (cp[5] == 0)
     return cp - str + 5;
    if (cp[6] == 0)
     return cp - str + 6;
    if (cp[7] == 0)
     return cp - str + 7;
   }
  }
 }
}

canonical_original_code:
unsigned long k_strlen(char *str)
{
 char *char_ptr;
 unsigned long *longword_ptr;
 unsigned long longword; unsigned long himagic; unsigned long lomagic;
 for (char_ptr = str;
   ((unsigned long) char_ptr & (sizeof(longword) - 1)) != 0;
   ++char_ptr)
  if (*char_ptr == '\0')
   return char_ptr - str;
 longword_ptr = (unsigned long *) char_ptr;
 himagic = 0x80808080L;
 lomagic = 0x01010101L;
 for (;;)
 {
  longword = *longword_ptr++;
  if (
  ((longword - lomagic) & himagic)
    != 0)
  {
   char *cp = (const char *) (longword_ptr - 1);
   if (cp[0] == 0)
    return cp - str;
   if (cp[1] == 0)
    return cp - str + 1;
   if (cp[2] == 0)
    return cp - str + 2;
   if (cp[3] == 0)
    return cp - str + 3;
   if (sizeof(longword) > 4)
   {
    if (cp[4] == 0)
     return cp - str + 4;
    if (cp[5] == 0)
     return cp - str + 5;
    if (cp[6] == 0)
     return cp - str + 6;
    if (cp[7] == 0)
     return cp - str + 7;
   }
  }
 }
}

variable_types:
str
char *

variable_types:
longword
unsigned long

variable_types:
himagic
unsigned long

variable_types:
lomagic
unsigned long

variable_types:
cp
char *

return_type: unsigned long


decompiled_code:
__int64 __fastcall k_strcpy(__int64 a1, char *a2)
{
__int64 v2; // rdx
char v3; // al

v2 = a1 - (_QWORD)a2;
do
{
v3 = *a2++;
a2[v2 - 1] = v3;
}
while ( v3 );
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
__int64 v2; // rdx
char v3; // al

v2 = a1 - (_QWORD)a2;
do
{
v3 = *a2++;
a2[v2 - 1] = v3;
}
while ( v3 );
return a1;
}

original_code:
char *
k_strcpy(char *dest, const char *src)
{
 char c;
 char *s = (char *) src;
 const size_t off = dest - src - 1;
 do
 {
  c = *s++;
  s[off] = c;
 }
 while (c != '\0');
 return dest;
}

canonical_original_code:
char *k_strcpy(char *dest, char *src)
{
 char c;
 char *s = (char *) src;
 unsigned long off = dest - src - 1;
 do
 {
  c = *s++;
  s[off] = c;
 }
 while (c != '\0');
 return dest;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
off
unsigned long


decompiled_code:
__int64 __fastcall k_strcmp(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int8 v3; // dl
int v4; // ecx

v2 = 0LL;
do
{
v3 = *(_BYTE *)(a1 + v2);
v4 = *(unsigned __int8 *)(a2 + v2);
if ( !v3 )
return (unsigned int)-(unsigned __int8)v4;
++v2;
}
while ( v3 == (_BYTE)v4 );
return (unsigned int)v3 - v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int8 v3; // dl
int v4; // ecx

v2 = 0LL;
do
{
v3 = *(_BYTE *)(a1 + v2);
v4 = *(unsigned __int8 *)(a2 + v2);
if ( !v3 )
return (unsigned int)-(unsigned __int8)v4;
++v2;
}
while ( v3 == (_BYTE)v4 );
return (unsigned int)v3 - v4;
}

original_code:
int
k_strcmp(const char *p1, const char *p2)
{
 register const unsigned char *s1 = (const unsigned char *) p1;
 register const unsigned char *s2 = (const unsigned char *) p2;
 unsigned char c1, c2;
 do
 {
  c1 = (unsigned char) *s1++;
  c2 = (unsigned char) *s2++;
  if (c1 == '\0')
   return c1 - c2;
 }
 while (c1 == c2);
 return c1 - c2;
}

canonical_original_code:
int k_strcmp(char *p1, char *p2)
{
 register unsigned char *s1 = (const unsigned char *) p1;
 register unsigned char *s2 = (const unsigned char *) p2;
 unsigned char c1; unsigned char c2;
 do
 {
  c1 = (unsigned char) *s1++;
  c2 = (unsigned char) *s2++;
  if (c1 == '\0')
   return c1 - c2;
 }
 while (c1 == c2);
 return c1 - c2;
}


decompiled_code:
__int64 __fastcall k_strspn(char *a1, _BYTE *a2)
{
char v2; // cl
__int64 v4; // r8
char v5; // si
_BYTE *v6; // rdx
char v7; // al

v2 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = *a2;
v4 = 0LL;
do
{
if ( !v5 )
break;
v6 = a2;
v7 = v5;
while ( v7 != v2 )
{
v7 = *++v6;
if ( !v7 )
return v4;
}
v2 = a1[++v4];
}
while ( v2 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, _BYTE *a2)
{
char v2; // cl
__int64 v4; // r8
char v5; // si
_BYTE *v6; // rdx
char v7; // al

v2 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = *a2;
v4 = 0LL;
do
{
if ( !v5 )
break;
v6 = a2;
v7 = v5;
while ( v7 != v2 )
{
v7 = *++v6;
if ( !v7 )
return v4;
}
v2 = a1[++v4];
}
while ( v2 );
}
return v4;
}

original_code:
size_t
k_strspn(const char *s, const char *accept)
{
 register const char *p;
 register const char *a;
 register size_t count = 0;
 for (p = s; *p != '\0'; ++p)
 {
  for (a = accept; *a != '\0'; ++a)
   if (*p == *a)
    break;
  if (*a == '\0')
   return count;
  else
   ++count;
 }
 return count;
}

canonical_original_code:
unsigned long k_strspn(char *s, char *accept)
{
 register char *p;
 register char *a;
 register unsigned long count = 0;
 for (p = s; *p != '\0'; ++p)
 {
  for (a = accept; *a != '\0'; ++a)
   if (*p == *a)
    break;
  if (*a == '\0')
   return count;
  else
   ++count;
 }
 return count;
}

variable_types:
accept
char *

variable_types:
p
char *

variable_types:
a
char *

variable_types:
count
unsigned long


decompiled_code:
__int64 __fastcall k_strcspn(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 v3; // si
__int64 i; // r8
__int64 v5; // rcx

v3 = *a1;
for ( i = 0LL; v3; v3 = *(_BYTE *)(v5 + i) )
{
if ( k_strchr(a2, v3) )
break;
++i;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 v3; // si
__int64 i; // r8
__int64 v5; // rcx

v3 = *a1;
for ( i = 0LL; v3; v3 = *(_BYTE *)(v5 + i) )
{
if ( func7(a2, v3) )
break;
++i;
}
return i;
}

original_code:
size_t
k_strcspn(const char *s, const char *reject)
{
 register size_t count = 0;
 while (*s != '\0')
  if (k_strchr(reject, *s++) == ((ptr_t)0x0))
   ++count;
  else
   return count;
 return count;
}

canonical_original_code:
unsigned long k_strcspn(char *s, char *reject)
{
 register unsigned long count = 0;
 while (*s != '\0')
  if (k_strchr(reject, *s++) == ((void *)0x0))
   ++count;
  else
   return count;
 return count;
}

variable_types:
reject
char *


original_code:
char *
k_strsep(char **stringp, const char *delim)
{
 char *begin, *end;
 begin = *stringp + k_strspn(*stringp, delim);
 end = *stringp + k_strcspn(*stringp, delim);
 if (end == *stringp)
  return ((ptr_t)0x0);
 if (*end != '\0')
  *end++ = '\0';
 *stringp = end;
 return begin;
}

canonical_original_code:
char *k_strsep(char **stringp, char *delim)
{
 char *begin; char *end;
 begin = *stringp + k_strspn(*stringp, delim);
 end = *stringp + k_strcspn(*stringp, delim);
 if (end == *stringp)
  return ((void *)0x0);
 if (*end != '\0')
  *end++ = '\0';
 *stringp = end;
 return begin;
}

variable_types:
stringp
char **

variable_types:
delim
char *

variable_types:
begin
char *

variable_types:
end
char *


decompiled_code:
_BOOL8 __fastcall k_isupper(char a1)
{
return (unsigned __int8)(a1 - 65) <= 0x19u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(char a1)
{
return (unsigned __int8)(a1 - 65) <= 0x19u;
}

original_code:
int
k_isupper(char c)
{
 return (c >= 'A' && c <= 'Z') ? 1 : 0;
}

variable_types: c char


decompiled_code:
__int64 __fastcall k_toupper(char a1)
{
unsigned int v1; // edx
_BOOL4 v2; // er8
__int64 result; // rax

v2 = k_isupper(a1);
result = v1 - 32;
if ( v2 )
result = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char a1)
{
unsigned int v1; // edx
_BOOL4 v2; // er8
__int64 result; // rax

v2 = func11(a1);
result = v1 - 32;
if ( v2 )
result = v1;
return result;
}

original_code:
char
k_toupper(char c)
{
 if (k_isupper(c))
  return c;
 return (c - 'a') + 'A';
}

return_type: char


decompiled_code:
__int64 __fastcall k_tolower(char a1)
{
unsigned int v1; // edx
_BOOL4 v2; // er8
__int64 result; // rax

v2 = k_isupper(a1);
result = v1 + 32;
if ( !v2 )
result = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char a1)
{
unsigned int v1; // edx
_BOOL4 v2; // er8
__int64 result; // rax

v2 = func11(a1);
result = v1 + 32;
if ( !v2 )
result = v1;
return result;
}

original_code:
char
k_tolower(char c)
{
 if (!k_isupper(c))
  return c;
 return (c - 'A') + 'a';
}


decompiled_code:
__int64 __fastcall k_strncasecmp(char *a1, char *a2, __int64 a3)
{
int v4; // edx
unsigned __int8 v5; // cl
char *v6; // r10

if ( a1 == a2 || !a3 )
return 0LL;
do
{
++a2;
k_tolower(*a1);
v4 = (unsigned __int8)k_tolower(*(a2 - 1));
}
while ( v5 && v5 == (_BYTE)v4 && a1 != v6 );
return (unsigned int)v5 - v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1, char *a2, __int64 a3)
{
int v4; // edx
unsigned __int8 v5; // cl
char *v6; // r10

if ( a1 == a2 || !a3 )
return 0LL;
do
{
++a2;
func13(*a1);
v4 = (unsigned __int8)func13(*(a2 - 1));
}
while ( v5 && v5 == (_BYTE)v4 && a1 != v6 );
return (unsigned int)v5 - v4;
}

original_code:
int
k_strncasecmp(const char *s1, const char *s2, size_t n)
{
 register const unsigned char *p1 = (const unsigned char *) s1;
 register const unsigned char *p2 = (const unsigned char *) s2;
 unsigned char c1, c2;
 if (p1 == p2 || n == 0)
  return 0;
 do
 {
  c1 = k_tolower(*p1++);
  c2 = k_tolower(*p2++);
  if (c1 == '\0' || c1 != c2)
   return c1 - c2;
 }
 while (--n > 0);
 return c1 - c2;
}

canonical_original_code:
int k_strncasecmp(char *s1, char *s2, unsigned long n)
{
 register unsigned char *p1 = (const unsigned char *) s1;
 register unsigned char *p2 = (const unsigned char *) s2;
 unsigned char c1; unsigned char c2;
 if (p1 == p2 || n == 0)
  return 0;
 do
 {
  c1 = k_tolower(*p1++);
  c2 = k_tolower(*p2++);
  if (c1 == '\0' || c1 != c2)
   return c1 - c2;
 }
 while (--n > 0);
 return c1 - c2;
}

variable_types:
n
unsigned long


decompiled_code:
unsigned __int64 __fastcall k_strtol(char *a1, char **a2, unsigned int a3)
{
char *v3; // r10
int v5; // er9
char v6; // cl
char *v7; // rbp
int v8; // ebx
unsigned int v9; // er12
unsigned __int64 v10; // rdi
__int64 v11; // r8
unsigned __int8 v12; // cl
unsigned int v13; // edx
char *v14; // rsi
int v15; // er13
unsigned __int64 result; // rax
char v17; // cl
char v18; // al

v3 = a1;
if ( a3 == 1 || (v5 = a3, a3 > 0x24) )
v5 = 10;
v6 = *a1;
if ( !*a1 )
{
result = 0LL;
if ( a2 )
*a2 = a1;
return result;
}
if ( v6 == 45 )
{
v6 = a1[1];
v7 = a1 + 1;
v8 = 1;
}
else
{
v7 = a1;
v8 = 0;
if ( v6 == 43 )
{
v6 = a1[1];
v7 = a1 + 1;
if ( v5 == 16 )
goto LABEL_8;
LABEL_12:
if ( v5 )
{
v11 = v5;
v10 = 0x7FFFFFFFuLL / v5;
v9 = 0xFFFFFFFF80000000LL % v5;
}
else if ( v6 == 48 )
{
if ( (unsigned __int8)k_toupper(v7[1]) != 88 )
{
v10 = 0xFFFFFFFLL;
v11 = 8LL;
v5 = 8;
goto LABEL_38;
}
v6 = v7[2];
v9 = 0;
v7 += 2;
v10 = 0x7FFFFFFLL;
v11 = 16LL;
v5 = 16;
}
else
{
v9 = 8;
v10 = 214748364LL;
v11 = 10LL;
v5 = 10;
}
LABEL_15:
if ( !v6 )
goto LABEL_35;
goto LABEL_16;
}
}
if ( v5 != 16 )
goto LABEL_12;
LABEL_8:
if ( v6 != 48 )
{
v9 = 0;
v10 = 0x7FFFFFFLL;
v11 = 16LL;
goto LABEL_15;
}
v18 = k_toupper(v7[1]);
v10 = 0x7FFFFFFLL;
v11 = 16LL;
if ( v18 == 88 )
{
v6 = v7[2];
v9 = 0;
v7 += 2;
goto LABEL_15;
}
LABEL_38:
v9 = 0;
LABEL_16:
v12 = v6 - 48;
v13 = v12;
if ( v5 <= v12 )
goto LABEL_35;
v14 = v7;
v15 = 0;
result = 0LL;
do
{
if ( v10 >= result )
{
if ( v10 != result || v9 >= v13 )
{
++v14;
result = v12 + v11 * result;
v17 = *v14;
if ( !*v14 )
break;
goto LABEL_20;
}
v15 = 1;
}
else
{
v15 = 1;
}
v17 = *++v14;
if ( !v17 )
break;
LABEL_20:
v12 = v17 - 48;
v13 = v12;
}
while ( v12 < v5 );
if ( v14 != v7 )
{
if ( a2 )
*a2 = v14;
if ( result > v8 + 0x7FFFFFFFLL || v15 )
return (unsigned int)(v8 + 0x7FFFFFFF);
if ( v8 )
result = (unsigned int)-(int)result;
return result;
}
LABEL_35:
result = 0LL;
if ( a2 )
*a2 = v3;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func16(char *a1, char **a2, unsigned int a3)
{
char *v3; // r10
int v5; // er9
char v6; // cl
char *v7; // rbp
int v8; // ebx
unsigned int v9; // er12
unsigned __int64 v10; // rdi
__int64 v11; // r8
unsigned __int8 v12; // cl
unsigned int v13; // edx
char *v14; // rsi
int v15; // er13
unsigned __int64 result; // rax
char v17; // cl
char v18; // al

v3 = a1;
if ( a3 == 1 || (v5 = a3, a3 > 0x24) )
v5 = 10;
v6 = *a1;
if ( !*a1 )
{
result = 0LL;
if ( a2 )
*a2 = a1;
return result;
}
if ( v6 == 45 )
{
v6 = a1[1];
v7 = a1 + 1;
v8 = 1;
}
else
{
v7 = a1;
v8 = 0;
if ( v6 == 43 )
{
v6 = a1[1];
v7 = a1 + 1;
if ( v5 == 16 )
goto LABEL_8;
LABEL_12:
if ( v5 )
{
v11 = v5;
v10 = 0x7FFFFFFFuLL / v5;
v9 = 0xFFFFFFFF80000000LL % v5;
}
else if ( v6 == 48 )
{
if ( (unsigned __int8)func12(v7[1]) != 88 )
{
v10 = 0xFFFFFFFLL;
v11 = 8LL;
v5 = 8;
goto LABEL_38;
}
v6 = v7[2];
v9 = 0;
v7 += 2;
v10 = 0x7FFFFFFLL;
v11 = 16LL;
v5 = 16;
}
else
{
v9 = 8;
v10 = 214748364LL;
v11 = 10LL;
v5 = 10;
}
LABEL_15:
if ( !v6 )
goto LABEL_35;
goto LABEL_16;
}
}
if ( v5 != 16 )
goto LABEL_12;
LABEL_8:
if ( v6 != 48 )
{
v9 = 0;
v10 = 0x7FFFFFFLL;
v11 = 16LL;
goto LABEL_15;
}
v18 = func12(v7[1]);
v10 = 0x7FFFFFFLL;
v11 = 16LL;
if ( v18 == 88 )
{
v6 = v7[2];
v9 = 0;
v7 += 2;
goto LABEL_15;
}
LABEL_38:
v9 = 0;
LABEL_16:
v12 = v6 - 48;
v13 = v12;
if ( v5 <= v12 )
goto LABEL_35;
v14 = v7;
v15 = 0;
result = 0LL;
do
{
if ( v10 >= result )
{
if ( v10 != result || v9 >= v13 )
{
++v14;
result = v12 + v11 * result;
v17 = *v14;
if ( !*v14 )
break;
goto LABEL_20;
}
v15 = 1;
}
else
{
v15 = 1;
}
v17 = *++v14;
if ( !v17 )
break;
LABEL_20:
v12 = v17 - 48;
v13 = v12;
}
while ( v12 < v5 );
if ( v14 != v7 )
{
if ( a2 )
*a2 = v14;
if ( result > v8 + 0x7FFFFFFFLL || v15 )
return (unsigned int)(v8 + 0x7FFFFFFF);
if ( v8 )
result = (unsigned int)-(int)result;
return result;
}
LABEL_35:
result = 0LL;
if ( a2 )
*a2 = v3;
return result;
}

original_code:
int32_t
k_strtol(const char *nptr, char **endptr, int base)
{
 int negative;
 register unsigned long int cutoff;
 register unsigned int cutlim;
 register unsigned long int i;
 register const char *s;
 register unsigned char c;
 const char *save;
 int overflow;
 if (base < 0 || base == 1 || base > 36)
  base = 10;
 s = nptr;
 if (*s == '\0')
  goto noconv;
 if (*s == '-')
 {
  negative = 1;
  ++s;
 }
 else if (*s == '+')
 {
  negative = 0;
  ++s;
 }
 else
  negative = 0;
 if (base == 16 && s[0] == '0' && k_toupper(s[1]) == 'X')
  s += 2;
 if (base == 0)
 {
  if (*s == '0')
  {
   if (k_toupper(s[1]) == 'X')
   {
    s += 2;
    base = 16;
   }
   else
    base = 8;
  }
  else
   base = 10;
 }
 save = s;
 cutoff = 0x7fffffff / (unsigned long int) base;
 cutlim = (-0x7fffffff - 1) % (unsigned long int) base;
 overflow = 0;
 i = 0;
 for (c = *s; c != '\0'; c = *++s)
 {
  c -= '0';
  if (c >= base)
   break;
  if (i > cutoff || (i == cutoff && c > cutlim))
   overflow = 1;
  else
  {
   i *= (unsigned long int) base;
   i += c;
  }
 }
 if (s == save)
  goto noconv;
 if (endptr != ((ptr_t)0x0))
  *endptr = (char *) s;
 if (i
   > (negative ?
     -(unsigned long int) (-0x7fffffff - 1) :
     (unsigned long int) 0x7fffffff))
  overflow = 1;
 if (overflow)
 {
  return negative ? (-0x7fffffff - 1) : 0x7fffffff;
 }
 return (negative ? -i : i);
 noconv:
 if (endptr != ((ptr_t)0x0))
  *endptr = (char *) nptr;
 return 0L;
}

canonical_original_code:
int k_strtol(char *nptr, char **endptr, int base)
{
 int negative;
 register unsigned long cutoff;
 register unsigned int cutlim;
 register unsigned long i;
 register char *s;
 register unsigned char c;
 char *save;
 int overflow;
 if (base < 0 || base == 1 || base > 36)
  base = 10;
 s = nptr;
 if (*s == '\0')
  goto noconv;
 if (*s == '-')
 {
  negative = 1;
  ++s;
 }
 else if (*s == '+')
 {
  negative = 0;
  ++s;
 }
 else
  negative = 0;
 if (base == 16 && s[0] == '0' && k_toupper(s[1]) == 'X')
  s += 2;
 if (base == 0)
 {
  if (*s == '0')
  {
   if (k_toupper(s[1]) == 'X')
   {
    s += 2;
    base = 16;
   }
   else
    base = 8;
  }
  else
   base = 10;
 }
 save = s;
 cutoff = 0x7fffffff / (unsigned long) base;
 cutlim = (-0x7fffffff - 1) % (unsigned long) base;
 overflow = 0;
 i = 0;
 for (c = *s; c != '\0'; c = *++s)
 {
  c -= '0';
  if (c >= base)
   break;
  if (i > cutoff || (i == cutoff && c > cutlim))
   overflow = 1;
  else
  {
   i *= (unsigned long) base;
   i += c;
  }
 }
 if (s == save)
  goto noconv;
 if (endptr != ((void *)0x0))
  *endptr = (char *) s;
 if (i
   > (negative ?
     -(unsigned long) (-0x7fffffff - 1) :
     (unsigned long) 0x7fffffff))
  overflow = 1;
 if (overflow)
 {
  return negative ? (-0x7fffffff - 1) : 0x7fffffff;
 }
 return (negative ? -i : i);
 noconv:
 if (endptr != ((void *)0x0))
  *endptr = (char *) nptr;
 return 0L;
}

variable_types:
nptr
char *

variable_types:
endptr
char **

variable_types: base int

variable_types: negative int

variable_types:
cutoff
unsigned long

variable_types:
cutlim
unsigned int

variable_types:
i
unsigned long

variable_types:
s
char *

variable_types:
c
unsigned char

variable_types:
save
char *

variable_types: overflow int


decompiled_code:
unsigned __int64 __fastcall k_atoi(char *a1)
{
return k_strtol(a1, 0LL, 0xAu);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(char *a1)
{
return func16(a1, 0LL, 0xAu);
}

original_code:
int
k_atoi(const char *nptr)
{
 return ((int) k_strtol(nptr, (char **) ((ptr_t)0x0), 10));
}

canonical_original_code:
int k_atoi(char *nptr)
{
 return ((int) k_strtol(nptr, (char **) ((void *)0x0), 10));
}


decompiled_code:
__int64 __fastcall get_next_power_of_two(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = a1 - 1;
if ( (unsigned __int64)(a1 - 1) <= 0xFF )
return *(unsigned __int8 *)(a1 + 863);
if ( v1 <= 0xFFFF )
return (unsigned int)(unsigned __int8)BitTable[v1 >> 8] + 8;
if ( v1 <= 0xFFFFFF )
return (unsigned int)(unsigned __int8)BitTable[v1 >> 16] + 16;
return (unsigned int)(unsigned __int8)BitTable[v1 >> 24] + 24;
}

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

v1 = a1 - 1;
if ( (unsigned __int64)(a1 - 1) <= 0xFF )
return *(unsigned __int8 *)(a1 + 863);
if ( v1 <= 0xFFFF )
return (unsigned int)(unsigned __int8)BitTable[v1 >> 8] + 8;
if ( v1 <= 0xFFFFFF )
return (unsigned int)(unsigned __int8)BitTable[v1 >> 16] + 16;
return (unsigned int)(unsigned __int8)BitTable[v1 >> 24] + 24;
}

original_code:
static uint32_t
get_next_power_of_two(size_t k)
{
 --k;
 if (k < 256)
  return BitTable[k];
 if (k < 256 * 256)
  return BitTable[k >> 8] + 8;
 if (k < 256 * 256 * 256)
  return BitTable[k >> 16] + 16;
 return BitTable[k >> 24] + 24;
}

canonical_original_code:
static unsigned int get_next_power_of_two(unsigned long k)
{
 --k;
 if (k < 256)
  return BitTable[k];
 if (k < 256 * 256)
  return BitTable[k >> 8] + 8;
 if (k < 256 * 256 * 256)
  return BitTable[k >> 16] + 16;
 return BitTable[k >> 24] + 24;
}

variable_types:
k
unsigned long


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

result = *(_QWORD *)(a1 + 8LL * a3);
*a2 = result;
*(_QWORD *)(a1 + 8LL * a3) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 8LL * a3);
*a2 = result;
*(_QWORD *)(a1 + 8LL * a3) = a2;
return result;
}

original_code:
static void
add_block_to_list(MemPool_t *pool, void *p_memory, byte listNum)
{
 struct BlockHeader_t *pHeader = (struct BlockHeader_t *) p_memory;
 pHeader->next = pool->freeSlicesLists[listNum];
 pool->freeSlicesLists[listNum] = pHeader;
}

canonical_original_code:
static void add_block_to_list(struct MemPool *pool, void *p_memory, unsigned char listNum)
{
 struct BlockHeader_t *pHeader = (struct BlockHeader_t *) p_memory;
 pHeader->next = pool->freeSlicesLists[listNum];
 pool->freeSlicesLists[listNum] = pHeader;
}

variable_types: struct MemPool { struct BlockHeader_t { union { struct BlockHeader_t *next; struct { unsigned char listNum; }; }; } *freeSlicesLists[31]; unsigned int numAllocatedBlocks[31]; unsigned int numBlockAllocations[31]; void *phisicalMemBeginPtr; void *phisicalMemPtr; void *phisicalMemPtrMax; } *

variable_types:
listNum
unsigned char

user_defined_types: struct MemPool { struct BlockHeader_t *freeSlicesLists[31]; unsigned int numAllocatedBlocks[31]; unsigned int numBlockAllocations[31]; void *phisicalMemBeginPtr; void *phisicalMemPtr; void *phisicalMemPtrMax; }


decompiled_code:
__int64 __fastcall split_block_and_add_to_lists(__int64 a1, _QWORD *a2, unsigned __int8 a3, char a4)
{
unsigned __int8 v5; // cl
_QWORD *v6; // rsi
unsigned __int8 v7; // r8
unsigned __int8 v8; // r9
_QWORD *v9; // r10
char v10; // cl
unsigned __int8 v11; // r11

v5 = a4 - 1;
v6 = (_QWORD *)((char *)a2 + (unsigned int)(1 << v5));
if ( v5 < a3 )
return add_block_to_list(a1, a2, a3);
v7 = v5;
do
{
add_block_to_list(a1, v6, v7);
v6 = (_QWORD *)((char *)v6 - (unsigned int)(1 << v10));
}
while ( v11 <= v7 );
return add_block_to_list(a1, v9, v8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, unsigned __int8 a3, char a4)
{
unsigned __int8 v5; // cl
_QWORD *v6; // rsi
unsigned __int8 v7; // r8
unsigned __int8 v8; // r9
_QWORD *v9; // r10
char v10; // cl
unsigned __int8 v11; // r11

v5 = a4 - 1;
v6 = (_QWORD *)((char *)a2 + (unsigned int)(1 << v5));
if ( v5 < a3 )
return func1(a1, a2, a3);
v7 = v5;
do
{
func1(a1, v6, v7);
v6 = (_QWORD *)((char *)v6 - (unsigned int)(1 << v10));
}
while ( v11 <= v7 );
return func1(a1, v9, v8);
}

original_code:
static void
split_block_and_add_to_lists(MemPool_t *pool, void *pRawMemory, byte firstListNum, byte memoryLogSize)
{
 void *p_memory = (char*) pRawMemory + (1U << (memoryLogSize - 1));
 byte i = memoryLogSize - 1;
 for (; i >= firstListNum; --i)
 {
  add_block_to_list(pool, p_memory, i);
  p_memory = (char*) p_memory - (1U << (i - 1));
 }
 add_block_to_list(pool, pRawMemory, firstListNum);
}

canonical_original_code:
static void split_block_and_add_to_lists(struct MemPool *pool, void *pRawMemory, unsigned char firstListNum, unsigned char memoryLogSize)
{
 void *p_memory = (char*) pRawMemory + (1U << (memoryLogSize - 1));
 unsigned char i = memoryLogSize - 1;
 for (; i >= firstListNum; --i)
 {
  add_block_to_list(pool, p_memory, i);
  p_memory = (char *) p_memory - (1U << (i - 1));
 }
 add_block_to_list(pool, pRawMemory, firstListNum);
}

variable_types:
pRawMemory
void *

variable_types:
firstListNum
unsigned char

variable_types:
memoryLogSize
unsigned char

variable_types:
i
unsigned char

user_defined_types: struct BlockHeader_t { union { struct BlockHeader_t *next; struct { unsigned char listNum; }; }; }


decompiled_code:
unsigned __int64 __fastcall phisic_mem_capture(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // r12
unsigned __int64 v4; // rsi
unsigned __int64 result; // rax

v3 = *(_QWORD *)(a1 + 504);
v4 = v3;
if ( *(_QWORD *)(a1 + 512) < v3 )
{
k_panic1(57351LL, v3);
v4 = *(_QWORD *)(a1 + 504);
}
result = v3;
*(_QWORD *)(a1 + 504) = a2 + v4;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // r12
unsigned __int64 v4; // rsi
unsigned __int64 result; // rax

v3 = *(_QWORD *)(a1 + 504);
v4 = v3;
if ( *(_QWORD *)(a1 + 512) < v3 )
{
k_panic1(57351LL, v3);
v4 = *(_QWORD *)(a1 + 504);
}
result = v3;
*(_QWORD *)(a1 + 504) = a2 + v4;
return result;
}

original_code:
static void *
phisic_mem_capture(MemPool_t *pool, size_t size)
{
 ptr_t mem = pool->phisicalMemPtr;
 if(pool->phisicalMemPtr > pool->phisicalMemPtrMax)
  k_panic1(0xE007);
 pool->phisicalMemPtr += size;
 return mem;
}

canonical_original_code:
static void *phisic_mem_capture(struct MemPool *pool, unsigned long size)
{
 void *mem = pool->phisicalMemPtr;
 if(pool->phisicalMemPtr > pool->phisicalMemPtrMax)
  k_panic1(0xE007);
 pool->phisicalMemPtr += size;
 return mem;
}

variable_types:
size
unsigned long

variable_types:
mem
void *

return_type: void *


decompiled_code:
__int64 __fastcall find_new_block_for_list(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // er8
_QWORD *v4; // rax
char v5; // r8
__int64 result; // rax
char v7; // cl
char v8; // r13
_QWORD *v9; // rsi

if ( a2 > 0x1Eu )
return 0LL;
v3 = a2 + 1;
if ( a2 == 30 )
{
LABEL_7:
v7 = 20;
if ( a2 >= 0x14u )
v7 = a2;
v8 = v7;
v9 = (_QWORD *)phisic_mem_capture(a1, (unsigned int)(1 << v7));
if ( v9 )
{
split_block_and_add_to_lists(a1, v9, a2, v8);
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
while ( !*(_QWORD *)(a1 + 8LL * v3) )
{
if ( ++v3 == 31 )
goto LABEL_7;
}
v4 = detach_first_block(a1, v3);
split_block_and_add_to_lists(a1, v4, a2, v5);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // er8
_QWORD *v4; // rax
char v5; // r8
__int64 result; // rax
char v7; // cl
char v8; // r13
_QWORD *v9; // rsi

if ( a2 > 0x1Eu )
return 0LL;
v3 = a2 + 1;
if ( a2 == 30 )
{
LABEL_7:
v7 = 20;
if ( a2 >= 0x14u )
v7 = a2;
v8 = v7;
v9 = (_QWORD *)func3(a1, (unsigned int)(1 << v7));
if ( v9 )
{
func2(a1, v9, a2, v8);
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
while ( !*(_QWORD *)(a1 + 8LL * v3) )
{
if ( ++v3 == 31 )
goto LABEL_7;
}
v4 = detach_first_block(a1, v3);
func2(a1, v4, a2, v5);
result = 1LL;
}
return result;
}

original_code:
static bool
find_new_block_for_list(MemPool_t *pool, byte listNum)
{
 if (listNum >= 31)
  return 0;
 uint32_t i = listNum + 1;
 for (; i < 31; ++i)
 {
  if (pool->freeSlicesLists[i])
   break;
 }
 void *result;
 if (i != 31)
 {
  result = detach_first_block(pool, i);
  split_block_and_add_to_lists(pool, result, listNum, i);
 }
 else
 {
  size_t size_of_new_os_block_log =
    (20 > listNum) ?
      20 : listNum;
  result = phisic_mem_capture(pool, 1U << size_of_new_os_block_log);
  if (!result)
   return 0;
  split_block_and_add_to_lists(pool, result, listNum, size_of_new_os_block_log);
 }
 return 1;
}

canonical_original_code:
static int find_new_block_for_list(struct MemPool *pool, unsigned char listNum)
{
 if (listNum >= 31)
  return 0;
 unsigned int i = listNum + 1;
 for (; i < 31; ++i)
 {
  if (pool->freeSlicesLists[i])
   break;
 }
 void *result;
 if (i != 31)
 {
  result = detach_first_block(pool, i);
  split_block_and_add_to_lists(pool, result, listNum, i);
 }
 else
 {
  unsigned long size_of_new_os_block_log = (20 > listNum) ?
      20 : listNum;
  result = phisic_mem_capture(pool, 1U << size_of_new_os_block_log);
  if (!result)
   return 0;
  split_block_and_add_to_lists(pool, result, listNum, size_of_new_os_block_log);
 }
 return 1;
}

variable_types:
i
unsigned int

variable_types:
result
void *


decompiled_code:
__int64 __fastcall k_pool_release(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx

if ( a2 )
{
if ( a1 )
{
result = add_block_to_list(a1, (_QWORD *)(a2 - 8), *(_BYTE *)(a2 - 8));
--*(_DWORD *)(a1 + 4 * v3 + 248);
}
}
return result;
}

original_code:
void
k_pool_release(MemPool_t *pool, ptr_t block)
{
 if (!block || !pool)
  return;
 struct BlockHeader_t *pHeader = (struct BlockHeader_t *) block - 1;
 byte listNum = pHeader->listNum;
 add_block_to_list(pool, pHeader, listNum);
 pool->numAllocatedBlocks[listNum]--;
}

canonical_original_code:
void k_pool_release(struct MemPool *pool, void *block)
{
 if (!block || !pool)
  return;
 struct BlockHeader_t *pHeader = (struct BlockHeader_t *) block - 1;
 unsigned char listNum = pHeader->listNum;
 add_block_to_list(pool, pHeader, listNum);
 pool->numAllocatedBlocks[listNum]--;
}

variable_types:
block
void *

variable_types: struct BlockHeader_t { union { struct BlockHeader_t *next; struct { unsigned char listNum; }; }; } *


decompiled_code:
__int64 __fastcall k_pool_block_size(__int64 a1)
{
return (unsigned int)(1 << *(_BYTE *)(a1 - 8));
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return (unsigned int)(1 << *(_BYTE *)(a1 - 8));
}

original_code:
size_t
k_pool_block_size(ptr_t block)
{
 struct BlockHeader_t *pHeader = (struct BlockHeader_t *) block - 1;
 size_t res = 1U << pHeader->listNum;
 return res;
}

canonical_original_code:
unsigned long k_pool_block_size(void *block)
{
 struct BlockHeader_t *pHeader = (struct BlockHeader_t *) block - 1;
 unsigned long res = 1U << pHeader->listNum;
 return res;
}

variable_types:
res
unsigned long


original_code:
static bool valid_vfs()
{
 node_t testNode = {
  "stdout1",
  file_open_1,
  file_close_1,
  ((ptr_t)0x0),
  file_write_1,
  ((ptr_t)0x0),
  ((ptr_t)0x0)
 };
 if(k_vfs_mknode("/dev/", &testNode, 0x0))
  return 0;
 if(k_vfs_mkdir("/dev", "net"))
  return 0;
 if(k_vfs_mkdir("/dev/net/", "net1"))
  return 0;
 return 1;
}

canonical_original_code:
static int valid_vfs()
{
 struct node_t testNode = {
  "stdout1",
  file_open_1,
  file_close_1,
  ((ptr_t)0x0),
  file_write_1,
  ((ptr_t)0x0),
  ((ptr_t)0x0)
 };
 if(k_vfs_mknode("/dev/", &testNode, 0x0))
  return 0;
 if(k_vfs_mkdir("/dev", "net"))
  return 0;
 if(k_vfs_mkdir("/dev/net/", "net1"))
  return 0;
 return 1;
}

variable_types: struct node_t { char name[50]; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); }


decompiled_code:
__int64 __fastcall dir_iterator(const char *a1, char a2)
{
const char *v2; // rdx

v2 = "->";
if ( (a2 & 1) == 0 )
v2 = (const char *)&unk_615;
return k_print("-> %s %s\n", a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, char a2)
{
const char *v2; // rdx

v2 = "->";
if ( (a2 & 1) == 0 )
v2 = (const char *)&unk_615;
return k_print("-> %s %s\n", a1, v2);
}

original_code:
static void dir_iterator(const char *name, uint32_t flags, void *arg)
{
 k_print("-> %s %s\n", name, flags & (1) ? "->" : "");
}

canonical_original_code:
static void dir_iterator(char *name, unsigned int flags, void *arg)
{
 k_print("-> %s %s\n", name, flags & (1) ? "->" : "");
}

variable_types:
name
char *

variable_types:
flags
unsigned int

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall file_close_2(__int64 a1)
{
k_print("file_close_2 %s, %d\n", (const char *)a1, *(unsigned int *)(a1 + 56));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
k_print("file_close_2 %s, %d\n", (const char *)a1, *(unsigned int *)(a1 + 56));
return 1LL;
}

original_code:
static bool file_close_2(void *file)
{
 file_t *myfile = (file_t *)file;
 k_print("file_close_2 %s, %d\n", myfile->name, myfile->fd);
 return 1;
}

canonical_original_code:
static int file_close_2(void *file)
{
 struct file_t *myfile = (file_t *)file;
 k_print("file_close_2 %s, %d\n", myfile->name, myfile->fd);
 return 1;
}

variable_types:
file
void *

variable_types: struct file_t { char name[50]; unsigned int flags; unsigned int fd; void *(*open)(char *path, unsigned int mode, void *file); int (*close)(void *file); long (*read)(void *buf, unsigned long size, unsigned long count, void *file); long (*write)(void *buf, unsigned long size, unsigned long count, void *file); long (*seek)(unsigned int offset, unsigned int whence, void *file); void (*flush)(void *file); void *internal; struct list_link { unsigned int poison; struct list { struct list_link l; } *list; struct list_link *next; } l; } *


decompiled_code:
__int64 __fastcall file_open_2(const char *a1, __int64 a2, __int64 a3)
{
k_print("File2 %s opened!\n", a1);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, __int64 a3)
{
k_print("File2 %s opened!\n", a1);
return a3;
}

original_code:
static void *file_open_2(const char *path, uint32_t mode, void *file)
{
 k_print("File2 %s opened!\n", path);
 return file;
}

canonical_original_code:
static void *file_open_2(char *path, unsigned int mode, void *file)
{
 k_print("File2 %s opened!\n", path);
 return file;
}

variable_types:
path
char *

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall file_write_1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
k_print("file_write_1 %s, %d\n", (const char *)a4, *(unsigned int *)(a4 + 56));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
k_print("file_write_1 %s, %d\n", (const char *)a4, *(unsigned int *)(a4 + 56));
return 1LL;
}

original_code:
static long file_write_1(const ptr_t buf, size_t size, size_t count, void *file)
{
 file_t *myfile = (file_t *)file;
 k_print("file_write_1 %s, %d\n", myfile->name, myfile->fd);
 return 1;
}

canonical_original_code:
static long file_write_1(void *buf, unsigned long size, unsigned long count, void *file)
{
 struct file_t *myfile = (file_t *)file;
 k_print("file_write_1 %s, %d\n", myfile->name, myfile->fd);
 return 1;
}

variable_types:
buf
void *

variable_types:
count
unsigned long


decompiled_code:
__int64 __fastcall file_close_1(__int64 a1)
{
k_print("file_close_1 %s, %d\n", (const char *)a1, *(unsigned int *)(a1 + 56));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
k_print("file_close_1 %s, %d\n", (const char *)a1, *(unsigned int *)(a1 + 56));
return 1LL;
}

original_code:
static bool file_close_1(void *file)
{
 file_t *myfile = (file_t *)file;
 k_print("file_close_1 %s, %d\n", myfile->name, myfile->fd);
 return 1;
}

canonical_original_code:
static int file_close_1(void *file)
{
 struct file_t *myfile = (file_t *)file;
 k_print("file_close_1 %s, %d\n", myfile->name, myfile->fd);
 return 1;
}


decompiled_code:
__int64 __fastcall file_open_1(const char *a1, __int64 a2, __int64 a3)
{
k_print("File1 %s opened!\n", a1);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2, __int64 a3)
{
k_print("File1 %s opened!\n", a1);
return a3;
}

original_code:
static void *file_open_1(const char *path, uint32_t mode, void *file)
{
 k_print("File1 %s opened!\n", path);
 return file;
}

canonical_original_code:
static void *file_open_1(char *path, unsigned int mode, void *file)
{
 k_print("File1 %s opened!\n", path);
 return file;
}


decompiled_code:
_BOOL8 setup_vfs()
{
__int64 v1[2]; // [rsp+0h] [rbp-E8h] BYREF
__int128 v2; // [rsp+10h] [rbp-D8h]
__int128 v3; // [rsp+20h] [rbp-C8h]
__int16 v4; // [rsp+30h] [rbp-B8h]
__int64 (__fastcall *v5)(const char *, __int64, __int64); // [rsp+38h] [rbp-B0h]
__int64 (__fastcall *v6)(__int64); // [rsp+40h] [rbp-A8h]
__int64 v7; // [rsp+48h] [rbp-A0h]
__int64 (__fastcall *v8)(__int64, __int64, __int64, __int64); // [rsp+50h] [rbp-98h]
__int64 v9; // [rsp+58h] [rbp-90h]
__int64 v10; // [rsp+60h] [rbp-88h]
__int64 v11[2]; // [rsp+70h] [rbp-78h] BYREF
__int128 v12; // [rsp+80h] [rbp-68h]
__int128 v13; // [rsp+90h] [rbp-58h]
__int16 v14; // [rsp+A0h] [rbp-48h]
__int64 (__fastcall *v15)(const char *, __int64, __int64); // [rsp+A8h] [rbp-40h]
__int64 (__fastcall *v16)(__int64); // [rsp+B0h] [rbp-38h]
__int64 v17; // [rsp+B8h] [rbp-30h]
__int64 (__fastcall *v18)(__int64, __int64, __int64, __int64); // [rsp+C0h] [rbp-28h]
__int64 v19; // [rsp+C8h] [rbp-20h]
__int64 v20; // [rsp+D0h] [rbp-18h]

v1[0] = 0x3174756F647473LL;
v1[1] = 0LL;
v4 = 0;
v11[1] = 0LL;
v5 = file_open_1;
v6 = file_close_1;
v7 = 0LL;
v8 = file_write_1;
v9 = 0LL;
v10 = 0LL;
v11[0] = 0x3274756F647473LL;
v14 = 0;
v15 = file_open_2;
v16 = file_close_2;
v17 = 0LL;
v18 = file_write_1;
v19 = 0LL;
v20 = 0LL;
v2 = 0LL;
v3 = 0LL;
v12 = 0LL;
v13 = 0LL;
if ( !(unsigned int)k_vfs_mkdir("/", "mnt") )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/", "dev") )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/", "tmp") )
return 0LL;
if ( !(unsigned int)k_vfs_mknode("/dev/", v1, 0LL) )
return 0LL;
if ( !(unsigned int)k_vfs_mknode("/dev/", v11, 0LL) )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/dev", "net") )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/dev", "disk") )
return 0LL;
k_strcpy(v1, "net1");
k_strcpy(v11, "net2");
if ( !(unsigned int)k_vfs_mknode("/dev/net", v1, 0LL) )
return 0LL;
if ( !(unsigned int)k_vfs_mknode("/dev/net", v11, 0LL) )
return 0LL;
k_strcpy(v1, "hdd1");
if ( !(unsigned int)k_vfs_mknode("/dev/", v1, 0LL) )
return 0LL;
k_print("/dev/=====\n");
if ( !(unsigned int)k_vfs_iterate_directory("/dev", dir_iterator, 0LL) )
return 0LL;
k_print("/dev/net/=====\n");
return (unsigned int)k_vfs_iterate_directory("/dev/net", dir_iterator, 0LL) != 0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
__int64 v1[2]; // [rsp+0h] [rbp-E8h] BYREF
__int128 v2; // [rsp+10h] [rbp-D8h]
__int128 v3; // [rsp+20h] [rbp-C8h]
__int16 v4; // [rsp+30h] [rbp-B8h]
__int64 (__fastcall *v5)(const char *, __int64, __int64); // [rsp+38h] [rbp-B0h]
__int64 (__fastcall *v6)(__int64); // [rsp+40h] [rbp-A8h]
__int64 v7; // [rsp+48h] [rbp-A0h]
__int64 (__fastcall *v8)(__int64, __int64, __int64, __int64); // [rsp+50h] [rbp-98h]
__int64 v9; // [rsp+58h] [rbp-90h]
__int64 v10; // [rsp+60h] [rbp-88h]
__int64 v11[2]; // [rsp+70h] [rbp-78h] BYREF
__int128 v12; // [rsp+80h] [rbp-68h]
__int128 v13; // [rsp+90h] [rbp-58h]
__int16 v14; // [rsp+A0h] [rbp-48h]
__int64 (__fastcall *v15)(const char *, __int64, __int64); // [rsp+A8h] [rbp-40h]
__int64 (__fastcall *v16)(__int64); // [rsp+B0h] [rbp-38h]
__int64 v17; // [rsp+B8h] [rbp-30h]
__int64 (__fastcall *v18)(__int64, __int64, __int64, __int64); // [rsp+C0h] [rbp-28h]
__int64 v19; // [rsp+C8h] [rbp-20h]
__int64 v20; // [rsp+D0h] [rbp-18h]

v1[0] = 0x3174756F647473LL;
v1[1] = 0LL;
v4 = 0;
v11[1] = 0LL;
v5 = file_open_1;
v6 = file_close_1;
v7 = 0LL;
v8 = file_write_1;
v9 = 0LL;
v10 = 0LL;
v11[0] = 0x3274756F647473LL;
v14 = 0;
v15 = file_open_2;
v16 = file_close_2;
v17 = 0LL;
v18 = file_write_1;
v19 = 0LL;
v20 = 0LL;
v2 = 0LL;
v3 = 0LL;
v12 = 0LL;
v13 = 0LL;
if ( !(unsigned int)k_vfs_mkdir("/", "mnt") )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/", "dev") )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/", "tmp") )
return 0LL;
if ( !(unsigned int)k_vfs_mknode("/dev/", v1, 0LL) )
return 0LL;
if ( !(unsigned int)k_vfs_mknode("/dev/", v11, 0LL) )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/dev", "net") )
return 0LL;
if ( !(unsigned int)k_vfs_mkdir("/dev", "disk") )
return 0LL;
k_strcpy(v1, "net1");
k_strcpy(v11, "net2");
if ( !(unsigned int)k_vfs_mknode("/dev/net", v1, 0LL) )
return 0LL;
if ( !(unsigned int)k_vfs_mknode("/dev/net", v11, 0LL) )
return 0LL;
k_strcpy(v1, "hdd1");
if ( !(unsigned int)k_vfs_mknode("/dev/", v1, 0LL) )
return 0LL;
k_print("/dev/=====\n");
if ( !(unsigned int)k_vfs_iterate_directory("/dev", dir_iterator, 0LL) )
return 0LL;
k_print("/dev/net/=====\n");
return (unsigned int)k_vfs_iterate_directory("/dev/net", dir_iterator, 0LL) != 0;
}

original_code:
static bool setup_vfs()
{
 node_t fsNodeOut1 = {
  "stdout1",
  file_open_1,
  file_close_1,
  ((ptr_t)0x0),
  file_write_1,
  ((ptr_t)0x0),
  ((ptr_t)0x0)
 };
 node_t fsNodeOut2 = {
  "stdout2",
  file_open_2,
  file_close_2,
  ((ptr_t)0x0),
  file_write_1,
  ((ptr_t)0x0),
  ((ptr_t)0x0)
 };
 if(!k_vfs_mkdir("/", "mnt"))
  return 0;
 if(!k_vfs_mkdir("/", "dev"))
  return 0;
 if(!k_vfs_mkdir("/", "tmp"))
  return 0;
 if(!k_vfs_mknode("/dev/", &fsNodeOut1, 0x0))
  return 0;
 if(!k_vfs_mknode("/dev/", &fsNodeOut2, 0x0))
  return 0;
 if(!k_vfs_mkdir("/dev", "net"))
  return 0;
 if(!k_vfs_mkdir("/dev", "disk"))
  return 0;
 k_strcpy(fsNodeOut1.name, "net1");
 k_strcpy(fsNodeOut2.name, "net2");
 if(!k_vfs_mknode("/dev/net", &fsNodeOut1, 0x0))
  return 0;
 if(!k_vfs_mknode("/dev/net", &fsNodeOut2, 0x0))
  return 0;
 k_strcpy(fsNodeOut1.name, "hdd1");
 if(!k_vfs_mknode("/dev/", &fsNodeOut1, 0x0))
  return 0;
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev", dir_iterator, ((ptr_t)0x0)))
  return 0;
 k_print("/dev/net/=====\n");
 if(!k_vfs_iterate_directory("/dev/net", dir_iterator, ((ptr_t)0x0)))
  return 0;
 return 1;
}

canonical_original_code:
static int setup_vfs()
{
 struct node_t fsNodeOut1 = {
  "stdout1",
  file_open_1,
  file_close_1,
  ((ptr_t)0x0),
  file_write_1,
  ((ptr_t)0x0),
  ((ptr_t)0x0)
 };
 struct node_t fsNodeOut2 = {
  "stdout2",
  file_open_2,
  file_close_2,
  ((ptr_t)0x0),
  file_write_1,
  ((ptr_t)0x0),
  ((ptr_t)0x0)
 };
 if(!k_vfs_mkdir("/", "mnt"))
  return 0;
 if(!k_vfs_mkdir("/", "dev"))
  return 0;
 if(!k_vfs_mkdir("/", "tmp"))
  return 0;
 if(!k_vfs_mknode("/dev/", &fsNodeOut1, 0x0))
  return 0;
 if(!k_vfs_mknode("/dev/", &fsNodeOut2, 0x0))
  return 0;
 if(!k_vfs_mkdir("/dev", "net"))
  return 0;
 if(!k_vfs_mkdir("/dev", "disk"))
  return 0;
 k_strcpy(fsNodeOut1.name, "net1");
 k_strcpy(fsNodeOut2.name, "net2");
 if(!k_vfs_mknode("/dev/net", &fsNodeOut1, 0x0))
  return 0;
 if(!k_vfs_mknode("/dev/net", &fsNodeOut2, 0x0))
  return 0;
 k_strcpy(fsNodeOut1.name, "hdd1");
 if(!k_vfs_mknode("/dev/", &fsNodeOut1, 0x0))
  return 0;
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev", dir_iterator, ((void *)0x0)))
  return 0;
 k_print("/dev/net/=====\n");
 if(!k_vfs_iterate_directory("/dev/net", dir_iterator, ((void *)0x0)))
  return 0;
 return 1;
}


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

k_print("/dev/=====\n");
if ( !(unsigned int)k_vfs_iterate_directory("/dev/", dir_iterator, 0LL)
|| (k_print("/dev/disk=====\n"), !(unsigned int)k_vfs_iterate_directory("/dev/disk", dir_iterator, 0LL))
|| !(unsigned int)k_vfs_mvnode("/dev/hdd1", "/dev/disk")
|| (k_print("/dev/=====\n"), !(unsigned int)k_vfs_iterate_directory("/dev/", dir_iterator, 0LL))
|| (k_print("/dev/disk=====\n"), !(unsigned int)k_vfs_iterate_directory("/dev/disk", dir_iterator, 0LL))
|| (unsigned int)k_vfs_mvnode("/dev/disk/hdd1", "/dev/disk/folder/")
|| (unsigned int)k_vfs_rmnode("/dev/disk/folder")
|| !(unsigned int)k_vfs_rmnode("/dev/disk/hdd1")
|| !(unsigned int)k_vfs_rmdir("/dev/disk/")
|| (k_print("/dev/=====\n"), result = k_vfs_iterate_directory("/dev/", dir_iterator, 0LL), !(_DWORD)result) )
{
result = 0LL;
}
return result;
}

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

k_print("/dev/=====\n");
if ( !(unsigned int)k_vfs_iterate_directory("/dev/", dir_iterator, 0LL)
|| (k_print("/dev/disk=====\n"), !(unsigned int)k_vfs_iterate_directory("/dev/disk", dir_iterator, 0LL))
|| !(unsigned int)k_vfs_mvnode("/dev/hdd1", "/dev/disk")
|| (k_print("/dev/=====\n"), !(unsigned int)k_vfs_iterate_directory("/dev/", dir_iterator, 0LL))
|| (k_print("/dev/disk=====\n"), !(unsigned int)k_vfs_iterate_directory("/dev/disk", dir_iterator, 0LL))
|| (unsigned int)k_vfs_mvnode("/dev/disk/hdd1", "/dev/disk/folder/")
|| (unsigned int)k_vfs_rmnode("/dev/disk/folder")
|| !(unsigned int)k_vfs_rmnode("/dev/disk/hdd1")
|| !(unsigned int)k_vfs_rmdir("/dev/disk/")
|| (k_print("/dev/=====\n"), result = k_vfs_iterate_directory("/dev/", dir_iterator, 0LL), !(_DWORD)result) )
{
result = 0LL;
}
return result;
}

original_code:
static bool rm_mv_some_vfs_nodes()
{
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev/", dir_iterator, ((ptr_t)0x0)))
  return 0;
 k_print("/dev/disk=====\n");
 if(!k_vfs_iterate_directory("/dev/disk", dir_iterator, ((ptr_t)0x0)))
  return 0;
 if(!k_vfs_mvnode("/dev/hdd1", "/dev/disk"))
  return 0;
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev/", dir_iterator, ((ptr_t)0x0)))
  return 0;
 k_print("/dev/disk=====\n");
 if(!k_vfs_iterate_directory("/dev/disk", dir_iterator, ((ptr_t)0x0)))
  return 0;
 if(k_vfs_mvnode("/dev/disk/hdd1", "/dev/disk/folder/"))
  return 0;
 if(k_vfs_rmnode("/dev/disk/folder"))
  return 0;
 if(!k_vfs_rmnode("/dev/disk/hdd1"))
  return 0;
 if(!k_vfs_rmdir("/dev/disk/"))
  return 0;
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev/", dir_iterator, ((ptr_t)0x0)))
  return 0;
}

canonical_original_code:
static int rm_mv_some_vfs_nodes()
{
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev/", dir_iterator, ((void *)0x0)))
  return 0;
 k_print("/dev/disk=====\n");
 if(!k_vfs_iterate_directory("/dev/disk", dir_iterator, ((void *)0x0)))
  return 0;
 if(!k_vfs_mvnode("/dev/hdd1", "/dev/disk"))
  return 0;
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev/", dir_iterator, ((void *)0x0)))
  return 0;
 k_print("/dev/disk=====\n");
 if(!k_vfs_iterate_directory("/dev/disk", dir_iterator, ((void *)0x0)))
  return 0;
 if(k_vfs_mvnode("/dev/disk/hdd1", "/dev/disk/folder/"))
  return 0;
 if(k_vfs_rmnode("/dev/disk/folder"))
  return 0;
 if(!k_vfs_rmnode("/dev/disk/hdd1"))
  return 0;
 if(!k_vfs_rmdir("/dev/disk/"))
  return 0;
 k_print("/dev/=====\n");
 if(!k_vfs_iterate_directory("/dev/", dir_iterator, ((void *)0x0)))
  return 0;
}


decompiled_code:
__int64 files_working_test()
{
__int64 result; // rax
unsigned int v1; // ebp
unsigned int v2; // er12

if ( (unsigned int)k_fopen("/dev/disk/", 5LL)
|| (unsigned int)k_fopen("/dev/net/", 5LL)
|| (v1 = k_fopen("/dev/stdout1", 5LL)) == 0
|| (v2 = k_fopen("/dev/net/net2", 5LL)) == 0
|| (k_fwrite(v1, "test1", 5LL, 1LL), k_fwrite(v2, "test2", 5LL, 1LL), !(unsigned int)k_fclose(v1))
|| (result = k_fclose(v2), !(_DWORD)result) )
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
unsigned int v1; // ebp
unsigned int v2; // er12

if ( (unsigned int)k_fopen("/dev/disk/", 5LL)
|| (unsigned int)k_fopen("/dev/net/", 5LL)
|| (v1 = k_fopen("/dev/stdout1", 5LL)) == 0
|| (v2 = k_fopen("/dev/net/net2", 5LL)) == 0
|| (k_fwrite(v1, "test1", 5LL, 1LL), k_fwrite(v2, "test2", 5LL, 1LL), !(unsigned int)k_fclose(v1))
|| (result = k_fclose(v2), !(_DWORD)result) )
{
result = 0LL;
}
return result;
}

original_code:
static bool files_working_test()
{
 uint32_t fd1, fd2;
 fd1 = k_fopen("/dev/disk/", (1) | (1<<2));
 if(fd1)
  return 0;
 fd1 = k_fopen("/dev/net/", (1) | (1<<2));
 if(fd1)
  return 0;
 fd1 = k_fopen("/dev/stdout1", (1) | (1<<2));
 if(!fd1)
  return 0;
 fd2 = k_fopen("/dev/net/net2", (1) | (1<<2));
 if(!fd2)
  return 0;
 k_fwrite(fd1, "test1", 5, 1);
 k_fwrite(fd2, "test2", 5, 1);
 if(!k_fclose(fd1))
  return 0;
 if(!k_fclose(fd2))
  return 0;
}

canonical_original_code:
static int files_working_test()
{
 unsigned int fd1; unsigned int fd2;
 fd1 = k_fopen("/dev/disk/", (1) | (1<<2));
 if(fd1)
  return 0;
 fd1 = k_fopen("/dev/net/", (1) | (1<<2));
 if(fd1)
  return 0;
 fd1 = k_fopen("/dev/stdout1", (1) | (1<<2));
 if(!fd1)
  return 0;
 fd2 = k_fopen("/dev/net/net2", (1) | (1<<2));
 if(!fd2)
  return 0;
 k_fwrite(fd1, "test1", 5, 1);
 k_fwrite(fd2, "test2", 5, 1);
 if(!k_fclose(fd1))
  return 0;
 if(!k_fclose(fd2))
  return 0;
}


decompiled_code:
_BOOL8 run_vfs_test()
{
_BOOL8 result; // rax

if ( (unsigned int)k_vfs_init() && setup_vfs() && valid_vfs() && (unsigned int)rm_mv_some_vfs_nodes() )
result = (unsigned int)files_working_test() != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 func10()
{
_BOOL8 result; // rax

if ( (unsigned int)k_vfs_init() && func7() && func0() && (unsigned int)func8() )
result = (unsigned int)func9() != 0;
else
result = 0LL;
return result;
}

original_code:
bool run_vfs_test()
{
 if(!k_vfs_init())
  return 0;
 if(!setup_vfs())
  return 0;
 if(!valid_vfs())
  return 0;
 if(!rm_mv_some_vfs_nodes())
  return 0;
 if(!files_working_test())
  return 0;
    return 1;
}

canonical_original_code:
int run_vfs_test()
{
 if(!k_vfs_init())
  return 0;
 if(!setup_vfs())
  return 0;
 if(!valid_vfs())
  return 0;
 if(!rm_mv_some_vfs_nodes())
  return 0;
 if(!files_working_test())
  return 0;
    return 1;
}


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

if ( a1 )
{
k_print("Registers: \n");
k_print(
"EAX=0x%08x; EBX=0x%08x; ECX=0x%08x; EDX=0x%08x\n",
*(unsigned int *)(a1 + 40),
*(unsigned int *)(a1 + 28),
*(unsigned int *)(a1 + 36),
*(unsigned int *)(a1 + 32));
result = k_print(
"ESP=0x%08x; DS=0x%08x; ES=0x%08x; FS=0x%08x; GS=0x%08x",
*(unsigned int *)(a1 + 24),
(unsigned int)*(__int16 *)(a1 + 10),
(unsigned int)*(__int16 *)(a1 + 8),
(unsigned int)*(__int16 *)(a1 + 6),
(unsigned int)*(__int16 *)(a1 + 4));
}
return result;
}

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

if ( a1 )
{
k_print("Registers: \n");
k_print(
"EAX=0x%08x; EBX=0x%08x; ECX=0x%08x; EDX=0x%08x\n",
*(unsigned int *)(a1 + 40),
*(unsigned int *)(a1 + 28),
*(unsigned int *)(a1 + 36),
*(unsigned int *)(a1 + 32));
result = k_print(
"ESP=0x%08x; DS=0x%08x; ES=0x%08x; FS=0x%08x; GS=0x%08x",
*(unsigned int *)(a1 + 24),
(unsigned int)*(__int16 *)(a1 + 10),
(unsigned int)*(__int16 *)(a1 + 8),
(unsigned int)*(__int16 *)(a1 + 6),
(unsigned int)*(__int16 *)(a1 + 4));
}
return result;
}

original_code:
static void k_print_regs(const regs_t *regs)
{
 if(!regs)
  return ;
 k_print("Registers: \n");
 k_print("EAX=0x%08x; EBX=0x%08x; ECX=0x%08x; EDX=0x%08x\n",
   regs->eax, regs->ebx, regs->ecx, regs->edx);
 k_print("ESP=0x%08x; DS=0x%08x; ES=0x%08x; FS=0x%08x; GS=0x%08x",
   regs->esp, regs->ds, regs->es, regs->fs, regs->gs);
}

canonical_original_code:
static void k_print_regs(struct regs_t *regs)
{
 if(!regs)
  return ;
 k_print("Registers: \n");
 k_print("EAX=0x%08x; EBX=0x%08x; ECX=0x%08x; EDX=0x%08x\n",
   regs->eax, regs->ebx, regs->ecx, regs->edx);
 k_print("ESP=0x%08x; DS=0x%08x; ES=0x%08x; FS=0x%08x; GS=0x%08x",
   regs->esp, regs->ds, regs->es, regs->fs, regs->gs);
}

variable_types: struct regs_t { short ss; short cs; short gs; short fs; short es; short ds; int edi; int esi; int ebp; int esp; int ebx; int edx; int ecx; int eax; } *


decompiled_code:
void __fastcall __noreturn k_panic4(unsigned int a1, unsigned int a2, const char *a3, __int64 a4, unsigned int a5)
{
k_print("*** Kernel Panic at 0x%08x\n", a5);
if ( !a3 )
a3 = "none";
k_print("Error Code 0x%08x; Second Code %d : %s\n", a1, a2, a3);
k_print_regs(a4);
_assert_fail("false", "kerror_mocked.c", 0x35u, "k_panic4");
}

canonical_decompiled_code:
void __fastcall __noreturn func1(unsigned int a1, unsigned int a2, const char *a3, __int64 a4, unsigned int a5)
{
k_print("*** Kernel Panic at 0x%08x\n", a5);
if ( !a3 )
a3 = "none";
k_print("Error Code 0x%08x; Second Code %d : %s\n", a1, a2, a3);
func0(a4);
_assert_fail("false", "kerror_mocked.c", 0x35u, "k_panic4");
}

original_code:
void k_panic4(int errCode, int addCode, const char *str, const regs_t *regs, uint32_t address)
{
 k_print("*** Kernel Panic at 0x%08x\n", address);
 k_print("Error Code 0x%08x; Second Code %d : %s\n", errCode, addCode,
   (str == ((ptr_t)0x0)) ? "none" : str);
 k_print_regs(regs);
 ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("false", "kerror_mocked.c", 53, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void k_panic4(int errCode, int addCode, char *str, struct regs_t *regs, unsigned int address)
{
 k_print("*** Kernel Panic at 0x%08x\n", address);
 k_print("Error Code 0x%08x; Second Code %d : %s\n", errCode, addCode,
   (str == ((void *)0x0)) ? "none" : str);
 k_print_regs(regs);
 ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("false", "kerror_mocked.c", 53, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: errCode int

variable_types: addCode int

variable_types:
str
char *

variable_types:
address
unsigned int

user_defined_types: struct regs_t { short ss; short cs; short gs; short fs; short es; short ds; int edi; int esi; int ebp; int esp; int ebx; int edx; int ecx; int eax; }


decompiled_code:
void __fastcall __noreturn k_panic3(unsigned int a1, unsigned int a2, const char *a3)
{
k_panic4(a1, a2, a3, 0LL, 0);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(unsigned int a1, unsigned int a2, const char *a3)
{
func1(a1, a2, a3, 0LL, 0);
}

original_code:
void k_panic3(int errCode, int addCode, const char *str)
{
 k_panic4(errCode, addCode, str, ((ptr_t)0x0), 0);
}

canonical_original_code:
void k_panic3(int errCode, int addCode, char *str)
{
 k_panic4(errCode, addCode, str, ((void *)0x0), 0);
}


decompiled_code:
void __fastcall __noreturn k_panic1(unsigned int a1)
{
k_panic3(a1, 0, 0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(unsigned int a1)
{
func2(a1, 0, 0LL);
}

original_code:
void k_panic1(int errCode)
{
 k_panic3(errCode, 0, ((ptr_t)0x0));
}

canonical_original_code:
void k_panic1(int errCode)
{
 k_panic3(errCode, 0, ((void *)0x0));
}


decompiled_code:
__int64 __fastcall tree_unlink_link(_QWORD *a1)
{
if ( !*a1 )
return 0LL;
list_unlink_link(a1 + 5);
*a1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( !*a1 )
return 0LL;
list_unlink_link(a1 + 5);
*a1 = 0LL;
return 1LL;
}

original_code:
int
tree_unlink_link(struct tree_link *link)
{
 if (link->par != ((ptr_t)0x0))
 {
  list_unlink_link(&link->listLink);
  link->par = ((ptr_t)0x0);
  return 1;
 }
 return 0;
}

canonical_original_code:
int tree_unlink_link(struct tree_link *link)
{
 if (link->par != ((void *)0x0))
 {
  list_unlink_link(&link->listLink);
  link->par = ((void *)0x0);
  return 1;
 }
 return 0;
}

variable_types: struct tree_link { struct tree_link *par; struct list { struct list_link { unsigned int poison; struct list *list; struct list_link *next; } l; } children; struct list_link listLink; } *