textdomain

decompiled_code:
const char *__fastcall textdomain(const char *a1)
{
const char *result; // rax
int v2; // edx

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

canonical_decompiled_code:
const char *__fastcall func6(const char *a1)
{
const char *result; // rax
int v2; // edx

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

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

repo: sabotage-linux/gettext-tiny

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:
domainname
char *

variable_types:
dirname
char *

variable_types:
dir
char []

return_type: char *


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

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, const char *a2)
{
if ( !a1 || !*a1 || a2 && strcasecmp(a2, "UTF-8") )
*_errno_location() = 22;
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(const char *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 )
return 0LL;
if ( !*a1 )
return 0LL;
v5 = strcmp(a1, "none") == 0;
result = !v5;
if ( !v5 )
{
v5 = strcmp(a1, "off") == 0;
result = !v5;
if ( !v5 )
{
if ( !strcmp(a1, "t") )
{
result = 1LL;
}
else if ( !strcmp(a1, "numbered") )
{
result = 1LL;
}
else if ( !strcmp(a1, "nil") )
{
result = 2LL;
}
else if ( !strcmp(a1, "existing") )
{
result = 2LL;
}
else
{
v3 = strcmp(a1, "simple") != 0;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = 6LL;
v7 = "never";
v8 = 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;
}
else
{
result = 3LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *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 )
return 0LL;
if ( !*a1 )
return 0LL;
v5 = strcmp(a1, "none") == 0;
result = !v5;
if ( !v5 )
{
v5 = strcmp(a1, "off") == 0;
result = !v5;
if ( !v5 )
{
if ( !strcmp(a1, "t") )
{
result = 1LL;
}
else if ( !strcmp(a1, "numbered") )
{
result = 1LL;
}
else if ( !strcmp(a1, "nil") )
{
result = 2LL;
}
else if ( !strcmp(a1, "existing") )
{
result = 2LL;
}
else
{
v3 = strcmp(a1, "simple") != 0;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = 6LL;
v7 = "never";
v8 = 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;
}
else
{
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

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v5; // rax
const char *v6; // rsi
const char *v7; // rdi
__int64 v8; // rdx
const char **v9; // rbx
const char **v10; // r13
int v11; // er14
int v12; // er12
bool v13; // cf
bool v14; // zf
__int64 v15; // rcx
char v16; // al
bool v17; // cf
bool v18; // zf
__int64 v19; // rcx
char v20; // al
bool v21; // cf
bool v22; // zf
__int64 v23; // rcx
char v24; // al
bool v25; // cf
bool v26; // zf
__int64 v27; // rcx
char v28; // al
bool v29; // cf
bool v30; // zf
__int64 v31; // rcx
int v32; // er12
__int64 v33; // rcx
char v34; // al
bool v35; // cf
bool v36; // zf
__int64 v37; // rcx
char v38; // al
bool v39; // cf
bool v40; // zf
__int64 v41; // rcx
const char *v42; // rbp
FILE **v44; // rbx
__int64 *v45; // rbp
struct _IO_FILE *v46; // rdi
int v47; // [rsp+0h] [rbp-88h]
int v48; // [rsp+4h] [rbp-84h]
int v49; // [rsp+8h] [rbp-80h]
_BYTE v50[12]; // [rsp+Ch] [rbp-7Ch] BYREF
struct _IO_FILE *v51; // [rsp+18h] [rbp-70h] BYREF
struct _IO_FILE *v52; // [rsp+20h] [rbp-68h] BYREF
struct _IO_FILE *v53; // [rsp+28h] [rbp-60h] BYREF
__int64 v54[11]; // [rsp+30h] [rbp-58h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v5; // rax
const char *v6; // rsi
const char *v7; // rdi
__int64 v8; // rdx
const char **v9; // rbx
const char **v10; // r13
int v11; // er14
int v12; // er12
bool v13; // cf
bool v14; // zf
__int64 v15; // rcx
char v16; // al
bool v17; // cf
bool v18; // zf
__int64 v19; // rcx
char v20; // al
bool v21; // cf
bool v22; // zf
__int64 v23; // rcx
char v24; // al
bool v25; // cf
bool v26; // zf
__int64 v27; // rcx
char v28; // al
bool v29; // cf
bool v30; // zf
__int64 v31; // rcx
int v32; // er12
__int64 v33; // rcx
char v34; // al
bool v35; // cf
bool v36; // zf
__int64 v37; // rcx
char v38; // al
bool v39; // cf
bool v40; // zf
__int64 v41; // rcx
const char *v42; // rbp
FILE **v44; // rbx
__int64 *v45; // rbp
struct _IO_FILE *v46; // rdi
int v47; // [rsp+0h] [rbp-88h]
int v48; // [rsp+4h] [rbp-84h]
int v49; // [rsp+8h] [rbp-80h]
_BYTE v50[12]; // [rsp+Ch] [rbp-7Ch] BYREF
struct _IO_FILE *v51; // [rsp+18h] [rbp-70h] BYREF
struct _IO_FILE *v52; // [rsp+20h] [rbp-68h] BYREF
struct _IO_FILE *v53; // [rsp+28h] [rbp-60h] BYREF
__int64 v54[11]; // [rsp+30h] [rbp-58h] BYREF

if ( argc == 1 )
func1(argc, argv, envp);
*(_DWORD *)&v50[8] = 0;
v51 = 0LL;
v52 = 0LL;
v53 = 0LL;
v54[0] = 1LL;
v54[1] = 0LL;
v54[2] = 0LL;
getenv("SIMPLE_BACKUP_SUFFIX");
v5 = getenv("VERSION_CONTROL");
*(_QWORD *)v50 = (unsigned int)func5(v5);
v6 = "-";
v7 = (_BYTE *)(process_line_callback + 1);
func4(1, "-", (struct _IO_FILE **)&v50[4]);
if ( argc <= 1 )
goto LABEL_129;
v9 = argv + 1;
v10 = &argv[(unsigned int)(argc - 2) + 2];
v11 = 0;
v49 = 0;
v12 = 0;
v47 = 1;
v48 = 0;
do
{
v42 = *v9;
if ( **v9 == 45 )
{
v13 = v42[1] < 0x2Du;
v14 = v42[1] == 45;
if ( v42[1] == 45 )
{
v33 = 7LL;
v7 = "strict";
v6 = v42 + 2;
do
{
if ( !v33 )
break;
v13 = *v6 < (unsigned int)*v7;
v14 = *v6++ == *v7++;
--v33;
}
while ( v14 );
v34 = (!v13 && !v14) - v13;
v35 = 0;
v36 = v34 == 0;
if ( v34 )
{
v37 = 17LL;
v7 = "properties-input";
v6 = v42 + 2;
do
{
if ( !v37 )
break;
v35 = *v6 < (unsigned int)*v7;
v36 = *v6++ == *v7++;
--v37;
}
while ( v36 );
v38 = (!v35 && !v36) - v35;
v39 = 0;
v40 = v38 == 0;
if ( v38 )
{
v41 = 18LL;
v7 = "properties-output";
v6 = v42 + 2;
do
{
if ( !v41 )
break;
v39 = *v6 < (unsigned int)*v7;
v40 = *v6++ == *v7++;
--v41;
}
while ( v40 );
if ( (!v39 && !v40) != v39 )
{
v6 = "stringtable-input";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "stringtable-input") )
{
v6 = "stringtable-output";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "stringtable-output") )
{
v6 = "no-fuzzy-matching";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "no-fuzzy-matching") )
{
v6 = "multi-domain";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "multi-domain") )
{
v6 = "previous";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "previous") )
{
v6 = "escape";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "escape") )
{
v6 = "no-escape";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "no-escape") )
{
v6 = "force-po";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "force-po") )
{
v6 = "indent";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "indent") )
{
v6 = "add-location";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "add-location") )
{
v6 = "no-location";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "no-location") )
{
v6 = "no-wrap";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "no-wrap") )
{
v6 = "sort-output";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "sort-output") )
{
v6 = "sort-by-file";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "sort-by-file") )
{
v6 = "lang=";
v7 = v42 + 2;
if ( memcmp(v42 + 2, "lang=", 5uLL) )
{
v6 = "color";
v7 = v42 + 2;
if ( memcmp(v42 + 2, "color", 5uLL) )
{
v6 = "style=";
v7 = v42 + 2;
if ( memcmp(v42 + 2, "style=", 6uLL) )
{
v6 = "width=";
v7 = v42 + 2;
if ( memcmp(v42 + 2, "width=", 6uLL) )
{
v6 = "verbose";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "verbose") )
{
v6 = "quiet";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "quiet") )
{
v6 = "silent";
v7 = v42 + 2;
if ( strcmp(v42 + 2, "silent") )
{
if ( !strcmp(v42 + 2, "version") )
func2();
if ( !memcmp(v42 + 2, "output-file=", 0xCuLL) )
{
v6 = v42 + 14;
v7 = (_BYTE *)(process_line_callback + 1);
func4(1, v42 + 14, (struct _IO_FILE **)&v50[4]);
}
else if ( !memcmp(v42 + 2, "compendium=", 0xBuLL) )
{
v6 = v42 + 13;
v7 = (_BYTE *)(process_line_callback + 1);
func4(1, v42 + 13, &v53);
}
else
{
v6 = "suffix=";
v7 = v42 + 2;
if ( memcmp(v42 + 2, "suffix=", 7uLL) )
{
if ( !memcmp(v42 + 2, "directory=", 0xAuLL) )
goto LABEL_91;
v6 = "backup";
v7 = v42 + 2;
if ( !memcmp(v42 + 2, "backup", 6uLL) )
{
if ( v42[8] == 61 )
{
v7 = v42 + 9;
func5(v42 + 9);
}
}
else
{
v6 = "update";
v7 = v42 + 2;
if ( !strcmp(v42 + 2, "update") )
{
v48 = 1;
}
else
{
v6 = "help";
v7 = v42 + 2;
if ( !strcmp(v42 + 2, "help") )
func1(v7, "help", v8);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
v15 = 2LL;
v6 = v42 + 1;
v7 = "o";
do
{
if ( !v15 )
break;
v13 = *v6 < (unsigned int)*v7;
v14 = *v6++ == *v7++;
--v15;
}
while ( v14 );
v16 = (!v13 && !v14) - v13;
v17 = 0;
v18 = v16 == 0;
if ( v16 )
{
v19 = 2LL;
v6 = v42 + 1;
v7 = "C";
do
{
if ( !v19 )
break;
v17 = *v6 < (unsigned int)*v7;
v18 = *v6++ == *v7++;
--v19;
}
while ( v18 );
v20 = (!v17 && !v18) - v17;
v21 = 0;
v22 = v20 == 0;
if ( v20 )
{
v23 = 2LL;
v6 = v42 + 1;
v7 = "U";
do
{
if ( !v23 )
break;
v21 = *v6 < (unsigned int)*v7;
v22 = *v6++ == *v7++;
--v23;
}
while ( v22 );
v24 = (!v21 && !v22) - v21;
v25 = 0;
v26 = v24 == 0;
if ( v24 )
{
v27 = 2LL;
v7 = "m";
v6 = v42 + 1;
do
{
if ( !v27 )
break;
v25 = *v6 < (unsigned int)*v7;
v26 = *v6++ == *v7++;
--v27;
}
while ( v26 );
v28 = (!v25 && !v26) - v25;
v29 = 0;
v30 = v28 == 0;
if ( v28 )
{
v31 = 2LL;
v7 = "N";
v6 = v42 + 1;
do
{
if ( !v31 )
break;
v29 = *v6 < (unsigned int)*v7;
v30 = *v6++ == *v7++;
--v31;
}
while ( v30 );
if ( (!v29 && !v30) != v29 )
{
v6 = "P";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "P") )
{
v6 = "e";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "e") )
{
v6 = "E";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "E") )
{
v6 = "i";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "i") )
{
v6 = "p";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "p") )
{
v6 = "w";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "w") )
{
v6 = "s";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "s") )
{
v6 = "F";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "F") )
{
v6 = "V";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "V") )
{
v6 = "q";
v7 = v42 + 1;
if ( strcmp(v42 + 1, "q") )
{
if ( !strcmp(v42 + 1, "v") )
func2();
if ( !strcmp(v42 + 1, "D") )
{
LABEL_91:
fwrite("EINVAL\n", 1uLL, 7uLL, stderr);
exit(1);
}
v6 = "h";
v7 = v42 + 1;
if ( !strcmp(v42 + 1, "h") )
func1(v7, "h", v8);
if ( v12 )
{
if ( v48 )
{
v32 = strcmp(v42, "/dev/null");
if ( !v32 )
return v32;
}
v6 = v42;
v7 = (_BYTE *)(process_line_callback + 1);
func4(1, v42, (struct _IO_FILE **)&v50[4]);
v12 = 0;
}
else if ( v11 )
{
v6 = v42;
v7 = (_BYTE *)(process_line_callback + 1);
func4(1, v42, &v53);
v11 = 0;
}
else if ( v47 )
{
if ( v48 )
{
v32 = strcmp(v42, "/dev/null");
if ( !v32 )
return v32;
}
v6 = v42;
v7 = 0LL;
func4(0, v42, &v51);
v49 = v47;
v47 = 0;
v12 = 0;
}
else if ( v49 )
{
if ( v48 )
{
v32 = strcmp(v42, "/dev/null");
if ( !v32 )
return v32;
}
v6 = v42;
v7 = 0LL;
func4(0, v42, &v52);
v12 = 0;
v11 = 0;
v49 = 0;
}
else
{
v12 = 0;
v11 = 0;
v47 = 0;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
v48 = 1;
}
}
else
{
v11 = 1;
}
}
else
{
v12 = 1;
}
}
}
else if ( v12 )
{
if ( v48 )
{
v14 = strcmp(*v9, "/dev/null") == 0;
v32 = !v14;
if ( v14 )
return v32;
}
v6 = *v9;
v7 = (_BYTE *)(process_line_callback + 1);
func4(1, *v9, (struct _IO_FILE **)&v50[4]);
v12 = 0;
}
else if ( v11 )
{
v6 = *v9;
v7 = (_BYTE *)(process_line_callback + 1);
func4(1, *v9, &v53);
v11 = 0;
}
else if ( v47 )
{
if ( v48 )
{
v14 = strcmp(*v9, "/dev/null") == 0;
v32 = !v14;
if ( v14 )
return v32;
}
v6 = *v9;
v7 = 0LL;
func4(0, *v9, &v51);
v49 = v47;
v47 = 0;
v12 = 0;
}
else if ( v49 )
{
if ( v48 )
{
v14 = strcmp(*v9, "/dev/null") == 0;
v32 = !v14;
if ( v14 )
return v32;
}
v6 = *v9;
v7 = 0LL;
func4(0, *v9, &v52);
v12 = 0;
v11 = 0;
v49 = 0;
}
else
{
v12 = 0;
v11 = 0;
v47 = 0;
}
++v9;
}
while ( v9 != v10 );
if ( v48 )
{
fwrite("warning: update functionality unimplemented\n", 1uLL, 0x2CuLL, stdout);
v32 = 0;
}
else
{
LABEL_129:
if ( !*(_QWORD *)&v50[4] || !v51 || !v52 )
func1(v7, v6, v8);
v44 = (FILE **)&v50[4];
v32 = func3((__int64)&v50[4]);
v45 = (__int64 *)&v50[4];
do
{
if ( *v44 )
fflush(*v44);
++v44;
}
while ( v54 != (__int64 *)v44 );
do
{
v46 = (struct _IO_FILE *)*v45;
if ( *v45 && v46 != stdout && v46 != stdin )
fclose(v46);
++v45;
}
while ( v54 != v45 );
}
return v32;
}

