decompiled_code:
size_t test_recv_longer()
{
size_t v0; // rax
size_t v1; // rbp
size_t result; // rax
int fds[2]; // [rsp+8h] [rbp-430h] BYREF
char v4[528]; // [rsp+10h] [rbp-428h] BYREF
char s[536]; // [rsp+220h] [rbp-218h] BYREF

if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair error");
exit(1);
}
strcpy(
s,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
sd = fdopen(fds[1], "r");
v0 = strlen(s);
send(fds[0], s, v0, 0);
net_recv(v4);
close(fds[0]);
close(fds[1]);
v1 = strlen(s);
result = strlen(v4);
if ( v1 <= result )
return mu_fail("test_recv_longer: The received message should be stripped");
if ( result != 512 )
result = mu_fail("test_recv_longer: Received message length should be 'MSG_SIZE'");
return result;
}

canonical_decompiled_code:
size_t func12()
{
size_t v0; // rax
size_t v1; // rbp
size_t result; // rax
int fds[2]; // [rsp+8h] [rbp-430h] BYREF
char v4[528]; // [rsp+10h] [rbp-428h] BYREF
char s[536]; // [rsp+220h] [rbp-218h] BYREF

if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair error");
exit(1);
}
strcpy(
s,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
sd = fdopen(fds[1], "r");
v0 = strlen(s);
send(fds[0], s, v0, 0);
func5(v4);
close(fds[0]);
close(fds[1]);
v1 = strlen(s);
result = strlen(v4);
if ( v1 <= result )
return mu_fail("test_recv_longer: The received message should be stripped");
if ( result != 512 )
result = mu_fail("test_recv_longer: Received message length should be 'MSG_SIZE'");
return result;
}

original_code:
void test_recv_longer() {
    int socks[2];
    char in[(512 + 1) + 10], out[(512 + 1) + 10];
    if (socketpair(1, SOCK_STREAM, 0, socks) == -1) {
        perror("socketpair error");
        exit(1);
    }
    memset(out, 'a', (512 + 1) + 10);
    out[(512 + 1) + 9] = '\0';
    _sd = fdopen(socks[1], "r");
    send(socks[0], out, strlen(out), 0);
    net_recv(in);
    close(socks[0]);
    close(socks[1]);
    do { if (!(strlen(out) > strlen(in))) { mu_fail("test_recv_longer: The received message should be stripped"); return; } } while (0);
    do { if (!(strlen(in) == 512)) { mu_fail("test_recv_longer: Received message length should be 'MSG_SIZE'"); return; } } while (0);
}

canonical_original_code:
void test_recv_longer() {
    int socks[2];
    char in[-1]; char out[-1];
    if (socketpair(1, SOCK_STREAM, 0, socks) == -1) {
        perror("socketpair error");
        exit(1);
    }
    memset(out, 'a', (512 + 1) + 10);
    out[(512 + 1) + 9] = '\0';
    _sd = fdopen(socks[1], "r");
    send(socks[0], out, strlen(out), 0);
    net_recv(in);
    close(socks[0]);
    close(socks[1]);
    do { if (!(strlen(out) > strlen(in))) { mu_fail("test_recv_longer: The received message should be stripped"); return; } } while (0);
    do { if (!(strlen(in) == 512)) { mu_fail("test_recv_longer: Received message length should be 'MSG_SIZE'"); return; } } while (0);
}

variable_types:
in
char [-1]


repo: nacx/circus

decompiled_code:
__int64 test_listen_ready()
{
__int64 result; // rax
unsigned int buf; // [rsp+8h] [rbp-20h] BYREF
int v2; // [rsp+Ch] [rbp-1Ch] BYREF
int pipedes[2]; // [rsp+10h] [rbp-18h] BYREF
int v4[2]; // [rsp+18h] [rbp-10h] BYREF

if ( pipe(pipedes) == -1 || pipe(v4) == -1 )
{
perror("pipe error");
exit(1);
}
if ( fork() <= 0 )
{
close(pipedes[1]);
close(v4[0]);
*(_DWORD *)socket = pipedes[0];
v2 = net_listen();
if ( write(v4[1], &v2, 4uLL) != -1 )
{
close(pipedes[0]);
close(v4[1]);
exit(0);
}
LABEL_12:
perror("write error");
exit(1);
}
close(pipedes[0]);
close(v4[1]);
poll(0LL, 0LL, 1000);
if ( write(pipedes[1], "test", 4uLL) == -1 || read(v4[0], &buf, 4uLL) == -1 )
goto LABEL_12;
close(pipedes[1]);
close(v4[0]);
result = buf;
if ( buf )
result = mu_fail("test_listen_ready: status should be 'NET_READY'");
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
unsigned int buf; // [rsp+8h] [rbp-20h] BYREF
int v2; // [rsp+Ch] [rbp-1Ch] BYREF
int pipedes[2]; // [rsp+10h] [rbp-18h] BYREF
int v4[2]; // [rsp+18h] [rbp-10h] BYREF

if ( pipe(pipedes) == -1 || pipe(v4) == -1 )
{
perror("pipe error");
exit(1);
}
if ( fork() <= 0 )
{
close(pipedes[1]);
close(v4[0]);
*(_DWORD *)socket = pipedes[0];
v2 = func6();
if ( write(v4[1], &v2, 4uLL) != -1 )
{
close(pipedes[0]);
close(v4[1]);
exit(0);
}
LABEL_12:
perror("write error");
exit(1);
}
close(pipedes[0]);
close(v4[1]);
poll(0LL, 0LL, 1000);
if ( write(pipedes[1], "test", 4uLL) == -1 || read(v4[0], &buf, 4uLL) == -1 )
goto LABEL_12;
close(pipedes[1]);
close(v4[0]);
result = buf;
if ( buf )
result = mu_fail("test_listen_ready: status should be 'NET_READY'");
return result;
}

original_code:
void test_listen_ready() {
    int pid, p2c[2], c2p[2];
    if (pipe(p2c) == -1) {
        perror("pipe error");
        exit(1);
    }
    if (pipe(c2p) == -1) {
        perror("pipe error");
        exit(1);
    }
    pid = fork();
    if (pid > 0) {
        enum net_status status;
        close(p2c[0]);
        close(c2p[1]);
        poll(0, 0, 1000);
        if (write(p2c[1], "test", strlen("test")) == -1) {
            perror("write error");
            exit(1);
        }
        if (read(c2p[0], &status, sizeof(enum net_status)) == -1) {
            perror("write error");
            exit(1);
        }
        close(p2c[1]);
        close(c2p[0]);
        do { if (!(status == NET_READY)) { mu_fail("test_listen_ready: status should be 'NET_READY'"); return; } } while (0);
    } else {
        enum net_status status;
        close(p2c[1]);
        close(c2p[0]);
        _socket = p2c[0];
        status = net_listen();
        if (write(c2p[1], &status, sizeof(enum net_status)) == -1) {
            perror("write error");
            exit(1);
        }
        close(p2c[0]);
        close(c2p[1]);
        exit(0);
    }
}

canonical_original_code:
void test_listen_ready() {
    int pid; int p2c[2]; int c2p[2];
    if (pipe(p2c) == -1) {
        perror("pipe error");
        exit(1);
    }
    if (pipe(c2p) == -1) {
        perror("pipe error");
        exit(1);
    }
    pid = fork();
    if (pid > 0) {
        enum net_status status;
        close(p2c[0]);
        close(c2p[1]);
        poll(0, 0, 1000);
        if (write(p2c[1], "test", strlen("test")) == -1) {
            perror("write error");
            exit(1);
        }
        if (read(c2p[0], &status, sizeof(enum net_status)) == -1) {
            perror("write error");
            exit(1);
        }
        close(p2c[1]);
        close(c2p[0]);
        do { if (!(status == NET_READY)) { mu_fail("test_listen_ready: status should be 'NET_READY'"); return; } } while (0);
    } else {
        enum net_status status;
        close(p2c[1]);
        close(c2p[0]);
        _socket = p2c[0];
        status = net_listen();
        if (write(c2p[1], &status, sizeof(enum net_status)) == -1) {
            perror("write error");
            exit(1);
        }
        close(p2c[0]);
        close(c2p[1]);
        exit(0);
    }
}

variable_types: pid int

variable_types: enum net_status { NET_READY=0, NET_ERROR=1, NET_CLOSE=2, NET_TIMEOUT=3 }

return_type: void


decompiled_code:
__int64 test_listen_error()
{
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

if ( pipe(pipedes) == -1 )
{
perror("pipe error");
exit(1);
}
*(_DWORD *)socket = pipedes[0];
close(pipedes[0]);
close(pipedes[1]);
result = net_listen();
if ( (_DWORD)result != 1 )
result = mu_fail("test_listen_error: status should be 'NET_ERROR'");
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

if ( pipe(pipedes) == -1 )
{
perror("pipe error");
exit(1);
}
*(_DWORD *)socket = pipedes[0];
close(pipedes[0]);
close(pipedes[1]);
result = func6();
if ( (_DWORD)result != 1 )
result = mu_fail("test_listen_error: status should be 'NET_ERROR'");
return result;
}

original_code:
void test_listen_error() {
    int fd[2];
    enum net_status status;
    if (pipe(fd) == -1) {
        perror("pipe error");
        exit(1);
    }
    _socket = fd[0];
    close(fd[0]);
    close(fd[1]);
    status = net_listen();
    do { if (!(status == NET_ERROR)) { mu_fail("test_listen_error: status should be 'NET_ERROR'"); return; } } while (0);
}

variable_types:
fd
int [2]

user_defined_types: enum net_status { NET_READY=0, NET_ERROR=1, NET_CLOSE=2, NET_TIMEOUT=3 }


decompiled_code:
__int64 test_network()
{
__int64 result; // rax

test_connection();
++tests_run;
test_send();
++tests_run;
test_send_longer();
++tests_run;
test_recv();
++tests_run;
test_recv_longer();
++tests_run;
test_listen_ready();
++tests_run;
result = test_listen_error();
++tests_run;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax

func8();
++tests_run;
func9();
++tests_run;
func10();
++tests_run;
func11();
++tests_run;
func12();
++tests_run;
func13();
++tests_run;
result = func14();
++tests_run;
return result;
}

original_code:
void test_network() {
    do { (void)0; test_connection(); tests_run++; } while (0);
    do { (void)0; test_send(); tests_run++; } while (0);
    do { (void)0; test_send_longer(); tests_run++; } while (0);
    do { (void)0; test_recv(); tests_run++; } while (0);
    do { (void)0; test_recv_longer(); tests_run++; } while (0);
    do { (void)0; test_listen_ready(); tests_run++; } while (0);
    do { (void)0; test_listen_error(); tests_run++; } while (0);
}


decompiled_code:
int q_create()
{
void *v0; // rax
_QWORD *v1; // rbx
pthread_mutex_t *v2; // rax

v0 = malloc(0x20uLL);
events = v0;
if ( !v0 )
{
perror("Out of memory (q_create)");
exit(1);
}
v1 = v0;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
v1[2] = v2;
if ( !v2 )
{
perror("Out of memory (q_create: lock)");
exit(1);
}
*v1 = 0LL;
v1[1] = 0LL;
*((_DWORD *)v1 + 6) = 0;
return pthread_mutex_init(v2, 0LL);
}

