main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
const char *v4; // r12
__int64 v5; // r13
int v6; // eax
size_t v7; // rdx
int v8; // er13
FILE *v10; // rsi
FILE *v11; // rdi
const char *v12; // [rsp+0h] [rbp-2068h]
char *filename; // [rsp+8h] [rbp-2060h]
unsigned int v14; // [rsp+10h] [rbp-2058h]
char v15; // [rsp+17h] [rbp-2051h]
char *s1; // [rsp+18h] [rbp-2050h]
FILE *s; // [rsp+20h] [rbp-2048h] BYREF
FILE *stream; // [rsp+28h] [rbp-2040h] BYREF
char v19[4096]; // [rsp+30h] [rbp-2038h] BYREF
char ptr[4152]; // [rsp+1030h] [rbp-1038h] BYREF

if ( argc == 1 )
{
LABEL_81:
syntax();
return 1;
}
s = 0LL;
stream = 0LL;
if ( argc <= 1 )
{
filename = 0LL;
v15 = 0;
LABEL_84:
set_file(1, (__int64)"messages.mo", &s);
v11 = stream;
if ( stream )
{
v10 = s;
if ( s )
{
LABEL_71:
v8 = process(v11, v10, v15);
goto LABEL_18;
}
}
return -1;
}
v15 = 0;
v3 = 1;
filename = 0LL;
v12 = 0LL;
v14 = 0;
do
{
while ( 1 )
{
v4 = argv[v3];
v5 = v3;
if ( *v4 != 45 )
goto LABEL_4;
if ( v4[1] == 45 )
{
if ( !strcmp(v4 + 2, "template")
|| !strcmp(v4 + 2, "strict")
|| !strcmp(v4 + 2, "properties-input")
|| !strcmp(v4 + 2, "stringtable-input")
|| !strcmp(v4 + 2, "use-fuzzy")
|| !memcmp(v4 + 2, "alignment=", 0xAuLL)
|| !strcmp(v4 + 2, "check-format")
|| !strcmp(v4 + 2, "check-header")
|| !strcmp(v4 + 2, "check-domain")
|| !strcmp(v4 + 2, "check-compatibility")
|| !strcmp(v4 + 2, "check-accelerators")
|| !strcmp(v4 + 2, "no-hash")
|| !strcmp(v4 + 2, "verbose")
|| !strcmp(v4 + 2, "statistics")
|| *(_QWORD *)(v4 + 2) == 0x3D64726F7779656BLL
|| !memcmp(v4 + 2, "check-accelerators=", 0x13uLL)
|| !memcmp(v4 + 2, "resource=", 9uLL) )
{
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "java") )
{
v14 = 1;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "java2") )
{
v14 = 2;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "csharp") )
{
v14 = 3;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "csharp-resources") )
{
v14 = 4;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "tcl") )
{
v14 = 5;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "qt") )
{
v14 = 6;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "desktop") )
{
v14 = 7;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "xml") )
{
v14 = 8;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "keyword") )
{
++v3;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "locale=", 7uLL) )
{
v12 = v4 + 9;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "check") )
{
v12 = 0LL;
v15 = 1;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "template=", 9uLL) )
{
set_file(0, (__int64)(v4 + 11), &stream);
v12 = 0LL;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "output-file=", 0xCuLL) )
{
set_file(1, (__int64)(v4 + 14), &s);
v12 = 0LL;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "output=", 7uLL) )
{
set_file(1, (__int64)(v4 + 9), &s);
v12 = 0LL;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "version") )
{
LABEL_91:
version();
return 0;
}
v8 = strcmp(v4 + 2, "help");
if ( !v8 )
{
syntax();
return v8;
}
v12 = 0LL;
goto LABEL_4;
}
v6 = *((unsigned __int8 *)v4 + 1);
if ( v6 == 111 && !v4[2] )
break;
if ( v6 == 106 && !v4[2] )
goto LABEL_5;
if ( v6 == 114 && !v4[2] )
goto LABEL_5;
if ( v6 == 80 && !v4[2] )
goto LABEL_5;
if ( v6 == 102 && !v4[2] )
goto LABEL_5;
s1 = (char *)(v4 + 1);
if ( !strcmp(v4 + 1, "a") || !strcmp(s1, "v") || !strcmp(s1, "C") )
goto LABEL_5;
if ( !strcmp(s1, "c") )
{
v15 = 1;
goto LABEL_5;
}
if ( !strcmp(s1, "V") )
goto LABEL_91;
if ( !strcmp(s1, "h") || !strcmp(s1, "D") )
goto LABEL_81;
if ( !strcmp(s1, "l") )
{
++v3;
v12 = argv[v5 + 1];
goto LABEL_5;
}
if ( !strcmp(s1, "d") )
{
filename = (char *)argv[v5 + 1];
++v3;
goto LABEL_5;
}
LABEL_4:
set_file(0, (__int64)v4, &stream);
LABEL_5:
if ( argc <= ++v3 )
goto LABEL_11;
}
v3 += 2;
set_file(1, (__int64)argv[v5 + 1], &s);
}
while ( argc > v3 );
LABEL_11:
if ( v14 == 5 )
{
if ( v12 && filename )
{
v8 = 0;
snprintf(v19, 0x1000uLL, "%s/%s.msg", filename, v12);
s = fopen(v19, "w");
if ( !s )
{
v8 = -1;
perror("fopen");
}
goto LABEL_18;
}
return -1;
}
if ( v14 <= 5 )
{
if ( v14 )
{
LABEL_80:
v8 = -1;
fprintf(stderr, "unsupported mode %d\n", v14);
goto LABEL_18;
}
v10 = s;
if ( !s )
goto LABEL_84;
v11 = stream;
if ( stream )
goto LABEL_71;
return -1;
}
if ( v14 - 7 > 1 )
goto LABEL_80;
while ( 1 )
{
v7 = fread(ptr, 1uLL, 0x1000uLL, stream);
if ( !v7 )
break;
fwrite(ptr, 1uLL, v7, s);
}
v8 = 0;
LABEL_18:
if ( stream == stdin )
fflush(stream);
else
fclose(stream);
if ( s == stdout )
fflush(s);
else
fclose(s);
if ( v8 < 0 )
remove(filename);
return v8;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
const char *v4; // r12
__int64 v5; // r13
int v6; // eax
size_t v7; // rdx
int v8; // er13
FILE *v10; // rsi
FILE *v11; // rdi
const char *v12; // [rsp+0h] [rbp-2068h]
char *filename; // [rsp+8h] [rbp-2060h]
unsigned int v14; // [rsp+10h] [rbp-2058h]
char v15; // [rsp+17h] [rbp-2051h]
char *s1; // [rsp+18h] [rbp-2050h]
FILE *s; // [rsp+20h] [rbp-2048h] BYREF
FILE *stream; // [rsp+28h] [rbp-2040h] BYREF
char v19[4096]; // [rsp+30h] [rbp-2038h] BYREF
char ptr[4152]; // [rsp+1030h] [rbp-1038h] BYREF

if ( argc == 1 )
{
LABEL_81:
func3();
return 1;
}
s = 0LL;
stream = 0LL;
if ( argc <= 1 )
{
filename = 0LL;
v15 = 0;
LABEL_84:
set_file(1, (__int64)"messages.mo", &s);
v11 = stream;
if ( stream )
{
v10 = s;
if ( s )
{
LABEL_71:
v8 = func4(v11, v10, v15);
goto LABEL_18;
}
}
return -1;
}
v15 = 0;
v3 = 1;
filename = 0LL;
v12 = 0LL;
v14 = 0;
do
{
while ( 1 )
{
v4 = argv[v3];
v5 = v3;
if ( *v4 != 45 )
goto LABEL_4;
if ( v4[1] == 45 )
{
if ( !strcmp(v4 + 2, "template")
|| !strcmp(v4 + 2, "strict")
|| !strcmp(v4 + 2, "properties-input")
|| !strcmp(v4 + 2, "stringtable-input")
|| !strcmp(v4 + 2, "use-fuzzy")
|| !memcmp(v4 + 2, "alignment=", 0xAuLL)
|| !strcmp(v4 + 2, "check-format")
|| !strcmp(v4 + 2, "check-header")
|| !strcmp(v4 + 2, "check-domain")
|| !strcmp(v4 + 2, "check-compatibility")
|| !strcmp(v4 + 2, "check-accelerators")
|| !strcmp(v4 + 2, "no-hash")
|| !strcmp(v4 + 2, "verbose")
|| !strcmp(v4 + 2, "statistics")
|| *(_QWORD *)(v4 + 2) == 0x3D64726F7779656BLL
|| !memcmp(v4 + 2, "check-accelerators=", 0x13uLL)
|| !memcmp(v4 + 2, "resource=", 9uLL) )
{
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "java") )
{
v14 = 1;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "java2") )
{
v14 = 2;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "csharp") )
{
v14 = 3;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "csharp-resources") )
{
v14 = 4;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "tcl") )
{
v14 = 5;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "qt") )
{
v14 = 6;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "desktop") )
{
v14 = 7;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "xml") )
{
v14 = 8;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "keyword") )
{
++v3;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "locale=", 7uLL) )
{
v12 = v4 + 9;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "check") )
{
v12 = 0LL;
v15 = 1;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "template=", 9uLL) )
{
set_file(0, (__int64)(v4 + 11), &stream);
v12 = 0LL;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "output-file=", 0xCuLL) )
{
set_file(1, (__int64)(v4 + 14), &s);
v12 = 0LL;
goto LABEL_5;
}
if ( !memcmp(v4 + 2, "output=", 7uLL) )
{
set_file(1, (__int64)(v4 + 9), &s);
v12 = 0LL;
goto LABEL_5;
}
if ( !strcmp(v4 + 2, "version") )
{
LABEL_91:
func2();
return 0;
}
v8 = strcmp(v4 + 2, "help");
if ( !v8 )
{
func3();
return v8;
}
v12 = 0LL;
goto LABEL_4;
}
v6 = *((unsigned __int8 *)v4 + 1);
if ( v6 == 111 && !v4[2] )
break;
if ( v6 == 106 && !v4[2] )
goto LABEL_5;
if ( v6 == 114 && !v4[2] )
goto LABEL_5;
if ( v6 == 80 && !v4[2] )
goto LABEL_5;
if ( v6 == 102 && !v4[2] )
goto LABEL_5;
s1 = (char *)(v4 + 1);
if ( !strcmp(v4 + 1, "a") || !strcmp(s1, "v") || !strcmp(s1, "C") )
goto LABEL_5;
if ( !strcmp(s1, "c") )
{
v15 = 1;
goto LABEL_5;
}
if ( !strcmp(s1, "V") )
goto LABEL_91;
if ( !strcmp(s1, "h") || !strcmp(s1, "D") )
goto LABEL_81;
if ( !strcmp(s1, "l") )
{
++v3;
v12 = argv[v5 + 1];
goto LABEL_5;
}
if ( !strcmp(s1, "d") )
{
filename = (char *)argv[v5 + 1];
++v3;
goto LABEL_5;
}
LABEL_4:
set_file(0, (__int64)v4, &stream);
LABEL_5:
if ( argc <= ++v3 )
goto LABEL_11;
}
v3 += 2;
set_file(1, (__int64)argv[v5 + 1], &s);
}
while ( argc > v3 );
LABEL_11:
if ( v14 == 5 )
{
if ( v12 && filename )
{
v8 = 0;
snprintf(v19, 0x1000uLL, "%s/%s.msg", filename, v12);
s = fopen(v19, "w");
if ( !s )
{
v8 = -1;
perror("fopen");
}
goto LABEL_18;
}
return -1;
}
if ( v14 <= 5 )
{
if ( v14 )
{
LABEL_80:
v8 = -1;
fprintf(stderr, "unsupported mode %d\n", v14);
goto LABEL_18;
}
v10 = s;
if ( !s )
goto LABEL_84;
v11 = stream;
if ( stream )
goto LABEL_71;
return -1;
}
if ( v14 - 7 > 1 )
goto LABEL_80;
while ( 1 )
{
v7 = fread(ptr, 1uLL, 0x1000uLL, stream);
if ( !v7 )
break;
fwrite(ptr, 1uLL, v7, s);
}
v8 = 0;
LABEL_18:
if ( stream == stdin )
fflush(stream);
else
fclose(stream);
if ( s == stdout )
fflush(s);
else
fclose(s);
if ( v8 < 0 )
remove(filename);
return v8;
}

original_code: int main(){}

canonical_original_code: int main(){}


version

repo: sabotage-linux/gettext-tiny

decompiled_code:
size_t version()
{
return fwrite("msgfmt (GNU gettext-tools compatible) 99.9999.9999\n", 1uLL, 0x33uLL, stdout);
}

canonical_decompiled_code:
size_t func2()
{
return fwrite("msgfmt (GNU gettext-tools compatible) 99.9999.9999\n", 1uLL, 0x33uLL, stdout);
}