original_code: int main(){}

canonical_original_code: int main(){}


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

return_type: void


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:
void __fastcall nlist_fshash_fini(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
free(a1);
}

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, const char **a2)
{
const char **v2; // rbx
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbp
int v9; // eax
__int64 v10; // rax
__int64 v11; // r14
__int64 *v12; // r15
__int64 v13; // r13
const char *i; // rsi
unsigned int *v16; // rax
const char *v17; // rax
_QWORD *v18; // rax
const char *v19; // rax
unsigned int fd; // [rsp+4h] [rbp-B4h]
unsigned __int64 v21; // [rsp+10h] [rbp-A8h]
unsigned __int64 v22; // [rsp+18h] [rbp-A0h]
const char *v23; // [rsp+20h] [rbp-98h] BYREF
char v24[24]; // [rsp+28h] [rbp-90h] BYREF
char v25[120]; // [rsp+40h] [rbp-78h] BYREF

v2 = a2;
fd = open(a1, 0);
if ( fd == -1 )
{
_libelf_seterrno(38LL);
}
else
{
if ( !_libelf_version_initialized )
elf_version(1LL);
v3 = elf_begin(fd, 8LL, 0LL);
if ( v3 )
{
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = elf_nextscn(v3, v5);
v5 = v6;
if ( !v6 )
break;
v7 = gelf_getshdr(v6, v25);
v8 = v7;
if ( !v7 )
goto LABEL_34;
v9 = *(_DWORD *)(v7 + 4);
if ( v9 == 2 )
goto LABEL_14;
if ( v9 == 11 )
v4 = v5;
}
if ( v4 )
{
v8 = gelf_getshdr(v4, v25);
v5 = v4;
LABEL_14:
v10 = elf_getdata(v5, 0LL);
v11 = v10;
if ( v10 )
{
v21 = *(_QWORD *)(v8 + 32);
v22 = gelf_fsize(v3, 11LL, 1LL, *(unsigned int *)(v10 + 12));
v12 = nlist_fshash_init(v21 / v22);
if ( v12 )
{
v13 = 0LL;
if ( v21 < v22 )
{
LABEL_17:
for ( i = *a2; *v2; i = *v2 )
{
if ( !*i )
break;
v23 = i;
v18 = nlist_fshash_find(v12, (__int64)i, 0LL, &v23);
if ( v18 )
{
v2[1] = (const char *)v18[2];
*((_WORD *)v2 + 8) = *((_WORD *)v18 + 7);
*((_WORD *)v2 + 9) = *((_BYTE *)v18 + 12) & 0xF;
}
else
{
v2[1] = 0LL;
*((_WORD *)v2 + 8) = 0;
*((_WORD *)v2 + 9) = 0;
}
*((_BYTE *)v2 + 20) = 0;
*((_BYTE *)v2 + 21) = 0;
v2 += 3;
}
nlist_fshash_fini(v12);
elf_end(v3);
close(fd);
return 0LL;
}
while ( 1 )
{
v16 = (unsigned int *)gelf_getsym(v11, (unsigned int)v13, v24);
if ( !v16 )
break;
v17 = (const char *)elf_strptr(v3, *(unsigned int *)(v8 + 40), *v16);
v23 = v17;
if ( !v17 )
break;
if ( *v17 )
nlist_fshash_overwrite(v12, (__int64)v17, 0LL, (__int64)&v23);
if ( v21 / v22 <= ++v13 )
goto LABEL_17;
}
nlist_fshash_fini(v12);
}
else
{
_libelf_seterrno(8LL);
}
}
}
LABEL_34:
elf_end(v3);
}
close(fd);
}
v19 = *a2;
if ( !*a2 )
return 0xFFFFFFFFLL;
do
{
if ( !*v19 )
return 0xFFFFFFFFLL;
v2[1] = 0LL;
*((_WORD *)v2 + 8) = 0;
*((_WORD *)v2 + 9) = 0;
*((_BYTE *)v2 + 20) = 0;
*((_BYTE *)v2 + 21) = 0;
v2 += 3;
v19 = *v2;
}
while ( *v2 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char **a2)
{
const char **v2; // rbx
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbp
int v9; // eax
__int64 v10; // rax
__int64 v11; // r14
__int64 *v12; // r15
__int64 v13; // r13
const char *i; // rsi
unsigned int *v16; // rax
const char *v17; // rax
_QWORD *v18; // rax
const char *v19; // rax
unsigned int fd; // [rsp+4h] [rbp-B4h]
unsigned __int64 v21; // [rsp+10h] [rbp-A8h]
unsigned __int64 v22; // [rsp+18h] [rbp-A0h]
const char *v23; // [rsp+20h] [rbp-98h] BYREF
char v24[24]; // [rsp+28h] [rbp-90h] BYREF
char v25[120]; // [rsp+40h] [rbp-78h] BYREF

v2 = a2;
fd = open(a1, 0);
if ( fd == -1 )
{
_libelf_seterrno(38LL);
}
else
{
if ( !_libelf_version_initialized )
elf_version(1LL);
v3 = elf_begin(fd, 8LL, 0LL);
if ( v3 )
{
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = elf_nextscn(v3, v5);
v5 = v6;
if ( !v6 )
break;
v7 = gelf_getshdr(v6, v25);
v8 = v7;
if ( !v7 )
goto LABEL_34;
v9 = *(_DWORD *)(v7 + 4);
if ( v9 == 2 )
goto LABEL_14;
if ( v9 == 11 )
v4 = v5;
}
if ( v4 )
{
v8 = gelf_getshdr(v4, v25);
v5 = v4;
LABEL_14:
v10 = elf_getdata(v5, 0LL);
v11 = v10;
if ( v10 )
{
v21 = *(_QWORD *)(v8 + 32);
v22 = gelf_fsize(v3, 11LL, 1LL, *(unsigned int *)(v10 + 12));
v12 = nlist_fshash_init(v21 / v22);
if ( v12 )
{
v13 = 0LL;
if ( v21 < v22 )
{
LABEL_17:
for ( i = *a2; *v2; i = *v2 )
{
if ( !*i )
break;
v23 = i;
v18 = nlist_fshash_find(v12, (__int64)i, 0LL, &v23);
if ( v18 )
{
v2[1] = (const char *)v18[2];
*((_WORD *)v2 + 8) = *((_WORD *)v18 + 7);
*((_WORD *)v2 + 9) = *((_BYTE *)v18 + 12) & 0xF;
}
else
{
v2[1] = 0LL;
*((_WORD *)v2 + 8) = 0;
*((_WORD *)v2 + 9) = 0;
}
*((_BYTE *)v2 + 20) = 0;
*((_BYTE *)v2 + 21) = 0;
v2 += 3;
}
func2(v12);
elf_end(v3);
close(fd);
return 0LL;
}
while ( 1 )
{
v16 = (unsigned int *)gelf_getsym(v11, (unsigned int)v13, v24);
if ( !v16 )
break;
v17 = (const char *)elf_strptr(v3, *(unsigned int *)(v8 + 40), *v16);
v23 = v17;
if ( !v17 )
break;
if ( *v17 )
func1(v12, (__int64)v17, 0LL, (__int64)&v23);
if ( v21 / v22 <= ++v13 )
goto LABEL_17;
}
func2(v12);
}
else
{
_libelf_seterrno(8LL);
}
}
}
LABEL_34:
elf_end(v3);
}
close(fd);
}
v19 = *a2;
if ( !*a2 )
return 0xFFFFFFFFLL;
do
{
if ( !*v19 )
return 0xFFFFFFFFLL;
v2[1] = 0LL;
*((_WORD *)v2 + 8) = 0;
*((_WORD *)v2 + 9) = 0;
*((_BYTE *)v2 + 20) = 0;
*((_BYTE *)v2 + 21) = 0;
v2 += 3;
v19 = *v2;
}
while ( *v2 );
return 0xFFFFFFFFLL;
}

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 v2; // [rsp+0h] [rbp-48h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-48h] BYREF

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

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


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; // er14
bool v8; // al
size_t v9; // rax
bool v10; // al
__mode_t v11; // esi
__int64 result; // rax
void *v13; // rax
size_t v14; // rax
struct stat v15; // [rsp+0h] [rbp-B8h] BYREF

