original_code:
size_t
elf_delscn(Elf *elf, Elf_Scn *scn) {
    Elf_Scn *pscn;
    Scn_Data *sd;
    Scn_Data *tmp;
    size_t index;
    if (!elf || !scn) {
 return 0;
    }
    do{}while(0);
    do{}while(0);
    do{}while(0);
    if (scn->s_elf != elf) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    do{}while(0);
    if (scn == elf->e_scn_1) {
 (_elf_errno = (ERROR_NULLSCN));
 return 0;
    }
    for (pscn = elf->e_scn_1; pscn->s_link; pscn = pscn->s_link) {
 if (pscn->s_link == scn) {
     break;
 }
    }
    if (pscn->s_link != scn) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    if (elf->e_scn_n == scn) {
 elf->e_scn_n = pscn;
    }
    pscn->s_link = scn->s_link;
    index = scn->s_index;
    for (sd = scn->s_data_1; sd; sd = tmp) {
 do{}while(0);
 do{}while(0);
 tmp = sd->sd_link;
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if ((sd = scn->s_rawdata)) {
 do{}while(0);
 do{}while(0);
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if (scn->s_freeme) {
 do{}while(0);
 free(scn);
    }
    for (scn = pscn->s_link; scn; scn = scn->s_link) {
 do{}while(0);
 scn->s_index--;
    }
    if (elf->e_class == 1) {
 _elf32_update_shdr(elf, index);
 return index;
    }
    else if (elf->e_class == 2) {
 _elf64_update_shdr(elf, index);
 return index;
    }
    else if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
    }
    else {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
    }
    return 0;
}

canonical_original_code:
unsigned long elf_delscn(struct Elf *elf, struct Elf_Scn *scn) {
    struct Elf_Scn *pscn;
    struct Scn_Data *sd;
    struct Scn_Data *tmp;
    unsigned long index;
    if (!elf || !scn) {
 return 0;
    }
    do{}while(0);
    do{}while(0);
    do{}while(0);
    if (scn->s_elf != elf) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    do{}while(0);
    if (scn == elf->e_scn_1) {
 (_elf_errno = (ERROR_NULLSCN));
 return 0;
    }
    for (pscn = elf->e_scn_1; pscn->s_link; pscn = pscn->s_link) {
 if (pscn->s_link == scn) {
     break;
 }
    }
    if (pscn->s_link != scn) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    if (elf->e_scn_n == scn) {
 elf->e_scn_n = pscn;
    }
    pscn->s_link = scn->s_link;
    index = scn->s_index;
    for (sd = scn->s_data_1; sd; sd = tmp) {
 do{}while(0);
 do{}while(0);
 tmp = sd->sd_link;
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if ((sd = scn->s_rawdata)) {
 do{}while(0);
 do{}while(0);
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if (scn->s_freeme) {
 do{}while(0);
 free(scn);
    }
    for (scn = pscn->s_link; scn; scn = scn->s_link) {
 do{}while(0);
 scn->s_index--;
    }
    if (elf->e_class == 1) {
 _elf32_update_shdr(elf, index);
 return index;
    }
    else if (elf->e_class == 2) {
 _elf64_update_shdr(elf, index);
 return index;
    }
    else if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
    }
    else {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
    }
    return 0;
}

variable_types:
scn
struct Elf_Scn *

variable_types: struct Elf_Scn { struct Elf_Scn *s_link; struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *

variable_types: struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn { struct Elf_Scn *s_link; struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *

variable_types:
index
unsigned long


repo: aodinokov/expos

decompiled_code:
__int64 elf_errno()
{
unsigned int v0; // er8

v0 = elf_errno;
elf_errno = 0;
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er8

v0 = elf_errno;
elf_errno = 0;
return v0;
}

original_code:
int
elf_errno(void) {
    int tmp = _elf_errno;
    _elf_errno = 0;
    return tmp;
}

canonical_original_code:
int elf_errno() {
    int tmp = _elf_errno;
    _elf_errno = 0;
    return tmp;
}

variable_types: tmp int

return_type: int


decompiled_code:
__int64 __fastcall elf_getaroff(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

if ( a1 && (v1 = *(_QWORD *)(a1 + 56)) != 0 )
result = *(_QWORD *)(a1 + 72) - 60LL - *(_QWORD *)(v1 + 72);
else
result = -1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

if ( a1 && (v1 = *(_QWORD *)(a1 + 56)) != 0 )
result = *(_QWORD *)(a1 + 72) - 60LL - *(_QWORD *)(v1 + 72);
else
result = -1LL;
return result;
}

original_code:
off_t
elf_getaroff(Elf *elf) {
    Elf *ref;
    if (!elf) {
 return (off_t)-1;
    }
    do{}while(0);
    if (!(ref = elf->e_parent)) {
 return (off_t)-1;
    }
    do{}while(0);
    do{}while(0);
    return (off_t)(elf->e_base - ref->e_base - sizeof(struct ar_hdr));
}

canonical_original_code:
long elf_getaroff(struct Elf *elf) {
    struct Elf *ref;
    if (!elf) {
 return (off_t)-1;
    }
    do{}while(0);
    if (!(ref = elf->e_parent)) {
 return (off_t)-1;
    }
    do{}while(0);
    do{}while(0);
    return (off_t)(elf->e_base - ref->e_base - sizeof(struct ar_hdr));
}

variable_types: struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn { struct Elf_Scn *s_link; struct Elf *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *

return_type: long

user_defined_types: struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_gid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; }

user_defined_types: struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; }

user_defined_types: struct Elf_Scn { struct Elf_Scn *s_link; struct Elf *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr u_shdr64; struct Elf32_Shdr u_shdr32; } s_uhdr; long s_magic; }

user_defined_types: struct Scn_Data { struct Elf_Data sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; }

user_defined_types: struct Elf_Data { void *d_buf; enum Elf_Type d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; }


decompiled_code:
__int64 __fastcall elf_rawfile(__int64 *a1, char *a2)
{
char *v2; // rbx
__int64 v3; // rcx
__int64 result; // rax
char v5; // [rsp+18h] [rbp-10h] BYREF

v2 = a2;
if ( !a2 )
v2 = &v5;
*(_QWORD *)v2 = 0LL;
if ( !a1 || (*((_BYTE *)a1 + 212) & 1) == 0 )
return 0LL;
v3 = *a1;
result = a1[4];
if ( !*a1 )
return result;
if ( !result )
{
if ( (*((_BYTE *)a1 + 212) & 8) == 0 )
{
result = a1[3];
a1[4] = result;
goto LABEL_7;
}
result = elf_read(a1, 0LL, 0LL);
a1[4] = result;
if ( result )
{
v3 = *a1;
goto LABEL_7;
}
return 0LL;
}
LABEL_7:
*(_QWORD *)v2 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, char *a2)
{
char *v2; // rbx
__int64 v3; // rcx
__int64 result; // rax
char v5; // [rsp+18h] [rbp-10h] BYREF

v2 = a2;
if ( !a2 )
v2 = &v5;
*(_QWORD *)v2 = 0LL;
if ( !a1 || (*((_BYTE *)a1 + 212) & 1) == 0 )
return 0LL;
v3 = *a1;
result = a1[4];
if ( !*a1 )
return result;
if ( !result )
{
if ( (*((_BYTE *)a1 + 212) & 8) == 0 )
{
result = a1[3];
a1[4] = result;
goto LABEL_7;
}
result = elf_read(a1, 0LL, 0LL);
a1[4] = result;
if ( result )
{
v3 = *a1;
goto LABEL_7;
}
return 0LL;
}
LABEL_7:
*(_QWORD *)v2 = v3;
return result;
}

original_code:
char*
elf_rawfile(Elf *elf, size_t *ptr) {
    size_t tmp;
    if (!ptr) {
 ptr = &tmp;
    }
    *ptr = 0;
    if (!elf) {
 return ((void *)0);
    }
    do{}while(0);
    if (!elf->e_readable) {
 return ((void *)0);
    }
    else if (elf->e_size) {
 if (!elf->e_rawdata) {
     do{}while(0);
     if (!elf->e_cooked) {
  elf->e_rawdata = elf->e_data;
     }
     else if (!(elf->e_rawdata = _elf_read(elf, ((void *)0), 0, elf->e_size))) {
  return ((void *)0);
     }
 }
 *ptr = elf->e_size;
    }
    return elf->e_rawdata;
}

canonical_original_code:
char *elf_rawfile(struct Elf *elf, unsigned long *ptr) {
    unsigned long tmp;
    if (!ptr) {
 ptr = &tmp;
    }
    *ptr = 0;
    if (!elf) {
 return ((void *)0);
    }
    do{}while(0);
    if (!elf->e_readable) {
 return ((void *)0);
    }
    else if (elf->e_size) {
 if (!elf->e_rawdata) {
     do{}while(0);
     if (!elf->e_cooked) {
  elf->e_rawdata = elf->e_data;
     }
     else if (!(elf->e_rawdata = _elf_read(elf, ((void *)0), 0, elf->e_size))) {
  return ((void *)0);
     }
 }
 *ptr = elf->e_size;
    }
    return elf->e_rawdata;
}

variable_types:
ptr
unsigned long *

variable_types:
tmp
unsigned long

return_type: char *

user_defined_types: enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 }

user_defined_types: struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; }

user_defined_types: struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; }

user_defined_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; }

user_defined_types: enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 }