original_code:
static void version(void) {
 fprintf(stdout, "msgfmt (GNU gettext-tools compatible) 99.9999.9999\n");
}

canonical_original_code:
static void version() {
 fprintf(stdout, "msgfmt (GNU gettext-tools compatible) 99.9999.9999\n");
}

return_type: void


syntax

decompiled_code:
size_t syntax()
{
return fwrite("Usage: msgfmt [OPTION] filename.po ...\n", 1uLL, 0x27uLL, stdout);
}

canonical_decompiled_code:
size_t func3()
{
return fwrite("Usage: msgfmt [OPTION] filename.po ...\n", 1uLL, 0x27uLL, stdout);
}

original_code:
static void syntax(void) {
 fprintf(stdout, "Usage: msgfmt [OPTION] filename.po ...\n");
}

canonical_original_code:
static void syntax() {
 fprintf(stdout, "Usage: msgfmt [OPTION] filename.po ...\n");
}


gettext

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

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

original_code:
char *gettext(const char *msgid)
{
 return (char *) msgid;
}

canonical_original_code:
char *gettext(char *msgid)
{
 return (char *) msgid;
}

variable_types:
msgid
char *

return_type: char *


dgettext

decompiled_code:
__int64 __fastcall dgettext(__int64 a1, __int64 a2)
{
return a2;
}

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

original_code:
char *dgettext(const char *domainname, const char *msgid)
{
 (void) domainname;
 return (char *) msgid;
}

canonical_original_code:
char *dgettext(char *domainname, char *msgid)
{
 (void) domainname;
 return (char *) msgid;
}

variable_types:
domainname
char *


dcgettext

decompiled_code:
__int64 __fastcall dcgettext(__int64 a1, __int64 a2)
{
return a2;
}

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

original_code:
char *dcgettext(const char *domainname, const char *msgid, int category)
{
 (void) domainname;
 (void) category;
 return (char *) msgid;
}

canonical_original_code:
char *dcgettext(char *domainname, char *msgid, int category)
{
 (void) domainname;
 (void) category;
 return (char *) msgid;
}

variable_types: category int


ngettext

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

result = a2;
if ( a3 == 1 )
result = a1;
return result;
}

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

result = a2;
if ( a3 == 1 )
result = a1;
return result;
}

