decompiled_code:
__int64 __fastcall get_edata_by_inode(unsigned int a1, __int64 a2, _DWORD *a3)
{
__int64 v4; // rax
__int64 v5; // r12

pthread_mutex_lock((pthread_mutex_t *)(a2 + 64));
get_edata_by_inode_unlocked(a1, a2, a3);
v5 = v4;
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 64));
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2, _DWORD *a3)
{
__int64 v4; // rax
__int64 v5; // r12

pthread_mutex_lock((pthread_mutex_t *)(a2 + 64));
func6(a1, a2, a3);
v5 = v4;
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 64));
return v5;
}

original_code:
struct extend_data *get_edata_by_inode(const __u32 extend_no,
    struct inode_vbfs *inode_v, int *err_no)
{
 struct extend_data *edata = ((void *)0);
 pthread_mutex_lock(&inode_v->inode_lock);
 edata = get_edata_by_inode_unlocked(extend_no, inode_v, err_no);
 pthread_mutex_unlock(&inode_v->inode_lock);
 return edata;
}

canonical_original_code:
struct extend_data *get_edata_by_inode(unsigned int extend_no, struct inode_vbfs *inode_v, int *err_no)
{
 struct extend_data *edata = ((void *)0);
 pthread_mutex_lock(&inode_v->inode_lock);
 edata = get_edata_by_inode_unlocked(extend_no, inode_v, err_no);
 pthread_mutex_unlock(&inode_v->inode_lock);
 return edata;
}

user_defined_types: struct inode_dirents { int ref; int dir_cnt; int status; struct list_head dir_list; }

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
__int64 __fastcall put_edata_by_inode(int a1, __int64 a2)
{
unsigned int v2; // er12

pthread_mutex_lock((pthread_mutex_t *)(a2 + 64));
v2 = put_edata_by_inode_unlocked(a1, a2);
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 64));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2)
{
unsigned int v2; // er12

pthread_mutex_lock((pthread_mutex_t *)(a2 + 64));
v2 = func8(a1, a2);
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 64));
return v2;
}

original_code:
int put_edata_by_inode(const __u32 extend_no, struct inode_vbfs *inode_v)
{
 int ret = 0;
 pthread_mutex_lock(&inode_v->inode_lock);
 ret = put_edata_by_inode_unlocked(extend_no, inode_v);
 pthread_mutex_unlock(&inode_v->inode_lock);
 return ret;
}

canonical_original_code:
int put_edata_by_inode(unsigned int extend_no, struct inode_vbfs *inode_v)
{
 int ret = 0;
 pthread_mutex_lock(&inode_v->inode_lock);
 ret = put_edata_by_inode_unlocked(extend_no, inode_v);
 pthread_mutex_unlock(&inode_v->inode_lock);
 return ret;
}

variable_types: struct inode_vbfs { unsigned int i_ino; unsigned int i_pino; unsigned int i_mode; unsigned long long i_size; unsigned int i_ctime; unsigned int i_atime; unsigned int i_mtime; unsigned int i_extend; int inode_dirty; int ref; struct list_head { struct list_head *next; } active_list; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } inode_lock; struct inode_dirents { int ref; int dir_cnt; int status; struct list_head dir_list; } dirent; struct list_head data_buf_list; } *

variable_types: ret int

return_type: int

user_defined_types: struct inode_vbfs { unsigned int i_ino; unsigned int i_pino; unsigned int i_mode; unsigned long long i_size; unsigned int i_ctime; unsigned int i_atime; unsigned int i_mtime; unsigned int i_extend; int inode_dirty; int ref; struct list_head active_list; union pthread_mutex_t inode_lock; struct inode_dirents dirent; struct list_head data_buf_list; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall file_init_default_fst(__int64 a1)
{
__int64 v1; // rbp
unsigned int v3; // edi
__int64 v4; // rax
unsigned int v5; // er12
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1;
v3 = *(_DWORD *)(a1 + 36);
v7[0] = 0;
v4 = alloc_edata_by_inode(v3, a1, v7);
v5 = v7[0];
if ( !v7[0] )
{
if ( *(_DWORD *)(v4 + 16) )
{
put_edata_by_inode(*(_DWORD *)(v1 + 36), v1);
}
else
{
log_error("%s(%d) BUG", "file_init_default_fst", 156LL);
v5 = -1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbp
unsigned int v3; // edi
__int64 v4; // rax
unsigned int v5; // er12
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1;
v3 = *(_DWORD *)(a1 + 36);
v7[0] = 0;
v4 = func5(v3, a1, v7);
v5 = v7[0];
if ( !v7[0] )
{
if ( *(_DWORD *)(v4 + 16) )
{
func9(*(_DWORD *)(v1 + 36), v1);
}
else
{
log_error("%s(%d) BUG", "file_init_default_fst", 156LL);
v5 = -1;
}
}
return v5;
}

original_code:
int file_init_default_fst(struct inode_vbfs *inode_v)
{
 struct extend_data *edata = ((void *)0);
 int ret = 0;
 edata = alloc_edata_by_inode(inode_v->i_extend, inode_v, &ret);
 if (ret)
  return ret;
 if (BUFFER_NOT_READY == edata->status) {
  do { log_error("%s(%d) " "BUG", __FUNCTION__, 156); } while(0);
  return -1;
 }
 put_edata_by_inode(inode_v->i_extend, inode_v);
 return 0;
}

variable_types: struct extend_data { unsigned int extend_no; char *buf; int status; int ref; int inode_ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } ed_lock; struct list_head { struct list_head *next; } data_list; struct list_head rq_list; struct extend_queue { struct list_head all_ed_list; union pthread_mutex_t all_ed_lock; struct list_head cache_list; union pthread_mutex_t cache_lock; void *q_private; } *equeue; } *

user_defined_types: struct extend_data { unsigned int extend_no; char *buf; int status; int ref; int inode_ref; union pthread_mutex_t ed_lock; struct list_head data_list; struct list_head rq_list; struct extend_queue *equeue; }


decompiled_code:
__int64 __fastcall vbfs_create_file(unsigned int *a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // r12
__int64 result; // rax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = *a1;
v6[0] = 0;
v4 = alloc_inode(v3, 1LL, v6);
result = v6[0];
if ( !v6[0] )
{
v6[0] = add_dirent(a1, v4, a2);
vbfs_inode_close(v4);
result = v6[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // r12
__int64 result; // rax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = *a1;
v6[0] = 0;
v4 = alloc_inode(v3, 1LL, v6);
result = v6[0];
if ( !v6[0] )
{
v6[0] = add_dirent(a1, v4, a2);
vbfs_inode_close(v4);
result = v6[0];
}
return result;
}

original_code:
int vbfs_create_file(struct inode_vbfs *v_inode_parent, const char *name)
{
 struct inode_vbfs *inode_v = ((void *)0);
 int ret = 0;
 inode_v = alloc_inode(v_inode_parent->i_ino, VBFS_FT_REG_FILE, &ret);
 if (ret) {
  return ret;
 }
 ret = add_dirent(v_inode_parent, inode_v, name);
 if (ret) {
  vbfs_inode_close(inode_v);
  return ret;
 }
 vbfs_inode_close(inode_v);
 return ret;
}

canonical_original_code:
int vbfs_create_file(struct inode_vbfs *v_inode_parent, char *name)
{
 struct inode_vbfs *inode_v = ((void *)0);
 int ret = 0;
 inode_v = alloc_inode(v_inode_parent->i_ino, VBFS_FT_REG_FILE, &ret);
 if (ret) {
  return ret;
 }
 ret = add_dirent(v_inode_parent, inode_v, name);
 if (ret) {
  vbfs_inode_close(inode_v);
  return ret;
 }
 vbfs_inode_close(inode_v);
 return ret;
}

variable_types:
name
char *

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall get_edata_by_file_idx(__int64 a1, int a2, int *a3)
{
__int64 v4; // rbp
__int64 v5; // rbx
unsigned int v7; // edi
__int64 v8; // r13
int v9; // eax
unsigned int *v10; // rbx
unsigned int v11; // edi
__int64 v12; // r13
unsigned int v14; // edi
int v15; // [rsp+8h] [rbp-30h] BYREF
unsigned int v16[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = a1;
v5 = a2;
v7 = *(_DWORD *)(a1 + 36);
v15 = 0;
v16[0] = 0;
v8 = get_edata_by_inode(v7, a1, &v15);
v9 = v15;
if ( !v15 )
{
v10 = (unsigned int *)(*(_QWORD *)(v8 + 8) + 4 * v5);
v11 = *v10;
v16[0] = v11;
if ( v11 )
{
v12 = get_edata_by_inode(v11, v4, &v15);
if ( !v15 )
{
LABEL_4:
put_edata_by_inode(*(_DWORD *)(v4 + 36), v4);
return v12;
}
}
else
{
v15 = alloc_extend_bitmap(v16);
if ( !v15 )
{
*v10 = v16[0];
v14 = v16[0];
*(_DWORD *)(v8 + 16) = 2;
v12 = alloc_edata_by_inode(v14, v4, &v15);
if ( !v15 )
goto LABEL_4;
}
}
put_edata_by_inode(*(_DWORD *)(v4 + 36), v4);
v9 = v15;
}
*a3 = v9;
return 0LL;
}

original_code:
struct extend_data *get_edata_by_file_idx(struct inode_vbfs *inode_v, int index, int *err_no)
{
 int ret = 0;
 struct extend_data *edata = ((void *)0), *new_edata = ((void *)0);
 __u32 *p_index = ((void *)0);
 __u32 extend_no = 0;
 edata = get_edata_by_inode(inode_v->i_extend, inode_v, &ret);
 if (ret) {
  *err_no = ret;
  return ((void *)0);
 }
 p_index = (__u32 *) edata->buf;
 p_index += index;
 extend_no = ((__u32)(*p_index));
 if (extend_no == 0) {
  ret = alloc_extend_bitmap(&extend_no);
  if (ret) {
   put_edata_by_inode(inode_v->i_extend, inode_v);
   *err_no = ret;
   return ((void *)0);
  }
  *p_index = ((__u32)(extend_no));
  edata->status = BUFFER_DIRTY;
  new_edata = alloc_edata_by_inode(extend_no, inode_v, &ret);
  if (ret) {
   put_edata_by_inode(inode_v->i_extend, inode_v);
   *err_no = ret;
   return ((void *)0);
  }
 } else {
  new_edata = get_edata_by_inode(extend_no, inode_v, &ret);
  if (ret) {
   put_edata_by_inode(inode_v->i_extend, inode_v);
   *err_no = ret;
   return ((void *)0);
  }
 }
 put_edata_by_inode(inode_v->i_extend, inode_v);
 return new_edata;
}

canonical_original_code:
struct extend_data *get_edata_by_file_idx(struct inode_vbfs *inode_v, int index, int *err_no)
{
 int ret = 0;
 struct extend_data *edata = ((void *)0); struct extend_data *new_edata = ((void *)0);
 unsigned int *p_index = ((void *)0);
 unsigned int extend_no = 0;
 edata = get_edata_by_inode(inode_v->i_extend, inode_v, &ret);
 if (ret) {
  *err_no = ret;
  return ((void *)0);
 }
 p_index = (unsigned int *) edata->buf;
 p_index += index;
 extend_no = ((__u32)(*p_index));
 if (extend_no == 0) {
  ret = alloc_extend_bitmap(&extend_no);
  if (ret) {
   put_edata_by_inode(inode_v->i_extend, inode_v);
   *err_no = ret;
   return ((void *)0);
  }
  *p_index = ((__u32)(extend_no));
  edata->status = BUFFER_DIRTY;
  new_edata = alloc_edata_by_inode(extend_no, inode_v, &ret);
  if (ret) {
   put_edata_by_inode(inode_v->i_extend, inode_v);
   *err_no = ret;
   return ((void *)0);
  }
 } else {
  new_edata = get_edata_by_inode(extend_no, inode_v, &ret);
  if (ret) {
   put_edata_by_inode(inode_v->i_extend, inode_v);
   *err_no = ret;
   return ((void *)0);
  }
 }
 put_edata_by_inode(inode_v->i_extend, inode_v);
 return new_edata;
}

variable_types: struct inode_vbfs { unsigned int i_ino; unsigned int i_pino; unsigned int i_mode; unsigned long long i_size; unsigned int i_ctime; unsigned int i_atime; unsigned int i_mtime; unsigned int i_extend; int inode_dirty; int ref; struct list_head active_list; union pthread_mutex_t inode_lock; struct inode_dirents { int ref; int dir_cnt; int status; struct list_head dir_list; } dirent; struct list_head data_buf_list; } *

variable_types: index int

return_type: struct extend_data { unsigned int extend_no; char *buf; int status; int ref; int inode_ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } ed_lock; struct list_head { struct list_head *next; } data_list; struct list_head rq_list; struct extend_queue { struct list_head all_ed_list; union pthread_mutex_t all_ed_lock; struct list_head cache_list; union pthread_mutex_t cache_lock; void *q_private; } *equeue; } *


decompiled_code:
__int64 __fastcall vbfs_create_file_fullpath(char *s)
{
char *v1; // rax
char *v2; // rbp
__int64 v3; // rax
unsigned int v4; // er14
__int64 v5; // r12
unsigned int v7; // [rsp+Ch] [rbp-20Ch] BYREF
char v8[464]; // [rsp+10h] [rbp-208h] BYREF
__int16 v9; // [rsp+1E0h] [rbp-38h]
unsigned __int64 v10; // [rsp+1E8h] [rbp-30h]

v10 = __readfsqword(0x28u);
v7 = 0;
memset(v8, 0, sizeof(v8));
v9 = 0;
v1 = strdup(s);
if ( !v1 )
return (unsigned int)-12;
v2 = v1;
v7 = get_lastname(v1, v8, 47LL);
if ( v7 )
{
v4 = -22;
free(v2);
}
else if ( v8[0] )
{
v3 = vbfs_pathname_to_inode(v2, &v7);
v4 = v7;
v5 = v3;
if ( v7 )
{
free(v2);
}
else
{
free(v2);
v7 = vbfs_create_file(v5, v8);
vbfs_inode_update_times(v5, 3LL);
vbfs_inode_close(v5);
v4 = v7;
}
}
else
{
v4 = -17;
free(v2);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *s)
{
char *v1; // rax
char *v2; // rbp
__int64 v3; // rax
unsigned int v4; // er14
__int64 v5; // r12
unsigned int v7; // [rsp+Ch] [rbp-20Ch] BYREF
char v8[464]; // [rsp+10h] [rbp-208h] BYREF
__int16 v9; // [rsp+1E0h] [rbp-38h]
unsigned __int64 v10; // [rsp+1E8h] [rbp-30h]

v10 = __readfsqword(0x28u);
v7 = 0;
memset(v8, 0, sizeof(v8));
v9 = 0;
v1 = strdup(s);
if ( !v1 )
return (unsigned int)-12;
v2 = v1;
v7 = get_lastname(v1, v8, 47LL);
if ( v7 )
{
v4 = -22;
free(v2);
}
else if ( v8[0] )
{
v3 = vbfs_pathname_to_inode(v2, &v7);
v4 = v7;
v5 = v3;
if ( v7 )
{
free(v2);
}
else
{
free(v2);
v7 = vbfs_create_file(v5, v8);
vbfs_inode_update_times(v5, 3LL);
vbfs_inode_close(v5);
v4 = v7;
}
}
else
{
v4 = -17;
free(v2);
}
return v4;
}

original_code:
static int vbfs_create_file_fullpath(const char *path)
{
 int ret = 0;
 struct inode_vbfs *v_inode_parent = ((void *)0);
 char last_name[466];
 char *name = ((void *)0);
 char *pos = ((void *)0);
 memset(last_name, 0, sizeof(last_name));
 name = strdup(path);
 if (((void *)0) == name) {
  return -12;
 }
 pos = name;
 ret = get_lastname(pos, last_name, '/');
 if (ret) {
  free(name);
  return -22;
 }
 if (strlen(last_name) == 0) {
  free(name);
  return -17;
 }
 v_inode_parent = vbfs_pathname_to_inode(pos, &ret);
 if (ret) {
  free(name);
  return ret;
 }
 free(name);
 ret = vbfs_create_file(v_inode_parent, last_name);
 vbfs_inode_update_times(v_inode_parent, UPDATE_ATIME | UPDATE_MTIME);
 vbfs_inode_close(v_inode_parent);
 if (ret) {
  return ret;
 }
 return 0;
}

canonical_original_code:
static int vbfs_create_file_fullpath(char *path)
{
 int ret = 0;
 struct inode_vbfs *v_inode_parent = ((void *)0);
 char last_name[466];
 char *name = ((void *)0);
 char *pos = ((void *)0);
 memset(last_name, 0, sizeof(last_name));
 name = strdup(path);
 if (((void *)0) == name) {
  return -12;
 }
 pos = name;
 ret = get_lastname(pos, last_name, '/');
 if (ret) {
  free(name);
  return -22;
 }
 if (strlen(last_name) == 0) {
  free(name);
  return -17;
 }
 v_inode_parent = vbfs_pathname_to_inode(pos, &ret);
 if (ret) {
  free(name);
  return ret;
 }
 free(name);
 ret = vbfs_create_file(v_inode_parent, last_name);
 vbfs_inode_update_times(v_inode_parent, UPDATE_ATIME | UPDATE_MTIME);
 vbfs_inode_close(v_inode_parent);
 if (ret) {
  return ret;
 }
 return 0;
}

variable_types:
path
char *

variable_types:
pos
char *


decompiled_code:
int ctx_equeue_init()
{
equeue_init_constprop_0((unsigned int)((_DWORD)&vbfs_ctx + 208));
equeue_init_constprop_0((unsigned int)((_DWORD)&vbfs_ctx + 328));
equeue_init_constprop_0((unsigned int)((_DWORD)&vbfs_ctx + 448));
return equeue_init_constprop_0((unsigned int)((_DWORD)&vbfs_ctx + 568));
}

canonical_decompiled_code:
int func24()
{
func23((unsigned int)((_DWORD)&vbfs_ctx + 208));
func23((unsigned int)((_DWORD)&vbfs_ctx + 328));
func23((unsigned int)((_DWORD)&vbfs_ctx + 448));
return func23((unsigned int)((_DWORD)&vbfs_ctx + 568));
}

original_code:
static void ctx_equeue_init()
{
 equeue_init(&vbfs_ctx.extend_bm_queue, ((void *)0));
 equeue_init(&vbfs_ctx.inode_bm_queue, ((void *)0));
 equeue_init(&vbfs_ctx.inode_queue, ((void *)0));
 equeue_init(&vbfs_ctx.data_queue, ((void *)0));
}

return_type: void


decompiled_code:
// attributes: thunk
void *__fastcall mp_malloc(size_t size)
{
return Malloc(size);
}

canonical_decompiled_code:
void *__fastcall func5(size_t size)
{
return func4(size);
}

original_code:
void *mp_malloc(unsigned int size)
{
 return Malloc(size);
}

variable_types:
size
unsigned int

return_type: void *


decompiled_code:
// attributes: thunk
void *__fastcall mp_valloc(size_t size)
{
return Valloc(size);
}

canonical_decompiled_code:
void *__fastcall func6(size_t size)
{
return func3(size);
}

original_code:
void *mp_valloc(unsigned int size)
{
 return Valloc(size);
}


decompiled_code:
// attributes: thunk
void mp_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func7(void *ptr)
{
free(ptr);
}

original_code:
void mp_free(void *p)
{
 free(p);
}

canonical_original_code:
void mp_free(void *p)
{
 free(p);
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall bitmap_get_bit(unsigned __int64 *a1, unsigned __int64 a2)
{
_BOOL4 v2; // eax
_BOOL4 *v3; // r8

if ( *a1 <= a2 )
return 0xFFFFFFFFLL;
v2 = bitmap_is_set_isra_0(a1[2], a2);
*v3 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int64 *a1, unsigned __int64 a2)
{
_BOOL4 v2; // eax
_BOOL4 *v3; // r8

if ( *a1 <= a2 )
return 0xFFFFFFFFLL;
v2 = func2(a1[2], a2);
*v3 = v2;
return 0LL;
}

original_code:
int bitmap_get_bit(struct vbfs_bitmap *bitmap, size_t bit, int *result)
{
 if (bitmap->max_bit <= bit)
  return -1;
 *result = bitmap_is_set(bitmap, bit);
 return 0;
}

canonical_original_code:
int bitmap_get_bit(struct vbfs_bitmap *bitmap, unsigned long bit, int *result)
{
 if (bitmap->max_bit <= bit)
  return -1;
 *result = bitmap_is_set(bitmap, bit);
 return 0;
}

variable_types: struct vbfs_bitmap { unsigned long max_bit; unsigned long map_len; unsigned int *bitmap; } *

variable_types:
bit
unsigned long

variable_types:
result
int *


decompiled_code:
__int64 __fastcall write_to_disk(int fd, void *buf, __off64_t offset, size_t n)
{
__int64 result; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax

if ( lseek64(fd, offset, 0) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_error("%s(%d) lseek error %s\n", "write_to_disk", 54LL, v7);
result = 0xFFFFFFFFLL;
}
else if ( write(fd, buf, n) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_error("%s(%d) write error %s\n", "write_to_disk", 58LL, v9);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, void *buf, __off64_t offset, size_t n)
{
__int64 result; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax

if ( lseek64(fd, offset, 0) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_error("%s(%d) lseek error %s\n", "write_to_disk", 54LL, v7);
result = 0xFFFFFFFFLL;
}
else if ( write(fd, buf, n) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_error("%s(%d) write error %s\n", "write_to_disk", 58LL, v9);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int write_to_disk(int fd, void *buf, uint64_t offset, size_t len)
{
 if (lseek64(fd, offset, 0) < 0) {
  do { log_error("%s(%d) " "lseek error %s\n", __FUNCTION__, 54, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 if (write(fd, buf, len) < 0) {
  do { log_error("%s(%d) " "write error %s\n", __FUNCTION__, 58, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 return 0;
}

canonical_original_code:
int write_to_disk(int fd, void *buf, unsigned long offset, unsigned long len)
{
 if (lseek64(fd, offset, 0) < 0) {
  do { log_error("%s(%d) " "lseek error %s\n", __FUNCTION__, 54, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 if (write(fd, buf, len) < 0) {
  do { log_error("%s(%d) " "write error %s\n", __FUNCTION__, 58, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 return 0;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
offset
unsigned long

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall read_from_disk(int fd, void *buf, __off64_t offset, size_t nbytes)
{
__int64 result; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax

if ( lseek64(fd, offset, 0) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_error("%s(%d) lseek error %s\n", "read_from_disk", 68LL, v7);
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, nbytes) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_error("%s(%d) read error %s\n", "read_from_disk", 72LL, v9);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, void *buf, __off64_t offset, size_t nbytes)
{
__int64 result; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax

if ( lseek64(fd, offset, 0) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_error("%s(%d) lseek error %s\n", "read_from_disk", 68LL, v7);
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, nbytes) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_error("%s(%d) read error %s\n", "read_from_disk", 72LL, v9);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int read_from_disk(int fd, void *buf, uint64_t offset, size_t len)
{
 if (lseek64(fd, offset, 0) < 0) {
  do { log_error("%s(%d) " "lseek error %s\n", __FUNCTION__, 68, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 if (read(fd, buf, len) < 0) {
  do { log_error("%s(%d) " "read error %s\n", __FUNCTION__, 72, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 return 0;
}

canonical_original_code:
int read_from_disk(int fd, void *buf, unsigned long offset, unsigned long len)
{
 if (lseek64(fd, offset, 0) < 0) {
  do { log_error("%s(%d) " "lseek error %s\n", __FUNCTION__, 68, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 if (read(fd, buf, len) < 0) {
  do { log_error("%s(%d) " "read error %s\n", __FUNCTION__, 72, strerror((*__errno_location ()))); } while(0);
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall write_extend(unsigned int a1, void *a2)
{
size_t v2; // r12
int v3; // eax

v2 = get_extend_size();
v3 = get_disk_fd();
return (unsigned int)-((unsigned int)write_to_disk(v3, a2, v2 * a1, v2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, void *a2)
{
size_t v2; // r12
int v3; // eax

v2 = get_extend_size();
v3 = get_disk_fd();
return (unsigned int)-((unsigned int)func8(v3, a2, v2 * a1, v2) != 0);
}

original_code:
int write_extend(uint32_t extend_no, void *buf)
{
 size_t len = get_extend_size();
 int fd = get_disk_fd();
 off64_t offset = (uint64_t)extend_no * len;
 if (write_to_disk(fd, buf, offset, len))
  return -1;
 return 0;
}

canonical_original_code:
int write_extend(unsigned int extend_no, void *buf)
{
 unsigned long len = get_extend_size();
 int fd = get_disk_fd();
 long offset = (uint64_t)extend_no * len;
 if (write_to_disk(fd, buf, offset, len))
  return -1;
 return 0;
}

variable_types: offset long


decompiled_code:
__int64 __fastcall read_extend(unsigned int a1, void *a2)
{
size_t v2; // r12
int v3; // eax

v2 = get_extend_size();
v3 = get_disk_fd();
return (unsigned int)-((unsigned int)read_from_disk(v3, a2, v2 * a1, v2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, void *a2)
{
size_t v2; // r12
int v3; // eax

v2 = get_extend_size();
v3 = get_disk_fd();
return (unsigned int)-((unsigned int)func9(v3, a2, v2 * a1, v2) != 0);
}

original_code:
int read_extend(uint32_t extend_no, void *buf)
{
 size_t len = get_extend_size();
 int fd = get_disk_fd();
 off64_t offset = (uint32_t)extend_no * len;
 if (read_from_disk(fd, buf, offset, len))
  return -1;
 return 0;
}

canonical_original_code:
int read_extend(unsigned int extend_no, void *buf)
{
 unsigned long len = get_extend_size();
 int fd = get_disk_fd();
 long offset = (uint32_t)extend_no * len;
 if (read_from_disk(fd, buf, offset, len))
  return -1;
 return 0;
}


decompiled_code:
void __fastcall register_ioengine(__int64 a1)
{
ioengine = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
ioengine = a1;
}

original_code:
void register_ioengine(struct ioengine_ops *ops)
{
 ioengine = ops;
}

variable_types: struct ioengine_ops { char *name; int (*io_init)(); int (*io_exit)(); int (*io_submit)(struct extend_buf { struct hlist_node { struct hlist_node *next; } hash_list; struct list_head { struct list_head *next; } lru_list; unsigned int eno; unsigned int real_eno; char *data; int rw; int error; unsigned int list_mode; unsigned int hold_cnt; unsigned int state; unsigned long last_accessed; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; void (*end_io_fn)(void *args); void *args; struct list_head data_list; struct queue { struct list_head lru[2]; unsigned long n_buffers[2]; struct hlist_head { struct hlist_node *first; } *cache_hash; int hash_bits; struct list_head reserved_buffers; unsigned int need_reserved_buffers; unsigned long clean_tid; int clean_stop; union pthread_mutex_t clean_lock; union pthread_cond_t free_buffer_cond; union pthread_mutex_t free_buffer_lock; union pthread_mutex_t lock; unsigned int eno_prefix; } *q; struct list_head inode_list; } *b); } *

user_defined_types: struct ioengine_ops { char *name; int (*io_init)(); int (*io_exit)(); int (*io_submit)(struct extend_buf *b); }

user_defined_types: struct extend_buf { struct hlist_node hash_list; struct list_head lru_list; unsigned int eno; unsigned int real_eno; char *data; int rw; int error; unsigned int list_mode; unsigned int hold_cnt; unsigned int state; unsigned long last_accessed; union pthread_mutex_t lock; union pthread_cond_t cond; void (*end_io_fn)(void *args); void *args; struct list_head data_list; struct queue *q; struct list_head inode_list; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct queue { struct list_head lru[2]; unsigned long n_buffers[2]; struct hlist_head *cache_hash; int hash_bits; struct list_head reserved_buffers; unsigned int need_reserved_buffers; unsigned long clean_tid; int clean_stop; union pthread_mutex_t clean_lock; union pthread_cond_t free_buffer_cond; union pthread_mutex_t free_buffer_lock; union pthread_mutex_t lock; unsigned int eno_prefix; }


repo: salmon/workdemo

decompiled_code:
unsigned __int64 __fastcall tf_to_lba(_BYTE *a1)
{
int v1; // edx
unsigned __int64 result; // rax

v1 = (unsigned __int8)a1[7] | ((unsigned __int8)a1[8] << 8) | ((unsigned __int8)a1[9] << 16);
if ( a1[4] )
result = v1 | ((unsigned __int64)((unsigned __int8)a1[12] | ((unsigned __int8)a1[13] << 8) | ((unsigned __int8)a1[14] << 16)) << 24);
else
result = v1 | ((unsigned __int64)(*a1 & 0xF) << 24);
return result;
}

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

v1 = (unsigned __int8)a1[7] | ((unsigned __int8)a1[8] << 8) | ((unsigned __int8)a1[9] << 16);
if ( a1[4] )
result = v1 | ((unsigned __int64)((unsigned __int8)a1[12] | ((unsigned __int8)a1[13] << 8) | ((unsigned __int8)a1[14] << 16)) << 24);
else
result = v1 | ((unsigned __int64)(*a1 & 0xF) << 24);
return result;
}

original_code:
static __u64 tf_to_lba(struct ata_tf *tf)
{
 __u32 lba24, lbah;
 __u64 lba64;
 lba24 = (tf->lob.lbah << 16) | (tf->lob.lbam << 8) | (tf->lob.lbal);
 if (tf->is_lba48)
  lbah = (tf->hob.lbah << 16) | (tf->hob.lbam << 8) | (tf->hob.lbal);
 else
  lbah = (tf->dev & 0x0f);
 lba64 = (((__u64)lbah) << 24) | (__u64)lba24;
 return lba64;
}

canonical_original_code:
static unsigned long long tf_to_lba(struct ata_tf *tf)
{
 unsigned int lba24; unsigned int lbah;
 unsigned long long lba64;
 lba24 = (tf->lob.lbah << 16) | (tf->lob.lbam << 8) | (tf->lob.lbal);
 if (tf->is_lba48)
  lbah = (tf->hob.lbah << 16) | (tf->hob.lbam << 8) | (tf->hob.lbal);
 else
  lbah = (tf->dev & 0x0f);
 lba64 = (((unsigned long long)lbah) << 24) | (unsigned long long)lba24;
 return lba64;
}

variable_types: struct ata_tf { unsigned char dev; unsigned char command; unsigned char error; unsigned char status; unsigned char is_lba48; struct ata_lba_regs { unsigned char feat; unsigned char nsect; unsigned char lbal; unsigned char lbam; unsigned char lbah; } lob; struct ata_lba_regs hob; } *

variable_types:
lbah
unsigned int

return_type: unsigned long long

user_defined_types: struct ata_tf { unsigned char dev; unsigned char command; unsigned char error; unsigned char status; unsigned char is_lba48; struct ata_lba_regs lob; struct ata_lba_regs hob; }


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

memset(&args_0, 0, 0x200uLL);
args_0 = -20;
byte_2C3 = 1;
*((_DWORD *)&args_0 + 128) = 0;
result = do_drive_cmd_constprop_0(a1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*a2 = qword_2C4;
a2[63] = qword_4BC;
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&qword_2C4 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 512) >> 3));
return result;
}

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

memset(&args_0, 0, 0x200uLL);
args_0 = -20;
byte_2C3 = 1;
*((_DWORD *)&args_0 + 128) = 0;
result = func2(a1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*a2 = qword_2C4;
a2[63] = qword_4BC;
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&qword_2C4 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 512) >> 3));
return result;
}

original_code:
int get_identify_data(int fd, __u16 *id)
{
 static __u8 args[4+512];
 int i;
 memset(args, 0, sizeof(args));
 args[0] = (0xec);
 args[3] = 1;
 if (do_drive_cmd(fd, args, 0))
  return -1;
 memcpy(id, (void *)(args + 4), 512);
 for (i = 0; i < 0x100; ++i)
  do { (void)(id[i]); } while (0);
 return 0;
}

canonical_original_code:
int get_identify_data(int fd, unsigned short *id)
{
 static unsigned char args[-1];
 int i;
 memset(args, 0, sizeof(args));
 args[0] = (0xec);
 args[3] = 1;
 if (do_drive_cmd(fd, args, 0))
  return -1;
 memcpy(id, (void *)(args + 4), 512);
 for (i = 0; i < 0x100; ++i)
  do { (void)(id[i]); } while (0);
 return 0;
}

variable_types:
id
unsigned short *

variable_types:
args
unsigned char [-1]

variable_types: i int


main

canonical_name: main

repo: salviati/ips

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 v4; // r12
char *v5; // rbp
int v6; // ebx
int v7; // eax
int v9; // eax
int v10; // ebp
int *v11; // rax
char *v12; // rax

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "acvr:m:i:hLV");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'L':
display_license();
exit(0);
case 'V':
display_version();
exit(0);
case 'a':
v6 = 1;
break;
case 'c':
v6 = 2;
break;
case 'h':
display_usage();
exit(0);
case 'i':
v4 = optarg;
break;
case 'm':
v3 = optarg;
break;
case 'r':
case 'v':
v5 = (char *)optarg;
break;
default:
continue;
}
}
if ( v6 == 1 )
{
if ( v5 )
{
if ( v4 )
{
v10 = ips_apply(v5);
if ( !v10 )
return 0;
goto LABEL_20;
}
LABEL_27:
error("no IPS file specified\n");
}
LABEL_29:
error("no rom file specified\n");
}
if ( v6 == 2 )
{
if ( v5 )
{
if ( !v3 )
error("no modified rom file specified\n");
if ( v4 )
{
v9 = ips_create(v5, v3, v4);
v10 = v9;
if ( !v9 )
return 0;
if ( v9 == -1 )
{
fwrite("rom lengths do not match.\n", 1uLL, 0x1AuLL, stderr);
LABEL_21:
exit(v10);
}
LABEL_20:
v11 = __errno_location();
v12 = strerror(*v11);
fprintf(stderr, "error: %s\n", v12);
goto LABEL_21;
}
goto LABEL_27;
}
goto LABEL_29;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 v4; // r12
char *v5; // rbp
int v6; // ebx
int v7; // eax
int v9; // eax
int v10; // ebp
int *v11; // rax
char *v12; // rax

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "acvr:m:i:hLV");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'L':
func9();
exit(0);
case 'V':
func7();
exit(0);
case 'a':
v6 = 1;
break;
case 'c':
v6 = 2;
break;
case 'h':
func8();
exit(0);
case 'i':
v4 = optarg;
break;
case 'm':
v3 = optarg;
break;
case 'r':
case 'v':
v5 = (char *)optarg;
break;
default:
continue;
}
}
if ( v6 == 1 )
{
if ( v5 )
{
if ( v4 )
{
v10 = func17(v5);
if ( !v10 )
return 0;
goto LABEL_20;
}
LABEL_27:
func10("no IPS file specified\n");
}
LABEL_29:
func10("no rom file specified\n");
}
if ( v6 == 2 )
{
if ( v5 )
{
if ( !v3 )
func10("no modified rom file specified\n");
if ( v4 )
{
v9 = func18(v5, v3, v4);
v10 = v9;
if ( !v9 )
return 0;
if ( v9 == -1 )
{
fwrite("rom lengths do not match.\n", 1uLL, 0x1AuLL, stderr);
LABEL_21:
exit(v10);
}
LABEL_20:
v11 = __errno_location();
v12 = strerror(*v11);
fprintf(stderr, "error: %s\n", v12);
goto LABEL_21;
}
goto LABEL_27;
}
goto LABEL_29;
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 enum {
  ACT_NONE,
  ACT_APPLY,
  ACT_CREATE
 } action = ACT_NONE;
 int c, err;
 char *ipsfile=0, *romfile=0, *modified_romfile=0;
 int verify=0;
 while((c=getopt(argc, argv, "acvr:m:i:hLV")) != (-1))
 {
  switch(c)
  {
   case 'a':
    action = ACT_APPLY;
   break;
   case 'c':
    action = ACT_CREATE;
   break;
   case 'v':
    verify = 1;
   case 'r':
    romfile = optarg;
   break;
   case 'm':
    modified_romfile = optarg;
   break;
   case 'i':
    ipsfile = optarg;
   break;
   case 'h':
    display_usage();
    exit(0);
   case 'L':
    display_license();
    exit(0);
   break;
   case 'V':
    display_version();
    exit(0);
  }
 }
 if(action == ACT_APPLY)
 {
  if(!romfile) error("no rom file specified\n");
  if(!ipsfile) error("no IPS file specified\n");
  if((err = ips_apply(romfile, ipsfile)))
  {
   fprintf(stderr, "error: %s\n", strerror((*__errno_location ())));
   exit(err);
  }
 }
 else if(action == ACT_CREATE)
 {
  if(!romfile) error("no rom file specified\n");
  if(!modified_romfile) error("no modified rom file specified\n");
  if(!ipsfile) error("no IPS file specified\n");
  if((err = ips_create(romfile, modified_romfile, ipsfile)))
  {
   if(err==-1) fprintf(stderr, "rom lengths do not match.\n");
   else fprintf(stderr, "error: %s\n", strerror((*__errno_location ())));
   exit(err);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 enum { ACT_NONE=0, ACT_APPLY=1, ACT_CREATE=2 } action = ACT_NONE;
 int c; int err;
 char *ipsfile = 0; char *romfile = 0; char *modified_romfile = 0;
 int verify = 0;
 while((c=getopt(argc, argv, "acvr:m:i:hLV")) != (-1))
 {
  switch(c)
  {
   case 'a':
    action = ACT_APPLY;
   break;
   case 'c':
    action = ACT_CREATE;
   break;
   case 'v':
    verify = 1;
   case 'r':
    romfile = optarg;
   break;
   case 'm':
    modified_romfile = optarg;
   break;
   case 'i':
    ipsfile = optarg;
   break;
   case 'h':
    display_usage();
    exit(0);
   case 'L':
    display_license();
    exit(0);
   break;
   case 'V':
    display_version();
    exit(0);
  }
 }
 if(action == ACT_APPLY)
 {
  if(!romfile) error("no rom file specified\n");
  if(!ipsfile) error("no IPS file specified\n");
  if((err = ips_apply(romfile, ipsfile)))
  {
   fprintf(stderr, "error: %s\n", strerror((*__errno_location ())));
   exit(err);
  }
 }
 else if(action == ACT_CREATE)
 {
  if(!romfile) error("no rom file specified\n");
  if(!modified_romfile) error("no modified rom file specified\n");
  if(!ipsfile) error("no IPS file specified\n");
  if((err = ips_create(romfile, modified_romfile, ipsfile)))
  {
   if(err==-1) fprintf(stderr, "rom lengths do not match.\n");
   else fprintf(stderr, "error: %s\n", strerror((*__errno_location ())));
   exit(err);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: err int

variable_types:
ipsfile
char *

variable_types:
romfile
char *

variable_types: verify int


decompiled_code:
int display_version()
{
return fprintf(stdout, "%s %s (%s)\n", "ips", "0.0.1", "May 23 2025");
}

original_code:
static void display_version()
{
 fprintf(stdout, "%s %s (%s)\n", "ips", "0.0.1", "Apr 24 2024");
}


decompiled_code:
size_t display_usage()
{
fprintf(stdout, "%s\n", "ips");
fwrite("A utility for appyling & creating IPS patches.\n\n", 1uLL, 0x30uLL, stdout);
fprintf(stdout, "usage: %s [-hLV] -a|c -r <romfile> -m <modified_romfile> -i <ipsfile>\n\n", "ips");
fwrite("-a apply IPS patch\n", 1uLL, 0x1FuLL, stderr);
fwrite("-c create IPS patch\n", 1uLL, 0x20uLL, stderr);
fwrite("-h create IPS patch\n", 1uLL, 0x20uLL, stderr);
fwrite("-i <ipsfile> set IPS patch filename\n", 1uLL, 0x26uLL, stderr);
fwrite("-L display software license and quit\n", 1uLL, 0x31uLL, stderr);
fwrite("-m <mromfile> set modified rom filename (only with -c)\n", 1uLL, 0x38uLL, stderr);
fwrite("-r <romfile> set original rom filename\n", 1uLL, 0x29uLL, stderr);
fwrite("-v verify integrity of IPS file\n", 1uLL, 0x2CuLL, stderr);
return fwrite("-V display version info and quit\n", 1uLL, 0x2DuLL, stderr);
}

canonical_decompiled_code:
size_t func8()
{
fprintf(stdout, "%s\n", "ips");
fwrite("A utility for appyling & creating IPS patches.\n\n", 1uLL, 0x30uLL, stdout);
fprintf(stdout, "usage: %s [-hLV] -a|c -r <romfile> -m <modified_romfile> -i <ipsfile>\n\n", "ips");
fwrite("-a apply IPS patch\n", 1uLL, 0x1FuLL, stderr);
fwrite("-c create IPS patch\n", 1uLL, 0x20uLL, stderr);
fwrite("-h create IPS patch\n", 1uLL, 0x20uLL, stderr);
fwrite("-i <ipsfile> set IPS patch filename\n", 1uLL, 0x26uLL, stderr);
fwrite("-L display software license and quit\n", 1uLL, 0x31uLL, stderr);
fwrite("-m <mromfile> set modified rom filename (only with -c)\n", 1uLL, 0x38uLL, stderr);
fwrite("-r <romfile> set original rom filename\n", 1uLL, 0x29uLL, stderr);
fwrite("-v verify integrity of IPS file\n", 1uLL, 0x2CuLL, stderr);
return fwrite("-V display version info and quit\n", 1uLL, 0x2DuLL, stderr);
}

original_code:
static void display_usage()
{
 fprintf(stdout, "%s\n", "ips");
 fprintf(stdout, "A utility for appyling & creating IPS patches.\n\n");
 fprintf(stdout, "usage: %s [-hLV] -a|c -r <romfile> -m <modified_romfile> -i <ipsfile>\n\n", "ips");
 fprintf(stderr, "-a             apply IPS patch\n");
 fprintf(stderr, "-c             create IPS patch\n");
 fprintf(stderr, "-h             create IPS patch\n");
 fprintf(stderr, "-i <ipsfile>   set IPS patch filename\n");
 fprintf(stderr, "-L             display software license and quit\n");
 fprintf(stderr, "-m <mromfile>  set modified rom filename (only with -c)\n");
 fprintf(stderr, "-r <romfile>   set original rom filename\n");
 fprintf(stderr, "-v             verify integrity of IPS file\n");
 fprintf(stderr, "-V             display version info and quit\n");
}


decompiled_code:
size_t display_license()
{
fwrite("You may redistribute copies of this program\n", 1uLL, 0x2CuLL, stdout);
fwrite("under the terms of the GNU General Public License.\n", 1uLL, 0x33uLL, stdout);
fwrite("For more information about these matters, see the file named COPYING.\n", 1uLL, 0x46uLL, stdout);
return fwrite("Report bugs to <bug@freeconsole.org>.\n", 1uLL, 0x26uLL, stdout);
}

canonical_decompiled_code:
size_t func9()
{
fwrite("You may redistribute copies of this program\n", 1uLL, 0x2CuLL, stdout);
fwrite("under the terms of the GNU General Public License.\n", 1uLL, 0x33uLL, stdout);
fwrite("For more information about these matters, see the file named COPYING.\n", 1uLL, 0x46uLL, stdout);
return fwrite("Report bugs to <bug@freeconsole.org>.\n", 1uLL, 0x26uLL, stdout);
}

original_code:
static void display_license()
{
 fprintf(stdout, "You may redistribute copies of this program\n");
 fprintf(stdout, "under the terms of the GNU General Public License.\n");
 fprintf(stdout, "For more information about these matters, see the file named COPYING.\n");
 fprintf(stdout, "Report bugs to <bug@freeconsole.org>.\n");
}


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

original_code:
static void error(const char *s)
{
 fprintf(stderr, "%s", s);
 exit(1);
}

canonical_original_code:
static void error(char *s)
{
 fprintf(stderr, "%s", s);
 exit(1);
}

variable_types:
s
char *


ra

original_code:
static unsigned int ra(const void *p)
{
 unsigned char *s = (unsigned char *)p;
 return s[2] | (s[1]<<8) | (s[0]<<16);
}

canonical_original_code:
static unsigned int ra(void *p)
{
 unsigned char *s = (unsigned char *)p;
 return s[2] | (s[1]<<8) | (s[0]<<16);
}

variable_types:
p
void *

variable_types:
s
unsigned char *

return_type: unsigned int


rs

decompiled_code:
__int64 __fastcall rs(_WORD *a1)
{
return (unsigned __int16)__ROL2__(*a1, 8);
}

canonical_decompiled_code:
__int64 __fastcall func12(_WORD *a1)
{
return (unsigned __int16)__ROL2__(*a1, 8);
}

original_code:
static unsigned int rs(const void *p)
{
 unsigned char *s = (unsigned char *)p;
 return s[1] | (s[0]<<8);
}

canonical_original_code:
static unsigned int rs(void *p)
{
 unsigned char *s = (unsigned char *)p;
 return s[1] | (s[0]<<8);
}


decompiled_code:
__int64 __fastcall ips_apply_mem(__int64 a1, __int64 a2, __int64 a3, int a4)
{
unsigned __int64 v4; // rbp
char *v5; // rbx
_WORD *v6; // rdi
unsigned int v7; // eax
unsigned int v8; // edx

v4 = a3 + a4 - 2;
v5 = (char *)(a3 + 5);
if ( v4 > a3 + 5 )
{
do
{
ra((unsigned __int8 *)v5);
v6 = v5 + 2;
v5 += 5;
v7 = rs(v6);
memcpy((void *)v8, v5, v7);
}
while ( (unsigned __int64)v5 < v4 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3, int a4)
{
unsigned __int64 v4; // rbp
char *v5; // rbx
_WORD *v6; // rdi
unsigned int v7; // eax
unsigned int v8; // edx

v4 = a3 + a4 - 2;
v5 = (char *)(a3 + 5);
if ( v4 > a3 + 5 )
{
do
{
func11((unsigned __int8 *)v5);
v6 = v5 + 2;
v5 += 5;
v7 = func12(v6);
memcpy((void *)v8, v5, v7);
}
while ( (unsigned __int64)v5 < v4 );
}
return 0LL;
}

original_code:
int ips_apply_mem(void *rom, int rom_size, const void *ips, int ips_size)
{
 char *p=(char*)ips, *end, *dst=(char*)dst;
 unsigned int adr,size;
 end = p + (ips_size - strlen("PATCH") + strlen("EOF")) ;
 p += strlen("PATCH");
 while(p<end)
 {
  adr = ra(p);
  p+=2;
  size = rs(p);
  p+=3;
  memcpy(dst+adr,p,size);
 }
 return 0;
}

canonical_original_code:
int ips_apply_mem(void *rom, int rom_size, void *ips, int ips_size)
{
 char *p = (char*)ips; char *end; char *dst = (char*)dst;
 unsigned int adr; unsigned int size;
 end = p + (ips_size - strlen("PATCH") + strlen("EOF")) ;
 p += strlen("PATCH");
 while(p<end)
 {
  adr = ra(p);
  p+=2;
  size = rs(p);
  p+=3;
  memcpy(dst+adr,p,size);
 }
 return 0;
}

variable_types:
rom
void *

variable_types:
ips
void *

variable_types:
p
char *

variable_types:
end
char *

variable_types:
dst
char *

variable_types:
adr
unsigned int

variable_types:
size
unsigned int


original_code:
int ips_create_mem(const void *rom, int rom_size, const void *modified_rom, void *_ips)
{
 char *ips = (char*)_ips;
 strcpy(ips, "PATCH");
 ips += strlen("PATCH");
 strcpy(ips,"EOF");
 return 0;
}

canonical_original_code:
int ips_create_mem(void *rom, int rom_size, void *modified_rom, void *_ips)
{
 char *ips = (char*)_ips;
 strcpy(ips, "PATCH");
 ips += strlen("PATCH");
 strcpy(ips,"EOF");
 return 0;
}

variable_types:
ips
char *


decompiled_code:
__int64 __fastcall ips_estimate(__int64 a1, __int64 a2, __int64 a3)
{
return ips_create_mem(a1, a2, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3)
{
return func15(a1, a2, a3, 0LL);
}

original_code:
int ips_estimate(const void *rom, int romsize, const void *modified_rom)
{
 return ips_create_mem(rom,romsize,modified_rom,0);
}

canonical_original_code:
int ips_estimate(void *rom, int romsize, void *modified_rom)
{
 return ips_create_mem(rom,romsize,modified_rom,0);
}

variable_types: romsize int


decompiled_code:
const char *ips_version()
{
return "0.0.1";
}

canonical_decompiled_code:
const char *func19()
{
return "0.0.1";
}

canonical_original_code:
char *ips_version()
{
 return "0.0.1";
}

return_type: char *


usage

repo: sam-github/netfilter-lua

decompiled_code:
void __noreturn usage()
{
fwrite(
"usage: expect-create-userspace [-v ] -s srcip -d dstip -f srcport -t dstport -e expectport -T timeout [-P]\n",
1uLL,
0x6BuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func10()
{
fwrite(
"usage: expect-create-userspace [-v ] -s srcip -d dstip -f srcport -t dstport -e expectport -T timeout [-P]\n",
1uLL,
0x6BuLL,
stderr);
exit(1);
}

original_code:
void usage(void)
{
    fprintf(stderr,
            "usage: expect-create-userspace [-v ] -s srcip -d dstip -f srcport -t dstport -e expectport -T timeout [-P]\n"
           );
    exit(1);
}

canonical_original_code:
void usage()
{
    fprintf(stderr,
            "usage: expect-create-userspace [-v ] -s srcip -d dstip -f srcport -t dstport -e expectport -T timeout [-P]\n"
           );
    exit(1);
}


error

repo: samaitra/unix-netwk-prog

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(0);
}

original_code:
void error(char *msg)
{
perror(msg);
exit(0);
}

variable_types:
msg
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v4; // rdi
in_addr_t v5; // eax
const char *v6; // rdi
unsigned __int16 v7; // ax
socklen_t v8; // edx
size_t v9; // rax
struct sockaddr v11; // [rsp+0h] [rbp-128h] BYREF
char s[280]; // [rsp+10h] [rbp-118h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "usage %s <IP ADDRESS> <PORT>\n", *argv);
exit(0);
}
v3 = socket(2, 1, 0);
if ( v3 < 0 )
error("ERROR opening socket");
v4 = argv[1];
v11 = 0LL;
v11.sa_family = 2;
v5 = inet_addr(v4);
v6 = argv[2];
*(_DWORD *)&v11.sa_data[2] = v5;
v7 = atoi(v6);
*(_WORD *)v11.sa_data = _bswap_16(v7, &v11, 16LL);
if ( connect(v3, &v11, v8) < 0 )
error("ERROR connecting");
puts("Connection Established");
printf("Query: ");
memset(s, 0, 0x100uLL);
fgets(s, 255, stdin);
v9 = strlen(s);
if ( (int)write(v3, s, v9) < 0 )
error("ERROR writing to socket");
memset(s, 0, 0x100uLL);
if ( (int)read(v3, s, 0xFFuLL) < 0 )
error("ERROR reading from socket");
printf("Client:%s\n", s);
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v4; // rdi
in_addr_t v5; // eax
const char *v6; // rdi
unsigned __int16 v7; // ax
socklen_t v8; // edx
size_t v9; // rax
struct sockaddr v11; // [rsp+0h] [rbp-128h] BYREF
char s[280]; // [rsp+10h] [rbp-118h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "usage %s <IP ADDRESS> <PORT>\n", *argv);
exit(0);
}
v3 = socket(2, 1, 0);
if ( v3 < 0 )
func8("ERROR opening socket");
v4 = argv[1];
v11 = 0LL;
v11.sa_family = 2;
v5 = inet_addr(v4);
v6 = argv[2];
*(_DWORD *)&v11.sa_data[2] = v5;
v7 = atoi(v6);
*(_WORD *)v11.sa_data = func7(v7, &v11, 16LL);
if ( connect(v3, &v11, v8) < 0 )
func8("ERROR connecting");
puts("Connection Established");
printf("Query: ");
memset(s, 0, 0x100uLL);
fgets(s, 255, stdin);
v9 = strlen(s);
if ( (int)write(v3, s, v9) < 0 )
func8("ERROR writing to socket");
memset(s, 0, 0x100uLL);
if ( (int)read(v3, s, 0xFFuLL) < 0 )
func8("ERROR reading from socket");
printf("Client:%s\n", s);
close(v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int sockfd, portno, n;
    struct sockaddr_in serv_addr;
    struct hostent *shost;
    char buff[256];
    if (argc < 3) { fprintf(stderr,"usage %s <IP ADDRESS> <PORT>\n", argv[0]);
     exit(0);
  }
    sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) error("ERROR opening socket");
    bzero((char *) &serv_addr, sizeof(serv_addr));
 portno = atoi(argv[2]);
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr= inet_addr(argv[1]);
   serv_addr.sin_port = htons(atoi(argv[2]));
   if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0)
       error("ERROR connecting");
       printf("Connection Established\n");
       printf("Query: ");
     bzero(buff,256);
    fgets(buff,255,stdin);
  n = write(sockfd,buff,strlen(buff));
     if (n < 0) error("ERROR writing to socket");
      bzero(buff,256);
  n = read(sockfd,buff,255);
    if (n < 0) error("ERROR reading from socket");
   printf("Client:%s\n",buff);
close(sockfd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int sockfd; int portno; int n;
    struct sockaddr_in serv_addr;
    struct hostent *shost;
    char buff[256];
    if (argc < 3) { fprintf(stderr,"usage %s <IP ADDRESS> <PORT>\n", argv[0]);
     exit(0);
  }
    sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) error("ERROR opening socket");
    bzero((char *) &serv_addr, sizeof(serv_addr));
 portno = atoi(argv[2]);
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr= inet_addr(argv[1]);
   serv_addr.sin_port = htons(atoi(argv[2]));
   if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0)
       error("ERROR connecting");
       printf("Connection Established\n");
       printf("Query: ");
     bzero(buff,256);
    fgets(buff,255,stdin);
  n = write(sockfd,buff,strlen(buff));
     if (n < 0) error("ERROR writing to socket");
      bzero(buff,256);
  n = read(sockfd,buff,255);
    if (n < 0) error("ERROR reading from socket");
   printf("Client:%s\n",buff);
close(sockfd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sockfd int

variable_types: portno int

variable_types: n 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: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
buff
char [256]

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:
void __fastcall sig_stp(unsigned int a1)
{
printf("Pressed ctrl-z");
printf("\nReceived SIGSTOP signal %d\n", a1);
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1)
{
printf("Pressed ctrl-z");
printf("\nReceived SIGSTOP signal %d\n", a1);
}

original_code:
void sig_stp(int signo) {
    printf("Pressed ctrl-z");
     printf("\nReceived SIGSTOP signal %d\n", signo);
}

variable_types: signo int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *i; // rbx
__pid_t v4; // eax
unsigned int v5; // eax
char *j; // rbx
__pid_t v7; // eax
__int64 v8; // rsi
__pid_t v9; // eax
char *v10; // rbp
char *v11; // rbp
char v12[32]; // [rsp+0h] [rbp-58h] BYREF
__m128i v13; // [rsp+20h] [rbp-38h]
__int128 v14; // [rsp+30h] [rbp-28h]

v13 = _mm_load_si128((const __m128i *)&xmmword_402120);
v14 = 0LL;
signal(2, sig_int);
signal(19, sig_stp);
while ( 1 )
{
while ( 1 )
{
puts("Enter command:");
__isoc99_scanf();
puts("Enter execution style, valid types are sequential(s) or parallel(p):");
__isoc99_scanf();
if ( (v13.m128i_i8[0] & 0xDF) == 83 )
break;
if ( (v13.m128i_i8[0] & 0xDF) == 80 )
goto LABEL_10;
}
for ( i = strtok(v12, ";"); i; i = strtok(0LL, ";") )
{
while ( 1 )
{
v4 = fork();
if ( v4 )
break;
while ( i[(int)strlen(i) - 1] != 38 )
{
printf("Executing command %s\n", i);
execlp(i, i, 0LL);
v4 = fork();
if ( v4 )
goto LABEL_8;
}
v10 = strtok(i, "&");
if ( v10 )
{
printf("Executing command in background %s\n", i);
execlp(v10, "&", 0LL);
}
}
LABEL_8:
v5 = waitpid(v4, 0LL, 0);
printf("PID of terminated Child:%d\n", v5);
}
if ( (v13.m128i_i8[0] & 0xDF) == 80 )
{
LABEL_10:
for ( j = strtok(v12, ";"); j; j = strtok(0LL, ";") )
{
while ( !fork() )
{
while ( j[(int)strlen(j) - 1] != 38 )
{
printf("Executing command %s\n", j);
execlp(j, j, 0LL);
if ( fork() )
goto LABEL_14;
}
v11 = strtok(j, "&");
if ( v11 )
{
printf("Executing command in background %s\n", j);
execlp(v11, "&", 0LL);
}
}
LABEL_14:
;
}
v7 = wait(0LL);
v8 = (unsigned int)v7;
if ( v7 > 0 )
{
do
{
printf("PID of terminated Child:%d\n", v8);
v9 = wait(0LL);
v8 = (unsigned int)v9;
}
while ( v9 > 0 );
}
}
}
}

original_code:
int main(int argc, char *argv[]) {
 char commands[32];
 char style[32] = "sequential";
 pid_t pid;
 int rid;
 char *token;
 char *bgjob;
 signal(2, sig_int);
 signal(19, sig_stp);
 for(;;){
 printf("Enter command:\n");
 scanf("%s", commands);
 printf("Enter execution style, valid types are sequential(s) or parallel(p):\n");
 scanf("%s", style);
 if (style[0] == 's' || style[0] == 'S') {
  token = strtok(commands, ";");
  while (token != ((void *)0) ) {
   pid = fork();
   if (pid == 0) {
    int len = strlen(token);
    char last = token[len - 1];
    if (last == '&') {
     bgjob = strtok(token, "&");
     if (bgjob != ((void *)0) ) {
      printf("Executing command in background %s\n", token);
      execlp(bgjob, "&", ((void *)0) );
     }
    } else {
     printf("Executing command %s\n", token);
     execlp(token, token, ((void *)0) );
     }
    }
    else {
    rid = waitpid(pid, 0, 0);
    printf("PID of terminated Child:%d\n", rid);
    token = strtok(((void *)0), ";");
   }
  }
 }
 if (style[0] == 'p' || style[0] == 'P') {
  token = strtok(commands, ";");
  while (token != ((void *)0) ) {
   pid = fork();
   if (pid == 0) {
    int len = strlen(token);
    char last = token[len - 1];
    if (last == '&') {
     bgjob = strtok(token, "&");
     if (bgjob != ((void *)0) ) {
      printf("Executing command in background %s\n", token);
      execlp(bgjob, "&", ((void *)0) );
     }
    } else {
     printf("Executing command %s\n", token);
     execlp(token, token, ((void *)0) );
    }
   } else {
    token = strtok(((void *)0), ";");
   }
  }
     while ((rid = wait(((void *)0))) > 0)
     {
      printf("PID of terminated Child:%d\n", rid);
     }
 }
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char commands[32];
 char style[32] = "sequential";
 int pid;
 int rid;
 char *token;
 char *bgjob;
 signal(2, sig_int);
 signal(19, sig_stp);
 for(;;){
 printf("Enter command:\n");
 scanf("%s", commands);
 printf("Enter execution style, valid types are sequential(s) or parallel(p):\n");
 scanf("%s", style);
 if (style[0] == 's' || style[0] == 'S') {
  token = strtok(commands, ";");
  while (token != ((void *)0) ) {
   pid = fork();
   if (pid == 0) {
    int len = strlen(token);
    char last = token[len - 1];
    if (last == '&') {
     bgjob = strtok(token, "&");
     if (bgjob != ((void *)0) ) {
      printf("Executing command in background %s\n", token);
      execlp(bgjob, "&", ((void *)0) );
     }
    } else {
     printf("Executing command %s\n", token);
     execlp(token, token, ((void *)0) );
     }
    }
    else {
    rid = waitpid(pid, 0, 0);
    printf("PID of terminated Child:%d\n", rid);
    token = strtok(((void *)0), ";");
   }
  }
 }
 if (style[0] == 'p' || style[0] == 'P') {
  token = strtok(commands, ";");
  while (token != ((void *)0) ) {
   pid = fork();
   if (pid == 0) {
    int len = strlen(token);
    char last = token[len - 1];
    if (last == '&') {
     bgjob = strtok(token, "&");
     if (bgjob != ((void *)0) ) {
      printf("Executing command in background %s\n", token);
      execlp(bgjob, "&", ((void *)0) );
     }
    } else {
     printf("Executing command %s\n", token);
     execlp(token, token, ((void *)0) );
    }
   } else {
    token = strtok(((void *)0), ";");
   }
  }
     while ((rid = wait(((void *)0))) > 0)
     {
      printf("PID of terminated Child:%d\n", rid);
     }
 }
 }
}

variable_types:
commands
char [32]

variable_types:
style
char [32]

variable_types: pid int

variable_types: rid int

variable_types:
token
char *

variable_types:
bgjob
char *

variable_types: len int

variable_types: last char


decompiled_code:
void __fastcall sig_int(unsigned int a1)
{
printf("Pressed ctrl-c");
printf("\nReceived SIGINT signal %d\n", a1);
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
printf("Pressed ctrl-c");
printf("\nReceived SIGINT signal %d\n", a1);
}

original_code:
void sig_int(int signo) {
      printf("Pressed ctrl-c");
      printf("\nReceived SIGINT signal %d\n", signo);
     }


decompiled_code:
int __fastcall str_echo(int fd)
{
char *v1; // rax
char *v2; // rax
size_t v3; // rax
__pid_t v5; // er12
unsigned int v6; // eax
char *v7; // rax
char *v8; // rax
size_t v9; // r13
__pid_t v10; // er13
unsigned int v11; // eax
int fda; // [rsp+0h] [rbp-C58h] BYREF
int v13; // [rsp+4h] [rbp-C54h]
int pipedes[2]; // [rsp+8h] [rbp-C50h] BYREF
char v15[32]; // [rsp+10h] [rbp-C48h] BYREF
char buf[256]; // [rsp+30h] [rbp-C28h] BYREF
char v17[256]; // [rsp+130h] [rbp-B28h] BYREF
char v18[256]; // [rsp+230h] [rbp-A28h] BYREF
char dest[256]; // [rsp+330h] [rbp-928h] BYREF
char src[8]; // [rsp+430h] [rbp-828h] BYREF
char *v21; // [rsp+438h] [rbp-820h]
char *v22; // [rsp+440h] [rbp-818h]
__int64 v23; // [rsp+448h] [rbp-810h]

if ( (int)read(fd, buf, 0xFFuLL) < 0 )
printf("ERROR reading from socket");
printf("Received message from Client: %s\n", buf);
v1 = strtok(buf, " \t");
strcpy(dest, v1);
v2 = strtok(0LL, " \t");
strcpy(v15, v2);
if ( v15[0] == 78 )
{
v7 = strtok(0LL, " \t");
v8 = stpcpy(v17, v7);
strncpy(v18, v17, v8 - v17 - 1);
}
printf("query %s\n", dest);
printf("type %s\n", v15);
printf("filename %s\n", v17);
if ( v15[0] != 78 )
{
if ( v15[0] != 89 )
goto LABEL_7;
pipe(&fda);
pipe(pipedes);
v5 = fork();
if ( v5 )
{
dup2(fda, 0);
close(v13);
v10 = fork();
if ( v10 )
{
close(pipedes[1]);
*(_QWORD *)&src[8 * (int)read(pipedes[0], src, 0x100uLL)] = 0LL;
v11 = waitpid(v10, 0LL, 0);
printf("Pid of terminated Child:%d\n", v11);
}
else
{
dup2(pipedes[1], 1);
close(pipedes[0]);
*(_QWORD *)src = "grep";
v21 = dest;
v22 = 0LL;
execvp("grep", (char *const *)src);
}
}
else
{
close(fda);
v9 = strlen(tempbuf);
printf("tempbuf len %d\n", (unsigned int)v9);
write(v13, tempbuf, v9);
}
goto LABEL_12;
}
pipe(pipedes);
v5 = fork();
if ( v5 )
{
close(pipedes[1]);
*(_QWORD *)&src[8 * (int)read(pipedes[0], src, 0x100uLL)] = 0LL;
LABEL_12:
v6 = waitpid(v5, 0LL, 0);
printf("Pid of terminated Child:%d\n", v6);
goto LABEL_7;
}
dup2(pipedes[1], 1);
close(pipedes[0]);
v21 = dest;
*(_QWORD *)src = "grep";
v22 = v18;
v23 = 0LL;
if ( execvp("grep", (char *const *)src) < 0 )
perror("execvp");
LABEL_7:
strcpy(tempbuf, src);
v3 = strlen(src);
if ( (int)write(fd, src, v3) < 0 )
perror("ERROR Received writing to socket");
return close(fd);
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
char *v1; // rax
char *v2; // rax
size_t v3; // rax
__pid_t v5; // er12
unsigned int v6; // eax
char *v7; // rax
char *v8; // rax
size_t v9; // r13
__pid_t v10; // er13
unsigned int v11; // eax
int fda; // [rsp+0h] [rbp-C58h] BYREF
int v13; // [rsp+4h] [rbp-C54h]
int pipedes[2]; // [rsp+8h] [rbp-C50h] BYREF
char v15[32]; // [rsp+10h] [rbp-C48h] BYREF
char buf[256]; // [rsp+30h] [rbp-C28h] BYREF
char v17[256]; // [rsp+130h] [rbp-B28h] BYREF
char v18[256]; // [rsp+230h] [rbp-A28h] BYREF
char dest[256]; // [rsp+330h] [rbp-928h] BYREF
char src[8]; // [rsp+430h] [rbp-828h] BYREF
char *v21; // [rsp+438h] [rbp-820h]
char *v22; // [rsp+440h] [rbp-818h]
__int64 v23; // [rsp+448h] [rbp-810h]

if ( (int)read(fd, buf, 0xFFuLL) < 0 )
printf("ERROR reading from socket");
printf("Received message from Client: %s\n", buf);
v1 = strtok(buf, " \t");
strcpy(dest, v1);
v2 = strtok(0LL, " \t");
strcpy(v15, v2);
if ( v15[0] == 78 )
{
v7 = strtok(0LL, " \t");
v8 = stpcpy(v17, v7);
strncpy(v18, v17, v8 - v17 - 1);
}
printf("query %s\n", dest);
printf("type %s\n", v15);
printf("filename %s\n", v17);
if ( v15[0] != 78 )
{
if ( v15[0] != 89 )
goto LABEL_7;
pipe(&fda);
pipe(pipedes);
v5 = fork();
if ( v5 )
{
dup2(fda, 0);
close(v13);
v10 = fork();
if ( v10 )
{
close(pipedes[1]);
*(_QWORD *)&src[8 * (int)read(pipedes[0], src, 0x100uLL)] = 0LL;
v11 = waitpid(v10, 0LL, 0);
printf("Pid of terminated Child:%d\n", v11);
}
else
{
dup2(pipedes[1], 1);
close(pipedes[0]);
*(_QWORD *)src = "grep";
v21 = dest;
v22 = 0LL;
execvp("grep", (char *const *)src);
}
}
else
{
close(fda);
v9 = strlen(tempbuf);
printf("tempbuf len %d\n", (unsigned int)v9);
write(v13, tempbuf, v9);
}
goto LABEL_12;
}
pipe(pipedes);
v5 = fork();
if ( v5 )
{
close(pipedes[1]);
*(_QWORD *)&src[8 * (int)read(pipedes[0], src, 0x100uLL)] = 0LL;
LABEL_12:
v6 = waitpid(v5, 0LL, 0);
printf("Pid of terminated Child:%d\n", v6);
goto LABEL_7;
}
dup2(pipedes[1], 1);
close(pipedes[0]);
v21 = dest;
*(_QWORD *)src = "grep";
v22 = v18;
v23 = 0LL;
if ( execvp("grep", (char *const *)src) < 0 )
perror("execvp");
LABEL_7:
strcpy(tempbuf, src);
v3 = strlen(src);
if ( (int)write(fd, src, v3) < 0 )
perror("ERROR Received writing to socket");
return close(fd);
}

original_code:
void str_echo(void *arg) {
 char buff[256], *ptr;
 int n;
 n = read(arg, buff, 255);
 if (n < 0)
  printf("ERROR reading from socket");
  printf("Received  message from Client: %s\n", buff);
  char type[32];
  char *filename[32];
  char *fi[32];
  char *query[32];
  strcpy(query, strtok(buff , " \t"));
  strcpy(type, strtok(((void *)0), " \t"));
  if(type[0]=='N'){
   strcpy(filename , strtok(((void *)0), " \t"));
   strncpy(fi, filename, (strlen(filename)-1));
   }
  printf("query %s\n",query);
  printf("type %s\n",type);
  printf("filename %s\n",filename);
  char* buf[256];
  if(type[0]=='N'){
   int fd[2], pid,retval,rid;
   int n;
       pipe(fd);
    pid=fork();
           if (pid==0) {
               dup2(fd[1],1);
               close(fd[0]);
               char *argv[] = { "grep", query, fi, ((void *)0)};
               if(execvp("grep", argv)<0){
               perror("execvp");
               }
           }
    else
      { close(fd[1]);
            n = read(fd[0], buf, 256);
            buf[n] = '\0';
            rid=waitpid(pid, 0, 0);
            printf("Pid of terminated Child:%d\n",rid);
      }
  }
  else if(type[0]=='Y'){
   int pfd[2], cpid,rid;
   int fd[2],cppid,rrid;
       pipe(pfd);
    pipe(fd);
       cpid=fork();
           if (cpid==0) {
               close(pfd[0]);
               int len = strlen(tempbuf);
               printf("tempbuf len %d\n",len);
               write(pfd[1],tempbuf,len);
               }
           else
           {
              dup2(pfd[0],0);
             close(pfd[1]);
             cppid = fork();
             if(cppid==0){
                  dup2(fd[1],1);
               close(fd[0]);
               char *argv[] = { "grep", query, ((void *)0)};
               execvp("grep", argv);
             }else{
              close(fd[1]);
              n = read(fd[0], buf, 256);
                    buf[n] = '\0';
                    rrid=waitpid(cppid, 0, 0);
                    printf("Pid of terminated Child:%d\n",rrid);
             }
            }
    rid=waitpid(cpid, 0, 0);
    printf("Pid of terminated Child:%d\n",rid);
  }
 strcpy(tempbuf, buf);
 n = write(arg, buf, strlen(buf));
 if (n < 0)
  perror("ERROR Received writing to socket");
 close(arg);
}

canonical_original_code:
void str_echo(void *arg) {
 char buff[256]; char *ptr;
 int n;
 n = read(arg, buff, 255);
 if (n < 0)
  printf("ERROR reading from socket");
  printf("Received  message from Client: %s\n", buff);
  char type[32];
  char *filename[32];
  char *fi[32];
  char *query[32];
  strcpy(query, strtok(buff , " \t"));
  strcpy(type, strtok(((void *)0), " \t"));
  if(type[0]=='N'){
   strcpy(filename , strtok(((void *)0), " \t"));
   strncpy(fi, filename, (strlen(filename)-1));
   }
  printf("query %s\n",query);
  printf("type %s\n",type);
  printf("filename %s\n",filename);
  char *buf[256];
  if(type[0]=='N'){
   int fd[2]; int pid; int retval; int rid;
   int n;
       pipe(fd);
    pid=fork();
           if (pid==0) {
               dup2(fd[1],1);
               close(fd[0]);
               char *argv[] = { "grep", query, fi, ((void *)0)};
               if(execvp("grep", argv)<0){
               perror("execvp");
               }
           }
    else
      { close(fd[1]);
            n = read(fd[0], buf, 256);
            buf[n] = '\0';
            rid=waitpid(pid, 0, 0);
            printf("Pid of terminated Child:%d\n",rid);
      }
  }
  else if(type[0]=='Y'){
   int pfd[2]; int cpid; int rid;
   int fd[2]; int cppid; int rrid;
       pipe(pfd);
    pipe(fd);
       cpid=fork();
           if (cpid==0) {
               close(pfd[0]);
               int len = strlen(tempbuf);
               printf("tempbuf len %d\n",len);
               write(pfd[1],tempbuf,len);
               }
           else
           {
              dup2(pfd[0],0);
             close(pfd[1]);
             cppid = fork();
             if(cppid==0){
                  dup2(fd[1],1);
               close(fd[0]);
               char *argv[] = { "grep", query, ((void *)0)};
               execvp("grep", argv);
             }else{
              close(fd[1]);
              n = read(fd[0], buf, 256);
                    buf[n] = '\0';
                    rrid=waitpid(cppid, 0, 0);
                    printf("Pid of terminated Child:%d\n",rrid);
             }
            }
    rid=waitpid(cpid, 0, 0);
    printf("Pid of terminated Child:%d\n",rid);
  }
 strcpy(tempbuf, buf);
 n = write(arg, buf, strlen(buf));
 if (n < 0)
  perror("ERROR Received writing to socket");
 close(arg);
}

variable_types:
arg
void *

variable_types:
ptr
char *

variable_types:
type
char [32]

variable_types:
filename
char *[32]

variable_types:
fi
char *[32]

variable_types:
query
char *[32]

variable_types:
buf
char *[256]

variable_types:
fd
int [2]

variable_types: retval int

variable_types:
pfd
int [2]

variable_types: cpid int

variable_types: cppid int

variable_types: rrid int


doit

decompiled_code:
void *__fastcall doit(void *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
pthread_detach(v1);
str_echo((int)a1);
close((int)a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
pthread_detach(v1);
func9((int)a1);
close((int)a1);
return 0LL;
}

original_code:
static void *
  doit(void *arg) {
   pthread_detach(pthread_self());
   str_echo((int) arg);
   close((int) arg);
   return (((void *)0) );
}

canonical_original_code:
static void *doit(void *arg) {
   pthread_detach(pthread_self());
   str_echo((int) arg);
   close((int) arg);
   return (((void *)0) );
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char *v4; // rdi
unsigned __int16 v5; // ax
socklen_t v6; // edx
int v7; // ebx
socklen_t addr_len; // [rsp+4h] [rbp-44h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-40h] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

if ( argc <= 1 )
fwrite("ERROR, no port provided\n", 1uLL, 0x18uLL, stderr);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
perror("ERROR opening socket");
v4 = argv[1];
v10 = 0LL;
v5 = atoi(v4);
v10.sa_family = 2;
*(_DWORD *)&v10.sa_data[2] = _bswap_32_constprop_0(v5, &v10, 16LL);
*(_WORD *)v10.sa_data = _bswap_16();
if ( bind(v3, &v10, v6) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
addr_len = 16;
v7 = accept(v3, &addr, &addr_len);
if ( v7 < 0 )
perror("ERROR on accept");
pthread_create(&newthread, 0LL, doit, (void *)v7);
}
}
perror("ERROR on binding");
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char *v4; // rdi
unsigned __int16 v5; // ax
socklen_t v6; // edx
int v7; // ebx
socklen_t addr_len; // [rsp+4h] [rbp-44h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-40h] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

if ( argc <= 1 )
fwrite("ERROR, no port provided\n", 1uLL, 0x18uLL, stderr);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
perror("ERROR opening socket");
v4 = argv[1];
v10 = 0LL;
v5 = atoi(v4);
v10.sa_family = 2;
*(_DWORD *)&v10.sa_data[2] = func8(v5, &v10, 16LL);
*(_WORD *)v10.sa_data = func7();
if ( bind(v3, &v10, v6) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
addr_len = 16;
v7 = accept(v3, &addr, &addr_len);
if ( v7 < 0 )
perror("ERROR on accept");
pthread_create(&newthread, 0LL, doit, (void *)v7);
}
}
perror("ERROR on binding");
exit(0);
}

original_code:
int main(int argc, char *argv[]) {
 int sockfd, newsockfd, portno, clilen;
 char buff[256], *ptr;
 struct sockaddr_in serv_addr, cli_addr;
 pthread_t tid;
 int n;
 const int on = 1;
 if (argc < 2) {
  fprintf(stderr, "ERROR, no port provided\n");
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  perror("ERROR opening socket");
 bzero((char *) &serv_addr, sizeof(serv_addr));
 portno = atoi(argv[1]);
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 serv_addr.sin_port = htons(portno);
 if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
  perror("ERROR on binding");
  exit(0);
 }
 listen(sockfd, 5);
 for (;;) {
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  if (newsockfd < 0)
   perror("ERROR on accept");
  pthread_create(&tid, ((void *)0), doit, (void *) newsockfd);
  }
 }

canonical_original_code:
int main(int argc, char *argv[]) {
 int sockfd; int newsockfd; int portno; int clilen;
 char buff[256]; char *ptr;
 struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
 unsigned long tid;
 int n;
 int on = 1;
 if (argc < 2) {
  fprintf(stderr, "ERROR, no port provided\n");
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  perror("ERROR opening socket");
 bzero((char *) &serv_addr, sizeof(serv_addr));
 portno = atoi(argv[1]);
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 serv_addr.sin_port = htons(portno);
 if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
  perror("ERROR on binding");
  exit(0);
 }
 listen(sockfd, 5);
 for (;;) {
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  if (newsockfd < 0)
   perror("ERROR on accept");
  pthread_create(&tid, ((void *)0), doit, (void *) newsockfd);
  }
 }

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sockfd int

variable_types: newsockfd int

variable_types: portno int

variable_types: clilen int

variable_types:
buff
char [256]

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:
tid
unsigned long

variable_types: n int

variable_types: on int


repo: sambeau/burp

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

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

original_code:
size_t bz_real_length(bz_Real* r)
{
  return 1;
}

canonical_original_code:
unsigned long bz_real_length(struct bz_Real *r)
{
  return 1;
}

variable_types: struct bz_Real { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; double value; } *

return_type: unsigned long

user_defined_types: struct bz_Real { struct bz_Type *type; double value; }


decompiled_code:
double *__fastcall bz_real_new(double a1)
{
double *v1; // r12

bz_barf_push_function("bz_real_new");
v1 = (double *)malloc(0x10uLL);
if ( !v1 )
bz_barf("Out of Memory");
v1[1] = a1;
*(_QWORD *)v1 = &bz_real_type;
bz_barf_pop_function();
return v1;
}

canonical_decompiled_code:
double *__fastcall func1(double a1)
{
double *v1; // r12

bz_barf_push_function("bz_real_new");
v1 = (double *)malloc(0x10uLL);
if ( !v1 )
bz_barf("Out of Memory");
v1[1] = a1;
*(_QWORD *)v1 = &bz_real_type;
bz_barf_pop_function();
return v1;
}

original_code:
bz_Real* bz_real_new(double r)
{
   bz_Real* R;
   {bz_barf_push_function(__PRETTY_FUNCTION__);;};
   R = malloc(sizeof(bz_Real));
   if(R == ((void *)0))
      bz_barf("Out of Memory");
   R->type = &bz_real_type;
   R->value = r;
   {;bz_barf_pop_function();return (R);};
}

canonical_original_code:
struct bz_Real *bz_real_new(double r)
{
   struct bz_Real *R;
   {bz_barf_push_function(__PRETTY_FUNCTION__);;};
   R = malloc(sizeof(bz_Real));
   if(R == ((void *)0))
      bz_barf("Out of Memory");
   R->type = &bz_real_type;
   R->value = r;
   {;bz_barf_pop_function();return (R);};
}

variable_types: r double

return_type: struct bz_Real { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; double value; } *


decompiled_code:
__int64 __fastcall bz_real_compare(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
__int64 result; // rax

bz_barf_push_function("bz_real_compare");
v2 = *(double *)(a1 + 8) - *(double *)(a2 + 8);
if ( v2 > 0.0 )
{
bz_barf_pop_function();
result = 1LL;
}
else
{
bz_barf_pop_function();
if ( v2 < 0.0 )
result = 0xFFFFFFFFLL;
else
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
__int64 result; // rax

bz_barf_push_function("bz_real_compare");
v2 = *(double *)(a1 + 8) - *(double *)(a2 + 8);
if ( v2 > 0.0 )
{
bz_barf_pop_function();
result = 1LL;
}
else
{
bz_barf_pop_function();
if ( v2 < 0.0 )
result = 0xFFFFFFFFLL;
else
result = 0LL;
}
return result;
}

original_code:
int bz_real_compare(bz_Real* x, bz_Real* y)
{
  double r;
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  r = x->value - y->value;
  if (r > 0) {;bz_barf_pop_function();return (1);};
  if (r < 0) {;bz_barf_pop_function();return (-1);};
                  {;bz_barf_pop_function();return (0);};
}

canonical_original_code:
int bz_real_compare(struct bz_Real *x, struct bz_Real *y)
{
  double r;
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  r = x->value - y->value;
  if (r > 0) {;bz_barf_pop_function();return (1);};
  if (r < 0) {;bz_barf_pop_function();return (-1);};
                  {;bz_barf_pop_function();return (0);};
}

variable_types:
y
struct bz_Real *

user_defined_types: struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); }


original_code:
size_t bz_real_charsize(bz_Real* r)
{
  double rv = r->value;
  if (rv == 0.0)
    return 6 + 2;
  int x = (int)trunc(abs(rv));
  if (x == 0)
    return 6 + 2 + (rv < 0.0 ? 1 : 0);
  else
    return ((int)floor( log10( x ) ) + 6 + 2 + (rv < 0.0 ? 1 : 0));
}

canonical_original_code:
unsigned long bz_real_charsize(struct bz_Real *r)
{
  double rv = r->value;
  if (rv == 0.0)
    return 6 + 2;
  int x = (int)trunc(abs(rv));
  if (x == 0)
    return 6 + 2 + (rv < 0.0 ? 1 : 0);
  else
    return ((int)floor( log10( x ) ) + 6 + 2 + (rv < 0.0 ? 1 : 0));
}

variable_types: rv double

variable_types: x int


decompiled_code:
int bz_real_show()
{
struct _IO_FILE *v0; // rbp
const wchar_t *v1; // rax

v0 = stdout;
v1 = (const wchar_t *)bz_real_to_wstr();
return fputws(v1, v0);
}

canonical_decompiled_code:
int func4()
{
struct _IO_FILE *v0; // rbp
const wchar_t *v1; // rax

v0 = stdout;
v1 = (const wchar_t *)bz_real_to_wstr();
return fputws(v1, v0);
}

original_code:
void bz_real_show(bz_Real* r)
{
  fputws(bz_real_to_wstr(r),stdout);
}

canonical_original_code:
void bz_real_show(struct bz_Real *r)
{
  fputws(bz_real_to_wstr(r),stdout);
}


decompiled_code:
__int64 __fastcall bz_integer_to_integer(__int64 a1)
{
bz_barf_push_function("bz_integer_to_integer");
bz_barf_pop_function();
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
bz_barf_push_function("bz_integer_to_integer");
bz_barf_pop_function();
return a1;
}

original_code:
bz_Integer* bz_integer_to_integer(bz_Integer* I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (I);};
}

canonical_original_code:
struct bz_Integer *bz_integer_to_integer(struct bz_Integer *I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (I);};
}

variable_types:
I
struct bz_Integer *

return_type: struct bz_Integer { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; long long value; } *

user_defined_types: struct bz_Integer { struct bz_Type *type; long long value; }


decompiled_code:
__int64 __fastcall bz_integer_to_real(__int64 a1)
{
bz_barf_push_function("bz_integer_to_real");
bz_barf_pop_function();
return bz_real_new((double)(int)*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
bz_barf_push_function("bz_integer_to_real");
bz_barf_pop_function();
return bz_real_new((double)(int)*(_QWORD *)(a1 + 8));
}

original_code:
bz_Real* bz_integer_to_real(bz_Integer* I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_real_new((double) I->value));};
}

canonical_original_code:
struct bz_Real *bz_integer_to_real(struct bz_Integer *I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_real_new((double) I->value));};
}

variable_types: struct bz_Integer { struct bz_Type *type; long long value; } *


decompiled_code:
__int64 __fastcall bz_integer_to_list(__int64 a1)
{
bz_barf_push_function("bz_integer_to_list");
bz_barf_pop_function();
return bz_list_cons(&bz_Empty_value, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
bz_barf_push_function("bz_integer_to_list");
bz_barf_pop_function();
return bz_list_cons(&bz_Empty_value, a1);
}

original_code:
bz_List* bz_integer_to_list(bz_Integer* I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_list_cons(((void *)&bz_Empty_value),I));};
}

canonical_original_code:
struct bz_list_node *bz_integer_to_list(struct bz_Integer *I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_list_cons(((void *)&bz_Empty_value),I));};
}

return_type: struct bz_list_node { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; void *node; struct bz_list_node *next; } *

user_defined_types: struct bz_list_node { struct bz_Type *type; void *node; struct bz_list_node *next; }


decompiled_code:
__int64 __fastcall bz_integer_to_string(__int64 a1)
{
wchar_t *v1; // rax

bz_barf_push_function("bz_integer_to_string");
bz_barf_pop_function();
v1 = bz_integer_to_wstr(a1);
return bz_string_new(v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
wchar_t *v1; // rax

bz_barf_push_function("bz_integer_to_string");
bz_barf_pop_function();
v1 = bz_integer_to_wstr(a1);
return bz_string_new(v1);
}

original_code:
bz_String* bz_integer_to_string(bz_Integer* I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_string_new(bz_integer_to_wstr(I)));};
}

canonical_original_code:
struct bz_String *bz_integer_to_string(struct bz_Integer *I)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_string_new(bz_integer_to_wstr(I)));};
}

return_type: struct bz_String { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; unsigned long buffer_size; unsigned long length; int *string; } *

user_defined_types: struct bz_String { struct bz_Type *type; unsigned long buffer_size; unsigned long length; int *string; }


decompiled_code:
__int64 __fastcall bz_real_to_integer(__int64 a1)
{
bz_barf_push_function("bz_real_to_integer");
bz_barf_pop_function();
return bz_integer_new((unsigned int)(int)*(double *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
bz_barf_push_function("bz_real_to_integer");
bz_barf_pop_function();
return bz_integer_new((unsigned int)(int)*(double *)(a1 + 8));
}

original_code:
bz_Integer* bz_real_to_integer(bz_Real* r)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_integer_new((long long)r->value));};
}

canonical_original_code:
struct bz_Integer *bz_real_to_integer(struct bz_Real *r)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return (bz_integer_new((long long)r->value));};
}

variable_types: struct bz_Real { struct bz_Type *type; double value; } *


decompiled_code:
__int64 __fastcall bz_real_to_real(__int64 a1)
{
bz_barf_push_function("bz_real_to_real");
bz_barf_pop_function();
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
bz_barf_push_function("bz_real_to_real");
bz_barf_pop_function();
return a1;
}

original_code:
bz_Real* bz_real_to_real(bz_Real* r)
{
    {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (r);};
}

canonical_original_code:
struct bz_Real *bz_real_to_real(struct bz_Real *r)
{
    {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (r);};
}

variable_types:
r
struct bz_Real *


decompiled_code:
__int64 __fastcall bz_real_to_list(__int64 a1)
{
bz_barf_push_function("bz_real_to_list");
bz_barf_pop_function();
return bz_list_cons(&bz_Empty_value, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
bz_barf_push_function("bz_real_to_list");
bz_barf_pop_function();
return bz_list_cons(&bz_Empty_value, a1);
}

original_code:
bz_List* bz_real_to_list(bz_Real* r)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_list_cons(((void *)&bz_Empty_value),r));};
}

canonical_original_code:
struct bz_list_node *bz_real_to_list(struct bz_Real *r)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_list_cons(((void *)&bz_Empty_value),r));};
}


decompiled_code:
__int64 __fastcall bz_real_to_string(__int64 a1)
{
wchar_t *v1; // rax

bz_barf_push_function("bz_real_to_string");
bz_barf_pop_function();
v1 = bz_real_to_wstr(a1);
return bz_string_new(v1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
wchar_t *v1; // rax

bz_barf_push_function("bz_real_to_string");
bz_barf_pop_function();
v1 = bz_real_to_wstr(a1);
return bz_string_new(v1);
}

original_code:
bz_String* bz_real_to_string(bz_Real* r)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_string_new(bz_real_to_wstr(r)));};
}

canonical_original_code:
struct bz_String *bz_real_to_string(struct bz_Real *r)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_string_new(bz_real_to_wstr(r)));};
}


decompiled_code:
__int64 __fastcall bz_string_to_integer(__int64 a1)
{
int *v1; // rax
const wchar_t *v2; // rdi
int *v3; // rbx
__int64 v4; // rdi
__int64 v5; // r12
wchar_t *endptr; // [rsp+8h] [rbp-20h] BYREF

bz_barf_push_function("bz_string_to_integer");
v1 = _errno_location();
v2 = *(const wchar_t **)(a1 + 24);
*v1 = 0;
v3 = v1;
v4 = wcstol(v2, &endptr, 0);
v5 = bz_integer_new(v4);
if ( *v3 )
bz_barf("bz_Integer too long");
bz_barf_pop_function();
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int *v1; // rax
const wchar_t *v2; // rdi
int *v3; // rbx
__int64 v4; // rdi
__int64 v5; // r12
wchar_t *endptr; // [rsp+8h] [rbp-20h] BYREF

bz_barf_push_function("bz_string_to_integer");
v1 = _errno_location();
v2 = *(const wchar_t **)(a1 + 24);
*v1 = 0;
v3 = v1;
v4 = wcstol(v2, &endptr, 0);
v5 = bz_integer_new(v4);
if ( *v3 )
bz_barf("bz_Integer too long");
bz_barf_pop_function();
return v5;
}

original_code:
bz_Integer* bz_string_to_integer(bz_String* s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  wchar_t *error;
  (*__errno_location ()) = 0;
  bz_Integer* I = bz_integer_new(wcstol(s->string, &error , 0));
  if((*__errno_location ())){
    bz_barf("bz_Integer too long");
  }
  {;bz_barf_pop_function();return (I);};
}

canonical_original_code:
struct bz_Integer *bz_string_to_integer(struct bz_String *s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  int *error;
  (*__errno_location ()) = 0;
  struct bz_Integer *I = bz_integer_new(wcstol(s->string, &error , 0));
  if((*__errno_location ())){
    bz_barf("bz_Integer too long");
  }
  {;bz_barf_pop_function();return (I);};
}

variable_types: struct bz_String { struct bz_Type *type; unsigned long buffer_size; unsigned long length; int *string; } *

variable_types:
error
int *

variable_types: struct bz_Integer { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; long long value; } *


decompiled_code:
__int64 __fastcall bz_string_to_real(__int64 a1)
{
int *v1; // rax
const wchar_t *v2; // rdi
int *v3; // rbx
double v4; // xmm0_8
__int64 v5; // r12
wchar_t *endptr; // [rsp+8h] [rbp-20h] BYREF

bz_barf_push_function("bz_string_to_real");
v1 = _errno_location();
v2 = *(const wchar_t **)(a1 + 24);
*v1 = 0;
v3 = v1;
v4 = wcstod(v2, &endptr);
v5 = bz_real_new(v4);
if ( *v3 )
bz_barf("bz_Real too long");
bz_barf_pop_function();
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int *v1; // rax
const wchar_t *v2; // rdi
int *v3; // rbx
double v4; // xmm0_8
__int64 v5; // r12
wchar_t *endptr; // [rsp+8h] [rbp-20h] BYREF

bz_barf_push_function("bz_string_to_real");
v1 = _errno_location();
v2 = *(const wchar_t **)(a1 + 24);
*v1 = 0;
v3 = v1;
v4 = wcstod(v2, &endptr);
v5 = bz_real_new(v4);
if ( *v3 )
bz_barf("bz_Real too long");
bz_barf_pop_function();
return v5;
}

original_code:
bz_Real* bz_string_to_real(bz_String* s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  wchar_t *error;
  (*__errno_location ()) = 0;
  bz_Real* R = bz_real_new(wcstod(s->string,&error));
  if((*__errno_location ())) {
    bz_barf("bz_Real too long");
  }
  {;bz_barf_pop_function();return (R);};
}

canonical_original_code:
struct bz_Real *bz_string_to_real(struct bz_String *s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  int *error;
  (*__errno_location ()) = 0;
  struct bz_Real *R = bz_real_new(wcstod(s->string,&error));
  if((*__errno_location ())) {
    bz_barf("bz_Real too long");
  }
  {;bz_barf_pop_function();return (R);};
}


decompiled_code:
__int64 __fastcall bz_string_to_string(__int64 a1)
{
bz_barf_push_function("bz_string_to_string");
bz_barf_pop_function();
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
bz_barf_push_function("bz_string_to_string");
bz_barf_pop_function();
return a1;
}

original_code:
bz_String* bz_string_to_string(bz_String* s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (s);};
}

canonical_original_code:
struct bz_String *bz_string_to_string(struct bz_String *s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (s);};
}

variable_types:
s
struct bz_String *


decompiled_code:
__int64 __fastcall bz_string_to_list(__int64 a1)
{
bz_barf_push_function("bz_string_to_list");
bz_barf_pop_function();
return bz_list_cons(&bz_Empty_value, a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
bz_barf_push_function("bz_string_to_list");
bz_barf_pop_function();
return bz_list_cons(&bz_Empty_value, a1);
}

original_code:
bz_List* bz_string_to_list(bz_String* s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_list_cons(((void *)&bz_Empty_value),s));};
}

canonical_original_code:
struct bz_list_node *bz_string_to_list(struct bz_String *s)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_list_cons(((void *)&bz_Empty_value),s));};
}


