disHandleReadable

decompiled_code:
__int64 __fastcall disHandleReadable(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 315LL, "disHandleReadable", "unknown file descriptor: %d\n", (unsigned int)a2);
return (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(v2 + 24))(a1, (unsigned int)a2, *(_QWORD *)(v2 + 32));
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 315LL, "disHandleReadable", "unknown file descriptor: %d\n", (unsigned int)a2);
return (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(v2 + 24))(a1, (unsigned int)a2, *(_QWORD *)(v2 + 32));
}

original_code:
void disHandleReadable(Dispatcher *dis, int fd)
{
    DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 315, __func__, "unknown file descriptor: %d\n", fd);
    file->cb(dis, fd, (void *) file->udata);
}

canonical_original_code:
void disHandleReadable(struct Dispatcher *dis, int fd)
{
    struct DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 315, __func__, "unknown file descriptor: %d\n", fd);
    file->cb(dis, fd, (void *) file->udata);
}


disHandleWritable

repo: jaccovanschaik/libjvs

decompiled_code:
ssize_t __fastcall disHandleWritable(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
size_t v3; // r13
const void *v4; // rax
ssize_t result; // rax

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 329LL, "disHandleWritable", "unknown file descriptor: %d\n", (unsigned int)a2);
v3 = bufLen(v2);
v4 = (const void *)bufGet(v2);
result = write(a2, v4, v3);
if ( (int)result > 0 )
result = bufTrim(v2, (int)result, 0LL);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func14(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
size_t v3; // r13
const void *v4; // rax
ssize_t result; // rax

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 329LL, "disHandleWritable", "unknown file descriptor: %d\n", (unsigned int)a2);
v3 = bufLen(v2);
v4 = (const void *)bufGet(v2);
result = write(a2, v4, v3);
if ( (int)result > 0 )
result = bufTrim(v2, (int)result, 0LL);
return result;
}

original_code:
void disHandleWritable(Dispatcher *dis, int fd)
{
    int r;
    DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 329, __func__, "unknown file descriptor: %d\n", fd);
    r = write(fd, bufGet(&file->outgoing), bufLen(&file->outgoing));
    if (r > 0) {
        bufTrim(&file->outgoing, r, 0);
    }
}

canonical_original_code:
void disHandleWritable(struct Dispatcher *dis, int fd)
{
    int r;
    struct DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 329, __func__, "unknown file descriptor: %d\n", fd);
    r = write(fd, bufGet(&file->outgoing), bufLen(&file->outgoing));
    if (r > 0) {
        bufTrim(&file->outgoing, r, 0);
    }
}

variable_types: fd int

variable_types: r int

variable_types: struct DIS_File { struct Buffer { char *data; unsigned long used; unsigned long size; } outgoing; void (*cb)(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, int fd, void *udata); void *udata; } *

return_type: void

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

user_defined_types: struct DIS_File { struct Buffer outgoing; void (*cb)(struct Dispatcher *dis, int fd, void *udata); void *udata; }

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


disHandleFiles

decompiled_code:
void __fastcall disHandleFiles(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int i; // er12
__int64 v8; // rsi

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
while ( 1 )
{
if ( disOwnsFd(a1, (unsigned int)i) && (*(_QWORD *)(a3 + 8LL * (i >> 6)) & (1LL << i)) != 0 )
disHandleReadable(a1, (unsigned int)i);
if ( disOwnsFd(a1, (unsigned int)i) && (*(_QWORD *)(a4 + 8LL * (i >> 6)) & (1LL << i)) != 0 )
break;
if ( a2 == ++i )
return;
}
v8 = (unsigned int)i;
disHandleWritable(a1, v8);
}
}
}