original_code:
char *ngettext(const char *msgid1, const char *msgid2, unsigned long n)
{
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

canonical_original_code:
char *ngettext(char *msgid1, char *msgid2, unsigned long n)
{
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

variable_types:
n
unsigned long


dngettext

decompiled_code:
__int64 __fastcall dngettext(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

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

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

original_code:
char *dngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long n)
{
 (void) domainname;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

canonical_original_code:
char *dngettext(char *domainname, char *msgid1, char *msgid2, unsigned long n)
{
 (void) domainname;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}


dcngettext

decompiled_code:
__int64 __fastcall dcngettext(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

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

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

original_code:
char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long n, int category)
{
 (void) domainname;
 (void) category;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

canonical_original_code:
char *dcngettext(char *domainname, char *msgid1, char *msgid2, unsigned long n, int category)
{
 (void) domainname;
 (void) category;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}


textdomain

decompiled_code:
const char *__fastcall textdomain(const char *a1)
{
const char *v1; // r12

v1 = "messages";
if ( a1 && *a1 && strcmp(a1, "messages") )
{
v1 = 0LL;
*_errno_location() = 22;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func6(const char *a1)
{
const char *v1; // r12

v1 = "messages";
if ( a1 && *a1 && strcmp(a1, "messages") )
{
v1 = 0LL;
*_errno_location() = 22;
}
return v1;
}

original_code:
char *textdomain(const char *domainname)
{
 static const char default_str[] = "messages";
 if (domainname && *domainname && strcmp(domainname, default_str)) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 return (char *) default_str;
}

canonical_original_code:
char *textdomain(char *domainname)
{
 static char default_str[] = "messages";
 if (domainname && *domainname && strcmp(domainname, default_str)) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 return (char *) default_str;
}


bindtextdomain

decompiled_code:
void *__fastcall bindtextdomain(_BYTE *a1, _BYTE *a2)
{
void *result; // rax

if ( !a1 || !*a1 || (result = &dir_0, a2) && (*a2 != 47 || a2[1]) )
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(_BYTE *a1, _BYTE *a2)
{
void *result; // rax

if ( !a1 || !*a1 || (result = &dir_0, a2) && (*a2 != 47 || a2[1]) )
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
char *bindtextdomain(const char *domainname, const char *dirname)
{
 static const char dir[] = "/";
 if (!domainname || !*domainname
  || (dirname && ((dirname[0] != '/') || dirname[1]))
  ) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 return (char *) dir;
}

canonical_original_code:
char *bindtextdomain(char *domainname, char *dirname)
{
 static char dir[] = "/";
 if (!domainname || !*domainname
  || (dirname && ((dirname[0] != '/') || dirname[1]))
  ) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 return (char *) dir;
}

variable_types:
dirname
char *

variable_types:
dir
char []


decompiled_code:
__int64 __fastcall bind_textdomain_codeset(_BYTE *a1, const char *a2)
{
if ( !a1 || !*a1 )
goto LABEL_3;
if ( !a2 )
return 0LL;
if ( strcasecmp(a2, "UTF-8") )
{
LABEL_3:
*_errno_location() = 22;
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, const char *a2)
{
if ( !a1 || !*a1 )
goto LABEL_3;
if ( !a2 )
return 0LL;
if ( strcasecmp(a2, "UTF-8") )
{
LABEL_3:
*_errno_location() = 22;
return 0LL;
}
return 0LL;
}

original_code:
char *bind_textdomain_codeset(const char *domainname, const char *codeset)
{
 if (!domainname || !*domainname || (codeset && strcasecmp(codeset, "UTF-8"))) {
  (*__errno_location ()) = 22;
 }
 return ((void *)0);
}

canonical_original_code:
char *bind_textdomain_codeset(char *domainname, char *codeset)
{
 if (!domainname || !*domainname || (codeset && strcasecmp(codeset, "UTF-8"))) {
  (*__errno_location ()) = 22;
 }
 return ((void *)0);
}

variable_types:
codeset
char *


escape

canonical_original_code:
unsigned long escape(char *in, char *out, unsigned long outsize) {
 unsigned long l = 0;
 while(*in && l + 3 < outsize) {
  switch(*in) {
   case '\n':
    *out++ = '\\';
    l++;
    *out = 'n';
    break;
   case '\r':
    *out++ = '\\';
    l++;
    *out = 'r';
    break;
   case '\t':
    *out++ = '\\';
    l++;
    *out = 't';
    break;
   case '\\':
    *out++ = '\\';
    l++;
    *out = '\\';
    break;
   case '"':
    *out++ = '\\';
    l++;
    *out = '"';
    break;
   case '\v':
    *out++ = '\\';
    l++;
    *out = 'v';
    break;
   case '\?':
    *out++ = '\\';
    l++;
    *out = '?';
    break;
   case '\f':
    *out++ = '\\';
    l++;
    *out = 'f';
    break;
   case '\b':
    *out++ = '\\';
    l++;
    *out = 'b';
    break;
   case '\a':
    *out++ = '\\';
    l++;
    *out = 'a';
    break;
   default:
    *out = *in;
  }
  in++;
  out++;
  l++;
 }
 *out = 0;
 return l;
}

variable_types:
in
char *

variable_types:
out
char *

variable_types:
outsize
unsigned long

variable_types:
l
unsigned long

return_type: unsigned long


getbackuptype

decompiled_code:
__int64 __fastcall getbackuptype(__int64 a1)
{
__int64 result; // rax
bool v3; // al
bool v4; // cf
bool v5; // zf
__int64 v6; // rcx
const char *v7; // rdi
const char *v8; // rsi

if ( !a1 || !*(_BYTE *)a1 )
return 0LL;
v5 = strcmp((const char *)a1, "none") == 0;
result = !v5;
if ( !v5 )
{
v5 = strcmp((const char *)a1, "off") == 0;
result = !v5;
if ( !v5 )
{
if ( *(_BYTE *)a1 != 116 || (result = 1LL, *(_BYTE *)(a1 + 1)) )
{
if ( !strcmp((const char *)a1, "numbered") )
{
result = 1LL;
}
else if ( !strcmp((const char *)a1, "nil") || !strcmp((const char *)a1, "existing") )
{
result = 2LL;
}
else
{
v3 = strcmp((const char *)a1, "simple") != 0;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = 6LL;
v7 = "never";
v8 = (const char *)a1;
do
{
if ( !v6 )
break;
v4 = *v8 < (unsigned int)*v7;
v5 = *v8++ == *v7++;
--v6;
}
while ( v5 );
if ( (!v4 && !v5) != v4 )
syntax(v7, v8, a1);
}
result = 3LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
bool v3; // al
bool v4; // cf
bool v5; // zf
__int64 v6; // rcx
const char *v7; // rdi
const char *v8; // rsi

if ( !a1 || !*(_BYTE *)a1 )
return 0LL;
v5 = strcmp((const char *)a1, "none") == 0;
result = !v5;
if ( !v5 )
{
v5 = strcmp((const char *)a1, "off") == 0;
result = !v5;
if ( !v5 )
{
if ( *(_BYTE *)a1 != 116 || (result = 1LL, *(_BYTE *)(a1 + 1)) )
{
if ( !strcmp((const char *)a1, "numbered") )
{
result = 1LL;
}
else if ( !strcmp((const char *)a1, "nil") || !strcmp((const char *)a1, "existing") )
{
result = 2LL;
}
else
{
v3 = strcmp((const char *)a1, "simple") != 0;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = 6LL;
v7 = "never";
v8 = (const char *)a1;
do
{
if ( !v6 )
break;
v4 = *v8 < (unsigned int)*v7;
v5 = *v8++ == *v7++;
--v6;
}
while ( v5 );
if ( (!v4 && !v5) != v4 )
func1(v7, v8, a1);
}
result = 3LL;
}
}
}
}
return result;
}

original_code:
int getbackuptype(char* str) {
 if(!str || !*str || (!strcmp(str, "none")) || (!strcmp(str, "off")))
  return 0;
 else if((!strcmp(str, "t")) || (!strcmp(str, "numbered")))
  return 1;
 else if((!strcmp(str, "nil")) || (!strcmp(str, "existing")))
  return 2;
 else if((!strcmp(str, "simple")) || (!strcmp(str, "never")))
  return 3;
 else syntax();
}

canonical_original_code:
int getbackuptype(char *str) {
 if(!str || !*str || (!strcmp(str, "none")) || (!strcmp(str, "off")))
  return 0;
 else if((!strcmp(str, "t")) || (!strcmp(str, "numbered")))
  return 1;
 else if((!strcmp(str, "nil")) || (!strcmp(str, "existing")))
  return 2;
 else if((!strcmp(str, "simple")) || (!strcmp(str, "never")))
  return 3;
 else syntax();
}

variable_types:
str
char *

return_type: int


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; // ebx
const char **v4; // r12
__int128 *v5; // rbp
char *v6; // rax
const char **v7; // r14
int v8; // er15
int v9; // er13
__int64 v10; // rbx
int v11; // er12
int v12; // er10
char *v13; // r9
bool v14; // cf
bool v15; // zf
int v16; // eax
FILE **v17; // rbx
int v18; // er13
struct _IO_FILE *v19; // rdi
unsigned int v21; // eax
__int64 v22; // rcx
char v23; // al
bool v24; // cf
bool v25; // zf
__int64 v26; // rcx
char v27; // al
bool v28; // cf
bool v29; // zf
__int64 v30; // rcx
const char *v31; // rsi
char *v32; // rdi
int v33; // eax
__int64 v34; // rdx
__int64 v35; // rcx
__int64 v36; // r8
char *v37; // r11
char *v38; // r9
char *v39; // rdi
int v40; // eax
int v41; // eax
int v42; // eax
unsigned int v43; // [rsp+0h] [rbp-98h]
char *v44; // [rsp+8h] [rbp-90h]
char *v45; // [rsp+8h] [rbp-90h]
char *v46; // [rsp+8h] [rbp-90h]
unsigned int v47; // [rsp+10h] [rbp-88h]
char *s1; // [rsp+18h] [rbp-80h]
char *s1a; // [rsp+18h] [rbp-80h]
char *s1b; // [rsp+18h] [rbp-80h]
__int128 v51; // [rsp+20h] [rbp-78h] BYREF
__int128 v52; // [rsp+30h] [rbp-68h] BYREF
__int128 v53; // [rsp+40h] [rbp-58h] BYREF
__int64 v54; // [rsp+50h] [rbp-48h]

if ( argc == 1 )
goto LABEL_111;
v3 = argc;
v4 = argv;
v53 = 0LL;
v5 = &v51;
v51 = 0LL;
v52 = 0LL;
v54 = 0LL;
LODWORD(v53) = 1;
getenv("SIMPLE_BACKUP_SUFFIX");
v6 = getenv("VERSION_CONTROL");
*(_QWORD *)&argc = 1LL;
argv = (const char **)"-";
getbackuptype((__int64)v6);
set_file(1, (__int64)"-", (FILE **)&v51);
if ( v3 <= 1 )
{
LABEL_15:
if ( (_QWORD)v51 && *((_QWORD *)&v51 + 1) && (_QWORD)v52 )
{
v17 = (FILE **)&v51;
v18 = process((__int64)&v51);
do
{
if ( *v17 )
fflush(*v17);
++v17;
}
while ( v17 != (FILE **)&v53 );
do
{
v19 = *(struct _IO_FILE **)v5;
if ( *(_QWORD *)v5 && v19 != stdout && v19 != stdin )
fclose(v19);
v5 = (__int128 *)((char *)v5 + 8);
}
while ( v5 != &v53 );
return v18;
}
LABEL_111:
syntax(*(_QWORD *)&argc, argv, envp);
}
v7 = v4 + 1;
v8 = 0;
v9 = 0;
v10 = (__int64)&v4[(unsigned int)(v3 - 2) + 2];
v43 = 0;
v11 = 0;
v47 = 1;
do
{
while ( 1 )
{
v13 = (char *)*v7;
if ( **v7 == 45 )
break;
if ( v8 )
{
if ( v9 )
{
v15 = strcmp(*v7, "/dev/null") == 0;
v12 = !v15;
if ( v15 )
return v12;
}
LABEL_7:
argv = (const char **)v13;
*(_QWORD *)&argc = 1LL;
v8 = 0;
set_file(1, (__int64)v13, (FILE **)&v51);
goto LABEL_8;
}
if ( v11 )
goto LABEL_82;
envp = (const char **)v47;
if ( v47 )
{
if ( v9 )
{
v15 = strcmp(*v7, "/dev/null") == 0;
v12 = !v15;
if ( v15 )
return v12;
}
LABEL_33:
argv = (const char **)v13;
*(_QWORD *)&argc = 0LL;
v8 = 0;
set_file(0, (__int64)v13, (FILE **)&v51 + 1);
v21 = v47;
v47 = 0;
v43 = v21;
goto LABEL_8;
}
if ( v43 )
{
if ( v9 )
{
v15 = strcmp(*v7, "/dev/null") == 0;
v12 = !v15;
if ( v15 )
return v12;
}
LABEL_81:
argv = (const char **)v13;
*(_QWORD *)&argc = 0LL;
v11 = 0;
set_file(0, (__int64)v13, (FILE **)&v52);
v8 = 0;
v43 = 0;
}
LABEL_8:
if ( ++v7 == (const char **)v10 )
goto LABEL_14;
}
v14 = (unsigned __int8)v13[1] < 0x2Du;
v15 = v13[1] == 45;
if ( v13[1] == 45 )
{
v22 = 7LL;
v44 = (char *)*v7;
*(_QWORD *)&argc = "strict";
argv = (const char **)(v13 + 2);
do
{
if ( !v22 )
break;
v14 = *(_BYTE *)argv < **(_BYTE **)&argc;
v15 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v22;
}
while ( v15 );
v23 = (!v14 && !v15) - v14;
v24 = 0;
v25 = v23 == 0;
if ( !v23 )
goto LABEL_8;
v26 = 17LL;
argv = (const char **)(v13 + 2);
*(_QWORD *)&argc = "properties-input";
do
{
if ( !v26 )
break;
v24 = *(_BYTE *)argv < **(_BYTE **)&argc;
v25 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v26;
}
while ( v25 );
v27 = (!v24 && !v25) - v24;
v28 = 0;
v29 = v27 == 0;
if ( !v27 )
goto LABEL_8;
v30 = 18LL;
argv = (const char **)(v13 + 2);
*(_QWORD *)&argc = "properties-output";
do
{
if ( !v30 )
break;
v28 = *(_BYTE *)argv < **(_BYTE **)&argc;
v29 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v30;
}
while ( v29 );
if ( (!v28 && !v29) == v28 )
goto LABEL_8;
argv = (const char **)"stringtable-input";
*(_QWORD *)&argc = v13 + 2;
s1 = v13 + 2;
if ( !strcmp(v13 + 2, "stringtable-input") )
goto LABEL_8;
argv = (const char **)"stringtable-output";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "stringtable-output") )
goto LABEL_8;
argv = (const char **)"no-fuzzy-matching";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-fuzzy-matching") )
goto LABEL_8;
argv = (const char **)"multi-domain";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "multi-domain") )
goto LABEL_8;
argv = (const char **)"previous";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "previous") )
goto LABEL_8;
argv = (const char **)"escape";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "escape") )
goto LABEL_8;
argv = (const char **)"no-escape";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-escape") )
goto LABEL_8;
argv = (const char **)"force-po";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "force-po") )
goto LABEL_8;
argv = (const char **)"indent";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "indent") )
goto LABEL_8;
argv = (const char **)"add-location";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "add-location") )
goto LABEL_8;
argv = (const char **)"no-location";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-location") )
goto LABEL_8;
argv = (const char **)"no-wrap";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-wrap") )
goto LABEL_8;
argv = (const char **)"sort-output";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "sort-output") )
goto LABEL_8;
argv = (const char **)"sort-by-file";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "sort-by-file") )
goto LABEL_8;
argv = (const char **)"lang=";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "lang=", 5uLL) )
goto LABEL_8;
argv = (const char **)"color";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "color", 5uLL) )
goto LABEL_8;
argv = (const char **)"style=";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "style=", 6uLL) )
goto LABEL_8;
argv = (const char **)"width=";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "width=", 6uLL) )
goto LABEL_8;
argv = (const char **)"verbose";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "verbose") )
goto LABEL_8;
argv = (const char **)"quiet";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "quiet") )
goto LABEL_8;
argv = (const char **)"silent";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "silent") )
goto LABEL_8;
v31 = "version";
v32 = s1;
v33 = strcmp(s1, "version");
v37 = s1;
v38 = v44;
if ( !v33 )
goto LABEL_113;
v39 = s1;
s1a = v44;
v45 = v37;
if ( !memcmp(v39, "output-file=", 0xCuLL) )
{
argv = (const char **)(s1a + 14);
*(_QWORD *)&argc = 1LL;
set_file(1, (__int64)(s1a + 14), (FILE **)&v51);
goto LABEL_8;
}
if ( !memcmp(v45, "compendium=", 0xBuLL) )
{
argv = (const char **)(s1a + 13);
*(_QWORD *)&argc = 1LL;
set_file(1, (__int64)(s1a + 13), (FILE **)&v52 + 1);
goto LABEL_8;
}
argv = (const char **)"suffix=";
*(_QWORD *)&argc = v45;
if ( memcmp(v45, "suffix=", 7uLL) )
{
if ( !memcmp(v45, "directory=", 0xAuLL) )
goto LABEL_112;
argv = (const char **)"backup";
*(_QWORD *)&argc = v45;
if ( !memcmp(v45, "backup", 6uLL) )
{
if ( s1a[8] == 61 )
{
*(_QWORD *)&argc = s1a + 9;
getbackuptype((__int64)(s1a + 9));
}
goto LABEL_8;
}
argv = (const char **)"update";
*(_QWORD *)&argc = v45;
if ( !strcmp(v45, "update") )
{
LABEL_85:
v9 = 1;
goto LABEL_8;
}
argv = (const char **)"help";
*(_QWORD *)&argc = v45;
if ( !strcmp(v45, "help") )
goto LABEL_111;
}
goto LABEL_8;
}
v16 = (unsigned __int8)v13[1];
*(_QWORD *)&argc = v13 + 1;
if ( v16 != 111 || v13[2] )
{
if ( v16 == 67 && !v13[2] )
{
v11 = 1;
goto LABEL_8;
}
if ( v16 == 85 && !v13[2] )
goto LABEL_85;
if ( v16 == 109 && !v13[2] )
goto LABEL_8;
if ( v16 == 78 && !v13[2] )
goto LABEL_8;
argv = (const char **)"P";
s1b = (char *)*v7;
v46 = v13 + 1;
if ( !strcmp(*(const char **)&argc, "P") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"e";
if ( !strcmp(v46, "e") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"E";
if ( !strcmp(v46, "E") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"i";
if ( !strcmp(v46, "i") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"p";
if ( !strcmp(v46, "p") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"w";
if ( !strcmp(v46, "w") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"s";
if ( !strcmp(v46, "s") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"F";
if ( !strcmp(v46, "F") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"V";
if ( !strcmp(v46, "V") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"q";
if ( !strcmp(v46, "q") )
goto LABEL_8;
v32 = v46;
v31 = "v";
if ( !strcmp(v46, "v") )
LABEL_113:
version(v32, v31, v34, v35, v36, v38);
*(_QWORD *)&argc = v46;
if ( !strcmp(v46, "D") )
{
LABEL_112:
fwrite("EINVAL\n", 1uLL, 7uLL, stderr);
exit(1);
}
argv = (const char **)"h";
if ( !strcmp(v46, "h") )
goto LABEL_111;
v13 = s1b;
if ( !v8 )
{
if ( v11 )
{
LABEL_82:
argv = (const char **)v13;
*(_QWORD *)&argc = 1LL;
v11 = 0;
set_file(1, (__int64)v13, (FILE **)&v52 + 1);
goto LABEL_8;
}
if ( !v47 )
{
if ( !v43 )
goto LABEL_8;
if ( v9 )
{
v42 = strcmp(s1b, "/dev/null");
v13 = s1b;
v12 = v42;
if ( !v42 )
return v12;
}
goto LABEL_81;
}
if ( v9 )
{
v41 = strcmp(s1b, "/dev/null");
v13 = s1b;
v12 = v41;
if ( !v41 )
return v12;
}
goto LABEL_33;
}
if ( v9 )
{
v40 = strcmp(s1b, "/dev/null");
v13 = s1b;
v12 = v40;
if ( !v40 )
return v12;
}
goto LABEL_7;
}
++v7;
v8 = 1;
}
while ( v7 != (const char **)v10 );
LABEL_14:
if ( !v9 )
goto LABEL_15;
fwrite("warning: update functionality unimplemented\n", 1uLL, 0x2CuLL, stdout);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char **v4; // r12
__int128 *v5; // rbp
char *v6; // rax
const char **v7; // r14
int v8; // er15
int v9; // er13
__int64 v10; // rbx
int v11; // er12
int v12; // er10
char *v13; // r9
bool v14; // cf
bool v15; // zf
int v16; // eax
FILE **v17; // rbx
int v18; // er13
struct _IO_FILE *v19; // rdi
unsigned int v21; // eax
__int64 v22; // rcx
char v23; // al
bool v24; // cf
bool v25; // zf
__int64 v26; // rcx
char v27; // al
bool v28; // cf
bool v29; // zf
__int64 v30; // rcx
const char *v31; // rsi
char *v32; // rdi
int v33; // eax
__int64 v34; // rdx
__int64 v35; // rcx
__int64 v36; // r8
char *v37; // r11
char *v38; // r9
char *v39; // rdi
int v40; // eax
int v41; // eax
int v42; // eax
unsigned int v43; // [rsp+0h] [rbp-98h]
char *v44; // [rsp+8h] [rbp-90h]
char *v45; // [rsp+8h] [rbp-90h]
char *v46; // [rsp+8h] [rbp-90h]
unsigned int v47; // [rsp+10h] [rbp-88h]
char *s1; // [rsp+18h] [rbp-80h]
char *s1a; // [rsp+18h] [rbp-80h]
char *s1b; // [rsp+18h] [rbp-80h]
__int128 v51; // [rsp+20h] [rbp-78h] BYREF
__int128 v52; // [rsp+30h] [rbp-68h] BYREF
__int128 v53; // [rsp+40h] [rbp-58h] BYREF
__int64 v54; // [rsp+50h] [rbp-48h]

if ( argc == 1 )
goto LABEL_111;
v3 = argc;
v4 = argv;
v53 = 0LL;
v5 = &v51;
v51 = 0LL;
v52 = 0LL;
v54 = 0LL;
LODWORD(v53) = 1;
getenv("SIMPLE_BACKUP_SUFFIX");
v6 = getenv("VERSION_CONTROL");
*(_QWORD *)&argc = 1LL;
argv = (const char **)"-";
func4((__int64)v6);
set_file(1, (__int64)"-", (FILE **)&v51);
if ( v3 <= 1 )
{
LABEL_15:
if ( (_QWORD)v51 && *((_QWORD *)&v51 + 1) && (_QWORD)v52 )
{
v17 = (FILE **)&v51;
v18 = func3((__int64)&v51);
do
{
if ( *v17 )
fflush(*v17);
++v17;
}
while ( v17 != (FILE **)&v53 );
do
{
v19 = *(struct _IO_FILE **)v5;
if ( *(_QWORD *)v5 && v19 != stdout && v19 != stdin )
fclose(v19);
v5 = (__int128 *)((char *)v5 + 8);
}
while ( v5 != &v53 );
return v18;
}
LABEL_111:
func1(*(_QWORD *)&argc, argv, envp);
}
v7 = v4 + 1;
v8 = 0;
v9 = 0;
v10 = (__int64)&v4[(unsigned int)(v3 - 2) + 2];
v43 = 0;
v11 = 0;
v47 = 1;
do
{
while ( 1 )
{
v13 = (char *)*v7;
if ( **v7 == 45 )
break;
if ( v8 )
{
if ( v9 )
{
v15 = strcmp(*v7, "/dev/null") == 0;
v12 = !v15;
if ( v15 )
return v12;
}
LABEL_7:
argv = (const char **)v13;
*(_QWORD *)&argc = 1LL;
v8 = 0;
set_file(1, (__int64)v13, (FILE **)&v51);
goto LABEL_8;
}
if ( v11 )
goto LABEL_82;
envp = (const char **)v47;
if ( v47 )
{
if ( v9 )
{
v15 = strcmp(*v7, "/dev/null") == 0;
v12 = !v15;
if ( v15 )
return v12;
}
LABEL_33:
argv = (const char **)v13;
*(_QWORD *)&argc = 0LL;
v8 = 0;
set_file(0, (__int64)v13, (FILE **)&v51 + 1);
v21 = v47;
v47 = 0;
v43 = v21;
goto LABEL_8;
}
if ( v43 )
{
if ( v9 )
{
v15 = strcmp(*v7, "/dev/null") == 0;
v12 = !v15;
if ( v15 )
return v12;
}
LABEL_81:
argv = (const char **)v13;
*(_QWORD *)&argc = 0LL;
v11 = 0;
set_file(0, (__int64)v13, (FILE **)&v52);
v8 = 0;
v43 = 0;
}
LABEL_8:
if ( ++v7 == (const char **)v10 )
goto LABEL_14;
}
v14 = (unsigned __int8)v13[1] < 0x2Du;
v15 = v13[1] == 45;
if ( v13[1] == 45 )
{
v22 = 7LL;
v44 = (char *)*v7;
*(_QWORD *)&argc = "strict";
argv = (const char **)(v13 + 2);
do
{
if ( !v22 )
break;
v14 = *(_BYTE *)argv < **(_BYTE **)&argc;
v15 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v22;
}
while ( v15 );
v23 = (!v14 && !v15) - v14;
v24 = 0;
v25 = v23 == 0;
if ( !v23 )
goto LABEL_8;
v26 = 17LL;
argv = (const char **)(v13 + 2);
*(_QWORD *)&argc = "properties-input";
do
{
if ( !v26 )
break;
v24 = *(_BYTE *)argv < **(_BYTE **)&argc;
v25 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v26;
}
while ( v25 );
v27 = (!v24 && !v25) - v24;
v28 = 0;
v29 = v27 == 0;
if ( !v27 )
goto LABEL_8;
v30 = 18LL;
argv = (const char **)(v13 + 2);
*(_QWORD *)&argc = "properties-output";
do
{
if ( !v30 )
break;
v28 = *(_BYTE *)argv < **(_BYTE **)&argc;
v29 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v30;
}
while ( v29 );
if ( (!v28 && !v29) == v28 )
goto LABEL_8;
argv = (const char **)"stringtable-input";
*(_QWORD *)&argc = v13 + 2;
s1 = v13 + 2;
if ( !strcmp(v13 + 2, "stringtable-input") )
goto LABEL_8;
argv = (const char **)"stringtable-output";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "stringtable-output") )
goto LABEL_8;
argv = (const char **)"no-fuzzy-matching";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-fuzzy-matching") )
goto LABEL_8;
argv = (const char **)"multi-domain";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "multi-domain") )
goto LABEL_8;
argv = (const char **)"previous";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "previous") )
goto LABEL_8;
argv = (const char **)"escape";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "escape") )
goto LABEL_8;
argv = (const char **)"no-escape";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-escape") )
goto LABEL_8;
argv = (const char **)"force-po";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "force-po") )
goto LABEL_8;
argv = (const char **)"indent";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "indent") )
goto LABEL_8;
argv = (const char **)"add-location";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "add-location") )
goto LABEL_8;
argv = (const char **)"no-location";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-location") )
goto LABEL_8;
argv = (const char **)"no-wrap";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "no-wrap") )
goto LABEL_8;
argv = (const char **)"sort-output";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "sort-output") )
goto LABEL_8;
argv = (const char **)"sort-by-file";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "sort-by-file") )
goto LABEL_8;
argv = (const char **)"lang=";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "lang=", 5uLL) )
goto LABEL_8;
argv = (const char **)"color";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "color", 5uLL) )
goto LABEL_8;
argv = (const char **)"style=";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "style=", 6uLL) )
goto LABEL_8;
argv = (const char **)"width=";
*(_QWORD *)&argc = s1;
if ( !memcmp(s1, "width=", 6uLL) )
goto LABEL_8;
argv = (const char **)"verbose";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "verbose") )
goto LABEL_8;
argv = (const char **)"quiet";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "quiet") )
goto LABEL_8;
argv = (const char **)"silent";
*(_QWORD *)&argc = s1;
if ( !strcmp(s1, "silent") )
goto LABEL_8;
v31 = "version";
v32 = s1;
v33 = strcmp(s1, "version");
v37 = s1;
v38 = v44;
if ( !v33 )
goto LABEL_113;
v39 = s1;
s1a = v44;
v45 = v37;
if ( !memcmp(v39, "output-file=", 0xCuLL) )
{
argv = (const char **)(s1a + 14);
*(_QWORD *)&argc = 1LL;
set_file(1, (__int64)(s1a + 14), (FILE **)&v51);
goto LABEL_8;
}
if ( !memcmp(v45, "compendium=", 0xBuLL) )
{
argv = (const char **)(s1a + 13);
*(_QWORD *)&argc = 1LL;
set_file(1, (__int64)(s1a + 13), (FILE **)&v52 + 1);
goto LABEL_8;
}
argv = (const char **)"suffix=";
*(_QWORD *)&argc = v45;
if ( memcmp(v45, "suffix=", 7uLL) )
{
if ( !memcmp(v45, "directory=", 0xAuLL) )
goto LABEL_112;
argv = (const char **)"backup";
*(_QWORD *)&argc = v45;
if ( !memcmp(v45, "backup", 6uLL) )
{
if ( s1a[8] == 61 )
{
*(_QWORD *)&argc = s1a + 9;
func4((__int64)(s1a + 9));
}
goto LABEL_8;
}
argv = (const char **)"update";
*(_QWORD *)&argc = v45;
if ( !strcmp(v45, "update") )
{
LABEL_85:
v9 = 1;
goto LABEL_8;
}
argv = (const char **)"help";
*(_QWORD *)&argc = v45;
if ( !strcmp(v45, "help") )
goto LABEL_111;
}
goto LABEL_8;
}
v16 = (unsigned __int8)v13[1];
*(_QWORD *)&argc = v13 + 1;
if ( v16 != 111 || v13[2] )
{
if ( v16 == 67 && !v13[2] )
{
v11 = 1;
goto LABEL_8;
}
if ( v16 == 85 && !v13[2] )
goto LABEL_85;
if ( v16 == 109 && !v13[2] )
goto LABEL_8;
if ( v16 == 78 && !v13[2] )
goto LABEL_8;
argv = (const char **)"P";
s1b = (char *)*v7;
v46 = v13 + 1;
if ( !strcmp(*(const char **)&argc, "P") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"e";
if ( !strcmp(v46, "e") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"E";
if ( !strcmp(v46, "E") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"i";
if ( !strcmp(v46, "i") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"p";
if ( !strcmp(v46, "p") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"w";
if ( !strcmp(v46, "w") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"s";
if ( !strcmp(v46, "s") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"F";
if ( !strcmp(v46, "F") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"V";
if ( !strcmp(v46, "V") )
goto LABEL_8;
*(_QWORD *)&argc = v46;
argv = (const char **)"q";
if ( !strcmp(v46, "q") )
goto LABEL_8;
v32 = v46;
v31 = "v";
if ( !strcmp(v46, "v") )
LABEL_113:
func2(v32, v31, v34, v35, v36, v38);
*(_QWORD *)&argc = v46;
if ( !strcmp(v46, "D") )
{
LABEL_112:
fwrite("EINVAL\n", 1uLL, 7uLL, stderr);
exit(1);
}
argv = (const char **)"h";
if ( !strcmp(v46, "h") )
goto LABEL_111;
v13 = s1b;
if ( !v8 )
{
if ( v11 )
{
LABEL_82:
argv = (const char **)v13;
*(_QWORD *)&argc = 1LL;
v11 = 0;
set_file(1, (__int64)v13, (FILE **)&v52 + 1);
goto LABEL_8;
}
if ( !v47 )
{
if ( !v43 )
goto LABEL_8;
if ( v9 )
{
v42 = strcmp(s1b, "/dev/null");
v13 = s1b;
v12 = v42;
if ( !v42 )
return v12;
}
goto LABEL_81;
}
if ( v9 )
{
v41 = strcmp(s1b, "/dev/null");
v13 = s1b;
v12 = v41;
if ( !v41 )
return v12;
}
goto LABEL_33;
}
if ( v9 )
{
v40 = strcmp(s1b, "/dev/null");
v13 = s1b;
v12 = v40;
if ( !v40 )
return v12;
}
goto LABEL_7;
}
++v7;
v8 = 1;
}
while ( v7 != (const char **)v10 );
LABEL_14:
if ( !v9 )
goto LABEL_15;
fwrite("warning: update functionality unimplemented\n", 1uLL, 0x2CuLL, stdout);
return 0;
}


syntax

decompiled_code:
void __noreturn syntax()
{
fwrite("Usage: msgmerge [OPTION] def.po ref.pot\n", 1uLL, 0x28uLL, stdout);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fwrite("Usage: msgmerge [OPTION] def.po ref.pot\n", 1uLL, 0x28uLL, stdout);
exit(1);
}

original_code:
__attribute__((noreturn))
static void syntax(void) {
 fprintf(stdout,
 "Usage: msgmerge [OPTION] def.po ref.pot\n");
 exit(1);
}

canonical_original_code:
static void syntax() {
 fprintf(stdout,
 "Usage: msgmerge [OPTION] def.po ref.pot\n");
 exit(1);
}


version

decompiled_code:
void __noreturn version()
{
fwrite("msgmerge (GNU gettext-tools compatible) 99.9999.9999\n", 1uLL, 0x35uLL, stdout);
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
fwrite("msgmerge (GNU gettext-tools compatible) 99.9999.9999\n", 1uLL, 0x35uLL, stdout);
exit(0);
}

original_code:
__attribute__((noreturn))
static void version(void) {
 fprintf(stdout,
  "msgmerge (GNU gettext-tools compatible) 99.9999.9999\n");
 exit(0);
}

canonical_original_code:
static void version() {
 fprintf(stdout,
  "msgmerge (GNU gettext-tools compatible) 99.9999.9999\n");
 exit(0);
}


repo: sabotage-linux/libelf-compat

decompiled_code:
int elf_errno()
{
int result; // eax

result = global_error;
global_error = 0;
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = global_error;
global_error = 0;
return result;
}

original_code:
int
elf_errno (void)
{
  int result = global_error;
  global_error = ELF_E_NOERROR;
  return result;
}

canonical_original_code:
int elf_errno()
{
  int result = global_error;
  global_error = ELF_E_NOERROR;
  return result;
}

variable_types: result int


original_code:
static struct nlist_fshashent *
nlist_fshash_lookup (struct nlist_fshash *htab,
         size_t hval, struct hashentry *data)
{
  size_t idx = 1 + hval % htab->nslots;
  if (htab->table[idx].hval != 0)
    {
      size_t hash;
      if (htab->table[idx].hval == hval
   && strcmp ((data)->str, (&(htab->table[idx]).entry)->str) == 0)
 return &htab->table[idx];
      hash = 1 + hval % (htab->nslots - 2);
      do
 {
   if (idx <= hash)
     idx = htab->nslots + idx - hash;
   else
     idx -= hash;
   if (htab->table[idx].hval == hval
       && strcmp ((data)->str, (&(htab->table[idx]).entry)->str) == 0)
     return &htab->table[idx];
 }
      while (htab->table[idx].hval != 0);
    }
  return &htab->table[idx];
}

canonical_original_code:
static struct nlist_fshashent *nlist_fshash_lookup(struct nlist_fshash *htab, unsigned long hval, struct hashentry *data)
{
  unsigned long idx = 1 + hval % htab->nslots;
  if (htab->table[idx].hval != 0)
    {
      unsigned long hash;
      if (htab->table[idx].hval == hval
   && strcmp ((data)->str, (&(htab->table[idx]).entry)->str) == 0)
 return &htab->table[idx];
      hash = 1 + hval % (htab->nslots - 2);
      do
 {
   if (idx <= hash)
     idx = htab->nslots + idx - hash;
   else
     idx -= hash;
   if (htab->table[idx].hval == hval
       && strcmp ((data)->str, (&(htab->table[idx]).entry)->str) == 0)
     return &htab->table[idx];
 }
      while (htab->table[idx].hval != 0);
    }
  return &htab->table[idx];
}

variable_types: struct nlist_fshash { unsigned long nslots; struct nlist_fshashent table[]; } *

variable_types:
hval
unsigned long

variable_types:
data
struct hashentry *

variable_types:
idx
unsigned long

variable_types:
hash
unsigned long

return_type: struct nlist_fshashent { unsigned long hval; struct hashentry { char *str; 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; } sym; } entry; } *

user_defined_types: struct nlist_fshashent { unsigned long hval; struct hashentry entry; }

user_defined_types: struct hashentry { char *str; struct Elf64_Sym sym; }


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

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

original_code:
static void
nlist_fshash_fini (struct nlist_fshash *htab)
{
  free (htab);
}

canonical_original_code:
static void nlist_fshash_fini(struct nlist_fshash *htab)
{
  free (htab);
}

variable_types: struct nlist_fshash { unsigned long nslots; struct nlist_fshashent { unsigned long hval; struct hashentry { char *str; 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; } sym; } entry; } table[]; } *

user_defined_types: struct nlist_fshash { unsigned long nslots; struct nlist_fshashent table[]; }


nlist

decompiled_code:
__int64 __fastcall nlist(const char *a1, __int64 a2)
{
int v3; // eax
unsigned int v4; // er12
__int64 v5; // rbp
char *v6; // rbx
char *v7; // r13
char *v8; // rsi
__int64 v9; // rax
__int64 v10; // r14
int v11; // eax
__int64 v12; // rax
__int64 v14; // rax
__int64 v15; // r13
__int64 v16; // rbx
const char *v17; // rax
const char *v18; // rsi
unsigned int *v19; // rax
char v20; // al
_BYTE *v21; // rsi
_QWORD *v22; // rax
__int64 *ptr; // [rsp+8h] [rbp-B0h]
unsigned __int64 v24; // [rsp+10h] [rbp-A8h]
unsigned __int64 v25; // [rsp+18h] [rbp-A0h]
const char *v26; // [rsp+20h] [rbp-98h] BYREF
char v27[24]; // [rsp+28h] [rbp-90h] BYREF
char v28[120]; // [rsp+40h] [rbp-78h] BYREF

v3 = open(a1, 0);
if ( v3 == -1 )
{
_libelf_seterrno(38LL);
LABEL_16:
while ( *(_QWORD *)a2 && **(_BYTE **)a2 )
{
*(_QWORD *)(a2 + 8) = 0LL;
a2 += 24LL;
*(_WORD *)(a2 - 8) = 0;
*(_WORD *)(a2 - 6) = 0;
*(_BYTE *)(a2 - 4) = 0;
*(_BYTE *)(a2 - 3) = 0;
}
return 0xFFFFFFFFLL;
}
v4 = v3;
if ( !_libelf_version_initialized )
elf_version(1LL);
v5 = elf_begin(v4, 8LL, 0LL);
if ( !v5 )
{
LABEL_13:
close(v4);
goto LABEL_16;
}
v6 = 0LL;
v7 = 0LL;
while ( 1 )
{
v8 = v7;
v12 = elf_nextscn(v5, v7);
v7 = (char *)v12;
if ( !v12 )
break;
v8 = v28;
v9 = gelf_getshdr(v12, v28);
v10 = v9;
if ( !v9 )
goto LABEL_12;
v11 = *(_DWORD *)(v9 + 4);
if ( v11 == 2 )
goto LABEL_19;
if ( v11 == 11 )
v6 = v7;
}
if ( !v6 )
goto LABEL_12;
v7 = v6;
v10 = gelf_getshdr(v6, v28);
LABEL_19:
v8 = 0LL;
v14 = elf_getdata(v7, 0LL);
v15 = v14;
if ( !v14 )
{
LABEL_12:
elf_end(v5, v8);
goto LABEL_13;
}
v8 = (_BYTE *)&loc_B;
v24 = *(_QWORD *)(v10 + 32);
v25 = gelf_fsize(v5, 11LL, 1LL, *(unsigned int *)(v14 + 12));
ptr = nlist_fshash_init(v24 / v25);
if ( !ptr )
{
_libelf_seterrno(8LL);
goto LABEL_12;
}
v16 = 0LL;
if ( v24 >= v25 )
{
while ( 1 )
{
v18 = (const char *)(unsigned int)v16;
v19 = (unsigned int *)gelf_getsym(v15, (unsigned int)v16, v27);
if ( !v19 )
break;
v17 = (const char *)elf_strptr(v5, *(unsigned int *)(v10 + 40), *v19);
v26 = v17;
v18 = v17;
if ( !v17 )
break;
if ( *v17 )
nlist_fshash_overwrite_constprop_0_isra_0(ptr, (__int64)v17, (__int64)&v26);
if ( v24 / v25 <= ++v16 )
goto LABEL_31;
}
nlist_fshash_fini(ptr);
elf_end(v5, v18);
goto LABEL_13;
}
LABEL_31:
while ( 1 )
{
v21 = *(_BYTE **)a2;
if ( !*(_QWORD *)a2 || !*v21 )
break;
v26 = *(const char **)a2;
v22 = nlist_fshash_find_constprop_0(ptr, (__int64)v21, &v26);
if ( v22 )
{
*(_QWORD *)(a2 + 8) = v22[2];
*(_WORD *)(a2 + 16) = *((_WORD *)v22 + 7);
v20 = *((_BYTE *)v22 + 12);
*(_BYTE *)(a2 + 20) = 0;
*(_BYTE *)(a2 + 21) = 0;
*(_WORD *)(a2 + 18) = v20 & 0xF;
}
else
{
*(_BYTE *)(a2 + 20) = 0;
*(_QWORD *)(a2 + 8) = 0LL;
*(_WORD *)(a2 + 16) = 0;
*(_WORD *)(a2 + 18) = 0;
*(_BYTE *)(a2 + 21) = 0;
}
a2 += 24LL;
}
nlist_fshash_fini(ptr);
elf_end(v5, v21);
close(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2)
{
int v3; // eax
unsigned int v4; // er12
__int64 v5; // rbp
char *v6; // rbx
char *v7; // r13
char *v8; // rsi
__int64 v9; // rax
__int64 v10; // r14
int v11; // eax
__int64 v12; // rax
__int64 v14; // rax
__int64 v15; // r13
__int64 v16; // rbx
const char *v17; // rax
const char *v18; // rsi
unsigned int *v19; // rax
char v20; // al
_BYTE *v21; // rsi
_QWORD *v22; // rax
__int64 *ptr; // [rsp+8h] [rbp-B0h]
unsigned __int64 v24; // [rsp+10h] [rbp-A8h]
unsigned __int64 v25; // [rsp+18h] [rbp-A0h]
const char *v26; // [rsp+20h] [rbp-98h] BYREF
char v27[24]; // [rsp+28h] [rbp-90h] BYREF
char v28[120]; // [rsp+40h] [rbp-78h] BYREF

v3 = open(a1, 0);
if ( v3 == -1 )
{
_libelf_seterrno(38LL);
LABEL_16:
while ( *(_QWORD *)a2 && **(_BYTE **)a2 )
{
*(_QWORD *)(a2 + 8) = 0LL;
a2 += 24LL;
*(_WORD *)(a2 - 8) = 0;
*(_WORD *)(a2 - 6) = 0;
*(_BYTE *)(a2 - 4) = 0;
*(_BYTE *)(a2 - 3) = 0;
}
return 0xFFFFFFFFLL;
}
v4 = v3;
if ( !_libelf_version_initialized )
elf_version(1LL);
v5 = elf_begin(v4, 8LL, 0LL);
if ( !v5 )
{
LABEL_13:
close(v4);
goto LABEL_16;
}
v6 = 0LL;
v7 = 0LL;
while ( 1 )
{
v8 = v7;
v12 = elf_nextscn(v5, v7);
v7 = (char *)v12;
if ( !v12 )
break;
v8 = v28;
v9 = gelf_getshdr(v12, v28);
v10 = v9;
if ( !v9 )
goto LABEL_12;
v11 = *(_DWORD *)(v9 + 4);
if ( v11 == 2 )
goto LABEL_19;
if ( v11 == 11 )
v6 = v7;
}
if ( !v6 )
goto LABEL_12;
v7 = v6;
v10 = gelf_getshdr(v6, v28);
LABEL_19:
v8 = 0LL;
v14 = elf_getdata(v7, 0LL);
v15 = v14;
if ( !v14 )
{
LABEL_12:
elf_end(v5, v8);
goto LABEL_13;
}
v8 = (_BYTE *)&loc_B;
v24 = *(_QWORD *)(v10 + 32);
v25 = gelf_fsize(v5, 11LL, 1LL, *(unsigned int *)(v14 + 12));
ptr = nlist_fshash_init(v24 / v25);
if ( !ptr )
{
_libelf_seterrno(8LL);
goto LABEL_12;
}
v16 = 0LL;
if ( v24 >= v25 )
{
while ( 1 )
{
v18 = (const char *)(unsigned int)v16;
v19 = (unsigned int *)gelf_getsym(v15, (unsigned int)v16, v27);
if ( !v19 )
break;
v17 = (const char *)elf_strptr(v5, *(unsigned int *)(v10 + 40), *v19);
v26 = v17;
v18 = v17;
if ( !v17 )
break;
if ( *v17 )
func2(ptr, (__int64)v17, (__int64)&v26);
if ( v24 / v25 <= ++v16 )
goto LABEL_31;
}
func1(ptr);
elf_end(v5, v18);
goto LABEL_13;
}
LABEL_31:
while ( 1 )
{
v21 = *(_BYTE **)a2;
if ( !*(_QWORD *)a2 || !*v21 )
break;
v26 = *(const char **)a2;
v22 = nlist_fshash_find_constprop_0(ptr, (__int64)v21, &v26);
if ( v22 )
{
*(_QWORD *)(a2 + 8) = v22[2];
*(_WORD *)(a2 + 16) = *((_WORD *)v22 + 7);
v20 = *((_BYTE *)v22 + 12);
*(_BYTE *)(a2 + 20) = 0;
*(_BYTE *)(a2 + 21) = 0;
*(_WORD *)(a2 + 18) = v20 & 0xF;
}
else
{
*(_BYTE *)(a2 + 20) = 0;
*(_QWORD *)(a2 + 8) = 0LL;
*(_WORD *)(a2 + 16) = 0;
*(_WORD *)(a2 + 18) = 0;
*(_BYTE *)(a2 + 21) = 0;
}
a2 += 24LL;
}
func1(ptr);
elf_end(v5, v21);
close(v4);
return 0LL;
}

original_code:
int
nlist (const char *filename, struct nlist *nl)
{
  int fd;
  Elf *elf;
  Elf_Scn *scn = ((void *)0);
  Elf_Scn *symscn = ((void *)0);
  GElf_Shdr shdr_mem;
  GElf_Shdr *shdr = ((void *)0);
  Elf_Data *data;
  struct nlist_fshash *table;
  size_t nsyms;
  size_t cnt;
  fd = open (filename, 00);
  if (fd == -1)
    {
      __libelf_seterrno (ELF_E_NOFILE);
      goto fail;
    }
  if (__libelf_version_initialized == 0)
    elf_version (1);
  elf = elf_begin (fd, ELF_C_READ_MMAP, ((void *)0));
  if (elf == ((void *)0))
    goto fail_fd;
  while ((scn = elf_nextscn (elf, scn)) != ((void *)0))
    {
      shdr = gelf_getshdr (scn, &shdr_mem);
      if (shdr == ((void *)0))
 goto fail_close;
      if (shdr->sh_type == 2)
 {
   symscn = scn;
   break;
 }
      if (shdr->sh_type == 11)
 symscn = scn;
    }
  if (symscn == ((void *)0))
    goto fail_close;
  if (scn == ((void *)0))
    shdr = gelf_getshdr (symscn, &shdr_mem);
  data = elf_getdata (symscn, ((void *)0));
  if (data == ((void *)0))
    goto fail_close;
  nsyms = (shdr->sh_size
    / gelf_fsize (elf, ELF_T_SYM, 1, data->d_version));
  table = nlist_fshash_init (nsyms);
  if (table == ((void *)0))
    {
      __libelf_seterrno (ELF_E_NOMEM);
      goto fail_close;
    }
  for (cnt = 0; cnt < nsyms; ++cnt)
    {
      struct hashentry mem;
      GElf_Sym *sym;
      sym = gelf_getsym (data, cnt, &mem.sym);
      if (sym == ((void *)0))
 goto fail_dealloc;
      mem.str = elf_strptr (elf, shdr->sh_link, sym->st_name);
      if (mem.str == ((void *)0))
 goto fail_dealloc;
      if (mem.str[0] == '\0')
 continue;
      (void) nlist_fshash_overwrite (table, mem.str, 0, &mem);
    }
  while (nl->n_name != ((void *)0) && nl->n_name[0] != '\0')
    {
      struct hashentry search;
      const struct hashentry *found;
      search.str = nl->n_name;
      found = nlist_fshash_find (table, nl->n_name, 0, &search);
      if (found != ((void *)0))
 {
   nl->n_value = found->sym.st_value;
   nl->n_scnum = found->sym.st_shndx;
   nl->n_type = ((found->sym.st_info) & 0xf);
   nl->n_sclass = 0;
   nl->n_numaux = 0;
 }
      else
 {
   nl->n_value = 0;
   nl->n_scnum = 0;
   nl->n_type = 0;
   nl->n_sclass = 0;
   nl->n_numaux = 0;
 }
      ++nl;
    }
  nlist_fshash_fini (table);
  (void) elf_end (elf);
  (void) close (fd);
  return 0;
 fail_dealloc:
  nlist_fshash_fini (table);
 fail_close:
  (void) elf_end (elf);
 fail_fd:
  (void) close (fd);
 fail:
  while (nl->n_name != ((void *)0) && nl->n_name[0] != '\0')
    {
      nl->n_value = 0;
      nl->n_scnum = 0;
      nl->n_type = 0;
      nl->n_sclass = 0;
      nl->n_numaux = 0;
      ++nl;
    }
  return -1;
}

canonical_original_code:
int nlist(char *filename, struct nlist *nl)
{
  int fd;
  struct Elf *elf;
  struct Elf_Scn *scn = ((void *)0);
  struct Elf_Scn *symscn = ((void *)0);
  struct Elf64_Shdr shdr_mem;
  struct Elf64_Shdr *shdr = ((void *)0);
  struct Elf_Data *data;
  struct nlist_fshash *table;
  unsigned long nsyms;
  unsigned long cnt;
  fd = open (filename, 00);
  if (fd == -1)
    {
      __libelf_seterrno (ELF_E_NOFILE);
      goto fail;
    }
  if (__libelf_version_initialized == 0)
    elf_version (1);
  elf = elf_begin (fd, ELF_C_READ_MMAP, ((void *)0));
  if (elf == ((void *)0))
    goto fail_fd;
  while ((scn = elf_nextscn (elf, scn)) != ((void *)0))
    {
      shdr = gelf_getshdr (scn, &shdr_mem);
      if (shdr == ((void *)0))
 goto fail_close;
      if (shdr->sh_type == 2)
 {
   symscn = scn;
   break;
 }
      if (shdr->sh_type == 11)
 symscn = scn;
    }
  if (symscn == ((void *)0))
    goto fail_close;
  if (scn == ((void *)0))
    shdr = gelf_getshdr (symscn, &shdr_mem);
  data = elf_getdata (symscn, ((void *)0));
  if (data == ((void *)0))
    goto fail_close;
  nsyms = (shdr->sh_size
    / gelf_fsize (elf, ELF_T_SYM, 1, data->d_version));
  table = nlist_fshash_init (nsyms);
  if (table == ((void *)0))
    {
      __libelf_seterrno (ELF_E_NOMEM);
      goto fail_close;
    }
  for (cnt = 0; cnt < nsyms; ++cnt)
    {
      struct hashentry mem;
      struct Elf64_Sym *sym;
      sym = gelf_getsym (data, cnt, &mem.sym);
      if (sym == ((void *)0))
 goto fail_dealloc;
      mem.str = elf_strptr (elf, shdr->sh_link, sym->st_name);
      if (mem.str == ((void *)0))
 goto fail_dealloc;
      if (mem.str[0] == '\0')
 continue;
      (void) nlist_fshash_overwrite (table, mem.str, 0, &mem);
    }
  while (nl->n_name != ((void *)0) && nl->n_name[0] != '\0')
    {
      struct hashentry search;
      struct hashentry *found;
      search.str = nl->n_name;
      found = nlist_fshash_find (table, nl->n_name, 0, &search);
      if (found != ((void *)0))
 {
   nl->n_value = found->sym.st_value;
   nl->n_scnum = found->sym.st_shndx;
   nl->n_type = ((found->sym.st_info) & 0xf);
   nl->n_sclass = 0;
   nl->n_numaux = 0;
 }
      else
 {
   nl->n_value = 0;
   nl->n_scnum = 0;
   nl->n_type = 0;
   nl->n_sclass = 0;
   nl->n_numaux = 0;
 }
      ++nl;
    }
  nlist_fshash_fini (table);
  (void) elf_end (elf);
  (void) close (fd);
  return 0;
 fail_dealloc:
  nlist_fshash_fini (table);
 fail_close:
  (void) elf_end (elf);
 fail_fd:
  (void) close (fd);
 fail:
  while (nl->n_name != ((void *)0) && nl->n_name[0] != '\0')
    {
      nl->n_value = 0;
      nl->n_scnum = 0;
      nl->n_type = 0;
      nl->n_sclass = 0;
      nl->n_numaux = 0;
      ++nl;
    }
  return -1;
}

variable_types:
filename
char *

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

variable_types: fd int

variable_types: struct Elf { void *map_address; struct Elf *parent; struct Elf *next; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } kind; enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_RDWR=2, ELF_C_WRITE=3, ELF_C_CLR=4, ELF_C_SET=5, ELF_C_FDDONE=6, ELF_C_FDREAD=7, ELF_C_READ_MMAP=8, ELF_C_RDWR_MMAP=9, ELF_C_WRITE_MMAP=10, ELF_C_READ_MMAP_PRIVATE=11, ELF_C_EMPTY=12, ELF_C_NUM=13 } cmd; unsigned int class; int fildes; long start_offset; unsigned long maximum_size; int flags; int ref_count; int lock; union { struct { void *ehdr; void *shdr; void *phdr; struct Elf_ScnList { unsigned int cnt; unsigned int max; struct Elf_ScnList *next; struct Elf_Scn { struct Elf_Data_List { struct Elf_Data_Scn { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_XWORD=13, ELF_T_SXWORD=14, ELF_T_VDEF=15, ELF_T_VDAUX=16, ELF_T_VNEED=17, ELF_T_VNAUX=18, ELF_T_NHDR=19, ELF_T_SYMINFO=20, ELF_T_MOVE=21, ELF_T_LIB=22, ELF_T_GNUHASH=23, ELF_T_AUXV=24, ELF_T_NUM=25 } d_type; unsigned int d_version; unsigned long d_size; long d_off; unsigned long d_align; } d; struct Elf_Scn *s; } data; struct Elf_Data_List *next; int flags; } data_list; struct Elf_Data_List *data_list_rear; struct Elf_Data_Scn rawdata; int data_read; int shndx_index; unsigned long index; struct Elf *elf; union { struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *e32; struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } *e64; } shdr; unsigned int shdr_flags; unsigned int flags; char *rawdata_base; char *data_base; struct Elf_ScnList *list; } data[]; } *scns_last; struct Elf_Data_Chunk { struct Elf_Data_Scn data; union { struct Elf_Scn dummy_scn; struct Elf_Data_Chunk *next; }; } *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; } elf; struct { struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf32_Shdr *shdr; struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf32_Ehdr ehdr_mem; char __e32scnspad[-1]; struct Elf_ScnList scns; } elf32; struct { struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf64_Shdr *shdr; struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf64_Ehdr ehdr_mem; struct Elf_ScnList scns; } elf64; struct { struct Elf *children; struct Elf_Arsym { char *as_name; unsigned long as_off; unsigned long as_hash; } *ar_sym; unsigned long ar_sym_num; char *long_names; unsigned long long_names_len; long offset; struct Elf_Arhdr { char *ar_name; long ar_date; unsigned int ar_uid; unsigned int ar_gid; unsigned int ar_mode; long ar_size; char *ar_rawname; } elf_ar_hdr; struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } ar_hdr; char ar_name[16]; char raw_name[17]; } ar; } state; } *