decompiled_code:
__int64 __fastcall bz_string_to_wstr(__int64 a1)
{
bz_barf_push_function("bz_string_to_wstr");
bz_barf_pop_function();
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
bz_barf_push_function("bz_string_to_wstr");
bz_barf_pop_function();
return *(_QWORD *)(a1 + 24);
}

original_code:
wchar_t* bz_string_to_wstr(bz_String* e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (e->string);};
}

canonical_original_code:
int *bz_string_to_wstr(struct bz_String *e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (e->string);};
}

variable_types: struct bz_String { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; unsigned long buffer_size; unsigned long length; int *string; } *

return_type: int *


decompiled_code:
__int64 bz_empty_to_integer()
{
bz_barf_push_function("bz_empty_to_integer");
bz_barf_pop_function();
return bz_integer_new(0LL);
}

canonical_decompiled_code:
__int64 func13()
{
bz_barf_push_function("bz_empty_to_integer");
bz_barf_pop_function();
return bz_integer_new(0LL);
}

original_code:
bz_Integer* bz_empty_to_integer(bz_Empty* e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_integer_new(0));};
}

canonical_original_code:
struct bz_Integer *bz_empty_to_integer(struct bz_Empty *e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_integer_new(0));};
}

variable_types: struct bz_Empty { struct bz_Type *type; } *


