decompiled_code:
__int64 __fastcall kcache_get_slab(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 result; // rax
unsigned __int64 v7; // rdx

result = *(_QWORD *)(a2 + 8);
if ( a2 == result )
return 0LL;
while ( 1 )
{
v7 = *(_QWORD *)(result + 16);
if ( v7 <= a3 && a3 <= (unsigned int)(*(_DWORD *)(a1 + 72) * *(_DWORD *)(result + 24)) + v7 )
break;
result = *(_QWORD *)(result + 8);
if ( result == a2 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 result; // rax
unsigned __int64 v7; // rdx

result = *(_QWORD *)(a2 + 8);
if ( a2 == result )
return 0LL;
while ( 1 )
{
v7 = *(_QWORD *)(result + 16);
if ( v7 <= a3 && a3 <= (unsigned int)(*(_DWORD *)(a1 + 72) * *(_DWORD *)(result + 24)) + v7 )
break;
result = *(_QWORD *)(result + 8);
if ( result == a2 )
return 0LL;
}
return result;
}

original_code:
static inline struct slab *kcache_get_slab(struct kcache *cache, struct list_head *l, void *buf)
{
 struct slab *s;
 for (s = (typeof (*s) *)((char *)((l)->next) - __builtin_offsetof (typeof (*s), l)); &((s)->l) != (l); s = (typeof (*s) *)((char *)((s)->l.next) - __builtin_offsetof (typeof (*s), l))) {
  if (buf >= (void *)s->first_element &&
      buf <= (void *)s->first_element + s->objcount * cache->objsz)
   return s;
 }
 return ((void *)0);
}

variable_types: struct kcache { struct list_head slabs_full; struct list_head slabs_notfull; struct slab *first_slab; unsigned long total_alloc; unsigned long total_freed; unsigned long kma_alloc; unsigned long kma_free; unsigned int objsz; unsigned int last_slab; } *

variable_types:
l
struct list_head *

variable_types:
buf
void *

return_type: struct slab { struct list_head { struct list_head *prev; } l; void *first_element; unsigned int objcount; unsigned int objused; union { unsigned char usedb[]; unsigned long used[]; }; } *


repo: acceso/jOS

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

if ( *(_QWORD **)(a1 + 32) != a2 )
{
list_del(a2);
++*(_QWORD *)(a1 + 64);
result = kma_free(a2);
}
return result;
}

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

if ( *(_QWORD **)(a1 + 32) != a2 )
{
list_del(a2);
++*(_QWORD *)(a1 + 64);
result = func30(a2);
}
return result;
}

original_code:
static void kcache_free_slab(struct kcache *cache, struct slab *slab)
{
 if (slab == cache->first_slab)
  return;
 list_del(&slab->l);
 cache->kma_free++;
 kma_free(slab);
}

variable_types: struct kcache { struct list_head { struct list_head *prev; } slabs_full; struct list_head slabs_notfull; struct slab { struct list_head l; void *first_element; unsigned int objcount; unsigned int objused; union { unsigned char usedb[]; unsigned long used[]; }; } *first_slab; unsigned long total_alloc; unsigned long total_freed; unsigned long kma_alloc; unsigned long kma_free; unsigned int objsz; unsigned int last_slab; } *

variable_types:
slab
struct slab *

return_type: void

user_defined_types: struct kcache { struct list_head slabs_full; struct list_head slabs_notfull; struct slab *first_slab; unsigned long total_alloc; unsigned long total_freed; unsigned long kma_alloc; unsigned long kma_free; unsigned int objsz; unsigned int last_slab; }


decompiled_code:
__int64 __fastcall bitscan_right(__int64 _RDI)
{
__int64 result; // rax

if ( !_RDI )
return 0xFFFFFFFFLL;
__asm { tzcnt rax, rdi }
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 _RDI)
{
__int64 result; // rax

if ( !_RDI )
return 0xFFFFFFFFLL;
__asm { tzcnt rax, rdi }
return result;
}

original_code:
inline static s8 bitscan_right(u64 word)
{
 if (word == 0)
  return -1;
 return __builtin_ctzl(word);
}

canonical_original_code:
inline static char bitscan_right(unsigned long word)
{
 if (word == 0)
  return -1;
 return __builtin_ctzl(word);
}

variable_types:
word
unsigned long

return_type: char


decompiled_code:
__int64 __fastcall kcache_free(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rbp
int v3; // edx
unsigned int v4; // ecx

v2 = kcache_get_slab(a1, a1 + 16, a2);
if ( !v2 && (v2 = kcache_get_slab(a1, a1, a2)) == 0 )
return 0;
bitclearptr(v2 + 32, (__int64)(a2 - *(_QWORD *)(v2 + 16)) / *(unsigned int *)(a1 + 72));
--*(_DWORD *)(v2 + 28);
++*(_QWORD *)(a1 + 48);
v3 = *(_DWORD *)(v2 + 28);
if ( v3 )
{
v4 = 1;
if ( v3 == *(_DWORD *)(v2 + 24) - 1 )
{
list_del((_QWORD *)v2);
list_add(a1 + 16, (_QWORD *)v2);
v4 = 1;
}
}
else
{
kcache_free_slab(a1, (_QWORD *)v2);
v4 = 1;
}
return v4;
}

original_code:
u8 kcache_free(struct kcache *cache, void *buf)
{
 struct slab *slab;
 slab = kcache_get_slab(cache, &cache->slabs_notfull, buf);
 if (slab == ((void *)0)) {
  slab = kcache_get_slab(cache, &cache->slabs_full, buf);
  if (slab == ((void *)0))
   return 0;
 }
 bitclearptr(slab->usedb, (buf - slab->first_element) / cache->objsz);
 slab->objused--;
 cache->total_freed++;
 if (slab->objused == 0)
  kcache_free_slab(cache, slab);
 else if (slab->objused == slab->objcount - 1) {
  list_del(&slab->l);
  list_add(&cache->slabs_notfull, &slab->l);
 }
 return 1;
}

canonical_original_code:
unsigned char kcache_free(struct kcache *cache, void *buf)
{
 struct slab *slab;
 slab = kcache_get_slab(cache, &cache->slabs_notfull, buf);
 if (slab == ((void *)0)) {
  slab = kcache_get_slab(cache, &cache->slabs_full, buf);
  if (slab == ((void *)0))
   return 0;
 }
 bitclearptr(slab->usedb, (buf - slab->first_element) / cache->objsz);
 slab->objused--;
 cache->total_freed++;
 if (slab->objused == 0)
  kcache_free_slab(cache, slab);
 else if (slab->objused == slab->objcount - 1) {
  list_del(&slab->l);
  list_add(&cache->slabs_notfull, &slab->l);
 }
 return 1;
}

variable_types: struct slab { struct list_head { struct list_head *prev; } l; void *first_element; unsigned int objcount; unsigned int objused; union { unsigned char usedb[]; unsigned long used[]; }; } *

return_type: unsigned char

user_defined_types: struct slab { struct list_head l; void *first_element; unsigned int objcount; unsigned int objused; union { unsigned char usedb[]; unsigned long used[]; }; }


original_code:
u64 get_mm_range(void **addr, u16 n)
{
 mboot_mmap_info *mmap;
 u8 i = 0;
 mmap = (mboot_mmap_info *)((void *)(((u64)mbi->mmap_addr) + 0xffff800000000000));
 while ((void *)mmap < ((void *)(((u64)mbi->mmap_addr) + 0xffff800000000000)) + mbi->mmap_length) {
  if (mmap->type == 1 && i++ == n) {
   *addr = (void *)mmap->addr;
   return mmap->len;
  }
  mmap = (mboot_mmap_info *)((u64)mmap + mmap->size
   + sizeof(mmap->size));
 }
 return 0;
}

canonical_original_code:
unsigned long get_mm_range(void **addr, unsigned short n)
{
 struct mboot_mmap_info *mmap;
 unsigned char i = 0;
 mmap = (struct mboot_mmap_info *)((void *)(((unsigned long)mbi->mmap_addr) + 0xffff800000000000));
 while ((void *)mmap < ((void *)(((unsigned long)mbi->mmap_addr) + 0xffff800000000000)) + mbi->mmap_length) {
  if (mmap->type == 1 && i++ == n) {
   *addr = (void *)mmap->addr;
   return mmap->len;
  }
  mmap = (struct mboot_mmap_info *)((unsigned long)mmap + mmap->size
   + sizeof(mmap->size));
 }
 return 0;
}

variable_types:
addr
void **

variable_types:
n
unsigned short

variable_types: struct mboot_mmap_info { unsigned int size; unsigned long addr; unsigned long len; unsigned int type; } *

variable_types:
i
unsigned char

return_type: unsigned long


oom

decompiled_code:
__int64 __fastcall oom(const char *a1)
{
kprintf("Out of memory: %s\n", a1);
return kpanic(":(");
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
kprintf("Out of memory: %s\n", a1);
return kpanic(":(");
}

original_code:
void oom(const char *str)
{
 kprintf("Out of memory: %s\n", str);
 kpanic(":(");
}

canonical_original_code:
void oom(char *str)
{
 kprintf("Out of memory: %s\n", str);
 kpanic(":(");
}

variable_types:
str
char *


decompiled_code:
__int64 init_memory()
{
mbi = *(&mbi32 - 0x200000000000LL) - 0x800000000000LL;
kprintf("%i lower and %i upper KB detected.\n", *(unsigned int *)(mbi + 4), *(unsigned int *)(mbi + 8));
if ( (*(_BYTE *)mbi & 1) == 0 )
kpanic("Can't detect memory!\n");
build_page_frames();
return kma_init();
}

canonical_decompiled_code:
__int64 func2()
{
mbi = *(&mbi32 - 0x200000000000LL) - 0x800000000000LL;
kprintf("%i lower and %i upper KB detected.\n", *(unsigned int *)(mbi + 4), *(unsigned int *)(mbi + 8));
if ( (*(_BYTE *)mbi & 1) == 0 )
kpanic("Can't detect memory!\n");
build_page_frames();
return kma_init();
}

original_code:
void init_memory(void)
{
 mbi = (mboot_info *)((void *)(((u64)*(u32 *)((void *)(((u64)&mbi32) + 0xffff800000000000))) + 0xffff800000000000));
 kprintf("%i lower and %i upper KB detected.\n",
  mbi->mem_lower, mbi->mem_upper);
 if ((mbi->flags & (1 << 0)) == 0x0)
  kpanic("Can't detect memory!\n");
 build_page_frames();
 kma_init();
}

canonical_original_code:
void init_memory()
{
 mbi = (struct mboot_info *)((void *)(((u64)*(unsigned int *)((void *)(((u64)&mbi32) + 0xffff800000000000))) + 0xffff800000000000));
 kprintf("%i lower and %i upper KB detected.\n",
  mbi->mem_lower, mbi->mem_upper);
 if ((mbi->flags & (1 << 0)) == 0x0)
  kpanic("Can't detect memory!\n");
 build_page_frames();
 kma_init();
}

user_defined_types: struct mboot_info { unsigned int flags; unsigned int mem_lower; unsigned int mem_upper; unsigned int boot_device; unsigned int cmdline; unsigned int mods_count; unsigned int mods_addr; unsigned int a; unsigned int mmap_length; unsigned int mmap_addr; unsigned int drives_length; unsigned int drives_addr; unsigned int config_table; unsigned int boot_loader_name; unsigned int apm_table; }


iget

original_code:
struct inode *iget(struct super *sb, size_t inum)
{
 struct inode *ino;
 for (ino = (typeof (*ino) *)((char *)((&sb->icache)->next) - __builtin_offsetof (typeof (*ino), l)); &((ino)->l) != (&sb->icache); ino = (typeof (*ino) *)((char *)((ino)->l.next) - __builtin_offsetof (typeof (*ino), l))) {
  if (ino->num == inum) {
   ino->count++;
   return ino;
  }
 }
 ino = xkmallocf(sizeof(struct inode), __func__);
 ino->num = inum;
 ino->count = 0;
 list_add(&sb->icache, &ino->l);
 return ino;
}

canonical_original_code:
struct inode *iget(struct super *sb, unsigned long inum)
{
 struct inode *ino;
 for (ino = (typeof (*ino) *)((char *)((&sb->icache)->next) - __builtin_offsetof (typeof (*ino), l)); &((ino)->l) != (&sb->icache); ino = (typeof (*ino) *)((char *)((ino)->l.next) - __builtin_offsetof (typeof (*ino), l))) {
  if (ino->num == inum) {
   ino->count++;
   return ino;
  }
 }
 ino = xkmallocf(sizeof(struct inode), __func__);
 ino->num = inum;
 ino->count = 0;
 list_add(&sb->icache, &ino->l);
 return ino;
}

variable_types:
sb
struct super *

variable_types:
inum
unsigned long

variable_types: struct inode { struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head { struct list_head *prev; } bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; } *(*block_read)(struct inode *, long); } *ops; void *priv; } *

user_defined_types: struct inode { struct super *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops *ops; void *priv; }

user_defined_types: struct super { struct dev_t dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head bcache; struct list_head icache; struct super_ops *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; }

user_defined_types: struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead *(*block_read)(struct inode *, long); }


iput

decompiled_code:
__int64 __fastcall iput(__int64 a1)
{
list_del((_QWORD *)(a1 + 80));
return kfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
list_del((_QWORD *)(a1 + 80));
return kfree(a1);
}

