crcon

repo: naclander/crcon

decompiled_code:
int __fastcall crcon(char *src, char *haystack, char *cp, __int16 a4, const char *a5, unsigned __int16 a6)
{
int v9; // er13
size_t v10; // rax
size_t v11; // r15
void *v12; // rbx
char v13; // r12
int result; // eax
__int16 v15; // r12
char *v16; // rax
char *v17; // rdx
struct timespec v18; // [rsp+0h] [rbp-258h] BYREF
char s; // [rsp+10h] [rbp-248h] BYREF
char dest; // [rsp+11h] [rbp-247h] BYREF
char v21; // [rsp+12h] [rbp-246h]
char v22; // [rsp+13h] [rbp-245h]
char v23; // [rsp+14h] [rbp-244h] BYREF
char v24[507]; // [rsp+15h] [rbp-243h] BYREF
struct sockaddr inp[4]; // [rsp+210h] [rbp-48h] BYREF

v18.tv_sec = 0LL;
v18.tv_nsec = 1000000LL;
if ( !strcmp(a5, "moh") )
{
s = -1;
dest = -1;
v21 = -1;
v22 = -1;
v23 = 2;
strcpy(v24, src);
}
else
{
s = -1;
if ( !strcmp(a5, "bf") )
{
strcpy(&dest, src);
}
else
{
dest = -1;
v21 = -1;
v22 = -1;
strcpy(&v23, src);
}
}
v9 = socket(2, 2, 0);
if ( v9 <= 0 )
{
perror("socket");
result = -1;
}
else
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
*(_WORD *)inp[0].sa_data = _bswap_16(a4);
if ( inet_aton(cp, (struct in_addr *)&inp[0].sa_data[2]) )
{
if ( connect(v9, inp, 0x10u) )
{
perror("connect");
result = -1;
}
else
{
fcntl(v9, 4, 2048LL);
v10 = strlen(&s);
if ( send(v9, &s, v10, 0) <= 0 )
{
perror("send");
result = -1;
}
else
{
v11 = a6;
memset(haystack, 0, a6);
v12 = malloc(a6);
memset(v12, 0, a6);
v13 = 1;
while ( 1 )
{
while ( read(v9, v12, (__int16)a6 - 1) > 0 )
{
v15 = strlen((const char *)v12);
strcat(haystack, (const char *)v12);
memset(v12, 0, v11);
a6 -= v15;
v13 = 1;
}
if ( nanosleep(&v18, 0LL) )
break;
if ( (unsigned __int8)++v13 > 9u )
goto LABEL_21;
}
perror("nanosleep");
LABEL_21:
free(v12);
if ( (unsigned __int8)v13 > 1u )
{
while ( 1 )
{
v16 = strstr(haystack, "print\n");
if ( !v16 )
break;
v17 = v16 + 6;
do
*v16++ = 32;
while ( v17 != v16 );
}
}
result = close(v9);
if ( result )
{
perror("close");
result = -1;
}
}
}
}
else
{
perror("inet_aton");
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *src, char *haystack, char *cp, __int16 a4, const char *a5, unsigned __int16 a6)
{
int v9; // er13
size_t v10; // rax
size_t v11; // r15
void *v12; // rbx
char v13; // r12
int result; // eax
__int16 v15; // r12
char *v16; // rax
char *v17; // rdx
struct timespec v18; // [rsp+0h] [rbp-258h] BYREF
char s; // [rsp+10h] [rbp-248h] BYREF
char dest; // [rsp+11h] [rbp-247h] BYREF
char v21; // [rsp+12h] [rbp-246h]
char v22; // [rsp+13h] [rbp-245h]
char v23; // [rsp+14h] [rbp-244h] BYREF
char v24[507]; // [rsp+15h] [rbp-243h] BYREF
struct sockaddr inp[4]; // [rsp+210h] [rbp-48h] BYREF

v18.tv_sec = 0LL;
v18.tv_nsec = 1000000LL;
if ( !strcmp(a5, "moh") )
{
s = -1;
dest = -1;
v21 = -1;
v22 = -1;
v23 = 2;
strcpy(v24, src);
}
else
{
s = -1;
if ( !strcmp(a5, "bf") )
{
strcpy(&dest, src);
}
else
{
dest = -1;
v21 = -1;
v22 = -1;
strcpy(&v23, src);
}
}
v9 = socket(2, 2, 0);
if ( v9 <= 0 )
{
perror("socket");
result = -1;
}
else
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
*(_WORD *)inp[0].sa_data = func0(a4);
if ( inet_aton(cp, (struct in_addr *)&inp[0].sa_data[2]) )
{
if ( connect(v9, inp, 0x10u) )
{
perror("connect");
result = -1;
}
else
{
fcntl(v9, 4, 2048LL);
v10 = strlen(&s);
if ( send(v9, &s, v10, 0) <= 0 )
{
perror("send");
result = -1;
}
else
{
v11 = a6;
memset(haystack, 0, a6);
v12 = malloc(a6);
memset(v12, 0, a6);
v13 = 1;
while ( 1 )
{
while ( read(v9, v12, (__int16)a6 - 1) > 0 )
{
v15 = strlen((const char *)v12);
strcat(haystack, (const char *)v12);
memset(v12, 0, v11);
a6 -= v15;
v13 = 1;
}
if ( nanosleep(&v18, 0LL) )
break;
if ( (unsigned __int8)++v13 > 9u )
goto LABEL_21;
}
perror("nanosleep");
LABEL_21:
free(v12);
if ( (unsigned __int8)v13 > 1u )
{
while ( 1 )
{
v16 = strstr(haystack, "print\n");
if ( !v16 )
break;
v17 = v16 + 6;
do
*v16++ = 32;
while ( v17 != v16 );
}
}
result = close(v9);
if ( result )
{
perror("close");
result = -1;
}
}
}
}
else
{
perror("inet_aton");
result = -1;
}
}
return result;
}

original_code:
int crcon ( char *cmd, char *p_result_buf, char *server, int port, char *gtype, unsigned short int size_result_buf )
{
 unsigned char i;
 int sock;
 short int bytesleft;
 short int buflen;
 struct sockaddr_in addr;
 const unsigned int addr_len = sizeof(addr);
 char *sock_buffer;
 char send_buffer[512];
 char *tmp;
 struct timespec stimespec;
 stimespec.tv_sec = 0;
 stimespec.tv_nsec = 1000000;
 if(strcmp(gtype,"moh") == 0){
  send_buffer[0] = 0xff;
  send_buffer[1] = 0xff;
  send_buffer[2] = 0xff;
  send_buffer[3] = 0xff;
  send_buffer[4] = 0x02;
  strcpy(&send_buffer[5],cmd);
 } else if(strcmp(gtype,"bf") == 0){
  send_buffer[0] = 0xff;
  strcpy(&send_buffer[1],cmd);
 } else {
  send_buffer[0] = 0xff;
  send_buffer[1] = 0xff;
  send_buffer[2] = 0xff;
  send_buffer[3] = 0xff;
  strcpy(&send_buffer[4],cmd);
 }
 sock = socket (2, SOCK_DGRAM, 0);
 if(sock <= 0){
  perror("socket");
  return -1;
 }
 memset(&addr,'\0', addr_len);
 addr.sin_family = 2;
 addr.sin_port = htons(port);
 if( inet_aton ( server, (struct in_addr*)&addr.sin_addr ) == 0 ){
  perror("inet_aton");
  return -1;
 }
 if( connect ( sock, (struct sockaddr*)&addr, addr_len) ){
  perror("connect");
  return -1;
 }
 fcntl(sock,4,04000);
 if ( send(sock, send_buffer, strlen(send_buffer), 0) < 1 ) {
  perror("send");
  return -1;
 }
 memset(p_result_buf,'\0',size_result_buf);
 i = 1;
 bytesleft = size_result_buf;
 sock_buffer = (char*)malloc(size_result_buf);
 memset(sock_buffer, '\0',size_result_buf);
 while(i < 10){
  while( read (sock,sock_buffer,( bytesleft - 1 )) > 0 ){
   buflen = strlen(sock_buffer);
   strcat(p_result_buf,sock_buffer);
   memset(sock_buffer,'\0', size_result_buf);
   bytesleft = bytesleft - buflen;
   i=1;
  }
  if(nanosleep(&stimespec,((void *)0)) != 0){
   perror("nanosleep");
   break;
         }
  i++;
 }
 free(sock_buffer);
 if(i > 1){
  while((tmp = strstr(p_result_buf,"print\n")) != ((void *)0)){
   for(i=0;i<6;i++){
       *tmp = ' ';
       tmp++;
   }
  }
 }
 if( close(sock) ){
  perror("close");
  return -1;
 }
 return 0;
}

canonical_original_code:
int crcon(char *cmd, char *p_result_buf, char *server, int port, char *gtype, unsigned short size_result_buf)
{
 unsigned char i;
 int sock;
 short bytesleft;
 short buflen;
 struct sockaddr_in addr;
 unsigned int addr_len = sizeof(addr);
 char *sock_buffer;
 char send_buffer[512];
 char *tmp;
 struct timespec stimespec;
 stimespec.tv_sec = 0;
 stimespec.tv_nsec = 1000000;
 if(strcmp(gtype,"moh") == 0){
  send_buffer[0] = 0xff;
  send_buffer[1] = 0xff;
  send_buffer[2] = 0xff;
  send_buffer[3] = 0xff;
  send_buffer[4] = 0x02;
  strcpy(&send_buffer[5],cmd);
 } else if(strcmp(gtype,"bf") == 0){
  send_buffer[0] = 0xff;
  strcpy(&send_buffer[1],cmd);
 } else {
  send_buffer[0] = 0xff;
  send_buffer[1] = 0xff;
  send_buffer[2] = 0xff;
  send_buffer[3] = 0xff;
  strcpy(&send_buffer[4],cmd);
 }
 sock = socket (2, SOCK_DGRAM, 0);
 if(sock <= 0){
  perror("socket");
  return -1;
 }
 memset(&addr,'\0', addr_len);
 addr.sin_family = 2;
 addr.sin_port = htons(port);
 if( inet_aton ( server, (struct in_addr *)&addr.sin_addr ) == 0 ){
  perror("inet_aton");
  return -1;
 }
 if( connect ( sock, (struct sockaddr *)&addr, addr_len) ){
  perror("connect");
  return -1;
 }
 fcntl(sock,4,04000);
 if ( send(sock, send_buffer, strlen(send_buffer), 0) < 1 ) {
  perror("send");
  return -1;
 }
 memset(p_result_buf,'\0',size_result_buf);
 i = 1;
 bytesleft = size_result_buf;
 sock_buffer = (char *)malloc(size_result_buf);
 memset(sock_buffer, '\0',size_result_buf);
 while(i < 10){
  while( read (sock,sock_buffer,( bytesleft - 1 )) > 0 ){
   buflen = strlen(sock_buffer);
   strcat(p_result_buf,sock_buffer);
   memset(sock_buffer,'\0', size_result_buf);
   bytesleft = bytesleft - buflen;
   i=1;
  }
  if(nanosleep(&stimespec,((void *)0)) != 0){
   perror("nanosleep");
   break;
         }
  i++;
 }
 free(sock_buffer);
 if(i > 1){
  while((tmp = strstr(p_result_buf,"print\n")) != ((void *)0)){
   for(i=0;i<6;i++){
       *tmp = ' ';
       tmp++;
   }
  }
 }
 if( close(sock) ){
  perror("close");
  return -1;
 }
 return 0;
}

