original_code:
char *rand_filename(char *random_filename, unsigned int min_length, unsigned int max_length, _Bool add_extension)
{
    int x, length, num;
    static _Bool selector;
    static long long runtime = 0;
    srand((unsigned)clock() + runtime + (time(((void *)0)) - 800500));
    while((length = rand() % max_length) < min_length)
        ;
    if(selector)
        selector = 0;
    else
        selector = 1;
    srand((unsigned)time(((void *)0)) + runtime);
    for(x = 0; x < length; x++) {
        num = rand() % 63;
        if(selector)
            num = 62 - num;
        switch(num) {
            case 0:
                random_filename[x] = '0'; break;
            case 1:
                random_filename[x] = '1'; break;
            case 2:
                random_filename[x] = '2'; break;
            case 3:
                random_filename[x] = '3'; break;
            case 4:
                random_filename[x] = '4'; break;
            case 5:
                random_filename[x] = '5'; break;
            case 6:
                random_filename[x] = '6'; break;
            case 7:
                random_filename[x] = '7'; break;
            case 8:
                random_filename[x] = '8'; break;
            case 9:
                random_filename[x] = '9'; break;
            case 10:
                random_filename[x] = 'a'; break;
            case 11:
                random_filename[x] = 'b'; break;
            case 12:
                random_filename[x] = 'c'; break;
            case 13:
                random_filename[x] = 'd'; break;
            case 14:
                random_filename[x] = 'e'; break;
            case 15:
                random_filename[x] = 'f'; break;
            case 16:
                random_filename[x] = 'g'; break;
            case 17:
                random_filename[x] = 'h'; break;
            case 18:
                random_filename[x] = 'i'; break;
            case 19:
                random_filename[x] = 'j'; break;
            case 20:
                random_filename[x] = 'k'; break;
            case 21:
                random_filename[x] = 'l'; break;
            case 22:
                random_filename[x] = 'm'; break;
            case 23:
                random_filename[x] = 'n'; break;
            case 24:
                random_filename[x] = 'o'; break;
            case 25:
                random_filename[x] = 'p'; break;
            case 26:
                random_filename[x] = 'q'; break;
            case 27:
                random_filename[x] = 'r'; break;
            case 28:
                random_filename[x] = 's'; break;
            case 29:
                random_filename[x] = 't'; break;
            case 30:
                random_filename[x] = 'u'; break;
            case 31:
                random_filename[x] = 'v'; break;
            case 32:
                random_filename[x] = 'w'; break;
            case 33:
                random_filename[x] = 'x'; break;
            case 34:
                random_filename[x] = 'y'; break;
            case 35:
                random_filename[x] = 'z'; break;
            case 36:
                random_filename[x] = 'A'; break;
            case 37:
                random_filename[x] = 'B'; break;
            case 38:
                random_filename[x] = 'C'; break;
            case 39:
                random_filename[x] = 'D'; break;
            case 40:
                random_filename[x] = 'E'; break;
            case 41:
                random_filename[x] = 'F'; break;
            case 42:
                random_filename[x] = 'G'; break;
            case 43:
                random_filename[x] = 'H'; break;
            case 44:
                random_filename[x] = 'I'; break;
            case 45:
                random_filename[x] = 'J'; break;
            case 46:
                random_filename[x] = 'K'; break;
            case 47:
                random_filename[x] = 'L'; break;
            case 48:
                random_filename[x] = 'M'; break;
            case 49:
                random_filename[x] = 'N'; break;
            case 50:
                random_filename[x] = 'O'; break;
            case 51:
                random_filename[x] = 'P'; break;
            case 52:
                random_filename[x] = 'Q'; break;
            case 53:
                random_filename[x] = 'R'; break;
            case 54:
                random_filename[x] = 'S'; break;
            case 55:
                random_filename[x] = 'T'; break;
            case 56:
                random_filename[x] = 'U'; break;
            case 57:
                random_filename[x] = 'V'; break;
            case 58:
                random_filename[x] = 'W'; break;
            case 59:
                random_filename[x] = 'X'; break;
            case 60:
                random_filename[x] = 'Y'; break;
            case 61:
                random_filename[x] = 'Z'; break;
            case 62:
                random_filename[x] = '_'; break;
            default:
                random_filename[x] = '_';
                break;
        }
    }
    if(add_extension)
        strcat(random_filename, extension);
    runtime++;
    return random_filename;
}

canonical_original_code:
char *rand_filename(char *random_filename, unsigned int min_length, unsigned int max_length, _Bool add_extension)
{
    int x; int length; int num;
    static _Bool selector;
    static long long runtime = 0;
    srand((unsigned int)clock() + runtime + (time(((void *)0)) - 800500));
    while((length = rand() % max_length) < min_length)
        ;
    if(selector)
        selector = 0;
    else
        selector = 1;
    srand((unsigned int)time(((void *)0)) + runtime);
    for(x = 0; x < length; x++) {
        num = rand() % 63;
        if(selector)
            num = 62 - num;
        switch(num) {
            case 0:
                random_filename[x] = '0'; break;
            case 1:
                random_filename[x] = '1'; break;
            case 2:
                random_filename[x] = '2'; break;
            case 3:
                random_filename[x] = '3'; break;
            case 4:
                random_filename[x] = '4'; break;
            case 5:
                random_filename[x] = '5'; break;
            case 6:
                random_filename[x] = '6'; break;
            case 7:
                random_filename[x] = '7'; break;
            case 8:
                random_filename[x] = '8'; break;
            case 9:
                random_filename[x] = '9'; break;
            case 10:
                random_filename[x] = 'a'; break;
            case 11:
                random_filename[x] = 'b'; break;
            case 12:
                random_filename[x] = 'c'; break;
            case 13:
                random_filename[x] = 'd'; break;
            case 14:
                random_filename[x] = 'e'; break;
            case 15:
                random_filename[x] = 'f'; break;
            case 16:
                random_filename[x] = 'g'; break;
            case 17:
                random_filename[x] = 'h'; break;
            case 18:
                random_filename[x] = 'i'; break;
            case 19:
                random_filename[x] = 'j'; break;
            case 20:
                random_filename[x] = 'k'; break;
            case 21:
                random_filename[x] = 'l'; break;
            case 22:
                random_filename[x] = 'm'; break;
            case 23:
                random_filename[x] = 'n'; break;
            case 24:
                random_filename[x] = 'o'; break;
            case 25:
                random_filename[x] = 'p'; break;
            case 26:
                random_filename[x] = 'q'; break;
            case 27:
                random_filename[x] = 'r'; break;
            case 28:
                random_filename[x] = 's'; break;
            case 29:
                random_filename[x] = 't'; break;
            case 30:
                random_filename[x] = 'u'; break;
            case 31:
                random_filename[x] = 'v'; break;
            case 32:
                random_filename[x] = 'w'; break;
            case 33:
                random_filename[x] = 'x'; break;
            case 34:
                random_filename[x] = 'y'; break;
            case 35:
                random_filename[x] = 'z'; break;
            case 36:
                random_filename[x] = 'A'; break;
            case 37:
                random_filename[x] = 'B'; break;
            case 38:
                random_filename[x] = 'C'; break;
            case 39:
                random_filename[x] = 'D'; break;
            case 40:
                random_filename[x] = 'E'; break;
            case 41:
                random_filename[x] = 'F'; break;
            case 42:
                random_filename[x] = 'G'; break;
            case 43:
                random_filename[x] = 'H'; break;
            case 44:
                random_filename[x] = 'I'; break;
            case 45:
                random_filename[x] = 'J'; break;
            case 46:
                random_filename[x] = 'K'; break;
            case 47:
                random_filename[x] = 'L'; break;
            case 48:
                random_filename[x] = 'M'; break;
            case 49:
                random_filename[x] = 'N'; break;
            case 50:
                random_filename[x] = 'O'; break;
            case 51:
                random_filename[x] = 'P'; break;
            case 52:
                random_filename[x] = 'Q'; break;
            case 53:
                random_filename[x] = 'R'; break;
            case 54:
                random_filename[x] = 'S'; break;
            case 55:
                random_filename[x] = 'T'; break;
            case 56:
                random_filename[x] = 'U'; break;
            case 57:
                random_filename[x] = 'V'; break;
            case 58:
                random_filename[x] = 'W'; break;
            case 59:
                random_filename[x] = 'X'; break;
            case 60:
                random_filename[x] = 'Y'; break;
            case 61:
                random_filename[x] = 'Z'; break;
            case 62:
                random_filename[x] = '_'; break;
            default:
                random_filename[x] = '_';
                break;
        }
    }
    if(add_extension)
        strcat(random_filename, extension);
    runtime++;
    return random_filename;
}

variable_types: length int

variable_types: num int

variable_types:
runtime
long long


results

