decompiled_code:
void __fastcall parse_args(int a1, __int64 a2)
{
int v3; // er12
_BYTE *v4; // rdx
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
char v10; // al
char v11; // al
int v12; // [rsp+4h] [rbp-24h] BYREF
__int64 v13[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 > 1 )
{
v3 = a1;
while ( 2 )
{
v4 = *(_BYTE **)(a2 + 8);
if ( *v4 != 45 )
goto LABEL_9;
v5 = v4[1];
if ( v5 != 45 )
{
if ( v5 && !v4[2] )
{
a2 += 16LL;
switch ( v5 )
{
case 'b':
v11 = string_to_double(*(char **)a2, (double *)v13);
my_assert(v11, "Parsen der Argumente fehlgeschlagen.\nWert von -b muss vom Typ double sein.\n");
bottom = v13[0];
goto LABEL_11;
case 'i':
v10 = string_to_int(*(char **)a2, &v12);
my_assert(v10, "Parsen der Argumente fehlgeschlagen.\nWert von -i muss vom Typ int sein.\n");
n = v12;
my_assert(v12 > 0, aNMussGr);
goto LABEL_11;
case 'l':
v9 = string_to_double(*(char **)a2, (double *)v13);
my_assert(v9, "Parsen der Argumente fehlgeschlagen.\nWert von -l muss vom Typ double sein.\n");
left = v13[0];
goto LABEL_11;
case 'p':
v8 = string_to_int(*(char **)a2, &v12);
my_assert(v8, "Parsen der Argumente fehlgeschlagen.\nWert von -p muss vom Typ int sein.\n");
*(double *)&pixel = (double)v12;
goto LABEL_11;
case 'r':
v7 = string_to_double(*(char **)a2, (double *)v13);
my_assert(v7, "Parsen der Argumente fehlgeschlagen.\nWert von -r muss vom Typ double sein.\n");
right = v13[0];
goto LABEL_11;
case 't':
v6 = string_to_double(*(char **)a2, (double *)v13);
my_assert(v6, "Parsen der Argumente fehlgeschlagen.\nWert von -t muss vom Typ double sein.\n");
top = v13[0];
LABEL_11:
v3 -= 2;
if ( v3 == (a1 & 1) )
goto LABEL_12;
continue;
default:
break;
}
}
LABEL_9:
print_usage();
exit(1);
}
break;
}
if ( v4[2] )
goto LABEL_9;
a2 += 16LL;
if ( v3 > 2 )
goto LABEL_9;
}
LABEL_12:
if ( *(_QWORD *)(a2 + 8) )
goto LABEL_9;
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; // er12
_BYTE *v4; // rdx
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
char v10; // al
char v11; // al
int v12; // [rsp+4h] [rbp-24h] BYREF
__int64 v13[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 > 1 )
{
v3 = a1;
while ( 2 )
{
v4 = *(_BYTE **)(a2 + 8);
if ( *v4 != 45 )
goto LABEL_9;
v5 = v4[1];
if ( v5 != 45 )
{
if ( v5 && !v4[2] )
{
a2 += 16LL;
switch ( v5 )
{
case 'b':
v11 = func13(*(char **)a2, (double *)v13);
func10(v11, "Parsen der Argumente fehlgeschlagen.\nWert von -b muss vom Typ double sein.\n");
bottom = v13[0];
goto LABEL_11;
case 'i':
v10 = func12(*(char **)a2, &v12);
func10(v10, "Parsen der Argumente fehlgeschlagen.\nWert von -i muss vom Typ int sein.\n");
n = v12;
func10(v12 > 0, aNMussGr);
goto LABEL_11;
case 'l':
v9 = func13(*(char **)a2, (double *)v13);
func10(v9, "Parsen der Argumente fehlgeschlagen.\nWert von -l muss vom Typ double sein.\n");
left = v13[0];
goto LABEL_11;
case 'p':
v8 = func12(*(char **)a2, &v12);
func10(v8, "Parsen der Argumente fehlgeschlagen.\nWert von -p muss vom Typ int sein.\n");
*(double *)&pixel = (double)v12;
goto LABEL_11;
case 'r':
v7 = func13(*(char **)a2, (double *)v13);
func10(v7, "Parsen der Argumente fehlgeschlagen.\nWert von -r muss vom Typ double sein.\n");
right = v13[0];
goto LABEL_11;
case 't':
v6 = func13(*(char **)a2, (double *)v13);
func10(v6, "Parsen der Argumente fehlgeschlagen.\nWert von -t muss vom Typ double sein.\n");
top = v13[0];
LABEL_11:
v3 -= 2;
if ( v3 == (a1 & 1) )
goto LABEL_12;
continue;
default:
break;
}
}
LABEL_9:
func7();
exit(1);
}
break;
}
if ( v4[2] )
goto LABEL_9;
a2 += 16LL;
if ( v3 > 2 )
goto LABEL_9;
}
LABEL_12:
if ( *(_QWORD *)(a2 + 8) )
goto LABEL_9;
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 **


repo: Robotregent/system-soft

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

return_type: int


decompiled_code:
bool __fastcall copy_file(const char *a1, char *a2)
{
bool result; // al
struct stat v3; // [rsp-18h] [rbp-A8h] BYREF

result = a2 != 0LL && a1 != 0LL;
if ( result )
{
lstat(a1, &v3);
if ( (unsigned __int8)copy_file_content(a1, a2)
&& copy_time_stamp_isra_0(a2, v3.st_atim.tv_sec, v3.st_atim.tv_nsec, v3.st_mtim.tv_sec, v3.st_mtim.tv_nsec) )
{
result = copy_permissions_isra_0(a2, v3.st_mode);
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func3(const char *a1, char *a2)
{
bool result; // al
struct stat v3; // [rsp-18h] [rbp-A8h] BYREF

result = a2 != 0LL && a1 != 0LL;
if ( result )
{
lstat(a1, &v3);
if ( (unsigned __int8)func0(a1, a2)
&& func2(a2, v3.st_atim.tv_sec, v3.st_atim.tv_nsec, v3.st_mtim.tv_sec, v3.st_mtim.tv_nsec) )
{
result = func1(a2, v3.st_mode);
}
else
{
result = 0;
}
}
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:
int __fastcall printped(__int64 a1, __int64 a2)
{
__int64 v3; // rbp
int v4; // er13
int v5; // ebx
int result; // eax

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

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v3; // rbp
int v4; // er13
int v5; // ebx
int result; // eax

if ( a1 )
{
v3 = a1;
do
{
v4 = a2++;
v5 = v4;
func10(*(_QWORD *)(v3 + 16), a2);
if ( v4 > 0 )
{
do
{
printf(" ");
--v5;
}
while ( v5 );
}
result = puts(*(const char **)v3);
v3 = *(_QWORD *)(v3 + 8);
}
while ( v3 );
}
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

variable_types: i int

return_type: void

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


print

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

canonical_decompiled_code:
int __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)
{
int v1; // edx
int v2; // eax
_BOOL4 v3; // er8

v1 = (unsigned __int8)a1->d_name[0] - 46;
if ( a1->d_name[0] == 46 )
v1 = (unsigned __int8)a1->d_name[1];
v2 = (unsigned __int8)a1->d_name[0] - 46;
if ( a1->d_name[0] == 46 )
{
v2 = (unsigned __int8)a1->d_name[1] - 46;
if ( a1->d_name[1] == 46 )
v2 = (unsigned __int8)a1->d_name[2];
}
v3 = 0;
if ( ((a1->d_type - 4) & 0xFB) == 0 )
v3 = v1 != 0 && v2 != 0;
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const struct dirent *a1)
{
int v1; // edx
int v2; // eax
_BOOL4 v3; // er8

v1 = (unsigned __int8)a1->d_name[0] - 46;
if ( a1->d_name[0] == 46 )
v1 = (unsigned __int8)a1->d_name[1];
v2 = (unsigned __int8)a1->d_name[0] - 46;
if ( a1->d_name[0] == 46 )
{
v2 = (unsigned __int8)a1->d_name[1] - 46;
if ( a1->d_name[1] == 46 )
v2 = (unsigned __int8)a1->d_name[2];
}
v3 = 0;
if ( ((a1->d_type - 4) & 0xFB) == 0 )
v3 = v1 != 0 && v2 != 0;
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; // er15
int v5; // er13
char *v6; // rbp
char *v7; // r12
int v8; // eax
const char *v9; // rax
char *v10; // r12
int *v11; // rax
char *v12; // rax
int v13; // [rsp+4h] [rbp-194h]
char *v14; // [rsp+8h] [rbp-190h]
int v15; // [rsp+18h] [rbp-180h]
__int64 v17; // [rsp+20h] [rbp-178h]
struct dirent **namelist; // [rsp+30h] [rbp-168h] BYREF
struct dirent **v20; // [rsp+38h] [rbp-160h] BYREF
struct stat buf; // [rsp+40h] [rbp-158h] BYREF
struct stat v22; // [rsp+D0h] [rbp-C8h] BYREF

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

canonical_decompiled_code:
void __fastcall func1(const char *a1, const char *a2, int a3, unsigned __int8 a4)
{
int v4; // er15
int v5; // er13
char *v6; // rbp
char *v7; // r12
int v8; // eax
const char *v9; // rax
char *v10; // r12
int *v11; // rax
char *v12; // rax
int v13; // [rsp+4h] [rbp-194h]
char *v14; // [rsp+8h] [rbp-190h]
int v15; // [rsp+18h] [rbp-180h]
__int64 v17; // [rsp+20h] [rbp-178h]
struct dirent **namelist; // [rsp+30h] [rbp-168h] BYREF
struct dirent **v20; // [rsp+38h] [rbp-160h] BYREF
struct stat buf; // [rsp+40h] [rbp-158h] BYREF
struct stat v22; // [rsp+D0h] [rbp-C8h] BYREF

namelist = 0LL;
v20 = 0LL;
v13 = scandir(
a1,
&namelist,
(int (*)(const struct dirent *))dir_filter,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v13 < 0 )
{
a2 = a1;
goto LABEL_37;
}
v15 = scandir(
a2,
&v20,
(int (*)(const struct dirent *))dir_filter,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v15 < 0 )
{
LABEL_37:
printf("Try to open %s, but:\n", a2);
v11 = _errno_location();
v12 = strerror(*v11);
printf("ERROR: %s\n", v12);
exit(2);
}
if ( v13 )
{
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = (char *)create_path(a1, namelist[v5]->d_name);
lstat(v6, &buf);
if ( v15 <= v4 )
break;
v17 = v4;
v14 = v20[v4]->d_name;
v7 = namelist[v5]->d_name;
v8 = strcmp(v7, v14);
if ( v8 < 0 )
goto LABEL_16;
++v4;
if ( !v8 )
{
v10 = (char *)create_path(a2, v14);
if ( (buf.st_mode & 0xF000) == 0x4000 )
{
if ( a3 > 1 )
{
func1(v6, v10, (unsigned int)(a3 - 1), a4);
}
else if ( a4 )
{
puts("Reached recursion limit");
}
}
else
{
lstat(v10, &v22);
if ( v22.st_mtim.tv_sec < buf.st_mtim.tv_sec )
{
copy_file(v6, v10);
if ( a4 )
printf("Update\t%s\t->\t%s\n", v6, v10);
}
}
free(namelist[v5]);
free(v20[v17]);
goto LABEL_22;
}
free(v6);
LABEL_9:
if ( v13 <= v5 )
goto LABEL_10;
}
v7 = namelist[v5]->d_name;
LABEL_16:
v9 = (const char *)create_path(a2, v7);
v10 = (char *)v9;
if ( (buf.st_mode & 0xF000) == 0x8000 )
{
copy_file(v6, v9);
if ( a4 )
printf("Copy\t%s\t->\t%s\n", v6, v10);
}
else if ( !mkdir(v9, buf.st_mode) )
{
if ( a3 > 1 )
{
func1(v6, v10, (unsigned int)(a3 - 1), a4);
}
else if ( a4 )
{
puts("Reached recursion limit");
}
}
free(namelist[v5]);
LABEL_22:
++v5;
free(v6);
if ( v10 )
free(v10);
goto LABEL_9;
}
LABEL_10:
if ( v20 )
free(v20);
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
char s[7]; // [rsp+1h] [rbp-2Fh] BYREF
__int128 v3; // [rsp+8h] [rbp-28h] BYREF
int v4; // [rsp+18h] [rbp-18h]

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

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 result; // rax
char s[7]; // [rsp+1h] [rbp-2Fh] BYREF
__int128 v3; // [rsp+8h] [rbp-28h] BYREF
int v4; // [rsp+18h] [rbp-18h]

v3 = 0LL;
v4 = 0;
sprintf(s, "%d", a1);
func10(a1, &v3);
result = func11(s);
if ( (_DWORD)result )
result = (unsigned int)func11(&v3) != 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; // edx
int v3; // edx

LOBYTE(v2) = a1;
if ( a1 > 0 )
{
do
{
*a2++ = digitToChar(v2 & 1);
v2 = v3 >> 1;
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func10(int a1, _BYTE *a2)
{
int v2; // edx
int v3; // edx

LOBYTE(v2) = a1;
if ( a1 > 0 )
{
do
{
*a2++ = func9(v2 & 1);
v2 = v3 >> 1;
}
while ( v2 );
}
}

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 []


isPalindrome

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

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

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

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

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; // er12
unsigned int v4; // ebp
unsigned int i; // ebx

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

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

v3 = 0;
v4 = 0;
for ( i = 0; i != 1000000; ++i )
{
if ( (unsigned int)func7(i, argv, envp) )
{
v3 += i;
++v4;
}
}
printf("Total both base palindromes below 1000000 is %d and the sum is %d \n", v4, v3);
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: i 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)
{
char *v3; // rbx
unsigned int v4; // ebp
__int16 v5; // ax
socklen_t v6; // edx
unsigned int v7; // eax
socklen_t addr_len; // [rsp+8h] [rbp-40h] BYREF
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr newthread; // [rsp+20h] [rbp-28h] BYREF

if ( argc > 1 )
{
v3 = (char *)&thread_pool;
v4 = atoi(argv[1]);
_sysv_signal(2, (__sighandler_t)sigint_handler);
connection_queue = (__int64)malloc(0x200uLL);
setup_queue(connection_queue);
while ( !pthread_create((pthread_t *)&newthread.sa_family, 0LL, (void *(*)(void *))connection_consumer, 0LL) )
{
v3 += 8;
*((_QWORD *)v3 - 1) = *(_QWORD *)&newthread.sa_family;
if ( v3 == (char *)&thread_pool + 240 )
{
http_socket_fd = socket(2, 1, 0);
if ( http_socket_fd != -1 )
{
optval = 1;
if ( setsockopt(http_socket_fd, 1, 2, &optval, 4u) != -1 )
{
newthread.sa_family = 2;
v5 = _bswap_16(v4);
*(_DWORD *)&newthread.sa_data[2] = 0;
*(_WORD *)newthread.sa_data = v5;
if ( bind(http_socket_fd, &newthread, v6) != -1 )
{
if ( listen(http_socket_fd, 10) == -1 )
{
perror("Unable to Listen on Socket");
exit(1);
}
printf("Server is listening on port %d\n", v4);
while ( 1 )
{
addr_len = 16;
v7 = accept(http_socket_fd, &addr, &addr_len);
if ( v7 == -1 )
perror("Unable to accept connection");
else
add_connection(connection_queue, v7);
}
}
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)
{
char *v3; // rbx
unsigned int v4; // ebp
__int16 v5; // ax
socklen_t v6; // edx
unsigned int v7; // eax
socklen_t addr_len; // [rsp+8h] [rbp-40h] BYREF
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr newthread; // [rsp+20h] [rbp-28h] BYREF

if ( argc > 1 )
{
v3 = (char *)&thread_pool;
v4 = atoi(argv[1]);
_sysv_signal(2, (__sighandler_t)sigint_handler);
connection_queue = (__int64)malloc(0x200uLL);
setup_queue(connection_queue);
while ( !pthread_create((pthread_t *)&newthread.sa_family, 0LL, (void *(*)(void *))connection_consumer, 0LL) )
{
v3 += 8;
*((_QWORD *)v3 - 1) = *(_QWORD *)&newthread.sa_family;
if ( v3 == (char *)&thread_pool + 240 )
{
http_socket_fd = socket(2, 1, 0);
if ( http_socket_fd != -1 )
{
optval = 1;
if ( setsockopt(http_socket_fd, 1, 2, &optval, 4u) != -1 )
{
newthread.sa_family = 2;
v5 = func1(v4);
*(_DWORD *)&newthread.sa_data[2] = 0;
*(_WORD *)newthread.sa_data = v5;
if ( bind(http_socket_fd, &newthread, v6) != -1 )
{
if ( listen(http_socket_fd, 10) == -1 )
{
perror("Unable to Listen on Socket");
exit(1);
}
printf("Server is listening on port %d\n", v4);
while ( 1 )
{
addr_len = 16;
v7 = accept(http_socket_fd, &addr, &addr_len);
if ( v7 == -1 )
perror("Unable to accept connection");
else
add_connection(connection_queue, v7);
}
}
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:
__int64 __fastcall setup_queue(__int64 a1)
{
__int64 result; // rax

pthread_mutex_init((pthread_mutex_t *)(a1 + 408), 0LL);
sem_init((sem_t *)(a1 + 448), 0, 0x64u);
sem_init((sem_t *)(a1 + 480), 0, 0);
result = 0x6300000000LL;
*(_QWORD *)(a1 + 400) = 0x6300000000LL;
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)
{
unsigned int v1; // 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 + 4LL * *(int *)(a1 + 400));
*(_DWORD *)(a1 + 400) = (*(_DWORD *)(a1 + 400) + 1) % 100;
sem_post((sem_t *)(a1 + 448));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 408));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // 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 + 4LL * *(int *)(a1 + 400));
*(_DWORD *)(a1 + 400) = (*(_DWORD *)(a1 + 400) + 1) % 100;
sem_post((sem_t *)(a1 + 448));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 408));
return v1;
}

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
__int64 v5; // rsi
int result; // eax

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

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

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


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, int a3)
{
__int64 result; // rax

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

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

if ( a1 < 0 || a1 >= a2 )
return 0LL;
result = 1LL;
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; // er12

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 func4(int a1, char *a2, __int64 a3, int a4)
{
__int64 v5; // rsi
unsigned int v6; // er12

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: i int

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 func9(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

decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall arvoreminima(__int64 *a1, __int64 a2, __int64 a3, unsigned int a4)
{
int v4; // er14
__int64 *v5; // r13
__int64 v6; // rbx
unsigned int *v7; // rax
int v8; // esi
int v9; // eax
int *v10; // rdx
__int64 v11; // rbp
__int64 v12; // r12
__int64 v13; // rdx
__int64 v14; // rbx
unsigned int *v15; // rbp

v5 = a1;
v6 = a4;
v7 = (unsigned int *)malloc(0x18uLL);
v8 = 0;
if ( (int)v6 > 0 )
{
do
{
v9 = 0;
do
{
v10 = (int *)(a1[v8] + 8LL * v9);
if ( v10[1] == 1 )
{
v4 = *v10;
v8 = v6;
v9 = v6;
}
++v9;
}
while ( (int)v6 > v9 );
++v8;
}
while ( (int)v6 > v8 );
v11 = 8 * v6;
v12 = (__int64)&a1[(unsigned int)(v6 - 1) + 1];
do
{
v13 = *v5;
v14 = 0LL;
do
{
while ( *(_DWORD *)(v13 + v14 + 4) != 1 || *(_DWORD *)(v13 + v14) > v4 )
{
v14 += 8LL;
if ( v11 == v14 )
goto LABEL_13;
}
puts("entrou.");
puts("passou por aqui.");
puts("alguem inserido.");
v13 = *v5;
v4 = *(_DWORD *)(*v5 + v14);
v14 += 8LL;
}
while ( v11 != v14 );
LABEL_13:
++v5;
}
while ( (__int64 *)v12 != v5 );
LABEL_14:
*(_DWORD *)cabecalho = 0;
BUG();
}
v15 = v7;
if ( (_DWORD)v6 * (_DWORD)v6 )
goto LABEL_14;
puts("saiu.");
for ( ; v15; v15 = (unsigned int *)*((_QWORD *)v15 + 2) )
printf("aresta - [%d][%d] - peso - %d\n", v15[1], v15[2], *v15);
return 0LL;
}

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // r13
char *v4; // r14
int v5; // ebx
const char *v6; // rdx
int v7; // eax
_DWORD *v8; // rdi
__int64 v9; // rsi
unsigned __int64 v10; // rcx
_DWORD *v11; // r8
__int64 v12; // rax
__int64 v13; // rdx
unsigned __int64 v14; // rax
char *v15; // r15
int v16; // ebx
char *v17; // rsi
int v18; // ebx
int v19; // eax
int *v20; // rax
int v21; // edx
char *v22; // r15
int v23; // ebx
char *v24; // rsi
__int64 v25; // r15
__int64 v26; // r15
__int64 v27; // r15
int v28; // eax
int v29; // eax
char *v30; // r15
int v31; // ebx
char *v32; // rsi
signed int v33; // ebx
bool v34; // zf
int v35; // eax
char v36; // dl
int v37; // er8
__int64 v38; // rax
int v39; // ecx
int v40; // er15
int v41; // eax
__int64 v42; // r8
char *v43; // rax
__int64 v44; // rbx
int v45; // er12
size_t v46; // rbx
char *v47; // rax
char *v48; // r15
char *v49; // r12
__int64 v50; // rsi
__int64 *v51; // rcx
__int64 *v52; // r8
__int64 v53; // rax
__int64 v54; // rdx
_DWORD *v55; // rdx
__int64 v56; // rax
char *v57; // r15
int v58; // ebx
char *v59; // rsi
int v60; // ebx
int v61; // eax
__int64 v62; // rax
int *v63; // rsi
__int64 v64; // rcx
int v65; // edx
int *v66; // rax
const char *v68; // [rsp+8h] [rbp-470h]
int v69; // [rsp+8h] [rbp-470h]
void *v70; // [rsp+18h] [rbp-460h]
int v71; // [rsp+20h] [rbp-458h]
char v72; // [rsp+28h] [rbp-450h]
int v73; // [rsp+28h] [rbp-450h]
unsigned int v74; // [rsp+28h] [rbp-450h]
int v75; // [rsp+2Ch] [rbp-44Ch]
unsigned int v76; // [rsp+30h] [rbp-448h] BYREF
unsigned int v77; // [rsp+34h] [rbp-444h] BYREF
unsigned int v78; // [rsp+38h] [rbp-440h] BYREF
int v79; // [rsp+3Ch] [rbp-43Ch] BYREF
char dest[256]; // [rsp+40h] [rbp-438h] BYREF
char nptr[256]; // [rsp+140h] [rbp-338h] BYREF
char s1[8]; // [rsp+240h] [rbp-238h] BYREF
__int16 v83; // [rsp+248h] [rbp-230h]
char v84; // [rsp+33Fh] [rbp-139h]
char v85[312]; // [rsp+340h] [rbp-138h] BYREF

v5 = 0;
v76 = 0;
v77 = 0;
v78 = 0;
v79 = 0;
v75 = 0;
while ( 1 )
{
_isoc99_scanf("%s", s1);
if ( *(_WORD *)s1 == 64 )
goto LABEL_91;
if ( *(_QWORD *)s1 == 0x656369747265562ALL && v83 == 115 )
{
LABEL_31:
_isoc99_scanf("%d", &v76);
if ( v5 == 1 )
{
if ( *(_DWORD *)s1 != 1734624554 || *(_WORD *)&s1[4] != 29541 || s1[6] )
{
if ( !strcmp(s1, "*Arcs") )
goto LABEL_37;
if ( strcmp(s1, "*Queries") )
{
v75 = -2;
goto LABEL_95;
}
goto LABEL_90;
}
goto LABEL_35;
}
while ( 1 )
{
v44 = (int)v76;
v4 = (char *)malloc(264LL * (int)v76);
v70 = malloc(8 * v44);
init_nome(v4, (unsigned int)v44);
v45 = v76;
v46 = 8LL * (int)v76;
v47 = (char *)malloc(v46);
v3 = (__int64 *)v47;
if ( v45 > 0 )
{
v48 = v47;
v49 = &v47[8 * v45];
do
{
v48 += 8;
*((_QWORD *)v48 - 1) = malloc(v46);
}
while ( v48 != v49 );
}
if ( strcmp(s1, "*Edges") )
break;
LABEL_148:
v6 = "*Arcs";
while ( 1 )
{
LABEL_18:
if ( !memcmp(s1, v6, 6uLL) )
goto LABEL_19;
v68 = v6;
if ( !strcmp(s1, "*Queries") )
goto LABEL_183;
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( !strcmp(s1, "@") )
goto LABEL_91;
if ( !strcmp(s1, "*Vertices") )
goto LABEL_143;
v28 = strcmp(s1, "*Edges");
v6 = v68;
if ( v28 )
{
if ( !strcmp(s1, "*Arcs") )
goto LABEL_19;
if ( !strcmp(s1, "*Queries") )
goto LABEL_183;
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( !strcmp(s1, "@") )
goto LABEL_91;
v5 = strcmp(s1, "*Vertices");
if ( !v5 )
goto LABEL_31;
v29 = strcmp(s1, "*Edges");
v6 = v68;
if ( v29 )
break;
}
}
if ( strcmp(s1, "*Arcs") )
{
LABEL_106:
if ( strcmp(s1, "*Queries") )
{
v75 = -1;
v5 = 0;
goto LABEL_95;
}
LABEL_183:
v5 = 0;
goto LABEL_90;
}
while ( 1 )
{
LABEL_19:
if ( !strcmp(s1, "*Queries") )
goto LABEL_183;
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( !strcmp(s1, "@") )
goto LABEL_91;
if ( !strcmp(s1, "*Vertices") )
break;
if ( !strcmp(s1, "*Edges") )
goto LABEL_148;
if ( strcmp(s1, "*Arcs") )
{
if ( !strcmp(s1, "*Queries") )
goto LABEL_183;
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( !strcmp(s1, "@") )
goto LABEL_91;
v5 = strcmp(s1, "*Vertices");
if ( !v5 )
goto LABEL_31;
if ( !strcmp(s1, "*Edges") )
goto LABEL_148;
if ( strcmp(s1, "*Arcs") )
goto LABEL_106;
}
}
LABEL_143:
_isoc99_scanf("%d", &v76);
}
v75 = 1;
v5 = 0;
}
else if ( *(_DWORD *)s1 == 1734624554 && *(_WORD *)&s1[4] == 29541 && !s1[6] )
{
LABEL_17:
v6 = "*Arcs";
if ( !v5 )
goto LABEL_18;
LABEL_35:
v7 = strcmp(s1, "*Arcs") != 0;
goto LABEL_36;
}
if ( *(_DWORD *)s1 == 1668432170 && *(_WORD *)&s1[4] == 115 )
{
LABEL_125:
if ( !v5 )
goto LABEL_19;
LABEL_37:
v5 = 1;
if ( !strcmp(s1, "*Queries") )
goto LABEL_90;
LABEL_38:
if ( (int)v76 > 0 )
{
v8 = v4 + 256;
v9 = 8LL * v76;
v10 = 0LL;
v11 = v4 + 256;
do
{
v12 = v3[v10 / 8];
if ( *v11 == 1 )
*(_DWORD *)(v12 + v10 + 4) = 1;
v13 = v12 + v9;
do
{
*(_DWORD *)(v12 + 4) = 0;
v12 += 8LL;
*(_DWORD *)(v12 - 8) = 0;
}
while ( v12 != v13 );
v10 += 8LL;
v11 += 66;
}
while ( v10 != v9 );
v14 = 0LL;
do
{
if ( *v8 == 1 )
*(_DWORD *)(v3[v14 / 8] + v14 + 4) = 1;
v14 += 8LL;
v8 += 66;
}
while ( v14 != v9 );
}
while ( 1 )
{
v15 = v85;
v16 = -1;
do
{
v17 = v15++;
_isoc99_scanf("%c", v17);
++v16;
}
while ( *(v15 - 1) != 10 );
v85[v16] = 0;
if ( v85[0] == 42 )
{
if ( !strcmp(v85, "*Queries") )
{
LABEL_58:
strcpy(s1, "*Queries");
if ( !strcmp(s1, "*Queries") )
goto LABEL_59;
goto LABEL_38;
}
puts("Instrucao nao suportada dentro da instrucao *Arcs.");
}
else
{
separa_string(v85, &v77, &v78, &v79);
v18 = validar((int)v77, v76, *(unsigned int *)&v4[264 * v77 + 256]);
v19 = validar((int)v78, v76, *(unsigned int *)&v4[264 * v78 + 256]);
if ( v18 == 1 && v19 == 1 )
{
v20 = (int *)(v3[v77] + 8LL * (int)v78);
v21 = v79;
v20[1] = 1;
*v20 = v21;
}
}
if ( !strcmp(v85, "*Queries") )
goto LABEL_58;
}
}
if ( strcmp(s1, "*Queries") )
{
switch ( v75 )
{
case -3:
case -2:
case -1:
goto LABEL_95;
case 1:
do
{
while ( 1 )
{
while ( (int)v76 <= 0 )
{
puts("Erro.Numero minimo de 1 vertice nao atingido.");
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( !strcmp(s1, "@") )
goto LABEL_91;
v5 = strcmp(s1, "*Vertices");
if ( !v5 )
goto LABEL_31;
if ( !strcmp(s1, "*Edges") )
goto LABEL_148;
if ( !strcmp(s1, "*Arcs") )
goto LABEL_19;
v5 = strcmp(s1, "*Queries");
if ( !v5 )
goto LABEL_90;
}
v69 = -1;
while ( 1 )
{
v30 = v85;
v31 = -1;
do
{
v32 = v30++;
_isoc99_scanf("%c", v32);
++v31;
}
while ( *(v30 - 1) != 10 );
v85[v31] = 0;
v33 = v76;
v72 = v85[0];
if ( v85[0] == 42 )
{
++v69;
}
else
{
v35 = strlen(v85);
v36 = v72;
v37 = v35;
if ( v72 == 32 )
{
v39 = 0;
}
else
{
v38 = 1LL;
do
{
dest[v38 + 255] = v36;
v39 = v38++;
v36 = *(&v84 + v38);
}
while ( v36 != 32 );
}
v71 = v37;
v73 = v39;
nptr[v39] = 0;
v40 = atoi(nptr);
v41 = v73 + 2;
if ( v73 + 2 >= v71 )
{
v42 = -1LL;
}
else
{
v74 = v71 - 3 - v73;
memcpy(nptr, &v85[v41], v74 + 1LL);
v42 = (int)v74;
}
nptr[v42] = 0;
v43 = stpcpy(dest, nptr);
if ( v40 >= v33 )
{
puts("Indice superior ao maior indice na matriz de adjacencia.");
v33 = v76;
}
else
{
*((_QWORD *)memcpy(&v4[264 * v40], dest, v43 - dest + 1) + 32) = 1LL;
++v69;
}
}
v34 = strcmp(v85, "*Edges") == 0;
if ( v69 >= v33 )
break;
if ( v34 )
goto LABEL_15;
if ( !strcmp(v85, "*Arcs") )
goto LABEL_122;
}
if ( v34 )
break;
if ( strcmp(v85, "*Arcs") )
{
v5 = v75;
goto LABEL_95;
}
LABEL_122:
strcpy(s1, "*Arcs");
if ( !strcmp(s1, "*Arcs") )
goto LABEL_37;
}
LABEL_15:
strcpy(s1, "*Edges");
}
while ( strcmp(s1, "*Edges") );
v5 = v75;
goto LABEL_17;
default:
break;
}
while ( 1 )
{
puts("Instrucao nao implementada.");
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( s1[0] == 64 && !s1[1] )
break;
if ( !strcmp(s1, "*Vertices") )
goto LABEL_31;
if ( !strcmp(s1, "*Edges") )
goto LABEL_17;
if ( !strcmp(s1, "*Arcs") )
goto LABEL_125;
if ( !strcmp(s1, "*Queries") )
goto LABEL_90;
}
LABEL_91:
exit(0);
}
while ( 1 )
{
LABEL_90:
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( !strcmp(s1, "@") )
goto LABEL_91;
if ( !strcmp(s1, "*Vertices") )
goto LABEL_31;
if ( !strcmp(s1, "*Edges") )
{
if ( !v5 )
goto LABEL_148;
v7 = strcmp(s1, "*Arcs");
LABEL_36:
if ( !v7 )
goto LABEL_37;
if ( !strcmp(s1, "*Queries") )
{
v5 = 1;
continue;
}
LABEL_160:
v50 = v76;
if ( (int)v76 > 0 )
{
v51 = v3;
v52 = &v3[v76];
do
{
v53 = *v51;
v54 = *v51 + 8 * v50;
do
{
*(_DWORD *)(v53 + 4) = 0;
v53 += 8LL;
*(_DWORD *)(v53 - 8) = 0;
}
while ( v53 != v54 );
++v51;
}
while ( v51 != v52 );
v55 = v4 + 256;
v56 = 0LL;
do
{
if ( *v55 == 1 )
*(_DWORD *)(v3[v56] + v56 * 8 + 4) = 1;
++v56;
v55 += 66;
}
while ( v50 != v56 );
}
while ( 1 )
{
v57 = v85;
v58 = -1;
do
{
v59 = v57++;
_isoc99_scanf("%c", v59);
++v58;
}
while ( *(v57 - 1) != 10 );
v85[v58] = 0;
if ( v85[0] == 42 )
{
if ( !strcmp(v85, "*Queries") )
{
LABEL_178:
strcpy(s1, "*Queries");
if ( !strcmp(s1, "*Queries") )
{
LABEL_59:
while ( 1 )
{
v22 = s1;
v23 = -1;
do
{
v24 = v22++;
_isoc99_scanf("%c", v24);
++v23;
}
while ( *(v22 - 1) != 10 );
s1[v23] = 0;
if ( s1[0] == 64 && !s1[1] )
break;
if ( strstr(s1, "get") )
{
v25 = (unsigned int)separa_id(s1);
if ( (unsigned int)get_ID(v25, dest, v4, v76) == 1 )
printf(
"\"{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"sucesso\"}}\n",
(unsigned int)v25,
dest);
else
printf(
"{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"falha\"}}\n",
(unsigned int)v25,
dest);
}
if ( strstr(s1, "delete") )
{
v26 = (unsigned int)separa_id(s1);
if ( (unsigned int)delete_ID(v26, v76, v3, v4) == 1 )
printf("{\"delete\":{\"ID\":%d,\"resposta\":\"sucesso\"}}\n", (unsigned int)v26);
else
printf("{\"delete\":{\"ID\":%d,\"resposta\":\"falha\"}}\n", (unsigned int)v26);
}
if ( strstr(s1, "vizinhos") )
{
v27 = (unsigned int)separa_id(s1);
if ( (unsigned int)vizinhos_ID(v27, v76, v3, v85) == 1 )
printf(
"{\"vizinhos\":{\"ID\":%d, \"resposta\":\"sucesso\", \"vizinhos\":[%s]}}\n",
(unsigned int)v27,
v85);
else
printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"falha\", \"vizinhos\":[]}}\n", (unsigned int)v27);
}
if ( strstr(s1, "conexao") )
{
separa_id_id(s1, &v77, &v78);
if ( (unsigned int)conexao(v77, v78, v76, v3) == 1 )
printf(
"{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"sucesso\", \"conexao\":\"sim\"}}\n",
v77,
v78);
else
printf(
"{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"falha\", \"conexao\":\"\"}}\n",
v77,
v78);
}
if ( strstr(s1, "ordemtopologica") )
{
v85[0] = 0;
v70 = (void *)adjacencia(v70, v3, v76);
if ( (unsigned int)ordem_t(v3, v70, v4, v85, v76) == 1 )
printf("{\"ordemtop\":%s}\n", v85);
else
puts("{\"ordemtop\":falha}");
}
if ( strstr(s1, "arvoreminima") )
{
v85[0] = 0;
if ( (unsigned int)arvoreminima(v3, v4, v85, v76, 0LL) == 1 )
printf("{\"arvoreminima\":{\"arestas\":[%s],\"custo\":%d}}\n", v85, 0LL);
else
puts("{\"arvoreminima\":falha}");
}
}
goto LABEL_91;
}
goto LABEL_160;
}
puts("Instrucao nao suportada dentro da instrucao *Edges.");
}
else
{
separa_string(v85, &v77, &v78, &v79);
v60 = validar((int)v77, v76, *(unsigned int *)&v4[264 * v77 + 256]);
v61 = validar((int)v78, v76, *(unsigned int *)&v4[264 * v78 + 256]);
if ( v60 == 1 && v61 == 1 )
{
v62 = (int)v77;
v63 = (int *)(v3[v77] + 8LL * (int)v78);
v64 = v3[v78];
v65 = v79;
v63[1] = 1;
v66 = (int *)(v64 + 8 * v62);
*v63 = v65;
v66[1] = 1;
*v66 = v65;
}
}
if ( !strcmp(v85, "*Queries") )
goto LABEL_178;
}
}
if ( !strcmp(s1, "*Arcs") )
goto LABEL_125;
if ( strcmp(s1, "*Queries") )
{
sleep(2u);
printf("\x1B[H\x1B[2J");
_isoc99_scanf("%s", s1);
if ( !strcmp(s1, "@") )
goto LABEL_91;
if ( !strcmp(s1, "*Vertices") )
goto LABEL_31;
if ( !strcmp(s1, "*Edges") )
goto LABEL_17;
if ( !strcmp(s1, "*Arcs") )
goto LABEL_125;
if ( strcmp(s1, "*Queries") )
break;
}
}
v75 = -3;
LABEL_95:
sleep(2u);
printf("\x1B[H\x1B[2J");
}
}

original_code:
int main()
{
   int vertices=0,vertices_ok=0,arestas_ok=0;
   int code=0,valido_1=0,valido_2=0,resposta=0;
   int id=-1;
   int i=0,j=0,k=0;
   int indice=0,tamanho=0;
   int v1=0,v2=0,peso=0;
   int custo=0;
   char nome[255];
   char aux[255];
   char entrada[255];
   char string[255];
   NOME_VERTICES *nodos;
   MATRIZ **grafo;
   LISTA_ADJACENCIA *lista;
   do{
 scanf("%s",entrada);
 if(strcmp(entrada,"@")==0){
   exit(0);
    }
    if(strcmp(entrada,"*Vertices")==0){
    scanf("%d",&vertices);
    if(vertices_ok!=1){
   nodos=malloc(vertices*sizeof(NOME_VERTICES));
   lista=malloc(vertices*sizeof(LISTA_ADJACENCIA));
         init_nome(nodos,vertices);
         grafo=malloc(vertices*sizeof(MATRIZ));
         for(i=0;i<vertices;i++){
              grafo[i]=malloc(vertices*sizeof(MATRIZ));
   }
  code=1;
    }
    else{
       code=-2;
    }
 }
menu:
    if(strcmp(entrada,"*Edges")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=2;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
     }
    if(strcmp(entrada,"*Arcs")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=3;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
 }
 if(strcmp(entrada,"*Queries")==0){
   if(arestas_ok!=0){
     code=4;
   }
   else{
     code=-3;
   }
 }
    switch(code){
      case -4:
           break;
      case -3:
           break;
      case -2:
           if(arestas_ok!=1){
           }
           else{
     }
           break;
      case -1:
           break;
      case 1:
           if(vertices>0){
     i=-1;
     do{
       i++;
       j=-1;
       do{
         j++;
         scanf("%c",&string[j]);
       }while(string[j]!='\n');
       string[j]='\0';
       tamanho=strlen(string);
       if(string[0]!='*'){
         j=0;
         while(string[j]!=' '){
         aux[j]=string[j];
         j++;
      }
      aux[j]='\0';
      indice=atoi(aux);
      k=0;
      j+=2;
      while(j<tamanho){
         aux[k]=string[j];
         j++;
         k++;
      }
      aux[k-1]='\0';
      strcpy(nome,aux);
                  if(indice<(vertices)){
                    strcpy(nodos[indice].nome,nome);
                    nodos[indice].ini=1;
                    nodos[indice].del=0;
                  }
         else{
        printf("Indice superior ao maior indice na matriz de adjacencia.\n");
     i--;
      }
    }
    }while((i<(vertices))&&((strcmp(string,"*Edges")!=0)&&(strcmp(string,"*Arcs")!=0)));
       vertices_ok=1;
    if(strcmp(string,"*Edges")==0){
    strcpy(entrada,"*Edges");
       goto menu;
       }
    else{
               if(strcmp(string,"*Arcs")==0){
         strcpy(entrada,"*Arcs");
         goto menu;
         }
    }
     }
     else{
       printf("Erro.Numero minimo de 1 vertice nao atingido.\n");
       vertices_ok=0;
     }
           break;
      case 2:
   for(j=0;j<vertices;j++){
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
     do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                   grafo[v2][v1].conexo=1;
                   grafo[v2][v1].peso=peso;
                }
              }
              else{
       if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Edges.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
           strcpy(entrada,"*Queries");
           goto menu;
           break;
     case 3:
   for(j=0;j<vertices;j++){
     if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
   do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                }
              }
              else{
    if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Arcs.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
     strcpy(entrada,"*Queries");
     goto menu;
           break;
     case 4:
           do{
             j=-1;
             do{
      j++;
       scanf("%c",&entrada[j]);
    }while(entrada[j]!='\n');
    entrada[j]='\0';
             if(strcmp(entrada,"@")==0){
         exit(0);
             }
             if(strstr(entrada,"get")){
    resposta=0;
          id=separa_id(entrada);
          resposta=get_ID(id,nome,nodos,vertices);
          if(resposta==1){
       printf("\"{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"sucesso\"}}\n",id,nome);
    }
    else{
       printf("{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"falha\"}}\n",id,nome);
    }
       }
       if(strstr(entrada,"delete")){
    resposta=0;
          id=separa_id(entrada);
          resposta=delete_ID(id,vertices,grafo,nodos);
       if(resposta==1){
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"sucesso\"}}\n",id);
    }
    else{
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"falha\"}}\n",id);
    }
    }
       if(strstr(entrada,"vizinhos")){
                resposta=0;
          id=separa_id(entrada);
          resposta=vizinhos_ID(id,vertices,grafo,string);
          if(resposta==1){
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"sucesso\", \"vizinhos\":[%s]}}\n",id,string);
    }
    else{
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"falha\", \"vizinhos\":[]}}\n",id);
    }
       }
             if(strstr(entrada,"conexao")){
       resposta=0;
          separa_id_id(entrada,&v1,&v2);
          resposta=conexao(v1,v2,vertices,grafo);
       if(resposta==1){
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"sucesso\", \"conexao\":\"sim\"}}\n",v1,v2);
    }
    else{
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"falha\", \"conexao\":\"\"}}\n",v1,v2);
    }
    }
             if(strstr(entrada,"ordemtopologica")){
    resposta=0;
    string[0]='\0';
       lista=adjacencia(lista,grafo,vertices);
       resposta=ordem_t(grafo,lista,nodos,string,vertices);
        if(resposta==1){
       printf("{\"ordemtop\":%s}\n",string);
     }
     else{
       printf("{\"ordemtop\":falha}\n");
     }
    }
             if(strstr(entrada,"arvoreminima")){
       resposta=0;
    custo=0;
    string[0]='\0';
       resposta=arvoreminima(grafo,nodos,string,vertices,custo);
        if(resposta==1){
       printf("{\"arvoreminima\":{\"arestas\":[%s],\"custo\":%d}}\n",string,custo);
     }
     else{
       printf("{\"arvoreminima\":falha}\n");
     }
    }
           }while(1);
           break;
     default:
           printf("Instrucao nao implementada.\n");
           code=5;
           break;
    }
   sleep(2);
   printf("\33[H\33[2J");
   }while(code!=0);
 return 0;
}

canonical_original_code:
int main()
{
   int vertices = 0; int vertices_ok = 0; int arestas_ok = 0;
   int code = 0; int valido_1 = 0; int valido_2 = 0; int resposta = 0;
   int id = -1;
   int i = 0; int j = 0; int k = 0;
   int indice = 0; int tamanho = 0;
   int v1 = 0; int v2 = 0; int peso = 0;
   int custo = 0;
   char nome[255];
   char aux[255];
   char entrada[255];
   char string[255];
   struct nome_vertices *nodos;
   struct matriz **grafo;
   struct lista_adjacencia *lista;
   do{
 scanf("%s",entrada);
 if(strcmp(entrada,"@")==0){
   exit(0);
    }
    if(strcmp(entrada,"*Vertices")==0){
    scanf("%d",&vertices);
    if(vertices_ok!=1){
   nodos=malloc(vertices*sizeof(NOME_VERTICES));
   lista=malloc(vertices*sizeof(LISTA_ADJACENCIA));
         init_nome(nodos,vertices);
         grafo=malloc(vertices*sizeof(MATRIZ));
         for(i=0;i<vertices;i++){
              grafo[i]=malloc(vertices*sizeof(MATRIZ));
   }
  code=1;
    }
    else{
       code=-2;
    }
 }
menu:
    if(strcmp(entrada,"*Edges")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=2;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
     }
    if(strcmp(entrada,"*Arcs")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=3;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
 }
 if(strcmp(entrada,"*Queries")==0){
   if(arestas_ok!=0){
     code=4;
   }
   else{
     code=-3;
   }
 }
    switch(code){
      case -4:
           break;
      case -3:
           break;
      case -2:
           if(arestas_ok!=1){
           }
           else{
     }
           break;
      case -1:
           break;
      case 1:
           if(vertices>0){
     i=-1;
     do{
       i++;
       j=-1;
       do{
         j++;
         scanf("%c",&string[j]);
       }while(string[j]!='\n');
       string[j]='\0';
       tamanho=strlen(string);
       if(string[0]!='*'){
         j=0;
         while(string[j]!=' '){
         aux[j]=string[j];
         j++;
      }
      aux[j]='\0';
      indice=atoi(aux);
      k=0;
      j+=2;
      while(j<tamanho){
         aux[k]=string[j];
         j++;
         k++;
      }
      aux[k-1]='\0';
      strcpy(nome,aux);
                  if(indice<(vertices)){
                    strcpy(nodos[indice].nome,nome);
                    nodos[indice].ini=1;
                    nodos[indice].del=0;
                  }
         else{
        printf("Indice superior ao maior indice na matriz de adjacencia.\n");
     i--;
      }
    }
    }while((i<(vertices))&&((strcmp(string,"*Edges")!=0)&&(strcmp(string,"*Arcs")!=0)));
       vertices_ok=1;
    if(strcmp(string,"*Edges")==0){
    strcpy(entrada,"*Edges");
       goto menu;
       }
    else{
               if(strcmp(string,"*Arcs")==0){
         strcpy(entrada,"*Arcs");
         goto menu;
         }
    }
     }
     else{
       printf("Erro.Numero minimo de 1 vertice nao atingido.\n");
       vertices_ok=0;
     }
           break;
      case 2:
   for(j=0;j<vertices;j++){
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
     do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                   grafo[v2][v1].conexo=1;
                   grafo[v2][v1].peso=peso;
                }
              }
              else{
       if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Edges.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
           strcpy(entrada,"*Queries");
           goto menu;
           break;
     case 3:
   for(j=0;j<vertices;j++){
     if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
   do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                }
              }
              else{
    if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Arcs.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
     strcpy(entrada,"*Queries");
     goto menu;
           break;
     case 4:
           do{
             j=-1;
             do{
      j++;
       scanf("%c",&entrada[j]);
    }while(entrada[j]!='\n');
    entrada[j]='\0';
             if(strcmp(entrada,"@")==0){
         exit(0);
             }
             if(strstr(entrada,"get")){
    resposta=0;
          id=separa_id(entrada);
          resposta=get_ID(id,nome,nodos,vertices);
          if(resposta==1){
       printf("\"{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"sucesso\"}}\n",id,nome);
    }
    else{
       printf("{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"falha\"}}\n",id,nome);
    }
       }
       if(strstr(entrada,"delete")){
    resposta=0;
          id=separa_id(entrada);
          resposta=delete_ID(id,vertices,grafo,nodos);
       if(resposta==1){
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"sucesso\"}}\n",id);
    }
    else{
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"falha\"}}\n",id);
    }
    }
       if(strstr(entrada,"vizinhos")){
                resposta=0;
          id=separa_id(entrada);
          resposta=vizinhos_ID(id,vertices,grafo,string);
          if(resposta==1){
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"sucesso\", \"vizinhos\":[%s]}}\n",id,string);
    }
    else{
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"falha\", \"vizinhos\":[]}}\n",id);
    }
       }
             if(strstr(entrada,"conexao")){
       resposta=0;
          separa_id_id(entrada,&v1,&v2);
          resposta=conexao(v1,v2,vertices,grafo);
       if(resposta==1){
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"sucesso\", \"conexao\":\"sim\"}}\n",v1,v2);
    }
    else{
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"falha\", \"conexao\":\"\"}}\n",v1,v2);
    }
    }
             if(strstr(entrada,"ordemtopologica")){
    resposta=0;
    string[0]='\0';
       lista=adjacencia(lista,grafo,vertices);
       resposta=ordem_t(grafo,lista,nodos,string,vertices);
        if(resposta==1){
       printf("{\"ordemtop\":%s}\n",string);
     }
     else{
       printf("{\"ordemtop\":falha}\n");
     }
    }
             if(strstr(entrada,"arvoreminima")){
       resposta=0;
    custo=0;
    string[0]='\0';
       resposta=arvoreminima(grafo,nodos,string,vertices,custo);
        if(resposta==1){
       printf("{\"arvoreminima\":{\"arestas\":[%s],\"custo\":%d}}\n",string,custo);
     }
     else{
       printf("{\"arvoreminima\":falha}\n");
     }
    }
           }while(1);
           break;
     default:
           printf("Instrucao nao implementada.\n");
           code=5;
           break;
    }
   sleep(2);
   printf("\33[H\33[2J");
   }while(code!=0);
 return 0;
}

variable_types: vertices int

variable_types: code int

variable_types: resposta int

variable_types: j int

variable_types: k int

variable_types: indice int

variable_types: peso int

variable_types:
nome
char [255]

variable_types:
aux
char [255]

variable_types:
entrada
char [255]

variable_types:
string
char [255]