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

memset(&file_type_regexps, 0, 0x100uLL);
if ( regcomp(&preg, "^_trace_shm_([[:digit:]]{1,6})_dynamic_trace_data$", 1) )
_assert_fail(
"(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0"
" == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1))",
"file_naming.c",
0x79u,
"compile_regexps");
if ( regcomp(&stru_420, "^_trace_shm_([[:digit:]]{1,6})_([[:digit:]]+)_static_trace_metadata$", 1) )
_assert_fail(
"(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || TRACE_LOG_ASSERTION"
"_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1))",
"file_naming.c",
0x7Au,
"compile_regexps");
result = regcomp(&file_type_regexps, "^_trace_shm_([[:digit:]]{1,6})_.+ic_trace_.*data$", 1);
if ( result )
_assert_fail(
"(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == "
"regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1))",
"file_naming.c",
0x7Bu,
"compile_regexps");
return result;
}

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

memset(&file_type_regexps, 0, 0x100uLL);
if ( regcomp(&preg, "^_trace_shm_([[:digit:]]{1,6})_dynamic_trace_data$", 1) )
_assert_fail(
"(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0"
" == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1))",
"file_naming.c",
0x79u,
"compile_regexps");
if ( regcomp(&stru_420, "^_trace_shm_([[:digit:]]{1,6})_([[:digit:]]+)_static_trace_metadata$", 1) )
_assert_fail(
"(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || TRACE_LOG_ASSERTION"
"_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1))",
"file_naming.c",
0x7Au,
"compile_regexps");
result = regcomp(&file_type_regexps, "^_trace_shm_([[:digit:]]{1,6})_.+ic_trace_.*data$", 1);
if ( result )
_assert_fail(
"(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == "
"regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1))",
"file_naming.c",
0x7Bu,
"compile_regexps");
return result;
}