decompiled_code:
int results()
{
printf("\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
printf("-------------------------------------------------------------------------------");
fprintf(primefile, "\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
return fclose(primefile);
}

canonical_decompiled_code:
int func1()
{
printf("\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
printf("-------------------------------------------------------------------------------");
fprintf(primefile, "\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
return fclose(primefile);
}

original_code:
void results(void)
{
 printf("\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 printf("-------------------------------------------------------------------------------");
 fprintf(primefile,"\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 fclose(primefile);
}

canonical_original_code:
void results()
{
 printf("\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 printf("-------------------------------------------------------------------------------");
 fprintf(primefile,"\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 fclose(primefile);
}

return_type: void


decompiled_code:
char *get_date()
{
struct tm *v0; // rax
const char *v1; // rsi
__int64 v2; // rdx
time_t timer; // [rsp+8h] [rbp-50h] BYREF
__int64 v5[9]; // [rsp+10h] [rbp-48h]

v5[0] = (__int64)"Sunday";
v5[1] = (__int64)"Monday";
v5[2] = (__int64)"Tuesday";
v5[3] = (__int64)"Wednesday";
v5[4] = (__int64)"Thursday";
v5[5] = (__int64)"Friday";
v5[6] = (__int64)"Saturday";
time(&timer);
v0 = localtime(&timer);
v1 = (const char *)&unk_283;
v2 = (unsigned int)v0->tm_hour;
if ( (int)v2 > 12 )
{
v2 = (unsigned int)(v2 - 12);
v1 = (const char *)&unk_280;
}
sprintf(
output_0,
"; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
(const char *)v5[v0->tm_wday],
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)(v0->tm_year + 1900),
v2,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec,
v1);
return output_0;
}

canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rax
const char *v1; // rsi
__int64 v2; // rdx
time_t timer; // [rsp+8h] [rbp-50h] BYREF
__int64 v5[9]; // [rsp+10h] [rbp-48h]

v5[0] = (__int64)"Sunday";
v5[1] = (__int64)"Monday";
v5[2] = (__int64)"Tuesday";
v5[3] = (__int64)"Wednesday";
v5[4] = (__int64)"Thursday";
v5[5] = (__int64)"Friday";
v5[6] = (__int64)"Saturday";
time(&timer);
v0 = localtime(&timer);
v1 = (const char *)&unk_283;
v2 = (unsigned int)v0->tm_hour;
if ( (int)v2 > 12 )
{
v2 = (unsigned int)(v2 - 12);
v1 = (const char *)&unk_280;
}
sprintf(
output_0,
"; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
(const char *)v5[v0->tm_wday],
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)(v0->tm_year + 1900),
v2,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec,
v1);
return output_0;
}

original_code:
char *get_date(void) {
 int month;
 int day;
 int year;
 char *wdays[] = {
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday"
 };
 struct tm *t;
 time_t now;
 static char output[256];
 time(&now);
 t = localtime(&now);
 month = t->tm_mon;
 day = t->tm_mday;
 year = t->tm_year;
 sprintf(output,
  "; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
  wdays[t->tm_wday],
  month +1, day, year + 1900,
  t->tm_hour > 12 ? t->tm_hour - 12 : t->tm_hour,
  t->tm_min,
  t->tm_sec,
  t->tm_hour > 12 ? "PM" : "AM"
 );
 return output;
}

canonical_original_code:
char *get_date() {
 int month;
 int day;
 int year;
 char *wdays[] = {
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday"
 };
 struct tm *t;
 long now;
 static char output[256];
 time(&now);
 t = localtime(&now);
 month = t->tm_mon;
 day = t->tm_mday;
 year = t->tm_year;
 sprintf(output,
  "; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
  wdays[t->tm_wday],
  month +1, day, year + 1900,
  t->tm_hour > 12 ? t->tm_hour - 12 : t->tm_hour,
  t->tm_min,
  t->tm_sec,
  t->tm_hour > 12 ? "PM" : "AM"
 );
 return output;
}

variable_types: month int

variable_types: day int

variable_types: year int

variable_types:
wdays
char *[]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: now long

variable_types:
output
char [256]

return_type: char *


struppercpy

decompiled_code:
__int64 __fastcall struppercpy(__int64 a1, __int64 a2)
{
const __int32_t **v3; // rsi
__int64 result; // rax
__int32_t v5; // edx

v3 = __ctype_toupper_loc();
result = 0LL;
do
{
v5 = (*v3)[*(char *)(a2 + result)];
*(_BYTE *)(a1 + result++) = v5;
}
while ( (_BYTE)v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
const __int32_t **v3; // rsi
__int64 result; // rax
__int32_t v5; // edx

v3 = __ctype_toupper_loc();
result = 0LL;
do
{
v5 = (*v3)[*(char *)(a2 + result)];
*(_BYTE *)(a1 + result++) = v5;
}
while ( (_BYTE)v5 );
return result;
}

original_code:
void struppercpy(char *output, char *string)
{
  while(*output++ = toupper(*string++));
}

variable_types:
output
char *

variable_types:
string
char *


welcome

decompiled_code:
int welcome()
{
return puts("\nHexdump v 0.1.2 - Copyright (C) 2008 samus250\nThis software comes with ABSOLUTELY NO WARRANTY.\n");
}

canonical_decompiled_code:
int func7()
{
return puts("\nHexdump v 0.1.2 - Copyright (C) 2008 samus250\nThis software comes with ABSOLUTELY NO WARRANTY.\n");
}

original_code:
void welcome(void)
{
  printf("\n"
      "Hexdump" " " "v 0.1.2" " - Copyright (C) 2008 samus250\n"
      "This software comes with ABSOLUTELY NO WARRANTY.\n\n");
  return;
}

canonical_original_code:
void welcome()
{
  printf("\n"
      "Hexdump" " " "v 0.1.2" " - Copyright (C) 2008 samus250\n"
      "This software comes with ABSOLUTELY NO WARRANTY.\n\n");
  return;
}


help

decompiled_code:
int help()
{
return puts("Usage: [input file] [output file] [array name]");
}

canonical_decompiled_code:
int func8()
{
return puts("Usage: [input file] [output file] [array name]");
}

original_code:
void help(void)
{
  printf("Usage: [input file] [output file] [array name]\n");
  return;
}

canonical_original_code:
void help()
{
  printf("Usage: [input file] [output file] [array name]\n");
  return;
}


primegen

decompiled_code:
unsigned __int64 primegen()
{
unsigned __int64 v0; // r12
char v1; // r15
char v2; // r14
__int16 v3; // r13
unsigned __int64 result; // rax
char v5; // r12
unsigned __int64 v6; // rcx
__int64 v7; // [rsp+8h] [rbp-40h]

v0 = first_range;
if ( first_range == 1LL )
{
v1 = 0;
v0 = 2LL;
}
else
{
v1 = first_range & 1;
}
v2 = 0;
v3 = 1;
v7 = 2LL;
if ( v0 <= second_range )
{
while ( 1 )
{
if ( v0 == 2 || (v0 & 1) != 0 )
{
if ( v0 <= 8 )
goto LABEL_13;
if ( 0xAAAAAAAAAAAAAAABLL * v0 > 0x5555555555555555LL )
break;
}
LABEL_6:
result = v0;
v5 = v1;
v1 = 1;
v0 = (v5 & 1) + result + 1;
if ( second_range < v0 )
return result;
}
v6 = 3LL;
while ( 1 )
{
v6 += 2LL;
if ( v6 * v6 > v0 )
break;
if ( !(v0 % v6) )
goto LABEL_6;
}
LABEL_13:
printf("%llu\t", v0);
if ( !v2 )
fwrite(&unk_191, 1uLL, 2uLL, primefile);
fprintf(primefile, "\t%llu", v0);
if ( v3 == 10 )
{
v3 = 1;
fprintf(primefile, "\n%llu.", v7++);
}
else
{
++v3;
}
++prime_numbers;
v2 = 1;
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
unsigned __int64 v0; // r12
char v1; // r15
char v2; // r14
__int16 v3; // r13
unsigned __int64 result; // rax
char v5; // r12
unsigned __int64 v6; // rcx
__int64 v7; // [rsp+8h] [rbp-40h]

v0 = first_range;
if ( first_range == 1LL )
{
v1 = 0;
v0 = 2LL;
}
else
{
v1 = first_range & 1;
}
v2 = 0;
v3 = 1;
v7 = 2LL;
if ( v0 <= second_range )
{
while ( 1 )
{
if ( v0 == 2 || (v0 & 1) != 0 )
{
if ( v0 <= 8 )
goto LABEL_13;
if ( 0xAAAAAAAAAAAAAAABLL * v0 > 0x5555555555555555LL )
break;
}
LABEL_6:
result = v0;
v5 = v1;
v1 = 1;
v0 = (v5 & 1) + result + 1;
if ( second_range < v0 )
return result;
}
v6 = 3LL;
while ( 1 )
{
v6 += 2LL;
if ( v6 * v6 > v0 )
break;
if ( !(v0 % v6) )
goto LABEL_6;
}
LABEL_13:
printf("%llu\t", v0);
if ( !v2 )
fwrite(&unk_191, 1uLL, 2uLL, primefile);
fprintf(primefile, "\t%llu", v0);
if ( v3 == 10 )
{
v3 = 1;
fprintf(primefile, "\n%llu.", v7++);
}
else
{
++v3;
}
++prime_numbers;
v2 = 1;
goto LABEL_6;
}
return result;
}

original_code:
void primegen(void)
{
 u_long_64 number_to_check,file_linecount=2;
 u_short filecount=1;
 _Bool line_number_switch=0,prime=1;
 _Bool pair=0;
 u_long_64 i;
 number_to_check=first_range;
 if(number_to_check==1)
 {
  number_to_check=2;
  pair=1;
 }
 pair = number_to_check % 2;
 while(number_to_check<=second_range)
 {
  if(number_to_check % 2 == 0 && number_to_check != 2)
  {
   prime = 0;
  }
  else
  {
   for(i=3; i*i <= number_to_check; i+=2)
   {
    if(number_to_check % i == 0)
    {
     prime = 0;
     break;
    }
   }
  }
  if(prime)
  {
   printf("%llu" "\t",number_to_check);
   if(line_number_switch==0)
   {
    fprintf(primefile,"1.");
    line_number_switch=1;
   }
   fprintf(primefile,"\t" "%llu" ,number_to_check);
   if(filecount==10)
   {
    fprintf(primefile,"\n" "%llu" ".",file_linecount);
    filecount=0;
    file_linecount++;
   }
   prime_numbers++;
   filecount++;
  }
  if(pair)
  {
   number_to_check+=2;
  }
  else
  {
   number_to_check++;
   pair=1;
  }
  prime=1;
 }
 line_number_switch=0;
 filecount=1;
 file_linecount=2;
}

canonical_original_code:
void primegen()
{
 unsigned long long number_to_check; unsigned long long file_linecount = 2;
 unsigned short filecount = 1;
 _Bool line_number_switch = 0; _Bool prime = 1;
 _Bool pair = 0;
 unsigned long long i;
 number_to_check=first_range;
 if(number_to_check==1)
 {
  number_to_check=2;
  pair=1;
 }
 pair = number_to_check % 2;
 while(number_to_check<=second_range)
 {
  if(number_to_check % 2 == 0 && number_to_check != 2)
  {
   prime = 0;
  }
  else
  {
   for(i=3; i*i <= number_to_check; i+=2)
   {
    if(number_to_check % i == 0)
    {
     prime = 0;
     break;
    }
   }
  }
  if(prime)
  {
   printf("%llu" "\t",number_to_check);
   if(line_number_switch==0)
   {
    fprintf(primefile,"1.");
    line_number_switch=1;
   }
   fprintf(primefile,"\t" "%llu" ,number_to_check);
   if(filecount==10)
   {
    fprintf(primefile,"\n" "%llu" ".",file_linecount);
    filecount=0;
    file_linecount++;
   }
   prime_numbers++;
   filecount++;
  }
  if(pair)
  {
   number_to_check+=2;
  }
  else
  {
   number_to_check++;
   pair=1;
  }
  prime=1;
 }
 line_number_switch=0;
 filecount=1;
 file_linecount=2;
}

variable_types:
filecount
unsigned short

variable_types:
i
unsigned long long


myrealloc

decompiled_code:
void *__fastcall myrealloc(void *a1, size_t a2)
{
void *result; // rax

if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, size_t a2)
{
void *result; // rax

if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
return result;
}

original_code:
static void *myrealloc(void *ptr, size_t size)
{
    if(ptr)
        return realloc(ptr, size);
    else
        return malloc(size);
}

canonical_original_code:
static void *myrealloc(void *ptr, unsigned long size)
{
    if(ptr)
        return realloc(ptr, size);
    else
        return malloc(size);
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

return_type: void *


original_code:
static size_t write_mem_callback(void *ptr, size_t size, size_t nmemb, void *data)
{
    size_t realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct *)data;
    mem->memory = myrealloc(mem->memory, mem->size + realsize + 1);
    if (mem->memory) {
        memcpy(&(mem->memory[mem->size]), ptr, realsize);
        mem->size += realsize;
        mem->memory[mem->size] = 0;
    }
    return realsize;
}

canonical_original_code:
static unsigned long write_mem_callback(void *ptr, unsigned long size, unsigned long nmemb, void *data)
{
    unsigned long realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct *)data;
    mem->memory = myrealloc(mem->memory, mem->size + realsize + 1);
    if (mem->memory) {
        memcpy(&(mem->memory[mem->size]), ptr, realsize);
        mem->size += realsize;
        mem->memory[mem->size] = 0;
    }
    return realsize;
}

variable_types:
nmemb
unsigned long

variable_types:
data
void *

variable_types:
realsize
unsigned long

variable_types: struct MemoryStruct { char *memory; unsigned long size; } *

return_type: unsigned long


original_code:
void print_progress(double total, double now)
{
    int perc = 0;
    double i = 0;
    fprintf(stderr, "\r");
    if(total > 0) {
        perc = (int)((now / total) * 100);
        fprintf(stderr, "%3d%%",perc);
        fprintf(stderr, "|");
        for (i = 0; i < 100 / 3; i++) {
            if (i == perc / 3)
                fprintf(stderr, "*");
            else
                fprintf(stderr, "-");
        }
        fprintf(stderr, "|");
    }
    if(now / 1024 < 1024)
        fprintf(stderr, " %.0f KB", now / 1024);
    else if(now / (1024 * 1024) < 1024)
        fprintf(stderr, " %.2f MB", now / (1024*1024));
    else
        fprintf(stderr, " %.2f GB", now / (1024*1024*1024));
    if(total > 0) {
        fprintf(stderr, " /");
        if(total / 1024 < 1024)
            fprintf(stderr, " %.0f KB", total / 1024);
        else if(total / (1024 * 1024) < 1024)
            fprintf(stderr, " %.2f MB", total / (1024*1024));
        else
            fprintf(stderr, " %.2f GB", total / (1024*1024*1024));
    }
    return;
}

variable_types: total double

variable_types: now double

variable_types: perc int

variable_types: i double


decompiled_code:
__int64 __fastcall progress_callback(void *a1, double a2, double a3, double a4, double a5)
{
if ( a2 <= 0.0 && a3 <= 0.0 )
{
if ( a4 <= 0.0 && a5 <= 0.0 )
{
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
return 0LL;
}
a3 = a5;
a2 = a4;
}
print_progress(a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1, double a2, double a3, double a4, double a5)
{
if ( a2 <= 0.0 && a3 <= 0.0 )
{
if ( a4 <= 0.0 && a5 <= 0.0 )
{
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
return 0LL;
}
a3 = a5;
a2 = a4;
}
func0(a2, a3);
return 0LL;
}

original_code:
int progress_callback(void *clientp,
                        double dltotal, double dlnow,
                        double ultotal, double ulnow)
{
    if(dltotal > 0 || dlnow > 0)
        print_progress(dltotal, dlnow);
    else if (ultotal > 0 || ulnow > 0)
        print_progress(ultotal, ulnow);
    else
        fprintf(stderr, "\rUnknown Progress...");
    return 0;
}

variable_types:
clientp
void *

variable_types: dltotal double

variable_types: dlnow double

variable_types: ultotal double

variable_types: ulnow double

return_type: int


canonical_original_code:
void print_progress(double total, double now)
{
    int perc = 0;
    double i = 0;
    fprintf(stderr, "\r");
    if(total > 0) {
        perc = (int)((now / total) * 100);
        fprintf(stderr, "%3d%%",perc);
        fprintf(stderr, "|");
        for (i = 0; i < 100 / 3; i++) {
            if (i == perc / 3)
                fprintf(stderr, "*");
            else
                fprintf(stderr, "-");
        }
        fprintf(stderr, "|");
    }
    if(now / 1024 < 1024)
        fprintf(stderr, " %.0f KB", now / 1024);
    else if(now / (1024 * 1024) < 1024)
        fprintf(stderr, " %.2f MB", now / (1024*1024));
    else
        fprintf(stderr, " %.2f GB", now / (1024*1024*1024));
    if(total > 0) {
        fprintf(stderr, " /");
        if(total / 1024 < 1024)
            fprintf(stderr, " %.0f KB", total / 1024);
        else if(total / (1024 * 1024) < 1024)
            fprintf(stderr, " %.2f MB", total / (1024*1024));
        else
            fprintf(stderr, " %.2f GB", total / (1024*1024*1024));
    }
    return;
}


decompiled_code:
__int64 __fastcall progress_callback(double a1, double a2, double a3, double a4)
{
if ( a1 <= 0.0 && a2 <= 0.0 )
{
if ( a3 <= 0.0 && a4 <= 0.0 )
{
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
return 0LL;
}
a2 = a4;
a1 = a3;
}
print_progress(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1, double a2, double a3, double a4)
{
if ( a1 <= 0.0 && a2 <= 0.0 )
{
if ( a3 <= 0.0 && a4 <= 0.0 )
{
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
return 0LL;
}
a2 = a4;
a1 = a3;
}
func0(a1, a2);
return 0LL;
}

canonical_original_code:
int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
    if(dltotal > 0 || dlnow > 0)
        print_progress(dltotal, dlnow);
    else if (ultotal > 0 || ulnow > 0)
        print_progress(ultotal, ulnow);
    else
        fprintf(stderr, "\rUnknown Progress...");
    return 0;
}


user_defined_types: struct MemoryStruct { char *memory; unsigned long size; }


repo: sanXVII/sima

decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf("Usage: %s [key]\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("Usage: %s [key]\n", a1);
}

original_code:
static void print_usage( const char * prog )
{
 printf( "Usage: %s [key]\n", prog );
}

canonical_original_code:
static void print_usage(char *prog)
{
 printf( "Usage: %s [key]\n", prog );
}

variable_types:
prog
char *


decompiled_code:
int print_help()
{
puts("Simulation for Ants action.\n");
puts("Keys:");
puts(" -h, --help Print this help information about mosaic ants simulator.");
puts(" -i, --image <file> Image file.");
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
puts("Simulation for Ants action.\n");
puts("Keys:");
puts(" -h, --help Print this help information about mosaic ants simulator.");
puts(" -i, --image <file> Image file.");
return putchar(10);
}

original_code:
static void print_help()
{
 printf( "Simulation for Ants action.\n\n" );
 printf( "Keys:\n" );
 printf( "     -h, --help                Print this help information about mosaic ants simulator.\n" );
 printf( "     -i, --image <file>        Image file.\n" );
 printf( "\n" );
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v5; // rbx
const char *v6; // r13
bool v7; // cf
bool v8; // zf
const char *v9; // rsi
const char *v10; // rax
int v11; // er10
unsigned int v12; // er9
bool v13; // cf
bool v14; // zf
const char *v15; // rsi
__int64 v16; // rcx
const char *v17; // rdi
const char *v18; // rdi
__int64 v19; // rcx
unsigned int v20; // eax
int v21; // ebx
__int64 v22; // rdx
int v23; // eax
__int64 v25; // rax
__int64 v26; // rsi
const char *v27; // rax
char v28[4]; // [rsp+0h] [rbp-528h] BYREF
char s[252]; // [rsp+4h] [rbp-524h] BYREF
char v30[1064]; // [rsp+100h] [rbp-428h] BYREF

if ( argc <= 1 )
{
if ( (unsigned int)SDL_Init(33LL, argv, envp) )
{
LABEL_63:
v27 = (const char *)SDL_GetError();
printf("fail: %s\n", v27);
return -1;
}
wd_of_ants_init();
init_gui();
}
else
{
LODWORD(v5) = 1;
v6 = 0LL;
while ( 2 )
{
v5 = (int)v5;
while ( 1 )
{
v10 = argv[v5];
v11 = v5;
v12 = *(unsigned __int8 *)v10;
v13 = v12 > 0x2D;
v14 = v12 == 45;
if ( v12 == 45 )
{
v13 = v10[1] < 0x68u;
v14 = v10[1] == 104;
if ( v10[1] == 104 )
{
v13 = 0;
v14 = v10[2] == 0;
if ( !v10[2] )
goto LABEL_46;
}
}
v15 = "--help";
v16 = 7LL;
v17 = argv[v5];
do
{
if ( !v16 )
break;
v13 = *v15 < (unsigned int)*v17;
v14 = *v15++ == *v17++;
--v16;
}
while ( v14 );
LOBYTE(envp) = (!v13 && !v14) - v13;
if ( !(_BYTE)envp )
{
LABEL_46:
print_usage(*argv);
print_help();
return 0;
}
v7 = v12 > 0x2D;
v8 = v12 == 45;
if ( v12 != 45 || (v7 = v10[1] < 0x69u, v8 = v10[1] == 105, v10[1] != 105) || (v7 = 0, v8 = v10[2] == 0, v10[2]) )
{
v18 = argv[v5];
v15 = "--image";
v19 = 8LL;
do
{
if ( !v19 )
break;
v7 = *v15 < (unsigned int)*v18;
v8 = *v15++ == *v18++;
--v19;
}
while ( v8 );
if ( (!v7 && !v8) != v7 )
break;
}
if ( (int)v5 + 1 >= argc )
goto LABEL_23;
v6 = argv[v5 + 1];
if ( !*v6 || *v6 == 45 )
{
puts("Invalid filename.");
return -1;
}
v9 = argv[v5 + 1];
v5 += 2LL;
printf("Image file: '%s'.\n", v9);
if ( argc <= (int)v5 )
{
if ( (unsigned int)SDL_Init(33LL, v9, envp) )
goto LABEL_63;
wd_of_ants_init();
init_gui();
goto LABEL_49;
}
}
LODWORD(v5) = v5 + 1;
if ( argc > v11 + 1 )
continue;
break;
}
LABEL_23:
if ( (unsigned int)SDL_Init(33LL, v15, envp) )
goto LABEL_63;
wd_of_ants_init();
init_gui();
if ( v6 )
{
LABEL_49:
v25 = get_world();
load_image(v6, v25 + 16);
goto LABEL_25;
}
}
LABEL_25:
v20 = fcntl(0, 3, 0LL);
BYTE1(v20) |= 8u;
fcntl(0, 4, v20);
while ( 1 )
{
v21 = 0;
printf("cmd: ");
while ( 1 )
{
v23 = getchar();
if ( v23 == 10 )
break;
if ( v23 != -1 )
{
v22 = v21++;
v28[v22] = v23;
if ( v21 > 254 )
{
v28[v21] = 0;
goto LABEL_33;
}
}
if ( main_done )
goto LABEL_45;
usleep(0x3E8u);
}
v28[v21] = 0;
if ( !v21 )
continue;
LABEL_33:
if ( main_done )
break;
if ( !strcmp(v28, "h") )
{
puts("List of supported commands:");
puts(" h - Print help information.");
puts(" fs - Start fast simulation.");
puts(" rs - Start realtime simulation.");
puts(" cb - Clear barriers.");
puts(" arb - Add random stubs.");
puts(" ab1 - Add 2 horizontal walls.");
puts(" ab2 - Add vertical walls.");
printf(" img <filename> - Load image.\n ");
puts(" q - Quit.");
putchar(10);
}
else if ( !strncmp(v28, "img ", 4uLL) )
{
if ( sscanf(s, "%s", v30) == 1 )
{
printf("Load file '%s'\n", v30);
v26 = get_world() + 16;
load_image(v30, v26);
}
else
{
puts("Invalid filename.");
}
}
else
{
if ( !strcmp(v28, "q") )
{
main_done = 1;
break;
}
if ( !strcmp(v28, "fs") )
{
do
wd_of_ants_run();
while ( !main_done );
break;
}
if ( !strcmp(v28, "rs") )
{
run_rtime_sim();
break;
}
if ( !strcmp(v28, "cb") )
{
reset_barriers();
}
else if ( !strcmp(v28, "arb") )
{
add_random_barriers();
}
else if ( !strcmp(v28, "ab1") )
{
add_barriers_1();
}
else if ( !strcmp(v28, "ab2") )
{
add_barriers_2();
}
else
{
printf("Unknown command `%s`. Enter `h` for help.\n\n", v28);
}
}
}
LABEL_45:
close_gui();
wd_of_ants_destroy();
SDL_Quit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v5; // rbx
const char *v6; // r13
bool v7; // cf
bool v8; // zf
const char *v9; // rsi
const char *v10; // rax
int v11; // er10
unsigned int v12; // er9
bool v13; // cf
bool v14; // zf
const char *v15; // rsi
__int64 v16; // rcx
const char *v17; // rdi
const char *v18; // rdi
__int64 v19; // rcx
unsigned int v20; // eax
int v21; // ebx
__int64 v22; // rdx
int v23; // eax
__int64 v25; // rax
__int64 v26; // rsi
const char *v27; // rax
char v28[4]; // [rsp+0h] [rbp-528h] BYREF
char s[252]; // [rsp+4h] [rbp-524h] BYREF
char v30[1064]; // [rsp+100h] [rbp-428h] BYREF

if ( argc <= 1 )
{
if ( (unsigned int)SDL_Init(33LL, argv, envp) )
{
LABEL_63:
v27 = (const char *)SDL_GetError();
printf("fail: %s\n", v27);
return -1;
}
wd_of_ants_init();
init_gui();
}
else
{
LODWORD(v5) = 1;
v6 = 0LL;
while ( 2 )
{
v5 = (int)v5;
while ( 1 )
{
v10 = argv[v5];
v11 = v5;
v12 = *(unsigned __int8 *)v10;
v13 = v12 > 0x2D;
v14 = v12 == 45;
if ( v12 == 45 )
{
v13 = v10[1] < 0x68u;
v14 = v10[1] == 104;
if ( v10[1] == 104 )
{
v13 = 0;
v14 = v10[2] == 0;
if ( !v10[2] )
goto LABEL_46;
}
}
v15 = "--help";
v16 = 7LL;
v17 = argv[v5];
do
{
if ( !v16 )
break;
v13 = *v15 < (unsigned int)*v17;
v14 = *v15++ == *v17++;
--v16;
}
while ( v14 );
LOBYTE(envp) = (!v13 && !v14) - v13;
if ( !(_BYTE)envp )
{
LABEL_46:
func1(*argv);
func2();
return 0;
}
v7 = v12 > 0x2D;
v8 = v12 == 45;
if ( v12 != 45 || (v7 = v10[1] < 0x69u, v8 = v10[1] == 105, v10[1] != 105) || (v7 = 0, v8 = v10[2] == 0, v10[2]) )
{
v18 = argv[v5];
v15 = "--image";
v19 = 8LL;
do
{
if ( !v19 )
break;
v7 = *v15 < (unsigned int)*v18;
v8 = *v15++ == *v18++;
--v19;
}
while ( v8 );
if ( (!v7 && !v8) != v7 )
break;
}
if ( (int)v5 + 1 >= argc )
goto LABEL_23;
v6 = argv[v5 + 1];
if ( !*v6 || *v6 == 45 )
{
puts("Invalid filename.");
return -1;
}
v9 = argv[v5 + 1];
v5 += 2LL;
printf("Image file: '%s'.\n", v9);
if ( argc <= (int)v5 )
{
if ( (unsigned int)SDL_Init(33LL, v9, envp) )
goto LABEL_63;
wd_of_ants_init();
init_gui();
goto LABEL_49;
}
}
LODWORD(v5) = v5 + 1;
if ( argc > v11 + 1 )
continue;
break;
}
LABEL_23:
if ( (unsigned int)SDL_Init(33LL, v15, envp) )
goto LABEL_63;
wd_of_ants_init();
init_gui();
if ( v6 )
{
LABEL_49:
v25 = get_world();
func3(v6, v25 + 16);
goto LABEL_25;
}
}
LABEL_25:
v20 = fcntl(0, 3, 0LL);
BYTE1(v20) |= 8u;
fcntl(0, 4, v20);
while ( 1 )
{
v21 = 0;
printf("cmd: ");
while ( 1 )
{
v23 = getchar();
if ( v23 == 10 )
break;
if ( v23 != -1 )
{
v22 = v21++;
v28[v22] = v23;
if ( v21 > 254 )
{
v28[v21] = 0;
goto LABEL_33;
}
}
if ( main_done )
goto LABEL_45;
usleep(0x3E8u);
}
v28[v21] = 0;
if ( !v21 )
continue;
LABEL_33:
if ( main_done )
break;
if ( !strcmp(v28, "h") )
{
puts("List of supported commands:");
puts(" h - Print help information.");
puts(" fs - Start fast simulation.");
puts(" rs - Start realtime simulation.");
puts(" cb - Clear barriers.");
puts(" arb - Add random stubs.");
puts(" ab1 - Add 2 horizontal walls.");
puts(" ab2 - Add vertical walls.");
printf(" img <filename> - Load image.\n ");
puts(" q - Quit.");
putchar(10);
}
else if ( !strncmp(v28, "img ", 4uLL) )
{
if ( sscanf(s, "%s", v30) == 1 )
{
printf("Load file '%s'\n", v30);
v26 = get_world() + 16;
func3(v30, v26);
}
else
{
puts("Invalid filename.");
}
}
else
{
if ( !strcmp(v28, "q") )
{
main_done = 1;
break;
}
if ( !strcmp(v28, "fs") )
{
do
wd_of_ants_run();
while ( !main_done );
break;
}
if ( !strcmp(v28, "rs") )
{
run_rtime_sim();
break;
}
if ( !strcmp(v28, "cb") )
{
reset_barriers();
}
else if ( !strcmp(v28, "arb") )
{
add_random_barriers();
}
else if ( !strcmp(v28, "ab1") )
{
add_barriers_1();
}
else if ( !strcmp(v28, "ab2") )
{
add_barriers_2();
}
else
{
printf("Unknown command `%s`. Enter `h` for help.\n\n", v28);
}
}
}
LABEL_45:
close_gui();
wd_of_ants_destroy();
SDL_Quit();
return 0;
}

original_code:
int main( int argc, char ** argv )
{
 char * arg_image_name = 0;
 int vn;
 int arg_state = 0;
 for( vn = 1; vn < argc; vn++ )
 {
  switch( arg_state )
  {
  case 0:
   if( !strcmp( "-h", argv[ vn ] ) || !strcmp( "--help", argv[ vn ] ) )
   {
    print_usage( argv[0] );
    print_help();
    return 0;
   }
   else if( !strcmp( "-i", argv[ vn ] ) || !strcmp( "--image", argv[ vn ] ) )
   {
    arg_state = 1;
   }
   break;
  case 1:
   if( ( !argv[ vn ][ 0 ] ) || ( argv[ vn ][ 0 ] == '-' ) )
   {
    printf( "Invalid filename.\n" );
    return -1;
   }
   arg_image_name = argv[ vn ];
   printf( "Image file: '%s'.\n", arg_image_name );
   arg_state = 0;
   break;
  default:
   break;
  }
 }
 if( SDL_Init( 0x00000020 | 0x00000001 ) )
 {
  printf( "fail: %s\n", SDL_GetError() );
  return -1;
 }
 wd_of_ants_init();
 init_gui();
 if( arg_image_name ) load_image( arg_image_name, &( get_world()->plan ) );
 int flags = fcntl(0, 3, 0);
 fcntl(0, 4, flags | 04000);
 char cmd[ 256 ];
 while( 1 )
 {
  int clen = 0;
  while( !clen )
  {
   printf( "cmd: " );
   while( 1 )
   {
    int c = getchar();
    if( c == '\n' ) break;
    if( c != (-1) )
    {
     cmd[ clen ] = c;
     clen++;
     if( clen >= ( sizeof( cmd ) - 1 ) ) break;
    }
    if( main_done ) goto exit;
    usleep( 1000 );
   }
   cmd[ clen ] = 0;
  }
  if( main_done ) goto exit;
  if( !strcmp( cmd, "h" ) )
  {
   printf( "List of supported commands:\n" );
   printf( "     h - Print help information.\n" );
   printf( "    fs - Start fast simulation.\n" );
   printf( "    rs - Start realtime simulation.\n" );
   printf( "    cb - Clear barriers.\n" );
   printf( "   arb - Add random stubs.\n" );
   printf( "   ab1 - Add 2 horizontal walls.\n" );
   printf( "   ab2 - Add vertical walls.\n" );
   printf( "   img <filename> - Load image.\n " );
   printf( "     q - Quit.\n" );
   printf( "\n" );
  }
  else if( !strncmp( cmd, "img ", 4 ) )
  {
   char buf[1024];
   if( sscanf( cmd + 4, "%s", buf ) == 1 )
   {
    printf( "Load file '%s'\n", buf );
    load_image( buf, &( get_world()->plan ) );
   }
   else
   {
    printf( "Invalid filename.\n" );
   }
  }
  else if( !strcmp( cmd, "q" ) )
  {
   main_done++;
   break;
  }
  else if( !strcmp( cmd, "fs" ) )
  {
   while( !main_done ) { wd_of_ants_run(); }
   break;
  }
  else if( !strcmp( cmd, "rs" ) )
  {
   run_rtime_sim();
   break;
  }
  else if( !strcmp( cmd, "cb" ) )
  {
   reset_barriers();
  }
  else if( !strcmp( cmd, "arb" ) )
  {
   add_random_barriers();
  }
  else if( !strcmp( cmd, "ab1" ) )
  {
   add_barriers_1();
  }
  else if( !strcmp( cmd, "ab2" ) )
  {
   add_barriers_2();
  }
  else
  {
   printf( "Unknown command `%s`. Enter `h` for help.\n\n", cmd );
  }
 }
exit:
 close_gui();
 wd_of_ants_destroy();
 SDL_Quit();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *arg_image_name = 0;
 int vn;
 int arg_state = 0;
 for( vn = 1; vn < argc; vn++ )
 {
  switch( arg_state )
  {
  case 0:
   if( !strcmp( "-h", argv[ vn ] ) || !strcmp( "--help", argv[ vn ] ) )
   {
    print_usage( argv[0] );
    print_help();
    return 0;
   }
   else if( !strcmp( "-i", argv[ vn ] ) || !strcmp( "--image", argv[ vn ] ) )
   {
    arg_state = 1;
   }
   break;
  case 1:
   if( ( !argv[ vn ][ 0 ] ) || ( argv[ vn ][ 0 ] == '-' ) )
   {
    printf( "Invalid filename.\n" );
    return -1;
   }
   arg_image_name = argv[ vn ];
   printf( "Image file: '%s'.\n", arg_image_name );
   arg_state = 0;
   break;
  default:
   break;
  }
 }
 if( SDL_Init( 0x00000020 | 0x00000001 ) )
 {
  printf( "fail: %s\n", SDL_GetError() );
  return -1;
 }
 wd_of_ants_init();
 init_gui();
 if( arg_image_name ) load_image( arg_image_name, &( get_world()->plan ) );
 int flags = fcntl(0, 3, 0);
 fcntl(0, 4, flags | 04000);
 char cmd[256];
 while( 1 )
 {
  int clen = 0;
  while( !clen )
  {
   printf( "cmd: " );
   while( 1 )
   {
    int c = getchar();
    if( c == '\n' ) break;
    if( c != (-1) )
    {
     cmd[ clen ] = c;
     clen++;
     if( clen >= ( sizeof( cmd ) - 1 ) ) break;
    }
    if( main_done ) goto exit;
    usleep( 1000 );
   }
   cmd[ clen ] = 0;
  }
  if( main_done ) goto exit;
  if( !strcmp( cmd, "h" ) )
  {
   printf( "List of supported commands:\n" );
   printf( "     h - Print help information.\n" );
   printf( "    fs - Start fast simulation.\n" );
   printf( "    rs - Start realtime simulation.\n" );
   printf( "    cb - Clear barriers.\n" );
   printf( "   arb - Add random stubs.\n" );
   printf( "   ab1 - Add 2 horizontal walls.\n" );
   printf( "   ab2 - Add vertical walls.\n" );
   printf( "   img <filename> - Load image.\n " );
   printf( "     q - Quit.\n" );
   printf( "\n" );
  }
  else if( !strncmp( cmd, "img ", 4 ) )
  {
   char buf[1024];
   if( sscanf( cmd + 4, "%s", buf ) == 1 )
   {
    printf( "Load file '%s'\n", buf );
    load_image( buf, &( get_world()->plan ) );
   }
   else
   {
    printf( "Invalid filename.\n" );
   }
  }
  else if( !strcmp( cmd, "q" ) )
  {
   main_done++;
   break;
  }
  else if( !strcmp( cmd, "fs" ) )
  {
   while( !main_done ) { wd_of_ants_run(); }
   break;
  }
  else if( !strcmp( cmd, "rs" ) )
  {
   run_rtime_sim();
   break;
  }
  else if( !strcmp( cmd, "cb" ) )
  {
   reset_barriers();
  }
  else if( !strcmp( cmd, "arb" ) )
  {
   add_random_barriers();
  }
  else if( !strcmp( cmd, "ab1" ) )
  {
   add_barriers_1();
  }
  else if( !strcmp( cmd, "ab2" ) )
  {
   add_barriers_2();
  }
  else
  {
   printf( "Unknown command `%s`. Enter `h` for help.\n\n", cmd );
  }
 }
exit:
 close_gui();
 wd_of_ants_destroy();
 SDL_Quit();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: vn int

variable_types: flags int

variable_types:
cmd
char [256]

variable_types: clen int

variable_types: c int

variable_types:
buf
char [1024]


decompiled_code:
__int128 *get_world()
{
return &my_world;
}

canonical_decompiled_code:
__int128 *func1()
{
return &my_world;
}

original_code:
wd_of_ants * get_world( void )
{
 return &my_world;
}

canonical_original_code:
struct wd_of_ants *get_world()
{
 return &my_world;
}

return_type: struct wd_of_ants { struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *stub; struct ant { struct pix { float red; float green; float blue; int state; } cpix; float pos_x; float pos_ang; float left_angle; float right_angle; float left_speed; float right_speed; float axis_len; float tire_radius; float nose_len; struct ant *next; } *muvis; struct genplan { float left_up_x; float left_up_y; float pix_side; int width; int hight; struct pix *pixs; int last_tasked; } plan; struct free_pixels { int pix_cnt; struct free_pix_blk { struct free_pix { float x; float red; float green; float blue; float angle; float state; } pix[100]; struct free_pix_blk *next; } *last_blk; struct rtree *tree; } *free_pixs; struct free_pixels *free_pixs_4del; unsigned long sim_cnt; } *

user_defined_types: struct wd_of_ants { struct rtree *stub; struct ant *muvis; struct genplan plan; struct free_pixels *free_pixs; struct free_pixels *free_pixs_4del; unsigned long sim_cnt; }

user_defined_types: struct rtree { struct rtree_n *adam; struct rtree_nblk first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; }

user_defined_types: struct ant { struct pix cpix; float pos_x; float pos_ang; float left_angle; float right_angle; float left_speed; float right_speed; float axis_len; float tire_radius; float nose_len; struct ant *next; }

user_defined_types: struct free_pixels { int pix_cnt; struct free_pix_blk *last_blk; struct rtree *tree; }

user_defined_types: struct free_pix_blk { struct free_pix pix[100]; struct free_pix_blk *next; }


decompiled_code:
__int64 reset_barriers()
{
__int64 v0; // rbp

v0 = my_world;
*(_QWORD *)&my_world = new_rtree();
if ( !(_QWORD)my_world )
_assert_fail("my_world.stub", "wd_of_ants.c", 0x34u, "reset_barriers");
return del_rtree(v0);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp

v0 = my_world;
*(_QWORD *)&my_world = new_rtree();
if ( !(_QWORD)my_world )
_assert_fail("my_world.stub", "wd_of_ants.c", 0x34u, "reset_barriers");
return del_rtree(v0);
}

original_code:
void reset_barriers( void )
{
 rtree * ob = my_world.stub;
 my_world.stub = new_rtree();
 ((void) sizeof ((my_world.stub) ? 1 : 0), __extension__ ({ if (my_world.stub) ; else __assert_fail ("my_world.stub", "wd_of_ants.c", 52, __extension__ __PRETTY_FUNCTION__); }));
 del_rtree( ob );
}

canonical_original_code:
void reset_barriers()
{
 struct rtree *ob = my_world.stub;
 my_world.stub = new_rtree();
 ((void) sizeof ((my_world.stub) ? 1 : 0), __extension__ ({ if (my_world.stub) ; else __assert_fail ("my_world.stub", "wd_of_ants.c", 52, __extension__ __PRETTY_FUNCTION__); }));
 del_rtree( ob );
}

variable_types: struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *


decompiled_code:
__int64 add_random_barriers()
{
int v0; // ebx
int v1; // ebp
float v2; // xmm1_4
float v3; // xmm0_4
__int64 result; // rax

v0 = 10;
do
{
v1 = rand();
v2 = (float)(rand() % 100) / 25.0 - 2.0;
v3 = (float)(v1 % 100) / 25.0 - 2.0;
result = to_rtree(my_world, 1LL, v3, v2);
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebx
int v1; // ebp
float v2; // xmm1_4
float v3; // xmm0_4
__int64 result; // rax

v0 = 10;
do
{
v1 = rand();
v2 = (float)(rand() % 100) / 25.0 - 2.0;
v3 = (float)(v1 % 100) / 25.0 - 2.0;
result = to_rtree(my_world, 1LL, v3, v2);
--v0;
}
while ( v0 );
return result;
}

original_code:
void add_random_barriers( void )
{
 int i;
 for( i = 0; i < 10; i++ )
 {
  float xx = ( float )( rand() % 100 ) / 25.0 - 2.0;
  float yy = ( float )( rand() % 100 ) / 25.0 - 2.0;
  to_rtree( my_world.stub, xx, yy, ( void * )1 );
 }
}

canonical_original_code:
void add_random_barriers()
{
 int i;
 for( i = 0; i < 10; i++ )
 {
  float xx = ( float )( rand() % 100 ) / 25.0 - 2.0;
  float yy = ( float )( rand() % 100 ) / 25.0 - 2.0;
  to_rtree( my_world.stub, xx, yy, ( void * )1 );
 }
}

variable_types: i int

variable_types: xx float

variable_types: yy float


decompiled_code:
__int64 add_barriers_1()
{
int v0; // ebx
float v1; // xmm0_4
double v2; // xmm2_8
__int64 result; // rax

v0 = 15;
v1 = *(float *)&LC6;
v2 = *(double *)&LC7;
do
{
to_rtree(my_world, 1LL, v1, 0.69999999);
result = to_rtree(my_world, 1LL, v1, -0.69999999);
v1 = v2 + 0.08;
v2 = v1;
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
float v1; // xmm0_4
double v2; // xmm2_8
__int64 result; // rax

v0 = 15;
v1 = *(float *)&LC6;
v2 = *(double *)&LC7;
do
{
to_rtree(my_world, 1LL, v1, 0.69999999);
result = to_rtree(my_world, 1LL, v1, -0.69999999);
v1 = v2 + 0.08;
v2 = v1;
--v0;
}
while ( v0 );
return result;
}

original_code:
void add_barriers_1( void )
{
 float xx;
 for( xx = -0.6; xx < 0.6; xx += 0.08 )
 {
  to_rtree( my_world.stub, xx, 0.7, ( void * )1 );
  to_rtree( my_world.stub, xx, -0.7, ( void * )1 );
 }
}

canonical_original_code:
void add_barriers_1()
{
 float xx;
 for( xx = -0.6; xx < 0.6; xx += 0.08 )
 {
  to_rtree( my_world.stub, xx, 0.7, ( void * )1 );
  to_rtree( my_world.stub, xx, -0.7, ( void * )1 );
 }
}


decompiled_code:
__int64 add_barriers_2()
{
int v0; // ebx
float v1; // xmm3_4
double v2; // xmm2_8
__int64 result; // rax

v0 = 15;
v1 = *(float *)&LC6;
v2 = *(double *)&LC7;
do
{
to_rtree(my_world, 1LL, 0.0, v1 + 1.0);
result = to_rtree(my_world, 1LL, 0.0, v1 - 1.0);
v1 = v2 + 0.08;
v2 = v1;
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ebx
float v1; // xmm3_4
double v2; // xmm2_8
__int64 result; // rax

v0 = 15;
v1 = *(float *)&LC6;
v2 = *(double *)&LC7;
do
{
to_rtree(my_world, 1LL, 0.0, v1 + 1.0);
result = to_rtree(my_world, 1LL, 0.0, v1 - 1.0);
v1 = v2 + 0.08;
v2 = v1;
--v0;
}
while ( v0 );
return result;
}

original_code:
void add_barriers_2( void )
{
 float yy;
 for( yy = -0.6; yy < 0.6; yy += 0.08 )
 {
  to_rtree( my_world.stub, 0.0, yy + 1.0, ( void * )1 );
  to_rtree( my_world.stub, 0.0, yy - 1.0, ( void * )1 );
 }
}

canonical_original_code:
void add_barriers_2()
{
 float yy;
 for( yy = -0.6; yy < 0.6; yy += 0.08 )
 {
  to_rtree( my_world.stub, 0.0, yy + 1.0, ( void * )1 );
  to_rtree( my_world.stub, 0.0, yy - 1.0, ( void * )1 );
 }
}


decompiled_code:
__int64 wd_of_ants_init()
{
_DWORD *v0; // rax
float *v1; // rax
int v2; // edx
float v3; // xmm0_4
float v4; // xmm0_4

my_world = 0LL;
xmmword_950 = 0LL;
xmmword_960 = 0LL;
xmmword_970 = 0LL;
xmmword_980 = 0LL;
v0 = add_muvi_ant_constprop_0();
add_sim_drv(&my_world, v0);
*(_QWORD *)&my_world = new_rtree();
if ( !(_QWORD)my_world )
_assert_fail("my_world.stub", "wd_of_ants.c", 0x63u, "wd_of_ants_init");
LODWORD(xmmword_960) = 200;
*(_QWORD *)&xmmword_950 = 0x40A33333C0E33333LL;
*((_QWORD *)&xmmword_950 + 1) = 0x12C3CA3D70ALL;
v1 = (float *)calloc(0xEA600uLL, 1uLL);
*((_QWORD *)&xmmword_960 + 1) = v1;
if ( !v1 )
_assert_fail("my_world.plan.pixs", "wd_of_ants.c", 0x6Eu, "wd_of_ants_init");
v2 = 0;
do
{
v1 += 4;
v3 = (float)v2++;
v4 = v3 / 60000.0;
*(v1 - 4) = v4;
*(v1 - 3) = 1.0 - v4;
*(v1 - 2) = v4 * (float)(1.0 - v4);
}
while ( v2 != 60000 );
puts("I am happy say you that: Make the World of Ants complete!");
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
_DWORD *v0; // rax
float *v1; // rax
int v2; // edx
float v3; // xmm0_4
float v4; // xmm0_4

my_world = 0LL;
xmmword_950 = 0LL;
xmmword_960 = 0LL;
xmmword_970 = 0LL;
xmmword_980 = 0LL;
v0 = func0();
add_sim_drv(&my_world, v0);
*(_QWORD *)&my_world = new_rtree();
if ( !(_QWORD)my_world )
_assert_fail("my_world.stub", "wd_of_ants.c", 0x63u, "wd_of_ants_init");
LODWORD(xmmword_960) = 200;
*(_QWORD *)&xmmword_950 = 0x40A33333C0E33333LL;
*((_QWORD *)&xmmword_950 + 1) = 0x12C3CA3D70ALL;
v1 = (float *)calloc(0xEA600uLL, 1uLL);
*((_QWORD *)&xmmword_960 + 1) = v1;
if ( !v1 )
_assert_fail("my_world.plan.pixs", "wd_of_ants.c", 0x6Eu, "wd_of_ants_init");
v2 = 0;
do
{
v1 += 4;
v3 = (float)v2++;
v4 = v3 / 60000.0;
*(v1 - 4) = v4;
*(v1 - 3) = 1.0 - v4;
*(v1 - 2) = v4 * (float)(1.0 - v4);
}
while ( v2 != 60000 );
puts("I am happy say you that: Make the World of Ants complete!");
return 0LL;
}

original_code:
int wd_of_ants_init( void )
{
 memset( &my_world, 0, sizeof( my_world ) );
 ant * first_ant = add_muvi_ant( &my_world, 0, 0, 0 );
 add_sim_drv( &my_world, first_ant );
 my_world.stub = new_rtree();
 ((void) sizeof ((my_world.stub) ? 1 : 0), __extension__ ({ if (my_world.stub) ; else __assert_fail ("my_world.stub", "wd_of_ants.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 my_world.plan.left_up_x = -7.1 ;
 my_world.plan.left_up_y = 5.1;
 my_world.plan.pix_side = 0.02;
 my_world.plan.width = 300;
 my_world.plan.hight = 200;
 int pix_num = my_world.plan.width * my_world.plan.hight;
 my_world.plan.pixs = ( pix * )malloc( sizeof( pix ) * pix_num );
 ((void) sizeof ((my_world.plan.pixs) ? 1 : 0), __extension__ ({ if (my_world.plan.pixs) ; else __assert_fail ("my_world.plan.pixs", "wd_of_ants.c", 110, __extension__ __PRETTY_FUNCTION__); }));
 memset( my_world.plan.pixs, 0, pix_num * sizeof( pix ) );
 int i;
 for( i = 0; i < pix_num; i++ )
 {
  my_world.plan.pixs[ i ].red = ( float )i / ( float )pix_num;
  my_world.plan.pixs[ i ].green = 1.0 - ( float )i / ( float )pix_num;
  my_world.plan.pixs[ i ].blue =
   my_world.plan.pixs[ i ].red * my_world.plan.pixs[ i ].green;
 }
 printf( "I am happy say you that: Make the World of Ants complete!\n" );
 return 0;
}

canonical_original_code:
int wd_of_ants_init()
{
 memset( &my_world, 0, sizeof( my_world ) );
 struct ant *first_ant = add_muvi_ant( &my_world, 0, 0, 0 );
 add_sim_drv( &my_world, first_ant );
 my_world.stub = new_rtree();
 ((void) sizeof ((my_world.stub) ? 1 : 0), __extension__ ({ if (my_world.stub) ; else __assert_fail ("my_world.stub", "wd_of_ants.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 my_world.plan.left_up_x = -7.1 ;
 my_world.plan.left_up_y = 5.1;
 my_world.plan.pix_side = 0.02;
 my_world.plan.width = 300;
 my_world.plan.hight = 200;
 int pix_num = my_world.plan.width * my_world.plan.hight;
 my_world.plan.pixs = ( struct pix * )malloc( sizeof( pix ) * pix_num );
 ((void) sizeof ((my_world.plan.pixs) ? 1 : 0), __extension__ ({ if (my_world.plan.pixs) ; else __assert_fail ("my_world.plan.pixs", "wd_of_ants.c", 110, __extension__ __PRETTY_FUNCTION__); }));
 memset( my_world.plan.pixs, 0, pix_num * sizeof( pix ) );
 int i;
 for( i = 0; i < pix_num; i++ )
 {
  my_world.plan.pixs[ i ].red = ( float )i / ( float )pix_num;
  my_world.plan.pixs[ i ].green = 1.0 - ( float )i / ( float )pix_num;
  my_world.plan.pixs[ i ].blue =
   my_world.plan.pixs[ i ].red * my_world.plan.pixs[ i ].green;
 }
 printf( "I am happy say you that: Make the World of Ants complete!\n" );
 return 0;
}

variable_types: struct ant { struct pix { float red; float green; float blue; int state; } cpix; float pos_x; float pos_ang; float left_angle; float right_angle; float left_speed; float right_speed; float axis_len; float tire_radius; float nose_len; struct ant *next; } *


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

if ( (_QWORD)xmmword_980 )
del_free_pixels();
if ( *((_QWORD *)&xmmword_970 + 1) )
del_free_pixels();
free(*((void **)&xmmword_960 + 1));
del_rtree(my_world);
close_sim_drv();
v0 = (_QWORD *)*((_QWORD *)&my_world + 1);
if ( *((_QWORD *)&my_world + 1) )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[7];
free(v1);
}
while ( v0 );
}
}

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

if ( (_QWORD)xmmword_980 )
del_free_pixels();
if ( *((_QWORD *)&xmmword_970 + 1) )
del_free_pixels();
free(*((void **)&xmmword_960 + 1));
del_rtree(my_world);
close_sim_drv();
v0 = (_QWORD *)*((_QWORD *)&my_world + 1);
if ( *((_QWORD *)&my_world + 1) )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[7];
free(v1);
}
while ( v0 );
}
}

original_code:
void wd_of_ants_destroy( void )
{
 if( my_world.free_pixs_4del ) del_free_pixels( my_world.free_pixs_4del );
 if( my_world.free_pixs ) del_free_pixels( my_world.free_pixs );
 free( my_world.plan.pixs );
 del_rtree( my_world.stub );
 close_sim_drv();
 ant * cant = my_world.muvis;
 while( cant )
 {
  ant * rip = cant;
  cant = cant->next;
  free( rip );
 }
}

canonical_original_code:
void wd_of_ants_destroy()
{
 if( my_world.free_pixs_4del ) del_free_pixels( my_world.free_pixs_4del );
 if( my_world.free_pixs ) del_free_pixels( my_world.free_pixs );
 free( my_world.plan.pixs );
 del_rtree( my_world.stub );
 close_sim_drv();
 struct ant *cant = my_world.muvis;
 while( cant )
 {
  struct ant *rip = cant;
  cant = cant->next;
  free( rip );
 }
}

user_defined_types: struct pix { float red; float green; float blue; int state; }


original_code:
void wd_of_ants_run( void )
{
 exec_sim_drv();
 ant * cant = my_world.muvis;
 while( cant )
 {
  float lrotate = cant->left_speed * 0.0002;
  float rrotate = cant->right_speed * 0.0002;
  cant->left_angle += lrotate;
  cant->right_angle += rrotate;
  cant->left_angle = (cant->left_angle > 2*3.14159265358979323846) ? cant->left_angle-2*3.14159265358979323846 : cant->left_angle;
  cant->right_angle = (cant->right_angle > 2*3.14159265358979323846) ? cant->right_angle-2*3.14159265358979323846 : cant->right_angle;
  float lmove = lrotate * cant->tire_radius;
  float rmove = rrotate * cant->tire_radius;
  float move = ( lmove + rmove ) / 2.0;
  cant->pos_x += cos( cant->pos_ang ) * move;
  cant->pos_y += sin( cant->pos_ang ) * move;
  cant->pos_ang += ( rmove - lmove ) / cant->axis_len;
  cant->pos_ang = (cant->pos_ang > 2*3.14159265358979323846) ? cant->pos_ang-2*3.14159265358979323846 : cant->pos_ang;
  cant->pos_ang = (cant->pos_ang < -2*3.14159265358979323846) ? cant->pos_ang+2*3.14159265358979323846 : cant->pos_ang;
  cant = cant->next;
 }
 if( !( my_world.sim_cnt % 16000 ) )
 {
  free_pixels * new_data = new_free_pixels();
  int i;
  for( i = 0; i < 1600; i++ )
  {
   float x = ( float )( rand() % 100 ) / 25.0 - 2.0;
   float y = ( float )( rand() % 100 ) / 25.0 - 2.0;
   float r = ( float )( rand() % 100 ) / 100.0;
   float g = ( float )( rand() % 100 ) / 100.0;
   float b = ( float )( rand() % 100 ) / 100.0;
   float ang = ( float )( rand() % 628 ) / 100.0;
   if( ( x < 0.1 ) && ( y > -0.1 ) ) continue;
   if( get_next_near( my_world.stub->adam, x, y, 0.45 ) )
    continue;
   add_pixel( new_data, x, y, r, g, b, ang );
  }
  if( my_world.free_pixs_4del ) del_free_pixels( my_world.free_pixs_4del );
  my_world.free_pixs_4del = my_world.free_pixs;
  my_world.free_pixs = new_data;
 }
 my_world.sim_cnt++;
}

canonical_original_code:
void wd_of_ants_run()
{
 exec_sim_drv();
 struct ant *cant = my_world.muvis;
 while( cant )
 {
  float lrotate = cant->left_speed * 0.0002;
  float rrotate = cant->right_speed * 0.0002;
  cant->left_angle += lrotate;
  cant->right_angle += rrotate;
  cant->left_angle = (cant->left_angle > 2*3.14159265358979323846) ? cant->left_angle-2*3.14159265358979323846 : cant->left_angle;
  cant->right_angle = (cant->right_angle > 2*3.14159265358979323846) ? cant->right_angle-2*3.14159265358979323846 : cant->right_angle;
  float lmove = lrotate * cant->tire_radius;
  float rmove = rrotate * cant->tire_radius;
  float move = ( lmove + rmove ) / 2.0;
  cant->pos_x += cos( cant->pos_ang ) * move;
  cant->pos_y += sin( cant->pos_ang ) * move;
  cant->pos_ang += ( rmove - lmove ) / cant->axis_len;
  cant->pos_ang = (cant->pos_ang > 2*3.14159265358979323846) ? cant->pos_ang-2*3.14159265358979323846 : cant->pos_ang;
  cant->pos_ang = (cant->pos_ang < -2*3.14159265358979323846) ? cant->pos_ang+2*3.14159265358979323846 : cant->pos_ang;
  cant = cant->next;
 }
 if( !( my_world.sim_cnt % 16000 ) )
 {
  struct free_pixels *new_data = new_free_pixels();
  int i;
  for( i = 0; i < 1600; i++ )
  {
   float x = ( float )( rand() % 100 ) / 25.0 - 2.0;
   float y = ( float )( rand() % 100 ) / 25.0 - 2.0;
   float r = ( float )( rand() % 100 ) / 100.0;
   float g = ( float )( rand() % 100 ) / 100.0;
   float b = ( float )( rand() % 100 ) / 100.0;
   float ang = ( float )( rand() % 628 ) / 100.0;
   if( ( x < 0.1 ) && ( y > -0.1 ) ) continue;
   if( get_next_near( my_world.stub->adam, x, y, 0.45 ) )
    continue;
   add_pixel( new_data, x, y, r, g, b, ang );
  }
  if( my_world.free_pixs_4del ) del_free_pixels( my_world.free_pixs_4del );
  my_world.free_pixs_4del = my_world.free_pixs;
  my_world.free_pixs = new_data;
 }
 my_world.sim_cnt++;
}

variable_types: lrotate float

variable_types: rrotate float

variable_types: lmove float

variable_types: rmove float

variable_types: move float

variable_types: struct free_pixels { int pix_cnt; struct free_pix_blk { struct free_pix { float x; float red; float green; float blue; float angle; float state; } pix[100]; struct free_pix_blk *next; } *last_blk; struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *tree; } *

variable_types: x float

variable_types: y float

variable_types: r float

variable_types: g float

variable_types: b float

variable_types: ang float


decompiled_code:
__int64 __fastcall ant_catch_pix(__int64 a1, __int64 a2, float a3, float a4, float a5)
{
double v5; // xmm6_8
float v6; // xmm1_4
float v7; // xmm0_4
__int64 result; // rax
int v9; // xmm0_4
double cosx; // [rsp+10h] [rbp-28h] BYREF
double sinx[4]; // [rsp+18h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 12) = 0;
sincos(*(float *)(a2 + 24), sinx, &cosx);
v5 = *(float *)(a2 + 52);
v6 = sinx[0] * v5 + *(float *)(a2 + 20);
v7 = *(float *)(a2 + 16) + v5 * cosx;
result = booking_free_pix(*(_QWORD *)(a1 + 56), 13LL, v7, v6, 0.0099999998, a3, a4, a5);
if ( result )
{
*(_DWORD *)a2 = *(_DWORD *)(result + 8);
*(_DWORD *)(a2 + 4) = *(_DWORD *)(result + 12);
v9 = *(_DWORD *)(result + 16);
++*(_DWORD *)(a2 + 12);
*(_DWORD *)(a2 + 8) = v9;
*(float *)(result + 24) = *(float *)(result + 24) + 1.0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, float a3, float a4, float a5)
{
double v5; // xmm6_8
float v6; // xmm1_4
float v7; // xmm0_4
__int64 result; // rax
int v9; // xmm0_4
double cosx; // [rsp+10h] [rbp-28h] BYREF
double sinx[4]; // [rsp+18h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 12) = 0;
sincos(*(float *)(a2 + 24), sinx, &cosx);
v5 = *(float *)(a2 + 52);
v6 = sinx[0] * v5 + *(float *)(a2 + 20);
v7 = *(float *)(a2 + 16) + v5 * cosx;
result = booking_free_pix(*(_QWORD *)(a1 + 56), 13LL, v7, v6, 0.0099999998, a3, a4, a5);
if ( result )
{
*(_DWORD *)a2 = *(_DWORD *)(result + 8);
*(_DWORD *)(a2 + 4) = *(_DWORD *)(result + 12);
v9 = *(_DWORD *)(result + 16);
++*(_DWORD *)(a2 + 12);
*(_DWORD *)(a2 + 8) = v9;
*(float *)(result + 24) = *(float *)(result + 24) + 1.0;
}
return result;
}

original_code:
void ant_catch_pix( wd_of_ants * wd, ant * at, float r, float g, float b )
{
 at->cpix.state = 0;
 float nx = at->pos_x + cos( at->pos_ang ) * at->nose_len;
 float ny = at->pos_y + sin( at->pos_ang ) * at->nose_len;
 free_pix * bpix = 0l;
 bpix = booking_free_pix( wd->free_pixs, nx, ny,
  0.01 , r, g, b, 13 );
 if( !bpix ) return;
 at->cpix.red = bpix->red;
 at->cpix.green = bpix->green;
 at->cpix.blue = bpix->blue;
 at->cpix.state++;
 bpix->state++;
}

canonical_original_code:
void ant_catch_pix(struct wd_of_ants *wd, struct ant *at, float r, float g, float b)
{
 at->cpix.state = 0;
 float nx = at->pos_x + cos( at->pos_ang ) * at->nose_len;
 float ny = at->pos_y + sin( at->pos_ang ) * at->nose_len;
 struct free_pix *bpix = 0l;
 bpix = booking_free_pix( wd->free_pixs, nx, ny,
  0.01 , r, g, b, 13 );
 if( !bpix ) return;
 at->cpix.red = bpix->red;
 at->cpix.green = bpix->green;
 at->cpix.blue = bpix->blue;
 at->cpix.state++;
 bpix->state++;
}

variable_types: struct wd_of_ants { struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *stub; struct ant { struct pix { float red; float green; float blue; int state; } cpix; float pos_x; float pos_ang; float left_angle; float right_angle; float left_speed; float right_speed; float axis_len; float tire_radius; float nose_len; struct ant *next; } *muvis; struct genplan { float left_up_x; float left_up_y; float pix_side; int width; int hight; struct pix *pixs; int last_tasked; } plan; struct free_pixels { int pix_cnt; struct free_pix_blk { struct free_pix { float x; float red; float green; float blue; float angle; float state; } pix[100]; struct free_pix_blk *next; } *last_blk; struct rtree *tree; } *free_pixs; struct free_pixels *free_pixs_4del; unsigned long sim_cnt; } *

variable_types:
at
struct ant *

variable_types: nx float

variable_types: ny float

variable_types: struct free_pix { float x; float red; float green; float blue; float angle; float state; } *


decompiled_code:
_BOOL8 __fastcall is_good_xy(float *a1, float a2, float a3, float a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( (float)(a1[1] - a4) <= a2 && a2 <= (float)(*a1 + a4) && (float)(a1[3] - a4) <= a3 )
result = a3 <= (float)(a4 + a1[2]);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(float *a1, float a2, float a3, float a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( (float)(a1[1] - a4) <= a2 && a2 <= (float)(*a1 + a4) && (float)(a1[3] - a4) <= a3 )
result = a3 <= (float)(a4 + a1[2]);
return result;
}

original_code:
static int is_good_xy( rtree_n * n, float x, float y, float delta )
{
 if( x < ( n->min_x - delta ) ) return 0;
 if( x > ( n->max_x + delta ) ) return 0;
 if( y < ( n->min_y - delta ) ) return 0;
 if( y > ( n->max_y + delta ) ) return 0;
 return 1;
}

canonical_original_code:
static int is_good_xy(struct rtree_n *n, float x, float y, float delta)
{
 if( x < ( n->min_x - delta ) ) return 0;
 if( x > ( n->max_x + delta ) ) return 0;
 if( y < ( n->min_y - delta ) ) return 0;
 if( y > ( n->max_y + delta ) ) return 0;
 return 1;
}

variable_types: struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *

variable_types: delta float


decompiled_code:
float *__fastcall get_down(__int64 a1, float a2, float a3, float a4)
{
float *v5; // r8
__int64 v6; // rdx

v5 = (float *)a1;
if ( !*(_QWORD *)(a1 + 32) )
return (float *)a1;
do
{
if ( !is_good_xy(v5, a2, a3, a4) )
break;
v5 = (float *)v6;
}
while ( *(_QWORD *)(v6 + 32) );
return v5;
}

canonical_decompiled_code:
float *__fastcall func8(__int64 a1, float a2, float a3, float a4)
{
float *v5; // r8
__int64 v6; // rdx

v5 = (float *)a1;
if ( !*(_QWORD *)(a1 + 32) )
return (float *)a1;
do
{
if ( !func7(v5, a2, a3, a4) )
break;
v5 = (float *)v6;
}
while ( *(_QWORD *)(v6 + 32) );
return v5;
}

original_code:
static rtree_n * get_down( rtree_n * cur_n, float x, float y, float delta )
{
 while( cur_n->child )
 {
  if( !is_good_xy( cur_n, x, y, delta ) ) break;
  cur_n = cur_n->child;
 }
 return cur_n;
}

canonical_original_code:
static struct rtree_n *get_down(struct rtree_n *cur_n, float x, float y, float delta)
{
 while( cur_n->child )
 {
  if( !is_good_xy( cur_n, x, y, delta ) ) break;
  cur_n = cur_n->child;
 }
 return cur_n;
}

return_type: struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *


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

if ( !a1 )
return 0LL;
do
{
result = *(_QWORD *)(a1 + 40);
if ( result )
break;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
do
{
result = *(_QWORD *)(a1 + 40);
if ( result )
break;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

original_code:
static rtree_n * get_right( rtree_n * cur_n )
{
 while( cur_n )
 {
  if( cur_n->sister )
  {
   return cur_n->sister;
  }
  cur_n = cur_n->parent;
 }
 return cur_n;
}

canonical_original_code:
static struct rtree_n *get_right(struct rtree_n *cur_n)
{
 while( cur_n )
 {
  if( cur_n->sister )
  {
   return cur_n->sister;
  }
  cur_n = cur_n->parent;
 }
 return cur_n;
}

user_defined_types: struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; }


original_code:
static void to_rtree_node( rtree * rt, rtree_n * parent, rtree_n * child )
{
 if( parent->val )
 {
  rtree_n * nn = get_new_node( rt );
  nn->max_x = nn->min_x = parent->max_x;
  nn->max_y = nn->min_y = parent->max_y;
  nn->val = parent->val;
  nn->parent = parent;
  parent->val = 0l;
  parent->child = nn;
 }
 parent->max_x = ( child->max_x > parent->max_x ) ? child->max_x : parent->max_x;
 parent->max_y = ( child->max_y > parent->max_y ) ? child->max_y : parent->max_y;
 parent->min_x = ( child->min_x < parent->min_x ) ? child->min_x : parent->min_x;
 parent->min_y = ( child->min_y < parent->min_y ) ? child->min_y : parent->min_y;
 float min_dS;
 rtree_n * best_child = parent->child;
 int i;
 rtree_n * tnod = parent->child;
 for( i = 0; i < (4); i++ )
 {
  if( !tnod )
  {
   child->sister = parent->child;
   parent->child = child;
   child->parent = parent;
   return;
  }
  float max_x = ( child->max_x > tnod->max_x ) ? child->max_x : tnod->max_x;
  float max_y = ( child->max_y > tnod->max_y ) ? child->max_y : tnod->max_y;
  float min_x = ( child->min_x < tnod->min_x ) ? child->min_x : tnod->min_x;
  float min_y = ( child->min_y < tnod->min_y ) ? child->min_y : tnod->min_y;
  float dS = ( max_x - min_x ) * ( max_y - min_y );
  dS -= ( tnod->max_x - tnod->min_x ) * ( tnod->max_y - tnod->min_y );
  min_dS = !i ? dS : min_dS;
  if( min_dS > dS )
  {
   min_dS = dS;
   best_child = tnod;
  }
  tnod = tnod->sister;
 }
 to_rtree_node( rt, best_child, child );
}

canonical_original_code:
static void to_rtree_node(struct rtree *rt, struct rtree_n *parent, struct rtree_n *child)
{
 if( parent->val )
 {
  struct rtree_n *nn = get_new_node( rt );
  nn->max_x = nn->min_x = parent->max_x;
  nn->max_y = nn->min_y = parent->max_y;
  nn->val = parent->val;
  nn->parent = parent;
  parent->val = 0l;
  parent->child = nn;
 }
 parent->max_x = ( child->max_x > parent->max_x ) ? child->max_x : parent->max_x;
 parent->max_y = ( child->max_y > parent->max_y ) ? child->max_y : parent->max_y;
 parent->min_x = ( child->min_x < parent->min_x ) ? child->min_x : parent->min_x;
 parent->min_y = ( child->min_y < parent->min_y ) ? child->min_y : parent->min_y;
 float min_dS;
 struct rtree_n *best_child = parent->child;
 int i;
 struct rtree_n *tnod = parent->child;
 for( i = 0; i < (4); i++ )
 {
  if( !tnod )
  {
   child->sister = parent->child;
   parent->child = child;
   child->parent = parent;
   return;
  }
  float max_x = ( child->max_x > tnod->max_x ) ? child->max_x : tnod->max_x;
  float max_y = ( child->max_y > tnod->max_y ) ? child->max_y : tnod->max_y;
  float min_x = ( child->min_x < tnod->min_x ) ? child->min_x : tnod->min_x;
  float min_y = ( child->min_y < tnod->min_y ) ? child->min_y : tnod->min_y;
  float dS = ( max_x - min_x ) * ( max_y - min_y );
  dS -= ( tnod->max_x - tnod->min_x ) * ( tnod->max_y - tnod->min_y );
  min_dS = !i ? dS : min_dS;
  if( min_dS > dS )
  {
   min_dS = dS;
   best_child = tnod;
  }
  tnod = tnod->sister;
 }
 to_rtree_node( rt, best_child, child );
}

variable_types: struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *

variable_types:
parent
struct rtree_n *

variable_types:
child
struct rtree_n *

variable_types: i int

variable_types: dS float


decompiled_code:
int __fastcall print_node(__int64 a1)
{
const void *v1; // rsi
__int64 v2; // rbx
int result; // eax
__int64 i; // rbx

v1 = *(const void **)(a1 + 16);
v2 = a1;
if ( v1 )
{
while ( 1 )
{
printf(
"(x:%0.2f..%0.2f y:%0.2f..%0.2f)[%p] -> ",
*(float *)(v2 + 4),
*(float *)v2,
*(float *)(v2 + 12),
*(float *)(v2 + 8),
v1);
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
break;
v1 = *(const void **)(v2 + 16);
}
result = putchar(10);
}
else
{
for ( i = *(_QWORD *)(a1 + 32); i; i = *(_QWORD *)(i + 40) )
result = print_node(i);
}
return result;
}

original_code:
static void print_node( rtree_n * n )
{
 if( n->val )
 {
  rtree_n * show = n;
  while( show )
  {
   printf( "(x:%0.2f..%0.2f y:%0.2f..%0.2f)[%p] -> ", show->min_x,
    show->max_x, show->min_y, show->max_y, show->val );
   show = show->parent;
  }
  printf( "\n" );
  return;
 }
 rtree_n * cur_n = n->child;;
 while( cur_n )
 {
  print_node( cur_n );
  cur_n = cur_n->sister;
 }
}

canonical_original_code:
static void print_node(struct rtree_n *n)
{
 if( n->val )
 {
  struct rtree_n *show = n;
  while( show )
  {
   printf( "(x:%0.2f..%0.2f y:%0.2f..%0.2f)[%p] -> ", show->min_x,
    show->max_x, show->min_y, show->max_y, show->val );
   show = show->parent;
  }
  printf( "\n" );
  return;
 }
 struct rtree_n *cur_n = n->child;;
 while( cur_n )
 {
  print_node( cur_n );
  cur_n = cur_n->sister;
 }
}


decompiled_code:
_DWORD *new_rtree()
{
_DWORD *result; // rax

result = calloc(0x3A9A0uLL, 1uLL);
if ( !result )
__assert_fail(assertion, "rtree.c", 0xCu, "new_rtree");
result[60007] = 1;
*((_QWORD *)result + 30002) = result + 2;
return result;
}

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

result = calloc(0x3A9A0uLL, 1uLL);
if ( !result )
__assert_fail(assertion, "rtree.c", 0xCu, "new_rtree");
result[60007] = 1;
*((_QWORD *)result + 30002) = result + 2;
return result;
}

original_code:
rtree * new_rtree( void )
{
 rtree * new = ( rtree * )malloc( sizeof( struct rtree ) );
 ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "rtree.c", 12, __extension__ __PRETTY_FUNCTION__); }));
 memset( new, 0, sizeof( struct rtree ) );
 new->cur_blk = &( new->first_blk );
 new->not_del_cnt++;
 return new;
}

canonical_original_code:
struct rtree *new_rtree()
{
 struct rtree *new = ( rtree * )malloc( sizeof( struct rtree ) );
 ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "rtree.c", 12, __extension__ __PRETTY_FUNCTION__); }));
 memset( new, 0, sizeof( struct rtree ) );
 new->cur_blk = &( new->first_blk );
 new->not_del_cnt++;
 return new;
}

return_type: struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *


decompiled_code:
void __fastcall del_rtree(void *ptr)
{
_QWORD *v3; // rbx
void *v4; // rdi

if ( (*((_DWORD *)ptr + 60007))-- == 1 )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 30001);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[30000];
free(v4);
}
free(ptr);
}
}

original_code:
void del_rtree( rtree * rt )
{
 rt->not_del_cnt--;
 if( rt->not_del_cnt )return;
 rtree_nblk * ct = rt->first_blk.next;
 while( ct )
 {
  rtree_nblk * kill = ct;
  ct = ct->next;
  free( kill );
 }
 free( rt );
}

canonical_original_code:
void del_rtree(struct rtree *rt)
{
 rt->not_del_cnt--;
 if( rt->not_del_cnt )return;
 struct rtree_nblk *ct = rt->first_blk.next;
 while( ct )
 {
  struct rtree_nblk *kill = ct;
  ct = ct->next;
  free( kill );
 }
 free( rt );
}

variable_types: struct rtree_nblk { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } node[-1]; struct rtree_nblk *next; } *

user_defined_types: struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; }


decompiled_code:
void __fastcall not_del_rtree_pls(__int64 a1)
{
++*(_DWORD *)(a1 + 240028);
}

original_code:
void not_del_rtree_pls( rtree * rt )
{
 rt->not_del_cnt++;
}

canonical_original_code:
void not_del_rtree_pls(struct rtree *rt)
{
 rt->not_del_cnt++;
}


decompiled_code:
// attributes: thunk
void __fastcall thx_may_del_rtree(void *ptr)
{
del_rtree(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
func14(ptr);
}

original_code:
void thx_may_del_rtree( rtree * rt )
{
 del_rtree( rt );
}

canonical_original_code:
void thx_may_del_rtree(struct rtree *rt)
{
 del_rtree( rt );
}


decompiled_code:
float *__fastcall get_next_near(float *a1, float a2, float a3, float a4)
{
float *v4; // rsi
int v6; // ecx
__int64 v7; // rax
int v8; // ecx

v4 = a1;
v6 = 0;
if ( !a1 )
return 0LL;
do
{
if ( v6 )
{
v7 = get_right((__int64)a1);
v6 = ~v8;
a1 = (float *)v7;
if ( !v7 )
return 0LL;
}
else
{
a1 = get_down((__int64)a1, a2, a3, a4);
if ( !a1 )
return 0LL;
}
}
while ( !*((_QWORD *)a1 + 2) || a1 == v4 || !is_good_xy(a1, a2, a3, a4) );
return a1;
}

canonical_decompiled_code:
float *__fastcall func18(float *a1, float a2, float a3, float a4)
{
float *v4; // rsi
int v6; // ecx
__int64 v7; // rax
int v8; // ecx

v4 = a1;
v6 = 0;
if ( !a1 )
return 0LL;
do
{
if ( v6 )
{
v7 = func9((__int64)a1);
v6 = ~v8;
a1 = (float *)v7;
if ( !v7 )
return 0LL;
}
else
{
a1 = func8((__int64)a1, a2, a3, a4);
if ( !a1 )
return 0LL;
}
}
while ( !*((_QWORD *)a1 + 2) || a1 == v4 || !func7(a1, a2, a3, a4) );
return a1;
}

original_code:
rtree_n * get_next_near( rtree_n * cur_n, float x, float y, float delta )
{
 if( !cur_n ) return 0l;
 rtree_n * next = cur_n;
 int to_right = 0;
 while( 1 )
 {
  next = to_right ? get_right( next ) : get_down( next, x, y, delta );
  to_right = ~to_right;
  if( !next ) break;
  if( next->val && ( next != cur_n ) )
  {
   if( is_good_xy( next, x, y, delta ) ) break;
  }
 }
 return next;
}

canonical_original_code:
struct rtree_n *get_next_near(struct rtree_n *cur_n, float x, float y, float delta)
{
 if( !cur_n ) return 0l;
 struct rtree_n *next = cur_n;
 int to_right = 0;
 while( 1 )
 {
  next = to_right ? get_right( next ) : get_down( next, x, y, delta );
  to_right = ~to_right;
  if( !next ) break;
  if( next->val && ( next != cur_n ) )
  {
   if( is_good_xy( next, x, y, delta ) ) break;
  }
 }
 return next;
}

variable_types: x float

variable_types: y float


decompiled_code:
int __fastcall print_rtree(__int64 *a1)
{
return print_node(*a1);
}

canonical_decompiled_code:
int __fastcall func19(__int64 *a1)
{
return func12(*a1);
}

original_code:
void print_rtree( rtree * rt )
{
 print_node( rt->adam );
}

canonical_original_code:
void print_rtree(struct rtree *rt)
{
 print_node( rt->adam );
}


original_code:
static rtree_n * get_new_node( rtree * rt )
{
 rtree_n * rval = rt->cur_blk->node + rt->cur_cnt;
 rt->cur_cnt++;
 if( rt->cur_cnt == (5000) )
 {
  rt->cur_cnt = 0;
  rtree_nblk * new = ( rtree_nblk * )malloc( sizeof( rtree_nblk ) );
  ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "rtree.c", 56, __extension__ __PRETTY_FUNCTION__); }));
  memset( new, 0, sizeof( rtree_nblk ) );
  rt->cur_blk->next = new;
  rt->cur_blk = new;
 }
 return rval;
}