variable_types:
cmd
char *

variable_types:
server
char *

variable_types: port int

variable_types:
gtype
char *

variable_types:
i
unsigned char

variable_types: bytesleft short

variable_types: buflen short

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
tmp
char *

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


decompiled_code:
int __fastcall print_player_var(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return puts(a1);
}

original_code:
void print_player_var(char *val){
 printf("%s\n",val);
}

variable_types:
val
char *

return_type: void


decompiled_code:
int __fastcall print_player_list(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 208) )
result = printf("\"%s\"\n", (const char *)i);
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 208) )
result = printf("\"%s\"\n", (const char *)i);
return result;
}

original_code:
void print_player_list(player_list *plist){
 player_node *cur_pnode;
 cur_pnode = plist->first;
 while(cur_pnode != ((void *)0)){
  printf("\"%s\"\n",cur_pnode->player_name);
  cur_pnode = cur_pnode->next;
 }
}

canonical_original_code:
void print_player_list(struct _player_list *plist){
 struct _player_node *cur_pnode;
 cur_pnode = plist->first;
 while(cur_pnode != ((void *)0)){
  printf("\"%s\"\n",cur_pnode->player_name);
  cur_pnode = cur_pnode->next;
 }
}

variable_types: struct _player_list { unsigned char count; struct _player_node { unsigned char player_name[96]; char nice_name[96]; unsigned long kioskid; unsigned long userid; struct _player_node *next; } *first; } *

user_defined_types: struct _player_list { unsigned char count; struct _player_node *first; }


target

repo: nacx/circus

decompiled_code:
void target()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void target(char* txt) {
}

canonical_original_code:
void target(char *txt) {
}

variable_types:
txt
char *


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

v0 = malloc(0x10uLL);
bindings = v0;
if ( !v0 )
{
perror("Out of memory (bnd_init: table)");
exit(1);
}
*v0 = ht_create();
v1 = bindings;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
v1[1] = v2;
if ( !v2 )
{
perror("Out of memory (bnd_init: lock)");
exit(1);
}
return pthread_mutex_init(v2, 0LL);
}

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

v0 = malloc(0x10uLL);
bindings = v0;
if ( !v0 )
{
perror("Out of memory (bnd_init: table)");
exit(1);
}
*v0 = ht_create();
v1 = bindings;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
v1[1] = v2;
if ( !v2 )
{
perror("Out of memory (bnd_init: lock)");
exit(1);
}
return pthread_mutex_init(v2, 0LL);
}

original_code:
static void bnd_init() {
    (void)0;
    if ((bindings = malloc(sizeof(struct bnd_table))) == 0) {
        perror("Out of memory (bnd_init: table)");
        exit(1);
    }
    bindings->table = ht_create();
    (void)0;
    if ((bindings->lock = malloc(sizeof(pthread_mutex_t))) == 0) {
        perror("Out of memory (bnd_init: lock)");
        exit(1);
    }
    pthread_mutex_init(bindings->lock, ((void *)0));
}

user_defined_types: struct bnd_table { struct ht_table *table; union pthread_mutex_t *lock; }

user_defined_types: struct ht_table { struct ht_entry **entries; int size; int num_entries; }

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 __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct ht_entry { struct ht_entry *next; struct ht_data *data; }

user_defined_types: struct ht_data { char *key; void *value; void (*function)(); }


decompiled_code:
int __fastcall bnd_bind(__int64 a1, __int64 a2)
{
if ( !bindings )
bnd_init();
pthread_mutex_lock(*((pthread_mutex_t **)bindings + 1));
ht_add_function(*(_QWORD *)bindings, a1, a2);
return pthread_mutex_unlock(*((pthread_mutex_t **)bindings + 1));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
if ( !bindings )
func1();
pthread_mutex_lock(*((pthread_mutex_t **)bindings + 1));
ht_add_function(*(_QWORD *)bindings, a1, a2);
return pthread_mutex_unlock(*((pthread_mutex_t **)bindings + 1));
}

original_code:
void bnd_bind(char* event, Callback callback) {
    (void)0;
    if (bindings == ((void *)0)) {
        bnd_init();
    }
    pthread_mutex_lock(bindings->lock);
    ht_add_function(bindings->table, event, callback);
    pthread_mutex_unlock(bindings->lock);
}

canonical_original_code:
void bnd_bind(char *event, void (*callback)()) {
    (void)0;
    if (bindings == ((void *)0)) {
        bnd_init();
    }
    pthread_mutex_lock(bindings->lock);
    ht_add_function(bindings->table, event, callback);
    pthread_mutex_unlock(bindings->lock);
}

variable_types:
event
char *

variable_types:
callback
void (*)()


decompiled_code:
int __fastcall bnd_unbind(__int64 a1)
{
pthread_mutex_lock(*((pthread_mutex_t **)bindings + 1));
ht_del(*(_QWORD *)bindings, a1);
return pthread_mutex_unlock(*((pthread_mutex_t **)bindings + 1));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
pthread_mutex_lock(*((pthread_mutex_t **)bindings + 1));
ht_del(*(_QWORD *)bindings, a1);
return pthread_mutex_unlock(*((pthread_mutex_t **)bindings + 1));
}

original_code:
void bnd_unbind(char* event) {
    (void)0;
    pthread_mutex_lock(bindings->lock);
    ht_del(bindings->table, event);
    pthread_mutex_unlock(bindings->lock);
}

canonical_original_code:
void bnd_unbind(char *event) {
    (void)0;
    pthread_mutex_lock(bindings->lock);
    ht_del(bindings->table, event);
    pthread_mutex_unlock(bindings->lock);
}


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

v1 = ht_find(*(_QWORD *)bindings, a1);
if ( v1 )
result = *(_QWORD *)(v1 + 16);
else
result = 0LL;
return result;
}

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

v1 = ht_find(*(_QWORD *)bindings, a1);
if ( v1 )
result = *(_QWORD *)(v1 + 16);
else
result = 0LL;
return result;
}

original_code:
Callback bnd_lookup(char* event) {
    struct ht_data* data;
    (void)0;
    data = ht_find(bindings->table, event);
    return data == ((void *)0)? ((void *)0) : data->function;
}

canonical_original_code:
void (*bnd_lookup(char *event))() {
    struct ht_data *data;
    (void)0;
    data = ht_find(bindings->table, event);
    return data == ((void *)0)? ((void *)0) : data->function;
}

variable_types: struct ht_data { char *key; void *value; void (*function)(); } *


decompiled_code:
void bnd_destroy()
{
void **v0; // rbx

if ( bindings )
{
ht_destroy(*(_QWORD *)bindings);
v0 = (void **)bindings;
pthread_mutex_destroy(*((pthread_mutex_t **)bindings + 1));
free(v0[1]);
free(v0);
bindings = 0LL;
}
}

canonical_decompiled_code:
void func5()
{
void **v0; // rbx

if ( bindings )
{
ht_destroy(*(_QWORD *)bindings);
v0 = (void **)bindings;
pthread_mutex_destroy(*((pthread_mutex_t **)bindings + 1));
free(v0[1]);
free(v0);
bindings = 0LL;
}
}

original_code:
void bnd_destroy() {
    if (bindings != ((void *)0)) {
        (void)0;
        ht_destroy(bindings->table);
        (void)0;
        pthread_mutex_destroy(bindings->lock);
        free(bindings->lock);
        free(bindings);
        bindings = ((void *)0);
    }
}


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

bnd_init();
result = bindings;
if ( !bindings )
return (void *)mu_fail("test_bnd_init: bindings should not be NULL");
if ( !*(_QWORD *)bindings )
return (void *)mu_fail("test_bnd_init: binding table should not be NULL");
if ( !*((_QWORD *)bindings + 1) )
result = (void *)mu_fail("test_bnd_init: binding lock should not be NULL");
return result;
}

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

func1();
result = bindings;
if ( !bindings )
return (void *)mu_fail("test_bnd_init: bindings should not be NULL");
if ( !*(_QWORD *)bindings )
return (void *)mu_fail("test_bnd_init: binding table should not be NULL");
if ( !*((_QWORD *)bindings + 1) )
result = (void *)mu_fail("test_bnd_init: binding lock should not be NULL");
return result;
}

original_code:
void test_bnd_init() {
    bnd_init();
    do { if (!(bindings != ((void *)0))) { mu_fail("test_bnd_init: bindings should not be NULL"); return; } } while (0);
    do { if (!(bindings->table != ((void *)0))) { mu_fail("test_bnd_init: binding table should not be NULL"); return; } } while (0);
    do { if (!(bindings->lock != ((void *)0))) { mu_fail("test_bnd_init: binding lock should not be NULL"); return; } } while (0);
}


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

bnd_bind((__int64)"test", (__int64)target);
if ( bnd_lookup((__int64)"test") )
return mu_fail("test_bnd_lookup: Found a different memory address");
bnd_unbind((__int64)"test");
result = bnd_lookup((__int64)"test");
if ( result )
result = mu_fail("test_bnd_lookup: callback should be NULL");
return result;
}

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

func2((__int64)"test", (__int64)target);
if ( func4((__int64)"test") )
return mu_fail("test_bnd_lookup: Found a different memory address");
func3((__int64)"test");
result = func4((__int64)"test");
if ( result )
result = mu_fail("test_bnd_lookup: callback should be NULL");
return result;
}

original_code:
void test_bnd_lookup() {
    Callback callback;
    bnd_bind("test", (Callback) target);
    callback = bnd_lookup("test");
    do { if (!(callback == (Callback) target)) { mu_fail("test_bnd_lookup: Found a different memory address"); return; } } while (0);
    bnd_unbind("test");
    callback = bnd_lookup("test");
    do { if (!(callback == ((void *)0))) { mu_fail("test_bnd_lookup: callback should be NULL"); return; } } while (0);
}

canonical_original_code:
void test_bnd_lookup() {
    void (*callback)();
    bnd_bind("test", (void (*)()) target);
    callback = bnd_lookup("test");
    do { if (!(callback == (void (*)()) target)) { mu_fail("test_bnd_lookup: Found a different memory address"); return; } } while (0);
    bnd_unbind("test");
    callback = bnd_lookup("test");
    do { if (!(callback == ((void *)0))) { mu_fail("test_bnd_lookup: callback should be NULL"); return; } } while (0);
}


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

result = bnd_lookup((__int64)"test-unexisting");
if ( result )
result = mu_fail("test_lookup_unexisting_event: Callback should be NULL");
return result;
}

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

result = func4((__int64)"test-unexisting");
if ( result )
result = mu_fail("test_lookup_unexisting_event: Callback should be NULL");
return result;
}

original_code:
void test_lookup_unexisting_event() {
    Callback callback = bnd_lookup("test-unexisting");
    do { if (!(callback == ((void *)0))) { mu_fail("test_lookup_unexisting_event: Callback should be NULL"); return; } } while (0);
}

canonical_original_code:
void test_lookup_unexisting_event() {
    void (*callback)() = bnd_lookup("test-unexisting");
    do { if (!(callback == ((void *)0))) { mu_fail("test_lookup_unexisting_event: Callback should be NULL"); return; } } while (0);
}


decompiled_code:
void test_bnd_destroy()
{
bnd_destroy();
if ( bindings )
mu_fail("test_bnd_destroy: Binding table should be NULL");
}

canonical_decompiled_code:
void func9()
{
func5();
if ( bindings )
mu_fail("test_bnd_destroy: Binding table should be NULL");
}

original_code:
void test_bnd_destroy() {
    bnd_destroy();
    do { if (!(bindings == ((void *)0))) { mu_fail("test_bnd_destroy: Binding table should be NULL"); return; } } while (0);
}


decompiled_code:
void test_binding()
{
test_bnd_init();
++tests_run;
test_bnd_lookup();
++tests_run;
test_lookup_unexisting_event();
++tests_run;
test_bnd_destroy();
++tests_run;
}

canonical_decompiled_code:
void func10()
{
func6();
++tests_run;
func7();
++tests_run;
func8();
++tests_run;
func9();
++tests_run;
}

original_code:
void test_binding() {
    do { (void)0; test_bnd_init(); tests_run++; } while (0);
    do { (void)0; test_bnd_lookup(); tests_run++; } while (0);
    do { (void)0; test_lookup_unexisting_event(); tests_run++; } while (0);
    do { (void)0; test_bnd_destroy(); tests_run++; } while (0);
}


decompiled_code:
__int64 __fastcall ht_hash(unsigned __int8 *a1)
{
int v1; // eax
unsigned int v2; // edx

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

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

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

original_code:
static unsigned char ht_hash(char* key) {
    unsigned char hash = 0;
    char* str = key;
    while (*str) {
        hash += *str++;
    }
    return hash;
}

canonical_original_code:
static unsigned char ht_hash(char *key) {
    unsigned char hash = 0;
    char *str = key;
    while (*str) {
        hash += *str++;
    }
    return hash;
}

variable_types:
key
char *

variable_types:
hash
unsigned char

variable_types:
str
char *

return_type: unsigned char


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

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

original_code:
static void ht_data_destroy(struct ht_data* data) {
    if (data != ((void *)0)) {
        free(data->key);
        free(data);
    }
}

canonical_original_code:
static void ht_data_destroy(struct ht_data *data) {
    if (data != ((void *)0)) {
        free(data->key);
        free(data);
    }
}


decompiled_code:
char **__fastcall ht_data_create(char *src, char *a2, char *a3)
{
char **v4; // rax
char **v5; // rbx
size_t v6; // rax
char *v7; // r12
size_t v8; // rax

v4 = (char **)malloc(0x18uLL);
if ( !v4 )
{
perror("Out of memory (ht_data_create)");
exit(1);
}
v5 = v4;
v6 = strlen(src);
v7 = (char *)malloc(v6 + 1);
*v5 = v7;
if ( !v7 )
{
perror("Out of memory (ht_data_create: key)");
exit(1);
}
v8 = strlen(src);
strncpy(v7, src, v8 + 1);
v5[1] = a2;
v5[2] = a3;
return v5;
}

canonical_decompiled_code:
char **__fastcall func2(char *src, char *a2, char *a3)
{
char **v4; // rax
char **v5; // rbx
size_t v6; // rax
char *v7; // r12
size_t v8; // rax

v4 = (char **)malloc(0x18uLL);
if ( !v4 )
{
perror("Out of memory (ht_data_create)");
exit(1);
}
v5 = v4;
v6 = strlen(src);
v7 = (char *)malloc(v6 + 1);
*v5 = v7;
if ( !v7 )
{
perror("Out of memory (ht_data_create: key)");
exit(1);
}
v8 = strlen(src);
strncpy(v7, src, v8 + 1);
v5[1] = a2;
v5[2] = a3;
return v5;
}

original_code:
static struct ht_data* ht_data_create(char* key, void* value, Function function) {
    struct ht_data* data;
    if ((data = malloc(sizeof(struct ht_data))) == 0) {
        perror("Out of memory (ht_data_create)");
        exit(1);
    }
    if ((data->key = malloc((strlen(key) + 1) * sizeof(char))) == 0) {
        perror("Out of memory (ht_data_create: key)");
        exit(1);
    }
    strncpy(data->key, key, strlen(key) + 1);
    data->value = value;
    data->function = function;
    return data;
}

canonical_original_code:
static struct ht_data *ht_data_create(char *key, void *value, void (*function)()) {
    struct ht_data *data;
    if ((data = malloc(sizeof(struct ht_data))) == 0) {
        perror("Out of memory (ht_data_create)");
        exit(1);
    }
    if ((data->key = malloc((strlen(key) + 1) * sizeof(char))) == 0) {
        perror("Out of memory (ht_data_create: key)");
        exit(1);
    }
    strncpy(data->key, key, strlen(key) + 1);
    data->value = value;
    data->function = function;
    return data;
}

variable_types:
value
void *

variable_types:
function
void (*)()

return_type: struct ht_data { char *key; void *value; void (*function)(); } *


decompiled_code:
_DWORD *ht_create()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // rdx

v0 = malloc(0x10uLL);
if ( !v0 )
{
perror("Out of memory (ht_create)");
exit(1);
}
v1 = v0;
v2 = malloc(0x800uLL);
*(_QWORD *)v1 = v2;
if ( !v2 )
{
perror("Out of memory (ht_create: entries)");
exit(1);
}
v3 = v2 + 256;
do
*v2++ = 0LL;
while ( v2 != v3 );
v1[3] = 0;
v1[2] = 256;
return v1;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // rdx

v0 = malloc(0x10uLL);
if ( !v0 )
{
perror("Out of memory (ht_create)");
exit(1);
}
v1 = v0;
v2 = malloc(0x800uLL);
*(_QWORD *)v1 = v2;
if ( !v2 )
{
perror("Out of memory (ht_create: entries)");
exit(1);
}
v3 = v2 + 256;
do
*v2++ = 0LL;
while ( v2 != v3 );
v1[3] = 0;
v1[2] = 256;
return v1;
}

original_code:
struct ht_table* ht_create() {
    int i;
    struct ht_table* ht;
    (void)0;
    if ((ht = malloc(sizeof(struct ht_table))) == 0) {
        perror("Out of memory (ht_create)");
        exit(1);
    }
    if ((ht->entries = malloc(256 * sizeof(struct ht_entry*))) == 0) {
        perror("Out of memory (ht_create: entries)");
        exit(1);
    }
    for (i = 0; i < 256; i++) {
        ht->entries[i] = ((void *)0);
    }
    ht->num_entries = 0;
    ht->size = 256;
    return ht;
}

canonical_original_code:
struct ht_table *ht_create() {
    int i;
    struct ht_table *ht;
    (void)0;
    if ((ht = malloc(sizeof(struct ht_table))) == 0) {
        perror("Out of memory (ht_create)");
        exit(1);
    }
    if ((ht->entries = malloc(256 * sizeof(struct ht_entry *))) == 0) {
        perror("Out of memory (ht_create: entries)");
        exit(1);
    }
    for (i = 0; i < 256; i++) {
        ht->entries[i] = ((void *)0);
    }
    ht->num_entries = 0;
    ht->size = 256;
    return ht;
}

variable_types: i int

variable_types: struct ht_table { struct ht_entry { struct ht_entry *next; struct ht_data { char *key; void *value; void (*function)(); } *data; } **entries; int size; int num_entries; } *


decompiled_code:
void __fastcall ht_destroy(void *ptr)
{
__int64 v1; // r12
void **v2; // rbx
void **v3; // rbp

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
{
v2 = *(void ***)(*(_QWORD *)ptr + 8 * v1);
while ( v2 )
{
v3 = v2;
v2 = (void **)*v2;
ht_data_destroy(v3[1]);
free(v3);
}
++v1;
}
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
__int64 v1; // r12
void **v2; // rbx
void **v3; // rbp

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
{
v2 = *(void ***)(*(_QWORD *)ptr + 8 * v1);
while ( v2 )
{
v3 = v2;
v2 = (void **)*v2;
func1(v3[1]);
free(v3);
}
++v1;
}
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void ht_destroy(struct ht_table* ht) {
    struct ht_entry* current, *previous;
    int i = 0;
    (void)0;
    for (i = 0; i < ht->size; i++) {
        if (ht->entries[i] != ((void *)0)) {
            current = ht->entries[i];
            while (current != ((void *)0)) {
                previous = current;
                current = current->next;
                ht_data_destroy(previous->data);
                free(previous);
            }
        }
    }
    free(ht->entries);
    free(ht);
}

canonical_original_code:
void ht_destroy(struct ht_table *ht) {
    struct ht_entry *current; struct ht_entry *previous;
    int i = 0;
    (void)0;
    for (i = 0; i < ht->size; i++) {
        if (ht->entries[i] != ((void *)0)) {
            current = ht->entries[i];
            while (current != ((void *)0)) {
                previous = current;
                current = current->next;
                ht_data_destroy(previous->data);
                free(previous);
            }
        }
    }
    free(ht->entries);
    free(ht);
}

variable_types: struct ht_entry { struct ht_entry *next; struct ht_data { char *key; void *value; void (*function)(); } *data; } *


decompiled_code:
void __fastcall ht_del(__int64 a1, unsigned __int8 *a2)
{
void **v2; // r14
void *v3; // rbx
_QWORD *v4; // r12

v2 = (void **)(*(_QWORD *)a1 + 8LL * (unsigned __int8)ht_hash(a2));
v3 = *v2;
v4 = 0LL;
if ( *v2 )
{
while ( strcmp(**((const char ***)v3 + 1), (const char *)a2) )
{
v4 = v3;
if ( !*(_QWORD *)v3 )
return;
v3 = *(void **)v3;
}
if ( v4 )
*v4 = *(_QWORD *)v3;
else
*v2 = *(void **)v3;
ht_data_destroy(*((void **)v3 + 1));
free(v3);
--*(_DWORD *)(a1 + 12);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, unsigned __int8 *a2)
{
void **v2; // r14
void *v3; // rbx
_QWORD *v4; // r12

v2 = (void **)(*(_QWORD *)a1 + 8LL * (unsigned __int8)func0(a2));
v3 = *v2;
v4 = 0LL;
if ( *v2 )
{
while ( strcmp(**((const char ***)v3 + 1), (const char *)a2) )
{
v4 = v3;
if ( !*(_QWORD *)v3 )
return;
v3 = *(void **)v3;
}
if ( v4 )
*v4 = *(_QWORD *)v3;
else
*v2 = *(void **)v3;
func1(*((void **)v3 + 1));
free(v3);
--*(_DWORD *)(a1 + 12);
}
}

original_code:
void ht_del(struct ht_table* ht, char* key) {
    struct ht_entry *current, *old;
    unsigned char idx;
    (void)0;
    old = 0;
    idx = ht_hash(key);
    current = ht->entries[idx];
    while (current != ((void *)0) && (strcmp(current->data->key,key) != 0)) {
        old = current;
        current = current->next;
    }
    if (current != ((void *)0)) {
        if (old != ((void *)0)) {
            old->next = current->next;
        } else {
            ht->entries[idx] = current->next;
        }
        ht_data_destroy(current->data);
        free(current);
        ht->num_entries--;
    }
}

canonical_original_code:
void ht_del(struct ht_table *ht, char *key) {
    struct ht_entry *current; struct ht_entry *old;
    unsigned char idx;
    (void)0;
    old = 0;
    idx = ht_hash(key);
    current = ht->entries[idx];
    while (current != ((void *)0) && (strcmp(current->data->key,key) != 0)) {
        old = current;
        current = current->next;
    }
    if (current != ((void *)0)) {
        if (old != ((void *)0)) {
            old->next = current->next;
        } else {
            ht->entries[idx] = current->next;
        }
        ht_data_destroy(current->data);
        free(current);
        ht->num_entries--;
    }
}

variable_types:
idx
unsigned char


decompiled_code:
void test_ht_add_function()
{
ht_add_function((__int64)ht, "test-key", (char *)test_ht_add_function);
if ( *(_QWORD *)(*(_QWORD *)ht + 8LL * (unsigned __int8)ht_hash("test-key")) )
{
if ( *((_DWORD *)ht + 3) == 1 )
ht_del((__int64)ht, "test-key");
else
mu_fail("test_ht_add: ht->num_entries should be 1");
}
else
{
mu_fail("test_ht_add: ht->entries[idx] should not be NULL");
}
}

canonical_decompiled_code:
void func9()
{
func7((__int64)ht, "test-key", (char *)test_ht_add_function);
if ( *(_QWORD *)(*(_QWORD *)ht + 8LL * (unsigned __int8)func0("test-key")) )
{
if ( *((_DWORD *)ht + 3) == 1 )
func8((__int64)ht, "test-key");
else
mu_fail("test_ht_add: ht->num_entries should be 1");
}
else
{
mu_fail("test_ht_add: ht->entries[idx] should not be NULL");
}
}

original_code:
void test_ht_add_function() {
    unsigned char idx;
    char* key = "test-key";
    ht_add_function(ht, key, test_ht_add_function);
    idx = ht_hash(key);
    do { if (!(ht->entries[idx] != ((void *)0))) { mu_fail("test_ht_add: ht->entries[idx] should not be NULL"); return; } } while (0);
    do { if (!(ht->num_entries == 1)) { mu_fail("test_ht_add: ht->num_entries should be 1"); return; } } while (0);
    ht_del(ht, key);
}

canonical_original_code:
void test_ht_add_function() {
    unsigned char idx;
    char *key = "test-key";
    ht_add_function(ht, key, test_ht_add_function);
    idx = ht_hash(key);
    do { if (!(ht->entries[idx] != ((void *)0))) { mu_fail("test_ht_add: ht->entries[idx] should not be NULL"); return; } } while (0);
    do { if (!(ht->num_entries == 1)) { mu_fail("test_ht_add: ht->num_entries should be 1"); return; } } while (0);
    ht_del(ht, key);
}


original_code:
void ht_print_keys(struct ht_table* ht) {
    struct ht_entry* current;
    int i = 0;
    (void)0;
    for (i = 0; i < ht->size; i++) {
        if (ht->entries[i] != ((void *)0)) {
            current = ht->entries[i];
            while (current != ((void *)0)) {
                printf("Key: %s\n", current->data->key);
                current = current->next;
            }
        }
    }
}

canonical_original_code:
void ht_print_keys(struct ht_table *ht) {
    struct ht_entry *current;
    int i = 0;
    (void)0;
    for (i = 0; i < ht->size; i++) {
        if (ht->entries[i] != ((void *)0)) {
            current = ht->entries[i];
            while (current != ((void *)0)) {
                printf("Key: %s\n", current->data->key);
                current = current->next;
            }
        }
    }
}


decompiled_code:
_DWORD *test_ht_create()
{
_DWORD *result; // rax

result = ht_create();
ht = result;
if ( !result )
return (_DWORD *)mu_fail("test_ht_create: Hash table should exist");
if ( result[3] )
result = (_DWORD *)mu_fail("test_ht_create: ht->num_entries should be 0");
return result;
}

canonical_decompiled_code:
_DWORD *func12()
{
_DWORD *result; // rax

result = func4();
ht = result;
if ( !result )
return (_DWORD *)mu_fail("test_ht_create: Hash table should exist");
if ( result[3] )
result = (_DWORD *)mu_fail("test_ht_create: ht->num_entries should be 0");
return result;
}

original_code:
void test_ht_create() {
    ht = ht_create();
    do { if (!(ht != ((void *)0))) { mu_fail("test_ht_create: Hash table should exist"); return; } } while (0);
    do { if (!(ht->num_entries == 0)) { mu_fail("test_ht_create: ht->num_entries should be 0"); return; } } while (0);
}


decompiled_code:
void test_ht_add_value()
{
ht_add_value((__int64)ht, "test-key", "test-key");
if ( *(_QWORD *)(*(_QWORD *)ht + 8LL * (unsigned __int8)ht_hash("test-key")) )
{
if ( *((_DWORD *)ht + 3) == 1 )
ht_del((__int64)ht, "test-key");
else
mu_fail("test_ht_add: ht->num_entries should be 1");
}
else
{
mu_fail("test_ht_add: ht->entries[idx] should not be NULL");
}
}

canonical_decompiled_code:
void func13()
{
func6((__int64)ht, "test-key", "test-key");
if ( *(_QWORD *)(*(_QWORD *)ht + 8LL * (unsigned __int8)func0("test-key")) )
{
if ( *((_DWORD *)ht + 3) == 1 )
func8((__int64)ht, "test-key");
else
mu_fail("test_ht_add: ht->num_entries should be 1");
}
else
{
mu_fail("test_ht_add: ht->entries[idx] should not be NULL");
}
}

original_code:
void test_ht_add_value() {
    unsigned char idx;
    char* key = "test-key";
    ht_add_value(ht, key, key);
    idx = ht_hash(key);
    do { if (!(ht->entries[idx] != ((void *)0))) { mu_fail("test_ht_add: ht->entries[idx] should not be NULL"); return; } } while (0);
    do { if (!(ht->num_entries == 1)) { mu_fail("test_ht_add: ht->num_entries should be 1"); return; } } while (0);
    ht_del(ht, key);
}

canonical_original_code:
void test_ht_add_value() {
    unsigned char idx;
    char *key = "test-key";
    ht_add_value(ht, key, key);
    idx = ht_hash(key);
    do { if (!(ht->entries[idx] != ((void *)0))) { mu_fail("test_ht_add: ht->entries[idx] should not be NULL"); return; } } while (0);
    do { if (!(ht->num_entries == 1)) { mu_fail("test_ht_add: ht->num_entries should be 1"); return; } } while (0);
    ht_del(ht, key);
}


decompiled_code:
void test_ht_add_replace()
{
ht_add_value((__int64)ht, "test-key", "test-key");
ht_add_value((__int64)ht, "test-key", "test-key");
if ( *((_DWORD *)ht + 3) == 1 )
ht_del((__int64)ht, "test-key");
else
mu_fail("test_ht_add_replace: ht->num_entries should be 1");
}

canonical_decompiled_code:
void func14()
{
func6((__int64)ht, "test-key", "test-key");
func6((__int64)ht, "test-key", "test-key");
if ( *((_DWORD *)ht + 3) == 1 )
func8((__int64)ht, "test-key");
else
mu_fail("test_ht_add_replace: ht->num_entries should be 1");
}

original_code:
void test_ht_add_replace() {
    char* key = "test-key";
    ht_add_value(ht, key, key);
    ht_add_value(ht, key, key);
    do { if (!(ht->num_entries == 1)) { mu_fail("test_ht_add_replace: ht->num_entries should be 1"); return; } } while (0);
    ht_del(ht, key);
}

canonical_original_code:
void test_ht_add_replace() {
    char *key = "test-key";
    ht_add_value(ht, key, key);
    ht_add_value(ht, key, key);
    do { if (!(ht->num_entries == 1)) { mu_fail("test_ht_add_replace: ht->num_entries should be 1"); return; } } while (0);
    ht_del(ht, key);
}


decompiled_code:
__int64 test_ht_del()
{
unsigned __int8 v0; // bl
__int64 *v1; // rbp
__int64 result; // rax

ht_add_value((__int64)ht, "test-key", "test-key");
v0 = ht_hash("test-key");
v1 = (__int64 *)ht;
ht_del((__int64)ht, "test-key");
result = *v1;
if ( *(_QWORD *)(*v1 + 8LL * v0) )
return mu_fail("test_ht_del: ht->entries[idx] should be NULL");
if ( *((_DWORD *)v1 + 3) )
result = mu_fail("test_ht_del: ht->num_entries should be 0");
return result;
}

canonical_decompiled_code:
__int64 func15()
{
unsigned __int8 v0; // bl
__int64 *v1; // rbp
__int64 result; // rax

func6((__int64)ht, "test-key", "test-key");
v0 = func0("test-key");
v1 = (__int64 *)ht;
func8((__int64)ht, "test-key");
result = *v1;
if ( *(_QWORD *)(*v1 + 8LL * v0) )
return mu_fail("test_ht_del: ht->entries[idx] should be NULL");
if ( *((_DWORD *)v1 + 3) )
result = mu_fail("test_ht_del: ht->num_entries should be 0");
return result;
}

original_code:
void test_ht_del() {
    unsigned char idx;
    char* key = "test-key";
    ht_add_value(ht, key, key);
    idx = ht_hash(key);
    ht_del(ht, key);
    do { if (!(ht->entries[idx] == ((void *)0))) { mu_fail("test_ht_del: ht->entries[idx] should be NULL"); return; } } while (0);
    do { if (!(ht->num_entries == 0)) { mu_fail("test_ht_del: ht->num_entries should be 0"); return; } } while (0);
}

canonical_original_code:
void test_ht_del() {
    unsigned char idx;
    char *key = "test-key";
    ht_add_value(ht, key, key);
    idx = ht_hash(key);
    ht_del(ht, key);
    do { if (!(ht->entries[idx] == ((void *)0))) { mu_fail("test_ht_del: ht->entries[idx] should be NULL"); return; } } while (0);
    do { if (!(ht->num_entries == 0)) { mu_fail("test_ht_del: ht->num_entries should be 0"); return; } } while (0);
}


decompiled_code:
__int64 test_ht_del_unexisting()
{
unsigned __int8 v0; // bl
__int64 *v1; // rbp
__int64 result; // rax

v0 = ht_hash("test-key");
v1 = (__int64 *)ht;
ht_del((__int64)ht, "test-key");
result = *v1;
if ( *(_QWORD *)(*v1 + 8LL * v0) )
result = mu_fail("test_ht_del_unexisting: ht->entries[idx] should be NULL");
return result;
}

canonical_decompiled_code:
__int64 func16()
{
unsigned __int8 v0; // bl
__int64 *v1; // rbp
__int64 result; // rax

v0 = func0("test-key");
v1 = (__int64 *)ht;
func8((__int64)ht, "test-key");
result = *v1;
if ( *(_QWORD *)(*v1 + 8LL * v0) )
result = mu_fail("test_ht_del_unexisting: ht->entries[idx] should be NULL");
return result;
}

original_code:
void test_ht_del_unexisting() {
    char* key = "test-key";
    unsigned char idx;
    idx = ht_hash(key);
    ht_del(ht, key);
    do { if (!(ht->entries[idx] == ((void *)0))) { mu_fail("test_ht_del_unexisting: ht->entries[idx] should be NULL"); return; } } while (0);
}

canonical_original_code:
void test_ht_del_unexisting() {
    char *key = "test-key";
    unsigned char idx;
    idx = ht_hash(key);
    ht_del(ht, key);
    do { if (!(ht->entries[idx] == ((void *)0))) { mu_fail("test_ht_del_unexisting: ht->entries[idx] should be NULL"); return; } } while (0);
}


decompiled_code:
void test_ht_find()
{
void *v0; // rbx
const char **v1; // rax

ht_add_value((__int64)ht, "test-key", "test-key");
v0 = ht;
v1 = ht_find(ht, "test-key");
if ( v1 )
{
if ( !strcmp(*v1, "test-key") )
ht_del((__int64)v0, "test-key");
else
mu_fail("test_ht_find: key does not match");
}
else
{
mu_fail("test_ht_find: Entry should not be NULL");
}
}

canonical_decompiled_code:
void func17()
{
void *v0; // rbx
const char **v1; // rax

func6((__int64)ht, "test-key", "test-key");
v0 = ht;
v1 = func10(ht, "test-key");
if ( v1 )
{
if ( !strcmp(*v1, "test-key") )
func8((__int64)v0, "test-key");
else
mu_fail("test_ht_find: key does not match");
}
else
{
mu_fail("test_ht_find: Entry should not be NULL");
}
}

original_code:
void test_ht_find() {
    char* key = "test-key";
    struct ht_data* data;
    ht_add_value(ht, key, key);
    data = ht_find(ht, key);
    do { if (!(data != ((void *)0))) { mu_fail("test_ht_find: Entry should not be NULL"); return; } } while (0);
    do { if (!((strcmp(data->key,key) == 0))) { mu_fail("test_ht_find: key does not match"); return; } } while (0);
    ht_del(ht, key);
}

canonical_original_code:
void test_ht_find() {
    char *key = "test-key";
    struct ht_data *data;
    ht_add_value(ht, key, key);
    data = ht_find(ht, key);
    do { if (!(data != ((void *)0))) { mu_fail("test_ht_find: Entry should not be NULL"); return; } } while (0);
    do { if (!((strcmp(data->key,key) == 0))) { mu_fail("test_ht_find: key does not match"); return; } } while (0);
    ht_del(ht, key);
}


decompiled_code:
const char **test_ht_find_unexisting()
{
const char **result; // rax

result = ht_find(ht, "test-key");
if ( result )
result = (const char **)mu_fail("test_ht_find_unexisting: Entry should be NULL");
return result;
}

canonical_decompiled_code:
const char **func18()
{
const char **result; // rax

result = func10(ht, "test-key");
if ( result )
result = (const char **)mu_fail("test_ht_find_unexisting: Entry should be NULL");
return result;
}

original_code:
void test_ht_find_unexisting() {
    char* key = "test-key";
    struct ht_data* data;
    data = ht_find(ht, key);
    do { if (!(data == ((void *)0))) { mu_fail("test_ht_find_unexisting: Entry should be NULL"); return; } } while (0);
}

canonical_original_code:
void test_ht_find_unexisting() {
    char *key = "test-key";
    struct ht_data *data;
    data = ht_find(ht, key);
    do { if (!(data == ((void *)0))) { mu_fail("test_ht_find_unexisting: Entry should be NULL"); return; } } while (0);
}


decompiled_code:
void test_ht_destroy()
{
ht_destroy(ht);
}

canonical_decompiled_code:
void func19()
{
func5(ht);
}


decompiled_code:
void test_hashtable()
{
test_ht_create();
++tests_run;
test_ht_add_value();
++tests_run;
test_ht_add_replace();
++tests_run;
test_ht_del();
++tests_run;
test_ht_del_unexisting();
++tests_run;
test_ht_find();
++tests_run;
test_ht_find_unexisting();
++tests_run;
test_ht_destroy();
++tests_run;
}

canonical_decompiled_code:
void func20()
{
func12();
++tests_run;
func13();
++tests_run;
func14();
++tests_run;
func15();
++tests_run;
func16();
++tests_run;
func17();
++tests_run;
func18();
++tests_run;
func19();
++tests_run;
}

original_code:
void test_hashtable() {
    do { (void)0; test_ht_create(); tests_run++; } while (0);
    do { (void)0; test_ht_add_value(); tests_run++; } while (0);
    do { (void)0; test_ht_add_replace(); tests_run++; } while (0);
    do { (void)0; test_ht_del(); tests_run++; } while (0);
    do { (void)0; test_ht_del_unexisting(); tests_run++; } while (0);
    do { (void)0; test_ht_find(); tests_run++; } while (0);
    do { (void)0; test_ht_find_unexisting(); tests_run++; } while (0);
    do { (void)0; test_ht_destroy(); tests_run++; } while (0);
}


decompiled_code:
char test_upper()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char result; // al
char v6[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(v6, "Test Text");
upper(v6);
v2 = "TEST TEXT";
v3 = 10LL;
v4 = v6;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
result = (!v0 && !v1) - v0;
if ( result )
result = mu_fail("test_uppper: text should be 'TEST TEXT'", v4);
return result;
}

canonical_decompiled_code:
char func0()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char result; // al
char v6[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(v6, "Test Text");
upper(v6);
v2 = "TEST TEXT";
v3 = 10LL;
v4 = v6;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
result = (!v0 && !v1) - v0;
if ( result )
result = mu_fail("test_uppper: text should be 'TEST TEXT'", v4);
return result;
}

original_code:
void test_upper() {
    char text[10] = "Test Text";
    upper(text);
    do { if (!((strcmp(text,"TEST TEXT") == 0))) { mu_fail("test_uppper: text should be 'TEST TEXT'"); return; } } while (0);
}

variable_types:
text
char [10]


decompiled_code:
char test_lower()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char result; // al
char v6[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(v6, "Test Text");
lower(v6);
v2 = "test text";
v3 = 10LL;
v4 = v6;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
result = (!v0 && !v1) - v0;
if ( result )
result = mu_fail("test_uppper: text should be 'test text'", v4);
return result;
}

canonical_decompiled_code:
char func1()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char result; // al
char v6[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(v6, "Test Text");
lower(v6);
v2 = "test text";
v3 = 10LL;
v4 = v6;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
result = (!v0 && !v1) - v0;
if ( result )
result = mu_fail("test_uppper: text should be 'test text'", v4);
return result;
}

original_code:
void test_lower() {
    char text[10] = "Test Text";
    lower(text);
    do { if (!((strcmp(text,"test text") == 0))) { mu_fail("test_uppper: text should be 'test text'"); return; } } while (0);
}


decompiled_code:
char test_build_command_key()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
const char *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char result; // al
_BYTE v11[72]; // [rsp+0h] [rbp-48h] BYREF

build_command_key(v11, "cmd");
v2 = "PRIVMSG#cmd";
v3 = 12LL;
v4 = v11;
do
{
if ( !v3 )
break;
v0 = *v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
if ( (!v0 && !v1) != v0 )
return mu_fail("test_build_command_key: key should be 'PRIVMSG#cmd'", v4);
build_command_key(v11, &unk_37B);
v7 = "PRIVMSG#";
v8 = 9LL;
v9 = v11;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
result = (!v5 && !v6) - v5;
if ( result )
result = mu_fail("test_build_command_key: key should be 'PRIVMSG#'", v9);
return result;
}

canonical_decompiled_code:
char func2()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
const char *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char result; // al
_BYTE v11[72]; // [rsp+0h] [rbp-48h] BYREF

build_command_key(v11, "cmd");
v2 = "PRIVMSG#cmd";
v3 = 12LL;
v4 = v11;
do
{
if ( !v3 )
break;
v0 = *v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
if ( (!v0 && !v1) != v0 )
return mu_fail("test_build_command_key: key should be 'PRIVMSG#cmd'", v4);
build_command_key(v11, &unk_37B);
v7 = "PRIVMSG#";
v8 = 9LL;
v9 = v11;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
result = (!v5 && !v6) - v5;
if ( result )
result = mu_fail("test_build_command_key: key should be 'PRIVMSG#'", v9);
return result;
}

original_code:
void test_build_command_key() {
    char key[50];
    build_command_key(key, "cmd");
    do { if (!((strcmp(key,"PRIVMSG#cmd") == 0))) { mu_fail("test_build_command_key: key should be 'PRIVMSG#cmd'"); return; } } while (0);
    build_command_key(key, "");
    do { if (!((strcmp(key,"PRIVMSG#") == 0))) { mu_fail("test_build_command_key: key should be 'PRIVMSG#'"); return; } } while (0);
}

variable_types:
key
char [50]


decompiled_code:
char test_append_channel_flags()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
__int64 *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
__int64 *v9; // rsi
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
__int64 *v14; // rsi
char result; // al
__int64 v16; // [rsp+6h] [rbp-12h] BYREF
__int16 v17; // [rsp+Eh] [rbp-Ah]

v16 = 0LL;
v17 = 0;
append_channel_flags(&v16, 0LL);
if ( (_BYTE)v16 )
return mu_fail("test_append_channel_flags: text should be an empty string", 0LL);
LOBYTE(v16) = 0;
append_channel_flags(&v16, 32LL);
v2 = "m";
v3 = 2LL;
v4 = &v16;
do
{
if ( !v3 )
break;
v0 = *(_BYTE *)v4 < *v2;
v1 = *(_BYTE *)v4 == *v2;
v4 = (__int64 *)((char *)v4 + 1);
++v2;
--v3;
}
while ( v1 );
if ( (!v0 && !v1) != v0 )
return mu_fail("test_append_channel_flags: text should be 'm'", v4);
LOBYTE(v16) = 0;
append_channel_flags(&v16, 28LL);
v7 = "itn";
v8 = 4LL;
v9 = &v16;
do
{
if ( !v8 )
break;
v5 = *(_BYTE *)v9 < *v7;
v6 = *(_BYTE *)v9 == *v7;
v9 = (__int64 *)((char *)v9 + 1);
++v7;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) != v5 )
return mu_fail("test_append_channel_flags: text should be 'itn'", v9);
LOBYTE(v16) = 0;
append_channel_flags(&v16, 0xFFFFLL);
v12 = "psitnm";
v13 = 7LL;
v14 = &v16;
do
{
if ( !v13 )
break;
v10 = *(_BYTE *)v14 < *v12;
v11 = *(_BYTE *)v14 == *v12;
v14 = (__int64 *)((char *)v14 + 1);
++v12;
--v13;
}
while ( v11 );
result = (!v10 && !v11) - v10;
if ( result )
result = mu_fail("test_append_channel_flags: text should be 'psitnm'", v14);
return result;
}