canonical_decompiled_code:
int func0()
{
void *v0; // rax
_QWORD *v1; // rbx
pthread_mutex_t *v2; // rax

v0 = malloc(0x20uLL);
events = v0;
if ( !v0 )
{
perror("Out of memory (q_create)");
exit(1);
}
v1 = v0;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
v1[2] = v2;
if ( !v2 )
{
perror("Out of memory (q_create: lock)");
exit(1);
}
*v1 = 0LL;
v1[1] = 0LL;
*((_DWORD *)v1 + 6) = 0;
return pthread_mutex_init(v2, 0LL);
}

original_code:
static void q_create() {
    (void)0;
    if ((events = malloc(sizeof(struct q_dispatch))) == 0) {
        perror("Out of memory (q_create)");
        exit(1);
    }
    if ((events->lock = malloc(sizeof(pthread_mutex_t))) == 0) {
        perror("Out of memory (q_create: lock)");
        exit(1);
    }
    events->top = ((void *)0);
    events->bottom = ((void *)0);
    events->size = 0;
    pthread_mutex_init(events->lock, ((void *)0));
}

user_defined_types: struct q_dispatch { struct q_node *top; struct q_node *bottom; union pthread_mutex_t *lock; int size; }

user_defined_types: struct q_node { struct raw_event *event; struct q_node *prev; struct q_node *next; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct raw_event { struct timeval timestamp; char *__buffer; char *type; char *prefix; int num_params; char *params[15]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

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


decompiled_code:
int consumer_create()
{
void *v0; // rax
void *v1; // rbx
void *v2; // rax
pthread_mutex_t *v3; // rax
pthread_mutex_t *v4; // rbp
void *v5; // rax
int result; // eax

v0 = malloc(0x20uLL);
consumer = v0;
if ( !v0 )
{
perror("Out of memory (consumer_create)");
exit(1);
}
v1 = v0;
v2 = malloc(8uLL);
*(_QWORD *)v1 = v2;
if ( !v2 )
{
perror("Out of memory (consumer_create: worker)");
exit(1);
}
v3 = (pthread_mutex_t *)malloc(0x28uLL);
*((_QWORD *)v1 + 1) = v3;
v4 = v3;
if ( !v3 )
{
perror("Out of memory (consumer_create: lock)");
exit(1);
}
v5 = malloc(0x30uLL);
*((_QWORD *)v1 + 2) = v5;
if ( !v5 )
{
perror("Out of memory (consumer_create: ready)");
exit(1);
}
*((_DWORD *)v1 + 6) = 0;
pthread_mutex_init(v4, 0LL);
pthread_cond_init(*((pthread_cond_t **)v1 + 2), 0LL);
result = pthread_create(*(pthread_t **)v1, 0LL, event_consumer, 0LL);
if ( result )
{
puts("dispatcher: Error creating event consumer thread");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
void *v0; // rax
void *v1; // rbx
void *v2; // rax
pthread_mutex_t *v3; // rax
pthread_mutex_t *v4; // rbp
void *v5; // rax
int result; // eax

v0 = malloc(0x20uLL);
consumer = v0;
if ( !v0 )
{
perror("Out of memory (consumer_create)");
exit(1);
}
v1 = v0;
v2 = malloc(8uLL);
*(_QWORD *)v1 = v2;
if ( !v2 )
{
perror("Out of memory (consumer_create: worker)");
exit(1);
}
v3 = (pthread_mutex_t *)malloc(0x28uLL);
*((_QWORD *)v1 + 1) = v3;
v4 = v3;
if ( !v3 )
{
perror("Out of memory (consumer_create: lock)");
exit(1);
}
v5 = malloc(0x30uLL);
*((_QWORD *)v1 + 2) = v5;
if ( !v5 )
{
perror("Out of memory (consumer_create: ready)");
exit(1);
}
*((_DWORD *)v1 + 6) = 0;
pthread_mutex_init(v4, 0LL);
pthread_cond_init(*((pthread_cond_t **)v1 + 2), 0LL);
result = pthread_create(*(pthread_t **)v1, 0LL, event_consumer, 0LL);
if ( result )
{
puts("dispatcher: Error creating event consumer thread");
exit(1);
}
return result;
}

original_code:
static void consumer_create() {
    if ((consumer = malloc(sizeof(struct dsp_consumer))) == 0) {
        perror("Out of memory (consumer_create)");
        exit(1);
    }
    if ((consumer->worker = malloc(sizeof(pthread_t))) == 0) {
        perror("Out of memory (consumer_create: worker)");
        exit(1);
    }
    if ((consumer->lock = malloc(sizeof(pthread_mutex_t))) == 0) {
        perror("Out of memory (consumer_create: lock)");
        exit(1);
    }
    if ((consumer->ready = malloc(sizeof(pthread_cond_t))) == 0) {
        perror("Out of memory (consumer_create: ready)");
        exit(1);
    }
    consumer->terminate = 0;
    pthread_mutex_init(consumer->lock, ((void *)0));
    pthread_cond_init(consumer->ready, ((void *)0));
    (void)0;
    if (pthread_create(consumer->worker, ((void *)0), event_consumer, ((void *)0)) != 0) {
        printf("dispatcher: Error creating event consumer thread\n");
        exit(1);
    }
}

user_defined_types: struct dsp_consumer { unsigned long *worker; union pthread_mutex_t *lock; union pthread_cond_t *ready; int terminate; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


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

result = (int)consumer;
if ( consumer )
result = pthread_cond_signal(*((pthread_cond_t **)consumer + 2));
return result;
}

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

result = (int)consumer;
if ( consumer )
result = pthread_cond_signal(*((pthread_cond_t **)consumer + 2));
return result;
}

original_code:
static void consumer_notify() {
    if (consumer != ((void *)0)) {
        pthread_cond_signal(consumer->ready);
    }
}


decompiled_code:
int __fastcall q_push(__int64 a1)
{
_QWORD *v1; // rax
void *v2; // rdx
bool v3; // zf
__int64 v4; // rcx

pthread_mutex_lock(*((pthread_mutex_t **)events + 2));
v1 = malloc(0x18uLL);
if ( !v1 )
{
perror("Out of memory (q_node)");
exit(1);
}
v2 = events;
*v1 = a1;
v1[1] = 0LL;
v3 = *(_QWORD *)v2 == 0LL;
v1[2] = 0LL;
if ( v3 )
{
*(_QWORD *)v2 = v1;
}
else
{
v4 = *((_QWORD *)v2 + 1);
*(_QWORD *)(v4 + 16) = v1;
v1[1] = v4;
}
*((_QWORD *)v2 + 1) = v1;
++*((_DWORD *)v2 + 6);
pthread_mutex_unlock(*((pthread_mutex_t **)v2 + 2));
return consumer_notify();
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
_QWORD *v1; // rax
void *v2; // rdx
bool v3; // zf
__int64 v4; // rcx

pthread_mutex_lock(*((pthread_mutex_t **)events + 2));
v1 = malloc(0x18uLL);
if ( !v1 )
{
perror("Out of memory (q_node)");
exit(1);
}
v2 = events;
*v1 = a1;
v1[1] = 0LL;
v3 = *(_QWORD *)v2 == 0LL;
v1[2] = 0LL;
if ( v3 )
{
*(_QWORD *)v2 = v1;
}
else
{
v4 = *((_QWORD *)v2 + 1);
*(_QWORD *)(v4 + 16) = v1;
v1[1] = v4;
}
*((_QWORD *)v2 + 1) = v1;
++*((_DWORD *)v2 + 6);
pthread_mutex_unlock(*((pthread_mutex_t **)v2 + 2));
return func2();
}

original_code:
static void q_push(struct raw_event* event) {
    struct q_node* node;
    pthread_mutex_lock(events->lock);
    if ((node = malloc(sizeof(struct q_node))) == 0) {
        perror("Out of memory (q_node)");
        exit(1);
    }
    node->event = event;
    node->prev = ((void *)0);
    node->next = ((void *)0);
    if (events->top == ((void *)0)) {
        (void)0;
        events->top = node;
        events->bottom = node;
    } else {
        (void)0;
        events->bottom->next = node;
        node->prev = events->bottom;
        events->bottom = node;
    }
    events->size++;
    (void)0;
    pthread_mutex_unlock(events->lock);
    consumer_notify();
}

canonical_original_code:
static void q_push(struct raw_event *event) {
    struct q_node *node;
    pthread_mutex_lock(events->lock);
    if ((node = malloc(sizeof(struct q_node))) == 0) {
        perror("Out of memory (q_node)");
        exit(1);
    }
    node->event = event;
    node->prev = ((void *)0);
    node->next = ((void *)0);
    if (events->top == ((void *)0)) {
        (void)0;
        events->top = node;
        events->bottom = node;
    } else {
        (void)0;
        events->bottom->next = node;
        node->prev = events->bottom;
        events->bottom = node;
    }
    events->size++;
    (void)0;
    pthread_mutex_unlock(events->lock);
    consumer_notify();
}

variable_types: struct q_node { struct raw_event { struct timeval { long tv_sec; long tv_usec; } timestamp; char *__buffer; char *type; char *prefix; int num_params; char *params[15]; } *event; struct q_node *prev; struct q_node *next; } *


decompiled_code:
void q_destroy()
{
pthread_mutex_t **v0; // rbp
_QWORD *v1; // rbx
void *v2; // rdi

v0 = (pthread_mutex_t **)events;
if ( events )
{
v1 = *(_QWORD **)events;
if ( *(_QWORD *)events )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[2];
free(v2);
}
while ( v1 );
}
pthread_mutex_destroy(v0[2]);
free(v0[2]);
free(v0);
events = 0LL;
}
}

canonical_decompiled_code:
void func4()
{
pthread_mutex_t **v0; // rbp
_QWORD *v1; // rbx
void *v2; // rdi

v0 = (pthread_mutex_t **)events;
if ( events )
{
v1 = *(_QWORD **)events;
if ( *(_QWORD *)events )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[2];
free(v2);
}
while ( v1 );
}
pthread_mutex_destroy(v0[2]);
free(v0[2]);
free(v0);
events = 0LL;
}
}

original_code:
static void q_destroy() {
    if (events != ((void *)0)) {
        struct q_node* node, *next;
        (void)0;
        node = events->top;
        while (node != ((void *)0)) {
            next = node->next;
            free(node);
            node = next;
        }
        pthread_mutex_destroy(events->lock);
        free(events->lock);
        free(events);
        events = ((void *)0);
    }
}

canonical_original_code:
static void q_destroy() {
    if (events != ((void *)0)) {
        struct q_node *node; struct q_node *next;
        (void)0;
        node = events->top;
        while (node != ((void *)0)) {
            next = node->next;
            free(node);
            node = next;
        }
        pthread_mutex_destroy(events->lock);
        free(events->lock);
        free(events);
        events = ((void *)0);
    }
}


