decompiled_code:
__int64 __fastcall dict_add_double(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, double a5, double a6)
{
if ( *(_BYTE *)(a1 + 8) == 2 )
return dict_add_object(a1, a2, a3, *(__int64 *)&a5, 0LL, a4, a6);
puts("Incompatible Dict Addition");
return 4294967293LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, double a5, double a6)
{
if ( *(_BYTE *)(a1 + 8) == 2 )
return func3(a1, a2, a3, *(__int64 *)&a5, 0LL, a4, a6);
puts("Incompatible Dict Addition");
return 4294967293LL;
}

original_code:
int dict_add_double(dict *d,char *key,int klen,double value,int flag,double expiry)
{
    if(d->type != 2)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    vr_object obj;
    obj.value = value;
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

canonical_original_code:
int dict_add_double(struct dict_ *d, char *key, int klen, double value, int flag, double expiry)
{
    if(d->type != 2)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    union vr_object obj;
    obj.value = value;
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

variable_types: value double

variable_types: union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; }


repo: vighneshbirodkar/vigredis

decompiled_code:
__int64 __fastcall dict_add_string(__int64 a1, __int64 a2, unsigned int a3, const char *a4, unsigned int a5, unsigned int a6, double a7)
{
size_t v7; // r12
char *v11; // rax
char *v12; // rax
__int64 result; // rax
__int64 v14; // [rsp+0h] [rbp-48h]

if ( *(_BYTE *)(a1 + 8) == 1 )
{
v7 = (int)a5;
v14 = a5;
v11 = (char *)malloc((int)a5);
v12 = strncpy(v11, a4, v7);
result = dict_add_object(a1, a2, a3, v14, (__int64)v12, a6, a7);
}
else
{
puts("Incompatible Dict Addition");
result = 4294967293LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3, const char *a4, unsigned int a5, unsigned int a6, double a7)
{
size_t v7; // r12
char *v11; // rax
char *v12; // rax
__int64 result; // rax
__int64 v14; // [rsp+0h] [rbp-48h]

if ( *(_BYTE *)(a1 + 8) == 1 )
{
v7 = (int)a5;
v14 = a5;
v11 = (char *)malloc((int)a5);
v12 = strncpy(v11, a4, v7);
result = func3(a1, a2, a3, v14, (__int64)v12, a6, a7);
}
else
{
puts("Incompatible Dict Addition");
result = 4294967293LL;
}
return result;
}

original_code:
int dict_add_string(dict *d,char* key,int klen,char* value,int vlen,int flag,double expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    vr_object obj;
    obj.string.len = vlen;
    obj.string.string = (char*)malloc(sizeof(char)*vlen);
    strncpy(obj.string.string,value,vlen);
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

canonical_original_code:
int dict_add_string(struct dict_ *d, char *key, int klen, char *value, int vlen, int flag, double expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    union vr_object obj;
    obj.string.len = vlen;
    obj.string.string = (char *)malloc(sizeof(char)*vlen);
    strncpy(obj.string.string,value,vlen);
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

variable_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *table; } *

variable_types:
key
char *

variable_types: klen int

variable_types:
value
char *

variable_types: vlen int

variable_types: flag int

variable_types: expiry double

return_type: int

user_defined_types: union vr_object { double value; struct set *obj_set; struct vr_string string; }

user_defined_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list *table; }

user_defined_types: struct set { struct dict_ set_dict; struct skip_list set_list; int len; }

user_defined_types: struct list { char type; unsigned int len; struct list_node *root; }

user_defined_types: struct skip_list { struct skip_list_node *header; int level; }

user_defined_types: struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; }


decompiled_code:
__int64 __fastcall dict_set_bit(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, char a5, _QWORD *a6)
{
unsigned int v10; // edx
__int64 v11; // rax
__int64 v12; // rdx
unsigned int v14; // er12
__int64 v15; // [rsp+0h] [rbp-48h] BYREF
__int64 v16; // [rsp+8h] [rbp-40h]

v10 = (unsigned int)hash_string_32(a2, a3) % *(_DWORD *)(a1 + 4);
if ( *(_BYTE *)(a1 + 8) == 1 )
{
v11 = list_find(*(_QWORD *)(a1 + 16) + 16LL * v10, a2, a3);
v12 = (unsigned int)a5;
if ( v11 )
{
*a6 = *(_QWORD *)(v11 + 40);
return string_set_bit(v11 + 24, a4, v12);
}
v16 = 0LL;
LODWORD(v15) = 0;
v14 = string_set_bit(&v15, a4, v12);
dict_add_object(a1, a2, a3, v15, v16, 0, -1.0);
}
else
{
v14 = -3;
puts("Incompatible Dict Operation");
}
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, char a5, _QWORD *a6)
{
unsigned int v10; // edx
__int64 v11; // rax
__int64 v12; // rdx
unsigned int v14; // er12
__int64 v15; // [rsp+0h] [rbp-48h] BYREF
__int64 v16; // [rsp+8h] [rbp-40h]

v10 = (unsigned int)hash_string_32(a2, a3) % *(_DWORD *)(a1 + 4);
if ( *(_BYTE *)(a1 + 8) == 1 )
{
v11 = list_find(*(_QWORD *)(a1 + 16) + 16LL * v10, a2, a3);
v12 = (unsigned int)a5;
if ( v11 )
{
*a6 = *(_QWORD *)(v11 + 40);
return string_set_bit(v11 + 24, a4, v12);
}
v16 = 0LL;
LODWORD(v15) = 0;
v14 = string_set_bit(&v15, a4, v12);
func3(a1, a2, a3, v15, v16, 0, -1.0);
}
else
{
v14 = -3;
puts("Incompatible Dict Operation");
}
return v14;
}

original_code:
int dict_set_bit(dict *d,char* key,int klen,int n,char b,double* expiry)
{
    list_node* tmp;
    int ret;
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    if(d->type != 1)
    {
        printf("Incompatible Dict Operation\n");
        return -3;
    }
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return string_set_bit(&tmp->object.string,n,b);
    }
    else
    {
        vr_object obj;
        obj.string.string = ((void *)0);
        obj.string.len = 0;
        ret = string_set_bit(&obj.string,n,b);
        dict_add_object(d,key,klen,obj,0,-1);
        return ret;
    }
}

canonical_original_code:
int dict_set_bit(struct dict_ *d, char *key, int klen, int n, char b, double *expiry)
{
    struct list_node *tmp;
    int ret;
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    if(d->type != 1)
    {
        printf("Incompatible Dict Operation\n");
        return -3;
    }
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return string_set_bit(&tmp->object.string,n,b);
    }
    else
    {
        union vr_object obj;
        obj.string.string = ((void *)0);
        obj.string.len = 0;
        ret = string_set_bit(&obj.string,n,b);
        dict_add_object(d,key,klen,obj,0,-1);
        return ret;
    }
}

variable_types: n int

variable_types: b char

variable_types:
expiry
double *

variable_types: struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *

variable_types: ret int

variable_types:
hash
unsigned int

variable_types:
index
unsigned int


original_code:
void dict_contract(dict *d)
{
    list* old_table = d->table;
    uint32_t old_size = d->size;
    uint32_t i;
    uint32_t new_size = 8;
    list_node *tmp,*current;
    while(new_size < d->len)
        new_size *= 2;
    d->table = (list*)malloc(sizeof(list)*new_size);
    d->size = new_size;
    d->len = 0;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],d->type);
    for(i=0;i < old_size;i++)
    {
        current = old_table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            dict_add_object(d,tmp->key,tmp->klen,tmp->object,0,tmp->expiry);
            free(tmp->key);
            free(tmp);
        }
    }
    free(old_table);
}

canonical_original_code:
void dict_contract(struct dict_ *d)
{
    struct list *old_table = d->table;
    unsigned int old_size = d->size;
    unsigned int i;
    unsigned int new_size = 8;
    struct list_node *tmp; struct list_node *current;
    while(new_size < d->len)
        new_size *= 2;
    d->table = (struct list *)malloc(sizeof(list)*new_size);
    d->size = new_size;
    d->len = 0;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],d->type);
    for(i=0;i < old_size;i++)
    {
        current = old_table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            dict_add_object(d,tmp->key,tmp->klen,tmp->object,0,tmp->expiry);
            free(tmp->key);
            free(tmp);
        }
    }
    free(old_table);
}

variable_types: struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *

variable_types:
i
unsigned int

return_type: void


