decompiled_code:
void __fastcall ns_handle_data(_QWORD *a1, unsigned int a2)
{
__int64 v2; // r13
int v3; // eax
void (__fastcall *v4)(_QWORD *, _QWORD, _QWORD, _QWORD); // rbx
int *v5; // rax
void (__fastcall *v6)(_QWORD *, _QWORD, _QWORD); // rax
void (__fastcall *v7)(_QWORD *, _QWORD, __int64, _QWORD, __int64); // r14
__int64 v8; // r15
unsigned int v9; // ebx
__int64 v10; // rax
_BYTE v11[9064]; // [rsp+0h] [rbp-2368h] BYREF

v2 = paGet(a1 + 7);
v3 = read(a2, v11, 0x2328uLL);
if ( v3 > 0 )
{
bufAdd(v2, v11, v3);
v7 = (void (__fastcall *)(_QWORD *, _QWORD, __int64, _QWORD, __int64))a1[15];
if ( v7 )
{
v8 = a1[16];
v9 = bufLen(v2);
v10 = bufGet(v2);
v7(a1, a2, v10, v9, v8);
}
}
else if ( v3 )
{
nsDisconnect((__int64)a1, a2);
v4 = (void (__fastcall *)(_QWORD *, _QWORD, _QWORD, _QWORD))a1[13];
if ( v4 )
{
v5 = _errno_location();
v4(a1, a2, (unsigned int)*v5, a1[14]);
}
}
else
{
nsDisconnect((__int64)a1, a2);
v6 = (void (__fastcall *)(_QWORD *, _QWORD, _QWORD))a1[11];
if ( v6 )
v6(a1, a2, a1[12]);
}
}

canonical_decompiled_code:
void __fastcall func10(_QWORD *a1, unsigned int a2)
{
__int64 v2; // r13
int v3; // eax
void (__fastcall *v4)(_QWORD *, _QWORD, _QWORD, _QWORD); // rbx
int *v5; // rax
void (__fastcall *v6)(_QWORD *, _QWORD, _QWORD); // rax
void (__fastcall *v7)(_QWORD *, _QWORD, __int64, _QWORD, __int64); // r14
__int64 v8; // r15
unsigned int v9; // ebx
__int64 v10; // rax
_BYTE v11[9064]; // [rsp+0h] [rbp-2368h] BYREF

v2 = paGet(a1 + 7);
v3 = read(a2, v11, 0x2328uLL);
if ( v3 > 0 )
{
bufAdd(v2, v11, v3);
v7 = (void (__fastcall *)(_QWORD *, _QWORD, __int64, _QWORD, __int64))a1[15];
if ( v7 )
{
v8 = a1[16];
v9 = bufLen(v2);
v10 = bufGet(v2);
v7(a1, a2, v10, v9, v8);
}
}
else if ( v3 )
{
func9((__int64)a1, a2);
v4 = (void (__fastcall *)(_QWORD *, _QWORD, _QWORD, _QWORD))a1[13];
if ( v4 )
{
v5 = _errno_location();
v4(a1, a2, (unsigned int)*v5, a1[14]);
}
}
else
{
func9((__int64)a1, a2);
v6 = (void (__fastcall *)(_QWORD *, _QWORD, _QWORD))a1[11];
if ( v6 )
v6(a1, a2, a1[12]);
}
}

original_code:
static void ns_handle_data(Dispatcher *dis, int fd, __attribute__((unused)) void *udata)
{
    char data[9000];
    NS *ns = (NS *) dis;
    NS_Connection *conn = paGet(&ns->connections, fd);
    int n;
    if (0) _dbgPrint(stderr, "ns.c", 41, __func__, "Reading from fd %d...\n", fd);
    n = read(fd, data, sizeof(data));
    if (0) _dbgPrint(stderr, "ns.c", 45, __func__, "read() returned %d.\n", n);
    if (n > 0) {
        if (0) _dbgPrint(stderr, "ns.c", 48, __func__, "Adding to incoming buffer.\n");
        bufAdd(&conn->incoming, data, n);
        if (ns->on_socket_cb != ((void *)0)) {
            if (0) _dbgPrint(stderr, "ns.c", 53, __func__, "Calling on_socket_cb.\n");
            ns->on_socket_cb(ns, fd,
                    bufGet(&conn->incoming), bufLen(&conn->incoming),
                    ns->on_socket_udata);
        }
    }
    else if (n == 0) {
        if (0) _dbgPrint(stderr, "ns.c", 61, __func__, "End of file, disconnecting.\n");
        nsDisconnect(ns, fd);
        if (ns->on_disconnect_cb != ((void *)0)) {
            if (0) _dbgPrint(stderr, "ns.c", 66, __func__, "Calling on_disconnect_cb.\n");
            ns->on_disconnect_cb(ns, fd, ns->on_disconnect_udata);
        }
    }
    else {
        if (0) _dbgPrint(stderr, "ns.c", 72, __func__, "Error, disconnecting.\n");
        nsDisconnect(ns, fd);
        if (ns->on_error_cb != ((void *)0)) {
            if (0) _dbgPrint(stderr, "ns.c", 77, __func__, "Calling on_error_cb.\n");
            ns->on_error_cb(ns, fd, (*__errno_location ()), ns->on_error_udata);
        }
    }
}

canonical_original_code:
static void ns_handle_data(struct Dispatcher *dis, int fd, void *udata)
{
    char data[9000];
    struct NS *ns = (NS *) dis;
    struct NS_Connection *conn = paGet(&ns->connections, fd);
    int n;
    if (0) _dbgPrint(stderr, "ns.c", 41, __func__, "Reading from fd %d...\n", fd);
    n = read(fd, data, sizeof(data));
    if (0) _dbgPrint(stderr, "ns.c", 45, __func__, "read() returned %d.\n", n);
    if (n > 0) {
        if (0) _dbgPrint(stderr, "ns.c", 48, __func__, "Adding to incoming buffer.\n");
        bufAdd(&conn->incoming, data, n);
        if (ns->on_socket_cb != ((void *)0)) {
            if (0) _dbgPrint(stderr, "ns.c", 53, __func__, "Calling on_socket_cb.\n");
            ns->on_socket_cb(ns, fd,
                    bufGet(&conn->incoming), bufLen(&conn->incoming),
                    ns->on_socket_udata);
        }
    }
    else if (n == 0) {
        if (0) _dbgPrint(stderr, "ns.c", 61, __func__, "End of file, disconnecting.\n");
        nsDisconnect(ns, fd);
        if (ns->on_disconnect_cb != ((void *)0)) {
            if (0) _dbgPrint(stderr, "ns.c", 66, __func__, "Calling on_disconnect_cb.\n");
            ns->on_disconnect_cb(ns, fd, ns->on_disconnect_udata);
        }
    }
    else {
        if (0) _dbgPrint(stderr, "ns.c", 72, __func__, "Error, disconnecting.\n");
        nsDisconnect(ns, fd);
        if (ns->on_error_cb != ((void *)0)) {
            if (0) _dbgPrint(stderr, "ns.c", 77, __func__, "Calling on_error_cb.\n");
            ns->on_error_cb(ns, fd, (*__errno_location ()), ns->on_error_udata);
        }
    }
}

variable_types: struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } timers; struct timeval { long tv_sec; long tv_usec; } tv; } *

variable_types:
data
char [9000]

variable_types: n int


nsDropData

repo: jaccovanschaik/libjvs

decompiled_code:
// attributes: thunk
__int64 __fastcall nsDropData(__int64 a1, __int64 a2)
{
return disDropData(a1, a2);
}

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

original_code:
void nsDropData(NS *ns, int fd)
{
    if (0) _dbgPrint(stderr, "ns.c", 246, __func__, "Calling disDropData for fd %d\n", fd);
    disDropData(&ns->dis, fd);
}

canonical_original_code:
void nsDropData(struct NS *ns, int fd)
{
    if (0) _dbgPrint(stderr, "ns.c", 246, __func__, "Calling disDropData for fd %d\n", fd);
    disDropData(&ns->dis, fd);
}

variable_types: struct NS { struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } timers; struct timeval { long tv_sec; long tv_usec; } tv; } dis; struct PointerArray connections; void (*on_connect_cb)(struct NS *ns, int fd, void *udata); void *on_connect_udata; void (*on_disconnect_cb)(struct NS *ns, int fd, void *udata); void *on_disconnect_udata; void (*on_error_cb)(struct NS *ns, int fd, int error, void *udata); void *on_error_udata; void (*on_socket_cb)(struct NS *ns, int fd, char *buffer, int size, void *udata); void *on_socket_udata; } *

variable_types: fd int

return_type: void

user_defined_types: struct NS { struct Dispatcher dis; struct PointerArray connections; void (*on_connect_cb)(struct NS *ns, int fd, void *udata); void *on_connect_udata; void (*on_disconnect_cb)(struct NS *ns, int fd, void *udata); void *on_disconnect_udata; void (*on_error_cb)(struct NS *ns, int fd, int error, void *udata); void *on_error_udata; void (*on_socket_cb)(struct NS *ns, int fd, char *buffer, int size, void *udata); void *on_socket_udata; }

user_defined_types: struct Dispatcher { struct PointerArray files; struct List timers; struct timeval tv; }

user_defined_types: struct List { struct ListNode *head; struct ListNode *tail; int length; }


nsWrite

decompiled_code:
// attributes: thunk
__int64 nsWrite()
{
return disWrite();
}

canonical_decompiled_code:
__int64 func13()
{
return disWrite();
}

original_code:
void nsWrite(NS *ns, int fd, const char *data, size_t size)
{
    disWrite(&ns->dis, fd, data, size);
}

canonical_original_code:
void nsWrite(struct NS *ns, int fd, char *data, unsigned long size)
{
    disWrite(&ns->dis, fd, data, size);
}

variable_types:
data
char *

variable_types:
size
unsigned long

user_defined_types: struct PointerArray { int num_ptrs; void **ptr; }

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

user_defined_types: struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; }


nsVaPack

decompiled_code:
void __fastcall nsVaPack(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = vastrpack(&ptr, a3);
nsWrite(a1, a2, ptr, v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = vastrpack(&ptr, a3);
func13(a1, a2, ptr, v3);
free(ptr);
}

original_code:
void nsVaPack(NS *ns, int fd, va_list ap)
{
    char *str;
    int n = vastrpack(&str, ap);
    nsWrite(ns, fd, str, n);
    free(str);
}

canonical_original_code:
void nsVaPack(struct NS *ns, int fd, __builtin_va_list ap)
{
    char *str;
    int n = vastrpack(&str, ap);
    nsWrite(ns, fd, str, n);
    free(str);
}

variable_types:
str
char *


nsPack

decompiled_code:
void nsPack(__int64 a1, unsigned int a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
nsVaPack(a1, a2, (__int64)va);
}

canonical_decompiled_code:
void func15(__int64 a1, unsigned int a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func14(a1, a2, (__int64)va);
}

original_code:
void nsPack(NS *ns, int fd, ...)
{
    va_list ap;
    __builtin_va_start(ap,fd);
    nsVaPack(ns, fd, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void nsPack(struct NS *ns, int fd, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fd);
    nsVaPack(ns, fd, ap);
    __builtin_va_end(ap);
}


nsIncoming

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

v1 = paGet(a1 + 56);
return bufGet(v1);
}

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

v1 = paGet(a1 + 56);
return bufGet(v1);
}

original_code:
const char *nsIncoming(NS *ns, int fd)
{
    NS_Connection *conn = paGet(&ns->connections, fd);
    return bufGet(&conn->incoming);
}

canonical_original_code:
char *nsIncoming(struct NS *ns, int fd)
{
    struct NS_Connection *conn = paGet(&ns->connections, fd);
    return bufGet(&conn->incoming);
}

variable_types: struct NS_Connection { struct Buffer { char *data; unsigned long used; unsigned long size; } incoming; } *

return_type: char *

user_defined_types: struct NS_Connection { struct Buffer incoming; }


nsAvailable

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

v1 = paGet(a1 + 56);
return bufLen(v1);
}

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

v1 = paGet(a1 + 56);
return bufLen(v1);
}

original_code:
int nsAvailable(NS *ns, int fd)
{
    NS_Connection *conn = paGet(&ns->connections, fd);
    return bufLen(&conn->incoming);
}

canonical_original_code:
int nsAvailable(struct NS *ns, int fd)
{
    struct NS_Connection *conn = paGet(&ns->connections, fd);
    return bufLen(&conn->incoming);
}

return_type: int

user_defined_types: struct Buffer { char *data; unsigned long used; unsigned long size; }


nsDiscard

decompiled_code:
__int64 __fastcall nsDiscard(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax

v4 = paGet(a1 + 56);
return bufTrim(v4, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax

v4 = paGet(a1 + 56);
return bufTrim(v4, a3, 0LL);
}

original_code:
void nsDiscard(NS *ns, int fd, int length)
{
    NS_Connection *conn = paGet(&ns->connections, fd);
    bufTrim(&conn->incoming, length, 0);
}

canonical_original_code:
void nsDiscard(struct NS *ns, int fd, int length)
{
    struct NS_Connection *conn = paGet(&ns->connections, fd);
    bufTrim(&conn->incoming, length, 0);
}

variable_types: length int


nsFdCount

decompiled_code:
// attributes: thunk
__int64 nsFdCount()
{
return disFdCount();
}

canonical_decompiled_code:
__int64 func21()
{
return disFdCount();
}

original_code:
int nsFdCount(NS *ns)
{
    return disFdCount(&ns->dis);
}

canonical_original_code:
int nsFdCount(struct NS *ns)
{
    return disFdCount(&ns->dis);
}


nsOwnsFd

decompiled_code:
// attributes: thunk
__int64 nsOwnsFd()
{
return disOwnsFd();
}

canonical_decompiled_code:
__int64 func22()
{
return disOwnsFd();
}

original_code:
int nsOwnsFd(NS *ns, int fd)
{
    return disOwnsFd(&ns->dis, fd);
}

canonical_original_code:
int nsOwnsFd(struct NS *ns, int fd)
{
    return disOwnsFd(&ns->dis, fd);
}


nsPrepareSelect

decompiled_code:
// attributes: thunk
__int64 nsPrepareSelect()
{
return disPrepareSelect();
}

canonical_decompiled_code:
__int64 func23()
{
return disPrepareSelect();
}

original_code:
int nsPrepareSelect(NS *ns, int *nfds, fd_set *rfds, fd_set *wfds,
        struct timeval **tv)
{
    return disPrepareSelect(&ns->dis, nfds, rfds, wfds, tv);
}

canonical_original_code:
int nsPrepareSelect(struct NS *ns, int *nfds, struct fd_set *rfds, struct fd_set *wfds, struct timeval **tv)
{
    return disPrepareSelect(&ns->dis, nfds, rfds, wfds, tv);
}

variable_types:
nfds
int *

variable_types:
rfds
struct fd_set { long fds_bits[-1]; } *

variable_types:
wfds
struct fd_set *

variable_types:
tv
struct timeval **


nsHandleTimer

decompiled_code:
// attributes: thunk
__int64 nsHandleTimer()
{
return disHandleTimer();
}

canonical_decompiled_code:
__int64 func24()
{
return disHandleTimer();
}

original_code:
void nsHandleTimer(NS *ns)
{
    disHandleTimer(&ns->dis);
}

canonical_original_code:
void nsHandleTimer(struct NS *ns)
{
    disHandleTimer(&ns->dis);
}


nsHandleFiles

decompiled_code:
// attributes: thunk
__int64 nsHandleFiles()
{
return disHandleFiles();
}

canonical_decompiled_code:
__int64 func25()
{
return disHandleFiles();
}

original_code:
void nsHandleFiles(NS *ns, int nfds, fd_set *rfds, fd_set *wfds)
{
    disHandleFiles(&ns->dis, nfds, rfds, wfds);
}

canonical_original_code:
void nsHandleFiles(struct NS *ns, int nfds, struct fd_set *rfds, struct fd_set *wfds)
{
    disHandleFiles(&ns->dis, nfds, rfds, wfds);
}

variable_types: nfds int


nsHandleReadable

decompiled_code:
// attributes: thunk
__int64 nsHandleReadable()
{
return disHandleReadable();
}

canonical_decompiled_code:
__int64 func26()
{
return disHandleReadable();
}

original_code:
void nsHandleReadable(NS *ns, int fd)
{
    disHandleReadable(&ns->dis, fd);
}

canonical_original_code:
void nsHandleReadable(struct NS *ns, int fd)
{
    disHandleReadable(&ns->dis, fd);
}


nsHandleWritable

decompiled_code:
// attributes: thunk
__int64 nsHandleWritable()
{
return disHandleWritable();
}

canonical_decompiled_code:
__int64 func27()
{
return disHandleWritable();
}

original_code:
void nsHandleWritable(NS *ns, int fd)
{
    disHandleWritable(&ns->dis, fd);
}

canonical_original_code:
void nsHandleWritable(struct NS *ns, int fd)
{
    disHandleWritable(&ns->dis, fd);
}


nsProcessSelect

decompiled_code:
// attributes: thunk
__int64 nsProcessSelect()
{
return disProcessSelect();
}

canonical_decompiled_code:
__int64 func28()
{
return disProcessSelect();
}

original_code:
void nsProcessSelect(NS *ns, int r, int nfds, fd_set *rfds, fd_set *wfds)
{
    disProcessSelect(&ns->dis, r, nfds, rfds, wfds);
}

canonical_original_code:
void nsProcessSelect(struct NS *ns, int r, int nfds, struct fd_set *rfds, struct fd_set *wfds)
{
    disProcessSelect(&ns->dis, r, nfds, rfds, wfds);
}

variable_types: r int


nsHandleEvents

decompiled_code:
// attributes: thunk
__int64 nsHandleEvents()
{
return disHandleEvents();
}

canonical_decompiled_code:
__int64 func29()
{
return disHandleEvents();
}

original_code:
int nsHandleEvents(NS *ns)
{
    return disHandleEvents(&ns->dis);
}

canonical_original_code:
int nsHandleEvents(struct NS *ns)
{
    return disHandleEvents(&ns->dis);
}


nsRun

decompiled_code:
// attributes: thunk
__int64 nsRun()
{
return disRun();
}

canonical_decompiled_code:
__int64 func30()
{
return disRun();
}

original_code:
int nsRun(NS *ns)
{
    return disRun(&ns->dis);
}

canonical_original_code:
int nsRun(struct NS *ns)
{
    return disRun(&ns->dis);
}


nsClose

decompiled_code:
// attributes: thunk
__int64 nsClose()
{
return disClose();
}

canonical_decompiled_code:
__int64 func31()
{
return disClose();
}

original_code:
void nsClose(NS *ns)
{
    disClose((Dispatcher *) ns);
}

canonical_original_code:
void nsClose(struct NS *ns)
{
    disClose((struct Dispatcher *) ns);
}


nsClear

decompiled_code:
__int64 __fastcall nsClear(_QWORD *a1)
{
__int64 result; // rax

disClear();
*a1 = 0LL;
result = 0LL;
a1[16] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 136) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func32(_QWORD *a1)
{
__int64 result; // rax

disClear();
*a1 = 0LL;
result = 0LL;
a1[16] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 136) >> 3));
return result;
}

original_code:
void nsClear(NS *ns)
{
    disClear(&ns->dis);
    memset(ns, 0, sizeof(NS));
}

canonical_original_code:
void nsClear(struct NS *ns)
{
    disClear(&ns->dis);
    memset(ns, 0, sizeof(NS));
}


nsDestroy

decompiled_code:
void __fastcall nsDestroy(void *ptr)
{
nsClose();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func33(void *ptr)
{
func31();
free(ptr);
}

original_code:
void nsDestroy(NS *ns)
{
    nsClose(ns);
    free(ns);
}

canonical_original_code:
void nsDestroy(struct NS *ns)
{
    nsClose(ns);
    free(ns);
}


tvNormalized

original_code:
struct timeval tvNormalized(struct timeval tv)
{
    struct timeval dup = tv;
    while (dup.tv_usec < 0) {
        dup.tv_sec--;
        dup.tv_usec += 1000000L;
    }
    while (dup.tv_usec >= 1000000L) {
        dup.tv_sec++;
        dup.tv_usec -= 1000000L;
    }
    return dup;
}

variable_types:
tv
struct timeval

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


tvNormalize

decompiled_code:
__int64 __fastcall tvNormalize(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = tvNormalized(*a1, a1[1]);
*a1 = result;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = func0(*a1, a1[1]);
*a1 = result;
a1[1] = v2;
return result;
}

original_code:
void tvNormalize(struct timeval *tv)
{
    *tv = tvNormalized(*tv);
}

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


tvMake

decompiled_code:
__int64 __fastcall tvMake(__int64 a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a1;
v3[1] = a2;
tvNormalize(v3);
return v3[0];
}

original_code:
struct timeval tvMake(long sec, long usec)
{
    struct timeval t = {
        .tv_sec = sec,
        .tv_usec = usec
    };
    tvNormalize(&t);
    return t;
}

variable_types: sec long

variable_types: usec long

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


tvNow

decompiled_code:
__time_t tvNow()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

v1 = 0LL;
gettimeofday(&v1, 0LL);
return v1.tv_sec;
}

canonical_decompiled_code:
__time_t func3()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

v1 = 0LL;
gettimeofday(&v1, 0LL);
return v1.tv_sec;
}

original_code:
struct timeval tvNow(void)
{
    struct timeval tv = { 0 };
    gettimeofday(&tv, ((void *)0));
    return tv;
}

canonical_original_code:
struct timeval tvNow()
{
    struct timeval tv = { 0 };
    gettimeofday(&tv, ((void *)0));
    return tv;
}


tvCompare

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