original_code:
void iput(struct inode *inode)
{
 list_del(&inode->l);
 kfree(inode);
}

user_defined_types: struct dev_t { unsigned int major; unsigned int minor; }

user_defined_types: struct list_head { struct list_head *prev; }

user_defined_types: struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); }

user_defined_types: struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; }


bmap

original_code:
size_t bmap(struct inode *inode, off_t offset)
{
 return inode->ops->bmap(inode, offset);
}

canonical_original_code:
unsigned long bmap(struct inode *inode, long offset)
{
 return inode->ops->bmap(inode, offset);
}

variable_types: offset long


decompiled_code:
__int64 __fastcall ext2_block_read(_QWORD *a1)
{
__int64 v1; // rsi
__int64 result; // rax

v1 = bmap();
result = 0LL;
if ( v1 )
result = bread(*a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // rsi
__int64 result; // rax

v1 = bmap();
result = 0LL;
if ( v1 )
result = bread(*a1);
return result;
}

original_code:
static struct bhead *ext2_block_read(struct inode *inode, off_t offset)
{
 size_t blk;
 blk = bmap(inode, offset);
 if (blk == 0)
  return ((void *)0);
 return bread(inode->sb, blk);
}

canonical_original_code:
static struct bhead *ext2_block_read(struct inode *inode, long offset)
{
 unsigned long blk;
 blk = bmap(inode, offset);
 if (blk == 0)
  return ((void *)0);
 return bread(inode->sb, blk);
}

variable_types: struct inode { struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead *(*block_read)(struct inode *, long); } *ops; void *priv; } *

variable_types:
blk
unsigned long

return_type: struct bhead { struct list_head { struct list_head *prev; } l; unsigned long bnum; void *data; unsigned char count; } *


decompiled_code:
__int64 __fastcall ext2_bmap(__int64 *a1, unsigned __int64 a2)
{
__int64 v2; // r8
__int64 v3; // rdi
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rbx
unsigned __int64 v8; // rcx
__int64 result; // rax

v2 = a1[14];
v3 = *a1;
v4 = *(_QWORD *)(v3 + 8);
v5 = a2 / v4;
v6 = a2 % v4;
v7 = a2 / v4;
if ( a2 / v4 <= 0xB )
return *(unsigned int *)(v2 + 4 * v5);
v8 = (v4 >> 2) + 12;
if ( v8 <= v5 )
{
kpanic("No double nor triply indirect block supported yet\n", a2, v6, v8, v2);
result = 0LL;
}
else
{
result = 0LL;
if ( *(_DWORD *)(v2 + 48) )
result = *(unsigned int *)(*(_QWORD *)(bread(v3) + 24) + 4 * v7 - 48);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, unsigned __int64 a2)
{
__int64 v2; // r8
__int64 v3; // rdi
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rbx
unsigned __int64 v8; // rcx
__int64 result; // rax

v2 = a1[14];
v3 = *a1;
v4 = *(_QWORD *)(v3 + 8);
v5 = a2 / v4;
v6 = a2 % v4;
v7 = a2 / v4;
if ( a2 / v4 <= 0xB )
return *(unsigned int *)(v2 + 4 * v5);
v8 = (v4 >> 2) + 12;
if ( v8 <= v5 )
{
kpanic("No double nor triply indirect block supported yet\n", a2, v6, v8, v2);
result = 0LL;
}
else
{
result = 0LL;
if ( *(_DWORD *)(v2 + 48) )
result = *(unsigned int *)(*(_QWORD *)(bread(v3) + 24) + 4 * v7 - 48);
}
return result;
}

original_code:
static size_t ext2_bmap(struct inode *inode, off_t offset)
{
 struct ext2_inode_priv *ipriv = inode->priv;
 size_t nblock;
 struct bhead *block;
 nblock = offset / inode->sb->blocksize;
 if (nblock < 12)
  return ipriv->blocks[nblock];
 else if (nblock < 12 + (inode->sb->blocksize >> 2)) {
  if (ipriv->blocks[12] == 0)
   return 0;
  block = bread(inode->sb, ipriv->blocks[12]);
  return *(u32 *)(block->data + 4 * (nblock - 12));
 }
 else
  kpanic("No double nor triply indirect block supported yet\n");
 return 0;
}

canonical_original_code:
static unsigned long ext2_bmap(struct inode *inode, long offset)
{
 struct ext2_inode_priv *ipriv = inode->priv;
 unsigned long nblock;
 struct bhead *block;
 nblock = offset / inode->sb->blocksize;
 if (nblock < 12)
  return ipriv->blocks[nblock];
 else if (nblock < 12 + (inode->sb->blocksize >> 2)) {
  if (ipriv->blocks[12] == 0)
   return 0;
  block = bread(inode->sb, ipriv->blocks[12]);
  return *(unsigned int *)(block->data + 4 * (nblock - 12));
 }
 else
  kpanic("No double nor triply indirect block supported yet\n");
 return 0;
}

variable_types: struct ext2_inode_priv { unsigned int blocks[15]; } *

variable_types:
nblock
unsigned long

variable_types: struct bhead { struct list_head { struct list_head *prev; } l; unsigned long bnum; void *data; unsigned char count; } *


original_code:
struct inode *ext2_inode_read(struct super *sb, u64 inum)
{
 struct ext2_super_ext2 *sbpriv = sb->priv;
 size_t bgroup;
 struct bhead *buf;
 struct ext2_bg_desc *e2desc;
 size_t iindex;
 struct ext2_inode *e2ino;
 struct inode *inode;
 struct ext2_inode_priv *ipriv;
 u8 i;
 if (inum > sbpriv->inodes_max)
  return ((void *)0);
 bgroup = (inum - 1) / sbpriv->inodes_per_group;
 buf = ext2_bread (sb, sbpriv->bgroup_base
  + bgroup / (sb->blocksize / sizeof(struct ext2_bg_desc)));
 e2desc = (struct ext2_bg_desc *)buf->data;
 e2desc += bgroup;
 iindex = (inum - 1) % sbpriv->inodes_per_group;
 buf = ext2_bread(sb, e2desc->bg_inode_table + (iindex * sbpriv->inode_size) / sb->blocksize);
 e2ino = (struct ext2_inode *)buf->data;
 e2ino += (iindex % (sb->blocksize / sbpriv->inode_size));
 inode = iget(sb, inum);
 if (inode->count > 0)
  return inode;
 inode->count++;
 inode->sb = sb;
 inode->mode = e2ino->i_mode;
 inode->nlinks = e2ino->i_links_count;
 inode->uid = e2ino->i_uid;
 inode->gid = e2ino->i_gid;
 inode->filesize = e2ino->i_size;
 inode->nblocks = e2ino->i_blocks;
 inode->atime = e2ino->i_atime;
 inode->mtime = e2ino->i_mtime;
 inode->ctime = e2ino->i_ctime;
 inode->covered = ((void *)0);
 inode->flags = e2ino->i_flags;
 inode->priv = xkmallocf(sizeof(struct ext2_inode_priv), __func__);
 ipriv = (struct ext2_inode_priv *)inode->priv;
 for (i = 0; i < 15; i++)
  ipriv->blocks[i] = e2ino->i_block[i];
 inode->ops = &ext2_inode_ops;
 return inode;
}

canonical_original_code:
struct inode *ext2_inode_read(struct super *sb, unsigned long inum)
{
 struct ext2_super_ext2 *sbpriv = sb->priv;
 unsigned long bgroup;
 struct bhead *buf;
 struct ext2_bg_desc *e2desc;
 unsigned long iindex;
 struct ext2_inode *e2ino;
 struct inode *inode;
 struct ext2_inode_priv *ipriv;
 unsigned char i;
 if (inum > sbpriv->inodes_max)
  return ((void *)0);
 bgroup = (inum - 1) / sbpriv->inodes_per_group;
 buf = ext2_bread (sb, sbpriv->bgroup_base
  + bgroup / (sb->blocksize / sizeof(struct ext2_bg_desc)));
 e2desc = (struct ext2_bg_desc *)buf->data;
 e2desc += bgroup;
 iindex = (inum - 1) % sbpriv->inodes_per_group;
 buf = ext2_bread(sb, e2desc->bg_inode_table + (iindex * sbpriv->inode_size) / sb->blocksize);
 e2ino = (struct ext2_inode *)buf->data;
 e2ino += (iindex % (sb->blocksize / sbpriv->inode_size));
 inode = iget(sb, inum);
 if (inode->count > 0)
  return inode;
 inode->count++;
 inode->sb = sb;
 inode->mode = e2ino->i_mode;
 inode->nlinks = e2ino->i_links_count;
 inode->uid = e2ino->i_uid;
 inode->gid = e2ino->i_gid;
 inode->filesize = e2ino->i_size;
 inode->nblocks = e2ino->i_blocks;
 inode->atime = e2ino->i_atime;
 inode->mtime = e2ino->i_mtime;
 inode->ctime = e2ino->i_ctime;
 inode->covered = ((void *)0);
 inode->flags = e2ino->i_flags;
 inode->priv = xkmallocf(sizeof(struct ext2_inode_priv), __func__);
 ipriv = (struct ext2_inode_priv *)inode->priv;
 for (i = 0; i < 15; i++)
  ipriv->blocks[i] = e2ino->i_block[i];
 inode->ops = &ext2_inode_ops;
 return inode;
}

variable_types: struct ext2_super_ext2 { unsigned int nblocks; unsigned long bgroup_base; unsigned short inode_size; unsigned short bg_desc_per_block; unsigned int inodes_per_group; unsigned int inodes_max; } *

variable_types:
bgroup
unsigned long

variable_types: struct ext2_bg_desc { unsigned int bg_block_bitmap; unsigned int bg_inode_bitmap; unsigned int bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; char pad[14]; } *

variable_types:
iindex
unsigned long

variable_types: struct ext2_inode { unsigned short i_mode; unsigned short i_uid; unsigned int i_size; unsigned int i_atime; unsigned int i_ctime; unsigned int i_mtime; unsigned int i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned int i_blocks; unsigned int i_flags; unsigned int i_osdl; unsigned int i_block[15]; unsigned int i_generation; unsigned int i_file_acl; unsigned int i_dir_acl; unsigned int i_faddr; char i_osd2[12]; } *

return_type: struct inode { struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head { struct list_head *prev; } bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; } *(*block_read)(struct inode *, long); } *ops; void *priv; } *

user_defined_types: struct ext2_inode_priv { unsigned int blocks[15]; }


