decompiled_code:
int init_my_alloc()
{
_QWORD *v0; // rax
__int64 v1; // rdx
_QWORD *v2; // rax
__int64 v3; // rax
const void *v4; // rsi

v0 = (_QWORD *)get_block_from_system();
if ( !v0 )
exit(1);
root = (__int64)v0;
node = (__int64)(v0 + 4);
*v0 = 0LL;
v1 = root;
v2 = (_QWORD *)node;
*(_QWORD *)(root + 8) = node;
*(_QWORD *)(v1 + 16) = v2;
*(_DWORD *)(v1 + 24) = 0;
*v2 = 8128LL;
v3 = node;
v4 = (const void *)root;
*(_QWORD *)(node + 8) = root;
*(_QWORD *)(v3 + 16) = v4;
*(_DWORD *)(v3 + 24) = 0;
min_address = (__int64)v4;
return printf("Root:\t %p\n", v4);
}

canonical_decompiled_code:
int func0()
{
_QWORD *v0; // rax
__int64 v1; // rdx
_QWORD *v2; // rax
__int64 v3; // rax
const void *v4; // rsi

v0 = (_QWORD *)get_block_from_system();
if ( !v0 )
exit(1);
root = (__int64)v0;
node = (__int64)(v0 + 4);
*v0 = 0LL;
v1 = root;
v2 = (_QWORD *)node;
*(_QWORD *)(root + 8) = node;
*(_QWORD *)(v1 + 16) = v2;
*(_DWORD *)(v1 + 24) = 0;
*v2 = 8128LL;
v3 = node;
v4 = (const void *)root;
*(_QWORD *)(node + 8) = root;
*(_QWORD *)(v3 + 16) = v4;
*(_DWORD *)(v3 + 24) = 0;
min_address = (__int64)v4;
return printf("Root:\t %p\n", v4);
}

original_code:
void init_my_alloc() {
    void *block = get_block_from_system();
    if (!block)
        exit(1);
    root = (header *) block;
    node = root + 1;
    root->size = 0;
    root->next = node;
    root->succ = node;
    root->flag = is_free;
    node->size = 8192 - 2 * sizeof(header);
    node->next = root;
    node->succ = root;
    node->flag = is_free;
    min_address = root;
    printf("Root:\t %p\n",root);
    if(0) printf("Node:\t %p\n",node);
    if(0) printf("Min:\t %p\n",min_address);
}

canonical_original_code:
void init_my_alloc() {
    void *block = get_block_from_system();
    if (!block)
        exit(1);
    root = (struct header *) block;
    node = root + 1;
    root->size = 0;
    root->next = node;
    root->succ = node;
    root->flag = is_free;
    node->size = 8192 - 2 * sizeof(header);
    node->next = root;
    node->succ = root;
    node->flag = is_free;
    min_address = root;
    printf("Root:\t %p\n",root);
    if(0) printf("Node:\t %p\n",node);
    if(0) printf("Min:\t %p\n",min_address);
}

variable_types:
block
void *

user_defined_types: struct header { unsigned long size; struct header *next; struct header *succ; enum alloc_flag flag; }

user_defined_types: enum alloc_flag { is_free=0, is_alloc=1 }


repo: Robotregent/system-soft

original_code:
header* append_new(header *new){
    if (new > min_address){
        if(0) printf("Nicht absteigend!\n");
        exit (1);
    }
    header *min_free = min_address;
    while (min_free->flag == is_alloc){
        min_free = min_free->succ;
    }
    header *max_free = min_free;
    while(max_free->next != min_free){
        max_free = max_free->next;
    }
    header *prev = min_address;
    while(prev->succ != min_address){
        prev = prev->succ;
    }
    if (min_address->flag == is_alloc)
        min_address->next = new;
    prev->succ = new;
    new->succ = min_address;
    new->next = min_free;
    max_free->next = new;
    min_address = new;
    new->flag = is_free;
    return max_free;
}

canonical_original_code:
struct header *append_new(struct header *new){
    if (new > min_address){
        if(0) printf("Nicht absteigend!\n");
        exit (1);
    }
    struct header *min_free = min_address;
    while (min_free->flag == is_alloc){
        min_free = min_free->succ;
    }
    struct header *max_free = min_free;
    while(max_free->next != min_free){
        max_free = max_free->next;
    }
    struct header *prev = min_address;
    while(prev->succ != min_address){
        prev = prev->succ;
    }
    if (min_address->flag == is_alloc)
        min_address->next = new;
    prev->succ = new;
    new->succ = min_address;
    new->next = min_free;
    max_free->next = new;
    min_address = new;
    new->flag = is_free;
    return max_free;
}

variable_types:
new
struct header *

variable_types: struct header { unsigned long size; struct header *next; struct header *succ; enum alloc_flag { is_free=0, is_alloc=1 } flag; } *


original_code:
void trim_block(header *old, header *new, int size){
    if(0) printf("\nOld->size: %d size %d\n", (int)old->size, size);
    new->next = old;
    new->succ = old->succ;
    if (old->succ->next == old && old->succ != root && old->succ->flag == is_alloc)
        old->succ->next = new;
    old->succ = new;
    new->size = size;
    old->size -= size + sizeof(header);
    new->flag = is_alloc;
}

canonical_original_code:
void trim_block(struct header *old, struct header *new, int size){
    if(0) printf("\nOld->size: %d size %d\n", (int)old->size, size);
    new->next = old;
    new->succ = old->succ;
    if (old->succ->next == old && old->succ != root && old->succ->flag == is_alloc)
        old->succ->next = new;
    old->succ = new;
    new->size = size;
    old->size -= size + sizeof(header);
    new->flag = is_alloc;
}

variable_types: size int

return_type: void


decompiled_code:
unsigned __int64 __fastcall remove_from_free_ring(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdx

result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a1 + 8) = result;
if ( a2 <= a1 )
{
result = *(_QWORD *)(a2 + 16);
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result != a2 );
}
else
{
do
{
v3 = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 < a2 );
}
*(_QWORD *)(a2 + 8) = v3;
*(_DWORD *)(a2 + 24) = 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdx

result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a1 + 8) = result;
if ( a2 <= a1 )
{
result = *(_QWORD *)(a2 + 16);
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result != a2 );
}
else
{
do
{
v3 = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 < a2 );
}
*(_QWORD *)(a2 + 8) = v3;
*(_DWORD *)(a2 + 24) = 1;
return result;
}

original_code:
void remove_from_free_ring(header *prev_free, header *current){
    header *prev;
    prev_free->next = current->next;
    if (prev_free < current){
        prev = prev_free;
        while (prev->succ < current){
            prev = prev->succ;
        }
    }
    else {
        prev = current->succ;
        while (prev->succ != current){
            prev = prev->succ;
        }
    }
    current->next = prev;
    current->flag = is_alloc;
}

canonical_original_code:
void remove_from_free_ring(struct header *prev_free, struct header *current){
    struct header *prev;
    prev_free->next = current->next;
    if (prev_free < current){
        prev = prev_free;
        while (prev->succ < current){
            prev = prev->succ;
        }
    }
    else {
        prev = current->succ;
        while (prev->succ != current){
            prev = prev->succ;
        }
    }
    current->next = prev;
    current->flag = is_alloc;
}

variable_types:
current
struct header *


original_code:
int join_free(header* prev, header* current){
    header *n = (header *)((char*) prev + sizeof(header) + prev->size);
    if (n!=current || prev == root )
        return 0;
    if(0) printf("Join %p and %p\n",prev,current);
    prev->size += current->size + sizeof(header);
    prev->succ = current->succ;
    prev->next = current->next;
    if (current->succ->next == current)
        current->succ->next = prev;
    if (node == current)
        node = prev;
    return 1;
}

canonical_original_code:
int join_free(struct header *prev, struct header *current){
    struct header *n = (header *)((char*) prev + sizeof(header) + prev->size);
    if (n!=current || prev == root )
        return 0;
    if(0) printf("Join %p and %p\n",prev,current);
    prev->size += current->size + sizeof(header);
    prev->succ = current->succ;
    prev->next = current->next;
    if (current->succ->next == current)
        current->succ->next = prev;
    if (node == current)
        node = prev;
    return 1;
}

return_type: int


original_code:
void my_free(void* current_ptr) {
    if(0) printf("Free: %p, ptr %p\n",current_ptr-sizeof(header), current_ptr);
    header *current = (header *)((char *) current_ptr - sizeof(header));
    header *prev = current->next;
    while (prev->flag == is_alloc){
        prev = prev->next;
    }
    current->next = prev->next;
    prev->next = current;
    current->flag = is_free;
    join_free(current, current->next);
    join_free(prev, current);
    if(0) printf("\n");
}

canonical_original_code:
void my_free(void *current_ptr) {
    if(0) printf("Free: %p, ptr %p\n",current_ptr-sizeof(header), current_ptr);
    struct header *current = (header *)((char *) current_ptr - sizeof(header));
    struct header *prev = current->next;
    while (prev->flag == is_alloc){
        prev = prev->next;
    }
    current->next = prev->next;
    prev->next = current;
    current->flag = is_free;
    join_free(current, current->next);
    join_free(prev, current);
    if(0) printf("\n");
}


decompiled_code:
char *__fastcall create_path(char *src, char *a2)
{
int v2; // ebp
int v3; // er12
int v4; // eax
char *v5; // rax
char *v6; // rbx
char *v7; // rax

v2 = strlen(src);
v3 = strlen(a2);
if ( v2 <= 0 )
{
v4 = 0;
LABEL_7:
v7 = (char *)calloc(v4 + v3 + v2, 1uLL);
v6 = v7;
if ( v7 )
{
strncpy(v7, src, v2);
return strncat(v6, a2, v3);
}
LABEL_5:
_assert_fail("ret", "dirlib.c", 0x13u, "create_path");
}
v4 = 1;
if ( src[v2 - 1] == 47 )
goto LABEL_7;
v5 = (char *)calloc(v3 + v2 + 2, 1uLL);
v6 = v5;
if ( !v5 )
goto LABEL_5;
strncpy(v5, src, v2);
*(_WORD *)&v6[strlen(v6)] = 47;
return strncat(v6, a2, v3);
}

canonical_decompiled_code:
char *__fastcall func0(char *src, char *a2)
{
int v2; // ebp
int v3; // er12
int v4; // eax
char *v5; // rax
char *v6; // rbx
char *v7; // rax

v2 = strlen(src);
v3 = strlen(a2);
if ( v2 <= 0 )
{
v4 = 0;
LABEL_7:
v7 = (char *)calloc(v4 + v3 + v2, 1uLL);
v6 = v7;
if ( v7 )
{
strncpy(v7, src, v2);
return strncat(v6, a2, v3);
}
LABEL_5:
_assert_fail("ret", "dirlib.c", 0x13u, "create_path");
}
v4 = 1;
if ( src[v2 - 1] == 47 )
goto LABEL_7;
v5 = (char *)calloc(v3 + v2 + 2, 1uLL);
v6 = v5;
if ( !v5 )
goto LABEL_5;
strncpy(v5, src, v2);
*(_WORD *)&v6[strlen(v6)] = 47;
return strncat(v6, a2, v3);
}

original_code:
char *create_path(const char * path, const char * filename){
    int p_len = strlen(path);
    int f_len = strlen(filename);
    int offset=1;
    if (p_len > 0){
        if (path[p_len-1] !='/')
            offset = 2;
    }
    else{
        offset = 0;
    }
    char *ret = (char *) calloc((p_len + f_len) + offset, sizeof(char));
    ((void) sizeof ((ret) ? 1 : 0), __extension__ ({ if (ret) ; else __assert_fail ("ret", "dirlib.c", 19, __extension__ __PRETTY_FUNCTION__); }));
    strncpy(ret,path,p_len);
    if (offset > 1)
        strncat(ret,"/",1);
    strncat(ret,filename,f_len);
    strncat(ret,"\0",1);
    return ret;
}