canonical_original_code:
static struct rtree_n *get_new_node(struct rtree *rt)
{
 struct rtree_n *rval = rt->cur_blk->node + rt->cur_cnt;
 rt->cur_cnt++;
 if( rt->cur_cnt == (5000) )
 {
  rt->cur_cnt = 0;
  struct rtree_nblk *new = ( rtree_nblk * )malloc( sizeof( rtree_nblk ) );
  ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "rtree.c", 56, __extension__ __PRETTY_FUNCTION__); }));
  memset( new, 0, sizeof( rtree_nblk ) );
  rt->cur_blk->next = new;
  rt->cur_blk = new;
 }
 return rval;
}

variable_types: struct rtree { struct rtree_n *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *


decompiled_code:
_QWORD *new_free_pixels()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
__int64 v2; // rax

v0 = calloc(0x18uLL, 1uLL);
if ( !v0 )
_assert_fail("new", "wd_free_pix.c", 0x10u, "new_free_pixels");
v1 = v0;
v2 = new_rtree();
v1[2] = v2;
if ( !v2 )
_assert_fail("new->tree", "wd_free_pix.c", 0x14u, "new_free_pixels");
return v1;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
__int64 v2; // rax

v0 = calloc(0x18uLL, 1uLL);
if ( !v0 )
_assert_fail("new", "wd_free_pix.c", 0x10u, "new_free_pixels");
v1 = v0;
v2 = new_rtree();
v1[2] = v2;
if ( !v2 )
_assert_fail("new->tree", "wd_free_pix.c", 0x14u, "new_free_pixels");
return v1;
}

