decompiled_code:
void __fastcall main_process_response_queue(char *s1)
{
_QWORD *v1; // rbx
__int64 v2; // r12
__int64 v3; // rsi
__int64 v4; // rbp
int v5; // eax
__int64 v6; // rbx
__int64 v7; // 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 = *(_QWORD *)(v4 + 264);
if ( *(_DWORD *)(v7 + 280) == 1 )
{
*(_DWORD *)(v7 + 280) = 2;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v6);
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, v6);
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; // rbx
__int64 v2; // r12
__int64 v3; // rsi
__int64 v4; // rbp
int v5; // eax
__int64 v6; // rbx
__int64 v7; // 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 = *(_QWORD *)(v4 + 264);
if ( *(_DWORD *)(v7 + 280) == 1 )
{
*(_DWORD *)(v7 + 280) = 2;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v6);
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, v6);
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; }


repo: vijkp/Remodel

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: 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:
target
char *

return_type: void

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

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

return_type: double


decompiled_code:
void __fastcall send_killsignal_to_threads(int a1)
{
char *v1; // rbx
int v2; // ebp
__int64 v3; // r12
int v4; // ebp
__int64 v5; // rbx
_BYTE *v6; // rbx

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

canonical_decompiled_code:
void __fastcall func7(int a1)
{
char *v1; // rbx
int v2; // ebp
__int64 v3; // r12
int v4; // ebp
__int64 v5; // rbx
_BYTE *v6; // rbx

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

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: struct queue_node_ { struct queue_node_ *prev; struct queue_node_ *next; void *data; _Bool signal; } *

variable_types: i int


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

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; // ebx

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

return_type: int

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


main

canonical_name: main

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, ...)
{
char v4[200]; // [rsp+0h] [rbp-198h] BYREF
gcc_va_list arg; // [rsp+C8h] [rbp-D0h] BYREF

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

canonical_decompiled_code:
int func0(const char *a1, unsigned int a2, const char *a3, ...)
{
char v4[200]; // [rsp+0h] [rbp-198h] BYREF
gcc_va_list arg; // [rsp+C8h] [rbp-D0h] BYREF

va_start(arg, a3);
sprintf(v4, "remodel: %s +%d: %s", a1, a2, a3);
return vprintf(v4, 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, ...)
{
char v2[200]; // [rsp+0h] [rbp-198h] BYREF
gcc_va_list arg; // [rsp+C8h] [rbp-D0h] BYREF

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

canonical_decompiled_code:
int func1(const char *a1, ...)
{
char v2[200]; // [rsp+0h] [rbp-198h] BYREF
gcc_va_list arg; // [rsp+C8h] [rbp-D0h] BYREF

va_start(arg, a1);
sprintf(v2, "remodel: %s", a1);
return vprintf(v2, 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

for ( result = *(_QWORD *)(srcfile_head + 296LL); result; result = *(_QWORD *)(result + 296) )
;
return result;
}

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

for ( result = *(_QWORD *)(srcfile_head + 296LL); result; result = *(_QWORD *)(result + 296) )
;
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]


decompiled_code:
char *__fastcall queue_new(char *src)
{
char *v1; // rax
char *v2; // rbx

v1 = (char *)malloc(0x138uLL);
v2 = v1;
if ( v1 )
{
strcpy(v1, src);
*((_QWORD *)v2 + 32) = 0LL;
*((_QWORD *)v2 + 33) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(v2 + 272), 0LL);
}
else
{
LOG("error: creation of queue failed.\n");
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
char *v1; // rax
char *v2; // rbx

v1 = (char *)malloc(0x138uLL);
v2 = v1;
if ( v1 )
{
strcpy(v1, src);
*((_QWORD *)v2 + 32) = 0LL;
*((_QWORD *)v2 + 33) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(v2 + 272), 0LL);
}
else
{
LOG("error: creation of queue failed.\n");
}
return v2;
}

original_code:
queue_t* queue_new(char *name) {
    queue_t *queue;
    queue = (queue_t *)malloc(sizeof(queue_t));
    if (queue == ((void *)0)) {
        LOG("error: creation of queue failed.\n");
        return queue;
    } else {
        strcpy(queue->name, name);
        queue->head = ((void *)0);
        queue->tail = ((void *)0);
        pthread_mutex_init(&queue->mtx, ((void *)0));
    }
    return queue;
}

canonical_original_code:
struct queue_ *queue_new(char *name) {
    struct queue_ *queue;
    queue = (struct queue_ *)malloc(sizeof(queue_t));
    if (queue == ((void *)0)) {
        LOG("error: creation of queue failed.\n");
        return queue;
    } else {
        strcpy(queue->name, name);
        queue->head = ((void *)0);
        queue->tail = ((void *)0);
        pthread_mutex_init(&queue->mtx, ((void *)0));
    }
    return queue;
}

variable_types:
name
char *

variable_types: struct queue_ { char name[256]; struct queue_node_ { struct queue_node_ *prev; struct queue_node_ *next; void *data; _Bool signal; } *head; struct queue_node_ *tail; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mtx; } *

user_defined_types: struct queue_ { char name[256]; struct queue_node_ *head; struct queue_node_ *tail; union pthread_mutex_t mtx; }

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

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


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

if ( !a1 )
return 1LL;
result = 0LL;
if ( !*(_QWORD *)(a1 + 256) )
{
if ( *(_QWORD *)(a1 + 264) )
LOG("queue: '%s' has something wrong.\n", (const char *)a1);
result = 1LL;
}
return result;
}

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

if ( !a1 )
return 1LL;
result = 0LL;
if ( !*(_QWORD *)(a1 + 256) )
{
if ( *(_QWORD *)(a1 + 264) )
LOG("queue: '%s' has something wrong.\n", (const char *)a1);
result = 1LL;
}
return result;
}

original_code:
bool queue_is_empty(queue_t *queue) {
    if (queue == ((void *)0)) {
        return 1;
    }
    if ((queue->head == ((void *)0)) && (queue->tail == ((void *)0))) {
        return 1;
    }
    if ((queue->head == ((void *)0)) || (queue->head == ((void *)0))) {
        LOG("queue: '%s' has something wrong.\n", queue->name);
        return 1;
    }
    return 0;
}

canonical_original_code:
_Bool queue_is_empty(struct queue_ *queue) {
    if (queue == ((void *)0)) {
        return 1;
    }
    if ((queue->head == ((void *)0)) && (queue->tail == ((void *)0))) {
        return 1;
    }
    if ((queue->head == ((void *)0)) || (queue->head == ((void *)0))) {
        LOG("queue: '%s' has something wrong.\n", queue->name);
        return 1;
    }
    return 0;
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall queue_add_node(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
_QWORD *v3; // rax

if ( a1 )
{
if ( a2 )
{
result = queue_is_empty(a1);
if ( (_BYTE)result )
{
*(_QWORD *)(a1 + 256) = a2;
*(_QWORD *)(a1 + 264) = a2;
a2[1] = 0LL;
*a2 = 0LL;
}
else
{
v3 = *(_QWORD **)(a1 + 256);
a2[1] = v3;
*v3 = a2;
*(_QWORD *)(a1 + 256) = a2;
*a2 = 0LL;
result = 1LL;
}
}
else
{
LOG("error: node add to a queue failed: node doesn't exist.\n");
result = 0LL;
}
}
else
{
LOG("error: node add to a queue failed: queue doesn't exist.\n");
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
result = func1(a1);
if ( (_BYTE)result )
{
*(_QWORD *)(a1 + 256) = a2;
*(_QWORD *)(a1 + 264) = a2;
a2[1] = 0LL;
*a2 = 0LL;
}
else
{
v3 = *(_QWORD **)(a1 + 256);
a2[1] = v3;
*v3 = a2;
*(_QWORD *)(a1 + 256) = a2;
*a2 = 0LL;
result = 1LL;
}
}
else
{
LOG("error: node add to a queue failed: node doesn't exist.\n");
result = 0LL;
}
}
else
{
LOG("error: node add to a queue failed: queue doesn't exist.\n");
result = 0LL;
}
return result;
}

original_code:
bool queue_add_node(queue_t* queue, queue_node_t *node) {
    if (queue == ((void *)0)) {
        LOG("error: node add to a queue failed: queue doesn't exist.\n");
        return 0;
    }
    if (node == ((void *)0)) {
        LOG("error: node add to a queue failed: node doesn't exist.\n");
        return 0;
    }
    if (queue_is_empty(queue)) {
        queue->head = node;
        queue->tail = node;
        node->next = ((void *)0);
        node->prev = ((void *)0);
    } else {
        node->next = queue->head;
        queue->head->prev = node;
        queue->head = node;
        node->prev = ((void *)0);
    }
    return 1;
}

canonical_original_code:
_Bool queue_add_node(struct queue_ *queue, struct queue_node_ *node) {
    if (queue == ((void *)0)) {
        LOG("error: node add to a queue failed: queue doesn't exist.\n");
        return 0;
    }
    if (node == ((void *)0)) {
        LOG("error: node add to a queue failed: node doesn't exist.\n");
        return 0;
    }
    if (queue_is_empty(queue)) {
        queue->head = node;
        queue->tail = node;
        node->next = ((void *)0);
        node->prev = ((void *)0);
    } else {
        node->next = queue->head;
        queue->head->prev = node;
        queue->head = node;
        node->prev = ((void *)0);
    }
    return 1;
}

variable_types:
node
struct queue_node_ *


decompiled_code:
int __fastcall queue_print_all_nodes(__int64 a1)
{
__int64 i; // rbx

if ( !a1 )
return LOG("error: queue doesn't exist.\n");
LOG("queue: '%s' head %x tail %x ", (const char *)a1, *(_QWORD *)(a1 + 256), *(_QWORD *)(a1 + 264));
if ( !(unsigned __int8)queue_is_empty(a1) )
{
for ( i = *(_QWORD *)(a1 + 256); i; i = *(_QWORD *)(i + 8) )
printf("%s -> ", *(const char **)(i + 16));
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 i; // rbx

if ( !a1 )
return LOG("error: queue doesn't exist.\n");
LOG("queue: '%s' head %x tail %x ", (const char *)a1, *(_QWORD *)(a1 + 256), *(_QWORD *)(a1 + 264));
if ( !(unsigned __int8)func1(a1) )
{
for ( i = *(_QWORD *)(a1 + 256); i; i = *(_QWORD *)(i + 8) )
printf("%s -> ", *(const char **)(i + 16));
}
return putchar(10);
}

original_code:
void queue_print_all_nodes(queue_t *queue) {
    queue_node_t *node = ((void *)0);
    remodel_node_t *rmnode = ((void *)0);
    if (queue == ((void *)0)) {
        LOG("error: queue doesn't exist.\n");
        return;
    }
    LOG("queue: '%s' head %x tail %x ", queue->name,
            queue->head, queue->tail);
    if (queue_is_empty(queue)) {
        printf("\n");
        return;
    }
    node = queue->head;
    while (node != ((void *)0)) {
        rmnode = (remodel_node_t *)node->data;
        printf("%s -> ", rmnode->name);
        node = node->next;
    }
    printf("\n");
}

canonical_original_code:
void queue_print_all_nodes(struct queue_ *queue) {
    struct queue_node_ *node = ((void *)0);
    struct remodel_node_ *rmnode = ((void *)0);
    if (queue == ((void *)0)) {
        LOG("error: queue doesn't exist.\n");
        return;
    }
    LOG("queue: '%s' head %x tail %x ", queue->name,
            queue->head, queue->tail);
    if (queue_is_empty(queue)) {
        printf("\n");
        return;
    }
    node = queue->head;
    while (node != ((void *)0)) {
        rmnode = (struct remodel_node_ *)node->data;
        printf("%s -> ", rmnode->name);
        node = node->next;
    }
    printf("\n");
}

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


decompiled_code:
_QWORD *queue_node_new()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x20uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
*((_BYTE *)v0 + 24) = 0;
}
else
{
LOG("error: memory allocation failed.\n");
}
return v1;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x20uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
*((_BYTE *)v0 + 24) = 0;
}
else
{
LOG("error: memory allocation failed.\n");
}
return v1;
}