original_code:
int
gelf_update_phdr(Elf *elf, int ndx, GElf_Phdr *src) {
    char *tmp;
    size_t n;
    if (!elf || !src) {
 return 0;
    }
    do{}while(0);
    tmp = _elf_getphdr(elf, elf->e_class);
    if (!tmp) {
 return 0;
    }
    if (ndx < 0 || ndx >= elf->e_phnum) {
 (_elf_errno = (ERROR_BADINDEX));
 return 0;
    }
    n = (_elf_fmsize[((elf->e_class))-1][((_elf_version))-0 -1][((ELF_T_PHDR))-ELF_T_BYTE][(0)]);
    if (n == 0) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
 return 0;
    }
    if (elf->e_class == 2) {
 *(Elf64_Phdr*)(tmp + ndx * n) = *src;
    }
    else if (elf->e_class == 1) {
 Elf32_Phdr *dst = (Elf32_Phdr*)(tmp + ndx * n);
 do { if (sizeof((dst)->p_type) < sizeof((src)->p_type) && (Elf32_Word)(src)->p_type != (src)->p_type) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_type = (Elf32_Word)(src)->p_type; } while (0);
 do { if (sizeof((dst)->p_offset) < sizeof((src)->p_offset) && (Elf32_Off)(src)->p_offset != (src)->p_offset) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_offset = (Elf32_Off)(src)->p_offset; } while (0);
 do { if (sizeof((dst)->p_vaddr) < sizeof((src)->p_vaddr) && (Elf32_Addr)(src)->p_vaddr != (src)->p_vaddr) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_vaddr = (Elf32_Addr)(src)->p_vaddr; } while (0);
 do { if (sizeof((dst)->p_paddr) < sizeof((src)->p_paddr) && (Elf32_Addr)(src)->p_paddr != (src)->p_paddr) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_paddr = (Elf32_Addr)(src)->p_paddr; } while (0);
 do { if (sizeof((dst)->p_filesz) < sizeof((src)->p_filesz) && (Elf32_Word)(src)->p_filesz != (src)->p_filesz) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_filesz = (Elf32_Word)(src)->p_filesz; } while (0);
 do { if (sizeof((dst)->p_memsz) < sizeof((src)->p_memsz) && (Elf32_Word)(src)->p_memsz != (src)->p_memsz) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_memsz = (Elf32_Word)(src)->p_memsz; } while (0);
 do { if (sizeof((dst)->p_flags) < sizeof((src)->p_flags) && (Elf32_Word)(src)->p_flags != (src)->p_flags) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_flags = (Elf32_Word)(src)->p_flags; } while (0);
 do { if (sizeof((dst)->p_align) < sizeof((src)->p_align) && (Elf32_Word)(src)->p_align != (src)->p_align) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_align = (Elf32_Word)(src)->p_align; } while (0);
    }
    else {
 if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
     (_elf_errno = (ERROR_UNIMPLEMENTED));
 }
 else {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
 return 0;
    }
    return 1;
}

canonical_original_code:
int gelf_update_phdr(struct Elf *elf, int ndx, struct Elf64_Phdr *src) {
    char *tmp;
    unsigned long n;
    if (!elf || !src) {
 return 0;
    }
    do{}while(0);
    tmp = _elf_getphdr(elf, elf->e_class);
    if (!tmp) {
 return 0;
    }
    if (ndx < 0 || ndx >= elf->e_phnum) {
 (_elf_errno = (ERROR_BADINDEX));
 return 0;
    }
    n = (_elf_fmsize[((elf->e_class))-1][((_elf_version))-0 -1][((ELF_T_PHDR))-ELF_T_BYTE][(0)]);
    if (n == 0) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
 return 0;
    }
    if (elf->e_class == 2) {
 *(struct Elf64_Phdr *)(tmp + ndx * n) = *src;
    }
    else if (elf->e_class == 1) {
 struct Elf32_Phdr *dst = (Elf32_Phdr*)(tmp + ndx * n);
 do { if (sizeof((dst)->p_type) < sizeof((src)->p_type) && (Elf32_Word)(src)->p_type != (src)->p_type) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_type = (Elf32_Word)(src)->p_type; } while (0);
 do { if (sizeof((dst)->p_offset) < sizeof((src)->p_offset) && (Elf32_Off)(src)->p_offset != (src)->p_offset) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_offset = (Elf32_Off)(src)->p_offset; } while (0);
 do { if (sizeof((dst)->p_vaddr) < sizeof((src)->p_vaddr) && (Elf32_Addr)(src)->p_vaddr != (src)->p_vaddr) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_vaddr = (Elf32_Addr)(src)->p_vaddr; } while (0);
 do { if (sizeof((dst)->p_paddr) < sizeof((src)->p_paddr) && (Elf32_Addr)(src)->p_paddr != (src)->p_paddr) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_paddr = (Elf32_Addr)(src)->p_paddr; } while (0);
 do { if (sizeof((dst)->p_filesz) < sizeof((src)->p_filesz) && (Elf32_Word)(src)->p_filesz != (src)->p_filesz) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_filesz = (Elf32_Word)(src)->p_filesz; } while (0);
 do { if (sizeof((dst)->p_memsz) < sizeof((src)->p_memsz) && (Elf32_Word)(src)->p_memsz != (src)->p_memsz) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_memsz = (Elf32_Word)(src)->p_memsz; } while (0);
 do { if (sizeof((dst)->p_flags) < sizeof((src)->p_flags) && (Elf32_Word)(src)->p_flags != (src)->p_flags) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_flags = (Elf32_Word)(src)->p_flags; } while (0);
 do { if (sizeof((dst)->p_align) < sizeof((src)->p_align) && (Elf32_Word)(src)->p_align != (src)->p_align) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->p_align = (Elf32_Word)(src)->p_align; } while (0);
    }
    else {
 if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
     (_elf_errno = (ERROR_UNIMPLEMENTED));
 }
 else {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
 return 0;
    }
    return 1;
}

variable_types: ndx int

variable_types: struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; } *

variable_types:
tmp
char *

variable_types:
n
unsigned long

variable_types: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *


decompiled_code:
void *__fastcall elf32_newphdr(__int64 a1, unsigned __int64 a2)
{
return elf_newphdr(a1, a2, 1);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, unsigned __int64 a2)
{
return func0(a1, a2, 1);
}

original_code:
Elf32_Phdr*
elf32_newphdr(Elf *elf, size_t count) {
    return (Elf32_Phdr*)_elf_newphdr(elf, count, 1);
}

canonical_original_code:
struct Elf32_Phdr *elf32_newphdr(struct Elf *elf, unsigned long count) {
    return (struct Elf32_Phdr *)_elf_newphdr(elf, count, 1);
}

variable_types:
count
unsigned long

return_type: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *


decompiled_code:
void *__fastcall elf64_newphdr(__int64 a1, unsigned __int64 a2)
{
return elf_newphdr(a1, a2, 2);
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, unsigned __int64 a2)
{
return func0(a1, a2, 2);
}

original_code:
Elf64_Phdr*
elf64_newphdr(Elf *elf, size_t count) {
    return (Elf64_Phdr*)_elf_newphdr(elf, count, 2);
}

canonical_original_code:
struct Elf64_Phdr *elf64_newphdr(struct Elf *elf, unsigned long count) {
    return (struct Elf64_Phdr *)_elf_newphdr(elf, count, 2);
}

return_type: struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; } *


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

v2 = *(_DWORD *)(a1 + 144);
if ( (unsigned int)(v2 - 1) <= 1 )
return elf_newphdr(a1, a2, v2);
elf_errno = 19;
return 0LL;
}

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

v2 = *(_DWORD *)(a1 + 144);
if ( (unsigned int)(v2 - 1) <= 1 )
return func0(a1, a2, v2);
elf_errno = 19;
return 0LL;
}

original_code:
unsigned long
gelf_newphdr(Elf *elf, size_t phnum) {
    if (!((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return 0;
    }
    return (unsigned long)_elf_newphdr(elf, phnum, elf->e_class);
}

canonical_original_code:
unsigned long gelf_newphdr(struct Elf *elf, unsigned long phnum) {
    if (!((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return 0;
    }
    return (unsigned long)_elf_newphdr(elf, phnum, elf->e_class);
}

variable_types:
phnum
unsigned long

return_type: unsigned long


original_code:
size_t
elfx_remscn(Elf *elf, Elf_Scn *scn) {
    Elf_Scn *pscn;
    Scn_Data *sd;
    Scn_Data *tmp;
    size_t index;
    if (!elf || !scn) {
 return 0;
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 (_elf_errno = (ERROR_NOTELF));
 return 0;
    }
    do{}while(0);
    do{}while(0);
    if (scn->s_elf != elf) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    do{}while(0);
    if (scn == elf->e_scn_1) {
 (_elf_errno = (ERROR_NULLSCN));
 return 0;
    }
    for (pscn = elf->e_scn_1; pscn->s_link; pscn = pscn->s_link) {
 if (pscn->s_link == scn) {
     break;
 }
    }
    if (pscn->s_link != scn) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    if (elf->e_scn_n == scn) {
 elf->e_scn_n = pscn;
    }
    pscn->s_link = scn->s_link;
    index = scn->s_index;
    for (sd = scn->s_data_1; sd; sd = tmp) {
 do{}while(0);
 do{}while(0);
 tmp = sd->sd_link;
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if ((sd = scn->s_rawdata)) {
 do{}while(0);
 do{}while(0);
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if (scn->s_freeme) {
 do{}while(0);
 free(scn);
    }
    for (scn = pscn->s_link; scn; scn = scn->s_link) {
 do{}while(0);
 scn->s_index--;
    }
    if (_elf_update_shnum(elf, elf->e_scn_n->s_index + 1)) {
 return 0;
    }
    return index;
}

canonical_original_code:
unsigned long elfx_remscn(struct Elf *elf, struct Elf_Scn *scn) {
    struct Elf_Scn *pscn;
    struct Scn_Data *sd;
    struct Scn_Data *tmp;
    unsigned long index;
    if (!elf || !scn) {
 return 0;
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 (_elf_errno = (ERROR_NOTELF));
 return 0;
    }
    do{}while(0);
    do{}while(0);
    if (scn->s_elf != elf) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    do{}while(0);
    if (scn == elf->e_scn_1) {
 (_elf_errno = (ERROR_NULLSCN));
 return 0;
    }
    for (pscn = elf->e_scn_1; pscn->s_link; pscn = pscn->s_link) {
 if (pscn->s_link == scn) {
     break;
 }
    }
    if (pscn->s_link != scn) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    if (elf->e_scn_n == scn) {
 elf->e_scn_n = pscn;
    }
    pscn->s_link = scn->s_link;
    index = scn->s_index;
    for (sd = scn->s_data_1; sd; sd = tmp) {
 do{}while(0);
 do{}while(0);
 tmp = sd->sd_link;
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if ((sd = scn->s_rawdata)) {
 do{}while(0);
 do{}while(0);
 if (sd->sd_free_data && sd->sd_memdata) {
     free(sd->sd_memdata);
 }
 if (sd->sd_freeme) {
     free(sd);
 }
    }
    if (scn->s_freeme) {
 do{}while(0);
 free(scn);
    }
    for (scn = pscn->s_link; scn; scn = scn->s_link) {
 do{}while(0);
 scn->s_index--;
    }
    if (_elf_update_shnum(elf, elf->e_scn_n->s_index + 1)) {
 return 0;
    }
    return index;
}


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

if ( a1 )
result = elf_flag((_DWORD *)(a1 + 72), a2, a3);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func0((_DWORD *)(a1 + 72), a2, a3);
else
result = 0LL;
return result;
}

original_code:
unsigned
elf_flagdata(Elf_Data *data, Elf_Cmd cmd, unsigned flags) {
    Scn_Data *sd = (Scn_Data*)data;
    if (!sd) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&sd->sd_data_flags, cmd, flags);
}

canonical_original_code:
unsigned int elf_flagdata(struct Elf_Data *data, enum Elf_Cmd cmd, unsigned int flags) {
    struct Scn_Data *sd = (Scn_Data*)data;
    if (!sd) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&sd->sd_data_flags, cmd, flags);
}

variable_types: struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } *

variable_types: enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_WRITE=2, ELF_C_CLR=3, ELF_C_SET=4, ELF_C_FDDONE=5, ELF_C_FDREAD=6, ELF_C_RDWR=7, ELF_C_NUM=8 }

variable_types:
flags
unsigned int

return_type: unsigned int


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

if ( a1 )
result = elf_flag((_DWORD *)(a1 + 204), a2, a3);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func0((_DWORD *)(a1 + 204), a2, a3);
else
result = 0LL;
return result;
}

original_code:
unsigned
elf_flagehdr(Elf *elf, Elf_Cmd cmd, unsigned flags) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&elf->e_ehdr_flags, cmd, flags);
}