decompiled_code:
__int64 bz_empty_to_real()
{
bz_barf_push_function("bz_empty_to_real");
bz_barf_pop_function();
return bz_real_new(0.0);
}

canonical_decompiled_code:
__int64 func14()
{
bz_barf_push_function("bz_empty_to_real");
bz_barf_pop_function();
return bz_real_new(0.0);
}

original_code:
bz_Real* bz_empty_to_real(bz_Empty* e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_real_new((double)0.0));};
}

canonical_original_code:
struct bz_Real *bz_empty_to_real(struct bz_Empty *e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_real_new((double)0.0));};
}

user_defined_types: struct bz_Empty { struct bz_Type *type; }


decompiled_code:
__int64 bz_empty_to_string()
{
return bz_string_new(&unk_768);
}

canonical_decompiled_code:
__int64 func15()
{
return bz_string_new(&unk_768);
}

original_code:
bz_String* bz_empty_to_string(bz_Empty* e)
{
  return bz_string_new(L"");
}

canonical_original_code:
struct bz_String *bz_empty_to_string(struct bz_Empty *e)
{
  return bz_string_new(L"");
}


decompiled_code:
void *bz_empty_to_wstr()
{
return &unk_768;
}

canonical_decompiled_code:
void *func16()
{
return &unk_768;
}