original_code:
free_pixels * new_free_pixels( void )
{
 free_pixels * new = ( free_pixels * )malloc( sizeof( free_pixels ) );
 ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "wd_free_pix.c", 16, __extension__ __PRETTY_FUNCTION__); }));
 memset( new, 0, sizeof( free_pixels ) );
 new->tree = new_rtree();
 ((void) sizeof ((new->tree) ? 1 : 0), __extension__ ({ if (new->tree) ; else __assert_fail ("new->tree", "wd_free_pix.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 return new;
}

canonical_original_code:
struct free_pixels *new_free_pixels()
{
 struct free_pixels *new = ( free_pixels * )malloc( sizeof( free_pixels ) );
 ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "wd_free_pix.c", 16, __extension__ __PRETTY_FUNCTION__); }));
 memset( new, 0, sizeof( free_pixels ) );
 new->tree = new_rtree();
 ((void) sizeof ((new->tree) ? 1 : 0), __extension__ ({ if (new->tree) ; else __assert_fail ("new->tree", "wd_free_pix.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 return new;
}

variable_types: struct free_pixels { int pix_cnt; struct free_pix_blk { struct free_pix { float x; float red; float green; float blue; float angle; float state; } pix[100]; struct free_pix_blk *next; } *last_blk; struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *tree; } *


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

del_rtree(*((_QWORD *)ptr + 2));
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[350];
free(v3);
}
free(ptr);
}

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

del_rtree(*((_QWORD *)ptr + 2));
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[350];
free(v3);
}
free(ptr);
}