canonical_original_code:
char *create_path(char *path, char *filename){
    int p_len = strlen(path);
    int f_len = strlen(filename);
    int offset = 1;
    if (p_len > 0){
        if (path[p_len-1] !='/')
            offset = 2;
    }
    else{
        offset = 0;
    }
    char *ret = (char *) calloc((p_len + f_len) + offset, sizeof(char));
    ((void) sizeof ((ret) ? 1 : 0), __extension__ ({ if (ret) ; else __assert_fail ("ret", "dirlib.c", 19, __extension__ __PRETTY_FUNCTION__); }));
    strncpy(ret,path,p_len);
    if (offset > 1)
        strncat(ret,"/",1);
    strncat(ret,filename,f_len);
    strncat(ret,"\0",1);
    return ret;
}

variable_types:
path
char *

variable_types:
filename
char *

variable_types: offset int

variable_types:
ret
char *

return_type: char *


decompiled_code:
int print_usage()
{
printf("-l\tMinimum reelle Achse (\"left\") Default: %f\n", -1.5);
printf("-r\tMaximum reelle Achse (\"right\") Default: %f\n", 1.5);
printf(aBMinimumImagin, -1.5);
printf(aTMaximumImagin, 1.5);
printf(aPPixelProEinhe, 1000LL);
printf("-i\tMaximale Anzahl der Iterationen. Default: %d\n", 500LL);
return puts("Leerzeichen zwischen allen Argumenten notwendig");
}

canonical_decompiled_code:
int func7()
{
printf("-l\tMinimum reelle Achse (\"left\") Default: %f\n", -1.5);
printf("-r\tMaximum reelle Achse (\"right\") Default: %f\n", 1.5);
printf(aBMinimumImagin, -1.5);
printf(aTMaximumImagin, 1.5);
printf(aPPixelProEinhe, 1000LL);
printf("-i\tMaximale Anzahl der Iterationen. Default: %d\n", 500LL);
return puts("Leerzeichen zwischen allen Argumenten notwendig");
}

original_code:
void print_usage(){
    printf("-l\tMinimum reelle Achse (\"left\") Default: %f\n",-1.5);
    printf("-r\tMaximum reelle Achse (\"right\") Default: %f\n",1.5);
    printf("-b\tMinimum imaginäre Achse (\"bottom\") Default: %f\n",-1.5);
    printf("-t\tMaximum imaginäre Achse (\"top\") Default: %f\n",1.5);
    printf("-p\tPixel pro Einheit auf imaginärer/reeller Achse. Default: %d\n", 1000);
    printf("-i\tMaximale Anzahl der Iterationen. Default: %d\n",500);
    printf("Leerzeichen zwischen allen Argumenten notwendig\n");
}


decompiled_code:
__m128d __fastcall d_abs(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)xmmword_402530);
return result;
}

canonical_decompiled_code:
__m128d __fastcall func8(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)xmmword_402530);
return result;
}

original_code:
double d_abs(double d){
    if (d<0)
        d = -1 * d;
    return d;
}

variable_types: d double

return_type: double