original_code:
wchar_t* bz_empty_to_wstr(bz_Empty* e)
{
  return L"";
}

canonical_original_code:
int *bz_empty_to_wstr(struct bz_Empty *e)
{
  return L"";
}

variable_types: struct bz_Empty { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; } *


decompiled_code:
__int64 __fastcall bz_empty_to_list(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return a1;
}

original_code:
bz_List* bz_empty_to_list(bz_Empty* e)
{
  return (bz_List*)e;
}

canonical_original_code:
struct bz_list_node *bz_empty_to_list(struct bz_Empty *e)
{
  return (struct bz_list_node *)e;
}


decompiled_code:
char *__fastcall wstr_to_cstr(wchar_t *pwcs)
{
size_t v1; // r13
char *v2; // r12

bz_barf_push_function("wstr_to_cstr");
v1 = wcstombs(0LL, pwcs, 0LL);
v2 = (char *)malloc(v1 + 1);
v2[wcstombs(v2, pwcs, v1)] = 0;
bz_barf_pop_function();
return v2;
}

canonical_decompiled_code:
char *__fastcall func18(wchar_t *pwcs)
{
size_t v1; // r13
char *v2; // r12

bz_barf_push_function("wstr_to_cstr");
v1 = wcstombs(0LL, pwcs, 0LL);
v2 = (char *)malloc(v1 + 1);
v2[wcstombs(v2, pwcs, v1)] = 0;
bz_barf_pop_function();
return v2;
}