decompiled_code:
__int64 __fastcall dict_delete(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // er12
unsigned int v6; // edx

v4 = hash_string_32(a2, a3);
v5 = list_delete_object(16LL * (v4 % *(_DWORD *)(a1 + 4)) + *(_QWORD *)(a1 + 16), a2, a3);
if ( v5 == -1 )
{
v6 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v6;
}
else
{
v6 = *(_DWORD *)a1;
}
if ( *(_DWORD *)(a1 + 4) / 0xAu > v6 )
dict_contract(a1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // er12
unsigned int v6; // edx

v4 = hash_string_32(a2, a3);
v5 = list_delete_object(16LL * (v4 % *(_DWORD *)(a1 + 4)) + *(_QWORD *)(a1 + 16), a2, a3);
if ( v5 == -1 )
{
v6 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v6;
}
else
{
v6 = *(_DWORD *)a1;
}
if ( *(_DWORD *)(a1 + 4) / 0xAu > v6 )
func7(a1);
return v5;
}

original_code:
int dict_delete(dict *d,char *key,int klen)
{
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object(&d->table[index],key,klen);
    if( ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

canonical_original_code:
int dict_delete(struct dict_ *d, char *key, int klen)
{
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object(&d->table[index],key,klen);
    if( ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

user_defined_types: struct vr_string { int len; char *string; }

user_defined_types: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; }


decompiled_code:
__int64 __fastcall dict_delete_ife(__int64 a1, __int64 a2, unsigned int a3, double a4)
{
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // edx

v5 = hash_string_32(a2, a3);
v6 = list_delete_object_ife(16LL * (v5 % *(_DWORD *)(a1 + 4)) + *(_QWORD *)(a1 + 16), a2, a3, a4);
if ( v6 == -1 )
{
v7 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v7;
}
else
{
v7 = *(_DWORD *)a1;
}
if ( *(_DWORD *)(a1 + 4) / 0xAu > v7 )
dict_contract(a1);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned int a3, double a4)
{
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // edx

v5 = hash_string_32(a2, a3);
v6 = list_delete_object_ife(16LL * (v5 % *(_DWORD *)(a1 + 4)) + *(_QWORD *)(a1 + 16), a2, a3, a4);
if ( v6 == -1 )
{
v7 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v7;
}
else
{
v7 = *(_DWORD *)a1;
}
if ( *(_DWORD *)(a1 + 4) / 0xAu > v7 )
func7(a1);
return v6;
}

original_code:
int dict_delete_ife(dict *d,char *key,int klen, double time)
{
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object_ife(&d->table[index],key,klen,time);
    if(ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

canonical_original_code:
int dict_delete_ife(struct dict_ *d, char *key, int klen, double time)
{
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object_ife(&d->table[index],key,klen,time);
    if(ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

variable_types: time double


decompiled_code:
__int64 __fastcall dict_print(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // er12
__int64 *v3; // rbx

printf("Length = %u\n", *a1);
result = a1[1];
if ( (_DWORD)result )
{
v2 = 0;
while ( 1 )
{
result = *((_QWORD *)a1 + 2) + 16LL * v2;
v3 = *(__int64 **)(result + 8);
if ( v3 )
break;
LABEL_12:
if ( a1[1] <= ++v2 )
return result;
}
while ( 1 )
{
while ( 1 )
{
result = *((unsigned __int8 *)a1 + 8);
if ( (_BYTE)result == 1 )
break;
if ( (_BYTE)result == 2 )
goto LABEL_10;
LABEL_6:
if ( (_BYTE)result != 3 )
goto LABEL_7;
LABEL_11:
printf("SET - %.*s\n", *((_DWORD *)v3 + 2), (const char *)v3[2]);
puts("-------------");
result = set_print(v3[3]);
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_12;
}
printf("%.*s : %.*s\n", *((_DWORD *)v3 + 2), (const char *)v3[2], *((_DWORD *)v3 + 6), (const char *)v3[4]);
result = *((unsigned __int8 *)a1 + 8);
if ( (_BYTE)result != 2 )
goto LABEL_6;
LABEL_10:
printf("%.*s : %lf\n", *((_DWORD *)v3 + 2), (const char *)v3[2], *((double *)v3 + 3));
result = *((unsigned __int8 *)a1 + 8);
if ( (_BYTE)result == 3 )
goto LABEL_11;
LABEL_7:
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_12;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // er12
__int64 *v3; // rbx

printf("Length = %u\n", *a1);
result = a1[1];
if ( (_DWORD)result )
{
v2 = 0;
while ( 1 )
{
result = *((_QWORD *)a1 + 2) + 16LL * v2;
v3 = *(__int64 **)(result + 8);
if ( v3 )
break;
LABEL_12:
if ( a1[1] <= ++v2 )
return result;
}
while ( 1 )
{
while ( 1 )
{
result = *((unsigned __int8 *)a1 + 8);
if ( (_BYTE)result == 1 )
break;
if ( (_BYTE)result == 2 )
goto LABEL_10;
LABEL_6:
if ( (_BYTE)result != 3 )
goto LABEL_7;
LABEL_11:
printf("SET - %.*s\n", *((_DWORD *)v3 + 2), (const char *)v3[2]);
puts("-------------");
result = set_print(v3[3]);
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_12;
}
printf("%.*s : %.*s\n", *((_DWORD *)v3 + 2), (const char *)v3[2], *((_DWORD *)v3 + 6), (const char *)v3[4]);
result = *((unsigned __int8 *)a1 + 8);
if ( (_BYTE)result != 2 )
goto LABEL_6;
LABEL_10:
printf("%.*s : %lf\n", *((_DWORD *)v3 + 2), (const char *)v3[2], *((double *)v3 + 3));
result = *((unsigned __int8 *)a1 + 8);
if ( (_BYTE)result == 3 )
goto LABEL_11;
LABEL_7:
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_12;
}
}
return result;
}

original_code:
void dict_print(dict *d)
{
    uint32_t i;
    list_node* tmp ;
    printf("Length = %u\n",d->len);
    for(i=0; i<d->size; i++)
    {
        tmp = (&d->table[i])->root;
        while( tmp != ((void *)0))
        {
            if(d->type == 1)
                printf("%.*s : %.*s\n", (int)tmp->klen, tmp->key , (int)tmp->object.string.len, tmp->object.string.string);
            if(d->type == 2)
                printf("%.*s : %lf\n", (int)tmp->klen, tmp->key , tmp->object.value);
            if(d->type == 3)
            {
                printf("SET - %.*s\n",tmp->klen,tmp->key);
                printf("-------------\n");
                set_print(tmp->object.obj_set);
            }
            tmp = tmp->next;
        }
    }
}

canonical_original_code:
void dict_print(struct dict_ *d)
{
    unsigned int i;
    struct list_node *tmp;
    printf("Length = %u\n",d->len);
    for(i=0; i<d->size; i++)
    {
        tmp = (&d->table[i])->root;
        while( tmp != ((void *)0))
        {
            if(d->type == 1)
                printf("%.*s : %.*s\n", (int)tmp->klen, tmp->key , (int)tmp->object.string.len, tmp->object.string.string);
            if(d->type == 2)
                printf("%.*s : %lf\n", (int)tmp->klen, tmp->key , tmp->object.value);
            if(d->type == 3)
            {
                printf("SET - %.*s\n",tmp->klen,tmp->key);
                printf("-------------\n");
                set_print(tmp->object.obj_set);
            }
            tmp = tmp->next;
        }
    }
}

variable_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *table; } *


decompiled_code:
__int64 __fastcall dict_get(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
unsigned int v6; // eax
__int64 result; // rax
__int64 v8; // xmm0_8

v6 = hash_string_32(a2, a3);
result = list_find(16LL * (v6 % *(_DWORD *)(a1 + 4)) + *(_QWORD *)(a1 + 16), a2, a3);
if ( result )
{
v8 = *(_QWORD *)(result + 40);
result += 24LL;
*a4 = v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
unsigned int v6; // eax
__int64 result; // rax
__int64 v8; // xmm0_8

v6 = hash_string_32(a2, a3);
result = list_find(16LL * (v6 % *(_DWORD *)(a1 + 4)) + *(_QWORD *)(a1 + 16), a2, a3);
if ( result )
{
v8 = *(_QWORD *)(result + 40);
result += 24LL;
*a4 = v8;
}
return result;
}

original_code:
vr_object* dict_get(dict *d,char* key,int klen,double* expiry)
{
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    list_node* tmp;
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return &tmp->object;
    }
    else
        return ((void *)0);
}

canonical_original_code:
union vr_object *dict_get(struct dict_ *d, char *key, int klen, double *expiry)
{
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    struct list_node *tmp;
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return &tmp->object;
    }
    else
        return ((void *)0);
}

variable_types:
d
struct dict_ *

variable_types:
key
char *

return_type: union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } *


decompiled_code:
__int64 __fastcall dict_get_string(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
if ( *(_BYTE *)(a1 + 8) == 1 )
return dict_get(a1, a2, a3, a4);
puts("Incompatible Dict Addition");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
if ( *(_BYTE *)(a1 + 8) == 1 )
return func11(a1, a2, a3, a4);
puts("Incompatible Dict Addition");
return 0LL;
}

original_code:
vr_string* dict_get_string(dict* d,char* key,int klen,double * expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return ((void *)0);
    }
    return &dict_get(d,key,klen,expiry)->string;
}

canonical_original_code:
struct vr_string *dict_get_string(struct dict_ *d, char *key, int klen, double *expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return ((void *)0);
    }
    return &dict_get(d,key,klen,expiry)->string;
}

variable_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string string; } object; double expiry; } *root; } *table; } *

variable_types: klen int

return_type: struct vr_string { int len; char *string; } *


decompiled_code:
void __fastcall dict_delete_expired(__int64 a1, __int64 a2)
{
double v2; // r14
__int64 v3; // rbp

v2 = get_time_ms();
while ( v2 > skip_list_first(a2) )
{
v3 = skip_list_pop(a2);
dict_delete_ife(a1, *(_QWORD *)(v3 + 16), *(_DWORD *)(v3 + 24), v2);
free(*(void **)(v3 + 16));
free(*(void **)(v3 + 8));
free((void *)v3);
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int64 a2)
{
double v2; // r14
__int64 v3; // rbp

v2 = get_time_ms();
while ( v2 > skip_list_first(a2) )
{
v3 = skip_list_pop(a2);
func9(a1, *(_QWORD *)(v3 + 16), *(_DWORD *)(v3 + 24), v2);
free(*(void **)(v3 + 16));
free(*(void **)(v3 + 8));
free((void *)v3);
}
}

original_code:
void dict_delete_expired(dict *d,skip_list* sl)
{
    double time = get_time_ms();
    skip_list_node* tmp;
    while( (time > skip_list_first(sl) ))
    {
        tmp = skip_list_pop(sl);
        dict_delete_ife(d,tmp->key,tmp->klen,time);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
}

canonical_original_code:
void dict_delete_expired(struct dict_ *d, struct skip_list *sl)
{
    double time = get_time_ms();
    struct skip_list_node *tmp;
    while( (time > skip_list_first(sl) ))
    {
        tmp = skip_list_pop(sl);
        dict_delete_ife(d,tmp->key,tmp->klen,time);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
}

variable_types:
sl
struct skip_list *

variable_types: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *


original_code:
void dict_clear(dict *d)
{
    list_node* tmp,*current;
    int i;
    for(i=0;i < d->size;i++)
    {
        current = d->table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            free(tmp->key);
            if(d->type == 1)
            {
                free(tmp->object.string.string);
            }
            if(d->type == 3)
            {
                set_clear(tmp->object.obj_set);
                free(tmp->object.obj_set);
            }
            free(tmp);
        }
    }
    free(d->table);
}

canonical_original_code:
void dict_clear(struct dict_ *d)
{
    struct list_node *tmp; struct list_node *current;
    int i;
    for(i=0;i < d->size;i++)
    {
        current = d->table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            free(tmp->key);
            if(d->type == 1)
            {
                free(tmp->object.string.string);
            }
            if(d->type == 3)
            {
                set_clear(tmp->object.obj_set);
                free(tmp->object.obj_set);
            }
            free(tmp);
        }
    }
    free(d->table);
}

variable_types: i int


decompiled_code:
__int64 random_level()
{
unsigned int i; // er12

for ( i = 1; rand() <= 1073741822 && i != 32; ++i )
;
return i;
}

variable_types: x int


original_code:
void skip_list_insert(skip_list *sl,double score,char* key,int klen)
{
    int i;
    int v;
    skip_list_node* update[32];
    skip_list_node* x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( (x->next[i] != ((void *)0)) && x->next[i]->score < score )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    v = random_level();
    if(v > sl->level)
    {
        for(i=(sl->level );i < v;i++)
            update[i]= sl->header;
        sl->level = v;
    }
    x = (skip_list_node*)malloc(sizeof(skip_list_node));
    x->score = score;
    x->key = (char*)malloc(klen);
    strncpy(x->key,key,klen);
    x->klen = klen;
    x->next = (skip_list_node**)malloc(v*sizeof(char*));
    for(i=0;i < v;i++)
    {
        x->next[i] = update[i]->next[i];
        update[i]->next[i] = x;
    }
}

canonical_original_code:
void skip_list_insert(struct skip_list *sl, double score, char *key, int klen)
{
    int i;
    int v;
    struct skip_list_node *update[32];
    struct skip_list_node *x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( (x->next[i] != ((void *)0)) && x->next[i]->score < score )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    v = random_level();
    if(v > sl->level)
    {
        for(i=(sl->level );i < v;i++)
            update[i]= sl->header;
        sl->level = v;
    }
    x = (struct skip_list_node *)malloc(sizeof(skip_list_node));
    x->score = score;
    x->key = (char *)malloc(klen);
    strncpy(x->key,key,klen);
    x->klen = klen;
    x->next = (struct skip_list_node **)malloc(v*sizeof(char *));
    for(i=0;i < v;i++)
    {
        x->next[i] = update[i]->next[i];
        update[i]->next[i] = x;
    }
}

variable_types: struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } *

variable_types: score double

variable_types: v int

variable_types: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *[32]


decompiled_code:
__int64 __fastcall skip_list_point(_DWORD *a1, double a2)
{
__int64 v2; // rdx
int v3; // esi
__int64 v4; // rcx
unsigned __int64 v5; // rsi
__int64 v6; // rax

v2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v3 = a1[2] - 1;
if ( v3 >= 0 )
{
v4 = 8LL * v3;
v5 = 8 * ((int)a1[2] - (unsigned __int64)(unsigned int)v3) - 16;
do
{
while ( 1 )
{
v6 = *(_QWORD *)(v2 + v4);
if ( !v6 || a2 <= *(double *)v6 )
break;
v2 = *(_QWORD *)(v6 + 8);
}
v4 -= 8LL;
}
while ( v5 != v4 );
}
return *(_QWORD *)v2;
}

original_code:
skip_list_node* skip_list_point(skip_list* sl,double score)
{
    int i;
    skip_list_node* x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
    }
    x = x->next[0];
    return x;
}

canonical_original_code:
struct skip_list_node *skip_list_point(struct skip_list *sl, double score)
{
    int i;
    struct skip_list_node *x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
    }
    x = x->next[0];
    return x;
}

variable_types: struct skip_list { struct skip_list_node *header; int level; } *

return_type: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *


original_code:
void skip_list_delete_with_key(skip_list *sl,double score,char* key,int klen)
{
    skip_list_node* update[32];
    skip_list_node* x = sl->header;
    int i;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    if( x == ((void *)0))
    {
        printf("Fatal : key not found\n");
        return;
    }
    while( (x->next[0] != ((void *)0)) && ( abs(x->score-score) < 0.000000001 ) && (x->klen != klen) && ( strncmp(x->key,key,klen) != 0) )
    {
        x = x->next[0];
    }
    if( (x->klen == klen) && (strncmp(x->key,key,klen) == 0) )
    {
        for(i=0;i < sl->level;i++)
        {
            if( update[i]->next[i] != x)
                break;
            update[i]->next[i] = x->next[i];
        }
        free(x->key);
        free(x->next);
        free(x);
        while( (sl->level > 0) && (sl->header->next[sl->level] == ((void *)0)) )
        {
            sl->level--;
        }
    }
    else
        printf("Fatal : key not found\n");
}

canonical_original_code:
void skip_list_delete_with_key(struct skip_list *sl, double score, char *key, int klen)
{
    struct skip_list_node *update[32];
    struct skip_list_node *x = sl->header;
    int i;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    if( x == ((void *)0))
    {
        printf("Fatal : key not found\n");
        return;
    }
    while( (x->next[0] != ((void *)0)) && ( abs(x->score-score) < 0.000000001 ) && (x->klen != klen) && ( strncmp(x->key,key,klen) != 0) )
    {
        x = x->next[0];
    }
    if( (x->klen == klen) && (strncmp(x->key,key,klen) == 0) )
    {
        for(i=0;i < sl->level;i++)
        {
            if( update[i]->next[i] != x)
                break;
            update[i]->next[i] = x->next[i];
        }
        free(x->key);
        free(x->next);
        free(x);
        while( (sl->level > 0) && (sl->header->next[sl->level] == ((void *)0)) )
        {
            sl->level--;
        }
    }
    else
        printf("Fatal : key not found\n");
}


decompiled_code:
double __fastcall skip_list_first(__int64 a1)
{
double result; // xmm0_8
double *v2; // rax

result = *(double *)&LC1;
v2 = **(double ***)(*(_QWORD *)a1 + 8LL);
if ( v2 )
result = *v2;
return result;
}

canonical_decompiled_code:
double __fastcall func5(__int64 a1)
{
double result; // xmm0_8
double *v2; // rax

result = *(double *)&LC1;
v2 = **(double ***)(*(_QWORD *)a1 + 8LL);
if ( v2 )
result = *v2;
return result;
}

original_code:
double skip_list_first(skip_list* sl)
{
    if(sl->header->next[0])
        return sl->header->next[0]->score;
    else
        return ((double)1.79769313486231570814527423731704357e+308L);
}

canonical_original_code:
double skip_list_first(struct skip_list *sl)
{
    if(sl->header->next[0])
        return sl->header->next[0]->score;
    else
        return ((double)1.79769313486231570814527423731704357e+308L);
}

return_type: double


decompiled_code:
_BOOL8 __fastcall skip_list_empty(__int64 a1)
{
return **(_QWORD **)(*(_QWORD *)a1 + 8LL) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return **(_QWORD **)(*(_QWORD *)a1 + 8LL) == 0LL;
}

original_code:
int skip_list_empty(skip_list* sl)
{
    return (sl->header->next[0] == ((void *)0));
}

canonical_original_code:
int skip_list_empty(struct skip_list *sl)
{
    return (sl->header->next[0] == ((void *)0));
}


original_code:
skip_list_node* skip_list_pop(skip_list *sl)
{
    int i;
    skip_list_node* first = sl->header->next[0];
    for(i=0;i<32;i++)
    {
        if(sl->header->next[i] == first )
            sl->header->next[i] = first->next[0];
    }
    return first;
}

canonical_original_code:
struct skip_list_node *skip_list_pop(struct skip_list *sl)
{
    int i;
    struct skip_list_node *first = sl->header->next[0];
    for(i=0;i<32;i++)
    {
        if(sl->header->next[i] == first )
            sl->header->next[i] = first->next[0];
    }
    return first;
}


decompiled_code:
int __fastcall skip_list_print(__int64 a1)
{
unsigned int v1; // ebp
__int64 i; // rbx
double v3; // xmm0_8
int v4; // er9
__int64 v5; // rdx
__int64 v6; // rsi

v1 = 1;
for ( i = **(_QWORD **)(*(_QWORD *)a1 + 8LL); i; i = **(_QWORD **)(i + 8) )
{
while ( 1 )
{
v3 = *(double *)i;
v4 = *(_DWORD *)(i + 24);
v5 = (unsigned int)(int)*(double *)i;
if ( v3 != (double)(int)v5 )
break;
printf("%d) %d , %.*s \n", v1++, v5, v4, *(const char **)(i + 16));
i = **(_QWORD **)(i + 8);
if ( !i )
return putchar(10);
}
v6 = v1++;
printf("%d) %lf , %.*s \n", v6, v3, v4, *(const char **)(i + 16));
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
unsigned int v1; // ebp
__int64 i; // rbx
double v3; // xmm0_8
int v4; // er9
__int64 v5; // rdx
__int64 v6; // rsi

v1 = 1;
for ( i = **(_QWORD **)(*(_QWORD *)a1 + 8LL); i; i = **(_QWORD **)(i + 8) )
{
while ( 1 )
{
v3 = *(double *)i;
v4 = *(_DWORD *)(i + 24);
v5 = (unsigned int)(int)*(double *)i;
if ( v3 != (double)(int)v5 )
break;
printf("%d) %d , %.*s \n", v1++, v5, v4, *(const char **)(i + 16));
i = **(_QWORD **)(i + 8);
if ( !i )
return putchar(10);
}
v6 = v1++;
printf("%d) %lf , %.*s \n", v6, v3, v4, *(const char **)(i + 16));
}
return putchar(10);
}

original_code:
void skip_list_print(skip_list* sl)
{
    skip_list_node* tmp = sl->header;
    tmp = tmp->next[0];
    int counter = 1;
    int trunc;
    while(tmp != ((void *)0))
    {
        trunc = (int)tmp->score;
        if(trunc == tmp->score)
            printf("%d) %d , %.*s \n",counter,trunc,tmp->klen,tmp->key);
        else
            printf("%d) %lf , %.*s \n",counter,tmp->score,tmp->klen,tmp->key);
        tmp = tmp->next[0];
        counter++;
    }
    printf("\n");
}

canonical_original_code:
void skip_list_print(struct skip_list *sl)
{
    struct skip_list_node *tmp = sl->header;
    tmp = tmp->next[0];
    int counter = 1;
    int trunc;
    while(tmp != ((void *)0))
    {
        trunc = (int)tmp->score;
        if(trunc == tmp->score)
            printf("%d) %d , %.*s \n",counter,trunc,tmp->klen,tmp->key);
        else
            printf("%d) %lf , %.*s \n",counter,tmp->score,tmp->klen,tmp->key);
        tmp = tmp->next[0];
        counter++;
    }
    printf("\n");
}

variable_types: counter int

variable_types: trunc int


decompiled_code:
void __fastcall skip_list_clear(void **a1)
{
void **v1; // rbp

while ( !skip_list_empty((__int64)a1) )
{
v1 = (void **)skip_list_pop((__int64)a1);
free(v1[2]);
free(v1[1]);
free(v1);
}
free(*((void **)*a1 + 1));
free(*a1);
}

original_code:
void skip_list_clear(skip_list* sl)
{
    skip_list_node* tmp;
    while(!skip_list_empty(sl))
    {
        tmp = skip_list_pop(sl);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
    free(sl->header->next);
    free(sl->header);
}

canonical_original_code:
void skip_list_clear(struct skip_list *sl)
{
    struct skip_list_node *tmp;
    while(!skip_list_empty(sl))
    {
        tmp = skip_list_pop(sl);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
    free(sl->header->next);
    free(sl->header);
}


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

dict_init(a1, 2LL);
result = skip_list_init(a1 + 24);
*(_DWORD *)(a1 + 40) = 0;
return result;
}

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

dict_init(a1, 2LL);
result = skip_list_init(a1 + 24);
*(_DWORD *)(a1 + 40) = 0;
return result;
}

original_code:
void set_init(set *s)
{
    dict_init(&s->set_dict,2);
    skip_list_init(&s->set_list);
    s->len = 0;
}

canonical_original_code:
void set_init(struct set *s)
{
    dict_init(&s->set_dict,2);
    skip_list_init(&s->set_list);
    s->len = 0;
}

variable_types: struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *


decompiled_code:
__int64 __fastcall set_add(__int64 a1, __int64 a2, __int64 a3, double a4)
{
unsigned int v4; // er12
double *v5; // rax
unsigned int v6; // er14
char v8[48]; // [rsp+18h] [rbp-30h] BYREF

v4 = a3;
v5 = (double *)dict_get(a1, a2, a3, v8);
if ( v5 )
{
if ( (int)(a4 - *v5) )
{
skip_list_delete_with_key(a1 + 24, a2, v4);
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 != -1 )
puts("Fatal : Key which is supposed to exist, does not exist");
}
else
{
v6 = -1;
}
}
else
{
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 )
puts("Fatal : Key which is not supposed to exists, does exist");
++*(_DWORD *)(a1 + 40);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, double a4)
{
unsigned int v4; // er12
double *v5; // rax
unsigned int v6; // er14
char v8[48]; // [rsp+18h] [rbp-30h] BYREF

v4 = a3;
v5 = (double *)dict_get(a1, a2, a3, v8);
if ( v5 )
{
if ( (int)(a4 - *v5) )
{
skip_list_delete_with_key(a1 + 24, a2, v4);
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 != -1 )
puts("Fatal : Key which is supposed to exist, does not exist");
}
else
{
v6 = -1;
}
}
else
{
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 )
puts("Fatal : Key which is not supposed to exists, does exist");
++*(_DWORD *)(a1 + 40);
}
return v6;
}

original_code:
int set_add(set *s,char* key,int klen,double score)
{
    int ret;
    double exp;
    vr_object *obj;
    obj = dict_get(&s->set_dict,key,klen,&exp);
    if( obj == ((void *)0))
    {
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != 0)
            printf("Fatal : Key which is not supposed to exists, does exist\n");
        s->len = s->len + 1;
    }
    else
    {
        if(( abs(score-obj->value) < 0.000000001 ))
            return -1;
        skip_list_delete_with_key(&s->set_list,obj->value,key,klen);
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != -1)
            printf("Fatal : Key which is supposed to exist, does not exist\n");
    }
    return ret;
}

canonical_original_code:
int set_add(struct set *s, char *key, int klen, double score)
{
    int ret;
    double exp;
    union vr_object *obj;
    obj = dict_get(&s->set_dict,key,klen,&exp);
    if( obj == ((void *)0))
    {
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != 0)
            printf("Fatal : Key which is not supposed to exists, does exist\n");
        s->len = s->len + 1;
    }
    else
    {
        if(( abs(score-obj->value) < 0.000000001 ))
            return -1;
        skip_list_delete_with_key(&s->set_list,obj->value,key,klen);
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != -1)
            printf("Fatal : Key which is supposed to exist, does not exist\n");
    }
    return ret;
}

variable_types: ret int

variable_types: exp double

variable_types: union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } *


decompiled_code:
__int64 __fastcall set_print(__int64 a1)
{
return skip_list_print(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return skip_list_print(a1 + 24);
}

original_code:
void set_print(set* s)
{
    skip_list_print(&s->set_list);
}

canonical_original_code:
void set_print(struct set *s)
{
    skip_list_print(&s->set_list);
}


decompiled_code:
__int64 __fastcall set_clear(__int64 a1)
{
dict_clear();
return skip_list_clear(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
dict_clear();
return skip_list_clear(a1 + 24);
}

original_code:
void set_clear(set *s)
{
    dict_clear(&s->set_dict);
    skip_list_clear(&s->set_list);
}

canonical_original_code:
void set_clear(struct set *s)
{
    dict_clear(&s->set_dict);
    skip_list_clear(&s->set_list);
}


repo: vijkp/Remodel

decompiled_code:
int __fastcall main_dispatch_all_leaf_nodes(__int64 a1)
{
int result; // eax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // rbp
__int64 v8; // rdi
__int64 v9; // rax
__int64 v10; // rbp

if ( !a1 )
_assert_fail("rmnode != NULL", "main.c", 0xBAu, "main_dispatch_all_leaf_nodes");
result = *(_DWORD *)(a1 + 296);
if ( result )
{
v7 = 0LL;
if ( result > 0 )
{
do
{
v8 = *(_QWORD *)(*(_QWORD *)(a1 + 288) + 8 * v7++);
result = main_dispatch_all_leaf_nodes(v8);
}
while ( *(_DWORD *)(a1 + 296) > (int)v7 );
}
}
else
{
if ( *(_DWORD *)(a1 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "main.c", 0xBCu, "main_dispatch_all_leaf_nodes");
v3 = *(_QWORD *)(a1 + 264);
if ( *(_DWORD *)(v3 + 280) == 1 )
{
*(_DWORD *)(v3 + 280) = 2;
v9 = queue_node_new();
*(_QWORD *)(v9 + 16) = a1;
v10 = v9;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v10);
v6 = (char *)dispatch_queue;
}
else
{
v4 = queue_node_new();
*(_QWORD *)(v4 + 16) = a1;
v5 = v4;
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v5);
v6 = (char *)monitor_queue;
}
result = pthread_mutex_unlock((pthread_mutex_t *)(v6 + 272));
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int result; // eax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // rbp
__int64 v8; // rdi
__int64 v9; // rax
__int64 v10; // rbp

if ( !a1 )
_assert_fail("rmnode != NULL", "main.c", 0xBAu, "main_dispatch_all_leaf_nodes");
result = *(_DWORD *)(a1 + 296);
if ( result )
{
v7 = 0LL;
if ( result > 0 )
{
do
{
v8 = *(_QWORD *)(*(_QWORD *)(a1 + 288) + 8 * v7++);
result = func0(v8);
}
while ( *(_DWORD *)(a1 + 296) > (int)v7 );
}
}
else
{
if ( *(_DWORD *)(a1 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "main.c", 0xBCu, "main_dispatch_all_leaf_nodes");
v3 = *(_QWORD *)(a1 + 264);
if ( *(_DWORD *)(v3 + 280) == 1 )
{
*(_DWORD *)(v3 + 280) = 2;
v9 = queue_node_new();
*(_QWORD *)(v9 + 16) = a1;
v10 = v9;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v10);
v6 = (char *)dispatch_queue;
}
else
{
v4 = queue_node_new();
*(_QWORD *)(v4 + 16) = a1;
v5 = v4;
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v5);
v6 = (char *)monitor_queue;
}
result = pthread_mutex_unlock((pthread_mutex_t *)(v6 + 272));
}
return result;
}

original_code:
void main_dispatch_all_leaf_nodes(remodel_node_t *rmnode) {
    queue_node_t *queue_node = ((void *)0);
    build_state_t build_state;
    int i;
    ((void) sizeof ((rmnode != ((void *)0)) ? 1 : 0), __extension__ ({ if (rmnode != ((void *)0)) ; else __assert_fail ("rmnode != NULL", "main.c", 186, __extension__ __PRETTY_FUNCTION__); }));
    if (rmnode->child_nodes == 0) {
        ((void) sizeof ((rmnode->type == RM_TYPE_TARGET) ? 1 : 0), __extension__ ({ if (rmnode->type == RM_TYPE_TARGET) ; else __assert_fail ("rmnode->type == RM_TYPE_TARGET", "main.c", 188, __extension__ __PRETTY_FUNCTION__); }));
        build_state = rmnode->target->build_state;
        if (build_state == RM_BUILD_READY) {
            rmnode->target->build_state = RM_BUILD_ONQ;
        }
        queue_node = queue_node_new();
        queue_node->data = (void *)rmnode;
        if (build_state == RM_BUILD_READY) {
            do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
        } else {
            do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
        }
        return;
    }
    for (i = 0; i < rmnode->child_nodes; i++) {
        main_dispatch_all_leaf_nodes(rmnode->children[i]);
    }
}

canonical_original_code:
void main_dispatch_all_leaf_nodes(struct remodel_node_ *rmnode) {
    struct queue_node_ *queue_node = ((void *)0);
    enum build_state_t build_state;
    int i;
    ((void) sizeof ((rmnode != ((void *)0)) ? 1 : 0), __extension__ ({ if (rmnode != ((void *)0)) ; else __assert_fail ("rmnode != NULL", "main.c", 186, __extension__ __PRETTY_FUNCTION__); }));
    if (rmnode->child_nodes == 0) {
        ((void) sizeof ((rmnode->type == RM_TYPE_TARGET) ? 1 : 0), __extension__ ({ if (rmnode->type == RM_TYPE_TARGET) ; else __assert_fail ("rmnode->type == RM_TYPE_TARGET", "main.c", 188, __extension__ __PRETTY_FUNCTION__); }));
        build_state = rmnode->target->build_state;
        if (build_state == RM_BUILD_READY) {
            rmnode->target->build_state = RM_BUILD_ONQ;
        }
        queue_node = queue_node_new();
        queue_node->data = (void *)rmnode;
        if (build_state == RM_BUILD_READY) {
            do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
        } else {
            do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
        }
        return;
    }
    for (i = 0; i < rmnode->child_nodes; i++) {
        main_dispatch_all_leaf_nodes(rmnode->children[i]);
    }
}

variable_types: struct remodel_node_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct target_ { char name[256]; char *command; struct dependency_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct dependency_ *next; } *dp_head; struct target_ *next; enum build_state_t { RM_BUILD_DONE=0, RM_BUILD_READY=1, RM_BUILD_ONQ=2, RM_BUILD_RUNNING=3 } build_state; int total_dp; int changed_dp; } *target; struct srcfile_ { char name[256]; char md5hash[-1]; _Bool md5_present; _Bool md5_changed; struct srcfile_ *next; } *srcfile; struct remodel_node_ *parent; struct remodel_node_ **children; int child_nodes; } *

variable_types: struct queue_node_ { struct queue_node_ *prev; struct queue_node_ *next; void *data; _Bool signal; } *

user_defined_types: struct remodel_node_ { char name[256]; enum rm_file_type_t type; struct target_ *target; struct srcfile_ *srcfile; struct remodel_node_ *parent; struct remodel_node_ **children; int child_nodes; }

user_defined_types: struct target_ { char name[256]; char *command; struct dependency_ *dp_head; struct target_ *next; enum build_state_t build_state; int total_dp; int changed_dp; }

user_defined_types: struct dependency_ { char name[256]; enum rm_file_type_t type; struct dependency_ *next; }


decompiled_code:
void __fastcall main_process_response_queue(char *s1)
{
_QWORD *v1; // rbp
__int64 v2; // r12
__int64 v3; // rsi
__int64 v4; // rbx
int v5; // eax
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rax

while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)((char *)response_queue + 272));
v1 = (_QWORD *)queue_get_node(response_queue);
pthread_mutex_unlock((pthread_mutex_t *)((char *)response_queue + 272));
}
while ( !v1 );
v2 = v1[2];
if ( *(_DWORD *)(v2 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "main.c", 0xE9u, "main_process_response_queue");
v3 = *(_QWORD *)(v2 + 264);
if ( *(_DWORD *)(v3 + 280) )
_assert_fail("target->build_state == RM_BUILD_DONE", "main.c", 0xEBu, "main_process_response_queue");
if ( !strcmp(s1, (const char *)v3) )
break;
v4 = *(_QWORD *)(v2 + 280);
if ( !v4 )
_assert_fail("rmnode->parent != NULL", "main.c", 0xF5u, "main_process_response_queue");
--*(_DWORD *)(v4 + 296);
free((void *)v2);
free(v1);
v5 = *(_DWORD *)(v4 + 296);
if ( v5 < 0 )
_assert_fail("rmnode->child_nodes >= 0", "main.c", 0xFFu, "main_process_response_queue");
if ( !v5 )
{
v6 = queue_node_new();
*(_QWORD *)(v6 + 16) = v4;
v7 = v6;
v8 = *(_QWORD *)(v4 + 264);
if ( *(_DWORD *)(v8 + 280) == 1 )
{
*(_DWORD *)(v8 + 280) = 2;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v7);
pthread_mutex_unlock((pthread_mutex_t *)((char *)dispatch_queue + 272));
}
else
{
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v7);
pthread_mutex_unlock((pthread_mutex_t *)((char *)monitor_queue + 272));
}
}
}
free(v1);
free((void *)v2);
}

canonical_decompiled_code:
void __fastcall func1(char *s1)
{
_QWORD *v1; // rbp
__int64 v2; // r12
__int64 v3; // rsi
__int64 v4; // rbx
int v5; // eax
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rax

while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)((char *)response_queue + 272));
v1 = (_QWORD *)queue_get_node(response_queue);
pthread_mutex_unlock((pthread_mutex_t *)((char *)response_queue + 272));
}
while ( !v1 );
v2 = v1[2];
if ( *(_DWORD *)(v2 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "main.c", 0xE9u, "main_process_response_queue");
v3 = *(_QWORD *)(v2 + 264);
if ( *(_DWORD *)(v3 + 280) )
_assert_fail("target->build_state == RM_BUILD_DONE", "main.c", 0xEBu, "main_process_response_queue");
if ( !strcmp(s1, (const char *)v3) )
break;
v4 = *(_QWORD *)(v2 + 280);
if ( !v4 )
_assert_fail("rmnode->parent != NULL", "main.c", 0xF5u, "main_process_response_queue");
--*(_DWORD *)(v4 + 296);
free((void *)v2);
free(v1);
v5 = *(_DWORD *)(v4 + 296);
if ( v5 < 0 )
_assert_fail("rmnode->child_nodes >= 0", "main.c", 0xFFu, "main_process_response_queue");
if ( !v5 )
{
v6 = queue_node_new();
*(_QWORD *)(v6 + 16) = v4;
v7 = v6;
v8 = *(_QWORD *)(v4 + 264);
if ( *(_DWORD *)(v8 + 280) == 1 )
{
*(_DWORD *)(v8 + 280) = 2;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v7);
pthread_mutex_unlock((pthread_mutex_t *)((char *)dispatch_queue + 272));
}
else
{
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v7);
pthread_mutex_unlock((pthread_mutex_t *)((char *)monitor_queue + 272));
}
}
}
free(v1);
free((void *)v2);
}

