decompiled_code:
__int64 __fastcall timer_create(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 result; // rax

if ( a1 == 1 )
{
v3 = syscall_timer_create(1LL, 1LL, a2, a3);
if ( v3 < 0 )
{
errno = -v3;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 result; // rax

if ( a1 == 1 )
{
v3 = func2(1LL, 1LL, a2, a3);
if ( v3 < 0 )
{
errno = -v3;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
{
 int tmrid;
 int flag;
 if(clockid != 1)
 {
  errno= 0x1d;
  return -1;
 }
 flag = 1;
 tmrid = syscall_timer_create(clockid, flag, evp, timerid);
 if(tmrid < 0)
 {
  errno= -tmrid;
  return -1;
 }
 return 0;
}

canonical_original_code:
int timer_create(unsigned long clockid, struct sigevent *evp, int *timerid)
{
 int tmrid;
 int flag;
 if(clockid != 1)
 {
  errno= 0x1d;
  return -1;
 }
 flag = 1;
 tmrid = syscall_timer_create(clockid, flag, evp, timerid);
 if(tmrid < 0)
 {
  errno= -tmrid;
  return -1;
 }
 return 0;
}

variable_types:
clockid
unsigned long

variable_types: struct sigevent { int sigev_notify; int sigev_signo; union sigval { int sigval_int; void *sigval_ptr; } handler; } *

variable_types:
timerid
int *

variable_types: tmrid int

variable_types: flag int

user_defined_types: struct sigevent { int sigev_notify; int sigev_signo; union sigval handler; }


repo: mregmi/manrix

decompiled_code:
__int64 __fastcall group_desc_read(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 1984LL) + 56LL * a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 1984LL) + 56LL * a2;
}

original_code:
static inline struct ext2_group_desc* group_desc_read
     (struct vnode* parent, unsigned int group)
{
 struct ext2_group_desc *gd;
 gd = &parent->vfsp->sb.ext2_sb.gdes[group];
 return gd;
}

canonical_original_code:
static inline struct ext2_group_desc *group_desc_read(struct vnode *parent, unsigned int group)
{
 struct ext2_group_desc *gd;
 gd = &parent->vfsp->sb.ext2_sb.gdes[group];
 return gd;
}

variable_types: struct vnode { unsigned short v_flag; int v_count; struct vfs { struct linked_list { void *next; } vfs_next; struct vnode *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb { struct ext2_super_block { unsigned long s_inodes_count; unsigned long s_blocks_count; unsigned long s_r_blocks_count; unsigned long s_free_blocks_count; unsigned long s_free_inodes_count; unsigned long s_first_data_block; unsigned long s_log_block_size; unsigned long s_log_frag_size; unsigned long s_blocks_per_group; unsigned long s_frags_per_group; unsigned long s_inodes_per_group; unsigned long s_mtime; unsigned long s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_pad; unsigned short s_minor_rev_level; unsigned long s_lastcheck; unsigned long s_checkinterval; unsigned long s_creator_os; unsigned long s_rev_level; unsigned short s_def_resuid; unsigned short s_def_regid; unsigned long s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned long s_feature_compat; unsigned long s_feature_incompat; unsigned long s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned long s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_padding1; unsigned long s_reserved[204]; } ext2; struct ext2_group_desc *gdes; } ext2_sb; struct fat_super_block { int ino_val; int fat_type; char fatbs[512]; void *bsptr; } fat; } sb; struct vfsops { int (*vfs_mount)(); int (*vfs_unmount)(); int (*vfs_statvfs)(); int (*vfs_sync)(); } *ops; struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } lock; } *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops { int (*vop_open)(struct file { int f_access; unsigned long f_offset; int f_ref; struct indev { int inode; unsigned long dev; } vnode; } *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata { struct vnode *vn; struct userid { int uid; int gid; } id; struct vfs *vfs; char *path; int mode; int access; } *); void (*vop_get_attr)(struct vnode *, struct vattr { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; } *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); } *ops; void *data; struct mrx_mutex smlock; union inode { struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; } ext2inode; } v_ino; } *

variable_types:
group
unsigned int

variable_types: struct ext2_group_desc { unsigned long bg_block_bitmap; unsigned long bg_inode_bitmap; unsigned long bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned long bg_reserved[3]; } *

user_defined_types: struct vnode { unsigned short v_flag; int v_count; struct vfs *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops *ops; void *data; struct mrx_mutex smlock; union inode v_ino; }

user_defined_types: union inode { struct ext2inode ext2inode; }

user_defined_types: struct vfs { struct linked_list vfs_next; struct vnode *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb ext2_sb; struct fat_super_block fat; } sb; struct vfsops *ops; struct mrx_mutex lock; }

user_defined_types: struct vnodeops { int (*vop_open)(struct file *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata *); void (*vop_get_attr)(struct vnode *, struct vattr *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); }

user_defined_types: struct mrx_mutex { struct mrx_mutexattr mattr; int counter; int sync_id; }

user_defined_types: struct ext2sb { struct ext2_super_block ext2; struct ext2_group_desc *gdes; }

user_defined_types: struct file { int f_access; unsigned long f_offset; int f_ref; struct indev vnode; }

user_defined_types: struct nameidata { struct vnode *vn; struct userid id; struct vfs *vfs; char *path; int mode; int access; }


original_code:
int ext2_read_inode(struct vnode *parent, ino_t inum)
{
 unsigned long group;
 unsigned long index;
 struct ext2_group_desc *group_desc;
 struct ext2inode *inode = &parent->v_ino.ext2inode;
 group = (inum-1) / ((&parent->vfsp->sb.ext2_sb.ext2)->s_inodes_per_group) ;
 group_desc = group_desc_read(parent, group);
 index = ((inum-1) %
  ((&parent->vfsp->sb.ext2_sb.ext2)->s_inodes_per_group)) * sizeof(struct ext2inode);
 read_inode_index(parent, group_desc, index, inode);
 parent->v_type = inode->i_mode ;
 parent->ops = (struct vnodeops *)&ext2_vnode_ops;
 return 0;
}

canonical_original_code:
int ext2_read_inode(struct vnode *parent, int inum)
{
 unsigned long group;
 unsigned long index;
 struct ext2_group_desc *group_desc;
 struct ext2inode *inode = &parent->v_ino.ext2inode;
 group = (inum-1) / ((&parent->vfsp->sb.ext2_sb.ext2)->s_inodes_per_group) ;
 group_desc = group_desc_read(parent, group);
 index = ((inum-1) %
  ((&parent->vfsp->sb.ext2_sb.ext2)->s_inodes_per_group)) * sizeof(struct ext2inode);
 read_inode_index(parent, group_desc, index, inode);
 parent->v_type = inode->i_mode ;
 parent->ops = (struct vnodeops *)&ext2_vnode_ops;
 return 0;
}

variable_types: struct vnode { unsigned short v_flag; int v_count; struct vfs { struct linked_list { void *next; } vfs_next; struct vnode *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb { struct ext2_super_block { unsigned long s_inodes_count; unsigned long s_blocks_count; unsigned long s_r_blocks_count; unsigned long s_free_blocks_count; unsigned long s_free_inodes_count; unsigned long s_first_data_block; unsigned long s_log_block_size; unsigned long s_log_frag_size; unsigned long s_blocks_per_group; unsigned long s_frags_per_group; unsigned long s_inodes_per_group; unsigned long s_mtime; unsigned long s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_pad; unsigned short s_minor_rev_level; unsigned long s_lastcheck; unsigned long s_checkinterval; unsigned long s_creator_os; unsigned long s_rev_level; unsigned short s_def_resuid; unsigned short s_def_regid; unsigned long s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned long s_feature_compat; unsigned long s_feature_incompat; unsigned long s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned long s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_padding1; unsigned long s_reserved[204]; } ext2; struct ext2_group_desc { unsigned long bg_block_bitmap; unsigned long bg_inode_bitmap; unsigned long bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned long bg_reserved[3]; } *gdes; } ext2_sb; struct fat_super_block { int ino_val; int fat_type; char fatbs[512]; void *bsptr; } fat; } sb; struct vfsops { int (*vfs_mount)(); int (*vfs_unmount)(); int (*vfs_statvfs)(); int (*vfs_sync)(); } *ops; struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } lock; } *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops { int (*vop_open)(struct file { int f_access; unsigned long f_offset; int f_ref; struct indev { int inode; unsigned long dev; } vnode; } *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata { struct vnode *vn; struct userid { int uid; int gid; } id; struct vfs *vfs; char *path; int mode; int access; } *); void (*vop_get_attr)(struct vnode *, struct vattr { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; } *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); } *ops; void *data; struct mrx_mutex smlock; union inode { struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; } ext2inode; } v_ino; } *

variable_types: inum int

variable_types:
group
unsigned long

variable_types:
index
unsigned long

variable_types: struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; } *

return_type: int


original_code:
unsigned long ext2_bmap( struct vnode *vnode, unsigned long offset)
{
 unsigned int blkno , itotal , tot, totalb;
 unsigned long *blk, blk_no;
 struct ext2inode *inode;
 struct bcache *bcache;
 inode = &vnode->v_ino.ext2inode;
 if(offset < 12)
 {
  blkno = inode->i_block[offset];
  return blkno;
 }
 itotal = vnode->vfsp->blk_size/sizeof(unsigned int);
 tot = itotal + 12;
 if(offset >= 12 && offset < tot)
 {
  blkno = inode->i_block[12];
  bcache = bread(vnode->v_rdev, blkno, vnode->vfsp->blk_size);
  blk = (unsigned long *)bcache->b_data;
            blk_no = blk[offset - 12];
     brelse(bcache);
  return blk_no;
 }
 if( offset >= tot && offset <= (offset + tot))
 {
  blkno = inode->i_block[(12 + 1)];
  bcache = bread(vnode->v_rdev,blkno,vnode->vfsp->blk_size);
  blk = (unsigned long *)bcache->b_data;
  blk_no =blk[offset -tot];
  brelse(bcache);
  bcache = bread(vnode->v_rdev,blk_no,vnode->vfsp->blk_size);
  blk = (unsigned long *)bcache->b_data;
  blk_no = blk[offset -tot];
  brelse(bcache);
  return blk_no;
 }
 totalb = (tot)*(tot);
 blkno = inode->i_block[15];
 bcache = bread(vnode->v_rdev,blkno,vnode->vfsp->blk_size);
 blk = (unsigned long *)bcache->b_data;
 blk_no = blk[offset - totalb];
 brelse(bcache);
 bcache = bread(vnode->v_rdev,blk_no,vnode->vfsp->blk_size);
 blk = (unsigned long *)bcache->b_data;
 blk_no = blk[offset -totalb];
 brelse(bcache);
 bcache = bread(vnode->v_rdev,blk_no,vnode->vfsp->blk_size);
 blk = (unsigned long *)bcache->b_data;
 blk_no = blk[offset -totalb];
 brelse(bcache);
 return blk_no;
}

