strrev

decompiled_code:
char *__fastcall strrev(_BYTE *a1)
{
char *result; // rax
unsigned int v3; // ecx
unsigned int i; // esi
char *v5; // rdx
char v6; // di

result = (char *)((unsigned int)strlen(a1) - 1);
if ( (_DWORD)result )
{
v3 = (unsigned int)result;
for ( i = 0; i < v3; ++i )
{
v5 = &a1[i];
v6 = *v5;
result = &a1[v3];
*v5 = *result;
*result = v6;
--v3;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(_BYTE *a1)
{
char *result; // rax
unsigned int v3; // ecx
unsigned int i; // esi
char *v5; // rdx
char v6; // di

result = (char *)((unsigned int)func2(a1) - 1);
if ( (_DWORD)result )
{
v3 = (unsigned int)result;
for ( i = 0; i < v3; ++i )
{
v5 = &a1[i];
v6 = *v5;
result = &a1[v3];
*v5 = *result;
*result = v6;
--v3;
}
}
return result;
}

original_code:
void strrev(char s[])
{
 uint32_t i=0;
 uint32_t j=0;
 char c=0;
 for (i=0,j=strlen(s)-1; i<j;i++,j--) {
  c = s[i];
  s[i] = s[j];
  s[j] = c;
 }
}

canonical_original_code:
void strrev(char s[])
{
 unsigned int i = 0;
 unsigned int j = 0;
 char c = 0;
 for (i=0,j=strlen(s)-1; i<j;i++,j--) {
  c = s[i];
  s[i] = s[j];
  s[j] = c;
 }
}

variable_types:
s
char []

variable_types:
j
unsigned int

variable_types: c char


itoa

decompiled_code:
char *__fastcall itoa(unsigned int a1, _BYTE *a2)
{
int v2; // er8
int v3; // edx
unsigned int v4; // edx

v2 = 0;
do
{
v3 = v2++;
a2[v3] = a1 % 0xA + 48;
v4 = a1;
a1 /= 0xAu;
}
while ( v4 > 9 );
a2[v2] = 0;
return strrev(a2);
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1, _BYTE *a2)
{
int v2; // er8
int v3; // edx
unsigned int v4; // edx

v2 = 0;
do
{
v3 = v2++;
a2[v3] = a1 % 0xA + 48;
v4 = a1;
a1 /= 0xAu;
}
while ( v4 > 9 );
a2[v2] = 0;
return func4(a2);
}

original_code:
void itoa(uint32_t number, char s[])
 {
  uint32_t idx = 0;
  uint32_t sign = number;
    if (sign < 0){
     number = -number;
    }
    do {
     s[idx++] = (number % 10) + '0';
     number = number / 10;
    }while (number > 0);
     if (sign < 0){
         s[idx++] = '-';
     }
     s[idx] = '\0';
     strrev(s);
 }

canonical_original_code:
void itoa(unsigned int number, char s[])
 {
  unsigned int idx = 0;
  unsigned int sign = number;
    if (sign < 0){
     number = -number;
    }
    do {
     s[idx++] = (number % 10) + '0';
     number = number / 10;
    }while (number > 0);
     if (sign < 0){
         s[idx++] = '-';
     }
     s[idx] = '\0';
     strrev(s);
 }

variable_types:
number
unsigned int

variable_types:
idx
unsigned int

variable_types:
sign
unsigned int

return_type: void


decToHexStr

decompiled_code:
char *__fastcall decToHexStr(unsigned int a1, _BYTE *a2, _BYTE *a3, char a4)
{
unsigned int v5; // ebx
unsigned int i; // eax
unsigned int v7; // edx
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // er13
int v11; // edi
_BYTE *v12; // r12
int v13; // ebx
unsigned int v14; // eax
unsigned int v15; // edx

if ( !a1 )
{
v5 = 0;
LABEL_14:
for ( i = v5; i <= 0xF; ++i )
{
v7 = i;
a2[v7] = 48;
}
v8 = 15 - v5;
if ( v5 + 1 > 0x10 )
v8 = 0;
v5 += v8 + 1;
goto LABEL_19;
}
v5 = 0;
while ( 1 )
{
switch ( a1 & 0xF )
{
case 0xAu:
a2[v5] = 65;
break;
case 0xBu:
a2[v5] = 66;
break;
case 0xCu:
a2[v5] = 67;
break;
case 0xDu:
a2[v5] = 68;
break;
case 0xEu:
a2[v5] = 69;
break;
case 0xFu:
a2[v5] = 70;
break;
default:
a2[v5] = (a1 & 0xF) + 48;
break;
}
++v5;
if ( a1 <= 0xF )
break;
a1 >>= 4;
}
if ( v5 <= 0xF )
goto LABEL_14;
LABEL_19:
if ( a4 )
{
v9 = v5 + 1;
a2[v5] = 120;
v5 += 2;
a2[v9] = 48;
}
v10 = v5 + 1;
a2[v5] = 32;
v11 = strlen(a3);
if ( v11 )
{
v12 = &a3[v11 - 1];
v13 = v11 + v5;
v14 = v10;
do
{
v15 = v14++;
a2[v15] = *v12--;
}
while ( v13 != v15 );
v10 += v11;
}
a2[v10] = 0;
return strrev(a2);
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int a1, _BYTE *a2, _BYTE *a3, char a4)
{
unsigned int v5; // ebx
unsigned int i; // eax
unsigned int v7; // edx
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // er13
int v11; // edi
_BYTE *v12; // r12
int v13; // ebx
unsigned int v14; // eax
unsigned int v15; // edx

if ( !a1 )
{
v5 = 0;
LABEL_14:
for ( i = v5; i <= 0xF; ++i )
{
v7 = i;
a2[v7] = 48;
}
v8 = 15 - v5;
if ( v5 + 1 > 0x10 )
v8 = 0;
v5 += v8 + 1;
goto LABEL_19;
}
v5 = 0;
while ( 1 )
{
switch ( a1 & 0xF )
{
case 0xAu:
a2[v5] = 65;
break;
case 0xBu:
a2[v5] = 66;
break;
case 0xCu:
a2[v5] = 67;
break;
case 0xDu:
a2[v5] = 68;
break;
case 0xEu:
a2[v5] = 69;
break;
case 0xFu:
a2[v5] = 70;
break;
default:
a2[v5] = (a1 & 0xF) + 48;
break;
}
++v5;
if ( a1 <= 0xF )
break;
a1 >>= 4;
}
if ( v5 <= 0xF )
goto LABEL_14;
LABEL_19:
if ( a4 )
{
v9 = v5 + 1;
a2[v5] = 120;
v5 += 2;
a2[v9] = 48;
}
v10 = v5 + 1;
a2[v5] = 32;
v11 = func2(a3);
if ( v11 )
{
v12 = &a3[v11 - 1];
v13 = v11 + v5;
v14 = v10;
do
{
v15 = v14++;
a2[v15] = *v12--;
}
while ( v13 != v15 );
v10 += v11;
}
a2[v10] = 0;
return func4(a2);
}

original_code:
void decToHexStr(uint32_t num, char* output, char* title, uint8_t hasHexPrefix){
 uint32_t idx = 0;
 while(num>0){
  uint32_t remainder = num%16;
  switch(remainder){
         case 10:
             output[idx] = 'A';
             break;
         case 11:
             output[idx] = 'B';
             break;
         case 12:
             output[idx] = 'C';
             break;
         case 13:
             output[idx] = 'D';
             break;
         case 14:
             output[idx] = 'E';
             break;
         case 15:
             output[idx] = 'F';
             break;
         default :
            output[idx] = remainder + 48;
            break;
  }
  num=(uint32_t) (num/16);
  idx++;
 }
 while(idx<16 ){
  output[idx++]='0';
 }
 if(hasHexPrefix!=0){
  output[idx++] = 'x';
  output[idx++] = '0';
 }
 output[idx++] = ' ';
 uint32_t lenTitle=strlen(title);
 while(lenTitle--){
  output[idx++] = title[lenTitle];
 }
 output[idx]='\0';
 strrev(output);
}

canonical_original_code:
void decToHexStr(unsigned int num, char *output, char *title, unsigned char hasHexPrefix){
 unsigned int idx = 0;
 while(num>0){
  unsigned int remainder = num%16;
  switch(remainder){
         case 10:
             output[idx] = 'A';
             break;
         case 11:
             output[idx] = 'B';
             break;
         case 12:
             output[idx] = 'C';
             break;
         case 13:
             output[idx] = 'D';
             break;
         case 14:
             output[idx] = 'E';
             break;
         case 15:
             output[idx] = 'F';
             break;
         default :
            output[idx] = remainder + 48;
            break;
  }
  num=(unsigned int) (num/16);
  idx++;
 }
 while(idx<16 ){
  output[idx++]='0';
 }
 if(hasHexPrefix!=0){
  output[idx++] = 'x';
  output[idx++] = '0';
 }
 output[idx++] = ' ';
 unsigned int lenTitle = strlen(title);
 while(lenTitle--){
  output[idx++] = title[lenTitle];
 }
 output[idx]='\0';
 strrev(output);
}

variable_types:
num
unsigned int

variable_types:
output
char *

variable_types:
title
char *

variable_types:
hasHexPrefix
unsigned char

variable_types:
remainder
unsigned int

variable_types:
lenTitle
unsigned int


getError

decompiled_code:
const char *__fastcall getError(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "#DE Divide Error";
break;
case 1:
result = "#DB RESERVED";
break;
case 2:
result = "NMI Interrupt";
break;
case 3:
result = "#BP Breakpoint";
break;
case 4:
result = "#OF Overflow";
break;
case 5:
result = "#BR BOUND Range Exceeded";
break;
case 6:
result = "#UD Invalid Opcode (Undefined Opcode)";
break;
case 7:
result = "#NM Device Not Available (No Math Coprocessor)";
break;
case 8:
result = "#DF Double Fault";
break;
case 9:
result = "Coprocessor Segment Overrun (reserved)";
break;
case 10:
result = "#TS Invalid TSS";
break;
case 11:
result = "#NP Segment Not Present";
break;
case 12:
result = "#SS Stack-Segment Fault";
break;
case 13:
result = "#GP General Protection";
break;
case 14:
result = "#PF Page Fault";
break;
case 15:
result = "(Intel reserved. Do not use.)";
break;
case 16:
result = "#MF x87 FPU Floating-Point Error (Math Fault)";
break;
case 17:
result = "#AC Alignment Check";
break;
case 18:
result = "#MC Machine Check";
break;
case 19:
result = "#XM SIMD Floating-Point Exception";
break;
case 20:
result = "#VE Virtualization Exception";
break;
default:
result = (const char *)&unk_4D0;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "#DE Divide Error";
break;
case 1:
result = "#DB RESERVED";
break;
case 2:
result = "NMI Interrupt";
break;
case 3:
result = "#BP Breakpoint";
break;
case 4:
result = "#OF Overflow";
break;
case 5:
result = "#BR BOUND Range Exceeded";
break;
case 6:
result = "#UD Invalid Opcode (Undefined Opcode)";
break;
case 7:
result = "#NM Device Not Available (No Math Coprocessor)";
break;
case 8:
result = "#DF Double Fault";
break;
case 9:
result = "Coprocessor Segment Overrun (reserved)";
break;
case 10:
result = "#TS Invalid TSS";
break;
case 11:
result = "#NP Segment Not Present";
break;
case 12:
result = "#SS Stack-Segment Fault";
break;
case 13:
result = "#GP General Protection";
break;
case 14:
result = "#PF Page Fault";
break;
case 15:
result = "(Intel reserved. Do not use.)";
break;
case 16:
result = "#MF x87 FPU Floating-Point Error (Math Fault)";
break;
case 17:
result = "#AC Alignment Check";
break;
case 18:
result = "#MC Machine Check";
break;
case 19:
result = "#XM SIMD Floating-Point Exception";
break;
case 20:
result = "#VE Virtualization Exception";
break;
default:
result = (const char *)&unk_4D0;
break;
}
return result;
}

original_code:
char* getError(uint32_t codError){
char* descripcion;
 switch(codError)
 {
  case 0:
   descripcion = "#DE Divide Error";
  break;
  case 1:
   descripcion = "#DB RESERVED";
  break;
  case 2:
   descripcion = "NMI Interrupt";
  break;
  case 3:
   descripcion = "#BP Breakpoint";
  break;
  case 4:
   descripcion = "#OF Overflow";
  break;
  case 5:
   descripcion = "#BR BOUND Range Exceeded";
  break;
  case 6:
   descripcion = "#UD Invalid Opcode (Undefined Opcode)";
  break;
  case 7:
   descripcion = "#NM Device Not Available (No Math Coprocessor)";
  break;
  case 8:
   descripcion = "#DF Double Fault";
  break;
  case 9:
   descripcion = "Coprocessor Segment Overrun (reserved)";
  break;
  case 10:
   descripcion = "#TS Invalid TSS";
  break;
  case 11:
   descripcion = "#NP Segment Not Present";
  break;
  case 12:
   descripcion = "#SS Stack-Segment Fault";
  break;
  case 13:
   descripcion = "#GP General Protection";
  break;
  case 14:
   descripcion = "#PF Page Fault";
  break;
  case 15:
   descripcion = "(Intel reserved. Do not use.)";
  break;
  case 16:
   descripcion = "#MF x87 FPU Floating-Point Error (Math Fault)";
  break;
  case 17:
   descripcion = "#AC Alignment Check";
  break;
  case 18:
   descripcion = "#MC Machine Check";
  break;
  case 19:
   descripcion = "#XM SIMD Floating-Point Exception";
  break;
  case 20:
   descripcion = "#VE Virtualization Exception";
  break;
  default:
   descripcion = "";
  break;
 }
 return descripcion;
}

canonical_original_code:
char *getError(unsigned int codError){
char *descripcion;
 switch(codError)
 {
  case 0:
   descripcion = "#DE Divide Error";
  break;
  case 1:
   descripcion = "#DB RESERVED";
  break;
  case 2:
   descripcion = "NMI Interrupt";
  break;
  case 3:
   descripcion = "#BP Breakpoint";
  break;
  case 4:
   descripcion = "#OF Overflow";
  break;
  case 5:
   descripcion = "#BR BOUND Range Exceeded";
  break;
  case 6:
   descripcion = "#UD Invalid Opcode (Undefined Opcode)";
  break;
  case 7:
   descripcion = "#NM Device Not Available (No Math Coprocessor)";
  break;
  case 8:
   descripcion = "#DF Double Fault";
  break;
  case 9:
   descripcion = "Coprocessor Segment Overrun (reserved)";
  break;
  case 10:
   descripcion = "#TS Invalid TSS";
  break;
  case 11:
   descripcion = "#NP Segment Not Present";
  break;
  case 12:
   descripcion = "#SS Stack-Segment Fault";
  break;
  case 13:
   descripcion = "#GP General Protection";
  break;
  case 14:
   descripcion = "#PF Page Fault";
  break;
  case 15:
   descripcion = "(Intel reserved. Do not use.)";
  break;
  case 16:
   descripcion = "#MF x87 FPU Floating-Point Error (Math Fault)";
  break;
  case 17:
   descripcion = "#AC Alignment Check";
  break;
  case 18:
   descripcion = "#MC Machine Check";
  break;
  case 19:
   descripcion = "#XM SIMD Floating-Point Exception";
  break;
  case 20:
   descripcion = "#VE Virtualization Exception";
  break;
  default:
   descripcion = "";
  break;
 }
 return descripcion;
}

variable_types:
codError
unsigned int

variable_types:
descripcion
char *

return_type: char *


strcpy

decompiled_code:
__int64 __fastcall strcpy(__int64 a1, char *a2)
{
char v2; // dl
__int64 result; // rax

v2 = *a2;
if ( *a2 )
{
result = 0LL;
do
{
*(_BYTE *)(a1 + result++) = v2;
v2 = a2[result];
}
while ( v2 );
}
else
{
result = 0LL;
}
*(_BYTE *)(a1 + result) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
char v2; // dl
__int64 result; // rax

v2 = *a2;
if ( *a2 )
{
result = 0LL;
do
{
*(_BYTE *)(a1 + result++) = v2;
v2 = a2[result];
}
while ( v2 );
}
else
{
result = 0LL;
}
*(_BYTE *)(a1 + result) = 0;
return result;
}

original_code:
void strcpy(char* dst, const char* src)
{
        uint64_t i;
        for(i = 0; src[i] != '\0'; i++) {
                dst[i] = src[i];
        }
        dst[i] = '\0';
}

canonical_original_code:
void strcpy(char *dst, char *src)
{
        unsigned long long i;
        for(i = 0; src[i] != '\0'; i++) {
                dst[i] = src[i];
        }
        dst[i] = '\0';
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
i
unsigned long long


strcat

decompiled_code:
__int64 __fastcall strcat(_BYTE *a1, char *a2)
{
__int64 v2; // rdx
char v3; // cl
__int64 result; // rax
char *v5; // rsi

if ( *a1 )
{
v2 = 0LL;
do
++v2;
while ( a1[v2] );
}
else
{
v2 = 0LL;
}
v3 = *a2;
if ( *a2 )
{
result = v2;
v5 = &a2[-v2];
do
{
a1[result++] = v3;
v3 = v5[result];
}
while ( v3 );
}
else
{
result = v2;
}
a1[result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, char *a2)
{
__int64 v2; // rdx
char v3; // cl
__int64 result; // rax
char *v5; // rsi

if ( *a1 )
{
v2 = 0LL;
do
++v2;
while ( a1[v2] );
}
else
{
v2 = 0LL;
}
v3 = *a2;
if ( *a2 )
{
result = v2;
v5 = &a2[-v2];
do
{
a1[result++] = v3;
v3 = v5[result];
}
while ( v3 );
}
else
{
result = v2;
}
a1[result] = 0;
return result;
}

original_code:
void strcat(char* dst, const char* src)
{
        uint64_t i = 0, j = 0;
        while(dst[i]) {
                i++;
        }
        while(src[j]) {
                dst[i] = src[j];
                i++; j++;
        }
        dst[i] = '\0';
}

canonical_original_code:
void strcat(char *dst, char *src)
{
        unsigned long long i = 0; unsigned long long j = 0;
        while(dst[i]) {
                i++;
        }
        while(src[j]) {
                dst[i] = src[j];
                i++; j++;
        }
        dst[i] = '\0';
}

variable_types:
j
unsigned long long


memcmp

decompiled_code:
__int64 __fastcall memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( a3 == ++v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( a3 == ++v3 )
return 0LL;
}
return 1LL;
}

original_code:
uint64_t memcmp(const void* _m1, const void* _m2, uint64_t bytes)
{
        const char* m1 = _m1, * m2 = _m2;
        for(uint64_t i = 0; i < bytes; i++)
                if(m1[i] != m2[i]) {
                    return 1;
                }
        return 0;
}

canonical_original_code:
unsigned long long memcmp(void *_m1, void *_m2, unsigned long long bytes)
{
        char *m1 = _m1; char *m2 = _m2;
        for(unsigned long long i = 0; i < bytes; i++)
                if(m1[i] != m2[i]) {
                    return 1;
                }
        return 0;
}

variable_types:
bytes
unsigned long long

return_type: unsigned long long


strcmp

decompiled_code:
__int64 __fastcall strcmp(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax

v2 = *a1;
if ( *a1 != *a2 )
return 1LL;
v3 = 0LL;
while ( v2 )
{
v2 = a1[++v3];
if ( v2 != a2[v3] )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax

v2 = *a1;
if ( *a1 != *a2 )
return 1LL;
v3 = 0LL;
while ( v2 )
{
v2 = a1[++v3];
if ( v2 != a2[v3] )
return 1LL;
}
return 0LL;
}

original_code:
uint64_t strcmp(const char* str1, const char* str2)
{
        uint64_t i;
        for(i = 0; str1[i] == str2[i]; i++)
                if(str1[i] == '\0') {
                    return 0;
                }
        return 1;
}

canonical_original_code:
unsigned long long strcmp(char *str1, char *str2)
{
        unsigned long long i;
        for(i = 0; str1[i] == str2[i]; i++)
                if(str1[i] == '\0') {
                    return 0;
                }
        return 1;
}


strncpy

original_code:
void strncpy(char* dst, const char* src, uint64_t len)
{
        for(uint64_t i = 0; i < len; i++) {
                if(src[i] == '\0') {
                        dst[i] = '\0';
                        return;
                }
                dst[i] = src[i];
        }
}

canonical_original_code:
void strncpy(char *dst, char *src, unsigned long long len)
{
        for(unsigned long long i = 0; i < len; i++) {
                if(src[i] == '\0') {
                        dst[i] = '\0';
                        return;
                }
                dst[i] = src[i];
        }
}

variable_types:
len
unsigned long long


abs

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

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

original_code:
static double abs(double a)
{
    return a < 0.0 ? -a : a;
}

variable_types: a double

return_type: double


decompiled_code:
__int64 sort_monocore()
{
return heapsort(367001600LL, MEMORY[0x200600]);
}

canonical_original_code:
void sort_monocore()
{
    heapsort(
        (unsigned int *) (0x1e00000 + 32 * 0xa00000),
        *((unsigned int *) 0x200600)
    );
}


wait

decompiled_code:
unsigned __int64 wait()
{
unsigned __int64 v0; // rsi
unsigned __int64 result; // rax

_mm_mfence();
v0 = __rdtsc();
start = v0;
do
{
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
result = __rdtsc();
}
while ( result - v0 <= 0x13D18C1FFLL );
stop = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 func2()
{
unsigned __int64 v0; // rsi
unsigned __int64 result; // rax

_mm_mfence();
v0 = __rdtsc();
start = v0;
do
{
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
result = __rdtsc();
}
while ( result - v0 <= 0x13D18C1FFLL );
stop = result;
return result;
}

original_code:
void wait()
{
    uint64_t limit = 5320000000;
    { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
    do {
        { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
    } while ((stop - start) < limit);
    return;
}

canonical_original_code:
void wait()
{
    unsigned long limit = 5320000000;
    { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
    do {
        { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
    } while ((stop - start) < limit);
    return;
}

variable_types:
limit
unsigned long


rand

canonical_original_code:
unsigned int rand()
{
    unsigned long seed = *((uint64_t *) 0x200500);
    seed = seed * 1103515245 + 12345;
    *((unsigned long *) 0x200500) = seed;
    return (unsigned int) (seed / 65536) % 32768;
}

variable_types:
seed
unsigned long

return_type: unsigned int


decompiled_code:
__int64 verfiy_sort()
{
__int64 v0; // rax
unsigned int v1; // edx

if ( MEMORY[0x200600] <= 1u )
return 1LL;
v0 = 367001600LL;
while ( 1 )
{
v1 = *(_DWORD *)v0;
v0 += 4LL;
if ( v1 > *(_DWORD *)v0 )
break;
if ( v0 == 4LL * (unsigned int)(MEMORY[0x200600] - 2) + 367001604 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
unsigned int v1; // edx

if ( MEMORY[0x200600] <= 1u )
return 1LL;
v0 = 367001600LL;
while ( 1 )
{
v1 = *(_DWORD *)v0;
v0 += 4LL;
if ( v1 > *(_DWORD *)v0 )
break;
if ( v0 == 4LL * (unsigned int)(MEMORY[0x200600] - 2) + 367001604 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool verfiy_sort(uint32_t len)
{
    for (uint32_t i = 1; i < len; ++i) {
        if (array[i - 1] > array[i]) {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
_Bool verfiy_sort(unsigned int len)
{
    for (unsigned int i = 1; i < len; ++i) {
        if (array[i - 1] > array[i]) {
            return 0;
        }
    }
    return 1;
}

variable_types:
len
unsigned int

variable_types:
i
unsigned int


original_code:
void clean_array(uint32_t len)
{
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    for (uint32_t i = 0; i < len; ++i) {
        array[i] = 0;
    }
}

canonical_original_code:
void clean_array(unsigned int len)
{
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    for (unsigned int i = 0; i < len; ++i) {
        array[i] = 0;
    }
}

variable_types:
array
unsigned int *


decompiled_code:
__int64 __fastcall test_suite_sort(void (*a1)(void), unsigned __int8 a2, int a3, __int64 a4)
{
unsigned int v4; // er14
int v5; // er12
__int64 i; // rax
int v7; // er15
double v8; // xmm0_8
__int64 v9; // rsi
__int64 v10; // rbp
unsigned __int64 v11; // rax
__int64 v12; // rcx
unsigned __int64 v13; // rbx
__int64 v14; // rbx
int v15; // ebp
__int64 j; // rbx
unsigned __int64 v17; // rdi
double v18; // xmm0_8

v4 = a2;
v5 = a3 + 1;
print_string(a4, (unsigned __int8)a3, a2);
for ( i = 2100736LL; i != 2100920; i += 8LL )
*(_QWORD *)i = 0LL;
v7 = 5;
do
{
MEMORY[0x200600] = 2;
v10 = 2100736LL;
v9 = 2LL;
do
{
generate_global_array(13214LL, v9);
_mm_mfence();
start = __rdtsc();
a1();
_mm_mfence();
__rdtsc();
_mm_mfence();
v11 = __rdtsc();
v12 = (unsigned int)v11;
_mm_mfence();
v13 = __rdtsc();
stop = v13;
if ( (unsigned int)verfiy_sort(13214LL, v9, (unsigned int)v13, v12) )
{
v14 = v13 - start;
if ( v14 < 0 )
v8 = (double)(int)(v14 & 1 | ((unsigned __int64)v14 >> 1))
+ (double)(int)(v14 & 1 | ((unsigned __int64)v14 >> 1));
else
v8 = (double)(int)v14;
*(double *)v10 = v8 + *(double *)v10;
}
else
{
print_string("bad sort :(", (unsigned __int8)v5++, v4);
}
v9 = (unsigned int)(2 * MEMORY[0x200600]);
MEMORY[0x200600] = v9;
v10 += 8LL;
}
while ( (unsigned int)v9 <= 0x7FFFFF );
--v7;
}
while ( v7 );
v15 = v5;
for ( j = 2100736LL; j != 2100920; j += 8LL )
{
v18 = *(double *)j / 5.0;
if ( v18 >= 9.223372036854776e18 )
v17 = (unsigned int)(int)(v18 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v17 = (unsigned int)(int)v18;
print_number_u64(v17, (unsigned __int8)v15++, v4);
}
return print_string("Done! :D", (unsigned __int8)(v5 + 23), v4);
}

canonical_decompiled_code:
__int64 __fastcall func7(void (*a1)(void), unsigned __int8 a2, int a3, __int64 a4)
{
unsigned int v4; // er14
int v5; // er12
__int64 i; // rax
int v7; // er15
double v8; // xmm0_8
__int64 v9; // rsi
__int64 v10; // rbp
unsigned __int64 v11; // rax
__int64 v12; // rcx
unsigned __int64 v13; // rbx
__int64 v14; // rbx
int v15; // ebp
__int64 j; // rbx
unsigned __int64 v17; // rdi
double v18; // xmm0_8

v4 = a2;
v5 = a3 + 1;
print_string(a4, (unsigned __int8)a3, a2);
for ( i = 2100736LL; i != 2100920; i += 8LL )
*(_QWORD *)i = 0LL;
v7 = 5;
do
{
MEMORY[0x200600] = 2;
v10 = 2100736LL;
v9 = 2LL;
do
{
func4(13214LL, v9);
_mm_mfence();
start = __rdtsc();
a1();
_mm_mfence();
__rdtsc();
_mm_mfence();
v11 = __rdtsc();
v12 = (unsigned int)v11;
_mm_mfence();
v13 = __rdtsc();
stop = v13;
if ( (unsigned int)func5(13214LL, v9, (unsigned int)v13, v12) )
{
v14 = v13 - start;
if ( v14 < 0 )
v8 = (double)(int)(v14 & 1 | ((unsigned __int64)v14 >> 1))
+ (double)(int)(v14 & 1 | ((unsigned __int64)v14 >> 1));
else
v8 = (double)(int)v14;
*(double *)v10 = v8 + *(double *)v10;
}
else
{
print_string("bad sort :(", (unsigned __int8)v5++, v4);
}
v9 = (unsigned int)(2 * MEMORY[0x200600]);
MEMORY[0x200600] = v9;
v10 += 8LL;
}
while ( (unsigned int)v9 <= 0x7FFFFF );
--v7;
}
while ( v7 );
v15 = v5;
for ( j = 2100736LL; j != 2100920; j += 8LL )
{
v18 = *(double *)j / 5.0;
if ( v18 >= 9.223372036854776e18 )
v17 = (unsigned int)(int)(v18 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v17 = (unsigned int)(int)v18;
print_number_u64(v17, (unsigned __int8)v15++, v4);
}
return print_string("Done! :D", (unsigned __int8)(v5 + 23), v4);
}

original_code:
void test_suite_sort(sort_test function, uint8_t col, uint8_t line, const char *header)
{
    uint32_t *len = (uint32_t *) 0x200600;
    print_string(header, line++, col);
    int iter;
    double *run_measures = (double *) 0x200e00;
    for (int i = 0; i < 23; ++i) {
        run_measures[i] = 0;
    }
    for (int run = 0; run < 5; ++run) {
        for (iter = 0, *len = 2; *len < (8*1024*1024); *len <<= 1, iter++) {
            uint32_t seed = 13214;
            generate_global_array(seed, *len);
            { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
            function();
            { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
            if (verfiy_sort()) {
                run_measures[iter] += stop - start;
            } else {
                print_string("bad sort :(", line++, col);
            }
        }
    }
    for (int i = 0; i < 23; i++, line++) {
        uint64_t res = run_measures[i] / ((double) 5);
        print_number_u64(res, line, col);
    }
    print_string("Done! :D", line, col);
}

canonical_original_code:
void test_suite_sort(void (*function)(), unsigned char col, unsigned char line, char *header)
{
    unsigned int *len = (uint32_t *) 0x200600;
    print_string(header, line++, col);
    int iter;
    double *run_measures = (double *) 0x200e00;
    for (int i = 0; i < 23; ++i) {
        run_measures[i] = 0;
    }
    for (int run = 0; run < 5; ++run) {
        for (iter = 0, *len = 2; *len < (8*1024*1024); *len <<= 1, iter++) {
            unsigned int seed = 13214;
            generate_global_array(seed, *len);
            { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
            function();
            { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
            if (verfiy_sort()) {
                run_measures[iter] += stop - start;
            } else {
                print_string("bad sort :(", line++, col);
            }
        }
    }
    for (int i = 0; i < 23; i++, line++) {
        unsigned long res = run_measures[i] / ((double) 5);
        print_number_u64(res, line, col);
    }
    print_string("Done! :D", line, col);
}

variable_types:
function
void (*)()

variable_types:
col
unsigned char

variable_types:
line
unsigned char

variable_types:
header
char *

variable_types:
len
unsigned int *

variable_types: iter int

variable_types: i int

variable_types: run int

variable_types:
seed
unsigned int

variable_types:
res
unsigned long


decompiled_code:
__int64 test_1_core()
{
clean_array(0x800000);
clear_screen();
return test_suite_sort((void (*)(void))sort_monocore, 0, 0, (__int64)"Test 1 core");
}

canonical_decompiled_code:
__int64 func8()
{
func6(0x800000);
clear_screen();
return func7((void (*)(void))sort_monocore, 0, 0, (__int64)"Test 1 core");
}

original_code:
void test_1_core()
{
    clean_array((8*1024*1024));
    clear_screen();
    test_suite_sort(sort_monocore, 0, 0, "Test 1 core");
}


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

result = test_suite_sort((void (*)(void))&sort_bsp, 0x1Eu, 0, (__int64)"Test 2 cores");
MEMORY[0x200200] = 1;
return result;
}

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

result = func7((void (*)(void))&sort_bsp, 0x1Eu, 0, (__int64)"Test 2 cores");
MEMORY[0x200200] = 1;
return result;
}

original_code:
void test_2_cores()
{
    test_suite_sort(sort_bsp, 30, 0, "Test 2 cores");
    *((uint8_t *) 0x200200) = 1;
}

canonical_original_code:
void test_2_cores()
{
    test_suite_sort(sort_bsp, 30, 0, "Test 2 cores");
    *((unsigned char *) 0x200200) = 1;
}


decompiled_code:
__int64 test_ipi_cores()
{
return test_suite_sort((void (*)(void))&sort_bsp_ipi, 0x3Cu, 0, (__int64)"Test Dual Ipis");
}

canonical_decompiled_code:
__int64 func10()
{
return func7((void (*)(void))&sort_bsp_ipi, 0x3Cu, 0, (__int64)"Test Dual Ipis");
}

original_code:
void test_ipi_cores()
{
    test_suite_sort(sort_bsp_ipi, 60, 0, "Test Dual Ipis");
}


decompiled_code:
__int64 test_sync_ipi_cores()
{
int v0; // ebx
__int64 v1; // rsi
__int64 v2; // rdx
__int64 v3; // rcx
int *v4; // rbp
unsigned int v5; // ebx
__int64 result; // rax
int v7; // [rsp+Ah] [rbp-1Eh] BYREF
__int16 v8; // [rsp+Eh] [rbp-1Ah]
char v9; // [rsp+10h] [rbp-18h] BYREF

wait();
wait();
clear_screen();
v7 = 656018688;
v8 = 16692;
print_string("Test Dual Ipis", 0LL, 0LL);
print_string("Sync", 1LL, 13LL);
print_string("Sync", 1LL, 39LL);
print_string("Sync", 1LL, 65LL);
MEMORY[0x200600] = 2;
v0 = 1;
v1 = 2LL;
do
{
generate_global_array(13214LL, v1);
measure_sync_ipis();
if ( (unsigned int)verfiy_sort(13214LL, v1, v2, v3) )
{
print_number_u64(MEMORY[0x200D08], (unsigned __int8)++v0, BYTE1(v7));
print_number_u64(MEMORY[0x200D18], (unsigned __int8)v0, HIBYTE(v7));
print_number_u64(MEMORY[0x200D28], (unsigned __int8)v0, HIBYTE(v8));
}
else
{
print_string("bad_sort :(", (unsigned __int8)v0, BYTE1(v7));
print_string("bad_sort :(", (unsigned __int8)(v0 + 1), HIBYTE(v7));
v0 += 2;
}
v1 = (unsigned int)(2 * MEMORY[0x200600]);
MEMORY[0x200600] = v1;
}
while ( (unsigned int)v1 <= 0x7FFFFF );
v4 = &v7;
v5 = (unsigned __int8)(v0 + 1);
do
{
result = print_string("Done!", v5, *((unsigned __int8 *)v4 + 1));
v4 = (int *)((char *)v4 + 2);
}
while ( v4 != (int *)&v9 );
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebx
__int64 v1; // rsi
__int64 v2; // rdx
__int64 v3; // rcx
int *v4; // rbp
unsigned int v5; // ebx
__int64 result; // rax
int v7; // [rsp+Ah] [rbp-1Eh] BYREF
__int16 v8; // [rsp+Eh] [rbp-1Ah]
char v9; // [rsp+10h] [rbp-18h] BYREF

func2();
func2();
clear_screen();
v7 = 656018688;
v8 = 16692;
print_string("Test Dual Ipis", 0LL, 0LL);
print_string("Sync", 1LL, 13LL);
print_string("Sync", 1LL, 39LL);
print_string("Sync", 1LL, 65LL);
MEMORY[0x200600] = 2;
v0 = 1;
v1 = 2LL;
do
{
func4(13214LL, v1);
measure_sync_ipis();
if ( (unsigned int)func5(13214LL, v1, v2, v3) )
{
print_number_u64(MEMORY[0x200D08], (unsigned __int8)++v0, BYTE1(v7));
print_number_u64(MEMORY[0x200D18], (unsigned __int8)v0, HIBYTE(v7));
print_number_u64(MEMORY[0x200D28], (unsigned __int8)v0, HIBYTE(v8));
}
else
{
print_string("bad_sort :(", (unsigned __int8)v0, BYTE1(v7));
print_string("bad_sort :(", (unsigned __int8)(v0 + 1), HIBYTE(v7));
v0 += 2;
}
v1 = (unsigned int)(2 * MEMORY[0x200600]);
MEMORY[0x200600] = v1;
}
while ( (unsigned int)v1 <= 0x7FFFFF );
v4 = &v7;
v5 = (unsigned __int8)(v0 + 1);
do
{
result = print_string("Done!", v5, *((unsigned __int8 *)v4 + 1));
v4 = (int *)((char *)v4 + 2);
}
while ( v4 != (int *)&v9 );
return result;
}

original_code:
void test_sync_ipi_cores()
{
    wait();
    wait();
    clear_screen();
    uint32_t *len = (uint32_t *) 0x200600;
    uint64_t *time_measures = (uint64_t *) 0x200d00;
    uint8_t col[6] = {0, 13, 26, 39, 52, 65};
    uint8_t line = 0;
    print_string("Test Dual Ipis", line++, col[0]);
    print_string("Sync", line, col[1]);
    print_string("Sync", line, col[3]);
    print_string("Sync", line, col[5]);
    for (*len = 2; *len < (8*1024*1024); *len *= 2) {
        uint32_t seed = 13214;
        generate_global_array(seed, *len);
        measure_sync_ipis();
        if (verfiy_sort()) {
            line++;
            uint8_t i;
            for (i = 1; i < 6; i += 2) {
                print_number_u64(time_measures[i], line, col[i]);
            }
        } else {
            for (uint8_t i = 1; i < 5; i += 2) {
                print_string("bad_sort :(", line++, col[i]);
            }
        }
    }
    uint8_t i;
    line++;
    for (i = 1; i < 6; i += 2) {
        print_string("Done!", line, col[i]);
    }
}

canonical_original_code:
void test_sync_ipi_cores()
{
    wait();
    wait();
    clear_screen();
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned long *time_measures = (uint64_t *) 0x200d00;
    unsigned char col[6] = {0, 13, 26, 39, 52, 65};
    unsigned char line = 0;
    print_string("Test Dual Ipis", line++, col[0]);
    print_string("Sync", line, col[1]);
    print_string("Sync", line, col[3]);
    print_string("Sync", line, col[5]);
    for (*len = 2; *len < (8*1024*1024); *len *= 2) {
        unsigned int seed = 13214;
        generate_global_array(seed, *len);
        measure_sync_ipis();
        if (verfiy_sort()) {
            line++;
            unsigned char i;
            for (i = 1; i < 6; i += 2) {
                print_number_u64(time_measures[i], line, col[i]);
            }
        } else {
            for (unsigned char i = 1; i < 5; i += 2) {
                print_string("bad_sort :(", line++, col[i]);
            }
        }
    }
    unsigned char i;
    line++;
    for (i = 1; i < 6; i += 2) {
        print_string("Done!", line, col[i]);
    }
}

variable_types:
col
unsigned char [6]

variable_types:
i
unsigned char


original_code:
void sum_vector(uint32_t len)
{
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    for (uint32_t i = 0; i < len; ++i) {
        array[i]++;
    }
}

canonical_original_code:
void sum_vector(unsigned int len)
{
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    for (unsigned int i = 0; i < len; ++i) {
        array[i]++;
    }
}


decompiled_code:
__int64 test_sum_vector1()
{
int v0; // ebx
unsigned __int8 v1; // bp

print_string("sum 1 core", 0LL, 68LL);
MEMORY[0x200600] = 2;
v0 = 1;
do
{
_mm_mfence();
start = __rdtsc();
sum_vector(MEMORY[0x200600]);
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
v1 = v0++;
print_number_u64(stop - start, v1, 68LL);
MEMORY[0x200600] *= 2;
}
while ( MEMORY[0x200600] <= 0x7FFFFFu );
return print_string("Done! :D", (unsigned __int8)(v1 + 2), 68LL);
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebx
unsigned __int8 v1; // bp

print_string("sum 1 core", 0LL, 68LL);
MEMORY[0x200600] = 2;
v0 = 1;
do
{
_mm_mfence();
start = __rdtsc();
func13(MEMORY[0x200600]);
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
v1 = v0++;
print_number_u64(stop - start, v1, 68LL);
MEMORY[0x200600] *= 2;
}
while ( MEMORY[0x200600] <= 0x7FFFFFu );
return print_string("Done! :D", (unsigned __int8)(v1 + 2), 68LL);
}

original_code:
void test_sum_vector1()
{
    uint32_t *len = (uint32_t *) 0x200600;
    uint8_t col = 68;
    uint8_t line = 0;
    print_string("sum 1 core", line++, col);
    for (*len = 2; *len < (8*1024*1024); *len *= 2) {
        { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
        sum_vector(*len);
        { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
        print_number_u64(stop - start, line++, col);
    }
    print_string("Done! :D", ++line, col);
}

canonical_original_code:
void test_sum_vector1()
{
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned char col = 68;
    unsigned char line = 0;
    print_string("sum 1 core", line++, col);
    for (*len = 2; *len < (8*1024*1024); *len *= 2) {
        { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
        sum_vector(*len);
        { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
        print_number_u64(stop - start, line++, col);
    }
    print_string("Done! :D", ++line, col);
}


decompiled_code:
__int64 test_sum_vector2()
{
int v0; // ebx
unsigned __int8 v1; // bp
__int64 result; // rax

print_string("sum 2 cores", 0LL, 102LL);
MEMORY[0x200600] = 2;
v0 = 1;
do
{
_mm_mfence();
start = __rdtsc();
sum_vector_bsp();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
v1 = v0++;
print_number_u64(stop - start, v1, 102LL);
MEMORY[0x200600] *= 2;
}
while ( MEMORY[0x200600] <= 0x7FFFFFu );
result = print_string("Done! :D", (unsigned __int8)(v1 + 2), 102LL);
MEMORY[0x200200] = 1;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // ebx
unsigned __int8 v1; // bp
__int64 result; // rax

print_string("sum 2 cores", 0LL, 102LL);
MEMORY[0x200600] = 2;
v0 = 1;
do
{
_mm_mfence();
start = __rdtsc();
sum_vector_bsp();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
v1 = v0++;
print_number_u64(stop - start, v1, 102LL);
MEMORY[0x200600] *= 2;
}
while ( MEMORY[0x200600] <= 0x7FFFFFu );
result = print_string("Done! :D", (unsigned __int8)(v1 + 2), 102LL);
MEMORY[0x200200] = 1;
return result;
}

original_code:
void test_sum_vector2()
{
    uint32_t *len = (uint32_t *) 0x200600;
    uint8_t *sleep = (uint8_t *) 0x200200;
    uint8_t col = 102;
    uint8_t line = 0;
    print_string("sum 2 cores", line++, col);
    for (*len = 2; *len < (8*1024*1024); *len *= 2) {
        { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
        sum_vector_bsp();
        { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
        print_number_u64(stop - start, line++, col);
    }
    print_string("Done! :D", ++line, col);
    *sleep = 1;
}

canonical_original_code:
void test_sum_vector2()
{
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned char *sleep = (uint8_t *) 0x200200;
    unsigned char col = 102;
    unsigned char line = 0;
    print_string("sum 2 cores", line++, col);
    for (*len = 2; *len < (8*1024*1024); *len *= 2) {
        { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); start = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
        sum_vector_bsp();
        { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
        print_number_u64(stop - start, line++, col);
    }
    print_string("Done! :D", ++line, col);
    *sleep = 1;
}

variable_types:
sleep
unsigned char *


original_code:
void generate_fft_array(uint32_t N)
{
    Complex *array = (Complex *) (0x1e00000 + 32 * 0xa00000);
    for (uint32_t i = 0; i < N / 2; ++i) {
        array[i].m_re = 1.0;
        array[i].m_im = 0.0;
    }
    for (uint32_t i = N / 2; i < N; ++i) {
        array[i].m_re = 0.0;
        array[i].m_im = 0.0;
    }
}

canonical_original_code:
void generate_fft_array(unsigned int N)
{
    struct s_complex *array = (Complex *) (0x1e00000 + 32 * 0xa00000);
    for (unsigned int i = 0; i < N / 2; ++i) {
        array[i].m_re = 1.0;
        array[i].m_im = 0.0;
    }
    for (unsigned int i = N / 2; i < N; ++i) {
        array[i].m_re = 0.0;
        array[i].m_im = 0.0;
    }
}

variable_types:
N
unsigned int

variable_types: struct s_complex { double m_re; double m_im; } *


decompiled_code:
__int64 test_fft_mono()
{
return test_suite_fft(
(void (__fastcall *)(__int64, __int64, _QWORD, __int64))&Inverse_IO,
0,
0,
(__int64)"fft monocore");
}

canonical_decompiled_code:
__int64 func20()
{
return func19(
(void (__fastcall *)(__int64, __int64, _QWORD, __int64))&Inverse_IO,
0,
0,
(__int64)"fft monocore");
}

original_code:
void test_fft_mono()
{
    test_suite_fft(Inverse_IO, 0, 0, "fft monocore");
}


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

clear_screen();
result = test_suite_fft(
(void (__fastcall *)(__int64, __int64, _QWORD, __int64))&Inverse_IO_Dual,
0,
0x1Eu,
(__int64)"fft dualcore");
MEMORY[0x200200] = 1;
return result;
}

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

clear_screen();
result = func19(
(void (__fastcall *)(__int64, __int64, _QWORD, __int64))&Inverse_IO_Dual,
0,
0x1Eu,
(__int64)"fft dualcore");
MEMORY[0x200200] = 1;
return result;
}

original_code:
void test_fft_dual_mem()
{
    clear_screen();
    test_suite_fft(Inverse_IO_Dual, 0, 30, "fft dualcore");
    *((uint8_t *) 0x200200) = 1;
}

canonical_original_code:
void test_fft_dual_mem()
{
    clear_screen();
    test_suite_fft(Inverse_IO_Dual, 0, 30, "fft dualcore");
    *((unsigned char *) 0x200200) = 1;
}


decompiled_code:
__int64 test_fft_dual_ipi()
{
return test_suite_fft(
(void (__fastcall *)(__int64, __int64, _QWORD, __int64))&Inverse_IO_Ipi,
0,
0x3Cu,
(__int64)"fft dualcore ipis");
}

canonical_decompiled_code:
__int64 func22()
{
return func19(
(void (__fastcall *)(__int64, __int64, _QWORD, __int64))&Inverse_IO_Ipi,
0,
0x3Cu,
(__int64)"fft dualcore ipis");
}

original_code:
void test_fft_dual_ipi()
{
    test_suite_fft(Inverse_IO_Ipi, 0, 60, "fft dualcore ipis");
}


decompiled_code:
void __fastcall __noreturn dummy_function(void *a1)
{
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
pthread_exit(0LL);
}

original_code:
void *dummy_function(void *p)
{
    pthread_exit(((void *)0));
}

variable_types:
p
void *

return_type: void *


decompiled_code:
void __fastcall __noreturn thread_sort(void *a1)
{
heapsort(&array[*(_DWORD *)a1 >> 1]);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
heapsort(&array[*(_DWORD *)a1 >> 1]);
pthread_exit(0LL);
}

original_code:
void *thread_sort(void *v_len)
{
    uint32_t len = *((uint32_t *) v_len);
    heapsort(array + len / 2, len / 2);
    pthread_exit(((void *)0));
}

canonical_original_code:
void *thread_sort(void *v_len)
{
    unsigned int len = *((uint32_t *) v_len);
    heapsort(array + len / 2, len / 2);
    pthread_exit(((void *)0));
}

variable_types:
len
unsigned int


decompiled_code:
void __fastcall __noreturn thread_copy(void *a1)
{
copy(array, *(_DWORD *)a1 >> 1, &ap_temp, 0LL, *(_DWORD *)a1 >> 1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
copy(array, *(_DWORD *)a1 >> 1, &ap_temp, 0LL, *(_DWORD *)a1 >> 1);
pthread_exit(0LL);
}

original_code:
void *thread_copy(void *v_len)
{
    uint32_t len = *((uint32_t *) v_len);
    copy(array, len / 2, ap_temp, 0, len / 2);
    pthread_exit(((void *)0));
}

canonical_original_code:
void *thread_copy(void *v_len)
{
    unsigned int len = *((uint32_t *) v_len);
    copy(array, len / 2, ap_temp, 0, len / 2);
    pthread_exit(((void *)0));
}


decompiled_code:
void __fastcall __noreturn thread_merge(void *a1)
{
limit_merge_reverse(array, &ap_temp, 0LL, (unsigned int)((*(_DWORD *)a1 >> 1) - 1), (unsigned int)(*(_DWORD *)a1 - 1));
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(void *a1)
{
limit_merge_reverse(array, &ap_temp, 0LL, (unsigned int)((*(_DWORD *)a1 >> 1) - 1), (unsigned int)(*(_DWORD *)a1 - 1));
pthread_exit(0LL);
}

original_code:
void *thread_merge(void *v_len)
{
    uint32_t len = *((uint32_t *) v_len);
    limit_merge_reverse(array, ap_temp, 0, (len / 2) - 1, len - 1, len / 2);
    pthread_exit(((void *)0));
}

canonical_original_code:
void *thread_merge(void *v_len)
{
    unsigned int len = *((uint32_t *) v_len);
    limit_merge_reverse(array, ap_temp, 0, (len / 2) - 1, len - 1, len / 2);
    pthread_exit(((void *)0));
}


decompiled_code:
void __fastcall exit_if_error(unsigned int a1)
{
if ( a1 )
{
printf("ERROR; return code from create or join is %d\n", a1);
exit(-1);
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1)
{
if ( a1 )
{
printf("ERROR; return code from create or join is %d\n", a1);
exit(-1);
}
}

original_code:
void exit_if_error(int err_code)
{
    if (err_code) {
        printf("ERROR; return code from create or join is %d\n", err_code);
        exit(-1);
    }
}


decompiled_code:
int __fastcall do_sort_pthreads(unsigned int a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
unsigned int arg; // [rsp+Ch] [rbp-6Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-68h] BYREF
pthread_t v10; // [rsp+50h] [rbp-28h] BYREF
pthread_t th; // [rsp+58h] [rbp-20h] BYREF
pthread_t newthread; // [rsp+60h] [rbp-18h] BYREF
void *thread_return[2]; // [rsp+68h] [rbp-10h] BYREF

arg = a1;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 0);
v1 = pthread_create(&newthread, &attr, (void *(*)(void *))thread_sort, &arg);
exit_if_error(v1);
heapsort(array);
v2 = pthread_join(newthread, thread_return);
exit_if_error(v2);
v3 = pthread_create(&th, &attr, (void *(*)(void *))thread_merge, &arg);
exit_if_error(v3);
limit_merge(array, &bsp_temp, 0LL, (arg >> 1) - 1, arg - 1);
v4 = pthread_join(th, thread_return);
exit_if_error(v4);
v5 = pthread_create(&v10, &attr, (void *(*)(void *))thread_copy, &arg);
exit_if_error(v5);
copy(array, 0LL, &bsp_temp, 0LL, arg >> 1);
v6 = pthread_join(v10, thread_return);
exit_if_error(v6);
return pthread_attr_destroy(&attr);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
unsigned int arg; // [rsp+Ch] [rbp-6Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-68h] BYREF
pthread_t v10; // [rsp+50h] [rbp-28h] BYREF
pthread_t th; // [rsp+58h] [rbp-20h] BYREF
pthread_t newthread; // [rsp+60h] [rbp-18h] BYREF
void *thread_return[2]; // [rsp+68h] [rbp-10h] BYREF

arg = a1;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 0);
v1 = pthread_create(&newthread, &attr, (void *(*)(void *))thread_sort, &arg);
func4(v1);
heapsort(array);
v2 = pthread_join(newthread, thread_return);
func4(v2);
v3 = pthread_create(&th, &attr, (void *(*)(void *))thread_merge, &arg);
func4(v3);
limit_merge(array, &bsp_temp, 0LL, (arg >> 1) - 1, arg - 1);
v4 = pthread_join(th, thread_return);
func4(v4);
v5 = pthread_create(&v10, &attr, (void *(*)(void *))thread_copy, &arg);
func4(v5);
copy(array, 0LL, &bsp_temp, 0LL, arg >> 1);
v6 = pthread_join(v10, thread_return);
func4(v6);
return pthread_attr_destroy(&attr);
}

original_code:
void do_sort_pthreads(uint32_t len)
{
    void *status;
    pthread_t ap_heap_sort, ap_merge, ap_copy;
    pthread_attr_t join_attr;
    pthread_attr_init(&join_attr);
    pthread_attr_setdetachstate(&join_attr, PTHREAD_CREATE_JOINABLE);
    exit_if_error(
        pthread_create(&ap_heap_sort, &join_attr, thread_sort, (void *) &len)
    );
    heapsort(array, len / 2);
    exit_if_error(
        pthread_join(ap_heap_sort, &status)
    );
    exit_if_error(
        pthread_create(&ap_merge, &join_attr, thread_merge, (void *) &len)
    );
    limit_merge(array, bsp_temp, 0, (len / 2) - 1, len - 1, len / 2);
    exit_if_error(
        pthread_join(ap_merge, &status)
    );
    exit_if_error(
        pthread_create(&ap_copy, &join_attr, thread_copy, (void *) &len)
    );
    copy(array, 0, bsp_temp, 0, len / 2);
    exit_if_error(
        pthread_join(ap_copy, &status)
    );
    pthread_attr_destroy(&join_attr);
}

canonical_original_code:
void do_sort_pthreads(unsigned int len)
{
    void *status;
    unsigned long ap_heap_sort; unsigned long ap_merge; unsigned long ap_copy;
    union pthread_attr_t join_attr;
    pthread_attr_init(&join_attr);
    pthread_attr_setdetachstate(&join_attr, PTHREAD_CREATE_JOINABLE);
    exit_if_error(
        pthread_create(&ap_heap_sort, &join_attr, thread_sort, (void *) &len)
    );
    heapsort(array, len / 2);
    exit_if_error(
        pthread_join(ap_heap_sort, &status)
    );
    exit_if_error(
        pthread_create(&ap_merge, &join_attr, thread_merge, (void *) &len)
    );
    limit_merge(array, bsp_temp, 0, (len / 2) - 1, len - 1, len / 2);
    exit_if_error(
        pthread_join(ap_merge, &status)
    );
    exit_if_error(
        pthread_create(&ap_copy, &join_attr, thread_copy, (void *) &len)
    );
    copy(array, 0, bsp_temp, 0, len / 2);
    exit_if_error(
        pthread_join(ap_copy, &status)
    );
    pthread_attr_destroy(&join_attr);
}

variable_types:
status
void *

variable_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
unsigned __int64 custom_rand()
{
global_seed = 1103515245 * global_seed + 12345;
return ((unsigned __int64)global_seed >> 16) & 0x7FFF;
}

canonical_decompiled_code:
unsigned __int64 func6()
{
global_seed = 1103515245 * global_seed + 12345;
return ((unsigned __int64)global_seed >> 16) & 0x7FFF;
}

original_code:
uint32_t custom_rand()
{
    global_seed = global_seed * 1103515245 + 12345;
    return (uint32_t) (global_seed / 65536) % 32768;
}

canonical_original_code:
unsigned int custom_rand()
{
    global_seed = global_seed * 1103515245 + 12345;
    return (unsigned int) (global_seed / 65536) % 32768;
}


decompiled_code:
__int64 __fastcall verfiy_sort(unsigned int a1)
{
__int64 v1; // rax

if ( a1 <= 1 )
return 1LL;
v1 = 0LL;
while ( array[v1] <= array[v1 + 1] )
{
if ( ++v1 == a1 - 1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
__int64 v1; // rax

if ( a1 <= 1 )
return 1LL;
v1 = 0LL;
while ( array[v1] <= array[v1 + 1] )
{
if ( ++v1 == a1 - 1 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool verfiy_sort(uint32_t len)
{
    for (uint32_t i = 1; i < len; ++i) {
        if (array[i - 1] > array[i]) {
            return 0;
        }
    }
    return 1;
}

variable_types:
i
unsigned int


decompiled_code:
int test_pthreads_sync()
{
int v0; // ebp
unsigned int v1; // ebx

puts("\nTesting pthreads sync");
puts("Elementos\tCiclos\t\tCiclos\t\tCiclos");
v0 = 22;
v1 = 2;
do
{
generate_global_array(13214LL, v1);
sort_measure_sync(v1);
if ( (unsigned __int8)verfiy_sort(v1) )
printf("%u\t\t%lu\t\t%lu\t\t%lu\n", v1, sync_times[0], sync_times[1], sync_times[2]);
else
puts("Bad sort! :(");
v1 *= 2;
--v0;
}
while ( v0 );
return puts("Done! :D");
}

canonical_decompiled_code:
int func9()
{
int v0; // ebp
unsigned int v1; // ebx

puts("\nTesting pthreads sync");
puts("Elementos\tCiclos\t\tCiclos\t\tCiclos");
v0 = 22;
v1 = 2;
do
{
func7(13214LL, v1);
sort_measure_sync(v1);
if ( (unsigned __int8)func8(v1) )
printf("%u\t\t%lu\t\t%lu\t\t%lu\n", v1, sync_times[0], sync_times[1], sync_times[2]);
else
puts("Bad sort! :(");
v1 *= 2;
--v0;
}
while ( v0 );
return puts("Done! :D");
}

original_code:
void test_pthreads_sync()
{
    printf("\nTesting pthreads sync\n");
    printf("Elementos\tCiclos\t\tCiclos\t\tCiclos\n");
    for (uint32_t len = 2; len < (8*1024*1024); len *= 2) {
        uint32_t seed = 13214;
        generate_global_array(seed, len);
        sort_measure_sync(len);
        if (verfiy_sort(len)) {
            printf("%u\t\t%lu\t\t%lu\t\t%lu\n", len, sync_times[0], sync_times[1], sync_times[2]);
        } else {
            printf("Bad sort! :(\n");
        }
    }
    printf("Done! :D\n");
}

canonical_original_code:
void test_pthreads_sync()
{
    printf("\nTesting pthreads sync\n");
    printf("Elementos\tCiclos\t\tCiclos\t\tCiclos\n");
    for (unsigned int len = 2; len < (8*1024*1024); len *= 2) {
        unsigned int seed = 13214;
        generate_global_array(seed, len);
        sort_measure_sync(len);
        if (verfiy_sort(len)) {
            printf("%u\t\t%lu\t\t%lu\t\t%lu\n", len, sync_times[0], sync_times[1], sync_times[2]);
        } else {
            printf("Bad sort! :(\n");
        }
    }
    printf("Done! :D\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_pthreads();
test_pthreads_sync();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_pthreads();
func9();
return 0;
}

original_code:
int main()
{
    test_pthreads();
    test_pthreads_sync();
    return 0;
}

return_type: int


decompiled_code:
void __fastcall generate_global_array(__int64 a1, int a2)
{
__int64 i; // rbx

global_seed = a1;
if ( a2 )
{
for ( i = 0LL; i != a2; array[i++] = custom_rand() )
;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
__int64 i; // rbx

global_seed = a1;
if ( a2 )
{
for ( i = 0LL; i != a2; array[i++] = func6() )
;
}
}

original_code:
void generate_global_array(uint64_t seed, uint32_t len)
{
    global_seed = seed;
    for (uint32_t i = 0; i < len; ++i) {
        array[i] = custom_rand();
    }
}

canonical_original_code:
void generate_global_array(unsigned long seed, unsigned int len)
{
    global_seed = seed;
    for (unsigned int i = 0; i < len; ++i) {
        array[i] = custom_rand();
    }
}

variable_types:
seed
unsigned long


original_code:
void sort_ap()
{
    uint64_t *start = (uint64_t *) 0x200000;
    uint64_t *start_merge = (uint64_t *) 0x200100;
    uint64_t *done = (uint64_t *) 0x200700;
    uint64_t *finish_copy = (uint64_t *) 0x200800;
    uint64_t *sleep = (uint64_t *) 0x200200;
    uint64_t *start_copy = (uint64_t *) 0x200300;
    *sleep = 0;
    while(!(*sleep)) {
        while(!(*start)) {
            if (*sleep) {
                return;
            }
        }
        uint32_t *len = (uint32_t *) 0x200600;
        uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
        uint32_t *ap_temp = (uint32_t *) (0x1e00000 + 0xa00000);
        *start = 0;
        heapsort(array + *len / 2, *len / 2);
        *done = 1;
        while(!(*start_merge));
        limit_merge_reverse(array, ap_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
        *done = 1;
        while(!(*start_copy));
        copy(array, *len / 2, ap_temp, 0, *len / 2);
        *finish_copy = 1;
    }
    *sleep = 0;
}

canonical_original_code:
void sort_ap()
{
    unsigned long *start = (uint64_t *) 0x200000;
    unsigned long *start_merge = (uint64_t *) 0x200100;
    unsigned long *done = (uint64_t *) 0x200700;
    unsigned long *finish_copy = (uint64_t *) 0x200800;
    unsigned long *sleep = (uint64_t *) 0x200200;
    unsigned long *start_copy = (uint64_t *) 0x200300;
    *sleep = 0;
    while(!(*sleep)) {
        while(!(*start)) {
            if (*sleep) {
                return;
            }
        }
        unsigned int *len = (uint32_t *) 0x200600;
        unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
        unsigned int *ap_temp = (uint32_t *) (0x1e00000 + 0xa00000);
        *start = 0;
        heapsort(array + *len / 2, *len / 2);
        *done = 1;
        while(!(*start_merge));
        limit_merge_reverse(array, ap_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
        *done = 1;
        while(!(*start_copy));
        copy(array, *len / 2, ap_temp, 0, *len / 2);
        *finish_copy = 1;
    }
    *sleep = 0;
}

variable_types:
start
unsigned long *

variable_types:
done
unsigned long *

variable_types:
sleep
unsigned long *

variable_types:
len
unsigned int *

variable_types:
array
unsigned int *


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

MEMORY[0x200200] = 0LL;
MEMORY[0x200000] = 0LL;
do
{
result = MEMORY[0x200000];
while ( !MEMORY[0x200000] )
;
MEMORY[0x200000] = 0LL;
MEMORY[0x200700] = 1LL;
}
while ( !MEMORY[0x200200] );
return result;
}

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

MEMORY[0x200200] = 0LL;
MEMORY[0x200000] = 0LL;
do
{
result = MEMORY[0x200000];
while ( !MEMORY[0x200000] )
;
MEMORY[0x200000] = 0LL;
MEMORY[0x200700] = 1LL;
}
while ( !MEMORY[0x200200] );
return result;
}

original_code:
void ap_sync()
{
    uint64_t *start = (uint64_t *) 0x200000;
    uint64_t *done = (uint64_t *) 0x200700;
    uint64_t *sleep = (uint64_t *) 0x200200;
    *sleep = 0;
    *start = 0;
    while(!(*sleep)) {
        while(!(*start)) {
            if (*sleep) {
                return;
            }
        }
        *start = 0;
        *done = 1;
    }
}

canonical_original_code:
void ap_sync()
{
    unsigned long *start = (uint64_t *) 0x200000;
    unsigned long *done = (uint64_t *) 0x200700;
    unsigned long *sleep = (uint64_t *) 0x200200;
    *sleep = 0;
    *start = 0;
    while(!(*sleep)) {
        while(!(*start)) {
            if (*sleep) {
                return;
            }
        }
        *start = 0;
        *done = 1;
    }
}


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

result = MEMORY[0x200000];
while ( !MEMORY[0x200000] )
{
if ( MEMORY[0x200200] )
return result;
}
for ( result = MEMORY[0x200600] >> 1; MEMORY[0x200600] > (unsigned int)result; result = (unsigned int)(result + 1) )
++*(_DWORD *)(4LL * (unsigned int)result + 0x15E00000);
MEMORY[0x200800] = 1LL;
return result;
}

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

result = MEMORY[0x200000];
while ( !MEMORY[0x200000] )
{
if ( MEMORY[0x200200] )
return result;
}
for ( result = MEMORY[0x200600] >> 1; MEMORY[0x200600] > (unsigned int)result; result = (unsigned int)(result + 1) )
++*(_DWORD *)(4LL * (unsigned int)result + 0x15E00000);
MEMORY[0x200800] = 1LL;
return result;
}

canonical_original_code:
void sum_vector_ap()
{
    unsigned long *start = (uint64_t *) 0x200000;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned long *sleep = (uint64_t *) 0x200200;
    while(!(*start)) {
        if (*sleep) {
            return;
        }
    }
    for (unsigned int i = *len / 2; i < *len; ++i) {
        array[i]++;
    }
    *((unsigned long *) 0x200800) = 1;
}


decompiled_code:
__int64 sort_ap_int()
{
heapsort(4LL * (MEMORY[0x200600] >> 1) + 367001600);
return signal_finished();
}

canonical_decompiled_code:
__int64 func3()
{
heapsort(4LL * (MEMORY[0x200600] >> 1) + 367001600);
return signal_finished();
}

original_code:
void sort_ap_int()
{
    uint32_t *len = (uint32_t *) 0x200600;
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    heapsort(array + *len / 2, *len / 2);
    signal_finished();
}

canonical_original_code:
void sort_ap_int()
{
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    heapsort(array + *len / 2, *len / 2);
    signal_finished();
}


decompiled_code:
__int64 merge_ap_int()
{
limit_merge_reverse(
367001600LL,
41943040LL,
0LL,
(unsigned int)((MEMORY[0x200600] >> 1) - 1),
(unsigned int)(MEMORY[0x200600] - 1));
return signal_finished();
}

canonical_decompiled_code:
__int64 func4()
{
limit_merge_reverse(
367001600LL,
41943040LL,
0LL,
(unsigned int)((MEMORY[0x200600] >> 1) - 1),
(unsigned int)(MEMORY[0x200600] - 1));
return signal_finished();
}

original_code:
void merge_ap_int()
{
    uint32_t *len = (uint32_t *) 0x200600;
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    uint32_t *ap_temp = (uint32_t *) (0x1e00000 + 0xa00000);
    limit_merge_reverse(array, ap_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    signal_finished();
}

canonical_original_code:
void merge_ap_int()
{
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    unsigned int *ap_temp = (uint32_t *) (0x1e00000 + 0xa00000);
    limit_merge_reverse(array, ap_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    signal_finished();
}


canonical_original_code:
void copy_ap_int()
{
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    unsigned int *ap_temp = (uint32_t *) (0x1e00000 + 0xa00000);
    copy(array, *len / 2, ap_temp, 0, *len / 2);
    signal_finished();
}


decompiled_code:
__int64 ap_jump()
{
return signal_finished();
}

canonical_decompiled_code:
__int64 func6()
{
return signal_finished();
}

original_code:
void ap_jump()
{
    signal_finished();
}

canonical_original_code:
void ap_jump()
{
    signal_finished();
}


decompiled_code:
void startKernel64_BSPMODE()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void startKernel64_BSPMODE(){
}

canonical_original_code:
void startKernel64_BSPMODE(){
}


decompiled_code:
void startKernel64_APMODE()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void startKernel64_APMODE(){
}

canonical_original_code:
void startKernel64_APMODE(){
}


canonical_original_code:
static void clean_flags()
{
    *((unsigned long *) 0x200000) = 0;
    *((unsigned long *) 0x200100) = 0;
    *((unsigned long *) 0x200700) = 0;
    *((unsigned long *) 0x200800) = 0;
    *((unsigned long *) 0x200300) = 0;
}


original_code:
void sort_bsp()
{
    uint64_t *start = (uint64_t *) 0x200000;
    uint64_t *start_merge = (uint64_t *) 0x200100;
    uint64_t *done = (uint64_t *) 0x200700;
    uint64_t *finish_copy = (uint64_t *) 0x200800;
    uint64_t *start_copy = (uint64_t *) 0x200300;
    uint32_t *len = (uint32_t *) 0x200600;
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    uint32_t *bsp_temp = (uint32_t *) 0x1e00000;
    clean_flags();
    *start = 1;
    heapsort(array, *len / 2);
    while(!(*done));
    *done = 0;
    *start_merge = 1;
    limit_merge(array, bsp_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    while(!(*done));
    *done = 0;
    *start_copy = 1;
    copy(array, 0, bsp_temp, 0, *len / 2);
    while(!(*finish_copy));
    clean_flags();
}

canonical_original_code:
void sort_bsp()
{
    unsigned long *start = (uint64_t *) 0x200000;
    unsigned long *start_merge = (uint64_t *) 0x200100;
    unsigned long *done = (uint64_t *) 0x200700;
    unsigned long *finish_copy = (uint64_t *) 0x200800;
    unsigned long *start_copy = (uint64_t *) 0x200300;
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    unsigned int *bsp_temp = (uint32_t *) 0x1e00000;
    clean_flags();
    *start = 1;
    heapsort(array, *len / 2);
    while(!(*done));
    *done = 0;
    *start_merge = 1;
    limit_merge(array, bsp_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    while(!(*done));
    *done = 0;
    *start_copy = 1;
    copy(array, 0, bsp_temp, 0, *len / 2);
    while(!(*finish_copy));
    clean_flags();
}


original_code:
void sort_bsp_ipi()
{
    uint32_t *len = (uint32_t *) 0x200600;
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    uint32_t *bsp_temp = (uint32_t *) 0x1e00000;
    send_ipi_ap(40);
    heapsort(array, *len / 2);
    check_rax();
    send_ipi_ap(41);
    limit_merge(array, bsp_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    check_rax();
    send_ipi_ap(42);
    copy(array, 0, bsp_temp, 0, *len / 2);
    check_rax();
}

canonical_original_code:
void sort_bsp_ipi()
{
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    unsigned int *bsp_temp = (uint32_t *) 0x1e00000;
    send_ipi_ap(40);
    heapsort(array, *len / 2);
    check_rax();
    send_ipi_ap(41);
    limit_merge(array, bsp_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    check_rax();
    send_ipi_ap(42);
    copy(array, 0, bsp_temp, 0, *len / 2);
    check_rax();
}


canonical_decompiled_code:
unsigned __int64 func3()
{
global_seed = 1103515245 * global_seed + 12345;
return ((unsigned __int64)global_seed >> 16) & 0x7FFF;
}


decompiled_code:
void __fastcall generate_random_array(_DWORD *a1, __int64 a2, int a3)
{
_DWORD *v3; // rbx
__int64 v4; // rbp

global_seed = a2;
if ( a3 )
{
v3 = a1;
v4 = (__int64)&a1[a3 - 1 + 1];
do
*v3++ = custom_rand();
while ( v3 != (_DWORD *)v4 );
}
}

canonical_decompiled_code:
void __fastcall func4(_DWORD *a1, __int64 a2, int a3)
{
_DWORD *v3; // rbx
__int64 v4; // rbp

global_seed = a2;
if ( a3 )
{
v3 = a1;
v4 = (__int64)&a1[a3 - 1 + 1];
do
*v3++ = func3();
while ( v3 != (_DWORD *)v4 );
}
}

original_code:
void generate_random_array(int *array, uint64_t seed, uint32_t len)
{
    global_seed = seed;
    for (uint32_t i = 0; i < len; ++i) {
        array[i] = custom_rand();
    }
}

canonical_original_code:
void generate_random_array(int *array, unsigned long seed, unsigned int len)
{
    global_seed = seed;
    for (unsigned int i = 0; i < len; ++i) {
        array[i] = custom_rand();
    }
}

variable_types:
array
int *


original_code:
void bubble_sort(int *array, uint32_t len)
{
    for (int j = 0; j < len; ++j) {
        for (int i = 0; i < len - 1 - j; ++i) {
            if (array[i] > array[i + 1]) {
                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
            }
        }
    }
}

canonical_original_code:
void bubble_sort(int *array, unsigned int len)
{
    for (int j = 0; j < len; ++j) {
        for (int i = 0; i < len - 1 - j; ++i) {
            if (array[i] > array[i + 1]) {
                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
            }
        }
    }
}

variable_types: j int

variable_types: i int

variable_types: aux int


decompiled_code:
unsigned __int64 measure_sync_mem()
{
int v0; // ebp
int v1; // ebx
int *v2; // rax
unsigned __int64 v3; // rcx
unsigned __int64 result; // rax
int v5[9]; // [rsp+0h] [rbp-40h] BYREF
char v6; // [rsp+24h] [rbp-1Ch] BYREF

v0 = MEMORY[0x200600];
MEMORY[0x200000] = 1LL;
if ( MEMORY[0x200600] )
{
v1 = 0;
do
{
generate_random_array(v5, 13214LL, 10);
bubble_sort(v5, 10);
v2 = v5;
do
{
if ( *v2 > v2[1] )
break;
++v2;
}
while ( v2 != (int *)&v6 );
++v1;
}
while ( v1 != v0 );
}
_mm_mfence();
v3 = __rdtsc();
init = v3;
while ( !MEMORY[0x200700] )
;
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
result = stop - v3;
MEMORY[0x200D00] = stop - v3;
return result;
}

canonical_decompiled_code:
unsigned __int64 func6()
{
int v0; // ebp
int v1; // ebx
int *v2; // rax
unsigned __int64 v3; // rcx
unsigned __int64 result; // rax
int v5[9]; // [rsp+0h] [rbp-40h] BYREF
char v6; // [rsp+24h] [rbp-1Ch] BYREF

v0 = MEMORY[0x200600];
MEMORY[0x200000] = 1LL;
if ( MEMORY[0x200600] )
{
v1 = 0;
do
{
func4(v5, 13214LL, 10);
func5(v5, 10);
v2 = v5;
do
{
if ( *v2 > v2[1] )
break;
++v2;
}
while ( v2 != (int *)&v6 );
++v1;
}
while ( v1 != v0 );
}
_mm_mfence();
v3 = __rdtsc();
init = v3;
while ( !MEMORY[0x200700] )
;
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
result = stop - v3;
MEMORY[0x200D00] = stop - v3;
return result;
}

original_code:
void measure_sync_mem()
{
    int my_len = 10;
    int my_array[my_len];
    uint64_t *start = (uint64_t *) 0x200000;
    uint64_t *done = (uint64_t *) 0x200700;
    uint32_t len = *((uint32_t *) 0x200600);
    uint64_t *time_measures = (uint64_t *) 0x200d00;
    *start = 1;
    for (int i = 0; i < len; ++i) {
        generate_random_array(my_array, 13214, my_len);
        bubble_sort(my_array, my_len);
        for (int j = 1; j < my_len ; ++j) {
            if (my_array[j - 1] > my_array[j]) {
                break;
            }
        }
    }
    { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
    while(!(*done));
    { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
    time_measures[0] = stop - init;
}

canonical_original_code:
void measure_sync_mem()
{
    int my_len = 10;
    int my_array[-1];
    unsigned long *start = (uint64_t *) 0x200000;
    unsigned long *done = (uint64_t *) 0x200700;
    unsigned int len = *((uint32_t *) 0x200600);
    unsigned long *time_measures = (uint64_t *) 0x200d00;
    *start = 1;
    for (int i = 0; i < len; ++i) {
        generate_random_array(my_array, 13214, my_len);
        bubble_sort(my_array, my_len);
        for (int j = 1; j < my_len ; ++j) {
            if (my_array[j - 1] > my_array[j]) {
                break;
            }
        }
    }
    { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
    while(!(*done));
    { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
    time_measures[0] = stop - init;
}


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

send_ipi_ap(39LL);
heapsort(367001600LL, MEMORY[0x200600] >> 1);
heapsort(4LL * (MEMORY[0x200600] >> 1) + 367001600, MEMORY[0x200600] >> 1);
_mm_mfence();
init = __rdtsc();
check_rax();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
MEMORY[0x200D08] = stop - init;
send_ipi_ap(39LL);
limit_merge(
367001600LL,
31457280LL,
0LL,
(unsigned int)((MEMORY[0x200600] >> 1) - 1),
(unsigned int)(MEMORY[0x200600] - 1));
limit_merge_reverse(
367001600LL,
41943040LL,
0LL,
(unsigned int)((MEMORY[0x200600] >> 1) - 1),
(unsigned int)(MEMORY[0x200600] - 1));
_mm_mfence();
init = __rdtsc();
check_rax();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
MEMORY[0x200D18] = stop - init;
send_ipi_ap(39LL);
copy(367001600LL, 0LL, 31457280LL, 0LL, MEMORY[0x200600] >> 1);
copy(367001600LL, MEMORY[0x200600] >> 1, 41943040LL, 0LL, MEMORY[0x200600] >> 1);
_mm_mfence();
init = __rdtsc();
check_rax();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
result = stop - init;
MEMORY[0x200D28] = stop - init;
return result;
}

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

send_ipi_ap(39LL);
heapsort(367001600LL, MEMORY[0x200600] >> 1);
heapsort(4LL * (MEMORY[0x200600] >> 1) + 367001600, MEMORY[0x200600] >> 1);
_mm_mfence();
init = __rdtsc();
check_rax();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
MEMORY[0x200D08] = stop - init;
send_ipi_ap(39LL);
limit_merge(
367001600LL,
31457280LL,
0LL,
(unsigned int)((MEMORY[0x200600] >> 1) - 1),
(unsigned int)(MEMORY[0x200600] - 1));
limit_merge_reverse(
367001600LL,
41943040LL,
0LL,
(unsigned int)((MEMORY[0x200600] >> 1) - 1),
(unsigned int)(MEMORY[0x200600] - 1));
_mm_mfence();
init = __rdtsc();
check_rax();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
MEMORY[0x200D18] = stop - init;
send_ipi_ap(39LL);
copy(367001600LL, 0LL, 31457280LL, 0LL, MEMORY[0x200600] >> 1);
copy(367001600LL, MEMORY[0x200600] >> 1, 41943040LL, 0LL, MEMORY[0x200600] >> 1);
_mm_mfence();
init = __rdtsc();
check_rax();
_mm_mfence();
__rdtsc();
_mm_mfence();
__rdtsc();
_mm_mfence();
stop = __rdtsc();
result = stop - init;
MEMORY[0x200D28] = stop - init;
return result;
}

original_code:
void measure_sync_ipis()
{
    uint32_t *len = (uint32_t *) 0x200600;
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    uint32_t *bsp_temp = (uint32_t *) 0x1e00000;
    uint64_t *time_measures = (uint64_t *) 0x200d00;
    uint32_t *ap_temp = (uint32_t *) (0x1e00000 + 0xa00000);
    send_ipi_ap(39);
    heapsort(array, *len / 2);
    heapsort(array + *len / 2, *len / 2);
    { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
    check_rax();
    { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
    time_measures[1] = stop - init;
    send_ipi_ap(39);
    limit_merge(array, bsp_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    limit_merge_reverse(array, ap_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
    check_rax();
    { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
    time_measures[3] = stop - init;
    send_ipi_ap(39);
    copy(array, 0, bsp_temp, 0, *len / 2);
    copy(array, *len / 2, ap_temp, 0, *len / 2);
    { unsigned int start_high, start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long int) start_high) << 32) | (unsigned long long int) (start_low); };
    check_rax();
    { { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } { unsigned int end_high, end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long int) end_high) << 32) | (unsigned long long int) (end_low); } };
    time_measures[5] = stop - init;
}

canonical_original_code:
void measure_sync_ipis()
{
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    unsigned int *bsp_temp = (uint32_t *) 0x1e00000;
    unsigned long *time_measures = (uint64_t *) 0x200d00;
    unsigned int *ap_temp = (uint32_t *) (0x1e00000 + 0xa00000);
    send_ipi_ap(39);
    heapsort(array, *len / 2);
    heapsort(array + *len / 2, *len / 2);
    { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
    check_rax();
    { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
    time_measures[1] = stop - init;
    send_ipi_ap(39);
    limit_merge(array, bsp_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    limit_merge_reverse(array, ap_temp, 0, (*len / 2) - 1, *len - 1, *len / 2);
    { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
    check_rax();
    { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
    time_measures[3] = stop - init;
    send_ipi_ap(39);
    copy(array, 0, bsp_temp, 0, *len / 2);
    copy(array, *len / 2, ap_temp, 0, *len / 2);
    { unsigned int start_high; unsigned int start_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (start_high), "=r" (start_low) : : "%eax" ); init = (((unsigned long long) start_high) << 32) | (unsigned long long) (start_low); };
    check_rax();
    { { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } { unsigned int end_high; unsigned int end_low; __asm__ __volatile__ ( "mfence\n\t" "rdtsc\n\t" "mov %%edx, %0\n\t" "mov %%eax, %1\n\t" : "=r" (end_high), "=r" (end_low) : : "%eax" ); stop = (((unsigned long long) end_high) << 32) | (unsigned long long) (end_low); } };
    time_measures[5] = stop - init;
}


decompiled_code:
void sum_vector_bsp()
{
unsigned int v0; // eax

clean_flags();
MEMORY[0x200000] = 1LL;
if ( MEMORY[0x200600] > 1u )
{
v0 = 0;
do
++*(_DWORD *)(4LL * v0++ + 0x15E00000);
while ( MEMORY[0x200600] >> 1 > v0 );
}
while ( !MEMORY[0x200800] )
;
clean_flags();
}

original_code:
void sum_vector_bsp()
{
    uint64_t *start = (uint64_t *) 0x200000;
    uint32_t *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    uint32_t *len = (uint32_t *) 0x200600;
    uint64_t *finish = (uint64_t *) 0x200800;
    clean_flags();
    *start = 1;
    for (uint32_t i = 0; i < *len / 2; ++i) {
        array[i]++;
    }
    while(!(*finish));
    clean_flags();
}

canonical_original_code:
void sum_vector_bsp()
{
    unsigned long *start = (uint64_t *) 0x200000;
    unsigned int *array = (uint32_t *) (0x1e00000 + 32 * 0xa00000);
    unsigned int *len = (uint32_t *) 0x200600;
    unsigned long *finish = (uint64_t *) 0x200800;
    clean_flags();
    *start = 1;
    for (unsigned int i = 0; i < *len / 2; ++i) {
        array[i]++;
    }
    while(!(*finish));
    clean_flags();
}

variable_types:
finish
unsigned long *


decompiled_code:
__int64 make_ap_jump()
{
char v1[2]; // [rsp+8h] [rbp-10h] BYREF
char v2; // [rsp+Ah] [rbp-Eh]

initialize_ipi_options(v1, 0LL, 39LL, 1LL);
v2 |= 0xCu;
send_ipi(v1);
wait_for_ipi_reception();
return print_string("Jumpeo?", 1LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
char v1[2]; // [rsp+8h] [rbp-10h] BYREF
char v2; // [rsp+Ah] [rbp-Eh]

initialize_ipi_options(v1, 0LL, 39LL, 1LL);
v2 |= 0xCu;
send_ipi(v1);
wait_for_ipi_reception();
return print_string("Jumpeo?", 1LL, 0LL);
}

original_code:
void make_ap_jump()
{
    intr_command_register icr;
    initialize_ipi_options(&icr, FIXED, 39, 1);
    icr.destination_shorthand = 3;
    send_ipi(&icr);
    wait_for_ipi_reception();
    print_string("Jumpeo?", 1, 0);
}

canonical_original_code:
void make_ap_jump()
{
    struct intr_command_register icr;
    initialize_ipi_options(&icr, FIXED, 39, 1);
    icr.destination_shorthand = 3;
    send_ipi(&icr);
    wait_for_ipi_reception();
    print_string("Jumpeo?", 1, 0);
}

variable_types: struct intr_command_register { unsigned char vector; unsigned char delivery_mode; unsigned char destination_mode; unsigned char delivery_status; unsigned char __reserved1; unsigned char level; unsigned char trigger_mode; unsigned char __reserved2; unsigned char destination_shorthand; unsigned char __reserved3; unsigned char __reserved4[4]; unsigned char destination_field; }


isPrime

repo: JAChapmanII/bprime

original_code:
size_t isPrime(char *p, size_t x) {
 x = (x >> 1) - 1;
 return p[x >> 3] & (0x1 << (x % 8));
}

canonical_original_code:
unsigned long isPrime(char *p, unsigned long x) {
 x = (x >> 1) - 1;
 return p[x >> 3] & (0x1 << (x % 8));
}

variable_types:
p
char *

variable_types:
x
unsigned long

return_type: unsigned long


crossOut

decompiled_code:
void *__fastcall crossOut(void *a1)
{
unsigned __int64 v1; // rsi
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v5; // rax

v1 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
{
v5 = i * (v1 / i);
v2 = v5;
if ( v1 > v5 )
v2 = v5 + i;
}
else
{
v2 = i * i;
}
if ( i >= v2 )
v2 += i;
v3 = *((_QWORD *)a1 + 1);
if ( v3 >= v2 && v3 > v2 )
{
do
{
if ( (v2 & 1) != 0 )
setNotPrime(prime, v2);
v2 += i;
}
while ( *((_QWORD *)a1 + 1) > v2 );
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
unsigned __int64 v1; // rsi
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v5; // rax

v1 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
{
v5 = i * (v1 / i);
v2 = v5;
if ( v1 > v5 )
v2 = v5 + i;
}
else
{
v2 = i * i;
}
if ( i >= v2 )
v2 += i;
v3 = *((_QWORD *)a1 + 1);
if ( v3 >= v2 && v3 > v2 )
{
do
{
if ( (v2 & 1) != 0 )
func8(prime, v2);
v2 += i;
}
while ( *((_QWORD *)a1 + 1) > v2 );
}
return 0LL;
}

original_code:
void *crossOut(void *args) {
 size_t j;
 if(((size_t *)args)[0] == 0) {
  j = i * i;
 } else {
  j = (((size_t *)args)[0] / i) * i;
  if(j < ((size_t *)args)[0])
   j += i;
 }
 if(j <= i)
  j += i;
 if(((size_t *)args)[1] < j)
  return ((void *)0);
 for(; j < ((size_t *)args)[1]; j += i)
  if(j % 2)
   setNotPrime(prime, j);
 return ((void *)0);
}

canonical_original_code:
void *crossOut(void *args) {
 unsigned long j;
 if(((unsigned long *)args)[0] == 0) {
  j = i * i;
 } else {
  j = (((unsigned long *)args)[0] / i) * i;
  if(j < ((unsigned long *)args)[0])
   j += i;
 }
 if(j <= i)
  j += i;
 if(((unsigned long *)args)[1] < j)
  return ((void *)0);
 for(; j < ((unsigned long *)args)[1]; j += i)
  if(j % 2)
   setNotPrime(prime, j);
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
j
unsigned long