original_code:
char* wstr_to_cstr(wchar_t* bz_string_to_wstr)
{
  char *cstr;
  size_t cstrlength;
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  cstrlength = wcstombs(((void *)0),bz_string_to_wstr,0);
 cstr = malloc(sizeof(char)*(cstrlength + 1));
 cstrlength = wcstombs(cstr, bz_string_to_wstr, cstrlength);
 if (cstrlength < 0){
  bz_barf("Unreadable string");
 }
 cstr[cstrlength]='\0';
   {;bz_barf_pop_function();return (cstr);};
}

canonical_original_code:
char *wstr_to_cstr(int *bz_string_to_wstr)
{
  char *cstr;
  unsigned long cstrlength;
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  cstrlength = wcstombs(((void *)0),bz_string_to_wstr,0);
 cstr = malloc(sizeof(char)*(cstrlength + 1));
 cstrlength = wcstombs(cstr, bz_string_to_wstr, cstrlength);
 if (cstrlength < 0){
  bz_barf("Unreadable string");
 }
 cstr[cstrlength]='\0';
   {;bz_barf_pop_function();return (cstr);};
}

variable_types:
cstr
char *

variable_types:
cstrlength
unsigned long


decompiled_code:
__int64 __fastcall bz_list_to_integer(__int64 a1)
{
bz_barf_push_function("bz_list_to_integer");
bz_barf_pop_function();
return (*(__int64 (__fastcall **)(_QWORD))(**(_QWORD **)(a1 + 8) + 56LL))(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
bz_barf_push_function("bz_list_to_integer");
bz_barf_pop_function();
return (*(__int64 (__fastcall **)(_QWORD))(**(_QWORD **)(a1 + 8) + 56LL))(*(_QWORD *)(a1 + 8));
}

original_code:
bz_Integer* bz_list_to_integer(bz_List* e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return ((bz_Integer *) (void *)((bz_Type *)((bz_node *)e->node)->type)->to_integer(e->node));};
}

