decompiled_code:
__int64 __fastcall fs_rm(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-4530h] BYREF
char v9[256]; // [rsp+10h] [rbp-4528h] BYREF
char dest[1024]; // [rsp+110h] [rbp-4428h] BYREF
int v11; // [rsp+510h] [rbp-4028h] BYREF
char src[16420]; // [rsp+514h] [rbp-4024h] BYREF

debug_puts("fs_rm()\n");
v8 = 0LL;
fs_split_path(a1, &v11);
strcpy(dest, "/");
if ( v11 == 1 )
{
v4 = 4LL;
}
else
{
v1 = 0;
do
{
v2 = v1++;
strcat(dest, &src[512 * v2]);
strcat(dest, "/");
v3 = (unsigned int)(v11 - 1);
}
while ( (unsigned int)v3 > v1 );
v4 = (v3 << 9) + 4;
}
strcpy(v9, (const char *)&v11 + v4);
fs_get_node(dest, &v8);
if ( v8
&& (v5 = fs_get_fs_driver((__int64)dest)) != 0
&& (v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 336)) != 0LL )
{
result = v6(v8, v9);
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-4530h] BYREF
char v9[256]; // [rsp+10h] [rbp-4528h] BYREF
char dest[1024]; // [rsp+110h] [rbp-4428h] BYREF
int v11; // [rsp+510h] [rbp-4028h] BYREF
char src[16420]; // [rsp+514h] [rbp-4024h] BYREF

debug_puts("fs_rm()\n");
v8 = 0LL;
fs_split_path(a1, &v11);
strcpy(dest, "/");
if ( v11 == 1 )
{
v4 = 4LL;
}
else
{
v1 = 0;
do
{
v2 = v1++;
strcat(dest, &src[512 * v2]);
strcat(dest, "/");
v3 = (unsigned int)(v11 - 1);
}
while ( (unsigned int)v3 > v1 );
v4 = (v3 << 9) + 4;
}
strcpy(v9, (const char *)&v11 + v4);
fs_get_node(dest, &v8);
if ( v8
&& (v5 = func0((__int64)dest)) != 0
&& (v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 336)) != 0LL )
{
result = v6(v8, v9);
}
else
{
result = 0LL;
}
return result;
}

original_code:
uint32_t fs_rm(char *path_)
{
 debug_puts("fs_rm()\n");
 fs_splitted_path sp;
 inode_t *node = 0;
 char path[1024];
 char name[255];
 uint32_t i;
 fs_split_path(path_, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 fs_get_node(path, &node);
 if(node == 0)
  return 0;
 driver_t *drv = fs_get_fs_driver(path);
 driver_fs_t *filesystem_struct;
 if(drv != 0)
  filesystem_struct = &drv->fs;
 else
  return 0;
 if(filesystem_struct->delete_node != 0)
  return filesystem_struct->delete_node(node, name);
 return 0;
}

canonical_original_code:
unsigned int fs_rm(char *path_)
{
 debug_puts("fs_rm()\n");
 struct fs_splitted_path sp;
 struct inode_p *node = 0;
 char path[1024];
 char name[255];
 unsigned int i;
 fs_split_path(path_, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 fs_get_node(path, &node);
 if(node == 0)
  return 0;
 struct driver_p *drv = fs_get_fs_driver(path);
 struct driver_fs_t *filesystem_struct;
 if(drv != 0)
  filesystem_struct = &drv->fs;
 else
  return 0;
 if(filesystem_struct->delete_node != 0)
  return filesystem_struct->delete_node(node, name);
 return 0;
}

variable_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *

user_defined_types: struct fs_splitted_path { unsigned int i; char list[32][512]; }

user_defined_types: struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); }

user_defined_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; }

user_defined_types: struct dirent { char name[255]; unsigned int inode; }

user_defined_types: struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; }


repo: dakk/spiderpig-os

decompiled_code:
__int64 __fastcall fs_close(void *ptr)
{
debug_puts("fs_close()\n");
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
debug_puts("fs_close()\n");
free(ptr);
return 0LL;
}

original_code:
uint32_t fs_close(file_t *f)
{
 debug_puts("fs_close()\n");
 free(f);
 return 0;
}

canonical_original_code:
unsigned int fs_close(struct file_p *f)
{
 debug_puts("fs_close()\n");
 free(f);
 return 0;
}

variable_types: struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *node; void *drv; struct file_p *next; } *

return_type: unsigned int

user_defined_types: struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p *node; void *drv; struct file_p *next; }


decompiled_code:
__int64 __fastcall fs_read(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 (__fastcall *v5)(_QWORD, __int64, _QWORD, _QWORD); // rax
__int64 result; // rax
__int64 v7; // rdx

debug_puts("fs_read()\n");
v4 = a1[4];
if ( !v4 )
return 0LL;
v5 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, _QWORD))(v4 + 384);
if ( v5 )
{
result = v5(a1[3], a2, a3, a1[1]);
v7 = (unsigned int)result;
}
else
{
v7 = 0LL;
result = 0LL;
}
a1[1] += v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 (__fastcall *v5)(_QWORD, __int64, _QWORD, _QWORD); // rax
__int64 result; // rax
__int64 v7; // rdx

debug_puts("fs_read()\n");
v4 = a1[4];
if ( !v4 )
return 0LL;
v5 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, _QWORD))(v4 + 384);
if ( v5 )
{
result = v5(a1[3], a2, a3, a1[1]);
v7 = (unsigned int)result;
}
else
{
v7 = 0LL;
result = 0LL;
}
a1[1] += v7;
return result;
}

original_code:
uint32_t fs_read(file_t *f, char *buf, uint32_t size)
{
 debug_puts("fs_read()\n");
 driver_fs_t *filesystem_struct = 0;
 unsigned av = 0;
 if(f->drv != 0)
  filesystem_struct = &((driver_t *) (f->drv))->fs;
 else
  return 0;
 if(filesystem_struct->read != 0)
  av = filesystem_struct->read(f->node, buf, size, f->seek_p);
 f->seek_p = f->seek_p + av;
 return av;
}

canonical_original_code:
unsigned int fs_read(struct file_p *f, char *buf, unsigned int size)
{
 debug_puts("fs_read()\n");
 struct driver_fs_t *filesystem_struct = 0;
 unsigned int av = 0;
 if(f->drv != 0)
  filesystem_struct = &((struct driver_p *) (f->drv))->fs;
 else
  return 0;
 if(filesystem_struct->read != 0)
  av = filesystem_struct->read(f->node, buf, size, f->seek_p);
 f->seek_p = f->seek_p + av;
 return av;
}

variable_types:
buf
char *

variable_types:
size
unsigned int

variable_types: struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } *

variable_types:
av
unsigned int

user_defined_types: struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; }

user_defined_types: struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t fs; struct driver_video_t video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; }


decompiled_code:
__int64 __fastcall fs_write(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 (__fastcall *v5)(_QWORD, __int64, _QWORD, _QWORD); // rax
__int64 result; // rax
__int64 v7; // rdx

debug_puts("fs_write()\n");
v4 = a1[4];
if ( !v4 )
return 0LL;
v5 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, _QWORD))(v4 + 392);
if ( v5 )
{
result = v5(a1[3], a2, a3, a1[1]);
v7 = (unsigned int)result;
}
else
{
v7 = 0LL;
result = 0LL;
}
a1[1] += v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 (__fastcall *v5)(_QWORD, __int64, _QWORD, _QWORD); // rax
__int64 result; // rax
__int64 v7; // rdx

debug_puts("fs_write()\n");
v4 = a1[4];
if ( !v4 )
return 0LL;
v5 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, _QWORD))(v4 + 392);
if ( v5 )
{
result = v5(a1[3], a2, a3, a1[1]);
v7 = (unsigned int)result;
}
else
{
v7 = 0LL;
result = 0LL;
}
a1[1] += v7;
return result;
}

original_code:
uint32_t fs_write(file_t *f, char *buf, uint32_t size)
{
 debug_puts("fs_write()\n");
 driver_fs_t *filesystem_struct = 0;
 unsigned av = 0;
 if(f->drv != 0)
  filesystem_struct = &((driver_t *) (f->drv))->fs;
 else
  return 0;
 if(filesystem_struct->write != 0)
  av = filesystem_struct->write(f->node, buf, size, f->seek_p);
 f->seek_p = f->seek_p + av;
 return av;
}

canonical_original_code:
unsigned int fs_write(struct file_p *f, char *buf, unsigned int size)
{
 debug_puts("fs_write()\n");
 struct driver_fs_t *filesystem_struct = 0;
 unsigned int av = 0;
 if(f->drv != 0)
  filesystem_struct = &((struct driver_p *) (f->drv))->fs;
 else
  return 0;
 if(filesystem_struct->write != 0)
  av = filesystem_struct->write(f->node, buf, size, f->seek_p);
 f->seek_p = f->seek_p + av;
 return av;
}

user_defined_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; }


decompiled_code:
__int64 __fastcall fs_seek(__int64 a1, char a2, __int64 a3)
{
__int64 result; // rax

debug_puts("fs_seek()\n");
switch ( a2 )
{
case 1:
*(_QWORD *)(a1 + 8) += a3;
result = 0LL;
break;
case 0:
*(_QWORD *)(a1 + 8) = a3;
return 0LL;
case 2:
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 16) - a3;
result = 0LL;
break;
default:
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2, __int64 a3)
{
__int64 result; // rax

debug_puts("fs_seek()\n");
switch ( a2 )
{
case 1:
*(_QWORD *)(a1 + 8) += a3;
result = 0LL;
break;
case 0:
*(_QWORD *)(a1 + 8) = a3;
return 0LL;
case 2:
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 16) - a3;
result = 0LL;
break;
default:
return 0LL;
}
return result;
}

original_code:
uint32_t fs_seek(file_t *f, uint8_t mod, uint64_t offset)
{
 debug_puts("fs_seek()\n");
 if(mod == 1)
  f->seek_p = f->seek_p + offset;
 else if(mod == 0)
  f->seek_p = offset;
 else if(mod == 2)
  f->seek_p = f->size - offset;
 return 0;
}

canonical_original_code:
unsigned int fs_seek(struct file_p *f, unsigned char mod, unsigned long long offset)
{
 debug_puts("fs_seek()\n");
 if(mod == 1)
  f->seek_p = f->seek_p + offset;
 else if(mod == 0)
  f->seek_p = offset;
 else if(mod == 2)
  f->seek_p = f->size - offset;
 return 0;
}

variable_types:
mod
unsigned char

variable_types:
offset
unsigned long long