canonical_original_code:
unsigned int elf_flagehdr(struct Elf *elf, enum Elf_Cmd cmd, unsigned int flags) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&elf->e_ehdr_flags, cmd, flags);
}

user_defined_types: enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_WRITE=2, ELF_C_CLR=3, ELF_C_SET=4, ELF_C_FDDONE=5, ELF_C_FDREAD=6, ELF_C_RDWR=7, ELF_C_NUM=8 }


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

if ( a1 )
result = elf_flag((_DWORD *)(a1 + 200), a2, a3);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func0((_DWORD *)(a1 + 200), a2, a3);
else
result = 0LL;
return result;
}

original_code:
unsigned
elf_flagelf(Elf *elf, Elf_Cmd cmd, unsigned flags) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&elf->e_elf_flags, cmd, flags);
}

canonical_original_code:
unsigned int elf_flagelf(struct Elf *elf, enum Elf_Cmd cmd, unsigned int flags) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&elf->e_elf_flags, cmd, flags);
}


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

if ( a1 )
result = elf_flag((_DWORD *)(a1 + 208), a2, a3);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func0((_DWORD *)(a1 + 208), a2, a3);
else
result = 0LL;
return result;
}

original_code:
unsigned
elf_flagphdr(Elf *elf, Elf_Cmd cmd, unsigned flags) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&elf->e_phdr_flags, cmd, flags);
}

canonical_original_code:
unsigned int elf_flagphdr(struct Elf *elf, enum Elf_Cmd cmd, unsigned int flags) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&elf->e_phdr_flags, cmd, flags);
}


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

if ( a1 )
result = elf_flag((_DWORD *)(a1 + 24), a2, a3);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func0((_DWORD *)(a1 + 24), a2, a3);
else
result = 0LL;
return result;
}

original_code:
unsigned
elf_flagscn(Elf_Scn *scn, Elf_Cmd cmd, unsigned flags) {
    if (!scn) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&scn->s_scn_flags, cmd, flags);
}

canonical_original_code:
unsigned int elf_flagscn(struct Elf_Scn *scn, enum Elf_Cmd cmd, unsigned int flags) {
    if (!scn) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&scn->s_scn_flags, cmd, flags);
}

variable_types: struct Elf_Scn { struct Elf_Scn *s_link; struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *


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

if ( a1 )
result = elf_flag((_DWORD *)(a1 + 28), a2, a3);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func0((_DWORD *)(a1 + 28), a2, a3);
else
result = 0LL;
return result;
}

original_code:
unsigned
elf_flagshdr(Elf_Scn *scn, Elf_Cmd cmd, unsigned flags) {
    if (!scn) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&scn->s_shdr_flags, cmd, flags);
}

canonical_original_code:
unsigned int elf_flagshdr(struct Elf_Scn *scn, enum Elf_Cmd cmd, unsigned int flags) {
    if (!scn) {
 return 0;
    }
    do{}while(0);
    return _elf_flag(&scn->s_shdr_flags, cmd, flags);
}


original_code:
char*
elf_getident(Elf *elf, size_t *ptr) {
    size_t tmp;
    if (!ptr) {
 ptr = &tmp;
    }
    if (!elf) {
 *ptr = 0;
 return ((void *)0);
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 *ptr = elf->e_idlen;
 return elf->e_data;
    }
    if (elf->e_ehdr || _elf_cook(elf)) {
 *ptr = elf->e_idlen;
 return elf->e_ehdr;
    }
    *ptr = 0;
    return ((void *)0);
}

canonical_original_code:
char *elf_getident(struct Elf *elf, unsigned long *ptr) {
    unsigned long tmp;
    if (!ptr) {
 ptr = &tmp;
    }
    if (!elf) {
 *ptr = 0;
 return ((void *)0);
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 *ptr = elf->e_idlen;
 return elf->e_data;
    }
    if (elf->e_ehdr || _elf_cook(elf)) {
 *ptr = elf->e_idlen;
 return elf->e_ehdr;
    }
    *ptr = 0;
    return ((void *)0);
}


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

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

original_code:
int vfs_open(const char *pathname, int flags, mode_t mode) {
 return 0;
}

canonical_original_code:
int vfs_open(char *pathname, int flags, unsigned int mode) {
 return 0;
}

variable_types:
pathname
char *

variable_types: flags int

variable_types:
mode
unsigned int


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

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

original_code:
int vfs_close(int fd) {
 return 0;
}

canonical_original_code:
int vfs_close(int fd) {
 return 0;
}

variable_types: fd int


decompiled_code:
__int64 __fastcall get_addr_and_class(__int64 *a1, int a2, unsigned int a3, _DWORD *a4)
{
__int64 v4; // rax
int v5; // er8
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rsi
__int64 result; // rax

if ( !a1 )
return 0LL;
v4 = *(_QWORD *)(a1[7] + 8);
if ( *(_DWORD *)(v4 + 16) == 3 )
{
v5 = *(_DWORD *)(v4 + 144);
v6 = (unsigned int)(v5 - 1);
if ( (unsigned int)v6 > 1 )
{
elf_errno = 19;
result = 0LL;
}
else if ( *((_DWORD *)a1 + 2) == a3 )
{
v7 = elf_fmsize[34 * v6 + 34 * (unsigned int)(*((_DWORD *)a1 + 10) - 1) + 2 * a3];
if ( v7 )
{
if ( a2 < 0 || (v8 = v7 * (a2 + 1), a1[2] < v8) )
{
elf_errno = 70;
result = 0LL;
}
else
{
result = *a1;
if ( *a1 )
{
*a4 = v5;
result += v8 - v7;
}
else
{
elf_errno = 18;
}
}
}
else
{
elf_errno = 3;
result = 0LL;
}
}
else
{
elf_errno = 71;
result = 0LL;
}
}
else
{
elf_errno = 13;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, int a2, unsigned int a3, _DWORD *a4)
{
__int64 v4; // rax
int v5; // er8
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rsi
__int64 result; // rax

if ( !a1 )
return 0LL;
v4 = *(_QWORD *)(a1[7] + 8);
if ( *(_DWORD *)(v4 + 16) == 3 )
{
v5 = *(_DWORD *)(v4 + 144);
v6 = (unsigned int)(v5 - 1);
if ( (unsigned int)v6 > 1 )
{
elf_errno = 19;
result = 0LL;
}
else if ( *((_DWORD *)a1 + 2) == a3 )
{
v7 = elf_fmsize[34 * v6 + 34 * (unsigned int)(*((_DWORD *)a1 + 10) - 1) + 2 * a3];
if ( v7 )
{
if ( a2 < 0 || (v8 = v7 * (a2 + 1), a1[2] < v8) )
{
elf_errno = 70;
result = 0LL;
}
else
{
result = *a1;
if ( *a1 )
{
*a4 = v5;
result += v8 - v7;
}
else
{
elf_errno = 18;
}
}
}
else
{
elf_errno = 3;
result = 0LL;
}
}
else
{
elf_errno = 71;
result = 0LL;
}
}
else
{
elf_errno = 13;
result = 0LL;
}
return result;
}

original_code:
static char*
get_addr_and_class(const Elf_Data *data, int ndx, Elf_Type type, unsigned *cls) {
    Scn_Data *sd = (Scn_Data*)data;
    Elf_Scn *scn;
    Elf *elf;
    size_t n;
    if (!sd) {
 return ((void *)0);
    }
    do{}while(0);
    scn = sd->sd_scn;
    do{}while(0);
    do{}while(0);
    elf = scn->s_elf;
    do{}while(0);
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 (_elf_errno = (ERROR_NOTELF));
 return ((void *)0);
    }
    if (!((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return ((void *)0);
    }
    if (data->d_type != type) {
 (_elf_errno = (ERROR_BADTYPE));
 return ((void *)0);
    }
    n = (_elf_fmsize[((elf->e_class))-1][((data->d_version))-0 -1][((type))-ELF_T_BYTE][(0)]);
    if (n == 0) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
 return ((void *)0);
    }
    if (ndx < 0 || data->d_size < (ndx + 1) * n) {
 (_elf_errno = (ERROR_BADINDEX));
 return ((void *)0);
    }
    if (!data->d_buf) {
 (_elf_errno = (ERROR_NULLBUF));
 return ((void *)0);
    }
    if (cls) {
 *cls = elf->e_class;
    }
    return (char*)data->d_buf + n * ndx;
}

canonical_original_code:
static char *get_addr_and_class(struct Elf_Data *data, int ndx, enum Elf_Type type, unsigned int *cls) {
    struct Scn_Data *sd = (Scn_Data*)data;
    struct Elf_Scn *scn;
    struct Elf *elf;
    unsigned long n;
    if (!sd) {
 return ((void *)0);
    }
    do{}while(0);
    scn = sd->sd_scn;
    do{}while(0);
    do{}while(0);
    elf = scn->s_elf;
    do{}while(0);
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 (_elf_errno = (ERROR_NOTELF));
 return ((void *)0);
    }
    if (!((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return ((void *)0);
    }
    if (data->d_type != type) {
 (_elf_errno = (ERROR_BADTYPE));
 return ((void *)0);
    }
    n = (_elf_fmsize[((elf->e_class))-1][((data->d_version))-0 -1][((type))-ELF_T_BYTE][(0)]);
    if (n == 0) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
 return ((void *)0);
    }
    if (ndx < 0 || data->d_size < (ndx + 1) * n) {
 (_elf_errno = (ERROR_BADINDEX));
 return ((void *)0);
    }
    if (!data->d_buf) {
 (_elf_errno = (ERROR_NULLBUF));
 return ((void *)0);
    }
    if (cls) {
 *cls = elf->e_class;
    }
    return (char *)data->d_buf + n * ndx;
}

variable_types:
cls
unsigned int *

variable_types: struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn { struct Elf_Scn *s_link; struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *

variable_types: struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn { struct Elf_Scn *s_link; struct Elf *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *


decompiled_code:
__int64 __fastcall elf32_fsize(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx

v3 = elf_fsize(1, a1, a3);
return v4 * v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx

v3 = func0(1, a1, a3);
return v4 * v3;
}

original_code:
size_t
elf32_fsize(Elf_Type type, size_t count, unsigned ver) {
    return count * _elf_fsize(1, type, ver);
}

canonical_original_code:
unsigned long elf32_fsize(enum Elf_Type type, unsigned long count, unsigned int ver) {
    return count * _elf_fsize(1, type, ver);
}

variable_types: enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 }

variable_types:
ver
unsigned int


decompiled_code:
__int64 __fastcall elf64_fsize(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx

v3 = elf_fsize(2, a1, a3);
return v4 * v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx

v3 = func0(2, a1, a3);
return v4 * v3;
}

original_code:
size_t
elf64_fsize(Elf_Type type, size_t count, unsigned ver) {
    return count * _elf_fsize(2, type, ver);
}

canonical_original_code:
unsigned long elf64_fsize(enum Elf_Type type, unsigned long count, unsigned int ver) {
    return count * _elf_fsize(2, type, ver);
}


decompiled_code:
__int64 __fastcall gelf_fsize(__int64 a1, unsigned int a2, __int64 a3, int a4)
{
__int64 result; // rax
int v5; // edi
__int64 v6; // rax
__int64 v7; // r8

result = 0LL;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 16) == 3 )
{
v5 = *(_DWORD *)(a1 + 144);
if ( (unsigned int)(v5 - 1) <= 1 )
{
v6 = elf_fsize(v5, a2, a4);
result = v7 * v6;
}
else
{
elf_errno = 19;
}
}
else
{
elf_errno = 13;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, __int64 a3, int a4)
{
__int64 result; // rax
int v5; // edi
__int64 v6; // rax
__int64 v7; // r8

result = 0LL;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 16) == 3 )
{
v5 = *(_DWORD *)(a1 + 144);
if ( (unsigned int)(v5 - 1) <= 1 )
{
v6 = func0(v5, a2, a4);
result = v7 * v6;
}
else
{
elf_errno = 19;
}
}
else
{
elf_errno = 13;
}
}
return result;
}