decompiled_code:
void __fastcall my_assert(char a1, const char *a2)
{
if ( !a1 )
{
printf("Fehler:\n%s", a2);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func10(char a1, const char *a2)
{
if ( !a1 )
{
printf("Fehler:\n%s", a2);
exit(1);
}
}

original_code:
void my_assert(_Bool p, char *s){
    if (!p){
        printf("Fehler:\n%s",s);
        exit(1);
    }
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall string_to_int(char *nptr, _DWORD *a2)
{
int *v2; // rbp
int v3; // eax
unsigned int v4; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = __errno_location();
*v2 = 0;
v3 = strtol(nptr, &endptr, 10);
if ( endptr == nptr )
return 0;
v4 = 0;
if ( !*endptr && !*v2 )
{
*a2 = v3;
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *nptr, _DWORD *a2)
{
int *v2; // rbp
int v3; // eax
unsigned int v4; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = __errno_location();
*v2 = 0;
v3 = strtol(nptr, &endptr, 10);
if ( endptr == nptr )
return 0;
v4 = 0;
if ( !*endptr && !*v2 )
{
*a2 = v3;
v4 = 1;
}
return v4;
}

original_code:
_Bool string_to_int(char* s,int* val) {
    char* endptr;
    (*__errno_location ()) = 0;
    int i = strtol(s, &endptr, 10);
    if (endptr == s) return 0;
    if (*endptr) return 0;
    if ((*__errno_location ())) return 0;
    *val = i;
    return 1;
}

canonical_original_code:
_Bool string_to_int(char *s, int *val) {
    char *endptr;
    (*__errno_location ()) = 0;
    int i = strtol(s, &endptr, 10);
    if (endptr == s) return 0;
    if (*endptr) return 0;
    if ((*__errno_location ())) return 0;
    *val = i;
    return 1;
}

variable_types:
val
int *

variable_types:
endptr
char *

variable_types: i int


decompiled_code:
__int64 __fastcall string_to_double(char *nptr, double *a2)
{
int *v2; // rbp
double v3; // xmm0_8
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = __errno_location();
*v2 = 0;
v3 = strtod(nptr, &endptr);
if ( endptr == nptr )
return 0LL;
result = 0LL;
if ( !*endptr && !*v2 )
{
*a2 = v3;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *nptr, double *a2)
{
int *v2; // rbp
double v3; // xmm0_8
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = __errno_location();
*v2 = 0;
v3 = strtod(nptr, &endptr);
if ( endptr == nptr )
return 0LL;
result = 0LL;
if ( !*endptr && !*v2 )
{
*a2 = v3;
result = 1LL;
}
return result;
}

original_code:
_Bool string_to_double(char* s, double* val) {
    char* endptr;
    (*__errno_location ()) = 0;
    double x = strtod(s, &endptr);
    if (endptr == s) return 0;
    if (*endptr) return 0;
    if ((*__errno_location ())) return 0;
    *val = x;
    return 1;
}

canonical_original_code:
_Bool string_to_double(char *s, double *val) {
    char *endptr;
    (*__errno_location ()) = 0;
    double x = strtod(s, &endptr);
    if (endptr == s) return 0;
    if (*endptr) return 0;
    if ((*__errno_location ())) return 0;
    *val = x;
    return 1;
}

variable_types:
val
double *

variable_types: x double


decompiled_code:
void __fastcall parse_args(int a1, __int64 a2)
{
int v3; // ebx
int v4; // eax
char v5; // al
_BYTE *v6; // rdx
char v7; // al
char v8; // al
char v9; // al
char v10; // al
char v11; // al
char v12; // al
__int64 v13; // [rsp+0h] [rbp-28h] BYREF
int v14[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = a1 - 1;
if ( a1 - 1 > 0 )
{
while ( 1 )
{
v4 = v3;
v6 = *(_BYTE **)(a2 + 8);
if ( *v6 != 45 )
{
a2 += 8LL;
goto LABEL_20;
}
v7 = v6[1];
if ( v7 == 45 )
break;
if ( !v7 || v6[2] )
goto LABEL_4;
a2 += 16LL;
switch ( v7 )
{
case 'b':
v9 = string_to_double(*(char **)a2, (double *)&v13);
my_assert(v9, "Parsen der Argumente fehlgeschlagen.\nWert von -b muss vom Typ double sein.\n");
bottom = v13;
break;
case 'i':
v12 = string_to_int(*(char **)a2, v14);
my_assert(v12, "Parsen der Argumente fehlgeschlagen.\nWert von -i muss vom Typ int sein.\n");
n = v14[0];
my_assert(v14[0] > 0, aNMussGr);
break;
case 'l':
v5 = string_to_double(*(char **)a2, (double *)&v13);
my_assert(v5, "Parsen der Argumente fehlgeschlagen.\nWert von -l muss vom Typ double sein.\n");
left = v13;
break;
case 'p':
v11 = string_to_int(*(char **)a2, v14);
my_assert(v11, "Parsen der Argumente fehlgeschlagen.\nWert von -p muss vom Typ int sein.\n");
*(double *)&pixel = (double)v14[0];
break;
case 'r':
v10 = string_to_double(*(char **)a2, (double *)&v13);
my_assert(v10, "Parsen der Argumente fehlgeschlagen.\nWert von -r muss vom Typ double sein.\n");
right = v13;
break;
case 't':
v8 = string_to_double(*(char **)a2, (double *)&v13);
my_assert(v8, "Parsen der Argumente fehlgeschlagen.\nWert von -t muss vom Typ double sein.\n");
top = v13;
break;
default:
print_usage();
exit(1);
}
v3 -= 2;
if ( v3 <= 0 )
goto LABEL_21;
}
if ( v6[2] )
{
LABEL_4:
print_usage();
exit(1);
}
v4 = v3 - 1;
a2 += 16LL;
LABEL_20:
if ( v4 > 0 )
{
LABEL_23:
print_usage();
exit(1);
}
}
LABEL_21:
if ( *(_QWORD *)(a2 + 8) )
goto LABEL_23;
my_assert(*(double *)&right > *(double *)&left, "Left muss kleiner right sein.\n");
my_assert(*(double *)&top > *(double *)&bottom, "Bottom muss kleiner top sein.\n");
my_assert(*(double *)&pixel > 0.0, "Keine Pixel?\n");
my_assert(n > 0, "Zu wenig Iterationen.\n");
}

canonical_decompiled_code:
void __fastcall func14(int a1, __int64 a2)
{
int v3; // ebx
int v4; // eax
char v5; // al
_BYTE *v6; // rdx
char v7; // al
char v8; // al
char v9; // al
char v10; // al
char v11; // al
char v12; // al
__int64 v13; // [rsp+0h] [rbp-28h] BYREF
int v14[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = a1 - 1;
if ( a1 - 1 > 0 )
{
while ( 1 )
{
v4 = v3;
v6 = *(_BYTE **)(a2 + 8);
if ( *v6 != 45 )
{
a2 += 8LL;
goto LABEL_20;
}
v7 = v6[1];
if ( v7 == 45 )
break;
if ( !v7 || v6[2] )
goto LABEL_4;
a2 += 16LL;
switch ( v7 )
{
case 'b':
v9 = func13(*(char **)a2, (double *)&v13);
func10(v9, "Parsen der Argumente fehlgeschlagen.\nWert von -b muss vom Typ double sein.\n");
bottom = v13;
break;
case 'i':
v12 = func12(*(char **)a2, v14);
func10(v12, "Parsen der Argumente fehlgeschlagen.\nWert von -i muss vom Typ int sein.\n");
n = v14[0];
func10(v14[0] > 0, aNMussGr);
break;
case 'l':
v5 = func13(*(char **)a2, (double *)&v13);
func10(v5, "Parsen der Argumente fehlgeschlagen.\nWert von -l muss vom Typ double sein.\n");
left = v13;
break;
case 'p':
v11 = func12(*(char **)a2, v14);
func10(v11, "Parsen der Argumente fehlgeschlagen.\nWert von -p muss vom Typ int sein.\n");
*(double *)&pixel = (double)v14[0];
break;
case 'r':
v10 = func13(*(char **)a2, (double *)&v13);
func10(v10, "Parsen der Argumente fehlgeschlagen.\nWert von -r muss vom Typ double sein.\n");
right = v13;
break;
case 't':
v8 = func13(*(char **)a2, (double *)&v13);
func10(v8, "Parsen der Argumente fehlgeschlagen.\nWert von -t muss vom Typ double sein.\n");
top = v13;
break;
default:
func7();
exit(1);
}
v3 -= 2;
if ( v3 <= 0 )
goto LABEL_21;
}
if ( v6[2] )
{
LABEL_4:
func7();
exit(1);
}
v4 = v3 - 1;
a2 += 16LL;
LABEL_20:
if ( v4 > 0 )
{
LABEL_23:
func7();
exit(1);
}
}
LABEL_21:
if ( *(_QWORD *)(a2 + 8) )
goto LABEL_23;
func10(*(double *)&right > *(double *)&left, "Left muss kleiner right sein.\n");
func10(*(double *)&top > *(double *)&bottom, "Bottom muss kleiner top sein.\n");
func10(*(double *)&pixel > 0.0, "Keine Pixel?\n");
func10(n > 0, "Zu wenig Iterationen.\n");
}

original_code:
void parse_args(int c,char **v){
    int i; double d;
    while (--c > 0 && **++v == '-'){
        if (v[0][1] == '-' && v[0][2] == '\0'){
            c--; v++;
            break;
        }
        if (v[0][1] == '\0'|| v[0][2]!='\0'){
            print_usage();
            exit(1);
        }
        switch (v++[0][1]){
            case 'l':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -l muss vom Typ double sein.\n\0");
                left = d;
                break;
            case 't':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -t muss vom Typ double sein.\n\0");
                top = d;
                break;
            case 'b':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -b muss vom Typ double sein.\n\0");
                bottom = d;
                break;
            case 'r':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -r muss vom Typ double sein.\n\0");
                right = d;
                break;
            case 'p':
                my_assert(string_to_int(v[0],&i),"Parsen der Argumente fehlgeschlagen.\nWert von -p muss vom Typ int sein.\n\0");
                pixel = i;
                break;
            case 'i':
                my_assert(string_to_int(v[0],&i),"Parsen der Argumente fehlgeschlagen.\nWert von -i muss vom Typ int sein.\n\0");
                n = i;
                my_assert(n>0,"n muss größer 0 sein\n\0");
                break;
            case 'h':
            default:
                print_usage();
                exit(1);
        }
        c--;
    }
    if (c>0 || *++v != '\0'){
        print_usage();
        exit(1);
    }
    my_assert(left<right,"Left muss kleiner right sein.\n\0");
    my_assert(bottom<top,"Bottom muss kleiner top sein.\n\0");
    my_assert(pixel>0,"Keine Pixel?\n\0");
    my_assert(n>0,"Zu wenig Iterationen.\n\0");
}

canonical_original_code:
void parse_args(int c, char **v){
    int i; double d;
    while (--c > 0 && **++v == '-'){
        if (v[0][1] == '-' && v[0][2] == '\0'){
            c--; v++;
            break;
        }
        if (v[0][1] == '\0'|| v[0][2]!='\0'){
            print_usage();
            exit(1);
        }
        switch (v++[0][1]){
            case 'l':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -l muss vom Typ double sein.\n\0");
                left = d;
                break;
            case 't':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -t muss vom Typ double sein.\n\0");
                top = d;
                break;
            case 'b':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -b muss vom Typ double sein.\n\0");
                bottom = d;
                break;
            case 'r':
                my_assert(string_to_double(v[0],&d),"Parsen der Argumente fehlgeschlagen.\nWert von -r muss vom Typ double sein.\n\0");
                right = d;
                break;
            case 'p':
                my_assert(string_to_int(v[0],&i),"Parsen der Argumente fehlgeschlagen.\nWert von -p muss vom Typ int sein.\n\0");
                pixel = i;
                break;
            case 'i':
                my_assert(string_to_int(v[0],&i),"Parsen der Argumente fehlgeschlagen.\nWert von -i muss vom Typ int sein.\n\0");
                n = i;
                my_assert(n>0,"n muss größer 0 sein\n\0");
                break;
            case 'h':
            default:
                print_usage();
                exit(1);
        }
        c--;
    }
    if (c>0 || *++v != '\0'){
        print_usage();
        exit(1);
    }
    my_assert(left<right,"Left muss kleiner right sein.\n\0");
    my_assert(bottom<top,"Bottom muss kleiner top sein.\n\0");
    my_assert(pixel>0,"Keine Pixel?\n\0");
    my_assert(n>0,"Zu wenig Iterationen.\n\0");
}

variable_types: c int

variable_types:
v
char **


decompiled_code:
__int64 __fastcall get_green(int a1)
{
return (unsigned int)(int)(pow((double)a1 / (double)n, 0.2) * 255.0);
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return (unsigned int)(int)(pow((double)a1 / (double)n, 0.2) * 255.0);
}

original_code:
int get_green(int it){
    return pow((((double) it)/((double) n)),0.2)*255;
}

variable_types: it int


decompiled_code:
char __fastcall copy_file(const char *a1, char *a2)
{
char result; // al
char v3; // al
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
char v8; // bl
int v9; // edx
int v10; // ecx
int v11; // er8
int v12; // er9
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

result = a2 != 0LL && a1 != 0LL;
if ( result )
{
lstat(a1, &v13);
v3 = copy_file_content(a1, a2);
v8 = v3;
if ( v3 )
{
v3 = copy_time_stamp(
a2,
(__int64)a2,
v4,
v5,
v6,
v7,
v13.st_dev,
v13.st_ino,
v13.st_nlink,
v13.st_mode,
v13.st_gid,
v13.st_rdev,
v13.st_size,
v13.st_blksize,
v13.st_blocks,
*(_OWORD *)&v13.st_atim,
*(_OWORD *)&v13.st_mtim);
v8 = v3;
if ( v3 )
v3 = copy_permissions(a2, (int)a2, v9, v10, v11, v12, v13.st_dev, v13.st_ino, v13.st_nlink, v13.st_mode);
}
result = v8 & v3;
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(const char *a1, char *a2)
{
char result; // al
char v3; // al
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
char v8; // bl
int v9; // edx
int v10; // ecx
int v11; // er8
int v12; // er9
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

result = a2 != 0LL && a1 != 0LL;
if ( result )
{
lstat(a1, &v13);
v3 = func0(a1, a2);
v8 = v3;
if ( v3 )
{
v3 = func1(
a2,
(__int64)a2,
v4,
v5,
v6,
v7,
v13.st_dev,
v13.st_ino,
v13.st_nlink,
v13.st_mode,
v13.st_gid,
v13.st_rdev,
v13.st_size,
v13.st_blksize,
v13.st_blocks,
*(_OWORD *)&v13.st_atim,
*(_OWORD *)&v13.st_mtim);
v8 = v3;
if ( v3 )
v3 = func2(a2, (int)a2, v9, v10, v11, v12, v13.st_dev, v13.st_ino, v13.st_nlink, v13.st_mode);
}
result = v8 & v3;
}
return result;
}

original_code:
_Bool copy_file(const char * src, const char * dst){
    _Bool ret = 0, content = 0,
         timestamp = 0, permissions = 0;
    if (src && dst){
        struct stat stat_buf;
        lstat(src, &stat_buf);
        content = copy_file_content(src, dst);
        if (content)
            timestamp = copy_time_stamp(dst, stat_buf);
        if (content && timestamp)
            permissions = copy_permissions(dst, stat_buf);
        ret = content && timestamp && permissions;
    }
    return ret;
}

canonical_original_code:
_Bool copy_file(char *src, char *dst){
    _Bool ret = 0; _Bool content = 0; _Bool timestamp = 0; _Bool permissions = 0;
    if (src && dst){
        struct stat stat_buf;
        lstat(src, &stat_buf);
        content = copy_file_content(src, dst);
        if (content)
            timestamp = copy_time_stamp(dst, stat_buf);
        if (content && timestamp)
            permissions = copy_permissions(dst, stat_buf);
        ret = content && timestamp && permissions;
    }
    return ret;
}

variable_types:
src
char *

variable_types:
dst
char *

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

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


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

result = malloc(0x18uLL);
if ( !result )
{
fwrite("Couldn't allocate memory\n.", 1uLL, 0x1AuLL, stderr);
exit(1);
}
result[2] = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
if ( !result )
{
fwrite("Couldn't allocate memory\n.", 1uLL, 0x1AuLL, stderr);
exit(1);
}
result[2] = 0LL;
result[1] = 0LL;
return result;
}

original_code:
node* create_root() {
 node* root = malloc(sizeof(node));
 if(root == ((void *)0)) {
  fprintf(stderr,"Couldn't allocate memory\n.");
  exit(1);
 }
 root->father = 0;
 root->mother = 0;
 return root;
}

canonical_original_code:
struct node *create_root() {
 struct node *root = malloc(sizeof(node));
 if(root == ((void *)0)) {
  fprintf(stderr,"Couldn't allocate memory\n.");
  exit(1);
 }
 root->father = 0;
 root->mother = 0;
 return root;
}

variable_types: struct node { char *name; struct node *mother; struct node *father; } *


printped

decompiled_code:
__int64 __fastcall printped(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax

if ( a1 )
{
printped(*(_QWORD *)(a1 + 16), a2 + 1);
v2 = a2;
if ( (int)a2 > 0 )
{
do
{
printf(" ");
--v2;
}
while ( v2 );
}
puts(*(const char **)a1);
result = printped(*(_QWORD *)(a1 + 8), a2 + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax

if ( a1 )
{
func10(*(_QWORD *)(a1 + 16), a2 + 1);
v2 = a2;
if ( (int)a2 > 0 )
{
do
{
printf(" ");
--v2;
}
while ( v2 );
}
puts(*(const char **)a1);
result = func10(*(_QWORD *)(a1 + 8), a2 + 1);
}
return result;
}

original_code:
static void printped(node* root, size_t indent) {
 if(root != ((void *)0)) {
  printped(root->father,indent+1);
  int i;
  for(i = indent; i > 0; i--) {
   printf("   ");
  }
  printf("%s\n",root->name);
  printped(root->mother,indent+1);
 }
}

canonical_original_code:
static void printped(struct node *root, unsigned long indent) {
 if(root != ((void *)0)) {
  printped(root->father,indent+1);
  int i;
  for(i = indent; i > 0; i--) {
   printf("   ");
  }
  printf("%s\n",root->name);
  printped(root->mother,indent+1);
 }
}

variable_types:
indent
unsigned long

user_defined_types: struct node { char *name; struct node *mother; struct node *father; }


print

decompiled_code:
__int64 __fastcall print(__int64 a1)
{
return printped(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return func10(a1, 0LL);
}

original_code:
void print(node* root) {
    printped(root,0);
}

canonical_original_code:
void print(struct node *root) {
    printped(root,0);
}


decompiled_code:
_BOOL8 __fastcall dir_filter(const struct dirent *a1)
{
bool v1; // dl
bool v2; // zf
_BOOL4 v3; // esi

v1 = strcmp(a1->d_name, ".") != 0;
v2 = strcmp(a1->d_name, "..") == 0;
v3 = 0;
if ( ((a1->d_type - 4) & 0xFB) == 0 )
v3 = v1 && !v2;
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const struct dirent *a1)
{
bool v1; // dl
bool v2; // zf
_BOOL4 v3; // esi

v1 = strcmp(a1->d_name, ".") != 0;
v2 = strcmp(a1->d_name, "..") == 0;
v3 = 0;
if ( ((a1->d_type - 4) & 0xFB) == 0 )
v3 = v1 && !v2;
return v3;
}

original_code:
static int dir_filter(const struct dirent *dir){
    int ret = 0, self, parent;
    self = strcmp(dir->d_name, ".\0");
    parent = strcmp(dir->d_name, "..\0");
    if ((dir->d_type == DT_REG || dir->d_type == DT_DIR)
            && (self != 0) && (parent != 0))
        ret = 1;
    return ret;
}

canonical_original_code:
static int dir_filter(struct dirent *dir){
    int ret = 0; int self; int parent;
    self = strcmp(dir->d_name, ".\0");
    parent = strcmp(dir->d_name, "..\0");
    if ((dir->d_type == DT_REG || dir->d_type == DT_DIR)
            && (self != 0) && (parent != 0))
        ret = 1;
    return ret;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *

variable_types: ret int

variable_types: self int

variable_types: parent int


decompiled_code:
void __fastcall update_dir(const char *a1, const char *a2, int a3, unsigned __int8 a4)
{
int v4; // eax
int v5; // er15
int v6; // er14
int v7; // ebp
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
char *v12; // r12
char *v13; // rbx
char *v14; // r12
int v15; // eax
int v16; // [rsp+10h] [rbp-178h]
struct stat v19; // [rsp+20h] [rbp-168h] BYREF
struct stat buf; // [rsp+B0h] [rbp-D8h] BYREF
struct dirent **v21; // [rsp+140h] [rbp-48h] BYREF
struct dirent **namelist; // [rsp+148h] [rbp-40h] BYREF

namelist = 0LL;
v21 = 0LL;
v4 = scandir(
a1,
&namelist,
(int (*)(const struct dirent *))dir_filter,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v4 < 0 )
{
printf("Try to open %s, but:\n", a1);
v8 = _errno_location();
v9 = strerror(*v8);
printf("ERROR: %s\n", v9);
exit(2);
}
v5 = v4;
v16 = scandir(
a2,
&v21,
(int (*)(const struct dirent *))dir_filter,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v16 < 0 )
{
printf("Try to open %s, but:\n", a2);
v10 = _errno_location();
v11 = strerror(*v10);
printf("ERROR: %s\n", v11);
exit(2);
}
v6 = 0;
v7 = 0;
if ( v5 > 0 )
{
while ( 1 )
{
v13 = (char *)create_path(a1, namelist[v7]->d_name);
lstat(v13, &buf);
if ( v16 <= v6 )
break;
v14 = v21[v6]->d_name;
v15 = strcmp(namelist[v7]->d_name, v14);
if ( v15 < 0 )
break;
if ( v15 <= 0 )
{
v12 = (char *)create_path(a2, v14);
if ( (buf.st_mode & 0xF000) == 0x4000 )
{
if ( a3 > 1 )
{
update_dir(v13, v12, (unsigned int)(a3 - 1), a4);
}
else if ( a4 )
{
puts("Reached recursion limit");
}
}
else
{
lstat(v12, &v19);
if ( v19.st_mtim.tv_sec < buf.st_mtim.tv_sec )
{
copy_file(v13, v12);
if ( a4 )
printf("Update\t%s\t->\t%s\n", v13, v12);
}
}
free(namelist[v7]);
free(v21[v6++]);
LABEL_15:
free(v13);
if ( v12 )
free(v12);
goto LABEL_17;
}
++v6;
--v7;
free(v13);
LABEL_17:
if ( v5 <= ++v7 )
goto LABEL_32;
}
v12 = (char *)create_path(a2, namelist[v7]->d_name);
if ( (buf.st_mode & 0xF000) == 0x8000 )
{
copy_file(v13, v12);
if ( a4 )
printf("Copy\t%s\t->\t%s\n", v13, v12);
}
else if ( !mkdir(v12, buf.st_mode) )
{
if ( a3 > 1 )
{
update_dir(v13, v12, (unsigned int)(a3 - 1), a4);
}
else if ( a4 )
{
puts("Reached recursion limit");
}
}
free(namelist[v7]);
goto LABEL_15;
}
LABEL_32:
if ( v21 )
free(v21);
if ( namelist )
free(namelist);
}

canonical_decompiled_code:
void __fastcall func1(const char *a1, const char *a2, int a3, unsigned __int8 a4)
{
int v4; // eax
int v5; // er15
int v6; // er14
int v7; // ebp
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
char *v12; // r12
char *v13; // rbx
char *v14; // r12
int v15; // eax
int v16; // [rsp+10h] [rbp-178h]
struct stat v19; // [rsp+20h] [rbp-168h] BYREF
struct stat buf; // [rsp+B0h] [rbp-D8h] BYREF
struct dirent **v21; // [rsp+140h] [rbp-48h] BYREF
struct dirent **namelist; // [rsp+148h] [rbp-40h] BYREF

namelist = 0LL;
v21 = 0LL;
v4 = scandir(
a1,
&namelist,
(int (*)(const struct dirent *))dir_filter,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v4 < 0 )
{
printf("Try to open %s, but:\n", a1);
v8 = _errno_location();
v9 = strerror(*v8);
printf("ERROR: %s\n", v9);
exit(2);
}
v5 = v4;
v16 = scandir(
a2,
&v21,
(int (*)(const struct dirent *))dir_filter,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v16 < 0 )
{
printf("Try to open %s, but:\n", a2);
v10 = _errno_location();
v11 = strerror(*v10);
printf("ERROR: %s\n", v11);
exit(2);
}
v6 = 0;
v7 = 0;
if ( v5 > 0 )
{
while ( 1 )
{
v13 = (char *)create_path(a1, namelist[v7]->d_name);
lstat(v13, &buf);
if ( v16 <= v6 )
break;
v14 = v21[v6]->d_name;
v15 = strcmp(namelist[v7]->d_name, v14);
if ( v15 < 0 )
break;
if ( v15 <= 0 )
{
v12 = (char *)create_path(a2, v14);
if ( (buf.st_mode & 0xF000) == 0x4000 )
{
if ( a3 > 1 )
{
func1(v13, v12, (unsigned int)(a3 - 1), a4);
}
else if ( a4 )
{
puts("Reached recursion limit");
}
}
else
{
lstat(v12, &v19);
if ( v19.st_mtim.tv_sec < buf.st_mtim.tv_sec )
{
copy_file(v13, v12);
if ( a4 )
printf("Update\t%s\t->\t%s\n", v13, v12);
}
}
free(namelist[v7]);
free(v21[v6++]);
LABEL_15:
free(v13);
if ( v12 )
free(v12);
goto LABEL_17;
}
++v6;
--v7;
free(v13);
LABEL_17:
if ( v5 <= ++v7 )
goto LABEL_32;
}
v12 = (char *)create_path(a2, namelist[v7]->d_name);
if ( (buf.st_mode & 0xF000) == 0x8000 )
{
copy_file(v13, v12);
if ( a4 )
printf("Copy\t%s\t->\t%s\n", v13, v12);
}
else if ( !mkdir(v12, buf.st_mode) )
{
if ( a3 > 1 )
{
func1(v13, v12, (unsigned int)(a3 - 1), a4);
}
else if ( a4 )
{
puts("Reached recursion limit");
}
}
free(namelist[v7]);
goto LABEL_15;
}
LABEL_32:
if ( v21 )
free(v21);
if ( namelist )
free(namelist);
}

original_code:
void update_dir(const char * src_path, const char * dst_path, int rec_bucket, _Bool verbose){
    struct dirent **src_list = 0;
    struct dirent **dst_list = 0;
    int count_scr, count_dst, delta, i, j;
    char *path_src_file=0, *path_dst_file=0;
    count_scr = scandir(src_path, &src_list, dir_filter, alphasort);
    if (count_scr<0){
        printf("Try to open %s, but:\n",src_path);
        printf("ERROR: %s\n", strerror((*__errno_location ())));
        exit(2);
    }
    count_dst = scandir(dst_path, &dst_list, dir_filter, alphasort);
    if (count_dst <0){
        printf("Try to open %s, but:\n",dst_path);
        printf("ERROR: %s\n", strerror((*__errno_location ())));
        exit(2);
    }
    struct stat stat_src, stat_dst;
    for (i=0,j=0; i<count_scr; i++){
        path_src_file = create_path(src_path, src_list[i]->d_name);
        lstat(path_src_file, &stat_src);
        if (j+1 > count_dst)
            delta = -1;
        else
            delta = strcmp(src_list[i]->d_name, dst_list[j]->d_name);
        if (delta < 0){
            path_dst_file = create_path(dst_path, src_list[i]->d_name);
            if (((((stat_src.st_mode)) & 0170000) == (0100000))){
                copy_file(path_src_file, path_dst_file);
                if (verbose)
                    printf("Copy\t%s\t->\t%s\n",path_src_file,path_dst_file);
            }
            else{
                if (0 == mkdir(path_dst_file, stat_src.st_mode)){
                    if (rec_bucket > 1)
                        update_dir(path_src_file, path_dst_file, rec_bucket - 1, verbose);
                    else {
                        if (verbose)
                            printf("Reached recursion limit\n");
                    }
                }
            }
            free(src_list[i]);
        }
        else if (delta > 0){
            j++;
            i--;
            path_dst_file = 0;
        }
        else if (delta == 0){
            path_dst_file = create_path(dst_path, dst_list[j]->d_name);
            if (((((stat_src.st_mode)) & 0170000) == (0040000))){
                if (rec_bucket > 1)
                    update_dir(path_src_file, path_dst_file, rec_bucket - 1, verbose);
                else {
                    if (verbose)
                        printf("Reached recursion limit\n");
                }
            }
            else {
                lstat(path_dst_file, &stat_dst);
                if (stat_dst.st_mtim.tv_sec < stat_src.st_mtim.tv_sec){
                    copy_file(path_src_file, path_dst_file);
                    if (verbose)
                        printf("Update\t%s\t->\t%s\n",path_src_file,path_dst_file);
                }
            }
            free(src_list[i]);
            free(dst_list[j]);
            j++;
        }
        if (path_src_file)
            free(path_src_file);
        if (path_dst_file)
            free(path_dst_file);
    }
    if (dst_list)
        free(dst_list);
    if (src_list)
        free(src_list);
}

canonical_original_code:
void update_dir(char *src_path, char *dst_path, int rec_bucket, _Bool verbose){
    struct dirent **src_list = 0;
    struct dirent **dst_list = 0;
    int count_scr; int count_dst; int delta; int i; int j;
    char *path_src_file = 0; char *path_dst_file = 0;
    count_scr = scandir(src_path, &src_list, dir_filter, alphasort);
    if (count_scr<0){
        printf("Try to open %s, but:\n",src_path);
        printf("ERROR: %s\n", strerror((*__errno_location ())));
        exit(2);
    }
    count_dst = scandir(dst_path, &dst_list, dir_filter, alphasort);
    if (count_dst <0){
        printf("Try to open %s, but:\n",dst_path);
        printf("ERROR: %s\n", strerror((*__errno_location ())));
        exit(2);
    }
    struct stat stat_src; struct stat stat_dst;
    for (i=0,j=0; i<count_scr; i++){
        path_src_file = create_path(src_path, src_list[i]->d_name);
        lstat(path_src_file, &stat_src);
        if (j+1 > count_dst)
            delta = -1;
        else
            delta = strcmp(src_list[i]->d_name, dst_list[j]->d_name);
        if (delta < 0){
            path_dst_file = create_path(dst_path, src_list[i]->d_name);
            if (((((stat_src.st_mode)) & 0170000) == (0100000))){
                copy_file(path_src_file, path_dst_file);
                if (verbose)
                    printf("Copy\t%s\t->\t%s\n",path_src_file,path_dst_file);
            }
            else{
                if (0 == mkdir(path_dst_file, stat_src.st_mode)){
                    if (rec_bucket > 1)
                        update_dir(path_src_file, path_dst_file, rec_bucket - 1, verbose);
                    else {
                        if (verbose)
                            printf("Reached recursion limit\n");
                    }
                }
            }
            free(src_list[i]);
        }
        else if (delta > 0){
            j++;
            i--;
            path_dst_file = 0;
        }
        else if (delta == 0){
            path_dst_file = create_path(dst_path, dst_list[j]->d_name);
            if (((((stat_src.st_mode)) & 0170000) == (0040000))){
                if (rec_bucket > 1)
                    update_dir(path_src_file, path_dst_file, rec_bucket - 1, verbose);
                else {
                    if (verbose)
                        printf("Reached recursion limit\n");
                }
            }
            else {
                lstat(path_dst_file, &stat_dst);
                if (stat_dst.st_mtim.tv_sec < stat_src.st_mtim.tv_sec){
                    copy_file(path_src_file, path_dst_file);
                    if (verbose)
                        printf("Update\t%s\t->\t%s\n",path_src_file,path_dst_file);
                }
            }
            free(src_list[i]);
            free(dst_list[j]);
            j++;
        }
        if (path_src_file)
            free(path_src_file);
        if (path_dst_file)
            free(path_dst_file);
    }
    if (dst_list)
        free(dst_list);
    if (src_list)
        free(src_list);
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types: delta int

variable_types: j int

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


isPalindromeBoth

repo: RockNCode/EulerProblems

decompiled_code:
__int64 __fastcall isPalindromeBoth(unsigned int a1)
{
__int64 result; // rax
__int64 v2[2]; // [rsp+0h] [rbp-28h] BYREF
int v3; // [rsp+10h] [rbp-18h]
char s[15]; // [rsp+19h] [rbp-Fh] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
v3 = 0;
sprintf(s, "%d", a1);
convertToBinaryString(a1, v2);
result = isPalindrome(s);
if ( (_DWORD)result )
result = (unsigned int)isPalindrome(v2) != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 result; // rax
__int64 v2[2]; // [rsp+0h] [rbp-28h] BYREF
int v3; // [rsp+10h] [rbp-18h]
char s[15]; // [rsp+19h] [rbp-Fh] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
v3 = 0;
sprintf(s, "%d", a1);
func10(a1, v2);
result = func11(s);
if ( (_DWORD)result )
result = (unsigned int)func11(v2) != 0;
return result;
}

original_code:
int isPalindromeBoth(int digit){
    char bufferDec[7];
    char bin[20] = {((void *)0)};
    int decLen = sprintf(bufferDec,"%d",digit);
    convertToBinaryString(digit,bin);
    if(!isPalindrome(bufferDec)){
        return 0;
    }
    if(!isPalindrome(bin)){
        return 0;
    }
    return 1;
}

variable_types: digit int

variable_types:
bufferDec
char [7]

variable_types:
bin
char [20]

variable_types: decLen int


charToDigit

decompiled_code:
__int64 __fastcall charToDigit(char a1)
{
return (unsigned int)(a1 - 48);
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return (unsigned int)(a1 - 48);
}

original_code:
int charToDigit(char mychar){
  return mychar - '0';
}

variable_types: mychar char


digitToChar

decompiled_code:
__int64 __fastcall digitToChar(int a1)
{
return (unsigned int)(a1 + 48);
}

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

original_code:
char digitToChar(int digit)
{
    return '0' + digit;
}

return_type: char


convertToBinaryString

decompiled_code:
void __fastcall convertToBinaryString(int a1, _BYTE *a2)
{
int v2; // ebx
int v4; // eax

if ( a1 > 0 )
{
v2 = a1;
do
{
*a2 = digitToChar(v2 % 2);
v4 = v2;
v2 /= 2;
++a2;
}
while ( v4 > 1 );
}
}

original_code:
int convertToBinaryString(int dec, char bin[]){
    int i =0;
    while(dec >=1 ){
        bin[i]= digitToChar(dec % 2);
        dec /=2;
        i++;
    }
}

canonical_original_code:
int convertToBinaryString(int dec, char bin[]){
    int i = 0;
    while(dec >=1 ){
        bin[i]= digitToChar(dec % 2);
        dec /=2;
        i++;
    }
}

variable_types: dec int

variable_types:
bin
char []

variable_types: i int


isPalindrome

decompiled_code:
__int64 __fastcall isPalindrome(const char *a1)
{
const char *v1; // rbx
const char *v2; // rdx
char v3; // al

v1 = a1;
v2 = &a1[(int)strlen(a1) - 1];
while ( 1 )
{
v3 = *v1;
if ( !*v1 )
break;
++v1;
if ( *v2-- != v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
const char *v1; // rbx
const char *v2; // rdx
char v3; // al

v1 = a1;
v2 = &a1[(int)strlen(a1) - 1];
while ( 1 )
{
v3 = *v1;
if ( !*v1 )
break;
++v1;
if ( *v2-- != v3 )
return 0LL;
}
return 1LL;
}

original_code:
int isPalindrome(char str[]){
    int len = strlen(str);
    char *start = str;
    char *end = str+len-1;
    while( *(start) !='\0'){
        if(*(start++) != *(end--))
        {
            return 0;
        }
    }
    return 1;
}

variable_types:
str
char []

variable_types: len int

variable_types:
start
char *

variable_types:
end
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // er12

v3 = 0;
v4 = 0;
v5 = 0;
do
{
if ( (unsigned int)isPalindromeBoth(v4) )
{
v5 += v4;
++v3;
}
++v4;
}
while ( v4 != 1000000 );
printf("Total both base palindromes below 1000000 is %d and the sum is %d \n", v3, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // er12

v3 = 0;
v4 = 0;
v5 = 0;
do
{
if ( (unsigned int)func7(v4) )
{
v5 += v4;
++v3;
}
++v4;
}
while ( v4 != 1000000 );
printf("Total both base palindromes below 1000000 is %d and the sum is %d \n", v3, v5);
return 0;
}

original_code:
int main(){
    int sum =0;
    int i=0;
    int totalNum=0;
    for( i= 0 ; i<1000000;i++){
        if(isPalindromeBoth(i)){
            sum+=i;
            totalNum++;
        }
    }
    printf("Total both base palindromes below 1000000 is %d and the sum is %d \n",totalNum,sum);
}

canonical_original_code:
int main(){
    int sum = 0;
    int i = 0;
    int totalNum = 0;
    for( i= 0 ; i<1000000;i++){
        if(isPalindromeBoth(i)){
            sum+=i;
            totalNum++;
        }
    }
    printf("Total both base palindromes below 1000000 is %d and the sum is %d \n",totalNum,sum);
}

variable_types: sum int

variable_types: totalNum int


decompiled_code:
void __noreturn sigint_handler()
{
puts("\nClosing Socket....");
close(http_socket_fd);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("\nClosing Socket....");
close(http_socket_fd);
exit(0);
}

original_code:
void sigint_handler(int sig)
{
    printf("\nClosing Socket....\n");
    close(http_socket_fd);
    exit(0);
}

variable_types: sig int


readline

original_code:
size_t readline(int connection, char* buffer, size_t size)
{
    int i = 0;
    char c = '\0';
    int recv_size;
    while((i < size-1) && (c != '\n'))
    {
        recv_size = recv(connection, &c, 1, 0);
        if (recv_size > 0)
        {
            if (c == '\r')
            {
                recv_size = recv(connection, &c, 1, MSG_PEEK);
                if ((recv_size >0) && (c == '\n'))
                {
                    recv(connection, &c, 1, 0);
                }
                else
                {
                    c = '\n';
                }
            }
            buffer[i] = c;
            i++;
        }
        else
        {
            c = '\n';
        }
    }
    buffer[i] = '\0';
    return i;
}

canonical_original_code:
unsigned long readline(int connection, char *buffer, unsigned long size)
{
    int i = 0;
    char c = '\0';
    int recv_size;
    while((i < size-1) && (c != '\n'))
    {
        recv_size = recv(connection, &c, 1, 0);
        if (recv_size > 0)
        {
            if (c == '\r')
            {
                recv_size = recv(connection, &c, 1, MSG_PEEK);
                if ((recv_size >0) && (c == '\n'))
                {
                    recv(connection, &c, 1, 0);
                }
                else
                {
                    c = '\n';
                }
            }
            buffer[i] = c;
            i++;
        }
        else
        {
            c = '\n';
        }
    }
    buffer[i] = '\0';
    return i;
}

variable_types: connection int

variable_types:
buffer
char *

variable_types:
size
unsigned long

variable_types: c char

return_type: unsigned long


decompiled_code:
int __fastcall write_line(int fd, void *buf)
{
int v2; // eax
ssize_t v3; // rax

v2 = strlen((const char *)buf);
v3 = send(fd, buf, v2, 0);
if ( v3 == -1 )
LODWORD(v3) = printf("Unable to send line");
return v3;
}

canonical_decompiled_code:
int __fastcall func3(int fd, void *buf)
{
int v2; // eax
ssize_t v3; // rax

v2 = strlen((const char *)buf);
v3 = send(fd, buf, v2, 0);
if ( v3 == -1 )
LODWORD(v3) = printf("Unable to send line");
return v3;
}

original_code:
void write_line(int connection, char* str)
{ if (send(connection, str,(int)strlen(str), 0) == -1)
        printf("Unable to send line");
}

canonical_original_code:
void write_line(int connection, char *str)
{ if (send(connection, str,(int)strlen(str), 0) == -1)
        printf("Unable to send line");
}

variable_types:
str
char *


decompiled_code:
void __fastcall __noreturn connection_consumer(void *a1)
{
int v1; // eax

while ( 1 )
{
v1 = get_next_connection(connection_queue);
connection_handler(v1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func5(void *a1)
{
int v1; // eax

while ( 1 )
{
v1 = get_next_connection(connection_queue);
func4(v1);
}
}

original_code:
void *connection_consumer (void *param)
{
    while (1)
    {
        int connection_fd = get_next_connection(connection_queue);
        connection_handler(connection_fd);
    }
    return 0;
}

canonical_original_code:
void *connection_consumer(void *param)
{
    while (1)
    {
        int connection_fd = get_next_connection(connection_queue);
        connection_handler(connection_fd);
    }
    return 0;
}

variable_types:
param
void *

return_type: void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
_QWORD *v4; // rbx
int v5; // eax
unsigned int v6; // eax
pthread_t v7; // [rsp+0h] [rbp-48h] BYREF
int optval; // [rsp+8h] [rbp-40h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-28h] BYREF

if ( argc > 1 )
{
v3 = atoi(argv[1]);
_sysv_signal(2, (__sighandler_t)sigint_handler);
connection_queue = (__int64)malloc(0x200uLL);
setup_queue(connection_queue);
v4 = &thread_pool;
while ( !pthread_create(&v7, 0LL, connection_consumer, 0LL) )
{
*v4++ = v7;
if ( v4 == (_QWORD *)(unsigned int)((_DWORD)&thread_pool + 240) )
{
v5 = socket(2, 1, 0);
http_socket_fd = v5;
if ( v5 != -1 )
{
optval = 1;
if ( setsockopt(v5, 1, 2, &optval, 4u) != -1 )
{
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v3);
*(_DWORD *)&addr.sa_data[2] = 0;
if ( bind(http_socket_fd, &addr, 0x10u) != -1 )
{
if ( listen(http_socket_fd, 10) == -1 )
{
perror("Unable to Listen on Socket");
exit(1);
}
printf("Server is listening on port %d\n", v3);
while ( 1 )
{
addr_len = 16;
v6 = accept(http_socket_fd, &v11, &addr_len);
if ( v6 == -1 )
perror("Unable to accept connection");
else
add_connection(connection_queue, v6);
}
}
perror("Unable to Bind Socket");
exit(1);
}
perror("setsockopt");
exit(1);
}
perror("Socket Creation Failed");
exit(1);
}
}
perror("Error creating consumer thread");
exit(1);
}
puts("You must supply a port number for web server. Perhaps 80? ");
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
_QWORD *v4; // rbx
int v5; // eax
unsigned int v6; // eax
pthread_t v7; // [rsp+0h] [rbp-48h] BYREF
int optval; // [rsp+8h] [rbp-40h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-28h] BYREF

if ( argc > 1 )
{
v3 = atoi(argv[1]);
_sysv_signal(2, (__sighandler_t)sigint_handler);
connection_queue = (__int64)malloc(0x200uLL);
setup_queue(connection_queue);
v4 = &thread_pool;
while ( !pthread_create(&v7, 0LL, connection_consumer, 0LL) )
{
*v4++ = v7;
if ( v4 == (_QWORD *)(unsigned int)((_DWORD)&thread_pool + 240) )
{
v5 = socket(2, 1, 0);
http_socket_fd = v5;
if ( v5 != -1 )
{
optval = 1;
if ( setsockopt(v5, 1, 2, &optval, 4u) != -1 )
{
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(v3);
*(_DWORD *)&addr.sa_data[2] = 0;
if ( bind(http_socket_fd, &addr, 0x10u) != -1 )
{
if ( listen(http_socket_fd, 10) == -1 )
{
perror("Unable to Listen on Socket");
exit(1);
}
printf("Server is listening on port %d\n", v3);
while ( 1 )
{
addr_len = 16;
v6 = accept(http_socket_fd, &v11, &addr_len);
if ( v6 == -1 )
perror("Unable to accept connection");
else
add_connection(connection_queue, v6);
}
}
perror("Unable to Bind Socket");
exit(1);
}
perror("setsockopt");
exit(1);
}
perror("Socket Creation Failed");
exit(1);
}
}
perror("Error creating consumer thread");
exit(1);
}
puts("You must supply a port number for web server. Perhaps 80? ");
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
    if (argc <2)
    {
        printf("You must supply a port number for web server. Perhaps 80? \n");
        exit(0);
    }
    int server_port = atoi(argv[1]);
    signal(2, sigint_handler);
    connection_queue = (connection_queue_t*)malloc(sizeof(connection_queue_t));
    setup_queue(connection_queue);
    int thread_index = 0;
    while (thread_index < 30)
    {
        pthread_t consumer_thread;
        if (pthread_create(&consumer_thread, ((void *)0), connection_consumer, ((void *)0)))
        {
            perror("Error creating consumer thread");
            exit(1);
        }
        thread_pool[thread_index] = consumer_thread;
        thread_index++;
    }
    int connection_fd;
    struct sockaddr_in their_addr;
    struct sockaddr_in my_addr;
    socklen_t sin_size;
    if ((http_socket_fd = socket(2, SOCK_STREAM, 0)) == -1)
    {
        perror("Socket Creation Failed");
        exit(1);
    }
    int reuse_socket = 1;
    if (setsockopt(http_socket_fd,1,2,&reuse_socket,sizeof(int)) == -1)
    {
        perror("setsockopt");
        exit(1);
    }
    my_addr.sin_family = 2;
    my_addr.sin_port = htons(server_port);
    my_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    if (bind(http_socket_fd, (struct sockaddr *)&my_addr,
             sizeof(struct sockaddr)) == -1)
    {
        perror("Unable to Bind Socket");
        exit(1);
    }
    if (listen(http_socket_fd, 10) == -1)
    {
        perror("Unable to Listen on Socket");
        exit(1);
    }
    printf("Server is listening on port %d\n", server_port);
    while(1)
    {
        sin_size = sizeof(struct sockaddr_in);
        if ((connection_fd = accept(http_socket_fd, (struct sockaddr *)&their_addr,
                                    &sin_size)) == -1)
        {
            perror("Unable to accept connection");
            continue;
        }
        add_connection(connection_queue, connection_fd);
    }
    close(connection_fd);
    thread_index = 0;
    while (thread_index < 30)
    {
        if (pthread_join(thread_pool[thread_index], ((void *)0)))
        {
            printf("error joining consumer");
            abort();
        }
    }
    free(connection_queue);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if (argc <2)
    {
        printf("You must supply a port number for web server. Perhaps 80? \n");
        exit(0);
    }
    int server_port = atoi(argv[1]);
    signal(2, sigint_handler);
    connection_queue = (struct connection_queue *)malloc(sizeof(connection_queue_t));
    setup_queue(connection_queue);
    int thread_index = 0;
    while (thread_index < 30)
    {
        unsigned long consumer_thread;
        if (pthread_create(&consumer_thread, ((void *)0), connection_consumer, ((void *)0)))
        {
            perror("Error creating consumer thread");
            exit(1);
        }
        thread_pool[thread_index] = consumer_thread;
        thread_index++;
    }
    int connection_fd;
    struct sockaddr_in their_addr;
    struct sockaddr_in my_addr;
    unsigned int sin_size;
    if ((http_socket_fd = socket(2, SOCK_STREAM, 0)) == -1)
    {
        perror("Socket Creation Failed");
        exit(1);
    }
    int reuse_socket = 1;
    if (setsockopt(http_socket_fd,1,2,&reuse_socket,sizeof(int)) == -1)
    {
        perror("setsockopt");
        exit(1);
    }
    my_addr.sin_family = 2;
    my_addr.sin_port = htons(server_port);
    my_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    if (bind(http_socket_fd, (struct sockaddr *)&my_addr,
             sizeof(struct sockaddr)) == -1)
    {
        perror("Unable to Bind Socket");
        exit(1);
    }
    if (listen(http_socket_fd, 10) == -1)
    {
        perror("Unable to Listen on Socket");
        exit(1);
    }
    printf("Server is listening on port %d\n", server_port);
    while(1)
    {
        sin_size = sizeof(struct sockaddr_in);
        if ((connection_fd = accept(http_socket_fd, (struct sockaddr *)&their_addr,
                                    &sin_size)) == -1)
        {
            perror("Unable to accept connection");
            continue;
        }
        add_connection(connection_queue, connection_fd);
    }
    close(connection_fd);
    thread_index = 0;
    while (thread_index < 30)
    {
        if (pthread_join(thread_pool[thread_index], ((void *)0)))
        {
            printf("error joining consumer");
            abort();
        }
    }
    free(connection_queue);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct connection_queue { int connection_queue[100]; int first; union pthread_mutex_t queue_mutex; union sem_t slots_free; union sem_t slots_used; }

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

user_defined_types: union sem_t { char __size[32]; 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; }

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


decompiled_code:
int __fastcall setup_queue(__int64 a1)
{
int result; // eax

pthread_mutex_init((pthread_mutex_t *)(a1 + 408), 0LL);
sem_init((sem_t *)(a1 + 448), 0, 0x64u);
result = sem_init((sem_t *)(a1 + 480), 0, 0);
*(_DWORD *)(a1 + 400) = 0;
*(_DWORD *)(a1 + 404) = 99;
return result;
}

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

pthread_mutex_init((pthread_mutex_t *)(a1 + 408), 0LL);
sem_init((sem_t *)(a1 + 448), 0, 0x64u);
result = sem_init((sem_t *)(a1 + 480), 0, 0);
*(_DWORD *)(a1 + 400) = 0;
*(_DWORD *)(a1 + 404) = 99;
return result;
}

original_code:
void setup_queue(connection_queue_t *queue)
{
    pthread_mutex_init(&queue->queue_mutex, ((void *)0));
    sem_init(&queue->slots_free, 0, 100);
    sem_init(&queue->slots_used, 0, 0);
    queue->first = 0;
    queue->last = 100 -1;
}

canonical_original_code:
void setup_queue(struct connection_queue *queue)
{
    pthread_mutex_init(&queue->queue_mutex, ((void *)0));
    sem_init(&queue->slots_free, 0, 100);
    sem_init(&queue->slots_used, 0, 0);
    queue->first = 0;
    queue->last = 100 -1;
}

variable_types: struct connection_queue { int connection_queue[100]; int first; 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; } queue_mutex; union sem_t { char __size[32]; long __align; } slots_free; union sem_t slots_used; } *


decompiled_code:
int __fastcall add_connection(__int64 a1, int a2)
{
int v2; // eax

sem_wait((sem_t *)(a1 + 448));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 408));
v2 = (*(_DWORD *)(a1 + 404) + 1) % 100;
*(_DWORD *)(a1 + 404) = v2;
*(_DWORD *)(a1 + 4LL * v2) = a2;
sem_post((sem_t *)(a1 + 480));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 408));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
int v2; // eax

sem_wait((sem_t *)(a1 + 448));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 408));
v2 = (*(_DWORD *)(a1 + 404) + 1) % 100;
*(_DWORD *)(a1 + 404) = v2;
*(_DWORD *)(a1 + 4LL * v2) = a2;
sem_post((sem_t *)(a1 + 480));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 408));
}

original_code:
void add_connection(connection_queue_t *queue, int connection)
{
    sem_wait(&queue->slots_free);
    pthread_mutex_lock(&queue->queue_mutex);
    queue->last = ++queue->last % 100;
    queue->connection_queue[queue->last] = connection;
    sem_post(&queue->slots_used);
    pthread_mutex_unlock(&queue->queue_mutex);
}

canonical_original_code:
void add_connection(struct connection_queue *queue, int connection)
{
    sem_wait(&queue->slots_free);
    pthread_mutex_lock(&queue->queue_mutex);
    queue->last = ++queue->last % 100;
    queue->connection_queue[queue->last] = connection;
    sem_post(&queue->slots_used);
    pthread_mutex_unlock(&queue->queue_mutex);
}


decompiled_code:
__int64 __fastcall get_next_connection(__int64 a1)
{
int v1; // edx
unsigned int v2; // er12
int sval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

sem_getvalue((sem_t *)(a1 + 480), sval);
sem_wait((sem_t *)(a1 + 480));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 408));
v1 = *(_DWORD *)(a1 + 400);
v2 = *(_DWORD *)(a1 + 4LL * v1);
*(_DWORD *)(a1 + 400) = (v1 + 1) % 100;
sem_post((sem_t *)(a1 + 448));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 408));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // edx
unsigned int v2; // er12
int sval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

sem_getvalue((sem_t *)(a1 + 480), sval);
sem_wait((sem_t *)(a1 + 480));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 408));
v1 = *(_DWORD *)(a1 + 400);
v2 = *(_DWORD *)(a1 + 4LL * v1);
*(_DWORD *)(a1 + 400) = (v1 + 1) % 100;
sem_post((sem_t *)(a1 + 448));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 408));
return v2;
}