decompiled_code:
__int64 __fastcall ext2_lookup(__int64 a1, const char *a2, unsigned __int8 a3)
{
__int64 v3; // rbp
size_t v5; // r14
unsigned int *v6; // rbx
__int64 v7; // rax
__int64 v9; // rax
unsigned __int64 v10; // [rsp+10h] [rbp-48h]
__int64 v11; // [rsp+18h] [rbp-40h]

v3 = 0LL;
if ( (*(_WORD *)(a1 + 16) & 0xF000) == 0x4000 )
{
v10 = 0LL;
v11 = 0LL;
v5 = a3;
while ( 1 )
{
v9 = ext2_block_read((_QWORD *)a1);
v3 = v9;
if ( !v9 )
break;
v6 = *(unsigned int **)(v9 + 24);
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( v6 < (unsigned int *)((char *)v6 + v7) )
{
while ( *((_BYTE *)v6 + 6) != a3 || (unsigned __int8)strncmp(a2, (const char *)v6 + 8, v5) )
{
v6 = (unsigned int *)((char *)v6 + *((unsigned __int16 *)v6 + 2));
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( (unsigned __int64)v6 >= *(_QWORD *)(v3 + 24) + v7 )
goto LABEL_8;
}
return ext2_inode_read(*(_QWORD *)a1, *v6);
}
LABEL_8:
v10 += v7;
++v11;
if ( *(_QWORD *)(a1 + 32) < v10 )
return 0LL;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, unsigned __int8 a3)
{
__int64 v3; // rbp
size_t v5; // r14
unsigned int *v6; // rbx
__int64 v7; // rax
__int64 v9; // rax
unsigned __int64 v10; // [rsp+10h] [rbp-48h]
__int64 v11; // [rsp+18h] [rbp-40h]

v3 = 0LL;
if ( (*(_WORD *)(a1 + 16) & 0xF000) == 0x4000 )
{
v10 = 0LL;
v11 = 0LL;
v5 = a3;
while ( 1 )
{
v9 = func0((_QWORD *)a1);
v3 = v9;
if ( !v9 )
break;
v6 = *(unsigned int **)(v9 + 24);
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( v6 < (unsigned int *)((char *)v6 + v7) )
{
while ( *((_BYTE *)v6 + 6) != a3 || (unsigned __int8)strncmp(a2, (const char *)v6 + 8, v5) )
{
v6 = (unsigned int *)((char *)v6 + *((unsigned __int16 *)v6 + 2));
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( (unsigned __int64)v6 >= *(_QWORD *)(v3 + 24) + v7 )
goto LABEL_8;
}
return func2(*(_QWORD *)a1, *v6);
}
LABEL_8:
v10 += v7;
++v11;
if ( *(_QWORD *)(a1 + 32) < v10 )
return 0LL;
}
}
return v3;
}

original_code:
static struct inode *ext2_lookup(struct inode *inode, const char *name, u8 len)
{
 size_t block = 0;
 size_t offset = 0;
 struct bhead *buffer;
 struct ext2_dirent *dirent;
 if (!(((inode->mode) & 0170000) == 0040000))
  return ((void *)0);
 while (offset <= inode->filesize) {
  buffer = ext2_block_read(inode, block);
  if (buffer == ((void *)0))
   break;
  dirent = buffer->data;
  while ((void *)dirent < buffer->data + inode->sb->blocksize) {
   if (len == dirent->name_len &&
    strncmp(name, dirent->name, len) == 0)
    return ext2_inode_read(inode->sb, dirent->inode);
   dirent = (void *)dirent + dirent->rec_len;
  }
  offset += inode->sb->blocksize;
  block++;
 }
 return ((void *)0);
}

canonical_original_code:
static struct inode *ext2_lookup(struct inode *inode, char *name, unsigned char len)
{
 unsigned long block = 0;
 unsigned long offset = 0;
 struct bhead *buffer;
 struct ext2_dirent *dirent;
 if (!(((inode->mode) & 0170000) == 0040000))
  return ((void *)0);
 while (offset <= inode->filesize) {
  buffer = ext2_block_read(inode, block);
  if (buffer == ((void *)0))
   break;
  dirent = buffer->data;
  while ((void *)dirent < buffer->data + inode->sb->blocksize) {
   if (len == dirent->name_len &&
    strncmp(name, dirent->name, len) == 0)
    return ext2_inode_read(inode->sb, dirent->inode);
   dirent = (void *)dirent + dirent->rec_len;
  }
  offset += inode->sb->blocksize;
  block++;
 }
 return ((void *)0);
}

variable_types:
inode
struct inode *

variable_types:
name
char *

variable_types:
len
unsigned char

variable_types:
block
unsigned long

variable_types:
offset
unsigned long

variable_types: struct ext2_dirent { unsigned int inode; unsigned short rec_len; unsigned char name_len; unsigned char file_type; char name[256]; } *


getblk

original_code:
struct bhead *getblk(struct super *sb, size_t block)
{
 struct bhead *bh;
 for (bh = (typeof (*bh) *)((char *)((&sb->bcache)->next) - __builtin_offsetof (typeof (*bh), l)); &((bh)->l) != (&sb->bcache); bh = (typeof (*bh) *)((char *)((bh)->l.next) - __builtin_offsetof (typeof (*bh), l))) {
  if (bh->bnum == block) {
   bh->count++;
   return bh;
  }
 }
 bh = xkmallocf(sizeof(struct bhead), __func__);
 bh->bnum = block;
 bh->data = xkmallocf(sb->blocksize, __func__);
 if (bh->data == ((void *)0)) {
  kfree(bh);
  return ((void *)0);
 }
 bh->count = 0;
 list_add(&sb->bcache, &bh->l);
 return bh;
}

canonical_original_code:
struct bhead *getblk(struct super *sb, unsigned long block)
{
 struct bhead *bh;
 for (bh = (typeof (*bh) *)((char *)((&sb->bcache)->next) - __builtin_offsetof (typeof (*bh), l)); &((bh)->l) != (&sb->bcache); bh = (typeof (*bh) *)((char *)((bh)->l.next) - __builtin_offsetof (typeof (*bh), l))) {
  if (bh->bnum == block) {
   bh->count++;
   return bh;
  }
 }
 bh = xkmallocf(sizeof(struct bhead), __func__);
 bh->bnum = block;
 bh->data = xkmallocf(sb->blocksize, __func__);
 if (bh->data == ((void *)0)) {
  kfree(bh);
  return ((void *)0);
 }
 bh->count = 0;
 list_add(&sb->bcache, &bh->l);
 return bh;
}

variable_types: struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode { struct super *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead *(*block_read)(struct inode *, long); } *ops; void *priv; } *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *


bread

original_code:
struct bhead *bread(struct super *sb, size_t block)
{
 struct bhead *bh;
 bh = getblk(sb, block);
 if (bh == ((void *)0))
  return ((void *)0);
 if (bh->count > 0)
  return bh;
 bh->count++;
 if (breadu(&sb->dev, block * sb->blocksize / sb->blocksizephys,
  bh->data, sb->blocksize) == 0)
  return ((void *)0);
 return bh;
}

canonical_original_code:
struct bhead *bread(struct super *sb, unsigned long block)
{
 struct bhead *bh;
 bh = getblk(sb, block);
 if (bh == ((void *)0))
  return ((void *)0);
 if (bh->count > 0)
  return bh;
 bh->count++;
 if (breadu(&sb->dev, block * sb->blocksize / sb->blocksizephys,
  bh->data, sb->blocksize) == 0)
  return ((void *)0);
 return bh;
}


decompiled_code:
__int64 init_ext2()
{
return fs_register(ext2);
}

canonical_decompiled_code:
__int64 func3()
{
return fs_register(ext2);
}

original_code:
void init_ext2(void)
{
 fs_register(&ext2);
}

canonical_original_code:
void init_ext2()
{
 fs_register(&ext2);
}


iowait

decompiled_code:
void iowait()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static inline void iowait(void)
{
 asm volatile(
  "jmp 1f\n\t"
  "1:\n\t"
  "jmp 1f\n\t"
  "1:\n\t"
  );
}

canonical_original_code:
static inline void iowait()
{
 asm volatile(
  "jmp 1f\n\t"
  "1:\n\t"
  "jmp 1f\n\t"
  "1:\n\t"
  );
}


decompiled_code:
__int64 lapic_eoi()
{
return lapic_write(0xB0u, 0);
}

canonical_decompiled_code:
__int64 func3()
{
return func2(0xB0u, 0);
}

original_code:
static inline void lapic_eoi(void)
{
 lapic_write(0xb0, 0);
}

canonical_original_code:
static inline void lapic_eoi()
{
 lapic_write(0xb0, 0);
}


decompiled_code:
// positive sp value has been detected, the output may be wrong!
void do_keyboard()
{
unsigned __int8 v0; // al
char v1; // dl
_BYTE *v2; // rcx

v0 = inb(0x60u);
if ( v0 != 0xAA )
{
if ( v0 <= 0xAAu )
{
if ( v0 == 42 || v0 == 54 )
{
keyb |= 1u;
}
else if ( (v0 & 0x80u) == 0 )
{
if ( (keyb & 1) != 0 )
v1 = kb_en_caps[v0];
else
v1 = kb_en[v0];
if ( v1 == 8 )
{
--kbdbptr;
((void (__fastcall *)(void *, __int64))kprintf)(&unk_510, 8LL);
}
else
{
v2 = (_BYTE *)kbdbptr;
if ( kbdbptr - (__int64)&kbdb <= 255 )
{
++kbdbptr;
*v2 = v1;
}
((void (__fastcall *)(void *, _QWORD))kprintf)(&unk_510, (unsigned int)v1);
}
}
LABEL_7:
lapic_eoi();
__asm { iretq }
JUMPOUT(0xCFLL);
}
if ( v0 != 0xB6 )
goto LABEL_7;
}
keyb &= 0xFEu;
goto LABEL_7;
}

canonical_decompiled_code:
void func4()
{
unsigned __int8 v0; // al
char v1; // dl
_BYTE *v2; // rcx

v0 = func1(0x60u);
if ( v0 != 0xAA )
{
if ( v0 <= 0xAAu )
{
if ( v0 == 42 || v0 == 54 )
{
keyb |= 1u;
}
else if ( (v0 & 0x80u) == 0 )
{
if ( (keyb & 1) != 0 )
v1 = kb_en_caps[v0];
else
v1 = kb_en[v0];
if ( v1 == 8 )
{
--kbdbptr;
((void (__fastcall *)(void *, __int64))kprintf)(&unk_510, 8LL);
}
else
{
v2 = (_BYTE *)kbdbptr;
if ( kbdbptr - (__int64)&kbdb <= 255 )
{
++kbdbptr;
*v2 = v1;
}
((void (__fastcall *)(void *, _QWORD))kprintf)(&unk_510, (unsigned int)v1);
}
}
LABEL_7:
func3();
__asm { iretq }
JUMPOUT(0xCFLL);
}
if ( v0 != 0xB6 )
goto LABEL_7;
}
keyb &= 0xFEu;
goto LABEL_7;
}

original_code:
__attribute__((aligned(16))) static void do_keyboard(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq $0\n\t" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 u8 scancode = inb(0x60);
 switch (scancode) {
 case 0x2a:
 case 0x36:
  keyb.shift = 1;
  break;
 case 0xaa:
 case 0xb6:
  keyb.shift = 0;
  break;
 default: {
  char c;
  if (scancode & 0x80)
   break;
  if (keyb.shift)
   c = kb_en_caps[scancode];
  else
   c = kb_en[scancode];
  switch (c) {
  case '\b':
   kbdbptr--;
   kprintf("%c", c);
   break;
  default:
   if (kbdbptr - kbdb < 256)
    *kbdbptr++ = c;
   kprintf("%c", c);
  }
 }
 }
 lapic_eoi();
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "addq $8, %rsp\n\t" "iretq\n\t" );
}

canonical_original_code:
static void do_keyboard(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq $0\n\t" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 unsigned char scancode = inb(0x60);
 switch (scancode) {
 case 0x2a:
 case 0x36:
  keyb.shift = 1;
  break;
 case 0xaa:
 case 0xb6:
  keyb.shift = 0;
  break;
 default: {
  char c;
  if (scancode & 0x80)
   break;
  if (keyb.shift)
   c = kb_en_caps[scancode];
  else
   c = kb_en[scancode];
  switch (c) {
  case '\b':
   kbdbptr--;
   kprintf("%c", c);
   break;
  default:
   if (kbdbptr - kbdb < 256)
    *kbdbptr++ = c;
   kprintf("%c", c);
  }
 }
 }
 lapic_eoi();
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "addq $8, %rsp\n\t" "iretq\n\t" );
}

variable_types: struct intr_frame { unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rdi; unsigned long rsi; unsigned long rbx; unsigned long rdx; unsigned long rcx; unsigned long rax; unsigned int ecode; unsigned int pad4; unsigned long rip; unsigned char cs; unsigned char pad0; unsigned int pad1; unsigned long rflags; unsigned long rsp; unsigned char ss; unsigned char pad2; unsigned int pad3; }

variable_types:
scancode
unsigned char

variable_types: c char


decompiled_code:
__int64 init_keyboard()
{
kbdbptr = (__int64)&kbdb;
return intr_install_handler(1LL, do_keyboard);
}

canonical_decompiled_code:
__int64 func5()
{
kbdbptr = (__int64)&kbdb;
return intr_install_handler(1LL, do_keyboard);
}

original_code:
void init_keyboard(void)
{
 kbdbptr = kbdb;
 intr_install_handler(1, do_keyboard);
 return;
}

canonical_original_code:
void init_keyboard()
{
 kbdbptr = kbdb;
 intr_install_handler(1, do_keyboard);
 return;
}


div