decompiled_code:
void consumer_destroy()
{
pthread_cond_t **v0; // rax
void *v1; // rbp
void *thread_return; // [rsp+0h] [rbp-10h] BYREF

v0 = (pthread_cond_t **)consumer;
if ( consumer )
{
*((_DWORD *)consumer + 6) = 1;
pthread_cond_signal(v0[2]);
if ( pthread_join(**(_QWORD **)consumer, &thread_return) )
{
puts("dispatcher: Error waiting for the event consumer thread");
exit(1);
}
v1 = consumer;
pthread_mutex_destroy(*((pthread_mutex_t **)consumer + 1));
pthread_cond_destroy(*((pthread_cond_t **)v1 + 2));
free(*((void **)v1 + 1));
free(*((void **)v1 + 2));
free(*(void **)v1);
free(v1);
consumer = 0LL;
}
}

canonical_decompiled_code:
void func5()
{
pthread_cond_t **v0; // rax
void *v1; // rbp
void *thread_return; // [rsp+0h] [rbp-10h] BYREF

v0 = (pthread_cond_t **)consumer;
if ( consumer )
{
*((_DWORD *)consumer + 6) = 1;
pthread_cond_signal(v0[2]);
if ( pthread_join(**(_QWORD **)consumer, &thread_return) )
{
puts("dispatcher: Error waiting for the event consumer thread");
exit(1);
}
v1 = consumer;
pthread_mutex_destroy(*((pthread_mutex_t **)consumer + 1));
pthread_cond_destroy(*((pthread_cond_t **)v1 + 2));
free(*((void **)v1 + 1));
free(*((void **)v1 + 2));
free(*(void **)v1);
free(v1);
consumer = 0LL;
}
}

original_code:
static void consumer_destroy() {
    if (consumer != ((void *)0)) {
        void* status;
        consumer->terminate = 1;
        pthread_cond_signal(consumer->ready);
        (void)0;
        if (pthread_join(*consumer->worker, &status) != 0) {
            printf("dispatcher: Error waiting for the event consumer thread\n");
            exit(1);
        }
        pthread_mutex_destroy(consumer->lock);
        pthread_cond_destroy(consumer->ready);
        free(consumer->lock);
        free(consumer->ready);
        free(consumer->worker);
        free(consumer);
        consumer = ((void *)0);
    }
}

canonical_original_code:
static void consumer_destroy() {
    if (consumer != ((void *)0)) {
        void *status;
        consumer->terminate = 1;
        pthread_cond_signal(consumer->ready);
        (void)0;
        if (pthread_join(*consumer->worker, &status) != 0) {
            printf("dispatcher: Error waiting for the event consumer thread\n");
            exit(1);
        }
        pthread_mutex_destroy(consumer->lock);
        pthread_cond_destroy(consumer->ready);
        free(consumer->lock);
        free(consumer->ready);
        free(consumer->worker);
        free(consumer);
        consumer = ((void *)0);
    }
}

variable_types:
status
void *


decompiled_code:
__int64 q_pop()
{
void *v0; // rbx
__int64 *v1; // rdi
__int64 v2; // rax
__int64 v3; // r12

pthread_mutex_lock(*((pthread_mutex_t **)events + 2));
v0 = events;
v1 = *(__int64 **)events;
if ( *(_QWORD *)events )
{
v2 = v1[2];
*(_QWORD *)events = v2;
if ( v2 )
*(_QWORD *)(v2 + 8) = 0LL;
else
*((_QWORD *)v0 + 1) = 0LL;
--*((_DWORD *)v0 + 6);
v3 = *v1;
free(v1);
}
else
{
v3 = 0LL;
}
pthread_mutex_unlock(*((pthread_mutex_t **)v0 + 2));
return v3;
}

canonical_decompiled_code:
__int64 func8()
{
void *v0; // rbx
__int64 *v1; // rdi
__int64 v2; // rax
__int64 v3; // r12

pthread_mutex_lock(*((pthread_mutex_t **)events + 2));
v0 = events;
v1 = *(__int64 **)events;
if ( *(_QWORD *)events )
{
v2 = v1[2];
*(_QWORD *)events = v2;
if ( v2 )
*(_QWORD *)(v2 + 8) = 0LL;
else
*((_QWORD *)v0 + 1) = 0LL;
--*((_DWORD *)v0 + 6);
v3 = *v1;
free(v1);
}
else
{
v3 = 0LL;
}
pthread_mutex_unlock(*((pthread_mutex_t **)v0 + 2));
return v3;
}

original_code:
struct raw_event* q_pop() {
    struct raw_event* event = ((void *)0);
    pthread_mutex_lock(events->lock);
    if (events->top != ((void *)0)) {
        struct q_node* node;
        node = events->top;
        events->top = node->next;
        if (events->top == ((void *)0)) {
            events->bottom = ((void *)0);
        } else {
            events->top->prev = ((void *)0);
        }
        events->size--;
        event = node->event;
        free(node);
        (void)0;
        (void)0;
    }
    pthread_mutex_unlock(events->lock);
    return event;
}

canonical_original_code:
struct raw_event *q_pop() {
    struct raw_event *event = ((void *)0);
    pthread_mutex_lock(events->lock);
    if (events->top != ((void *)0)) {
        struct q_node *node;
        node = events->top;
        events->top = node->next;
        if (events->top == ((void *)0)) {
            events->bottom = ((void *)0);
        } else {
            events->top->prev = ((void *)0);
        }
        events->size--;
        event = node->event;
        free(node);
        (void)0;
        (void)0;
    }
    pthread_mutex_unlock(events->lock);
    return event;
}

variable_types: struct raw_event { struct timeval { long tv_sec; long tv_usec; } timestamp; char *__buffer; char *type; char *prefix; int num_params; char *params[15]; } *


decompiled_code:
void __fastcall __noreturn event_consumer(void *a1)
{
__int64 v1; // rbp
pthread_mutex_t **v2; // rax

pthread_mutex_lock(*((pthread_mutex_t **)consumer + 1));
while ( 1 )
{
v2 = (pthread_mutex_t **)consumer;
if ( *((_DWORD *)consumer + 6) )
break;
if ( !*((_DWORD *)events + 6) )
{
pthread_cond_wait(*((pthread_cond_t **)consumer + 2), *((pthread_mutex_t **)consumer + 1));
v2 = (pthread_mutex_t **)consumer;
if ( *((_DWORD *)consumer + 6) )
break;
}
v1 = q_pop();
fire_event(v1);
evt_raw_destroy(v1);
}
pthread_mutex_unlock(v2[1]);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
__int64 v1; // rbp
pthread_mutex_t **v2; // rax

pthread_mutex_lock(*((pthread_mutex_t **)consumer + 1));
while ( 1 )
{
v2 = (pthread_mutex_t **)consumer;
if ( *((_DWORD *)consumer + 6) )
break;
if ( !*((_DWORD *)events + 6) )
{
pthread_cond_wait(*((pthread_cond_t **)consumer + 2), *((pthread_mutex_t **)consumer + 1));
v2 = (pthread_mutex_t **)consumer;
if ( *((_DWORD *)consumer + 6) )
break;
}
v1 = func8();
func7(v1);
evt_raw_destroy(v1);
}
pthread_mutex_unlock(v2[1]);
pthread_exit(0LL);
}

original_code:
static void* event_consumer(void* arg) {
    pthread_mutex_lock(consumer->lock);
    while (consumer->terminate == 0) {
        if (events->size == 0) {
            (void)0;
            pthread_cond_wait(consumer->ready, consumer->lock);
            (void)0;
        }
        if (consumer->terminate == 0) {
            struct raw_event* event = q_pop();
            _fire_event(event);
            evt_raw_destroy(event);
        }
    }
    (void)0;
    pthread_mutex_unlock(consumer->lock);
    pthread_exit(((void *)0));
}

canonical_original_code:
static void *event_consumer(void *arg) {
    pthread_mutex_lock(consumer->lock);
    while (consumer->terminate == 0) {
        if (events->size == 0) {
            (void)0;
            pthread_cond_wait(consumer->ready, consumer->lock);
            (void)0;
        }
        if (consumer->terminate == 0) {
            struct raw_event *event = q_pop();
            _fire_event(event);
            evt_raw_destroy(event);
        }
    }
    (void)0;
    pthread_mutex_unlock(consumer->lock);
    pthread_exit(((void *)0));
}

variable_types:
arg
void *

return_type: void *


decompiled_code:
int dsp_start()
{
q_create();
return consumer_create();
}

canonical_decompiled_code:
int func10()
{
func0();
return func1();
}

original_code:
void dsp_start() {
    q_create();
    consumer_create();
}


decompiled_code:
void dsp_shutdown()
{
consumer_destroy();
q_destroy();
}

canonical_decompiled_code:
void func11()
{
func5();
func4();
}


decompiled_code:
// attributes: thunk
int __fastcall dsp_dispatch(__int64 a1)
{
return q_push(a1);
}

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

original_code:
void dsp_dispatch(struct raw_event* event) {
    q_push(event);
}

canonical_original_code:
void dsp_dispatch(struct raw_event *event) {
    q_push(event);
}


original_code:
struct raw_event* lst_parse(char* msg) {
    int i = 0, is_last_parameter = 0;
    size_t msg_len;
    struct raw_event* raw = evt_raw_create();
    char* token, *token_end = ((void *)0);
    if (msg != ((void *)0) && (msg_len = strlen(msg)) > 0) {
        if ((raw->__buffer = malloc((msg_len + 1) * sizeof(char))) == 0) {
            perror("Out of memory (parse)");
            exit(1);
        }
        memset(raw->__buffer, '\0', msg_len + 1);
        strncpy(raw->__buffer, msg, msg_len);
        token = strtok_r(raw->__buffer, " ", &token_end);
        while(token != ((void *)0))
        {
            if (raw->type == ((void *)0)) {
                if (token[0] == ':') {
                    raw->prefix = token + 1;
                } else {
                    raw->type = token;
                }
            } else {
                if (is_last_parameter == 0 && token[0] == ':') {
                    raw->params[i] = token + 1;
                    is_last_parameter = 1;
                } else {
                    if (is_last_parameter == 0) {
                        raw->params[i++] = token;
                    } else {
                        sprintf(raw->params[i], "%s %s", raw->params[i], token);
                    }
                }
            }
            token = strtok_r(((void *)0), " ", &token_end);
        }
        raw->num_params = (is_last_parameter == 0)? i : i + 1;
    }
    return raw;
}