decompiled_code:
__int64 __fastcall fs_opendir(char *src)
{
__int64 result; // rax
signed int v2; // eax
bool v3; // zf
__int64 v4; // r12
char v5[256]; // [rsp+0h] [rbp-4128h] BYREF
int v6; // [rsp+100h] [rbp-4028h] BYREF
char srca[16420]; // [rsp+104h] [rbp-4024h] BYREF

debug_puts("fs_opendir()\n");
fs_split_path(src, &v6);
strcpy(v5, &srca[512 * (unsigned __int64)(unsigned int)(v6 - 1)]);
result = fs_get_fs_driver((__int64)src);
if ( result )
{
v2 = (unsigned int)malloc(0x218uLL);
v3 = v5[0] == 0;
v4 = v2;
*(_QWORD *)((char *)&loc_7 + v2 + 1) = v5;
if ( v3 )
strcpy(v5, "/");
strcpy((char *)(v4 + 20), src);
*(_QWORD *)v4 = 0LL;
result = v4;
*(_DWORD *)(v4 + 16) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src)
{
__int64 result; // rax
signed int v2; // eax
bool v3; // zf
__int64 v4; // r12
char v5[256]; // [rsp+0h] [rbp-4128h] BYREF
int v6; // [rsp+100h] [rbp-4028h] BYREF
char srca[16420]; // [rsp+104h] [rbp-4024h] BYREF

debug_puts("fs_opendir()\n");
fs_split_path(src, &v6);
strcpy(v5, &srca[512 * (unsigned __int64)(unsigned int)(v6 - 1)]);
result = func0((__int64)src);
if ( result )
{
v2 = (unsigned int)malloc(0x218uLL);
v3 = v5[0] == 0;
v4 = v2;
*(_QWORD *)((char *)&loc_7 + v2 + 1) = v5;
if ( v3 )
strcpy(v5, "/");
strcpy((char *)(v4 + 20), src);
*(_QWORD *)v4 = 0LL;
result = v4;
*(_DWORD *)(v4 + 16) = 0;
}
return result;
}

original_code:
dir_t *fs_opendir(char *path)
{
 debug_puts("fs_opendir()\n");
 file_t *f = 0;
 fs_splitted_path sp;
 char name[255];
 uint32_t i;
 struct dirent dir;
 fs_split_path(path, &sp);
 strcpy(name, sp.list[sp.i - 1]);
 driver_t *drv = fs_get_fs_driver(path);
 if(drv == 0)
  return (dir_t *) 0;
 dir_t *d = (dir_t *) malloc(sizeof(dir_t));
 d->d_name = name;
 if(d->d_name[0] == '\0')
  strcpy(d->d_name, "/");
 strcpy(d->path, path);
 d->f = f;
 d->cur_i = 0;
 return d;
}

canonical_original_code:
struct dir_p *fs_opendir(char *path)
{
 debug_puts("fs_opendir()\n");
 struct file_p *f = 0;
 struct fs_splitted_path sp;
 char name[255];
 unsigned int i;
 struct dirent dir;
 fs_split_path(path, &sp);
 strcpy(name, sp.list[sp.i - 1]);
 struct driver_p *drv = fs_get_fs_driver(path);
 if(drv == 0)
  return (struct dir_p *) 0;
 struct dir_p *d = (dir_t *) malloc(sizeof(dir_t));
 d->d_name = name;
 if(d->d_name[0] == '\0')
  strcpy(d->d_name, "/");
 strcpy(d->path, path);
 d->f = f;
 d->cur_i = 0;
 return d;
}

variable_types:
path
char *

variable_types: struct fs_splitted_path { unsigned int i; char list[32][512]; }

variable_types:
name
char [255]

variable_types:
i
unsigned int

variable_types: struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *

variable_types: struct dir_p { struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *node; void *drv; struct file_p *next; } *f; char *d_name; unsigned int cur_i; char path[512]; } *

user_defined_types: struct dir_p { struct file_p *f; char *d_name; unsigned int cur_i; char path[512]; }


decompiled_code:
__int64 __fastcall fs_closedir(void *ptr)
{
debug_puts("fs_closedir()\n");
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
debug_puts("fs_closedir()\n");
free(ptr);
return 0LL;
}

original_code:
uint32_t fs_closedir(dir_t *dr)
{
 debug_puts("fs_closedir()\n");
 free(dr);
 return 0;
}

canonical_original_code:
unsigned int fs_closedir(struct dir_p *dr)
{
 debug_puts("fs_closedir()\n");
 free(dr);
 return 0;
}


decompiled_code:
__int64 __fastcall fs_rewinddir(__int64 a1)
{
debug_puts("fs_rewinddir()\n");
*(_DWORD *)(a1 + 16) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
debug_puts("fs_rewinddir()\n");
*(_DWORD *)(a1 + 16) = 0;
return 0LL;
}

original_code:
uint32_t fs_rewinddir(dir_t *dr)
{
 debug_puts("fs_rewinddir()\n");
 dr->cur_i = 0;
 return 0;
}

canonical_original_code:
unsigned int fs_rewinddir(struct dir_p *dr)
{
 debug_puts("fs_rewinddir()\n");
 dr->cur_i = 0;
 return 0;
}


original_code:
uint32_t fs_readdir2(char *path, uint32_t in, struct dirent *dir)
{
 inode_t *node = 0;
 fs_get_node(path, &node);
 if(node == 0)
  return 0;
 if(node->type == 3)
  node = node->link;
 if(node == 0)
  return 0;
 strcpy(dir->name, "\0");
 dir->inode = 0;
 driver_t *drv = fs_get_fs_driver(path);
 driver_fs_t *filesystem_struct;
 if(drv != 0)
  filesystem_struct = &drv->fs;
 else
  return 0;
 if(filesystem_struct->readdir != 0)
  return filesystem_struct->readdir(node, in, dir);
 return 0;
}

canonical_original_code:
unsigned int fs_readdir2(char *path, unsigned int in, struct dirent *dir)
{
 struct inode_p *node = 0;
 fs_get_node(path, &node);
 if(node == 0)
  return 0;
 if(node->type == 3)
  node = node->link;
 if(node == 0)
  return 0;
 strcpy(dir->name, "\0");
 dir->inode = 0;
 struct driver_p *drv = fs_get_fs_driver(path);
 struct driver_fs_t *filesystem_struct;
 if(drv != 0)
  filesystem_struct = &drv->fs;
 else
  return 0;
 if(filesystem_struct->readdir != 0)
  return filesystem_struct->readdir(node, in, dir);
 return 0;
}

variable_types:
in
unsigned int

variable_types: struct dirent { char name[255]; unsigned int inode; } *