original_code:
void disHandleFiles(Dispatcher *dis, int nfds, fd_set *rfds, fd_set *wfds)
{
    int fd;
    for (fd = 0; fd < nfds; fd++) {
        if (disOwnsFd(dis, fd) && ((((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            disHandleReadable(dis, fd);
        }
        if (disOwnsFd(dis, fd) && ((((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            disHandleWritable(dis, fd);
        }
    }
}

canonical_original_code:
void disHandleFiles(struct Dispatcher *dis, int nfds, struct fd_set *rfds, struct fd_set *wfds)
{
    int fd;
    for (fd = 0; fd < nfds; fd++) {
        if (disOwnsFd(dis, fd) && ((((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            disHandleReadable(dis, fd);
        }
        if (disOwnsFd(dis, fd) && ((((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            disHandleWritable(dis, fd);
        }
    }
}

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

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

variable_types:
wfds
struct fd_set *


disProcessSelect

decompiled_code:
void __fastcall disProcessSelect(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
if ( a2 )
{
if ( a2 > 0 )
disHandleFiles(a1, a3, a4, a5);
}
else
{
disHandleTimer(a1);
}
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
if ( a2 )
{
if ( a2 > 0 )
func15(a1, a3, a4, a5);
}
else
{
func12(a1);
}
}

original_code:
void disProcessSelect(Dispatcher *dis, int r, int nfds,
        fd_set *rfds, fd_set *wfds)
{
    if (0) _dbgPrint(stderr, "dis.c", 347, __func__, "r = %d, nfds = %d.\n", r, nfds);
    if (0) dumpfds(stderr, "\trfds:", nfds, rfds);
    if (0) dumpfds(stderr, "\twfds:", nfds, wfds);
    if (r == 0) {
        if (0) _dbgPrint(stderr, "dis.c", 353, __func__, "Timeout, calling disHandleTimer.\n");
        disHandleTimer(dis);
    }
    else if (r > 0) {
        if (0) _dbgPrint(stderr, "dis.c", 357, __func__, "Data available, calling disHandleFiles.\n");
        disHandleFiles(dis, nfds, rfds, wfds);
    }
}

canonical_original_code:
void disProcessSelect(struct Dispatcher *dis, int r, int nfds, struct fd_set *rfds, struct fd_set *wfds)
{
    if (0) _dbgPrint(stderr, "dis.c", 347, __func__, "r = %d, nfds = %d.\n", r, nfds);
    if (0) dumpfds(stderr, "\trfds:", nfds, rfds);
    if (0) dumpfds(stderr, "\twfds:", nfds, wfds);
    if (r == 0) {
        if (0) _dbgPrint(stderr, "dis.c", 353, __func__, "Timeout, calling disHandleTimer.\n");
        disHandleTimer(dis);
    }
    else if (r > 0) {
        if (0) _dbgPrint(stderr, "dis.c", 357, __func__, "Data available, calling disHandleFiles.\n");
        disHandleFiles(dis, nfds, rfds, wfds);
    }
}

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


disHandleEvents

decompiled_code:
int __fastcall disHandleEvents(__int64 a1)
{
int result; // eax
int nfds; // [rsp+4h] [rbp-124h] BYREF
struct timeval *timeout; // [rsp+8h] [rbp-120h] BYREF
fd_set readfds; // [rsp+10h] [rbp-118h] BYREF
fd_set writefds; // [rsp+90h] [rbp-98h] BYREF

if ( (int)disPrepareSelect(a1, &nfds, &readfds, &writefds, &timeout) < 0 )
{
disProcessSelect(a1, 0, 0, 0LL, 0LL);
result = 0;
}
else if ( nfds || timeout )
{
result = select(nfds, &readfds, &writefds, 0LL, timeout);
if ( result >= 0 )
{
disProcessSelect(a1, result, nfds, (__int64)&readfds, (__int64)&writefds);
result = 0;
}
}
else
{
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1)
{
int result; // eax
int nfds; // [rsp+4h] [rbp-124h] BYREF
struct timeval *timeout; // [rsp+8h] [rbp-120h] BYREF
fd_set readfds; // [rsp+10h] [rbp-118h] BYREF
fd_set writefds; // [rsp+90h] [rbp-98h] BYREF

if ( (int)func11(a1, &nfds, &readfds, &writefds, &timeout) < 0 )
{
func16(a1, 0, 0, 0LL, 0LL);
result = 0;
}
else if ( nfds || timeout )
{
result = select(nfds, &readfds, &writefds, 0LL, timeout);
if ( result >= 0 )
{
func16(a1, result, nfds, (__int64)&readfds, (__int64)&writefds);
result = 0;
}
}
else
{
result = 1;
}
return result;
}

original_code:
int disHandleEvents(Dispatcher *dis)
{
    int nfds, r;
    fd_set rfds, wfds;
    struct timeval *tv;
    if (0) _dbgPrint(stderr, "dis.c", 373, __func__, "Calling disPrepareSelect.\n");
    r = disPrepareSelect(dis, &nfds, &rfds, &wfds, &tv);
    if (0) _dbgPrint(stderr, "dis.c", 377, __func__, "disPrepareSelect returned:\n\tr:    %d\n\tnfds: %d\n", r, nfds);
    if (r < 0) {
        disProcessSelect(dis, 0, 0, ((void *)0), ((void *)0));
        return 0;
    }
    else if (nfds > 0) {
        if (0) dumpfds(stderr, "\trfds:", nfds, &rfds);
        if (0) dumpfds(stderr, "\twfds:", nfds, &wfds);
    }
    if (0) {
        if (tv == ((void *)0)) {
            fprintf(stderr, "\ttv:   NULL\n");
        }
        else {
            fprintf(stderr, "\ttv:   %ld.%06ld\n", tv->tv_sec, tv->tv_usec);
        }
    }
    if (nfds == 0 && tv == ((void *)0)) {
        if (0) _dbgPrint(stderr, "dis.c", 402, __func__, "No more files, no more timeouts: return 1.\n");
        return 1;
    }
    if (0) _dbgPrint(stderr, "dis.c", 406, __func__, "Calling select.\n");
    r = select(nfds, &rfds, &wfds, ((void *)0), tv);
    if (0) _dbgPrint(stderr, "dis.c", 410, __func__, "select returned %d\n", r);
    if (r < 0) {
        return r;
    }
    else if (r > 0) {
        if (0) dumpfds(stderr, "\trfds:", nfds, &rfds);
        if (0) dumpfds(stderr, "\twfds:", nfds, &wfds);
    }
    if (0) _dbgPrint(stderr, "dis.c", 420, __func__, "Calling disProcessSelect.\n");
    disProcessSelect(dis, r, nfds, &rfds, &wfds);
    return 0;
}

canonical_original_code:
int disHandleEvents(struct Dispatcher *dis)
{
    int nfds; int r;
    struct fd_set rfds; struct fd_set wfds;
    struct timeval *tv;
    if (0) _dbgPrint(stderr, "dis.c", 373, __func__, "Calling disPrepareSelect.\n");
    r = disPrepareSelect(dis, &nfds, &rfds, &wfds, &tv);
    if (0) _dbgPrint(stderr, "dis.c", 377, __func__, "disPrepareSelect returned:\n\tr:    %d\n\tnfds: %d\n", r, nfds);
    if (r < 0) {
        disProcessSelect(dis, 0, 0, ((void *)0), ((void *)0));
        return 0;
    }
    else if (nfds > 0) {
        if (0) dumpfds(stderr, "\trfds:", nfds, &rfds);
        if (0) dumpfds(stderr, "\twfds:", nfds, &wfds);
    }
    if (0) {
        if (tv == ((void *)0)) {
            fprintf(stderr, "\ttv:   NULL\n");
        }
        else {
            fprintf(stderr, "\ttv:   %ld.%06ld\n", tv->tv_sec, tv->tv_usec);
        }
    }
    if (nfds == 0 && tv == ((void *)0)) {
        if (0) _dbgPrint(stderr, "dis.c", 402, __func__, "No more files, no more timeouts: return 1.\n");
        return 1;
    }
    if (0) _dbgPrint(stderr, "dis.c", 406, __func__, "Calling select.\n");
    r = select(nfds, &rfds, &wfds, ((void *)0), tv);
    if (0) _dbgPrint(stderr, "dis.c", 410, __func__, "select returned %d\n", r);
    if (r < 0) {
        return r;
    }
    else if (r > 0) {
        if (0) dumpfds(stderr, "\trfds:", nfds, &rfds);
        if (0) dumpfds(stderr, "\twfds:", nfds, &wfds);
    }
    if (0) _dbgPrint(stderr, "dis.c", 420, __func__, "Calling disProcessSelect.\n");
    disProcessSelect(dis, r, nfds, &rfds, &wfds);
    return 0;
}

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

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

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

return_type: int


disRun

decompiled_code:
int __fastcall disRun(__int64 a1)
{
int result; // eax

do
result = disHandleEvents(a1);
while ( !result );
if ( result == 1 )
result = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1)
{
int result; // eax

do
result = func17(a1);
while ( !result );
if ( result == 1 )
result = 0;
return result;
}

original_code:
int disRun(Dispatcher *dis)
{
    int r;
    do {
        r = disHandleEvents(dis);
        if (0) fprintf(stderr, "disHandleEvents returned %d\n", r);
    } while (r == 0);
    return r == 1 ? 0 : r;
}

canonical_original_code:
int disRun(struct Dispatcher *dis)
{
    int r;
    do {
        r = disHandleEvents(dis);
        if (0) fprintf(stderr, "disHandleEvents returned %d\n", r);
    } while (r == 0);
    return r == 1 ? 0 : r;
}


disClose

decompiled_code:
void *__fastcall disClose(__int64 a1)
{
unsigned int i; // ebx
void *v2; // rbp
void *result; // rax

for ( i = 0; (int)paCount(a1) > (int)i; ++i )
{
v2 = (void *)paGet(a1, i);
if ( v2 )
{
paDrop(a1, i);
bufRewind(v2);
free(v2);
}
}
while ( 1 )
{
result = (void *)listRemoveHead(a1 + 16);
if ( !result )
break;
free(result);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func19(__int64 a1)
{
unsigned int i; // ebx
void *v2; // rbp
void *result; // rax

for ( i = 0; (int)paCount(a1) > (int)i; ++i )
{
v2 = (void *)paGet(a1, i);
if ( v2 )
{
paDrop(a1, i);
bufRewind(v2);
free(v2);
}
}
while ( 1 )
{
result = (void *)listRemoveHead(a1 + 16);
if ( !result )
break;
free(result);
}
return result;
}

original_code:
void disClose(Dispatcher *dis)
{
    int fd;
    DIS_Timer *timer;
    for (fd = 0; fd < paCount(&dis->files); fd++) {
        DIS_File *file = paGet(&dis->files, fd);
        if (file != ((void *)0)) {
            paDrop(&dis->files, fd);
            bufRewind(&file->outgoing);
            free(file);
        }
    }
    while ((timer = listRemoveHead(&dis->timers)) != ((void *)0)) {
        free(timer);
    }
}

canonical_original_code:
void disClose(struct Dispatcher *dis)
{
    int fd;
    struct DIS_Timer *timer;
    for (fd = 0; fd < paCount(&dis->files); fd++) {
        struct DIS_File *file = paGet(&dis->files, fd);
        if (file != ((void *)0)) {
            paDrop(&dis->files, fd);
            bufRewind(&file->outgoing);
            free(file);
        }
    }
    while ((timer = listRemoveHead(&dis->timers)) != ((void *)0)) {
        free(timer);
    }
}

variable_types: struct DIS_Timer { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List { struct ListNode *head; struct ListNode *tail; int length; } *list; } _node; double t; void (*cb)(struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List timers; struct timeval { long tv_sec; long tv_usec; } tv; } *dis, double t, void *udata); void *udata; } *

user_defined_types: struct DIS_Timer { struct ListNode _node; double t; void (*cb)(struct Dispatcher *dis, double t, void *udata); void *udata; }

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


disClear

decompiled_code:
void *__fastcall disClear(__int64 a1)
{
void *result; // rax

result = disClose(a1);
*(_QWORD *)(a1 + 48) = 0LL;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_OWORD *)(a1 + 32) = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func20(__int64 a1)
{
void *result; // rax

result = func19(a1);
*(_QWORD *)(a1 + 48) = 0LL;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_OWORD *)(a1 + 32) = 0LL;
return result;
}

original_code:
void disClear(Dispatcher *dis)
{
    disClose(dis);
    memset(dis, 0, sizeof(Dispatcher));
}

canonical_original_code:
void disClear(struct Dispatcher *dis)
{
    disClose(dis);
    memset(dis, 0, sizeof(Dispatcher));
}


disDestroy

decompiled_code:
void __fastcall disDestroy(void *ptr)
{
disClose((__int64)ptr);
free(ptr);
}

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

original_code:
void disDestroy(Dispatcher *dis)
{
    disClose(dis);
    free(dis);
}

canonical_original_code:
void disDestroy(struct Dispatcher *dis)
{
    disClose(dis);
    free(dis);
}


hlCreate

decompiled_code:
void *hlCreate()
{
return calloc(1uLL, 0x18018uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(1uLL, 0x18018uLL);
}

original_code:
HashList *hlCreate(void)
{
    return calloc(1, sizeof(HashList));
}

canonical_original_code:
struct HashList *hlCreate()
{
    return calloc(1, sizeof(HashList));
}

return_type: struct HashList { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } list; struct HashTable { struct List bucket[-1]; } hash; } *

user_defined_types: struct HashList { struct List list; struct HashTable hash; }


hlInitialize

decompiled_code:
void *__fastcall hlInitialize(void *a1)
{
return memset(a1, 0, 0x18018uLL);
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
return memset(a1, 0, 0x18018uLL);
}

original_code:
void hlInitialize(HashList *hashlist)
{
    memset(hashlist, 0, sizeof(*hashlist));
}

canonical_original_code:
void hlInitialize(struct HashList *hashlist)
{
    memset(hashlist, 0, sizeof(*hashlist));
}

variable_types: struct HashList { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } list; struct HashTable { struct List bucket[-1]; } hash; } *


hlContains

decompiled_code:
__int64 __fastcall hlContains(__int64 a1)
{
return hashContains(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return hashContains(a1 + 24);
}

original_code:
int hlContains(const HashList *hashlist, const void *key, int key_len)
{
    return hashContains(&hashlist->hash, key, key_len);
}

canonical_original_code:
int hlContains(struct HashList *hashlist, void *key, int key_len)
{
    return hashContains(&hashlist->hash, key, key_len);
}

variable_types:
key
void *

user_defined_types: struct HashTable { struct List bucket[-1]; }


hlGet

decompiled_code:
__int64 __fastcall hlGet(__int64 a1)
{
return hashGet(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return hashGet(a1 + 24);
}

original_code:
void *hlGet(HashList *hashlist, const void *key, int key_len)
{
    return hashGet(&hashlist->hash, key, key_len);
}

canonical_original_code:
void *hlGet(struct HashList *hashlist, void *key, int key_len)
{
    return hashGet(&hashlist->hash, key, key_len);
}

return_type: void *


hlDel

decompiled_code:
__int64 __fastcall hlDel(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 v5; // r12

v4 = hashGet(a1 + 24);
if ( !v4 )
_assert_fail("node", "hashlist.c", 0x60u, "hlDel");
v5 = v4;
hashDrop(a1 + 24, a2, a3);
return listRemove(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 v5; // r12

v4 = hashGet(a1 + 24);
if ( !v4 )
_assert_fail("node", "hashlist.c", 0x60u, "hlDel");
v5 = v4;
hashDrop(a1 + 24, a2, a3);
return listRemove(a1, v5);
}

original_code:
void hlDel(HashList *hashlist, const void *key, int key_len)
{
    ListNode *node = hashGet(&hashlist->hash, key, key_len);
    ((void) sizeof ((node) ? 1 : 0), __extension__ ({ if (node) ; else __assert_fail ("node", "hashlist.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    hashDrop(&hashlist->hash, key, key_len);
    _listRemove(&hashlist->list, node);
}

canonical_original_code:
void hlDel(struct HashList *hashlist, void *key, int key_len)
{
    struct ListNode *node = hashGet(&hashlist->hash, key, key_len);
    ((void) sizeof ((node) ? 1 : 0), __extension__ ({ if (node) ; else __assert_fail ("node", "hashlist.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    hashDrop(&hashlist->hash, key, key_len);
    _listRemove(&hashlist->list, node);
}

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


hlHead

decompiled_code:
// attributes: thunk
__int64 hlHead()
{
return listHead();
}

canonical_decompiled_code:
__int64 func7()
{
return listHead();
}

original_code:
void *hlHead(const HashList *hashlist)
{
    return listHead(&hashlist->list);
}

canonical_original_code:
void *hlHead(struct HashList *hashlist)
{
    return listHead(&hashlist->list);
}


hlTail

decompiled_code:
// attributes: thunk
__int64 hlTail()
{
return listTail();
}

canonical_decompiled_code:
__int64 func8()
{
return listTail();
}

original_code:
void *hlTail(const HashList *hashlist)
{
    return listTail(&hashlist->list);
}

canonical_original_code:
void *hlTail(struct HashList *hashlist)
{
    return listTail(&hashlist->list);
}


hlIsEmpty

decompiled_code:
// attributes: thunk
__int64 hlIsEmpty()
{
return listIsEmpty();
}

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

original_code:
int hlIsEmpty(const HashList *hashlist)
{
    return listIsEmpty(&hashlist->list);
}

canonical_original_code:
int hlIsEmpty(struct HashList *hashlist)
{
    return listIsEmpty(&hashlist->list);
}


hlSort

decompiled_code:
// attributes: thunk
__int64 hlSort()
{
return listSort();
}

canonical_decompiled_code:
__int64 func12()
{
return listSort();
}

original_code:
void hlSort(HashList *hashlist, int(*cmp)(const void *, const void *))
{
    listSort(&hashlist->list, cmp);
}

canonical_original_code:
void hlSort(struct HashList *hashlist, int (*cmp)(void *, void *))
{
    listSort(&hashlist->list, cmp);
}

variable_types:
cmp
int (*)(void *, void *)


hlClear

decompiled_code:
__int64 __fastcall hlClear(__int64 a1)
{
while ( listRemoveHead(a1) )
;
return hashClear(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
while ( listRemoveHead(a1) )
;
return hashClear(a1 + 24);
}

original_code:
void hlClear(HashList *hashlist)
{
    ListNode *ptr;
    while ((ptr = listRemoveHead(&hashlist->list)) != ((void *)0)) ;
    hashClear(&hashlist->hash);
}

canonical_original_code:
void hlClear(struct HashList *hashlist)
{
    struct ListNode *ptr;
    while ((ptr = listRemoveHead(&hashlist->list)) != ((void *)0)) ;
    hashClear(&hashlist->hash);
}


hlDestroy

decompiled_code:
void __fastcall hlDestroy(void *ptr)
{
hlClear((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
func13((__int64)ptr);
free(ptr);
}

original_code:
void hlDestroy(HashList *hashlist)
{
    hlClear(hashlist);
    free(hashlist);
}

canonical_original_code:
void hlDestroy(struct HashList *hashlist)
{
    hlClear(hashlist);
    free(hashlist);
}


decompiled_code:
__int64 __fastcall path_add_file(__int64 a1, char *a2, char *a3)
{
size_t v4; // rax
_QWORD *v5; // rbp
size_t v6; // rax
__int64 result; // rax
size_t v8; // rax
_QWORD *v9; // rbp
size_t v10; // rax

v4 = strlen(a2);
v5 = (_QWORD *)hlGet(a1, a2, v4);
if ( !v5 )
{
v5 = path_create_dir(a2);
v8 = strlen(a2);
hlAdd(a1, v5, a2, v8);
}
v6 = strlen(a3);
result = hlGet(a1 + 98328, a3, v6);
if ( !result )
{
v9 = path_create_file(a3, (__int64)v5);
v10 = strlen(a3);
result = hlAdd(a1 + 98328, v9, a3, v10);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, char *a3)
{
size_t v4; // rax
_QWORD *v5; // rbp
size_t v6; // rax
__int64 result; // rax
size_t v8; // rax
_QWORD *v9; // rbp
size_t v10; // rax

v4 = strlen(a2);
v5 = (_QWORD *)hlGet(a1, a2, v4);
if ( !v5 )
{
v5 = path_create_dir(a2);
v8 = strlen(a2);
hlAdd(a1, v5, a2, v8);
}
v6 = strlen(a3);
result = hlGet(a1 + 98328, a3, v6);
if ( !result )
{
v9 = path_create_file(a3, (__int64)v5);
v10 = strlen(a3);
result = hlAdd(a1 + 98328, v9, a3, v10);
}
return result;
}

original_code:
static void path_add_file(Path *path, const char *dirname, const char *filename)
{
    PathDir *dir;
    PathFile *file;
    if ((dir = hlGet(&path->dirs, dirname, strlen(dirname))) == ((void *)0)) {
        dir = path_create_dir(dirname);
        _hlAdd((&path->dirs), &(dir)->_node, dirname, strlen(dirname));
    }
    if ((file = hlGet(&path->files, filename, strlen(filename))) == ((void *)0)) {
        file = path_create_file(filename, dir);
        _hlAdd((&path->files), &(file)->_node, filename, strlen(filename));
    }
}

canonical_original_code:
static void path_add_file(struct Path *path, char *dirname, char *filename)
{
    struct PathDir *dir;
    struct PathFile *file;
    if ((dir = hlGet(&path->dirs, dirname, strlen(dirname))) == ((void *)0)) {
        dir = path_create_dir(dirname);
        _hlAdd((&path->dirs), &(dir)->_node, dirname, strlen(dirname));
    }
    if ((file = hlGet(&path->files, filename, strlen(filename))) == ((void *)0)) {
        file = path_create_file(filename, dir);
        _hlAdd((&path->files), &(file)->_node, filename, strlen(filename));
    }
}

variable_types: struct Path { struct HashList { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } list; struct HashTable { struct List bucket[-1]; } hash; } dirs; struct HashList files; } *

variable_types:
dirname
char *

variable_types:
filename
char *

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

variable_types: struct PathFile { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List { struct ListNode *head; struct ListNode *tail; int length; } *list; } _node; struct PathDir { struct ListNode _node; char *name; } *dir; char *name; } *

user_defined_types: struct Path { struct HashList dirs; struct HashList files; }

user_defined_types: struct PathFile { struct ListNode _node; struct PathDir *dir; char *name; }


decompiled_code:
__int64 __fastcall path_get(__int64 a1, const char *a2)
{
size_t v2; // rax
__int64 v3; // rax
__int64 v4; // rbx

v2 = strlen(a2);
v3 = hlGet(a1 + 98328, a2, v2);
if ( !v3 )
return 0LL;
v4 = v3;
bufSetS(&namebuf_0, *(_QWORD *)(*(_QWORD *)(v3 + 24) + 24LL));
bufAddS(&namebuf_0, &LC0);
bufAddS(&namebuf_0, *(_QWORD *)(v4 + 32));
return bufGet(&namebuf_0);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
size_t v2; // rax
__int64 v3; // rax
__int64 v4; // rbx

v2 = strlen(a2);
v3 = hlGet(a1 + 98328, a2, v2);
if ( !v3 )
return 0LL;
v4 = v3;
bufSetS(&namebuf_0, *(_QWORD *)(*(_QWORD *)(v3 + 24) + 24LL));
bufAddS(&namebuf_0, &LC0);
bufAddS(&namebuf_0, *(_QWORD *)(v4 + 32));
return bufGet(&namebuf_0);
}

original_code:
static const char *path_get(Path *path, const char *filename)
{
    static Buffer namebuf = { 0 };
    PathFile *file;
    if ((file = hlGet(&path->files, filename, strlen(filename))) == ((void *)0)) {
        return ((void *)0);
    }
    bufSetS(&namebuf, file->dir->name);
    bufAddS(&namebuf, "/");
    bufAddS(&namebuf, file->name);
    return bufGet(&namebuf);
}

canonical_original_code:
static char *path_get(struct Path *path, char *filename)
{
    static struct Buffer namebuf = { 0 };
    struct PathFile *file;
    if ((file = hlGet(&path->files, filename, strlen(filename))) == ((void *)0)) {
        return ((void *)0);
    }
    bufSetS(&namebuf, file->dir->name);
    bufAddS(&namebuf, "/");
    bufAddS(&namebuf, file->name);
    return bufGet(&namebuf);
}

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

return_type: char *

user_defined_types: struct PathDir { struct ListNode _node; char *name; }


pathAdd

decompiled_code:
__int64 __fastcall pathAdd(__int64 a1, const char *a2)
{
dbgAssert(stderr, a2 != 0LL, "path.c", 186LL, "pathAdd", "<addition> may not be NULL");
return path_scan(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
dbgAssert(stderr, a2 != 0LL, "path.c", 186LL, "pathAdd", "<addition> may not be NULL");
return func1(a1, a2);
}

original_code:
void pathAdd(Path *path, const char *addition)
{
    _dbgAssert(stderr, addition != ((void *)0), "path.c", 186, __func__, "<addition> may not be NULL");
    path_scan(path, addition);
}

canonical_original_code:
void pathAdd(struct Path *path, char *addition)
{
    _dbgAssert(stderr, addition != ((void *)0), "path.c", 186, __func__, "<addition> may not be NULL");
    path_scan(path, addition);
}

variable_types:
addition
char *


pathCreate

decompiled_code:
void *__fastcall pathCreate(const char *a1)
{
void *v1; // rax
void *v2; // r12

v1 = calloc(1uLL, 0x30030uLL);
v2 = v1;
if ( a1 )
pathAdd((__int64)v1, a1);
return v2;
}

canonical_decompiled_code:
void *__fastcall func4(const char *a1)
{
void *v1; // rax
void *v2; // r12

v1 = calloc(1uLL, 0x30030uLL);
v2 = v1;
if ( a1 )
func3((__int64)v1, a1);
return v2;
}

original_code:
Path *pathCreate(const char *initial)
{
    Path *path = calloc(1, sizeof(*path));
    if (initial) pathAdd(path, initial);
    return path;
}

canonical_original_code:
struct Path *pathCreate(char *initial)
{
    struct Path *path = calloc(1, sizeof(*path));
    if (initial) pathAdd(path, initial);
    return path;
}

variable_types:
initial
char *

return_type: struct Path { struct HashList { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } list; struct HashTable { struct List bucket[-1]; } hash; } dirs; struct HashList files; } *


pathGet

decompiled_code:
// attributes: thunk
__int64 __fastcall pathGet(__int64 a1, const char *a2)
{
return path_get(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
return func2(a1, a2);
}

original_code:
const char *pathGet(Path *path, const char *filename)
{
    return path_get(path, filename);
}

canonical_original_code:
char *pathGet(struct Path *path, char *filename)
{
    return path_get(path, filename);
}


pathOpen

decompiled_code:
int __fastcall pathOpen(__int64 a1, const char *a2, int a3)
{
const char *v4; // rax

v4 = (const char *)pathGet(a1, a2);
if ( v4 )
return open(v4, a3);
*_errno_location() = 2;
return -1;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, const char *a2, int a3)
{
const char *v4; // rax

v4 = (const char *)func5(a1, a2);
if ( v4 )
return open(v4, a3);
*_errno_location() = 2;
return -1;
}

original_code:
int pathOpen(Path *path, const char *filename, int flags)
{
    const char *fullpath;
    int fd;
    if ((fullpath = pathGet(path, filename)) == ((void *)0)) {
        (*__errno_location ()) = 2;
        return -1;
    }
    else if ((fd = open(fullpath, flags)) == -1) {
        return -1;
    }
    else {
        return fd;
    }
}

canonical_original_code:
int pathOpen(struct Path *path, char *filename, int flags)
{
    char *fullpath;
    int fd;
    if ((fullpath = pathGet(path, filename)) == ((void *)0)) {
        (*__errno_location ()) = 2;
        return -1;
    }
    else if ((fd = open(fullpath, flags)) == -1) {
        return -1;
    }
    else {
        return fd;
    }
}

variable_types: flags int

variable_types:
fullpath
char *

variable_types: fd int


pathClear

original_code:
void pathClear(Path *path)
{
    PathDir *dir, *next_dir;
    PathFile *file, *next_file;
    for (file = hlHead(&path->files); file; file = next_file) {
        next_file = _hlNext(&(file)->_node);
        hlDel(&path->files, file->name, strlen(file->name));
        free(file->name);
        free(file);
    }
    for (dir = hlHead(&path->dirs); dir; dir = next_dir) {
        next_dir = _hlNext(&(dir)->_node);
        hlDel(&path->dirs, dir->name, strlen(dir->name));
        free(dir->name);
        free(dir);
    }
}

canonical_original_code:
void pathClear(struct Path *path)
{
    struct PathDir *dir; struct PathDir *next_dir;
    struct PathFile *file; struct PathFile *next_file;
    for (file = hlHead(&path->files); file; file = next_file) {
        next_file = _hlNext(&(file)->_node);
        hlDel(&path->files, file->name, strlen(file->name));
        free(file->name);
        free(file);
    }
    for (dir = hlHead(&path->dirs); dir; dir = next_dir) {
        next_dir = _hlNext(&(dir)->_node);
        hlDel(&path->dirs, dir->name, strlen(dir->name));
        free(dir->name);
        free(dir);
    }
}


pathDestroy

decompiled_code:
void __fastcall pathDestroy(void *ptr)
{
pathClear((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
func7((__int64)ptr);
free(ptr);
}

original_code:
void pathDestroy(Path *path)
{
    pathClear(path);
    free(path);
}

canonical_original_code:
void pathDestroy(struct Path *path)
{
    pathClear(path);
    free(path);
}


decompiled_code:
void *__fastcall bm_check_size(unsigned __int8 *a1, unsigned int a2)
{
int v2; // ebx
void *result; // rax
char *v4; // rax
__int64 v5; // rcx

v2 = (a2 >> 3) + 1;
result = (void *)*a1;
if ( (int)result < v2 )
{
v4 = (char *)realloc(*((void **)a1 + 1), (unsigned int)v2);
v5 = *a1;
*((_QWORD *)a1 + 1) = v4;
result = memset(&v4[v5], 0, v2 - (int)v5);
*a1 = v2;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(unsigned __int8 *a1, unsigned int a2)
{
int v2; // ebx
void *result; // rax
char *v4; // rax
__int64 v5; // rcx

v2 = (a2 >> 3) + 1;
result = (void *)*a1;
if ( (int)result < v2 )
{
v4 = (char *)realloc(*((void **)a1 + 1), (unsigned int)v2);
v5 = *a1;
*((_QWORD *)a1 + 1) = v4;
result = memset(&v4[v5], 0, v2 - (int)v5);
*a1 = v2;
}
return result;
}

original_code:
static void bm_check_size(Bitmask *mask, unsigned int bit)
{
    int n_required_bytes = 1 + (bit / 8);
    if (mask->n_bytes < n_required_bytes) {
        mask->bits = realloc(mask->bits, n_required_bytes);
        memset(mask->bits + mask->n_bytes, 0, n_required_bytes - mask->n_bytes);
        mask->n_bytes = n_required_bytes;
    }
}

canonical_original_code:
static void bm_check_size(struct Bitmask *mask, unsigned int bit)
{
    int n_required_bytes = 1 + (bit / 8);
    if (mask->n_bytes < n_required_bytes) {
        mask->bits = realloc(mask->bits, n_required_bytes);
        memset(mask->bits + mask->n_bytes, 0, n_required_bytes - mask->n_bytes);
        mask->n_bytes = n_required_bytes;
    }
}

variable_types: struct Bitmask { unsigned char n_bytes; unsigned char *bits; } *

variable_types:
bit
unsigned int


bmCreate

decompiled_code:
void *bmCreate()
{
return calloc(1uLL, 0x10uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(1uLL, 0x10uLL);
}

original_code:
Bitmask *bmCreate(void)
{
    return calloc(1, sizeof(Bitmask));
}

canonical_original_code:
struct Bitmask *bmCreate()
{
    return calloc(1, sizeof(Bitmask));
}

return_type: struct Bitmask { unsigned char n_bytes; unsigned char *bits; } *


bmGetBit

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

result = 0LL;
if ( 8 * (unsigned int)*a1 > a2 )
result = ((int)*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + (a2 >> 3)) >> (a2 & 7)) & 1;
return result;
}

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

result = 0LL;
if ( 8 * (unsigned int)*a1 > a2 )
result = ((int)*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + (a2 >> 3)) >> (a2 & 7)) & 1;
return result;
}

original_code:
int bmGetBit(const Bitmask *mask, unsigned int bit)
{
    if (bit >= 8 * mask->n_bytes)
        return 0;
    else
        return (mask->bits[bit / 8] & (1 << (bit % 8))) ? 1 : 0;
}

canonical_original_code:
int bmGetBit(struct Bitmask *mask, unsigned int bit)
{
    if (bit >= 8 * mask->n_bytes)
        return 0;
    else
        return (mask->bits[bit / 8] & (1 << (bit % 8))) ? 1 : 0;
}

user_defined_types: struct Bitmask { unsigned char n_bytes; unsigned char *bits; }


bmSetBits

decompiled_code:
char *bmSetBits(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
char *result; // rax
unsigned int v10; // esi
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( va[0].gp_offset <= 0x2F )
{
result = (char *)(va[0].gp_offset + 8);
v10 = *(_DWORD *)((char *)va[0].reg_save_area + va[0].gp_offset);
va[0].gp_offset += 8;
if ( v10 == -1 )
return result;
LABEL_3:
bmSetBit(a1, v10);
}
v10 = *(_DWORD *)va[0].overflow_arg_area;
result = (char *)va[0].overflow_arg_area + 8;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v10 != -1 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
char *func3(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
char *result; // rax
unsigned int v10; // esi
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( va[0].gp_offset <= 0x2F )
{
result = (char *)(va[0].gp_offset + 8);
v10 = *(_DWORD *)((char *)va[0].reg_save_area + va[0].gp_offset);
va[0].gp_offset += 8;
if ( v10 == -1 )
return result;
LABEL_3:
bmSetBit(a1, v10);
}
v10 = *(_DWORD *)va[0].overflow_arg_area;
result = (char *)va[0].overflow_arg_area + 8;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v10 != -1 )
goto LABEL_3;
return result;
}

original_code:
void bmSetBits(Bitmask *mask, ...)
{
    int b;
    va_list ap;
    __builtin_va_start(ap,mask);
    while ((b = (__builtin_va_arg(ap,int))) != (-1)) {
        bmSetBit(mask, b);
    }
    __builtin_va_end(ap);
}

canonical_original_code:
void bmSetBits(struct Bitmask *mask, ...)
{
    int b;
    __builtin_va_list ap;
    __builtin_va_start(ap,mask);
    while ((b = (__builtin_va_arg(ap,int))) != (-1)) {
        bmSetBit(mask, b);
    }
    __builtin_va_end(ap);
}

variable_types: b int


bmClrBits

decompiled_code:
char *bmClrBits(unsigned __int8 *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
char *result; // rax
unsigned int v10; // esi
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( va[0].gp_offset <= 0x2F )
{
result = (char *)(va[0].gp_offset + 8);
v10 = *(_DWORD *)((char *)va[0].reg_save_area + va[0].gp_offset);
va[0].gp_offset += 8;
if ( v10 == -1 )
return result;
LABEL_3:
bmClrBit(a1, v10);
}
v10 = *(_DWORD *)va[0].overflow_arg_area;
result = (char *)va[0].overflow_arg_area + 8;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v10 != -1 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
char *func4(unsigned __int8 *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
char *result; // rax
unsigned int v10; // esi
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( va[0].gp_offset <= 0x2F )
{
result = (char *)(va[0].gp_offset + 8);
v10 = *(_DWORD *)((char *)va[0].reg_save_area + va[0].gp_offset);
va[0].gp_offset += 8;
if ( v10 == -1 )
return result;
LABEL_3:
bmClrBit(a1, v10);
}
v10 = *(_DWORD *)va[0].overflow_arg_area;
result = (char *)va[0].overflow_arg_area + 8;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v10 != -1 )
goto LABEL_3;
return result;
}

original_code:
void bmClrBits(Bitmask *mask, ...)
{
    int b;
    va_list ap;
    __builtin_va_start(ap,mask);
    while ((b = (__builtin_va_arg(ap,int))) != (-1)) {
        bmClrBit(mask, b);
    }
    __builtin_va_end(ap);
}

canonical_original_code:
void bmClrBits(struct Bitmask *mask, ...)
{
    int b;
    __builtin_va_list ap;
    __builtin_va_start(ap,mask);
    while ((b = (__builtin_va_arg(ap,int))) != (-1)) {
        bmClrBit(mask, b);
    }
    __builtin_va_end(ap);
}


bmCompare

decompiled_code:
__int64 __fastcall bmCompare(unsigned __int8 *a1, unsigned __int8 *a2)
{
int v2; // ecx
int v4; // esi
int v6; // edx
int v7; // eax
__int64 v8; // rdx
unsigned __int8 v9; // di
unsigned __int8 v10; // r8

v2 = *a1;
v4 = *a2;
v6 = (unsigned __int8)v2;
if ( (unsigned __int8)v4 >= (unsigned __int8)v2 )
v6 = v4;
v7 = v6 - 1;
if ( v6 )
{
v8 = v7;
do
{
if ( v7 < v2 )
{
v9 = *(_BYTE *)(*((_QWORD *)a1 + 1) + v8);
if ( v7 >= v4 )
{
if ( v9 )
return 1LL;
}
else
{
v10 = *(_BYTE *)(*((_QWORD *)a2 + 1) + v8);
if ( v9 < v10 )
return 0xFFFFFFFFLL;
if ( v9 > v10 )
return 1LL;
}
}
else if ( v7 < v4 && *(_BYTE *)(*((_QWORD *)a2 + 1) + v8) )
{
return 0xFFFFFFFFLL;
}
--v7;
--v8;
}
while ( v7 != -1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, unsigned __int8 *a2)
{
int v2; // ecx
int v4; // esi
int v6; // edx
int v7; // eax
__int64 v8; // rdx
unsigned __int8 v9; // di
unsigned __int8 v10; // r8

v2 = *a1;
v4 = *a2;
v6 = (unsigned __int8)v2;
if ( (unsigned __int8)v4 >= (unsigned __int8)v2 )
v6 = v4;
v7 = v6 - 1;
if ( v6 )
{
v8 = v7;
do
{
if ( v7 < v2 )
{
v9 = *(_BYTE *)(*((_QWORD *)a1 + 1) + v8);
if ( v7 >= v4 )
{
if ( v9 )
return 1LL;
}
else
{
v10 = *(_BYTE *)(*((_QWORD *)a2 + 1) + v8);
if ( v9 < v10 )
return 0xFFFFFFFFLL;
if ( v9 > v10 )
return 1LL;
}
}
else if ( v7 < v4 && *(_BYTE *)(*((_QWORD *)a2 + 1) + v8) )
{
return 0xFFFFFFFFLL;
}
--v7;
--v8;
}
while ( v7 != -1 );
}
return 0LL;
}

original_code:
int bmCompare(const Bitmask *left, const Bitmask *right)
{
    int i, n_bytes = ((left->n_bytes) > (right->n_bytes) ? (left->n_bytes) : (right->n_bytes));
    for (i = n_bytes - 1; i >= 0; i--) {
        uint8_t l = left->n_bytes > i ? left->bits[i] : 0;
        uint8_t r = right->n_bytes > i ? right->bits[i] : 0;
        if (l < r)
            return -1;
        else if (l > r)
            return 1;
    }
    return 0;
}

canonical_original_code:
int bmCompare(struct Bitmask *left, struct Bitmask *right)
{
    int i; int n_bytes = ((left->n_bytes) > (right->n_bytes) ? (left->n_bytes) : (right->n_bytes));
    for (i = n_bytes - 1; i >= 0; i--) {
        unsigned char l = left->n_bytes > i ? left->bits[i] : 0;
        unsigned char r = right->n_bytes > i ? right->bits[i] : 0;
        if (l < r)
            return -1;
        else if (l > r)
            return 1;
    }
    return 0;
}

variable_types:
right
struct Bitmask *

variable_types: i int

variable_types:
l
unsigned char

variable_types:
r
unsigned char


bmClear

decompiled_code:
void __fastcall bmClear(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
*(_QWORD *)(a1 + 8) = 0LL;
*(_BYTE *)a1 = 0;
}

original_code:
void bmClear(Bitmask *mask)
{
    if (mask->bits) free(mask->bits);
    mask->bits = ((void *)0);
    mask->n_bytes = 0;
}

canonical_original_code:
void bmClear(struct Bitmask *mask)
{
    if (mask->bits) free(mask->bits);
    mask->bits = ((void *)0);
    mask->n_bytes = 0;
}


bmDestroy

decompiled_code:
void __fastcall bmDestroy(void *ptr)
{
bmClear((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
func6((__int64)ptr);
free(ptr);
}

original_code:
void bmDestroy(Bitmask *mask)
{
    bmClear(mask);
    free(mask);
}

canonical_original_code:
void bmDestroy(struct Bitmask *mask)
{
    bmClear(mask);
    free(mask);
}


decompiled_code:
void v2Make()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
Vector2 v2Make(double x, double y)
{
    Vector2 v = { .r[0] = x, .r[1] = y };
    return v;
}

canonical_original_code:
struct Vector2 v2Make(double x, double y)
{
    struct Vector2 v = { .r[0] = x, .r[1] = y };
    return v;
}

variable_types: x double

variable_types: y double

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

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


decompiled_code:
void v2New()
{
v2Make();
}

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

original_code:
Vector2 v2New(void)
{
    return v2Make(0, 0);
}

canonical_original_code:
struct Vector2 v2New()
{
    return v2Make(0, 0);
}


decompiled_code:
void __fastcall v2Set(double *a1, double a2, double a3)
{
*a1 = a2;
a1[1] = a3;
}

canonical_decompiled_code:
void __fastcall func2(double *a1, double a2, double a3)
{
*a1 = a2;
a1[1] = a3;
}

original_code:
void v2Set(Vector2 *v, double x, double y)
{
    v->r[0] = x;
    v->r[1] = y;
}

canonical_original_code:
void v2Set(struct Vector2 *v, double x, double y)
{
    v->r[0] = x;
    v->r[1] = y;
}

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


decompiled_code:
void v2Sum()
{
v2Make();
}

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

original_code:
Vector2 v2Sum(Vector2 v1, Vector2 v2)
{
    return v2Make(v1.r[0] + v2.r[0], v1.r[1] + v2.r[1]);
}

canonical_original_code:
struct Vector2 v2Sum(struct Vector2 v1, struct Vector2 v2)
{
    return v2Make(v1.r[0] + v2.r[0], v1.r[1] + v2.r[1]);
}


decompiled_code:
void __fastcall v2Add(double *a1, double a2, double a3)
{
double v3; // xmm1_8

v3 = a3 + a1[1];
*a1 = a2 + *a1;
a1[1] = v3;
}

canonical_decompiled_code:
void __fastcall func4(double *a1, double a2, double a3)
{
double v3; // xmm1_8

v3 = a3 + a1[1];
*a1 = a2 + *a1;
a1[1] = v3;
}

canonical_original_code:
void v2Add(struct Vector2 *v, struct Vector2 d)
{
    v->r[0] += d.r[0];
    v->r[1] += d.r[1];
}

variable_types:
d
struct Vector2


decompiled_code:
void v2Diff()
{
v2Make();
}

canonical_decompiled_code:
void func5()
{
func0();
}

original_code:
Vector2 v2Diff(Vector2 v1, Vector2 v2)
{
    return v2Make(v1.r[0] - v2.r[0], v1.r[1] - v2.r[1]);
}

canonical_original_code:
struct Vector2 v2Diff(struct Vector2 v1, struct Vector2 v2)
{
    return v2Make(v1.r[0] - v2.r[0], v1.r[1] - v2.r[1]);
}


decompiled_code:
void __fastcall v2Sub(double *a1, double a2, double a3)
{
*a1 = *a1 - a2;
a1[1] = a1[1] - a3;
}

canonical_decompiled_code:
void __fastcall func6(double *a1, double a2, double a3)
{
*a1 = *a1 - a2;
a1[1] = a1[1] - a3;
}

canonical_original_code:
void v2Sub(struct Vector2 *v, struct Vector2 d)
{
    v->r[0] -= d.r[0];
    v->r[1] -= d.r[1];
}


decompiled_code:
double __fastcall v2LenSquared(double a1, double a2)
{
return a1 * a1 + a2 * a2;
}

canonical_decompiled_code:
double __fastcall func7(double a1, double a2)
{
return a1 * a1 + a2 * a2;
}

original_code:
double v2LenSquared(Vector2 v)
{
    return v.r[0] * v.r[0] + v.r[1] * v.r[1];
}

canonical_original_code:
double v2LenSquared(struct Vector2 v)
{
    return v.r[0] * v.r[0] + v.r[1] * v.r[1];
}

return_type: double


decompiled_code:
void __fastcall v2Len(double a1, double a2)
{
double v2; // xmm0_8

v2 = v2LenSquared(a1, a2);
if ( v2 < 0.0 )
sqrt(v2);
}

canonical_decompiled_code:
void __fastcall func8(double a1, double a2)
{
double v2; // xmm0_8

v2 = func7(a1, a2);
if ( v2 < 0.0 )
sqrt(v2);
}

original_code:
double v2Len(Vector2 v)
{
    return sqrt(v2LenSquared(v));
}

canonical_original_code:
double v2Len(struct Vector2 v)
{
    return sqrt(v2LenSquared(v));
}


decompiled_code:
void __fastcall v2Scale(double *a1, double a2)
{
double v2; // xmm1_8
double v3; // xmm0_8

v2 = *a1 * a2;
v3 = a2 * a1[1];
*a1 = v2;
a1[1] = v3;
}

canonical_decompiled_code:
void __fastcall func9(double *a1, double a2)
{
double v2; // xmm1_8
double v3; // xmm0_8

v2 = *a1 * a2;
v3 = a2 * a1[1];
*a1 = v2;
a1[1] = v3;
}

original_code:
void v2Scale(Vector2 *v, double scale)
{
    v->r[0] *= scale;
    v->r[1] *= scale;
}

canonical_original_code:
void v2Scale(struct Vector2 *v, double scale)
{
    v->r[0] *= scale;
    v->r[1] *= scale;
}

variable_types: scale double


decompiled_code:
void v2Scaled()
{
v2Make();
}

canonical_decompiled_code:
void func10()
{
func0();
}

original_code:
Vector2 v2Scaled(Vector2 v, double scale)
{
    return v2Make(v.r[0] * scale, v.r[1] * scale);
}

canonical_original_code:
struct Vector2 v2Scaled(struct Vector2 v, double scale)
{
    return v2Make(v.r[0] * scale, v.r[1] * scale);
}

variable_types:
v
struct Vector2


decompiled_code:
void __fastcall v2Normalize(double *a1)
{
double v1; // xmm0_8

v1 = *a1;
v2Len(*a1, a1[1]);
*a1 = *a1 / v1;
a1[1] = a1[1] / v1;
}

original_code:
void v2Normalize(Vector2 *v)
{
    double len = v2Len(*v);
    v->r[0] /= len;
    v->r[1] /= len;
}

canonical_original_code:
void v2Normalize(struct Vector2 *v)
{
    double len = v2Len(*v);
    v->r[0] /= len;
    v->r[1] /= len;
}

variable_types: len double


decompiled_code:
void __fastcall v2Normalized(double a1, double a2)
{
v2Len(a1, a2);
v2Scaled();
}

canonical_decompiled_code:
void __fastcall func12(double a1, double a2)
{
func8(a1, a2);
func10();
}

original_code:
Vector2 v2Normalized(Vector2 v)
{
    return v2Scaled(v, 1 / v2Len(v));
}

canonical_original_code:
struct Vector2 v2Normalized(struct Vector2 v)
{
    return v2Scaled(v, 1 / v2Len(v));
}


decompiled_code:
double __fastcall v2Dot(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

canonical_decompiled_code:
double __fastcall func13(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

original_code:
double v2Dot(Vector2 v1, Vector2 v2)
{
    return v1.r[0] * v2.r[0] + v1.r[1] * v2.r[1];
}

canonical_original_code:
double v2Dot(struct Vector2 v1, struct Vector2 v2)
{
    return v1.r[0] * v2.r[0] + v1.r[1] * v2.r[1];
}


decompiled_code:
void __fastcall v2Angle(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

*(_QWORD *)&v4 = v2Cos(a1, a2, a3, a4);
acos(v4);
}

canonical_decompiled_code:
void __fastcall func14(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

*(_QWORD *)&v4 = v2Cos(a1, a2, a3, a4);
acos(v4);
}

original_code:
double v2Angle(Vector2 v1, Vector2 v2)
{
    return acos(v2Cos(v1, v2));
}

canonical_original_code:
double v2Angle(struct Vector2 v1, struct Vector2 v2)
{
    return acos(v2Cos(v1, v2));
}


decompiled_code:
void __fastcall ml_delete_link(void *ptr)
{
ml_disconnect_link((__int64 *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
ml_disconnect_link((__int64 *)ptr);
free(ptr);
}

original_code:
static void ml_delete_link(Link *link)
{
    ml_disconnect_link(link);
    free(link);
}

canonical_original_code:
static void ml_delete_link(struct Link *link)
{
    ml_disconnect_link(link);
    free(link);
}

variable_types: struct Link { struct Link *next_in_list; struct Link *prev_in_list; struct Link *next_in_node; struct Link *prev_in_node; struct MList { struct Link *first_in_list; struct Link *last_in_list; } *list; struct MListNode { struct Link *first_in_node; struct Link *last_in_node; } *node; } *

user_defined_types: struct Link { struct Link *next_in_list; struct Link *prev_in_list; struct Link *next_in_node; struct Link *prev_in_node; struct MList *list; struct MListNode *node; }


mlCreate

decompiled_code:
void *mlCreate()
{
return calloc(1uLL, 0x10uLL);
}

canonical_decompiled_code:
void *func3()
{
return calloc(1uLL, 0x10uLL);
}

original_code:
MList *mlCreate(void)
{
    MList *list = calloc(1, sizeof(MList));
    return(list);
}

canonical_original_code:
struct MList *mlCreate()
{
    struct MList *list = calloc(1, sizeof(MList));
    return(list);
}

variable_types: struct MList { struct Link { struct Link *next_in_list; struct Link *prev_in_list; struct Link *next_in_node; struct Link *prev_in_node; struct MList *list; struct MListNode { struct Link *first_in_node; struct Link *last_in_node; } *node; } *first_in_list; struct Link *last_in_list; } *

user_defined_types: struct MList { struct Link *first_in_list; struct Link *last_in_list; }


mlDelete

decompiled_code:
void __fastcall mlDelete(void *ptr)
{
mlClear((_QWORD **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
func5((_QWORD **)ptr);
free(ptr);
}

original_code:
void mlDelete(MList *list)
{
    mlClear(list);
    free(list);
}

canonical_original_code:
void mlDelete(struct MList *list)
{
    mlClear(list);
    free(list);
}

user_defined_types: struct MListNode { struct Link *first_in_node; struct Link *last_in_node; }


mlHead

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

result = *a1;
if ( *a1 )
result = *(_QWORD *)(result + 40);
return result;
}

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

result = *a1;
if ( *a1 )
result = *(_QWORD *)(result + 40);
return result;
}

original_code:
void *mlHead(MList *list)
{
    return(list->first_in_list == ((void *)0) ? ((void *)0) : list->first_in_list->node);
}

canonical_original_code:
void *mlHead(struct MList *list)
{
    return(list->first_in_list == ((void *)0) ? ((void *)0) : list->first_in_list->node);
}


mlTail

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

result = *(_QWORD *)(a1 + 8);
if ( result )
result = *(_QWORD *)(result + 40);
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( result )
result = *(_QWORD *)(result + 40);
return result;
}

original_code:
void *mlTail(MList *list)
{
    return(list->last_in_list == ((void *)0) ? ((void *)0) : list->last_in_list->node);
}

canonical_original_code:
void *mlTail(struct MList *list)
{
    return(list->last_in_list == ((void *)0) ? ((void *)0) : list->last_in_list->node);
}


mlRemoveHead

decompiled_code:
__int64 __fastcall mlRemoveHead(_QWORD **a1)
{
_QWORD *v1; // rdi
__int64 v2; // r12

v1 = *a1;
if ( !v1 )
return 0LL;
v2 = v1[5];
ml_delete_link(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD **a1)
{
_QWORD *v1; // rdi
__int64 v2; // r12

v1 = *a1;
if ( !v1 )
return 0LL;
v2 = v1[5];
func0(v1);
return v2;
}

original_code:
void *mlRemoveHead(MList *list)
{
    Link *link;
    MListNode *node;
    if ((link = list->first_in_list) == ((void *)0)) return(((void *)0));
    node = link->node;
    ml_delete_link(link);
    return(node);
}

canonical_original_code:
void *mlRemoveHead(struct MList *list)
{
    struct Link *link;
    struct MListNode *node;
    if ((link = list->first_in_list) == ((void *)0)) return(((void *)0));
    node = link->node;
    ml_delete_link(link);
    return(node);
}

variable_types: struct MListNode { struct Link { struct Link *next_in_list; struct Link *prev_in_list; struct Link *next_in_node; struct Link *prev_in_node; struct MList { struct Link *first_in_list; struct Link *last_in_list; } *list; struct MListNode *node; } *first_in_node; struct Link *last_in_node; } *


mlRemoveTail

decompiled_code:
__int64 __fastcall mlRemoveTail(__int64 a1)
{
_QWORD *v1; // rdi
__int64 v2; // r12

v1 = *(_QWORD **)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = v1[5];
ml_delete_link(v1);
return v2;
}

original_code:
void *mlRemoveTail(MList *list)
{
    Link *link;
    MListNode *node;
    if ((link = list->last_in_list) == ((void *)0)) return(((void *)0));
    node = link->node;
    ml_delete_link(link);
    return(node);
}

canonical_original_code:
void *mlRemoveTail(struct MList *list)
{
    struct Link *link;
    struct MListNode *node;
    if ((link = list->last_in_list) == ((void *)0)) return(((void *)0));
    node = link->node;
    ml_delete_link(link);
    return(node);
}


mlLength

decompiled_code:
__int64 __fastcall mlLength(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

original_code:
int mlLength(MList *list)
{
    Link *link;
    int count = 0;
    for (link = list->first_in_list; link; link = link->next_in_list) count++;
    return(count);
}

canonical_original_code:
int mlLength(struct MList *list)
{
    struct Link *link;
    int count = 0;
    for (link = list->first_in_list; link; link = link->next_in_list) count++;
    return(count);
}

variable_types: count int


mlIsEmpty

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

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

original_code:
int mlIsEmpty(MList *list)
{
    return(list->first_in_list == ((void *)0));
}

canonical_original_code:
int mlIsEmpty(struct MList *list)
{
    return(list->first_in_list == ((void *)0));
}


decompiled_code:
__int64 __fastcall udp_socket(int a1)
{
int v1; // eax
unsigned int v2; // er12
const char *v4; // r8
__int64 v5; // rdx

v1 = socket(a1, 2, 0);
v2 = v1;
if ( v1 == -1 )
{
dbgError(stderr, "udp.c", 42LL, "udp_socket", "unable to create socket");
return v2;
}
if ( setsockopt(v1, 1, 2, &one, 4u) )
{
v4 = "setsockopt(REUSEADDR) failed";
v5 = 47LL;
LABEL_6:
v2 = -1;
dbgError(stderr, "udp.c", v5, "udp_socket", v4);
return v2;
}
if ( setsockopt(v2, 1, 13, &linger, 8u) )
{
v4 = "setsockopt(LINGER) failed";
v5 = 52LL;
goto LABEL_6;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
unsigned int v2; // er12
const char *v4; // r8
__int64 v5; // rdx

v1 = socket(a1, 2, 0);
v2 = v1;
if ( v1 == -1 )
{
dbgError(stderr, "udp.c", 42LL, "udp_socket", "unable to create socket");
return v2;
}
if ( setsockopt(v1, 1, 2, &one, 4u) )
{
v4 = "setsockopt(REUSEADDR) failed";
v5 = 47LL;
LABEL_6:
v2 = -1;
dbgError(stderr, "udp.c", v5, "udp_socket", v4);
return v2;
}
if ( setsockopt(v2, 1, 13, &linger, 8u) )
{
v4 = "setsockopt(LINGER) failed";
v5 = 52LL;
goto LABEL_6;
}
return v2;
}

original_code:
static int udp_socket(int family)
{
    int sd;
    if ((sd = socket(family, SOCK_DGRAM, 0)) == -1) {
        _dbgError(stderr, "udp.c", 42, __func__, "unable to create socket");
        return -1;
    }
    if (setsockopt(sd, 1, 2, &one, sizeof(one)) != 0) {
        _dbgError(stderr, "udp.c", 47, __func__, "setsockopt(REUSEADDR) failed");
        return -1;
    }
    if (setsockopt(sd, 1, 13, &linger, sizeof(linger)) != 0) {
        _dbgError(stderr, "udp.c", 52, __func__, "setsockopt(LINGER) failed");
        return -1;
    }
    return sd;
}

variable_types: family int

variable_types: sd int


decompiled_code:
__int64 __fastcall udp_bind(int fd, char *name, unsigned __int16 a3, int a4)
{
int v4; // eax
unsigned int v5; // er12
__int64 v7; // rdx
const char *v8; // r8
int *v9; // rax
char s[6]; // [rsp+0h] [rbp-66h] BYREF
struct addrinfo *pai; // [rsp+6h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-58h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_family = a4;
pai = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a3);
v4 = getaddrinfo(name, s, &req, &pai);
if ( v4 )
{
gai_strerror(v4);
v7 = 149LL;
v8 = "%s: getaddrinfo for %s:%hu failed (%s)";
LABEL_5:
v5 = -1;
dbgError(stderr, "udp.c", v7, "udp_bind", v8);
goto LABEL_3;
}
v5 = bind(fd, pai->ai_addr, pai->ai_addrlen);
if ( v5 )
{
v9 = _errno_location();
strerror(*v9);
v7 = 155LL;
v8 = "%s: bind to %s:%hu failed: %s";
goto LABEL_5;
}
LABEL_3:
freeaddrinfo(pai);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, char *name, unsigned __int16 a3, int a4)
{
int v4; // eax
unsigned int v5; // er12
__int64 v7; // rdx
const char *v8; // r8
int *v9; // rax
char s[6]; // [rsp+0h] [rbp-66h] BYREF
struct addrinfo *pai; // [rsp+6h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-58h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_family = a4;
pai = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a3);
v4 = getaddrinfo(name, s, &req, &pai);
if ( v4 )
{
gai_strerror(v4);
v7 = 149LL;
v8 = "%s: getaddrinfo for %s:%hu failed (%s)";
LABEL_5:
v5 = -1;
dbgError(stderr, "udp.c", v7, "udp_bind", v8);
goto LABEL_3;
}
v5 = bind(fd, pai->ai_addr, pai->ai_addrlen);
if ( v5 )
{
v9 = _errno_location();
strerror(*v9);
v7 = 155LL;
v8 = "%s: bind to %s:%hu failed: %s";
goto LABEL_5;
}
LABEL_3:
freeaddrinfo(pai);
return v5;
}

original_code:
static int udp_bind(int sd, const char *host, uint16_t port, int family)
{
    struct addrinfo *info = ((void *)0);
    struct addrinfo hint = {
        .ai_family = family,
        .ai_socktype = SOCK_DGRAM
    };
    char port_str[6];
    snprintf(port_str, sizeof(port_str), "%hu", port);
    int r;
    if ((r = getaddrinfo(host, port_str, &hint, &info)) != 0) {
        _dbgError(stderr, "udp.c", 149, __func__, "%s: getaddrinfo for %s:%hu failed (%s)", __func__, host, port, gai_strerror(r));
        r = -1;
    }
    else if ((r = bind(sd, info->ai_addr, info->ai_addrlen)) != 0) {
        _dbgError(stderr, "udp.c", 155, __func__, "%s: bind to %s:%hu failed: %s", __func__, host, port, strerror((*__errno_location ())));
        r = -1;
    }
    freeaddrinfo(info);
    return r;
}

canonical_original_code:
static int udp_bind(int sd, char *host, unsigned short port, int family)
{
    struct addrinfo *info = ((void *)0);
    struct addrinfo hint = {
        .ai_family = family,
        .ai_socktype = SOCK_DGRAM
    };
    char port_str[6];
    snprintf(port_str, sizeof(port_str), "%hu", port);
    int r;
    if ((r = getaddrinfo(host, port_str, &hint, &info)) != 0) {
        _dbgError(stderr, "udp.c", 149, __func__, "%s: getaddrinfo for %s:%hu failed (%s)", __func__, host, port, gai_strerror(r));
        r = -1;
    }
    else if ((r = bind(sd, info->ai_addr, info->ai_addrlen)) != 0) {
        _dbgError(stderr, "udp.c", 155, __func__, "%s: bind to %s:%hu failed: %s", __func__, host, port, strerror((*__errno_location ())));
        r = -1;
    }
    freeaddrinfo(info);
    return r;
}

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: r 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 udp_connect(int fd, char *name, unsigned __int16 a3, int a4)
{
int v4; // eax
unsigned int v5; // er12
const char *v7; // 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 = a4;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a3);
v4 = getaddrinfo(name, s, &req, &pai);
if ( v4 )
{
v5 = -1;
v7 = gai_strerror(v4);
dbgError(stderr, "udp.c", 114LL, "udp_connect", "%s: getaddrinfo failed (%s)", "udp_connect", v7);
}
else
{
v5 = connect(fd, pai->ai_addr, pai->ai_addrlen);
if ( v5 )
{
v5 = -1;
dbgError(stderr, "udp.c", 120LL, "udp_connect", "%s: connect failed", "udp_connect");
}
}
freeaddrinfo(pai);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, char *name, unsigned __int16 a3, int a4)
{
int v4; // eax
unsigned int v5; // er12
const char *v7; // 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 = a4;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a3);
v4 = getaddrinfo(name, s, &req, &pai);
if ( v4 )
{
v5 = -1;
v7 = gai_strerror(v4);
dbgError(stderr, "udp.c", 114LL, "udp_connect", "%s: getaddrinfo failed (%s)", "udp_connect", v7);
}
else
{
v5 = connect(fd, pai->ai_addr, pai->ai_addrlen);
if ( v5 )
{
v5 = -1;
dbgError(stderr, "udp.c", 120LL, "udp_connect", "%s: connect failed", "udp_connect");
}
}
freeaddrinfo(pai);
return v5;
}

original_code:
static int udp_connect(int sd, const char *host, uint16_t port, int family)
{
    int r;
    char port_as_text[6];
    struct addrinfo *info;
    struct addrinfo hints = {
        .ai_family = family,
        .ai_socktype = SOCK_DGRAM
    };
    snprintf(port_as_text, sizeof(port_as_text), "%hu", port);
    if ((r = getaddrinfo(host, port_as_text, &hints, &info)) != 0) {
        _dbgError(stderr, "udp.c", 114, __func__, "%s: getaddrinfo failed (%s)", __func__, gai_strerror(r));
        r = -1;
    }
    else if (connect(sd, info->ai_addr, info->ai_addrlen) != 0) {
        _dbgError(stderr, "udp.c", 120, __func__, "%s: connect failed", __func__);
        r = -1;
    }
    freeaddrinfo(info);
    return r;
}

canonical_original_code:
static int udp_connect(int sd, char *host, unsigned short port, int family)
{
    int r;
    char port_as_text[6];
    struct addrinfo *info;
    struct addrinfo hints = {
        .ai_family = family,
        .ai_socktype = SOCK_DGRAM
    };
    snprintf(port_as_text, sizeof(port_as_text), "%hu", port);
    if ((r = getaddrinfo(host, port_as_text, &hints, &info)) != 0) {
        _dbgError(stderr, "udp.c", 114, __func__, "%s: getaddrinfo failed (%s)", __func__, gai_strerror(r));
        r = -1;
    }
    else if (connect(sd, info->ai_addr, info->ai_addrlen) != 0) {
        _dbgError(stderr, "udp.c", 120, __func__, "%s: connect failed", __func__);
        r = -1;
    }
    freeaddrinfo(info);
    return r;
}

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 udp_send(int fd, char *name, unsigned __int16 a3, int a4, const void *a5, size_t a6)
{
int v8; // eax
unsigned int v9; // ebx
const char *v11; // rax
char s[6]; // [rsp+0h] [rbp-76h] BYREF
struct addrinfo *pai; // [rsp+6h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-68h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_family = a4;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a3);
v8 = getaddrinfo(name, s, &req, &pai);
if ( v8 )
{
v11 = gai_strerror(v8);
dbgError(stderr, "udp.c", 82LL, "udp_send", "%s: getaddrinfo failed (%s)", "udp_send", v11);
}
v9 = sendto(fd, a5, a6, 0, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(pai);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, char *name, unsigned __int16 a3, int a4, const void *a5, size_t a6)
{
int v8; // eax
unsigned int v9; // ebx
const char *v11; // rax
char s[6]; // [rsp+0h] [rbp-76h] BYREF
struct addrinfo *pai; // [rsp+6h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-68h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_family = a4;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 6uLL, "%hu", a3);
v8 = getaddrinfo(name, s, &req, &pai);
if ( v8 )
{
v11 = gai_strerror(v8);
dbgError(stderr, "udp.c", 82LL, "udp_send", "%s: getaddrinfo failed (%s)", "udp_send", v11);
}
v9 = sendto(fd, a5, a6, 0, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(pai);
return v9;
}

original_code:
static int udp_send(int sd, const char *host, uint16_t port, int family,
        const char *data, size_t size)
{
    int r;
    char port_as_text[6];
    struct addrinfo *info;
    struct addrinfo hints = {
        .ai_family = family,
        .ai_socktype = SOCK_DGRAM
    };
    snprintf(port_as_text, sizeof(port_as_text), "%hu", port);
    if ((r = getaddrinfo(host, port_as_text, &hints, &info)) != 0) {
        _dbgError(stderr, "udp.c", 82, __func__, "%s: getaddrinfo failed (%s)", __func__, gai_strerror(r));
        r = -1;
    }
    r = sendto(sd, data, size, 0, info->ai_addr, info->ai_addrlen);
    freeaddrinfo(info);
    return r;
}

canonical_original_code:
static int udp_send(int sd, char *host, unsigned short port, int family, char *data, unsigned long size)
{
    int r;
    char port_as_text[6];
    struct addrinfo *info;
    struct addrinfo hints = {
        .ai_family = family,
        .ai_socktype = SOCK_DGRAM
    };
    snprintf(port_as_text, sizeof(port_as_text), "%hu", port);
    if ((r = getaddrinfo(host, port_as_text, &hints, &info)) != 0) {
        _dbgError(stderr, "udp.c", 82, __func__, "%s: getaddrinfo failed (%s)", __func__, gai_strerror(r));
        r = -1;
    }
    r = sendto(sd, data, size, 0, info->ai_addr, info->ai_addrlen);
    freeaddrinfo(info);
    return r;
}

variable_types:
data
char *

variable_types:
size
unsigned long

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


udpSocket

decompiled_code:
__int64 udpSocket()
{
return udp_socket(2);
}

canonical_decompiled_code:
__int64 func5()
{
return func0(2);
}

original_code:
int udpSocket(void)
{
    return udp_socket(2);
}

canonical_original_code:
int udpSocket()
{
    return udp_socket(2);
}


udpBind

decompiled_code:
__int64 __fastcall udpBind(int a1, char *a2, unsigned __int16 a3)
{
return udp_bind(a1, a2, a3, 2);
}

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

original_code:
int udpBind(int sd, const char *host, uint16_t port)
{
    return udp_bind(sd, host, port, 2);
}

canonical_original_code:
int udpBind(int sd, char *host, unsigned short port)
{
    return udp_bind(sd, host, port, 2);
}


udpConnect

decompiled_code:
__int64 __fastcall udpConnect(int a1, char *a2, unsigned __int16 a3)
{
return udp_connect(a1, a2, a3, 2);
}

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

original_code:
int udpConnect(int sd, const char *host, uint16_t port)
{
    return udp_connect(sd, host, port, 2);
}

canonical_original_code:
int udpConnect(int sd, char *host, unsigned short port)
{
    return udp_connect(sd, host, port, 2);
}


udpSend

decompiled_code:
__int64 __fastcall udpSend(int a1, char *a2, unsigned __int16 a3, const void *a4, size_t a5)
{
return udp_send(a1, a2, a3, 2, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char *a2, unsigned __int16 a3, const void *a4, size_t a5)
{
return func3(a1, a2, a3, 2, a4, a5);
}

original_code:
int udpSend(int sd, const char *host, uint16_t port,
        const char *data, size_t size)
{
    return udp_send(sd, host, port, 2, data, size);
}

canonical_original_code:
int udpSend(int sd, char *host, unsigned short port, char *data, unsigned long size)
{
    return udp_send(sd, host, port, 2, data, size);
}


decompiled_code:
__int64 udp6Socket()
{
return udp_socket(10);
}

canonical_decompiled_code:
__int64 func9()
{
return func0(10);
}

original_code:
int udp6Socket(void)
{
    return udp_socket(10);
}

canonical_original_code:
int udp6Socket()
{
    return udp_socket(10);
}


decompiled_code:
__int64 __fastcall udp6Bind(int a1, char *a2, unsigned __int16 a3)
{
return udp_bind(a1, a2, a3, 10);
}

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

original_code:
int udp6Bind(int sd, const char *host, uint16_t port)
{
    return udp_bind(sd, host, port, 10);
}

canonical_original_code:
int udp6Bind(int sd, char *host, unsigned short port)
{
    return udp_bind(sd, host, port, 10);
}


decompiled_code:
__int64 __fastcall udp6Connect(int a1, char *a2, unsigned __int16 a3)
{
return udp_connect(a1, a2, a3, 10);
}

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

original_code:
int udp6Connect(int sd, const char *host, uint16_t port)
{
    return udp_connect(sd, host, port, 10);
}

canonical_original_code:
int udp6Connect(int sd, char *host, unsigned short port)
{
    return udp_connect(sd, host, port, 10);
}


decompiled_code:
__int64 __fastcall udp6Send(int a1, char *a2, unsigned __int16 a3, const void *a4, size_t a5)
{
return udp_send(a1, a2, a3, 10, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, char *a2, unsigned __int16 a3, const void *a4, size_t a5)
{
return func3(a1, a2, a3, 10, a4, a5);
}

original_code:
int udp6Send(int sd, const char *host, uint16_t port,
        const char *data, size_t size)
{
    return udp_send(sd, host, port, 10, data, size);
}

canonical_original_code:
int udp6Send(int sd, char *host, unsigned short port, char *data, unsigned long size)
{
    return udp_send(sd, host, port, 10, data, size);
}


udpMulticastJoin

decompiled_code:
__int64 __fastcall udpMulticastJoin(unsigned int a1, const char *a2)
{
int v2; // edx
const void *v3; // rcx
socklen_t v4; // er8
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

v6[0] = inet_addr(a2);
v6[1] = _bswap_32_constprop_0(a1, 0LL, 35LL, v6, 8LL);
if ( setsockopt(a1, 0, v2, v3, v4) >= 0 )
return 0LL;
perror("Adding multicast membership");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, const char *a2)
{
int v2; // edx
const void *v3; // rcx
socklen_t v4; // er8
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

v6[0] = inet_addr(a2);
v6[1] = func4(a1, 0LL, 35LL, v6, 8LL);
if ( setsockopt(a1, 0, v2, v3, v4) >= 0 )
return 0LL;
perror("Adding multicast membership");
return 0xFFFFFFFFLL;
}

original_code:
int udpMulticastJoin(int sd, const char *group)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = inet_addr(group);
    mreq.imr_interface.s_addr = htonl(((in_addr_t) 0x00000000));
    if (setsockopt(sd, IPPROTO_IP, 35, &mreq, sizeof(mreq)) < 0)
    {
         perror("Adding multicast membership");
         return -1;
    }
    return 0;
}

canonical_original_code:
int udpMulticastJoin(int sd, char *group)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = inet_addr(group);
    mreq.imr_interface.s_addr = htonl(((unsigned int) 0x00000000));
    if (setsockopt(sd, IPPROTO_IP, 35, &mreq, sizeof(mreq)) < 0)
    {
         perror("Adding multicast membership");
         return -1;
    }
    return 0;
}

variable_types:
group
char *

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }


udpMulticastLoop

decompiled_code:
__int64 __fastcall udpMulticastLoop(int a1, char a2)
{
char optval[9]; // [rsp+Fh] [rbp-9h] BYREF

optval[0] = a2;
if ( setsockopt(a1, 0, 34, optval, 1u) >= 0 )
return 0LL;
perror("Setting IP_MULTICAST_LOOP");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, char a2)
{
char optval[9]; // [rsp+Fh] [rbp-9h] BYREF

optval[0] = a2;
if ( setsockopt(a1, 0, 34, optval, 1u) >= 0 )
return 0LL;
perror("Setting IP_MULTICAST_LOOP");
return 0xFFFFFFFFLL;
}

original_code:
int udpMulticastLoop(int sd, int allow_loop)
{
    char loop = allow_loop;
    if (setsockopt(sd, IPPROTO_IP, 34, (char *) &loop,
                sizeof(loop)) < 0)
    {
        perror("Setting IP_MULTICAST_LOOP");
        return -1;
    }
    return 0;
}

variable_types: loop char


udpMulticastInterface

decompiled_code:
__int64 __fastcall udpMulticastInterface(int fd, char *cp)
{
in_addr_t optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = inet_addr(cp);
if ( setsockopt(fd, 0, 32, optval, 4u) >= 0 )
return 0LL;
perror("Setting IP_MULTICAST_IF");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func15(int fd, char *cp)
{
in_addr_t optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = inet_addr(cp);
if ( setsockopt(fd, 0, 32, optval, 4u) >= 0 )
return 0LL;
perror("Setting IP_MULTICAST_IF");
return 0xFFFFFFFFLL;
}

original_code:
int udpMulticastInterface(int sd, const char *address)
{
    struct in_addr addr;
    addr.s_addr = inet_addr(address);
    if(setsockopt(sd, IPPROTO_IP, 32, (char *)&addr,
                sizeof(addr)) < 0)
    {
        perror("Setting IP_MULTICAST_IF");
        return -1;
    }
    return 0;
}

canonical_original_code:
int udpMulticastInterface(int sd, char *address)
{
    struct in_addr addr;
    addr.s_addr = inet_addr(address);
    if(setsockopt(sd, IPPROTO_IP, 32, (char *)&addr,
                sizeof(addr)) < 0)
    {
        perror("Setting IP_MULTICAST_IF");
        return -1;
    }
    return 0;
}

variable_types:
address
char *

variable_types:
addr
struct in_addr { unsigned int s_addr; }


udpMulticastLeave

decompiled_code:
__int64 __fastcall udpMulticastLeave(unsigned int a1, const char *a2)
{
int v2; // edx
const void *v3; // rcx
socklen_t v4; // er8
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

v6[0] = inet_addr(a2);
v6[1] = _bswap_32_constprop_0(a1, 0LL, 36LL, v6, 8LL);
if ( setsockopt(a1, 0, v2, v3, v4) >= 0 )
return 0LL;
perror("Removing multicast membership");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, const char *a2)
{
int v2; // edx
const void *v3; // rcx
socklen_t v4; // er8
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

v6[0] = inet_addr(a2);
v6[1] = func4(a1, 0LL, 36LL, v6, 8LL);
if ( setsockopt(a1, 0, v2, v3, v4) >= 0 )
return 0LL;
perror("Removing multicast membership");
return 0xFFFFFFFFLL;
}

original_code:
int udpMulticastLeave(int sd, const char *group)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = inet_addr(group);
    mreq.imr_interface.s_addr = htonl(((in_addr_t) 0x00000000));
    if (setsockopt(sd, IPPROTO_IP, 36, &mreq, sizeof(mreq)) < 0)
    {
         perror("Removing multicast membership");
         return -1;
    }
    return 0;
}

canonical_original_code:
int udpMulticastLeave(int sd, char *group)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = inet_addr(group);
    mreq.imr_interface.s_addr = htonl(((unsigned int) 0x00000000));
    if (setsockopt(sd, IPPROTO_IP, 36, &mreq, sizeof(mreq)) < 0)
    {
         perror("Removing multicast membership");
         return -1;
    }
    return 0;
}


paGet

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

result = 0LL;
if ( *(_DWORD *)a1 > a2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

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

result = 0LL;
if ( *(_DWORD *)a1 > a2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

original_code:
void *paGet(PointerArray *pa, int index)
{
    if (index >= pa->num_ptrs) {
        return ((void *)0);
    }
    else {
        return pa->ptr[index];
    }
}

canonical_original_code:
void *paGet(struct PointerArray *pa, int index)
{
    if (index >= pa->num_ptrs) {
        return ((void *)0);
    }
    else {
        return pa->ptr[index];
    }
}

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

variable_types: index int


paDrop

original_code:
void paDrop(PointerArray *pa, int index)
{
    if (index >= pa->num_ptrs) return;
    pa->ptr[index] = ((void *)0);
    if (index == pa->num_ptrs - 1) {
        int new_num_ptrs;
        while (index >= 0 && pa->ptr[index] == ((void *)0)) index--;
        new_num_ptrs = index + 1;
        pa->ptr = realloc(pa->ptr, sizeof(void *) * new_num_ptrs);
        pa->num_ptrs = new_num_ptrs;
    }
}

canonical_original_code:
void paDrop(struct PointerArray *pa, int index)
{
    if (index >= pa->num_ptrs) return;
    pa->ptr[index] = ((void *)0);
    if (index == pa->num_ptrs - 1) {
        int new_num_ptrs;
        while (index >= 0 && pa->ptr[index] == ((void *)0)) index--;
        new_num_ptrs = index + 1;
        pa->ptr = realloc(pa->ptr, sizeof(void *) * new_num_ptrs);
        pa->num_ptrs = new_num_ptrs;
    }
}

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


paSet

decompiled_code:
__int64 __fastcall paSet(int *a1, int a2, __int64 a3)
{
__int64 result; // rax
char *v5; // rax
__int64 v6; // rcx

if ( !a3 )
{
paDrop(a1, a2);
LABEL_5:
result = *((_QWORD *)a1 + 1);
*(_QWORD *)(result + 8LL * a2) = a3;
return result;
}
if ( a2 >= 0 )
{
if ( *a1 <= a2 )
{
v5 = (char *)realloc(*((void **)a1 + 1), 8LL * (a2 + 1));
v6 = *a1;
*((_QWORD *)a1 + 1) = v5;
memset(&v5[8 * v6], 0, 8LL * (a2 + 1 - (int)v6));
*a1 = a2 + 1;
}
goto LABEL_5;
}
dbgAbort(stderr, "pa.c", 43LL, "paSet", "index must be >= 0, got %d\n", (unsigned int)a2);
return paCount();
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, int a2, __int64 a3)
{
__int64 result; // rax
char *v5; // rax
__int64 v6; // rcx

if ( !a3 )
{
func1(a1, a2);
LABEL_5:
result = *((_QWORD *)a1 + 1);
*(_QWORD *)(result + 8LL * a2) = a3;
return result;
}
if ( a2 >= 0 )
{
if ( *a1 <= a2 )
{
v5 = (char *)realloc(*((void **)a1 + 1), 8LL * (a2 + 1));
v6 = *a1;
*((_QWORD *)a1 + 1) = v5;
memset(&v5[8 * v6], 0, 8LL * (a2 + 1 - (int)v6));
*a1 = a2 + 1;
}
goto LABEL_5;
}
dbgAbort(stderr, "pa.c", 43LL, "paSet", "index must be >= 0, got %d\n", (unsigned int)a2);
return func3();
}

original_code:
void paSet(PointerArray *pa, int index, void *ptr)
{
    if (ptr == ((void *)0)) {
        paDrop(pa, index);
    }
    else if (index < 0) {
        _dbgAbort(stderr, "pa.c", 43, __func__, "index must be >= 0, got %d\n", index);
    }
    else if (index >= pa->num_ptrs) {
        int new_num_ptrs = index + 1;
        pa->ptr = realloc(pa->ptr, sizeof(void *) * new_num_ptrs);
        memset(pa->ptr + pa->num_ptrs, 0,
                sizeof(void *) * (new_num_ptrs - pa->num_ptrs));
        pa->num_ptrs = new_num_ptrs;
    }
    pa->ptr[index] = ptr;
}

canonical_original_code:
void paSet(struct PointerArray *pa, int index, void *ptr)
{
    if (ptr == ((void *)0)) {
        paDrop(pa, index);
    }
    else if (index < 0) {
        _dbgAbort(stderr, "pa.c", 43, __func__, "index must be >= 0, got %d\n", index);
    }
    else if (index >= pa->num_ptrs) {
        int new_num_ptrs = index + 1;
        pa->ptr = realloc(pa->ptr, sizeof(void *) * new_num_ptrs);
        memset(pa->ptr + pa->num_ptrs, 0,
                sizeof(void *) * (new_num_ptrs - pa->num_ptrs));
        pa->num_ptrs = new_num_ptrs;
    }
    pa->ptr[index] = ptr;
}

variable_types:
ptr
void *


paCount

decompiled_code:
__int64 __fastcall paCount(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
return *a1;
}

original_code:
int paCount(PointerArray *pa)
{
    return pa->num_ptrs;
}

canonical_original_code:
int paCount(struct PointerArray *pa)
{
    return pa->num_ptrs;
}


paClear

decompiled_code:
void __fastcall paClear(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)a1 = 0;
}

original_code:
void paClear(PointerArray *pa)
{
    if (pa->ptr != ((void *)0)) free(pa->ptr);
    pa->ptr = ((void *)0);
    pa->num_ptrs = 0;
}

canonical_original_code:
void paClear(struct PointerArray *pa)
{
    if (pa->ptr != ((void *)0)) free(pa->ptr);
    pa->ptr = ((void *)0);
    pa->num_ptrs = 0;
}


paDestroy

decompiled_code:
void __fastcall paDestroy(void *ptr)
{
paClear((__int64)ptr);
free(ptr);
}

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

original_code:
void paDestroy(PointerArray *pa)
{
    paClear(pa);
    free(pa);
}

canonical_original_code:
void paDestroy(struct PointerArray *pa)
{
    paClear(pa);
    free(pa);
}


listCreate

decompiled_code:
void *listCreate()
{
void *result; // rax

result = calloc(1uLL, 0x18uLL);
if ( !result )
_assert_fail("list", "list.c", 0x1Du, "listCreate");
return result;
}

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

result = calloc(1uLL, 0x18uLL);
if ( !result )
_assert_fail("list", "list.c", 0x1Du, "listCreate");
return result;
}

original_code:
List *listCreate(void)
{
   List *list = calloc(1, sizeof(List));
   ((void) sizeof ((list) ? 1 : 0), __extension__ ({ if (list) ; else __assert_fail ("list", "list.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   return list;
}

canonical_original_code:
struct List *listCreate()
{
   struct List *list = calloc(1, sizeof(List));
   ((void) sizeof ((list) ? 1 : 0), __extension__ ({ if (list) ; else __assert_fail ("list", "list.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   return list;
}

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

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


listInitialize

decompiled_code:
void __fastcall listInitialize(__int64 a1)
{
if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x27u, "listInitialize");
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x27u, "listInitialize");
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}

original_code:
void listInitialize(List *list)
{
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    memset(list, 0, sizeof(List));
}

canonical_original_code:
void listInitialize(struct List *list)
{
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    memset(list, 0, sizeof(List));
}

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


listHead

decompiled_code:
__int64 __fastcall listHead(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
void *listHead(const List *list)
{
    return(list->head);
}

canonical_original_code:
void *listHead(struct List *list)
{
    return(list->head);
}


listTail

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

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

original_code:
void *listTail(const List *list)
{
    return(list->tail);
}

canonical_original_code:
void *listTail(struct List *list)
{
    return(list->tail);
}


listRemoveTail

decompiled_code:
__int64 __fastcall listRemoveTail(__int64 a1)
{
__int64 v1; // r12

if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x133u, "listRemoveTail");
v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
listRemove(a1, *(__int64 **)(a1 + 8));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // r12

if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x133u, "listRemoveTail");
v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
listRemove(a1, *(__int64 **)(a1 + 8));
return v1;
}

original_code:
void *listRemoveTail(List *list)
{
    ListNode *node;
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 307, __extension__ __PRETTY_FUNCTION__); }));
    if (list->tail == ((void *)0)) return(((void *)0));
    node = list->tail;
    _listRemove(list, node);
    return(node);
}

canonical_original_code:
void *listRemoveTail(struct List *list)
{
    struct ListNode *node;
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 307, __extension__ __PRETTY_FUNCTION__); }));
    if (list->tail == ((void *)0)) return(((void *)0));
    node = list->tail;
    _listRemove(list, node);
    return(node);
}

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


listLength

decompiled_code:
__int64 __fastcall listLength(__int64 a1)
{
if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x143u, "listLength");
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x143u, "listLength");
return *(unsigned int *)(a1 + 16);
}

original_code:
int listLength(const List *list)
{
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 323, __extension__ __PRETTY_FUNCTION__); }));
    return list->length;
}

canonical_original_code:
int listLength(struct List *list)
{
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 323, __extension__ __PRETTY_FUNCTION__); }));
    return list->length;
}


listIsEmpty

decompiled_code:
_BOOL8 __fastcall listIsEmpty(__int64 a1)
{
if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x14Du, "listIsEmpty");
return *(_DWORD *)(a1 + 16) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
if ( !a1 )
_assert_fail("list != NULL", "list.c", 0x14Du, "listIsEmpty");
return *(_DWORD *)(a1 + 16) == 0;
}

original_code:
int listIsEmpty(const List *list)
{
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 333, __extension__ __PRETTY_FUNCTION__); }));
    return(list->length == 0);
}

canonical_original_code:
int listIsEmpty(struct List *list)
{
    ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list.c", 333, __extension__ __PRETTY_FUNCTION__); }));
    return(list->length == 0);
}


decompiled_code:
__int64 __fastcall mdf_interpret_number(char *nptr, __int64 a2)
{
__int64 v2; // r12
size_t v3; // rax
double v4; // xmm0_8
size_t v5; // rax
__int64 result; // rax
char *endptr[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = strtol(nptr, endptr, 0);
v3 = strlen(nptr);
if ( endptr[0] == &nptr[v3] )
{
*(_QWORD *)(a2 + 40) = v2;
result = 0LL;
*(_DWORD *)(a2 + 8) = 1;
}
else
{
v4 = strtod(nptr, endptr);
v5 = strlen(nptr);
if ( endptr[0] == &nptr[v5] )
{
*(_DWORD *)(a2 + 8) = 2;
result = 0LL;
*(double *)(a2 + 40) = v4;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr, __int64 a2)
{
__int64 v2; // r12
size_t v3; // rax
double v4; // xmm0_8
size_t v5; // rax
__int64 result; // rax
char *endptr[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = strtol(nptr, endptr, 0);
v3 = strlen(nptr);
if ( endptr[0] == &nptr[v3] )
{
*(_QWORD *)(a2 + 40) = v2;
result = 0LL;
*(_DWORD *)(a2 + 8) = 1;
}
else
{
v4 = strtod(nptr, endptr);
v5 = strlen(nptr);
if ( endptr[0] == &nptr[v5] )
{
*(_DWORD *)(a2 + 8) = 2;
result = 0LL;
*(double *)(a2 + 40) = v4;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static int mdf_interpret_number(const char *value, MDF_Object *obj)
{
    long i;
    double f;
    char *end;
    i = strtol(value, &end, 0);
    if (end == value + strlen(value)) {
        obj->type = MDF_INT;
        obj->u.i = i;
        return 0;
    }
    f = strtod(value, &end);
    if (end == value + strlen(value)) {
        obj->type = MDF_FLOAT;
        obj->u.f = f;
        return 0;
    }
    return -1;
}

canonical_original_code:
static int mdf_interpret_number(char *value, struct MDF_Object *obj)
{
    long i;
    double f;
    char *end;
    i = strtol(value, &end, 0);
    if (end == value + strlen(value)) {
        obj->type = MDF_INT;
        obj->u.i = i;
        return 0;
    }
    f = strtod(value, &end);
    if (end == value + strlen(value)) {
        obj->type = MDF_FLOAT;
        obj->u.f = f;
        return 0;
    }
    return -1;
}

variable_types:
value
char *

variable_types: struct MDF_Object { struct MDF_Object *next; enum MDF_Type { MDF_STRING=0, MDF_INT=1, MDF_FLOAT=2, MDF_CONTAINER=3 } type; char *name; char *file; int line; union { char *s; long i; double f; struct MDF_Object *c; } u; } *

variable_types: i long

variable_types: f double

variable_types:
end
char *

user_defined_types: struct MDF_Object { struct MDF_Object *next; enum MDF_Type type; char *name; char *file; int line; union { char *s; long i; double f; struct MDF_Object *c; } u; }


mdfTypeName

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

result = "float";
if ( a1 != 2 )
{
if ( a1 > 2 )
{
result = "container";
if ( a1 != 3 )
result = 0LL;
}
else
{
result = "int";
if ( !a1 )
result = "string";
}
}
return result;
}

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

result = "float";
if ( a1 != 2 )
{
if ( a1 > 2 )
{
result = "container";
if ( a1 != 3 )
result = 0LL;
}
else
{
result = "int";
if ( !a1 )
result = "string";
}
}
return result;
}

original_code:
const char *mdfTypeName(const MDF_Type type)
{
    switch(type) {
    case MDF_STRING:
        return "string";
    case MDF_INT:
        return "int";
    case MDF_FLOAT:
        return "float";
    case MDF_CONTAINER:
        return "container";
    default:
        return ((void *)0);
    }
}

canonical_original_code:
char *mdfTypeName(enum MDF_Type type)
{
    switch(type) {
    case MDF_STRING:
        return "string";
    case MDF_INT:
        return "int";
    case MDF_FLOAT:
        return "float";
    case MDF_CONTAINER:
        return "container";
    default:
        return ((void *)0);
    }
}

variable_types: enum MDF_Type { MDF_STRING=0, MDF_INT=1, MDF_FLOAT=2, MDF_CONTAINER=3 }


scAddV

original_code:
const char *scAddV(SC *sc, const char *fmt, va_list ap)
{
    sc->curr = (sc->curr + 1) % sc->count;
    SC_Cell *cell = sc->cell + sc->curr;
    va_list ap_copy;
    __builtin_va_copy(ap_copy,ap);
    size_t n = vsnprintf(cell->str, cell->size, fmt, ap_copy);
    __builtin_va_end(ap_copy);
    if (n >= cell->size) {
        cell->size = n + 1;
        cell->str = realloc(cell->str, cell->size);
        vsnprintf(cell->str, cell->size, fmt, ap);
    }
    return cell->str;
}

canonical_original_code:
char *scAddV(struct SC *sc, char *fmt, __builtin_va_list ap)
{
    sc->curr = (sc->curr + 1) % sc->count;
    struct SC_Cell *cell = sc->cell + sc->curr;
    __builtin_va_list ap_copy;
    __builtin_va_copy(ap_copy,ap);
    unsigned long n = vsnprintf(cell->str, cell->size, fmt, ap_copy);
    __builtin_va_end(ap_copy);
    if (n >= cell->size) {
        cell->size = n + 1;
        cell->str = realloc(cell->str, cell->size);
        vsnprintf(cell->str, cell->size, fmt, ap);
    }
    return cell->str;
}

variable_types: struct SC { unsigned long curr; unsigned long count; struct SC_Cell { unsigned long size; char *str; } *cell; } *

variable_types:
fmt
char *

variable_types:
n
unsigned long

user_defined_types: struct SC { unsigned long curr; unsigned long count; struct SC_Cell *cell; }


scAdd

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

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

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

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

original_code:
__attribute__((format (printf, 2, 3)))
const char *scAdd(SC *sc, const char *fmt, ...)
{
    const char *ptr;
    va_list ap;
    __builtin_va_start(ap,fmt);
    ptr = scAddV(sc, fmt, ap);
    __builtin_va_end(ap);
    return ptr;
}

canonical_original_code:
char *scAdd(struct SC *sc, char *fmt, ...)
{
    char *ptr;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    ptr = scAddV(sc, fmt, ap);
    __builtin_va_end(ap);
    return ptr;
}

variable_types:
ptr
char *

user_defined_types: struct SC_Cell { unsigned long size; char *str; }


scDestroy

decompiled_code:
void __fastcall scDestroy(void *ptr)
{
unsigned __int64 v1; // rbx
__int64 v2; // rax

if ( *((_QWORD *)ptr + 1) )
{
v1 = 0LL;
do
{
v2 = v1++;
free(*(void **)(*((_QWORD *)ptr + 2) + 16 * v2 + 8));
}
while ( *((_QWORD *)ptr + 1) > v1 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
unsigned __int64 v1; // rbx
__int64 v2; // rax

if ( *((_QWORD *)ptr + 1) )
{
v1 = 0LL;
do
{
v2 = v1++;
free(*(void **)(*((_QWORD *)ptr + 2) + 16 * v2 + 8));
}
while ( *((_QWORD *)ptr + 1) > v1 );
}
free(ptr);
}

original_code:
void scDestroy(SC *sc)
{
    for (size_t i = 0; i < sc->count; i++) {
        free(sc->cell[i].str);
    }
    free(sc);
}

canonical_original_code:
void scDestroy(struct SC *sc)
{
    for (unsigned long i = 0; i < sc->count; i++) {
        free(sc->cell[i].str);
    }
    free(sc);
}

variable_types:
i
unsigned long


repo: jaccovanschaik/mx

decompiled_code:
char *__fastcall cmd_enum_to_string(unsigned int a1)
{
char *result; // rax

switch ( a1 )
{
case 0u:
result = "write";
break;
case 1u:
result = "timer_create";
break;
case 2u:
result = "timer_adjust";
break;
case 3u:
result = "timer_delete";
break;
case 4u:
result = "exit";
break;
default:
snprintf(buf_0, 0x50uLL, "%d (out of range)", a1);
result = buf_0;
break;
}
return result;
}

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

switch ( a1 )
{
case 0u:
result = "write";
break;
case 1u:
result = "timer_create";
break;
case 2u:
result = "timer_adjust";
break;
case 3u:
result = "timer_delete";
break;
case 4u:
result = "exit";
break;
default:
snprintf(buf_0, 0x50uLL, "%d (out of range)", a1);
result = buf_0;
break;
}
return result;
}

original_code:
char *cmd_enum_to_string(MX_CommandType val)
{
   static char buf[80];
   switch(val) {
   case MX_CT_WRITE: return("write");
   case MX_CT_TIMER_CREATE: return("timer_create");
   case MX_CT_TIMER_ADJUST: return("timer_adjust");
   case MX_CT_TIMER_DELETE: return("timer_delete");
   case MX_CT_EXIT: return("exit");
   default:
      snprintf(buf, sizeof(buf), "%d (out of range)", val);
      return(buf);
   }
}

canonical_original_code:
char *cmd_enum_to_string(enum MX_CommandType val)
{
   static char buf[80];
   switch(val) {
   case MX_CT_WRITE: return("write");
   case MX_CT_TIMER_CREATE: return("timer_create");
   case MX_CT_TIMER_ADJUST: return("timer_adjust");
   case MX_CT_TIMER_DELETE: return("timer_delete");
   case MX_CT_EXIT: return("exit");
   default:
      snprintf(buf, sizeof(buf), "%d (out of range)", val);
      return(buf);
   }
}

variable_types: enum MX_CommandType { MX_CT_WRITE=0, MX_CT_TIMER_CREATE=1, MX_CT_TIMER_ADJUST=2, MX_CT_TIMER_DELETE=3, MX_CT_EXIT=4, NUM_COMMANDS=5 }

variable_types:
buf
char [80]