original_code:
void main_process_response_queue(char *target_name) {
    queue_node_t *queue_node = ((void *)0);
    remodel_node_t *rmnode = ((void *)0);
    remodel_node_t *parent = ((void *)0);
    target_t *target = ((void *)0);
    while (1) {
        rmnode = ((void *)0);
        parent = ((void *)0);
        target = ((void *)0);
        queue_node = ((void *)0);
        pthread_mutex_lock(&response_queue->mtx);
        queue_node = queue_get_node(response_queue);
        pthread_mutex_unlock(&response_queue->mtx);
        if (queue_node == ((void *)0)) {
            continue;
        }
        ((void) sizeof ((queue_node != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue_node != ((void *)0)) ; else __assert_fail ("queue_node != NULL", "main.c", 231, __extension__ __PRETTY_FUNCTION__); }));
        rmnode = (remodel_node_t *)queue_node->data;
        ((void) sizeof ((rmnode->type == RM_TYPE_TARGET) ? 1 : 0), __extension__ ({ if (rmnode->type == RM_TYPE_TARGET) ; else __assert_fail ("rmnode->type == RM_TYPE_TARGET", "main.c", 233, __extension__ __PRETTY_FUNCTION__); }));
        target = rmnode->target;
        ((void) sizeof ((target->build_state == RM_BUILD_DONE) ? 1 : 0), __extension__ ({ if (target->build_state == RM_BUILD_DONE) ; else __assert_fail ("target->build_state == RM_BUILD_DONE", "main.c", 235, __extension__ __PRETTY_FUNCTION__); }));
        if (strcmp(target_name, target->name) == 0) {
            ;
            do { if (queue_node != ((void *)0)) { free(queue_node); queue_node = ((void *)0); } } while(0);
            do { if (rmnode != ((void *)0)) { free(rmnode); rmnode = ((void *)0); } } while(0);
            break;
        }
        ((void) sizeof ((rmnode->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (rmnode->parent != ((void *)0)) ; else __assert_fail ("rmnode->parent != NULL", "main.c", 245, __extension__ __PRETTY_FUNCTION__); }));
        parent = rmnode->parent;
        parent->child_nodes--;
        do { if (rmnode != ((void *)0)) { free(rmnode); rmnode = ((void *)0); } } while(0);
        do { if (queue_node != ((void *)0)) { free(queue_node); queue_node = ((void *)0); } } while(0);
        rmnode = parent;
        ((void) sizeof ((rmnode->child_nodes >= 0) ? 1 : 0), __extension__ ({ if (rmnode->child_nodes >= 0) ; else __assert_fail ("rmnode->child_nodes >= 0", "main.c", 255, __extension__ __PRETTY_FUNCTION__); }));
        if (rmnode->child_nodes == 0) {
            queue_node = queue_node_new();
            queue_node->data = (void *)rmnode;
            if (rmnode->target->build_state == RM_BUILD_READY) {
                rmnode->target->build_state = RM_BUILD_ONQ;
                do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
            } else {
                do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
            }
        }
    }
}

canonical_original_code:
void main_process_response_queue(char *target_name) {
    struct queue_node_ *queue_node = ((void *)0);
    struct remodel_node_ *rmnode = ((void *)0);
    struct remodel_node_ *parent = ((void *)0);
    struct target_ *target = ((void *)0);
    while (1) {
        rmnode = ((void *)0);
        parent = ((void *)0);
        target = ((void *)0);
        queue_node = ((void *)0);
        pthread_mutex_lock(&response_queue->mtx);
        queue_node = queue_get_node(response_queue);
        pthread_mutex_unlock(&response_queue->mtx);
        if (queue_node == ((void *)0)) {
            continue;
        }
        ((void) sizeof ((queue_node != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue_node != ((void *)0)) ; else __assert_fail ("queue_node != NULL", "main.c", 231, __extension__ __PRETTY_FUNCTION__); }));
        rmnode = (struct remodel_node_ *)queue_node->data;
        ((void) sizeof ((rmnode->type == RM_TYPE_TARGET) ? 1 : 0), __extension__ ({ if (rmnode->type == RM_TYPE_TARGET) ; else __assert_fail ("rmnode->type == RM_TYPE_TARGET", "main.c", 233, __extension__ __PRETTY_FUNCTION__); }));
        target = rmnode->target;
        ((void) sizeof ((target->build_state == RM_BUILD_DONE) ? 1 : 0), __extension__ ({ if (target->build_state == RM_BUILD_DONE) ; else __assert_fail ("target->build_state == RM_BUILD_DONE", "main.c", 235, __extension__ __PRETTY_FUNCTION__); }));
        if (strcmp(target_name, target->name) == 0) {
            ;
            do { if (queue_node != ((void *)0)) { free(queue_node); queue_node = ((void *)0); } } while(0);
            do { if (rmnode != ((void *)0)) { free(rmnode); rmnode = ((void *)0); } } while(0);
            break;
        }
        ((void) sizeof ((rmnode->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (rmnode->parent != ((void *)0)) ; else __assert_fail ("rmnode->parent != NULL", "main.c", 245, __extension__ __PRETTY_FUNCTION__); }));
        parent = rmnode->parent;
        parent->child_nodes--;
        do { if (rmnode != ((void *)0)) { free(rmnode); rmnode = ((void *)0); } } while(0);
        do { if (queue_node != ((void *)0)) { free(queue_node); queue_node = ((void *)0); } } while(0);
        rmnode = parent;
        ((void) sizeof ((rmnode->child_nodes >= 0) ? 1 : 0), __extension__ ({ if (rmnode->child_nodes >= 0) ; else __assert_fail ("rmnode->child_nodes >= 0", "main.c", 255, __extension__ __PRETTY_FUNCTION__); }));
        if (rmnode->child_nodes == 0) {
            queue_node = queue_node_new();
            queue_node->data = (void *)rmnode;
            if (rmnode->target->build_state == RM_BUILD_READY) {
                rmnode->target->build_state = RM_BUILD_ONQ;
                do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
            } else {
                do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
            }
        }
    }
}

variable_types: struct target_ { char name[256]; char *command; struct dependency_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct dependency_ *next; } *dp_head; struct target_ *next; enum build_state_t { RM_BUILD_DONE=0, RM_BUILD_READY=1, RM_BUILD_ONQ=2, RM_BUILD_RUNNING=3 } build_state; int total_dp; int changed_dp; } *

user_defined_types: struct queue_node_ { struct queue_node_ *prev; struct queue_node_ *next; void *data; _Bool signal; }

user_defined_types: struct srcfile_ { char name[256]; char md5hash[-1]; _Bool md5_present; _Bool md5_changed; struct srcfile_ *next; }


decompiled_code:
void __fastcall main_initiate_builds(__int64 a1, char *a2)
{
main_dispatch_all_leaf_nodes(a1);
main_process_response_queue(a2);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char *a2)
{
func0(a1);
func1(a2);
}

original_code:
void main_initiate_builds(remodel_node_t *rmnode, char *target) {
    main_dispatch_all_leaf_nodes(rmnode);
    main_process_response_queue(target);
}

canonical_original_code:
void main_initiate_builds(struct remodel_node_ *rmnode, char *target) {
    main_dispatch_all_leaf_nodes(rmnode);
    main_process_response_queue(target);
}

variable_types:
target
char *

user_defined_types: enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 }

user_defined_types: enum build_state_t { RM_BUILD_DONE=0, RM_BUILD_READY=1, RM_BUILD_ONQ=2, RM_BUILD_RUNNING=3 }


decompiled_code:
void clean_target_list()
{
_QWORD *v0; // rbp
_QWORD *v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

v0 = target_head;
if ( target_head )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[34];
v2 = (_QWORD *)v1[33];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[33];
free(v3);
}
}
while ( v0 );
if ( target_head )
{
free(target_head);
target_head = 0LL;
}
}
}

canonical_decompiled_code:
void func3()
{
_QWORD *v0; // rbp
_QWORD *v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

v0 = target_head;
if ( target_head )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[34];
v2 = (_QWORD *)v1[33];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[33];
free(v3);
}
}
while ( v0 );
if ( target_head )
{
free(target_head);
target_head = 0LL;
}
}
}

original_code:
void clean_target_list() {
    target_t *tmp;
    target_t *current;
    dependency_t *dtmp;
    dependency_t *dcurrent;
    if (target_head == ((void *)0)) {
        return;
    }
    current = target_head;
    while (current != ((void *)0)) {
        tmp = current->next;
        if (current->dp_head != ((void *)0)) {
            dcurrent = current->dp_head;
            while (dcurrent !=((void *)0)) {
                dtmp = dcurrent->next;
                ;
                do { if (dcurrent != ((void *)0)) { free(dcurrent); dcurrent = ((void *)0); } } while(0);
                dcurrent = dtmp;
            }
        }
        ;
        current = tmp;
    }
    ;
    do { if (target_head != ((void *)0)) { free(target_head); target_head = ((void *)0); } } while(0);
}

canonical_original_code:
void clean_target_list() {
    struct target_ *tmp;
    struct target_ *current;
    struct dependency_ *dtmp;
    struct dependency_ *dcurrent;
    if (target_head == ((void *)0)) {
        return;
    }
    current = target_head;
    while (current != ((void *)0)) {
        tmp = current->next;
        if (current->dp_head != ((void *)0)) {
            dcurrent = current->dp_head;
            while (dcurrent !=((void *)0)) {
                dtmp = dcurrent->next;
                ;
                do { if (dcurrent != ((void *)0)) { free(dcurrent); dcurrent = ((void *)0); } } while(0);
                dcurrent = dtmp;
            }
        }
        ;
        current = tmp;
    }
    ;
    do { if (target_head != ((void *)0)) { free(target_head); target_head = ((void *)0); } } while(0);
}

variable_types: struct dependency_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct dependency_ *next; } *


decompiled_code:
void clean_srcfile_list()
{
void *v0; // rdi
_QWORD *v1; // rbx
void *v2; // rdi

v0 = srcfile_head;
if ( srcfile_head )
{
v1 = (_QWORD *)*((_QWORD *)srcfile_head + 37);
if ( !v1 )
goto LABEL_5;
do
{
v2 = v1;
v1 = (_QWORD *)v1[37];
free(v2);
}
while ( v1 );
v0 = srcfile_head;
if ( srcfile_head )
{
LABEL_5:
free(v0);
srcfile_head = 0LL;
}
}
}

canonical_decompiled_code:
void func4()
{
void *v0; // rdi
_QWORD *v1; // rbx
void *v2; // rdi

v0 = srcfile_head;
if ( srcfile_head )
{
v1 = (_QWORD *)*((_QWORD *)srcfile_head + 37);
if ( !v1 )
goto LABEL_5;
do
{
v2 = v1;
v1 = (_QWORD *)v1[37];
free(v2);
}
while ( v1 );
v0 = srcfile_head;
if ( srcfile_head )
{
LABEL_5:
free(v0);
srcfile_head = 0LL;
}
}
}

original_code:
void clean_srcfile_list() {
    srcfile_t *tmp;
    srcfile_t *current;
    if (srcfile_head == ((void *)0)) {
        return;
    }
    current = srcfile_head->next;
    while (current != ((void *)0)) {
        tmp = current->next;
        ;
        do { if (current != ((void *)0)) { free(current); current = ((void *)0); } } while(0);
        current = tmp;
    }
    ;
    do { if (srcfile_head != ((void *)0)) { free(srcfile_head); srcfile_head = ((void *)0); } } while(0);
}

canonical_original_code:
void clean_srcfile_list() {
    struct srcfile_ *tmp;
    struct srcfile_ *current;
    if (srcfile_head == ((void *)0)) {
        return;
    }
    current = srcfile_head->next;
    while (current != ((void *)0)) {
        tmp = current->next;
        ;
        do { if (current != ((void *)0)) { free(current); current = ((void *)0); } } while(0);
        current = tmp;
    }
    ;
    do { if (srcfile_head != ((void *)0)) { free(srcfile_head); srcfile_head = ((void *)0); } } while(0);
}

variable_types: struct srcfile_ { char name[256]; char md5hash[-1]; _Bool md5_present; _Bool md5_changed; struct srcfile_ *next; } *


decompiled_code:
void clean_queues()
{
if ( dispatch_queue )
{
free(dispatch_queue);
dispatch_queue = 0LL;
}
if ( monitor_queue )
{
free(monitor_queue);
monitor_queue = 0LL;
}
if ( response_queue )
{
free(response_queue);
response_queue = 0LL;
}
}

canonical_decompiled_code:
void func5()
{
if ( dispatch_queue )
{
free(dispatch_queue);
dispatch_queue = 0LL;
}
if ( monitor_queue )
{
free(monitor_queue);
monitor_queue = 0LL;
}
if ( response_queue )
{
free(response_queue);
response_queue = 0LL;
}
}

original_code:
void clean_queues() {
    do { if (dispatch_queue != ((void *)0)) { free(dispatch_queue); dispatch_queue = ((void *)0); } } while(0);
    do { if (monitor_queue != ((void *)0)) { free(monitor_queue); monitor_queue = ((void *)0); } } while(0);
    do { if (response_queue != ((void *)0)) { free(response_queue); response_queue = ((void *)0); } } while(0);
}


decompiled_code:
double get_time_in_sec()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(1000 * LODWORD(v1.tv_sec)) + (double)SLODWORD(v1.tv_usec) / 1000.0;
}