original_code:
queue_node_t* queue_node_new() {
    queue_node_t *node = ((void *)0);
    node = (queue_node_t *)malloc(sizeof(queue_node_t));
    if (node == ((void *)0)) {
        LOG("error: memory allocation failed.\n");
        return node;
    }
    node->prev = ((void *)0);
    node->next = ((void *)0);
    node->data = ((void *)0);
    node->signal = 0;
    return node;
}

canonical_original_code:
struct queue_node_ *queue_node_new() {
    struct queue_node_ *node = ((void *)0);
    node = (struct queue_node_ *)malloc(sizeof(queue_node_t));
    if (node == ((void *)0)) {
        LOG("error: memory allocation failed.\n");
        return node;
    }
    node->prev = ((void *)0);
    node->next = ((void *)0);
    node->data = ((void *)0);
    node->signal = 0;
    return node;
}

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


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

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

original_code:
void queue_node_free(queue_node_t* node){
    do { if (node != ((void *)0)) { free(node); node = ((void *)0); } } while(0);
}

canonical_original_code:
void queue_node_free(struct queue_node_ *node){
    do { if (node != ((void *)0)) { free(node); node = ((void *)0); } } while(0);
}


decompiled_code:
void __fastcall queue_free(void *ptr)
{
__int64 *v1; // rax

while ( !(unsigned __int8)queue_is_empty((__int64)ptr) )
{
v1 = queue_get_node((__int64)ptr);
queue_node_free(v1);
}
if ( ptr )
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
__int64 *v1; // rax

while ( !(unsigned __int8)func1((__int64)ptr) )
{
v1 = queue_get_node((__int64)ptr);
func5(v1);
}
if ( ptr )
free(ptr);
}

