original_code:
flist_t *flist_new()
{
    flist_t *list = malloc(sizeof(flist_t));
    if (list == ((void *)0))
        return ((void *)0);
    list->items = calloc(5L, sizeof(file_t *));
    if (list->items == ((void *)0)) {
        free(list);
        return ((void *)0);
    }
    list->count = 0;
    list->count_f = 0;
    list->size = 0;
    list->bytes_done = 0;
    list->arr_size = 5L;
    return list;
}

canonical_original_code:
struct flist_t *flist_new()
{
    struct flist_t *list = malloc(sizeof(flist_t));
    if (list == ((void *)0))
        return ((void *)0);
    list->items = calloc(5L, sizeof(struct file_t *));
    if (list->items == ((void *)0)) {
        free(list);
        return ((void *)0);
    }
    list->count = 0;
    list->count_f = 0;
    list->size = 0;
    list->bytes_done = 0;
    list->arr_size = 5L;
    return list;
}

variable_types: struct flist_t { unsigned long count; unsigned long count_f; unsigned long arr_size; long size; long bytes_done; struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t { RFILE=0, RDIR=1, SLINK=2 } type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf { long actime; long modtime; } times; char done; } **items; } *


repo: lynix/vcp

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

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

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

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

original_code:
void flist_delete(flist_t *list)
{
    for (ulong i = 0; i < list->count; i++)
        f_delete(list->items[i]);
    free(list->items);
    free(list);
}

canonical_original_code:
void flist_delete(struct flist_t *list)
{
    for (unsigned long i = 0; i < list->count; i++)
        f_delete(list->items[i]);
    free(list->items);
    free(list);
}

variable_types:
i
unsigned long

return_type: void

user_defined_types: struct flist_t { unsigned long count; unsigned long count_f; unsigned long arr_size; long size; long bytes_done; struct file_t **items; }

user_defined_types: struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf times; char done; }

user_defined_types: enum ftype_t { RFILE=0, RDIR=1, SLINK=2 }

user_defined_types: struct utimbuf { long actime; long modtime; }