decompiled_code:
__int64 __fastcall div(unsigned __int64 a1, unsigned int a2)
{
return (unsigned int)(a1 / a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, unsigned int a2)
{
return (unsigned int)(a1 / a2);
}

canonical_original_code:
inline static unsigned long div(unsigned long n, unsigned int d)
{
 unsigned int q; unsigned int r;
 asm (
  "divl %[n]\n\t"
  : "=d" (r), "=a" (q)
  : "0" (n >> 32), "1" (n), [n] "rm" (d));
 return q;
}

variable_types:
n
unsigned long

variable_types:
d
unsigned int

variable_types:
q
unsigned int

variable_types:
r
unsigned int


yield

decompiled_code:
void yield()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
static inline void yield(void)
{
 asm volatile("nop\n\t");
}

canonical_original_code:
static inline void yield()
{
 asm volatile("nop\n\t");
}


ticks

decompiled_code:
unsigned __int64 ticks()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func4()
{
return __rdtsc();
}

original_code:
static inline u64 ticks(void)
{
 u32 a;
 u32 d;
 asm volatile(
  "rdtsc\n\t"
  : "=a"(a), "=d"(d));
 return ((u64)d << 32) | a;
}

canonical_original_code:
static inline unsigned long ticks()
{
 unsigned int a;
 unsigned int d;
 asm volatile(
  "rdtsc\n\t"
  : "=a"(a), "=d"(d));
 return ((unsigned long)d << 32) | a;
}

variable_types:
a
unsigned int


decompiled_code:
__int64 __fastcall init_lapic_timer(__int64 a1, unsigned int a2)
{
int v2; // ebx
unsigned int v3; // edi
int v4; // eax
__int64 v5; // rax

intr_install_handler(66LL, a1);
lapic_write(0x3E0u, 11);
lapic_write(0x320u, 131138);
lapic_write(0x380u, -1);
v2 = lapic_get_current_count();
msleep(1u);
v3 = v2 - lapic_get_current_count();
sys[3] = v3;
v4 = div(1000 * v3, a2);
lapic_write(0x380u, v4);
v5 = div(v3, 0x3E8u);
return kprintf("External clock: %ldMhz\n", v5);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
int v2; // ebx
unsigned int v3; // edi
int v4; // eax
__int64 v5; // rax

intr_install_handler(66LL, a1);
func1(0x3E0u, 11);
func1(0x320u, 131138);
func1(0x380u, -1);
v2 = func7();
func6(1u);
v3 = v2 - func7();
sys[3] = v3;
v4 = func2(1000 * v3, a2);
func1(0x380u, v4);
v5 = func2(v3, 0x3E8u);
return kprintf("External clock: %ldMhz\n", v5);
}

original_code:
void init_lapic_timer(void *intr_handler, u32 hz)
{
 u32 lapictic;
 intr_install_handler(66, intr_handler);
 lapic_write(0x3e0, 0xb);
 lapic_write(0x320, (1 << 17) | 66);
 lapic_write(0x380, (u32)-1);
 lapictic = lapic_get_current_count();
 msleep(1);
 lapictic -= lapic_get_current_count();
 sys.busspeed = lapictic;
 lapic_write(0x380, div(lapictic * 1000, hz));
 kprintf("External clock: %ldMhz\n", div(lapictic, 1000));
 return;
}

canonical_original_code:
void init_lapic_timer(void *intr_handler, unsigned int hz)
{
 unsigned int lapictic;
 intr_install_handler(66, intr_handler);
 lapic_write(0x3e0, 0xb);
 lapic_write(0x320, (1 << 17) | 66);
 lapic_write(0x380, (u32)-1);
 lapictic = lapic_get_current_count();
 msleep(1);
 lapictic -= lapic_get_current_count();
 sys.busspeed = lapictic;
 lapic_write(0x380, div(lapictic * 1000, hz));
 kprintf("External clock: %ldMhz\n", div(lapictic, 1000));
 return;
}

variable_types:
hz
unsigned int

variable_types:
lapictic
unsigned int


repo: xant/wurfld

decompiled_code:
__int64 __fastcall open_socket(char *src, int a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-48h] BYREF
int optval[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

optval[0] = 1;
*_errno_location() = 22;
if ( !src )
return (unsigned int)-1;
if ( !*src || !a2 )
return (unsigned int)-1;
v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 != -1 )
{
setsockopt(v2, 1, 2, optval, 4u);
setsockopt(v3, 6, 1, optval, 4u);
if ( (unsigned int)string2sockaddr(src, a2, (__int64)&v5) == -1 || bind(v3, &v5, 0x10u) == -1 )
{
shutdown(v3, 2);
close(v3);
v3 = -1;
}
else
{
listen(v3, -1);
fcntl(v3, 2, 1LL);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, int a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-48h] BYREF
int optval[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

optval[0] = 1;
*_errno_location() = 22;
if ( !src )
return (unsigned int)-1;
if ( !*src || !a2 )
return (unsigned int)-1;
v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 != -1 )
{
setsockopt(v2, 1, 2, optval, 4u);
setsockopt(v3, 6, 1, optval, 4u);
if ( (unsigned int)func2(src, a2, (__int64)&v5) == -1 || bind(v3, &v5, 0x10u) == -1 )
{
shutdown(v3, 2);
close(v3);
v3 = -1;
}
else
{
listen(v3, -1);
fcntl(v3, 2, 1LL);
}
}
return v3;
}

original_code:
int
open_socket(const char *host, int port)
{
    int val = 1;
    struct sockaddr_in sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (host == ((void *)0) || strlen(host) == 0 || port == 0)
 return -1;
    sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1)
 return -1;
    setsockopt(sock, 1, 2, &val, sizeof(val));
    setsockopt(sock, IPPROTO_TCP, 1, &val, sizeof(val));
    if (string2sockaddr(host, port, &sockaddr) == -1
 || bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1) {
 shutdown(sock, SHUT_RDWR);
 close(sock);
 return -1;
    }
    listen(sock, -1);
    fcntl(sock, 2, 1);
    return sock;
}

canonical_original_code:
int open_socket(char *host, int port)
{
    int val = 1;
    struct sockaddr_in sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (host == ((void *)0) || strlen(host) == 0 || port == 0)
 return -1;
    sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1)
 return -1;
    setsockopt(sock, 1, 2, &val, sizeof(val));
    setsockopt(sock, IPPROTO_TCP, 1, &val, sizeof(val));
    if (string2sockaddr(host, port, &sockaddr) == -1
 || bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1) {
 shutdown(sock, SHUT_RDWR);
 close(sock);
 return -1;
    }
    listen(sock, -1);
    fcntl(sock, 2, 1);
    return sock;
}

variable_types:
host
char *

variable_types: port int

variable_types: val int

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

variable_types: sock int

