disDropData

decompiled_code:
__int64 __fastcall disDropData(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 89LL, "disDropData", "unknown file descriptor: %d\n", (unsigned int)a2);
return paDrop(a1, (unsigned int)a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 89LL, "disDropData", "unknown file descriptor: %d\n", (unsigned int)a2);
return paDrop(a1, (unsigned int)a2);
}

original_code:
void disDropData(Dispatcher *dis, int fd)
{
    DIS_File *file = paGet(&dis->files, fd);
    if (0) _dbgPrint(stderr, "dis.c", 87, __func__, "Dropping fd %d\n", fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 89, __func__, "unknown file descriptor: %d\n", fd);
    paDrop(&dis->files, fd);
}

canonical_original_code:
void disDropData(struct Dispatcher *dis, int fd)
{
    struct DIS_File *file = paGet(&dis->files, fd);
    if (0) _dbgPrint(stderr, "dis.c", 87, __func__, "Dropping fd %d\n", fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 89, __func__, "unknown file descriptor: %d\n", fd);
    paDrop(&dis->files, fd);
}

variable_types: fd 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; } *

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


disWrite

repo: jaccovanschaik/libjvs

decompiled_code:
__int64 __fastcall disWrite(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbx

v6 = paGet(a1, a2);
dbgAssert(stderr, v6 != 0, "dis.c", 105LL, "disWrite", "unknown file descriptor: %d\n", (unsigned int)a2);
return bufAdd(v6, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbx

v6 = paGet(a1, a2);
dbgAssert(stderr, v6 != 0, "dis.c", 105LL, "disWrite", "unknown file descriptor: %d\n", (unsigned int)a2);
return bufAdd(v6, a3, a4);
}

original_code:
void disWrite(Dispatcher *dis, int fd, const char *data, size_t size)
{
    DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 105, __func__, "unknown file descriptor: %d\n", fd);
    bufAdd(&file->outgoing, data, size);
}

canonical_original_code:
void disWrite(struct Dispatcher *dis, int fd, char *data, unsigned long size)
{
    struct DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 105, __func__, "unknown file descriptor: %d\n", fd);
    bufAdd(&file->outgoing, data, size);
}

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

variable_types:
data
char *

variable_types:
size
unsigned long

return_type: void

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

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

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


disVaPack

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

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

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

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

original_code:
void disVaPack(Dispatcher *dis, int fd, va_list ap)
{
    char *str;
    int n = vastrpack(&str, ap);
    disWrite(dis, fd, str, n);
    free(str);
}

canonical_original_code:
void disVaPack(struct Dispatcher *dis, int fd, __builtin_va_list ap)
{
    char *str;
    int n = vastrpack(&str, ap);
    disWrite(dis, fd, str, n);
    free(str);
}

variable_types:
str
char *

variable_types: n int

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


disPack

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

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

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

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

