decompiled_code:
int __fastcall elfu_mDumpElf(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi
_QWORD *i; // rbx
__int64 v4; // r15
__int64 v5; // r13
__int64 v6; // r12
const char *v7; // rax
__int64 v9[8]; // [rsp+8h] [rbp-40h] BYREF

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/dump.c", 0xDDu, "elfu_mDumpElf");
elfu_mDumpEhdr(a1);
fputc(10, stdout);
fwrite("Segments:\n", 1uLL, 0xAuLL, stdout);
fwrite(
" # (type) p_type p_offset p_vaddr p_paddr p_filesz p_memsz p_flags p_align\n",
1uLL,
0x5DuLL,
stdout);
fwrite(
" | | | | | | | | | \n",
1uLL,
0x5DuLL,
stdout);
v1 = *(_QWORD *)(a1 + 72);
v2 = 0LL;
for ( v9[0] = 0LL; v1 != a1 + 72; ++v9[0] )
{
printf(" [%4d] ", v2);
elfu_mDumpPhdr(a1, v1);
v1 = *(_QWORD *)(v1 + 104);
v2 = v9[0] + 1;
}
fputc(10, stdout);
fwrite("Orphaned sections:\n", 1uLL, 0x13uLL, stdout);
for ( i = *(_QWORD **)(a1 + 88); i != (_QWORD *)(a1 + 88); i = (_QWORD *)i[16] )
{
v4 = i[4];
v5 = i[3];
v6 = i[2];
v7 = (const char *)elfu_mScnName(a1, i);
fprintf(
stdout,
" * %-17s @ %8x offset %8x size %8x\n",
v7,
(unsigned int)v6,
(unsigned int)v5,
(unsigned int)v4);
}
fputc(10, stdout);
fwrite("Sections:\n", 1uLL, 0xAuLL, stdout);
fwrite(
" # Name sh_type sh_addr sh_offset sh_size ES Fl Al sh_link sh_info \n",
1uLL,
0x73uLL,
stdout);
fwrite(
" | | | | | | | | | | \n",
1uLL,
0x73uLL,
stdout);
elfu_mScnForall(a1, subScnDump, v9, 0LL);
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi
_QWORD *i; // rbx
__int64 v4; // r15
__int64 v5; // r13
__int64 v6; // r12
const char *v7; // rax
__int64 v9[8]; // [rsp+8h] [rbp-40h] BYREF

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/dump.c", 0xDDu, "elfu_mDumpElf");
func5(a1);
fputc(10, stdout);
fwrite("Segments:\n", 1uLL, 0xAuLL, stdout);
fwrite(
" # (type) p_type p_offset p_vaddr p_paddr p_filesz p_memsz p_flags p_align\n",
1uLL,
0x5DuLL,
stdout);
fwrite(
" | | | | | | | | | \n",
1uLL,
0x5DuLL,
stdout);
v1 = *(_QWORD *)(a1 + 72);
v2 = 0LL;
for ( v9[0] = 0LL; v1 != a1 + 72; ++v9[0] )
{
printf(" [%4d] ", v2);
func2(a1, v1);
v1 = *(_QWORD *)(v1 + 104);
v2 = v9[0] + 1;
}
fputc(10, stdout);
fwrite("Orphaned sections:\n", 1uLL, 0x13uLL, stdout);
for ( i = *(_QWORD **)(a1 + 88); i != (_QWORD *)(a1 + 88); i = (_QWORD *)i[16] )
{
v4 = i[4];
v5 = i[3];
v6 = i[2];
v7 = (const char *)elfu_mScnName(a1, i);
fprintf(
stdout,
" * %-17s @ %8x offset %8x size %8x\n",
v7,
(unsigned int)v6,
(unsigned int)v5,
(unsigned int)v4);
}
fputc(10, stdout);
fwrite("Sections:\n", 1uLL, 0xAuLL, stdout);
fwrite(
" # Name sh_type sh_addr sh_offset sh_size ES Fl Al sh_link sh_info \n",
1uLL,
0x73uLL,
stdout);
fwrite(
" | | | | | | | | | | \n",
1uLL,
0x73uLL,
stdout);
elfu_mScnForall(a1, subScnDump, v9, 0LL);
return fputc(10, stdout);
}

original_code:
void elfu_mDumpElf(ElfuElf *me)
{
  ElfuPhdr *mp;
  ElfuScn *ms;
  size_t i;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/dump.c", 221, __extension__ __PRETTY_FUNCTION__); }));
  elfu_mDumpEhdr(me);
  do { fprintf(stdout, "\n"); } while(0);
  do { fprintf(stdout, "Segments:\n"); } while(0);
  do { fprintf(stdout, "     #        (type)   p_type p_offset  p_vaddr  p_paddr p_filesz  p_memsz  p_flags  p_align\n"); } while(0);
  do { fprintf(stdout, "       |            |        |        |        |        |        |        |        |        \n"); } while(0);
  i = 0;
  for ((mp) = ((&me->phdrList)->cqh_first); (mp) != (const void *)(&me->phdrList); (mp) = ((mp)->elem.cqe_next)) {
    printf(" [%4d] ", i);
    elfu_mDumpPhdr(me, mp);
    i++;
  }
  do { fprintf(stdout, "\n"); } while(0);
  do { fprintf(stdout, "Orphaned sections:\n"); } while(0);
  for ((ms) = ((&me->orphanScnList)->cqh_first); (ms) != (const void *)(&me->orphanScnList); (ms) = ((ms)->elemChildScn.cqe_next)) {
    do { fprintf(stdout, "        * %-17s @ %8x  offset %8x  size %8x\n", elfu_mScnName(me, ms), (unsigned)ms->shdr.sh_addr, (unsigned)ms->shdr.sh_offset, (unsigned)ms->shdr.sh_size); } while(0);
  }
  do { fprintf(stdout, "\n"); } while(0);
  do { fprintf(stdout, "Sections:\n"); } while(0);
  do { fprintf(stdout, "     #  Name              sh_type          sh_addr sh_offset  sh_size ES Fl Al sh_link           sh_info          \n"); } while(0);
  do { fprintf(stdout, "       |                 |               |        |         |        |  |  |  |                 |                 \n"); } while(0);
  elfu_mScnForall(me, subScnDump, &i, ((void *)0));
  do { fprintf(stdout, "\n"); } while(0);
}

canonical_original_code:
void elfu_mDumpElf(struct ElfuElf *me)
{
  struct ElfuPhdr *mp;
  struct ElfuScn *ms;
  unsigned long i;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/dump.c", 221, __extension__ __PRETTY_FUNCTION__); }));
  elfu_mDumpEhdr(me);
  do { fprintf(stdout, "\n"); } while(0);
  do { fprintf(stdout, "Segments:\n"); } while(0);
  do { fprintf(stdout, "     #        (type)   p_type p_offset  p_vaddr  p_paddr p_filesz  p_memsz  p_flags  p_align\n"); } while(0);
  do { fprintf(stdout, "       |            |        |        |        |        |        |        |        |        \n"); } while(0);
  i = 0;
  for ((mp) = ((&me->phdrList)->cqh_first); (mp) != (void *)(&me->phdrList); (mp) = ((mp)->elem.cqe_next)) {
    printf(" [%4d] ", i);
    elfu_mDumpPhdr(me, mp);
    i++;
  }
  do { fprintf(stdout, "\n"); } while(0);
  do { fprintf(stdout, "Orphaned sections:\n"); } while(0);
  for ((ms) = ((&me->orphanScnList)->cqh_first); (ms) != (void *)(&me->orphanScnList); (ms) = ((ms)->elemChildScn.cqe_next)) {
    do { fprintf(stdout, "        * %-17s @ %8x  offset %8x  size %8x\n", elfu_mScnName(me, ms), (unsigned int)ms->shdr.sh_addr, (unsigned int)ms->shdr.sh_offset, (unsigned int)ms->shdr.sh_size); } while(0);
  }
  do { fprintf(stdout, "\n"); } while(0);
  do { fprintf(stdout, "Sections:\n"); } while(0);
  do { fprintf(stdout, "     #  Name              sh_type          sh_addr sh_offset  sh_size ES Fl Al sh_link           sh_info          \n"); } while(0);
  do { fprintf(stdout, "       |                 |               |        |         |        |  |  |  |                 |                 \n"); } while(0);
  elfu_mScnForall(me, subScnDump, &i, ((void *)0));
  do { fprintf(stdout, "\n"); } while(0);
}

variable_types: struct ElfuPhdr { 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; } phdr; struct ChildScnList { struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } *cqh_first; struct ElfuScn *cqh_last; } childScnList; struct ChildPhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; } childPhdrList; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elemChildPhdr; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elem; } *

variable_types:
i
unsigned long


cmpPhdrType

repo: norly/centaur