canonical_decompiled_code:
char func3()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
__int64 *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
__int64 *v9; // rsi
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
__int64 *v14; // rsi
char result; // al
__int64 v16; // [rsp+6h] [rbp-12h] BYREF
__int16 v17; // [rsp+Eh] [rbp-Ah]

v16 = 0LL;
v17 = 0;
append_channel_flags(&v16, 0LL);
if ( (_BYTE)v16 )
return mu_fail("test_append_channel_flags: text should be an empty string", 0LL);
LOBYTE(v16) = 0;
append_channel_flags(&v16, 32LL);
v2 = "m";
v3 = 2LL;
v4 = &v16;
do
{
if ( !v3 )
break;
v0 = *(_BYTE *)v4 < *v2;
v1 = *(_BYTE *)v4 == *v2;
v4 = (__int64 *)((char *)v4 + 1);
++v2;
--v3;
}
while ( v1 );
if ( (!v0 && !v1) != v0 )
return mu_fail("test_append_channel_flags: text should be 'm'", v4);
LOBYTE(v16) = 0;
append_channel_flags(&v16, 28LL);
v7 = "itn";
v8 = 4LL;
v9 = &v16;
do
{
if ( !v8 )
break;
v5 = *(_BYTE *)v9 < *v7;
v6 = *(_BYTE *)v9 == *v7;
v9 = (__int64 *)((char *)v9 + 1);
++v7;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) != v5 )
return mu_fail("test_append_channel_flags: text should be 'itn'", v9);
LOBYTE(v16) = 0;
append_channel_flags(&v16, 0xFFFFLL);
v12 = "psitnm";
v13 = 7LL;
v14 = &v16;
do
{
if ( !v13 )
break;
v10 = *(_BYTE *)v14 < *v12;
v11 = *(_BYTE *)v14 == *v12;
v14 = (__int64 *)((char *)v14 + 1);
++v12;
--v13;
}
while ( v11 );
result = (!v10 && !v11) - v10;
if ( result )
result = mu_fail("test_append_channel_flags: text should be 'psitnm'", v14);
return result;
}