return_type: int

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 { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall write_socket(int fd, __int64 a2, int a3)
{
int v4; // ebp
unsigned int v5; // er14
unsigned int v6; // eax
int *v8; // rax
char *v9; // rax

v4 = 0;
v5 = 0;
while ( 1 )
{
a3 -= v5;
v4 += v5;
v6 = write(fd, (const void *)(a2 + v4), a3);
v5 = v6;
if ( v6 == -1 )
break;
if ( a3 == v6 || !v6 )
return 0;
}
v8 = _errno_location();
v9 = strerror(*v8);
log_message(5LL, 0LL, "write on fd %d failed: %s", (unsigned int)fd, v9);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2, int a3)
{
int v4; // ebp
unsigned int v5; // er14
unsigned int v6; // eax
int *v8; // rax
char *v9; // rax

v4 = 0;
v5 = 0;
while ( 1 )
{
a3 -= v5;
v4 += v5;
v6 = write(fd, (const void *)(a2 + v4), a3);
v5 = v6;
if ( v6 == -1 )
break;
if ( a3 == v6 || !v6 )
return 0;
}
v8 = _errno_location();
v9 = strerror(*v8);
log_message(5LL, 0LL, "write on fd %d failed: %s", (unsigned int)fd, v9);
return v5;
}

original_code:
int write_socket(int fd, char *buf, int len) {
    int wb = 0;
    int ofx = 0;
    do {
        len -= wb;
        ofx += wb;
        wb = write(fd, buf+ofx, len);
        if (wb == -1) {
            if ((*__errno_location ()) != 4 || (*__errno_location ()) != 11) {
                do { log_message(5, 0, "write on fd %d failed: %s", fd, strerror((*__errno_location ()))); } while (0);
                return -1;
            }
            wb = 0;
        } else if (wb == 0) {
            break;
        }
    } while (wb != len);
    return 0;
}

variable_types: fd int

variable_types:
buf
char *

variable_types: len int

variable_types: wb int

variable_types: ofx int


decompiled_code:
__int64 __fastcall read_socket(unsigned int a1, void *a2, int *a3)
{
int v4; // eax
unsigned int v5; // er12
int *v7; // rax
char *v8; // rax

v4 = read(a1, a2, *a3);
if ( v4 == -1 )
{
v5 = -1;
v7 = _errno_location();
v8 = strerror(*v7);
log_message(5LL, 0LL, "Read on fd %d failed: %s", a1, v8);
}
else
{
*a3 = v4;
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, void *a2, int *a3)
{
int v4; // eax
unsigned int v5; // er12
int *v7; // rax
char *v8; // rax

v4 = read(a1, a2, *a3);
if ( v4 == -1 )
{
v5 = -1;
v7 = _errno_location();
v8 = strerror(*v7);
log_message(5LL, 0LL, "Read on fd %d failed: %s", a1, v8);
}
else
{
*a3 = v4;
v5 = 0;
}
return v5;
}

original_code:
int read_socket(int fd, char *buf, int *len) {
    int rb = 0;
    int to_read = *len;
    rb = read(fd, buf, to_read);
    if (rb == -1 && ((*__errno_location ()) != 4 || (*__errno_location ()) != 11)) {
        do { log_message(5, 0, "Read on fd %d failed: %s", fd, strerror((*__errno_location ()))); } while (0);
        return -1;
    }
    *len = rb;
    return 0;
}

variable_types:
len
int *

variable_types: rb int


decompiled_code:
__int64 __fastcall open_connection(char *src, unsigned int a2, unsigned int a3)
{
int v4; // eax
unsigned int v5; // ebx
__int64 v7[2]; // [rsp+0h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
int optval[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

optval[0] = 1;
*_errno_location() = 22;
if ( !src )
return (unsigned int)-1;
if ( !*src || !a2 )
return (unsigned int)-1;
v4 = socket(2, 1, 6);
v5 = v4;
if ( v4 != -1 )
{
setsockopt(v4, 6, 1, optval, 4u);
if ( a3 )
{
v7[0] = a3;
v7[1] = 0LL;
if ( setsockopt(v5, 1, 21, v7, 0x10u) == -1 || setsockopt(v5, 1, 20, v7, 0x10u) == -1 )
log_message(6LL, 0LL, "%s:%d: Failed to set timeout to %d\n", src, a2, a3);
}
if ( (unsigned int)string2sockaddr(src, a2, (__int64)&addr) == -1 || connect(v5, &addr, 0x10u) == -1 )
{
shutdown(v5, 2);
close(v5);
v5 = -1;
}
else
{
fcntl(v5, 2, 1LL);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src, unsigned int a2, unsigned int a3)
{
int v4; // eax
unsigned int v5; // ebx
__int64 v7[2]; // [rsp+0h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
int optval[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

optval[0] = 1;
*_errno_location() = 22;
if ( !src )
return (unsigned int)-1;
if ( !*src || !a2 )
return (unsigned int)-1;
v4 = socket(2, 1, 6);
v5 = v4;
if ( v4 != -1 )
{
setsockopt(v4, 6, 1, optval, 4u);
if ( a3 )
{
v7[0] = a3;
v7[1] = 0LL;
if ( setsockopt(v5, 1, 21, v7, 0x10u) == -1 || setsockopt(v5, 1, 20, v7, 0x10u) == -1 )
log_message(6LL, 0LL, "%s:%d: Failed to set timeout to %d\n", src, a2, a3);
}
if ( (unsigned int)func2(src, a2, (__int64)&addr) == -1 || connect(v5, &addr, 0x10u) == -1 )
{
shutdown(v5, 2);
close(v5);
v5 = -1;
}
else
{
fcntl(v5, 2, 1LL);
}
}
return v5;
}

original_code:
int
open_connection(const char *host, int port, unsigned int timeout)
{
    int val = 1;
    struct sockaddr_in sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (host == ((void *)0) || strlen(host) == 0 || port == 0)
 return -1;
    sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1)
 return -1;
    setsockopt(sock, IPPROTO_TCP, 1, &val, sizeof(val));
    if (timeout > 0) {
 struct timeval tv = { timeout, 0 };
 if (setsockopt(sock, 1, 21, &tv, sizeof(tv)) == -1
     || setsockopt(sock, 1, 20, &tv, sizeof(tv)) == -1)
     do { log_message(6, 0, "%s:%d: Failed to set timeout to %d\n", host, port, timeout); } while (0);
    }
    if (string2sockaddr(host, port, &sockaddr) == -1
 || connect(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1) {
 shutdown(sock, SHUT_RDWR);
 close(sock);
 return -1;
    }
    fcntl(sock, 2, 1);
    return sock;
}

canonical_original_code:
int open_connection(char *host, int port, unsigned int timeout)
{
    int val = 1;
    struct sockaddr_in sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (host == ((void *)0) || strlen(host) == 0 || port == 0)
 return -1;
    sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1)
 return -1;
    setsockopt(sock, IPPROTO_TCP, 1, &val, sizeof(val));
    if (timeout > 0) {
 struct timeval tv = { timeout, 0 };
 if (setsockopt(sock, 1, 21, &tv, sizeof(tv)) == -1
     || setsockopt(sock, 1, 20, &tv, sizeof(tv)) == -1)
     do { log_message(6, 0, "%s:%d: Failed to set timeout to %d\n", host, port, timeout); } while (0);
    }
    if (string2sockaddr(host, port, &sockaddr) == -1
 || connect(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1) {
 shutdown(sock, SHUT_RDWR);
 close(sock);
 return -1;
    }
    fcntl(sock, 2, 1);
    return sock;
}

variable_types:
timeout
unsigned int

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


decompiled_code:
__int64 __fastcall open_lsocket(char *name)
{
unsigned int v1; // ebx
struct sockaddr v3[8]; // [rsp+0h] [rbp-88h] BYREF

*_errno_location() = 22;
if ( !name )
return (unsigned int)-1;
if ( !*name )
return (unsigned int)-1;
v1 = socket(1, 1, 0);
if ( v1 != -1 )
{
unlink(name);
v3[0].sa_family = 1;
strncpy(v3[0].sa_data, name, 0x6CuLL);
if ( bind(v1, v3, 0x6Eu) == -1 || listen(v1, -1) == -1 )
{
shutdown(v1, 2);
close(v1);
v1 = -1;
}
else
{
fcntl(v1, 2, 1LL);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *name)
{
unsigned int v1; // ebx
struct sockaddr v3[8]; // [rsp+0h] [rbp-88h] BYREF

*_errno_location() = 22;
if ( !name )
return (unsigned int)-1;
if ( !*name )
return (unsigned int)-1;
v1 = socket(1, 1, 0);
if ( v1 != -1 )
{
unlink(name);
v3[0].sa_family = 1;
strncpy(v3[0].sa_data, name, 0x6CuLL);
if ( bind(v1, v3, 0x6Eu) == -1 || listen(v1, -1) == -1 )
{
shutdown(v1, 2);
close(v1);
v1 = -1;
}
else
{
fcntl(v1, 2, 1LL);
}
}
return v1;
}

original_code:
int
open_lsocket(const char *filename)
{
    struct sockaddr_un sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (filename == ((void *)0) || strlen(filename) == 0)
 return -1;
    sock = socket(1, SOCK_STREAM, 0);
    if (sock == -1)
 return -1;
    unlink(filename);
    sockaddr.sun_family = 1;
    strncpy(sockaddr.sun_path, filename, sizeof(sockaddr.sun_path));
    if (bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1
 || listen(sock, -1) == -1) {
 shutdown(sock, SHUT_RDWR);
 close(sock);
 return -1;
    }
    fcntl(sock, 2, 1);
    return sock;
}

canonical_original_code:
int open_lsocket(char *filename)
{
    struct sockaddr_un sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (filename == ((void *)0) || strlen(filename) == 0)
 return -1;
    sock = socket(1, SOCK_STREAM, 0);
    if (sock == -1)
 return -1;
    unlink(filename);
    sockaddr.sun_family = 1;
    strncpy(sockaddr.sun_path, filename, sizeof(sockaddr.sun_path));
    if (bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1
 || listen(sock, -1) == -1) {
 shutdown(sock, SHUT_RDWR);
 close(sock);
 return -1;
    }
    fcntl(sock, 2, 1);
    return sock;
}

variable_types:
filename
char *

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall open_fifo(char *file)
{
int *v1; // r12
unsigned int v2; // ebx
int v3; // eax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

if ( mkfifo(file, 0x1180u) )
{
v1 = _errno_location();
if ( *v1 != 17 )
return (unsigned int)-1;
v2 = stat(file, &v5);
if ( v2 == -1 )
{
*v1 = 17;
return v2;
}
if ( (v5.st_mode & 0xF000) != 4096 )
return (unsigned int)-1;
}
v3 = open(file, 2178);
v2 = v3;
if ( v3 != -1 )
fcntl(v3, 2, 1LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *file)
{
int *v1; // r12
unsigned int v2; // ebx
int v3; // eax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

if ( mkfifo(file, 0x1180u) )
{
v1 = _errno_location();
if ( *v1 != 17 )
return (unsigned int)-1;
v2 = stat(file, &v5);
if ( v2 == -1 )
{
*v1 = 17;
return v2;
}
if ( (v5.st_mode & 0xF000) != 4096 )
return (unsigned int)-1;
}
v3 = open(file, 2178);
v2 = v3;
if ( v3 != -1 )
fcntl(v3, 2, 1LL);
return v2;
}

original_code:
int
open_fifo(const char *filename)
{
    struct stat sb;
    int fd;
    if (mkfifo(filename, 0010000 | 0600) != 0) {
 if ((*__errno_location ()) == 17) {
     if (stat(filename, &sb) == -1) {
  (*__errno_location ()) = 17;
  return -1;
     } else if (!((((sb.st_mode)) & 0170000) == (0010000))) {
  return -1;
     }
 } else {
     return -1;
 }
    }
    fd = open(filename, 02|0200|04000);
    if (fd == -1)
 return -1;
    fcntl(fd, 2, 1);
    return fd;
}

canonical_original_code:
int open_fifo(char *filename)
{
    struct stat sb;
    int fd;
    if (mkfifo(filename, 0010000 | 0600) != 0) {
 if ((*__errno_location ()) == 17) {
     if (stat(filename, &sb) == -1) {
  (*__errno_location ()) = 17;
  return -1;
     } else if (!((((sb.st_mode)) & 0170000) == (0010000))) {
  return -1;
     }
 } else {
     return -1;
 }
    }
    fd = open(filename, 02|0200|04000);
    if (fd == -1)
 return -1;
    fcntl(fd, 2, 1);
    return fd;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void *__fastcall fbuf_swap(__m128i *a1, __m128i *a2)
{
void *result; // rax
__m128i v3; // [rsp+0h] [rbp-28h] BYREF
__m128i v4; // [rsp+10h] [rbp-18h] BYREF

v3 = _mm_loadu_si128(a1);
v4 = _mm_loadu_si128(a1 + 1);
result = memmove(a1, a2, 0x20uLL);
*a2 = _mm_loadu_si128(&v3);
a2[1] = _mm_loadu_si128(&v4);
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__m128i *a1, __m128i *a2)
{
void *result; // rax
__m128i v3; // [rsp+0h] [rbp-28h] BYREF
__m128i v4; // [rsp+10h] [rbp-18h] BYREF

v3 = _mm_loadu_si128(a1);
v4 = _mm_loadu_si128(a1 + 1);
result = memmove(a1, a2, 0x20uLL);
*a2 = _mm_loadu_si128(&v3);
a2[1] = _mm_loadu_si128(&v4);
return result;
}

original_code:
void
fbuf_swap(fbuf_t *fbuf1, fbuf_t *fbuf2)
{
    fbuf_t fbuf3;
    ;
    ;
    bcopy(fbuf1, &fbuf3, sizeof(fbuf_t));
    bcopy(fbuf2, fbuf1, sizeof(fbuf_t));
    bcopy(&fbuf3, fbuf2, sizeof(fbuf_t));
}

canonical_original_code:
void fbuf_swap(struct __fbuf *fbuf1, struct __fbuf *fbuf2)
{
    struct __fbuf fbuf3;
    ;
    ;
    bcopy(fbuf1, &fbuf3, sizeof(fbuf_t));
    bcopy(fbuf2, fbuf1, sizeof(fbuf_t));
    bcopy(&fbuf3, fbuf2, sizeof(fbuf_t));
}

variable_types: struct __fbuf { unsigned int id; char *data; unsigned int len; unsigned int prefmaxlen; unsigned int used; } *


decompiled_code:
__int64 __fastcall fbuf_extended(__int64 a1, int a2)
{
unsigned int v2; // esi
__int64 result; // rax
unsigned int v5; // edx
unsigned int v6; // edi
bool v7; // r8
int v8; // edx
_BYTE *v9; // rax

v2 = a2 + 1;
result = *(unsigned int *)(a1 + 16);
if ( (unsigned int)result < v2 )
{
v5 = *(_DWORD *)(a1 + 20);
if ( (unsigned int)result > v5 && v5 )
goto LABEL_7;
v6 = globalMaxLen;
v7 = globalMaxLen != 0;
if ( globalMaxLen < v2 && globalMaxLen )
{
if ( !v5 )
exit(99);
LABEL_7:
*_errno_location() = 12;
return 0LL;
}
do
{
if ( (_DWORD)result )
{
v8 = 2 * result;
if ( (unsigned int)result >= 0x10000 )
v8 = result + 0x10000;
*(_DWORD *)(a1 + 16) = v8;
}
else
{
*(_DWORD *)(a1 + 16) = 0x2000;
}
LODWORD(result) = *(_DWORD *)(a1 + 16);
}
while ( (unsigned int)result < v2 );
if ( v6 < (unsigned int)result && v7 )
*(_DWORD *)(a1 + 16) = v6;
v9 = realloc(*(void **)(a1 + 8), *(unsigned int *)(a1 + 16));
if ( v9 )
{
if ( !*(_QWORD *)(a1 + 8) )
*v9 = 0;
*(_QWORD *)(a1 + 8) = v9;
result = *(unsigned int *)(a1 + 16);
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
unsigned int v2; // esi
__int64 result; // rax
unsigned int v5; // edx
unsigned int v6; // edi
bool v7; // r8
int v8; // edx
_BYTE *v9; // rax

v2 = a2 + 1;
result = *(unsigned int *)(a1 + 16);
if ( (unsigned int)result < v2 )
{
v5 = *(_DWORD *)(a1 + 20);
if ( (unsigned int)result > v5 && v5 )
goto LABEL_7;
v6 = globalMaxLen;
v7 = globalMaxLen != 0;
if ( globalMaxLen < v2 && globalMaxLen )
{
if ( !v5 )
exit(99);
LABEL_7:
*_errno_location() = 12;
return 0LL;
}
do
{
if ( (_DWORD)result )
{
v8 = 2 * result;
if ( (unsigned int)result >= 0x10000 )
v8 = result + 0x10000;
*(_DWORD *)(a1 + 16) = v8;
}
else
{
*(_DWORD *)(a1 + 16) = 0x2000;
}
LODWORD(result) = *(_DWORD *)(a1 + 16);
}
while ( (unsigned int)result < v2 );
if ( v6 < (unsigned int)result && v7 )
*(_DWORD *)(a1 + 16) = v6;
v9 = realloc(*(void **)(a1 + 8), *(unsigned int *)(a1 + 16));
if ( v9 )
{
if ( !*(_QWORD *)(a1 + 8) )
*v9 = 0;
*(_QWORD *)(a1 + 8) = v9;
result = *(unsigned int *)(a1 + 16);
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
unsigned int
fbuf_extended(fbuf_t *fbuf, unsigned int newlen)
{
    char *p;
    newlen++;
    if (newlen <= fbuf->len)
 return fbuf->len;
    if (fbuf->prefmaxlen != 0 && fbuf->len > fbuf->prefmaxlen) {
 (*__errno_location ()) = 12;
        return 0;
    }
    if (globalMaxLen && newlen > globalMaxLen) {
 if (fbuf->prefmaxlen != 0) {
     (*__errno_location ()) = 12;
     return 0;
 } else {
     exit(99);
 }
    }
    while (newlen > fbuf->len) {
 if (fbuf->len == 0)
     fbuf->len = 8192;
 else if (fbuf->len < 64*1024)
     fbuf->len *= 2;
 else
     fbuf->len += 64*1024;
    }
    if (globalMaxLen && fbuf->len > globalMaxLen)
 fbuf->len = globalMaxLen;
    p = (char *)realloc(fbuf->data, fbuf->len);
    if (p) {
 if (!fbuf->data)
     p[0] = '\0';
 fbuf->data = p;
 ;
 return fbuf->len;
    } else {
 return 0;
    }
}

canonical_original_code:
unsigned int fbuf_extended(struct __fbuf *fbuf, unsigned int newlen)
{
    char *p;
    newlen++;
    if (newlen <= fbuf->len)
 return fbuf->len;
    if (fbuf->prefmaxlen != 0 && fbuf->len > fbuf->prefmaxlen) {
 (*__errno_location ()) = 12;
        return 0;
    }
    if (globalMaxLen && newlen > globalMaxLen) {
 if (fbuf->prefmaxlen != 0) {
     (*__errno_location ()) = 12;
     return 0;
 } else {
     exit(99);
 }
    }
    while (newlen > fbuf->len) {
 if (fbuf->len == 0)
     fbuf->len = 8192;
 else if (fbuf->len < 64*1024)
     fbuf->len *= 2;
 else
     fbuf->len += 64*1024;
    }
    if (globalMaxLen && fbuf->len > globalMaxLen)
 fbuf->len = globalMaxLen;
    p = (char *)realloc(fbuf->data, fbuf->len);
    if (p) {
 if (!fbuf->data)
     p[0] = '\0';
 fbuf->data = p;
 ;
 return fbuf->len;
    } else {
 return 0;
    }
}

variable_types:
newlen
unsigned int

variable_types:
p
char *

return_type: unsigned int

user_defined_types: struct __fbuf { unsigned int id; char *data; unsigned int len; unsigned int prefmaxlen; unsigned int used; }


original_code:
unsigned int
fbuf_shrink(fbuf_t *fbuf)
{
    unsigned int newlen, len = fbuf->len;
    char *p;
    if (fbuf->used == 0)
 len = 0;
    do {
 newlen = len;
 if (len <= 8192)
     break;
 else if (len <= 64*1024)
     len /= 2;
 else
     len -= 64*1024;
    } while (len >= fbuf->used+1);
    if (newlen == fbuf->len)
 return fbuf->len;
    if (newlen == 0) {
 free(fbuf->data);
 fbuf->data = ((void *)0);
 fbuf->len = 0;
    } else if ((p = (char *)realloc(fbuf->data, newlen)) != ((void *)0)) {
 fbuf->data = p;
 fbuf->len = newlen;
    }
    ;
    return fbuf->len;
}

canonical_original_code:
unsigned int fbuf_shrink(struct __fbuf *fbuf)
{
    unsigned int newlen; unsigned int len = fbuf->len;
    char *p;
    if (fbuf->used == 0)
 len = 0;
    do {
 newlen = len;
 if (len <= 8192)
     break;
 else if (len <= 64*1024)
     len /= 2;
 else
     len -= 64*1024;
    } while (len >= fbuf->used+1);
    if (newlen == fbuf->len)
 return fbuf->len;
    if (newlen == 0) {
 free(fbuf->data);
 fbuf->data = ((void *)0);
 fbuf->len = 0;
    } else if ((p = (char *)realloc(fbuf->data, newlen)) != ((void *)0)) {
 fbuf->data = p;
 fbuf->len = newlen;
    }
    ;
    return fbuf->len;
}

variable_types:
len
unsigned int


original_code:
void
fbuf_destroy(fbuf_t *fbuf)
{
    if (fbuf->data)
 free(fbuf->data);
    fbuf->data = ((void *)0);
    fbuf->used = fbuf->len = 0;
    ;
}

canonical_original_code:
void fbuf_destroy(struct __fbuf *fbuf)
{
    if (fbuf->data)
 free(fbuf->data);
    fbuf->data = ((void *)0);
    fbuf->used = fbuf->len = 0;
    ;
}


decompiled_code:
void __fastcall fbuf_free(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void
fbuf_free(fbuf_t *fbuf)
{
    if (fbuf->data)
 free(fbuf->data);
    ;
    free(fbuf);
}

canonical_original_code:
void fbuf_free(struct __fbuf *fbuf)
{
    if (fbuf->data)
 free(fbuf->data);
    ;
    free(fbuf);
}


decompiled_code:
__int64 __fastcall fbuf_add_binary(__int64 a1, const void *a2, unsigned int a3)
{
unsigned int v4; // eax

if ( !(unsigned int)fbuf_extended(a1, *(_DWORD *)(a1 + 24) + a3) )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)), a2, (int)a3);
v4 = *(_DWORD *)(a1 + 24) + a3;
*(_DWORD *)(a1 + 24) = v4;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + v4) = 0;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2, unsigned int a3)
{
unsigned int v4; // eax

if ( !(unsigned int)func1(a1, *(_DWORD *)(a1 + 24) + a3) )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)), a2, (int)a3);
v4 = *(_DWORD *)(a1 + 24) + a3;
*(_DWORD *)(a1 + 24) = v4;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + v4) = 0;
return a3;
}

original_code:
int
fbuf_add_binary(fbuf_t *fbuf, const char *data, int len)
{
    if (!fbuf_extended(fbuf, fbuf->used+len))
 return -1;
    memcpy(fbuf->data+fbuf->used, data, len);
    fbuf->used += len;
    fbuf->data[fbuf->used] = 0;
    return len;
}

canonical_original_code:
int fbuf_add_binary(struct __fbuf *fbuf, char *data, int len)
{
    if (!fbuf_extended(fbuf, fbuf->used+len))
 return -1;
    memcpy(fbuf->data+fbuf->used, data, len);
    fbuf->used += len;
    fbuf->data[fbuf->used] = 0;
    return len;
}

variable_types:
data
char *


decompiled_code:
__int64 __fastcall fbuf_add(__int64 a1, const char *a2)
{
__int64 result; // rax
unsigned int v3; // eax

if ( !a2 )
return 0LL;
result = 0LL;
if ( *a2 )
{
v3 = strlen(a2);
result = fbuf_add_binary(a1, a2, v3);
}
return result;
}

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

if ( !a2 )
return 0LL;
result = 0LL;
if ( *a2 )
{
v3 = strlen(a2);
result = func6(a1, a2, v3);
}
return result;
}

original_code:
int
fbuf_add(fbuf_t *fbuf, const char *data)
{
    int datalen;
    if (!data || data[0] == '\0')
 return 0;
    datalen = strlen(data);
    return fbuf_add_binary(fbuf, data, datalen);
}

canonical_original_code:
int fbuf_add(struct __fbuf *fbuf, char *data)
{
    int datalen;
    if (!data || data[0] == '\0')
 return 0;
    datalen = strlen(data);
    return fbuf_add_binary(fbuf, data, datalen);
}

variable_types: datalen int


decompiled_code:
__int64 __fastcall fbuf_add_nl(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
int v3; // eax

v2 = fbuf_add(a1, a2);
if ( v2 != -1 )
{
v3 = fbuf_add(a1, "\n");
if ( v3 == -1 )
v2 = -1;
else
v2 += v3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
int v3; // eax

v2 = func7(a1, a2);
if ( v2 != -1 )
{
v3 = func7(a1, "\n");
if ( v3 == -1 )
v2 = -1;
else
v2 += v3;
}
return v2;
}

original_code:
int
fbuf_add_nl(fbuf_t *fbuf, const char *data)
{
    int n1 = 0, n2 = 0;
    n1 = fbuf_add(fbuf, data);
    if (n1 == -1)
 return -1;
    n2 = fbuf_add(fbuf, "\n");
    if (n2 == -1)
 return -1;
    return n1 + n2;
}

canonical_original_code:
int fbuf_add_nl(struct __fbuf *fbuf, char *data)
{
    int n1 = 0; int n2 = 0;
    n1 = fbuf_add(fbuf, data);
    if (n1 == -1)
 return -1;
    n2 = fbuf_add(fbuf, "\n");
    if (n2 == -1)
 return -1;
    return n1 + n2;
}


original_code:
int
fbuf_concat(fbuf_t *fbufdst, fbuf_t *fbufsrc)
{
    int datalen;
    if (fbufsrc->used == 0)
 return 0;
    datalen = fbufsrc->used;
    if (!fbuf_extended(fbufdst, fbufdst->used+datalen))
 return -1;
    memcpy(fbufdst->data+fbufdst->used, fbufsrc->data, datalen+1);
    fbufdst->used += datalen;
    return datalen;
}

canonical_original_code:
int fbuf_concat(struct __fbuf *fbufdst, struct __fbuf *fbufsrc)
{
    int datalen;
    if (fbufsrc->used == 0)
 return 0;
    datalen = fbufsrc->used;
    if (!fbuf_extended(fbufdst, fbufdst->used+datalen))
 return -1;
    memcpy(fbufdst->data+fbufdst->used, fbufsrc->data, datalen+1);
    fbufdst->used += datalen;
    return datalen;
}

variable_types:
fbufsrc
struct __fbuf *


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

if ( !(unsigned int)fbuf_extended(a2, *(_DWORD *)(a1 + 24)) )
return 0xFFFFFFFFLL;
fbuf_clear(a2);
strcpy(*(char **)(a2 + 8), *(const char **)(a1 + 8));
result = *(unsigned int *)(a1 + 24);
*(_DWORD *)(a2 + 24) = result;
return result;
}

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

if ( !(unsigned int)func1(a2, *(_DWORD *)(a1 + 24)) )
return 0xFFFFFFFFLL;
fbuf_clear(a2);
strcpy(*(char **)(a2 + 8), *(const char **)(a1 + 8));
result = *(unsigned int *)(a1 + 24);
*(_DWORD *)(a2 + 24) = result;
return result;
}

original_code:
int
fbuf_copy(fbuf_t *fbufsrc, fbuf_t *fbufdst)
{
    if (!fbuf_extended(fbufdst, fbufsrc->used))
 return -1;
    fbuf_clear(fbufdst);
    strcpy(fbufdst->data, fbufsrc->data);
    fbufdst->used = fbufsrc->used;
    return fbufdst->used;
}

canonical_original_code:
int fbuf_copy(struct __fbuf *fbufsrc, struct __fbuf *fbufdst)
{
    if (!fbuf_extended(fbufdst, fbufsrc->used))
 return -1;
    fbuf_clear(fbufdst);
    strcpy(fbufdst->data, fbufsrc->data);
    fbufdst->used = fbufsrc->used;
    return fbufdst->used;
}

variable_types:
fbufdst
struct __fbuf *


decompiled_code:
__int64 __fastcall fbuf_set(__int64 a1, const char *a2)
{
int v2; // ebx
unsigned int v3; // er13

v2 = strlen(a2);
v3 = v2;
if ( !(unsigned int)fbuf_extended(a1, v2) )
return (unsigned int)-1;
memcpy(*(void **)(a1 + 8), a2, v2 + 1);
*(_DWORD *)(a1 + 24) = v2;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char *a2)
{
int v2; // ebx
unsigned int v3; // er13

v2 = strlen(a2);
v3 = v2;
if ( !(unsigned int)func1(a1, v2) )
return (unsigned int)-1;
memcpy(*(void **)(a1 + 8), a2, v2 + 1);
*(_DWORD *)(a1 + 24) = v2;
return v3;
}

original_code:
int
fbuf_set(fbuf_t *fbuf, const char *data)
{
    int datalen = strlen(data);
    if (!fbuf_extended(fbuf, datalen))
 return -1;
    memcpy(fbuf->data, data, datalen+1);
    fbuf->used = datalen;
    return datalen;
}

canonical_original_code:
int fbuf_set(struct __fbuf *fbuf, char *data)
{
    int datalen = strlen(data);
    if (!fbuf_extended(fbuf, datalen))
 return -1;
    memcpy(fbuf->data, data, datalen+1);
    fbuf->used = datalen;
    return datalen;
}


decompiled_code:
unsigned int fbuf_printf(__int64 a1, const char *a2, ...)
{
unsigned int result; // eax
int v4; // esi
unsigned int v5; // edx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !(unsigned int)fbuf_extended(a1, *(_DWORD *)(a1 + 24) + 127) )
return -1;
va_start(arg, a2);
result = vsnprintf(
(char *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)),
(unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a1 + 24)),
a2,
arg);
v4 = *(_DWORD *)(a1 + 24);
if ( *(_DWORD *)(a1 + 16) - v4 > result )
{
LABEL_3:
v5 = *(_DWORD *)(a1 + 24) + result;
*(_DWORD *)(a1 + 24) = v5;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + v5) = 0;
return result;
}
if ( (unsigned int)fbuf_extended(a1, result + v4) )
{
va_end(arg);
va_start(arg, a2);
result = vsnprintf(
(char *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)),
(unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a1 + 24)),
a2,
arg);
goto LABEL_3;
}
*(_BYTE *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)) = 0;
return -1;
}