original_code:
void disPack(Dispatcher *dis, int fd, ...)
{
    va_list ap;
    __builtin_va_start(ap,fd);
    disVaPack(dis, fd, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void disPack(struct Dispatcher *dis, int fd, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fd);
    disVaPack(dis, fd, ap);
    __builtin_va_end(ap);
}


disOnTime

decompiled_code:
__int64 __fastcall disOnTime(__int64 a1, __int64 a2, __int64 a3, double a4)
{
double *v5; // rbx
__int64 v6; // rbp
__int64 i; // rdi

v5 = (double *)calloc(1uLL, 0x30uLL);
v5[3] = a4;
*((_QWORD *)v5 + 4) = a2;
*((_QWORD *)v5 + 5) = a3;
v6 = a1 + 16;
for ( i = listHead(a1 + 16); i; i = listNext() )
{
if ( *(double *)(i + 24) > v5[3] )
break;
}
return listInsert(v6, v5, i);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, double a4)
{
double *v5; // rbx
__int64 v6; // rbp
__int64 i; // rdi

v5 = (double *)calloc(1uLL, 0x30uLL);
v5[3] = a4;
*((_QWORD *)v5 + 4) = a2;
*((_QWORD *)v5 + 5) = a3;
v6 = a1 + 16;
for ( i = listHead(a1 + 16); i; i = listNext() )
{
if ( *(double *)(i + 24) > v5[3] )
break;
}
return listInsert(v6, v5, i);
}

original_code:
void disOnTime(Dispatcher *dis, double t, void (*cb)(Dispatcher *dis, double t, void *udata), const void *udata)
{
    DIS_Timer *next_timer, *new_timer = calloc(1, sizeof(DIS_Timer));
    new_timer->t = t;
    new_timer->cb = cb;
    new_timer->udata = udata;
    for (next_timer = listHead(&dis->timers); next_timer;
         next_timer = _listNext(&(next_timer)->_node))
    {
        if (next_timer->t > new_timer->t) break;
    }
    _listInsert((&dis->timers), &(new_timer)->_node, &(next_timer)->_node);
}

canonical_original_code:
void disOnTime(struct Dispatcher *dis, double t, void (*cb)(struct Dispatcher *dis, double t, void *udata), void *udata)
{
    struct DIS_Timer *next_timer; struct DIS_Timer *new_timer = calloc(1, sizeof(DIS_Timer));
    new_timer->t = t;
    new_timer->cb = cb;
    new_timer->udata = udata;
    for (next_timer = listHead(&dis->timers); next_timer;
         next_timer = _listNext(&(next_timer)->_node))
    {
        if (next_timer->t > new_timer->t) break;
    }
    _listInsert((&dis->timers), &(new_timer)->_node, &(next_timer)->_node);
}

variable_types: t double

variable_types: void (*)(struct Dispatcher *dis, double t, void *udata)

variable_types:
udata
void *

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


disDropTime

decompiled_code:
void __fastcall disDropTime(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rbx

v3 = listHead(a1 + 16);
if ( v3 )
goto LABEL_4;
LABEL_2:
dbgAbort(stderr, "dis.c", 177LL, "disDropTime", "no such timer\n");
do
{
v3 = listNext(v3);
if ( !v3 )
goto LABEL_2;
LABEL_4:
;
}
while ( a3 != *(double *)(v3 + 24) || *(_QWORD *)(v3 + 32) != a2 );
listRemove(a1 + 16, v3, a3, a3);
free((void *)v3);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rbx

v3 = listHead(a1 + 16);
if ( v3 )
goto LABEL_4;
LABEL_2:
dbgAbort(stderr, "dis.c", 177LL, "disDropTime", "no such timer\n");
do
{
v3 = listNext(v3);
if ( !v3 )
goto LABEL_2;
LABEL_4:
;
}
while ( a3 != *(double *)(v3 + 24) || *(_QWORD *)(v3 + 32) != a2 );
listRemove(a1 + 16, v3, a3, a3);
free((void *)v3);
}

original_code:
void disDropTime(Dispatcher *dis, double t,
        void (*cb)(Dispatcher *dis, double t, void *udata))
{
    DIS_Timer *timer;
    for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        if (timer->t == t && timer->cb == cb) {
            _listRemove((&dis->timers), &(timer)->_node);
            free(timer);
            return;
        }
    }
    _dbgAbort(stderr, "dis.c", 177, __func__, "no such timer\n");
}

canonical_original_code:
void disDropTime(struct Dispatcher *dis, double t, void (*cb)(struct Dispatcher *dis, double t, void *udata))
{
    struct DIS_Timer *timer;
    for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        if (timer->t == t && timer->cb == cb) {
            _listRemove((&dis->timers), &(timer)->_node);
            free(timer);
            return;
        }
    }
    _dbgAbort(stderr, "dis.c", 177, __func__, "no such timer\n");
}


disFdCount

decompiled_code:
__int64 disFdCount()
{
return paCount();
}

canonical_decompiled_code:
__int64 func9()
{
return paCount();
}

original_code:
int disFdCount(Dispatcher *dis)
{
    return paCount(&dis->files);
}

canonical_original_code:
int disFdCount(struct Dispatcher *dis)
{
    return paCount(&dis->files);
}

