outstringsize

original_code:
long outstringsize(char const *str, long length)
{
    long size, i;
    size = 0;
    for (i = 0 ; i < length ; ++i) {
 switch (str[i]) {
   case '\0':
     if (i < length - 1 && str[i + 1] >= '0' && str[i + 1] <= '7')
  size += 4;
     else
  size += 2;
     break;
   case '\a': case '\r':
   case '\b': case '\t':
   case '\f': case '\v':
   case '\n': case '\\':
   case '"':
     size += 2;
     break;
   case ' ':
     ++size;
     break;
   default:
     if (((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short int) _ISprint))
  ++size;
     else
  size += 4;
     break;
 }
    }
    return size;
}

canonical_original_code:
long outstringsize(char *str, long length)
{
    long size; long i;
    size = 0;
    for (i = 0 ; i < length ; ++i) {
 switch (str[i]) {
   case '\0':
     if (i < length - 1 && str[i + 1] >= '0' && str[i + 1] <= '7')
  size += 4;
     else
  size += 2;
     break;
   case '\a': case '\r':
   case '\b': case '\t':
   case '\f': case '\v':
   case '\n': case '\\':
   case '"':
     size += 2;
     break;
   case ' ':
     ++size;
     break;
   default:
     if (((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short) _ISprint))
  ++size;
     else
  size += 4;
     break;
 }
    }
    return size;
}

variable_types: length long

variable_types: size long

variable_types: i long

return_type: long


outstring

decompiled_code:
__int64 __fastcall outstring(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er13
__int64 v4; // rbx
char *v5; // rax
__int64 result; // rax

if ( xpos >= rmargin )
goto LABEL_4;
if ( a2 <= 4 )
goto LABEL_5;
if ( rmargin <= xpos + 8 )
{
LABEL_4:
linebreak();
LABEL_5:
out("\"");
v2 = level;
v3 = pendingcomma;
pendingcomma = 0;
++level;
if ( a2 <= 0 )
goto LABEL_12;
goto LABEL_6;
}
out("\"");
v3 = pendingcomma;
++level;
pendingcomma = 0;
LABEL_6:
v4 = 0LL;
do
{
while ( 1 )
{
v5 = stringchar((char *)(a1 + v4));
textout(v5);
if ( xpos >= rmargin && (int)v4 + 2 < a2 )
break;
if ( a2 <= ++v4 )
goto LABEL_11;
}
++v4;
textout("\"");
linebreak();
textout("\"");
}
while ( a2 > v4 );
LABEL_11:
v2 = level - 1;
LABEL_12:
level = v2;
result = textout("\"");
pendingcomma = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er13
__int64 v4; // rbx
char *v5; // rax
__int64 result; // rax

if ( xpos >= rmargin )
goto LABEL_4;
if ( a2 <= 4 )
goto LABEL_5;
if ( rmargin <= xpos + 8 )
{
LABEL_4:
func5();
LABEL_5:
func8("\"");
v2 = level;
v3 = pendingcomma;
pendingcomma = 0;
++level;
if ( a2 <= 0 )
goto LABEL_12;
goto LABEL_6;
}
func8("\"");
v3 = pendingcomma;
++level;
pendingcomma = 0;
LABEL_6:
v4 = 0LL;
do
{
while ( 1 )
{
v5 = func1((char *)(a1 + v4));
func0(v5);
if ( xpos >= rmargin && (int)v4 + 2 < a2 )
break;
if ( a2 <= ++v4 )
goto LABEL_11;
}
++v4;
func0("\"");
func5();
func0("\"");
}
while ( a2 > v4 );
LABEL_11:
v2 = level - 1;
LABEL_12:
level = v2;
result = func0("\"");
pendingcomma = v3;
return result;
}

original_code:
void outstring(char const *str, long length)
{
    char const *s;
    int pc, i;
    if (xpos >= rmargin || (length > 4 && xpos + 8 >= rmargin))
 linebreak();
    out("\"");
    pc = pendingcomma;
    pendingcomma = 0;
    ++level;
    for (i = 0, s = str ; i < length ; ++i, ++s) {
 textout(stringchar(s));
 if (xpos >= rmargin && i + 2 < length) {
     textout("\"");
     linebreak();
     textout("\"");
 }
    }
    --level;
    textout("\"");
    pendingcomma = pc;
}

canonical_original_code:
void outstring(char *str, long length)
{
    char *s;
    int pc; int i;
    if (xpos >= rmargin || (length > 4 && xpos + 8 >= rmargin))
 linebreak();
    out("\"");
    pc = pendingcomma;
    pendingcomma = 0;
    ++level;
    for (i = 0, s = str ; i < length ; ++i, ++s) {
 textout(stringchar(s));
 if (xpos >= rmargin && i + 2 < length) {
     textout("\"");
     linebreak();
     textout("\"");
 }
    }
    --level;
    textout("\"");
    pendingcomma = pc;
}

variable_types:
str
char *

variable_types:
s
char *

variable_types: pc int

variable_types: i int

return_type: void


setprogramname

decompiled_code:
void __fastcall setprogramname(char *a1)
{
programname = a1;
}

canonical_decompiled_code:
void __fastcall func0(char *a1)
{
programname = a1;
}

original_code:
void setprogramname(char const *str)
{
    programname = str;
}

canonical_original_code:
void setprogramname(char *str)
{
    programname = str;
}


setfilename

decompiled_code:
void __fastcall setfilename(__int64 a1)
{
filename = a1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
filename = a1;
}

original_code:
void setfilename(char const *str)
{
    filename = str;
}

canonical_original_code:
void setfilename(char *str)
{
    filename = str;
}


enablewarnings

decompiled_code:
void __fastcall enablewarnings(int a1)
{
showwarnings = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
showwarnings = a1;
}

original_code:
void enablewarnings(int flag)
{
    showwarnings = flag;
}

variable_types: flag int


warn

decompiled_code:
__int64 warn(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !showwarnings )
return 0LL;
fprintf(stderr, "%s: ", programname);
if ( filename )
fprintf(stderr, "%s: ", (const char *)filename);
fwrite("warning: ", 1uLL, 9uLL, stderr);
va_start(arg, format);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !showwarnings )
return 0LL;
fprintf(stderr, "%s: ", programname);
if ( filename )
fprintf(stderr, "%s: ", (const char *)filename);
fwrite("warning: ", 1uLL, 9uLL, stderr);
va_start(arg, format);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return 0LL;
}

original_code:
int warn(char const *fmt, ...)
{
    va_list args;
    if (showwarnings) {
 fprintf(stderr, "%s: ", programname);
 if (filename)
     fprintf(stderr, "%s: ", filename);
 fputs("warning: ", stderr);
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
 fputc('\n', stderr);
    }
    return 0;
}

canonical_original_code:
int warn(char *fmt, ...)
{
    __builtin_va_list args;
    if (showwarnings) {
 fprintf(stderr, "%s: ", programname);
 if (filename)
     fprintf(stderr, "%s: ", filename);
 fputs("warning: ", stderr);
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
 fputc('\n', stderr);
    }
    return 0;
}

variable_types:
fmt
char *

return_type: int


deallocate

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

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

variable_types:
ptr
void *


err

decompiled_code:
void __noreturn err(const char *a1, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fprintf(stderr, "%s: ", programname);
if ( filename )
fprintf(stderr, "%s: ", (const char *)filename);
if ( a1 )
{
va_start(arg, a1);
vfprintf(stderr, a1, arg);
}
else
{
v1 = _errno_location();
v2 = strerror(*v1);
fputs(v2, stderr);
}
fputc(10, stderr);
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fprintf(stderr, "%s: ", programname);
if ( filename )
fprintf(stderr, "%s: ", (const char *)filename);
if ( a1 )
{
va_start(arg, a1);
vfprintf(stderr, a1, arg);
}
else
{
v1 = _errno_location();
v2 = strerror(*v1);
fputs(v2, stderr);
}
fputc(10, stderr);
}

original_code:
int err(char const *fmt, ...)
{
    va_list args;
    fprintf(stderr, "%s: ", programname);
    if (filename)
 fprintf(stderr, "%s: ", filename);
    if (fmt) {
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
    } else {
 fprintf(stderr, "%s", strerror((*__errno_location ())));
    }
    fputc('\n', stderr);
    return 0;
}

canonical_original_code:
int err(char *fmt, ...)
{
    __builtin_va_list args;
    fprintf(stderr, "%s: ", programname);
    if (filename)
 fprintf(stderr, "%s: ", filename);
    if (fmt) {
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
    } else {
 fprintf(stderr, "%s", strerror((*__errno_location ())));
    }
    fputc('\n', stderr);
    return 0;
}


fail

decompiled_code:
void __noreturn fail(char *format, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fprintf(stderr, "%s: ", programname);
if ( filename )
fprintf(stderr, "%s: ", (const char *)filename);
if ( format )
{
va_start(arg, format);
vfprintf(stderr, format, arg);
}
else
{
v1 = _errno_location();
v2 = strerror(*v1);
fputs(v2, stderr);
}
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func5(char *format, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fprintf(stderr, "%s: ", programname);
if ( filename )
fprintf(stderr, "%s: ", (const char *)filename);
if ( format )
{
va_start(arg, format);
vfprintf(stderr, format, arg);
}
else
{
v1 = _errno_location();
v2 = strerror(*v1);
fputs(v2, stderr);
}
fputc(10, stderr);
exit(1);
}

original_code:
void fail(char const *fmt, ...)
{
    va_list args;
    fprintf(stderr, "%s: ", programname);
    if (filename)
 fprintf(stderr, "%s: ", filename);
    if (fmt) {
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
    } else {
 fprintf(stderr, "%s", strerror((*__errno_location ())));
    }
    fputc('\n', stderr);
    exit(1);
}

canonical_original_code:
void fail(char *fmt, ...)
{
    __builtin_va_list args;
    fprintf(stderr, "%s: ", programname);
    if (filename)
 fprintf(stderr, "%s: ", filename);
    if (fmt) {
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
    } else {
 fprintf(stderr, "%s", strerror((*__errno_location ())));
    }
    fputc('\n', stderr);
    exit(1);
}


allocate

decompiled_code:
void *__fastcall allocate(size_t size)
{
void *result; // rax
char *v2; // rax

result = malloc((unsigned int)size);
if ( !result )
{
v2 = strerror(12);
fail(v2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(size_t size)
{
void *result; // rax
char *v2; // rax

result = malloc((unsigned int)size);
if ( !result )
{
v2 = strerror(12);
func5(v2);
}
return result;
}

original_code:
void *allocate(unsigned int size)
{
    void *ptr;
    ptr = malloc(size);
    if (!ptr)
 fail(strerror(12));
    return ptr;
}

variable_types:
size
unsigned int

return_type: void *


reallocate

decompiled_code:
void *__fastcall reallocate(void *a1, unsigned int a2)
{
void *result; // rax
char *v3; // rax

result = realloc(a1, a2);
if ( !result )
{
v3 = strerror(12);
fail(v3);
}
return result;
}

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

result = realloc(a1, a2);
if ( !result )
{
v3 = strerror(12);
func5(v3);
}
return result;
}

original_code:
void *reallocate(void *ptr, unsigned int size)
{
    ptr = realloc(ptr, size);
    if (!ptr)
 fail(strerror(12));
    return ptr;
}


strallocate

decompiled_code:
void *__fastcall strallocate(void *src)
{
size_t v1; // rax
size_t v2; // r12
void *v3; // rax

v1 = strlen((const char *)src);
v2 = v1 + 1;
v3 = allocate((unsigned int)(v1 + 1));
return memcpy(v3, src, v2);
}

canonical_decompiled_code:
void *__fastcall func8(void *src)
{
size_t v1; // rax
size_t v2; // r12
void *v3; // rax

v1 = strlen((const char *)src);
v2 = v1 + 1;
v3 = func6((unsigned int)(v1 + 1));
return memcpy(v3, src, v2);
}

original_code:
char *strallocate(char const *str)
{
    char *copy;
    size_t size;
    size = strlen(str) + 1;
    copy = allocate(size);
    memcpy(copy, str, size);
    return copy;
}

canonical_original_code:
char *strallocate(char *str)
{
    char *copy;
    unsigned long size;
    size = strlen(str) + 1;
    copy = allocate(size);
    memcpy(copy, str, size);
    return copy;
}

variable_types:
copy
char *

variable_types:
size
unsigned long

return_type: char *


decompiled_code:
__int16 __fastcall rev2(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static inline unsigned short rev2(unsigned short in)
{
    return ((in & 0x00FF) << 8) | ((in & 0xFF00) >> 8);
}

variable_types:
in
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall rev4(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return _byteswap_ulong(a1);
}

original_code:
static inline unsigned int rev4(unsigned int in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}

variable_types:
in
unsigned int

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall rev8(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

original_code:
static inline unsigned long long rev8(unsigned long long in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}

variable_types:
in
unsigned long long

return_type: unsigned long long


decompiled_code:
void __fastcall revinplc2(_WORD *a1)
{
*a1 = __ROL2__(*a1, 8);
}

canonical_decompiled_code:
void __fastcall func3(_WORD *a1)
{
*a1 = __ROL2__(*a1, 8);
}

original_code:
static inline void revinplc2(void *in)
{
    unsigned char tmp;
    tmp = ((unsigned char*)in)[0];
    ((unsigned char*)in)[0] = ((unsigned char*)in)[1];
    ((unsigned char*)in)[1] = tmp;
}

canonical_original_code:
static inline void revinplc2(void *in)
{
    unsigned char tmp;
    tmp = ((unsigned char *)in)[0];
    ((unsigned char *)in)[0] = ((unsigned char *)in)[1];
    ((unsigned char *)in)[1] = tmp;
}

variable_types:
in
void *

variable_types:
tmp
unsigned char


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

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}

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

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}

original_code:
static inline void revinplc4(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned int*)in) : "0"(*(unsigned int*)in));
}

canonical_original_code:
static inline void revinplc4(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned int *)in) : "0"(*(unsigned int *)in));
}


decompiled_code:
unsigned __int64 __fastcall revinplc8(unsigned __int64 *a1)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a1 = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned __int64 *a1)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a1 = result;
return result;
}