canonical_original_code:
struct raw_event *lst_parse(char *msg) {
    int i = 0; int is_last_parameter = 0;
    unsigned long msg_len;
    struct raw_event *raw = evt_raw_create();
    char *token; char *token_end = ((void *)0);
    if (msg != ((void *)0) && (msg_len = strlen(msg)) > 0) {
        if ((raw->__buffer = malloc((msg_len + 1) * sizeof(char))) == 0) {
            perror("Out of memory (parse)");
            exit(1);
        }
        memset(raw->__buffer, '\0', msg_len + 1);
        strncpy(raw->__buffer, msg, msg_len);
        token = strtok_r(raw->__buffer, " ", &token_end);
        while(token != ((void *)0))
        {
            if (raw->type == ((void *)0)) {
                if (token[0] == ':') {
                    raw->prefix = token + 1;
                } else {
                    raw->type = token;
                }
            } else {
                if (is_last_parameter == 0 && token[0] == ':') {
                    raw->params[i] = token + 1;
                    is_last_parameter = 1;
                } else {
                    if (is_last_parameter == 0) {
                        raw->params[i++] = token;
                    } else {
                        sprintf(raw->params[i], "%s %s", raw->params[i], token);
                    }
                }
            }
            token = strtok_r(((void *)0), " ", &token_end);
        }
        raw->num_params = (is_last_parameter == 0)? i : i + 1;
    }
    return raw;
}

variable_types:
msg
char *

variable_types: i int

variable_types:
token
char *

return_type: struct raw_event { struct timeval { long tv_sec; long tv_usec; } timestamp; char *__buffer; char *type; char *prefix; int num_params; char *params[15]; } *