original_code:
void test_append_channel_flags() {
    char text[10] = "";
    append_channel_flags(text, 0x0000);
    do { if (!((strcmp(text,"") == 0))) { mu_fail("test_append_channel_flags: text should be an empty string"); return; } } while (0);
    *text = '\0';
    append_channel_flags(text, CH_MODERATED);
    do { if (!((strcmp(text,"m") == 0))) { mu_fail("test_append_channel_flags: text should be 'm'"); return; } } while (0);
    *text = '\0';
    append_channel_flags(text, CH_INVITEONLY | CH_NOEXTMSGS | CH_TOPICLOCK);
    do { if (!((strcmp(text,"itn") == 0))) { mu_fail("test_append_channel_flags: text should be 'itn'"); return; } } while (0);
    *text = '\0';
    append_channel_flags(text, 0xFFFF);
    do { if (!((strcmp(text,"psitnm") == 0))) { mu_fail("test_append_channel_flags: text should be 'psitnm'"); return; } } while (0);
}


decompiled_code:
char test_append_user_flags()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
__int64 *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
__int64 *v9; // rsi
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
__int64 *v14; // rsi
char result; // al
__int64 v16; // [rsp+6h] [rbp-12h] BYREF
__int16 v17; // [rsp+Eh] [rbp-Ah]

v16 = 0LL;
v17 = 0;
append_user_flags(&v16, 0LL);
if ( (_BYTE)v16 )
return mu_fail("test_append_user_flags: text should be an empty string", 0LL);
LOBYTE(v16) = 0;
append_user_flags(&v16, 1LL);
v2 = "i";
v3 = 2LL;
v4 = &v16;
do
{
if ( !v3 )
break;
v0 = *(_BYTE *)v4 < *v2;
v1 = *(_BYTE *)v4 == *v2;
v4 = (__int64 *)((char *)v4 + 1);
++v2;
--v3;
}
while ( v1 );
if ( (!v0 && !v1) != v0 )
return mu_fail("test_append_user_flags: text should be 'i'", v4);
LOBYTE(v16) = 0;
append_user_flags(&v16, 3LL);
v7 = "iw";
v8 = 3LL;
v9 = &v16;
do
{
if ( !v8 )
break;
v5 = *(_BYTE *)v9 < *v7;
v6 = *(_BYTE *)v9 == *v7;
v9 = (__int64 *)((char *)v9 + 1);
++v7;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) != v5 )
return mu_fail("test_append_user_flags: text should be 'iw'", v9);
LOBYTE(v16) = 0;
append_user_flags(&v16, 0xFFFFLL);
v12 = "iwo";
v13 = 4LL;
v14 = &v16;
do
{
if ( !v13 )
break;
v10 = *(_BYTE *)v14 < *v12;
v11 = *(_BYTE *)v14 == *v12;
v14 = (__int64 *)((char *)v14 + 1);
++v12;
--v13;
}
while ( v11 );
result = (!v10 && !v11) - v10;
if ( result )
result = mu_fail("test_append_user_flags: text should be 'iwo'", v14);
return result;
}

canonical_decompiled_code:
char func4()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
__int64 *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
__int64 *v9; // rsi
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
__int64 *v14; // rsi
char result; // al
__int64 v16; // [rsp+6h] [rbp-12h] BYREF
__int16 v17; // [rsp+Eh] [rbp-Ah]

v16 = 0LL;
v17 = 0;
append_user_flags(&v16, 0LL);
if ( (_BYTE)v16 )
return mu_fail("test_append_user_flags: text should be an empty string", 0LL);
LOBYTE(v16) = 0;
append_user_flags(&v16, 1LL);
v2 = "i";
v3 = 2LL;
v4 = &v16;
do
{
if ( !v3 )
break;
v0 = *(_BYTE *)v4 < *v2;
v1 = *(_BYTE *)v4 == *v2;
v4 = (__int64 *)((char *)v4 + 1);
++v2;
--v3;
}
while ( v1 );
if ( (!v0 && !v1) != v0 )
return mu_fail("test_append_user_flags: text should be 'i'", v4);
LOBYTE(v16) = 0;
append_user_flags(&v16, 3LL);
v7 = "iw";
v8 = 3LL;
v9 = &v16;
do
{
if ( !v8 )
break;
v5 = *(_BYTE *)v9 < *v7;
v6 = *(_BYTE *)v9 == *v7;
v9 = (__int64 *)((char *)v9 + 1);
++v7;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) != v5 )
return mu_fail("test_append_user_flags: text should be 'iw'", v9);
LOBYTE(v16) = 0;
append_user_flags(&v16, 0xFFFFLL);
v12 = "iwo";
v13 = 4LL;
v14 = &v16;
do
{
if ( !v13 )
break;
v10 = *(_BYTE *)v14 < *v12;
v11 = *(_BYTE *)v14 == *v12;
v14 = (__int64 *)((char *)v14 + 1);
++v12;
--v13;
}
while ( v11 );
result = (!v10 && !v11) - v10;
if ( result )
result = mu_fail("test_append_user_flags: text should be 'iwo'", v14);
return result;
}

original_code:
void test_append_user_flags() {
    char text[10] = "";
    append_user_flags(text, 0x0000);
    do { if (!((strcmp(text,"") == 0))) { mu_fail("test_append_user_flags: text should be an empty string"); return; } } while (0);
    *text = '\0';
    append_user_flags(text, USR_INVISIBLE);
    do { if (!((strcmp(text,"i") == 0))) { mu_fail("test_append_user_flags: text should be 'i'"); return; } } while (0);
    *text = '\0';
    append_user_flags(text, USR_WALLOPS | USR_INVISIBLE);
    do { if (!((strcmp(text,"iw") == 0))) { mu_fail("test_append_user_flags: text should be 'iw'"); return; } } while (0);
    *text = '\0';
    append_user_flags(text, 0xFFFF);
    do { if (!((strcmp(text,"iwo") == 0))) { mu_fail("test_append_user_flags: text should be 'iwo'"); return; } } while (0);
}


decompiled_code:
char test_utils()
{
char result; // al

test_upper();
++tests_run;
test_lower();
++tests_run;
test_build_command_key();
++tests_run;
test_append_channel_flags();
++tests_run;
result = test_append_user_flags();
++tests_run;
return result;
}

canonical_decompiled_code:
char func5()
{
char result; // al

func0();
++tests_run;
func1();
++tests_run;
func2();
++tests_run;
func3();
++tests_run;
result = func4();
++tests_run;
return result;
}

original_code:
void test_utils() {
    do { (void)0; test_upper(); tests_run++; } while (0);
    do { (void)0; test_lower(); tests_run++; } while (0);
    do { (void)0; test_build_command_key(); tests_run++; } while (0);
    do { (void)0; test_append_channel_flags(); tests_run++; } while (0);
    do { (void)0; test_append_user_flags(); tests_run++; } while (0);
}


decompiled_code:
void __fastcall __noreturn mock_server(void *a1)
{
int v1; // eax
int v2; // ebx
__int16 v3; // ax
int v4; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr v6; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v3 = atoi("19876");
*(_WORD *)addr.sa_data = _bswap_16(v3);
if ( bind(v2, &addr, 0x10u) != -1 )
{
if ( listen(v2, 1) != -1 )
{
addr_len = 16;
v4 = accept(v2, &v6, &addr_len);
if ( v4 != -1 )
{
close(v2);
close(v4);
pthread_exit(0LL);
}
perror("accept error");
exit(1);
}
perror("listen error");
exit(1);
}
perror("socket binding error");
exit(1);
}
perror("socket creation error");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
int v1; // eax
int v2; // ebx
__int16 v3; // ax
int v4; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr v6; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v3 = atoi("19876");
*(_WORD *)addr.sa_data = func0(v3);
if ( bind(v2, &addr, 0x10u) != -1 )
{
if ( listen(v2, 1) != -1 )
{
addr_len = 16;
v4 = accept(v2, &v6, &addr_len);
if ( v4 != -1 )
{
close(v2);
close(v4);
pthread_exit(0LL);
}
perror("accept error");
exit(1);
}
perror("listen error");
exit(1);
}
perror("socket binding error");
exit(1);
}
perror("socket creation error");
exit(1);
}

original_code:
void* mock_server() {
    int sockfd, newsockfd;
    struct sockaddr_in serv_addr, cli_addr;
    unsigned int clilen;
    if ((sockfd = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("socket creation error");
        exit(1);
    }
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    serv_addr.sin_port = htons(atoi("19876"));
    if (bind(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) == -1) {
         perror("socket binding error");
         exit(1);
    }
    if (listen(sockfd, 1) == -1) {
        perror("listen error");
        exit(1);
    }
    clilen = sizeof(cli_addr);
    if ((newsockfd = accept(sockfd, (struct sockaddr*) &cli_addr, &clilen)) == -1) {
        perror("accept error");
        exit(1);
    }
    close(sockfd);
    close(newsockfd);
    pthread_exit(((void *)0));
}

canonical_original_code:
void *mock_server() {
    int sockfd; int newsockfd;
    struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
    unsigned int clilen;
    if ((sockfd = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("socket creation error");
        exit(1);
    }
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    serv_addr.sin_port = htons(atoi("19876"));
    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
         perror("socket binding error");
         exit(1);
    }
    if (listen(sockfd, 1) == -1) {
        perror("listen error");
        exit(1);
    }
    clilen = sizeof(cli_addr);
    if ((newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen)) == -1) {
        perror("accept error");
        exit(1);
    }
    close(sockfd);
    close(newsockfd);
    pthread_exit(((void *)0));
}

variable_types: sockfd int

variable_types: newsockfd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
clilen
unsigned int

return_type: void *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


decompiled_code:
void __fastcall net_connect(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *i; // rbx
const char *v4; // rax
int v5; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v4 = gai_strerror(v2);
errx(1, "%s", v4);
}
for ( i = pai; i; i = i->ai_next )
{
if ( *(_DWORD *)socket != -1 )
break;
v5 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
*(_DWORD *)socket = v5;
if ( v5 != -1 )
{
if ( connect(v5, i->ai_addr, i->ai_addrlen) == -1 )
{
close(*(int *)socket);
*(_DWORD *)socket = -1;
}
else
{
sd = fdopen(*(int *)socket, "r");
setvbuf(sd, 0LL, 2, 0LL);
}
}
}
freeaddrinfo(pai);
if ( *(_DWORD *)socket == -1 )
errx(1, "Could not connect to: %s:%s\n", a1, a2);
}

canonical_decompiled_code:
void __fastcall func2(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *i; // rbx
const char *v4; // rax
int v5; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v4 = gai_strerror(v2);
errx(1, "%s", v4);
}
for ( i = pai; i; i = i->ai_next )
{
if ( *(_DWORD *)socket != -1 )
break;
v5 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
*(_DWORD *)socket = v5;
if ( v5 != -1 )
{
if ( connect(v5, i->ai_addr, i->ai_addrlen) == -1 )
{
close(*(int *)socket);
*(_DWORD *)socket = -1;
}
else
{
sd = fdopen(*(int *)socket, "r");
setvbuf(sd, 0LL, 2, 0LL);
}
}
}
freeaddrinfo(pai);
if ( *(_DWORD *)socket == -1 )
errx(1, "Could not connect to: %s:%s\n", a1, a2);
}

original_code:
void net_connect(char* address, char* port) {
    struct addrinfo addr_in;
    struct addrinfo *addr_out, *addr;
    int error;
    (void)0;
    memset(&addr_in, 0, sizeof(addr_in));
    addr_in.ai_family = 2;
    addr_in.ai_socktype = SOCK_STREAM;
    error = getaddrinfo(address, port, &addr_in, &addr_out);
    if (error) {
        errx(1, "%s", gai_strerror(error));
    }
    (void)0;
    for (addr = addr_out; addr && _socket == -1; addr = addr->ai_next) {
        if ((_socket = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol)) != -1) {
            if (connect(_socket, addr->ai_addr, addr->ai_addrlen) != -1) {
                _sd = fdopen(_socket, "r");
                setvbuf(_sd, ((void *)0), 2, 0);
            } else {
                close(_socket);
                _socket = -1;
            }
        }
    }
    freeaddrinfo(addr_out);
    if (_socket == -1) {
        errx(1, "Could not connect to: %s:%s\n", address, port);
    }
}

canonical_original_code:
void net_connect(char *address, char *port) {
    struct addrinfo addr_in;
    struct addrinfo *addr_out; struct addrinfo *addr;
    int error;
    (void)0;
    memset(&addr_in, 0, sizeof(addr_in));
    addr_in.ai_family = 2;
    addr_in.ai_socktype = SOCK_STREAM;
    error = getaddrinfo(address, port, &addr_in, &addr_out);
    if (error) {
        errx(1, "%s", gai_strerror(error));
    }
    (void)0;
    for (addr = addr_out; addr && _socket == -1; addr = addr->ai_next) {
        if ((_socket = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol)) != -1) {
            if (connect(_socket, addr->ai_addr, addr->ai_addrlen) != -1) {
                _sd = fdopen(_socket, "r");
                setvbuf(_sd, ((void *)0), 2, 0);
            } else {
                close(_socket);
                _socket = -1;
            }
        }
    }
    freeaddrinfo(addr_out);
    if (_socket == -1) {
        errx(1, "Could not connect to: %s:%s\n", address, port);
    }
}

variable_types:
address
char *

variable_types:
port
char *

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

variable_types: error int

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


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

result = close(*(int *)socket);
*(_DWORD *)socket = -1;
sd = 0LL;
return result;
}

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

result = close(*(int *)socket);
*(_DWORD *)socket = -1;
sd = 0LL;
return result;
}

original_code:
void net_disconnect() {
    (void)0;
    close(_socket);
    _socket = -1;
    _sd = ((void *)0);
}