v7 = *(_DWORD *)(a1 + 32);
if ( fstat(*(_DWORD *)(a1 + 36), &v15) )
goto LABEL_31;
if ( !*(_QWORD *)(a1 + 8) )
{
v9 = *(_QWORD *)(a1 + 48);
if ( v9 == -1LL || v9 < a2 )
{
if ( ftruncate(*(_DWORD *)(a1 + 36), a2) )
goto LABEL_31;
}
}
if ( *(_QWORD *)a1 )
{
LABEL_4:
if ( v7 == 1 )
v8 = (unsigned int)_elf32_updatemmap(a1, a3, a4) != 0;
else
v8 = (unsigned int)_elf64_updatemmap(a1, a3, a4) != 0;
if ( v8 )
return -1LL;
goto LABEL_17;
}
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 )
{
goto LABEL_4;
}
}
if ( v7 == 1 )
v10 = (unsigned int)_elf32_updatefile(a1, a3, a4) != 0;
else
v10 = (unsigned int)_elf64_updatefile(a1, a3, a4) != 0;
if ( v10 )
return -1LL;
LABEL_17:
if ( a2 != -1LL )
{
if ( *(_QWORD *)(a1 + 8) )
{
v11 = v15.st_mode;
if ( (v15.st_mode & 0xC00) == 0 )
return a2;
LABEL_30:
if ( fchmod(*(_DWORD *)(a1 + 36), v11) )
{
LABEL_31:
_libelf_seterrno(19LL);
return -1LL;
}
LABEL_34:
result = a2;
if ( *(_QWORD *)(a1 + 8) )
return result;
goto LABEL_35;
}
v14 = *(_QWORD *)(a1 + 48);
if ( v14 == -1LL || v14 <= a2 )
{
v11 = v15.st_mode;
if ( (v15.st_mode & 0xC00) == 0 )
{
LABEL_35:
*(_QWORD *)(a1 + 48) = a2;
return a2;
}
goto LABEL_30;
}
if ( !ftruncate(*(_DWORD *)(a1 + 36), a2) )
{
v11 = v15.st_mode;
if ( (v15.st_mode & 0xC00) == 0 )
goto LABEL_34;
goto LABEL_30;
}
_libelf_seterrno(19LL);
}
return -1LL;
}

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