original_code:
void queue_free(queue_t *queue) {
    queue_node_t *node;
    while(!queue_is_empty(queue)) {
        node = queue_get_node(queue);
        queue_node_free(node);
    }
    do { if (queue != ((void *)0)) { free(queue); queue = ((void *)0); } } while(0);
}

canonical_original_code:
void queue_free(struct queue_ *queue) {
    struct queue_node_ *node;
    while(!queue_is_empty(queue)) {
        node = queue_get_node(queue);
        queue_node_free(node);
    }
    do { if (queue != ((void *)0)) { free(queue); queue = ((void *)0); } } while(0);
}


decompiled_code:
__int64 __fastcall queue_next_node(__int64 a1, __int64 a2)
{
if ( !a1 )
return LOG("error: queue doesn't exist.\n");
if ( a2 )
return *(_QWORD *)(a2 + 8);
return LOG("error: given node doesn't exist.\n");
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
if ( !a1 )
return LOG("error: queue doesn't exist.\n");
if ( a2 )
return *(_QWORD *)(a2 + 8);
return LOG("error: given node doesn't exist.\n");
}

original_code:
queue_node_t* queue_next_node(queue_t* queue, queue_node_t* node) {
    if (queue == ((void *)0)) {
        LOG("error: queue doesn't exist.\n");
        return;
    }
    if (node == ((void *)0)) {
        LOG("error: given node doesn't exist.\n");
        return;
    }
    return node->next;
}

canonical_original_code:
struct queue_node_ *queue_next_node(struct queue_ *queue, struct queue_node_ *node) {
    if (queue == ((void *)0)) {
        LOG("error: queue doesn't exist.\n");
        return;
    }
    if (node == ((void *)0)) {
        LOG("error: given node doesn't exist.\n");
        return;
    }
    return node->next;
}

variable_types: struct queue_ { char name[256]; struct queue_node_ *head; struct queue_node_ *tail; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mtx; } *


decompiled_code:
__int64 __fastcall queue_prev_node(__int64 a1, __int64 a2)
{
if ( !a1 )
return LOG("error: queue doesn't exist.\n");
if ( a2 )
return *(_QWORD *)a2;
return LOG("error: given node doesn't exist.\n");
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
if ( !a1 )
return LOG("error: queue doesn't exist.\n");
if ( a2 )
return *(_QWORD *)a2;
return LOG("error: given node doesn't exist.\n");
}

original_code:
queue_node_t* queue_prev_node(queue_t* queue, queue_node_t* node) {
    if (queue == ((void *)0)) {
        LOG("error: queue doesn't exist.\n");
        return;
    }
    if (node == ((void *)0)) {
        LOG("error: given node doesn't exist.\n");
        return;
    }
    return node->prev;
}

canonical_original_code:
struct queue_node_ *queue_prev_node(struct queue_ *queue, struct queue_node_ *node) {
    if (queue == ((void *)0)) {
        LOG("error: queue doesn't exist.\n");
        return;
    }
    if (node == ((void *)0)) {
        LOG("error: given node doesn't exist.\n");
        return;
    }
    return node->prev;
}


decompiled_code:
void __fastcall __noreturn monitor_thread(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( !a1 )
pthread_exit(0LL);
while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)(monitor_queue + 272LL));
v1 = queue_get_node(monitor_queue);
pthread_mutex_unlock((pthread_mutex_t *)(monitor_queue + 272LL));
}
while ( !v1 );
if ( *(_BYTE *)(v1 + 24) )
break;
v2 = *(_QWORD *)(v1 + 16);
if ( *(_DWORD *)(v2 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "threads.c", 0x9Fu, "monitor_thread");
if ( *(_DWORD *)(*(_QWORD *)(v2 + 264) + 280LL) )
{
pthread_mutex_lock((pthread_mutex_t *)(monitor_queue + 272LL));
queue_add_node(monitor_queue, v1);
pthread_mutex_unlock((pthread_mutex_t *)(monitor_queue + 272LL));
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v1);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
}
}
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v1);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( !a1 )
pthread_exit(0LL);
while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)(monitor_queue + 272LL));
v1 = queue_get_node(monitor_queue);
pthread_mutex_unlock((pthread_mutex_t *)(monitor_queue + 272LL));
}
while ( !v1 );
if ( *(_BYTE *)(v1 + 24) )
break;
v2 = *(_QWORD *)(v1 + 16);
if ( *(_DWORD *)(v2 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "threads.c", 0x9Fu, "monitor_thread");
if ( *(_DWORD *)(*(_QWORD *)(v2 + 264) + 280LL) )
{
pthread_mutex_lock((pthread_mutex_t *)(monitor_queue + 272LL));
queue_add_node(monitor_queue, v1);
pthread_mutex_unlock((pthread_mutex_t *)(monitor_queue + 272LL));
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v1);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
}
}
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v1);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
pthread_exit(0LL);
}

original_code:
error_t monitor_thread(void *data) {
    thread_data_t *tdata = ((void *)0);
    queue_node_t *qnode = ((void *)0);
    remodel_node_t *rmnode = ((void *)0);
    target_t *target = ((void *)0);
    int tid;
    build_state_t build_state;
    tdata = (thread_data_t *)data;
    if (tdata == ((void *)0)) {
        pthread_exit(((void *)0));
    }
    tid = tdata->tid;
    while(1) {
        rmnode = ((void *)0);
        target = ((void *)0);
        qnode = ((void *)0);
        build_state = RM_BUILD_RUNNING;
        pthread_mutex_lock(&monitor_queue->mtx);
        qnode = queue_get_node(monitor_queue);
        pthread_mutex_unlock(&monitor_queue->mtx);
        if (qnode == ((void *)0)) {
            continue;
        }
        if (qnode->signal) {
            pthread_mutex_lock(&response_queue->mtx);
            queue_add_node(response_queue, qnode);
            pthread_mutex_unlock(&response_queue->mtx);
            ;
            pthread_exit(((void *)0));
        }
        ((void) sizeof ((qnode != ((void *)0)) ? 1 : 0), __extension__ ({ if (qnode != ((void *)0)) ; else __assert_fail ("qnode != NULL", "threads.c", 157, __extension__ __PRETTY_FUNCTION__); }));
        rmnode = (remodel_node_t *)qnode->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", "threads.c", 159, __extension__ __PRETTY_FUNCTION__); }));
        target = rmnode->target;
        build_state = target->build_state;
        if (build_state == RM_BUILD_DONE) {
            pthread_mutex_lock(&response_queue->mtx);
            queue_add_node(response_queue, qnode);
            pthread_mutex_unlock(&response_queue->mtx);
        } else {
            pthread_mutex_lock(&monitor_queue->mtx);
            queue_add_node(monitor_queue, qnode);
            pthread_mutex_unlock(&monitor_queue->mtx);
            continue;
        }
    }
}