decompiled_code:
__int64 __fastcall lst_handle(char *src)
{
__int64 v1; // rax

src[strlen(src) - 2] = 0;
v1 = lst_parse(src);
return dsp_dispatch(v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
__int64 v1; // rax

src[strlen(src) - 2] = 0;
v1 = func0(src);
return dsp_dispatch(v1);
}

original_code:
void lst_handle(char* msg) {
    struct raw_event* raw;
    msg[strlen(msg) - 2] = '\0';
    raw = lst_parse(msg);
    dsp_dispatch(raw);
}

canonical_original_code:
void lst_handle(char *msg) {
    struct raw_event *raw;
    msg[strlen(msg) - 2] = '\0';
    raw = lst_parse(msg);
    dsp_dispatch(raw);
}


decompiled_code:
__int64 test_parse_empty_message()
{
__int64 v0; // rax
__int64 v1; // rax

v0 = lst_parse(0LL);
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse_empty_message: prefix should be NULL");
if ( *(_QWORD *)(v0 + 24) )
return mu_fail("test_parse_empty_message: type should be NULL");
if ( !*(_DWORD *)(v0 + 40) )
{
evt_raw_destroy(v0);
v1 = lst_parse((char *)&src);
if ( !*(_QWORD *)(v1 + 32) )
{
if ( !*(_QWORD *)(v1 + 24) )
{
if ( !*(_DWORD *)(v1 + 40) )
return evt_raw_destroy(v1);
return mu_fail("test_parse_empty_message: there should be 0 parameters");
}
return mu_fail("test_parse_empty_message: type should be NULL");
}
return mu_fail("test_parse_empty_message: prefix should be NULL");
}
return mu_fail("test_parse_empty_message: there should be 0 parameters");
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // rax

v0 = func0(0LL);
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse_empty_message: prefix should be NULL");
if ( *(_QWORD *)(v0 + 24) )
return mu_fail("test_parse_empty_message: type should be NULL");
if ( !*(_DWORD *)(v0 + 40) )
{
evt_raw_destroy(v0);
v1 = func0((char *)&src);
if ( !*(_QWORD *)(v1 + 32) )
{
if ( !*(_QWORD *)(v1 + 24) )
{
if ( !*(_DWORD *)(v1 + 40) )
return evt_raw_destroy(v1);
return mu_fail("test_parse_empty_message: there should be 0 parameters");
}
return mu_fail("test_parse_empty_message: type should be NULL");
}
return mu_fail("test_parse_empty_message: prefix should be NULL");
}
return mu_fail("test_parse_empty_message: there should be 0 parameters");
}

original_code:
void test_parse_empty_message() {
    struct raw_event* raw;
    raw = lst_parse(((void *)0));
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_empty_message: prefix should be NULL"); return; } } while (0);
    do { if (!(raw->type == ((void *)0))) { mu_fail("test_parse_empty_message: type should be NULL"); return; } } while (0);
    do { if (!(raw->num_params == 0)) { mu_fail("test_parse_empty_message: there should be 0 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
    raw = lst_parse("");
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_empty_message: prefix should be NULL"); return; } } while (0);
    do { if (!(raw->type == ((void *)0))) { mu_fail("test_parse_empty_message: type should be NULL"); return; } } while (0);
    do { if (!(raw->num_params == 0)) { mu_fail("test_parse_empty_message: there should be 0 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
}

canonical_original_code:
void test_parse_empty_message() {
    struct raw_event *raw;
    raw = lst_parse(((void *)0));
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_empty_message: prefix should be NULL"); return; } } while (0);
    do { if (!(raw->type == ((void *)0))) { mu_fail("test_parse_empty_message: type should be NULL"); return; } } while (0);
    do { if (!(raw->num_params == 0)) { mu_fail("test_parse_empty_message: there should be 0 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
    raw = lst_parse("");
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_empty_message: prefix should be NULL"); return; } } while (0);
    do { if (!(raw->type == ((void *)0))) { mu_fail("test_parse_empty_message: type should be NULL"); return; } } while (0);
    do { if (!(raw->num_params == 0)) { mu_fail("test_parse_empty_message: there should be 0 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
}


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

v0 = lst_parse("TEST This is a message test without prefix");
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse: prefix should be NULL");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse: type should be TEST");
if ( *(_DWORD *)(v0 + 40) == 7 )
return evt_raw_destroy(v0);
return mu_fail("test_parse: there should be 7 parameters");
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax

v0 = func0("TEST This is a message test without prefix");
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse: prefix should be NULL");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse: type should be TEST");
if ( *(_DWORD *)(v0 + 40) == 7 )
return evt_raw_destroy(v0);
return mu_fail("test_parse: there should be 7 parameters");
}

original_code:
void test_parse() {
    struct raw_event* raw;
    raw = lst_parse("TEST This is a message test without prefix");
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse: prefix should be NULL"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse: type should be TEST"); return; } } while (0);
    do { if (!(raw->num_params == 7)) { mu_fail("test_parse: there should be 7 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
}

canonical_original_code:
void test_parse() {
    struct raw_event *raw;
    raw = lst_parse("TEST This is a message test without prefix");
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse: prefix should be NULL"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse: type should be TEST"); return; } } while (0);
    do { if (!(raw->num_params == 7)) { mu_fail("test_parse: there should be 7 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
}


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

v0 = lst_parse(":prefix TEST This is a message test with prefix");
if ( strcmp(*(const char **)(v0 + 32), "prefix") )
return mu_fail("test_parse_with_prefix: prefix should be 'prefix'");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_prefix: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) == 7 )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_prefix: there should be 7 parameters");
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax

v0 = func0(":prefix TEST This is a message test with prefix");
if ( strcmp(*(const char **)(v0 + 32), "prefix") )
return mu_fail("test_parse_with_prefix: prefix should be 'prefix'");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_prefix: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) == 7 )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_prefix: there should be 7 parameters");
}

original_code:
void test_parse_with_prefix() {
    struct raw_event* raw;
    raw = lst_parse(":prefix TEST This is a message test with prefix");
    do { if (!((strcmp(raw->prefix,"prefix") == 0))) { mu_fail("test_parse_with_prefix: prefix should be 'prefix'"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_prefix: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 7)) { mu_fail("test_parse_with_prefix: there should be 7 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
}

canonical_original_code:
void test_parse_with_prefix() {
    struct raw_event *raw;
    raw = lst_parse(":prefix TEST This is a message test with prefix");
    do { if (!((strcmp(raw->prefix,"prefix") == 0))) { mu_fail("test_parse_with_prefix: prefix should be 'prefix'"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_prefix: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 7)) { mu_fail("test_parse_with_prefix: there should be 7 parameters"); return; } } while (0);
    evt_raw_destroy(raw);
}


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

v0 = lst_parse("TEST This is a message test with a :last parameter");
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse_with_last_param: prefix should be NULL");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 8 )
return mu_fail("test_parse_with_last_param: there should be 8 parameters");
if ( !strcmp(*(const char **)(v0 + 104), "last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_last_param: last parameter should be 'last parameter'");
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax

v0 = func0("TEST This is a message test with a :last parameter");
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse_with_last_param: prefix should be NULL");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 8 )
return mu_fail("test_parse_with_last_param: there should be 8 parameters");
if ( !strcmp(*(const char **)(v0 + 104), "last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_last_param: last parameter should be 'last parameter'");
}

original_code:
void test_parse_with_last_param() {
    char* last_param;
    struct raw_event* raw;
    raw = lst_parse("TEST This is a message test with a :last parameter");
    last_param = raw->params[raw->num_params -1];
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_with_last_param: prefix should be NULL"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 8)) { mu_fail("test_parse_with_last_param: there should be 8 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"last parameter") == 0))) { mu_fail("test_parse_with_last_param: last parameter should be 'last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}

canonical_original_code:
void test_parse_with_last_param() {
    char *last_param;
    struct raw_event *raw;
    raw = lst_parse("TEST This is a message test with a :last parameter");
    last_param = raw->params[raw->num_params -1];
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_with_last_param: prefix should be NULL"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 8)) { mu_fail("test_parse_with_last_param: there should be 8 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"last parameter") == 0))) { mu_fail("test_parse_with_last_param: last parameter should be 'last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}


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

v0 = lst_parse(":prefix TEST This is a message test with a :last parameter");
if ( strcmp(*(const char **)(v0 + 32), "prefix") )
return mu_fail("test_parse_with_prefix_and_last_param: prefix should be 'prefix'");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_prefix_and_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 8 )
return mu_fail("test_parse_with_prefix_and_last_param: there should be 8 parameters");
if ( !strcmp(*(const char **)(v0 + 104), "last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_prefix_and_last_param: last parameter should be 'last parameter'");
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rax

v0 = func0(":prefix TEST This is a message test with a :last parameter");
if ( strcmp(*(const char **)(v0 + 32), "prefix") )
return mu_fail("test_parse_with_prefix_and_last_param: prefix should be 'prefix'");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_prefix_and_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 8 )
return mu_fail("test_parse_with_prefix_and_last_param: there should be 8 parameters");
if ( !strcmp(*(const char **)(v0 + 104), "last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_prefix_and_last_param: last parameter should be 'last parameter'");
}

original_code:
void test_parse_with_prefix_and_last_param() {
    char* last_param;
    struct raw_event* raw;
    raw = lst_parse(":prefix TEST This is a message test with a :last parameter");
    last_param = raw->params[raw->num_params - 1];
    do { if (!((strcmp(raw->prefix,"prefix") == 0))) { mu_fail("test_parse_with_prefix_and_last_param: prefix should be 'prefix'"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_prefix_and_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 8)) { mu_fail("test_parse_with_prefix_and_last_param: there should be 8 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"last parameter") == 0))) { mu_fail("test_parse_with_prefix_and_last_param: last parameter should be 'last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}

canonical_original_code:
void test_parse_with_prefix_and_last_param() {
    char *last_param;
    struct raw_event *raw;
    raw = lst_parse(":prefix TEST This is a message test with a :last parameter");
    last_param = raw->params[raw->num_params - 1];
    do { if (!((strcmp(raw->prefix,"prefix") == 0))) { mu_fail("test_parse_with_prefix_and_last_param: prefix should be 'prefix'"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_prefix_and_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 8)) { mu_fail("test_parse_with_prefix_and_last_param: there should be 8 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"last parameter") == 0))) { mu_fail("test_parse_with_prefix_and_last_param: last parameter should be 'last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}


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

v0 = lst_parse("TEST :only last parameter");
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse_only_last_param: prefix should be NULL");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_only_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 1 )
return mu_fail("test_parse_only_last_param: there should be 1 parameters");
if ( !strcmp(*(const char **)(v0 + 48), "only last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_only_last_param: last parameter should be 'only last parameter'");
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax

v0 = func0("TEST :only last parameter");
if ( *(_QWORD *)(v0 + 32) )
return mu_fail("test_parse_only_last_param: prefix should be NULL");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_only_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 1 )
return mu_fail("test_parse_only_last_param: there should be 1 parameters");
if ( !strcmp(*(const char **)(v0 + 48), "only last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_only_last_param: last parameter should be 'only last parameter'");
}

original_code:
void test_parse_only_last_param() {
    char* last_param;
    struct raw_event* raw;
    raw = lst_parse("TEST :only last parameter");
    last_param = raw->params[raw->num_params -1];
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_only_last_param: prefix should be NULL"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_only_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 1)) { mu_fail("test_parse_only_last_param: there should be 1 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"only last parameter") == 0))) { mu_fail("test_parse_only_last_param: last parameter should be 'only last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}

canonical_original_code:
void test_parse_only_last_param() {
    char *last_param;
    struct raw_event *raw;
    raw = lst_parse("TEST :only last parameter");
    last_param = raw->params[raw->num_params -1];
    do { if (!(raw->prefix == ((void *)0))) { mu_fail("test_parse_only_last_param: prefix should be NULL"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_only_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 1)) { mu_fail("test_parse_only_last_param: there should be 1 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"only last parameter") == 0))) { mu_fail("test_parse_only_last_param: last parameter should be 'only last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}


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

v0 = lst_parse(":prefix TEST :only last parameter");
if ( strcmp(*(const char **)(v0 + 32), "prefix") )
return mu_fail("test_parse_with_prefix_only_last_param: prefix should be 'prefix'");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_prefix_only_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 1 )
return mu_fail("test_parse_with_prefix_only_last_param: there should be 1 parameters");
if ( !strcmp(*(const char **)(v0 + 48), "only last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_prefix_only_last_param: last parameter should be 'only last parameter'");
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax

v0 = func0(":prefix TEST :only last parameter");
if ( strcmp(*(const char **)(v0 + 32), "prefix") )
return mu_fail("test_parse_with_prefix_only_last_param: prefix should be 'prefix'");
if ( strcmp(*(const char **)(v0 + 24), "TEST") )
return mu_fail("test_parse_with_prefix_only_last_param: type should be 'TEST'");
if ( *(_DWORD *)(v0 + 40) != 1 )
return mu_fail("test_parse_with_prefix_only_last_param: there should be 1 parameters");
if ( !strcmp(*(const char **)(v0 + 48), "only last parameter") )
return evt_raw_destroy(v0);
return mu_fail("test_parse_with_prefix_only_last_param: last parameter should be 'only last parameter'");
}

original_code:
void test_parse_with_prefix_only_last_param() {
    char* last_param;
    struct raw_event* raw;
    raw = lst_parse(":prefix TEST :only last parameter");
    last_param = raw->params[raw->num_params - 1];
    do { if (!((strcmp(raw->prefix,"prefix") == 0))) { mu_fail("test_parse_with_prefix_only_last_param: prefix should be 'prefix'"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_prefix_only_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 1)) { mu_fail("test_parse_with_prefix_only_last_param: there should be 1 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"only last parameter") == 0))) { mu_fail("test_parse_with_prefix_only_last_param: last parameter should be 'only last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}

canonical_original_code:
void test_parse_with_prefix_only_last_param() {
    char *last_param;
    struct raw_event *raw;
    raw = lst_parse(":prefix TEST :only last parameter");
    last_param = raw->params[raw->num_params - 1];
    do { if (!((strcmp(raw->prefix,"prefix") == 0))) { mu_fail("test_parse_with_prefix_only_last_param: prefix should be 'prefix'"); return; } } while (0);
    do { if (!((strcmp(raw->type,"TEST") == 0))) { mu_fail("test_parse_with_prefix_only_last_param: type should be 'TEST'"); return; } } while (0);
    do { if (!(raw->num_params == 1)) { mu_fail("test_parse_with_prefix_only_last_param: there should be 1 parameters"); return; } } while (0);
    do { if (!((strcmp(last_param,"only last parameter") == 0))) { mu_fail("test_parse_with_prefix_only_last_param: last parameter should be 'only last parameter'"); return; } } while (0);
    evt_raw_destroy(raw);
}


decompiled_code:
__int64 test_listener()
{
__int64 result; // rax

test_parse_empty_message();
++tests_run;
test_parse();
++tests_run;
test_parse_with_prefix();
++tests_run;
test_parse_with_last_param();
++tests_run;
test_parse_with_prefix_and_last_param();
++tests_run;
test_parse_only_last_param();
++tests_run;
result = test_parse_with_prefix_only_last_param();
++tests_run;
return result;
}

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

func2();
++tests_run;
func3();
++tests_run;
func4();
++tests_run;
func5();
++tests_run;
func6();
++tests_run;
func7();
++tests_run;
result = func8();
++tests_run;
return result;
}

original_code:
void test_listener() {
    do { (void)0; test_parse_empty_message(); tests_run++; } while (0);
    do { (void)0; test_parse(); tests_run++; } while (0);
    do { (void)0; test_parse_with_prefix(); tests_run++; } while (0);
    do { (void)0; test_parse_with_last_param(); tests_run++; } while (0);
    do { (void)0; test_parse_with_prefix_and_last_param(); tests_run++; } while (0);
    do { (void)0; test_parse_only_last_param(); tests_run++; } while (0);
    do { (void)0; test_parse_with_prefix_only_last_param(); tests_run++; } while (0);
}


decompiled_code:
__int64 test_is_error()
{
__int64 result; // rax

if ( !(unsigned int)is_error(&unk_1A7) )
return mu_fail("test_is_error: 400 should be a valid error");
if ( !(unsigned int)is_error(&unk_1AB) )
return mu_fail("test_is_error: 427 should be a valid error");
if ( !(unsigned int)is_error(&unk_1AF) )
return mu_fail("test_is_error: 599 should be a valid error");
if ( (unsigned int)is_error(&unk_1B3) )
return mu_fail("test_is_error: 200 should not be a valid error");
if ( (unsigned int)is_error(&unk_1B7) )
return mu_fail("test_is_error: 299 should not be a valid error");
result = is_error(&unk_1BB);
if ( (_DWORD)result )
result = mu_fail("test_is_error: 600 should not be a valid error");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

if ( !(unsigned int)is_error(&unk_1A7) )
return mu_fail("test_is_error: 400 should be a valid error");
if ( !(unsigned int)is_error(&unk_1AB) )
return mu_fail("test_is_error: 427 should be a valid error");
if ( !(unsigned int)is_error(&unk_1AF) )
return mu_fail("test_is_error: 599 should be a valid error");
if ( (unsigned int)is_error(&unk_1B3) )
return mu_fail("test_is_error: 200 should not be a valid error");
if ( (unsigned int)is_error(&unk_1B7) )
return mu_fail("test_is_error: 299 should not be a valid error");
result = is_error(&unk_1BB);
if ( (_DWORD)result )
result = mu_fail("test_is_error: 600 should not be a valid error");
return result;
}

original_code:
void test_is_error() {
    do { if (!(is_error("400"))) { mu_fail("test_is_error: 400 should be a valid error"); return; } } while (0);
    do { if (!(is_error("427"))) { mu_fail("test_is_error: 427 should be a valid error"); return; } } while (0);
    do { if (!(is_error("599"))) { mu_fail("test_is_error: 599 should be a valid error"); return; } } while (0);
    do { if (!(!is_error("200"))) { mu_fail("test_is_error: 200 should not be a valid error"); return; } } while (0);
    do { if (!(!is_error("399"))) { mu_fail("test_is_error: 299 should not be a valid error"); return; } } while (0);
    do { if (!(!is_error("600"))) { mu_fail("test_is_error: 600 should not be a valid error"); return; } } while (0);
}


decompiled_code:
__int64 test_is_numeric_response()
{
__int64 result; // rax

if ( !(unsigned int)is_numeric_response(&unk_1B3) )
return mu_fail("test_is_numeric_response: 200 should be a valid response");
if ( !(unsigned int)is_numeric_response(&unk_1B7) )
return mu_fail("test_is_numeric_response: 399 should be a valid response");
if ( !(unsigned int)is_numeric_response(&unk_1BF) )
return mu_fail("test_is_numeric_response: 250 should be a valid response");
if ( (unsigned int)is_numeric_response(&unk_1C3) )
return mu_fail("test_is_numeric_response: 199 should not be a valid response");
if ( (unsigned int)is_numeric_response(&unk_1A7) )
return mu_fail("test_is_numeric_response: 400 should not be a valid response");
result = is_numeric_response(&unk_1C7);
if ( (_DWORD)result )
result = mu_fail("test_is_numeric_response: 403 should not be a valid response");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

if ( !(unsigned int)is_numeric_response(&unk_1B3) )
return mu_fail("test_is_numeric_response: 200 should be a valid response");
if ( !(unsigned int)is_numeric_response(&unk_1B7) )
return mu_fail("test_is_numeric_response: 399 should be a valid response");
if ( !(unsigned int)is_numeric_response(&unk_1BF) )
return mu_fail("test_is_numeric_response: 250 should be a valid response");
if ( (unsigned int)is_numeric_response(&unk_1C3) )
return mu_fail("test_is_numeric_response: 199 should not be a valid response");
if ( (unsigned int)is_numeric_response(&unk_1A7) )
return mu_fail("test_is_numeric_response: 400 should not be a valid response");
result = is_numeric_response(&unk_1C7);
if ( (_DWORD)result )
result = mu_fail("test_is_numeric_response: 403 should not be a valid response");
return result;
}

original_code:
void test_is_numeric_response() {
    do { if (!(is_numeric_response("200"))) { mu_fail("test_is_numeric_response: 200 should be a valid response"); return; } } while (0);
    do { if (!(is_numeric_response("399"))) { mu_fail("test_is_numeric_response: 399 should be a valid response"); return; } } while (0);
    do { if (!(is_numeric_response("250"))) { mu_fail("test_is_numeric_response: 250 should be a valid response"); return; } } while (0);
    do { if (!(!is_numeric_response("199"))) { mu_fail("test_is_numeric_response: 199 should not be a valid response"); return; } } while (0);
    do { if (!(!is_numeric_response("400"))) { mu_fail("test_is_numeric_response: 400 should not be a valid response"); return; } } while (0);
    do { if (!(!is_numeric_response("403"))) { mu_fail("test_is_numeric_response: 403 should not be a valid response"); return; } } while (0);
}


decompiled_code:
__int64 test_codes()
{
__int64 result; // rax

test_is_error();
++tests_run;
result = test_is_numeric_response();
++tests_run;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

func0();
++tests_run;
result = func1();
++tests_run;
return result;
}

original_code:
void test_codes() {
    do { (void)0; test_is_error(); tests_run++; } while (0);
    do { (void)0; test_is_numeric_response(); tests_run++; } while (0);
}


decompiled_code:
void __fastcall shutdown_handler(int a1, int a2)
{
if ( a1 <= 2 )
{
if ( a1 <= 0 )
return;
LABEL_5:
shutdown(a1, a2);
return;
}
if ( a1 == 15 )
goto LABEL_5;
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
if ( a1 <= 2 )
{
if ( a1 <= 0 )
return;
LABEL_5:
func0(a1, a2);
return;
}
if ( a1 == 15 )
goto LABEL_5;
}

original_code:
void shutdown_handler(int signal) {
    switch (signal) {
        case 1:
        case 15:
        case 2:
            _shutdown();
            break;
        default:
            break;
    }
}

variable_types: signal int


decompiled_code:
// attributes: thunk
__int64 irc_bind_event()
{
return bnd_bind();
}

canonical_decompiled_code:
__int64 func2()
{
return bnd_bind();
}

original_code:
void irc_bind_event(char* event, Callback callback) {
    bnd_bind(event, callback);
}

canonical_original_code:
void irc_bind_event(char *event, void (*callback)()) {
    bnd_bind(event, callback);
}

variable_types:
event
char *

variable_types:
callback
void (*)()


decompiled_code:
// attributes: thunk
__int64 irc_unbind_event()
{
return bnd_unbind();
}

canonical_decompiled_code:
__int64 func3()
{
return bnd_unbind();
}

original_code:
void irc_unbind_event(char* event) {
    bnd_unbind(event);
}

canonical_original_code:
void irc_unbind_event(char *event) {
    bnd_unbind(event);
}


decompiled_code:
__int64 __fastcall irc_bind_command(__int64 a1, __int64 a2)
{
__int128 v3[3]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+30h] [rbp-18h]

v4 = 0;
v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
build_command_key(v3, a1);
return bnd_bind(v3, a2);
}

original_code:
void irc_bind_command(char* command, Callback callback) {
    char key[50];
    memset(key, '\0', 50);
    build_command_key(key, command);
    bnd_bind(key, callback);
}

canonical_original_code:
void irc_bind_command(char *command, void (*callback)()) {
    char key[50];
    memset(key, '\0', 50);
    build_command_key(key, command);
    bnd_bind(key, callback);
}

variable_types:
command
char *

variable_types:
key
char [50]


decompiled_code:
__int64 __fastcall irc_unbind_command(__int64 a1)
{
__int128 v2[3]; // [rsp+0h] [rbp-48h] BYREF
__int16 v3; // [rsp+30h] [rbp-18h]

v3 = 0;
v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
build_command_key(v2, a1);
return bnd_unbind(v2);
}

original_code:
void irc_unbind_command(char* command) {
    char key[50];
    memset(key, '\0', 50);
    build_command_key(key, command);
    bnd_unbind(key);
}

canonical_original_code:
void irc_unbind_command(char *command) {
    char key[50];
    memset(key, '\0', 50);
    build_command_key(key, command);
    bnd_unbind(key);
}


decompiled_code:
// attributes: thunk
__int64 irc_connect()
{
return net_connect();
}

canonical_decompiled_code:
__int64 func6()
{
return net_connect();
}

original_code:
void irc_connect(char* address, char* port) {
    net_connect(address, port);
}

canonical_original_code:
void irc_connect(char *address, char *port) {
    net_connect(address, port);
}

variable_types:
address
char *

variable_types:
port
char *


decompiled_code:
__int64 irc_disconnect()
{
return net_disconnect();
}

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

original_code:
void irc_disconnect() {
    net_disconnect();
}


decompiled_code:
__int64 irc_listen()
{
const char *v0; // rdi
int v1; // esi
__int64 result; // rax
int v3; // eax
_BYTE v4[536]; // [rsp+0h] [rbp-218h] BYREF

_sysv_signal(1, (__sighandler_t)shutdown_handler);
_sysv_signal(15, (__sighandler_t)shutdown_handler);
_sysv_signal(2, (__sighandler_t)shutdown_handler);
v0 = "Starting %s %s...\n Git: %s\n Build: %s\n Platform: %s\n";
v1 = lib_name;
printf(
"Starting %s %s...\n Git: %s\n Build: %s\n Platform: %s\n",
*(const char **)&lib_name,
lib_version,
git_revision,
build_date,
build_platform);
dsp_start();
LABEL_2:
while ( 1 )
{
result = (unsigned int)shutdown_requested;
if ( shutdown_requested )
return result;
while ( 1 )
{
v3 = net_listen();
if ( v3 == 1 )
{
perror("Error listening for messages");
exit(1);
}
if ( v3 == 2 )
break;
if ( v3 )
goto LABEL_2;
net_recv(v4);
v0 = v4;
lst_handle(v4);
result = (unsigned int)shutdown_requested;
if ( shutdown_requested )
return result;
}
shutdown((int)v0, v1);
}
}

canonical_decompiled_code:
__int64 func8()
{
const char *v0; // rdi
int v1; // esi
__int64 result; // rax
int v3; // eax
_BYTE v4[536]; // [rsp+0h] [rbp-218h] BYREF

_sysv_signal(1, (__sighandler_t)shutdown_handler);
_sysv_signal(15, (__sighandler_t)shutdown_handler);
_sysv_signal(2, (__sighandler_t)shutdown_handler);
v0 = "Starting %s %s...\n Git: %s\n Build: %s\n Platform: %s\n";
v1 = lib_name;
printf(
"Starting %s %s...\n Git: %s\n Build: %s\n Platform: %s\n",
*(const char **)&lib_name,
lib_version,
git_revision,
build_date,
build_platform);
dsp_start();
LABEL_2:
while ( 1 )
{
result = (unsigned int)shutdown_requested;
if ( shutdown_requested )
return result;
while ( 1 )
{
v3 = net_listen();
if ( v3 == 1 )
{
perror("Error listening for messages");
exit(1);
}
if ( v3 == 2 )
break;
if ( v3 )
goto LABEL_2;
net_recv(v4);
v0 = v4;
lst_handle(v4);
result = (unsigned int)shutdown_requested;
if ( shutdown_requested )
return result;
}
func0((int)v0, v1);
}
}

original_code:
void irc_listen() {
    enum net_status status;
    char msg[(512 + 1)];
    signal(1, shutdown_handler);
    signal(15, shutdown_handler);
    signal(2, shutdown_handler);
    printf("Starting %s %s...\n  Git: %s\n  Build: %s\n  Platform: %s\n",
        lib_name, lib_version, git_revision, build_date, build_platform);
    dsp_start();
    while (shutdown_requested == 0) {
        status = net_listen();
        switch(status) {
            case NET_ERROR:
                perror("Error listening for messages");
                exit(1);
                break;
            case NET_CLOSE:
                (void)0;
                _shutdown();
                break;
            case NET_READY:
                net_recv(msg);
                lst_handle(msg);
                break;
            case NET_TIMEOUT:
                (void)0;
                break;
            default:
                break;
        }
    }
    (void)0;
}

canonical_original_code:
void irc_listen() {
    enum net_status status;
    char msg[-1];
    signal(1, shutdown_handler);
    signal(15, shutdown_handler);
    signal(2, shutdown_handler);
    printf("Starting %s %s...\n  Git: %s\n  Build: %s\n  Platform: %s\n",
        lib_name, lib_version, git_revision, build_date, build_platform);
    dsp_start();
    while (shutdown_requested == 0) {
        status = net_listen();
        switch(status) {
            case NET_ERROR:
                perror("Error listening for messages");
                exit(1);
                break;
            case NET_CLOSE:
                (void)0;
                _shutdown();
                break;
            case NET_READY:
                net_recv(msg);
                lst_handle(msg);
                break;
            case NET_TIMEOUT:
                (void)0;
                break;
            default:
                break;
        }
    }
    (void)0;
}

variable_types:
msg
char [-1]


decompiled_code:
__int64 __fastcall irc_nick(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "NICK", a1);
return net_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "NICK", a1);
return net_send(v2);
}

original_code:
void irc_nick(char* nick) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s", "NICK", nick);
    net_send(msg);
}

canonical_original_code:
void irc_nick(char *nick) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s", "NICK", nick);
    net_send(msg);
}

variable_types:
nick
char *


decompiled_code:
__int64 __fastcall irc_user(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s hostname server :%s", "USER", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s hostname server :%s", "USER", a1, a2);
return net_send(v3);
}

original_code:
void irc_user(char* user_name, char* real_name) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s hostname server :%s", "USER", user_name, real_name);
    net_send(msg);
}

canonical_original_code:
void irc_user(char *user_name, char *real_name) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s hostname server :%s", "USER", user_name, real_name);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_login(const char *a1, const char *a2, const char *a3)
{
irc_nick(a1);
return irc_user(a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, const char *a2, const char *a3)
{
func9(a1);
return func10(a2, a3);
}

original_code:
void irc_login(char* nick, char* user_name, char* real_name) {
    irc_nick(nick);
    irc_user(user_name, real_name);
}

canonical_original_code:
void irc_login(char *nick, char *user_name, char *real_name) {
    irc_nick(nick);
    irc_user(user_name, real_name);
}


decompiled_code:
__int64 __fastcall irc_quit(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s :%s", "QUIT", a1);
return net_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s :%s", "QUIT", a1);
return net_send(v2);
}

original_code:
void irc_quit(char* message) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s :%s", "QUIT", message);
    net_send(msg);
}

canonical_original_code:
void irc_quit(char *message) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s :%s", "QUIT", message);
    net_send(msg);
}

variable_types:
message
char *


decompiled_code:
__int64 __fastcall irc_join(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "JOIN", a1);
return net_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "JOIN", a1);
return net_send(v2);
}

original_code:
void irc_join(char* channel) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s", "JOIN", channel);
    net_send(msg);
}

canonical_original_code:
void irc_join(char *channel) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s", "JOIN", channel);
    net_send(msg);
}

variable_types:
channel
char *


decompiled_code:
__int64 __fastcall irc_join_pass(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s %s", "JOIN", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s %s", "JOIN", a1, a2);
return net_send(v3);
}

original_code:
void irc_join_pass(char* channel, char* pass) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s %s", "JOIN", channel, pass);
    net_send(msg);
}

canonical_original_code:
void irc_join_pass(char *channel, char *pass) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s %s", "JOIN", channel, pass);
    net_send(msg);
}

variable_types:
pass
char *


decompiled_code:
__int64 __fastcall irc_part(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "PART", a1);
return net_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "PART", a1);
return net_send(v2);
}

original_code:
void irc_part(char* channel) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s", "PART", channel);
    net_send(msg);
}

canonical_original_code:
void irc_part(char *channel) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s", "PART", channel);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_topic(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s :%s", "TOPIC", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func16(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s :%s", "TOPIC", a1, a2);
return net_send(v3);
}

original_code:
void irc_topic(char* channel, char* topic) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s :%s", "TOPIC", channel, topic);
    net_send(msg);
}