original_code:
int get_next_connection(connection_queue_t *queue)
{
    int cur_value;
    sem_getvalue(&queue->slots_used, &cur_value);
    sem_wait(&queue->slots_used);
    pthread_mutex_lock(&queue->queue_mutex);
    int next_connection = queue->connection_queue[queue->first];
    queue->first = ++queue->first % 100;
    sem_post(&queue->slots_free);
    pthread_mutex_unlock(&queue->queue_mutex);
    return next_connection;
}

canonical_original_code:
int get_next_connection(struct connection_queue *queue)
{
    int cur_value;
    sem_getvalue(&queue->slots_used, &cur_value);
    sem_wait(&queue->slots_used);
    pthread_mutex_lock(&queue->queue_mutex);
    int next_connection = queue->connection_queue[queue->first];
    queue->first = ++queue->first % 100;
    sem_post(&queue->slots_free);
    pthread_mutex_unlock(&queue->queue_mutex);
    return next_connection;
}


repo: RodrigoAcosta/Codigos

decompiled_code:
int __fastcall print_nomes(__int64 a1, int a2)
{
unsigned int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( *(_DWORD *)(a1 + 256) == 1 )
result = printf("Indice - %d - Nome - %s\n", i, (const char *)a1);
else
result = printf("Indice - %d - Nao Inicializado\n", i);
a1 += 264LL;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
unsigned int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( *(_DWORD *)(a1 + 256) == 1 )
result = printf("Indice - %d - Nome - %s\n", i, (const char *)a1);
else
result = printf("Indice - %d - Nao Inicializado\n", i);
a1 += 264LL;
}
}
return result;
}