decompiled_code:
__int64 __fastcall fs_open(__int64 a1, _BYTE *a2)
{
unsigned int v3; // ebp
__int64 v4; // rax
unsigned __int64 v5; // rsi
__int64 v6; // r12
unsigned int i; // ebp
void (__fastcall *v9)(__int64, _QWORD, __int64 *); // rax
__int64 v10; // [rsp+0h] [rbp-4648h] BYREF
__int64 v11; // [rsp+8h] [rbp-4640h] BYREF
char s2[256]; // [rsp+10h] [rbp-4638h] BYREF
char s1[256]; // [rsp+110h] [rbp-4538h] BYREF
unsigned int v14; // [rsp+210h] [rbp-4438h]
char dest[1024]; // [rsp+220h] [rbp-4428h] BYREF
int v16; // [rsp+620h] [rbp-4028h] BYREF
char src[16420]; // [rsp+624h] [rbp-4024h] BYREF

debug_puts("fs_open()\n");
fs_split_path(a1, &v16);
strcpy(dest, "/");
if ( v16 == 1 )
{
v5 = 4LL;
}
else
{
v3 = 0;
do
{
v4 = v3++;
strcat(dest, &src[512 * v4]);
strcat(dest, "/");
}
while ( v16 - 1 > v3 );
v5 = ((unsigned __int64)(unsigned int)(v16 - 1) << 9) + 4;
}
strcpy(s2, (const char *)&v16 + v5);
v10 = 0LL;
fs_split_path(dest, &v16);
v6 = fs_get_fs_driver((__int64)dest);
if ( v6 )
{
for ( i = 0; (unsigned int)fs_readdir2((__int64)dest, i, (__int64)s1) && strcmp(s1, s2); ++i )
v14 = 0;
if ( !v14 )
{
if ( *a2 != 119 )
return 0LL;
fs_get_node(dest, &v10);
if ( !v10 )
return 0LL;
fs_create_node(s2, v10, 1LL, 0LL);
if ( !v10 )
return 0LL;
LABEL_18:
BUG();
}
fs_get_node(dest, &v11);
v9 = *(void (__fastcall **)(__int64, _QWORD, __int64 *))(v6 + 328);
if ( v9 && v11 )
v9(v11, v14, &v10);
if ( v10 && *(_BYTE *)(v10 + 260) == 1 )
goto LABEL_18;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _BYTE *a2)
{
unsigned int v3; // ebp
__int64 v4; // rax
unsigned __int64 v5; // rsi
__int64 v6; // r12
unsigned int i; // ebp
void (__fastcall *v9)(__int64, _QWORD, __int64 *); // rax
__int64 v10; // [rsp+0h] [rbp-4648h] BYREF
__int64 v11; // [rsp+8h] [rbp-4640h] BYREF
char s2[256]; // [rsp+10h] [rbp-4638h] BYREF
char s1[256]; // [rsp+110h] [rbp-4538h] BYREF
unsigned int v14; // [rsp+210h] [rbp-4438h]
char dest[1024]; // [rsp+220h] [rbp-4428h] BYREF
int v16; // [rsp+620h] [rbp-4028h] BYREF
char src[16420]; // [rsp+624h] [rbp-4024h] BYREF

debug_puts("fs_open()\n");
fs_split_path(a1, &v16);
strcpy(dest, "/");
if ( v16 == 1 )
{
v5 = 4LL;
}
else
{
v3 = 0;
do
{
v4 = v3++;
strcat(dest, &src[512 * v4]);
strcat(dest, "/");
}
while ( v16 - 1 > v3 );
v5 = ((unsigned __int64)(unsigned int)(v16 - 1) << 9) + 4;
}
strcpy(s2, (const char *)&v16 + v5);
v10 = 0LL;
fs_split_path(dest, &v16);
v6 = func0((__int64)dest);
if ( v6 )
{
for ( i = 0; (unsigned int)func10((__int64)dest, i, (__int64)s1) && strcmp(s1, s2); ++i )
v14 = 0;
if ( !v14 )
{
if ( *a2 != 119 )
return 0LL;
fs_get_node(dest, &v10);
if ( !v10 )
return 0LL;
fs_create_node(s2, v10, 1LL, 0LL);
if ( !v10 )
return 0LL;
LABEL_18:
BUG();
}
fs_get_node(dest, &v11);
v9 = *(void (__fastcall **)(__int64, _QWORD, __int64 *))(v6 + 328);
if ( v9 && v11 )
v9(v11, v14, &v10);
if ( v10 && *(_BYTE *)(v10 + 260) == 1 )
goto LABEL_18;
}
return 0LL;
}

original_code:
file_t *fs_open(char *path_, char *flags)
{
 debug_puts("fs_open()\n");
 file_t *f = 0;
 fs_splitted_path sp;
 char path[1024];
 char name[255];
 uint32_t i;
 struct dirent dir;
 fs_split_path(path_, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 inode_t *node = 0;
 fs_split_path(path, &sp);
 driver_t *drv = fs_get_fs_driver(path);
 driver_fs_t *filesystem_struct;
 if(drv == 0)
  return (file_t *) 0;
 filesystem_struct = &drv->fs;
 i = 0;
 while(fs_readdir2(path, i, &dir) != 0)
 {
  if(strcmp(dir.name, name) == 0)
   break;
  else
   dir.inode = 0;
  i++;
 }
 if((dir.inode == 0) && (flags[0] == 'w'))
 {
  fs_get_node(path, &node);
  if(node != 0)
   fs_create_node(name, node, 1, 0);
  else
   return 0;
 }
 else if(dir.inode == 0)
 {
  return 0;
 }
 else if(dir.inode != 0)
 {
  inode_t *node_tmp;
  fs_get_node(path, &node_tmp);
  if(filesystem_struct->get_node != 0 && node_tmp != 0)
   filesystem_struct->get_node(node_tmp, dir.inode, &node);
  if(node == 0 || node->type != 1)
   return 0;
 }
 if(node == 0)
   return 0;
 f->node->fs_driver = filesystem_struct;
 if(filesystem_struct->open != 0)
 {
  if(!filesystem_struct->open(node, flags))
   return (file_t *) 0;
 }
 f = (file_t *) malloc(sizeof(file_t));
 f->next = file_list;
 f->drv = (void *) drv;
 f->node = node;
 file_list = f;
 f->id = files_open_n++;
 f->seek_p = 0;
 return f;
}

canonical_original_code:
struct file_p *fs_open(char *path_, char *flags)
{
 debug_puts("fs_open()\n");
 struct file_p *f = 0;
 struct fs_splitted_path sp;
 char path[1024];
 char name[255];
 unsigned int i;
 struct dirent dir;
 fs_split_path(path_, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 struct inode_p *node = 0;
 fs_split_path(path, &sp);
 struct driver_p *drv = fs_get_fs_driver(path);
 struct driver_fs_t *filesystem_struct;
 if(drv == 0)
  return (struct file_p *) 0;
 filesystem_struct = &drv->fs;
 i = 0;
 while(fs_readdir2(path, i, &dir) != 0)
 {
  if(strcmp(dir.name, name) == 0)
   break;
  else
   dir.inode = 0;
  i++;
 }
 if((dir.inode == 0) && (flags[0] == 'w'))
 {
  fs_get_node(path, &node);
  if(node != 0)
   fs_create_node(name, node, 1, 0);
  else
   return 0;
 }
 else if(dir.inode == 0)
 {
  return 0;
 }
 else if(dir.inode != 0)
 {
  struct inode_p *node_tmp;
  fs_get_node(path, &node_tmp);
  if(filesystem_struct->get_node != 0 && node_tmp != 0)
   filesystem_struct->get_node(node_tmp, dir.inode, &node);
  if(node == 0 || node->type != 1)
   return 0;
 }
 if(node == 0)
   return 0;
 f->node->fs_driver = filesystem_struct;
 if(filesystem_struct->open != 0)
 {
  if(!filesystem_struct->open(node, flags))
   return (struct file_p *) 0;
 }
 f = (struct file_p *) malloc(sizeof(file_t));
 f->next = file_list;
 f->drv = (void *) drv;
 f->node = node;
 file_list = f;
 f->id = files_open_n++;
 f->seek_p = 0;
 return f;
}

variable_types:
flags
char *

variable_types:
path
char [1024]

variable_types: struct dirent { char name[255]; unsigned int inode; }

return_type: struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *node; void *drv; struct file_p *next; } *


decompiled_code:
__int64 __fastcall fs_readdir(__int64 a1, __int64 a2)
{
unsigned int v3; // esi

debug_puts("fs_readdir()\n");
if ( !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v3 + 1;
return fs_readdir2(a1 + 20, v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
unsigned int v3; // esi

debug_puts("fs_readdir()\n");
if ( !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v3 + 1;
return func10(a1 + 20, v3, a2);
}

original_code:
uint32_t fs_readdir(dir_t *dr, struct dirent *dir)
{
 debug_puts("fs_readdir()\n");
 if(dr == 0)
  return 0;
 dr->cur_i++;
 return fs_readdir2(dr->path, (dr->cur_i - 1), dir);
}

canonical_original_code:
unsigned int fs_readdir(struct dir_p *dr, struct dirent *dir)
{
 debug_puts("fs_readdir()\n");
 if(dr == 0)
  return 0;
 dr->cur_i++;
 return fs_readdir2(dr->path, (dr->cur_i - 1), dir);
}


decompiled_code:
__int64 __fastcall fs_link(__int64 a1, __int64 a2)
{
unsigned int v3; // ebx
__int64 v4; // rax
unsigned __int64 v5; // rsi
unsigned int v6; // ebx
__int64 v7; // r12
__int64 result; // rax
void (__fastcall *v9)(__int64, _QWORD, __int64 *); // rax
unsigned int v10; // ebx
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rsi
__int64 v14; // [rsp+8h] [rbp-8B60h] BYREF
__int64 v15; // [rsp+10h] [rbp-8B58h] BYREF
__int64 v16; // [rsp+18h] [rbp-8B50h] BYREF
char s2[256]; // [rsp+20h] [rbp-8B48h] BYREF
char v18[256]; // [rsp+120h] [rbp-8A48h] BYREF
char s1[256]; // [rsp+220h] [rbp-8948h] BYREF
unsigned int v20; // [rsp+320h] [rbp-8848h]
char dest[1024]; // [rsp+330h] [rbp-8838h] BYREF
char v22[1024]; // [rsp+730h] [rbp-8438h] BYREF
int v23; // [rsp+B30h] [rbp-8038h] BYREF
char src[16396]; // [rsp+B34h] [rbp-8034h] BYREF
int v25; // [rsp+4B40h] [rbp-4028h] BYREF
char v26[16420]; // [rsp+4B44h] [rbp-4024h] BYREF

debug_puts("fs_link()\n");
fs_split_path(a1, &v23);
strcpy(dest, "/");
if ( v23 == 1 )
{
v5 = 4LL;
}
else
{
v3 = 0;
do
{
v4 = v3++;
strcat(dest, &src[512 * v4]);
strcat(dest, "/");
}
while ( v23 - 1 > v3 );
v5 = ((unsigned __int64)(unsigned int)(v23 - 1) << 9) + 4;
}
v6 = 0;
strcpy(s2, (const char *)&v23 + v5);
v14 = 0LL;
fs_split_path(dest, &v23);
v7 = fs_get_fs_driver((__int64)dest);
if ( !v7 )
return 1LL;
while ( (unsigned int)fs_readdir2((__int64)dest, v6, (__int64)s1) && strcmp(s1, s2) )
{
v20 = 0;
++v6;
}
if ( !v20 )
return 1LL;
fs_get_node(dest, &v15);
v9 = *(void (__fastcall **)(__int64, _QWORD, __int64 *))(v7 + 328);
if ( v9 && v15 )
v9(v15, v20, &v14);
if ( !v14 )
return 1LL;
result = 3LL;
if ( *(_QWORD *)(v7 + 400) )
{
fs_split_path(a2, &v25);
strcpy(v22, "/");
if ( v25 == 1 )
{
v13 = 4LL;
}
else
{
v10 = 0;
do
{
v11 = v10++;
strcat(v22, &v26[512 * v11]);
strcat(v22, "/");
v12 = (unsigned int)(v25 - 1);
}
while ( (unsigned int)v12 > v10 );
v13 = (v12 << 9) + 4;
}
strcpy(v18, (const char *)&v25 + v13);
fs_get_node(v22, &v16);
if ( v16 )
return (*(__int64 (__fastcall **)(__int64, char *, __int64, char *))(v7 + 400))(v15, s2, v16, v18);
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
unsigned int v3; // ebx
__int64 v4; // rax
unsigned __int64 v5; // rsi
unsigned int v6; // ebx
__int64 v7; // r12
__int64 result; // rax
void (__fastcall *v9)(__int64, _QWORD, __int64 *); // rax
unsigned int v10; // ebx
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rsi
__int64 v14; // [rsp+8h] [rbp-8B60h] BYREF
__int64 v15; // [rsp+10h] [rbp-8B58h] BYREF
__int64 v16; // [rsp+18h] [rbp-8B50h] BYREF
char s2[256]; // [rsp+20h] [rbp-8B48h] BYREF
char v18[256]; // [rsp+120h] [rbp-8A48h] BYREF
char s1[256]; // [rsp+220h] [rbp-8948h] BYREF
unsigned int v20; // [rsp+320h] [rbp-8848h]
char dest[1024]; // [rsp+330h] [rbp-8838h] BYREF
char v22[1024]; // [rsp+730h] [rbp-8438h] BYREF
int v23; // [rsp+B30h] [rbp-8038h] BYREF
char src[16396]; // [rsp+B34h] [rbp-8034h] BYREF
int v25; // [rsp+4B40h] [rbp-4028h] BYREF
char v26[16420]; // [rsp+4B44h] [rbp-4024h] BYREF

debug_puts("fs_link()\n");
fs_split_path(a1, &v23);
strcpy(dest, "/");
if ( v23 == 1 )
{
v5 = 4LL;
}
else
{
v3 = 0;
do
{
v4 = v3++;
strcat(dest, &src[512 * v4]);
strcat(dest, "/");
}
while ( v23 - 1 > v3 );
v5 = ((unsigned __int64)(unsigned int)(v23 - 1) << 9) + 4;
}
v6 = 0;
strcpy(s2, (const char *)&v23 + v5);
v14 = 0LL;
fs_split_path(dest, &v23);
v7 = func0((__int64)dest);
if ( !v7 )
return 1LL;
while ( (unsigned int)func10((__int64)dest, v6, (__int64)s1) && strcmp(s1, s2) )
{
v20 = 0;
++v6;
}
if ( !v20 )
return 1LL;
fs_get_node(dest, &v15);
v9 = *(void (__fastcall **)(__int64, _QWORD, __int64 *))(v7 + 328);
if ( v9 && v15 )
v9(v15, v20, &v14);
if ( !v14 )
return 1LL;
result = 3LL;
if ( *(_QWORD *)(v7 + 400) )
{
fs_split_path(a2, &v25);
strcpy(v22, "/");
if ( v25 == 1 )
{
v13 = 4LL;
}
else
{
v10 = 0;
do
{
v11 = v10++;
strcat(v22, &v26[512 * v11]);
strcat(v22, "/");
v12 = (unsigned int)(v25 - 1);
}
while ( (unsigned int)v12 > v10 );
v13 = (v12 << 9) + 4;
}
strcpy(v18, (const char *)&v25 + v13);
fs_get_node(v22, &v16);
if ( v16 )
return (*(__int64 (__fastcall **)(__int64, char *, __int64, char *))(v7 + 400))(v15, s2, v16, v18);
return 1LL;
}
return result;
}

original_code:
uint32_t fs_link(char *file_name, char *link_name)
{
 debug_puts("fs_link()\n");
 fs_splitted_path sp;
 char path[1024];
 char name[255];
 uint32_t i;
 struct dirent dir;
 fs_split_path(file_name, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 inode_t *node = 0;
 fs_split_path(path, &sp);
 driver_t *drv = fs_get_fs_driver(path);
 driver_fs_t *filesystem_struct;
 if(drv == 0)
  return 1;
 filesystem_struct = &drv->fs;
 i = 0;
 while(fs_readdir2(path, i, &dir) != 0)
 {
  if(strcmp(dir.name, name) == 0)
   break;
  else
   dir.inode = 0;
  i++;
 }
 inode_t *node_tmp;
 if(dir.inode == 0)
 {
  return 1;
 }
 else if(dir.inode != 0)
 {
  fs_get_node(path, &node_tmp);
  if(filesystem_struct->get_node != 0 && node_tmp != 0)
   filesystem_struct->get_node(node_tmp, dir.inode, &node);
 }
 if(node == 0)
  return 1;
 if(filesystem_struct->link != 0)
 {
  fs_splitted_path sp2;
  char path2[1024];
  char name2[255];
  fs_split_path(link_name, &sp2);
  strcpy(path2, "/");
  for(i = 0; i < (sp2.i - 1); i++)
  {
   strcat(path2, sp2.list[i]);
   strcat(path2, "/");
  }
  strcpy(name2, sp2.list[sp2.i - 1]);
  inode_t *dest_root;
  fs_get_node(path2, &dest_root);
  if(dest_root == 0)
   return 1;
  if(!filesystem_struct->link(node_tmp, name, dest_root, name2))
   return 0;
 }
 else
  return 3;
}

canonical_original_code:
unsigned int fs_link(char *file_name, char *link_name)
{
 debug_puts("fs_link()\n");
 struct fs_splitted_path sp;
 char path[1024];
 char name[255];
 unsigned int i;
 struct dirent dir;
 fs_split_path(file_name, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 struct inode_p *node = 0;
 fs_split_path(path, &sp);
 struct driver_p *drv = fs_get_fs_driver(path);
 struct driver_fs_t *filesystem_struct;
 if(drv == 0)
  return 1;
 filesystem_struct = &drv->fs;
 i = 0;
 while(fs_readdir2(path, i, &dir) != 0)
 {
  if(strcmp(dir.name, name) == 0)
   break;
  else
   dir.inode = 0;
  i++;
 }
 struct inode_p *node_tmp;
 if(dir.inode == 0)
 {
  return 1;
 }
 else if(dir.inode != 0)
 {
  fs_get_node(path, &node_tmp);
  if(filesystem_struct->get_node != 0 && node_tmp != 0)
   filesystem_struct->get_node(node_tmp, dir.inode, &node);
 }
 if(node == 0)
  return 1;
 if(filesystem_struct->link != 0)
 {
  struct fs_splitted_path sp2;
  char path2[1024];
  char name2[255];
  fs_split_path(link_name, &sp2);
  strcpy(path2, "/");
  for(i = 0; i < (sp2.i - 1); i++)
  {
   strcat(path2, sp2.list[i]);
   strcat(path2, "/");
  }
  strcpy(name2, sp2.list[sp2.i - 1]);
  struct inode_p *dest_root;
  fs_get_node(path2, &dest_root);
  if(dest_root == 0)
   return 1;
  if(!filesystem_struct->link(node_tmp, name, dest_root, name2))
   return 0;
 }
 else
  return 3;
}

variable_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *


decompiled_code:
__int64 __fastcall fs_unlink(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-4530h] BYREF
char v9[256]; // [rsp+10h] [rbp-4528h] BYREF
char dest[1024]; // [rsp+110h] [rbp-4428h] BYREF
int v11; // [rsp+510h] [rbp-4028h] BYREF
char src[16420]; // [rsp+514h] [rbp-4024h] BYREF

debug_puts("fs_unlink()\n");
v8 = 0LL;
fs_split_path(a1, &v11);
strcpy(dest, "/");
if ( v11 == 1 )
{
v4 = 4LL;
}
else
{
v1 = 0;
do
{
v2 = v1++;
strcat(dest, &src[512 * v2]);
strcat(dest, "/");
v3 = (unsigned int)(v11 - 1);
}
while ( (unsigned int)v3 > v1 );
v4 = (v3 << 9) + 4;
}
strcpy(v9, (const char *)&v11 + v4);
fs_get_node(dest, &v8);
if ( !v8 )
return 0LL;
v5 = fs_get_fs_driver((__int64)dest);
if ( !v5 )
return 0LL;
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 408);
if ( v6 )
result = v6(v8, v9);
else
result = 3LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-4530h] BYREF
char v9[256]; // [rsp+10h] [rbp-4528h] BYREF
char dest[1024]; // [rsp+110h] [rbp-4428h] BYREF
int v11; // [rsp+510h] [rbp-4028h] BYREF
char src[16420]; // [rsp+514h] [rbp-4024h] BYREF

debug_puts("fs_unlink()\n");
v8 = 0LL;
fs_split_path(a1, &v11);
strcpy(dest, "/");
if ( v11 == 1 )
{
v4 = 4LL;
}
else
{
v1 = 0;
do
{
v2 = v1++;
strcat(dest, &src[512 * v2]);
strcat(dest, "/");
v3 = (unsigned int)(v11 - 1);
}
while ( (unsigned int)v3 > v1 );
v4 = (v3 << 9) + 4;
}
strcpy(v9, (const char *)&v11 + v4);
fs_get_node(dest, &v8);
if ( !v8 )
return 0LL;
v5 = func0((__int64)dest);
if ( !v5 )
return 0LL;
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 408);
if ( v6 )
result = v6(v8, v9);
else
result = 3LL;
return result;
}

original_code:
uint32_t fs_unlink(char *path_)
{
 debug_puts("fs_unlink()\n");
 fs_splitted_path sp;
 inode_t *node = 0;
 char path[1024];
 char name[255];
 uint32_t i;
 fs_split_path(path_, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 fs_get_node(path, &node);
 if(node == 0)
  return 0;
 driver_t *drv = fs_get_fs_driver(path);
 driver_fs_t *filesystem_struct;
 if(drv != 0)
  filesystem_struct = &drv->fs;
 else
  return 0;
 if(filesystem_struct->unlink != 0)
  return filesystem_struct->unlink(node, name);
 else
 {
  return 3;
 }
}

canonical_original_code:
unsigned int fs_unlink(char *path_)
{
 debug_puts("fs_unlink()\n");
 struct fs_splitted_path sp;
 struct inode_p *node = 0;
 char path[1024];
 char name[255];
 unsigned int i;
 fs_split_path(path_, &sp);
 strcpy(path, "/");
 for(i = 0; i < (sp.i - 1); i++)
 {
  strcat(path, sp.list[i]);
  strcat(path, "/");
 }
 strcpy(name, sp.list[sp.i - 1]);
 fs_get_node(path, &node);
 if(node == 0)
  return 0;
 struct driver_p *drv = fs_get_fs_driver(path);
 struct driver_fs_t *filesystem_struct;
 if(drv != 0)
  filesystem_struct = &drv->fs;
 else
  return 0;
 if(filesystem_struct->unlink != 0)
  return filesystem_struct->unlink(node, name);
 else
 {
  return 3;
 }
}


decompiled_code:
int __fastcall sock_shutdown(int a1)
{
LODWORD(sockets[2056 * a1 + 4]) = 0;
return printf("shutdown ok\n");
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
LODWORD(sockets[2056 * a1 + 4]) = 0;
return printf("shutdown ok\n");
}

original_code:
int sock_shutdown(int sockfd, int how)
{
 {
  sockets[sockfd].used = 0;
  printf("shutdown ok\n");
 }
}

variable_types: sockfd int

variable_types: how int

return_type: int


decompiled_code:
__int64 __fastcall sock_connect(int a1, __int64 a2, unsigned int a3)
{
unsigned int i; // ebx
__int64 result; // rax
__int64 v6[6]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0; ; ++i )
{
result = route_iget(i, v6);
if ( !(_DWORD)result )
break;
if ( !strncmp((const char *)(a2 + 4), (const char *)(v6[0] + 4), a3) )
{
sockets[2056 * a1] = *(_QWORD *)(v6[0] + 24);
printf("found a valid routing rule for this address\n");
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2, unsigned int a3)
{
unsigned int i; // ebx
__int64 result; // rax
__int64 v6[6]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0; ; ++i )
{
result = route_iget(i, v6);
if ( !(_DWORD)result )
break;
if ( !strncmp((const char *)(a2 + 4), (const char *)(v6[0] + 4), a3) )
{
sockets[2056 * a1] = *(_QWORD *)(v6[0] + 24);
printf("found a valid routing rule for this address\n");
return 0LL;
}
}
return result;
}

original_code:
int sock_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
 int i = 0;
 route_entry_t *re;
 while(route_iget(i, &re))
 {
  if(strncmp((char *) addr->sa_data, (char *) re->dest, addrlen) == 0)
  {
   sockets[sockfd].iface = re->iface;
   printf("found a valid routing rule for this address\n");
   return 0;
  }
  i++;
 }
}

canonical_original_code:
int sock_connect(int sockfd, struct sockaddr *addr, unsigned int addrlen)
{
 int i = 0;
 struct route_entry_p *re;
 while(route_iget(i, &re))
 {
  if(strncmp((char *) addr->sa_data, (char *) re->dest, addrlen) == 0)
  {
   sockets[sockfd].iface = re->iface;
   printf("found a valid routing rule for this address\n");
   return 0;
  }
  i++;
 }
}

variable_types: struct sockaddr { unsigned int sa_family; char sa_data[14]; } *

variable_types:
addrlen
unsigned int

variable_types: i int

variable_types: struct route_entry_p { char gw[4]; char dest[4]; char genmask[4]; unsigned char addr_len; unsigned char if_net; unsigned int flags; struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *iface; struct route_entry_p *next; } *

user_defined_types: struct route_entry_p { char gw[4]; char dest[4]; char genmask[4]; unsigned char addr_len; unsigned char if_net; unsigned int flags; struct network_iface_p *iface; struct route_entry_p *next; }

user_defined_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; }


decompiled_code:
void sock_sendto()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
uint32_t sock_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
{
}

canonical_original_code:
unsigned int sock_sendto(int sockfd, void *buf, unsigned int len, int flags, struct sockaddr *dest_addr, unsigned int addrlen)
{
}

variable_types:
buf
void *

variable_types:
len
unsigned int

variable_types: flags int

user_defined_types: struct sockaddr { unsigned int sa_family; char sa_data[14]; }


decompiled_code:
void sock_recvfrom()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
uint32_t sock_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
{
}

canonical_original_code:
unsigned int sock_recvfrom(int sockfd, void *buf, unsigned int len, int flags, struct sockaddr *src_addr, unsigned int *addrlen)
{
}

variable_types:
addrlen
unsigned int *


decompiled_code:
__int64 __fastcall sock_iget(unsigned int a1, _QWORD *a2)
{
__int64 result; // rax

result = 0LL;
if ( a1 <= 0x400 )
{
result = 1LL;
*a2 = &sockets[2056 * a1];
}
return result;
}

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

result = 0LL;
if ( a1 <= 0x400 )
{
result = 1LL;
*a2 = &sockets[2056 * a1];
}
return result;
}

original_code:
uint32_t sock_iget(uint32_t x, socket_t **s)
{
 if(x > 1024)
  return 0;
 *s = &sockets[x];
 return 1;
}

canonical_original_code:
unsigned int sock_iget(unsigned int x, struct socket_t **s)
{
 if(x > 1024)
  return 0;
 *s = &sockets[x];
 return 1;
}

variable_types:
x
unsigned int

variable_types: struct socket_t { struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *iface; unsigned int protocol; unsigned int type; unsigned int domain; unsigned char is_server; unsigned short port; char addr[4]; int uid; unsigned int used; char rec_buf[8192]; int rec_p1; int rec_p2; int rec_data_len; char send_buf[8192]; int send_p1; int send_p2; int send_data_len; } **

user_defined_types: struct socket_t { struct network_iface_p *iface; unsigned int protocol; unsigned int type; unsigned int domain; unsigned char is_server; unsigned short port; char addr[4]; int uid; unsigned int used; char rec_buf[8192]; int rec_p1; int rec_p2; int rec_data_len; char send_buf[8192]; int send_p1; int send_p2; int send_data_len; }


decompiled_code:
__int64 __fastcall sock_bind(unsigned int a1)
{
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-8h] BYREF

sock_iget(a1, &v3);
result = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_BYTE *)(v3 + 20) = 1;
*(_WORD *)(result + 22) = *(_DWORD *)(v1 + 4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-8h] BYREF

func5(a1, &v3);
result = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_BYTE *)(v3 + 20) = 1;
*(_WORD *)(result + 22) = *(_DWORD *)(v1 + 4);
return result;
}