variable_types: struct Elf_Scn { struct Elf_Data_List { struct Elf_Data_Scn { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_XWORD=13, ELF_T_SXWORD=14, ELF_T_VDEF=15, ELF_T_VDAUX=16, ELF_T_VNEED=17, ELF_T_VNAUX=18, ELF_T_NHDR=19, ELF_T_SYMINFO=20, ELF_T_MOVE=21, ELF_T_LIB=22, ELF_T_GNUHASH=23, ELF_T_AUXV=24, ELF_T_NUM=25 } d_type; unsigned int d_version; unsigned long d_size; long d_off; unsigned long d_align; } d; struct Elf_Scn *s; } data; struct Elf_Data_List *next; int flags; } data_list; struct Elf_Data_List *data_list_rear; struct Elf_Data_Scn rawdata; int data_read; int shndx_index; unsigned long index; struct Elf { void *map_address; struct Elf *parent; struct Elf *next; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } kind; enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_RDWR=2, ELF_C_WRITE=3, ELF_C_CLR=4, ELF_C_SET=5, ELF_C_FDDONE=6, ELF_C_FDREAD=7, ELF_C_READ_MMAP=8, ELF_C_RDWR_MMAP=9, ELF_C_WRITE_MMAP=10, ELF_C_READ_MMAP_PRIVATE=11, ELF_C_EMPTY=12, ELF_C_NUM=13 } cmd; unsigned int class; int fildes; long start_offset; unsigned long maximum_size; int flags; int ref_count; int lock; union { struct { void *ehdr; void *shdr; void *phdr; struct Elf_ScnList { unsigned int cnt; unsigned int max; struct Elf_ScnList *next; struct Elf_Scn data[]; } *scns_last; struct Elf_Data_Chunk { struct Elf_Data_Scn data; union { struct Elf_Scn dummy_scn; struct Elf_Data_Chunk *next; }; } *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; } elf; struct { struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *shdr; struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf32_Ehdr ehdr_mem; char __e32scnspad[-1]; struct Elf_ScnList scns; } elf32; struct { struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } *shdr; struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf64_Ehdr ehdr_mem; struct Elf_ScnList scns; } elf64; struct { struct Elf *children; struct Elf_Arsym { char *as_name; unsigned long as_off; unsigned long as_hash; } *ar_sym; unsigned long ar_sym_num; char *long_names; unsigned long long_names_len; long offset; struct Elf_Arhdr { char *ar_name; long ar_date; unsigned int ar_uid; unsigned int ar_gid; unsigned int ar_mode; long ar_size; char *ar_rawname; } elf_ar_hdr; struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } ar_hdr; char ar_name[16]; char raw_name[17]; } ar; } state; } *elf; union { struct Elf32_Shdr *e32; struct Elf64_Shdr *e64; } shdr; unsigned int shdr_flags; unsigned int flags; char *rawdata_base; char *data_base; struct Elf_ScnList *list; } *