canonical_decompiled_code:
unsigned int func12(__int64 a1, const char *a2, ...)
{
unsigned int result; // eax
int v4; // esi
unsigned int v5; // edx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !(unsigned int)func1(a1, *(_DWORD *)(a1 + 24) + 127) )
return -1;
va_start(arg, a2);
result = vsnprintf(
(char *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)),
(unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a1 + 24)),
a2,
arg);
v4 = *(_DWORD *)(a1 + 24);
if ( *(_DWORD *)(a1 + 16) - v4 > result )
{
LABEL_3:
v5 = *(_DWORD *)(a1 + 24) + result;
*(_DWORD *)(a1 + 24) = v5;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + v5) = 0;
return result;
}
if ( (unsigned int)func1(a1, result + v4) )
{
va_end(arg);
va_start(arg, a2);
result = vsnprintf(
(char *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)),
(unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a1 + 24)),
a2,
arg);
goto LABEL_3;
}
*(_BYTE *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)) = 0;
return -1;
}

original_code:
int
fbuf_printf(fbuf_t *fbuf, const char *fmt, ...)
{
    va_list args;
    unsigned int n;
    if (!fbuf_extended(fbuf, fbuf->used+127))
        return -1;
    __builtin_va_start(args,fmt);
    n = vsnprintf(fbuf->data+fbuf->used, fbuf->len-fbuf->used, fmt, args);
    __builtin_va_end(args);
    if (n >= fbuf->len-fbuf->used) {
        if (!fbuf_extended(fbuf, fbuf->used+n)) {
            fbuf->data[fbuf->used] = '\0';
            return -1;
        }
        __builtin_va_start(args,fmt);
        n = vsnprintf(fbuf->data+fbuf->used, fbuf->len-fbuf->used, fmt, args);
        __builtin_va_end(args);
    }
    fbuf->used += n;
    fbuf->data[fbuf->used] = '\0';
    __builtin_va_end(args);
    return n;
}

canonical_original_code:
int fbuf_printf(struct __fbuf *fbuf, char *fmt, ...)
{
    __builtin_va_list args;
    unsigned int n;
    if (!fbuf_extended(fbuf, fbuf->used+127))
        return -1;
    __builtin_va_start(args,fmt);
    n = vsnprintf(fbuf->data+fbuf->used, fbuf->len-fbuf->used, fmt, args);
    __builtin_va_end(args);
    if (n >= fbuf->len-fbuf->used) {
        if (!fbuf_extended(fbuf, fbuf->used+n)) {
            fbuf->data[fbuf->used] = '\0';
            return -1;
        }
        __builtin_va_start(args,fmt);
        n = vsnprintf(fbuf->data+fbuf->used, fbuf->len-fbuf->used, fmt, args);
        __builtin_va_end(args);
    }
    fbuf->used += n;
    fbuf->data[fbuf->used] = '\0';
    __builtin_va_end(args);
    return n;
}

variable_types:
fmt
char *

variable_types:
n
unsigned int


decompiled_code:
__int64 __fastcall fbuf_read(__int64 a1, int a2, unsigned int a3)
{
unsigned int v3; // ebp
int v4; // eax
unsigned int v5; // edx

v3 = a3;
if ( !a3 )
v3 = 1024;
if ( !(unsigned int)fbuf_extended(a1, *(_DWORD *)(a1 + 24) + v3) )
return (unsigned int)-1;
v4 = read(a2, (void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)), v3);
v5 = v4;
if ( v4 > 0 )
*(_DWORD *)(a1 + 24) += v4;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)) = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2, unsigned int a3)
{
unsigned int v3; // ebp
int v4; // eax
unsigned int v5; // edx

v3 = a3;
if ( !a3 )
v3 = 1024;
if ( !(unsigned int)func1(a1, *(_DWORD *)(a1 + 24) + v3) )
return (unsigned int)-1;
v4 = read(a2, (void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)), v3);
v5 = v4;
if ( v4 > 0 )
*(_DWORD *)(a1 + 24) += v4;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 24)) = 0;
return v5;
}

original_code:
int
fbuf_read(fbuf_t *fbuf, int fd, unsigned int explen)
{
    int n;
    if (explen == 0)
 explen = 1024;
    if (!fbuf_extended(fbuf, fbuf->used+explen))
 return -1;
    n = read(fd, fbuf->data+fbuf->used, explen);
    if (n > 0)
 fbuf->used += n;
    fbuf->data[fbuf->used] = '\0';
    return n;
}

canonical_original_code:
int fbuf_read(struct __fbuf *fbuf, int fd, unsigned int explen)
{
    int n;
    if (explen == 0)
 explen = 1024;
    if (!fbuf_extended(fbuf, fbuf->used+explen))
 return -1;
    n = read(fd, fbuf->data+fbuf->used, explen);
    if (n > 0)
 fbuf->used += n;
    fbuf->data[fbuf->used] = '\0';
    return n;
}

variable_types: fd int

variable_types:
explen
unsigned int