canonical_original_code:
enum error_t monitor_thread(void *data) {
    struct thread_data_ *tdata = ((void *)0);
    struct queue_node_ *qnode = ((void *)0);
    struct remodel_node_ *rmnode = ((void *)0);
    struct target_ *target = ((void *)0);
    int tid;
    enum build_state_t build_state;
    tdata = (struct thread_data_ *)data;
    if (tdata == ((void *)0)) {
        pthread_exit(((void *)0));
    }
    tid = tdata->tid;
    while(1) {
        rmnode = ((void *)0);
        target = ((void *)0);
        qnode = ((void *)0);
        build_state = RM_BUILD_RUNNING;
        pthread_mutex_lock(&monitor_queue->mtx);
        qnode = queue_get_node(monitor_queue);
        pthread_mutex_unlock(&monitor_queue->mtx);
        if (qnode == ((void *)0)) {
            continue;
        }
        if (qnode->signal) {
            pthread_mutex_lock(&response_queue->mtx);
            queue_add_node(response_queue, qnode);
            pthread_mutex_unlock(&response_queue->mtx);
            ;
            pthread_exit(((void *)0));
        }
        ((void) sizeof ((qnode != ((void *)0)) ? 1 : 0), __extension__ ({ if (qnode != ((void *)0)) ; else __assert_fail ("qnode != NULL", "threads.c", 157, __extension__ __PRETTY_FUNCTION__); }));
        rmnode = (struct remodel_node_ *)qnode->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", "threads.c", 159, __extension__ __PRETTY_FUNCTION__); }));
        target = rmnode->target;
        build_state = target->build_state;
        if (build_state == RM_BUILD_DONE) {
            pthread_mutex_lock(&response_queue->mtx);
            queue_add_node(response_queue, qnode);
            pthread_mutex_unlock(&response_queue->mtx);
        } else {
            pthread_mutex_lock(&monitor_queue->mtx);
            queue_add_node(monitor_queue, qnode);
            pthread_mutex_unlock(&monitor_queue->mtx);
            continue;
        }
    }
}

variable_types:
data
void *

variable_types: struct thread_data_ { unsigned long ptp; int tid; char message[10]; } *

variable_types: tid int

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

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


decompiled_code:
void __fastcall __noreturn build_thread(void *a1)
{
unsigned int v1; // er12
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rbp
const char *v5; // r13

if ( a1 )
{
v1 = *((_DWORD *)a1 + 2);
while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)(dispatch_queue + 272LL));
v2 = queue_get_node(dispatch_queue);
pthread_mutex_unlock((pthread_mutex_t *)(dispatch_queue + 272LL));
}
while ( !v2 );
if ( *(_BYTE *)(v2 + 24) )
break;
v3 = *(_QWORD *)(v2 + 16);
if ( *(_DWORD *)(v3 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "threads.c", 0x5Fu, "build_thread");
v4 = *(_QWORD *)(v3 + 264);
if ( *(_DWORD *)(v4 + 280) != 2 )
_assert_fail("target->build_state == RM_BUILD_ONQ", "threads.c", 0x61u, "build_thread");
*(_DWORD *)(v4 + 280) = 3;
v5 = *(const char **)(v4 + 256);
if ( *v5 )
{
LOG("thread %d running \"%s\"\n", v1, *(const char **)(v4 + 256));
system(v5);
}
*(_DWORD *)(v4 + 280) = 0;
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v2);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
}
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v2);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
pthread_exit(0LL);
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
unsigned int v1; // er12
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rbp
const char *v5; // r13

if ( a1 )
{
v1 = *((_DWORD *)a1 + 2);
while ( 1 )
{
do
{
pthread_mutex_lock((pthread_mutex_t *)(dispatch_queue + 272LL));
v2 = queue_get_node(dispatch_queue);
pthread_mutex_unlock((pthread_mutex_t *)(dispatch_queue + 272LL));
}
while ( !v2 );
if ( *(_BYTE *)(v2 + 24) )
break;
v3 = *(_QWORD *)(v2 + 16);
if ( *(_DWORD *)(v3 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "threads.c", 0x5Fu, "build_thread");
v4 = *(_QWORD *)(v3 + 264);
if ( *(_DWORD *)(v4 + 280) != 2 )
_assert_fail("target->build_state == RM_BUILD_ONQ", "threads.c", 0x61u, "build_thread");
*(_DWORD *)(v4 + 280) = 3;
v5 = *(const char **)(v4 + 256);
if ( *v5 )
{
LOG("thread %d running \"%s\"\n", v1, *(const char **)(v4 + 256));
system(v5);
}
*(_DWORD *)(v4 + 280) = 0;
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v2);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
}
pthread_mutex_lock((pthread_mutex_t *)(response_queue + 272LL));
queue_add_node(response_queue, v2);
pthread_mutex_unlock((pthread_mutex_t *)(response_queue + 272LL));
pthread_exit(0LL);
}
pthread_exit(0LL);
}

original_code:
error_t build_thread(void *data) {
    thread_data_t *tdata = ((void *)0);
    queue_node_t *qnode = ((void *)0);
    target_t *target = ((void *)0);
    remodel_node_t *rmnode = ((void *)0);
    char *command = ((void *)0);
    int tid;
    tdata = (thread_data_t *)data;
    if (tdata == ((void *)0)) {
        pthread_exit(((void *)0));
    }
    tid = tdata->tid;
    while(1) {
        rmnode = ((void *)0);
        target = ((void *)0);
        qnode = ((void *)0);
        pthread_mutex_lock(&dispatch_queue->mtx);
        qnode = queue_get_node(dispatch_queue);
        pthread_mutex_unlock(&dispatch_queue->mtx);
        if (qnode == ((void *)0)) {
            continue;
        }
        if (qnode->signal) {
            pthread_mutex_lock(&response_queue->mtx);
            queue_add_node(response_queue, qnode);
            pthread_mutex_unlock(&response_queue->mtx);
            ;
            pthread_exit(((void *)0));
        }
        rmnode = (remodel_node_t *)qnode->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", "threads.c", 95, __extension__ __PRETTY_FUNCTION__); }));
        target = rmnode->target;
        ((void) sizeof ((target->build_state == RM_BUILD_ONQ) ? 1 : 0), __extension__ ({ if (target->build_state == RM_BUILD_ONQ) ; else __assert_fail ("target->build_state == RM_BUILD_ONQ", "threads.c", 97, __extension__ __PRETTY_FUNCTION__); }));
        target->build_state = RM_BUILD_RUNNING;
        command = target->command;
        if (command[0] != '\0') {
            LOG("thread %d running \"%s\"\n", tid, target->command);
            system(command);
        }
        target->build_state = RM_BUILD_DONE;
        pthread_mutex_lock(&response_queue->mtx);
        queue_add_node(response_queue, qnode);
        pthread_mutex_unlock(&response_queue->mtx);
    }
}