original_code:
void del_free_pixels( free_pixels * das )
{
 del_rtree( das->tree );
 free_pix_blk * cblk = das->last_blk;
 while( cblk )
 {
  free_pix_blk * kill_that = cblk;
  cblk = cblk->next;
  free( kill_that );
 }
 free( das );
}

canonical_original_code:
void del_free_pixels(struct free_pixels *das)
{
 del_rtree( das->tree );
 struct free_pix_blk *cblk = das->last_blk;
 while( cblk )
 {
  struct free_pix_blk *kill_that = cblk;
  cblk = cblk->next;
  free( kill_that );
 }
 free( das );
}

variable_types: struct free_pix_blk { struct free_pix { float x; float red; float green; float blue; float angle; float state; } pix[100]; struct free_pix_blk *next; } *


original_code:
void add_pixel( free_pixels * das, float x, float y,
                        float r, float g, float b, float angle )
{
 int b_in = das->pix_cnt % 100;
 if( !( b_in ) )
 {
  free_pix_blk * new = ( free_pix_blk * )malloc( sizeof( free_pix_blk ) );
  ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "wd_free_pix.c", 52, __extension__ __PRETTY_FUNCTION__); }));
  memset( new, 0, sizeof( free_pix_blk ) );
  new->next = das->last_blk;
  das->last_blk = new;
 }
 free_pix * pix = das->last_blk->pix + b_in;
 pix->red = r;
 pix->green = g;
 pix->blue = b;
 pix->angle = angle;
 pix->x = x;
 pix->y = y;
 to_rtree( das->tree, x, y, pix );
 das->pix_cnt++;
}

