original_code:
int ext2_readdir(struct vnode *parent, char *path, struct nameidata *nm)
{
 uint32_t block_no, blkindex = 0, blksz;
 struct ext2inode *eino = &parent->v_ino.ext2inode;
 struct bcache *entry;
 struct ext2dirent *dir;
 struct vnode *vnode = parent;
 uint32_t last_sym= 0, entrysz;
 char name[255];
 char *pth = path;
 int ret= -0x1d , comp = 0, index = 0;
again:
 do{
  while(*pth == '/')
   pth++;
  while (*pth != '/')
  {
   if(*pth == '\0')
    break;
   name[index] = *pth++;
   index++;
  }
  name[index] = 0;
  if((*pth == '\0') || (*(pth + 1) == '\0'))
   comp = 1;
  pthread_mutex_lock(&vnode->smlock);
  do{
   if(!(vnode->v_type & 0x4))
   {
    ret = -0x1d;
    goto err;
   }
   if(vnode->v_fsmounted)
   {
    nm->vfs = vnode->v_fsmounted;
    return 1;
   }
   can_execute(&nm->id, eino);
   block_no = ext2_bmap(vnode, blkindex);
   entry = (struct bcache *)bread(vnode->v_rdev, block_no, vnode->vfsp->blk_size);
   if(!entry)
    return -0x1c;
   dir = (struct ext2dirent *)entry->b_data;
   entrysz = ((uint32_t)entry->b_data + entry->b_datasz);
   while((dir->rec_len != 0))
   {
    if(dir->namelen > 255)
     return (-0x26);
    ret = check_name(dir->name, dir->namelen, name);
    if(ret == 0)
     goto fileok;
    dir = (struct ext2dirent *)(((uint32_t)dir)+dir->rec_len);
    if((uint32_t)dir >= entrysz)
     break;
   }
   brelse(entry);
   blksz = get_file_blk(vnode);
   blkindex++;
   if((blkindex * vnode->vfsp->blk_size) >= blksz)
    break;
  }while(1);
  if(comp == 1)
   nm->vn = vnode;
  pthread_mutex_unlock(&vnode->smlock);
  return -1;
 fileok:
  pthread_mutex_unlock(&vnode->smlock);
  vnode = vget(vnode, dir->inum, vnode->v_rdev);
  if(vnode == ((void *) 0))
   return -1;
  eino = &vnode->v_ino.ext2inode;
  can_execute(&nm->id, eino);
  blkindex = 0;
  index = 0;
 }while(comp == 0);
 nm->vn = vnode;
 pthread_mutex_lock(&vnode->smlock);
 return 0;
err:
 pthread_mutex_unlock(&vnode->smlock);
 return ret;
}

canonical_original_code:
int ext2_readdir(struct vnode *parent, char *path, struct nameidata *nm)
{
 unsigned long block_no; unsigned long blkindex = 0; unsigned long blksz;
 struct ext2inode *eino = &parent->v_ino.ext2inode;
 struct bcache *entry;
 struct ext2dirent *dir;
 struct vnode *vnode = parent;
 unsigned long last_sym = 0; unsigned long entrysz;
 char name[255];
 char *pth = path;
 int ret = -0x1d; int comp = 0; int index = 0;
again:
 do{
  while(*pth == '/')
   pth++;
  while (*pth != '/')
  {
   if(*pth == '\0')
    break;
   name[index] = *pth++;
   index++;
  }
  name[index] = 0;
  if((*pth == '\0') || (*(pth + 1) == '\0'))
   comp = 1;
  pthread_mutex_lock(&vnode->smlock);
  do{
   if(!(vnode->v_type & 0x4))
   {
    ret = -0x1d;
    goto err;
   }
   if(vnode->v_fsmounted)
   {
    nm->vfs = vnode->v_fsmounted;
    return 1;
   }
   can_execute(&nm->id, eino);
   block_no = ext2_bmap(vnode, blkindex);
   entry = (struct bcache *)bread(vnode->v_rdev, block_no, vnode->vfsp->blk_size);
   if(!entry)
    return -0x1c;
   dir = (struct ext2dirent *)entry->b_data;
   entrysz = ((unsigned long)entry->b_data + entry->b_datasz);
   while((dir->rec_len != 0))
   {
    if(dir->namelen > 255)
     return (-0x26);
    ret = check_name(dir->name, dir->namelen, name);
    if(ret == 0)
     goto fileok;
    dir = (struct ext2dirent *)(((unsigned long)dir)+dir->rec_len);
    if((unsigned long)dir >= entrysz)
     break;
   }
   brelse(entry);
   blksz = get_file_blk(vnode);
   blkindex++;
   if((blkindex * vnode->vfsp->blk_size) >= blksz)
    break;
  }while(1);
  if(comp == 1)
   nm->vn = vnode;
  pthread_mutex_unlock(&vnode->smlock);
  return -1;
 fileok:
  pthread_mutex_unlock(&vnode->smlock);
  vnode = vget(vnode, dir->inum, vnode->v_rdev);
  if(vnode == ((void *) 0))
   return -1;
  eino = &vnode->v_ino.ext2inode;
  can_execute(&nm->id, eino);
  blkindex = 0;
  index = 0;
 }while(comp == 0);
 nm->vn = vnode;
 pthread_mutex_lock(&vnode->smlock);
 return 0;
err:
 pthread_mutex_unlock(&vnode->smlock);
 return ret;
}

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:
path
char *

variable_types:
nm
struct nameidata *

variable_types:
blkindex
unsigned long

variable_types:
blksz
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; } *

variable_types: struct ext2dirent { unsigned long inum; unsigned short rec_len; unsigned char namelen; unsigned char file_type; char name[255]; } *

variable_types:
entrysz
unsigned long

variable_types:
name
char [255]

variable_types:
pth
char *

variable_types: ret int

variable_types: comp int

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 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; }


strlen

repo: mregmi/manrix

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
__int64 v1; // rcx
bool v2; // zf

v1 = 0xFFFFFFFFLL;
do
{
if ( !v1 )
break;
v2 = *a1++ == 0;
--v1;
}
while ( !v2 );
return (unsigned int)(-(int)v1 - 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rcx
bool v2; // zf

v1 = 0xFFFFFFFFLL;
do
{
if ( !v1 )
break;
v2 = *a1++ == 0;
--v1;
}
while ( !v2 );
return (unsigned int)(-(int)v1 - 2);
}

original_code:
static inline size_t strlen(const char * s)
{
int d0;
register int __res;
__asm__ __volatile__(
 "repne\n\t"
 "scasb\n\t"
 "notl %0\n\t"
 "decl %0"
 :"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffffu));
return __res;
}

canonical_original_code:
static inline unsigned int strlen(char *s)
{
int d0;
register int __res;
__asm__ __volatile__(
 "repne\n\t"
 "scasb\n\t"
 "notl %0\n\t"
 "decl %0"
 :"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffffu));
return __res;
}

variable_types:
s
char *

return_type: unsigned int


original_code:
static inline int read_primary(MBR *mbr, struct partition_info *pinfo)
{
 PARTITION *part;
 int index, ebr = -1;
 for(index = 1; index <= 4; index++)
 {
  part = &mbr->part[index];
  pinfo->start = part->relativeSectors;
  pinfo->size = part->totalSectors;
  pinfo->ptype = part->systemId;
  pinfo->flag = part->bootIndicator;
 printf(" Part %x,  size %d MB lba %d\n", part->systemId, part->totalSectors/(2 * 1024), part->relativeSectors);
  if((pinfo->ptype == 0x05) ||
   (pinfo->ptype == 0x0F))
   ebr = index;
 }
 return ebr;
}

canonical_original_code:
static inline int read_primary(struct tagMBR *mbr, struct partition_info *pinfo)
{
 struct tagPARTITION *part;
 int index; int ebr = -1;
 for(index = 1; index <= 4; index++)
 {
  part = &mbr->part[index];
  pinfo->start = part->relativeSectors;
  pinfo->size = part->totalSectors;
  pinfo->ptype = part->systemId;
  pinfo->flag = part->bootIndicator;
 printf(" Part %x,  size %d MB lba %d\n", part->systemId, part->totalSectors/(2 * 1024), part->relativeSectors);
  if((pinfo->ptype == 0x05) ||
   (pinfo->ptype == 0x0F))
   ebr = index;
 }
 return ebr;
}

variable_types: struct tagMBR { char res[446]; struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; } part[4]; unsigned short signature; } *

variable_types: struct partition_info { unsigned long start; unsigned long size; unsigned short ptype; unsigned short flag; } *

variable_types: struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; } *

variable_types: index int

variable_types: ebr int

return_type: int

user_defined_types: struct tagMBR { char res[446]; struct tagPARTITION part[4]; unsigned short signature; }


readsect

original_code:
int readsect(dev_t dev, unsigned long lba, void *data, int sectsize)
{
 struct operation op;
 int ret;
 op.device = dev;
 op.type = 1;
 op.block = lba;
 op.blksize = sectsize;
 op.buffer = data;
 ret = devstrat(&op);
 return ret;
}

canonical_original_code:
int readsect(unsigned long dev, unsigned long lba, void *data, int sectsize)
{
 struct operation op;
 int ret;
 op.device = dev;
 op.type = 1;
 op.block = lba;
 op.blksize = sectsize;
 op.buffer = data;
 ret = devstrat(&op);
 return ret;
}

variable_types:
dev
unsigned long

variable_types:
lba
unsigned long

variable_types:
data
void *

variable_types: sectsize int

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


decompiled_code:
__int64 __fastcall read_mbr(__int64 a1, int a2, __int64 a3)
{
unsigned __int16 v4; // ax

if ( (int)readsect(a1, 0LL, a3, a2) < 0 )
return 0xFFFFFFFFLL;
v4 = *(_WORD *)(a3 + 542);
if ( v4 == 0xAA55 )
return 0LL;
printf(" Invalid Signature in MBR on disk %d %X \n", BYTE1(a1), v4);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
unsigned __int16 v4; // ax

if ( (int)func2(a1, 0LL, a3, a2) < 0 )
return 0xFFFFFFFFLL;
v4 = *(_WORD *)(a3 + 542);
if ( v4 == 0xAA55 )
return 0LL;
printf(" Invalid Signature in MBR on disk %d %X \n", BYTE1(a1), v4);
return 0xFFFFFFFFLL;
}

original_code:
int read_mbr(dev_t dev, int sectsize, MBR *mbr)
{
 int ret;
 ret = readsect(dev, 0, (void *)mbr, sectsize);
 if(ret < 0)
  return -1;
 if(mbr->signature != 0xAA55)
 {
  printf(" Invalid Signature in MBR on disk %d %X \n", (((dev & 0xFFFF) >> 8) & 0xff), mbr->signature);
  return -1;
 }
 return 0;
}

canonical_original_code:
int read_mbr(unsigned long dev, int sectsize, struct tagMBR *mbr)
{
 int ret;
 ret = readsect(dev, 0, (void *)mbr, sectsize);
 if(ret < 0)
  return -1;
 if(mbr->signature != 0xAA55)
 {
  printf(" Invalid Signature in MBR on disk %d %X \n", (((dev & 0xFFFF) >> 8) & 0xff), mbr->signature);
  return -1;
 }
 return 0;
}