canonical_original_code:
enum error_t build_thread(void *data) {
    struct thread_data_ *tdata = ((void *)0);
    struct queue_node_ *qnode = ((void *)0);
    struct target_ *target = ((void *)0);
    struct remodel_node_ *rmnode = ((void *)0);
    char *command = ((void *)0);
    int tid;
    tdata = (struct thread_data_ *)data;
    if (tdata == ((void *)0)) {
        pthread_exit(((void *)0));
    }
    tid = tdata->tid;
    while(1) {
        rmnode = ((void *)0);
        target = ((void *)0);
        qnode = ((void *)0);
        pthread_mutex_lock(&dispatch_queue->mtx);
        qnode = queue_get_node(dispatch_queue);
        pthread_mutex_unlock(&dispatch_queue->mtx);
        if (qnode == ((void *)0)) {
            continue;
        }
        if (qnode->signal) {
            pthread_mutex_lock(&response_queue->mtx);
            queue_add_node(response_queue, qnode);
            pthread_mutex_unlock(&response_queue->mtx);
            ;
            pthread_exit(((void *)0));
        }
        rmnode = (struct remodel_node_ *)qnode->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", "threads.c", 95, __extension__ __PRETTY_FUNCTION__); }));
        target = rmnode->target;
        ((void) sizeof ((target->build_state == RM_BUILD_ONQ) ? 1 : 0), __extension__ ({ if (target->build_state == RM_BUILD_ONQ) ; else __assert_fail ("target->build_state == RM_BUILD_ONQ", "threads.c", 97, __extension__ __PRETTY_FUNCTION__); }));
        target->build_state = RM_BUILD_RUNNING;
        command = target->command;
        if (command[0] != '\0') {
            LOG("thread %d running \"%s\"\n", tid, target->command);
            system(command);
        }
        target->build_state = RM_BUILD_DONE;
        pthread_mutex_lock(&response_queue->mtx);
        queue_add_node(response_queue, qnode);
        pthread_mutex_unlock(&response_queue->mtx);
    }
}

variable_types:
command
char *

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

user_defined_types: struct thread_data_ { unsigned long ptp; int tid; char message[10]; }


decompiled_code:
__int64 __fastcall spawn_threads(int a1)
{
pthread_t *v1; // rbx
int v2; // ebp

if ( a1 > 0 )
{
v1 = &thread_list;
v2 = 0;
do
{
*((_DWORD *)v1 + 2) = ++v2;
pthread_create(v1, 0LL, (void *(*)(void *))build_thread, v1);
v1 += 3;
}
while ( v2 != a1 );
}
*((_DWORD *)&thread_list + 6 * a1 + 2) = a1 + 1;
pthread_create(&thread_list + 3 * a1, 0LL, (void *(*)(void *))monitor_thread, &thread_list + 3 * a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
pthread_t *v1; // rbx
int v2; // ebp

if ( a1 > 0 )
{
v1 = &thread_list;
v2 = 0;
do
{
*((_DWORD *)v1 + 2) = ++v2;
pthread_create(v1, 0LL, (void *(*)(void *))build_thread, v1);
v1 += 3;
}
while ( v2 != a1 );
}
*((_DWORD *)&thread_list + 6 * a1 + 2) = a1 + 1;
pthread_create(&thread_list + 3 * a1, 0LL, (void *(*)(void *))monitor_thread, &thread_list + 3 * a1);
return 0LL;
}

original_code:
error_t spawn_threads(int number) {
    error_t ret = SUCCESS;
    int i = 0;
    for (i = 0; i < number; i++) {
        thread_list[i].tid = i+1;
        pthread_create(&thread_list[i].ptp, ((void *)0),
                (void *)&build_thread, (void *)&thread_list[i]);
    }
    thread_list[number].tid = number+1;
    pthread_create(&thread_list[number].ptp, ((void *)0),
                (void *)&monitor_thread, (void *)&thread_list[number]);
end:
    return ret;
}

canonical_original_code:
enum error_t spawn_threads(int number) {
    enum error_t ret = SUCCESS;
    int i = 0;
    for (i = 0; i < number; i++) {
        thread_list[i].tid = i+1;
        pthread_create(&thread_list[i].ptp, ((void *)0),
                (void *)&build_thread, (void *)&thread_list[i]);
    }
    thread_list[number].tid = number+1;
    pthread_create(&thread_list[number].ptp, ((void *)0),
                (void *)&monitor_thread, (void *)&thread_list[number]);
end:
    return ret;
}

variable_types: number int

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:
void *new_target_node()
{
void *v0; // rbx

v0 = malloc(0x128uLL);
if ( v0 )
{
memset(v0, 0, 0x100uLL);
*((_QWORD *)v0 + 33) = 0LL;
*((_QWORD *)v0 + 32) = 0LL;
*((_QWORD *)v0 + 34) = 0LL;
*((_DWORD *)v0 + 70) = 1;
*((_DWORD *)v0 + 71) = 0;
*((_DWORD *)v0 + 72) = 0;
}
else
{
LOG("error: system out of memory.\nremodel failed.\n");
}
return v0;
}

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

v0 = malloc(0x128uLL);
if ( v0 )
{
memset(v0, 0, 0x100uLL);
*((_QWORD *)v0 + 33) = 0LL;
*((_QWORD *)v0 + 32) = 0LL;
*((_QWORD *)v0 + 34) = 0LL;
*((_DWORD *)v0 + 70) = 1;
*((_DWORD *)v0 + 71) = 0;
*((_DWORD *)v0 + 72) = 0;
}
else
{
LOG("error: system out of memory.\nremodel failed.\n");
}
return v0;
}