variable_types: n int


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

v2 = *(_DWORD *)(a1 + 24);
if ( v2 > a2 )
{
if ( a2 )
{
v4 = v2 - a2;
*(_DWORD *)(a1 + 24) = v4;
memmove(*(void **)(a1 + 8), (const void *)(*(_QWORD *)(a1 + 8) + a2), v4 + 1);
}
}
else
{
*(_DWORD *)(a1 + 24) = 0;
**(_BYTE **)(a1 + 8) = 0;
}
return *(unsigned int *)(a1 + 24);
}

original_code:
int
fbuf_remove(fbuf_t *fbuf, unsigned int len)
{
    if (len >= fbuf->used) {
        fbuf->used = 0;
 fbuf->data[fbuf->used] = '\0';
    } else if (len) {
 fbuf->used -= len;
 memmove(fbuf->data, fbuf->data+len, fbuf->used+1);
    }
    return fbuf->used;
}

canonical_original_code:
int fbuf_remove(struct __fbuf *fbuf, unsigned int len)
{
    if (len >= fbuf->used) {
        fbuf->used = 0;
 fbuf->data[fbuf->used] = '\0';
    } else if (len) {
 fbuf->used -= len;
 memmove(fbuf->data, fbuf->data+len, fbuf->used+1);
    }
    return fbuf->used;
}


decompiled_code:
__int64 __fastcall fbuf_write(__int64 a1, int a2, unsigned int a3)
{
unsigned int v3; // ebp
signed int v5; // eax

if ( !a3 )
a3 = *(_DWORD *)(a1 + 24);
if ( *(_DWORD *)(a1 + 24) <= a3 )
a3 = *(_DWORD *)(a1 + 24);
v3 = 0;
if ( a3 )
{
v5 = write(a2, *(const void **)(a1 + 8), a3);
v3 = v5;
if ( v5 > 0 )
fbuf_remove(a1, v5);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2, unsigned int a3)
{
unsigned int v3; // ebp
signed int v5; // eax

if ( !a3 )
a3 = *(_DWORD *)(a1 + 24);
if ( *(_DWORD *)(a1 + 24) <= a3 )
a3 = *(_DWORD *)(a1 + 24);
v3 = 0;
if ( a3 )
{
v5 = write(a2, *(const void **)(a1 + 8), a3);
v3 = v5;
if ( v5 > 0 )
func15(a1, v5);
}
return v3;
}

original_code:
int
fbuf_write(fbuf_t *fbuf, int fd, unsigned int nbytes)
{
    int n = 0;
    if (nbytes == 0)
 nbytes = fbuf->used;
    if (nbytes > fbuf->used)
 nbytes = fbuf->used;
    if (nbytes > 0) {
 n = write(fd, fbuf->data, nbytes);
 if (n > 0)
     fbuf_remove(fbuf, n);
    }
    return n;
}

canonical_original_code:
int fbuf_write(struct __fbuf *fbuf, int fd, unsigned int nbytes)
{
    int n = 0;
    if (nbytes == 0)
 nbytes = fbuf->used;
    if (nbytes > fbuf->used)
 nbytes = fbuf->used;
    if (nbytes > 0) {
 n = write(fd, fbuf->data, nbytes);
 if (n > 0)
     fbuf_remove(fbuf, n);
    }
    return n;
}

variable_types:
nbytes
unsigned int


decompiled_code:
__int64 __fastcall fbuf_trim(__int64 a1)
{
unsigned int v1; // ebx
const unsigned __int16 *v2; // rsi
char *v3; // rdx
unsigned int v4; // eax

v1 = *(_DWORD *)(a1 + 24);
if ( v1 )
{
v2 = *_ctype_b_loc();
v3 = *(char **)(a1 + 8);
v4 = 0;
while ( (v2[*v3] & 0x2000) != 0 )
{
++v4;
++v3;
if ( v4 == v1 )
goto LABEL_7;
}
v1 = v4;
}
LABEL_7:
fbuf_remove(a1, v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
unsigned int v1; // ebx
const unsigned __int16 *v2; // rsi
char *v3; // rdx
unsigned int v4; // eax

v1 = *(_DWORD *)(a1 + 24);
if ( v1 )
{
v2 = *_ctype_b_loc();
v3 = *(char **)(a1 + 8);
v4 = 0;
while ( (v2[*v3] & 0x2000) != 0 )
{
++v4;
++v3;
if ( v4 == v1 )
goto LABEL_7;
}
v1 = v4;
}
LABEL_7:
func15(a1, v1);
return v1;
}

original_code:
int
fbuf_trim(fbuf_t *fbuf)
{
    unsigned int i = 0;
    while (i < fbuf->used && ((*__ctype_b_loc ())[(int) ((fbuf->data[i]))] & (unsigned short int) _ISspace))
 i++;
    fbuf_remove(fbuf, i);
    return i;
}

canonical_original_code:
int fbuf_trim(struct __fbuf *fbuf)
{
    unsigned int i = 0;
    while (i < fbuf->used && ((*__ctype_b_loc ())[(int) ((fbuf->data[i]))] & (unsigned short) _ISspace))
 i++;
    fbuf_remove(fbuf, i);
    return i;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall fbuf_data(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
char *
fbuf_data(fbuf_t *fbuf)
{
    return fbuf->data;
}

canonical_original_code:
char *fbuf_data(struct __fbuf *fbuf)
{
    return fbuf->data;
}

return_type: char *


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

result = *(_QWORD *)(a1 + 8);
if ( result )
result += *(unsigned int *)(a1 + 24);
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( result )
result += *(unsigned int *)(a1 + 24);
return result;
}

original_code:
char *
fbuf_end(fbuf_t *fbuf)
{
    if (fbuf->data)
 return fbuf->data + fbuf->used;
    else
 return ((void *)0);
}

canonical_original_code:
char *fbuf_end(struct __fbuf *fbuf)
{
    if (fbuf->data)
 return fbuf->data + fbuf->used;
    else
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall fbuf_set_used(__int64 a1, unsigned int a2)
{
if ( *(_DWORD *)(a1 + 24) > a2 )
{
*(_DWORD *)(a1 + 24) = a2;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + a2) = 0;
}
return *(unsigned int *)(a1 + 24);
}

original_code:
int
fbuf_set_used(fbuf_t *fbuf, unsigned int newused)
{
    if (newused < fbuf->used) {
 fbuf->used = newused;
 fbuf->data[fbuf->used] = '\0';
    }
    return fbuf->used;
}

canonical_original_code:
int fbuf_set_used(struct __fbuf *fbuf, unsigned int newused)
{
    if (newused < fbuf->used) {
 fbuf->used = newused;
 fbuf->data[fbuf->used] = '\0';
    }
    return fbuf->used;
}

variable_types:
newused
unsigned int


decompiled_code:
__int64 __fastcall fbuf_used(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
unsigned int
fbuf_used(fbuf_t *fbuf)
{
    return fbuf->used;
}

canonical_original_code:
unsigned int fbuf_used(struct __fbuf *fbuf)
{
    return fbuf->used;
}


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

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

original_code:
unsigned int
fbuf_len(fbuf_t *fbuf)
{
    return fbuf->len;
}

canonical_original_code:
unsigned int fbuf_len(struct __fbuf *fbuf)
{
    return fbuf->len;
}


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

result = a2;
*(_DWORD *)(a1 + 20) = a2;
return result;
}

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

result = a2;
*(_DWORD *)(a1 + 20) = a2;
return result;
}

original_code:
unsigned int
fbuf_set_pref_maxlen(fbuf_t *fbuf, unsigned int newprefmaxlen)
{
    return (fbuf->prefmaxlen = newprefmaxlen);
}

canonical_original_code:
unsigned int fbuf_set_pref_maxlen(struct __fbuf *fbuf, unsigned int newprefmaxlen)
{
    return (fbuf->prefmaxlen = newprefmaxlen);
}

variable_types:
newprefmaxlen
unsigned int


decompiled_code:
__int64 __fastcall fbuf_pref_maxlen(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
unsigned int
fbuf_pref_maxlen(fbuf_t *fbuf)
{
    return fbuf->prefmaxlen;
}

canonical_original_code:
unsigned int fbuf_pref_maxlen(struct __fbuf *fbuf)
{
    return fbuf->prefmaxlen;
}

variable_types: struct __fbuf { unsigned int id; char *data; unsigned int len; unsigned int prefmaxlen; unsigned int used; } *


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

result = a1;
globalMaxLen = a1;
return result;
}

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

result = a1;
globalMaxLen = a1;
return result;
}

original_code:
unsigned int
fbuf_set_maxlen(unsigned int maxlen)
{
    return (globalMaxLen = maxlen);
}

variable_types:
maxlen
unsigned int


decompiled_code:
__int64 fbuf_maxlen()
{
return (unsigned int)globalMaxLen;
}

canonical_decompiled_code:
__int64 func26()
{
return (unsigned int)globalMaxLen;
}

original_code:
unsigned int
fbuf_maxlen(void)
{
    return globalMaxLen;
}

canonical_original_code:
unsigned int fbuf_maxlen()
{
    return globalMaxLen;
}


original_code:
unsigned long
byte_escape(char ch, char esc, char *buffer, unsigned long len, char **dest, unsigned long *newlen)
{
    char *newbuf;
    unsigned long buflen;
    unsigned long i;
    unsigned long cnt;
    int escape;
    char *p;
    unsigned long off;
    if(len == 0)
        return 0;
    newbuf = (char *)malloc(len);
    if(!newbuf)
        return 0;
    buflen = len;
    p = buffer;
    off = 0;
    cnt = 0;
    for(i=0;i<len;i++)
    {
        escape = 0;
        if(*p == ch)
            cnt ++;
        if(*p == ch || *p == esc)
            escape = 1;
        if(escape)
        {
            buflen++;
            newbuf = (char *)realloc(newbuf, buflen+1);
            memcpy(newbuf+off, &esc, 1);
            off++;
        }
        memcpy(newbuf+off, p, 1);
        p++;
        off++;
    }
    *dest = newbuf;
    *newlen = buflen;
    return cnt;
}

variable_types: ch char

variable_types: esc char

variable_types:
buffer
char *

variable_types:
len
unsigned long

variable_types:
dest
char **

variable_types:
newlen
unsigned long *

variable_types:
newbuf
char *

variable_types:
buflen
unsigned long

variable_types:
i
unsigned long

variable_types:
cnt
unsigned long

variable_types: escape int

variable_types:
p
char *

variable_types:
off
unsigned long


decompiled_code:
void *__fastcall hex_escape(char *a1, int a2)
{
char *v3; // rax
char *v4; // rbx
char *v5; // r13

v3 = (char *)realloc(str_0, 2 * a2 + 4);
str_0 = v3;
strcpy(v3, "0x");
if ( a2 > 0 )
{
v4 = v3 + 2;
v5 = &v3[2 * (a2 + 1)];
do
{
sprintf(v4, "%02x", (unsigned int)*a1);
v4 += 2;
++a1;
}
while ( v4 != v5 );
}
return str_0;
}

canonical_decompiled_code:
void *__fastcall func1(char *a1, int a2)
{
char *v3; // rax
char *v4; // rbx
char *v5; // r13

v3 = (char *)realloc(str_0, 2 * a2 + 4);
str_0 = v3;
strcpy(v3, "0x");
if ( a2 > 0 )
{
v4 = v3 + 2;
v5 = &v3[2 * (a2 + 1)];
do
{
sprintf(v4, "%02x", (unsigned int)*a1);
v4 += 2;
++a1;
}
while ( v4 != v5 );
}
return str_0;
}

original_code:
char *hex_escape(const char *buf, int len) {
    int i;
    static char *str = ((void *)0);
    str = realloc(str, (len*2)+4);
    strcpy(str, "0x");
    char *p = str+2;
    for (i = 0; i < len; i++) {
        sprintf(p, "%02x", buf[i]);
        p+=2;
    }
    return str;
}

canonical_original_code:
char *hex_escape(char *buf, int len) {
    int i;
    static char *str = ((void *)0);
    str = realloc(str, (len*2)+4);
    strcpy(str, "0x");
    char *p = str+2;
    for (i = 0; i < len; i++) {
        sprintf(p, "%02x", buf[i]);
        p+=2;
    }
    return str;
}

variable_types:
buf
char *

variable_types: len int

variable_types: i int

variable_types:
str
char *


decompiled_code:
int __fastcall log_init(const char *a1, int a2)
{
_loglevel = a2;
openlog(a1, 34, 128);
return setlogmask(255);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, int a2)
{
_loglevel = a2;
openlog(a1, 34, 128);
return setlogmask(255);
}

original_code:
void log_init(char *ident, int loglevel)
{
    __loglevel = loglevel;
    openlog(ident, 0x02|0x20, (16<<3));
    setlogmask(((1 << ((7)+1)) - 1));
}

variable_types:
ident
char *

variable_types: loglevel int


decompiled_code:
__int64 log_level()
{
return (unsigned int)_loglevel;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)_loglevel;
}

original_code:
unsigned int log_level()
{
    return __loglevel;
}


