decompiled_code:
const char *write_tree()
{
char *v0; // rbp
size_t v1; // rax
char *v2; // rbp
int v3; // er13
__off_t v4; // r14
char *v5; // r12
int v6; // ebx
unsigned int v7; // ebx
const char *v8; // r13
char *v9; // rbp
size_t v10; // rax
char *v11; // rbp
int v12; // eax
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "index");
v3 = open(v2, 2);
free(v2);
fstat(v3, &v14);
v4 = v14.st_size;
v5 = (char *)malloc(v14.st_size + 15);
sprintf(v5, "tree %lu", v4);
v6 = strlen(v5) + 1;
read(v3, &v5[v6], v14.st_size);
v7 = LODWORD(v14.st_size) + v6;
v8 = (const char *)hash_object(v5, v7);
v9 = (char *)get_repo_troll_dir();
v10 = strlen(v9);
v11 = (char *)realloc(v9, v10 + 49);
strcat(v11, "objects/");
strncat(v11, v8, 0x28uLL);
v12 = open(v11, 577, 420LL);
write(v12, v5, (int)v7);
return v8;
}

canonical_decompiled_code:
const char *func0()
{
char *v0; // rbp
size_t v1; // rax
char *v2; // rbp
int v3; // er13
__off_t v4; // r14
char *v5; // r12
int v6; // ebx
unsigned int v7; // ebx
const char *v8; // r13
char *v9; // rbp
size_t v10; // rax
char *v11; // rbp
int v12; // eax
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "index");
v3 = open(v2, 2);
free(v2);
fstat(v3, &v14);
v4 = v14.st_size;
v5 = (char *)malloc(v14.st_size + 15);
sprintf(v5, "tree %lu", v4);
v6 = strlen(v5) + 1;
read(v3, &v5[v6], v14.st_size);
v7 = LODWORD(v14.st_size) + v6;
v8 = (const char *)hash_object(v5, v7);
v9 = (char *)get_repo_troll_dir();
v10 = strlen(v9);
v11 = (char *)realloc(v9, v10 + 49);
strcat(v11, "objects/");
strncat(v11, v8, 0x28uLL);
v12 = open(v11, 577, 420LL);
write(v12, v5, (int)v7);
return v8;
}

original_code:
char *write_tree() {
    char *indexpath = get_repo_troll_dir();
    indexpath = (char *) realloc(indexpath, strlen(indexpath) + 5);
    strcat(indexpath, "index");
    int fd = open(indexpath, 02);
    free(indexpath);
    struct stat buf;
    fstat(fd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 15);
    sprintf(data, "tree %lu", (unsigned long) buf.st_size);
    int left_part_len = strlen(data) + 1;
    read(fd, data + left_part_len, buf.st_size);
    int full_len = left_part_len + buf.st_size;
    char *hash = hash_object(data, full_len);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 49);
    strcat(path, "objects/");
    strncat(path, hash, 40);
    int objectfd = open(path, 0100 | 01000 | 01, 0644);
    write(objectfd, data, full_len);
    return hash;
}

variable_types:
indexpath
char *

variable_types:
path
char *

variable_types: objectfd int


repo: kevinwang/troll

decompiled_code:
const char *write_commit()
{
char *v0; // rbp
size_t v1; // rax
char *v2; // rbp
int v3; // er12
__off_t v4; // r14
char *v5; // r13
int v6; // ebx
unsigned int v7; // ebx
const char *v8; // r12
char *v9; // rbp
size_t v10; // rax
char *v11; // rbp
int v12; // eax
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 10);
strcat(v2, "tmpcommit");
v3 = open(v2, 0, 420LL);
free(v2);
fstat(v3, &v14);
v4 = v14.st_size;
v5 = (char *)malloc(v14.st_size + 17);
sprintf(v5, "commit %lu", v4);
v6 = strlen(v5) + 1;
read(v3, &v5[v6], v14.st_size);
close(v3);
v7 = LODWORD(v14.st_size) + v6;
v8 = (const char *)hash_object(v5, v7);
v9 = (char *)get_repo_troll_dir();
v10 = strlen(v9);
v11 = (char *)realloc(v9, v10 + 49);
strcat(v11, "objects/");
strncat(v11, v8, 0x28uLL);
v12 = open(v11, 577, 420LL);
write(v12, v5, (int)v7);
return v8;
}

canonical_decompiled_code:
const char *func0()
{
char *v0; // rbp
size_t v1; // rax
char *v2; // rbp
int v3; // er12
__off_t v4; // r14
char *v5; // r13
int v6; // ebx
unsigned int v7; // ebx
const char *v8; // r12
char *v9; // rbp
size_t v10; // rax
char *v11; // rbp
int v12; // eax
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v0 = (char *)get_repo_troll_dir();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 10);
strcat(v2, "tmpcommit");
v3 = open(v2, 0, 420LL);
free(v2);
fstat(v3, &v14);
v4 = v14.st_size;
v5 = (char *)malloc(v14.st_size + 17);
sprintf(v5, "commit %lu", v4);
v6 = strlen(v5) + 1;
read(v3, &v5[v6], v14.st_size);
close(v3);
v7 = LODWORD(v14.st_size) + v6;
v8 = (const char *)hash_object(v5, v7);
v9 = (char *)get_repo_troll_dir();
v10 = strlen(v9);
v11 = (char *)realloc(v9, v10 + 49);
strcat(v11, "objects/");
strncat(v11, v8, 0x28uLL);
v12 = open(v11, 577, 420LL);
write(v12, v5, (int)v7);
return v8;
}

original_code:
char *write_commit() {
    char *tmpcommit_path = get_repo_troll_dir();
    tmpcommit_path = (char *) realloc(tmpcommit_path, strlen(tmpcommit_path) + 10);
    strcat(tmpcommit_path, "tmpcommit");
    int tmpcommitfd = open(tmpcommit_path, 00, 0644);
    free(tmpcommit_path);
    struct stat buf;
    fstat(tmpcommitfd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 17);
    sprintf(data, "commit %lu", (unsigned long) buf.st_size);
    int left_part_len = strlen(data) + 1;
    read(tmpcommitfd, data + left_part_len, buf.st_size);
    close(tmpcommitfd);
    int full_len = left_part_len + buf.st_size;
    char *hash = hash_object(data, full_len);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 49);
    strcat(path, "objects/");
    strncat(path, hash, 40);
    int objectfd = open(path, 0100 | 01000 | 01, 0644);
    write(objectfd, data, full_len);
    return hash;
}

variable_types: tmpcommitfd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
data
char *

variable_types:
hash
char *

return_type: char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


commit

decompiled_code:
int __fastcall commit(void *buf)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // r12
const void *v4; // r13
int v5; // ebp
char *v6; // r12
size_t v7; // rax
char *v8; // r12
int v9; // er13
void *v10; // r15
char *v11; // rax
size_t v12; // r15
char *v13; // rax
size_t v14; // rax
const char *v15; // r15
void *v16; // rbp
size_t v17; // rax
char *v18; // rbp
int v19; // ebp
struct stat v21; // [rsp+0h] [rbp-148h] BYREF
struct stat bufa; // [rsp+90h] [rbp-B8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 10);
strcat(v3, "tmpcommit");
v4 = (const void *)write_tree();
v5 = open(v3, 577, 420LL);
free(v3);
write(v5, "tree ", 5uLL);
write(v5, v4, 0x28uLL);
v6 = (char *)get_repo_troll_dir();
v7 = strlen(v6);
v8 = (char *)realloc(v6, v7 + 7);
strcat(v8, "master");
v9 = open(v8, 66, 420LL);
fstat(v9, &v21);
if ( v21.st_size > 0 )
{
write(v5, "\nparent ", 8uLL);
v10 = malloc(0x29uLL);
read(v9, v10, 0x28uLL);
write(v5, v10, 0x28uLL);
}
write(v5, "\nauthor ", 8uLL);
v11 = getenv("USER");
v12 = strlen(v11);
v13 = getenv("USER");
write(v5, v13, v12);
write(v5, "\n\n", 2uLL);
v14 = strlen((const char *)buf);
write(v5, buf, v14);
write(v5, "\n", 1uLL);
close(v5);
v15 = write_commit();
lseek(v9, 0LL, 0);
write(v9, v15, 0x28uLL);
v16 = (void *)get_repo_troll_dir();
v17 = strlen(v8);
v18 = (char *)realloc(v16, v17 + 5);
strcat(v18, "HEAD");
v19 = open(v18, 66, 420LL);
fstat(v19, &bufa);
if ( !bufa.st_size )
write(v19, "master", 6uLL);
return printf("[master %.7s] %s\n", v15, (const char *)buf);
}

canonical_decompiled_code:
int __fastcall func1(void *buf)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // r12
const void *v4; // r13
int v5; // ebp
char *v6; // r12
size_t v7; // rax
char *v8; // r12
int v9; // er13
void *v10; // r15
char *v11; // rax
size_t v12; // r15
char *v13; // rax
size_t v14; // rax
const char *v15; // r15
void *v16; // rbp
size_t v17; // rax
char *v18; // rbp
int v19; // ebp
struct stat v21; // [rsp+0h] [rbp-148h] BYREF
struct stat bufa; // [rsp+90h] [rbp-B8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 10);
strcat(v3, "tmpcommit");
v4 = (const void *)write_tree();
v5 = open(v3, 577, 420LL);
free(v3);
write(v5, "tree ", 5uLL);
write(v5, v4, 0x28uLL);
v6 = (char *)get_repo_troll_dir();
v7 = strlen(v6);
v8 = (char *)realloc(v6, v7 + 7);
strcat(v8, "master");
v9 = open(v8, 66, 420LL);
fstat(v9, &v21);
if ( v21.st_size > 0 )
{
write(v5, "\nparent ", 8uLL);
v10 = malloc(0x29uLL);
read(v9, v10, 0x28uLL);
write(v5, v10, 0x28uLL);
}
write(v5, "\nauthor ", 8uLL);
v11 = getenv("USER");
v12 = strlen(v11);
v13 = getenv("USER");
write(v5, v13, v12);
write(v5, "\n\n", 2uLL);
v14 = strlen((const char *)buf);
write(v5, buf, v14);
write(v5, "\n", 1uLL);
close(v5);
v15 = func0();
lseek(v9, 0LL, 0);
write(v9, v15, 0x28uLL);
v16 = (void *)get_repo_troll_dir();
v17 = strlen(v8);
v18 = (char *)realloc(v16, v17 + 5);
strcat(v18, "HEAD");
v19 = open(v18, 66, 420LL);
fstat(v19, &bufa);
if ( !bufa.st_size )
write(v19, "master", 6uLL);
return printf("[master %.7s] %s\n", v15, (const char *)buf);
}

original_code:
void commit(const char *message) {
    char *tmpcommit_path = get_repo_troll_dir();
    tmpcommit_path = (char *) realloc(tmpcommit_path, strlen(tmpcommit_path) + 10);
    strcat(tmpcommit_path, "tmpcommit");
    char *treehash = write_tree();
    int tmpcommitfd = open(tmpcommit_path, 0100 | 01000 | 01, 0644);
    free(tmpcommit_path);
    write(tmpcommitfd, "tree ", 5);
    write(tmpcommitfd, treehash, 40);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 7);
    strcat(path, "master");
    int masterfd = open(path, 0100 | 02, 0644);
    struct stat buf;
    fstat(masterfd, &buf);
    if (buf.st_size > 0) {
        write(tmpcommitfd, "\nparent ", 8);
        char *parenthash = (char *) malloc(41 * sizeof(char));
        read(masterfd, parenthash, 40);
        write(tmpcommitfd, parenthash, 40);
    }
    write(tmpcommitfd, "\nauthor ", 8);
    write(tmpcommitfd, getenv("USER"), strlen(getenv("USER")));
    write(tmpcommitfd, "\n\n", 2);
    write(tmpcommitfd, message, strlen(message));
    write(tmpcommitfd, "\n", 1);
    close(tmpcommitfd);
    char *hash = write_commit();
    lseek(masterfd, 0, 0);
    write(masterfd, hash, 40);
    char *headpath = get_repo_troll_dir();
    headpath = (char *) realloc(headpath, strlen(path) + 5);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100 | 02, 0644);
    struct stat headbuf;
    fstat(headfd, &headbuf);
    if (headbuf.st_size == 0) {
        write(headfd, "master", 6);
    }
    printf("[master %.7s] %s\n", hash, message);
}

canonical_original_code:
void commit(char *message) {
    char *tmpcommit_path = get_repo_troll_dir();
    tmpcommit_path = (char *) realloc(tmpcommit_path, strlen(tmpcommit_path) + 10);
    strcat(tmpcommit_path, "tmpcommit");
    char *treehash = write_tree();
    int tmpcommitfd = open(tmpcommit_path, 0100 | 01000 | 01, 0644);
    free(tmpcommit_path);
    write(tmpcommitfd, "tree ", 5);
    write(tmpcommitfd, treehash, 40);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 7);
    strcat(path, "master");
    int masterfd = open(path, 0100 | 02, 0644);
    struct stat buf;
    fstat(masterfd, &buf);
    if (buf.st_size > 0) {
        write(tmpcommitfd, "\nparent ", 8);
        char *parenthash = (char *) malloc(41 * sizeof(char));
        read(masterfd, parenthash, 40);
        write(tmpcommitfd, parenthash, 40);
    }
    write(tmpcommitfd, "\nauthor ", 8);
    write(tmpcommitfd, getenv("USER"), strlen(getenv("USER")));
    write(tmpcommitfd, "\n\n", 2);
    write(tmpcommitfd, message, strlen(message));
    write(tmpcommitfd, "\n", 1);
    close(tmpcommitfd);
    char *hash = write_commit();
    lseek(masterfd, 0, 0);
    write(masterfd, hash, 40);
    char *headpath = get_repo_troll_dir();
    headpath = (char *) realloc(headpath, strlen(path) + 5);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100 | 02, 0644);
    struct stat headbuf;
    fstat(headfd, &headbuf);
    if (headbuf.st_size == 0) {
        write(headfd, "master", 6);
    }
    printf("[master %.7s] %s\n", hash, message);
}

variable_types:
message
char *

variable_types:
treehash
char *

variable_types: masterfd int

variable_types:
parenthash
char *

variable_types:
headpath
char *

variable_types: headfd int

return_type: void

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


decompiled_code:
char *__fastcall get_parent(char *src)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // r12
int v4; // er12
__off_t v5; // r13
void *v6; // rbp
size_t v7; // rax
char *v8; // rax
const char *v9; // r13
char *v10; // r12
char *result; // rax
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 49);
strcat(v3, "objects/");
strncat(v3, src, 0x28uLL);
v4 = open(v3, 0);
if ( *_errno_location() == 2 )
{
puts("fatal: Object does not exist.");
exit(128);
}
fstat(v4, &v12);
v5 = v12.st_size;
v6 = malloc(v12.st_size + 1);
read(v4, v6, v5);
v7 = strlen((const char *)v6);
v8 = strstr((const char *)v6 + v7 + 1, "parent");
if ( v8 )
{
v9 = v8 + 7;
v10 = (char *)malloc(0x29uLL);
strncpy(v10, v9, 0x28uLL);
free(v6);
result = v10;
}
else
{
free(v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // r12
int v4; // er12
__off_t v5; // r13
void *v6; // rbp
size_t v7; // rax
char *v8; // rax
const char *v9; // r13
char *v10; // r12
char *result; // rax
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 49);
strcat(v3, "objects/");
strncat(v3, src, 0x28uLL);
v4 = open(v3, 0);
if ( *_errno_location() == 2 )
{
puts("fatal: Object does not exist.");
exit(128);
}
fstat(v4, &v12);
v5 = v12.st_size;
v6 = malloc(v12.st_size + 1);
read(v4, v6, v5);
v7 = strlen((const char *)v6);
v8 = strstr((const char *)v6 + v7 + 1, "parent");
if ( v8 )
{
v9 = v8 + 7;
v10 = (char *)malloc(0x29uLL);
strncpy(v10, v9, 0x28uLL);
free(v6);
result = v10;
}
else
{
free(v6);
result = 0LL;
}
return result;
}

original_code:
char *get_parent(char *hash) {
    char *obj_path = get_repo_troll_dir();
    obj_path = (char *) realloc(obj_path, strlen(obj_path) + 49);
    strcat(obj_path, "objects/");
    strncat(obj_path, hash, 40);
    int objectfd = open(obj_path, 00);
    if ((*__errno_location ()) == 2) {
        printf("fatal: Object does not exist.\n");
        exit(128);
    }
    struct stat buf;
    fstat(objectfd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 1);
    read(objectfd, data, buf.st_size);
    char *data_right = data + strlen(data) + 1;
    char *parent_hash = strstr(data_right, "parent");
    if (parent_hash) {
        parent_hash += 7;
        char *hashcpy = (char *) malloc(41 * sizeof(char));
        strncpy(hashcpy, parent_hash, 40);
        free(data);
        return hashcpy;
    }
    free(data);
    return ((void *)0);
}

variable_types:
hashcpy
char *


decompiled_code:
void *__fastcall init_troll_dir(char *path)
{
char *v1; // rbp
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
char *v6; // rdx
size_t v7; // r13
void *v8; // r12
size_t v9; // rax
char *v10; // rbp
size_t v11; // rax
void *v12; // r13
size_t v13; // rbx
int v14; // eax
size_t v15; // rax
void *v16; // r13
size_t v17; // rbx
int v18; // eax
size_t v20; // rax

v1 = getcwd(0LL, 0LL);
if ( path )
{
v2 = strlen(v1);
v3 = strlen(path);
v4 = (char *)realloc(v1, v2 + v3 + 9);
v5 = strlen(v4);
*(_WORD *)&v4[v5] = 47;
strncat(v4, path, v5 + 1);
*(_WORD *)&v4[strlen(v4)] = 47;
mkdir(path, 0x1EDu);
}
else
{
v20 = strlen(v1);
v4 = (char *)realloc(v1, v20 + 9);
*(_WORD *)&v4[strlen(v4)] = 47;
}
v6 = &v4[strlen(v4)];
*((_WORD *)v6 + 2) = 27756;
*(_DWORD *)v6 = 1869771822;
*((_WORD *)v6 + 3) = 47;
mkdir(v4, 0x1EDu);
v7 = strlen(v4) + 1;
v8 = malloc(v7);
memcpy(v8, v4, v7);
v9 = strlen(v4);
v10 = (char *)realloc(v4, v9 + 7);
*(_QWORD *)&v10[strlen(v10)] = 0x737463656A626FLL;
mkdir(v10, 0x1EDu);
v11 = strlen(v10);
v12 = malloc(v11 + 6);
v13 = strlen((const char *)v8);
memcpy(v12, v8, v13);
strcpy((char *)v12 + v13, "index");
v14 = open((const char *)v12, 64, 420LL);
close(v14);
v15 = strlen(v10);
v16 = malloc(v15 + 5);
v17 = strlen((const char *)v8);
memcpy(v16, v8, v17);
strcpy((char *)v16 + v17, "HEAD");
v18 = open((const char *)v16, 64, 420LL);
close(v18);
free(v10);
return v8;
}

canonical_decompiled_code:
void *__fastcall func0(char *path)
{
char *v1; // rbp
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
char *v6; // rdx
size_t v7; // r13
void *v8; // r12
size_t v9; // rax
char *v10; // rbp
size_t v11; // rax
void *v12; // r13
size_t v13; // rbx
int v14; // eax
size_t v15; // rax
void *v16; // r13
size_t v17; // rbx
int v18; // eax
size_t v20; // rax

v1 = getcwd(0LL, 0LL);
if ( path )
{
v2 = strlen(v1);
v3 = strlen(path);
v4 = (char *)realloc(v1, v2 + v3 + 9);
v5 = strlen(v4);
*(_WORD *)&v4[v5] = 47;
strncat(v4, path, v5 + 1);
*(_WORD *)&v4[strlen(v4)] = 47;
mkdir(path, 0x1EDu);
}
else
{
v20 = strlen(v1);
v4 = (char *)realloc(v1, v20 + 9);
*(_WORD *)&v4[strlen(v4)] = 47;
}
v6 = &v4[strlen(v4)];
*((_WORD *)v6 + 2) = 27756;
*(_DWORD *)v6 = 1869771822;
*((_WORD *)v6 + 3) = 47;
mkdir(v4, 0x1EDu);
v7 = strlen(v4) + 1;
v8 = malloc(v7);
memcpy(v8, v4, v7);
v9 = strlen(v4);
v10 = (char *)realloc(v4, v9 + 7);
*(_QWORD *)&v10[strlen(v10)] = 0x737463656A626FLL;
mkdir(v10, 0x1EDu);
v11 = strlen(v10);
v12 = malloc(v11 + 6);
v13 = strlen((const char *)v8);
memcpy(v12, v8, v13);
strcpy((char *)v12 + v13, "index");
v14 = open((const char *)v12, 64, 420LL);
close(v14);
v15 = strlen(v10);
v16 = malloc(v15 + 5);
v17 = strlen((const char *)v8);
memcpy(v16, v8, v17);
strcpy((char *)v16 + v17, "HEAD");
v18 = open((const char *)v16, 64, 420LL);
close(v18);
free(v10);
return v8;
}

original_code:
char *init_troll_dir(const char *base) {
    char *dir = getcwd(((void *)0), 0);
    if (base) {
        dir = (char *) realloc(dir, strlen(dir) + strlen(base) + 9);
    }
    else {
        dir = (char *) realloc(dir, strlen(dir) + 9);
    }
    strcat(dir, "/");
    if (base) {
        strncat(dir, base, strlen(dir));
        strcat(dir, "/");
        mkdir(base, 0755);
    }
    strcat(dir, ".troll");
    strcat(dir, "/");
    mkdir(dir, 0755);
    char *trolldir = (char *) malloc(strlen(dir) + 1);
    memcpy(trolldir, dir, strlen(dir) + 1);
    dir = (char *) realloc(dir, strlen(dir) + 7);
    strcat(dir, "objects");
    mkdir(dir, 0755);
    char *indexpath = (char *) malloc(strlen(dir) + 6);
    memcpy(indexpath, trolldir, strlen(trolldir) + 1);
    strcat(indexpath, "index");
    int fd = open(indexpath, 0100, 0644);
    close(fd);
    char *headpath = (char *) malloc(strlen(dir) + 5);
    memcpy(headpath, trolldir, strlen(trolldir) + 1);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100, 0644);
    close(headfd);
    free(dir);
    return trolldir;
}

canonical_original_code:
char *init_troll_dir(char *base) {
    char *dir = getcwd(((void *)0), 0);
    if (base) {
        dir = (char *) realloc(dir, strlen(dir) + strlen(base) + 9);
    }
    else {
        dir = (char *) realloc(dir, strlen(dir) + 9);
    }
    strcat(dir, "/");
    if (base) {
        strncat(dir, base, strlen(dir));
        strcat(dir, "/");
        mkdir(base, 0755);
    }
    strcat(dir, ".troll");
    strcat(dir, "/");
    mkdir(dir, 0755);
    char *trolldir = (char *) malloc(strlen(dir) + 1);
    memcpy(trolldir, dir, strlen(dir) + 1);
    dir = (char *) realloc(dir, strlen(dir) + 7);
    strcat(dir, "objects");
    mkdir(dir, 0755);
    char *indexpath = (char *) malloc(strlen(dir) + 6);
    memcpy(indexpath, trolldir, strlen(trolldir) + 1);
    strcat(indexpath, "index");
    int fd = open(indexpath, 0100, 0644);
    close(fd);
    char *headpath = (char *) malloc(strlen(dir) + 5);
    memcpy(headpath, trolldir, strlen(trolldir) + 1);
    strcat(headpath, "HEAD");
    int headfd = open(headpath, 0100, 0644);
    close(headfd);
    free(dir);
    return trolldir;
}

variable_types:
base
char *

variable_types:
dir
char *

variable_types:
trolldir
char *

variable_types: fd int


decompiled_code:
char *recursive_get_repo_troll_dir()
{
char *v0; // rbp
size_t v2; // rax
char *v3; // r12

while ( 1 )
{
v0 = getcwd(0LL, 0LL);
if ( !chdir(".troll") )
break;
if ( *v0 == 47 && !v0[1] )
return 0LL;
chdir("..");
}
v2 = strlen(v0);
v3 = (char *)realloc(v0, v2 + 9);
strcat(v3, "/.troll/");
return v3;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbp
size_t v2; // rax
char *v3; // r12

while ( 1 )
{
v0 = getcwd(0LL, 0LL);
if ( !chdir(".troll") )
break;
if ( *v0 == 47 && !v0[1] )
return 0LL;
chdir("..");
}
v2 = strlen(v0);
v3 = (char *)realloc(v0, v2 + 9);
strcat(v3, "/.troll/");
return v3;
}

original_code:
char *recursive_get_repo_troll_dir() {
  char *cwd = getcwd(((void *)0), 0);
  int ret;
  ret = chdir(".troll");
  if (ret == 0 ) {
    cwd = (char *) realloc(cwd, strlen(cwd) + 9);
    strcat(cwd, "/.troll/");
    return cwd;
  }
  if (!strcmp(cwd, "/")) {
    return ((void *)0);
  }
  ret = chdir("..");
  return recursive_get_repo_troll_dir();
}

variable_types:
cwd
char *

variable_types: ret int


