main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
int v5; // ebx
_DWORD *v6; // r12
socklen_t addr_len; // [rsp+4h] [rbp-A4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-A0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

v3 = 0LL;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "p:");
if ( v4 == -1 )
break;
if ( v4 == 112 )
v3 = optarg;
}
addr_len = 128;
if ( !v3 )
v3 = "1492";
v5 = init_socket(v3);
if ( v5 == -1 )
{
perror("Error returned in init_socket");
exit(1);
}
while ( 1 )
{
v6 = malloc(4uLL);
if ( !v6 )
break;
*v6 = accept(v5, &addr, &addr_len);
pthread_create(&newthread, 0LL, thread, v6);
}
perror("malloc error");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
int v5; // ebx
_DWORD *v6; // r12
socklen_t addr_len; // [rsp+4h] [rbp-A4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-A0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

v3 = 0LL;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "p:");
if ( v4 == -1 )
break;
if ( v4 == 112 )
v3 = optarg;
}
addr_len = 128;
if ( !v3 )
v3 = "1492";
v5 = func1(v3);
if ( v5 == -1 )
{
perror("Error returned in init_socket");
exit(1);
}
while ( 1 )
{
v6 = malloc(4uLL);
if ( !v6 )
break;
*v6 = accept(v5, &addr, &addr_len);
pthread_create(&newthread, 0LL, thread, v6);
}
perror("malloc error");
exit(1);
}

original_code:
int
main(int argc, char **argv)
{
    char *port = ((void *)0);
    int c;
    while ((c = getopt(argc, argv, "p:")) != -1)
        switch (c) {
            case 'p':
                port = optarg;
                break;
        }
    if (port == ((void *)0)) {
        port = "1492";
    }
    int sock_fd, *conn_fd;
    pthread_t tid;
    struct sockaddr_storage addr;
    socklen_t clientsize = sizeof(addr);
    sock_fd = init_socket(port);
    if (sock_fd == -1) {
        perror("Error returned in init_socket");
        exit(1);
        }
    for(;;) {
        conn_fd = malloc(sizeof(int));
        if (conn_fd == ((void *)0)) {
            perror("malloc error");
            exit(1);
        }
        *conn_fd = accept(sock_fd, (struct sockaddr *) &addr, &clientsize);
        pthread_create(&tid, ((void *)0), &thread, conn_fd);
    }
    pthread_rwlock_destroy(&rw_lock);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *port = ((void *)0);
    int c;
    while ((c = getopt(argc, argv, "p:")) != -1)
        switch (c) {
            case 'p':
                port = optarg;
                break;
        }
    if (port == ((void *)0)) {
        port = "1492";
    }
    int sock_fd; int *conn_fd;
    unsigned long tid;
    struct sockaddr_storage addr;
    unsigned int clientsize = sizeof(addr);
    sock_fd = init_socket(port);
    if (sock_fd == -1) {
        perror("Error returned in init_socket");
        exit(1);
        }
    for(;;) {
        conn_fd = malloc(sizeof(int));
        if (conn_fd == ((void *)0)) {
            perror("malloc error");
            exit(1);
        }
        *conn_fd = accept(sock_fd, (struct sockaddr *) &addr, &clientsize);
        pthread_create(&tid, ((void *)0), &thread, conn_fd);
    }
    pthread_rwlock_destroy(&rw_lock);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types:
tid
unsigned long

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
clientsize
unsigned int

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


set

repo: jschneier/Memcache

decompiled_code:
const char *__fastcall set(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rbp
_QWORD *v5; // rax
const char *result; // rax

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( v2 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[6];
if ( !v2 )
set_cold(a2);
}
while ( *v2 != a2[1] );
v4 = v2[6];
v5 = init_block(a2);
v3[6] = v5;
v5[6] = v4;
result = "STORED\r\n";
}
else
{
init_block(a2);
result = "STORED\r\n";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rbp
_QWORD *v5; // rax
const char *result; // rax

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( v2 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[6];
if ( !v2 )
func10(a2);
}
while ( *v2 != a2[1] );
v4 = v2[6];
v5 = init_block(a2);
v3[6] = v5;
v5[6] = v4;
result = "STORED\r\n";
}
else
{
init_block(a2);
result = "STORED\r\n";
}
return result;
}

original_code:
static char *
set(unsigned index, parsed_text *parsed)
{
    block *cur = database[index];
    if (cur == ((void *)0))
        cur = init_block(parsed);
    else {
        while(cur->next != ((void *)0) && cur->next->key != parsed->key)
            cur = cur->next;
        block *tmp = cur->next->next;
        cur->next = init_block(parsed);
        cur->next->next = tmp;
    }
    return "STORED\r\n";
}

canonical_original_code:
static char *set(unsigned int index, struct parsed_text *parsed)
{
    struct block *cur = database[index];
    if (cur == ((void *)0))
        cur = init_block(parsed);
    else {
        while(cur->next != ((void *)0) && cur->next->key != parsed->key)
            cur = cur->next;
        struct block *tmp = cur->next->next;
        cur->next = init_block(parsed);
        cur->next->next = tmp;
    }
    return "STORED\r\n";
}

variable_types:
index
unsigned int

variable_types: struct parsed_text { char *cmd; char *key; unsigned long flags; unsigned long exptime; unsigned long bytes; unsigned long cas_unique; unsigned long change; char *keys[10]; _Bool no_reply; char *data; } *

variable_types: struct block { char *key; char *data; unsigned long flags; unsigned long exptime; unsigned long bytes; unsigned long cas_unique; struct block *next; } *

return_type: char *


add