canonical_original_code:
unsigned long ext2_bmap(struct vnode *vnode, unsigned long offset)
{
 unsigned int blkno; unsigned int itotal; unsigned int tot; unsigned int totalb;
 unsigned long *blk; unsigned long blk_no;
 struct ext2inode *inode;
 struct bcache *bcache;
 inode = &vnode->v_ino.ext2inode;
 if(offset < 12)
 {
  blkno = inode->i_block[offset];
  return blkno;
 }
 itotal = vnode->vfsp->blk_size/sizeof(unsigned int);
 tot = itotal + 12;
 if(offset >= 12 && offset < tot)
 {
  blkno = inode->i_block[12];
  bcache = bread(vnode->v_rdev, blkno, vnode->vfsp->blk_size);
  blk = (unsigned long *)bcache->b_data;
            blk_no = blk[offset - 12];
     brelse(bcache);
  return blk_no;
 }
 if( offset >= tot && offset <= (offset + tot))
 {
  blkno = inode->i_block[(12 + 1)];
  bcache = bread(vnode->v_rdev,blkno,vnode->vfsp->blk_size);
  blk = (unsigned long *)bcache->b_data;
  blk_no =blk[offset -tot];
  brelse(bcache);
  bcache = bread(vnode->v_rdev,blk_no,vnode->vfsp->blk_size);
  blk = (unsigned long *)bcache->b_data;
  blk_no = blk[offset -tot];
  brelse(bcache);
  return blk_no;
 }
 totalb = (tot)*(tot);
 blkno = inode->i_block[15];
 bcache = bread(vnode->v_rdev,blkno,vnode->vfsp->blk_size);
 blk = (unsigned long *)bcache->b_data;
 blk_no = blk[offset - totalb];
 brelse(bcache);
 bcache = bread(vnode->v_rdev,blk_no,vnode->vfsp->blk_size);
 blk = (unsigned long *)bcache->b_data;
 blk_no = blk[offset -totalb];
 brelse(bcache);
 bcache = bread(vnode->v_rdev,blk_no,vnode->vfsp->blk_size);
 blk = (unsigned long *)bcache->b_data;
 blk_no = blk[offset -totalb];
 brelse(bcache);
 return blk_no;
}

variable_types:
offset
unsigned long

variable_types:
blkno
unsigned int

variable_types:
itotal
unsigned int

variable_types:
tot
unsigned int

variable_types:
totalb
unsigned int

variable_types:
blk
unsigned long *

variable_types: struct bcache { int b_status; struct bcache *next; struct linked_list { void *next; } b_freelist; unsigned long b_devno; unsigned long b_blockno; int b_ioerror; void *b_data; unsigned int b_datasz; struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } smlock; } *

return_type: unsigned long

user_defined_types: struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; }

user_defined_types: struct bcache { int b_status; struct bcache *next; struct linked_list b_freelist; unsigned long b_devno; unsigned long b_blockno; int b_ioerror; void *b_data; unsigned int b_datasz; struct mrx_mutex smlock; }

user_defined_types: struct fat_super_block { int ino_val; int fat_type; char fatbs[512]; void *bsptr; }

user_defined_types: struct vfsops { int (*vfs_mount)(); int (*vfs_unmount)(); int (*vfs_statvfs)(); int (*vfs_sync)(); }

user_defined_types: struct ext2_super_block { unsigned long s_inodes_count; unsigned long s_blocks_count; unsigned long s_r_blocks_count; unsigned long s_free_blocks_count; unsigned long s_free_inodes_count; unsigned long s_first_data_block; unsigned long s_log_block_size; unsigned long s_log_frag_size; unsigned long s_blocks_per_group; unsigned long s_frags_per_group; unsigned long s_inodes_per_group; unsigned long s_mtime; unsigned long s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_pad; unsigned short s_minor_rev_level; unsigned long s_lastcheck; unsigned long s_checkinterval; unsigned long s_creator_os; unsigned long s_rev_level; unsigned short s_def_resuid; unsigned short s_def_regid; unsigned long s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned long s_feature_compat; unsigned long s_feature_incompat; unsigned long s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned long s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_padding1; unsigned long s_reserved[204]; }

user_defined_types: struct ext2_group_desc { unsigned long bg_block_bitmap; unsigned long bg_inode_bitmap; unsigned long bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned long bg_reserved[3]; }

user_defined_types: struct vattr { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; }

user_defined_types: struct indev { int inode; unsigned long dev; }


original_code:
void ext2_get_attr(struct vnode *vn, struct vattr *attr)
{
 struct ext2inode *ino = &vn->v_ino.ext2inode;
 attr->st_ino = vn->v_inum;
 attr->st_mode = ino->i_mode;
 attr->st_nlink = ino->i_links_count;
 attr->st_uid = ino->i_uid;
 attr->st_gid = ino->i_gid;
 attr->st_size = ino->i_size;
 attr->st_atime = ino->i_atime;
 attr->st_mtime = ino->i_mtime;
 attr->st_ctime = ino->i_ctime;
 attr->st_blksize = vn->vfsp->blk_size;
}

variable_types:
attr
struct vattr *

return_type: void

user_defined_types: struct mrx_mutexattr { int type; int pshared; int protocol; }


original_code:
void ext2_put_attr(struct vnode *vn, struct vattr *attr)
{
 struct ext2inode *ino = &vn->v_ino.ext2inode;
 vn->v_inum = attr->st_ino;
 ino->i_mode = attr->st_mode;
 ino->i_links_count = attr->st_nlink;
 ino->i_uid = attr->st_uid;
 ino->i_gid = attr->st_gid;
 ino->i_size = attr->st_size;
 ino->i_atime = attr->st_atime;
 ino->i_mtime = attr->st_mtime;
 ino->i_ctime = attr->st_ctime;
 vn->v_flag |= 8;
}

user_defined_types: struct vnode { unsigned short v_flag; int v_count; struct vfs *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops *ops; void *data; struct mrx_mutex smlock; union inode v_ino; }


outportb

decompiled_code:
__int64 __fastcall outportb(unsigned int a1, unsigned __int16 a2)
{
__int64 result; // rax

result = a1;
__outbyte(a2, a1);
return result;
}

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

result = a1;
__outbyte(a2, a1);
return result;
}

original_code:
static inline void outportb(unsigned char value, unsigned short port)
{
 __asm__ volatile(
  "outb %%al, %%dx"
  :
  :"a" (value),"d" (port)
  );
}

variable_types:
value
unsigned char

variable_types:
port
unsigned short


inportb

decompiled_code:
unsigned __int8 __fastcall inportb(unsigned __int16 a1)
{
return __inbyte(a1);
}

canonical_decompiled_code:
unsigned __int8 __fastcall func1(unsigned __int16 a1)
{
return __inbyte(a1);
}

original_code:
static inline unsigned char inportb(unsigned short port)
{
 register unsigned char ret;
 __asm__ volatile
   (
   "inb %%dx,%%al"
   :"=a" (ret)
   :"d" (port)
   );
 return ret;
}

variable_types:
ret
unsigned char

return_type: unsigned char


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

LODWORD(result) = 1000000;
do
result = (unsigned int)(result - 1);
while ( (_DWORD)result );
return result;
}

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

LODWORD(result) = 1000000;
do
result = (unsigned int)(result - 1);
while ( (_DWORD)result );
return result;
}

original_code:
static inline void wait_for_int()
{
 int i;
 for(i=0;i<1000000;i++)
  asm("nop");
}

variable_types: i int