canonical_original_code:
void irc_topic(char *channel, char *topic) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s :%s", "TOPIC", channel, topic);
    net_send(msg);
}

variable_types:
topic
char *


decompiled_code:
__int64 __fastcall irc_names(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "NAMES", a1);
return net_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "NAMES", a1);
return net_send(v2);
}

original_code:
void irc_names(char* channel) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s", "NAMES", channel);
    net_send(msg);
}

canonical_original_code:
void irc_names(char *channel) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s", "NAMES", channel);
    net_send(msg);
}


decompiled_code:
__int64 irc_list()
{
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v1, 0x1FDuLL, "%s", "LIST");
return net_send(v1);
}

canonical_decompiled_code:
__int64 func18()
{
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v1, 0x1FDuLL, "%s", "LIST");
return net_send(v1);
}

original_code:
void irc_list() {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s", "LIST");
    net_send(msg);
}

canonical_original_code:
void irc_list() {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s", "LIST");
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_invite(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s %s", "INVITE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func19(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s %s", "INVITE", a1, a2);
return net_send(v3);
}

original_code:
void irc_invite(char* nick, char* channel) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s %s", "INVITE", nick, channel);
    net_send(msg);
}

canonical_original_code:
void irc_invite(char *nick, char *channel) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s %s", "INVITE", nick, channel);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_message(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s :%s", "PRIVMSG", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func20(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s :%s", "PRIVMSG", a1, a2);
return net_send(v3);
}

original_code:
void irc_message(char* target, char* message) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s :%s", "PRIVMSG", target, message);
    net_send(msg);
}

