repo: hdevalence/wordgen

decompiled_code:
const char *__fastcall parse_data(__int64 a1, const char *a2, __int64 a3)
{
unsigned __int64 v3; // r13
const char *v4; // rbx
unsigned __int8 v5; // r12
__int64 v6; // rbp
__int64 v7; // rax
char v8; // r8
const char *result; // rax
const char *v10; // rbx
char v11; // dl
unsigned __int64 v12; // rax

v3 = (unsigned __int64)&a2[a3];
v4 = a2;
memset(ngram_buf_0, 0, sizeof(ngram_buf_0));
do
{
LABEL_2:
v5 = *v4;
v6 = 1LL;
v7 = 0LL;
if ( *v4 == 9 )
{
LABEL_14:
ngram_buf_0[v7] = 0;
do
++v4;
while ( *v4 != 9 );
v12 = strtoull(v4, 0LL, 10);
wtrie_add_entry(a1, ngram_buf_0, v12);
result = v4;
}
else
{
while ( 1 )
{
v8 = wtrie_valid_char(v5);
result = v4++;
if ( !v8 )
break;
*(_BYTE *)(v6 + 543) = v5;
v5 = *v4;
v7 = (int)v6;
if ( *v4 == 9 )
goto LABEL_14;
if ( ++v6 == 512 )
{
v7 = 511LL;
goto LABEL_14;
}
}
}
v10 = result;
if ( v3 > (unsigned __int64)result )
{
while ( 1 )
{
v11 = *result;
v10 = result++;
if ( v11 == 10 )
break;
if ( (const char *)v3 == result )
{
v4 = (const char *)(v3 + 1);
if ( v3 != v3 + 1 )
goto LABEL_2;
return result;
}
}
}
v4 = v10 + 1;
}
while ( (const char *)v3 != v4 );
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1, const char *a2, __int64 a3)
{
unsigned __int64 v3; // r13
const char *v4; // rbx
unsigned __int8 v5; // r12
__int64 v6; // rbp
__int64 v7; // rax
char v8; // r8
const char *result; // rax
const char *v10; // rbx
char v11; // dl
unsigned __int64 v12; // rax

v3 = (unsigned __int64)&a2[a3];
v4 = a2;
memset(ngram_buf_0, 0, sizeof(ngram_buf_0));
do
{
LABEL_2:
v5 = *v4;
v6 = 1LL;
v7 = 0LL;
if ( *v4 == 9 )
{
LABEL_14:
ngram_buf_0[v7] = 0;
do
++v4;
while ( *v4 != 9 );
v12 = strtoull(v4, 0LL, 10);
wtrie_add_entry(a1, ngram_buf_0, v12);
result = v4;
}
else
{
while ( 1 )
{
v8 = wtrie_valid_char(v5);
result = v4++;
if ( !v8 )
break;
*(_BYTE *)(v6 + 543) = v5;
v5 = *v4;
v7 = (int)v6;
if ( *v4 == 9 )
goto LABEL_14;
if ( ++v6 == 512 )
{
v7 = 511LL;
goto LABEL_14;
}
}
}
v10 = result;
if ( v3 > (unsigned __int64)result )
{
while ( 1 )
{
v11 = *result;
v10 = result++;
if ( v11 == 10 )
break;
if ( (const char *)v3 == result )
{
v4 = (const char *)(v3 + 1);
if ( v3 != v3 + 1 )
goto LABEL_2;
return result;
}
}
}
v4 = v10 + 1;
}
while ( (const char *)v3 != v4 );
return result;
}

original_code:
void parse_data(wtrie_t *root, const char *data, size_t len) {
    const char *end = data + len;
    static char ngram_buf[511 +1];
    memset(ngram_buf, 0, 511 +1);
    _Bool eof;
    while (!eof) {
        int count = 0;
        while (*data != '\t' && count < 511) {
            if (!wtrie_valid_char(*data))
                goto nextline;
            ngram_buf[count] = *data;
            ++count;
            ++data;
        }
        ngram_buf[count] = 0;
        do
            ++data;
        while (*data != '\t');
        uint64_t freq = strtoull(data,((void *)0),10);
        wtrie_add_entry(root,ngram_buf,freq);
        nextline:
        while (data < end && *data != '\n')
            data++;
        eof = (++data == end);
    }
}

canonical_original_code:
void parse_data(struct wtrie_t *root, char *data, unsigned long len) {
    char *end = data + len;
    static char ngram_buf[-1];
    memset(ngram_buf, 0, 511 +1);
    _Bool eof;
    while (!eof) {
        int count = 0;
        while (*data != '\t' && count < 511) {
            if (!wtrie_valid_char(*data))
                goto nextline;
            ngram_buf[count] = *data;
            ++count;
            ++data;
        }
        ngram_buf[count] = 0;
        do
            ++data;
        while (*data != '\t');
        unsigned long freq = strtoull(data,((void *)0),10);
        wtrie_add_entry(root,ngram_buf,freq);
        nextline:
        while (data < end && *data != '\n')
            data++;
        eof = (++data == end);
    }
}

variable_types: struct wtrie_t { union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } child_arr; unsigned long self_freq; unsigned long children_freq; } *

variable_types:
data
char *

variable_types:
len
unsigned long

variable_types:
end
char *

variable_types: count int

variable_types:
freq
unsigned long

user_defined_types: struct wtrie_t { union tagptr_t child_arr; unsigned long self_freq; unsigned long children_freq; }


decompiled_code:
int __fastcall add_to_trie(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // ebp
char *v4; // rax
char *v5; // rbp
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(a2, 0);
if ( v2 < 0 )
{
fprintf(stderr, "Cannot open file %s", a2);
goto LABEL_6;
}
v3 = v2;
if ( fstat(v2, &v7) < 0 )
{
fprintf(stderr, "Cannot stat file %s", a2);
LABEL_6:
exit(1);
}
v4 = (char *)mmap(0LL, v7.st_size, 1, 2, v3, 0LL);
v5 = v4;
if ( v4 == (char *)-1LL )
{
fprintf(stderr, "Cannot mmap file %s", a2);
goto LABEL_6;
}
madvise(v4, v7.st_size, 2);
parse_data(a1, v5, v7.st_size);
return munmap(v5, v7.st_size);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // ebp
char *v4; // rax
char *v5; // rbp
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(a2, 0);
if ( v2 < 0 )
{
fprintf(stderr, "Cannot open file %s", a2);
goto LABEL_6;
}
v3 = v2;
if ( fstat(v2, &v7) < 0 )
{
fprintf(stderr, "Cannot stat file %s", a2);
LABEL_6:
exit(1);
}
v4 = (char *)mmap(0LL, v7.st_size, 1, 2, v3, 0LL);
v5 = v4;
if ( v4 == (char *)-1LL )
{
fprintf(stderr, "Cannot mmap file %s", a2);
goto LABEL_6;
}
madvise(v4, v7.st_size, 2);
func0(a1, v5, v7.st_size);
return munmap(v5, v7.st_size);
}

original_code:
void add_to_trie(wtrie_t *root, char *filepath) {
    int fd = open(filepath, 00);
    if (fd < 0) {
        fprintf(stderr, "Cannot open file %s", filepath);
        exit(1);
    }
    struct stat statbuf;
    if (fstat(fd, &statbuf) < 0) {
        fprintf(stderr, "Cannot stat file %s", filepath);
        exit(1);
    }
    char *data = mmap(((void *)0), statbuf.st_size, 0x1, 0x02, fd, 0);
    if (data == ((void *) -1)) {
        fprintf(stderr, "Cannot mmap file %s", filepath);
        exit(1);
    }
    madvise(data, statbuf.st_size, 2);
    parse_data(root, data, statbuf.st_size);
    munmap(data, statbuf.st_size);
}

canonical_original_code:
void add_to_trie(struct wtrie_t *root, char *filepath) {
    int fd = open(filepath, 00);
    if (fd < 0) {
        fprintf(stderr, "Cannot open file %s", filepath);
        exit(1);
    }
    struct stat statbuf;
    if (fstat(fd, &statbuf) < 0) {
        fprintf(stderr, "Cannot stat file %s", filepath);
        exit(1);
    }
    char *data = mmap(((void *)0), statbuf.st_size, 0x1, 0x02, fd, 0);
    if (data == ((void *) -1)) {
        fprintf(stderr, "Cannot mmap file %s", filepath);
        exit(1);
    }
    madvise(data, statbuf.st_size, 2);
    parse_data(root, data, statbuf.st_size);
    munmap(data, statbuf.st_size);
}

variable_types:
filepath
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]; }

return_type: void

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

user_defined_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }


decompiled_code:
__int64 __fastcall build_trie(const char *a1)
{
__int64 v1; // r12

v1 = wtrie_alloc();
add_to_trie(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v1; // r12

v1 = wtrie_alloc();
func1(v1, a1);
return v1;
}

original_code:
wtrie_t* build_trie(char *filepath) {
    wtrie_t* root = wtrie_alloc();
    add_to_trie(root,filepath);
    return root;
}

canonical_original_code:
struct wtrie_t *build_trie(char *filepath) {
    struct wtrie_t *root = wtrie_alloc();
    add_to_trie(root,filepath);
    return root;
}

return_type: struct wtrie_t { union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } child_arr; unsigned long self_freq; unsigned long children_freq; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
__int64 v5; // rbp
const char **v6; // r13
const char *v7; // rsi
FILE *v8; // r13
__int64 v9; // rax
const char *v10; // rax
const char *v11; // rax

seedrand(argc, argv, envp);
if ( argc <= 3 )
{
puts("Usage: wordtrie outfile NGRAM dataset [dataset dataset...]");
}
else
{
v4 = argv + 3;
puts("Building trie");
v5 = wtrie_alloc();
v6 = &argv[(unsigned int)(argc - 4) + 4];
do
{
v7 = *v4++;
printf("Loading %s\n", v7);
add_to_trie(v5, *(v4 - 1));
}
while ( v4 != v6 );
puts("Computing frequencies");
wtrie_compute_freq(v5);
printf("Writing file to %s...\n", argv[1]);
v8 = fopen(argv[1], "w");
wtrie_serialize(v5, v8);
fclose(v8);
puts("Done.");
v9 = wtrie_find_entry(v5, argv[2]);
if ( v9 )
printf("%s: self %lu, children %lu\n", argv[2], *(_QWORD *)(v9 + 8), *(_QWORD *)(v9 + 16));
else
printf("Search term %s not found\n", argv[2]);
v10 = (const char *)wtrie_sample_string(v5, 0LL);
printf("Generated text %s\n", v10);
v11 = (const char *)wtrie_sample_string(v5, argv[2]);
printf("Generated text %s\n", v11);
wtrie_free(v5, 0LL);
mempool_free_globals();
}
return 0;
}

original_code:
int main() {
    tagptr_t arr;
    arr.ptr = ((void *)0);
    tagarray_pprint(arr);
    tagptr_t tmp;
    tmp.ptr = malloc(16);
    set_tag(&tmp,'e');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'b');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'c');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'a');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'d');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tagarray_sort(arr);
    tagptr_t val = tagarray_search(arr, 'd');
    tagarray_pprint(arr);
    tagarray_pprint(val);
    return 0;
}

canonical_original_code:
int main() {
    union tagptr_t arr;
    arr.ptr = ((void *)0);
    tagarray_pprint(arr);
    union tagptr_t tmp;
    tmp.ptr = malloc(16);
    set_tag(&tmp,'e');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'b');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'c');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'a');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'d');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tagarray_sort(arr);
    union tagptr_t val = tagarray_search(arr, 'd');
    tagarray_pprint(arr);
    tagarray_pprint(val);
    return 0;
}

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }

return_type: int


decompiled_code:
__int64 __fastcall tagarray_at(__int64 a1, int a2)
{
return *(_QWORD *)(mask_ptr() + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return *(_QWORD *)(mask_ptr() + 8LL * a2);
}

original_code:
inline tagptr_t tagarray_at(tagptr_t arr, int i) {
    return ((tagptr_t*)mask_ptr(arr))[i];
}

canonical_original_code:
inline union tagptr_t tagarray_at(union tagptr_t arr, int i) {
    return ((union tagptr_t *)mask_ptr(arr))[i];
}

variable_types:
arr
union tagptr_t

variable_types: i int

return_type: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }


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

result = mask_ptr();
*(_QWORD *)(result + 8LL * a2) = a3;
return result;
}

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

result = mask_ptr();
*(_QWORD *)(result + 8LL * a2) = a3;
return result;
}

original_code:
inline void tagarray_set(tagptr_t arr, int i, tagptr_t obj) {
    ((tagptr_t*)mask_ptr(arr))[i] = obj;
}

canonical_original_code:
inline void tagarray_set(union tagptr_t arr, int i, union tagptr_t obj) {
    ((union tagptr_t *)mask_ptr(arr))[i] = obj;
}

variable_types:
obj
union tagptr_t