user_defined_types: struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; }


original_code:
static inline int read_extended(dev_t dev, int sectsize, PARTITION *p, struct partition_info *pinfo)
{
 MBR ebr;
 PARTITION *p1, *p0;
 int ret, index = 5;
 uint32_t ebrBase, nextPart, ebr2 = 0;
 ebrBase = p->relativeSectors;
 ret = readsect(dev, ebrBase, &ebr, sectsize);
 if(ret < 0)
  return ret;
 do{
  p0 = &ebr.part[0];
  p1 = &ebr.part[1];
  pinfo[index].ptype = p0->systemId;
  pinfo[index].size = p0->totalSectors;
  pinfo[index].flag = p0->bootIndicator;
  pinfo[index].start = p0->relativeSectors + ebrBase + ebr2;
printf("Part %x,  size %d MB lba %d\n", p0->systemId, p0->totalSectors/(2 * 1024),p0->relativeSectors);
  ebr2 = p1->relativeSectors;
  nextPart = p1->relativeSectors + ebrBase;
  readsect(dev, nextPart, &ebr, sectsize);
  index++;
  if(index >= 255)
  {
   printf("Too many partitions. Cannot handle more than 256.\n");
   break;
  }
 }while (ebr.part[1].systemId != 0x00);
 pinfo[index].ptype = ebr.part[0].systemId;
 pinfo[index].size = ebr.part[0].totalSectors;
 pinfo[index].flag = p0->bootIndicator;
 pinfo[index].start = ebr.part[0].relativeSectors + ebrBase +ebr2;
 return (index + 1);
}

canonical_original_code:
static inline int read_extended(unsigned long dev, int sectsize, struct tagPARTITION *p, struct partition_info *pinfo)
{
 struct tagMBR ebr;
 struct tagPARTITION *p1; struct tagPARTITION *p0;
 int ret; int index = 5;
 unsigned long ebrBase; unsigned long nextPart; unsigned long ebr2 = 0;
 ebrBase = p->relativeSectors;
 ret = readsect(dev, ebrBase, &ebr, sectsize);
 if(ret < 0)
  return ret;
 do{
  p0 = &ebr.part[0];
  p1 = &ebr.part[1];
  pinfo[index].ptype = p0->systemId;
  pinfo[index].size = p0->totalSectors;
  pinfo[index].flag = p0->bootIndicator;
  pinfo[index].start = p0->relativeSectors + ebrBase + ebr2;
printf("Part %x,  size %d MB lba %d\n", p0->systemId, p0->totalSectors/(2 * 1024),p0->relativeSectors);
  ebr2 = p1->relativeSectors;
  nextPart = p1->relativeSectors + ebrBase;
  readsect(dev, nextPart, &ebr, sectsize);
  index++;
  if(index >= 255)
  {
   printf("Too many partitions. Cannot handle more than 256.\n");
   break;
  }
 }while (ebr.part[1].systemId != 0x00);
 pinfo[index].ptype = ebr.part[0].systemId;
 pinfo[index].size = ebr.part[0].totalSectors;
 pinfo[index].flag = p0->bootIndicator;
 pinfo[index].start = ebr.part[0].relativeSectors + ebrBase +ebr2;
 return (index + 1);
}

variable_types: struct tagMBR { char res[446]; struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; } part[4]; unsigned short signature; }

variable_types:
ebrBase
unsigned long

variable_types:
nextPart
unsigned long

user_defined_types: struct partition_info { unsigned long start; unsigned long size; unsigned short ptype; unsigned short flag; }


decompiled_code:
__int64 __fastcall read_partitions(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int v6; // eax
__int64 result; // rax

v6 = read_primary(a3, a4);
if ( v6 == -1 )
result = 0LL;
else
result = read_extended(a1, a2, a3 + 24LL * v6 + 446, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int v6; // eax
__int64 result; // rax

v6 = func0(a3, a4);
if ( v6 == -1 )
result = 0LL;
else
result = func4(a1, a2, a3 + 24LL * v6 + 446, a4);
return result;
}

original_code:
int read_partitions(dev_t dev, int sectsize, MBR *mbr, struct partition_info *pinfo)
{
 PARTITION *ebr;
 int index, ret = 0;
 index = read_primary(mbr, pinfo);
 if(index == -1)
  return 0;
 ebr = &mbr->part[index];
 ret = read_extended(dev, sectsize, ebr, pinfo);
 return ret;
}

canonical_original_code:
int read_partitions(unsigned long dev, int sectsize, struct tagMBR *mbr, struct partition_info *pinfo)
{
 struct tagPARTITION *ebr;
 int index; int ret = 0;
 index = read_primary(mbr, pinfo);
 if(index == -1)
  return 0;
 ebr = &mbr->part[index];
 ret = read_extended(dev, sectsize, ebr, pinfo);
 return ret;
}


decompiled_code:
void *__fastcall initialize_partitions(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
void *v3; // r13
int v4; // eax
void *result; // rax
_BYTE v6[568]; // [rsp+0h] [rbp-238h] BYREF

devstrat = a3;
if ( (int)read_mbr(a1, a2, (__int64)v6) < 0
|| (v3 = malloc(0x1800uLL),
memset_constprop_0_isra_0((char *)v3),
v4 = read_partitions(a1, a2, (__int64)v6, (__int64)v3),
v4 < 0) )
{
result = 0LL;
}
else
{
result = realloc(v3, (unsigned int)(24 * v4));
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
void *v3; // r13
int v4; // eax
void *result; // rax
_BYTE v6[568]; // [rsp+0h] [rbp-238h] BYREF

devstrat = a3;
if ( (int)func3(a1, a2, (__int64)v6) < 0
|| (v3 = malloc(0x1800uLL),
func1((char *)v3),
v4 = func5(a1, a2, (__int64)v6, (__int64)v3),
v4 < 0) )
{
result = 0LL;
}
else
{
result = realloc(v3, (unsigned int)(24 * v4));
}
return result;
}

original_code:
struct partition_info *initialize_partitions(dev_t device, int sectorsize, int (* strategy)(struct operation *))
{
 MBR mbr;
 struct partition_info *pinfo;
 int ret;
 devstrat = strategy;
 ret = read_mbr(device, sectorsize, &mbr);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *) malloc(sizeof(struct partition_info) * 256);
 memset(pinfo, 0, sizeof(struct partition_info) * 256);
 ret = read_partitions(device, sectorsize, &mbr, pinfo);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *)realloc(pinfo, sizeof(struct partition_info) * ret);
 return pinfo;
}

canonical_original_code:
struct partition_info *initialize_partitions(unsigned long device, int sectorsize, int (*strategy)(struct operation *))
{
 struct tagMBR mbr;
 struct partition_info *pinfo;
 int ret;
 devstrat = strategy;
 ret = read_mbr(device, sectorsize, &mbr);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *) malloc(sizeof(struct partition_info) * 256);
 memset(pinfo, 0, sizeof(struct partition_info) * 256);
 ret = read_partitions(device, sectorsize, &mbr, pinfo);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *)realloc(pinfo, sizeof(struct partition_info) * ret);
 return pinfo;
}

variable_types:
device
unsigned long

variable_types: sectorsize int

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

return_type: struct partition_info { unsigned long start; unsigned long size; unsigned short ptype; unsigned short flag; } *


original_code:
int console_init()
{
 struct winattr *wattr = &(ttys[termindex]).t_win;
 wattr->current_x = wattr->current_y = 8;
 vga = vga_init(vga, &wattr->max_x, &wattr->max_y, &wattr->attr);
 if(!vga)
  return -1;
 return 0;
}

variable_types: struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; } *


decompiled_code:
__int64 __fastcall scr_write(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // di
__int64 v3; // r12

v1 = a1;
v2 = *a1;
v3 = ttys + 3168LL * termindex;
if ( v2 )
{
do
{
++v1;
put_char(v2, (int *)(v3 + 1144), 0);
v2 = *v1;
}
while ( *v1 );
}
return update_cursor((unsigned int)(*(_DWORD *)(v3 + 1144) + 1), *(unsigned int *)(v3 + 1148));
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // di
__int64 v3; // r12

v1 = a1;
v2 = *a1;
v3 = ttys + 3168LL * termindex;
if ( v2 )
{
do
{
++v1;
func9(v2, (int *)(v3 + 1144), 0);
v2 = *v1;
}
while ( *v1 );
}
return func1((unsigned int)(*(_DWORD *)(v3 + 1144) + 1), *(unsigned int *)(v3 + 1148));
}

original_code:
void scr_write(const char *string)
{
 struct terminal *term;
 struct winattr *wattr;
 term = &(ttys[termindex]);
 wattr = &term->t_win;
 while(*string != '\0')
 {
  put_char(*string, wattr, 0);
  string++;
 }
 update_cursor(wattr->current_x+1, wattr->current_y);
}

canonical_original_code:
void scr_write(char *string)
{
 struct terminal *term;
 struct winattr *wattr;
 term = &(ttys[termindex]);
 wattr = &term->t_win;
 while(*string != '\0')
 {
  put_char(*string, wattr, 0);
  string++;
 }
 update_cursor(wattr->current_x+1, wattr->current_y);
}

variable_types:
string
char *

variable_types: struct terminal { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; } t_termios; struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; } t_input; struct termqueue t_output; struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; } t_win; int pgid; } *

return_type: void

user_defined_types: struct terminal { struct termios t_termios; struct termqueue t_input; struct termqueue t_output; struct winattr t_win; int pgid; }


decompiled_code:
__int64 __fastcall con_printf(char *format)
{
unsigned int v1; // er12
char arg[8]; // [rsp+10h] [rbp-8h] BYREF

v1 = vsprintf(buf, format, arg);
scr_write((unsigned __int8 *)buf);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *format)
{
unsigned int v1; // er12
char arg[8]; // [rsp+10h] [rbp-8h] BYREF

v1 = vsprintf(buf, format, arg);
func10((unsigned __int8 *)buf);
return v1;
}

original_code:
int con_printf(const char *format, ...)
{
 va_list ap;
 int ret;
 ((ap = (va_list)(&format)+sizeof(format)));
 ret = vsprintf(buf, format, ap);
 ((void)0);
 scr_write(buf);
 return ret;
}

canonical_original_code:
int con_printf(char *format, ...)
{
 char *ap;
 int ret;
 ((ap = (va_list)(&format)+sizeof(format)));
 ret = vsprintf(buf, format, ap);
 ((void)0);
 scr_write(buf);
 return ret;
}

variable_types:
format
char *

variable_types:
ap
char *

variable_types: ret int


readline