original_code:
size_t
gelf_fsize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
    if (elf) {
 if (elf->e_kind != ELF_K_ELF) {
     (_elf_errno = (ERROR_NOTELF));
 }
 else if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
     return count * _elf_fsize(elf->e_class, type, ver);
 }
 else {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
    }
    return 0;
}

canonical_original_code:
unsigned long gelf_fsize(struct Elf *elf, enum Elf_Type type, unsigned long count, unsigned int ver) {
    if (elf) {
 if (elf->e_kind != ELF_K_ELF) {
     (_elf_errno = (ERROR_NOTELF));
 }
 else if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
     return count * _elf_fsize(elf->e_class, type, ver);
 }
 else {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
    }
    return 0;
}


decompiled_code:
__int64 __fastcall gelf_msize(__int64 a1, unsigned int a2, __int64 a3, int a4)
{
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rax

result = 0LL;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 16) == 3 )
{
v5 = (unsigned int)(*(_DWORD *)(a1 + 144) - 1);
if ( (unsigned int)v5 <= 1 )
{
if ( a4 == 1 )
{
if ( a2 <= 0x10 && (v6 = elf_fmsize[34 * v5 + 2 * a2]) != 0 )
{
result = a3 * v6;
}
else
{
elf_errno = 15;
result = 0LL;
}
}
else
{
elf_errno = 9;
}
}
else
{
elf_errno = 19;
}
}
else
{
elf_errno = 13;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, __int64 a3, int a4)
{
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rax

result = 0LL;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 16) == 3 )
{
v5 = (unsigned int)(*(_DWORD *)(a1 + 144) - 1);
if ( (unsigned int)v5 <= 1 )
{
if ( a4 == 1 )
{
if ( a2 <= 0x10 && (v6 = elf_fmsize[34 * v5 + 2 * a2]) != 0 )
{
result = a3 * v6;
}
else
{
elf_errno = 15;
result = 0LL;
}
}
else
{
elf_errno = 9;
}
}
else
{
elf_errno = 19;
}
}
else
{
elf_errno = 13;
}
}
return result;
}

original_code:
size_t
gelf_msize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
    size_t n;
    if (elf) {
 if (elf->e_kind != ELF_K_ELF) {
     (_elf_errno = (ERROR_NOTELF));
 }
 else if (!((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
 else if (!((ver) > 0 && (ver) <= 1)) {
     (_elf_errno = (ERROR_UNKNOWN_VERSION));
 }
 else if (!((unsigned)(type) < ELF_T_NUM)) {
     (_elf_errno = (ERROR_UNKNOWN_TYPE));
 }
 else if (!(n = (_elf_fmsize[((elf->e_class))-1][((ver))-0 -1][((type))-ELF_T_BYTE][(0)]))) {
     (_elf_errno = (ERROR_UNKNOWN_TYPE));
 }
 else {
     return count * n;
 }
    }
    return 0;
}

canonical_original_code:
unsigned long gelf_msize(struct Elf *elf, enum Elf_Type type, unsigned long count, unsigned int ver) {
    unsigned long n;
    if (elf) {
 if (elf->e_kind != ELF_K_ELF) {
     (_elf_errno = (ERROR_NOTELF));
 }
 else if (!((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
 else if (!((ver) > 0 && (ver) <= 1)) {
     (_elf_errno = (ERROR_UNKNOWN_VERSION));
 }
 else if (!((unsigned int)(type) < ELF_T_NUM)) {
     (_elf_errno = (ERROR_UNKNOWN_TYPE));
 }
 else if (!(n = (_elf_fmsize[((elf->e_class))-1][((ver))-0 -1][((type))-ELF_T_BYTE][(0)]))) {
     (_elf_errno = (ERROR_UNKNOWN_TYPE));
 }
 else {
     return count * n;
 }
    }
    return 0;
}

variable_types:
n
unsigned long


decompiled_code:
void *__fastcall elf32_newehdr(__int64 a1)
{
return elf_newehdr(a1, 1);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
return func0(a1, 1);
}

original_code:
Elf32_Ehdr*
elf32_newehdr(Elf *elf) {
    return (Elf32_Ehdr*)_elf_newehdr(elf, 1);
}

canonical_original_code:
struct Elf32_Ehdr *elf32_newehdr(struct Elf *elf) {
    return (struct Elf32_Ehdr *)_elf_newehdr(elf, 1);
}

return_type: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *


decompiled_code:
void *__fastcall elf64_newehdr(__int64 a1)
{
return elf_newehdr(a1, 2);
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
return func0(a1, 2);
}

original_code:
Elf64_Ehdr*
elf64_newehdr(Elf *elf) {
    return (Elf64_Ehdr*)_elf_newehdr(elf, 2);
}

canonical_original_code:
struct Elf64_Ehdr *elf64_newehdr(struct Elf *elf) {
    return (struct Elf64_Ehdr *)_elf_newehdr(elf, 2);
}

return_type: struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *


decompiled_code:
void *__fastcall gelf_newehdr(__int64 a1, int a2)
{
if ( (unsigned int)(a2 - 1) <= 1 && elf_fmsize[34 * (unsigned int)(elf_version - 1) + 6 + 34 * (__int64)(a2 - 1)] )
return elf_newehdr(a1, a2);
elf_errno = 19;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, int a2)
{
if ( (unsigned int)(a2 - 1) <= 1 && elf_fmsize[34 * (unsigned int)(elf_version - 1) + 6 + 34 * (__int64)(a2 - 1)] )
return func0(a1, a2);
elf_errno = 19;
return 0LL;
}

original_code:
unsigned long
gelf_newehdr(Elf *elf, int cls) {
    if (!((cls) >= 1 && (cls) <= 2) || !(_elf_fmsize[((cls))-1][((_elf_version))-0 -1][((ELF_T_EHDR))-ELF_T_BYTE][(0)])) {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return 0;
    }
    return (unsigned long)_elf_newehdr(elf, cls);
}

canonical_original_code:
unsigned long gelf_newehdr(struct Elf *elf, int cls) {
    if (!((cls) >= 1 && (cls) <= 2) || !(_elf_fmsize[((cls))-1][((_elf_version))-0 -1][((ELF_T_EHDR))-ELF_T_BYTE][(0)])) {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return 0;
    }
    return (unsigned long)_elf_newehdr(elf, cls);
}

variable_types: cls int


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

if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 16) == 1 )
{
if ( a2 && *(_QWORD *)a1 >= a2 )
{
*(_QWORD *)(a1 + 96) = a2;
result = a2;
}
else
{
elf_errno = 8;
result = 0LL;
}
}
else
{
elf_errno = 7;
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 16) == 1 )
{
if ( a2 && *(_QWORD *)a1 >= a2 )
{
*(_QWORD *)(a1 + 96) = a2;
result = a2;
}
else
{
elf_errno = 8;
result = 0LL;
}
}
else
{
elf_errno = 7;
result = 0LL;
}
return result;
}

original_code:
size_t
elf_rand(Elf *elf, size_t offset) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_AR) {
 (_elf_errno = (ERROR_NOTARCHIVE));
    }
    else if (offset <= 0 || offset > elf->e_size) {
 (_elf_errno = (ERROR_BADOFF));
    }
    else {
 elf->e_off = offset;
 return offset;
    }
    return 0;
}

canonical_original_code:
unsigned long elf_rand(struct Elf *elf, unsigned long offset) {
    if (!elf) {
 return 0;
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_AR) {
 (_elf_errno = (ERROR_NOTARCHIVE));
    }
    else if (offset <= 0 || offset > elf->e_size) {
 (_elf_errno = (ERROR_BADOFF));
    }
    else {
 elf->e_off = offset;
 return offset;
    }
    return 0;
}