decompiled_code:
char *get_repo_troll_dir()
{
char *v0; // rbp
char *v1; // r12

v0 = getcwd(0LL, 0LL);
v1 = recursive_get_repo_troll_dir();
chdir(v0);
free(v0);
return v1;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbp
char *v1; // r12

v0 = getcwd(0LL, 0LL);
v1 = func1();
chdir(v0);
free(v0);
return v1;
}

original_code:
char *get_repo_troll_dir() {
    char *cwd = getcwd(((void *)0), 0);
    char *trolldir = recursive_get_repo_troll_dir();
    chdir(cwd);
    free(cwd);
    return trolldir;
}


decompiled_code:
void die_if_not_troll_repo()
{
char *v0; // rax

v0 = get_repo_troll_dir();
if ( !v0 )
{
puts("Not a troll repository.");
exit(128);
}
free(v0);
}

canonical_decompiled_code:
void func3()
{
char *v0; // rax

v0 = func2();
if ( !v0 )
{
puts("Not a troll repository.");
exit(128);
}
free(v0);
}

original_code:
void die_if_not_troll_repo() {
    char *trolldir = get_repo_troll_dir();
    if (trolldir) {
        free(trolldir);
    }
    else {
        free(trolldir);
        printf("Not a troll repository.\n");
        exit(128);
    }
}


decompiled_code:
__int64 __fastcall cmd_help(int a1, __int64 a2)
{
const char *v2; // r8
__int64 result; // rax

if ( a1 == 1 )
{
puts(help_text);
result = 0LL;
}
else
{
v2 = *(const char **)(a2 + 8);
if ( !strcmp(v2, "help") )
{
puts(h_help);
return 0LL;
}
if ( !strcmp(v2, "init") )
{
puts(h_init);
result = 0LL;
}
else
{
if ( strcmp(v2, "add") )
{
if ( !strcmp(v2, "commit") )
{
puts(h_commit);
}
else if ( !strcmp(v2, "ls-files") )
{
puts(h_ls_files);
}
else if ( !strcmp(v2, "log") )
{
puts(h_log);
}
else if ( !strcmp(v2, "checkout") )
{
puts(h_checkout);
}
else if ( !strcmp(v2, "status") )
{
puts(h_status);
}
else if ( !strcmp(v2, "face") )
{
puts(h_face);
}
else
{
printf("No manual entry for troll%s\n", v2);
}
return 0LL;
}
puts(h_add);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
const char *v2; // r8
__int64 result; // rax

if ( a1 == 1 )
{
puts(help_text);
result = 0LL;
}
else
{
v2 = *(const char **)(a2 + 8);
if ( !strcmp(v2, "help") )
{
puts(h_help);
return 0LL;
}
if ( !strcmp(v2, "init") )
{
puts(h_init);
result = 0LL;
}
else
{
if ( strcmp(v2, "add") )
{
if ( !strcmp(v2, "commit") )
{
puts(h_commit);
}
else if ( !strcmp(v2, "ls-files") )
{
puts(h_ls_files);
}
else if ( !strcmp(v2, "log") )
{
puts(h_log);
}
else if ( !strcmp(v2, "checkout") )
{
puts(h_checkout);
}
else if ( !strcmp(v2, "status") )
{
puts(h_status);
}
else if ( !strcmp(v2, "face") )
{
puts(h_face);
}
else
{
printf("No manual entry for troll%s\n", v2);
}
return 0LL;
}
puts(h_add);
result = 0LL;
}
}
return result;
}

original_code:
int cmd_help(int argc, const char *argv[]) {
    if (argc == 1) {
        printf("%s\n", help_text);
    }
    else {
      if(!strcmp(argv[1],"help")) {
 printf("%s\n", h_help);
      }
      else if(!strcmp(argv[1],"init")) {
 printf("%s\n", h_init);
      }
      else if(!strcmp(argv[1],"add")) {
 printf("%s\n", h_add);
      }
      else if(!strcmp(argv[1],"commit")) {
 printf("%s\n", h_commit);
      }
      else if(!strcmp(argv[1],"ls-files")) {
 printf("%s\n", h_ls_files);
      }
      else if(!strcmp(argv[1],"log")) {
 printf("%s\n", h_log);
      }
      else if(!strcmp(argv[1],"checkout")) {
 printf("%s\n", h_checkout);
      }
      else if(!strcmp(argv[1],"status")) {
 printf("%s\n", h_status);
      }
      else if(!strcmp(argv[1],"face")) {
 printf("%s\n", h_face);
      }
      else {
 printf("No manual entry for troll%s\n", argv[1]);
      }
    }
    return 0;
}

canonical_original_code:
int cmd_help(int argc, char *argv[]) {
    if (argc == 1) {
        printf("%s\n", help_text);
    }
    else {
      if(!strcmp(argv[1],"help")) {
 printf("%s\n", h_help);
      }
      else if(!strcmp(argv[1],"init")) {
 printf("%s\n", h_init);
      }
      else if(!strcmp(argv[1],"add")) {
 printf("%s\n", h_add);
      }
      else if(!strcmp(argv[1],"commit")) {
 printf("%s\n", h_commit);
      }
      else if(!strcmp(argv[1],"ls-files")) {
 printf("%s\n", h_ls_files);
      }
      else if(!strcmp(argv[1],"log")) {
 printf("%s\n", h_log);
      }
      else if(!strcmp(argv[1],"checkout")) {
 printf("%s\n", h_checkout);
      }
      else if(!strcmp(argv[1],"status")) {
 printf("%s\n", h_status);
      }
      else if(!strcmp(argv[1],"face")) {
 printf("%s\n", h_face);
      }
      else {
 printf("No manual entry for troll%s\n", argv[1]);
      }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


decompiled_code:
int __fastcall new_index(__int64 a1)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // rbp
int v4; // er12

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 5);
strcat(v3, "index");
printf("New index at %s\n", v3);
v4 = open(v3, 513, 420LL);
free(v3);
lseek(v4, 0LL, 0);
LODWORD(v3) = dup(1);
dup2(v4, 1);
print_object(a1);
return dup2((int)v3, 1);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // rbp
int v4; // er12

v1 = (char *)get_repo_troll_dir();
v2 = strlen(v1);
v3 = (char *)realloc(v1, v2 + 5);
strcat(v3, "index");
printf("New index at %s\n", v3);
v4 = open(v3, 513, 420LL);
free(v3);
lseek(v4, 0LL, 0);
LODWORD(v3) = dup(1);
dup2(v4, 1);
print_object(a1);
return dup2((int)v3, 1);
}

original_code:
void new_index(char *hash) {
    char *indexpath = get_repo_troll_dir();
    indexpath = (char *) realloc(indexpath, strlen(indexpath) + 5);
    strcat(indexpath, "index");
    printf("New index at %s\n",indexpath);
    int index = open(indexpath, 01 | 01000, 0644);
    free(indexpath);
    lseek(index, 0, 0);
    int sout = dup(1);
    dup2(index,1);
    print_object(hash);
    dup2(sout,1);
}

variable_types:
indexpath
char *

variable_types: index int

variable_types: sout int


decompiled_code:
__int64 __fastcall cmd_checkout(__int64 a1, __int64 a2)
{
new_index(*(_QWORD *)(a2 + 8));
copy_out();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
func0(*(_QWORD *)(a2 + 8));
func1();
return 0LL;
}

original_code:
int cmd_checkout(int argc, const char *argv[]) {
    new_index((char *)(argv[1]));
    copy_out();
    return 0;
}

canonical_original_code:
int cmd_checkout(int argc, char *argv[]) {
    new_index((char *)(argv[1]));
    copy_out();
    return 0;
}


decompiled_code:
void __fastcall print_log(__int64 a1)
{
__int64 v1; // rbp

if ( a1 )
{
v1 = a1;
do
{
print_object(v1);
putchar(10);
v1 = get_parent(v1);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
__int64 v1; // rbp

if ( a1 )
{
v1 = a1;
do
{
print_object(v1);
putchar(10);
v1 = get_parent(v1);
}
while ( v1 );
}
}

original_code:
void print_log(char *hash) {
    if (!hash) {
        return;
    }
    print_object(hash);
    printf("\n");
    print_log(get_parent(hash));
}

variable_types:
hash
char *


decompiled_code:
__int64 cmd_log()
{
char *v0; // rbp
size_t v1; // rax
char *v2; // rbp
int v3; // er12
void *v4; // rbp
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char *v11; // r13
size_t v12; // rax
char *v13; // r13
int v14; // eax

die_if_not_troll_repo();
v0 = (char *)((__int64 (*)(void))get_repo_troll_dir)();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "HEAD");
v3 = open(v2, 0);
v4 = malloc(0x29uLL);
if ( !(unsigned int)read(v3, v4, 0x28uLL) )
return 0xFFFFFFFFLL;
puts((const char *)v4);
v7 = "master";
v8 = 7LL;
v9 = (const char *)v4;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
v11 = (char *)get_repo_troll_dir(v7, v9);
v12 = strlen(v11);
v13 = (char *)realloc(v11, v12 + 7);
strcat(v13, "master");
v14 = open(v13, 0);
read(v14, v4, 0x28uLL);
}
print_log((__int64)v4);
free(v4);
close(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rbp
size_t v1; // rax
char *v2; // rbp
int v3; // er12
void *v4; // rbp
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char *v11; // r13
size_t v12; // rax
char *v13; // r13
int v14; // eax

die_if_not_troll_repo();
v0 = (char *)((__int64 (*)(void))get_repo_troll_dir)();
v1 = strlen(v0);
v2 = (char *)realloc(v0, v1 + 5);
strcat(v2, "HEAD");
v3 = open(v2, 0);
v4 = malloc(0x29uLL);
if ( !(unsigned int)read(v3, v4, 0x28uLL) )
return 0xFFFFFFFFLL;
puts((const char *)v4);
v7 = "master";
v8 = 7LL;
v9 = (const char *)v4;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
v11 = (char *)get_repo_troll_dir(v7, v9);
v12 = strlen(v11);
v13 = (char *)realloc(v11, v12 + 7);
strcat(v13, "master");
v14 = open(v13, 0);
read(v14, v4, 0x28uLL);
}
func0((__int64)v4);
free(v4);
close(v3);
return 0LL;
}

original_code:
int cmd_log(int argc, const char *argv[]) {
    die_if_not_troll_repo();
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 5);
    strcat(path, "HEAD");
    int fd = open(path, 00);
    char *hash = (char *) malloc(41 * sizeof(char));
    int test;
    test = read(fd, hash, 40);
    if(!test)
      return -1;
    printf("%s\n", hash);
    if (strcmp(hash, "master") == 0) {
        char *path2 = get_repo_troll_dir();
        path2 = (char *) realloc(path2, strlen(path2) + 7);
        strcat(path2, "master");
        int fd = open(path2, 00);
        read(fd, hash, 40);
    }
    print_log(hash);
    free(hash);
    close(fd);
    return 0;
}

canonical_original_code:
int cmd_log(int argc, char *argv[]) {
    die_if_not_troll_repo();
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 5);
    strcat(path, "HEAD");
    int fd = open(path, 00);
    char *hash = (char *) malloc(41 * sizeof(char));
    int test;
    test = read(fd, hash, 40);
    if(!test)
      return -1;
    printf("%s\n", hash);
    if (strcmp(hash, "master") == 0) {
        char *path2 = get_repo_troll_dir();
        path2 = (char *) realloc(path2, strlen(path2) + 7);
        strcat(path2, "master");
        int fd = open(path2, 00);
        read(fd, hash, 40);
    }
    print_log(hash);
    free(hash);
    close(fd);
    return 0;
}

variable_types:
path
char *

variable_types: test int


decompiled_code:
char *__fastcall sha1tohex(unsigned __int8 *a1)
{
char *v2; // r13
char *v3; // rbx
__int64 v4; // rdx
char *v5; // rdi

v2 = (char *)malloc(0x29uLL);
v3 = v2;
do
{
v4 = *a1;
v5 = v3;
v3 += 2;
++a1;
sprintf(v5, "%02x", v4);
}
while ( v2 + 40 != v3 );
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 *a1)
{
char *v2; // r13
char *v3; // rbx
__int64 v4; // rdx
char *v5; // rdi

v2 = (char *)malloc(0x29uLL);
v3 = v2;
do
{
v4 = *a1;
v5 = v3;
v3 += 2;
++a1;
sprintf(v5, "%02x", v4);
}
while ( v2 + 40 != v3 );
return v2;
}

original_code:
char *sha1tohex(unsigned char *hash) {
    char *hex = (char *) malloc(41 * sizeof(char));
    int i;
    for (i = 0; i < 20; i++) {
        sprintf(hex + i * 2, "%02x", hash[i]);
    }
    return hex;
}

variable_types:
hash
unsigned char *

variable_types:
hex
char *

variable_types: i int