variable_types: struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_XWORD=13, ELF_T_SXWORD=14, ELF_T_VDEF=15, ELF_T_VDAUX=16, ELF_T_VNEED=17, ELF_T_VNAUX=18, ELF_T_NHDR=19, ELF_T_SYMINFO=20, ELF_T_MOVE=21, ELF_T_LIB=22, ELF_T_GNUHASH=23, ELF_T_AUXV=24, ELF_T_NUM=25 } d_type; unsigned int d_version; unsigned long d_size; long d_off; unsigned long d_align; } *

variable_types:
nsyms
unsigned long

variable_types:
cnt
unsigned long

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

variable_types: struct hashentry { char *str; 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; } sym; } *

user_defined_types: struct Elf { void *map_address; struct Elf *parent; struct Elf *next; enum Elf_Kind kind; enum Elf_Cmd cmd; unsigned int class; int fildes; long start_offset; unsigned long maximum_size; int flags; int ref_count; int lock; union { struct { void *ehdr; void *shdr; void *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; } elf; struct { struct Elf32_Ehdr *ehdr; struct Elf32_Shdr *shdr; struct Elf32_Phdr *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf32_Ehdr ehdr_mem; char __e32scnspad[-1]; struct Elf_ScnList scns; } elf32; struct { struct Elf64_Ehdr *ehdr; struct Elf64_Shdr *shdr; struct Elf64_Phdr *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf64_Ehdr ehdr_mem; struct Elf_ScnList scns; } elf64; struct { struct Elf *children; struct Elf_Arsym *ar_sym; unsigned long ar_sym_num; char *long_names; unsigned long long_names_len; long offset; struct Elf_Arhdr elf_ar_hdr; struct ar_hdr ar_hdr; char ar_name[16]; char raw_name[17]; } ar; } state; }

