decompiled_code:
void *__fastcall print_prime_factors_wrapper(void *a1)
{
print_prime_factors(*(_DWORD *)a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
func6(*(_DWORD *)a1);
return 0LL;
}

original_code:
void * print_prime_factors_wrapper(void *i) {
 unsigned *p = (unsigned*) i;
 print_prime_factors(*p);
 return (void*)((void *)0);
}

canonical_original_code:
void *print_prime_factors_wrapper(void *i) {
 unsigned int *p = (unsigned*) i;
 print_prime_factors(*p);
 return (void *)((void *)0);
}

variable_types:
i
void *

variable_types:
p
unsigned int *


repo: tdubourg/TPThread

original_code:
unsigned get_prime_factors(unsigned n, unsigned* factors) {
 t_el* already;
 unsigned index = 0;
 unsigned pas_i = 4;
 unsigned lastone = 0;
 unsigned n_prev = n;
 unsigned char first_loop = 1;
 while (n > 1) {
  if (!first_loop && ((n) < 64000 && (n) > 8)) {
   already = rechercher( n);
   if (already != ((void *)0)) {
    unsigned index2 = 0;
    for (index2 = 0; index2 < already->val_size; index2++) {
     factors[index++] = already->valeur[index2];
    }
    if(((n_prev) < 64000 && (n_prev) > 8)) {
     t_element* factors_cpy = (t_element*) malloc(sizeof (t_element) * (index));
     memcpy(factors_cpy, factors, sizeof (t_element) * (index));
     pthread_mutex_lock(&mid2);
     inserer( n_prev, factors_cpy, index);
     pthread_mutex_unlock(&mid2);
    }
    return index;
   }
  }
  first_loop = 0;
  if (!lastone) {
   if (!(n % 2)) {
    factors[index++] = 2;
    factors[index] = (-42);
    n_prev = n;
    n /= 2;
    continue;
   } else if (!(n % 3)) {
    factors[index++] = 3;
    factors[index] = (-42);
    n_prev = n;
    n /= 3;
    continue;
   } else if (!(n % 5)) {
    factors[index++] = 5;
    factors[index] = (-42);
    n_prev = n;
    n /= 5;
    continue;
   } else {
    lastone = 3;
   }
  }
  unsigned i;
  n_prev = n;
  for (i = lastone + pas_i; (i*i) <= n;) {
   if (!(n % i)) {
    factors[index++] = i;
    n_prev = n;
    n /= i;
    already = rechercher( n);
    if (already != ((void *)0)) {
     unsigned index2 = 0;
     for (index2 = 0; index2 < already->val_size; index2++) {
      factors[index++] = already->valeur[index2];
     }
     if(((n_prev) < 64000 && (n_prev) > 8)) {
      t_element* factors_cpy = (t_element*) malloc(sizeof (t_element) * (index + 1));
      memcpy(factors_cpy, factors, sizeof (t_element) * (index + 1));
      pthread_mutex_lock(&mid2);
      inserer( n_prev, factors_cpy, index + 1);
      pthread_mutex_unlock(&mid2);
     }
     return index;
    }
   } else {
    i += pas_i;
    pas_i = 6 - pas_i;
   }
  }
  if((i*i) >= n && n != 1) {
   factors[index++] = n;
  }
  break;
 }
 int memo;
 int curr = factors[0];
 for (memo = 1; memo < index; memo++) {
  curr *= factors[memo];
  if(((curr) < 64000 && (curr) > 8)) {
   t_element* factors_cpy = (t_element*) malloc(sizeof (t_element) * (memo + 1));
   memcpy(factors_cpy, factors, sizeof (t_element) * (memo + 1));
   pthread_mutex_lock(&mid2);
   inserer( curr, factors_cpy, memo + 1);
   pthread_mutex_unlock(&mid2);
  }
 }
 return index;
}

canonical_original_code:
unsigned int get_prime_factors(unsigned int n, unsigned int *factors) {
 struct t_table_el *already;
 unsigned int index = 0;
 unsigned int pas_i = 4;
 unsigned int lastone = 0;
 unsigned int n_prev = n;
 unsigned char first_loop = 1;
 while (n > 1) {
  if (!first_loop && ((n) < 64000 && (n) > 8)) {
   already = rechercher( n);
   if (already != ((void *)0)) {
    unsigned int index2 = 0;
    for (index2 = 0; index2 < already->val_size; index2++) {
     factors[index++] = already->valeur[index2];
    }
    if(((n_prev) < 64000 && (n_prev) > 8)) {
     unsigned int *factors_cpy = (t_element*) malloc(sizeof (t_element) * (index));
     memcpy(factors_cpy, factors, sizeof (t_element) * (index));
     pthread_mutex_lock(&mid2);
     inserer( n_prev, factors_cpy, index);
     pthread_mutex_unlock(&mid2);
    }
    return index;
   }
  }
  first_loop = 0;
  if (!lastone) {
   if (!(n % 2)) {
    factors[index++] = 2;
    factors[index] = (-42);
    n_prev = n;
    n /= 2;
    continue;
   } else if (!(n % 3)) {
    factors[index++] = 3;
    factors[index] = (-42);
    n_prev = n;
    n /= 3;
    continue;
   } else if (!(n % 5)) {
    factors[index++] = 5;
    factors[index] = (-42);
    n_prev = n;
    n /= 5;
    continue;
   } else {
    lastone = 3;
   }
  }
  unsigned int i;
  n_prev = n;
  for (i = lastone + pas_i; (i*i) <= n;) {
   if (!(n % i)) {
    factors[index++] = i;
    n_prev = n;
    n /= i;
    already = rechercher( n);
    if (already != ((void *)0)) {
     unsigned int index2 = 0;
     for (index2 = 0; index2 < already->val_size; index2++) {
      factors[index++] = already->valeur[index2];
     }
     if(((n_prev) < 64000 && (n_prev) > 8)) {
      unsigned int *factors_cpy = (t_element*) malloc(sizeof (t_element) * (index + 1));
      memcpy(factors_cpy, factors, sizeof (t_element) * (index + 1));
      pthread_mutex_lock(&mid2);
      inserer( n_prev, factors_cpy, index + 1);
      pthread_mutex_unlock(&mid2);
     }
     return index;
    }
   } else {
    i += pas_i;
    pas_i = 6 - pas_i;
   }
  }
  if((i*i) >= n && n != 1) {
   factors[index++] = n;
  }
  break;
 }
 int memo;
 int curr = factors[0];
 for (memo = 1; memo < index; memo++) {
  curr *= factors[memo];
  if(((curr) < 64000 && (curr) > 8)) {
   unsigned int *factors_cpy = (t_element*) malloc(sizeof (t_element) * (memo + 1));
   memcpy(factors_cpy, factors, sizeof (t_element) * (memo + 1));
   pthread_mutex_lock(&mid2);
   inserer( curr, factors_cpy, memo + 1);
   pthread_mutex_unlock(&mid2);
  }
 }
 return index;
}

variable_types:
n
unsigned int

variable_types:
factors
unsigned int *

variable_types: struct t_table_el { int cle; unsigned int *valeur; unsigned int val_size; } *

variable_types:
index
unsigned int

variable_types:
lastone
unsigned int

variable_types:
i
unsigned int

variable_types: memo int

variable_types: curr int

return_type: unsigned int


decompiled_code:
int __fastcall print_prime_factorsMemoized(unsigned int a1)
{
int v1; // er12
unsigned int *v2; // rbx
__int64 v3; // rsi
unsigned int v5[38]; // [rsp+0h] [rbp-98h] BYREF

v1 = get_prime_factors(a1, v5);
pthread_mutex_lock(&m_screen);
printf("%u: ", a1);
if ( v1 > 0 )
{
v2 = v5;
do
{
v3 = *v2++;
printf("%u ", v3);
}
while ( v2 != &v5[v1 - 1 + 1] );
}
putchar(10);
return pthread_mutex_unlock(&m_screen);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
int v1; // er12
unsigned int *v2; // rbx
__int64 v3; // rsi
unsigned int v5[38]; // [rsp+0h] [rbp-98h] BYREF

v1 = func9(a1, v5);
pthread_mutex_lock(&m_screen);
printf("%u: ", a1);
if ( v1 > 0 )
{
v2 = v5;
do
{
v3 = *v2++;
printf("%u ", v3);
}
while ( v2 != &v5[v1 - 1 + 1] );
}
putchar(10);
return pthread_mutex_unlock(&m_screen);
}

original_code:
void print_prime_factorsMemoized(unsigned n) {
 int j, k;
 unsigned factors[30];
 k = get_prime_factors(n, factors);
 pthread_mutex_lock(&m_screen);
 printf("%u: ", n);
 for (j = 0; j < k; j++) {
  printf("%u ", factors[j]);
 }
 printf("\n");
 pthread_mutex_unlock(&m_screen);
}

canonical_original_code:
void print_prime_factorsMemoized(unsigned int n) {
 int j; int k;
 unsigned int factors[30];
 k = get_prime_factors(n, factors);
 pthread_mutex_lock(&m_screen);
 printf("%u: ", n);
 for (j = 0; j < k; j++) {
  printf("%u ", factors[j]);
 }
 printf("\n");
 pthread_mutex_unlock(&m_screen);
}

variable_types: j int

variable_types: k int

variable_types:
factors
unsigned int [30]

return_type: void


decompiled_code:
void *__fastcall readMyFileFromMemorySynced_And_Memoized(void *a1)
{
unsigned int v1; // eax
int v2; // er12
char *v3; // rax
const char *v4; // rbp

while ( 1 )
{
pthread_mutex_lock(&mid);
v2 = shift_pos;
v3 = strtok((char *)a1 + (unsigned int)shift_pos, "\n");
v4 = v3;
if ( !v3 )
break;
shift_pos = v2 + strlen(v3) + 1;
pthread_mutex_unlock(&mid);
v1 = atol(v4);
print_prime_factorsMemoized(v1);
}
pthread_mutex_unlock(&mid);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func11(void *a1)
{
unsigned int v1; // eax
int v2; // er12
char *v3; // rax
const char *v4; // rbp

while ( 1 )
{
pthread_mutex_lock(&mid);
v2 = shift_pos;
v3 = strtok((char *)a1 + (unsigned int)shift_pos, "\n");
v4 = v3;
if ( !v3 )
break;
shift_pos = v2 + strlen(v3) + 1;
pthread_mutex_unlock(&mid);
v1 = atol(v4);
func10(v1);
}
pthread_mutex_unlock(&mid);
return 0LL;
}

original_code:
void *readMyFileFromMemorySynced_And_Memoized(void* aF) {
 char* buffer;
 char* file_in_memory = (char*) aF;
 for (;;) {
  pthread_mutex_lock(&mid);
  buffer = strtok(file_in_memory+shift_pos, "\n");
  if (buffer == ((void *)0)) {
   pthread_mutex_unlock(&mid);
   return (void*)((void *)0);
  }
  shift_pos += strlen(buffer)+1;
  pthread_mutex_unlock(&mid);
  unsigned tmp = (unsigned) atol(buffer);
  print_prime_factorsMemoized(tmp);
 }
 pthread_exit((void*)((void *)0));
 return (void*)((void *)0);
}

canonical_original_code:
void *readMyFileFromMemorySynced_And_Memoized(void *aF) {
 char *buffer;
 char *file_in_memory = (char*) aF;
 for (;;) {
  pthread_mutex_lock(&mid);
  buffer = strtok(file_in_memory+shift_pos, "\n");
  if (buffer == ((void *)0)) {
   pthread_mutex_unlock(&mid);
   return (void *)((void *)0);
  }
  shift_pos += strlen(buffer)+1;
  pthread_mutex_unlock(&mid);
  unsigned int tmp = (unsigned) atol(buffer);
  print_prime_factorsMemoized(tmp);
 }
 pthread_exit((void *)((void *)0));
 return (void *)((void *)0);
}

variable_types:
aF
void *

variable_types:
buffer
char *

variable_types:
tmp
unsigned int

return_type: void *


testIsPrime

decompiled_code:
__int64 __fastcall testIsPrime(int a1)
{
unsigned int v2; // ebp

if ( !(unsigned int)is_prime(1u)
|| !(unsigned int)is_prime(2u)
|| !(unsigned int)is_prime(3u)
|| !(unsigned int)is_prime(5u)
|| !(unsigned int)is_prime(7u)
|| !(unsigned int)is_prime(1u)
|| !(unsigned int)is_prime(0xBu)
|| !(unsigned int)is_prime(0xDu) )
{
return 0LL;
}
v2 = 16;
if ( a1 > 16 )
{
do
{
if ( (unsigned int)is_prime(v2) )
printf("%u est premier\n", v2);
else
printf("%u est PAS premier\n", v2);
++v2;
}
while ( a1 != v2 );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
unsigned int v2; // ebp

if ( !(unsigned int)func5(1u)
|| !(unsigned int)func5(2u)
|| !(unsigned int)func5(3u)
|| !(unsigned int)func5(5u)
|| !(unsigned int)func5(7u)
|| !(unsigned int)func5(1u)
|| !(unsigned int)func5(0xBu)
|| !(unsigned int)func5(0xDu) )
{
return 0LL;
}
v2 = 16;
if ( a1 > 16 )
{
do
{
if ( (unsigned int)func5(v2) )
printf("%u est premier\n", v2);
else
printf("%u est PAS premier\n", v2);
++v2;
}
while ( a1 != v2 );
}
return 1LL;
}

original_code:
int testIsPrime(int max) {
 if (!is_prime(1)) {
  return 0;
 }
 if (!is_prime(2)) {
  return 0;
 }
 if (!is_prime(3)) {
  return 0;
 }
 if (!is_prime(5)) {
  return 0;
 }
 if (!is_prime(7)) {
  return 0;
 }
 if (!is_prime(1)) {
  return 0;
 }
 if (!is_prime(11)) {
  return 0;
 }
 if (!is_prime(13)) {
  return 0;
 }
 int i;
 for (i = 16; i < max; i++) {
  if (is_prime(i)) {
   printf("%u est premier\n", i);
  } else {
   printf("%u est PAS premier\n", i);
  }
 }
 return 1;
}

variable_types: max int

variable_types: i int

return_type: int


testPrintPrimeFactors

decompiled_code:
__int64 testPrintPrimeFactors()
{
putchar(10);
print_prime_factors(0x54u);
print_prime_factors(0x8Au);
return 1LL;
}

canonical_decompiled_code:
__int64 func18()
{
putchar(10);
func6(0x54u);
func6(0x8Au);
return 1LL;
}

original_code:
int testPrintPrimeFactors() {
 printf("\n");
 print_prime_factors(84);
 print_prime_factors(138);
 return 1;
}


decompiled_code:
int write_log()
{
printf("\nDPD Monte Carlo Simulation Program");
puts("\n");
printf("n_mon \t\t\t%10d\n", *((unsigned int *)&sys + 17));
printf("density_s \t\t\t%10.5lf\n", *((double *)&sys + 17));
printf("n_solvent \t\t\t%10d\n", *((unsigned int *)&sys + 19));
printf("calc_list \t\t\t%10d\n\n", *((unsigned int *)&sys + 1));
printf("length_x \t\t\t%10.5lf\n", *((double *)&sys + 42));
printf("length_y \t\t\t%10.5lf\n", *((double *)&sys + 43));
printf("length_z \t\t\t%10.5lf\n", *((double *)&sys + 44));
printf("volume \t\t\t%10.5lf\n\n", *((double *)&sys + 35));
printf("density_w \t\t\t%10.5lf\n", *((double *)&sys + 18));
printf("n_layers \t\t\t%10d\n", *((unsigned int *)&sys + 16));
printf("r_wall \t\t\t%10.5lf\n", *((double *)&sys + 32));
printf("n_wall \t\t\t%10d\n", *((unsigned int *)&sys + 22));
printf("wall_volume \t\t\t%10.5lf\n\n", *((double *)&sys + 36));
printf("pore_radius \t\t\t%10.5lf\n", *((double *)&sys + 26));
printf("r_pore \t\t\t%10.5lf\n", *((double *)&sys + 31));
printf("n_pore \t\t\t%10d\n", *((unsigned int *)&sys + 18));
printf("pore_volume \t\t\t%10.5lf\n\n", *((double *)&sys + 27));
printf("r_c \t\t\t%10.5lf\n", *((double *)&sys + 28));
printf("dr_max_dpd \t\t\t%10.5lf\n", *((double *)&sys + 19));
printf("dr_max_mon \t\t\t%10.5lf\n\n", *((double *)&sys + 20));
printf("a_mm \t\t\t%10.5lf\n", *((double *)&sys + 13));
printf("a_ms \t\t\t%10.5lf\n", *((double *)&sys + 14));
printf("a_ss \t\t\t%10.5lf\n", *((double *)&sys + 15));
printf("a_sw \t\t\t%10.5lf\n\n", *((double *)&sys + 16));
printf("pol_init_z \t\t\t%10.5lf\n", *((double *)&sys + 25));
printf("pol_init_bl \t\t\t%10.5lf\n\n", *((double *)&sys + 24));
printf("nsteps \t\t\t%10d\n", *((unsigned int *)&sys + 21));
printf("mc_ratio \t\t\t%10.5lf\n", *((double *)&sys + 23));
printf("temp \t\t\t%10.5lf\n", *((double *)&sys + 34));
printf("freq_sample \t\t\t%10d\n", *((unsigned int *)&sys + 3));
printf("freq_monitor\t\t\t%10d\n\n", *((unsigned int *)&sys + 2));
printf("iseed \t\t\t%10d\n", *((unsigned int *)&sys + 4));
return puts("\n");
}

canonical_decompiled_code:
int func1()
{
printf("\nDPD Monte Carlo Simulation Program");
puts("\n");
printf("n_mon \t\t\t%10d\n", *((unsigned int *)&sys + 17));
printf("density_s \t\t\t%10.5lf\n", *((double *)&sys + 17));
printf("n_solvent \t\t\t%10d\n", *((unsigned int *)&sys + 19));
printf("calc_list \t\t\t%10d\n\n", *((unsigned int *)&sys + 1));
printf("length_x \t\t\t%10.5lf\n", *((double *)&sys + 42));
printf("length_y \t\t\t%10.5lf\n", *((double *)&sys + 43));
printf("length_z \t\t\t%10.5lf\n", *((double *)&sys + 44));
printf("volume \t\t\t%10.5lf\n\n", *((double *)&sys + 35));
printf("density_w \t\t\t%10.5lf\n", *((double *)&sys + 18));
printf("n_layers \t\t\t%10d\n", *((unsigned int *)&sys + 16));
printf("r_wall \t\t\t%10.5lf\n", *((double *)&sys + 32));
printf("n_wall \t\t\t%10d\n", *((unsigned int *)&sys + 22));
printf("wall_volume \t\t\t%10.5lf\n\n", *((double *)&sys + 36));
printf("pore_radius \t\t\t%10.5lf\n", *((double *)&sys + 26));
printf("r_pore \t\t\t%10.5lf\n", *((double *)&sys + 31));
printf("n_pore \t\t\t%10d\n", *((unsigned int *)&sys + 18));
printf("pore_volume \t\t\t%10.5lf\n\n", *((double *)&sys + 27));
printf("r_c \t\t\t%10.5lf\n", *((double *)&sys + 28));
printf("dr_max_dpd \t\t\t%10.5lf\n", *((double *)&sys + 19));
printf("dr_max_mon \t\t\t%10.5lf\n\n", *((double *)&sys + 20));
printf("a_mm \t\t\t%10.5lf\n", *((double *)&sys + 13));
printf("a_ms \t\t\t%10.5lf\n", *((double *)&sys + 14));
printf("a_ss \t\t\t%10.5lf\n", *((double *)&sys + 15));
printf("a_sw \t\t\t%10.5lf\n\n", *((double *)&sys + 16));
printf("pol_init_z \t\t\t%10.5lf\n", *((double *)&sys + 25));
printf("pol_init_bl \t\t\t%10.5lf\n\n", *((double *)&sys + 24));
printf("nsteps \t\t\t%10d\n", *((unsigned int *)&sys + 21));
printf("mc_ratio \t\t\t%10.5lf\n", *((double *)&sys + 23));
printf("temp \t\t\t%10.5lf\n", *((double *)&sys + 34));
printf("freq_sample \t\t\t%10d\n", *((unsigned int *)&sys + 3));
printf("freq_monitor\t\t\t%10d\n\n", *((unsigned int *)&sys + 2));
printf("iseed \t\t\t%10d\n", *((unsigned int *)&sys + 4));
return puts("\n");
}

original_code:
void write_log(void) {
  printf("\nDPD Monte Carlo Simulation Program");
  printf("\n\n");
  printf("n_mon       \t\t\t%10d\n", sys.n_mon);
  printf("density_s   \t\t\t%10.5lf\n", sys.density_s);
  printf("n_solvent   \t\t\t%10d\n", sys.n_solvent);
  printf("calc_list   \t\t\t%10d\n\n", sys.calc_list);
  printf("length_x    \t\t\t%10.5lf\n", sys.length.x);
  printf("length_y    \t\t\t%10.5lf\n", sys.length.y);
  printf("length_z    \t\t\t%10.5lf\n", sys.length.z);
  printf("volume      \t\t\t%10.5lf\n\n", sys.volume);
  printf("density_w   \t\t\t%10.5lf\n", sys.density_w);
  printf("n_layers    \t\t\t%10d\n", sys.n_layers);
  printf("r_wall      \t\t\t%10.5lf\n", sys.r_wall);
  printf("n_wall      \t\t\t%10d\n", sys.n_wall);
  printf("wall_volume \t\t\t%10.5lf\n\n", sys.wall_volume);
  printf("pore_radius \t\t\t%10.5lf\n", sys.pore_radius);
  printf("r_pore      \t\t\t%10.5lf\n", sys.r_pore);
  printf("n_pore      \t\t\t%10d\n", sys.n_pore);
  printf("pore_volume \t\t\t%10.5lf\n\n", sys.pore_volume);
  printf("r_c         \t\t\t%10.5lf\n", sys.r_c);
  printf("dr_max_dpd  \t\t\t%10.5lf\n", sys.dr_max_dpd);
  printf("dr_max_mon  \t\t\t%10.5lf\n\n", sys.dr_max_mon);
  printf("a_mm        \t\t\t%10.5lf\n", sys.a_mm);
  printf("a_ms        \t\t\t%10.5lf\n", sys.a_ms);
  printf("a_ss        \t\t\t%10.5lf\n", sys.a_ss);
  printf("a_sw        \t\t\t%10.5lf\n\n", sys.a_sw);
  printf("pol_init_z  \t\t\t%10.5lf\n", sys.pol_init_z);
  printf("pol_init_bl \t\t\t%10.5lf\n\n", sys.pol_init_bl);
  printf("nsteps      \t\t\t%10d\n", sys.n_steps);
  printf("mc_ratio    \t\t\t%10.5lf\n", sys.mc_ratio);
  printf("temp        \t\t\t%10.5lf\n", sys.temp);
  printf("freq_sample \t\t\t%10d\n", sys.freq_sample);
  printf("freq_monitor\t\t\t%10d\n\n", sys.freq_monitor);
  printf("iseed       \t\t\t%10d\n", sys.iseed);
  printf("\n\n");
}

canonical_original_code:
void write_log() {
  printf("\nDPD Monte Carlo Simulation Program");
  printf("\n\n");
  printf("n_mon       \t\t\t%10d\n", sys.n_mon);
  printf("density_s   \t\t\t%10.5lf\n", sys.density_s);
  printf("n_solvent   \t\t\t%10d\n", sys.n_solvent);
  printf("calc_list   \t\t\t%10d\n\n", sys.calc_list);
  printf("length_x    \t\t\t%10.5lf\n", sys.length.x);
  printf("length_y    \t\t\t%10.5lf\n", sys.length.y);
  printf("length_z    \t\t\t%10.5lf\n", sys.length.z);
  printf("volume      \t\t\t%10.5lf\n\n", sys.volume);
  printf("density_w   \t\t\t%10.5lf\n", sys.density_w);
  printf("n_layers    \t\t\t%10d\n", sys.n_layers);
  printf("r_wall      \t\t\t%10.5lf\n", sys.r_wall);
  printf("n_wall      \t\t\t%10d\n", sys.n_wall);
  printf("wall_volume \t\t\t%10.5lf\n\n", sys.wall_volume);
  printf("pore_radius \t\t\t%10.5lf\n", sys.pore_radius);
  printf("r_pore      \t\t\t%10.5lf\n", sys.r_pore);
  printf("n_pore      \t\t\t%10d\n", sys.n_pore);
  printf("pore_volume \t\t\t%10.5lf\n\n", sys.pore_volume);
  printf("r_c         \t\t\t%10.5lf\n", sys.r_c);
  printf("dr_max_dpd  \t\t\t%10.5lf\n", sys.dr_max_dpd);
  printf("dr_max_mon  \t\t\t%10.5lf\n\n", sys.dr_max_mon);
  printf("a_mm        \t\t\t%10.5lf\n", sys.a_mm);
  printf("a_ms        \t\t\t%10.5lf\n", sys.a_ms);
  printf("a_ss        \t\t\t%10.5lf\n", sys.a_ss);
  printf("a_sw        \t\t\t%10.5lf\n\n", sys.a_sw);
  printf("pol_init_z  \t\t\t%10.5lf\n", sys.pol_init_z);
  printf("pol_init_bl \t\t\t%10.5lf\n\n", sys.pol_init_bl);
  printf("nsteps      \t\t\t%10d\n", sys.n_steps);
  printf("mc_ratio    \t\t\t%10.5lf\n", sys.mc_ratio);
  printf("temp        \t\t\t%10.5lf\n", sys.temp);
  printf("freq_sample \t\t\t%10d\n", sys.freq_sample);
  printf("freq_monitor\t\t\t%10d\n\n", sys.freq_monitor);
  printf("iseed       \t\t\t%10d\n", sys.iseed);
  printf("\n\n");
}


original_code:
void final_stats(void) {
  int i;
  for (i = 0; i < sys.n_stats; i++) {
    sys.stats[i].sum /= sys.stats[i].num;
    sys.stats[i].sumsq /= sys.stats[i].num;
    sys.stats[i].err =
      sqrt(sys.stats[i].sumsq - sys.stats[i].sum*sys.stats[i].sum);
  }
}

canonical_original_code:
void final_stats() {
  int i;
  for (i = 0; i < sys.n_stats; i++) {
    sys.stats[i].sum /= sys.stats[i].num;
    sys.stats[i].sumsq /= sys.stats[i].num;
    sys.stats[i].err =
      sqrt(sys.stats[i].sumsq - sys.stats[i].sum*sys.stats[i].sum);
  }
}


decompiled_code:
int print_stats()
{
__int64 v0; // rbp
int v1; // ebx
__int64 v2; // rax
double v4; // [rsp+0h] [rbp-28h]
double v5; // [rsp+8h] [rbp-20h]

puts("\nFinal averages\n");
if ( *((int *)&sys + 20) > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
++v1;
v2 = v0 + *((_QWORD *)&sys + 60);
v0 += 48LL;
printf("%s %12.8lf +/- %12.8lf\n", *(const char **)v2, *(double *)(v2 + 24), *(double *)(v2 + 40));
}
while ( *((_DWORD *)&sys + 20) > v1 );
}
v5 = (double)*((int *)&sys + 12) / (double)*((int *)&sys + 14);
v4 = (double)*((int *)&sys + 11) / (double)*((int *)&sys + 13);
puts("\n\nSelection and acceptance stats\n");
puts("Particle Moves Accepted Percent");
puts("-------- --------- -------- -------");
printf(" Solvent %9d%10d%9.2lf\n", *((unsigned int *)&sys + 14), *((unsigned int *)&sys + 12), v5);
return printf(" Monomer %9d%10d%9.2lf\n", *((unsigned int *)&sys + 13), *((unsigned int *)&sys + 11), v4);
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rbp
int v1; // ebx
__int64 v2; // rax
double v4; // [rsp+0h] [rbp-28h]
double v5; // [rsp+8h] [rbp-20h]

puts("\nFinal averages\n");
if ( *((int *)&sys + 20) > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
++v1;
v2 = v0 + *((_QWORD *)&sys + 60);
v0 += 48LL;
printf("%s %12.8lf +/- %12.8lf\n", *(const char **)v2, *(double *)(v2 + 24), *(double *)(v2 + 40));
}
while ( *((_DWORD *)&sys + 20) > v1 );
}
v5 = (double)*((int *)&sys + 12) / (double)*((int *)&sys + 14);
v4 = (double)*((int *)&sys + 11) / (double)*((int *)&sys + 13);
puts("\n\nSelection and acceptance stats\n");
puts("Particle Moves Accepted Percent");
puts("-------- --------- -------- -------");
printf(" Solvent %9d%10d%9.2lf\n", *((unsigned int *)&sys + 14), *((unsigned int *)&sys + 12), v5);
return printf(" Monomer %9d%10d%9.2lf\n", *((unsigned int *)&sys + 13), *((unsigned int *)&sys + 11), v4);
}

original_code:
void print_stats(void) {
  int i;
  double perc_dpd, perc_mon;
  printf("\nFinal averages\n\n");
  for (i = 0; i < sys.n_stats; i++) {
    printf("%s %12.8lf +/- %12.8lf\n",
      sys.stats[i].name, sys.stats[i].sum, sys.stats[i].err);
  }
  perc_dpd = (double) sys.n_accept_solvent / sys.n_attempt_solvent;
  perc_mon = (double) sys.n_accept_mon / sys.n_attempt_mon;
  printf("\n\nSelection and acceptance stats\n\n");
  printf("Particle    Moves    Accepted  Percent\n");
  printf("--------  ---------  --------  -------\n");
  printf(" Solvent  %9d%10d%9.2lf\n",
    sys.n_attempt_solvent, sys.n_accept_solvent, perc_dpd);
  printf(" Monomer  %9d%10d%9.2lf\n",
    sys.n_attempt_mon, sys.n_accept_mon, perc_mon);
}

canonical_original_code:
void print_stats() {
  int i;
  double perc_dpd; double perc_mon;
  printf("\nFinal averages\n\n");
  for (i = 0; i < sys.n_stats; i++) {
    printf("%s %12.8lf +/- %12.8lf\n",
      sys.stats[i].name, sys.stats[i].sum, sys.stats[i].err);
  }
  perc_dpd = (double) sys.n_accept_solvent / sys.n_attempt_solvent;
  perc_mon = (double) sys.n_accept_mon / sys.n_attempt_mon;
  printf("\n\nSelection and acceptance stats\n\n");
  printf("Particle    Moves    Accepted  Percent\n");
  printf("--------  ---------  --------  -------\n");
  printf(" Solvent  %9d%10d%9.2lf\n",
    sys.n_attempt_solvent, sys.n_accept_solvent, perc_dpd);
  printf(" Monomer  %9d%10d%9.2lf\n",
    sys.n_attempt_mon, sys.n_accept_mon, perc_mon);
}


vmag

decompiled_code:
void __fastcall vmag(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v9; // xmm0_8

v9 = a10 * a10 + a9 * a9 + a11 * a11;
if ( v9 < 0.0 )
sqrt(v9);
}

canonical_decompiled_code:
void __fastcall func1(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v9; // xmm0_8

v9 = a10 * a10 + a9 * a9 + a11 * a11;
if ( v9 < 0.0 )
sqrt(v9);
}

original_code:
double vmag(Vector v) {
  return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
}

canonical_original_code:
double vmag(struct vector_type v) {
  return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
}

variable_types:
v
struct vector_type { double x; }

return_type: double


mod

decompiled_code:
__int64 __fastcall mod(int a1, int a2)
{
int v2; // edx
unsigned int v3; // esi
__int64 result; // rax

v2 = a1 % a2;
v3 = a1 % a2 + a2;
result = (unsigned int)v2;
if ( v2 < 0 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
int v2; // edx
unsigned int v3; // esi
__int64 result; // rax

v2 = a1 % a2;
v3 = a1 % a2 + a2;
result = (unsigned int)v2;
if ( v2 < 0 )
result = v3;
return result;
}

original_code:
int mod(int a, int b) {
  int c = a % b;
  if (c < 0) {
    c += b;
  }
  return c;
}

variable_types: a int

variable_types: b int

variable_types: c int


original_code:
double ran3()
{
  static int ma[60],mj,mk,mz,i,ii,k,inext,inextp,iff,mbig,mseed;
  if (iff ==0) {
    iff=1;
    mbig = 1000000000;
      mseed = sys.iseed;
    mz =0;
    mj = mseed ;
    mj = mj % mbig;
    ma[55] = mj;
    mk = 1;
    for (i=1;i<55;i++){
      ii = (21*i) % 55;
      ma[ii] = mk;
      mk = mj - mk;
      if (mk<mz) mk=mk+mbig;
      mj = ma[ii];
    }
    for(k=1;k<=4;k++){
      for(i=1;i<=55;i++){
 ma[i] = ma[i] - ma[1 + ((i+30)%55)];
 if (ma[i]<mz) ma[i] = ma[i] + mbig;
      }
    }
    inext=0;
    inextp=31;
   }
  if (++inext == 56) inext =1;
  if (++inextp ==56) inextp =1;
  mj = ma[inext] - ma[inextp];
  if (mj<mz) mj=mj+mbig;
  ma[inext]=mj;
  sys.iseed = mj;
  return (double)mj / mbig;
}

canonical_original_code:
double ran3()
{
  static int ma[60]; static int mj; static int mk; static int mz; static int i; static int ii; static int k; static int inext; static int inextp; static int iff; static int mbig; static int mseed;
  if (iff ==0) {
    iff=1;
    mbig = 1000000000;
      mseed = sys.iseed;
    mz =0;
    mj = mseed ;
    mj = mj % mbig;
    ma[55] = mj;
    mk = 1;
    for (i=1;i<55;i++){
      ii = (21*i) % 55;
      ma[ii] = mk;
      mk = mj - mk;
      if (mk<mz) mk=mk+mbig;
      mj = ma[ii];
    }
    for(k=1;k<=4;k++){
      for(i=1;i<=55;i++){
 ma[i] = ma[i] - ma[1 + ((i+30)%55)];
 if (ma[i]<mz) ma[i] = ma[i] + mbig;
      }
    }
    inext=0;
    inextp=31;
   }
  if (++inext == 56) inext =1;
  if (++inextp ==56) inextp =1;
  mj = ma[inext] - ma[inextp];
  if (mj<mz) mj=mj+mbig;
  ma[inext]=mj;
  sys.iseed = mj;
  return (double)mj / mbig;
}

variable_types:
ma
int [60]

variable_types: mj int

variable_types: mk int

variable_types: mz int

variable_types: ii int

variable_types: inext int

variable_types: inextp int

variable_types: iff int

variable_types: mbig int

variable_types: mseed int


readrand

repo: tdz/performance

decompiled_code:
char *__fastcall readrand(size_t nbytes)
{
size_t v1; // rbp
char *v2; // r13
int v3; // eax
int v4; // ebx
char *v5; // r12
ssize_t v6; // rax

v1 = nbytes;
v2 = (char *)malloc(nbytes);
if ( v2 )
{
while ( 1 )
{
v3 = open("./random.data", 0);
v4 = v3;
if ( v3 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_21;
}
if ( v3 < 0 )
{
LABEL_21:
perror("open");
LABEL_20:
free(v2);
return 0LL;
}
v5 = v2;
if ( nbytes )
{
do
{
while ( 1 )
{
v6 = read(v4, v5, v1);
if ( v6 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_17;
}
if ( v6 < 0 )
{
LABEL_17:
perror("read");
while ( close(v4) == -1 && *__errno_location() == 4 )
;
goto LABEL_20;
}
if ( !v6 )
goto LABEL_15;
v5 += v6;
v1 -= v6;
}
while ( v1 );
if ( close(v4) == -1 )
goto LABEL_14;
}
else
{
LABEL_15:
while ( close(v4) == -1 )
{
LABEL_14:
if ( *__errno_location() != 4 )
return v2;
}
}
}
else
{
perror("malloc");
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func7(size_t nbytes)
{
size_t v1; // rbp
char *v2; // r13
int v3; // eax
int v4; // ebx
char *v5; // r12
ssize_t v6; // rax

v1 = nbytes;
v2 = (char *)malloc(nbytes);
if ( v2 )
{
while ( 1 )
{
v3 = open("./random.data", 0);
v4 = v3;
if ( v3 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_21;
}
if ( v3 < 0 )
{
LABEL_21:
perror("open");
LABEL_20:
free(v2);
return 0LL;
}
v5 = v2;
if ( nbytes )
{
do
{
while ( 1 )
{
v6 = read(v4, v5, v1);
if ( v6 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_17;
}
if ( v6 < 0 )
{
LABEL_17:
perror("read");
while ( close(v4) == -1 && *__errno_location() == 4 )
;
goto LABEL_20;
}
if ( !v6 )
goto LABEL_15;
v5 += v6;
v1 -= v6;
}
while ( v1 );
if ( close(v4) == -1 )
goto LABEL_14;
}
else
{
LABEL_15:
while ( close(v4) == -1 )
{
LABEL_14:
if ( *__errno_location() != 4 )
return v2;
}
}
}
else
{
perror("malloc");
}
return v2;
}

original_code:
void *
readrand(size_t siz)
{
  void *buf = malloc(siz);
  if (!buf) {
    perror("malloc");
    goto err_malloc;
  }
  int fd = (__extension__ ({ long int __result; do __result = (long int) (open("./random.data", 00)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
  if (fd < 0) {
    perror("open");
    goto err_open;
  }
  char *pos = buf;
  while (siz) {
    ssize_t res = (__extension__ ({ long int __result; do __result = (long int) (read(fd, pos, siz)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
    if (res < 0) {
      perror("read");
      goto err_read;
    } else if (res == 0) {
      break;
    }
    siz -= res;
    pos += res;
  }
  (__extension__ ({ long int __result; do __result = (long int) (close(fd)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
  return buf;
err_read:
  (__extension__ ({ long int __result; do __result = (long int) (close(fd)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
err_open:
  free(buf);
err_malloc:
  return ((void *)0);
}

canonical_original_code:
void *readrand(unsigned long siz)
{
  void *buf = malloc(siz);
  if (!buf) {
    perror("malloc");
    goto err_malloc;
  }
  int fd = (__extension__ ({ long int __result; do __result = (long int) (open("./random.data", 00)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
  if (fd < 0) {
    perror("open");
    goto err_open;
  }
  char *pos = buf;
  while (siz) {
    long res = (__extension__ ({ long int __result; do __result = (long int) (read(fd, pos, siz)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
    if (res < 0) {
      perror("read");
      goto err_read;
    } else if (res == 0) {
      break;
    }
    siz -= res;
    pos += res;
  }
  (__extension__ ({ long __result; do __result = (long) (close(fd)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
  return buf;
err_read:
  (__extension__ ({ long __result; do __result = (long) (close(fd)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
err_open:
  free(buf);
err_malloc:
  return ((void *)0);
}

variable_types:
siz
unsigned long

variable_types:
buf
void *

variable_types: fd int

variable_types:
pos
char *

variable_types: res long


sort

decompiled_code:
__int64 __fastcall sort(int *a1, unsigned __int64 a2)
{
__int64 v2; // r11
__int64 v5; // r12
__int64 i; // r10
int *v7; // rdi
unsigned __int64 v8; // rcx
int *v9; // rdx
unsigned __int64 v10; // rax

if ( !a2 )
return 0LL;
v2 = 0LL;
v5 = 0LL;
for ( i = 1LL; a2 != i; v5 = v5 + v10 - 1 )
{
v7 = a1++;
v8 = i;
v9 = a1;
do
{
while ( *v7 <= *v9 )
{
++v8;
++v9;
if ( a2 <= v8 )
goto LABEL_7;
}
swap(v7, v9);
}
while ( a2 > v8 );
LABEL_7:
v10 = a2 - v2;
v2 = i++;
}
return v5;
}

original_code:
long long
sort(int *data, size_t len)
{
  long long nsteps = 0;
  struct range *s = malloc(sizeof(*s));
  if (!s) {
    perror("malloc");
    goto err_malloc;
  }
  size_t siz = 1;
  size_t top = 0;
  s[top].off = 0;
  s[top].len = len;
  ++top;
  long long iter = 0;
  while (top) {
    --top;
    size_t off = s[top].off;
    size_t len = s[top].len;
    size_t pivot = off + len / 2;
    size_t i;
    for (i = off; i < pivot; ++i) {
      if (data[i] < data[pivot])
        swap(data+i, data+pivot);
      ++nsteps;
    }
    size_t end = off+len;
    for (i = pivot+1; i < end; ++i) {
      if (data[pivot] < data[i])
        swap(data+pivot, data+i);
      ++nsteps;
    }
    if ((top+2) > siz) {
      siz *= 2;
      void *mem = realloc(s, siz*sizeof(*s));
      if (!mem) {
        perror("realloc");
        goto err_realloc;
      }
      s = mem;
    }
    if (pivot > off) {
      s[top].off = off;
      s[top].len = pivot-1-off;
      ++top;
    }
    if (pivot < end) {
      s[top].off = pivot+1;
      s[top].len = end-s[top].off;
      ++top;
    }
  }
  free(s);
  return nsteps;
err_realloc:
  free(s);
err_malloc:
  return -1;
}

canonical_original_code:
long long sort(int *data, unsigned long len)
{
  long long nsteps = 0;
  struct range *s = malloc(sizeof(*s));
  if (!s) {
    perror("malloc");
    goto err_malloc;
  }
  unsigned long siz = 1;
  unsigned long top = 0;
  s[top].off = 0;
  s[top].len = len;
  ++top;
  long long iter = 0;
  while (top) {
    --top;
    unsigned long off = s[top].off;
    unsigned long len = s[top].len;
    unsigned long pivot = off + len / 2;
    unsigned long i;
    for (i = off; i < pivot; ++i) {
      if (data[i] < data[pivot])
        swap(data+i, data+pivot);
      ++nsteps;
    }
    unsigned long end = off+len;
    for (i = pivot+1; i < end; ++i) {
      if (data[pivot] < data[i])
        swap(data+pivot, data+i);
      ++nsteps;
    }
    if ((top+2) > siz) {
      siz *= 2;
      void *mem = realloc(s, siz*sizeof(*s));
      if (!mem) {
        perror("realloc");
        goto err_realloc;
      }
      s = mem;
    }
    if (pivot > off) {
      s[top].off = off;
      s[top].len = pivot-1-off;
      ++top;
    }
    if (pivot < end) {
      s[top].off = pivot+1;
      s[top].len = end-s[top].off;
      ++top;
    }
  }
  free(s);
  return nsteps;
err_realloc:
  free(s);
err_malloc:
  return -1;
}

variable_types:
data
int *

variable_types:
len
unsigned long

variable_types:
nsteps
long long

variable_types: struct range { unsigned long off; unsigned long len; } *

variable_types:
top
unsigned long

variable_types:
iter
long long

variable_types:
off
unsigned long

variable_types:
pivot
unsigned long

variable_types:
i
unsigned long

variable_types:
end
unsigned long

variable_types:
mem
void *

return_type: long long


readrand

canonical_decompiled_code:
char *__fastcall func9(size_t nbytes)
{
size_t v1; // rbp
char *v2; // r13
int v3; // eax
int v4; // ebx
char *v5; // r12
ssize_t v6; // rax

v1 = nbytes;
v2 = (char *)malloc(nbytes);
if ( v2 )
{
while ( 1 )
{
v3 = open("./random.data", 0);
v4 = v3;
if ( v3 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_21;
}
if ( v3 < 0 )
{
LABEL_21:
perror("open");
LABEL_20:
free(v2);
return 0LL;
}
v5 = v2;
if ( nbytes )
{
do
{
while ( 1 )
{
v6 = read(v4, v5, v1);
if ( v6 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_17;
}
if ( v6 < 0 )
{
LABEL_17:
perror("read");
while ( close(v4) == -1 && *__errno_location() == 4 )
;
goto LABEL_20;
}
if ( !v6 )
goto LABEL_15;
v5 += v6;
v1 -= v6;
}
while ( v1 );
if ( close(v4) == -1 )
goto LABEL_14;
}
else
{
LABEL_15:
while ( close(v4) == -1 )
{
LABEL_14:
if ( *__errno_location() != 4 )
return v2;
}
}
}
else
{
perror("malloc");
}
return v2;
}


canonical_decompiled_code:
char *__fastcall func8(size_t nbytes)
{
size_t v1; // rbp
char *v2; // r13
int v3; // eax
int v4; // ebx
char *v5; // r12
ssize_t v6; // rax

v1 = nbytes;
v2 = (char *)malloc(nbytes);
if ( v2 )
{
while ( 1 )
{
v3 = open("./random.data", 0);
v4 = v3;
if ( v3 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_21;
}
if ( v3 < 0 )
{
LABEL_21:
perror("open");
LABEL_20:
free(v2);
return 0LL;
}
v5 = v2;
if ( nbytes )
{
do
{
while ( 1 )
{
v6 = read(v4, v5, v1);
if ( v6 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_17;
}
if ( v6 < 0 )
{
LABEL_17:
perror("read");
while ( close(v4) == -1 && *__errno_location() == 4 )
;
goto LABEL_20;
}
if ( !v6 )
goto LABEL_15;
v5 += v6;
v1 -= v6;
}
while ( v1 );
if ( close(v4) == -1 )
goto LABEL_14;
}
else
{
LABEL_15:
while ( close(v4) == -1 )
{
LABEL_14:
if ( *__errno_location() != 4 )
return v2;
}
}
}
else
{
perror("malloc");
}
return v2;
}


compare

repo: te-bachi/mpc-sort

decompiled_code:
__int64 __fastcall compare(const void *a1, const void *a2)
{
return (unsigned int)(int)(*(double *)a1 - *(double *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)(int)(*(double *)a1 - *(double *)a2);
}

original_code:
int compare(const void *a, const void *b) {
    return ( *(sort_t*)a - *(sort_t*)b );
}

canonical_original_code:
int compare(void *a, void *b) {
    return ( *(double *)a - *(double *)b );
}

variable_types:
a
void *

variable_types:
b
void *


sortThread

decompiled_code:
void *__fastcall sortThread(void *a1)
{
qsort(*(void **)a1, *((int *)a1 + 3), 8uLL, (__compar_fn_t)compare);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
qsort(*(void **)a1, *((int *)a1 + 3), 8uLL, (__compar_fn_t)compare);
return 0LL;
}

original_code:
void *sortThread(void *arg) {
    chunk_t *chunk = (chunk_t *)(arg);
    qsort(chunk->data, chunk->len, sizeof(sort_t), compare);
    return ((void *)0);
}

canonical_original_code:
void *sortThread(void *arg) {
    struct chunk_t *chunk = (chunk_t *)(arg);
    qsort(chunk->data, chunk->len, sizeof(sort_t), compare);
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct chunk_t { double *data; int idx; int len; } *


getNumCpus

decompiled_code:
__int64 getNumCpus()
{
return readInfo(1);
}

canonical_decompiled_code:
__int64 func3()
{
return func2(1);
}

original_code:
int getNumCpus(void) {
    return readInfo(1);
}

canonical_original_code:
int getNumCpus() {
    return readInfo(1);
}


getNumThreads

decompiled_code:
__int64 getNumThreads()
{
return readInfo(2);
}

canonical_decompiled_code:
__int64 func4()
{
return func2(2);
}

original_code:
int getNumThreads(void) {
    return readInfo(2);
}

canonical_original_code:
int getNumThreads() {
    return readInfo(2);
}


getNumCores

decompiled_code:
__int64 getNumCores()
{
return readInfo(3);
}

canonical_decompiled_code:
__int64 func5()
{
return func2(3);
}

original_code:
int getNumCores(void) {
    return readInfo(3);
}

canonical_original_code:
int getNumCores() {
    return readInfo(3);
}


resetIndexes

decompiled_code:
void __fastcall resetIndexes(__int64 a1, int a2)
{
_DWORD *v2; // rax

if ( a2 > 0 )
{
v2 = (_DWORD *)(a1 + 8);
do
{
*v2 = 0;
v2 += 4;
}
while ( v2 != (_DWORD *)(a1 + 16LL * (unsigned int)(a2 - 1) + 24) );
}
}

original_code:
void resetIndexes(chunk_t *chunks, int nThreads) {
    int i;
    for (i = 0; i < nThreads; i++) {
        chunks[i].idx = 0;
    }
}

canonical_original_code:
void resetIndexes(struct chunk_t *chunks, int nThreads) {
    int i;
    for (i = 0; i < nThreads; i++) {
        chunks[i].idx = 0;
    }
}

variable_types: nThreads int

variable_types: i int

user_defined_types: struct chunk_t { double *data; int idx; int len; }


getLeast

original_code:
sort_t *getLeast(chunk_t *chunks, int nThreads) {
    chunk_t *chunkOne;
    chunk_t *chunkTwo;
    sort_t *dataOne;
    sort_t *dataTwo;
    int start;
    int i;
    chunkOne = ((void *)0);
    for (i = 0; i < nThreads; i++) {
        if (chunks[i].idx < chunks[i].len) {
            chunkOne = &chunks[i];
            dataOne = &chunkOne->data[chunkOne->idx];
            start = i + 1;
            break;
        }
    }
    for (i = start; i < nThreads; i++) {
        if (chunks[i].idx < chunks[i].len) {
            chunkTwo = &chunks[i];
            dataTwo = &chunkTwo->data[chunkTwo->idx];
            if (*dataTwo < *dataOne) {
                chunkOne = chunkTwo;
                dataOne = &chunkOne->data[chunkOne->idx];
            }
        }
    }
    if (chunkOne != ((void *)0)) {
        chunkOne->idx++;
    }
    return dataOne;
}

canonical_original_code:
double *getLeast(struct chunk_t *chunks, int nThreads) {
    struct chunk_t *chunkOne;
    struct chunk_t *chunkTwo;
    double *dataOne;
    double *dataTwo;
    int start;
    int i;
    chunkOne = ((void *)0);
    for (i = 0; i < nThreads; i++) {
        if (chunks[i].idx < chunks[i].len) {
            chunkOne = &chunks[i];
            dataOne = &chunkOne->data[chunkOne->idx];
            start = i + 1;
            break;
        }
    }
    for (i = start; i < nThreads; i++) {
        if (chunks[i].idx < chunks[i].len) {
            chunkTwo = &chunks[i];
            dataTwo = &chunkTwo->data[chunkTwo->idx];
            if (*dataTwo < *dataOne) {
                chunkOne = chunkTwo;
                dataOne = &chunkOne->data[chunkOne->idx];
            }
        }
    }
    if (chunkOne != ((void *)0)) {
        chunkOne->idx++;
    }
    return dataOne;
}

variable_types:
dataOne
double *

variable_types:
dataTwo
double *

variable_types: start int

return_type: double *


parSort

original_code:
void parSort(sort_t *data, int len, int nThreads, int thresh) {
    pthread_t th[nThreads];
    chunk_t chunks[nThreads];
    int chunkSize;
    size_t allocBytes;
    long start;
    long i;
    if(nThreads < 1) {
        nThreads = getNumCpus();
    }
    chunkSize = len / nThreads;
    start = 0;
    for (i = 0; i < nThreads; i++) {
        if(i + 1 == nThreads) {
            chunks[i].len = len - ((nThreads - 1) * chunkSize);
        } else {
            chunks[i].len = chunkSize;
        }
        allocBytes = chunks[i].len * sizeof(sort_t);
        chunks[i].data = (sort_t *) malloc(allocBytes);
        memcpy(chunks[i].data, &data[start], allocBytes);
        printf("%li: len=%i\n", i, chunks[i].len);
        pthread_create(&th[i], ((void *)0), sortThread, (void *)&chunks[i]);
        start += chunkSize;
    }
    for (i = 0; i < nThreads; i++) {
        pthread_join(th[i], ((void *)0));
    }
    resetIndexes(chunks, nThreads);
    for (i = 0; i < len; i++) {
        data[i] = *getLeast(chunks, nThreads);
    }
    for (i = 0; i < nThreads; i++) {
        free(chunks[i].data);
    }
}

canonical_original_code:
void parSort(double *data, int len, int nThreads, int thresh) {
    unsigned long th[-1];
    struct chunk_t chunks[-1];
    int chunkSize;
    unsigned long allocBytes;
    long start;
    long i;
    if(nThreads < 1) {
        nThreads = getNumCpus();
    }
    chunkSize = len / nThreads;
    start = 0;
    for (i = 0; i < nThreads; i++) {
        if(i + 1 == nThreads) {
            chunks[i].len = len - ((nThreads - 1) * chunkSize);
        } else {
            chunks[i].len = chunkSize;
        }
        allocBytes = chunks[i].len * sizeof(sort_t);
        chunks[i].data = (double *) malloc(allocBytes);
        memcpy(chunks[i].data, &data[start], allocBytes);
        printf("%li: len=%i\n", i, chunks[i].len);
        pthread_create(&th[i], ((void *)0), sortThread, (void *)&chunks[i]);
        start += chunkSize;
    }
    for (i = 0; i < nThreads; i++) {
        pthread_join(th[i], ((void *)0));
    }
    resetIndexes(chunks, nThreads);
    for (i = 0; i < len; i++) {
        data[i] = *getLeast(chunks, nThreads);
    }
    for (i = 0; i < nThreads; i++) {
        free(chunks[i].data);
    }
}

variable_types:
data
double *

variable_types: len int

variable_types: thresh int

variable_types:
th
unsigned long [-1]

variable_types: struct chunk_t { double *data; int idx; int len; } [-1]

variable_types: chunkSize int

variable_types:
allocBytes
unsigned long

variable_types: start long

variable_types: i long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
void *v5; // rbx
double v6; // r14
double v7; // r15
struct timespec v9; // [rsp+0h] [rbp-88h] BYREF
struct timespec v10; // [rsp+10h] [rbp-78h] BYREF
clockid_t v11; // [rsp+20h] [rbp-68h]
struct timespec tp; // [rsp+30h] [rbp-58h] BYREF
struct timespec v13; // [rsp+40h] [rbp-48h] BYREF
clockid_t clock_id; // [rsp+50h] [rbp-38h]

v3 = 0;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = 16;
if ( v3 <= 16 )
v4 = v3;
v11 = 2;
v5 = 0LL;
clock_id = 1;
clock_gettime(2, &v9);
clock_gettime(clock_id, &tp);
parSort(dummyDoubleSortData, &unk_1E8480, (unsigned int)v4, 0LL);
clock_gettime(v11, &v10);
clock_gettime(clock_id, &v13);
v6 = ((double)SLODWORD(v10.tv_nsec) - (double)SLODWORD(v9.tv_nsec)) / 1000000000.0
+ (double)SLODWORD(v10.tv_sec)
- (double)SLODWORD(v9.tv_sec);
v7 = ((double)SLODWORD(v13.tv_nsec) - (double)SLODWORD(tp.tv_nsec)) / 1000000000.0
+ (double)SLODWORD(v13.tv_sec)
- (double)SLODWORD(tp.tv_sec);
puts("after:");
while ( 1 )
{
printf("%12.4f ", dummyDoubleSortData[(_QWORD)v5]);
if ( !v5 )
goto LABEL_7;
if ( __ROR4__(-858993459 * (_DWORD)v5, 1) <= 0x19999999u )
break;
if ( v5 == &unk_1E847F )
goto LABEL_11;
LABEL_7:
v5 = (char *)v5 + 1;
}
putchar(10);
if ( v5 != &unk_1E847F )
goto LABEL_7;
LABEL_11:
putchar(10);
printf("Elapsed: %2.2f, process %2.2f, average per CPU %2.2f)\n", v7, v6, v6 / (double)v4);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 ctimer_t cp;
 ctimer_t ce;
 int nThreads;
 sort_t *sort = dummyDoubleSortData;
 size_t sortLen = sizeof(dummyDoubleSortData) / sizeof(sort_t);
 nThreads = 0;
 if (argc > 1) {
     nThreads= atoi(argv[1]);
 }
 nThreads = (nThreads > 16) ? 16 : nThreads;
 cp.clockID = PROCESS;
 ce.clockID = MONOTONIC;
 clock_gettime(cp.clockID, &(cp.sT));
 clock_gettime(ce.clockID, &(ce.sT));
 parSort(sort, sortLen, nThreads, 0);
    clock_gettime(cp.clockID, &(cp.eT));
    clock_gettime(ce.clockID, &(ce.eT));
    double ptime = ((double)(cp.eT.tv_sec) - (double)(cp.sT.tv_sec)) + ((double)cp.eT.tv_nsec - (double)cp.sT.tv_nsec)/1e9;
    double etime = ((double)(ce.eT.tv_sec) - (double)(ce.sT.tv_sec)) + ((double)ce.eT.tv_nsec - (double)ce.sT.tv_nsec)/1e9;
    printf("after:\n");
    for (int i = 0; i < sortLen; i++) {
        printf("%12.4f ", sort[i]);
        if (i != 0 && i % 10 == 0) {
            printf("\n");
        }
    }
    printf("\n");
    printf("Elapsed: %2.2f, process %2.2f, " "average per CPU %2.2f)\n",
                    etime, ptime, ptime/((double)nThreads));
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct ctimer_t cp;
 struct ctimer_t ce;
 int nThreads;
 double *sort = dummyDoubleSortData;
 unsigned long sortLen = sizeof(dummyDoubleSortData) / sizeof(sort_t);
 nThreads = 0;
 if (argc > 1) {
     nThreads= atoi(argv[1]);
 }
 nThreads = (nThreads > 16) ? 16 : nThreads;
 cp.clockID = PROCESS;
 ce.clockID = MONOTONIC;
 clock_gettime(cp.clockID, &(cp.sT));
 clock_gettime(ce.clockID, &(ce.sT));
 parSort(sort, sortLen, nThreads, 0);
    clock_gettime(cp.clockID, &(cp.eT));
    clock_gettime(ce.clockID, &(ce.eT));
    double ptime = ((double)(cp.eT.tv_sec) - (double)(cp.sT.tv_sec)) + ((double)cp.eT.tv_nsec - (double)cp.sT.tv_nsec)/1e9;
    double etime = ((double)(ce.eT.tv_sec) - (double)(ce.sT.tv_sec)) + ((double)ce.eT.tv_nsec - (double)ce.sT.tv_nsec)/1e9;
    printf("after:\n");
    for (int i = 0; i < sortLen; i++) {
        printf("%12.4f ", sort[i]);
        if (i != 0 && i % 10 == 0) {
            printf("\n");
        }
    }
    printf("\n");
    printf("Elapsed: %2.2f, process %2.2f, " "average per CPU %2.2f)\n",
                    etime, ptime, ptime/((double)nThreads));
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct ctimer_t { struct timespec { long tv_sec; long tv_nsec; } sT; struct timespec eT; int clockID; }

variable_types:
sort
double *

variable_types:
sortLen
unsigned long

variable_types: ptime double

variable_types: etime double

user_defined_types: struct ctimer_t { struct timespec sT; struct timespec eT; int clockID; }


sigchldhandler

decompiled_code:
void sigchldhandler()
{
while ( waitpid(-1, 0LL, 1) > 0 )
;
}

canonical_decompiled_code:
void func1()
{
while ( waitpid(-1, 0LL, 1) > 0 )
;
}

original_code:
static void sigchldhandler(int sig)
{
 while(waitpid(-1, ((void *)0), 1) > 0);
}

variable_types: sig int


decompiled_code:
int __fastcall setup_alarms(unsigned int a1, unsigned int a2, unsigned int a3)
{
struct itimerspec v5; // [rsp+0h] [rbp-D8h] BYREF
struct itimerspec value; // [rsp+20h] [rbp-B8h] BYREF
struct sigevent evp; // [rsp+40h] [rbp-98h] BYREF
struct sigevent v8; // [rsp+80h] [rbp-58h] BYREF

*(_QWORD *)&evp.sigev_signo = 14LL;
evp.sigev_value.sival_ptr = &load_timer;
timer_create(0, &evp, &load_timer);
v5.it_value.tv_sec = a1 / 0x3E8;
v5.it_value.tv_nsec = 1000000 * (a1 % 0x3E8);
v5.it_interval.tv_sec = a2 / 0x3E8 + a1 / 0x3E8;
v5.it_interval.tv_nsec = 1000000 * (a1 % 0x3E8 + a2 % 0x3E8);
timer_settime(load_timer, 0, &v5, 0LL);
*(_QWORD *)&v8.sigev_signo = 14LL;
v8.sigev_value.sival_ptr = &deadline_timer;
timer_create(0, &v8, &deadline_timer);
value.it_interval.tv_sec = 0LL;
value.it_value.tv_sec = a3 / 0x3E8;
value.it_value.tv_nsec = 1000000 * (a3 % 0x3E8);
return timer_settime(deadline_timer, 0, &value, 0LL);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, unsigned int a2, unsigned int a3)
{
struct itimerspec v5; // [rsp+0h] [rbp-D8h] BYREF
struct itimerspec value; // [rsp+20h] [rbp-B8h] BYREF
struct sigevent evp; // [rsp+40h] [rbp-98h] BYREF
struct sigevent v8; // [rsp+80h] [rbp-58h] BYREF

*(_QWORD *)&evp.sigev_signo = 14LL;
evp.sigev_value.sival_ptr = &load_timer;
timer_create(0, &evp, &load_timer);
v5.it_value.tv_sec = a1 / 0x3E8;
v5.it_value.tv_nsec = 1000000 * (a1 % 0x3E8);
v5.it_interval.tv_sec = a2 / 0x3E8 + a1 / 0x3E8;
v5.it_interval.tv_nsec = 1000000 * (a1 % 0x3E8 + a2 % 0x3E8);
timer_settime(load_timer, 0, &v5, 0LL);
*(_QWORD *)&v8.sigev_signo = 14LL;
v8.sigev_value.sival_ptr = &deadline_timer;
timer_create(0, &v8, &deadline_timer);
value.it_interval.tv_sec = 0LL;
value.it_value.tv_sec = a3 / 0x3E8;
value.it_value.tv_nsec = 1000000 * (a3 % 0x3E8);
return timer_settime(deadline_timer, 0, &value, 0LL);
}

original_code:
static void setup_alarms(unsigned int onperiod, unsigned int offperiod, unsigned int deadline)
{
 struct sigevent sigev_load, sigev_deadline;
 struct itimerspec its_load, its_deadline;
 sigev_load.sigev_notify = SIGEV_SIGNAL;
 sigev_load.sigev_signo = 14;
 sigev_load.sigev_value.sival_ptr = &load_timer;
 timer_create(0, &sigev_load, &load_timer);
 its_load.it_value.tv_sec = onperiod / 1000;
 its_load.it_value.tv_nsec = (onperiod % 1000) * 1000000;
 its_load.it_interval.tv_sec = onperiod / 1000 + offperiod / 1000;
 its_load.it_interval.tv_nsec = (onperiod % 1000 + offperiod % 1000) * 1000000;
 timer_settime(load_timer, 0, &its_load, ((void *)0));
 sigev_deadline.sigev_notify = SIGEV_SIGNAL;
 sigev_deadline.sigev_signo = 14;
 sigev_deadline.sigev_value.sival_ptr = &deadline_timer;
 timer_create(0, &sigev_deadline, &deadline_timer);
 its_deadline.it_value.tv_sec = deadline / 1000;
 its_deadline.it_value.tv_nsec = (deadline % 1000) * 1000000;
 its_deadline.it_interval.tv_sec = 0;
 its_deadline.it_interval.tv_sec = 0;
 timer_settime(deadline_timer, 0, &its_deadline, ((void *)0));
}

canonical_original_code:
static void setup_alarms(unsigned int onperiod, unsigned int offperiod, unsigned int deadline)
{
 struct sigevent sigev_load; struct sigevent sigev_deadline;
 struct itimerspec its_load; struct itimerspec its_deadline;
 sigev_load.sigev_notify = SIGEV_SIGNAL;
 sigev_load.sigev_signo = 14;
 sigev_load.sigev_value.sival_ptr = &load_timer;
 timer_create(0, &sigev_load, &load_timer);
 its_load.it_value.tv_sec = onperiod / 1000;
 its_load.it_value.tv_nsec = (onperiod % 1000) * 1000000;
 its_load.it_interval.tv_sec = onperiod / 1000 + offperiod / 1000;
 its_load.it_interval.tv_nsec = (onperiod % 1000 + offperiod % 1000) * 1000000;
 timer_settime(load_timer, 0, &its_load, ((void *)0));
 sigev_deadline.sigev_notify = SIGEV_SIGNAL;
 sigev_deadline.sigev_signo = 14;
 sigev_deadline.sigev_value.sival_ptr = &deadline_timer;
 timer_create(0, &sigev_deadline, &deadline_timer);
 its_deadline.it_value.tv_sec = deadline / 1000;
 its_deadline.it_value.tv_nsec = (deadline % 1000) * 1000000;
 its_deadline.it_interval.tv_sec = 0;
 its_deadline.it_interval.tv_sec = 0;
 timer_settime(deadline_timer, 0, &its_deadline, ((void *)0));
}

variable_types:
onperiod
unsigned int

variable_types:
offperiod
unsigned int

variable_types:
deadline
unsigned int

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

variable_types: struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }


load

decompiled_code:
void __noreturn load()
{
double v0; // xmm0_8

while ( 1 )
{
do
v0 = (double)rand();
while ( v0 >= 0.0 );
sqrt(v0);
}
}

canonical_decompiled_code:
void __noreturn func3()
{
double v0; // xmm0_8

while ( 1 )
{
do
v0 = (double)rand();
while ( v0 >= 0.0 );
sqrt(v0);
}
}

original_code:
static void load()
{
 while (1)
  sqrt(rand());
}


bindcpu

decompiled_code:
int __fastcall bindcpu(__pid_t pid, int a2)
{
cpu_set_t v3; // [rsp+0h] [rbp-88h] BYREF

memset(&v3, 0, sizeof(v3));
if ( (unsigned __int64)a2 <= 0x3FF )
v3.__bits[(unsigned __int64)a2 >> 6] |= 1LL << a2;
return sched_setaffinity(pid, 0x80uLL, &v3);
}

canonical_decompiled_code:
int __fastcall func4(__pid_t pid, int a2)
{
cpu_set_t v3; // [rsp+0h] [rbp-88h] BYREF

memset(&v3, 0, sizeof(v3));
if ( (unsigned __int64)a2 <= 0x3FF )
v3.__bits[(unsigned __int64)a2 >> 6] |= 1LL << a2;
return sched_setaffinity(pid, 0x80uLL, &v3);
}

original_code:
static void bindcpu(pid_t pid, int cpu)
{
 cpu_set_t cpuset;
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 sched_setaffinity(pid, sizeof(cpuset), &cpuset);
}

canonical_original_code:
static void bindcpu(int pid, int cpu)
{
 struct cpu_set_t cpuset;
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 sched_setaffinity(pid, sizeof(cpuset), &cpuset);
}

variable_types: pid int

variable_types: cpu int

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }


decompiled_code:
__pid_t __fastcall create_workers(int a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
int v5; // er14
int v9; // ebx
int v10; // esi
__pid_t result; // eax

if ( a1 <= 0 )
return 0;
v5 = a2;
v9 = a2 + 2 * a1;
while ( 1 )
{
result = fork();
if ( result == -1 )
break;
if ( !result )
{
prctl(1, 1LL);
setup_alarms(a3, a4, a5);
load();
}
v10 = v5;
v5 += 2;
bindcpu(result, v10);
if ( v5 == v9 )
return 0;
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func5(int a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
int v5; // er14
int v9; // ebx
int v10; // esi
__pid_t result; // eax

if ( a1 <= 0 )
return 0;
v5 = a2;
v9 = a2 + 2 * a1;
while ( 1 )
{
result = fork();
if ( result == -1 )
break;
if ( !result )
{
prctl(1, 1LL);
func2(a3, a4, a5);
func3();
}
v10 = v5;
v5 += 2;
func4(result, v10);
if ( v5 == v9 )
return 0;
}
return result;
}

original_code:
static int create_workers(int workers, int startcpu, unsigned int onperiod, unsigned int offperiod, unsigned int deadline)
{
 int pid;
 for(; workers > 0; workers--) {
  pid = fork();
  if (pid == -1) {
   return -1;
  }
  if (pid == 0) {
   prctl(1, 1);
   setup_alarms(onperiod, offperiod, deadline);
   load();
  }
  else {
   bindcpu(pid, startcpu);
   startcpu += 2;
  }
 }
 return 0;
}

variable_types: workers int

variable_types: startcpu int


decompiled_code:
__int64 __fastcall synthload_start(unsigned int a1, unsigned int a2, unsigned int a3, int a4, int a5)
{
__pid_t v8; // eax
unsigned int v9; // er12
sigset_t v11; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v12; // [rsp+80h] [rbp-D8h] BYREF

offperiod = a2;
v8 = fork();
v9 = v8;
if ( v8 != -1 )
{
if ( v8 )
{
bindcpu(v8, a5 + 1);
}
else
{
signal(15, 0LL);
signal(2, 0LL);
signal(1, 0LL);
signal(20, 0LL);
signal(17, (__sighandler_t)sigchldhandler);
prctl(1, 1LL);
sigemptyset(&v11);
sigaddset(&v11, 15);
sigaddset(&v11, 1);
sigprocmask(1, &v11, 0LL);
v12.sa_flags = 4;
v12.sa_handler = (__sighandler_t)sigalrmhandler;
sigemptyset(&v12.sa_mask);
sigaction(14, &v12, 0LL);
if ( !create_workers(a4 - 1, a5 + 3, a1, a2, a3) )
{
setup_alarms(a1, a2, a3);
load();
}
v9 = -2;
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2, unsigned int a3, int a4, int a5)
{
__pid_t v8; // eax
unsigned int v9; // er12
sigset_t v11; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v12; // [rsp+80h] [rbp-D8h] BYREF

offperiod = a2;
v8 = fork();
v9 = v8;
if ( v8 != -1 )
{
if ( v8 )
{
func4(v8, a5 + 1);
}
else
{
signal(15, 0LL);
signal(2, 0LL);
signal(1, 0LL);
signal(20, 0LL);
signal(17, (__sighandler_t)sigchldhandler);
prctl(1, 1LL);
sigemptyset(&v11);
sigaddset(&v11, 15);
sigaddset(&v11, 1);
sigprocmask(1, &v11, 0LL);
v12.sa_flags = 4;
v12.sa_handler = (__sighandler_t)sigalrmhandler;
sigemptyset(&v12.sa_mask);
sigaction(14, &v12, 0LL);
if ( !func5(a4 - 1, a5 + 3, a1, a2, a3) )
{
func2(a1, a2, a3);
func3();
}
v9 = -2;
}
}
return v9;
}

original_code:
pid_t synthload_start(unsigned int onperiod, unsigned int offperiod, unsigned int deadline, int workers, int startcpu)
{
 int mpid;
 struct sigaction sa;
 _offperiod = offperiod;
 mpid = fork();
 if (mpid == -1) {
  return -1;
 }
 if (mpid == 0) {
  sigset_t unblock;
  signal(15, ((__sighandler_t) 0));
  signal(2, ((__sighandler_t) 0));
  signal(1, ((__sighandler_t) 0));
  signal(20, ((__sighandler_t) 0));
  signal(17, sigchldhandler);
  prctl(1, 1);
  sigemptyset(&unblock);
  sigaddset(&unblock, 15);
  sigaddset(&unblock, 1);
  sigprocmask(1, &unblock, ((void *)0));
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = sigalrmhandler;
  sigemptyset(&sa.sa_mask);
  sigaction(14, &sa, ((void *)0));
  if (create_workers(workers-1, startcpu+3, onperiod, offperiod, deadline) != 0)
   return -2;
  setup_alarms(onperiod, offperiod, deadline);
  load();
 } else {
  bindcpu(mpid, startcpu+1);
 }
 return mpid;
}

canonical_original_code:
int synthload_start(unsigned int onperiod, unsigned int offperiod, unsigned int deadline, int workers, int startcpu)
{
 int mpid;
 struct sigaction sa;
 _offperiod = offperiod;
 mpid = fork();
 if (mpid == -1) {
  return -1;
 }
 if (mpid == 0) {
  struct __sigset_t unblock;
  signal(15, ((void (*)(int)) 0));
  signal(2, ((void (*)(int)) 0));
  signal(1, ((void (*)(int)) 0));
  signal(20, ((void (*)(int)) 0));
  signal(17, sigchldhandler);
  prctl(1, 1);
  sigemptyset(&unblock);
  sigaddset(&unblock, 15);
  sigaddset(&unblock, 1);
  sigprocmask(1, &unblock, ((void *)0));
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = sigalrmhandler;
  sigemptyset(&sa.sa_mask);
  sigaction(14, &sa, ((void *)0));
  if (create_workers(workers-1, startcpu+3, onperiod, offperiod, deadline) != 0)
   return -2;
  setup_alarms(onperiod, offperiod, deadline);
  load();
 } else {
  bindcpu(mpid, startcpu+1);
 }
 return mpid;
}

variable_types: mpid int

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

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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


sigalrmhandler

decompiled_code:
int __fastcall sigalrmhandler(__int64 a1, __int64 a2)
{
if ( *(timer_t **)(a2 + 24) == &deadline_timer )
exit(0);
return usleep(1000 * offperiod);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
if ( *(timer_t **)(a2 + 24) == &deadline_timer )
exit(0);
return usleep(1000 * offperiod);
}

original_code:
static void sigalrmhandler(int sig, siginfo_t *si, void *uc)
{
 if (si->_sifields._rt.si_sigval.sival_ptr == &deadline_timer) {
  _exit(0);
 }
 usleep(_offperiod * 1000);
}

canonical_original_code:
static void sigalrmhandler(int sig, struct siginfo_t *si, void *uc)
{
 if (si->_sifields._rt.si_sigval.sival_ptr == &deadline_timer) {
  _exit(0);
 }
 usleep(_offperiod * 1000);
}

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

variable_types:
uc
void *


repo: teamosceola/base-station

decompiled_code:
__int64 Init_Draw_Compass()
{
int v0; // ebp
__int64 v1; // rbx
int *v2; // rdx
int *v3; // rcx
double v4; // xmm0_8
__int64 result; // rax

v0 = 0;
v1 = 0LL;
do
{
v2 = &v_delta_x[v1];
v3 = &v_delta_y[v1];
v4 = (double)v0++;
++v1;
rotozoomSurfaceSize(500LL, 500LL, v2, v3, v4, 1.0);
dword_11BC[v1] = (int)((double)((dword_11BC[v1] - 500) / 2) + 78.0);
result = (unsigned int)(int)((double)((*(_DWORD *)(v1 * 4 + 3068) - 500) / 2) + 78.0);
*(_DWORD *)(v1 * 4 + 3068) = result;
}
while ( v0 != 361 );
return result;
}

variable_types: i int


main

repo: technetia/project-tdm

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax

init_registers(argc, argv, envp);
init_memory();
puts(">> Begin 6502 emulation");
v3 = get_full_SP();
printf("SP: 0x%X\n", v3);
puts("Execute instruction DEX");
instr_dex();
printf("X: %d\n", (unsigned int)reg_X);
printf("A: %d\n", (unsigned int)reg_A);
puts("Execute instruction TXA");
instr_txa();
printf("X: %d\n", (unsigned int)reg_X);
printf("A: %d\n", (unsigned int)reg_A);
puts("Execute instruction LDA #$42");
instr_lda(42LL, 2LL);
printf("X: %d\n", (unsigned int)reg_X);
printf("A: %d\n", (unsigned int)reg_A);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    init_registers();
    init_memory();
    printf(">> Begin 6502 emulation\n");
    printf("SP: 0x%X\n", get_full_SP());
    printf("Execute instruction DEX\n");
    instr_dex();
    printf("X: %d\n", reg_X.data);
    printf("A: %d\n", reg_A.data);
    printf("Execute instruction TXA\n");
    instr_txa();
    printf("X: %d\n", reg_X.data);
    printf("A: %d\n", reg_A.data);
    printf("Execute instruction LDA #$42\n");
    instr_lda(42, IMMEDIATE);
    printf("X: %d\n", reg_X.data);
    printf("A: %d\n", reg_A.data);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


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

result = (unsigned __int8)reg_SP;
reg_X = reg_SP;
if ( reg_SP )
{
if ( (reg_SP & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned __int8)reg_SP;
reg_X = reg_SP;
if ( reg_SP )
{
if ( (reg_SP & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_tsx(void) {
    reg_X.data = (signed char)reg_SP.data;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_tsx() {
    reg_X.data = (char)reg_SP.data;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned __int8)reg_X;
reg_SP = reg_X;
return result;
}

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

result = (unsigned __int8)reg_X;
reg_SP = reg_X;
return result;
}

original_code:
void instr_txs(void) {
    reg_SP.data = (unsigned char)reg_X.data;
}

canonical_original_code:
void instr_txs() {
    reg_SP.data = (unsigned char)reg_X.data;
}


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

LOWORD(result) = get_full_SP();
--reg_SP;
result = (unsigned __int16)result;
*((_BYTE *)&MEMORY_BLOCK + (unsigned __int16)result) = reg_A;
return result;
}

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

LOWORD(result) = get_full_SP();
--reg_SP;
result = (unsigned __int16)result;
*((_BYTE *)&MEMORY_BLOCK + (unsigned __int16)result) = reg_A;
return result;
}

original_code:
void instr_pha(void) {
    unsigned short stack_index = get_full_SP();
    MEMORY_BLOCK[stack_index] = reg_A.data;
    reg_SP.data--;
}

canonical_original_code:
void instr_pha() {
    unsigned short stack_index = get_full_SP();
    MEMORY_BLOCK[stack_index] = reg_A.data;
    reg_SP.data--;
}


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

LOWORD(result) = get_full_SP();
--reg_SP;
result = (unsigned __int16)result;
*((_BYTE *)&MEMORY_BLOCK + (unsigned __int16)result) = reg_PSR;
return result;
}

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

LOWORD(result) = get_full_SP();
--reg_SP;
result = (unsigned __int16)result;
*((_BYTE *)&MEMORY_BLOCK + (unsigned __int16)result) = reg_PSR;
return result;
}

original_code:
void instr_php(void) {
    unsigned short stack_index = get_full_SP();
    MEMORY_BLOCK[stack_index] = reg_PSR.data.reg;
    reg_SP.data--;
}

canonical_original_code:
void instr_php() {
    unsigned short stack_index = get_full_SP();
    MEMORY_BLOCK[stack_index] = reg_PSR.data.reg;
    reg_SP.data--;
}


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

++reg_SP;
result = *((unsigned __int8 *)&MEMORY_BLOCK + (unsigned __int16)get_full_SP());
reg_A = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

++reg_SP;
result = *((unsigned __int8 *)&MEMORY_BLOCK + (unsigned __int16)get_full_SP());
reg_A = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_pla(void) {
    unsigned short stack_index;
    reg_SP.data++;
    stack_index = get_full_SP();
    reg_A.data = MEMORY_BLOCK[stack_index];
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_pla() {
    unsigned short stack_index;
    reg_SP.data++;
    stack_index = get_full_SP();
    reg_A.data = MEMORY_BLOCK[stack_index];
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

++reg_SP;
result = *((unsigned __int8 *)&MEMORY_BLOCK + (unsigned __int16)get_full_SP());
reg_PSR = result;
return result;
}

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

++reg_SP;
result = *((unsigned __int8 *)&MEMORY_BLOCK + (unsigned __int16)get_full_SP());
reg_PSR = result;
return result;
}

original_code:
void instr_plp(void) {
    unsigned short stack_index;
    reg_SP.data++;
    stack_index = get_full_SP();
    reg_PSR.data.reg = MEMORY_BLOCK[stack_index];
}

canonical_original_code:
void instr_plp() {
    unsigned short stack_index;
    reg_SP.data++;
    stack_index = get_full_SP();
    reg_PSR.data.reg = MEMORY_BLOCK[stack_index];
}


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

result = (unsigned __int8)reg_A;
reg_X = reg_A;
if ( reg_A )
{
if ( (reg_A & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned __int8)reg_A;
reg_X = reg_A;
if ( reg_A )
{
if ( (reg_A & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_tax(void) {
    reg_X.data = reg_A.data;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_tax() {
    reg_X.data = reg_A.data;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned __int8)reg_A;
reg_Y = reg_A;
if ( reg_A )
{
if ( (reg_A & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned __int8)reg_A;
reg_Y = reg_A;
if ( reg_A )
{
if ( (reg_A & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_tay(void) {
    reg_Y.data = reg_A.data;
    if (reg_Y.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_Y.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_tay() {
    reg_Y.data = reg_A.data;
    if (reg_Y.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_Y.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned __int8)reg_X;
reg_A = reg_X;
if ( reg_X )
{
if ( (reg_X & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned __int8)reg_X;
reg_A = reg_X;
if ( reg_X )
{
if ( (reg_X & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_txa(void) {
    reg_A.data = reg_X.data;
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_txa() {
    reg_A.data = reg_X.data;
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned __int8)reg_Y;
reg_A = reg_Y;
if ( reg_Y )
{
if ( (reg_Y & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned __int8)reg_Y;
reg_A = reg_Y;
if ( reg_Y )
{
if ( (reg_Y & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_tya(void) {
    reg_A.data = reg_Y.data;
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_tya() {
    reg_A.data = reg_Y.data;
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned int)(unsigned __int8)reg_X + 1;
reg_X = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned int)(unsigned __int8)reg_X + 1;
reg_X = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_inx(void) {
    reg_X.data++;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_inx() {
    reg_X.data++;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned int)(unsigned __int8)reg_Y + 1;
reg_Y = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned int)(unsigned __int8)reg_Y + 1;
reg_Y = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_iny(void) {
    reg_Y.data++;
    if (reg_Y.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_Y.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_iny() {
    reg_Y.data++;
    if (reg_Y.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_Y.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned int)(unsigned __int8)reg_X - 1;
reg_X = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned int)(unsigned __int8)reg_X - 1;
reg_X = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_dex(void) {
    reg_X.data--;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_dex() {
    reg_X.data--;
    if (reg_X.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_X.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = (unsigned int)(unsigned __int8)reg_Y - 1;
reg_Y = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

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

result = (unsigned int)(unsigned __int8)reg_Y - 1;
reg_Y = result;
if ( (_BYTE)result )
{
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
reg_PSR |= 2u;
}
return result;
}

original_code:
void instr_dey(void) {
    reg_Y.data--;
    if (reg_Y.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_Y.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_dey() {
    reg_Y.data--;
    if (reg_Y.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_Y.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}


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

result = 0LL;
reg_A = 0;
reg_X = 0;
reg_Y = 0;
reg_PSR = 32;
reg_PC = 0;
reg_SP = 511;
return result;
}

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

result = 0LL;
reg_A = 0;
reg_X = 0;
reg_Y = 0;
reg_PSR = 32;
reg_PC = 0;
reg_SP = 511;
return result;
}

original_code:
void init_registers(void) {
    reg_A.data = 0x00;
    reg_X.data = 0x00;
    reg_Y.data = 0x00;
    reg_PSR.data.reg = 0x00;
    reg_PSR.data.flags.X = 1;
    reg_PC.data = 0x00;
    reg_SP.data = 0xFF;
    reg_SP.page_index = 0x01;
}

canonical_original_code:
void init_registers() {
    reg_A.data = 0x00;
    reg_X.data = 0x00;
    reg_Y.data = 0x00;
    reg_PSR.data.reg = 0x00;
    reg_PSR.data.flags.X = 1;
    reg_PC.data = 0x00;
    reg_SP.data = 0xFF;
    reg_SP.page_index = 0x01;
}


decompiled_code:
__int64 get_full_SP()
{
return (unsigned __int8)reg_SP + (HIBYTE(reg_SP) << 8);
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned __int8)reg_SP + (HIBYTE(reg_SP) << 8);
}

original_code:
unsigned short get_full_SP(void) {
    return (reg_SP.page_index << 8) + reg_SP.data;
}

canonical_original_code:
unsigned short get_full_SP() {
    return (reg_SP.page_index << 8) + reg_SP.data;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall instr_lda(__int64 a1, int a2)
{
__int64 result; // rax

switch ( a2 )
{
case 2:
reg_A = a1;
result = (unsigned int)a1;
goto LABEL_3;
case 3:
case 7:
result = *((unsigned __int8 *)&MEMORY_BLOCK + a1);
reg_A = *((_BYTE *)&MEMORY_BLOCK + a1);
goto LABEL_3;
case 8:
result = *((unsigned __int8 *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_X);
reg_A = *((_BYTE *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_X);
goto LABEL_3;
case 9:
result = *((unsigned __int8 *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_Y);
reg_A = *((_BYTE *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_Y);
LABEL_3:
if ( !(_BYTE)result )
goto LABEL_4;
goto LABEL_6;
default:
result = (unsigned __int8)reg_A;
if ( reg_A )
{
LABEL_6:
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
LABEL_4:
reg_PSR |= 2u;
}
return result;
}
}

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

switch ( a2 )
{
case 2:
reg_A = a1;
result = (unsigned int)a1;
goto LABEL_3;
case 3:
case 7:
result = *((unsigned __int8 *)&MEMORY_BLOCK + a1);
reg_A = *((_BYTE *)&MEMORY_BLOCK + a1);
goto LABEL_3;
case 8:
result = *((unsigned __int8 *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_X);
reg_A = *((_BYTE *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_X);
goto LABEL_3;
case 9:
result = *((unsigned __int8 *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_Y);
reg_A = *((_BYTE *)&MEMORY_BLOCK + a1 + (unsigned __int8)reg_Y);
LABEL_3:
if ( !(_BYTE)result )
goto LABEL_4;
goto LABEL_6;
default:
result = (unsigned __int8)reg_A;
if ( reg_A )
{
LABEL_6:
if ( (result & 0x10) != 0 )
reg_PSR |= 0x80u;
}
else
{
LABEL_4:
reg_PSR |= 2u;
}
return result;
}
}

original_code:
void instr_lda(long value, ADDR_MODE mode) {
    switch (mode) {
        case IMMEDIATE:
            reg_A.data = (signed char)value;
            break;
        case ZERO:
        case ABS:
            reg_A.data = (signed char)MEMORY_BLOCK[value];
            break;
        case ABS_X:
            reg_A.data = (signed char)MEMORY_BLOCK[value + (unsigned char)reg_X.data];
            break;
        case ABS_Y:
            reg_A.data = (signed char)MEMORY_BLOCK[value + (unsigned char)reg_Y.data];
            break;
        case ZERO_X:
            break;
        case ZERO_Y:
            break;
        case IDX_INDIRECT:
            break;
        case INDIRECT_IDX:
            break;
        default:
            break;
    }
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

canonical_original_code:
void instr_lda(long value, enum ADDR_MODE mode) {
    switch (mode) {
        case IMMEDIATE:
            reg_A.data = (char)value;
            break;
        case ZERO:
        case ABS:
            reg_A.data = (char)MEMORY_BLOCK[value];
            break;
        case ABS_X:
            reg_A.data = (char)MEMORY_BLOCK[value + (unsigned char)reg_X.data];
            break;
        case ABS_Y:
            reg_A.data = (char)MEMORY_BLOCK[value + (unsigned char)reg_Y.data];
            break;
        case ZERO_X:
            break;
        case ZERO_Y:
            break;
        case IDX_INDIRECT:
            break;
        case INDIRECT_IDX:
            break;
        default:
            break;
    }
    if (reg_A.data == 0x00) {
        reg_PSR.data.flags.Z = 1;
    }
    if (reg_A.data & 0x10) {
        reg_PSR.data.flags.N = 1;
    }
}

variable_types: value long

variable_types: enum ADDR_MODE { IMPLICIT=0, ACCUM=1, IMMEDIATE=2, ZERO=3, ZERO_X=4, ZERO_Y=5, RELATIVE=6, ABS=7, ABS_X=8, ABS_Y=9, INDIRECT=10, IDX_INDIRECT=11, INDIRECT_IDX=12 }


decompiled_code:
__int64 __fastcall instr_sta(__int64 a1, int a2)
{
__int64 result; // rax

if ( (a2 & 0xFFFFFFFB) == 3 )
{
result = (unsigned __int8)reg_A;
*((_BYTE *)&MEMORY_BLOCK + a1) = reg_A;
}
return result;
}

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

if ( (a2 & 0xFFFFFFFB) == 3 )
{
result = (unsigned __int8)reg_A;
*((_BYTE *)&MEMORY_BLOCK + a1) = reg_A;
}
return result;
}

original_code:
void instr_sta(long value, ADDR_MODE mode) {
    switch (mode) {
        case ZERO:
        case ABS:
            MEMORY_BLOCK[value] = (char)reg_A.data;
            break;
        default:
            break;
    }
}

canonical_original_code:
void instr_sta(long value, enum ADDR_MODE mode) {
    switch (mode) {
        case ZERO:
        case ABS:
            MEMORY_BLOCK[value] = (char)reg_A.data;
            break;
        default:
            break;
    }
}

user_defined_types: enum ADDR_MODE { IMPLICIT=0, ACCUM=1, IMMEDIATE=2, ZERO=3, ZERO_X=4, ZERO_Y=5, RELATIVE=6, ABS=7, ABS_X=8, ABS_Y=9, INDIRECT=10, IDX_INDIRECT=11, INDIRECT_IDX=12 }


decompiled_code:
void instr_clc()
{
reg_PSR &= 0xFEu;
}

canonical_decompiled_code:
void func0()
{
reg_PSR &= 0xFEu;
}

original_code:
void instr_clc() {
    reg_PSR.data.flags.C = 0;
}


decompiled_code:
void instr_sec()
{
reg_PSR |= 1u;
}

canonical_decompiled_code:
void func1()
{
reg_PSR |= 1u;
}

original_code:
void instr_sec() {
    reg_PSR.data.flags.C = 1;
}


decompiled_code:
void instr_cli()
{
reg_PSR &= 0xFBu;
}

canonical_decompiled_code:
void func2()
{
reg_PSR &= 0xFBu;
}

original_code:
void instr_cli() {
    reg_PSR.data.flags.I = 0;
}


decompiled_code:
void instr_sei()
{
reg_PSR |= 4u;
}

canonical_decompiled_code:
void func3()
{
reg_PSR |= 4u;
}

original_code:
void instr_sei() {
    reg_PSR.data.flags.I = 1;
}


decompiled_code:
void instr_clv()
{
reg_PSR &= 0xBFu;
}

canonical_decompiled_code:
void func4()
{
reg_PSR &= 0xBFu;
}

original_code:
void instr_clv() {
    reg_PSR.data.flags.V = 0;
}


decompiled_code:
void instr_cld()
{
reg_PSR &= 0xF7u;
}

canonical_decompiled_code:
void func5()
{
reg_PSR &= 0xF7u;
}

original_code:
void instr_cld() {
    reg_PSR.data.flags.D = 0;
}


decompiled_code:
void instr_sed()
{
reg_PSR |= 8u;
}

canonical_decompiled_code:
void func6()
{
reg_PSR |= 8u;
}

original_code:
void instr_sed() {
    reg_PSR.data.flags.D = 1;
}


decompiled_code:
void *init_memory()
{
return memset(&MEMORY_BLOCK, 0, (size_t)&unk_10000);
}

canonical_decompiled_code:
void *func0()
{
return memset(&MEMORY_BLOCK, 0, (size_t)&unk_10000);
}

original_code:
void init_memory(void) {
    int i;
    for (i = 0; i < 65536; i++) {
        MEMORY_BLOCK[i] = '\0';
    }
}

canonical_original_code:
void init_memory() {
    int i;
    for (i = 0; i < 65536; i++) {
        MEMORY_BLOCK[i] = '\0';
    }
}


repo: tedajax/vaders

decompiled_code:
__int64 __fastcall collider_init(__int64 a1, unsigned int a2, unsigned int a3, int a4, int a5, __m128i a6)
{
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rdx

v8 = rect_make(
(unsigned int)(int)COERCE_FLOAT(_mm_cvtsi128_si32(a6)),
(unsigned int)(int)*(float *)&a6.m128i_i32[1],
a2,
a3);
*(_DWORD *)(a1 + 16) = a4;
*(_QWORD *)a1 = v8;
result = 0x100000000LL;
*(_DWORD *)(a1 + 20) = a5;
*(_QWORD *)(a1 + 8) = v10;
*(_QWORD *)(a1 + 24) = 0x100000000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, int a4, int a5, __m128i a6)
{
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rdx

v8 = rect_make(
(unsigned int)(int)COERCE_FLOAT(_mm_cvtsi128_si32(a6)),
(unsigned int)(int)*(float *)&a6.m128i_i32[1],
a2,
a3);
*(_DWORD *)(a1 + 16) = a4;
*(_QWORD *)a1 = v8;
result = 0x100000000LL;
*(_DWORD *)(a1 + 20) = a5;
*(_QWORD *)(a1 + 8) = v10;
*(_QWORD *)(a1 + 24) = 0x100000000LL;
return result;
}

original_code:
void collider_init(collider_t *self, vec2 pos, int width, int height, int tag, int collflag)
{
 self->bounds = rect_make(pos.x, pos.y, width, height);
 self->tag = tag;
 self->collidesWith = collflag;
 self->colliding = 0;
 self->enabled = 1;
}

canonical_original_code:
void collider_init(struct collider_t *self, struct vec2 pos, int width, int height, int tag, int collflag)
{
 self->bounds = rect_make(pos.x, pos.y, width, height);
 self->tag = tag;
 self->collidesWith = collflag;
 self->colliding = 0;
 self->enabled = 1;
}

variable_types: struct collider_t { struct rect { int x; } bounds; int tag; int collidesWith; int colliding; int enabled; } *

variable_types:
pos
struct vec2 { float x; }

variable_types: width int

variable_types: height int

variable_types: tag int

variable_types: collflag int

user_defined_types: struct collider_t { struct rect bounds; int tag; int collidesWith; int colliding; int enabled; }


decompiled_code:
__int64 __fastcall collider_check_collision(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
_assert_fail("self && other", "collider.c", 0x13u, "collider_check_collision");
result = (unsigned int)(*(_DWORD *)(a2 + 16) & *(_DWORD *)(a1 + 20));
if ( (*(_DWORD *)(a2 + 16) & *(_DWORD *)(a1 + 20)) > 0 )
{
if ( *(_DWORD *)(a1 + 28) )
{
result = *(unsigned int *)(a2 + 28);
if ( (_DWORD)result )
{
result = intersect_rr(*(_QWORD *)a1, *(_QWORD *)(a1 + 8), *(_QWORD *)a2, *(_QWORD *)(a2 + 8));
if ( (_DWORD)result )
*(_DWORD *)(a1 + 24) = 1;
}
}
}
return result;
}

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

if ( !a1 || !a2 )
_assert_fail("self && other", "collider.c", 0x13u, "collider_check_collision");
result = (unsigned int)(*(_DWORD *)(a2 + 16) & *(_DWORD *)(a1 + 20));
if ( (*(_DWORD *)(a2 + 16) & *(_DWORD *)(a1 + 20)) > 0 )
{
if ( *(_DWORD *)(a1 + 28) )
{
result = *(unsigned int *)(a2 + 28);
if ( (_DWORD)result )
{
result = intersect_rr(*(_QWORD *)a1, *(_QWORD *)(a1 + 8), *(_QWORD *)a2, *(_QWORD *)(a2 + 8));
if ( (_DWORD)result )
*(_DWORD *)(a1 + 24) = 1;
}
}
}
return result;
}

original_code:
void collider_check_collision(collider_t *self, collider_t *other)
{
 ((self && other) ? (void) (0) : __assert_fail ("self && other", "collider.c", 19, __extension__ __PRETTY_FUNCTION__));
 if ((self->collidesWith & other->tag) > 0) {
  if (self->enabled && other->enabled) {
   if (intersect_rr(self->bounds, other->bounds)) {
    self->colliding = 1;
   }
  }
 }
}

canonical_original_code:
void collider_check_collision(struct collider_t *self, struct collider_t *other)
{
 ((self && other) ? (void) (0) : __assert_fail ("self && other", "collider.c", 19, __extension__ __PRETTY_FUNCTION__));
 if ((self->collidesWith & other->tag) > 0) {
  if (self->enabled && other->enabled) {
   if (intersect_rr(self->bounds, other->bounds)) {
    self->colliding = 1;
   }
  }
 }
}

variable_types:
other
struct collider_t *


decompiled_code:
__int64 colliders_init()
{
__int64 result; // rax
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

colliders = (__int64)calloc(0x320uLL, 1uLL);
stack_init(&colliderFreeIndices, 100LL, 4LL, 0LL);
v1[0] = 0;
LODWORD(result) = 0;
do
{
*(_QWORD *)(colliders + 8LL * (int)result) = 0LL;
stack_push(&colliderFreeIndices, v1);
result = (unsigned int)(v1[0] + 1);
v1[0] = result;
}
while ( (int)result <= 99 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

colliders = (__int64)calloc(0x320uLL, 1uLL);
stack_init(&colliderFreeIndices, 100LL, 4LL, 0LL);
v1[0] = 0;
LODWORD(result) = 0;
do
{
*(_QWORD *)(colliders + 8LL * (int)result) = 0LL;
stack_push(&colliderFreeIndices, v1);
result = (unsigned int)(v1[0] + 1);
v1[0] = result;
}
while ( (int)result <= 99 );
return result;
}

original_code:
void colliders_init()
{
 colliders = (collider_t **)malloc(sizeof(collider_t *) * MAX_COLLIDERS);
 memset(colliders, 0, MAX_COLLIDERS * sizeof(collider_t *));
 stack_init(&colliderFreeIndices, MAX_COLLIDERS, sizeof(int), ((void *)0));
 for (int i = 0; i < MAX_COLLIDERS; ++i) {
  colliders[i] = ((void *)0);
  stack_push(&colliderFreeIndices, (void *)&i);
 }
}

canonical_original_code:
void colliders_init()
{
 colliders = (struct collider_t **)malloc(sizeof(struct collider_t *) * MAX_COLLIDERS);
 memset(colliders, 0, MAX_COLLIDERS * sizeof(struct collider_t *));
 stack_init(&colliderFreeIndices, MAX_COLLIDERS, sizeof(int), ((void *)0));
 for (int i = 0; i < MAX_COLLIDERS; ++i) {
  colliders[i] = ((void *)0);
  stack_push(&colliderFreeIndices, (void *)&i);
 }
}


decompiled_code:
__int64 colliders_next_index()
{
__int64 result; // rax
unsigned int v1; // eax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -1;
if ( !(unsigned int)stack_size(&colliderFreeIndices)
|| (stack_pop(&colliderFreeIndices, v2), result = v2[0], v2[0] == -1) )
{
v1 = stack_size(&colliderFreeIndices);
fprintf(stderr, "Error: %d\n", v1);
result = v2[0];
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned int v1; // eax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -1;
if ( !(unsigned int)stack_size(&colliderFreeIndices)
|| (stack_pop(&colliderFreeIndices, v2), result = v2[0], v2[0] == -1) )
{
v1 = stack_size(&colliderFreeIndices);
fprintf(stderr, "Error: %d\n", v1);
result = v2[0];
}
return result;
}

original_code:
int colliders_next_index()
{
 int result = -1;
 if (stack_size(&colliderFreeIndices) > 0) {
  stack_pop(&colliderFreeIndices, &result);
 }
 if (result == -1) {
  fprintf(stderr, "Error: %d\n", stack_size(&colliderFreeIndices));
 }
 return result;
}

variable_types: result int


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

if ( !a1 )
_assert_fail("self", "collider.c", 0x2Cu, "colliders_add");
LODWORD(result) = colliders_next_index();
if ( (int)result < 0 )
_assert_fail("index >= 0", "collider.c", 0x31u, "colliders_add");
result = (int)result;
*(_QWORD *)(colliders + 8LL * (int)result) = a1;
return result;
}

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

if ( !a1 )
_assert_fail("self", "collider.c", 0x2Cu, "colliders_add");
LODWORD(result) = func3();
if ( (int)result < 0 )
_assert_fail("index >= 0", "collider.c", 0x31u, "colliders_add");
result = (int)result;
*(_QWORD *)(colliders + 8LL * (int)result) = a1;
return result;
}

original_code:
void colliders_add(collider_t *self)
{
 ((self) ? (void) (0) : __assert_fail ("self", "collider.c", 44, __extension__ __PRETTY_FUNCTION__));
 int index = colliders_next_index();
 ((index >= 0) ? (void) (0) : __assert_fail ("index >= 0", "collider.c", 49, __extension__ __PRETTY_FUNCTION__));
 colliders[index] = self;
}

canonical_original_code:
void colliders_add(struct collider_t *self)
{
 ((self) ? (void) (0) : __assert_fail ("self", "collider.c", 44, __extension__ __PRETTY_FUNCTION__));
 int index = colliders_next_index();
 ((index >= 0) ? (void) (0) : __assert_fail ("index >= 0", "collider.c", 49, __extension__ __PRETTY_FUNCTION__));
 colliders[index] = self;
}

variable_types: index int


decompiled_code:
__int64 colliders_update()
{
__int64 i; // rbp
__int64 j; // rbx
__int64 result; // rax
__int64 v3; // rdi
__int64 v4; // rsi

for ( i = 0LL; i != 100; ++i )
{
for ( j = 0LL; j != 100; ++j )
{
if ( (_DWORD)i != (_DWORD)j )
{
result = colliders;
v3 = *(_QWORD *)(colliders + 8 * i);
if ( v3 )
{
v4 = *(_QWORD *)(colliders + 8 * j);
if ( v4 )
result = collider_check_collision(v3, v4);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 i; // rbp
__int64 j; // rbx
__int64 result; // rax
__int64 v3; // rdi
__int64 v4; // rsi

for ( i = 0LL; i != 100; ++i )
{
for ( j = 0LL; j != 100; ++j )
{
if ( (_DWORD)i != (_DWORD)j )
{
result = colliders;
v3 = *(_QWORD *)(colliders + 8 * i);
if ( v3 )
{
v4 = *(_QWORD *)(colliders + 8 * j);
if ( v4 )
result = func1(v3, v4);
}
}
}
}
return result;
}

original_code:
void colliders_update()
{
 for (int i = 0; i < MAX_COLLIDERS; ++i) {
  for (int j = 0; j < MAX_COLLIDERS; ++j) {
   if (i != j) {
    if (colliders[i] && colliders[j]) {
     collider_check_collision(colliders[i], colliders[j]);
    }
   }
  }
 }
}

variable_types: j int


decompiled_code:
_DWORD *colliders_debug_draw()
{
__int64 i; // rbx
_DWORD *result; // rax

for ( i = 0LL; i != 800; i += 8LL )
{
result = *(_DWORD **)(colliders + i);
if ( result )
result = (_DWORD *)rectangleRGBA(
globals[2],
(unsigned int)(__int16)*result,
(unsigned int)(__int16)result[1],
(unsigned int)(__int16)(*result + result[2]),
(unsigned int)(__int16)(result[1] + result[3]),
255LL,
0LL,
0LL,
255LL);
}
return result;
}

canonical_decompiled_code:
_DWORD *func6()
{
__int64 i; // rbx
_DWORD *result; // rax

for ( i = 0LL; i != 800; i += 8LL )
{
result = *(_DWORD **)(colliders + i);
if ( result )
result = (_DWORD *)rectangleRGBA(
globals[2],
(unsigned int)(__int16)*result,
(unsigned int)(__int16)result[1],
(unsigned int)(__int16)(*result + result[2]),
(unsigned int)(__int16)(result[1] + result[3]),
255LL,
0LL,
0LL,
255LL);
}
return result;
}

original_code:
void colliders_debug_draw()
{
 for (int i = 0; i < MAX_COLLIDERS; ++i) {
  if (colliders[i]) {
   int x1 = colliders[i]->bounds.x;
   int y1 = colliders[i]->bounds.y;
   int x2 = x1 + colliders[i]->bounds.w;
   int y2 = y1 + colliders[i]->bounds.h;
   rectangleRGBA(globals.screen, x1, y1, x2, y2, 255, 0, 0, 255);
  }
 }
}


decompiled_code:
double enemies_calc_move()
{
__m128i v0; // xmm0
unsigned int v1; // edx
__m128i v2; // xmm0
double result; // xmm0_8

v0 = 0LL;
*(double *)v0.m128i_i64 = v2make(0.0);
v1 = _mm_cvtsi128_si32(v0);
v2 = _mm_cvtsi32_si128(v0.m128i_u32[1]);
if ( enemiesMoveRight )
{
if ( (float)(*(float *)&enemiesRight + 24.0) <= (float)SLODWORD(globals[0]) )
{
v1 = _mm_cvtsi128_si32((__m128i)(unsigned int)LC3);
}
else
{
enemiesMoveRight = 0;
v2 = (__m128i)(unsigned int)LC3;
}
}
else if ( (float)(*(float *)&enemiesLeft - 24.0) < 0.0 )
{
enemiesMoveRight = 1;
v2 = (__m128i)(unsigned int)LC3;
}
else
{
v1 = LC4;
}
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v2) << 32) | (unsigned int)_mm_cvtsi128_si32(_mm_cvtsi32_si128(v1));
return result;
}

canonical_decompiled_code:
double func2()
{
__m128i v0; // xmm0
unsigned int v1; // edx
__m128i v2; // xmm0
double result; // xmm0_8

v0 = 0LL;
*(double *)v0.m128i_i64 = v2make(0.0);
v1 = _mm_cvtsi128_si32(v0);
v2 = _mm_cvtsi32_si128(v0.m128i_u32[1]);
if ( enemiesMoveRight )
{
if ( (float)(*(float *)&enemiesRight + 24.0) <= (float)SLODWORD(globals[0]) )
{
v1 = _mm_cvtsi128_si32((__m128i)(unsigned int)LC3);
}
else
{
enemiesMoveRight = 0;
v2 = (__m128i)(unsigned int)LC3;
}
}
else if ( (float)(*(float *)&enemiesLeft - 24.0) < 0.0 )
{
enemiesMoveRight = 1;
v2 = (__m128i)(unsigned int)LC3;
}
else
{
v1 = LC4;
}
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v2) << 32) | (unsigned int)_mm_cvtsi128_si32(_mm_cvtsi32_si128(v1));
return result;
}

original_code:
vec2 enemies_calc_move()
{
 vec2 result = v2make(0, 0);
 if (enemiesMoveRight) {
  if (enemiesRight + HORIZONTAL_MOVEMENT_PER_TICK > globals.window.width) {
   enemiesMoveRight = 0;
   result.y = VERTICAL_MOVEMENT_PER_TICK;
  } else {
   result.x = HORIZONTAL_MOVEMENT_PER_TICK;
  }
 } else {
  if (enemiesLeft - HORIZONTAL_MOVEMENT_PER_TICK < 0) {
   enemiesMoveRight = 1;
   result.y = VERTICAL_MOVEMENT_PER_TICK;
  } else {
   result.x = -HORIZONTAL_MOVEMENT_PER_TICK;
  }
 }
 return result;
}

canonical_original_code:
struct vec2 enemies_calc_move()
{
 struct vec2 result = v2make(0, 0);
 if (enemiesMoveRight) {
  if (enemiesRight + HORIZONTAL_MOVEMENT_PER_TICK > globals.window.width) {
   enemiesMoveRight = 0;
   result.y = VERTICAL_MOVEMENT_PER_TICK;
  } else {
   result.x = HORIZONTAL_MOVEMENT_PER_TICK;
  }
 } else {
  if (enemiesLeft - HORIZONTAL_MOVEMENT_PER_TICK < 0) {
   enemiesMoveRight = 1;
   result.y = VERTICAL_MOVEMENT_PER_TICK;
  } else {
   result.x = -HORIZONTAL_MOVEMENT_PER_TICK;
  }
 }
 return result;
}

variable_types:
result
struct vec2 { float x; }

return_type: struct vec2 { float x; }


decompiled_code:
float **__fastcall enemies_move(double a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
double v4; // [rsp+8h] [rbp-10h]

v1 = 0LL;
v4 = a1;
do
{
while ( 1 )
{
v2 = *(_QWORD *)((char *)enemies + v1);
if ( v2 )
{
if ( !*(_DWORD *)(v2 + 48) )
break;
}
v1 += 8LL;
if ( v1 == 240 )
return enemies_update_bounds();
}
v1 += 8LL;
enemy_move(v2, v4);
}
while ( v1 != 240 );
return enemies_update_bounds();
}

canonical_decompiled_code:
float **__fastcall func4(double a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
double v4; // [rsp+8h] [rbp-10h]

v1 = 0LL;
v4 = a1;
do
{
while ( 1 )
{
v2 = *(_QWORD *)((char *)enemies + v1);
if ( v2 )
{
if ( !*(_DWORD *)(v2 + 48) )
break;
}
v1 += 8LL;
if ( v1 == 240 )
return func3();
}
v1 += 8LL;
func0(v2, v4);
}
while ( v1 != 240 );
return func3();
}

original_code:
void enemies_move(vec2 dist)
{
 for (int i = 0; i < MAX_ENEMIES; ++i) {
  if (enemies[i] && !enemies[i]->dead) {
   enemy_move(enemies[i], dist);
  }
 }
 enemies_update_bounds();
}

canonical_original_code:
void enemies_move(struct vec2 dist)
{
 for (int i = 0; i < MAX_ENEMIES; ++i) {
  if (enemies[i] && !enemies[i]->dead) {
   enemy_move(enemies[i], dist);
  }
 }
 enemies_update_bounds();
}

variable_types:
dist
struct vec2 { float x; }