original_code:
int sock_bind(int sockfd, const struct sockaddr_in *addr, socklen_t addrlen)
{
 socket_t *sock;
 sock_iget(sockfd, &sock);
 if(sock == 0)
  return -1;
 sock->is_server = 1;
 sock->port = addr->sin_port;
}

canonical_original_code:
int sock_bind(int sockfd, struct sockaddr_in *addr, unsigned int addrlen)
{
 struct socket_t *sock;
 sock_iget(sockfd, &sock);
 if(sock == 0)
  return -1;
 sock->is_server = 1;
 sock->port = addr->sin_port;
}

variable_types: struct sockaddr_in { unsigned int sin_family; unsigned int sin_port; struct in_addr { unsigned int s_addr; } sin_addr; } *

variable_types: struct socket_t { struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *iface; unsigned int protocol; unsigned int type; unsigned int domain; unsigned char is_server; unsigned short port; char addr[4]; int uid; unsigned int used; char rec_buf[8192]; int rec_p1; int rec_p2; int rec_data_len; char send_buf[8192]; int send_p1; int send_p2; int send_data_len; } *

user_defined_types: struct sockaddr_in { unsigned int sin_family; unsigned int sin_port; struct in_addr sin_addr; }


decompiled_code:
__int64 __fastcall sock_send(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

sock_iget(a1, v5);
printf("sending sock pack\n");
result = 0xFFFFFFFFLL;
if ( v5[0] )
{
result = packet_create(a2, a3);
if ( *(_DWORD *)(v5[0] + 12) == 2 )
result = udp_send_packet(v5[0], result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

func5(a1, v5);
printf("sending sock pack\n");
result = 0xFFFFFFFFLL;
if ( v5[0] )
{
result = packet_create(a2, a3);
if ( *(_DWORD *)(v5[0] + 12) == 2 )
result = udp_send_packet(v5[0], result);
}
return result;
}

original_code:
uint32_t sock_send(int sockfd, const void *buf, size_t len, int flags)
{
 socket_t *sock;
 sock_iget(sockfd, &sock);
 printf("sending sock pack\n");
 if(sock == 0)
  return -1;
 packet_t *p = packet_create((char *) buf, len);
 if(sock->type == 0x02)
  return udp_send_packet(sock, p);
}

canonical_original_code:
unsigned int sock_send(int sockfd, void *buf, unsigned int len, int flags)
{
 struct socket_t *sock;
 sock_iget(sockfd, &sock);
 printf("sending sock pack\n");
 if(sock == 0)
  return -1;
 struct packet_t *p = packet_create((char *) buf, len);
 if(sock->type == 0x02)
  return udp_send_packet(sock, p);
}

variable_types: struct packet_t { unsigned int size; char *data; } *


original_code:
uint32_t sock_recv(int sockfd, void *buf_, size_t len, int flags)
{
 socket_t *sock;
 sock_iget(sockfd, &sock);
 if(sock == 0)
  return -1;
 if(sock->rec_data_len > 0)
 {
  unsigned i;
  for(i = 0; i < len; i++)
  {
   char *buf = buf_;
   buf[i] = sock->rec_buf[sock->rec_p2];
   sock->rec_p2++;
   if(sock->rec_p2 >= sock->rec_p1)
    return i;
   sock->rec_data_len--;
  }
  return len;
 }
 return -1;
}

canonical_original_code:
unsigned int sock_recv(int sockfd, void *buf_, unsigned int len, int flags)
{
 struct socket_t *sock;
 sock_iget(sockfd, &sock);
 if(sock == 0)
  return -1;
 if(sock->rec_data_len > 0)
 {
  unsigned int i;
  for(i = 0; i < len; i++)
  {
   char *buf = buf_;
   buf[i] = sock->rec_buf[sock->rec_p2];
   sock->rec_p2++;
   if(sock->rec_p2 >= sock->rec_p1)
    return i;
   sock->rec_data_len--;
  }
  return len;
 }
 return -1;
}

variable_types:
i
unsigned int

variable_types:
buf
char *


decompiled_code:
int sock_test()
{
unsigned int v0; // ebp
unsigned int v1; // er12
int result; // eax
char v3[16]; // [rsp+10h] [rbp-48h] BYREF
int v4; // [rsp+20h] [rbp-38h] BYREF
char v5[52]; // [rsp+24h] [rbp-34h] BYREF

printf("\nsock_test()\n");
v0 = socket(1LL, 2);
sock_bind(v0);
v1 = socket(1LL, 2);
network_toaddr(v5, 127LL, 0LL, 0LL, 1LL);
v4 = 1;
sock_connect(v1, (__int64)&v4, 4u);
sock_send(v1, (__int64)"ciao", 5u);
result = sock_recv(v0);
if ( result != -1 )
result = printf("Received packet data: %s\n\n", v3);
return result;
}

canonical_decompiled_code:
int func9()
{
unsigned int v0; // ebp
unsigned int v1; // er12
int result; // eax
char v3[16]; // [rsp+10h] [rbp-48h] BYREF
int v4; // [rsp+20h] [rbp-38h] BYREF
char v5[52]; // [rsp+24h] [rbp-34h] BYREF

printf("\nsock_test()\n");
v0 = func0(1LL, 2);
func6(v0);
v1 = func0(1LL, 2);
network_toaddr(v5, 127LL, 0LL, 0LL, 1LL);
v4 = 1;
func2(v1, (__int64)&v4, 4u);
func7(v1, (__int64)"ciao", 5u);
result = func8(v0);
if ( result != -1 )
result = printf("Received packet data: %s\n\n", v3);
return result;
}

original_code:
void sock_test()
{
 printf("\nsock_test()\n");
 int sock_s = socket(0x01, 0x02, 0);
 struct sockaddr_in s;
 s.sin_family = 0x01;
    s.sin_port = 24;
 sock_bind(sock_s, &s, sizeof(s));
 int sock_c = socket(0x01, 0x02, 0);
 struct sockaddr c;
 network_toaddr(c.sa_data, 127, 0, 0, 1);
 c.sa_family = 0x01;
 sock_connect(sock_c, &c, 4);
 sock_send(sock_c, "ciao\0", 5, 0);
 char buf[16];
 if(sock_recv(sock_s, buf, 16, 0) != -1)
  printf("Received packet data: %s\n\n", buf);
}

variable_types: struct sockaddr_in { unsigned int sin_family; unsigned int sin_port; struct in_addr { unsigned int s_addr; } sin_addr; }

variable_types: struct sockaddr { unsigned int sa_family; char sa_data[14]; }

variable_types:
buf
char [16]

return_type: void


socket

decompiled_code:
__int64 __fastcall socket(__int64 a1, int a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
int v4; // er8
__int64 *v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
unsigned int v8; // edx
__int64 v9; // rax
int v10; // ecx

v2 = sock_first_free;
v3 = task_get_pid();
v4 = task_get_uid(v3);
v5 = &sockets[2056 * (int)v2];
*((_DWORD *)v5 + 7) = v4;
if ( a2 == 2 )
{
*((_DWORD *)v5 + 3) = 2;
}
else
{
if ( a2 != 1 )
return (unsigned int)-1;
*((_DWORD *)v5 + 3) = 1;
}
v6 = (unsigned int)sock_first_free;
v7 = 2056LL * (int)v2;
LODWORD(sockets[v7 + 4]) = 1;
HIDWORD(sockets[v7 + 1028]) = 0;
sockets[v7 + 1029] = 0LL;
sockets[v7 + 2054] = 0LL;
LODWORD(sockets[v7 + 2055]) = 0;
sockets[v7] = 0LL;
if ( LODWORD(sockets[2056 * v6 + 4]) )
{
v8 = v6 + 1;
do
{
v9 = 257LL * v8;
v10 = v8++;
}
while ( LODWORD(sockets[8 * v9 + 4]) );
sock_first_free = v10;
}
printf("created socket %d\n", v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
int v4; // er8
__int64 *v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
unsigned int v8; // edx
__int64 v9; // rax
int v10; // ecx

v2 = sock_first_free;
v3 = task_get_pid();
v4 = task_get_uid(v3);
v5 = &sockets[2056 * (int)v2];
*((_DWORD *)v5 + 7) = v4;
if ( a2 == 2 )
{
*((_DWORD *)v5 + 3) = 2;
}
else
{
if ( a2 != 1 )
return (unsigned int)-1;
*((_DWORD *)v5 + 3) = 1;
}
v6 = (unsigned int)sock_first_free;
v7 = 2056LL * (int)v2;
LODWORD(sockets[v7 + 4]) = 1;
HIDWORD(sockets[v7 + 1028]) = 0;
sockets[v7 + 1029] = 0LL;
sockets[v7 + 2054] = 0LL;
LODWORD(sockets[v7 + 2055]) = 0;
sockets[v7] = 0LL;
if ( LODWORD(sockets[2056 * v6 + 4]) )
{
v8 = v6 + 1;
do
{
v9 = 257LL * v8;
v10 = v8++;
}
while ( LODWORD(sockets[8 * v9 + 4]) );
sock_first_free = v10;
}
printf("created socket %d\n", v2);
return v2;
}

original_code:
int socket(uint32_t domain, uint32_t type, uint32_t protocol)
{
 int sock;
 sock = sock_first_free;
 sockets[sock].uid = task_get_uid(task_get_pid());
  if(type == 0x02)
  {
   sockets[sock].type = 0x02;
  }
  else if(type == 0x01)
  {
   sockets[sock].type = 0x01;
  }
  else
  {
   return -1;
  }
 sockets[sock].used = 1;
 sockets[sock].send_p1 = sockets[sock].send_p2 = 0;
 sockets[sock].rec_p1 = sockets[sock].rec_p2 = 0;
 sockets[sock].send_data_len = sockets[sock].rec_data_len = 0;
 sockets[sock].iface = 0;
 while(sockets[sock_first_free].used)
  sock_first_free++;
 printf("created socket %d\n", sock);
 return sock;
}

canonical_original_code:
int socket(unsigned int domain, unsigned int type, unsigned int protocol)
{
 int sock;
 sock = sock_first_free;
 sockets[sock].uid = task_get_uid(task_get_pid());
  if(type == 0x02)
  {
   sockets[sock].type = 0x02;
  }
  else if(type == 0x01)
  {
   sockets[sock].type = 0x01;
  }
  else
  {
   return -1;
  }
 sockets[sock].used = 1;
 sockets[sock].send_p1 = sockets[sock].send_p2 = 0;
 sockets[sock].rec_p1 = sockets[sock].rec_p2 = 0;
 sockets[sock].send_data_len = sockets[sock].rec_data_len = 0;
 sockets[sock].iface = 0;
 while(sockets[sock_first_free].used)
  sock_first_free++;
 printf("created socket %d\n", sock);
 return sock;
}

variable_types:
domain
unsigned int

variable_types:
type
unsigned int

variable_types:
protocol
unsigned int

variable_types: sock int


decompiled_code:
__int64 ata_pio_probe()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
uint32_t ata_pio_probe(device_t *dev)
{
 return 1;
}

canonical_original_code:
unsigned int ata_pio_probe(struct device_p *dev)
{
 return 1;
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *


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

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

original_code:
uint32_t ata_pio_free()
{
 return 0;
}

canonical_original_code:
unsigned int ata_pio_free()
{
 return 0;
}


decompiled_code:
void ata_pio_read()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
uint32_t ata_pio_read(device_t *dev, char *data, uint32_t size, uint64_t off)
{
}

canonical_original_code:
unsigned int ata_pio_read(struct device_p *dev, char *data, unsigned int size, unsigned long long off)
{
}

variable_types:
data
char *

variable_types:
size
unsigned int

variable_types:
off
unsigned long long


decompiled_code:
__int64 ata_pio_init()
{
devfs_reg_device(0LL, 0LL, "ata0");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
devfs_reg_device(0LL, 0LL, "ata0");
return 0LL;
}

original_code:
uint32_t ata_pio_init()
{
 devfs_reg_device(0, 0, "ata0");
 return 0;
}

canonical_original_code:
unsigned int ata_pio_init()
{
 devfs_reg_device(0, 0, "ata0");
 return 0;
}


decompiled_code:
// attributes: thunk
void ata_pio_write()
{
ata_pio_read_constprop_0();
}

canonical_decompiled_code:
void func5()
{
func4();
}

original_code:
uint32_t ata_pio_write(device_t *dev, char *data, uint32_t size, uint64_t off)
{
}

canonical_original_code:
unsigned int ata_pio_write(struct device_p *dev, char *data, unsigned int size, unsigned long long off)
{
}


connect

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

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

original_code:
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
 return 0;
}

canonical_original_code:
int connect(int sockfd, struct sockaddr *addr, unsigned int addrlen)
{
 return 0;
}

variable_types: sockfd int

variable_types:
addr
struct sockaddr { char a; } *

variable_types:
addrlen
unsigned int


send

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

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

original_code:
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
{
 return 0;
}

canonical_original_code:
unsigned int send(int sockfd, void *buf, unsigned int len, int flags)
{
 return 0;
}

variable_types:
buf
void *

variable_types:
len
unsigned int

variable_types: flags int


sendto

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

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

original_code:
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
{
 return 0;
}

canonical_original_code:
unsigned int sendto(int sockfd, void *buf, unsigned int len, int flags, struct sockaddr *dest_addr, unsigned int addrlen)
{
 return 0;
}


recv

decompiled_code:
// attributes: thunk
__int64 recv()
{
return send_constprop_0();
}

canonical_decompiled_code:
__int64 func5()
{
return func0();
}

original_code:
ssize_t recv(int sockfd, void *buf, size_t len, int flags)
{
 return 0;
}

canonical_original_code:
unsigned int recv(int sockfd, void *buf, unsigned int len, int flags)
{
 return 0;
}


recvfrom

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

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

original_code:
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
{
 return 0;
}

canonical_original_code:
unsigned int recvfrom(int sockfd, void *buf, unsigned int len, int flags, struct sockaddr *src_addr, unsigned int *addrlen)
{
 return 0;
}

variable_types:
addrlen
unsigned int *


shutdown

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

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

original_code:
int shutdown(int sockfd, int how)
{
 return 0;
}

variable_types: how int


socket

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

original_code:
int socket(int domain, int type, int protocol)
{
 return 0;
}

variable_types: domain int

variable_types: type int

variable_types: protocol int


decompiled_code:
_BOOL8 log_stat()
{
return log_file != 0;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return log_file != 0;
}

original_code:
uint32_t log_stat()
{
 if(log_file != 0)
  return 1;
 else
  return 0;
}

canonical_original_code:
unsigned int log_stat()
{
 if(log_file != 0)
  return 1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall log_write(const char *a1)
{
unsigned int v2; // eax

if ( !log_file )
return 0LL;
v2 = strlen(a1);
return fs_write(log_file, a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v2; // eax

if ( !log_file )
return 0LL;
v2 = strlen(a1);
return fs_write(log_file, a1, v2);
}

original_code:
uint32_t log_write(char *buf)
{
 if(log_file != 0)
  return fs_write(log_file, buf, strlen(buf));
 return 0;
}

canonical_original_code:
unsigned int log_write(char *buf)
{
 if(log_file != 0)
  return fs_write(log_file, buf, strlen(buf));
 return 0;
}

variable_types:
buf
char *


decompiled_code:
__int64 log_init()
{
fs_makedir("/log");
log_file = fs_open("/log/syslog.txt", "w");
return log_write("log started\n");
}

canonical_decompiled_code:
__int64 func2()
{
fs_makedir("/log");
log_file = fs_open("/log/syslog.txt", "w");
return func1("log started\n");
}

original_code:
void log_init()
{
 fs_makedir("/log");
 log_file = fs_open("/log/syslog.txt", "w");
 log_write("log started\n");
}


strlen

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
_BYTE *v1; // rax
unsigned int v2; // er8

v1 = a1 + 1;
if ( !*a1 )
return 0LL;
do
v2 = (_DWORD)v1++ - (_DWORD)a1;
while ( *(v1 - 1) );
return v2;
}

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

v1 = a1 + 1;
if ( !*a1 )
return 0LL;
do
v2 = (_DWORD)v1++ - (_DWORD)a1;
while ( *(v1 - 1) );
return v2;
}

original_code:
size_t strlen(const char *str)
{
 size_t x = 0;
 while(*str++ != '\0') x++;
 return x;
}

canonical_original_code:
unsigned int strlen(char *str)
{
 unsigned int x = 0;
 while(*str++ != '\0') x++;
 return x;
}

variable_types:
str
char *

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall strncpy2(_BYTE *a1, __int64 a2, unsigned int a3)
{
return strcpy(a1, (unsigned __int8 *)(a3 + a2));
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2, unsigned int a3)
{
return func1(a1, (unsigned __int8 *)(a3 + a2));
}

original_code:
void strncpy2(char *str1, char *str2, size_t n)
{
 int i = 0;
 str2 = str2 + n;
 strcpy(str1, str2);
}

canonical_original_code:
void strncpy2(char *str1, char *str2, unsigned int n)
{
 int i = 0;
 str2 = str2 + n;
 strcpy(str1, str2);
}

variable_types:
n
unsigned int

variable_types: i int


strcmp

decompiled_code:
__int64 __fastcall strcmp(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax

v2 = *a1;
if ( *a1 != *a2 )
return 1LL;
v3 = 1LL;
while ( v2 )
{
v2 = a1[v3++];
if ( v2 != a2[v3 - 1] )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax

v2 = *a1;
if ( *a1 != *a2 )
return 1LL;
v3 = 1LL;
while ( v2 )
{
v2 = a1[v3++];
if ( v2 != a2[v3 - 1] )
return 1LL;
}
return 0LL;
}

original_code:
int strcmp(const char *s1, const char *s2)
{
 while(1)
 {
  if(*s1 != *s2) return 1;
  else if(*s1 == '\0' && *s2 == '\0') return 0;
  s1++;
  s2++;
 }
}


strncmp

decompiled_code:
__int64 __fastcall strncmp(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
char v5; // dl

if ( !a3 )
return 0LL;
v3 = a3;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( v5 != *(_BYTE *)(a2 + v4) )
break;
if ( v5 )
{
if ( ++v4 != v3 )
continue;
}
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
char v5; // dl

if ( !a3 )
return 0LL;
v3 = a3;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( v5 != *(_BYTE *)(a2 + v4) )
break;
if ( v5 )
{
if ( ++v4 != v3 )
continue;
}
return 0LL;
}
return 1LL;
}

original_code:
int strncmp(const char *s1, const char *s2, size_t dim)
{
 int a = 0;
 while(a < dim)
 {
  if(*s1 != *s2) return 1;
  else if(*s1 == '\0' && *s2 == '\0') return 0;
  s1++;
  s2++;
  a++;
 }
 return 0;
}

canonical_original_code:
int strncmp(char *s1, char *s2, unsigned int dim)
{
 int a = 0;
 while(a < dim)
 {
  if(*s1 != *s2) return 1;
  else if(*s1 == '\0' && *s2 == '\0') return 0;
  s1++;
  s2++;
  a++;
 }
 return 0;
}

variable_types:
dim
unsigned int

variable_types: a int


memmove

decompiled_code:
void memmove()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void *memmove(void *a, void *b, size_t dim)
{
}

canonical_original_code:
void *memmove(void *a, void *b, unsigned int dim)
{
}

variable_types:
a
void *

variable_types:
b
void *

return_type: void *


memcmp

decompiled_code:
void memcmp()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
int memcmp(const void *a, const void *b, size_t dim)
{
}

canonical_original_code:
int memcmp(void *a, void *b, unsigned int dim)
{
}


decompiled_code:
void ne2k_ioctl()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
uint32_t ne2k_ioctl(device_t *d, uint32_t call, uint32_t a, uint32_t b)
{
 switch(call)
 {
  default:
   break;
 }
}

canonical_original_code:
unsigned int ne2k_ioctl(struct device_p *d, unsigned int call, unsigned int a, unsigned int b)
{
 switch(call)
 {
  default:
   break;
 }
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *

variable_types:
call
unsigned int

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
__int64 __fastcall ne2k_probe()
{
unsigned int v0; // ebp
__int64 result; // rax
__int64 v2; // rax
void **v3; // rbx
__int64 v4; // rax
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
result = device_iget(v0, v5);
if ( (_DWORD)result )
break;
v2 = v5[0];
if ( *(_BYTE *)(v5[0] + 228) == 1 )
{
v3 = &ne2k_dev_list;
while ( 1 )
{
v4 = *(_QWORD *)(v2 + 232);
if ( *(_DWORD *)(v4 + 32) == *((_DWORD *)v3 + 1) && *(_DWORD *)(v4 + 28) == *(_DWORD *)v3 )
printf("found ne2k\n");
if ( ++v3 == &ne2k_dev_list + 8 )
break;
v2 = v5[0];
}
}
++v0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1()
{
unsigned int v0; // ebp
__int64 result; // rax
__int64 v2; // rax
void **v3; // rbx
__int64 v4; // rax
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
result = device_iget(v0, v5);
if ( (_DWORD)result )
break;
v2 = v5[0];
if ( *(_BYTE *)(v5[0] + 228) == 1 )
{
v3 = &ne2k_dev_list;
while ( 1 )
{
v4 = *(_QWORD *)(v2 + 232);
if ( *(_DWORD *)(v4 + 32) == *((_DWORD *)v3 + 1) && *(_DWORD *)(v4 + 28) == *(_DWORD *)v3 )
printf("found ne2k\n");
if ( ++v3 == &ne2k_dev_list + 8 )
break;
v2 = v5[0];
}
}
++v0;
}
return result;
}

original_code:
uint32_t ne2k_probe(device_t *d)
{
 uint32_t i, j;
 device_t *dev;
 while(device_iget(i, &dev) == 0)
 {
   if(dev->bus_type == 0x01)
   {
    for(j = 0; j < sizeof(sizeof(ne2k_dev_list) / sizeof(pci_id_entry_t)); j++)
    {
     if( (((pci_device_t *) (dev->pci_dev))->device_id == ne2k_dev_list[j].device_id) &&
      (((pci_device_t *) (dev->pci_dev))->vendor_id == ne2k_dev_list[j].vendor_id))
     {
      printf("found ne2k\n");
     }
    }
   }
  i++;
 }
}

canonical_original_code:
unsigned int ne2k_probe(struct device_p *d)
{
 unsigned int i; unsigned int j;
 struct device_p *dev;
 while(device_iget(i, &dev) == 0)
 {
   if(dev->bus_type == 0x01)
   {
    for(j = 0; j < sizeof(sizeof(ne2k_dev_list) / sizeof(pci_id_entry_t)); j++)
    {
     if( (((struct pci_device_t *) (dev->pci_dev))->device_id == ne2k_dev_list[j].device_id) &&
      (((struct pci_device_t *) (dev->pci_dev))->vendor_id == ne2k_dev_list[j].vendor_id))
     {
      printf("found ne2k\n");
     }
    }
   }
  i++;
 }
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int

user_defined_types: struct pci_device_t { unsigned int bus; unsigned int function; unsigned int device; unsigned int command; unsigned int status; unsigned int rev_id; unsigned int iface; unsigned int vendor_id; unsigned int device_id; unsigned int class_id; unsigned int subclass_id; unsigned int bar[6]; unsigned int int_line; unsigned int int_pin; }


decompiled_code:
__int64 ne2k_init()
{
unsigned int v0; // ebx
__int64 v1; // rsi
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // al

v0 = 280;
driver_initd("keyboard");
do
{
scanf("%d", 0LL);
v1 = v0;
device_ne2k_qemu = v0++;
printf("%d ", v1);
v2 = io_inb((unsigned int)(device_ne2k_qemu + 1));
printf("%x:", v2);
v3 = io_inb((unsigned int)(device_ne2k_qemu + 2));
printf("%x:", v3);
v4 = io_inb((unsigned int)(device_ne2k_qemu + 3));
printf("%x:", v4);
v5 = io_inb((unsigned int)(device_ne2k_qemu + 4));
printf("%x:", v5);
v6 = io_inb((unsigned int)(device_ne2k_qemu + 5));
printf("%x:", v6);
v7 = io_inb((unsigned int)(device_ne2k_qemu + 6));
printf("%x", v7);
printf("\n");
}
while ( v0 != 400 );
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
__int64 v1; // rsi
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // al

v0 = 280;
driver_initd("keyboard");
do
{
scanf("%d", 0LL);
v1 = v0;
device_ne2k_qemu = v0++;
printf("%d ", v1);
v2 = io_inb((unsigned int)(device_ne2k_qemu + 1));
printf("%x:", v2);
v3 = io_inb((unsigned int)(device_ne2k_qemu + 2));
printf("%x:", v3);
v4 = io_inb((unsigned int)(device_ne2k_qemu + 3));
printf("%x:", v4);
v5 = io_inb((unsigned int)(device_ne2k_qemu + 4));
printf("%x:", v5);
v6 = io_inb((unsigned int)(device_ne2k_qemu + 5));
printf("%x:", v6);
v7 = io_inb((unsigned int)(device_ne2k_qemu + 6));
printf("%x", v7);
printf("\n");
}
while ( v0 != 400 );
return 0LL;
}

original_code:
uint32_t ne2k_init()
{
 uint8_t a;
 driver_initd("keyboard");
 uint32_t c;
 uint32_t i;
 for(i = 280; i < 400; i++)
 {
  scanf("%d", c);
  device_ne2k_qemu.io_base = i;
  printf("%d   ", i);
  a = io_inb(device_ne2k_qemu.io_base + 1);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 2);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 3);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 4);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 5);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 6);
  printf("%x",a);
  printf("\n");
 }
 return 0;
}

canonical_original_code:
unsigned int ne2k_init()
{
 unsigned char a;
 driver_initd("keyboard");
 unsigned int c;
 unsigned int i;
 for(i = 280; i < 400; i++)
 {
  scanf("%d", c);
  device_ne2k_qemu.io_base = i;
  printf("%d   ", i);
  a = io_inb(device_ne2k_qemu.io_base + 1);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 2);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 3);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 4);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 5);
  printf("%x:",a);
  a = io_inb(device_ne2k_qemu.io_base + 6);
  printf("%x",a);
  printf("\n");
 }
 return 0;
}

variable_types:
a
unsigned char

variable_types:
c
unsigned int


decompiled_code:
void ne2k_send_packet()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
uint32_t ne2k_send_packet(device_t *dev, packet_t *pack)
{
}

canonical_original_code:
unsigned int ne2k_send_packet(struct device_p *dev, struct packet_t *pack)
{
}

variable_types: struct packet_t { unsigned int size; char *data; } *


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

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

original_code:
uint32_t wifi_handle_frame(network_iface_t *iface, packet_t *p)
{
 return 0;
}

canonical_original_code:
unsigned int wifi_handle_frame(struct network_iface_p *iface, struct packet_t *p)
{
 return 0;
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *

user_defined_types: struct packet_t { unsigned int size; char *data; }


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

v2 = *(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 496LL);
if ( !v2 )
return 0LL;
result = v2(*(_QWORD *)(a1 + 72), *((_QWORD *)a2 + 1), *a2, 0LL);
*(_DWORD *)(a1 + 56) += result;
return result;
}

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