decompiled_code:
const char *__fastcall add(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax
const char *result; // rax

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( v2 )
{
do
{
v2 = (_QWORD *)v2[6];
if ( !v2 )
BUG();
}
while ( *v2 != a2[1] );
result = "NOT_STORED\r\n";
}
else
{
init_block(a2);
result = "STORED\r\n";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax
const char *result; // rax

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( v2 )
{
do
{
v2 = (_QWORD *)v2[6];
if ( !v2 )
BUG();
}
while ( *v2 != a2[1] );
result = "NOT_STORED\r\n";
}
else
{
init_block(a2);
result = "STORED\r\n";
}
return result;
}

original_code:
static char *
add(unsigned index, parsed_text *parsed)
{
    block *cur = database[index];
    if (cur == ((void *)0))
        cur = init_block(parsed);
    else {
        while(cur->next != ((void *)0) && cur->next->key != parsed->key)
            cur = cur->next;
        if (cur->next != ((void *)0))
            return "NOT_STORED\r\n";
        block *tmp = cur->next->next;
        cur->next = init_block(parsed);
        cur->next->next = tmp;
    }
    return "STORED\r\n";
}

canonical_original_code:
static char *add(unsigned int index, struct parsed_text *parsed)
{
    struct block *cur = database[index];
    if (cur == ((void *)0))
        cur = init_block(parsed);
    else {
        while(cur->next != ((void *)0) && cur->next->key != parsed->key)
            cur = cur->next;
        if (cur->next != ((void *)0))
            return "NOT_STORED\r\n";
        struct block *tmp = cur->next->next;
        cur->next = init_block(parsed);
        cur->next->next = tmp;
    }
    return "STORED\r\n";
}

user_defined_types: struct parsed_text { char *cmd; char *key; unsigned long flags; unsigned long exptime; unsigned long bytes; unsigned long cas_unique; unsigned long change; char *keys[10]; _Bool no_reply; char *data; }

user_defined_types: struct block { char *key; char *data; unsigned long flags; unsigned long exptime; unsigned long bytes; unsigned long cas_unique; struct block *next; }


replace

decompiled_code:
const char *__fastcall replace(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
__int64 v5; // rbp
_QWORD *v6; // rax

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( !v2 )
return "NOT_STORED\r\n";
do
{
v3 = v2;
v2 = (_QWORD *)v2[6];
if ( !v2 )
return "NOT_STORED\r\n";
}
while ( *v2 != a2[1] );
v5 = v2[6];
v6 = init_block(a2);
v3[6] = v6;
v6[6] = v5;
return "STORED\r\n";
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
__int64 v5; // rbp
_QWORD *v6; // rax

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( !v2 )
return "NOT_STORED\r\n";
do
{
v3 = v2;
v2 = (_QWORD *)v2[6];
if ( !v2 )
return "NOT_STORED\r\n";
}
while ( *v2 != a2[1] );
v5 = v2[6];
v6 = init_block(a2);
v3[6] = v6;
v6[6] = v5;
return "STORED\r\n";
}

original_code:
static char *
replace(unsigned index, parsed_text *parsed)
{
    block *cur = database[index];
    if (cur == ((void *)0))
        return "NOT_STORED\r\n";
    else {
        while(cur->next != ((void *)0) && cur->next->key != parsed->key)
            cur = cur->next;
        if (cur->next != ((void *)0)) {
            block *tmp = cur->next->next;
            cur->next = init_block(parsed);
            cur->next->next = tmp;
            return "STORED\r\n";
        }
        else
            return "NOT_STORED\r\n";
    }
}

canonical_original_code:
static char *replace(unsigned int index, struct parsed_text *parsed)
{
    struct block *cur = database[index];
    if (cur == ((void *)0))
        return "NOT_STORED\r\n";
    else {
        while(cur->next != ((void *)0) && cur->next->key != parsed->key)
            cur = cur->next;
        if (cur->next != ((void *)0)) {
            struct block *tmp = cur->next->next;
            cur->next = init_block(parsed);
            cur->next->next = tmp;
            return "STORED\r\n";
        }
        else
            return "NOT_STORED\r\n";
    }
}


pend

decompiled_code:
const char *__fastcall pend(unsigned int a1, __int64 a2)
{
_QWORD *v2; // rbx
const char *v4; // rcx
const char *v5; // r8
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( !v2 )
return "NOT_STORED\r\n";
while ( *v2 != *(_QWORD *)(a2 + 8) )
{
v2 = (_QWORD *)v2[6];
if ( !v2 )
return "NOT_STORED\r\n";
}
v4 = *(const char **)(a2 + 144);
if ( !strcmp(*(const char **)a2, "append") )
{
v5 = *(const char **)(a2 + 144);
v4 = (const char *)v2[1];
}
else
{
v5 = (const char *)v2[1];
}
snprintf(v6, 0x400uLL, "%s%s", v4, v5);
v2[1] = v6;
return "STORED\r\n";
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned int a1, __int64 a2)
{
_QWORD *v2; // rbx
const char *v4; // rcx
const char *v5; // r8
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = (_QWORD *)*((_QWORD *)&database + a1);
if ( !v2 )
return "NOT_STORED\r\n";
while ( *v2 != *(_QWORD *)(a2 + 8) )
{
v2 = (_QWORD *)v2[6];
if ( !v2 )
return "NOT_STORED\r\n";
}
v4 = *(const char **)(a2 + 144);
if ( !strcmp(*(const char **)a2, "append") )
{
v5 = *(const char **)(a2 + 144);
v4 = (const char *)v2[1];
}
else
{
v5 = (const char *)v2[1];
}
snprintf(v6, 0x400uLL, "%s%s", v4, v5);
v2[1] = v6;
return "STORED\r\n";
}

original_code:
static char *
pend(unsigned index, parsed_text *parsed)
{
    block *cur = database[index];
    char buf[1024];
    if (cur == ((void *)0))
        return "NOT_STORED\r\n";
    else {
        while(cur != ((void *)0) && cur->key != parsed->key)
            cur = cur->next;
        if (cur != ((void *)0)) {
            if ((strcmp(parsed->cmd, "append") == 0))
                snprintf(buf, 1024, "%s%s", cur->data, parsed->data);
            else
                snprintf(buf, 1024, "%s%s", parsed->data, cur->data);
            cur->data = buf;
            return "STORED\r\n";
        }
    }
    return "NOT_STORED\r\n";
}

canonical_original_code:
static char *pend(unsigned int index, struct parsed_text *parsed)
{
    struct block *cur = database[index];
    char buf[1024];
    if (cur == ((void *)0))
        return "NOT_STORED\r\n";
    else {
        while(cur != ((void *)0) && cur->key != parsed->key)
            cur = cur->next;
        if (cur != ((void *)0)) {
            if ((strcmp(parsed->cmd, "append") == 0))
                snprintf(buf, 1024, "%s%s", cur->data, parsed->data);
            else
                snprintf(buf, 1024, "%s%s", parsed->data, cur->data);
            cur->data = buf;
            return "STORED\r\n";
        }
    }
    return "NOT_STORED\r\n";
}

variable_types:
buf
char [1024]


decompiled_code:
const char *__fastcall incr_decr(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, char a8)
{
_QWORD *v8; // rbx
__int64 i; // rax
__int64 v10; // rdi
int v11; // edx
int v12; // ecx
int v13; // er8
int v14; // er9
const char *result; // rax
char v16; // [rsp+8h] [rbp-420h] BYREF

v8 = (_QWORD *)*((_QWORD *)&database + a1);
if ( !v8 )
return "NOT_FOUND\r\n";
for ( i = *(_QWORD *)(a2 + 8); *v8 != i; v8 = (_QWORD *)v8[6] )
;
v10 = v8[1];
if ( (unsigned int)_isoc99_sscanf(v10, "%llu", &v16) == -1 )
result = "BAD_VALUE\r\n";
else
result = (const char *)incr_decr_cold(v10, (int)"%llu", v11, v12, v13, v14, a7, a8);
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, char a8)
{
_QWORD *v8; // rbx
__int64 i; // rax
__int64 v10; // rdi
int v11; // edx
int v12; // ecx
int v13; // er8
int v14; // er9
const char *result; // rax
char v16; // [rsp+8h] [rbp-420h] BYREF

v8 = (_QWORD *)*((_QWORD *)&database + a1);
if ( !v8 )
return "NOT_FOUND\r\n";
for ( i = *(_QWORD *)(a2 + 8); *v8 != i; v8 = (_QWORD *)v8[6] )
;
v10 = v8[1];
if ( (unsigned int)_isoc99_sscanf(v10, "%llu", &v16) == -1 )
result = "BAD_VALUE\r\n";
else
result = (const char *)func11(v10, (int)"%llu", v11, v12, v13, v14, a7, a8);
return result;
}

original_code:
static char *
incr_decr(unsigned index, parsed_text *parsed)
{
    block *cur = database[index];
    char *ret;
    char buf[1024];
    if (cur == ((void *)0))
        return "NOT_FOUND\r\n";
    while (cur->key != parsed->key)
        cur = cur->next;
    if (cur == ((void *)0))
        return "NOT_FOUND\r\n";
    uint64_t value;
    int status = sscanf(cur->data, "%llu", &value);
    if (status == (-1))
        return "BAD_VALUE\r\n";
    if ((strcmp(parsed->cmd, "decr") == 0)) {
        if (parsed->change > value)
            value = 0;
        else
            value -= parsed->change;
    }
    else {
        value += parsed->change;
    }
    sprintf(buf, "%llu", value);
    cur->data = buf;
    sprintf(buf, "%llu\r\n", value);
    ret = buf;
    return ret;
}

canonical_original_code:
static char *incr_decr(unsigned int index, struct parsed_text *parsed)
{
    struct block *cur = database[index];
    char *ret;
    char buf[1024];
    if (cur == ((void *)0))
        return "NOT_FOUND\r\n";
    while (cur->key != parsed->key)
        cur = cur->next;
    if (cur == ((void *)0))
        return "NOT_FOUND\r\n";
    unsigned long value;
    int status = sscanf(cur->data, "%llu", &value);
    if (status == (-1))
        return "BAD_VALUE\r\n";
    if ((strcmp(parsed->cmd, "decr") == 0)) {
        if (parsed->change > value)
            value = 0;
        else
            value -= parsed->change;
    }
    else {
        value += parsed->change;
    }
    sprintf(buf, "%llu", value);
    cur->data = buf;
    sprintf(buf, "%llu\r\n", value);
    ret = buf;
    return ret;
}

variable_types:
ret
char *

variable_types:
value
unsigned long

variable_types: status int


store

decompiled_code:
const char *__fastcall store(const char **a1)
{
unsigned int v1; // eax

v1 = hash(a1[1]) & 0x7FF;
if ( !strcmp(*a1, "set") )
return set(v1, a1);
if ( !strcmp(*a1, "add") )
return add(v1, a1);
if ( !strcmp(*a1, "replace") )
return replace(v1, a1);
if ( !strcmp(*a1, "append") || !strcmp(*a1, "prepend") )
return pend(v1, (__int64)a1);
return "FOO";
}

canonical_decompiled_code:
const char *__fastcall func6(const char **a1)
{
unsigned int v1; // eax

v1 = hash(a1[1]) & 0x7FF;
if ( !strcmp(*a1, "set") )
return func0(v1, a1);
if ( !strcmp(*a1, "add") )
return func1(v1, a1);
if ( !strcmp(*a1, "replace") )
return func2(v1, a1);
if ( !strcmp(*a1, "append") || !strcmp(*a1, "prepend") )
return func3(v1, (__int64)a1);
return "FOO";
}

original_code:
char *
store(parsed_text *parsed)
{
    unsigned index = hash(parsed->key) % 2048;
    if ((strcmp(parsed->cmd, "set") == 0))
        return set(index, parsed);
    else if ((strcmp(parsed->cmd, "add") == 0))
        return add(index, parsed);
    else if ((strcmp(parsed->cmd, "replace") == 0))
        return replace(index, parsed);
    else if ((strcmp(parsed->cmd, "append") == 0) || (strcmp(parsed->cmd, "prepend") == 0))
        return pend(index, parsed);
    else
        return "FOO";
}

canonical_original_code:
char *store(struct parsed_text *parsed)
{
    unsigned int index = hash(parsed->key) % 2048;
    if ((strcmp(parsed->cmd, "set") == 0))
        return set(index, parsed);
    else if ((strcmp(parsed->cmd, "add") == 0))
        return add(index, parsed);
    else if ((strcmp(parsed->cmd, "replace") == 0))
        return replace(index, parsed);
    else if ((strcmp(parsed->cmd, "append") == 0) || (strcmp(parsed->cmd, "prepend") == 0))
        return pend(index, parsed);
    else
        return "FOO";
}


change

decompiled_code:
const char *__fastcall change(const char **a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, char a8)
{
bool v9; // cf
bool v10; // zf
__int16 v11; // ax
__int64 v12; // r8
__int64 v13; // r9
const char *v14; // rsi
const char *v15; // rdi
__int64 v16; // rcx
const char *result; // rax

v11 = hash(a1[1]);
v14 = *a1;
v15 = "touch";
v16 = 6LL;
do
{
if ( !v16 )
break;
v9 = *v14 < (unsigned int)*v15;
v10 = *v14++ == *v15++;
--v16;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
result = touch_constprop_0();
else
result = incr_decr(v11 & 0x7FF, (__int64)a1, v11 & 0x7FF, v16, v12, v13, a7, a8);
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(const char **a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, char a8)
{
bool v9; // cf
bool v10; // zf
__int16 v11; // ax
__int64 v12; // r8
__int64 v13; // r9
const char *v14; // rsi
const char *v15; // rdi
__int64 v16; // rcx
const char *result; // rax

v11 = hash(a1[1]);
v14 = *a1;
v15 = "touch";
v16 = 6LL;
do
{
if ( !v16 )
break;
v9 = *v14 < (unsigned int)*v15;
v10 = *v14++ == *v15++;
--v16;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
result = func5();
else
result = func4(v11 & 0x7FF, (__int64)a1, v11 & 0x7FF, v16, v12, v13, a7, a8);
return result;
}

original_code:
char *
change(parsed_text *parsed)
{
    unsigned index = hash(parsed->key) % 2048;
    if ((strcmp(parsed->cmd, "touch") == 0))
        return touch(index, parsed);
    else
        return incr_decr(index, parsed);
}

canonical_original_code:
char *change(struct parsed_text *parsed)
{
    unsigned int index = hash(parsed->key) % 2048;
    if ((strcmp(parsed->cmd, "touch") == 0))
        return touch(index, parsed);
    else
        return incr_decr(index, parsed);
}


delete

decompiled_code:
const char *__fastcall delete(__int64 a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 v4; // rbx
const char *result; // rax

v2 = (_QWORD *)*((_QWORD *)&database + (hash(*(_QWORD *)(a1 + 8)) & 0x7FF));
do
{
v3 = v2;
v2 = (_QWORD *)v2[6];
if ( !v2 )
delete_cold();
}
while ( *v2 != *(_QWORD *)(a1 + 8) );
v4 = v2[6];
free(v2);
result = "DELETED\r\n";
v3[6] = v4;
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(__int64 a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 v4; // rbx
const char *result; // rax

v2 = (_QWORD *)*((_QWORD *)&database + (hash(*(_QWORD *)(a1 + 8)) & 0x7FF));
do
{
v3 = v2;
v2 = (_QWORD *)v2[6];
if ( !v2 )
func12();
}
while ( *v2 != *(_QWORD *)(a1 + 8) );
v4 = v2[6];
free(v2);
result = "DELETED\r\n";
v3[6] = v4;
return result;
}

original_code:
char *
delete(parsed_text *parsed)
{
    unsigned index = hash(parsed->key) % 2048;
    block *cur = database[index];
    while(cur->next != ((void *)0) && cur->next->key != parsed->key)
        cur = cur->next;
    if (cur == ((void *)0))
        return "NOT_FOUND\r\n";
    block *tmp = cur->next->next;
    free(cur->next);
    cur->next = tmp;
    return "DELETED\r\n";
}

canonical_original_code:
char *delete(struct parsed_text *parsed)
{
    unsigned int index = hash(parsed->key) % 2048;
    struct block *cur = database[index];
    while(cur->next != ((void *)0) && cur->next->key != parsed->key)
        cur = cur->next;
    if (cur == ((void *)0))
        return "NOT_FOUND\r\n";
    struct block *tmp = cur->next->next;
    free(cur->next);
    cur->next = tmp;
    return "DELETED\r\n";
}


get

original_code:
void
get(parsed_text *parsed, char *messages[10][2])
{
    int i;
    block *cur;
    char *key;
    for(i=0; i<10; i++) {
        key = parsed->keys[i];
        cur = database[hash(key) % 2048];
        while(cur != ((void *)0) && cur->key != key)
            cur = cur->next;
        if(cur == ((void *)0))
            continue;
        else {
            sprintf(messages[i][0], "VALUE %s %lu %lu\r\n", key, cur->flags, cur->bytes);
            sprintf(messages[i][1], "%s\r\n", cur->data);
        }
    }
}

canonical_original_code:
void get(struct parsed_text *parsed, char *messages[10][2])
{
    int i;
    struct block *cur;
    char *key;
    for(i=0; i<10; i++) {
        key = parsed->keys[i];
        cur = database[hash(key) % 2048];
        while(cur != ((void *)0) && cur->key != key)
            cur = cur->next;
        if(cur == ((void *)0))
            continue;
        else {
            sprintf(messages[i][0], "VALUE %s %lu %lu\r\n", key, cur->flags, cur->bytes);
            sprintf(messages[i][1], "%s\r\n", cur->data);
        }
    }
}

variable_types:
messages
char *[10][2]

variable_types: i int

variable_types:
key
char *

return_type: void


hash

decompiled_code:
__int64 __fastcall hash(char *a1)
{
int v1; // eax
char *v2; // rsi
unsigned int v3; // ecx

v1 = *a1;
v2 = a1 + 1;
if ( !(_BYTE)v1 )
return 5381LL;
v3 = 5381;
do
{
++v2;
v3 += 32 * v3 + v1;
v1 = *(v2 - 1);
}
while ( (_BYTE)v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
int v1; // eax
char *v2; // rsi
unsigned int v3; // ecx

v1 = *a1;
v2 = a1 + 1;
if ( !(_BYTE)v1 )
return 5381LL;
v3 = 5381;
do
{
++v2;
v3 += 32 * v3 + v1;
v1 = *(v2 - 1);
}
while ( (_BYTE)v1 );
return v3;
}

original_code:
unsigned
hash(char *str)
{
    unsigned long hash = 5381;
    int c;
    while ((c = *str++))
        hash = ((hash << 5) + hash) + c;
    return hash;
}

canonical_original_code:
unsigned int hash(char *str)
{
    unsigned long hash = 5381;
    int c;
    while ((c = *str++))
        hash = ((hash << 5) + hash) + c;
    return hash;
}

variable_types:
str
char *

variable_types:
hash
unsigned long

return_type: unsigned int


decompiled_code:
__int64 __fastcall strip_n_trailing_spaces(const char *a1, int a2)
{
__int64 result; // rax
const char *v3; // rbx
const unsigned __int16 *v4; // rcx
const char *v5; // rdx

result = (int)strlen(a1);
v3 = &a1[(int)result - 1];
if ( a2 > 0 )
{
v4 = *_ctype_b_loc();
v5 = &v3[~(unsigned __int64)(unsigned int)(a2 - 1)];
do
{
result = *v3;
if ( (v4[result] & 0x2000) == 0 )
break;
--v3;
}
while ( v3 != v5 );
}
*v3 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, int a2)
{
__int64 result; // rax
const char *v3; // rbx
const unsigned __int16 *v4; // rcx
const char *v5; // rdx

result = (int)strlen(a1);
v3 = &a1[(int)result - 1];
if ( a2 > 0 )
{
v4 = *_ctype_b_loc();
v5 = &v3[~(unsigned __int64)(unsigned int)(a2 - 1)];
do
{
result = *v3;
if ( (v4[result] & 0x2000) == 0 )
break;
--v3;
}
while ( v3 != v5 );
}
*v3 = 0;
return result;
}

original_code:
void
strip_n_trailing_spaces(char *str, int n)
{
    int size = strlen(str);
    char *end = str + size - 1;
    int i;
    for(i=0; i<n; i++) {
        if (((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace))
            end--;
        else
            break;
    }
    *end = '\0';
}

canonical_original_code:
void strip_n_trailing_spaces(char *str, int n)
{
    int size = strlen(str);
    char *end = str + size - 1;
    int i;
    for(i=0; i<n; i++) {
        if (((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace))
            end--;
        else
            break;
    }
    *end = '\0';
}

variable_types: n int

variable_types: size int

variable_types:
end
char *


decompiled_code:
__int64 __fastcall parse_cmd(char *src)
{
char *v1; // rax
const char *v2; // r8
bool v3; // zf
__int64 result; // rax
char v5[1032]; // [rsp+0h] [rbp-408h] BYREF

strncpy(v5, src, 0xAuLL);
v1 = strtok(v5, " ");
if ( !v1 )
return 6LL;
v2 = v1;
v3 = strcmp(v1, "set") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "add") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "replace") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "append") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "prepend") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "cas") == 0;
result = !v3;
if ( !v3 )
{
result = 1LL;
if ( strcmp(v2, "get") )
{
if ( strcmp(v2, "gets") )
{
result = 2LL;
if ( strcmp(v2, "delete") )
{
result = 3LL;
if ( strcmp(v2, "incr") )
{
if ( strcmp(v2, "decr") && strcmp(v2, "touch") )
{
result = 4LL;
if ( strcmp(v2, "stats") )
result = 5 - ((unsigned int)(strcmp(v2, "quit") == 0) - 1);
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
char *v1; // rax
const char *v2; // r8
bool v3; // zf
__int64 result; // rax
char v5[1032]; // [rsp+0h] [rbp-408h] BYREF

strncpy(v5, src, 0xAuLL);
v1 = strtok(v5, " ");
if ( !v1 )
return 6LL;
v2 = v1;
v3 = strcmp(v1, "set") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "add") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "replace") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "append") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "prepend") == 0;
result = !v3;
if ( !v3 )
{
v3 = strcmp(v2, "cas") == 0;
result = !v3;
if ( !v3 )
{
result = 1LL;
if ( strcmp(v2, "get") )
{
if ( strcmp(v2, "gets") )
{
result = 2LL;
if ( strcmp(v2, "delete") )
{
result = 3LL;
if ( strcmp(v2, "incr") )
{
if ( strcmp(v2, "decr") && strcmp(v2, "touch") )
{
result = 4LL;
if ( strcmp(v2, "stats") )
result = 5 - ((unsigned int)(strcmp(v2, "quit") == 0) - 1);
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
int
parse_cmd(char *buf)
{
    char tmp[1024];
    strncpy(tmp, buf, 10);
    char *cmd = strtok(tmp, " ");
    if (cmd == ((void *)0))
        return ERROR;
    if ((strcmp(cmd, "set") == 0) || (strcmp(cmd, "add") == 0) || (strcmp(cmd, "replace") == 0) ||
            (strcmp(cmd, "append") == 0) || (strcmp(cmd, "prepend") == 0) || (strcmp(cmd, "cas") == 0))
        return STORE;
    else if ((strcmp(cmd, "get") == 0) || (strcmp(cmd, "gets") == 0))
        return GET;
    else if ((strcmp(cmd, "delete") == 0))
        return DEL;
    else if ((strcmp(cmd, "incr") == 0) || (strcmp(cmd, "decr") == 0) || (strcmp(cmd, "touch") == 0))
        return CHANGE;
    else if ((strcmp(cmd, "stats") == 0))
        return STATS;
    else if ((strcmp(cmd, "quit") == 0))
        return QUIT;
    else
        return ERROR;
}

variable_types:
buf
char *

variable_types:
tmp
char [1024]

variable_types:
cmd
char *

return_type: int


decompiled_code:
char *__fastcall parse_store(char *a1, __int64 a2)
{
char *v3; // rdx
char *result; // rax
char *v5; // rdi
__int64 v6; // rdx
char *v7; // rdi
unsigned __int64 v8; // rdx
char *v9; // rdi
unsigned __int64 v10; // rdx
char *v11; // rdi
unsigned __int64 v12; // rdx
const char *v13; // rsi
char *endptr[2]; // [rsp+8h] [rbp-10h] BYREF

*(_QWORD *)a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
result = "CLIENT_ERROR: no key received\r\n";
if ( v3 )
{
*(_QWORD *)(a2 + 8) = v3;
v5 = strtok(0LL, " ");
result = "CLIENT_ERROR: no flags received\r\n";
if ( v5 )
{
v6 = strtol(v5, endptr, 10);
result = "CLIENT_ERROR: flags not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 16) = v6;
v7 = strtok(0LL, " ");
result = "CLIENT_ERROR: no exptime received\r\n";
if ( v7 )
{
v8 = strtoul(v7, endptr, 10);
result = "CLIENT_ERROR: exptime not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 24) = v8;
v9 = strtok(0LL, " ");
result = "CLIENT_ERROR: no bytes (length) received\r\n";
if ( v9 )
{
v10 = strtoul(v9, endptr, 10);
result = "CLIENT_ERROR: bytes not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 32) = v10;
if ( strcmp("cas", *(const char **)a2) )
goto LABEL_12;
v11 = strtok(0LL, " ");
result = "CLIENT_ERROR: didn't receive cas unique\r\n";
if ( v11 )
{
v12 = strtoull(v11, endptr, 10);
result = "CLIENT_ERROR: cas unique not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 40) = v12;
LABEL_12:
result = strtok(0LL, " ");
if ( result )
{
v13 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v13, "noreply") )
{
*(_BYTE *)(a2 + 136) = 1;
result = 0LL;
}
}
else
{
*(_BYTE *)(a2 + 136) = 0;
}
return result;
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, __int64 a2)
{
char *v3; // rdx
char *result; // rax
char *v5; // rdi
__int64 v6; // rdx
char *v7; // rdi
unsigned __int64 v8; // rdx
char *v9; // rdi
unsigned __int64 v10; // rdx
char *v11; // rdi
unsigned __int64 v12; // rdx
const char *v13; // rsi
char *endptr[2]; // [rsp+8h] [rbp-10h] BYREF

*(_QWORD *)a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
result = "CLIENT_ERROR: no key received\r\n";
if ( v3 )
{
*(_QWORD *)(a2 + 8) = v3;
v5 = strtok(0LL, " ");
result = "CLIENT_ERROR: no flags received\r\n";
if ( v5 )
{
v6 = strtol(v5, endptr, 10);
result = "CLIENT_ERROR: flags not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 16) = v6;
v7 = strtok(0LL, " ");
result = "CLIENT_ERROR: no exptime received\r\n";
if ( v7 )
{
v8 = strtoul(v7, endptr, 10);
result = "CLIENT_ERROR: exptime not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 24) = v8;
v9 = strtok(0LL, " ");
result = "CLIENT_ERROR: no bytes (length) received\r\n";
if ( v9 )
{
v10 = strtoul(v9, endptr, 10);
result = "CLIENT_ERROR: bytes not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 32) = v10;
if ( strcmp("cas", *(const char **)a2) )
goto LABEL_12;
v11 = strtok(0LL, " ");
result = "CLIENT_ERROR: didn't receive cas unique\r\n";
if ( v11 )
{
v12 = strtoull(v11, endptr, 10);
result = "CLIENT_ERROR: cas unique not number\r\n";
if ( !*endptr[0] )
{
*(_QWORD *)(a2 + 40) = v12;
LABEL_12:
result = strtok(0LL, " ");
if ( result )
{
v13 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v13, "noreply") )
{
*(_BYTE *)(a2 + 136) = 1;
result = 0LL;
}
}
else
{
*(_BYTE *)(a2 + 136) = 0;
}
return result;
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
char *
parse_store(char *buf, parsed_text *parsed)
{
    char *end;
    char *cur = strtok(buf, " ");
    unsigned long dat;
    parsed->cmd = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no key received\r\n";
    parsed->key = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no flags received\r\n";
    dat = strtol(cur, &end, 10);
    if(*end != '\0')
        return "CLIENT_ERROR: flags not number\r\n";
    parsed->flags = dat;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no exptime received\r\n";
    dat = strtoul(cur, &end, 10);
    if (*end != '\0')
        return "CLIENT_ERROR: exptime not number\r\n";
    parsed->exptime = dat;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no bytes (length) received\r\n";
    dat = strtoul(cur, &end, 10);
    if (*end != '\0')
        return "CLIENT_ERROR: bytes not number\r\n";
    parsed->bytes = dat;
    if ((strcmp("cas", parsed->cmd) == 0)) {
        cur = strtok(((void *)0), " ");
        if (cur == ((void *)0))
            return "CLIENT_ERROR: didn't receive cas unique\r\n";
        uint64_t cas = strtoull(cur, &end, 10);
        if (*end != '\0')
            return "CLIENT_ERROR: cas unique not number\r\n";
        parsed->cas_unique = cas;
    }
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}

canonical_original_code:
char *parse_store(char *buf, struct parsed_text *parsed)
{
    char *end;
    char *cur = strtok(buf, " ");
    unsigned long dat;
    parsed->cmd = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no key received\r\n";
    parsed->key = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no flags received\r\n";
    dat = strtol(cur, &end, 10);
    if(*end != '\0')
        return "CLIENT_ERROR: flags not number\r\n";
    parsed->flags = dat;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no exptime received\r\n";
    dat = strtoul(cur, &end, 10);
    if (*end != '\0')
        return "CLIENT_ERROR: exptime not number\r\n";
    parsed->exptime = dat;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no bytes (length) received\r\n";
    dat = strtoul(cur, &end, 10);
    if (*end != '\0')
        return "CLIENT_ERROR: bytes not number\r\n";
    parsed->bytes = dat;
    if ((strcmp("cas", parsed->cmd) == 0)) {
        cur = strtok(((void *)0), " ");
        if (cur == ((void *)0))
            return "CLIENT_ERROR: didn't receive cas unique\r\n";
        unsigned long cas = strtoull(cur, &end, 10);
        if (*end != '\0')
            return "CLIENT_ERROR: cas unique not number\r\n";
        parsed->cas_unique = cas;
    }
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}

variable_types: struct parsed_text { char *cmd; char *key; unsigned long flags; unsigned long exptime; unsigned long bytes; unsigned long cas_unique; unsigned long change; char *keys[10]; _Bool no_reply; char *data; } *

variable_types:
cur
char *

variable_types:
dat
unsigned long

variable_types:
cas
unsigned long


decompiled_code:
char *__fastcall parse_change(char *a1, __int64 a2)
{
char *v3; // rdx
char *result; // rax
char *v5; // rdi
unsigned __int64 v6; // rdx
const char *v7; // rsi
char *endptr; // [rsp+8h] [rbp-10h] BYREF

*(_QWORD *)a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
result = "CLIENT_ERROR: no key received\r\n";
if ( v3 )
{
*(_QWORD *)(a2 + 8) = v3;
v5 = strtok(0LL, " ");
result = "CLIENT_ERROR: didn't receive value\r\n";
if ( v5 )
{
v6 = strtoull(v5, &endptr, 10);
result = "CLIENT_ERROR: value not number\r\n";
if ( !*endptr )
{
*(_QWORD *)(a2 + 48) = v6;
result = strtok(0LL, " ");
if ( result )
{
v7 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v7, "noreply") )
{
*(_BYTE *)(a2 + 136) = 1;
result = 0LL;
}
}
else
{
*(_BYTE *)(a2 + 136) = 0;
}
}
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, __int64 a2)
{
char *v3; // rdx
char *result; // rax
char *v5; // rdi
unsigned __int64 v6; // rdx
const char *v7; // rsi
char *endptr; // [rsp+8h] [rbp-10h] BYREF

*(_QWORD *)a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
result = "CLIENT_ERROR: no key received\r\n";
if ( v3 )
{
*(_QWORD *)(a2 + 8) = v3;
v5 = strtok(0LL, " ");
result = "CLIENT_ERROR: didn't receive value\r\n";
if ( v5 )
{
v6 = strtoull(v5, &endptr, 10);
result = "CLIENT_ERROR: value not number\r\n";
if ( !*endptr )
{
*(_QWORD *)(a2 + 48) = v6;
result = strtok(0LL, " ");
if ( result )
{
v7 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v7, "noreply") )
{
*(_BYTE *)(a2 + 136) = 1;
result = 0LL;
}
}
else
{
*(_BYTE *)(a2 + 136) = 0;
}
}
}
}
return result;
}

original_code:
char *
parse_change(char *buf, parsed_text *parsed)
{
    char *end;
    char *cur = strtok(buf, " ");
    uint64_t val;
    parsed->cmd = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no key received\r\n";
    parsed->key = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: didn't receive value\r\n";
    val = strtoull(cur, &end, 10);
    if (*end != '\0')
        return "CLIENT_ERROR: value not number\r\n";
    parsed->change = val;
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}

canonical_original_code:
char *parse_change(char *buf, struct parsed_text *parsed)
{
    char *end;
    char *cur = strtok(buf, " ");
    unsigned long val;
    parsed->cmd = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no key received\r\n";
    parsed->key = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: didn't receive value\r\n";
    val = strtoull(cur, &end, 10);
    if (*end != '\0')
        return "CLIENT_ERROR: value not number\r\n";
    parsed->change = val;
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}

variable_types:
val
unsigned long


decompiled_code:
char *__fastcall parse_get(char *a1, char **a2)
{
char *v3; // rax
char **v4; // rbx
char *v5; // rax
char *result; // rax
const char *v7; // rsi

*a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
if ( !v3 )
return "CLIENT_ERROR: no keys provided in get command\r\n";
a2[7] = v3;
v4 = a2 + 8;
do
{
v5 = strtok(0LL, " ");
if ( !v5 )
break;
*v4++ = v5;
}
while ( a2 + 17 != v4 );
result = strtok(0LL, " ");
if ( result )
{
v7 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v7, "noreply") )
{
*((_BYTE *)a2 + 136) = 1;
result = 0LL;
}
}
else
{
*((_BYTE *)a2 + 136) = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1, char **a2)
{
char *v3; // rax
char **v4; // rbx
char *v5; // rax
char *result; // rax
const char *v7; // rsi

*a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
if ( !v3 )
return "CLIENT_ERROR: no keys provided in get command\r\n";
a2[7] = v3;
v4 = a2 + 8;
do
{
v5 = strtok(0LL, " ");
if ( !v5 )
break;
*v4++ = v5;
}
while ( a2 + 17 != v4 );
result = strtok(0LL, " ");
if ( result )
{
v7 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v7, "noreply") )
{
*((_BYTE *)a2 + 136) = 1;
result = 0LL;
}
}
else
{
*((_BYTE *)a2 + 136) = 0;
}
return result;
}

original_code:
char *
parse_get(char *buf, parsed_text *parsed)
{
    char *cur = strtok(buf, " ");
    parsed->cmd = cur;
    int i = 0;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no keys provided in get command\r\n";
    parsed->keys[i] = cur;
    ++i;
    while (i < 10 && ((cur = strtok(((void *)0), " ")) != ((void *)0)))
        parsed->keys[i++] = cur;
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}

canonical_original_code:
char *parse_get(char *buf, struct parsed_text *parsed)
{
    char *cur = strtok(buf, " ");
    parsed->cmd = cur;
    int i = 0;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no keys provided in get command\r\n";
    parsed->keys[i] = cur;
    ++i;
    while (i < 10 && ((cur = strtok(((void *)0), " ")) != ((void *)0)))
        parsed->keys[i++] = cur;
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}


decompiled_code:
char *__fastcall parse_del(char *a1, __int64 a2)
{
char *v3; // rdx
char *result; // rax
const char *v5; // rsi

*(_QWORD *)a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
result = "CLIENT_ERROR: no key provided for delete\r\n";
if ( v3 )
{
*(_QWORD *)(a2 + 8) = v3;
result = strtok(0LL, " ");
if ( result )
{
v5 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v5, "noreply") )
{
*(_BYTE *)(a2 + 136) = 1;
result = 0LL;
}
}
else
{
*(_BYTE *)(a2 + 136) = 0;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *a1, __int64 a2)
{
char *v3; // rdx
char *result; // rax
const char *v5; // rsi

*(_QWORD *)a2 = strtok(a1, " ");
v3 = strtok(0LL, " ");
result = "CLIENT_ERROR: no key provided for delete\r\n";
if ( v3 )
{
*(_QWORD *)(a2 + 8) = v3;
result = strtok(0LL, " ");
if ( result )
{
v5 = result;
result = "CLIENT_ERROR: too many tokens sent\r\n";
if ( !strcmp(v5, "noreply") )
{
*(_BYTE *)(a2 + 136) = 1;
result = 0LL;
}
}
else
{
*(_BYTE *)(a2 + 136) = 0;
}
}
return result;
}

original_code:
char *
parse_del(char *buf, parsed_text *parsed)
{
    char *cur = strtok(buf, " ");
    parsed->cmd = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no key provided for delete\r\n";
    parsed->key = cur;
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}

canonical_original_code:
char *parse_del(char *buf, struct parsed_text *parsed)
{
    char *cur = strtok(buf, " ");
    parsed->cmd = cur;
    cur = strtok(((void *)0), " ");
    if (cur == ((void *)0))
        return "CLIENT_ERROR: no key provided for delete\r\n";
    parsed->key = cur;
    cur = strtok(((void *)0), " "); if (cur == ((void *)0)) { parsed->no_reply = 0; return ((void *)0); } else if ((strcmp(cur, "noreply") == 0)) { parsed->no_reply = 1; return ((void *)0); } else return "CLIENT_ERROR: too many tokens sent\r\n";
}


min

repo: jserv/scalable-font-editor

decompiled_code:
double __fastcall min(double a1, double a2)
{
return fmin(a1, a2);
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2)
{
return fmin(a1, a2);
}

original_code:
double min (double a, double b)
{
 return a < b ? a : b;
}

canonical_original_code:
double min(double a, double b)
{
 return a < b ? a : b;
}

variable_types: a double

variable_types: b double

return_type: double


max

decompiled_code:
double __fastcall max(double a1, double a2)
{
return fmax(a1, a2);
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2)
{
return fmax(a1, a2);
}

original_code:
double max (double a, double b)
{
 return a > b ? a : b;
}

canonical_original_code:
double max(double a, double b)
{
 return a > b ? a : b;
}


decompiled_code:
__m128d __fastcall my_abs(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)LC1);
return result;
}

canonical_decompiled_code:
__m128d __fastcall func2(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)LC1);
return result;
}

original_code:
double my_abs (double a)
{
 return a < 0 ? -a : a;
}

canonical_original_code:
double my_abs(double a)
{
 return a < 0 ? -a : a;
}


sqrt

decompiled_code:
double __fastcall sqrt(double x)
{
double result; // xmm0_8
double v3; // xmm2_8

result = 0.0;
if ( x >= 0.0 )
{
result = x * 0.5;
v3 = x / (x * 0.5);
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(x * 0.5 - v3) & LC3) / (x * 0.5) > 1.0e-15 )
{
do
{
result = (result + v3) * 0.5;
v3 = x / result;
}
while ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(result - x / result) & LC3) / result > 1.0e-15 );
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func3(double x)
{
double result; // xmm0_8
double v3; // xmm2_8

result = 0.0;
if ( x >= 0.0 )
{
result = x * 0.5;
v3 = x / (x * 0.5);
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(x * 0.5 - v3) & LC3) / (x * 0.5) > 1.0e-15 )
{
do
{
result = (result + v3) * 0.5;
v3 = x / result;
}
while ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(result - x / result) & LC3) / result > 1.0e-15 );
}
}
return result;
}

original_code:
double sqrt(double x)
{
 double i = x / 2;
 if (x < 0)
  return 0;
 while (fabs(i - (x / i)) / i > 0.000000000000001)
  i = (i + (x / i)) / 2;
 return i;
}

variable_types: x double

variable_types: i double


decompiled_code:
_QWORD *new_pts()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
pts_t *new_pts (void)
{
 pts_t *pts = malloc (sizeof (pts_t));
 pts->n = 0;
 pts->s = 0;
 pts->pt = 0;
 return pts;
}

canonical_original_code:
struct _pts_t *new_pts()
{
 struct _pts_t *pts = malloc (sizeof (pts_t));
 pts->n = 0;
 pts->s = 0;
 pts->pt = 0;
 return pts;
}

variable_types: struct _pts_t { int n; int s; struct pt_t { double x; } *pt; } *

user_defined_types: struct _pts_t { int n; int s; struct pt_t *pt; }


decompiled_code:
void __fastcall dispose_pts(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void dispose_pts (pts_t *pts)
{
 if (pts->pt)
  free (pts->pt);
 free (pts);
}

canonical_original_code:
void dispose_pts(struct _pts_t *pts)
{
 if (pts->pt)
  free (pts->pt);
 free (pts);
}


decompiled_code:
double __fastcall distance_to_point(double *a1, double *a2)
{
return sqrt((*a2 - *a1) * (*a2 - *a1) + (a2[1] - a1[1]) * (a2[1] - a1[1]));
}

original_code:
double distance_to_point (pt_t * a, pt_t * b)
{
 double dx = (b->x - a->x);
 double dy = (b->y - a->y);
 return sqrt (dx*dx + dy*dy);
}

canonical_original_code:
double distance_to_point(struct pt_t *a, struct pt_t *b)
{
 double dx = (b->x - a->x);
 double dy = (b->y - a->y);
 return sqrt (dx*dx + dy*dy);
}

variable_types:
a
struct pt_t { double x; } *

variable_types:
b
struct pt_t *

variable_types: dx double

variable_types: dy double


decompiled_code:
double __fastcall distance_to_line(double *a1, double *a2, double *a3)
{
double v3; // xmm3_8
double v4; // xmm6_8
double v5; // xmm5_8
double v6; // xmm2_8
double result; // xmm0_8

v3 = a2[1];
v4 = a3[1] - v3;
v5 = *a2 - *a3;
v6 = v5 * v5 + v4 * v4;
if ( v6 == 0.0 )
result = distance_to_point(a1, a2);
else
result = sqrt((*a3 * v3 - a3[1] * *a2 + *a1 * v4 + v5 * a1[1]) * (*a3 * v3 - a3[1] * *a2 + *a1 * v4 + v5 * a1[1]) / v6);
return result;
}

canonical_decompiled_code:
double __fastcall func8(double *a1, double *a2, double *a3)
{
double v3; // xmm3_8
double v4; // xmm6_8
double v5; // xmm5_8
double v6; // xmm2_8
double result; // xmm0_8

v3 = a2[1];
v4 = a3[1] - v3;
v5 = *a2 - *a3;
v6 = v5 * v5 + v4 * v4;
if ( v6 == 0.0 )
result = func7(a1, a2);
else
result = func3((*a3 * v3 - a3[1] * *a2 + *a1 * v4 + v5 * a1[1]) * (*a3 * v3 - a3[1] * *a2 + *a1 * v4 + v5 * a1[1]) / v6);
return result;
}

original_code:
double distance_to_line (pt_t * p, pt_t * p1, pt_t * p2)
{
 double A = p2->y - p1->y;
 double B = p1->x - p2->x;
 double C = (p1->y * p2->x - p1->x * p2->y);
 double den, num;
 num = A * p->x + B * p->y + C;
 den = A * A + B * B;
 if (den == 0)
  return distance_to_point (p, p1);
 else
  return sqrt ((num * num) / den);
}

canonical_original_code:
double distance_to_line(struct pt_t *p, struct pt_t *p1, struct pt_t *p2)
{
 double A = p2->y - p1->y;
 double B = p1->x - p2->x;
 double C = (p1->y * p2->x - p1->x * p2->y);
 double den; double num;
 num = A * p->x + B * p->y + C;
 den = A * A + B * B;
 if (den == 0)
  return distance_to_point (p, p1);
 else
  return sqrt ((num * num) / den);
}

variable_types:
p
struct pt_t { double x; } *

variable_types: A double

variable_types: B double

variable_types: C double

variable_types: den double

variable_types: num double


decompiled_code:
double __fastcall spline_error(double *a1)
{
double v1; // xmm10_8
double *v2; // rdx
double v3; // xmm0_8

v1 = distance_to_line(a1 + 2, a1, a1 + 6);
v3 = distance_to_line(a1 + 4, a1, v2);
return max(v1, v3);
}

canonical_decompiled_code:
double __fastcall func9(double *a1)
{
double v1; // xmm10_8
double *v2; // rdx
double v3; // xmm0_8

v1 = func8(a1 + 2, a1, a1 + 6);
v3 = func8(a1 + 4, a1, v2);
return func1(v1, v3);
}

original_code:
static double spline_error (spline_t *s)
{
 double berr, cerr;
 berr = distance_to_line (&s->b, &s->a, &s->d);
 cerr = distance_to_line (&s->c, &s->a, &s->d);
 return max (berr, cerr);
}

canonical_original_code:
static double spline_error(struct _spline *s)
{
 double berr; double cerr;
 berr = distance_to_line (&s->b, &s->a, &s->d);
 cerr = distance_to_line (&s->c, &s->a, &s->d);
 return max (berr, cerr);
}

variable_types: struct _spline { struct pt_t { double x; } a; } *

variable_types: berr double

variable_types: cerr double

user_defined_types:
struct _spline { struct pt_t a; }
struct pt_t { double x; }


original_code:
double distance_to_segment (pt_t * p, pt_t * p1, pt_t * p2)
{
 double dx, dy;
 double pdx, pdy;
 pt_t px;
 dx = p2->x - p1->x;
 dy = p2->y - p1->y;
 if (dx == 0 && dy == 0)
  return distance_to_point (p, p1);
 pdx = p->x - p1->x;
 pdy = p->y - p1->y;
 double u = (pdx * dx + pdy * dy) / (dx*dx + dy*dy);
 if (u <= 0)
  return distance_to_point (p, p1);
 else if (u >= 1)
  return distance_to_point (p, p2);
 px.x = p1->x + u * (p2->x - p1->x);
 px.y = p1->y + u * (p2->y - p1->y);
 return distance_to_point (p, &px);
}

canonical_original_code:
double distance_to_segment(struct pt_t *p, struct pt_t *p1, struct pt_t *p2)
{
 double dx; double dy;
 double pdx; double pdy;
 struct pt_t px;
 dx = p2->x - p1->x;
 dy = p2->y - p1->y;
 if (dx == 0 && dy == 0)
  return distance_to_point (p, p1);
 pdx = p->x - p1->x;
 pdy = p->y - p1->y;
 double u = (pdx * dx + pdy * dy) / (dx*dx + dy*dy);
 if (u <= 0)
  return distance_to_point (p, p1);
 else if (u >= 1)
  return distance_to_point (p, p2);
 px.x = p1->x + u * (p2->x - p1->x);
 px.y = p1->y + u * (p2->y - p1->y);
 return distance_to_point (p, &px);
}

variable_types: pdx double

variable_types: pdy double

variable_types:
px
struct pt_t { double x; }

variable_types: u double


lerp

decompiled_code:
double __fastcall lerp(double *a1, double *a2)
{
return (*a2 - *a1) * 0.5 + *a1;
}

canonical_decompiled_code:
double __fastcall func12(double *a1, double *a2)
{
return (*a2 - *a1) * 0.5 + *a1;
}

canonical_original_code:
struct pt_t lerp(struct pt_t *a, struct pt_t *b)
{
 struct pt_t p;
 p.x = a->x + (b->x - a->x) / 2;
 p.y = a->y + (b->y - a->y) / 2;
 return p;
}

variable_types:
a
struct pt_t *

variable_types:
p
struct pt_t { double x; }

return_type: struct pt_t { double x; }


dcj

original_code:
static void dcj (spline_t *s, spline_t *s1, spline_t *s2)
{
 pt_t ab = lerp (&s->a, &s->b);
 pt_t bc = lerp (&s->b, &s->c);
 pt_t cd = lerp (&s->c, &s->d);
 pt_t abbc = lerp (&ab, &bc);
 pt_t bccd = lerp (&bc, &cd);
 pt_t final = lerp (&abbc, &bccd);
 s1->a = s->a;
 s1->b = ab;
 s1->c = abbc;
 s1->d = final;
 s2->a = final;
 s2->b = bccd;
 s2->c = cd;
 s2->d = s->d;
}

canonical_original_code:
static void dcj(struct _spline *s, struct _spline *s1, struct _spline *s2)
{
 struct pt_t ab = lerp (&s->a, &s->b);
 struct pt_t bc = lerp (&s->b, &s->c);
 struct pt_t cd = lerp (&s->c, &s->d);
 struct pt_t abbc = lerp (&ab, &bc);
 struct pt_t bccd = lerp (&bc, &cd);
 struct pt_t final = lerp (&abbc, &bccd);
 s1->a = s->a;
 s1->b = ab;
 s1->c = abbc;
 s1->d = final;
 s2->a = final;
 s2->b = bccd;
 s2->c = cd;
 s2->d = s->d;
}

variable_types:
ab
struct pt_t { double x; }

variable_types:
bc
struct pt_t { double x; }

variable_types:
cd
struct pt_t { double x; }

variable_types:
abbc
struct pt_t { double x; }

variable_types:
bccd
struct pt_t { double x; }

variable_types:
final
struct pt_t { double x; }

user_defined_types:
struct pt_t { double x; }
struct _spline { struct pt_t a; }


main

canonical_name: main

repo: jsharf/logic-sim

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
void *v9; // r8

v3 = (_QWORD *)create_adder(1LL, 1LL, 0LL);
if ( (unsigned int)evaluate(*v3, 1LL, v4, v5, v3) )
__assert_fail("evaluate(test->root) == 0", "logic.c", 0xB8u, "main");
if ( (unsigned int)evaluate(*(_QWORD *)(v8 + 8), 1LL, v6, v7, v8) != 1 )
__assert_fail("evaluate(test->carryout) == 1", "logic.c", 0xB9u, "main");
clean_adder(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
void *v9; // r8

v3 = (_QWORD *)create_adder(1LL, 1LL, 0LL);
if ( (unsigned int)func9(*v3, 1LL, v4, v5, v3) )
__assert_fail("evaluate(test->root) == 0", "logic.c", 0xB8u, "main");
if ( (unsigned int)func9(*(_QWORD *)(v8 + 8), 1LL, v6, v7, v8) != 1 )
__assert_fail("evaluate(test->carryout) == 1", "logic.c", 0xB9u, "main");
func11(v9);
return 0;
}

original_code:
int main()
{
 add_t test = create_adder(1, 1, 0);
 ((void) sizeof ((evaluate(test->root) == 0) ? 1 : 0), __extension__ ({ if (evaluate(test->root) == 0) ; else __assert_fail ("evaluate(test->root) == 0", "logic.c", 184, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((evaluate(test->carryout) == 1) ? 1 : 0), __extension__ ({ if (evaluate(test->carryout) == 1) ; else __assert_fail ("evaluate(test->carryout) == 1", "logic.c", 185, __extension__ __PRETTY_FUNCTION__); }));
 clean_adder(test);
}

canonical_original_code:
int main()
{
 struct add *test = create_adder(1, 1, 0);
 ((void) sizeof ((evaluate(test->root) == 0) ? 1 : 0), __extension__ ({ if (evaluate(test->root) == 0) ; else __assert_fail ("evaluate(test->root) == 0", "logic.c", 184, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((evaluate(test->carryout) == 1) ? 1 : 0), __extension__ ({ if (evaluate(test->carryout) == 1) ; else __assert_fail ("evaluate(test->carryout) == 1", "logic.c", 185, __extension__ __PRETTY_FUNCTION__); }));
 clean_adder(test);
}

variable_types: struct add { struct gate { int type; union { struct gate *operand[2]; int val; } u; } *root; struct gate *carryout; struct gate *ina; struct gate *inb; struct gate *carryin; } *

user_defined_types: struct add { struct gate *root; struct gate *carryout; struct gate *ina; struct gate *inb; struct gate *carryin; }


set

decompiled_code:
_BOOL8 __fastcall set(_WORD *a1, int a2)
{
*a1 = __ROL2__(a2, 8);
return (a2 & 0xFFFF0000) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_WORD *a1, int a2)
{
*a1 = __ROL2__(a2, 8);
return (a2 & 0xFFFF0000) == 0;
}

original_code:
bool set(reg_t a, int val)
{
 int val2= val & 0xFFFF;
 a->upper = val2 >> 8;
 a->lower = val2&0xFF;
 return val2 == val;
}

canonical_original_code:
int set(struct reg *a, int val)
{
 int val2 = val & 0xFFFF;
 a->upper = val2 >> 8;
 a->lower = val2&0xFF;
 return val2 == val;
}

variable_types: struct reg { char upper; char lower; } *

variable_types: val int


val

decompiled_code:
__int64 __fastcall val(char *a1)
{
return a1[1] | (unsigned int)(*a1 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
return a1[1] | (unsigned int)(*a1 << 8);
}

original_code:
int val(reg_t a)
{
 return a->upper<<8 | a->lower;
}

canonical_original_code:
int val(struct reg *a)
{
 return a->upper<<8 | a->lower;
}


evaluate

decompiled_code:
__int64 __fastcall evaluate(int *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v5; // ebp
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
int v9; // er12
__int64 result; // rax

v5 = *a1;
if ( *a1 == 4 )
return (unsigned int)a1[2];
v9 = evaluate(*((_QWORD *)a1 + 1), a2, a3, a4, a5);
result = 0LL;
if ( v9 )
{
result = (unsigned int)evaluate(*((_QWORD *)a1 + 2), a2, v6, v7, v8) != 0;
if ( !v5 )
return result;
}
else if ( !v5 )
{
return result;
}
if ( v5 == 1 )
goto LABEL_14;
result = 1LL;
if ( !v9 )
result = (unsigned int)evaluate(*((_QWORD *)a1 + 2), a2, v6, v7, v8) != 0;
if ( v5 != 2 )
{
if ( v5 != 3 )
{
result = evaluate(*((_QWORD *)a1 + 2), a2, v6, v7, v8);
if ( v5 == 5 )
result = v9 ^ (unsigned int)result;
return result;
}
LABEL_14:
result = (unsigned int)result ^ 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v5; // ebp
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
int v9; // er12
__int64 result; // rax

v5 = *a1;
if ( *a1 == 4 )
return (unsigned int)a1[2];
v9 = func9(*((_QWORD *)a1 + 1), a2, a3, a4, a5);
result = 0LL;
if ( v9 )
{
result = (unsigned int)func9(*((_QWORD *)a1 + 2), a2, v6, v7, v8) != 0;
if ( !v5 )
return result;
}
else if ( !v5 )
{
return result;
}
if ( v5 == 1 )
goto LABEL_14;
result = 1LL;
if ( !v9 )
result = (unsigned int)func9(*((_QWORD *)a1 + 2), a2, v6, v7, v8) != 0;
if ( v5 != 2 )
{
if ( v5 != 3 )
{
result = func9(*((_QWORD *)a1 + 2), a2, v6, v7, v8);
if ( v5 == 5 )
result = v9 ^ (unsigned int)result;
return result;
}
LABEL_14:
result = (unsigned int)result ^ 1;
}
return result;
}

original_code:
bool evaluate(gate_t a)
{
 if(a->type == CONST)
  return (a->u.val);
 bool ab = evaluate(a->u.operand[0]) && evaluate(a->u.operand[1]);
 if(a->type == AND)
  return ab;
 if(a->type == NAND)
  return !ab;
 int aorb = evaluate(a->u.operand[0]) || evaluate(a->u.operand[1]);
 if(a->type == OR)
  return aorb;
 if(a->type == NOR)
  return !aorb;
 bool axorb = evaluate(a->u.operand[0]) ^ evaluate(a->u.operand[1]);
 if(a->type == XOR)
  return axorb;
}

canonical_original_code:
int evaluate(struct gate *a)
{
 if(a->type == CONST)
  return (a->u.val);
 int ab = evaluate(a->u.operand[0]) && evaluate(a->u.operand[1]);
 if(a->type == AND)
  return ab;
 if(a->type == NAND)
  return !ab;
 int aorb = evaluate(a->u.operand[0]) || evaluate(a->u.operand[1]);
 if(a->type == OR)
  return aorb;
 if(a->type == NOR)
  return !aorb;
 int axorb = evaluate(a->u.operand[0]) ^ evaluate(a->u.operand[1]);
 if(a->type == XOR)
  return axorb;
}

variable_types: struct gate { int type; union { struct gate *operand[2]; int val; } u; } *

variable_types: ab int

variable_types: aorb int

variable_types: axorb int


decompiled_code:
void __fastcall clean_gates(_QWORD *a1)
{
if ( *(_DWORD *)a1 != 4 )
{
clean_gates(a1[1]);
clean_gates(a1[2]);
}
free(a1);
}

original_code:
void clean_gates(gate_t a)
{
 if(a->type == CONST)
 {
  free(a);
  return;
 }
 else
 {
  clean_gates(a->u.operand[0]);
  clean_gates(a->u.operand[1]);
  free(a);
  return;
 }
}

canonical_original_code:
void clean_gates(struct gate *a)
{
 if(a->type == CONST)
 {
  free(a);
  return;
 }
 else
 {
  clean_gates(a->u.operand[0]);
  clean_gates(a->u.operand[1]);
  free(a);
  return;
 }
}

user_defined_types: struct gate { int type; union { struct gate *operand[2]; int val; } u; }


decompiled_code:
void __fastcall clean_adder(void *ptr)
{
clean_gates(*(_QWORD **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
func10(*(_QWORD **)ptr);
free(ptr);
}

original_code:
void clean_adder(add_t a)
{
 clean_gates(a->root);
 free(a);
}

canonical_original_code:
void clean_adder(struct add *a)
{
 clean_gates(a->root);
 free(a);
}


WTTraverse

decompiled_code:
__int64 __fastcall WTTraverse(_QWORD *a1, char a2)
{
return traverse(*a1, (unsigned int)a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, char a2)
{
return traverse(*a1, (unsigned int)a2);
}

original_code:
void WTTraverse(WordTree *tree, char c) {
 traverse(tree->root, c);
}

canonical_original_code:
void WTTraverse(struct WordTree *tree, char c) {
 traverse(tree->root, c);
}

variable_types: struct WordTree { struct treeRoot { struct Node { char letter; struct Node **branches; struct FreqList { struct FreqNode { char *filename; struct FreqNode *next; } *first; } *freak; char isWord; int count; } *root; struct Node *ptr; struct FilenameNode { char *filename; struct FilenameNode *next; } *filenames; int depth; } *root; } *

variable_types: c char

user_defined_types: struct WordTree { struct treeRoot *root; }

user_defined_types: struct treeRoot { struct Node *root; struct Node *ptr; struct FilenameNode *filenames; int depth; }

user_defined_types: struct Node { char letter; struct Node **branches; struct FreqList *freak; char isWord; int count; }

user_defined_types: struct FreqList { struct FreqNode *first; }


getFileNames

original_code:
FreqNode *getFileNames(WordTree *tree) {
 FreqNode *list = tree->root->ptr->freak->first;
 tree->root->ptr = tree->root->root;
 return list;
}

canonical_original_code:
struct FreqNode *getFileNames(struct WordTree *tree) {
 struct FreqNode *list = tree->root->ptr->freak->first;
 tree->root->ptr = tree->root->root;
 return list;
}

variable_types: struct WordTree { struct treeRoot { struct Node { char letter; struct Node **branches; struct FreqList { struct FreqNode *first; } *freak; char isWord; int count; } *root; struct Node *ptr; struct FilenameNode { char *filename; struct FilenameNode *next; } *filenames; int depth; } *root; } *

variable_types: struct FreqNode { char *filename; struct FreqNode *next; } *


WTDestroy

decompiled_code:
void __fastcall WTDestroy(void *ptr)
{
freeTree(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
freeTree(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void WTDestroy(WordTree *tree) {
    freeTree(tree->root);
    free(tree);
}

canonical_original_code:
void WTDestroy(struct WordTree *tree) {
    freeTree(tree->root);
    free(tree);
}

user_defined_types: struct FilenameNode { char *filename; struct FilenameNode *next; }

user_defined_types: struct FreqNode { char *filename; struct FreqNode *next; }


main

repo: jsocol/yodawg

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // r12
int v5; // eax
const char *v6; // rsi
unsigned int *v7; // rax
__int64 v8; // rsi
_QWORD *v9; // rbp
__int64 v10; // rbx
const char *v11; // rdi

if ( argc <= 1 )
return -1;
v4 = (void *)yodawg_create(argc, argv, envp);
yodawg_add_string(v4, "foo0");
yodawg_add_string(v4, "bar");
yodawg_add_string(v4, "baz");
yodawg_add_string(v4, "bark");
yodawg_add_string(v4, "bars");
yodawg_add_string(v4, "barf");
yodawg_add_string(v4, "quxxxx");
yodawg_add_string(v4, "bbq");
v5 = yodawg_string_in_dawg(v4, argv[1]);
v6 = argv[1];
if ( v5 )
printf("The string %s is in the dawg.\n\n", v6);
else
printf("The string %s is not in the dawg.\n\n", v6);
v7 = (unsigned int *)yodawg_find_strings(v4, argv[1]);
v8 = *v7;
v9 = v7;
if ( (int)v8 < 0 )
puts("Prefix not in dawg.");
else
printf("Found %d matching strings:\n", v8);
yodawg_free_dawg(v4);
if ( *(int *)v9 > 0 )
{
v10 = 0LL;
do
{
v11 = *(const char **)(v9[1] + 8 * v10++);
puts(v11);
}
while ( *(_DWORD *)v9 > (int)v10 );
}
yodawg_free_wordlist(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // r12
int v5; // eax
const char *v6; // rsi
unsigned int *v7; // rax
__int64 v8; // rsi
_QWORD *v9; // rbp
__int64 v10; // rbx
const char *v11; // rdi

if ( argc <= 1 )
return -1;
v4 = (void *)func12(argc, argv, envp);
func9(v4, "foo0");
func9(v4, "bar");
func9(v4, "baz");
func9(v4, "bark");
func9(v4, "bars");
func9(v4, "barf");
func9(v4, "quxxxx");
func9(v4, "bbq");
v5 = func10(v4, argv[1]);
v6 = argv[1];
if ( v5 )
printf("The string %s is in the dawg.\n\n", v6);
else
printf("The string %s is not in the dawg.\n\n", v6);
v7 = (unsigned int *)func17(v4, argv[1]);
v8 = *v7;
v9 = v7;
if ( (int)v8 < 0 )
puts("Prefix not in dawg.");
else
printf("Found %d matching strings:\n", v8);
func13(v4);
if ( *(int *)v9 > 0 )
{
v10 = 0LL;
do
{
v11 = *(const char **)(v9[1] + 8 * v10++);
puts(v11);
}
while ( *(_DWORD *)v9 > (int)v10 );
}
func16(v9);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    struct yonode *dawg;
    int j;
    struct yowordlist *strings;
    if (argc < 2) return -1;
    dawg = yodawg_create();
    yodawg_add_string(dawg, "foo0");
    yodawg_add_string(dawg, "bar");
    yodawg_add_string(dawg, "baz");
    yodawg_add_string(dawg, "bark");
    yodawg_add_string(dawg, "bars");
    yodawg_add_string(dawg, "barf");
    yodawg_add_string(dawg, "quxxxx");
    yodawg_add_string(dawg, "bbq");
    if(yodawg_string_in_dawg(dawg, argv[1]))
        printf("The string %s is in the dawg.\n\n", argv[1]);
    else
        printf("The string %s is not in the dawg.\n\n", argv[1]);
    strings = yodawg_find_strings(dawg, argv[1]);
    if(strings->cursize < 0)
        printf("Prefix not in dawg.\n");
    else
        printf("Found %d matching strings:\n", strings->cursize);
    yodawg_free_dawg(dawg);
    for(j = 0; j < strings->cursize; j++)
        printf("%s\n", strings->words[j]);
    yodawg_free_wordlist(strings);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct yonode { char value; int cursize; struct yonode **edges; } *

variable_types: j int

variable_types: struct yowordlist { int cursize; char **words; } *


decompiled_code:
__int64 __fastcall yodawg_add_node(__int64 a1, __int64 a2)
{
_QWORD *v4; // rdi
__int64 v5; // rsi
__int64 result; // rax
_QWORD *v7; // rax
int v8; // esi
_QWORD *v9; // rax

v4 = *(_QWORD **)(a1 + 16);
if ( !v4 )
{
v7 = malloc(0x80uLL);
*(_QWORD *)(a1 + 16) = v7;
v4 = v7;
if ( !v7 )
return 0xFFFFFFFFLL;
LABEL_5:
v5 = *(int *)(a1 + 4);
goto LABEL_3;
}
v5 = *(int *)(a1 + 4);
if ( (_DWORD)v5 != *(_DWORD *)(a1 + 8) )
{
LABEL_3:
*(_DWORD *)(a1 + 4) = v5 + 1;
result = 0LL;
v4[v5] = a2;
return result;
}
v8 = 2 * v5;
*(_DWORD *)(a1 + 8) = v8;
v9 = realloc(v4, v8);
*(_QWORD *)(a1 + 16) = v9;
v4 = v9;
if ( v9 )
goto LABEL_5;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
_QWORD *v4; // rdi
__int64 v5; // rsi
__int64 result; // rax
_QWORD *v7; // rax
int v8; // esi
_QWORD *v9; // rax

v4 = *(_QWORD **)(a1 + 16);
if ( !v4 )
{
v7 = malloc(0x80uLL);
*(_QWORD *)(a1 + 16) = v7;
v4 = v7;
if ( !v7 )
return 0xFFFFFFFFLL;
LABEL_5:
v5 = *(int *)(a1 + 4);
goto LABEL_3;
}
v5 = *(int *)(a1 + 4);
if ( (_DWORD)v5 != *(_DWORD *)(a1 + 8) )
{
LABEL_3:
*(_DWORD *)(a1 + 4) = v5 + 1;
result = 0LL;
v4[v5] = a2;
return result;
}
v8 = 2 * v5;
*(_DWORD *)(a1 + 8) = v8;
v9 = realloc(v4, v8);
*(_QWORD *)(a1 + 16) = v9;
v4 = v9;
if ( v9 )
goto LABEL_5;
return 0xFFFFFFFFLL;
}

original_code:
int yodawg_add_node(struct yonode *parent, struct yonode *child)
{
    if (parent->edges == ((void *)0)) {
        parent->edges = malloc(16 * sizeof (struct yonode *));
        if(parent->edges == ((void *)0)) return -1;
    }
    else if (parent->cursize == parent->maxsize) {
        parent->maxsize *= 2;
        parent->edges = realloc(parent->edges, parent->maxsize);
        if(parent->edges == ((void *)0)) return -1;
    }
    parent->edges[parent->cursize++] = child;
    return 0;
}

variable_types:
child
struct yonode *

user_defined_types: struct yonode { char value; int cursize; struct yonode **edges; }


decompiled_code:
__int64 __fastcall yodawg_value_in_node(__int64 a1, char a2)
{
__int64 v2; // rcx
__int64 v3; // rdi
__int64 result; // rax

v2 = *(int *)(a1 + 4);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)(a1 + 16);
result = 0LL;
while ( **(_BYTE **)(v3 + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char a2)
{
__int64 v2; // rcx
__int64 v3; // rdi
__int64 result; // rax

v2 = *(int *)(a1 + 4);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)(a1 + 16);
result = 0LL;
while ( **(_BYTE **)(v3 + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int yodawg_value_in_node(struct yonode *node, char value)
{
    int i;
    for(i = 0; i < node->cursize; i++)
        if (value == node->edges[i]->value)
            return i;
    return -1;
}

variable_types: value char

variable_types: i int


decompiled_code:
__int64 __fastcall yodawg_add_string(__int64 a1, char *a2)
{
char v2; // al
char *v3; // r12
__int64 v4; // rbp
int v5; // eax
char v6; // r9
_QWORD *v7; // r13
int v8; // er8
__int64 result; // rax

v2 = *a2;
if ( *a2 )
{
v3 = a2 + 1;
v4 = a1;
while ( 1 )
{
while ( 1 )
{
v5 = yodawg_value_in_node(v4, v2);
if ( v5 < 0 )
break;
++v3;
v4 = *(_QWORD *)(*(_QWORD *)(v4 + 16) + 8LL * v5);
v2 = *(v3 - 1);
if ( !v2 )
goto LABEL_7;
}
v7 = yodawg_create_node(v6);
if ( (unsigned int)yodawg_add_node(v4, (__int64)v7) )
break;
v2 = *v3++;
v4 = (__int64)v7;
if ( !v2 )
goto LABEL_7;
}
result = 0xFFFFFFFFLL;
}
else
{
v4 = a1;
LABEL_7:
v8 = yodawg_value_in_node(v4, -1);
result = 0LL;
if ( v8 < 0 )
result = (unsigned int)-((unsigned int)yodawg_add_node(v4, **(_QWORD **)(a1 + 16)) != 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char *a2)
{
char v2; // al
char *v3; // r12
__int64 v4; // rbp
int v5; // eax
char v6; // r9
_QWORD *v7; // r13
int v8; // er8
__int64 result; // rax

v2 = *a2;
if ( *a2 )
{
v3 = a2 + 1;
v4 = a1;
while ( 1 )
{
while ( 1 )
{
v5 = func8(v4, v2);
if ( v5 < 0 )
break;
++v3;
v4 = *(_QWORD *)(*(_QWORD *)(v4 + 16) + 8LL * v5);
v2 = *(v3 - 1);
if ( !v2 )
goto LABEL_7;
}
v7 = yodawg_create_node(v6);
if ( (unsigned int)func7(v4, (__int64)v7) )
break;
v2 = *v3++;
v4 = (__int64)v7;
if ( !v2 )
goto LABEL_7;
}
result = 0xFFFFFFFFLL;
}
else
{
v4 = a1;
LABEL_7:
v8 = func8(v4, -1);
result = 0LL;
if ( v8 < 0 )
result = (unsigned int)-((unsigned int)func7(v4, **(_QWORD **)(a1 + 16)) != 0);
}
return result;
}

original_code:
int yodawg_add_string(struct yonode *dawg, char *str)
{
    char c;
    struct yonode *cur, *buf;
    int i;
    cur = dawg;
    while((c = *str++) != '\0') {
        i = yodawg_value_in_node(cur, c);
        if(i < 0) {
            buf = yodawg_create_node(c);
            if(yodawg_add_node(cur, buf)) return -1;
            cur = buf;
        }
        else {
            cur = cur->edges[i];
        }
    }
    if(yodawg_value_in_node(cur, -1) < 0) {
        if(yodawg_add_node(cur, dawg->edges[0])) return -1;
    }
    return 0;
}

canonical_original_code:
int yodawg_add_string(struct yonode *dawg, char *str)
{
    char c;
    struct yonode *cur; struct yonode *buf;
    int i;
    cur = dawg;
    while((c = *str++) != '\0') {
        i = yodawg_value_in_node(cur, c);
        if(i < 0) {
            buf = yodawg_create_node(c);
            if(yodawg_add_node(cur, buf)) return -1;
            cur = buf;
        }
        else {
            cur = cur->edges[i];
        }
    }
    if(yodawg_value_in_node(cur, -1) < 0) {
        if(yodawg_add_node(cur, dawg->edges[0])) return -1;
    }
    return 0;
}

variable_types:
str
char *


decompiled_code:
_BOOL8 __fastcall yodawg_string_in_dawg(__int64 a1, char *a2)
{
char v2; // si
int v4; // eax
__int64 v5; // r9
char *v6; // r10

v2 = *a2;
if ( !v2 )
return (int)yodawg_value_in_node(a1, -1) >= 0;
while ( 1 )
{
v4 = yodawg_value_in_node(a1, v2);
if ( v4 < 0 )
break;
v2 = *v6;
a1 = *(_QWORD *)(*(_QWORD *)(v5 + 16) + 8LL * v4);
if ( !*v6 )
return (int)yodawg_value_in_node(a1, -1) >= 0;
}
return 0LL;
}

original_code:
int yodawg_string_in_dawg(struct yonode *dawg, char *str)
{
    char c;
    int i;
    struct yonode *cur;
    cur = dawg;
    while((c = *str++) != '\0') {
        i = yodawg_value_in_node(cur, c);
        if(i < 0) return 0;
        cur = cur->edges[i];
    }
    if(yodawg_value_in_node(cur, -1) < 0) return 0;
    return 1;
}


decompiled_code:
void __fastcall yodawg_free_node(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void yodawg_free_node(struct yonode *node)
{
    free(node->edges);
    free(node);
}


decompiled_code:
_QWORD *yodawg_create()
{
_QWORD *v0; // r12
_QWORD *v1; // rax
void *v2; // rbp

v0 = yodawg_create_node(0);
if ( !v0 )
return v0;
v1 = yodawg_create_node(-1);
v2 = v1;
if ( v1 )
{
if ( !(unsigned int)yodawg_add_node((__int64)v0, (__int64)v1) )
return v0;
yodawg_free_node(v2);
}
yodawg_free_node(v0);
return 0LL;
}

canonical_decompiled_code:
_QWORD *func12()
{
_QWORD *v0; // r12
_QWORD *v1; // rax
void *v2; // rbp

v0 = yodawg_create_node(0);
if ( !v0 )
return v0;
v1 = yodawg_create_node(-1);
v2 = v1;
if ( v1 )
{
if ( !(unsigned int)func7((__int64)v0, (__int64)v1) )
return v0;
func11(v2);
}
func11(v0);
return 0LL;
}

original_code:
struct yonode *yodawg_create()
{
    struct yonode *start, *eow;
    start = yodawg_create_node(0);
    if(start == ((void *)0)) return ((void *)0);
    eow = yodawg_create_node(-1);
    if(eow == ((void *)0)) {
        yodawg_free_node(start);
        return ((void *)0);
    }
    if(yodawg_add_node(start, eow)) {
        yodawg_free_node(eow);
        yodawg_free_node(start);
        return ((void *)0);
    }
    return start;
}

canonical_original_code:
struct yonode *yodawg_create()
{
    struct yonode *start; struct yonode *eow;
    start = yodawg_create_node(0);
    if(start == ((void *)0)) return ((void *)0);
    eow = yodawg_create_node(-1);
    if(eow == ((void *)0)) {
        yodawg_free_node(start);
        return ((void *)0);
    }
    if(yodawg_add_node(start, eow)) {
        yodawg_free_node(eow);
        yodawg_free_node(start);
        return ((void *)0);
    }
    return start;
}

return_type: struct yonode { char value; int cursize; struct yonode **edges; } *


decompiled_code:
__int64 __fastcall yodawg_free_dawg(void *ptr)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
__int64 v4; // rbx
void *v5; // rdi
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7 = 0;
v8[0] = 16;
v2 = malloc(0x80uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = yodawg_add_dawg_to_list(v2, &v7, v8, (__int64)ptr);
if ( !v3 )
return 0xFFFFFFFFLL;
if ( v7 > 0 )
{
v4 = 0LL;
do
{
v5 = (void *)v3[v4++];
yodawg_free_node(v5);
}
while ( v7 > (int)v4 );
}
yodawg_free_node(ptr);
free(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(void *ptr)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
__int64 v4; // rbx
void *v5; // rdi
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7 = 0;
v8[0] = 16;
v2 = malloc(0x80uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = yodawg_add_dawg_to_list(v2, &v7, v8, (__int64)ptr);
if ( !v3 )
return 0xFFFFFFFFLL;
if ( v7 > 0 )
{
v4 = 0LL;
do
{
v5 = (void *)v3[v4++];
func11(v5);
}
while ( v7 > (int)v4 );
}
func11(ptr);
free(v3);
return 0LL;
}

original_code:
int yodawg_free_dawg(struct yonode *dawg)
{
    int *cursize;
    int *maxsize;
    int _cursize = 0;
    int _maxsize = 16;
    int i;
    struct yonode **nodes;
    cursize = &_cursize;
    maxsize = &_maxsize;
    nodes = malloc(*maxsize * sizeof (struct yonode *));
    if(nodes == ((void *)0)) return -1;
    nodes = yodawg_add_dawg_to_list(nodes, cursize, maxsize, dawg);
    if(nodes == ((void *)0)) return -1;
    for(i = 0; i < *cursize; i++) {
        yodawg_free_node(nodes[i]);
    }
    yodawg_free_node(dawg);
    free(nodes);
    return 0;
}

variable_types:
cursize
int *

variable_types:
maxsize
int *

variable_types: struct yonode { char value; int cursize; struct yonode **edges; } **


decompiled_code:
__int64 __fastcall yodawg_build_strings(__int64 a1, const char *a2, int *a3)
{
int v5; // er15
char *v6; // rax
char *v7; // r13
__int64 v8; // rbx
int v9; // er15
int v10; // eax
_QWORD *v11; // r8
int v12; // eax
void *v13; // rdi
_QWORD *v14; // rax
char *v15; // rax
const char *v16; // r15
_QWORD *v18; // [rsp+0h] [rbp-48h]
int i; // [rsp+Ch] [rbp-3Ch]

v5 = strlen(a2);
v6 = (char *)malloc(v5 + 2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = 0LL;
for ( i = v5 + 1; *(_DWORD *)(a1 + 4) > (int)v8; ++v8 )
{
v16 = *(const char **)(*(_QWORD *)(a1 + 16) + 8 * v8);
if ( *v16 == -1 )
{
v9 = *a3;
v10 = a3[1];
v11 = (_QWORD *)*((_QWORD *)a3 + 1);
if ( *a3 >= v10 )
{
v12 = 2 * v10;
v13 = (void *)*((_QWORD *)a3 + 1);
a3[1] = v12;
v14 = realloc(v13, 8LL * v12);
*((_QWORD *)a3 + 1) = v14;
v11 = v14;
if ( !v14 )
return 0xFFFFFFFFLL;
v9 = *a3;
}
v18 = v11;
v15 = (char *)malloc(i);
v18[v9] = v15;
if ( !v15 )
return 0xFFFFFFFFLL;
strcpy(v15, a2);
*a3 = v9 + 1;
}
else
{
strcpy(v7, a2);
strncat(v7, v16, 1uLL);
if ( (unsigned int)yodawg_build_strings(v16, v7, a3) )
return 0xFFFFFFFFLL;
}
}
free(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const char *a2, int *a3)
{
int v5; // er15
char *v6; // rax
char *v7; // r13
__int64 v8; // rbx
int v9; // er15
int v10; // eax
_QWORD *v11; // r8
int v12; // eax
void *v13; // rdi
_QWORD *v14; // rax
char *v15; // rax
const char *v16; // r15
_QWORD *v18; // [rsp+0h] [rbp-48h]
int i; // [rsp+Ch] [rbp-3Ch]

v5 = strlen(a2);
v6 = (char *)malloc(v5 + 2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = 0LL;
for ( i = v5 + 1; *(_DWORD *)(a1 + 4) > (int)v8; ++v8 )
{
v16 = *(const char **)(*(_QWORD *)(a1 + 16) + 8 * v8);
if ( *v16 == -1 )
{
v9 = *a3;
v10 = a3[1];
v11 = (_QWORD *)*((_QWORD *)a3 + 1);
if ( *a3 >= v10 )
{
v12 = 2 * v10;
v13 = (void *)*((_QWORD *)a3 + 1);
a3[1] = v12;
v14 = realloc(v13, 8LL * v12);
*((_QWORD *)a3 + 1) = v14;
v11 = v14;
if ( !v14 )
return 0xFFFFFFFFLL;
v9 = *a3;
}
v18 = v11;
v15 = (char *)malloc(i);
v18[v9] = v15;
if ( !v15 )
return 0xFFFFFFFFLL;
strcpy(v15, a2);
*a3 = v9 + 1;
}
else
{
strcpy(v7, a2);
strncat(v7, v16, 1uLL);
if ( (unsigned int)func14(v16, v7, a3) )
return 0xFFFFFFFFLL;
}
}
free(v7);
return 0LL;
}

original_code:
int yodawg_build_strings(struct yonode *dawg, const char *prefix, struct yowordlist *strings)
{
    struct yonode *cur;
    int i;
    int plen = strlen(prefix);
    char *newprefix;
    newprefix = malloc(plen + 2);
    if(newprefix == ((void *)0)) return -1;
    for(i = 0; i < dawg->cursize; i++) {
        cur = dawg->edges[i];
        if(cur->value == -1) {
            if(strings->cursize >= strings->maxsize) {
                strings->maxsize *= 2;
                strings->words = realloc(strings->words, strings->maxsize * sizeof (char *));
                if(strings->words == ((void *)0)) return -1;
            }
            strings->words[strings->cursize] = malloc(plen + 1);
            if(strings->words[strings->cursize] == ((void *)0)) return -1;
            strcpy(strings->words[strings->cursize], prefix);
            strings->cursize++;
        }
        else {
            strcpy(newprefix, prefix);
            strncat(newprefix, &(cur->value), 1);
            if(yodawg_build_strings(cur, newprefix, strings)) return -1;
        }
    }
    free(newprefix);
    return 0;
}

canonical_original_code:
int yodawg_build_strings(struct yonode *dawg, char *prefix, struct yowordlist *strings)
{
    struct yonode *cur;
    int i;
    int plen = strlen(prefix);
    char *newprefix;
    newprefix = malloc(plen + 2);
    if(newprefix == ((void *)0)) return -1;
    for(i = 0; i < dawg->cursize; i++) {
        cur = dawg->edges[i];
        if(cur->value == -1) {
            if(strings->cursize >= strings->maxsize) {
                strings->maxsize *= 2;
                strings->words = realloc(strings->words, strings->maxsize * sizeof (char *));
                if(strings->words == ((void *)0)) return -1;
            }
            strings->words[strings->cursize] = malloc(plen + 1);
            if(strings->words[strings->cursize] == ((void *)0)) return -1;
            strcpy(strings->words[strings->cursize], prefix);
            strings->cursize++;
        }
        else {
            strcpy(newprefix, prefix);
            strncat(newprefix, &(cur->value), 1);
            if(yodawg_build_strings(cur, newprefix, strings)) return -1;
        }
    }
    free(newprefix);
    return 0;
}

variable_types:
prefix
char *

variable_types: plen int

variable_types:
newprefix
char *

user_defined_types: struct yowordlist { int cursize; char **words; }


decompiled_code:
_QWORD *yodawg_create_wordlist()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(0x10uLL);
if ( v0 )
{
*v0 = 0x1000000000LL;
v1 = malloc(0x80uLL);
v0[1] = v1;
if ( !v1 )
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
struct yowordlist *yodawg_create_wordlist(int size)
{
    struct yowordlist *wordlist;
    wordlist = malloc(sizeof (struct yowordlist));
    if(wordlist == ((void *)0)) return ((void *)0);
    wordlist->cursize = 0;
    wordlist->maxsize = 16;
    wordlist->words = malloc(16 * sizeof (char *));
    if(wordlist->words == ((void *)0)) {
        free(wordlist);
        return ((void *)0);
    }
    return wordlist;
}

variable_types: size int

return_type: struct yowordlist { int cursize; char **words; } *


decompiled_code:
void __fastcall yodawg_free_wordlist(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

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

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

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

original_code:
void yodawg_free_wordlist(struct yowordlist *wordlist)
{
    int i;
    if(wordlist == ((void *)0)) return;
    for(i = 0; i < wordlist->cursize; i++)
        free(wordlist->words[i]);
    free(wordlist->words);
    free(wordlist);
}


decompiled_code:
int *__fastcall yodawg_find_strings(__int64 a1, const char *a2)
{
int *v4; // rax
char v5; // si
int *v6; // r12
int v7; // eax
char *v8; // r9
int *result; // rax

v4 = (int *)yodawg_create_wordlist();
v5 = *a2;
v6 = v4;
if ( *a2 )
{
while ( 1 )
{
v7 = yodawg_value_in_node(a1, v5);
if ( v7 < 0 )
break;
v5 = *v8;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v7);
if ( !*v8 )
goto LABEL_6;
}
*v6 = -1;
result = v6;
}
else
{
LABEL_6:
yodawg_build_strings(a1, a2, v6);
result = v6;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func17(__int64 a1, const char *a2)
{
int *v4; // rax
char v5; // si
int *v6; // r12
int v7; // eax
char *v8; // r9
int *result; // rax

v4 = (int *)func15();
v5 = *a2;
v6 = v4;
if ( *a2 )
{
while ( 1 )
{
v7 = func8(a1, v5);
if ( v7 < 0 )
break;
v5 = *v8;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v7);
if ( !*v8 )
goto LABEL_6;
}
*v6 = -1;
result = v6;
}
else
{
LABEL_6:
func14(a1, a2, v6);
result = v6;
}
return result;
}

original_code:
struct yowordlist *yodawg_find_strings(struct yonode *dawg, char *prefix)
{
    char c;
    char *p;
    int i;
    struct yowordlist *strings;
    strings = yodawg_create_wordlist(16);
    p = prefix;
    while((c = *p++) != '\0') {
        i = yodawg_value_in_node(dawg, c);
        if(i < 0) {
            strings->cursize = -1;
            return strings;
        }
        dawg = dawg->edges[i];
    }
    yodawg_build_strings(dawg, prefix, strings);
    return strings;
}

variable_types: c char

variable_types:
p
char *


original_code:
void write08(unsigned long BASE, unsigned long reg1, signed char val){
 unsigned long val_to_write, val32, temp;
 unsigned long bitmask[4]={0xffffff00, 0xffff00ff, 0xff00ffff, 0x00ffffff};
 int byte;
 byte=reg1%4;
 reg1=reg1-byte;
 val32=val<<(8*byte);
 temp=*((unsigned int*)(BASE+reg1));
 val_to_write=temp & bitmask[byte];
 val_to_write=val_to_write | val32;
 *((unsigned int*)(BASE+reg1))=val_to_write;
}

canonical_original_code:
void write08(unsigned long BASE, unsigned long reg1, char val){
 unsigned long val_to_write; unsigned long val32; unsigned long temp;
 unsigned long bitmask[4] = {0xffffff00, 0xffff00ff, 0xff00ffff, 0x00ffffff};
 int byte;
 byte=reg1%4;
 reg1=reg1-byte;
 val32=val<<(8*byte);
 temp=*((unsigned int *)(BASE+reg1));
 val_to_write=temp & bitmask[byte];
 val_to_write=val_to_write | val32;
 *((unsigned int *)(BASE+reg1))=val_to_write;
}

variable_types:
BASE
unsigned long

variable_types: val char

variable_types:
temp
unsigned long

variable_types:
bitmask
unsigned long [4]

variable_types: byte int


original_code:
void write16(unsigned long BASE, unsigned long reg1, signed short val){
 unsigned long val_to_write, val32, temp;
 unsigned long bitmask[3]={0xffff0000, 0xff0000ff, 0x0000ffff};
 int byte;
 byte=reg1%4;
 reg1=reg1-byte;
 val32=val<<(8*byte);
 temp=*((unsigned int*)(BASE+reg1));
 val_to_write=temp & bitmask[byte];
 val_to_write=val_to_write | val32;
 *((unsigned int*)(BASE+reg1))=val_to_write;
}

canonical_original_code:
void write16(unsigned long BASE, unsigned long reg1, short val){
 unsigned long val_to_write; unsigned long val32; unsigned long temp;
 unsigned long bitmask[3] = {0xffff0000, 0xff0000ff, 0x0000ffff};
 int byte;
 byte=reg1%4;
 reg1=reg1-byte;
 val32=val<<(8*byte);
 temp=*((unsigned int *)(BASE+reg1));
 val_to_write=temp & bitmask[byte];
 val_to_write=val_to_write | val32;
 *((unsigned int *)(BASE+reg1))=val_to_write;
}

variable_types: val short

variable_types:
bitmask
unsigned long [3]


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

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

original_code:
void write32(unsigned long BASE, unsigned long reg1, signed long val){
 unsigned long val_to_write, val32, temp;
 unsigned long bitmask[1]={0x00000000};
 int byte;
 *((unsigned int*)(BASE+reg1))=val;
}

canonical_original_code:
void write32(unsigned long BASE, unsigned long reg1, long val){
 unsigned long val_to_write; unsigned long val32; unsigned long temp;
 unsigned long bitmask[1] = {0x00000000};
 int byte;
 *((unsigned int *)(BASE+reg1))=val;
}

variable_types: val long

variable_types:
bitmask
unsigned long [1]


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

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

original_code:
char read08(unsigned long reg1){
 unsigned long *reg;
 signed char val;
 reg=reg1;
 val=(char)(*reg);
 return val;
}

canonical_original_code:
char read08(unsigned long reg1){
 unsigned long *reg;
 char val;
 reg=reg1;
 val=(char)(*reg);
 return val;
}

variable_types:
reg
unsigned long *

return_type: char


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

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

original_code:
signed short read16(unsigned long reg1){
 unsigned long *reg;
 signed short val;
 reg=reg1;
 val=(short)*(reg);
 return val;
}

canonical_original_code:
short read16(unsigned long reg1){
 unsigned long *reg;
 short val;
 reg=reg1;
 val=(short)*(reg);
 return val;
}

return_type: short


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

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

original_code:
long read32(unsigned long reg1){
 unsigned long *reg;
 signed long val;
 reg=reg1;
 val=(long)*(reg);
 return val;
}

canonical_original_code:
long read32(unsigned long reg1){
 unsigned long *reg;
 long val;
 reg=reg1;
 val=(long)*(reg);
 return val;
}

return_type: long


decompiled_code:
__int64 __fastcall send_data(int fd, void *buf, size_t n)
{
size_t v4; // rbx
unsigned int v5; // er12
int v6; // eax

if ( !n )
return 0;
v4 = n;
v5 = 0;
while ( 1 )
{
v6 = send(fd, buf, v4, 0x4000);
if ( (unsigned int)(v6 + 1) <= 1 )
break;
v5 += v6;
buf = (char *)buf + v6;
v4 -= v6;
if ( !v4 )
return v5;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, size_t n)
{
size_t v4; // rbx
unsigned int v5; // er12
int v6; // eax

if ( !n )
return 0;
v4 = n;
v5 = 0;
while ( 1 )
{
v6 = send(fd, buf, v4, 0x4000);
if ( (unsigned int)(v6 + 1) <= 1 )
break;
v5 += v6;
buf = (char *)buf + v6;
v4 -= v6;
if ( !v4 )
return v5;
}
return (unsigned int)-1;
}

original_code:
int send_data(int fd,void *buf,size_t buflen)
{
     int cc=0,total=0;
     while (buflen > 0) {
          cc = send(fd, buf, buflen, MSG_NOSIGNAL);
          if (cc == -1) {
               return cc;
          }
          if (cc == 0) {
            return -1;
          }
          buf += cc;
          total += cc;
          buflen -= cc;
     }
     return total;
}

canonical_original_code:
int send_data(int fd, void *buf, unsigned long buflen)
{
     int cc = 0; int total = 0;
     while (buflen > 0) {
          cc = send(fd, buf, buflen, MSG_NOSIGNAL);
          if (cc == -1) {
               return cc;
          }
          if (cc == 0) {
            return -1;
          }
          buf += cc;
          total += cc;
          buflen -= cc;
     }
     return total;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
buflen
unsigned long

variable_types: cc int

variable_types: total int


decompiled_code:
__int64 __fastcall recv_data(int fd, void *buf, size_t n)
{
size_t v4; // rbx
unsigned int v5; // er12
int v6; // eax

if ( !n )
return 0;
v4 = n;
v5 = 0;
while ( 1 )
{
v6 = recv(fd, buf, v4, 0x4000);
if ( (unsigned int)(v6 + 1) <= 1 )
break;
v5 += v6;
buf = (char *)buf + v6;
v4 -= v6;
if ( !v4 )
return v5;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf, size_t n)
{
size_t v4; // rbx
unsigned int v5; // er12
int v6; // eax

if ( !n )
return 0;
v4 = n;
v5 = 0;
while ( 1 )
{
v6 = recv(fd, buf, v4, 0x4000);
if ( (unsigned int)(v6 + 1) <= 1 )
break;
v5 += v6;
buf = (char *)buf + v6;
v4 -= v6;
if ( !v4 )
return v5;
}
return (unsigned int)-1;
}

original_code:
int recv_data(int fd,void *buf,size_t buflen)
{
     int cc=0,total=0;
     while (buflen > 0) {
          cc = recv(fd, buf, buflen, MSG_NOSIGNAL);
          if (cc == -1) {
               return cc;
          }
          if (cc == 0) {
            return -1;
          }
          buf += cc;
          total += cc;
          buflen -= cc;
     }
     return total;
}

canonical_original_code:
int recv_data(int fd, void *buf, unsigned long buflen)
{
     int cc = 0; int total = 0;
     while (buflen > 0) {
          cc = recv(fd, buf, buflen, MSG_NOSIGNAL);
          if (cc == -1) {
               return cc;
          }
          if (cc == 0) {
            return -1;
          }
          buf += cc;
          total += cc;
          buflen -= cc;
     }
     return total;
}


repo: jsravn/fixpixel

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init(argc, argv, envp);
spamcolors();
cleanup();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(argc, argv, envp);
func11();
func12();
return 0;
}

original_code:
int main(void) {
    init();
    spamcolors();
    cleanup();
    return 0;
}

canonical_original_code:
int main() {
    init();
    spamcolors();
    cleanup();
    return 0;
}


nanotime

decompiled_code:
__syscall_slong_t nanotime()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return v1.tv_nsec + 1000000000 * v1.tv_sec;
}

canonical_decompiled_code:
__syscall_slong_t func7()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return v1.tv_nsec + 1000000000 * v1.tv_sec;
}

original_code:
static long nanotime(void) {
    struct timespec cur;
    clock_gettime(1, &cur);
    return cur.tv_sec * ONE_BILLION + cur.tv_nsec;
}

canonical_original_code:
static long nanotime() {
    struct timespec cur;
    clock_gettime(1, &cur);
    return cur.tv_sec * ONE_BILLION + cur.tv_nsec;
}

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


init

decompiled_code:
__syscall_slong_t init()
{
int v0; // eax
unsigned int v1; // eax
__syscall_slong_t result; // rax
int v3; // ebp

initscr();
cbreak();
noecho();
nodelay(_bss_start, 1);
curs_set(0);
v0 = start_color();
if ( v0 )
{
v3 = v0;
endwin();
puts("Terminal does not support color mode");
exit(v3);
}
init_pair(1, 7, 1);
init_pair(2, 7, 2);
init_pair(3, 7, 4);
v1 = time(0LL);
srand(v1);
frames = 0LL;
result = nanotime();
start = result;
return result;
}

canonical_decompiled_code:
__syscall_slong_t func8()
{
int v0; // eax
unsigned int v1; // eax
__syscall_slong_t result; // rax
int v3; // ebp

initscr();
cbreak();
noecho();
nodelay(_bss_start, 1);
curs_set(0);
v0 = start_color();
if ( v0 )
{
v3 = v0;
endwin();
puts("Terminal does not support color mode");
exit(v3);
}
init_pair(1, 7, 1);
init_pair(2, 7, 2);
init_pair(3, 7, 4);
v1 = time(0LL);
srand(v1);
frames = 0LL;
result = func7();
start = result;
return result;
}

original_code:
static void init(void) {
    initscr(); cbreak(); noecho(); nodelay(stdscr, 1); curs_set(0);
    int r = start_color();
    if (r) {
        endwin();
        puts("Terminal does not support color mode");
        exit(r);
    }
    init_pair(RED_BG, 7, 1);
    init_pair(GREEN_BG, 7, 2);
    init_pair(BLUE_BG, 7, 4);
    srand(time(((void *)0)));
    frames = 0;
    start = nanotime();
}

canonical_original_code:
static void init() {
    initscr(); cbreak(); noecho(); nodelay(stdscr, 1); curs_set(0);
    int r = start_color();
    if (r) {
        endwin();
        puts("Terminal does not support color mode");
        exit(r);
    }
    init_pair(RED_BG, 7, 1);
    init_pair(GREEN_BG, 7, 2);
    init_pair(BLUE_BG, 7, 4);
    srand(time(((void *)0)));
    frames = 0;
    start = nanotime();
}

variable_types: r int


decompiled_code:
__int64 rand_color_pair()
{
unsigned int v0; // eax

v0 = rand() % 3;
if ( v0 > 2 )
{
endwin();
puts("BUG - rand_color_pair");
exit(-1);
}
return (v0 + 1) << 8;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // eax

v0 = rand() % 3;
if ( v0 > 2 )
{
endwin();
puts("BUG - rand_color_pair");
exit(-1);
}
return (v0 + 1) << 8;
}


decompiled_code:
__syscall_slong_t wait_for_next_frame()
{
__syscall_slong_t result; // rax
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

v1.tv_sec = 0LL;
v1.tv_nsec = 100000LL;
while ( 1 )
{
result = nanotime();
if ( (double)((int)result - (int)last_nanos_0) > 16666666.66666667 )
break;
nanosleep(&v1, 0LL);
}
last_nanos_0 = result;
return result;
}

canonical_decompiled_code:
__syscall_slong_t func10()
{
__syscall_slong_t result; // rax
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

v1.tv_sec = 0LL;
v1.tv_nsec = 100000LL;
while ( 1 )
{
result = func7();
if ( (double)((int)result - (int)last_nanos_0) > 16666666.66666667 )
break;
nanosleep(&v1, 0LL);
}
last_nanos_0 = result;
return result;
}

original_code:
static void wait_for_next_frame(void) {
    static long last_nanos = 0;
    const struct timespec sleep_time = { 0, RESOLUTION_MS * ONE_MILLION };
    while (1) {
        long cur_nanos = nanotime();
        long since_last_nanos = cur_nanos - last_nanos;
        if (since_last_nanos > (1.0 / FPS_CAP) * ONE_BILLION) {
            last_nanos = cur_nanos;
            break;
        }
        nanosleep(&sleep_time, ((void *)0));
    }
}

canonical_original_code:
static void wait_for_next_frame() {
    static long last_nanos = 0;
    struct timespec sleep_time = { 0, RESOLUTION_MS * ONE_MILLION };
    while (1) {
        long cur_nanos = nanotime();
        long since_last_nanos = cur_nanos - last_nanos;
        if (since_last_nanos > (1.0 / FPS_CAP) * ONE_BILLION) {
            last_nanos = cur_nanos;
            break;
        }
        nanosleep(&sleep_time, ((void *)0));
    }
}

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


spamcolors

decompiled_code:
int spamcolors()
{
chtype v0; // rsi
int result; // eax

while ( 1 )
{
result = wgetch(_bss_start);
if ( result != -1 )
break;
v0 = (unsigned int)rand_color_pair();
wbkgd(_bss_start, v0);
wrefresh(_bss_start);
++frames;
wait_for_next_frame();
}
return result;
}

canonical_decompiled_code:
int func11()
{
chtype v0; // rsi
int result; // eax

while ( 1 )
{
result = wgetch(_bss_start);
if ( result != -1 )
break;
v0 = (unsigned int)func9();
wbkgd(_bss_start, v0);
wrefresh(_bss_start);
++frames;
func10();
}
return result;
}

original_code:
static void spamcolors(void) {
    while (wgetch(stdscr) == (-1)) {
        wbkgd(stdscr,(rand_color_pair()));
        wrefresh(stdscr);
        frames++;
        wait_for_next_frame();
    }
}

canonical_original_code:
static void spamcolors() {
    while (wgetch(stdscr) == (-1)) {
        wbkgd(stdscr,(rand_color_pair()));
        wrefresh(stdscr);
        frames++;
        wait_for_next_frame();
    }
}


cleanup

decompiled_code:
int cleanup()
{
int v0; // eax
double v1; // xmm0_8

endwin();
v0 = nanotime();
if ( frames < 0 )
v1 = (double)(int)(frames & 1 | ((unsigned __int64)frames >> 1))
+ (double)(int)(frames & 1 | ((unsigned __int64)frames >> 1));
else
v1 = (double)(int)frames;
return printf("Frames per second: %f\n", v1 / ((double)(v0 - (int)start) / 1000000000.0));
}

canonical_decompiled_code:
int func12()
{
int v0; // eax
double v1; // xmm0_8

endwin();
v0 = func7();
if ( frames < 0 )
v1 = (double)(int)(frames & 1 | ((unsigned __int64)frames >> 1))
+ (double)(int)(frames & 1 | ((unsigned __int64)frames >> 1));
else
v1 = (double)(int)frames;
return printf("Frames per second: %f\n", v1 / ((double)(v0 - (int)start) / 1000000000.0));
}

original_code:
static void cleanup(void) {
    endwin();
    double elapsed_s = ((nanotime() - start) / (double) ONE_BILLION);
    printf("Frames per second: %f\n", frames / elapsed_s);
}

canonical_original_code:
static void cleanup() {
    endwin();
    double elapsed_s = ((nanotime() - start) / (double) ONE_BILLION);
    printf("Frames per second: %f\n", frames / elapsed_s);
}


dummyFunc

repo: jstancek/selinux-testsuite

decompiled_code:
void __fastcall __noreturn dummyFunc(void *arg)
{
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *arg)
{
exit(0);
}

original_code:
static int dummyFunc(void *arg)
{
 exit(0);
}

variable_types:
arg
void *