decompiled_code:
char *__fastcall hash_object(__int64 a1, int a2)
{
unsigned __int8 *v2; // rax

v2 = (unsigned __int8 *)SHA1(a1, a2, 0LL);
return sha1tohex(v2);
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, int a2)
{
unsigned __int8 *v2; // rax

v2 = (unsigned __int8 *)SHA1(a1, a2, 0LL);
return func0(v2);
}

original_code:
char *hash_object(char *data, int len) {
    unsigned char *hash = SHA1((unsigned char *) data, len, ((void *)0));
    char *hex = sha1tohex(hash);
    return hex;
}

variable_types:
data
char *

variable_types: len int


decompiled_code:
__int64 cmd_face()
{
puts(&s);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
puts(&s);
return 0LL;
}

original_code: int cmd_face(int b, const char *e[]){printf("░░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░\n░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░\n░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░\n░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░\n░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░\n█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█\n█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█\n░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░\n░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░\n░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░\n░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░\n░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░\n░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░\n░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░\n░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░\nUMAD?\n");return 0;}

canonical_original_code: int cmd_face(int b, char *e[]){printf("░░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░\n░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░\n░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░\n░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░\n░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░\n█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█\n█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█\n░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░\n░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░\n░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░\n░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░\n░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░\n░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░\n░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░\n░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░\nUMAD?\n");return 0;}

variable_types: b int

variable_types:
e
char *[]


decompiled_code:
__int64 __fastcall cmd_commit(int a1, __int64 a2)
{
_BYTE *v2; // rax
__int64 result; // rax

die_if_not_troll_repo();
if ( a1 > 2 && (v2 = *(_BYTE **)(a2 + 8), *v2 == 45) && v2[1] == 109 && !v2[2] )
{
commit(*(_QWORD *)(a2 + 16));
result = 0LL;
}
else
{
puts("Please run 'troll commit -m \"your commit message here\".");
result = 0LL;
}
return result;
}

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

die_if_not_troll_repo();
if ( a1 > 2 && (v2 = *(_BYTE **)(a2 + 8), *v2 == 45) && v2[1] == 109 && !v2[2] )
{
commit(*(_QWORD *)(a2 + 16));
result = 0LL;
}
else
{
puts("Please run 'troll commit -m \"your commit message here\".");
result = 0LL;
}
return result;
}

original_code:
int cmd_commit(int argc, const char *argv[]) {
    die_if_not_troll_repo();
    if (argc < 3 || strcmp(argv[1], "-m") != 0) {
        printf("Please run 'troll commit -m \"your commit message here\".\n");
        return 0;
    }
    commit(argv[2]);
    return 0;
}

canonical_original_code:
int cmd_commit(int argc, char *argv[]) {
    die_if_not_troll_repo();
    if (argc < 3 || strcmp(argv[1], "-m") != 0) {
        printf("Please run 'troll commit -m \"your commit message here\".\n");
        return 0;
    }
    commit(argv[2]);
    return 0;
}


decompiled_code:
__int64 __fastcall write_blob(const char *a1)
{
int v1; // ebp
__off_t v2; // r13
char *v3; // r12
int v4; // ebx
unsigned int v5; // ebx
const char *v6; // r13
char *v7; // rbp
size_t v8; // rax
char *v9; // rbp
int v10; // eax
struct stat v12; // [rsp+0h] [rbp-B8h] BYREF

v1 = open(a1, 0);
fstat(v1, &v12);
v2 = v12.st_size;
v3 = (char *)malloc(v12.st_size + 15);
sprintf(v3, "blob %lu", v2);
v4 = strlen(v3) + 1;
read(v1, &v3[v4], v12.st_size);
v5 = LODWORD(v12.st_size) + v4;
v6 = (const char *)hash_object(v3, v5);
v7 = (char *)get_repo_troll_dir();
v8 = strlen(v7);
v9 = (char *)realloc(v7, v8 + 49);
strcat(v9, "objects/");
strncat(v9, v6, 0x28uLL);
v10 = open(v9, 577, 420LL);
write(v10, v3, (int)v5);
return add_to_index(v6, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // ebp
__off_t v2; // r13
char *v3; // r12
int v4; // ebx
unsigned int v5; // ebx
const char *v6; // r13
char *v7; // rbp
size_t v8; // rax
char *v9; // rbp
int v10; // eax
struct stat v12; // [rsp+0h] [rbp-B8h] BYREF

v1 = open(a1, 0);
fstat(v1, &v12);
v2 = v12.st_size;
v3 = (char *)malloc(v12.st_size + 15);
sprintf(v3, "blob %lu", v2);
v4 = strlen(v3) + 1;
read(v1, &v3[v4], v12.st_size);
v5 = LODWORD(v12.st_size) + v4;
v6 = (const char *)hash_object(v3, v5);
v7 = (char *)get_repo_troll_dir();
v8 = strlen(v7);
v9 = (char *)realloc(v7, v8 + 49);
strcat(v9, "objects/");
strncat(v9, v6, 0x28uLL);
v10 = open(v9, 577, 420LL);
write(v10, v3, (int)v5);
return add_to_index(v6, a1);
}

original_code:
void write_blob(char *filename) {
    int fd;
    fd = open(filename, 00);
    struct stat buf;
    fstat(fd, &buf);
    char *data = (char *) malloc((size_t) buf.st_size + 15);
    sprintf(data, "blob %lu", (unsigned long) buf.st_size);
    int left_part_len = strlen(data) + 1;
    read(fd, data + left_part_len, buf.st_size);
    int full_len = left_part_len + buf.st_size;
    char *hash = hash_object(data, full_len);
    char *path = get_repo_troll_dir();
    path = (char *) realloc(path, strlen(path) + 49);
    strcat(path, "objects/");
    strncat(path, hash, 40);
    int objectfd = open(path, 0100 | 01000 | 01, 0644);
    write(objectfd, data, full_len);
    add_to_index(hash, filename);
}

variable_types:
filename
char *

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: objectfd int


decompiled_code:
__int64 __fastcall cmd_init(int a1, __int64 a2)
{
__int64 v3; // rdi
char *v4; // rbp

v3 = 0LL;
if ( a1 > 1 )
v3 = *(_QWORD *)(a2 + 8);
v4 = (char *)init_troll_dir(v3);
printf("Initialized empty troll repository in %s\n", v4);
free(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
__int64 v3; // rdi
char *v4; // rbp

v3 = 0LL;
if ( a1 > 1 )
v3 = *(_QWORD *)(a2 + 8);
v4 = (char *)init_troll_dir(v3);
printf("Initialized empty troll repository in %s\n", v4);
free(v4);
return 0LL;
}

original_code:
int cmd_init(int argc, const char *argv[]) {
    char *dir = init_troll_dir(argc > 1 ? argv[1] : ((void *)0));
    printf("Initialized empty troll repository in %s\n", dir);
    free(dir);
    return 0;
}

canonical_original_code:
int cmd_init(int argc, char *argv[]) {
    char *dir = init_troll_dir(argc > 1 ? argv[1] : ((void *)0));
    printf("Initialized empty troll repository in %s\n", dir);
    free(dir);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
dir
char *


queueListen

decompiled_code:
void *__fastcall queueListen(void *a1)
{
const char *v1; // rsi
int *v2; // rax
char *v3; // rax
int v5; // [rsp+0h] [rbp-808h] BYREF
int v6; // [rsp+8h] [rbp-800h] BYREF
char v7[46]; // [rsp+Ch] [rbp-7FCh] BYREF
char v8[1998]; // [rsp+3Ah] [rbp-7CEh] BYREF

LABEL_1:
while ( mq_receive((unsigned int)ClientQueue, &v5, 2048LL, 0LL) >= 0 )
{
switch ( v5 )
{
case 3:
safePrintf("info: %s\n", (const char *)&v6);
break;
case 4:
safePrintf("server message: %s\n", (const char *)&v6);
break;
case 5:
v1 = "success";
if ( !v6 )
v1 = "fail";
safePrintf("confirm message (%s): %s\n", v1, v7);
break;
case 8:
safePrintf("private msg from %s: %s\n", (const char *)&v6, v8);
break;
case 9:
safePrintf("channel msg from %s: %s\n", (const char *)&v6, v8);
break;
case 10:
safePrintf("on-line users:\n%s\n", (const char *)&v6);
break;
case 11:
safePrintf("all channels:\n%s\n", (const char *)&v6);
break;
default:
goto LABEL_1;
}
}
v2 = _errno_location();
v3 = strerror(*v2);
safePrintf("error receving from client queue: %s\n", v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
const char *v1; // rsi
int *v2; // rax
char *v3; // rax
int v5; // [rsp+0h] [rbp-808h] BYREF
int v6; // [rsp+8h] [rbp-800h] BYREF
char v7[46]; // [rsp+Ch] [rbp-7FCh] BYREF
char v8[1998]; // [rsp+3Ah] [rbp-7CEh] BYREF

LABEL_1:
while ( mq_receive((unsigned int)ClientQueue, &v5, 2048LL, 0LL) >= 0 )
{
switch ( v5 )
{
case 3:
safePrintf("info: %s\n", (const char *)&v6);
break;
case 4:
safePrintf("server message: %s\n", (const char *)&v6);
break;
case 5:
v1 = "success";
if ( !v6 )
v1 = "fail";
safePrintf("confirm message (%s): %s\n", v1, v7);
break;
case 8:
safePrintf("private msg from %s: %s\n", (const char *)&v6, v8);
break;
case 9:
safePrintf("channel msg from %s: %s\n", (const char *)&v6, v8);
break;
case 10:
safePrintf("on-line users:\n%s\n", (const char *)&v6);
break;
case 11:
safePrintf("all channels:\n%s\n", (const char *)&v6);
break;
default:
goto LABEL_1;
}
}
v2 = _errno_location();
v3 = strerror(*v2);
safePrintf("error receving from client queue: %s\n", v3);
return 0LL;
}

original_code:
static void *queueListen(void *arg)
{
    while (1)
    {
        Message message;
        if (mq_receive(ClientQueue, (char *)&message, 2048, ((void *)0)) < 0)
        {
            safePrintf("error receving from client queue: %s\n", strerror((*__errno_location ())));
            return ((void *)0);
        }
        switch (message.type)
        {
            case CONFIRM_MSG:
                safePrintf("confirm message (%s): %s\n",
                           message.data.confmsg.confirmed ? "success" : "fail",
                           message.data.confmsg.text);
                break;
            case SRV_MSG:
                safePrintf("server message: %s\n", message.data.srvmsg.text);
                break;
            case SHOW_USERS:
                safePrintf("on-line users:\n%s\n", message.data.srvmsg.text);
                break;
            case SHOW_CHANNELS:
                safePrintf("all channels:\n%s\n", message.data.srvmsg.text);
                break;
            case INFO_MSG:
                safePrintf("info: %s\n", message.data.srvmsg.text);
                break;
            case SEND_CHANNEL_MSG:
                safePrintf("channel msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
                break;
            case SEND_USER_MSG:
                safePrintf("private msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
        }
    }
}

canonical_original_code:
static void *queueListen(void *arg)
{
    while (1)
    {
        struct Message message;
        if (mq_receive(ClientQueue, (char *)&message, 2048, ((void *)0)) < 0)
        {
            safePrintf("error receving from client queue: %s\n", strerror((*__errno_location ())));
            return ((void *)0);
        }
        switch (message.type)
        {
            case CONFIRM_MSG:
                safePrintf("confirm message (%s): %s\n",
                           message.data.confmsg.confirmed ? "success" : "fail",
                           message.data.confmsg.text);
                break;
            case SRV_MSG:
                safePrintf("server message: %s\n", message.data.srvmsg.text);
                break;
            case SHOW_USERS:
                safePrintf("on-line users:\n%s\n", message.data.srvmsg.text);
                break;
            case SHOW_CHANNELS:
                safePrintf("all channels:\n%s\n", message.data.srvmsg.text);
                break;
            case INFO_MSG:
                safePrintf("info: %s\n", message.data.srvmsg.text);
                break;
            case SEND_CHANNEL_MSG:
                safePrintf("channel msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
                break;
            case SEND_USER_MSG:
                safePrintf("private msg from %s: %s\n", message.data.textmsg.name,
                           message.data.textmsg.text);
        }
    }
}

variable_types:
arg
void *

variable_types: struct Message { enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 } type; union { struct LoginMessage { int cid; char name[50]; char queueName[255]; } loginmsg; struct TextMessage { int cid; char name[50]; char text[-1]; } textmsg; struct DisconnectMessage { int cid; } discmsg; struct ServerMessage { int cid; char text[-1]; } srvmsg; struct ConfirmationMessage { int cid; int confirmed; char text[-1]; } confmsg; struct ChannelMessage { int cid; char channel_name[50]; } chmsg; } data; }

return_type: void *

user_defined_types: struct Message { enum MessageType type; union { struct LoginMessage loginmsg; struct TextMessage textmsg; struct DisconnectMessage discmsg; struct ServerMessage srvmsg; struct ConfirmationMessage confmsg; struct ChannelMessage chmsg; } data; }


showUsers

decompiled_code:
void __fastcall showUsers(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 10;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send show users");
else
safePrintf("successfully sent show users request\n");
}

canonical_decompiled_code:
void __fastcall func1(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 10;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send show users");
else
safePrintf("successfully sent show users request\n");
}

original_code:
static void showUsers(Message *msgbuf)
{
    msgbuf->type = SHOW_USERS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show users");
        return;
    }
    safePrintf("successfully sent show users request\n");
}

canonical_original_code:
static void showUsers(struct Message *msgbuf)
{
    msgbuf->type = SHOW_USERS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show users");
        return;
    }
    safePrintf("successfully sent show users request\n");
}

variable_types: struct Message { enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 } type; union { struct LoginMessage { int cid; char name[50]; char queueName[255]; } loginmsg; struct TextMessage { int cid; char name[50]; char text[-1]; } textmsg; struct DisconnectMessage { int cid; } discmsg; struct ServerMessage { int cid; char text[-1]; } srvmsg; struct ConfirmationMessage { int cid; int confirmed; char text[-1]; } confmsg; struct ChannelMessage { int cid; char channel_name[50]; } chmsg; } data; } *


showChannels

decompiled_code:
void __fastcall showChannels(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 11;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send show channels");
else
safePrintf("successfully sent show channels request\n");
}

canonical_decompiled_code:
void __fastcall func2(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 11;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send show channels");
else
safePrintf("successfully sent show channels request\n");
}

original_code:
static void showChannels(Message *msgbuf)
{
    msgbuf->type = SHOW_CHANNELS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show channels");
        return;
    }
    safePrintf("successfully sent show channels request\n");
}

canonical_original_code:
static void showChannels(struct Message *msgbuf)
{
    msgbuf->type = SHOW_CHANNELS;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send show channels");
        return;
    }
    safePrintf("successfully sent show channels request\n");
}

user_defined_types: enum MessageType { LOGIN_MSG=1, DISCONNECT_MSG=2, INFO_MSG=3, SRV_MSG=4, CONFIRM_MSG=5, JOIN_CHANNEL_MSG=6, LEAVE_CHANNEL_MSG=7, SEND_USER_MSG=8, SEND_CHANNEL_MSG=9, SHOW_USERS=10, SHOW_CHANNELS=11 }

user_defined_types: struct LoginMessage { int cid; char name[50]; char queueName[255]; }

user_defined_types: struct TextMessage { int cid; char name[50]; char text[-1]; }

user_defined_types: struct ServerMessage { int cid; char text[-1]; }

user_defined_types: struct ConfirmationMessage { int cid; int confirmed; char text[-1]; }

user_defined_types: struct ChannelMessage { int cid; char channel_name[50]; }


requestInfo

decompiled_code:
void __fastcall requestInfo(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 3;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send info request");
else
safePrintf("successfully sent info request\n");
}

canonical_decompiled_code:
void __fastcall func3(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 3;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send info request");
else
safePrintf("successfully sent info request\n");
}

original_code:
static void requestInfo(Message *msgbuf)
{
    msgbuf->type = INFO_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send info request");
        return;
    }
    safePrintf("successfully sent info request\n");
}