decompiled_code:
__int64 __fastcall enable_motor(char a1)
{
__int16 v1; // ax

v1 = get_port(2u);
return outportb((unsigned __int8)(a1 | (16 << a1)) | 0xCu, v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
__int16 v1; // ax

v1 = func2(2u);
return func0((unsigned __int8)(a1 | (16 << a1)) | 0xCu, v1);
}

original_code:
static inline void enable_motor(unsigned char drive)
{
 unsigned char val;
 val = 1 << drive;
 val <<= 4;
 val |= drive|0x04|0x08;
 (outportb(val, get_port(0x02)));
}

variable_types:
drive
unsigned char

variable_types:
val
unsigned char


decompiled_code:
void fdc_intr()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void fdc_intr()
{
}

canonical_original_code:
void fdc_intr()
{
}


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

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

original_code:
int fdc_open(struct operation *op)
{
 return 0;
}

variable_types: struct operation { unsigned long device; int caller; int type; unsigned long block; unsigned int blksize; void *buffer; } *


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

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

original_code:
int fdc_close(struct operation *op)
{
 return 0;
}

user_defined_types: struct operation { unsigned long device; int caller; int type; unsigned long block; unsigned int blksize; void *buffer; }


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

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

original_code:
int fdc_size(struct operation *op)
{
 return 0;
}


decompiled_code:
__int64 __fastcall send_byte(unsigned __int8 a1)
{
__int16 v1; // bp
signed __int8 v2; // al
int v3; // ebx
__int16 v5; // ax

v1 = get_port(4u);
v2 = inportb(v1);
v3 = 99999;
while ( v2 >= 0 )
{
v2 = inportb(v1);
if ( !--v3 )
return 0xFFFFFFFFLL;
}
v5 = get_port(5u);
outportb(a1, v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned __int8 a1)
{
__int16 v1; // bp
signed __int8 v2; // al
int v3; // ebx
__int16 v5; // ax

v1 = func2(4u);
v2 = func1(v1);
v3 = 99999;
while ( v2 >= 0 )
{
v2 = func1(v1);
if ( !--v3 )
return 0xFFFFFFFFLL;
}
v5 = func2(5u);
func0(a1, v5);
return 0LL;
}

original_code:
int send_byte(uint8_t val)
{
 int timeout = 100000;
 unsigned char data;
 do{
  data = (inportb(get_port(0x04)));
  if(!--timeout)
   return -1;
 }while((data & 0x80) != 0x80);
 (outportb(val, get_port(0x05)));
 return 0;
}

canonical_original_code:
int send_byte(unsigned char val)
{
 int timeout = 100000;
 unsigned char data;
 do{
  data = (inportb(get_port(0x04)));
  if(!--timeout)
   return -1;
 }while((data & 0x80) != 0x80);
 (outportb(val, get_port(0x05)));
 return 0;
}

variable_types: timeout int

variable_types:
data
unsigned char


decompiled_code:
__int64 get_byte()
{
__int16 v0; // bp
unsigned __int8 v1; // al
int v2; // ebx
__int16 v4; // ax

v0 = get_port(4u);
v1 = inportb(v0);
v2 = 99999;
while ( (v1 & 0xC0) != 0xC0 )
{
v1 = inportb(v0);
if ( !--v2 )
return 0xFFFFFFFFLL;
}
v4 = get_port(5u);
return inportb(v4);
}

canonical_decompiled_code:
__int64 func19()
{
__int16 v0; // bp
unsigned __int8 v1; // al
int v2; // ebx
__int16 v4; // ax

v0 = func2(4u);
v1 = func1(v0);
v2 = 99999;
while ( (v1 & 0xC0) != 0xC0 )
{
v1 = func1(v0);
if ( !--v2 )
return 0xFFFFFFFFLL;
}
v4 = func2(5u);
return func1(v4);
}

original_code:
int get_byte()
{
 int timeout = 100000;
 unsigned char data, stat;
 do{
  stat = (inportb(get_port(0x04)));
  if(!--timeout)
   return -1;
 }while((stat & (0x80|0x40)) != (0x80|0x40));
 data = (inportb(get_port(0x05)));
 return (int)data;
}

canonical_original_code:
int get_byte()
{
 int timeout = 100000;
 unsigned char data; unsigned char stat;
 do{
  stat = (inportb(get_port(0x04)));
  if(!--timeout)
   return -1;
 }while((stat & (0x80|0x40)) != (0x80|0x40));
 data = (inportb(get_port(0x05)));
 return (int)data;
}

variable_types:
stat
unsigned char


decompiled_code:
int __fastcall get_results(_BYTE *a1)
{
_BYTE *v1; // rbx
__int16 v2; // ax

v1 = a1;
do
{
*v1 = get_byte();
v2 = get_port(4u);
inportb(v2);
++v1;
}
while ( v1 != a1 + 7 );
return printf("results over");
}

canonical_decompiled_code:
int __fastcall func20(_BYTE *a1)
{
_BYTE *v1; // rbx
__int16 v2; // ax

v1 = a1;
do
{
*v1 = func19();
v2 = func2(4u);
func1(v2);
++v1;
}
while ( v1 != a1 + 7 );
return printf("results over");
}

original_code:
static inline void get_results(uint8_t results[])
{
 int index = 0, timeout = 100000;
 while(index < 7)
 {
  results[index++] = get_byte();
  while((inportb(get_port(0x04))) & 0x10)
  if(--timeout)
  {
   timeout = 100000;
   break;
  }
 }
 printf("results over");
}

canonical_original_code:
static inline void get_results(unsigned char results[])
{
 int index = 0; int timeout = 100000;
 while(index < 7)
 {
  results[index++] = get_byte();
  while((inportb(get_port(0x04))) & 0x10)
  if(--timeout)
  {
   timeout = 100000;
   break;
  }
 }
 printf("results over");
}

variable_types:
results
unsigned char []

variable_types: index int


decompiled_code:
__int64 __fastcall fdc_rw_sect(unsigned __int64 a1, char a2, char a3, _DWORD *a4)
{
__int16 v6; // ax
char v8[7]; // [rsp+6h] [rbp-32h] BYREF
unsigned __int8 v9; // [rsp+Dh] [rbp-2Bh] BYREF
unsigned __int8 v10; // [rsp+Eh] [rbp-2Ah] BYREF
unsigned __int8 v11[41]; // [rsp+Fh] [rbp-29h] BYREF

enable_motor(a2);
v6 = get_port(7u);
outportb(0, v6);
dma_init(memaddr, 512, a3);
lba_to_chs(a1, v11, &v10, &v9);
if ( (a3 & 1) != 0 )
send_byte(0xE6u);
else
send_byte(0xE5u);
send_byte((4 * v11[0]) | a2);
send_byte(v10);
send_byte(v11[0]);
send_byte(v9);
send_byte(2u);
send_byte(0x12u);
send_byte(0x1Bu);
printf("Waiting for int");
wait_for_int();
printf("Int Arrived");
get_results(v8);
printf("Results Arrived");
memcpy(a4, (_DWORD *)memaddr, 0x200u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned __int64 a1, char a2, char a3, _DWORD *a4)
{
__int16 v6; // ax
char v8[7]; // [rsp+6h] [rbp-32h] BYREF
unsigned __int8 v9; // [rsp+Dh] [rbp-2Bh] BYREF
unsigned __int8 v10; // [rsp+Eh] [rbp-2Ah] BYREF
unsigned __int8 v11[41]; // [rsp+Fh] [rbp-29h] BYREF

func5(a2);
v6 = func2(7u);
func0(0, v6);
func3(memaddr, 512, a3);
func11(a1, v11, &v10, &v9);
if ( (a3 & 1) != 0 )
func18(0xE6u);
else
func18(0xE5u);
func18((4 * v11[0]) | a2);
func18(v10);
func18(v11[0]);
func18(v9);
func18(2u);
func18(0x12u);
func18(0x1Bu);
printf("Waiting for int");
func4();
printf("Int Arrived");
func20(v8);
printf("Results Arrived");
memcpy(a4, (_DWORD *)memaddr, 0x200u);
return 0LL;
}

original_code:
static inline int fdc_rw_sect(uint32_t block, uint8_t drive, int type, void *data)
{
 unsigned char head, cyl, sector;
 unsigned char results[7];
 int times;
 enable_motor(drive);
 (outportb(0, get_port(0x07)));
 for(times = 0; times < 3; times++)
 {
  dma_init(memaddr, 512, type);
  lba_to_chs(block, &head, &cyl, &sector);
  if(type & 1)
   send_byte((0x06 | 0x40 | 0x80 | 0x20));
  else
   send_byte((0x05 | 0x40 | 0x80 | 0x20));
  send_byte((head << 2) | drive);
  send_byte(cyl);
  send_byte(head);
  send_byte(sector);
  send_byte(2);
  send_byte(18);
  send_byte(0x1B);
  printf("Waiting for int");
  wait_for_int();
  printf("Int Arrived");
  get_results(results);
  printf("Results Arrived");
  memcpy(data, memaddr, 512);
  return 0;
 }
 return -1;
}

canonical_original_code:
static inline int fdc_rw_sect(unsigned long block, unsigned char drive, int type, void *data)
{
 unsigned char head; unsigned char cyl; unsigned char sector;
 unsigned char results[7];
 int times;
 enable_motor(drive);
 (outportb(0, get_port(0x07)));
 for(times = 0; times < 3; times++)
 {
  dma_init(memaddr, 512, type);
  lba_to_chs(block, &head, &cyl, &sector);
  if(type & 1)
   send_byte((0x06 | 0x40 | 0x80 | 0x20));
  else
   send_byte((0x05 | 0x40 | 0x80 | 0x20));
  send_byte((head << 2) | drive);
  send_byte(cyl);
  send_byte(head);
  send_byte(sector);
  send_byte(2);
  send_byte(18);
  send_byte(0x1B);
  printf("Waiting for int");
  wait_for_int();
  printf("Int Arrived");
  get_results(results);
  printf("Results Arrived");
  memcpy(data, memaddr, 512);
  return 0;
 }
 return -1;
}

variable_types:
block
unsigned long

variable_types: type int

variable_types:
data
void *

variable_types:
head
unsigned char

variable_types:
cyl
unsigned char

variable_types:
sector
unsigned char

variable_types:
results
unsigned char [7]

variable_types: times int


decompiled_code:
__int64 fdc_reset()
{
__int16 v0; // ax

v0 = get_port(2u);
return outportb(0, v0);
}

original_code:
void fdc_reset()
{
 (outportb(0, get_port(0x02)));
}


recalibrate

decompiled_code:
__int64 __fastcall recalibrate(char a1)
{
enable_motor(a1);
send_byte(7u);
send_byte(a1);
wait_for_int();
return send_byte(8u);
}

canonical_decompiled_code:
__int64 __fastcall func23(char a1)
{
func5(a1);
func18(7u);
func18(a1);
func4();
return func18(8u);
}

original_code:
void recalibrate(uint8_t drive)
{
 enable_motor(drive);
 send_byte((0x07));
 send_byte(drive);
 wait_for_int();
 send_byte(0x08);
}

canonical_original_code:
void recalibrate(unsigned char drive)
{
 enable_motor(drive);
 send_byte((0x07));
 send_byte(drive);
 wait_for_int();
 send_byte(0x08);
}


decompiled_code:
__int64 fdc_initialize()
{
__int16 v0; // ax
__int16 v1; // ax

fdc_reset();
v0 = get_port(7u);
outportb(0, v0);
v1 = get_port(2u);
outportb(0xCu, v1);
return 0LL;
}

original_code:
int fdc_initialize()
{
 fdc_reset();
 (outportb(0, get_port(0x07)));
 (outportb(0x04|0x08, get_port(0x02)));
 return 0;
}


decompiled_code:
__int64 fdc_init()
{
_DWORD *v0; // rax
int v1; // eax
_DWORD v3[18]; // [rsp+0h] [rbp-48h] BYREF

printf("Initializing Floppy Driver... \n");
IRQ_request(6LL, fdc_intr);
v0 = malloc(0x10uLL);
device = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
detect_devices(v0);
register_blockdev(2LL, &fdcblkop, 4LL);
v3[10] = 512;
v1 = syscall_vm_map(v3, 64LL);
memaddr = v1;
if ( v1 )
return 0LL;
printf("Could Not allocate space in lowmem\n");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func25()
{
_DWORD *v0; // rax
int v1; // eax
_DWORD v3[18]; // [rsp+0h] [rbp-48h] BYREF

printf("Initializing Floppy Driver... \n");
IRQ_request(6LL, fdc_intr);
v0 = malloc(0x10uLL);
device = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
func7(v0);
register_blockdev(2LL, &fdcblkop, 4LL);
v3[10] = 512;
v1 = func16(v3, 64LL);
memaddr = v1;
if ( v1 )
return 0LL;
printf("Could Not allocate space in lowmem\n");
return 0xFFFFFFFFLL;
}

original_code:
int fdc_init()
{
 struct vn_object obj;
 printf("Initializing Floppy Driver... \n");
 IRQ_request(6, fdc_intr);
 device = malloc(sizeof(struct device) * 4);
 if(!device)
  return -1;
 detect_devices(device);
 register_blockdev(2, &fdcblkop, 4);
 obj.size = 512;
 memaddr = (void *)syscall_vm_map(&obj, 0x40);
 if(memaddr == ((void *) 0))
 {
  printf("Could Not allocate space in lowmem\n");
  return -1;
 }
 return 0;
}

variable_types: struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned long va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned long noload_start; }


decompiled_code:
__int64 fdc_exit()
{
free(device);
unregister_blockdev(2LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func26()
{
free(device);
unregister_blockdev(2LL);
return 0LL;
}

original_code:
int fdc_exit()
{
 free(device);
 unregister_blockdev(2);
 return 0;
}


decompiled_code:
__int64 __fastcall fdc_rw(__int64 a1, int a2)
{
char *v2; // rbx
unsigned __int64 v3; // rbp
char v4; // r14
int v5; // er12
__int64 result; // rax

v2 = *(char **)(a1 + 32);
v3 = *(_QWORD *)(a1 + 16);
v4 = *(_BYTE *)a1;
if ( !*(_DWORD *)(a1 + 24) )
return 0LL;
v5 = 0;
while ( 1 )
{
result = fdc_rw_sect(v3, v4, *(_DWORD *)(a1 + 12), v2);
if ( (int)result < 0 )
break;
printf("DATA %s", v2);
++v3;
v2 += a2;
if ( *(_DWORD *)(a1 + 24) <= (unsigned int)++v5 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1, int a2)
{
char *v2; // rbx
unsigned __int64 v3; // rbp
char v4; // r14
int v5; // er12
__int64 result; // rax

v2 = *(char **)(a1 + 32);
v3 = *(_QWORD *)(a1 + 16);
v4 = *(_BYTE *)a1;
if ( !*(_DWORD *)(a1 + 24) )
return 0LL;
v5 = 0;
while ( 1 )
{
result = func21(v3, v4, *(_DWORD *)(a1 + 12), v2);
if ( (int)result < 0 )
break;
printf("DATA %s", v2);
++v3;
v2 += a2;
if ( *(_DWORD *)(a1 + 24) <= (unsigned int)++v5 )
return 0LL;
}
return result;
}

original_code:
int fdc_rw(struct operation *op, int sector_size)
{
 int times, ret;
 void *data = op->buffer;
 uint32_t block = op->block;
 uint8_t device = ((op->device & 0xFFFF) & 0xFF);
 for(times = 0; times < op->blksize; times++)
 {
  ret = fdc_rw_sect(block, device, op->type, data);
  if(ret < 0)
   return ret;
  printf("DATA %s", data);
  block++;
  data = (void *)((uint32_t)data + sector_size);
 }
 return 0;
}

canonical_original_code:
int fdc_rw(struct operation *op, int sector_size)
{
 int times; int ret;
 void *data = op->buffer;
 unsigned long block = op->block;
 unsigned char device = ((op->device & 0xFFFF) & 0xFF);
 for(times = 0; times < op->blksize; times++)
 {
  ret = fdc_rw_sect(block, device, op->type, data);
  if(ret < 0)
   return ret;
  printf("DATA %s", data);
  block++;
  data = (void *)((unsigned long)data + sector_size);
 }
 return 0;
}

variable_types: ret int

variable_types:
device
unsigned char


decompiled_code:
__int64 __fastcall fdc_strategy(unsigned __int8 *a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

v1 = *((_DWORD *)device + *a1);
v2 = *((_DWORD *)a1 + 6) / v1;
*((_DWORD *)a1 + 6) = v2;
*((_QWORD *)a1 + 2) *= v2;
*((_DWORD *)a1 + 2) = pthread_self();
printf("reading block %d \n", *((_QWORD *)a1 + 2));
return fdc_rw((__int64)a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func28(unsigned __int8 *a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

v1 = *((_DWORD *)device + *a1);
v2 = *((_DWORD *)a1 + 6) / v1;
*((_DWORD *)a1 + 6) = v2;
*((_QWORD *)a1 + 2) *= v2;
*((_DWORD *)a1 + 2) = pthread_self();
printf("reading block %d \n", *((_QWORD *)a1 + 2));
return func27((__int64)a1, v1);
}

original_code:
int fdc_strategy(struct operation *op)
{
 int diskno = ((op->device & 0xFFFF) & 0xFF);
 int sector_size = device[diskno].sector_size;
 op->blksize = op->blksize/sector_size;
 op->block = (op->block * op->blksize);
 op->caller = pthread_self();
 glob_oper = op;
 printf("reading block %d \n", op->block);
 return fdc_rw(op, sector_size);
}

variable_types: struct operation { unsigned long device; int caller; int type; unsigned long block; unsigned int blksize; void *buffer; } *

variable_types: diskno int


decompiled_code:
__int64 __fastcall chrdev_open(__int64 a1, __int64 a2)
{
void (**v2)(void); // rax
void (*v3)(void); // rax

v2 = (void (**)(void))chrdev[2 * (*(_QWORD *)(a2 + 32) >> 16)];
if ( !v2 )
return 0LL;
v3 = *v2;
if ( !v3 )
return 0LL;
v3();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
void (**v2)(void); // rax
void (*v3)(void); // rax

v2 = (void (**)(void))chrdev[2 * (*(_QWORD *)(a2 + 32) >> 16)];
if ( !v2 )
return 0LL;
v3 = *v2;
if ( !v3 )
return 0LL;
v3();
return 0LL;
}

original_code:
int chrdev_open(struct file *file, struct vnode *vn, mode_t mode)
{
 struct chevsw *chops ;
 chops = chrdev[(vn->v_rdev >> 16)].ops;
 if(!chops || !chops->d_open)
  return 0;
 chops->d_open(file, vn, mode);
 return 0;
}

canonical_original_code:
int chrdev_open(struct file *file, struct vnode *vn, int mode)
{
 struct chevsw *chops;
 chops = chrdev[(vn->v_rdev >> 16)].ops;
 if(!chops || !chops->d_open)
  return 0;
 chops->d_open(file, vn, mode);
 return 0;
}

variable_types: mode int

variable_types: struct chevsw { int (*d_open)(struct file { int f_access; unsigned long f_offset; int f_ref; struct indev { int inode; unsigned long dev; } vnode; } *, struct vnode { unsigned short v_flag; int v_count; struct vfs { struct linked_list { void *next; } vfs_next; struct vnode *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb { struct ext2_super_block { unsigned long s_inodes_count; unsigned long s_blocks_count; unsigned long s_r_blocks_count; unsigned long s_free_blocks_count; unsigned long s_free_inodes_count; unsigned long s_first_data_block; unsigned long s_log_block_size; unsigned long s_log_frag_size; unsigned long s_blocks_per_group; unsigned long s_frags_per_group; unsigned long s_inodes_per_group; unsigned long s_mtime; unsigned long s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_pad; unsigned short s_minor_rev_level; unsigned long s_lastcheck; unsigned long s_checkinterval; unsigned long s_creator_os; unsigned long s_rev_level; unsigned short s_def_resuid; unsigned short s_def_regid; unsigned long s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned long s_feature_compat; unsigned long s_feature_incompat; unsigned long s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned long s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_padding1; unsigned long s_reserved[204]; } ext2; struct ext2_group_desc { unsigned long bg_block_bitmap; unsigned long bg_inode_bitmap; unsigned long bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned long bg_reserved[3]; } *gdes; } ext2_sb; struct fat_super_block { int ino_val; int fat_type; char fatbs[512]; void *bsptr; } fat; } sb; struct vfsops { int (*vfs_mount)(); int (*vfs_unmount)(); int (*vfs_statvfs)(); int (*vfs_sync)(); } *ops; struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } lock; } *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops { int (*vop_open)(struct file *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata { struct vnode *vn; struct userid { int uid; int gid; } id; struct vfs *vfs; char *path; int mode; int access; } *); void (*vop_get_attr)(struct vnode *, struct vattr { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; } *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); } *ops; void *data; struct mrx_mutex smlock; union inode { struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; } ext2inode; } v_ino; } *, int); int (*d_close)(struct file *, struct vnode *); int (*d_read)(struct file *, struct vnode *, void *, unsigned int); int (*d_write)(struct file *, struct vnode *, void *, unsigned int); int (*d_ioctl)(); int (*d_mmap)(); } *

user_defined_types: struct chevsw { int (*d_open)(struct file *, struct vnode *, int); int (*d_close)(struct file *, struct vnode *); int (*d_read)(struct file *, struct vnode *, void *, unsigned int); int (*d_write)(struct file *, struct vnode *, void *, unsigned int); int (*d_ioctl)(); int (*d_mmap)(); }

user_defined_types: union inode { struct ext2inode ext2inode; }

user_defined_types: struct vfs { struct linked_list vfs_next; struct vnode *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb ext2_sb; struct fat_super_block fat; } sb; struct vfsops *ops; struct mrx_mutex lock; }


original_code:
int chrdev_close(struct file *file, struct vnode *vn)
{
 if(!vn || !vn->ops || !vn->ops->vop_close)
  return 0;
 chrdev[(vn->v_rdev >> 16)].ops->d_close(file, vn);
 return 0;
}

variable_types: struct file { int f_access; unsigned long f_offset; int f_ref; struct indev { int inode; unsigned long dev; } vnode; } *

variable_types: struct vnode { unsigned short v_flag; int v_count; struct vfs { struct linked_list { void *next; } vfs_next; struct vnode *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb { struct ext2_super_block { unsigned long s_inodes_count; unsigned long s_blocks_count; unsigned long s_r_blocks_count; unsigned long s_free_blocks_count; unsigned long s_free_inodes_count; unsigned long s_first_data_block; unsigned long s_log_block_size; unsigned long s_log_frag_size; unsigned long s_blocks_per_group; unsigned long s_frags_per_group; unsigned long s_inodes_per_group; unsigned long s_mtime; unsigned long s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_pad; unsigned short s_minor_rev_level; unsigned long s_lastcheck; unsigned long s_checkinterval; unsigned long s_creator_os; unsigned long s_rev_level; unsigned short s_def_resuid; unsigned short s_def_regid; unsigned long s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned long s_feature_compat; unsigned long s_feature_incompat; unsigned long s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned long s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_padding1; unsigned long s_reserved[204]; } ext2; struct ext2_group_desc { unsigned long bg_block_bitmap; unsigned long bg_inode_bitmap; unsigned long bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned long bg_reserved[3]; } *gdes; } ext2_sb; struct fat_super_block { int ino_val; int fat_type; char fatbs[512]; void *bsptr; } fat; } sb; struct vfsops { int (*vfs_mount)(); int (*vfs_unmount)(); int (*vfs_statvfs)(); int (*vfs_sync)(); } *ops; struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } lock; } *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops { int (*vop_open)(struct file *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata { struct vnode *vn; struct userid { int uid; int gid; } id; struct vfs *vfs; char *path; int mode; int access; } *); void (*vop_get_attr)(struct vnode *, struct vattr { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; } *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); } *ops; void *data; struct mrx_mutex smlock; union inode { struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; } ext2inode; } v_ino; } *

user_defined_types: struct vnodeops { int (*vop_open)(struct file *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata *); void (*vop_get_attr)(struct vnode *, struct vattr *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); }

user_defined_types: struct mrx_mutex { struct mrx_mutexattr mattr; int counter; int sync_id; }

user_defined_types: struct ext2sb { struct ext2_super_block ext2; struct ext2_group_desc *gdes; }


original_code:
int chrdev_read(struct file *file, struct vnode *vn, void *data, size_t size)
{
 chrdev[(vn->v_rdev >> 16)].ops->d_read(file, vn, data, size);
 return 0;
}

canonical_original_code:
int chrdev_read(struct file *file, struct vnode *vn, void *data, unsigned int size)
{
 chrdev[(vn->v_rdev >> 16)].ops->d_read(file, vn, data, size);
 return 0;
}

variable_types:
size
unsigned int

user_defined_types: struct file { int f_access; unsigned long f_offset; int f_ref; struct indev vnode; }

user_defined_types: struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; }

user_defined_types: struct nameidata { struct vnode *vn; struct userid id; struct vfs *vfs; char *path; int mode; int access; }


original_code:
int chrdev_write(struct file *file, struct vnode *vn, void *data, size_t size)
{
 chrdev[(vn->v_rdev >> 16)].ops->d_write(file, vn, data, size);
 return 0;
}

canonical_original_code:
int chrdev_write(struct file *file, struct vnode *vn, void *data, unsigned int size)
{
 chrdev[(vn->v_rdev >> 16)].ops->d_write(file, vn, data, size);
 return 0;
}

user_defined_types: struct fat_super_block { int ino_val; int fat_type; char fatbs[512]; void *bsptr; }

user_defined_types: struct vfsops { int (*vfs_mount)(); int (*vfs_unmount)(); int (*vfs_statvfs)(); int (*vfs_sync)(); }


decompiled_code:
__int64 __fastcall chrdev_register(unsigned int a1, __int64 a2)
{
if ( a1 > 0x1F )
return 0xFFFFFFFFLL;
chrdev[2 * (int)a1] = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2)
{
if ( a1 > 0x1F )
return 0xFFFFFFFFLL;
chrdev[2 * (int)a1] = a2;
return 0LL;
}

original_code:
int chrdev_register(int major, struct chevsw *chops)
{
 if((major >= 32) || (major < 0))
  return -1;
 chrdev[major].ops = chops;
 return 0;
}

variable_types: major int

user_defined_types: struct ext2_super_block { unsigned long s_inodes_count; unsigned long s_blocks_count; unsigned long s_r_blocks_count; unsigned long s_free_blocks_count; unsigned long s_free_inodes_count; unsigned long s_first_data_block; unsigned long s_log_block_size; unsigned long s_log_frag_size; unsigned long s_blocks_per_group; unsigned long s_frags_per_group; unsigned long s_inodes_per_group; unsigned long s_mtime; unsigned long s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_pad; unsigned short s_minor_rev_level; unsigned long s_lastcheck; unsigned long s_checkinterval; unsigned long s_creator_os; unsigned long s_rev_level; unsigned short s_def_resuid; unsigned short s_def_regid; unsigned long s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned long s_feature_compat; unsigned long s_feature_incompat; unsigned long s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned long s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_padding1; unsigned long s_reserved[204]; }

user_defined_types: struct ext2_group_desc { unsigned long bg_block_bitmap; unsigned long bg_inode_bitmap; unsigned long bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned long bg_reserved[3]; }


decompiled_code:
__int64 __fastcall chrdev_unregister(unsigned int a1)
{
if ( a1 > 0x1F )
return 0xFFFFFFFFLL;
chrdev[2 * (int)a1] = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
if ( a1 > 0x1F )
return 0xFFFFFFFFLL;
chrdev[2 * (int)a1] = 0LL;
return 0LL;
}

original_code:
int chrdev_unregister(int major)
{
 if((major >= 32) || (major < 0))
  return -1;
 chrdev[major].ops = ((void *) 0);
 return 0;
}


decompiled_code:
int *chr_init()
{
return memset((int *)chrdev, 0, sizeof(chrdev));
}

canonical_decompiled_code:
int *func7()
{
return func0((int *)chrdev, 0, sizeof(chrdev));
}

original_code:
void chr_init()
{
 memset((void *)chrdev, 0, sizeof(struct char_device) * 32);
}

user_defined_types: struct char_device { struct chevsw *ops; int server; }

user_defined_types: struct indev { int inode; unsigned long dev; }

user_defined_types: struct vattr { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; }


decompiled_code:
void chr_exit()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void chr_exit()
{
}

canonical_original_code:
void chr_exit()
{
}


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

result = 7LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

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

result = 7LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

original_code:
static inline int syscall_get_ppid()
{
 register int ppid;
 asm volatile (
  "int $0x30\n\t"
  :"=a"(ppid)
  :"0"(7)
  );
 return ppid;
}

variable_types: ppid int


access

decompiled_code:
__int64 __fastcall access(_BYTE *a1, int a2)
{
int v2; // eax
__int64 v4[6]; // [rsp+0h] [rbp-58h] BYREF
__int64 v5; // [rsp+30h] [rbp-28h]
__int16 v6; // [rsp+3Ah] [rbp-1Eh]

v2 = strlen(a1);
v6 = 2 * (v2 > 256) + 2;
v4[5] = (__int64)a1;
v4[0] = v2;
v5 = 8LL;
v4[1] = a2;
send_message(2LL, v4);
if ( (int)v5 >= 0 )
return 0LL;
errno = -(int)v5;
return 0xFFFFFFFFLL;
}

original_code:
int access(const char *path, int amode)
{
 struct message msg;
 int fd, length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.w1 = 8;
 msg.m2.w4 = amode;
 send_message(2, &msg);
 fd = msg.w1;
 if(fd < 0)
 {
  errno = -fd;
  return -1;
 }
 return 0;
}

canonical_original_code:
int access(char *path, int amode)
{
 struct message msg;
 int fd; int length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.w1 = 8;
 msg.m2.w4 = amode;
 send_message(2, &msg);
 fd = msg.w1;
 if(fd < 0)
 {
  errno = -fd;
  return -1;
 }
 return 0;
}

variable_types:
path
char *

variable_types: amode int

variable_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }

variable_types: fd int

variable_types: length int


alarm

decompiled_code:
// attributes: thunk
__int64 alarm()
{
return syscall_alarm();
}

canonical_decompiled_code:
__int64 func8()
{
return func6();
}

original_code:
unsigned alarm(unsigned seconds)
{
 return syscall_alarm(seconds);
}

canonical_original_code:
unsigned int alarm(unsigned int seconds)
{
 return syscall_alarm(seconds);
}

variable_types:
seconds
unsigned int

return_type: unsigned int


chdir

decompiled_code:
__int64 __fastcall chdir(_BYTE *a1)
{
int v1; // eax
__int64 v3[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+30h] [rbp-18h]
__int16 v5; // [rsp+3Ah] [rbp-Eh]

v1 = strlen(a1);
v5 = 2 * (v1 > 256) + 2;
v3[5] = (__int64)a1;
v3[0] = v1;
v4 = 9LL;
send_message(2LL, v3);
if ( (int)v4 >= 0 )
return 0LL;
errno = -(int)v4;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1)
{
int v1; // eax
__int64 v3[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+30h] [rbp-18h]
__int16 v5; // [rsp+3Ah] [rbp-Eh]

v1 = func0(a1);
v5 = 2 * (v1 > 256) + 2;
v3[5] = (__int64)a1;
v3[0] = v1;
v4 = 9LL;
send_message(2LL, v3);
if ( (int)v4 >= 0 )
return 0LL;
errno = -(int)v4;
return 0xFFFFFFFFLL;
}