v2 = *(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 496LL);
if ( !v2 )
return 0LL;
result = v2(*(_QWORD *)(a1 + 72), *((_QWORD *)a2 + 1), *a2, 0LL);
*(_DWORD *)(a1 + 56) += result;
return result;
}

original_code:
uint32_t wifi_send_frame(network_iface_t *iface, packet_t *p)
{
 uint32_t sended_b;
 if((iface->drv)->write != 0)
  sended_b = (iface->drv)->write(iface->dev, p->data, p->size, 0);
 else
  return 0;
 iface->tx_bytes = iface->tx_bytes + sended_b;
 return sended_b;
}

canonical_original_code:
unsigned int wifi_send_frame(struct network_iface_p *iface, struct packet_t *p)
{
 unsigned int sended_b;
 if((iface->drv)->write != 0)
  sended_b = (iface->drv)->write(iface->dev, p->data, p->size, 0);
 else
  return 0;
 iface->tx_bytes = iface->tx_bytes + sended_b;
 return sended_b;
}


decompiled_code:
void wifi_up()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
uint32_t wifi_up(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int wifi_up(struct network_iface_p *iface)
{
}


decompiled_code:
// attributes: thunk
void wifi_down()
{
wifi_up();
}

canonical_decompiled_code:
void func3()
{
func2();
}

original_code:
uint32_t wifi_down(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int wifi_down(struct network_iface_p *iface)
{
}


decompiled_code:
__int64 __fastcall tmpfs_get_node(__int64 a1, int a2, __int64 *a3)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 312);
if ( !result )
return 0LL;
while ( *(_DWORD *)(result + 256) != a2 )
{
result = *(_QWORD *)(result + 288);
if ( !result )
return result;
}
*a3 = result;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 *a3)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 312);
if ( !result )
return 0LL;
while ( *(_DWORD *)(result + 256) != a2 )
{
result = *(_QWORD *)(result + 288);
if ( !result )
return result;
}
*a3 = result;
return 1LL;
}

original_code:
uint32_t tmpfs_get_node(inode_t *root, uint32_t i, inode_t **child)
{
 inode_t *tmp = root->childs;
 while(tmp != 0)
 {
  if(tmp->inode_n == i)
  {
   *child = tmp;
   return 1;
  }
  tmp = tmp->next;
 }
 return 0;
}

canonical_original_code:
unsigned int tmpfs_get_node(struct inode_p *root, unsigned int i, struct inode_p **child)
{
 struct inode_p *tmp = root->childs;
 while(tmp != 0)
 {
  if(tmp->inode_n == i)
  {
   *child = tmp;
   return 1;
  }
  tmp = tmp->next;
 }
 return 0;
}

variable_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *

variable_types:
child
struct inode_p **


decompiled_code:
__int64 tmpfs_umount()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
uint32_t tmpfs_umount(inode_t *root)
{
 return 1;
}

canonical_original_code:
unsigned int tmpfs_umount(struct inode_p *root)
{
 return 1;
}


decompiled_code:
__int64 tmpfs_mount()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
uint32_t tmpfs_mount(char *dev, uint32_t flags, inode_t *root)
{
 return 1;
}

canonical_original_code:
unsigned int tmpfs_mount(char *dev, unsigned int flags, struct inode_p *root)
{
 return 1;
}

variable_types:
dev
char *

variable_types:
flags
unsigned int