result = 0xFFFFFFFFLL;
if ( a1 >= a3 )
{
result = 1LL;
if ( a1 <= a3 )
{
result = a2 > a4;
if ( a2 < a4 )
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 >= a3 )
{
result = 1LL;
if ( a1 <= a3 )
{
result = a2 > a4;
if ( a2 < a4 )
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int tvCompare(struct timeval t1, struct timeval t0)
{
    if (t1.tv_sec < t0.tv_sec) {
        return -1;
    }
    else if (t1.tv_sec > t0.tv_sec) {
        return 1;
    }
    else if (t1.tv_usec < t0.tv_usec) {
        return -1;
    }
    else if (t1.tv_usec > t0.tv_usec) {
        return 1;
    }
    else {
        return 0;
    }
}


tvDelta

decompiled_code:
double __fastcall tvDelta(int a1, int a2, int a3, int a4)
{
return (double)(a2 - a4) / 1000000.0 + (double)(a1 - a3);
}

canonical_decompiled_code:
double __fastcall func5(int a1, int a2, int a3, int a4)
{
return (double)(a2 - a4) / 1000000.0 + (double)(a1 - a3);
}

original_code:
double tvDelta(struct timeval t1, struct timeval t0)
{
    return t1.tv_sec - t0.tv_sec
         + (double) (t1.tv_usec - t0.tv_usec) / 1000000L;
}

return_type: double


tvDec

decompiled_code:
__int64 __fastcall tvDec(__int64 a1, __int64 a2, double a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a1 - (unsigned int)(int)a3;
v4[1] = a2 - (unsigned int)(int)(fmod(a3, 1.0) * 1000000.0);
tvNormalize(v4);
return v4[0];
}

original_code:
struct timeval tvDec(struct timeval tv, double seconds)
{
    tv.tv_sec -= (long) seconds;
    tv.tv_usec -= (long) (1000000L * fmod(seconds, 1));
    tvNormalize(&tv);
    return tv;
}

variable_types: seconds double


tvInc

decompiled_code:
__int64 __fastcall tvInc(__int64 a1, __int64 a2, double a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = (unsigned int)(int)a3 + a1;
v4[1] = (unsigned int)(int)(fmod(a3, 1.0) * 1000000.0) + a2;
tvNormalize(v4);
return v4[0];
}

original_code:
struct timeval tvInc(struct timeval tv, double seconds)
{
    tv.tv_sec += (long) seconds;
    tv.tv_usec += (long) (1000000L * fmod(seconds, 1));
    tvNormalize(&tv);
    return tv;
}


tvFromDouble

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

v1 = fmod(a1 * 1000000.0, 1000000.0);
return tvMake((int)a1, (unsigned int)(int)v1);
}

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

v1 = fmod(a1 * 1000000.0, 1000000.0);
return func2((int)a1, (unsigned int)(int)v1);
}

original_code:
struct timeval tvFromDouble(double t)
{
    return tvMake((int) t, fmod(1000000L * t, 1000000L));
}

variable_types: t double


tvToDouble

decompiled_code:
double __fastcall tvToDouble(int a1, int a2)
{
return (double)a2 / 1000000.0 + (double)a1;
}

canonical_decompiled_code:
double __fastcall func9(int a1, int a2)
{
return (double)a2 / 1000000.0 + (double)a1;
}

original_code:
double tvToDouble(struct timeval tv)
{
    return (double) tv.tv_sec + (double) tv.tv_usec / 1000000L;
}


tvFromTimespec

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

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

original_code:
struct timeval tvFromTimespec(struct timespec ts)
{
    struct timeval tv = {
        .tv_sec = ts.tv_sec,
        .tv_usec = ts.tv_nsec * 1000
    };
    return tv;
}

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


tvFormatC

decompiled_code:
__int64 __fastcall tvFormatC(__int64 a1, int a2)
{
return t_format_c(a1, (unsigned int)(1000 * a2));
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
return t_format_c(a1, (unsigned int)(1000 * a2));
}

original_code:
const char *tvFormatC(const struct timeval tv, const char *tz,
        const char *fmt)
{
    return t_format_c(tv.tv_sec, 1000 * tv.tv_usec, tz, fmt);
}

canonical_original_code:
char *tvFormatC(struct timeval tv, char *tz, char *fmt)
{
    return t_format_c(tv.tv_sec, 1000 * tv.tv_usec, tz, fmt);
}

variable_types:
tz
char *

variable_types:
fmt
char *


tvFormat

decompiled_code:
char *__fastcall tvFormat(__int64 a1, int a2)
{
const char *v2; // rax

v2 = (const char *)tvFormatC(a1, a2);
return strdup(v2);
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1, int a2)
{
const char *v2; // rax

v2 = (const char *)func11(a1, a2);
return strdup(v2);
}

original_code:
char *tvFormat(const struct timeval tv, const char *tz, const char *fmt)
{
    return strdup(tvFormatC(tv, tz, fmt));
}

canonical_original_code:
char *tvFormat(struct timeval tv, char *tz, char *fmt)
{
    return strdup(tvFormatC(tv, tz, fmt));
}


decompiled_code:
__int64 __fastcall tcp_socket(int a1)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi

v1 = socket(a1, 1, 0);
v2 = v1;
if ( v1 != -1 && setsockopt(v1, 1, 13, &linger, 8u) )
{
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi

v1 = socket(a1, 1, 0);
v2 = v1;
if ( v1 != -1 && setsockopt(v1, 1, 13, &linger, 8u) )
{
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

original_code:
static int tcp_socket(int family)
{
    int sd;
    if ((sd = socket(family, SOCK_STREAM, 0)) == -1) {
        if (0) _dbgError(stderr, "tcp.c", 39, __func__, "socket failed");
    }
    else if (setsockopt(sd, 1, 13,
                        &linger, sizeof(linger)) != 0)
    {
        if (0) _dbgError(stderr, "tcp.c", 44, __func__, "setsockopt(LINGER) failed");
        close(sd);
        sd = -1;
    }
    return sd;
}

variable_types: family int

variable_types: sd int


decompiled_code:
__int64 __fastcall tcp_listen(char *name, unsigned __int16 a2, int a3)
{
int v3; // eax
struct addrinfo *v4; // r12
int v5; // eax
unsigned int v6; // ebp
const char *v8; // rax
int optval; // [rsp+0h] [rbp-5Ch] BYREF
char s[6]; // [rsp+6h] [rbp-56h] BYREF
struct addrinfo *pai; // [rsp+Ch] [rbp-50h] BYREF
struct addrinfo req; // [rsp+14h] [rbp-48h] BYREF

req.ai_family = a3;
*(_OWORD *)&req.ai_socktype = 0LL;
pai = 0LL;
req.ai_next = 0LL;
req.ai_flags = 1;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addr = 0LL;
snprintf(s, 6uLL, "%hu", a2);
v3 = getaddrinfo(name, s, &req, &pai);
if ( v3 )
{
v8 = gai_strerror(v3);
v6 = -1;
dbgPrint(stderr, "tcp.c", 80LL, "tcp_listen", "getaddrinfo for %s:%hu failed: %s", name, a2, v8);
}
else
{
v4 = pai;
optval = 1;
if ( pai )
{
do
{
v5 = tcp_socket(v4->ai_family);
v6 = v5;
if ( v5 != -1 )
{
if ( !setsockopt(v5, 1, 2, &optval, 4u) && bind(v6, v4->ai_addr, v4->ai_addrlen) >= 0 && listen(v6, 128) != -1 )
{
v4 = pai;
goto LABEL_8;
}
close(v6);
}
v4 = v4->ai_next;
}
while ( v4 );
v4 = pai;
v6 = -1;
}
else
{
v6 = -1;
}
LABEL_8:
freeaddrinfo(v4);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name, unsigned __int16 a2, int a3)
{
int v3; // eax
struct addrinfo *v4; // r12
int v5; // eax
unsigned int v6; // ebp
const char *v8; // rax
int optval; // [rsp+0h] [rbp-5Ch] BYREF
char s[6]; // [rsp+6h] [rbp-56h] BYREF
struct addrinfo *pai; // [rsp+Ch] [rbp-50h] BYREF
struct addrinfo req; // [rsp+14h] [rbp-48h] BYREF

req.ai_family = a3;
*(_OWORD *)&req.ai_socktype = 0LL;
pai = 0LL;
req.ai_next = 0LL;
req.ai_flags = 1;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addr = 0LL;
snprintf(s, 6uLL, "%hu", a2);
v3 = getaddrinfo(name, s, &req, &pai);
if ( v3 )
{
v8 = gai_strerror(v3);
v6 = -1;
dbgPrint(stderr, "tcp.c", 80LL, "tcp_listen", "getaddrinfo for %s:%hu failed: %s", name, a2, v8);
}
else
{
v4 = pai;
optval = 1;
if ( pai )
{
do
{
v5 = func0(v4->ai_family);
v6 = v5;
if ( v5 != -1 )
{
if ( !setsockopt(v5, 1, 2, &optval, 4u) && bind(v6, v4->ai_addr, v4->ai_addrlen) >= 0 && listen(v6, 128) != -1 )
{
v4 = pai;
goto LABEL_8;
}
close(v6);
}
v4 = v4->ai_next;
}
while ( v4 );
v4 = pai;
v6 = -1;
}
else
{
v6 = -1;
}
LABEL_8:
freeaddrinfo(v4);
}
return v6;
}

original_code:
static int tcp_listen(const char *host, uint16_t port, int family)
{
    struct addrinfo *info = ((void *)0), *first_info = ((void *)0);
    struct addrinfo hint = {
        .ai_family = family,
        .ai_socktype = SOCK_STREAM,
        .ai_flags = 0x0001
    };
    char port_str[6];
    snprintf(port_str, sizeof(port_str), "%hu", port);
    int r;
    if ((r = getaddrinfo(host, port_str, &hint, &first_info)) != 0) {
        _dbgPrint(stderr, "tcp.c", 80, __func__, "getaddrinfo for %s:%hu failed: %s", host, port, gai_strerror(r));
        return -1;
    }
    int lsd = -1;
    int one = 1;
    for (info = first_info; lsd == -1 && info != ((void *)0); info = info->ai_next) {
        if ((lsd = tcp_socket(info->ai_family)) == -1) {
            if (0) _dbgError(stderr, "tcp.c", 99, __func__, "tcp_socket() failed");
        }
        else if (setsockopt(lsd, 1,
                 2, &one, sizeof(one)) != 0)
        {
            if (0) _dbgError(stderr, "tcp.c", 113, __func__, "setsockopt(REUSEADDR) failed");
            close(lsd);
            lsd = -1;
        }
        else if (bind(lsd, info->ai_addr, info->ai_addrlen) < 0) {
            if (0) _dbgAbort(stderr, "tcp.c", 118, __func__, "bind() failed");
            close(lsd);
            lsd = -1;
        }
        else if (listen(lsd, 128) == -1) {
            if (0) _dbgError(stderr, "tcp.c", 123, __func__, "listen() failed");
            close(lsd);
            lsd = -1;
        }
    }
    freeaddrinfo(first_info);
    return lsd;
}

canonical_original_code:
static int tcp_listen(char *host, unsigned short port, int family)
{
    struct addrinfo *info = ((void *)0); struct addrinfo *first_info = ((void *)0);
    struct addrinfo hint = {
        .ai_family = family,
        .ai_socktype = SOCK_STREAM,
        .ai_flags = 0x0001
    };
    char port_str[6];
    snprintf(port_str, sizeof(port_str), "%hu", port);
    int r;
    if ((r = getaddrinfo(host, port_str, &hint, &first_info)) != 0) {
        _dbgPrint(stderr, "tcp.c", 80, __func__, "getaddrinfo for %s:%hu failed: %s", host, port, gai_strerror(r));
        return -1;
    }
    int lsd = -1;
    int one = 1;
    for (info = first_info; lsd == -1 && info != ((void *)0); info = info->ai_next) {
        if ((lsd = tcp_socket(info->ai_family)) == -1) {
            if (0) _dbgError(stderr, "tcp.c", 99, __func__, "tcp_socket() failed");
        }
        else if (setsockopt(lsd, 1,
                 2, &one, sizeof(one)) != 0)
        {
            if (0) _dbgError(stderr, "tcp.c", 113, __func__, "setsockopt(REUSEADDR) failed");
            close(lsd);
            lsd = -1;
        }
        else if (bind(lsd, info->ai_addr, info->ai_addrlen) < 0) {
            if (0) _dbgAbort(stderr, "tcp.c", 118, __func__, "bind() failed");
            close(lsd);
            lsd = -1;
        }
        else if (listen(lsd, 128) == -1) {
            if (0) _dbgError(stderr, "tcp.c", 123, __func__, "listen() failed");
            close(lsd);
            lsd = -1;
        }
    }
    freeaddrinfo(first_info);
    return lsd;
}

variable_types:
host
char *

variable_types:
port
unsigned short

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: lsd int

variable_types: one int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall tcp_connect(char *name, unsigned __int16 a2, int a3)
{
int v3; // eax
struct addrinfo *v4; // rbx
int v5; // eax
unsigned int v6; // ebp
const char *v8; // rax
char s[6]; // [rsp+0h] [rbp-56h] BYREF
struct addrinfo *pai; // [rsp+6h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_family = a3;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a2);
v3 = getaddrinfo(name, s, &req, &pai);
if ( v3 )
{
v6 = -1;
v8 = gai_strerror(v3);
dbgPrint(stderr, "tcp.c", 153LL, "tcp_connect", "%s: getaddrinfo failed: %s", "tcp_connect", v8);
}
else
{
v4 = pai;
if ( pai )
{
do
{
v5 = tcp_socket(v4->ai_family);
v6 = v5;
if ( v5 != -1 )
{
if ( connect(v5, v4->ai_addr, v4->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
return v6;
}
close(v6);
}
v4 = v4->ai_next;
}
while ( v4 );
v6 = -1;
freeaddrinfo(pai);
}
else
{
v6 = -1;
freeaddrinfo(0LL);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *name, unsigned __int16 a2, int a3)
{
int v3; // eax
struct addrinfo *v4; // rbx
int v5; // eax
unsigned int v6; // ebp
const char *v8; // rax
char s[6]; // [rsp+0h] [rbp-56h] BYREF
struct addrinfo *pai; // [rsp+6h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_family = a3;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a2);
v3 = getaddrinfo(name, s, &req, &pai);
if ( v3 )
{
v6 = -1;
v8 = gai_strerror(v3);
dbgPrint(stderr, "tcp.c", 153LL, "tcp_connect", "%s: getaddrinfo failed: %s", "tcp_connect", v8);
}
else
{
v4 = pai;
if ( pai )
{
do
{
v5 = func0(v4->ai_family);
v6 = v5;
if ( v5 != -1 )
{
if ( connect(v5, v4->ai_addr, v4->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
return v6;
}
close(v6);
}
v4 = v4->ai_next;
}
while ( v4 );
v6 = -1;
freeaddrinfo(pai);
}
else
{
v6 = -1;
freeaddrinfo(0LL);
}
}
return v6;
}

original_code:
static int tcp_connect(const char *host, uint16_t port, int family)
{
    int r, sd = -1;
    char port_as_text[6];
    struct addrinfo *first_info, *info;
    struct addrinfo hints = {
        .ai_family = family,
        .ai_socktype = SOCK_STREAM
    };
    snprintf(port_as_text, sizeof(port_as_text), "%hu", port);
    if ((r = getaddrinfo(host, port_as_text, &hints, &first_info)) != 0) {
        _dbgPrint(stderr, "tcp.c", 153, __func__, "%s: getaddrinfo failed: %s", __func__, gai_strerror(r));
        return -1;
    }
    for (info = first_info; sd == -1 && info != ((void *)0); info = info->ai_next) {
        if ((sd = tcp_socket(info->ai_family)) == -1 ||
            (r = connect(sd, info->ai_addr, info->ai_addrlen)) == -1)
        {
            if (sd != -1) {
                close(sd);
                sd = -1;
            }
        }
    }
    freeaddrinfo(first_info);
    if (sd == -1) {
        if (0) _dbgError(stderr, "tcp.c", 184, __func__, "socket() failed");
        return -1;
    }
    else if (r == -1) {
        if (0) _dbgError(stderr, "tcp.c", 188, __func__, "connect() failed");
        return -1;
    }
    return sd;
}

canonical_original_code:
static int tcp_connect(char *host, unsigned short port, int family)
{
    int r; int sd = -1;
    char port_as_text[6];
    struct addrinfo *first_info; struct addrinfo *info;
    struct addrinfo hints = {
        .ai_family = family,
        .ai_socktype = SOCK_STREAM
    };
    snprintf(port_as_text, sizeof(port_as_text), "%hu", port);
    if ((r = getaddrinfo(host, port_as_text, &hints, &first_info)) != 0) {
        _dbgPrint(stderr, "tcp.c", 153, __func__, "%s: getaddrinfo failed: %s", __func__, gai_strerror(r));
        return -1;
    }
    for (info = first_info; sd == -1 && info != ((void *)0); info = info->ai_next) {
        if ((sd = tcp_socket(info->ai_family)) == -1 ||
            (r = connect(sd, info->ai_addr, info->ai_addrlen)) == -1)
        {
            if (sd != -1) {
                close(sd);
                sd = -1;
            }
        }
    }
    freeaddrinfo(first_info);
    if (sd == -1) {
        if (0) _dbgError(stderr, "tcp.c", 184, __func__, "socket() failed");
        return -1;
    }
    else if (r == -1) {
        if (0) _dbgError(stderr, "tcp.c", 188, __func__, "connect() failed");
        return -1;
    }
    return sd;
}

variable_types: r int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall tcp4Listen(char *a1, unsigned __int16 a2)
{
return tcp_listen(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, unsigned __int16 a2)
{
return func1(a1, a2, 2);
}

original_code:
int tcp4Listen(const char *host, uint16_t port)
{
    return tcp_listen(host, port, 2);
}

canonical_original_code:
int tcp4Listen(char *host, unsigned short port)
{
    return tcp_listen(host, port, 2);
}


decompiled_code:
__int64 __fastcall tcp4Connect(char *a1, unsigned __int16 a2)
{
return tcp_connect(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, unsigned __int16 a2)
{
return func2(a1, a2, 2);
}

original_code:
int tcp4Connect(const char *host, uint16_t port)
{
    return tcp_connect(host, port, 2);
}

canonical_original_code:
int tcp4Connect(char *host, unsigned short port)
{
    return tcp_connect(host, port, 2);
}


decompiled_code:
__int64 __fastcall tcp6Listen(char *a1, unsigned __int16 a2)
{
return tcp_listen(a1, a2, 10);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, unsigned __int16 a2)
{
return func1(a1, a2, 10);
}

original_code:
int tcp6Listen(const char *host, uint16_t port)
{
    return tcp_listen(host, port, 10);
}

canonical_original_code:
int tcp6Listen(char *host, unsigned short port)
{
    return tcp_listen(host, port, 10);
}


decompiled_code:
__int64 __fastcall tcp6Connect(char *a1, unsigned __int16 a2)
{
return tcp_connect(a1, a2, 10);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, unsigned __int16 a2)
{
return func2(a1, a2, 10);
}

original_code:
int tcp6Connect(const char *host, uint16_t port)
{
    return tcp_connect(host, port, 10);
}

canonical_original_code:
int tcp6Connect(char *host, unsigned short port)
{
    return tcp_connect(host, port, 10);
}


tcpListen

decompiled_code:
__int64 __fastcall tcpListen(char *a1, unsigned __int16 a2)
{
return tcp_listen(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, unsigned __int16 a2)
{
return func1(a1, a2, 0);
}

original_code:
int tcpListen(const char *host, uint16_t port)
{
    return tcp_listen(host, port, 0);
}

canonical_original_code:
int tcpListen(char *host, unsigned short port)
{
    return tcp_listen(host, port, 0);
}


tcpConnect

decompiled_code:
__int64 __fastcall tcpConnect(char *a1, unsigned __int16 a2)
{
return tcp_connect(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, unsigned __int16 a2)
{
return func2(a1, a2, 0);
}

original_code:
int tcpConnect(const char *host, uint16_t port)
{
    return tcp_connect(host, port, 0);
}

canonical_original_code:
int tcpConnect(char *host, unsigned short port)
{
    return tcp_connect(host, port, 0);
}


tcpAccept

decompiled_code:
__int64 __fastcall tcpAccept(int fd)
{
unsigned int v1; // er12

do
v1 = accept(fd, 0LL, 0LL);
while ( v1 == -1 && *_errno_location() == 4 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
unsigned int v1; // er12

do
v1 = accept(fd, 0LL, 0LL);
while ( v1 == -1 && *_errno_location() == 4 );
return v1;
}

original_code:
int tcpAccept(int sd)
{
    int csd;
    do {
        csd = accept(sd, ((void *)0), ((void *)0));
    } while (csd == -1 && (*__errno_location ()) == 4);
    if (csd == -1) {
        if (0) _dbgError(stderr, "tcp.c", 270, __func__, "accept failed");
    }
    return csd;
}

variable_types: csd int


tcpRead

decompiled_code:
__int64 __fastcall tcpRead(int fd, __int64 a2, int a3)
{
unsigned int v3; // er14
__int64 v4; // rbp
int v6; // eax
int *v7; // rax

v3 = 0;
v4 = 0LL;
while ( 1 )
{
v6 = read(fd, (void *)(a2 + v4), (int)(a3 - v3));
if ( !v6 )
break;
if ( v6 <= 0 )
{
v7 = _errno_location();
if ( *v7 == 4 )
{
*v7 = 0;
}
else if ( *v7 == 11 )
{
*v7 = 0;
usleep(0x186A0u);
}
}
else
{
v3 += v6;
if ( a3 == v3 )
return v3;
v4 = (int)v3;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, __int64 a2, int a3)
{
unsigned int v3; // er14
__int64 v4; // rbp
int v6; // eax
int *v7; // rax

v3 = 0;
v4 = 0LL;
while ( 1 )
{
v6 = read(fd, (void *)(a2 + v4), (int)(a3 - v3));
if ( !v6 )
break;
if ( v6 <= 0 )
{
v7 = _errno_location();
if ( *v7 == 4 )
{
*v7 = 0;
}
else if ( *v7 == 11 )
{
*v7 = 0;
usleep(0x186A0u);
}
}
else
{
v3 += v6;
if ( a3 == v3 )
return v3;
v4 = (int)v3;
}
}
return v3;
}

original_code:
int tcpRead(int fd, void *buf, int len)
{
    int res, n = 0;
    while (1) {
        if ((res = read(fd, (char *) buf + n, len - n)) == 0) {
            break;
        }
        else if (res > 0 && (n += res) == len) {
            break;
        }
        else if (res < 0 && (*__errno_location ()) == 4) {
            (*__errno_location ()) = 0;
            continue;
        }
        else if (res < 0 && ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)) {
            (*__errno_location ()) = 0;
            usleep(100000);
            continue;
        }
    }
    if (res == -1) {
        if (0) _dbgError(stderr, "tcp.c", 302, __func__, "read failed");
        return -1;
    }
    else {
        return n;
    }
}

canonical_original_code:
int tcpRead(int fd, void *buf, int len)
{
    int res; int n = 0;
    while (1) {
        if ((res = read(fd, (char *) buf + n, len - n)) == 0) {
            break;
        }
        else if (res > 0 && (n += res) == len) {
            break;
        }
        else if (res < 0 && (*__errno_location ()) == 4) {
            (*__errno_location ()) = 0;
            continue;
        }
        else if (res < 0 && ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)) {
            (*__errno_location ()) = 0;
            usleep(100000);
            continue;
        }
    }
    if (res == -1) {
        if (0) _dbgError(stderr, "tcp.c", 302, __func__, "read failed");
        return -1;
    }
    else {
        return n;
    }
}

variable_types: fd int

variable_types:
buf
void *

variable_types: len int

variable_types: res int

variable_types: n int


tcpWrite

decompiled_code:
__int64 __fastcall tcpWrite(int fd, __int64 a2, int a3)
{
int v3; // er12
int v5; // ebx

v3 = 0;
do
{
v5 = write(fd, (const void *)(a2 + v3), a3 - v3);
if ( v5 <= 0 && *_errno_location() != 4 )
break;
v3 += v5;
}
while ( a3 > v3 );
if ( v5 == -1 )
v3 = -1;
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, __int64 a2, int a3)
{
int v3; // er12
int v5; // ebx

v3 = 0;
do
{
v5 = write(fd, (const void *)(a2 + v3), a3 - v3);
if ( v5 <= 0 && *_errno_location() != 4 )
break;
v3 += v5;
}
while ( a3 > v3 );
if ( v5 == -1 )
v3 = -1;
return (unsigned int)v3;
}

original_code:
int tcpWrite(int fd, const void *buf, int len)
{
    int res, n = 0;
    do {
        res = write(fd, (const char *) buf + n, len - n);
    } while ((res > 0 || (*__errno_location ()) == 4) && (n += res) < len);
    if (res == -1) {
        if (0) _dbgError(stderr, "tcp.c", 322, __func__, "write failed");
        return -1;
    }
    else {
        return n;
    }
}

canonical_original_code:
int tcpWrite(int fd, void *buf, int len)
{
    int res; int n = 0;
    do {
        res = write(fd, (char *) buf + n, len - n);
    } while ((res > 0 || (*__errno_location ()) == 4) && (n += res) < len);
    if (res == -1) {
        if (0) _dbgError(stderr, "tcp.c", 322, __func__, "write failed");
        return -1;
    }
    else {
        return n;
    }
}


decompiled_code:
unsigned __int64 __fastcall as_increase_by(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 result; // rax
void *v5; // rdi
size_t v6; // rax
void *v7; // rax

v2 = *(_QWORD *)(a1 + 16);
result = a2 + 1 + *(_QWORD *)(a1 + 8);
if ( result > v2 )
{
v5 = *(void **)a1;
do
{
v6 = 2 * v2;
if ( !v2 )
v6 = 16LL;
v2 = v6;
v7 = realloc(v5, v6);
*(_QWORD *)(a1 + 16) = v2;
*(_QWORD *)a1 = v7;
v5 = v7;
result = a2 + 1 + *(_QWORD *)(a1 + 8);
}
while ( result > v2 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 result; // rax
void *v5; // rdi
size_t v6; // rax
void *v7; // rax

v2 = *(_QWORD *)(a1 + 16);
result = a2 + 1 + *(_QWORD *)(a1 + 8);
if ( result > v2 )
{
v5 = *(void **)a1;
do
{
v6 = 2 * v2;
if ( !v2 )
v6 = 16LL;
v2 = v6;
v7 = realloc(v5, v6);
*(_QWORD *)(a1 + 16) = v2;
*(_QWORD *)a1 = v7;
v5 = v7;
result = a2 + 1 + *(_QWORD *)(a1 + 8);
}
while ( result > v2 );
}
return result;
}

original_code:
static void as_increase_by(astring *str, size_t len)
{
    size_t new_len;
    while (str->used + len + 1 > str->size) {
        if (str->size == 0)
            new_len = 16;
        else
            new_len = 2 * str->size;
        str->data = realloc(str->data, new_len);
        str->size = new_len;
    }
}

canonical_original_code:
static void as_increase_by(struct astring *str, unsigned long len)
{
    unsigned long new_len;
    while (str->used + len + 1 > str->size) {
        if (str->size == 0)
            new_len = 16;
        else
            new_len = 2 * str->size;
        str->data = realloc(str->data, new_len);
        str->size = new_len;
    }
}

variable_types: struct astring { char *data; unsigned long used; unsigned long size; } *

variable_types:
len
unsigned long


asClear

decompiled_code:
void __fastcall asClear(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}

original_code:
void asClear(astring *str)
{
    free(str->data);
    memset(str, 0, sizeof(astring));
}

canonical_original_code:
void asClear(struct astring *str)
{
    free(str->data);
    memset(str, 0, sizeof(astring));
}

user_defined_types: struct astring { char *data; unsigned long used; unsigned long size; }


asDetach

decompiled_code:
char *__fastcall asDetach(char **a1)
{
char *result; // rax

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

canonical_decompiled_code:
char *__fastcall func2(char **a1)
{
char *result; // rax

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

original_code:
char *asDetach(astring *str)
{
    char *data = str->data;
    str->data = ((void *)0);
    str->size = 0;
    str->used = 0;
    return data ? data : strdup("");
}

canonical_original_code:
char *asDetach(struct astring *str)
{
    char *data = str->data;
    str->data = ((void *)0);
    str->size = 0;
    str->used = 0;
    return data ? data : strdup("");
}

variable_types:
data
char *


asFinish

decompiled_code:
char *__fastcall asFinish(char **a1)
{
char *v1; // r12
char *result; // rax

v1 = *a1;
free(a1);
if ( v1 )
result = v1;
else
result = strdup(&LC0);
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char **a1)
{
char *v1; // r12
char *result; // rax

v1 = *a1;
free(a1);
if ( v1 )
result = v1;
else
result = strdup(&LC0);
return result;
}

original_code:
char *asFinish(astring *str)
{
    char *data = str->data;
    free(str);
    return data ? data : strdup("");
}

canonical_original_code:
char *asFinish(struct astring *str)
{
    char *data = str->data;
    free(str);
    return data ? data : strdup("");
}


asDestroy

decompiled_code:
void __fastcall asDestroy(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void asDestroy(astring *str)
{
    free(str->data);
    free(str);
}

canonical_original_code:
void asDestroy(struct astring *str)
{
    free(str->data);
    free(str);
}


asAddF

decompiled_code:
_QWORD *asAddF(_QWORD *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
asAddV(a1, a2, (const __m128i *)va);
return a1;
}

canonical_decompiled_code:
_QWORD *func5(_QWORD *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
asAddV(a1, a2, (const __m128i *)va);
return a1;
}

original_code:
__attribute__((format (printf, 2, 3)))
astring *asAddF(astring *str, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    asAddV(str, fmt, ap);
    __builtin_va_end(ap);
    return str;
}

canonical_original_code:
struct astring *asAddF(struct astring *str, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    asAddV(str, fmt, ap);
    __builtin_va_end(ap);
    return str;
}

variable_types:
str
struct astring *

variable_types:
fmt
char *

return_type: struct astring { char *data; unsigned long used; unsigned long size; } *


asGet

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

result = *a1;
if ( !*a1 )
result = &LC0;
return result;
}

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

result = *a1;
if ( !*a1 )
result = &LC0;
return result;
}

original_code:
const char *asGet(const astring *str)
{
    return str->data ? str->data : "";
}

canonical_original_code:
char *asGet(struct astring *str)
{
    return str->data ? str->data : "";
}


asRewind

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

result = a1;
if ( *(_QWORD *)a1 )
**(_BYTE **)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

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

result = a1;
if ( *(_QWORD *)a1 )
**(_BYTE **)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

original_code:
astring *asRewind(astring *str)
{
    if (str->data != ((void *)0)) str->data[0] = 0;
    str->used = 0;
    return str;
}

canonical_original_code:
struct astring *asRewind(struct astring *str)
{
    if (str->data != ((void *)0)) str->data[0] = 0;
    str->used = 0;
    return str;
}


asCreate

decompiled_code:
_QWORD *asCreate(const char *a1, ...)
{
_QWORD *v1; // rax
_QWORD *v2; // r12
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

v1 = calloc(1uLL, 0x18uLL);
v2 = v1;
if ( a1 )
{
va_start(va, a1);
asSetV(v1, a1, (const __m128i *)va);
}
return v2;
}

canonical_decompiled_code:
_QWORD *func8(const char *a1, ...)
{
_QWORD *v1; // rax
_QWORD *v2; // r12
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

v1 = calloc(1uLL, 0x18uLL);
v2 = v1;
if ( a1 )
{
va_start(va, a1);
asSetV(v1, a1, (const __m128i *)va);
}
return v2;
}

original_code:
__attribute__((format (printf, 1, 2)))
astring *asCreate(const char *fmt, ...)
{
    astring *str = calloc(1, sizeof(*str));
    if (fmt) {
        va_list ap;
        __builtin_va_start(ap,fmt);
        asSetV(str, fmt, ap);
        __builtin_va_end(ap);
    }
    return str;
}

canonical_original_code:
struct astring *asCreate(char *fmt, ...)
{
    struct astring *str = calloc(1, sizeof(*str));
    if (fmt) {
        __builtin_va_list ap;
        __builtin_va_start(ap,fmt);
        asSetV(str, fmt, ap);
        __builtin_va_end(ap);
    }
    return str;
}


asInit

decompiled_code:
_QWORD *asInit(_QWORD *a1, const char *a2, ...)
{
void *v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

a1[2] = 16LL;
v2 = calloc(1uLL, 0x10uLL);
a1[1] = 0LL;
*a1 = v2;
if ( a2 )
{
va_start(va, a2);
asSetV(a1, a2, (const __m128i *)va);
}
return a1;
}

canonical_decompiled_code:
_QWORD *func9(_QWORD *a1, const char *a2, ...)
{
void *v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

a1[2] = 16LL;
v2 = calloc(1uLL, 0x10uLL);
a1[1] = 0LL;
*a1 = v2;
if ( a2 )
{
va_start(va, a2);
asSetV(a1, a2, (const __m128i *)va);
}
return a1;
}

original_code:
astring *asInit(astring *str, const char *fmt, ...)
{
    str->size = 16;
    str->data = calloc(1, str->size);
    str->used = 0;
    if (fmt) {
        va_list ap;
        __builtin_va_start(ap,fmt);
        asSetV(str, fmt, ap);
        __builtin_va_end(ap);
    }
    return str;
}

canonical_original_code:
struct astring *asInit(struct astring *str, char *fmt, ...)
{
    str->size = 16;
    str->data = calloc(1, str->size);
    str->used = 0;
    if (fmt) {
        __builtin_va_list ap;
        __builtin_va_start(ap,fmt);
        asSetV(str, fmt, ap);
        __builtin_va_end(ap);
    }
    return str;
}


asSetF

decompiled_code:
_QWORD *asSetF(_QWORD *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
asSetV(a1, a2, (const __m128i *)va);
return a1;
}

canonical_decompiled_code:
_QWORD *func10(_QWORD *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
asSetV(a1, a2, (const __m128i *)va);
return a1;
}

original_code:
__attribute__((format (printf, 2, 3)))
astring *asSetF(astring *str, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    asSetV(str, fmt, ap);
    __builtin_va_end(ap);
    return str;
}

canonical_original_code:
struct astring *asSetF(struct astring *str, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    asSetV(str, fmt, ap);
    __builtin_va_end(ap);
    return str;
}


asLen

decompiled_code:
__int64 __fastcall asLen(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
int asLen(const astring *str)
{
    return str->used;
}

canonical_original_code:
int asLen(struct astring *str)
{
    return str->used;
}


asIsEmpty

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

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

original_code:
int asIsEmpty(const astring *str)
{
    return str->used == 0;
}

canonical_original_code:
int asIsEmpty(struct astring *str)
{
    return str->used == 0;
}


asStrip

decompiled_code:
char **__fastcall asStrip(char **a1, unsigned __int64 a2, unsigned __int64 a3)
{
char *v4; // rdi
char *v6; // rdx
char *v7; // rbx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rbp
char *v10; // rdx
char *v11; // rax

v4 = *a1;
if ( v4 )
{
v6 = a1[1];
v7 = (char *)a2;
if ( (unsigned __int64)v6 <= a2 )
v7 = a1[1];
v8 = v6 - v7;
if ( v8 <= a3 )
a3 = v8;
v9 = a3;
memmove(v4, &v7[(_QWORD)v4], v8 - a3);
v10 = *a1;
v11 = (char *)(a1[1] - v7 - v9);
a1[1] = v11;
v11[(_QWORD)v10] = 0;
}
return a1;
}

canonical_decompiled_code:
char **__fastcall func13(char **a1, unsigned __int64 a2, unsigned __int64 a3)
{
char *v4; // rdi
char *v6; // rdx
char *v7; // rbx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rbp
char *v10; // rdx
char *v11; // rax

v4 = *a1;
if ( v4 )
{
v6 = a1[1];
v7 = (char *)a2;
if ( (unsigned __int64)v6 <= a2 )
v7 = a1[1];
v8 = v6 - v7;
if ( v8 <= a3 )
a3 = v8;
v9 = a3;
memmove(v4, &v7[(_QWORD)v4], v8 - a3);
v10 = *a1;
v11 = (char *)(a1[1] - v7 - v9);
a1[1] = v11;
v11[(_QWORD)v10] = 0;
}
return a1;
}

original_code:
astring *asStrip(astring *str, size_t left, size_t right)
{
    if (str->data == ((void *)0)) return str;
    if (left > str->used) left = str->used;
    if (right > str->used - left) right = str->used - left;
    memmove(str->data, str->data + left, str->used - left - right);
    str->used -= (left + right);
    *(str->data + str->used) = '\0';
    return str;
}

canonical_original_code:
struct astring *asStrip(struct astring *str, unsigned long left, unsigned long right)
{
    if (str->data == ((void *)0)) return str;
    if (left > str->used) left = str->used;
    if (right > str->used - left) right = str->used - left;
    memmove(str->data, str->data + left, str->used - left - right);
    str->used -= (left + right);
    *(str->data + str->used) = '\0';
    return str;
}

variable_types:
left
unsigned long

variable_types:
right
unsigned long


asCompare

decompiled_code:
int __fastcall asCompare(const char **a1, const char **a2)
{
int v2; // ebx
const char *v3; // r12
const char *v4; // rax

v2 = asLen((__int64)a1);
if ( v2 < (int)asLen((__int64)a2) )
return -1;
v3 = asGet(a2);
v4 = asGet(a1);
return memcmp(v4, v3, v2);
}

canonical_decompiled_code:
int __fastcall func14(const char **a1, const char **a2)
{
int v2; // ebx
const char *v3; // r12
const char *v4; // rax

v2 = func11((__int64)a1);
if ( v2 < (int)func11((__int64)a2) )
return -1;
v3 = func6(a2);
v4 = func6(a1);
return memcmp(v4, v3, v2);
}

original_code:
int asCompare(const astring *left, const astring *right)
{
    int len1 = asLen(left);
    int len2 = asLen(right);
    if (len1 < len2)
        return -1;
    else if (len2 > len1)
        return 1;
    else
        return memcmp(asGet(left), asGet(right), len1);
}

canonical_original_code:
int asCompare(struct astring *left, struct astring *right)
{
    int len1 = asLen(left);
    int len2 = asLen(right);
    if (len1 < len2)
        return -1;
    else if (len2 > len1)
        return 1;
    else
        return memcmp(asGet(left), asGet(right), len1);
}

variable_types:
right
struct astring *


asStartsWith

decompiled_code:
bool asStartsWith(const char **a1, const char *a2, ...)
{
char *v2; // r13
size_t v3; // r12
const char *v4; // rax
int v5; // ebx
char *s; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
vasprintf(&s, a2, arg);
v2 = s;
v3 = strlen(s);
v4 = asGet(a1);
v5 = strncmp(v4, v2, v3);
free(s);
return v5 == 0;
}

canonical_decompiled_code:
bool func15(const char **a1, const char *a2, ...)
{
char *v2; // r13
size_t v3; // r12
const char *v4; // rax
int v5; // ebx
char *s; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
vasprintf(&s, a2, arg);
v2 = s;
v3 = strlen(s);
v4 = func6(a1);
v5 = strncmp(v4, v2, v3);
free(s);
return v5 == 0;
}

original_code:
__attribute__((format (printf, 2, 3)))
_Bool asStartsWith(const astring *str, const char *fmt, ...)
{
    va_list ap;
    char *pat;
    int r;
    __builtin_va_start(ap,fmt);
    r = vasprintf(&pat, fmt, ap);
    __builtin_va_end(ap);
    r = strncmp(asGet(str), pat, strlen(pat));
    free(pat);
    return r == 0;
}

canonical_original_code:
_Bool asStartsWith(struct astring *str, char *fmt, ...)
{
    __builtin_va_list ap;
    char *pat;
    int r;
    __builtin_va_start(ap,fmt);
    r = vasprintf(&pat, fmt, ap);
    __builtin_va_end(ap);
    r = strncmp(asGet(str), pat, strlen(pat));
    free(pat);
    return r == 0;
}

variable_types:
pat
char *


asEndsWith

decompiled_code:
bool asEndsWith(const char **a1, const char *a2, ...)
{
char *v2; // r13
const char *v3; // rbp
int v4; // eax
char *v5; // r12
__int64 v6; // rbx
size_t v7; // rax
char *s; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
vasprintf(&s, a2, arg);
v2 = s;
v3 = asGet(a1);
v4 = asLen((__int64)a1);
v5 = s;
v6 = v4;
v7 = strlen(s);
LODWORD(v6) = strcmp(&v3[v6 - v7], v2);
free(v5);
return (_DWORD)v6 == 0;
}

canonical_decompiled_code:
bool func16(const char **a1, const char *a2, ...)
{
char *v2; // r13
const char *v3; // rbp
int v4; // eax
char *v5; // r12
__int64 v6; // rbx
size_t v7; // rax
char *s; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
vasprintf(&s, a2, arg);
v2 = s;
v3 = func6(a1);
v4 = func11((__int64)a1);
v5 = s;
v6 = v4;
v7 = strlen(s);
LODWORD(v6) = strcmp(&v3[v6 - v7], v2);
free(v5);
return (_DWORD)v6 == 0;
}

original_code:
__attribute__((format (printf, 2, 3)))
_Bool asEndsWith(const astring *str, const char *fmt, ...)
{
    va_list ap;
    char *pat;
    int r;
    __builtin_va_start(ap,fmt);
    r = vasprintf(&pat, fmt, ap);
    __builtin_va_end(ap);
    r = strcmp(asGet(str) + asLen(str) - strlen(pat), pat);
    free(pat);
    return r == 0;
}

canonical_original_code:
_Bool asEndsWith(struct astring *str, char *fmt, ...)
{
    __builtin_va_list ap;
    char *pat;
    int r;
    __builtin_va_start(ap,fmt);
    r = vasprintf(&pat, fmt, ap);
    __builtin_va_end(ap);
    r = strcmp(asGet(str) + asLen(str) - strlen(pat), pat);
    free(pat);
    return r == 0;
}

variable_types: r int


tsNormalized

original_code:
struct timespec tsNormalized(struct timespec ts)
{
    struct timespec dup = ts;
    while (dup.tv_nsec < 0) {
        dup.tv_sec--;
        dup.tv_nsec += 1000000000L;
    }
    while (dup.tv_nsec >= 1000000000L) {
        dup.tv_sec++;
        dup.tv_nsec -= 1000000000L;
    }
    return dup;
}

variable_types:
ts
struct timespec

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


tsNormalize

decompiled_code:
__int64 __fastcall tsNormalize(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = tsNormalized(*a1, a1[1]);
*a1 = result;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = func0(*a1, a1[1]);
*a1 = result;
a1[1] = v2;
return result;
}

original_code:
void tsNormalize(struct timespec *ts)
{
    *ts = tsNormalized(*ts);
}

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


tsMake

decompiled_code:
__int64 __fastcall tsMake(__int64 a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a1;
v3[1] = a2;
tsNormalize(v3);
return v3[0];
}

original_code:
struct timespec tsMake(time_t sec, long nsec)
{
    struct timespec t = {
        .tv_sec = sec,
        .tv_nsec = nsec
    };
    tsNormalize(&t);
    return t;
}

canonical_original_code:
struct timespec tsMake(long sec, long nsec)
{
    struct timespec t = {
        .tv_sec = sec,
        .tv_nsec = nsec
    };
    tsNormalize(&t);
    return t;
}

variable_types: sec long

variable_types: nsec long

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


tsNow

decompiled_code:
__time_t tsNow()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

v1 = 0LL;
clock_gettime(0, &v1);
return v1.tv_sec;
}

canonical_decompiled_code:
__time_t func3()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

v1 = 0LL;
clock_gettime(0, &v1);
return v1.tv_sec;
}

original_code:
struct timespec tsNow(void)
{
    struct timespec ts = { 0 };
    clock_gettime(0, &ts);
    return ts;
}

canonical_original_code:
struct timespec tsNow()
{
    struct timespec ts = { 0 };
    clock_gettime(0, &ts);
    return ts;
}

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


tsCompare

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

result = 0xFFFFFFFFLL;
if ( a1 >= a3 )
{
result = 1LL;
if ( a1 <= a3 )
{
result = a2 > a4;
if ( a2 < a4 )
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 >= a3 )
{
result = 1LL;
if ( a1 <= a3 )
{
result = a2 > a4;
if ( a2 < a4 )
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int tsCompare(struct timespec t1, struct timespec t0)
{
    if (t1.tv_sec < t0.tv_sec) {
        return -1;
    }
    else if (t1.tv_sec > t0.tv_sec) {
        return 1;
    }
    else if (t1.tv_nsec < t0.tv_nsec) {
        return -1;
    }
    else if (t1.tv_nsec > t0.tv_nsec) {
        return 1;
    }
    else {
        return 0;
    }
}


tsDelta

decompiled_code:
double __fastcall tsDelta(int a1, int a2, int a3, int a4)
{
return (double)(a2 - a4) / 1000000000.0 + (double)(a1 - a3);
}

canonical_decompiled_code:
double __fastcall func5(int a1, int a2, int a3, int a4)
{
return (double)(a2 - a4) / 1000000000.0 + (double)(a1 - a3);
}

original_code:
double tsDelta(struct timespec t1, struct timespec t0)
{
    return t1.tv_sec - t0.tv_sec
         + (double) (t1.tv_nsec - t0.tv_nsec) / 1000000000L;
}


tsDec

decompiled_code:
__int64 __fastcall tsDec(__int64 a1, __int64 a2, double a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a1 - (unsigned int)(int)a3;
v4[1] = a2 - (unsigned int)(int)(fmod(a3, 1.0) * 1000000000.0);
tsNormalize(v4);
return v4[0];
}

original_code:
struct timespec tsDec(struct timespec ts, double seconds)
{
    ts.tv_sec -= (time_t) seconds;
    ts.tv_nsec -= (long) (1000000000L * fmod(seconds, 1));
    tsNormalize(&ts);
    return ts;
}

canonical_original_code:
struct timespec tsDec(struct timespec ts, double seconds)
{
    ts.tv_sec -= (long) seconds;
    ts.tv_nsec -= (long) (1000000000L * fmod(seconds, 1));
    tsNormalize(&ts);
    return ts;
}

variable_types: seconds double


tsInc

decompiled_code:
__int64 __fastcall tsInc(__int64 a1, __int64 a2, double a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = (unsigned int)(int)a3 + a1;
v4[1] = (unsigned int)(int)(fmod(a3, 1.0) * 1000000000.0) + a2;
tsNormalize(v4);
return v4[0];
}

original_code:
struct timespec tsInc(struct timespec ts, double seconds)
{
    ts.tv_sec += (time_t) seconds;
    ts.tv_nsec += (long) (1000000000L * fmod(seconds, 1));
    tsNormalize(&ts);
    return ts;
}

canonical_original_code:
struct timespec tsInc(struct timespec ts, double seconds)
{
    ts.tv_sec += (long) seconds;
    ts.tv_nsec += (long) (1000000000L * fmod(seconds, 1));
    tsNormalize(&ts);
    return ts;
}


tsToDouble

decompiled_code:
double __fastcall tsToDouble(int a1, int a2)
{
return (double)a2 / 1000000000.0 + (double)a1;
}

canonical_decompiled_code:
double __fastcall func9(int a1, int a2)
{
return (double)a2 / 1000000000.0 + (double)a1;
}

original_code:
double tsToDouble(struct timespec ts)
{
    return (double) ts.tv_sec + (double) ts.tv_nsec / 1000000000L;
}


tsFromTimeval

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

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

original_code:
struct timespec tsFromTimeval(struct timeval tv)
{
    struct timespec ts = {
        .tv_sec = tv.tv_sec,
        .tv_nsec = tv.tv_usec * 1000
    };
    return ts;
}

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


tsFormatC

decompiled_code:
// attributes: thunk
__int64 tsFormatC()
{
return t_format_c();
}

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

original_code:
const char *tsFormatC(const struct timespec ts, const char *tz,
                      const char *fmt)
{
    return t_format_c(ts.tv_sec, ts.tv_nsec, tz, fmt);
}

canonical_original_code:
char *tsFormatC(struct timespec ts, char *tz, char *fmt)
{
    return t_format_c(ts.tv_sec, ts.tv_nsec, tz, fmt);
}

variable_types:
tz
char *


tsFormat

decompiled_code:
char *tsFormat()
{
const char *v0; // rax

v0 = (const char *)tsFormatC();
return strdup(v0);
}

canonical_decompiled_code:
char *func12()
{
const char *v0; // rax

v0 = (const char *)func11();
return strdup(v0);
}

original_code:
char *tsFormat(const struct timespec ts, const char *tz, const char *fmt)
{
    return strdup(tsFormatC(ts, tz, fmt));
}

canonical_original_code:
char *tsFormat(struct timespec ts, char *tz, char *fmt)
{
    return strdup(tsFormatC(ts, tz, fmt));
}


decompiled_code:
__int64 __fastcall find_branch_between(__int64 a1, unsigned __int8 a2, int a3, int a4)
{
__int64 v4; // r8
unsigned __int8 v5; // r9
unsigned __int8 v6; // al
int v7; // eax
unsigned int v8; // er9
unsigned __int8 *v9; // r8

while ( 1 )
{
if ( a3 > a4 )
return (unsigned int)-1;
v4 = *(_QWORD *)(a1 + 16);
v5 = **(_BYTE **)(v4 + 8LL * a4);
v6 = **(_BYTE **)(v4 + 8LL * a3);
if ( v5 < a2 || v6 > a2 )
return (unsigned int)-1;
if ( v6 == a2 )
return (unsigned int)a3;
if ( v5 == a2 )
break;
v7 = (a3 + a4) / 2;
v8 = v7;
v9 = *(unsigned __int8 **)(v4 + 8LL * v7);
if ( a2 == *v9 )
return v8;
if ( a2 >= *v9 )
{
--a4;
a3 = v7 + 1;
}
else
{
a4 = v7 - 1;
++a3;
}
}
return (unsigned int)a4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, int a3, int a4)
{
__int64 v4; // r8
unsigned __int8 v5; // r9
unsigned __int8 v6; // al
int v7; // eax
unsigned int v8; // er9
unsigned __int8 *v9; // r8

while ( 1 )
{
if ( a3 > a4 )
return (unsigned int)-1;
v4 = *(_QWORD *)(a1 + 16);
v5 = **(_BYTE **)(v4 + 8LL * a4);
v6 = **(_BYTE **)(v4 + 8LL * a3);
if ( v5 < a2 || v6 > a2 )
return (unsigned int)-1;
if ( v6 == a2 )
return (unsigned int)a3;
if ( v5 == a2 )
break;
v7 = (a3 + a4) / 2;
v8 = v7;
v9 = *(unsigned __int8 **)(v4 + 8LL * v7);
if ( a2 == *v9 )
return v8;
if ( a2 >= *v9 )
{
--a4;
a3 = v7 + 1;
}
else
{
a4 = v7 - 1;
++a3;
}
}
return (unsigned int)a4;
}

original_code:
static int find_branch_between(const Tree *tree, uint8_t id,
        int low_index, int high_index)
{
    if (low_index > high_index) return -1;
    uint8_t low_id = tree->branch[low_index]->id;
    uint8_t high_id = tree->branch[high_index]->id;
    if (id < low_id) return -1;
    if (id > high_id) return -1;
    if (id == low_id) return low_index;
    if (id == high_id) return high_index;
    int middle_index = (low_index + high_index) / 2;
    uint8_t middle_id = tree->branch[middle_index]->id;
    if (id == middle_id)
        return middle_index;
    else if (id < middle_id)
        return find_branch_between(tree, id, low_index + 1, middle_index - 1);
    else
        return find_branch_between(tree, id, middle_index + 1, high_index - 1);
}

canonical_original_code:
static int find_branch_between(struct Tree *tree, unsigned char id, int low_index, int high_index)
{
    if (low_index > high_index) return -1;
    unsigned char low_id = tree->branch[low_index]->id;
    unsigned char high_id = tree->branch[high_index]->id;
    if (id < low_id) return -1;
    if (id > high_id) return -1;
    if (id == low_id) return low_index;
    if (id == high_id) return high_index;
    int middle_index = (low_index + high_index) / 2;
    unsigned char middle_id = tree->branch[middle_index]->id;
    if (id == middle_id)
        return middle_index;
    else if (id < middle_id)
        return find_branch_between(tree, id, low_index + 1, middle_index - 1);
    else
        return find_branch_between(tree, id, middle_index + 1, high_index - 1);
}

variable_types: struct Tree { unsigned char id; void *data; struct Tree **branch; int branch_count; } *

variable_types:
id
unsigned char


decompiled_code:
__int64 __fastcall find_branch(__int64 a1, unsigned __int8 a2)
{
return find_branch_between(a1, a2, 0, *(_DWORD *)(a1 + 24) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 a2)
{
return func0(a1, a2, 0, *(_DWORD *)(a1 + 24) - 1);
}

original_code:
static int find_branch(const Tree *tree, uint8_t id)
{
    return find_branch_between(tree, id, 0, tree->branch_count - 1);
}

canonical_original_code:
static int find_branch(struct Tree *tree, unsigned char id)
{
    return find_branch_between(tree, id, 0, tree->branch_count - 1);
}

user_defined_types: struct Tree { unsigned char id; void *data; struct Tree **branch; int branch_count; }


decompiled_code:
__int64 __fastcall find_leaf(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v3; // r11
unsigned __int8 *v4; // rbx
__int64 v5; // rdx
int v6; // eax
__int64 v7; // r11

if ( !a3 )
return a1;
v3 = a2;
v4 = &a2[a3];
do
{
v6 = find_branch(a1, *v3);
if ( v6 == -1 )
return 0LL;
v5 = *(_QWORD *)(a1 + 16);
v3 = (unsigned __int8 *)(v7 + 1);
a1 = *(_QWORD *)(v5 + 8LL * v6);
}
while ( v3 != v4 );
return *(_QWORD *)(v5 + 8LL * v6);
}

original_code:
static Tree *find_leaf(Tree *tree, const void *key, size_t key_size)
{
    if (key_size == 0) return tree;
    uint8_t id = ((uint8_t *) key)[0];
    int index = find_branch(tree, id);
    if (index == -1) {
        return ((void *)0);
    }
    else {
        return find_leaf(tree->branch[index],
                         ((uint8_t *) key) + 1, key_size - 1);
    }
}

canonical_original_code:
static struct Tree *find_leaf(struct Tree *tree, void *key, unsigned long key_size)
{
    if (key_size == 0) return tree;
    unsigned char id = ((uint8_t *) key)[0];
    int index = find_branch(tree, id);
    if (index == -1) {
        return ((void *)0);
    }
    else {
        return find_leaf(tree->branch[index],
                         ((unsigned char *) key) + 1, key_size - 1);
    }
}

variable_types:
tree
struct Tree *

variable_types:
key
void *

variable_types: index int

return_type: struct Tree { unsigned char id; void *data; struct Tree **branch; int branch_count; } *


original_code:
static void insert_branch(Tree *tree, Tree *branch, int at_index)
{
    tree->branch = realloc(tree->branch,
            (tree->branch_count + 1) * sizeof(Tree *));
    memmove(tree->branch + at_index + 1,
            tree->branch + at_index,
            (tree->branch_count - at_index) * sizeof(Tree *));
    tree->branch[at_index] = branch;
    tree->branch_count++;
}

canonical_original_code:
static void insert_branch(struct Tree *tree, struct Tree *branch, int at_index)
{
    tree->branch = realloc(tree->branch,
            (tree->branch_count + 1) * sizeof(struct Tree *));
    memmove(tree->branch + at_index + 1,
            tree->branch + at_index,
            (tree->branch_count - at_index) * sizeof(struct Tree *));
    tree->branch[at_index] = branch;
    tree->branch_count++;
}

variable_types:
branch
struct Tree *


decompiled_code:
__int64 __fastcall find_or_add_leaf(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
int v5; // eax
unsigned __int8 v6; // r11

v3 = &a2[a3];
if ( a3 )
{
v4 = a2;
do
{
while ( 1 )
{
v5 = find_branch(a1, *v4);
if ( v5 == -1 )
break;
++v4;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v5);
if ( v4 == v3 )
return a1;
}
++v4;
a1 = add_branch(a1, v6);
}
while ( v4 != v3 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
int v5; // eax
unsigned __int8 v6; // r11

v3 = &a2[a3];
if ( a3 )
{
v4 = a2;
do
{
while ( 1 )
{
v5 = func1(a1, *v4);
if ( v5 == -1 )
break;
++v4;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v5);
if ( v4 == v3 )
return a1;
}
++v4;
a1 = func4(a1, v6);
}
while ( v4 != v3 );
}
return a1;
}

original_code:
static Tree *find_or_add_leaf(Tree *tree, const void *key, size_t key_size)
{
    if (key_size == 0) return tree;
    uint8_t id = ((uint8_t *) key)[0];
    int index = find_branch(tree, id);
    Tree *branch;
    if (index == -1) {
        branch = add_branch(tree, id);
    }
    else {
        branch = tree->branch[index];
    }
    return find_or_add_leaf(branch, ((uint8_t *) key) + 1, key_size - 1);
}

canonical_original_code:
static struct Tree *find_or_add_leaf(struct Tree *tree, void *key, unsigned long key_size)
{
    if (key_size == 0) return tree;
    unsigned char id = ((uint8_t *) key)[0];
    int index = find_branch(tree, id);
    struct Tree *branch;
    if (index == -1) {
        branch = add_branch(tree, id);
    }
    else {
        branch = tree->branch[index];
    }
    return find_or_add_leaf(branch, ((unsigned char *) key) + 1, key_size - 1);
}


decompiled_code:
void __fastcall destroy_iter_node(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
static void destroy_iter_node(TreeIterNode *node)
{
    free(node->key);
    free(node);
}

canonical_original_code:
static void destroy_iter_node(struct TreeIterNode *node)
{
    free(node->key);
    free(node);
}

variable_types: struct TreeIterNode { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List { struct ListNode *head; struct ListNode *tail; int length; } *list; } _node; char *key; unsigned long key_size; } *

user_defined_types: struct TreeIterNode { struct ListNode _node; char *key; unsigned long key_size; }


original_code:
static void collect_leaves(const Tree *branch,
        uint8_t *key, size_t key_size, List *nodes)
{
    uint8_t sub_key[key_size + 1];
    memcpy(sub_key, key, key_size);
    for (int i = 0; i < branch->branch_count; i++) {
        Tree *sub_branch = branch->branch[i];
        sub_key[key_size] = sub_branch->id;
        if (sub_branch->data != ((void *)0)) {
            TreeIterNode *node = calloc(1, sizeof(TreeIterNode));
            node->key = memdup(sub_key, key_size + 1);
            node->key_size = key_size + 1;
            _listAppendTail((nodes), &(node)->_node);
        }
        collect_leaves(sub_branch, sub_key, key_size + 1, nodes);
    }
}

canonical_original_code:
static void collect_leaves(struct Tree *branch, unsigned char *key, unsigned long key_size, struct List *nodes)
{
    unsigned char sub_key[-1];
    memcpy(sub_key, key, key_size);
    for (int i = 0; i < branch->branch_count; i++) {
        struct Tree *sub_branch = branch->branch[i];
        sub_key[key_size] = sub_branch->id;
        if (sub_branch->data != ((void *)0)) {
            struct TreeIterNode *node = calloc(1, sizeof(TreeIterNode));
            node->key = memdup(sub_key, key_size + 1);
            node->key_size = key_size + 1;
            _listAppendTail((nodes), &(node)->_node);
        }
        collect_leaves(sub_branch, sub_key, key_size + 1, nodes);
    }
}

variable_types:
key
unsigned char *

variable_types: struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } *

variable_types: i int


decompiled_code:
void __fastcall destroy_iterator(void *ptr)
{
void *v2; // rdi

while ( 1 )
{
v2 = (void *)listRemoveHead(ptr);
if ( !v2 )
break;
destroy_iter_node(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
void *v2; // rdi

while ( 1 )
{
v2 = (void *)listRemoveHead(ptr);
if ( !v2 )
break;
func6(v2);
}
free(ptr);
}

original_code:
static void destroy_iterator(TreeIter *iter)
{
    TreeIterNode *node;
    while ((node = listRemoveHead(&iter->nodes)) != ((void *)0)) {
        destroy_iter_node(node);
    }
    free(iter);
}

canonical_original_code:
static void destroy_iterator(struct TreeIter *iter)
{
    struct TreeIterNode *node;
    while ((node = listRemoveHead(&iter->nodes)) != ((void *)0)) {
        destroy_iter_node(node);
    }
    free(iter);
}

variable_types: struct TreeIter { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } nodes; } *


original_code:
static void tree_prune(Tree *tree)
{
    for (int i = 0; i < tree->branch_count; i++) {
        Tree *branch = tree->branch[i];
        tree_prune(branch);
        if (branch->data == ((void *)0) && branch->branch_count == 0) {
            remove_branch(tree, i);
            free(branch);
        }
    }
}

canonical_original_code:
static void tree_prune(struct Tree *tree)
{
    for (int i = 0; i < tree->branch_count; i++) {
        struct Tree *branch = tree->branch[i];
        tree_prune(branch);
        if (branch->data == ((void *)0) && branch->branch_count == 0) {
            remove_branch(tree, i);
            free(branch);
        }
    }
}


decompiled_code:
__int64 __fastcall delete_leaf(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
__int64 result; // rax
int v4; // eax
__int64 v5; // r11
int v6; // er12
__int64 v7; // r13

if ( !a3 )
{
if ( *(_QWORD *)(a1 + 8) )
{
*(_QWORD *)(a1 + 8) = 0LL;
return 0LL;
}
return 1LL;
}
v4 = find_branch(a1, *a2);
v6 = v4;
if ( v4 == -1 )
return 1LL;
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v4);
result = delete_leaf(v7, a2 + 1, v5 - 1);
if ( (_DWORD)result )
return 1LL;
if ( !*(_QWORD *)(v7 + 8) && !*(_DWORD *)(v7 + 24) )
{
remove_branch_isra_0(a1, v6);
free((void *)v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
__int64 result; // rax
int v4; // eax
__int64 v5; // r11
int v6; // er12
__int64 v7; // r13

if ( !a3 )
{
if ( *(_QWORD *)(a1 + 8) )
{
*(_QWORD *)(a1 + 8) = 0LL;
return 0LL;
}
return 1LL;
}
v4 = func1(a1, *a2);
v6 = v4;
if ( v4 == -1 )
return 1LL;
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v4);
result = func11(v7, a2 + 1, v5 - 1);
if ( (_DWORD)result )
return 1LL;
if ( !*(_QWORD *)(v7 + 8) && !*(_DWORD *)(v7 + 24) )
{
func9(a1, v6);
free((void *)v7);
result = 0LL;
}
return result;
}

original_code:
static int delete_leaf(Tree *tree, const void *key, size_t key_size)
{
    if (key_size > 0) {
        uint8_t id = ((uint8_t *) key)[0];
        int index = find_branch(tree, id);
        if (index == -1) return 1;
        Tree *branch = tree->branch[index];
        if (delete_leaf(branch, ((uint8_t *) key) + 1, key_size - 1) != 0) {
            return 1;
        }
        if (branch->data == ((void *)0) && branch->branch_count == 0) {
            remove_branch(tree, index);
            free(branch);
        }
        return 0;
    }
    else {
        if (tree->data == ((void *)0)) {
            return 1;
        }
        else {
            tree->data = ((void *)0);
            return 0;
        }
    }
}

canonical_original_code:
static int delete_leaf(struct Tree *tree, void *key, unsigned long key_size)
{
    if (key_size > 0) {
        unsigned char id = ((uint8_t *) key)[0];
        int index = find_branch(tree, id);
        if (index == -1) return 1;
        struct Tree *branch = tree->branch[index];
        if (delete_leaf(branch, ((unsigned char *) key) + 1, key_size - 1) != 0) {
            return 1;
        }
        if (branch->data == ((void *)0) && branch->branch_count == 0) {
            remove_branch(tree, index);
            free(branch);
        }
        return 0;
    }
    else {
        if (tree->data == ((void *)0)) {
            return 1;
        }
        else {
            tree->data = ((void *)0);
            return 0;
        }
    }
}


treeCreate

decompiled_code:
void *treeCreate()
{
return calloc(1uLL, 0x20uLL);
}

canonical_decompiled_code:
void *func12()
{
return calloc(1uLL, 0x20uLL);
}

original_code:
Tree *treeCreate(void)
{
    Tree *tree = calloc(1, sizeof(*tree));
    return tree;
}

canonical_original_code:
struct Tree *treeCreate()
{
    struct Tree *tree = calloc(1, sizeof(*tree));
    return tree;
}


treeAdd

decompiled_code:
__int64 __fastcall treeAdd(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = find_or_add_leaf(a1, a3, a4);
result = dbgAssert(stderr, *(_QWORD *)(v4 + 8) == 0LL, "tree.c", 250LL, "treeAdd", "Key already used.\n");
*(_QWORD *)(v4 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = func5(a1, a3, a4);
result = dbgAssert(stderr, *(_QWORD *)(v4 + 8) == 0LL, "tree.c", 250LL, "treeAdd", "Key already used.\n");
*(_QWORD *)(v4 + 8) = a2;
return result;
}

original_code:
void treeAdd(Tree *tree, const void *data, const void *key, size_t key_size)
{
    Tree *leaf = find_or_add_leaf(tree, key, key_size);
    _dbgAssert(stderr, leaf->data == ((void *)0), "tree.c", 250, __func__, "Key already used.\n");
    leaf->data = data;
}

canonical_original_code:
void treeAdd(struct Tree *tree, void *data, void *key, unsigned long key_size)
{
    struct Tree *leaf = find_or_add_leaf(tree, key, key_size);
    _dbgAssert(stderr, leaf->data == ((void *)0), "tree.c", 250, __func__, "Key already used.\n");
    leaf->data = data;
}

variable_types:
data
void *


treeGet

decompiled_code:
__int64 __fastcall treeGet(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
__int64 result; // rax

result = find_leaf(a1, a2, a3);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
__int64 result; // rax

result = func2(a1, a2, a3);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
void *treeGet(Tree *tree, const void *key, size_t key_size)
{
    Tree *leaf = find_leaf(tree, key, key_size);
    return leaf ? (void *) leaf->data : ((void *)0);
}

canonical_original_code:
void *treeGet(struct Tree *tree, void *key, unsigned long key_size)
{
    struct Tree *leaf = find_leaf(tree, key, key_size);
    return leaf ? (void *) leaf->data : ((void *)0);
}

return_type: void *


treeSet

decompiled_code:
__int64 __fastcall treeSet(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
__int64 v5; // rax
_BOOL8 v6; // rsi
__int64 v7; // rbx
__int64 result; // rax

v5 = find_leaf(a1, a3, a4);
v6 = 0LL;
v7 = v5;
if ( v5 )
v6 = *(_QWORD *)(v5 + 8) != 0LL;
result = dbgAssert(stderr, v6, "tree.c", 273LL, "treeSet", "Key doesn't exist.\n");
*(_QWORD *)(v7 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
__int64 v5; // rax
_BOOL8 v6; // rsi
__int64 v7; // rbx
__int64 result; // rax

v5 = func2(a1, a3, a4);
v6 = 0LL;
v7 = v5;
if ( v5 )
v6 = *(_QWORD *)(v5 + 8) != 0LL;
result = dbgAssert(stderr, v6, "tree.c", 273LL, "treeSet", "Key doesn't exist.\n");
*(_QWORD *)(v7 + 8) = a2;
return result;
}

original_code:
void treeSet(Tree *tree, const void *data, const void *key, size_t key_size)
{
    Tree *leaf = find_leaf(tree, key, key_size);
    _dbgAssert(stderr, leaf != ((void *)0) && leaf->data != ((void *)0), "tree.c", 273, __func__, "Key doesn't exist.\n");
    leaf->data = data;
}

canonical_original_code:
void treeSet(struct Tree *tree, void *data, void *key, unsigned long key_size)
{
    struct Tree *leaf = find_leaf(tree, key, key_size);
    _dbgAssert(stderr, leaf != ((void *)0) && leaf->data != ((void *)0), "tree.c", 273, __func__, "Key doesn't exist.\n");
    leaf->data = data;
}


treeIterate

decompiled_code:
void *__fastcall treeIterate(__int64 a1)
{
void *v1; // r12
void *v2; // rsi

v1 = calloc(1uLL, 0x18uLL);
v2 = malloc(0LL);
collect_leaves(a1, v2, 0LL, (__int64)v1);
free(v2);
if ( !(unsigned int)listIsEmpty(v1) )
return v1;
destroy_iterator(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func16(__int64 a1)
{
void *v1; // r12
void *v2; // rsi

v1 = calloc(1uLL, 0x18uLL);
v2 = malloc(0LL);
func7(a1, v2, 0LL, (__int64)v1);
free(v2);
if ( !(unsigned int)listIsEmpty(v1) )
return v1;
func8(v1);
return 0LL;
}

original_code:
TreeIter *treeIterate(const Tree *tree)
{
    TreeIter *iter = calloc(1, sizeof(TreeIter));
    uint8_t *key = malloc(0);
    collect_leaves(tree, key, 0, &iter->nodes);
    free(key);
    if (listIsEmpty(&iter->nodes)) {
        destroy_iterator(iter);
        return ((void *)0);
    }
    else {
        return iter;
    }
}

canonical_original_code:
struct TreeIter *treeIterate(struct Tree *tree)
{
    struct TreeIter *iter = calloc(1, sizeof(TreeIter));
    unsigned char *key = malloc(0);
    collect_leaves(tree, key, 0, &iter->nodes);
    free(key);
    if (listIsEmpty(&iter->nodes)) {
        destroy_iterator(iter);
        return ((void *)0);
    }
    else {
        return iter;
    }
}

return_type: struct TreeIter { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } nodes; } *


treeIterNext

decompiled_code:
void *__fastcall treeIterNext(void *ptr)
{
void *v1; // rax

v1 = (void *)listRemoveHead(ptr);
destroy_iter_node(v1);
if ( !(unsigned int)listIsEmpty(ptr) )
return ptr;
destroy_iterator(ptr);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func17(void *ptr)
{
void *v1; // rax

v1 = (void *)listRemoveHead(ptr);
func6(v1);
if ( !(unsigned int)listIsEmpty(ptr) )
return ptr;
func8(ptr);
return 0LL;
}

original_code:
TreeIter *treeIterNext(TreeIter *iter)
{
    TreeIterNode *head = listRemoveHead(&iter->nodes);
    destroy_iter_node(head);
    if (listIsEmpty(&iter->nodes)) {
        destroy_iterator(iter);
        return ((void *)0);
    }
    else {
        return iter;
    }
}

canonical_original_code:
struct TreeIter *treeIterNext(struct TreeIter *iter)
{
    struct TreeIterNode *head = listRemoveHead(&iter->nodes);
    destroy_iter_node(head);
    if (listIsEmpty(&iter->nodes)) {
        destroy_iterator(iter);
        return ((void *)0);
    }
    else {
        return iter;
    }
}

variable_types:
iter
struct TreeIter *


treeIterKey

decompiled_code:
__int64 __fastcall treeIterKey(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = listHead();
v3 = *(_QWORD *)(v2 + 32);
result = *(_QWORD *)(v2 + 24);
*a2 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = listHead();
v3 = *(_QWORD *)(v2 + 32);
result = *(_QWORD *)(v2 + 24);
*a2 = v3;
return result;
}

original_code:
const void *treeIterKey(TreeIter *iter, size_t *key_size)
{
    TreeIterNode *head = listHead(&iter->nodes);
    *key_size = head->key_size;
    return head->key;
}

canonical_original_code:
void *treeIterKey(struct TreeIter *iter, unsigned long *key_size)
{
    struct TreeIterNode *head = listHead(&iter->nodes);
    *key_size = head->key_size;
    return head->key;
}


treeIterStop

decompiled_code:
// attributes: thunk
void __fastcall treeIterStop(void *ptr)
{
destroy_iterator(ptr);
}

canonical_decompiled_code:
void __fastcall func19(void *ptr)
{
func8(ptr);
}

original_code:
void treeIterStop(TreeIter *iter)
{
    destroy_iterator(iter);
}

canonical_original_code:
void treeIterStop(struct TreeIter *iter)
{
    destroy_iterator(iter);
}


treeDrop

decompiled_code:
void __fastcall treeDrop(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
int v3; // eax

v3 = delete_leaf(a1, a2, a3);
dbgAssert(stderr, v3 == 0, "tree.c", 407LL, "treeDrop", "Key doesn't exist.\n");
tree_prune(a1);
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
int v3; // eax

v3 = func11(a1, a2, a3);
dbgAssert(stderr, v3 == 0, "tree.c", 407LL, "treeDrop", "Key doesn't exist.\n");
func10(a1);
}

original_code:
void treeDrop(Tree *tree, const void *key, size_t key_size)
{
    int r = delete_leaf(tree, key, key_size);
    _dbgAssert(stderr, r == 0, "tree.c", 407, __func__, "Key doesn't exist.\n");
    tree_prune(tree);
}

canonical_original_code:
void treeDrop(struct Tree *tree, void *key, unsigned long key_size)
{
    int r = delete_leaf(tree, key, key_size);
    _dbgAssert(stderr, r == 0, "tree.c", 407, __func__, "Key doesn't exist.\n");
    tree_prune(tree);
}

variable_types: r int


treeDestroy

decompiled_code:
void __fastcall treeDestroy(void *ptr)
{
treeClear();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func21(void *ptr)
{
func22();
free(ptr);
}

original_code:
void treeDestroy(Tree *tree)
{
    treeClear(tree);
    free(tree);
}

canonical_original_code:
void treeDestroy(struct Tree *tree)
{
    treeClear(tree);
    free(tree);
}


treeClear

original_code:
void treeClear(Tree *tree)
{
    for (int i = 0; i < tree->branch_count; i++) {
        treeDestroy(tree->branch[i]);
    }
    free(tree->branch);
    tree->data = ((void *)0);
    tree->branch = ((void *)0);
    tree->branch_count = 0;
}

canonical_original_code:
void treeClear(struct Tree *tree)
{
    for (int i = 0; i < tree->branch_count; i++) {
        treeDestroy(tree->branch[i]);
    }
    free(tree->branch);
    tree->data = ((void *)0);
    tree->branch = ((void *)0);
    tree->branch_count = 0;
}


decompiled_code:
double *__fastcall m2Make(double *a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm0_8
double *result; // rax

*a1 = v2Make(a2, a4);
a1[1] = a4;
v5 = v2Make(a3, a5);
result = a1;
a1[2] = v5;
a1[3] = a5;
return result;
}

canonical_decompiled_code:
double *__fastcall func0(double *a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm0_8
double *result; // rax

*a1 = v2Make(a2, a4);
a1[1] = a4;
v5 = v2Make(a3, a5);
result = a1;
a1[2] = v5;
a1[3] = a5;
return result;
}

original_code:
Matrix2 m2Make(double xx, double yx,
               double xy, double yy)
{
    Matrix2 m = {
        .c[0] = v2Make(xx, xy),
        .c[1] = v2Make(yx, yy),
    };
    return m;
}

canonical_original_code:
struct Matrix2 m2Make(double xx, double yx, double xy, double yy)
{
    struct Matrix2 m = {
        .c[0] = v2Make(xx, xy),
        .c[1] = v2Make(yx, yy),
    };
    return m;
}

variable_types: xx double

variable_types: yx double

variable_types: xy double

variable_types: yy double

variable_types: struct Matrix2 { struct Vector2 { double r[2]; } c[2]; }

user_defined_types:
struct Matrix2 { struct Vector2 c[2]; }
struct Vector2 { double r[2]; }


decompiled_code:
double *__fastcall m2Identity(double *a1)
{
m2Make(a1, 1.0, 0.0, 0.0, 1.0);
return a1;
}

canonical_decompiled_code:
double *__fastcall func2(double *a1)
{
func0(a1, 1.0, 0.0, 0.0, 1.0);
return a1;
}

original_code:
Matrix2 m2Identity(void)
{
    return m2Make(1, 0,
                  0, 1);
}

canonical_original_code:
struct Matrix2 m2Identity()
{
    return m2Make(1, 0,
                  0, 1);
}

return_type: struct Matrix2 { struct Vector2 { double r[2]; } c[2]; }


decompiled_code:
double *__fastcall m2Transposed(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
m2Make(a1, a10, a11, a12, a13);
return a1;
}

canonical_decompiled_code:
double *__fastcall func3(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
func0(a1, a10, a11, a12, a13);
return a1;
}

original_code:
Matrix2 m2Transposed(Matrix2 m)
{
    return m2Make(
            m.c[0].r[0], m.c[0].r[1],
            m.c[1].r[0], m.c[1].r[1]);
}

canonical_original_code:
struct Matrix2 m2Transposed(struct Matrix2 m)
{
    return m2Make(
            m.c[0].r[0], m.c[0].r[1],
            m.c[1].r[0], m.c[1].r[1]);
}

variable_types:
m
struct Matrix2


decompiled_code:
double *__fastcall m2Transpose(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double *result; // rax
__m128i v10; // xmm1
__m128i v11; // [rsp+0h] [rbp-28h] BYREF
__m128i v12; // [rsp+10h] [rbp-18h] BYREF

result = m2Transposed((double *)v11.m128i_i64, a2, a3, a4, a5, a6, a7, a8, a9, *a1, a1[1], a1[2], a1[3]);
v10 = _mm_loadu_si128(&v12);
*(__m128i *)a1 = _mm_loadu_si128(&v11);
*((__m128i *)a1 + 1) = v10;
return result;
}

canonical_decompiled_code:
double *__fastcall func4(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double *result; // rax
__m128i v10; // xmm1
__m128i v11; // [rsp+0h] [rbp-28h] BYREF
__m128i v12; // [rsp+10h] [rbp-18h] BYREF

result = func3((double *)v11.m128i_i64, a2, a3, a4, a5, a6, a7, a8, a9, *a1, a1[1], a1[2], a1[3]);
v10 = _mm_loadu_si128(&v12);
*(__m128i *)a1 = _mm_loadu_si128(&v11);
*((__m128i *)a1 + 1) = v10;
return result;
}

original_code:
void m2Transpose(Matrix2 *m)
{
    *m = m2Transposed(*m);
}

canonical_original_code:
void m2Transpose(struct Matrix2 *m)
{
    *m = m2Transposed(*m);
}

variable_types: struct Matrix2 { struct Vector2 { double r[2]; } c[2]; } *


decompiled_code:
double __fastcall m2Row(signed int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, __int64 a9)
{
if ( (unsigned int)a1 > 1 )
_assert_fail("row >= 0 && row < 2", "matrix2.c", 0x5Bu, "m2Row");
return v2Make(*((double *)&a7 + a1), *((double *)&a9 + a1));
}

canonical_decompiled_code:
double __fastcall func5(signed int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, __int64 a9)
{
if ( (unsigned int)a1 > 1 )
_assert_fail("row >= 0 && row < 2", "matrix2.c", 0x5Bu, "m2Row");
return v2Make(*((double *)&a7 + a1), *((double *)&a9 + a1));
}

original_code:
Vector2 m2Row(Matrix2 m, int row)
{
    ((void) sizeof ((row >= 0 && row < 2) ? 1 : 0), __extension__ ({ if (row >= 0 && row < 2) ; else __assert_fail ("row >= 0 && row < 2", "matrix2.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    return v2Make(m.c[0].r[row], m.c[1].r[row]);
}

canonical_original_code:
struct Vector2 m2Row(struct Matrix2 m, int row)
{
    ((void) sizeof ((row >= 0 && row < 2) ? 1 : 0), __extension__ ({ if (row >= 0 && row < 2) ; else __assert_fail ("row >= 0 && row < 2", "matrix2.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    return v2Make(m.c[0].r[row], m.c[1].r[row]);
}

variable_types:
m
struct Matrix2 { struct Vector2 c[2]; }

variable_types: row int

return_type: struct Vector2 { double r[2]; }


decompiled_code:
double __fastcall m2Det(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
return a9 * a12 - a10 * a11;
}

canonical_decompiled_code:
double __fastcall func6(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
return a9 * a12 - a10 * a11;
}


original_code:
int m2Invert(Matrix2 *m)
{
    double det = m2Det(*m);
    if (det == 0) {
        return 1;
    }
    *m = m2Inverse(*m, det);
    return 0;
}

canonical_original_code:
int m2Invert(struct Matrix2 *m)
{
    double det = m2Det(*m);
    if (det == 0) {
        return 1;
    }
    *m = m2Inverse(*m, det);
    return 0;
}

variable_types: det double


original_code:
Vector2 m2Applied(Matrix2 m, Vector2 v)
{
    Vector2 res;
    int row;
    for (row = 0; row < 2; row++) {
        res.r[row] = v2Dot(v, m2Row(m, row));
    };
    return res;
}

canonical_original_code:
struct Vector2 m2Applied(struct Matrix2 m, struct Vector2 v)
{
    struct Vector2 res;
    int row;
    for (row = 0; row < 2; row++) {
        res.r[row] = v2Dot(v, m2Row(m, row));
    };
    return res;
}

variable_types:
v
struct Vector2

variable_types:
res
struct Vector2 { double r[2]; }


original_code:
void m2Apply(Matrix2 m, Vector2 *v)
{
    *v = m2Applied(m, *v);
}

canonical_original_code:
void m2Apply(struct Matrix2 m, struct Vector2 *v)
{
    *v = m2Applied(m, *v);
}

variable_types:
v
struct Vector2 *


sqr

decompiled_code:
double __fastcall sqr(double a1)
{
return a1 * a1;
}

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

original_code: static inline double sqr(double x) { return x * x; }

variable_types: x double


decompiled_code:
void g2dVectorNew()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
Vector2D g2dVectorNew(double x, double y)
{
    Vector2D v = { .x = x, .y = y };
    return v;
}

canonical_original_code:
struct Vector2D g2dVectorNew(double x, double y)
{
    struct Vector2D v = { .x = x, .y = y };
    return v;
}

variable_types: y double

variable_types:
v
struct Vector2D { double x; }

return_type: struct Vector2D { double x; }


decompiled_code:
void g2dVectorAdd()
{
g2dVectorNew();
}

canonical_decompiled_code:
void func2()
{
func1();
}

original_code:
Vector2D g2dVectorAdd(Vector2D v1, Vector2D v2)
{
    return g2dVectorNew(v1.x + v2.x, v1.y + v2.y);
}

canonical_original_code:
struct Vector2D g2dVectorAdd(struct Vector2D v1, struct Vector2D v2)
{
    return g2dVectorNew(v1.x + v2.x, v1.y + v2.y);
}


decompiled_code:
void g2dVectorSubtract()
{
g2dVectorNew();
}

canonical_decompiled_code:
void func3()
{
func1();
}

original_code:
Vector2D g2dVectorSubtract(Vector2D v1, Vector2D v2)
{
    return g2dVectorNew(v2.x - v1.x, v2.y - v1.y);
}

canonical_original_code:
struct Vector2D g2dVectorSubtract(struct Vector2D v1, struct Vector2D v2)
{
    return g2dVectorNew(v2.x - v1.x, v2.y - v1.y);
}


decompiled_code:
void g2dVectorMultiply()
{
g2dVectorNew();
}

canonical_decompiled_code:
void func4()
{
func1();
}

original_code:
Vector2D g2dVectorMultiply(Vector2D v, double r)
{
    return g2dVectorNew(v.x * r, v.y * r);
}

canonical_original_code:
struct Vector2D g2dVectorMultiply(struct Vector2D v, double r)
{
    return g2dVectorNew(v.x * r, v.y * r);
}

variable_types:
v
struct Vector2D

variable_types: r double