canonical_original_code:
void irc_message(char *target, char *message) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s :%s", "PRIVMSG", target, message);
    net_send(msg);
}

variable_types:
target
char *


decompiled_code:
__int64 __fastcall irc_op(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +o %s", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func21(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +o %s", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_op(char* channel, char* nick) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +o %s", "MODE", channel, nick);
    net_send(msg);
}

canonical_original_code:
void irc_op(char *channel, char *nick) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +o %s", "MODE", channel, nick);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_deop(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -o %s", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func22(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -o %s", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_deop(char* channel, char* nick) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s -o %s", "MODE", channel, nick);
    net_send(msg);
}

canonical_original_code:
void irc_deop(char *channel, char *nick) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s -o %s", "MODE", channel, nick);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_voice(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +v %s", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func23(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +v %s", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_voice(char* channel, char* nick) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +v %s", "MODE", channel, nick);
    net_send(msg);
}

canonical_original_code:
void irc_voice(char *channel, char *nick) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +v %s", "MODE", channel, nick);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_devoice(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -v %s", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func24(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -v %s", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_devoice(char* channel, char* nick) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s -v %s", "MODE", channel, nick);
    net_send(msg);
}

canonical_original_code:
void irc_devoice(char *channel, char *nick) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s -v %s", "MODE", channel, nick);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_kick(const char *a1, const char *a2, const char *a3)
{
char s[520]; // [rsp+8h] [rbp-208h] BYREF

snprintf(s, 0x1FDuLL, "%s %s %s :%s", "KICK", a1, a2, a3);
return net_send(s);
}

canonical_decompiled_code:
__int64 __fastcall func25(const char *a1, const char *a2, const char *a3)
{
char s[520]; // [rsp+8h] [rbp-208h] BYREF

snprintf(s, 0x1FDuLL, "%s %s %s :%s", "KICK", a1, a2, a3);
return net_send(s);
}

original_code:
void irc_kick(char* channel, char* nick, char* message) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s %s :%s", "KICK", channel, nick, message);
    net_send(msg);
}

canonical_original_code:
void irc_kick(char *channel, char *nick, char *message) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s %s :%s", "KICK", channel, nick, message);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_ban(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +b %s", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func26(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +b %s", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_ban(char* channel, char* mask) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +b %s", "MODE", channel, mask);
    net_send(msg);
}

canonical_original_code:
void irc_ban(char *channel, char *mask) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +b %s", "MODE", channel, mask);
    net_send(msg);
}

variable_types:
mask
char *


decompiled_code:
__int64 __fastcall irc_unban(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -b %s", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func27(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -b %s", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_unban(char* channel, char* mask) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s -b %s", "MODE", channel, mask);
    net_send(msg);
}

canonical_original_code:
void irc_unban(char *channel, char *mask) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s -b %s", "MODE", channel, mask);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_ban_list(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s +b", "MODE", a1);
return net_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func28(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s +b", "MODE", a1);
return net_send(v2);
}

original_code:
void irc_ban_list(char* channel) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +b", "MODE", channel);
    net_send(msg);
}

canonical_original_code:
void irc_ban_list(char *channel) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +b", "MODE", channel);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_limit(const char *a1, unsigned int a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +l %d", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func29(const char *a1, unsigned int a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +l %d", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_limit(char* channel, int limit) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +l %d", "MODE", channel, limit);
    net_send(msg);
}

canonical_original_code:
void irc_limit(char *channel, int limit) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +l %d", "MODE", channel, limit);
    net_send(msg);
}

variable_types: limit int


decompiled_code:
__int64 __fastcall irc_channel_key(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +k %s", "MODE", a1, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func30(const char *a1, const char *a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +k %s", "MODE", a1, a2);
return net_send(v3);
}

original_code:
void irc_channel_key(char* channel, char* key) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +k %s", "MODE", channel, key);
    net_send(msg);
}

canonical_original_code:
void irc_channel_key(char *channel, char *key) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +k %s", "MODE", channel, key);
    net_send(msg);
}

variable_types:
key
char *


decompiled_code:
__int64 __fastcall irc_channel_set(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +", "MODE", a1);
append_channel_flags(v3, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func31(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +", "MODE", a1);
append_channel_flags(v3, a2);
return net_send(v3);
}

original_code:
void irc_channel_set(char* channel, unsigned short int flags) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +", "MODE", channel);
    append_channel_flags(msg, flags);
    net_send(msg);
}

canonical_original_code:
void irc_channel_set(char *channel, unsigned short flags) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +", "MODE", channel);
    append_channel_flags(msg, flags);
    net_send(msg);
}

variable_types:
flags
unsigned short


decompiled_code:
__int64 __fastcall irc_channel_unset(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -", "MODE", a1);
append_channel_flags(v3, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func32(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -", "MODE", a1);
append_channel_flags(v3, a2);
return net_send(v3);
}

original_code:
void irc_channel_unset(char* channel, unsigned short int flags) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s -", "MODE", channel);
    append_channel_flags(msg, flags);
    net_send(msg);
}

canonical_original_code:
void irc_channel_unset(char *channel, unsigned short flags) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s -", "MODE", channel);
    append_channel_flags(msg, flags);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_user_set(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +", "MODE", a1);
append_user_flags(v3, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func33(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s +", "MODE", a1);
append_user_flags(v3, a2);
return net_send(v3);
}

original_code:
void irc_user_set(char* user, unsigned short int flags) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s +", "MODE", user);
    append_user_flags(msg, flags);
    net_send(msg);
}

canonical_original_code:
void irc_user_set(char *user, unsigned short flags) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s +", "MODE", user);
    append_user_flags(msg, flags);
    net_send(msg);
}

variable_types:
user
char *


decompiled_code:
__int64 __fastcall irc_user_unset(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -", "MODE", a1);
append_user_flags(v3, a2);
return net_send(v3);
}

canonical_decompiled_code:
__int64 __fastcall func34(const char *a1, unsigned __int16 a2)
{
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v3, 0x1FDuLL, "%s %s -", "MODE", a1);
append_user_flags(v3, a2);
return net_send(v3);
}

original_code:
void irc_user_unset(char* user, unsigned short int flags) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s -", "MODE", user);
    append_user_flags(msg, flags);
    net_send(msg);
}

canonical_original_code:
void irc_user_unset(char *user, unsigned short flags) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s -", "MODE", user);
    append_user_flags(msg, flags);
    net_send(msg);
}


decompiled_code:
__int64 __fastcall irc_pong(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "PONG", a1);
return net_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func35(const char *a1)
{
char v2[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v2, 0x1FDuLL, "%s %s", "PONG", a1);
return net_send(v2);
}

original_code:
void irc_pong(char* server) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), "%s %s", "PONG", server);
    net_send(msg);
}

canonical_original_code:
void irc_pong(char *server) {
    char msg[-1];
    snprintf(msg, (512 - 3), "%s %s", "PONG", server);
    net_send(msg);
}

variable_types:
server
char *


decompiled_code:
__int64 __fastcall irc_raw(const char *a1, const char *a2, const char *a3)
{
char v4[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v4, 0x1FDuLL, ":%s %s %s", a1, a2, a3);
return net_send(v4);
}

canonical_decompiled_code:
__int64 __fastcall func36(const char *a1, const char *a2, const char *a3)
{
char v4[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v4, 0x1FDuLL, ":%s %s %s", a1, a2, a3);
return net_send(v4);
}

original_code:
void irc_raw(char* prefix, char* type, char* message) {
    char msg[(512 - 3)];
    snprintf(msg, (512 - 3), ":%s %s %s", prefix, type, message);
    net_send(msg);
}

canonical_original_code:
void irc_raw(char *prefix, char *type, char *message) {
    char msg[-1];
    snprintf(msg, (512 - 3), ":%s %s %s", prefix, type, message);
    net_send(msg);
}

variable_types:
prefix
char *

variable_types:
type
char *