canonical_original_code:
void add_pixel(struct free_pixels *das, float x, float y, float r, float g, float b, float angle)
{
 int b_in = das->pix_cnt % 100;
 if( !( b_in ) )
 {
  struct free_pix_blk *new = ( free_pix_blk * )malloc( sizeof( free_pix_blk ) );
  ((void) sizeof ((new) ? 1 : 0), __extension__ ({ if (new) ; else __assert_fail ("new", "wd_free_pix.c", 52, __extension__ __PRETTY_FUNCTION__); }));
  memset( new, 0, sizeof( free_pix_blk ) );
  new->next = das->last_blk;
  das->last_blk = new;
 }
 struct free_pix *pix = das->last_blk->pix + b_in;
 pix->red = r;
 pix->green = g;
 pix->blue = b;
 pix->angle = angle;
 pix->x = x;
 pix->y = y;
 to_rtree( das->tree, x, y, pix );
 das->pix_cnt++;
}

variable_types: r float

variable_types: g float

variable_types: b float

variable_types: angle float

user_defined_types: struct free_pix { float x; float red; float green; float blue; float angle; float state; }


decompiled_code:
__int64 __fastcall find_next_pixel(__int64 a1, char *a2)
{
__int64 v3; // rdi
char *v4; // rbx
__int64 result; // rax
char v6; // [rsp+8h] [rbp-10h] BYREF

if ( a2 )
{
v3 = *(_QWORD *)a2;
v4 = a2;
if ( *(_QWORD *)a2 )
goto LABEL_3;
}
else
{
v4 = &v6;
}
v3 = **(_QWORD **)(a1 + 16);
LABEL_3:
*(_QWORD *)v4 = v3;
result = get_next_near();
*(_QWORD *)v4 = result;
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char *a2)
{
__int64 v3; // rdi
char *v4; // rbx
__int64 result; // rax
char v6; // [rsp+8h] [rbp-10h] BYREF

if ( a2 )
{
v3 = *(_QWORD *)a2;
v4 = a2;
if ( *(_QWORD *)a2 )
goto LABEL_3;
}
else
{
v4 = &v6;
}
v3 = **(_QWORD **)(a1 + 16);
LABEL_3:
*(_QWORD *)v4 = v3;
result = get_next_near();
*(_QWORD *)v4 = result;
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
free_pix * find_next_pixel( free_pixels * das, rtree_n ** search,
                                float x, float y, float delta )
{
 rtree_n * cn = 0l;
 search = !search ? &cn : search;
 *search = !( *search ) ? das->tree->adam : ( *search );
 *search = get_next_near( *search, x, y, delta );
 free_pix * rv = ( *search ) ? ( free_pix * )( *search )->val : 0l;
 return rv;
}

canonical_original_code:
struct free_pix *find_next_pixel(struct free_pixels *das, struct rtree_n **search, float x, float y, float delta)
{
 struct rtree_n *cn = 0l;
 search = !search ? &cn : search;
 *search = !( *search ) ? das->tree->adam : ( *search );
 *search = get_next_near( *search, x, y, delta );
 struct free_pix *rv = ( *search ) ? ( free_pix * )( *search )->val : 0l;
 return rv;
}

variable_types: struct free_pixels { int pix_cnt; struct free_pix_blk { struct free_pix pix[100]; struct free_pix_blk *next; } *last_blk; struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *tree; } *

variable_types:
search
struct rtree_n **

variable_types: struct free_pix { float x; float red; float green; float blue; float angle; float state; } *


original_code:
free_pix * booking_free_pix( free_pixels * das, float x, float y,
                        float delta, float r, float g, float b, int only_free )
{
 free_pix * select = 0l;
 float color_distance = 999.99;
 rtree_n * search = 0l;
 free_pix * pix;
 while( ( pix = find_next_pixel( das, &search, x, y, delta ) ) )
 {
  if( only_free && pix->state ) continue;
  float c_dist = sqrt( ( r - pix->red ) * ( r - pix->red ) +
   ( g - pix->green ) * ( g - pix->green ) +
   ( b - pix->blue ) * ( b - pix->blue ) );
  if( c_dist < color_distance )
  {
   color_distance = c_dist;
   select = pix;
  }
 }
 if( color_distance > 0.2 ) return 0l;
 return select;
}

canonical_original_code:
struct free_pix *booking_free_pix(struct free_pixels *das, float x, float y, float delta, float r, float g, float b, int only_free)
{
 struct free_pix *select = 0l;
 float color_distance = 999.99;
 struct rtree_n *search = 0l;
 struct free_pix *pix;
 while( ( pix = find_next_pixel( das, &search, x, y, delta ) ) )
 {
  if( only_free && pix->state ) continue;
  float c_dist = sqrt( ( r - pix->red ) * ( r - pix->red ) +
   ( g - pix->green ) * ( g - pix->green ) +
   ( b - pix->blue ) * ( b - pix->blue ) );
  if( c_dist < color_distance )
  {
   color_distance = c_dist;
   select = pix;
  }
 }
 if( color_distance > 0.2 ) return 0l;
 return select;
}

variable_types: delta float

variable_types: struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *

return_type: struct free_pix { float x; float red; float green; float blue; float angle; float state; } *


original_code:
int get_next_task( task * pt, ant * pa, wd_of_ants * wd )
{
 free_pix * bpix = 0l;
 if( !wd->free_pixs ) return -1;
 if( wd->plan.width * wd->plan.hight <= wd->plan.last_tasked ) return -1;
 pt->dst_pix = wd->plan.pixs + wd->plan.last_tasked;
 pt->dst_x = wd->plan.left_up_x
  + ( wd->plan.last_tasked % wd->plan.width ) * wd->plan.pix_side;
 pt->dst_y = wd->plan.left_up_y
  - ( wd->plan.last_tasked / wd->plan.width ) * wd->plan.pix_side - pa->nose_len;
 pt->dst_ang = 3.14159265358979323846/2.0;
 bpix = booking_free_pix( wd->free_pixs, 0.0, 0.0,
                   100.0 , pt->dst_pix->red, pt->dst_pix->green, pt->dst_pix->blue, 13 );
 if( !bpix ) return -1;
 pt->tg_x = bpix->x - cos( bpix->angle ) * pa->nose_len;
 pt->tg_y = bpix->y - sin( bpix->angle ) * pa->nose_len;
 pt->tg_ang = bpix->angle;
 pt->tg_r = bpix->red;
 pt->tg_g = bpix->green;
 pt->tg_b = bpix->blue;
 wd->plan.last_tasked++;
        return 0;
}

canonical_original_code:
int get_next_task(struct task *pt, struct ant *pa, struct wd_of_ants *wd)
{
 struct free_pix *bpix = 0l;
 if( !wd->free_pixs ) return -1;
 if( wd->plan.width * wd->plan.hight <= wd->plan.last_tasked ) return -1;
 pt->dst_pix = wd->plan.pixs + wd->plan.last_tasked;
 pt->dst_x = wd->plan.left_up_x
  + ( wd->plan.last_tasked % wd->plan.width ) * wd->plan.pix_side;
 pt->dst_y = wd->plan.left_up_y
  - ( wd->plan.last_tasked / wd->plan.width ) * wd->plan.pix_side - pa->nose_len;
 pt->dst_ang = 3.14159265358979323846/2.0;
 bpix = booking_free_pix( wd->free_pixs, 0.0, 0.0,
                   100.0 , pt->dst_pix->red, pt->dst_pix->green, pt->dst_pix->blue, 13 );
 if( !bpix ) return -1;
 pt->tg_x = bpix->x - cos( bpix->angle ) * pa->nose_len;
 pt->tg_y = bpix->y - sin( bpix->angle ) * pa->nose_len;
 pt->tg_ang = bpix->angle;
 pt->tg_r = bpix->red;
 pt->tg_g = bpix->green;
 pt->tg_b = bpix->blue;
 wd->plan.last_tasked++;
        return 0;
}

variable_types: struct task { float tg_r; float tg_g; float tg_b; float tg_x; float tg_y; float tg_ang; float dst_x; float dst_y; float dst_ang; struct pix { float red; float green; float blue; int state; } *dst_pix; } *

variable_types: struct ant { struct pix cpix; float pos_x; float pos_ang; float left_angle; float right_angle; float left_speed; float right_speed; float axis_len; float tire_radius; float nose_len; struct ant *next; } *

variable_types: struct wd_of_ants { struct rtree { struct rtree_n { float max_x; float min_x; float max_y; float min_y; void *val; struct rtree_n *parent; struct rtree_n *child; struct rtree_n *sister; } *adam; struct rtree_nblk { struct rtree_n node[-1]; struct rtree_nblk *next; } first_blk; struct rtree_nblk *cur_blk; int cur_cnt; int not_del_cnt; } *stub; struct ant *muvis; struct genplan { float left_up_x; float left_up_y; float pix_side; int width; int hight; struct pix *pixs; int last_tasked; } plan; struct free_pixels { int pix_cnt; struct free_pix_blk { struct free_pix { float x; float red; float green; float blue; float angle; float state; } pix[100]; struct free_pix_blk *next; } *last_blk; struct rtree *tree; } *free_pixs; struct free_pixels *free_pixs_4del; unsigned long sim_cnt; } *

user_defined_types: struct task { float tg_r; float tg_g; float tg_b; float tg_x; float tg_y; float tg_ang; float dst_x; float dst_y; float dst_ang; struct pix *dst_pix; }


original_code:
int reset_task( task * pt, ant * pa, wd_of_ants * wd )
{
 if( !wd->free_pixs ) return -1;
 free_pix * bpix = 0l;
 bpix = booking_free_pix( wd->free_pixs, pt->tg_x + cos( pt->tg_ang ) * pa->nose_len,
  pt->tg_y + sin( pt->tg_ang ) * pa->nose_len, 0.02 , pt->tg_r, pt->tg_g, pt->tg_b, 13 );
 if( bpix )
 {
  bpix->state++;
 }
 bpix = booking_free_pix( wd->free_pixs, 0.0, 0.0,
  100.0 , pt->dst_pix->red, pt->dst_pix->green, pt->dst_pix->blue, 13 );
 if( !bpix ) return -1;
 pt->tg_x = bpix->x - cos( bpix->angle ) * pa->nose_len;
 pt->tg_y = bpix->y - sin( bpix->angle ) * pa->nose_len;
 pt->tg_ang = bpix->angle;
 pt->tg_r = bpix->red;
 pt->tg_g = bpix->green;
 pt->tg_b = bpix->blue;
 return 0;
}

canonical_original_code:
int reset_task(struct task *pt, struct ant *pa, struct wd_of_ants *wd)
{
 if( !wd->free_pixs ) return -1;
 struct free_pix *bpix = 0l;
 bpix = booking_free_pix( wd->free_pixs, pt->tg_x + cos( pt->tg_ang ) * pa->nose_len,
  pt->tg_y + sin( pt->tg_ang ) * pa->nose_len, 0.02 , pt->tg_r, pt->tg_g, pt->tg_b, 13 );
 if( bpix )
 {
  bpix->state++;
 }
 bpix = booking_free_pix( wd->free_pixs, 0.0, 0.0,
  100.0 , pt->dst_pix->red, pt->dst_pix->green, pt->dst_pix->blue, 13 );
 if( !bpix ) return -1;
 pt->tg_x = bpix->x - cos( bpix->angle ) * pa->nose_len;
 pt->tg_y = bpix->y - sin( bpix->angle ) * pa->nose_len;
 pt->tg_ang = bpix->angle;
 pt->tg_r = bpix->red;
 pt->tg_g = bpix->green;
 pt->tg_b = bpix->blue;
 return 0;
}

user_defined_types: struct genplan { float left_up_x; float left_up_y; float pix_side; int width; int hight; struct pix *pixs; int last_tasked; }


die

repo: sanbeg/fisher-price-keyboard

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void die(const char * msg)
{
  perror(msg);
  exit(1);
}

canonical_original_code:
void die(char *msg)
{
  perror(msg);
  exit(1);
}

variable_types:
msg
char *


decompiled_code:
int print_nodelist_to_file()
{
_QWORD *v0; // rbx
FILE *v1; // rax
FILE *i; // rdi

v0 = head;
v1 = fopen("S_malloc_logs.txt", "w");
fptr = v1;
if ( !v1 )
{
puts("\nFailure: Cannot Open Log-File for Writing\n");
exit(1);
}
for ( i = v1; v0; i = fptr )
{
fprintf(i, "\nHeap Memory Address: %ld, Size = %d Bytes\n", *v0, *((unsigned int *)v0 + 2));
v0 = (_QWORD *)v0[2];
}
return fclose(i);
}

canonical_decompiled_code:
int func0()
{
_QWORD *v0; // rbx
FILE *v1; // rax
FILE *i; // rdi

v0 = head;
v1 = fopen("S_malloc_logs.txt", "w");
fptr = v1;
if ( !v1 )
{
puts("\nFailure: Cannot Open Log-File for Writing\n");
exit(1);
}
for ( i = v1; v0; i = fptr )
{
fprintf(i, "\nHeap Memory Address: %ld, Size = %d Bytes\n", *v0, *((unsigned int *)v0 + 2));
v0 = (_QWORD *)v0[2];
}
return fclose(i);
}

original_code:
void print_nodelist_to_file ()
{
 ListNode *temp = head;
 fptr = fopen ("S_malloc_logs.txt", "w");
 if (((void *)0)==fptr)
 {
  printf ("\nFailure: Cannot Open Log-File for Writing\n\n");
  exit (1);
 }
 while (temp)
 {
  fprintf (fptr, "\nHeap Memory Address: %ld, Size = %d Bytes\n", (long)temp->memaddress, temp->memsize);
  temp = temp->next;
 }
 fclose (fptr);
}

canonical_original_code:
void print_nodelist_to_file()
{
 struct node *temp = head;
 fptr = fopen ("S_malloc_logs.txt", "w");
 if (((void *)0)==fptr)
 {
  printf ("\nFailure: Cannot Open Log-File for Writing\n\n");
  exit (1);
 }
 while (temp)
 {
  fprintf (fptr, "\nHeap Memory Address: %ld, Size = %d Bytes\n", (long)temp->memaddress, temp->memsize);
  temp = temp->next;
 }
 fclose (fptr);
}

variable_types: struct node { void *memaddress; int memsize; struct node *next; } *


decompiled_code:
int __fastcall add_allocated_node(__int64 a1, int a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
_DWORD *v4; // rax
_QWORD *v5; // rax

v2 = head;
if ( head )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
}
while ( v2 );
v4 = malloc(0x18uLL);
v3[2] = v4;
if ( !v4 )
{
puts("\nMemory Allocation Failure !");
exit(1);
}
v4[2] = a2;
*(_QWORD *)v4 = a1;
*((_QWORD *)v4 + 2) = 0LL;
}
else
{
v5 = malloc(0x18uLL);
head = v5;
*((_DWORD *)v5 + 2) = a2;
*v5 = a1;
v5[2] = 0LL;
}
return print_nodelist_to_file();
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
_DWORD *v4; // rax
_QWORD *v5; // rax