original_code:
void print_nomes(const NOME_VERTICES nodo[],int tamanho){
   int i;
   for(i=0;i<(tamanho);i++){
      if(nodo[i].ini==1){
        printf("Indice - %d - Nome - %s\n",i,nodo[i].nome);
      }
      else{
     printf("Indice - %d - Nao Inicializado\n",i);
   }
   }
}

canonical_original_code:
void print_nomes(struct nome_vertices nodo[], int tamanho){
   int i;
   for(i=0;i<(tamanho);i++){
      if(nodo[i].ini==1){
        printf("Indice - %d - Nome - %s\n",i,nodo[i].nome);
      }
      else{
     printf("Indice - %d - Nao Inicializado\n",i);
   }
   }
}

variable_types: struct nome_vertices { char nome[255]; int ini; int del; } []

variable_types: tamanho int

variable_types: i int


original_code:
void init_nome(NOME_VERTICES nodo[],int tamanho){
   int i;
   for(i=0;i<(tamanho);i++){
       nodo[i].ini=0;
   }
}

canonical_original_code:
void init_nome(struct nome_vertices nodo[], int tamanho){
   int i;
   for(i=0;i<(tamanho);i++){
       nodo[i].ini=0;
   }
}

user_defined_types: struct nome_vertices { char nome[255]; int ini; int del; }