original_code:
static void compile_regexps(void)
{
    memset(file_type_regexps, 0, sizeof(file_type_regexps));
    ((void) sizeof (((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || (0)) ? 1 : 0), __extension__ ({ if ((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || (0)) ; else __assert_fail ("(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1))", "file_naming.c", 121, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || (0)) ? 1 : 0), __extension__ ({ if ((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || (0)) ; else __assert_fail ("(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1))", "file_naming.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || (0)) ? 1 : 0), __extension__ ({ if ((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || (0)) ; else __assert_fail ("(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1))", "file_naming.c", 123, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void compile_regexps()
{
    memset(file_type_regexps, 0, sizeof(file_type_regexps));
    ((void) sizeof (((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || (0)) ? 1 : 0), __extension__ ({ if ((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || (0)) ; else __assert_fail ("(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_DYNAMIC, shm_dynamic_regexp, 1))", "file_naming.c", 121, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || (0)) ? 1 : 0), __extension__ ({ if ((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || (0)) ; else __assert_fail ("(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_STATIC_PER_PROCESS, shm_static_regexp, 1))", "file_naming.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || (0)) ? 1 : 0), __extension__ ({ if ((0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || (0)) ; else __assert_fail ("(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1)) || TRACE_LOG_ASSERTION_FAILURE(0 == regcomp(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_generic_regexp, 1))", "file_naming.c", 123, __extension__ __PRETTY_FUNCTION__); }));
}


repo: Infinidat/infinitrace

decompiled_code:
__int64 __fastcall trace_get_pid_from_shm_name(char *string)
{
regmatch_t v2; // [rsp+0h] [rbp-18h] BYREF
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

if ( !regexec(&file_type_regexps, string, 2uLL, &v2, 0) )
return get_number_from_match_group((__int64)string, v3);
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *string)
{
regmatch_t v2; // [rsp+0h] [rbp-18h] BYREF
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

if ( !regexec(&file_type_regexps, string, 2uLL, &v2, 0) )
return func0((__int64)string, v3);
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}

original_code:
pid_t trace_get_pid_from_shm_name(const char *shm_name)
{
    regmatch_t matches[2];
    if (0 != regexec(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_name, (sizeof(matches) / sizeof(matches[0])), matches, 0)) {
        (*__errno_location ()) = 22;
        return -1;
    }
    return (pid_t) get_number_from_match_group(shm_name, matches + 1);
}

canonical_original_code:
int trace_get_pid_from_shm_name(char *shm_name)
{
    struct regmatch_t matches[2];
    if (0 != regexec(file_type_regexps + TRACE_SHM_TYPE_ANY, shm_name, (sizeof(matches) / sizeof(matches[0])), matches, 0)) {
        (*__errno_location ()) = 22;
        return -1;
    }
    return (int) get_number_from_match_group(shm_name, matches + 1);
}

variable_types: struct regmatch_t { int rm_so; int rm_eo; } [2]

return_type: int


decompiled_code:
_BOOL8 __fastcall is_digit(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
static int is_digit(char chr) {
    return chr >= '0' && chr <= '9' ;
}

variable_types: chr char


decompiled_code:
_BOOL8 __fastcall all_digits(char *a1)
{
char *v1; // rbx
char v2; // di
_BOOL8 result; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = *a1;
result = 0LL;
if ( v2 )
{
while ( 1 )
{
result = is_digit(v2);
if ( !result )
break;
v2 = *++v1;
if ( !*v1 )
return 1LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *a1)
{
char *v1; // rbx
char v2; // di
_BOOL8 result; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = *a1;
result = 0LL;
if ( v2 )
{
while ( 1 )
{
result = func0(v2);
if ( !result )
break;
v2 = *++v1;
if ( !*v1 )
return 1LL;
}
}
return result;
}

original_code:
static int all_digits(const char* str) {
    if (! (str && *str) )
        return 0;
    for (;*str; str++)
        if ( ! is_digit(*str))
            return 0;
    return 1;
}

canonical_original_code:
static int all_digits(char *str) {
    if (! (str && *str) )
        return 0;
    for (;*str; str++)
        if ( ! is_digit(*str))
            return 0;
    return 1;
}

variable_types:
str
char *


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

result = 1LL;
if ( a1 > 0 )
result = 10 * (unsigned int)pow10i((unsigned int)(a1 - 1));
return result;
}

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

result = 1LL;
if ( a1 > 0 )
result = 10 * (unsigned int)func2((unsigned int)(a1 - 1));
return result;
}

original_code:
static int pow10i(int n){
    return n>0 ? 10*pow10i(n-1) : 1;
}

variable_types: n int


decompiled_code:
__int64 __fastcall atoll_n(char *a1, int a2)
{
int v2; // ebp
__int64 v4; // r13
int v5; // ebx

if ( !a2 )
return 0LL;
v2 = a2;
v4 = 0LL;
do
{
v5 = *a1;
if ( !is_digit(*a1) )
break;
v4 += (int)(pow10i(--v2) * (v5 - 48));
++a1;
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int a2)
{
int v2; // ebp
__int64 v4; // r13
int v5; // ebx

if ( !a2 )
return 0LL;
v2 = a2;
v4 = 0LL;
do
{
v5 = *a1;
if ( !func0(*a1) )
break;
v4 += (int)(func2(--v2) * (v5 - 48));
++a1;
}
while ( v2 );
return v4;
}

original_code:
static long long atoll_n(const char* str, int n) {
    long long ret = 0;
    for (int i = n ; i; i -- ) {
        if (! is_digit(str[n-i]))
            return ret;
        ret += (str[n-i] - '0') * pow10i(i-1);
    }
    return ret;
}

canonical_original_code:
static long long atoll_n(char *str, int n) {
    long long ret = 0;
    for (int i = n; i; i -- ) {
        if (! is_digit(str[n-i]))
            return ret;
        ret += (str[n-i] - '0') * pow10i(i-1);
    }
    return ret;
}

variable_types:
ret
long long

variable_types: i int

return_type: long long


timegm

decompiled_code:
time_t __fastcall timegm(struct tm *tp)
{
char *v1; // rbx
time_t v2; // rbp

v1 = getenv("TZ");
setenv("TZ", &LC1, 1);
tzset();
v2 = mktime(tp);
if ( v1 )
setenv("TZ", v1, 1);
else
unsetenv("TZ");
tzset();
return v2;
}

canonical_decompiled_code:
time_t __fastcall func4(struct tm *tp)
{
char *v1; // rbx
time_t v2; // rbp

v1 = getenv("TZ");
setenv("TZ", &LC1, 1);
tzset();
v2 = mktime(tp);
if ( v1 )
setenv("TZ", v1, 1);
else
unsetenv("TZ");
tzset();
return v2;
}

original_code:
time_t timegm(struct tm *tm)
{
    time_t ret;
    char *tz;
    tz = getenv("TZ");
    setenv("TZ", "", 1);
    tzset();
    ret = mktime(tm);
    if (tz) {
        setenv("TZ", tz, 1);
    } else {
        unsetenv("TZ");
    }
    tzset();
    return ret;
}

canonical_original_code:
long timegm(struct tm *tm)
{
    long ret;
    char *tz;
    tz = getenv("TZ");
    setenv("TZ", "", 1);
    tzset();
    ret = mktime(tm);
    if (tz) {
        setenv("TZ", tz, 1);
    } else {
        unsetenv("TZ");
    }
    tzset();
    return ret;
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: ret long

variable_types:
tz
char *

return_type: long


decompiled_code:
__int64 __fastcall str_to_nano_seconds(char *nptr)
{
char *v1; // rbx
char v2; // di
int v3; // edx
time_t v4; // rbp
char *v6; // rbp
char v7; // di
char *v8; // rbp
char v9; // di
struct tm v10; // [rsp+0h] [rbp-58h] BYREF

if ( !nptr )
return 0LL;
v1 = nptr;
v2 = *nptr;
if ( v2 )
{
do
{
if ( is_digit(v2) )
break;
v2 = *++v1;
}
while ( *v1 );
}
v3 = strlen(v1);
if ( v3 > 9 )
{
if ( all_digits(v1) )
return atoll(v1);
*(_QWORD *)&v10.tm_sec = 0LL;
*(_QWORD *)&v10.tm_hour = 0LL;
*(_QWORD *)&v10.tm_mon = 0LL;
*(_QWORD *)&v10.tm_wday = 0LL;
*(_QWORD *)&v10.tm_isdst = 0LL;
v10.tm_gmtoff = 0LL;
v10.tm_zone = 0LL;
if ( v1[4] != 47 || v1[7] != 47 )
goto LABEL_12;
v10.tm_year = atoll_n(v1, 4) - 1900;
v10.tm_mon = atoll_n(v1 + 5, 2) - 1;
v10.tm_mday = atoll_n(v1 + 8, 2);
v8 = v1 + 10;
v9 = v1[10];
v1 += 10;
if ( v9 )
{
while ( !is_digit(v9) )
{
v9 = *++v8;
if ( !*v8 )
{
v1 = v8;
goto LABEL_25;
}
}
v1 = v8;
}
LABEL_25:
v3 = strlen(v1);
}
else
{
*(_QWORD *)&v10.tm_sec = 0LL;
*(_QWORD *)&v10.tm_hour = 0LL;
*(_QWORD *)&v10.tm_mon = 0LL;
*(_QWORD *)&v10.tm_wday = 0LL;
*(_QWORD *)&v10.tm_isdst = 0LL;
v10.tm_gmtoff = 0LL;
v10.tm_zone = 0LL;
}
if ( v3 > 7 )
{
LABEL_12:
if ( v1[2] == 58 && v1[5] == 58 )
{
v10.tm_hour = atoll_n(v1, 2);
v10.tm_min = atoll_n(v1 + 3, 2);
v10.tm_sec = atoll_n(v1 + 6, 2);
v6 = v1 + 8;
v7 = v1[8];
v1 += 8;
if ( v7 )
{
while ( !is_digit(v7) )
{
v7 = *++v6;
if ( !*v6 )
{
v1 = v6;
goto LABEL_8;
}
}
v1 = v6;
}
}
}
LABEL_8:
v4 = timegm(&v10);
return atoll_n(v1, 9) + 1000000000 * v4;
}

original_code:
unsigned long long str_to_nano_seconds(const char* str) {
    int len;
    if (!str) return 0;
    while (*str && !is_digit(*str)) str++ ; len = strlen(str);
    if (len > 9 && all_digits(str)) {
        return atoll(str);
    }
    struct tm t = { 0 };
    if (len >= 10 && str[4] == '/' && str[7] == '/') {
        t.tm_year = atoll_n(str+0, 4) - 1900;
        t.tm_mon = atoll_n(str+5, 2) - 1;
        t.tm_mday = atoll_n(str+8, 2);
        str += 10;
        while (*str && !is_digit(*str)) str++ ; len = strlen(str);
    }
    if (len >= 8 && str[2] == ':' && str[5] == ':') {
        t.tm_hour = atoll_n(str+0, 2);
        t.tm_min = atoll_n(str+3, 2);
        t.tm_sec = atoll_n(str+6, 2);
        str += 8;
        while (*str && !is_digit(*str)) str++ ; len = strlen(str);
    }
    return ((1000000000LL) * (timegm(&t))) + atoll_n(str, 9);
}

canonical_original_code:
unsigned long long str_to_nano_seconds(char *str) {
    int len;
    if (!str) return 0;
    while (*str && !is_digit(*str)) str++ ; len = strlen(str);
    if (len > 9 && all_digits(str)) {
        return atoll(str);
    }
    struct tm t = { 0 };
    if (len >= 10 && str[4] == '/' && str[7] == '/') {
        t.tm_year = atoll_n(str+0, 4) - 1900;
        t.tm_mon = atoll_n(str+5, 2) - 1;
        t.tm_mday = atoll_n(str+8, 2);
        str += 10;
        while (*str && !is_digit(*str)) str++ ; len = strlen(str);
    }
    if (len >= 8 && str[2] == ':' && str[5] == ':') {
        t.tm_hour = atoll_n(str+0, 2);
        t.tm_min = atoll_n(str+3, 2);
        t.tm_sec = atoll_n(str+6, 2);
        str += 8;
        while (*str && !is_digit(*str)) str++ ; len = strlen(str);
    }
    return ((1000000000LL) * (timegm(&t))) + atoll_n(str, 9);
}

variable_types: len int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

return_type: unsigned long long


decompiled_code:
char *__fastcall format_timestamp(unsigned __int64 a1, int a2, int a3)
{
unsigned __int64 v4; // rdx
struct tm *v6; // rax
struct tm *v7; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( a2 )
{
sprintf(cached_timestamp, "%012llu", a1);
}
else
{
v4 = a1 / 0x3B9ACA00;
timer = a1 / 0x3B9ACA00;
if ( a3 )
{
if ( v4 != cached_sec_int )
{
cached_sec_int = a1 / 0x3B9ACA00;
v7 = gmtime(&timer);
sprintf(
cached_timestamp,
"%02d:%02d:%02d_",
(unsigned int)v7->tm_hour,
(unsigned int)v7->tm_min,
(unsigned int)v7->tm_sec);
}
sprintf(byte_529, "%09llu", a1 % 0x3B9ACA00);
}
else
{
if ( v4 != cached_sec_int )
{
cached_sec_int = a1 / 0x3B9ACA00;
v6 = gmtime(&timer);
sprintf(
cached_timestamp,
"%04d/%02d/%02d_%02d:%02d:%02d_",
(unsigned int)(v6->tm_year + 1900),
(unsigned int)(v6->tm_mon + 1),
(unsigned int)v6->tm_mday,
(unsigned int)v6->tm_hour,
(unsigned int)v6->tm_min,
(unsigned int)v6->tm_sec);
}
sprintf(s, "%09llu", a1 % 0x3B9ACA00);
}
}
return cached_timestamp;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned __int64 a1, int a2, int a3)
{
unsigned __int64 v4; // rdx
struct tm *v6; // rax
struct tm *v7; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( a2 )
{
sprintf(cached_timestamp, "%012llu", a1);
}
else
{
v4 = a1 / 0x3B9ACA00;
timer = a1 / 0x3B9ACA00;
if ( a3 )
{
if ( v4 != cached_sec_int )
{
cached_sec_int = a1 / 0x3B9ACA00;
v7 = gmtime(&timer);
sprintf(
cached_timestamp,
"%02d:%02d:%02d_",
(unsigned int)v7->tm_hour,
(unsigned int)v7->tm_min,
(unsigned int)v7->tm_sec);
}
sprintf(byte_529, "%09llu", a1 % 0x3B9ACA00);
}
else
{
if ( v4 != cached_sec_int )
{
cached_sec_int = a1 / 0x3B9ACA00;
v6 = gmtime(&timer);
sprintf(
cached_timestamp,
"%04d/%02d/%02d_%02d:%02d:%02d_",
(unsigned int)(v6->tm_year + 1900),
(unsigned int)(v6->tm_mon + 1),
(unsigned int)v6->tm_mday,
(unsigned int)v6->tm_hour,
(unsigned int)v6->tm_min,
(unsigned int)v6->tm_sec);
}
sprintf(s, "%09llu", a1 % 0x3B9ACA00);
}
}
return cached_timestamp;
}

original_code:
const char* format_timestamp(unsigned long long ts, int relative, int compact) {
    if (relative) {
        sprintf(cached_timestamp, "%012llu", ts - first_ts);
        return cached_timestamp;
    }
    time_t seconds = ts / (1000000000LL);
    if (!compact) {
        if (cached_sec_int != seconds) {
            cached_sec_int = seconds;
            const struct tm *_time = gmtime(&seconds);
            sprintf(cached_timestamp, "%04d/%02d/%02d_%02d:%02d:%02d_",
                    1900+_time->tm_year, 1+_time->tm_mon, _time->tm_mday,
                    _time->tm_hour, _time->tm_min, _time->tm_sec
                   );
        }
        sprintf(cached_timestamp + 20, "%09llu", ts % (1000000000LL));
    }
    else {
        if (cached_sec_int != seconds) {
            cached_sec_int = seconds;
            const struct tm *_time = gmtime(&seconds);
            sprintf(cached_timestamp, "%02d:%02d:%02d_", _time->tm_hour, _time->tm_min, _time->tm_sec);
        }
        sprintf(cached_timestamp + 9, "%09llu", ts % (1000000000LL));
    }
    return cached_timestamp;
}

canonical_original_code:
char *format_timestamp(unsigned long long ts, int relative, int compact) {
    if (relative) {
        sprintf(cached_timestamp, "%012llu", ts - first_ts);
        return cached_timestamp;
    }
    long seconds = ts / (1000000000LL);
    if (!compact) {
        if (cached_sec_int != seconds) {
            cached_sec_int = seconds;
            struct tm *_time = gmtime(&seconds);
            sprintf(cached_timestamp, "%04d/%02d/%02d_%02d:%02d:%02d_",
                    1900+_time->tm_year, 1+_time->tm_mon, _time->tm_mday,
                    _time->tm_hour, _time->tm_min, _time->tm_sec
                   );
        }
        sprintf(cached_timestamp + 20, "%09llu", ts % (1000000000LL));
    }
    else {
        if (cached_sec_int != seconds) {
            cached_sec_int = seconds;
            struct tm *_time = gmtime(&seconds);
            sprintf(cached_timestamp, "%02d:%02d:%02d_", _time->tm_hour, _time->tm_min, _time->tm_sec);
        }
        sprintf(cached_timestamp + 9, "%09llu", ts % (1000000000LL));
    }
    return cached_timestamp;
}

variable_types:
ts
unsigned long long

variable_types: relative int

variable_types: compact int

variable_types: seconds long

return_type: char *

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
unsigned __int64 __fastcall num_metadata_trace_records(__int64 a1)
{
return (a1 + 43) / 0x2CuLL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1)
{
return (a1 + 43) / 0x2CuLL;
}

original_code:
static inline size_t num_metadata_trace_records(size_t metadata_size)
{
 return (metadata_size + 44U - 1) / 44U;
}

canonical_original_code:
static inline unsigned long num_metadata_trace_records(unsigned long metadata_size)
{
 return (metadata_size + 44U - 1) / 44U;
}

return_type: unsigned long


decompiled_code:
__int64 trace_dumper_async_timed_out()
{
int *v0; // rax

v0 = _errno_location();
return (*v0 == 4) | (unsigned __int8)(*v0 == 11);
}

canonical_decompiled_code:
__int64 func1()
{
int *v0; // rax

v0 = _errno_location();
return (*v0 == 4) | (unsigned __int8)(*v0 == 11);
}

original_code:
static inline bool_t trace_dumper_async_timed_out(void)
{
    const int e = (*__errno_location ());
    return ((11 == e) || (4 == e));
}

canonical_original_code:
static inline int trace_dumper_async_timed_out()
{
    int e = (*__errno_location ());
    return ((11 == e) || (4 == e));
}

variable_types: e int


decompiled_code:
void __fastcall free_metadata(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 104) = 0LL;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 104) = 0LL;
}

original_code:
void free_metadata(struct trace_mapped_metadata *metadata)
{
    free(metadata->metadata_iovec);
 metadata->metadata_iovec = ((void *)0);
 metadata->metadata_iovec_len = 0;
}

variable_types: struct trace_mapped_metadata { struct iovec { void *iov_base; unsigned long iov_len; } *metadata_iovec; struct trace_record { unsigned long long ts; unsigned short pid; unsigned short tid; short nesting; short bit_fields[]; unsigned int termination; unsigned int module_id; unsigned int reserved; unsigned int severity; unsigned int rec_type; unsigned int generation; union trace_record_u { unsigned char payload[44]; struct trace_record_typed { unsigned int log_id; unsigned char payload[]; } typed; struct trace_record_file_header { char machine_id[24]; unsigned short format_version; unsigned short flags; unsigned char reserved[4]; unsigned int magic; } file_header; struct trace_record_metadata { unsigned int metadata_size_bytes; unsigned short dead_pids[4]; unsigned char reserved[-1]; unsigned int metadata_magic; } metadata; struct trace_record_dump_header { unsigned int prev_dump_offset; unsigned int total_dump_size; unsigned int first_chunk_offset; unsigned long records_previously_discarded; } dump_header; struct trace_record_buffer_dump { unsigned int last_metadata_offset; unsigned int prev_chunk_offset; unsigned int dump_header_offset; unsigned long long ts; unsigned int records; unsigned int severity_type; unsigned int lost_records; unsigned short flags; unsigned char slack_bytes; } buffer_chunk; struct trace_record_data_loss { unsigned int lost_records; unsigned long long ts_start; unsigned long long ts_end; } data_loss; } u; } metadata_payload_record; unsigned long log_descriptor_count; unsigned long type_definition_count; unsigned long size; unsigned long metadata_iovec_len; struct trace_metadata_region { char name[-1]; void *base_address; unsigned long log_descriptor_count; unsigned long type_definition_count; char data[]; } *base_address; struct trace_log_descriptor { enum trace_log_descriptor_kind { TRACE_LOG_DESCRIPTOR_KIND_FUNC_ENTRY=0, TRACE_LOG_DESCRIPTOR_KIND_FUNC_LEAVE=1, TRACE_LOG_DESCRIPTOR_KIND_EXPLICIT=2 } kind; unsigned int line; unsigned int severity; struct trace_param_descriptor { unsigned long flags; char *param_name; union { char *str; char *const_str; char *type_name; }; } *params; char *file; char *function; } *descriptors; } *

return_type: void

user_defined_types: struct trace_mapped_metadata { struct iovec *metadata_iovec; struct trace_record metadata_payload_record; unsigned long log_descriptor_count; unsigned long type_definition_count; unsigned long size; unsigned long metadata_iovec_len; struct trace_metadata_region *base_address; struct trace_log_descriptor *descriptors; }

user_defined_types: struct trace_record { unsigned long long ts; unsigned short pid; unsigned short tid; short nesting; short bit_fields[]; unsigned int termination; unsigned int module_id; unsigned int reserved; unsigned int severity; unsigned int rec_type; unsigned int generation; union trace_record_u u; }

user_defined_types: union trace_record_u { unsigned char payload[44]; struct trace_record_typed typed; struct trace_record_file_header file_header; struct trace_record_metadata metadata; struct trace_record_dump_header dump_header; struct trace_record_buffer_dump buffer_chunk; struct trace_record_data_loss data_loss; }

user_defined_types: struct trace_log_descriptor { enum trace_log_descriptor_kind kind; unsigned int line; unsigned int severity; struct trace_param_descriptor *params; char *file; char *function; }


usage

repo: IsaacHorvath/RhythmboxAlarm

decompiled_code:
int usage()
{
printf("Usage:\n\tRhythmboxAlarm set <alarm> <on|off> <hour>:<minute>");
return puts("\n\tRhythmboxAlarm get <alarm>");
}

canonical_decompiled_code:
int func7()
{
printf("Usage:\n\tRhythmboxAlarm set <alarm> <on|off> <hour>:<minute>");
return puts("\n\tRhythmboxAlarm get <alarm>");
}

original_code:
void usage() {
 printf("Usage:\n\tRhythmboxAlarm set <alarm> <on|off> <hour>:<minute>");
 printf("\n\tRhythmboxAlarm get <alarm>\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__uid_t v3; // eax
struct passwd *v4; // rax
int v5; // ebx
int v6; // ebx
int v8; // er12
_BOOL4 v9; // er13
FILE *v10; // rbp
int v11; // er12
FILE *v12; // rbp
char v13[16]; // [rsp+0h] [rbp-148h] BYREF
char dest[260]; // [rsp+10h] [rbp-138h] BYREF
unsigned int v15; // [rsp+118h] [rbp-30h]
unsigned int v16; // [rsp+11Ch] [rbp-2Ch]

v3 = getuid();
v4 = getpwuid(v3);
strcpy(dest, v4->pw_dir);
strcpy(&dest[strlen(dest)], "/.alarms");
if ( argc <= 4 )
{
if ( argc <= 2 )
goto LABEL_4;
}
else
{
v5 = strcmp(argv[1], "set");
if ( !v5 )
{
v8 = atoi(argv[2]);
v9 = strcmp(argv[3], "on") == 0;
__isoc99_sscanf();
v10 = fopen(dest, "r+");
if ( v8 > 0 )
{
do
{
fgets(v13, 16, v10);
++v5;
}
while ( v8 != v5 );
}
fprintf(v10, "%d %02d:%02d", v9, v16, v15);
fclose(v10);
return 0;
}
}
v6 = strcmp(argv[1], "get");
if ( v6 )
{
LABEL_4:
usage();
return 0;
}
v11 = atoi(argv[2]);
v12 = fopen(dest, "r");
__isoc99_fscanf();
if ( v11 > 0 )
{
do
{
__isoc99_fscanf();
++v6;
}
while ( v11 != v6 );
}
printf("Alarm %d: %02d:%02d\n", (unsigned int)v11, v16, v15);
fclose(v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__uid_t v3; // eax
struct passwd *v4; // rax
int v5; // ebx
int v6; // ebx
int v8; // er12
_BOOL4 v9; // er13
FILE *v10; // rbp
int v11; // er12
FILE *v12; // rbp
char v13[16]; // [rsp+0h] [rbp-148h] BYREF
char dest[260]; // [rsp+10h] [rbp-138h] BYREF
unsigned int v15; // [rsp+118h] [rbp-30h]
unsigned int v16; // [rsp+11Ch] [rbp-2Ch]

v3 = getuid();
v4 = getpwuid(v3);
strcpy(dest, v4->pw_dir);
strcpy(&dest[strlen(dest)], "/.alarms");
if ( argc <= 4 )
{
if ( argc <= 2 )
goto LABEL_4;
}
else
{
v5 = strcmp(argv[1], "set");
if ( !v5 )
{
v8 = atoi(argv[2]);
v9 = strcmp(argv[3], "on") == 0;
__isoc99_sscanf();
v10 = fopen(dest, "r+");
if ( v8 > 0 )
{
do
{
fgets(v13, 16, v10);
++v5;
}
while ( v8 != v5 );
}
fprintf(v10, "%d %02d:%02d", v9, v16, v15);
fclose(v10);
return 0;
}
}
v6 = strcmp(argv[1], "get");
if ( v6 )
{
LABEL_4:
func7();
return 0;
}
v11 = atoi(argv[2]);
v12 = fopen(dest, "r");
__isoc99_fscanf();
if ( v11 > 0 )
{
do
{
__isoc99_fscanf();
++v6;
}
while ( v11 != v6 );
}
printf("Alarm %d: %02d:%02d\n", (unsigned int)v11, v16, v15);
fclose(v12);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int i, num_alarms;
 time_t rawtime;
 struct tm *timeinfo;
 int alarms[32][4];
 pid_t pid = 0, sid = 0;
 pid = fork();
 if (pid < 0) {
  printf("Fork failed!\n");
  exit(1);
 }
 else if (pid > 0) {
  printf("pid of child process %d \n", pid);
         exit(0);
     }
 umask(0);
 sid = setsid();
 if(sid < 0)
  exit(1);
 close(0);
 close(1);
 close(2);
 while (1) {
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  num_alarms = read_file(alarms);
  for (i = 0; i < num_alarms; i++) {
   if (alarms[i][0]) {
    if (timeinfo->tm_hour == alarms[i][1] && timeinfo->tm_min == alarms[i][2]) {
     if (!alarms[i][3]) {
      system("amixer set Master 0");
      system("rhythmbox-client --play");
      alarms[i][3] = 1;
     }
     else system("amixer set Master 5+");
    }
    else alarms[i][3] = 0;
   }
  }
  usleep(3000000);
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int i; int num_alarms;
 long rawtime;
 struct tm *timeinfo;
 int alarms[32][4];
 int pid = 0; int sid = 0;
 pid = fork();
 if (pid < 0) {
  printf("Fork failed!\n");
  exit(1);
 }
 else if (pid > 0) {
  printf("pid of child process %d \n", pid);
         exit(0);
     }
 umask(0);
 sid = setsid();
 if(sid < 0)
  exit(1);
 close(0);
 close(1);
 close(2);
 while (1) {
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  num_alarms = read_file(alarms);
  for (i = 0; i < num_alarms; i++) {
   if (alarms[i][0]) {
    if (timeinfo->tm_hour == alarms[i][1] && timeinfo->tm_min == alarms[i][2]) {
     if (!alarms[i][3]) {
      system("amixer set Master 0");
      system("rhythmbox-client --play");
      alarms[i][3] = 1;
     }
     else system("amixer set Master 5+");
    }
    else alarms[i][3] = 0;
   }
  }
  usleep(3000000);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: rawtime long

variable_types:
alarms
int [32][4]

variable_types: pid int

variable_types: sid int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
_DWORD *v4; // rbx
struct tm *v5; // rbp
int v6; // eax
_BYTE *v7; // r13
_BYTE v8[520]; // [rsp+0h] [rbp-238h] BYREF
time_t timer; // [rsp+208h] [rbp-30h] BYREF

v3 = fork();
if ( v3 >= 0 )
{
if ( v3 > 0 )
{
printf("pid of child process %d \n", (unsigned int)v3);
exit(0);
}
umask(0);
if ( setsid() >= 0 )
{
close(0);
close(1);
close(2);
while ( 1 )
{
time(&timer);
v5 = localtime(&timer);
v6 = read_file((__int64)v8);
if ( v6 > 0 )
{
v4 = v8;
v7 = &v8[16 * (v6 - 1) + 16];
do
{
if ( *v4 )
{
if ( v5->tm_hour == v4[1] && v5->tm_min == v4[2] )
{
if ( v4[3] )
{
system("amixer set Master 5+");
}
else
{
system("amixer set Master 0");
system("rhythmbox-client --play");
v4[3] = 1;
}
}
else
{
v4[3] = 0;
}
}
v4 += 4;
}
while ( v4 != (_DWORD *)v7 );
}
usleep(0x2DC6C0u);
}
}
exit(1);
}
puts("Fork failed!");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
_DWORD *v4; // rbx
struct tm *v5; // rbp
int v6; // eax
_BYTE *v7; // r13
_BYTE v8[520]; // [rsp+0h] [rbp-238h] BYREF
time_t timer; // [rsp+208h] [rbp-30h] BYREF

v3 = fork();
if ( v3 >= 0 )
{
if ( v3 > 0 )
{
printf("pid of child process %d \n", (unsigned int)v3);
exit(0);
}
umask(0);
if ( setsid() >= 0 )
{
close(0);
close(1);
close(2);
while ( 1 )
{
time(&timer);
v5 = localtime(&timer);
v6 = func7((__int64)v8);
if ( v6 > 0 )
{
v4 = v8;
v7 = &v8[16 * (v6 - 1) + 16];
do
{
if ( *v4 )
{
if ( v5->tm_hour == v4[1] && v5->tm_min == v4[2] )
{
if ( v4[3] )
{
system("amixer set Master 5+");
}
else
{
system("amixer set Master 0");
system("rhythmbox-client --play");
v4[3] = 1;
}
}
else
{
v4[3] = 0;
}
}
v4 += 4;
}
while ( v4 != (_DWORD *)v7 );
}
usleep(0x2DC6C0u);
}
}
exit(1);
}
puts("Fork failed!");
exit(1);
}

variable_types: i int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


repo: IvanMalison/grid

decompiled_code:
__int64 __fastcall build_address(const char *a1, __int16 a2, __int64 a3)
{
struct hostent *v4; // rax

v4 = gethostbyname(a1);
if ( !v4 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)&v4->h_addrtype != 0x400000002LL )
return 0xFFFFFFFFLL;
*(_WORD *)a3 = 2;
*(_DWORD *)(a3 + 4) = **(_DWORD **)v4->h_addr_list;
*(_WORD *)(a3 + 2) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int16 a2, __int64 a3)
{
struct hostent *v4; // rax

v4 = gethostbyname(a1);
if ( !v4 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)&v4->h_addrtype != 0x400000002LL )
return 0xFFFFFFFFLL;
*(_WORD *)a3 = 2;
*(_DWORD *)(a3 + 4) = **(_DWORD **)v4->h_addr_list;
*(_WORD *)(a3 + 2) = a2;
return 0LL;
}

original_code:
int build_address(char *hostname, int port, struct sockaddr_in *inet_address) {
  struct hostent *host_entries;
  host_entries = gethostbyname(hostname);
  if (host_entries == ((void *)0) || host_entries->h_addrtype != 2 || host_entries->h_length != 4) {
    return (-1);
  } else {
    inet_address->sin_family = 2;
    inet_address->sin_addr.s_addr = *((uint32_t *)host_entries->h_addr_list[0]);
    inet_address->sin_port = port;
    return 0;
  }
}

canonical_original_code:
int build_address(char *hostname, int port, struct sockaddr_in *inet_address) {
  struct hostent *host_entries;
  host_entries = gethostbyname(hostname);
  if (host_entries == ((void *)0) || host_entries->h_addrtype != 2 || host_entries->h_length != 4) {
    return (-1);
  } else {
    inet_address->sin_family = 2;
    inet_address->sin_addr.s_addr = *((unsigned int *)host_entries->h_addr_list[0]);
    inet_address->sin_port = port;
    return 0;
  }
}

variable_types:
hostname
char *

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
__int64 __fastcall set_up_listener(__int16 a1, int *a2)
{
int v2; // eax
int v3; // ebx
__int64 result; // rax
int v5; // eax
struct sockaddr v6; // [rsp+0h] [rbp-A8h] BYREF
char name[152]; // [rsp+10h] [rbp-98h] BYREF

*(_QWORD *)&v6.sa_family = 0LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
v2 = socket(2, 1, 6);
if ( v2 == -1 )
return 4294967293LL;
v3 = v2;
if ( gethostname(name, 0x80uLL) < 0 )
return 4294967293LL;
result = build_address(name, a1, (__int64)&v6);
if ( (int)result >= 0 )
{
v5 = bind(v3, &v6, 0x10u);
if ( v5 == 98 )
{
result = 4294967294LL;
}
else if ( v5 < 0 )
{
result = 4294967293LL;
}
else
{
*a2 = v3;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, int *a2)
{
int v2; // eax
int v3; // ebx
__int64 result; // rax
int v5; // eax
struct sockaddr v6; // [rsp+0h] [rbp-A8h] BYREF
char name[152]; // [rsp+10h] [rbp-98h] BYREF

*(_QWORD *)&v6.sa_family = 0LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
v2 = socket(2, 1, 6);
if ( v2 == -1 )
return 4294967293LL;
v3 = v2;
if ( gethostname(name, 0x80uLL) < 0 )
return 4294967293LL;
result = func1(name, a1, (__int64)&v6);
if ( (int)result >= 0 )
{
v5 = bind(v3, &v6, 0x10u);
if ( v5 == 98 )
{
result = 4294967294LL;
}
else if ( v5 < 0 )
{
result = 4294967293LL;
}
else
{
*a2 = v3;
result = 0LL;
}
}
return result;
}

original_code:
int set_up_listener(int port, int *listener) {
  int listen_socket;
  char hostname[128];
  struct sockaddr_in address;
  int lookup_result, bind_result;
  memset(&address, 0, sizeof(struct sockaddr_in));
  listen_socket = socket(2, SOCK_STREAM, 6);
  if (listen_socket == -1) return (-3);
  if (gethostname(hostname,sizeof(hostname)) < 0) return (-3);
  lookup_result = build_address(hostname,port,&address);
  if (lookup_result < 0) return lookup_result;
  bind_result = bind(listen_socket,(struct sockaddr *)&address,sizeof(address));
  if (bind_result == 98) return (-2);
  if (bind_result < 0) return (-3);
  *listener = listen_socket;
  return 0;
}

canonical_original_code:
int set_up_listener(int port, int *listener) {
  int listen_socket;
  char hostname[128];
  struct sockaddr_in address;
  int lookup_result; int bind_result;
  memset(&address, 0, sizeof(struct sockaddr_in));
  listen_socket = socket(2, SOCK_STREAM, 6);
  if (listen_socket == -1) return (-3);
  if (gethostname(hostname,sizeof(hostname)) < 0) return (-3);
  lookup_result = build_address(hostname,port,&address);
  if (lookup_result < 0) return lookup_result;
  bind_result = bind(listen_socket,(struct sockaddr *)&address,sizeof(address));
  if (bind_result == 98) return (-2);
  if (bind_result < 0) return (-3);
  *listener = listen_socket;
  return 0;
}

variable_types:
listener
int *

variable_types:
hostname
char [128]

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall wait_for_connection(int fd, int *a2)
{
int v2; // eax

if ( listen(fd, 5) < 0 )
return 4294967293LL;
v2 = accept(fd, 0LL, 0LL);
if ( v2 < 0 )
return 4294967293LL;
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int *a2)
{
int v2; // eax

if ( listen(fd, 5) < 0 )
return 4294967293LL;
v2 = accept(fd, 0LL, 0LL);
if ( v2 < 0 )
return 4294967293LL;
*a2 = v2;
return 0LL;
}

original_code:
int wait_for_connection(int listen_socket, int *connection) {
  int bulletin_socket;
  if (listen(listen_socket, 5) < 0) return (-3);
  bulletin_socket = accept(listen_socket,((void *)0),((void *)0));
  if (bulletin_socket < 0) return (-3);
  *connection = bulletin_socket;
  return 0;
}

variable_types:
connection
int *


decompiled_code:
__int64 __fastcall make_connection_with(const char *a1, __int16 a2, int *a3)
{
int v4; // eax
int v5; // ebx
__int64 result; // rax
struct sockaddr v7[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
if ( v4 == -1 )
return 4294967291LL;
v5 = v4;
result = build_address(a1, a2, (__int64)v7);
if ( (int)result >= 0 )
{
if ( connect(v5, v7, 0x10u) < 0 )
{
result = 4294967293LL;
}
else
{
*a3 = v5;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int16 a2, int *a3)
{
int v4; // eax
int v5; // ebx
__int64 result; // rax
struct sockaddr v7[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
if ( v4 == -1 )
return 4294967291LL;
v5 = v4;
result = func1(a1, a2, (__int64)v7);
if ( (int)result >= 0 )
{
if ( connect(v5, v7, 0x10u) < 0 )
{
result = 4294967293LL;
}
else
{
*a3 = v5;
result = 0LL;
}
}
return result;
}

original_code:
int make_connection_with(char *hostname, int port, int *connection) {
  int bulletin_socket;
  struct sockaddr_in address;
  int lookup_result, connect_result;
  bulletin_socket = socket(2, SOCK_STREAM, 6);
  if (bulletin_socket == -1) return (-5);
  lookup_result = build_address(hostname,port,&address);
  if (lookup_result < 0) return lookup_result;
  connect_result = connect(bulletin_socket,(struct sockaddr *)&address,sizeof(address));
  if (connect_result < 0) return (-3);
  *connection = bulletin_socket;
  return 0;
}

canonical_original_code:
int make_connection_with(char *hostname, int port, int *connection) {
  int bulletin_socket;
  struct sockaddr_in address;
  int lookup_result; int connect_result;
  bulletin_socket = socket(2, SOCK_STREAM, 6);
  if (bulletin_socket == -1) return (-5);
  lookup_result = build_address(hostname,port,&address);
  if (lookup_result < 0) return lookup_result;
  connect_result = connect(bulletin_socket,(struct sockaddr *)&address,sizeof(address));
  if (connect_result < 0) return (-3);
  *connection = bulletin_socket;
  return 0;
}


decompiled_code:
__int64 __fastcall get_ip(int a1, char *a2)
{
unsigned int v2; // ebx
int *v4; // rax
int *v5; // rax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( getpeername(a1, &addr, &len) < 0 )
{
v4 = _errno_location();
fprintf(stderr, "get peer name failed %d\n", (unsigned int)*v4);
v2 = -1;
}
else
{
v2 = (unsigned int)inet_ntop(2, &addr.sa_data[2], a2, 0x10u);
if ( v2 )
{
v2 = 0;
}
else
{
v5 = _errno_location();
fprintf(stderr, "inet_ntop failed %d\n", (unsigned int)*v5);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, char *a2)
{
unsigned int v2; // ebx
int *v4; // rax
int *v5; // rax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( getpeername(a1, &addr, &len) < 0 )
{
v4 = _errno_location();
fprintf(stderr, "get peer name failed %d\n", (unsigned int)*v4);
v2 = -1;
}
else
{
v2 = (unsigned int)inet_ntop(2, &addr.sa_data[2], a2, 0x10u);
if ( v2 )
{
v2 = 0;
}
else
{
v5 = _errno_location();
fprintf(stderr, "inet_ntop failed %d\n", (unsigned int)*v5);
}
}
return v2;
}

original_code:
int get_ip(int connection, char *buffer) {
    struct sockaddr_in their_address;
    socklen_t length;
    int err;
    length = sizeof their_address;
    memset(&their_address, 0, sizeof(struct sockaddr_in));
    err = getpeername(connection, (struct sockaddr *)&their_address, &length);
    if(err < 0) {
      fprintf(stderr, "get peer name failed %d\n", (*__errno_location ()));
      return (-1);
    }
    if(!inet_ntop(2, &(their_address.sin_addr), buffer, 16))
      fprintf(stderr, "inet_ntop failed %d\n", (*__errno_location ()));
    return 0;
}

canonical_original_code:
int get_ip(int connection, char *buffer) {
    struct sockaddr_in their_address;
    unsigned int length;
    int err;
    length = sizeof their_address;
    memset(&their_address, 0, sizeof(struct sockaddr_in));
    err = getpeername(connection, (struct sockaddr *)&their_address, &length);
    if(err < 0) {
      fprintf(stderr, "get peer name failed %d\n", (*__errno_location ()));
      return (-1);
    }
    if(!inet_ntop(2, &(their_address.sin_addr), buffer, 16))
      fprintf(stderr, "inet_ntop failed %d\n", (*__errno_location ()));
    return 0;
}

variable_types: connection int

variable_types:
buffer
char *

variable_types:
length
unsigned int

variable_types: err int


decompiled_code:
__int64 __fastcall get_my_ip(char *buf)
{
struct hostent *v1; // rax
char *v2; // rsi
__int64 result; // rax
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

gethostname(v4, 0x100uLL);
v1 = gethostbyname(v4);
if ( v1 && (v2 = *v1->h_addr_list) != 0LL )
{
inet_ntop(2, v2, buf, 0x10u);
result = 0LL;
}
else
{
fprintf(stderr, "gethostbyname did not provide an address for %s \n", v4);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *buf)
{
struct hostent *v1; // rax
char *v2; // rsi
__int64 result; // rax
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

gethostname(v4, 0x100uLL);
v1 = gethostbyname(v4);
if ( v1 && (v2 = *v1->h_addr_list) != 0LL )
{
inet_ntop(2, v2, buf, 0x10u);
result = 0LL;
}
else
{
fprintf(stderr, "gethostbyname did not provide an address for %s \n", v4);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int get_my_ip(char *buffer) {
  struct hostent *h;
  char name[256];
  int i;
  gethostname(name, 256);
  h = gethostbyname(name);
  if(h && h->h_addr_list[0]) {
    inet_ntop(2, h->h_addr_list[0], buffer, 16);
  } else {
    fprintf(stderr, "gethostbyname did not provide an address for %s \n", name);
    return (-1);
  }
  return 0;
}

variable_types:
name
char [256]

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


decompiled_code:
__int64 __fastcall safe_send(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned int v5; // er14
int *v6; // rax
unsigned int *v7; // r13
unsigned __int64 v8; // rsi
int v9; // eax
__int64 result; // rax
unsigned int v11; // [rsp+4h] [rbp-34h] BYREF
unsigned __int64 buf[6]; // [rsp+8h] [rbp-30h] BYREF

buf[0] = (unsigned int)_bswap_32(a3);
v5 = send(fd, buf, 8uLL, 0);
v11 = v5;
v6 = _errno_location();
*v6 = 0;
if ( v5 <= 7 )
{
fprintf(stderr, "Error sending size of transmission. Only %d bytes sent. errno: %d\n", v5, 0LL);
result = 4294967291LL;
}
else
{
v7 = (unsigned int *)v6;
v11 = -1;
recv(fd, &v11, 4uLL, 0);
if ( v11 )
{
fprintf(stderr, "Error in communication. receiver was not ready. err was: %d\n", v11);
result = 4294967290LL;
}
else
{
buf[0] = 0LL;
if ( a3 )
{
v8 = 0LL;
while ( 1 )
{
v9 = send(fd, (const void *)(a2 + v8), a3 - v8, 0);
v11 = v9;
if ( v9 < 0 )
break;
v8 = buf[0] + v9;
buf[0] = v8;
if ( v8 >= a3 )
goto LABEL_7;
}
fprintf(stderr, "Error transmitting data. Only %lu bytes sent. errno: %d\n", buf[0], *v7);
result = 4294967291LL;
}
else
{
LODWORD(v8) = 0;
LABEL_7:
result = (unsigned int)v8;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned int v5; // er14
int *v6; // rax
unsigned int *v7; // r13
unsigned __int64 v8; // rsi
int v9; // eax
__int64 result; // rax
unsigned int v11; // [rsp+4h] [rbp-34h] BYREF
unsigned __int64 buf[6]; // [rsp+8h] [rbp-30h] BYREF

buf[0] = (unsigned int)func0(a3);
v5 = send(fd, buf, 8uLL, 0);
v11 = v5;
v6 = _errno_location();
*v6 = 0;
if ( v5 <= 7 )
{
fprintf(stderr, "Error sending size of transmission. Only %d bytes sent. errno: %d\n", v5, 0LL);
result = 4294967291LL;
}
else
{
v7 = (unsigned int *)v6;
v11 = -1;
recv(fd, &v11, 4uLL, 0);
if ( v11 )
{
fprintf(stderr, "Error in communication. receiver was not ready. err was: %d\n", v11);
result = 4294967290LL;
}
else
{
buf[0] = 0LL;
if ( a3 )
{
v8 = 0LL;
while ( 1 )
{
v9 = send(fd, (const void *)(a2 + v8), a3 - v8, 0);
v11 = v9;
if ( v9 < 0 )
break;
v8 = buf[0] + v9;
buf[0] = v8;
if ( v8 >= a3 )
goto LABEL_7;
}
fprintf(stderr, "Error transmitting data. Only %lu bytes sent. errno: %d\n", buf[0], *v7);
result = 4294967291LL;
}
else
{
LODWORD(v8) = 0;
LABEL_7:
result = (unsigned int)v8;
}
}
}
return result;
}

original_code:
int safe_send(int connection, void *data, size_t length) {
  char *bits;
  size_t transmitted;
  int err;
  bits = data;
  err = 0;
  transmitted = htonl(length);
  err = send(connection, &transmitted, sizeof(transmitted), 0);
  (*__errno_location ()) = 0;
  if(err < sizeof(transmitted)) {
    fprintf(stderr, "Error sending size of transmission.  Only %d bytes sent.  errno: %d\n" , err, (*__errno_location ()));
    return (-5);
  }
  err = (-1);
  recv(connection, &err, sizeof(err), 0);
  if(err) {
    fprintf(stderr, "Error in communication.  receiver was not ready. err was: %d\n", err);
    return (-6);
  }
  err = 0;
  transmitted = 0;
  while(transmitted < length) {
    err = send(connection, (void *)(data+transmitted), (length-transmitted), 0);
    if(err < 0) {
      fprintf(stderr, "Error transmitting data.  Only %lu bytes sent. errno: %d\n", transmitted, (*__errno_location ()));
      return (-5);
    }
    transmitted += err;
  }
  return transmitted;
}

canonical_original_code:
int safe_send(int connection, void *data, unsigned long length) {
  char *bits;
  unsigned long transmitted;
  int err;
  bits = data;
  err = 0;
  transmitted = htonl(length);
  err = send(connection, &transmitted, sizeof(transmitted), 0);
  (*__errno_location ()) = 0;
  if(err < sizeof(transmitted)) {
    fprintf(stderr, "Error sending size of transmission.  Only %d bytes sent.  errno: %d\n" , err, (*__errno_location ()));
    return (-5);
  }
  err = (-1);
  recv(connection, &err, sizeof(err), 0);
  if(err) {
    fprintf(stderr, "Error in communication.  receiver was not ready. err was: %d\n", err);
    return (-6);
  }
  err = 0;
  transmitted = 0;
  while(transmitted < length) {
    err = send(connection, (void *)(data+transmitted), (length-transmitted), 0);
    if(err < 0) {
      fprintf(stderr, "Error transmitting data.  Only %lu bytes sent. errno: %d\n", transmitted, (*__errno_location ()));
      return (-5);
    }
    transmitted += err;
  }
  return transmitted;
}

variable_types:
data
void *

variable_types:
length
unsigned long

variable_types:
bits
char *

variable_types:
transmitted
unsigned long


decompiled_code:
unsigned __int64 __fastcall safe_recv(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned __int64 v6; // rbx
unsigned __int64 result; // rax
int *v8; // rax
unsigned int v9; // [rsp+4h] [rbp-34h] BYREF
unsigned __int64 buf[6]; // [rsp+8h] [rbp-30h] BYREF

buf[0] = 0LL;
v4 = recv(fd, buf, 8uLL, 0);
v9 = v4;
v5 = _bswap_32(buf[0]);
buf[0] = v5;
if ( v4 <= 7 )
{
v8 = _errno_location();
fprintf(
stderr,
"Error receiving size of transmission. Only %d bytes received. errno: %d\n",
v4,
(unsigned int)*v8);
result = 4294967291LL;
}
else if ( v5 > a3 )
{
fprintf(stderr, "Size of data to be sent was to too large. max: %lu, recv: %lu\n", a3, v5);
v9 = 0;
send(fd, &v9, 4uLL, 0);
result = 4294967290LL;
}
else
{
v9 = 0;
send(fd, &v9, 4uLL, 0);
v6 = buf[0];
buf[0] = 0LL;
if ( v6 )
{
for ( result = 0LL; result < v6; buf[0] = result )
{
v9 = recv(fd, (void *)(a2 + result), v6 - result, 0);
result = buf[0] + v9;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned __int64 v6; // rbx
unsigned __int64 result; // rax
int *v8; // rax
unsigned int v9; // [rsp+4h] [rbp-34h] BYREF
unsigned __int64 buf[6]; // [rsp+8h] [rbp-30h] BYREF

buf[0] = 0LL;
v4 = recv(fd, buf, 8uLL, 0);
v9 = v4;
v5 = func0(buf[0]);
buf[0] = v5;
if ( v4 <= 7 )
{
v8 = _errno_location();
fprintf(
stderr,
"Error receiving size of transmission. Only %d bytes received. errno: %d\n",
v4,
(unsigned int)*v8);
result = 4294967291LL;
}
else if ( v5 > a3 )
{
fprintf(stderr, "Size of data to be sent was to too large. max: %lu, recv: %lu\n", a3, v5);
v9 = 0;
send(fd, &v9, 4uLL, 0);
result = 4294967290LL;
}
else
{
v9 = 0;
send(fd, &v9, 4uLL, 0);
v6 = buf[0];
buf[0] = 0LL;
if ( v6 )
{
for ( result = 0LL; result < v6; buf[0] = result )
{
v9 = recv(fd, (void *)(a2 + result), v6 - result, 0);
result = buf[0] + v9;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int safe_recv(int connection, void *data, size_t max) {
  char *bits;
  size_t received;
  uint32_t err;
  bits = data;
  err = 0;
  received = 0;
  err = recv(connection, &received, sizeof(received), 0);
  received = ntohl(received);
  if(err < sizeof(received)) {
    fprintf(stderr, "Error receiving size of transmission.  Only %d bytes received.  errno: %d\n" , err, (*__errno_location ()));
    return (-5);
  }
  if(received > max) {
    fprintf(stderr, "Size of data to be sent was to too large. max: %lu, recv: %lu\n", max, received);
    err = 0;
    send(connection, &err, sizeof(err), 0);
    return (-6);
  }
  err = 0;
  send(connection, &err, sizeof(err), 0);
  max = received;
  received = 0;
  while(received < max) {
    err = recv(connection, (void *)(data + received), (max-received), 0);
    if(err < 0) {
      fprintf(stderr, "Error received data.  Only %lu bytes received. errno: %d\n", received, (*__errno_location ()));
      return (-5);
    }
    received += err;
  }
  return received;
}

canonical_original_code:
int safe_recv(int connection, void *data, unsigned long max) {
  char *bits;
  unsigned long received;
  unsigned int err;
  bits = data;
  err = 0;
  received = 0;
  err = recv(connection, &received, sizeof(received), 0);
  received = ntohl(received);
  if(err < sizeof(received)) {
    fprintf(stderr, "Error receiving size of transmission.  Only %d bytes received.  errno: %d\n" , err, (*__errno_location ()));
    return (-5);
  }
  if(received > max) {
    fprintf(stderr, "Size of data to be sent was to too large. max: %lu, recv: %lu\n", max, received);
    err = 0;
    send(connection, &err, sizeof(err), 0);
    return (-6);
  }
  err = 0;
  send(connection, &err, sizeof(err), 0);
  max = received;
  received = 0;
  while(received < max) {
    err = recv(connection, (void *)(data + received), (max-received), 0);
    if(err < 0) {
      fprintf(stderr, "Error received data.  Only %lu bytes received. errno: %d\n", received, (*__errno_location ()));
      return (-5);
    }
    received += err;
  }
  return received;
}

variable_types:
max
unsigned long

variable_types:
received
unsigned long

variable_types:
err
unsigned int


decompiled_code:
__int64 __fastcall submit_job_to_server(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
int v7; // eax
int v8; // eax
int v10[3]; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v11; // [rsp+18h] [rbp-20h] BYREF
int fd[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v10[0] = a5;
if ( (int)make_connection_with(a1, a2, fd) < 0 )
{
fwrite("Connection to server failed\n", 1uLL, 0x1CuLL, stderr);
exit(-1);
}
v11 = 8;
safe_send((unsigned int)fd[0], &v11, 4LL);
v7 = safe_send((unsigned int)fd[0], a3, 492LL);
if ( v7 < 0 )
fprintf(stderr, "Send job failed, %d\n", (unsigned int)v7);
safe_send((unsigned int)fd[0], v10, 4LL);
v11 = 0;
if ( v10[0] > 0 )
{
v8 = 0;
do
{
if ( (int)safe_send((unsigned int)fd[0], a4 + 56LL * v8 + 8, 8LL) < 0 )
fwrite("Send failed size\n", 1uLL, 0x11uLL, stderr);
if ( (int)safe_send((unsigned int)fd[0], *(_QWORD *)(a4 + 56LL * (int)v11), *(_QWORD *)(a4 + 56LL * (int)v11 + 8)) < 0 )
fwrite("Send failed data\n", 1uLL, 0x11uLL, stderr);
if ( (int)safe_send((unsigned int)fd[0], a4 + 56LL * (int)v11 + 16, 40LL) < 0 )
fwrite("Send failed name\n", 1uLL, 0x11uLL, stderr);
v8 = v11 + 1;
v11 = v8;
}
while ( v8 < v10[0] );
}
safe_recv((unsigned int)fd[0], &v11, 4LL);
close(fd[0]);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
int v7; // eax
int v8; // eax
int v10[3]; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v11; // [rsp+18h] [rbp-20h] BYREF
int fd[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v10[0] = a5;
if ( (int)make_connection_with(a1, a2, fd) < 0 )
{
fwrite("Connection to server failed\n", 1uLL, 0x1CuLL, stderr);
exit(-1);
}
v11 = 8;
safe_send((unsigned int)fd[0], &v11, 4LL);
v7 = safe_send((unsigned int)fd[0], a3, 492LL);
if ( v7 < 0 )
fprintf(stderr, "Send job failed, %d\n", (unsigned int)v7);
safe_send((unsigned int)fd[0], v10, 4LL);
v11 = 0;
if ( v10[0] > 0 )
{
v8 = 0;
do
{
if ( (int)safe_send((unsigned int)fd[0], a4 + 56LL * v8 + 8, 8LL) < 0 )
fwrite("Send failed size\n", 1uLL, 0x11uLL, stderr);
if ( (int)safe_send((unsigned int)fd[0], *(_QWORD *)(a4 + 56LL * (int)v11), *(_QWORD *)(a4 + 56LL * (int)v11 + 8)) < 0 )
fwrite("Send failed data\n", 1uLL, 0x11uLL, stderr);
if ( (int)safe_send((unsigned int)fd[0], a4 + 56LL * (int)v11 + 16, 40LL) < 0 )
fwrite("Send failed name\n", 1uLL, 0x11uLL, stderr);
v8 = v11 + 1;
v11 = v8;
}
while ( v8 < v10[0] );
}
safe_recv((unsigned int)fd[0], &v11, 4LL);
close(fd[0]);
return v11;
}

original_code:
int submit_job_to_server(char *host, int port, job *to_send, data_size *files, int num_files) {
  int connection, i, err;
  char ip[16];
  i = make_connection_with(host, port, &connection);
  if(i < 0) {
    fprintf(stderr, "Connection to server failed\n");
    exit(-1);
  }
  i = 8;
  safe_send(connection, &i, sizeof(int));
  err = safe_send(connection, to_send, sizeof(job));
  if(err < 0) fprintf(stderr, "Send job failed, %d\n", err);
  safe_send(connection, &num_files, sizeof(int));
  for(i = 0; i < num_files; i++) {
    err = safe_send(connection, &(files[i].size), sizeof(size_t));
    if(err < 0) fprintf(stderr, "Send failed size\n");
    err = safe_send(connection, files[i].data, files[i].size);
    if(err < 0) fprintf(stderr, "Send failed data\n");
    err = safe_send(connection, files[i].name, 40*sizeof(char));
    if(err < 0) fprintf(stderr, "Send failed name\n");
  }
  safe_recv(connection, &i, sizeof(int));
  close(connection);
  return i;
}

canonical_original_code:
int submit_job_to_server(char *host, int port, struct _job *to_send, struct _data_size *files, int num_files) {
  int connection; int i; int err;
  char ip[16];
  i = make_connection_with(host, port, &connection);
  if(i < 0) {
    fprintf(stderr, "Connection to server failed\n");
    exit(-1);
  }
  i = 8;
  safe_send(connection, &i, sizeof(int));
  err = safe_send(connection, to_send, sizeof(job));
  if(err < 0) fprintf(stderr, "Send job failed, %d\n", err);
  safe_send(connection, &num_files, sizeof(int));
  for(i = 0; i < num_files; i++) {
    err = safe_send(connection, &(files[i].size), sizeof(unsigned long));
    if(err < 0) fprintf(stderr, "Send failed size\n");
    err = safe_send(connection, files[i].data, files[i].size);
    if(err < 0) fprintf(stderr, "Send failed data\n");
    err = safe_send(connection, files[i].name, 40*sizeof(char));
    if(err < 0) fprintf(stderr, "Send failed name\n");
  }
  safe_recv(connection, &i, sizeof(int));
  close(connection);
  return i;
}

variable_types:
host
char *

variable_types: port int

variable_types: struct _job { unsigned int id; int argc; char name[40]; } *

variable_types: struct _data_size { char *data; unsigned long size; char name[40]; } *

variable_types: i int

variable_types:
ip
char [16]


decompiled_code:
int __fastcall simple_add(__int64 a1, unsigned int a2)
{
int v2; // ebx
void *v3; // rax
__int64 v4; // r14
__int64 v5; // r13
unsigned int v6; // er12
int v7; // ebx
char *v8; // rbp
int i; // ebx
int result; // eax
int j; // ebx
unsigned int v12; // eax
char v13[4]; // [rsp+10h] [rbp-368h] BYREF
int v14; // [rsp+14h] [rbp-364h] BYREF
char v15; // [rsp+43h] [rbp-335h]
char s[40]; // [rsp+44h] [rbp-334h] BYREF
char v17[404]; // [rsp+6Ch] [rbp-30Ch] BYREF
char src[48]; // [rsp+200h] [rbp-178h] BYREF
char v19[264]; // [rsp+230h] [rbp-148h] BYREF
int v20; // [rsp+338h] [rbp-40h] BYREF
int v21[15]; // [rsp+33Ch] [rbp-3Ch] BYREF

printf("Enter the name of your job");
putchar(10);
fgets(s, 40, stdin);
*(&v15 + strlen(s)) = 0;
puts("How many files?");
fgets(v19, 256, stdin);
_isoc99_sscanf(v19, "%d", v21);
v2 = v21[0];
v3 = malloc(56LL * v21[0]);
v4 = (__int64)v3;
if ( v2 > 0 )
{
v5 = (__int64)v3;
v6 = 1;
do
{
v7 = v6;
do
{
printf("Enter the name of file %d\n", v6);
fgets(src, 40, stdin);
v17[strlen(src) + 403] = 0;
}
while ( (unsigned int)get_file_into_memory(src, v5) );
++v6;
v5 += 56LL;
}
while ( v7 < v21[0] );
}
puts("Enter the number of arguments: ");
fgets(v19, 256, stdin);
_isoc99_sscanf(v19, "%d", &v14);
if ( v14 > 0 )
{
v8 = v17;
for ( i = 0; i < v14; ++i )
{
printf("Enter the name of argument %d\n", (unsigned int)i);
fgets(v8, 40, stdin);
*((_BYTE *)&v21[10 * i - 180] + strlen(v8) - 1) = 0;
v8 += 40;
}
}
puts("How many times would you like to add the job?");
result = _isoc99_scanf("%d", &v20);
if ( v20 > 0 )
{
for ( j = 0; j < v20; ++j )
{
v12 = submit_job_to_server(a1, a2, (__int64)v13, v4, v21[0]);
result = printf("Your job id is %d\n", v12);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, unsigned int a2)
{
int v2; // ebx
void *v3; // rax
__int64 v4; // r14
__int64 v5; // r13
unsigned int v6; // er12
int v7; // ebx
char *v8; // rbp
int i; // ebx
int result; // eax
int j; // ebx
unsigned int v12; // eax
char v13[4]; // [rsp+10h] [rbp-368h] BYREF
int v14; // [rsp+14h] [rbp-364h] BYREF
char v15; // [rsp+43h] [rbp-335h]
char s[40]; // [rsp+44h] [rbp-334h] BYREF
char v17[404]; // [rsp+6Ch] [rbp-30Ch] BYREF
char src[48]; // [rsp+200h] [rbp-178h] BYREF
char v19[264]; // [rsp+230h] [rbp-148h] BYREF
int v20; // [rsp+338h] [rbp-40h] BYREF
int v21[15]; // [rsp+33Ch] [rbp-3Ch] BYREF

printf("Enter the name of your job");
putchar(10);
fgets(s, 40, stdin);
*(&v15 + strlen(s)) = 0;
puts("How many files?");
fgets(v19, 256, stdin);
_isoc99_sscanf(v19, "%d", v21);
v2 = v21[0];
v3 = malloc(56LL * v21[0]);
v4 = (__int64)v3;
if ( v2 > 0 )
{
v5 = (__int64)v3;
v6 = 1;
do
{
v7 = v6;
do
{
printf("Enter the name of file %d\n", v6);
fgets(src, 40, stdin);
v17[strlen(src) + 403] = 0;
}
while ( (unsigned int)func1(src, v5) );
++v6;
v5 += 56LL;
}
while ( v7 < v21[0] );
}
puts("Enter the number of arguments: ");
fgets(v19, 256, stdin);
_isoc99_sscanf(v19, "%d", &v14);
if ( v14 > 0 )
{
v8 = v17;
for ( i = 0; i < v14; ++i )
{
printf("Enter the name of argument %d\n", (unsigned int)i);
fgets(v8, 40, stdin);
*((_BYTE *)&v21[10 * i - 180] + strlen(v8) - 1) = 0;
v8 += 40;
}
}
puts("How many times would you like to add the job?");
result = _isoc99_scanf("%d", &v20);
if ( v20 > 0 )
{
for ( j = 0; j < v20; ++j )
{
v12 = func0(a1, a2, (__int64)v13, v4, v21[0]);
result = printf("Your job id is %d\n", v12);
}
}
return result;
}

original_code:
void simple_add(char *host, int port){
  int num_files, i, num_times_to_add, job_num;
  char buffer[256], filename[40];
  job ajob;
  data_size *data;
  printf("Enter the name of your job"); printf("\n");
  fgets(ajob.name, 40, stdin);
  ajob.name[strlen(ajob.name)-1] = '\0';
  printf("How many files?\n");
  fgets(buffer, 256, stdin);
  sscanf(buffer, "%d", &num_files);
  data = malloc(sizeof(data_size)*num_files);
  for(i = 0; i < num_files; i++) {
    do {
      printf("Enter the name of file %d\n", i + 1);
      fgets(filename, 40, stdin);
      filename[strlen(filename)-1] = '\0';
    } while(get_file_into_memory(filename, &data[i]));
  }
  printf("Enter the number of arguments: \n");
  fgets(buffer, 256, stdin);
  sscanf(buffer, "%d", &(ajob.argc));
  for(i = 0; i < ajob.argc; i++) {
    printf("Enter the name of argument %d\n", i);
    fgets(ajob.argv[i], 40, stdin);
    ajob.argv[i][strlen(ajob.argv[i])-1] = '\0';
  }
  printf("How many times would you like to add the job?\n");
  scanf("%d", &num_times_to_add);
  for(i = 0; i < num_times_to_add; i++) {
    job_num = submit_job_to_server(host, port, &ajob, data, num_files);
    printf("Your job id is %d\n", job_num);
  }
}

canonical_original_code:
void simple_add(char *host, int port){
  int num_files; int i; int num_times_to_add; int job_num;
  char buffer[256]; char filename[40];
  struct _job ajob;
  struct _data_size *data;
  printf("Enter the name of your job"); printf("\n");
  fgets(ajob.name, 40, stdin);
  ajob.name[strlen(ajob.name)-1] = '\0';
  printf("How many files?\n");
  fgets(buffer, 256, stdin);
  sscanf(buffer, "%d", &num_files);
  data = malloc(sizeof(data_size)*num_files);
  for(i = 0; i < num_files; i++) {
    do {
      printf("Enter the name of file %d\n", i + 1);
      fgets(filename, 40, stdin);
      filename[strlen(filename)-1] = '\0';
    } while(get_file_into_memory(filename, &data[i]));
  }
  printf("Enter the number of arguments: \n");
  fgets(buffer, 256, stdin);
  sscanf(buffer, "%d", &(ajob.argc));
  for(i = 0; i < ajob.argc; i++) {
    printf("Enter the name of argument %d\n", i);
    fgets(ajob.argv[i], 40, stdin);
    ajob.argv[i][strlen(ajob.argv[i])-1] = '\0';
  }
  printf("How many times would you like to add the job?\n");
  scanf("%d", &num_times_to_add);
  for(i = 0; i < num_times_to_add; i++) {
    job_num = submit_job_to_server(host, port, &ajob, data, num_files);
    printf("Your job id is %d\n", job_num);
  }
}

variable_types:
buffer
char [256]

variable_types:
filename
char [40]

variable_types: struct _job { unsigned int id; int argc; char name[40]; }

user_defined_types: struct _data_size { char *data; unsigned long size; char name[40]; }


lowercase

decompiled_code:
void __fastcall lowercase(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func3(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void lowercase(char *str) {
  int i=0;
     while(str[i]) {
       str[i] = (char)tolower(str[i]);
       i++;
     }
}

canonical_original_code:
void lowercase(char *str) {
  int i = 0;
     while(str[i]) {
       str[i] = (char)tolower(str[i]);
       i++;
     }
}

variable_types:
str
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax

if ( argc > 2 )
{
v4 = atoi(argv[2]);
simple_add((__int64)argv[1], v4);
}
return 0;
}

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

if ( argc > 2 )
{
v4 = atoi(argv[2]);
func2((__int64)argv[1], v4);
}
return 0;
}

original_code:
int main(int argc, char **argv) {
  if(argc > 2) {
    simple_add(argv[1], atoi(argv[2]));
  }
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall conflicting_writes(void *a1)
{
int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (int)make_connection_with((char *)a1 + 20, *((unsigned int *)a1 + 3), v3) < 0 )
{
fwrite("Connection failure.\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
printf("Made connection in second thread, file descriptor is %d\n", v3[0]);
v2 = 0;
safe_send(v3[0], &v2, 4LL);
v2 = 3000;
return safe_send(v3[0], &v2, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (int)make_connection_with((char *)a1 + 20, *((unsigned int *)a1 + 3), v3) < 0 )
{
fwrite("Connection failure.\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
printf("Made connection in second thread, file descriptor is %d\n", v3[0]);
v2 = 0;
safe_send(v3[0], &v2, 4LL);
v2 = 3000;
return safe_send(v3[0], &v2, 4LL);
}

original_code:
void conflicting_writes(host_port *host) {
  int connection, err;
  err = make_connection_with(host->ip, host->port, &connection);
  if(err < 0) {
    fprintf(stderr, "Connection failure.\n");
    exit(-1);
  }
  printf("Made connection in second thread, file descriptor is %d\n", connection);
  err = 0;
  safe_send(connection, &err, sizeof(int));
  err = 3000;
  safe_send(connection, &err, sizeof(int));
}

canonical_original_code:
void conflicting_writes(struct _host_port *host) {
  int connection; int err;
  err = make_connection_with(host->ip, host->port, &connection);
  if(err < 0) {
    fprintf(stderr, "Connection failure.\n");
    exit(-1);
  }
  printf("Made connection in second thread, file descriptor is %d\n", connection);
  err = 0;
  safe_send(connection, &err, sizeof(int));
  err = 3000;
  safe_send(connection, &err, sizeof(int));
}

variable_types: struct _host_port { unsigned int location; char ip[16]; } *

variable_types: connection int

variable_types: err int


decompiled_code:
int __fastcall receive_int(void *a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
safe_recv(*(unsigned int *)a1, v2, 4LL);
return printf("Received %d\n", v2[0]);
}

canonical_decompiled_code:
int __fastcall func1(void *a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
safe_recv(*(unsigned int *)a1, v2, 4LL);
return printf("Received %d\n", v2[0]);
}

original_code:
void receive_int(int *connection) {
  int incoming = 0;
  safe_recv(*connection, &incoming, sizeof(int));
  printf("Received %d\n", incoming);
}

variable_types:
connection
int *

variable_types: incoming int


decompiled_code:
void __fastcall __noreturn listen_for_connection(void *a1)
{
unsigned int v1; // [rsp+Ch] [rbp-1Ch] BYREF
int v2; // [rsp+10h] [rbp-18h] BYREF
unsigned int arg; // [rsp+14h] [rbp-14h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

set_up_listener(*((unsigned int *)a1 + 3), &v1);
v2 = -1;
while ( 1 )
{
do
v2 = wait_for_connection(v1, &arg);
while ( v2 < 0 );
v2 = 0;
safe_recv(arg, &v2, 4LL);
if ( v2 )
pthread_create(newthread, 0LL, (void *(*)(void *))receive_int, &arg);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
unsigned int v1; // [rsp+Ch] [rbp-1Ch] BYREF
int v2; // [rsp+10h] [rbp-18h] BYREF
unsigned int arg; // [rsp+14h] [rbp-14h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

set_up_listener(*((unsigned int *)a1 + 3), &v1);
v2 = -1;
while ( 1 )
{
do
v2 = wait_for_connection(v1, &arg);
while ( v2 < 0 );
v2 = 0;
safe_recv(arg, &v2, 4LL);
if ( v2 )
pthread_create(newthread, 0LL, (void *(*)(void *))receive_int, &arg);
}
}

original_code:
void listen_for_connection(host_port *info) {
  pthread_t thread;
  int connection, connect_result, listener;
  connect_result = set_up_listener(info->port, &listener);
  connect_result = -1;
  while(1) {
    do {
      connect_result = wait_for_connection(listener, &connection);
    } while(connect_result < 0);
    connect_result = 0;
    safe_recv(connection, &connect_result, sizeof(int));
    if(connect_result) {
      pthread_create(&thread, ((void *)0), (void *(*)(void *))receive_int, (void *)&connection);
    }
  }
}

canonical_original_code:
void listen_for_connection(struct _host_port *info) {
  unsigned long thread;
  int connection; int connect_result; int listener;
  connect_result = set_up_listener(info->port, &listener);
  connect_result = -1;
  while(1) {
    do {
      connect_result = wait_for_connection(listener, &connection);
    } while(connect_result < 0);
    connect_result = 0;
    safe_recv(connection, &connect_result, sizeof(int));
    if(connect_result) {
      pthread_create(&thread, ((void *)0), (void *(*)(void *))receive_int, (void *)&connection);
    }
  }
}

variable_types:
thread
unsigned long

variable_types: listener int

user_defined_types: struct _host_port { unsigned int location; char ip[16]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[12]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v5; // [rsp+Ch] [rbp-3Ch]
char dest[28]; // [rsp+14h] [rbp-34h] BYREF
pthread_t newthread; // [rsp+30h] [rbp-18h] BYREF
int v8; // [rsp+38h] [rbp-10h] BYREF
unsigned int v9[3]; // [rsp+3Ch] [rbp-Ch] BYREF

if ( argc > 2 )
{
strcpy(dest, argv[1]);
v5 = atoi(argv[2]);
make_connection_with(dest, v5, v9);
printf("Made connection in main thread, file descriptor is %d", v9[0]);
putchar(10);
v8 = 1;
safe_send(v9[0], &v8, 4LL);
pthread_create(&newthread, 0LL, (void *(*)(void *))conflicting_writes, v4);
}
else
{
v5 = atoi(argv[1]);
pthread_create(&newthread, 0LL, (void *(*)(void *))listen_for_connection, v4);
}
pthread_join(newthread, 0LL);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int connection, err;
  pthread_t thread;
  host_port host;
  struct timespec req;
  if(argc < 3) {
    host.port = atoi(argv[1]);
    pthread_create(&thread, ((void *)0), (void *(*)(void *))listen_for_connection, &host);
    pthread_join(thread, ((void *)0));
  } else {
    strcpy(host.ip, argv[1]);
    host.port = atoi(argv[2]);
    make_connection_with(host.ip, host.port, &connection);
    printf("Made connection in main thread, file descriptor is %d", connection); printf("\n");
    err = 1;
    safe_send(connection, &err, sizeof(int));
    pthread_create(&thread, ((void *)0), (void *(*)(void *))conflicting_writes, &host);
    req.tv_sec = 2;
    pthread_join(thread, ((void *)0));
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  int connection; int err;
  unsigned long thread;
  struct _host_port host;
  struct timespec req;
  if(argc < 3) {
    host.port = atoi(argv[1]);
    pthread_create(&thread, ((void *)0), (void *(*)(void *))listen_for_connection, &host);
    pthread_join(thread, ((void *)0));
  } else {
    strcpy(host.ip, argv[1]);
    host.port = atoi(argv[2]);
    make_connection_with(host.ip, host.port, &connection);
    printf("Made connection in main thread, file descriptor is %d", connection); printf("\n");
    err = 1;
    safe_send(connection, &err, sizeof(int));
    pthread_create(&thread, ((void *)0), (void *(*)(void *))conflicting_writes, &host);
    req.tv_sec = 2;
    pthread_join(thread, ((void *)0));
  }
}

variable_types: struct _host_port { unsigned int location; char ip[16]; }

variable_types: struct timespec { long tv_sec; long tv_nsec; }


runner

variable_types: struct _job { unsigned int id; int argc; char name[40]; } *

variable_types: status int

variable_types: i int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


usage

repo: IxLabs/mptp

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s [test_no]\n\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Usage: %s [test_no]\n\n", a1);
exit(1);
}

original_code:
static void usage(const char *argv0)
{
 fprintf(stderr, "Usage: %s [test_no]\n\n", argv0);
 exit(1);
}

canonical_original_code:
static void usage(char *argv0)
{
 fprintf(stderr, "Usage: %s [test_no]\n\n", argv0);
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void **v5; // rbx

if ( argc == 1 )
{
v5 = &funcs_4A;
do
((void (__fastcall *)(int, const char **, const char **))*v5++)(argc, argv, envp);
while ( v5 != (void **)&unk_138 );
}
else
{
if ( argc != 2 )
usage(*argv);
v3 = atoi(argv[1]);
if ( v3 - 1 > 9 )
{
fprintf(stderr, "Error: test index %d is out of bounds\n", v3);
exit(1);
}
((void (*)(void))*(&funcs_4A + (int)v3 - 1))();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void **v5; // rbx

if ( argc == 1 )
{
v5 = &funcs_4A;
do
((void (__fastcall *)(int, const char **, const char **))*v5++)(argc, argv, envp);
while ( v5 != (void **)&unk_138 );
}
else
{
if ( argc != 2 )
func0(*argv);
v3 = atoi(argv[1]);
if ( v3 - 1 > 9 )
{
fprintf(stderr, "Error: test index %d is out of bounds\n", v3);
exit(1);
}
((void (*)(void))*(&funcs_4A + (int)v3 - 1))();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int test_idx;
 if (argc == 1) {
  int i;
  for (i = 1; i < sizeof(test_fun_array)/sizeof(test_fun_array[0]); i++)
   test_fun_array[i]();
  return 0;
 }
 if (argc != 2)
  usage(argv[0]);
 test_idx = atoi(argv[1]);
 if (test_idx < 1 || test_idx >= sizeof(test_fun_array)/sizeof(test_fun_array[0])) {
  fprintf(stderr, "Error: test index %d is out of bounds\n", test_idx);
  exit(1);
 }
 test_fun_array[test_idx]();
 return 0;
}


decompiled_code:
__pid_t __fastcall run_as_child_process(void (*a1)(void))
{
__pid_t v1; // eax
__pid_t result; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = fork();
if ( v1 == -1 )
{
fprintf(stderr, "(%s, %d): ", "test_common.c", 28LL);
perror("fork");
exit(1);
}
if ( !v1 )
{
a1();
exit(0);
}
result = waitpid(v1, stat_loc, 0);
if ( result < 0 )
{
fprintf(stderr, "(%s, %d): ", "test_common.c", 43LL);
perror("waitpid");
exit(1);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func0(void (*a1)(void))
{
__pid_t v1; // eax
__pid_t result; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = fork();
if ( v1 == -1 )
{
fprintf(stderr, "(%s, %d): ", "test_common.c", 28LL);
perror("fork");
exit(1);
}
if ( !v1 )
{
a1();
exit(0);
}
result = waitpid(v1, stat_loc, 0);
if ( result < 0 )
{
fprintf(stderr, "(%s, %d): ", "test_common.c", 43LL);
perror("waitpid");
exit(1);
}
return result;
}

original_code:
void run_as_child_process(test_fn f)
{
 pid_t pid;
 int status;
 int rc;
 pid = fork();
 switch (pid) {
 case -1:
  do { fprintf(stderr, "(%s, %d): ", "test_common.c", 28); perror("fork"); } while (0);
  exit(1);
 case 0:
  f();
  exit(0);
  break;
 default:
  break;
 }
 rc = waitpid(pid, &status, 0);
 do { if (rc < 0) { do { fprintf(stderr, "(%s, %d): ", "test_common.c", 43); perror("waitpid"); } while (0); exit(1); } } while(0);
}

canonical_original_code:
void run_as_child_process(void (*f)())
{
 int pid;
 int status;
 int rc;
 pid = fork();
 switch (pid) {
 case -1:
  do { fprintf(stderr, "(%s, %d): ", "test_common.c", 28); perror("fork"); } while (0);
  exit(1);
 case 0:
  f();
  exit(0);
  break;
 default:
  break;
 }
 rc = waitpid(pid, &status, 0);
 do { if (rc < 0) { do { fprintf(stderr, "(%s, %d): ", "test_common.c", 43); perror("waitpid"); } while (0); exit(1); } } while(0);
}

variable_types:
f
void (*)()

variable_types: pid int

variable_types: rc int


decompiled_code:
int getsockopt_dummy()
{
__int64 v0; // rbx

printf("%s", "getsockopt_dummy");
fflush(stdout);
v0 = 44LL;
do
{
putchar(46);
--v0;
}
while ( v0 );
puts("passed");
return fflush(stdout);
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rbx

printf("%s", "getsockopt_dummy");
fflush(stdout);
v0 = 44LL;
do
{
putchar(46);
--v0;
}
while ( v0 );
puts("passed");
return fflush(stdout);
}

original_code:
static void getsockopt_dummy(void)
{
 do { size_t i; int t = (1 == 1); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void getsockopt_dummy()
{
 do { unsigned long i; int t = (1 == 1); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

variable_types:
i
unsigned long

variable_types: t int


decompiled_code:
int getsockopt_test_suite()
{
printf("\n==== Starting %s ====\n", "getsockopt_test_suite");
return getsockopt_dummy();
}

canonical_decompiled_code:
int func1()
{
printf("\n==== Starting %s ====\n", "getsockopt_test_suite");
return func0();
}

original_code:
void getsockopt_test_suite(void)
{
 do { printf("\n==== Starting %s ====\n", __FUNCTION__); } while (0);
 getsockopt_dummy();
}

canonical_original_code:
void getsockopt_test_suite()
{
 do { printf("\n==== Starting %s ====\n", __FUNCTION__); } while (0);
 getsockopt_dummy();
}


decompiled_code:
int bind_dummy()
{
__int64 v0; // rbx

printf("%s", "bind_dummy");
fflush(stdout);
v0 = 50LL;
do
{
putchar(46);
--v0;
}
while ( v0 );
puts("passed");
return fflush(stdout);
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rbx

printf("%s", "bind_dummy");
fflush(stdout);
v0 = 50LL;
do
{
putchar(46);
--v0;
}
while ( v0 );
puts("passed");
return fflush(stdout);
}

original_code:
static void bind_dummy(void)
{
 do { size_t i; int t = (1 == 1); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void bind_dummy()
{
 do { unsigned long i; int t = (1 == 1); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}


decompiled_code:
int bind_invalid_descriptor()
{
_BOOL4 v0; // ebp
__int64 v1; // rbx
struct sockaddr v3; // [rsp+0h] [rbp-38h] BYREF

v0 = 0;
if ( bind(-2, &v3, 0x14u) < 0 )
v0 = *_errno_location() == 9;
printf("%s", "bind_invalid_descriptor");
fflush(stdout);
v1 = 37LL;
do
{
putchar(46);
--v1;
}
while ( v1 );
if ( v0 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

canonical_decompiled_code:
int func1()
{
_BOOL4 v0; // ebp
__int64 v1; // rbx
struct sockaddr v3; // [rsp+0h] [rbp-38h] BYREF

v0 = 0;
if ( bind(-2, &v3, 0x14u) < 0 )
v0 = *_errno_location() == 9;
printf("%s", "bind_invalid_descriptor");
fflush(stdout);
v1 = 37LL;
do
{
putchar(46);
--v1;
}
while ( v1 );
if ( v0 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

original_code:
static void bind_invalid_descriptor(void)
{
 struct sockaddr_sw addr;
 int rc;
 rc = bind(-2, (struct sockaddr *) &addr, sizeof(addr));
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 9); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void bind_invalid_descriptor()
{
 struct sockaddr_sw addr;
 int rc;
 rc = bind(-2, (struct sockaddr *) &addr, sizeof(addr));
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 9); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

variable_types: struct sockaddr_sw { unsigned short sin_family; struct in_addr { unsigned int s_addr; } sin_addr; struct sw_hash { unsigned int h_array[8]; } sw_hash; unsigned char sw_zero[-1]; }

user_defined_types: struct sockaddr_sw { unsigned short sin_family; struct in_addr sin_addr; struct sw_hash sw_hash; unsigned char sw_zero[-1]; }


decompiled_code:
int bind_descriptor_not_a_socket()
{
int v0; // eax
_BOOL4 v1; // ebp
__int64 v2; // rbx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF

v0 = dup(1);
v1 = 0;
if ( bind(v0, &v4, 0x14u) < 0 )
v1 = *_errno_location() == 88;
printf("%s", "bind_descriptor_not_a_socket");
fflush(stdout);
v2 = 32LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

canonical_decompiled_code:
int func2()
{
int v0; // eax
_BOOL4 v1; // ebp
__int64 v2; // rbx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF

v0 = dup(1);
v1 = 0;
if ( bind(v0, &v4, 0x14u) < 0 )
v1 = *_errno_location() == 88;
printf("%s", "bind_descriptor_not_a_socket");
fflush(stdout);
v2 = 32LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

original_code:
static void bind_descriptor_not_a_socket(void)
{
 struct sockaddr_sw addr;
 int fd = dup(1);
 int rc;
 rc = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 88); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void bind_descriptor_not_a_socket()
{
 struct sockaddr_sw addr;
 int fd = dup(1);
 int rc;
 rc = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 88); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

variable_types: fd int

user_defined_types: struct sw_hash { unsigned int h_array[8]; }


decompiled_code:
int bind_invalid_ip_address()
{
int v0; // ebp
_BOOL4 v1; // er12
__int64 v2; // rbx
struct sockaddr buf; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+10h] [rbp-28h]

v0 = socket(2, 2, 137);
*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
v5 = 0;
inet_pton(2, "254.254.254.254", &buf.sa_data[2]);
v1 = 0;
if ( bind(v0, &buf, 0x14u) < 0 )
v1 = *_errno_location() == 99;
printf("%s", "bind_invalid_ip_address");
fflush(stdout);
v2 = 37LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("passed");
else
puts("failed");
fflush(stdout);
return close(v0);
}

canonical_decompiled_code:
int func3()
{
int v0; // ebp
_BOOL4 v1; // er12
__int64 v2; // rbx
struct sockaddr buf; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+10h] [rbp-28h]

v0 = socket(2, 2, 137);
*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
v5 = 0;
inet_pton(2, "254.254.254.254", &buf.sa_data[2]);
v1 = 0;
if ( bind(v0, &buf, 0x14u) < 0 )
v1 = *_errno_location() == 99;
printf("%s", "bind_invalid_ip_address");
fflush(stdout);
v2 = 37LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("passed");
else
puts("failed");
fflush(stdout);
return close(v0);
}

original_code:
static void bind_invalid_ip_address(void)
{
 struct sockaddr_sw addr;
 int sockfd;
 int rc;
 sockfd = socket(2, SOCK_DGRAM, 137);
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2, "254.254.254.254", &addr.sin_addr.s_addr);
 rc = bind(sockfd, (struct sockaddr *) &addr, sizeof(addr));
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 99); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd);
}

canonical_original_code:
static void bind_invalid_ip_address()
{
 struct sockaddr_sw addr;
 int sockfd;
 int rc;
 sockfd = socket(2, SOCK_DGRAM, 137);
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2, "254.254.254.254", &addr.sin_addr.s_addr);
 rc = bind(sockfd, (struct sockaddr *) &addr, sizeof(addr));
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 99); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd);
}

variable_types: sockfd int


decompiled_code:
int bind_ok()
{
int v0; // ebp
int v1; // er12
__int64 v2; // rbx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+10h] [rbp-28h]

v0 = socket(2, 2, 137);
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
v5 = 0;
v1 = bind(v0, &v4, 0x14u);
printf("%s", "bind_ok");
fflush(stdout);
v2 = 53LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("failed");
else
puts("passed");
fflush(stdout);
return close(v0);
}

canonical_decompiled_code:
int func4()
{
int v0; // ebp
int v1; // er12
__int64 v2; // rbx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+10h] [rbp-28h]

v0 = socket(2, 2, 137);
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
v5 = 0;
v1 = bind(v0, &v4, 0x14u);
printf("%s", "bind_ok");
fflush(stdout);
v2 = 53LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("failed");
else
puts("passed");
fflush(stdout);
return close(v0);
}

original_code:
static void bind_ok(void)
{
 struct sockaddr_sw addr;
 int sockfd;
 int rc;
 sockfd = socket(2, SOCK_DGRAM, 137);
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 rc = bind(sockfd, (struct sockaddr *) &addr, sizeof(addr));
 do { size_t i; int t = (rc == 0); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd);
}

canonical_original_code:
static void bind_ok()
{
 struct sockaddr_sw addr;
 int sockfd;
 int rc;
 sockfd = socket(2, SOCK_DGRAM, 137);
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 rc = bind(sockfd, (struct sockaddr *) &addr, sizeof(addr));
 do { unsigned long i; int t = (rc == 0); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd);
}


decompiled_code:
int bind_socket_already_bound()
{
int v0; // ebp
_BOOL4 v1; // er12
__int64 v2; // rbx
struct sockaddr v4; // [rsp+0h] [rbp-58h] BYREF
int v5; // [rsp+10h] [rbp-48h]
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
int v7; // [rsp+30h] [rbp-28h]

v0 = socket(2, 2, 137);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v7 = 0;
bind(v0, &addr, 0x14u);
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 255LL;
v5 = 0;
v1 = 0;
if ( bind(v0, &v4, 0x14u) < 0 )
v1 = *_errno_location() == 22;
printf("%s", "bind_socket_already_bound");
fflush(stdout);
v2 = 35LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("passed");
else
puts("failed");
fflush(stdout);
return close(v0);
}

canonical_decompiled_code:
int func5()
{
int v0; // ebp
_BOOL4 v1; // er12
__int64 v2; // rbx
struct sockaddr v4; // [rsp+0h] [rbp-58h] BYREF
int v5; // [rsp+10h] [rbp-48h]
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
int v7; // [rsp+30h] [rbp-28h]

v0 = socket(2, 2, 137);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v7 = 0;
bind(v0, &addr, 0x14u);
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 255LL;
v5 = 0;
v1 = 0;
if ( bind(v0, &v4, 0x14u) < 0 )
v1 = *_errno_location() == 22;
printf("%s", "bind_socket_already_bound");
fflush(stdout);
v2 = 35LL;
do
{
putchar(46);
--v2;
}
while ( v2 );
if ( v1 )
puts("passed");
else
puts("failed");
fflush(stdout);
return close(v0);
}

original_code:
static void bind_socket_already_bound(void)
{
 struct sockaddr_sw addr1, addr2;
 int sockfd;
 int rc;
 sockfd = socket(2, SOCK_DGRAM, 137);
 memset(&addr1, 0, sizeof(addr1));
 addr1.sin_family = 2;
 addr1.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 rc = bind(sockfd, (struct sockaddr *) &addr1, sizeof(addr1));
 memset(&addr2, 0, sizeof(addr2));
 addr2.sin_family = 2;
 addr2.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 addr2.sw_hash.h_array[0] = 0xFF;
 rc = bind(sockfd, (struct sockaddr *) &addr2, sizeof(addr2));
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 22); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd);
}

canonical_original_code:
static void bind_socket_already_bound()
{
 struct sockaddr_sw addr1; struct sockaddr_sw addr2;
 int sockfd;
 int rc;
 sockfd = socket(2, SOCK_DGRAM, 137);
 memset(&addr1, 0, sizeof(addr1));
 addr1.sin_family = 2;
 addr1.sin_addr.s_addr = ((unsigned int) 0x00000000);
 rc = bind(sockfd, (struct sockaddr *) &addr1, sizeof(addr1));
 memset(&addr2, 0, sizeof(addr2));
 addr2.sin_family = 2;
 addr2.sin_addr.s_addr = ((unsigned int) 0x00000000);
 addr2.sw_hash.h_array[0] = 0xFF;
 rc = bind(sockfd, (struct sockaddr *) &addr2, sizeof(addr2));
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 22); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd);
}


decompiled_code:
int bind_address_in_use()
{
int v0; // er12
int v1; // eax
int v2; // ebp
int v3; // ebx
_BOOL4 v4; // er13
__int64 v5; // rbx
struct sockaddr v7; // [rsp+10h] [rbp-68h] BYREF
int v8; // [rsp+20h] [rbp-58h]
struct sockaddr addr; // [rsp+30h] [rbp-48h] BYREF
int v10; // [rsp+40h] [rbp-38h]

v0 = socket(2, 2, 137);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v10 = 0;
v1 = bind(v0, &addr, 0x14u);
dprintf((int)"after first bind rc = %d\n", (const char *)v1);
v2 = socket(2, 2, 137);
*(_QWORD *)&v7.sa_family = 2LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
v8 = 0;
v3 = bind(v2, &v7, 0x14u);
dprintf((int)"after second bind rc = %d\n", (const char *)v3);
v4 = 0;
if ( v3 < 0 )
v4 = *_errno_location() == 98;
printf("%s", "bind_address_in_use");
fflush(stdout);
v5 = 41LL;
do
{
putchar(46);
--v5;
}
while ( v5 );
if ( v4 )
puts("passed");
else
puts("failed");
fflush(stdout);
close(v0);
return close(v2);
}

canonical_decompiled_code:
int func6()
{
int v0; // er12
int v1; // eax
int v2; // ebp
int v3; // ebx
_BOOL4 v4; // er13
__int64 v5; // rbx
struct sockaddr v7; // [rsp+10h] [rbp-68h] BYREF
int v8; // [rsp+20h] [rbp-58h]
struct sockaddr addr; // [rsp+30h] [rbp-48h] BYREF
int v10; // [rsp+40h] [rbp-38h]

v0 = socket(2, 2, 137);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v10 = 0;
v1 = bind(v0, &addr, 0x14u);
dprintf((int)"after first bind rc = %d\n", (const char *)v1);
v2 = socket(2, 2, 137);
*(_QWORD *)&v7.sa_family = 2LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
v8 = 0;
v3 = bind(v2, &v7, 0x14u);
dprintf((int)"after second bind rc = %d\n", (const char *)v3);
v4 = 0;
if ( v3 < 0 )
v4 = *_errno_location() == 98;
printf("%s", "bind_address_in_use");
fflush(stdout);
v5 = 41LL;
do
{
putchar(46);
--v5;
}
while ( v5 );
if ( v4 )
puts("passed");
else
puts("failed");
fflush(stdout);
close(v0);
return close(v2);
}

original_code:
static void bind_address_in_use(void)
{
 struct sockaddr_sw addr1, addr2;
 int sockfd1, sockfd2;
 int rc;
 sockfd1 = socket(2, SOCK_DGRAM, 137);
 memset(&addr1, 0, sizeof(addr1));
 addr1.sin_family = 2;
 addr1.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 rc = bind(sockfd1, (struct sockaddr *) &addr1, sizeof(addr1));
 dprintf("after first bind rc = %d\n", rc);
 sockfd2 = socket(2, SOCK_DGRAM, 137);
 memset(&addr2, 0, sizeof(addr2));
 addr2.sin_family = 2;
 addr2.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 rc = bind(sockfd2, (struct sockaddr *) &addr2, sizeof(addr2));
 dprintf("after second bind rc = %d\n", rc);
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 98); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd1);
 close(sockfd2);
}

canonical_original_code:
static void bind_address_in_use()
{
 struct sockaddr_sw addr1; struct sockaddr_sw addr2;
 int sockfd1; int sockfd2;
 int rc;
 sockfd1 = socket(2, SOCK_DGRAM, 137);
 memset(&addr1, 0, sizeof(addr1));
 addr1.sin_family = 2;
 addr1.sin_addr.s_addr = ((unsigned int) 0x00000000);
 rc = bind(sockfd1, (struct sockaddr *) &addr1, sizeof(addr1));
 dprintf("after first bind rc = %d\n", rc);
 sockfd2 = socket(2, SOCK_DGRAM, 137);
 memset(&addr2, 0, sizeof(addr2));
 addr2.sin_family = 2;
 addr2.sin_addr.s_addr = ((unsigned int) 0x00000000);
 rc = bind(sockfd2, (struct sockaddr *) &addr2, sizeof(addr2));
 dprintf("after second bind rc = %d\n", rc);
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 98); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
 close(sockfd1);
 close(sockfd2);
}


decompiled_code:
int bind_test_suite()
{
printf("\n==== Starting %s ====\n", "bind_test_suite");
bind_dummy();
bind_invalid_descriptor();
bind_descriptor_not_a_socket();
bind_invalid_ip_address();
bind_ok();
bind_address_in_use();
return bind_socket_already_bound();
}

canonical_decompiled_code:
int func7()
{
printf("\n==== Starting %s ====\n", "bind_test_suite");
func0();
func1();
func2();
func3();
func4();
func6();
return func5();
}

original_code:
void bind_test_suite(void)
{
 do { printf("\n==== Starting %s ====\n", __FUNCTION__); } while (0);
 bind_dummy();
 bind_invalid_descriptor();
 bind_descriptor_not_a_socket();
 bind_invalid_ip_address();
 bind_ok();
 bind_address_in_use();
 bind_socket_already_bound();
}

canonical_original_code:
void bind_test_suite()
{
 do { printf("\n==== Starting %s ====\n", __FUNCTION__); } while (0);
 bind_dummy();
 bind_invalid_descriptor();
 bind_descriptor_not_a_socket();
 bind_invalid_ip_address();
 bind_ok();
 bind_address_in_use();
 bind_socket_already_bound();
}


decompiled_code:
int socket_insufficient_file_descriptors()
{
int v0; // ebp
int *v1; // rbx
_BOOL4 v2; // er12
__int64 v3; // rbx

while ( dup(1) >= 0 )
;
v0 = socket(2, 2, 137);
v1 = _errno_location();
dprintf((int)"errno = %d\n", (const char *)*v1);
v2 = 0;
if ( v0 < 0 )
v2 = *v1 == 24;
printf("%s", "socket_insufficient_file_descriptors");
fflush(stdout);
v3 = 24LL;
do
{
putchar(46);
--v3;
}
while ( v3 );
if ( v2 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

canonical_decompiled_code:
int func0()
{
int v0; // ebp
int *v1; // rbx
_BOOL4 v2; // er12
__int64 v3; // rbx

while ( dup(1) >= 0 )
;
v0 = socket(2, 2, 137);
v1 = _errno_location();
dprintf((int)"errno = %d\n", (const char *)*v1);
v2 = 0;
if ( v0 < 0 )
v2 = *v1 == 24;
printf("%s", "socket_insufficient_file_descriptors");
fflush(stdout);
v3 = 24LL;
do
{
putchar(46);
--v3;
}
while ( v3 );
if ( v2 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

original_code:
static void socket_insufficient_file_descriptors(void)
{
 int fd;
 int rc;
 while (1) {
  fd = dup(1);
  if (fd < 0)
   break;
 }
 rc = socket(2, SOCK_DGRAM, 137);
 dprintf("errno = %d\n", (*__errno_location ()));
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 24); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void socket_insufficient_file_descriptors()
{
 int fd;
 int rc;
 while (1) {
  fd = dup(1);
  if (fd < 0)
   break;
 }
 rc = socket(2, SOCK_DGRAM, 137);
 dprintf("errno = %d\n", (*__errno_location ()));
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 24); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}


decompiled_code:
int socket_dummy()
{
__int64 v0; // rbx

printf("%s", "socket_dummy");
fflush(stdout);
v0 = 48LL;
do
{
putchar(46);
--v0;
}
while ( v0 );
puts("passed");
return fflush(stdout);
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbx

printf("%s", "socket_dummy");
fflush(stdout);
v0 = 48LL;
do
{
putchar(46);
--v0;
}
while ( v0 );
puts("passed");
return fflush(stdout);
}

original_code:
static void socket_dummy(void)
{
 do { size_t i; int t = (1 == 1); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void socket_dummy()
{
 do { unsigned long i; int t = (1 == 1); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}


decompiled_code:
int socket_invalid_domain()
{
_BOOL4 v0; // ebp
__int64 v1; // rbx

v0 = 0;
if ( socket(1, 2, 137) < 0 )
v0 = *_errno_location() == 22;
printf("%s", "socket_invalid_domain");
fflush(stdout);
v1 = 39LL;
do
{
putchar(46);
--v1;
}
while ( v1 );
if ( v0 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

canonical_decompiled_code:
int func2()
{
_BOOL4 v0; // ebp
__int64 v1; // rbx

v0 = 0;
if ( socket(1, 2, 137) < 0 )
v0 = *_errno_location() == 22;
printf("%s", "socket_invalid_domain");
fflush(stdout);
v1 = 39LL;
do
{
putchar(46);
--v1;
}
while ( v1 );
if ( v0 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

original_code:
static void socket_invalid_domain(void)
{
 int rc;
 rc = socket(1, SOCK_DGRAM, 137);
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 22); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void socket_invalid_domain()
{
 int rc;
 rc = socket(1, SOCK_DGRAM, 137);
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 22); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}


decompiled_code:
int socket_invalid_type()
{
_BOOL4 v0; // ebp
__int64 v1; // rbx

v0 = 0;
if ( socket(2, 1, 137) < 0 )
v0 = *_errno_location() == 22;
printf("%s", "socket_invalid_type");
fflush(stdout);
v1 = 41LL;
do
{
putchar(46);
--v1;
}
while ( v1 );
if ( v0 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

canonical_decompiled_code:
int func3()
{
_BOOL4 v0; // ebp
__int64 v1; // rbx

v0 = 0;
if ( socket(2, 1, 137) < 0 )
v0 = *_errno_location() == 22;
printf("%s", "socket_invalid_type");
fflush(stdout);
v1 = 41LL;
do
{
putchar(46);
--v1;
}
while ( v1 );
if ( v0 )
puts("passed");
else
puts("failed");
return fflush(stdout);
}

original_code:
static void socket_invalid_type(void)
{
 int rc;
 rc = socket(2, SOCK_STREAM, 137);
 do { size_t i; int t = (rc < 0 && (*__errno_location ()) == 22); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}

canonical_original_code:
static void socket_invalid_type()
{
 int rc;
 rc = socket(2, SOCK_STREAM, 137);
 do { unsigned long i; int t = (rc < 0 && (*__errno_location ()) == 22); printf("%s", __FUNCTION__); fflush(stdout); for (i = 0; i < 60 - strlen(__FUNCTION__); i++) putchar('.'); if (!t) printf("failed\n"); else printf("passed\n"); fflush(stdout); } while (0);
}