decompiled_code:
__int64 __fastcall readline(_WORD *a1, char *a2)
{
char v3; // al
char v4; // bl
char v5; // r12
__int64 result; // rax
char *v7; // rbx
int v8; // ebx
__int16 v9; // ax
FILE *v10; // rdi
__int64 v11; // rdx
char v12; // al
__int64 v13; // rdx
int v14; // ebx
__int64 v15; // rdx
char nptr[4]; // [rsp+Bh] [rbp-2Dh] BYREF
char v17; // [rsp+Fh] [rbp-29h] BYREF

while ( 1 )
{
while ( 1 )
{
v3 = fgetc(in);
v4 = v3;
v5 = v3;
if ( v3 != 59 )
break;
fgets(a2, 80, in);
fgets(a2, 80, in);
}
if ( v3 == 86 || v3 == 68 )
break;
fgets(a2, 80, in);
if ( v4 == -1 )
return 0LL;
}
v7 = nptr;
fgetc(in);
do
*v7++ = fgetc(in);
while ( &v17 != v7 );
v8 = 0;
v17 = 0;
v9 = strtol(nptr, 0LL, 16);
v10 = in;
*a1 = v9;
fgetc(v10);
while ( 1 )
{
v12 = fgetc(in);
if ( v12 == 10 )
break;
if ( v12 == 34 || v12 == 63 )
{
v13 = v8;
v14 = v8 + 1;
a2[v13] = 92;
v15 = v14;
v8 = v14 + 1;
a2[v15] = v12;
if ( v8 > 79 )
break;
}
else
{
v11 = v8++;
a2[v11] = v12;
if ( v8 > 79 )
break;
}
}
result = (unsigned int)v5;
a2[v8] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_WORD *a1, char *a2)
{
char v3; // al
char v4; // bl
char v5; // r12
__int64 result; // rax
char *v7; // rbx
int v8; // ebx
__int16 v9; // ax
FILE *v10; // rdi
__int64 v11; // rdx
char v12; // al
__int64 v13; // rdx
int v14; // ebx
__int64 v15; // rdx
char nptr[4]; // [rsp+Bh] [rbp-2Dh] BYREF
char v17; // [rsp+Fh] [rbp-29h] BYREF

while ( 1 )
{
while ( 1 )
{
v3 = fgetc(in);
v4 = v3;
v5 = v3;
if ( v3 != 59 )
break;
fgets(a2, 80, in);
fgets(a2, 80, in);
}
if ( v3 == 86 || v3 == 68 )
break;
fgets(a2, 80, in);
if ( v4 == -1 )
return 0LL;
}
v7 = nptr;
fgetc(in);
do
*v7++ = fgetc(in);
while ( &v17 != v7 );
v8 = 0;
v17 = 0;
v9 = strtol(nptr, 0LL, 16);
v10 = in;
*a1 = v9;
fgetc(v10);
while ( 1 )
{
v12 = fgetc(in);
if ( v12 == 10 )
break;
if ( v12 == 34 || v12 == 63 )
{
v13 = v8;
v14 = v8 + 1;
a2[v13] = 92;
v15 = v14;
v8 = v14 + 1;
a2[v15] = v12;
if ( v8 > 79 )
break;
}
else
{
v11 = v8++;
a2[v11] = v12;
if ( v8 > 79 )
break;
}
}
result = (unsigned int)v5;
a2[v8] = 0;
return result;
}

original_code:
static inline int readline(unsigned short *id, char *str)
{
 char etype, ch;
 char eid[5];
 int index, ret = 0, len;
 do{
  etype = fgetc(in);
  if(etype == ';')
   fgets(str, 80, in);
  if((etype == 'V') || (etype == 'D'))
  {
   fgetc(in);
   for(index = 0; index < 4; index++)
   {
    eid[index] = fgetc(in);
   }
   eid[4] = '\0';
   *id = (unsigned short)strtol(eid, (char **)((void *)0), 16);
   fgetc(in);
   for(index = 0; index < 80; index++)
   {
    ch = fgetc(in);
    if(ch == '\n')
     break;
    if((ch == '"')||(ch == '?'))
    {
     str[index++] = '\\';
    }
    str[index] = ch;
   }
   str[index] = '\0';
   ret = (int)etype;
   break;
  }
  else
  {
   fgets(str, 80, in);
  }
 }while(etype != (-1));
 return ret;
}

canonical_original_code:
static inline int readline(unsigned short *id, char *str)
{
 char etype; char ch;
 char eid[5];
 int index; int ret = 0; int len;
 do{
  etype = fgetc(in);
  if(etype == ';')
   fgets(str, 80, in);
  if((etype == 'V') || (etype == 'D'))
  {
   fgetc(in);
   for(index = 0; index < 4; index++)
   {
    eid[index] = fgetc(in);
   }
   eid[4] = '\0';
   *id = (unsigned short)strtol(eid, (char **)((void *)0), 16);
   fgetc(in);
   for(index = 0; index < 80; index++)
   {
    ch = fgetc(in);
    if(ch == '\n')
     break;
    if((ch == '"')||(ch == '?'))
    {
     str[index++] = '\\';
    }
    str[index] = ch;
   }
   str[index] = '\0';
   ret = (int)etype;
   break;
  }
  else
  {
   fgets(str, 80, in);
  }
 }while(etype != (-1));
 return ret;
}

variable_types:
id
unsigned short *

variable_types:
str
char *

variable_types: etype char

variable_types: ch char

variable_types:
eid
char [5]

variable_types: index int

variable_types: len int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned __int16 v5; // [rsp+Eh] [rbp-5Ah] BYREF
char v6[88]; // [rsp+10h] [rbp-58h] BYREF

in = fopen("pcidevs.txt", "r");
if ( !in )
{
perror("Error opening pcidevs.txt: ");
exit(1);
}
out = fopen("pciid.c", "w");
if ( !out )
{
perror("Error opening/creating pciid.c: ");
exit(1);
}
fwrite(
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005\tManish Regmi (regmi dot manish at gmail dot com)\n"
" *\t\t\t\tRajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * \t\tPCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * \tAutomatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n"
"\n"
"struct pciid vendors[] = {\n",
1uLL,
0x431uLL,
out);
while ( 1 )
{
v3 = readline(&v5, v6);
if ( !v3 )
break;
fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (unsigned int)(char)v3, v5, v6);
}
fwrite("\t{ 'N', 0x0, NULL }\n};\n", 1uLL, 0x17uLL, out);
fclose(in);
fclose(out);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned __int16 v5; // [rsp+Eh] [rbp-5Ah] BYREF
char v6[88]; // [rsp+10h] [rbp-58h] BYREF

in = fopen("pcidevs.txt", "r");
if ( !in )
{
perror("Error opening pcidevs.txt: ");
exit(1);
}
out = fopen("pciid.c", "w");
if ( !out )
{
perror("Error opening/creating pciid.c: ");
exit(1);
}
fwrite(
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005\tManish Regmi (regmi dot manish at gmail dot com)\n"
" *\t\t\t\tRajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * \t\tPCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * \tAutomatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n"
"\n"
"struct pciid vendors[] = {\n",
1uLL,
0x431uLL,
out);
while ( 1 )
{
v3 = func7(&v5, v6);
if ( !v3 )
break;
fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (unsigned int)(char)v3, v5, v6);
}
fwrite("\t{ 'N', 0x0, NULL }\n};\n", 1uLL, 0x17uLL, out);
fclose(in);
fclose(out);
return 0;
}

original_code:
int main()
{
 int length, type;
 unsigned short id;
 char str[80], entry[80];
 char *vendors = {
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005	Manish Regmi (regmi dot manish at gmail dot com)\n"
" *				Rajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * 		PCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * 	Automatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n\n"
"struct pciid vendors[] = {\n"};
 in = fopen("pcidevs.txt", "r");
 if(!in)
 {
  perror("Error opening pcidevs.txt: ");
  exit(1);
 }
 out = fopen("pciid.c","w");
 if(!out)
 {
  perror("Error opening/creating pciid.c: ");
  exit(1);
 }
 length = strlen(vendors);
 fwrite(vendors, 1, length, out);
 while((type = readline(&id, str)) != 0)
  fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (char)type, id, str);
 fprintf(out, "\t{ 'N', 0x0, NULL }\n};\n");
 fclose(in);
 fclose(out);
 return 0;
}

canonical_original_code:
int main()
{
 int length; int type;
 unsigned short id;
 char str[80]; char entry[80];
 char *vendors = {
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005	Manish Regmi (regmi dot manish at gmail dot com)\n"
" *				Rajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * 		PCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * 	Automatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n\n"
"struct pciid vendors[] = {\n"};
 in = fopen("pcidevs.txt", "r");
 if(!in)
 {
  perror("Error opening pcidevs.txt: ");
  exit(1);
 }
 out = fopen("pciid.c","w");
 if(!out)
 {
  perror("Error opening/creating pciid.c: ");
  exit(1);
 }
 length = strlen(vendors);
 fwrite(vendors, 1, length, out);
 while((type = readline(&id, str)) != 0)
  fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (char)type, id, str);
 fprintf(out, "\t{ 'N', 0x0, NULL }\n};\n");
 fclose(in);
 fclose(out);
 return 0;
}

variable_types: length int

variable_types: type int

variable_types:
id
unsigned short

variable_types:
str
char [80]

variable_types:
entry
char [80]

variable_types:
vendors
char *


decompiled_code:
__int64 __fastcall console_write(char *a1)
{
char i; // di
__int64 v2; // r8

for ( i = *a1; i; i = *(_BYTE *)(v2 + 1) )
put_char(i);
return update_cursor(current_x, current_y);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char i; // di
__int64 v2; // r8

for ( i = *a1; i; i = *(_BYTE *)(v2 + 1) )
func4(i);
return func0(current_x, current_y);
}

original_code:
void console_write(char *string)
{
 while(*string != '\0')
 {
  put_char(*string);
  string++;
 }
 update_cursor(current_x, current_y);
}

variable_types:
string
char *


decompiled_code:
__int64 __fastcall update_cursor(int a1, int a2)
{
unsigned int v2; // edi
__int64 result; // rax

v2 = 80 * a2 + a1;
__outbyte(0x3D4u, 0xEu);
__outbyte(0x3D5u, BYTE1(v2));
__outbyte(0x3D4u, 0xFu);
result = v2;
__outbyte(0x3D5u, v2);
return result;
}

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

v2 = 80 * a2 + a1;
__outbyte(0x3D4u, 0xEu);
__outbyte(0x3D5u, BYTE1(v2));
__outbyte(0x3D4u, 0xFu);
result = v2;
__outbyte(0x3D5u, v2);
return result;
}

original_code:
static void update_cursor(int x, int y)
{
 u16 position = (y * 80) + x;
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0E),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)((position >> 8) & 0xFF)),"d" (0x3D5));
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0F),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)(position & 0xFF)),"d" (0x3D5));
}

canonical_original_code:
static void update_cursor(int x, int y)
{
 unsigned short position = (y * 80) + x;
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0E),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)((position >> 8) & 0xFF)),"d" (0x3D5));
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0F),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)(position & 0xFF)),"d" (0x3D5));
}

variable_types: x int

variable_types: y int

variable_types:
position
unsigned short


scroll