original_code:
target_t *new_target_node() {
    target_t *new_node;
    new_node = (target_t *)malloc(sizeof(target_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    memset(new_node->name, '\0', 256);
    new_node->dp_head = ((void *)0);
    new_node->command = ((void *)0);
    new_node->next = ((void *)0);
    new_node->build_state = RM_BUILD_READY;
    new_node->total_dp = 0;
    new_node->changed_dp = 0;
    return new_node;
}

canonical_original_code:
struct target_ *new_target_node() {
    struct target_ *new_node;
    new_node = (struct target_ *)malloc(sizeof(target_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    memset(new_node->name, '\0', 256);
    new_node->dp_head = ((void *)0);
    new_node->command = ((void *)0);
    new_node->next = ((void *)0);
    new_node->build_state = RM_BUILD_READY;
    new_node->total_dp = 0;
    new_node->changed_dp = 0;
    return new_node;
}

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:
void free_target_node()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void free_target_node() {
}

canonical_original_code:
void free_target_node() {
}


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

v0 = malloc(0x110uLL);
if ( v0 )
{
memset(v0, 0, 0x100uLL);
*((_QWORD *)v0 + 33) = 0LL;
*((_DWORD *)v0 + 64) = 0;
}
else
{
LOG("error: system out of memory.\nremodel failed.\n");
}
return v0;
}

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

v0 = malloc(0x110uLL);
if ( v0 )
{
memset(v0, 0, 0x100uLL);
*((_QWORD *)v0 + 33) = 0LL;
*((_DWORD *)v0 + 64) = 0;
}
else
{
LOG("error: system out of memory.\nremodel failed.\n");
}
return v0;
}

original_code:
dependency_t *new_dp_node() {
    dependency_t *new_node;
    new_node = (dependency_t *)malloc(sizeof(dependency_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    memset(new_node->name, '\0', 256);
    new_node->next = ((void *)0);
    new_node->type = RM_TYPE_UNKNOWN;
    return new_node;
}

canonical_original_code:
struct dependency_ *new_dp_node() {
    struct dependency_ *new_node;
    new_node = (struct dependency_ *)malloc(sizeof(dependency_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    memset(new_node->name, '\0', 256);
    new_node->next = ((void *)0);
    new_node->type = RM_TYPE_UNKNOWN;
    return new_node;
}

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:
_DWORD *new_remodel_node()
{
_DWORD *result; // rax

result = malloc(0x130uLL);
if ( result )
{
result[64] = 0;
*((_QWORD *)result + 35) = 0LL;
*((_QWORD *)result + 36) = 0LL;
result[74] = 0;
}
else
{
LOG("error: system out of memory.\nremodel failed.\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *result; // rax

result = malloc(0x130uLL);
if ( result )
{
result[64] = 0;
*((_QWORD *)result + 35) = 0LL;
*((_QWORD *)result + 36) = 0LL;
result[74] = 0;
}
else
{
LOG("error: system out of memory.\nremodel failed.\n");
result = 0LL;
}
return result;
}

original_code:
remodel_node_t *new_remodel_node() {
    remodel_node_t *new_node;
    new_node = (remodel_node_t *)malloc(sizeof(remodel_node_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    new_node->type = RM_TYPE_UNKNOWN;
    new_node->parent = ((void *)0);
    new_node->children = ((void *)0);
    new_node->child_nodes = 0;
}

canonical_original_code:
struct remodel_node_ *new_remodel_node() {
    struct remodel_node_ *new_node;
    new_node = (struct remodel_node_ *)malloc(sizeof(remodel_node_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    new_node->type = RM_TYPE_UNKNOWN;
    new_node->parent = ((void *)0);
    new_node->children = ((void *)0);
    new_node->child_nodes = 0;
}

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


original_code:
srcfile_t *new_src_node() {
    srcfile_t *new_node;
    new_node = (srcfile_t *)malloc(sizeof(srcfile_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    memset(new_node->name, '\0', 256);
    memset(new_node->md5hash, '\0', 32);
    new_node->next = ((void *)0);
    new_node->md5_present = 0;
    new_node->md5_changed = 0;
    return new_node;
}

canonical_original_code:
struct srcfile_ *new_src_node() {
    struct srcfile_ *new_node;
    new_node = (struct srcfile_ *)malloc(sizeof(srcfile_t));
    if (new_node == ((void *)0)) {
        LOG("error: system out of memory.\nremodel failed.\n");
        return new_node;
    }
    memset(new_node->name, '\0', 256);
    memset(new_node->md5hash, '\0', 32);
    new_node->next = ((void *)0);
    new_node->md5_present = 0;
    new_node->md5_changed = 0;
    return new_node;
}

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


decompiled_code:
__int64 __fastcall add_src_node(char *s2)
{
__int64 v1; // r13
__int64 v2; // r12
__int64 v3; // rbx
__int64 result; // rax

v1 = srcfile_head;
v2 = *(_QWORD *)(srcfile_head + 296LL);
if ( v2 )
{
v3 = *(_QWORD *)(srcfile_head + 296LL);
while ( strcmp((const char *)v3, s2) )
{
v3 = *(_QWORD *)(v3 + 296);
if ( !v3 )
goto LABEL_6;
}
result = 2LL;
}
else
{
LABEL_6:
*((_QWORD *)s2 + 37) = v2;
*(_QWORD *)(v1 + 296) = s2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
__int64 v1; // r13
__int64 v2; // r12
__int64 v3; // rbx
__int64 result; // rax

v1 = srcfile_head;
v2 = *(_QWORD *)(srcfile_head + 296LL);
if ( v2 )
{
v3 = *(_QWORD *)(srcfile_head + 296LL);
while ( strcmp((const char *)v3, s2) )
{
v3 = *(_QWORD *)(v3 + 296);
if ( !v3 )
goto LABEL_6;
}
result = 2LL;
}
else
{
LABEL_6:
*((_QWORD *)s2 + 37) = v2;
*(_QWORD *)(v1 + 296) = s2;
result = 0LL;
}
return result;
}

original_code:
error_t add_src_node(srcfile_t *src_node) {
    error_t ret = RM_FAIL;
    srcfile_t *tempnode;
    int src_found = 0;
    tempnode = srcfile_head->next;
    while((tempnode != ((void *)0)) && (src_found == 0)) {
        if (strcmp(tempnode->name, src_node->name) == 0) {
            src_found = 1;
        }
        tempnode = tempnode->next;
    }
    if (src_found == 0) {
        src_node->next = srcfile_head->next;
        srcfile_head->next = src_node;
        ret = RM_SUCCESS;
        goto end;
    } else {
        ret = RM_FAIL;
        goto end;
    }
end:
    return ret;
}

canonical_original_code:
enum error_t add_src_node(struct srcfile_ *src_node) {
    enum error_t ret = RM_FAIL;
    struct srcfile_ *tempnode;
    int src_found = 0;
    tempnode = srcfile_head->next;
    while((tempnode != ((void *)0)) && (src_found == 0)) {
        if (strcmp(tempnode->name, src_node->name) == 0) {
            src_found = 1;
        }
        tempnode = tempnode->next;
    }
    if (src_found == 0) {
        src_node->next = srcfile_head->next;
        srcfile_head->next = src_node;
        ret = RM_SUCCESS;
        goto end;
    } else {
        ret = RM_FAIL;
        goto end;
    }
end:
    return ret;
}


decompiled_code:
__int64 __fastcall check_dp_type(const char *a1)
{
char *v1; // rax
unsigned int v2; // edx

v1 = strchr(a1, 46);
if ( !v1 )
return 1;
v2 = 2;
if ( strcmp(v1, ".c") )
{
v2 = 3;
if ( strcmp(v1, ".h") )
v2 = (strcmp(v1, ".cpp") == 0) + 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
char *v1; // rax
unsigned int v2; // edx

v1 = strchr(a1, 46);
if ( !v1 )
return 1;
v2 = 2;
if ( strcmp(v1, ".c") )
{
v2 = 3;
if ( strcmp(v1, ".h") )
v2 = (strcmp(v1, ".cpp") == 0) + 1;
}
return v2;
}

original_code:
rm_file_type_t check_dp_type(char *name) {
    rm_file_type_t result = RM_TYPE_TARGET;
    char *extn;
    extn = strstr(name, ".");
    if (extn == ((void *)0)) return result;
    if (strcmp(extn, ".c") == 0) return RM_TYPE_SRC;
    if (strcmp(extn, ".h") == 0) return RM_TYPE_HEADER;
    if (strcmp(extn, ".cpp") == 0) return RM_TYPE_SRC;
    return result;
}

canonical_original_code:
enum rm_file_type_t check_dp_type(char *name) {
    enum rm_file_type_t result = RM_TYPE_TARGET;
    char *extn;
    extn = strstr(name, ".");
    if (extn == ((void *)0)) return result;
    if (strcmp(extn, ".c") == 0) return RM_TYPE_SRC;
    if (strcmp(extn, ".h") == 0) return RM_TYPE_HEADER;
    if (strcmp(extn, ".cpp") == 0) return RM_TYPE_SRC;
    return result;
}

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

variable_types:
extn
char *


decompiled_code:
__int64 __fastcall md5_to_string(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 result; // rax
char s; // [rsp+Eh] [rbp-1Ah] BYREF
unsigned __int8 v5; // [rsp+Fh] [rbp-19h]

for ( i = 0LL; i != 16; ++i )
{
sprintf(&s, "%02x", *(unsigned __int8 *)(a1 + i));
*(_BYTE *)(a2 + 2 * i) = s;
result = v5;
*(_BYTE *)(a2 + 2 * i + 1) = v5;
}
*(_BYTE *)(a2 + 32) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 result; // rax
char s; // [rsp+Eh] [rbp-1Ah] BYREF
unsigned __int8 v5; // [rsp+Fh] [rbp-19h]

for ( i = 0LL; i != 16; ++i )
{
sprintf(&s, "%02x", *(unsigned __int8 *)(a1 + i));
*(_BYTE *)(a2 + 2 * i) = s;
result = v5;
*(_BYTE *)(a2 + 2 * i + 1) = v5;
}
*(_BYTE *)(a2 + 32) = 0;
return result;
}

original_code:
void md5_to_string(unsigned char *md, char *result) {
    int i;
    char tmp[2];
    for(i=0; i < 16; i++) {
        sprintf(tmp, "%02x",md[i]);
        result[2*i] = tmp[0];
        result[2*i+1] = tmp[1];
    }
    result[32] = '\0';
}

variable_types:
md
unsigned char *

variable_types:
result
char *

variable_types: i int

variable_types:
tmp
char [2]


repo: vikingeff/minitalk

decompiled_code:
__int64 __fastcall ft_putchar(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

original_code:
int ft_putchar(char c)
{
 write(1, &c, 1);
 return (1);
}

variable_types: c char


decompiled_code:
__int64 __fastcall ft_strlen(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int ft_strlen(char *str)
{
 int size;
 size = 0;
 while (str[size])
  ++size;
 return (size);
}

variable_types:
str
char *

variable_types: size int


decompiled_code:
__int64 __fastcall ft_putstr(void *buf)
{
int v1; // eax

v1 = ft_strlen(buf);
write(1, buf, v1);
return ft_strlen(buf);
}

canonical_decompiled_code:
__int64 __fastcall func9(void *buf)
{
int v1; // eax

v1 = func8(buf);
write(1, buf, v1);
return func8(buf);
}

original_code:
int ft_putstr(char *str)
{
 write(1, str, ft_strlen(str));
 return (ft_strlen(str));
}


error

decompiled_code:
__int64 __fastcall error(void *buf)
{
int v1; // eax

v1 = ft_strlen(buf);
write(2, buf, v1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *buf)
{
int v1; // eax

v1 = func8(buf);
write(2, buf, v1);
return 0xFFFFFFFFLL;
}

original_code:
int error(char *str)
{
 write(2, str, ft_strlen(str));
 return (-1);
}


decompiled_code:
__int64 __fastcall ft_putnbr(int a1)
{
int v1; // ebx

v1 = a1;
if ( a1 < 0 )
{
ft_putchar(45);
v1 = -a1;
}
if ( v1 > 9 )
ft_putnbr((unsigned int)(v1 / 10));
return ft_putchar((unsigned __int8)(v1 % 10) + 48);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
int v1; // ebx

v1 = a1;
if ( a1 < 0 )
{
func7(45);
v1 = -a1;
}
if ( v1 > 9 )
func11((unsigned int)(v1 / 10));
return func7((unsigned __int8)(v1 % 10) + 48);
}

original_code:
void ft_putnbr(int nb)
{
 if (nb < 0)
 {
  ft_putchar('-');
  nb = nb * -1;
 }
 if (nb >= 10)
  ft_putnbr(nb / 10);
 ft_putchar(nb % 10 + '0');
}

variable_types: nb int


decompiled_code:
__int64 __fastcall clean_str(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // esi
char v3; // dl

if ( (unsigned __int8)(*a1 - 9) > 4u && *a1 != 32 )
return 0;
v1 = 1LL;
do
{
do
{
v2 = v1;
v3 = a1[v1++];
}
while ( (unsigned __int8)(v3 - 9) <= 4u );
}
while ( v3 == 32 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // esi
char v3; // dl

if ( (unsigned __int8)(*a1 - 9) > 4u && *a1 != 32 )
return 0;
v1 = 1LL;
do
{
do
{
v2 = v1;
v3 = a1[v1++];
}
while ( (unsigned __int8)(v3 - 9) <= 4u );
}
while ( v3 == 32 );
return v2;
}

original_code:
static int clean_str(const char *str)
{
 int index;
 index = 0;
 while (str[index] == ' ' || str[index] == '\t' || str[index] == '\n'
  || str[index] == '\r' || str[index] == '\f' || str[index] == '\v')
  index++;
 return (index);
}

canonical_original_code:
static int clean_str(char *str)
{
 int index;
 index = 0;
 while (str[index] == ' ' || str[index] == '\t' || str[index] == '\n'
  || str[index] == '\r' || str[index] == '\f' || str[index] == '\v')
  index++;
 return (index);
}

variable_types: index int


decompiled_code:
_BOOL8 __fastcall ft_isdigit(int a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

original_code:
int ft_isdigit(int c)
{
 if (c >= '0' && c <= '9')
  return (1);
 else
  return (0);
}

variable_types: c int


original_code:
int ft_atoi(const char *str)
{
 int index;
 int res;
 int sign;
 index = clean_str(str);
 res = 0;
 sign = 1;
 if (*(str + index) == '-' || *(str + index) == '+')
  sign = (*(str + index++) == '-') ? -1 : 1;
 while (*(str + index) && *(str + index) >= '0' && *(str + index) <= '9')
 {
  res *= 10;
  res += (*(str + index) - '0');
  index++;
 }
 return (res * sign);
}

canonical_original_code:
int ft_atoi(char *str)
{
 int index;
 int res;
 int sign;
 index = clean_str(str);
 res = 0;
 sign = 1;
 if (*(str + index) == '-' || *(str + index) == '+')
  sign = (*(str + index++) == '-') ? -1 : 1;
 while (*(str + index) && *(str + index) >= '0' && *(str + index) <= '9')
 {
  res *= 10;
  res += (*(str + index) - '0');
  index++;
 }
 return (res * sign);
}

variable_types: res int

variable_types: sign int


decompiled_code:
__int64 __fastcall send_info(char a1, __pid_t a2)
{
int v3; // ebp

v3 = 64;
while ( a1 < v3 )
{
if ( kill(a2, 10) == -1 )
return (unsigned int)error("Error on kill\n");
LABEL_3:
v3 /= 2;
usleep(0xAu);
if ( !v3 )
return (unsigned int)v3;
}
a1 -= v3;
if ( kill(a2, 12) != -1 )
goto LABEL_3;
return (unsigned int)error("Error on kill\n");
}

canonical_decompiled_code:
__int64 __fastcall func15(char a1, __pid_t a2)
{
int v3; // ebp

v3 = 64;
while ( a1 < v3 )
{
if ( kill(a2, 10) == -1 )
return (unsigned int)func10("Error on kill\n");
LABEL_3:
v3 /= 2;
usleep(0xAu);
if ( !v3 )
return (unsigned int)v3;
}
a1 -= v3;
if ( kill(a2, 12) != -1 )
goto LABEL_3;
return (unsigned int)func10("Error on kill\n");
}

original_code:
int send_info(char c, int pid)
{
 int nb;
 nb = 64;
 while (nb != 0)
 {
  if (c >= nb)
  {
   c = c - nb;
   if (kill(pid, 12) == -1)
    return (error("Error on kill\n"));
  }
  else
  {
   if (kill(pid, 10) == -1)
    return (error("Error on kill\n"));
  }
  nb = nb / 2;
  usleep(10);
 }
 return (0);
}

variable_types: pid int


decompiled_code:
__int64 __fastcall check_pid(_BYTE *a1)
{
int v1; // eax
char *v2; // rbx
__int64 v3; // rbp

v1 = ft_strlen(a1);
if ( v1 <= 0 )
return 0LL;
v2 = a1;
v3 = (__int64)&a1[v1 - 1 + 1];
while ( ft_isdigit(*v2) )
{
if ( ++v2 == (char *)v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(_BYTE *a1)
{
int v1; // eax
char *v2; // rbx
__int64 v3; // rbp

v1 = func8(a1);
if ( v1 <= 0 )
return 0LL;
v2 = a1;
v3 = (__int64)&a1[v1 - 1 + 1];
while ( func13(*v2) )
{
if ( ++v2 == (char *)v3 )
return 0LL;
}
return 1LL;
}

original_code:
int check_pid(char *str)
{
 int size;
 int loop;
 loop = 0;
 size = ft_strlen(str);
 while (loop < size)
 {
  if (ft_isdigit(str[loop]))
  loop++;
 else
  return (1);
 }
 return (0);
}

variable_types: loop int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__pid_t v4; // er12
__int64 i; // rbx
char v6; // di

result = -1;
if ( argc == 3 )
{
if ( (unsigned int)check_pid(argv[1]) )
{
error("Le PID n'est pas conforme.\n");
result = 1;
}
else
{
v4 = ft_atoi(argv[1]);
for ( i = 0LL; ; ++i )
{
v6 = argv[2][i];
if ( !v6 )
break;
result = send_info(v6, v4);
if ( result == -1 )
return result;
}
result = -((unsigned int)send_info(10, v4) == -1);
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__pid_t v4; // er12
__int64 i; // rbx
char v6; // di

result = -1;
if ( argc == 3 )
{
if ( (unsigned int)func16(argv[1]) )
{
func10("Le PID n'est pas conforme.\n");
result = 1;
}
else
{
v4 = func14(argv[1]);
for ( i = 0LL; ; ++i )
{
v6 = argv[2][i];
if ( !v6 )
break;
result = func15(v6, v4);
if ( result == -1 )
return result;
}
result = -((unsigned int)func15(10, v4) == -1);
}
}
return result;
}

original_code:
int main(int ac, char **av)
{
 int pid;
 int index;
 index = 0;
 if (ac != 3)
  return (-1);
 if (check_pid(av[1]))
 {
  error("Le PID n'est pas conforme.\n");
  return (1);
 }
 else
 {
  pid = ft_atoi(av[1]);
  while (av[2][index])
  {
   if (send_info(av[2][index++], pid) == -1)
    return (-1);
  }
  if (send_info('\n', pid) == -1)
   return (-1);
 }
 return (0);
}

variable_types: ac int

variable_types:
av
char **


canonical_original_code:
int ft_putchar(char c)
{
 write(1, &c, 1);
 return (1);
}


canonical_original_code:
int ft_strlen(char *str)
{
 int size;
 size = 0;
 while (str[size])
  ++size;
 return (size);
}


canonical_original_code:
int ft_putstr(char *str)
{
 write(1, str, ft_strlen(str));
 return (ft_strlen(str));
}


error

canonical_original_code:
int error(char *str)
{
 write(2, str, ft_strlen(str));
 return (-1);
}


canonical_original_code:
void ft_putnbr(int nb)
{
 if (nb < 0)
 {
  ft_putchar('-');
  nb = nb * -1;
 }
 if (nb >= 10)
  ft_putnbr(nb / 10);
 ft_putchar(nb % 10 + '0');
}


decompiled_code:
char __fastcall receive_signal(int a1)
{
char result; // al

if ( a1 == 12 )
bit_1 += value_0;
result = value_0 / 2;
value_0 /= 2;
if ( !value_0 )
{
result = ft_putchar(bit_1);
value_0 = 64;
bit_1 = 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func12(int a1)
{
char result; // al

if ( a1 == 12 )
bit_1 += value_0;
result = value_0 / 2;
value_0 /= 2;
if ( !value_0 )
{
result = func7(bit_1);
value_0 = 64;
bit_1 = 0;
}
return result;
}

original_code:
void receive_signal(int signal, siginfo_t *siginfo, void *unused)
{
 static char value = 64;
 static char bit = 0;
 (void)unused;
 (void)siginfo;
 if (signal == 12)
  bit = bit + value;
 value = value / 2;
 if (value == 0)
 {
  ft_putchar(bit);
  value = 64;
  bit = 0;
 }
}

canonical_original_code:
void receive_signal(int signal, struct siginfo_t *siginfo, void *unused)
{
 static char value = 64;
 static char bit = 0;
 (void)unused;
 (void)siginfo;
 if (signal == 12)
  bit = bit + value;
 value = value / 2;
 if (value == 0)
 {
  ft_putchar(bit);
  value = 64;
  bit = 0;
 }
}

variable_types: signal int

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

variable_types:
unused
void *

variable_types: value char

variable_types: bit char

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


decompiled_code:
__int64 __fastcall show_usage(void *buf)
{
error("Usage: ");
error(buf);
return error("\n");
}

canonical_decompiled_code:
__int64 __fastcall func13(void *buf)
{
func10("Usage: ");
func10(buf);
return func10("\n");
}

original_code:
void show_usage(char *prog_name)
{
 error("Usage: ");
 error(prog_name);
 error("\n");
}