original_code:
void separa_string(char string[],int *v1,int *v2,int *peso){
 int i=0,j=0;
 char aux[255];
 int tamanho=0;
 tamanho=strlen(string);
 if(tamanho>=5){
   while(string[i]!=' '){
  aux[i]=string[i];
     i++;
   }
   aux[i]='\0';
   *v1=atoi(aux);
   i++;
   j=0;
   while(string[i]!=' '){
  aux[j]=string[i];
     i++;
     j++;
   }
   aux[j]='\0';
   *v2=atoi(aux);
   i++;
   j=0;
   while((string[i]!='\0')&&(string[i]!='\n')){
  aux[j]=string[i];
     i++;
     j++;
   }
   aux[j]='\0';
   *peso=atoi(aux);
 }
 else{
    *v1=-1;
    *v2=-1;
    *peso=-1;
 }
}

canonical_original_code:
void separa_string(char string[], int *v1, int *v2, int *peso){
 int i = 0; int j = 0;
 char aux[255];
 int tamanho = 0;
 tamanho=strlen(string);
 if(tamanho>=5){
   while(string[i]!=' '){
  aux[i]=string[i];
     i++;
   }
   aux[i]='\0';
   *v1=atoi(aux);
   i++;
   j=0;
   while(string[i]!=' '){
  aux[j]=string[i];
     i++;
     j++;
   }
   aux[j]='\0';
   *v2=atoi(aux);
   i++;
   j=0;
   while((string[i]!='\0')&&(string[i]!='\n')){
  aux[j]=string[i];
     i++;
     j++;
   }
   aux[j]='\0';
   *peso=atoi(aux);
 }
 else{
    *v1=-1;
    *v2=-1;
    *peso=-1;
 }
}