user_defined_types: struct Elf_Scn { struct Elf_Data_List data_list; struct Elf_Data_List *data_list_rear; struct Elf_Data_Scn rawdata; int data_read; int shndx_index; unsigned long index; struct Elf *elf; union { struct Elf32_Shdr *e32; struct Elf64_Shdr *e64; } shdr; unsigned int shdr_flags; unsigned int flags; char *rawdata_base; char *data_base; struct Elf_ScnList *list; }

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

user_defined_types: struct Elf_Data_List { struct Elf_Data_Scn data; struct Elf_Data_List *next; int flags; }

user_defined_types: struct Elf_Data_Scn { struct Elf_Data d; struct Elf_Scn *s; }


original_code:
int
gelf_update_rela (Elf_Data *dst, int ndx, GElf_Rela *src)
{
  Elf_Data_Scn *data_scn = (Elf_Data_Scn *) dst;
  Elf_Scn *scn;
  int result = 0;
  if (dst == ((void *)0))
    return 0;
  if (__builtin_expect (!!(ndx < 0), 0))
    {
      __libelf_seterrno (ELF_E_INVALID_INDEX);
      return 0;
    }
  if (__builtin_expect (!!(data_scn->d.d_type != ELF_T_RELA), 0))
    {
      __libelf_seterrno (ELF_E_DATA_MISMATCH);
      return 0;
    }
  scn = data_scn->s;
  ((void) (scn->elf->lock));
  if (scn->elf->class == 1)
    {
      Elf32_Rela *rel;
      if (__builtin_expect (!!(src->r_offset > 0xffffffffull), 0)
   || __builtin_expect (!!(((src->r_info) >> 32) > 0xffffff), 0)
   || __builtin_expect (!!(((src->r_info) & 0xffffffff) > 0xff), 0)
   || __builtin_expect (!!(src->r_addend < -0x80000000ll), 0)
   || __builtin_expect (!!(src->r_addend > 0x7fffffffll), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_DATA);
   goto out;
 }
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      rel = &((Elf32_Rela *) data_scn->d.d_buf)[ndx];
      rel->r_offset = src->r_offset;
      rel->r_info = (((((src->r_info) >> 32)) << 8) + ((((src->r_info) & 0xffffffff)) & 0xff));
      rel->r_addend = src->r_addend;
    }
  else
    {
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      ((Elf64_Rela *) data_scn->d.d_buf)[ndx] = *src;
    }
  result = 1;
  scn->flags |= ELF_F_DIRTY;
 out:
  ((void) (scn->elf->lock));
  return result;
}