decompiled_code:
__int64 __fastcall give_op(__int64 a1)
{
return irc_op(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return irc_op(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

original_code:
void give_op(MessageEvent* event) {
    irc_op(event->to, event->user.nick);
}

canonical_original_code:
void give_op(struct MessageEvent *event) {
    irc_op(event->to, event->user.nick);
}

variable_types: struct MessageEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; struct UserInfo { char *nick; char *user; char *server; } user; int is_channel; char *to; char *message; } *

user_defined_types: struct MessageEvent { struct timeval *timestamp; struct UserInfo user; int is_channel; char *to; char *message; }


decompiled_code:
__int64 __fastcall take_op(__int64 a1)
{
return irc_deop(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return irc_deop(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

original_code:
void take_op(MessageEvent* event) {
    irc_deop(event->to, event->user.nick);
}

canonical_original_code:
void take_op(struct MessageEvent *event) {
    irc_deop(event->to, event->user.nick);
}

user_defined_types: struct UserInfo { char *nick; char *user; char *server; }


decompiled_code:
__int64 __fastcall give_voice(__int64 a1)
{
return irc_voice(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return irc_voice(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

original_code:
void give_voice(MessageEvent* event) {
    irc_voice(event->to, event->user.nick);
}

canonical_original_code:
void give_voice(struct MessageEvent *event) {
    irc_voice(event->to, event->user.nick);
}


decompiled_code:
__int64 __fastcall take_voice(__int64 a1)
{
return irc_devoice(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return irc_devoice(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

original_code:
void take_voice(MessageEvent* event) {
    irc_devoice(event->to, event->user.nick);
}

canonical_original_code:
void take_voice(struct MessageEvent *event) {
    irc_devoice(event->to, event->user.nick);
}


upper

decompiled_code:
void __fastcall upper(char *s)
{
size_t i; // rbx

if ( s )
{
for ( i = 0LL; i < strlen(s); ++i )
s[i] = (*_ctype_toupper_loc())[s[i]];
}
}

canonical_decompiled_code:
void __fastcall func0(char *s)
{
size_t i; // rbx

if ( s )
{
for ( i = 0LL; i < strlen(s); ++i )
s[i] = (*_ctype_toupper_loc())[s[i]];
}
}

original_code:
void upper(char* str) {
    int i;
    if (str != ((void *)0)) {
        for (i = 0; i < strlen(str); i++) {
            str[i] = toupper(str[i]);
        }
    }
}

canonical_original_code:
void upper(char *str) {
    int i;
    if (str != ((void *)0)) {
        for (i = 0; i < strlen(str); i++) {
            str[i] = toupper(str[i]);
        }
    }
}

variable_types:
str
char *

variable_types: i int


lower

decompiled_code:
void __fastcall lower(char *s)
{
size_t i; // rbx

if ( s )
{
for ( i = 0LL; i < strlen(s); ++i )
s[i] = (*_ctype_tolower_loc())[s[i]];
}
}

canonical_decompiled_code:
void __fastcall func1(char *s)
{
size_t i; // rbx

if ( s )
{
for ( i = 0LL; i < strlen(s); ++i )
s[i] = (*_ctype_tolower_loc())[s[i]];
}
}

original_code:
void lower(char* str) {
    int i;
    if (str != ((void *)0)) {
        for (i = 0; i < strlen(str); i++) {
            str[i] = tolower(str[i]);
        }
    }
}

canonical_original_code:
void lower(char *str) {
    int i;
    if (str != ((void *)0)) {
        for (i = 0; i < strlen(str); i++) {
            str[i] = tolower(str[i]);
        }
    }
}


decompiled_code:
int __fastcall build_command_key(char *a1, const char *a2)
{
return snprintf(a1, 0x32uLL, "%s#%s", "PRIVMSG", a2);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, const char *a2)
{
return snprintf(a1, 0x32uLL, "%s#%s", "PRIVMSG", a2);
}

original_code:
void build_command_key(char* key, char* command) {
    snprintf(key, 50, "%s#%s", "PRIVMSG", command);
}

canonical_original_code:
void build_command_key(char *key, char *command) {
    snprintf(key, 50, "%s#%s", "PRIVMSG", command);
}

variable_types:
command
char *


original_code:
void append_channel_flags(char* str, unsigned short int flags) {
    if (flags & CH_PRIVATE) strcat(str, "p");
    if (flags & CH_SECRET) strcat(str, "s");
    if (flags & CH_INVITEONLY) strcat(str, "i");
    if (flags & CH_TOPICLOCK) strcat(str, "t");
    if (flags & CH_NOEXTMSGS) strcat(str, "n");
    if (flags & CH_MODERATED) strcat(str, "m");
}

canonical_original_code:
void append_channel_flags(char *str, unsigned short flags) {
    if (flags & CH_PRIVATE) strcat(str, "p");
    if (flags & CH_SECRET) strcat(str, "s");
    if (flags & CH_INVITEONLY) strcat(str, "i");
    if (flags & CH_TOPICLOCK) strcat(str, "t");
    if (flags & CH_NOEXTMSGS) strcat(str, "n");
    if (flags & CH_MODERATED) strcat(str, "m");
}


decompiled_code:
void __fastcall append_user_flags(char *s, char a2)
{
if ( (a2 & 1) != 0 )
{
*(_WORD *)&s[strlen(s)] = 105;
if ( (a2 & 2) == 0 )
{
LABEL_3:
if ( (a2 & 4) == 0 )
return;
LABEL_7:
*(_WORD *)&s[strlen(s)] = 111;
return;
}
}
else if ( (a2 & 2) == 0 )
{
goto LABEL_3;
}
*(_WORD *)&s[strlen(s)] = 119;
if ( (a2 & 4) != 0 )
goto LABEL_7;
}

original_code:
void append_user_flags(char* str, unsigned short int flags) {
    if (flags & USR_INVISIBLE) strcat(str, "i");
    if (flags & USR_WALLOPS) strcat(str, "w");
    if (flags & USR_OPERATOR) strcat(str, "o");
}

canonical_original_code:
void append_user_flags(char *str, unsigned short flags) {
    if (flags & USR_INVISIBLE) strcat(str, "i");
    if (flags & USR_WALLOPS) strcat(str, "w");
    if (flags & USR_OPERATOR) strcat(str, "o");
}


decompiled_code:
_BOOL8 __fastcall is_error(const char *a1)
{
return (unsigned int)(atoi(a1) - 400) <= 0xC7;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
return (unsigned int)(atoi(a1) - 400) <= 0xC7;
}

original_code:
int is_error(char* code) {
    int num_code = atoi(code);
    return num_code >= 400 && num_code <= 599;
}

canonical_original_code:
int is_error(char *code) {
    int num_code = atoi(code);
    return num_code >= 400 && num_code <= 599;
}

variable_types:
code
char *

return_type: int


decompiled_code:
_BOOL8 __fastcall is_numeric_response(const char *a1)
{
return (unsigned int)(atoi(a1) - 200) <= 0xC7;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
return (unsigned int)(atoi(a1) - 200) <= 0xC7;
}

original_code:
int is_numeric_response(char* code) {
    int num_code = atoi(code);
    return num_code >= 200 && num_code <= 399;
}

canonical_original_code:
int is_numeric_response(char *code) {
    int num_code = atoi(code);
    return num_code >= 200 && num_code <= 399;
}


decompiled_code:
void __fastcall __noreturn on_nick_in_use(__int64 a1)
{
printf("Nick %s is already in use\n", *(const char **)(a1 + 32));
irc_quit("Bye");
irc_disconnect();
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(__int64 a1)
{
printf("Nick %s is already in use\n", *(const char **)(a1 + 32));
irc_quit("Bye");
irc_disconnect();
exit(1);
}

original_code:
void on_nick_in_use(ErrorEvent* event) {
    printf("Nick %s is already in use\n", event->params[1]);
    irc_quit("Bye");
    irc_disconnect();
    exit(1);
}

canonical_original_code:
void on_nick_in_use(struct ErrorEvent *event) {
    printf("Nick %s is already in use\n", event->params[1]);
    irc_quit("Bye");
    irc_disconnect();
    exit(1);
}

variable_types: struct ErrorEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; char *code; int num_params; char *params[15]; char *message; } *

user_defined_types: struct ErrorEvent { struct timeval *timestamp; char *code; int num_params; char *params[15]; char *message; }


decompiled_code:
int __fastcall on_error(__int64 a1)
{
return printf("Incoming error message: [%s] %s\n", *(const char **)(a1 + 8), *(const char **)(a1 + 144));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
return printf("Incoming error message: [%s] %s\n", *(const char **)(a1 + 8), *(const char **)(a1 + 144));
}

original_code:
void on_error(ErrorEvent* event) {
    printf("Incoming error message: [%s] %s\n", event->code, event->message);
}

canonical_original_code:
void on_error(struct ErrorEvent *event) {
    printf("Incoming error message: [%s] %s\n", event->code, event->message);
}


decompiled_code:
int __fastcall on_message(__int64 a1)
{
return printf("Incoming message: [%s] %s\n", *(const char **)(a1 + 8), *(const char **)(a1 + 144));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
return printf("Incoming message: [%s] %s\n", *(const char **)(a1 + 8), *(const char **)(a1 + 144));
}

original_code:
void on_message(GenericEvent* event) {
    printf("Incoming message: [%s] %s\n", event->code, event->message);
}

canonical_original_code:
void on_message(struct GenericEvent *event) {
    printf("Incoming message: [%s] %s\n", event->code, event->message);
}

variable_types: struct GenericEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; char *code; int num_params; char *params[15]; char *message; } *

user_defined_types: struct GenericEvent { struct timeval *timestamp; char *code; int num_params; char *params[15]; char *message; }


decompiled_code:
char __fastcall on_join(__int64 a1)
{
const char *v1; // r8
bool v2; // zf
char result; // al
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = *(const char **)(a1 + 8);
v2 = strcmp(v1, "circus-bot") == 0;
result = !v2;
if ( !v2 )
{
snprintf(v4, 0x1EuLL, "Welcome %s", v1);
result = irc_message(*(_QWORD *)(a1 + 32), v4);
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(__int64 a1)
{
const char *v1; // r8
bool v2; // zf
char result; // al
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = *(const char **)(a1 + 8);
v2 = strcmp(v1, "circus-bot") == 0;
result = !v2;
if ( !v2 )
{
snprintf(v4, 0x1EuLL, "Welcome %s", v1);
result = irc_message(*(_QWORD *)(a1 + 32), v4);
}
return result;
}

original_code:
void on_join(JoinEvent* event) {
    char msg[30];
    if ((strcmp(event->user.nick,"circus-bot") != 0)) {
        snprintf(msg, 30, "Welcome %s", event->user.nick);
        irc_message(event->channel, msg);
    }
}

canonical_original_code:
void on_join(struct JoinEvent *event) {
    char msg[30];
    if ((strcmp(event->user.nick,"circus-bot") != 0)) {
        snprintf(msg, 30, "Welcome %s", event->user.nick);
        irc_message(event->channel, msg);
    }
}

variable_types: struct JoinEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; struct UserInfo { char *nick; char *user; char *server; } user; char *channel; } *

variable_types:
msg
char [30]

user_defined_types: struct JoinEvent { struct timeval *timestamp; struct UserInfo user; char *channel; }


decompiled_code:
int mu_results()
{
int result; // eax
const char **v1; // rbx

printf(" Tests run: %d\n", (unsigned int)tests_run);
if ( !test_fails )
return puts(" Test result: Ok");
result = printf(" Test result: %d Failures\n", (unsigned int)test_fails);
v1 = (const char **)fails;
if ( fails )
{
do
{
result = printf(" %s\n", v1[1]);
v1 = (const char **)*v1;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
const char **v1; // rbx

printf(" Tests run: %d\n", (unsigned int)tests_run);
if ( !test_fails )
return puts(" Test result: Ok");
result = printf(" Test result: %d Failures\n", (unsigned int)test_fails);
v1 = (const char **)fails;
if ( fails )
{
do
{
result = printf(" %s\n", v1[1]);
v1 = (const char **)*v1;
}
while ( v1 );
}
return result;
}

original_code:
void mu_results() {
    struct failure *f;
    printf("  Tests run: %d\n", tests_run);
    if (test_fails == 0) {
        printf("  Test result: Ok\n");
    } else {
        printf("  Test result: %d Failures\n", test_fails);
        for (f = fails; f; f = f->next) {
            printf("    %s\n", f->msg);
        }
    }
}

variable_types: struct failure { struct failure *next; char *msg; } *