decompiled_code:
int __fastcall unlink_or_exit(const char *errnum)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = unlink(errnum);
if ( result )
{
v2 = _errno_location();
v3 = strerror(*v2);
error((int)"Could not unlink (%s): %s", (int)errnum, v3);
result = memory_check();
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *errnum)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = unlink(errnum);
if ( result )
{
v2 = _errno_location();
v3 = strerror(*v2);
error((int)"Could not unlink (%s): %s", (int)errnum, v3);
result = func12();
}
return result;
}

original_code:
void
unlink_or_exit (const char * path)
{
    int status;
    status = unlink (path);
    if (status) {
 error ("Could not unlink (%s): %s", path, strerror ((*__errno_location ())));
    }
}

canonical_original_code:
void unlink_or_exit(char *path)
{
    int status;
    status = unlink (path);
    if (status) {
 error ("Could not unlink (%s): %s", path, strerror ((*__errno_location ())));
    }
}


repo: benkasminbullock/cfunctions

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

if ( n_mallocs )
result = fprintf(stderr, "%s:%d: n_mallocs = %d\n", "sys-or-exit.c", 179LL, (unsigned int)n_mallocs);
return result;
}

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

if ( n_mallocs )
result = fprintf(stderr, "%s:%d: n_mallocs = %d\n", "sys-or-exit.c", 179LL, (unsigned int)n_mallocs);
return result;
}

original_code:
void
memory_check ()
{
    if (n_mallocs != 0) {
 fprintf (stderr, "%s:%d: n_mallocs = %d\n",
   "sys-or-exit.c", 179, n_mallocs);
    }
}

canonical_original_code:
void memory_check()
{
    if (n_mallocs != 0) {
 fprintf (stderr, "%s:%d: n_mallocs = %d\n",
   "sys-or-exit.c", 179, n_mallocs);
    }
}

return_type: void


dirname

decompiled_code:
char *__fastcall dirname(char *src)
{
char *v1; // rbp
char *v2; // rax
int v3; // ebx
char *v4; // r12
char *result; // rax

v1 = src;
v2 = strrchr(src, 47);
if ( v2 )
{
if ( src < v2 )
{
do
{
if ( *v2 != 47 )
break;
--v2;
}
while ( src != v2 );
}
v3 = (_DWORD)v2 - (_DWORD)src + 1;
}
else
{
v3 = 1;
v1 = (char *)&unk_3F8;
}
v4 = (char *)malloc_or_exit(v3 + 1);
++backup_n_mallocs;
result = strncpy(v4, v1, v3);
v4[v3] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
char *v1; // rbp
char *v2; // rax
int v3; // ebx
char *v4; // r12
char *result; // rax

v1 = src;
v2 = strrchr(src, 47);
if ( v2 )
{
if ( src < v2 )
{
do
{
if ( *v2 != 47 )
break;
--v2;
}
while ( src != v2 );
}
v3 = (_DWORD)v2 - (_DWORD)src + 1;
}
else
{
v3 = 1;
v1 = (char *)&unk_3F8;
}
v4 = (char *)malloc_or_exit(v3 + 1);
++backup_n_mallocs;
result = strncpy(v4, v1, v3);
v4[v3] = 0;
return result;
}

original_code:
static char *
dirname (const char * path)
{
    char *newpath;
    char *slash;
    int length;
    slash = strrchr (path, '/');
    if (slash == 0) {
 path = ".";
 length = 1;
    }
    else {
 while (slash > path && *slash == '/') {
     slash--;
 }
 length = slash - path + 1;
    }
    newpath = malloc_or_exit (length + 1);
    backup_n_mallocs++;
    strncpy (newpath, path, length);
    newpath[length] = 0;
    return newpath;
}

canonical_original_code:
static char *dirname(char *path)
{
    char *newpath;
    char *slash;
    int length;
    slash = strrchr (path, '/');
    if (slash == 0) {
 path = ".";
 length = 1;
    }
    else {
 while (slash > path && *slash == '/') {
     slash--;
 }
 length = slash - path + 1;
    }
    newpath = malloc_or_exit (length + 1);
    backup_n_mallocs++;
    strncpy (newpath, path, length);
    newpath[length] = 0;
    return newpath;
}

variable_types:
path
char *

variable_types:
newpath
char *

variable_types:
slash
char *

variable_types: length int

return_type: char *


original_code:
static int
version_number (const char * base, const char * backup, int base_length)
{
    int version;
    const char *p;
    version = 0;
    if (!strncmp (base, backup, base_length) && ((*__ctype_b_loc ())[(int) ((backup[base_length]))] & (unsigned short int) _ISdigit)) {
 for (p = &backup[base_length]; ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit); p++) {
     version = version * 10 + *p - '0';
 }
 if (p[0] != '~' || p[1]) {
     version = 0;
 }
    }
    return version;
}

canonical_original_code:
static int version_number(char *base, char *backup, int base_length)
{
    int version;
    char *p;
    version = 0;
    if (!strncmp (base, backup, base_length) && ((*__ctype_b_loc ())[(int) ((backup[base_length]))] & (unsigned short) _ISdigit)) {
 for (p = &backup[base_length]; ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit); p++) {
     version = version * 10 + *p - '0';
 }
 if (p[0] != '~' || p[1]) {
     version = 0;
 }
    }
    return version;
}

variable_types:
base
char *

variable_types:
backup
char *

variable_types: version int

variable_types:
p
char *

return_type: int


decompiled_code:
char *__fastcall make_version_name(const char *a1, unsigned int a2)
{
size_t v2; // rbx
char *v3; // rbp

v2 = (int)(strlen(a1) + 16);
v3 = (char *)malloc_or_exit(v2);
++backup_n_mallocs;
snprintf(v3, v2, "%s.~%d~", a1, a2);
return v3;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1, unsigned int a2)
{
size_t v2; // rbx
char *v3; // rbp

v2 = (int)(strlen(a1) + 16);
v3 = (char *)malloc_or_exit(v2);
++backup_n_mallocs;
snprintf(v3, v2, "%s.~%d~", a1, a2);
return v3;
}

original_code:
static char *
make_version_name (const char * file, int version)
{
    char * backup_name;
    int maxlen;
    maxlen = strlen (file) + 16;
    backup_name = malloc_or_exit (maxlen);
    backup_n_mallocs++;
    snprintf (backup_name, maxlen, "%s.~%d~", file, version);
    return backup_name;
}

canonical_original_code:
static char *make_version_name(char *file, int version)
{
    char *backup_name;
    int maxlen;
    maxlen = strlen (file) + 16;
    backup_name = malloc_or_exit (maxlen);
    backup_n_mallocs++;
    snprintf (backup_name, maxlen, "%s.~%d~", file, version);
    return backup_name;
}

variable_types:
file
char *

variable_types: maxlen int


decompiled_code:
char *__fastcall find_backup_file_name(char *src)
{
char *v1; // rax
char *v2; // r13
char *v3; // rax
char *v4; // rbp
int v5; // er12
unsigned int v6; // eax
unsigned int v7; // eax

v1 = basename(src);
v2 = concat(v1, ".~");
v3 = dirname(src);
if ( !v3 )
{
fprintf(stderr, "%s:%d: failed to make dirname.\n", "backup.c", 164LL);
exit(1);
}
v4 = v3;
v5 = max_backup_version(v2, v3);
v6 = free_or_exit(v2);
if ( v6 )
{
fprintf(stderr, "%s:%d: %s failed with status %d\n", "backup.c", 169LL, "free_or_exit (base_versions)", v6);
exit(1);
}
--backup_n_mallocs;
v7 = free_or_exit(v4);
if ( v7 )
{
fprintf(stderr, "%s:%d: %s failed with status %d\n", "backup.c", 171LL, "free_or_exit (dir)", v7);
exit(1);
}
--backup_n_mallocs;
return make_version_name(src, v5 + 1);
}

canonical_decompiled_code:
char *__fastcall func6(char *src)
{
char *v1; // rax
char *v2; // r13
char *v3; // rax
char *v4; // rbp
int v5; // er12
unsigned int v6; // eax
unsigned int v7; // eax

v1 = func0(src);
v2 = func1(v1, ".~");
v3 = func2(src);
if ( !v3 )
{
fprintf(stderr, "%s:%d: failed to make dirname.\n", "backup.c", 164LL);
exit(1);
}
v4 = v3;
v5 = func4(v2, v3);
v6 = free_or_exit(v2);
if ( v6 )
{
fprintf(stderr, "%s:%d: %s failed with status %d\n", "backup.c", 169LL, "free_or_exit (base_versions)", v6);
exit(1);
}
--backup_n_mallocs;
v7 = free_or_exit(v4);
if ( v7 )
{
fprintf(stderr, "%s:%d: %s failed with status %d\n", "backup.c", 171LL, "free_or_exit (dir)", v7);
exit(1);
}
--backup_n_mallocs;
return func5(src, v5 + 1);
}

original_code:
char *
find_backup_file_name (char *file)
{
    char *dir;
    char *base_versions;
    int highest_backup;
    base_versions = concat (basename (file), ".~");
    dir = dirname (file);
    if (dir == 0) {
 fprintf (stderr, "%s:%d: failed to make dirname.\n",
   "backup.c", 164);
 exit (1);
    }
    highest_backup = max_backup_version (base_versions, dir);
    { or_exit_t status = free_or_exit (base_versions); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 169, "free_or_exit (base_versions)", status); exit (1); } };
    backup_n_mallocs--;
    { or_exit_t status = free_or_exit (dir); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 171, "free_or_exit (dir)", status); exit (1); } };
    backup_n_mallocs--;
    return make_version_name (file, highest_backup + 1);
}

canonical_original_code:
char *find_backup_file_name(char *file)
{
    char *dir;
    char *base_versions;
    int highest_backup;
    base_versions = concat (basename (file), ".~");
    dir = dirname (file);
    if (dir == 0) {
 fprintf (stderr, "%s:%d: failed to make dirname.\n",
   "backup.c", 164);
 exit (1);
    }
    highest_backup = max_backup_version (base_versions, dir);
    { enum or_exit_t status = free_or_exit (base_versions); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 169, "free_or_exit (base_versions)", status); exit (1); } };
    backup_n_mallocs--;
    { enum or_exit_t status = free_or_exit (dir); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 171, "free_or_exit (dir)", status); exit (1); } };
    backup_n_mallocs--;
    return make_version_name (file, highest_backup + 1);
}

variable_types:
dir
char *

variable_types: enum or_exit_t { or_exit_ok=0, or_exit_null_pointer=1 }


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

result = free_or_exit(a1);
if ( (_DWORD)result )
{
fprintf(
stderr,
"%s:%d: %s failed with status %d\n",
"backup.c",
181LL,
"free_or_exit (backup_name)",
(unsigned int)result);
exit(1);
}
--backup_n_mallocs;
return result;
}

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

result = free_or_exit(a1);
if ( (_DWORD)result )
{
fprintf(
stderr,
"%s:%d: %s failed with status %d\n",
"backup.c",
181LL,
"free_or_exit (backup_name)",
(unsigned int)result);
exit(1);
}
--backup_n_mallocs;
return result;
}

original_code:
void
free_backup_name (char * backup_name)
{
    { or_exit_t status = free_or_exit (backup_name); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 181, "free_or_exit (backup_name)", status); exit (1); } };
    backup_n_mallocs--;
}

canonical_original_code:
void free_backup_name(char *backup_name)
{
    { enum or_exit_t status = free_or_exit (backup_name); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 181, "free_or_exit (backup_name)", status); exit (1); } };
    backup_n_mallocs--;
}

user_defined_types: enum or_exit_t { or_exit_ok=0, or_exit_null_pointer=1 }


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

if ( backup_n_mallocs )
result = fprintf(stderr, "%s:%d: backup_n_mallocs = %d.\n", "backup.c", 192LL, (unsigned int)backup_n_mallocs);
return result;
}

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

if ( backup_n_mallocs )
result = fprintf(stderr, "%s:%d: backup_n_mallocs = %d.\n", "backup.c", 192LL, (unsigned int)backup_n_mallocs);
return result;
}

original_code:
void
backup_memory_check ()
{
    if (backup_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: backup_n_mallocs = %d.\n",
   "backup.c", 192, backup_n_mallocs);
    }
}

canonical_original_code:
void backup_memory_check()
{
    if (backup_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: backup_n_mallocs = %d.\n",
   "backup.c", 192, backup_n_mallocs);
    }
}


lwarning