canonical_original_code:
int gelf_update_rela(struct Elf_Data *dst, int ndx, struct Elf64_Rela *src)
{
  struct Elf_Data_Scn *data_scn = (Elf_Data_Scn *) dst;
  struct Elf_Scn *scn;
  int result = 0;
  if (dst == ((void *)0))
    return 0;
  if (__builtin_expect (!!(ndx < 0), 0))
    {
      __libelf_seterrno (ELF_E_INVALID_INDEX);
      return 0;
    }
  if (__builtin_expect (!!(data_scn->d.d_type != ELF_T_RELA), 0))
    {
      __libelf_seterrno (ELF_E_DATA_MISMATCH);
      return 0;
    }
  scn = data_scn->s;
  ((void) (scn->elf->lock));
  if (scn->elf->class == 1)
    {
      struct Elf32_Rela *rel;
      if (__builtin_expect (!!(src->r_offset > 0xffffffffull), 0)
   || __builtin_expect (!!(((src->r_info) >> 32) > 0xffffff), 0)
   || __builtin_expect (!!(((src->r_info) & 0xffffffff) > 0xff), 0)
   || __builtin_expect (!!(src->r_addend < -0x80000000ll), 0)
   || __builtin_expect (!!(src->r_addend > 0x7fffffffll), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_DATA);
   goto out;
 }
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      rel = &((struct Elf32_Rela *) data_scn->d.d_buf)[ndx];
      rel->r_offset = src->r_offset;
      rel->r_info = (((((src->r_info) >> 32)) << 8) + ((((src->r_info) & 0xffffffff)) & 0xff));
      rel->r_addend = src->r_addend;
    }
  else
    {
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      ((struct Elf64_Rela *) data_scn->d.d_buf)[ndx] = *src;
    }
  result = 1;
  scn->flags |= ELF_F_DIRTY;
 out:
  ((void) (scn->elf->lock));
  return result;
}

variable_types: ndx int

variable_types: struct Elf64_Rela { unsigned long r_offset; unsigned long r_info; long r_addend; } *

variable_types: struct Elf_Data_Scn { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_XWORD=13, ELF_T_SXWORD=14, ELF_T_VDEF=15, ELF_T_VDAUX=16, ELF_T_VNEED=17, ELF_T_VNAUX=18, ELF_T_NHDR=19, ELF_T_SYMINFO=20, ELF_T_MOVE=21, ELF_T_LIB=22, ELF_T_GNUHASH=23, ELF_T_AUXV=24, ELF_T_NUM=25 } d_type; unsigned int d_version; unsigned long d_size; long d_off; unsigned long d_align; } d; struct Elf_Scn { struct Elf_Data_List { struct Elf_Data_Scn data; struct Elf_Data_List *next; int flags; } data_list; struct Elf_Data_List *data_list_rear; struct Elf_Data_Scn rawdata; int data_read; int shndx_index; unsigned long index; struct Elf { void *map_address; struct Elf *parent; struct Elf *next; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } kind; enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_RDWR=2, ELF_C_WRITE=3, ELF_C_CLR=4, ELF_C_SET=5, ELF_C_FDDONE=6, ELF_C_FDREAD=7, ELF_C_READ_MMAP=8, ELF_C_RDWR_MMAP=9, ELF_C_WRITE_MMAP=10, ELF_C_READ_MMAP_PRIVATE=11, ELF_C_EMPTY=12, ELF_C_NUM=13 } cmd; unsigned int class; int fildes; long start_offset; unsigned long maximum_size; int flags; int ref_count; int lock; union { struct { void *ehdr; void *shdr; void *phdr; struct Elf_ScnList { unsigned int cnt; unsigned int max; struct Elf_ScnList *next; struct Elf_Scn data[]; } *scns_last; struct Elf_Data_Chunk { struct Elf_Data_Scn data; union { struct Elf_Scn dummy_scn; struct Elf_Data_Chunk *next; }; } *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; } elf; struct { struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *shdr; struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf32_Ehdr ehdr_mem; char __e32scnspad[-1]; struct Elf_ScnList scns; } elf32; struct { struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } *shdr; struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf64_Ehdr ehdr_mem; struct Elf_ScnList scns; } elf64; struct { struct Elf *children; struct Elf_Arsym { char *as_name; unsigned long as_off; unsigned long as_hash; } *ar_sym; unsigned long ar_sym_num; char *long_names; unsigned long long_names_len; long offset; struct Elf_Arhdr { char *ar_name; long ar_date; unsigned int ar_uid; unsigned int ar_gid; unsigned int ar_mode; long ar_size; char *ar_rawname; } elf_ar_hdr; struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } ar_hdr; char ar_name[16]; char raw_name[17]; } ar; } state; } *elf; union { struct Elf32_Shdr *e32; struct Elf64_Shdr *e64; } shdr; unsigned int shdr_flags; unsigned int flags; char *rawdata_base; char *data_base; struct Elf_ScnList *list; } *s; } *

variable_types: result int

variable_types: struct Elf32_Rela { unsigned int r_offset; unsigned int r_info; int r_addend; } *


decompiled_code:
__int64 __fastcall elf_scnshndx(__int64 a1)
{
__int64 result; // rax
char v2[72]; // [rsp+8h] [rbp-48h] BYREF

result = *(unsigned int *)(a1 + 124);
if ( !(_DWORD)result )
{
gelf_getshdr(a1, v2);
result = *(unsigned int *)(a1 + 124);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
char v2[72]; // [rsp+8h] [rbp-48h] BYREF

result = *(unsigned int *)(a1 + 124);
if ( !(_DWORD)result )
{
gelf_getshdr(a1, v2);
result = *(unsigned int *)(a1 + 124);
}
return result;
}

original_code:
int
elf_scnshndx (Elf_Scn *scn)
{
  if (__builtin_expect (!!(scn->shndx_index == 0), 0))
    {
      GElf_Shdr shdr_mem;
      (void) gelf_getshdr (scn, &shdr_mem);
    }
  return scn->shndx_index;
}

canonical_original_code:
int elf_scnshndx(struct Elf_Scn *scn)
{
  if (__builtin_expect (!!(scn->shndx_index == 0), 0))
    {
      struct Elf64_Shdr shdr_mem;
      (void) gelf_getshdr (scn, &shdr_mem);
    }
  return scn->shndx_index;
}

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

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

user_defined_types: enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_RDWR=2, ELF_C_WRITE=3, ELF_C_CLR=4, ELF_C_SET=5, ELF_C_FDDONE=6, ELF_C_FDREAD=7, ELF_C_READ_MMAP=8, ELF_C_RDWR_MMAP=9, ELF_C_WRITE_MMAP=10, ELF_C_READ_MMAP_PRIVATE=11, ELF_C_EMPTY=12, ELF_C_NUM=13 }

user_defined_types: enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_XWORD=13, ELF_T_SXWORD=14, ELF_T_VDEF=15, ELF_T_VDAUX=16, ELF_T_VNEED=17, ELF_T_VNAUX=18, ELF_T_NHDR=19, ELF_T_SYMINFO=20, ELF_T_MOVE=21, ELF_T_LIB=22, ELF_T_GNUHASH=23, ELF_T_AUXV=24, ELF_T_NUM=25 }

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

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

user_defined_types: struct Elf_ScnList { unsigned int cnt; unsigned int max; struct Elf_ScnList *next; struct Elf_Scn data[]; }

user_defined_types: struct Elf_Data_Chunk { struct Elf_Data_Scn data; union { struct Elf_Scn dummy_scn; struct Elf_Data_Chunk *next; }; }

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall gelf_update_rel(__int64 a1, int a2, const __m128i *a3)
{
__int64 v3; // rax
unsigned __int64 v4; // rsi
unsigned __int64 v6; // rcx
unsigned __int64 v7; // rsi
_DWORD *v8; // rsi

if ( !a1 )
return 0LL;
if ( a2 < 0 )
goto LABEL_16;
if ( *(_DWORD *)(a1 + 8) != 8 )
{
_libelf_seterrno(30LL);
return 0LL;
}
v3 = *(_QWORD *)(a1 + 40);
if ( *(_DWORD *)(*(_QWORD *)(v3 + 136) + 32LL) == 1 )
{
if ( a3->m128i_i64[0] > 0xFFFFFFFFuLL || (v6 = a3->m128i_u64[1], HIDWORD(v6) > 0xFFFFFF) || (v6 & 0xFFFFFF00) != 0 )
{
_libelf_seterrno(32LL);
return 0LL;
}
v7 = 8LL * (a2 + 1);
if ( v7 <= *(_QWORD *)(a1 + 16) )
{
v8 = (_DWORD *)(*(_QWORD *)a1 + v7 - 8);
*v8 = a3->m128i_i64[0];
v8[1] = (unsigned __int8)v6 + (HIDWORD(v6) << 8);
goto LABEL_7;
}
LABEL_16:
_libelf_seterrno(21LL);
return 0LL;
}
v4 = 16LL * (a2 + 1);
if ( v4 > *(_QWORD *)(a1 + 16) )
goto LABEL_16;
*(__m128i *)(*(_QWORD *)a1 + v4 - 16) = _mm_loadu_si128(a3);
LABEL_7:
*(_DWORD *)(v3 + 156) |= 1u;
return 1LL;
}

original_code:
int
gelf_update_rel (Elf_Data *dst, int ndx, GElf_Rel *src)
{
  Elf_Data_Scn *data_scn = (Elf_Data_Scn *) dst;
  Elf_Scn *scn;
  int result = 0;
  if (dst == ((void *)0))
    return 0;
  if (__builtin_expect (!!(ndx < 0), 0))
    {
      __libelf_seterrno (ELF_E_INVALID_INDEX);
      return 0;
    }
  if (__builtin_expect (!!(data_scn->d.d_type != ELF_T_REL), 0))
    {
      __libelf_seterrno (ELF_E_DATA_MISMATCH);
      return 0;
    }
  scn = data_scn->s;
  ((void) (scn->elf->lock));
  if (scn->elf->class == 1)
    {
      Elf32_Rel *rel;
      if (__builtin_expect (!!(src->r_offset > 0xffffffffull), 0)
   || __builtin_expect (!!(((src->r_info) >> 32) > 0xffffff), 0)
   || __builtin_expect (!!(((src->r_info) & 0xffffffff) > 0xff), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_DATA);
   goto out;
 }
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      rel = &((Elf32_Rel *) data_scn->d.d_buf)[ndx];
      rel->r_offset = src->r_offset;
      rel->r_info = (((((src->r_info) >> 32)) << 8) + ((((src->r_info) & 0xffffffff)) & 0xff));
    }
  else
    {
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      ((Elf64_Rel *) data_scn->d.d_buf)[ndx] = *src;
    }
  result = 1;
  scn->flags |= ELF_F_DIRTY;
 out:
  ((void) (scn->elf->lock));
  return result;
}