decompiled_code:
__int64 __fastcall flist_add(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v4; // rsi
char *v5; // rdi
__int64 v6; // rdx
signed __int64 v7; // rax
char *v8; // rdi
signed __int64 v9; // rdx
__int64 result; // rax
char *v11; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = *a1;
v5 = (char *)a1[5];
if ( v4 == a1[2] )
{
v11 = (char *)realloc(v5, 16 * v4);
a1[5] = (unsigned __int64)v11;
v5 = v11;
if ( !v11 )
return 0xFFFFFFFFLL;
v4 = *a1;
a1[2] *= 2LL;
}
v6 = *(_QWORD *)(a2 + 40);
v7 = a1[3];
v8 = &v5[8 * v4];
*(_QWORD *)v8 = a2;
v9 = v7 + v6;
*a1 = v4 + 1;
a1[3] = v9;
if ( v9 < v7 || v4 + 1 <= v4 )
{
*a1 = v4;
a1[3] = v7;
*(_QWORD *)v8 = 0LL;
return 0xFFFFFFFFLL;
}
result = 0LL;
if ( !*(_DWORD *)(a2 + 32) )
++a1[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v4; // rsi
char *v5; // rdi
__int64 v6; // rdx
signed __int64 v7; // rax
char *v8; // rdi
signed __int64 v9; // rdx
__int64 result; // rax
char *v11; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = *a1;
v5 = (char *)a1[5];
if ( v4 == a1[2] )
{
v11 = (char *)realloc(v5, 16 * v4);
a1[5] = (unsigned __int64)v11;
v5 = v11;
if ( !v11 )
return 0xFFFFFFFFLL;
v4 = *a1;
a1[2] *= 2LL;
}
v6 = *(_QWORD *)(a2 + 40);
v7 = a1[3];
v8 = &v5[8 * v4];
*(_QWORD *)v8 = a2;
v9 = v7 + v6;
*a1 = v4 + 1;
a1[3] = v9;
if ( v9 < v7 || v4 + 1 <= v4 )
{
*a1 = v4;
a1[3] = v7;
*(_QWORD *)v8 = 0LL;
return 0xFFFFFFFFLL;
}
result = 0LL;
if ( !*(_DWORD *)(a2 + 32) )
++a1[1];
return result;
}

original_code:
int flist_add(flist_t *list, file_t *file)
{
    if (list == ((void *)0))
        return -1;
    if (list->count == list->arr_size) {
        ulong size_new = list->arr_size * 2L * sizeof(file_t *);
        list->items = realloc(list->items, size_new);
        if (list->items == ((void *)0))
            return -1;
        list->arr_size *= 2L;
    }
    list->items[list->count] = file;
    ulong temp_c = list->count;
    off_t temp_s = list->size;
    list->size += file->size;
    list->count++;
    if (list->count <= temp_c || list->size < temp_s) {
        list->count = temp_c;
        list->size = temp_s;
        list->items[list->count] = ((void *)0);
        return -1;
    }
    if (file->type == RFILE)
        list->count_f++;
    return 0;
}

canonical_original_code:
int flist_add(struct flist_t *list, struct file_t *file)
{
    if (list == ((void *)0))
        return -1;
    if (list->count == list->arr_size) {
        unsigned long size_new = list->arr_size * 2L * sizeof(file_t *);
        list->items = realloc(list->items, size_new);
        if (list->items == ((void *)0))
            return -1;
        list->arr_size *= 2L;
    }
    list->items[list->count] = file;
    unsigned long temp_c = list->count;
    long temp_s = list->size;
    list->size += file->size;
    list->count++;
    if (list->count <= temp_c || list->size < temp_s) {
        list->count = temp_c;
        list->size = temp_s;
        list->items[list->count] = ((void *)0);
        return -1;
    }
    if (file->type == RFILE)
        list->count_f++;
    return 0;
}

variable_types:
file
struct file_t *

return_type: int


original_code:
file_t *flist_search_src(flist_t *list, char *src)
{
    for (ulong i = 0; i < list->count; i++) {
        if (strcmp(list->items[i]->src, src) == 0 &&
                list->items[i]->type != SLINK) {
            return list->items[i];
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct file_t *flist_search_src(struct flist_t *list, char *src)
{
    for (unsigned long i = 0; i < list->count; i++) {
        if (strcmp(list->items[i]->src, src) == 0 &&
                list->items[i]->type != SLINK) {
            return list->items[i];
        }
    }
    return ((void *)0);
}

variable_types: struct flist_t { unsigned long count; unsigned long count_f; unsigned long arr_size; long size; long bytes_done; struct file_t **items; } *

variable_types:
src
char *

return_type: struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t { RFILE=0, RDIR=1, SLINK=2 } type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf { long actime; long modtime; } times; char done; } *


decompiled_code:
void __fastcall flist_sort(__int64 a1)
{
qsort(*(void **)(a1 + 40), *(_QWORD *)(a1 + 16), 8uLL, (__compar_fn_t)&f_cmpr_dst);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
qsort(*(void **)(a1 + 40), *(_QWORD *)(a1 + 16), 8uLL, (__compar_fn_t)&f_cmpr_dst);
}

original_code:
inline void flist_sort(flist_t *list)
{
    qsort(list->items, list->arr_size, sizeof(file_t *), f_cmpr_dst);
}

canonical_original_code:
inline void flist_sort(struct flist_t *list)
{
    qsort(list->items, list->arr_size, sizeof(struct file_t *), f_cmpr_dst);
}


decompiled_code:
__int64 __fastcall flist_shrink(__int64 a1)
{
void *v1; // rax

v1 = realloc(*(void **)(a1 + 40), 8LL * *(_QWORD *)a1);
*(_QWORD *)(a1 + 40) = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = *(_QWORD *)a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
void *v1; // rax

v1 = realloc(*(void **)(a1 + 40), 8LL * *(_QWORD *)a1);
*(_QWORD *)(a1 + 40) = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = *(_QWORD *)a1;
return 0LL;
}

original_code:
int flist_shrink(flist_t *list)
{
    list->items = realloc(list->items, list->count * sizeof(file_t *));
    if (list->items == ((void *)0))
        return -1;
    list->arr_size = list->count;
    return 0;
}

canonical_original_code:
int flist_shrink(struct flist_t *list)
{
    list->items = realloc(list->items, list->count * sizeof(struct file_t *));
    if (list->items == ((void *)0))
        return -1;
    list->arr_size = list->count;
    return 0;
}


decompiled_code:
int __fastcall flist_print(__int64 *a1, _BYTE *a2)
{
__int64 v2; // r12
unsigned __int64 v3; // rbx
__int64 v4; // r14
__int64 v5; // r15
int v6; // eax
const char *v7; // rax
const char *v8; // rax
char v10; // [rsp+Fh] [rbp-39h]

v2 = *a1;
if ( *a1 )
{
v10 = 0;
v3 = 0LL;
v2 = 0LL;
v4 = 0LL;
do
{
v5 = *(_QWORD *)(a1[5] + 8 * v3);
if ( !*(_BYTE *)(v5 + 80) || (*a2 & 0x10) != 0 )
{
v6 = *(_DWORD *)(v5 + 32);
if ( v6 )
{
if ( v6 == 1 )
{
printf(" [D] ");
}
else if ( v6 == 2 )
{
printf(" [S] ");
}
}
else
{
++v2;
printf(" [F] ");
v4 += *(_QWORD *)(v5 + 40);
}
printf("%s --> %s", *(const char **)(v5 + 8), *(const char **)(v5 + 16));
if ( *(_BYTE *)(v5 + 80) )
{
printf("(*)");
v10 = 1;
}
else if ( !*(_DWORD *)(v5 + 32) )
{
v7 = (const char *)size_str(*(_QWORD *)(v5 + 40));
printf(" (%s)", v7);
}
putchar(10);
}
++v3;
}
while ( *a1 > v3 );
putchar(10);
if ( v10 )
{
puts("(*) marked items already exist at their destination");
puts(" and do not count for transfer size.\n");
}
}
else
{
v4 = 0LL;
putchar(10);
}
v8 = (const char *)size_str(v4);
printf("Total transfer size: %lu file(s), %s\n\n", v2, v8);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func6(__int64 *a1, _BYTE *a2)
{
__int64 v2; // r12
unsigned __int64 v3; // rbx
__int64 v4; // r14
__int64 v5; // r15
int v6; // eax
const char *v7; // rax
const char *v8; // rax
char v10; // [rsp+Fh] [rbp-39h]

v2 = *a1;
if ( *a1 )
{
v10 = 0;
v3 = 0LL;
v2 = 0LL;
v4 = 0LL;
do
{
v5 = *(_QWORD *)(a1[5] + 8 * v3);
if ( !*(_BYTE *)(v5 + 80) || (*a2 & 0x10) != 0 )
{
v6 = *(_DWORD *)(v5 + 32);
if ( v6 )
{
if ( v6 == 1 )
{
printf(" [D] ");
}
else if ( v6 == 2 )
{
printf(" [S] ");
}
}
else
{
++v2;
printf(" [F] ");
v4 += *(_QWORD *)(v5 + 40);
}
printf("%s --> %s", *(const char **)(v5 + 8), *(const char **)(v5 + 16));
if ( *(_BYTE *)(v5 + 80) )
{
printf("(*)");
v10 = 1;
}
else if ( !*(_DWORD *)(v5 + 32) )
{
v7 = (const char *)size_str(*(_QWORD *)(v5 + 40));
printf(" (%s)", v7);
}
putchar(10);
}
++v3;
}
while ( *a1 > v3 );
putchar(10);
if ( v10 )
{
puts("(*) marked items already exist at their destination");
puts(" and do not count for transfer size.\n");
}
}
else
{
v4 = 0LL;
putchar(10);
}
v8 = (const char *)size_str(v4);
printf("Total transfer size: %lu file(s), %s\n\n", v2, v8);
return fflush(stdout);
}

original_code:
void flist_print(flist_t *list, opts_t *opts)
{
    off_t size = 0;
    ulong count = 0;
    char mark = 0;
    for (ulong i = 0; i < list->count; i++) {
        file_t *item = list->items[i];
        if (item->done && !opts->delete)
            continue;
        if (item->type == RFILE) {
            printf(" [F] ");
            count++;
            size += item->size;
        } else if (item->type == RDIR) {
            printf(" [D] ");
        } else if (item->type == SLINK) {
            printf(" [S] ");
        }
        printf("%s --> %s", item->src, item->dst);
        if (item->done) {
            mark = 1;
            printf("(*)");
        } else if (item->type == RFILE) {
            printf(" (%s)", size_str(item->size));
        }
        putchar('\n');
    }
    putchar('\n');
    if (mark) {
        puts("(*) marked items already exist at their destination");
        puts("    and do not count for transfer size.\n");
    }
    printf("Total transfer size: %lu file(s), %s\n\n", count, size_str(size));
    fflush(stdout);
    return;
}

canonical_original_code:
void flist_print(struct flist_t *list, struct opts_t *opts)
{
    long size = 0;
    unsigned long count = 0;
    char mark = 0;
    for (unsigned long i = 0; i < list->count; i++) {
        struct file_t *item = list->items[i];
        if (item->done && !opts->delete)
            continue;
        if (item->type == RFILE) {
            printf(" [F] ");
            count++;
            size += item->size;
        } else if (item->type == RDIR) {
            printf(" [D] ");
        } else if (item->type == SLINK) {
            printf(" [S] ");
        }
        printf("%s --> %s", item->src, item->dst);
        if (item->done) {
            mark = 1;
            printf("(*)");
        } else if (item->type == RFILE) {
            printf(" (%s)", size_str(item->size));
        }
        putchar('\n');
    }
    putchar('\n');
    if (mark) {
        puts("(*) marked items already exist at their destination");
        puts("    and do not count for transfer size.\n");
    }
    printf("Total transfer size: %lu file(s), %s\n\n", count, size_str(size));
    fflush(stdout);
    return;
}

variable_types: struct opts_t { unsigned int bars; unsigned int force; unsigned int filenames; unsigned int sync; unsigned int delete; unsigned int keep; unsigned int quiet; unsigned int update; unsigned int verbose; unsigned int pretend; unsigned int debug; unsigned int ignore_uid_err; } *

variable_types: size long

variable_types:
count
unsigned long

variable_types: mark char

variable_types: struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t { RFILE=0, RDIR=1, SLINK=2 } type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf { long actime; long modtime; } times; char done; } *


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

v0 = malloc(0x18uLL);
if ( v0 )
{
v1 = calloc(5uLL, 8uLL);
v0[2] = v1;
if ( v1 )
{
*v0 = 0LL;
v0[1] = 5LL;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(0x18uLL);
if ( v0 )
{
v1 = calloc(5uLL, 8uLL);
v0[2] = v1;
if ( v1 )
{
*v0 = 0LL;
v0[1] = 5LL;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
strlist_t *strlist_new()
{
    strlist_t *list = malloc(sizeof(strlist_t));
    if (list == ((void *)0))
        return ((void *)0);
    list->items = calloc(5L, sizeof(char *));
    if (list->items == ((void *)0)) {
        free(list);
        return ((void *)0);
    }
    list->count = 0;
    list->arr_size = 5L;
    return list;
}

canonical_original_code:
struct strlist_t *strlist_new()
{
    struct strlist_t *list = malloc(sizeof(strlist_t));
    if (list == ((void *)0))
        return ((void *)0);
    list->items = calloc(5L, sizeof(char *));
    if (list->items == ((void *)0)) {
        free(list);
        return ((void *)0);
    }
    list->count = 0;
    list->arr_size = 5L;
    return list;
}

variable_types: struct strlist_t { unsigned long count; unsigned long arr_size; char **items; } *


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

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

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

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

original_code:
void strlist_delete(strlist_t *list)
{
    for (ulong i = 0; i < list->count; i++)
        free(list->items[i]);
    free(list->items);
    free(list);
}

canonical_original_code:
void strlist_delete(struct strlist_t *list)
{
    for (unsigned long i = 0; i < list->count; i++)
        free(list->items[i]);
    free(list->items);
    free(list);
}

user_defined_types: struct strlist_t { unsigned long count; unsigned long arr_size; char **items; }


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

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = *a1;
v5 = (void *)a1[2];
if ( v4 == a1[1] )
{
v7 = realloc(v5, 16 * v4);
a1[2] = (unsigned __int64)v7;
v5 = v7;
if ( !v7 )
return 0xFFFFFFFFLL;
v4 = *a1;
a1[1] *= 2LL;
}
*((_QWORD *)v5 + v4) = a2;
*a1 = v4 + 1;
if ( v4 + 1 <= v4 )
{
*a1 = -1LL;
return 0xFFFFFFFFLL;
}
return 0LL;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = *a1;
v5 = (void *)a1[2];
if ( v4 == a1[1] )
{
v7 = realloc(v5, 16 * v4);
a1[2] = (unsigned __int64)v7;
v5 = v7;
if ( !v7 )
return 0xFFFFFFFFLL;
v4 = *a1;
a1[1] *= 2LL;
}
*((_QWORD *)v5 + v4) = a2;
*a1 = v4 + 1;
if ( v4 + 1 <= v4 )
{
*a1 = -1LL;
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int strlist_add(strlist_t *list, char *item)
{
    if (list == ((void *)0))
        return -1;
    if (list->count == list->arr_size) {
        ulong new_size = list->arr_size * 2L * sizeof(char *);
        list->items = realloc(list->items, new_size);
        if (list->items == ((void *)0))
            return -1;
        list->arr_size *= 2L;
    }
    list->items[list->count] = item;
    ulong temp = list->count++;
    if (list->count <= temp) {
        list->count--;
        return -1;
    }
    return 0;
}

canonical_original_code:
int strlist_add(struct strlist_t *list, char *item)
{
    if (list == ((void *)0))
        return -1;
    if (list->count == list->arr_size) {
        unsigned long new_size = list->arr_size * 2L * sizeof(char *);
        list->items = realloc(list->items, new_size);
        if (list->items == ((void *)0))
            return -1;
        list->arr_size *= 2L;
    }
    list->items[list->count] = item;
    unsigned long temp = list->count++;
    if (list->count <= temp) {
        list->count--;
        return -1;
    }
    return 0;
}

variable_types:
item
char *

variable_types:
temp
unsigned long


repo: lzungri/os-course

decompiled_code:
void __fastcall __noreturn thread_a(void *a1)
{
while ( 1 )
{
sem_wait(&sem_a);
putchar(65);
sem_post(&sem_d);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
while ( 1 )
{
sem_wait(&sem_a);
putchar(65);
sem_post(&sem_d);
}
}

original_code:
void *thread_a(void *params) {
 while(1) {
  sem_wait(&sem_a);
  printf("A");
  sem_post(&sem_d);
 }
}

variable_types:
params
void *

return_type: void *


decompiled_code:
void __fastcall __noreturn thread_b(void *a1)
{
while ( 1 )
{
sem_wait(&sem_b);
sem_wait(&sem_d);
putchar(66);
sem_post(&sem_a);
sem_post(&sem_c);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
while ( 1 )
{
sem_wait(&sem_b);
sem_wait(&sem_d);
putchar(66);
sem_post(&sem_a);
sem_post(&sem_c);
}
}

original_code:
void *thread_b(void *params) {
 while(1) {
  sem_wait(&sem_b);
  sem_wait(&sem_d);
  printf("B");
  sem_post(&sem_a);
  sem_post(&sem_c);
 }
}


decompiled_code:
void __fastcall __noreturn thread_c(void *a1)
{
while ( 1 )
{
sem_wait(&sem_c);
sem_wait(&sem_d);
putchar(67);
sem_post(&sem_a);
sem_post(&sem_b);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
while ( 1 )
{
sem_wait(&sem_c);
sem_wait(&sem_d);
putchar(67);
sem_post(&sem_a);
sem_post(&sem_b);
}
}

original_code:
void *thread_c(void *params) {
 while(1) {
  sem_wait(&sem_c);
  sem_wait(&sem_d);
  printf("C");
  sem_post(&sem_a);
  sem_post(&sem_b);
 }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

sem_init(&sem_a, 0, 0);
sem_init(&sem_b, 0, 1u);
sem_init(&sem_c, 0, 0);
sem_init(&sem_d, 0, 1u);
pthread_create(newthread, 0LL, thread_a, 0LL);
pthread_create(newthread, 0LL, thread_b, 0LL);
pthread_create(newthread, 0LL, thread_c, 0LL);
usleep(0x3E8u);
return 0;
}

original_code:
int main(void) {
 pthread_t th;
 sem_init(&sem_a, 0, 0);
 sem_init(&sem_b, 0, 1);
 sem_init(&sem_c, 0, 0);
 sem_init(&sem_d, 0, 1);
 pthread_create(&th, 0, thread_a, 0);
 pthread_create(&th, 0, thread_b, 0);
 pthread_create(&th, 0, thread_c, 0);
 usleep(1000);
 return 0;
}

canonical_original_code:
int main() {
 unsigned long th;
 sem_init(&sem_a, 0, 0);
 sem_init(&sem_b, 0, 1);
 sem_init(&sem_c, 0, 0);
 sem_init(&sem_d, 0, 1);
 pthread_create(&th, 0, thread_a, 0);
 pthread_create(&th, 0, thread_b, 0);
 pthread_create(&th, 0, thread_c, 0);
 usleep(1000);
 return 0;
}

variable_types:
th
unsigned long


decompiled_code:
void __fastcall th_func(void *a1)
{
counter += 10000;
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
counter += 10000;
}

original_code:
void *th_func(void *params) {
 int i;
 for(i = 0; i < 10000; ++i) {
  counter++;
 }
}

variable_types: i int


decompiled_code:
__m128 __fastcall x_punto(double a1, __m128 a2)
{
return a2;
}

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

original_code:
double x_punto(double t,double v_x )
{
        return v_x;
}

canonical_original_code:
double x_punto(double t, double v_x)
{
        return v_x;
}

variable_types: t double

return_type: double


decompiled_code:
// attributes: thunk
__m128 __fastcall y_punto(double a1, __m128 a2)
{
return x_punto(a1, a2);
}

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

original_code:
double y_punto(double t,double v_y )
{
        return v_y;
}

canonical_original_code:
double y_punto(double t, double v_y)
{
        return v_y;
}


decompiled_code:
double __fastcall v_x_punto1(double a1, double a2, double a3, double a4, double a5)
{
double v6; // [rsp+8h] [rbp-10h]

v6 = pow((a2 - a4) * (a2 - a4) + (a3 - a5) * (a3 - a5) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v6 * v6) * ((a2 - a4) / v6);
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2, double a3, double a4, double a5)
{
double v6; // [rsp+8h] [rbp-10h]

v6 = pow((a2 - a4) * (a2 - a4) + (a3 - a5) * (a3 - a5) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v6 * v6) * ((a2 - a4) / v6);
}

original_code:
double v_x_punto1(double t,double pos_x , double pos_y , double posM1_x, double posM1_y)
{
 double r, costheta;
 r = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
 costheta=(pos_x-posM1_x)/r;
 return ((-G_const()*pow(10,12))/pow(r, 2.0)*costheta);
}

canonical_original_code:
double v_x_punto1(double t, double pos_x, double pos_y, double posM1_x, double posM1_y)
{
 double r; double costheta;
 r = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
 costheta=(pos_x-posM1_x)/r;
 return ((-G_const()*pow(10,12))/pow(r, 2.0)*costheta);
}

variable_types: r double

variable_types: costheta double


decompiled_code:
double __fastcall v_y_punto1(double a1, double a2, double a3, double a4, double a5)
{
double v6; // [rsp+0h] [rbp-18h]
double v7; // [rsp+8h] [rbp-10h]

v6 = a3 - a5;
v7 = pow(v6 * v6 + (a2 - a4) * (a2 - a4) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v7 * v7) * (v6 / v7);
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2, double a3, double a4, double a5)
{
double v6; // [rsp+0h] [rbp-18h]
double v7; // [rsp+8h] [rbp-10h]

v6 = a3 - a5;
v7 = pow(v6 * v6 + (a2 - a4) * (a2 - a4) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v7 * v7) * (v6 / v7);
}

original_code:
double v_y_punto1(double t,double pos_x , double pos_y , double posM1_x, double posM1_y)
{
 double r, sintheta;
  r = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
  sintheta=(pos_y-posM1_y)/r;
  return ((-G_const()*pow(10,12))/pow(r , 2.0)*sintheta);
}

canonical_original_code:
double v_y_punto1(double t, double pos_x, double pos_y, double posM1_x, double posM1_y)
{
 double r; double sintheta;
  r = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
  sintheta=(pos_y-posM1_y)/r;
  return ((-G_const()*pow(10,12))/pow(r , 2.0)*sintheta);
}

variable_types: sintheta double


decompiled_code:
double __fastcall v_x_punto2(double a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
double v8; // [rsp+0h] [rbp-38h]
double v10; // [rsp+8h] [rbp-30h]
double v11; // [rsp+10h] [rbp-28h]
double v12; // [rsp+18h] [rbp-20h]

v12 = pow((a2 - a4) * (a2 - a4) + (a3 - a5) * (a3 - a5) + 0.01, 0.5);
v10 = a2 - a6;
v11 = pow((a3 - a7) * (a3 - a7) + v10 * v10 + 0.01, 0.5);
v8 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v12 * v12) * ((a2 - a4) / v12);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v11 * v11) * (v10 / v11) + v8;
}

canonical_decompiled_code:
double __fastcall func4(double a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
double v8; // [rsp+0h] [rbp-38h]
double v10; // [rsp+8h] [rbp-30h]
double v11; // [rsp+10h] [rbp-28h]
double v12; // [rsp+18h] [rbp-20h]

v12 = pow((a2 - a4) * (a2 - a4) + (a3 - a5) * (a3 - a5) + 0.01, 0.5);
v10 = a2 - a6;
v11 = pow((a3 - a7) * (a3 - a7) + v10 * v10 + 0.01, 0.5);
v8 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v12 * v12) * ((a2 - a4) / v12);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v11 * v11) * (v10 / v11) + v8;
}

original_code:
double v_x_punto2(double t,double pos_x , double pos_y , double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
 double r1, costheta1, r2, costheta2;
 r1 = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
 costheta1=(pos_x-posM1_x)/r1;
 r2 = pow((pow((pos_x-posM2_x),2.0)+ pow((pos_y-posM2_y),2.0) + pow(10,-2)),1.0/2.0);
 costheta2=(pos_x-posM2_x)/r2;
 return (((-G_const()*pow(10,12))/pow(r1 , 2.0)*costheta1)+((-G_const()*pow(10,12))/pow(r2 , 2.0)*costheta2));
}

canonical_original_code:
double v_x_punto2(double t, double pos_x, double pos_y, double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
 double r1; double costheta1; double r2; double costheta2;
 r1 = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
 costheta1=(pos_x-posM1_x)/r1;
 r2 = pow((pow((pos_x-posM2_x),2.0)+ pow((pos_y-posM2_y),2.0) + pow(10,-2)),1.0/2.0);
 costheta2=(pos_x-posM2_x)/r2;
 return (((-G_const()*pow(10,12))/pow(r1 , 2.0)*costheta1)+((-G_const()*pow(10,12))/pow(r2 , 2.0)*costheta2));
}


decompiled_code:
double __fastcall v_y_punto2(double a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
double v8; // [rsp+0h] [rbp-38h]
double v9; // [rsp+0h] [rbp-38h]
double v11; // [rsp+10h] [rbp-28h]
double v12; // [rsp+18h] [rbp-20h]

v8 = a3 - a5;
v12 = pow((a2 - a4) * (a2 - a4) + (a3 - a5) * (a3 - a5) + 0.01, 0.5);
v11 = pow((a2 - a6) * (a2 - a6) + (a3 - a7) * (a3 - a7) + 0.01, 0.5);
v9 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v12 * v12) * (v8 / v12);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v11 * v11) * ((a3 - a7) / v11) + v9;
}

canonical_decompiled_code:
double __fastcall func5(double a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
double v8; // [rsp+0h] [rbp-38h]
double v9; // [rsp+0h] [rbp-38h]
double v11; // [rsp+10h] [rbp-28h]
double v12; // [rsp+18h] [rbp-20h]

v8 = a3 - a5;
v12 = pow((a2 - a4) * (a2 - a4) + (a3 - a5) * (a3 - a5) + 0.01, 0.5);
v11 = pow((a2 - a6) * (a2 - a6) + (a3 - a7) * (a3 - a7) + 0.01, 0.5);
v9 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v12 * v12) * (v8 / v12);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v11 * v11) * ((a3 - a7) / v11) + v9;
}

original_code:
double v_y_punto2(double t,double pos_x , double pos_y , double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
 double r1, sintheta1, r2, sintheta2;
  r1 = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
  sintheta1=(pos_y-posM1_y)/r1;
  r2 = pow((pow((pos_x-posM2_x),2.0)+ pow((pos_y-posM2_y),2.0) + pow(10,-2)),1.0/2.0);
  sintheta2=(pos_y-posM2_y)/r2;
  return (((-G_const()*pow(10,12))/pow(r1, 2.0)*sintheta1)+((-G_const()*pow(10,12))/pow(r2, 2.0)*sintheta2));
}

canonical_original_code:
double v_y_punto2(double t, double pos_x, double pos_y, double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
 double r1; double sintheta1; double r2; double sintheta2;
  r1 = pow((pow((pos_x-posM1_x),2.0)+ pow((pos_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
  sintheta1=(pos_y-posM1_y)/r1;
  r2 = pow((pow((pos_x-posM2_x),2.0)+ pow((pos_y-posM2_y),2.0) + pow(10,-2)),1.0/2.0);
  sintheta2=(pos_y-posM2_y)/r2;
  return (((-G_const()*pow(10,12))/pow(r1, 2.0)*sintheta1)+((-G_const()*pow(10,12))/pow(r2, 2.0)*sintheta2));
}


decompiled_code:
// attributes: thunk
double __fastcall v_x_puntoMG1(double a1, double a2, double a3, double a4, double a5)
{
return v_x_punto1(a1, a2, a3, a4, a5);
}

canonical_decompiled_code:
double __fastcall func6(double a1, double a2, double a3, double a4, double a5)
{
return func2(a1, a2, a3, a4, a5);
}

original_code:
double v_x_puntoMG1(double t,double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
  double r, costheta;
  r = pow((pow((posM1_x-posM2_x),2.0)+ pow((posM1_y-posM2_y),2.0) + pow(10,-2) ),1.0/2.0);
  costheta=(posM1_x-posM2_x)/r;
  return((-G_const()*pow(10,12))/pow(r, 2.0)*costheta);
}

canonical_original_code:
double v_x_puntoMG1(double t, double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
  double r; double costheta;
  r = pow((pow((posM1_x-posM2_x),2.0)+ pow((posM1_y-posM2_y),2.0) + pow(10,-2) ),1.0/2.0);
  costheta=(posM1_x-posM2_x)/r;
  return((-G_const()*pow(10,12))/pow(r, 2.0)*costheta);
}


decompiled_code:
double __fastcall v_x_puntoMG2(double a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm3_8
double v7; // [rsp+8h] [rbp-10h]

v5 = a4 - a2;
v7 = pow(v5 * v5 + (a5 - a3) * (a5 - a3) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v7 * v7) * (v5 / v7);
}

canonical_decompiled_code:
double __fastcall func7(double a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm3_8
double v7; // [rsp+8h] [rbp-10h]

v5 = a4 - a2;
v7 = pow(v5 * v5 + (a5 - a3) * (a5 - a3) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v7 * v7) * (v5 / v7);
}

original_code:
double v_x_puntoMG2(double t,double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
  double r, costheta;
  r = pow((pow((posM2_x-posM1_x),2.0)+ pow((posM2_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
  costheta=(posM2_x-posM1_x)/r;
  return((-G_const()*pow(10,12))/pow(r, 2.0)*costheta);
}

canonical_original_code:
double v_x_puntoMG2(double t, double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
  double r; double costheta;
  r = pow((pow((posM2_x-posM1_x),2.0)+ pow((posM2_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
  costheta=(posM2_x-posM1_x)/r;
  return((-G_const()*pow(10,12))/pow(r, 2.0)*costheta);
}


decompiled_code:
// attributes: thunk
double __fastcall v_y_puntoMG1(double a1, double a2, double a3, double a4, double a5)
{
return v_y_punto1(a1, a2, a3, a4, a5);
}

canonical_decompiled_code:
double __fastcall func8(double a1, double a2, double a3, double a4, double a5)
{
return func3(a1, a2, a3, a4, a5);
}

original_code:
double v_y_puntoMG1(double t,double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
   double r, sintheta;
   r = pow((pow((posM1_x-posM2_x),2.0)+ pow((posM1_y-posM2_y),2.0) + pow(10,-2)),1.0/2.0);
   sintheta=(posM1_y-posM2_y)/r;
   return((-G_const()*pow(10,12))/pow(r, 2.0)*sintheta);
}

canonical_original_code:
double v_y_puntoMG1(double t, double posM1_x, double posM1_y, double posM2_x, double posM2_y)
{
   double r; double sintheta;
   r = pow((pow((posM1_x-posM2_x),2.0)+ pow((posM1_y-posM2_y),2.0) + pow(10,-2)),1.0/2.0);
   sintheta=(posM1_y-posM2_y)/r;
   return((-G_const()*pow(10,12))/pow(r, 2.0)*sintheta);
}


decompiled_code:
double __fastcall v_y_puntoMG2(double a1, double a2, double a3, double a4, double a5)
{
double v6; // [rsp+0h] [rbp-18h]
double v7; // [rsp+8h] [rbp-10h]

v6 = a5 - a3;
v7 = pow(v6 * v6 + (a4 - a2) * (a4 - a2) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v7 * v7) * (v6 / v7);
}

canonical_decompiled_code:
double __fastcall func9(double a1, double a2, double a3, double a4, double a5)
{
double v6; // [rsp+0h] [rbp-18h]
double v7; // [rsp+8h] [rbp-10h]

v6 = a5 - a3;
v7 = pow(v6 * v6 + (a4 - a2) * (a4 - a2) + 0.01, 0.5);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(G_const()) ^ LC2) * 1.0e12 / (v7 * v7) * (v6 / v7);
}

original_code:
double v_y_puntoMG2(double t,double posM1_x, double posM1_y, double posM2_x, double posM2_y){
 double r, sintheta;
 r = pow((pow((posM2_x-posM1_x),2.0)+ pow((posM2_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
 sintheta=(posM2_y-posM1_y)/r;
 return((-G_const()*pow(10,12))/pow(r, 2.0)*sintheta);
}

canonical_original_code:
double v_y_puntoMG2(double t, double posM1_x, double posM1_y, double posM2_x, double posM2_y){
 double r; double sintheta;
 r = pow((pow((posM2_x-posM1_x),2.0)+ pow((posM2_y-posM1_y),2.0) + pow(10,-2)),1.0/2.0);
 sintheta=(posM2_y-posM1_y)/r;
 return((-G_const()*pow(10,12))/pow(r, 2.0)*sintheta);
}


decompiled_code:
double G_const()
{
return *(double *)&LC0;
}

canonical_decompiled_code:
double func0()
{
return *(double *)&LC0;
}

original_code:
double G_const(){
 return(4.46391e-6);
}

canonical_original_code:
double G_const(){
 return(4.46391e-6);
}


PI

decompiled_code:
double PI()
{
return *(double *)&LC1;
}

canonical_decompiled_code:
double func1()
{
return *(double *)&LC1;
}


decompiled_code:
double __fastcall Kms_KpcGyr(double a1)
{
return a1 * 1.022;
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
return a1 * 1.022;
}

original_code:
double Kms_KpcGyr(double value){
 return(value*1.022);
}

variable_types: value double


decompiled_code:
double __fastcall KpcGyr_Kms(double a1)
{
return a1 * 0.9785;
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
return a1 * 0.9785;
}

original_code:
double KpcGyr_Kms(double value){
 return(value*0.9785);
}


original_code:
double Gyr_s(double value){
 return((value)*(31540000.0)*(pow(10,9)));
}


decompiled_code:
double __fastcall Kpc_m(double a1)
{
return a1 * 3.0e16 * 1000.0;
}

canonical_decompiled_code:
double __fastcall func5(double a1)
{
return a1 * 3.0e16 * 1000.0;
}


original_code:
double m_Kpc(double value){
 return((value)*(3.241)*(pow(10,-20)));
}


decompiled_code:
__int64 cmd_init()
{
int v0; // ebx
int v1; // eax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( !(unsigned int)stat("/tmp/input", &v3) )
unlink("/tmp/input");
if ( !(unsigned int)stat("/tmp/output", &v3) )
unlink("/tmp/output");
v0 = mkfifo("/tmp/input", 0);
v1 = mkfifo("/tmp/output", 1u);
if ( v0 < 0 || v1 < 0 )
{
fwrite("error: main(): Couldn't open(r|w) pipe file\n", 1uLL, 0x2CuLL, stderr);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ebx
int v1; // eax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( !(unsigned int)func18("/tmp/input", &v3) )
unlink("/tmp/input");
if ( !(unsigned int)func18("/tmp/output", &v3) )
unlink("/tmp/output");
v0 = mkfifo("/tmp/input", 0);
v1 = mkfifo("/tmp/output", 1u);
if ( v0 < 0 || v1 < 0 )
{
fwrite("error: main(): Couldn't open(r|w) pipe file\n", 1uLL, 0x2CuLL, stderr);
exit(1);
}
return 0LL;
}

original_code:
int cmd_init(void) {
    int fifo_input, fifo_output;
    struct stat buf;
    if (stat("/tmp/input", &buf) == 0)
        unlink("/tmp/input");
    if (stat("/tmp/output", &buf) == 0)
        unlink("/tmp/output");
    fifo_input = mkfifo("/tmp/input", 00);
    fifo_output = mkfifo("/tmp/output", 01);
    if (fifo_input < 0 || fifo_output < 0) {
        fprintf(stderr, "error: main(): Couldn't open(r|w) pipe file\n");
        exit(1);
    }
    return 0;
}

canonical_original_code:
int cmd_init() {
    int fifo_input; int fifo_output;
    struct stat buf;
    if (stat("/tmp/input", &buf) == 0)
        unlink("/tmp/input");
    if (stat("/tmp/output", &buf) == 0)
        unlink("/tmp/output");
    fifo_input = mkfifo("/tmp/input", 00);
    fifo_output = mkfifo("/tmp/output", 01);
    if (fifo_input < 0 || fifo_output < 0) {
        fprintf(stderr, "error: main(): Couldn't open(r|w) pipe file\n");
        exit(1);
    }
    return 0;
}

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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 cmd_kill()
{
unlink("/tmp/input");
unlink("/tmp/output");
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
unlink("/tmp/input");
unlink("/tmp/output");
return 0LL;
}

original_code:
int cmd_kill(void) {
    unlink("/tmp/input");
    unlink("/tmp/output");
    return 0;
}

canonical_original_code:
int cmd_kill() {
    unlink("/tmp/input");
    unlink("/tmp/output");
    return 0;
}


decompiled_code:
__int64 __fastcall cmd_exec(void *a1)
{
const char **v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (const char **)explode(a1);
if ( !v1 )
return 0xFFFFFFFFLL;
execv(*v1, (char *const *)v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1)
{
const char **v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (const char **)explode(a1);
if ( !v1 )
return 0xFFFFFFFFLL;
execv(*v1, (char *const *)v1);
return 0LL;
}

original_code:
int cmd_exec(uint8_t *cmd, int cmd_len) {
    char **argv;
    int argc;
    if (!cmd)
        return -1;
    argv = explode(cmd, cmd_len, " ", &argc);
    if (!argv)
        return -1;
    execv(argv[0], argv);
    return 0;
}

canonical_original_code:
int cmd_exec(unsigned char *cmd, int cmd_len) {
    char **argv;
    int argc;
    if (!cmd)
        return -1;
    argv = explode(cmd, cmd_len, " ", &argc);
    if (!argv)
        return -1;
    execv(argv[0], argv);
    return 0;
}

variable_types:
cmd
unsigned char *

variable_types:
argv
char **

variable_types: argc int


decompiled_code:
__int64 cmd_read()
{
int v0; // eax
int v1; // ebp
unsigned int v2; // ebx
void *v3; // rax
void *v4; // r12
void *buf; // [rsp+8h] [rbp-20h] BYREF

v0 = open("/tmp/output", 0);
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
v1 = v0;
buf = malloc(0x2800uLL);
if ( !buf )
{
fwrite("Error allocating reading buffer !", 1uLL, 0x21uLL, stderr);
return 0xFFFFFFFFLL;
}
v2 = read(v1, &buf, 0x2800uLL);
v3 = (void *)msg_pack(5LL, buf, v2);
v4 = v3;
if ( v3 )
{
if ( (int)write(1, v3, (int)(v2 + 4)) > 0 )
{
free(buf);
free(v4);
close(v1);
return 0LL;
}
return 0xFFFFFFFFLL;
}
free(buf);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax
int v1; // ebp
unsigned int v2; // ebx
void *v3; // rax
void *v4; // r12
void *buf; // [rsp+8h] [rbp-20h] BYREF

v0 = open("/tmp/output", 0);
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
v1 = v0;
buf = malloc(0x2800uLL);
if ( !buf )
{
fwrite("Error allocating reading buffer !", 1uLL, 0x21uLL, stderr);
return 0xFFFFFFFFLL;
}
v2 = read(v1, &buf, 0x2800uLL);
v3 = (void *)msg_pack(5LL, buf, v2);
v4 = v3;
if ( v3 )
{
if ( (int)write(1, v3, (int)(v2 + 4)) > 0 )
{
free(buf);
free(v4);
close(v1);
return 0LL;
}
return 0xFFFFFFFFLL;
}
free(buf);
return 0xFFFFFFFFLL;
}

original_code:
int cmd_read(void) {
    uint8_t *buf, *msg;
    int fd;
    int len;
    fd = open("/tmp/output", 00);
    if (fd <= 0)
        return -1;
    buf = malloc(sizeof(char) * 1024 * 10);
    if (!buf) {
        fprintf(stderr, "Error allocating reading buffer !");
        return -1;
    }
    len = read(fd, &buf, 1024 * 10);
    msg = msg_pack(MSG_TYPE_DATA, buf, len);
    if (!msg) {
        free(buf);
        return -1;
    }
    len = write(1, msg, 4 + len);
    if (len <= 0) {
        return -1;
    }
    else if (len < 4 + len) {
    }
    free(buf);
    free(msg);
    close(fd);
    return 0;
}

canonical_original_code:
int cmd_read() {
    unsigned char *buf; unsigned char *msg;
    int fd;
    int len;
    fd = open("/tmp/output", 00);
    if (fd <= 0)
        return -1;
    buf = malloc(sizeof(char) * 1024 * 10);
    if (!buf) {
        fprintf(stderr, "Error allocating reading buffer !");
        return -1;
    }
    len = read(fd, &buf, 1024 * 10);
    msg = msg_pack(MSG_TYPE_DATA, buf, len);
    if (!msg) {
        free(buf);
        return -1;
    }
    len = write(1, msg, 4 + len);
    if (len <= 0) {
        return -1;
    }
    else if (len < 4 + len) {
    }
    free(buf);
    free(msg);
    close(fd);
    return 0;
}

variable_types:
buf
unsigned char *

variable_types:
msg
unsigned char *

variable_types: fd int

variable_types: len int


decompiled_code:
__int64 __fastcall cmd_write(void *buf, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12

if ( buf && (v2 = open("/tmp/input", 1), v3 = v2, v2 > 0) && (v4 = write(v2, buf, a2), v4 > 0) )
close(v3);
else
v4 = -1;
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(void *buf, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12

if ( buf && (v2 = open("/tmp/input", 1), v3 = v2, v2 > 0) && (v4 = write(v2, buf, a2), v4 > 0) )
close(v3);
else
v4 = -1;
return (unsigned int)v4;
}

original_code:
int cmd_write(uint8_t *data, int data_len) {
    int len;
    int fd;
    if (!data)
        return -1;
    fd = open("/tmp/input", 01);
    if (fd <= 0)
        return -1;
    len = write(fd, data, data_len);
    if (len <= 0) {
        return -1;
    }
    else if (len < data_len) {
    }
    close(fd);
    return len;
}

canonical_original_code:
int cmd_write(unsigned char *data, int data_len) {
    int len;
    int fd;
    if (!data)
        return -1;
    fd = open("/tmp/input", 01);
    if (fd <= 0)
        return -1;
    len = write(fd, data, data_len);
    if (len <= 0) {
        return -1;
    }
    else if (len < data_len) {
    }
    close(fd);
    return len;
}

variable_types:
data
unsigned char *


main

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

v3 = malloc(0x2800uLL);
if ( v3 )
{
v4 = v3;
v5 = read(0, v3, 0x2800uLL);
v6 = msg_unpack(v4, v5);
v7 = (void *)v6;
if ( v6 )
{
v8 = *(unsigned __int8 *)(v6 + 1);
switch ( (char)v8 )
{
case 0:
cmd_init();
v9 = 0;
break;
case 1:
cmd_kill();
v9 = 0;
break;
case 2:
v9 = 0;
cmd_exec(*(_QWORD *)(v6 + 8), *(unsigned __int16 *)(v6 + 2));
break;
case 3:
cmd_read();
v9 = 0;
break;
case 4:
v9 = 0;
cmd_write(*(void **)(v6 + 8));
break;
default:
v9 = -1;
fprintf(stderr, "unknown request type %d\n", v8);
break;
}
free(v4);
free(v7);
}
else
{
v9 = -1;
fwrite("error unpacking message\n", 1uLL, 0x18uLL, stderr);
free(v4);
}
}
else
{
v9 = -1;
fwrite("cannot allocate receiving request buffer !\n", 1uLL, 0x2BuLL, stderr);
}
return v9;
}

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

v3 = malloc(0x2800uLL);
if ( v3 )
{
v4 = v3;
v5 = read(0, v3, 0x2800uLL);
v6 = msg_unpack(v4, v5);
v7 = (void *)v6;
if ( v6 )
{
v8 = *(unsigned __int8 *)(v6 + 1);
switch ( (char)v8 )
{
case 0:
func7();
v9 = 0;
break;
case 1:
func8();
v9 = 0;
break;
case 2:
v9 = 0;
func9(*(_QWORD *)(v6 + 8), *(unsigned __int16 *)(v6 + 2));
break;
case 3:
func10();
v9 = 0;
break;
case 4:
v9 = 0;
func11(*(void **)(v6 + 8));
break;
default:
v9 = -1;
fprintf(stderr, "unknown request type %d\n", v8);
break;
}
free(v4);
free(v7);
}
else
{
v9 = -1;
fwrite("error unpacking message\n", 1uLL, 0x18uLL, stderr);
free(v4);
}
}
else
{
v9 = -1;
fwrite("cannot allocate receiving request buffer !\n", 1uLL, 0x2BuLL, stderr);
}
return v9;
}

original_code:
int main(int argc, char *argv[]) {
    struct ihf_msg *msg = ((void *)0);
    uint8_t *req = ((void *)0);
    int ret = 0;
    int len;
    req = malloc(sizeof(char) * 1024 * 10);
    if (!req) {
        fprintf(stderr, "cannot allocate receiving request buffer !\n");
        ret = -1;
        goto exit;
    }
    len = read(0, req, 1024 * 10);
    msg = msg_unpack(req, len);
    if (!msg) {
        fprintf(stderr, "error unpacking message\n");
        ret = -1;
        goto exit;
    }
    switch (msg->type) {
        case MSG_TYPE_INIT:
            cmd_init();
            break;
        case MSG_TYPE_KILL:
            cmd_kill();
            break;
        case MSG_TYPE_EXEC:
            cmd_exec(msg->arg, msg->arglen);
            break;
        case MSG_TYPE_READ:
            cmd_read();
            break;
        case MSG_TYPE_WRITE:
            cmd_write(msg->arg, msg->arglen);
            break;
        default:
            fprintf(stderr, "unknown request type %d\n", msg->type);
            ret = -1;
            goto exit;
    }
exit:
    if (req)
        free(req);
    if (msg)
        free(msg);
    return ret;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct ihf_msg *msg = ((void *)0);
    unsigned char *req = ((void *)0);
    int ret = 0;
    int len;
    req = malloc(sizeof(char) * 1024 * 10);
    if (!req) {
        fprintf(stderr, "cannot allocate receiving request buffer !\n");
        ret = -1;
        goto exit;
    }
    len = read(0, req, 1024 * 10);
    msg = msg_unpack(req, len);
    if (!msg) {
        fprintf(stderr, "error unpacking message\n");
        ret = -1;
        goto exit;
    }
    switch (msg->type) {
        case MSG_TYPE_INIT:
            cmd_init();
            break;
        case MSG_TYPE_KILL:
            cmd_kill();
            break;
        case MSG_TYPE_EXEC:
            cmd_exec(msg->arg, msg->arglen);
            break;
        case MSG_TYPE_READ:
            cmd_read();
            break;
        case MSG_TYPE_WRITE:
            cmd_write(msg->arg, msg->arglen);
            break;
        default:
            fprintf(stderr, "unknown request type %d\n", msg->type);
            ret = -1;
            goto exit;
    }
exit:
    if (req)
        free(req);
    if (msg)
        free(msg);
    return ret;
}

variable_types:
argv
char *[]

variable_types: struct ihf_msg { unsigned char version; unsigned char type; unsigned short arglen; unsigned char *arg; } *

variable_types:
req
unsigned char *

variable_types: ret int


decompiled_code:
int __fastcall print_array_uint8_t(__int64 a1, int a2)
{
__int64 v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a1 && a2 > 0 )
{
v3 = 0LL;
do
{
v4 = *(unsigned __int8 *)(a1 + v3++);
printf("%02x ", v4);
}
while ( a2 > (int)v3 );
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
__int64 v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a1 && a2 > 0 )
{
v3 = 0LL;
do
{
v4 = *(unsigned __int8 *)(a1 + v3++);
printf("%02x ", v4);
}
while ( a2 > (int)v3 );
result = putchar(10);
}
return result;
}

original_code:
void print_array_uint8_t (uint8_t *array, int n_elements) {
    int idx_array;
    if (!array || n_elements <= 0)
        return;
    for (idx_array = 0; idx_array < n_elements; idx_array++)
        printf("%02x ", array[idx_array]);
    putchar('\n');
}

canonical_original_code:
void print_array_uint8_t(unsigned char *array, int n_elements) {
    int idx_array;
    if (!array || n_elements <= 0)
        return;
    for (idx_array = 0; idx_array < n_elements; idx_array++)
        printf("%02x ", array[idx_array]);
    putchar('\n');
}

variable_types:
array
unsigned char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
__int64 v4; // rbp
__int64 i; // rax
__m128i v6; // xmm0
char *v7; // r12
size_t v8; // rax
int v9; // er12
char *s; // [rsp+0h] [rbp-38h] BYREF
void *s2; // [rsp+8h] [rbp-30h] BYREF
size_t n; // [rsp+10h] [rbp-28h] BYREF
char v14[32]; // [rsp+18h] [rbp-20h] BYREF

v3 = calloc(0x119uLL, 1uLL);
if ( v3 )
{
v4 = (__int64)v3;
for ( i = 0LL; i != 256; ++i )
*(_BYTE *)(v4 + i) = i;
v6 = _mm_load_si128((const __m128i *)&LC11);
*(_QWORD *)(v4 + 272) = 0xA34677261203367LL;
*(__m128i *)(v4 + 256) = v6;
puts("printing array...");
print_array_uint8_t(v4, 280);
puts("\nEncoding buffer ...");
base64_encode_alloc(v4, 280LL, &s);
if ( s )
{
printf("encoded: %s\n\n", s);
puts("Decoding buffer ...");
base64_decode_ctx_init(v14);
v7 = s;
v8 = strlen(s);
base64_decode_alloc_ctx(v14, v7, v8, &s2, &n);
printf("len_decoded: %lu\n\n", n);
puts("printing array...");
print_array_uint8_t((__int64)s2, n);
puts("comparing arrays...");
v9 = memcmp((const void *)v4, s2, n);
if ( v9 )
{
v9 = 0;
puts("Decoding failed");
}
else
{
puts("Decoding succeeded");
}
}
else
{
v9 = -1;
fwrite("error: Could not encode buffer\n", 1uLL, 0x1FuLL, stderr);
}
}
else
{
v9 = -1;
fwrite("error: Could not alloc buffer\n", 1uLL, 0x1EuLL, stderr);
}
return v9;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
__int64 v4; // rbp
__int64 i; // rax
__m128i v6; // xmm0
char *v7; // r12
size_t v8; // rax
int v9; // er12
char *s; // [rsp+0h] [rbp-38h] BYREF
void *s2; // [rsp+8h] [rbp-30h] BYREF
size_t n; // [rsp+10h] [rbp-28h] BYREF
char v14[32]; // [rsp+18h] [rbp-20h] BYREF

v3 = calloc(0x119uLL, 1uLL);
if ( v3 )
{
v4 = (__int64)v3;
for ( i = 0LL; i != 256; ++i )
*(_BYTE *)(v4 + i) = i;
v6 = _mm_load_si128((const __m128i *)&LC11);
*(_QWORD *)(v4 + 272) = 0xA34677261203367LL;
*(__m128i *)(v4 + 256) = v6;
puts("printing array...");
func0(v4, 280);
puts("\nEncoding buffer ...");
base64_encode_alloc(v4, 280LL, &s);
if ( s )
{
printf("encoded: %s\n\n", s);
puts("Decoding buffer ...");
base64_decode_ctx_init(v14);
v7 = s;
v8 = strlen(s);
base64_decode_alloc_ctx(v14, v7, v8, &s2, &n);
printf("len_decoded: %lu\n\n", n);
puts("printing array...");
func0((__int64)s2, n);
puts("comparing arrays...");
v9 = memcmp((const void *)v4, s2, n);
if ( v9 )
{
v9 = 0;
puts("Decoding failed");
}
else
{
puts("Decoding succeeded");
}
}
else
{
v9 = -1;
fwrite("error: Could not encode buffer\n", 1uLL, 0x1FuLL, stderr);
}
}
else
{
v9 = -1;
fwrite("error: Could not alloc buffer\n", 1uLL, 0x1EuLL, stderr);
}
return v9;
}

original_code:
int main(int argc, char *argv[]) {
    int idx_buf, sz_buf;
    char *buf;
    struct base64_decode_context dctx;
    char *b64_encoded, *b64_decoded;
    size_t len_decoded;
    sz_buf = 256 + strlen("ag0 arg1 arg2 arg3 arg4\n") + 1;
    buf = calloc(sz_buf, sizeof(*buf));
    if (!buf) {
        fprintf(stderr, "error: Could not alloc buffer\n");
        return -1;
    }
    for (idx_buf = 0; idx_buf < 256; idx_buf++)
        buf[idx_buf] = idx_buf;
    memcpy(buf + 256, "ag0 arg1 arg2 arg3 arg4\n", strlen("ag0 arg1 arg2 arg3 arg4\n"));
    printf("printing array...\n");
    print_array_uint8_t (buf, sz_buf - 1);
    printf("\nEncoding buffer ...\n");
    base64_encode_alloc(buf, sz_buf - 1, &b64_encoded);
    if (!b64_encoded) {
        fprintf(stderr, "error: Could not encode buffer\n");
        return -1;
    }
    printf("encoded: %s\n\n", b64_encoded);
    printf("Decoding buffer ...\n");
    base64_decode_ctx_init (&dctx);
    base64_decode_alloc_ctx(&dctx,
            b64_encoded, strlen(b64_encoded),
            &b64_decoded, &len_decoded);
    printf("len_decoded: %lu\n\n", len_decoded);
    printf("printing array...\n");
    print_array_uint8_t (b64_decoded, len_decoded);
    printf("comparing arrays...\n");
    if (memcmp(buf, b64_decoded, len_decoded))
        printf("Decoding failed\n");
    else
        printf("Decoding succeeded\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int idx_buf; int sz_buf;
    char *buf;
    struct base64_decode_context dctx;
    char *b64_encoded; char *b64_decoded;
    unsigned long len_decoded;
    sz_buf = 256 + strlen("ag0 arg1 arg2 arg3 arg4\n") + 1;
    buf = calloc(sz_buf, sizeof(*buf));
    if (!buf) {
        fprintf(stderr, "error: Could not alloc buffer\n");
        return -1;
    }
    for (idx_buf = 0; idx_buf < 256; idx_buf++)
        buf[idx_buf] = idx_buf;
    memcpy(buf + 256, "ag0 arg1 arg2 arg3 arg4\n", strlen("ag0 arg1 arg2 arg3 arg4\n"));
    printf("printing array...\n");
    print_array_uint8_t (buf, sz_buf - 1);
    printf("\nEncoding buffer ...\n");
    base64_encode_alloc(buf, sz_buf - 1, &b64_encoded);
    if (!b64_encoded) {
        fprintf(stderr, "error: Could not encode buffer\n");
        return -1;
    }
    printf("encoded: %s\n\n", b64_encoded);
    printf("Decoding buffer ...\n");
    base64_decode_ctx_init (&dctx);
    base64_decode_alloc_ctx(&dctx,
            b64_encoded, strlen(b64_encoded),
            &b64_decoded, &len_decoded);
    printf("len_decoded: %lu\n\n", len_decoded);
    printf("printing array...\n");
    print_array_uint8_t (b64_decoded, len_decoded);
    printf("comparing arrays...\n");
    if (memcmp(buf, b64_decoded, len_decoded))
        printf("Decoding failed\n");
    else
        printf("Decoding succeeded\n");
    return 0;
}

variable_types:
buf
char *

variable_types: struct base64_decode_context { unsigned int i; char buf[4]; }


usage

decompiled_code:
void __noreturn usage()
{
printf("Usage: %s [-hv] host port command\n", (const char *)program_invocation_short_name);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
printf("Usage: %s [-hv] host port command\n", (const char *)program_invocation_short_name);
exit(1);
}

original_code:
int usage() {
    printf("Usage: %s [-hv] host port command\n", __progname);
    exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // rbp
const char *v6; // r13
int v7; // eax
const char *v8; // rcx

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hv");
if ( v4 == -1 )
break;
v3 = 1;
if ( v4 != 118 )
goto LABEL_10;
}
v5 = &argv[optind];
if ( argc - optind != 3 || (v6 = *v5, v7 = atoi(v5[1]), v8 = v5[2], v6 == 0LL || v8 == 0LL) || v7 < 0 )
LABEL_10:
usage();
if ( v3 )
printf("Connecting to %s port %d, executing %s\n", v6, (unsigned int)v7, v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // rbp
const char *v6; // r13
int v7; // eax
const char *v8; // rcx

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hv");
if ( v4 == -1 )
break;
v3 = 1;
if ( v4 != 118 )
goto LABEL_10;
}
v5 = &argv[optind];
if ( argc - optind != 3 || (v6 = *v5, v7 = atoi(v5[1]), v8 = v5[2], v6 == 0LL || v8 == 0LL) || v7 < 0 )
LABEL_10:
func7();
if ( v3 )
printf("Connecting to %s port %d, executing %s\n", v6, (unsigned int)v7, v8);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    int opt;
    int verbose = 0;
    char *host;
    int port;
    char *cmd;
    while ((opt = getopt(argc, argv, "hv")) != -1) {
        switch (opt) {
            case 'h':
                usage();
            case 'v':
                verbose = 1;
                break;
            default:
                usage();
        }
    }
    argc -= optind;
    argv += optind;
    if (argc != 3)
        usage();
    host = argv[0];
    port = atoi(argv[1]);
    cmd = argv[2];
    if (!host || port < 0 || !cmd)
        usage();
    if (verbose)
        printf("Connecting to %s port %d, executing %s\n",
                host, port, cmd);
    return 0;
}

variable_types: opt int

variable_types: verbose int

variable_types:
host
char *

variable_types: port int

variable_types:
cmd
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
while ( !feof(stdin) )
{
buffer_0 = 0;
fread(&buffer_0, 4uLL, 1uLL, stdin);
write_signal(&buffer_0);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
while ( !feof(stdin) )
{
buffer_0 = 0;
fread(&buffer_0, 4uLL, 1uLL, stdin);
func7(&buffer_0);
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    while(!feof(stdin)) {
        static char buffer[4];
        memset(buffer, 0, 4);
        fread(buffer, 4, 1, stdin);
        write_signal(buffer);
    }
    return 0;
}

variable_types: argc int

variable_types:
buffer
char [4]


original_code:
void write_signal(char buffer[4]) {
    unsigned int freq_i, sample_i;
    char halfbuffer[8] = {
        (((unsigned char) (buffer[0])) >> 4), ((buffer[0]) & 0xf), (((unsigned char) (buffer[1])) >> 4), ((buffer[1]) & 0xf),
        (((unsigned char) (buffer[2])) >> 4), ((buffer[2]) & 0xf), (((unsigned char) (buffer[3])) >> 4), ((buffer[3]) & 0xf),
    };
    float outbuf[200] = {0.0};
    for(freq_i = 0; freq_i<8; freq_i++)
        for(sample_i = 0; sample_i<200; sample_i++) {
            outbuf[sample_i] += sin(2*3.14159265358979323846*(carrier_freq[freq_i]*sample_i/96000 +(halfbuffer[freq_i] & 0x7)/8.0))/(halfbuffer[freq_i] & 0x8 ? 16 : 8 );
        }
    fwrite(outbuf, sizeof outbuf, 1, stdout);
}

canonical_original_code:
void write_signal(char buffer[4]) {
    unsigned int freq_i; unsigned int sample_i;
    char halfbuffer[8] = {
        (((unsigned char) (buffer[0])) >> 4), ((buffer[0]) & 0xf), (((unsigned char) (buffer[1])) >> 4), ((buffer[1]) & 0xf),
        (((unsigned char) (buffer[2])) >> 4), ((buffer[2]) & 0xf), (((unsigned char) (buffer[3])) >> 4), ((buffer[3]) & 0xf),
    };
    float outbuf[200] = {0.0};
    for(freq_i = 0; freq_i<8; freq_i++)
        for(sample_i = 0; sample_i<200; sample_i++) {
            outbuf[sample_i] += sin(2*3.14159265358979323846*(carrier_freq[freq_i]*sample_i/96000 +(halfbuffer[freq_i] & 0x7)/8.0))/(halfbuffer[freq_i] & 0x8 ? 16 : 8 );
        }
    fwrite(outbuf, sizeof outbuf, 1, stdout);
}

variable_types:
halfbuffer
char [8]

variable_types:
outbuf
float [200]


decompiled_code:
__int64 __fastcall pull_flags(__int64 a1, char *a2, const char *a3)
{
_QWORD *v3; // r12
const unsigned __int16 **v6; // rax
const unsigned __int16 *v7; // rcx
const unsigned __int16 **v8; // r8
__int64 result; // rax
char *v10; // r15
int v11; // edx
_QWORD *v12; // rax
char *v13; // rax
const unsigned __int16 **v14; // [rsp+8h] [rbp-1040h]
const unsigned __int16 **v15; // [rsp+8h] [rbp-1040h]
const unsigned __int16 **v16; // [rsp+8h] [rbp-1040h]
char v17[2048]; // [rsp+10h] [rbp-1038h] BYREF
char s[2104]; // [rsp+810h] [rbp-838h] BYREF

v6 = _ctype_b_loc();
v7 = *v6;
v8 = v6;
while ( 1 )
{
result = *a2;
if ( (v7[result] & 0x2000) == 0 )
break;
++a2;
}
v10 = (char *)a3;
v11 = 1;
if ( (_BYTE)result )
{
while ( 1 )
{
++a2;
if ( v11 == 1 && (_BYTE)result == 45 )
{
v11 = 3;
memset(s, 0, 0x800uLL);
v10 = s;
}
else
{
if ( (_BYTE)result == 40 && v11 == 3 )
{
v15 = v8;
v10 = v17;
s[strlen(s)] = 0;
v3 = create_flag(s);
AttachToList(v3, a1);
memset(s, 0, 0x800uLL);
v8 = v15;
v11 = 2;
goto LABEL_7;
}
if ( (_BYTE)result == 41 && v11 == 2 )
{
v16 = v8;
v10 = (char *)&a3[strlen(a3)];
v17[strlen(v17)] = 0;
v13 = strdup(v17);
v8 = v16;
v3[1] = v13;
v11 = 1;
memset(v17, 0, sizeof(v17));
goto LABEL_7;
}
if ( ((*v8)[result] & 0x2000) != 0 && v11 == 3 )
{
v14 = v8;
v10 = (char *)&a3[strlen(a3)];
s[strlen(s)] = 0;
v3 = create_flag(s);
AttachToList(v3, a1);
memset(s, 0, 0x800uLL);
v8 = v14;
v11 = 1;
}
}
*v10++ = *(a2 - 1);
LABEL_7:
result = *a2;
if ( !(_BYTE)result )
{
if ( v11 == 3 )
{
s[strlen(s)] = 0;
v12 = create_flag(s);
result = AttachToList(v12, a1);
}
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, const char *a3)
{
_QWORD *v3; // r12
const unsigned __int16 **v6; // rax
const unsigned __int16 *v7; // rcx
const unsigned __int16 **v8; // r8
__int64 result; // rax
char *v10; // r15
int v11; // edx
_QWORD *v12; // rax
char *v13; // rax
const unsigned __int16 **v14; // [rsp+8h] [rbp-1040h]
const unsigned __int16 **v15; // [rsp+8h] [rbp-1040h]
const unsigned __int16 **v16; // [rsp+8h] [rbp-1040h]
char v17[2048]; // [rsp+10h] [rbp-1038h] BYREF
char s[2104]; // [rsp+810h] [rbp-838h] BYREF

v6 = _ctype_b_loc();
v7 = *v6;
v8 = v6;
while ( 1 )
{
result = *a2;
if ( (v7[result] & 0x2000) == 0 )
break;
++a2;
}
v10 = (char *)a3;
v11 = 1;
if ( (_BYTE)result )
{
while ( 1 )
{
++a2;
if ( v11 == 1 && (_BYTE)result == 45 )
{
v11 = 3;
memset(s, 0, 0x800uLL);
v10 = s;
}
else
{
if ( (_BYTE)result == 40 && v11 == 3 )
{
v15 = v8;
v10 = v17;
s[strlen(s)] = 0;
v3 = create_flag(s);
AttachToList(v3, a1);
memset(s, 0, 0x800uLL);
v8 = v15;
v11 = 2;
goto LABEL_7;
}
if ( (_BYTE)result == 41 && v11 == 2 )
{
v16 = v8;
v10 = (char *)&a3[strlen(a3)];
v17[strlen(v17)] = 0;
v13 = strdup(v17);
v8 = v16;
v3[1] = v13;
v11 = 1;
memset(v17, 0, sizeof(v17));
goto LABEL_7;
}
if ( ((*v8)[result] & 0x2000) != 0 && v11 == 3 )
{
v14 = v8;
v10 = (char *)&a3[strlen(a3)];
s[strlen(s)] = 0;
v3 = create_flag(s);
AttachToList(v3, a1);
memset(s, 0, 0x800uLL);
v8 = v14;
v11 = 1;
}
}
*v10++ = *(a2 - 1);
LABEL_7:
result = *a2;
if ( !(_BYTE)result )
{
if ( v11 == 3 )
{
s[strlen(s)] = 0;
v12 = create_flag(s);
result = AttachToList(v12, a1);
}
return result;
}
}
}
return result;
}

original_code:
void pull_flags( LIST *flags, char *arg, char *arg_no_flags )
{
   CMD_FLAG *cFlag;
   char parambuf[2048];
   char flagbuf[2048];
   char *ptr;
   int mode = 1;
   ptr = arg_no_flags;
   while( ((*__ctype_b_loc ())[(int) ((*arg))] & (unsigned short int) _ISspace) )
      arg++;
   while( arg && *arg != '\0' )
   {
      if( *arg == '-' && mode == 1 )
      {
         mode = 3;
         memset( &flagbuf[0], 0, sizeof( flagbuf ) );
         ptr = flagbuf;
      }
      else if( *arg == '(' && mode == 3 )
      {
         arg++;
         mode = 2;
         ptr = parambuf;
         flagbuf[strlen(flagbuf)] = '\0';
         cFlag = create_flag( flagbuf );
         AttachToList( cFlag, flags );
         memset( &flagbuf[0], 0, sizeof( flagbuf ) );
         continue;
      }
      else if( *arg == ')' && mode == 2 )
      {
         arg++;
         mode = 1;
         ptr = arg_no_flags + strlen( arg_no_flags );
         parambuf[strlen(parambuf)] = '\0';
         cFlag->params = strdup( parambuf );
         memset( &parambuf[0], 0, sizeof( parambuf ) );
         continue;
      }
      else if( ((*__ctype_b_loc ())[(int) ((*arg))] & (unsigned short int) _ISspace) && mode == 3 )
      {
         mode = 1;
         ptr = arg_no_flags + strlen( arg_no_flags );
         flagbuf[strlen(flagbuf)] = '\0';
         cFlag = create_flag( flagbuf );
         AttachToList( cFlag, flags );
         memset( &flagbuf[0], 0, sizeof( flagbuf ) );
      }
      *ptr++ = *arg++;
   }
   if( mode == 3 )
   {
      flagbuf[strlen(flagbuf)] = '\0';
      cFlag = create_flag( flagbuf );
      AttachToList( cFlag, flags );
      memset( &flagbuf[0], 0, sizeof( flagbuf ) );
   }
   return;
}

canonical_original_code:
void pull_flags(struct List *flags, char *arg, char *arg_no_flags)
{
   struct cmdFlag *cFlag;
   char parambuf[2048];
   char flagbuf[2048];
   char *ptr;
   int mode = 1;
   ptr = arg_no_flags;
   while( ((*__ctype_b_loc ())[(int) ((*arg))] & (unsigned short) _ISspace) )
      arg++;
   while( arg && *arg != '\0' )
   {
      if( *arg == '-' && mode == 1 )
      {
         mode = 3;
         memset( &flagbuf[0], 0, sizeof( flagbuf ) );
         ptr = flagbuf;
      }
      else if( *arg == '(' && mode == 3 )
      {
         arg++;
         mode = 2;
         ptr = parambuf;
         flagbuf[strlen(flagbuf)] = '\0';
         cFlag = create_flag( flagbuf );
         AttachToList( cFlag, flags );
         memset( &flagbuf[0], 0, sizeof( flagbuf ) );
         continue;
      }
      else if( *arg == ')' && mode == 2 )
      {
         arg++;
         mode = 1;
         ptr = arg_no_flags + strlen( arg_no_flags );
         parambuf[strlen(parambuf)] = '\0';
         cFlag->params = strdup( parambuf );
         memset( &parambuf[0], 0, sizeof( parambuf ) );
         continue;
      }
      else if( ((*__ctype_b_loc ())[(int) ((*arg))] & (unsigned short) _ISspace) && mode == 3 )
      {
         mode = 1;
         ptr = arg_no_flags + strlen( arg_no_flags );
         flagbuf[strlen(flagbuf)] = '\0';
         cFlag = create_flag( flagbuf );
         AttachToList( cFlag, flags );
         memset( &flagbuf[0], 0, sizeof( flagbuf ) );
      }
      *ptr++ = *arg++;
   }
   if( mode == 3 )
   {
      flagbuf[strlen(flagbuf)] = '\0';
      cFlag = create_flag( flagbuf );
      AttachToList( cFlag, flags );
      memset( &flagbuf[0], 0, sizeof( flagbuf ) );
   }
   return;
}

variable_types: struct List { struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; } *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; } *

variable_types:
arg
char *

variable_types: struct cmdFlag { char *flag; char *params; } *

variable_types:
parambuf
char [2048]

variable_types:
flagbuf
char [2048]

variable_types:
ptr
char *

variable_types: mode int

user_defined_types: struct List { struct Cell *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; }


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

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

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

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

original_code:
void free_flag( CMD_FLAG *cmdFlag )
{
   if( cmdFlag->flag )
      free( cmdFlag->flag );
   free( cmdFlag );
   return;
}

canonical_original_code:
void free_flag(struct cmdFlag *cmdFlag)
{
   if( cmdFlag->flag )
      free( cmdFlag->flag );
   free( cmdFlag );
   return;
}

user_defined_types: struct cmdFlag { char *flag; char *params; }


decompiled_code:
__int64 __fastcall free_flag_list(__int64 a1)
{
void *v2; // rdi
_BYTE v4[24]; // [rsp+0h] [rbp-18h] BYREF

AttachIterator(v4, a1);
while ( 1 )
{
v2 = (void *)NextInList(v4);
if ( !v2 )
break;
free_flag(v2);
}
DetachIterator(v4);
return FreeList(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
void *v2; // rdi
_BYTE v4[24]; // [rsp+0h] [rbp-18h] BYREF

AttachIterator(v4, a1);
while ( 1 )
{
v2 = (void *)NextInList(v4);
if ( !v2 )
break;
func3(v2);
}
DetachIterator(v4);
return FreeList(a1);
}

original_code:
void free_flag_list( LIST *flag_list )
{
   CMD_FLAG *cmdFlag;
   ITERATOR Iter;
   AttachIterator( &Iter, flag_list );
   while( ( cmdFlag = (CMD_FLAG *)NextInList( &Iter ) ) != ((void *)0) )
      free_flag( cmdFlag );
   DetachIterator( &Iter );
   FreeList( flag_list );
   return;
}

canonical_original_code:
void free_flag_list(struct List *flag_list)
{
   struct cmdFlag *cmdFlag;
   struct Iterator Iter;
   AttachIterator( &Iter, flag_list );
   while( ( cmdFlag = (struct cmdFlag *)NextInList( &Iter ) ) != ((void *)0) )
      free_flag( cmdFlag );
   DetachIterator( &Iter );
   FreeList( flag_list );
   return;
}

variable_types: struct Iterator { struct List { struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; } *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; } *_pList; struct Cell *_pCell; }

user_defined_types: struct Iterator { struct List *_pList; struct Cell *_pCell; }


decompiled_code:
const char **__fastcall get_flag(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // r12
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

AttachIterator(v5, a1);
do
{
v2 = (const char **)NextInList(v5);
v3 = v2;
}
while ( v2 && strcmp(*v2, a2) );
DetachIterator(v5);
return v3;
}

canonical_decompiled_code:
const char **__fastcall func5(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // r12
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

AttachIterator(v5, a1);
do
{
v2 = (const char **)NextInList(v5);
v3 = v2;
}
while ( v2 && strcmp(*v2, a2) );
DetachIterator(v5);
return v3;
}

original_code:
CMD_FLAG *get_flag( LIST *flag_list, const char *flag )
{
   CMD_FLAG *cmdFlag;
   ITERATOR Iter;
   AttachIterator( &Iter, flag_list );
   while( ( cmdFlag = (CMD_FLAG *)NextInList( &Iter ) ) != ((void *)0) )
      if( !strcmp( cmdFlag->flag, flag ) )
         break;
   DetachIterator( &Iter );
   return cmdFlag;
}

canonical_original_code:
struct cmdFlag *get_flag(struct List *flag_list, char *flag)
{
   struct cmdFlag *cmdFlag;
   struct Iterator Iter;
   AttachIterator( &Iter, flag_list );
   while( ( cmdFlag = (struct cmdFlag *)NextInList( &Iter ) ) != ((void *)0) )
      if( !strcmp( cmdFlag->flag, flag ) )
         break;
   DetachIterator( &Iter );
   return cmdFlag;
}

variable_types:
flag
char *

return_type: struct cmdFlag { char *flag; char *params; } *

user_defined_types: struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; }


decompiled_code:
__int64 __fastcall log_flags(__int64 a1)
{
const char **v1; // rax
_BYTE v3[24]; // [rsp+0h] [rbp-18h] BYREF

AttachIterator(v3, a1);
while ( 1 )
{
v1 = (const char **)NextInList(v3);
if ( !v1 )
break;
log_string("Flag: '%s' Param: '%s'", *v1, v1[1]);
}
return DetachIterator(v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
const char **v1; // rax
_BYTE v3[24]; // [rsp+0h] [rbp-18h] BYREF

AttachIterator(v3, a1);
while ( 1 )
{
v1 = (const char **)NextInList(v3);
if ( !v1 )
break;
log_string("Flag: '%s' Param: '%s'", *v1, v1[1]);
}
return DetachIterator(v3);
}

original_code:
void log_flags( LIST *flags )
{
   CMD_FLAG *flag;
   ITERATOR Iter;
   AttachIterator( &Iter, flags );
   while( ( flag = (CMD_FLAG *)NextInList( &Iter ) ) != ((void *)0) )
      log_string( "Flag: '%s' Param: '%s'", flag->flag, flag->params );
   DetachIterator( &Iter );
   return;
}

canonical_original_code:
void log_flags(struct List *flags)
{
   struct cmdFlag *flag;
   struct Iterator Iter;
   AttachIterator( &Iter, flags );
   while( ( flag = (struct cmdFlag *)NextInList( &Iter ) ) != ((void *)0) )
      log_string( "Flag: '%s' Param: '%s'", flag->flag, flag->params );
   DetachIterator( &Iter );
   return;
}


decompiled_code:
void *__fastcall zlib_alloc(__int64 a1, unsigned int a2, unsigned int a3)
{
return calloc(a2, a3);
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
return calloc(a2, a3);
}

original_code:
void *zlib_alloc(void *opaque, unsigned int items, unsigned int size)
{
  return calloc(items, size);
}

variable_types:
opaque
void *

variable_types:
items
unsigned int

variable_types:
size
unsigned int


decompiled_code:
void __fastcall zlib_free(__int64 a1, void *a2)
{
free(a2);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, void *a2)
{
free(a2);
}

original_code:
void zlib_free(void *opaque, void *address)
{
  free(address);
}

variable_types:
address
void *


decompiled_code:
void init_offset()
{
void *v0; // rax

v0 = calloc(1uLL, 0xCuLL);
if ( !v0 )
{
perror("calloc failure");
fprintf(stderr, "Malloc failure @ %s:%d\n", "offset.c", 10LL);
abort();
}
clear_offset((__int64)v0);
}

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

v0 = calloc(1uLL, 0xCuLL);
if ( !v0 )
{
perror("calloc failure");
fprintf(stderr, "Malloc failure @ %s:%d\n", "offset.c", 10LL);
abort();
}
func0((__int64)v0);
}

original_code:
OFFSET *init_offset( void )
{
   OFFSET *off;
   do { if (!((off) = (OFFSET *) calloc ((1), sizeof(OFFSET)))) { perror("calloc failure"); fprintf(stderr, "Malloc failure @ %s:%d\n", "offset.c", 10 ); abort(); } } while(0);
   clear_offset( off );
   return off;
}

canonical_original_code:
struct offset *init_offset()
{
   struct offset *off;
   do { if (!((off) = (struct offset *) calloc ((1), sizeof(OFFSET)))) { perror("calloc failure"); fprintf(stderr, "Malloc failure @ %s:%d\n", "offset.c", 10 ); abort(); } } while(0);
   clear_offset( off );
   return off;
}

variable_types: struct offset { int x; int y; int z; } *


decompiled_code:
// attributes: thunk
void free_offset(void *ptr)
{
free(ptr);
}

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

original_code:
void free_offset( OFFSET *off )
{
   free( off );
   return;
}

canonical_original_code:
void free_offset(struct offset *off)
{
   free( off );
   return;
}


decompiled_code:
__int64 __fastcall free_offset_list(__int64 a1)
{
void *v1; // rdi
_BYTE v3[24]; // [rsp+0h] [rbp-18h] BYREF

AttachIterator(v3, a1);
while ( 1 )
{
v1 = (void *)NextInList(v3);
if ( !v1 )
break;
free_offset(v1);
}
return DetachIterator(v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
void *v1; // rdi
_BYTE v3[24]; // [rsp+0h] [rbp-18h] BYREF

AttachIterator(v3, a1);
while ( 1 )
{
v1 = (void *)NextInList(v3);
if ( !v1 )
break;
func2(v1);
}
return DetachIterator(v3);
}

original_code:
void free_offset_list( LIST *offsets )
{
   OFFSET *off;
   ITERATOR Iter;
   AttachIterator( &Iter, offsets );
   while( ( off = (OFFSET *)NextInList( &Iter ) ) != ((void *)0) )
      free_offset( off );
   DetachIterator( &Iter );
   return;
}

canonical_original_code:
void free_offset_list(struct List *offsets)
{
   struct offset *off;
   struct Iterator Iter;
   AttachIterator( &Iter, offsets );
   while( ( off = (struct offset *)NextInList( &Iter ) ) != ((void *)0) )
      free_offset( off );
   DetachIterator( &Iter );
   return;
}


decompiled_code:
void __fastcall clear_rFramework(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void clear_rFramework( R_FRAMEWORK *rFrame )
{
   rFrame->title = ((void *)0);
   rFrame->description = ((void *)0);
   return;
}

canonical_original_code:
void clear_rFramework(struct room_framework *rFrame)
{
   rFrame->title = ((void *)0);
   rFrame->description = ((void *)0);
   return;
}

variable_types: struct room_framework { struct framework { void *content; int type; struct instance_id { int id; char *created_by; char *created_on; char *modified_by; char *last_modified; } *id; char *name; char *short_descr; char *long_descr; } *container; char *title; char *description; unsigned char inside; } *

user_defined_types: struct room_framework { struct framework *container; char *title; char *description; unsigned char inside; }

user_defined_types: struct framework { void *content; int type; struct instance_id *id; char *name; char *short_descr; char *long_descr; }


decompiled_code:
void init_rFramework()
{
void *v0; // rax

v0 = calloc(1uLL, 0x20uLL);
if ( !v0 )
{
perror("calloc failure");
fprintf(stderr, "Malloc failure @ %s:%d\n", "framework.c", 92LL);
abort();
}
clear_rFramework((__int64)v0);
}

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

v0 = calloc(1uLL, 0x20uLL);
if ( !v0 )
{
perror("calloc failure");
fprintf(stderr, "Malloc failure @ %s:%d\n", "framework.c", 92LL);
abort();
}
func2((__int64)v0);
}

original_code:
R_FRAMEWORK *init_rFramework( void )
{
   R_FRAMEWORK *rFrame;
   do { if (!((rFrame) = (R_FRAMEWORK *) calloc ((1), sizeof(R_FRAMEWORK)))) { perror("calloc failure"); fprintf(stderr, "Malloc failure @ %s:%d\n", "framework.c", 92 ); abort(); } } while(0);
   clear_rFramework( rFrame );
   return rFrame;
}

canonical_original_code:
struct room_framework *init_rFramework()
{
   struct room_framework *rFrame;
   do { if (!((rFrame) = (struct room_framework *) calloc ((1), sizeof(R_FRAMEWORK)))) { perror("calloc failure"); fprintf(stderr, "Malloc failure @ %s:%d\n", "framework.c", 92 ); abort(); } } while(0);
   clear_rFramework( rFrame );
   return rFrame;
}

return_type: struct room_framework { struct framework { void *content; int type; struct instance_id { int id; char *created_by; char *created_on; char *modified_by; char *last_modified; } *id; char *name; char *short_descr; char *long_descr; } *container; char *title; char *description; unsigned char inside; } *


decompiled_code:
__int64 create_rFramework()
{
__int64 v0; // rax
__int64 v1; // r12

init_rFramework();
v1 = v0;
*(_QWORD *)(v0 + 8) = strdup("A new room");
*(_QWORD *)(v1 + 16) = strdup("none");
return v1;
}

original_code:
R_FRAMEWORK *create_rFramework( void )
{
   R_FRAMEWORK *rFrame = init_rFramework();;
   rFrame->title = strdup( "A new room" );
   rFrame->description = strdup( "none" );
   return rFrame;
}

canonical_original_code:
struct room_framework *create_rFramework()
{
   struct room_framework *rFrame = init_rFramework();;
   rFrame->title = strdup( "A new room" );
   rFrame->description = strdup( "none" );
   return rFrame;
}

user_defined_types: struct instance_id { int id; char *created_by; char *created_on; char *modified_by; char *last_modified; }


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

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

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

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

original_code:
void free_rFramework( R_FRAMEWORK *rFrame )
{
   rFrame->container = ((void *)0);
   if( rFrame->title )
      free( rFrame->title );
   if( rFrame->description )
      free( rFrame->description );
   free( rFrame );
}

canonical_original_code:
void free_rFramework(struct room_framework *rFrame)
{
   rFrame->container = ((void *)0);
   if( rFrame->title )
      free( rFrame->title );
   if( rFrame->description )
      free( rFrame->description );
   free( rFrame );
}


decompiled_code:
void __fastcall free_framework(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 4);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 5);
if ( v4 )
free(v4);
if ( !*((_DWORD *)ptr + 2) )
free_rFramework(*(void **)ptr);
if ( *((_QWORD *)ptr + 2) )
free_i_id();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 4);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 5);
if ( v4 )
free(v4);
if ( !*((_DWORD *)ptr + 2) )
func5(*(void **)ptr);
if ( *((_QWORD *)ptr + 2) )
free_i_id();
free(ptr);
}

original_code:
void free_framework( FRAMEWORK *frame )
{
   if( frame->name )
      free(frame->name);
   if( frame->short_descr )
      free(frame->short_descr);
   if( frame->long_descr )
      free(frame->long_descr);
   switch( frame->type )
   {
      case FRAMEWORK_ROOM:
         free_rFramework( (R_FRAMEWORK *)frame->content );
         break;
   }
   if( frame->id )
      free_i_id( frame->id );
   free( frame );
   return;
}

canonical_original_code:
void free_framework(struct framework *frame)
{
   if( frame->name )
      free(frame->name);
   if( frame->short_descr )
      free(frame->short_descr);
   if( frame->long_descr )
      free(frame->long_descr);
   switch( frame->type )
   {
      case FRAMEWORK_ROOM:
         free_rFramework( (struct room_framework *)frame->content );
         break;
   }
   if( frame->id )
      free_i_id( frame->id );
   free( frame );
   return;
}

variable_types: struct framework { void *content; int type; struct instance_id { int id; char *created_by; char *created_on; char *modified_by; char *last_modified; } *id; char *name; char *short_descr; char *long_descr; } *


decompiled_code:
__int64 __fastcall get_frame(int a1, int a2)
{
__int64 v2; // rax
__int64 v4; // [rsp+8h] [rbp-30h]
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

AttachIterator(v5, all_frameworks);
do
v2 = NextInList(v5);
while ( v2 && (*(_DWORD *)(v2 + 8) != a1 || **(_DWORD **)(v2 + 16) != a2) );
v4 = v2;
DetachIterator(v5);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2)
{
__int64 v2; // rax
__int64 v4; // [rsp+8h] [rbp-30h]
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

AttachIterator(v5, all_frameworks);
do
v2 = NextInList(v5);
while ( v2 && (*(_DWORD *)(v2 + 8) != a1 || **(_DWORD **)(v2 + 16) != a2) );
v4 = v2;
DetachIterator(v5);
return v4;
}

original_code:
FRAMEWORK *get_frame( int type, int id )
{
   FRAMEWORK *frame;
   ITERATOR Iter;
   AttachIterator( &Iter, all_frameworks );
   while( ( frame = (FRAMEWORK *)NextInList( &Iter ) ) != ((void *)0) )
      if( frame->type == type && frame->id->id == id )
         break;
   DetachIterator( &Iter );
   return frame;
}

canonical_original_code:
struct framework *get_frame(int type, int id)
{
   struct framework *frame;
   struct Iterator Iter;
   AttachIterator( &Iter, all_frameworks );
   while( ( frame = (struct framework *)NextInList( &Iter ) ) != ((void *)0) )
      if( frame->type == type && frame->id->id == id )
         break;
   DetachIterator( &Iter );
   return frame;
}

variable_types: type int

variable_types: id int

return_type: struct framework { void *content; int type; struct instance_id { int id; char *created_by; char *created_on; char *modified_by; char *last_modified; } *id; char *name; char *short_descr; char *long_descr; } *


decompiled_code:
bool __fastcall valid_ftype(unsigned int a1)
{
return a1 <= 1;
}

canonical_decompiled_code:
bool __fastcall func15(unsigned int a1)
{
return a1 <= 1;
}

original_code:
bool valid_ftype( int type )
{
   if( type >= MAX_FRAMEWORK || type < 0 )
      return 0;
   return 1;
}

canonical_original_code:
unsigned char valid_ftype(int type)
{
   if( type >= MAX_FRAMEWORK || type < 0 )
      return 0;
   return 1;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall check_frame_name(char *s2)
{
__int64 v1; // rax
unsigned int v2; // er12
_BYTE v4[40]; // [rsp+0h] [rbp-28h] BYREF

AttachIterator(v4, all_frameworks);
do
{
v1 = NextInList(v4);
if ( !v1 )
{
v2 = 0;
goto LABEL_5;
}
}
while ( strcmp(*(const char **)(v1 + 24), s2) );
v2 = 1;
LABEL_5:
DetachIterator(v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func17(char *s2)
{
__int64 v1; // rax
unsigned int v2; // er12
_BYTE v4[40]; // [rsp+0h] [rbp-28h] BYREF

AttachIterator(v4, all_frameworks);
do
{
v1 = NextInList(v4);
if ( !v1 )
{
v2 = 0;
goto LABEL_5;
}
}
while ( strcmp(*(const char **)(v1 + 24), s2) );
v2 = 1;
LABEL_5:
DetachIterator(v4);
return v2;
}

original_code:
bool check_frame_name( const char *name )
{
   FRAMEWORK *fWork;
   ITERATOR Iter;
   bool found = 0;
   AttachIterator( &Iter, all_frameworks );
   while( ( fWork = (FRAMEWORK *)NextInList( &Iter ) ) != ((void *)0) )
      if( !strcmp( fWork->name, name ) )
      {
         found = 1;
         break;
      }
   DetachIterator( &Iter );
   return found;
}

canonical_original_code:
unsigned char check_frame_name(char *name)
{
   struct framework *fWork;
   struct Iterator Iter;
   unsigned char found = 0;
   AttachIterator( &Iter, all_frameworks );
   while( ( fWork = (struct framework *)NextInList( &Iter ) ) != ((void *)0) )
      if( !strcmp( fWork->name, name ) )
      {
         found = 1;
         break;
      }
   DetachIterator( &Iter );
   return found;
}

variable_types:
name
char *

variable_types:
found
unsigned char


decompiled_code:
void __fastcall set_rFramework(__int64 a1, const char *a2, int a3)
{
void *v4; // rdi

if ( a3 == 3 )
{
v4 = *(void **)(a1 + 8);
if ( v4 )
free(v4);
*(_QWORD *)(a1 + 8) = strdup(a2);
}
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1, const char *a2, int a3)
{
void *v4; // rdi

if ( a3 == 3 )
{
v4 = *(void **)(a1 + 8);
if ( v4 )
free(v4);
*(_QWORD *)(a1 + 8) = strdup(a2);
}
}

original_code:
void set_rFramework( R_FRAMEWORK *rFrame, VALUE value, int type )
{
   switch( type )
   {
      case RFRAME_TITLE:
         if( rFrame->title )
            free( rFrame->title );
         rFrame->title = strdup( (char *)value );
         break;
   }
   return;
}

canonical_original_code:
void set_rFramework(struct room_framework *rFrame, unsigned long value, int type)
{
   switch( type )
   {
      case RFRAME_TITLE:
         if( rFrame->title )
            free( rFrame->title );
         rFrame->title = strdup( (char *)value );
         break;
   }
   return;
}

variable_types:
value
unsigned long


decompiled_code:
int __fastcall set_framework(__int64 a1, const char *a2, int a3)
{
int result; // eax
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi

if ( a3 == 1 )
{
v7 = *(void **)(a1 + 32);
if ( v7 )
free(v7);
*(_QWORD *)(a1 + 32) = strdup(a2);
result = save_framework(a1);
}
else if ( a3 == 2 )
{
v6 = *(void **)(a1 + 40);
if ( v6 )
free(v6);
*(_QWORD *)(a1 + 40) = strdup(a2);
result = save_framework(a1);
}
else
{
if ( a3 )
{
if ( *(_DWORD *)(a1 + 8) )
return bug("%s: bad framework type.", "set_framework");
set_rFramework(*(_QWORD *)a1, a2, a3);
}
v5 = *(void **)(a1 + 24);
if ( v5 )
free(v5);
*(_QWORD *)(a1 + 24) = strdup(a2);
result = save_framework(a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func19(__int64 a1, const char *a2, int a3)
{
int result; // eax
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi

if ( a3 == 1 )
{
v7 = *(void **)(a1 + 32);
if ( v7 )
free(v7);
*(_QWORD *)(a1 + 32) = strdup(a2);
result = func10(a1);
}
else if ( a3 == 2 )
{
v6 = *(void **)(a1 + 40);
if ( v6 )
free(v6);
*(_QWORD *)(a1 + 40) = strdup(a2);
result = func10(a1);
}
else
{
if ( a3 )
{
if ( *(_DWORD *)(a1 + 8) )
return bug("%s: bad framework type.", "set_framework");
func18(*(_QWORD *)a1, a2, a3);
}
v5 = *(void **)(a1 + 24);
if ( v5 )
free(v5);
*(_QWORD *)(a1 + 24) = strdup(a2);
result = func10(a1);
}
return result;
}

original_code:
void set_framework( FRAMEWORK *frame, VALUE value, int type )
{
   switch( type )
   {
      default:
         switch( frame->type )
         {
            default:
               bug( "%s: bad framework type.", __FUNCTION__ );
               return;
            case FRAMEWORK_ROOM:
               set_rFramework( (R_FRAMEWORK *)frame->content, value, type );
               break;
         }
      case FRAME_NAME:
         if( frame->name )
            free( frame->name );
         frame->name = strdup( (char * )value );
         break;
      case FRAME_SHORT_DESCR:
         if( frame->short_descr )
            free( frame->short_descr );
         frame->short_descr = strdup( (char *)value );
         break;
      case FRAME_LONG_DESCR:
         if( frame->long_descr )
            free( frame->long_descr );
         frame->long_descr = strdup( (char *)value );
         break;
   }
   save_framework( frame );
   return;
}

canonical_original_code:
void set_framework(struct framework *frame, unsigned long value, int type)
{
   switch( type )
   {
      default:
         switch( frame->type )
         {
            default:
               bug( "%s: bad framework type.", __FUNCTION__ );
               return;
            case FRAMEWORK_ROOM:
               set_rFramework( (struct room_framework *)frame->content, value, type );
               break;
         }
      case FRAME_NAME:
         if( frame->name )
            free( frame->name );
         frame->name = strdup( (char * )value );
         break;
      case FRAME_SHORT_DESCR:
         if( frame->short_descr )
            free( frame->short_descr );
         frame->short_descr = strdup( (char *)value );
         break;
      case FRAME_LONG_DESCR:
         if( frame->long_descr )
            free( frame->long_descr );
         frame->long_descr = strdup( (char *)value );
         break;
   }
   save_framework( frame );
   return;
}


AllocList

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

result = malloc(0x20uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 6) = 1;
return result;
}

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

result = malloc(0x20uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 6) = 1;
return result;
}

original_code:
LIST *AllocList()
{
  LIST *pList;
  pList = malloc(sizeof(*pList));
  pList->_pFirstCell = ((void *)0);
  pList->_pLastCell = ((void *)0);
  pList->_iterators = 0;
  pList->_valid = 1;
  pList->_size = 0;
  return pList;
}

canonical_original_code:
struct List *AllocList()
{
  struct List *pList;
  pList = malloc(sizeof(*pList));
  pList->_pFirstCell = ((void *)0);
  pList->_pLastCell = ((void *)0);
  pList->_iterators = 0;
  pList->_valid = 1;
  pList->_size = 0;
  return pList;
}

variable_types: struct List { struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; } *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; } *


AllocCell

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

result = malloc(0x20uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 6) = 1;
return result;
}

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

result = malloc(0x20uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 6) = 1;
return result;
}

original_code:
CELL *AllocCell()
{
  CELL *pCell;
  pCell = malloc(sizeof(*pCell));
  pCell->_pNextCell = ((void *)0);
  pCell->_pPrevCell = ((void *)0);
  pCell->_pContent = ((void *)0);
  pCell->_valid = 1;
  return pCell;
}

canonical_original_code:
struct Cell *AllocCell()
{
  struct Cell *pCell;
  pCell = malloc(sizeof(*pCell));
  pCell->_pNextCell = ((void *)0);
  pCell->_pPrevCell = ((void *)0);
  pCell->_pContent = ((void *)0);
  pCell->_valid = 1;
  return pCell;
}

variable_types: struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; } *


FreeCell

decompiled_code:
void __fastcall FreeCell(void *ptr, __int64 a2)
{
__int64 v2; // rax
_QWORD *v3; // rdx

v2 = *(_QWORD *)ptr;
if ( *(void **)a2 == ptr )
{
*(_QWORD *)a2 = v2;
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( *(void **)(a2 + 8) != ptr )
goto LABEL_3;
}
else
{
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( *(void **)(a2 + 8) != ptr )
goto LABEL_3;
}
*(_QWORD *)(a2 + 8) = v3;
LABEL_3:
if ( v3 )
{
*v3 = v2;
v2 = *(_QWORD *)ptr;
}
if ( v2 )
*(_QWORD *)(v2 + 8) = v3;
free(ptr);
}

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

v2 = *(_QWORD *)ptr;
if ( *(void **)a2 == ptr )
{
*(_QWORD *)a2 = v2;
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( *(void **)(a2 + 8) != ptr )
goto LABEL_3;
}
else
{
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( *(void **)(a2 + 8) != ptr )
goto LABEL_3;
}
*(_QWORD *)(a2 + 8) = v3;
LABEL_3:
if ( v3 )
{
*v3 = v2;
v2 = *(_QWORD *)ptr;
}
if ( v2 )
*(_QWORD *)(v2 + 8) = v3;
free(ptr);
}

original_code:
void FreeCell(CELL *pCell, LIST *pList)
{
  if (pList->_pFirstCell == pCell)
    pList->_pFirstCell = pCell->_pNextCell;
  if (pList->_pLastCell == pCell)
    pList->_pLastCell = pCell->_pPrevCell;
  if (pCell->_pPrevCell != ((void *)0))
    pCell->_pPrevCell->_pNextCell = pCell->_pNextCell;
  if (pCell->_pNextCell != ((void *)0))
    pCell->_pNextCell->_pPrevCell = pCell->_pPrevCell;
  free(pCell);
}

canonical_original_code:
void FreeCell(struct Cell *pCell, struct List *pList)
{
  if (pList->_pFirstCell == pCell)
    pList->_pFirstCell = pCell->_pNextCell;
  if (pList->_pLastCell == pCell)
    pList->_pLastCell = pCell->_pPrevCell;
  if (pCell->_pPrevCell != ((void *)0))
    pCell->_pPrevCell->_pNextCell = pCell->_pNextCell;
  if (pCell->_pNextCell != ((void *)0))
    pCell->_pNextCell->_pPrevCell = pCell->_pPrevCell;
  free(pCell);
}

variable_types: struct List { struct Cell *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; } *


FreeList

decompiled_code:
void __fastcall FreeList(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 4) > 0 )
{
*((_DWORD *)ptr + 6) = 0;
}
else
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
FreeCell(v3, (__int64)ptr);
}
while ( v2 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 4) > 0 )
{
*((_DWORD *)ptr + 6) = 0;
}
else
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
func3(v3, (__int64)ptr);
}
while ( v2 );
}
free(ptr);
}
}

original_code:
void FreeList(LIST *pList)
{
  CELL *pCell, *pNextCell;
  if (pList->_iterators > 0)
  {
    pList->_valid = 0;
    return;
  }
  for (pCell = pList->_pFirstCell; pCell != ((void *)0); pCell = pNextCell)
  {
    pNextCell = pCell->_pNextCell;
    FreeCell(pCell, pList);
  }
  free(pList);
}

canonical_original_code:
void FreeList(struct List *pList)
{
  struct Cell *pCell; struct Cell *pNextCell;
  if (pList->_iterators > 0)
  {
    pList->_valid = 0;
    return;
  }
  for (pCell = pList->_pFirstCell; pCell != ((void *)0); pCell = pNextCell)
  {
    pNextCell = pCell->_pNextCell;
    FreeCell(pCell, pList);
  }
  free(pList);
}


DetachIterator

decompiled_code:
void __fastcall DetachIterator(_DWORD **a1)
{
_DWORD *v1; // rbp
int v2; // eax
_QWORD *v3; // rbx
_DWORD *v4; // rdi

v1 = *a1;
if ( *a1 )
{
v2 = v1[4] - 1;
v1[4] = v2;
if ( v2 <= 0 )
{
v3 = *(_QWORD **)v1;
while ( v3 )
{
while ( 1 )
{
v4 = v3;
v3 = (_QWORD *)*v3;
if ( v4[6] )
break;
FreeCell(v4, (__int64)v1);
if ( !v3 )
goto LABEL_8;
}
}
LABEL_8:
if ( !v1[6] )
FreeList(v1);
}
}
}

original_code:
void DetachIterator(ITERATOR *pIter)
{
  LIST *pList = pIter->_pList;
  if (pList != ((void *)0))
  {
    pList->_iterators--;
    if (pList->_iterators <= 0)
    {
      CELL *pCell, *pNextCell;
      for (pCell = pList->_pFirstCell; pCell != ((void *)0); pCell = pNextCell)
      {
        pNextCell = pCell->_pNextCell;
        if (!pCell->_valid)
          FreeCell(pCell, pList);
      }
      if (!pList->_valid)
        FreeList(pList);
    }
  }
}

canonical_original_code:
void DetachIterator(struct Iterator *pIter)
{
  struct List *pList = pIter->_pList;
  if (pList != ((void *)0))
  {
    pList->_iterators--;
    if (pList->_iterators <= 0)
    {
      struct Cell *pCell; struct Cell *pNextCell;
      for (pCell = pList->_pFirstCell; pCell != ((void *)0); pCell = pNextCell)
      {
        pNextCell = pCell->_pNextCell;
        if (!pCell->_valid)
          FreeCell(pCell, pList);
      }
      if (!pList->_valid)
        FreeList(pList);
    }
  }
}

variable_types: struct Iterator { struct List { struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; } *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; } *_pList; struct Cell *_pCell; } *


InvalidateCell

decompiled_code:
void __fastcall InvalidateCell(__int64 a1)
{
*(_DWORD *)(a1 + 24) = 0;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
*(_DWORD *)(a1 + 24) = 0;
}

original_code:
void InvalidateCell(CELL *pCell)
{
  pCell->_valid = 0;
}

canonical_original_code:
void InvalidateCell(struct Cell *pCell)
{
  pCell->_valid = 0;
}


NextInList

original_code:
void *NextInList(ITERATOR *pIter)
{
  void *pContent = ((void *)0);
  while (pIter->_pCell != ((void *)0) && !pIter->_pCell->_valid)
  {
    pIter->_pCell = pIter->_pCell->_pNextCell;
  }
  if (pIter->_pCell != ((void *)0))
  {
    pContent = pIter->_pCell->_pContent;
    pIter->_pCell = pIter->_pCell->_pNextCell;
  }
  return pContent;
}

canonical_original_code:
void *NextInList(struct Iterator *pIter)
{
  void *pContent = ((void *)0);
  while (pIter->_pCell != ((void *)0) && !pIter->_pCell->_valid)
  {
    pIter->_pCell = pIter->_pCell->_pNextCell;
  }
  if (pIter->_pCell != ((void *)0))
  {
    pContent = pIter->_pCell->_pContent;
    pIter->_pCell = pIter->_pCell->_pNextCell;
  }
  return pContent;
}

variable_types:
pContent
void *


SizeOfList

decompiled_code:
__int64 __fastcall SizeOfList(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int SizeOfList(LIST *pList)
{
  return pList->_size;
}

canonical_original_code:
int SizeOfList(struct List *pList)
{
  return pList->_size;
}


decompiled_code:
void __fastcall free_i_id(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void free_i_id( I_ID *id )
{
   free(id->created_by);
   free(id->created_on);
   free(id->modified_by);
   free(id->last_modified);
   free(id);
}

canonical_original_code:
void free_i_id(struct instance_id *id)
{
   free(id->created_by);
   free(id->created_on);
   free(id->modified_by);
   free(id->last_modified);
   free(id);
}

variable_types: struct instance_id { int id; char *created_by; char *created_on; char *modified_by; char *last_modified; } *


decompiled_code:
void __fastcall free_id_handler(void *ptr)
{
_BYTE v1[24]; // [rsp+0h] [rbp-18h] BYREF

DetachFromList(ptr, id_handlers);
AttachIterator(v1, *(_QWORD *)ptr);
while ( !NextInList(v1) )
free_i_id(0LL);
DetachIterator(v1);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_BYTE v1[24]; // [rsp+0h] [rbp-18h] BYREF

DetachFromList(ptr, id_handlers);
AttachIterator(v1, *(_QWORD *)ptr);
while ( !NextInList(v1) )
func0(0LL);
DetachIterator(v1);
free(ptr);
}

original_code:
void free_id_handler( ID_HANDLER *handler )
{
   I_ID *id;
   ITERATOR Iter;
   DetachFromList( handler, id_handlers );
   AttachIterator( &Iter, handler->free_ids );
   while ( ( id = (I_ID *)NextInList(&Iter) ) == ((void *)0) )
      free_i_id( id );
   DetachIterator( &Iter );
   free( handler );
   return;
}

canonical_original_code:
void free_id_handler(struct id_handler *handler)
{
   struct instance_id *id;
   struct Iterator Iter;
   DetachFromList( handler, id_handlers );
   AttachIterator( &Iter, handler->free_ids );
   while ( ( id = (struct instance_id *)NextInList(&Iter) ) == ((void *)0) )
      free_i_id( id );
   DetachIterator( &Iter );
   free( handler );
   return;
}

variable_types: struct id_handler { struct List { struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; } *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; } *free_ids; int type; int top_id; } *

variable_types: struct Iterator { struct List { struct Cell { struct Cell *_pNextCell; struct Cell *_pPrevCell; void *_pContent; int _valid; } *_pFirstCell; struct Cell *_pLastCell; int _iterators; int _size; int _valid; } *_pList; struct Cell *_pCell; }

user_defined_types: struct id_handler { struct List *free_ids; int type; int top_id; }