v7 = *(_DWORD *)(a1 + 32);
if ( fstat(*(_DWORD *)(a1 + 36), &v15) )
goto LABEL_31;
if ( !*(_QWORD *)(a1 + 8) )
{
v9 = *(_QWORD *)(a1 + 48);
if ( v9 == -1LL || v9 < a2 )
{
if ( ftruncate(*(_DWORD *)(a1 + 36), a2) )
goto LABEL_31;
}
}
if ( *(_QWORD *)a1 )
{
LABEL_4:
if ( v7 == 1 )
v8 = (unsigned int)_elf32_updatemmap(a1, a3, a4) != 0;
else
v8 = (unsigned int)_elf64_updatemmap(a1, a3, a4) != 0;
if ( v8 )
return -1LL;
goto LABEL_17;
}
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 )
{
goto LABEL_4;
}
}
if ( v7 == 1 )
v10 = (unsigned int)_elf32_updatefile(a1, a3, a4) != 0;
else
v10 = (unsigned int)_elf64_updatefile(a1, a3, a4) != 0;
if ( v10 )
return -1LL;
LABEL_17:
if ( a2 != -1LL )
{
if ( *(_QWORD *)(a1 + 8) )
{
v11 = v15.st_mode;
if ( (v15.st_mode & 0xC00) == 0 )
return a2;
LABEL_30:
if ( fchmod(*(_DWORD *)(a1 + 36), v11) )
{
LABEL_31:
_libelf_seterrno(19LL);
return -1LL;
}
LABEL_34:
result = a2;
if ( *(_QWORD *)(a1 + 8) )
return result;
goto LABEL_35;
}
v14 = *(_QWORD *)(a1 + 48);
if ( v14 == -1LL || v14 <= a2 )
{
v11 = v15.st_mode;
if ( (v15.st_mode & 0xC00) == 0 )
{
LABEL_35:
*(_QWORD *)(a1 + 48) = a2;
return a2;
}
goto LABEL_30;
}
if ( !ftruncate(*(_DWORD *)(a1 + 36), a2) )
{
v11 = v15.st_mode;
if ( (v15.st_mode & 0xC00) == 0 )
goto LABEL_34;
goto LABEL_30;
}
_libelf_seterrno(19LL);
}
return -1LL;
}

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