decompiled_code:
__int64 scroll()
{
__int64 v0; // rdi
__int64 v1; // rax
__int64 result; // rax

memset_constprop_0((void *)0xB8000);
v0 = 753664LL;
do
{
memcpy_constprop_0((void *)v0, (const void *)(v0 + 160));
v0 = v1;
}
while ( v1 != 757664 );
result = memset_constprop_0((void *)0xB8F00);
current_x = 0;
current_y = 24;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdi
__int64 v1; // rax
__int64 result; // rax

func2((void *)0xB8000);
v0 = 753664LL;
do
{
func1((void *)v0, (const void *)(v0 + 160));
v0 = v1;
}
while ( v1 != 757664 );
result = func2((void *)0xB8F00);
current_x = 0;
current_y = 24;
return result;
}

canonical_original_code:
static void scroll()
{
 int i = 0;
 unsigned char *up = (u8 *) 0xB8000;
 unsigned char *down = (u8 *) (0xB8000 + 160);
 memset(up, 0, 160);
 while(i < 25)
 {
  memcpy(up, down, 160);
  up += 160;
  down += 160;
  i++;
 }
 memset((void *)(0xB8000 + (160 * 24)), 0, 160);
 current_x= 0;
 current_y = 24;
}

variable_types: i int

variable_types:
up
unsigned char *

variable_types:
down
unsigned char *


decompiled_code:
void __fastcall put_char(char a1)
{
int v1; // eax

if ( a1 == 11 )
{
current_y += 5;
return;
}
if ( a1 > 11 )
{
if ( a1 == 13 )
{
current_x = 0;
return;
}
}
else
{
if ( a1 == 9 )
{
current_x += 5;
return;
}
if ( a1 == 10 )
{
++current_y;
current_x = 0;
return;
}
}
v1 = current_y;
if ( current_x > 79 )
{
current_x = 0;
v1 = ++current_y;
}
if ( v1 > 24 )
{
scroll();
v1 = current_y;
}
*(_BYTE *)(VGA + 2 * (current_x + 80 * v1)) = a1;
*(_BYTE *)(VGA + 160 * current_y + 2 * current_x++ + 1) = attr;
}

canonical_decompiled_code:
void __fastcall func4(char a1)
{
int v1; // eax

if ( a1 == 11 )
{
current_y += 5;
return;
}
if ( a1 > 11 )
{
if ( a1 == 13 )
{
current_x = 0;
return;
}
}
else
{
if ( a1 == 9 )
{
current_x += 5;
return;
}
if ( a1 == 10 )
{
++current_y;
current_x = 0;
return;
}
}
v1 = current_y;
if ( current_x > 79 )
{
current_x = 0;
v1 = ++current_y;
}
if ( v1 > 24 )
{
func3();
v1 = current_y;
}
*(_BYTE *)(VGA + 2 * (current_x + 80 * v1)) = a1;
*(_BYTE *)(VGA + 160 * current_y + 2 * current_x++ + 1) = attr;
}

original_code:
static void put_char(char ch)
{
 switch(ch)
 {
  case 0xb: current_y += 5; goto end;
  case 0x9: current_x += 5;goto end;
  case 0xa: current_y += 1;current_x = 0;goto end;
  case 0xd: current_x = 0;goto end;
 }
 if(current_x > 79)
 {
  current_x = 0;
  current_y += 1;
 }
 if(current_y > 24)
  scroll();
 VGA[(current_y * 160) + (current_x * 2)] = ch;
 VGA[(current_y * 160) + (current_x * 2 + 1)] = attr;
 current_x++;
end: ;
}

variable_types: ch char


tcgetattr

decompiled_code:
__int64 __fastcall tcgetattr(unsigned __int16 a1)
{
_QWORD v2[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v3; // [rsp+3Ah] [rbp-Eh]

v2[1] = a1;
v3 = 8;
v2[2] = 56LL;
v2[6] = 5LL;
send_message(1LL, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
_QWORD v2[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v3; // [rsp+3Ah] [rbp-Eh]

v2[1] = a1;
v3 = 8;
v2[2] = 56LL;
v2[6] = 5LL;
send_message(1LL, v2);
return 0LL;
}

original_code:
int tcgetattr(int fildes, struct termios *termios_p)
{
 struct message msg;
 msg.flags = 8;
 msg.m2.rcv_ptr = termios_p;
 msg.m3.rcv_bufsize = sizeof(struct termios);
 msg.w1 = 5;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

variable_types: fildes int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; } *

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; }


tcsetattr

decompiled_code:
__int64 __fastcall tcsetattr(unsigned __int16 a1, __int64 a2, __int64 a3)
{
__int64 v4[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v5; // [rsp+3Ah] [rbp-Eh]

v4[1] = a1;
v5 = 2;
v4[5] = a3;
v4[0] = 56LL;
v4[6] = 6LL;
send_message(1LL, v4);
return 0LL;
}

original_code:
int tcsetattr(int fildes, int optional_actions,
       const struct termios *termios_p)
{
 struct message msg;
 msg.flags = 2;
 msg.m4.snd_ptr = (void *)termios_p;
 msg.m1.snd_bufsize = sizeof(struct termios);
 msg.w1 = 6;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

canonical_original_code:
int tcsetattr(int fildes, int optional_actions, struct termios *termios_p)
{
 struct message msg;
 msg.flags = 2;
 msg.m4.snd_ptr = (void *)termios_p;
 msg.m1.snd_bufsize = sizeof(struct termios);
 msg.w1 = 6;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

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; }

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; }


tcgetsid

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

v2[1] = a1;
v4 = 1;
v3 = 7LL;
send_message(1LL, v2);
return (unsigned int)v3;
}

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

v2[1] = a1;
v4 = 1;
v3 = 7LL;
send_message(1LL, v2);
return (unsigned int)v3;
}

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

canonical_original_code:
int tcgetsid(int fildes)
{
 struct message msg;
 msg.flags = 1;
 msg.w1 = 7;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return msg.w1;
}


tcflush

decompiled_code:
__int64 __fastcall tcflush(unsigned __int16 a1, int a2)
{
_QWORD v3[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+3Ah] [rbp-Eh]

v3[1] = a1;
v3[5] = a2;
v4 = 1;
v3[6] = 8LL;
send_message(1LL, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, int a2)
{
_QWORD v3[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+3Ah] [rbp-Eh]

v3[1] = a1;
v3[5] = a2;
v4 = 1;
v3[6] = 8LL;
send_message(1LL, v3);
return 0LL;
}

original_code:
int tcflush(int fildes, int queue_selector)
{
 struct message msg;
 msg.flags = 1;
 msg.w1 = 8;
 msg.m2.w4 = (fildes & 0xFFFF);
 msg.m4.w2 = queue_selector;
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}


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

result = kmem_cache_create("vm_object_cache", 104LL, 4LL, 0LL, 0LL);
vm_object_cache = result;
return result;
}

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

result = kmem_cache_create("vm_object_cache", 104LL, 4LL, 0LL, 0LL);
vm_object_cache = result;
return result;
}

original_code:
void vm_object_init()
{
 vm_object_cache = kmem_cache_create("vm_object_cache", sizeof(struct vm_object), 4, ((void *)0), ((void *)0));
}

user_defined_types: struct vm_object { struct linked_list page; struct atomic_t ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object vn; struct spinlock lock; }

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


decompiled_code:
void __fastcall vm_object_create(int a1)
{
__int64 v1; // rax
__int64 v2; // rax

v1 = kmem_cache_alloc(vm_object_cache, 0LL);
*(_DWORD *)(v1 + 24) = a1;
*(_DWORD *)(v1 + 16) = 1;
list_init((_QWORD *)v1);
*(_DWORD *)(v2 + 96) = 1;
*(_QWORD *)(v2 + 32) = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
__int64 v1; // rax
__int64 v2; // rax

v1 = kmem_cache_alloc(vm_object_cache, 0LL);
*(_DWORD *)(v1 + 24) = a1;
*(_DWORD *)(v1 + 16) = 1;
func0((_QWORD *)v1);
*(_DWORD *)(v2 + 96) = 1;
*(_QWORD *)(v2 + 32) = 0LL;
}

original_code:
vm_object_t vm_object_create(vm_size_t size)
{
 vm_object_t new_vm_object;
 new_vm_object = (vm_object_t) kmem_cache_alloc(vm_object_cache, 0);
 new_vm_object->size = size;
 ((&new_vm_object->ref_count)->value = 1);
 list_init(&new_vm_object->page);
 ((&new_vm_object->lock)->lock = 1);
 new_vm_object->shadow = ((void *)0);
 return new_vm_object;
}

canonical_original_code:
struct vm_object *vm_object_create(unsigned int size)
{
 struct vm_object *new_vm_object;
 new_vm_object = (struct vm_object *) kmem_cache_alloc(vm_object_cache, 0);
 new_vm_object->size = size;
 ((&new_vm_object->ref_count)->value = 1);
 list_init(&new_vm_object->page);
 ((&new_vm_object->lock)->lock = 1);
 new_vm_object->shadow = ((void *)0);
 return new_vm_object;
}

variable_types:
size
unsigned int

variable_types: struct vm_object { struct linked_list { void *next; } page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *


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

result = atomic_dec((volatile signed __int32 *)(a1 + 16));
if ( (_DWORD)result )
{
free_pages(a1);
result = kmem_cache_free(vm_object_cache, a1);
}
return result;
}

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

result = func1((volatile signed __int32 *)(a1 + 16));
if ( (_DWORD)result )
{
free_pages(a1);
result = kmem_cache_free(vm_object_cache, a1);
}
return result;
}

original_code:
void delete_object(vm_object_t object)
{
 if(!atomic_dec(&object->ref_count))
  return;
 free_pages(object);
 kmem_cache_free(vm_object_cache, object);
}

canonical_original_code:
void delete_object(struct vm_object *object)
{
 if(!atomic_dec(&object->ref_count))
  return;
 free_pages(object);
 kmem_cache_free(vm_object_cache, object);
}