canonical_decompiled_code:
double func6()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(1000 * LODWORD(v1.tv_sec)) + (double)SLODWORD(v1.tv_usec) / 1000.0;
}

original_code:
double get_time_in_sec() {
    double time_sec;
    struct timeval time;
    gettimeofday(&time, ((void *)0));
    time_sec = time.tv_sec*1000 + (time.tv_usec/1000.0);
    return time_sec;
}

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


decompiled_code:
void __fastcall send_killsignal_to_threads(int a1)
{
char *v1; // rbp
int v2; // ebx
__int64 v3; // rax
__int64 v4; // r12
int v5; // ebx
__int64 v6; // rax
__int64 v7; // rbp
_BYTE *v8; // rbp

if ( a1 > 0 )
{
v1 = (char *)&thread_list;
v2 = 0;
do
{
if ( *((_DWORD *)v1 + 2) != -1 )
{
++v2;
v3 = queue_node_new();
*(_BYTE *)(v3 + 24) = 1;
v4 = v3;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v4);
pthread_mutex_unlock((pthread_mutex_t *)((char *)dispatch_queue + 272));
}
v1 += 24;
}
while ( v1 != (char *)&thread_list + 24 * (unsigned int)(a1 - 1) + 24 );
if ( v2 )
{
v5 = v2 + 1;
v6 = queue_node_new();
*(_BYTE *)(v6 + 24) = 1;
v7 = v6;
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v7);
pthread_mutex_unlock((pthread_mutex_t *)((char *)monitor_queue + 272));
while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)((char *)response_queue + 272));
v8 = (_BYTE *)queue_get_node(response_queue);
pthread_mutex_unlock((pthread_mutex_t *)((char *)response_queue + 272));
}
while ( !v8 );
if ( v8[24] )
{
free(v8);
if ( !--v5 )
break;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
char *v1; // rbp
int v2; // ebx
__int64 v3; // rax
__int64 v4; // r12
int v5; // ebx
__int64 v6; // rax
__int64 v7; // rbp
_BYTE *v8; // rbp

if ( a1 > 0 )
{
v1 = (char *)&thread_list;
v2 = 0;
do
{
if ( *((_DWORD *)v1 + 2) != -1 )
{
++v2;
v3 = queue_node_new();
*(_BYTE *)(v3 + 24) = 1;
v4 = v3;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v4);
pthread_mutex_unlock((pthread_mutex_t *)((char *)dispatch_queue + 272));
}
v1 += 24;
}
while ( v1 != (char *)&thread_list + 24 * (unsigned int)(a1 - 1) + 24 );
if ( v2 )
{
v5 = v2 + 1;
v6 = queue_node_new();
*(_BYTE *)(v6 + 24) = 1;
v7 = v6;
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v7);
pthread_mutex_unlock((pthread_mutex_t *)((char *)monitor_queue + 272));
while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)((char *)response_queue + 272));
v8 = (_BYTE *)queue_get_node(response_queue);
pthread_mutex_unlock((pthread_mutex_t *)((char *)response_queue + 272));
}
while ( !v8 );
if ( v8[24] )
{
free(v8);
if ( !--v5 )
break;
}
}
}
}
}

original_code:
void send_killsignal_to_threads(int total_threads) {
    int threads_alive = 0;
    queue_node_t *queue_node = ((void *)0);
    int i;
    for (i = 0; i < (total_threads); i++) {
        if (thread_list[i].tid != -1) {
            threads_alive++;
            queue_node = queue_node_new();
            queue_node->signal = 1;
            do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
        }
    }
    if (threads_alive == 0) {
        return;
    }
    threads_alive++;
    queue_node = queue_node_new();
    queue_node->signal = 1;
    do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
    while (threads_alive > 0) {
        pthread_mutex_lock(&response_queue->mtx);
        queue_node = queue_get_node(response_queue);
        pthread_mutex_unlock(&response_queue->mtx);
        if (queue_node == ((void *)0)) {
            continue;
        }
        if (queue_node->signal) {
            ;
            do { if (queue_node != ((void *)0)) { free(queue_node); queue_node = ((void *)0); } } while(0);
            threads_alive--;
        }
    }
}

canonical_original_code:
void send_killsignal_to_threads(int total_threads) {
    int threads_alive = 0;
    struct queue_node_ *queue_node = ((void *)0);
    int i;
    for (i = 0; i < (total_threads); i++) {
        if (thread_list[i].tid != -1) {
            threads_alive++;
            queue_node = queue_node_new();
            queue_node->signal = 1;
            do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
        }
    }
    if (threads_alive == 0) {
        return;
    }
    threads_alive++;
    queue_node = queue_node_new();
    queue_node->signal = 1;
    do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
    while (threads_alive > 0) {
        pthread_mutex_lock(&response_queue->mtx);
        queue_node = queue_get_node(response_queue);
        pthread_mutex_unlock(&response_queue->mtx);
        if (queue_node == ((void *)0)) {
            continue;
        }
        if (queue_node->signal) {
            ;
            do { if (queue_node != ((void *)0)) { free(queue_node); queue_node = ((void *)0); } } while(0);
            threads_alive--;
        }
    }
}

variable_types: i int


decompiled_code:
__int64 calculate_number_of_threads_needed()
{
double v0; // xmm0_8
double v1; // xmm0_8
unsigned int v2; // er12

v0 = (double)(int)print_dependency_graph();
if ( v0 < 0.0 )
v1 = sqrt(v0);
else
v1 = sqrt(v0);
v2 = (int)v1;
if ( !(int)v1 )
v2 = 1;
LOG("using (%d) threads for parallel builds\n", v2);
return v2;
}

canonical_decompiled_code:
__int64 func8()
{
double v0; // xmm0_8
double v1; // xmm0_8
unsigned int v2; // er12

v0 = (double)(int)print_dependency_graph();
if ( v0 < 0.0 )
v1 = sqrt(v0);
else
v1 = sqrt(v0);
v2 = (int)v1;
if ( !(int)v1 )
v2 = 1;
LOG("using (%d) threads for parallel builds\n", v2);
return v2;
}

original_code:
int calculate_number_of_threads_needed(remodel_node_t *rmnode) {
    int nthreads = 1;
    nthreads = print_dependency_graph(rmnode);
    nthreads = (int)(sqrt(nthreads ));
    if (nthreads == 0) nthreads = 1;
    LOG("using (%d) threads for parallel builds\n", nthreads);
    return nthreads;
}

canonical_original_code:
int calculate_number_of_threads_needed(struct remodel_node_ *rmnode) {
    int nthreads = 1;
    nthreads = print_dependency_graph(rmnode);
    nthreads = (int)(sqrt(nthreads ));
    if (nthreads == 0) nthreads = 1;
    LOG("using (%d) threads for parallel builds\n", nthreads);
    return nthreads;
}

variable_types: nthreads int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
bool v4; // zf
unsigned int v5; // ebp
double v7; // xmm0_8
__int64 v8; // rax
__int64 v9; // rbp
const char *v10; // rsi
const char *v11; // rsi
double v12; // [rsp+0h] [rbp-120h]
char dest[8]; // [rsp+8h] [rbp-118h] BYREF
__int64 v14; // [rsp+10h] [rbp-110h]
__int128 v15; // [rsp+18h] [rbp-108h]
__int128 v16; // [rsp+28h] [rbp-F8h]
__int128 v17; // [rsp+38h] [rbp-E8h]
__int128 v18; // [rsp+48h] [rbp-D8h]
__int128 v19; // [rsp+58h] [rbp-C8h]
__int128 v20; // [rsp+68h] [rbp-B8h]
__int128 v21; // [rsp+78h] [rbp-A8h]
__int128 v22; // [rsp+88h] [rbp-98h]
__int128 v23; // [rsp+98h] [rbp-88h]
__int128 v24; // [rsp+A8h] [rbp-78h]
__int128 v25; // [rsp+B8h] [rbp-68h]
__int128 v26; // [rsp+C8h] [rbp-58h]
__int128 v27; // [rsp+D8h] [rbp-48h]
__int128 v28; // [rsp+E8h] [rbp-38h]
__int128 v29; // [rsp+F8h] [rbp-28h]

strcpy(dest, "DEFAULT");
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v12 = get_time_in_sec();
if ( argc == 1 )
{
LOG("building the default target 'DEFAULT'\n");
goto LABEL_5;
}
if ( argc != 2 )
{
LOG("error: invalid number of arguments (%d)\n", (unsigned int)(argc - 1));
LABEL_11:
print_usage();
return 0;
}
strcpy(dest, argv[1]);
if ( !strcmp(dest, "-h") || !strcmp(dest, "--help") )
goto LABEL_11;
LABEL_5:
target_head = (void *)new_target_node();
srcfile_head = (void *)new_src_node();
v3 = new_remodel_node();
v4 = target_head == 0LL;
thread_list[2] = -1;
remodel_head = v3;
thread_list[8] = -1;
thread_list[14] = -1;
thread_list[20] = -1;
if ( !v4 && srcfile_head && v3 )
{
if ( (unsigned int)file_process_remodelfile() )
{
LABEL_9:
v5 = 3;
goto LABEL_15;
}
v8 = file_get_target(dest);
v9 = v8;
if ( v8 )
{
if ( *(_QWORD *)(v8 + 264) || (v10 = *(const char **)(v8 + 256), !*v10) )
{
if ( !(unsigned int)md5_calculate_for_sources() )
{
md5_load_from_file();
if ( !(unsigned int)file_create_dependency_graph(v9) )
{
if ( (unsigned int)file_mark_all_targets_for_build(remodel_head) )
{
file_cleanup_nodes_for_unchanged_files(remodel_head);
v5 = calculate_number_of_threads_needed(remodel_head);
dispatch_queue = (void *)queue_new("dispatch queue");
monitor_queue = (void *)queue_new("monitor queue");
response_queue = (void *)queue_new("response queue");
if ( (unsigned int)spawn_threads(v5) )
{
LOG("error: unable to create threads\n");
}
else
{
main_initiate_builds(remodel_head, dest);
LOG("build done!\n");
md5_save_md5_hashes();
}
}
else
{
v11 = (const char *)v9;
v5 = 3;
LOG("nothing new to build for the target '%s'.\n", v11);
}
goto LABEL_15;
}
}
}
else
{
LOG("running the command \"%s\"\n", v10);
system(*(const char **)(v9 + 256));
LOG("done!\n");
}
goto LABEL_9;
}
v5 = 3;
LOG("error: given target '%s' doesn't exist.\n", dest);
}
else
{
v5 = 3;
LOG("error: malloc failed; system out of memory.\n");
}
LABEL_15:
LOG("cleaning up\n");
send_killsignal_to_threads(v5);
clean_queues();
clean_target_list();
clean_srcfile_list();
v7 = get_time_in_sec() - v12;
if ( v7 <= 1000.0 )
LOG("remodel took %.0lf milliseconds to complete\n", v7);
else
LOG("remodel took %.3lf seconds to complete\n", v7 / 1000.0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
bool v4; // zf
unsigned int v5; // ebp
double v7; // xmm0_8
__int64 v8; // rax
__int64 v9; // rbp
const char *v10; // rsi
const char *v11; // rsi
double v12; // [rsp+0h] [rbp-120h]
char dest[8]; // [rsp+8h] [rbp-118h] BYREF
__int64 v14; // [rsp+10h] [rbp-110h]
__int128 v15; // [rsp+18h] [rbp-108h]
__int128 v16; // [rsp+28h] [rbp-F8h]
__int128 v17; // [rsp+38h] [rbp-E8h]
__int128 v18; // [rsp+48h] [rbp-D8h]
__int128 v19; // [rsp+58h] [rbp-C8h]
__int128 v20; // [rsp+68h] [rbp-B8h]
__int128 v21; // [rsp+78h] [rbp-A8h]
__int128 v22; // [rsp+88h] [rbp-98h]
__int128 v23; // [rsp+98h] [rbp-88h]
__int128 v24; // [rsp+A8h] [rbp-78h]
__int128 v25; // [rsp+B8h] [rbp-68h]
__int128 v26; // [rsp+C8h] [rbp-58h]
__int128 v27; // [rsp+D8h] [rbp-48h]
__int128 v28; // [rsp+E8h] [rbp-38h]
__int128 v29; // [rsp+F8h] [rbp-28h]

strcpy(dest, "DEFAULT");
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v12 = func6();
if ( argc == 1 )
{
LOG("building the default target 'DEFAULT'\n");
goto LABEL_5;
}
if ( argc != 2 )
{
LOG("error: invalid number of arguments (%d)\n", (unsigned int)(argc - 1));
LABEL_11:
print_usage();
return 0;
}
strcpy(dest, argv[1]);
if ( !strcmp(dest, "-h") || !strcmp(dest, "--help") )
goto LABEL_11;
LABEL_5:
target_head = (void *)new_target_node();
srcfile_head = (void *)new_src_node();
v3 = new_remodel_node();
v4 = target_head == 0LL;
thread_list[2] = -1;
remodel_head = v3;
thread_list[8] = -1;
thread_list[14] = -1;
thread_list[20] = -1;
if ( !v4 && srcfile_head && v3 )
{
if ( (unsigned int)file_process_remodelfile() )
{
LABEL_9:
v5 = 3;
goto LABEL_15;
}
v8 = file_get_target(dest);
v9 = v8;
if ( v8 )
{
if ( *(_QWORD *)(v8 + 264) || (v10 = *(const char **)(v8 + 256), !*v10) )
{
if ( !(unsigned int)md5_calculate_for_sources() )
{
md5_load_from_file();
if ( !(unsigned int)file_create_dependency_graph(v9) )
{
if ( (unsigned int)file_mark_all_targets_for_build(remodel_head) )
{
file_cleanup_nodes_for_unchanged_files(remodel_head);
v5 = func8(remodel_head);
dispatch_queue = (void *)queue_new("dispatch queue");
monitor_queue = (void *)queue_new("monitor queue");
response_queue = (void *)queue_new("response queue");
if ( (unsigned int)spawn_threads(v5) )
{
LOG("error: unable to create threads\n");
}
else
{
func2(remodel_head, dest);
LOG("build done!\n");
md5_save_md5_hashes();
}
}
else
{
v11 = (const char *)v9;
v5 = 3;
LOG("nothing new to build for the target '%s'.\n", v11);
}
goto LABEL_15;
}
}
}
else
{
LOG("running the command \"%s\"\n", v10);
system(*(const char **)(v9 + 256));
LOG("done!\n");
}
goto LABEL_9;
}
v5 = 3;
LOG("error: given target '%s' doesn't exist.\n", dest);
}
else
{
v5 = 3;
LOG("error: malloc failed; system out of memory.\n");
}
LABEL_15:
LOG("cleaning up\n");
func7(v5);
func5();
func3();
func4();
v7 = func6() - v12;
if ( v7 <= 1000.0 )
LOG("remodel took %.0lf milliseconds to complete\n", v7);
else
LOG("remodel took %.3lf seconds to complete\n", v7 / 1000.0);
return 0;
}

