decompiled_code:
__int64 log_mesg(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
__int64 v5; // r14
const char *v7; // rbx
unsigned int v8; // er15
int v9; // ebx
int v10; // ebx
size_t v11; // rax
time_t v13; // [rsp+0h] [rbp-2168h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-2160h] BYREF
char s[32]; // [rsp+20h] [rbp-2148h] BYREF
struct tm tp; // [rsp+40h] [rbp-2128h] BYREF
char buf[8192]; // [rsp+80h] [rbp-20E8h] BYREF

v5 = a3;
if ( a4 == 4 )
{
v7 = "error";
}
else if ( a4 > 4 )
{
v7 = "what's this";
if ( a4 == 8 )
v7 = "info ";
}
else
{
if ( a4 == 1 )
return 0LL;
v7 = "what's this";
if ( a4 == 2 )
v7 = "warn ";
}
v8 = syscall(186LL);
v13 = time(0LL);
localtime_r(&v13, &tp);
snprintf(
s,
0x1EuLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
va_start(arg, a5);
v9 = snprintf(buf, 0x2000uLL, "[%s] [%s] (#%d %s %s:%d) ", s, v7, v8, a2, a1, v5);
v10 = vsnprintf(&buf[v9], 0x2000LL - v9, a5, arg) + v9;
if ( v10 > 8190 )
v10 = 8190;
buf[v10] = 10;
buf[v10 + 1] = 0;
pthread_mutex_lock(&lock);
v11 = strlen(buf);
write(log_fd, buf, v11);
pthread_mutex_unlock(&lock);
return 0LL;
}

canonical_decompiled_code:
__int64 func1(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
__int64 v5; // r14
const char *v7; // rbx
unsigned int v8; // er15
int v9; // ebx
int v10; // ebx
size_t v11; // rax
time_t v13; // [rsp+0h] [rbp-2168h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-2160h] BYREF
char s[32]; // [rsp+20h] [rbp-2148h] BYREF
struct tm tp; // [rsp+40h] [rbp-2128h] BYREF
char buf[8192]; // [rsp+80h] [rbp-20E8h] BYREF

v5 = a3;
if ( a4 == 4 )
{
v7 = "error";
}
else if ( a4 > 4 )
{
v7 = "what's this";
if ( a4 == 8 )
v7 = "info ";
}
else
{
if ( a4 == 1 )
return 0LL;
v7 = "what's this";
if ( a4 == 2 )
v7 = "warn ";
}
v8 = syscall(186LL);
v13 = time(0LL);
localtime_r(&v13, &tp);
snprintf(
s,
0x1EuLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
va_start(arg, a5);
v9 = snprintf(buf, 0x2000uLL, "[%s] [%s] (#%d %s %s:%d) ", s, v7, v8, a2, a1, v5);
v10 = vsnprintf(&buf[v9], 0x2000LL - v9, a5, arg) + v9;
if ( v10 > 8190 )
v10 = 8190;
buf[v10] = 10;
buf[v10 + 1] = 0;
pthread_mutex_lock(&lock);
v11 = strlen(buf);
write(log_fd, buf, v11);
pthread_mutex_unlock(&lock);
return 0LL;
}

original_code:
int
log_mesg(const char *codefile, const char *func, int linenum, uint32_t mesg_level, const char *fmt, ...)
{
    char line[8192];
    va_list ap;
    char *level;
    time_t now;
    struct tm t;
    char time_string[30];
    int printed_len;
    int process_id;
    switch (mesg_level)
    {
    case 0x1:
        return 0;
        level = "debug";
        break;
    case 0x2:
        level = "warn ";
        break;
    case 0x4:
        level = "error";
        break;
    case 0x8:
        level = "info ";
        break;
    default:
        level = "what's this";
        break;
    }
    process_id = (int)syscall(186);
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(time_string, sizeof time_string, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    __builtin_va_start(ap,fmt);
    printed_len = snprintf(line, sizeof(line), "[%s] [%s] (#%d %s %s:%d) ", time_string, level, process_id, func, codefile, linenum);
    printed_len += vsnprintf(line + printed_len, sizeof(line) - printed_len, fmt, ap);
    __builtin_va_end(ap);
    if (printed_len > 8192 - 2)
        printed_len = 8192 - 2;
    line[ printed_len ] = '\n';
    line[ printed_len + 1 ] = '\0';
    pthread_mutex_lock(&lock);
    ssize_t writesize = write(log_fd, line, strlen(line));
    (void) writesize;
    pthread_mutex_unlock(&lock);
    return 0;
}

canonical_original_code:
int log_mesg(char *codefile, char *func, int linenum, unsigned int mesg_level, char *fmt, ...)
{
    char line[8192];
    __builtin_va_list ap;
    char *level;
    long now;
    struct tm t;
    char time_string[30];
    int printed_len;
    int process_id;
    switch (mesg_level)
    {
    case 0x1:
        return 0;
        level = "debug";
        break;
    case 0x2:
        level = "warn ";
        break;
    case 0x4:
        level = "error";
        break;
    case 0x8:
        level = "info ";
        break;
    default:
        level = "what's this";
        break;
    }
    process_id = (int)syscall(186);
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(time_string, sizeof time_string, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    __builtin_va_start(ap,fmt);
    printed_len = snprintf(line, sizeof(line), "[%s] [%s] (#%d %s %s:%d) ", time_string, level, process_id, func, codefile, linenum);
    printed_len += vsnprintf(line + printed_len, sizeof(line) - printed_len, fmt, ap);
    __builtin_va_end(ap);
    if (printed_len > 8192 - 2)
        printed_len = 8192 - 2;
    line[ printed_len ] = '\n';
    line[ printed_len + 1 ] = '\0';
    pthread_mutex_lock(&lock);
    long writesize = write(log_fd, line, strlen(line));
    (void) writesize;
    pthread_mutex_unlock(&lock);
    return 0;
}

variable_types:
codefile
char *

variable_types:
func
char *

variable_types: linenum int

variable_types:
fmt
char *

variable_types:
line
char [8192]

variable_types:
level
char *

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: writesize long


repo: lqs/crabdb

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

pthread_mutex_destroy(&lock);
close(log_fd);
result = 0LL;
log_fd = -1;
return result;
}

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

pthread_mutex_destroy(&lock);
close(log_fd);
result = 0LL;
log_fd = -1;
return result;
}

original_code:
int
log_close()
{
    pthread_mutex_destroy(&lock);
    close(log_fd);
    log_fd = -1;
    return 0;
}

return_type: int


decompiled_code:
char *__fastcall get_time_string(char *s)
{
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
snprintf(
s,
0x14uLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
s[19] = 0;
return s;
}

canonical_decompiled_code:
char *__fastcall func4(char *s)
{
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
snprintf(
s,
0x14uLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
s[19] = 0;
return s;
}

original_code:
const char *
get_time_string(char *string)
{
    time_t now;
    struct tm t;
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(string, 20, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    string[19] = '\0';
    return string;
}

canonical_original_code:
char *get_time_string(char *string)
{
    long now;
    struct tm t;
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(string, 20, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    string[19] = '\0';
    return string;
}

variable_types:
string
char *

return_type: char *

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
__int64 __fastcall crc32_calc(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned int v3; // eax
char v4; // dl

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = -1;
do
{
v4 = *a1++;
v3 = crc32_tab[(unsigned __int8)(v3 ^ v4)] ^ (v3 >> 8);
}
while ( a1 != v2 );
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned int v3; // eax
char v4; // dl

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = -1;
do
{
v4 = *a1++;
v3 = crc32_tab[(unsigned __int8)(v3 ^ v4)] ^ (v3 >> 8);
}
while ( a1 != v2 );
return ~v3;
}

original_code:
uint32_t
crc32_calc(const char *buf, size_t size)
{
    const unsigned char *p;
    uint32_t crc;
    p = (const unsigned char *)buf;
    crc = ~0U;
    while (size--)
        crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
    return crc ^ ~0U;
}

canonical_original_code:
unsigned int crc32_calc(char *buf, unsigned long size)
{
    unsigned char *p;
    unsigned int crc;
    p = (unsigned char *)buf;
    crc = ~0U;
    while (size--)
        crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
    return crc ^ ~0U;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types:
p
unsigned char *

variable_types:
crc
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall is_valid_name(unsigned __int8 *a1)
{
int v1; // edx
int v2; // esi
unsigned int v3; // eax
int v4; // ecx
__int64 result; // rax

v1 = *a1;
v2 = 1;
if ( !(_BYTE)v1 )
return 0LL;
while ( 1 )
{
v3 = v1 - 48;
v4 = v1 - 97;
LOBYTE(v3) = (unsigned __int8)(v1 - 48) <= 9u;
LOBYTE(v4) = (unsigned __int8)(v1 - 97) <= 0x19u;
result = v4 | v3;
LOBYTE(result) = ((_BYTE)v1 == 95) | result;
if ( !(_BYTE)result )
break;
v1 = *++a1;
if ( !(_BYTE)v1 )
break;
if ( ++v2 == 32 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
int v1; // edx
int v2; // esi
unsigned int v3; // eax
int v4; // ecx
__int64 result; // rax

v1 = *a1;
v2 = 1;
if ( !(_BYTE)v1 )
return 0LL;
while ( 1 )
{
v3 = v1 - 48;
v4 = v1 - 97;
LOBYTE(v3) = (unsigned __int8)(v1 - 48) <= 9u;
LOBYTE(v4) = (unsigned __int8)(v1 - 97) <= 0x19u;
result = v4 | v3;
LOBYTE(result) = ((_BYTE)v1 == 95) | result;
if ( !(_BYTE)result )
break;
v1 = *++a1;
if ( !(_BYTE)v1 )
break;
if ( ++v2 == 32 )
return 0LL;
}
return result;
}

original_code:
_Bool is_valid_name(const char *name) {
    int len = 0;
    while (*name) {
        char ch = *name;
        if (++len < 32 && ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch == '_'))) {
            name++;
            continue;
        }
        return 0;
    }
    return len > 0 && name[0] != '_';
}

canonical_original_code:
_Bool is_valid_name(char *name) {
    int len = 0;
    while (*name) {
        char ch = *name;
        if (++len < 32 && ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch == '_'))) {
            name++;
            continue;
        }
        return 0;
    }
    return len > 0 && name[0] != '_';
}

variable_types:
name
char *

variable_types: len int

variable_types: ch char


decompiled_code:
__int64 randu64()
{
int v0; // ebp
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/urandom", 0x80000);
read(v0, &buf, 8uLL);
close(v0);
return buf;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebp
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/urandom", 0x80000);
read(v0, &buf, 8uLL);
close(v0);
return buf;
}

original_code:
uint64_t randu64() {
    uint64_t result;
    int fd = open("/dev/urandom", 00 | 02000000);
    ssize_t readsize = read(fd, &result, sizeof(result));
    (void) readsize;
    close(fd);
    return result;
}

canonical_original_code:
unsigned long randu64() {
    unsigned long result;
    int fd = open("/dev/urandom", 00 | 02000000);
    long readsize = read(fd, &result, sizeof(result));
    (void) readsize;
    close(fd);
    return result;
}

variable_types:
result
unsigned long

variable_types: fd int

variable_types: readsize long

return_type: unsigned long


decompiled_code:
void __fastcall stat_add(int a1, unsigned __int64 a2)
{
_InterlockedAdd64(&stats[a1], a2);
}

canonical_decompiled_code:
void __fastcall func0(int a1, unsigned __int64 a2)
{
_InterlockedAdd64(&stats[a1], a2);
}

original_code:
void stat_add(int key, uint64_t value) {
    __sync_add_and_fetch(&stats[key], value);
}

canonical_original_code:
void stat_add(int key, unsigned long value) {
    __sync_add_and_fetch(&stats[key], value);
}

variable_types: key int

variable_types:
value
unsigned long

return_type: void


main

canonical_name: main

repo: lrem/splay

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
__int64 v4; // rbx
char *v5; // r12
char *v6; // rsi
unsigned int v7; // er14
__int64 v8; // rax
unsigned int v9; // er12
__int64 v10; // rax
__int64 v12[3]; // [rsp+0h] [rbp-48h] BYREF
int v13; // [rsp+18h] [rbp-30h]
char v14[44]; // [rsp+1Ch] [rbp-2Ch] BYREF

v3 = (char *)v12;
v13 = 7;
v4 = new_tree(compare_int, argv, envp);
v5 = (char *)v12;
v12[0] = 0x400000003LL;
v12[1] = 0x200000001LL;
v12[2] = 0x500000008LL;
output(v4);
do
{
v6 = v5;
v5 += 4;
insert(v4, v6);
v7 = **(_DWORD **)(last(v4) + 24);
v8 = first(v4);
printf("+%d: min %d max %d\n", *((unsigned int *)v5 - 1), **(unsigned int **)(v8 + 24), v7);
output(v4);
}
while ( v5 != v14 );
do
{
delete(v4, v3);
printf("-%d: ", *(unsigned int *)v3);
if ( first(v4) )
{
v9 = **(_DWORD **)(last(v4) + 24);
v10 = first(v4);
printf("min %d max %d\n", **(unsigned int **)(v10 + 24), v9);
}
else
{
puts("EMPTY");
}
v3 += 4;
output(v4);
}
while ( v3 != v14 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
__int64 v4; // rbx
char *v5; // r12
char *v6; // rsi
unsigned int v7; // er14
__int64 v8; // rax
unsigned int v9; // er12
__int64 v10; // rax
__int64 v12[3]; // [rsp+0h] [rbp-48h] BYREF
int v13; // [rsp+18h] [rbp-30h]
char v14[44]; // [rsp+1Ch] [rbp-2Ch] BYREF

v3 = (char *)v12;
v13 = 7;
v4 = new_tree(compare_int, argv, envp);
v5 = (char *)v12;
v12[0] = 0x400000003LL;
v12[1] = 0x200000001LL;
v12[2] = 0x500000008LL;
func8(v4);
do
{
v6 = v5;
v5 += 4;
insert(v4, v6);
v7 = **(_DWORD **)(func16(v4) + 24);
v8 = func12(v4);
printf("+%d: min %d max %d\n", *((unsigned int *)v5 - 1), **(unsigned int **)(v8 + 24), v7);
func8(v4);
}
while ( v5 != v14 );
do
{
func14(v4, v3);
printf("-%d: ", *(unsigned int *)v3);
if ( func12(v4) )
{
v9 = **(_DWORD **)(func16(v4) + 24);
v10 = func12(v4);
printf("min %d max %d\n", **(unsigned int **)(v10 + 24), v9);
}
else
{
puts("EMPTY");
}
v3 += 4;
func8(v4);
}
while ( v3 != v14 );
return 0;
}

original_code:
int main() {
    splay_tree *tree = new_tree(&compare_int);
    int values[] = {3, 4, 1, 2, 8, 5, 7};
    output(tree);
    for(int i = 0; i < 7; i++) {
        insert(tree, &values[i]);
        printf("+%d: min %d max %d\n", values[i],
                *(int*)first(tree)->value, *(int*)last(tree)->value);
        output(tree);
    }
    for(int i = 0; i < 7; i++) {
        delete(tree, &values[i]);
        printf("-%d: ", values[i]);
        if(first(tree) == ((void *)0)) {
            printf("EMPTY\n");
        } else {
            printf("min %d max %d\n",
                    *(int*)first(tree)->value, *(int*)last(tree)->value);
        }
        output(tree);
    }
    return 0;
}

canonical_original_code:
int main() {
    struct splay_tree *tree = new_tree(&compare_int);
    int values[] = {3, 4, 1, 2, 8, 5, 7};
    output(tree);
    for(int i = 0; i < 7; i++) {
        insert(tree, &values[i]);
        printf("+%d: min %d max %d\n", values[i],
                *(int *)first(tree)->value, *(int *)last(tree)->value);
        output(tree);
    }
    for(int i = 0; i < 7; i++) {
        delete(tree, &values[i]);
        printf("-%d: ", values[i]);
        if(first(tree) == ((void *)0)) {
            printf("EMPTY\n");
        } else {
            printf("min %d max %d\n",
                    *(int *)first(tree)->value, *(int *)last(tree)->value);
        }
        output(tree);
    }
    return 0;
}

variable_types: struct splay_tree { struct splay_node { struct splay_node *parent; void *value; } *root; int (*comp)(void *left, void *right); int size; } *

variable_types:
values
int []

variable_types: i int

user_defined_types: struct splay_tree { struct splay_node *root; int (*comp)(void *left, void *right); int size; }


decompiled_code:
__int64 __fastcall compare_int(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int compare_int(void *l, void *r) {
    return *((int*)l) - *((int*)r);
}

canonical_original_code:
int compare_int(void *l, void *r) {
    return *((int *)l) - *((int *)r);
}

variable_types:
l
void *

variable_types:
r
void *


output

decompiled_code:
int __fastcall output(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // rbp
unsigned int *v5; // rax

v1 = first(a1);
if ( v1 )
{
v2 = v1;
do
{
printf("%d ", **(unsigned int **)(v2 + 24));
v2 = next(v2);
}
while ( v2 );
}
putchar(10);
v3 = contents(a1);
if ( *(int *)(a1 + 16) > 0 )
{
v4 = 0LL;
do
{
v5 = *(unsigned int **)(v3 + 8 * v4++);
printf("%d ", *v5);
}
while ( *(_DWORD *)(a1 + 16) > (int)v4 );
}
return putchar(10);
}

original_code:
void output(splay_tree *tree) {
    splay_node *node = first(tree);
    while(node != ((void *)0)) {
        printf("%d ", *(int*)node->value);
        node = next(node);
    }
    printf("\n");
    void **t = contents(tree);
    for(int i = 0; i < tree->size; i++) {
        printf("%d ", *(int*)t[i]);
    }
    printf("\n");
}

canonical_original_code:
void output(struct splay_tree *tree) {
    struct splay_node *node = first(tree);
    while(node != ((void *)0)) {
        printf("%d ", *(int *)node->value);
        node = next(node);
    }
    printf("\n");
    void **t = contents(tree);
    for(int i = 0; i < tree->size; i++) {
        printf("%d ", *(int *)t[i]);
    }
    printf("\n");
}

variable_types: struct splay_node { struct splay_node *parent; void *value; } *

variable_types:
t
void **


contents

decompiled_code:
char *__fastcall contents(__int64 a1)
{
char *result; // rax
__int64 v3; // rdi
char *v4; // rax
_QWORD *v5; // rdi
char *v6; // [rsp+8h] [rbp-10h] BYREF

result = 0LL;
v3 = *(int *)(a1 + 16);
if ( (_DWORD)v3 )
{
v4 = (char *)malloc(8 * v3);
v5 = *(_QWORD **)a1;
v6 = v4;
store(v5, &v6);
result = &v6[-8 * *(int *)(a1 + 16)];
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
char *result; // rax
__int64 v3; // rdi
char *v4; // rax
_QWORD *v5; // rdi
char *v6; // [rsp+8h] [rbp-10h] BYREF

result = 0LL;
v3 = *(int *)(a1 + 16);
if ( (_DWORD)v3 )
{
v4 = (char *)malloc(8 * v3);
v5 = *(_QWORD **)a1;
v6 = v4;
store(v5, &v6);
result = &v6[-8 * *(int *)(a1 + 16)];
}
return result;
}

original_code:
extern void* contents(splay_tree *tree) {
    if(tree->size == 0)
        return ((void *)0);
    void **out = malloc(tree->size * sizeof(void*));
    void ***tmp = &out;
    store(tree->root, tmp);
    return out - tree->size;
}

canonical_original_code:
extern void *contents(struct splay_tree *tree) {
    if(tree->size == 0)
        return ((void *)0);
    void **out = malloc(tree->size * sizeof(void*));
    void ***tmp = &out;
    store(tree->root, tmp);
    return out - tree->size;
}

variable_types:
out
void **

variable_types:
tmp
void ***

return_type: void *

user_defined_types: struct splay_node { struct splay_node *parent; void *value; }


leftmost

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

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
splay_node* leftmost(splay_node *node) {
    splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->left;
    }
    return parent;
}

canonical_original_code:
struct splay_node *leftmost(struct splay_node *node) {
    struct splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->left;
    }
    return parent;
}

variable_types:
node
struct splay_node *

return_type: struct splay_node { struct splay_node *parent; void *value; } *


first

decompiled_code:
__int64 __fastcall first(__int64 *a1)
{
return leftmost(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1)
{
return func11(*a1);
}

original_code:
extern splay_node* first(splay_tree *tree) {
    return leftmost(tree->root);
}

canonical_original_code:
extern struct splay_node *first(struct splay_tree *tree) {
    return leftmost(tree->root);
}

variable_types: struct splay_tree { struct splay_node *root; int (*comp)(void *left, void *right); int size; } *


original_code:
extern void delete_hint(splay_tree *tree, splay_node *node) {
    if(node == ((void *)0))
        return;
    splay(tree, node);
    if(node->left == ((void *)0)) {
        tree->root = node->right;
        if(tree->root != ((void *)0))
            tree->root->parent = ((void *)0);
    } else if(node->right == ((void *)0)) {
        tree->root = node->left;
        tree->root->parent = ((void *)0);
    } else {
        splay_node *x = leftmost(node->right);
        if(x->parent != node) {
            x->parent->left = x->right;
            if(x->right != ((void *)0))
                x->right->parent = x->parent;
            x->right = node->right;
            x->right->parent = x;
        }
        tree->root = x;
        x->parent = ((void *)0);
        x->left = node->left;
        x->left->parent = x;
    }
    free(node);
    tree->size--;
    check_sanity(tree);
}

canonical_original_code:
extern void delete_hint(struct splay_tree *tree, struct splay_node *node) {
    if(node == ((void *)0))
        return;
    splay(tree, node);
    if(node->left == ((void *)0)) {
        tree->root = node->right;
        if(tree->root != ((void *)0))
            tree->root->parent = ((void *)0);
    } else if(node->right == ((void *)0)) {
        tree->root = node->left;
        tree->root->parent = ((void *)0);
    } else {
        struct splay_node *x = leftmost(node->right);
        if(x->parent != node) {
            x->parent->left = x->right;
            if(x->right != ((void *)0))
                x->right->parent = x->parent;
            x->right = node->right;
            x->right->parent = x;
        }
        tree->root = x;
        x->parent = ((void *)0);
        x->left = node->left;
        x->left->parent = x;
    }
    free(node);
    tree->size--;
    check_sanity(tree);
}


delete

decompiled_code:
void __fastcall delete(__int64 a1, __int64 a2)
{
__int64 **v2; // rax

v2 = find(a1, a2);
delete_hint(a1, (__int64)v2);
}

original_code:
extern void delete(splay_tree *tree, void *value) {
    splay_node *node = find(tree, value);
    delete_hint(tree, node);
}

canonical_original_code:
extern void delete(struct splay_tree *tree, void *value) {
    struct splay_node *node = find(tree, value);
    delete_hint(tree, node);
}

variable_types:
value
void *


rightmost

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

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
splay_node* rightmost(splay_node *node) {
    splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->right;
    }
    return parent;
}

canonical_original_code:
struct splay_node *rightmost(struct splay_node *node) {
    struct splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->right;
    }
    return parent;
}


last

decompiled_code:
__int64 __fastcall last(__int64 *a1)
{
return rightmost(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1)
{
return func15(*a1);
}

original_code:
extern splay_node* last(splay_tree *tree) {
    return rightmost(tree->root);
}

canonical_original_code:
extern struct splay_node *last(struct splay_tree *tree) {
    return rightmost(tree->root);
}


decompiled_code:
void check_sanity()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void check_sanity(splay_tree *tree) {
}

canonical_original_code:
void check_sanity(struct splay_tree *tree) {
}


original_code:
static bbus_hashmap* create_hashmap(enum bbus_hmap_type type, size_t size)
{
 bbus_hashmap* hmap;
 unsigned i;
 hmap = bbus_malloc(sizeof(struct __bbus_hashmap));
 if (hmap == ((void *)0))
  return ((void *)0);
 hmap->buckets = bbus_malloc(size * sizeof(struct entry_list));
 if (hmap->buckets == ((void *)0)) {
  bbus_free(hmap);
  return ((void *)0);
 }
 for (i = 0; i < size; ++i) {
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
 hmap->size = size;
 hmap->numstored = 0;
 hmap->type = type;
 return hmap;
}

canonical_original_code:
static struct __bbus_hashmap *create_hashmap(enum bbus_hmap_type type, unsigned long size)
{
 struct __bbus_hashmap *hmap;
 unsigned int i;
 hmap = bbus_malloc(sizeof(struct __bbus_hashmap));
 if (hmap == ((void *)0))
  return ((void *)0);
 hmap->buckets = bbus_malloc(size * sizeof(struct entry_list));
 if (hmap->buckets == ((void *)0)) {
  bbus_free(hmap);
  return ((void *)0);
 }
 for (i = 0; i < size; ++i) {
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
 hmap->size = size;
 hmap->numstored = 0;
 hmap->type = type;
 return hmap;
}

variable_types:
size
unsigned long

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:
i
unsigned 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 dump_append(char **a1, size_t *a2, const char *a3, ...)
{
int v3; // eax
size_t v4; // rdx
size_t v5; // rdx
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
v3 = vsnprintf(*a1, *a2, a3, arg);
v4 = *a2;
if ( v3 >= (int)*a2 )
{
_bbus_seterr(10004LL);
result = 0xFFFFFFFFLL;
}
else
{
*a1 += v3;
v5 = v4 - v3;
result = 0LL;
*a2 = v5;
}
return result;
}

canonical_decompiled_code:
__int64 func2(char **a1, size_t *a2, const char *a3, ...)
{
int v3; // eax
size_t v4; // rdx
size_t v5; // rdx
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
v3 = vsnprintf(*a1, *a2, a3, arg);
v4 = *a2;
if ( v3 >= (int)*a2 )
{
_bbus_seterr(10004LL);
result = 0xFFFFFFFFLL;
}
else
{
*a1 += v3;
v5 = v4 - v3;
result = 0LL;
*a2 = v5;
}
return result;
}

original_code:
static int __attribute__((format(printf, 3, 4))) dump_append(char** buf,
  size_t* bufsize, const char* fmt, ...)
{
 int r;
 va_list va;
 __builtin_va_start(va,fmt);
 r = vsnprintf(*buf, *bufsize, fmt, va);
 if (r >= (int)(*bufsize)) {
  __bbus_seterr(10004);
  return -1;
 }
 *buf += r;
 *bufsize -= r;
 return 0;
}

canonical_original_code:
static int dump_append(char **buf, unsigned long *bufsize, char *fmt, ...)
{
 int r;
 __builtin_va_list va;
 __builtin_va_start(va,fmt);
 r = vsnprintf(*buf, *bufsize, fmt, va);
 if (r >= (int)(*bufsize)) {
  __bbus_seterr(10004);
  return -1;
 }
 *buf += r;
 *bufsize -= r;
 return 0;
}

variable_types:
buf
char **

variable_types:
bufsize
unsigned long *

variable_types:
fmt
char *

variable_types: r int


decompiled_code:
__int64 __fastcall bbus_hmap_create(int a1)
{
return create_hashmap(a1, 0x20uLL);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return func0(a1, 0x20uLL);
}

original_code:
bbus_hashmap* bbus_hmap_create(enum bbus_hmap_type type)
{
 return create_hashmap(type, 32);
}

canonical_original_code:
struct __bbus_hashmap *bbus_hmap_create(enum bbus_hmap_type type)
{
 return create_hashmap(type, 32);
}

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


original_code:
void bbus_hmap_reset(bbus_hashmap* hmap)
{
 unsigned i;
 struct map_entry* el;
 struct map_entry* tmpel;
 for (i = 0; i < hmap->size; ++i) {
  el = hmap->buckets[i].head;
  while (el != ((void *)0)) {
   tmpel = el;
   el = el->next;
   bbus_free(tmpel->key);
   bbus_free(tmpel);
  }
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
}

canonical_original_code:
void bbus_hmap_reset(struct __bbus_hashmap *hmap)
{
 unsigned int i;
 struct map_entry *el;
 struct map_entry *tmpel;
 for (i = 0; i < hmap->size; ++i) {
  el = hmap->buckets[i].head;
  while (el != ((void *)0)) {
   tmpel = el;
   el = el->next;
   bbus_free(tmpel->key);
   bbus_free(tmpel);
  }
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
}

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

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


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

if ( a1 )
{
bbus_hmap_reset(a1);
bbus_free(a1[2]);
result = bbus_free(a1);
}
return result;
}

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

if ( a1 )
{
func7(a1);
bbus_free(a1[2]);
result = bbus_free(a1);
}
return result;
}

original_code:
void bbus_hmap_free(bbus_hashmap* hmap)
{
 if (hmap) {
  bbus_hmap_reset(hmap);
  bbus_free(hmap->buckets);
  bbus_free(hmap);
 }
}

canonical_original_code:
void bbus_hmap_free(struct __bbus_hashmap *hmap)
{
 if (hmap) {
  bbus_hmap_reset(hmap);
  bbus_free(hmap->buckets);
  bbus_free(hmap);
 }
}

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 enlarge_map(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // r13
unsigned int v3; // er12
__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_9:
v4 = ++v3;
if ( (unsigned __int64)v3 >= *(_QWORD *)a1 )
goto LABEL_10;
}
while ( (int)hmap_set(v2, v5[2], v5[3], v5[4]) >= 0 )
{
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_9;
}
bbus_hmap_free(v2);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_10:
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 func9(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // r13
unsigned int v3; // er12
__int64 v4; // rax
_QWORD *v5; // rbx
__int64 result; // rax

v1 = func0(*(_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_9:
v4 = ++v3;
if ( (unsigned __int64)v3 >= *(_QWORD *)a1 )
goto LABEL_10;
}
while ( (int)func10(v2, v5[2], v5[3], v5[4]) >= 0 )
{
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_9;
}
func8(v2);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_10:
func7((_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:
int __fastcall bbus_hmap_setstr(__int64 a1, const char *a2, __int64 *a3)
{
size_t v4; // rax
int result; // eax

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

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

if ( *(_DWORD *)(a1 + 24) == 2 )
{
v4 = strlen(a2);
result = func10((_QWORD *)a1, a2, v4, a3);
}
else
{
_bbus_seterr(10017LL);
result = -1;
}
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:
key
char *

variable_types:
val
void *


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

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

canonical_decompiled_code:
int __fastcall func12(__int64 a1, int a2, __int64 *a3)
{
bool v3; // zf
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = *(_DWORD *)(a1 + 24) == 1;
v5[0] = a2;
if ( v3 )
return func10((_QWORD *)a1, v5, 4uLL, a3);
_bbus_seterr(10017LL);
return -1;
}

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


decompiled_code:
__int64 __fastcall bbus_hmap_dump(unsigned int *a1, char *a2, size_t a3)
{
__int64 v3; // r9
__int64 v4; // r15
void *v5; // r8
_QWORD *i; // r15
__int64 v7; // rax
const char *v8; // rdx
unsigned int v10; // [rsp+Ch] [rbp-4Ch]
size_t v11; // [rsp+10h] [rbp-48h] BYREF
char *v12[8]; // [rsp+18h] [rbp-40h] BYREF

v12[0] = 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;
v3 = 0LL;
v10 = 0;
if ( *(_QWORD *)a1 )
{
while ( 1 )
{
v4 = 16 * v3;
v5 = &LC1;
if ( !*(_QWORD *)(*((_QWORD *)a1 + 2) + 16 * v3) )
v5 = &LC0;
if ( (int)dump_append(v12, &v11, "Bucket nr %u:\n%s", v10, v5) < 0 )
return 0xFFFFFFFFLL;
for ( i = *(_QWORD **)(*((_QWORD *)a1 + 2) + v4); i; i = (_QWORD *)*i )
{
v7 = keyrepr_constprop_0(i[2]);
if ( (int)dump_append(v12, &v11, v8, v7, i[4]) < 0 )
return 0xFFFFFFFFLL;
}
v3 = ++v10;
if ( (unsigned __int64)v10 >= *(_QWORD *)a1 )
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, char *a2, size_t a3)
{
__int64 v3; // r9
__int64 v4; // r15
void *v5; // r8
_QWORD *i; // r15
__int64 v7; // rax
const char *v8; // rdx
unsigned int v10; // [rsp+Ch] [rbp-4Ch]
size_t v11; // [rsp+10h] [rbp-48h] BYREF
char *v12[8]; // [rsp+18h] [rbp-40h] BYREF

v12[0] = 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;
v3 = 0LL;
v10 = 0;
if ( *(_QWORD *)a1 )
{
while ( 1 )
{
v4 = 16 * v3;
v5 = &LC1;
if ( !*(_QWORD *)(*((_QWORD *)a1 + 2) + 16 * v3) )
v5 = &LC0;
if ( (int)func2(v12, &v11, "Bucket nr %u:\n%s", v10, v5) < 0 )
return 0xFFFFFFFFLL;
for ( i = *(_QWORD **)(*((_QWORD *)a1 + 2) + v4); i; i = (_QWORD *)*i )
{
v7 = func3(i[2]);
if ( (int)func2(v12, &v11, v8, v7, i[4]) < 0 )
return 0xFFFFFFFFLL;
}
v3 = ++v10;
if ( (unsigned __int64)v10 >= *(_QWORD *)a1 )
return 0LL;
}
}
return 0LL;
}

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

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

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


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; // ebp
__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; // ebp
__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 v1; // rdi
__int128 v3; // [rsp+0h] [rbp-18h] BYREF

v1 = *a1;
v3 = 0LL;
return _bbus_sock_rdready(v1, &v3);
}

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

v1 = *a1;
v3 = 0LL;
return _bbus_sock_rdready(v1, &v3);
}

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

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

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

v2 = *a2;
*(_QWORD *)(a1 + 8LL * (v2 / 64)) |= 1LL << (v2 % 64);
update_highsock(a1, v2);
}

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

v2 = *a2;
*(_QWORD *)(a1 + 8LL * (v2 / 64)) |= 1LL << (v2 % 64);
update_highsock(a1, v2);
}

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 v3; // edi
int result; // eax
__int64 v5; // rdi
struct timeval v6; // [rsp+0h] [rbp-18h] BYREF

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

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

v3 = readfds[1].fds_bits[0];
v6 = *a2;
result = select(v3, readfds, 0LL, 0LL, &v6);
*a2 = v6;
if ( result < 0 )
{
v5 = (unsigned int)*_errno_location();
if ( (_DWORD)v5 == 4 )
v5 = 10015LL;
_bbus_seterr(v5);
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:
// attributes: thunk
__int64 __fastcall bbus_pollset_free(__int64 a1)
{
return bbus_srv_free_localalias(a1);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
return func14(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; // er12
size_t v6; // rax
__int128 v8[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = _bbus_sock_un_mksocket();
if ( v4 >= 0 )
{
v5 = v4;
if ( (int)_bbus_sock_un_connect((unsigned int)v4, a1) >= 0 )
{
v8[0] = 0LL;
_bbus_prot_hdrsetmagic(v8);
BYTE2(v8[0]) = 1;
BYTE3(v8[0]) = a2;
if ( a3 )
{
BYTE14(v8[0]) |= 1u;
v6 = strlen(a3);
bbus_hdr_setpsize(v8, v6 + 1);
}
if ( (int)_bbus_prot_sendvmsg(v5, v8, a3, 0LL, 0LL) >= 0 )
{
v8[0] = 0LL;
if ( (int)_bbus_prot_recvvmsg(v5, v8, 0LL, 0LL) >= 0 )
{
if ( BYTE2(v8[0]) == 2 )
return v5;
if ( BYTE2(v8[0]) == 3 )
_bbus_seterr(10009LL);
else
_bbus_seterr(10008LL);
}
}
_bbus_sock_close(v5);
}
}
return 0xFFFFFFFFLL;
}

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

v4 = _bbus_sock_un_mksocket();
if ( v4 >= 0 )
{
v5 = v4;
if ( (int)_bbus_sock_un_connect((unsigned int)v4, a1) >= 0 )
{
v8[0] = 0LL;
_bbus_prot_hdrsetmagic(v8);
BYTE2(v8[0]) = 1;
BYTE3(v8[0]) = a2;
if ( a3 )
{
BYTE14(v8[0]) |= 1u;
v6 = strlen(a3);
bbus_hdr_setpsize(v8, v6 + 1);
}
if ( (int)_bbus_prot_sendvmsg(v5, v8, a3, 0LL, 0LL) >= 0 )
{
v8[0] = 0LL;
if ( (int)_bbus_prot_recvvmsg(v5, v8, 0LL, 0LL) >= 0 )
{
if ( BYTE2(v8[0]) == 2 )
return v5;
if ( BYTE2(v8[0]) == 3 )
_bbus_seterr(10009LL);
else
_bbus_seterr(10008LL);
}
}
_bbus_sock_close(v5);
}
}
return 0xFFFFFFFFLL;
}

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

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
__int128 v2[2]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = 0LL;
_bbus_prot_hdrsetmagic(v2);
BYTE2(v2[0]) = 13;
if ( (int)_bbus_prot_sendvmsg(a1, v2, 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
__int128 v2[2]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = 0LL;
_bbus_prot_hdrsetmagic(v2);
BYTE2(v2[0]) = 13;
if ( (int)_bbus_prot_sendvmsg(a1, v2, 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;
}

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:
__int64 __fastcall bbusunit_registertest(_QWORD *a1)
{
__int64 result; // rax

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

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

result = qword_278;
if ( qword_278 )
{
*(_QWORD *)qword_278 = a1;
++tests_registered;
*a1 = 0LL;
qword_278 = (__int64)a1;
}
else
{
++tests_registered;
qword_278 = (__int64)a1;
tests = (__int64)a1;
*a1 = 0LL;
}
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 func2(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 func3(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);
}


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

canonical_decompiled_code:
void func4()
{
tests = 0LL;
qword_278 = 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);
}


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[16]; // [rsp+0h] [rbp-68h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
__int128 v11[4]; // [rsp+20h] [rbp-48h] BYREF

*(_OWORD *)v9 = 0LL;
tv = 0LL;
v11[0] = 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((struct timeval *)v9, 0LL);
if ( !v3 )
{
gettimeofday(&tv, 0LL);
timeval_diff_isra_0(v11, tv.tv_sec, tv.tv_usec, *(__int64 *)v9, *(__int64 *)&v9[8]);
bbusunit_print("All done!");
bbusunit_print("SUMMARY:");
bbusunit_print(" %u %s run in %d.%06d seconds.", 0LL, "tests", LODWORD(v11[0]), DWORD2(v11[0]));
LABEL_13:
bbusunit_print(" All tests PASSED!");
return 0;
}
v4 = 0;
v5 = 0;
do
{
while ( 1 )
{
bbusunit_print("Case:\t[%s]", *(const char **)(v3 + 8));
if ( (*(int (**)(void))(v3 + 16))() < 0 )
break;
v3 = *(_QWORD *)v3;
++v5;
if ( !v3 )
goto LABEL_6;
}
++v5;
++v4;
bbusunit_printerr("[%s]: TEST FAILED", *(const char **)(v3 + 8));
v3 = *(_QWORD *)v3;
}
while ( v3 );
LABEL_6:
gettimeofday(&tv, 0LL);
timeval_diff_isra_0(v11, tv.tv_sec, tv.tv_usec, *(__int64 *)v9, *(__int64 *)&v9[8]);
bbusunit_print("All done!");
bbusunit_print("SUMMARY:");
v6 = "tests";
if ( v5 == 1 )
v6 = "test";
bbusunit_print(" %u %s run in %d.%06d seconds.", (unsigned int)v5, v6, LODWORD(v11[0]), DWORD2(v11[0]));
if ( !v4 )
goto LABEL_13;
v7 = "tests";
if ( v4 == 1 )
v7 = "test";
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[16]; // [rsp+0h] [rbp-68h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
__int128 v11[4]; // [rsp+20h] [rbp-48h] BYREF

*(_OWORD *)v9 = 0LL;
tv = 0LL;
v11[0] = 0LL;
func2("##############################", argv, envp);
func2("####> Busybus unit-tests <####");
func2("##############################");
func2("%u tests registered.", (unsigned int)tests_registered);
func2("Running tests...");
v3 = tests;
gettimeofday((struct timeval *)v9, 0LL);
if ( !v3 )
{
gettimeofday(&tv, 0LL);
func0(v11, tv.tv_sec, tv.tv_usec, *(__int64 *)v9, *(__int64 *)&v9[8]);
func2("All done!");
func2("SUMMARY:");
func2(" %u %s run in %d.%06d seconds.", 0LL, "tests", LODWORD(v11[0]), DWORD2(v11[0]));
LABEL_13:
func2(" All tests PASSED!");
return 0;
}
v4 = 0;
v5 = 0;
do
{
while ( 1 )
{
func2("Case:\t[%s]", *(const char **)(v3 + 8));
if ( (*(int (**)(void))(v3 + 16))() < 0 )
break;
v3 = *(_QWORD *)v3;
++v5;
if ( !v3 )
goto LABEL_6;
}
++v5;
++v4;
func3("[%s]: TEST FAILED", *(const char **)(v3 + 8));
v3 = *(_QWORD *)v3;
}
while ( v3 );
LABEL_6:
gettimeofday(&tv, 0LL);
func0(v11, tv.tv_sec, tv.tv_usec, *(__int64 *)v9, *(__int64 *)&v9[8]);
func2("All done!");
func2("SUMMARY:");
v6 = "tests";
if ( v5 == 1 )
v6 = "test";
func2(" %u %s run in %d.%06d seconds.", (unsigned int)v5, v6, LODWORD(v11[0]), DWORD2(v11[0]));
if ( !v4 )
goto LABEL_13;
v7 = "tests";
if ( v4 == 1 )
v7 = "test";
func3(" %u %s FAILED", (unsigned int)v4, v7);
func3(" 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(_WORD *a1)
{
return *a1 == 0xC5BB;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_WORD *a1)
{
return *a1 == 0xC5BB;
}

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 func1(__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:
__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 func5(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);
}


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

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

canonical_decompiled_code:
char *func6()
{
char *v0; // r12

_bbus_spinlock_lock(&sockpath_lock);
v0 = (char *)hdr_check_magic + _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 func10(__int64 a1)
{
return func2(*(_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
__int64 v3; // rdx

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

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

result = func2(a2);
*(_DWORD *)(v3 + 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 func12(__int64 a1)
{
return (unsigned __int16)func3(*(_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);
}


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

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

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 func19(__int64 a1, unsigned __int64 a2)
{
__int16 result; // ax

result = -1;
if ( a2 <= 0xFFFF )
result = func3(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


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 func20()
{
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 *

variable_types:
path
char *


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:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5; // al
char v6; // al

if ( !bbus_mon_connect() )
{
bbus_lasterror();
v6 = bbus_strerror();
die("Error connecting to bbusd: %s\n", v6);
}
signal(15, sighandler);
signal(2, sighandler);
run = 1;
LABEL_3:
while ( (unsigned int)do_run() )
{
while ( 1 )
{
v3 = bbus_mon_recvmsg();
if ( v3 < 0 )
break;
if ( !v3 )
goto LABEL_3;
((void (__fastcall *)())print_msg_info)();
if ( !(unsigned int)do_run() )
goto LABEL_7;
}
if ( (unsigned int)bbus_lasterror() != 10015 )
{
bbus_lasterror();
v5 = bbus_strerror();
die("Error receiving message: %s\n", v5);
}
}
LABEL_7:
bbus_closeconn();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5; // al
char v6; // al

if ( !bbus_mon_connect() )
{
bbus_lasterror();
v6 = bbus_strerror();
func13("Error connecting to bbusd: %s\n", v6);
}
signal(15, sighandler);
signal(2, sighandler);
run = 1;
LABEL_3:
while ( (unsigned int)func15() )
{
while ( 1 )
{
v3 = bbus_mon_recvmsg();
if ( v3 < 0 )
break;
if ( !v3 )
goto LABEL_3;
((void (__fastcall *)())print_msg_info)();
if ( !(unsigned int)func15() )
goto LABEL_7;
}
if ( (unsigned int)bbus_lasterror() != 10015 )
{
bbus_lasterror();
v5 = bbus_strerror();
func13("Error receiving message: %s\n", v5);
}
}
LABEL_7:
bbus_closeconn();
return 0;
}

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:
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; // er8
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; // er8
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);
}


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:
__int64 bbus_str_build(char *format, ...)
{
__int64 v1; // rax
__int64 v2; // r12
int v3; // er13
signed __int64 v4; // rbx
__int64 v5; // r15
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

v1 = bbus_malloc(128LL);
v2 = 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;
v6 = (char *)bbus_realloc(v2, v4);
v2 = (__int64)v6;
if ( !v6 )
break;
va_end(arg);
va_start(arg, format);
if ( vsnprintf(v6, v4, format, arg) < v4 )
return v2;
if ( !--v3 )
{
v5 = v2;
_bbus_seterr(10004LL);
break;
}
}
v2 = 0LL;
bbus_free(v5);
}
}
return v2;
}

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

v1 = bbus_malloc(128LL);
v2 = 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;
v6 = (char *)bbus_realloc(v2, v4);
v2 = (__int64)v6;
if ( !v6 )
break;
va_end(arg);
va_start(arg, format);
if ( vsnprintf(v6, v4, format, arg) < v4 )
return v2;
if ( !--v3 )
{
v5 = v2;
_bbus_seterr(10004LL);
break;
}
}
v2 = 0LL;
bbus_free(v5);
}
}
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; // r12
char *v2; // rax
char *v3; // r8
char *v4; // rax

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

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v1; // r12
char *v2; // rax
char *v3; // r8
char *v4; // rax

v1 = strlen(src) + 1;
v2 = (char *)bbus_malloc(v1);
v3 = v2;
if ( v2 )
{
v4 = (char *)memset(v2, 0, v1);
v3 = strncpy(v4, 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