variable_types:
string
char []

variable_types:
peso
int *

variable_types: j int

variable_types:
aux
char [255]


validar

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

if ( a1 < 0 || a1 >= a2 )
return 0LL;
result = a3;
if ( a3 != 1 )
{
puts("Vertice nao inicializado, nao podera ser usado.");
result = 0LL;
}
return result;
}

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

if ( a1 < 0 || a1 >= a2 )
return 0LL;
result = a3;
if ( a3 != 1 )
{
puts("Vertice nao inicializado, nao podera ser usado.");
result = 0LL;
}
return result;
}

original_code:
int validar(int num,int n_vertices,const int nodo){
   if((num>=0)&&(num<n_vertices)){
     if(nodo!=1){
        printf("Vertice nao inicializado, nao podera ser usado.\n");
     }
     else{
    return 1;
  }
   }
   else{
   }
  return 0;
}

canonical_original_code:
int validar(int num, int n_vertices, int nodo){
   if((num>=0)&&(num<n_vertices)){
     if(nodo!=1){
        printf("Vertice nao inicializado, nao podera ser usado.\n");
     }
     else{
    return 1;
  }
   }
   else{
   }
  return 0;
}

variable_types: num int

variable_types: nodo int


decompiled_code:
__int64 __fastcall get_ID(int a1, char *a2, __int64 a3, int a4)
{
__int64 v5; // rsi
unsigned int v6; // ebx

if ( a1 < a4 && (v5 = a3 + 264LL * a1, v6 = *(_DWORD *)(v5 + 256), v6 == 1) )
{
strcpy(a2, (const char *)v5);
}
else
{
*a2 = 0;
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, char *a2, __int64 a3, int a4)
{
__int64 v5; // rsi
unsigned int v6; // ebx

if ( a1 < a4 && (v5 = a3 + 264LL * a1, v6 = *(_DWORD *)(v5 + 256), v6 == 1) )
{
strcpy(a2, (const char *)v5);
}
else
{
*a2 = 0;
v6 = 0;
}
return v6;
}

original_code:
int get_ID(int id,char nome[],const NOME_VERTICES nodo[],int tamanho){
  if(id<tamanho){
    if(nodo[id].ini==1){
      strcpy(nome,nodo[id].nome);
   return 1;
    }
  }
 nome[0]='\0';
 return 0;
}

canonical_original_code:
int get_ID(int id, char nome[], struct nome_vertices nodo[], int tamanho){
  if(id<tamanho){
    if(nodo[id].ini==1){
      strcpy(nome,nodo[id].nome);
   return 1;
    }
  }
 nome[0]='\0';
 return 0;
}

variable_types: id int

variable_types:
nome
char []


original_code:
int separa_id(char string[]){
   int i=0,j=0;
   int numero=-1;
   char aux[255];
   while((string[i]!=' ')&&(string[i]!='\0')){
      i++;
   }
   i++;
   while((string[i]!='\0')&&(string[i]!='\n')){
      aux[j]=string[i];
      j++;
      i++;
   }
   aux[j]='\0';
   numero=atoi(aux);
   return numero;
}

canonical_original_code:
int separa_id(char string[]){
   int i = 0; int j = 0;
   int numero = -1;
   char aux[255];
   while((string[i]!=' ')&&(string[i]!='\0')){
      i++;
   }
   i++;
   while((string[i]!='\0')&&(string[i]!='\n')){
      aux[j]=string[i];
      j++;
      i++;
   }
   aux[j]='\0';
   numero=atoi(aux);
   return numero;
}

variable_types: numero int


original_code:
void separa_id_id(char string[],int *id1,int *id2){
   int i=0,j=0;
   char aux[255];
   while((string[i]!=' ')&&(string[i]!='\0')){
      i++;
   }
   i++;
   while(string[i]!=' '){
      aux[j]=string[i];
      j++;
      i++;
   }
   aux[j]='\0';
   *id1=atoi(aux);
   j=0;
   i++;
   while((string[i]!='\n')&&(string[i]!='\0')){
      aux[j]=string[i];
      j++;
      i++;
   }
   aux[j]='\0';
   *id2=atoi(aux);
}

canonical_original_code:
void separa_id_id(char string[], int *id1, int *id2){
   int i = 0; int j = 0;
   char aux[255];
   while((string[i]!=' ')&&(string[i]!='\0')){
      i++;
   }
   i++;
   while(string[i]!=' '){
      aux[j]=string[i];
      j++;
      i++;
   }
   aux[j]='\0';
   *id1=atoi(aux);
   j=0;
   i++;
   while((string[i]!='\n')&&(string[i]!='\0')){
      aux[j]=string[i];
      j++;
      i++;
   }
   aux[j]='\0';
   *id2=atoi(aux);
}


original_code:
int delete_ID(int id,int tamanho,MATRIZ **nodo,NOME_VERTICES nodos[]){
   int i=0;
   if(id<tamanho){
    if(nodo[id][id].conexo==1){
     while(i<tamanho){
     nodo[id][i].conexo=0;
     nodo[id][i].peso=pow(2,-15);
     i++;
  }
  i=0;
  while(i<tamanho){
     nodo[i][id].conexo=0;
     nodo[i][id].peso=pow(2,-15);
     i++;
  }
  nodos[id].ini=0;
  nodos[id].nome[0]='\0';
  nodos[id].del=1;
  return 1;
    }
   }
   return 0;
}

canonical_original_code:
int delete_ID(int id, int tamanho, struct matriz **nodo, struct nome_vertices nodos[]){
   int i = 0;
   if(id<tamanho){
    if(nodo[id][id].conexo==1){
     while(i<tamanho){
     nodo[id][i].conexo=0;
     nodo[id][i].peso=pow(2,-15);
     i++;
  }
  i=0;
  while(i<tamanho){
     nodo[i][id].conexo=0;
     nodo[i][id].peso=pow(2,-15);
     i++;
  }
  nodos[id].ini=0;
  nodos[id].nome[0]='\0';
  nodos[id].del=1;
  return 1;
    }
   }
   return 0;
}

variable_types: struct matriz { int peso; int conexo; } **


original_code:
int vizinhos_ID(int id,int tamanho,MATRIZ **nodo,char string[]){
  int i=0;
  char buffer [255];
  string[0]='\0';
  if(id<tamanho){
 if(nodo[id][id].conexo==1){
     i=0;
     while(i<tamanho){
     if(nodo[id][i].conexo==1){
     snprintf(buffer, 10,"%d",i);
     strcat(string,buffer);
     strcat(string,",");
  }
  i++;
  }
  i=strlen(string);
  i--;
  string[i]='\0';
    return 1;
 }
  }
  return 0;
}

canonical_original_code:
int vizinhos_ID(int id, int tamanho, struct matriz **nodo, char string[]){
  int i = 0;
  char buffer[255];
  string[0]='\0';
  if(id<tamanho){
 if(nodo[id][id].conexo==1){
     i=0;
     while(i<tamanho){
     if(nodo[id][i].conexo==1){
     snprintf(buffer, 10,"%d",i);
     strcat(string,buffer);
     strcat(string,",");
  }
  i++;
  }
  i=strlen(string);
  i--;
  string[i]='\0';
    return 1;
 }
  }
  return 0;
}

variable_types:
buffer
char [255]


conexao

decompiled_code:
_BOOL8 __fastcall conexao(int a1, int a2, int a3, __int64 a4)
{
int v5; // edx
_BOOL8 result; // rax

v5 = a2;
if ( a1 >= a2 )
v5 = a1;
result = 0LL;
if ( a3 > v5 )
result = *(_DWORD *)(*(_QWORD *)(a4 + 8LL * a1) + 8LL * a2 + 4) == 1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(int a1, int a2, int a3, __int64 a4)
{
int v5; // edx
_BOOL8 result; // rax

v5 = a2;
if ( a1 >= a2 )
v5 = a1;
result = 0LL;
if ( a3 > v5 )
result = *(_DWORD *)(*(_QWORD *)(a4 + 8LL * a1) + 8LL * a2 + 4) == 1;
return result;
}

original_code:
int conexao(int id1,int id2,int tamanho,MATRIZ **nodo){
  if((id1<tamanho)&&(id2<tamanho)){
     if(nodo[id1][id2].conexo==1){
    return 1;
  }
  }
  return 0;
}

canonical_original_code:
int conexao(int id1, int id2, int tamanho, struct matriz **nodo){
  if((id1<tamanho)&&(id2<tamanho)){
     if(nodo[id1][id2].conexo==1){
    return 1;
  }
  }
  return 0;
}


adjacencia

original_code:
LISTA_ADJACENCIA* adjacencia(LISTA_ADJACENCIA *lista,MATRIZ **nodo,int tamanho){
 int i=0,j=0;
 for(i=0;i<tamanho;i++){
    lista[i].id=i;
 }
 for(j=0;j<tamanho;j++){
     for(i=0;i<tamanho;i++){
        if(i!=j){
          if(nodo[j][i].conexo==1){
   lista[i].id=i;
      lista[i].chegam+=1;
    }
         }
  }
    }
    return lista;
}

canonical_original_code:
struct lista_adjacencia *adjacencia(struct lista_adjacencia *lista, struct matriz **nodo, int tamanho){
 int i = 0; int j = 0;
 for(i=0;i<tamanho;i++){
    lista[i].id=i;
 }
 for(j=0;j<tamanho;j++){
     for(i=0;i<tamanho;i++){
        if(i!=j){
          if(nodo[j][i].conexo==1){
   lista[i].id=i;
      lista[i].chegam+=1;
    }
         }
  }
    }
    return lista;
}

variable_types:
lista
struct lista_adjacencia *

return_type: struct lista_adjacencia { int id; int chegam; } *


ordenar

original_code:
LISTA_ADJACENCIA* ordenar(LISTA_ADJACENCIA *lista,int tamanho){
  int i=0;
  int percorre=0,j=0;
  int aux_id=0,aux_chegam=0;
  while(percorre<tamanho){
     for(j=0;j<tamanho;j++){
       for(i=0;i<tamanho-1;i++){
       if((lista[i].chegam)>(lista[i+1].chegam)){
       aux_chegam=lista[i].chegam;
       aux_id=lista[i].id;
       lista[i].id=lista[i+1].id;
       lista[i].chegam=lista[i+1].chegam;
       lista[i+1].id=aux_id;
       lista[i+1].chegam=aux_chegam;
    }
    if((lista[i].chegam)==(lista[i+1].chegam)){
       if((lista[i].id)>(lista[i+1].id)){
         aux_chegam=lista[i].chegam;
         aux_id=lista[i].id;
         lista[i].id=lista[i+1].id;
         lista[i].chegam=lista[i+1].chegam;
         lista[i+1].id=aux_id;
         lista[i+1].chegam=aux_chegam;
       }
    }
    }
     }
     percorre++;
  }
 return lista;
}

canonical_original_code:
struct lista_adjacencia *ordenar(struct lista_adjacencia *lista, int tamanho){
  int i = 0;
  int percorre = 0; int j = 0;
  int aux_id = 0; int aux_chegam = 0;
  while(percorre<tamanho){
     for(j=0;j<tamanho;j++){
       for(i=0;i<tamanho-1;i++){
       if((lista[i].chegam)>(lista[i+1].chegam)){
       aux_chegam=lista[i].chegam;
       aux_id=lista[i].id;
       lista[i].id=lista[i+1].id;
       lista[i].chegam=lista[i+1].chegam;
       lista[i+1].id=aux_id;
       lista[i+1].chegam=aux_chegam;
    }
    if((lista[i].chegam)==(lista[i+1].chegam)){
       if((lista[i].id)>(lista[i+1].id)){
         aux_chegam=lista[i].chegam;
         aux_id=lista[i].id;
         lista[i].id=lista[i+1].id;
         lista[i].chegam=lista[i+1].chegam;
         lista[i+1].id=aux_id;
         lista[i+1].chegam=aux_chegam;
       }
    }
    }
     }
     percorre++;
  }
 return lista;
}

variable_types: percorre int

user_defined_types: struct lista_adjacencia { int id; int chegam; }


original_code:
int ordem_t(MATRIZ **nodo,LISTA_ADJACENCIA *lista,NOME_VERTICES *vet,char string[],int tamanho){
   int i=0,j=0;
   MATRIZ **copia_matriz;
   NOME_VERTICES *copia_nome;
   for(i=0;i<tamanho;i++){
   if(vet[i].ini==0){
     return 0;
   }
   }
   copia_matriz=malloc(tamanho*sizeof(MATRIZ));
   copia_nome=malloc(tamanho*sizeof(NOME_VERTICES));
   for(i=0;i<tamanho;i++){
     copia_matriz[i]=malloc(tamanho*sizeof(MATRIZ));
   }
   for(j=0;j<tamanho;j++){
     for(i=0;i<tamanho;i++){
     copia_matriz[j][i].conexo=nodo[j][i].conexo;
     copia_matriz[j][i].peso=nodo[j][i].peso;
  }
   }
   for(i=0;i<tamanho;i++){
     strcpy(copia_nome[i].nome,vet[i].nome);
     copia_nome[i].ini=vet[i].ini;
   }
   return 0;
}

canonical_original_code:
int ordem_t(struct matriz **nodo, struct lista_adjacencia *lista, struct nome_vertices *vet, char string[], int tamanho){
   int i = 0; int j = 0;
   struct matriz **copia_matriz;
   struct nome_vertices *copia_nome;
   for(i=0;i<tamanho;i++){
   if(vet[i].ini==0){
     return 0;
   }
   }
   copia_matriz=malloc(tamanho*sizeof(MATRIZ));
   copia_nome=malloc(tamanho*sizeof(NOME_VERTICES));
   for(i=0;i<tamanho;i++){
     copia_matriz[i]=malloc(tamanho*sizeof(MATRIZ));
   }
   for(j=0;j<tamanho;j++){
     for(i=0;i<tamanho;i++){
     copia_matriz[j][i].conexo=nodo[j][i].conexo;
     copia_matriz[j][i].peso=nodo[j][i].peso;
  }
   }
   for(i=0;i<tamanho;i++){
     strcpy(copia_nome[i].nome,vet[i].nome);
     copia_nome[i].ini=vet[i].ini;
   }
   return 0;
}

variable_types: struct lista_adjacencia { int id; int chegam; } *

variable_types: struct nome_vertices { char nome[255]; int ini; int del; } *


arvoreminima

original_code:
int arvoreminima(MATRIZ **nodo,NOME_VERTICES *vet,char string[],int tamanho,int custo){
   int i=0,j=0,vezes;
   int menor_peso;
   int de=0,para=0;
   int ja_add=0;
   PESOS *lista_pesos;
   PESOS *topo;
   PESOS *aux;
   topo=malloc(sizeof(PESOS));
   aux=malloc(sizeof(PESOS));
   lista_pesos=((void *)0);
   aux=((void *)0);
   for(j=0;j<tamanho;j++){
     for(i=0;i<tamanho;i++){
        if(nodo[j][i].conexo==1){
       menor_peso=nodo[j][i].peso;
       i=tamanho;
       j=tamanho;
  }
     }
   }
   for(vezes=0;vezes<(tamanho*tamanho);vezes++){
     for(j=0;j<tamanho;j++){
       for(i=0;i<tamanho;i++){
       if(nodo[j][i].conexo==1){
      if(nodo[j][i].peso<=menor_peso){
      printf("entrou.\n");
      ja_add=0;
      while((aux!=((void *)0))&&(ja_add!=1)){
        aux=topo;
        if((aux->de==j)&&(aux->para==1)){
                    ja_add=1;
     }
     else{
        aux=aux->prox;
     }
      }
      printf("passou por aqui.\n");
      if(ja_add==0){
        printf("alguem inserido.\n");
        menor_peso=nodo[j][i].peso;
        de=j;
        para=i;
      }
    }
    }
     }
      }
      if(lista_pesos==((void *)0)){
      aux->peso=menor_peso;
         aux->de=de;
         aux->para=para;
         aux->prox=((void *)0);
         lista_pesos=aux;
         if(vezes==0){
           topo=lista_pesos;
      }
       }
       else{
      aux->peso=menor_peso;
         aux->de=de;
         aux->para=para;
         aux->prox=((void *)0);
         lista_pesos->prox=aux;
       }
     }
   printf("saiu.\n");
   aux=topo;
   while(aux!=((void *)0)){
      printf("aresta - [%d][%d] - peso - %d\n",aux->de,aux->para,aux->peso);
      aux=aux->prox;
   }
  return 0;
}

canonical_original_code:
int arvoreminima(struct matriz **nodo, struct nome_vertices *vet, char string[], int tamanho, int custo){
   int i = 0; int j = 0; int vezes;
   int menor_peso;
   int de = 0; int para = 0;
   int ja_add = 0;
   struct pesos *lista_pesos;
   struct pesos *topo;
   struct pesos *aux;
   topo=malloc(sizeof(PESOS));
   aux=malloc(sizeof(PESOS));
   lista_pesos=((void *)0);
   aux=((void *)0);
   for(j=0;j<tamanho;j++){
     for(i=0;i<tamanho;i++){
        if(nodo[j][i].conexo==1){
       menor_peso=nodo[j][i].peso;
       i=tamanho;
       j=tamanho;
  }
     }
   }
   for(vezes=0;vezes<(tamanho*tamanho);vezes++){
     for(j=0;j<tamanho;j++){
       for(i=0;i<tamanho;i++){
       if(nodo[j][i].conexo==1){
      if(nodo[j][i].peso<=menor_peso){
      printf("entrou.\n");
      ja_add=0;
      while((aux!=((void *)0))&&(ja_add!=1)){
        aux=topo;
        if((aux->de==j)&&(aux->para==1)){
                    ja_add=1;
     }
     else{
        aux=aux->prox;
     }
      }
      printf("passou por aqui.\n");
      if(ja_add==0){
        printf("alguem inserido.\n");
        menor_peso=nodo[j][i].peso;
        de=j;
        para=i;
      }
    }
    }
     }
      }
      if(lista_pesos==((void *)0)){
      aux->peso=menor_peso;
         aux->de=de;
         aux->para=para;
         aux->prox=((void *)0);
         lista_pesos=aux;
         if(vezes==0){
           topo=lista_pesos;
      }
       }
       else{
      aux->peso=menor_peso;
         aux->de=de;
         aux->para=para;
         aux->prox=((void *)0);
         lista_pesos->prox=aux;
       }
     }
   printf("saiu.\n");
   aux=topo;
   while(aux!=((void *)0)){
      printf("aresta - [%d][%d] - peso - %d\n",aux->de,aux->para,aux->peso);
      aux=aux->prox;
   }
  return 0;
}

variable_types: tamanho int

variable_types: custo int

variable_types: vezes int

variable_types: de int

variable_types: para int

variable_types: struct pesos { int peso; int de; int para; struct pesos *prox; } *