decompiled_code:
__int64 __fastcall cmpPhdrType(const void *a1, const void *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // ecx
unsigned __int64 v5; // rcx

v2 = *(_DWORD *)a1;
result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 != 6 )
{
v4 = *(_DWORD *)a2;
result = 1LL;
if ( *(_DWORD *)a2 != 6 )
{
result = 0xFFFFFFFFLL;
if ( v2 != 3 )
{
if ( v4 == 3 || v2 == 1685382482 )
{
result = 1LL;
}
else if ( v4 != 1685382482 )
{
result = 1LL;
if ( v2 != 1685382481 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 1685382481 )
{
result = 1LL;
if ( v2 != 1685382480 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 1685382480 )
{
result = 1LL;
if ( v2 != 4 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 4 )
{
result = 1LL;
if ( v2 != 2 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 2 )
{
v5 = *((_QWORD *)a2 + 2);
if ( *((_QWORD *)a1 + 2) >= v5 )
result = *((_QWORD *)a1 + 2) > v5;
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // ecx
unsigned __int64 v5; // rcx

v2 = *(_DWORD *)a1;
result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 != 6 )
{
v4 = *(_DWORD *)a2;
result = 1LL;
if ( *(_DWORD *)a2 != 6 )
{
result = 0xFFFFFFFFLL;
if ( v2 != 3 )
{
if ( v4 == 3 || v2 == 1685382482 )
{
result = 1LL;
}
else if ( v4 != 1685382482 )
{
result = 1LL;
if ( v2 != 1685382481 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 1685382481 )
{
result = 1LL;
if ( v2 != 1685382480 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 1685382480 )
{
result = 1LL;
if ( v2 != 4 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 4 )
{
result = 1LL;
if ( v2 != 2 )
{
result = 0xFFFFFFFFLL;
if ( v4 != 2 )
{
v5 = *((_QWORD *)a2 + 2);
if ( *((_QWORD *)a1 + 2) >= v5 )
result = *((_QWORD *)a1 + 2) > v5;
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
static int cmpPhdrType(const void *v1, const void *v2)
{
  const GElf_Phdr *p1 = (const GElf_Phdr*)v1;
  const GElf_Phdr *p2 = (const GElf_Phdr*)v2;
  if (p1->p_type == 6) {
    return -1;
  } else if (p2->p_type == 6) {
    return 1;
  } else if (p1->p_type == 3) {
    return -1;
  } else if (p2->p_type == 3) {
    return 1;
  }
  if (p1->p_type == 0x6474e552) {
    return 1;
  } else if (p2->p_type == 0x6474e552) {
    return -1;
  } else if (p1->p_type == 0x6474e551) {
    return 1;
  } else if (p2->p_type == 0x6474e551) {
    return -1;
  } else if (p1->p_type == 0x6474e550) {
    return 1;
  } else if (p2->p_type == 0x6474e550) {
    return -1;
  } else if (p1->p_type == 4) {
    return 1;
  } else if (p2->p_type == 4) {
    return -1;
  } else if (p1->p_type == 2) {
    return 1;
  } else if (p2->p_type == 2) {
    return -1;
  }
  if (p1->p_vaddr < p2->p_vaddr) {
    return -1;
  } else if (p1->p_vaddr > p2->p_vaddr) {
    return 1;
  }
  return 0;
}

canonical_original_code:
static int cmpPhdrType(void *v1, void *v2)
{
  struct Elf64_Phdr *p1 = (const GElf_Phdr*)v1;
  struct Elf64_Phdr *p2 = (const GElf_Phdr*)v2;
  if (p1->p_type == 6) {
    return -1;
  } else if (p2->p_type == 6) {
    return 1;
  } else if (p1->p_type == 3) {
    return -1;
  } else if (p2->p_type == 3) {
    return 1;
  }
  if (p1->p_type == 0x6474e552) {
    return 1;
  } else if (p2->p_type == 0x6474e552) {
    return -1;
  } else if (p1->p_type == 0x6474e551) {
    return 1;
  } else if (p2->p_type == 0x6474e551) {
    return -1;
  } else if (p1->p_type == 0x6474e550) {
    return 1;
  } else if (p2->p_type == 0x6474e550) {
    return -1;
  } else if (p1->p_type == 4) {
    return 1;
  } else if (p2->p_type == 4) {
    return -1;
  } else if (p1->p_type == 2) {
    return 1;
  } else if (p2->p_type == 2) {
    return -1;
  }
  if (p1->p_vaddr < p2->p_vaddr) {
    return -1;
  } else if (p1->p_vaddr > p2->p_vaddr) {
    return 1;
  }
  return 0;
}

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

return_type: int


decompiled_code:
__int64 __fastcall elfu_mPhdrForall(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64, __int64, __int64), __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 i; // r15
__int64 v8; // [rsp+0h] [rbp-48h]

v8 = *(_QWORD *)(a1 + 72);
if ( v8 == a1 + 72 )
return 0LL;
while ( 1 )
{
result = a2(a1, v8, a3, a4);
if ( result )
return result;
for ( i = *(_QWORD *)(v8 + 72); i != v8 + 72; i = *(_QWORD *)(i + 88) )
{
result = a2(a1, i, a3, a4);
if ( result )
return result;
}
v8 = *(_QWORD *)(v8 + 104);
if ( a1 + 72 == v8 )
return 0LL;
}
}

original_code:
void* elfu_mPhdrForall(ElfuElf *me, PhdrHandlerFunc f, void *aux1, void *aux2)
{
  ElfuPhdr *mp;
  for ((mp) = ((&me->phdrList)->cqh_first); (mp) != (const void *)(&me->phdrList); (mp) = ((mp)->elem.cqe_next)) {
    ElfuPhdr *mp2;
    void *rv = f(me, mp, aux1, aux2);
    if (rv) {
      return rv;
    }
    for ((mp2) = ((&mp->childPhdrList)->cqh_first); (mp2) != (const void *)(&mp->childPhdrList); (mp2) = ((mp2)->elemChildPhdr.cqe_next)) {
      void *rv = f(me, mp2, aux1, aux2);
      if (rv) {
        return rv;
      }
    }
  }
  return ((void *)0);
}

canonical_original_code:
void *elfu_mPhdrForall(struct ElfuElf *me, void *f(struct ElfuElf *me, struct ElfuPhdr *mp, void *aux1, void *aux2), void *aux1, void *aux2)
{
  struct ElfuPhdr *mp;
  for ((mp) = ((&me->phdrList)->cqh_first); (mp) != (void *)(&me->phdrList); (mp) = ((mp)->elem.cqe_next)) {
    struct ElfuPhdr *mp2;
    void *rv = f(me, mp, aux1, aux2);
    if (rv) {
      return rv;
    }
    for ((mp2) = ((&mp->childPhdrList)->cqh_first); (mp2) != (void *)(&mp->childPhdrList); (mp2) = ((mp2)->elemChildPhdr.cqe_next)) {
      void *rv = f(me, mp2, aux1, aux2);
      if (rv) {
        return rv;
      }
    }
  }
  return ((void *)0);
}

variable_types: struct ElfuElf { int elfclass; 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; } ehdr; struct PhdrList { struct ElfuPhdr { 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; } phdr; struct ChildScnList { struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } *cqh_first; struct ElfuScn *cqh_last; } childScnList; struct ChildPhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; } childPhdrList; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elemChildPhdr; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elem; } *cqh_first; struct ElfuPhdr *cqh_last; } phdrList; struct OrphanScnList { struct ElfuScn *cqh_first; struct ElfuScn *cqh_last; } orphanScnList; struct ElfuScn *shstrtab; struct ElfuScn *symtab; } *

variable_types: void *(struct ElfuElf *me, struct ElfuPhdr *mp, void *aux1, void *aux2)

variable_types:
rv
void *

return_type: void *

user_defined_types: struct ElfuElf { int elfclass; struct Elf64_Ehdr ehdr; struct PhdrList phdrList; struct OrphanScnList orphanScnList; struct ElfuScn *shstrtab; struct ElfuScn *symtab; }

user_defined_types: struct ElfuPhdr { struct Elf64_Phdr phdr; struct ChildScnList childScnList; struct ChildPhdrList childPhdrList; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elemChildPhdr; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elem; }

user_defined_types: struct PhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; }

user_defined_types: struct ChildScnList { struct ElfuScn *cqh_first; struct ElfuScn *cqh_last; }

user_defined_types: struct ElfuScn { struct Elf64_Shdr shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab symtab; struct ElfuReltab reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; }

user_defined_types: struct Syms { struct ElfuSym *cqh_first; struct ElfuSym *cqh_last; }

user_defined_types: struct Rels { struct ElfuRel *cqh_first; struct ElfuRel *cqh_last; }


decompiled_code:
__int64 __fastcall elfu_mPhdrCount(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( !a1 )
_assert_fail("me", "src/libelfu/model/phdr.c", 0x42u, "elfu_mPhdrCount");
elfu_mPhdrForall(a1, (__int64 (__fastcall *)(__int64, __int64, __int64, __int64))subCounter, (__int64)&v2, 0LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( !a1 )
_assert_fail("me", "src/libelfu/model/phdr.c", 0x42u, "elfu_mPhdrCount");
func3(a1, (__int64 (__fastcall *)(__int64, __int64, __int64, __int64))subCounter, (__int64)&v2, 0LL);
return v2;
}

original_code:
size_t elfu_mPhdrCount(ElfuElf *me)
{
  size_t i = 0;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/model/phdr.c", 66, __extension__ __PRETTY_FUNCTION__); }));
  elfu_mPhdrForall(me, subCounter, &i, ((void *)0));
  return i;
}

canonical_original_code:
unsigned long elfu_mPhdrCount(struct ElfuElf *me)
{
  unsigned long i = 0;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/model/phdr.c", 66, __extension__ __PRETTY_FUNCTION__); }));
  elfu_mPhdrForall(me, subCounter, &i, ((void *)0));
  return i;
}

return_type: unsigned long

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

user_defined_types: struct OrphanScnList { struct ElfuScn *cqh_first; struct ElfuScn *cqh_last; }

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

user_defined_types: struct ChildPhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; }

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 ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; }

user_defined_types: struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; }


decompiled_code:
__int64 __fastcall elfu_mPhdrByAddr(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return elfu_mPhdrForall(
a1,
(__int64 (__fastcall *)(__int64, __int64, __int64, __int64))subFindLoadByAddr,
(__int64)&v3,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return func3(
a1,
(__int64 (__fastcall *)(__int64, __int64, __int64, __int64))subFindLoadByAddr,
(__int64)&v3,
0LL);
}

original_code:
ElfuPhdr* elfu_mPhdrByAddr(ElfuElf *me, GElf_Addr addr)
{
  return elfu_mPhdrForall(me, subFindLoadByAddr, &addr, ((void *)0));
}

canonical_original_code:
struct ElfuPhdr *elfu_mPhdrByAddr(struct ElfuElf *me, unsigned long addr)
{
  return elfu_mPhdrForall(me, subFindLoadByAddr, &addr, ((void *)0));
}

variable_types: struct ElfuElf { int elfclass; 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; } ehdr; struct PhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; } phdrList; struct OrphanScnList { struct ElfuScn *cqh_first; struct ElfuScn *cqh_last; } orphanScnList; struct ElfuScn *shstrtab; struct ElfuScn *symtab; } *

variable_types:
addr
unsigned long

return_type: struct ElfuPhdr { 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; } phdr; struct ChildScnList { struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } *cqh_first; struct ElfuScn *cqh_last; } childScnList; struct ChildPhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; } childPhdrList; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elemChildPhdr; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elem; } *


decompiled_code:
__int64 __fastcall elfu_mPhdrByOffset(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return elfu_mPhdrForall(
a1,
(__int64 (__fastcall *)(__int64, __int64, __int64, __int64))subFindLoadByOffset,
(__int64)&v3,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return func3(
a1,
(__int64 (__fastcall *)(__int64, __int64, __int64, __int64))subFindLoadByOffset,
(__int64)&v3,
0LL);
}

original_code:
ElfuPhdr* elfu_mPhdrByOffset(ElfuElf *me, GElf_Off offset)
{
  return elfu_mPhdrForall(me, subFindLoadByOffset, &offset, ((void *)0));
}

canonical_original_code:
struct ElfuPhdr *elfu_mPhdrByOffset(struct ElfuElf *me, unsigned long offset)
{
  return elfu_mPhdrForall(me, subFindLoadByOffset, &offset, ((void *)0));
}

variable_types:
offset
unsigned long


decompiled_code:
_QWORD *elfu_mPhdrAlloc()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
char *v2; // rax

v0 = calloc(0x78uLL, 1uLL);
v1 = v0;
if ( v0 )
{
v2 = (char *)(v0 + 7);
v1[7] = v2;
v1[8] = v2;
v1[9] = v1 + 9;
v1[10] = v1 + 9;
}
else
{
fwrite("mPhdrAlloc: malloc() failed for ElfuPhdr.\n", 1uLL, 0x2AuLL, stderr);
}
return v1;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
char *v2; // rax

v0 = calloc(0x78uLL, 1uLL);
v1 = v0;
if ( v0 )
{
v2 = (char *)(v0 + 7);
v1[7] = v2;
v1[8] = v2;
v1[9] = v1 + 9;
v1[10] = v1 + 9;
}
else
{
fwrite("mPhdrAlloc: malloc() failed for ElfuPhdr.\n", 1uLL, 0x2AuLL, stderr);
}
return v1;
}

original_code:
ElfuPhdr* elfu_mPhdrAlloc()
{
  ElfuPhdr *mp;
  mp = malloc(sizeof(ElfuPhdr));
  if (!mp) {
    do { fprintf(stderr, "mPhdrAlloc: malloc() failed for ElfuPhdr.\n"); } while(0);
    return ((void *)0);
  }
  memset(mp, 0, sizeof(*mp));
  do { (&mp->childScnList)->cqh_first = (void *)(&mp->childScnList); (&mp->childScnList)->cqh_last = (void *)(&mp->childScnList); } while ( 0);
  do { (&mp->childPhdrList)->cqh_first = (void *)(&mp->childPhdrList); (&mp->childPhdrList)->cqh_last = (void *)(&mp->childPhdrList); } while ( 0);
  return mp;
}

canonical_original_code:
struct ElfuPhdr *elfu_mPhdrAlloc()
{
  struct ElfuPhdr *mp;
  mp = malloc(sizeof(ElfuPhdr));
  if (!mp) {
    do { fprintf(stderr, "mPhdrAlloc: malloc() failed for ElfuPhdr.\n"); } while(0);
    return ((void *)0);
  }
  memset(mp, 0, sizeof(*mp));
  do { (&mp->childScnList)->cqh_first = (void *)(&mp->childScnList); (&mp->childScnList)->cqh_last = (void *)(&mp->childScnList); } while ( 0);
  do { (&mp->childPhdrList)->cqh_first = (void *)(&mp->childPhdrList); (&mp->childPhdrList)->cqh_last = (void *)(&mp->childPhdrList); } while ( 0);
  return mp;
}


decompiled_code:
void __fastcall elfu_mPhdrDestroy(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
_QWORD *v4; // rdi
_QWORD *v5; // rax
_QWORD *v6; // rbx
_QWORD *v7; // rbp
_QWORD *v8; // rdi
_QWORD *v9; // rax

if ( !a1 )
_assert_fail("mp", "src/libelfu/model/phdr.c", 0xD4u, "elfu_mPhdrDestroy");
v1 = (_QWORD *)a1[9];
v2 = a1 + 9;
while ( v2 != v1 )
{
v4 = v1;
v1 = (_QWORD *)v1[11];
v5 = (_QWORD *)v4[12];
if ( v2 == v1 )
a1[10] = v5;
else
v1[12] = v5;
if ( v2 == v5 )
a1[9] = v1;
else
v5[11] = v1;
elfu_mPhdrDestroy();
}
v6 = (_QWORD *)a1[7];
v7 = a1 + 7;
if ( v6 != a1 + 7 )
{
while ( 1 )
{
v8 = v6;
v6 = (_QWORD *)v6[16];
v9 = (_QWORD *)v8[17];
if ( v7 == v6 )
{
a1[8] = v9;
if ( v7 == v9 )
goto LABEL_14;
LABEL_11:
v9[16] = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
else
{
v6[17] = v9;
if ( v7 != v9 )
goto LABEL_11;
LABEL_14:
a1[7] = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
}
}
free(a1);
}

canonical_decompiled_code:
void __fastcall func8(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
_QWORD *v4; // rdi
_QWORD *v5; // rax
_QWORD *v6; // rbx
_QWORD *v7; // rbp
_QWORD *v8; // rdi
_QWORD *v9; // rax

if ( !a1 )
_assert_fail("mp", "src/libelfu/model/phdr.c", 0xD4u, "elfu_mPhdrDestroy");
v1 = (_QWORD *)a1[9];
v2 = a1 + 9;
while ( v2 != v1 )
{
v4 = v1;
v1 = (_QWORD *)v1[11];
v5 = (_QWORD *)v4[12];
if ( v2 == v1 )
a1[10] = v5;
else
v1[12] = v5;
if ( v2 == v5 )
a1[9] = v1;
else
v5[11] = v1;
func8();
}
v6 = (_QWORD *)a1[7];
v7 = a1 + 7;
if ( v6 != a1 + 7 )
{
while ( 1 )
{
v8 = v6;
v6 = (_QWORD *)v6[16];
v9 = (_QWORD *)v8[17];
if ( v7 == v6 )
{
a1[8] = v9;
if ( v7 == v9 )
goto LABEL_14;
LABEL_11:
v9[16] = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
else
{
v6[17] = v9;
if ( v7 != v9 )
goto LABEL_11;
LABEL_14:
a1[7] = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
}
}
free(a1);
}

original_code:
void elfu_mPhdrDestroy(ElfuPhdr* mp)
{
  ((void) sizeof ((mp) ? 1 : 0), __extension__ ({ if (mp) ; else __assert_fail ("mp", "src/libelfu/model/phdr.c", 212, __extension__ __PRETTY_FUNCTION__); }));
  if (!((&mp->childPhdrList)->cqh_first == (void *)(&mp->childPhdrList))) {
    ElfuPhdr *nextmp;
    nextmp = ((&mp->childPhdrList)->cqh_first);
    while ((void*)nextmp != (void*)&mp->childPhdrList) {
      ElfuPhdr *curmp = nextmp;
      nextmp = ((curmp)->elemChildPhdr.cqe_next);
      do { if ((curmp)->elemChildPhdr.cqe_next == (void *)(&mp->childPhdrList)) (&mp->childPhdrList)->cqh_last = (curmp)->elemChildPhdr.cqe_prev; else (curmp)->elemChildPhdr.cqe_next->elemChildPhdr.cqe_prev = (curmp)->elemChildPhdr.cqe_prev; if ((curmp)->elemChildPhdr.cqe_prev == (void *)(&mp->childPhdrList)) (&mp->childPhdrList)->cqh_first = (curmp)->elemChildPhdr.cqe_next; else (curmp)->elemChildPhdr.cqe_prev->elemChildPhdr.cqe_next = (curmp)->elemChildPhdr.cqe_next; } while ( 0);
      elfu_mPhdrDestroy(curmp);
    }
  }
  if (!((&mp->childScnList)->cqh_first == (void *)(&mp->childScnList))) {
    ElfuScn *nextms;
    nextms = ((&mp->childScnList)->cqh_first);
    while ((void*)nextms != (void*)&mp->childScnList) {
      ElfuScn *curms = nextms;
      nextms = ((curms)->elemChildScn.cqe_next);
      do { if ((curms)->elemChildScn.cqe_next == (void *)(&mp->childScnList)) (&mp->childScnList)->cqh_last = (curms)->elemChildScn.cqe_prev; else (curms)->elemChildScn.cqe_next->elemChildScn.cqe_prev = (curms)->elemChildScn.cqe_prev; if ((curms)->elemChildScn.cqe_prev == (void *)(&mp->childScnList)) (&mp->childScnList)->cqh_first = (curms)->elemChildScn.cqe_next; else (curms)->elemChildScn.cqe_prev->elemChildScn.cqe_next = (curms)->elemChildScn.cqe_next; } while ( 0);
      elfu_mScnDestroy(curms);
    }
  }
  free(mp);
}

canonical_original_code:
void elfu_mPhdrDestroy(struct ElfuPhdr *mp)
{
  ((void) sizeof ((mp) ? 1 : 0), __extension__ ({ if (mp) ; else __assert_fail ("mp", "src/libelfu/model/phdr.c", 212, __extension__ __PRETTY_FUNCTION__); }));
  if (!((&mp->childPhdrList)->cqh_first == (void *)(&mp->childPhdrList))) {
    struct ElfuPhdr *nextmp;
    nextmp = ((&mp->childPhdrList)->cqh_first);
    while ((void *)nextmp != (void *)&mp->childPhdrList) {
      struct ElfuPhdr *curmp = nextmp;
      nextmp = ((curmp)->elemChildPhdr.cqe_next);
      do { if ((curmp)->elemChildPhdr.cqe_next == (void *)(&mp->childPhdrList)) (&mp->childPhdrList)->cqh_last = (curmp)->elemChildPhdr.cqe_prev; else (curmp)->elemChildPhdr.cqe_next->elemChildPhdr.cqe_prev = (curmp)->elemChildPhdr.cqe_prev; if ((curmp)->elemChildPhdr.cqe_prev == (void *)(&mp->childPhdrList)) (&mp->childPhdrList)->cqh_first = (curmp)->elemChildPhdr.cqe_next; else (curmp)->elemChildPhdr.cqe_prev->elemChildPhdr.cqe_next = (curmp)->elemChildPhdr.cqe_next; } while ( 0);
      elfu_mPhdrDestroy(curmp);
    }
  }
  if (!((&mp->childScnList)->cqh_first == (void *)(&mp->childScnList))) {
    struct ElfuScn *nextms;
    nextms = ((&mp->childScnList)->cqh_first);
    while ((void *)nextms != (void *)&mp->childScnList) {
      struct ElfuScn *curms = nextms;
      nextms = ((curms)->elemChildScn.cqe_next);
      do { if ((curms)->elemChildScn.cqe_next == (void *)(&mp->childScnList)) (&mp->childScnList)->cqh_last = (curms)->elemChildScn.cqe_prev; else (curms)->elemChildScn.cqe_next->elemChildScn.cqe_prev = (curms)->elemChildScn.cqe_prev; if ((curms)->elemChildScn.cqe_prev == (void *)(&mp->childScnList)) (&mp->childScnList)->cqh_first = (curms)->elemChildScn.cqe_next; else (curms)->elemChildScn.cqe_prev->elemChildScn.cqe_next = (curms)->elemChildScn.cqe_next; } while ( 0);
      elfu_mScnDestroy(curms);
    }
  }
  free(mp);
}

variable_types: struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } *

return_type: void


subCounter

decompiled_code:
__int64 __fastcall subCounter(__int64 a1, __int64 a2, _QWORD *a3)
{
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3)
{
++*a3;
return 0LL;
}

original_code:
static void* subCounter(ElfuElf *me, ElfuPhdr *mp, void *aux1, void *aux2)
{
  size_t *i = (size_t*)aux1;
  (void)aux2;
  *i += 1;
  return ((void *)0);
}

canonical_original_code:
static void *subCounter(struct ElfuElf *me, struct ElfuPhdr *mp, void *aux1, void *aux2)
{
  unsigned long *i = (size_t*)aux1;
  (void)aux2;
  *i += 1;
  return ((void *)0);
}

variable_types:
mp
struct ElfuPhdr *

variable_types:
i
unsigned long *


decompiled_code:
_QWORD *elfu_mElfAlloc()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
char *v2; // rax

v0 = calloc(0x78uLL, 1uLL);
v1 = v0;
if ( v0 )
{
v2 = (char *)(v0 + 9);
v1[9] = v2;
v1[10] = v2;
v1[11] = v1 + 11;
v1[12] = v1 + 11;
}
else
{
fwrite("mElfAlloc: malloc() failed for ElfuElf.\n", 1uLL, 0x28uLL, stderr);
}
return v1;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
char *v2; // rax

v0 = calloc(0x78uLL, 1uLL);
v1 = v0;
if ( v0 )
{
v2 = (char *)(v0 + 9);
v1[9] = v2;
v1[10] = v2;
v1[11] = v1 + 11;
v1[12] = v1 + 11;
}
else
{
fwrite("mElfAlloc: malloc() failed for ElfuElf.\n", 1uLL, 0x28uLL, stderr);
}
return v1;
}

original_code:
ElfuElf* elfu_mElfAlloc()
{
  ElfuElf *me;
  me = malloc(sizeof(ElfuElf));
  if (!me) {
    do { fprintf(stderr, "mElfAlloc: malloc() failed for ElfuElf.\n"); } while(0);
    return ((void *)0);
  }
  memset(me, 0, sizeof(*me));
  do { (&me->phdrList)->cqh_first = (void *)(&me->phdrList); (&me->phdrList)->cqh_last = (void *)(&me->phdrList); } while ( 0);
  do { (&me->orphanScnList)->cqh_first = (void *)(&me->orphanScnList); (&me->orphanScnList)->cqh_last = (void *)(&me->orphanScnList); } while ( 0);
  return me;
}

canonical_original_code:
struct ElfuElf *elfu_mElfAlloc()
{
  struct ElfuElf *me;
  me = malloc(sizeof(ElfuElf));
  if (!me) {
    do { fprintf(stderr, "mElfAlloc: malloc() failed for ElfuElf.\n"); } while(0);
    return ((void *)0);
  }
  memset(me, 0, sizeof(*me));
  do { (&me->phdrList)->cqh_first = (void *)(&me->phdrList); (&me->phdrList)->cqh_last = (void *)(&me->phdrList); } while ( 0);
  do { (&me->orphanScnList)->cqh_first = (void *)(&me->orphanScnList); (&me->orphanScnList)->cqh_last = (void *)(&me->orphanScnList); } while ( 0);
  return me;
}

return_type: struct ElfuElf { int elfclass; 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; } ehdr; struct PhdrList { struct ElfuPhdr { 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; } phdr; struct ChildScnList { struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } *cqh_first; struct ElfuScn *cqh_last; } childScnList; struct ChildPhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; } childPhdrList; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elemChildPhdr; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elem; } *cqh_first; struct ElfuPhdr *cqh_last; } phdrList; struct OrphanScnList { struct ElfuScn *cqh_first; struct ElfuScn *cqh_last; } orphanScnList; struct ElfuScn *shstrtab; struct ElfuScn *symtab; } *


decompiled_code:
void __fastcall elfu_mElfDestroy(void *ptr)
{
char *v1; // rbx
char *v2; // rbp
char *v4; // rdi
__int64 v5; // rax
char *v6; // rbx
char *v7; // rbp
char *v8; // rdi
__int64 v9; // rax

if ( !ptr )
_assert_fail("me", "src/libelfu/model/elf.c", 0x2Fu, "elfu_mElfDestroy");
v1 = (char *)*((_QWORD *)ptr + 9);
v2 = (char *)ptr + 72;
if ( v1 != (char *)ptr + 72 )
{
while ( 1 )
{
v4 = v1;
v1 = (char *)*((_QWORD *)v1 + 13);
v5 = *((_QWORD *)v4 + 14);
if ( v2 == v1 )
{
*((_QWORD *)ptr + 10) = v5;
if ( v2 == (char *)v5 )
goto LABEL_8;
LABEL_5:
*(_QWORD *)(v5 + 104) = v1;
elfu_mPhdrDestroy();
if ( v2 == v1 )
break;
}
else
{
*((_QWORD *)v1 + 14) = v5;
if ( v2 != (char *)v5 )
goto LABEL_5;
LABEL_8:
*((_QWORD *)ptr + 9) = v1;
elfu_mPhdrDestroy();
if ( v2 == v1 )
break;
}
}
}
v6 = (char *)*((_QWORD *)ptr + 11);
v7 = (char *)ptr + 88;
if ( v6 != (char *)ptr + 88 )
{
while ( 1 )
{
v8 = v6;
v6 = (char *)*((_QWORD *)v6 + 16);
v9 = *((_QWORD *)v8 + 17);
if ( v7 == v6 )
{
*((_QWORD *)ptr + 12) = v9;
if ( v7 == (char *)v9 )
goto LABEL_15;
LABEL_12:
*(_QWORD *)(v9 + 128) = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
else
{
*((_QWORD *)v6 + 17) = v9;
if ( v7 != (char *)v9 )
goto LABEL_12;
LABEL_15:
*((_QWORD *)ptr + 11) = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
char *v1; // rbx
char *v2; // rbp
char *v4; // rdi
__int64 v5; // rax
char *v6; // rbx
char *v7; // rbp
char *v8; // rdi
__int64 v9; // rax

if ( !ptr )
_assert_fail("me", "src/libelfu/model/elf.c", 0x2Fu, "elfu_mElfDestroy");
v1 = (char *)*((_QWORD *)ptr + 9);
v2 = (char *)ptr + 72;
if ( v1 != (char *)ptr + 72 )
{
while ( 1 )
{
v4 = v1;
v1 = (char *)*((_QWORD *)v1 + 13);
v5 = *((_QWORD *)v4 + 14);
if ( v2 == v1 )
{
*((_QWORD *)ptr + 10) = v5;
if ( v2 == (char *)v5 )
goto LABEL_8;
LABEL_5:
*(_QWORD *)(v5 + 104) = v1;
elfu_mPhdrDestroy();
if ( v2 == v1 )
break;
}
else
{
*((_QWORD *)v1 + 14) = v5;
if ( v2 != (char *)v5 )
goto LABEL_5;
LABEL_8:
*((_QWORD *)ptr + 9) = v1;
elfu_mPhdrDestroy();
if ( v2 == v1 )
break;
}
}
}
v6 = (char *)*((_QWORD *)ptr + 11);
v7 = (char *)ptr + 88;
if ( v6 != (char *)ptr + 88 )
{
while ( 1 )
{
v8 = v6;
v6 = (char *)*((_QWORD *)v6 + 16);
v9 = *((_QWORD *)v8 + 17);
if ( v7 == v6 )
{
*((_QWORD *)ptr + 12) = v9;
if ( v7 == (char *)v9 )
goto LABEL_15;
LABEL_12:
*(_QWORD *)(v9 + 128) = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
else
{
*((_QWORD *)v6 + 17) = v9;
if ( v7 != (char *)v9 )
goto LABEL_12;
LABEL_15:
*((_QWORD *)ptr + 11) = v6;
elfu_mScnDestroy();
if ( v7 == v6 )
break;
}
}
}
free(ptr);
}

original_code:
void elfu_mElfDestroy(ElfuElf* me)
{
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/model/elf.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  if (!((&me->phdrList)->cqh_first == (void *)(&me->phdrList))) {
    ElfuPhdr *nextmp;
    nextmp = ((&me->phdrList)->cqh_first);
    while ((void*)nextmp != (void*)&me->phdrList) {
      ElfuPhdr *curmp = nextmp;
      nextmp = ((curmp)->elem.cqe_next);
      do { if ((curmp)->elem.cqe_next == (void *)(&me->phdrList)) (&me->phdrList)->cqh_last = (curmp)->elem.cqe_prev; else (curmp)->elem.cqe_next->elem.cqe_prev = (curmp)->elem.cqe_prev; if ((curmp)->elem.cqe_prev == (void *)(&me->phdrList)) (&me->phdrList)->cqh_first = (curmp)->elem.cqe_next; else (curmp)->elem.cqe_prev->elem.cqe_next = (curmp)->elem.cqe_next; } while ( 0);
      elfu_mPhdrDestroy(curmp);
    }
  }
  if (!((&me->orphanScnList)->cqh_first == (void *)(&me->orphanScnList))) {
    ElfuScn *nextms;
    nextms = ((&me->orphanScnList)->cqh_first);
    while ((void*)nextms != (void*)&me->orphanScnList) {
      ElfuScn *curms = nextms;
      nextms = ((curms)->elemChildScn.cqe_next);
      do { if ((curms)->elemChildScn.cqe_next == (void *)(&me->orphanScnList)) (&me->orphanScnList)->cqh_last = (curms)->elemChildScn.cqe_prev; else (curms)->elemChildScn.cqe_next->elemChildScn.cqe_prev = (curms)->elemChildScn.cqe_prev; if ((curms)->elemChildScn.cqe_prev == (void *)(&me->orphanScnList)) (&me->orphanScnList)->cqh_first = (curms)->elemChildScn.cqe_next; else (curms)->elemChildScn.cqe_prev->elemChildScn.cqe_next = (curms)->elemChildScn.cqe_next; } while ( 0);
      elfu_mScnDestroy(curms);
    }
  }
  free(me);
}

canonical_original_code:
void elfu_mElfDestroy(struct ElfuElf *me)
{
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/model/elf.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  if (!((&me->phdrList)->cqh_first == (void *)(&me->phdrList))) {
    struct ElfuPhdr *nextmp;
    nextmp = ((&me->phdrList)->cqh_first);
    while ((void *)nextmp != (void *)&me->phdrList) {
      struct ElfuPhdr *curmp = nextmp;
      nextmp = ((curmp)->elem.cqe_next);
      do { if ((curmp)->elem.cqe_next == (void *)(&me->phdrList)) (&me->phdrList)->cqh_last = (curmp)->elem.cqe_prev; else (curmp)->elem.cqe_next->elem.cqe_prev = (curmp)->elem.cqe_prev; if ((curmp)->elem.cqe_prev == (void *)(&me->phdrList)) (&me->phdrList)->cqh_first = (curmp)->elem.cqe_next; else (curmp)->elem.cqe_prev->elem.cqe_next = (curmp)->elem.cqe_next; } while ( 0);
      elfu_mPhdrDestroy(curmp);
    }
  }
  if (!((&me->orphanScnList)->cqh_first == (void *)(&me->orphanScnList))) {
    struct ElfuScn *nextms;
    nextms = ((&me->orphanScnList)->cqh_first);
    while ((void *)nextms != (void *)&me->orphanScnList) {
      struct ElfuScn *curms = nextms;
      nextms = ((curms)->elemChildScn.cqe_next);
      do { if ((curms)->elemChildScn.cqe_next == (void *)(&me->orphanScnList)) (&me->orphanScnList)->cqh_last = (curms)->elemChildScn.cqe_prev; else (curms)->elemChildScn.cqe_next->elemChildScn.cqe_prev = (curms)->elemChildScn.cqe_prev; if ((curms)->elemChildScn.cqe_prev == (void *)(&me->orphanScnList)) (&me->orphanScnList)->cqh_first = (curms)->elemChildScn.cqe_next; else (curms)->elemChildScn.cqe_prev->elemChildScn.cqe_next = (curms)->elemChildScn.cqe_next; } while ( 0);
      elfu_mScnDestroy(curms);
    }
  }
  free(me);
}


decompiled_code:
__int64 __fastcall subScnAdd2(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // er12
__int64 result; // rax
__int64 v6; // rax
const char *v7; // rax

v3 = *(_DWORD *)(a2 + 4);
if ( v3 == 8 )
return 0LL;
if ( v3 > 8 )
{
if ( v3 == 9 )
goto LABEL_5;
LABEL_8:
v7 = (const char *)elfu_mScnName(a1, a2);
fprintf(stderr, "mReladd: Skipping section %s (type %d).\n", v7, v3);
return 0LL;
}
result = 0LL;
if ( v3 <= 3 )
return result;
if ( v3 != 4 )
goto LABEL_8;
LABEL_5:
v6 = elfu_mScnByOldscn(a3, *(_QWORD *)(a2 + 80));
return -(__int64)((unsigned int)elfu_mRelocate(a3, v6, a2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // er12
__int64 result; // rax
__int64 v6; // rax
const char *v7; // rax

v3 = *(_DWORD *)(a2 + 4);
if ( v3 == 8 )
return 0LL;
if ( v3 > 8 )
{
if ( v3 == 9 )
goto LABEL_5;
LABEL_8:
v7 = (const char *)elfu_mScnName(a1, a2);
fprintf(stderr, "mReladd: Skipping section %s (type %d).\n", v7, v3);
return 0LL;
}
result = 0LL;
if ( v3 <= 3 )
return result;
if ( v3 != 4 )
goto LABEL_8;
LABEL_5:
v6 = elfu_mScnByOldscn(a3, *(_QWORD *)(a2 + 80));
return -(__int64)((unsigned int)elfu_mRelocate(a3, v6, a2) != 0);
}

original_code:
static void* subScnAdd2(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2)
{
  ElfuElf *me = (ElfuElf*)aux1;
  (void)aux2;
  switch(ms->shdr.sh_type) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 8:
      break;
    case 4:
    case 9:
      if (elfu_mRelocate(me, elfu_mScnByOldscn(me, ms->infoptr), ms)) {
        return (void*)-1;
      }
      break;
    case 7:
    case 5:
    case 6:
    case 10:
    case 11:
    case 14:
    case 15:
    case 16:
    case 17:
    case 18:
    case 19:
    default:
      do { fprintf(stderr, "mReladd: Skipping section %s (type %d).\n", elfu_mScnName(mrel, ms), ms->shdr.sh_type); } while(0);
  }
  return ((void *)0);
}

canonical_original_code:
static void *subScnAdd2(struct ElfuElf *mrel, struct ElfuScn *ms, void *aux1, void *aux2)
{
  struct ElfuElf *me = (ElfuElf*)aux1;
  (void)aux2;
  switch(ms->shdr.sh_type) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 8:
      break;
    case 4:
    case 9:
      if (elfu_mRelocate(me, elfu_mScnByOldscn(me, ms->infoptr), ms)) {
        return (void *)-1;
      }
      break;
    case 7:
    case 5:
    case 6:
    case 10:
    case 11:
    case 14:
    case 15:
    case 16:
    case 17:
    case 18:
    case 19:
    default:
      do { fprintf(stderr, "mReladd: Skipping section %s (type %d).\n", elfu_mScnName(mrel, ms), ms->shdr.sh_type); } while(0);
  }
  return ((void *)0);
}

variable_types:
ms
struct ElfuScn *


decompiled_code:
__int64 __fastcall subScnAdd1(__int64 a1, const __m128i *a2, __int64 a3)
{
__int32 v3; // eax
unsigned __int32 v5; // er13
const char *v6; // rax

v3 = a2->m128i_i32[1];
if ( (v3 == 1 || v3 == 8) && a2[2].m128i_i64[0] && !insertSection(a3, a1, a2) )
{
v5 = a2->m128i_u32[1];
v6 = (const char *)elfu_mScnName(a1, a2);
fprintf(stderr, "mReladd: Could not insert section %s (type %d), skipping.\n", v6, v5);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const __m128i *a2, __int64 a3)
{
__int32 v3; // eax
unsigned __int32 v5; // er13
const char *v6; // rax

v3 = a2->m128i_i32[1];
if ( (v3 == 1 || v3 == 8) && a2[2].m128i_i64[0] && !insertSection(a3, a1, a2) )
{
v5 = a2->m128i_u32[1];
v6 = (const char *)elfu_mScnName(a1, a2);
fprintf(stderr, "mReladd: Could not insert section %s (type %d), skipping.\n", v6, v5);
}
return 0LL;
}

original_code:
static void* subScnAdd1(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2)
{
  ElfuScn *newscn;
  ElfuElf *me = (ElfuElf*)aux1;
  (void)aux2;
  switch(ms->shdr.sh_type) {
    case 1:
    case 8:
      if (ms->shdr.sh_size == 0) {
        break;
      }
      newscn = insertSection(me, mrel, ms);
      if (!newscn) {
        do { fprintf(stderr, "mReladd: Could not insert section %s (type %d), skipping.\n", elfu_mScnName(mrel, ms), ms->shdr.sh_type); } while(0);
      }
      break;
  }
  return ((void *)0);
}

canonical_original_code:
static void *subScnAdd1(struct ElfuElf *mrel, struct ElfuScn *ms, void *aux1, void *aux2)
{
  struct ElfuScn *newscn;
  struct ElfuElf *me = (ElfuElf*)aux1;
  (void)aux2;
  switch(ms->shdr.sh_type) {
    case 1:
    case 8:
      if (ms->shdr.sh_size == 0) {
        break;
      }
      newscn = insertSection(me, mrel, ms);
      if (!newscn) {
        do { fprintf(stderr, "mReladd: Could not insert section %s (type %d), skipping.\n", elfu_mScnName(mrel, ms), ms->shdr.sh_type); } while(0);
      }
      break;
  }
  return ((void *)0);
}


insertSymClone

decompiled_code:
void __fastcall insertSymClone(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // r13
_DWORD *v6; // rbp
const char *v7; // r15
size_t v8; // r14
char *v9; // rax
__int64 v10; // rdx
__int64 v11; // rdi
_QWORD *v12; // rax
unsigned int v13; // esi
unsigned int v14; // edx
char v15; // cl
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // [rsp+8h] [rbp-40h]

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/reladd.c", 0xECu, "insertSymClone");
if ( !a2 )
_assert_fail("oldmsst", "src/libelfu/modelops/reladd.c", 0xEDu, "insertSymClone");
if ( !a3 )
_assert_fail("oldsym", "src/libelfu/modelops/reladd.c", 0xEEu, "insertSymClone");
v4 = *((_QWORD *)a3 + 3);
if ( !v4 || (v4 = elfu_mScnByOldscn(a1, *((_QWORD *)a3 + 3))) != 0 )
{
elfu_mSymtabAddGlobalDymtabIfNotPresent(a1);
v6 = malloc(0x38uLL);
if ( v6 )
{
v7 = (const char *)(*(_QWORD *)(*(_QWORD *)(a2 + 72) + 64LL) + *a3);
v18 = *(_QWORD *)(*(_QWORD *)(a1 + 112) + 72LL);
v8 = *(_QWORD *)(v18 + 32) + strlen(v7) + 1;
v9 = (char *)realloc(*(void **)(v18 + 64), v8);
if ( v9 )
{
v10 = *(_QWORD *)(*(_QWORD *)(a1 + 112) + 72LL);
v11 = *(_QWORD *)(v10 + 32);
*(_QWORD *)(v10 + 64) = v9;
*v6 = v11;
strcpy(&v9[(unsigned int)v11], v7);
v12 = *(_QWORD **)(a1 + 112);
v13 = a3[4];
*(_QWORD *)(v12[9] + 32LL) = v8;
v14 = a3[8];
v6[4] = v13;
v15 = *((_BYTE *)a3 + 22);
v6[8] = v14;
LOWORD(v13) = *((_WORD *)a3 + 10);
v16 = *((_QWORD *)a3 + 1);
*((_QWORD *)v6 + 3) = v4;
*((_WORD *)v6 + 10) = v13;
*((_QWORD *)v6 + 1) = v16;
*((_BYTE *)v6 + 22) = v15;
if ( v4 )
*((_QWORD *)v6 + 1) = *(_QWORD *)(v4 + 16) + v16;
v17 = v12[13];
*((_QWORD *)v6 + 5) = v12 + 12;
*((_QWORD *)v6 + 6) = v17;
if ( v12 + 12 == (_QWORD *)v12[12] )
v12[12] = v6;
else
*(_QWORD *)(v17 + 40) = v6;
v12[13] = v6;
}
else
{
fwrite("insertSymClone: realloc() failed for strtab.\n", 1uLL, 0x2DuLL, stderr);
free(v6);
}
}
else
{
fwrite("insertSymClone: malloc() failed for newsym.\n", 1uLL, 0x2CuLL, stderr);
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // r13
_DWORD *v6; // rbp
const char *v7; // r15
size_t v8; // r14
char *v9; // rax
__int64 v10; // rdx
__int64 v11; // rdi
_QWORD *v12; // rax
unsigned int v13; // esi
unsigned int v14; // edx
char v15; // cl
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // [rsp+8h] [rbp-40h]

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/reladd.c", 0xECu, "insertSymClone");
if ( !a2 )
_assert_fail("oldmsst", "src/libelfu/modelops/reladd.c", 0xEDu, "insertSymClone");
if ( !a3 )
_assert_fail("oldsym", "src/libelfu/modelops/reladd.c", 0xEEu, "insertSymClone");
v4 = *((_QWORD *)a3 + 3);
if ( !v4 || (v4 = elfu_mScnByOldscn(a1, *((_QWORD *)a3 + 3))) != 0 )
{
elfu_mSymtabAddGlobalDymtabIfNotPresent(a1);
v6 = malloc(0x38uLL);
if ( v6 )
{
v7 = (const char *)(*(_QWORD *)(*(_QWORD *)(a2 + 72) + 64LL) + *a3);
v18 = *(_QWORD *)(*(_QWORD *)(a1 + 112) + 72LL);
v8 = *(_QWORD *)(v18 + 32) + strlen(v7) + 1;
v9 = (char *)realloc(*(void **)(v18 + 64), v8);
if ( v9 )
{
v10 = *(_QWORD *)(*(_QWORD *)(a1 + 112) + 72LL);
v11 = *(_QWORD *)(v10 + 32);
*(_QWORD *)(v10 + 64) = v9;
*v6 = v11;
strcpy(&v9[(unsigned int)v11], v7);
v12 = *(_QWORD **)(a1 + 112);
v13 = a3[4];
*(_QWORD *)(v12[9] + 32LL) = v8;
v14 = a3[8];
v6[4] = v13;
v15 = *((_BYTE *)a3 + 22);
v6[8] = v14;
LOWORD(v13) = *((_WORD *)a3 + 10);
v16 = *((_QWORD *)a3 + 1);
*((_QWORD *)v6 + 3) = v4;
*((_WORD *)v6 + 10) = v13;
*((_QWORD *)v6 + 1) = v16;
*((_BYTE *)v6 + 22) = v15;
if ( v4 )
*((_QWORD *)v6 + 1) = *(_QWORD *)(v4 + 16) + v16;
v17 = v12[13];
*((_QWORD *)v6 + 5) = v12 + 12;
*((_QWORD *)v6 + 6) = v17;
if ( v12 + 12 == (_QWORD *)v12[12] )
v12[12] = v6;
else
*(_QWORD *)(v17 + 40) = v6;
v12[13] = v6;
}
else
{
fwrite("insertSymClone: realloc() failed for strtab.\n", 1uLL, 0x2DuLL, stderr);
free(v6);
}
}
else
{
fwrite("insertSymClone: malloc() failed for newsym.\n", 1uLL, 0x2CuLL, stderr);
}
}
}

original_code:
static void insertSymClone(ElfuElf *me, const ElfuScn *oldmsst, const ElfuSym *oldsym)
{
  GElf_Xword newsize;
  char *newbuf;
  ElfuScn *newscn = ((void *)0);
  ElfuSym *newsym;
  char *oldsymname;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/reladd.c", 236, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((oldmsst) ? 1 : 0), __extension__ ({ if (oldmsst) ; else __assert_fail ("oldmsst", "src/libelfu/modelops/reladd.c", 237, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((oldsym) ? 1 : 0), __extension__ ({ if (oldsym) ; else __assert_fail ("oldsym", "src/libelfu/modelops/reladd.c", 238, __extension__ __PRETTY_FUNCTION__); }));
  if (oldsym->scnptr) {
    newscn = elfu_mScnByOldscn(me, oldsym->scnptr);
    if (!newscn) {
      return;
    }
  }
  elfu_mSymtabAddGlobalDymtabIfNotPresent(me);
  newsym = malloc(sizeof(*newsym));
  if (!newsym) {
    do { fprintf(stderr, "insertSymClone: malloc() failed for newsym.\n"); } while(0);
    goto ERROR;
  }
  oldsymname = ((oldmsst)->linkptr->databuf + (oldsym->name));
  newsize = me->symtab->linkptr->shdr.sh_size + strlen(oldsymname) + 1;
  newbuf = realloc(me->symtab->linkptr->databuf, newsize);
  if (!newbuf) {
    do { fprintf(stderr, "insertSymClone: realloc() failed for strtab.\n"); } while(0);
    goto ERROR;
  }
  me->symtab->linkptr->databuf = newbuf;
  newsym->name = me->symtab->linkptr->shdr.sh_size;
  strcpy(newbuf + newsym->name, oldsymname);
  me->symtab->linkptr->shdr.sh_size = newsize;
  newsym->scnptr = newscn;
  newsym->shndx = oldsym->shndx;
  newsym->bind = oldsym->bind;
  newsym->other = oldsym->other;
  newsym->size = oldsym->size;
  newsym->type = oldsym->type;
  newsym->value = oldsym->value;
  if (newscn) {
    newsym->value += newscn->shdr.sh_addr;
  }
  do { (newsym)->elem.cqe_next = (void *)(&me->symtab->symtab.syms); (newsym)->elem.cqe_prev = (&me->symtab->symtab.syms)->cqh_last; if ((&me->symtab->symtab.syms)->cqh_first == (void *)(&me->symtab->symtab.syms)) (&me->symtab->symtab.syms)->cqh_first = (newsym); else (&me->symtab->symtab.syms)->cqh_last->elem.cqe_next = (newsym); (&me->symtab->symtab.syms)->cqh_last = (newsym); } while ( 0);
  return;
  ERROR:
  if (newsym) {
    free(newsym);
  }
}

canonical_original_code:
static void insertSymClone(struct ElfuElf *me, struct ElfuScn *oldmsst, struct ElfuSym *oldsym)
{
  unsigned long newsize;
  char *newbuf;
  struct ElfuScn *newscn = ((void *)0);
  struct ElfuSym *newsym;
  char *oldsymname;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/reladd.c", 236, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((oldmsst) ? 1 : 0), __extension__ ({ if (oldmsst) ; else __assert_fail ("oldmsst", "src/libelfu/modelops/reladd.c", 237, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((oldsym) ? 1 : 0), __extension__ ({ if (oldsym) ; else __assert_fail ("oldsym", "src/libelfu/modelops/reladd.c", 238, __extension__ __PRETTY_FUNCTION__); }));
  if (oldsym->scnptr) {
    newscn = elfu_mScnByOldscn(me, oldsym->scnptr);
    if (!newscn) {
      return;
    }
  }
  elfu_mSymtabAddGlobalDymtabIfNotPresent(me);
  newsym = malloc(sizeof(*newsym));
  if (!newsym) {
    do { fprintf(stderr, "insertSymClone: malloc() failed for newsym.\n"); } while(0);
    goto ERROR;
  }
  oldsymname = ((oldmsst)->linkptr->databuf + (oldsym->name));
  newsize = me->symtab->linkptr->shdr.sh_size + strlen(oldsymname) + 1;
  newbuf = realloc(me->symtab->linkptr->databuf, newsize);
  if (!newbuf) {
    do { fprintf(stderr, "insertSymClone: realloc() failed for strtab.\n"); } while(0);
    goto ERROR;
  }
  me->symtab->linkptr->databuf = newbuf;
  newsym->name = me->symtab->linkptr->shdr.sh_size;
  strcpy(newbuf + newsym->name, oldsymname);
  me->symtab->linkptr->shdr.sh_size = newsize;
  newsym->scnptr = newscn;
  newsym->shndx = oldsym->shndx;
  newsym->bind = oldsym->bind;
  newsym->other = oldsym->other;
  newsym->size = oldsym->size;
  newsym->type = oldsym->type;
  newsym->value = oldsym->value;
  if (newscn) {
    newsym->value += newscn->shdr.sh_addr;
  }
  do { (newsym)->elem.cqe_next = (void *)(&me->symtab->symtab.syms); (newsym)->elem.cqe_prev = (&me->symtab->symtab.syms)->cqh_last; if ((&me->symtab->symtab.syms)->cqh_first == (void *)(&me->symtab->symtab.syms)) (&me->symtab->symtab.syms)->cqh_first = (newsym); else (&me->symtab->symtab.syms)->cqh_last->elem.cqe_next = (newsym); (&me->symtab->symtab.syms)->cqh_last = (newsym); } while ( 0);
  return;
  ERROR:
  if (newsym) {
    free(newsym);
  }
}

variable_types:
oldmsst
struct ElfuScn *

variable_types:
oldsym
struct ElfuSym *

variable_types:
newsize
unsigned long

variable_types:
newbuf
char *

variable_types: struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *

variable_types:
oldsymname
char *


mergeSymtab

decompiled_code:
__int64 __fastcall mergeSymtab(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 i; // rbx

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/reladd.c", 0x136u, "mergeSymtab");
if ( !a2 )
_assert_fail("mrel", "src/libelfu/modelops/reladd.c", 0x137u, "mergeSymtab");
v3 = *(_QWORD *)(a2 + 112);
for ( i = *(_QWORD *)(v3 + 96); i != v3 + 96; i = *(_QWORD *)(i + 40) )
{
insertSymClone(a1, v3, (unsigned int *)i);
v3 = *(_QWORD *)(a2 + 112);
}
return elfu_mSymtabFlatten(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 i; // rbx

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/reladd.c", 0x136u, "mergeSymtab");
if ( !a2 )
_assert_fail("mrel", "src/libelfu/modelops/reladd.c", 0x137u, "mergeSymtab");
v3 = *(_QWORD *)(a2 + 112);
for ( i = *(_QWORD *)(v3 + 96); i != v3 + 96; i = *(_QWORD *)(i + 40) )
{
func2(a1, v3, (unsigned int *)i);
v3 = *(_QWORD *)(a2 + 112);
}
return elfu_mSymtabFlatten(a1);
}

original_code:
static void mergeSymtab(ElfuElf *me, const ElfuElf *mrel)
{
  ElfuSym *sym;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/reladd.c", 310, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mrel) ? 1 : 0), __extension__ ({ if (mrel) ; else __assert_fail ("mrel", "src/libelfu/modelops/reladd.c", 311, __extension__ __PRETTY_FUNCTION__); }));
  for ((sym) = ((&mrel->symtab->symtab.syms)->cqh_first); (sym) != (const void *)(&mrel->symtab->symtab.syms); (sym) = ((sym)->elem.cqe_next)) {
    insertSymClone(me, mrel->symtab, sym);
  }
  elfu_mSymtabFlatten(me);
}

canonical_original_code:
static void mergeSymtab(struct ElfuElf *me, struct ElfuElf *mrel)
{
  struct ElfuSym *sym;
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/reladd.c", 310, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mrel) ? 1 : 0), __extension__ ({ if (mrel) ; else __assert_fail ("mrel", "src/libelfu/modelops/reladd.c", 311, __extension__ __PRETTY_FUNCTION__); }));
  for ((sym) = ((&mrel->symtab->symtab.syms)->cqh_first); (sym) != (void *)(&mrel->symtab->symtab.syms); (sym) = ((sym)->elem.cqe_next)) {
    insertSymClone(me, mrel->symtab, sym);
  }
  elfu_mSymtabFlatten(me);
}

variable_types:
mrel
struct ElfuElf *


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

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/reladd.c", 0x144u, "elfu_mReladd");
if ( !a2 )
_assert_fail("mrel", "src/libelfu/modelops/reladd.c", 0x145u, "elfu_mReladd");
elfu_mScnForall(a2, subScnAdd1, a1, 0LL);
mergeSymtab(a1, a2);
if ( elfu_mScnForall(a2, subScnAdd2, a1, 0LL) )
{
fwrite("elfu_mReladd: Reladd aborted. Target model is unclean.\n", 1uLL, 0x37uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
elfu_mLayoutAuto(a1);
result = 0LL;
}
return result;
}

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

if ( !a1 )
_assert_fail("me", "src/libelfu/modelops/reladd.c", 0x144u, "elfu_mReladd");
if ( !a2 )
_assert_fail("mrel", "src/libelfu/modelops/reladd.c", 0x145u, "elfu_mReladd");
elfu_mScnForall(a2, subScnAdd1, a1, 0LL);
func3(a1, a2);
if ( elfu_mScnForall(a2, subScnAdd2, a1, 0LL) )
{
fwrite("elfu_mReladd: Reladd aborted. Target model is unclean.\n", 1uLL, 0x37uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
elfu_mLayoutAuto(a1);
result = 0LL;
}
return result;
}

original_code:
int elfu_mReladd(ElfuElf *me, const ElfuElf *mrel)
{
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/reladd.c", 324, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mrel) ? 1 : 0), __extension__ ({ if (mrel) ; else __assert_fail ("mrel", "src/libelfu/modelops/reladd.c", 325, __extension__ __PRETTY_FUNCTION__); }));
  elfu_mScnForall((ElfuElf*)mrel, subScnAdd1, me, ((void *)0));
  mergeSymtab(me, mrel);
  if (elfu_mScnForall((ElfuElf*)mrel, subScnAdd2, me, ((void *)0))) {
    do { fprintf(stderr, "elfu_mReladd: Reladd aborted. Target model is unclean.\n"); } while(0);
    return -1;
  }
  elfu_mLayoutAuto(me);
  return 0;
}

canonical_original_code:
int elfu_mReladd(struct ElfuElf *me, struct ElfuElf *mrel)
{
  ((void) sizeof ((me) ? 1 : 0), __extension__ ({ if (me) ; else __assert_fail ("me", "src/libelfu/modelops/reladd.c", 324, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mrel) ? 1 : 0), __extension__ ({ if (mrel) ; else __assert_fail ("mrel", "src/libelfu/modelops/reladd.c", 325, __extension__ __PRETTY_FUNCTION__); }));
  elfu_mScnForall((struct ElfuElf *)mrel, subScnAdd1, me, ((void *)0));
  mergeSymtab(me, mrel);
  if (elfu_mScnForall((struct ElfuElf *)mrel, subScnAdd2, me, ((void *)0))) {
    do { fprintf(stderr, "elfu_mReladd: Reladd aborted. Target model is unclean.\n"); } while(0);
    return -1;
  }
  elfu_mLayoutAuto(me);
  return 0;
}

variable_types: struct ElfuElf { int elfclass; 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; } ehdr; struct PhdrList { struct ElfuPhdr { 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; } phdr; struct ChildScnList { struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } *cqh_first; struct ElfuScn *cqh_last; } childScnList; struct ChildPhdrList { struct ElfuPhdr *cqh_first; struct ElfuPhdr *cqh_last; } childPhdrList; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elemChildPhdr; struct { struct ElfuPhdr *cqe_next; struct ElfuPhdr *cqe_prev; } elem; } *cqh_first; struct ElfuPhdr *cqh_last; } phdrList; struct OrphanScnList { struct ElfuScn *cqh_first; struct ElfuScn *cqh_last; } orphanScnList; struct ElfuScn *shstrtab; struct ElfuScn *symtab; } *


decompiled_code:
int __fastcall puts_alternative(char *s)
{
puts("puts_alternative() has been reached.");
puts(s);
return puts("puts_alternative() is returning.");
}

canonical_decompiled_code:
int __fastcall func0(char *s)
{
puts("puts_alternative() has been reached.");
puts(s);
return puts("puts_alternative() is returning.");
}

original_code:
void puts_alternative(char *arg)
{
  puts("puts_alternative() has been reached.");
  puts(arg);
  puts("puts_alternative() is returning.");
}

variable_types:
arg
char *


decompiled_code:
int puts_noarg()
{
puts("puts_noarg() has been reached.");
return puts("puts_noarg() is returning.");
}

canonical_decompiled_code:
int func0()
{
puts("puts_noarg() has been reached.");
return puts("puts_noarg() is returning.");
}

original_code:
void puts_noarg()
{
  puts("puts_noarg() has been reached.");
  puts("puts_noarg() is returning.");
}


decompiled_code:
__int64 __fastcall elfu_mRelocate(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rbx
int *v6; // rbp
__int64 v7; // rax
__int64 v8; // r15
int v9; // eax
_BOOL8 v10; // rdx
int v11; // esi
unsigned __int8 v12; // al
int v13; // ecx
int v15; // ecx
unsigned __int8 v16; // al
int v17; // esi
__int64 v18; // rax
int v19; // eax
__int64 v20; // rax
const char *v21; // rax
__int64 v22; // [rsp+8h] [rbp-50h]
_DWORD v23[16]; // [rsp+18h] [rbp-40h] BYREF

if ( !a2 )
_assert_fail("mstarget", "src/libelfu/modelops/relocate.c", 0x1Du, "elfu_mRelocate");
if ( !a3 )
_assert_fail("msrt", "src/libelfu/modelops/relocate.c", 0x1Eu, "elfu_mRelocate");
fprintf(stdout, "Relocating in section of type %u size %x\n", *(unsigned int *)(a2 + 4), *(unsigned int *)(a2 + 32));
v5 = *(_QWORD *)(a3 + 112);
v22 = a3 + 112;
if ( v5 == a3 + 112 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v6 = (int *)(*(_QWORD *)(a2 + 64) + *(_QWORD *)v5);
v7 = elfu_mSymtabIndexToSym(*(_QWORD *)(a3 + 72), *(unsigned int *)(v5 + 8));
v8 = v7;
if ( !v7 )
_assert_fail("sym", "src/libelfu/modelops/relocate.c", 0x2Bu, "elfu_mRelocate");
v9 = elfu_mSymtabLookupSymToAddr(a1, *(_QWORD *)(a3 + 72), v7, v23);
v10 = v9 == 0;
if ( v9 )
{
if ( !*(_DWORD *)(v8 + 32) )
{
v18 = elfu_mSymtabSymToName(*(_QWORD *)(a3 + 72), v8, v10);
v19 = elfu_mDynLookupPltAddrByName(a1, v18, v23);
v10 = 1LL;
if ( v19 )
{
v20 = elfu_mSymtabSymToName(*(_QWORD *)(a3 + 72), v8, 1LL);
v10 = (unsigned int)elfu_mDynLookupReldynAddrByName(a1, v20, v23) == 0;
}
}
}
if ( *(_DWORD *)a1 != 1 )
break;
if ( *(_DWORD *)(v5 + 16) )
v11 = *(_DWORD *)(v5 + 20);
else
v11 = *v6;
if ( *(_WORD *)(a1 + 26) != 3 )
goto LABEL_19;
v12 = *(_BYTE *)(v5 + 12);
v13 = v23[0];
switch ( v12 )
{
case 1u:
if ( !v10 )
goto LABEL_39;
goto LABEL_37;
case 2u:
if ( !v10 )
goto LABEL_39;
v13 = v23[0] - *(_DWORD *)(a2 + 16) - *(_DWORD *)v5;
LABEL_37:
*v6 = v13 + v11;
goto LABEL_6;
case 0u:
goto LABEL_34;
}
fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d\n", v12);
v5 = *(_QWORD *)(v5 + 24);
if ( v5 == v22 )
return 0LL;
}
if ( *(_DWORD *)a1 == 2 )
break;
LABEL_6:
v5 = *(_QWORD *)(v5 + 24);
if ( v5 == v22 )
return 0LL;
}
if ( *(_DWORD *)(v5 + 16) )
v15 = *(_DWORD *)(v5 + 20);
else
v15 = *v6;
if ( *(_WORD *)(a1 + 26) != 62 )
{
LABEL_19:
fwrite("elfu_mRelocate: Unknown machine type. Aborting.\n", 1uLL, 0x30uLL, stderr);
goto LABEL_6;
}
v16 = *(_BYTE *)(v5 + 12);
v17 = v23[0];
if ( v16 != 2 )
{
if ( v16 > 2u )
{
if ( v16 != 10 )
{
fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d", v16);
goto LABEL_6;
}
}
else if ( !v16 )
{
LABEL_34:
fwrite("Skipping relocation: R_386_NONE\n", 1uLL, 0x20uLL, stdout);
goto LABEL_6;
}
if ( !v10 )
goto LABEL_39;
goto LABEL_27;
}
if ( v10 )
{
v17 = v23[0] - *(_DWORD *)(a2 + 16) - *(_DWORD *)v5;
LABEL_27:
*v6 = v17 + v15;
goto LABEL_6;
}
LABEL_39:
v21 = (const char *)elfu_mSymtabSymToName(*(_QWORD *)(a3 + 72), v8, v10);
fprintf(stderr, "elfu_mRelocate: Could not resolve symbol %s. Aborting.\n", v21);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rbx
int *v6; // rbp
__int64 v7; // rax
__int64 v8; // r15
int v9; // eax
_BOOL8 v10; // rdx
int v11; // esi
unsigned __int8 v12; // al
int v13; // ecx
int v15; // ecx
unsigned __int8 v16; // al
int v17; // esi
__int64 v18; // rax
int v19; // eax
__int64 v20; // rax
const char *v21; // rax
__int64 v22; // [rsp+8h] [rbp-50h]
_DWORD v23[16]; // [rsp+18h] [rbp-40h] BYREF

if ( !a2 )
_assert_fail("mstarget", "src/libelfu/modelops/relocate.c", 0x1Du, "elfu_mRelocate");
if ( !a3 )
_assert_fail("msrt", "src/libelfu/modelops/relocate.c", 0x1Eu, "elfu_mRelocate");
fprintf(stdout, "Relocating in section of type %u size %x\n", *(unsigned int *)(a2 + 4), *(unsigned int *)(a2 + 32));
v5 = *(_QWORD *)(a3 + 112);
v22 = a3 + 112;
if ( v5 == a3 + 112 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v6 = (int *)(*(_QWORD *)(a2 + 64) + *(_QWORD *)v5);
v7 = elfu_mSymtabIndexToSym(*(_QWORD *)(a3 + 72), *(unsigned int *)(v5 + 8));
v8 = v7;
if ( !v7 )
_assert_fail("sym", "src/libelfu/modelops/relocate.c", 0x2Bu, "elfu_mRelocate");
v9 = elfu_mSymtabLookupSymToAddr(a1, *(_QWORD *)(a3 + 72), v7, v23);
v10 = v9 == 0;
if ( v9 )
{
if ( !*(_DWORD *)(v8 + 32) )
{
v18 = elfu_mSymtabSymToName(*(_QWORD *)(a3 + 72), v8, v10);
v19 = elfu_mDynLookupPltAddrByName(a1, v18, v23);
v10 = 1LL;
if ( v19 )
{
v20 = elfu_mSymtabSymToName(*(_QWORD *)(a3 + 72), v8, 1LL);
v10 = (unsigned int)elfu_mDynLookupReldynAddrByName(a1, v20, v23) == 0;
}
}
}
if ( *(_DWORD *)a1 != 1 )
break;
if ( *(_DWORD *)(v5 + 16) )
v11 = *(_DWORD *)(v5 + 20);
else
v11 = *v6;
if ( *(_WORD *)(a1 + 26) != 3 )
goto LABEL_19;
v12 = *(_BYTE *)(v5 + 12);
v13 = v23[0];
switch ( v12 )
{
case 1u:
if ( !v10 )
goto LABEL_39;
goto LABEL_37;
case 2u:
if ( !v10 )
goto LABEL_39;
v13 = v23[0] - *(_DWORD *)(a2 + 16) - *(_DWORD *)v5;
LABEL_37:
*v6 = v13 + v11;
goto LABEL_6;
case 0u:
goto LABEL_34;
}
fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d\n", v12);
v5 = *(_QWORD *)(v5 + 24);
if ( v5 == v22 )
return 0LL;
}
if ( *(_DWORD *)a1 == 2 )
break;
LABEL_6:
v5 = *(_QWORD *)(v5 + 24);
if ( v5 == v22 )
return 0LL;
}
if ( *(_DWORD *)(v5 + 16) )
v15 = *(_DWORD *)(v5 + 20);
else
v15 = *v6;
if ( *(_WORD *)(a1 + 26) != 62 )
{
LABEL_19:
fwrite("elfu_mRelocate: Unknown machine type. Aborting.\n", 1uLL, 0x30uLL, stderr);
goto LABEL_6;
}
v16 = *(_BYTE *)(v5 + 12);
v17 = v23[0];
if ( v16 != 2 )
{
if ( v16 > 2u )
{
if ( v16 != 10 )
{
fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d", v16);
goto LABEL_6;
}
}
else if ( !v16 )
{
LABEL_34:
fwrite("Skipping relocation: R_386_NONE\n", 1uLL, 0x20uLL, stdout);
goto LABEL_6;
}
if ( !v10 )
goto LABEL_39;
goto LABEL_27;
}
if ( v10 )
{
v17 = v23[0] - *(_DWORD *)(a2 + 16) - *(_DWORD *)v5;
LABEL_27:
*v6 = v17 + v15;
goto LABEL_6;
}
LABEL_39:
v21 = (const char *)elfu_mSymtabSymToName(*(_QWORD *)(a3 + 72), v8, v10);
fprintf(stderr, "elfu_mRelocate: Could not resolve symbol %s. Aborting.\n", v21);
return 0xFFFFFFFFLL;
}

original_code:
int elfu_mRelocate(ElfuElf *metarget, ElfuScn *mstarget, ElfuScn *msrt)
{
  ElfuRel *rel;
  ElfuSym *sym;
  ((void) sizeof ((mstarget) ? 1 : 0), __extension__ ({ if (mstarget) ; else __assert_fail ("mstarget", "src/libelfu/modelops/relocate.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((msrt) ? 1 : 0), __extension__ ({ if (msrt) ; else __assert_fail ("msrt", "src/libelfu/modelops/relocate.c", 30, __extension__ __PRETTY_FUNCTION__); }));
  do { fprintf(stdout, "Relocating in section of type %u size %x\n", mstarget->shdr.sh_type, (unsigned)mstarget->shdr.sh_size); } while(0);
  for ((rel) = ((&msrt->reltab.rels)->cqh_first); (rel) != (const void *)(&msrt->reltab.rels); (rel) = ((rel)->elem.cqe_next)) {
    Elf32_Word *dest32 = (Elf32_Word*)(mstarget->databuf + rel->offset);
    Elf64_Word *dest64 = (Elf64_Word*)(mstarget->databuf + rel->offset);
    GElf_Addr s;
    int haveSymval = 0;
    sym = elfu_mSymtabIndexToSym(msrt->linkptr, rel->sym);
    ((void) sizeof ((sym) ? 1 : 0), __extension__ ({ if (sym) ; else __assert_fail ("sym", "src/libelfu/modelops/relocate.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    haveSymval = !elfu_mSymtabLookupSymToAddr(metarget,
                                              msrt->linkptr,
                                              sym,
                                              &s);
    if (!haveSymval) {
      if (sym->shndx == 0) {
        haveSymval = !elfu_mDynLookupPltAddrByName(metarget,
                                     elfu_mSymtabSymToName(msrt->linkptr, sym),
                                     &s);
        if (!haveSymval) {
          haveSymval = !elfu_mDynLookupReldynAddrByName(metarget,
                                       elfu_mSymtabSymToName(msrt->linkptr, sym),
                                       &s);
        }
      }
    }
    if (metarget->elfclass == 1) {
      Elf32_Word a32 = rel->addendUsed ? rel->addend : *dest32;
      Elf32_Addr p32 = mstarget->shdr.sh_addr + rel->offset;
      Elf32_Addr s32 = (Elf32_Addr)s;
      switch(metarget->ehdr.e_machine) {
        case 3:
          switch(rel->type) {
            case 0:
              do { fprintf(stdout, "Skipping relocation: R_386_NONE\n"); } while(0);
              break;
            case 1:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s32 + a32;
              break;
            case 2:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s32 + a32 - p32;
              break;
            default:
              do { fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d\n", rel->type); } while(0);
          }
          break;
        default:
          do { fprintf(stderr, "elfu_mRelocate: Unknown machine type. Aborting.\n"); } while(0);
      }
    } else if (metarget->elfclass == 2) {
      Elf64_Word a64 = rel->addendUsed ? rel->addend : *dest64;
      Elf64_Addr p64 = mstarget->shdr.sh_addr + rel->offset;
      Elf64_Addr s64 = (Elf64_Addr)s;
      switch(metarget->ehdr.e_machine) {
        case 62:
          switch(rel->type) {
            case 0:
              do { fprintf(stdout, "Skipping relocation: R_386_NONE\n"); } while(0);
              break;
            case 1:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest64 = s64 + a64;
              break;
            case 2:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s64 + a64 - p64;
              break;
            case 10:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s64 + a64;
              break;
            default:
              do { fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d", rel->type); } while(0);
          }
          break;
        default:
          do { fprintf(stderr, "elfu_mRelocate: Unknown machine type. Aborting.\n"); } while(0);
      }
    }
  }
  return 0;
  MISSINGSYM:
  do { fprintf(stderr, "elfu_mRelocate: Could not resolve symbol %s. Aborting.\n", elfu_mSymtabSymToName(msrt->linkptr, sym)); } while(0);
  return -1;
}

canonical_original_code:
int elfu_mRelocate(struct ElfuElf *metarget, struct ElfuScn *mstarget, struct ElfuScn *msrt)
{
  struct ElfuRel *rel;
  struct ElfuSym *sym;
  ((void) sizeof ((mstarget) ? 1 : 0), __extension__ ({ if (mstarget) ; else __assert_fail ("mstarget", "src/libelfu/modelops/relocate.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((msrt) ? 1 : 0), __extension__ ({ if (msrt) ; else __assert_fail ("msrt", "src/libelfu/modelops/relocate.c", 30, __extension__ __PRETTY_FUNCTION__); }));
  do { fprintf(stdout, "Relocating in section of type %u size %x\n", mstarget->shdr.sh_type, (unsigned int)mstarget->shdr.sh_size); } while(0);
  for ((rel) = ((&msrt->reltab.rels)->cqh_first); (rel) != (void *)(&msrt->reltab.rels); (rel) = ((rel)->elem.cqe_next)) {
    unsigned int *dest32 = (Elf32_Word*)(mstarget->databuf + rel->offset);
    unsigned int *dest64 = (Elf64_Word*)(mstarget->databuf + rel->offset);
    unsigned long s;
    int haveSymval = 0;
    sym = elfu_mSymtabIndexToSym(msrt->linkptr, rel->sym);
    ((void) sizeof ((sym) ? 1 : 0), __extension__ ({ if (sym) ; else __assert_fail ("sym", "src/libelfu/modelops/relocate.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    haveSymval = !elfu_mSymtabLookupSymToAddr(metarget,
                                              msrt->linkptr,
                                              sym,
                                              &s);
    if (!haveSymval) {
      if (sym->shndx == 0) {
        haveSymval = !elfu_mDynLookupPltAddrByName(metarget,
                                     elfu_mSymtabSymToName(msrt->linkptr, sym),
                                     &s);
        if (!haveSymval) {
          haveSymval = !elfu_mDynLookupReldynAddrByName(metarget,
                                       elfu_mSymtabSymToName(msrt->linkptr, sym),
                                       &s);
        }
      }
    }
    if (metarget->elfclass == 1) {
      unsigned int a32 = rel->addendUsed ? rel->addend : *dest32;
      unsigned int p32 = mstarget->shdr.sh_addr + rel->offset;
      unsigned int s32 = (Elf32_Addr)s;
      switch(metarget->ehdr.e_machine) {
        case 3:
          switch(rel->type) {
            case 0:
              do { fprintf(stdout, "Skipping relocation: R_386_NONE\n"); } while(0);
              break;
            case 1:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s32 + a32;
              break;
            case 2:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s32 + a32 - p32;
              break;
            default:
              do { fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d\n", rel->type); } while(0);
          }
          break;
        default:
          do { fprintf(stderr, "elfu_mRelocate: Unknown machine type. Aborting.\n"); } while(0);
      }
    } else if (metarget->elfclass == 2) {
      unsigned int a64 = rel->addendUsed ? rel->addend : *dest64;
      unsigned long p64 = mstarget->shdr.sh_addr + rel->offset;
      unsigned long s64 = (Elf64_Addr)s;
      switch(metarget->ehdr.e_machine) {
        case 62:
          switch(rel->type) {
            case 0:
              do { fprintf(stdout, "Skipping relocation: R_386_NONE\n"); } while(0);
              break;
            case 1:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest64 = s64 + a64;
              break;
            case 2:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s64 + a64 - p64;
              break;
            case 10:
              if (!haveSymval) {
                goto MISSINGSYM;
              }
              *dest32 = s64 + a64;
              break;
            default:
              do { fprintf(stdout, "elfu_mRelocate: Skipping unknown relocation type %d", rel->type); } while(0);
          }
          break;
        default:
          do { fprintf(stderr, "elfu_mRelocate: Unknown machine type. Aborting.\n"); } while(0);
      }
    }
  }
  return 0;
  MISSINGSYM:
  do { fprintf(stderr, "elfu_mRelocate: Could not resolve symbol %s. Aborting.\n", elfu_mSymtabSymToName(msrt->linkptr, sym)); } while(0);
  return -1;
}

variable_types:
mstarget
struct ElfuScn *

variable_types:
msrt
struct ElfuScn *

variable_types: struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *

variable_types:
s
unsigned long

variable_types: haveSymval int


decompiled_code:
size_t sub_with_global()
{
fwrite("sub_with_global() has been reached.\n", 1uLL, 0x24uLL, stdout);
return fwrite("sub_with_global() is returning.\n", 1uLL, 0x20uLL, stdout);
}

canonical_decompiled_code:
size_t func0()
{
fwrite("sub_with_global() has been reached.\n", 1uLL, 0x24uLL, stdout);
return fwrite("sub_with_global() is returning.\n", 1uLL, 0x20uLL, stdout);
}

original_code:
void sub_with_global()
{
  fprintf(stdout, "sub_with_global() has been reached.\n");
  fprintf(stdout, "sub_with_global() is returning.\n");
}


printUsage

decompiled_code:
int __fastcall printUsage(const char *a1)
{
printf("Usage: %s -i <inputfile> [OPTIONS]\n", a1);
return puts(
"\n"
"Options, executed in order given:\n"
" -h, --help Print this help message\n"
"\n"
" -i, --input infile Load new ELF file (must be first command)\n"
"\n"
" -c, --check Do a few sanity checks and print any errors\n"
" -d, --dump Dump current model state (debug only)\n"
" --reladd obj.o Insert object file contents\n"
" --detour from,to Write a jump to <to> at <from>\n"
" -o, --output outfile Where to write the modified ELF file to\n");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("Usage: %s -i <inputfile> [OPTIONS]\n", a1);
return puts(
"\n"
"Options, executed in order given:\n"
" -h, --help Print this help message\n"
"\n"
" -i, --input infile Load new ELF file (must be first command)\n"
"\n"
" -c, --check Do a few sanity checks and print any errors\n"
" -d, --dump Dump current model state (debug only)\n"
" --reladd obj.o Insert object file contents\n"
" --detour from,to Write a jump to <to> at <from>\n"
" -o, --output outfile Where to write the modified ELF file to\n");
}

original_code:
static void printUsage(char *progname)
{
  printf("Usage: %s -i <inputfile> [OPTIONS]\n", progname);
  printf("\n"
         "Options, executed in order given:\n"
         "  -h, --help                     Print this help message\n"
         "\n"
         "  -i, --input         infile     Load new ELF file (must be first command)\n"
         "\n"
         "  -c, --check                    Do a few sanity checks and print any errors\n"
         "  -d, --dump                     Dump current model state (debug only)\n"
         "      --reladd        obj.o      Insert object file contents\n"
         "      --detour        from,to    Write a jump to <to> at <from>\n"
         "  -o, --output        outfile    Where to write the modified ELF file to\n"
         "\n");
}

variable_types:
progname
char *


decompiled_code:
__int64 __fastcall elfu_mCheck(__int64 a1)
{
__int64 v2; // rax
unsigned __int64 v3; // rbx
_QWORD *v4; // rbp
unsigned __int64 v5; // rax
__int64 v6; // rax
unsigned __int64 v7; // rdx
const char *v8; // r13
const char *v9; // rax
unsigned __int64 v10; // rbx
unsigned __int64 v11; // rax
const char *v12; // rax
unsigned __int64 i; // rbx
int v14; // ecx
int v15; // edi
const char *v16; // rax
__int64 v17; // rsi
unsigned __int64 v18; // rdx
unsigned __int64 v19; // rax
__int64 v20; // r8
unsigned __int64 v22[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = elfu_mScnSortedByOffset(a1, v22);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = 0LL;
v4 = (_QWORD *)v2;
if ( v22[0] == 1 )
goto LABEL_35;
do
{
while ( 1 )
{
v6 = v4[v3];
v7 = *(_QWORD *)(v6 + 24);
if ( *(_DWORD *)(v6 + 4) != 8 )
v7 += *(_QWORD *)(v6 + 32);
if ( *(_QWORD *)(v4[++v3] + 24LL) < v7 )
break;
v5 = v22[0];
if ( v3 >= v22[0] - 1 )
goto LABEL_9;
}
v8 = (const char *)elfu_mScnName(a1);
v9 = (const char *)elfu_mScnName(a1);
fprintf(stderr, "elfu_check: Found overlapping sections: %s and %s.\n", v9, v8);
v5 = v22[0];
}
while ( v3 < v22[0] - 1 );
LABEL_9:
if ( v5 )
{
LABEL_35:
v10 = 0LL;
do
{
while ( *(_QWORD *)(v4[v10] + 24LL) >= (unsigned __int64)*(unsigned __int16 *)(a1 + 60) )
{
v11 = v22[0];
if ( v22[0] <= ++v10 )
goto LABEL_14;
}
++v10;
v12 = (const char *)elfu_mScnName(a1);
fprintf(stderr, "elfu_check: Found section overlapping with EHDR: %s.\n", v12);
v11 = v22[0];
}
while ( v22[0] > v10 );
LABEL_14:
if ( v11 )
{
for ( i = 0LL; v22[0] > i; ++i )
{
v17 = v4[i];
v18 = *(_QWORD *)(a1 + 40);
v19 = *(_QWORD *)(v17 + 24);
if ( v19 == v18 )
{
if ( *(_DWORD *)(v17 + 4) == 8 )
continue;
v20 = *(_QWORD *)(v17 + 32);
if ( !v20 )
continue;
v14 = *(unsigned __int16 *)(a1 + 62);
v15 = *(unsigned __int16 *)(a1 + 64);
if ( !(v15 * v14) )
continue;
if ( v19 < v19 + v20 )
{
LABEL_19:
v16 = (const char *)elfu_mScnName(a1);
fprintf(stderr, "elfu_check: Found section overlapping with PHDRs: %s.\n", v16);
continue;
}
}
else
{
if ( v19 <= v18 )
{
if ( *(_DWORD *)(v17 + 4) != 8 && v18 < v19 + *(_QWORD *)(v17 + 32) )
goto LABEL_19;
if ( v19 < v18 )
continue;
}
v14 = *(unsigned __int16 *)(a1 + 62);
v15 = *(unsigned __int16 *)(a1 + 64);
}
if ( v19 < v15 * v14 + v18 )
goto LABEL_19;
}
}
}
free(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rax
unsigned __int64 v3; // rbx
_QWORD *v4; // rbp
unsigned __int64 v5; // rax
__int64 v6; // rax
unsigned __int64 v7; // rdx
const char *v8; // r13
const char *v9; // rax
unsigned __int64 v10; // rbx
unsigned __int64 v11; // rax
const char *v12; // rax
unsigned __int64 i; // rbx
int v14; // ecx
int v15; // edi
const char *v16; // rax
__int64 v17; // rsi
unsigned __int64 v18; // rdx
unsigned __int64 v19; // rax
__int64 v20; // r8
unsigned __int64 v22[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = elfu_mScnSortedByOffset(a1, v22);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = 0LL;
v4 = (_QWORD *)v2;
if ( v22[0] == 1 )
goto LABEL_35;
do
{
while ( 1 )
{
v6 = v4[v3];
v7 = *(_QWORD *)(v6 + 24);
if ( *(_DWORD *)(v6 + 4) != 8 )
v7 += *(_QWORD *)(v6 + 32);
if ( *(_QWORD *)(v4[++v3] + 24LL) < v7 )
break;
v5 = v22[0];
if ( v3 >= v22[0] - 1 )
goto LABEL_9;
}
v8 = (const char *)elfu_mScnName(a1);
v9 = (const char *)elfu_mScnName(a1);
fprintf(stderr, "elfu_check: Found overlapping sections: %s and %s.\n", v9, v8);
v5 = v22[0];
}
while ( v3 < v22[0] - 1 );
LABEL_9:
if ( v5 )
{
LABEL_35:
v10 = 0LL;
do
{
while ( *(_QWORD *)(v4[v10] + 24LL) >= (unsigned __int64)*(unsigned __int16 *)(a1 + 60) )
{
v11 = v22[0];
if ( v22[0] <= ++v10 )
goto LABEL_14;
}
++v10;
v12 = (const char *)elfu_mScnName(a1);
fprintf(stderr, "elfu_check: Found section overlapping with EHDR: %s.\n", v12);
v11 = v22[0];
}
while ( v22[0] > v10 );
LABEL_14:
if ( v11 )
{
for ( i = 0LL; v22[0] > i; ++i )
{
v17 = v4[i];
v18 = *(_QWORD *)(a1 + 40);
v19 = *(_QWORD *)(v17 + 24);
if ( v19 == v18 )
{
if ( *(_DWORD *)(v17 + 4) == 8 )
continue;
v20 = *(_QWORD *)(v17 + 32);
if ( !v20 )
continue;
v14 = *(unsigned __int16 *)(a1 + 62);
v15 = *(unsigned __int16 *)(a1 + 64);
if ( !(v15 * v14) )
continue;
if ( v19 < v19 + v20 )
{
LABEL_19:
v16 = (const char *)elfu_mScnName(a1);
fprintf(stderr, "elfu_check: Found section overlapping with PHDRs: %s.\n", v16);
continue;
}
}
else
{
if ( v19 <= v18 )
{
if ( *(_DWORD *)(v17 + 4) != 8 && v18 < v19 + *(_QWORD *)(v17 + 32) )
goto LABEL_19;
if ( v19 < v18 )
continue;
}
v14 = *(unsigned __int16 *)(a1 + 62);
v15 = *(unsigned __int16 *)(a1 + 64);
}
if ( v19 < v15 * v14 + v18 )
goto LABEL_19;
}
}
}
free(v4);
return 0LL;
}

original_code:
int elfu_mCheck(ElfuElf *me)
{
  size_t numSecs;
  ElfuScn **sortedSecs;
  size_t i;
  sortedSecs = elfu_mScnSortedByOffset(me, &numSecs);
  if (!sortedSecs) {
    return -1;
  }
  for (i = 0; i < numSecs - 1; i++) {
    if (sortedSecs[i]->shdr.sh_offset + ((&sortedSecs[i]->shdr)->sh_type == 8 ? 0 : (&sortedSecs[i]->shdr)->sh_size)
        > sortedSecs[i+1]->shdr.sh_offset) {
      do { fprintf(stderr, "elfu_check: Found overlapping sections: %s and %s.\n", elfu_mScnName(me, sortedSecs[i]), elfu_mScnName(me, sortedSecs[i+1])); } while(0);
    }
  }
  for (i = 0; i < numSecs; i++) {
    if (sortedSecs[i]->shdr.sh_offset < me->ehdr.e_ehsize) {
      do { fprintf(stderr, "elfu_check: Found section overlapping with EHDR: %s.\n", elfu_mScnName(me, sortedSecs[i])); } while(0);
    }
  }
  for (i = 0; i < numSecs; i++) {
    if ((!((sortedSecs[i]->shdr.sh_offset) == (me->ehdr.e_phoff) && ((((&sortedSecs[i]->shdr)->sh_type == 8 ? 0 : (&sortedSecs[i]->shdr)->sh_size) == 0) || (me->ehdr.e_phentsize * me->ehdr.e_phnum == 0))) && (((sortedSecs[i]->shdr.sh_offset) <= (me->ehdr.e_phoff) && (me->ehdr.e_phoff) < (((sortedSecs[i]->shdr.sh_offset)) + ((((&sortedSecs[i]->shdr)->sh_type == 8 ? 0 : (&sortedSecs[i]->shdr)->sh_size))))) || ((me->ehdr.e_phoff) <= (sortedSecs[i]->shdr.sh_offset) && (sortedSecs[i]->shdr.sh_offset) < (((me->ehdr.e_phoff)) + ((me->ehdr.e_phentsize * me->ehdr.e_phnum))))) )) {
      do { fprintf(stderr, "elfu_check: Found section overlapping with PHDRs: %s.\n", elfu_mScnName(me, sortedSecs[i])); } while(0);
    }
  }
  free(sortedSecs);
  return 0;
}

canonical_original_code:
int elfu_mCheck(struct ElfuElf *me)
{
  unsigned long numSecs;
  struct ElfuScn **sortedSecs;
  unsigned long i;
  sortedSecs = elfu_mScnSortedByOffset(me, &numSecs);
  if (!sortedSecs) {
    return -1;
  }
  for (i = 0; i < numSecs - 1; i++) {
    if (sortedSecs[i]->shdr.sh_offset + ((&sortedSecs[i]->shdr)->sh_type == 8 ? 0 : (&sortedSecs[i]->shdr)->sh_size)
        > sortedSecs[i+1]->shdr.sh_offset) {
      do { fprintf(stderr, "elfu_check: Found overlapping sections: %s and %s.\n", elfu_mScnName(me, sortedSecs[i]), elfu_mScnName(me, sortedSecs[i+1])); } while(0);
    }
  }
  for (i = 0; i < numSecs; i++) {
    if (sortedSecs[i]->shdr.sh_offset < me->ehdr.e_ehsize) {
      do { fprintf(stderr, "elfu_check: Found section overlapping with EHDR: %s.\n", elfu_mScnName(me, sortedSecs[i])); } while(0);
    }
  }
  for (i = 0; i < numSecs; i++) {
    if ((!((sortedSecs[i]->shdr.sh_offset) == (me->ehdr.e_phoff) && ((((&sortedSecs[i]->shdr)->sh_type == 8 ? 0 : (&sortedSecs[i]->shdr)->sh_size) == 0) || (me->ehdr.e_phentsize * me->ehdr.e_phnum == 0))) && (((sortedSecs[i]->shdr.sh_offset) <= (me->ehdr.e_phoff) && (me->ehdr.e_phoff) < (((sortedSecs[i]->shdr.sh_offset)) + ((((&sortedSecs[i]->shdr)->sh_type == 8 ? 0 : (&sortedSecs[i]->shdr)->sh_size))))) || ((me->ehdr.e_phoff) <= (sortedSecs[i]->shdr.sh_offset) && (sortedSecs[i]->shdr.sh_offset) < (((me->ehdr.e_phoff)) + ((me->ehdr.e_phentsize * me->ehdr.e_phnum))))) )) {
      do { fprintf(stderr, "elfu_check: Found section overlapping with PHDRs: %s.\n", elfu_mScnName(me, sortedSecs[i])); } while(0);
    }
  }
  free(sortedSecs);
  return 0;
}

variable_types:
numSecs
unsigned long

variable_types: struct ElfuScn { 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; } shdr; char *databuf; struct ElfuScn *linkptr; struct ElfuScn *infoptr; struct ElfuScn *oldptr; struct ElfuSymtab { struct Syms { struct ElfuSym { unsigned int name; unsigned long value; unsigned int size; unsigned char bind; unsigned char type; unsigned char other; struct ElfuScn *scnptr; int shndx; struct { struct ElfuSym *cqe_next; struct ElfuSym *cqe_prev; } elem; } *cqh_first; struct ElfuSym *cqh_last; } syms; } symtab; struct ElfuReltab { struct Rels { struct ElfuRel { unsigned long offset; unsigned int sym; unsigned char type; int addendUsed; int addend; struct { struct ElfuRel *cqe_next; struct ElfuRel *cqe_prev; } elem; } *cqh_first; struct ElfuRel *cqh_last; } rels; } reltab; struct { struct ElfuScn *cqe_next; struct ElfuScn *cqe_prev; } elemChildScn; } **

variable_types:
i
unsigned long


repo: norly/sysstatus

decompiled_code:
size_t __fastcall line_clear(__int64 a1)
{
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("g->linemax > 0", "src/common/common.c", 0x11u, "line_clear");
**(_BYTE **)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 24) = 0;
return line_append_str((size_t *)a1, "[");
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1)
{
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("g->linemax > 0", "src/common/common.c", 0x11u, "line_clear");
**(_BYTE **)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 24) = 0;
return func2((size_t *)a1, "[");
}

original_code:
void line_clear(GlobalData *g)
{
  ((void) sizeof ((g->linemax > 0) ? 1 : 0), __extension__ ({ if (g->linemax > 0) ; else __assert_fail ("g->linemax > 0", "src/common/common.c", 17, __extension__ __PRETTY_FUNCTION__); }));
  g->line[0] = '\0';
  g->linelen = 0;
  g->firstItemDone = 0;
  line_append_str(g, "[");
}

canonical_original_code:
void line_clear(struct GlobalData *g)
{
  ((void) sizeof ((g->linemax > 0) ? 1 : 0), __extension__ ({ if (g->linemax > 0) ; else __assert_fail ("g->linemax > 0", "src/common/common.c", 17, __extension__ __PRETTY_FUNCTION__); }));
  g->line[0] = '\0';
  g->linelen = 0;
  g->firstItemDone = 0;
  line_append_str(g, "[");
}

variable_types: struct GlobalData { char *line; unsigned long linelen; unsigned long linemax; int firstItemDone; } *


decompiled_code:
int __fastcall line_print(size_t *a1)
{
line_append_str(a1, "],");
return puts((const char *)*a1);
}

canonical_decompiled_code:
int __fastcall func5(size_t *a1)
{
func2(a1, "],");
return puts((const char *)*a1);
}

original_code:
void line_print(GlobalData *g)
{
  line_append_str(g, "],");
  puts(g->line);
}

canonical_original_code:
void line_print(struct GlobalData *g)
{
  line_append_str(g, "],");
  puts(g->line);
}

user_defined_types: struct GlobalData { char *line; unsigned long linelen; unsigned long linemax; int firstItemDone; }


updatestatus

decompiled_code:
int updatestatus()
{
line_clear(&gd);
status_cpuusage(&gd);
status_battery(&gd, "BAT0");
status_battery(&gd, "BAT1");
status_memusage(&gd);
status_netif(&gd, "eno0");
status_netif(&gd, "eth0");
status_netif(&gd, "wlp1s0");
status_netif(&gd, "wlan0");
status_netif(&gd, "usb0");
status_netif(&gd, "usb1");
status_temp(&gd, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon3/temp1_input");
status_temp(&gd, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon5/temp1_input");
status_fan(&gd, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon2/fan1_input");
status_fan(&gd, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/fan1_input");
if ( (unsigned int)status_volume_alsa(&gd, "default", "Master", 0LL)
&& (unsigned int)status_volume_alsa(&gd, "default", "DX3 Pro ", 0LL)
&& (unsigned int)status_volume_alsa(&gd, "default", "D10 ", 0LL)
&& (unsigned int)status_volume_alsa(&gd, "default", "PCM", 0LL) )
{
status_volume_alsa(&gd, "default", "Headset", 0LL);
}
status_datetime(&gd);
line_print(&gd);
return fflush(stdout);
}

canonical_decompiled_code:
int func0()
{
line_clear(&gd);
status_cpuusage(&gd);
status_battery(&gd, "BAT0");
status_battery(&gd, "BAT1");
status_memusage(&gd);
status_netif(&gd, "eno0");
status_netif(&gd, "eth0");
status_netif(&gd, "wlp1s0");
status_netif(&gd, "wlan0");
status_netif(&gd, "usb0");
status_netif(&gd, "usb1");
status_temp(&gd, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon3/temp1_input");
status_temp(&gd, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon5/temp1_input");
status_fan(&gd, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon2/fan1_input");
status_fan(&gd, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/fan1_input");
if ( (unsigned int)status_volume_alsa(&gd, "default", "Master", 0LL)
&& (unsigned int)status_volume_alsa(&gd, "default", "DX3 Pro ", 0LL)
&& (unsigned int)status_volume_alsa(&gd, "default", "D10 ", 0LL)
&& (unsigned int)status_volume_alsa(&gd, "default", "PCM", 0LL) )
{
status_volume_alsa(&gd, "default", "Headset", 0LL);
}
status_datetime(&gd);
line_print(&gd);
return fflush(stdout);
}

original_code:
void updatestatus()
{
  GlobalData *g = &gd;
  line_clear(g);
  status_cpuusage(g);
  status_battery(g, "BAT0");
  status_battery(g, "BAT1");
  status_memusage(g);
  status_netif(g, "eno0");
  status_netif(g, "eth0");
  status_netif(g, "wlp1s0");
  status_netif(g, "wlan0");
  status_netif(g, "usb0");
  status_netif(g, "usb1");
  status_temp(g, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon3/temp1_input");
  status_temp(g, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon5/temp1_input");
  status_fan(g, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon2/fan1_input");
  status_fan(g, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/fan1_input");
  if (status_volume_alsa(g, "default", "Master", 0))
  if (status_volume_alsa(g, "default", "DX3 Pro ", 0))
  if (status_volume_alsa(g, "default", "D10 ", 0))
  if (status_volume_alsa(g, "default", "PCM", 0))
  if (status_volume_alsa(g, "default", "Headset", 0)) {
    ;
  }
  status_datetime(g);
  line_print(g);
  fflush(stdout);
}

canonical_original_code:
void updatestatus()
{
  struct GlobalData *g = &gd;
  line_clear(g);
  status_cpuusage(g);
  status_battery(g, "BAT0");
  status_battery(g, "BAT1");
  status_memusage(g);
  status_netif(g, "eno0");
  status_netif(g, "eth0");
  status_netif(g, "wlp1s0");
  status_netif(g, "wlan0");
  status_netif(g, "usb0");
  status_netif(g, "usb1");
  status_temp(g, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon3/temp1_input");
  status_temp(g, "CPU: ", "/sys/devices/platform/coretemp.0/hwmon/hwmon5/temp1_input");
  status_fan(g, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon2/fan1_input");
  status_fan(g, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/fan1_input");
  if (status_volume_alsa(g, "default", "Master", 0))
  if (status_volume_alsa(g, "default", "DX3 Pro ", 0))
  if (status_volume_alsa(g, "default", "D10 ", 0))
  if (status_volume_alsa(g, "default", "PCM", 0))
  if (status_volume_alsa(g, "default", "Headset", 0)) {
    ;
  }
  status_datetime(g);
  line_print(g);
  fflush(stdout);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

puts("{\"version\":1}\n[");
while ( 1 )
{
updatestatus();
v3.tv_sec = 1LL;
v3.tv_usec = 0LL;
select(0, 0LL, 0LL, 0LL, &v3);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

puts("{\"version\":1}\n[");
while ( 1 )
{
func0();
v3.tv_sec = 1LL;
v3.tv_usec = 0LL;
select(0, 0LL, 0LL, 0LL, &v3);
}
}

original_code:
int main()
{
  struct timeval tv;
  printf("{\"version\":1}\n[\n");
  for(;;)
  {
    updatestatus();
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
  }
  return 0;
}

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