decompiled_code:
const char *__fastcall get_file_type(__int16 a1)
{
int v1; // edi
const char *result; // rax

v1 = a1 & 0xF000;
result = "directory";
if ( v1 != 0x4000 )
{
switch ( v1 )
{
case 32768:
result = "regular file";
break;
case 40960:
result = "symbolic link";
break;
case 24576:
result = "block special file";
break;
case 8192:
result = "character special file";
break;
case 49152:
result = "socket special file";
break;
default:
result = "FIFO special file";
if ( v1 != 4096 )
result = "unknown";
break;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int16 a1)
{
int v1; // edi
const char *result; // rax

v1 = a1 & 0xF000;
result = "directory";
if ( v1 != 0x4000 )
{
switch ( v1 )
{
case 32768:
result = "regular file";
break;
case 40960:
result = "symbolic link";
break;
case 24576:
result = "block special file";
break;
case 8192:
result = "character special file";
break;
case 49152:
result = "socket special file";
break;
default:
result = "FIFO special file";
if ( v1 != 4096 )
result = "unknown";
break;
}
}
return result;
}

original_code:
static char *get_file_type(mode_t mode)
{
  char *type;
  if(((mode & 0xF000) == 0x4000))
   type = "directory";
  else if(((mode & 0xF000) == 0x8000))
   type = "regular file";
  else if(((mode & 0xF000) == 0xA000))
   type = "symbolic link";
  else if(((mode & 0xF000) == 0x6000))
   type = "block special file";
  else if(((mode & 0xF000) == 0x2000))
   type = "character special file";
  else if(((mode & 0xF000) == 0xC000))
   type = "socket special file";
  else if(((mode & 0xF000) == 0x1000))
   type = "FIFO special file";
  else
   type = "unknown";
  return type;
}

canonical_original_code:
static char *get_file_type(int mode)
{
  char *type;
  if(((mode & 0xF000) == 0x4000))
   type = "directory";
  else if(((mode & 0xF000) == 0x8000))
   type = "regular file";
  else if(((mode & 0xF000) == 0xA000))
   type = "symbolic link";
  else if(((mode & 0xF000) == 0x6000))
   type = "block special file";
  else if(((mode & 0xF000) == 0x2000))
   type = "character special file";
  else if(((mode & 0xF000) == 0xC000))
   type = "socket special file";
  else if(((mode & 0xF000) == 0x1000))
   type = "FIFO special file";
  else
   type = "unknown";
  return type;
}

variable_types: mode int

variable_types:
type
char *

return_type: char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-68h] BYREF
unsigned int v5; // [rsp+8h] [rbp-60h]
int v6; // [rsp+Ch] [rbp-5Ch]
unsigned int v7; // [rsp+10h] [rbp-58h]
__int64 v8; // [rsp+28h] [rbp-40h]
unsigned int v9; // [rsp+48h] [rbp-20h]
__int64 v10; // [rsp+50h] [rbp-18h]

if ( stat("/bin/stat", (struct stat *)&v4) < 0 )
{
fprintf((FILE *)"Could not stat file \"%s\"", "/bin/stat");
}
else
{
printf("\n File: '%s'", "/bin/stat");
get_file_type(v6);
printf("\n Size: %-15d Blocks: %-15d IO Block: %-8d", v8, v10, v9);
printf("\nDevice: %-15d Inode: %-15d Links: %-8d", v4, v5, v7);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-68h] BYREF
unsigned int v5; // [rsp+8h] [rbp-60h]
int v6; // [rsp+Ch] [rbp-5Ch]
unsigned int v7; // [rsp+10h] [rbp-58h]
__int64 v8; // [rsp+28h] [rbp-40h]
unsigned int v9; // [rsp+48h] [rbp-20h]
__int64 v10; // [rsp+50h] [rbp-18h]

if ( stat("/bin/stat", (struct stat *)&v4) < 0 )
{
fprintf((FILE *)"Could not stat file \"%s\"", "/bin/stat");
}
else
{
printf("\n File: '%s'", "/bin/stat");
func0(v6);
printf("\n Size: %-15d Blocks: %-15d IO Block: %-8d", v8, v10, v9);
printf("\nDevice: %-15d Inode: %-15d Links: %-8d", v4, v5, v7);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int ret;
  struct stat st;
  char *path = "/bin/stat";
  ret = stat(path, &st);
  if(ret < 0)
  {
   fprintf("Could not stat file \"%s\"", path);
 return 0;
  }
  printf("\n  File: '%s'", path);
  printf("\n  Size: %-15d Blocks: %-15d IO Block: %-8d" , st.st_size, st.st_blocks, st.st_blksize, get_file_type(st.st_mode));
  printf("\nDevice: %-15d Inode: %-15d Links: %-8d", st.st_dev, st.st_ino, st.st_nlink);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

variable_types: struct stat { 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; }

variable_types:
path
char *


original_code:
void qb_initialize(struct QueueBuffer **qbuf) {
 if (!qbuf)
  return;
 *qbuf = malloc(sizeof(struct QueueBuffer));
 (*qbuf)->head = malloc(sizeof(struct QueueBufferNode));
 (*qbuf)->tail = (*qbuf)->head;
 (*qbuf)->head->front =
 (*qbuf)->head->back = (*qbuf)->head->buffer;
 (*qbuf)->head->next = ((void *)0);
}

variable_types: struct QueueBuffer { struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; } *head; } **

user_defined_types: struct QueueBuffer { struct QueueBufferNode *head; }


original_code:
void qb_push(struct QueueBuffer *qbuf, const void *buffer, size_t len) {
 if (!qbuf)
  return;
 const char *cbuffer = (const char*)buffer;
 int i = 0,
     delta;
 while (i < len) {
  if (qbuf->tail->back - qbuf->tail->buffer >= 4096) {
   qbuf->tail->next = malloc(sizeof(struct QueueBufferNode));
   qbuf->tail = qbuf->tail->next;
   qbuf->tail->front =
   qbuf->tail->back = qbuf->tail->buffer;
   qbuf->tail->next = ((void *)0);
  }
  if (len - i > 4096 - (qbuf->tail->back - qbuf->tail->buffer))
   delta = 4096 - (qbuf->tail->back - qbuf->tail->buffer);
  else
   delta = len - i;
  memcpy(qbuf->tail->back, cbuffer + i, delta);
  qbuf->tail->back += delta;
  i += delta;
 }
}

canonical_original_code:
void qb_push(struct QueueBuffer *qbuf, void *buffer, unsigned long len) {
 if (!qbuf)
  return;
 char *cbuffer = (const char*)buffer;
 int i = 0; int delta;
 while (i < len) {
  if (qbuf->tail->back - qbuf->tail->buffer >= 4096) {
   qbuf->tail->next = malloc(sizeof(struct QueueBufferNode));
   qbuf->tail = qbuf->tail->next;
   qbuf->tail->front =
   qbuf->tail->back = qbuf->tail->buffer;
   qbuf->tail->next = ((void *)0);
  }
  if (len - i > 4096 - (qbuf->tail->back - qbuf->tail->buffer))
   delta = 4096 - (qbuf->tail->back - qbuf->tail->buffer);
  else
   delta = len - i;
  memcpy(qbuf->tail->back, cbuffer + i, delta);
  qbuf->tail->back += delta;
  i += delta;
 }
}

variable_types: struct QueueBuffer { struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; } *head; } *

variable_types:
buffer
void *

variable_types:
len
unsigned long

variable_types:
cbuffer
char *

variable_types: i int

variable_types: delta int


original_code:
int qb_pop(struct QueueBuffer *qbuf, void *buffer, size_t numbytes) {
 if (!qbuf)
  return 0;
 struct QueueBufferNode *current = qbuf->head;
 char *cbuffer = (char *)buffer;
 int i = 0,
     delta;
 while (i < numbytes) {
  if (qbuf->head->front == qbuf->head->back) {
   if (qbuf->head->next == ((void *)0)) {
    return i;
   } else {
    struct QueueBufferNode *temp = qbuf->head->next;
    free(qbuf->head);
    qbuf->head = temp;
   }
  }
  delta = qbuf->head->back - qbuf->head->front;
  if (numbytes - i < delta)
   delta = numbytes - i;
  memcpy(cbuffer + i, qbuf->head->front, delta);
  qbuf->head->front += delta;
  i += delta;
 }
 return i;
}

canonical_original_code:
int qb_pop(struct QueueBuffer *qbuf, void *buffer, unsigned long numbytes) {
 if (!qbuf)
  return 0;
 struct QueueBufferNode *current = qbuf->head;
 char *cbuffer = (char *)buffer;
 int i = 0; int delta;
 while (i < numbytes) {
  if (qbuf->head->front == qbuf->head->back) {
   if (qbuf->head->next == ((void *)0)) {
    return i;
   } else {
    struct QueueBufferNode *temp = qbuf->head->next;
    free(qbuf->head);
    qbuf->head = temp;
   }
  }
  delta = qbuf->head->back - qbuf->head->front;
  if (numbytes - i < delta)
   delta = numbytes - i;
  memcpy(cbuffer + i, qbuf->head->front, delta);
  qbuf->head->front += delta;
  i += delta;
 }
 return i;
}

variable_types:
numbytes
unsigned long

variable_types: struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; } *


decompiled_code:
__int64 __fastcall qb_getSize(_QWORD *a1)
{
_QWORD *v1; // rax
unsigned int v2; // er8
__int64 v3; // rdx

if ( !a1 )
return 0LL;
v1 = (_QWORD *)*a1;
v2 = 0;
if ( *a1 )
{
do
{
v3 = v1[513] - v1[512];
v1 = (_QWORD *)v1[514];
v2 += v3;
}
while ( v1 );
}
return v2;
}

original_code:
int qb_getSize(struct QueueBuffer *qbuf) {
 if (!qbuf)
  return 0;
 int size = 0;
 struct QueueBufferNode *current = qbuf->head;
 while (current != ((void *)0)) {
  size += current->back - current->front;
  current = current->next;
 }
 return size;
}

variable_types: size int

user_defined_types: struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; }


dolog

repo: quadstor/ietbsd

decompiled_code:
void __fastcall dolog(int a1, const char *a2, void *a3)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( log_daemon )
{
vsyslog(a1, a2, a3);
}
else
{
gettimeofday(&v4, 0LL);
fprintf(stderr, "%ld.%06ld: ", v4.tv_sec, v4.tv_usec);
vfprintf(stderr, a2, a3);
fputc(10, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, const char *a2, void *a3)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( log_daemon )
{
vsyslog(a1, a2, a3);
}
else
{
gettimeofday(&v4, 0LL);
fprintf(stderr, "%ld.%06ld: ", v4.tv_sec, v4.tv_usec);
vfprintf(stderr, a2, a3);
fputc(10, stderr);
fflush(stderr);
}
}

original_code:
static void dolog(int prio, const char *fmt, va_list ap)
{
 if (log_daemon)
  vsyslog(prio, fmt, ap);
 else {
  struct timeval time;
  gettimeofday(&time, ((void *)0));
  fprintf(stderr, "%ld.%06ld: ", time.tv_sec, time.tv_usec);
  vfprintf(stderr, fmt, ap);
  fprintf(stderr, "\n");
  fflush(stderr);
 }
}

canonical_original_code:
static void dolog(int prio, char *fmt, __builtin_va_list ap)
{
 if (log_daemon)
  vsyslog(prio, fmt, ap);
 else {
  struct timeval time;
  gettimeofday(&time, ((void *)0));
  fprintf(stderr, "%ld.%06ld: ", time.tv_sec, time.tv_usec);
  vfprintf(stderr, fmt, ap);
  fprintf(stderr, "\n");
  fflush(stderr);
 }
}

variable_types: prio int

variable_types:
fmt
char *

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
void log_init()
{
if ( log_daemon )
openlog("ietd", 0, 24);
}

canonical_decompiled_code:
void func1()
{
if ( log_daemon )
openlog("ietd", 0, 24);
}

original_code:
void log_init(void)
{
 if (log_daemon)
  openlog("ietd", 0, (3<<3));
}

canonical_original_code:
void log_init()
{
 if (log_daemon)
  openlog("ietd", 0, (3<<3));
}


decompiled_code:
void log_warning(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
dolog(4, a1, va);
}