decompiled_code:
size_t lwarning(unsigned int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", a1);
vfprintf(stderr, a2, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t func0(unsigned int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", a1);
vfprintf(stderr, a2, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

original_code:
void
    lwarning (unsigned line_number, const char * format, ...)
{
    va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, line_number);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void lwarning(unsigned int line_number, char *format, ...)
{
    __builtin_va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, line_number);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

variable_types:
format
char *


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

va_start(arg, a1);
fprintf(stderr, "%s:%u: error: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, a1, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

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

va_start(arg, a1);
fprintf(stderr, "%s:%u: error: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, a1, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

original_code:
void
line_error (const char * format, ... )
{
    va_list a;
    fprintf (stderr, "%s:%u: error: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}

canonical_original_code:
void line_error(char *format, ...)
{
    __builtin_va_list a;
    fprintf (stderr, "%s:%u: error: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}


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

va_start(arg, format);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

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

va_start(arg, format);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

original_code:
void
    line_warning (const char * format, ... )
{
    va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void line_warning(char *format, ...)
{
    __builtin_va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}


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

va_start(arg, format);
fprintf(stdout, "%s:%u: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stdout, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stdout);
}

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

va_start(arg, format);
fprintf(stdout, "%s:%u: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stdout, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stdout);
}

original_code:
void
line_info (const char * format, ... )
{
    va_list a;
    fprintf (stdout, "%s:%u: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stdout, format, a); fprintf (stdout, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void line_info(char *format, ...)
{
    __builtin_va_list a;
    fprintf (stdout, "%s:%u: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stdout, format, a); fprintf (stdout, ".\n"); __builtin_va_end(a);
}


error

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

va_start(arg, a1);
fprintf(stderr, "%s: error: ", program_name);
vfprintf(stderr, a1, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

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

va_start(arg, a1);
fprintf(stderr, "%s: error: ", program_name);
vfprintf(stderr, a1, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

original_code:
void
error (const char * format, ... )
{
    va_list a;
    fprintf ( stderr, "%s: error: ", program_name );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}

canonical_original_code:
void error(char *format, ...)
{
    __builtin_va_list a;
    fprintf ( stderr, "%s: error: ", program_name );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}


warning

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

va_start(arg, format);
fprintf(stderr, "%s: warning: ", program_name);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

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

va_start(arg, format);
fprintf(stderr, "%s: warning: ", program_name);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

original_code:
void
warning (const char * format, ... )
{
    va_list a;
    fprintf ( stderr, "%s: warning: ", program_name );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void warning(char *format, ...)
{
    __builtin_va_list a;
    fprintf ( stderr, "%s: warning: ", program_name );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}


bug

decompiled_code:
void __noreturn bug(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
vfprintf(stderr, a3, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func6(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
vfprintf(stderr, a3, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

original_code:
void
bug (const char * file, unsigned line, const char * format, ... )
{
    va_list a;
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}

canonical_original_code:
void bug(char *file, unsigned int line, char *format, ...)
{
    __builtin_va_list a;
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}

variable_types:
line
unsigned int


decompiled_code:
void __fastcall set_program_name(char *a1)
{
program_name = a1;
}

canonical_decompiled_code:
void __fastcall func7(char *a1)
{
program_name = a1;
}

original_code:
void
set_program_name (const char * name)
{
    program_name = name;
}

canonical_original_code:
void set_program_name(char *name)
{
    program_name = name;
}

variable_types:
name
char *


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

result = *a1;
if ( *a1 )
{
*(_QWORD *)(result + 8) = a2;
result = *a1;
*(_QWORD *)(a2 + 16) = *a1;
}
*a1 = a2;
return result;
}

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

result = *a1;
if ( *a1 )
{
*(_QWORD *)(result + 8) = a2;
result = *a1;
*(_QWORD *)(a2 + 16) = *a1;
}
*a1 = a2;
return result;
}

original_code:
static void
type_list_add (struct type ** a, struct type * b)
{
    if (* a) {
        (* a)->next = b;
        b->prev = * a;
    }
    * a = b;
}

canonical_original_code:
static void type_list_add(struct type **a, struct type *b)
{
    if (* a) {
        (* a)->next = b;
        b->prev = * a;
    }
    * a = b;
}

variable_types: struct type { unsigned char *name; struct type *next; struct type *prev; } **

variable_types:
b
struct type *


decompiled_code:
__int64 new_arg()
{
__int64 result; // rax

result = calloc_or_exit(1LL, 88LL);
++arg_n_mallocs;
return result;
}

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

result = calloc_or_exit(1LL, 88LL);
++arg_n_mallocs;
return result;
}

original_code:
static struct arg *
new_arg ()
{
    struct arg * value;
    value = calloc_or_exit (1, sizeof (* value));
    arg_n_mallocs++;
    return value;
}

canonical_original_code:
static struct arg *new_arg()
{
    struct arg *value;
    value = calloc_or_exit (1, sizeof (* value));
    arg_n_mallocs++;
    return value;
}

variable_types: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type { unsigned char *name; struct type *next; struct type *prev; } *name; struct shared_type { struct type *t; int ref_count; } *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; } *

user_defined_types: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type *name; struct shared_type *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; }


decompiled_code:
char *__fastcall check_cpp_muddle(_DWORD *a1, const char *a2)
{
char *result; // rax

result = strchr(a2, 64);
if ( result )
{
*a1 = 3;
result = (char *)line_warning("cfunctions was unable to adequately cope with some complex C preprocessor instructions");
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(_DWORD *a1, const char *a2)
{
char *result; // rax

result = strchr(a2, 64);
if ( result )
{
*a1 = 3;
result = (char *)line_warning("cfunctions was unable to adequately cope with some complex C preprocessor instructions");
}
return result;
}

original_code:
static void
check_cpp_muddle (struct arg * a, const char * t)
{
    char * at;
    at = strchr (t, '@');
    if (at) {
 a->parse_state = CPP_MUDDLE;
 line_warning ("cfunctions was unable to adequately cope with "
        "some complex C preprocessor instructions");
    }
}

canonical_original_code:
static void check_cpp_muddle(struct arg *a, char *t)
{
    char *at;
    at = strchr (t, '@');
    if (at) {
 a->parse_state = CPP_MUDDLE;
 line_warning ("cfunctions was unable to adequately cope with "
        "some complex C preprocessor instructions");
    }
}

variable_types:
t
char *

variable_types:
at
char *

user_defined_types: struct type { unsigned char *name; struct type *next; struct type *prev; }

user_defined_types: struct shared_type { struct type *t; int ref_count; }


decompiled_code:
__int64 __fastcall type_free(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 result; // rax

if ( a1 )
{
do
{
v1 = a1;
a1 = (_QWORD *)a1[2];
}
while ( a1 );
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free_or_exit(*v2);
*v2 = 0LL;
--arg_n_mallocs;
result = free_or_exit(v2);
--arg_n_mallocs;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 result; // rax

if ( a1 )
{
do
{
v1 = a1;
a1 = (_QWORD *)a1[2];
}
while ( a1 );
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free_or_exit(*v2);
*v2 = 0LL;
--arg_n_mallocs;
result = free_or_exit(v2);
--arg_n_mallocs;
}
while ( v1 );
}
return result;
}

original_code:
static void
type_free (struct type * t)
{
    if (! t) {
 return;
    }
    while (t->prev) {
 t = t->prev;
    }
    while (t) {
 struct type * prev;
 prev = t;
 t = prev->next;
 free_or_exit (prev->name);
 prev->name = 0;
 arg_n_mallocs--;
 free_or_exit (prev);
 prev = 0;
 arg_n_mallocs--;
    }
}

canonical_original_code:
static void type_free(struct type *t)
{
    if (! t) {
 return;
    }
    while (t->prev) {
 t = t->prev;
    }
    while (t) {
 struct type *prev;
 prev = t;
 t = prev->next;
 free_or_exit (prev->name);
 prev->name = 0;
 arg_n_mallocs--;
 free_or_exit (prev);
 prev = 0;
 arg_n_mallocs--;
    }
}

variable_types: struct type { unsigned char *name; struct type *next; struct type *prev; } *


decompiled_code:
__int64 arg_start()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = new_arg();
v1 = calloc_or_exit(1LL, 16LL);
*(_QWORD *)(v0 + 16) = v1;
++arg_n_mallocs;
*(_DWORD *)(v1 + 8) = 1;
return v0;
}

original_code:
struct arg *
arg_start ()
{
    struct arg * a;
    a = new_arg ();
    a->types = calloc_or_exit (1, sizeof (* a->types));
    arg_n_mallocs++;
    a->types->ref_count = 1;
    return a;
}

canonical_original_code:
struct arg *arg_start()
{
    struct arg *a;
    a = new_arg ();
    a->types = calloc_or_exit (1, sizeof (* a->types));
    arg_n_mallocs++;
    a->types->ref_count = 1;
    return a;
}

return_type: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type { unsigned char *name; struct type *next; struct type *prev; } *name; struct shared_type { struct type *t; int ref_count; } *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; } *


decompiled_code:
__int64 __fastcall arg_share(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
int v3; // edx

result = new_arg();
v2 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(result + 16) = v2;
v3 = *(_DWORD *)(v2 + 8);
if ( v3 )
{
*(_DWORD *)(v2 + 8) = v3 + 1;
*(_DWORD *)result = 1;
*(_QWORD *)(result + 48) = a1;
if ( !*(_QWORD *)(a1 + 56) )
{
*(_QWORD *)(a1 + 56) = result;
return result;
}
}
else
{
bug("argument.c", 54LL, "zero ref count in copied argument");
}
bug("argument.c", 60LL, "non-zero next argument in arg");
return arg_add();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
int v3; // edx

result = func2();
v2 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(result + 16) = v2;
v3 = *(_DWORD *)(v2 + 8);
if ( v3 )
{
*(_DWORD *)(v2 + 8) = v3 + 1;
*(_DWORD *)result = 1;
*(_QWORD *)(result + 48) = a1;
if ( !*(_QWORD *)(a1 + 56) )
{
*(_QWORD *)(a1 + 56) = result;
return result;
}
}
else
{
bug("argument.c", 54LL, "zero ref count in copied argument");
}
bug("argument.c", 60LL, "non-zero next argument in arg");
return func9();
}

original_code:
struct arg *
arg_share (struct arg * a)
{
    struct arg * b;
    b = new_arg ();
    b->types = a->types;
    if (a->types->ref_count == 0) {
 bug ("argument.c", 54, "zero ref count in copied argument");
    }
    b->types->ref_count++;
    b->parse_state = POINTER;
    b->prev = a;
    if (a->next) {
 bug ("argument.c", 60, "non-zero next argument in arg");
    }
    a->next = b;
    return b;
}

canonical_original_code:
struct arg *arg_share(struct arg *a)
{
    struct arg *b;
    b = new_arg ();
    b->types = a->types;
    if (a->types->ref_count == 0) {
 bug ("argument.c", 54, "zero ref count in copied argument");
    }
    b->types->ref_count++;
    b->parse_state = POINTER;
    b->prev = a;
    if (a->next) {
 bug ("argument.c", 60, "non-zero next argument in arg");
    }
    a->next = b;
    return b;
}

variable_types:
a
struct arg *


decompiled_code:
void *__fastcall arg_add(__int64 *a1, const char *a2)
{
_QWORD *v2; // r13
int v3; // eax
int v4; // er12
size_t v5; // r12
void *v6; // rax
void *result; // rax
__int64 v8; // rcx
__int64 v9; // rdi

v3 = strlen(a2);
if ( !v3 )
{
result = (void *)bug("argument.c", 102LL, "Length of string is zero in arg_add");
goto LABEL_9;
}
v4 = v3;
v2 = (_QWORD *)calloc_or_exit(1LL, 24LL);
++arg_n_mallocs;
v5 = (unsigned int)(v4 + 1);
v6 = (void *)malloc_or_exit(v5);
*v2 = v6;
++arg_n_mallocs;
result = memcpy(v6, a2, v5);
if ( *a2 == 42 )
{
LABEL_9:
*(_DWORD *)a1 = 1;
goto LABEL_10;
}
if ( *(_DWORD *)a1 != 2 )
{
v8 = *(unsigned int *)a1;
goto LABEL_5;
}
result = check_cpp_muddle(a1, a2);
LABEL_10:
v8 = *(unsigned int *)a1;
if ( (_DWORD)v8 == 2 )
{
if ( strchr(a2, 91) )
return (void *)type_list_add(a1 + 4, (__int64)v2);
bug("argument.c", 118LL, "no [ in suffix, string is %s", a2);
goto LABEL_17;
}
LABEL_5:
if ( (unsigned int)v8 <= 2 )
{
if ( (_DWORD)v8 )
return (void *)type_list_add(a1 + 3, (__int64)v2);
LABEL_17:
v9 = a1[2];
if ( *(int *)(v9 + 8) <= 1 )
return (void *)type_list_add((__int64 *)v9, (__int64)v2);
bug("argument.c", 129LL, "addition to a shared type list");
goto LABEL_20;
}
if ( (_DWORD)v8 != 3 )
{
LABEL_20:
bug("argument.c", 142LL, "a->parse_state had bad value %d", v8);
result = (void *)arg_put_name();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(__int64 *a1, const char *a2)
{
_QWORD *v2; // r13
int v3; // eax
int v4; // er12
size_t v5; // r12
void *v6; // rax
void *result; // rax
__int64 v8; // rcx
__int64 v9; // rdi

v3 = strlen(a2);
if ( !v3 )
{
result = (void *)bug("argument.c", 102LL, "Length of string is zero in arg_add");
goto LABEL_9;
}
v4 = v3;
v2 = (_QWORD *)calloc_or_exit(1LL, 24LL);
++arg_n_mallocs;
v5 = (unsigned int)(v4 + 1);
v6 = (void *)malloc_or_exit(v5);
*v2 = v6;
++arg_n_mallocs;
result = memcpy(v6, a2, v5);
if ( *a2 == 42 )
{
LABEL_9:
*(_DWORD *)a1 = 1;
goto LABEL_10;
}
if ( *(_DWORD *)a1 != 2 )
{
v8 = *(unsigned int *)a1;
goto LABEL_5;
}
result = func3(a1, a2);
LABEL_10:
v8 = *(unsigned int *)a1;
if ( (_DWORD)v8 == 2 )
{
if ( strchr(a2, 91) )
return (void *)func0(a1 + 4, (__int64)v2);
bug("argument.c", 118LL, "no [ in suffix, string is %s", a2);
goto LABEL_17;
}
LABEL_5:
if ( (unsigned int)v8 <= 2 )
{
if ( (_DWORD)v8 )
return (void *)func0(a1 + 3, (__int64)v2);
LABEL_17:
v9 = a1[2];
if ( *(int *)(v9 + 8) <= 1 )
return (void *)func0((__int64 *)v9, (__int64)v2);
bug("argument.c", 129LL, "addition to a shared type list");
goto LABEL_20;
}
if ( (_DWORD)v8 != 3 )
{
LABEL_20:
bug("argument.c", 142LL, "a->parse_state had bad value %d", v8);
result = (void *)func10();
}
return result;
}

original_code:
void
arg_add (struct arg * a, const char * t, int yyleng)
{
    unsigned t_len;
    struct type * x;
    t_len = strlen (t);
    if (t_len == 0) {
 bug ("argument.c", 102, "Length of string is zero in arg_add");
    }
    x = calloc_or_exit (1, sizeof (struct type));
    arg_n_mallocs++;
    x->name = malloc_or_exit (t_len + 1);
    arg_n_mallocs++;
    memcpy (x->name, t, t_len + 1);
    if (t[0] == '*') {
        a->parse_state = POINTER;
    }
    if (a->parse_state == SUFFIX) {
        check_cpp_muddle (a, t);
    }
    switch (a->parse_state) {
    case SUFFIX:
        if (! strchr (t, '[')) {
            bug ("argument.c", 118, "no [ in suffix, string is %s", t);
        }
        type_list_add (& a->suffixes, x);
        break;
    case POINTER:
        type_list_add (& a->pointers, x);
        break;
    case TYPE:
        if (a->types->ref_count > 1) {
            bug ("argument.c", 129, "addition to a shared type list");
        }
        else {
            type_list_add (& a->types->t, x);
        }
        break;
    case CPP_MUDDLE:
        break;
    default:
        bug ("argument.c", 142, "a->parse_state had bad value %d", a->parse_state);
    }
}

canonical_original_code:
void arg_add(struct arg *a, char *t, int yyleng)
{
    unsigned int t_len;
    struct type *x;
    t_len = strlen (t);
    if (t_len == 0) {
 bug ("argument.c", 102, "Length of string is zero in arg_add");
    }
    x = calloc_or_exit (1, sizeof (struct type));
    arg_n_mallocs++;
    x->name = malloc_or_exit (t_len + 1);
    arg_n_mallocs++;
    memcpy (x->name, t, t_len + 1);
    if (t[0] == '*') {
        a->parse_state = POINTER;
    }
    if (a->parse_state == SUFFIX) {
        check_cpp_muddle (a, t);
    }
    switch (a->parse_state) {
    case SUFFIX:
        if (! strchr (t, '[')) {
            bug ("argument.c", 118, "no [ in suffix, string is %s", t);
        }
        type_list_add (& a->suffixes, x);
        break;
    case POINTER:
        type_list_add (& a->pointers, x);
        break;
    case TYPE:
        if (a->types->ref_count > 1) {
            bug ("argument.c", 129, "addition to a shared type list");
        }
        else {
            type_list_add (& a->types->t, x);
        }
        break;
    case CPP_MUDDLE:
        break;
    default:
        bug ("argument.c", 142, "a->parse_state had bad value %d", a->parse_state);
    }
}

variable_types: yyleng int


decompiled_code:
__int64 __fastcall arg_put_name(const char *a1)
{
char *v1; // rbx
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // rsi

if ( (a1[80] & 2) == 0 )
{
v1 = (char *)a1;
if ( !*((_QWORD *)a1 + 1) )
{
v2 = *(unsigned int *)a1;
if ( (_DWORD)v2 == 1 )
goto LABEL_9;
if ( (unsigned int)v2 <= 1 )
goto LABEL_14;
if ( (_DWORD)v2 == 2 )
{
LABEL_18:
bug("argument.c", 194LL, "attempt to move a suffix to arg name");
}
else if ( (_DWORD)v2 == 3 )
{
while ( 1 )
{
a1 = "argument.c";
bug("argument.c", 201LL, "Could not find a name");
LABEL_9:
if ( *((_QWORD *)a1 + 3) )
{
result = type_list_move((__int64)a1, (__int64 *)a1 + 3);
}
else
{
a1 = "argument.c";
result = bug("argument.c", 175LL, "attempt to move non-existent name from pointer list");
LABEL_14:
v4 = *((_QWORD *)a1 + 2);
if ( !*(_QWORD *)v4 )
return result;
if ( *(int *)(v4 + 8) > 1 )
{
bug("argument.c", 185LL, "attempt to move a shared type to arg name");
goto LABEL_18;
}
result = type_list_move((__int64)a1, (__int64 *)v4);
}
if ( *((_QWORD *)v1 + 1) )
{
*(_DWORD *)v1 = 2;
return result;
}
}
}
result = bug("argument.c", 197LL, "a->parse_state had bad value %d", v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
char *v1; // rbx
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // rsi

if ( (a1[80] & 2) == 0 )
{
v1 = (char *)a1;
if ( !*((_QWORD *)a1 + 1) )
{
v2 = *(unsigned int *)a1;
if ( (_DWORD)v2 == 1 )
goto LABEL_9;
if ( (unsigned int)v2 <= 1 )
goto LABEL_14;
if ( (_DWORD)v2 == 2 )
{
LABEL_18:
bug("argument.c", 194LL, "attempt to move a suffix to arg name");
}
else if ( (_DWORD)v2 == 3 )
{
while ( 1 )
{
a1 = "argument.c";
bug("argument.c", 201LL, "Could not find a name");
LABEL_9:
if ( *((_QWORD *)a1 + 3) )
{
result = func1((__int64)a1, (__int64 *)a1 + 3);
}
else
{
a1 = "argument.c";
result = bug("argument.c", 175LL, "attempt to move non-existent name from pointer list");
LABEL_14:
v4 = *((_QWORD *)a1 + 2);
if ( !*(_QWORD *)v4 )
return result;
if ( *(int *)(v4 + 8) > 1 )
{
bug("argument.c", 185LL, "attempt to move a shared type to arg name");
goto LABEL_18;
}
result = func1((__int64)a1, (__int64 *)v4);
}
if ( *((_QWORD *)v1 + 1) )
{
*(_DWORD *)v1 = 2;
return result;
}
}
}
result = bug("argument.c", 197LL, "a->parse_state had bad value %d", v2);
}
}
return result;
}

original_code:
void
arg_put_name (struct arg * a)
{
    if (a->is_function_pointer) {
        return;
    }
    if (a->name) {
        return;
    }
    switch (a->parse_state) {
    case POINTER:
 if (! a->pointers) {
     bug ("argument.c", 175, "attempt to move non-existent name from pointer list");
 }
 type_list_move (a, & a->pointers);
 break;
    case TYPE:
 if (! a->types->t) {
     return;
 }
 if (a->types->ref_count > 1) {
     bug ("argument.c", 185, "attempt to move a shared type to arg name");
 }
 type_list_move (a, & a->types->t);
 break;
    case CPP_MUDDLE:
 break;
    case SUFFIX:
 bug ("argument.c", 194, "attempt to move a suffix to arg name");
    default:
        bug ("argument.c", 197, "a->parse_state had bad value %d", a->parse_state);
    }
    if (! a->name) {
 bug ("argument.c", 201, "Could not find a name");
    }
    a->parse_state = SUFFIX;
}

canonical_original_code:
void arg_put_name(struct arg *a)
{
    if (a->is_function_pointer) {
        return;
    }
    if (a->name) {
        return;
    }
    switch (a->parse_state) {
    case POINTER:
 if (! a->pointers) {
     bug ("argument.c", 175, "attempt to move non-existent name from pointer list");
 }
 type_list_move (a, & a->pointers);
 break;
    case TYPE:
 if (! a->types->t) {
     return;
 }
 if (a->types->ref_count > 1) {
     bug ("argument.c", 185, "attempt to move a shared type to arg name");
 }
 type_list_move (a, & a->types->t);
 break;
    case CPP_MUDDLE:
 break;
    case SUFFIX:
 bug ("argument.c", 194, "attempt to move a suffix to arg name");
    default:
        bug ("argument.c", 197, "a->parse_state had bad value %d", a->parse_state);
    }
    if (! a->name) {
 bug ("argument.c", 201, "Could not find a name");
    }
    a->parse_state = SUFFIX;
}


original_code:
void
arg_free (struct arg * a)
{
    a->types->ref_count--;
    if (a->types->ref_count == 0) {
 type_free (a->types->t);
 free_or_exit (a->types);
 a->types = 0;
 arg_n_mallocs--;
    }
    if (a->name) {
 free_or_exit (a->name->name);
 a->name->name = 0;
 arg_n_mallocs--;
 free_or_exit (a->name);
 a->name = 0;
 arg_n_mallocs--;
    }
    type_free (a->pointers);
    type_free (a->suffixes);
    if (a->prev) {
 arg_free (a->prev);
    }
    if (a->is_function_pointer) {
 if (a->function_pointer) {
     free_or_exit (a->function_pointer);
     a->function_pointer = 0;
 }
    }
    if (a->function_pointer_arguments) {
 free_or_exit (a->function_pointer_arguments);
 a->function_pointer_arguments = 0;
    }
    free_or_exit (a);
    a = 0;
    arg_n_mallocs--;
}

canonical_original_code:
void arg_free(struct arg *a)
{
    a->types->ref_count--;
    if (a->types->ref_count == 0) {
 type_free (a->types->t);
 free_or_exit (a->types);
 a->types = 0;
 arg_n_mallocs--;
    }
    if (a->name) {
 free_or_exit (a->name->name);
 a->name->name = 0;
 arg_n_mallocs--;
 free_or_exit (a->name);
 a->name = 0;
 arg_n_mallocs--;
    }
    type_free (a->pointers);
    type_free (a->suffixes);
    if (a->prev) {
 arg_free (a->prev);
    }
    if (a->is_function_pointer) {
 if (a->function_pointer) {
     free_or_exit (a->function_pointer);
     a->function_pointer = 0;
 }
    }
    if (a->function_pointer_arguments) {
 free_or_exit (a->function_pointer_arguments);
 a->function_pointer_arguments = 0;
    }
    free_or_exit (a);
    a = 0;
    arg_n_mallocs--;
}


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

if ( arg_n_mallocs )
result = fprintf(stderr, "%s:%d: arg_n_mallocs = %d\n", "argument.c", 402LL, (unsigned int)arg_n_mallocs);
return result;
}

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

if ( arg_n_mallocs )
result = fprintf(stderr, "%s:%d: arg_n_mallocs = %d\n", "argument.c", 402LL, (unsigned int)arg_n_mallocs);
return result;
}

original_code:
void
arg_memory_check ()
{
    if (arg_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: arg_n_mallocs = %d\n",
   "argument.c", 402, arg_n_mallocs);
    }
}

canonical_original_code:
void arg_memory_check()
{
    if (arg_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: arg_n_mallocs = %d\n",
   "argument.c", 402, arg_n_mallocs);
    }
}


fexists

decompiled_code:
__int64 __fastcall fexists(const char *errnum)
{
int v1; // ebx
int v2; // edi
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

v1 = (int)errnum;
if ( stat(errnum, &v5) )
{
v2 = *_errno_location();
if ( v2 == 2 )
return 0LL;
v4 = strerror(v2);
error((int)"could not stat %s: %s", v1, v4);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *errnum)
{
int v1; // ebx
int v2; // edi
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

v1 = (int)errnum;
if ( stat(errnum, &v5) )
{
v2 = *_errno_location();
if ( v2 == 2 )
return 0LL;
v4 = strerror(v2);
error((int)"could not stat %s: %s", v1, v4);
}
return 1LL;
}

original_code:
int
fexists (const char * file_name)
{
    struct stat dummy;
    if (stat (file_name, & dummy)) {
 if ((*__errno_location ()) != 2) {
     error ("could not stat %s: %s", file_name, strerror ((*__errno_location ())));
 }
 return 0;
    }
    return 1;
}

canonical_original_code:
int fexists(char *file_name)
{
    struct stat dummy;
    if (stat (file_name, & dummy)) {
 if ((*__errno_location ()) != 2) {
     error ("could not stat %s: %s", file_name, strerror ((*__errno_location ())));
 }
 return 0;
    }
    return 1;
}

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

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


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

if ( file_n_mallocs )
result = fprintf(stderr, "%s:%d: file_n_mallocs = %d.\n", "file.c", 161LL, (unsigned int)file_n_mallocs);
return result;
}

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

if ( file_n_mallocs )
result = fprintf(stderr, "%s:%d: file_n_mallocs = %d.\n", "file.c", 161LL, (unsigned int)file_n_mallocs);
return result;
}

original_code:
void
file_memory_check ()
{
    if (file_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: file_n_mallocs = %d.\n",
   "file.c", 161, file_n_mallocs);
    }
}

canonical_original_code:
void file_memory_check()
{
    if (file_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: file_n_mallocs = %d.\n",
   "file.c", 161, file_n_mallocs);
    }
}


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

pthread_key_create(&threadInfoKey, 0LL);
if ( !xbeeList )
{
xbeeList = xbee_ll_alloc();
if ( !xbeeList )
fwrite("libxbee: failed to initialize xbeeList...\n", 1uLL, 0x2AuLL, stderr);
}
if ( !conList )
{
conList = xbee_ll_alloc();
if ( !conList )
fwrite("libxbee: failed to initialize conList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !pktList )
{
pktList = xbee_ll_alloc();
if ( !pktList )
fwrite("libxbee: failed to initialize pktList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !netDeadClientList )
{
netDeadClientList = xbee_ll_alloc();
if ( !netDeadClientList )
fwrite("libxbee: failed to initialize netDeadClientList...\n", 1uLL, 0x33uLL, stderr);
}
if ( !threadList )
{
threadList = xbee_ll_alloc();
if ( !threadList )
fwrite("libxbee: failed to initialize threadList...\n", 1uLL, 0x2CuLL, stderr);
}
result = &needsFree;
if ( !needsFree )
{
result = (_QWORD *)xbee_ll_alloc();
needsFree = result;
if ( !result )
result = (_QWORD *)fwrite("libxbee: failed to initialize needsFree...\n", 1uLL, 0x2BuLL, stderr);
}
return result;
}

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

pthread_key_create(&threadInfoKey, 0LL);
if ( !xbeeList )
{
xbeeList = xbee_ll_alloc();
if ( !xbeeList )
fwrite("libxbee: failed to initialize xbeeList...\n", 1uLL, 0x2AuLL, stderr);
}
if ( !conList )
{
conList = xbee_ll_alloc();
if ( !conList )
fwrite("libxbee: failed to initialize conList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !pktList )
{
pktList = xbee_ll_alloc();
if ( !pktList )
fwrite("libxbee: failed to initialize pktList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !netDeadClientList )
{
netDeadClientList = xbee_ll_alloc();
if ( !netDeadClientList )
fwrite("libxbee: failed to initialize netDeadClientList...\n", 1uLL, 0x33uLL, stderr);
}
if ( !threadList )
{
threadList = xbee_ll_alloc();
if ( !threadList )
fwrite("libxbee: failed to initialize threadList...\n", 1uLL, 0x2CuLL, stderr);
}
result = &needsFree;
if ( !needsFree )
{
result = (_QWORD *)xbee_ll_alloc();
needsFree = result;
if ( !result )
result = (_QWORD *)fwrite("libxbee: failed to initialize needsFree...\n", 1uLL, 0x2BuLL, stderr);
}
return result;
}

original_code:
__attribute__((visibility("default"))) __attribute__((constructor)) void xbee_init(void) {
 pthread_key_create((&threadInfoKey), (((void *)0)));
 if (!xbeeList && (xbeeList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize xbeeList...\n");
 }
 if (!conList && (conList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize conList...\n");
 }
 if (!pktList && (pktList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize pktList...\n");
 }
 if (!netDeadClientList && (netDeadClientList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize netDeadClientList...\n");
 }
 if (!threadList && (threadList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize threadList...\n");
 }
 if (!needsFree && (needsFree = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize needsFree...\n");
 }
}

canonical_original_code:
void xbee_init() {
 pthread_key_create((&threadInfoKey), (((void *)0)));
 if (!xbeeList && (xbeeList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize xbeeList...\n");
 }
 if (!conList && (conList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize conList...\n");
 }
 if (!pktList && (pktList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize pktList...\n");
 }
 if (!netDeadClientList && (netDeadClientList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize netDeadClientList...\n");
 }
 if (!threadList && (threadList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize threadList...\n");
 }
 if (!needsFree && (needsFree = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize needsFree...\n");
 }
}


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

if ( threadList )
{
xbee_ll_free(threadList, &xbee_threadKillThis);
threadList = 0LL;
}
if ( xbeeList )
{
xbee_ll_free(xbeeList, &xbee_shutdown);
xbeeList = 0LL;
}
if ( conList )
{
xbee_ll_free(conList, &xbee_conEnd);
conList = 0LL;
}
if ( pktList )
{
xbee_ll_free(pktList, &xbee_pktFree);
pktList = 0LL;
}
if ( netDeadClientList )
{
xbee_ll_free(netDeadClientList, &xbee_netClientShutdown);
netDeadClientList = 0LL;
}
result = &needsFree;
if ( needsFree )
{
xbee_ll_free(needsFree, &free);
result = &needsFree;
needsFree = 0LL;
}
return result;
}

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

if ( threadList )
{
xbee_ll_free(threadList, &xbee_threadKillThis);
threadList = 0LL;
}
if ( xbeeList )
{
xbee_ll_free(xbeeList, &xbee_shutdown);
xbeeList = 0LL;
}
if ( conList )
{
xbee_ll_free(conList, &xbee_conEnd);
conList = 0LL;
}
if ( pktList )
{
xbee_ll_free(pktList, &xbee_pktFree);
pktList = 0LL;
}
if ( netDeadClientList )
{
xbee_ll_free(netDeadClientList, &xbee_netClientShutdown);
netDeadClientList = 0LL;
}
result = &needsFree;
if ( needsFree )
{
xbee_ll_free(needsFree, &free);
result = &needsFree;
needsFree = 0LL;
}
return result;
}

original_code:
__attribute__((visibility("default"))) __attribute__((destructor)) void xbee_fini(void) {
 if (threadList) {
  xbee_ll_free(threadList, (void(*)(void*))xbee_threadKillThis);
  threadList = ((void *)0);
 }
 if (xbeeList) {
  xbee_ll_free(xbeeList, (void(*)(void*))xbee_shutdown);
  xbeeList = ((void *)0);
 }
 if (conList) {
  xbee_ll_free(conList, (void(*)(void*))xbee_conEnd);
  conList = ((void *)0);
 }
 if (pktList) {
  xbee_ll_free(pktList, (void(*)(void*))xbee_pktFree);
  pktList = ((void *)0);
 }
 if (netDeadClientList) {
  xbee_ll_free(netDeadClientList, (void(*)(void*))xbee_netClientShutdown);
  netDeadClientList = ((void *)0);
 }
 if (needsFree) {
  xbee_ll_free(needsFree, (void(*)(void*))free);
  needsFree = ((void *)0);
 }
}

canonical_original_code:
void xbee_fini() {
 if (threadList) {
  xbee_ll_free(threadList, (void (*)(void *))xbee_threadKillThis);
  threadList = ((void *)0);
 }
 if (xbeeList) {
  xbee_ll_free(xbeeList, (void (*)(void *))xbee_shutdown);
  xbeeList = ((void *)0);
 }
 if (conList) {
  xbee_ll_free(conList, (void (*)(void *))xbee_conEnd);
  conList = ((void *)0);
 }
 if (pktList) {
  xbee_ll_free(pktList, (void (*)(void *))xbee_pktFree);
  pktList = ((void *)0);
 }
 if (netDeadClientList) {
  xbee_ll_free(netDeadClientList, (void (*)(void *))xbee_netClientShutdown);
  netDeadClientList = ((void *)0);
 }
 if (needsFree) {
  xbee_ll_free(needsFree, (void (*)(void *))free);
  needsFree = ((void *)0);
 }
}


decompiled_code:
__int64 gpio_init()
{
__int64 result; // rax

result = 0LL;
if ( gFd < 0 )
{
gFd = open("/dev/user-gpio", 2);
result = (unsigned int)(gFd >> 31);
}
return result;
}

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

result = 0LL;
if ( gFd < 0 )
{
gFd = open("/dev/user-gpio", 2);
result = (unsigned int)(gFd >> 31);
}
return result;
}

original_code:
int gpio_init( void )
{
    if ( gFd < 0 )
    {
        if (( gFd = open( "/dev/user-gpio", 02 )) < 0 )
        {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int gpio_init()
{
    if ( gFd < 0 )
    {
        if (( gFd = open( "/dev/user-gpio", 02 )) < 0 )
        {
            return -1;
        }
    }
    return 0;
}


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

if ( gFd >= 0 )
{
result = close(gFd);
gFd = -1;
}
return result;
}

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

if ( gFd >= 0 )
{
result = close(gFd);
gFd = -1;
}
return result;
}

original_code:
void gpio_term( void )
{
    if ( gFd >= 0 )
    {
        close( gFd );
        gFd = -1;
    }
}

canonical_original_code:
void gpio_term()
{
    if ( gFd >= 0 )
    {
        close( gFd );
        gFd = -1;
    }
}


decompiled_code:
int __fastcall gpio_request(int a1, const char *a2)
{
int result; // eax
int v3; // [rsp+0h] [rbp-38h] BYREF
char dest[52]; // [rsp+4h] [rbp-34h] BYREF

v3 = a1;
strncpy(dest, a2, 0x1FuLL);
dest[31] = 0;
result = ioctl(gFd, 0x40244780uLL, &v3);
if ( result )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, const char *a2)
{
int result; // eax
int v3; // [rsp+0h] [rbp-38h] BYREF
char dest[52]; // [rsp+4h] [rbp-34h] BYREF

v3 = a1;
strncpy(dest, a2, 0x1FuLL);
dest[31] = 0;
result = ioctl(gFd, 0x40244780uLL, &v3);
if ( result )
result = -*_errno_location();
return result;
}

original_code:
int gpio_request( unsigned gpio, const char *label )
{
    GPIO_Request_t request;
    request.gpio = gpio;
    strncpy( request.label, label, sizeof( request.label ));
    request.label[ sizeof( request.label ) - 1 ] = '\0';
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x80)) << 0) | ((((sizeof(GPIO_Request_t)))) << ((0 +8)+8))), &request ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

canonical_original_code:
int gpio_request(unsigned int gpio, char *label)
{
    struct GPIO_Request_t request;
    request.gpio = gpio;
    strncpy( request.label, label, sizeof( request.label ));
    request.label[ sizeof( request.label ) - 1 ] = '\0';
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x80)) << 0) | ((((sizeof(GPIO_Request_t)))) << ((0 +8)+8))), &request ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

variable_types:
gpio
unsigned int

variable_types:
label
char *

variable_types: struct GPIO_Request_t { unsigned int gpio; char label[32]; }


decompiled_code:
int __fastcall gpio_free(unsigned int a1)
{
return ioctl(gFd, 0x4781uLL, a1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
return ioctl(gFd, 0x4781uLL, a1);
}


decompiled_code:
int __fastcall gpio_direction_input(unsigned int a1)
{
int result; // eax

result = ioctl(gFd, 0x4782uLL, a1);
if ( result )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1)
{
int result; // eax

result = ioctl(gFd, 0x4782uLL, a1);
if ( result )
result = -*_errno_location();
return result;
}


decompiled_code:
int __fastcall gpio_direction_output(int a1, int a2)
{
int result; // eax
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v3[1] = a2;
result = ioctl(gFd, 0x40084783uLL, v3);
if ( result )
result = -*_errno_location();
return result;
}

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

v3[0] = a1;
v3[1] = a2;
result = ioctl(gFd, 0x40084783uLL, v3);
if ( result )
result = -*_errno_location();
return result;
}

original_code:
int gpio_direction_output( unsigned gpio, int initialValue )
{
    GPIO_Value_t setDirOutput;
    setDirOutput.gpio = gpio;
    setDirOutput.value = initialValue;
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x83)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setDirOutput ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

canonical_original_code:
int gpio_direction_output(unsigned int gpio, int initialValue)
{
    struct GPIO_Value_t setDirOutput;
    setDirOutput.gpio = gpio;
    setDirOutput.value = initialValue;
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x83)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setDirOutput ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

variable_types: initialValue int

variable_types: struct GPIO_Value_t { unsigned int gpio; int value; }


decompiled_code:
__int64 __fastcall gpio_get_value(int a1)
{
int v1; // edx
__int64 result; // rax
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v1 = ioctl(gFd, 0xC0084784uLL, v3);
result = (unsigned int)v3[1];
if ( v1 )
result = (unsigned int)-*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // edx
__int64 result; // rax
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v1 = ioctl(gFd, 0xC0084784uLL, v3);
result = (unsigned int)v3[1];
if ( v1 )
result = (unsigned int)-*_errno_location();
return result;
}

original_code:
int gpio_get_value( unsigned gpio )
{
    GPIO_Value_t getValue;
    getValue.gpio = gpio;
    if ( ioctl( gFd, (((2U|1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x84)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &getValue ) != 0 )
    {
        return -(*__errno_location ());
    }
    return getValue.value;
}

canonical_original_code:
int gpio_get_value(unsigned int gpio)
{
    struct GPIO_Value_t getValue;
    getValue.gpio = gpio;
    if ( ioctl( gFd, (((2U|1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x84)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &getValue ) != 0 )
    {
        return -(*__errno_location ());
    }
    return getValue.value;
}

user_defined_types: struct GPIO_Value_t { unsigned int gpio; int value; }


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

v3[0] = a1;
v3[1] = a2;
return ioctl(gFd, 0x40084785uLL, v3);
}

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

v3[0] = a1;
v3[1] = a2;
return ioctl(gFd, 0x40084785uLL, v3);
}

original_code:
void gpio_set_value( unsigned gpio, int value )
{
    GPIO_Value_t setValue;
    setValue.gpio = gpio;
    setValue.value = value;
    ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x85)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setValue );
}

canonical_original_code:
void gpio_set_value(unsigned int gpio, int value)
{
    struct GPIO_Value_t setValue;
    setValue.gpio = gpio;
    setValue.value = value;
    ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x85)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setValue );
}

variable_types: value int


decompiled_code:
__int64 __fastcall xbee_modeGetList(_QWORD *a1)
{
__int64 *v1; // rbp
const char ***v2; // rbx
__int64 v3; // r13
int v4; // er12
const char **v5; // rax
char *v6; // rax
char *v7; // r13
char *v8; // rbx
int v9; // er12
__int64 result; // rax

if ( !a1 )
return 4294967284LL;
v1 = (__int64 *)&modeList;
v2 = (const char ***)&modeList;
v3 = 0LL;
v4 = 0;
v5 = (const char **)&mode_xbee1;
do
{
if ( *v5 )
{
v3 += strlen(*v5) + 9;
++v4;
}
v5 = *++v2;
}
while ( *v2 );
v6 = (char *)malloc(v3 + 8);
v7 = v6;
if ( !v6 )
return 4294967294LL;
v8 = &v6[8 * v4 + 8];
v9 = 0;
result = (__int64)&mode_xbee1;
do
{
if ( *(_QWORD *)result )
{
*(_QWORD *)&v7[8 * v9] = v8;
strcpy(v8, *(const char **)result);
v8 += strlen(v8) + 1;
++v9;
}
result = *++v1;
}
while ( *v1 );
*(_QWORD *)&v7[8 * v9] = 0LL;
*a1 = v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 *v1; // rbp
const char ***v2; // rbx
__int64 v3; // r13
int v4; // er12
const char **v5; // rax
char *v6; // rax
char *v7; // r13
char *v8; // rbx
int v9; // er12
__int64 result; // rax

if ( !a1 )
return 4294967284LL;
v1 = (__int64 *)&modeList;
v2 = (const char ***)&modeList;
v3 = 0LL;
v4 = 0;
v5 = (const char **)&mode_xbee1;
do
{
if ( *v5 )
{
v3 += strlen(*v5) + 9;
++v4;
}
v5 = *++v2;
}
while ( *v2 );
v6 = (char *)malloc(v3 + 8);
v7 = v6;
if ( !v6 )
return 4294967294LL;
v8 = &v6[8 * v4 + 8];
v9 = 0;
result = (__int64)&mode_xbee1;
do
{
if ( *(_QWORD *)result )
{
*(_QWORD *)&v7[8 * v9] = v8;
strcpy(v8, *(const char **)result);
v8 += strlen(v8) + 1;
++v9;
}
result = *++v1;
}
while ( *v1 );
*(_QWORD *)&v7[8 * v9] = 0LL;
*a1 = v7;
return result;
}

original_code:
__attribute__((visibility("default"))) xbee_err xbee_modeGetList(char ***retList) {
 int i, o;
 size_t memSize;
 char **mList;
 char *mName;
 if (!retList) return XBEE_EMISSINGPARAM;
 memSize = 0;
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  memSize += sizeof(char *);
  memSize += sizeof(char) * (strlen(modeList[i]->name) + 1);
  o++;
 }
 memSize += sizeof(char *);
 if ((mList = malloc(memSize)) == ((void *)0)) {
  return XBEE_ENOMEM;
 }
 mName = (char *)&(mList[o+1]);
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  mList[o] = mName;
  strcpy(mName, modeList[i]->name);
  mName += strlen(mName) + 1;
  o++;
 }
 mList[o] = ((void *)0);
 *retList = mList;
 return XBEE_ENONE;
}

canonical_original_code:
enum xbee_errors xbee_modeGetList(char ***retList) {
 int i; int o;
 unsigned long memSize;
 char **mList;
 char *mName;
 if (!retList) return XBEE_EMISSINGPARAM;
 memSize = 0;
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  memSize += sizeof(char *);
  memSize += sizeof(char) * (strlen(modeList[i]->name) + 1);
  o++;
 }
 memSize += sizeof(char *);
 if ((mList = malloc(memSize)) == ((void *)0)) {
  return XBEE_ENOMEM;
 }
 mName = (char *)&(mList[o+1]);
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  mList[o] = mName;
  strcpy(mName, modeList[i]->name);
  mName += strlen(mName) + 1;
  o++;
 }
 mList[o] = ((void *)0);
 *retList = mList;
 return XBEE_ENONE;
}

variable_types:
retList
char ***

variable_types: i int

variable_types: o int

variable_types:
memSize
unsigned long

variable_types:
mList
char **

variable_types:
mName
char *

return_type: enum xbee_errors { XBEE_ENONE=0, XBEE_EUNKNOWN=-1, XBEE_ENOMEM=-2, XBEE_ESELECT=-3, XBEE_ESELECTINTERRUPTED=-4, XBEE_EEOF=-5, XBEE_EIO=-6, XBEE_ESEMAPHORE=-7, XBEE_EMUTEX=-8, XBEE_ETHREAD=-9, XBEE_ELINKEDLIST=-10, XBEE_ESETUP=-11, XBEE_EMISSINGPARAM=-12, XBEE_EINVAL=-13, XBEE_ERANGE=-14, XBEE_ELENGTH=-15, XBEE_EFAILED=-18, XBEE_ETIMEOUT=-17, XBEE_EWOULDBLOCK=-16, XBEE_EINUSE=-19, XBEE_EEXISTS=-20, XBEE_ENOTEXISTS=-21, XBEE_ENOFREEFRAMEID=-22, XBEE_ESTALE=-23, XBEE_ENOTIMPLEMENTED=-24, XBEE_ETX=-25, XBEE_EREMOTE=-26, XBEE_ESLEEPING=-27, XBEE_ECATCHALL=-28 }


decompiled_code:
void __fastcall xbee_freeMemory(void *a1)
{
free(a1);
}

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

original_code:
__attribute__((visibility("default"))) void xbee_freeMemory(void *ptr) {
 free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
const char *__fastcall xbee_errorToStr(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -28:
result = "The given connection is a catch-all connection";
break;
case -27:
result = "The given connection is not currently awake";
break;
case -26:
result = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
break;
case -25:
result = "Transmission failed (check the retVal)";
break;
case -24:
result = "The called functionality has not yet been implemented";
break;
case -23:
result = "Stale information was used during this function call";
break;
case -22:
result = "There is currently no free frame ID that can be used for the request";
break;
case -21:
result = "The requested item does not exist";
break;
case -20:
result = "An item already exists by that name or identifier";
break;
case -19:
result = "A the item request is currently in use";
break;
case -18:
result = "A function call failed";
break;
case -17:
result = "A timeout occured";
break;
case -16:
result = "The call would block, but something is marked 'non-blocking'";
break;
case -15:
result = "A length mis-match occured";
break;
case -14:
result = "Requested data falls outside the boundaries";
break;
case -13:
result = "An invalid argument was provided";
break;
case -12:
result = "A crucial parameter was missing";
break;
case -11:
result = "Setup failed";
break;
case -10:
result = "A linkedlist error occured";
break;
case -9:
result = "A pthread error occured";
break;
case -8:
result = "A mutex error occured";
break;
case -7:
result = "A semaphore error occured";
break;
case -6:
result = "An I/O request failed";
break;
case -5:
result = "An EOF character was read";
break;
case -4:
result = "select() was interrupted";
break;
case -3:
result = "select() failed";
break;
case -2:
result = "Out of memory";
break;
case 0:
result = "No error";
break;
default:
result = "Unknown error...";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -28:
result = "The given connection is a catch-all connection";
break;
case -27:
result = "The given connection is not currently awake";
break;
case -26:
result = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
break;
case -25:
result = "Transmission failed (check the retVal)";
break;
case -24:
result = "The called functionality has not yet been implemented";
break;
case -23:
result = "Stale information was used during this function call";
break;
case -22:
result = "There is currently no free frame ID that can be used for the request";
break;
case -21:
result = "The requested item does not exist";
break;
case -20:
result = "An item already exists by that name or identifier";
break;
case -19:
result = "A the item request is currently in use";
break;
case -18:
result = "A function call failed";
break;
case -17:
result = "A timeout occured";
break;
case -16:
result = "The call would block, but something is marked 'non-blocking'";
break;
case -15:
result = "A length mis-match occured";
break;
case -14:
result = "Requested data falls outside the boundaries";
break;
case -13:
result = "An invalid argument was provided";
break;
case -12:
result = "A crucial parameter was missing";
break;
case -11:
result = "Setup failed";
break;
case -10:
result = "A linkedlist error occured";
break;
case -9:
result = "A pthread error occured";
break;
case -8:
result = "A mutex error occured";
break;
case -7:
result = "A semaphore error occured";
break;
case -6:
result = "An I/O request failed";
break;
case -5:
result = "An EOF character was read";
break;
case -4:
result = "select() was interrupted";
break;
case -3:
result = "select() failed";
break;
case -2:
result = "Out of memory";
break;
case 0:
result = "No error";
break;
default:
result = "Unknown error...";
break;
}
return result;
}

original_code:
__attribute__((visibility("default"))) const char *xbee_errorToStr(xbee_err error) {
 char *str = "Unknown error...";
 switch (error) {
  case XBEE_ENONE:
   str = "No error";
   break;
  case XBEE_EUNKNOWN:
  default:
   str = "Unknown error...";
   break;
  case XBEE_ENOMEM:
   str = "Out of memory";
   break;
  case XBEE_ESELECT:
   str = "select() failed";
   break;
  case XBEE_ESELECTINTERRUPTED:
   str = "select() was interrupted";
   break;
  case XBEE_EEOF:
   str = "An EOF character was read";
   break;
  case XBEE_EIO:
   str = "An I/O request failed";
   break;
  case XBEE_ESEMAPHORE:
   str = "A semaphore error occured";
   break;
  case XBEE_EMUTEX:
   str = "A mutex error occured";
   break;
  case XBEE_ETHREAD:
   str = "A pthread error occured";
   break;
  case XBEE_ELINKEDLIST:
   str = "A linkedlist error occured";
   break;
  case XBEE_ESETUP:
   str = "Setup failed";
   break;
  case XBEE_EMISSINGPARAM:
   str = "A crucial parameter was missing";
   break;
  case XBEE_EINVAL:
   str = "An invalid argument was provided";
   break;
  case XBEE_ERANGE:
   str = "Requested data falls outside the boundaries";
   break;
  case XBEE_ELENGTH:
   str = "A length mis-match occured";
   break;
  case XBEE_EFAILED:
   str = "A function call failed";
   break;
  case XBEE_ETIMEOUT:
   str = "A timeout occured";
   break;
  case XBEE_EWOULDBLOCK:
   str = "The call would block, but something is marked 'non-blocking'";
   break;
  case XBEE_EINUSE:
   str = "A the item request is currently in use";
   break;
  case XBEE_EEXISTS:
   str = "An item already exists by that name or identifier";
   break;
  case XBEE_ENOTEXISTS:
   str = "The requested item does not exist";
   break;
  case XBEE_ENOFREEFRAMEID:
   str = "There is currently no free frame ID that can be used for the request";
   break;
  case XBEE_ESTALE:
   str = "Stale information was used during this function call";
   break;
  case XBEE_ENOTIMPLEMENTED:
   str = "The called functionality has not yet been implemented";
   break;
  case XBEE_ETX:
   str = "Transmission failed (check the retVal)";
   break;
  case XBEE_EREMOTE:
   str = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
   break;
  case XBEE_ESLEEPING:
   str = "The given connection is not currently awake";
   break;
  case XBEE_ECATCHALL:
   str = "The given connection is a catch-all connection";
   break;
 }
 return str;
}

canonical_original_code:
char *xbee_errorToStr(enum xbee_errors error) {
 char *str = "Unknown error...";
 switch (error) {
  case XBEE_ENONE:
   str = "No error";
   break;
  case XBEE_EUNKNOWN:
  default:
   str = "Unknown error...";
   break;
  case XBEE_ENOMEM:
   str = "Out of memory";
   break;
  case XBEE_ESELECT:
   str = "select() failed";
   break;
  case XBEE_ESELECTINTERRUPTED:
   str = "select() was interrupted";
   break;
  case XBEE_EEOF:
   str = "An EOF character was read";
   break;
  case XBEE_EIO:
   str = "An I/O request failed";
   break;
  case XBEE_ESEMAPHORE:
   str = "A semaphore error occured";
   break;
  case XBEE_EMUTEX:
   str = "A mutex error occured";
   break;
  case XBEE_ETHREAD:
   str = "A pthread error occured";
   break;
  case XBEE_ELINKEDLIST:
   str = "A linkedlist error occured";
   break;
  case XBEE_ESETUP:
   str = "Setup failed";
   break;
  case XBEE_EMISSINGPARAM:
   str = "A crucial parameter was missing";
   break;
  case XBEE_EINVAL:
   str = "An invalid argument was provided";
   break;
  case XBEE_ERANGE:
   str = "Requested data falls outside the boundaries";
   break;
  case XBEE_ELENGTH:
   str = "A length mis-match occured";
   break;
  case XBEE_EFAILED:
   str = "A function call failed";
   break;
  case XBEE_ETIMEOUT:
   str = "A timeout occured";
   break;
  case XBEE_EWOULDBLOCK:
   str = "The call would block, but something is marked 'non-blocking'";
   break;
  case XBEE_EINUSE:
   str = "A the item request is currently in use";
   break;
  case XBEE_EEXISTS:
   str = "An item already exists by that name or identifier";
   break;
  case XBEE_ENOTEXISTS:
   str = "The requested item does not exist";
   break;
  case XBEE_ENOFREEFRAMEID:
   str = "There is currently no free frame ID that can be used for the request";
   break;
  case XBEE_ESTALE:
   str = "Stale information was used during this function call";
   break;
  case XBEE_ENOTIMPLEMENTED:
   str = "The called functionality has not yet been implemented";
   break;
  case XBEE_ETX:
   str = "Transmission failed (check the retVal)";
   break;
  case XBEE_EREMOTE:
   str = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
   break;
  case XBEE_ESLEEPING:
   str = "The given connection is not currently awake";
   break;
  case XBEE_ECATCHALL:
   str = "The given connection is a catch-all connection";
   break;
 }
 return str;
}

variable_types: enum xbee_errors { XBEE_ENONE=0, XBEE_EUNKNOWN=-1, XBEE_ENOMEM=-2, XBEE_ESELECT=-3, XBEE_ESELECTINTERRUPTED=-4, XBEE_EEOF=-5, XBEE_EIO=-6, XBEE_ESEMAPHORE=-7, XBEE_EMUTEX=-8, XBEE_ETHREAD=-9, XBEE_ELINKEDLIST=-10, XBEE_ESETUP=-11, XBEE_EMISSINGPARAM=-12, XBEE_EINVAL=-13, XBEE_ERANGE=-14, XBEE_ELENGTH=-15, XBEE_EFAILED=-18, XBEE_ETIMEOUT=-17, XBEE_EWOULDBLOCK=-16, XBEE_EINUSE=-19, XBEE_EEXISTS=-20, XBEE_ENOTEXISTS=-21, XBEE_ENOFREEFRAMEID=-22, XBEE_ESTALE=-23, XBEE_ENOTIMPLEMENTED=-24, XBEE_ETX=-25, XBEE_EREMOTE=-26, XBEE_ESLEEPING=-27, XBEE_ECATCHALL=-28 }

variable_types:
str
char *


repo: berlincount/vchat-client

decompiled_code:
void command_reconnect()
{
status = 0;
wantreconnect = 1;
ownquit = 0;
}

canonical_decompiled_code:
void func0()
{
status = 0;
wantreconnect = 1;
ownquit = 0;
}

original_code:
static void
command_reconnect(char *tail)
{
  status = 0;
  wantreconnect = 1;
  ownquit = 0;
}

variable_types:
tail
char *


decompiled_code:
__int64 command_version()
{
flushout();
writeout(vchat_cl_version);
writeout(vchat_ui_version);
writeout(vchat_io_version);
writeout(vchat_us_version);
writeout(vchat_cm_version);
writeout(vchat_ssl_version);
writeout(vchat_ssl_version_external);
return showout();
}

canonical_decompiled_code:
__int64 func1()
{
flushout();
writeout(vchat_cl_version);
writeout(vchat_ui_version);
writeout(vchat_io_version);
writeout(vchat_us_version);
writeout(vchat_cm_version);
writeout(vchat_ssl_version);
writeout(vchat_ssl_version_external);
return showout();
}

original_code:
void
command_version(char *tail)
{
  flushout();
  writeout (vchat_cl_version);
  writeout (vchat_ui_version);
  writeout (vchat_io_version);
  writeout (vchat_us_version);
  writeout (vchat_cm_version);
  writeout (vchat_ssl_version);
  writeout (vchat_ssl_version_external);
  showout();
}


decompiled_code:
__int64 __fastcall command_none(const char *a1)
{
snprintf(tmpstr, 0x400uLL, " Unknown client command: %s ", a1);
flushout();
writeout(tmpstr);
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
snprintf(tmpstr, 0x400uLL, " Unknown client command: %s ", a1);
flushout();
writeout(tmpstr);
return showout();
}

original_code:
static void
command_none(char *line) {
    snprintf(tmpstr, 1024, "  Unknown client command: %s ", line);
    {flushout();writeout(tmpstr);showout();};
}

variable_types:
line
char *


decompiled_code:
__int64 __fastcall command_quit(const char *a1)
{
__int64 result; // rax

snprintf(tmpstr, 0x400uLL, ".x %s", a1);
networkoutput(tmpstr);
result = writechan(tmpstr);
status = 0;
ownquit = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
__int64 result; // rax

snprintf(tmpstr, 0x400uLL, ".x %s", a1);
networkoutput(tmpstr);
result = writechan(tmpstr);
status = 0;
ownquit = 1;
return result;
}

original_code:
static void
command_quit(char *tail)
{
  snprintf (tmpstr, 1024, ".x %s", tail);
  networkoutput (tmpstr);
  writechan (tmpstr);
  status = 0;
  ownquit = 1;
}


dothink

decompiled_code:
__int64 __fastcall dothink(const char *a1, char a2)
{
const char *i; // rbx
const char *v3; // rdx

for ( i = a1; *i == 32; ++i )
;
snprintf(tmpstr, 0x400uLL, ".%c %s", (unsigned int)a2, i);
networkoutput(tmpstr);
if ( a2 == 79 )
v3 = (const char *)getformatstr(33LL);
else
v3 = (const char *)getformatstr(32LL);
snprintf(tmpstr, 0x400uLL, v3, i);
return writechan(tmpstr);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, char a2)
{
const char *i; // rbx
const char *v3; // rdx

for ( i = a1; *i == 32; ++i )
;
snprintf(tmpstr, 0x400uLL, ".%c %s", (unsigned int)a2, i);
networkoutput(tmpstr);
if ( a2 == 79 )
v3 = (const char *)getformatstr(33LL);
else
v3 = (const char *)getformatstr(32LL);
snprintf(tmpstr, 0x400uLL, v3, i);
return writechan(tmpstr);
}

original_code:
static void
dothink( char *tail, char nice )
{
  while( *tail == ' ' ) tail++;
  snprintf (tmpstr, 1024, ".%c %s", nice, tail);
  networkoutput (tmpstr);
  snprintf (tmpstr, 1024, nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) : getformatstr(FS_TXPUBTHOUGHT), tail);
  writechan (tmpstr);
}

canonical_original_code:
static void dothink(char *tail, char nice)
{
  while( *tail == ' ' ) tail++;
  snprintf (tmpstr, 1024, ".%c %s", nice, tail);
  networkoutput (tmpstr);
  snprintf (tmpstr, 1024, nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) : getformatstr(FS_TXPUBTHOUGHT), tail);
  writechan (tmpstr);
}

variable_types: nice char


decompiled_code:
__int64 __fastcall command_flt(unsigned __int8 *a1)
{
__int64 result; // rax
_BYTE *v2; // rsi

for ( result = *a1; (_BYTE)result == 32; result = *a1 )
++a1;
v2 = a1 + 1;
if ( (_BYTE)result )
{
while ( *v2 == 32 )
++v2;
if ( *v2 )
result = addfilter((unsigned int)(char)result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
__int64 result; // rax
_BYTE *v2; // rsi

for ( result = *a1; (_BYTE)result == 32; result = *a1 )
++a1;
v2 = a1 + 1;
if ( (_BYTE)result )
{
while ( *v2 == 32 )
++v2;
if ( *v2 )
result = addfilter((unsigned int)(char)result);
}
return result;
}

original_code:
static void
command_flt(char *tail){
  char colour;
  while(*tail==' ') tail++;
  colour = *tail++;
  while( colour && *tail == ' ') tail++;
  if( colour && *tail) {
      addfilter( colour, tail);
  }
}

variable_types: colour char


decompiled_code:
__int64 command_dict()
{
return ul_add_to_dict();
}

canonical_decompiled_code:
__int64 func6()
{
return ul_add_to_dict();
}

original_code:
void
command_dict(char *tail)
{
  ul_add_to_dict(tail);
}


decompiled_code:
__int64 __fastcall command_user(char *a1)
{
char *v1; // rbx
char i; // al
_BYTE *v3; // rbp
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax

v1 = a1;
for ( i = *a1; *v1 == 32; i = *v1 )
++v1;
if ( i )
{
v3 = (_BYTE *)ul_match_user(v1);
if ( *v3 )
{
v4 = (const char *)getformatstr(16LL);
snprintf(tmpstr, 0x400uLL, v4, v1, v3);
}
else
{
v5 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v5, " No user matched that regex. ");
}
}
else
{
v6 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v6, " Which user? ");
}
flushout();
writeout(tmpstr);
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char *v1; // rbx
char i; // al
_BYTE *v3; // rbp
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax

v1 = a1;
for ( i = *a1; *v1 == 32; i = *v1 )
++v1;
if ( i )
{
v3 = (_BYTE *)ul_match_user(v1);
if ( *v3 )
{
v4 = (const char *)getformatstr(16LL);
snprintf(tmpstr, 0x400uLL, v4, v1, v3);
}
else
{
v5 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v5, " No user matched that regex. ");
}
}
else
{
v6 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v6, " Which user? ");
}
flushout();
writeout(tmpstr);
return showout();
}

original_code:
static void
command_user(char *tail)
{
  while( *tail == ' ') tail++;
  if( *tail ) {
      char * out = ul_match_user( tail);
      if( *out ) {
          snprintf( tmpstr, 1024, getformatstr(FS_USMATCH), tail, out);
      } else {
          snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  No user matched that regex. ");
      }
  } else {
      snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  Which user? ");
  }
  {flushout();writeout(tmpstr);showout();};
}

canonical_original_code:
static void command_user(char *tail)
{
  while( *tail == ' ') tail++;
  if( *tail ) {
      char *out = ul_match_user( tail);
      if( *out ) {
          snprintf( tmpstr, 1024, getformatstr(FS_USMATCH), tail, out);
      } else {
          snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  No user matched that regex. ");
      }
  } else {
      snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  Which user? ");
  }
  {flushout();writeout(tmpstr);showout();};
}

variable_types:
out
char *


decompiled_code:
__int64 __fastcall command_format(const char *a1)
{
const char *v1; // rbx
const char *v2; // rax
char *v3; // rbp
const char *v4; // rax
char v6[4096]; // [rsp+0h] [rbp-10A8h] BYREF
struct stat v7; // [rsp+1000h] [rbp-A8h] BYREF

v1 = a1;
flushout();
if ( *a1 == 32 )
{
do
++v1;
while ( *v1 == 32 );
}
v2 = (const char *)tilde_expand(v1);
v3 = (char *)v2;
if ( v2 && !stat(v2, &v7) )
{
loadformats(v3);
}
else
{
snprintf(v6, 0x1000uLL, "~/.vchat/sample-%s.fmt", v1);
free(v3);
v4 = (const char *)tilde_expand(v1);
v3 = (char *)v4;
if ( v4 && !stat(v4, &v7) )
loadformats(v3);
}
writeout(" Sort of done. ");
free(v3);
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
const char *v1; // rbx
const char *v2; // rax
char *v3; // rbp
const char *v4; // rax
char v6[4096]; // [rsp+0h] [rbp-10A8h] BYREF
struct stat v7; // [rsp+1000h] [rbp-A8h] BYREF

v1 = a1;
flushout();
if ( *a1 == 32 )
{
do
++v1;
while ( *v1 == 32 );
}
v2 = (const char *)tilde_expand(v1);
v3 = (char *)v2;
if ( v2 && !stat(v2, &v7) )
{
loadformats(v3);
}
else
{
snprintf(v6, 0x1000uLL, "~/.vchat/sample-%s.fmt", v1);
free(v3);
v4 = (const char *)tilde_expand(v1);
v3 = (char *)v4;
if ( v4 && !stat(v4, &v7) )
loadformats(v3);
}
writeout(" Sort of done. ");
free(v3);
return showout();
}

original_code:
static void
command_format(char *line) {
  struct stat testexist;
  char * tildex = ((void *)0);
  flushout();
  while( *line==' ') line++;
  if(line) {
    tildex = tilde_expand( line );
    if(tildex && !stat(tildex, &testexist ))
      loadformats(tildex);
    else {
      char buf[4096];
      snprintf( buf, 4096, "~/.vchat/sample-%s.fmt", line );
      free(tildex);
      tildex = tilde_expand( line );
      if(tildex && !stat(tildex, &testexist ))
        loadformats(tildex);
    }
    writeout("  Sort of done.  ");
  } else {
    writeout("  Forgot to specify format file.  ");
  }
  free(tildex);
  showout();
}

canonical_original_code:
static void command_format(char *line) {
  struct stat testexist;
  char *tildex = ((void *)0);
  flushout();
  while( *line==' ') line++;
  if(line) {
    tildex = tilde_expand( line );
    if(tildex && !stat(tildex, &testexist ))
      loadformats(tildex);
    else {
      char buf[4096];
      snprintf( buf, 4096, "~/.vchat/sample-%s.fmt", line );
      free(tildex);
      tildex = tilde_expand( line );
      if(tildex && !stat(tildex, &testexist ))
        loadformats(tildex);
    }
    writeout("  Sort of done.  ");
  } else {
    writeout("  Forgot to specify format file.  ");
  }
  free(tildex);
  showout();
}

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

variable_types:
tildex
char *

variable_types:
buf
char [4096]


decompiled_code:
__int64 __fastcall command_clflt(char *a1)
{
char i; // al

for ( i = *a1; *a1 == 32; i = *a1 )
++a1;
return clearfilters((unsigned int)i);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
char i; // al

for ( i = *a1; *a1 == 32; i = *a1 )
++a1;
return clearfilters((unsigned int)i);
}

original_code:
static void
command_clflt (char *tail) {
  while( *tail == ' ') tail++;
  clearfilters( *tail );
}

canonical_original_code:
static void command_clflt(char *tail) {
  while( *tail == ' ') tail++;
  clearfilters( *tail );
}


decompiled_code:
__int64 __fastcall command_rmflt(_BYTE *a1)
{
for ( ; *a1 == 32; ++a1 )
;
return removefilter();
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1)
{
for ( ; *a1 == 32; ++a1 )
;
return removefilter();
}

original_code:
static void
command_rmflt (char *tail) {
  while( *tail == ' ') tail++;
  removefilter( tail );
}

canonical_original_code:
static void command_rmflt(char *tail) {
  while( *tail == ' ') tail++;
  removefilter( tail );
}


decompiled_code:
__int64 command_lsflt()
{
return listfilters();
}

canonical_decompiled_code:
__int64 func11()
{
return listfilters();
}

original_code:
static void
command_lsflt (char *tail) {
  listfilters();
}

canonical_original_code:
static void command_lsflt(char *tail) {
  listfilters();
}


privatemessagetx

decompiled_code:
__int64 __fastcall privatemessagetx(const char *a1)
{
const char *v1; // rbx
char i; // cl
char v3; // dl
const char *v4; // rax
const char *v5; // rdi
__int64 result; // rax
const char *v7; // rbp
const char *v8; // rax

v1 = a1;
for ( i = *a1; *v1 == 32; i = *v1 )
++v1;
v3 = *v1;
if ( (*v1 & 0xDF) != 0 )
{
v4 = v1;
do
v3 = *++v4;
while ( (*v4 & 0xDF) != 0 );
}
else
{
v4 = v1;
}
if ( v3 && i )
{
v7 = v4 + 1;
*v4 = 0;
snprintf(tmpstr, 0x400uLL, ".m %s %s", v1, v4 + 1);
networkoutput(tmpstr);
v8 = (const char *)getformatstr(30LL);
snprintf(tmpstr, 0x400uLL, v8, v1, v7);
writepriv(tmpstr, 0LL);
result = ul_private_action(v1);
}
else
{
flushout();
v5 = " Won't send empty message. ";
if ( !*v1 )
v5 = " Recipient missing. ";
writeout(v5);
result = showout();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
const char *v1; // rbx
char i; // cl
char v3; // dl
const char *v4; // rax
const char *v5; // rdi
__int64 result; // rax
const char *v7; // rbp
const char *v8; // rax

v1 = a1;
for ( i = *a1; *v1 == 32; i = *v1 )
++v1;
v3 = *v1;
if ( (*v1 & 0xDF) != 0 )
{
v4 = v1;
do
v3 = *++v4;
while ( (*v4 & 0xDF) != 0 );
}
else
{
v4 = v1;
}
if ( v3 && i )
{
v7 = v4 + 1;
*v4 = 0;
snprintf(tmpstr, 0x400uLL, ".m %s %s", v1, v4 + 1);
networkoutput(tmpstr);
v8 = (const char *)getformatstr(30LL);
snprintf(tmpstr, 0x400uLL, v8, v1, v7);
writepriv(tmpstr, 0LL);
result = ul_private_action(v1);
}
else
{
flushout();
v5 = " Won't send empty message. ";
if ( !*v1 )
v5 = " Recipient missing. ";
writeout(v5);
result = showout();
}
return result;
}

original_code:
static void
privatemessagetx ( char *tail ) {
  char *mesg;
  while( *tail==' ') tail++;
  mesg = tail;
  while ( *mesg && *mesg!=' ') mesg++;
  if(*tail && *mesg) {
      *mesg++ = '\0';
      snprintf (tmpstr, 1024, ".m %s %s", tail, mesg);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPRIVMSG), tail, mesg);
      writepriv (tmpstr, 0);
      ul_private_action(tail);
  } else {
      {flushout();writeout(*tail ? "  Won't send empty message. ":"  Recipient missing. ");showout();};
  }
}

canonical_original_code:
static void privatemessagetx(char *tail) {
  char *mesg;
  while( *tail==' ') tail++;
  mesg = tail;
  while ( *mesg && *mesg!=' ') mesg++;
  if(*tail && *mesg) {
      *mesg++ = '\0';
      snprintf (tmpstr, 1024, ".m %s %s", tail, mesg);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPRIVMSG), tail, mesg);
      writepriv (tmpstr, 0);
      ul_private_action(tail);
  } else {
      {flushout();writeout(*tail ? "  Won't send empty message. ":"  Recipient missing. ");showout();};
  }
}

variable_types:
mesg
char *


decompiled_code:
__int64 __fastcall command_pm(const char *a1)
{
return privatemessagetx(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1)
{
return func12(a1);
}

original_code:
static void
command_pm (char *tail)
{
  privatemessagetx( tail );
}

canonical_original_code:
static void command_pm(char *tail)
{
  privatemessagetx( tail );
}


decompiled_code:
__int64 __fastcall command_query(char *s)
{
char *i; // rbx
char *v2; // rbp

for ( i = s; *i == 32; ++i )
;
v2 = strchr(i, 32);
if ( v2 )
{
privatemessagetx(i);
*v2 = 0;
}
return handlequery(i);
}

canonical_decompiled_code:
__int64 __fastcall func14(char *s)
{
char *i; // rbx
char *v2; // rbp

for ( i = s; *i == 32; ++i )
;
v2 = strchr(i, 32);
if ( v2 )
{
func12(i);
*v2 = 0;
}
return handlequery(i);
}

original_code:
void
command_query(char *tail)
{
  char *msg;
  while( *tail == ' ') tail++;
  if((msg = strchr(tail, ' '))) {
    privatemessagetx( tail );
    *msg = 0;
  }
  handlequery( tail );
}

variable_types:
msg
char *


doaction

decompiled_code:
__int64 __fastcall doaction(const char *a1)
{
const char *v1; // rbx
char i; // al
__int64 v3; // rbp
const char *v4; // rax
__int64 result; // rax

v1 = a1;
for ( i = *a1; *v1 == 32; i = *v1 )
++v1;
if ( i )
{
snprintf(tmpstr, 0x400uLL, ".a %s", v1);
networkoutput(tmpstr);
v3 = own_nick_get();
v4 = (const char *)getformatstr(35LL);
snprintf(tmpstr, 0x400uLL, v4, v3, v1);
result = writechan(tmpstr);
}
else
{
flushout();
writeout(" You do nothing. ");
result = showout();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1)
{
const char *v1; // rbx
char i; // al
__int64 v3; // rbp
const char *v4; // rax
__int64 result; // rax

v1 = a1;
for ( i = *a1; *v1 == 32; i = *v1 )
++v1;
if ( i )
{
snprintf(tmpstr, 0x400uLL, ".a %s", v1);
networkoutput(tmpstr);
v3 = own_nick_get();
v4 = (const char *)getformatstr(35LL);
snprintf(tmpstr, 0x400uLL, v4, v3, v1);
result = writechan(tmpstr);
}
else
{
flushout();
writeout(" You do nothing. ");
result = showout();
}
return result;
}

original_code:
static void
doaction( char *tail )
{
  while( *tail == ' ' ) tail++;
  if( *tail ) {
      snprintf (tmpstr, 1024, ".a %s", tail);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBACTION), own_nick_get(), tail);
      writechan (tmpstr);
  } else {
      {flushout();writeout("  You do nothing. ");showout();};
  }
}

canonical_original_code:
static void doaction(char *tail)
{
  while( *tail == ' ' ) tail++;
  if( *tail ) {
      snprintf (tmpstr, 1024, ".a %s", tail);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBACTION), own_nick_get(), tail);
      writechan (tmpstr);
  } else {
      {flushout();writeout("  You do nothing. ");showout();};
  }
}


decompiled_code:
__int64 __fastcall command_action(const char *a1)
{
return doaction(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(const char *a1)
{
return func15(a1);
}

original_code:
static void
command_action(char *tail)
{
  doaction( tail);
}


decompiled_code:
__int64 __fastcall output_default(__int64 a1)
{
__int64 v1; // rbp
const char *v2; // rax

v1 = own_nick_get();
v2 = (const char *)getformatstr(28LL);
snprintf(tmpstr, 0x400uLL, v2, v1, a1);
networkoutput(a1);
return writechan(tmpstr);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 v1; // rbp
const char *v2; // rax

v1 = own_nick_get();
v2 = (const char *)getformatstr(28LL);
snprintf(tmpstr, 0x400uLL, v2, v1, a1);
networkoutput(a1);
return writechan(tmpstr);
}

original_code:
static void
output_default(char *line ) {
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBMSG), own_nick_get(), line);
      networkoutput (line);
      writechan (tmpstr);
}

canonical_original_code:
static void output_default(char *line) {
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBMSG), own_nick_get(), line);
      networkoutput (line);
      writechan (tmpstr);
}


translatecommand

original_code:
static int
translatecommand( char **cmd)
{
  int result;
  int cut = 0;
  int maxcut = 0;
  while( (*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) maxcut++;
  if( maxcut ) maxcut--;
  do {
      for( result = 0;
             (result != COMMAND_NONE) &&
             (strncasecmp(*cmd, commandtable[result].name, commandtable[result].len -
               ((commandtable[result].len - maxcut - cut > 0) ? cut : 0)));
           result++);
  } while ((cut < commandtable[0].len) && (commandtable[result].number == COMMAND_NONE) && (++cut));
  (*cmd) += commandtable[result].len;
  if( commandtable[result].number != COMMAND_NONE )
      (*cmd) -= cut;
  return result;
}

canonical_original_code:
static int translatecommand(char **cmd)
{
  int result;
  int cut = 0;
  int maxcut = 0;
  while( (*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) maxcut++;
  if( maxcut ) maxcut--;
  do {
      for( result = 0;
             (result != COMMAND_NONE) &&
             (strncasecmp(*cmd, commandtable[result].name, commandtable[result].len -
               ((commandtable[result].len - maxcut - cut > 0) ? cut : 0)));
           result++);
  } while ((cut < commandtable[0].len) && (commandtable[result].number == COMMAND_NONE) && (++cut));
  (*cmd) += commandtable[result].len;
  if( commandtable[result].number != COMMAND_NONE )
      (*cmd) -= cut;
  return result;
}

variable_types:
cmd
char **

variable_types: result int

variable_types: cut int

variable_types: maxcut int


decompiled_code:
__int64 __fastcall command_help(const char *a1)
{
char v1; // dl
const char *v2; // rax
char **v3; // rbx
int v4; // eax
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rbp
__int64 v8; // rbp
char *v9; // rdi
const char *v10; // rax
char *v11; // rdx
const char *v12; // rsi
const char *v13; // rax
char v14; // cl
const char *v16; // [rsp+8h] [rbp-20h] BYREF

v16 = a1;
flushout();
v1 = *a1;
if ( *a1 == 32 )
{
v2 = v16 + 1;
do
{
v16 = v2++;
v1 = *(v2 - 1);
}
while ( v1 == 32 );
}
if ( !v1 )
{
v3 = &off_9E0;
if ( commandtable[0] != 19 )
{
do
{
if ( *v3 )
writeout(*v3);
v3 += 6;
}
while ( *((_DWORD *)v3 - 8) != 19 );
}
return showout();
}
v4 = translatecommand(&v16);
v5 = v4;
if ( v4 == 19 )
{
command_help(" ");
return showout();
}
v6 = v4;
v7 = 2LL * v4;
snprintf(tmpstr, 0x400uLL, "Help on command: %s", &s2[48 * v4]);
writeout(tmpstr);
writeout(" ");
v8 = 2 * (v6 + v7);
v9 = (&off_9E0)[v8];
if ( !v9 )
goto LABEL_14;
v10 = (const char *)qword_9E8[v8];
if ( !v10 )
{
writeout(v9);
LABEL_14:
v10 = (const char *)qword_9E8[6 * v5];
v16 = v10;
if ( !v10 )
return showout();
goto LABEL_11;
}
v16 = (const char *)qword_9E8[v8];
LABEL_11:
if ( *v10 )
{
do
{
v12 = v16;
if ( !*v16 || (v13 = v16 + 1, v11 = tmpstr, *v16 == 10) )
{
v11 = tmpstr;
}
else
{
do
{
v12 = v13;
v16 = v13;
*v11++ = *(v13 - 1);
v14 = *v13++;
}
while ( v14 && v14 != 10 );
}
*v11 = 0;
if ( *v12 == 10 )
v16 = v12 + 1;
writeout(tmpstr);
}
while ( *v16 );
}
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func19(const char *a1)
{
char v1; // dl
const char *v2; // rax
char **v3; // rbx
int v4; // eax
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rbp
__int64 v8; // rbp
char *v9; // rdi
const char *v10; // rax
char *v11; // rdx
const char *v12; // rsi
const char *v13; // rax
char v14; // cl
const char *v16; // [rsp+8h] [rbp-20h] BYREF

v16 = a1;
flushout();
v1 = *a1;
if ( *a1 == 32 )
{
v2 = v16 + 1;
do
{
v16 = v2++;
v1 = *(v2 - 1);
}
while ( v1 == 32 );
}
if ( !v1 )
{
v3 = &off_9E0;
if ( commandtable[0] != 19 )
{
do
{
if ( *v3 )
writeout(*v3);
v3 += 6;
}
while ( *((_DWORD *)v3 - 8) != 19 );
}
return showout();
}
v4 = func18(&v16);
v5 = v4;
if ( v4 == 19 )
{
func19(" ");
return showout();
}
v6 = v4;
v7 = 2LL * v4;
snprintf(tmpstr, 0x400uLL, "Help on command: %s", &s2[48 * v4]);
writeout(tmpstr);
writeout(" ");
v8 = 2 * (v6 + v7);
v9 = (&off_9E0)[v8];
if ( !v9 )
goto LABEL_14;
v10 = (const char *)qword_9E8[v8];
if ( !v10 )
{
writeout(v9);
LABEL_14:
v10 = (const char *)qword_9E8[6 * v5];
v16 = v10;
if ( !v10 )
return showout();
goto LABEL_11;
}
v16 = (const char *)qword_9E8[v8];
LABEL_11:
if ( *v10 )
{
do
{
v12 = v16;
if ( !*v16 || (v13 = v16 + 1, v11 = tmpstr, *v16 == 10) )
{
v11 = tmpstr;
}
else
{
do
{
v12 = v13;
v16 = v13;
*v11++ = *(v13 - 1);
v14 = *v13++;
}
while ( v14 && v14 != 10 );
}
*v11 = 0;
if ( *v12 == 10 )
v16 = v12 + 1;
writeout(tmpstr);
}
while ( *v16 );
}
return showout();
}

original_code:
static void
command_help (char *line) {
  flushout( );
  while( *line==' ') line++;
  if( *line ) {
      int i;
      if( ( i = translatecommand( &line ) ) != COMMAND_NONE ) {
          snprintf( tmpstr, 1024, "Help on command: %s", commandtable[i].name);
          writeout( tmpstr );
          writeout(" ");
          if( commandtable[i].short_help && !commandtable[i].help )
              writeout(commandtable[i].short_help );
          line = commandtable[i].help;
          if( line ) {
            while( *line ) {
              char *tmp = tmpstr;
              while( *line && (*line != '\n') )
                  *tmp++ = *line++;
              *tmp = '\0'; if( *line == '\n') line++;
              writeout ( tmpstr );
            }
          }
      } else {
          command_help( " " );
      }
  } else {
      int i;
      for( i = 0; commandtable[i].number != COMMAND_NONE; i++ ) {
          if( commandtable[i].short_help )
              writeout( commandtable[i].short_help );
      }
  }
  showout();
}

canonical_original_code:
static void command_help(char *line) {
  flushout( );
  while( *line==' ') line++;
  if( *line ) {
      int i;
      if( ( i = translatecommand( &line ) ) != COMMAND_NONE ) {
          snprintf( tmpstr, 1024, "Help on command: %s", commandtable[i].name);
          writeout( tmpstr );
          writeout(" ");
          if( commandtable[i].short_help && !commandtable[i].help )
              writeout(commandtable[i].short_help );
          line = commandtable[i].help;
          if( line ) {
            while( *line ) {
              char *tmp = tmpstr;
              while( *line && (*line != '\n') )
                  *tmp++ = *line++;
              *tmp = '\0'; if( *line == '\n') line++;
              writeout ( tmpstr );
            }
          }
      } else {
          command_help( " " );
      }
  } else {
      int i;
      for( i = 0; commandtable[i].number != COMMAND_NONE; i++ ) {
          if( commandtable[i].short_help )
              writeout( commandtable[i].short_help );
      }
  }
  showout();
}

variable_types: i int

variable_types:
tmp
char *


handleline

decompiled_code:
__int64 __fastcall handleline(const char *a1)
{
char v2; // si
const char *v3; // rax
int v4; // eax
const char *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = a1;
if ( *a1 == 46 )
{
v2 = a1[1];
if ( v2 == 109 )
return privatemessagetx(a1 + 2);
if ( v2 > 109 )
{
if ( v2 != 111 )
{
if ( v2 == 120 )
ownquit = 1;
goto LABEL_9;
}
}
else if ( v2 != 79 )
{
if ( v2 == 97 )
return doaction(a1 + 2);
if ( v2 == 46 )
{
if ( a1[2] != 109 )
return output_default((__int64)a1);
flushout();
writeout("? You probably misstyped ?");
writeout(" ");
writeout(v5);
return showout();
}
LABEL_9:
v3 = (const char *)getformatstr(36LL);
snprintf(tmpstr, 0x400uLL, v3, a1);
writechan(tmpstr);
return networkoutput(v5);
}
return dothink(a1 + 2, v2);
}
if ( *a1 != 47 )
return output_default((__int64)a1);
v5 = a1 + 1;
v4 = translatecommand(&v5);
return ((__int64 (__fastcall *)(const char *))*(&off_9D8 + 6 * v4))(v5);
}

canonical_decompiled_code:
__int64 __fastcall func20(const char *a1)
{
char v2; // si
const char *v3; // rax
int v4; // eax
const char *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = a1;
if ( *a1 == 46 )
{
v2 = a1[1];
if ( v2 == 109 )
return func12(a1 + 2);
if ( v2 > 109 )
{
if ( v2 != 111 )
{
if ( v2 == 120 )
ownquit = 1;
goto LABEL_9;
}
}
else if ( v2 != 79 )
{
if ( v2 == 97 )
return func15(a1 + 2);
if ( v2 == 46 )
{
if ( a1[2] != 109 )
return func17((__int64)a1);
flushout();
writeout("? You probably misstyped ?");
writeout(" ");
writeout(v5);
return showout();
}
LABEL_9:
v3 = (const char *)getformatstr(36LL);
snprintf(tmpstr, 0x400uLL, v3, a1);
writechan(tmpstr);
return networkoutput(v5);
}
return func4(a1 + 2, v2);
}
if ( *a1 != 47 )
return func17((__int64)a1);
v5 = a1 + 1;
v4 = func18(&v5);
return ((__int64 (__fastcall *)(const char *))*(&off_9D8 + 6 * v4))(v5);
}

original_code:
void
handleline (char *line)
{
  switch ( line[0] )
  {
  case '.':
      switch ( line[1] ) {
      case 'm':
          privatemessagetx( line+2 );
          break;
      case 'a':
          doaction( line+2 );
          break;
      case '.':
          if( line[2] != 'm' ) {
              output_default( line );
          } else {
              flushout( );
              writeout("? You probably misstyped ?");
              writeout(" ");
              writeout(line );
              showout( );
          }
          break;
      case 'o':
      case 'O':
          dothink( line + 2, line[1] );
          break;
      case 'x':
          ownquit = 1;
      default:
          snprintf (tmpstr, 1024, getformatstr(FS_COMMAND), line);
          writechan (tmpstr);
          networkoutput (line);
          break;
      }
      break;
  case '/':
      line++;
      commandtable[translatecommand(&line)].handler(line);
      break;
  default:
      output_default( line );
      break;
  }
}

canonical_original_code:
void handleline(char *line)
{
  switch ( line[0] )
  {
  case '.':
      switch ( line[1] ) {
      case 'm':
          privatemessagetx( line+2 );
          break;
      case 'a':
          doaction( line+2 );
          break;
      case '.':
          if( line[2] != 'm' ) {
              output_default( line );
          } else {
              flushout( );
              writeout("? You probably misstyped ?");
              writeout(" ");
              writeout(line );
              showout( );
          }
          break;
      case 'o':
      case 'O':
          dothink( line + 2, line[1] );
          break;
      case 'x':
          ownquit = 1;
      default:
          snprintf (tmpstr, 1024, getformatstr(FS_COMMAND), line);
          writechan (tmpstr);
          networkoutput (line);
          break;
      }
      break;
  case '/':
      line++;
      commandtable[translatecommand(&line)].handler(line);
      break;
  default:
      output_default( line );
      break;
  }
}


transform

repo: bernarpa/PAES

variable_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; } *

variable_types:
data
unsigned char *

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int

variable_types:
e
unsigned int

variable_types:
f
unsigned int

variable_types:
g
unsigned int

variable_types:
h
unsigned int

variable_types:
w
unsigned int [64]

variable_types: t int

variable_types:
k
unsigned int []