v2 = head;
if ( head )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
}
while ( v2 );
v4 = malloc(0x18uLL);
v3[2] = v4;
if ( !v4 )
{
puts("\nMemory Allocation Failure !");
exit(1);
}
v4[2] = a2;
*(_QWORD *)v4 = a1;
*((_QWORD *)v4 + 2) = 0LL;
}
else
{
v5 = malloc(0x18uLL);
head = v5;
*((_DWORD *)v5 + 2) = a2;
*v5 = a1;
v5[2] = 0LL;
}
return func0();
}

original_code:
void add_allocated_node (void *address, int size)
{
 ListNode *temp = ((void *)0);
 if (((void *)0)==head)
 {
   head = malloc(sizeof(ListNode));
  (head)->memsize = size;
  (head)->memaddress = address;
  (head)->next = ((void *)0);
 }
 else
 {
  temp = head;
  while (temp->next!=((void *)0))
  {
   temp=temp->next;
  }
  temp->next = malloc(sizeof(ListNode));
  if (temp->next == ((void *)0))
  {
   printf ("\nMemory Allocation Failure !\n");
   exit (1);
  }
  (temp->next)->memsize = size;
  (temp->next)->memaddress = address;
  (temp->next)->next = ((void *)0);
 }
 print_nodelist_to_file ();
}

canonical_original_code:
void add_allocated_node(void *address, int size)
{
 struct node *temp = ((void *)0);
 if (((void *)0)==head)
 {
   head = malloc(sizeof(ListNode));
  (head)->memsize = size;
  (head)->memaddress = address;
  (head)->next = ((void *)0);
 }
 else
 {
  temp = head;
  while (temp->next!=((void *)0))
  {
   temp=temp->next;
  }
  temp->next = malloc(sizeof(ListNode));
  if (temp->next == ((void *)0))
  {
   printf ("\nMemory Allocation Failure !\n");
   exit (1);
  }
  (temp->next)->memsize = size;
  (temp->next)->memaddress = address;
  (temp->next)->next = ((void *)0);
 }
 print_nodelist_to_file ();
}

variable_types:
address
void *

variable_types: size int

user_defined_types: struct node { void *memaddress; int memsize; struct node *next; }