canonical_decompiled_code:
void func2(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(4, a1, va);
}

original_code:
void log_warning(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(4, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void log_warning(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(4, fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void log_error(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
dolog(3, a1, va);
}

canonical_decompiled_code:
void func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(3, a1, va);
}

original_code:
void log_error(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(3, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void log_error(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(3, fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void log_debug(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( log_level >= a1 )
{
va_start(va, a2);
dolog(7, a2, va);
}
}

canonical_decompiled_code:
void func4(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( log_level >= a1 )
{
va_start(va, a2);
func0(7, a2, va);
}
}

original_code:
void log_debug(int level, const char *fmt, ...)
{
 if (log_level >= level) {
  va_list ap;
  __builtin_va_start(ap,fmt);
  dolog(7, fmt, ap);
  __builtin_va_end(ap);
 }
}

canonical_original_code:
void log_debug(int level, char *fmt, ...)
{
 if (log_level >= level) {
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  dolog(7, fmt, ap);
  __builtin_va_end(ap);
 }
}

variable_types: level int


original_code:
void log_pdu(int level, struct PDU *pdu)
{
 unsigned char char_buf[16];
 int char_cnt = 0;
 unsigned char *buf;
 int i;
 if (log_level < level)
  return;
 buf = (void *)&pdu->bhs;
 log_debug(level, "BHS: (%p)", buf);
 for (i = 0; i < 48; i++)
  __dump_char(level, char_buf, &char_cnt, *buf++);
 __dump_line(level, char_buf, &char_cnt);
 buf = (void *)pdu->ahs;
 log_debug(level, "AHS: (%p)", buf);
 for (i = 0; i < pdu->ahssize; i++)
  __dump_char(level, char_buf, &char_cnt, *buf++);
 __dump_line(level, char_buf, &char_cnt);
 buf = (void *)pdu->data;
 log_debug(level, "Data: (%p)", buf);
 for (i = 0; i < pdu->datasize; i++)
  __dump_char(level, char_buf, &char_cnt, *buf++);
 __dump_line(level, char_buf, &char_cnt);
}

variable_types: struct PDU { struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; } bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; } *

variable_types:
buf
unsigned char *

user_defined_types: struct PDU { struct iscsi_hdr bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; }


decompiled_code:
__int64 __fastcall or_set_val(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) | *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

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

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) | *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

original_code:
static void or_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 *val |= param[idx].val;
 param[idx].val = *val;
}

variable_types: struct iscsi_param { int state; unsigned int val; } *

variable_types: idx int

variable_types:
val
unsigned int *


decompiled_code:
__int64 __fastcall and_set_val(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) & *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) & *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

original_code:
static void and_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 *val &= param[idx].val;
 param[idx].val = *val;
}

user_defined_types: struct iscsi_param { int state; unsigned int val; }


decompiled_code:
__int64 __fastcall minimum_check_val(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a1 + 12);
if ( *a2 < v2 || *a2 > *(_DWORD *)(a1 + 16) )
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a1 + 12);
if ( *a2 < v2 || *a2 > *(_DWORD *)(a1 + 16) )
*a2 = v2;
return 0LL;
}

original_code:
static int minimum_check_val(struct iscsi_key *key, unsigned int *val)
{
 int err = 0;
 if (*val < key->min || key->max < *val) {
  *val = key->min;
  err = -22;
 }
 return 0;
}

variable_types: struct iscsi_key { char *name; unsigned int def; unsigned int min; unsigned int max; struct iscsi_key_ops { int (*val_to_str)(unsigned int, char *); int (*str_to_val)(char *, unsigned int *); int (*check_val)(struct iscsi_key *, unsigned int *); void (*set_val)(struct iscsi_param { int state; unsigned int val; } *, int, unsigned int *); } *ops; } *

variable_types: err int

user_defined_types: struct iscsi_key { char *name; unsigned int def; unsigned int min; unsigned int max; struct iscsi_key_ops *ops; }

user_defined_types: struct iscsi_key_ops { int (*val_to_str)(unsigned int, char *); int (*str_to_val)(char *, unsigned int *); int (*check_val)(struct iscsi_key *, unsigned int *); void (*set_val)(struct iscsi_param *, int, unsigned int *); }


decompiled_code:
__int64 __fastcall maximum_check_val(__int64 a1, unsigned int *a2)
{
unsigned int v2; // edx

v2 = *(_DWORD *)(a1 + 16);
if ( *a2 < *(_DWORD *)(a1 + 12) || *a2 > v2 )
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int *a2)
{
unsigned int v2; // edx

v2 = *(_DWORD *)(a1 + 16);
if ( *a2 < *(_DWORD *)(a1 + 12) || *a2 > v2 )
*a2 = v2;
return 0LL;
}