return_type: int


disOwnsFd

decompiled_code:
_BOOL8 __fastcall disOwnsFd(__int64 a1, __int64 a2)
{
return paGet(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, __int64 a2)
{
return paGet(a1, a2) != 0;
}

original_code:
int disOwnsFd(Dispatcher *dis, int fd)
{
    return (paGet(&dis->files, fd) != ((void *)0));
}

canonical_original_code:
int disOwnsFd(struct Dispatcher *dis, int fd)
{
    return (paGet(&dis->files, fd) != ((void *)0));
}


disPrepareSelect

original_code:
int disPrepareSelect(Dispatcher *dis, int *nfds, fd_set *rfds, fd_set *wfds,
        struct timeval **tv)
{
    int fd;
    double delta_t;
    DIS_Timer *timer;
    *nfds = paCount(&dis->files);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((rfds)->fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wfds)->fds_bits)[0]) : "memory"); } while (0);
    if (0) _dbgPrint(stderr, "dis.c", 220, __func__, "File descriptors:");
    for (fd = 0; fd < *nfds; fd++) {
        DIS_File *file = paGet(&dis->files, fd);
        if (file == ((void *)0)) continue;
        if (0) fprintf(stderr, " %d", fd);
        ((void) (((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (bufLen(&file->outgoing) > 0) ((void) (((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (0) {
            fprintf(stderr, " (%s%s)",
                    ((((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "r" : "",
                    ((((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "w" : "");
        }
    }
    if (0) fprintf(stderr, "\n");
    if (0) _dbgPrint(stderr, "dis.c", 242, __func__, "%d pending timers:\n", listLength(&dis->timers));
    if (0) for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        fprintf(stderr, "\t%f seconds\n", timer->t - dnow());
    }
    if ((timer = listHead(&dis->timers)) == ((void *)0)) {
        *tv = ((void *)0);
    }
    else if ((delta_t = timer->t - dnow()) < 0) {
        dis->tv.tv_sec = 0;
        dis->tv.tv_usec = 0;
        *tv = &dis->tv;
    }
    else {
        if (0) _dbgPrint(stderr, "dis.c", 263, __func__, "First timer in %f seconds.\n", delta_t);
        dis->tv.tv_sec = (int) delta_t;
        dis->tv.tv_usec = 1000000 * fmod(delta_t, 1.0);
        *tv = &dis->tv;
    }
    return 0;
}

canonical_original_code:
int disPrepareSelect(struct Dispatcher *dis, int *nfds, struct fd_set *rfds, struct fd_set *wfds, struct timeval **tv)
{
    int fd;
    double delta_t;
    struct DIS_Timer *timer;
    *nfds = paCount(&dis->files);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((rfds)->fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wfds)->fds_bits)[0]) : "memory"); } while (0);
    if (0) _dbgPrint(stderr, "dis.c", 220, __func__, "File descriptors:");
    for (fd = 0; fd < *nfds; fd++) {
        struct DIS_File *file = paGet(&dis->files, fd);
        if (file == ((void *)0)) continue;
        if (0) fprintf(stderr, " %d", fd);
        ((void) (((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (bufLen(&file->outgoing) > 0) ((void) (((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (0) {
            fprintf(stderr, " (%s%s)",
                    ((((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "r" : "",
                    ((((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "w" : "");
        }
    }
    if (0) fprintf(stderr, "\n");
    if (0) _dbgPrint(stderr, "dis.c", 242, __func__, "%d pending timers:\n", listLength(&dis->timers));
    if (0) for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        fprintf(stderr, "\t%f seconds\n", timer->t - dnow());
    }
    if ((timer = listHead(&dis->timers)) == ((void *)0)) {
        *tv = ((void *)0);
    }
    else if ((delta_t = timer->t - dnow()) < 0) {
        dis->tv.tv_sec = 0;
        dis->tv.tv_usec = 0;
        *tv = &dis->tv;
    }
    else {
        if (0) _dbgPrint(stderr, "dis.c", 263, __func__, "First timer in %f seconds.\n", delta_t);
        dis->tv.tv_sec = (int) delta_t;
        dis->tv.tv_usec = 1000000 * fmod(delta_t, 1.0);
        *tv = &dis->tv;
    }
    return 0;
}

variable_types:
nfds
int *

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

variable_types:
wfds
struct fd_set *

variable_types:
tv
struct timeval **


disHandleTimer

decompiled_code:
void __fastcall disHandleTimer(__int64 a1)
{
__int64 v1; // rbx

v1 = listRemoveHead(a1 + 16);
dbgAssert(stderr, v1 != 0, "dis.c", 281LL, "disHandleTimer", "no pending timer.\n");
(*(void (__fastcall **)(__int64, _QWORD, double))(v1 + 32))(a1, *(_QWORD *)(v1 + 40), *(double *)(v1 + 24));
free((void *)v1);
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
__int64 v1; // rbx

v1 = listRemoveHead(a1 + 16);
dbgAssert(stderr, v1 != 0, "dis.c", 281LL, "disHandleTimer", "no pending timer.\n");
(*(void (__fastcall **)(__int64, _QWORD, double))(v1 + 32))(a1, *(_QWORD *)(v1 + 40), *(double *)(v1 + 24));
free((void *)v1);
}

original_code:
void disHandleTimer(Dispatcher *dis)
{
    DIS_Timer *timer = listRemoveHead(&dis->timers);
    _dbgAssert(stderr, timer != ((void *)0), "dis.c", 281, __func__, "no pending timer.\n");
    timer->cb(dis, timer->t, (void *) timer->udata);
    free(timer);
}

canonical_original_code:
void disHandleTimer(struct Dispatcher *dis)
{
    struct DIS_Timer *timer = listRemoveHead(&dis->timers);
    _dbgAssert(stderr, timer != ((void *)0), "dis.c", 281, __func__, "no pending timer.\n");
    timer->cb(dis, timer->t, (void *) timer->udata);
    free(timer);
}


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

decompiled_code:
ssize_t __fastcall disHandleWritable(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
size_t v3; // r12
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; // rbx
size_t v3; // r12
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: r int


disHandleFiles

decompiled_code:
void __fastcall disHandleFiles(__int64 a1, int a2, __int64 a3, __int64 a4)
{
unsigned int i; // ebx

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( disOwnsFd(a1, i) && (*(_QWORD *)(a3 + 8LL * ((int)i / 64)) & (1LL << ((int)i % 64))) != 0 )
disHandleReadable(a1, i);
if ( disOwnsFd(a1, i) && (*(_QWORD *)(a4 + 8LL * ((int)i / 64)) & (1LL << ((int)i % 64))) != 0 )
disHandleWritable(a1, i);
}
}
}

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


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


disHandleEvents

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

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

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

if ( (int)func11(a1, nfds, &readfds, &writefds, &timeout) < 0 )
{
func16(a1, 0, 0, 0LL, 0LL);
result = 0;
}
else if ( nfds[0] || timeout )
{
result = select(nfds[0], &readfds, &writefds, 0LL, timeout);
if ( result >= 0 )
{
func16(a1, result, nfds[0], (__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; } *


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

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


disClose

decompiled_code:
void *__fastcall disClose(__int64 a1)
{
unsigned int i; // ebp
void *v2; // rbx
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; // ebp
void *v2; // rbx
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: fd 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; } *


disClear

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

result = disClose((__int64)a1);
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
a1[4] = 0LL;
a1[5] = 0LL;
a1[6] = 0LL;
return result;
}

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

result = func19((__int64)a1);
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
a1[4] = 0LL;
a1[5] = 0LL;
a1[6] = 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; // rbp

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; // rbp

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:
__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:
__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:
__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:
__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; // r13
size_t v6; // rax
__int64 result; // rax
size_t v8; // rax
_QWORD *v9; // r12
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; // r13
size_t v6; // rax
__int64 result; // rax
size_t v8; // rax
_QWORD *v9; // r12
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);
v4 = v3;
if ( v3 )
{
bufSetS(&namebuf_0, *(_QWORD *)(*(_QWORD *)(v3 + 24) + 24LL));
bufAddS(&namebuf_0, &LC0);
bufAddS(&namebuf_0, *(_QWORD *)(v4 + 32));
v4 = bufGet(&namebuf_0);
}
return v4;
}

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);
v4 = v3;
if ( v3 )
{
bufSetS(&namebuf_0, *(_QWORD *)(*(_QWORD *)(v3 + 24) + 24LL));
bufAddS(&namebuf_0, &LC0);
bufAddS(&namebuf_0, *(_QWORD *)(v4 + 32));
v4 = bufGet(&namebuf_0);
}
return v4;
}

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; // rbx

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; // rbx

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:
__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 *


pathClear

decompiled_code:
void __fastcall pathClear(__int64 a1)
{
__int64 v1; // rbx
void **v2; // rbp
const char *v3; // r13
size_t v4; // rax
__int64 v5; // rbx
void **v6; // rbp
const char *v7; // r13
size_t v8; // rax

v1 = hlHead(a1 + 98328);
while ( v1 )
{
v2 = (void **)v1;
v1 = hlNext(v1);
v3 = (const char *)v2[4];
v4 = strlen(v3);
hlDel(a1 + 98328, v3, v4);
free(v2[4]);
free(v2);
}
v5 = hlHead(a1);
while ( v5 )
{
v6 = (void **)v5;
v5 = hlNext(v5);
v7 = (const char *)v6[3];
v8 = strlen(v7);
hlDel(a1, v7, v8);
free(v6[3]);
free(v6);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
void **v2; // rbp
const char *v3; // r13
size_t v4; // rax
__int64 v5; // rbx
void **v6; // rbp
const char *v7; // r13
size_t v8; // rax

v1 = hlHead(a1 + 98328);
while ( v1 )
{
v2 = (void **)v1;
v1 = hlNext(v1);
v3 = (const char *)v2[4];
v4 = strlen(v3);
hlDel(a1 + 98328, v3, v4);
free(v2[4]);
free(v2);
}
v5 = hlHead(a1);
while ( v5 )
{
v6 = (void **)v5;
v5 = hlNext(v5);
v7 = (const char *)v6[3];
v8 = strlen(v7);
hlDel(a1, v7, v8);
free(v6[3]);
free(v6);
}
}

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

v2 = (a2 >> 3) + 1;
result = (void *)*a1;
if ( (int)result < v2 )
{
v4 = (char *)realloc(*((void **)a1 + 1), v2);
*((_QWORD *)a1 + 1) = v4;
result = memset(&v4[*a1], 0, v2 - *a1);
*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

v2 = (a2 >> 3) + 1;
result = (void *)*a1;
if ( (int)result < v2 )
{
v4 = (char *)realloc(*((void **)a1 + 1), v2);
*((_QWORD *)a1 + 1) = v4;
result = memset(&v4[*a1], 0, v2 - *a1);
*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, ...)
{
unsigned int *v9; // rdx
char *result; // rax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( 1 )
{
if ( va[0].gp_offset > 0x2F )
{
v9 = (unsigned int *)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;
}
else
{
v9 = (unsigned int *)((char *)va[0].reg_save_area + va[0].gp_offset);
result = (char *)(va[0].gp_offset + 8);
va[0].gp_offset += 8;
}
if ( *v9 == -1 )
break;
bmSetBit(a1, *v9);
}
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, ...)
{
unsigned int *v9; // rdx
char *result; // rax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( 1 )
{
if ( va[0].gp_offset > 0x2F )
{
v9 = (unsigned int *)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;
}
else
{
v9 = (unsigned int *)((char *)va[0].reg_save_area + va[0].gp_offset);
result = (char *)(va[0].gp_offset + 8);
va[0].gp_offset += 8;
}
if ( *v9 == -1 )
break;
bmSetBit(a1, *v9);
}
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, ...)
{
unsigned int *v9; // rdx
char *result; // rax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( 1 )
{
if ( va[0].gp_offset > 0x2F )
{
v9 = (unsigned int *)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;
}
else
{
v9 = (unsigned int *)((char *)va[0].reg_save_area + va[0].gp_offset);
result = (char *)(va[0].gp_offset + 8);
va[0].gp_offset += 8;
}
if ( *v9 == -1 )
break;
bmClrBit(a1, *v9);
}
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, ...)
{
unsigned int *v9; // rdx
char *result; // rax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( 1 )
{
if ( va[0].gp_offset > 0x2F )
{
v9 = (unsigned int *)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;
}
else
{
v9 = (unsigned int *)((char *)va[0].reg_save_area + va[0].gp_offset);
result = (char *)(va[0].gp_offset + 8);
va[0].gp_offset += 8;
}
if ( *v9 == -1 )
break;
bmClrBit(a1, *v9);
}
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)
{
unsigned __int8 v4; // r8
unsigned __int8 v5; // di
unsigned __int8 v6; // al
int v7; // eax
__int64 v8; // rdx
unsigned __int8 v10; // cl
unsigned __int8 v11; // si

v4 = *a2;
v5 = *a1;
v6 = v5;
if ( *a2 >= v5 )
v6 = *a2;
v7 = v6 - 1;
if ( v7 < 0 )
return 0LL;
v8 = v7;
while ( v5 <= v7 )
{
if ( v7 < v4 )
{
v10 = 0;
goto LABEL_11;
}
LABEL_13:
--v7;
--v8;
if ( v7 == -1 )
return 0LL;
}
v10 = *(_BYTE *)(*((_QWORD *)a1 + 1) + v8);
if ( v4 <= v7 )
{
v11 = 0;
goto LABEL_12;
}
LABEL_11:
v11 = *(_BYTE *)(*((_QWORD *)a2 + 1) + v8);
if ( v11 > v10 )
return 0xFFFFFFFFLL;
LABEL_12:
if ( v11 >= v10 )
goto LABEL_13;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 v4; // r8
unsigned __int8 v5; // di
unsigned __int8 v6; // al
int v7; // eax
__int64 v8; // rdx
unsigned __int8 v10; // cl
unsigned __int8 v11; // si

v4 = *a2;
v5 = *a1;
v6 = v5;
if ( *a2 >= v5 )
v6 = *a2;
v7 = v6 - 1;
if ( v7 < 0 )
return 0LL;
v8 = v7;
while ( v5 <= v7 )
{
if ( v7 < v4 )
{
v10 = 0;
goto LABEL_11;
}
LABEL_13:
--v7;
--v8;
if ( v7 == -1 )
return 0LL;
}
v10 = *(_BYTE *)(*((_QWORD *)a1 + 1) + v8);
if ( v4 <= v7 )
{
v11 = 0;
goto LABEL_12;
}
LABEL_11:
v11 = *(_BYTE *)(*((_QWORD *)a2 + 1) + v8);
if ( v11 > v10 )
return 0xFFFFFFFFLL;
LABEL_12:
if ( v11 >= v10 )
goto LABEL_13;
return 1LL;
}

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)
{
*a1 = a2 + *a1;
a1[1] = a3 + a1[1];
}

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

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:
double __fastcall v2Len(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

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

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

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

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)
{
*a1 = a2 * *a1;
a1[1] = a2 * a1[1];
}

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

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 = 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:
double __fastcall v2Angle(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

v4 = v2Cos(a1, a2, a3, a4);
return acos(v4);
}

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

v4 = func14(a1, a2, a3, a4);
return 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 func2(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; // rbx

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; // rbx

v1 = *a1;
if ( !v1 )
return 0LL;
v2 = v1[5];
func2(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; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
_QWORD *v1; // rdi
__int64 v2; // rbx

v1 = *(_QWORD **)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = v1[5];
func2(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 v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

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; // ebx

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

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

v1 = socket(a1, 2, 0);
v2 = v1;
if ( v1 == -1 )
{
dbgError(stderr, "udp.c", 42LL, "udp_socket", "unable to create socket");
}
else if ( setsockopt(v1, 1, 2, &one, 4u) )
{
dbgError(stderr, "udp.c", 47LL, "udp_socket", "setsockopt(REUSEADDR) failed");
v2 = -1;
}
else if ( setsockopt(v2, 1, 13, &linger, 8u) )
{
dbgError(stderr, "udp.c", 52LL, "udp_socket", "setsockopt(LINGER) failed");
v2 = -1;
}
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)
{
__int64 v4; // r12
int v5; // eax
unsigned int v6; // ebx
const char *v8; // rax
int *v9; // rax
char *v10; // rax
char s[6]; // [rsp+Ah] [rbp-6Eh] BYREF
struct addrinfo req; // [rsp+10h] [rbp-68h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-30h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(int fd, char *name, unsigned __int16 a3, int a4)
{
__int64 v4; // r12
int v5; // eax
unsigned int v6; // ebx
const char *v8; // rax
int *v9; // rax
char *v10; // rax
char s[6]; // [rsp+Ah] [rbp-6Eh] BYREF
struct addrinfo req; // [rsp+10h] [rbp-68h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-30h] BYREF

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

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; // ebx
const char *v7; // rax
struct addrinfo v8; // [rsp+0h] [rbp-58h] BYREF
struct addrinfo *pai; // [rsp+30h] [rbp-28h] BYREF
char s[30]; // [rsp+3Ah] [rbp-1Eh] BYREF

v8.ai_flags = 0;
*(_QWORD *)&v8.ai_socktype = 2LL;
*(_QWORD *)&v8.ai_addrlen = 0LL;
v8.ai_addr = 0LL;
v8.ai_canonname = 0LL;
v8.ai_next = 0LL;
v8.ai_family = a4;
snprintf(s, 6uLL, "%hu", a3);
v4 = getaddrinfo(name, s, &v8, &pai);
if ( v4 )
{
v7 = gai_strerror(v4);
dbgError(stderr, "udp.c", 114LL, "udp_connect", "%s: getaddrinfo failed (%s)", "udp_connect", v7);
v5 = -1;
}
else
{
v5 = connect(fd, pai->ai_addr, pai->ai_addrlen);
if ( v5 )
{
dbgError(stderr, "udp.c", 120LL, "udp_connect", "%s: connect failed", "udp_connect");
v5 = -1;
}
}
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; // ebx
const char *v7; // rax
struct addrinfo v8; // [rsp+0h] [rbp-58h] BYREF
struct addrinfo *pai; // [rsp+30h] [rbp-28h] BYREF
char s[30]; // [rsp+3Ah] [rbp-1Eh] BYREF

v8.ai_flags = 0;
*(_QWORD *)&v8.ai_socktype = 2LL;
*(_QWORD *)&v8.ai_addrlen = 0LL;
v8.ai_addr = 0LL;
v8.ai_canonname = 0LL;
v8.ai_next = 0LL;
v8.ai_family = a4;
snprintf(s, 6uLL, "%hu", a3);
v4 = getaddrinfo(name, s, &v8, &pai);
if ( v4 )
{
v7 = gai_strerror(v4);
dbgError(stderr, "udp.c", 114LL, "udp_connect", "%s: getaddrinfo failed (%s)", "udp_connect", v7);
v5 = -1;
}
else
{
v5 = connect(fd, pai->ai_addr, pai->ai_addrlen);
if ( v5 )
{
dbgError(stderr, "udp.c", 120LL, "udp_connect", "%s: connect failed", "udp_connect");
v5 = -1;
}
}
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
struct addrinfo v12; // [rsp+0h] [rbp-68h] BYREF
struct addrinfo *pai; // [rsp+30h] [rbp-38h] BYREF
char s[46]; // [rsp+3Ah] [rbp-2Eh] BYREF

v12.ai_flags = 0;
*(_QWORD *)&v12.ai_socktype = 2LL;
*(_QWORD *)&v12.ai_addrlen = 0LL;
v12.ai_addr = 0LL;
v12.ai_canonname = 0LL;
v12.ai_next = 0LL;
v12.ai_family = a4;
snprintf(s, 6uLL, "%hu", a3);
v8 = getaddrinfo(name, s, &v12, &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
struct addrinfo v12; // [rsp+0h] [rbp-68h] BYREF
struct addrinfo *pai; // [rsp+30h] [rbp-38h] BYREF
char s[46]; // [rsp+3Ah] [rbp-2Eh] BYREF

v12.ai_flags = 0;
*(_QWORD *)&v12.ai_socktype = 2LL;
*(_QWORD *)&v12.ai_addrlen = 0LL;
v12.ai_addr = 0LL;
v12.ai_canonname = 0LL;
v12.ai_next = 0LL;
v12.ai_family = a4;
snprintf(s, 6uLL, "%hu", a3);
v8 = getaddrinfo(name, s, &v12, &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(int fd, char *cp)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = inet_addr(cp);
optval[1] = _bswap_32(0);
if ( setsockopt(fd, 0, 35, optval, 8u) >= 0 )
return 0LL;
perror("Adding multicast membership");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd, char *cp)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = inet_addr(cp);
optval[1] = func4(0);
if ( setsockopt(fd, 0, 35, optval, 8u) >= 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(int fd, char *cp)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = inet_addr(cp);
optval[1] = _bswap_32(0);
if ( setsockopt(fd, 0, 36, optval, 8u) >= 0 )
return 0LL;
perror("Removing multicast membership");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func16(int fd, char *cp)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = inet_addr(cp);
optval[1] = func4(0);
if ( setsockopt(fd, 0, 36, optval, 8u) >= 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;
    }
}


paSet

decompiled_code:
char *__fastcall paSet(struct _IO_FILE *a1, const char *a2, __int64 a3)
{
struct _IO_FILE *v3; // rbp
int v4; // ebx
char *result; // rax
__int64 v7; // r9
char *v8; // rax

v3 = a1;
v4 = (int)a2;
if ( !a3 )
{
paDrop((__int64)a1, (int)a2);
goto LABEL_4;
}
if ( (int)a2 < 0 )
{
v7 = (unsigned int)a2;
a2 = "pa.c";
a1 = stderr;
dbgAbort(stderr, "pa.c", 43LL, "paSet", "index must be >= 0, got %d\n", v7);
goto LABEL_7;
}
if ( a1->_flags <= (int)a2 )
{
LABEL_7:
v8 = (char *)realloc(a1->_IO_read_ptr, 8LL * ((int)a2 + 1));
v3->_IO_read_ptr = v8;
memset(&v8[8 * v3->_flags], 0, 8LL * ((int)a2 + 1 - v3->_flags));
v3->_flags = (_DWORD)a2 + 1;
}
LABEL_4:
result = v3->_IO_read_ptr;
*(_QWORD *)&result[8 * v4] = a3;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(struct _IO_FILE *a1, const char *a2, __int64 a3)
{
struct _IO_FILE *v3; // rbp
int v4; // ebx
char *result; // rax
__int64 v7; // r9
char *v8; // rax

v3 = a1;
v4 = (int)a2;
if ( !a3 )
{
func1((__int64)a1, (int)a2);
goto LABEL_4;
}
if ( (int)a2 < 0 )
{
v7 = (unsigned int)a2;
a2 = "pa.c";
a1 = stderr;
dbgAbort(stderr, "pa.c", 43LL, "paSet", "index must be >= 0, got %d\n", v7);
goto LABEL_7;
}
if ( a1->_flags <= (int)a2 )
{
LABEL_7:
v8 = (char *)realloc(a1->_IO_read_ptr, 8LL * ((int)a2 + 1));
v3->_IO_read_ptr = v8;
memset(&v8[8 * v3->_flags], 0, 8LL * ((int)a2 + 1 - v3->_flags));
v3->_flags = (_DWORD)a2 + 1;
}
LABEL_4:
result = v3->_IO_read_ptr;
*(_QWORD *)&result[8 * v4] = a3;
return result;
}

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