decompiled_code:
void log_message(int pri, int a2, const char *a3, ...)
{
const char *v4; // r12
size_t v5; // r13
size_t v6; // rax
char *v7; // rax
char *v8; // r13
gcc_va_list ap; // [rsp+8h] [rbp-F0h] BYREF

switch ( pri )
{
case 3:
v4 = "[ERROR]: ";
break;
case 4:
v4 = "[WARNING]: ";
break;
case 5:
v4 = "[NOTICE]: ";
break;
case 6:
v4 = "[INFO]: ";
break;
case 7:
v4 = "[DBG3]: ";
if ( a2 != 3 )
{
if ( a2 > 3 )
{
v4 = "[DBGX]: ";
if ( a2 == 4 )
v4 = "[DBG4]: ";
}
else
{
v4 = "[DBG]: ";
if ( a2 != 1 )
{
v4 = "[DBGX]: ";
if ( a2 == 2 )
v4 = "[DBG2]: ";
}
}
}
break;
default:
v4 = "[UNKNOWN]: ";
break;
}
if ( a3 )
{
v5 = strlen(a3);
v6 = strlen(v4);
v7 = (char *)calloc(1uLL, v5 + v6 + 1);
v8 = v7;
if ( v7 )
{
sprintf(v7, "%s%s", v4, a3);
va_start(ap, a3);
vsyslog(pri, v8, ap);
free(v8);
}
}
}

canonical_decompiled_code:
void func4(int pri, int a2, const char *a3, ...)
{
const char *v4; // r12
size_t v5; // r13
size_t v6; // rax
char *v7; // rax
char *v8; // r13
gcc_va_list ap; // [rsp+8h] [rbp-F0h] BYREF

switch ( pri )
{
case 3:
v4 = "[ERROR]: ";
break;
case 4:
v4 = "[WARNING]: ";
break;
case 5:
v4 = "[NOTICE]: ";
break;
case 6:
v4 = "[INFO]: ";
break;
case 7:
v4 = "[DBG3]: ";
if ( a2 != 3 )
{
if ( a2 > 3 )
{
v4 = "[DBGX]: ";
if ( a2 == 4 )
v4 = "[DBG4]: ";
}
else
{
v4 = "[DBG]: ";
if ( a2 != 1 )
{
v4 = "[DBGX]: ";
if ( a2 == 2 )
v4 = "[DBG2]: ";
}
}
}
break;
default:
v4 = "[UNKNOWN]: ";
break;
}
if ( a3 )
{
v5 = strlen(a3);
v6 = strlen(v4);
v7 = (char *)calloc(1uLL, v5 + v6 + 1);
v8 = v7;
if ( v7 )
{
sprintf(v7, "%s%s", v4, a3);
va_start(ap, a3);
vsyslog(pri, v8, ap);
free(v8);
}
}
}

original_code:
void log_message(int prio, int dbglevel, const char *fmt, ...)
{
    char *newfmt = ((void *)0);
    const char *prefix = ((void *)0);
    switch (prio) {
        case 3:
            prefix = "[ERROR]: ";
            break;
        case 4:
            prefix = "[WARNING]: ";
            break;
        case 5:
            prefix = "[NOTICE]: ";
            break;
        case 6:
            prefix = "[INFO]: ";
            break;
        case 7:
            switch (dbglevel) {
                case 1:
                    prefix = "[DBG]: ";
                    break;
                case 2:
                    prefix = "[DBG2]: ";
                    break;
                case 3:
                    prefix = "[DBG3]: ";
                    break;
                case 4:
                    prefix = "[DBG4]: ";
                    break;
                default:
                    prefix = "[DBGX]: ";
                    break;
            }
            break;
        default:
            prefix = "[UNKNOWN]: ";
            break;
    }
    if (prefix && fmt) {
        newfmt = (char *)calloc(1, strlen(fmt)+strlen(prefix)+1);
        if (newfmt) {
            sprintf(newfmt, "%s%s", prefix, fmt);
            va_list arg;
            __builtin_va_start(arg,fmt);
            vsyslog(prio, newfmt, arg);
            __builtin_va_end(arg);
            free(newfmt);
        }
    }
}

canonical_original_code:
void log_message(int prio, int dbglevel, char *fmt, ...)
{
    char *newfmt = ((void *)0);
    char *prefix = ((void *)0);
    switch (prio) {
        case 3:
            prefix = "[ERROR]: ";
            break;
        case 4:
            prefix = "[WARNING]: ";
            break;
        case 5:
            prefix = "[NOTICE]: ";
            break;
        case 6:
            prefix = "[INFO]: ";
            break;
        case 7:
            switch (dbglevel) {
                case 1:
                    prefix = "[DBG]: ";
                    break;
                case 2:
                    prefix = "[DBG2]: ";
                    break;
                case 3:
                    prefix = "[DBG3]: ";
                    break;
                case 4:
                    prefix = "[DBG4]: ";
                    break;
                default:
                    prefix = "[DBGX]: ";
                    break;
            }
            break;
        default:
            prefix = "[UNKNOWN]: ";
            break;
    }
    if (prefix && fmt) {
        newfmt = (char *)calloc(1, strlen(fmt)+strlen(prefix)+1);
        if (newfmt) {
            sprintf(newfmt, "%s%s", prefix, fmt);
            __builtin_va_list arg;
            __builtin_va_start(arg,fmt);
            vsyslog(prio, newfmt, arg);
            __builtin_va_end(arg);
            free(newfmt);
        }
    }
}

variable_types: prio int

variable_types: dbglevel int

variable_types:
fmt
char *

variable_types:
newfmt
char *

variable_types:
prefix
char *


repo: xcvista/libcore

decompiled_code:
bool __fastcall vector_binary_compare_internal(const void *a1, const void *a2)
{
return memcmp(a1, a2, vector_current_size) == 0;
}

canonical_decompiled_code:
bool __fastcall func0(const void *a1, const void *a2)
{
return memcmp(a1, a2, vector_current_size) == 0;
}

original_code:
_Bool vector_binary_compare_internal(const void *r1, const void *r2)
{
    return !memcmp(r1, r2, vector_current_size);
}

canonical_original_code:
_Bool vector_binary_compare_internal(void *r1, void *r2)
{
    return !memcmp(r1, r2, vector_current_size);
}


decompiled_code:
__int64 __fastcall vector_max_pointer(_QWORD *a1)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x12u, "vector_max_pointer");
return *a1 + a1[3] * a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x12u, "vector_max_pointer");
return *a1 + a1[3] * a1[2];
}

original_code:
void *vector_max_pointer(vector_t vec)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    void *base = vec -> data;
    size_t size = vec -> element_size * vec -> count;
    return base + size;
}

canonical_original_code:
void *vector_max_pointer(struct __vector_s *vec)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    void *base = vec -> data;
    unsigned long size = vec -> element_size * vec -> count;
    return base + size;
}

variable_types: struct __vector_s { void *data; unsigned long alloc_size; unsigned long element_size; unsigned long count; } *

variable_types:
base
void *

variable_types:
size
unsigned long

return_type: void *


decompiled_code:
__int64 __fastcall vector_indexof_ptr(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x23u, "vector_indexof_ptr");
if ( a2 >= vector_max_pointer(a1) )
return 0xFFFFFFFFLL;
if ( *a1 >= a2 )
return 0xFFFFFFFFLL;
return (a2 - *a1) / a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x23u, "vector_indexof_ptr");
if ( a2 >= func1(a1) )
return 0xFFFFFFFFLL;
if ( *a1 >= a2 )
return 0xFFFFFFFFLL;
return (a2 - *a1) / a1[2];
}

original_code:
int vector_indexof_ptr(vector_t vec, const void *ptr)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    void *max = vector_max_pointer(vec);
    if (ptr >= max || ptr <= vec -> data)
        return (-1);
    else
        return (int)((ptr - vec -> data) / vec -> element_size);
}

canonical_original_code:
int vector_indexof_ptr(struct __vector_s *vec, void *ptr)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    void *max = vector_max_pointer(vec);
    if (ptr >= max || ptr <= vec -> data)
        return (-1);
    else
        return (int)((ptr - vec -> data) / vec -> element_size);
}

variable_types:
ptr
void *

variable_types:
max
void *

user_defined_types: struct __vector_s { void *data; unsigned long alloc_size; unsigned long element_size; unsigned long count; }


decompiled_code:
__int64 __fastcall vector_count(__int64 a1)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x71u, "vector_count");
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x71u, "vector_count");
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t vector_count(vector_t vec)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 113, __extension__ __PRETTY_FUNCTION__); }));
    return vec -> count;
}

canonical_original_code:
unsigned long vector_count(struct __vector_s *vec)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 113, __extension__ __PRETTY_FUNCTION__); }));
    return vec -> count;
}


decompiled_code:
void *__fastcall vector_alloc_object(__int64 a1)
{
size_t v1; // rbp
void *v2; // rax
void *v3; // rbx

if ( !a1 )
_assert_fail("vec", "vector.c", 0x7Au, "vector_alloc_object");
v1 = *(_QWORD *)(a1 + 16);
v2 = malloc(v1);
v3 = v2;
if ( v2 )
memset(v2, 0, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1)
{
size_t v1; // rbp
void *v2; // rax
void *v3; // rbx

if ( !a1 )
_assert_fail("vec", "vector.c", 0x7Au, "vector_alloc_object");
v1 = *(_QWORD *)(a1 + 16);
v2 = malloc(v1);
v3 = v2;
if ( v2 )
memset(v2, 0, v1);
return v3;
}

original_code:
void *vector_alloc_object(vector_t vec)
{
    void *block = ((void *)0);
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    block = malloc(vec -> element_size);
    if (block)
        memset(block, 0, vec -> element_size);
    return block;
}

canonical_original_code:
void *vector_alloc_object(struct __vector_s *vec)
{
    void *block = ((void *)0);
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    block = malloc(vec -> element_size);
    if (block)
        memset(block, 0, vec -> element_size);
    return block;
}

variable_types:
block
void *


decompiled_code:
void *__fastcall vector_objectat(_QWORD *a1, void *a2, unsigned __int64 a3)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x87u, "vector_objectat");
if ( !a2 )
_assert_fail("buf", "vector.c", 0x88u, "vector_objectat");
if ( a1[3] <= a3 )
_assert_fail("index < vec -> count", "vector.c", 0x89u, "vector_objectat");
return memcpy(a2, (const void *)(*a1 + a1[2] * a3), a1[2]);
}

canonical_decompiled_code:
void *__fastcall func6(_QWORD *a1, void *a2, unsigned __int64 a3)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0x87u, "vector_objectat");
if ( !a2 )
_assert_fail("buf", "vector.c", 0x88u, "vector_objectat");
if ( a1[3] <= a3 )
_assert_fail("index < vec -> count", "vector.c", 0x89u, "vector_objectat");
return memcpy(a2, (const void *)(*a1 + a1[2] * a3), a1[2]);
}

original_code:
void *vector_objectat(vector_t vec, void *buf, size_t index)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 135, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buf) ? 1 : 0), __extension__ ({ if (buf) ; else __assert_fail ("buf", "vector.c", 136, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((index < vec -> count) ? 1 : 0), __extension__ ({ if (index < vec -> count) ; else __assert_fail ("index < vec -> count", "vector.c", 137, __extension__ __PRETTY_FUNCTION__); }));
    void *ptr = vec -> data + index * vec -> element_size;
    return memcpy(buf, ptr, vec -> element_size);
}

canonical_original_code:
void *vector_objectat(struct __vector_s *vec, void *buf, unsigned long index)
{
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 135, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buf) ? 1 : 0), __extension__ ({ if (buf) ; else __assert_fail ("buf", "vector.c", 136, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((index < vec -> count) ? 1 : 0), __extension__ ({ if (index < vec -> count) ; else __assert_fail ("index < vec -> count", "vector.c", 137, __extension__ __PRETTY_FUNCTION__); }));
    void *ptr = vec -> data + index * vec -> element_size;
    return memcpy(buf, ptr, vec -> element_size);
}

variable_types:
buf
void *

variable_types:
index
unsigned long


decompiled_code:
void *__fastcall vector_set(_QWORD *a1, const void *a2, __int64 a3)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0xC1u, "vector_set");
if ( !a2 )
_assert_fail("object", "vector.c", 0xC2u, "vector_set");
return memcpy((void *)(*a1 + a1[2] * a3), a2, a1[2]);
}

canonical_decompiled_code:
void *__fastcall func7(_QWORD *a1, const void *a2, __int64 a3)
{
if ( !a1 )
_assert_fail("vec", "vector.c", 0xC1u, "vector_set");
if ( !a2 )
_assert_fail("object", "vector.c", 0xC2u, "vector_set");
return memcpy((void *)(*a1 + a1[2] * a3), a2, a1[2]);
}

original_code:
void vector_set(vector_t vec, const void *object, size_t index)
{
    void *ptr = ((void *)0);
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 193, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((object) ? 1 : 0), __extension__ ({ if (object) ; else __assert_fail ("object", "vector.c", 194, __extension__ __PRETTY_FUNCTION__); }));
    ptr = vec -> data + vec -> element_size * index;
    memcpy(ptr, object, vec -> element_size);
}

canonical_original_code:
void vector_set(struct __vector_s *vec, void *object, unsigned long index)
{
    void *ptr = ((void *)0);
    ((void) sizeof ((vec) ? 1 : 0), __extension__ ({ if (vec) ; else __assert_fail ("vec", "vector.c", 193, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((object) ? 1 : 0), __extension__ ({ if (object) ; else __assert_fail ("object", "vector.c", 194, __extension__ __PRETTY_FUNCTION__); }));
    ptr = vec -> data + vec -> element_size * index;
    memcpy(ptr, object, vec -> element_size);
}

variable_types:
object
void *