variable_types:
offset
unsigned long


nlist

decompiled_code:
__int64 __fastcall nlist(char *file, _QWORD *a2)
{
unsigned int v2; // er12
_QWORD *v3; // rbx
unsigned int v4; // eax
_BYTE *v5; // rax
unsigned int v7; // ebp
unsigned int v8; // eax
__int64 v9; // rax
__int64 v10; // r13
unsigned int v11; // er14
int v12; // edi

v2 = -1;
v3 = a2;
v4 = elf_version(1LL);
if ( v4 )
{
v7 = v4;
v8 = open(file, 0);
v2 = v8;
if ( v8 == -1 )
{
elf_version(v7);
}
else
{
v9 = elf_begin(v8, 1LL, 0LL);
v10 = v9;
if ( v9 )
{
v11 = elf_nlist(v9, (__int64)a2);
elf_end(v10);
close(v2);
elf_version(v7);
if ( !v11 )
return 0;
v2 = v11;
}
else
{
v12 = v2;
v2 = -1;
close(v12);
elf_version(v7);
}
}
}
v5 = (_BYTE *)*a2;
if ( *a2 )
{
do
{
if ( !*v5 )
break;
v3[1] = 0LL;
v5 = (_BYTE *)v3[3];
v3 += 3;
}
while ( v5 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *file, _QWORD *a2)
{
unsigned int v2; // er12
_QWORD *v3; // rbx
unsigned int v4; // eax
_BYTE *v5; // rax
unsigned int v7; // ebp
unsigned int v8; // eax
__int64 v9; // rax
__int64 v10; // r13
unsigned int v11; // er14
int v12; // edi

v2 = -1;
v3 = a2;
v4 = elf_version(1LL);
if ( v4 )
{
v7 = v4;
v8 = open(file, 0);
v2 = v8;
if ( v8 == -1 )
{
elf_version(v7);
}
else
{
v9 = elf_begin(v8, 1LL, 0LL);
v10 = v9;
if ( v9 )
{
v11 = func2(v9, (__int64)a2);
elf_end(v10);
close(v2);
elf_version(v7);
if ( !v11 )
return 0;
v2 = v11;
}
else
{
v12 = v2;
v2 = -1;
close(v12);
elf_version(v7);
}
}
}
v5 = (_BYTE *)*a2;
if ( *a2 )
{
do
{
if ( !*v5 )
break;
v3[1] = 0LL;
v5 = (_BYTE *)v3[3];
v3 += 3;
}
while ( v5 );
}
return v2;
}

original_code:
int
nlist(const char *filename, struct nlist *nl) {
    int result = -1;
    unsigned oldver;
    Elf *elf;
    int fd;
    if ((oldver = elf_version(1)) != 0) {
 if ((fd = open(filename, (0 | 0))) != -1) {
     if ((elf = elf_begin(fd, ELF_C_READ, ((void *)0)))) {
  result = _elf_nlist(elf, nl);
  elf_end(elf);
     }
     close(fd);
 }
 elf_version(oldver);
    }
    if (result) {
 while (nl->n_name && *nl->n_name) {
     nl->n_value = 0;
     nl++;
 }
    }
    return result;
}

canonical_original_code:
int nlist(char *filename, struct nlist *nl) {
    int result = -1;
    unsigned int oldver;
    struct Elf *elf;
    int fd;
    if ((oldver = elf_version(1)) != 0) {
 if ((fd = open(filename, (0 | 0))) != -1) {
     if ((elf = elf_begin(fd, ELF_C_READ, ((void *)0)))) {
  result = _elf_nlist(elf, nl);
  elf_end(elf);
     }
     close(fd);
 }
 elf_version(oldver);
    }
    if (result) {
 while (nl->n_name && *nl->n_name) {
     nl->n_value = 0;
     nl++;
 }
    }
    return result;
}

variable_types:
filename
char *

variable_types: struct nlist { char *n_name; long n_value; short n_scnum; unsigned short n_type; char n_sclass; char n_numaux; } *

variable_types: result int

variable_types:
oldver
unsigned int


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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
size_t
elf_ndxscn(Elf_Scn *scn) {
    if (!scn) {
 return 0;
    }
    do{}while(0);
    return scn->s_index;
}

canonical_original_code:
unsigned long elf_ndxscn(struct Elf_Scn *scn) {
    if (!scn) {
 return 0;
    }
    do{}while(0);
    return scn->s_index;
}

variable_types: struct Elf_Scn { struct Elf_Scn *s_link; struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *


original_code:
Elf_Arsym*
elf_getarsym(Elf *elf, size_t *ptr) {
    Elf_Arsym *syms;
    size_t count;
    size_t tmp;
    size_t i;
    char *s;
    char *e;
    if (!ptr) {
 ptr = &tmp;
    }
    *ptr = 0;
    if (!elf) {
 return ((void *)0);
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_AR) {
 (_elf_errno = (ERROR_NOTARCHIVE));
 return ((void *)0);
    }
    if (elf->e_symtab && !elf->e_free_syms) {
 if (elf->e_symlen < 4) {
     (_elf_errno = (ERROR_SIZE_ARSYMTAB));
     return ((void *)0);
 }
 count = ((unsigned int) ((((unsigned int)((unsigned char*)(elf->e_symtab))[0])<<(24)) | (((unsigned int)((unsigned char*)(elf->e_symtab))[1])<<(16)) | (((unsigned int)((unsigned char*)(elf->e_symtab))[2])<<(8)) | (((unsigned int)((unsigned char*)(elf->e_symtab))[3])<<(0))));
 if (elf->e_symlen < 4 * (count + 1)) {
     (_elf_errno = (ERROR_SIZE_ARSYMTAB));
     return ((void *)0);
 }
 if (!(syms = (Elf_Arsym*)malloc((count + 1) * sizeof(*syms)))) {
     (_elf_errno = (ERROR_MEM_ARSYMTAB));
     return ((void *)0);
 }
 s = elf->e_symtab + 4 * (count + 1);
 e = elf->e_symtab + elf->e_symlen;
 for (i = 0; i < count; i++, s++) {
     syms[i].as_name = s;
     while (s < e && *s) {
  s++;
     }
     if (s >= e) {
  (_elf_errno = (ERROR_SIZE_ARSYMTAB));
  free(syms);
  return ((void *)0);
     }
     do{}while(0);
     syms[i].as_hash = elf_hash((unsigned char*)syms[i].as_name);
     syms[i].as_off = ((unsigned int) ((((unsigned int)((unsigned char*)(elf->e_symtab + 4 * (i + 1)))[0])<<(24)) | (((unsigned int)((unsigned char*)(elf->e_symtab + 4 * (i + 1)))[1])<<(16)) | (((unsigned int)((unsigned char*)(elf->e_symtab + 4 * (i + 1)))[2])<<(8)) | (((unsigned int)((unsigned char*)(elf->e_symtab + 4 * (i + 1)))[3])<<(0))));
 }
 syms[count].as_name = ((void *)0);
 syms[count].as_hash = ~0UL;
 syms[count].as_off = 0;
 elf->e_symtab = (char*)syms;
 elf->e_symlen = count + 1;
 elf->e_free_syms = 1;
    }
    *ptr = elf->e_symlen;
    return (Elf_Arsym*)elf->e_symtab;
}

canonical_original_code:
struct Elf_Arsym *elf_getarsym(struct Elf *elf, unsigned long *ptr) {
    struct Elf_Arsym *syms;
    unsigned long count;
    unsigned long tmp;
    unsigned long i;
    char *s;
    char *e;
    if (!ptr) {
 ptr = &tmp;
    }
    *ptr = 0;
    if (!elf) {
 return ((void *)0);
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_AR) {
 (_elf_errno = (ERROR_NOTARCHIVE));
 return ((void *)0);
    }
    if (elf->e_symtab && !elf->e_free_syms) {
 if (elf->e_symlen < 4) {
     (_elf_errno = (ERROR_SIZE_ARSYMTAB));
     return ((void *)0);
 }
 count = ((unsigned int) ((((unsigned int)((unsigned char *)(elf->e_symtab))[0])<<(24)) | (((unsigned int)((unsigned char *)(elf->e_symtab))[1])<<(16)) | (((unsigned int)((unsigned char *)(elf->e_symtab))[2])<<(8)) | (((unsigned int)((unsigned char *)(elf->e_symtab))[3])<<(0))));
 if (elf->e_symlen < 4 * (count + 1)) {
     (_elf_errno = (ERROR_SIZE_ARSYMTAB));
     return ((void *)0);
 }
 if (!(syms = (struct Elf_Arsym *)malloc((count + 1) * sizeof(*syms)))) {
     (_elf_errno = (ERROR_MEM_ARSYMTAB));
     return ((void *)0);
 }
 s = elf->e_symtab + 4 * (count + 1);
 e = elf->e_symtab + elf->e_symlen;
 for (i = 0; i < count; i++, s++) {
     syms[i].as_name = s;
     while (s < e && *s) {
  s++;
     }
     if (s >= e) {
  (_elf_errno = (ERROR_SIZE_ARSYMTAB));
  free(syms);
  return ((void *)0);
     }
     do{}while(0);
     syms[i].as_hash = elf_hash((unsigned char *)syms[i].as_name);
     syms[i].as_off = ((unsigned int) ((((unsigned int)((unsigned char *)(elf->e_symtab + 4 * (i + 1)))[0])<<(24)) | (((unsigned int)((unsigned char *)(elf->e_symtab + 4 * (i + 1)))[1])<<(16)) | (((unsigned int)((unsigned char *)(elf->e_symtab + 4 * (i + 1)))[2])<<(8)) | (((unsigned int)((unsigned char *)(elf->e_symtab + 4 * (i + 1)))[3])<<(0))));
 }
 syms[count].as_name = ((void *)0);
 syms[count].as_hash = ~0UL;
 syms[count].as_off = 0;
 elf->e_symtab = (char *)syms;
 elf->e_symlen = count + 1;
 elf->e_free_syms = 1;
    }
    *ptr = elf->e_symlen;
    return (struct Elf_Arsym *)elf->e_symtab;
}

variable_types:
ptr
unsigned long *

variable_types: struct Elf_Arsym { char *as_name; unsigned long as_off; unsigned long as_hash; } *

variable_types:
count
unsigned long

variable_types:
tmp
unsigned long

variable_types:
i
unsigned long

variable_types:
s
char *

variable_types:
e
char *


original_code:
char*
elf_strptr(Elf *elf, size_t section, size_t offset) {
    Elf_Data *data;
    Elf_Scn *scn;
    size_t n;
    char *s;
    if (!elf) {
 return ((void *)0);
    }
    do{}while(0);
    if (!(scn = elf_getscn(elf, section))) {
 return ((void *)0);
    }
    if (scn->s_index == 0) {
 (_elf_errno = (ERROR_NOSTRTAB));
 return ((void *)0);
    }
    if (elf->e_class == 1) {
 if (scn->s_uhdr.u_shdr32.sh_type != 3) {
     (_elf_errno = (ERROR_NOSTRTAB));
     return ((void *)0);
 }
    }
    else if (elf->e_class == 2) {
 if (scn->s_uhdr.u_shdr64.sh_type != 3) {
     (_elf_errno = (ERROR_NOSTRTAB));
     return ((void *)0);
 }
    }
    else if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
 return ((void *)0);
    }
    else {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return ((void *)0);
    }
    n = 0;
    data = ((void *)0);
    if (elf->e_elf_flags & 0x4) {
 while ((data = elf_getdata(scn, data))) {
     n = data->d_off;
     if (offset >= n && offset - n < data->d_size) {
  break;
     }
 }
    }
    else {
 while ((data = elf_getdata(scn, data))) {
     if (data->d_align > 1) {
  n += data->d_align - 1;
  n -= n % data->d_align;
     }
     if (offset < n) {
  (_elf_errno = (ERROR_BADSTROFF));
  return ((void *)0);
     }
     if (offset - n < data->d_size) {
  break;
     }
     n += data->d_size;
 }
    }
    if (data == ((void *)0)) {
 (_elf_errno = (ERROR_BADSTROFF));
 return ((void *)0);
    }
    if (data->d_buf == ((void *)0)) {
 (_elf_errno = (ERROR_NULLBUF));
 return ((void *)0);
    }
    offset -= n;
    s = (char*)data->d_buf;
    if (!(_elf_sanity_checks & (1u << 0))) {
 return s + offset;
    }
    for (n = offset; n < data->d_size; n++) {
 if (s[n] == '\0') {
     return s + offset;
 }
    }
    (_elf_errno = (ERROR_UNTERM));
    return ((void *)0);
}

canonical_original_code:
char *elf_strptr(struct Elf *elf, unsigned long section, unsigned long offset) {
    struct Elf_Data *data;
    struct Elf_Scn *scn;
    unsigned long n;
    char *s;
    if (!elf) {
 return ((void *)0);
    }
    do{}while(0);
    if (!(scn = elf_getscn(elf, section))) {
 return ((void *)0);
    }
    if (scn->s_index == 0) {
 (_elf_errno = (ERROR_NOSTRTAB));
 return ((void *)0);
    }
    if (elf->e_class == 1) {
 if (scn->s_uhdr.u_shdr32.sh_type != 3) {
     (_elf_errno = (ERROR_NOSTRTAB));
     return ((void *)0);
 }
    }
    else if (elf->e_class == 2) {
 if (scn->s_uhdr.u_shdr64.sh_type != 3) {
     (_elf_errno = (ERROR_NOSTRTAB));
     return ((void *)0);
 }
    }
    else if (((elf->e_class) >= 1 && (elf->e_class) <= 2)) {
 (_elf_errno = (ERROR_UNIMPLEMENTED));
 return ((void *)0);
    }
    else {
 (_elf_errno = (ERROR_UNKNOWN_CLASS));
 return ((void *)0);
    }
    n = 0;
    data = ((void *)0);
    if (elf->e_elf_flags & 0x4) {
 while ((data = elf_getdata(scn, data))) {
     n = data->d_off;
     if (offset >= n && offset - n < data->d_size) {
  break;
     }
 }
    }
    else {
 while ((data = elf_getdata(scn, data))) {
     if (data->d_align > 1) {
  n += data->d_align - 1;
  n -= n % data->d_align;
     }
     if (offset < n) {
  (_elf_errno = (ERROR_BADSTROFF));
  return ((void *)0);
     }
     if (offset - n < data->d_size) {
  break;
     }
     n += data->d_size;
 }
    }
    if (data == ((void *)0)) {
 (_elf_errno = (ERROR_BADSTROFF));
 return ((void *)0);
    }
    if (data->d_buf == ((void *)0)) {
 (_elf_errno = (ERROR_NULLBUF));
 return ((void *)0);
    }
    offset -= n;
    s = (char *)data->d_buf;
    if (!(_elf_sanity_checks & (1u << 0))) {
 return s + offset;
    }
    for (n = offset; n < data->d_size; n++) {
 if (s[n] == '\0') {
     return s + offset;
 }
    }
    (_elf_errno = (ERROR_UNTERM));
    return ((void *)0);
}

variable_types: struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn { struct Elf_Scn *s_link; struct Elf *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *

variable_types:
section
unsigned long

variable_types: struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } *


decompiled_code:
__int64 __fastcall elf_version(int a1)
{
signed int v1; // eax
__int64 result; // rax

v1 = (unsigned int)getenv("LIBELF_SANITY_CHECKS");
if ( v1 )
elf_sanity_checks = strtol((const char *)v1, 0LL, 0);
result = 1LL;
if ( a1 )
{
if ( a1 == 1 )
{
if ( elf_version )
result = elf_version;
elf_version = 1;
}
else
{
elf_errno = 9;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
signed int v1; // eax
__int64 result; // rax

v1 = (unsigned int)getenv("LIBELF_SANITY_CHECKS");
if ( v1 )
elf_sanity_checks = strtol((const char *)v1, 0LL, 0);
result = 1LL;
if ( a1 )
{
if ( a1 == 1 )
{
if ( elf_version )
result = elf_version;
elf_version = 1;
}
else
{
elf_errno = 9;
result = 0LL;
}
}
return result;
}

original_code:
unsigned
elf_version(unsigned ver) {
    const char *s;
    unsigned tmp;
    if ((s = getenv("LIBELF_SANITY_CHECKS"))) {
 _elf_sanity_checks = (int)strtol(s, (char**)((void *)0), 0);
    }
    if (ver == 0) {
 return 1;
    }
    if (!((ver) > 0 && (ver) <= 1)) {
 (_elf_errno = (ERROR_UNKNOWN_VERSION));
 return 0;
    }
    tmp = _elf_version == 0 ? 1 : _elf_version;
    _elf_version = ver;
    return tmp;
}

canonical_original_code:
unsigned int elf_version(unsigned int ver) {
    char *s;
    unsigned int tmp;
    if ((s = getenv("LIBELF_SANITY_CHECKS"))) {
 _elf_sanity_checks = (int)strtol(s, (char **)((void *)0), 0);
    }
    if (ver == 0) {
 return 1;
    }
    if (!((ver) > 0 && (ver) <= 1)) {
 (_elf_errno = (ERROR_UNKNOWN_VERSION));
 return 0;
    }
    tmp = _elf_version == 0 ? 1 : _elf_version;
    _elf_version = ver;
    return tmp;
}

variable_types:
ver
unsigned int

variable_types:
tmp
unsigned int


decompiled_code:
__int64 __fastcall elf32_getehdr(__int64 a1)
{
return elf_getehdr(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return func0(a1, 1);
}

original_code:
Elf32_Ehdr*
elf32_getehdr(Elf *elf) {
    return (Elf32_Ehdr*)_elf_getehdr(elf, 1);
}

canonical_original_code:
struct Elf32_Ehdr *elf32_getehdr(struct Elf *elf) {
    return (struct Elf32_Ehdr *)_elf_getehdr(elf, 1);
}

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }


decompiled_code:
__int64 __fastcall elf64_getehdr(__int64 a1)
{
return elf_getehdr(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return func0(a1, 2);
}

original_code:
Elf64_Ehdr*
elf64_getehdr(Elf *elf) {
    return (Elf64_Ehdr*)_elf_getehdr(elf, 2);
}

canonical_original_code:
struct Elf64_Ehdr *elf64_getehdr(struct Elf *elf) {
    return (struct Elf64_Ehdr *)_elf_getehdr(elf, 2);
}

user_defined_types: struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }


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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
Elf_Kind
elf_kind(Elf *elf) {
    if (!elf) {
 return ELF_K_NONE;
    }
    do{}while(0);
    return elf->e_kind;
}

canonical_original_code:
enum Elf_Kind elf_kind(struct Elf *elf) {
    if (!elf) {
 return ELF_K_NONE;
    }
    do{}while(0);
    return elf->e_kind;
}

return_type: enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 }


original_code:
size_t
elfx_movscn(Elf *elf, Elf_Scn *scn, Elf_Scn *after) {
    Elf_Scn *prev;
    Elf_Scn *tmp;
    int off;
    if (!elf || !scn || !after) {
 return 0;
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 (_elf_errno = (ERROR_NOTELF));
 return 0;
    }
    do{}while(0);
    do{}while(0);
    if (scn->s_elf != elf || after->s_elf != elf) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    do{}while(0);
    if (scn == elf->e_scn_1) {
 (_elf_errno = (ERROR_NULLSCN));
 return 0;
    }
    if (scn == after || scn == after->s_link) {
 return scn->s_index;
    }
    prev = ((void *)0);
    for (tmp = elf->e_scn_1; tmp->s_link; tmp = tmp->s_link) {
 if (tmp->s_link == scn) {
     prev = tmp;
     break;
 }
    }
    do{}while(0);
    off = 0;
    for (tmp = elf->e_scn_1; tmp; tmp = tmp->s_link) {
 if (off) {
     tmp->s_index += off;
 }
 if (tmp == after) {
     off++;
 }
 else if (tmp == scn) {
     off--;
 }
    }
    do{}while(0);
    prev->s_link = scn->s_link;
    scn->s_link = after->s_link;
    after->s_link = scn;
    scn->s_index = after->s_index + 1;
    if (elf->e_scn_n == scn) {
 elf->e_scn_n = prev;
    }
    else if (elf->e_scn_n == after) {
 elf->e_scn_n = scn;
    }
    return scn->s_index;
}

canonical_original_code:
unsigned long elfx_movscn(struct Elf *elf, struct Elf_Scn *scn, struct Elf_Scn *after) {
    struct Elf_Scn *prev;
    struct Elf_Scn *tmp;
    int off;
    if (!elf || !scn || !after) {
 return 0;
    }
    do{}while(0);
    if (elf->e_kind != ELF_K_ELF) {
 (_elf_errno = (ERROR_NOTELF));
 return 0;
    }
    do{}while(0);
    do{}while(0);
    if (scn->s_elf != elf || after->s_elf != elf) {
 (_elf_errno = (ERROR_ELFSCNMISMATCH));
 return 0;
    }
    do{}while(0);
    if (scn == elf->e_scn_1) {
 (_elf_errno = (ERROR_NULLSCN));
 return 0;
    }
    if (scn == after || scn == after->s_link) {
 return scn->s_index;
    }
    prev = ((void *)0);
    for (tmp = elf->e_scn_1; tmp->s_link; tmp = tmp->s_link) {
 if (tmp->s_link == scn) {
     prev = tmp;
     break;
 }
    }
    do{}while(0);
    off = 0;
    for (tmp = elf->e_scn_1; tmp; tmp = tmp->s_link) {
 if (off) {
     tmp->s_index += off;
 }
 if (tmp == after) {
     off++;
 }
 else if (tmp == scn) {
     off--;
 }
    }
    do{}while(0);
    prev->s_link = scn->s_link;
    scn->s_link = after->s_link;
    after->s_link = scn;
    scn->s_index = after->s_index + 1;
    if (elf->e_scn_n == scn) {
 elf->e_scn_n = prev;
    }
    else if (elf->e_scn_n == after) {
 elf->e_scn_n = scn;
    }
    return scn->s_index;
}

variable_types:
scn
struct Elf_Scn *

variable_types:
after
struct Elf_Scn *

variable_types: off int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
size_t v4; // rbx
unsigned int v5; // er12
int v6; // ebx
char ptr[3]; // [rsp+7h] [rbp-21h] BYREF
char s[30]; // [rsp+Ah] [rbp-1Eh] BYREF

if ( argc <= 0 )
{
puts("ERROR: USAGE: COMMAND <input file> <output file(*.coe)>\n");
exit(1);
}
fi = fopen(argv[1], "rb");
if ( !fi )
goto LABEL_28;
fp = fopen("/Users/toku1938/Work/Convert2Coe/src/header.txt", "rb");
if ( !fp )
{
fwrite("ERROR: cannot find header file\n\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
ft = fopen("test.coe", "wb");
if ( !ft )
{
LABEL_28:
fwrite("ERROR: cannot open input file\n\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
for ( i = 0; i != 3; i += buf == 10 )
{
if ( !fread(&buf, 1uLL, 1uLL, fi) )
break;
printf("%02x", (unsigned __int8)buf);
}
while ( fread(&data, 1uLL, 1uLL, fp) == 1 )
{
if ( fwrite(&data, 1uLL, 1uLL, ft) != 1 )
{
fwrite("ERROR: cannot write header file to output file\n\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
}
fclose(fp);
while ( fread(ptr, 1uLL, 3uLL, fi) == 3 )
{
sprintf(s, "%x%x%x", (unsigned __int8)ptr[0] >> 4, (unsigned __int8)ptr[1] >> 4, (unsigned __int8)ptr[2] >> 4);
v4 = strlen(s);
v5 = fwrite(s, 1uLL, v4, ft);
if ( v5 != (_DWORD)v4 )
{
fwrite("ERROR: cannot write the data to output file\n\n", 1uLL, 0x2DuLL, stderr);
printf("fwrite returns %d\n", v5);
exit(1);
}
fwrite(",\n", 1uLL, 2uLL, ft);
}
fseek(ft, -2LL, 2);
fwrite(";\n", 1uLL, 2uLL, ft);
v6 = ftell(ft);
fclose(ft);
ft = fopen("test.coe", "rb");
if ( !ft || (fo = fopen(argv[2], "wb")) == 0LL )
{
fwrite("ERROR: cannot open output file\n\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
do
{
if ( fread(&data, 1uLL, 1uLL, ft) != 1 )
break;
if ( fwrite(&data, 1uLL, 1uLL, fo) != 1 )
{
fwrite("ERROR: cannot write the data to output file\n\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
}
while ( v6 != (unsigned int)ftell(fo) );
fclose(fi);
fclose(ft);
remove("test.coe");
fclose(fo);
return 0;
}

original_code:
int main(int argc, char** argv)
{
    int i,index;
    char *p,foo[]="\n";
    index = 0;
    i = 0;
    if(argc < 1){
 printf("ERROR: USAGE: COMMAND <input file> <output file(*.coe)>\n\n");
 exit(1);
    }
    if((fi = fopen(argv[1],"rb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open input file\n\n");
 exit(1);
    }
    if((fp = fopen("/Users/toku1938/Work/Convert2Coe/src/header.txt","rb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot find header file\n\n");
 exit(1);
    }
    if((ft = fopen("test.coe","wb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open input file\n\n");
 exit(1);
    }
    while(i= fread(buf,sizeof(unsigned char),1,fi) != 0){
 p = buf;
 do{
     printf("%02x", *p & 0xff);
     if(memcmp(p,foo,1)==0) index++;
     *p++;
 } while(--i);
 if(index==3)break;
    }
    while(fread(&data,sizeof(unsigned char),1,fp) == 1){
 if(fwrite(&data,sizeof(unsigned char),1,ft) != 1){
     fprintf(stderr,"ERROR: cannot write header file to output file\n\n");
     exit(1);
 }
    }
    fclose(fp);
    unsigned char data1[3];
    while(fread(&data1,sizeof(unsigned char),3,fi)==3){
 char a[6];
 int t,len;
 sprintf(a,"%x%x%x", data1[0]/16,data1[1]/16,data1[2]/16);
 len = strlen(a);
 if((t=fwrite(&a,sizeof(char),len,ft))!=len){
     fprintf(stderr,"ERROR: cannot write the data to output file\n\n");
     printf("fwrite returns %d\n",t);
     exit(1);
 }
 fputs(",\n",ft);
    }
    fseek(ft,-2L,2);
    fputs(";\n",ft);
    int loc = ftell(ft);
    fclose(ft);
    if((ft = fopen("test.coe","rb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open output file\n\n");
 exit(1);
    }
    if((fo = fopen(argv[2],"wb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open output file\n\n");
 exit(1);
    }
    while(fread(&data,sizeof(unsigned char),1,ft) == 1){
 int loc_t;
 if(fwrite(&data,sizeof(unsigned char),1,fo)!=1){
     fprintf(stderr,"ERROR: cannot write the data to output file\n\n");
     exit(1);
 }
 if((loc_t=ftell(fo)) == loc) break;
    }
    fclose(fi);
    fclose(ft);
    remove("test.coe");
    fclose(fo);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i; int index;
    char *p; char foo[] = "\n";
    index = 0;
    i = 0;
    if(argc < 1){
 printf("ERROR: USAGE: COMMAND <input file> <output file(*.coe)>\n\n");
 exit(1);
    }
    if((fi = fopen(argv[1],"rb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open input file\n\n");
 exit(1);
    }
    if((fp = fopen("/Users/toku1938/Work/Convert2Coe/src/header.txt","rb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot find header file\n\n");
 exit(1);
    }
    if((ft = fopen("test.coe","wb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open input file\n\n");
 exit(1);
    }
    while(i= fread(buf,sizeof(unsigned char),1,fi) != 0){
 p = buf;
 do{
     printf("%02x", *p & 0xff);
     if(memcmp(p,foo,1)==0) index++;
     *p++;
 } while(--i);
 if(index==3)break;
    }
    while(fread(&data,sizeof(unsigned char),1,fp) == 1){
 if(fwrite(&data,sizeof(unsigned char),1,ft) != 1){
     fprintf(stderr,"ERROR: cannot write header file to output file\n\n");
     exit(1);
 }
    }
    fclose(fp);
    unsigned char data1[3];
    while(fread(&data1,sizeof(unsigned char),3,fi)==3){
 char a[6];
 int t; int len;
 sprintf(a,"%x%x%x", data1[0]/16,data1[1]/16,data1[2]/16);
 len = strlen(a);
 if((t=fwrite(&a,sizeof(char),len,ft))!=len){
     fprintf(stderr,"ERROR: cannot write the data to output file\n\n");
     printf("fwrite returns %d\n",t);
     exit(1);
 }
 fputs(",\n",ft);
    }
    fseek(ft,-2L,2);
    fputs(";\n",ft);
    int loc = ftell(ft);
    fclose(ft);
    if((ft = fopen("test.coe","rb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open output file\n\n");
 exit(1);
    }
    if((fo = fopen(argv[2],"wb")) == ((void *)0)){
 fprintf(stderr,"ERROR: cannot open output file\n\n");
 exit(1);
    }
    while(fread(&data,sizeof(unsigned char),1,ft) == 1){
 int loc_t;
 if(fwrite(&data,sizeof(unsigned char),1,fo)!=1){
     fprintf(stderr,"ERROR: cannot write the data to output file\n\n");
     exit(1);
 }
 if((loc_t=ftell(fo)) == loc) break;
    }
    fclose(fi);
    fclose(ft);
    remove("test.coe");
    fclose(fo);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: index int

variable_types:
p
char *

variable_types:
foo
char []

variable_types:
a
char [6]

variable_types: t int

variable_types: len int

variable_types: loc int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // ebp

if ( argc <= 1 )
{
v4 = 4000;
}
else
{
if ( !(unsigned int)is_number(argv[1], argv, envp) )
{
log(v3);
exit(1);
}
v4 = atoi(argv[1]);
if ( v4 <= 1024 )
{
log(v3);
exit(1);
}
}
gettimeofday(&last_time, 0LL);
current_time = last_time.tv_sec;
create_host((unsigned int)v4);
while ( 1 )
{
mudsleep(1LL);
gettimeofday(&last_time, 0LL);
current_time = last_time.tv_sec;
check_connections();
}
}

original_code:
int main(int argc, char **argv) {
 int port = 4000;
 if( argc > 1 )
 {
  if( !is_number(argv[1]) )
  {
   log("Invalid port number!");
   exit(1);
  }
  else if( (port = atoi(argv[1])) <= 1024 )
  {
   log("Port must be above 1024!");
   exit(1);
  }
 }
 gettimeofday( &last_time, 0 );
 current_time = (time_t)last_time.tv_sec;
 create_host(port);
 while(1) {
  mudsleep(1);
  gettimeofday( &last_time, 0 );
  current_time = (time_t)last_time.tv_sec;
  check_connections();
 }
 return 1;
}

canonical_original_code:
int main(int argc, char **argv) {
 int port = 4000;
 if( argc > 1 )
 {
  if( !is_number(argv[1]) )
  {
   log("Invalid port number!");
   exit(1);
  }
  else if( (port = atoi(argv[1])) <= 1024 )
  {
   log("Port must be above 1024!");
   exit(1);
  }
 }
 gettimeofday( &last_time, 0 );
 current_time = (long)last_time.tv_sec;
 create_host(port);
 while(1) {
  mudsleep(1);
  gettimeofday( &last_time, 0 );
  current_time = (long)last_time.tv_sec;
  check_connections();
 }
 return 1;
}

variable_types: port int


original_code:
void init_socket(SOCKET_T *sock) {
 sock->inbuf[0] = '\0';
 sock->outbuf[0] = '\0';
 sock->connected = 2;
}

canonical_original_code:
void init_socket(struct socket_t *sock) {
 sock->inbuf[0] = '\0';
 sock->outbuf[0] = '\0';
 sock->connected = 2;
}

variable_types: struct socket_t { struct socket_t *next; struct socket_t *prev; struct socket_t *reply; char inbuf[4096]; char outbuf[4096]; char *name; char *password; char *host; int desc; int connected; } *

return_type: void


decompiled_code:
__int64 __fastcall free_socket(__int64 a1)
{
_QWORD *v1; // rax
__int64 result; // rax
__int64 v3; // rax

*(_DWORD *)(a1 + 8244) = 0;
close(*(_DWORD *)(a1 + 8240));
v1 = *(_QWORD **)(a1 + 8);
if ( v1 )
{
*v1 = *(_QWORD *)a1;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
}
else
{
v3 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
{
socket_list = *(_QWORD *)a1;
*(_QWORD *)(v3 + 8) = 0LL;
result = socket_free;
*(_QWORD *)a1 = 0LL;
if ( result )
goto LABEL_4;
goto LABEL_7;
}
socket_list = 0LL;
}
result = socket_free;
if ( socket_free )
{
LABEL_4:
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)a1 = result;
socket_free = a1;
return result;
}
LABEL_7:
socket_free = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_QWORD *v1; // rax
__int64 result; // rax
__int64 v3; // rax

*(_DWORD *)(a1 + 8244) = 0;
close(*(_DWORD *)(a1 + 8240));
v1 = *(_QWORD **)(a1 + 8);
if ( v1 )
{
*v1 = *(_QWORD *)a1;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
}
else
{
v3 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
{
socket_list = *(_QWORD *)a1;
*(_QWORD *)(v3 + 8) = 0LL;
result = socket_free;
*(_QWORD *)a1 = 0LL;
if ( result )
goto LABEL_4;
goto LABEL_7;
}
socket_list = 0LL;
}
result = socket_free;
if ( socket_free )
{
LABEL_4:
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)a1 = result;
socket_free = a1;
return result;
}
LABEL_7:
socket_free = a1;
return result;
}

original_code:
void free_socket(SOCKET_T *sock) {
 sock->connected = 0;
 close(sock->desc);
 if( sock->prev == 0 ) { if( sock->next == 0 ) { socket_list = 0; } else { socket_list = sock->next; socket_list->prev = 0; sock->next = 0; } } else { sock->prev->next = sock->next; sock->next = sock->prev = 0; };
 if( socket_free != 0 ) { socket_free->prev = sock; sock->next = socket_free; socket_free = sock; } else { socket_free = sock; };
}

canonical_original_code:
void free_socket(struct socket_t *sock) {
 sock->connected = 0;
 close(sock->desc);
 if( sock->prev == 0 ) { if( sock->next == 0 ) { socket_list = 0; } else { socket_list = sock->next; socket_list->prev = 0; sock->next = 0; } } else { sock->prev->next = sock->next; sock->next = sock->prev = 0; };
 if( socket_free != 0 ) { socket_free->prev = sock; sock->next = socket_free; socket_free = sock; } else { socket_free = sock; };
}

user_defined_types: struct socket_t { struct socket_t *next; struct socket_t *prev; struct socket_t *reply; char inbuf[4096]; char outbuf[4096]; char *name; char *password; char *host; int desc; int connected; }


decompiled_code:
double __fastcall get_address(__int64 a1, __int64 a2, double a3)
{
int v4; // edi
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
unsigned int v9; // eax
struct hostent *v10; // rax
__int64 v11; // rdi
socklen_t len; // [rsp+Ch] [rbp-101Ch] BYREF
char s[4120]; // [rsp+10h] [rbp-1018h] BYREF

v4 = *(_DWORD *)(a1 + 8240);
len = 16;
getpeername(v4, (struct sockaddr *)a2, &len);
v9 = _bswap_32(*(unsigned int *)(a2 + 4), "%d.%d.%d.%d", v5, v6, v7, v8);
sprintf(s, "%d.%d.%d.%d", HIBYTE(v9), BYTE2(v9), BYTE1(v9), (unsigned __int8)v9);
v10 = gethostbyaddr((const void *)(a2 + 4), 4u, 2);
v11 = a1 + 8232;
if ( v10 )
str_dup(v11, v10->h_name);
else
str_dup(v11, s);
sprintf(s, "Socket connected from %s", *(const char **)(a1 + 8232));
return log(a3);
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1, __int64 a2, double a3)
{
int v4; // edi
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
unsigned int v9; // eax
struct hostent *v10; // rax
__int64 v11; // rdi
socklen_t len; // [rsp+Ch] [rbp-101Ch] BYREF
char s[4120]; // [rsp+10h] [rbp-1018h] BYREF

v4 = *(_DWORD *)(a1 + 8240);
len = 16;
getpeername(v4, (struct sockaddr *)a2, &len);
v9 = _bswap_32(*(unsigned int *)(a2 + 4), "%d.%d.%d.%d", v5, v6, v7, v8);
sprintf(s, "%d.%d.%d.%d", HIBYTE(v9), BYTE2(v9), BYTE1(v9), (unsigned __int8)v9);
v10 = gethostbyaddr((const void *)(a2 + 4), 4u, 2);
v11 = a1 + 8232;
if ( v10 )
str_dup(v11, v10->h_name);
else
str_dup(v11, s);
sprintf(s, "Socket connected from %s", *(const char **)(a1 + 8232));
return log(a3);
}

original_code:
void get_address(SOCKET_T *sock, struct sockaddr_in *sockad) {
 char buf[4096];
 struct hostent *from;
 int addr;
 int size = sizeof(struct sockaddr_in);
 getpeername(sock->desc, (struct sockaddr*)sockad, &size);
 addr = ntohl(sockad->sin_addr.s_addr);
 sprintf( buf, "%d.%d.%d.%d",
  (addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
  (addr >> 8) & 0xFF, (addr) & 0xFF );
 from = gethostbyaddr((char*)&sockad->sin_addr,sizeof(sockad->sin_addr), 2);
 if(from)
  str_dup(&sock->host,from->h_name);
 else
  str_dup(&sock->host,buf);
 sprintf(buf,"Socket connected from %s",sock->host);
 log(buf);
}

canonical_original_code:
void get_address(struct socket_t *sock, struct sockaddr_in *sockad) {
 char buf[4096];
 struct hostent *from;
 int addr;
 int size = sizeof(struct sockaddr_in);
 getpeername(sock->desc, (struct sockaddr *)sockad, &size);
 addr = ntohl(sockad->sin_addr.s_addr);
 sprintf( buf, "%d.%d.%d.%d",
  (addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
  (addr >> 8) & 0xFF, (addr) & 0xFF );
 from = gethostbyaddr((char *)&sockad->sin_addr,sizeof(sockad->sin_addr), 2);
 if(from)
  str_dup(&sock->host,from->h_name);
 else
  str_dup(&sock->host,buf);
 sprintf(buf,"Socket connected from %s",sock->host);
 log(buf);
}

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:
buf
char [4096]

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: addr int

variable_types: size int

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

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


decompiled_code:
__int64 __fastcall create_host(unsigned int a1, double a2)
{
socklen_t v2; // edx
int v3; // er8
struct sockaddr v5; // [rsp+0h] [rbp-118h] BYREF
char s[264]; // [rsp+10h] [rbp-108h] BYREF

host = socket(2, 1, 0);
if ( host < 0 )
{
perror("create_host: failed to create host socket");
exit(1);
}
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(a1);
*(_DWORD *)&v5.sa_data[2] = _bswap_32(0LL, (const char *)&v5);
if ( bind(v3, &v5, v2) < 0 )
{
perror("create_host: bind failed");
exit(1);
}
if ( listen(host, 5) < 0 )
{
perror("create_host: listen failed");
exit(1);
}
sprintf(s, "Host socket listening on port %d, file descriptor %d.\n", a1, (unsigned int)host);
log(a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, double a2)
{
socklen_t v2; // edx
int v3; // er8
struct sockaddr v5; // [rsp+0h] [rbp-118h] BYREF
char s[264]; // [rsp+10h] [rbp-108h] BYREF

host = socket(2, 1, 0);
if ( host < 0 )
{
perror("create_host: failed to create host socket");
exit(1);
}
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func0(a1);
*(_DWORD *)&v5.sa_data[2] = _bswap_32(0LL, (const char *)&v5);
if ( bind(v3, &v5, v2) < 0 )
{
perror("create_host: bind failed");
exit(1);
}
if ( listen(host, 5) < 0 )
{
perror("create_host: listen failed");
exit(1);
}
sprintf(s, "Host socket listening on port %d, file descriptor %d.\n", a1, (unsigned int)host);
log(a2);
return 1LL;
}

original_code:
int create_host(int port) {
 char buf[256];
 struct sockaddr_in sa;
 if((host = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("create_host: failed to create host socket");
  exit(1);
 }
 sa.sin_family = 2;
 sa.sin_port = htons(port);
 sa.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 if(bind(host, (struct sockaddr*)&sa, sizeof(sa)) < 0) {
  perror("create_host: bind failed");
  exit(1);
 }
 if(listen(host, 5) < 0) {
  perror("create_host: listen failed");
  exit(1);
 }
 sprintf(buf,"Host socket listening on port %d, file descriptor %d.\n",port,host);
 log(buf);
 return 1;
}

canonical_original_code:
int create_host(int port) {
 char buf[256];
 struct sockaddr_in sa;
 if((host = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("create_host: failed to create host socket");
  exit(1);
 }
 sa.sin_family = 2;
 sa.sin_port = htons(port);
 sa.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 if(bind(host, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
  perror("create_host: bind failed");
  exit(1);
 }
 if(listen(host, 5) < 0) {
  perror("create_host: listen failed");
  exit(1);
 }
 sprintf(buf,"Host socket listening on port %d, file descriptor %d.\n",port,host);
 log(buf);
 return 1;
}

variable_types:
buf
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]; }