decompiled_code:
__int64 __fastcall buffer_locate(__int64 a1, const char *a2)
{
__int64 v2; // rax
const char *v3; // rdx
const char *v4; // rax
char v5; // r13
const char *v6; // rbp
char *v7; // rax
const char *v9; // rax
char v10; // r13
const char *v11; // rbp
size_t v12; // rax
__int64 v13; // rbp
const char *v14; // r15
size_t v15; // r14
char *v16; // rax
const char *v17; // r15
char v18; // r13
const char *v19; // rbp
char *v20; // rax
char v21[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !*(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
if ( !*a2 )
return 0xFFFFFFFFLL;
v2 = *(int *)(a1 + 28);
v3 = *(const char **)a1;
if ( *(_DWORD *)(a1 + 24) < (int)v2 )
{
v9 = &v3[v2];
v10 = *v9;
*v9 = 0;
v11 = *(const char **)a1;
v7 = strstr((const char *)(*(_QWORD *)a1 + *(int *)(a1 + 24)), a2);
v11[*(int *)(a1 + 28)] = v10;
if ( v7 )
return (unsigned int)((_DWORD)v7 - *(_DWORD *)a1 - *(_DWORD *)(a1 + 24));
return 0xFFFFFFFFLL;
}
v4 = &v3[*(_QWORD *)(a1 + 16) - 1];
v5 = *v4;
*v4 = 0;
v6 = *(const char **)a1;
v7 = strstr((const char *)(*(_QWORD *)a1 + *(int *)(a1 + 24)), a2);
v6[*(_QWORD *)(a1 + 16) - 1] = v5;
if ( !v7 )
{
v12 = strlen(a2);
v13 = *(_QWORD *)(a1 + 16);
v14 = *(const char **)a1;
v15 = v12;
memcpy(v21, (const void *)(*(_QWORD *)a1 + v13 - v12), v12);
memcpy(&v21[v15], v14, v15);
v21[2 * v15 + 1] = 0;
v16 = strstr(v21, a2);
if ( v16 )
return (_DWORD)v13 - *(_DWORD *)(a1 + 24) - (_DWORD)v15 + (unsigned int)v16 - (unsigned int)v21;
v17 = &v14[*(int *)(a1 + 28)];
v18 = *v17;
*v17 = 0;
v19 = *(const char **)a1;
v20 = strstr(*(const char **)a1, a2);
v19[*(int *)(a1 + 28)] = v18;
if ( v20 )
return (unsigned int)*(_QWORD *)(a1 + 16) - *(_DWORD *)(a1 + 24) + (_DWORD)v20 - *(_DWORD *)a1;
return 0xFFFFFFFFLL;
}
return (unsigned int)((_DWORD)v7 - *(_DWORD *)a1 - *(_DWORD *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2)
{
__int64 v2; // rax
const char *v3; // rdx
const char *v4; // rax
char v5; // r13
const char *v6; // rbp
char *v7; // rax
const char *v9; // rax
char v10; // r13
const char *v11; // rbp
size_t v12; // rax
__int64 v13; // rbp
const char *v14; // r15
size_t v15; // r14
char *v16; // rax
const char *v17; // r15
char v18; // r13
const char *v19; // rbp
char *v20; // rax
char v21[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !*(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
if ( !*a2 )
return 0xFFFFFFFFLL;
v2 = *(int *)(a1 + 28);
v3 = *(const char **)a1;
if ( *(_DWORD *)(a1 + 24) < (int)v2 )
{
v9 = &v3[v2];
v10 = *v9;
*v9 = 0;
v11 = *(const char **)a1;
v7 = strstr((const char *)(*(_QWORD *)a1 + *(int *)(a1 + 24)), a2);
v11[*(int *)(a1 + 28)] = v10;
if ( v7 )
return (unsigned int)((_DWORD)v7 - *(_DWORD *)a1 - *(_DWORD *)(a1 + 24));
return 0xFFFFFFFFLL;
}
v4 = &v3[*(_QWORD *)(a1 + 16) - 1];
v5 = *v4;
*v4 = 0;
v6 = *(const char **)a1;
v7 = strstr((const char *)(*(_QWORD *)a1 + *(int *)(a1 + 24)), a2);
v6[*(_QWORD *)(a1 + 16) - 1] = v5;
if ( !v7 )
{
v12 = strlen(a2);
v13 = *(_QWORD *)(a1 + 16);
v14 = *(const char **)a1;
v15 = v12;
memcpy(v21, (const void *)(*(_QWORD *)a1 + v13 - v12), v12);
memcpy(&v21[v15], v14, v15);
v21[2 * v15 + 1] = 0;
v16 = strstr(v21, a2);
if ( v16 )
return (_DWORD)v13 - *(_DWORD *)(a1 + 24) - (_DWORD)v15 + (unsigned int)v16 - (unsigned int)v21;
v17 = &v14[*(int *)(a1 + 28)];
v18 = *v17;
*v17 = 0;
v19 = *(const char **)a1;
v20 = strstr(*(const char **)a1, a2);
v19[*(int *)(a1 + 28)] = v18;
if ( v20 )
return (unsigned int)*(_QWORD *)(a1 + 16) - *(_DWORD *)(a1 + 24) + (_DWORD)v20 - *(_DWORD *)a1;
return 0xFFFFFFFFLL;
}
return (unsigned int)((_DWORD)v7 - *(_DWORD *)a1 - *(_DWORD *)(a1 + 24));
}

original_code:
int buffer_locate(buffer_t *buf, char *delimiter) {
    char tmp[20];
    char last_char;
    char *sub;
    int idx = -1;
    size_t delim_len;
    if (buf->size <= 0 || *delimiter == '\0') {
        return -1;
    }
    if (buf->head < buf->tail) {
        last_char = buf->data[buf->tail];
        buf->data[buf->tail] = '\0';
        sub = strstr((char*)buf->data + buf->head, delimiter);
        buf->data[buf->tail] = last_char;
        if (sub != ((void *)0)) {
            idx = (sub - (char*)buf->data) - buf->head;
            goto finish;
        }
    } else {
        last_char = buf->data[buf->capacity - 1];
        buf->data[buf->capacity - 1] = '\0';
        sub = strstr((char*)buf->data + buf->head, delimiter);
        buf->data[buf->capacity - 1] = last_char;
        if (sub != ((void *)0)) {
            idx = (sub - (char*)buf->data) - buf->head;
            goto finish;
        }
        delim_len = strlen(delimiter);
        memcpy(tmp, buf->data + buf->capacity - delim_len, delim_len);
        memcpy(tmp + delim_len, buf->data, delim_len);
        tmp[delim_len * 2 + 1] = '\0';
        sub = strstr(tmp, delimiter);
        if (sub != ((void *)0)) {
            idx = buf->capacity - delim_len - buf->head + (sub - tmp);
            goto finish;
        }
        last_char = buf->data[buf->tail];
        buf->data[buf->tail] = '\0';
        sub = strstr((char*)buf->data, delimiter);
        buf->data[buf->tail] = last_char;
        if (sub != ((void *)0)) {
            idx = (sub - (char*)buf->data) + (buf->capacity - buf->head);
            goto finish;
        }
    }
finish:
    return idx;
}

canonical_original_code:
int buffer_locate(struct _buffer *buf, char *delimiter) {
    char tmp[20];
    char last_char;
    char *sub;
    int idx = -1;
    unsigned long delim_len;
    if (buf->size <= 0 || *delimiter == '\0') {
        return -1;
    }
    if (buf->head < buf->tail) {
        last_char = buf->data[buf->tail];
        buf->data[buf->tail] = '\0';
        sub = strstr((char *)buf->data + buf->head, delimiter);
        buf->data[buf->tail] = last_char;
        if (sub != ((void *)0)) {
            idx = (sub - (char *)buf->data) - buf->head;
            goto finish;
        }
    } else {
        last_char = buf->data[buf->capacity - 1];
        buf->data[buf->capacity - 1] = '\0';
        sub = strstr((char *)buf->data + buf->head, delimiter);
        buf->data[buf->capacity - 1] = last_char;
        if (sub != ((void *)0)) {
            idx = (sub - (char *)buf->data) - buf->head;
            goto finish;
        }
        delim_len = strlen(delimiter);
        memcpy(tmp, buf->data + buf->capacity - delim_len, delim_len);
        memcpy(tmp + delim_len, buf->data, delim_len);
        tmp[delim_len * 2 + 1] = '\0';
        sub = strstr(tmp, delimiter);
        if (sub != ((void *)0)) {
            idx = buf->capacity - delim_len - buf->head + (sub - tmp);
            goto finish;
        }
        last_char = buf->data[buf->tail];
        buf->data[buf->tail] = '\0';
        sub = strstr((char *)buf->data, delimiter);
        buf->data[buf->tail] = last_char;
        if (sub != ((void *)0)) {
            idx = (sub - (char *)buf->data) + (buf->capacity - buf->head);
            goto finish;
        }
    }
finish:
    return idx;
}

variable_types:
delimiter
char *

variable_types:
tmp
char [20]

variable_types:
sub
char *

variable_types: idx int


logging

repo: moonranger/breeze

decompiled_code:
void logging(int a1, const char *a2, unsigned int a3, const char *a4, ...)
{
struct tm *v6; // rax
int v7; // eax
int v8; // er12
char *v9; // rbp
int v10; // eax
char *v11; // rbp
int v12; // eax
time_t v13; // [rsp+0h] [rbp-308h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char s[512]; // [rsp+20h] [rbp-2E8h] BYREF

if ( log_level <= a1 )
{
v13 = time(0LL);
v6 = localtime(&v13);
v7 = strftime(s, 0x200uLL, "[%Y-%m-%d %H:%M:%S]", v6);
v8 = 512 - v7;
v9 = &s[v7];
v10 = snprintf(v9, 512 - v7, "[%-5s][%s:%d] ", LEVEL_NAMES[a1], a2, a3);
v11 = &v9[v10];
va_start(arg, a4);
v12 = vsnprintf(v11, v8 - v10, a4, arg);
v11[v12] = 10;
v11[v12 + 1] = 0;
if ( enable_console )
{
if ( a1 <= 1 )
fputs(s, stdout);
else
fputs(s, stderr);
}
if ( log_stream )
fputs(s, log_stream);
}
}

canonical_decompiled_code:
void func0(int a1, const char *a2, unsigned int a3, const char *a4, ...)
{
struct tm *v6; // rax
int v7; // eax
int v8; // er12
char *v9; // rbp
int v10; // eax
char *v11; // rbp
int v12; // eax
time_t v13; // [rsp+0h] [rbp-308h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char s[512]; // [rsp+20h] [rbp-2E8h] BYREF

if ( log_level <= a1 )
{
v13 = time(0LL);
v6 = localtime(&v13);
v7 = strftime(s, 0x200uLL, "[%Y-%m-%d %H:%M:%S]", v6);
v8 = 512 - v7;
v9 = &s[v7];
v10 = snprintf(v9, 512 - v7, "[%-5s][%s:%d] ", LEVEL_NAMES[a1], a2, a3);
v11 = &v9[v10];
va_start(arg, a4);
v12 = vsnprintf(v11, v8 - v10, a4, arg);
v11[v12] = 10;
v11[v12 + 1] = 0;
if ( enable_console )
{
if ( a1 <= 1 )
fputs(s, stdout);
else
fputs(s, stderr);
}
if ( log_stream )
fputs(s, log_stream);
}
}

original_code:
void logging(int lvl, const char *file, const int line, const char *fmt, ...) {
    va_list ap;
    char buffer[512], *ptr = buffer;
    int size, cap = 512;
    time_t ts;
    struct tm *tmp;
    if (lvl < log_level) {
        return;
    }
    ts = time(((void *)0));
    tmp = localtime(&ts);
    size = strftime(ptr, cap, "[%Y-%m-%d %H:%M:%S]", tmp);
    ptr += size;
    cap -= size;
    size = snprintf(ptr, cap, "[%-5s][%s:%d] ",
                    LEVEL_NAMES[lvl], file, line);
    ptr += size;
    cap -= size;
    __builtin_va_start(ap,fmt);
    size = vsnprintf(ptr, cap, fmt, ap);
    __builtin_va_end(ap);
    *(ptr + size) = '\n';
    *(ptr + size + 1) = '\0';
    if (enable_console) {
        if (lvl >= WARN) {
            fputs(buffer, stderr);
        } else {
            fputs(buffer, stdout);
        }
    }
    if (log_stream != ((void *)0)) {
        fputs(buffer, log_stream);
    }
}

canonical_original_code:
void logging(int lvl, char *file, int line, char *fmt, ...) {
    __builtin_va_list ap;
    char buffer[512]; char *ptr = buffer;
    int size; int cap = 512;
    long ts;
    struct tm *tmp;
    if (lvl < log_level) {
        return;
    }
    ts = time(((void *)0));
    tmp = localtime(&ts);
    size = strftime(ptr, cap, "[%Y-%m-%d %H:%M:%S]", tmp);
    ptr += size;
    cap -= size;
    size = snprintf(ptr, cap, "[%-5s][%s:%d] ",
                    LEVEL_NAMES[lvl], file, line);
    ptr += size;
    cap -= size;
    __builtin_va_start(ap,fmt);
    size = vsnprintf(ptr, cap, fmt, ap);
    __builtin_va_end(ap);
    *(ptr + size) = '\n';
    *(ptr + size + 1) = '\0';
    if (enable_console) {
        if (lvl >= WARN) {
            fputs(buffer, stderr);
        } else {
            fputs(buffer, stdout);
        }
    }
    if (log_stream != ((void *)0)) {
        fputs(buffer, log_stream);
    }
}

variable_types: lvl int

variable_types:
file
char *

variable_types: line int

variable_types:
fmt
char *

variable_types:
buffer
char [512]

variable_types:
ptr
char *

variable_types: size int

variable_types: cap int

variable_types: ts long

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


decompiled_code:
size_t __fastcall format_http_date(const time_t *a1, char *a2, size_t a3)
{
struct tm *v4; // rax

v4 = gmtime(a1);
return strftime(a2, a3, HTTP_DATE_FMT, v4);
}

canonical_decompiled_code:
size_t __fastcall func0(const time_t *a1, char *a2, size_t a3)
{
struct tm *v4; // rax

v4 = gmtime(a1);
return strftime(a2, a3, HTTP_DATE_FMT, v4);
}

original_code:
void format_http_date(const time_t* time, char *dst, size_t len) {
    strftime(dst, len, HTTP_DATE_FMT, gmtime(time));
}

canonical_original_code:
void format_http_date(long *time, char *dst, unsigned long len) {
    strftime(dst, len, HTTP_DATE_FMT, gmtime(time));
}

variable_types:
time
long *

variable_types:
dst
char *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall parse_http_date(const char *a1, time_t *a2)
{
struct tm v3; // [rsp+0h] [rbp-48h] BYREF

if ( !strptime(a1, HTTP_DATE_FMT, &v3) )
return 0xFFFFFFFFLL;
*a2 = timegm(&v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, time_t *a2)
{
struct tm v3; // [rsp+0h] [rbp-48h] BYREF

if ( !strptime(a1, HTTP_DATE_FMT, &v3) )
return 0xFFFFFFFFLL;
*a2 = timegm(&v3);
return 0LL;
}

original_code:
int parse_http_date(const char* str, time_t *time) {
    struct tm tm;
    if (strptime(str, HTTP_DATE_FMT, &tm) == ((void *)0)) {
        return -1;
    }
    *time = timegm(&tm);
    return 0;
}

canonical_original_code:
int parse_http_date(char *str, long *time) {
    struct tm tm;
    if (strptime(str, HTTP_DATE_FMT, &tm) == ((void *)0)) {
        return -1;
    }
    *time = timegm(&tm);
    return 0;
}

variable_types:
str
char *

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


decompiled_code:
__int64 __fastcall current_http_date(char *a1, size_t a2)
{
const char *v2; // rdx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( gettimeofday(&v4, 0LL) < 0 )
{
error((int)"Error getting time of day", 0, v2);
result = 0xFFFFFFFFLL;
}
else
{
format_http_date(&v4.tv_sec, a1, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, size_t a2)
{
const char *v2; // rdx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( gettimeofday(&v4, 0LL) < 0 )
{
error((int)"Error getting time of day", 0, v2);
result = 0xFFFFFFFFLL;
}
else
{
func0(&v4.tv_sec, a1, a2);
result = 0LL;
}
return result;
}

original_code:
int current_http_date(char *dst, size_t len) {
    struct timeval tv;
    int res;
    res = gettimeofday(&tv, ((void *)0));
    if (res < 0) {
        error("Error getting time of day");
        return -1;
    }
    format_http_date(&tv.tv_sec, dst, len);
    return 0;
}

canonical_original_code:
int current_http_date(char *dst, unsigned long len) {
    struct timeval tv;
    int res;
    res = gettimeofday(&tv, ((void *)0));
    if (res < 0) {
        error("Error getting time of day");
        return -1;
    }
    format_http_date(&tv.tv_sec, dst, len);
    return 0;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: res int


decompiled_code:
__int64 __fastcall path_starts_with(char *a1, char *a2)
{
char v2; // al
unsigned int v3; // er8
char v4; // dl

if ( !a2 || !a1 )
return 0;
v2 = *a2;
v3 = 0;
if ( !*a2 )
{
LABEL_15:
if ( *a1 )
v3 = 0;
return v3;
}
while ( 1 )
{
v4 = *a1;
if ( *a1 != v2 )
break;
if ( !v4 )
goto LABEL_11;
v2 = *++a2;
++v3;
++a1;
if ( !v2 )
goto LABEL_15;
}
if ( v4 )
return 0;
LABEL_11:
if ( v2 == 47 )
return v3;
if ( *(a1 - 1) != 47 )
v3 = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, char *a2)
{
char v2; // al
unsigned int v3; // er8
char v4; // dl

if ( !a2 || !a1 )
return 0;
v2 = *a2;
v3 = 0;
if ( !*a2 )
{
LABEL_15:
if ( *a1 )
v3 = 0;
return v3;
}
while ( 1 )
{
v4 = *a1;
if ( *a1 != v2 )
break;
if ( !v4 )
goto LABEL_11;
v2 = *++a2;
++v3;
++a1;
if ( !v2 )
goto LABEL_15;
}
if ( v4 )
return 0;
LABEL_11:
if ( v2 == 47 )
return v3;
if ( *(a1 - 1) != 47 )
v3 = 0;
return v3;
}

original_code:
int path_starts_with(const char* prefix, const char* path) {
    int match_count;
    if (path == ((void *)0) || prefix == ((void *)0))
        return 0;
    match_count = 0;
    while (*path != '\0' && *prefix != '\0' && *path == *prefix) {
        match_count++;
        path++;
        prefix++;
    }
    if (*prefix == '\0'
        && (*path == '\0' || *path == '/' || *(prefix-1) == '/'))
        return match_count;
    else
        return 0;
}

canonical_original_code:
int path_starts_with(char *prefix, char *path) {
    int match_count;
    if (path == ((void *)0) || prefix == ((void *)0))
        return 0;
    match_count = 0;
    while (*path != '\0' && *prefix != '\0' && *path == *prefix) {
        match_count++;
        path++;
        prefix++;
    }
    if (*prefix == '\0'
        && (*path == '\0' || *path == '/' || *(prefix-1) == '/'))
        return match_count;
    else
        return 0;
}

variable_types:
prefix
char *

variable_types:
path
char *


decompiled_code:
void __fastcall __noreturn stacktrace_handler(int a1)
{
int v1; // ebp
char *v2; // rax
void *v3[33]; // [rsp+0h] [rbp-108h] BYREF

v1 = backtrace(v3, 30);
v2 = strsignal(a1);
logging(3LL, "stacktrace.c", 18LL, "Error captured. Signal: %s", v2);
backtrace_symbols_fd(v3, v1, 2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
int v1; // ebp
char *v2; // rax
void *v3[33]; // [rsp+0h] [rbp-108h] BYREF

v1 = backtrace(v3, 30);
v2 = strsignal(a1);
logging(3LL, "stacktrace.c", 18LL, "Error captured. Signal: %s", v2);
backtrace_symbols_fd(v3, v1, 2);
exit(1);
}

original_code:
static void stacktrace_handler(int sig) {
    void *trace[30];
    size_t depth;
    depth = backtrace(trace, 30);
    logging(ERROR, "stacktrace.c", 18, "Error captured. Signal: %s", strsignal(sig));
    backtrace_symbols_fd(trace, depth, 2);
    exit(1);
}

canonical_original_code:
static void stacktrace_handler(int sig) {
    void *trace[30];
    unsigned long depth;
    depth = backtrace(trace, 30);
    logging(ERROR, "stacktrace.c", 18, "Error captured. Signal: %s", strsignal(sig));
    backtrace_symbols_fd(trace, depth, 2);
    exit(1);
}

variable_types: sig int

variable_types:
trace
void *[30]

variable_types:
depth
unsigned long


decompiled_code:
__sighandler_t print_stacktrace_on_error()
{
signal(11, (__sighandler_t)stacktrace_handler);
signal(8, (__sighandler_t)stacktrace_handler);
return signal(6, (__sighandler_t)stacktrace_handler);
}

canonical_decompiled_code:
__sighandler_t func1()
{
signal(11, (__sighandler_t)stacktrace_handler);
signal(8, (__sighandler_t)stacktrace_handler);
return signal(6, (__sighandler_t)stacktrace_handler);
}

original_code:
void print_stacktrace_on_error() {
    signal(11, stacktrace_handler);
    signal(8, stacktrace_handler);
    signal(6, stacktrace_handler);
}


vsay

repo: moonsdad/Troll-Raider

decompiled_code:
int vsay(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-120h] BYREF
char s[80]; // [rsp+20h] [rbp-108h] BYREF

va_start(arg, format);
vsnprintf(s, 0x50uLL, format, arg);
return wsay(display_btm, s);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-120h] BYREF
char s[80]; // [rsp+20h] [rbp-108h] BYREF

va_start(arg, format);
vsnprintf(s, 0x50uLL, format, arg);
return func0(display_btm, s);
}

original_code:
void vsay( const char * fmt, ... )
{
    char buf[80];
    va_list valist;
    __builtin_va_start(valist,fmt);
    vsnprintf( buf, 80, fmt, valist );
    __builtin_va_end(valist);
    wsay( display_btm, buf );
}

canonical_original_code:
void vsay(char *fmt, ...)
{
    char buf[80];
    __builtin_va_list valist;
    __builtin_va_start(valist,fmt);
    vsnprintf( buf, 80, fmt, valist );
    __builtin_va_end(valist);
    wsay( display_btm, buf );
}

variable_types:
fmt
char *

variable_types:
buf
char [80]


stricpy

original_code:
size_t stricpy( char * dest, const char * src, size_t n )
{
    size_t i;
    ((void) sizeof ((src && dest) ? 1 : 0), __extension__ ({ if (src && dest) ; else __assert_fail ("src && dest", "src/rmhv_stdlib.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    for( i = 0; ( i < n )&&( src[i] != '\0' ); i++ ) dest[i] = src[i];
    if( i < n ) dest[i] = '\0';
    return i;
}

canonical_original_code:
unsigned long stricpy(char *dest, char *src, unsigned long n)
{
    unsigned long i;
    ((void) sizeof ((src && dest) ? 1 : 0), __extension__ ({ if (src && dest) ; else __assert_fail ("src && dest", "src/rmhv_stdlib.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    for( i = 0; ( i < n )&&( src[i] != '\0' ); i++ ) dest[i] = src[i];
    if( i < n ) dest[i] = '\0';
    return i;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


mypause

decompiled_code:
int __fastcall mypause(char a1)
{
if ( a1 )
printf("Press [Enter] to continue . . .");
fflush(stdout);
return getchar();
}

canonical_decompiled_code:
int __fastcall func2(char a1)
{
if ( a1 )
printf("Press [Enter] to continue . . .");
fflush(stdout);
return getchar();
}

original_code:
void mypause( _Bool display_prompt )
{
    if( display_prompt ) printf( "Press [Enter] to continue . . ." );
    fflush( stdout );
    getchar();
}

canonical_original_code:
void mypause(_Bool display_prompt)
{
    if( display_prompt ) printf( "Press [Enter] to continue . . ." );
    fflush( stdout );
    getchar();
}


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

if ( !a1 )
_assert_fail("ptr != NULL", "src/item.c", 0x66u, "slot_of");
v1 = *(unsigned __int16 *)(a1 + 26);
if ( (unsigned __int16)v1 <= 6u )
result = (unsigned int)CSWTCH_9[v1];
else
result = 4LL;
return result;
}

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

if ( !a1 )
_assert_fail("ptr != NULL", "src/item.c", 0x66u, "slot_of");
v1 = *(unsigned __int16 *)(a1 + 26);
if ( (unsigned __int16)v1 <= 6u )
result = (unsigned int)CSWTCH_9[v1];
else
result = 4LL;
return result;
}

original_code:
int slot_of( const ITEM * ptr )
{
    ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "src/item.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    switch( ptr->type ) {
        case 0: case 4: case 2: return 0;
        case 1: case 3: return 1;
        case 6: return 2;
        case 5: return 3;
        default: return 4;
    }
}

canonical_original_code:
int slot_of(struct ITEM *ptr)
{
    ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "src/item.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    switch( ptr->type ) {
        case 0: case 4: case 2: return 0;
        case 1: case 3: return 1;
        case 6: return 2;
        case 5: return 3;
        default: return 4;
    }
}

variable_types: struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *


decompiled_code:
bool __fastcall is_equipable(__int64 a1)
{
if ( !a1 )
_assert_fail("itm != NULL", "src/item.c", 0x78u, "is_equipable");
return *(_WORD *)(a1 + 26) <= 6u;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("itm != NULL", "src/item.c", 0x78u, "is_equipable");
return *(_WORD *)(a1 + 26) <= 6u;
}

original_code:
_Bool is_equipable( ITEM * itm )
{
    ((void) sizeof ((itm != ((void *)0)) ? 1 : 0), __extension__ ({ if (itm != ((void *)0)) ; else __assert_fail ("itm != NULL", "src/item.c", 120, __extension__ __PRETTY_FUNCTION__); }));
    if( itm->type < 7 ) return 1;
    else return 0;
}

canonical_original_code:
_Bool is_equipable(struct ITEM *itm)
{
    ((void) sizeof ((itm != ((void *)0)) ? 1 : 0), __extension__ ({ if (itm != ((void *)0)) ; else __assert_fail ("itm != NULL", "src/item.c", 120, __extension__ __PRETTY_FUNCTION__); }));
    if( itm->type < 7 ) return 1;
    else return 0;
}

user_defined_types: struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; }


roomgen

original_code:
static _Bool roomgen( RECT * room, COORD center )
{
    int dvert = 2 + ( rand() % (4) ),
        dhorz = 2 + ( rand() % (6) );
    room->a.rowy = center.rowy - dvert;
    room->a.colx = center.colx - dhorz;
    room->b.rowy = center.rowy + dvert;
    room->b.colx = center.colx + dhorz;
    if( ( room->a.rowy < 1 )||( room->a.colx < 1 ) ) return 0;
    if( room->b.rowy > ( 20 - 2 ) ) return 0;
    if( room->b.colx > ( 60 - 2 ) ) return 0;
    return 1;
}

canonical_original_code:
static _Bool roomgen(struct RECT *room, struct COORD center)
{
    int dvert = 2 + ( rand() % (4) ); int dhorz = 2 + ( rand() % (6) );
    room->a.rowy = center.rowy - dvert;
    room->a.colx = center.colx - dhorz;
    room->b.rowy = center.rowy + dvert;
    room->b.colx = center.colx + dhorz;
    if( ( room->a.rowy < 1 )||( room->a.colx < 1 ) ) return 0;
    if( room->b.rowy > ( 20 - 2 ) ) return 0;
    if( room->b.colx > ( 60 - 2 ) ) return 0;
    return 1;
}

variable_types: struct RECT { struct COORD { int rowy; int colx; } a; struct COORD b; } *

variable_types:
center
struct COORD

variable_types: dvert int

variable_types: dhorz int

user_defined_types: struct RECT { struct COORD a; struct COORD b; }


original_code:
void set_loc( LOC * spot, char type )
{
    spot->litter = ((void *)0);
    spot->mon = ((void *)0);
    spot->icon = type;
    spot->is_trap = 0;
}

canonical_original_code:
void set_loc(struct LOC *spot, char type)
{
    spot->litter = ((void *)0);
    spot->mon = ((void *)0);
    spot->icon = type;
    spot->is_trap = 0;
}

variable_types: struct LOC { struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *litter; struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *mon; char icon; _Bool is_trap; } *

variable_types: type char

user_defined_types: struct LOC { struct ITEM *litter; struct PLAYER *mon; char icon; _Bool is_trap; }


towngen

original_code:
static void towngen( LEVEL * outside, LEVEL * inside, COORD * stair_spot )
{
    unsigned short hut_qt = 1 + ( rand() % (5) );
    unsigned short i, j, z;
    COORD hutspot[5];
    RECT room;
    for( i = 0; i < hut_qt; i++ ) {
        do {
            randspot( &hutspot[i] );
            if( i > 0 ) for( z = 0; z < i; z++ )
                if( dist( hutspot[z], hutspot[i] ) < 2.0 ) continue;
        } while( !roomgen( &room, hutspot[i]) );
        fill(outside,WALL,room);
        fill(inside,FLOOR,room);
        for( j = 0, z = ( rand() % (4) ) ; j < 4; j++ ) {
            if( ++z > 4 ) z = 1;
            switch( z ) {
                case 1:
                    hutspot[i].rowy = room.a.rowy;
                    ((void) sizeof ((hutspot[i].rowy-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].rowy-1 > -1) ; else __assert_fail ("hutspot[i].rowy-1 > -1", "src/map.c", 198, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy-1]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 2:
                    hutspot[i].rowy = room.b.rowy - 1;
                    if( outside->map[room.b.rowy]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 3:
                    hutspot[i].colx = room.b.colx - 1;
                    if( outside->map[hutspot[i].rowy]
                                    [room.b.colx].icon == WALL ) continue;
                    break;
                case 4:
                    hutspot[i].colx = room.a.colx;
                    ((void) sizeof ((hutspot[i].colx-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].colx-1 > -1) ; else __assert_fail ("hutspot[i].colx-1 > -1", "src/map.c", 214, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy]
                                    [hutspot[i].colx-1].icon == WALL ) continue;
                    break;
            }
            set_loc( &outside->map[hutspot[i].rowy][hutspot[i].colx], DOOR );
            if( inside->map[hutspot[i].rowy-1]
                           [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy-1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy+1]
                                [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy+1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx+1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx+1], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx-1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx-1], DOOR);
            break;
        }
    }
    randspot( stair_spot );
    if( outside->map[stair_spot->rowy][stair_spot->colx].icon == WALL )
        set_loc( &inside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
    else set_loc( &outside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
}

canonical_original_code:
static void towngen(struct level_struct *outside, struct level_struct *inside, struct COORD *stair_spot)
{
    unsigned short hut_qt = 1 + ( rand() % (5) );
    unsigned short i; unsigned short j; unsigned short z;
    struct COORD hutspot[5];
    struct RECT room;
    for( i = 0; i < hut_qt; i++ ) {
        do {
            randspot( &hutspot[i] );
            if( i > 0 ) for( z = 0; z < i; z++ )
                if( dist( hutspot[z], hutspot[i] ) < 2.0 ) continue;
        } while( !roomgen( &room, hutspot[i]) );
        fill(outside,WALL,room);
        fill(inside,FLOOR,room);
        for( j = 0, z = ( rand() % (4) ) ; j < 4; j++ ) {
            if( ++z > 4 ) z = 1;
            switch( z ) {
                case 1:
                    hutspot[i].rowy = room.a.rowy;
                    ((void) sizeof ((hutspot[i].rowy-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].rowy-1 > -1) ; else __assert_fail ("hutspot[i].rowy-1 > -1", "src/map.c", 198, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy-1]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 2:
                    hutspot[i].rowy = room.b.rowy - 1;
                    if( outside->map[room.b.rowy]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 3:
                    hutspot[i].colx = room.b.colx - 1;
                    if( outside->map[hutspot[i].rowy]
                                    [room.b.colx].icon == WALL ) continue;
                    break;
                case 4:
                    hutspot[i].colx = room.a.colx;
                    ((void) sizeof ((hutspot[i].colx-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].colx-1 > -1) ; else __assert_fail ("hutspot[i].colx-1 > -1", "src/map.c", 214, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy]
                                    [hutspot[i].colx-1].icon == WALL ) continue;
                    break;
            }
            set_loc( &outside->map[hutspot[i].rowy][hutspot[i].colx], DOOR );
            if( inside->map[hutspot[i].rowy-1]
                           [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy-1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy+1]
                                [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy+1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx+1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx+1], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx-1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx-1], DOOR);
            break;
        }
    }
    randspot( stair_spot );
    if( outside->map[stair_spot->rowy][stair_spot->colx].icon == WALL )
        set_loc( &inside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
    else set_loc( &outside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
}

variable_types: struct level_struct { struct LOC { struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *litter; struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *mon; char icon; _Bool is_trap; } map[20][60]; int type; _Bool is_new; } *

variable_types:
inside
struct level_struct *

variable_types:
i
unsigned short

variable_types:
j
unsigned short

variable_types:
z
unsigned short

variable_types: struct COORD { int rowy; int colx; } [5]

variable_types: struct RECT { struct COORD { int rowy; int colx; } a; struct COORD b; }

user_defined_types: struct level_struct { struct LOC map[20][60]; int type; _Bool is_new; }


decompiled_code:
__int64 __fastcall get_map_icon(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned __int8 a9)
{
__int64 result; // rax

result = 38LL;
if ( !a7 )
{
result = 111LL;
if ( !a8 )
result = a9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned __int8 a9)
{
__int64 result; // rax

result = 38LL;
if ( !a7 )
{
result = 111LL;
if ( !a8 )
result = a9;
}
return result;
}

original_code:
char get_map_icon( LOC here )
{
    if( here.litter != ((void *)0) ) return '&';
    if( here.mon != ((void *)0) ) return 'o';
                              return here.icon;
}

canonical_original_code:
char get_map_icon(struct LOC here)
{
    if( here.litter != ((void *)0) ) return '&';
    if( here.mon != ((void *)0) ) return 'o';
                              return here.icon;
}

variable_types: struct LOC { struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *litter; struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *mon; char icon; _Bool is_trap; }

return_type: char


decompiled_code:
int __fastcall draw_map(__int64 a1)
{
int i; // ebp
int j; // ebx
WINDOW *v4; // rdi
int result; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
char v10; // al

for ( i = 0; i != 20; ++i )
{
for ( j = 0; j != 60; ++j )
{
v4 = stdscr;
result = wmove(stdscr, i, j);
if ( result != -1 )
{
v10 = get_map_icon(
(__int64)v4,
(unsigned int)i,
v6,
v7,
v8,
v9,
*(_QWORD *)(a1 + 1440LL * i + 24LL * j),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 8),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 16));
result = waddch(stdscr, (unsigned int)v10);
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int i; // ebp
int j; // ebx
WINDOW *v4; // rdi
int result; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
char v10; // al

for ( i = 0; i != 20; ++i )
{
for ( j = 0; j != 60; ++j )
{
v4 = stdscr;
result = wmove(stdscr, i, j);
if ( result != -1 )
{
v10 = func6(
(__int64)v4,
(unsigned int)i,
v6,
v7,
v8,
v9,
*(_QWORD *)(a1 + 1440LL * i + 24LL * j),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 8),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 16));
result = waddch(stdscr, (unsigned int)v10);
}
}
}
return result;
}

original_code:
void draw_map( LEVEL * curlv )
{
    int r, c;
    for( r = 0; r < 20; r++ ) for( c = 0; c < 60; c++ )
        (wmove((stdscr),((r)),((c))) == (-1) ? (-1) : waddch((stdscr),((get_map_icon( curlv->map[r][c] )))));
}

canonical_original_code:
void draw_map(struct level_struct *curlv)
{
    int r; int c;
    for( r = 0; r < 20; r++ ) for( c = 0; c < 60; c++ )
        (wmove((stdscr),((r)),((c))) == (-1) ? (-1) : waddch((stdscr),((get_map_icon( curlv->map[r][c] )))));
}

variable_types: r int

variable_types: c int

user_defined_types: struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; }


dungen

original_code:
_Bool dungen( LEVEL * curlv, PLAYER * npc )
{
    int i;
    COORD prev_stair_spot;
    COORD top_left = { 0, 0 };
    COORD btm_right = { 20, 60 };
    RECT room = { top_left, btm_right };
    for( i = 0; i < 9; i++ ) {
        curlv[i].type = i;
        curlv[i].is_new = 1;
        if( i == 0 ) fill(&curlv[i],FLOOR,room);
        else fill(&curlv[i],WALL,room);
    }
    towngen( &curlv[0], &curlv[1], &prev_stair_spot );
    if( !roomgen( &room, prev_stair_spot ) ) {
        set_loc( &( curlv[6].map[prev_stair_spot.rowy]
                                       [prev_stair_spot.colx] ), FLOOR );
    } else fill(&curlv[6],FLOOR,room);
    return 1;
}

canonical_original_code:
_Bool dungen(struct level_struct *curlv, struct PLAYER *npc)
{
    int i;
    struct COORD prev_stair_spot;
    struct COORD top_left = { 0, 0 };
    struct COORD btm_right = { 20, 60 };
    struct RECT room = { top_left, btm_right };
    for( i = 0; i < 9; i++ ) {
        curlv[i].type = i;
        curlv[i].is_new = 1;
        if( i == 0 ) fill(&curlv[i],FLOOR,room);
        else fill(&curlv[i],WALL,room);
    }
    towngen( &curlv[0], &curlv[1], &prev_stair_spot );
    if( !roomgen( &room, prev_stair_spot ) ) {
        set_loc( &( curlv[6].map[prev_stair_spot.rowy]
                                       [prev_stair_spot.colx] ), FLOOR );
    } else fill(&curlv[6],FLOOR,room);
    return 1;
}

variable_types:
npc
struct PLAYER *

variable_types: i int


decompiled_code:
__int64 get_cmd()
{
int v0; // eax
unsigned int v1; // er8

v0 = wgetch(stdscr);
if ( v0 <= 119 )
{
if ( v0 <= 26 )
return 0;
switch ( v0 )
{
case 27:
case 81:
case 113:
v1 = 10;
break;
case 44:
case 103:
v1 = 16;
break;
case 49:
v1 = 8;
break;
case 50:
v1 = 2;
break;
case 51:
v1 = 7;
break;
case 52:
return 4;
case 53:
v1 = 9;
break;
case 54:
v1 = 3;
break;
case 55:
v1 = 6;
break;
case 56:
v1 = 1;
break;
case 57:
v1 = 5;
break;
case 73:
case 105:
v1 = 11;
break;
case 75:
v1 = 15;
break;
case 84:
case 117:
v1 = 14;
break;
case 100:
v1 = 13;
break;
case 101:
case 119:
v1 = 12;
break;
default:
return 0;
}
return v1;
}
if ( v0 == 260 )
return 4;
if ( v0 <= 260 )
{
v1 = 2;
if ( v0 != 258 )
v1 = v0 == 259;
return v1;
}
return 3 * (unsigned int)(v0 == 261);
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
unsigned int v1; // er8

v0 = wgetch(stdscr);
if ( v0 <= 119 )
{
if ( v0 <= 26 )
return 0;
switch ( v0 )
{
case 27:
case 81:
case 113:
v1 = 10;
break;
case 44:
case 103:
v1 = 16;
break;
case 49:
v1 = 8;
break;
case 50:
v1 = 2;
break;
case 51:
v1 = 7;
break;
case 52:
return 4;
case 53:
v1 = 9;
break;
case 54:
v1 = 3;
break;
case 55:
v1 = 6;
break;
case 56:
v1 = 1;
break;
case 57:
v1 = 5;
break;
case 73:
case 105:
v1 = 11;
break;
case 75:
v1 = 15;
break;
case 84:
case 117:
v1 = 14;
break;
case 100:
v1 = 13;
break;
case 101:
case 119:
v1 = 12;
break;
default:
return 0;
}
return v1;
}
if ( v0 == 260 )
return 4;
if ( v0 <= 260 )
{
v1 = 2;
if ( v0 != 258 )
v1 = v0 == 259;
return v1;
}
return 3 * (unsigned int)(v0 == 261);
}

original_code:
static int get_cmd( void )
{
    switch( wgetch(stdscr) ) {
        case '8': case 0403: return 1;
        case '2': case 0402: return 2;
        case '6': case 0405: return 3;
        case '4': case 0404: return 4;
        case '9': return 5;
        case '7': return 6;
        case '3': return 7;
        case '1': return 8;
        case '5': return 9;
        case 'q':
        case 'Q': case 27: return 10;
        case 'g': case ',': return 16;
        case 'i': case 'I': return 11;
        case 'e': case 'w': return 12;
        case 'u': case 'T': return 14;
        case 'd': return 13;
        case 'K': return 15;
        default: return 0;
    }
}

canonical_original_code:
static int get_cmd()
{
    switch( wgetch(stdscr) ) {
        case '8': case 0403: return 1;
        case '2': case 0402: return 2;
        case '6': case 0405: return 3;
        case '4': case 0404: return 4;
        case '9': return 5;
        case '7': return 6;
        case '3': return 7;
        case '1': return 8;
        case '5': return 9;
        case 'q':
        case 'Q': case 27: return 10;
        case 'g': case ',': return 16;
        case 'i': case 'I': return 11;
        case 'e': case 'w': return 12;
        case 'u': case 'T': return 14;
        case 'd': return 13;
        case 'K': return 15;
        default: return 0;
    }
}


decompiled_code:
__int64 get_subi_cmd()
{
int v0; // eax
unsigned int v1; // er8
__int64 v2; // rax

v0 = wgetch(stdscr);
v1 = 0;
v2 = (unsigned int)(v0 - 27);
if ( (unsigned int)v2 <= 0x5D )
v1 = CSWTCH_84[v2];
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
unsigned int v1; // er8
__int64 v2; // rax

v0 = wgetch(stdscr);
v1 = 0;
v2 = (unsigned int)(v0 - 27);
if ( (unsigned int)v2 <= 0x5D )
v1 = CSWTCH_84[v2];
return v1;
}

original_code:
static int get_subi_cmd( void )
{
    switch( wgetch(stdscr) ) {
        case 'f': case 'F': case 27:
        case 'q': case 'Q': case ' ': return 10;
        case 'D': case 'd':
                                               return 13;
        case 'E': case 'e': case 'r':
        case 'w': case 'W': return 12;
        case 'u': case 'U': case 'R':
        case 't': case 'T': return 14;
        case 'K': case 'k':
        case 'x': case 'X': return 15;
        default: return 0;
    }
}

canonical_original_code:
static int get_subi_cmd()
{
    switch( wgetch(stdscr) ) {
        case 'f': case 'F': case 27:
        case 'q': case 'Q': case ' ': return 10;
        case 'D': case 'd':
                                               return 13;
        case 'E': case 'e': case 'r':
        case 'w': case 'W': return 12;
        case 'u': case 'U': case 'R':
        case 't': case 'T': return 14;
        case 'K': case 'k':
        case 'x': case 'X': return 15;
        default: return 0;
    }
}


decompiled_code:
__int64 __fastcall manage_inventory(__int64 a1, __int64 a2, int a3)
{
int v3; // eax
bool v4; // cc

v3 = a3;
if ( (unsigned int)(a3 - 12) > 3 )
goto LABEL_6;
v4 = a3 <= 14;
if ( a3 == 14 )
goto LABEL_8;
while ( !v4 )
{
if ( v3 != 15 )
return 1LL;
if ( (unsigned __int8)destroy_my_item(a1, 0xFFFFFFFFLL, 1LL) )
return 0LL;
while ( 1 )
{
do
LABEL_6:
v3 = get_subi_cmd();
while ( !v3 );
v4 = v3 <= 14;
if ( v3 != 14 )
break;
LABEL_8:
if ( (unsigned __int8)unequip_me(a1, 0xFFFFFFFFLL, 1LL) )
return 0LL;
}
}
if ( v3 == 12 )
{
if ( !(unsigned __int8)equip_me(a1, 0xFFFFFFFFLL, 1LL) )
goto LABEL_6;
return 0LL;
}
if ( v3 == 13 )
{
if ( !(unsigned __int8)drop_my_item(a1, a2, 0xFFFFFFFFLL, 1LL) )
goto LABEL_6;
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
int v3; // eax
bool v4; // cc

v3 = a3;
if ( (unsigned int)(a3 - 12) > 3 )
goto LABEL_6;
v4 = a3 <= 14;
if ( a3 == 14 )
goto LABEL_8;
while ( !v4 )
{
if ( v3 != 15 )
return 1LL;
if ( (unsigned __int8)destroy_my_item(a1, 0xFFFFFFFFLL, 1LL) )
return 0LL;
while ( 1 )
{
do
LABEL_6:
v3 = func1();
while ( !v3 );
v4 = v3 <= 14;
if ( v3 != 14 )
break;
LABEL_8:
if ( (unsigned __int8)unequip_me(a1, 0xFFFFFFFFLL, 1LL) )
return 0LL;
}
}
if ( v3 == 12 )
{
if ( !(unsigned __int8)equip_me(a1, 0xFFFFFFFFLL, 1LL) )
goto LABEL_6;
return 0LL;
}
if ( v3 == 13 )
{
if ( !(unsigned __int8)drop_my_item(a1, a2, 0xFFFFFFFFLL, 1LL) )
goto LABEL_6;
return 0LL;
}
return 1LL;
}

original_code:
static _Bool manage_inventory( PLAYER * pc, LOC * active_loc, int cmd )
{
    _Bool done_with_sub = 0;
    while( done_with_sub == 0) {
        if( ( cmd > 11 )&&( cmd <= 15 ) );
        else while( ( cmd = get_subi_cmd() ) == 0 );
        switch( cmd ) {
            case 12: done_with_sub = equip_me(pc,-1,1); break;
            case 13: done_with_sub = drop_my_item(pc,active_loc,-1,1); break;
            case 14: done_with_sub = unequip_me(pc,-1,1); break;
            case 15: done_with_sub = destroy_my_item(pc,-1,1); break;
            default: return 1;
        }
        cmd = 0;
    }
    return 0;
}

canonical_original_code:
static _Bool manage_inventory(struct PLAYER *pc, struct LOC *active_loc, int cmd)
{
    _Bool done_with_sub = 0;
    while( done_with_sub == 0) {
        if( ( cmd > 11 )&&( cmd <= 15 ) );
        else while( ( cmd = get_subi_cmd() ) == 0 );
        switch( cmd ) {
            case 12: done_with_sub = equip_me(pc,-1,1); break;
            case 13: done_with_sub = drop_my_item(pc,active_loc,-1,1); break;
            case 14: done_with_sub = unequip_me(pc,-1,1); break;
            case 15: done_with_sub = destroy_my_item(pc,-1,1); break;
            default: return 1;
        }
        cmd = 0;
    }
    return 0;
}

variable_types: struct PLAYER { char name[-1]; int stats[6]; struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *

variable_types: struct LOC { struct ITEM *litter; struct PLAYER *mon; char icon; _Bool is_trap; } *

variable_types: cmd int


repo: moorescloud/secretapi

decompiled_code:
void gpio_map()
{
int v0; // ebp

if ( !gpio_mmap )
{
v0 = open("/dev/mem", 2);
if ( v0 < 0 )
{
v0 = 0;
perror("Unable to open /dev/mem");
}
gpio_mmap = (__int64)mmap(0LL, 0xFFFuLL, 3, 1, v0, 2147581952LL);
if ( (_DWORD)gpio_mmap == -1 )
{
perror("Unable to mmap file");
gpio_mmap = 0LL;
}
if ( close(v0) == -1 )
perror("Couldn't close file");
}
}

canonical_decompiled_code:
void func10()
{
int v0; // ebp

if ( !gpio_mmap )
{
v0 = open("/dev/mem", 2);
if ( v0 < 0 )
{
v0 = 0;
perror("Unable to open /dev/mem");
}
gpio_mmap = (__int64)mmap(0LL, 0xFFFuLL, 3, 1, v0, 2147581952LL);
if ( (_DWORD)gpio_mmap == -1 )
{
perror("Unable to mmap file");
gpio_mmap = 0LL;
}
if ( close(v0) == -1 )
perror("Couldn't close file");
}
}

original_code:
int *gpio_map() {
 int fd;
 if (gpio_mmap != 0) return;
 fd = open("/dev/mem", 02);
 if( fd < 0 ) {
  perror("Unable to open /dev/mem");
  fd = 0;
 }
 gpio_mmap = mmap(0, 0xfff, 0x1|0x2, 0x01, fd, 0x80018000);
 if( -1 == (int)gpio_mmap) {
  perror("Unable to mmap file");
  gpio_mmap = 0;
 }
 if( -1 == close(fd))
  perror("Couldn't close file");
 fd=0;
}

variable_types: fd int

return_type: int *


decompiled_code:
__int64 __fastcall gpio_rd(__int64 a1)
{
__int64 v2; // rdi

v2 = a1 + 3;
if ( a1 >= 0 )
v2 = a1;
return *(unsigned int *)(gpio_mmap + 4 * (v2 >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v2; // rdi

v2 = a1 + 3;
if ( a1 >= 0 )
v2 = a1;
return *(unsigned int *)(gpio_mmap + 4 * (v2 >> 2));
}

original_code:
int gpio_rd(long offset) {
 return gpio_mmap[offset/4];
}

variable_types: offset long


decompiled_code:
__int64 __fastcall gpio_output(int a1, char a2)
{
__int64 result; // rax

result = 4 * a1 + 449;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, char a2)
{
__int64 result; // rax

result = 4 * a1 + 449;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

original_code:
void gpio_output(int bank, int pin) {
 gpio_mmap[0x1C1 + (bank*4)] = 1 << pin;
}

variable_types: bank int

variable_types: pin int


decompiled_code:
__int64 __fastcall gpio_input(int a1, char a2)
{
__int64 result; // rax

result = 4 * a1 + 450;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, char a2)
{
__int64 result; // rax

result = 4 * a1 + 450;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

original_code:
void gpio_input(int bank, int pin) {
 gpio_mmap[0x1C2 + (bank*4)] = 1 << pin;
}


decompiled_code:
__int64 spi_open()
{
__int64 v0; // rax

gpio_map();
v0 = gpio_mmap;
*(_QWORD *)(gpio_mmap + 1284) = 0x100000000080000LL;
*(_DWORD *)(v0 + 1320) = 2;
gpio_input(0, 0);
gpio_output(0, 16);
gpio_output(0, 19);
gpio_output(0, 20);
gpio_input(0, 23);
gpio_output(0, 24);
return gpio_output(2, 1);
}


decompiled_code:
void spi_close()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void spi_close()
{
}

canonical_original_code:
void spi_close()
{
}


diep

decompiled_code:
void __fastcall __noreturn diep(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func17(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void diep(char *s)
{
    perror(s);
    exit(1);
}

variable_types:
s
char *


render

decompiled_code:
// attributes: thunk
__int64 __fastcall render(__int64 a1)
{
return spi_send_constprop_0(a1);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return func8(a1);
}

original_code:
void render(char* buf) {
int j, k;
char* obf;
    obf = &buf[10];
    spi_send(obf, 150);
    return;
}

canonical_original_code:
void render(char *buf) {
int j; int k;
char *obf;
    obf = &buf[10];
    spi_send(obf, 150);
    return;
}

variable_types:
buf
char *

variable_types: j int

variable_types: k int

variable_types:
obf
char *


constant

decompiled_code:
double __fastcall constant(__int64 a1)
{
return *(double *)(a1 + 8);
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
return *(double *)(a1 + 8);
}

original_code:
double
constant(distn *d)
{
    return (d->mean);
}

canonical_original_code:
double constant(struct _distn *d)
{
    return (d->mean);
}

variable_types: struct _distn { double (*function)(struct _distn *distribution); double mean; double shape; } *

return_type: double


expon

decompiled_code:
double __fastcall expon(__int64 a1)
{
double v1; // xmm0_8

v1 = drand48();
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(v1)) ^ LC0) * *(double *)(a1 + 8);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
double v1; // xmm0_8

v1 = drand48();
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(v1)) ^ LC0) * *(double *)(a1 + 8);
}

original_code:
double
expon(distn *d)
{
    double r = (double) drand48();
    double val = -log(r) * d->mean;
    return (val);
}

canonical_original_code:
double expon(struct _distn *d)
{
    double r = (double) drand48();
    double val = -log(r) * d->mean;
    return (val);
}

variable_types: r double

variable_types: val double

user_defined_types: struct _distn { double (*function)(struct _distn *distribution); double mean; double shape; }


paretoon

decompiled_code:
double __fastcall paretoon(__int64 a1)
{
double v1; // xmm0_8
double v3; // [rsp+8h] [rbp-10h]

v1 = drand48();
v3 = *(double *)(a1 + 8);
return 1.0 / pow(v1, 1.0 / *(double *)(a1 + 16)) * v3;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
double v1; // xmm0_8
double v3; // [rsp+8h] [rbp-10h]

v1 = drand48();
v3 = *(double *)(a1 + 8);
return 1.0 / pow(v1, 1.0 / *(double *)(a1 + 16)) * v3;
}

original_code:
double paretoon(distn *d)
{
    double r = (double) drand48();
    double val = (d->mean * (1.0/pow(r, 1.0/d->shape)));
    return (val);
}

canonical_original_code:
double paretoon(struct _distn *d)
{
    double r = (double) drand48();
    double val = (d->mean * (1.0/pow(r, 1.0/d->shape)));
    return (val);
}


decompiled_code:
__int64 __fastcall parse_distn(double (__fastcall **a1)(__int64 a1), int *a2, __int64 a3, int a4)
{
__int64 v4; // r15
int v7; // er14
const char *v8; // rbp
const char *v9; // rsi
unsigned int v10; // er8
double (__fastcall **v11)(__int64); // rax
int v12; // eax
int v14; // eax
int v15; // eax
__int64 v16; // [rsp+10h] [rbp-48h]
int v17; // [rsp+18h] [rbp-40h]

v4 = 0LL;
v7 = *a2 - 1;
v17 = *a2;
v8 = *(const char **)(a3 + 8LL * v7);
*a2 = v7;
v9 = "constant";
v16 = 8LL * v7;
while ( strncmp(v8, v9, 0xFFuLL) )
{
if ( ++v4 == 3 )
goto LABEL_16;
v9 = (&Distn_Function_Type)[v4];
}
if ( (_DWORD)v4 == 1 )
{
if ( a4 - v7 <= 1 )
{
fprintf(stderr, "%s: exponent requries one argument (mean)\n", "parse_distn");
return (unsigned int)-1;
}
v11 = a1;
*a1 = expon;
*a2 = v17;
LABEL_13:
v12 = _isoc99_sscanf(*(_QWORD *)(a3 + v16 + 8), "%lg", v11 + 1);
v10 = 0;
if ( v12 != 1 )
{
fprintf(stderr, "%s: bad constant %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}
LABEL_14:
++*a2;
return v10;
}
if ( (_DWORD)v4 != 2 )
{
if ( (_DWORD)v4 )
{
LABEL_16:
fprintf(stderr, "%s: unknown distribution type %s\n", "parse_distn", v8);
v10 = -1;
goto LABEL_14;
}
if ( a4 - v7 <= 1 )
{
fprintf(stderr, "%s: constant requries one argument\n", "parse_distn");
return (unsigned int)-1;
}
v11 = a1;
*a1 = constant;
*a2 = v17;
goto LABEL_13;
}
if ( a4 - v7 <= 2 )
{
fprintf(stderr, "%s: pareto requries two arguments (mean and shape)\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = paretoon;
*a2 = v17;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + v16 + 8), "%lg", a1 + 1) != 1 )
{
fprintf(stderr, "%s: bad mean %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}
v14 = *a2 + 1;
*a2 = v14;
v15 = _isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v14), "%lg", a1 + 2);
v10 = 0;
if ( v15 == 1 )
goto LABEL_14;
fprintf(stderr, "%s: bad shape %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(double (__fastcall **a1)(__int64 a1), int *a2, __int64 a3, int a4)
{
__int64 v4; // r15
int v7; // er14
const char *v8; // rbp
const char *v9; // rsi
unsigned int v10; // er8
double (__fastcall **v11)(__int64); // rax
int v12; // eax
int v14; // eax
int v15; // eax
__int64 v16; // [rsp+10h] [rbp-48h]
int v17; // [rsp+18h] [rbp-40h]

v4 = 0LL;
v7 = *a2 - 1;
v17 = *a2;
v8 = *(const char **)(a3 + 8LL * v7);
*a2 = v7;
v9 = "constant";
v16 = 8LL * v7;
while ( strncmp(v8, v9, 0xFFuLL) )
{
if ( ++v4 == 3 )
goto LABEL_16;
v9 = (&Distn_Function_Type)[v4];
}
if ( (_DWORD)v4 == 1 )
{
if ( a4 - v7 <= 1 )
{
fprintf(stderr, "%s: exponent requries one argument (mean)\n", "parse_distn");
return (unsigned int)-1;
}
v11 = a1;
*a1 = expon;
*a2 = v17;
LABEL_13:
v12 = _isoc99_sscanf(*(_QWORD *)(a3 + v16 + 8), "%lg", v11 + 1);
v10 = 0;
if ( v12 != 1 )
{
fprintf(stderr, "%s: bad constant %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}
LABEL_14:
++*a2;
return v10;
}
if ( (_DWORD)v4 != 2 )
{
if ( (_DWORD)v4 )
{
LABEL_16:
fprintf(stderr, "%s: unknown distribution type %s\n", "parse_distn", v8);
v10 = -1;
goto LABEL_14;
}
if ( a4 - v7 <= 1 )
{
fprintf(stderr, "%s: constant requries one argument\n", "parse_distn");
return (unsigned int)-1;
}
v11 = a1;
*a1 = constant;
*a2 = v17;
goto LABEL_13;
}
if ( a4 - v7 <= 2 )
{
fprintf(stderr, "%s: pareto requries two arguments (mean and shape)\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = paretoon;
*a2 = v17;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + v16 + 8), "%lg", a1 + 1) != 1 )
{
fprintf(stderr, "%s: bad mean %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}
v14 = *a2 + 1;
*a2 = v14;
v15 = _isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v14), "%lg", a1 + 2);
v10 = 0;
if ( v15 == 1 )
goto LABEL_14;
fprintf(stderr, "%s: bad shape %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}

original_code:
int
parse_distn(distn *distribution, int *optind, char **argv, int argc)
{
    int rv=0,rc;
    int theType;
    (*optind)--;
    for(theType=0; theType < Distn_Function_nTypes; theType++)
    {
        if(!strncmp(argv[*optind], Distn_Function_Type[theType], 255))
            break;
    }
    switch(theType)
    {
        case Distn_Function_Constant:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: constant requries one argument\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = constant;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Exponent:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: exponent requries one argument (mean)\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = expon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Pareto:
        {
            if((argc - *optind) < 3)
            {
                fprintf(stderr,
                        "%s: pareto requries two arguments (mean and shape)\n",
                        __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = paretoon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad mean %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->shape);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad shape %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        default:
            fprintf(stderr,
                    "%s: unknown distribution type %s\n",
                    __FUNCTION__, argv[*optind]);
            rv = -1;
    }
    (*optind)++;
abort:
    return rv;
}

canonical_original_code:
int parse_distn(struct _distn *distribution, int *optind, char **argv, int argc)
{
    int rv = 0; int rc;
    int theType;
    (*optind)--;
    for(theType=0; theType < Distn_Function_nTypes; theType++)
    {
        if(!strncmp(argv[*optind], Distn_Function_Type[theType], 255))
            break;
    }
    switch(theType)
    {
        case Distn_Function_Constant:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: constant requries one argument\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = constant;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Exponent:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: exponent requries one argument (mean)\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = expon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Pareto:
        {
            if((argc - *optind) < 3)
            {
                fprintf(stderr,
                        "%s: pareto requries two arguments (mean and shape)\n",
                        __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = paretoon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad mean %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->shape);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad shape %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        default:
            fprintf(stderr,
                    "%s: unknown distribution type %s\n",
                    __FUNCTION__, argv[*optind]);
            rv = -1;
    }
    (*optind)++;
abort:
    return rv;
}

variable_types:
optind
int *

variable_types:
argv
char **

variable_types: argc int

variable_types: rv int

variable_types: rc int

variable_types: theType int


decompiled_code:
void __fastcall __noreturn surge_client(int a1, __int64 a2, int a3, unsigned int a4, __m128 a5)
{
int v5; // ebx
__int64 v6; // rax
char *v7; // rbp
double v8; // xmm0_8
int v9; // edx
int v10; // eax
int v11; // er13
__int64 v12; // rdi
__m128 v13; // xmm1
int v14; // eax
int v15; // ecx
int v16; // eax
int v17; // edx
int v18; // eax
int v19; // er13
__int64 v20; // rbx
__int64 v21; // r12
char *v22; // rbp
char *v23; // r12
char *v24; // r12
int v25; // eax
int v26; // ebp
__int64 i; // rdi
__int64 v28; // rax
__int64 v29; // rdx
signed int v30; // er12
double v31; // rbx
int v32; // eax
int v33; // ebp
int v34; // ebp
int v35; // ebp
int v36; // ebp
__int64 v37; // rbp
__int64 v38; // r13
unsigned int v39; // ebx
unsigned int v40; // eax
__int64 j; // rdi
int v42; // edx
char *v43; // rax
int v44; // er12
int v45; // eax
__int64 v46; // r13
int v47; // ebx
int v49; // [rsp+0h] [rbp-318h]
unsigned int v50; // [rsp+0h] [rbp-318h]
int v51; // [rsp+8h] [rbp-310h]
unsigned int v52; // [rsp+8h] [rbp-310h]
int v53; // [rsp+10h] [rbp-308h]
__int64 v55; // [rsp+28h] [rbp-2F0h]
__int64 v56; // [rsp+30h] [rbp-2E8h] BYREF
__int64 v57; // [rsp+38h] [rbp-2E0h]
struct timeval tv; // [rsp+40h] [rbp-2D8h] BYREF
struct timeval timeout; // [rsp+50h] [rbp-2C8h] BYREF
__int64 v60[16]; // [rsp+60h] [rbp-2B8h] BYREF
char v61[128]; // [rsp+E0h] [rbp-238h] BYREF
__int64 v62[16]; // [rsp+160h] [rbp-1B8h] BYREF
__int64 v63[16]; // [rsp+1E0h] [rbp-138h] BYREF
__int64 v64[23]; // [rsp+260h] [rbp-B8h] BYREF

v56 = 0LL;
v57 = 0LL;
v55 = host2ipaddr(a2);
memset(v60, 0, sizeof(v60));
memset(v61, 0, sizeof(v61));
memset(v62, 0, sizeof(v62));
memset(v63, 0, sizeof(v63));
memset(v64, 0, 0x80uLL);
if ( a1 > 0 )
{
v5 = 0;
do
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v10 = create_tx_tcp(v55, v5 % a3 + a4);
v11 = v10;
if ( v10 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
exit(-1);
}
if ( maxfd < v10 )
maxfd = v10;
v6 = 40LL * v10;
v7 = (char *)&state[v6];
state[v6 + 34] = v11;
*((_DWORD *)v7 + 35) = (int)objperpage(&objperpage);
v8 = objsize(&objsize);
*((_QWORD *)v7 + 5) = 0LL;
v9 = (int)v8;
*((_DWORD *)v7 + 23) = 0;
if ( (int)v8 <= 0 )
v9 = 1;
++v5;
*((_DWORD *)v7 + 9) = v9;
v60[v11 >> 6] |= 1LL << v11;
timeout.tv_usec = (int)(drand48() * 10000.0);
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
while ( a1 != v5 );
}
while ( 1 )
{
while ( 1 )
{
send_request(v60, v61);
v12 = 0LL;
if ( (int)sink_data(v61, v62) > 0 )
{
while ( 1 )
{
v18 = FD_FFSandC(v12, maxfd, v62);
v19 = v18;
if ( !v18 )
break;
v20 = v18;
v21 = 40LL * v18;
v22 = (char *)&state[v21 + 30];
tvsub(&timeout, v22, &state[v21 + 26]);
v23 = (char *)&state[v21];
v49 = state[40 * v19 + 23];
v51 = timeout.tv_sec;
v53 = timeout.tv_usec;
gettimeofday(&tv, 0LL);
if ( verbose )
{
a5 = 0LL;
fprintf(
stderr,
"%d.%06d Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
(unsigned int)v19,
*((unsigned int *)v23 + 23),
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)v49 * 8.0 / ((double)v51 * 1000000.0 + (double)v53) / scalar);
}
close(v19);
v24 = (char *)&state[40 * v20];
v25 = *((_DWORD *)v24 + 35);
*((_DWORD *)v24 + 8) = 0;
*((_DWORD *)v24 + 35) = --v25;
if ( v25 > 0 )
{
*(double *)a5.m128_u64 = interobj(&interobj);
v13 = a5;
}
else
{
v13 = (__m128)COERCE_UNSIGNED_INT64(interpage(&interpage));
*((_DWORD *)v24 + 35) = (int)objperpage(&objperpage);
}
*(double *)v13.m128_u64 = *(double *)v13.m128_u64 * scalar;
a5.m128_u64[1] = v13.m128_u64[1];
v56 = (int)*(double *)v13.m128_u64;
v57 = (int)((*(double *)v13.m128_u64 - (double)(int)*(double *)v13.m128_u64) * 1000000.0);
tvadd(&state[40 * state[40 * v19 + 34] + 36], v22, &v56);
if ( verbose )
printf(
"(%d): time_us %d.%06d opp %d\n",
433LL,
(unsigned int)v56,
(unsigned int)v57,
(unsigned int)state[40 * v19 + 35]);
v14 = v19 + 63;
v12 = (unsigned int)(v19 + 1);
if ( v19 >= 0 )
v14 = v19;
v62[v14 >> 6] &= ~(1LL << (v19 % 64));
v15 = state[40 * v19 + 34];
v16 = v15 + 63;
if ( v15 >= 0 )
v16 = state[40 * v19 + 34];
v17 = state[40 * v19 + 34];
v63[v16 >> 6] |= 1LL << (((((unsigned int)(v17 >> 31) >> 26) + v15) & 0x3F) - ((unsigned int)(v17 >> 31) >> 26));
}
}
v26 = 0;
for ( i = 0LL; ; i = (unsigned int)(v30 + 1) )
{
v30 = FD_FFS(i, maxfd, v63);
if ( !v30 )
break;
gettimeofday(&tv, 0LL);
if ( (unsigned int)tveqless(&state[40 * v30 + 36], &tv) )
{
if ( state[40 * v30 + 35] > 0 )
{
++v26;
v28 = v30 / 64;
v29 = 1LL << (v30 % 64);
v64[v28] |= v29;
v63[v28] &= ~v29;
}
else
{
v31 = interpage(&interpage);
v32 = (int)objperpage(&objperpage);
a5 = (__m128)*(unsigned __int64 *)&v31;
*(double *)a5.m128_u64 = v31 * scalar;
state[35] = v32;
v56 = (int)*(double *)a5.m128_u64;
v57 = (int)((*(double *)a5.m128_u64 - (double)(int)*(double *)a5.m128_u64) * 1000000.0);
tvadd(&state[40 * state[34] + 36], (unsigned int)((_DWORD)state + 120), &v56);
}
}
}
if ( verbose )
break;
if ( v26 )
goto LABEL_35;
}
if ( v26 )
{
v33 = FD_POP(maxfd, v60);
v34 = FD_POP(maxfd, v61) + v33;
v35 = FD_POP(maxfd, v62) + v34;
v36 = FD_POP(maxfd, v63) + v35;
v50 = v36 + FD_POP(maxfd, v64);
v52 = FD_POP(maxfd, v64);
v37 = (unsigned int)FD_POP(maxfd, v63);
v38 = (unsigned int)FD_POP(maxfd, v62);
v39 = FD_POP(maxfd, v61);
v40 = FD_POP(maxfd, v60);
fprintf(
stdout,
"%d.%06d %d %d %d %d %d (%d)\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
v40,
v39,
v38,
v37,
v52,
v50);
LABEL_35:
for ( j = (unsigned int)v30; ; j = (unsigned int)(v44 + 1) )
{
v44 = FD_FFSandC(j, maxfd, v64);
if ( !v44 )
break;
v45 = create_tx_tcp(v55, a4);
v46 = v45;
v47 = v45;
state[40 * v45 + 34] = v44;
if ( v45 >= 0 )
{
if ( maxfd < v45 )
maxfd = v45;
v42 = (int)objsize(&objsize);
v43 = (char *)&state[40 * v46];
*((_DWORD *)v43 + 23) = 0;
if ( v42 <= 0 )
v42 = 1;
*((_DWORD *)v43 + 9) = v42;
v60[v47 >> 6] |= 1LL << v47;
}
else
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int a1, __int64 a2, int a3, unsigned int a4, __m128 a5)
{
int v5; // ebx
__int64 v6; // rax
char *v7; // rbp
double v8; // xmm0_8
int v9; // edx
int v10; // eax
int v11; // er13
__int64 v12; // rdi
__m128 v13; // xmm1
int v14; // eax
int v15; // ecx
int v16; // eax
int v17; // edx
int v18; // eax
int v19; // er13
__int64 v20; // rbx
__int64 v21; // r12
char *v22; // rbp
char *v23; // r12
char *v24; // r12
int v25; // eax
int v26; // ebp
__int64 i; // rdi
__int64 v28; // rax
__int64 v29; // rdx
signed int v30; // er12
double v31; // rbx
int v32; // eax
int v33; // ebp
int v34; // ebp
int v35; // ebp
int v36; // ebp
__int64 v37; // rbp
__int64 v38; // r13
unsigned int v39; // ebx
unsigned int v40; // eax
__int64 j; // rdi
int v42; // edx
char *v43; // rax
int v44; // er12
int v45; // eax
__int64 v46; // r13
int v47; // ebx
int v49; // [rsp+0h] [rbp-318h]
unsigned int v50; // [rsp+0h] [rbp-318h]
int v51; // [rsp+8h] [rbp-310h]
unsigned int v52; // [rsp+8h] [rbp-310h]
int v53; // [rsp+10h] [rbp-308h]
__int64 v55; // [rsp+28h] [rbp-2F0h]
__int64 v56; // [rsp+30h] [rbp-2E8h] BYREF
__int64 v57; // [rsp+38h] [rbp-2E0h]
struct timeval tv; // [rsp+40h] [rbp-2D8h] BYREF
struct timeval timeout; // [rsp+50h] [rbp-2C8h] BYREF
__int64 v60[16]; // [rsp+60h] [rbp-2B8h] BYREF
char v61[128]; // [rsp+E0h] [rbp-238h] BYREF
__int64 v62[16]; // [rsp+160h] [rbp-1B8h] BYREF
__int64 v63[16]; // [rsp+1E0h] [rbp-138h] BYREF
__int64 v64[23]; // [rsp+260h] [rbp-B8h] BYREF

v56 = 0LL;
v57 = 0LL;
v55 = host2ipaddr(a2);
memset(v60, 0, sizeof(v60));
memset(v61, 0, sizeof(v61));
memset(v62, 0, sizeof(v62));
memset(v63, 0, sizeof(v63));
memset(v64, 0, 0x80uLL);
if ( a1 > 0 )
{
v5 = 0;
do
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v10 = create_tx_tcp(v55, v5 % a3 + a4);
v11 = v10;
if ( v10 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
exit(-1);
}
if ( maxfd < v10 )
maxfd = v10;
v6 = 40LL * v10;
v7 = (char *)&state[v6];
state[v6 + 34] = v11;
*((_DWORD *)v7 + 35) = (int)objperpage(&objperpage);
v8 = objsize(&objsize);
*((_QWORD *)v7 + 5) = 0LL;
v9 = (int)v8;
*((_DWORD *)v7 + 23) = 0;
if ( (int)v8 <= 0 )
v9 = 1;
++v5;
*((_DWORD *)v7 + 9) = v9;
v60[v11 >> 6] |= 1LL << v11;
timeout.tv_usec = (int)(drand48() * 10000.0);
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
while ( a1 != v5 );
}
while ( 1 )
{
while ( 1 )
{
send_request(v60, v61);
v12 = 0LL;
if ( (int)sink_data(v61, v62) > 0 )
{
while ( 1 )
{
v18 = FD_FFSandC(v12, maxfd, v62);
v19 = v18;
if ( !v18 )
break;
v20 = v18;
v21 = 40LL * v18;
v22 = (char *)&state[v21 + 30];
tvsub(&timeout, v22, &state[v21 + 26]);
v23 = (char *)&state[v21];
v49 = state[40 * v19 + 23];
v51 = timeout.tv_sec;
v53 = timeout.tv_usec;
gettimeofday(&tv, 0LL);
if ( verbose )
{
a5 = 0LL;
fprintf(
stderr,
"%d.%06d Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
(unsigned int)v19,
*((unsigned int *)v23 + 23),
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)v49 * 8.0 / ((double)v51 * 1000000.0 + (double)v53) / scalar);
}
close(v19);
v24 = (char *)&state[40 * v20];
v25 = *((_DWORD *)v24 + 35);
*((_DWORD *)v24 + 8) = 0;
*((_DWORD *)v24 + 35) = --v25;
if ( v25 > 0 )
{
*(double *)a5.m128_u64 = interobj(&interobj);
v13 = a5;
}
else
{
v13 = (__m128)COERCE_UNSIGNED_INT64(interpage(&interpage));
*((_DWORD *)v24 + 35) = (int)objperpage(&objperpage);
}
*(double *)v13.m128_u64 = *(double *)v13.m128_u64 * scalar;
a5.m128_u64[1] = v13.m128_u64[1];
v56 = (int)*(double *)v13.m128_u64;
v57 = (int)((*(double *)v13.m128_u64 - (double)(int)*(double *)v13.m128_u64) * 1000000.0);
tvadd(&state[40 * state[40 * v19 + 34] + 36], v22, &v56);
if ( verbose )
printf(
"(%d): time_us %d.%06d opp %d\n",
433LL,
(unsigned int)v56,
(unsigned int)v57,
(unsigned int)state[40 * v19 + 35]);
v14 = v19 + 63;
v12 = (unsigned int)(v19 + 1);
if ( v19 >= 0 )
v14 = v19;
v62[v14 >> 6] &= ~(1LL << (v19 % 64));
v15 = state[40 * v19 + 34];
v16 = v15 + 63;
if ( v15 >= 0 )
v16 = state[40 * v19 + 34];
v17 = state[40 * v19 + 34];
v63[v16 >> 6] |= 1LL << (((((unsigned int)(v17 >> 31) >> 26) + v15) & 0x3F) - ((unsigned int)(v17 >> 31) >> 26));
}
}
v26 = 0;
for ( i = 0LL; ; i = (unsigned int)(v30 + 1) )
{
v30 = FD_FFS(i, maxfd, v63);
if ( !v30 )
break;
gettimeofday(&tv, 0LL);
if ( (unsigned int)tveqless(&state[40 * v30 + 36], &tv) )
{
if ( state[40 * v30 + 35] > 0 )
{
++v26;
v28 = v30 / 64;
v29 = 1LL << (v30 % 64);
v64[v28] |= v29;
v63[v28] &= ~v29;
}
else
{
v31 = interpage(&interpage);
v32 = (int)objperpage(&objperpage);
a5 = (__m128)*(unsigned __int64 *)&v31;
*(double *)a5.m128_u64 = v31 * scalar;
state[35] = v32;
v56 = (int)*(double *)a5.m128_u64;
v57 = (int)((*(double *)a5.m128_u64 - (double)(int)*(double *)a5.m128_u64) * 1000000.0);
tvadd(&state[40 * state[34] + 36], (unsigned int)((_DWORD)state + 120), &v56);
}
}
}
if ( verbose )
break;
if ( v26 )
goto LABEL_35;
}
if ( v26 )
{
v33 = FD_POP(maxfd, v60);
v34 = FD_POP(maxfd, v61) + v33;
v35 = FD_POP(maxfd, v62) + v34;
v36 = FD_POP(maxfd, v63) + v35;
v50 = v36 + FD_POP(maxfd, v64);
v52 = FD_POP(maxfd, v64);
v37 = (unsigned int)FD_POP(maxfd, v63);
v38 = (unsigned int)FD_POP(maxfd, v62);
v39 = FD_POP(maxfd, v61);
v40 = FD_POP(maxfd, v60);
fprintf(
stdout,
"%d.%06d %d %d %d %d %d (%d)\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
v40,
v39,
v38,
v37,
v52,
v50);
LABEL_35:
for ( j = (unsigned int)v30; ; j = (unsigned int)(v44 + 1) )
{
v44 = FD_FFSandC(j, maxfd, v64);
if ( !v44 )
break;
v45 = create_tx_tcp(v55, a4);
v46 = v45;
v47 = v45;
state[40 * v45 + 34] = v44;
if ( v45 >= 0 )
{
if ( maxfd < v45 )
maxfd = v45;
v42 = (int)objsize(&objsize);
v43 = (char *)&state[40 * v46];
*((_DWORD *)v43 + 23) = 0;
if ( v42 <= 0 )
v42 = 1;
*((_DWORD *)v43 + 9) = v42;
v60[v47 >> 6] |= 1LL << v47;
}
else
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
}
}
}
}
}

original_code:
void
surge_client(int n, char *host, int num_ports, int base_rx_port)
{
    int i;
    fd_set fds_new, fds_active, fds_finished, ids_sleeping, ids_want_to_run;
    unsigned long ipaddr;
    double tmbs=0;
    double time_us;
    struct timeval next_start_time = {0,0};
    struct timeval current_time;
    ipaddr = host2ipaddr(host);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_sleeping)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_want_to_run)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd;
        struct timeval tp={ 0, 0 };
        fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        if(fd < 0)
        {
            fprintf(stderr,"Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].client_id = fd;
        state[fd].object_count = objperpage.function(&objperpage);
        state[fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = (int)(drand48()*10000.0);
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s, fd, client_id, sink_data_rc, want_to_run_rc=0;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        sink_data_rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (sink_data_rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd) /
                (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            gettimeofday(&current_time,((void *)0));
            if(verbose)
                fprintf(stderr,
                        "%d.%06d Finished with %d after %d bytes. "
                        "%ld.%03lds = %.4f Mb/s.\n",
                        (int)current_time.tv_sec,(int)current_time.tv_usec,
                        fd, state[fd].rx_rcvd,
                        (long int)tdiff.tv_sec, (long int)tdiff.tv_usec/1000,
                        mbs/scalar);
            close(fd);
            state[fd].open = 0;
            state[fd].object_count--;
            if(state[fd].object_count > 0)
                time_us = interobj.function(&interobj);
            else
            {
                time_us = interpage.function(&interpage);
                state[fd].object_count = objperpage.function(&objperpage);
            }
            time_us *= scalar;
            next_start_time.tv_sec = (int) time_us;
            next_start_time.tv_usec = (int)
                ((time_us - (double)next_start_time.tv_sec)
                 * 1e6 );
            tvadd(&state[state[fd].client_id].next_start_time,&state[fd].rx_stop,
                  &next_start_time);
            if(verbose)
                printf("(%d): time_us %d.%06d opp %d\n",433,
                       (int)next_start_time.tv_sec,
                       (int)next_start_time.tv_usec,
                       state[fd].object_count);
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            ((void) (((&ids_sleeping)->__fds_bits)[((state[fd].client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((state[fd].client_id) % (8 * (int) sizeof (__fd_mask)))))));
        }
        for(s=0;(client_id = FD_FFS(s, maxfd, &ids_sleeping));
            s = client_id+1)
        {
            gettimeofday(&current_time,((void *)0));
            if(tveqless(&state[client_id].next_start_time,&current_time))
            {
                if(state[client_id].object_count > 0)
                {
                    ((void) (((&ids_sleeping)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    ((void) (((&ids_want_to_run)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    want_to_run_rc++;
                }
                else
                {
                    time_us = interpage.function(&interpage);
                    state[fd].object_count = objperpage.function(&objperpage);
                    time_us *= scalar;
                    next_start_time.tv_sec = (int) time_us;
                    next_start_time.tv_usec = (int)
                        ((time_us - (double)next_start_time.tv_sec)
                         * 1e6 );
                    tvadd(&state[state[fd].client_id].next_start_time,
                          &state[fd].rx_stop,
                          &next_start_time);
                }
            }
        }
        if(verbose && want_to_run_rc>0)
        {
            fprintf(stdout,"%d.%06d %d %d %d %d %d (%d)\n",
                    (int)current_time.tv_sec,(int)current_time.tv_usec,
                    FD_POP(maxfd,&fds_new),
                    FD_POP(maxfd,&fds_active),
                    FD_POP(maxfd,&fds_finished),
                    FD_POP(maxfd,&ids_sleeping),
                    FD_POP(maxfd,&ids_want_to_run),
                    (FD_POP(maxfd,&fds_new)+
                     FD_POP(maxfd,&fds_active)+
                     FD_POP(maxfd,&fds_finished)+
                     FD_POP(maxfd,&ids_sleeping)+
                     FD_POP(maxfd,&ids_want_to_run)));
        }
        for(s = 0;
            ((want_to_run_rc>0)
             && (client_id = FD_FFSandC(s, maxfd, &ids_want_to_run)));
            s = client_id+1)
        {
            int new_fd;
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            state[new_fd].client_id=client_id;
            if(new_fd < 0)
            {
                fprintf(stderr,"Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

canonical_original_code:
void surge_client(int n, char *host, int num_ports, int base_rx_port)
{
    int i;
    struct fd_set fds_new; struct fd_set fds_active; struct fd_set fds_finished; struct fd_set ids_sleeping; struct fd_set ids_want_to_run;
    unsigned long ipaddr;
    double tmbs = 0;
    double time_us;
    struct timeval next_start_time = {0,0};
    struct timeval current_time;
    ipaddr = host2ipaddr(host);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_sleeping)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_want_to_run)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd;
        struct timeval tp = { 0, 0 };
        fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        if(fd < 0)
        {
            fprintf(stderr,"Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].client_id = fd;
        state[fd].object_count = objperpage.function(&objperpage);
        state[fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = (int)(drand48()*10000.0);
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s; int fd; int client_id; int sink_data_rc; int want_to_run_rc = 0;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        sink_data_rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (sink_data_rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd) /
                (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            gettimeofday(&current_time,((void *)0));
            if(verbose)
                fprintf(stderr,
                        "%d.%06d Finished with %d after %d bytes. "
                        "%ld.%03lds = %.4f Mb/s.\n",
                        (int)current_time.tv_sec,(int)current_time.tv_usec,
                        fd, state[fd].rx_rcvd,
                        (long)tdiff.tv_sec, (long)tdiff.tv_usec/1000,
                        mbs/scalar);
            close(fd);
            state[fd].open = 0;
            state[fd].object_count--;
            if(state[fd].object_count > 0)
                time_us = interobj.function(&interobj);
            else
            {
                time_us = interpage.function(&interpage);
                state[fd].object_count = objperpage.function(&objperpage);
            }
            time_us *= scalar;
            next_start_time.tv_sec = (int) time_us;
            next_start_time.tv_usec = (int)
                ((time_us - (double)next_start_time.tv_sec)
                 * 1e6 );
            tvadd(&state[state[fd].client_id].next_start_time,&state[fd].rx_stop,
                  &next_start_time);
            if(verbose)
                printf("(%d): time_us %d.%06d opp %d\n",433,
                       (int)next_start_time.tv_sec,
                       (int)next_start_time.tv_usec,
                       state[fd].object_count);
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            ((void) (((&ids_sleeping)->__fds_bits)[((state[fd].client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((state[fd].client_id) % (8 * (int) sizeof (__fd_mask)))))));
        }
        for(s=0;(client_id = FD_FFS(s, maxfd, &ids_sleeping));
            s = client_id+1)
        {
            gettimeofday(&current_time,((void *)0));
            if(tveqless(&state[client_id].next_start_time,&current_time))
            {
                if(state[client_id].object_count > 0)
                {
                    ((void) (((&ids_sleeping)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    ((void) (((&ids_want_to_run)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    want_to_run_rc++;
                }
                else
                {
                    time_us = interpage.function(&interpage);
                    state[fd].object_count = objperpage.function(&objperpage);
                    time_us *= scalar;
                    next_start_time.tv_sec = (int) time_us;
                    next_start_time.tv_usec = (int)
                        ((time_us - (double)next_start_time.tv_sec)
                         * 1e6 );
                    tvadd(&state[state[fd].client_id].next_start_time,
                          &state[fd].rx_stop,
                          &next_start_time);
                }
            }
        }
        if(verbose && want_to_run_rc>0)
        {
            fprintf(stdout,"%d.%06d %d %d %d %d %d (%d)\n",
                    (int)current_time.tv_sec,(int)current_time.tv_usec,
                    FD_POP(maxfd,&fds_new),
                    FD_POP(maxfd,&fds_active),
                    FD_POP(maxfd,&fds_finished),
                    FD_POP(maxfd,&ids_sleeping),
                    FD_POP(maxfd,&ids_want_to_run),
                    (FD_POP(maxfd,&fds_new)+
                     FD_POP(maxfd,&fds_active)+
                     FD_POP(maxfd,&fds_finished)+
                     FD_POP(maxfd,&ids_sleeping)+
                     FD_POP(maxfd,&ids_want_to_run)));
        }
        for(s = 0;
            ((want_to_run_rc>0)
             && (client_id = FD_FFSandC(s, maxfd, &ids_want_to_run)));
            s = client_id+1)
        {
            int new_fd;
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            state[new_fd].client_id=client_id;
            if(new_fd < 0)
            {
                fprintf(stderr,"Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

variable_types: n int

variable_types:
host
char *

variable_types: i int

variable_types:
ipaddr
unsigned long

variable_types: tmbs double

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: fd int

variable_types: s int

variable_types: mbs double


decompiled_code:
void __fastcall __noreturn continuous_client(int a1, int a2, __int64 a3, int a4, int a5)
{
__int64 v5; // r14
int v6; // er15
__int64 v7; // rax
int v8; // eax
int v9; // ecx
int v10; // eax
__int64 v11; // rsi
__int64 v12; // rdi
int v13; // eax
int v14; // er15
int v15; // eax
__int64 v16; // [rsp+8h] [rbp-1E0h]
struct timeval timeout; // [rsp+20h] [rbp-1C8h] BYREF
__int64 v20[16]; // [rsp+30h] [rbp-1B8h] BYREF
char v21[128]; // [rsp+B0h] [rbp-138h] BYREF
__int64 v22[23]; // [rsp+130h] [rbp-B8h] BYREF

v5 = host2ipaddr(a3);
memset(v20, 0, sizeof(v20));
memset(v21, 0, sizeof(v21));
memset(v22, 0, 0x80uLL);
v6 = 0;
if ( a1 > 0 )
{
do
{
v8 = create_tx_tcp(v5, (unsigned int)(v6 % a4 + a5));
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v9 = v8;
if ( v8 < 0 )
{
puts("Unable to open connection!");
exit(-1);
}
if ( maxfd < v8 )
maxfd = v8;
++v6;
v7 = 40LL * v8;
state[v7 + 9] = a2;
*(_QWORD *)&state[v7 + 10] = 0LL;
state[v7 + 23] = 0;
v20[v9 >> 6] |= 1LL << v9;
timeout.tv_usec = rand() % 10000;
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
while ( a1 != v6 );
}
while ( 1 )
{
do
{
send_request(v20, v21);
v10 = sink_data(v21, v22);
v11 = maxfd;
v12 = 0LL;
}
while ( v10 <= 0 );
while ( 1 )
{
v13 = FD_FFSandC(v12, v11, v22);
v14 = v13;
if ( !v13 )
break;
v16 = 40LL * v13;
tvsub(&timeout, &state[v16 + 30], &state[v16 + 26]);
fprintf(
stderr,
"Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
(unsigned int)v14,
(unsigned int)state[v16 + 23],
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)(int)state[v16 + 23]
* 8.0
/ ((double)SLODWORD(timeout.tv_sec) * 1000000.0 + (double)SLODWORD(timeout.tv_usec))
/ scalar);
close(v14);
state[v16 + 8] = 0;
v22[v14 / 64] &= __ROL8__(-2LL, v14 % 64);
v15 = create_tx_tcp(v5, (unsigned int)(v14 % a4 + a5));
if ( v15 >= 0 )
{
v11 = maxfd;
if ( maxfd < v15 )
{
maxfd = v15;
v11 = (unsigned int)v15;
}
state[40 * v15 + 23] = 0;
v20[v15 >> 6] |= 1LL << v15;
}
else
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
v11 = maxfd;
}
v12 = (unsigned int)(v14 + 1);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1, int a2, __int64 a3, int a4, int a5)
{
__int64 v5; // r14
int v6; // er15
__int64 v7; // rax
int v8; // eax
int v9; // ecx
int v10; // eax
__int64 v11; // rsi
__int64 v12; // rdi
int v13; // eax
int v14; // er15
int v15; // eax
__int64 v16; // [rsp+8h] [rbp-1E0h]
struct timeval timeout; // [rsp+20h] [rbp-1C8h] BYREF
__int64 v20[16]; // [rsp+30h] [rbp-1B8h] BYREF
char v21[128]; // [rsp+B0h] [rbp-138h] BYREF
__int64 v22[23]; // [rsp+130h] [rbp-B8h] BYREF

v5 = host2ipaddr(a3);
memset(v20, 0, sizeof(v20));
memset(v21, 0, sizeof(v21));
memset(v22, 0, 0x80uLL);
v6 = 0;
if ( a1 > 0 )
{
do
{
v8 = create_tx_tcp(v5, (unsigned int)(v6 % a4 + a5));
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v9 = v8;
if ( v8 < 0 )
{
puts("Unable to open connection!");
exit(-1);
}
if ( maxfd < v8 )
maxfd = v8;
++v6;
v7 = 40LL * v8;
state[v7 + 9] = a2;
*(_QWORD *)&state[v7 + 10] = 0LL;
state[v7 + 23] = 0;
v20[v9 >> 6] |= 1LL << v9;
timeout.tv_usec = rand() % 10000;
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
while ( a1 != v6 );
}
while ( 1 )
{
do
{
send_request(v20, v21);
v10 = sink_data(v21, v22);
v11 = maxfd;
v12 = 0LL;
}
while ( v10 <= 0 );
while ( 1 )
{
v13 = FD_FFSandC(v12, v11, v22);
v14 = v13;
if ( !v13 )
break;
v16 = 40LL * v13;
tvsub(&timeout, &state[v16 + 30], &state[v16 + 26]);
fprintf(
stderr,
"Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
(unsigned int)v14,
(unsigned int)state[v16 + 23],
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)(int)state[v16 + 23]
* 8.0
/ ((double)SLODWORD(timeout.tv_sec) * 1000000.0 + (double)SLODWORD(timeout.tv_usec))
/ scalar);
close(v14);
state[v16 + 8] = 0;
v22[v14 / 64] &= __ROL8__(-2LL, v14 % 64);
v15 = create_tx_tcp(v5, (unsigned int)(v14 % a4 + a5));
if ( v15 >= 0 )
{
v11 = maxfd;
if ( maxfd < v15 )
{
maxfd = v15;
v11 = (unsigned int)v15;
}
state[40 * v15 + 23] = 0;
v20[v15 >> 6] |= 1LL << v15;
}
else
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
v11 = maxfd;
}
v12 = (unsigned int)(v14 + 1);
}
}
}

original_code:
void
continuous_client(int n, int bytes, char *host, int num_ports, int base_rx_port)
{
    int i;
    fd_set fds_new, fds_active, fds_finished;
    unsigned long ipaddr;
    double tmbs=0;
    ipaddr = host2ipaddr(host);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        struct timeval tp={ 0, 0 };
        if(fd < 0)
        {
            printf("Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].tx_target = bytes;
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = rand()%10000;
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s, fd, rc;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            int new_fd;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd)
                  / (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            fprintf(stderr,
                    "Finished with %d after %d bytes. %ld.%03lds = %.4f "
                    "Mb/s.\n",
                    fd, state[fd].rx_rcvd,
                    (long int)tdiff.tv_sec, (long int)tdiff.tv_usec/1000,
                    mbs/scalar);
            close(fd);
            state[fd].open = 0;
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            if(new_fd < 0)
            {
                fprintf(stderr, "Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

canonical_original_code:
void continuous_client(int n, int bytes, char *host, int num_ports, int base_rx_port)
{
    int i;
    struct fd_set fds_new; struct fd_set fds_active; struct fd_set fds_finished;
    unsigned long ipaddr;
    double tmbs = 0;
    ipaddr = host2ipaddr(host);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        struct timeval tp = { 0, 0 };
        if(fd < 0)
        {
            printf("Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].tx_target = bytes;
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = rand()%10000;
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s; int fd; int rc;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            int new_fd;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd)
                  / (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            fprintf(stderr,
                    "Finished with %d after %d bytes. %ld.%03lds = %.4f "
                    "Mb/s.\n",
                    fd, state[fd].rx_rcvd,
                    (long)tdiff.tv_sec, (long)tdiff.tv_usec/1000,
                    mbs/scalar);
            close(fd);
            state[fd].open = 0;
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            if(new_fd < 0)
            {
                fprintf(stderr, "Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

variable_types: bytes int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }