decompiled_code:
__int64 __fastcall enlarge_map(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbp
unsigned int v3; // er13
__int64 v4; // rax
_QWORD *v5; // rbx
__int64 result; // rax

v1 = create_hashmap(*(_DWORD *)(a1 + 24), 2LL * *(_QWORD *)a1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = (_QWORD *)v1;
if ( *(_QWORD *)a1 )
{
v3 = 0;
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*(_QWORD *)(a1 + 16) + 16 * v4);
if ( v5 )
break;
LABEL_7:
v4 = ++v3;
if ( (unsigned __int64)v3 >= *(_QWORD *)a1 )
goto LABEL_8;
}
while ( (int)hmap_set(v2, v5[2], v5[3], v5[4]) >= 0 )
{
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_7;
}
bbus_hmap_free(v2);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_8:
bbus_hmap_reset((_QWORD *)a1);
bbus_free(*(_QWORD *)(a1 + 16));
*(_QWORD *)a1 = *v2;
*(_QWORD *)(a1 + 8) = v2[1];
*(_QWORD *)(a1 + 16) = v2[2];
bbus_free(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbp
unsigned int v3; // er13
__int64 v4; // rax
_QWORD *v5; // rbx
__int64 result; // rax

v1 = func1(*(_DWORD *)(a1 + 24), 2LL * *(_QWORD *)a1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = (_QWORD *)v1;
if ( *(_QWORD *)a1 )
{
v3 = 0;
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*(_QWORD *)(a1 + 16) + 16 * v4);
if ( v5 )
break;
LABEL_7:
v4 = ++v3;
if ( (unsigned __int64)v3 >= *(_QWORD *)a1 )
goto LABEL_8;
}
while ( (int)func7(v2, v5[2], v5[3], v5[4]) >= 0 )
{
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_7;
}
func5(v2);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_8:
func4((_QWORD *)a1);
bbus_free(*(_QWORD *)(a1 + 16));
*(_QWORD *)a1 = *v2;
*(_QWORD *)(a1 + 8) = v2[1];
*(_QWORD *)(a1 + 16) = v2[2];
bbus_free(v2);
result = 0LL;
}
return result;
}

original_code:
static int enlarge_map(bbus_hashmap* hmap)
{
 bbus_hashmap* newmap;
 struct map_entry* el;
 unsigned i;
 int r;
 newmap = create_hashmap(hmap->type, hmap->size * 2);
 if (newmap == ((void *)0))
  return -1;
 for (i = 0; i < hmap->size; ++i) {
  for (el = hmap->buckets[i].head; el != ((void *)0); el = el->next) {
   r = hmap_set(newmap, el->key, el->ksize, el->val);
   if (r < 0) {
    bbus_hmap_free(newmap);
    return -1;
   }
  }
 }
 bbus_hmap_reset(hmap);
 bbus_free(hmap->buckets);
 hmap->size = newmap->size;
 hmap->numstored = newmap->numstored;
 hmap->buckets = newmap->buckets;
 bbus_free(newmap);
 return 0;
}

canonical_original_code:
static int enlarge_map(struct __bbus_hashmap *hmap)
{
 struct __bbus_hashmap *newmap;
 struct map_entry *el;
 unsigned int i;
 int r;
 newmap = create_hashmap(hmap->type, hmap->size * 2);
 if (newmap == ((void *)0))
  return -1;
 for (i = 0; i < hmap->size; ++i) {
  for (el = hmap->buckets[i].head; el != ((void *)0); el = el->next) {
   r = hmap_set(newmap, el->key, el->ksize, el->val);
   if (r < 0) {
    bbus_hmap_free(newmap);
    return -1;
   }
  }
 }
 bbus_hmap_reset(hmap);
 bbus_free(hmap->buckets);
 hmap->size = newmap->size;
 hmap->numstored = newmap->numstored;
 hmap->buckets = newmap->buckets;
 bbus_free(newmap);
 return 0;
}


decompiled_code:
__int64 __fastcall bbus_hmap_setstr(__int64 a1, const char *a2, __int64 *a3)
{
size_t v4; // rax
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) == 2 )
{
v4 = strlen(a2);
result = hmap_set((_QWORD *)a1, a2, v4, a3);
}
else
{
_bbus_seterr(10017LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, __int64 *a3)
{
size_t v4; // rax
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) == 2 )
{
v4 = strlen(a2);
result = func7((_QWORD *)a1, a2, v4, a3);
}
else
{
_bbus_seterr(10017LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int bbus_hmap_setstr(bbus_hashmap* hmap, const char* key, void* val)
{
 do { if ((hmap)->type != (BBUS_HMAP_KEYSTR)) { __bbus_seterr(10017); return (-1); } } while (0);
 return hmap_set(hmap, key, strlen(key), val);
}

canonical_original_code:
int bbus_hmap_setstr(struct __bbus_hashmap *hmap, char *key, void *val)
{
 do { if ((hmap)->type != (BBUS_HMAP_KEYSTR)) { __bbus_seterr(10017); return (-1); } } while (0);
 return hmap_set(hmap, key, strlen(key), val);
}

variable_types: struct __bbus_hashmap { unsigned long size; unsigned long numstored; struct entry_list { struct map_entry { struct map_entry *next; struct map_entry *prev; void *key; unsigned long ksize; void *val; } *head; struct map_entry *tail; } *buckets; enum bbus_hmap_type { BBUS_HMAP_KEYUINT=1, BBUS_HMAP_KEYSTR=2 } type; } *

variable_types:
key
char *

variable_types:
val
void *

return_type: int

user_defined_types: struct __bbus_hashmap { unsigned long size; unsigned long numstored; struct entry_list *buckets; enum bbus_hmap_type type; }

user_defined_types: struct entry_list { struct map_entry *head; struct map_entry *tail; }


decompiled_code:
__int64 __fastcall bbus_hmap_setuint(__int64 a1, int a2, __int64 *a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a2;
if ( *(_DWORD *)(a1 + 24) == 1 )
return hmap_set((_QWORD *)a1, v4, 4uLL, a3);
_bbus_seterr(10017LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, __int64 *a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a2;
if ( *(_DWORD *)(a1 + 24) == 1 )
return func7((_QWORD *)a1, v4, 4uLL, a3);
_bbus_seterr(10017LL);
return 0xFFFFFFFFLL;
}

original_code:
int bbus_hmap_setuint(bbus_hashmap* hmap, unsigned key, void* val)
{
 do { if ((hmap)->type != (BBUS_HMAP_KEYUINT)) { __bbus_seterr(10017); return (-1); } } while (0);
 return hmap_set(hmap, &key, sizeof(unsigned), val);
}

canonical_original_code:
int bbus_hmap_setuint(struct __bbus_hashmap *hmap, unsigned int key, void *val)
{
 do { if ((hmap)->type != (BBUS_HMAP_KEYUINT)) { __bbus_seterr(10017); return (-1); } } while (0);
 return hmap_set(hmap, &key, sizeof(unsigned int), val);
}

variable_types:
key
unsigned int

user_defined_types: enum bbus_hmap_type { BBUS_HMAP_KEYUINT=1, BBUS_HMAP_KEYSTR=2 }

user_defined_types: struct map_entry { struct map_entry *next; struct map_entry *prev; void *key; unsigned long ksize; void *val; }


decompiled_code:
__int64 __fastcall bbus_hmap_dump(unsigned int *a1, char *a2, size_t a3)
{
__int64 v3; // rbx
__int64 v4; // rbx
const char *v5; // r8
__int64 **v6; // rbx
const char *v7; // rbp
const char *v8; // rax
unsigned int v10; // [rsp+Ch] [rbp-44Ch]
size_t v11; // [rsp+10h] [rbp-448h] BYREF
char *v12; // [rsp+18h] [rbp-440h] BYREF

v12 = a2;
v11 = a3;
memset(a2, 0, a3);
if ( (int)dump_append(&v12, &v11, "Hashmap size: %u, objects stored: %u\n", *a1, a1[2]) < 0 )
return 0xFFFFFFFFLL;
if ( !*(_QWORD *)a1 )
return 0LL;
v10 = 0;
v3 = 0LL;
while ( 1 )
{
v4 = 16 * v3;
v5 = (const char *)&LC1;
if ( !*(_QWORD *)(*((_QWORD *)a1 + 2) + v4) )
v5 = (const char *)&LC0;
if ( (int)dump_append(&v12, &v11, "Bucket nr %u:\n%s", v10, v5) < 0 )
return 0xFFFFFFFFLL;
v6 = *(__int64 ***)(*((_QWORD *)a1 + 2) + v4);
if ( v6 )
break;
LABEL_12:
v3 = ++v10;
if ( (unsigned __int64)v10 >= *(_QWORD *)a1 )
return 0LL;
}
while ( 1 )
{
v7 = (const char *)&LC0;
if ( !*v6 )
v7 = (const char *)&LC2;
v8 = (const char *)keyrepr((__int64)v6[2]);
if ( (int)dump_append(&v12, &v11, " [\"%s\"]->[0x%p] |%s", v8, v6[4], v7) < 0 )
return 0xFFFFFFFFLL;
v6 = (__int64 **)*v6;
if ( !v6 )
goto LABEL_12;
}
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, char *a2, size_t a3)
{
__int64 v3; // rbx
__int64 v4; // rbx
const char *v5; // r8
__int64 **v6; // rbx
const char *v7; // rbp
const char *v8; // rax
unsigned int v10; // [rsp+Ch] [rbp-44Ch]
size_t v11; // [rsp+10h] [rbp-448h] BYREF
char *v12; // [rsp+18h] [rbp-440h] BYREF

v12 = a2;
v11 = a3;
memset(a2, 0, a3);
if ( (int)func2(&v12, &v11, "Hashmap size: %u, objects stored: %u\n", *a1, a1[2]) < 0 )
return 0xFFFFFFFFLL;
if ( !*(_QWORD *)a1 )
return 0LL;
v10 = 0;
v3 = 0LL;
while ( 1 )
{
v4 = 16 * v3;
v5 = (const char *)&LC1;
if ( !*(_QWORD *)(*((_QWORD *)a1 + 2) + v4) )
v5 = (const char *)&LC0;
if ( (int)func2(&v12, &v11, "Bucket nr %u:\n%s", v10, v5) < 0 )
return 0xFFFFFFFFLL;
v6 = *(__int64 ***)(*((_QWORD *)a1 + 2) + v4);
if ( v6 )
break;
LABEL_12:
v3 = ++v10;
if ( (unsigned __int64)v10 >= *(_QWORD *)a1 )
return 0LL;
}
while ( 1 )
{
v7 = (const char *)&LC0;
if ( !*v6 )
v7 = (const char *)&LC2;
v8 = (const char *)func0((__int64)v6[2]);
if ( (int)func2(&v12, &v11, " [\"%s\"]->[0x%p] |%s", v8, v6[4], v7) < 0 )
return 0xFFFFFFFFLL;
v6 = (__int64 **)*v6;
if ( !v6 )
goto LABEL_12;
}
}

original_code:
int bbus_hmap_dump(bbus_hashmap* hmap, char* buf, size_t bufsize)
{
 unsigned i;
 int r;
 struct map_entry* el;
 char reprbuf[1024];
 memset(buf, 0, bufsize);
 r = dump_append(&buf, &bufsize,
   "Hashmap size: %u, objects stored: %u\n",
   (unsigned)hmap->size, (unsigned)hmap->numstored);
 if (r < 0)
  return -1;
 for (i = 0; i < hmap->size; ++i) {
  r = dump_append(&buf, &bufsize, "Bucket nr %u:\n%s", i,
    hmap->buckets[i].head == ((void *)0) ? "" : "| ");
  if (r < 0)
   return -1;
  el = hmap->buckets[i].head;
  while (el != ((void *)0)) {
   r = dump_append(&buf, &bufsize,
    " [\"%s\"]->[0x%p] |%s",
    keyrepr(el->key, el->ksize, reprbuf,
      sizeof(reprbuf)),
    el->val,
    el->next == ((void *)0) ? "\n" : "");
   if (r < 0)
    return -1;
   el = el->next;
  }
 }
 return 0;
}

canonical_original_code:
int bbus_hmap_dump(struct __bbus_hashmap *hmap, char *buf, unsigned long bufsize)
{
 unsigned int i;
 int r;
 struct map_entry *el;
 char reprbuf[1024];
 memset(buf, 0, bufsize);
 r = dump_append(&buf, &bufsize,
   "Hashmap size: %u, objects stored: %u\n",
   (unsigned int)hmap->size, (unsigned int)hmap->numstored);
 if (r < 0)
  return -1;
 for (i = 0; i < hmap->size; ++i) {
  r = dump_append(&buf, &bufsize, "Bucket nr %u:\n%s", i,
    hmap->buckets[i].head == ((void *)0) ? "" : "| ");
  if (r < 0)
   return -1;
  el = hmap->buckets[i].head;
  while (el != ((void *)0)) {
   r = dump_append(&buf, &bufsize,
    " [\"%s\"]->[0x%p] |%s",
    keyrepr(el->key, el->ksize, reprbuf,
      sizeof(reprbuf)),
    el->val,
    el->next == ((void *)0) ? "\n" : "");
   if (r < 0)
    return -1;
   el = el->next;
  }
 }
 return 0;
}

variable_types:
buf
char *

variable_types:
bufsize
unsigned long

variable_types:
i
unsigned int

variable_types: r int

variable_types: struct map_entry { struct map_entry *next; struct map_entry *prev; void *key; unsigned long ksize; void *val; } *

variable_types:
reprbuf
char [1024]


decompiled_code:
void __fastcall update_highsock(__int64 a1, int a2)
{
if ( *(_DWORD *)(a1 + 128) <= a2 )
*(_DWORD *)(a1 + 128) = a2 + 1;
}

original_code:
static inline void update_highsock(bbus_pollset* pset, int sock)
{
 if (pset->highsock < (sock+1))
  pset->highsock = sock+1;
}

canonical_original_code:
static inline void update_highsock(struct __bbus_pollset *pset, int sock)
{
 if (pset->highsock < (sock+1))
  pset->highsock = sock+1;
}

variable_types: struct __bbus_pollset { struct fd_set { long fds_bits[-1]; } fdset; int highsock; } *

variable_types: sock int

return_type: void

user_defined_types: struct __bbus_pollset { struct fd_set fdset; int highsock; }


decompiled_code:
__int64 __fastcall bbus_client_gettoken(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
uint32_t bbus_client_gettoken(bbus_client* cli)
{
 return cli->token;
}

canonical_original_code:
unsigned int bbus_client_gettoken(struct __bbus_client *cli)
{
 return cli->token;
}

variable_types: struct __bbus_client { int sock; int type; unsigned int token; struct bbus_client_cred { int pid; unsigned int uid; unsigned int gid; } cred; char *name; } *

return_type: unsigned int

user_defined_types: struct __bbus_client { int sock; int type; unsigned int token; struct bbus_client_cred cred; char *name; }


decompiled_code:
void __fastcall bbus_client_settoken(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 8) = a2;
}

original_code:
void bbus_client_settoken(bbus_client* cli, uint32_t tok)
{
 cli->token = tok;
}

canonical_original_code:
void bbus_client_settoken(struct __bbus_client *cli, unsigned int tok)
{
 cli->token = tok;
}

variable_types:
tok
unsigned int

user_defined_types: struct bbus_client_cred { int pid; unsigned int uid; unsigned int gid; }


decompiled_code:
__int64 __fastcall bbus_client_gettype(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

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

original_code:
int bbus_client_gettype(bbus_client* cli)
{
 return cli->type;
}

canonical_original_code:
int bbus_client_gettype(struct __bbus_client *cli)
{
 return cli->type;
}


decompiled_code:
__int64 __fastcall bbus_client_getname(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

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

original_code:
const char* bbus_client_getname(bbus_client* cli)
{
 return cli->name;
}

canonical_original_code:
char *bbus_client_getname(struct __bbus_client *cli)
{
 return cli->name;
}

return_type: char *


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

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

original_code:
int bbus_client_rcvmsg(bbus_client* cli,
    struct bbus_msg* buf, size_t bufsize)
{
 return __bbus_prot_recvmsg(cli->sock, buf, bufsize);
}

canonical_original_code:
int bbus_client_rcvmsg(struct __bbus_client *cli, struct bbus_msg *buf, unsigned long bufsize)
{
 return __bbus_prot_recvmsg(cli->sock, buf, bufsize);
}

variable_types: struct bbus_msg { struct bbus_msg_hdr { unsigned short magic; unsigned char msgtype; unsigned char sotype; unsigned char errcode; unsigned int token; unsigned short psize; unsigned char flags; } hdr; char payload[1]; } *

user_defined_types: struct bbus_msg { struct bbus_msg_hdr hdr; char payload[1]; }


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

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

original_code:
int bbus_client_close(bbus_client* cli)
{
 return __bbus_sock_close(cli->sock);
}

canonical_original_code:
int bbus_client_close(struct __bbus_client *cli)
{
 return __bbus_sock_close(cli->sock);
}


decompiled_code:
__int64 __fastcall bbus_client_free(__int64 a1)
{
bbus_str_free(*(_QWORD *)(a1 + 24));
return bbus_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
bbus_str_free(*(_QWORD *)(a1 + 24));
return bbus_free(a1);
}

original_code:
void bbus_client_free(bbus_client* cli)
{
 bbus_str_free(cli->name);
 bbus_free(cli);
}

canonical_original_code:
void bbus_client_free(struct __bbus_client *cli)
{
 bbus_str_free(cli->name);
 bbus_free(cli);
}


decompiled_code:
int *bbus_srv_create()
{
int v0; // ebx
__int64 v1; // rax
int *result; // rax

v0 = _bbus_sock_un_mksocket();
if ( v0 >= 0
&& (v1 = bbus_prot_getsockpath(), (int)_bbus_sock_un_bind((unsigned int)v0, v1) >= 0)
&& (result = (int *)bbus_malloc(4LL)) != 0LL )
{
*result = v0;
}
else
{
_bbus_sock_close((unsigned int)v0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
int *func9()
{
int v0; // ebx
__int64 v1; // rax
int *result; // rax

v0 = _bbus_sock_un_mksocket();
if ( v0 >= 0
&& (v1 = bbus_prot_getsockpath(), (int)_bbus_sock_un_bind((unsigned int)v0, v1) >= 0)
&& (result = (int *)bbus_malloc(4LL)) != 0LL )
{
*result = v0;
}
else
{
_bbus_sock_close((unsigned int)v0);
result = 0LL;
}
return result;
}

original_code:
bbus_server* bbus_srv_create(void)
{
 bbus_server* srv;
 int sock;
 int ret;
 sock = __bbus_sock_un_mksocket();
 if (sock < 0)
  goto err;
 ret = __bbus_sock_un_bind(sock, bbus_prot_getsockpath());
 if (ret < 0)
  goto err;
 srv = bbus_malloc(sizeof(struct __bbus_server));
 if (srv == ((void *)0))
  goto err;
 srv->sock = sock;
 return srv;
err:
 __bbus_sock_close(sock);
 return ((void *)0);
}

canonical_original_code:
struct __bbus_server *bbus_srv_create()
{
 struct __bbus_server *srv;
 int sock;
 int ret;
 sock = __bbus_sock_un_mksocket();
 if (sock < 0)
  goto err;
 ret = __bbus_sock_un_bind(sock, bbus_prot_getsockpath());
 if (ret < 0)
  goto err;
 srv = bbus_malloc(sizeof(struct __bbus_server));
 if (srv == ((void *)0))
  goto err;
 srv->sock = sock;
 return srv;
err:
 __bbus_sock_close(sock);
 return ((void *)0);
}

variable_types:
srv
struct __bbus_server { int sock; } *

variable_types: ret int

return_type: struct __bbus_server { int sock; } *


decompiled_code:
__int64 __fastcall bbus_srv_listen(unsigned int *a1)
{
return _bbus_sock_listen(*a1, 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
return _bbus_sock_listen(*a1, 5LL);
}

original_code:
int bbus_srv_listen(bbus_server* srv)
{
 return __bbus_sock_listen(srv->sock, 5);
}

canonical_original_code:
int bbus_srv_listen(struct __bbus_server *srv)
{
 return __bbus_sock_listen(srv->sock, 5);
}


decompiled_code:
__int64 __fastcall bbus_srv_clientpending(unsigned int *a1)
{
__int64 v2[3]; // [rsp+0h] [rbp-18h] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
return _bbus_sock_rdready(*a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1)
{
__int64 v2[3]; // [rsp+0h] [rbp-18h] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
return _bbus_sock_rdready(*a1, v2);
}

original_code:
int bbus_srv_clientpending(bbus_server* srv)
{
 struct bbus_timeval tv;
 memset(&tv, 0, sizeof(struct bbus_timeval));
 tv.sec = 0;
 tv.usec = 0;
 return __bbus_sock_rdready(srv->sock, &tv);
}

canonical_original_code:
int bbus_srv_clientpending(struct __bbus_server *srv)
{
 struct bbus_timeval tv;
 memset(&tv, 0, sizeof(struct bbus_timeval));
 tv.sec = 0;
 tv.usec = 0;
 return __bbus_sock_rdready(srv->sock, &tv);
}

variable_types: struct bbus_timeval { long sec; long usec; }


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

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

original_code:
int bbus_srv_close(bbus_server* srv)
{
 return __bbus_sock_close(srv->sock);
}

canonical_original_code:
int bbus_srv_close(struct __bbus_server *srv)
{
 return __bbus_sock_close(srv->sock);
}


decompiled_code:
_DWORD *bbus_pollset_make()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = (_DWORD *)bbus_malloc0(136LL);
v1 = v0;
if ( v0 )
bbus_pollset_clear(v0);
return v1;
}

canonical_decompiled_code:
_DWORD *func16()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = (_DWORD *)bbus_malloc0(136LL);
v1 = v0;
if ( v0 )
func15(v0);
return v1;
}

original_code:
bbus_pollset* bbus_pollset_make(void)
{
 bbus_pollset* pset;
 pset = bbus_malloc0(sizeof(struct __bbus_pollset));
 if (pset == ((void *)0))
  return ((void *)0);
 bbus_pollset_clear(pset);
 return pset;
}

canonical_original_code:
struct __bbus_pollset *bbus_pollset_make()
{
 struct __bbus_pollset *pset;
 pset = bbus_malloc0(sizeof(struct __bbus_pollset));
 if (pset == ((void *)0))
  return ((void *)0);
 bbus_pollset_clear(pset);
 return pset;
}

return_type: struct __bbus_pollset { struct fd_set { long fds_bits[-1]; } fdset; int highsock; } *


decompiled_code:
void __fastcall bbus_pollset_addsrv(__int64 a1, int *a2)
{
int v2; // eax

v2 = *a2 + 63;
if ( *a2 >= 0 )
v2 = *a2;
*(_QWORD *)(a1 + 8LL * (v2 >> 6)) |= 1LL << (*a2 % 64);
update_highsock(a1, *a2);
}

original_code:
void bbus_pollset_addsrv(bbus_pollset* pset, bbus_server* src)
{
 ((void) (((&pset->fdset)->fds_bits)[((src->sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((src->sock) % (8 * (int) sizeof (__fd_mask)))))));
 update_highsock(pset, src->sock);
}

canonical_original_code:
void bbus_pollset_addsrv(struct __bbus_pollset *pset, struct __bbus_server *src)
{
 ((void) (((&pset->fdset)->fds_bits)[((src->sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((src->sock) % (8 * (int) sizeof (__fd_mask)))))));
 update_highsock(pset, src->sock);
}

variable_types:
src
struct __bbus_server { int sock; } *


decompiled_code:
void __fastcall bbus_pollset_addcli(__int64 a1, int *a2)
{
int v2; // eax

v2 = *a2 + 63;
if ( *a2 >= 0 )
v2 = *a2;
*(_QWORD *)(a1 + 8LL * (v2 >> 6)) |= 1LL << (*a2 % 64);
update_highsock(a1, *a2);
}

original_code:
void bbus_pollset_addcli(bbus_pollset* pset, bbus_client* cli)
{
 ((void) (((&pset->fdset)->fds_bits)[((cli->sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cli->sock) % (8 * (int) sizeof (__fd_mask)))))));
 update_highsock(pset, cli->sock);
}

canonical_original_code:
void bbus_pollset_addcli(struct __bbus_pollset *pset, struct __bbus_client *cli)
{
 ((void) (((&pset->fdset)->fds_bits)[((cli->sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cli->sock) % (8 * (int) sizeof (__fd_mask)))))));
 update_highsock(pset, cli->sock);
}


decompiled_code:
int __fastcall bbus_poll(fd_set *readfds, struct timeval *a2)
{
int result; // eax
__int64 v3; // rdi
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

v4 = *a2;
result = select(readfds[1].fds_bits[0], readfds, 0LL, 0LL, &v4);
*a2 = v4;
if ( result < 0 )
{
v3 = (unsigned int)*_errno_location();
if ( (_DWORD)v3 == 4 )
v3 = 10015LL;
_bbus_seterr(v3);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func19(fd_set *readfds, struct timeval *a2)
{
int result; // eax
__int64 v3; // rdi
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

v4 = *a2;
result = select(readfds[1].fds_bits[0], readfds, 0LL, 0LL, &v4);
*a2 = v4;
if ( result < 0 )
{
v3 = (unsigned int)*_errno_location();
if ( (_DWORD)v3 == 4 )
v3 = 10015LL;
_bbus_seterr(v3);
result = -1;
}
return result;
}

original_code:
int bbus_poll(bbus_pollset* pset, struct bbus_timeval* tv)
{
 struct timeval stv;
 int ret;
 memset(&stv, 0, sizeof(struct timeval));
 stv.tv_sec = tv->sec;
 stv.tv_usec = tv->usec;
 ret = select(pset->highsock, &pset->fdset, ((void *)0), ((void *)0), &stv);
 tv->sec = stv.tv_sec;
 tv->usec = stv.tv_usec;
 if (ret < 0) {
  __bbus_seterr((*__errno_location ()) == 4 ? 10015 : (*__errno_location ()));
  return -1;
 }
 return ret;
}

canonical_original_code:
int bbus_poll(struct __bbus_pollset *pset, struct bbus_timeval *tv)
{
 struct timeval stv;
 int ret;
 memset(&stv, 0, sizeof(struct timeval));
 stv.tv_sec = tv->sec;
 stv.tv_usec = tv->usec;
 ret = select(pset->highsock, &pset->fdset, ((void *)0), ((void *)0), &stv);
 tv->sec = stv.tv_sec;
 tv->usec = stv.tv_usec;
 if (ret < 0) {
  __bbus_seterr((*__errno_location ()) == 4 ? 10015 : (*__errno_location ()));
  return -1;
 }
 return ret;
}

variable_types: struct bbus_timeval { long sec; long usec; } *

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


original_code:
int bbus_pollset_srvisset(bbus_pollset* pset, bbus_server* srv)
{
 return ((((&pset->fdset)->fds_bits)[((srv->sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((srv->sock) % (8 * (int) sizeof (__fd_mask)))))) != 0);
}

canonical_original_code:
int bbus_pollset_srvisset(struct __bbus_pollset *pset, struct __bbus_server *srv)
{
 return ((((&pset->fdset)->fds_bits)[((srv->sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((srv->sock) % (8 * (int) sizeof (__fd_mask)))))) != 0);
}


original_code:
int bbus_pollset_cliisset(bbus_pollset* pset, bbus_client* cli)
{
 return ((((&pset->fdset)->fds_bits)[((cli->sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cli->sock) % (8 * (int) sizeof (__fd_mask)))))) != 0);
}

canonical_original_code:
int bbus_pollset_cliisset(struct __bbus_pollset *pset, struct __bbus_client *cli)
{
 return ((((&pset->fdset)->fds_bits)[((cli->sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cli->sock) % (8 * (int) sizeof (__fd_mask)))))) != 0);
}


decompiled_code:
__int64 __fastcall bbus_pollset_free(__int64 a1)
{
return bbus_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
return bbus_free(a1);
}

original_code:
void bbus_pollset_free(bbus_pollset* pset)
{
 bbus_free(pset);
}

canonical_original_code:
void bbus_pollset_free(struct __bbus_pollset *pset)
{
 bbus_free(pset);
}


decompiled_code:
__int64 __fastcall do_session_open(__int64 a1, char a2, const char *a3)
{
int v4; // eax
unsigned int v5; // ebx
size_t v6; // rax
__int64 v8; // [rsp+0h] [rbp-38h] BYREF
__int64 v9; // [rsp+8h] [rbp-30h]

v4 = _bbus_sock_un_mksocket();
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
if ( (int)_bbus_sock_un_connect((unsigned int)v4, a1) < 0 )
return (unsigned int)-1;
v8 = 0LL;
v9 = 0LL;
_bbus_prot_hdrsetmagic(&v8);
BYTE2(v8) = 1;
BYTE3(v8) = a2;
if ( a3 )
{
BYTE6(v9) |= 1u;
v6 = strlen(a3);
bbus_hdr_setpsize(&v8, v6 + 1);
}
if ( (int)_bbus_prot_sendvmsg(v5, &v8, a3, 0LL, 0LL) < 0 )
goto LABEL_11;
v8 = 0LL;
v9 = 0LL;
if ( (int)_bbus_prot_recvvmsg(v5, &v8, 0LL, 0LL) < 0 )
goto LABEL_11;
if ( BYTE2(v8) != 2 )
{
if ( BYTE2(v8) == 3 )
_bbus_seterr(10009LL);
else
_bbus_seterr(10008LL);
LABEL_11:
_bbus_sock_close(v5);
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, const char *a3)
{
int v4; // eax
unsigned int v5; // ebx
size_t v6; // rax
__int64 v8; // [rsp+0h] [rbp-38h] BYREF
__int64 v9; // [rsp+8h] [rbp-30h]

v4 = _bbus_sock_un_mksocket();
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
if ( (int)_bbus_sock_un_connect((unsigned int)v4, a1) < 0 )
return (unsigned int)-1;
v8 = 0LL;
v9 = 0LL;
_bbus_prot_hdrsetmagic(&v8);
BYTE2(v8) = 1;
BYTE3(v8) = a2;
if ( a3 )
{
BYTE6(v9) |= 1u;
v6 = strlen(a3);
bbus_hdr_setpsize(&v8, v6 + 1);
}
if ( (int)_bbus_prot_sendvmsg(v5, &v8, a3, 0LL, 0LL) < 0 )
goto LABEL_11;
v8 = 0LL;
v9 = 0LL;
if ( (int)_bbus_prot_recvvmsg(v5, &v8, 0LL, 0LL) < 0 )
goto LABEL_11;
if ( BYTE2(v8) != 2 )
{
if ( BYTE2(v8) == 3 )
_bbus_seterr(10009LL);
else
_bbus_seterr(10008LL);
LABEL_11:
_bbus_sock_close(v5);
v5 = -1;
}
return v5;
}

original_code:
static int do_session_open(const char* path, int clitype, const char* name)
{
 int r;
 struct bbus_msg_hdr hdr;
 int sock;
 sock = __bbus_sock_un_mksocket();
 if (sock < 0)
  goto errout;
 r = __bbus_sock_un_connect(sock, path);
 if (r < 0)
  goto errout;
 memset(&hdr, 0, (sizeof(struct bbus_msg_hdr)));
 __bbus_prot_hdrsetmagic(&hdr);
 hdr.msgtype = 0x01;
 hdr.sotype = clitype;
 if (name) {
  do { (&hdr)->flags |= ((1 << 0)); } while (0);
  bbus_hdr_setpsize(&hdr, strlen(name)+1);
 }
 r = __bbus_prot_sendvmsg(sock, &hdr, name, ((void *)0), 0);
 if (r < 0)
  goto errout_close;
 memset(&hdr, 0, (sizeof(struct bbus_msg_hdr)));
 r = __bbus_prot_recvvmsg(sock, &hdr, ((void *)0), 0);
 if (r < 0)
  goto errout_close;
 if (hdr.msgtype == 0x02) {
  return sock;
 } else
 if (hdr.msgtype == 0x03) {
  __bbus_seterr(10009);
  goto errout_close;
 } else {
  __bbus_seterr(10008);
  goto errout_close;
 }
errout_close:
 __bbus_sock_close(sock);
errout:
 return -1;
}

canonical_original_code:
static int do_session_open(char *path, int clitype, char *name)
{
 int r;
 struct bbus_msg_hdr hdr;
 int sock;
 sock = __bbus_sock_un_mksocket();
 if (sock < 0)
  goto errout;
 r = __bbus_sock_un_connect(sock, path);
 if (r < 0)
  goto errout;
 memset(&hdr, 0, (sizeof(struct bbus_msg_hdr)));
 __bbus_prot_hdrsetmagic(&hdr);
 hdr.msgtype = 0x01;
 hdr.sotype = clitype;
 if (name) {
  do { (&hdr)->flags |= ((1 << 0)); } while (0);
  bbus_hdr_setpsize(&hdr, strlen(name)+1);
 }
 r = __bbus_prot_sendvmsg(sock, &hdr, name, ((void *)0), 0);
 if (r < 0)
  goto errout_close;
 memset(&hdr, 0, (sizeof(struct bbus_msg_hdr)));
 r = __bbus_prot_recvvmsg(sock, &hdr, ((void *)0), 0);
 if (r < 0)
  goto errout_close;
 if (hdr.msgtype == 0x02) {
  return sock;
 } else
 if (hdr.msgtype == 0x03) {
  __bbus_seterr(10009);
  goto errout_close;
 } else {
  __bbus_seterr(10008);
  goto errout_close;
 }
errout_close:
 __bbus_sock_close(sock);
errout:
 return -1;
}

variable_types:
path
char *

variable_types: clitype int

variable_types:
name
char *

variable_types: struct bbus_msg_hdr { unsigned short magic; unsigned char msgtype; unsigned char sotype; unsigned char errcode; unsigned int token; unsigned short psize; unsigned char flags; }


decompiled_code:
__int64 __fastcall send_session_close(unsigned int a1)
{
__int64 result; // rax
__int64 vars0[5]; // [rsp+0h] [rbp+0h] BYREF

vars0[0] = 0LL;
vars0[1] = 0LL;
_bbus_prot_hdrsetmagic(vars0);
BYTE2(vars0[0]) = 13;
if ( (int)_bbus_prot_sendvmsg(a1, vars0, 0LL, 0LL, 0LL) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)_bbus_sock_close(a1) >> 31);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax
__int64 vars0[5]; // [rsp+0h] [rbp+0h] BYREF

vars0[0] = 0LL;
vars0[1] = 0LL;
_bbus_prot_hdrsetmagic(vars0);
BYTE2(vars0[0]) = 13;
if ( (int)_bbus_prot_sendvmsg(a1, vars0, 0LL, 0LL, 0LL) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)_bbus_sock_close(a1) >> 31);
return result;
}

original_code:
static int send_session_close(int sock)
{
 int r;
 struct bbus_msg_hdr hdr;
 memset(&hdr, 0, (sizeof(struct bbus_msg_hdr)));
 __bbus_prot_hdrsetmagic(&hdr);
 hdr.msgtype = 0x0D;
 r = __bbus_prot_sendvmsg(sock, &hdr, ((void *)0), ((void *)0), 0);
 if (r < 0)
  return -1;
 r = __bbus_sock_close(sock);
 if (r < 0)
  return -1;
 return 0;
}

variable_types: r int

user_defined_types: struct bbus_msg_hdr { unsigned short magic; unsigned char msgtype; unsigned char sotype; unsigned char errcode; unsigned int token; unsigned short psize; unsigned char flags; }


decompiled_code:
int *__fastcall bbus_connect(const char *a1)
{
__int64 v1; // rax
int v2; // ebx
int *result; // rax

v1 = bbus_prot_getsockpath();
v2 = do_session_open(v1, 1, a1);
result = 0LL;
if ( v2 >= 0 )
{
result = (int *)bbus_malloc(4LL);
if ( result )
*result = v2;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func2(const char *a1)
{
__int64 v1; // rax
int v2; // ebx
int *result; // rax

v1 = bbus_prot_getsockpath();
v2 = func0(v1, 1, a1);
result = 0LL;
if ( v2 >= 0 )
{
result = (int *)bbus_malloc(4LL);
if ( result )
*result = v2;
}
return result;
}

original_code:
bbus_client_connection* bbus_connect(const char* name)
{
 int sock;
 bbus_client_connection* conn;
 sock = do_session_open(bbus_prot_getsockpath(),
    0x01, name);
 if (sock < 0)
  return ((void *)0);
 conn = bbus_malloc(sizeof(struct __bbus_client_connection));
 if (conn == ((void *)0))
  return ((void *)0);
 conn->sock = sock;
 return conn;
}

canonical_original_code:
struct __bbus_client_connection *bbus_connect(char *name)
{
 int sock;
 struct __bbus_client_connection *conn;
 sock = do_session_open(bbus_prot_getsockpath(),
    0x01, name);
 if (sock < 0)
  return ((void *)0);
 conn = bbus_malloc(sizeof(struct __bbus_client_connection));
 if (conn == ((void *)0))
  return ((void *)0);
 conn->sock = sock;
 return conn;
}

variable_types: struct __bbus_client_connection { int sock; } *


decompiled_code:
int *bbus_mon_connect()
{
__int64 v0; // rax
int v1; // ebx
int *result; // rax

v0 = bbus_prot_getsockpath();
v1 = do_session_open(v0, 3, 0LL);
result = 0LL;
if ( v1 >= 0 )
{
result = (int *)bbus_malloc(4LL);
if ( result )
*result = v1;
}
return result;
}

canonical_decompiled_code:
int *func4()
{
__int64 v0; // rax
int v1; // ebx
int *result; // rax

v0 = bbus_prot_getsockpath();
v1 = func0(v0, 3, 0LL);
result = 0LL;
if ( v1 >= 0 )
{
result = (int *)bbus_malloc(4LL);
if ( result )
*result = v1;
}
return result;
}

original_code:
bbus_client_connection* bbus_mon_connect(void)
{
 int sock;
 bbus_client_connection* conn;
 sock = do_session_open(bbus_prot_getsockpath(), 0x03, ((void *)0));
 if (sock < 0)
  return ((void *)0);
 conn = bbus_malloc(sizeof(struct __bbus_client_connection));
 if (conn == ((void *)0))
  return ((void *)0);
 conn->sock = sock;
 return conn;
}

canonical_original_code:
struct __bbus_client_connection *bbus_mon_connect()
{
 int sock;
 struct __bbus_client_connection *conn;
 sock = do_session_open(bbus_prot_getsockpath(), 0x03, ((void *)0));
 if (sock < 0)
  return ((void *)0);
 conn = bbus_malloc(sizeof(struct __bbus_client_connection));
 if (conn == ((void *)0))
  return ((void *)0);
 conn->sock = sock;
 return conn;
}

return_type: struct __bbus_client_connection { int sock; } *


decompiled_code:
__int64 __fastcall bbus_closeconn(unsigned int *a1)
{
int v1; // ebx
__int64 result; // rax

v1 = send_session_close(*a1);
bbus_free(a1);
result = 0xFFFFFFFFLL;
if ( v1 >= 0 )
result = (unsigned int)v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
int v1; // ebx
__int64 result; // rax

v1 = func1(*a1);
bbus_free(a1);
result = 0xFFFFFFFFLL;
if ( v1 >= 0 )
result = (unsigned int)v1;
return result;
}

original_code:
int bbus_closeconn(bbus_client_connection* conn)
{
 int r;
 r = send_session_close(conn->sock);
 if (r < 0)
  r = -1;
 bbus_free(conn);
 return r;
}

canonical_original_code:
int bbus_closeconn(struct __bbus_client_connection *conn)
{
 int r;
 r = send_session_close(conn->sock);
 if (r < 0)
  r = -1;
 bbus_free(conn);
 return r;
}

user_defined_types: struct __bbus_client_connection { int sock; }


decompiled_code:
void testlist_init()
{
tests = 0LL;
qword_508 = 0LL;
}

canonical_decompiled_code:
void func1()
{
tests = 0LL;
qword_508 = 0LL;
}

original_code:
static __attribute__((constructor(1000))) void testlist_init(void)
{
 tests.head = ((void *)0);
 tests.tail = ((void *)0);
}

canonical_original_code:
static void testlist_init()
{
 tests.head = ((void *)0);
 tests.tail = ((void *)0);
}


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

result = qword_508;
if ( qword_508 )
{
*(_QWORD *)qword_508 = a1;
*a1 = 0LL;
qword_508 = (__int64)a1;
}
else
{
qword_508 = (__int64)a1;
tests = (__int64)a1;
*a1 = 0LL;
}
++tests_registered;
return result;
}

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

result = qword_508;
if ( qword_508 )
{
*(_QWORD *)qword_508 = a1;
*a1 = 0LL;
qword_508 = (__int64)a1;
}
else
{
qword_508 = (__int64)a1;
tests = (__int64)a1;
*a1 = 0LL;
}
++tests_registered;
return result;
}

original_code:
void bbusunit_registertest(struct bbusunit_listelem* test)
{
 if (tests.tail == ((void *)0)) {
  tests.head = tests.tail = test;
  test->next = ((void *)0);
 } else {
  tests.tail->next = test;
  test->next = ((void *)0);
  tests.tail = test;
 }
 ++tests_registered;
}

canonical_original_code:
void bbusunit_registertest(struct bbusunit_listelem *test)
{
 if (tests.tail == ((void *)0)) {
  tests.head = tests.tail = test;
  test->next = ((void *)0);
 } else {
  tests.tail->next = test;
  test->next = ((void *)0);
  tests.tail = test;
 }
 ++tests_registered;
}

variable_types: struct bbusunit_listelem { struct bbusunit_listelem *next; char *name; int (*testfunc)(); } *


decompiled_code:
int bbusunit_print(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("[INFO]\t", 1uLL, 7uLL, stdout);
vfprintf(stdout, format, arg);
return fputc(10, stdout);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("[INFO]\t", 1uLL, 7uLL, stdout);
vfprintf(stdout, format, arg);
return fputc(10, stdout);
}

original_code:
void bbusunit_print(const char* fmt, ...)
{
 do { va_list va; __builtin_va_start(va,fmt); fprintf(stdout, "[INFO]""\t"); vfprintf(stdout, fmt, va); fprintf(stdout, "\n"); __builtin_va_end(va); } while (0);
}

canonical_original_code:
void bbusunit_print(char *fmt, ...)
{
 do { __builtin_va_list va; __builtin_va_start(va,fmt); fprintf(stdout, "[INFO]""\t"); vfprintf(stdout, fmt, va); fprintf(stdout, "\n"); __builtin_va_end(va); } while (0);
}

variable_types:
fmt
char *


decompiled_code:
int bbusunit_printerr(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("[ERROR]\t\t", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func4(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("[ERROR]\t\t", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

original_code:
void bbusunit_printerr(const char* fmt, ...)
{
 do { va_list va; __builtin_va_start(va,fmt); fprintf(stderr, "[ERROR]\t""\t"); vfprintf(stderr, fmt, va); fprintf(stderr, "\n"); __builtin_va_end(va); } while (0);
}

canonical_original_code:
void bbusunit_printerr(char *fmt, ...)
{
 do { __builtin_va_list va; __builtin_va_start(va,fmt); fprintf(stderr, "[ERROR]\t""\t"); vfprintf(stderr, fmt, va); fprintf(stderr, "\n"); __builtin_va_end(va); } while (0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // er12
int v5; // ebp
const char *v6; // rdx
const char *v7; // rdx
char v9[8]; // [rsp+0h] [rbp-58h] BYREF
__int64 v10; // [rsp+8h] [rbp-50h]
struct timeval v11; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF

tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v11.tv_sec = 0LL;
v11.tv_usec = 0LL;
*(_QWORD *)v9 = 0LL;
v10 = 0LL;
bbusunit_print("##############################", argv, envp);
bbusunit_print("####> Busybus unit-tests <####");
bbusunit_print("##############################");
bbusunit_print("%u tests registered.", (unsigned int)tests_registered);
bbusunit_print("Running tests...");
v3 = tests;
gettimeofday(&tv, 0LL);
if ( !v3 )
{
gettimeofday(&v11, 0LL);
timeval_diff(v9, &v11, &tv.tv_sec);
bbusunit_print("All done!");
bbusunit_print("SUMMARY:");
bbusunit_print(" %u %s run in %d.%06d seconds.", 0LL, "tests", *(unsigned int *)v9, (unsigned int)v10);
LABEL_13:
bbusunit_print(" All tests PASSED!");
return 0;
}
v4 = 0;
v5 = 0;
do
{
bbusunit_print("Case:\t[%s]", *(const char **)(v3 + 8));
if ( (*(int (**)(void))(v3 + 16))() < 0 )
{
bbusunit_printerr("[%s]: TEST FAILED", *(const char **)(v3 + 8));
++v4;
}
++v5;
v3 = *(_QWORD *)v3;
}
while ( v3 );
gettimeofday(&v11, 0LL);
timeval_diff(v9, &v11, &tv.tv_sec);
bbusunit_print("All done!");
bbusunit_print("SUMMARY:");
v6 = "test";
if ( v5 != 1 )
v6 = "tests";
bbusunit_print(" %u %s run in %d.%06d seconds.", (unsigned int)v5, v6, *(unsigned int *)v9, (unsigned int)v10);
if ( !v4 )
goto LABEL_13;
v7 = "test";
if ( v4 != 1 )
v7 = "tests";
bbusunit_printerr(" %u %s FAILED", (unsigned int)v4, v7);
bbusunit_printerr(" Failure rate: %.2f%%", (double)v4 / (double)v5 * 100.0);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // er12
int v5; // ebp
const char *v6; // rdx
const char *v7; // rdx
char v9[8]; // [rsp+0h] [rbp-58h] BYREF
__int64 v10; // [rsp+8h] [rbp-50h]
struct timeval v11; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF

tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v11.tv_sec = 0LL;
v11.tv_usec = 0LL;
*(_QWORD *)v9 = 0LL;
v10 = 0LL;
func3("##############################", argv, envp);
func3("####> Busybus unit-tests <####");
func3("##############################");
func3("%u tests registered.", (unsigned int)tests_registered);
func3("Running tests...");
v3 = tests;
gettimeofday(&tv, 0LL);
if ( !v3 )
{
gettimeofday(&v11, 0LL);
func0(v9, &v11, &tv.tv_sec);
func3("All done!");
func3("SUMMARY:");
func3(" %u %s run in %d.%06d seconds.", 0LL, "tests", *(unsigned int *)v9, (unsigned int)v10);
LABEL_13:
func3(" All tests PASSED!");
return 0;
}
v4 = 0;
v5 = 0;
do
{
func3("Case:\t[%s]", *(const char **)(v3 + 8));
if ( (*(int (**)(void))(v3 + 16))() < 0 )
{
func4("[%s]: TEST FAILED", *(const char **)(v3 + 8));
++v4;
}
++v5;
v3 = *(_QWORD *)v3;
}
while ( v3 );
gettimeofday(&v11, 0LL);
func0(v9, &v11, &tv.tv_sec);
func3("All done!");
func3("SUMMARY:");
v6 = "test";
if ( v5 != 1 )
v6 = "tests";
func3(" %u %s run in %d.%06d seconds.", (unsigned int)v5, v6, *(unsigned int *)v9, (unsigned int)v10);
if ( !v4 )
goto LABEL_13;
v7 = "test";
if ( v4 != 1 )
v7 = "tests";
func4(" %u %s FAILED", (unsigned int)v4, v7);
func4(" Failure rate: %.2f%%", (double)v4 / (double)v5 * 100.0);
return 1;
}

original_code:
int main(int argc __attribute__((unused)), char** argv __attribute__((unused)))
{
 struct bbusunit_listelem* el;
 int r;
 unsigned tests_run = 0;
 unsigned tests_failed = 0;
 struct timeval begin;
 struct timeval end;
 struct timeval time_spent;
 memset(&begin, 0, sizeof(struct timeval));
 memset(&end, 0, sizeof(struct timeval));
 memset(&time_spent, 0, sizeof(struct timeval));
 bbusunit_print("##############################");
 bbusunit_print("####> Busybus unit-tests <####");
 bbusunit_print("##############################");
 bbusunit_print("%u tests registered.", tests_registered);
 bbusunit_print("Running tests...");
 el = tests.head;
 gettimeofday(&begin, ((void *)0));
 while (el != ((void *)0)) {
  bbusunit_print("Case:\t[%s]", el->name);
  r = el->testfunc();
  if (r < 0) {
   bbusunit_printerr("[%s]: TEST FAILED", el->name);
   tests_failed++;
  }
  ++tests_run;
  el = el->next;
 }
 gettimeofday(&end, ((void *)0));
 timeval_diff(&time_spent, &end, &begin);
 bbusunit_print("All done!");
 bbusunit_print("SUMMARY:");
 bbusunit_print("  %u %s run in %d.%06d seconds.", tests_run,
   tests_run == 1 ? "test" : "tests",
   (int)time_spent.tv_sec, (int)time_spent.tv_usec);
 if (tests_failed > 0) {
  bbusunit_printerr("  %u %s FAILED", tests_failed,
    tests_failed == 1 ? "test" : "tests");
  bbusunit_printerr("  Failure rate: %.2f%%",
     ((double)tests_failed/tests_run)*100);
  r = 1;
 } else {
  bbusunit_print("  All tests PASSED!");
  r = 0;
 }
 return r;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct bbusunit_listelem *el;
 int r;
 unsigned int tests_run = 0;
 unsigned int tests_failed = 0;
 struct timeval begin;
 struct timeval end;
 struct timeval time_spent;
 memset(&begin, 0, sizeof(struct timeval));
 memset(&end, 0, sizeof(struct timeval));
 memset(&time_spent, 0, sizeof(struct timeval));
 bbusunit_print("##############################");
 bbusunit_print("####> Busybus unit-tests <####");
 bbusunit_print("##############################");
 bbusunit_print("%u tests registered.", tests_registered);
 bbusunit_print("Running tests...");
 el = tests.head;
 gettimeofday(&begin, ((void *)0));
 while (el != ((void *)0)) {
  bbusunit_print("Case:\t[%s]", el->name);
  r = el->testfunc();
  if (r < 0) {
   bbusunit_printerr("[%s]: TEST FAILED", el->name);
   tests_failed++;
  }
  ++tests_run;
  el = el->next;
 }
 gettimeofday(&end, ((void *)0));
 timeval_diff(&time_spent, &end, &begin);
 bbusunit_print("All done!");
 bbusunit_print("SUMMARY:");
 bbusunit_print("  %u %s run in %d.%06d seconds.", tests_run,
   tests_run == 1 ? "test" : "tests",
   (int)time_spent.tv_sec, (int)time_spent.tv_usec);
 if (tests_failed > 0) {
  bbusunit_printerr("  %u %s FAILED", tests_failed,
    tests_failed == 1 ? "test" : "tests");
  bbusunit_printerr("  Failure rate: %.2f%%",
     ((double)tests_failed/tests_run)*100);
  r = 1;
 } else {
  bbusunit_print("  All tests PASSED!");
  r = 0;
 }
 return r;
}

variable_types: argc int

variable_types:
argv
char **

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

user_defined_types: struct bbusunit_listelem { struct bbusunit_listelem *next; char *name; int (*testfunc)(); }


decompiled_code:
_BOOL8 __fastcall hdr_check_magic(const void *a1)
{
return memcmp(a1, &LC0, 2uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const void *a1)
{
return memcmp(a1, &LC0, 2uLL) == 0;
}

original_code:
static int hdr_check_magic(const struct bbus_msg_hdr* hdr)
{
 return memcmp(&hdr->magic, "\xBB\xC5", 2) == 0
      ? 1 : 0;
}

canonical_original_code:
static int hdr_check_magic(struct bbus_msg_hdr *hdr)
{
 return memcmp(&hdr->magic, "\xBB\xC5", 2) == 0
      ? 1 : 0;
}

variable_types: struct bbus_msg_hdr { unsigned short magic; unsigned char msgtype; unsigned char sotype; unsigned char errcode; unsigned int token; unsigned short psize; unsigned char flags; } *


decompiled_code:
__int64 __fastcall do_send(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax

v5 = _bbus_sock_send();
if ( v5 < 0 )
return 0xFFFFFFFFLL;
if ( a4 == v5 )
return 0LL;
_bbus_seterr(10010LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax

v5 = _bbus_sock_send();
if ( v5 < 0 )
return 0xFFFFFFFFLL;
if ( a4 == v5 )
return 0LL;
_bbus_seterr(10010LL);
return 0xFFFFFFFFLL;
}

original_code:
static int do_send(int sock, const struct iovec* iov,
    int numiov, size_t msgsize)
{
 ssize_t r;
 r = __bbus_sock_send(sock, iov, numiov);
 if (r < 0) {
  return -1;
 } else
 if (r != (ssize_t)msgsize) {
  __bbus_seterr(10010);
  return -1;
 }
 return 0;
}

canonical_original_code:
static int do_send(int sock, struct iovec *iov, int numiov, unsigned long msgsize)
{
 long r;
 r = __bbus_sock_send(sock, iov, numiov);
 if (r < 0) {
  return -1;
 } else
 if (r != (long)msgsize) {
  __bbus_seterr(10010);
  return -1;
 }
 return 0;
}

variable_types: sock int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } *

variable_types: numiov int

variable_types:
msgsize
unsigned long

variable_types: r long


decompiled_code:
int sockpath_init()
{
char *v0; // rcx

_bbus_spinlock_init(&sockpath_lock);
v0 = getenv("BBUS_SOCKPATH");
if ( !v0 )
v0 = "/tmp/bbus.sock";
return snprintf(sockpath, 0x100uLL, "%s", v0);
}

canonical_decompiled_code:
int func5()
{
char *v0; // rcx

_bbus_spinlock_init(&sockpath_lock);
v0 = getenv("BBUS_SOCKPATH");
if ( !v0 )
v0 = "/tmp/bbus.sock";
return snprintf(sockpath, 0x100uLL, "%s", v0);
}

original_code:
static void __attribute__((constructor)) sockpath_init(void)
{
 char* pathenv;
 char* path;
 __bbus_spinlock_init(&sockpath_lock);
 pathenv = getenv("BBUS_SOCKPATH");
 if (pathenv) {
  path = pathenv;
 } else {
  path = "/tmp/bbus.sock";
 }
 (void)snprintf(sockpath, 256, "%s", path);
}

canonical_original_code:
static void sockpath_init()
{
 char *pathenv;
 char *path;
 __bbus_spinlock_init(&sockpath_lock);
 pathenv = getenv("BBUS_SOCKPATH");
 if (pathenv) {
  path = pathenv;
 } else {
  path = "/tmp/bbus.sock";
 }
 (void)snprintf(sockpath, 256, "%s", path);
}

variable_types:
pathenv
char *


decompiled_code:
__int64 __fastcall bbus_prot_setsockpath(const char *a1)
{
_bbus_spinlock_lock(&sockpath_lock);
snprintf(sockpath, 0x100uLL, "%s", a1);
return _bbus_spinlock_unlock(&sockpath_lock);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
_bbus_spinlock_lock(&sockpath_lock);
snprintf(sockpath, 0x100uLL, "%s", a1);
return _bbus_spinlock_unlock(&sockpath_lock);
}

original_code:
void bbus_prot_setsockpath(const char* path)
{
 __bbus_spinlock_lock(&sockpath_lock);
 (void)snprintf(sockpath, 256, "%s", path);
 __bbus_spinlock_unlock(&sockpath_lock);
}

canonical_original_code:
void bbus_prot_setsockpath(char *path)
{
 __bbus_spinlock_lock(&sockpath_lock);
 (void)snprintf(sockpath, 256, "%s", path);
 __bbus_spinlock_unlock(&sockpath_lock);
}

variable_types:
path
char *


decompiled_code:
char *bbus_prot_getsockpath()
{
char *v0; // rbx

_bbus_spinlock_lock(&sockpath_lock);
v0 = (char *)header_to_iovec + _tls_get_addr(&localpath_tlsind);
snprintf(v0, 0x100uLL, "%s", sockpath);
_bbus_spinlock_unlock(&sockpath_lock);
return v0;
}

canonical_decompiled_code:
char *func7()
{
char *v0; // rbx

_bbus_spinlock_lock(&sockpath_lock);
v0 = (char *)header_to_iovec + _tls_get_addr(&localpath_tlsind);
snprintf(v0, 0x100uLL, "%s", sockpath);
_bbus_spinlock_unlock(&sockpath_lock);
return v0;
}

original_code:
const char* bbus_prot_getsockpath(void)
{
 __bbus_spinlock_lock(&sockpath_lock);
 (void)snprintf(localpath, 256, "%s", sockpath);
 __bbus_spinlock_unlock(&sockpath_lock);
 return localpath;
}

canonical_original_code:
char *bbus_prot_getsockpath()
{
 __bbus_spinlock_lock(&sockpath_lock);
 (void)snprintf(localpath, 256, "%s", sockpath);
 __bbus_spinlock_unlock(&sockpath_lock);
 return localpath;
}


decompiled_code:
__int64 __fastcall bbus_hdr_gettoken(__int64 a1)
{
return _bswap_32(*(_DWORD *)(a1 + 8));
}

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

original_code:
unsigned bbus_hdr_gettoken(const struct bbus_msg_hdr* hdr)
{
 return (unsigned)ntohl(hdr->token);
}

canonical_original_code:
unsigned int bbus_hdr_gettoken(struct bbus_msg_hdr *hdr)
{
 return (unsigned int)ntohl(hdr->token);
}


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

result = _bswap_32(a2);
*(_DWORD *)(a1 + 8) = result;
return result;
}

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

result = func3(a2);
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
void bbus_hdr_settoken(struct bbus_msg_hdr* hdr, unsigned tok)
{
 hdr->token = (uint32_t)htonl(tok);
}

canonical_original_code:
void bbus_hdr_settoken(struct bbus_msg_hdr *hdr, unsigned int tok)
{
 hdr->token = (unsigned int)htonl(tok);
}

variable_types:
tok
unsigned int


decompiled_code:
__int64 __fastcall bbus_hdr_getpsize(__int64 a1)
{
return (unsigned __int16)_bswap_16(*(_WORD *)(a1 + 12));
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return (unsigned __int16)func4(*(_WORD *)(a1 + 12));
}

original_code:
size_t bbus_hdr_getpsize(const struct bbus_msg_hdr* hdr)
{
 return (size_t)ntohs(hdr->psize);
}

canonical_original_code:
unsigned long bbus_hdr_getpsize(struct bbus_msg_hdr *hdr)
{
 return (unsigned long)ntohs(hdr->psize);
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall bbus_prot_extractmeta(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = bbus_hdr_getpsize(a1);
if ( (*(_BYTE *)(a1 + 14) & 1) == 0 || (v2 = a1 + 16, !memmem((const void *)(a1 + 16), v1, &unk_7F0, 1uLL)) )
{
_bbus_seterr(10003LL);
v2 = 0LL;
}
return v2;
}

original_code:
const char* bbus_prot_extractmeta(const struct bbus_msg* msg)
{
 const void* payload;
 size_t msgsize;
 msgsize = bbus_hdr_getpsize(&msg->hdr);
 if (msg->hdr.flags & (1 << 0)) {
  payload = msg->payload;
  if (memmem(payload, msgsize, "\0", 1) == ((void *)0)) {
   goto err;
  } else {
   return payload;
  }
 }
err:
 __bbus_seterr(10003);
 return ((void *)0);
}

canonical_original_code:
char *bbus_prot_extractmeta(struct bbus_msg *msg)
{
 void *payload;
 unsigned long msgsize;
 msgsize = bbus_hdr_getpsize(&msg->hdr);
 if (msg->hdr.flags & (1 << 0)) {
  payload = msg->payload;
  if (memmem(payload, msgsize, "\0", 1) == ((void *)0)) {
   goto err;
  } else {
   return payload;
  }
 }
err:
 __bbus_seterr(10003);
 return ((void *)0);
}

variable_types: struct bbus_msg { struct bbus_msg_hdr { unsigned short magic; unsigned char msgtype; unsigned char sotype; unsigned char errcode; unsigned int token; unsigned short psize; unsigned char flags; } hdr; char payload[1]; } *

variable_types:
payload
void *


decompiled_code:
__int16 __fastcall bbus_hdr_setpsize(__int64 a1, unsigned __int64 a2)
{
__int16 result; // ax

result = -1;
if ( a2 <= 0xFFFF )
result = _bswap_16(a2);
*(_WORD *)(a1 + 12) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func20(__int64 a1, unsigned __int64 a2)
{
__int16 result; // ax

result = -1;
if ( a2 <= 0xFFFF )
result = func4(a2);
*(_WORD *)(a1 + 12) = result;
return result;
}

original_code:
void bbus_hdr_setpsize(struct bbus_msg_hdr* hdr, size_t size)
{
 hdr->psize = size > (65535) ? (65535) : htons((uint16_t)size);
}

canonical_original_code:
void bbus_hdr_setpsize(struct bbus_msg_hdr *hdr, unsigned long size)
{
 hdr->psize = size > (65535) ? (65535) : htons((unsigned short)size);
}

variable_types:
size
unsigned long


original_code:
static inline void prepare_msghdr(struct msghdr* hdr,
    const struct iovec* iov, int numiov)
{
 hdr->msg_name = ((void *)0);
 hdr->msg_namelen = 0;
 hdr->msg_iov = (void*)iov;
 hdr->msg_iovlen = numiov;
 hdr->msg_control = ((void *)0);
 hdr->msg_controllen = 0;
 hdr->msg_flags = 0;
}

canonical_original_code:
static inline void prepare_msghdr(struct msghdr *hdr, struct iovec *iov, int numiov)
{
 hdr->msg_name = ((void *)0);
 hdr->msg_namelen = 0;
 hdr->msg_iov = (void *)iov;
 hdr->msg_iovlen = numiov;
 hdr->msg_control = ((void *)0);
 hdr->msg_controllen = 0;
 hdr->msg_flags = 0;
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

variable_types:
iov
struct iovec *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


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

switch ( a1 )
{
case 1:
result = "BBUS_MSGTYPE_SO";
break;
case 2:
result = "BBUS_MSGTYPE_SOOK";
break;
case 3:
result = "BBUS_MSGTYPE_SORJCT";
break;
case 4:
result = "BBUS_MSGTYPE_SRVREG";
break;
case 5:
result = "BBUS_MSGTYPE_SRVUNREG";
break;
case 6:
result = "BBUS_MSGTYPE_SRVACK";
break;
case 7:
result = "BBUS_MSGTYPE_CLICALL";
break;
case 8:
result = "BBUS_MSGTYPE_CLIREPLY";
break;
case 10:
result = "BBUS_MSGTYPE_SRVCALL";
break;
case 11:
result = "BBUS_MSGTYPE_SRVREPLY";
break;
case 13:
result = "BBUS_MSGTYPE_CLOSE";
break;
case 14:
result = "BBUS_MSGTYPE_CTRL";
break;
case 15:
result = "BBUS_MSGTYPE_MON";
break;
default:
result = "<unknown value>";
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
result = "BBUS_MSGTYPE_SO";
break;
case 2:
result = "BBUS_MSGTYPE_SOOK";
break;
case 3:
result = "BBUS_MSGTYPE_SORJCT";
break;
case 4:
result = "BBUS_MSGTYPE_SRVREG";
break;
case 5:
result = "BBUS_MSGTYPE_SRVUNREG";
break;
case 6:
result = "BBUS_MSGTYPE_SRVACK";
break;
case 7:
result = "BBUS_MSGTYPE_CLICALL";
break;
case 8:
result = "BBUS_MSGTYPE_CLIREPLY";
break;
case 10:
result = "BBUS_MSGTYPE_SRVCALL";
break;
case 11:
result = "BBUS_MSGTYPE_SRVREPLY";
break;
case 13:
result = "BBUS_MSGTYPE_CLOSE";
break;
case 14:
result = "BBUS_MSGTYPE_CTRL";
break;
case 15:
result = "BBUS_MSGTYPE_MON";
break;
default:
result = "<unknown value>";
break;
}
return result;
}

original_code:
static const char* str_msgtype(unsigned char msgtype)
{
 switch (msgtype) {
 case (0x01): return "BBUS_MSGTYPE_SO";
 case (0x02): return "BBUS_MSGTYPE_SOOK";
 case (0x03): return "BBUS_MSGTYPE_SORJCT";
 case (0x04): return "BBUS_MSGTYPE_SRVREG";
 case (0x05): return "BBUS_MSGTYPE_SRVUNREG";
 case (0x06): return "BBUS_MSGTYPE_SRVACK";
 case (0x07): return "BBUS_MSGTYPE_CLICALL";
 case (0x08): return "BBUS_MSGTYPE_CLIREPLY";
 case (0x0A): return "BBUS_MSGTYPE_SRVCALL";
 case (0x0B): return "BBUS_MSGTYPE_SRVREPLY";
 case (0x0D): return "BBUS_MSGTYPE_CLOSE";
 case (0x0E): return "BBUS_MSGTYPE_CTRL";
 case (0x0F): return "BBUS_MSGTYPE_MON";
 default: return "<unknown value>";
 }
}

canonical_original_code:
static char *str_msgtype(unsigned char msgtype)
{
 switch (msgtype) {
 case (0x01): return "BBUS_MSGTYPE_SO";
 case (0x02): return "BBUS_MSGTYPE_SOOK";
 case (0x03): return "BBUS_MSGTYPE_SORJCT";
 case (0x04): return "BBUS_MSGTYPE_SRVREG";
 case (0x05): return "BBUS_MSGTYPE_SRVUNREG";
 case (0x06): return "BBUS_MSGTYPE_SRVACK";
 case (0x07): return "BBUS_MSGTYPE_CLICALL";
 case (0x08): return "BBUS_MSGTYPE_CLIREPLY";
 case (0x0A): return "BBUS_MSGTYPE_SRVCALL";
 case (0x0B): return "BBUS_MSGTYPE_SRVREPLY";
 case (0x0D): return "BBUS_MSGTYPE_CLOSE";
 case (0x0E): return "BBUS_MSGTYPE_CTRL";
 case (0x0F): return "BBUS_MSGTYPE_MON";
 default: return "<unknown value>";
 }
}

variable_types:
msgtype
unsigned char


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

switch ( a1 )
{
case 0:
result = "BBUS_SOTYPE_NONE";
break;
case 1:
result = "BBUS_SOTYPE_MTHCL";
break;
case 2:
result = "BBUS_SOTYPE_SRVPRV";
break;
case 3:
result = "BBUS_SOTYPE_MON";
break;
case 4:
result = "BBUS_SOTYPE_CTL";
break;
default:
result = "<unknown value>";
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = "BBUS_SOTYPE_NONE";
break;
case 1:
result = "BBUS_SOTYPE_MTHCL";
break;
case 2:
result = "BBUS_SOTYPE_SRVPRV";
break;
case 3:
result = "BBUS_SOTYPE_MON";
break;
case 4:
result = "BBUS_SOTYPE_CTL";
break;
default:
result = "<unknown value>";
break;
}
return result;
}

original_code:
static const char* str_sotype(unsigned char sotype)
{
 switch (sotype) {
 case (0x00): return "BBUS_SOTYPE_NONE";
 case (0x01): return "BBUS_SOTYPE_MTHCL";
 case (0x02): return "BBUS_SOTYPE_SRVPRV";
 case (0x03): return "BBUS_SOTYPE_MON";
 case (0x04): return "BBUS_SOTYPE_CTL";
 default: return "<unknown value>";
 }
}

canonical_original_code:
static char *str_sotype(unsigned char sotype)
{
 switch (sotype) {
 case (0x00): return "BBUS_SOTYPE_NONE";
 case (0x01): return "BBUS_SOTYPE_MTHCL";
 case (0x02): return "BBUS_SOTYPE_SRVPRV";
 case (0x03): return "BBUS_SOTYPE_MON";
 case (0x04): return "BBUS_SOTYPE_CTL";
 default: return "<unknown value>";
 }
}

variable_types:
sotype
unsigned char


decompiled_code:
const char *__fastcall str_errcode(unsigned __int8 a1)
{
const char *result; // rax

result = "BBUS_PROT_EMETHODERR";
if ( a1 != 2 )
{
if ( a1 > 2u )
{
result = "<unknown value>";
if ( a1 == 3 )
result = "BBUS_PROT_EMREGERR";
}
else
{
result = "BBUS_PROT_ENOMETHOD";
if ( !a1 )
result = "BBUS_PROT_EGOOD";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(unsigned __int8 a1)
{
const char *result; // rax

result = "BBUS_PROT_EMETHODERR";
if ( a1 != 2 )
{
if ( a1 > 2u )
{
result = "<unknown value>";
if ( a1 == 3 )
result = "BBUS_PROT_EMREGERR";
}
else
{
result = "BBUS_PROT_ENOMETHOD";
if ( !a1 )
result = "BBUS_PROT_EGOOD";
}
}
return result;
}

original_code:
static const char* str_errcode(unsigned char errcode)
{
 switch (errcode) {
 case (0x00): return "BBUS_PROT_EGOOD";
 case (0x01): return "BBUS_PROT_ENOMETHOD";
 case (0x02): return "BBUS_PROT_EMETHODERR";
 case (0x03): return "BBUS_PROT_EMREGERR";
 default: return "<unknown value>";
 }
}

canonical_original_code:
static char *str_errcode(unsigned char errcode)
{
 switch (errcode) {
 case (0x00): return "BBUS_PROT_EGOOD";
 case (0x01): return "BBUS_PROT_ENOMETHOD";
 case (0x02): return "BBUS_PROT_EMETHODERR";
 case (0x03): return "BBUS_PROT_EMREGERR";
 default: return "<unknown value>";
 }
}

variable_types:
errcode
unsigned char


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

result = "BBUS_PROT_HASMETA | BBUS_PROT_HASOBJECT";
if ( (a1 & 3) != 3 )
{
result = "BBUS_PROT_HASMETA";
if ( (a1 & 1) == 0 )
{
result = "<no flags set>";
if ( (a1 & 2) != 0 )
result = "BBUS_PROT_HASOBJECT";
}
}
return result;
}

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

result = "BBUS_PROT_HASMETA | BBUS_PROT_HASOBJECT";
if ( (a1 & 3) != 3 )
{
result = "BBUS_PROT_HASMETA";
if ( (a1 & 1) == 0 )
{
result = "<no flags set>";
if ( (a1 & 2) != 0 )
result = "BBUS_PROT_HASOBJECT";
}
}
return result;
}

original_code:
static const char* str_flags(unsigned char flags)
{
 if ((flags & (1 << 0)) && (flags & (1 << 1))) {
  return "BBUS_PROT_HASMETA | BBUS_PROT_HASOBJECT";
 } else
 if (flags & (1 << 0)) {
  return "BBUS_PROT_HASMETA";
 } else
 if (flags & (1 << 1)) {
  return "BBUS_PROT_HASOBJECT";
 }
 return "<no flags set>";
}

canonical_original_code:
static char *str_flags(unsigned char flags)
{
 if ((flags & (1 << 0)) && (flags & (1 << 1))) {
  return "BBUS_PROT_HASMETA | BBUS_PROT_HASOBJECT";
 } else
 if (flags & (1 << 0)) {
  return "BBUS_PROT_HASMETA";
 } else
 if (flags & (1 << 1)) {
  return "BBUS_PROT_HASOBJECT";
 }
 return "<no flags set>";
}

variable_types:
flags
unsigned char


decompiled_code:
__int64 do_stop()
{
return (unsigned int)_InterlockedExchange(&run, 0);
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned int)_InterlockedExchange(&run, 0);
}

original_code:
static void do_stop(void)
{
 do { (void)__sync_lock_test_and_set(&(run), (0)); } while (0);
}

canonical_original_code:
static void do_stop()
{
 do { (void)__sync_lock_test_and_set(&(run), (0)); } while (0);
}


sighandler

decompiled_code:
void __fastcall sighandler(int a1)
{
if ( a1 == 2 || a1 == 15 )
do_stop();
}

canonical_decompiled_code:
void __fastcall func12(int a1)
{
if ( a1 == 2 || a1 == 15 )
func11();
}

original_code:
static void sighandler(int signum)
{
 switch (signum) {
 case 2:
 case 15:
  do_stop();
  break;
 }
}

variable_types: signum int


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func13(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
static void __attribute__((format(printf, 1, 2))) __attribute__((noreturn)) die(const char* format, ...)
{
 va_list va;
 __builtin_va_start(va,format);
 vfprintf(stderr, format, va);
 __builtin_va_end(va);
 exit(1);
}

canonical_original_code:
static void die(char *format, ...)
{
 __builtin_va_list va;
 __builtin_va_start(va,format);
 vfprintf(stderr, format, va);
 __builtin_va_end(va);
 exit(1);
}

variable_types:
format
char *


decompiled_code:
__int64 do_run()
{
signed __int32 v0; // eax
unsigned __int32 v1; // edx
signed __int32 v2; // ett

v0 = run;
do
{
v1 = v0;
v2 = v0;
v0 = _InterlockedCompareExchange(&run, v0, v0);
}
while ( v2 != v0 );
return v1;
}

canonical_decompiled_code:
__int64 func15()
{
signed __int32 v0; // eax
unsigned __int32 v1; // edx
signed __int32 v2; // ett

v0 = run;
do
{
v1 = v0;
v2 = v0;
v0 = _InterlockedCompareExchange(&run, v0, v0);
}
while ( v2 != v0 );
return v1;
}

original_code:
static int do_run(void)
{
 return __sync_fetch_and_or(&(run), 0);
}

canonical_original_code:
static int do_run()
{
 return __sync_fetch_and_or(&(run), 0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
int v4; // eax
const char *v5; // rax
const char *v7; // [rsp+0h] [rbp-38h]

if ( !bbus_mon_connect() )
{
bbus_lasterror();
v3 = (const char *)bbus_strerror();
die("Error connecting to bbusd: %s\n", v3);
}
signal(15, sighandler);
signal(2, sighandler);
run = 1;
while ( (unsigned int)do_run() )
{
v4 = bbus_mon_recvmsg();
if ( v4 < 0 )
{
if ( (unsigned int)bbus_lasterror() != 10015 )
{
bbus_lasterror();
v5 = (const char *)bbus_strerror();
die("Error receiving message: %s\n", v5);
}
}
else if ( v4 )
{
print_msg_info(v7);
}
}
bbus_closeconn();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
int v4; // eax
const char *v5; // rax
const char *v7; // [rsp+0h] [rbp-38h]

if ( !bbus_mon_connect() )
{
bbus_lasterror();
v3 = (const char *)bbus_strerror();
func13("Error connecting to bbusd: %s\n", v3);
}
signal(15, sighandler);
signal(2, sighandler);
run = 1;
while ( (unsigned int)func15() )
{
v4 = bbus_mon_recvmsg();
if ( v4 < 0 )
{
if ( (unsigned int)bbus_lasterror() != 10015 )
{
bbus_lasterror();
v5 = (const char *)bbus_strerror();
func13("Error receiving message: %s\n", v5);
}
}
else if ( v4 )
{
func14(v7);
}
}
bbus_closeconn();
return 0;
}

original_code:
int main(int argc __attribute__((unused)), char** argv __attribute__((unused)))
{
 struct bbusunit_listelem* el;
 int r;
 unsigned tests_run = 0;
 unsigned tests_failed = 0;
 struct timeval begin;
 struct timeval end;
 struct timeval time_spent;
 memset(&begin, 0, sizeof(struct timeval));
 memset(&end, 0, sizeof(struct timeval));
 memset(&time_spent, 0, sizeof(struct timeval));
 bbusunit_print("##############################");
 bbusunit_print("####> Busybus unit-tests <####");
 bbusunit_print("##############################");
 bbusunit_print("%u tests registered.", tests_registered);
 bbusunit_print("Running tests...");
 el = tests.head;
 gettimeofday(&begin, ((void *)0));
 while (el != ((void *)0)) {
  bbusunit_print("Case:\t[%s]", el->name);
  r = el->testfunc();
  if (r < 0) {
   bbusunit_printerr("[%s]: TEST FAILED", el->name);
   tests_failed++;
  }
  ++tests_run;
  el = el->next;
 }
 gettimeofday(&end, ((void *)0));
 timeval_diff(&time_spent, &end, &begin);
 bbusunit_print("All done!");
 bbusunit_print("SUMMARY:");
 bbusunit_print("  %u %s run in %d.%06d seconds.", tests_run,
   tests_run == 1 ? "test" : "tests",
   (int)time_spent.tv_sec, (int)time_spent.tv_usec);
 if (tests_failed > 0) {
  bbusunit_printerr("  %u %s FAILED", tests_failed,
    tests_failed == 1 ? "test" : "tests");
  bbusunit_printerr("  Failure rate: %.2f%%",
     ((double)tests_failed/tests_run)*100);
  r = 1;
 } else {
  bbusunit_print("  All tests PASSED!");
  r = 0;
 }
 return r;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct bbusunit_listelem *el;
 int r;
 unsigned int tests_run = 0;
 unsigned int tests_failed = 0;
 struct timeval begin;
 struct timeval end;
 struct timeval time_spent;
 memset(&begin, 0, sizeof(struct timeval));
 memset(&end, 0, sizeof(struct timeval));
 memset(&time_spent, 0, sizeof(struct timeval));
 bbusunit_print("##############################");
 bbusunit_print("####> Busybus unit-tests <####");
 bbusunit_print("##############################");
 bbusunit_print("%u tests registered.", tests_registered);
 bbusunit_print("Running tests...");
 el = tests.head;
 gettimeofday(&begin, ((void *)0));
 while (el != ((void *)0)) {
  bbusunit_print("Case:\t[%s]", el->name);
  r = el->testfunc();
  if (r < 0) {
   bbusunit_printerr("[%s]: TEST FAILED", el->name);
   tests_failed++;
  }
  ++tests_run;
  el = el->next;
 }
 gettimeofday(&end, ((void *)0));
 timeval_diff(&time_spent, &end, &begin);
 bbusunit_print("All done!");
 bbusunit_print("SUMMARY:");
 bbusunit_print("  %u %s run in %d.%06d seconds.", tests_run,
   tests_run == 1 ? "test" : "tests",
   (int)time_spent.tv_sec, (int)time_spent.tv_usec);
 if (tests_failed > 0) {
  bbusunit_printerr("  %u %s FAILED", tests_failed,
    tests_failed == 1 ? "test" : "tests");
  bbusunit_printerr("  Failure rate: %.2f%%",
     ((double)tests_failed/tests_run)*100);
  r = 1;
 } else {
  bbusunit_print("  All tests PASSED!");
  r = 0;
 }
 return r;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct bbusunit_listelem { struct bbusunit_listelem *next; char *name; int (*testfunc)(); } *

variable_types: r int

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


decompiled_code:
void *bbusd_getmsgbuf()
{
return &_msgbuf;
}

canonical_decompiled_code:
void *func0()
{
return &_msgbuf;
}

original_code:
struct bbus_msg* bbusd_getmsgbuf(void)
{
 return msgbuf;
}

canonical_original_code:
struct bbus_msg *bbusd_getmsgbuf()
{
 return msgbuf;
}

return_type: struct bbus_msg { struct bbus_msg_hdr { unsigned short magic; unsigned char msgtype; unsigned char sotype; unsigned char errcode; unsigned int token; unsigned short psize; unsigned char flags; } hdr; char payload[1]; } *


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

result = 0LL;
memset(&_msgbuf, 0, 0x2000uLL);
return result;
}

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

result = 0LL;
memset(&_msgbuf, 0, 0x2000uLL);
return result;
}

original_code:
void bbusd_zeromsgbuf(void)
{
 memset(msgbuf, 0, sizeof(__msgbuf));
}

canonical_original_code:
void bbusd_zeromsgbuf()
{
 memset(msgbuf, 0, sizeof(__msgbuf));
}


decompiled_code:
__int64 bbusd_msgbufsize()
{
return 0x2000LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0x2000LL;
}

original_code:
size_t bbusd_msgbufsize(void)
{
 return sizeof(__msgbuf);
}

canonical_original_code:
unsigned long bbusd_msgbufsize()
{
 return sizeof(__msgbuf);
}


decompiled_code:
char *bbus_str_build(char *format, ...)
{
__int64 v1; // rax
char *v2; // rbx
int v3; // er13
signed __int64 v4; // rbp
char *v5; // r15
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

v1 = bbus_malloc(128LL);
v2 = (char *)v1;
if ( v1 )
{
*(_QWORD *)v1 = 0LL;
*(_QWORD *)(v1 + 120) = 0LL;
memset(
(void *)((v1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 128) >> 3));
va_start(arg, format);
if ( vsnprintf((char *)v1, 0x80uLL, format, arg) > 127 )
{
v3 = 8;
v4 = 128LL;
while ( 1 )
{
v4 *= 2LL;
v5 = v2;
v2 = (char *)bbus_realloc(v2, v4);
if ( !v2 )
break;
va_end(arg);
va_start(arg, format);
if ( vsnprintf(v2, v4, format, arg) < v4 )
return v2;
if ( !--v3 )
{
_bbus_seterr(10004LL);
v5 = v2;
break;
}
}
bbus_free(v5);
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
char *func0(char *format, ...)
{
__int64 v1; // rax
char *v2; // rbx
int v3; // er13
signed __int64 v4; // rbp
char *v5; // r15
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

v1 = bbus_malloc(128LL);
v2 = (char *)v1;
if ( v1 )
{
*(_QWORD *)v1 = 0LL;
*(_QWORD *)(v1 + 120) = 0LL;
memset(
(void *)((v1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 128) >> 3));
va_start(arg, format);
if ( vsnprintf((char *)v1, 0x80uLL, format, arg) > 127 )
{
v3 = 8;
v4 = 128LL;
while ( 1 )
{
v4 *= 2LL;
v5 = v2;
v2 = (char *)bbus_realloc(v2, v4);
if ( !v2 )
break;
va_end(arg);
va_start(arg, format);
if ( vsnprintf(v2, v4, format, arg) < v4 )
return v2;
if ( !--v3 )
{
_bbus_seterr(10004LL);
v5 = v2;
break;
}
}
bbus_free(v5);
v2 = 0LL;
}
}
return v2;
}

original_code:
char* bbus_str_build(const char* fmt, ...)
{
 char* buf;
 va_list va;
 int r;
 ssize_t newbufsize;
 int i;
 char* newbuf;
 buf = bbus_malloc(128);
 if (buf == ((void *)0))
  return ((void *)0);
 memset(buf, 0, 128);
 __builtin_va_start(va,fmt);
 r = vsnprintf(buf, 128, fmt, va);
 __builtin_va_end(va);
 if (r >= 128) {
  newbufsize = 128;
  for (i = 0; i < 8; ++i) {
   newbufsize *= 2;
   newbuf = bbus_realloc(buf, newbufsize);
   if (newbuf == ((void *)0))
    goto errout_free;
   buf = newbuf;
   __builtin_va_start(va,fmt);
   r = vsnprintf(buf, newbufsize, fmt, va);
   __builtin_va_end(va);
   if (r < newbufsize)
    break;
  }
  if (r >= newbufsize) {
   __bbus_seterr(10004);
   goto errout_free;
  }
 }
 return buf;
errout_free:
 bbus_free(buf);
 return ((void *)0);
}

canonical_original_code:
char *bbus_str_build(char *fmt, ...)
{
 char *buf;
 __builtin_va_list va;
 int r;
 long newbufsize;
 int i;
 char *newbuf;
 buf = bbus_malloc(128);
 if (buf == ((void *)0))
  return ((void *)0);
 memset(buf, 0, 128);
 __builtin_va_start(va,fmt);
 r = vsnprintf(buf, 128, fmt, va);
 __builtin_va_end(va);
 if (r >= 128) {
  newbufsize = 128;
  for (i = 0; i < 8; ++i) {
   newbufsize *= 2;
   newbuf = bbus_realloc(buf, newbufsize);
   if (newbuf == ((void *)0))
    goto errout_free;
   buf = newbuf;
   __builtin_va_start(va,fmt);
   r = vsnprintf(buf, newbufsize, fmt, va);
   __builtin_va_end(va);
   if (r < newbufsize)
    break;
  }
  if (r >= newbufsize) {
   __bbus_seterr(10004);
   goto errout_free;
  }
 }
 return buf;
errout_free:
 bbus_free(buf);
 return ((void *)0);
}

variable_types:
fmt
char *

variable_types:
buf
char *

variable_types: newbufsize long

variable_types: i int

variable_types:
newbuf
char *


decompiled_code:
char *__fastcall bbus_str_cpy(char *src)
{
size_t v1; // rbp
char *v2; // rax
char *v3; // rbx

v1 = strlen(src) + 1;
v2 = (char *)bbus_malloc(v1);
v3 = v2;
if ( v2 )
{
memset(v2, 0, v1);
strncpy(v3, src, v1);
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v1; // rbp
char *v2; // rax
char *v3; // rbx

v1 = strlen(src) + 1;
v2 = (char *)bbus_malloc(v1);
v3 = v2;
if ( v2 )
{
memset(v2, 0, v1);
strncpy(v3, src, v1);
}
return v3;
}

original_code:
char* bbus_str_cpy(const char* str)
{
 char* s;
 size_t size;
 size = strlen(str)+1;
 s = bbus_malloc(size);
 if (s == ((void *)0))
  return ((void *)0);
 memset(s, 0, size);
 strncpy(s, str, size);
 return s;
}

canonical_original_code:
char *bbus_str_cpy(char *str)
{
 char *s;
 unsigned long size;
 size = strlen(str)+1;
 s = bbus_malloc(size);
 if (s == ((void *)0))
  return ((void *)0);
 memset(s, 0, size);
 strncpy(s, str, size);
 return s;
}

variable_types:
str
char *

variable_types:
s
char *

variable_types:
size
unsigned long


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

v2 = strlen(a1);
v3 = strlen(a2);
v4 = bbus_realloc(a1, v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
strncpy((char *)(v4 + v2), a2, v3);
*(_BYTE *)(v5 + v2 + v3) = 0;
}
return v5;
}

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

v2 = strlen(a1);
v3 = strlen(a2);
v4 = bbus_realloc(a1, v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
strncpy((char *)(v4 + v2), a2, v3);
*(_BYTE *)(v5 + v2 + v3) = 0;
}
return v5;
}

original_code:
char* bbus_str_join(char* dst, const char* src)
{
 size_t dsize, ssize;
 dsize = strlen(dst);
 ssize = strlen(src);
 dst = bbus_realloc(dst, dsize + ssize + 1);
 if (dst == ((void *)0))
  return ((void *)0);
 strncpy(dst+dsize, src, ssize);
 dst[dsize + ssize] = '\0';
 return dst;
}

canonical_original_code:
char *bbus_str_join(char *dst, char *src)
{
 unsigned long dsize; unsigned long ssize;
 dsize = strlen(dst);
 ssize = strlen(src);
 dst = bbus_realloc(dst, dsize + ssize + 1);
 if (dst == ((void *)0))
  return ((void *)0);
 strncpy(dst+dsize, src, ssize);
 dst[dsize + ssize] = '\0';
 return dst;
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
dsize
unsigned long

variable_types:
ssize
unsigned long


decompiled_code:
__int64 __fastcall bbus_str_free(__int64 a1)
{
return bbus_free(a1);
}

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

original_code:
void bbus_str_free(char* str)
{
 bbus_free(str);
}

canonical_original_code:
void bbus_str_free(char *str)
{
 bbus_free(str);
}


decompiled_code:
__int64 __fastcall bbusd_insert_method(__int64 a1, __int64 a2)
{
const char *v2; // rax
const char *v3; // rbx
unsigned int v4; // ebp

v2 = (const char *)bbus_str_cpy();
if ( !v2 )
return (unsigned int)-1;
v3 = v2;
v4 = do_insert_method(v2, a2, (_QWORD *)srvc_tree);
bbus_str_free(v3);
return v4;
}

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

v2 = (const char *)bbus_str_cpy();
if ( !v2 )
return (unsigned int)-1;
v3 = v2;
v4 = func1(v2, a2, (_QWORD *)srvc_tree);
bbus_str_free(v3);
return v4;
}

original_code:
int bbusd_insert_method(const char* path, struct bbusd_method* mthd)
{
 char* mname;
 int ret;
 mname = bbus_str_cpy(path);
 if (mname == ((void *)0))
  return -1;
 ret = do_insert_method(mname, mthd, srvc_tree);
 bbus_str_free(mname);
 return ret;
}

canonical_original_code:
int bbusd_insert_method(char *path, struct bbusd_method *mthd)
{
 char *mname;
 int ret;
 mname = bbus_str_cpy(path);
 if (mname == ((void *)0))
  return -1;
 ret = do_insert_method(mname, mthd, srvc_tree);
 bbus_str_free(mname);
 return ret;
}

variable_types:
path
char *

variable_types: struct bbusd_method { int type; char data[]; } *

variable_types:
mname
char *

variable_types: ret int


decompiled_code:
__int64 bbusd_locate_method()
{
const char *v0; // rax
const char *v1; // rbx
__int64 v2; // rbp

v0 = (const char *)bbus_str_cpy();
v1 = v0;
if ( !v0 )
return 0LL;
v2 = do_locate_method(v0, (_QWORD *)srvc_tree);
bbus_str_free(v1);
return v2;
}

canonical_decompiled_code:
__int64 func3()
{
const char *v0; // rax
const char *v1; // rbx
__int64 v2; // rbp

v0 = (const char *)bbus_str_cpy();
v1 = v0;
if ( !v0 )
return 0LL;
v2 = func0(v0, (_QWORD *)srvc_tree);
bbus_str_free(v1);
return v2;
}

original_code:
struct bbusd_method* bbusd_locate_method(const char* path)
{
 char* mname;
 struct bbusd_method* ret;
 mname = bbus_str_cpy(path);
 if (mname == ((void *)0))
  return ((void *)0);
 ret = do_locate_method(mname, srvc_tree);
 bbus_str_free(mname);
 return ret;
}

canonical_original_code:
struct bbusd_method *bbusd_locate_method(char *path)
{
 char *mname;
 struct bbusd_method *ret;
 mname = bbus_str_cpy(path);
 if (mname == ((void *)0))
  return ((void *)0);
 ret = do_locate_method(mname, srvc_tree);
 bbus_str_free(mname);
 return ret;
}

return_type: struct bbusd_method { int type; char data[]; } *


decompiled_code:
__int64 bbusd_free_service_map()
{
bbus_hmap_free(*(_QWORD *)(srvc_tree + 8));
bbus_hmap_free(*(_QWORD *)srvc_tree);
return bbus_free(srvc_tree);
}

canonical_decompiled_code:
__int64 func5()
{
bbus_hmap_free(*(_QWORD *)(srvc_tree + 8));
bbus_hmap_free(*(_QWORD *)srvc_tree);
return bbus_free(srvc_tree);
}

original_code:
void bbusd_free_service_map(void)
{
 bbus_hmap_free(srvc_tree->methods);
 bbus_hmap_free(srvc_tree->subsrvc);
 bbus_free(srvc_tree);
}

canonical_original_code:
void bbusd_free_service_map()
{
 bbus_hmap_free(srvc_tree->methods);
 bbus_hmap_free(srvc_tree->subsrvc);
 bbus_free(srvc_tree);
}


decompiled_code:
__int64 __fastcall handle_option(int a1, __int64 (__fastcall *a2)(__int64), __int64 a3)
{
__int64 result; // rax

switch ( a1 )
{
case 2:
*(_QWORD *)a2 = a3;
break;
case 3:
result = a2(a3);
break;
case 1:
*(_DWORD *)a2 = 1;
break;
}
return result;
}

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

switch ( a1 )
{
case 2:
*(_QWORD *)a2 = a3;
break;
case 3:
result = a2(a3);
break;
case 1:
*(_DWORD *)a2 = 1;
break;
}
return result;
}

original_code:
static void handle_option(enum bbus_opt_action action,
    void* actdata, char* arg)
{
 switch (action) {
 case BBUS_OPTACT_SETFLAG:
  *((int*)actdata) = 1;
  break;
 case BBUS_OPTACT_GETOPTARG:
  *((char**)actdata) = arg;
  break;
 case BBUS_OPTACT_CALLFUNC:
  ((bbus_opt_callback)actdata)(arg);
  break;
 case BBUS_OPTACT_NOTHING:
 default:
  break;
 }
}

canonical_original_code:
static void handle_option(enum bbus_opt_action action, void *actdata, char *arg)
{
 switch (action) {
 case BBUS_OPTACT_SETFLAG:
  *((int *)actdata) = 1;
  break;
 case BBUS_OPTACT_GETOPTARG:
  *((char **)actdata) = arg;
  break;
 case BBUS_OPTACT_CALLFUNC:
  ((void (*)(char *arg))actdata)(arg);
  break;
 case BBUS_OPTACT_NOTHING:
 default:
  break;
 }
}

variable_types: enum bbus_opt_action { BBUS_OPTACT_NOTHING=0, BBUS_OPTACT_SETFLAG=1, BBUS_OPTACT_GETOPTARG=2, BBUS_OPTACT_CALLFUNC=3 }

variable_types:
actdata
void *

variable_types:
arg
char *


decompiled_code:
__int64 __fastcall make_info_string(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
unsigned int v4; // er13
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // r14
const char *v10; // rcx
const char *v11; // r8
const char *v12; // r9
__int64 v13; // rdx
const char *v14; // rsi
__int64 v15; // rax
__int64 v16; // r12
__int64 v17; // rax
int v18; // edx
const char *v19; // rax

v1 = bbus_str_build(
"%s %s\n\n%s\n\n",
*(const char **)(a1 + 32),
*(const char **)(a1 + 40),
*(const char **)(a1 + 48));
v2 = v1;
if ( !v1 )
return v2;
if ( *(_QWORD *)(a1 + 8) )
{
v2 = bbus_str_join(v1, "Options:\n");
if ( v2 )
{
if ( *(_QWORD *)(a1 + 8) )
{
v4 = 0;
v5 = 0LL;
do
{
v17 = *(_QWORD *)a1 + 40 * v5;
v18 = *(_DWORD *)v17;
v12 = *(const char **)(v17 + 8);
v19 = *(const char **)(v17 + 32);
if ( v12 )
{
v10 = (const char *)&LC4;
v11 = (const char *)&LC3;
if ( !(_BYTE)v18 )
{
v13 = 32LL;
v10 = (const char *)&LC1;
v14 = (const char *)&LC2;
goto LABEL_20;
}
}
else
{
if ( !(_BYTE)v18 )
{
v13 = 32LL;
v10 = (const char *)&LC1;
v11 = (const char *)&LC1;
v12 = (const char *)&LC2;
v14 = (const char *)&LC2;
goto LABEL_20;
}
v10 = (const char *)&LC1;
v11 = (const char *)&LC1;
v12 = (const char *)&LC2;
}
v13 = (unsigned int)(char)v18;
v14 = (const char *)&LC0;
LABEL_20:
v15 = bbus_str_build(" %s%c%s%s%s -\t%s\n", v14, v13, v10, v11, v12, v19);
v16 = v15;
if ( !v15 )
goto LABEL_15;
v2 = bbus_str_join(v2, v15);
bbus_str_free(v16);
if ( !v2 )
goto LABEL_15;
v5 = ++v4;
}
while ( (unsigned __int64)v4 < *(_QWORD *)(a1 + 8) );
}
v2 = bbus_str_join(v2, "\n");
if ( v2 )
goto LABEL_3;
}
LABEL_15:
bbus_str_free(v2);
return 0LL;
}
LABEL_3:
if ( *(_QWORD *)(a1 + 24) )
{
v2 = bbus_str_join(v2, "Positional parameters:\n");
if ( !v2 )
goto LABEL_15;
v6 = 0;
while ( 1 )
{
v7 = v6;
if ( (unsigned __int64)v6 >= *(_QWORD *)(a1 + 24) )
break;
v8 = bbus_str_build(" #%d - %s\n", ++v6, *(const char **)(*(_QWORD *)(a1 + 16) + 24 * v7 + 16));
v9 = v8;
if ( v8 )
{
v2 = bbus_str_join(v2, v8);
bbus_str_free(v9);
if ( v2 )
continue;
}
goto LABEL_15;
}
v2 = bbus_str_join(v2, "\n");
if ( !v2 )
goto LABEL_15;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
unsigned int v4; // er13
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // r14
const char *v10; // rcx
const char *v11; // r8
const char *v12; // r9
__int64 v13; // rdx
const char *v14; // rsi
__int64 v15; // rax
__int64 v16; // r12
__int64 v17; // rax
int v18; // edx
const char *v19; // rax

v1 = bbus_str_build(
"%s %s\n\n%s\n\n",
*(const char **)(a1 + 32),
*(const char **)(a1 + 40),
*(const char **)(a1 + 48));
v2 = v1;
if ( !v1 )
return v2;
if ( *(_QWORD *)(a1 + 8) )
{
v2 = bbus_str_join(v1, "Options:\n");
if ( v2 )
{
if ( *(_QWORD *)(a1 + 8) )
{
v4 = 0;
v5 = 0LL;
do
{
v17 = *(_QWORD *)a1 + 40 * v5;
v18 = *(_DWORD *)v17;
v12 = *(const char **)(v17 + 8);
v19 = *(const char **)(v17 + 32);
if ( v12 )
{
v10 = (const char *)&LC4;
v11 = (const char *)&LC3;
if ( !(_BYTE)v18 )
{
v13 = 32LL;
v10 = (const char *)&LC1;
v14 = (const char *)&LC2;
goto LABEL_20;
}
}
else
{
if ( !(_BYTE)v18 )
{
v13 = 32LL;
v10 = (const char *)&LC1;
v11 = (const char *)&LC1;
v12 = (const char *)&LC2;
v14 = (const char *)&LC2;
goto LABEL_20;
}
v10 = (const char *)&LC1;
v11 = (const char *)&LC1;
v12 = (const char *)&LC2;
}
v13 = (unsigned int)(char)v18;
v14 = (const char *)&LC0;
LABEL_20:
v15 = bbus_str_build(" %s%c%s%s%s -\t%s\n", v14, v13, v10, v11, v12, v19);
v16 = v15;
if ( !v15 )
goto LABEL_15;
v2 = bbus_str_join(v2, v15);
bbus_str_free(v16);
if ( !v2 )
goto LABEL_15;
v5 = ++v4;
}
while ( (unsigned __int64)v4 < *(_QWORD *)(a1 + 8) );
}
v2 = bbus_str_join(v2, "\n");
if ( v2 )
goto LABEL_3;
}
LABEL_15:
bbus_str_free(v2);
return 0LL;
}
LABEL_3:
if ( *(_QWORD *)(a1 + 24) )
{
v2 = bbus_str_join(v2, "Positional parameters:\n");
if ( !v2 )
goto LABEL_15;
v6 = 0;
while ( 1 )
{
v7 = v6;
if ( (unsigned __int64)v6 >= *(_QWORD *)(a1 + 24) )
break;
v8 = bbus_str_build(" #%d - %s\n", ++v6, *(const char **)(*(_QWORD *)(a1 + 16) + 24 * v7 + 16));
v9 = v8;
if ( v8 )
{
v2 = bbus_str_join(v2, v8);
bbus_str_free(v9);
if ( v2 )
continue;
}
goto LABEL_15;
}
v2 = bbus_str_join(v2, "\n");
if ( !v2 )
goto LABEL_15;
}
return v2;
}

original_code:
static char* make_info_string(const struct bbus_opt_list* optlist)
{
 char* info;
 char* tmp;
 unsigned i;
 char shortopt;
 const char* longopt;
 info = bbus_str_build("%s %s\n\n%s\n\n",
    optlist->progname,
    optlist->version,
    optlist->progdescr);
 if (info == ((void *)0))
  return ((void *)0);
 if (optlist->numopts > 0) {
  info = bbus_str_join(info, "Options:\n");
  if (info == ((void *)0))
   goto errout;
  for (i = 0; i < optlist->numopts; ++i) {
   shortopt = optlist->opts[i].shortopt;
   longopt = optlist->opts[i].longopt;
   tmp = bbus_str_build("  %s%c%s%s%s -\t%s\n",
    shortopt == 0 ? " " : "-",
    shortopt == 0 ? ' ' : shortopt,
    (shortopt != 0)
     && (longopt != ((void *)0)) ? ", " : "  ",
    longopt == ((void *)0) ? "  " : "--",
    longopt == ((void *)0) ? " " : longopt,
    optlist->opts[i].descr);
   if (tmp == ((void *)0))
    goto errout;
   info = bbus_str_join(info, tmp);
   bbus_str_free(tmp);
   if (info == ((void *)0))
    goto errout;
  }
  info = bbus_str_join(info, "\n");
  if (info == ((void *)0))
   goto errout;
 }
 if (optlist->numpargs > 0) {
  info = bbus_str_join(info, "Positional parameters:\n");
  if (info == ((void *)0))
   goto errout;
  for (i = 0; i < optlist->numpargs; ++i) {
   tmp = bbus_str_build("  #%d - %s\n",
      i+1, optlist->pargs[i].descr);
   if (tmp == ((void *)0))
    goto errout;
   info = bbus_str_join(info, tmp);
   bbus_str_free(tmp);
   if (info == ((void *)0))
    goto errout;
  }
  info = bbus_str_join(info, "\n");
  if (info == ((void *)0))
   goto errout;
 }
 return info;
errout:
 bbus_str_free(info);
 return ((void *)0);
}

canonical_original_code:
static char *make_info_string(struct bbus_opt_list *optlist)
{
 char *info;
 char *tmp;
 unsigned int i;
 char shortopt;
 char *longopt;
 info = bbus_str_build("%s %s\n\n%s\n\n",
    optlist->progname,
    optlist->version,
    optlist->progdescr);
 if (info == ((void *)0))
  return ((void *)0);
 if (optlist->numopts > 0) {
  info = bbus_str_join(info, "Options:\n");
  if (info == ((void *)0))
   goto errout;
  for (i = 0; i < optlist->numopts; ++i) {
   shortopt = optlist->opts[i].shortopt;
   longopt = optlist->opts[i].longopt;
   tmp = bbus_str_build("  %s%c%s%s%s -\t%s\n",
    shortopt == 0 ? " " : "-",
    shortopt == 0 ? ' ' : shortopt,
    (shortopt != 0)
     && (longopt != ((void *)0)) ? ", " : "  ",
    longopt == ((void *)0) ? "  " : "--",
    longopt == ((void *)0) ? " " : longopt,
    optlist->opts[i].descr);
   if (tmp == ((void *)0))
    goto errout;
   info = bbus_str_join(info, tmp);
   bbus_str_free(tmp);
   if (info == ((void *)0))
    goto errout;
  }
  info = bbus_str_join(info, "\n");
  if (info == ((void *)0))
   goto errout;
 }
 if (optlist->numpargs > 0) {
  info = bbus_str_join(info, "Positional parameters:\n");
  if (info == ((void *)0))
   goto errout;
  for (i = 0; i < optlist->numpargs; ++i) {
   tmp = bbus_str_build("  #%d - %s\n",
      i+1, optlist->pargs[i].descr);
   if (tmp == ((void *)0))
    goto errout;
   info = bbus_str_join(info, tmp);
   bbus_str_free(tmp);
   if (info == ((void *)0))
    goto errout;
  }
  info = bbus_str_join(info, "\n");
  if (info == ((void *)0))
   goto errout;
 }
 return info;
errout:
 bbus_str_free(info);
 return ((void *)0);
}

variable_types: struct bbus_opt_list { struct bbus_option { int shortopt; char *longopt; enum bbus_opt_hasarg { BBUS_OPT_NOARG=0, BBUS_OPT_ARGREQ=1, BBUS_OPT_ARGOPT=2 } hasarg; enum bbus_opt_action { BBUS_OPTACT_NOTHING=0, BBUS_OPTACT_SETFLAG=1, BBUS_OPTACT_GETOPTARG=2, BBUS_OPTACT_CALLFUNC=3 } action; void *actdata; char *descr; } *opts; unsigned long numopts; struct bbus_posarg { enum bbus_opt_action { BBUS_OPTACT_NOTHING=0, BBUS_OPTACT_SETFLAG=1, BBUS_OPTACT_GETOPTARG=2, BBUS_OPTACT_CALLFUNC=3 } action; void *actdata; char *descr; } *pargs; unsigned long numpargs; char *progname; char *version; char *progdescr; } *

variable_types:
info
char *

variable_types:
tmp
char *

variable_types:
i
unsigned int

variable_types: shortopt char

variable_types:
longopt
char *

user_defined_types: struct bbus_opt_list { struct bbus_option *opts; unsigned long numopts; struct bbus_posarg *pargs; unsigned long numpargs; char *progname; char *version; char *progdescr; }

user_defined_types: struct bbus_option { int shortopt; char *longopt; enum bbus_opt_hasarg hasarg; enum bbus_opt_action action; void *actdata; char *descr; }

user_defined_types: struct bbus_posarg { enum bbus_opt_action action; void *actdata; char *descr; }


original_code:
static char* make_shortopts(const struct bbus_opt_list* optlist)
{
 unsigned i;
 size_t size = 0;
 char* ret;
 char* tmp;
 for (i = 0; i < optlist->numopts; ++i) {
  if (optlist->opts[i].shortopt != 0) {
   switch (optlist->opts[i].hasarg) {
   case BBUS_OPT_ARGREQ:
    size += 2;
    break;
   case BBUS_OPT_ARGOPT:
    size += 3;
    break;
   case BBUS_OPT_NOARG:
   default:
    ++size;
    break;
   }
  }
 }
 ret = bbus_malloc0(size);
 if (ret == ((void *)0))
  return ((void *)0);
 tmp = ret;
 for (i = 0; i < optlist->numopts; ++i) {
  if (optlist->opts[i].shortopt != 0) {
   switch (optlist->opts[i].hasarg) {
   case BBUS_OPT_ARGREQ:
    *tmp++ = (char)optlist->opts[i].shortopt;
    *tmp++ = ':';
    break;
   case BBUS_OPT_ARGOPT:
    *tmp++ = (char)optlist->opts[i].shortopt;
    *tmp++ = ':';
    *tmp++ = ':';
    break;
   case BBUS_OPT_NOARG:
   default:
    *tmp++ = (char)optlist->opts[i].shortopt;
    break;
   }
  }
 }
 return ret;
}

canonical_original_code:
static char *make_shortopts(struct bbus_opt_list *optlist)
{
 unsigned int i;
 unsigned long size = 0;
 char *ret;
 char *tmp;
 for (i = 0; i < optlist->numopts; ++i) {
  if (optlist->opts[i].shortopt != 0) {
   switch (optlist->opts[i].hasarg) {
   case BBUS_OPT_ARGREQ:
    size += 2;
    break;
   case BBUS_OPT_ARGOPT:
    size += 3;
    break;
   case BBUS_OPT_NOARG:
   default:
    ++size;
    break;
   }
  }
 }
 ret = bbus_malloc0(size);
 if (ret == ((void *)0))
  return ((void *)0);
 tmp = ret;
 for (i = 0; i < optlist->numopts; ++i) {
  if (optlist->opts[i].shortopt != 0) {
   switch (optlist->opts[i].hasarg) {
   case BBUS_OPT_ARGREQ:
    *tmp++ = (char)optlist->opts[i].shortopt;
    *tmp++ = ':';
    break;
   case BBUS_OPT_ARGOPT:
    *tmp++ = (char)optlist->opts[i].shortopt;
    *tmp++ = ':';
    *tmp++ = ':';
    break;
   case BBUS_OPT_NOARG:
   default:
    *tmp++ = (char)optlist->opts[i].shortopt;
    break;
   }
  }
 }
 return ret;
}

variable_types:
size
unsigned long

variable_types:
ret
char *

user_defined_types: enum bbus_opt_hasarg { BBUS_OPT_NOARG=0, BBUS_OPT_ARGREQ=1, BBUS_OPT_ARGOPT=2 }

user_defined_types: enum bbus_opt_action { BBUS_OPTACT_NOTHING=0, BBUS_OPTACT_SETFLAG=1, BBUS_OPTACT_GETOPTARG=2, BBUS_OPTACT_CALLFUNC=3 }


original_code:
static struct option* make_longopts(const struct bbus_opt_list* optlist,
        int* flag)
{
 struct option* ret;
 unsigned i;
 unsigned j = 2;
 size_t size = 2;
 for (i = 0; i < optlist->numopts; ++i)
  if (optlist->opts[i].longopt != ((void *)0))
   ++size;
 ret = bbus_malloc0((size+1) * sizeof(struct option));
 if (ret == ((void *)0))
  return ((void *)0);
 ret[0].name = "help";
 ret[0].has_arg = 0;
 ret[0].flag = flag;
 ret[0].val = -1;
 ret[1].name = "version";
 ret[1].has_arg = 0;
 ret[1].flag = flag;
 ret[1].val = -2;
 for (i = 0; i < optlist->numopts; ++i) {
  if (optlist->opts[i].longopt != ((void *)0)) {
   ret[j].name = optlist->opts[i].longopt;
   ret[j].flag = flag;
   ret[j].val = i;
   switch (optlist->opts[i].hasarg) {
   case BBUS_OPT_ARGREQ:
    ret[j].has_arg = 1;
    break;
   case BBUS_OPT_ARGOPT:
    ret[j].has_arg = 2;
    break;
   case BBUS_OPT_NOARG:
   default:
    ret[j].has_arg = 0;
    break;
   }
   ++j;
  }
 }
 return ret;
}

canonical_original_code:
static struct option *make_longopts(struct bbus_opt_list *optlist, int *flag)
{
 struct option *ret;
 unsigned int i;
 unsigned int j = 2;
 unsigned long size = 2;
 for (i = 0; i < optlist->numopts; ++i)
  if (optlist->opts[i].longopt != ((void *)0))
   ++size;
 ret = bbus_malloc0((size+1) * sizeof(struct option));
 if (ret == ((void *)0))
  return ((void *)0);
 ret[0].name = "help";
 ret[0].has_arg = 0;
 ret[0].flag = flag;
 ret[0].val = -1;
 ret[1].name = "version";
 ret[1].has_arg = 0;
 ret[1].flag = flag;
 ret[1].val = -2;
 for (i = 0; i < optlist->numopts; ++i) {
  if (optlist->opts[i].longopt != ((void *)0)) {
   ret[j].name = optlist->opts[i].longopt;
   ret[j].flag = flag;
   ret[j].val = i;
   switch (optlist->opts[i].hasarg) {
   case BBUS_OPT_ARGREQ:
    ret[j].has_arg = 1;
    break;
   case BBUS_OPT_ARGOPT:
    ret[j].has_arg = 2;
    break;
   case BBUS_OPT_NOARG:
   default:
    ret[j].has_arg = 0;
    break;
   }
   ++j;
  }
 }
 return ret;
}

variable_types:
flag
int *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *

variable_types:
j
unsigned int


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

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

original_code:
void bbus_free_nonopts(struct bbus_nonopts* nonopts)
{
 bbus_free(nonopts->args);
 bbus_free(nonopts);
}

canonical_original_code:
void bbus_free_nonopts(struct bbus_nonopts *nonopts)
{
 bbus_free(nonopts->args);
 bbus_free(nonopts);
}

variable_types: struct bbus_nonopts { char **args; unsigned long numargs; } *