canonical_original_code:
static void requestInfo(struct Message *msgbuf)
{
    msgbuf->type = INFO_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send info request");
        return;
    }
    safePrintf("successfully sent info request\n");
}


leaveChannel

decompiled_code:
void __fastcall leaveChannel(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 7;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send leave channel message");
else
puts("leave channel message sent successfully");
}

canonical_decompiled_code:
void __fastcall func4(_DWORD *a1)
{
__pid_t v2; // eax
__int64 v3; // rdi

*a1 = 7;
v2 = getpid();
v3 = (unsigned int)GlobalQueue;
a1[1] = v2;
if ( (int)mq_send(v3, a1, 2048LL, 0LL) < 0 )
perror("send leave channel message");
else
puts("leave channel message sent successfully");
}

original_code:
static void leaveChannel(Message *msgbuf)
{
    msgbuf->type = LEAVE_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
        perror("send leave channel message");
    else
        printf("leave channel message sent successfully\n");
}

canonical_original_code:
static void leaveChannel(struct Message *msgbuf)
{
    msgbuf->type = LEAVE_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
        perror("send leave channel message");
    else
        printf("leave channel message sent successfully\n");
}


showHelp

decompiled_code:
int showHelp()
{
puts("quit, exit");
puts("chmsg <msg> - send msg to channel");
puts("privmsg <user> <msg> - send private msg to <user>");
puts("join <channel>");
puts("leave - leave current channel");
puts("users - show users currently logged in");
puts("channels - show all channels");
puts("info - show additional commands which server can handle");
return puts("help - shows this help");
}

canonical_decompiled_code:
int func5()
{
puts("quit, exit");
puts("chmsg <msg> - send msg to channel");
puts("privmsg <user> <msg> - send private msg to <user>");
puts("join <channel>");
puts("leave - leave current channel");
puts("users - show users currently logged in");
puts("channels - show all channels");
puts("info - show additional commands which server can handle");
return puts("help - shows this help");
}

original_code:
static void showHelp()
{
    printf("quit, exit\n");
    printf("chmsg <msg> - send msg to channel\n");
    printf("privmsg <user> <msg> - send private msg to <user>\n");
    printf("join <channel>\n");
    printf("leave - leave current channel\n");
    printf("users - show users currently logged in\n");
    printf("channels - show all channels\n");
    printf("info - show additional commands which server can handle\n");
    printf("help - shows this help\n");
}


sendChannelMessage