decompiled_code:
__int64 __fastcall libelf_release_all(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) == 1 )
{
for ( i = *(_QWORD *)(a1 + 72); i; i = *(_QWORD *)(i + 16) )
{
if ( *(_DWORD *)(i + 60) )
result = libelf_release_all(i);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) == 1 )
{
for ( i = *(_QWORD *)(a1 + 72); i; i = *(_QWORD *)(i + 16) )
{
if ( *(_DWORD *)(i + 60) )
result = func1(i);
}
}
return result;
}

original_code:
static void
__attribute__ ((unused))
libelf_release_all (Elf *elf)
{
  if (elf->kind == ELF_K_AR)
    {
      Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->ref_count != 0)
     libelf_release_all (child);
   child = child->next;
 }
    }
  ((void) (elf->lock));
}

canonical_original_code:
static void libelf_release_all(struct Elf *elf)
{
  if (elf->kind == ELF_K_AR)
    {
      struct Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->ref_count != 0)
     libelf_release_all (child);
   child = child->next;
 }
    }
  ((void) (elf->lock));
}

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


original_code:
static void
set_address (Elf *elf, size_t offset)
{
  if (elf->kind == ELF_K_AR)
    {
      Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->map_address == ((void *)0))
     {
       child->map_address = elf->map_address;
       child->start_offset -= offset;
       if (child->kind == ELF_K_AR)
  child->state.ar.offset -= offset;
       set_address (child, offset);
     }
   child = child->next;
 }
    }
}