canonical_original_code:
int gelf_update_rel(struct Elf_Data *dst, int ndx, struct Elf64_Rel *src)
{
  struct Elf_Data_Scn *data_scn = (Elf_Data_Scn *) dst;
  struct Elf_Scn *scn;
  int result = 0;
  if (dst == ((void *)0))
    return 0;
  if (__builtin_expect (!!(ndx < 0), 0))
    {
      __libelf_seterrno (ELF_E_INVALID_INDEX);
      return 0;
    }
  if (__builtin_expect (!!(data_scn->d.d_type != ELF_T_REL), 0))
    {
      __libelf_seterrno (ELF_E_DATA_MISMATCH);
      return 0;
    }
  scn = data_scn->s;
  ((void) (scn->elf->lock));
  if (scn->elf->class == 1)
    {
      struct Elf32_Rel *rel;
      if (__builtin_expect (!!(src->r_offset > 0xffffffffull), 0)
   || __builtin_expect (!!(((src->r_info) >> 32) > 0xffffff), 0)
   || __builtin_expect (!!(((src->r_info) & 0xffffffff) > 0xff), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_DATA);
   goto out;
 }
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      rel = &((struct Elf32_Rel *) data_scn->d.d_buf)[ndx];
      rel->r_offset = src->r_offset;
      rel->r_info = (((((src->r_info) >> 32)) << 8) + ((((src->r_info) & 0xffffffff)) & 0xff));
    }
  else
    {
      if (__builtin_expect (!!((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size), 0))
 {
   __libelf_seterrno (ELF_E_INVALID_INDEX);
   goto out;
 }
      ((struct Elf64_Rel *) data_scn->d.d_buf)[ndx] = *src;
    }
  result = 1;
  scn->flags |= ELF_F_DIRTY;
 out:
  ((void) (scn->elf->lock));
  return result;
}

variable_types: struct Elf64_Rel { unsigned long r_offset; unsigned long r_info; } *

variable_types: struct Elf32_Rel { unsigned int r_offset; unsigned int r_info; } *

user_defined_types: struct Elf_Scn { struct Elf_Data_List data_list; struct Elf_Data_List *data_list_rear; struct Elf_Data_Scn rawdata; int data_read; int shndx_index; unsigned long index; struct Elf *elf; union { struct Elf32_Shdr *e32; struct Elf64_Shdr *e64; } shdr; unsigned int shdr_flags; unsigned int flags; char *rawdata_base; char *data_base; struct Elf_ScnList *list; }

user_defined_types: struct Elf { void *map_address; struct Elf *parent; struct Elf *next; enum Elf_Kind kind; enum Elf_Cmd cmd; unsigned int class; int fildes; long start_offset; unsigned long maximum_size; int flags; int ref_count; int lock; union { struct { void *ehdr; void *shdr; void *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; } elf; struct { struct Elf32_Ehdr *ehdr; struct Elf32_Shdr *shdr; struct Elf32_Phdr *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf32_Ehdr ehdr_mem; char __e32scnspad[-1]; struct Elf_ScnList scns; } elf32; struct { struct Elf64_Ehdr *ehdr; struct Elf64_Shdr *shdr; struct Elf64_Phdr *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf64_Ehdr ehdr_mem; struct Elf_ScnList scns; } elf64; struct { struct Elf *children; struct Elf_Arsym *ar_sym; unsigned long ar_sym_num; char *long_names; unsigned long long_names_len; long offset; struct Elf_Arhdr elf_ar_hdr; struct ar_hdr ar_hdr; char ar_name[16]; char raw_name[17]; } ar; } state; }

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


decompiled_code:
__int64 __fastcall write_file(__int64 a1, size_t a2, unsigned int a3, __int64 a4)
{
int v7; // er13
bool v8; // al
__mode_t v10; // esi
size_t v11; // rax
size_t v12; // rax
void *v13; // rax
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v7 = *(_DWORD *)(a1 + 32);
if ( fstat(*(_DWORD *)(a1 + 36), &v14) )
goto LABEL_16;
if ( !*(_QWORD *)(a1 + 8) )
{
v11 = *(_QWORD *)(a1 + 48);
if ( v11 == -1LL || v11 < a2 )
{
if ( ftruncate(*(_DWORD *)(a1 + 36), a2) )
goto LABEL_16;
}
}
if ( *(_QWORD *)a1 )
goto LABEL_4;
if ( *(_DWORD *)(a1 + 28) == 10 )
{
v13 = mmap(0LL, a2, 3, 1, *(_DWORD *)(a1 + 36), 0LL);
*(_QWORD *)a1 = v13;
if ( v13 == (void *)-1LL )
{
*(_QWORD *)a1 = 0LL;
}
else if ( v13 )
{
LABEL_4:
if ( v7 == 1 )
v8 = (unsigned int)_elf32_updatemmap(a1, a3, a4) != 0;
else
v8 = (unsigned int)_elf64_updatemmap(a1, a3, a4) != 0;
goto LABEL_6;
}
}
if ( v7 == 1 )
v8 = (unsigned int)_elf32_updatefile(a1, a3, a4) != 0;
else
v8 = (unsigned int)_elf64_updatefile(a1, a3, a4) != 0;
LABEL_6:
if ( v8 || a2 == -1LL )
return -1LL;
if ( *(_QWORD *)(a1 + 8) )
{
v10 = v14.st_mode;
if ( (v14.st_mode & 0xC00) == 0 )
return a2;
}
else
{
v12 = *(_QWORD *)(a1 + 48);
if ( v12 == -1LL || v12 <= a2 )
{
v10 = v14.st_mode;
if ( (v14.st_mode & 0xC00) == 0 )
goto LABEL_24;
}
else
{
if ( ftruncate(*(_DWORD *)(a1 + 36), a2) )
{
LABEL_16:
_libelf_seterrno(19LL);
return -1LL;
}
v10 = v14.st_mode;
if ( (v14.st_mode & 0xC00) == 0 )
goto LABEL_28;
}
}
if ( fchmod(*(_DWORD *)(a1 + 36), v10) )
goto LABEL_16;
LABEL_28:
if ( *(_QWORD *)(a1 + 8) )
return a2;
LABEL_24:
*(_QWORD *)(a1 + 48) = a2;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, size_t a2, unsigned int a3, __int64 a4)
{
int v7; // er13
bool v8; // al
__mode_t v10; // esi
size_t v11; // rax
size_t v12; // rax
void *v13; // rax
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v7 = *(_DWORD *)(a1 + 32);
if ( fstat(*(_DWORD *)(a1 + 36), &v14) )
goto LABEL_16;
if ( !*(_QWORD *)(a1 + 8) )
{
v11 = *(_QWORD *)(a1 + 48);
if ( v11 == -1LL || v11 < a2 )
{
if ( ftruncate(*(_DWORD *)(a1 + 36), a2) )
goto LABEL_16;
}
}
if ( *(_QWORD *)a1 )
goto LABEL_4;
if ( *(_DWORD *)(a1 + 28) == 10 )
{
v13 = mmap(0LL, a2, 3, 1, *(_DWORD *)(a1 + 36), 0LL);
*(_QWORD *)a1 = v13;
if ( v13 == (void *)-1LL )
{
*(_QWORD *)a1 = 0LL;
}
else if ( v13 )
{
LABEL_4:
if ( v7 == 1 )
v8 = (unsigned int)_elf32_updatemmap(a1, a3, a4) != 0;
else
v8 = (unsigned int)_elf64_updatemmap(a1, a3, a4) != 0;
goto LABEL_6;
}
}
if ( v7 == 1 )
v8 = (unsigned int)_elf32_updatefile(a1, a3, a4) != 0;
else
v8 = (unsigned int)_elf64_updatefile(a1, a3, a4) != 0;
LABEL_6:
if ( v8 || a2 == -1LL )
return -1LL;
if ( *(_QWORD *)(a1 + 8) )
{
v10 = v14.st_mode;
if ( (v14.st_mode & 0xC00) == 0 )
return a2;
}
else
{
v12 = *(_QWORD *)(a1 + 48);
if ( v12 == -1LL || v12 <= a2 )
{
v10 = v14.st_mode;
if ( (v14.st_mode & 0xC00) == 0 )
goto LABEL_24;
}
else
{
if ( ftruncate(*(_DWORD *)(a1 + 36), a2) )
{
LABEL_16:
_libelf_seterrno(19LL);
return -1LL;
}
v10 = v14.st_mode;
if ( (v14.st_mode & 0xC00) == 0 )
goto LABEL_28;
}
}
if ( fchmod(*(_DWORD *)(a1 + 36), v10) )
goto LABEL_16;
LABEL_28:
if ( *(_QWORD *)(a1 + 8) )
return a2;
LABEL_24:
*(_QWORD *)(a1 + 48) = a2;
return a2;
}

original_code:
static off_t
write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
{
  int class = elf->class;
  struct stat st;
  if (__builtin_expect (!!(fstat (elf->fildes, &st) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      return -1;
    }
  if (elf->parent == ((void *)0)
      && (elf->maximum_size == ~((size_t) 0)
   || (size_t) size > elf->maximum_size)
      && __builtin_expect (!!(ftruncate (elf->fildes, size) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      return -1;
    }
  if (elf->map_address == ((void *)0) && elf->cmd == ELF_C_WRITE_MMAP)
    {
      elf->map_address = mmap (((void *)0), size, 0x1 | 0x2,
          0x01, elf->fildes, 0);
      if (__builtin_expect (!!(elf->map_address == ((void *) -1)), 0))
 elf->map_address = ((void *)0);
    }
  if (elf->map_address != ((void *)0))
    {
      if ((class == 1
    ? __elf32_updatemmap (elf, change_bo, shnum)
    : __elf64_updatemmap (elf, change_bo, shnum)) != 0)
 size = -1;
    }
  else
    {
      if ((class == 1
    ? __elf32_updatefile (elf, change_bo, shnum)
    : __elf64_updatefile (elf, change_bo, shnum)) != 0)
 size = -1;
    }
  if (size != -1
      && elf->parent == ((void *)0)
      && elf->maximum_size != ~((size_t) 0)
      && (size_t) size < elf->maximum_size
      && __builtin_expect (!!(ftruncate (elf->fildes, size) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      size = -1;
    }
  if (size != -1
      && __builtin_expect (!!(st.st_mode & (04000 | 02000)), 0)
      && __builtin_expect (!!(fchmod (elf->fildes, st.st_mode) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      size = -1;
    }
  if (size != -1 && elf->parent == ((void *)0))
    elf->maximum_size = size;
  return size;
}

canonical_original_code:
static long write_file(struct Elf *elf, long size, int change_bo, unsigned long shnum)
{
  int class = elf->class;
  struct stat st;
  if (__builtin_expect (!!(fstat (elf->fildes, &st) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      return -1;
    }
  if (elf->parent == ((void *)0)
      && (elf->maximum_size == ~((unsigned long) 0)
   || (unsigned long) size > elf->maximum_size)
      && __builtin_expect (!!(ftruncate (elf->fildes, size) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      return -1;
    }
  if (elf->map_address == ((void *)0) && elf->cmd == ELF_C_WRITE_MMAP)
    {
      elf->map_address = mmap (((void *)0), size, 0x1 | 0x2,
          0x01, elf->fildes, 0);
      if (__builtin_expect (!!(elf->map_address == ((void *) -1)), 0))
 elf->map_address = ((void *)0);
    }
  if (elf->map_address != ((void *)0))
    {
      if ((class == 1
    ? __elf32_updatemmap (elf, change_bo, shnum)
    : __elf64_updatemmap (elf, change_bo, shnum)) != 0)
 size = -1;
    }
  else
    {
      if ((class == 1
    ? __elf32_updatefile (elf, change_bo, shnum)
    : __elf64_updatefile (elf, change_bo, shnum)) != 0)
 size = -1;
    }
  if (size != -1
      && elf->parent == ((void *)0)
      && elf->maximum_size != ~((unsigned long) 0)
      && (unsigned long) size < elf->maximum_size
      && __builtin_expect (!!(ftruncate (elf->fildes, size) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      size = -1;
    }
  if (size != -1
      && __builtin_expect (!!(st.st_mode & (04000 | 02000)), 0)
      && __builtin_expect (!!(fchmod (elf->fildes, st.st_mode) != 0), 0))
    {
      __libelf_seterrno (ELF_E_WRITE_ERROR);
      size = -1;
    }
  if (size != -1 && elf->parent == ((void *)0))
    elf->maximum_size = size;
  return size;
}

variable_types: size long

variable_types:
shnum
unsigned long

variable_types: class int

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

return_type: long

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

user_defined_types: struct Elf_Data_List { struct Elf_Data_Scn data; struct Elf_Data_List *next; int flags; }

user_defined_types: struct Elf_Data_Scn { struct Elf_Data d; struct Elf_Scn *s; }

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