original_code:
static int maximum_check_val(struct iscsi_key *key, unsigned int *val)
{
 int err = 0;
 if (*val < key->min || key->max < *val) {
  *val = key->max;
  err = -22;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall minimum_set_val(__int64 a1, int a2, unsigned int *a3)
{
__int64 result; // rax
unsigned int v4; // esi

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( *a3 <= v4 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

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

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( *a3 <= v4 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

original_code:
static void minimum_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if (*val > param[idx].val)
  *val = param[idx].val;
 else
  param[idx].val = *val;
}


decompiled_code:
__int64 __fastcall maximum_set_val(__int64 a1, int a2, unsigned int *a3)
{
__int64 result; // rax
unsigned int v4; // esi

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( v4 <= *a3 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

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

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( v4 <= *a3 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

original_code:
static void maximum_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if (param[idx].val > *val)
  *val = param[idx].val;
 else
  param[idx].val = *val;
}


decompiled_code:
__int64 __fastcall digest_set_val(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax
__int64 v4; // rcx

result = 1LL;
v4 = a1 + 8LL * a2;
if ( (*a3 & 2) != 0 )
result = (unsigned int)((*(_BYTE *)(v4 + 4) & 2) != 0) + 1;
*(_DWORD *)a3 = result;
*(_DWORD *)(v4 + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax
__int64 v4; // rcx

result = 1LL;
v4 = a1 + 8LL * a2;
if ( (*a3 & 2) != 0 )
result = (unsigned int)((*(_BYTE *)(v4 + 4) & 2) != 0) + 1;
*(_DWORD *)a3 = result;
*(_DWORD *)(v4 + 4) = result;
return result;
}

original_code:
static void digest_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if (*val & (1 << 1) && param[idx].val & (1 << 1))
  *val = (1 << 1);
 else
  *val = (1 << 0);
 param[idx].val = *val;
}


decompiled_code:
_BOOL8 __fastcall marker_set_val(_DWORD *a1, int a2, _DWORD *a3)
{
_BOOL8 result; // rax

if ( a2 == 17 )
{
result = a1[30] != 2;
*a3 = result;
a1[35] = result;
}
else
{
result = 1LL;
if ( a2 == 18 )
{
result = a1[32] != 2;
*a3 = result;
a1[37] = result;
}
else
{
*a3 = 1;
a1[2 * a2 + 1] = 1;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_DWORD *a1, int a2, _DWORD *a3)
{
_BOOL8 result; // rax

if ( a2 == 17 )
{
result = a1[30] != 2;
*a3 = result;
a1[35] = result;
}
else
{
result = 1LL;
if ( a2 == 18 )
{
result = a1[32] != 2;
*a3 = result;
a1[37] = result;
}
else
{
*a3 = 1;
a1[2 * a2 + 1] = 1;
}
}
return result;
}

original_code:
static void marker_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if ((idx == key_ofmarkint && param[key_ofmarker].state == 2) ||
     (idx == key_ifmarkint && param[key_ifmarker].state == 2))
  *val = 0;
 else
  *val = 1;
 param[idx].val = *val;
}


decompiled_code:
__int64 __fastcall range_str_to_val(const char *a1, _DWORD *a2)
{
*a2 = strtol(a1, 0LL, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, _DWORD *a2)
{
*a2 = strtol(a1, 0LL, 0);
return 0LL;
}

original_code:
static int range_str_to_val(char *str, unsigned int *val)
{
 *val = strtol(str, ((void *)0), 0);
 return 0;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall range_val_to_str(unsigned int a1, char *a2)
{
sprintf(a2, "%u", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, char *a2)
{
sprintf(a2, "%u", a1);
return 0LL;
}

original_code:
static int range_val_to_str(unsigned int val, char *str)
{
 sprintf(str, "%u", val);
 return 0;
}

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall marker_val_to_str(int a1, char *a2)
{
if ( a1 )
strcpy(a2, "Reject");
else
strcpy(a2, "Irrelevant");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, char *a2)
{
if ( a1 )
strcpy(a2, "Reject");
else
strcpy(a2, "Irrelevant");
return 0LL;
}

original_code:
static int marker_val_to_str(unsigned int val, char *str)
{
 if (val == 0)
  strcpy(str, "Irrelevant");
 else
  strcpy(str, "Reject");
 return 0;
}


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

if ( a1 )
{
if ( a1 == 1 )
{
*(_DWORD *)a2 = 7562585;
result = 0LL;
}
else
{
result = 4294967274LL;
}
}
else
{
strcpy(a2, "No");
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a1 == 1 )
{
*(_DWORD *)a2 = 7562585;
result = 0LL;
}
else
{
result = 4294967274LL;
}
}
else
{
strcpy(a2, "No");
result = 0LL;
}
return result;
}

original_code:
static int bool_val_to_str(unsigned int val, char *str)
{
 int err = 0;
 switch (val) {
 case 0:
  strcpy(str, "No");
  break;
 case 1:
  strcpy(str, "Yes");
  break;
 default:
  err = -22;
 }
 return err;
}


decompiled_code:
__int64 __fastcall digest_str_to_val(char *a1, _DWORD *a2)
{
char *v2; // rax
char *stringp; // [rsp+8h] [rbp-20h] BYREF

*a2 = 0;
stringp = a1;
while ( 1 )
{
while ( 1 )
{
v2 = strsep(&stringp, ",");
if ( strcmp(v2, "None") )
break;
*a2 |= 1u;
if ( !stringp )
return 0LL;
}
if ( strcmp(v2, "CRC32C") )
break;
*a2 |= 2u;
if ( !stringp )
return 0LL;
}
return 4294967274LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1, _DWORD *a2)
{
char *v2; // rax
char *stringp; // [rsp+8h] [rbp-20h] BYREF

*a2 = 0;
stringp = a1;
while ( 1 )
{
while ( 1 )
{
v2 = strsep(&stringp, ",");
if ( strcmp(v2, "None") )
break;
*a2 |= 1u;
if ( !stringp )
return 0LL;
}
if ( strcmp(v2, "CRC32C") )
break;
*a2 |= 2u;
if ( !stringp )
return 0LL;
}
return 4294967274LL;
}

original_code:
static int digest_str_to_val(char *str, unsigned int *val)
{
 int err = 0;
 char *p, *q;
 p = str;
 *val = 0;
 do {
  q = strsep(&p, ",");
  if (!strcmp(q, "None"))
   *val |= (1 << 0);
  else if (!strcmp(q, "CRC32C"))
   *val |= (1 << 1);
  else {
   err = -22;
   break;
  }
 } while (p);
 return err;
}

canonical_original_code:
static int digest_str_to_val(char *str, unsigned int *val)
{
 int err = 0;
 char *p; char *q;
 p = str;
 *val = 0;
 do {
  q = strsep(&p, ",");
  if (!strcmp(q, "None"))
   *val |= (1 << 0);
  else if (!strcmp(q, "CRC32C"))
   *val |= (1 << 1);
  else {
   err = -22;
   break;
  }
 } while (p);
 return err;
}

variable_types:
p
char *

variable_types:
q
char *


decompiled_code:
__int64 __fastcall bool_str_to_val(__int64 a1, _DWORD *a2)
{
bool v2; // zf
__int64 result; // rax

v2 = strcmp((const char *)a1, "Yes") == 0;
result = !v2;
if ( v2 )
{
*a2 = 1;
}
else if ( *(_BYTE *)a1 == 78
&& *(_BYTE *)(a1 + 1) == 111
&& (result = *(unsigned __int8 *)(a1 + 2), !*(_BYTE *)(a1 + 2)) )
{
*a2 = 0;
}
else
{
result = 4294967274LL;
}
return result;
}

original_code:
static int bool_str_to_val(char *str, unsigned int *val)
{
 int err = 0;
 if (!strcmp(str, "Yes"))
  *val = 1;
 else if (!strcmp(str, "No"))
  *val = 0;
 else
  err = -22;
 return err;
}


decompiled_code:
__int64 __fastcall digest_val_to_str(char a1, char *a2)
{
if ( (a1 & 1) != 0 )
strcpy(a2, "None");
if ( (a1 & 2) == 0 )
return *a2 == 0 ? 0xFFFFFFEA : 0;
if ( *a2 )
{
*(_QWORD *)&a2[strlen(a2)] = 0x4332334352432CLL;
return *a2 == 0 ? 0xFFFFFFEA : 0;
}
strcpy(a2, "CRC32C");
return *a2 == 0 ? 0xFFFFFFEA : 0;
}

canonical_decompiled_code:
__int64 __fastcall func14(char a1, char *a2)
{
if ( (a1 & 1) != 0 )
strcpy(a2, "None");
if ( (a1 & 2) == 0 )
return *a2 == 0 ? 0xFFFFFFEA : 0;
if ( *a2 )
{
*(_QWORD *)&a2[strlen(a2)] = 0x4332334352432CLL;
return *a2 == 0 ? 0xFFFFFFEA : 0;
}
strcpy(a2, "CRC32C");
return *a2 == 0 ? 0xFFFFFFEA : 0;
}

original_code:
static int digest_val_to_str(unsigned int val, char *str)
{
 int err = 0;
 if (val & (1 << 0))
  strcpy(str, "None");
 if (val & (1 << 1)) {
  if (strlen(str))
   strcat(str, ",CRC32C");
  else
   strcpy(str, "CRC32C");
 }
 if (!strlen(str))
  err = -22;
 return err;
}


decompiled_code:
__int64 __fastcall param_index_by_name(char *s2, const char **a2)
{
const char *v3; // rdi
const char **v4; // rbx
unsigned int v5; // er12

v3 = *a2;
if ( !*a2 )
return 4294967294LL;
v4 = a2 + 4;
v5 = 0;
while ( strcasecmp(v3, s2) )
{
v3 = *v4;
v4 += 4;
++v5;
if ( !v3 )
return 4294967294LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *s2, const char **a2)
{
const char *v3; // rdi
const char **v4; // rbx
unsigned int v5; // er12

v3 = *a2;
if ( !*a2 )
return 4294967294LL;
v4 = a2 + 4;
v5 = 0;
while ( strcasecmp(v3, s2) )
{
v3 = *v4;
v4 += 4;
++v5;
if ( !v3 )
return 4294967294LL;
}
return v5;
}

original_code:
int param_index_by_name(char *name, struct iscsi_key *keys)
{
 int i, err = -2;
 for (i = 0; keys[i].name; i++) {
  if (!strcasecmp(keys[i].name, name)) {
   err = i;
   break;
  }
 }
 return err;
}

canonical_original_code:
int param_index_by_name(char *name, struct iscsi_key *keys)
{
 int i; int err = -2;
 for (i = 0; keys[i].name; i++) {
  if (!strcasecmp(keys[i].name, name)) {
   err = i;
   break;
  }
 }
 return err;
}

variable_types:
name
char *

variable_types: i int


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

if ( *a2 )
{
v2 = 0LL;
do
{
*(_DWORD *)(a1 + v2 * 2 + 4) = a2[v2 + 1];
v2 += 4LL;
}
while ( a2[v2] );
}
}

original_code:
void param_set_defaults(struct iscsi_param *params, struct iscsi_key *keys)
{
 int i;
 for (i = 0; keys[i].name; i++)
  params[i].val = keys[i].def;
}

variable_types: struct iscsi_key { char *name; unsigned int def; unsigned int min; unsigned int max; struct iscsi_key_ops { int (*val_to_str)(unsigned int, char *); int (*str_to_val)(char *, unsigned int *); int (*check_val)(struct iscsi_key *, unsigned int *); void (*set_val)(struct iscsi_param *, int, unsigned int *); } *ops; } *


decompiled_code:
__int64 __fastcall param_val_to_str(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 (__fastcall *v4)(_QWORD, __int64); // rax
__int64 result; // rax

v4 = **(__int64 (__fastcall ***)(_QWORD, __int64))(32LL * a2 + a1 + 24);
if ( v4 )
result = v4(a3, a4);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 (__fastcall *v4)(_QWORD, __int64); // rax
__int64 result; // rax

v4 = **(__int64 (__fastcall ***)(_QWORD, __int64))(32LL * a2 + a1 + 24);
if ( v4 )
result = v4(a3, a4);
else
result = 0LL;
return result;
}

original_code:
int param_val_to_str(struct iscsi_key *keys, int idx, unsigned int val, char *str)
{
 if (keys[idx].ops->val_to_str)
  return keys[idx].ops->val_to_str(val, str);
 else
  return 0;
}


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

v4 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(32LL * a2 + a1 + 24) + 8LL);
if ( v4 )
result = v4(a3, a4);
else
result = 0LL;
return result;
}

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

v4 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(32LL * a2 + a1 + 24) + 8LL);
if ( v4 )
result = v4(a3, a4);
else
result = 0LL;
return result;
}

original_code:
int param_str_to_val(struct iscsi_key *keys, int idx, char *str, unsigned int *val)
{
 if (keys[idx].ops->str_to_val)
  return keys[idx].ops->str_to_val(str, val);
 else
  return 0;
}


decompiled_code:
__int64 __fastcall param_check_val(__int64 a1, int a2, __int64 a3)
{
__int64 v3; // rdi
__int64 (__fastcall *v4)(__int64, __int64); // rax
__int64 result; // rax

v3 = 32LL * a2 + a1;
v4 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(v3 + 24) + 16LL);
if ( v4 )
result = v4(v3, a3);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, int a2, __int64 a3)
{
__int64 v3; // rdi
__int64 (__fastcall *v4)(__int64, __int64); // rax
__int64 result; // rax

v3 = 32LL * a2 + a1;
v4 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(v3 + 24) + 16LL);
if ( v4 )
result = v4(v3, a3);
else
result = 0LL;
return result;
}

original_code:
int param_check_val(struct iscsi_key *keys, int idx, unsigned int *val)
{
 if (keys[idx].ops->check_val)
  return keys[idx].ops->check_val(&keys[idx], val);
 else
  return 0;
}


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static inline int list_empty(const struct __qelem *head)
{
 return head->q_forw == head;
}

canonical_original_code:
static inline int list_empty(struct __qelem *head)
{
 return head->q_forw == head;
}

variable_types: struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } *


decompiled_code:
__int64 __fastcall is_addr_unspecified(char *cp)
{
int v1; // er8
__int64 result; // rax
int buf; // [rsp+Ch] [rbp-1Ch] BYREF
int v4[6]; // [rsp+10h] [rbp-18h] BYREF

if ( inet_pton(2, cp, &buf) == 1 )
return buf == 0;
v1 = inet_pton(10, cp, v4);
result = 0LL;
if ( v1 == 1 )
result = (v4[3] | v4[2] | v4[1] | v4[0]) == 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *cp)
{
int v1; // er8
__int64 result; // rax
int buf; // [rsp+Ch] [rbp-1Ch] BYREF
int v4[6]; // [rsp+10h] [rbp-18h] BYREF

if ( inet_pton(2, cp, &buf) == 1 )
return buf == 0;
v1 = inet_pton(10, cp, v4);
result = 0LL;
if ( v1 == 1 )
result = (v4[3] | v4[2] | v4[1] | v4[0]) == 0;
return result;
}

original_code:
static int is_addr_unspecified(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return (ia.s_addr == 0);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; }));
 return 0;
}

canonical_original_code:
static int is_addr_unspecified(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return (ia.s_addr == 0);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; }));
 return 0;
}

variable_types:
addr
char *

variable_types:
ia
struct in_addr { unsigned int s_addr; }

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *


decompiled_code:
__int64 __fastcall target_print_addr(__int64 a1, char *a2, int a3)
{
char *v4; // rax
const char *v5; // rdx
char *stringp; // [rsp+8h] [rbp-450h] BYREF
char s[1096]; // [rsp+10h] [rbp-448h] BYREF

stringp = a2;
v4 = strsep(&stringp, "%");
v5 = "%s:%d,1";
stringp = v4;
if ( a3 != 2 )
v5 = "[%s]:%d,1";
snprintf(s, 0x426uLL, v5, v4, server_port);
return text_key_add(a1, "TargetAddress", s);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, int a3)
{
char *v4; // rax
const char *v5; // rdx
char *stringp; // [rsp+8h] [rbp-450h] BYREF
char s[1096]; // [rsp+10h] [rbp-448h] BYREF

stringp = a2;
v4 = strsep(&stringp, "%");
v5 = "%s:%d,1";
stringp = v4;
if ( a3 != 2 )
v5 = "[%s]:%d,1";
snprintf(s, 0x426uLL, v5, v4, server_port);
return text_key_add(a1, "TargetAddress", s);
}

original_code:
static void target_print_addr(struct connection *conn, char *addr, int family)
{
 char taddr[1025 + 32 + 5];
 addr = strsep(&addr, "%");
 snprintf(taddr, sizeof(taddr),
  (family == 2) ? "%s:%d,1" : "[%s]:%d,1",
       addr, server_port);
 text_key_add(conn, "TargetAddress", taddr);
}

canonical_original_code:
static void target_print_addr(struct connection *conn, char *addr, int family)
{
 char taddr[-1];
 addr = strsep(&addr, "%");
 snprintf(taddr, sizeof(taddr),
  (family == 2) ? "%s:%d,1" : "[%s]:%d,1",
       addr, server_port);
 text_key_add(conn, "TargetAddress", taddr);
}