canonical_original_code:
struct bz_Integer *bz_list_to_integer(struct bz_list_node *e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  {;bz_barf_pop_function();return ((struct bz_Integer *) (void *)((struct bz_Type *)((struct bz_node *)e->node)->type)->to_integer(e->node));};
}

variable_types: struct bz_list_node { struct bz_Type *type; void *node; struct bz_list_node *next; } *

user_defined_types: struct bz_node { struct bz_Type *type; }


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

bz_barf_push_function("bz_list_to_real");
bz_barf_pop_function();
v1 = bz_list_to_integer(a1);
return bz_integer_to_real(v1);
}

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

bz_barf_push_function("bz_list_to_real");
bz_barf_pop_function();
v1 = func19(a1);
return func1(v1);
}

original_code:
bz_Real* bz_list_to_real(bz_List* e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_integer_to_real(bz_list_to_integer(e)));};
}

canonical_original_code:
struct bz_Real *bz_list_to_real(struct bz_list_node *e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;}; {;bz_barf_pop_function();return (bz_integer_to_real(bz_list_to_integer(e)));};
}


decompiled_code:
__int64 __fastcall bz_list_to_string(__int64 a1)
{
__int64 v1; // rbx
__int64 i; // rbp
__int64 v3; // rax
__int64 v4; // rax

bz_barf_push_function("bz_list_to_string");
v1 = bz_list_flatten(a1);
for ( i = bz_string_new(0LL); (_UNKNOWN *)v1 != &bz_Empty_value; i = v4 )
{
if ( !v1 )
break;
v3 = (*(__int64 (__fastcall **)(_QWORD))(**(_QWORD **)(v1 + 8) + 72LL))(*(_QWORD *)(v1 + 8));
v4 = bz_string_cat(i, v3, 0LL);
v1 = *(_QWORD *)(v1 + 16);
}
bz_barf_pop_function();
return i;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
__int64 v1; // rbx
__int64 i; // rbp
__int64 v3; // rax
__int64 v4; // rax

bz_barf_push_function("bz_list_to_string");
v1 = bz_list_flatten(a1);
for ( i = bz_string_new(0LL); (_UNKNOWN *)v1 != &bz_Empty_value; i = v4 )
{
if ( !v1 )
break;
v3 = (*(__int64 (__fastcall **)(_QWORD))(**(_QWORD **)(v1 + 8) + 72LL))(*(_QWORD *)(v1 + 8));
v4 = bz_string_cat(i, v3, 0LL);
v1 = *(_QWORD *)(v1 + 16);
}
bz_barf_pop_function();
return i;
}