canonical_original_code:
static void set_address(struct Elf *elf, unsigned long offset)
{
  if (elf->kind == ELF_K_AR)
    {
      struct Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->map_address == ((void *)0))
     {
       child->map_address = elf->map_address;
       child->start_offset -= offset;
       if (child->kind == ELF_K_AR)
  child->state.ar.offset -= offset;
       set_address (child, offset);
     }
   child = child->next;
 }
    }
}

variable_types:
offset
unsigned long

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


createlinkList

repo: sachin-rajput/basic-ds-algo

decompiled_code:
_QWORD *createlinkList()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
linkList *createlinkList()
{
 linkList *newlinkList = (linkList*)malloc(sizeof(linkList));
 newlinkList->head = ((void *)0);
 newlinkList->tail = ((void *)0);
 return newlinkList;
}

canonical_original_code:
struct linkList *createlinkList()
{
 struct linkList *newlinkList = (linkList*)malloc(sizeof(linkList));
 newlinkList->head = ((void *)0);
 newlinkList->tail = ((void *)0);
 return newlinkList;
}

variable_types: struct linkList { struct nodePtr { struct nodePtr *next; struct data { int value; } *dataPtr; } *head; struct nodePtr *tail; } *

user_defined_types: struct linkList { struct nodePtr *head; struct nodePtr *tail; }