decompiled_code:
void __fastcall sendChannelMessage(__int64 a1, char *a2)
{
char *v3; // rax
const char *v4; // rdi
const char *v5; // r12
__int64 v6; // r13
size_t v7; // rax
unsigned int v8; // eax

*(_DWORD *)a1 = 9;
*(_DWORD *)(a1 + 4) = getpid();
v3 = strtok(a2, delim);
v4 = "no message to send to channel\n";
if ( !v3 )
goto LABEL_6;
v5 = v3;
v6 = a1 + 58;
v7 = strlen(v3);
if ( v7 <= 0x7C5 )
{
v8 = v7 + 1;
if ( v8 >= 8 )
{
*(_QWORD *)(a1 + 58) = *(_QWORD *)v5;
*(_QWORD *)(v6 + v8 - 8) = *(_QWORD *)&v5[v8 - 8];
qmemcpy(
(void *)((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL),
&v5[-(v6 - ((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL))],
8LL * (((_DWORD)v6 - (((_DWORD)a1 + 66) & 0xFFFFFFF8) + v8) >> 3));
}
else if ( (v8 & 4) != 0 )
{
*(_DWORD *)(a1 + 58) = *(_DWORD *)v5;
*(_DWORD *)(v6 + v8 - 4) = *(_DWORD *)&v5[v8 - 4];
}
else if ( v8 )
{
*(_BYTE *)(a1 + 58) = *v5;
if ( (v8 & 2) != 0 )
*(_WORD *)(v6 + v8 - 2) = *(_WORD *)&v5[v8 - 2];
}
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v5, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
v4 = "channel msg sent successfully\n";
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send channel message");
else
LABEL_6:
safePrintf(v4);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, char *a2)
{
char *v3; // rax
const char *v4; // rdi
const char *v5; // r12
__int64 v6; // r13
size_t v7; // rax
unsigned int v8; // eax

*(_DWORD *)a1 = 9;
*(_DWORD *)(a1 + 4) = getpid();
v3 = strtok(a2, delim);
v4 = "no message to send to channel\n";
if ( !v3 )
goto LABEL_6;
v5 = v3;
v6 = a1 + 58;
v7 = strlen(v3);
if ( v7 <= 0x7C5 )
{
v8 = v7 + 1;
if ( v8 >= 8 )
{
*(_QWORD *)(a1 + 58) = *(_QWORD *)v5;
*(_QWORD *)(v6 + v8 - 8) = *(_QWORD *)&v5[v8 - 8];
qmemcpy(
(void *)((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL),
&v5[-(v6 - ((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL))],
8LL * (((_DWORD)v6 - (((_DWORD)a1 + 66) & 0xFFFFFFF8) + v8) >> 3));
}
else if ( (v8 & 4) != 0 )
{
*(_DWORD *)(a1 + 58) = *(_DWORD *)v5;
*(_DWORD *)(v6 + v8 - 4) = *(_DWORD *)&v5[v8 - 4];
}
else if ( v8 )
{
*(_BYTE *)(a1 + 58) = *v5;
if ( (v8 & 2) != 0 )
*(_WORD *)(v6 + v8 - 2) = *(_WORD *)&v5[v8 - 2];
}
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v5, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
v4 = "channel msg sent successfully\n";
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send channel message");
else
LABEL_6:
safePrintf(v4);
}

original_code:
static void sendChannelMessage(Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_CHANNEL_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *text = strtok(msg, "\0");
    if (! text)
    {
        safePrintf("no message to send to channel\n");
        return;
    }
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send channel message");
        return;
    }
    safePrintf("channel msg sent successfully\n");
}

canonical_original_code:
static void sendChannelMessage(struct Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_CHANNEL_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *text = strtok(msg, "\0");
    if (! text)
    {
        safePrintf("no message to send to channel\n");
        return;
    }
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send channel message");
        return;
    }
    safePrintf("channel msg sent successfully\n");
}

variable_types:
msg
char *

variable_types:
text
char *


sendPrivateMessage

decompiled_code:
void __fastcall sendPrivateMessage(__int64 a1, char *a2)
{
char *v3; // rax
const char *v4; // rdi
const char *v5; // r13
char *v6; // rax
const char *v7; // r12
const char *v8; // rsi
__int64 v9; // r13
size_t v10; // rax
unsigned int v11; // eax

*(_DWORD *)a1 = 8;
*(_DWORD *)(a1 + 4) = getpid();
v3 = strtok(a2, " \t");
v4 = "no user name\n";
if ( !v3 )
goto LABEL_6;
v5 = v3;
v6 = strtok(0LL, delim);
v4 = "no text to user\n";
v7 = v6;
if ( !v6 )
goto LABEL_6;
safePrintf("args to sendusr: \"%s\" \"%s\"\n", v5, v6);
v8 = v5;
v9 = a1 + 58;
strcpy((char *)(a1 + 8), v8);
v10 = strlen(v7);
if ( v10 <= 0x7C5 )
{
v11 = v10 + 1;
if ( v11 >= 8 )
{
*(_QWORD *)(a1 + 58) = *(_QWORD *)v7;
*(_QWORD *)(v9 + v11 - 8) = *(_QWORD *)&v7[v11 - 8];
qmemcpy(
(void *)((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL),
&v7[-(v9 - ((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL))],
8LL * ((v11 + (_DWORD)v9 - (((_DWORD)a1 + 66) & 0xFFFFFFF8)) >> 3));
}
else if ( (v11 & 4) != 0 )
{
*(_DWORD *)(a1 + 58) = *(_DWORD *)v7;
*(_DWORD *)(v9 + v11 - 4) = *(_DWORD *)&v7[v11 - 4];
}
else if ( v11 )
{
*(_BYTE *)(a1 + 58) = *v7;
if ( (v11 & 2) != 0 )
*(_WORD *)(v9 + v11 - 2) = *(_WORD *)&v7[v11 - 2];
}
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v7, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
v4 = "private msg sent successfully\n";
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send private message");
else
LABEL_6:
safePrintf(v4);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char *a2)
{
char *v3; // rax
const char *v4; // rdi
const char *v5; // r13
char *v6; // rax
const char *v7; // r12
const char *v8; // rsi
__int64 v9; // r13
size_t v10; // rax
unsigned int v11; // eax

*(_DWORD *)a1 = 8;
*(_DWORD *)(a1 + 4) = getpid();
v3 = strtok(a2, " \t");
v4 = "no user name\n";
if ( !v3 )
goto LABEL_6;
v5 = v3;
v6 = strtok(0LL, delim);
v4 = "no text to user\n";
v7 = v6;
if ( !v6 )
goto LABEL_6;
safePrintf("args to sendusr: \"%s\" \"%s\"\n", v5, v6);
v8 = v5;
v9 = a1 + 58;
strcpy((char *)(a1 + 8), v8);
v10 = strlen(v7);
if ( v10 <= 0x7C5 )
{
v11 = v10 + 1;
if ( v11 >= 8 )
{
*(_QWORD *)(a1 + 58) = *(_QWORD *)v7;
*(_QWORD *)(v9 + v11 - 8) = *(_QWORD *)&v7[v11 - 8];
qmemcpy(
(void *)((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL),
&v7[-(v9 - ((a1 + 66) & 0xFFFFFFFFFFFFFFF8LL))],
8LL * ((v11 + (_DWORD)v9 - (((_DWORD)a1 + 66) & 0xFFFFFFF8)) >> 3));
}
else if ( (v11 & 4) != 0 )
{
*(_DWORD *)(a1 + 58) = *(_DWORD *)v7;
*(_DWORD *)(v9 + v11 - 4) = *(_DWORD *)&v7[v11 - 4];
}
else if ( v11 )
{
*(_BYTE *)(a1 + 58) = *v7;
if ( (v11 & 2) != 0 )
*(_WORD *)(v9 + v11 - 2) = *(_WORD *)&v7[v11 - 2];
}
}
else
{
safePrintf("message is too long, cutting...\n");
strncpy((char *)(a1 + 58), v7, 0x7C5uLL);
*(_BYTE *)(a1 + 2047) = 0;
}
v4 = "private msg sent successfully\n";
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send private message");
else
LABEL_6:
safePrintf(v4);
}

original_code:
static void sendPrivateMessage(Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_USER_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *username = strtok(msg, " 	");
    if (! username)
    {
        safePrintf("no user name\n");
        return;
    }
    char *text = strtok(((void *)0), "\0");
    if (! text)
    {
        safePrintf("no text to user\n");
        return;
    }
    safePrintf("args to sendusr: \"%s\" \"%s\"\n", username, text);
    strcpy(msgbuf->data.textmsg.name, username);
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send private message");
        return;
    }
    safePrintf("private msg sent successfully\n");
}

canonical_original_code:
static void sendPrivateMessage(struct Message *msgbuf, char *msg)
{
    msgbuf->type = SEND_USER_MSG;
    msgbuf->data.textmsg.cid = getpid();
    char *username = strtok(msg, " 	");
    if (! username)
    {
        safePrintf("no user name\n");
        return;
    }
    char *text = strtok(((void *)0), "\0");
    if (! text)
    {
        safePrintf("no text to user\n");
        return;
    }
    safePrintf("args to sendusr: \"%s\" \"%s\"\n", username, text);
    strcpy(msgbuf->data.textmsg.name, username);
    if (strlen(text) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("message is too long, cutting...\n");
        strncpy(msgbuf->data.textmsg.text, text, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.textmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.textmsg.text, text);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send private message");
        return;
    }
    safePrintf("private msg sent successfully\n");
}

variable_types:
username
char *


joinChannel

decompiled_code:
void __fastcall joinChannel(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // r12
__int64 v4; // r13
size_t v5; // rax
unsigned int v6; // eax
unsigned __int64 v7; // rsi
__int64 v8; // r13
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // edx
__int64 v12; // rcx

*(_DWORD *)a1 = 6;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, " \t");
if ( v2 )
{
v3 = v2;
v4 = a1 + 8;
v5 = strlen(v2);
if ( v5 <= 0x31 )
{
v6 = v5 + 1;
if ( v6 >= 8 )
{
v7 = (a1 + 16) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)(a1 + 8) = *(_QWORD *)v3;
*(_QWORD *)(a1 + v6) = *(_QWORD *)&v3[v6 - 8];
v8 = v4 - v7;
v9 = (v8 + v6) & 0xFFFFFFF8;
if ( v9 >= 8 )
{
v10 = v9 & 0xFFFFFFF8;
v11 = 0;
do
{
v12 = v11;
v11 += 8;
*(_QWORD *)(v7 + v12) = *(_QWORD *)&v3[v12 - v8];
}
while ( v11 < v10 );
}
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)(a1 + 8) = *(_DWORD *)v3;
*(_DWORD *)(v4 + v6 - 4) = *(_DWORD *)&v3[v6 - 4];
}
else if ( v6 )
{
*(_BYTE *)(a1 + 8) = *v3;
if ( (v6 & 2) != 0 )
*(_WORD *)(v4 + v6 - 2) = *(_WORD *)&v3[v6 - 2];
}
}
else
{
safePrintf("channel name is too long, cutting...\n");
strncpy((char *)(a1 + 8), v3, 0x31uLL);
*(_BYTE *)(a1 + 57) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("join channel");
else
safePrintf("successfully joined channel %s\n", v3);
}
else
{
safePrintf("no channel name\n");
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, char *a2)
{
char *v2; // rax
const char *v3; // r12
__int64 v4; // r13
size_t v5; // rax
unsigned int v6; // eax
unsigned __int64 v7; // rsi
__int64 v8; // r13
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // edx
__int64 v12; // rcx

*(_DWORD *)a1 = 6;
*(_DWORD *)(a1 + 4) = getpid();
v2 = strtok(a2, " \t");
if ( v2 )
{
v3 = v2;
v4 = a1 + 8;
v5 = strlen(v2);
if ( v5 <= 0x31 )
{
v6 = v5 + 1;
if ( v6 >= 8 )
{
v7 = (a1 + 16) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)(a1 + 8) = *(_QWORD *)v3;
*(_QWORD *)(a1 + v6) = *(_QWORD *)&v3[v6 - 8];
v8 = v4 - v7;
v9 = (v8 + v6) & 0xFFFFFFF8;
if ( v9 >= 8 )
{
v10 = v9 & 0xFFFFFFF8;
v11 = 0;
do
{
v12 = v11;
v11 += 8;
*(_QWORD *)(v7 + v12) = *(_QWORD *)&v3[v12 - v8];
}
while ( v11 < v10 );
}
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)(a1 + 8) = *(_DWORD *)v3;
*(_DWORD *)(v4 + v6 - 4) = *(_DWORD *)&v3[v6 - 4];
}
else if ( v6 )
{
*(_BYTE *)(a1 + 8) = *v3;
if ( (v6 & 2) != 0 )
*(_WORD *)(v4 + v6 - 2) = *(_WORD *)&v3[v6 - 2];
}
}
else
{
safePrintf("channel name is too long, cutting...\n");
strncpy((char *)(a1 + 8), v3, 0x31uLL);
*(_BYTE *)(a1 + 57) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("join channel");
else
safePrintf("successfully joined channel %s\n", v3);
}
else
{
safePrintf("no channel name\n");
}
}

original_code:
static void joinChannel(Message *msgbuf, char *msg)
{
    msgbuf->type = JOIN_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    char *channel = strtok(msg, " 	");
    if (! channel)
    {
        safePrintf("no channel name\n");
        return;
    }
    if (strlen(channel) >= 50)
    {
        safePrintf("channel name is too long, cutting...\n");
        strncpy(msgbuf->data.chmsg.channel_name, channel, 50 - 1);
        msgbuf->data.chmsg.channel_name[50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.chmsg.channel_name, channel);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("join channel");
        return;
    }
    safePrintf("successfully joined channel %s\n", channel);
}

canonical_original_code:
static void joinChannel(struct Message *msgbuf, char *msg)
{
    msgbuf->type = JOIN_CHANNEL_MSG;
    msgbuf->data.chmsg.cid = getpid();
    char *channel = strtok(msg, " 	");
    if (! channel)
    {
        safePrintf("no channel name\n");
        return;
    }
    if (strlen(channel) >= 50)
    {
        safePrintf("channel name is too long, cutting...\n");
        strncpy(msgbuf->data.chmsg.channel_name, channel, 50 - 1);
        msgbuf->data.chmsg.channel_name[50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.chmsg.channel_name, channel);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("join channel");
        return;
    }
    safePrintf("successfully joined channel %s\n", channel);
}

variable_types:
channel
char *


serverMessage

decompiled_code:
void __fastcall serverMessage(__int64 a1, const char *a2)
{
char *v2; // r13
size_t v3; // rax
unsigned int v4; // eax

*(_DWORD *)a1 = 4;
v2 = (char *)(a1 + 8);
*(_DWORD *)(a1 + 4) = getpid();
v3 = strlen(a2);
if ( v3 <= 0x7C5 )
{
v4 = v3 + 1;
if ( v4 >= 8 )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)a2;
*(_QWORD *)(a1 + v4) = *(_QWORD *)&a2[v4 - 8];
qmemcpy(
(void *)((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a2 - &v2[-((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((_DWORD)v2 - (((_DWORD)a1 + 16) & 0xFFFFFFF8) + v4) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)(a1 + 8) = *(_DWORD *)a2;
*(_DWORD *)&v2[v4 - 4] = *(_DWORD *)&a2[v4 - 4];
}
else if ( v4 )
{
*(_BYTE *)(a1 + 8) = *a2;
if ( (v4 & 2) != 0 )
*(_WORD *)&v2[v4 - 2] = *(_WORD *)&a2[v4 - 2];
}
}
else
{
safePrintf("server command is too long, cutting...\n");
strncpy(v2, a2, 0x7C5uLL);
*(_BYTE *)(a1 + 1997) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send server command");
else
safePrintf("successfully sent server command\n");
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, const char *a2)
{
char *v2; // r13
size_t v3; // rax
unsigned int v4; // eax

*(_DWORD *)a1 = 4;
v2 = (char *)(a1 + 8);
*(_DWORD *)(a1 + 4) = getpid();
v3 = strlen(a2);
if ( v3 <= 0x7C5 )
{
v4 = v3 + 1;
if ( v4 >= 8 )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)a2;
*(_QWORD *)(a1 + v4) = *(_QWORD *)&a2[v4 - 8];
qmemcpy(
(void *)((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a2 - &v2[-((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((_DWORD)v2 - (((_DWORD)a1 + 16) & 0xFFFFFFF8) + v4) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)(a1 + 8) = *(_DWORD *)a2;
*(_DWORD *)&v2[v4 - 4] = *(_DWORD *)&a2[v4 - 4];
}
else if ( v4 )
{
*(_BYTE *)(a1 + 8) = *a2;
if ( (v4 & 2) != 0 )
*(_WORD *)&v2[v4 - 2] = *(_WORD *)&a2[v4 - 2];
}
}
else
{
safePrintf("server command is too long, cutting...\n");
strncpy(v2, a2, 0x7C5uLL);
*(_BYTE *)(a1 + 1997) = 0;
}
if ( (int)mq_send((unsigned int)GlobalQueue, a1, 2048LL, 0LL) < 0 )
perror("send server command");
else
safePrintf("successfully sent server command\n");
}

original_code:
static void serverMessage(Message *msgbuf, char *command)
{
    msgbuf->type = SRV_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (strlen(command) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("server command is too long, cutting...\n");
        strncpy(msgbuf->data.srvmsg.text, command, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.srvmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.srvmsg.text, command);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send server command");
        return;
    }
    safePrintf("successfully sent server command\n");
}

canonical_original_code:
static void serverMessage(struct Message *msgbuf, char *command)
{
    msgbuf->type = SRV_MSG;
    msgbuf->data.srvmsg.cid = getpid();
    if (strlen(command) >= 2048 - sizeof(int)*2 - sizeof(char)*50)
    {
        safePrintf("server command is too long, cutting...\n");
        strncpy(msgbuf->data.srvmsg.text, command, 2048 - sizeof(int)*2 - sizeof(char)*50 - 1);
        msgbuf->data.srvmsg.text[2048 - sizeof(int)*2 - sizeof(char)*50 - 1] = '\0';
    }
    else
        strcpy(msgbuf->data.srvmsg.text, command);
    if (mq_send(GlobalQueue, (char *)msgbuf, sizeof(Message), 0) < 0)
    {
        perror("send server command");
        return;
    }
    safePrintf("successfully sent server command\n");
}

variable_types:
command
char *


parseCommand

decompiled_code:
void __fastcall parseCommand(void *ptr, _DWORD *a2)
{
if ( !ptr )
LABEL_25:
quit(0);
if ( !strcmp((const char *)ptr, "quit") || !strcmp((const char *)ptr, "exit") )
{
free(ptr);
goto LABEL_25;
}
if ( *(_BYTE *)ptr )
{
if ( !memcmp(ptr, "chmsg ", 6uLL) )
{
sendChannelMessage((__int64)a2, (char *)ptr + 6);
LABEL_15:
free(ptr);
return;
}
if ( memcmp(ptr, "privmsg ", 8uLL) )
{
if ( !memcmp(ptr, "join ", 5uLL) )
{
joinChannel((__int64)a2, (char *)ptr + 5);
}
else if ( !strcmp((const char *)ptr, "leave") )
{
leaveChannel(a2);
}
else if ( !strcmp((const char *)ptr, "users") )
{
showUsers(a2);
}
else if ( !strcmp((const char *)ptr, "channels") )
{
showChannels(a2);
}
else if ( !strcmp((const char *)ptr, "info") )
{
requestInfo(a2);
}
else if ( !strcmp((const char *)ptr, "help") )
{
showHelp();
}
else
{
serverMessage((__int64)a2, (const char *)ptr);
}
goto LABEL_15;
}
sendPrivateMessage((__int64)a2, (char *)ptr + 8);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr, _DWORD *a2)
{
if ( !ptr )
LABEL_25:
func6(0);
if ( !strcmp((const char *)ptr, "quit") || !strcmp((const char *)ptr, "exit") )
{
free(ptr);
goto LABEL_25;
}
if ( *(_BYTE *)ptr )
{
if ( !memcmp(ptr, "chmsg ", 6uLL) )
{
func7((__int64)a2, (char *)ptr + 6);
LABEL_15:
free(ptr);
return;
}
if ( memcmp(ptr, "privmsg ", 8uLL) )
{
if ( !memcmp(ptr, "join ", 5uLL) )
{
func9((__int64)a2, (char *)ptr + 5);
}
else if ( !strcmp((const char *)ptr, "leave") )
{
func4(a2);
}
else if ( !strcmp((const char *)ptr, "users") )
{
func1(a2);
}
else if ( !strcmp((const char *)ptr, "channels") )
{
func2(a2);
}
else if ( !strcmp((const char *)ptr, "info") )
{
func3(a2);
}
else if ( !strcmp((const char *)ptr, "help") )
{
func5();
}
else
{
func10((__int64)a2, (const char *)ptr);
}
goto LABEL_15;
}
func8((__int64)a2, (char *)ptr + 8);
free(ptr);
}
}

original_code:
static void parseCommand(char *cmdstr, Message *msgbuf)
{
    if (! cmdstr ||
        strcmp(cmdstr, "quit") == 0 || strcmp(cmdstr, "exit") == 0)
    {
        if (cmdstr)
            free(cmdstr);
        quit(0);
    }
    if (*cmdstr == '\0')
        return;
    if (strncmp(cmdstr, "chmsg ", 6) == 0)
        sendChannelMessage(msgbuf, cmdstr + 6);
    else if (strncmp(cmdstr, "privmsg ", 8) == 0)
        sendPrivateMessage(msgbuf, cmdstr + 8);
    else if (strncmp(cmdstr, "join ", 5) == 0)
        joinChannel(msgbuf, cmdstr + 5);
    else if (strcmp(cmdstr, "leave") == 0)
        leaveChannel(msgbuf);
    else if (strcmp(cmdstr, "users") == 0)
        showUsers(msgbuf);
    else if (strcmp(cmdstr, "channels") == 0)
        showChannels(msgbuf);
    else if (strcmp(cmdstr, "info") == 0)
        requestInfo(msgbuf);
    else if (strcmp(cmdstr, "help") == 0)
        showHelp();
    else
        serverMessage(msgbuf, cmdstr);
    free(cmdstr);
}

canonical_original_code:
static void parseCommand(char *cmdstr, struct Message *msgbuf)
{
    if (! cmdstr ||
        strcmp(cmdstr, "quit") == 0 || strcmp(cmdstr, "exit") == 0)
    {
        if (cmdstr)
            free(cmdstr);
        quit(0);
    }
    if (*cmdstr == '\0')
        return;
    if (strncmp(cmdstr, "chmsg ", 6) == 0)
        sendChannelMessage(msgbuf, cmdstr + 6);
    else if (strncmp(cmdstr, "privmsg ", 8) == 0)
        sendPrivateMessage(msgbuf, cmdstr + 8);
    else if (strncmp(cmdstr, "join ", 5) == 0)
        joinChannel(msgbuf, cmdstr + 5);
    else if (strcmp(cmdstr, "leave") == 0)
        leaveChannel(msgbuf);
    else if (strcmp(cmdstr, "users") == 0)
        showUsers(msgbuf);
    else if (strcmp(cmdstr, "channels") == 0)
        showChannels(msgbuf);
    else if (strcmp(cmdstr, "info") == 0)
        requestInfo(msgbuf);
    else if (strcmp(cmdstr, "help") == 0)
        showHelp();
    else
        serverMessage(msgbuf, cmdstr);
    free(cmdstr);
}

variable_types:
cmdstr
char *


quit

decompiled_code:
void __fastcall __noreturn quit(int a1)
{
int v1[514]; // [rsp+0h] [rbp-808h] BYREF

puts("quiting...");
v1[0] = 2;
v1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, v1, 2048LL, 0LL) < 0 )
perror("send disconnect message");
if ( (int)mq_close((unsigned int)ClientQueue) < 0 )
perror("close client queue");
if ( (int)mq_unlink(ClientQueueName) < 0 )
perror("unlink client queue");
if ( (int)mq_close((unsigned int)GlobalQueue) < 0 )
perror("close global queue");
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(int a1)
{
int v1[514]; // [rsp+0h] [rbp-808h] BYREF

puts("quiting...");
v1[0] = 2;
v1[1] = getpid();
if ( (int)mq_send((unsigned int)GlobalQueue, v1, 2048LL, 0LL) < 0 )
perror("send disconnect message");
if ( (int)mq_close((unsigned int)ClientQueue) < 0 )
perror("close client queue");
if ( (int)mq_unlink(ClientQueueName) < 0 )
perror("unlink client queue");
if ( (int)mq_close((unsigned int)GlobalQueue) < 0 )
perror("close global queue");
exit(a1);
}

original_code:
static void quit(int signum)
{
    printf("quiting...\n");
    Message msg;
    msg.type = DISCONNECT_MSG;
    msg.data.discmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)&msg, sizeof(Message), 0) < 0)
        perror("send disconnect message");
    if (mq_close(ClientQueue) < 0)
        perror("close client queue");
    if (mq_unlink(ClientQueueName) < 0)
        perror("unlink client queue");
    if (mq_close(GlobalQueue) < 0)
        perror("close global queue");
    exit(signum);
}

canonical_original_code:
static void quit(int signum)
{
    printf("quiting...\n");
    struct Message msg;
    msg.type = DISCONNECT_MSG;
    msg.data.discmsg.cid = getpid();
    if (mq_send(GlobalQueue, (char *)&msg, sizeof(Message), 0) < 0)
        perror("send disconnect message");
    if (mq_close(ClientQueue) < 0)
        perror("close client queue");
    if (mq_unlink(ClientQueueName) < 0)
        perror("unlink client queue");
    if (mq_close(GlobalQueue) < 0)
        perror("close global queue");
    exit(signum);
}

variable_types: signum int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbx
char *v5; // rdi
__int64 i; // rcx
const char *v7; // rbp
const char *v8; // rax
char *v9; // rbp
void *v10; // rax
pthread_t newthread; // [rsp+8h] [rbp-860h] BYREF
char v12; // [rsp+10h] [rbp-858h] BYREF
__int64 v13; // [rsp+18h] [rbp-850h]
__int64 v14; // [rsp+20h] [rbp-848h]
int v15[2]; // [rsp+50h] [rbp-818h] BYREF
char dest[4]; // [rsp+58h] [rbp-810h] BYREF
char s[46]; // [rsp+5Ch] [rbp-80Ch] BYREF
char v18[2014]; // [rsp+8Ah] [rbp-7DEh] BYREF

GlobalQueue = mq_open("/irc-commmon-queue", 1LL, envp);
if ( GlobalQueue >= 0 )
{
v4 = (unsigned int)getpid();
sprintf(ClientQueueName, "/irc-client-%d", v4);
v5 = &v12;
for ( i = 16LL; i; --i )
{
*(_DWORD *)v5 = 0;
v5 += 4;
}
v13 = 10LL;
v14 = 2048LL;
ClientQueue = mq_open(ClientQueueName, 64LL, 438LL);
if ( ClientQueue >= 0 )
{
signal(2, (__sighandler_t)quit);
if ( argc > 1 )
{
v7 = argv[1];
initializePrompt();
strcpy(dest, v7);
while ( 1 )
{
v15[0] = 1;
v15[1] = v4;
strcpy(v18, ClientQueueName);
if ( (int)mq_send((unsigned int)GlobalQueue, v15, 2048LL, 0LL) < 0 )
break;
if ( mq_receive((unsigned int)ClientQueue, v15, 2048LL, 0LL) < 0 )
{
perror("receiving login confirmation");
}
else if ( v15[0] == 5 )
{
puts(s);
if ( *(_DWORD *)dest )
{
pthread_create(&newthread, 0LL, queueListen, 0LL);
while ( 1 )
{
v10 = (void *)readline("-> ");
parseCommand(v10, v15);
}
}
v8 = (const char *)readline("Choose other name: ");
v9 = (char *)v8;
if ( !v8 )
quit(0);
strcpy(dest, v8);
free(v9);
}
}
perror("send login msg");
quit(0);
}
printf("Usage: %s <login>\n", *argv);
quit(0);
}
printf("name - %s\n", ClientQueueName);
perror("open client queue");
quit(0);
}
perror("open global queue");
quit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbx
char *v5; // rdi
__int64 i; // rcx
const char *v7; // rbp
const char *v8; // rax
char *v9; // rbp
void *v10; // rax
pthread_t newthread; // [rsp+8h] [rbp-860h] BYREF
char v12; // [rsp+10h] [rbp-858h] BYREF
__int64 v13; // [rsp+18h] [rbp-850h]
__int64 v14; // [rsp+20h] [rbp-848h]
int v15[2]; // [rsp+50h] [rbp-818h] BYREF
char dest[4]; // [rsp+58h] [rbp-810h] BYREF
char s[46]; // [rsp+5Ch] [rbp-80Ch] BYREF
char v18[2014]; // [rsp+8Ah] [rbp-7DEh] BYREF

GlobalQueue = mq_open("/irc-commmon-queue", 1LL, envp);
if ( GlobalQueue >= 0 )
{
v4 = (unsigned int)getpid();
sprintf(ClientQueueName, "/irc-client-%d", v4);
v5 = &v12;
for ( i = 16LL; i; --i )
{
*(_DWORD *)v5 = 0;
v5 += 4;
}
v13 = 10LL;
v14 = 2048LL;
ClientQueue = mq_open(ClientQueueName, 64LL, 438LL);
if ( ClientQueue >= 0 )
{
signal(2, (__sighandler_t)quit);
if ( argc > 1 )
{
v7 = argv[1];
initializePrompt();
strcpy(dest, v7);
while ( 1 )
{
v15[0] = 1;
v15[1] = v4;
strcpy(v18, ClientQueueName);
if ( (int)mq_send((unsigned int)GlobalQueue, v15, 2048LL, 0LL) < 0 )
break;
if ( mq_receive((unsigned int)ClientQueue, v15, 2048LL, 0LL) < 0 )
{
perror("receiving login confirmation");
}
else if ( v15[0] == 5 )
{
puts(s);
if ( *(_DWORD *)dest )
{
pthread_create(&newthread, 0LL, queueListen, 0LL);
while ( 1 )
{
v10 = (void *)readline("-> ");
func11(v10, v15);
}
}
v8 = (const char *)readline("Choose other name: ");
v9 = (char *)v8;
if ( !v8 )
func6(0);
strcpy(dest, v8);
free(v9);
}
}
perror("send login msg");
func6(0);
}
printf("Usage: %s <login>\n", *argv);
func6(0);
}
printf("name - %s\n", ClientQueueName);
perror("open client queue");
func6(0);
}
perror("open global queue");
func6(0);
}

original_code:
int main(int argc, char **argv)
{
    GlobalQueue = mq_open("/irc-commmon-queue", 01);
    if (GlobalQueue < 0)
    {
        perror("open global queue");
        quit(0);
    }
    int pid = getpid();
    sprintf(ClientQueueName, "/irc-client-%d", pid);
    struct mq_attr attrs = { .mq_flags = 0, .mq_maxmsg = 10,
                             .mq_msgsize = 2048, .mq_curmsgs = 0 };
    ClientQueue = mq_open(ClientQueueName, 00 | 0100, 0666, &attrs);
    if (ClientQueue < 0)
    {
        printf("name - %s\n", ClientQueueName);
        perror("open client queue");
        quit(0);
    }
    signal(2, quit);
    if (argc < 2)
    {
        printf("Usage: %s <login>\n", argv[0]);
        quit(0);
    }
    Message message;
    char *username = argv[1];
    initializePrompt();
    strcpy(message.data.loginmsg.name, username);
    while (1)
    {
        message.type = LOGIN_MSG;
        message.data.loginmsg.cid = pid;
        strcpy(message.data.loginmsg.queueName, ClientQueueName);
        if (mq_send(GlobalQueue, (char *)&message, sizeof(Message), 0) < 0)
        {
            perror("send login msg");
            quit(0);
        }
        if (mq_receive(ClientQueue, (char *)&message, sizeof(Message), ((void *)0)) < 0)
            perror("receiving login confirmation");
        else
            if (message.type == CONFIRM_MSG)
            {
                puts(message.data.confmsg.text);
                if (message.data.confmsg.confirmed)
                    break;
                username = readline("Choose other name: ");
                if (! username)
                    quit(0);
                strcpy(message.data.loginmsg.name, username);
                free(username);
            }
    }
    pthread_t queueListenerThread;
    pthread_create(&queueListenerThread, ((void *)0), queueListen, ((void *)0));
    while (1)
    {
        char *input = readline("-> ");
        parseCommand(input, &message);
    }
}

canonical_original_code:
int main(int argc, char **argv)
{
    GlobalQueue = mq_open("/irc-commmon-queue", 01);
    if (GlobalQueue < 0)
    {
        perror("open global queue");
        quit(0);
    }
    int pid = getpid();
    sprintf(ClientQueueName, "/irc-client-%d", pid);
    struct mq_attr attrs = { .mq_flags = 0, .mq_maxmsg = 10,
                             .mq_msgsize = 2048, .mq_curmsgs = 0 };
    ClientQueue = mq_open(ClientQueueName, 00 | 0100, 0666, &attrs);
    if (ClientQueue < 0)
    {
        printf("name - %s\n", ClientQueueName);
        perror("open client queue");
        quit(0);
    }
    signal(2, quit);
    if (argc < 2)
    {
        printf("Usage: %s <login>\n", argv[0]);
        quit(0);
    }
    struct Message message;
    char *username = argv[1];
    initializePrompt();
    strcpy(message.data.loginmsg.name, username);
    while (1)
    {
        message.type = LOGIN_MSG;
        message.data.loginmsg.cid = pid;
        strcpy(message.data.loginmsg.queueName, ClientQueueName);
        if (mq_send(GlobalQueue, (char *)&message, sizeof(Message), 0) < 0)
        {
            perror("send login msg");
            quit(0);
        }
        if (mq_receive(ClientQueue, (char *)&message, sizeof(Message), ((void *)0)) < 0)
            perror("receiving login confirmation");
        else
            if (message.type == CONFIRM_MSG)
            {
                puts(message.data.confmsg.text);
                if (message.data.confmsg.confirmed)
                    break;
                username = readline("Choose other name: ");
                if (! username)
                    quit(0);
                strcpy(message.data.loginmsg.name, username);
                free(username);
            }
    }
    unsigned long queueListenerThread;
    pthread_create(&queueListenerThread, ((void *)0), queueListen, ((void *)0));
    while (1)
    {
        char *input = readline("-> ");
        parseCommand(input, &message);
    }
}

variable_types:
argv
char **

variable_types: pid int

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

variable_types:
queueListenerThread
unsigned long

variable_types:
input
char *


Randomize

decompiled_code:
void Randomize()
{
struct timespec v0; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v0);
srand(v0.tv_nsec);
}

canonical_decompiled_code:
void func0()
{
struct timespec v0; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v0);
srand(v0.tv_nsec);
}

original_code:
void Randomize()
{
    struct timespec ts;
    clock_gettime(0, &ts);
    srand(ts.tv_nsec);
}

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


decompiled_code:
void __fastcall __noreturn perror_die(const char *a1)
{
int *v1; // rax

perror(a1);
v1 = _errno_location();
exit(*v1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
int *v1; // rax

perror(a1);
v1 = _errno_location();
exit(*v1);
}

original_code:
void perror_die(char *msg)
{
    perror(msg);
    exit((*__errno_location ()));
}


safeNewline

decompiled_code:
__int64 __fastcall safeNewline(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12

pthread_mutex_lock(&TerminalLock);
v2 = rl_newline(a1, a2);
pthread_mutex_unlock(&TerminalLock);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12

pthread_mutex_lock(&TerminalLock);
v2 = rl_newline(a1, a2);
pthread_mutex_unlock(&TerminalLock);
return v2;
}

original_code:
int safeNewline(int count, int key)
{
    pthread_mutex_lock(&TerminalLock);
    int res = rl_newline(count, key);
    pthread_mutex_unlock(&TerminalLock);
    return res;
}

variable_types: count int

variable_types: key int

variable_types: res int


readlineStartupHook

decompiled_code:
__int64 readlineStartupHook()
{
rl_bind_key(10LL, safeNewline);
return rl_bind_key(13LL, safeNewline);
}

canonical_decompiled_code:
__int64 func1()
{
rl_bind_key(10LL, safeNewline);
return rl_bind_key(13LL, safeNewline);
}

original_code:
void readlineStartupHook()
{
    rl_bind_key(10, safeNewline);
    rl_bind_key(13, safeNewline);
}


safePrintf

decompiled_code:
int safePrintf(char *format, ...)
{
int result; // eax
int v2; // ebx
void *v3; // r12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( (rl_readline_state & 8) != 0 )
{
pthread_mutex_lock(&TerminalLock);
v2 = rl_point;
v3 = (void *)rl_copy_text(0LL, rl_end);
rl_save_prompt();
rl_replace_line(&unk_228, 0LL);
rl_redisplay();
va_start(arg, format);
vprintf(format, arg);
rl_restore_prompt();
rl_replace_line(v3, 0LL);
rl_point = v2;
rl_redisplay();
free(v3);
result = pthread_mutex_unlock(&TerminalLock);
}
else
{
va_start(arg, format);
result = vprintf(format, arg);
}
return result;
}

canonical_decompiled_code:
int func2(char *format, ...)
{
int result; // eax
int v2; // ebx
void *v3; // r12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( (rl_readline_state & 8) != 0 )
{
pthread_mutex_lock(&TerminalLock);
v2 = rl_point;
v3 = (void *)rl_copy_text(0LL, rl_end);
rl_save_prompt();
rl_replace_line(&unk_228, 0LL);
rl_redisplay();
va_start(arg, format);
vprintf(format, arg);
rl_restore_prompt();
rl_replace_line(v3, 0LL);
rl_point = v2;
rl_redisplay();
free(v3);
result = pthread_mutex_unlock(&TerminalLock);
}
else
{
va_start(arg, format);
result = vprintf(format, arg);
}
return result;
}

original_code:
void safePrintf(char *fmt, ...)
{
    int need_hack = (rl_readline_state & 0x0000008) > 0;
    char *saved_line;
    int saved_point;
    if (need_hack)
    {
        pthread_mutex_lock(&TerminalLock);
        saved_point = rl_point;
        saved_line = rl_copy_text(0, rl_end);
        rl_save_prompt();
        rl_replace_line("", 0);
        rl_redisplay();
    }
    va_list args;
    __builtin_va_start(args,fmt);
    vprintf(fmt, args);
    __builtin_va_end(args);
    if (need_hack)
    {
        rl_restore_prompt();
        rl_replace_line(saved_line, 0);
        rl_point = saved_point;
        rl_redisplay();
        free(saved_line);
        pthread_mutex_unlock(&TerminalLock);
    }
}

canonical_original_code:
void safePrintf(char *fmt, ...)
{
    int need_hack = (rl_readline_state & 0x0000008) > 0;
    char *saved_line;
    int saved_point;
    if (need_hack)
    {
        pthread_mutex_lock(&TerminalLock);
        saved_point = rl_point;
        saved_line = rl_copy_text(0, rl_end);
        rl_save_prompt();
        rl_replace_line("", 0);
        rl_redisplay();
    }
    __builtin_va_list args;
    __builtin_va_start(args,fmt);
    vprintf(fmt, args);
    __builtin_va_end(args);
    if (need_hack)
    {
        rl_restore_prompt();
        rl_replace_line(saved_line, 0);
        rl_point = saved_point;
        rl_redisplay();
        free(saved_line);
        pthread_mutex_unlock(&TerminalLock);
    }
}

variable_types:
fmt
char *


initializePrompt

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

result = pthread_mutex_init(&TerminalLock, 0LL);
rl_startup_hook = readlineStartupHook;
return result;
}

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

result = pthread_mutex_init(&TerminalLock, 0LL);
rl_startup_hook = readlineStartupHook;
return result;
}

original_code:
void initializePrompt()
{
    pthread_mutex_init(&TerminalLock, ((void *)0));
    rl_startup_hook = (rl_hook_func_t *)readlineStartupHook;
}

canonical_original_code:
void initializePrompt()
{
    pthread_mutex_init(&TerminalLock, ((void *)0));
    rl_startup_hook = (int (*)())readlineStartupHook;
}


flute

repo: kffaxen/wool

decompiled_code:
int __fastcall flute(int a1, const char **a2, int a3, __int64 a4)
{
int v4; // ebx
int result; // eax
int v8; // esi
__int64 v9; // rcx
int v10; // edx

if ( a1 <= 0 )
{
fwrite("Params for flute: <coeff> [<power>]\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v4 = a1;
if ( a1 != 1 )
v4 = atoi(a2[1]);
result = atoi(*a2);
v8 = result;
if ( a3 > 0 )
{
v9 = a4;
result = 0;
do
{
v10 = result;
v9 += 4LL;
result += v8;
*(_DWORD *)(v9 - 4) = v4 ^ v10;
}
while ( v9 != a4 + 4LL * (unsigned int)(a3 - 1) + 4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, const char **a2, int a3, __int64 a4)
{
int v4; // ebx
int result; // eax
int v8; // esi
__int64 v9; // rcx
int v10; // edx

if ( a1 <= 0 )
{
fwrite("Params for flute: <coeff> [<power>]\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v4 = a1;
if ( a1 != 1 )
v4 = atoi(a2[1]);
result = atoi(*a2);
v8 = result;
if ( a3 > 0 )
{
v9 = a4;
result = 0;
do
{
v10 = result;
v9 += 4LL;
result += v8;
*(_DWORD *)(v9 - 4) = v4 ^ v10;
}
while ( v9 != a4 + 4LL * (unsigned int)(a3 - 1) + 4 );
}
return result;
}

original_code:
void flute( int argc, char** argv, int n, int* delays )
{
  int coeff, power;
  if( argc < 1 ) {
    fprintf( stderr, "Params for flute: <coeff> [<power>]\n" );
    exit(1);
  } else if( argc < 2 ) {
    power = 1;
  } else {
    power = atoi( argv[1] );
  }
  coeff = atoi( argv[0] );
  for( int i = 0; i < n; i++ ) {
    delays[i] = coeff * i^power;
  }
}

canonical_original_code:
void flute(int argc, char **argv, int n, int *delays)
{
  int coeff; int power;
  if( argc < 1 ) {
    fprintf( stderr, "Params for flute: <coeff> [<power>]\n" );
    exit(1);
  } else if( argc < 2 ) {
    power = 1;
  } else {
    power = atoi( argv[1] );
  }
  coeff = atoi( argv[0] );
  for( int i = 0; i < n; i++ ) {
    delays[i] = coeff * i^power;
  }
}

variable_types: argc int

variable_types: n int

variable_types:
delays
int *

variable_types: coeff int

variable_types: power int

variable_types: i int


decompiled_code:
unsigned __int64 __fastcall tloop_TREE_CALL(_QWORD *a1, int a2, int a3, __int64 a4)
{
unsigned __int64 result; // rax
int v6; // ebp
int v7; // ebx
unsigned __int64 v8; // rsi
unsigned int v9; // er14
__int64 v10; // rsi
unsigned __int64 v11; // r8
int v12; // edi

result = a3 - a2;
v6 = a2;
v7 = a3;
if ( result <= 1 )
{
LABEL_7:
if ( v7 > v6 )
{
do
{
v12 = v6++;
result = tloop_LOOP_constprop_0(v12, a4);
}
while ( v6 != v7 );
}
}
else
{
v8 = a1[62];
while ( 1 )
{
*(_DWORD *)(v8 + 36) = v7;
*(_QWORD *)(v8 + 40) = a4;
v9 = (v6 + v7) / 2;
*(_DWORD *)(v8 + 32) = v9;
if ( v8 >= a1[54] )
{
v10 = wool_slow_spawn(a1, v8, &tloop_TREE_DICT);
}
else
{
*(_QWORD *)v8 = &tloop_TREE_DICT;
v10 = v8 + 128;
}
a1[62] = v10;
tloop_TREE_CALL(a1, (unsigned int)v6, v9, a4);
v11 = a1[62];
if ( a1[53] >= v11 )
break;
v7 = *(_DWORD *)(v11 - 92);
v6 = *(_DWORD *)(v11 - 96);
v8 = v11 - 128;
a1[62] = v11 - 128;
a4 = *(_QWORD *)(v11 - 88);
result = v7 - v6;
if ( result <= 1 )
goto LABEL_7;
}
result = tloop_TREE_PUB(a1, a1[62]);
}
return result;
}

original_code: void tloop_TREE_CALL(Worker *_wool_self , int a1, int a2, int* a3){ return tloop_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

canonical_original_code: void tloop_TREE_CALL(struct _Worker *_wool_self, int a1, int a2, int *a3){ return tloop_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

variable_types: struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task { struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; } *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *

user_defined_types: struct _Worker { struct _Worker_private pr; char pad1[-1]; struct _Worker_public pu; char pad2[-1]; }

user_defined_types: struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; }

user_defined_types: struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t work_available; void *(*fun)(void *); void *fun_arg; }

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

user_defined_types: struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; }

user_defined_types: struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; }

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

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