original_code:
bz_String* bz_list_to_string(bz_List* e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  bz_List* e1 = bz_list_flatten(e);
  bz_String* s = bz_string_new(((void *)0));
  while (e1 && e1 != ((void *)&bz_Empty_value)) {
    s = _bz_string_cat(s, (void *)((bz_Type *)((bz_node *)e1->node)->type)->to_string(e1->node), ((void *)0));
    e1 = e1->next;
  }
  {;bz_barf_pop_function();return (s);};
}

canonical_original_code:
struct bz_String *bz_list_to_string(struct bz_list_node *e)
{
  {bz_barf_push_function(__PRETTY_FUNCTION__);;};
  struct bz_list_node *e1 = bz_list_flatten(e);
  struct bz_String *s = bz_string_new(((void *)0));
  while (e1 && e1 != ((void *)&bz_Empty_value)) {
    s = _bz_string_cat(s, (void *)((struct bz_Type *)((struct bz_node *)e1->node)->type)->to_string(e1->node), ((void *)0));
    e1 = e1->next;
  }
  {;bz_barf_pop_function();return (s);};
}

variable_types: struct bz_list_node { struct bz_Type { int *name; unsigned long size; void *(*new)(); void *(*clone)(); int (*length)(); int (*charsize)(); int (*compare)(); void *(*to_integer)(); void *(*to_real)(); void *(*to_string)(); void *(*to_list)(); void *(*to_wstr)(); void *(*show)(); } *type; void *node; struct bz_list_node *next; } *