user_defined_types: struct nodePtr { struct nodePtr *next; struct data *dataPtr; }


searchValue

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

result = *a1;
if ( !*a1 )
return 0LL;
while ( **(_DWORD **)(result + 8) != a2 )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 1LL;
}

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

result = *a1;
if ( !*a1 )
return 0LL;
while ( **(_DWORD **)(result + 8) != a2 )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 1LL;
}

original_code:
int searchValue(linkList *ll,int value)
{
 node *temp,*prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   return 1;
  }
  prev = temp;
 }
 return 0;
}

canonical_original_code:
int searchValue(struct linkList *ll, int value)
{
 struct nodePtr *temp; struct nodePtr *prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   return 1;
  }
  prev = temp;
 }
 return 0;
}

variable_types: value int

variable_types: struct nodePtr { struct nodePtr *next; struct data { int value; } *dataPtr; } *


checkHead

decompiled_code:
_BOOL8 __fastcall checkHead(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int checkHead(linkList *ll)
{
 if(ll->head) return 1;
 return 0;
}

canonical_original_code:
int checkHead(struct linkList *ll)
{
 if(ll->head) return 1;
 return 0;
}


checkTail

decompiled_code:
_BOOL8 __fastcall checkTail(__int64 a1)
{
return *(_QWORD *)(a1 + 8) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 8) != 0LL;
}

original_code:
int checkTail(linkList *ll)
{
 if(ll->tail) return 1;
 return 0;
}

canonical_original_code:
int checkTail(struct linkList *ll)
{
 if(ll->tail) return 1;
 return 0;
}


printlinkList

decompiled_code:
int __fastcall printlinkList(__int64 ***a1)
{
int result; // eax
__int64 **v2; // rbx

result = checkEmpty(a1);
if ( result )
{
v2 = *a1;
puts(">>==============Printing linkList from front================<<");
for ( ; v2; v2 = (__int64 **)*v2 )
printf("%d\n", *(unsigned int *)v2[1]);
result = puts(">>==============Printing linkList finished================<<");
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 ***a1)
{
int result; // eax
__int64 **v2; // rbx

result = func12(a1);
if ( result )
{
v2 = *a1;
puts(">>==============Printing linkList from front================<<");
for ( ; v2; v2 = (__int64 **)*v2 )
printf("%d\n", *(unsigned int *)v2[1]);
result = puts(">>==============Printing linkList finished================<<");
}
return result;
}

original_code:
void printlinkList(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 printf(">>==============Printing linkList from front================<<\n");
 while(temp != ((void *)0)) {
  printf("%d\n",temp->dataPtr->value);
  temp = temp->next;
 }
 printf(">>==============Printing linkList finished================<<\n");
}

canonical_original_code:
void printlinkList(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 printf(">>==============Printing linkList from front================<<\n");
 while(temp != ((void *)0)) {
  printf("%d\n",temp->dataPtr->value);
  temp = temp->next;
 }
 printf(">>==============Printing linkList finished================<<\n");
}


lengthlinkList

decompiled_code:
__int64 __fastcall lengthlinkList(_QWORD *a1)
{
unsigned int v1; // edx
_QWORD *v2; // rax

v1 = checkEmpty(a1);
if ( v1 )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
v1 = 0;
do
{
++v1;
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
else
{
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1)
{
unsigned int v1; // edx
_QWORD *v2; // rax

v1 = func12(a1);
if ( v1 )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
v1 = 0;
do
{
++v1;
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
else
{
v1 = 0;
}
}
return v1;
}

original_code:
int lengthlinkList(linkList *ll)
{
 if(!checkEmpty(ll)) return 0;
 node *temp = ll->head;
 int i= 0;
 while(temp != ((void *)0)) {
  i++;
  temp = temp->next;
 }
 return i;
}

canonical_original_code:
int lengthlinkList(struct linkList *ll)
{
 if(!checkEmpty(ll)) return 0;
 struct nodePtr *temp = ll->head;
 int i = 0;
 while(temp != ((void *)0)) {
  i++;
  temp = temp->next;
 }
 return i;
}

variable_types: i int


cleanlinkList

decompiled_code:
int __fastcall cleanlinkList(void *ptr)
{
int result; // eax
void **v2; // rbx
void **v3; // rbp

result = checkEmpty(ptr);
if ( result )
{
v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (void **)*v2;
free(v3[1]);
free(v3);
}
while ( v2 );
}
free(ptr);
result = puts(">>==============Linklist memory cleaned ================<<");
}
return result;
}

canonical_decompiled_code:
int __fastcall func21(void *ptr)
{
int result; // eax
void **v2; // rbx
void **v3; // rbp

result = func12(ptr);
if ( result )
{
v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (void **)*v2;
free(v3[1]);
free(v3);
}
while ( v2 );
}
free(ptr);
result = puts(">>==============Linklist memory cleaned ================<<");
}
return result;
}