original_code:
int main(int argc, char **argv) {
    error_t result;
    double time_start = 0, time_end = 0, time_taken = 0;
    char target_name[256] = "DEFAULT";
    int total_threads = 3;
    target_t *target = ((void *)0);
    queue_node_t *queue_node = ((void *)0);
    int i = 0;
    time_start = get_time_in_sec();
    if (argc == 1) {
        LOG("building the default target 'DEFAULT'\n");
    } else if (argc == 2) {
        strcpy(target_name, argv[1]);
        if ((strcmp(target_name, "-h") == 0) ||
                (strcmp(target_name, "--help") == 0)) {
                print_usage();
                goto far_end;
        }
        ;
    } else {
        LOG("error: invalid number of arguments (%d)\n", (argc - 1));
        print_usage();
        goto far_end;
    }
    target_head = new_target_node();
    srcfile_head = new_src_node();
    remodel_head = new_remodel_node();
    for (i = 0; i < (total_threads+1); i++) {
        thread_list[i].tid = -1;
    }
    if (!(target_head && srcfile_head && remodel_head)) {
        LOG("error: malloc failed; system out of memory.\n");
        goto end;
    }
    result = file_process_remodelfile();
    if (result != SUCCESS) {
        ;
        goto end;
    }
    target = file_get_target(target_name);
    if (target == ((void *)0)) {
        LOG("error: given target '%s' doesn't exist.\n",
                target_name);
        goto end;
    } else {
        if ((target->dp_head == ((void *)0)) &&
                (target->command[0] != '\0')) {
            LOG("running the command \"%s\"\n",
                    target->command);
            system(target->command);
            LOG("done!\n");
            goto end;
        }
    }
    result = md5_calculate_for_sources();
    if (result != SUCCESS) {
        ;
        goto end;
    }
    result = md5_load_from_file();
    if (result != SUCCESS) {
        ;
    }
    result = file_create_dependency_graph(target);
    if (result != SUCCESS) {
        ;
        goto end;
    }
    result = file_mark_all_targets_for_build(remodel_head);
    if (result == 0) {
        LOG("nothing new to build for the target '%s'.\n", target);
        goto end;
    }
    file_cleanup_nodes_for_unchanged_files(remodel_head);
    total_threads = calculate_number_of_threads_needed(remodel_head);
    dispatch_queue = queue_new("dispatch queue");
    monitor_queue = queue_new("monitor queue");
    response_queue = queue_new("response queue");
    result = spawn_threads(total_threads);
    if (result != SUCCESS) {
        LOG("error: unable to create threads\n");
        goto end;
    }
    main_initiate_builds(remodel_head, target_name);
    LOG("build done!\n");
    result = md5_save_md5_hashes();
    if (result != SUCCESS) {
        goto end;
    }
end:
    LOG("cleaning up\n");
    send_killsignal_to_threads(total_threads);
    clean_queues();
    clean_target_list();
    clean_srcfile_list();
    time_end = get_time_in_sec();
    do { double time_taken; time_taken = time_end - time_start; if (time_taken > 1000.0) { time_taken = time_taken/1000.0; LOG("remodel took %.3lf seconds to complete\n", time_taken); } else { LOG("remodel took %.0lf milliseconds to complete\n", time_taken); } } while(0);
far_end:
    return SUCCESS;
}

canonical_original_code:
int main(int argc, char **argv) {
    enum error_t result;
    double time_start = 0; double time_end = 0; double time_taken = 0;
    char target_name[256] = "DEFAULT";
    int total_threads = 3;
    struct target_ *target = ((void *)0);
    struct queue_node_ *queue_node = ((void *)0);
    int i = 0;
    time_start = get_time_in_sec();
    if (argc == 1) {
        LOG("building the default target 'DEFAULT'\n");
    } else if (argc == 2) {
        strcpy(target_name, argv[1]);
        if ((strcmp(target_name, "-h") == 0) ||
                (strcmp(target_name, "--help") == 0)) {
                print_usage();
                goto far_end;
        }
        ;
    } else {
        LOG("error: invalid number of arguments (%d)\n", (argc - 1));
        print_usage();
        goto far_end;
    }
    target_head = new_target_node();
    srcfile_head = new_src_node();
    remodel_head = new_remodel_node();
    for (i = 0; i < (total_threads+1); i++) {
        thread_list[i].tid = -1;
    }
    if (!(target_head && srcfile_head && remodel_head)) {
        LOG("error: malloc failed; system out of memory.\n");
        goto end;
    }
    result = file_process_remodelfile();
    if (result != SUCCESS) {
        ;
        goto end;
    }
    target = file_get_target(target_name);
    if (target == ((void *)0)) {
        LOG("error: given target '%s' doesn't exist.\n",
                target_name);
        goto end;
    } else {
        if ((target->dp_head == ((void *)0)) &&
                (target->command[0] != '\0')) {
            LOG("running the command \"%s\"\n",
                    target->command);
            system(target->command);
            LOG("done!\n");
            goto end;
        }
    }
    result = md5_calculate_for_sources();
    if (result != SUCCESS) {
        ;
        goto end;
    }
    result = md5_load_from_file();
    if (result != SUCCESS) {
        ;
    }
    result = file_create_dependency_graph(target);
    if (result != SUCCESS) {
        ;
        goto end;
    }
    result = file_mark_all_targets_for_build(remodel_head);
    if (result == 0) {
        LOG("nothing new to build for the target '%s'.\n", target);
        goto end;
    }
    file_cleanup_nodes_for_unchanged_files(remodel_head);
    total_threads = calculate_number_of_threads_needed(remodel_head);
    dispatch_queue = queue_new("dispatch queue");
    monitor_queue = queue_new("monitor queue");
    response_queue = queue_new("response queue");
    result = spawn_threads(total_threads);
    if (result != SUCCESS) {
        LOG("error: unable to create threads\n");
        goto end;
    }
    main_initiate_builds(remodel_head, target_name);
    LOG("build done!\n");
    result = md5_save_md5_hashes();
    if (result != SUCCESS) {
        goto end;
    }
end:
    LOG("cleaning up\n");
    send_killsignal_to_threads(total_threads);
    clean_queues();
    clean_target_list();
    clean_srcfile_list();
    time_end = get_time_in_sec();
    do { double time_taken; time_taken = time_end - time_start; if (time_taken > 1000.0) { time_taken = time_taken/1000.0; LOG("remodel took %.3lf seconds to complete\n", time_taken); } else { LOG("remodel took %.0lf milliseconds to complete\n", time_taken); } } while(0);
far_end:
    return SUCCESS;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: enum error_t { RM_ERROR=-1, RM_SUCCESS=0, RM_NOFILEENT=1, RM_FAIL=2, RM_PARSE_FAIL=3, SUCCESS=expr }


decompiled_code:
int drivers_init()
{
return printf("%s %d: %s()\n", "drivers.c", 10LL, "drivers_init");
}

canonical_decompiled_code:
int func7()
{
return printf("%s %d: %s()\n", "drivers.c", 10LL, "drivers_init");
}

original_code:
void drivers_init() {
    int a;
    int b;
    int c;
    c = a+b;
printf("%s %d: %s()\n", "drivers.c", 10, __FUNCTION__);
}

variable_types: a int

variable_types: b int

variable_types: c int


decompiled_code:
int drivers_run()
{
return printf("%s %d: %s()\n", "drivers.c", 18LL, "drivers_run");
}

canonical_decompiled_code:
int func8()
{
return printf("%s %d: %s()\n", "drivers.c", 18LL, "drivers_run");
}

original_code:
void drivers_run() {
    int hello = 20;
    int world = 10;
    int helloworld;
    helloworld = hello + world;
printf("%s %d: %s()\n", "drivers.c", 18, __FUNCTION__);
}

variable_types: hello int

variable_types: world int

variable_types: helloworld int


decompiled_code:
int drivers_update()
{
return printf("%s %d: %s()\n", "drivers.c", 26LL, "drivers_update");
}

canonical_decompiled_code:
int func9()
{
return printf("%s %d: %s()\n", "drivers.c", 26LL, "drivers_update");
}

original_code:
void drivers_update() {
    int i;
    int j;
    i = 20;
    j = 30;
printf("%s %d: %s()\n", "drivers.c", 26, __FUNCTION__);
}

variable_types: j int


decompiled_code:
int filesystem_init()
{
sched_init();
return printf("%s %d: %s()\n", "filesystem.c", 13LL, "filesystem_init");
}

canonical_decompiled_code:
int func10()
{
func16();
return printf("%s %d: %s()\n", "filesystem.c", 13LL, "filesystem_init");
}

original_code:
void filesystem_init() {
 sched_init();
    int a;
    int b;
    int c;
    c = a+b;
printf("%s %d: %s()\n", "filesystem.c", 13, __FUNCTION__);
}


decompiled_code:
int filesystem_run()
{
return printf("%s %d: %s()\n", "filesystem.c", 21LL, "filesystem_run");
}

canonical_decompiled_code:
int func11()
{
return printf("%s %d: %s()\n", "filesystem.c", 21LL, "filesystem_run");
}

original_code:
void filesystem_run() {
    int hello = 20;
    int world = 10;
    int helloworld;
    helloworld = hello + world;
printf("%s %d: %s()\n", "filesystem.c", 21, __FUNCTION__);
}


decompiled_code:
int filesystem_update()
{
sched_update();
return printf("%s %d: %s()\n", "filesystem.c", 30LL, "filesystem_update");
}

canonical_decompiled_code:
int func12()
{
func18();
return printf("%s %d: %s()\n", "filesystem.c", 30LL, "filesystem_update");
}

original_code:
void filesystem_update() {
 sched_update();
    int i;
    int j;
    i = 20;
    j = 30;
printf("%s %d: %s()\n", "filesystem.c", 30, __FUNCTION__);
}


decompiled_code:
int network_init()
{
sched_init();
return printf("%s %d: %s()\n", "network.c", 12LL, "network_init");
}

canonical_decompiled_code:
int func13()
{
func16();
return printf("%s %d: %s()\n", "network.c", 12LL, "network_init");
}

original_code:
void network_init() {
 sched_init();
    int a;
    int b;
    int c;
    c = a+b;
printf("%s %d: %s()\n", "network.c", 12, __FUNCTION__);
}


decompiled_code:
int network_run()
{
return printf("%s %d: %s()\n", "network.c", 20LL, "network_run");
}

canonical_decompiled_code:
int func14()
{
return printf("%s %d: %s()\n", "network.c", 20LL, "network_run");
}

original_code:
void network_run() {
    int hello = 20;
    int world = 10;
    int helloworld;
    helloworld = hello + world;
printf("%s %d: %s()\n", "network.c", 20, __FUNCTION__);
}


decompiled_code:
int network_update()
{
sched_update();
return printf("%s %d: %s()\n", "network.c", 29LL, "network_update");
}

canonical_decompiled_code:
int func15()
{
func18();
return printf("%s %d: %s()\n", "network.c", 29LL, "network_update");
}

original_code:
void network_update() {
 sched_update();
    int i;
    int j;
    i = 20;
    j = 30;
printf("%s %d: %s()\n", "network.c", 29, __FUNCTION__);
}


decompiled_code:
int sched_init()
{
return printf("%s %d: %s()\n", "sched.c", 10LL, "sched_init");
}

canonical_decompiled_code:
int func16()
{
return printf("%s %d: %s()\n", "sched.c", 10LL, "sched_init");
}

original_code:
void sched_init() {
 int a;
 int b;
 int c;
 c = a+b;
printf("%s %d: %s()\n", "sched.c", 10, __FUNCTION__);
}


decompiled_code:
int sched_run()
{
return printf("%s %d: %s()\n", "sched.c", 18LL, "sched_run");
}

canonical_decompiled_code:
int func17()
{
return printf("%s %d: %s()\n", "sched.c", 18LL, "sched_run");
}

original_code:
void sched_run() {
 int hello = 20;
 int world = 10;
 int helloworld;
 helloworld = hello + world;
printf("%s %d: %s()\n", "sched.c", 18, __FUNCTION__);
}


decompiled_code:
int sched_update()
{
return printf("%s %d: %s()\n", "sched.c", 26LL, "sched_update");
}

canonical_decompiled_code:
int func18()
{
return printf("%s %d: %s()\n", "sched.c", 26LL, "sched_update");
}

original_code:
void sched_update() {
 int i;
 int j;
 i = 20;
 j = 30;
printf("%s %d: %s()\n", "sched.c", 26, __FUNCTION__);
}


decompiled_code:
int DEBUG_LOG_(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-1A0h] BYREF
char s[208]; // [rsp+20h] [rbp-188h] BYREF

va_start(arg, a3);
sprintf(s, "remodel: %s +%d: %s", a1, a2, a3);
return vprintf(s, arg);
}