variable_types: struct connection { int state; int iostate; int fd; struct session { struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } slist; char *initiator; struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; } redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; } *target; union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; } sid; int conn_cnt; } *session; unsigned int tid; struct iscsi_param { int state; unsigned int val; } session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU { struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; } bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; } req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; } *

variable_types: family int

variable_types:
taddr
char [-1]

user_defined_types: struct connection { int state; int iostate; int fd; struct session *session; unsigned int tid; struct iscsi_param session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; }

user_defined_types: struct session { struct __qelem slist; char *initiator; struct target *target; union iscsi_sid sid; int conn_cnt; }

user_defined_types: struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; }


decompiled_code:
__int64 __fastcall all_accounts_del(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
_BYTE _0[256]; // [rsp+0h] [rbp+0h] BYREF
char vars100; // [rsp+100h] [rbp+100h] BYREF

memset(_0, 0, sizeof(_0));
while ( 1 )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _BYTE *, char *))(cops + 80LL))(a1, a2, _0, &vars100);
if ( (_DWORD)result == -2 )
break;
(*(void (__fastcall **)(_QWORD, _QWORD, _BYTE *))(cops + 72LL))(a1, a2, _0);
memset(_0, 0, sizeof(_0));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
_BYTE _0[256]; // [rsp+0h] [rbp+0h] BYREF
char vars100; // [rsp+100h] [rbp+100h] BYREF

memset(_0, 0, sizeof(_0));
while ( 1 )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _BYTE *, char *))(cops + 80LL))(a1, a2, _0, &vars100);
if ( (_DWORD)result == -2 )
break;
(*(void (__fastcall **)(_QWORD, _QWORD, _BYTE *))(cops + 72LL))(a1, a2, _0);
memset(_0, 0, sizeof(_0));
}
return result;
}

original_code:
static void all_accounts_del(u32 tid, int dir)
{
 char name[256], pass[256];
 memset(name, 0, sizeof(name));
 for (;cops->account_query(tid, dir, name, pass) != -2;
  memset(name, 0, sizeof(name))) {
  cops->account_del(tid, dir, name);
 }
}

canonical_original_code:
static void all_accounts_del(unsigned int tid, int dir)
{
 char name[256]; char pass[256];
 memset(name, 0, sizeof(name));
 for (;cops->account_query(tid, dir, name, pass) != -2;
  memset(name, 0, sizeof(name))) {
  cops->account_del(tid, dir, name);
 }
}

variable_types:
tid
unsigned int

variable_types: dir int

variable_types:
name
char [256]

variable_types:
pass
char [256]


decompiled_code:
__int64 __fastcall is_addr_loopback(char *cp)
{
int v1; // er8
__int64 result; // rax
char buf[4]; // [rsp+Ch] [rbp-1Ch] BYREF
int v4[6]; // [rsp+10h] [rbp-18h] BYREF

if ( inet_pton(2, cp, buf) == 1 )
return memcmp(cp, "127.", 4uLL) == 0;
v1 = inet_pton(10, cp, v4);
result = 0LL;
if ( v1 == 1 && !(v4[2] | v4[1] | v4[0]) )
result = v4[3] == (unsigned int)_bswap_32_constprop_0();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *cp)
{
int v1; // er8
__int64 result; // rax
char buf[4]; // [rsp+Ch] [rbp-1Ch] BYREF
int v4[6]; // [rsp+10h] [rbp-18h] BYREF

if ( inet_pton(2, cp, buf) == 1 )
return memcmp(cp, "127.", 4uLL) == 0;
v1 = inet_pton(10, cp, v4);
result = 0LL;
if ( v1 == 1 && !(v4[2] | v4[1] | v4[0]) )
result = v4[3] == (unsigned int)func4();
return result;
}

original_code:
static int is_addr_loopback(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return !strncmp(addr, "127.", 4);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == htonl (1); }));
 return 0;
}

canonical_original_code:
static int is_addr_loopback(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return !strncmp(addr, "127.", 4);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == htonl (1); }));
 return 0;
}

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
void __fastcall target_list_build_ifaddrs(__int64 a1, unsigned int a2, const char *a3, int a4)
{
struct ifaddrs *v7; // rbp
socklen_t v8; // er12
const struct sockaddr *v9; // rdi
struct ifaddrs *ifap; // [rsp+8h] [rbp-450h] BYREF
char host[1096]; // [rsp+10h] [rbp-448h] BYREF

getifaddrs(&ifap);
v7 = ifap;
if ( ifap )
{
v8 = 16;
if ( a4 != 2 )
v8 = 28;
do
{
v9 = v7->ifa_addr;
if ( v9
&& v9->sa_family == a4
&& !getnameinfo(v9, v8, host, 0x401u, 0LL, 0, 1)
&& strcmp(a3, host)
&& !(unsigned int)is_addr_loopback(host)
&& (*(unsigned int (__fastcall **)(_QWORD, struct sockaddr *))(cops + 104LL))(a2, v7->ifa_addr) )
{
target_print_addr(a1, host, a4);
}
v7 = v7->ifa_next;
}
while ( v7 );
v7 = ifap;
}
freeifaddrs(v7);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, unsigned int a2, const char *a3, int a4)
{
struct ifaddrs *v7; // rbp
socklen_t v8; // er12
const struct sockaddr *v9; // rdi
struct ifaddrs *ifap; // [rsp+8h] [rbp-450h] BYREF
char host[1096]; // [rsp+10h] [rbp-448h] BYREF

getifaddrs(&ifap);
v7 = ifap;
if ( ifap )
{
v8 = 16;
if ( a4 != 2 )
v8 = 28;
do
{
v9 = v7->ifa_addr;
if ( v9
&& v9->sa_family == a4
&& !getnameinfo(v9, v8, host, 0x401u, 0LL, 0, 1)
&& strcmp(a3, host)
&& !(unsigned int)func5(host)
&& (*(unsigned int (__fastcall **)(_QWORD, struct sockaddr *))(cops + 104LL))(a2, v7->ifa_addr) )
{
func2(a1, host, a4);
}
v7 = v7->ifa_next;
}
while ( v7 );
v7 = ifap;
}
freeifaddrs(v7);
}

original_code:
void target_list_build_ifaddrs(struct connection *conn, u32 tid, char *addr,
        int family)
{
 struct ifaddrs *ifaddr, *ifa;
 char if_addr[1025];
 getifaddrs(&ifaddr);
 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
  if (!ifa->ifa_addr)
   continue;
  int sa_family = ifa->ifa_addr->sa_family;
  if (sa_family == family) {
   if (getnameinfo(ifa->ifa_addr, (family == 2) ?
      sizeof(struct sockaddr_in) :
      sizeof(struct sockaddr_in6),
      if_addr, sizeof(if_addr),
      ((void *)0), 0, 1))
    continue;
   if (strcmp(addr, if_addr) && !is_addr_loopback(if_addr)
    && cops->target_allow(tid, ifa->ifa_addr))
    target_print_addr(conn, if_addr, family);
  }
 }
 freeifaddrs(ifaddr);
}

canonical_original_code:
void target_list_build_ifaddrs(struct connection *conn, unsigned int tid, char *addr, int family)
{
 struct ifaddrs *ifaddr; struct ifaddrs *ifa;
 char if_addr[1025];
 getifaddrs(&ifaddr);
 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
  if (!ifa->ifa_addr)
   continue;
  int sa_family = ifa->ifa_addr->sa_family;
  if (sa_family == family) {
   if (getnameinfo(ifa->ifa_addr, (family == 2) ?
      sizeof(struct sockaddr_in) :
      sizeof(struct sockaddr_in6),
      if_addr, sizeof(if_addr),
      ((void *)0), 0, 1))
    continue;
   if (strcmp(addr, if_addr) && !is_addr_loopback(if_addr)
    && cops->target_allow(tid, ifa->ifa_addr))
    target_print_addr(conn, if_addr, family);
  }
 }
 freeifaddrs(ifaddr);
}

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }

user_defined_types: struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; }

user_defined_types: struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; }

user_defined_types: union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; }

user_defined_types: struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; }


decompiled_code:
__int64 __fastcall target_del(unsigned int a1)
{
void **v1; // rax
void **v2; // rbp
int v3; // er12
unsigned int v4; // er12
int *v6; // rax

v1 = target_find_by_id(a1);
if ( !v1 )
return (unsigned int)-2;
v2 = v1;
if ( !list_empty(v1 + 2) )
{
v4 = -16;
log_warning("%s: target %u still has sessions\n", "target_del", a1);
return v4;
}
v3 = (*(__int64 (__fastcall **)(_QWORD))(ki + 56LL))(a1);
if ( v3 >= 0 )
{
v4 = 0;
remque(v2);
all_accounts_del(a1, 0);
all_accounts_del(a1, 1u);
isns_target_deregister((char *)v2 + 36);
free(v2);
return v4;
}
v6 = _errno_location();
log_error("unable to delete target %u: %d", a1, (unsigned int)*v6);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
void **v1; // rax
void **v2; // rbp
int v3; // er12
unsigned int v4; // er12
int *v6; // rax

v1 = func9(a1);
if ( !v1 )
return (unsigned int)-2;
v2 = v1;
if ( !func0(v1 + 2) )
{
v4 = -16;
log_warning("%s: target %u still has sessions\n", "target_del", a1);
return v4;
}
v3 = (*(__int64 (__fastcall **)(_QWORD))(ki + 56LL))(a1);
if ( v3 >= 0 )
{
v4 = 0;
remque(v2);
func3(a1, 0);
func3(a1, 1u);
isns_target_deregister((char *)v2 + 36);
free(v2);
return v4;
}
v6 = _errno_location();
log_error("unable to delete target %u: %d", a1, (unsigned int)*v6);
return (unsigned int)v3;
}

original_code:
int target_del(u32 tid)
{
 struct target *target = target_find_by_id(tid);
 int err;
 if (!target)
  return -2;
 if (!list_empty(&target->sessions_list)) {
  log_warning("%s: target %u still has sessions\n", __FUNCTION__,
     tid);
  return -16;
 }
 err = ki->target_destroy(tid);
 if (err < 0) {
  log_error("unable to delete target %u: %d", tid, (*__errno_location ()));
  return err;
 }
 remque(&target->tlist);
 all_accounts_del(tid, 0);
 all_accounts_del(tid, 1);
 isns_target_deregister(target->name);
 free(target);
 return 0;
}

canonical_original_code:
int target_del(unsigned int tid)
{
 struct target *target = target_find_by_id(tid);
 int err;
 if (!target)
  return -2;
 if (!list_empty(&target->sessions_list)) {
  log_warning("%s: target %u still has sessions\n", __FUNCTION__,
     tid);
  return -16;
 }
 err = ki->target_destroy(tid);
 if (err < 0) {
  log_error("unable to delete target %u: %d", tid, (*__errno_location ()));
  return err;
 }
 remque(&target->tlist);
 all_accounts_del(tid, 0);
 all_accounts_del(tid, 1);
 isns_target_deregister(target->name);
 free(target);
 return 0;
}

variable_types: struct target { struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; } redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; } *

variable_types: err int