original_code:
void cleanlinkList(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 node *curr = temp;
 while(temp !=((void *)0)) {
  curr=temp->next;
  free(temp->dataPtr);
  free(temp);
  temp = curr;
 }
 free(ll);
 printf(">>==============Linklist memory cleaned ================<<\n");
}

canonical_original_code:
void cleanlinkList(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 struct nodePtr *curr = temp;
 while(temp !=((void *)0)) {
  curr=temp->next;
  free(temp->dataPtr);
  free(temp);
  temp = curr;
 }
 free(ll);
 printf(">>==============Linklist memory cleaned ================<<\n");
}


popwithValue

original_code:
void popwithValue(linkList *ll,int value)
{
 node *temp,*prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   prev->next = temp->next;
   temp->next = ((void *)0);
   printf(">>==============Node pop'd with value : %d ================<<\n",value);
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
 }
}

canonical_original_code:
void popwithValue(struct linkList *ll, int value)
{
 struct nodePtr *temp; struct nodePtr *prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   prev->next = temp->next;
   temp->next = ((void *)0);
   printf(">>==============Node pop'd with value : %d ================<<\n",value);
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
 }
}


checkEmpty

decompiled_code:
_BOOL8 __fastcall checkEmpty(_QWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = a1[1] != 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_QWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = a1[1] != 0LL;
return result;
}

original_code:
int checkEmpty(linkList *ll)
{
 if(ll->head && ll->tail) return 1;
 return 0;
}

canonical_original_code:
int checkEmpty(struct linkList *ll)
{
 if(ll->head && ll->tail) return 1;
 return 0;
}


addFront

decompiled_code:
int __fastcall addFront(_QWORD *a1, unsigned int a2)
{
_QWORD *v2; // r12

v2 = createNode(a2);
if ( checkEmpty(a1) )
{
*v2 = *a1;
*a1 = v2;
}
else
{
*a1 = v2;
a1[1] = v2;
}
return printf("Node added at front of linkList with value : %d\n", a2);
}

canonical_decompiled_code:
int __fastcall func13(_QWORD *a1, unsigned int a2)
{
_QWORD *v2; // r12

v2 = createNode(a2);
if ( func12(a1) )
{
*v2 = *a1;
*a1 = v2;
}
else
{
*a1 = v2;
a1[1] = v2;
}
return printf("Node added at front of linkList with value : %d\n", a2);
}

original_code:
void addFront(linkList *ll,int value)
{
 node *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  newNode->next = ll->head;
  ll->head = newNode;
 }
 printf("Node added at front of linkList with value : %d\n",value);
}

canonical_original_code:
void addFront(struct linkList *ll, int value)
{
 struct nodePtr *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  newNode->next = ll->head;
  ll->head = newNode;
 }
 printf("Node added at front of linkList with value : %d\n",value);
}


addBack

decompiled_code:
int __fastcall addBack(__int64 a1, unsigned int a2)
{
_QWORD *v2; // r12

v2 = createNode(a2);
if ( checkEmpty((_QWORD *)a1) )
**(_QWORD **)(a1 + 8) = v2;
else
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v2;
return printf("Node added at back of linkList with value : %d\n", a2);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, unsigned int a2)
{
_QWORD *v2; // r12

v2 = createNode(a2);
if ( func12((_QWORD *)a1) )
**(_QWORD **)(a1 + 8) = v2;
else
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v2;
return printf("Node added at back of linkList with value : %d\n", a2);
}

original_code:
void addBack(linkList *ll,int value)
{
 node *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  ll->tail->next = newNode;
  ll->tail = newNode;
 }
 printf("Node added at back of linkList with value : %d\n",value);
}

canonical_original_code:
void addBack(struct linkList *ll, int value)
{
 struct nodePtr *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  ll->tail->next = newNode;
  ll->tail = newNode;
 }
 printf("Node added at back of linkList with value : %d\n",value);
}


popFront

original_code:
void popFront(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 ll->head = ll->head->next;
 printf(">>==============Node pop'd from front ================<<\n");
 free(temp->dataPtr);
 free(temp);
}

canonical_original_code:
void popFront(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 ll->head = ll->head->next;
 printf(">>==============Node pop'd from front ================<<\n");
 free(temp->dataPtr);
 free(temp);
}


popBack

original_code:
void popBack(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 node *prev = temp;
 while(temp != ((void *)0)) {
  if(temp->next == ((void *)0)) {
   node *temp = ll->tail;
   ll->tail = prev;
   prev->next = ((void *)0);
   printf(">>==============Node pop'd from back ================<<\n");
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
  temp = temp->next;
 }
}

canonical_original_code:
void popBack(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 struct nodePtr *prev = temp;
 while(temp != ((void *)0)) {
  if(temp->next == ((void *)0)) {
   struct nodePtr *temp = ll->tail;
   ll->tail = prev;
   prev->next = ((void *)0);
   printf(">>==============Node pop'd from back ================<<\n");
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
  temp = temp->next;
 }
}