original_code:
int chdir(const char *path)
{
 struct message msg;
 int ret, length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.w1 = 9;
 send_message(2, &msg);
 ret = msg.w1;
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int chdir(char *path)
{
 struct message msg;
 int ret; int length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.w1 = 9;
 send_message(2, &msg);
 ret = msg.w1;
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types: ret int

user_defined_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }


chown

original_code:
int chown(const char *path, uid_t owner, gid_t group)
{
 struct message msg;
 int ret, length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.w1 = 5;
 msg.m2.w4 = owner;
 msg.m3.w5 = group;
 send_message(2, &msg);
 ret = msg.w1;
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int chown(char *path, int owner, int group)
{
 struct message msg;
 int ret; int length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.w1 = 5;
 msg.m2.w4 = owner;
 msg.m3.w5 = group;
 send_message(2, &msg);
 ret = msg.w1;
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types: owner int

variable_types: group int


close

decompiled_code:
__int64 __fastcall close(int a1)
{
unsigned int v1; // edx
_QWORD v3[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+30h] [rbp-18h]
__int16 v5; // [rsp+3Ah] [rbp-Eh]

v5 = 1;
v4 = 2LL;
v3[1] = a1;
send_message(2LL, v3);
v1 = v4;
if ( (int)v4 < 0 )
{
errno = -(int)v4;
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
unsigned int v1; // edx
_QWORD v3[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+30h] [rbp-18h]
__int16 v5; // [rsp+3Ah] [rbp-Eh]

v5 = 1;
v4 = 2LL;
v3[1] = a1;
send_message(2LL, v3);
v1 = v4;
if ( (int)v4 < 0 )
{
errno = -(int)v4;
v1 = -1;
}
return v1;
}

original_code:
int close(int fildes)
{
 struct message msg;
 int fd;
 msg.flags = 1;
 msg.w1 = 2;
 msg.m2.w4 = fildes;
 send_message(2, &msg);
 fd = msg.w1;
 if(fd < 0)
 {
  errno = -fd;
  return -1;
 }
 return fd;
}

variable_types: fildes int


write

original_code:
ssize_t write(int fildes, const void *buf, size_t nbytes)
{
 struct message msg;
 tid_t server;
 if(nbytes < 256)
  msg.flags = 2;
 else
  msg.flags = 4;
 msg.m4.snd_ptr = (void *)buf;
 msg.m1.snd_bufsize = nbytes;
 msg.w1 = 4;
 msg.m2.w4 = fildes;
 if((fildes >= 0) && (fildes <= 2))
 {
  server = 1;
  msg.flags |= 0x20;
 }
 else
 {
  server = ((fildes >> 16) & 0xFFFF);
  if(!server)
   server = 2;
 }
 send_message(server, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
  return msg.w1;
}

canonical_original_code:
int write(int fildes, void *buf, unsigned int nbytes)
{
 struct message msg;
 int server;
 if(nbytes < 256)
  msg.flags = 2;
 else
  msg.flags = 4;
 msg.m4.snd_ptr = (void *)buf;
 msg.m1.snd_bufsize = nbytes;
 msg.w1 = 4;
 msg.m2.w4 = fildes;
 if((fildes >= 0) && (fildes <= 2))
 {
  server = 1;
  msg.flags |= 0x20;
 }
 else
 {
  server = ((fildes >> 16) & 0xFFFF);
  if(!server)
   server = 2;
 }
 send_message(server, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
  return msg.w1;
}

variable_types:
buf
void *

variable_types:
nbytes
unsigned int

variable_types: server int


read

decompiled_code:
__int64 __fastcall read(unsigned int a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax
_QWORD v5[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+30h] [rbp-18h]
__int16 v7; // [rsp+3Ah] [rbp-Eh]

v7 = a3 < 0x100 ? 64 : 8;
v5[1] = a2;
v5[2] = a3;
v6 = 3LL;
v5[5] = (int)a1;
v3 = 1;
if ( a1 > 2 )
{
v3 = HIWORD(a1);
if ( !HIWORD(a1) )
v3 = 2;
}
send_message(v3, v5);
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax
_QWORD v5[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+30h] [rbp-18h]
__int16 v7; // [rsp+3Ah] [rbp-Eh]

v7 = a3 < 0x100 ? 64 : 8;
v5[1] = a2;
v5[2] = a3;
v6 = 3LL;
v5[5] = (int)a1;
v3 = 1;
if ( a1 > 2 )
{
v3 = HIWORD(a1);
if ( !HIWORD(a1) )
v3 = 2;
}
send_message(v3, v5);
return (unsigned int)v6;
}

original_code:
ssize_t read(int fildes, void *buf, size_t nbyte)
{
 struct message msg;
 tid_t server;
 if(nbyte < 256)
  msg.flags = 0x40;
 else
  msg.flags = 8;
 msg.m2.rcv_ptr = buf;
 msg.m3.rcv_bufsize = nbyte;
 msg.w1 = 3;
 msg.m4.w2 = fildes;
 if((fildes >= 0) && (fildes <= 2))
  server = 1;
 else
 {
  server = ((fildes >> 16) & 0xFFFF);
  if(!server)
   server = 2;
 }
 send_message(server, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return msg.w1;
}

canonical_original_code:
int read(int fildes, void *buf, unsigned int nbyte)
{
 struct message msg;
 int server;
 if(nbyte < 256)
  msg.flags = 0x40;
 else
  msg.flags = 8;
 msg.m2.rcv_ptr = buf;
 msg.m3.rcv_bufsize = nbyte;
 msg.w1 = 3;
 msg.m4.w2 = fildes;
 if((fildes >= 0) && (fildes <= 2))
  server = 1;
 else
 {
  server = ((fildes >> 16) & 0xFFFF);
  if(!server)
   server = 2;
 }
 send_message(server, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return msg.w1;
}

variable_types:
nbyte
unsigned int


getgid

decompiled_code:
__int64 __fastcall getgid(__int64 a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

syscall_get_user(0, v5, a3, a4);
return v5[2];
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

func5(0, v5, a3, a4);
return v5[2];
}

original_code:
gid_t getgid(void)
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.gid;
}

canonical_original_code:
int getgid()
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.gid;
}

variable_types:
id
struct userid { int uid; int gid; }


getegid

decompiled_code:
__int64 __fastcall getegid(__int64 a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

syscall_get_user(0, v5, a3, a4);
return v5[3];
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

func5(0, v5, a3, a4);
return v5[3];
}

original_code:
gid_t getegid(void)
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.egid;
}

canonical_original_code:
int getegid()
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.egid;
}


geteuid

decompiled_code:
__int64 __fastcall geteuid(__int64 a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

syscall_get_user(0, v5, a3, a4);
return v5[1];
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

func5(0, v5, a3, a4);
return v5[1];
}

original_code:
uid_t geteuid(void)
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.euid;
}

canonical_original_code:
int geteuid()
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.euid;
}


getuid

decompiled_code:
__int64 __fastcall getuid(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int v5[4]; // [rsp+0h] [rbp-10h] BYREF

syscall_get_user(0, v5, a3, a4);
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int v5[4]; // [rsp+0h] [rbp-10h] BYREF

func5(0, v5, a3, a4);
return v5[0];
}

original_code:
uid_t getuid(void)
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.uid;
}

canonical_original_code:
int getuid()
{
 struct userid id;
 syscall_get_user(0, &id);
 return id.uid;
}


setegid

decompiled_code:
__int64 __fastcall setegid(int a1)
{
int v2[4]; // [rsp+0h] [rbp-10h] BYREF

v2[0] = -1;
v2[1] = -1;
v2[2] = -1;
v2[3] = a1;
return syscall_set_user(0LL, v2);
}

original_code:
int setegid(gid_t egid)
{
 struct userid id;
 id.uid = -1;
 id.euid = -1;
 id.gid = -1;
 id.egid = egid;
 return syscall_set_user(0, &id);
}

canonical_original_code:
int setegid(int egid)
{
 struct userid id;
 id.uid = -1;
 id.euid = -1;
 id.gid = -1;
 id.egid = egid;
 return syscall_set_user(0, &id);
}

variable_types: egid int


setgid

decompiled_code:
__int64 __fastcall setgid(int a1)
{
int v2[4]; // [rsp+0h] [rbp-10h] BYREF

v2[0] = -1;
v2[1] = -1;
v2[2] = a1;
v2[3] = -1;
return syscall_set_user(0LL, v2);
}

original_code:
int setgid(gid_t gid)
{
 struct userid id;
 id.uid = -1;
 id.euid = -1;
 id.gid = gid;
 id.egid = -1;
 return syscall_set_user(0, &id);
}

canonical_original_code:
int setgid(int gid)
{
 struct userid id;
 id.uid = -1;
 id.euid = -1;
 id.gid = gid;
 id.egid = -1;
 return syscall_set_user(0, &id);
}

variable_types: gid int


setuid

decompiled_code:
__int64 __fastcall setuid(int a1)
{
int v2[4]; // [rsp+0h] [rbp-10h] BYREF

v2[0] = a1;
v2[1] = -1;
v2[2] = -1;
v2[3] = -1;
return syscall_set_user(0LL, v2);
}

original_code:
int setuid(uid_t uid)
{
 struct userid id;
 id.uid = uid;
 id.euid = -1;
 id.gid = -1;
 id.egid = -1;
 return syscall_set_user(0, &id);
}

canonical_original_code:
int setuid(int uid)
{
 struct userid id;
 id.uid = uid;
 id.euid = -1;
 id.gid = -1;
 id.egid = -1;
 return syscall_set_user(0, &id);
}

variable_types: uid int


seteuid

decompiled_code:
__int64 __fastcall seteuid(int a1)
{
int v2[4]; // [rsp+0h] [rbp-10h] BYREF

v2[0] = -1;
v2[1] = a1;
v2[2] = -1;
v2[3] = -1;
return syscall_set_user(0LL, v2);
}

original_code:
int seteuid(uid_t euid)
{
 struct userid id;
 id.uid = -1;
 id.euid = euid;
 id.gid = -1;
 id.egid = -1;
 return syscall_set_user(0, &id);
}

canonical_original_code:
int seteuid(int euid)
{
 struct userid id;
 id.uid = -1;
 id.euid = euid;
 id.gid = -1;
 id.egid = -1;
 return syscall_set_user(0, &id);
}

variable_types: euid int


getpgid

decompiled_code:
__int64 __fastcall getpgid(int a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

syscall_get_user(a1, v5, a3, a4);
return v5[2];
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1, __int64 a2, int a3, int a4)
{
_DWORD v5[4]; // [rsp+0h] [rbp-10h] BYREF

func5(a1, v5, a3, a4);
return v5[2];
}

original_code:
pid_t getpgid(pid_t pid)
{
 struct userid id;
 syscall_get_user(pid, &id);
 return id.gid;
}

canonical_original_code:
int getpgid(int pid)
{
 struct userid id;
 syscall_get_user(pid, &id);
 return id.gid;
}

variable_types: pid int


getpgrp

decompiled_code:
// attributes: thunk
__int64 __fastcall getpgrp(__int64 a1, __int64 a2, int a3, int a4)
{
return getgid(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2, int a3, int a4)
{
return func14(a1, a2, a3, a4);
}

original_code:
pid_t getpgrp(void)
{
 return getgid();
}

canonical_original_code:
int getpgrp()
{
 return getgid();
}


setpgid

original_code:
int setpgid(pid_t pid, pid_t pgid)
{
 struct userid id;
 id.uid = -1;
 id.euid = -1;
 id.gid = pgid;
 id.egid = -1;
 return syscall_set_user(pid, &id);
}

canonical_original_code:
int setpgid(int pid, int pgid)
{
 struct userid id;
 id.uid = -1;
 id.euid = -1;
 id.gid = pgid;
 id.egid = -1;
 return syscall_set_user(pid, &id);
}

variable_types: pgid int


setsid

decompiled_code:
__int64 setsid()
{
return setpgid(0LL, 1);
}

canonical_decompiled_code:
__int64 func25()
{
return func24(0LL, 1);
}

original_code:
pid_t setsid(void)
{
 return setpgid(0, 1);
}

canonical_original_code:
int setsid()
{
 return setpgid(0, 1);
}


setpgrp

decompiled_code:
__int64 setpgrp()
{
return setpgid(0LL, 1);
}

canonical_decompiled_code:
__int64 func26()
{
return func24(0LL, 1);
}

original_code:
pid_t setpgrp(void)
{
 return setpgid(0, 1);
}

canonical_original_code:
int setpgrp()
{
 return setpgid(0, 1);
}


getpid

decompiled_code:
__int64 getpid()
{
return syscall_get_pid(0LL);
}

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

original_code:
pid_t getpid(void)
{
 return syscall_get_pid(0);
}

canonical_original_code:
int getpid()
{
 return syscall_get_pid(0);
}


getppid

decompiled_code:
__int64 getppid()
{
return syscall_get_ppid();
}

canonical_decompiled_code:
__int64 func28()
{
return func3();
}

original_code:
pid_t getppid(void)
{
 return syscall_get_ppid();
}

canonical_original_code:
int getppid()
{
 return syscall_get_ppid();
}


dup

decompiled_code:
__int64 __fastcall dup(__int64 a1)
{
return syscall_dup(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1)
{
return func1(a1, 0LL);
}

original_code:
int dup(int fildes)
{
 return syscall_dup(fildes, 0);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall dup2(__int64 a1, __int64 a2)
{
return syscall_dup(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1, __int64 a2)
{
return func1(a1, a2);
}

original_code:
int dup2(int fildes, int fildes2)
{
 return syscall_dup(fildes, fildes2);
}


decompiled_code:
__int64 __fastcall mrx_mutex_sleep(__int64 a1)
{
return syscall_sync_lock(*(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return func0(*(unsigned int *)(a1 + 16));
}

original_code:
void mrx_mutex_sleep(mrx_mutex_t *mt)
{
 syscall_sync_lock(mt->sync_id);
}

canonical_original_code:
void mrx_mutex_sleep(struct mrx_mutex *mt)
{
 syscall_sync_lock(mt->sync_id);
}

variable_types: struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } *


decompiled_code:
__int64 __fastcall mrx_mutex_wake(__int64 a1)
{
return syscall_sync_unlock(*(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return func1(*(unsigned int *)(a1 + 16));
}

original_code:
void mrx_mutex_wake(mrx_mutex_t *mt)
{
 syscall_sync_unlock(mt->sync_id);
}

canonical_original_code:
void mrx_mutex_wake(struct mrx_mutex *mt)
{
 syscall_sync_unlock(mt->sync_id);
}

user_defined_types: struct mrx_mutexattr { int type; int pshared; int protocol; }


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

result = syscall_send_message();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = syscall_send_message();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int send_message(tid_t tid, message_t msg)
{
 int ret;
 ret = syscall_send_message(tid, msg);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

canonical_original_code:
int send_message(int tid, struct message *msg)
{
 int ret;
 ret = syscall_send_message(tid, msg);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

variable_types: tid int

variable_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; } *


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

result = syscall_receive_message();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = syscall_receive_message();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int receive_message(tid_t tid, message_t msg)
{
 int ret;
 ret = syscall_receive_message(tid, msg);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

canonical_original_code:
int receive_message(int tid, struct message *msg)
{
 int ret;
 ret = syscall_receive_message(tid, msg);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

variable_types: ret int


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

result = syscall_reply_message();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = syscall_reply_message();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int reply_message(tid_t tid, message_t msg)
{
 int ret;
 ret = syscall_reply_message(tid, msg);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

canonical_original_code:
int reply_message(int tid, struct message *msg)
{
 int ret;
 ret = syscall_reply_message(tid, msg);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}


original_code:
static void cache_const(void *object, kmem_cache_t cache)
{
 kmem_cache_t obj = (kmem_cache_t) object;
 list_init(&obj->full);
 list_init(&obj->partial);
 list_init(&obj->free);
 obj->object = 0;
 obj->waste = 0;
 obj->nobjects = 0;
 obj->align = 0;
 obj->next_cache = ((void *)0);
}

canonical_original_code:
static void cache_const(void *object, struct kmem_cache *cache)
{
 struct kmem_cache *obj = (kmem_cache_t) object;
 list_init(&obj->full);
 list_init(&obj->partial);
 list_init(&obj->free);
 obj->object = 0;
 obj->waste = 0;
 obj->nobjects = 0;
 obj->align = 0;
 obj->next_cache = ((void *)0);
}

variable_types:
object
void *

variable_types: struct kmem_cache { struct linked_list { void *next; } partial; struct linked_list full; struct linked_list free; unsigned int object; unsigned int waste; unsigned int nobjects; unsigned char align; void (*ctor)(void *, struct kmem_cache *); void (*dtor)(void *, struct kmem_cache *); char name[11]; struct kmem_cache *next_cache; struct spinlock { int lock; } lock; } *

user_defined_types: struct kmem_cache { struct linked_list partial; struct linked_list full; struct linked_list free; unsigned int object; unsigned int waste; unsigned int nobjects; unsigned char align; void (*ctor)(void *, struct kmem_cache *); void (*dtor)(void *, struct kmem_cache *); char name[11]; struct kmem_cache *next_cache; struct spinlock lock; }


original_code:
static inline void free_all(kmem_cache_t cache)
{
 kmem_slab_t tmp;
 { do{}while(0); };
 while(cache->free.next != &cache->free)
 {
  tmp = cache->free.next;
  { kmem_slab_t nxt; (tmp) = (kmem_slab_t)(&cache->free)->next; nxt = (kmem_slab_t)(tmp)->list.next; (&cache->free)->next = nxt; if(nxt == (kmem_slab_t)&cache->free) (&cache->free)->prev = &cache->free; else nxt->list.prev = &cache->free; };
  page_dealloc(&kernel_object, (vm_offset_t)tmp);
 }
 { do{}while(0); };
}

canonical_original_code:
static inline void free_all(struct kmem_cache *cache)
{
 struct kmem_slab *tmp;
 { do{}while(0); };
 while(cache->free.next != &cache->free)
 {
  tmp = cache->free.next;
  { struct kmem_slab *nxt; (tmp) = (kmem_slab_t)(&cache->free)->next; nxt = (kmem_slab_t)(tmp)->list.next; (&cache->free)->next = nxt; if(nxt == (kmem_slab_t)&cache->free) (&cache->free)->prev = &cache->free; else nxt->list.prev = &cache->free; };
  page_dealloc(&kernel_object, (unsigned int)tmp);
 }
 { do{}while(0); };
}

variable_types: struct kmem_slab { struct linked_list { void *next; } list; void *objaddr; short nentries; unsigned short free; } *

user_defined_types: struct kmem_slab { struct linked_list list; void *objaddr; short nentries; unsigned short free; }


decompiled_code:
unsigned __int64 slab_init()
{
list_init(qword_470);
list_init(cache_cache);
list_init(qword_480);
dword_4C8 = 1;
return cache_calculate((__int64)cache_cache, dword_498, &dword_494);
}

canonical_decompiled_code:
unsigned __int64 func6()
{
func1(qword_470);
func1(cache_cache);
func1(qword_480);
dword_4C8 = 1;
return func3((__int64)cache_cache, dword_498, &dword_494);
}

original_code:
void slab_init()
{
 list_init(&cache_cache.full);
 list_init(&cache_cache.partial);
 list_init(&cache_cache.free);
 ((&cache_cache.lock)->lock = 1);
 cache_calculate(&cache_cache,&cache_cache.nobjects, &cache_cache.waste);
}


original_code:
void *kmem_cache_alloc(kmem_cache_t cache, u32 flags)
{
 void *objp;
 kmem_slab_t slab;
 kmem_slab_t temp;
 { do{}while(0); };
 if(cache->partial.next == &cache->partial)
 {
  if(cache->free.next == &cache->free)
  {
   kmem_cache_grow(cache);
  }
  else
  {
   temp = cache->free.next;
   { kmem_slab_t nxt; (temp) = (kmem_slab_t)(&cache->free)->next; nxt = (kmem_slab_t)(temp)->list.next; (&cache->free)->next = nxt; if(nxt == (kmem_slab_t)&cache->free) (&cache->free)->prev = &cache->free; else nxt->list.prev = &cache->free; };
   { kmem_slab_t nxt = (kmem_slab_t)(&cache->partial)->next; (&cache->partial)->next = (temp); (temp)->list.prev = (kmem_slab_t)(&cache->partial); (temp)->list.next = (kmem_slab_t)nxt; if(nxt == (kmem_slab_t) &cache->partial) (&cache->partial)->prev = (temp); else nxt->list.prev = (kmem_slab_t)(temp); };
  }
 }
 slab = (kmem_slab_t)cache->partial.next;
 objp = slab->objaddr + (slab->free * cache->object);
 slab->free = ((bufctl_t *)(((struct kmem_slab *)(slab))+1))[slab->free];
 slab->nentries += 1;
 { do{}while(0); };
 return objp;
}

canonical_original_code:
void *kmem_cache_alloc(struct kmem_cache *cache, unsigned int flags)
{
 void *objp;
 struct kmem_slab *slab;
 struct kmem_slab *temp;
 { do{}while(0); };
 if(cache->partial.next == &cache->partial)
 {
  if(cache->free.next == &cache->free)
  {
   kmem_cache_grow(cache);
  }
  else
  {
   temp = cache->free.next;
   { struct kmem_slab *nxt; (temp) = (kmem_slab_t)(&cache->free)->next; nxt = (kmem_slab_t)(temp)->list.next; (&cache->free)->next = nxt; if(nxt == (kmem_slab_t)&cache->free) (&cache->free)->prev = &cache->free; else nxt->list.prev = &cache->free; };
   { struct kmem_slab *nxt = (kmem_slab_t)(&cache->partial)->next; (&cache->partial)->next = (temp); (temp)->list.prev = (kmem_slab_t)(&cache->partial); (temp)->list.next = (struct kmem_slab *)nxt; if(nxt == (kmem_slab_t) &cache->partial) (&cache->partial)->prev = (temp); else nxt->list.prev = (kmem_slab_t)(temp); };
  }
 }
 slab = (struct kmem_slab *)cache->partial.next;
 objp = slab->objaddr + (slab->free * cache->object);
 slab->free = ((unsigned short *)(((struct kmem_slab *)(slab))+1))[slab->free];
 slab->nentries += 1;
 { do{}while(0); };
 return objp;
}

variable_types:
flags
unsigned int

variable_types:
objp
void *

return_type: void *


original_code:
int kmem_cache_free(kmem_cache_t cache, void *obj)
{
 kmem_slab_t slab;
 bufctl_t nobj;
 kmem_slab_t new;
 { do{}while(0); };
 slab = (kmem_slab_t)cache->partial.next;
 if(!slab->nentries)
  goto free;
 nobj = (obj - slab->objaddr)/cache->object;
 ((bufctl_t *)(((struct kmem_slab *)(slab))+1))[nobj] = slab->free;
 slab->free = nobj;
 slab->nentries -= 1;
 if(slab->nentries <= 0)
 {
free:
  new = cache->partial.next;
  { kmem_slab_t nxt; (new) = (kmem_slab_t)(&cache->partial)->next; nxt = (kmem_slab_t)(new)->list.next; (&cache->partial)->next = nxt; if(nxt == (kmem_slab_t)&cache->partial) (&cache->partial)->prev = &cache->partial; else nxt->list.prev = &cache->partial; };
  { kmem_slab_t nxt = (kmem_slab_t)(&cache->full)->next; (&cache->full)->next = (new); (new)->list.prev = (kmem_slab_t)(&cache->full); (new)->list.next = (kmem_slab_t)nxt; if(nxt == (kmem_slab_t) &cache->full) (&cache->full)->prev = (new); else nxt->list.prev = (kmem_slab_t)(new); };
 }
 { do{}while(0); };
 return 0;
}

canonical_original_code:
int kmem_cache_free(struct kmem_cache *cache, void *obj)
{
 struct kmem_slab *slab;
 unsigned short nobj;
 struct kmem_slab *new;
 { do{}while(0); };
 slab = (struct kmem_slab *)cache->partial.next;
 if(!slab->nentries)
  goto free;
 nobj = (obj - slab->objaddr)/cache->object;
 ((unsigned short *)(((struct kmem_slab *)(slab))+1))[nobj] = slab->free;
 slab->free = nobj;
 slab->nentries -= 1;
 if(slab->nentries <= 0)
 {
free:
  new = cache->partial.next;
  { struct kmem_slab *nxt; (new) = (kmem_slab_t)(&cache->partial)->next; nxt = (kmem_slab_t)(new)->list.next; (&cache->partial)->next = nxt; if(nxt == (kmem_slab_t)&cache->partial) (&cache->partial)->prev = &cache->partial; else nxt->list.prev = &cache->partial; };
  { struct kmem_slab *nxt = (kmem_slab_t)(&cache->full)->next; (&cache->full)->next = (new); (new)->list.prev = (kmem_slab_t)(&cache->full); (new)->list.next = (struct kmem_slab *)nxt; if(nxt == (kmem_slab_t) &cache->full) (&cache->full)->prev = (new); else nxt->list.prev = (kmem_slab_t)(new); };
 }
 { do{}while(0); };
 return 0;
}

variable_types:
obj
void *

variable_types:
nobj
unsigned short


decompiled_code:
__int64 __fastcall kmem_cache_create(char *a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v7; // rax
__int64 v8; // rbx

if ( !a1 || !a2 )
return 0LL;
v7 = kmem_cache_alloc((__int64)cache_cache);
v8 = v7;
if ( v7 )
{
*(_QWORD *)(v7 + 64) = a4;
*(_QWORD *)(v7 + 72) = a5;
*(_DWORD *)(v7 + 48) = a2;
list_init((_QWORD *)(v7 + 16));
list_init((_QWORD *)v8);
list_init((_QWORD *)(v8 + 32));
*(_DWORD *)(v8 + 104) = 1;
strcpy((_BYTE *)(v8 + 80), a1);
cache_calculate(v8, (_DWORD *)(v8 + 56), (_DWORD *)(v8 + 52));
if ( *(_DWORD *)(v8 + 56) )
{
(*cachep)[12] = v8;
cachep = (__int64 (*)[2])v8;
*(_QWORD *)(v8 + 96) = 0LL;
}
else
{
kprintf("Cannot create cache\n", v8 + 56);
kmem_cache_free((__int64 ***)cache_cache, v8);
v8 = 0LL;
}
}
else
{
kprintf("Cannot create cachedd\n", 0LL);
}
return v8;
}

original_code:
kmem_cache_t kmem_cache_create(const char *name, size_t size, u8 align, void (*ctor)(void *, kmem_cache_t), void (*dtor)(void *, kmem_cache_t))
{
 kmem_cache_t cache;
 if((!name) || (!size))
  return ((void *)0);
 cache = kmem_cache_alloc(&cache_cache, 0);
 if(!cache)
 {
  kprintf("Cannot create cachedd\n");
  return ((void *)0);
 }
 cache->ctor = ctor;
 cache->dtor = dtor;
 cache->object = size;
 list_init(&cache->full);
 list_init(&cache->partial);
 list_init(&cache->free);
 ((&cache->lock)->lock = 1);
 strcpy(cache->name, name);
 cache_calculate(cache, &cache->nobjects, &cache->waste);
 if(!cache->nobjects)
 {
  kprintf("Cannot create cache\n");
  kmem_cache_free(&cache_cache, cache);
  return ((void *)0);
 }
 cachep->next_cache = cache;
 cachep = cache;
 cache->next_cache = ((void *)0);
 return cache;
}

canonical_original_code:
struct kmem_cache *kmem_cache_create(char *name, unsigned int size, unsigned char align, void (*ctor)(void *, struct kmem_cache *), void (*dtor)(void *, struct kmem_cache *))
{
 struct kmem_cache *cache;
 if((!name) || (!size))
  return ((void *)0);
 cache = kmem_cache_alloc(&cache_cache, 0);
 if(!cache)
 {
  kprintf("Cannot create cachedd\n");
  return ((void *)0);
 }
 cache->ctor = ctor;
 cache->dtor = dtor;
 cache->object = size;
 list_init(&cache->full);
 list_init(&cache->partial);
 list_init(&cache->free);
 ((&cache->lock)->lock = 1);
 strcpy(cache->name, name);
 cache_calculate(cache, &cache->nobjects, &cache->waste);
 if(!cache->nobjects)
 {
  kprintf("Cannot create cache\n");
  kmem_cache_free(&cache_cache, cache);
  return ((void *)0);
 }
 cachep->next_cache = cache;
 cachep = cache;
 cache->next_cache = ((void *)0);
 return cache;
}

variable_types:
name
char *

variable_types:
size
unsigned int

variable_types:
align
unsigned char

variable_types:
ctor
void (*)(void *, struct kmem_cache *)

variable_types:
dtor
void (*)(void *, struct kmem_cache *)

return_type: struct kmem_cache { struct linked_list { void *next; } partial; struct linked_list full; struct linked_list free; unsigned int object; unsigned int waste; unsigned int nobjects; unsigned char align; void (*ctor)(void *, struct kmem_cache *); void (*dtor)(void *, struct kmem_cache *); char name[11]; struct kmem_cache *next_cache; struct spinlock { int lock; } lock; } *


decompiled_code:
void kmem_cache_reap()
{
_QWORD *v0; // rbx

if ( qword_4C0 )
{
v0 = cache_cache;
do
{
free_all((__int64)v0);
v0 = (_QWORD *)v0[12];
}
while ( v0[12] );
}
}

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

if ( qword_4C0 )
{
v0 = cache_cache;
do
{
func5((__int64)v0);
v0 = (_QWORD *)v0[12];
}
while ( v0[12] );
}
}

original_code:
void kmem_cache_reap()
{
 kmem_cache_t next = &cache_cache;
 { do{}while(0); };
 while(next->next_cache != ((void *)0))
 {
  free_all(next);
  next = next->next_cache;
 }
 { do{}while(0); };
}

canonical_original_code:
void kmem_cache_reap()
{
 struct kmem_cache *next = &cache_cache;
 { do{}while(0); };
 while(next->next_cache != ((void *)0))
 {
  free_all(next);
  next = next->next_cache;
 }
 { do{}while(0); };
}


dm

decompiled_code:
__int64 dm()
{
_QWORD *v0; // rbx
__int64 result; // rax

if ( qword_4C0 )
{
v0 = cache_cache;
do
{
result = kprintf("- %s %x -", v0 + 10);
v0 = (_QWORD *)v0[12];
}
while ( v0[12] );
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
_QWORD *v0; // rbx
__int64 result; // rax

if ( qword_4C0 )
{
v0 = cache_cache;
do
{
result = kprintf("- %s %x -", v0 + 10);
v0 = (_QWORD *)v0[12];
}
while ( v0[12] );
}
return result;
}

original_code:
void dm()
{
 kmem_cache_t ch = &cache_cache;
 while(ch->next_cache)
 {
  kprintf("- %s %x -", ch->name, ch->partial.next);
  ch = ch->next_cache;
 }
}

canonical_original_code:
void dm()
{
 struct kmem_cache *ch = &cache_cache;
 while(ch->next_cache)
 {
  kprintf("- %s %x -", ch->name, ch->partial.next);
  ch = ch->next_cache;
 }
}


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

result = 13LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

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

result = 13LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

original_code:
static inline int syscall_get_tid()
{
 register int tid;
 asm volatile (
  "int $0x30\n\t"
  :"=a"(tid)
  :"0"(13)
  );
 return tid;
}


decompiled_code:
__int64 get_pinternal()
{
return syscall_get_ustack();
}

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

original_code:
static inline struct pthread_internal *get_pinternal()
{
 struct pthread_internal *internal;
 internal = (struct pthread_internal *)syscall_get_ustack();
 return internal;
}

variable_types: struct pthread_internal { struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } attr; struct fork_handler { void (*prepare)(); void (*parent)(); void (*child)(); } pt_fork; void *(*entry)(void *); void *arg; int tid; } *

user_defined_types: struct pthread_internal { struct pthread_attr attr; struct fork_handler pt_fork; void *(*entry)(void *); void *arg; int tid; }

user_defined_types: struct pthread_attr { int flags; struct sched_param prio; void *stackaddr; unsigned int stack_size; int policy; }


original_code:
static inline void check_attr(pthread_attr_t *nattr, const pthread_attr_t *attr)
{
 struct pthread_internal *inter;
 if(attr == ((void *) 0))
 {
  pthread_attr_init(nattr);
  return;
 }
 if(attr->flags & 0x0001)
 {
  *nattr = *attr;
 }
 else
 {
  inter = get_pinternal();
  *nattr = inter->attr;
  nattr->stackaddr = ((void *) 0);
  nattr->stack_size = 0;
 }
}

canonical_original_code:
static inline void check_attr(struct pthread_attr *nattr, struct pthread_attr *attr)
{
 struct pthread_internal *inter;
 if(attr == ((void *) 0))
 {
  pthread_attr_init(nattr);
  return;
 }
 if(attr->flags & 0x0001)
 {
  *nattr = *attr;
 }
 else
 {
  inter = get_pinternal();
  *nattr = inter->attr;
  nattr->stackaddr = ((void *) 0);
  nattr->stack_size = 0;
 }
}

variable_types: struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } *

variable_types:
attr
struct pthread_attr *

user_defined_types: struct fork_handler { void (*prepare)(); void (*parent)(); void (*child)(); }


original_code:
static inline pthread_t pthread_internal_create(pthread_attr_t *attr,
         void *(* start_routine)(void *), void *arg)
{
 struct pthread_internal *pint;
 if(attr->stackaddr == ((void *) 0))
 {
  attr->stackaddr = malloc(0x2000);
  if(!attr->stackaddr)
   return -0x31;
  attr->stack_size = 0x2000;
 }
 pint = (struct pthread_internal *)attr->stackaddr;
 pint->attr = *attr;
 pint->pt_fork.prepare = ((void *) 0);
 pint->pt_fork.parent = ((void *) 0);
 pint->pt_fork.child = ((void *) 0);
 pint->entry = start_routine;
 pint->arg = arg;
 pint->tid = syscall_create_thread(attr, common_entry);
 return pint->tid;
}

canonical_original_code:
static inline int pthread_internal_create(struct pthread_attr *attr, void *(*start_routine)(void *), void *arg)
{
 struct pthread_internal *pint;
 if(attr->stackaddr == ((void *) 0))
 {
  attr->stackaddr = malloc(0x2000);
  if(!attr->stackaddr)
   return -0x31;
  attr->stack_size = 0x2000;
 }
 pint = (struct pthread_internal *)attr->stackaddr;
 pint->attr = *attr;
 pint->pt_fork.prepare = ((void *) 0);
 pint->pt_fork.parent = ((void *) 0);
 pint->pt_fork.child = ((void *) 0);
 pint->entry = start_routine;
 pint->arg = arg;
 pint->tid = syscall_create_thread(attr, common_entry);
 return pint->tid;
}

variable_types:
arg
void *

user_defined_types: struct sched_param { int sched_priority; }


decompiled_code:
__int64 pthread_self()
{
return syscall_get_tid();
}

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

original_code:
pthread_t pthread_self(void)
{
 return syscall_get_tid();
}

canonical_original_code:
int pthread_self()
{
 return syscall_get_tid();
}


decompiled_code:
void __fastcall __noreturn pthread_exit(unsigned int *a1)
{
syscall_destroy_thread(*a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(unsigned int *a1)
{
func2(*a1);
}

original_code:
void pthread_exit(void *value_ptr)
{
 int *val = (int *)value_ptr;
 syscall_destroy_thread(*val);
}

variable_types:
val
int *


decompiled_code:
void __noreturn common_entry()
{
__int64 v0; // rax
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = get_pinternal();
(*(void (__fastcall **)(_QWORD))(v0 + 48))(*(_QWORD *)(v0 + 56));
pthread_exit(v1);
}

canonical_decompiled_code:
void __noreturn func10()
{
__int64 v0; // rax
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = func5();
(*(void (__fastcall **)(_QWORD))(v0 + 48))(*(_QWORD *)(v0 + 56));
func9(v1);
}

original_code:
void common_entry()
{
 struct pthread_internal *inter;
 int value;
 inter = get_pinternal();
 inter->entry(inter->arg);
 pthread_exit(&value);
}

variable_types: value int


decompiled_code:
__int64 __fastcall pthread_create(int *a1, const __m128i *a2, __int64 a3, __int64 a4)
{
int v6; // ebx
__int64 result; // rax
__m128i v8[4]; // [rsp+0h] [rbp-48h] BYREF

check_attr((__int64)v8, a2);
v6 = pthread_internal_create(v8, a3, a4);
if ( v6 < 0 )
{
if ( !a2->m128i_i64[1] )
free((void *)v8[0].m128i_i64[1]);
result = (unsigned int)-v6;
}
else
{
result = 0LL;
if ( a1 )
*a1 = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, const __m128i *a2, __int64 a3, __int64 a4)
{
int v6; // ebx
__int64 result; // rax
__m128i v8[4]; // [rsp+0h] [rbp-48h] BYREF

func6((__int64)v8, a2);
v6 = func7(v8, a3, a4);
if ( v6 < 0 )
{
if ( !a2->m128i_i64[1] )
free((void *)v8[0].m128i_i64[1]);
result = (unsigned int)-v6;
}
else
{
result = 0LL;
if ( a1 )
*a1 = v6;
}
return result;
}

original_code:
int pthread_create(pthread_t *__restrict thread,
       const pthread_attr_t *__restrict attr,
       void *(* start_routine)(void *), void *__restrict arg)
{
 pthread_attr_t nattr;
 pthread_t tid;
 check_attr(&nattr, attr);
 tid = pthread_internal_create(&nattr, start_routine, arg);
 if(tid < 0)
 {
  if(!attr->stackaddr)
   free(nattr.stackaddr);
  return -tid;
 }
 if(thread)
  *thread = tid;
 return 0;
}

canonical_original_code:
int pthread_create(int *thread, struct pthread_attr *attr, void *(*start_routine)(void *), void *arg)
{
 struct pthread_attr nattr;
 int tid;
 check_attr(&nattr, attr);
 tid = pthread_internal_create(&nattr, start_routine, arg);
 if(tid < 0)
 {
  if(!attr->stackaddr)
   free(nattr.stackaddr);
  return -tid;
 }
 if(thread)
  *thread = tid;
 return 0;
}

variable_types:
thread
int *

variable_types: struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; }

variable_types: tid int


decompiled_code:
__int64 __fastcall pthread_join(__int64 a1, _DWORD **a2)
{
int v2; // eax
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
v2 = syscall_thread_join(a1, v4);
if ( v2 < 0 )
return (unsigned int)-v2;
result = 0LL;
if ( a2 )
{
**a2 = v4[0];
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, _DWORD **a2)
{
int v2; // eax
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
v2 = func4(a1, v4);
if ( v2 < 0 )
return (unsigned int)-v2;
result = 0LL;
if ( a2 )
{
**a2 = v4[0];
result = 0LL;
}
return result;
}

original_code:
int pthread_join(pthread_t thread, void **value_ptr)
{
 int ret, value = 0;
 int **val;
 val = (int **)value_ptr;
 ret = syscall_thread_join(thread, &value);
 if(ret < 0)
 {
  return -ret;
 }
 if(value_ptr)
  **val = value;
 return 0;
}

canonical_original_code:
int pthread_join(int thread, void **value_ptr)
{
 int ret; int value = 0;
 int **val;
 val = (int **)value_ptr;
 ret = syscall_thread_join(thread, &value);
 if(ret < 0)
 {
  return -ret;
 }
 if(value_ptr)
  **val = value;
 return 0;
}

variable_types: thread int

variable_types: ret int

variable_types:
val
int **