original_code:
static inline void revinplc8(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned long*)in) : "0"(*(unsigned long*)in));
}

canonical_original_code:
static inline void revinplc8(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned long *)in) : "0"(*(unsigned long *)in));
}


decompiled_code:
unsigned __int64 __fastcall elfrw_count_Syms(int a1)
{
return a1 / (8 * (unsigned __int64)(elfrw_current_class == 2) + 16);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func14(int a1)
{
return a1 / (8 * (unsigned __int64)(elfrw_current_class == 2) + 16);
}

original_code:
int elfrw_count_Syms(int size)
{
    return size / ((_elfrw_current_class == 2) ? sizeof(Elf64_Sym) : sizeof(Elf32_Sym));
}

variable_types: size int


decompiled_code:
unsigned __int64 __fastcall elfrw_count_Syminfos(int a1)
{
return (unsigned __int64)a1 >> 2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(int a1)
{
return (unsigned __int64)a1 >> 2;
}

original_code:
int elfrw_count_Syminfos(int size)
{
    return size / ((_elfrw_current_class == 2) ? sizeof(Elf64_Syminfo)
      : sizeof(Elf32_Syminfo));
}


addnametolist

decompiled_code:
__int64 __fastcall addnametolist(__int64 a1, int a2, int a3)
{
unsigned __int64 v4; // rbp
int v5; // ecx
void *v6; // rdi
size_t v7; // rbx
void *v8; // rax
__int64 result; // rax

v4 = 16 * (a3 + 14LL * a2);
v5 = dword_4040E8[v4 / 4];
v6 = (void *)namelists[v4 / 8];
dword_4040E8[v4 / 4] = v5 + 1;
v7 = 16LL * (v5 + 1);
v8 = realloc(v6, v7);
namelists[v4 / 8] = (__int64)v8;
result = (__int64)v8 + v7 - 16;
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3)
{
unsigned __int64 v4; // rbp
int v5; // ecx
void *v6; // rdi
size_t v7; // rbx
void *v8; // rax
__int64 result; // rax

v4 = 16 * (a3 + 14LL * a2);
v5 = dword_4040E8[v4 / 4];
v6 = (void *)namelists[v4 / 8];
dword_4040E8[v4 / 4] = v5 + 1;
v7 = 16LL * (v5 + 1);
v8 = realloc(v6, v7);
namelists[v4 / 8] = (__int64)v8;
result = (__int64)v8 + v7 - 16;
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = 0;
return result;
}

original_code:
static void addnametolist(char *name, int p, int m)
{
    struct namelist *list;
    int n;
    list = &namelists[p][m];
    n = list->count++;
    list->names = realloc(list->names, list->count * sizeof *list->names);
    list->names[n].str = name;
    list->names[n].hi = 0;
}

variable_types:
name
char *

variable_types: p int

variable_types: m int

variable_types: struct namelist { struct name { char *str; int hi; } *names; int count; } *

variable_types: n int

user_defined_types: struct namelist { struct name *names; int count; }


findhirange

decompiled_code:
__int64 __fastcall findhirange(const char **a1, int a2, int a3)
{
const char **v4; // rbp
int v5; // ebx
char v7[120]; // [rsp+0h] [rbp-78h] BYREF

v4 = a1;
strcpy(v7, a1[2 * a3]);
*(_WORD *)strstr(v7, "LO") = 18760;
if ( a2 <= 0 )
return 0LL;
v5 = 0;
while ( a3 == v5 || strcmp(*v4, v7) )
{
++v5;
v4 += 2;
if ( a2 == v5 )
return 0LL;
}
return (unsigned int)(v5 - a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char **a1, int a2, int a3)
{
const char **v4; // rbp
int v5; // ebx
char v7[120]; // [rsp+0h] [rbp-78h] BYREF

v4 = a1;
strcpy(v7, a1[2 * a3]);
*(_WORD *)strstr(v7, "LO") = 18760;
if ( a2 <= 0 )
return 0LL;
v5 = 0;
while ( a3 == v5 || strcmp(*v4, v7) )
{
++v5;
v4 += 2;
if ( a2 == v5 )
return 0LL;
}
return (unsigned int)(v5 - a3);
}

original_code:
static int findhirange(struct name const *names, int count, int lo)
{
    char hiname[80];
    char *p;
    int hi;
    strcpy(hiname, names[lo].str);
    p = strstr(hiname, "LO");
    p[0] = 'H';
    p[1] = 'I';
    for (hi = 0 ; hi < count ; ++hi)
 if (hi != lo && !strcmp(names[hi].str, hiname))
     return hi - lo;
    return 0;
}

canonical_original_code:
static int findhirange(struct name *names, int count, int lo)
{
    char hiname[80];
    char *p;
    int hi;
    strcpy(hiname, names[lo].str);
    p = strstr(hiname, "LO");
    p[0] = 'H';
    p[1] = 'I';
    for (hi = 0 ; hi < count ; ++hi)
 if (hi != lo && !strcmp(names[hi].str, hiname))
     return hi - lo;
    return 0;
}

variable_types:
names
struct name { char *str; int hi; } *

variable_types: count int

variable_types: lo int

variable_types:
hiname
char [80]

variable_types:
p
char *

variable_types: hi int


findranges

decompiled_code:
void __fastcall findranges(const char **a1, int a2)
{
const char **v2; // rbp
int i; // ebx

if ( a2 > 0 )
{
v2 = a1;
for ( i = 0; i != a2; ++i )
{
if ( strstr(*v2, "LO") )
*((_DWORD *)v2 + 2) = findhirange(a1, a2, i);
v2 += 2;
}
}
}

canonical_decompiled_code:
void __fastcall func9(const char **a1, int a2)
{
const char **v2; // rbp
int i; // ebx

if ( a2 > 0 )
{
v2 = a1;
for ( i = 0; i != a2; ++i )
{
if ( strstr(*v2, "LO") )
*((_DWORD *)v2 + 2) = func8(a1, a2, i);
v2 += 2;
}
}
}

original_code:
static void findranges(struct name *names, int count)
{
    int i;
    for (i = 0 ; i < count ; ++i)
 if (strstr(names[i].str, "LO"))
     names[i].hi = findhirange(names, count, i);
}

variable_types: i int


findallranges

decompiled_code:
void findallranges()
{
__int64 v0; // rbp
__int64 v1; // rbx
int v2; // esi
const char **v3; // rdi

v0 = 224LL;
do
{
v1 = v0 - 224;
do
{
v2 = *(int *)((char *)dword_4040E8 + v1);
v3 = *(const char ***)((char *)namelists + v1);
v1 += 16LL;
findranges(v3, v2);
}
while ( v1 != v0 );
v0 = v1 + 224;
}
while ( v1 != 7168 );
}

original_code:
static void findallranges(void)
{
    int p, m;
    for (p = 0 ; p < ((int)(sizeof prefixes / sizeof *prefixes)) ; ++p)
 for (m = 0 ; m < ((int)(sizeof machineids / sizeof *machineids)) ; ++m)
     findranges(namelists[p][m].names, namelists[p][m].count);
}

canonical_original_code:
static void findallranges()
{
    int p; int m;
    for (p = 0 ; p < ((int)(sizeof prefixes / sizeof *prefixes)) ; ++p)
 for (m = 0 ; m < ((int)(sizeof machineids / sizeof *machineids)) ; ++m)
     findranges(namelists[p][m].names, namelists[p][m].count);
}


findinfectionphdr

decompiled_code:
__int64 __fastcall findinfectionphdr(__int64 a1, int a2)
{
unsigned int v3; // er8
__int64 i; // rax
__int64 v6; // rdx
unsigned __int64 v7; // rdx
unsigned __int64 *v8; // rcx
int v9; // esi

v3 = 0;
for ( i = a1 + 4; ; i += 56LL )
{
v6 = *(_QWORD *)(i + 28);
if ( v6 )
{
if ( v6 == *(_QWORD *)(i + 36) && (*(_BYTE *)i & 1) != 0 )
break;
}
LABEL_2:
if ( a2 == ++v3 )
return 0xFFFFFFFFLL;
}
v7 = *(_QWORD *)(i + 4) + v6;
v8 = (unsigned __int64 *)(a1 + 8);
v9 = 0;
while ( *v8 >= v7 + 116 || *v8 < v7 || !v8[3] )
{
++v9;
v8 += 7;
if ( a2 == v9 )
return v3;
}
if ( a2 != v9 )
goto LABEL_2;
return v3;
}

original_code:
static int findinfectionphdr(Elf64_Phdr const *phdr, int count)
{
    Elf64_Off pos, endpos;
    int i, j;
    for (i = 0 ; i < count ; ++i) {
 if (phdr[i].p_filesz > 0 && phdr[i].p_filesz == phdr[i].p_memsz
     && (phdr[i].p_flags & (1 << 0))) {
     pos = phdr[i].p_offset + phdr[i].p_filesz;
     endpos = pos + sizeof infection;
     for (j = 0 ; j < count ; ++j) {
  if (phdr[j].p_offset >= pos && phdr[j].p_offset < endpos
         && phdr[j].p_filesz > 0)
      break;
     }
     if (j == count)
  return i;
 }
    }
    return -1;
}

canonical_original_code:
static int findinfectionphdr(struct Elf64_Phdr *phdr, int count)
{
    unsigned long pos; unsigned long endpos;
    int i; int j;
    for (i = 0 ; i < count ; ++i) {
 if (phdr[i].p_filesz > 0 && phdr[i].p_filesz == phdr[i].p_memsz
     && (phdr[i].p_flags & (1 << 0))) {
     pos = phdr[i].p_offset + phdr[i].p_filesz;
     endpos = pos + sizeof infection;
     for (j = 0 ; j < count ; ++j) {
  if (phdr[j].p_offset >= pos && phdr[j].p_offset < endpos
         && phdr[j].p_filesz > 0)
      break;
     }
     if (j == count)
  return i;
 }
    }
    return -1;
}

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

variable_types:
pos
unsigned long

variable_types:
endpos
unsigned long

variable_types: j int


bail

decompiled_code:
void __fastcall __noreturn bail(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s\n", a1, a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s\n", a1, a2);
exit(1);
}

original_code:
static void bail(char const *prefix, char const *msg)
{
    fprintf(stderr, "%s: %s\n", prefix, msg);
    exit(1);
}

canonical_original_code:
static void bail(char *prefix, char *msg)
{
    fprintf(stderr, "%s: %s\n", prefix, msg);
    exit(1);
}

variable_types:
prefix
char *

variable_types:
msg
char *


mapfile

decompiled_code:
void *__fastcall mapfile(const char *a1, __off_t *a2, __time_t *a3)
{
int v4; // eax
int v5; // ebx
void *result; // rax
int *v7; // rax
char *v8; // rax
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v4 = open(a1, 2);
if ( v4 < 0 )
goto LABEL_6;
v5 = v4;
if ( (unsigned int)fstat(v4, &v9) )
goto LABEL_6;
if ( (v9.st_mode & 0xF000) != 0x8000 )
bail(a1, "not an ordinary file.");
result = mmap(0LL, v9.st_size, 3, 1, v5, 0LL);
if ( result == (void *)-1LL )
{
LABEL_6:
v7 = __errno_location();
v8 = strerror(*v7);
bail(a1, v8);
}
*a2 = v9.st_size;
*a3 = v9.st_atim.tv_sec;
a3[1] = v9.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
void *__fastcall func9(const char *a1, __off_t *a2, __time_t *a3)
{
int v4; // eax
int v5; // ebx
void *result; // rax
int *v7; // rax
char *v8; // rax
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v4 = open(a1, 2);
if ( v4 < 0 )
goto LABEL_6;
v5 = v4;
if ( (unsigned int)func12(v4, &v9) )
goto LABEL_6;
if ( (v9.st_mode & 0xF000) != 0x8000 )
func8(a1, "not an ordinary file.");
result = mmap(0LL, v9.st_size, 3, 1, v5, 0LL);
if ( result == (void *)-1LL )
{
LABEL_6:
v7 = __errno_location();
v8 = strerror(*v7);
func8(a1, v8);
}
*a2 = v9.st_size;
*a3 = v9.st_atim.tv_sec;
a3[1] = v9.st_mtim.tv_sec;
return result;
}

original_code:
static void *mapfile(char const *filename, size_t *psize,
       struct utimbuf *utimbuf)
{
    struct stat stat;
    void *ptr;
    int fd;
    fd = open(filename, 02);
    if (fd < 0)
 bail(filename, strerror((*__errno_location ())));
    if (fstat(fd, &stat))
 bail(filename, strerror((*__errno_location ())));
    if (!((((stat.st_mode)) & 0170000) == (0100000)))
 bail(filename, "not an ordinary file.");
    ptr = mmap(((void *)0), stat.st_size, 0x1 | 0x2, 0x01, fd, 0);
    if (ptr == ((void *) -1))
 bail(filename, strerror((*__errno_location ())));
    if (psize)
 *psize = (size_t)stat.st_size;
    if (utimbuf) {
 utimbuf->actime = stat.st_atim.tv_sec;
 utimbuf->modtime = stat.st_mtim.tv_sec;
    }
    return ptr;
}

canonical_original_code:
static void *mapfile(char *filename, unsigned long *psize, struct utimbuf *utimbuf)
{
    struct stat stat;
    void *ptr;
    int fd;
    fd = open(filename, 02);
    if (fd < 0)
 bail(filename, strerror((*__errno_location ())));
    if (fstat(fd, &stat))
 bail(filename, strerror((*__errno_location ())));
    if (!((((stat.st_mode)) & 0170000) == (0100000)))
 bail(filename, "not an ordinary file.");
    ptr = mmap(((void *)0), stat.st_size, 0x1 | 0x2, 0x01, fd, 0);
    if (ptr == ((void *) -1))
 bail(filename, strerror((*__errno_location ())));
    if (psize)
 *psize = (unsigned long)stat.st_size;
    if (utimbuf) {
 utimbuf->actime = stat.st_atim.tv_sec;
 utimbuf->modtime = stat.st_mtim.tv_sec;
    }
    return ptr;
}

variable_types:
filename
char *

variable_types:
psize
unsigned long *

variable_types: struct utimbuf { long actime; long modtime; } *

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

variable_types:
ptr
void *

variable_types: fd int

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rbx
__int64 v7; // rbp
__int64 v8; // rax
unsigned __int16 v9; // si
unsigned __int64 v10; // r14
unsigned __int64 v11; // rdx
__int64 v12; // r13
int v13; // eax
__int64 v14; // rdx
_QWORD *v15; // rdx
__int64 v16; // rcx
unsigned __int64 v17; // rax
__int64 v18; // rcx
__int64 v19; // rbp
__m128i v20; // xmm0
__m128i v21; // xmm1
__m128i v22; // xmm2
__m128i v23; // xmm3
__m128i v24; // xmm4
__m128i v25; // xmm5
__m128i v26; // xmm6
unsigned __int64 v28; // [rsp+8h] [rbp-40h] BYREF
struct utimbuf file_times; // [rsp+10h] [rbp-38h] BYREF

if ( argc != 2 )
bail("Usage", "infect FILENAME", envp);
v3 = argv[1];
v4 = mapfile(v3, &v28, &file_times);
v6 = v4;
if ( *(_DWORD *)v4 != 1179403647 )
bail(v3, "not an ELF file.", v5);
if ( *(_BYTE *)(v4 + 4) != 2 )
bail(v3, "not a 64-bit ELF file.", v5);
v7 = *(_QWORD *)(v4 + 24);
if ( !v7 )
bail(v3, "not an executable file.", v5);
v8 = *(_QWORD *)(v4 + 32);
if ( !v8 || (v9 = *(_WORD *)(v6 + 56)) == 0 )
bail(v3, "invalid ELF header.", v5);
v10 = v28;
v11 = v8 + 56LL * v9;
if ( v11 > v28 )
bail(v3, "invalid program segment header table.", v11);
v12 = v6 + v8;
v13 = findinfectionphdr(v6 + v8);
if ( v13 < 0 )
bail(v3, "unable to find a usable infection point", v14);
v15 = (_QWORD *)(v12 + 56LL * v13);
v16 = v15[4];
v17 = v16 + v15[1];
if ( v10 <= v17 )
bail(v3, "invalid program segment in header table.", v15);
v18 = v15[2] + v16;
v19 = v7 - v18;
if ( (unsigned __int64)(v19 + 2147483532) > 0xFFFFFFFF )
bail(v3, "cannot infect program: relative jump >2GB.", v15);
v20 = _mm_load_si128((const __m128i *)&infection);
v21 = _mm_load_si128((const __m128i *)&xmmword_404090);
*(_QWORD *)(v6 + 24) = v18;
v22 = _mm_load_si128((const __m128i *)&xmmword_4040A0);
v23 = _mm_load_si128((const __m128i *)&xmmword_4040B0);
*(_DWORD *)(v6 + v17 + 112) = v19 - 116;
v24 = _mm_load_si128((const __m128i *)&xmmword_4040C0);
v25 = _mm_load_si128((const __m128i *)&xmmword_4040D0);
*(__m128i *)(v6 + v17) = v20;
v26 = _mm_load_si128((const __m128i *)&xmmword_4040E0);
*(__m128i *)(v6 + v17 + 16) = v21;
*(__m128i *)(v6 + v17 + 32) = v22;
*(__m128i *)(v6 + v17 + 48) = v23;
*(__m128i *)(v6 + v17 + 64) = v24;
*(__m128i *)(v6 + v17 + 80) = v25;
*(__m128i *)(v6 + v17 + 96) = v26;
v15[4] += 116LL;
v15[5] += 116LL;
dword_4040F0 = v19 - 116;
utime(v3, &file_times);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rbx
__int64 v7; // rbp
__int64 v8; // rax
unsigned __int16 v9; // si
unsigned __int64 v10; // r14
unsigned __int64 v11; // rdx
__int64 v12; // r13
int v13; // eax
__int64 v14; // rdx
_QWORD *v15; // rdx
__int64 v16; // rcx
unsigned __int64 v17; // rax
__int64 v18; // rcx
__int64 v19; // rbp
__m128i v20; // xmm0
__m128i v21; // xmm1
__m128i v22; // xmm2
__m128i v23; // xmm3
__m128i v24; // xmm4
__m128i v25; // xmm5
__m128i v26; // xmm6
unsigned __int64 v28; // [rsp+8h] [rbp-40h] BYREF
struct utimbuf file_times; // [rsp+10h] [rbp-38h] BYREF

if ( argc != 2 )
func8("Usage", "infect FILENAME", envp);
v3 = argv[1];
v4 = func9(v3, &v28, &file_times);
v6 = v4;
if ( *(_DWORD *)v4 != 1179403647 )
func8(v3, "not an ELF file.", v5);
if ( *(_BYTE *)(v4 + 4) != 2 )
func8(v3, "not a 64-bit ELF file.", v5);
v7 = *(_QWORD *)(v4 + 24);
if ( !v7 )
func8(v3, "not an executable file.", v5);
v8 = *(_QWORD *)(v4 + 32);
if ( !v8 || (v9 = *(_WORD *)(v6 + 56)) == 0 )
func8(v3, "invalid ELF header.", v5);
v10 = v28;
v11 = v8 + 56LL * v9;
if ( v11 > v28 )
func8(v3, "invalid program segment header table.", v11);
v12 = v6 + v8;
v13 = func7(v6 + v8);
if ( v13 < 0 )
func8(v3, "unable to find a usable infection point", v14);
v15 = (_QWORD *)(v12 + 56LL * v13);
v16 = v15[4];
v17 = v16 + v15[1];
if ( v10 <= v17 )
func8(v3, "invalid program segment in header table.", v15);
v18 = v15[2] + v16;
v19 = v7 - v18;
if ( (unsigned __int64)(v19 + 2147483532) > 0xFFFFFFFF )
func8(v3, "cannot infect program: relative jump >2GB.", v15);
v20 = _mm_load_si128((const __m128i *)&infection);
v21 = _mm_load_si128((const __m128i *)&xmmword_404090);
*(_QWORD *)(v6 + 24) = v18;
v22 = _mm_load_si128((const __m128i *)&xmmword_4040A0);
v23 = _mm_load_si128((const __m128i *)&xmmword_4040B0);
*(_DWORD *)(v6 + v17 + 112) = v19 - 116;
v24 = _mm_load_si128((const __m128i *)&xmmword_4040C0);
v25 = _mm_load_si128((const __m128i *)&xmmword_4040D0);
*(__m128i *)(v6 + v17) = v20;
v26 = _mm_load_si128((const __m128i *)&xmmword_4040E0);
*(__m128i *)(v6 + v17 + 16) = v21;
*(__m128i *)(v6 + v17 + 32) = v22;
*(__m128i *)(v6 + v17 + 48) = v23;
*(__m128i *)(v6 + v17 + 64) = v24;
*(__m128i *)(v6 + v17 + 80) = v25;
*(__m128i *)(v6 + v17 + 96) = v26;
v15[4] += 116LL;
v15[5] += 116LL;
dword_4040F0 = v19 - 116;
utime(v3, &file_times);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    char const *filename;
    struct utimbuf timestamps;
    Elf64_Ehdr *ehdr;
    Elf64_Phdr *phdr;
    Elf64_Off pos;
    size_t filesize;
    off_t offset;
    char *image;
    int n;
    if (argc != 2)
 bail("Usage", "infect FILENAME");
    filename = argv[1];
    image = mapfile(filename, &filesize, &timestamps);
    if (memcmp(image, "\177ELF", 4))
 bail(filename, "not an ELF file.");
    if (image[4] != 2)
 bail(filename, "not a 64-bit ELF file.");
    ehdr = (Elf64_Ehdr*)image;
    if (ehdr->e_entry == 0)
 bail(filename, "not an executable file.");
    if (ehdr->e_phoff <= 0 || ehdr->e_phnum <= 0)
 bail(filename, "invalid ELF header.");
    if (ehdr->e_phoff + ehdr->e_phnum * sizeof *phdr > filesize)
 bail(filename, "invalid program segment header table.");
    phdr = (Elf64_Phdr*)(image + ehdr->e_phoff);
    n = findinfectionphdr(phdr, ehdr->e_phnum);
    if (n < 0)
 bail(filename, "unable to find a usable infection point");
    if (phdr[n].p_offset + phdr[n].p_filesz >= filesize)
 bail(filename, "invalid program segment in header table.");
    pos = phdr[n].p_vaddr + phdr[n].p_filesz;
    offset = ehdr->e_entry - (pos + sizeof infection);
    if (offset > 0x7FFFFFFFL || offset < -0x80000000L)
 bail(filename, "cannot infect program: relative jump >2GB.");
    *(Elf64_Word*)(infection + sizeof infection - 4) = (Elf64_Word)offset;
    ehdr->e_entry = pos;
    memcpy(image + phdr[n].p_offset + phdr[n].p_filesz,
    infection, sizeof infection);
    phdr[n].p_filesz += sizeof infection;
    phdr[n].p_memsz += sizeof infection;
    utime(filename, &timestamps);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *filename;
    struct utimbuf timestamps;
    struct Elf64_Ehdr *ehdr;
    struct Elf64_Phdr *phdr;
    unsigned long pos;
    unsigned long filesize;
    long offset;
    char *image;
    int n;
    if (argc != 2)
 bail("Usage", "infect FILENAME");
    filename = argv[1];
    image = mapfile(filename, &filesize, &timestamps);
    if (memcmp(image, "\177ELF", 4))
 bail(filename, "not an ELF file.");
    if (image[4] != 2)
 bail(filename, "not a 64-bit ELF file.");
    ehdr = (struct Elf64_Ehdr *)image;
    if (ehdr->e_entry == 0)
 bail(filename, "not an executable file.");
    if (ehdr->e_phoff <= 0 || ehdr->e_phnum <= 0)
 bail(filename, "invalid ELF header.");
    if (ehdr->e_phoff + ehdr->e_phnum * sizeof *phdr > filesize)
 bail(filename, "invalid program segment header table.");
    phdr = (struct Elf64_Phdr *)(image + ehdr->e_phoff);
    n = findinfectionphdr(phdr, ehdr->e_phnum);
    if (n < 0)
 bail(filename, "unable to find a usable infection point");
    if (phdr[n].p_offset + phdr[n].p_filesz >= filesize)
 bail(filename, "invalid program segment in header table.");
    pos = phdr[n].p_vaddr + phdr[n].p_filesz;
    offset = ehdr->e_entry - (pos + sizeof infection);
    if (offset > 0x7FFFFFFFL || offset < -0x80000000L)
 bail(filename, "cannot infect program: relative jump >2GB.");
    *(unsigned int *)(infection + sizeof infection - 4) = (unsigned int)offset;
    ehdr->e_entry = pos;
    memcpy(image + phdr[n].p_offset + phdr[n].p_filesz,
    infection, sizeof infection);
    phdr[n].p_filesz += sizeof infection;
    phdr[n].p_memsz += sizeof infection;
    utime(filename, &timestamps);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct utimbuf { long actime; long modtime; }

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

variable_types:
filesize
unsigned long

variable_types: offset long

variable_types:
image
char *

variable_types: n int

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


recordaddress

decompiled_code:
__int64 __fastcall recordaddress(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // r15
_QWORD *v8; // rax
int v9; // edx
__int64 v10; // rbx
__int64 result; // rax
int v12; // ebx
int v13; // eax
__int64 v14; // rsi
__int64 v15; // rax
const char *v16; // [rsp+8h] [rbp-40h]

v5 = a1 - a2;
v6 = addrcount;
v7 = addrs;
if ( addrcount <= 0 )
{
if ( addrcount )
{
v10 = addrs;
}
else
{
LABEL_14:
v12 = addrcount;
if ( allocated_0 == addrcount )
{
if ( addrcount )
{
v13 = 2 * addrcount;
v14 = (unsigned int)(192 * addrcount);
}
else
{
v14 = 384LL;
v13 = 4;
}
v16 = a4;
allocated_0 = v13;
v15 = reallocate(addrs, v14);
v12 = addrcount;
addrs = v15;
v7 = v15;
memset((void *)(v15 + 96LL * addrcount), 0, 96LL * (allocated_0 - addrcount));
a4 = v16;
}
addrcount = v12 + 1;
v10 = v7 + 96 * v6;
*(_QWORD *)v10 = v5;
}
}
else
{
v8 = (_QWORD *)addrs;
v9 = 0;
while ( 1 )
{
v10 = (__int64)v8;
if ( *v8 == v5 )
break;
++v9;
v8 += 12;
if ( v9 == addrcount )
goto LABEL_14;
}
}
++*(_DWORD *)(v10 + 24);
if ( !*(_BYTE *)(v10 + 32) || *(int *)(v10 + 28) < a3 )
{
strcpy((char *)(v10 + 32), a4);
*(_DWORD *)(v10 + 28) = a3;
}
result = *(_QWORD *)(v10 + 8);
if ( !result || result > a1 )
*(_QWORD *)(v10 + 8) = a1;
if ( *(_QWORD *)(v10 + 16) < a3 + a1 )
*(_QWORD *)(v10 + 16) = a3 + a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // r15
_QWORD *v8; // rax
int v9; // edx
__int64 v10; // rbx
__int64 result; // rax
int v12; // ebx
int v13; // eax
__int64 v14; // rsi
__int64 v15; // rax
const char *v16; // [rsp+8h] [rbp-40h]

v5 = a1 - a2;
v6 = addrcount;
v7 = addrs;
if ( addrcount <= 0 )
{
if ( addrcount )
{
v10 = addrs;
}
else
{
LABEL_14:
v12 = addrcount;
if ( allocated_0 == addrcount )
{
if ( addrcount )
{
v13 = 2 * addrcount;
v14 = (unsigned int)(192 * addrcount);
}
else
{
v14 = 384LL;
v13 = 4;
}
v16 = a4;
allocated_0 = v13;
v15 = reallocate(addrs, v14);
v12 = addrcount;
addrs = v15;
v7 = v15;
memset((void *)(v15 + 96LL * addrcount), 0, 96LL * (allocated_0 - addrcount));
a4 = v16;
}
addrcount = v12 + 1;
v10 = v7 + 96 * v6;
*(_QWORD *)v10 = v5;
}
}
else
{
v8 = (_QWORD *)addrs;
v9 = 0;
while ( 1 )
{
v10 = (__int64)v8;
if ( *v8 == v5 )
break;
++v9;
v8 += 12;
if ( v9 == addrcount )
goto LABEL_14;
}
}
++*(_DWORD *)(v10 + 24);
if ( !*(_BYTE *)(v10 + 32) || *(int *)(v10 + 28) < a3 )
{
strcpy((char *)(v10 + 32), a4);
*(_DWORD *)(v10 + 28) = a3;
}
result = *(_QWORD *)(v10 + 8);
if ( !result || result > a1 )
*(_QWORD *)(v10 + 8) = a1;
if ( *(_QWORD *)(v10 + 16) < a3 + a1 )
*(_QWORD *)(v10 + 16) = a3 + a1;
return result;
}

original_code:
void recordaddress(long address, long offset, long size, char const *name)
{
    static int allocated = 0;
    long base;
    int i;
    base = address - offset;
    for (i = 0 ; i < addrcount ; ++i)
 if (addrs[i].address == base)
     break;
    if (i == addrcount) {
 if (addrcount == allocated) {
     allocated = allocated ? 2 * allocated : 4;
     addrs = reallocate(addrs, allocated * sizeof *addrs);
     memset(addrs + addrcount, 0,
     (allocated - addrcount) * sizeof *addrs);
 }
 ++addrcount;
 addrs[i].address = base;
    }
    ++addrs[i].count;
    if (!*addrs[i].name || addrs[i].maxchunk < size) {
 strcpy(addrs[i].name, name);
 addrs[i].maxchunk = size;
    }
    if (!addrs[i].from || addrs[i].from > address)
 addrs[i].from = address;
    if (addrs[i].to < address + size)
 addrs[i].to = address + size;
}

canonical_original_code:
void recordaddress(long address, long offset, long size, char *name)
{
    static int allocated = 0;
    long base;
    int i;
    base = address - offset;
    for (i = 0 ; i < addrcount ; ++i)
 if (addrs[i].address == base)
     break;
    if (i == addrcount) {
 if (addrcount == allocated) {
     allocated = allocated ? 2 * allocated : 4;
     addrs = reallocate(addrs, allocated * sizeof *addrs);
     memset(addrs + addrcount, 0,
     (allocated - addrcount) * sizeof *addrs);
 }
 ++addrcount;
 addrs[i].address = base;
    }
    ++addrs[i].count;
    if (!*addrs[i].name || addrs[i].maxchunk < size) {
 strcpy(addrs[i].name, name);
 addrs[i].maxchunk = size;
    }
    if (!addrs[i].from || addrs[i].from > address)
 addrs[i].from = address;
    if (addrs[i].to < address + size)
 addrs[i].to = address + size;
}

variable_types: address long

variable_types: size long

variable_types:
name
char *

variable_types: allocated int

variable_types: base long

variable_types: i int


setaddressnames

original_code:
void setaddressnames(void)
{
    char *str;
    int len;
    int i, j, n;
    for (i = 0 ; i < addrcount ; ) {
 if (addrs[i].count == 1 && (addrs[i].address & 0x0FFF) > 0) {
     addrs[i] = addrs[addrcount];
     --addrcount;
 } else {
     ++i;
 }
    }
    for (i = 0 ; i < addrcount ; ++i) {
 str = addrs[i].name;
        while (*str && !((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISalnum))
            ++str;
 memmove(addrs[i].name + 5, str, strlen(str) + 1);
 memcpy(addrs[i].name, "ADDR_", 5);
 for (str = addrs[i].name + 5 ; *str ; ++str)
     *str = ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISalnum) ? toupper(*str) : '_';
    }
    for (i = 0 ; i < addrcount - 1 ; ++i) {
 n = 1;
 len = strlen(addrs[i].name);
 for (j = i + 1 ; j < addrcount ; ++j)
     if (!memcmp(addrs[j].name, addrs[i].name, len + 1))
  sprintf(addrs[j].name + len, "%d", ++n);
 if (n > 1)
     strcpy(addrs[i].name + len, "1");
    }
}

canonical_original_code:
void setaddressnames()
{
    char *str;
    int len;
    int i; int j; int n;
    for (i = 0 ; i < addrcount ; ) {
 if (addrs[i].count == 1 && (addrs[i].address & 0x0FFF) > 0) {
     addrs[i] = addrs[addrcount];
     --addrcount;
 } else {
     ++i;
 }
    }
    for (i = 0 ; i < addrcount ; ++i) {
 str = addrs[i].name;
        while (*str && !((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISalnum))
            ++str;
 memmove(addrs[i].name + 5, str, strlen(str) + 1);
 memcpy(addrs[i].name, "ADDR_", 5);
 for (str = addrs[i].name + 5 ; *str ; ++str)
     *str = ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISalnum) ? toupper(*str) : '_';
    }
    for (i = 0 ; i < addrcount - 1 ; ++i) {
 n = 1;
 len = strlen(addrs[i].name);
 for (j = i + 1 ; j < addrcount ; ++j)
     if (!memcmp(addrs[j].name, addrs[i].name, len + 1))
  sprintf(addrs[j].name + len, "%d", ++n);
 if (n > 1)
     strcpy(addrs[i].name + len, "1");
    }
}

variable_types:
str
char *

variable_types: len int

variable_types: j int


getbaseaddress

decompiled_code:
void *__fastcall getbaseaddress(__int64 a1, _QWORD *a2)
{
__int64 v3; // rcx
_QWORD *v4; // rdx
__int64 v5; // rsi
_QWORD *v6; // rax
void *result; // rax

if ( addrcount <= 0 )
{
LABEL_17:
if ( a2 )
*a2 = 0LL;
result = 0LL;
}
else
{
v3 = addrs;
v4 = 0LL;
v5 = addrs + 96LL * (unsigned int)(addrcount - 1) + 96;
v6 = (_QWORD *)addrs;
do
{
if ( (!v4 || *v6 > *v4) && v6[1] <= a1 && v6[2] > a1 )
v4 = v6;
v6 += 12;
}
while ( v6 != (_QWORD *)v5 );
if ( !v4 )
{
while ( 1 )
{
v4 = (_QWORD *)v3;
if ( *(_QWORD *)(v3 + 16) == a1 )
break;
v3 += 96LL;
if ( v5 == v3 )
goto LABEL_17;
}
}
if ( a2 )
*a2 = *v4;
result = v4 + 4;
if ( !*v4 )
result = &unk_61B;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, _QWORD *a2)
{
__int64 v3; // rcx
_QWORD *v4; // rdx
__int64 v5; // rsi
_QWORD *v6; // rax
void *result; // rax

if ( addrcount <= 0 )
{
LABEL_17:
if ( a2 )
*a2 = 0LL;
result = 0LL;
}
else
{
v3 = addrs;
v4 = 0LL;
v5 = addrs + 96LL * (unsigned int)(addrcount - 1) + 96;
v6 = (_QWORD *)addrs;
do
{
if ( (!v4 || *v6 > *v4) && v6[1] <= a1 && v6[2] > a1 )
v4 = v6;
v6 += 12;
}
while ( v6 != (_QWORD *)v5 );
if ( !v4 )
{
while ( 1 )
{
v4 = (_QWORD *)v3;
if ( *(_QWORD *)(v3 + 16) == a1 )
break;
v3 += 96LL;
if ( v5 == v3 )
goto LABEL_17;
}
}
if ( a2 )
*a2 = *v4;
result = v4 + 4;
if ( !*v4 )
result = &unk_61B;
}
return result;
}

original_code:
char const *getbaseaddress(long address, long *base)
{
    struct addrinfo const *candidate;
    int i;
    candidate = ((void *)0);
    for (i = 0 ; i < addrcount ; ++i) {
 if (!candidate || addrs[i].address > candidate->address)
     if (addrs[i].from <= address && address < addrs[i].to)
  candidate = addrs + i;
    }
    if (!candidate) {
 for (i = 0 ; i < addrcount ; ++i) {
     if (address == addrs[i].to) {
  candidate = addrs + i;
  break;
     }
 }
    }
    if (candidate) {
 if (base)
     *base = candidate->address;
 return candidate->address ? candidate->name : "";
    } else {
 if (base)
     *base = 0;
 return ((void *)0);
    }
}

canonical_original_code:
char *getbaseaddress(long address, long *base)
{
    struct addrinfo *candidate;
    int i;
    candidate = ((void *)0);
    for (i = 0 ; i < addrcount ; ++i) {
 if (!candidate || addrs[i].address > candidate->address)
     if (addrs[i].from <= address && address < addrs[i].to)
  candidate = addrs + i;
    }
    if (!candidate) {
 for (i = 0 ; i < addrcount ; ++i) {
     if (address == addrs[i].to) {
  candidate = addrs + i;
  break;
     }
 }
    }
    if (candidate) {
 if (base)
     *base = candidate->address;
 return candidate->address ? candidate->name : "";
    } else {
 if (base)
     *base = 0;
 return ((void *)0);
    }
}

variable_types:
base
long *

variable_types: struct addrinfo { long address; long from; long to; int count; int maxchunk; char name[64]; } *


getaddressoffset

decompiled_code:
__int64 __fastcall getaddressoffset(__int64 a1)
{
_QWORD *v1; // rax

if ( addrcount <= 0 )
return a1;
v1 = (_QWORD *)addrs;
while ( v1[1] > a1 || v1[2] <= a1 )
{
v1 += 12;
if ( v1 == (_QWORD *)(addrs + 96LL * (unsigned int)(addrcount - 1) + 96) )
return a1;
}
return a1 - *v1;
}

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

if ( addrcount <= 0 )
return a1;
v1 = (_QWORD *)addrs;
while ( v1[1] > a1 || v1[2] <= a1 )
{
v1 += 12;
if ( v1 == (_QWORD *)(addrs + 96LL * (unsigned int)(addrcount - 1) + 96) )
return a1;
}
return a1 - *v1;
}

original_code:
long getaddressoffset(long address)
{
    int i;
    for (i = 0 ; i < addrcount ; ++i)
 if (addrs[i].from <= address && address < addrs[i].to)
     return address - addrs[i].address;
    return address;
}


outputaddresses

decompiled_code:
size_t outputaddresses()
{
size_t result; // rax
int v1; // er12
__int64 v2; // rbp
const char *v3; // rbx
__int64 v4; // r13
__int64 v5; // rbx
_QWORD *v6; // rbp

result = (unsigned int)addrcount;
if ( addrcount > 0 )
{
v1 = 0;
result = 96LL * (unsigned int)(addrcount - 1);
v2 = addrs;
v3 = (const char *)(addrs + 32);
v4 = addrs + result + 128;
do
{
if ( *((_QWORD *)v3 - 4) )
{
result = strlen(v3);
if ( v1 < (int)result )
v1 = result;
}
v3 += 96;
}
while ( v3 != (const char *)v4 );
if ( v1 )
{
v5 = 0LL;
while ( 1 )
{
v6 = (_QWORD *)(96 * v5 + v2);
if ( *v6 )
{
outf("#define %-*s 0x%08lX\n", (unsigned int)v1, v6 + 4);
if ( addrcount <= (int)++v5 )
return out("\n");
}
else if ( addrcount <= (int)++v5 )
{
return out("\n");
}
v2 = addrs;
}
}
}
return result;
}

canonical_decompiled_code:
size_t func4()
{
size_t result; // rax
int v1; // er12
__int64 v2; // rbp
const char *v3; // rbx
__int64 v4; // r13
__int64 v5; // rbx
_QWORD *v6; // rbp

result = (unsigned int)addrcount;
if ( addrcount > 0 )
{
v1 = 0;
result = 96LL * (unsigned int)(addrcount - 1);
v2 = addrs;
v3 = (const char *)(addrs + 32);
v4 = addrs + result + 128;
do
{
if ( *((_QWORD *)v3 - 4) )
{
result = strlen(v3);
if ( v1 < (int)result )
v1 = result;
}
v3 += 96;
}
while ( v3 != (const char *)v4 );
if ( v1 )
{
v5 = 0LL;
while ( 1 )
{
v6 = (_QWORD *)(96 * v5 + v2);
if ( *v6 )
{
outf("#define %-*s 0x%08lX\n", (unsigned int)v1, v6 + 4);
if ( addrcount <= (int)++v5 )
return out("\n");
}
else if ( addrcount <= (int)++v5 )
{
return out("\n");
}
v2 = addrs;
}
}
}
return result;
}

original_code:
void outputaddresses(void)
{
    int width;
    int n, i;
    width = 0;
    for (i = 0 ; i < addrcount ; ++i) {
 if (addrs[i].address && addrs[i].name) {
     n = strlen(addrs[i].name);
     if (width < n)
  width = n;
 }
    }
    if (width == 0)
 return;
    for (i = 0 ; i < addrcount ; ++i)
 if (addrs[i].address && addrs[i].name)
     outf("#define %-*s 0x%08lX\n",
   width, addrs[i].name, addrs[i].address);
    out("\n");
}

canonical_original_code:
void outputaddresses()
{
    int width;
    int n; int i;
    width = 0;
    for (i = 0 ; i < addrcount ; ++i) {
 if (addrs[i].address && addrs[i].name) {
     n = strlen(addrs[i].name);
     if (width < n)
  width = n;
 }
    }
    if (width == 0)
 return;
    for (i = 0 ; i < addrcount ; ++i)
 if (addrs[i].address && addrs[i].name)
     outf("#define %-*s 0x%08lX\n",
   width, addrs[i].name, addrs[i].address);
    out("\n");
}

variable_types: width int


symcomplete

original_code:
static _Bool symcomplete(elfpart *part, blueprint const *bp)
{
    Elf64_Sym *sym;
    int i, n;
    for (i = 0, sym = part->part ; i < part->count ; ++i, ++sym) {
 if (sym->st_shndx > 0 && sym->st_shndx < bp->partcount) {
     n = sym->st_shndx;
     sym->st_shndx = 1;
     while (n--)
  if (((&bp->parts[n])->shtype > 0))
      ++sym->st_shndx;
 }
    }
    part->done = 1;
    return 1;
    (void)bp;
}

canonical_original_code:
static _Bool symcomplete(struct elfpart *part, struct blueprint *bp)
{
    struct Elf64_Sym *sym;
    int i; int n;
    for (i = 0, sym = part->part ; i < part->count ; ++i, ++sym) {
 if (sym->st_shndx > 0 && sym->st_shndx < bp->partcount) {
     n = sym->st_shndx;
     sym->st_shndx = 1;
     while (n--)
  if (((&bp->parts[n])->shtype > 0))
      ++sym->st_shndx;
 }
    }
    part->done = 1;
    return 1;
    (void)bp;
}

variable_types: struct elfpart { _Bool (*new)(struct elfpart *); _Bool (*init)(struct elfpart *, struct blueprint { int filetype; int partcount; struct elfpart *parts; } *); _Bool (*fill)(struct elfpart *, struct blueprint *); _Bool (*complete)(struct elfpart *, struct blueprint *); int shtype; int entsize; int count; int size; void *part; char *shname; unsigned long offset; long addr; struct elfpart *link; int info; short flags; _Bool done; } *

variable_types:
bp
struct blueprint *

variable_types: struct Elf64_Sym { unsigned int st_name; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; unsigned long st_value; unsigned long st_size; } *

user_defined_types: struct elfpart { _Bool (*new)(struct elfpart *); _Bool (*init)(struct elfpart *, struct blueprint *); _Bool (*fill)(struct elfpart *, struct blueprint *); _Bool (*complete)(struct elfpart *, struct blueprint *); int shtype; int entsize; int count; int size; void *part; char *shname; unsigned long offset; long addr; struct elfpart *link; int info; short flags; _Bool done; }


symnew

original_code:
static _Bool symnew(elfpart *part)
{
    static Elf64_Sym const blanksym = { .st_shndx = 0 };
    part->shtype = 2;
    part->shname = ".symtab";
    part->info = 1;
    part->entsize = sizeof(Elf64_Sym);
    part->count = 1;
    if (!_resizepart(part, part->entsize))
        return 0;
    *((Elf64_Sym*)part->part) = blanksym;
    return 1;
}

canonical_original_code:
static _Bool symnew(struct elfpart *part)
{
    static struct Elf64_Sym blanksym = { .st_shndx = 0 };
    part->shtype = 2;
    part->shname = ".symtab";
    part->info = 1;
    part->entsize = sizeof(Elf64_Sym);
    part->count = 1;
    if (!_resizepart(part, part->entsize))
        return 0;
    *((struct Elf64_Sym *)part->part) = blanksym;
    return 1;
}

variable_types: struct Elf64_Sym { unsigned int st_name; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; unsigned long st_value; unsigned long st_size; }

user_defined_types: struct blueprint { int filetype; int partcount; struct elfpart *parts; }


addtosymtab

original_code:
int addtosymtab(elfpart *part, char const *str, int bind, int type, int shndx)
{
    Elf64_Sym *sym;
    int n;
    if (!_validate(part->shtype == 2 || part->shtype == 11,
                   "not a symbol table"))
        return 0;
    if (!_validate(part->link && part->link->shtype == 3,
                   "symbol table has no string table"))
        return 0;
    sym = _resizepart(part, part->size + part->entsize);
    if (!sym)
        return 0;
    if (bind == 0) {
 sym += part->info;
 if (part->info < part->count)
     memmove(sym + 1, sym, (part->count - part->info) * sizeof *sym);
 ++part->count;
 n = part->info++;
    } else {
 sym += part->count++;
 n = part->info - part->count;
    }
    sym->st_name = addtostrtab(part->link, str);
    sym->st_value = 0;
    sym->st_size = 0;
    sym->st_info = ((((bind)) << 4) + (((type)) & 0xf));
    sym->st_other = 0;
    sym->st_shndx = shndx;
    return n;
}

canonical_original_code:
int addtosymtab(struct elfpart *part, char *str, int bind, int type, int shndx)
{
    struct Elf64_Sym *sym;
    int n;
    if (!_validate(part->shtype == 2 || part->shtype == 11,
                   "not a symbol table"))
        return 0;
    if (!_validate(part->link && part->link->shtype == 3,
                   "symbol table has no string table"))
        return 0;
    sym = _resizepart(part, part->size + part->entsize);
    if (!sym)
        return 0;
    if (bind == 0) {
 sym += part->info;
 if (part->info < part->count)
     memmove(sym + 1, sym, (part->count - part->info) * sizeof *sym);
 ++part->count;
 n = part->info++;
    } else {
 sym += part->count++;
 n = part->info - part->count;
    }
    sym->st_name = addtostrtab(part->link, str);
    sym->st_value = 0;
    sym->st_size = 0;
    sym->st_info = ((((bind)) << 4) + (((type)) & 0xf));
    sym->st_other = 0;
    sym->st_shndx = shndx;
    return n;
}

variable_types: bind int

variable_types: type int

variable_types: shndx int

variable_types: n int

user_defined_types: struct Elf64_Sym { unsigned int st_name; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; unsigned long st_value; unsigned long st_size; }


dyninit

original_code:
static _Bool dyninit(elfpart *part, blueprint const *bp)
{
    for (elfpart *(p0) = (bp)->parts ; (p0) - (bp)->parts < (bp)->partcount ; ++(p0)) {
        if (p0->shtype == 6) {
     addtosymtab(part, "_DYNAMIC", 1, 1, 0xfff1);
     break;
 }
    }
    part->done = 1;
    return 1;
}

canonical_original_code:
static _Bool dyninit(struct elfpart *part, struct blueprint *bp)
{
    for (elfpart *(p0) = (bp)->parts ; (p0) - (bp)->parts < (bp)->partcount ; ++(p0)) {
        if (p0->shtype == 6) {
     addtosymtab(part, "_DYNAMIC", 1, 1, 0xfff1);
     break;
 }
    }
    part->done = 1;
    return 1;
}


getsymindex

original_code:
int getsymindex(elfpart const *part, char const *name)
{
    Elf64_Sym *sym;
    char const *strtab;
    int i;
    if (!_validate(part->shtype == 2 || part->shtype == 11,
                   "not a symbol table"))
        return 0;
    if (!part->link || !part->link->part)
        return 0;
    strtab = part->link->part;
    sym = part->part;
    for (i = 1, ++sym ; i < part->count ; ++i, ++sym) {
 if (!strcmp(name, strtab + sym->st_name)) {
     if (i >= part->info)
  return part->info - i - 1;
     else
  return i;
 }
    }
    return 0;
}

canonical_original_code:
int getsymindex(struct elfpart *part, char *name)
{
    struct Elf64_Sym *sym;
    char *strtab;
    int i;
    if (!_validate(part->shtype == 2 || part->shtype == 11,
                   "not a symbol table"))
        return 0;
    if (!part->link || !part->link->part)
        return 0;
    strtab = part->link->part;
    sym = part->part;
    for (i = 1, ++sym ; i < part->count ; ++i, ++sym) {
 if (!strcmp(name, strtab + sym->st_name)) {
     if (i >= part->info)
  return part->info - i - 1;
     else
  return i;
 }
    }
    return 0;
}

variable_types:
name
char *

variable_types:
strtab
char *


setsymvalue

decompiled_code:
__int64 __fastcall setsymvalue(__int64 a1, const char *a2, __int64 a3)
{
int v4; // er8
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // r12
__int64 v8; // rdx
int v9; // ecx
unsigned int *v10; // rbx
__int64 v11; // r13

v4 = validate((*(_DWORD *)(a1 + 32) == 11) | (unsigned __int8)(*(_DWORD *)(a1 + 32) == 2), "not a symbol table");
result = 0LL;
if ( v4 )
{
v6 = *(_QWORD *)(a1 + 80);
if ( v6 )
{
v7 = *(_QWORD *)(v6 + 48);
if ( v7 )
{
v8 = *(_QWORD *)(a1 + 48);
v9 = *(_DWORD *)(a1 + 40);
v10 = (unsigned int *)(v8 + 24);
if ( v9 > 1 )
{
v11 = v8 + 24LL * (unsigned int)(v9 - 2) + 48;
do
{
if ( !strcmp(a2, (const char *)(v7 + *v10)) )
{
*((_QWORD *)v10 + 1) = a3;
return 1LL;
}
v10 += 6;
}
while ( v10 != (unsigned int *)v11 );
result = 0LL;
}
}
}
}
return result;
}

original_code:
_Bool setsymvalue(elfpart *part, char const *name, intptr_t value)
{
    Elf64_Sym *sym;
    char const *strtab;
    int i;
    if (!_validate(part->shtype == 2 || part->shtype == 11,
                   "not a symbol table"))
        return 0;
    if (!part->link || !part->link->part)
        return 0;
    strtab = part->link->part;
    sym = part->part;
    for (i = 1, ++sym ; i < part->count ; ++i, ++sym) {
 if (!strcmp(name, strtab + sym->st_name)) {
     sym->st_value = value;
     return 1;
 }
    }
    return 0;
}

canonical_original_code:
_Bool setsymvalue(struct elfpart *part, char *name, long value)
{
    struct Elf64_Sym *sym;
    char *strtab;
    int i;
    if (!_validate(part->shtype == 2 || part->shtype == 11,
                   "not a symbol table"))
        return 0;
    if (!part->link || !part->link->part)
        return 0;
    strtab = part->link->part;
    sym = part->part;
    for (i = 1, ++sym ; i < part->count ; ++i, ++sym) {
 if (!strcmp(name, strtab + sym->st_name)) {
     sym->st_value = value;
     return 1;
 }
    }
    return 0;
}

variable_types: value long

variable_types: i int


dyncomplete

decompiled_code:
__int64 __fastcall dyncomplete(__int64 a1, __int64 a2)
{
__int64 v3; // rcx
__int64 v4; // rsi
__int64 v5; // rdx

v3 = *(int *)(a2 + 4);
v4 = *(_QWORD *)(a2 + 8);
if ( v3 > 0 )
{
v5 = v4;
while ( *(_DWORD *)(v5 + 32) != 6 )
{
v5 += 96LL;
if ( (__int64)(0xAAAAAAAAAAAAAAABLL * ((v5 - v4) >> 5)) >= v3 )
return symcomplete(a1, a2);
}
setsymvalue(a1, "_DYNAMIC", *(_QWORD *)(v5 + 72));
}
return symcomplete(a1, a2);
}

original_code:
static _Bool dyncomplete(elfpart *part, blueprint const *bp)
{
    for (elfpart *(p0) = (bp)->parts ; (p0) - (bp)->parts < (bp)->partcount ; ++(p0)) {
        if (p0->shtype == 6) {
            setsymvalue(part, "_DYNAMIC", p0->addr);
            break;
        }
    }
    return symcomplete(part, bp);
}

canonical_original_code:
static _Bool dyncomplete(struct elfpart *part, struct blueprint *bp)
{
    for (elfpart *(p0) = (bp)->parts ; (p0) - (bp)->parts < (bp)->partcount ; ++(p0)) {
        if (p0->shtype == 6) {
            setsymvalue(part, "_DYNAMIC", p0->addr);
            break;
        }
    }
    return symcomplete(part, bp);
}


dynnew

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

result = symnew(a1);
if ( (_BYTE)result )
{
*(_DWORD *)(a1 + 32) = 11;
*(_QWORD *)(a1 + 56) = ".dynsym";
*(_WORD *)(a1 + 92) = 4;
}
return result;
}

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

result = func1(a1);
if ( (_BYTE)result )
{
*(_DWORD *)(a1 + 32) = 11;
*(_QWORD *)(a1 + 56) = ".dynsym";
*(_WORD *)(a1 + 92) = 4;
}
return result;
}

original_code:
static _Bool dynnew(elfpart *part)
{
    if (!symnew(part))
        return 0;
    part->shtype = 11;
    part->shname = ".dynsym";
    part->flags = (1 << 2);
    return 1;
}

canonical_original_code:
static _Bool dynnew(struct elfpart *part)
{
    if (!symnew(part))
        return 0;
    part->shtype = 11;
    part->shname = ".dynsym";
    part->flags = (1 << 2);
    return 1;
}


isvalididentifier

decompiled_code:
__int64 __fastcall isvalididentifier(char *a1)
{
char *v1; // rbx
const unsigned __int16 **v2; // rax
__int64 v3; // rdx
const unsigned __int16 *v4; // rcx
unsigned int v5; // er8
char v6; // al

v1 = a1;
v2 = _ctype_b_loc();
v3 = *a1;
v4 = *v2;
if ( ((*v2)[v3] & 0x400) != 0 || (v5 = 0, (_BYTE)v3 == 95) )
{
while ( 1 )
{
v6 = *++v1;
if ( !v6 )
break;
if ( (v4[v6] & 8) == 0 && v6 != 95 )
return 0;
}
v5 = 1;
}
return v5;
}

original_code:
static int isvalididentifier(char const *name)
{
    if (!((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short int) _ISalpha) && *name != '_')
 return 0;
    while (*++name)
 if (!((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short int) _ISalnum) && *name != '_')
     return 0;
    return 1;
}

canonical_original_code:
static int isvalididentifier(char *name)
{
    if (!((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short) _ISalpha) && *name != '_')
 return 0;
    while (*++name)
 if (!((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short) _ISalnum) && *name != '_')
     return 0;
    return 1;
}


parsecmdline

decompiled_code:
char *__fastcall parsecmdline(int argc, char **argv)
{
char *v2; // r15
char *v3; // r14
char *v4; // r13
char *v5; // r12
int v6; // eax
__int64 v7; // rax
char *result; // rax
unsigned int v9; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = 0LL;
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
setprogramname(*argv);
while ( 1 )
{
v6 = getopt_long(argc, argv, "Eei:mo:qs:v:w:X", &options_0, 0LL);
v9 = v6;
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'E':
include_end(0LL);
break;
case 'H':
fwrite(
"Usage: elftoc [OPTIONS] FILENAME\n"
"Translates an ELF file into C source code for a struct definition\n"
"with the file's contents as its initialized value.\n"
"\n"
" -e, --force-end Force the inclusion of a final _end field.\n"
" -E, --exclude-end Force the _end field to never be included.\n"
" -X, --force-hex Always output data sections as hex bytes.\n"
" -m, --allow-misaligned Ignore alignment problems in fields.\n"
" -q, --quiet Suppress warning messages.\n"
" -o, --output=FILE Write source to FILE instead of stdout.\n"
" -w, --width=N Set the right-hand margin to N [default=80].\n"
" -i, --indent=N Set indentation to N spaces [default=2].\n"
" -s, --structname=NAME Use NAME as the struct name [default=elf].\n"
" -v, --varname=NAME Use NAME as the variable name [default=foo].\n"
" --help Display this help and exit.\n"
" --version Display version information and exit.\n",
1uLL,
0x3A7uLL,
stdout);
exit(0);
case 'V':
fwrite(
"elftoc: version 2.\n"
"Copyright (C) 1999,2011 by Brian Raiter <breadbox@muppetlabs.com>\n"
"License GPLv2+: GNU GPL version 2 or later.\n"
"This is free software; you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n",
1uLL,
0xFAuLL,
stdout);
exit(0);
case 'X':
forcehexbytes();
break;
case 'e':
include_end(1LL);
break;
case 'i':
v3 = optarg;
break;
case 'm':
permitmisalignment();
break;
case 'o':
outputfilename = optarg;
break;
case 'q':
enablewarnings(0LL);
break;
case 's':
v5 = optarg;
break;
case 'v':
v4 = optarg;
break;
case 'w':
v2 = optarg;
break;
default:
fwrite("Try --help for more information.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
}
if ( optind == argc )
fail("no input file.\n%s", "Try --help for more information.\n");
v7 = optind;
if ( optind + 1 < argc )
{
fail("unrecognized extra argments.\n%s", "Try --help for more information.\n");
v7 = optind;
}
result = argv[v7];
inputfilename = result;
if ( v2 )
{
if ( (unsigned int)_isoc99_sscanf(v2, "%d", &v9) != 1 || (int)v9 <= 3 )
fail("invalid width parameter: %s.", v2);
result = (char *)setoutputwidth(v9);
}
if ( v3 )
{
if ( (unsigned int)_isoc99_sscanf(v3, "%d", &v9) != 1 || (v9 & 0x80000000) != 0 )
fail("invalid indent parameter: %s.", v3);
result = (char *)setoutputindent(v9);
}
if ( v4 )
{
if ( !(unsigned int)isvalididentifier(v4) )
fail("invalid variable name: \"%s\".", v4);
result = (char *)setvarname(v4);
}
if ( v5 )
{
if ( !(unsigned int)isvalididentifier(v5) )
fail("invalid structure name: \"%s\".", v5);
result = (char *)setstructname(v5);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(int argc, char **argv)
{
char *v2; // r15
char *v3; // r14
char *v4; // r13
char *v5; // r12
int v6; // eax
__int64 v7; // rax
char *result; // rax
unsigned int v9; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = 0LL;
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
setprogramname(*argv);
while ( 1 )
{
v6 = getopt_long(argc, argv, "Eei:mo:qs:v:w:X", &options_0, 0LL);
v9 = v6;
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'E':
include_end(0LL);
break;
case 'H':
fwrite(
"Usage: elftoc [OPTIONS] FILENAME\n"
"Translates an ELF file into C source code for a struct definition\n"
"with the file's contents as its initialized value.\n"
"\n"
" -e, --force-end Force the inclusion of a final _end field.\n"
" -E, --exclude-end Force the _end field to never be included.\n"
" -X, --force-hex Always output data sections as hex bytes.\n"
" -m, --allow-misaligned Ignore alignment problems in fields.\n"
" -q, --quiet Suppress warning messages.\n"
" -o, --output=FILE Write source to FILE instead of stdout.\n"
" -w, --width=N Set the right-hand margin to N [default=80].\n"
" -i, --indent=N Set indentation to N spaces [default=2].\n"
" -s, --structname=NAME Use NAME as the struct name [default=elf].\n"
" -v, --varname=NAME Use NAME as the variable name [default=foo].\n"
" --help Display this help and exit.\n"
" --version Display version information and exit.\n",
1uLL,
0x3A7uLL,
stdout);
exit(0);
case 'V':
fwrite(
"elftoc: version 2.\n"
"Copyright (C) 1999,2011 by Brian Raiter <breadbox@muppetlabs.com>\n"
"License GPLv2+: GNU GPL version 2 or later.\n"
"This is free software; you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n",
1uLL,
0xFAuLL,
stdout);
exit(0);
case 'X':
forcehexbytes();
break;
case 'e':
include_end(1LL);
break;
case 'i':
v3 = optarg;
break;
case 'm':
permitmisalignment();
break;
case 'o':
outputfilename = optarg;
break;
case 'q':
enablewarnings(0LL);
break;
case 's':
v5 = optarg;
break;
case 'v':
v4 = optarg;
break;
case 'w':
v2 = optarg;
break;
default:
fwrite("Try --help for more information.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
}
if ( optind == argc )
fail("no input file.\n%s", "Try --help for more information.\n");
v7 = optind;
if ( optind + 1 < argc )
{
fail("unrecognized extra argments.\n%s", "Try --help for more information.\n");
v7 = optind;
}
result = argv[v7];
inputfilename = result;
if ( v2 )
{
if ( (unsigned int)_isoc99_sscanf(v2, "%d", &v9) != 1 || (int)v9 <= 3 )
fail("invalid width parameter: %s.", v2);
result = (char *)setoutputwidth(v9);
}
if ( v3 )
{
if ( (unsigned int)_isoc99_sscanf(v3, "%d", &v9) != 1 || (v9 & 0x80000000) != 0 )
fail("invalid indent parameter: %s.", v3);
result = (char *)setoutputindent(v9);
}
if ( v4 )
{
if ( !(unsigned int)func0(v4) )
fail("invalid variable name: \"%s\".", v4);
result = (char *)setvarname(v4);
}
if ( v5 )
{
if ( !(unsigned int)func0(v5) )
fail("invalid structure name: \"%s\".", v5);
result = (char *)setstructname(v5);
}
return result;
}

original_code:
static void parsecmdline(int argc, char *argv[])
{
    static char const *optstring = "Eei:mo:qs:v:w:X";
    static struct option options[] = {
 { "force-end", 0, ((void *)0), 'e' },
 { "exclude-end", 0, ((void *)0), 'E' },
 { "force-hex", 0, ((void *)0), 'X' },
 { "allow-misaligned", 0, ((void *)0), 'm' },
 { "quiet", 0, ((void *)0), 'q' },
 { "indent", 1, ((void *)0), 'i' },
 { "width", 1, ((void *)0), 'w' },
 { "output", 1, ((void *)0), 'o' },
 { "structname", 1, ((void *)0), 's' },
 { "varname", 1, ((void *)0), 'v' },
 { "help", 0, ((void *)0), 'H' },
 { "version", 0, ((void *)0), 'V' },
 { 0, 0, 0, 0 }
    };
    char const *structname = ((void *)0);
    char const *varname = ((void *)0);
    char const *width = ((void *)0);
    char const *indent = ((void *)0);
    int n;
    setprogramname(argv[0]);
    while ((n = getopt_long(argc, argv, optstring, options, ((void *)0))) != (-1)) {
 switch (n) {
   case 'e': include_end(1); break;
   case 'E': include_end(0); break;
   case 'X': forcehexbytes(); break;
   case 'm': permitmisalignment(); break;
   case 'q': enablewarnings(0); break;
   case 'i': indent = optarg; break;
   case 'w': width = optarg; break;
   case 'o': outputfilename = optarg; break;
   case 's': structname = optarg; break;
   case 'v': varname = optarg; break;
   case 'H': fputs(yowzitch, stdout); exit(0);
   case 'V': fputs(vourzhon, stdout); exit(0);
   default:
     fprintf(stderr, "%s", helpsuffix);
     exit(1);
 }
    }
    if (optind == argc)
 fail("no input file.\n%s", helpsuffix);
    if (optind + 1 < argc)
 fail("unrecognized extra argments.\n%s", helpsuffix);
    inputfilename = argv[optind];
    if (width) {
 if (sscanf(width, "%d", &n) != 1 || n < 4)
     fail("invalid width parameter: %s.", width);
 setoutputwidth(n);
    }
    if (indent) {
 if (sscanf(indent, "%d", &n) != 1 || n < 0)
     fail("invalid indent parameter: %s.", indent);
 setoutputindent(n);
    }
    if (varname) {
 if (!isvalididentifier(varname))
     fail("invalid variable name: \"%s\".", varname);
 setvarname(varname);
    }
    if (structname) {
 if (!isvalididentifier(structname))
     fail("invalid structure name: \"%s\".", structname);
 setstructname(structname);
    }
}

canonical_original_code:
static void parsecmdline(int argc, char *argv[])
{
    static char *optstring = "Eei:mo:qs:v:w:X";
    static struct option options[] = {
 { "force-end", 0, ((void *)0), 'e' },
 { "exclude-end", 0, ((void *)0), 'E' },
 { "force-hex", 0, ((void *)0), 'X' },
 { "allow-misaligned", 0, ((void *)0), 'm' },
 { "quiet", 0, ((void *)0), 'q' },
 { "indent", 1, ((void *)0), 'i' },
 { "width", 1, ((void *)0), 'w' },
 { "output", 1, ((void *)0), 'o' },
 { "structname", 1, ((void *)0), 's' },
 { "varname", 1, ((void *)0), 'v' },
 { "help", 0, ((void *)0), 'H' },
 { "version", 0, ((void *)0), 'V' },
 { 0, 0, 0, 0 }
    };
    char *structname = ((void *)0);
    char *varname = ((void *)0);
    char *width = ((void *)0);
    char *indent = ((void *)0);
    int n;
    setprogramname(argv[0]);
    while ((n = getopt_long(argc, argv, optstring, options, ((void *)0))) != (-1)) {
 switch (n) {
   case 'e': include_end(1); break;
   case 'E': include_end(0); break;
   case 'X': forcehexbytes(); break;
   case 'm': permitmisalignment(); break;
   case 'q': enablewarnings(0); break;
   case 'i': indent = optarg; break;
   case 'w': width = optarg; break;
   case 'o': outputfilename = optarg; break;
   case 's': structname = optarg; break;
   case 'v': varname = optarg; break;
   case 'H': fputs(yowzitch, stdout); exit(0);
   case 'V': fputs(vourzhon, stdout); exit(0);
   default:
     fprintf(stderr, "%s", helpsuffix);
     exit(1);
 }
    }
    if (optind == argc)
 fail("no input file.\n%s", helpsuffix);
    if (optind + 1 < argc)
 fail("unrecognized extra argments.\n%s", helpsuffix);
    inputfilename = argv[optind];
    if (width) {
 if (sscanf(width, "%d", &n) != 1 || n < 4)
     fail("invalid width parameter: %s.", width);
 setoutputwidth(n);
    }
    if (indent) {
 if (sscanf(indent, "%d", &n) != 1 || n < 0)
     fail("invalid indent parameter: %s.", indent);
 setoutputindent(n);
    }
    if (varname) {
 if (!isvalididentifier(varname))
     fail("invalid variable name: \"%s\".", varname);
 setvarname(varname);
    }
    if (structname) {
 if (!isvalididentifier(structname))
     fail("invalid structure name: \"%s\".", structname);
 setstructname(structname);
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
optstring
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
structname
char *

variable_types:
varname
char *

variable_types:
width
char *

variable_types:
indent
char *


readinputfile

decompiled_code:
__int64 readinputfile()
{
int v0; // ebp
void *v1; // r12
struct stat v3; // [rsp+0h] [rbp-A8h] BYREF

setfilename(inputfilename);
v0 = open(inputfilename, 0);
if ( v0 < 0 )
fail(0LL);
if ( fstat(v0, &v3) )
fail(0LL);
if ( (v3.st_mode & 0xF000) != 0x8000 )
fail("not a valid input file.");
v1 = mmap(0LL, v3.st_size, 1, 2, v0, 0LL);
if ( v1 == (void *)-1LL )
fail(0LL);
close(v0);
return readelf(v1, v3.st_size);
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebp
void *v1; // r12
struct stat v3; // [rsp+0h] [rbp-A8h] BYREF

setfilename(inputfilename);
v0 = open(inputfilename, 0);
if ( v0 < 0 )
fail(0LL);
if ( fstat(v0, &v3) )
fail(0LL);
if ( (v3.st_mode & 0xF000) != 0x8000 )
fail("not a valid input file.");
v1 = mmap(0LL, v3.st_size, 1, 2, v0, 0LL);
if ( v1 == (void *)-1LL )
fail(0LL);
close(v0);
return readelf(v1, v3.st_size);
}

original_code:
static int readinputfile(void)
{
    struct stat stat;
    void const *ptr;
    int fd;
    setfilename(inputfilename);
    fd = open(inputfilename, 00);
    if (fd < 0)
 fail(((void *)0));
    if (fstat(fd, &stat))
 fail(((void *)0));
    if (!((((stat.st_mode)) & 0170000) == (0100000)))
 fail("not a valid input file.");
    ptr = mmap(((void *)0), stat.st_size, 0x1, 0x02, fd, 0);
    if (ptr == ((void *) -1))
 fail(((void *)0));
    close(fd);
    return readelf(ptr, stat.st_size);
}

canonical_original_code:
static int readinputfile()
{
    struct stat stat;
    void *ptr;
    int fd;
    setfilename(inputfilename);
    fd = open(inputfilename, 00);
    if (fd < 0)
 fail(((void *)0));
    if (fstat(fd, &stat))
 fail(((void *)0));
    if (!((((stat.st_mode)) & 0170000) == (0100000)))
 fail("not a valid input file.");
    ptr = mmap(((void *)0), stat.st_size, 0x1, 0x02, fd, 0);
    if (ptr == ((void *) -1))
 fail(((void *)0));
    close(fd);
    return readelf(ptr, stat.st_size);
}

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

variable_types:
ptr
void *

variable_types: fd int


processcontents

decompiled_code:
__int64 processcontents()
{
arrangepieces();
verifypiecetypes();
setpiecenames();
return setaddressnames();
}

canonical_decompiled_code:
__int64 func3()
{
arrangepieces();
verifypiecetypes();
setpiecenames();
return setaddressnames();
}

original_code:
static void processcontents(void)
{
    arrangepieces();
    verifypiecetypes();
    setpiecenames();
    setaddressnames();
}

canonical_original_code:
static void processcontents()
{
    arrangepieces();
    verifypiecetypes();
    setpiecenames();
    setaddressnames();
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
int result; // eax

parsecmdline(argc, (char **)argv);
v3 = readinputfile();
result = 1;
if ( v3 )
{
processcontents();
writesource(*(__int64 *)&argc, (const char *)argv);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
int result; // eax

func1(argc, (char **)argv);
v3 = func2();
result = 1;
if ( v3 )
{
func3();
func4(*(__int64 *)&argc, (const char *)argv);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    parsecmdline(argc, argv);
    if (!readinputfile())
 return 1;
    processcontents();
    writesource();
    return 0;
}


emit

decompiled_code:
void __fastcall emit(char *a1, unsigned int a2)
{
__int64 v3; // rbx
__int64 v4; // r13
int v5; // esi
char *v6; // rdi
int v7; // er12
char *v8; // rdi
unsigned __int64 v9; // rcx
char *v10; // rdi
char *v11; // rbp
unsigned int v12; // edi
unsigned int v13; // edi
unsigned int v14; // eax
__int64 v15; // rdx

v3 = a2;
v4 = pos;
v5 = textallocsize;
v6 = (char *)textbuf;
v7 = pos + v3;
if ( pos + (int)v3 > textallocsize )
{
textallocsize += 4096;
textbuf = realloc(textbuf, v5 + 4096);
v6 = (char *)textbuf;
if ( !textbuf )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
}
v8 = &v6[v4];
if ( (unsigned int)v3 >= 8 )
{
v9 = (unsigned __int64)(v8 + 8) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)v8 = *(_QWORD *)a1;
*(_QWORD *)&v8[(unsigned int)v3 - 8] = *(_QWORD *)&a1[(unsigned int)v3 - 8];
v10 = &v8[-v9];
v11 = (char *)(a1 - v10);
v12 = (v3 + (_DWORD)v10) & 0xFFFFFFF8;
if ( v12 >= 8 )
{
v13 = v12 & 0xFFFFFFF8;
v14 = 0;
do
{
v15 = v14;
v14 += 8;
*(_QWORD *)(v9 + v15) = *(_QWORD *)&v11[v15];
}
while ( v14 < v13 );
}
}
else if ( (v3 & 4) != 0 )
{
*(_DWORD *)v8 = *(_DWORD *)a1;
*(_DWORD *)&v8[v3 - 4] = *(_DWORD *)&a1[v3 - 4];
}
else if ( (_DWORD)v3 )
{
*v8 = *a1;
if ( (v3 & 2) != 0 )
*(_WORD *)&v8[v3 - 2] = *(_WORD *)&a1[v3 - 2];
}
pos = v7;
}

canonical_decompiled_code:
void __fastcall func0(char *a1, unsigned int a2)
{
__int64 v3; // rbx
__int64 v4; // r13
int v5; // esi
char *v6; // rdi
int v7; // er12
char *v8; // rdi
unsigned __int64 v9; // rcx
char *v10; // rdi
char *v11; // rbp
unsigned int v12; // edi
unsigned int v13; // edi
unsigned int v14; // eax
__int64 v15; // rdx

v3 = a2;
v4 = pos;
v5 = textallocsize;
v6 = (char *)textbuf;
v7 = pos + v3;
if ( pos + (int)v3 > textallocsize )
{
textallocsize += 4096;
textbuf = realloc(textbuf, v5 + 4096);
v6 = (char *)textbuf;
if ( !textbuf )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
}
v8 = &v6[v4];
if ( (unsigned int)v3 >= 8 )
{
v9 = (unsigned __int64)(v8 + 8) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)v8 = *(_QWORD *)a1;
*(_QWORD *)&v8[(unsigned int)v3 - 8] = *(_QWORD *)&a1[(unsigned int)v3 - 8];
v10 = &v8[-v9];
v11 = (char *)(a1 - v10);
v12 = (v3 + (_DWORD)v10) & 0xFFFFFFF8;
if ( v12 >= 8 )
{
v13 = v12 & 0xFFFFFFF8;
v14 = 0;
do
{
v15 = v14;
v14 += 8;
*(_QWORD *)(v9 + v15) = *(_QWORD *)&v11[v15];
}
while ( v14 < v13 );
}
}
else if ( (v3 & 4) != 0 )
{
*(_DWORD *)v8 = *(_DWORD *)a1;
*(_DWORD *)&v8[v3 - 4] = *(_DWORD *)&a1[v3 - 4];
}
else if ( (_DWORD)v3 )
{
*v8 = *a1;
if ( (v3 & 2) != 0 )
*(_WORD *)&v8[v3 - 2] = *(_WORD *)&a1[v3 - 2];
}
pos = v7;
}

original_code:
static void emit(void const *bytes, int size)
{
    if (pos + size > textallocsize) {
 textallocsize += 4096;
 if (!(textbuf = realloc(textbuf, textallocsize))) {
     fputs("Out of memory!\n", stderr);
     exit(1);
 }
    }
    memcpy(textbuf + pos, bytes, size);
    pos += size;
}

canonical_original_code:
static void emit(void *bytes, int size)
{
    if (pos + size > textallocsize) {
 textallocsize += 4096;
 if (!(textbuf = realloc(textbuf, textallocsize))) {
     fputs("Out of memory!\n", stderr);
     exit(1);
 }
    }
    memcpy(textbuf + pos, bytes, size);
    pos += size;
}

variable_types:
bytes
void *

variable_types: size int


translatecmd

decompiled_code:
__int64 __fastcall translatecmd(int a1, const char *a2)
{
__int64 result; // rax
__int64 v7; // rax
void *v8; // rsi
char *v9; // rdi
char v10; // cl
__int64 v11; // rax
char v12[15]; // [rsp+Ch] [rbp-1Ch] BYREF
char v13; // [rsp+1Bh] [rbp-Dh] BYREF
int v14[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v12[0] = (char)a2;
if ( a1 > 46 )
{
switch ( a1 )
{
case '<':
LODWORD(v8) = 3;
v9 = (char *)&subptr;
if ( v12[0] != 1 )
goto LABEL_19;
emit(decptr, 3u);
result = 1LL;
break;
case '>':
LODWORD(v8) = 3;
v9 = (char *)&addptr;
if ( v12[0] == 1 )
{
emit(incptr, 3u);
result = 1LL;
}
else
{
LABEL_19:
emit(v9, (unsigned int)v8);
emit(v12, 1u);
result = 1LL;
}
break;
case 'Z':
emit(zerobyte, 2u);
result = 1LL;
break;
case '[':
v10 = v12[0];
if ( v12[0] + ((st_7 - (__int64)&stack_1) >> 2) > 256 )
err((int)"too many levels of nested loops", a2);
--v12[0];
if ( v10 )
{
do
{
emit(jump, (unsigned int)&loc_5);
v11 = st_7 + 4;
*(_DWORD *)st_7 = pos;
st_7 = v11;
LOBYTE(v11) = v12[0]--;
}
while ( (_BYTE)v11 );
}
goto LABEL_6;
case ']':
while ( v12[0]-- )
{
v7 = st_7;
if ( (_UNKNOWN *)st_7 == &stack_1 )
err((int)"unmatched ]", a2);
st_7 -= 4LL;
v14[0] = pos - *(_DWORD *)(v7 - 4);
*(_DWORD *)((char *)textbuf + *(int *)(v7 - 4) - 4) = v14[0];
if ( (unsigned __int64)(v14[0] + 4LL) <= 0x80 )
{
v13 = -4 - LOBYTE(v14[0]);
emit(branch, 3u);
a2 = (char *)emit + 1;
emit(&v13, (unsigned int)emit + 1);
}
else
{
v14[0] = -8 - v14[0];
emit(nbranch, 4u);
a2 = (_BYTE *)&loc_4;
emit((char *)v14, 4u);
}
}
goto LABEL_6;
default:
goto LABEL_6;
}
}
else if ( a1 < -1 )
{
LABEL_6:
result = 1LL;
}
else
{
switch ( a1 )
{
case -1:
if ( (_UNKNOWN *)st_7 != &stack_1 )
err((int)"unmatched [", a2);
goto LABEL_6;
case 0:
st_7 = (__int64)&stack_1;
emit(start, 5u);
result = 1LL;
break;
case 43:
LODWORD(v8) = 2;
v9 = (char *)&addbyte;
if ( v12[0] != 1 )
goto LABEL_19;
emit(incbyte, 2u);
result = 1LL;
break;
case 44:
while ( v12[0]-- )
emit(readbyte, 6u);
goto LABEL_6;
case 45:
v8 = &loc_2;
v9 = (char *)&subbyte;
if ( v12[0] != 1 )
goto LABEL_19;
emit(decbyte, (unsigned int)&loc_2);
result = 1LL;
break;
case 46:
while ( v12[0]-- )
emit(writebyte, 6u);
goto LABEL_6;
default:
goto LABEL_6;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, const char *a2)
{
__int64 result; // rax
__int64 v7; // rax
void *v8; // rsi
char *v9; // rdi
char v10; // cl
__int64 v11; // rax
char v12[15]; // [rsp+Ch] [rbp-1Ch] BYREF
char v13; // [rsp+1Bh] [rbp-Dh] BYREF
int v14[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v12[0] = (char)a2;
if ( a1 > 46 )
{
switch ( a1 )
{
case '<':
LODWORD(v8) = 3;
v9 = (char *)&subptr;
if ( v12[0] != 1 )
goto LABEL_19;
func0(decptr, 3u);
result = 1LL;
break;
case '>':
LODWORD(v8) = 3;
v9 = (char *)&addptr;
if ( v12[0] == 1 )
{
func0(incptr, 3u);
result = 1LL;
}
else
{
LABEL_19:
func0(v9, (unsigned int)v8);
func0(v12, 1u);
result = 1LL;
}
break;
case 'Z':
func0(zerobyte, 2u);
result = 1LL;
break;
case '[':
v10 = v12[0];
if ( v12[0] + ((st_7 - (__int64)&stack_1) >> 2) > 256 )
err((int)"too many levels of nested loops", a2);
--v12[0];
if ( v10 )
{
do
{
func0(jump, (unsigned int)&loc_5);
v11 = st_7 + 4;
*(_DWORD *)st_7 = pos;
st_7 = v11;
LOBYTE(v11) = v12[0]--;
}
while ( (_BYTE)v11 );
}
goto LABEL_6;
case ']':
while ( v12[0]-- )
{
v7 = st_7;
if ( (_UNKNOWN *)st_7 == &stack_1 )
err((int)"unmatched ]", a2);
st_7 -= 4LL;
v14[0] = pos - *(_DWORD *)(v7 - 4);
*(_DWORD *)((char *)textbuf + *(int *)(v7 - 4) - 4) = v14[0];
if ( (unsigned __int64)(v14[0] + 4LL) <= 0x80 )
{
v13 = -4 - LOBYTE(v14[0]);
func0(branch, 3u);
a2 = (char *)emit + 1;
func0(&v13, (unsigned int)emit + 1);
}
else
{
v14[0] = -8 - v14[0];
func0(nbranch, 4u);
a2 = (_BYTE *)&loc_4;
func0((char *)v14, 4u);
}
}
goto LABEL_6;
default:
goto LABEL_6;
}
}
else if ( a1 < -1 )
{
LABEL_6:
result = 1LL;
}
else
{
switch ( a1 )
{
case -1:
if ( (_UNKNOWN *)st_7 != &stack_1 )
err((int)"unmatched [", a2);
goto LABEL_6;
case 0:
st_7 = (__int64)&stack_1;
func0(start, 5u);
result = 1LL;
break;
case 43:
LODWORD(v8) = 2;
v9 = (char *)&addbyte;
if ( v12[0] != 1 )
goto LABEL_19;
func0(incbyte, 2u);
result = 1LL;
break;
case 44:
while ( v12[0]-- )
func0(readbyte, 6u);
goto LABEL_6;
case 45:
v8 = &loc_2;
v9 = (char *)&subbyte;
if ( v12[0] != 1 )
goto LABEL_19;
func0(decbyte, (unsigned int)&loc_2);
result = 1LL;
break;
case 46:
while ( v12[0]-- )
func0(writebyte, 6u);
goto LABEL_6;
default:
goto LABEL_6;
}
}
return result;
}

original_code:
static _Bool translatecmd(int cmd, char arg)
{
    static int stack[256];
    static int *st;
    int32_t diff;
    int8_t bdiff;
    switch (cmd) {
      case '+':
        if (arg == 1)
            (emit(&(incbyte), sizeof (incbyte)));
        else
            ((emit(&(addbyte), sizeof (addbyte))), (emit(&(arg), sizeof (arg))));
        break;
      case '-':
        if (arg == 1)
            (emit(&(decbyte), sizeof (decbyte)));
        else
            ((emit(&(subbyte), sizeof (subbyte))), (emit(&(arg), sizeof (arg))));
        break;
      case '>':
        if (arg == 1)
            (emit(&(incptr), sizeof (incptr)));
        else
            ((emit(&(addptr), sizeof (addptr))), (emit(&(arg), sizeof (arg))));
        break;
      case '<':
        if (arg == 1)
            (emit(&(decptr), sizeof (decptr)));
        else
            ((emit(&(subptr), sizeof (subptr))), (emit(&(arg), sizeof (arg))));
        break;
      case '.':
        while (arg--)
            (emit(&(writebyte), sizeof (writebyte)));
        break;
      case ',':
        while (arg--)
            (emit(&(readbyte), sizeof (readbyte)));
        break;
      case '[':
        if ((st - stack) + arg > (int)(sizeof stack / sizeof *stack)) {
     err("too many levels of nested loops");
     return 0;
 }
 while (arg--) {
     (emit(&(jump), sizeof (jump)));
     *st = pos;
     ++st;
 }
 break;
      case ']':
 while (arg--) {
     if (st == stack) {
  err("unmatched ]");
  return 0;
     }
     --st;
     diff = pos - *st;
            (memcpy(textbuf + (*st - sizeof diff), &(diff), sizeof (diff)));
            if (diff + sizeof branch + sizeof bdiff <= 0x80) {
                bdiff = -(diff + sizeof branch + sizeof bdiff);
                ((emit(&(branch), sizeof (branch))), (emit(&(bdiff), sizeof (bdiff))));
            } else {
                diff = -(diff + sizeof nbranch + sizeof diff);
                ((emit(&(nbranch), sizeof (nbranch))), (emit(&(diff), sizeof (diff))));
            }
 }
 break;
      case 0:
 st = stack;
 (emit(&(start), sizeof (start)));
 break;
      case 'Z':
        (emit(&(zerobyte), sizeof (zerobyte)));
        break;
      case (-1):
 if (st != stack) {
     err("unmatched [");
     return 0;
 }
 break;
    }
    return 1;
}

canonical_original_code:
static _Bool translatecmd(int cmd, char arg)
{
    static int stack[256];
    static int *st;
    int diff;
    char bdiff;
    switch (cmd) {
      case '+':
        if (arg == 1)
            (emit(&(incbyte), sizeof (incbyte)));
        else
            ((emit(&(addbyte), sizeof (addbyte))), (emit(&(arg), sizeof (arg))));
        break;
      case '-':
        if (arg == 1)
            (emit(&(decbyte), sizeof (decbyte)));
        else
            ((emit(&(subbyte), sizeof (subbyte))), (emit(&(arg), sizeof (arg))));
        break;
      case '>':
        if (arg == 1)
            (emit(&(incptr), sizeof (incptr)));
        else
            ((emit(&(addptr), sizeof (addptr))), (emit(&(arg), sizeof (arg))));
        break;
      case '<':
        if (arg == 1)
            (emit(&(decptr), sizeof (decptr)));
        else
            ((emit(&(subptr), sizeof (subptr))), (emit(&(arg), sizeof (arg))));
        break;
      case '.':
        while (arg--)
            (emit(&(writebyte), sizeof (writebyte)));
        break;
      case ',':
        while (arg--)
            (emit(&(readbyte), sizeof (readbyte)));
        break;
      case '[':
        if ((st - stack) + arg > (int)(sizeof stack / sizeof *stack)) {
     err("too many levels of nested loops");
     return 0;
 }
 while (arg--) {
     (emit(&(jump), sizeof (jump)));
     *st = pos;
     ++st;
 }
 break;
      case ']':
 while (arg--) {
     if (st == stack) {
  err("unmatched ]");
  return 0;
     }
     --st;
     diff = pos - *st;
            (memcpy(textbuf + (*st - sizeof diff), &(diff), sizeof (diff)));
            if (diff + sizeof branch + sizeof bdiff <= 0x80) {
                bdiff = -(diff + sizeof branch + sizeof bdiff);
                ((emit(&(branch), sizeof (branch))), (emit(&(bdiff), sizeof (bdiff))));
            } else {
                diff = -(diff + sizeof nbranch + sizeof diff);
                ((emit(&(nbranch), sizeof (nbranch))), (emit(&(diff), sizeof (diff))));
            }
 }
 break;
      case 0:
 st = stack;
 (emit(&(start), sizeof (start)));
 break;
      case 'Z':
        (emit(&(zerobyte), sizeof (zerobyte)));
        break;
      case (-1):
 if (st != stack) {
     err("unmatched [");
     return 0;
 }
 break;
    }
    return 1;
}

variable_types: cmd int

variable_types: arg char

variable_types:
stack
int [256]

variable_types:
st
int *

variable_types: diff int

variable_types: bdiff char


compilecmdwithcollapse

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

if ( lastcmd_3 == a1 && (int)(a2 + cmdcount_2) <= 127 )
{
cmdcount_2 += a2;
return 1LL;
}
if ( cmdcount_2 <= 0 )
{
if ( (unsigned int)(a1 + 1) > 1 )
{
LABEL_4:
lastcmd_3 = a1;
result = 1LL;
cmdcount_2 = a2;
return result;
}
return translatecmd(a1, (const char *)a2);
}
result = translatecmd(lastcmd_3, (const char *)(unsigned int)(char)cmdcount_2);
if ( (_BYTE)result )
{
lastcmd_3 = -1;
cmdcount_2 = 0;
if ( (unsigned int)(a1 + 1) > 1 )
goto LABEL_4;
return translatecmd(a1, (const char *)a2);
}
return result;
}

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

if ( lastcmd_3 == a1 && (int)(a2 + cmdcount_2) <= 127 )
{
cmdcount_2 += a2;
return 1LL;
}
if ( cmdcount_2 <= 0 )
{
if ( (unsigned int)(a1 + 1) > 1 )
{
LABEL_4:
lastcmd_3 = a1;
result = 1LL;
cmdcount_2 = a2;
return result;
}
return func1(a1, (const char *)a2);
}
result = func1(lastcmd_3, (const char *)(unsigned int)(char)cmdcount_2);
if ( (_BYTE)result )
{
lastcmd_3 = -1;
cmdcount_2 = 0;
if ( (unsigned int)(a1 + 1) > 1 )
goto LABEL_4;
return func1(a1, (const char *)a2);
}
return result;
}

original_code:
static _Bool compilecmdwithcollapse(int cmd, int count)
{
    static int lastcmd = -1;
    static int cmdcount = 0;
    if (cmd == lastcmd && cmdcount + count < 0x80) {
        cmdcount += count;
        return 1;
    }
    if (cmdcount > 0) {
        if (!translatecmd(lastcmd, cmdcount))
            return 0;
        lastcmd = -1;
        cmdcount = 0;
    }
    if (cmd == 0 || cmd == (-1))
        return translatecmd(cmd, count);
    lastcmd = cmd;
    cmdcount = count;
    return 1;
}

variable_types: count int

variable_types: lastcmd int

variable_types: cmdcount int


compilecmd

decompiled_code:
__int64 __fastcall compilecmd(int a1, unsigned int a2)
{
__int64 v3; // rbx
int i; // edi
__int64 result; // rax

if ( a2 == 1 && byte_1128[bufcount_4] == a1 )
{
if ( bufcount_4 == 2 )
{
bufcount_4 = 0;
result = compilecmdwithcollapse(90, 1u);
}
else
{
++bufcount_4;
result = 1LL;
}
return result;
}
if ( !bufcount_4 )
return compilecmdwithcollapse(a1, a2);
if ( bufcount_4 <= 0 )
{
LABEL_9:
bufcount_4 = 0;
return compilecmdwithcollapse(a1, a2);
}
v3 = 0LL;
for ( i = 91; ; i = byte_1128[v3] )
{
result = compilecmdwithcollapse(i, 1u);
if ( !(_BYTE)result )
break;
if ( bufcount_4 <= (int)++v3 )
goto LABEL_9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned int a2)
{
__int64 v3; // rbx
int i; // edi
__int64 result; // rax

if ( a2 == 1 && byte_1128[bufcount_4] == a1 )
{
if ( bufcount_4 == 2 )
{
bufcount_4 = 0;
result = func2(90, 1u);
}
else
{
++bufcount_4;
result = 1LL;
}
return result;
}
if ( !bufcount_4 )
return func2(a1, a2);
if ( bufcount_4 <= 0 )
{
LABEL_9:
bufcount_4 = 0;
return func2(a1, a2);
}
v3 = 0LL;
for ( i = 91; ; i = byte_1128[v3] )
{
result = func2(i, 1u);
if ( !(_BYTE)result )
break;
if ( bufcount_4 <= (int)++v3 )
goto LABEL_9;
}
return result;
}

original_code:
static _Bool compilecmd(int cmd, int count)
{
    static char const *zerocmd = "[-]";
    static int const zerocmdlen = 3;
    static int bufcount = 0;
    int i;
    if (count == 1 && cmd == zerocmd[bufcount]) {
        ++bufcount;
        if (bufcount == zerocmdlen) {
            bufcount = 0;
            return compilecmdwithcollapse('Z', 1);
        }
        return 1;
    } else if (bufcount) {
        for (i = 0 ; i < bufcount ; ++i)
            if (!compilecmdwithcollapse(zerocmd[i], 1))
                return 0;
        bufcount = 0;
    }
    return compilecmdwithcollapse(cmd, count);
}

canonical_original_code:
static _Bool compilecmd(int cmd, int count)
{
    static char *zerocmd = "[-]";
    static int zerocmdlen = 3;
    static int bufcount = 0;
    int i;
    if (count == 1 && cmd == zerocmd[bufcount]) {
        ++bufcount;
        if (bufcount == zerocmdlen) {
            bufcount = 0;
            return compilecmdwithcollapse('Z', 1);
        }
        return 1;
    } else if (bufcount) {
        for (i = 0 ; i < bufcount ; ++i)
            if (!compilecmdwithcollapse(zerocmd[i], 1))
                return 0;
        bufcount = 0;
    }
    return compilecmdwithcollapse(cmd, count);
}

variable_types:
zerocmd
char *

variable_types: zerocmdlen int

variable_types: bufcount int

variable_types: i int


decompiled_code:
__int16 __fastcall rev2(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static inline unsigned short rev2(unsigned short in)
{
    return ((in & 0x00FF) << 8) | ((in & 0xFF00) >> 8);
}

variable_types:
in
unsigned short


decompiled_code:
__int64 __fastcall rev4(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return _byteswap_ulong(a1);
}

original_code:
static inline unsigned int rev4(unsigned int in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}

variable_types:
in
unsigned int


decompiled_code:
unsigned __int64 __fastcall rev8(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

original_code:
static inline unsigned long long rev8(unsigned long long in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}

variable_types:
in
unsigned long long


decompiled_code:
__int64 __fastcall elfrw_initialize_direct(char a1, char a2, char a3)
{
__int64 result; // rax

if ( !elfrw_native_data )
elfrw_native_data = 1;
if ( a1 != 1 )
{
if ( a1 != 2 )
return 4294967292LL;
elfrw_current_class = 2;
if ( a2 != 1 )
goto LABEL_6;
LABEL_13:
elfrw_current_data = 1;
goto LABEL_8;
}
elfrw_current_class = 1;
if ( a2 == 1 )
goto LABEL_13;
LABEL_6:
if ( a2 != 2 )
return 4294967291LL;
elfrw_current_data = 2;
LABEL_8:
elfrw_current_version = a3;
result = 0LL;
if ( a3 != 1 )
result = 4294967290LL;
return result;
}

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

if ( !elfrw_native_data )
elfrw_native_data = 1;
if ( a1 != 1 )
{
if ( a1 != 2 )
return 4294967292LL;
elfrw_current_class = 2;
if ( a2 != 1 )
goto LABEL_6;
LABEL_13:
elfrw_current_data = 1;
goto LABEL_8;
}
elfrw_current_class = 1;
if ( a2 == 1 )
goto LABEL_13;
LABEL_6:
if ( a2 != 2 )
return 4294967291LL;
elfrw_current_data = 2;
LABEL_8:
elfrw_current_version = a3;
result = 0LL;
if ( a3 != 1 )
result = 4294967290LL;
return result;
}

original_code:
int elfrw_initialize_direct(unsigned char class, unsigned char data,
       unsigned char version)
{
    if (!_elfrw_native_data) {
 int msb = 1;
 *(char*)&msb = 0;
 _elfrw_native_data = msb ? 2 : 1;
    }
    switch (class) {
      case 1: _elfrw_current_class = 1; break;
      case 2: _elfrw_current_class = 2; break;
      default: return -4;
    }
    switch (data) {
      case 1: _elfrw_current_data = 1; break;
      case 2: _elfrw_current_data = 2; break;
      default: return -5;
    }
    _elfrw_current_version = version;
    if (_elfrw_current_version != 1)
 return -6;
    return 0;
}

canonical_original_code:
int elfrw_initialize_direct(unsigned char class, unsigned char data, unsigned char version)
{
    if (!_elfrw_native_data) {
 int msb = 1;
 *(char *)&msb = 0;
 _elfrw_native_data = msb ? 2 : 1;
    }
    switch (class) {
      case 1: _elfrw_current_class = 1; break;
      case 2: _elfrw_current_class = 2; break;
      default: return -4;
    }
    switch (data) {
      case 1: _elfrw_current_data = 1; break;
      case 2: _elfrw_current_data = 2; break;
      default: return -5;
    }
    _elfrw_current_version = version;
    if (_elfrw_current_version != 1)
 return -6;
    return 0;
}

variable_types:
class
unsigned char

variable_types:
data
unsigned char

variable_types:
version
unsigned char

variable_types: msb int


decompiled_code:
__int64 __fastcall elfrw_initialize_ident(_BYTE *a1)
{
__int64 result; // rax

if ( *a1 == 127 && a1[1] == 69 && a1[2] == 76 && a1[3] == 70 )
result = elfrw_initialize_direct(a1[4], a1[5], a1[6]);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( *a1 == 127 && a1[1] == 69 && a1[2] == 76 && a1[3] == 70 )
result = func3(a1[4], a1[5], a1[6]);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int elfrw_initialize_ident(unsigned char const *ident)
{
    if (ident[0] != 0x7f || ident[1] != 'E'
      || ident[2] != 'L'
      || ident[3] != 'F')
 return -1;
    return elfrw_initialize_direct(ident[4], ident[5],
       ident[6]);
}

canonical_original_code:
int elfrw_initialize_ident(unsigned char *ident)
{
    if (ident[0] != 0x7f || ident[1] != 'E'
      || ident[2] != 'L'
      || ident[3] != 'F')
 return -1;
    return elfrw_initialize_direct(ident[4], ident[5],
       ident[6]);
}

variable_types:
ident
unsigned char *