decompiled_code:
ssize_t __fastcall net_send(char *src)
{
size_t v1; // rax
char v3[536]; // [rsp+0h] [rbp-218h] BYREF

strncpy(v3, src, 0x1FDuLL);
v3[509] = 0;
strcat(v3, "\r\n");
printf(">> %s", v3);
v1 = strlen(v3);
return send(*(int *)socket, v3, v1, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func4(char *src)
{
size_t v1; // rax
char v3[536]; // [rsp+0h] [rbp-218h] BYREF

strncpy(v3, src, 0x1FDuLL);
v3[509] = 0;
strcat(v3, "\r\n");
printf(">> %s", v3);
v1 = strlen(v3);
return send(*(int *)socket, v3, v1, 0);
}

original_code:
int net_send(char* msg) {
    char out[(512 + 1)];
    strncpy(out, msg, (512 - 3));
    out[(512 - 3)]= '\0';
    strcat(out, "\r\n");
    printf(">> %s", out);
    return send(_socket, out, strlen(out), 0);
}

canonical_original_code:
int net_send(char *msg) {
    char out[-1];
    strncpy(out, msg, (512 - 3));
    out[(512 - 3)]= '\0';
    strcat(out, "\r\n");
    printf(">> %s", out);
    return send(_socket, out, strlen(out), 0);
}

variable_types:
msg
char *

variable_types:
out
char [-1]

return_type: int


decompiled_code:
int __fastcall net_recv(char *a1)
{
char *v1; // rax

v1 = fgets(a1, 513, sd);
a1[512] = 0;
if ( !v1 )
{
perror("Error reading from socket");
exit(1);
}
return printf("<< %s", a1);
}

canonical_decompiled_code:
int __fastcall func5(char *a1)
{
char *v1; // rax

v1 = fgets(a1, 513, sd);
a1[512] = 0;
if ( !v1 )
{
perror("Error reading from socket");
exit(1);
}
return printf("<< %s", a1);
}

original_code:
void net_recv(char* msg) {
    char* ret;
    ret = fgets(msg, (512 + 1), _sd);
    msg[(512 + 1) - 1] = '\0';
    if (ret == ((void *)0)) {
        perror("Error reading from socket");
        exit(1);
    }
    printf("<< %s", msg);
}

canonical_original_code:
void net_recv(char *msg) {
    char *ret;
    ret = fgets(msg, (512 + 1), _sd);
    msg[(512 + 1) - 1] = '\0';
    if (ret == ((void *)0)) {
        perror("Error reading from socket");
        exit(1);
    }
    printf("<< %s", msg);
}

variable_types:
ret
char *


decompiled_code:
__int64 net_listen()
{
int v0; // edi
int v1; // eax
unsigned int v2; // edx
fd_set v4; // [rsp+0h] [rbp-88h] BYREF

memset(&v4, 0, sizeof(v4));
v0 = *(_DWORD *)socket;
v4.fds_bits[*(_DWORD *)socket / 64] |= 1LL << (*(_DWORD *)socket % 64);
v1 = select(v0 + 1, &v4, 0LL, 0LL, 0LL);
if ( v1 < 0 )
return (unsigned int)((*_errno_location() == 4) + 1);
v2 = 3;
if ( v1 > 0 )
v2 = (v4.fds_bits[*(_DWORD *)socket / 64] & (1LL << (*(_DWORD *)socket % 64))) == 0 ? 3 : 0;
return v2;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // edi
int v1; // eax
unsigned int v2; // edx
fd_set v4; // [rsp+0h] [rbp-88h] BYREF

memset(&v4, 0, sizeof(v4));
v0 = *(_DWORD *)socket;
v4.fds_bits[*(_DWORD *)socket / 64] |= 1LL << (*(_DWORD *)socket % 64);
v1 = select(v0 + 1, &v4, 0LL, 0LL, 0LL);
if ( v1 < 0 )
return (unsigned int)((*_errno_location() == 4) + 1);
v2 = 3;
if ( v1 > 0 )
v2 = (v4.fds_bits[*(_DWORD *)socket / 64] & (1LL << (*(_DWORD *)socket % 64))) == 0 ? 3 : 0;
return v2;
}

original_code:
enum net_status net_listen() {
    int read, ret;
    fd_set read_fd_set;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_fd_set)->__fds_bits)[((_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_socket) % (8 * (int) sizeof (__fd_mask)))))));
    (void)0;
    read = select(_socket + 1, &read_fd_set, ((void *)0), ((void *)0), ((void *)0));
    if (read < 0) {
        (void)0;
        ret = ((*__errno_location ()) == 4)? NET_CLOSE : NET_ERROR;
    } else if (read > 0 && ((((&read_fd_set)->__fds_bits)[((_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        ret = NET_READY;
    } else {
        (void)0;
        ret = NET_TIMEOUT;
    }
    return ret;
}

canonical_original_code:
enum net_status net_listen() {
    int read; int ret;
    struct fd_set read_fd_set;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_fd_set)->__fds_bits)[((_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_socket) % (8 * (int) sizeof (__fd_mask)))))));
    (void)0;
    read = select(_socket + 1, &read_fd_set, ((void *)0), ((void *)0), ((void *)0));
    if (read < 0) {
        (void)0;
        ret = ((*__errno_location ()) == 4)? NET_CLOSE : NET_ERROR;
    } else if (read > 0 && ((((&read_fd_set)->__fds_bits)[((_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        ret = NET_READY;
    } else {
        (void)0;
        ret = NET_TIMEOUT;
    }
    return ret;
}

variable_types: read int

variable_types: ret int

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


decompiled_code:
void mock_handler()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void mock_handler(int signal) {
}

canonical_original_code:
void mock_handler(int signal) {
}

variable_types: signal int


decompiled_code:
int test_connection()
{
int result; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, (void *(*)(void *))mock_server, 0LL);
poll(0LL, 0LL, 1000);
net_connect("localhost", "19876");
if ( *(int *)socket <= 0 )
return mu_fail("test_connection: _socket should be > 0");
if ( !sd )
return mu_fail("test_connection: _sd should not be NULL");
result = net_disconnect();
if ( *(_DWORD *)socket != -1 )
return mu_fail("test_connection: _socket should be -1");
if ( sd )
result = mu_fail("test_connection: _sd should be NULL");
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, (void *(*)(void *))mock_server, 0LL);
poll(0LL, 0LL, 1000);
func2("localhost", "19876");
if ( *(int *)socket <= 0 )
return mu_fail("test_connection: _socket should be > 0");
if ( !sd )
return mu_fail("test_connection: _sd should not be NULL");
result = func3();
if ( *(_DWORD *)socket != -1 )
return mu_fail("test_connection: _socket should be -1");
if ( sd )
result = mu_fail("test_connection: _sd should be NULL");
return result;
}

original_code:
void test_connection() {
    pthread_t thread;
    pthread_create(&thread, ((void *)0), mock_server, ((void *)0));
    poll(0, 0, 1000);
    net_connect("localhost", "19876");
    do { if (!(_socket > 0)) { mu_fail("test_connection: _socket should be > 0"); return; } } while (0);
    do { if (!(_sd != ((void *)0))) { mu_fail("test_connection: _sd should not be NULL"); return; } } while (0);
    net_disconnect();
    do { if (!(_socket == -1)) { mu_fail("test_connection: _socket should be -1"); return; } } while (0);
    do { if (!(_sd == ((void *)0))) { mu_fail("test_connection: _sd should be NULL"); return; } } while (0);
}

canonical_original_code:
void test_connection() {
    unsigned long thread;
    pthread_create(&thread, ((void *)0), mock_server, ((void *)0));
    poll(0, 0, 1000);
    net_connect("localhost", "19876");
    do { if (!(_socket > 0)) { mu_fail("test_connection: _socket should be > 0"); return; } } while (0);
    do { if (!(_sd != ((void *)0))) { mu_fail("test_connection: _sd should not be NULL"); return; } } while (0);
    net_disconnect();
    do { if (!(_socket == -1)) { mu_fail("test_connection: _socket should be -1"); return; } } while (0);
    do { if (!(_sd == ((void *)0))) { mu_fail("test_connection: _sd should be NULL"); return; } } while (0);
}

variable_types:
thread
unsigned long


decompiled_code:
char test_recv()
{
bool v0; // zf
char result; // al
char v2[520]; // [rsp+0h] [rbp-218h] BYREF
int fds[2]; // [rsp+208h] [rbp-10h] BYREF

if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair error");
exit(1);
}
sd = fdopen(fds[1], "r");
send(fds[0], "Outgoing message\r\n", 0x12uLL, 0);
net_recv(v2);
close(fds[0]);
close(fds[1]);
v0 = strcmp(v2, "Outgoing message\r\n") == 0;
result = !v0;
if ( !v0 )
result = mu_fail("test_recv: Message should be 'Outgoing message\\r\\n'");
return result;
}

canonical_decompiled_code:
char func11()
{
bool v0; // zf
char result; // al
char v2[520]; // [rsp+0h] [rbp-218h] BYREF
int fds[2]; // [rsp+208h] [rbp-10h] BYREF

if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair error");
exit(1);
}
sd = fdopen(fds[1], "r");
send(fds[0], "Outgoing message\r\n", 0x12uLL, 0);
func5(v2);
close(fds[0]);
close(fds[1]);
v0 = strcmp(v2, "Outgoing message\r\n") == 0;
result = !v0;
if ( !v0 )
result = mu_fail("test_recv: Message should be 'Outgoing message\\r\\n'");
return result;
}

original_code:
void test_recv() {
    int socks[2];
    char msg[(512 + 1)];
    if (socketpair(1, SOCK_STREAM, 0, socks) == -1) {
        perror("socketpair error");
        exit(1);
    }
    _sd = fdopen(socks[1], "r");
    send(socks[0], "Outgoing message\r\n", strlen("Outgoing message\r\n"), 0);
    net_recv(msg);
    close(socks[0]);
    close(socks[1]);
    do { if (!((strcmp(msg,"Outgoing message\r\n") == 0))) { mu_fail("test_recv: Message should be 'Outgoing message\\r\\n'"); return; } } while (0);
}

canonical_original_code:
void test_recv() {
    int socks[2];
    char msg[-1];
    if (socketpair(1, SOCK_STREAM, 0, socks) == -1) {
        perror("socketpair error");
        exit(1);
    }
    _sd = fdopen(socks[1], "r");
    send(socks[0], "Outgoing message\r\n", strlen("Outgoing message\r\n"), 0);
    net_recv(msg);
    close(socks[0]);
    close(socks[1]);
    do { if (!((strcmp(msg,"Outgoing message\r\n") == 0))) { mu_fail("test_recv: Message should be 'Outgoing message\\r\\n'"); return; } } while (0);
}

variable_types:
socks
int [2]

variable_types:
msg
char [-1]


decompiled_code:
size_t test_recv_longer()
{
size_t v0; // rax
size_t v1; // rbx
size_t result; // rax
char v3[528]; // [rsp+0h] [rbp-438h] BYREF
char s[536]; // [rsp+210h] [rbp-228h] BYREF
int fds[2]; // [rsp+428h] [rbp-10h] BYREF

if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair error");
exit(1);
}
strcpy(
v3,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
sd = fdopen(fds[1], "r");
v0 = strlen(v3);
send(fds[0], v3, v0, 0);
net_recv(s);
close(fds[0]);
close(fds[1]);
v1 = strlen(v3);
result = strlen(s);
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; // rbx
size_t result; // rax
char v3[528]; // [rsp+0h] [rbp-438h] BYREF
char s[536]; // [rsp+210h] [rbp-228h] BYREF
int fds[2]; // [rsp+428h] [rbp-10h] BYREF

if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair error");
exit(1);
}
strcpy(
v3,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
sd = fdopen(fds[1], "r");
v0 = strlen(v3);
send(fds[0], v3, v0, 0);
func5(s);
close(fds[0]);
close(fds[1]);
v1 = strlen(v3);
result = strlen(s);
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]


decompiled_code:
int test_listen_ready()
{
int result; // eax
int buf; // [rsp+Ch] [rbp-1Ch] BYREF
int v2[2]; // [rsp+10h] [rbp-18h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-10h] BYREF

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

canonical_decompiled_code:
int func13()
{
int result; // eax
int buf; // [rsp+Ch] [rbp-1Ch] BYREF
int v2[2]; // [rsp+10h] [rbp-18h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-10h] BYREF

if ( pipe(pipedes) == -1 )
{
perror("pipe error");
exit(1);
}
if ( pipe(v2) == -1 )
{
perror("pipe error");
exit(1);
}
if ( fork() <= 0 )
{
close(pipedes[1]);
close(v2[0]);
*(_DWORD *)socket = pipedes[0];
buf = func6();
if ( write(v2[1], &buf, 4uLL) != -1 )
{
close(pipedes[0]);
close(v2[1]);
exit(0);
}
perror("write error");
exit(1);
}
close(pipedes[0]);
close(v2[1]);
poll(0LL, 0LL, 1000);
if ( write(pipedes[1], "test", 4uLL) == -1 )
{
perror("write error");
exit(1);
}
if ( read(v2[0], &buf, 4uLL) == -1 )
{
perror("write error");
exit(1);
}
close(pipedes[1]);
result = close(v2[0]);
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 }


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

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

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: struct raw_event { struct timeval timestamp; char *__buffer; char *type; char *prefix; int num_params; char *params[15]; }

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; // rbp
void *v4; // 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;
if ( !v3 )
{
perror("Out of memory (consumer_create: lock)");
exit(1);
}
v4 = malloc(0x30uLL);
*((_QWORD *)v1 + 2) = v4;
if ( !v4 )
{
perror("Out of memory (consumer_create: ready)");
exit(1);
}
*((_DWORD *)v1 + 6) = 0;
pthread_mutex_init(v3, 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; // rbp
void *v4; // 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;
if ( !v3 )
{
perror("Out of memory (consumer_create: lock)");
exit(1);
}
v4 = malloc(0x30uLL);
*((_QWORD *)v1 + 2) = v4;
if ( !v4 )
{
perror("Out of memory (consumer_create: ready)");
exit(1);
}
*((_DWORD *)v1 + 6) = 0;
pthread_mutex_init(v3, 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 func3()
{
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

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

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
_QWORD *v1; // rax
void *v2; // rdx

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

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 func5()
{
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; // rbx
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 func6()
{
pthread_cond_t **v0; // rax
void *v1; // rbx
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 *