decompiled_code:
unsigned __int64 __fastcall tagarray_size(unsigned __int64 a1)
{
return HIBYTE(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return HIBYTE(a1);
}

original_code:
inline uint8_t tagarray_size(tagptr_t arr) {
    return arr.bytes[7];
}

canonical_original_code:
inline unsigned char tagarray_size(union tagptr_t arr) {
    return arr.bytes[7];
}

return_type: unsigned char


decompiled_code:
unsigned __int64 __fastcall tagarray_reserved(unsigned __int64 a1)
{
return HIWORD(a1);
}

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

original_code:
inline uint8_t tagarray_reserved(tagptr_t arr) {
    return arr.bytes[6];
}

canonical_original_code:
inline unsigned char tagarray_reserved(union tagptr_t arr) {
    return arr.bytes[6];
}


decompiled_code:
unsigned __int64 __fastcall tagarray_free(unsigned __int64 a1)
{
unsigned __int64 result; // rax
unsigned __int8 v2; // bl
__int64 v3; // rbp
__int64 v4; // rax

result = tagarray_reserved(a1);
if ( (_BYTE)result )
{
v2 = result;
v3 = mask_ptr();
v4 = mempool(8LL * v2);
result = mempool_free(v4, v3);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 a1)
{
unsigned __int64 result; // rax
unsigned __int8 v2; // bl
__int64 v3; // rbp
__int64 v4; // rax

result = func3(a1);
if ( (_BYTE)result )
{
v2 = result;
v3 = mask_ptr();
v4 = mempool(8LL * v2);
result = mempool_free(v4, v3);
}
return result;
}

original_code:
void tagarray_free(tagptr_t arr)
{
    uint8_t reserved = tagarray_reserved(arr);
    if (reserved) {
        tagptr_t *raw_arr = (tagptr_t*)mask_ptr(arr);
        mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
    }
}

canonical_original_code:
void tagarray_free(union tagptr_t arr)
{
    unsigned char reserved = tagarray_reserved(arr);
    if (reserved) {
        union tagptr_t *raw_arr = (tagptr_t*)mask_ptr(arr);
        mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
    }
}

variable_types:
reserved
unsigned char

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } *


decompiled_code:
__int64 __fastcall tagarray_push_back(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int8 v6; // bp
unsigned __int8 v7; // r15
int v8; // er9
__int64 v9; // rax
int v10; // er14
__int64 v11; // rdi
__int64 v12; // rax
_QWORD *v13; // rax
__int64 v14; // r8
_QWORD *v15; // r13
__int64 result; // rax
__int64 v17; // rax
char *v18; // [rsp+0h] [rbp-48h]

v6 = *(_BYTE *)(a1 + 7);
v7 = *(_BYTE *)(a1 + 6);
v8 = v6;
if ( v6 == v7 )
{
v9 = mask_ptr(*(_QWORD *)a1, a2, a3, a4, a5, v6);
v10 = 2 * v6;
if ( v6 <= 0x40u )
{
if ( v10 )
{
v11 = 8LL * v10;
}
else
{
LOBYTE(v10) = 1;
v11 = 8LL;
}
}
else
{
if ( (v6 & 0x80u) != 0 )
_assert_fail("size < TAGARRAY_MAXLEN", "tagarray.c", 0x23u, "tagarray_push_back");
LOBYTE(v10) = 0x80;
v11 = 1024LL;
}
v18 = (char *)v9;
v12 = mempool(v11);
v13 = (_QWORD *)mempool_alloc(v12);
v8 = v6;
v14 = 8LL * v7;
v15 = v13;
if ( (unsigned int)v14 >= 8 )
{
*v13 = *(_QWORD *)v18;
v13[(unsigned __int64)v14 / 8 - 1] = *(_QWORD *)&v18[v14 - 8];
qmemcpy(
(void *)((unsigned __int64)(v13 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v18 - ((char *)v13 - ((unsigned __int64)(v13 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v14 + (_DWORD)v13 - (((_DWORD)v13 + 8) & 0xFFFFFFF8)) >> 3));
if ( !v7 )
{
LABEL_9:
*(_QWORD *)a1 = v15;
*(_BYTE *)(a1 + 7) = v6;
*(_BYTE *)(a1 + 6) = v10;
goto LABEL_10;
}
}
else
{
if ( (_DWORD)v14 )
*(_BYTE *)v13 = *v18;
if ( !v7 )
goto LABEL_9;
}
v17 = mempool(8LL * v7);
mempool_free(v17, v18);
v8 = v6;
goto LABEL_9;
}
LABEL_10:
result = tagarray_set(*(_QWORD *)a1, v8, a2);
*(_BYTE *)(a1 + 7) = v6 + 1;
return result;
}

original_code:
void tagarray_push_back(tagptr_t* arr, tagptr_t p) {
    uint8_t size = arr->bytes[7];
    uint8_t reserved = arr->bytes[6];
    if (size == reserved) {
        tagptr_t* raw_arr = (tagptr_t*)mask_ptr(*arr);
        int new_res = 2*reserved;
        if (new_res > 128) {
            new_res = 128;
            ((size < 128) ? (void) (0) : __assert_fail ("size < TAGARRAY_MAXLEN", "tagarray.c", 35, __extension__ __PRETTY_FUNCTION__));
        }
        if (new_res == 0)
            new_res = 1;
        tagptr_t* new_arr = mempool_alloc(mempool(sizeof(tagptr_t)*new_res));
        memcpy(new_arr, raw_arr, sizeof(tagptr_t)*reserved);
        if (reserved)
            mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
        arr->ptr = new_arr;
        arr->bytes[7] = size;
        arr->bytes[6] = new_res;
    }
    tagarray_set(*arr,size,p);
    ++size;
    arr->bytes[7] = size;
}

canonical_original_code:
void tagarray_push_back(union tagptr_t *arr, union tagptr_t p) {
    unsigned char size = arr->bytes[7];
    unsigned char reserved = arr->bytes[6];
    if (size == reserved) {
        union tagptr_t *raw_arr = (tagptr_t*)mask_ptr(*arr);
        int new_res = 2*reserved;
        if (new_res > 128) {
            new_res = 128;
            ((size < 128) ? (void) (0) : __assert_fail ("size < TAGARRAY_MAXLEN", "tagarray.c", 35, __extension__ __PRETTY_FUNCTION__));
        }
        if (new_res == 0)
            new_res = 1;
        union tagptr_t *new_arr = mempool_alloc(mempool(sizeof(tagptr_t)*new_res));
        memcpy(new_arr, raw_arr, sizeof(tagptr_t)*reserved);
        if (reserved)
            mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
        arr->ptr = new_arr;
        arr->bytes[7] = size;
        arr->bytes[6] = new_res;
    }
    tagarray_set(*arr,size,p);
    ++size;
    arr->bytes[7] = size;
}

variable_types:
p
union tagptr_t

variable_types:
size
unsigned char


decompiled_code:
unsigned __int64 __fastcall tagarray_insert(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 result; // rax
int v6; // ebp
int v7; // er15
__int64 v8; // r13
unsigned __int16 v9; // r14

tagarray_push_back((__int64)a1, a2, a3, a4, a5);
result = tagarray_size(*a1);
if ( (unsigned __int8)result > 1u )
{
v6 = (unsigned __int8)result - 1;
while ( 1 )
{
v7 = v6--;
v8 = tagarray_at(*a1, v6);
v9 = get_tag(v8);
if ( v9 <= (unsigned __int16)get_tag(a2) )
break;
tagarray_set(*a1, v7, v8);
if ( !v6 )
goto LABEL_5;
}
v6 = v7;
LABEL_5:
result = tagarray_set(*a1, v6, a2);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 result; // rax
int v6; // ebp
int v7; // er15
__int64 v8; // r13
unsigned __int16 v9; // r14

func5((__int64)a1, a2, a3, a4, a5);
result = func2(*a1);
if ( (unsigned __int8)result > 1u )
{
v6 = (unsigned __int8)result - 1;
while ( 1 )
{
v7 = v6--;
v8 = func0(*a1, v6);
v9 = get_tag(v8);
if ( v9 <= (unsigned __int16)get_tag(a2) )
break;
func1(*a1, v7, v8);
if ( !v6 )
goto LABEL_5;
}
v6 = v7;
LABEL_5:
result = func1(*a1, v6, a2);
}
return result;
}

original_code:
void tagarray_insert(tagptr_t* arr, tagptr_t p) {
    tagarray_push_back(arr,p);
    if (tagarray_size(*arr) <= 1)
        return;
    int i = tagarray_size(*arr) - 1;
    while (i > 0) {
        tagptr_t q = tagarray_at(*arr,i-1);
        if( get_tag(q) > get_tag(p) ) {
            tagarray_set(*arr,i,q);
            --i;
        } else break;
    }
    tagarray_set(*arr,i,p);
}

canonical_original_code:
void tagarray_insert(union tagptr_t *arr, union tagptr_t p) {
    tagarray_push_back(arr,p);
    if (tagarray_size(*arr) <= 1)
        return;
    int i = tagarray_size(*arr) - 1;
    while (i > 0) {
        union tagptr_t q = tagarray_at(*arr,i-1);
        if( get_tag(q) > get_tag(p) ) {
            tagarray_set(*arr,i,q);
            --i;
        } else break;
    }
    tagarray_set(*arr,i,p);
}


decompiled_code:
__int64 __fastcall tagarray_swap(__int64 a1, int a2, int a3)
{
__int64 v4; // r14
__int64 v5; // rax

v4 = tagarray_at(a1, a2);
v5 = tagarray_at(a1, a3);
tagarray_set(a1, a2, v5);
return tagarray_set(a1, a3, v4);
}

original_code:
void tagarray_swap(tagptr_t arr, int i, int j) {
    tagptr_t tmp = tagarray_at(arr, i);
    tagarray_set(arr, i, tagarray_at(arr, j));
    tagarray_set(arr, j, tmp);
}

canonical_original_code:
void tagarray_swap(union tagptr_t arr, int i, int j) {
    union tagptr_t tmp = tagarray_at(arr, i);
    tagarray_set(arr, i, tagarray_at(arr, j));
    tagarray_set(arr, j, tmp);
}

variable_types: j int


decompiled_code:
__int64 __fastcall tagarray_partition(__int64 a1, int a2, int a3, int a4)
{
unsigned int v6; // er12
__int64 v7; // rax
unsigned __int16 v8; // bp
int v9; // ebx
__int64 v10; // rax
int v11; // esi

v6 = a2;
v7 = tagarray_at(a1, a4);
v8 = get_tag(v7);
tagarray_swap(a1, a4, a3);
if ( a3 >= a2 )
{
v9 = a2;
do
{
while ( 1 )
{
v10 = tagarray_at(a1, v9);
if ( (unsigned __int16)get_tag(v10) < v8 )
break;
if ( a3 < ++v9 )
goto LABEL_6;
}
v11 = v9++;
tagarray_swap(a1, v11, v6++);
}
while ( a3 >= v9 );
}
LABEL_6:
tagarray_swap(a1, v6, a3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3, int a4)
{
unsigned int v6; // er12
__int64 v7; // rax
unsigned __int16 v8; // bp
int v9; // ebx
__int64 v10; // rax
int v11; // esi

v6 = a2;
v7 = func0(a1, a4);
v8 = get_tag(v7);
func7(a1, a4, a3);
if ( a3 >= a2 )
{
v9 = a2;
do
{
while ( 1 )
{
v10 = func0(a1, v9);
if ( (unsigned __int16)get_tag(v10) < v8 )
break;
if ( a3 < ++v9 )
goto LABEL_6;
}
v11 = v9++;
func7(a1, v11, v6++);
}
while ( a3 >= v9 );
}
LABEL_6:
func7(a1, v6, a3);
return v6;
}

original_code:
int tagarray_partition(tagptr_t arr, int l, int r, int p) {
    uint16_t pivot_tag = get_tag(tagarray_at(arr, p));
    tagarray_swap(arr, p, r);
    int store_idx = l;
    for (int i = l; i <= r; ++i) {
        if (pivot_tag > get_tag(tagarray_at(arr, i))) {
            tagarray_swap(arr,i,store_idx);
            store_idx++;
        }
    }
    tagarray_swap(arr,store_idx,r);
    return store_idx;
}

canonical_original_code:
int tagarray_partition(union tagptr_t arr, int l, int r, int p) {
    unsigned short pivot_tag = get_tag(tagarray_at(arr, p));
    tagarray_swap(arr, p, r);
    int store_idx = l;
    for (int i = l; i <= r; ++i) {
        if (pivot_tag > get_tag(tagarray_at(arr, i))) {
            tagarray_swap(arr,i,store_idx);
            store_idx++;
        }
    }
    tagarray_swap(arr,store_idx,r);
    return store_idx;
}

variable_types: l int

variable_types: r int

variable_types: p int


decompiled_code:
void __fastcall tagarray_qsort(__int64 a1, int a2, int a3)
{
unsigned int v4; // ebp
int v5; // er12

if ( a3 > a2 )
{
v4 = a2;
do
{
v5 = tagarray_partition(a1, v4, a3, (int)(a3 + v4) / 2);
tagarray_qsort(a1, v4, (unsigned int)(v5 - 1));
v4 = v5 + 1;
}
while ( v5 + 1 < a3 );
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, int a3)
{
unsigned int v4; // ebp
int v5; // er12

if ( a3 > a2 )
{
v4 = a2;
do
{
v5 = func8(a1, v4, a3, (int)(a3 + v4) / 2);
func9(a1, v4, (unsigned int)(v5 - 1));
v4 = v5 + 1;
}
while ( v5 + 1 < a3 );
}
}

original_code:
void tagarray_qsort(tagptr_t arr, int l, int r) {
    if (l < r) {
        int p = (l+r)/2;
        int newp = tagarray_partition(arr,l,r,p);
        tagarray_qsort(arr,l,newp-1);
        tagarray_qsort(arr,newp+1,r);
    }
}

canonical_original_code:
void tagarray_qsort(union tagptr_t arr, int l, int r) {
    if (l < r) {
        int p = (l+r)/2;
        int newp = tagarray_partition(arr,l,r,p);
        tagarray_qsort(arr,l,newp-1);
        tagarray_qsort(arr,newp+1,r);
    }
}

variable_types: newp int


decompiled_code:
void __fastcall tagarray_sort(unsigned __int64 a1)
{
tagarray_qsort(a1, 0, HIBYTE(a1) - 1);
}

canonical_decompiled_code:
void __fastcall func10(unsigned __int64 a1)
{
func9(a1, 0, HIBYTE(a1) - 1);
}

original_code:
void tagarray_sort(tagptr_t arr) {
    int size = arr.bytes[7];
    tagarray_qsort(arr,0,size-1);
}

canonical_original_code:
void tagarray_sort(union tagptr_t arr) {
    int size = arr.bytes[7];
    tagarray_qsort(arr,0,size-1);
}

variable_types: size int


decompiled_code:
__int64 __fastcall tagarray_search(unsigned __int64 a1, unsigned __int16 a2)
{
unsigned __int8 v2; // al
int v3; // ebx
int v4; // er13
int v5; // ebp
__int64 v6; // rax
unsigned __int16 v7; // ax

v2 = tagarray_size(a1);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = 0;
while ( 1 )
{
while ( 1 )
{
v5 = (v3 + v4) >> 1;
v6 = tagarray_at(a1, v5);
v7 = get_tag(v6);
if ( v7 >= a2 )
break;
v4 = v5 + 1;
if ( v5 + 1 >= v3 )
return 0LL;
}
if ( v7 <= a2 )
break;
v3 = (v3 + v4) >> 1;
if ( v4 >= v5 )
return 0LL;
}
return tagarray_at(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int64 a1, unsigned __int16 a2)
{
unsigned __int8 v2; // al
int v3; // ebx
int v4; // er13
int v5; // ebp
__int64 v6; // rax
unsigned __int16 v7; // ax

v2 = func2(a1);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = 0;
while ( 1 )
{
while ( 1 )
{
v5 = (v3 + v4) >> 1;
v6 = func0(a1, v5);
v7 = get_tag(v6);
if ( v7 >= a2 )
break;
v4 = v5 + 1;
if ( v5 + 1 >= v3 )
return 0LL;
}
if ( v7 <= a2 )
break;
v3 = (v3 + v4) >> 1;
if ( v4 >= v5 )
return 0LL;
}
return func0(a1, v5);
}

original_code:
tagptr_t tagarray_search(tagptr_t arr, uint16_t search_tag) {
    int l = 0;
    int r = tagarray_size(arr);
    while (l < r) {
        int mid = (l+r)/2;
        uint16_t mid_tag = get_tag(tagarray_at(arr,mid));
        if (mid_tag < search_tag) {
            l = mid + 1;
        } else if (mid_tag > search_tag) {
            r = mid;
        } else {
            return tagarray_at(arr,mid);
        }
    }
    tagptr_t not_found = { .ptr = ((void *)0) };
    return not_found;
}

canonical_original_code:
union tagptr_t tagarray_search(union tagptr_t arr, unsigned short search_tag) {
    int l = 0;
    int r = tagarray_size(arr);
    while (l < r) {
        int mid = (l+r)/2;
        unsigned short mid_tag = get_tag(tagarray_at(arr,mid));
        if (mid_tag < search_tag) {
            l = mid + 1;
        } else if (mid_tag > search_tag) {
            r = mid;
        } else {
            return tagarray_at(arr,mid);
        }
    }
    union tagptr_t not_found = { .ptr = ((void *)0) };
    return not_found;
}

variable_types: mid int


decompiled_code:
int __fastcall tagarray_pprint(unsigned __int64 a1)
{
int result; // eax
unsigned int v2; // er13
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // rbp
unsigned __int16 v6; // ax
__int64 v7; // rsi
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
__int64 v12; // rax

printf("PPRINT 0x%016llX\n", a1);
printf(" SIZE %d\n", HIBYTE(a1));
result = printf(" RSVD %d\n", BYTE6(a1));
if ( HIBYTE(a1) )
{
v2 = 0;
do
{
v3 = tagarray_at(a1, v2);
v4 = v2++;
v5 = v3;
printf("\t%d\t0x%016llX\n", v4, v3);
v6 = get_tag(v5);
v7 = v6;
printf("\t\tTAG\t%d : %c\n", v6, (unsigned int)(char)v6);
v12 = mask_ptr(v5, v7, v8, v9, v10, v11);
result = printf("\t\tVAL\t0x%016llX\n", v12);
}
while ( HIBYTE(a1) != v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int64 a1)
{
int result; // eax
unsigned int v2; // er13
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // rbp
unsigned __int16 v6; // ax
__int64 v7; // rsi
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
__int64 v12; // rax

printf("PPRINT 0x%016llX\n", a1);
printf(" SIZE %d\n", HIBYTE(a1));
result = printf(" RSVD %d\n", BYTE6(a1));
if ( HIBYTE(a1) )
{
v2 = 0;
do
{
v3 = func0(a1, v2);
v4 = v2++;
v5 = v3;
printf("\t%d\t0x%016llX\n", v4, v3);
v6 = get_tag(v5);
v7 = v6;
printf("\t\tTAG\t%d : %c\n", v6, (unsigned int)(char)v6);
v12 = mask_ptr(v5, v7, v8, v9, v10, v11);
result = printf("\t\tVAL\t0x%016llX\n", v12);
}
while ( HIBYTE(a1) != v2 );
}
return result;
}

original_code:
void tagarray_pprint(tagptr_t arr) {
    int size = arr.bytes[7];
    int reserved = arr.bytes[6];
    printf("PPRINT 0x%016llX\n", (unsigned long long) arr.ptr);
    printf("  SIZE %d\n", size);
    printf("  RSVD %d\n", reserved);
    for(int i = 0; i < size; ++i) {
        tagptr_t p = tagarray_at(arr,i);
        printf("\t%d\t0x%016llX\n", i, (unsigned long long) p.ptr);
        printf("\t\tTAG\t%d : %c\n", get_tag(p), (char)get_tag(p));
        printf("\t\tVAL\t0x%016llX\n", (unsigned long long) mask_ptr(p));
    }
}

canonical_original_code:
void tagarray_pprint(union tagptr_t arr) {
    int size = arr.bytes[7];
    int reserved = arr.bytes[6];
    printf("PPRINT 0x%016llX\n", (unsigned long long) arr.ptr);
    printf("  SIZE %d\n", size);
    printf("  RSVD %d\n", reserved);
    for(int i = 0; i < size; ++i) {
        union tagptr_t p = tagarray_at(arr,i);
        printf("\t%d\t0x%016llX\n", i, (unsigned long long) p.ptr);
        printf("\t\tTAG\t%d : %c\n", get_tag(p), (char)get_tag(p));
        printf("\t\tVAL\t0x%016llX\n", (unsigned long long) mask_ptr(p));
    }
}

variable_types: reserved int


decompiled_code:
void __fastcall free_mempool(void **a1)
{
if ( *a1 )
free_mempool();
free(a1[1]);
free(a1[4]);
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
if ( *a1 )
func0();
free(a1[1]);
free(a1[4]);
free(a1);
}

original_code:
void free_mempool(mempool_t *pool)
{
    if (pool->next) {
        free_mempool(pool->next);
    }
    free(pool->mem_start);
    free(pool->free_spots);
    free(pool);
}

canonical_original_code:
void free_mempool(struct mempool_t *pool)
{
    if (pool->next) {
        free_mempool(pool->next);
    }
    free(pool->mem_start);
    free(pool->free_spots);
    free(pool);
}

variable_types: struct mempool_t { struct mempool_t *next; char *mem_start; char *mem_end; char *alloc_ptr; char **free_spots; unsigned long alloc_size; unsigned long pool_size; unsigned long free_spots_size; unsigned long free_spots_res; } *


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

v0 = (void ***)global_pools;
do
{
if ( *v0 )
{
free_mempool(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != (void ***)"mempool_create" );
}

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

v0 = (void ***)global_pools;
do
{
if ( *v0 )
{
func0(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != (void ***)"mempool_create" );
}

original_code:
void mempool_free_globals()
{
    for (int i = 0; i < 129; ++i) {
        if (!global_pools[i])
            continue;
        free_mempool(global_pools[i]);
        global_pools[i] = ((void *)0);
    }
}


decompiled_code:
__int64 __fastcall mempool_alloc(_QWORD *a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
__int64 v3; // r8
unsigned __int64 v4; // rax
_QWORD *v5; // rax
_QWORD *v6; // rax
__int64 v7; // r8
__int64 result; // rax
unsigned __int64 v9; // rdx

v1 = a1[7];
v2 = a1;
if ( v1 )
{
LABEL_7:
v7 = *(_QWORD *)(v2[4] + 8 * v1 - 8);
v2[7] = v1 - 1;
result = v7;
}
else
{
while ( 1 )
{
v3 = v2[3];
v4 = v2[2];
if ( v3 != v4 )
break;
v5 = (_QWORD *)*v2;
if ( *v2 )
{
v2 = (_QWORD *)*v2;
v1 = v5[7];
if ( v1 )
goto LABEL_7;
}
else
{
v6 = create_mempool(v2[5], v2[6]);
*v2 = v6;
v2 = v6;
v1 = v6[7];
if ( v1 )
goto LABEL_7;
}
}
v9 = v3 + v2[5];
if ( v4 < v9 )
_assert_fail("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 0x4Eu, "mempool_alloc");
v2[3] = v9;
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
__int64 v3; // r8
unsigned __int64 v4; // rax
_QWORD *v5; // rax
_QWORD *v6; // rax
__int64 v7; // r8
__int64 result; // rax
unsigned __int64 v9; // rdx

v1 = a1[7];
v2 = a1;
if ( v1 )
{
LABEL_7:
v7 = *(_QWORD *)(v2[4] + 8 * v1 - 8);
v2[7] = v1 - 1;
result = v7;
}
else
{
while ( 1 )
{
v3 = v2[3];
v4 = v2[2];
if ( v3 != v4 )
break;
v5 = (_QWORD *)*v2;
if ( *v2 )
{
v2 = (_QWORD *)*v2;
v1 = v5[7];
if ( v1 )
goto LABEL_7;
}
else
{
v6 = create_mempool(v2[5], v2[6]);
*v2 = v6;
v2 = v6;
v1 = v6[7];
if ( v1 )
goto LABEL_7;
}
}
v9 = v3 + v2[5];
if ( v4 < v9 )
_assert_fail("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 0x4Eu, "mempool_alloc");
v2[3] = v9;
result = v3;
}
return result;
}

original_code:
void *mempool_alloc(mempool_t *pool)
{
    if (pool->free_spots_size > 0) {
        void *alloc = pool->free_spots[pool->free_spots_size -1];
        pool->free_spots_size--;
        return alloc;
    } else if (pool->alloc_ptr != pool->mem_end) {
        ((pool->alloc_ptr + pool->alloc_size <= pool->mem_end) ? (void) (0) : __assert_fail ("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 78, __extension__ __PRETTY_FUNCTION__));
        void *alloc = pool->alloc_ptr;
        pool->alloc_ptr += pool->alloc_size;
        return alloc;
    } else if (!pool->next) {
        pool->next = create_mempool(pool->alloc_size, pool->pool_size);
    }
    return mempool_alloc(pool->next);
}

canonical_original_code:
void *mempool_alloc(struct mempool_t *pool)
{
    if (pool->free_spots_size > 0) {
        void *alloc = pool->free_spots[pool->free_spots_size -1];
        pool->free_spots_size--;
        return alloc;
    } else if (pool->alloc_ptr != pool->mem_end) {
        ((pool->alloc_ptr + pool->alloc_size <= pool->mem_end) ? (void) (0) : __assert_fail ("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 78, __extension__ __PRETTY_FUNCTION__));
        void *alloc = pool->alloc_ptr;
        pool->alloc_ptr += pool->alloc_size;
        return alloc;
    } else if (!pool->next) {
        pool->next = create_mempool(pool->alloc_size, pool->pool_size);
    }
    return mempool_alloc(pool->next);
}

variable_types:
alloc
void *

return_type: void *

user_defined_types: struct mempool_t { struct mempool_t *next; char *mem_start; char *mem_end; char *alloc_ptr; char **free_spots; unsigned long alloc_size; unsigned long pool_size; unsigned long free_spots_size; unsigned long free_spots_res; }


decompiled_code:
void __fastcall mempool_free(_QWORD *a1, unsigned __int64 a2)
{
__int64 v4; // rsi
void *v5; // rdi
void *v6; // rax

while ( a1[1] > a2 || a1[2] < a2 )
{
a1 = (_QWORD *)*a1;
if ( !a1 )
{
fwrite("tried to mempool_free a pointer not in the memory pool!\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
}
v4 = a1[7];
v5 = (void *)a1[4];
if ( v4 == a1[8] )
{
v6 = realloc(v5, 16 * v4);
v5 = v6;
if ( !v6 )
{
err_oom("mempool_free");
JUMPOUT(0x2A3LL);
}
a1[4] = v6;
v4 = a1[7];
a1[8] *= 2LL;
}
*((_QWORD *)v5 + v4) = a2;
a1[7] = v4 + 1;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, unsigned __int64 a2)
{
__int64 v4; // rsi
void *v5; // rdi
void *v6; // rax

while ( a1[1] > a2 || a1[2] < a2 )
{
a1 = (_QWORD *)*a1;
if ( !a1 )
{
fwrite("tried to mempool_free a pointer not in the memory pool!\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
}
v4 = a1[7];
v5 = (void *)a1[4];
if ( v4 == a1[8] )
{
v6 = realloc(v5, 16 * v4);
v5 = v6;
if ( !v6 )
{
err_oom("mempool_free");
JUMPOUT(0x2A3LL);
}
a1[4] = v6;
v4 = a1[7];
a1[8] *= 2LL;
}
*((_QWORD *)v5 + v4) = a2;
a1[7] = v4 + 1;
}

original_code:
void mempool_free(mempool_t *pool, void *ptr) {
    if (pool->mem_start <= (char*)ptr && (char*)ptr <= pool->mem_end) {
        if (pool->free_spots_size == pool->free_spots_res) {
            size_t new_size = 2*sizeof(char*)*pool->free_spots_res;
            char **new_arr = realloc(pool->free_spots, new_size);
            if (!new_arr)
                err_oom("mempool_free");
            pool->free_spots = new_arr;
            pool->free_spots_res *= 2;
        }
        pool->free_spots[pool->free_spots_size] = ptr;
        pool->free_spots_size++;
        return;
    } else if (pool->next) {
        mempool_free(pool->next, ptr);
        return;
    } else {
        fprintf(stderr, "tried to mempool_free a pointer not in the memory pool!\n");
        exit(1);
    }
}

canonical_original_code:
void mempool_free(struct mempool_t *pool, void *ptr) {
    if (pool->mem_start <= (char *)ptr && (char *)ptr <= pool->mem_end) {
        if (pool->free_spots_size == pool->free_spots_res) {
            unsigned long new_size = 2*sizeof(char*)*pool->free_spots_res;
            char **new_arr = realloc(pool->free_spots, new_size);
            if (!new_arr)
                err_oom("mempool_free");
            pool->free_spots = new_arr;
            pool->free_spots_res *= 2;
        }
        pool->free_spots[pool->free_spots_size] = ptr;
        pool->free_spots_size++;
        return;
    } else if (pool->next) {
        mempool_free(pool->next, ptr);
        return;
    } else {
        fprintf(stderr, "tried to mempool_free a pointer not in the memory pool!\n");
        exit(1);
    }
}

variable_types:
ptr
void *


decompiled_code:
void __fastcall __noreturn err_oom(const char *a1)
{
fprintf(stderr, "Out of memory: malloc failed in\t%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Out of memory: malloc failed in\t%s\n", a1);
exit(1);
}

original_code:
inline void err_oom(char *msg)
{
    fprintf(stderr,"Out of memory: malloc failed in\t%s\n", msg);
    exit(1);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall in_string(char a1, _BYTE *a2)
{
__int64 result; // rax

if ( a2 )
{
LOBYTE(result) = *a2;
if ( !*a2 )
return 0LL;
while ( a1 != (_BYTE)result )
{
result = (unsigned __int8)*++a2;
if ( !(_BYTE)result )
return result;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, _BYTE *a2)
{
__int64 result; // rax

if ( a2 )
{
LOBYTE(result) = *a2;
if ( !*a2 )
return 0LL;
while ( a1 != (_BYTE)result )
{
result = (unsigned __int8)*++a2;
if ( !(_BYTE)result )
return result;
}
}
return 1LL;
}

original_code:
inline _Bool in_string(char c, char *allowed_chars) {
    if (!allowed_chars) {
        return 1;
    } else {
        while (*allowed_chars != 0) {
            if (*allowed_chars == c)
                return 1;
            ++allowed_chars;
        }
        return 0;
    }
}

variable_types: c char


sum

decompiled_code:
double __fastcall sum(int a1, double *a2)
{
double result; // xmm0_8
__int64 v3; // rax

if ( a1 <= 0 )
return 0.0;
result = 0.0;
v3 = (__int64)&a2[(unsigned int)(a1 - 1) + 1];
do
result = result + *a2++;
while ( a2 != (double *)v3 );
return result;
}

canonical_decompiled_code:
double __fastcall func2(int a1, double *a2)
{
double result; // xmm0_8
__int64 v3; // rax

if ( a1 <= 0 )
return 0.0;
result = 0.0;
v3 = (__int64)&a2[(unsigned int)(a1 - 1) + 1];
do
result = result + *a2++;
while ( a2 != (double *)v3 );
return result;
}

original_code:
inline double sum(int count, double *restrict arr) {
    double s = 0;
    for (int i = 0; i < count; ++i)
        s += arr[i];
    return s;
}

canonical_original_code:
inline double sum(int count, double *arr) {
    double s = 0;
    for (int i = 0; i < count; ++i)
        s += arr[i];
    return s;
}

variable_types: count int

variable_types:
arr
double *

variable_types: s double

variable_types: i int

return_type: double


decompiled_code:
__int64 __fastcall base128_count(unsigned __int64 a1)
{
_BitScanReverse64(&a1, a1);
return (unsigned int)(7 * ((int)(63 - (a1 ^ 0x3F)) / 7) != 63 - ((unsigned int)a1 ^ 0x3F))
+ (int)(63 - (a1 ^ 0x3F)) / 7;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1)
{
_BitScanReverse64(&a1, a1);
return (unsigned int)(7 * ((int)(63 - (a1 ^ 0x3F)) / 7) != 63 - ((unsigned int)a1 ^ 0x3F))
+ (int)(63 - (a1 ^ 0x3F)) / 7;
}

original_code:
inline int base128_count(uint64_t val) {
    int lg = 63 - __builtin_clzl(val);
    int q = lg / 7;
    if (7*q == lg)
        return q;
    else
        return q+1;
}

canonical_original_code:
inline int base128_count(unsigned long val) {
    int lg = 63 - __builtin_clzl(val);
    int q = lg / 7;
    if (7*q == lg)
        return q;
    else
        return q+1;
}

variable_types:
val
unsigned long

variable_types: lg int

variable_types: q int


decompiled_code:
__int64 __fastcall base128_digit(unsigned __int64 a1, char a2)
{
return (a1 >> (7 * a2)) & 0x7F;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, char a2)
{
return (a1 >> (7 * a2)) & 0x7F;
}

original_code:
inline uint8_t base128_digit(uint64_t val, int i) {
    return ((val >> 7*i) & 127);
}

canonical_original_code:
inline unsigned char base128_digit(unsigned long val, int i) {
    return ((val >> 7*i) & 127);
}


seedrand

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

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_usec) * LODWORD(v0.tv_sec));
srand48(v0.tv_sec * v0.tv_usec);
}

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

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_usec) * LODWORD(v0.tv_sec));
srand48(v0.tv_sec * v0.tv_usec);
}

original_code:
void seedrand() {
    struct timeval t;
    gettimeofday(&t, ((void *)0));
    srand(t.tv_usec * t.tv_sec);
    srand48(t.tv_usec * t.tv_sec);
}

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


decompiled_code:
__int64 __fastcall random_sample(int a1, __int64 a2, double a3)
{
double v3; // xmm1_8
__int64 result; // rax
double v5; // xmm0_8

v3 = a3 * drand48();
if ( a1 <= 0 )
return (unsigned int)(a1 - 1);
result = 0LL;
v5 = 0.0;
while ( 1 )
{
v5 = v5 + *(double *)(a2 + 8 * result);
if ( v5 > v3 )
break;
if ( ++result == a1 )
return (unsigned int)(a1 - 1);
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, __int64 a2, double a3)
{
double v3; // xmm1_8
__int64 result; // rax
double v5; // xmm0_8

v3 = a3 * drand48();
if ( a1 <= 0 )
return (unsigned int)(a1 - 1);
result = 0LL;
v5 = 0.0;
while ( 1 )
{
v5 = v5 + *(double *)(a2 + 8 * result);
if ( v5 > v3 )
break;
if ( ++result == a1 )
return (unsigned int)(a1 - 1);
}
return (unsigned int)result;
}

original_code:
int random_sample(int arraylen, double arraysum, double *array) {
    double sampled = arraysum*drand48();
    double cumsum = 0;
    for (int i = 0; i < arraylen; ++i) {
        cumsum += array[i];
        if (sampled < cumsum)
            return i;
    }
    return arraylen-1;
}

variable_types: arraylen int

variable_types: arraysum double

variable_types:
array
double *

variable_types: sampled double

variable_types: cumsum double


decompiled_code:
__int64 __fastcall mask_ptr(__int64 a1)
{
return a1 & 0xFFFFFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 & 0xFFFFFFFFFFFFLL;
}

original_code:
inline void * mask_ptr(tagptr_t p) {
    return (void*)(((uint64_t)p.ptr) & 0x0000ffffffffffffULL);
}

canonical_original_code:
inline void *mask_ptr(union tagptr_t p) {
    return (void *)(((unsigned long)p.ptr) & 0x0000ffffffffffffULL);
}

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }


decompiled_code:
void __fastcall set_tag(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 6) = a2;
}

original_code:
inline void set_tag(tagptr_t *p, uint16_t tag) {
    p->tags[3] = tag;
}

canonical_original_code:
inline void set_tag(union tagptr_t *p, unsigned short tag) {
    p->tags[3] = tag;
}

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } *

variable_types:
tag
unsigned short


decompiled_code:
unsigned __int64 __fastcall get_tag(unsigned __int64 a1)
{
return HIWORD(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return HIWORD(a1);
}

original_code:
inline uint16_t get_tag(tagptr_t p) {
    return p.tags[3];
}

canonical_original_code:
inline unsigned short get_tag(union tagptr_t p) {
    return p.tags[3];
}

return_type: unsigned short


main

repo: hdznrrd/noiseplug

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
while ( 1 )
{
argc = (unsigned __int8)next_sample(argc, argv, envp);
putchar(argc);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
while ( 1 )
{
argc = (unsigned __int8)func10(argc, argv, envp);
putchar(argc);
}
}

original_code:
int main()
{
 while(1) putchar(next_sample());
}


decompiled_code:
__int64 next_note()
{
char v0; // al
unsigned int v1; // er8

v0 = idx_1 + 1;
v1 = (unsigned __int8)melody[(unsigned __int8)idx_1];
if ( idx_1 == 23 )
v0 = 0;
idx_1 = v0;
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
char v0; // al
unsigned int v1; // er8

v0 = idx_1 + 1;
v1 = (unsigned __int8)melody[(unsigned __int8)idx_1];
if ( idx_1 == 23 )
v0 = 0;
idx_1 = v0;
return v1;
}

original_code:
static inline uint8_t next_note()
{
 static uint8_t idx=0;
 const uint8_t v = melody[idx++];
 if(idx == (sizeof((melody))/sizeof(*(melody))))
  idx = 0;
 return v;
}

canonical_original_code:
static inline unsigned char next_note()
{
 static unsigned char idx = 0;
 unsigned char v = melody[idx++];
 if(idx == (sizeof((melody))/sizeof(*(melody))))
  idx = 0;
 return v;
}

variable_types:
idx
unsigned char

variable_types:
v
unsigned char


decompiled_code:
__int64 __fastcall get_sin(char a1)
{
return sin[a1 & 0xF];
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return sin[a1 & 0xF];
}

original_code:
static inline uint8_t get_sin(const uint8_t idx)
{
 return sin[idx%(sizeof((sin))/sizeof(*(sin)))];
}

canonical_original_code:
static inline unsigned char get_sin(unsigned char idx)
{
 return sin[idx%(sizeof((sin))/sizeof(*(sin)))];
}


decompiled_code:
__int64 next_rnd()
{
rnd_0 = (2 * rnd_0) | (((int)(unsigned __int16)rnd_0 >> 10) ^ ((int)(unsigned __int16)rnd_0 >> 13)) & 3;
return get_sin(rnd_0);
}

original_code:
static inline uint8_t next_rnd()
{
 static unsigned short rnd = 13373;
 const uint8_t f1 = (rnd&(3<<13))>>13;
 const uint8_t f2 = (rnd&(3<<10))>>10;
 rnd <<=1;
 rnd |= f1^f2;
 return get_sin(rnd);
}

canonical_original_code:
static inline unsigned char next_rnd()
{
 static unsigned short rnd = 13373;
 unsigned char f1 = (rnd&(3<<13))>>13;
 unsigned char f2 = (rnd&(3<<10))>>10;
 rnd <<=1;
 rnd |= f1^f2;
 return get_sin(rnd);
}

variable_types:
rnd
unsigned short


original_code:
uint8_t next_sample()
{
static uint16_t t=0;
static uint8_t timer =0;
static uint8_t barevent=0;
static uint8_t bars=0;
static uint8_t pc = 0;
static uint8_t arpeggiocnt = 1;
static uint16_t next_sin_time = 0;
static uint8_t current_tone = 25;
static uint8_t current_tone_base = 25;
static unsigned short snaredelay = 0;
static unsigned short bassdelay = 0;
static uint8_t synth1 = 0;
static uint8_t synth2 = 0;
static uint8_t sin_speed = 4;
static uint8_t note_rep_cnt = 0;
if(t%128 == 0)
{
 if(t==0) timer = 0;
 else ++timer;
 barevent |= 64;
 if(timer%2 == 0) barevent |= 32;
 if(timer%4 == 0) barevent |= 16;
 if(timer%8 == 0) barevent |= 8;
 if(timer%16 == 0) barevent |= 4;
 if(timer%32 == 0) barevent |= 2;
 if(timer%64 == 0) barevent |= 1;
}
else barevent = 0;
if(barevent & 8)
{
 if(note_rep_cnt == (current_tone>>5))
 {
  note_rep_cnt = 0;
  current_tone = current_tone_base = next_note();
 }
 else ++note_rep_cnt;
 if(current_tone&~((0x40)|(0x80)) != 25)
  next_sin_time = t + octave_delay[current_tone&~((0x40)|(0x80))];
 else
  next_sin_time = 0;
}
if(barevent & 1) ++bars;
if(bars % 16 == 0)
{
 ++pc;
 if(pc == (4))
  pc = 0;
}
static uint8_t synthold1 = 0;
static uint8_t synthold2 = 0;
synthold2 = synthold1;
synthold1 = synth1;
synth1 = 0xfff0 & ( (t&t>>(synth[pc].a)) + (~t&t>>(synth[pc].b)) );
if(t == next_sin_time)
{
 if((current_tone&~((0x40)|(0x80))) != 25)
 {
   next_sin_time += octave_delay[current_tone&~((0x40)|(0x80))];
  synth2 = ~synth2;
 }
 else synth2 = 0;
}
unsigned int mix = (synth1>>1) + (synth2>>1);
if(barevent & 8 && snare[pc]) snaredelay = 200;
else if(snaredelay > 0) --snaredelay;
if(snaredelay>0) mix ^= (next_rnd() & 7) << 3;
if(barevent & 4 && bassdrum[pc]) bassdelay = 800;
else if(bassdelay > 0) --bassdelay;
if(bassdelay>0) mix = get_sin(t>>7);
++t;
return mix;
}

canonical_original_code:
unsigned char next_sample()
{
static unsigned short t = 0;
static unsigned char timer = 0;
static unsigned char barevent = 0;
static unsigned char bars = 0;
static unsigned char pc = 0;
static unsigned char arpeggiocnt = 1;
static unsigned short next_sin_time = 0;
static unsigned char current_tone = 25;
static unsigned char current_tone_base = 25;
static unsigned short snaredelay = 0;
static unsigned short bassdelay = 0;
static unsigned char synth1 = 0;
static unsigned char synth2 = 0;
static unsigned char sin_speed = 4;
static unsigned char note_rep_cnt = 0;
if(t%128 == 0)
{
 if(t==0) timer = 0;
 else ++timer;
 barevent |= 64;
 if(timer%2 == 0) barevent |= 32;
 if(timer%4 == 0) barevent |= 16;
 if(timer%8 == 0) barevent |= 8;
 if(timer%16 == 0) barevent |= 4;
 if(timer%32 == 0) barevent |= 2;
 if(timer%64 == 0) barevent |= 1;
}
else barevent = 0;
if(barevent & 8)
{
 if(note_rep_cnt == (current_tone>>5))
 {
  note_rep_cnt = 0;
  current_tone = current_tone_base = next_note();
 }
 else ++note_rep_cnt;
 if(current_tone&~((0x40)|(0x80)) != 25)
  next_sin_time = t + octave_delay[current_tone&~((0x40)|(0x80))];
 else
  next_sin_time = 0;
}
if(barevent & 1) ++bars;
if(bars % 16 == 0)
{
 ++pc;
 if(pc == (4))
  pc = 0;
}
static unsigned char synthold1 = 0;
static unsigned char synthold2 = 0;
synthold2 = synthold1;
synthold1 = synth1;
synth1 = 0xfff0 & ( (t&t>>(synth[pc].a)) + (~t&t>>(synth[pc].b)) );
if(t == next_sin_time)
{
 if((current_tone&~((0x40)|(0x80))) != 25)
 {
   next_sin_time += octave_delay[current_tone&~((0x40)|(0x80))];
  synth2 = ~synth2;
 }
 else synth2 = 0;
}
unsigned int mix = (synth1>>1) + (synth2>>1);
if(barevent & 8 && snare[pc]) snaredelay = 200;
else if(snaredelay > 0) --snaredelay;
if(snaredelay>0) mix ^= (next_rnd() & 7) << 3;
if(barevent & 4 && bassdrum[pc]) bassdelay = 800;
else if(bassdelay > 0) --bassdelay;
if(bassdelay>0) mix = get_sin(t>>7);
++t;
return mix;
}

variable_types:
t
unsigned short

variable_types:
timer
unsigned char

variable_types:
barevent
unsigned char

variable_types:
bars
unsigned char

variable_types:
pc
unsigned char

variable_types:
arpeggiocnt
unsigned char

variable_types:
snaredelay
unsigned short

variable_types:
bassdelay
unsigned short

variable_types:
mix
unsigned int


receiveData

decompiled_code:
unsigned int __fastcall receiveData(unsigned int a1)
{
unsigned int v1; // ebx
unsigned int result; // eax

v1 = 5;
printf("Wakeup by signal: %d from kernel\n", a1);
puts("Process will exit after 5 seconds...");
do
{
printf("%d\n", v1);
result = sleep(1u);
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func7(unsigned int a1)
{
unsigned int v1; // ebx
unsigned int result; // eax

v1 = 5;
printf("Wakeup by signal: %d from kernel\n", a1);
puts("Process will exit after 5 seconds...");
do
{
printf("%d\n", v1);
result = sleep(1u);
--v1;
}
while ( v1 );
return result;
}

original_code:
void receiveData(int n, siginfo_t *info, void* unused) {
    printf("Wakeup by signal: %d from kernel\n", n);
    printf("Process will exit after 5 seconds...\n");
    int i = 5;
    for(i = 5; i > 0; --i) {
        printf("%d\n", i);
        sleep(1);
    }
}

canonical_original_code:
void receiveData(int n, struct siginfo_t *info, void *unused) {
    printf("Wakeup by signal: %d from kernel\n", n);
    printf("Process will exit after 5 seconds...\n");
    int i = 5;
    for(i = 5; i > 0; --i) {
        printf("%d\n", i);
        sleep(1);
    }
}

variable_types: n int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
unused
void *

variable_types: i int

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct sigaction v4; // [rsp+0h] [rbp-A8h] BYREF

v4.sa_handler = (__sighandler_t)receiveData;
v4.sa_flags = 4;
sigaction(10, &v4, 0LL);
puts("Start to wait a signal...");
sleep(0x258u);
return 0;
}

original_code:
int main() {
    struct sigaction sig;
    sig.__sigaction_handler.sa_sigaction = receiveData;
    sig.sa_flags = 4;
    sigaction(10, &sig, ((void *)0));
    printf("Start to wait a signal...\n");
    sleep(600);
 return 0;
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }


repo: heckendorfc/cobra

decompiled_code:
__int64 __fastcall run_test(__int64 a1)
{
int v1; // ebp
void (__fastcall *v2)(_QWORD); // rax
void (__fastcall *v3)(_QWORD); // rax
unsigned int v4; // eax
unsigned int v5; // edx
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

v1 = 10;
*(_QWORD *)(a1 + 48) = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 56) = 0;
do
{
v2 = *(void (__fastcall **)(_QWORD))(a1 + 16);
if ( v2 )
v2(*(_QWORD *)(a1 + 40));
gettimeofday(&v7, 0LL);
(*(void (__fastcall **)(_QWORD))(a1 + 24))(*(_QWORD *)(a1 + 40));
gettimeofday(&tv, 0LL);
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(*(_QWORD *)(a1 + 40));
v4 = get_runtime_isra_0(v7.tv_sec, v7.tv_usec, tv.tv_sec, tv.tv_usec);
v5 = *(_DWORD *)(a1 + 56) + v4;
*(_DWORD *)(a1 + 56) = v5;
if ( *(_DWORD *)(a1 + 52) < v4 )
*(_DWORD *)(a1 + 52) = v4;
if ( *(_DWORD *)(a1 + 48) > v4 )
*(_DWORD *)(a1 + 48) = v4;
--v1;
}
while ( v1 );
result = 3435973837LL;
*(_DWORD *)(a1 + 56) = v5 / 0xA;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebp
void (__fastcall *v2)(_QWORD); // rax
void (__fastcall *v3)(_QWORD); // rax
unsigned int v4; // eax
unsigned int v5; // edx
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

v1 = 10;
*(_QWORD *)(a1 + 48) = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 56) = 0;
do
{
v2 = *(void (__fastcall **)(_QWORD))(a1 + 16);
if ( v2 )
v2(*(_QWORD *)(a1 + 40));
gettimeofday(&v7, 0LL);
(*(void (__fastcall **)(_QWORD))(a1 + 24))(*(_QWORD *)(a1 + 40));
gettimeofday(&tv, 0LL);
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(*(_QWORD *)(a1 + 40));
v4 = func1(v7.tv_sec, v7.tv_usec, tv.tv_sec, tv.tv_usec);
v5 = *(_DWORD *)(a1 + 56) + v4;
*(_DWORD *)(a1 + 56) = v5;
if ( *(_DWORD *)(a1 + 52) < v4 )
*(_DWORD *)(a1 + 52) = v4;
if ( *(_DWORD *)(a1 + 48) > v4 )
*(_DWORD *)(a1 + 48) = v4;
--v1;
}
while ( v1 );
result = 3435973837LL;
*(_DWORD *)(a1 + 56) = v5 / 0xA;
return result;
}

original_code:
void run_test(struct test *t){
 const int numruns=10;
 struct timeval start;
 struct timeval end;
 int i;
 unsigned int runtime;
 t->min=(0x7fffffff * 2U + 1U);
 t->max=0;
 t->avg=0;
 for(i=0;i<numruns;i++){
  if(t->pref)
   t->pref(t->arg);
  gettimeofday(&start,((void *)0));
  t->f(t->arg);
  gettimeofday(&end,((void *)0));
  if(t->postf)
   t->postf(t->arg);
  runtime=get_runtime(&start,&end);
  t->avg+=runtime;
  if(runtime>t->max)
   t->max=runtime;
  if(runtime<t->min)
   t->min=runtime;
 }
 t->avg/=numruns;
}

canonical_original_code:
void run_test(struct test *t){
 int numruns = 10;
 struct timeval start;
 struct timeval end;
 int i;
 unsigned int runtime;
 t->min=(0x7fffffff * 2U + 1U);
 t->max=0;
 t->avg=0;
 for(i=0;i<numruns;i++){
  if(t->pref)
   t->pref(t->arg);
  gettimeofday(&start,((void *)0));
  t->f(t->arg);
  gettimeofday(&end,((void *)0));
  if(t->postf)
   t->postf(t->arg);
  runtime=get_runtime(&start,&end);
  t->avg+=runtime;
  if(runtime>t->max)
   t->max=runtime;
  if(runtime<t->min)
   t->min=runtime;
 }
 t->avg/=numruns;
}

variable_types: struct test { struct test *next; char *name; void (*pref)(void *); void (*f)(void *); void (*postf)(void *); void *arg; unsigned int min; unsigned int max; unsigned int avg; } *

variable_types: numruns int

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

variable_types:
runtime
unsigned int


decompiled_code:
__int64 __fastcall bench_run(__int64 ***a1)
{
__int64 **i; // rbp
__int64 **j; // rbx

for ( i = *a1; i; i = (__int64 **)*i )
{
printf("Running group: %s\n", (const char *)i[1]);
for ( j = (__int64 **)i[2]; j; j = (__int64 **)*j )
{
printf("\tRunning test: %s\n", (const char *)j[1]);
run_test(j);
}
}
puts("\n");
return print_table(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 ***a1)
{
__int64 **i; // rbp
__int64 **j; // rbx

for ( i = *a1; i; i = (__int64 **)*i )
{
printf("Running group: %s\n", (const char *)i[1]);
for ( j = (__int64 **)i[2]; j; j = (__int64 **)*j )
{
printf("\tRunning test: %s\n", (const char *)j[1]);
run_test(j);
}
}
puts("\n");
return print_table(a1);
}

original_code:
void bench_run(BenchSet *bs){
 struct testgroup *tgp;
 struct test *tp;
 for(tgp=bs->list;tgp;tgp=tgp->next){
  printf("Running group: %s\n",tgp->name);
  for(tp=tgp->list;tp;tp=tp->next){
   printf("\tRunning test: %s\n",tp->name);
   run_test(tp);
  }
 }
 printf("\n\n");
 print_table(bs);
}

canonical_original_code:
void bench_run(struct BenchSet *bs){
 struct testgroup *tgp;
 struct test *tp;
 for(tgp=bs->list;tgp;tgp=tgp->next){
  printf("Running group: %s\n",tgp->name);
  for(tp=tgp->list;tp;tp=tp->next){
   printf("\tRunning test: %s\n",tp->name);
   run_test(tp);
  }
 }
 printf("\n\n");
 print_table(bs);
}

variable_types: struct BenchSet { struct testgroup { struct testgroup *next; char *name; struct test { struct test *next; char *name; void (*pref)(void *); void (*f)(void *); void (*postf)(void *); void *arg; unsigned int min; unsigned int max; unsigned int avg; } *list; } *list; } *

user_defined_types: struct BenchSet { struct testgroup *list; }

user_defined_types: struct testgroup { struct testgroup *next; char *name; struct test *list; }


decompiled_code:
void bench_free()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void bench_free(BenchSet *bs){
}

canonical_original_code:
void bench_free(struct BenchSet *bs){
}

user_defined_types: struct test { struct test *next; char *name; void (*pref)(void *); void (*f)(void *); void (*postf)(void *); void *arg; unsigned int min; unsigned int max; unsigned int avg; }


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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void Token_destroy(Token *token)
{
    if (token != ((void *)0)) {
        if (token->value != ((void *)0)) {
            free(token->value);
            token->value = ((void *)0);
        }
        free(token);
        token = ((void *)0);
    }
}

canonical_original_code:
void Token_destroy(struct Token *token)
{
    if (token != ((void *)0)) {
        if (token->value != ((void *)0)) {
            free(token->value);
            token->value = ((void *)0);
        }
        free(token);
        token = ((void *)0);
    }
}

variable_types: struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *

user_defined_types: struct Token { char *value; unsigned int begin; enum TOKEN_TYPE type; }


decompiled_code:
int init_terminal()
{
int v0; // eax
int v1; // eax

v0 = fileno(stdin);
tcgetattr(v0, &orig_term_attr);
*(_QWORD *)&raw_term_attr.c_cc[31] = *(_QWORD *)&orig_term_attr.c_cc[31];
*(__m128i *)&raw_term_attr.c_iflag = _mm_load_si128((const __m128i *)&orig_term_attr);
raw_term_attr.c_lflag &= 0xFFFFFDFF;
raw_term_attr.c_ospeed = orig_term_attr.c_ospeed;
*(__m128i *)&raw_term_attr.c_line = _mm_load_si128((const __m128i *)&orig_term_attr.c_line);
*(__m128i *)&raw_term_attr.c_cc[15] = _mm_load_si128((const __m128i *)&orig_term_attr.c_cc[15]);
v1 = fileno(stdin);
return tcsetattr(v1, 0, &raw_term_attr);
}

canonical_decompiled_code:
int func0()
{
int v0; // eax
int v1; // eax

v0 = fileno(stdin);
tcgetattr(v0, &orig_term_attr);
*(_QWORD *)&raw_term_attr.c_cc[31] = *(_QWORD *)&orig_term_attr.c_cc[31];
*(__m128i *)&raw_term_attr.c_iflag = _mm_load_si128((const __m128i *)&orig_term_attr);
raw_term_attr.c_lflag &= 0xFFFFFDFF;
raw_term_attr.c_ospeed = orig_term_attr.c_ospeed;
*(__m128i *)&raw_term_attr.c_line = _mm_load_si128((const __m128i *)&orig_term_attr.c_line);
*(__m128i *)&raw_term_attr.c_cc[15] = _mm_load_si128((const __m128i *)&orig_term_attr.c_cc[15]);
v1 = fileno(stdin);
return tcsetattr(v1, 0, &raw_term_attr);
}

original_code:
static void init_terminal(void)
{
    tcgetattr(fileno(stdin), &orig_term_attr);
    raw_term_attr = orig_term_attr;
    raw_term_attr.c_lflag &= (unsigned int) ~(0001000);
    tcsetattr(fileno(stdin), 0, &raw_term_attr);
}

canonical_original_code:
static void init_terminal()
{
    tcgetattr(fileno(stdin), &orig_term_attr);
    raw_term_attr = orig_term_attr;
    raw_term_attr.c_lflag &= (unsigned int) ~(0001000);
    tcsetattr(fileno(stdin), 0, &raw_term_attr);
}


decompiled_code:
int reset_terminal()
{
int v0; // eax

v0 = fileno(stdin);
return tcsetattr(v0, 0, &orig_term_attr);
}

canonical_decompiled_code:
int func1()
{
int v0; // eax

v0 = fileno(stdin);
return tcsetattr(v0, 0, &orig_term_attr);
}

original_code:
static void reset_terminal(void)
{
    tcsetattr(fileno(stdin), 0, &orig_term_attr);
}

canonical_original_code:
static void reset_terminal()
{
    tcsetattr(fileno(stdin), 0, &orig_term_attr);
}


decompiled_code:
__int64 command_unknown()
{
return IO_write("command not found\n");
}

canonical_decompiled_code:
__int64 func3()
{
return IO_write("command not found\n");
}

original_code:
static void command_unknown(void)
{
    IO_write("command not found\n");
}

canonical_original_code:
static void command_unknown()
{
    IO_write("command not found\n");
}


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

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

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

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

original_code:
void State_destroy(State *state)
{
    if (state != ((void *)0)) {
        if (state->transitions != ((void *)0)) {
            free(state->transitions);
            state->transitions = ((void *)0);
        }
        free(state);
        state = ((void *)0);
    }
}

canonical_original_code:
void State_destroy(struct State *state)
{
    if (state != ((void *)0)) {
        if (state->transitions != ((void *)0)) {
            free(state->transitions);
            state->transitions = ((void *)0);
        }
        free(state);
        state = ((void *)0);
    }
}

variable_types: struct State { unsigned long transition_count; unsigned int *transitions; } *


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

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

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

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

original_code:
void DFA_destroy(DFA *dfa)
{
    if (dfa != ((void *)0)) {
        if (dfa->states != ((void *)0)) {
            free(dfa->states);
            dfa->states = ((void *)0);
        }
        free(dfa);
        dfa = ((void *)0);
    }
}

canonical_original_code:
void DFA_destroy(struct DFA *dfa)
{
    if (dfa != ((void *)0)) {
        if (dfa->states != ((void *)0)) {
            free(dfa->states);
            dfa->states = ((void *)0);
        }
        free(dfa);
        dfa = ((void *)0);
    }
}

variable_types: struct DFA { unsigned long symbol_count; char **symbols; struct State { unsigned long transition_count; unsigned int *transitions; } *states; unsigned int *terminal_states; } *

user_defined_types: struct DFA { unsigned long symbol_count; char **symbols; struct State *states; unsigned int *terminal_states; }


original_code:
void DFA_set_state(DFA *dfa,
                   const unsigned int state_index,
                   const State *state)
{
    if (dfa == ((void *)0)
        || state_index >= dfa->state_count
        || state == ((void *)0)
        || state->transitions == ((void *)0)
    ) {
        return;
    }
    dfa->states[state_index].transition_count = state->transition_count;
    dfa->states[state_index].transitions = state->transitions;
}

canonical_original_code:
void DFA_set_state(struct DFA *dfa, unsigned int state_index, struct State *state)
{
    if (dfa == ((void *)0)
        || state_index >= dfa->state_count
        || state == ((void *)0)
        || state->transitions == ((void *)0)
    ) {
        return;
    }
    dfa->states[state_index].transition_count = state->transition_count;
    dfa->states[state_index].transitions = state->transitions;
}

variable_types:
state
struct State *

user_defined_types: struct State { unsigned long transition_count; unsigned int *transitions; }


original_code:
void DFA_to_string(DFA *dfa)
{
    char temp[128];
    temp[0] = '\0';
    sprintf(temp, "%-2u", dfa->state_count);
    size_t row_length, column_offset;
    row_length = 0;
    column_offset = strlen(temp) + 1;
    printf("%*s| ",
           column_offset,
           "");
    unsigned int i;
    for (i = 0; i < dfa->symbol_count; ++i) {
        printf("%s   ", dfa->symbols[i]);
        size_t padding;
        padding = (i != (dfa->symbol_count - 1)) ? 3 : 1;
        row_length += strlen(dfa->symbols[i]) + padding;
    }
    printf("\n");
    for (i = 0; i < column_offset; ++i) {
        printf("-");
    }
    printf("+-");
    for (i = 0; i < row_length; ++i) {
        printf("-");
    }
    printf("\n");
    if (dfa->states == ((void *)0)) {
        return;
    }
    for (i = 0; i < dfa->state_count; ++i) {
        printf("%-*u| ",
               column_offset,
               i);
        unsigned int j;
        for (j = 0; j < dfa->states[i].transition_count; ++j) {
            if (dfa->states[i].transitions != ((void *)0) && dfa->symbols[j] != ((void *)0)) {
                printf("%u %*s",
                       dfa->states[i].transitions[j],
                       strlen(dfa->symbols[j]) + 1,
                       "");
            }
        }
        printf("\n");
    }
    printf("\n");
}

canonical_original_code:
void DFA_to_string(struct DFA *dfa)
{
    char temp[128];
    temp[0] = '\0';
    sprintf(temp, "%-2u", dfa->state_count);
    unsigned long row_length; unsigned long column_offset;
    row_length = 0;
    column_offset = strlen(temp) + 1;
    printf("%*s| ",
           column_offset,
           "");
    unsigned int i;
    for (i = 0; i < dfa->symbol_count; ++i) {
        printf("%s   ", dfa->symbols[i]);
        unsigned long padding;
        padding = (i != (dfa->symbol_count - 1)) ? 3 : 1;
        row_length += strlen(dfa->symbols[i]) + padding;
    }
    printf("\n");
    for (i = 0; i < column_offset; ++i) {
        printf("-");
    }
    printf("+-");
    for (i = 0; i < row_length; ++i) {
        printf("-");
    }
    printf("\n");
    if (dfa->states == ((void *)0)) {
        return;
    }
    for (i = 0; i < dfa->state_count; ++i) {
        printf("%-*u| ",
               column_offset,
               i);
        unsigned int j;
        for (j = 0; j < dfa->states[i].transition_count; ++j) {
            if (dfa->states[i].transitions != ((void *)0) && dfa->symbols[j] != ((void *)0)) {
                printf("%u %*s",
                       dfa->states[i].transitions[j],
                       strlen(dfa->symbols[j]) + 1,
                       "");
            }
        }
        printf("\n");
    }
    printf("\n");
}

variable_types:
temp
char [128]

variable_types:
i
unsigned int

variable_types:
padding
unsigned long

variable_types:
j
unsigned int


original_code:
static void clear_data(Lexer *lexer)
{
    if (lexer == ((void *)0) || lexer->tokens == ((void *)0)) {
        return;
    }
    unsigned int i;
    for (i = 0; i < lexer->token_count; ++i) {
        if (lexer->tokens[i].value != ((void *)0)) {
            free(lexer->tokens[i].value);
            lexer->tokens[i].value = ((void *)0);
        }
    }
    free(lexer->tokens);
    lexer->tokens = ((void *)0);
    lexer->token_count = 0;
}

canonical_original_code:
static void clear_data(struct Lexer *lexer)
{
    if (lexer == ((void *)0) || lexer->tokens == ((void *)0)) {
        return;
    }
    unsigned int i;
    for (i = 0; i < lexer->token_count; ++i) {
        if (lexer->tokens[i].value != ((void *)0)) {
            free(lexer->tokens[i].value);
            lexer->tokens[i].value = ((void *)0);
        }
    }
    free(lexer->tokens);
    lexer->tokens = ((void *)0);
    lexer->token_count = 0;
}

variable_types: struct Lexer { struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *tokens; unsigned long token_count; } *

user_defined_types: struct Lexer { struct Token *tokens; unsigned long token_count; }


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

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

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

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

original_code:
Lexer *Lexer_create(void)
{
    Lexer *lexer = malloc(sizeof(Lexer));
    if (lexer != ((void *)0)) {
        lexer->tokens = ((void *)0);
        lexer->token_count = 0;
    }
    return lexer;
}

canonical_original_code:
struct Lexer *Lexer_create()
{
    struct Lexer *lexer = malloc(sizeof(Lexer));
    if (lexer != ((void *)0)) {
        lexer->tokens = ((void *)0);
        lexer->token_count = 0;
    }
    return lexer;
}

return_type: struct Lexer { struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *tokens; unsigned long token_count; } *


decompiled_code:
void __fastcall Lexer_destroy(void *ptr)
{
if ( ptr )
{
clear_data((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
func0((__int64)ptr);
free(ptr);
}
}

original_code:
void Lexer_destroy(Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return;
    }
    clear_data(lexer);
    free(lexer);
    lexer = ((void *)0);
}

canonical_original_code:
void Lexer_destroy(struct Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return;
    }
    clear_data(lexer);
    free(lexer);
    lexer = ((void *)0);
}

user_defined_types: enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 }


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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
Token *Lexer_get_tokens(Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return ((void *)0);
    }
    return lexer->tokens;
}

canonical_original_code:
struct Token *Lexer_get_tokens(struct Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return ((void *)0);
    }
    return lexer->tokens;
}

variable_types: struct Lexer { struct Token *tokens; unsigned long token_count; } *

return_type: struct Token { char *value; unsigned int begin; enum TOKEN_TYPE { TOKEN_UNKNOWN=0, TOKEN_SYMBOL=1, TOKEN_LITERAL=2, TOKEN_ESCAPE_CHAR=3 } type; } *


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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
size_t Lexer_get_token_count(Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return 0;
    }
    return lexer->token_count;
}

canonical_original_code:
unsigned long Lexer_get_token_count(struct Lexer *lexer)
{
    if (lexer == ((void *)0)) {
        return 0;
    }
    return lexer->token_count;
}

return_type: unsigned long


decompiled_code:
void __fastcall Node_destroy(void *ptr, void (*a2)(void))
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
a2();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, void (*a2)(void))
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
a2();
free(ptr);
}
}

original_code:
void Node_destroy(Node *node, Destructor destructor)
{
    if (node != ((void *)0)) {
        if (node->data != ((void *)0)) {
            destructor(node->data);
        }
        free(node);
        node = ((void *)0);
    }
}

canonical_original_code:
void Node_destroy(struct Node *node, void (*destructor)(void *object))
{
    if (node != ((void *)0)) {
        if (node->data != ((void *)0)) {
            destructor(node->data);
        }
        free(node);
        node = ((void *)0);
    }
}

variable_types: struct Node { struct Node *next; void *data; } *

variable_types:
destructor
void (*)(void *object)


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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

original_code:
List *List_create(void)
{
    List *list = malloc(sizeof(List));
    if (list != ((void *)0)) {
        list->head = ((void *)0);
    }
    return list;
}

canonical_original_code:
struct List *List_create()
{
    struct List *list = malloc(sizeof(List));
    if (list != ((void *)0)) {
        list->head = ((void *)0);
    }
    return list;
}

variable_types: struct List { struct Node { struct Node *next; void *data; } *head; } *


decompiled_code:
void __fastcall List_destroy(void *ptr, void (*a2)(void))
{
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
v3 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
Node_destroy(v4, a2);
*(_QWORD *)ptr = v3;
}
while ( v3 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, void (*a2)(void))
{
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
v3 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
func0(v4, a2);
*(_QWORD *)ptr = v3;
}
while ( v3 );
}
free(ptr);
}
}

original_code:
void List_destroy(List *list, Destructor destructor)
{
    if (list != ((void *)0)) {
        while (list->head != ((void *)0)) {
            Node *n = list->head->next;
            Node_destroy(list->head, destructor);
            list->head = n;
        }
        free(list);
        list = ((void *)0);
    }
}

canonical_original_code:
void List_destroy(struct List *list, void (*destructor)(void *object))
{
    if (list != ((void *)0)) {
        while (list->head != ((void *)0)) {
            struct Node *n = list->head->next;
            Node_destroy(list->head, destructor);
            list->head = n;
        }
        free(list);
        list = ((void *)0);
    }
}

user_defined_types: struct Node { struct Node *next; void *data; }


decompiled_code:
void __fastcall List_push_back(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rax
__int64 v4; // rdx

if ( a1 )
{
if ( a2 )
{
v2 = Node_create(a2);
if ( v2 )
{
if ( *a1 )
{
v3 = end(*a1);
*v3 = v4;
}
else
{
*a1 = v2;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rax
__int64 v4; // rdx

if ( a1 )
{
if ( a2 )
{
v2 = Node_create(a2);
if ( v2 )
{
if ( *a1 )
{
v3 = end(*a1);
*v3 = v4;
}
else
{
*a1 = v2;
}
}
}
}
}

original_code:
void List_push_back(List *l, void *data)
{
    if (l == ((void *)0) || data == ((void *)0)) {
        return;
    }
    Node *n;
    n = Node_create(data);
    if (n == ((void *)0)) {
        return;
    }
    if (l->head == ((void *)0)) {
        l->head = n;
        return;
    }
    end(l->head)->next = n;
}

canonical_original_code:
void List_push_back(struct List *l, void *data)
{
    if (l == ((void *)0) || data == ((void *)0)) {
        return;
    }
    struct Node *n;
    n = Node_create(data);
    if (n == ((void *)0)) {
        return;
    }
    if (l->head == ((void *)0)) {
        l->head = n;
        return;
    }
    end(l->head)->next = n;
}

variable_types:
data
void *


decompiled_code:
void __fastcall clear_buffer(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
static void clear_buffer(char *buffer)
{
    if (buffer != ((void *)0)) {
        free(buffer);
        buffer = ((void *)0);
    }
}

variable_types:
buffer
char *


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

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

original_code:
void IO_destroy(IO *io)
{
    if (io != ((void *)0)) {
        clear_buffer(io->buffer);
        free(io);
        io = ((void *)0);
    }
}

canonical_original_code:
void IO_destroy(struct IO *io)
{
    if (io != ((void *)0)) {
        clear_buffer(io->buffer);
        free(io);
        io = ((void *)0);
    }
}

variable_types: struct IO { char *buffer; char *prompt; } *


decompiled_code:
char *__fastcall IO_read(char **lineptr, const char *a2)
{
char *v2; // r12
char *v3; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !lineptr )
return 0LL;
if ( !a2 )
a2 = lineptr[1];
printf("%s", a2);
clear_buffer(*lineptr);
n[0] = 0LL;
if ( getline(lineptr, n, stdin) == -1 )
return 0LL;
v2 = *lineptr;
v3 = &v2[strlen(*lineptr) - 1];
if ( *v3 == 10 )
{
*v3 = 0;
v2 = *lineptr;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(char **lineptr, const char *a2)
{
char *v2; // r12
char *v3; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !lineptr )
return 0LL;
if ( !a2 )
a2 = lineptr[1];
printf("%s", a2);
func0(*lineptr);
n[0] = 0LL;
if ( getline(lineptr, n, stdin) == -1 )
return 0LL;
v2 = *lineptr;
v3 = &v2[strlen(*lineptr) - 1];
if ( *v3 == 10 )
{
*v3 = 0;
v2 = *lineptr;
}
return v2;
}

original_code:
const char *IO_read(IO *io, const char *prompt)
{
    if (io == ((void *)0)) {
        return ((void *)0);
    }
    if (prompt != ((void *)0)) {
        printf("%s", prompt);
    }
    else {
        printf("%s", io->prompt);
    }
    clear_buffer(io->buffer);
    size_t size;
    size = 0;
    if (getline(&io->buffer, &size, stdin) == -1) {
        return ((void *)0);
    }
    size_t buffer_length = strlen(io->buffer);
    if (io->buffer[buffer_length - 1] == '\n') {
        io->buffer[buffer_length - 1] = '\0';
    }
    return io->buffer;
}

canonical_original_code:
char *IO_read(struct IO *io, char *prompt)
{
    if (io == ((void *)0)) {
        return ((void *)0);
    }
    if (prompt != ((void *)0)) {
        printf("%s", prompt);
    }
    else {
        printf("%s", io->prompt);
    }
    clear_buffer(io->buffer);
    unsigned long size;
    size = 0;
    if (getline(&io->buffer, &size, stdin) == -1) {
        return ((void *)0);
    }
    unsigned long buffer_length = strlen(io->buffer);
    if (io->buffer[buffer_length - 1] == '\n') {
        io->buffer[buffer_length - 1] = '\0';
    }
    return io->buffer;
}

variable_types:
prompt
char *

variable_types:
size
unsigned long

return_type: char *

user_defined_types: struct IO { char *buffer; char *prompt; }


decompiled_code:
int IO_write(const char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 )
{
va_start(arg, a1);
result = vprintf(a1, arg);
}
return result;
}

canonical_decompiled_code:
int func3(const char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 )
{
va_start(arg, a1);
result = vprintf(a1, arg);
}
return result;
}

original_code:
void IO_write(const char *format, ...)
{
    if (format == ((void *)0)) {
        return;
    }
    va_list args;
    __builtin_va_start(args,format);
    vprintf(format, args);
    __builtin_va_end(args);
}

canonical_original_code:
void IO_write(char *format, ...)
{
    if (format == ((void *)0)) {
        return;
    }
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vprintf(format, args);
    __builtin_va_end(args);
}

variable_types:
format
char *


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
result = json_delete();
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
result = json_delete();
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


decompiled_code:
__int64 __fastcall write_response(void *src, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // r13
__int64 v6; // rdi
int v8; // ebp
__int64 result; // rax

v5 = a3 * a2;
v6 = *(int *)(a4 + 8);
if ( (unsigned __int64)(v6 + a3 * a2) > 0x3FFFE )
{
fwrite("error: too small buffer\n", 1uLL, 0x18uLL, stderr);
result = 0LL;
}
else
{
v8 = a3 * a2;
memcpy((void *)(*(_QWORD *)a4 + v6), src, a3 * a2);
*(_DWORD *)(a4 + 8) += v8;
result = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // r13
__int64 v6; // rdi
int v8; // ebp
__int64 result; // rax

v5 = a3 * a2;
v6 = *(int *)(a4 + 8);
if ( (unsigned __int64)(v6 + a3 * a2) > 0x3FFFE )
{
fwrite("error: too small buffer\n", 1uLL, 0x18uLL, stderr);
result = 0LL;
}
else
{
v8 = a3 * a2;
memcpy((void *)(*(_QWORD *)a4 + v6), src, a3 * a2);
*(_DWORD *)(a4 + 8) += v8;
result = v5;
}
return result;
}

original_code:
static size_t write_response(void *ptr, size_t size, size_t nmemb, void *stream)
{
 struct write_result *result = (struct write_result *)stream;
 if(result->pos + size * nmemb >= (256 * 1024) - 1)
 {
  fprintf(stderr, "error: too small buffer\n");
  return 0;
 }
 memcpy(result->data + result->pos, ptr, size * nmemb);
 result->pos += size * nmemb;
 return size * nmemb;
}

canonical_original_code:
static unsigned long write_response(void *ptr, unsigned long size, unsigned long nmemb, void *stream)
{
 struct write_result *result = (struct write_result *)stream;
 if(result->pos + size * nmemb >= (256 * 1024) - 1)
 {
  fprintf(stderr, "error: too small buffer\n");
  return 0;
 }
 memcpy(result->data + result->pos, ptr, size * nmemb);
 result->pos += size * nmemb;
 return size * nmemb;
}

variable_types:
ptr
void *

variable_types:
nmemb
unsigned long

variable_types:
stream
void *

variable_types: struct write_result { char *data; int pos; } *


decompiled_code:
void topology_discovery()
{
_BYTE *v0; // rax
void *v1; // rbp
__int128 v2[2]; // [rsp+0h] [rbp-108h] BYREF
char v3[16]; // [rsp+20h] [rbp-E8h] BYREF

strcpy(v3, "y/links/json");
v2[0] = (__int128)_mm_load_si128((const __m128i *)&LC31);
v2[1] = (__int128)_mm_load_si128((const __m128i *)&LC32);
v0 = request((const char *)v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)parse_topology((__int64)v0) )
{
puts("\n Error in parsing topology");
exit(0);
}
free(v1);
}

canonical_decompiled_code:
void func4()
{
_BYTE *v0; // rax
void *v1; // rbp
__int128 v2[2]; // [rsp+0h] [rbp-108h] BYREF
char v3[16]; // [rsp+20h] [rbp-E8h] BYREF

strcpy(v3, "y/links/json");
v2[0] = (__int128)_mm_load_si128((const __m128i *)&LC31);
v2[1] = (__int128)_mm_load_si128((const __m128i *)&LC32);
v0 = request((const char *)v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)func2((__int64)v0) )
{
puts("\n Error in parsing topology");
exit(0);
}
free(v1);
}

original_code:
void topology_discovery(void) {
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/topology/links/json");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_topology(text);
 if(result != 0){
  printf("\n Error in parsing topology\n");
  exit(0);
 }
 free(text);
}

canonical_original_code:
void topology_discovery() {
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/topology/links/json");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_topology(text);
 if(result != 0){
  printf("\n Error in parsing topology\n");
  exit(0);
 }
 free(text);
}

variable_types: result int

variable_types:
text
char *

variable_types:
url
char [256]


decompiled_code:
void device_discovery()
{
_BYTE *v0; // rax
void *v1; // rbp
__int128 v2[2]; // [rsp+0h] [rbp-108h] BYREF
char v3; // [rsp+20h] [rbp-E8h]

v3 = 0;
v2[0] = (__int128)_mm_load_si128((const __m128i *)&LC31);
v2[1] = (__int128)_mm_load_si128((const __m128i *)&LC34);
v0 = request((const char *)v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)parse_device((__int64)v0) )
{
puts("\n Error in parsing device attachment point ");
exit(0);
}
free(v1);
}

canonical_decompiled_code:
void func5()
{
_BYTE *v0; // rax
void *v1; // rbp
__int128 v2[2]; // [rsp+0h] [rbp-108h] BYREF
char v3; // [rsp+20h] [rbp-E8h]

v3 = 0;
v2[0] = (__int128)_mm_load_si128((const __m128i *)&LC31);
v2[1] = (__int128)_mm_load_si128((const __m128i *)&LC34);
v0 = request((const char *)v2);
if ( !v0 )
{
puts("\n Error in CURL request");
exit(0);
}
v1 = v0;
if ( (unsigned int)func3((__int64)v0) )
{
puts("\n Error in parsing device attachment point ");
exit(0);
}
free(v1);
}

original_code:
void device_discovery(void){
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/device/");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_device(text);
 if(result != 0){
  printf("\n Error in parsing device attachment point \n");
  exit(0);
 }
 free(text);
}

canonical_original_code:
void device_discovery(){
 int result;
 char *text;
 char url[256];
 snprintf(url, 256, "http://localhost:8080/wm/device/");
 text = request(url);
 if(!text){
  printf("\n Error in CURL request\n");
  exit(0);
 }
 result = parse_device(text);
 if(result != 0){
  printf("\n Error in parsing device attachment point \n");
  exit(0);
 }
 free(text);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp

topology_discovery();
device_discovery();
dijkstra(0LL, argv);
v3 = (const char *)find_dpid(0LL);
printf(" DPID for ipv4: %s dpid - %s", 0LL, v3);
print_dijkstra(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp

func4();
func5();
dijkstra(0LL, argv);
v3 = (const char *)find_dpid(0LL);
printf(" DPID for ipv4: %s dpid - %s", 0LL, v3);
print_dijkstra(v3);
return 0;
}

original_code:
int main(int argc, char **argv){
 char *dp;
 char *ip;
 char *source;
 topology_discovery();
  device_discovery();
 dijkstra(source);
 dp = find_dpid(ip);
 printf(" DPID for ipv4: %s  dpid - %s",ip,dp);
 print_dijkstra(dp);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
dp
char *

variable_types:
ip
char *

variable_types:
source
char *


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

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

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

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

original_code:
topo_graph* graph_instance(void) {
        topo_graph *temp = (topo_graph *)malloc(sizeof(topo_graph));
        temp->sdpid = ((void *)0);
        temp->next_element = ((void *)0);
        temp->adjnode = ((void *)0);
        return temp;
}

canonical_original_code:
struct topo_graph *graph_instance() {
        struct topo_graph *temp = (topo_graph *)malloc(sizeof(topo_graph));
        temp->sdpid = ((void *)0);
        temp->next_element = ((void *)0);
        temp->adjnode = ((void *)0);
        return temp;
}

variable_types: struct topo_graph { char *sdpid; struct topo_graph *next_element; struct adj_node { char *ddpid; int w; int min; struct adj_node *next_adjnode; } *adjnode; } *

user_defined_types: struct topo_graph { char *sdpid; struct topo_graph *next_element; struct adj_node *adjnode; }


decompiled_code:
__int64 __fastcall print_graph(const char **a1)
{
const char **v1; // rbp
const char *i; // rbx
__int64 result; // rax

v1 = a1;
if ( *a1 )
{
do
{
for ( i = v1[2]; i; i = (const char *)*((_QWORD *)i + 2) )
printf("source - %s\tdestination - %s\tweight - %d\n", *v1, *(const char **)i, *((unsigned int *)i + 2));
v1 = (const char **)v1[1];
}
while ( v1 );
result = 0LL;
}
else
{
puts("\n GRAPH is EMPTY");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char **a1)
{
const char **v1; // rbp
const char *i; // rbx
__int64 result; // rax

v1 = a1;
if ( *a1 )
{
do
{
for ( i = v1[2]; i; i = (const char *)*((_QWORD *)i + 2) )
printf("source - %s\tdestination - %s\tweight - %d\n", *v1, *(const char **)i, *((unsigned int *)i + 2));
v1 = (const char **)v1[1];
}
while ( v1 );
result = 0LL;
}
else
{
puts("\n GRAPH is EMPTY");
result = 1LL;
}
return result;
}

original_code:
int print_graph(topo_graph *graph){
 topo_graph *temp1;
 temp1 = graph;
 if(temp1->sdpid == ((void *)0)) {
  printf("\n GRAPH is EMPTY\n");
  return 1;
 }
 else {
  while(temp1 != ((void *)0)){
   adj_node* temp2 = temp1->adjnode;
   while(temp2 != ((void *)0)){
    printf("source - %s	destination - %s	weight - %d\n",temp1->sdpid,temp2->ddpid,temp2->w);
    temp2= temp2->next_adjnode;
   }
   temp1 = temp1->next_element;
  }
 }
 return 0;
}

canonical_original_code:
int print_graph(struct topo_graph *graph){
 struct topo_graph *temp1;
 temp1 = graph;
 if(temp1->sdpid == ((void *)0)) {
  printf("\n GRAPH is EMPTY\n");
  return 1;
 }
 else {
  while(temp1 != ((void *)0)){
   struct adj_node *temp2 = temp1->adjnode;
   while(temp2 != ((void *)0)){
    printf("source - %s	destination - %s	weight - %d\n",temp1->sdpid,temp2->ddpid,temp2->w);
    temp2= temp2->next_adjnode;
   }
   temp1 = temp1->next_element;
  }
 }
 return 0;
}

variable_types: struct adj_node { char *ddpid; int w; int min; struct adj_node *next_adjnode; } *


decompiled_code:
void free_graph()
{
free(*((void **)graph + 2));
free(graph);
}

canonical_decompiled_code:
void func3()
{
free(*((void **)graph + 2));
free(graph);
}

original_code:
void free_graph(void){
 free(graph->adjnode);
 free(graph);
}

canonical_original_code:
void free_graph(){
 free(graph->adjnode);
 free(graph);
}


decompiled_code:
__int64 __fastcall num_switches(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // edx

result = (unsigned int)count;
if ( a1 )
{
v2 = count + 1;
do
{
a1 = *(_QWORD *)(a1 + 8);
result = v2++;
}
while ( a1 );
count = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // edx

result = (unsigned int)count;
if ( a1 )
{
v2 = count + 1;
do
{
a1 = *(_QWORD *)(a1 + 8);
result = v2++;
}
while ( a1 );
count = result;
}
return result;
}

original_code:
int num_switches(topo_graph *graph) {
 topo_graph *temp;
 temp = graph;
 while(temp != ((void *)0)) {
  count++;
  temp = temp->next_element;
 }
 return count;
}

canonical_original_code:
int num_switches(struct topo_graph *graph) {
 struct topo_graph *temp;
 temp = graph;
 while(temp != ((void *)0)) {
  count++;
  temp = temp->next_element;
 }
 return count;
}

user_defined_types: struct adj_node { char *ddpid; int w; int min; struct adj_node *next_adjnode; }


decompiled_code:
_QWORD *init_prev_path()
{
_QWORD *v0; // rax
_QWORD *v1; // r8
__int64 *v2; // rax
_QWORD *v3; // rdx
__int64 v4; // rcx

v0 = malloc(16LL * count);
if ( !v0 )
{
puts("\n Error in one of list array malloc");
exit(0);
}
v1 = v0;
v2 = (__int64 *)graph;
if ( graph )
{
v3 = v1;
do
{
v4 = *v2;
v2 = (__int64 *)v2[1];
v3 += 2;
*(v3 - 1) = 0LL;
*(v3 - 2) = v4;
}
while ( v2 );
}
return v1;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rax
_QWORD *v1; // r8
__int64 *v2; // rax
_QWORD *v3; // rdx
__int64 v4; // rcx

v0 = malloc(16LL * count);
if ( !v0 )
{
puts("\n Error in one of list array malloc");
exit(0);
}
v1 = v0;
v2 = (__int64 *)graph;
if ( graph )
{
v3 = v1;
do
{
v4 = *v2;
v2 = (__int64 *)v2[1];
v3 += 2;
*(v3 - 1) = 0LL;
*(v3 - 2) = v4;
}
while ( v2 );
}
return v1;
}

original_code:
prev_path *init_prev_path(void){
 prev_path *a;
 topo_graph *temp;
 int i = 0;
 a = (prev_path *)malloc(count*sizeof(prev_path));
 if(!a){
                printf("\n Error in one of list array malloc\n");
                exit(0);
        }
 temp = graph;
 while(temp != ((void *)0)){
                a[i].dpid = (char *)malloc(48*sizeof(char));
  a[i].path_dpid = (char *)malloc(48*sizeof(char));
                a[i].dpid = temp->sdpid;
                a[i].path_dpid = ((void *)0);
                temp = temp->next_element;
                i++;
        }
        return a;
}

canonical_original_code:
struct prev_path *init_prev_path(){
 struct prev_path *a;
 struct topo_graph *temp;
 int i = 0;
 a = (struct prev_path *)malloc(count*sizeof(prev_path));
 if(!a){
                printf("\n Error in one of list array malloc\n");
                exit(0);
        }
 temp = graph;
 while(temp != ((void *)0)){
                a[i].dpid = (char *)malloc(48*sizeof(char));
  a[i].path_dpid = (char *)malloc(48*sizeof(char));
                a[i].dpid = temp->sdpid;
                a[i].path_dpid = ((void *)0);
                temp = temp->next_element;
                i++;
        }
        return a;
}

variable_types: struct prev_path { char *dpid; char *path_dpid; } *

variable_types: i int


decompiled_code:
__int64 __fastcall set_val_list_array(__int64 a1, const char *a2, int a3)
{
__int64 v4; // rbx
__int64 v5; // rbp

if ( count > 0 )
{
v4 = a1;
v5 = a1 + 16LL * (unsigned int)count;
while ( strcmp(*(const char **)v4, a2) )
{
v4 += 16LL;
if ( v4 == v5 )
return 0LL;
}
*(_DWORD *)(v4 + 8) = a3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, int a3)
{
__int64 v4; // rbx
__int64 v5; // rbp

if ( count > 0 )
{
v4 = a1;
v5 = a1 + 16LL * (unsigned int)count;
while ( strcmp(*(const char **)v4, a2) )
{
v4 += 16LL;
if ( v4 == v5 )
return 0LL;
}
*(_DWORD *)(v4 + 8) = a3;
}
return 0LL;
}

original_code:
int set_val_list_array(list_array *a, char *dpid, int value) {
 int i;
 for(i = 0; i < count; i++){
  if(strcmp(a[i].dpid,dpid) == 0){
   a[i].w = value;
   return 0;
  }
 }
 return 0;
}

canonical_original_code:
int set_val_list_array(struct list *a, char *dpid, int value) {
 int i;
 for(i = 0; i < count; i++){
  if(strcmp(a[i].dpid,dpid) == 0){
   a[i].w = value;
   return 0;
  }
 }
 return 0;
}

variable_types:
a
struct list { char *dpid; int w; } *

variable_types:
dpid
char *

variable_types: value int


decompiled_code:
__int64 __fastcall get_val_list_array(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

if ( count <= 0 )
return 0xFFFFFFFFLL;
v2 = a1;
v3 = a1 + 16LL * (unsigned int)(count - 1);
while ( 1 )
{
if ( !strcmp(*(const char **)v2, a2) )
return *(unsigned int *)(v2 + 8);
if ( v2 == v3 )
break;
v2 += 16LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

if ( count <= 0 )
return 0xFFFFFFFFLL;
v2 = a1;
v3 = a1 + 16LL * (unsigned int)(count - 1);
while ( 1 )
{
if ( !strcmp(*(const char **)v2, a2) )
return *(unsigned int *)(v2 + 8);
if ( v2 == v3 )
break;
v2 += 16LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int get_val_list_array(list_array *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return a[i].w;
  }
 }
 return -1;
}

canonical_original_code:
int get_val_list_array(struct list *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return a[i].w;
  }
 }
 return -1;
}