canonical_decompiled_code:
int func0(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-1A0h] BYREF
char s[208]; // [rsp+20h] [rbp-188h] BYREF

va_start(arg, a3);
sprintf(s, "remodel: %s +%d: %s", a1, a2, a3);
return vprintf(s, arg);
}

original_code:
int DEBUG_LOG_(char *filename, int ln, const char *format, ...) {
    va_list arg;
    int result;
    char format_new[200];
    sprintf(format_new, "remodel: %s +%d: %s", filename, ln, format);
    format = format_new;
    __builtin_va_start(arg,format);
    result = vprintf(format, arg);
    __builtin_va_end(arg);
    return result;
}

canonical_original_code:
int DEBUG_LOG_(char *filename, int ln, char *format, ...) {
    __builtin_va_list arg;
    int result;
    char format_new[200];
    sprintf(format_new, "remodel: %s +%d: %s", filename, ln, format);
    format = format_new;
    __builtin_va_start(arg,format);
    result = vprintf(format, arg);
    __builtin_va_end(arg);
    return result;
}

variable_types:
filename
char *

variable_types: ln int

variable_types:
format
char *

variable_types: result int


LOG

decompiled_code:
int LOG(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-1A0h] BYREF
char s[208]; // [rsp+20h] [rbp-188h] BYREF

va_start(arg, a1);
sprintf(s, "remodel: %s", a1);
return vprintf(s, arg);
}

canonical_decompiled_code:
int func1(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-1A0h] BYREF
char s[208]; // [rsp+20h] [rbp-188h] BYREF

va_start(arg, a1);
sprintf(s, "remodel: %s", a1);
return vprintf(s, arg);
}

original_code:
int LOG(const char *format, ...) {
    va_list arg;
    int result;
    char format_new[200];
    sprintf(format_new, "remodel: %s", format);
    format = format_new;
    __builtin_va_start(arg,format);
    result = vprintf(format, arg);
    __builtin_va_end(arg);
    return result;
}

canonical_original_code:
int LOG(char *format, ...) {
    __builtin_va_list arg;
    int result;
    char format_new[200];
    sprintf(format_new, "remodel: %s", format);
    format = format_new;
    __builtin_va_start(arg,format);
    result = vprintf(format, arg);
    __builtin_va_end(arg);
    return result;
}


decompiled_code:
int print_usage()
{
LOG("Usage: remodel [<target_name> | --help | -h]\n");
puts(" Description: <target_name> is optional. Default value 'DEFAULT'");
puts(" is used when none specified.");
return puts(" Options: '-h' and '--help' will print this message");
}

canonical_decompiled_code:
int func2()
{
func1("Usage: remodel [<target_name> | --help | -h]\n");
puts(" Description: <target_name> is optional. Default value 'DEFAULT'");
puts(" is used when none specified.");
return puts(" Options: '-h' and '--help' will print this message");
}

original_code:
void print_usage() {
    LOG("Usage: remodel [<target_name> | --help | -h]\n");
    printf("         Description: <target_name> is optional. Default value 'DEFAULT'\n");
    printf("                      is used when none specified.\n");
    printf("         Options: '-h' and '--help' will print this message\n");
}


decompiled_code:
__int64 print_target_list()
{
__int64 result; // rax
__int64 i; // rdx

result = target_head;
for ( i = *(_QWORD *)(target_head + 272LL); i; i = *(_QWORD *)(i + 272) )
{
for ( result = *(_QWORD *)(i + 264); result; result = *(_QWORD *)(result + 264) )
;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
__int64 i; // rdx

result = target_head;
for ( i = *(_QWORD *)(target_head + 272LL); i; i = *(_QWORD *)(i + 272) )
{
for ( result = *(_QWORD *)(i + 264); result; result = *(_QWORD *)(result + 264) )
;
}
return result;
}

original_code:
void print_target_list() {
    target_t *temp = target_head->next;
    dependency_t *dp_temp = ((void *)0);
    while (temp != ((void *)0)) {
        ;
        dp_temp = temp->dp_head;
        ;
        while(dp_temp != ((void *)0)) {
            ;
            dp_temp = dp_temp->next;
        }
        temp = temp->next;
    }
}

canonical_original_code:
void print_target_list() {
    struct target_ *temp = target_head->next;
    struct dependency_ *dp_temp = ((void *)0);
    while (temp != ((void *)0)) {
        ;
        dp_temp = temp->dp_head;
        ;
        while(dp_temp != ((void *)0)) {
            ;
            dp_temp = dp_temp->next;
        }
        temp = temp->next;
    }
}

variable_types: struct target_ { char name[256]; char *command; struct dependency_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct dependency_ *next; } *dp_head; struct target_ *next; enum build_state_t { RM_BUILD_DONE=0, RM_BUILD_READY=1, RM_BUILD_ONQ=2, RM_BUILD_RUNNING=3 } build_state; int total_dp; int changed_dp; } *


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

result = srcfile_head;
do
result = *(_QWORD *)(result + 296);
while ( result );
return result;
}

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

result = srcfile_head;
do
result = *(_QWORD *)(result + 296);
while ( result );
return result;
}

original_code:
void print_srcfile_list() {
    srcfile_t *temp2 = srcfile_head->next;
    ;
    while (temp2 != ((void *)0)) {
        ;
        temp2 = temp2->next;
    }
}

canonical_original_code:
void print_srcfile_list() {
    struct srcfile_ *temp2 = srcfile_head->next;
    ;
    while (temp2 != ((void *)0)) {
        ;
        temp2 = temp2->next;
    }
}

variable_types: struct srcfile_ { char name[256]; char md5hash[-1]; _Bool md5_present; _Bool md5_changed; struct srcfile_ *next; } *


original_code:
int print_dependency_graph(remodel_node_t *node, int level) {
    int i;
    int total_nodes = 0;
    char parentname[256] = "";
    char pad[200] = "";
    if (node->parent) {
        strcpy(parentname, node->parent->name);
    }
    for (i = 0; i < level; i++) {
        strcat(pad, "\t");
    }
    switch (node->type) {
        case RM_TYPE_UNKNOWN:
        case RM_TYPE_TARGET:
            ;
            total_nodes++;
            if (node->child_nodes == 0) {
                goto end;
            }
            level++;
            for (i = 0; i < node->child_nodes; i++) {
                if (node->children[i]) {
                    total_nodes += print_dependency_graph(node->children[i], level);
                }
            }
            break;
        case RM_TYPE_SRC:
        case RM_TYPE_HEADER:
            ;
            total_nodes++;
            goto end;
            break;
    }
end:
    return total_nodes;
}

canonical_original_code:
int print_dependency_graph(struct remodel_node_ *node, int level) {
    int i;
    int total_nodes = 0;
    char parentname[256] = "";
    char pad[200] = "";
    if (node->parent) {
        strcpy(parentname, node->parent->name);
    }
    for (i = 0; i < level; i++) {
        strcat(pad, "\t");
    }
    switch (node->type) {
        case RM_TYPE_UNKNOWN:
        case RM_TYPE_TARGET:
            ;
            total_nodes++;
            if (node->child_nodes == 0) {
                goto end;
            }
            level++;
            for (i = 0; i < node->child_nodes; i++) {
                if (node->children[i]) {
                    total_nodes += print_dependency_graph(node->children[i], level);
                }
            }
            break;
        case RM_TYPE_SRC:
        case RM_TYPE_HEADER:
            ;
            total_nodes++;
            goto end;
            break;
    }
end:
    return total_nodes;
}

variable_types: struct remodel_node_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct target_ { char name[256]; char *command; struct dependency_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct dependency_ *next; } *dp_head; struct target_ *next; enum build_state_t { RM_BUILD_DONE=0, RM_BUILD_READY=1, RM_BUILD_ONQ=2, RM_BUILD_RUNNING=3 } build_state; int total_dp; int changed_dp; } *target; struct srcfile_ { char name[256]; char md5hash[-1]; _Bool md5_present; _Bool md5_changed; struct srcfile_ *next; } *srcfile; struct remodel_node_ *parent; struct remodel_node_ **children; int child_nodes; } *

variable_types: level int

variable_types: i int

variable_types:
parentname
char [256]

variable_types:
pad
char [200]