decompiled_code:
__int64 __fastcall tmpfs_read(__int64 a1, _BYTE *a2, int a3, unsigned __int64 a4)
{
unsigned int *v5; // rdx
__int64 result; // rax
__int64 v9; // rdx
int v10; // ecx
int v11; // eax
unsigned int v12; // esi
_BYTE *v13; // rdi
__int64 v14; // rcx

v5 = *(unsigned int **)(a1 + 264);
if ( !v5 )
return 0LL;
result = 0LL;
if ( *v5 >= a4 )
{
v9 = *((_QWORD *)v5 + 1);
v10 = a4 >> 10;
if ( a4 >> 10 )
{
v11 = 0;
do
{
++v11;
v9 = *(_QWORD *)(v9 + 1024);
}
while ( v10 != v11 );
}
v12 = a4 & 0x3FF;
v13 = a2;
result = 0LL;
while ( (_DWORD)result != a3 )
{
if ( v12 > 0x400 )
{
v9 = *(_QWORD *)(v9 + 1024);
if ( !v9 )
goto LABEL_15;
v12 = 1;
v14 = 0LL;
}
else
{
v14 = v12++;
}
result = (unsigned int)(result + 1);
*v13++ = *(_BYTE *)(v9 + v14);
if ( a3 == (_DWORD)result )
{
LABEL_15:
a2[(unsigned int)result] = 0;
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _BYTE *a2, int a3, unsigned __int64 a4)
{
unsigned int *v5; // rdx
__int64 result; // rax
__int64 v9; // rdx
int v10; // ecx
int v11; // eax
unsigned int v12; // esi
_BYTE *v13; // rdi
__int64 v14; // rcx

v5 = *(unsigned int **)(a1 + 264);
if ( !v5 )
return 0LL;
result = 0LL;
if ( *v5 >= a4 )
{
v9 = *((_QWORD *)v5 + 1);
v10 = a4 >> 10;
if ( a4 >> 10 )
{
v11 = 0;
do
{
++v11;
v9 = *(_QWORD *)(v9 + 1024);
}
while ( v10 != v11 );
}
v12 = a4 & 0x3FF;
v13 = a2;
result = 0LL;
while ( (_DWORD)result != a3 )
{
if ( v12 > 0x400 )
{
v9 = *(_QWORD *)(v9 + 1024);
if ( !v9 )
goto LABEL_15;
v12 = 1;
v14 = 0LL;
}
else
{
v14 = v12++;
}
result = (unsigned int)(result + 1);
*v13++ = *(_BYTE *)(v9 + v14);
if ( a3 == (_DWORD)result )
{
LABEL_15:
a2[(unsigned int)result] = 0;
return result;
}
}
}
return result;
}

original_code:
uint32_t tmpfs_read(inode_t *node, char *buf, uint32_t size, uint64_t offset)
{
 uint32_t i;
 uint32_t j;
 uint32_t r;
 tmpfs_node_t *tmpnode;
 tmpfs_data_node_t *tmpdata;
 j = offset / 1024;
 tmpnode = (tmpfs_node_t *) (node->fs_node);
 if(tmpnode == 0 || tmpnode->size < offset)
  return 0;
 tmpdata = tmpnode->data;
 for(i = 0; i < j; i++)
  tmpdata = tmpdata->next;
 j = offset % 1024;
 r = 0;
 for(i = 0; i < size; i++)
 {
  if((j > 1024))
  {
   tmpdata = tmpdata->next;
   j = 0;
   if(tmpdata == 0)
   {
    buf[i] = '\0';
    return r;
   }
  }
  buf[i] = tmpdata->data[j];
  r++;
  j++;
  if(r == size)
  {
   buf[i+1] = '\0';
   return size;
  }
 }
}

canonical_original_code:
unsigned int tmpfs_read(struct inode_p *node, char *buf, unsigned int size, unsigned long long offset)
{
 unsigned int i;
 unsigned int j;
 unsigned int r;
 struct tmpfs_node_p *tmpnode;
 struct tmpfs_data_node_p *tmpdata;
 j = offset / 1024;
 tmpnode = (struct tmpfs_node_p *) (node->fs_node);
 if(tmpnode == 0 || tmpnode->size < offset)
  return 0;
 tmpdata = tmpnode->data;
 for(i = 0; i < j; i++)
  tmpdata = tmpdata->next;
 j = offset % 1024;
 r = 0;
 for(i = 0; i < size; i++)
 {
  if((j > 1024))
  {
   tmpdata = tmpdata->next;
   j = 0;
   if(tmpdata == 0)
   {
    buf[i] = '\0';
    return r;
   }
  }
  buf[i] = tmpdata->data[j];
  r++;
  j++;
  if(r == size)
  {
   buf[i+1] = '\0';
   return size;
  }
 }
}

variable_types:
buf
char *

variable_types:
size
unsigned int

variable_types:
offset
unsigned long long

variable_types:
r
unsigned int

variable_types: struct tmpfs_node_p { unsigned int size; struct tmpfs_data_node_p { char data[1024]; struct tmpfs_data_node_p *next; struct tmpfs_data_node_p *prev; } *data; } *

user_defined_types: struct tmpfs_node_p { unsigned int size; struct tmpfs_data_node_p *data; }


decompiled_code:
__int64 __fastcall tmpfs_readdir(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // rbx
unsigned int v5; // eax

v3 = *(_QWORD *)(a1 + 312);
if ( v3 )
{
if ( !a2 )
{
LABEL_7:
strcpy((char *)a3, (const char *)v3);
*(_DWORD *)(a3 + 256) = *(_DWORD *)(v3 + 256);
return 1LL;
}
v5 = 0;
while ( 1 )
{
v3 = *(_QWORD *)(v3 + 288);
++v5;
if ( !v3 || a2 < v5 )
break;
if ( a2 == v5 )
goto LABEL_7;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // rbx
unsigned int v5; // eax

v3 = *(_QWORD *)(a1 + 312);
if ( v3 )
{
if ( !a2 )
{
LABEL_7:
strcpy((char *)a3, (const char *)v3);
*(_DWORD *)(a3 + 256) = *(_DWORD *)(v3 + 256);
return 1LL;
}
v5 = 0;
while ( 1 )
{
v3 = *(_QWORD *)(v3 + 288);
++v5;
if ( !v3 || a2 < v5 )
break;
if ( a2 == v5 )
goto LABEL_7;
}
}
return 0LL;
}

original_code:
uint32_t tmpfs_readdir(inode_t *root, uint32_t n, struct dirent *d)
{
 inode_t *childs;
 unsigned i;
 childs = root->childs;
 i = 0;
 while(childs != 0 && i <= n)
 {
  if(i == n)
  {
   strcpy(d->name, childs->name);
   d->inode = childs->inode_n;
   return 1;
  }
  i++;
  childs = childs->next;
 }
 return 0;
}

canonical_original_code:
unsigned int tmpfs_readdir(struct inode_p *root, unsigned int n, struct dirent *d)
{
 struct inode_p *childs;
 unsigned int i;
 childs = root->childs;
 i = 0;
 while(childs != 0 && i <= n)
 {
  if(i == n)
  {
   strcpy(d->name, childs->name);
   d->inode = childs->inode_n;
   return 1;
  }
  i++;
  childs = childs->next;
 }
 return 0;
}

variable_types:
n
unsigned int

variable_types: struct dirent { char name[255]; unsigned int inode; } *


decompiled_code:
__int64 __fastcall tmpfs_mkdir(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(_BYTE *)(a1 + 260) == 2 )
result = *(unsigned int *)(fs_create_node(a2, a1, 2LL, 0LL) + 256);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(_BYTE *)(a1 + 260) == 2 )
result = *(unsigned int *)(fs_create_node(a2, a1, 2LL, 0LL) + 256);
else
result = 0LL;
return result;
}

original_code:
uint32_t tmpfs_mkdir(inode_t *root, char *name)
{
 if(root->type != 2)
  return 0;
 inode_t *node = fs_create_node(name, root, 2, 0);
 return node->inode_n;
}

canonical_original_code:
unsigned int tmpfs_mkdir(struct inode_p *root, char *name)
{
 if(root->type != 2)
  return 0;
 struct inode_p *node = fs_create_node(name, root, 2, 0);
 return node->inode_n;
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall tmpfs_link(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v8; // rax

if ( !a1 || *(_BYTE *)(a1 + 260) != 2 )
return 0LL;
v6 = *(_QWORD *)(a1 + 312);
if ( !v6 )
return 0LL;
while ( strcmp((const char *)v6, a2) )
{
v6 = *(_QWORD *)(v6 + 288);
if ( !v6 )
return 0LL;
}
if ( *(_BYTE *)(a3 + 260) != 2 )
return 0LL;
v8 = fs_create_node(a4, a3, 3LL, 0LL);
*(_QWORD *)(v8 + 280) = v6;
return *(unsigned int *)(v8 + 256);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v8; // rax

if ( !a1 || *(_BYTE *)(a1 + 260) != 2 )
return 0LL;
v6 = *(_QWORD *)(a1 + 312);
if ( !v6 )
return 0LL;
while ( strcmp((const char *)v6, a2) )
{
v6 = *(_QWORD *)(v6 + 288);
if ( !v6 )
return 0LL;
}
if ( *(_BYTE *)(a3 + 260) != 2 )
return 0LL;
v8 = fs_create_node(a4, a3, 3LL, 0LL);
*(_QWORD *)(v8 + 280) = v6;
return *(unsigned int *)(v8 + 256);
}

original_code:
uint32_t tmpfs_link(inode_t *root, char *name, inode_t *dest, char *link_name)
{
 if(root == 0 || root->type != 2)
  return 0;
 inode_t *c;
 inode_t *p;
 uint32_t in;
 c = root->childs;
 while(c != 0)
 {
  if(strcmp(c->name, name) == 0)
  {
   in = c->inode_n;
   break;
  }
  c = c->next;
 }
 if(c == 0)
  return 0;
 if(dest->type != 2)
  return 0;
 inode_t *node = fs_create_node(link_name, dest, 3, 0);
 node->link = c;
 return node->inode_n;
}

canonical_original_code:
unsigned int tmpfs_link(struct inode_p *root, char *name, struct inode_p *dest, char *link_name)
{
 if(root == 0 || root->type != 2)
  return 0;
 struct inode_p *c;
 struct inode_p *p;
 unsigned int in;
 c = root->childs;
 while(c != 0)
 {
  if(strcmp(c->name, name) == 0)
  {
   in = c->inode_n;
   break;
  }
  c = c->next;
 }
 if(c == 0)
  return 0;
 if(dest->type != 2)
  return 0;
 struct inode_p *node = fs_create_node(link_name, dest, 3, 0);
 node->link = c;
 return node->inode_n;
}

variable_types:
dest
struct inode_p *

variable_types:
in
unsigned int


original_code:
uint32_t tmpfs_delete_node(inode_t *root, char *name)
{
 inode_t *c;
 inode_t *p;
 uint32_t in;
 p = 0;
 c = root->childs;
 while(c != 0)
 {
  if(strcmp(c->name, name) == 0)
  {
   if(p != 0)
    p->next = c->next;
   else
    root->childs = root->childs->next;
   in = c->inode_n;
   free(c);
   return in;
  }
  p = c;
  c = c->next;
 }
 return 0;
}

canonical_original_code:
unsigned int tmpfs_delete_node(struct inode_p *root, char *name)
{
 struct inode_p *c;
 struct inode_p *p;
 unsigned int in;
 p = 0;
 c = root->childs;
 while(c != 0)
 {
  if(strcmp(c->name, name) == 0)
  {
   if(p != 0)
    p->next = c->next;
   else
    root->childs = root->childs->next;
   in = c->inode_n;
   free(c);
   return in;
  }
  p = c;
  c = c->next;
 }
 return 0;
}


decompiled_code:
// attributes: thunk
__int64 __fastcall tmpfs_unlink(__int64 a1, const char *a2)
{
return tmpfs_delete_node(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
return func7(a1, a2);
}

original_code:
uint32_t tmpfs_unlink(inode_t *root, char *name)
{
 return tmpfs_delete_node(root, name);
 return 0;
}

canonical_original_code:
unsigned int tmpfs_unlink(struct inode_p *root, char *name)
{
 return tmpfs_delete_node(root, name);
 return 0;
}


decompiled_code:
__int64 __fastcall tmpfs_close(__int64 a1)
{
void *v1; // rdi

v1 = *(void **)(a1 + 264);
if ( v1 )
free(v1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
void *v1; // rdi

v1 = *(void **)(a1 + 264);
if ( v1 )
free(v1);
return 1LL;
}

original_code:
uint32_t tmpfs_close(inode_t *n)
{
 if(n->fs_node != 0)
  free(n->fs_node);
 return 1;
}

canonical_original_code:
unsigned int tmpfs_close(struct inode_p *n)
{
 if(n->fs_node != 0)
  free(n->fs_node);
 return 1;
}


original_code:
uint32_t tmpfs_open(inode_t *node, char *flags)
{
 int i = 0;
 struct dirent dir;
 if(node->fs_node == 0)
 {
  (node->fs_node) = (void *) malloc(sizeof(tmpfs_node_t));
  ((tmpfs_node_t *) (node->fs_node))->size = 0;
  ((tmpfs_node_t *) (node->fs_node))->data = 0;
  return 1;
 }
 return 1;
}

canonical_original_code:
unsigned int tmpfs_open(struct inode_p *node, char *flags)
{
 int i = 0;
 struct dirent dir;
 if(node->fs_node == 0)
 {
  (node->fs_node) = (void *) malloc(sizeof(tmpfs_node_t));
  ((struct tmpfs_node_p *) (node->fs_node))->size = 0;
  ((struct tmpfs_node_p *) (node->fs_node))->data = 0;
  return 1;
 }
 return 1;
}

variable_types:
flags
char *

variable_types: i int

variable_types: struct dirent { char name[255]; unsigned int inode; }

user_defined_types: struct tmpfs_data_node_p { char data[1024]; struct tmpfs_data_node_p *next; struct tmpfs_data_node_p *prev; }


original_code:
uint32_t tmpfs_write(inode_t *node, char *buf, uint32_t size, uint64_t offset)
{
 uint32_t i;
 uint32_t j;
 uint32_t r;
 tmpfs_node_t *tmpnode;
 tmpfs_data_node_t *tmpdata;
 j = offset / 1024;
 tmpnode = (tmpfs_node_t *) (node->fs_node);
 if(tmpnode == 0 || tmpnode->size < offset)
  return 0;
 tmpdata = tmpnode->data;
 for(i = 0; i < j; i++)
 {
  if(tmpdata == 0)
  {
   tmpdata = (tmpfs_data_node_t *) malloc(sizeof(tmpfs_data_node_t));
  }
  tmpdata = tmpdata->next;
 }
 j = offset % 1024;
 r = 0;
 for(i = 0; i < size; i++)
 {
  if((j > 1024))
  {
   tmpdata = tmpdata->next;
   j = 0;
   if(tmpdata == 0)
    return r;
  }
  tmpdata->data[j] = buf[i];
  tmpnode->size++;
  r++;
  j++;
  if(r == size)
   return size;
 }
 return 0;
}

canonical_original_code:
unsigned int tmpfs_write(struct inode_p *node, char *buf, unsigned int size, unsigned long long offset)
{
 unsigned int i;
 unsigned int j;
 unsigned int r;
 struct tmpfs_node_p *tmpnode;
 struct tmpfs_data_node_p *tmpdata;
 j = offset / 1024;
 tmpnode = (struct tmpfs_node_p *) (node->fs_node);
 if(tmpnode == 0 || tmpnode->size < offset)
  return 0;
 tmpdata = tmpnode->data;
 for(i = 0; i < j; i++)
 {
  if(tmpdata == 0)
  {
   tmpdata = (struct tmpfs_data_node_p *) malloc(sizeof(tmpfs_data_node_t));
  }
  tmpdata = tmpdata->next;
 }
 j = offset % 1024;
 r = 0;
 for(i = 0; i < size; i++)
 {
  if((j > 1024))
  {
   tmpdata = tmpdata->next;
   j = 0;
   if(tmpdata == 0)
    return r;
  }
  tmpdata->data[j] = buf[i];
  tmpnode->size++;
  r++;
  j++;
  if(r == size)
   return size;
 }
 return 0;
}

variable_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types: struct tmpfs_data_node_p { char data[1024]; struct tmpfs_data_node_p *next; struct tmpfs_data_node_p *prev; } *


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

result = task_current;
if ( task_current )
{
*(_BYTE *)(task_current + 16) = 0;
do
{
result = *(_QWORD *)(result + 64);
if ( !result )
result = task_list;
}
while ( *(_BYTE *)(result + 16) );
task_current = result;
*(_BYTE *)(result + 16) = 1;
}
return result;
}

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

result = task_current;
if ( task_current )
{
*(_BYTE *)(task_current + 16) = 0;
do
{
result = *(_QWORD *)(result + 64);
if ( !result )
result = task_list;
}
while ( *(_BYTE *)(result + 16) );
task_current = result;
*(_BYTE *)(result + 16) = 1;
}
return result;
}

original_code:
void task_switch_round_robin()
{
 if(task_current != 0)
 {
    task_current->state = 0;
  do
  {
   task_current = task_current->next;
   if(task_current == 0)
    task_current = task_list;
  } while(task_current->state != 0);
  task_current->state = 1;
 }
}