getDiagonalLength

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

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

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

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

original_code:
int getDiagonalLength(int slice, int z, int sub) {
  int i = z;
  int j = slice - z;
  if (z <= 0)
    return j + 1;
  return j - i + 1;
}


removeNewLine

repo: l-urence/smith-waterman

decompiled_code:
char *__fastcall removeNewLine(char *s)
{
char *v1; // rax
char *result; // rax

v1 = strchr(s, 10);
if ( v1 )
*v1 = 0;
result = strchr(s, 13);
if ( result )
*result = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
char *v1; // rax
char *result; // rax

v1 = strchr(s, 10);
if ( v1 )
*v1 = 0;
result = strchr(s, 13);
if ( result )
*result = 0;
return result;
}

original_code:
void removeNewLine(char *string)
{
  char *c = strchr(string, '\n');
  if (c)
    *c = '\0';
  c = strchr(string, '\r');
  if (c)
    *c = '\0';
}

variable_types:
string
char *

variable_types:
c
char *

return_type: void


search

decompiled_code:
__int64 __fastcall search(__int64 a1, int a2, unsigned int a3, int a4)
{
int v6; // ecx

while ( 1 )
{
while ( 1 )
{
printf("Index %d\n", a3);
v6 = (a4 + 1) / 2;
a4 = v6;
if ( !a3 || *(_DWORD *)(a1 + 4LL * (int)a3 - 4) <= *(_DWORD *)(a1 + 4LL * (int)a3) )
break;
a3 -= v6;
}
if ( a3 == a2 - 1 || *(_DWORD *)(a1 + 4LL * (int)a3 + 4) <= *(_DWORD *)(a1 + 4LL * (int)a3) )
break;
a3 += v6;
}
return a3;
}

original_code:
int search(int values[], int count, int index, int step) {
 printf ("Index %d\n", index);
 int next_step = (step + 1) / 2;
 if (index != 0 && values[index - 1] > values[index]) {
  return search(values, count, index - next_step, next_step);
 } else if (index != count -1 && values[index + 1] > values[index]) {
  return search(values, count, index + next_step, next_step);
 } else {
  return index;
 }
}

variable_types:
values
int []

variable_types: count int

variable_types: index int

variable_types: step int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // edi
__int64 v5; // rbx
__int64 v6; // rsi
__int64 v7; // rdx
unsigned int v8; // eax
int v10[6]; // [rsp+0h] [rbp-18h] BYREF

v3 = time(0LL);
printf("Seed: %u\n", v3);
v4 = v3;
v5 = 0LL;
srand(v4);
puts("Input:");
do
{
v6 = (unsigned int)v5;
v7 = (unsigned int)(rand() % 4);
v10[v5++] = v7;
printf("%8d: %d\n", v6, v7);
}
while ( v5 != 4 );
v8 = search(v10, 4LL, 2LL, 2LL);
if ( v8 == -1 )
puts("No peak found");
else
printf("Peak found at index %d: %d\n", v8, (unsigned int)v10[v8]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // edi
__int64 v5; // rbx
__int64 v6; // rsi
__int64 v7; // rdx
unsigned int v8; // eax
int v10[6]; // [rsp+0h] [rbp-18h] BYREF

v3 = time(0LL);
printf("Seed: %u\n", v3);
v4 = v3;
v5 = 0LL;
srand(v4);
puts("Input:");
do
{
v6 = (unsigned int)v5;
v7 = (unsigned int)(rand() % 4);
v10[v5++] = v7;
printf("%8d: %d\n", v6, v7);
}
while ( v5 != 4 );
v8 = func7(v10, 4LL, 2LL, 2LL);
if ( v8 == -1 )
puts("No peak found");
else
printf("Peak found at index %d: %d\n", v8, (unsigned int)v10[v8]);
return 0;
}

original_code:
int main (void) {
 int result;
 unsigned seed = (unsigned)time(((void *)0));
 int count = 4;
 int limit = 4;
 int values[count];
 int index;
 printf ("Seed: %u\n", seed);
 srand(seed);
 printf ("Input:\n");
 for (index = 0; index < count; index++) {
  values[index] = rand() % limit;
  printf ("%8d: %d\n", index, values[index]);
 }
 result = search(values, count, count / 2, count / 2);
 if (result != -1) {
  printf ("Peak found at index %d: %d\n", result, values[result]);
 } else {
  printf ("No peak found\n");
 }
 return 0;
}

canonical_original_code:
int main() {
 int result;
 unsigned int seed = (unsigned)time(((void *)0));
 int count = 4;
 int limit = 4;
 int values[-1];
 int index;
 printf ("Seed: %u\n", seed);
 srand(seed);
 printf ("Input:\n");
 for (index = 0; index < count; index++) {
  values[index] = rand() % limit;
  printf ("%8d: %d\n", index, values[index]);
 }
 result = search(values, count, count / 2, count / 2);
 if (result != -1) {
  printf ("Peak found at index %d: %d\n", result, values[result]);
 } else {
  printf ("No peak found\n");
 }
 return 0;
}

variable_types: result int

variable_types:
seed
unsigned int

variable_types: limit int

variable_types:
values
int [-1]


odd

decompiled_code:
_BOOL8 __fastcall odd(unsigned int a1)
{
return ((a1 + (a1 >> 31)) & 0xFFFFFFFE) != a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(unsigned int a1)
{
return ((a1 + (a1 >> 31)) & 0xFFFFFFFE) != a1;
}

original_code:
int odd(int number)
{
 if ((number / 2) * 2 == number) {
  return 0;
 } else {
  return 1;
 }
}

variable_types: number int


binary

decompiled_code:
int __fastcall binary(unsigned int a1)
{
char *v1; // rbx
bool v2; // al
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // rsi
int result; // eax
char v7; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v8; // [rsp+10h] [rbp-18h] BYREF

v1 = &v7;
do
{
v2 = odd(a1);
--v3;
a1 >>= 1;
*(_BYTE *)(v3 + 4) = v2;
}
while ( v3 != v4 );
do
{
v5 = (unsigned int)*v1++;
result = printf("%d", v5);
}
while ( v1 != (char *)&v8 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
char *v1; // rbx
bool v2; // al
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // rsi
int result; // eax
char v7; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v8; // [rsp+10h] [rbp-18h] BYREF

v1 = &v7;
do
{
v2 = func7(a1);
--v3;
a1 >>= 1;
*(_BYTE *)(v3 + 4) = v2;
}
while ( v3 != v4 );
do
{
v5 = (unsigned int)*v1++;
result = printf("%d", v5);
}
while ( v1 != (char *)&v8 );
return result;
}

original_code:
void binary(unsigned int number)
{
 int index;
 char result[4];
 for (index = sizeof(result) - 1; index >= 0; index--) {
  result[index] = (char)odd(number);
  number = number / 2;
 }
 for (index = 0; index < sizeof(result); index++) {
  printf("%d", result[index]);
 }
}

variable_types:
number
unsigned int

variable_types:
result
char [4]


base

decompiled_code:
int __fastcall base(unsigned int a1, unsigned int a2)
{
char *v3; // rbx
char *v4; // rcx
int v5; // edx
__int64 v6; // rsi
int result; // eax
char v8; // [rsp+8h] [rbp-20h] BYREF
char v9[4]; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v10; // [rsp+10h] [rbp-18h] BYREF

v3 = v9;
v4 = v9;
do
{
--v4;
v5 = a1 % a2;
a1 /= a2;
v4[4] = v5;
}
while ( v4 != &v8 );
do
{
v6 = (unsigned int)*v3++;
result = printf("%d", v6);
}
while ( v3 != (char *)&v10 );
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, unsigned int a2)
{
char *v3; // rbx
char *v4; // rcx
int v5; // edx
__int64 v6; // rsi
int result; // eax
char v8; // [rsp+8h] [rbp-20h] BYREF
char v9[4]; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v10; // [rsp+10h] [rbp-18h] BYREF

v3 = v9;
v4 = v9;
do
{
--v4;
v5 = a1 % a2;
a1 /= a2;
v4[4] = v5;
}
while ( v4 != &v8 );
do
{
v6 = (unsigned int)*v3++;
result = printf("%d", v6);
}
while ( v3 != (char *)&v10 );
return result;
}

original_code:
void base(unsigned int number, unsigned int base)
{
 int index;
 unsigned int new, remainder;
 char result[4];
 for (index = sizeof(result) - 1; index >= 0; index--) {
  new = number / base;
  remainder = number - (new * base);
  result[index] = (char)remainder;
  number = new;
 }
 for (index = 0; index < sizeof(result); index++) {
  printf("%d", result[index]);
 }
}

canonical_original_code:
void base(unsigned int number, unsigned int base)
{
 int index;
 unsigned int new; unsigned int remainder;
 char result[4];
 for (index = sizeof(result) - 1; index >= 0; index--) {
  new = number / base;
  remainder = number - (new * base);
  result[index] = (char)remainder;
  number = new;
 }
 for (index = 0; index < sizeof(result); index++) {
  printf("%d", result[index]);
 }
}

variable_types:
base
unsigned int

variable_types:
new
unsigned int

variable_types:
remainder
unsigned int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v4; // ebx
__int64 v5; // rdi
unsigned int v6; // ebp
unsigned int v7; // ebx
__int64 v8; // rdi

for ( i = 0; i != 10; ++i )
{
printf("%d is ", i);
if ( (unsigned int)odd(i) == 1 )
printf("ODD");
else
printf("EVEN");
putchar(10);
}
v4 = 0;
putchar(10);
do
{
printf("%d == 0x", v4);
v5 = v4++;
binary(v5);
putchar(10);
}
while ( v4 != 10 );
v6 = 2;
putchar(10);
while ( 1 )
{
v7 = 0;
do
{
printf("%d in base 10 is ", v7);
v8 = v7++;
base(v8, v6);
printf(" in base %d", v6);
putchar(10);
}
while ( v7 != 11 );
++v6;
putchar(10);
if ( v6 == 11 )
{
putchar(10);
exit(0);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v4; // ebx
__int64 v5; // rdi
unsigned int v6; // ebp
unsigned int v7; // ebx
__int64 v8; // rdi

for ( i = 0; i != 10; ++i )
{
printf("%d is ", i);
if ( (unsigned int)func7(i) == 1 )
printf("ODD");
else
printf("EVEN");
putchar(10);
}
v4 = 0;
putchar(10);
do
{
printf("%d == 0x", v4);
v5 = v4++;
func8(v5);
putchar(10);
}
while ( v4 != 10 );
v6 = 2;
putchar(10);
while ( 1 )
{
v7 = 0;
do
{
printf("%d in base 10 is ", v7);
v8 = v7++;
func9(v8, v6);
printf(" in base %d", v6);
putchar(10);
}
while ( v7 != 11 );
++v6;
putchar(10);
if ( v6 == 11 )
{
putchar(10);
exit(0);
}
}
}

original_code:
int main()
{
 unsigned int number;
 for (number = 0; number < 10; number++) {
  printf("%d is ", number);
  if (1 == odd(number)) {
   printf("ODD");
  } else {
   printf("EVEN");
  }
  printf("\n");
 }
 printf("\n");
 for (number = 0; number < 10; number++) {
  printf("%d == 0x", number);
  binary(number);
  printf("\n");
 }
 printf("\n");
 unsigned int b;
 for (b = 2; b < 11; b++) {
  for (number = 0; number < 11; number++) {
   printf("%d in base 10 is ", number);
   base(number, b);
   printf(" in base %d", b);
   printf("\n");
  }
  printf("\n");
 }
 printf("\n");
 exit(0);
}

variable_types:
b
unsigned int


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

result = (unsigned int)(2 * a1);
if ( (int)result <= 999 )
{
result = (int)result;
do
{
*((_DWORD *)&numbers + result) = 0;
result += a1;
}
while ( (int)result <= 999 );
}
return result;
}

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

result = (unsigned int)(2 * a1);
if ( (int)result <= 999 )
{
result = (int)result;
do
{
*((_DWORD *)&numbers + result) = 0;
result += a1;
}
while ( (int)result <= 999 );
}
return result;
}

original_code:
void mark_multiples(int num)
{
 int ii = num;
 int primes = (sizeof(numbers)/sizeof(*(numbers)));
 for (ii = num + num; ii < primes; ii += num) {
  numbers[ii] = 0;
 }
}

variable_types: num int

variable_types: ii int

variable_types: primes int


decompiled_code:
__int64 __fastcall get_next_prime(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = a1 + 1;
do
{
result = (unsigned int)v1;
if ( *((_DWORD *)&numbers + v1) )
break;
result = (unsigned int)++v1;
}
while ( (_DWORD)v1 != 1000 );
return result;
}

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

v1 = a1 + 1;
do
{
result = (unsigned int)v1;
if ( *((_DWORD *)&numbers + v1) )
break;
result = (unsigned int)++v1;
}
while ( (_DWORD)v1 != 1000 );
return result;
}

original_code:
int get_next_prime(int num)
{
 int answer;
 int primes = (sizeof(numbers)/sizeof(*(numbers)));
 answer = num + 1;
 while (numbers[answer] == 0) {
  answer = answer + 1;
  if (answer == primes)
   break;
 }
 return answer;
}

variable_types: answer int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
int i; // er8
unsigned int v5; // er8
__int64 v6; // rbx
__int64 v7; // rsi

v3 = &numbers;
do
{
*(_DWORD *)v3 = 1;
v3 = (__int64 *)((char *)v3 + 4);
}
while ( v3 != (__int64 *)&end );
numbers = 0LL;
for ( i = 2; i <= 999; i = get_next_prime(v5) )
mark_multiples((unsigned int)i, argv, envp);
v6 = 0LL;
while ( 1 )
{
if ( *((_DWORD *)&numbers + v6) == 1 )
{
v7 = (unsigned int)v6++;
printf("%d\n", v7);
if ( v6 == 1000 )
LABEL_9:
exit(0);
}
else if ( ++v6 == 1000 )
{
goto LABEL_9;
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
int i; // er8
unsigned int v5; // er8
__int64 v6; // rbx
__int64 v7; // rsi

v3 = &numbers;
do
{
*(_DWORD *)v3 = 1;
v3 = (__int64 *)((char *)v3 + 4);
}
while ( v3 != (__int64 *)&end );
numbers = 0LL;
for ( i = 2; i <= 999; i = func8(v5) )
func7((unsigned int)i, argv, envp);
v6 = 0LL;
while ( 1 )
{
if ( *((_DWORD *)&numbers + v6) == 1 )
{
v7 = (unsigned int)v6++;
printf("%d\n", v7);
if ( v6 == 1000 )
LABEL_9:
exit(0);
}
else if ( ++v6 == 1000 )
{
goto LABEL_9;
}
}
}

original_code:
int main()
{
 int ii, next_prime;
 int primes = (sizeof(numbers)/sizeof(*(numbers)));
 for (ii = 0; ii < primes; ii++) {
  numbers[ii] = 1;
 }
 numbers[0] = 0;
 numbers[1] = 0;
 next_prime = 2;
 do {
  mark_multiples(next_prime);
  next_prime = get_next_prime(next_prime);
 }
 while (next_prime < primes);
 for (ii = 0; ii < primes; ii++) {
  if (1 == numbers[ii]) {
   printf("%d\n", ii);
  }
 }
 exit(0);
}

canonical_original_code:
int main()
{
 int ii; int next_prime;
 int primes = (sizeof(numbers)/sizeof(*(numbers)));
 for (ii = 0; ii < primes; ii++) {
  numbers[ii] = 1;
 }
 numbers[0] = 0;
 numbers[1] = 0;
 next_prime = 2;
 do {
  mark_multiples(next_prime);
  next_prime = get_next_prime(next_prime);
 }
 while (next_prime < primes);
 for (ii = 0; ii < primes; ii++) {
  if (1 == numbers[ii]) {
   printf("%d\n", ii);
  }
 }
 exit(0);
}


mean

decompiled_code:
__int64 __fastcall mean(int a1, int a2)
{
return (unsigned int)((a1 + a2) / 2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)((a1 + a2) / 2);
}

original_code:
int mean(int a, int b)
{
 return (a + b) / 2;
}

variable_types: a int

variable_types: b int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdx

v3 = mean(7LL, 9LL, 9LL);
printf("The mean of %d and %d is %d\n", 7LL, v4, v3);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdx

v3 = func7(7LL, 9LL, 9LL);
printf("The mean of %d and %d is %d\n", 7LL, v4, v3);
exit(0);
}

original_code:
int main()
{
 int i, j;
 int answer;
 i = 7;
 j = 9;
 answer = mean(i, j);
 printf("The mean of %d and %d is %d\n", i, j, answer);
 exit(0);
}

canonical_original_code:
int main()
{
 int i; int j;
 int answer;
 i = 7;
 j = 9;
 answer = mean(i, j);
 printf("The mean of %d and %d is %d\n", i, j, answer);
 exit(0);
}

variable_types: i int

variable_types: j int


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

initscr();
noecho();
keypad(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
do
v3 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
while ( (unsigned int)parseinput(v3) );
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

initscr();
noecho();
keypad(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
do
v3 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
while ( (unsigned int)func7(v3) );
endwin();
return 0;
}

original_code:
int main(int argc, char** argv) {
 initscr();
 noecho();
 keypad(stdscr, 1);
 while(parseinput(wgetch(stdscr)));
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 initscr();
 noecho();
 keypad(stdscr, 1);
 while(parseinput(wgetch(stdscr)));
 endwin();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


parseinput

decompiled_code:
__int64 __fastcall parseinput(unsigned int a1)
{
__int64 v1; // rcx
int v2; // esi
int v3; // edi
__int64 v5; // rax

if ( a1 == 274 )
return 0LL;
v1 = a1;
if ( !buf_0 )
{
v5 = g_array_new();
v1 = a1;
buf_0 = v5;
}
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v2 = stdscr__NCURSES6_TINFO_5_0_19991023->_curx;
v3 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy;
}
else
{
v3 = -2;
v2 = -1;
}
mvprintw(v3, v2, "%c", v1);
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 v1; // rcx
int v2; // esi
int v3; // edi
__int64 v5; // rax

if ( a1 == 274 )
return 0LL;
v1 = a1;
if ( !buf_0 )
{
v5 = g_array_new();
v1 = a1;
buf_0 = v5;
}
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v2 = stdscr__NCURSES6_TINFO_5_0_19991023->_curx;
v3 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy;
}
else
{
v3 = -2;
v2 = -1;
}
mvprintw(v3, v2, "%c", v1);
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
return 1LL;
}

original_code:
int parseinput(int ch) {
 static GArray *buf = 0;
 int x, y, mx, my;
 switch(ch) {
  case (0410 +(10)):
   return 0;
  case '\n':
  default:
   if(!buf) buf = g_array_new(0, 0, 1);
   (y = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), x = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
   (my = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
   mvprintw(my - 1, x, "%c", ch);
 }
 wrefresh(stdscr);
 return 1;
}

canonical_original_code:
int parseinput(int ch) {
 static struct _GArray *buf = 0;
 int x; int y; int mx; int my;
 switch(ch) {
  case (0410 +(10)):
   return 0;
  case '\n':
  default:
   if(!buf) buf = g_array_new(0, 0, 1);
   (y = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), x = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
   (my = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
   mvprintw(my - 1, x, "%c", ch);
 }
 wrefresh(stdscr);
 return 1;
}

variable_types: ch int

variable_types: struct _GArray { char *data; unsigned int len; } *

variable_types: x int

variable_types: y int

variable_types: mx int

variable_types: my int


doPthreadPool

repo: labanyd/threadpool

decompiled_code:
void __fastcall __noreturn doPthreadPool(void *a1)
{
pthread_mutex_t *v1; // rbp
int v2; // eax
__int64 v3; // rdx
__int64 v4; // r14
void (__fastcall *v5)(__int64); // r13
__int64 v6; // rdx
__int64 v7; // [rsp+0h] [rbp-C8h]
int v8; // [rsp+Ch] [rbp-BCh]
__int64 v9; // [rsp+10h] [rbp-B8h] BYREF
int v10; // [rsp+18h] [rbp-B0h]
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-A8h] BYREF

v7 = *(_QWORD *)a1;
v8 = *((_DWORD *)a1 + 2);
v9 = *(_QWORD *)a1;
v10 = v8;
pthread_setcanceltype(1, 0LL);
if ( !_sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
_pthread_register_cancel(&buf);
v1 = (pthread_mutex_t *)(v7 + 8);
while ( 1 )
{
pthread_mutex_lock(v1);
while ( 1 )
{
v2 = *(_DWORD *)(v7 + 120);
if ( v2 )
break;
*(_DWORD *)(*(_QWORD *)(v7 + 96) + 4LL * v8) = 1;
pthread_cond_wait((pthread_cond_t *)(v7 + 48), v1);
}
v3 = *(_QWORD *)(v7 + 104);
v4 = *(_QWORD *)(v3 + 8);
v5 = *(void (__fastcall **)(__int64))v3;
v6 = *(_QWORD *)(v3 + 16);
*(_DWORD *)(v7 + 120) = v2 - 1;
*(_QWORD *)(v7 + 104) = v6;
pthread_mutex_unlock(v1);
*(_DWORD *)(*(_QWORD *)(v7 + 96) + 4LL * v8) = 2;
pthread_testcancel();
v5(v4);
pthread_testcancel();
}
}
CleanUp(&v9);
_pthread_unwind_next(&buf);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
pthread_mutex_t *v1; // rbp
int v2; // eax
__int64 v3; // rdx
__int64 v4; // r14
void (__fastcall *v5)(__int64); // r13
__int64 v6; // rdx
__int64 v7; // [rsp+0h] [rbp-C8h]
int v8; // [rsp+Ch] [rbp-BCh]
__int64 v9; // [rsp+10h] [rbp-B8h] BYREF
int v10; // [rsp+18h] [rbp-B0h]
__pthread_unwind_buf_t buf; // [rsp+20h] [rbp-A8h] BYREF

v7 = *(_QWORD *)a1;
v8 = *((_DWORD *)a1 + 2);
v9 = *(_QWORD *)a1;
v10 = v8;
pthread_setcanceltype(1, 0LL);
if ( !_sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
_pthread_register_cancel(&buf);
v1 = (pthread_mutex_t *)(v7 + 8);
while ( 1 )
{
pthread_mutex_lock(v1);
while ( 1 )
{
v2 = *(_DWORD *)(v7 + 120);
if ( v2 )
break;
*(_DWORD *)(*(_QWORD *)(v7 + 96) + 4LL * v8) = 1;
pthread_cond_wait((pthread_cond_t *)(v7 + 48), v1);
}
v3 = *(_QWORD *)(v7 + 104);
v4 = *(_QWORD *)(v3 + 8);
v5 = *(void (__fastcall **)(__int64))v3;
v6 = *(_QWORD *)(v3 + 16);
*(_DWORD *)(v7 + 120) = v2 - 1;
*(_QWORD *)(v7 + 104) = v6;
pthread_mutex_unlock(v1);
*(_DWORD *)(*(_QWORD *)(v7 + 96) + 4LL * v8) = 2;
pthread_testcancel();
v5(v4);
pthread_testcancel();
}
}
func0(&v9);
_pthread_unwind_next(&buf);
}

original_code:
void *
doPthreadPool(void *arg)
{
 Func fun;
 void *argument;
 PthreadPool *pool = ((PthreadStatus *)arg)->m_pool;
 int seq = ((PthreadStatus *)arg)->m_iThread;
 PthreadStatus pStatus = {pool, seq};
 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
 do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (CleanUp); void *__cancel_arg = ((void*)&pStatus); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 while (1)
 {
  pthread_mutex_lock(&pool->m_mutex);
  while (pool->m_iTaskNum == 0)
  {
   *(pool->m_pStatus + seq) = THREAD_WAITTING;
   pthread_cond_wait(&pool->m_cond, &pool->m_mutex);
  }
  fun = pool->m_pTaskHead->m_pFunc;
  argument = pool->m_pTaskHead->m_pArg;
  pool->m_pTaskHead = pool->m_pTaskHead->next;
  pool->m_iTaskNum--;
  pthread_mutex_unlock(&pool->m_mutex);
  *(pool->m_pStatus + seq) = THREAD_RUNNING;
  pthread_testcancel();
  (*fun)(argument);
  pthread_testcancel();
 }
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
}

canonical_original_code:
void *doPthreadPool(void *arg)
{
 void (*fun)(void *arg);
 void *argument;
 struct pthreadpool_t *pool = ((PthreadStatus *)arg)->m_pool;
 int seq = ((PthreadStatus *)arg)->m_iThread;
 struct PthreadStatus pStatus = {pool, seq};
 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
 do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (CleanUp); void *__cancel_arg = ((void*)&pStatus); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 while (1)
 {
  pthread_mutex_lock(&pool->m_mutex);
  while (pool->m_iTaskNum == 0)
  {
   *(pool->m_pStatus + seq) = THREAD_WAITTING;
   pthread_cond_wait(&pool->m_cond, &pool->m_mutex);
  }
  fun = pool->m_pTaskHead->m_pFunc;
  argument = pool->m_pTaskHead->m_pArg;
  pool->m_pTaskHead = pool->m_pTaskHead->next;
  pool->m_iTaskNum--;
  pthread_mutex_unlock(&pool->m_mutex);
  *(pool->m_pStatus + seq) = THREAD_RUNNING;
  pthread_testcancel();
  (*fun)(argument);
  pthread_testcancel();
 }
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
}

variable_types:
arg
void *

variable_types:
fun
void (*)(void *arg)

variable_types:
argument
void *

variable_types: seq int

variable_types: struct PthreadStatus { struct pthreadpool_t { unsigned long *m_pth; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } m_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } m_cond; int *m_pStatus; struct task_element_t { void (*m_pFunc)(void *arg); void *m_pArg; struct task_element_t *next; } *m_pTaskHead; struct task_element_t *m_pTaskTail; int m_iTaskNum; int m_iPthreadNum; } *m_pool; int m_iThread; }

variable_types: struct __pthread_unwind_buf_t { struct { long __cancel_jmp_buf[8]; int __mask_was_saved; } __cancel_jmp_buf[1]; void *__pad[4]; }

return_type: void *

user_defined_types: struct PthreadStatus { struct pthreadpool_t *m_pool; int m_iThread; }

user_defined_types: struct pthreadpool_t { unsigned long *m_pth; union pthread_mutex_t m_mutex; union pthread_cond_t m_cond; int *m_pStatus; struct task_element_t *m_pTaskHead; struct task_element_t *m_pTaskTail; int m_iTaskNum; int m_iPthreadNum; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


PthreadPoolInit

decompiled_code:
__int64 __fastcall PthreadPoolInit(int a1)
{
char *v1; // rax
__int64 v2; // r12
void *v3; // rax
void *v4; // rbp
void *v5; // rax
__int64 v6; // rbx
void *v7; // rdi
void *v9; // rdi
__int64 v10; // [rsp+0h] [rbp-38h] BYREF
int v11; // [rsp+8h] [rbp-30h]

v1 = (char *)malloc(0x80uLL);
v2 = (__int64)v1;
if ( !v1 )
return v2;
*((_DWORD *)v1 + 30) = 0;
*((_QWORD *)v1 + 13) = 0LL;
*((_QWORD *)v1 + 14) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(v1 + 8), 0LL);
pthread_cond_init((pthread_cond_t *)(v2 + 48), 0LL);
v3 = malloc(8LL * a1);
*(_QWORD *)v2 = v3;
v4 = v3;
if ( !v3 )
{
LABEL_12:
v9 = (void *)v2;
v2 = 0LL;
free(v9);
return v2;
}
*(_DWORD *)(v2 + 124) = a1;
v5 = malloc(4LL * a1);
*(_QWORD *)(v2 + 96) = v5;
if ( !v5 )
{
free(v4);
goto LABEL_12;
}
if ( a1 > 0 )
{
v6 = 0LL;
while ( 1 )
{
v10 = v2;
v11 = v6;
if ( pthread_create((pthread_t *)v4 + v6, 0LL, (void *(*)(void *))doPthreadPool, &v10) )
break;
*(_DWORD *)(*(_QWORD *)(v2 + 96) + 4 * v6++) = 0;
usleep(0x3E8u);
if ( v6 == a1 )
return v2;
v4 = *(void **)v2;
}
free(*(void **)(v2 + 96));
free(*(void **)v2);
v7 = (void *)v2;
v2 = 0LL;
free(v7);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
char *v1; // rax
__int64 v2; // r12
void *v3; // rax
void *v4; // rbp
void *v5; // rax
__int64 v6; // rbx
void *v7; // rdi
void *v9; // rdi
__int64 v10; // [rsp+0h] [rbp-38h] BYREF
int v11; // [rsp+8h] [rbp-30h]

v1 = (char *)malloc(0x80uLL);
v2 = (__int64)v1;
if ( !v1 )
return v2;
*((_DWORD *)v1 + 30) = 0;
*((_QWORD *)v1 + 13) = 0LL;
*((_QWORD *)v1 + 14) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(v1 + 8), 0LL);
pthread_cond_init((pthread_cond_t *)(v2 + 48), 0LL);
v3 = malloc(8LL * a1);
*(_QWORD *)v2 = v3;
v4 = v3;
if ( !v3 )
{
LABEL_12:
v9 = (void *)v2;
v2 = 0LL;
free(v9);
return v2;
}
*(_DWORD *)(v2 + 124) = a1;
v5 = malloc(4LL * a1);
*(_QWORD *)(v2 + 96) = v5;
if ( !v5 )
{
free(v4);
goto LABEL_12;
}
if ( a1 > 0 )
{
v6 = 0LL;
while ( 1 )
{
v10 = v2;
v11 = v6;
if ( pthread_create((pthread_t *)v4 + v6, 0LL, (void *(*)(void *))doPthreadPool, &v10) )
break;
*(_DWORD *)(*(_QWORD *)(v2 + 96) + 4 * v6++) = 0;
usleep(0x3E8u);
if ( v6 == a1 )
return v2;
v4 = *(void **)v2;
}
free(*(void **)(v2 + 96));
free(*(void **)v2);
v7 = (void *)v2;
v2 = 0LL;
free(v7);
}
return v2;
}

original_code:
PthreadPool *
PthreadPoolInit(int pthreadNums)
{
 PthreadPool *pool = (PthreadPool *) malloc (sizeof(PthreadPool));
 if (pool == ((void *)0))
 {
  return ((void *)0);
 }
 pool->m_pTaskHead = ((void *)0);
 pool->m_pTaskTail = ((void *)0);
 pool->m_iTaskNum = 0;
 pthread_mutex_init(&pool->m_mutex, ((void *)0));
 pthread_cond_init(&pool->m_cond, ((void *)0));
 pool->m_pth = (pthread_t *) malloc (sizeof(pthread_t) * pthreadNums);
 if (((void *)0) == pool->m_pth)
 {
  free(pool);
  return ((void *)0);
 }
 pool->m_iPthreadNum = pthreadNums;
 pool->m_pStatus = (int *) malloc (sizeof(int) * pthreadNums);
 if (((void *)0) == pool->m_pStatus)
 {
  free(pool->m_pth);
  free(pool);
  return ((void *)0);
 }
 int i , ret;
 PthreadStatus pst;
 for (i = 0; i < pthreadNums; i++)
 {
  pst.m_pool = pool;
  pst.m_iThread = i;
  ret = pthread_create(pool->m_pth + i, ((void *)0), doPthreadPool,
   (void *)&pst);
  if (0 != ret)
  {
   free(pool->m_pStatus);
   free(pool->m_pth);
   free(pool);
   return ((void *)0);
  }
  *(pool->m_pStatus + i) = THREAD_INIT;
  usleep(1000);
 }
 return pool;
}

canonical_original_code:
struct pthreadpool_t *PthreadPoolInit(int pthreadNums)
{
 struct pthreadpool_t *pool = (PthreadPool *) malloc (sizeof(PthreadPool));
 if (pool == ((void *)0))
 {
  return ((void *)0);
 }
 pool->m_pTaskHead = ((void *)0);
 pool->m_pTaskTail = ((void *)0);
 pool->m_iTaskNum = 0;
 pthread_mutex_init(&pool->m_mutex, ((void *)0));
 pthread_cond_init(&pool->m_cond, ((void *)0));
 pool->m_pth = (unsigned long *) malloc (sizeof(pthread_t) * pthreadNums);
 if (((void *)0) == pool->m_pth)
 {
  free(pool);
  return ((void *)0);
 }
 pool->m_iPthreadNum = pthreadNums;
 pool->m_pStatus = (int *) malloc (sizeof(int) * pthreadNums);
 if (((void *)0) == pool->m_pStatus)
 {
  free(pool->m_pth);
  free(pool);
  return ((void *)0);
 }
 int i; int ret;
 struct PthreadStatus pst;
 for (i = 0; i < pthreadNums; i++)
 {
  pst.m_pool = pool;
  pst.m_iThread = i;
  ret = pthread_create(pool->m_pth + i, ((void *)0), doPthreadPool,
   (void *)&pst);
  if (0 != ret)
  {
   free(pool->m_pStatus);
   free(pool->m_pth);
   free(pool);
   return ((void *)0);
  }
  *(pool->m_pStatus + i) = THREAD_INIT;
  usleep(1000);
 }
 return pool;
}

variable_types: pthreadNums int

variable_types: struct pthreadpool_t { unsigned long *m_pth; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } m_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } m_cond; int *m_pStatus; struct task_element_t { void (*m_pFunc)(void *arg); void *m_pArg; struct task_element_t *next; } *m_pTaskHead; struct task_element_t *m_pTaskTail; int m_iTaskNum; int m_iPthreadNum; } *

variable_types: ret int


FreeTaskQueue

original_code:
void
FreeTaskQueue(PthreadPool *pool)
{
 TaskElement *ele = pool->m_pTaskHead;
 while (ele)
 {
  pool->m_pTaskHead = pool->m_pTaskHead->next;
  free(ele);
  ele = pool->m_pTaskHead;
 }
}

canonical_original_code:
void FreeTaskQueue(struct pthreadpool_t *pool)
{
 struct task_element_t *ele = pool->m_pTaskHead;
 while (ele)
 {
  pool->m_pTaskHead = pool->m_pTaskHead->next;
  free(ele);
  ele = pool->m_pTaskHead;
 }
}

variable_types: struct task_element_t { void (*m_pFunc)(void *arg); void *m_pArg; struct task_element_t *next; } *

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

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


PthreadPoolDestroy

decompiled_code:
__int64 __fastcall PthreadPoolDestroy(void *ptr)
{
__int64 v2; // r12
__int64 v3; // r12
__int64 v4; // rbx
pthread_t v5; // rdi

if ( !ptr )
return 4294967293LL;
v2 = *((int *)ptr + 31);
if ( (int)v2 > 0 )
{
v3 = 8 * v2;
v4 = 0LL;
do
{
pthread_cancel(*(_QWORD *)(*(_QWORD *)ptr + v4));
v5 = *(_QWORD *)(*(_QWORD *)ptr + v4);
v4 += 8LL;
pthread_join(v5, 0LL);
}
while ( v4 != v3 );
}
free(*(void **)ptr);
free(*((void **)ptr + 12));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 8));
pthread_cond_destroy((pthread_cond_t *)ptr + 1);
FreeTaskQueue((__int64)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
__int64 v2; // r12
__int64 v3; // r12
__int64 v4; // rbx
pthread_t v5; // rdi

if ( !ptr )
return 4294967293LL;
v2 = *((int *)ptr + 31);
if ( (int)v2 > 0 )
{
v3 = 8 * v2;
v4 = 0LL;
do
{
pthread_cancel(*(_QWORD *)(*(_QWORD *)ptr + v4));
v5 = *(_QWORD *)(*(_QWORD *)ptr + v4);
v4 += 8LL;
pthread_join(v5, 0LL);
}
while ( v4 != v3 );
}
free(*(void **)ptr);
free(*((void **)ptr + 12));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 8));
pthread_cond_destroy((pthread_cond_t *)ptr + 1);
func3((__int64)ptr);
free(ptr);
return 0LL;
}

original_code:
int
PthreadPoolDestroy(PthreadPool *pool)
{
 if (((void *)0) == (pool)) { return (PTHREAD_POOL_NULL); };
 int i = 0;
 int seq = pool->m_iPthreadNum;
 for (; i < seq; i++)
 {
  pthread_cancel(*(pool->m_pth + i));
  pthread_join(*(pool->m_pth + i), 0);
 }
 free(pool->m_pth);
 free(pool->m_pStatus);
 pthread_mutex_destroy(&pool->m_mutex);
 pthread_cond_destroy(&pool->m_cond);
 FreeTaskQueue(pool);
 free(pool);
 return SUCCESS;
}

canonical_original_code:
int PthreadPoolDestroy(struct pthreadpool_t *pool)
{
 if (((void *)0) == (pool)) { return (PTHREAD_POOL_NULL); };
 int i = 0;
 int seq = pool->m_iPthreadNum;
 for (; i < seq; i++)
 {
  pthread_cancel(*(pool->m_pth + i));
  pthread_join(*(pool->m_pth + i), 0);
 }
 free(pool->m_pth);
 free(pool->m_pStatus);
 pthread_mutex_destroy(&pool->m_mutex);
 pthread_cond_destroy(&pool->m_cond);
 FreeTaskQueue(pool);
 free(pool);
 return SUCCESS;
}

variable_types: i int

user_defined_types: struct task_element_t { void (*m_pFunc)(void *arg); void *m_pArg; struct task_element_t *next; }


PthreadPoolAddTask

decompiled_code:
__int64 __fastcall PthreadPoolAddTask(__int64 a1, __int64 a2, __int64 a3)
{
pthread_mutex_t *v3; // r13
_QWORD *v5; // rax
bool v6; // zf
__int64 result; // rax

if ( !a1 )
return 4294967293LL;
if ( !a2 )
return 4294967292LL;
v3 = (pthread_mutex_t *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v5 = malloc(0x18uLL);
if ( v5 )
{
v6 = *(_QWORD *)(a1 + 104) == 0LL;
*v5 = a2;
v5[1] = a3;
v5[2] = 0LL;
if ( v6 )
*(_QWORD *)(a1 + 104) = v5;
else
*(_QWORD *)(*(_QWORD *)(a1 + 112) + 16LL) = v5;
*(_QWORD *)(a1 + 112) = v5;
++*(_DWORD *)(a1 + 120);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
pthread_mutex_unlock(v3);
result = 0LL;
}
else
{
pthread_mutex_unlock(v3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
pthread_mutex_t *v3; // r13
_QWORD *v5; // rax
bool v6; // zf
__int64 result; // rax

if ( !a1 )
return 4294967293LL;
if ( !a2 )
return 4294967292LL;
v3 = (pthread_mutex_t *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v5 = malloc(0x18uLL);
if ( v5 )
{
v6 = *(_QWORD *)(a1 + 104) == 0LL;
*v5 = a2;
v5[1] = a3;
v5[2] = 0LL;
if ( v6 )
*(_QWORD *)(a1 + 104) = v5;
else
*(_QWORD *)(*(_QWORD *)(a1 + 112) + 16LL) = v5;
*(_QWORD *)(a1 + 112) = v5;
++*(_DWORD *)(a1 + 120);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
pthread_mutex_unlock(v3);
result = 0LL;
}
else
{
pthread_mutex_unlock(v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
PthreadPoolAddTask(PthreadPool *pool, Func fun, void *arg)
{
 if (((void *)0) == (pool)) { return (PTHREAD_POOL_NULL); };
 if (((void *)0) == (fun)) { return (TASK_FUNCTION_NULL); };
 pthread_mutex_lock(&pool->m_mutex);
 TaskElement * ele = (TaskElement *) malloc (sizeof(TaskElement));
 if (((void *)0) == ele)
 {
  pthread_mutex_unlock(&pool->m_mutex);
  return MALLOC_FAIL;
 }
 ele->m_pFunc = fun;
 ele->m_pArg = arg;
 ele->next = ((void *)0);
 if (pool->m_pTaskHead == ((void *)0))
 {
  pool->m_pTaskHead = ele;
  pool->m_pTaskTail = ele;
 }
 else
 {
  pool->m_pTaskTail->next = ele;
  pool->m_pTaskTail = ele;
 }
 pool->m_iTaskNum++;
 pthread_cond_broadcast(&pool->m_cond);
 pthread_mutex_unlock(&pool->m_mutex);
 return SUCCESS;
}

canonical_original_code:
int PthreadPoolAddTask(struct pthreadpool_t *pool, void (*fun)(void *arg), void *arg)
{
 if (((void *)0) == (pool)) { return (PTHREAD_POOL_NULL); };
 if (((void *)0) == (fun)) { return (TASK_FUNCTION_NULL); };
 pthread_mutex_lock(&pool->m_mutex);
 struct task_element_t *ele = (TaskElement *) malloc (sizeof(TaskElement));
 if (((void *)0) == ele)
 {
  pthread_mutex_unlock(&pool->m_mutex);
  return MALLOC_FAIL;
 }
 ele->m_pFunc = fun;
 ele->m_pArg = arg;
 ele->next = ((void *)0);
 if (pool->m_pTaskHead == ((void *)0))
 {
  pool->m_pTaskHead = ele;
  pool->m_pTaskTail = ele;
 }
 else
 {
  pool->m_pTaskTail->next = ele;
  pool->m_pTaskTail = ele;
 }
 pool->m_iTaskNum++;
 pthread_cond_broadcast(&pool->m_cond);
 pthread_mutex_unlock(&pool->m_mutex);
 return SUCCESS;
}


repo: lagodiuk/raytracing-render

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

if ( *(_QWORD *)(a1 + 16) )
release_kd_tree();
result = build_kd_tree(*(_QWORD *)a1, (unsigned int)(*(_DWORD *)(a1 + 12) + 1));
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

if ( *(_QWORD *)(a1 + 16) )
release_kd_tree();
result = build_kd_tree(*(_QWORD *)a1, (unsigned int)(*(_DWORD *)(a1 + 12) + 1));
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
static inline void
rebuild_kd_tree(Scene * scene) {
    if(scene->kd_tree)
        release_kd_tree(scene->kd_tree);
    scene->kd_tree = build_kd_tree(scene->objects, scene->last_object_index + 1);
}

canonical_original_code:
static inline void rebuild_kd_tree(struct Scene *scene) {
    if(scene->kd_tree)
        release_kd_tree(scene->kd_tree);
    scene->kd_tree = build_kd_tree(scene->objects, scene->last_object_index + 1);
}

variable_types: struct Scene { struct Object3d { void *data; int (*intersect)(void *data, struct Point3d { double x; double y; double z; } vector_start, struct Vector3d { double x; double y; double z; } vector, struct Point3d *intersection_point); struct Color { unsigned char r; unsigned char g; unsigned char b; } (*get_color)(void *data, struct Point3d intersection_point); struct Vector3d (*get_normal_vector)(void *data, struct Point3d intersection_point); struct Material { double Ka; double Kd; double Ks; double Kr; double Kt; double p; } (*get_material)(void *data, struct Point3d intersection_point); struct Point3d (*get_min_boundary_point)(void *data); struct Point3d (*get_max_boundary_point)(void *data); void (*release_data)(void *data); } **objects; int objects_count; int last_object_index; struct KDTree { struct KDNode { enum Plane { XY=0, XZ=1, YZ=2, NONE=3 } plane; union Coord { double x; double y; double z; } coord; struct Object3d **objects; int objects_count; struct KDNode *l; struct KDNode *r; } *root; struct Voxel { double x_min; double y_min; double z_min; double x_max; double y_max; double z_max; } bounding_box; } *kd_tree; struct LightSource3d { struct Point3d location_world; struct Point3d location; struct Color color; } **light_sources; int light_sources_count; int last_light_source_index; struct Color background_color; double (*fog_density)(double distance, void *fog_parameters); void *fog_parameters; } *

user_defined_types: struct Scene { struct Object3d **objects; int objects_count; int last_object_index; struct KDTree *kd_tree; struct LightSource3d **light_sources; int light_sources_count; int last_light_source_index; struct Color background_color; double (*fog_density)(double distance, void *fog_parameters); void *fog_parameters; }

user_defined_types: struct KDTree { struct KDNode *root; struct Voxel bounding_box; }

user_defined_types: struct Object3d { void *data; int (*intersect)(void *data, struct Point3d vector_start, struct Vector3d vector, struct Point3d *intersection_point); struct Color (*get_color)(void *data, struct Point3d intersection_point); struct Vector3d (*get_normal_vector)(void *data, struct Point3d intersection_point); struct Material (*get_material)(void *data, struct Point3d intersection_point); struct Point3d (*get_min_boundary_point)(void *data); struct Point3d (*get_max_boundary_point)(void *data); void (*release_data)(void *data); }

user_defined_types: struct KDNode { enum Plane plane; union Coord coord; struct Object3d **objects; int objects_count; struct KDNode *l; struct KDNode *r; }


decompiled_code:
__int64 __fastcall add_object(__int64 *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *a1;
LODWORD(result) = *((_DWORD *)a1 + 3) + 1;
*((_DWORD *)a1 + 3) = result;
result = (int)result;
*(_QWORD *)(v2 + 8LL * (int)result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *a1;
LODWORD(result) = *((_DWORD *)a1 + 3) + 1;
*((_DWORD *)a1 + 3) = result;
result = (int)result;
*(_QWORD *)(v2 + 8LL * (int)result) = a2;
return result;
}

original_code:
void
add_object(Scene * const scene,
           Object3d * const object) {
    scene->objects[++scene->last_object_index] = object;
}

canonical_original_code:
void add_object(struct Scene *scene, struct Object3d *object) {
    scene->objects[++scene->last_object_index] = object;
}

variable_types:
object
struct Object3d *

user_defined_types: struct Voxel { double x_min; double y_min; double z_min; double x_max; double y_max; double z_max; }

user_defined_types: struct LightSource3d { struct Point3d location_world; struct Point3d location; struct Color color; }

user_defined_types: union Coord { double x; double y; double z; }

user_defined_types: struct Point3d { double x; double y; double z; }

user_defined_types: struct Vector3d { double x; double y; double z; }

user_defined_types: struct Color { unsigned char r; unsigned char g; unsigned char b; }

user_defined_types: struct Material { double Ka; double Kd; double Ks; double Kr; double Kt; double p; }


decompiled_code:
// attributes: thunk
__int64 __fastcall prepare_scene(__int64 a1)
{
return rebuild_kd_tree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return func5(a1);
}

original_code:
void
prepare_scene(Scene * const scene) {
    rebuild_kd_tree(scene);
}

canonical_original_code:
void prepare_scene(struct Scene *scene) {
    rebuild_kd_tree(scene);
}


decompiled_code:
__int64 __fastcall add_light_source(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 24);
LODWORD(result) = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = result;
result = (int)result;
*(_QWORD *)(v2 + 8LL * (int)result) = a2;
return result;
}

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

v2 = *(_QWORD *)(a1 + 24);
LODWORD(result) = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = result;
result = (int)result;
*(_QWORD *)(v2 + 8LL * (int)result) = a2;
return result;
}

original_code:
void
add_light_source(Scene * const scene,
                 LightSource3d * const light_source) {
    scene->light_sources[++scene->last_light_source_index] = light_source;
}

canonical_original_code:
void add_light_source(struct Scene *scene, struct LightSource3d *light_source) {
    scene->light_sources[++scene->last_light_source_index] = light_source;
}


decompiled_code:
void __fastcall release_object3d(void *ptr)
{
(*((void (__fastcall **)(_QWORD))ptr + 7))(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
(*((void (__fastcall **)(_QWORD))ptr + 7))(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void
release_object3d(Object3d * obj) {
    obj->release_data(obj->data);
    free(obj);
}

canonical_original_code:
void release_object3d(struct Object3d *obj) {
    obj->release_data(obj->data);
    free(obj);
}

variable_types: struct Object3d { void *data; int (*intersect)(void *data, struct Point3d { double x; double y; double z; } vector_start, struct Vector3d { double x; double y; double z; } vector, struct Point3d *intersection_point); struct Color { unsigned char r; unsigned char g; unsigned char b; } (*get_color)(void *data, struct Point3d intersection_point); struct Vector3d (*get_normal_vector)(void *data, struct Point3d intersection_point); struct Material { double Ka; double Kd; double Ks; double Kr; double Kt; double p; } (*get_material)(void *data, struct Point3d intersection_point); struct Point3d (*get_min_boundary_point)(void *data); struct Point3d (*get_max_boundary_point)(void *data); void (*release_data)(void *data); } *


decompiled_code:
void __fastcall release_scene(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi
__int64 v4; // rbx
void *v5; // rdi
void *v6; // rdi

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
release_object3d(v3);
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
if ( *((int *)ptr + 8) > 0 )
{
v4 = 0LL;
do
{
v5 = *(void **)(*((_QWORD *)ptr + 3) + 8 * v4);
if ( v5 )
free(v5);
++v4;
}
while ( *((_DWORD *)ptr + 8) > (int)v4 );
}
free(*(void **)ptr);
free(*((void **)ptr + 3));
v6 = (void *)*((_QWORD *)ptr + 7);
if ( v6 )
free(v6);
if ( *((_QWORD *)ptr + 2) )
release_kd_tree();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi
__int64 v4; // rbx
void *v5; // rdi
void *v6; // rdi

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
func9(v3);
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
if ( *((int *)ptr + 8) > 0 )
{
v4 = 0LL;
do
{
v5 = *(void **)(*((_QWORD *)ptr + 3) + 8 * v4);
if ( v5 )
free(v5);
++v4;
}
while ( *((_DWORD *)ptr + 8) > (int)v4 );
}
free(*(void **)ptr);
free(*((void **)ptr + 3));
v6 = (void *)*((_QWORD *)ptr + 7);
if ( v6 )
free(v6);
if ( *((_QWORD *)ptr + 2) )
release_kd_tree();
free(ptr);
}

original_code:
void
release_scene(Scene * scene) {
    int i;
    for(i = 0; i < scene->objects_count; i++) {
        if(scene->objects[i]) {
            release_object3d(scene->objects[i]);
        }
    }
    for(i = 0; i < scene->light_sources_count; i++) {
        if(scene->light_sources[i]) {
            free(scene->light_sources[i]);
        }
    }
    free(scene->objects);
    free(scene->light_sources);
    if(scene->fog_parameters) {
        free(scene->fog_parameters);
    }
    if(scene->kd_tree)
        release_kd_tree(scene->kd_tree);
    free(scene);
}

canonical_original_code:
void release_scene(struct Scene *scene) {
    int i;
    for(i = 0; i < scene->objects_count; i++) {
        if(scene->objects[i]) {
            release_object3d(scene->objects[i]);
        }
    }
    for(i = 0; i < scene->light_sources_count; i++) {
        if(scene->light_sources[i]) {
            free(scene->light_sources[i]);
        }
    }
    free(scene->objects);
    free(scene->light_sources);
    if(scene->fog_parameters) {
        free(scene->fog_parameters);
    }
    if(scene->kd_tree)
        release_kd_tree(scene->kd_tree);
    free(scene);
}


decompiled_code:
double *__fastcall new_camera(double a1, double a2, double a3, double a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, __int128 a11, __int64 a12)
{
double *result; // rax
__m128i v13; // xmm4
__int64 v14; // rdx
double v15; // [rsp+0h] [rbp-68h]
double v16; // [rsp+8h] [rbp-60h]
double v17; // [rsp+10h] [rbp-58h]
double v18; // [rsp+18h] [rbp-50h]
double v19; // [rsp+20h] [rbp-48h]
double v20; // [rsp+28h] [rbp-40h]
double cosx; // [rsp+40h] [rbp-28h] BYREF
double sinx[4]; // [rsp+48h] [rbp-20h] BYREF

sincos(a3, sinx, &cosx);
v20 = cosx;
v19 = sinx[0];
sincos(a2, sinx, &cosx);
v18 = cosx;
v17 = sinx[0];
sincos(a1, sinx, &cosx);
v16 = cosx;
v15 = sinx[0];
result = (double *)malloc(0x68uLL);
v13 = _mm_loadu_si128((const __m128i *)&a11);
result[3] = a1;
*(__m128i *)result = v13;
v14 = a12;
result[6] = a2;
*((_QWORD *)result + 2) = v14;
result[4] = v15;
result[5] = v16;
result[7] = v17;
result[8] = v18;
result[9] = a3;
result[10] = v19;
result[11] = v20;
result[12] = a4;
return result;
}

canonical_decompiled_code:
double *__fastcall func13(double a1, double a2, double a3, double a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, __int128 a11, __int64 a12)
{
double *result; // rax
__m128i v13; // xmm4
__int64 v14; // rdx
double v15; // [rsp+0h] [rbp-68h]
double v16; // [rsp+8h] [rbp-60h]
double v17; // [rsp+10h] [rbp-58h]
double v18; // [rsp+18h] [rbp-50h]
double v19; // [rsp+20h] [rbp-48h]
double v20; // [rsp+28h] [rbp-40h]
double cosx; // [rsp+40h] [rbp-28h] BYREF
double sinx[4]; // [rsp+48h] [rbp-20h] BYREF

sincos(a3, sinx, &cosx);
v20 = cosx;
v19 = sinx[0];
sincos(a2, sinx, &cosx);
v18 = cosx;
v17 = sinx[0];
sincos(a1, sinx, &cosx);
v16 = cosx;
v15 = sinx[0];
result = (double *)malloc(0x68uLL);
v13 = _mm_loadu_si128((const __m128i *)&a11);
result[3] = a1;
*(__m128i *)result = v13;
v14 = a12;
result[6] = a2;
*((_QWORD *)result + 2) = v14;
result[4] = v15;
result[5] = v16;
result[7] = v17;
result[8] = v18;
result[9] = a3;
result[10] = v19;
result[11] = v20;
result[12] = a4;
return result;
}

original_code:
Camera *
new_camera(const Point3d camera_position,
           const Float al_x,
           const Float al_y,
           const Float al_z,
           const Float proj_plane_dist) {
    Camera * cam = malloc(sizeof(Camera));
    cam->camera_position = camera_position;
    cam->al_x = al_x;
    cam->sin_al_x = sin(al_x);
    cam->cos_al_x = cos(al_x);
    cam->al_y = al_y;
    cam->sin_al_y = sin(al_y);
    cam->cos_al_y = cos(al_y);
    cam->al_z = al_z;
    cam->sin_al_z = sin(al_z);
    cam->cos_al_z = cos(al_z);
    cam->proj_plane_dist = proj_plane_dist;
    return cam;
}

canonical_original_code:
struct Camera *new_camera(struct Point3d camera_position, double al_x, double al_y, double al_z, double proj_plane_dist) {
    struct Camera *cam = malloc(sizeof(Camera));
    cam->camera_position = camera_position;
    cam->al_x = al_x;
    cam->sin_al_x = sin(al_x);
    cam->cos_al_x = cos(al_x);
    cam->al_y = al_y;
    cam->sin_al_y = sin(al_y);
    cam->cos_al_y = cos(al_y);
    cam->al_z = al_z;
    cam->sin_al_z = sin(al_z);
    cam->cos_al_z = cos(al_z);
    cam->proj_plane_dist = proj_plane_dist;
    return cam;
}

variable_types: struct Camera { struct Point3d { double x; double y; double z; } camera_position; double al_x; double sin_al_x; double cos_al_x; double al_y; double sin_al_y; double cos_al_y; double al_z; double sin_al_z; double cos_al_z; double proj_plane_dist; } *

user_defined_types: struct Camera { struct Point3d camera_position; double al_x; double sin_al_x; double cos_al_x; double al_y; double sin_al_y; double cos_al_y; double al_z; double sin_al_z; double cos_al_z; double proj_plane_dist; }


decompiled_code:
// attributes: thunk
void release_camera(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func14(void *ptr)
{
free(ptr);
}

original_code:
void
release_camera(Camera * const cam) {
    free(cam);
}

canonical_original_code:
void release_camera(struct Camera *cam) {
    free(cam);
}


decompiled_code:
void __fastcall rotate_camera(double *a1, double a2, double a3, double a4)
{
__int64 v4; // xmm3_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // [rsp+0h] [rbp-30h]
double v8; // [rsp+0h] [rbp-30h]
double v9; // [rsp+0h] [rbp-30h]
double cosx; // [rsp+18h] [rbp-18h] BYREF
double sinx[2]; // [rsp+20h] [rbp-10h] BYREF

v4 = LC0;
if ( COERCE_DOUBLE(*(_QWORD *)&a2 & LC0) > 0.00001 )
{
v7 = a2 + a1[3];
sincos(v7, sinx, &cosx);
v4 = LC0;
a1[3] = v7;
a1[4] = sinx[0];
a1[5] = cosx;
}
if ( COERCE_DOUBLE(*(_QWORD *)&a3 & v4) > 0.00001 )
{
v8 = a3 + a1[6];
sincos(v8, sinx, &cosx);
v4 = LC0;
a1[7] = sinx[0];
v5 = cosx;
a1[6] = v8;
a1[8] = v5;
}
if ( COERCE_DOUBLE(v4 & *(_QWORD *)&a4) > 0.00001 )
{
v9 = a4 + a1[9];
sincos(v9, sinx, &cosx);
a1[10] = sinx[0];
v6 = cosx;
a1[9] = v9;
a1[11] = v6;
}
}

canonical_decompiled_code:
void __fastcall func15(double *a1, double a2, double a3, double a4)
{
__int64 v4; // xmm3_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // [rsp+0h] [rbp-30h]
double v8; // [rsp+0h] [rbp-30h]
double v9; // [rsp+0h] [rbp-30h]
double cosx; // [rsp+18h] [rbp-18h] BYREF
double sinx[2]; // [rsp+20h] [rbp-10h] BYREF

v4 = LC0;
if ( COERCE_DOUBLE(*(_QWORD *)&a2 & LC0) > 0.00001 )
{
v7 = a2 + a1[3];
sincos(v7, sinx, &cosx);
v4 = LC0;
a1[3] = v7;
a1[4] = sinx[0];
a1[5] = cosx;
}
if ( COERCE_DOUBLE(*(_QWORD *)&a3 & v4) > 0.00001 )
{
v8 = a3 + a1[6];
sincos(v8, sinx, &cosx);
v4 = LC0;
a1[7] = sinx[0];
v5 = cosx;
a1[6] = v8;
a1[8] = v5;
}
if ( COERCE_DOUBLE(v4 & *(_QWORD *)&a4) > 0.00001 )
{
v9 = a4 + a1[9];
sincos(v9, sinx, &cosx);
a1[10] = sinx[0];
v6 = cosx;
a1[9] = v9;
a1[11] = v6;
}
}

original_code:
void
rotate_camera(Camera * const cam,
              const Float al_x,
              const Float al_y,
              const Float al_z) {
    if(fabs(al_x) > 1e-5) {
        cam->al_x += al_x;
        cam->sin_al_x = sin(cam->al_x);
        cam->cos_al_x = cos(cam->al_x);
    }
    if(fabs(al_y) > 1e-5) {
        cam->al_y += al_y;
        cam->sin_al_y = sin(cam->al_y);
        cam->cos_al_y = cos(cam->al_y);
    }
    if(fabs(al_z) > 1e-5) {
        cam->al_z += al_z;
        cam->sin_al_z = sin(cam->al_z);
        cam->cos_al_z = cos(cam->al_z);
    }
}

canonical_original_code:
void rotate_camera(struct Camera *cam, double al_x, double al_y, double al_z) {
    if(fabs(al_x) > 1e-5) {
        cam->al_x += al_x;
        cam->sin_al_x = sin(cam->al_x);
        cam->cos_al_x = cos(cam->al_x);
    }
    if(fabs(al_y) > 1e-5) {
        cam->al_y += al_y;
        cam->sin_al_y = sin(cam->al_y);
        cam->cos_al_y = cos(cam->al_y);
    }
    if(fabs(al_z) > 1e-5) {
        cam->al_z += al_z;
        cam->sin_al_z = sin(cam->al_z);
        cam->cos_al_z = cos(cam->al_z);
    }
}


decompiled_code:
double __fastcall exponential_fog_density(_QWORD *a1, double a2)
{
return 1.0 - exp(COERCE_DOUBLE(*a1 ^ LC0) * a2);
}

canonical_decompiled_code:
double __fastcall func0(_QWORD *a1, double a2)
{
return 1.0 - exp(COERCE_DOUBLE(*a1 ^ LC0) * a2);
}

original_code:
static inline Float
exponential_fog_density(const Float distance,
                        const void * fog_data) {
    Float * k = (Float *) fog_data;
    return 1 - exp(- (*k) * distance);
}

canonical_original_code:
static inline double exponential_fog_density(double distance, void *fog_data) {
    double *k = (Float *) fog_data;
    return 1 - exp(- (*k) * distance);
}

variable_types: distance double

variable_types:
k
double *

return_type: double


decompiled_code:
void __fastcall set_no_fog(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)(a1 + 56);
if ( v2 )
free(v2);
*(_QWORD *)(a1 + 48) = 0LL;
}

original_code:
void
set_no_fog(Scene * const scene) {
    if(scene->fog_parameters) {
        free(scene->fog_parameters);
    }
    scene->fog_density = ((void *)0);
}

canonical_original_code:
void set_no_fog(struct Scene *scene) {
    if(scene->fog_parameters) {
        free(scene->fog_parameters);
    }
    scene->fog_density = ((void *)0);
}


decompiled_code:
void __fastcall set_exponential_fog(__int64 a1, double a2)
{
double *v3; // rax
void *v4; // rdi
double *v5; // rbp

*(_QWORD *)(a1 + 48) = exponential_fog_density;
v3 = (double *)malloc(8uLL);
v4 = *(void **)(a1 + 56);
v5 = v3;
*v3 = a2;
if ( v4 )
free(v4);
*(_QWORD *)(a1 + 56) = v5;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, double a2)
{
double *v3; // rax
void *v4; // rdi
double *v5; // rbp

*(_QWORD *)(a1 + 48) = exponential_fog_density;
v3 = (double *)malloc(8uLL);
v4 = *(void **)(a1 + 56);
v5 = v3;
*v3 = a2;
if ( v4 )
free(v4);
*(_QWORD *)(a1 + 56) = v5;
}

original_code:
void
set_exponential_fog(Scene * const scene,
                    const Float k) {
    scene->fog_density = exponential_fog_density;
    Float * k_p = malloc(sizeof(Float));
    *k_p = k;
    if(scene->fog_parameters) {
        free(scene->fog_parameters);
    }
    scene->fog_parameters = k_p;
}

canonical_original_code:
void set_exponential_fog(struct Scene *scene, double k) {
    scene->fog_density = exponential_fog_density;
    double *k_p = malloc(sizeof(Float));
    *k_p = k;
    if(scene->fog_parameters) {
        free(scene->fog_parameters);
    }
    scene->fog_parameters = k_p;
}

variable_types: k double


decompiled_code:
double __fastcall dot_product(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

original_code:
static inline Float
dot_product(const Vector3d v1,
            const Vector3d v2) {
    return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}

canonical_original_code:
static inline double dot_product(struct Vector3d v1, struct Vector3d v2) {
    return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}

variable_types: struct Vector3d { double x; double y; double z; }


decompiled_code:
double __fastcall sqr_module_vector(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
return dot_product(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a9, a10, a11);
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
return func2(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a9, a10, a11);
}

original_code:
static inline Float
sqr_module_vector(const Vector3d v) {
    return dot_product(v, v);
}

canonical_original_code:
static inline double sqr_module_vector(struct Vector3d v) {
    return dot_product(v, v);
}


decompiled_code:
unsigned __int64 __fastcall get_sphere_color(__int64 a1)
{
return ((unsigned __int64)*(unsigned __int8 *)(a1 + 34) << 16) | *(unsigned __int16 *)(a1 + 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1)
{
return ((unsigned __int64)*(unsigned __int8 *)(a1 + 34) << 16) | *(unsigned __int16 *)(a1 + 32);
}

original_code:
static Color
get_sphere_color(const void * data,
                 const Point3d intersection_point) {
 const Sphere * sphere = data;
 return sphere->color;
}

canonical_original_code:
static struct Color get_sphere_color(void *data, struct Point3d intersection_point) {
 struct Sphere *sphere = data;
 return sphere->color;
}

variable_types:
data
void *

variable_types: struct Sphere { struct Point3d { double x; double y; double z; } center; double radius; struct Color { unsigned char r; unsigned char g; unsigned char b; } color; struct Material { double Ka; double Kd; double Ks; double Kr; double Kt; double p; } material; } *

user_defined_types: struct Sphere { struct Point3d center; double radius; struct Color color; struct Material material; }


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

v17 = sqr_module_vector(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
if ( v17 < 0.0 )
sqrt(v17);
}

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

v17 = func3(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
if ( v17 < 0.0 )
sqrt(v17);
}

original_code:
static inline Float
module_vector(const Vector3d v) {
    return sqrt(sqr_module_vector(v));
}

canonical_original_code:
static inline double module_vector(struct Vector3d v) {
    return sqrt(sqr_module_vector(v));
}


decompiled_code:
void __fastcall normalize_vector(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
module_vector(a2, a3, a4, a5, a6, a7, a8, a9, *a1, a1[1], a1[2]);
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
}

canonical_decompiled_code:
void __fastcall func8(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
func7(a2, a3, a4, a5, a6, a7, a8, a9, *a1, a1[1], a1[2]);
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
}

original_code:
static inline void
normalize_vector(Vector3d * const v) {
    const Float module = module_vector(*v);
    v->x = v->x / module;
    v->y = v->y / module;
    v->z = v->z / module;
}

canonical_original_code:
static inline void normalize_vector(struct Vector3d *v) {
    double module = module_vector(*v);
    v->x = v->x / module;
    v->y = v->y / module;
    v->z = v->z / module;
}

variable_types: struct Vector3d { double x; double y; double z; } *

variable_types: module double


original_code:
static Boolean
intersect_sphere(const void * data,
                 const Point3d vector_start,
                 const Vector3d vector,
                 Point3d * const intersection_point) {
    const Sphere * sphere = data;
    const Point3d center = sphere->center;
    const Float r = sphere->radius;
    const Float a = vector.x * vector.x
                    + vector.y * vector.y
                    + vector.z * vector.z;
    const Float b = 2 * (vector.x * (vector_start.x - center.x)
                         + vector.y * (vector_start.y - center.y)
                         + vector.z * (vector_start.z - center.z));
    const Float c = center.x * center.x
                    + center.y * center.y
                    + center.z * center.z
                    + vector_start.x * vector_start.x
                    + vector_start.y * vector_start.y
                    + vector_start.z * vector_start.z
                    - 2 * (vector_start.x * center.x
                           + vector_start.y * center.y
                           + vector_start.z * center.z)
                    - r * r;
    const Float D = b * b - 4 * a * c;
    if(D < 0)
        return 0;
    const Float sqrt_D = sqrt(D);
    const Float a_2 = 2 * a;
    const Float t1 = (-b + sqrt_D) / a_2;
    const Float t2 = (-b - sqrt_D) / a_2;
    const Float min_t = (t1 < t2) ? t1 : t2;
    const Float max_t = (t1 > t2) ? t1 : t2;
    const Float t = (min_t > 1e-5) ? min_t : max_t;
    if(t < 1e-5)
        return 0;
    *intersection_point = point3d(vector_start.x + t * vector.x,
                                  vector_start.y + t * vector.y,
                                  vector_start.z + t * vector.z);
    return 1;
}

canonical_original_code:
static int intersect_sphere(void *data, struct Point3d vector_start, struct Vector3d vector, struct Point3d *intersection_point) {
    struct Sphere *sphere = data;
    struct Point3d center = sphere->center;
    double r = sphere->radius;
    double a = vector.x * vector.x
                    + vector.y * vector.y
                    + vector.z * vector.z;
    double b = 2 * (vector.x * (vector_start.x - center.x)
                         + vector.y * (vector_start.y - center.y)
                         + vector.z * (vector_start.z - center.z));
    double c = center.x * center.x
                    + center.y * center.y
                    + center.z * center.z
                    + vector_start.x * vector_start.x
                    + vector_start.y * vector_start.y
                    + vector_start.z * vector_start.z
                    - 2 * (vector_start.x * center.x
                           + vector_start.y * center.y
                           + vector_start.z * center.z)
                    - r * r;
    double D = b * b - 4 * a * c;
    if(D < 0)
        return 0;
    double sqrt_D = sqrt(D);
    double a_2 = 2 * a;
    double t1 = (-b + sqrt_D) / a_2;
    double t2 = (-b - sqrt_D) / a_2;
    double min_t = (t1 < t2) ? t1 : t2;
    double max_t = (t1 > t2) ? t1 : t2;
    double t = (min_t > 1e-5) ? min_t : max_t;
    if(t < 1e-5)
        return 0;
    *intersection_point = point3d(vector_start.x + t * vector.x,
                                  vector_start.y + t * vector.y,
                                  vector_start.z + t * vector.z);
    return 1;
}

variable_types: struct Point3d { double x; double y; double z; }

variable_types: r double

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: D double

variable_types: t double


decompiled_code:
// attributes: thunk
void release_sphere_data(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func10(void *ptr)
{
free(ptr);
}

original_code:
void
release_sphere_data(void * data) {
 Sphere * sphere = data;
 free(sphere);
}

canonical_original_code:
void release_sphere_data(void *data) {
 struct Sphere *sphere = data;
 free(sphere);
}


rgb

decompiled_code:
unsigned __int64 __fastcall rgb(char a1, char a2, unsigned __int8 a3)
{
unsigned __int16 v4; // [rsp+1h] [rbp-3h]

LOBYTE(v4) = a1;
HIBYTE(v4) = a2;
return ((unsigned __int64)a3 << 16) | v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(char a1, char a2, unsigned __int8 a3)
{
unsigned __int16 v4; // [rsp+1h] [rbp-3h]

LOBYTE(v4) = a1;
HIBYTE(v4) = a2;
return ((unsigned __int64)a3 << 16) | v4;
}

original_code:
static inline Color
rgb(Byte r,
    Byte g,
    Byte b) {
        Color c;
        c.r = r;
        c.g = g;
        c.b = b;
        return c;
}

canonical_original_code:
static inline struct Color rgb(unsigned char r, unsigned char g, unsigned char b) {
        struct Color c;
        c.r = r;
        c.g = g;
        c.b = b;
        return c;
}

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types: struct Color { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
unsigned __int64 __fastcall add_colors(int a1, int a2)
{
int v2; // eax
int v3; // edx
char v4; // di
int v5; // esi

v2 = (unsigned __int8)a2 + (unsigned __int8)a1;
v3 = BYTE2(a1) + BYTE2(a2);
LOBYTE(a1) = -1;
v5 = BYTE1(a1) + BYTE1(a2);
if ( v3 > 255 )
LOBYTE(v3) = -1;
if ( v5 > 255 )
LOBYTE(v5) = -1;
if ( v2 <= 255 )
v4 = v2;
return rgb(v4, v5, v3);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(int a1, int a2)
{
int v2; // eax
int v3; // edx
char v4; // di
int v5; // esi

v2 = (unsigned __int8)a2 + (unsigned __int8)a1;
v3 = BYTE2(a1) + BYTE2(a2);
LOBYTE(a1) = -1;
v5 = BYTE1(a1) + BYTE1(a2);
if ( v3 > 255 )
LOBYTE(v3) = -1;
if ( v5 > 255 )
LOBYTE(v5) = -1;
if ( v2 <= 255 )
v4 = v2;
return func0(v4, v5, v3);
}

original_code:
static inline Color
add_colors(Color c1,
           Color c2) {
 int r = (int) c1.r + c2.r;
 int g = (int) c1.g + c2.g;
 int b = (int) c1.b + c2.b;
 r = (r < 255) ? r : 255;
 g = (g < 255) ? g : 255;
 b = (b < 255) ? b : 255;
 return rgb((Byte) r, (Byte) g, (Byte) b);
}

canonical_original_code:
static inline struct Color add_colors(struct Color c1, struct Color c2) {
 int r = (int) c1.r + c2.r;
 int g = (int) c1.g + c2.g;
 int b = (int) c1.b + c2.b;
 r = (r < 255) ? r : 255;
 g = (g < 255) ? g : 255;
 b = (b < 255) ? b : 255;
 return rgb((unsigned char) r, (unsigned char) g, (unsigned char) b);
}

variable_types: r int

variable_types: g int

variable_types: b int

return_type: struct Color { unsigned char r; unsigned char g; unsigned char b; }


original_code:
void
render_scene(const Scene * const scene,
             const Camera * const camera,
             Canvas * canvas,
             const int num_threads) {
    const int w = canvas->w;
    const int h = canvas->h;
    const Float dx = w / 2.0;
    const Float dy = h / 2.0;
    const Float focus = camera->proj_plane_dist;
    omp_set_num_threads((num_threads < 2) ? 1 : num_threads);
    int i;
    int j;

#pragma omp parallel private(i, j)

#pragma omp for collapse(2) schedule(dynamic, 10)
    for(i = 0; i < w; i++) {
        for(j = 0; j < h; j++) {
            const Float x = i - dx;
            const Float y = j - dy;
            const Vector3d ray = vector3df(x, y, focus);
            const Color col = trace(scene, camera, ray);
            set_pixel(i, j, col, canvas);
        }
    }
    const int antialiasing = 1;
    if(antialiasing) {
        Canvas * edges = detect_edges_canvas(canvas, num_threads);

#pragma omp parallel private(i, j)

#pragma omp for collapse(2) schedule(dynamic, 10)
        for(i = 1; i < w - 1; i++) {
            for(j = 1; j < h - 1; j++) {
                Byte gray = get_pixel(i, j, edges).r;
                if(gray > 10) {
                    const Float x = i - dx;
                    const Float y = j - dy;
                    Color c = get_pixel(i, j, canvas);
                    const Float weight = 1.0 / 4;
                    c = mul_color(c, weight);
                    c = add_colors(c, mul_color(trace(scene, camera, vector3df(x + 0.5, y, focus)), weight));
                    c = add_colors(c, mul_color(trace(scene, camera, vector3df(x, y + 0.5, focus)), weight));
                    c = add_colors(c, mul_color(trace(scene, camera, vector3df(x + 0.5, y + 0.5, focus)), weight));
                    set_pixel(i, j, c, canvas);
                }
            }
        }
        release_canvas(edges);
    }
}

canonical_original_code:
void render_scene(struct Scene *scene, struct Camera *camera, struct Canvas *canvas, int num_threads) {
    int w = canvas->w;
    int h = canvas->h;
    double dx = w / 2.0;
    double dy = h / 2.0;
    double focus = camera->proj_plane_dist;
    omp_set_num_threads((num_threads < 2) ? 1 : num_threads);
    int i;
    int j;

#pragma omp parallel private(i, j)

#pragma omp for collapse(2) schedule(dynamic, 10)
    for(i = 0; i < w; i++) {
        for(j = 0; j < h; j++) {
            double x = i - dx;
            double y = j - dy;
            struct Vector3d ray = vector3df(x, y, focus);
            struct Color col = trace(scene, camera, ray);
            set_pixel(i, j, col, canvas);
        }
    }
    int antialiasing = 1;
    if(antialiasing) {
        struct Canvas *edges = detect_edges_canvas(canvas, num_threads);

#pragma omp parallel private(i, j)

#pragma omp for collapse(2) schedule(dynamic, 10)
        for(i = 1; i < w - 1; i++) {
            for(j = 1; j < h - 1; j++) {
                unsigned char gray = get_pixel(i, j, edges).r;
                if(gray > 10) {
                    double x = i - dx;
                    double y = j - dy;
                    struct Color c = get_pixel(i, j, canvas);
                    double weight = 1.0 / 4;
                    c = mul_color(c, weight);
                    c = add_colors(c, mul_color(trace(scene, camera, vector3df(x + 0.5, y, focus)), weight));
                    c = add_colors(c, mul_color(trace(scene, camera, vector3df(x, y + 0.5, focus)), weight));
                    c = add_colors(c, mul_color(trace(scene, camera, vector3df(x + 0.5, y + 0.5, focus)), weight));
                    set_pixel(i, j, c, canvas);
                }
            }
        }
        release_canvas(edges);
    }
}

variable_types: struct Scene { struct Object3d { void *data; int (*intersect)(void *data, struct Point3d { double x; double y; double z; } vector_start, struct Vector3d { double x; double y; double z; } vector, struct Point3d *intersection_point); struct Color { unsigned char r; unsigned char g; unsigned char b; } (*get_color)(void *data, struct Point3d intersection_point); struct Vector3d (*get_normal_vector)(void *data, struct Point3d intersection_point); struct Material { double Ka; double Kd; double Ks; double Kr; double Kt; double p; } (*get_material)(void *data, struct Point3d intersection_point); struct Point3d (*get_min_boundary_point)(void *data); struct Point3d (*get_max_boundary_point)(void *data); void (*release_data)(void *data); } **objects; int objects_count; int last_object_index; struct KDTree { struct KDNode { enum Plane { XY=0, XZ=1, YZ=2, NONE=3 } plane; union Coord { double x; double y; double z; } coord; struct Object3d **objects; int objects_count; struct KDNode *l; struct KDNode *r; } *root; struct Voxel { double x_min; double y_min; double z_min; double x_max; double y_max; double z_max; } bounding_box; } *kd_tree; struct LightSource3d { struct Point3d location_world; struct Point3d location; struct Color color; } **light_sources; int light_sources_count; int last_light_source_index; struct Color background_color; double (*fog_density)(double distance, void *fog_parameters); void *fog_parameters; } *

variable_types: struct Camera { struct Point3d camera_position; double al_x; double sin_al_x; double cos_al_x; double al_y; double sin_al_y; double cos_al_y; double al_z; double sin_al_z; double cos_al_z; double proj_plane_dist; } *

variable_types: struct Canvas { int w; int h; struct Color *data; } *

variable_types: w int

variable_types: h int

variable_types: dx double

variable_types: dy double

variable_types: focus double

variable_types: i int

variable_types: j int

variable_types: x double

variable_types: y double

variable_types: antialiasing int

variable_types: struct Canvas { int w; int h; struct Color { unsigned char r; unsigned char g; unsigned char b; } *data; } *

variable_types:
gray
unsigned char

variable_types: weight double


isOption

decompiled_code:
_BOOL8 __fastcall isOption(_BYTE *a1)
{
return *a1 == 45;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_BYTE *a1)
{
return *a1 == 45;
}

original_code:
int isOption(const char* arg){
 if(*arg=='-')
  return 1;
 else
  return 0;
}

canonical_original_code:
int isOption(char *arg){
 if(*arg=='-')
  return 1;
 else
  return 0;
}

variable_types:
arg
char *


getParam

decompiled_code:
void *__fastcall getParam(char *a1)
{
void *v1; // r8
void *result; // rax
size_t v3; // rax
int v4; // ebp
void *v5; // rax

if ( isOption(a1) && (v3 = strlen(a1), v4 = v3, v5 = malloc(v3 - 1), v1 = v5, v4 > 1) )
result = memcpy(v5, a1 + 1, (unsigned int)(v4 - 2) + 1LL);
else
result = v1;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(char *a1)
{
void *v1; // r8
void *result; // rax
size_t v3; // rax
int v4; // ebp
void *v5; // rax

if ( func7(a1) && (v3 = strlen(a1), v4 = v3, v5 = malloc(v3 - 1), v1 = v5, v4 > 1) )
result = memcpy(v5, a1 + 1, (unsigned int)(v4 - 2) + 1LL);
else
result = v1;
return result;
}

original_code:
char*getParam(const char* param){
 if(isOption(param)==0){
  return "NO_PARAM_INPUT";
 }
 int paramLen=strlen(param);
 char* res=(char*)malloc(sizeof(char)*(strlen(param)-1));
 for(int i=1;i<paramLen;i++)
  *(res+(i-1))=*(param+i);
 return res;
}

canonical_original_code:
char *getParam(char *param){
 if(isOption(param)==0){
  return "NO_PARAM_INPUT";
 }
 int paramLen = strlen(param);
 char *res = (char*)malloc(sizeof(char)*(strlen(param)-1));
 for(int i = 1;i<paramLen;i++)
  *(res+(i-1))=*(param+i);
 return res;
}

variable_types:
param
char *

variable_types: paramLen int

variable_types:
res
char *

return_type: char *


wiringPiSetup

decompiled_code:
__int64 wiringPiSetup()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code: int wiringPiSetup(void) {return 0;}

canonical_original_code: int wiringPiSetup() {return 0;}


pinMode

decompiled_code:
void pinMode()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code: void pinMode (int a, int b) {a=b;}

canonical_original_code: void pinMode(int a, int b) {a=b;}

variable_types: a int

variable_types: b int


delayMicroseconds

decompiled_code:
void delayMicroseconds()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void delayMicroseconds(unsigned int a) {a=a;}

variable_types:
a
unsigned int


digitalWrite

decompiled_code:
void digitalWrite()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code: void digitalWrite(int a, int b) {a=b;}

canonical_original_code: void digitalWrite(int a, int b) {a=b;}


digitalRead

decompiled_code:
__int64 __fastcall digitalRead(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return a1;
}

original_code: int digitalRead(int a) {return a;}

canonical_original_code: int digitalRead(int a) {return a;}


decodeByte

decompiled_code:
__int64 __fastcall decodeByte(__int16 a1)
{
int v1; // ecx
int v2; // eax
unsigned int v3; // er8
bool v4; // dl
int v5; // edx

v1 = 7;
v2 = 0x8000;
v3 = 0;
do
{
v4 = (unsigned __int16)(a1 & v2) == v2;
v2 >>= 2;
v5 = v4 << v1--;
v3 |= v5;
}
while ( v1 != -1 );
return v3;
}

original_code:
unsigned char decodeByte(unsigned short int word)
{
    unsigned char decodedChar=0;
    int j;
    int shift = 7;
    for(j=0x8000;j>0; j>>=2) {
     decodedChar |= (((word & j) == j) ? 0x01 : 0x00) << shift;
  shift -=1;
    }
    return decodedChar;
}

canonical_original_code:
unsigned char decodeByte(unsigned short word)
{
    unsigned char decodedChar = 0;
    int j;
    int shift = 7;
    for(j=0x8000;j>0; j>>=2) {
     decodedChar |= (((word & j) == j) ? 0x01 : 0x00) << shift;
  shift -=1;
    }
    return decodedChar;
}

variable_types:
word
unsigned short

variable_types:
decodedChar
unsigned char

variable_types: shift int

return_type: unsigned char


homeEasyDecode

decompiled_code:
__int64 __fastcall homeEasyDecode(__int64 *a1)
{
unsigned __int64 v1; // r11
unsigned __int64 v2; // rsi
__int64 v3; // rbx
unsigned __int64 v4; // rdx
char v5; // al
unsigned __int8 v6; // al
__int64 v7; // r9
__int64 v8; // r9
unsigned __int64 v9; // r10
__int16 v11; // [rsp+0h] [rbp-Ah]

v1 = a1[1];
if ( !((v1 + 1) >> 1) )
return 0LL;
LODWORD(v2) = 0;
v3 = *a1;
do
{
v4 = (unsigned int)(2 * v2 + 1);
v5 = 0;
if ( v4 < v1 )
v5 = *(_BYTE *)(v3 + v4);
LOBYTE(v11) = v5;
HIBYTE(v11) = *(_BYTE *)(v3 + (unsigned int)(2 * v2));
v6 = decodeByte(v11);
v8 = (v6 << (-8 * v2 + 24)) + v7;
v2 = (unsigned int)(v2 + 1);
}
while ( v2 < v9 );
return v8;
}

original_code:
unsigned long int homeEasyDecode(BYTE_BUFFER *buffer)
{
    unsigned long int result = 0;
    unsigned short int word;
    unsigned char *byte = (unsigned char*)&word;
    unsigned int i;
    for(i=0; i<(buffer->size+1)/2; i++) {
        byte[1] = buffer->data[2*i];
        byte[0] = (2*i+1 < buffer->size ? buffer->data[2*i+1]:0);
        result += (decodeByte(word)) << ((3 - i)* 8);
    }
    return result;
}

canonical_original_code:
unsigned long homeEasyDecode(struct BYTE_BUFFER *buffer)
{
    unsigned long result = 0;
    unsigned short word;
    unsigned char *byte = (unsigned char*)&word;
    unsigned int i;
    for(i=0; i<(buffer->size+1)/2; i++) {
        byte[1] = buffer->data[2*i];
        byte[0] = (2*i+1 < buffer->size ? buffer->data[2*i+1]:0);
        result += (decodeByte(word)) << ((3 - i)* 8);
    }
    return result;
}

variable_types: struct BYTE_BUFFER { char *data; unsigned long size; } *

variable_types:
result
unsigned long

variable_types:
byte
unsigned char *

variable_types:
i
unsigned int

return_type: unsigned long


encodeByte

decompiled_code:
__int64 __fastcall encodeByte(char a1)
{
int v1; // ecx
int v2; // edx
unsigned int v3; // er8
bool v4; // al
int v5; // eax

v1 = 14;
v2 = 128;
v3 = 0;
do
{
v4 = (unsigned __int8)(v2 & a1) == v2;
v2 >>= 1;
v5 = (v4 + 1) << v1;
v1 -= 2;
v3 |= v5;
}
while ( v1 != -2 );
return v3;
}

original_code:
unsigned short int encodeByte(unsigned char byte)
{
    unsigned short int encodedChar=0;
    int j;
    int shift = 14;
    for(j=0x80;j>0; j>>=1) {
       encodedChar |= (((byte & j) == j) ? 0x02 : 0x01) << shift;
       shift -=2;
    }
    return encodedChar;
}

canonical_original_code:
unsigned short encodeByte(unsigned char byte)
{
    unsigned short encodedChar = 0;
    int j;
    int shift = 14;
    for(j=0x80;j>0; j>>=1) {
       encodedChar |= (((byte & j) == j) ? 0x02 : 0x01) << shift;
       shift -=2;
    }
    return encodedChar;
}

variable_types:
byte
unsigned char

variable_types:
encodedChar
unsigned short

variable_types: j int

return_type: unsigned short


homeEasyEncode

decompiled_code:
__int64 __fastcall homeEasyEncode(unsigned __int64 a1)
{
int v1; // ebx
__int64 v2; // rdx
char v3; // cl
unsigned __int16 v4; // ax
__int64 v6[5]; // [rsp+0h] [rbp-28h] BYREF

v1 = 24;
v6[0] = createByteBuffer();
v6[1] = v2;
do
{
v3 = v1;
v1 -= 8;
v4 = encodeByte(a1 >> v3);
pushWord(v6, v4);
}
while ( v1 != -8 );
return v6[0];
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
int v1; // ebx
__int64 v2; // rdx
char v3; // cl
unsigned __int16 v4; // ax
__int64 v6[5]; // [rsp+0h] [rbp-28h] BYREF

v1 = 24;
v6[0] = createByteBuffer();
v6[1] = v2;
do
{
v3 = v1;
v1 -= 8;
v4 = func7(a1 >> v3);
pushWord(v6, v4);
}
while ( v1 != -8 );
return v6[0];
}

original_code:
BYTE_BUFFER homeEasyEncode(unsigned long int frame)
{
    BYTE_BUFFER result = createByteBuffer();
    unsigned int i;
    for(i=0; i<4; i++) {
        pushWord(&result, encodeByte((frame >> ((3 - i) * 8)) & 0xff));
    }
    return result;
}

canonical_original_code:
struct BYTE_BUFFER homeEasyEncode(unsigned long frame)
{
    struct BYTE_BUFFER result = createByteBuffer();
    unsigned int i;
    for(i=0; i<4; i++) {
        pushWord(&result, encodeByte((frame >> ((3 - i) * 8)) & 0xff));
    }
    return result;
}

variable_types:
frame
unsigned long

variable_types: struct BYTE_BUFFER { char *data; unsigned long size; }


createHomeEasyCommand

decompiled_code:
__int64 __fastcall createHomeEasyCommand(__int64 a1, char a2, char a3, char a4)
{
__int64 v4; // rdi
__int64 result; // rax

v4 = a1 << 6;
if ( a2 > 90 )
a2 -= 32;
if ( a2 == 71 )
{
result = v4 | 0x30;
if ( !a4 )
result = v4 | 0x20;
}
else
{
if ( a4 )
v4 |= 0x10uLL;
result = v4 | (4 * a2 + 12) & 0xC | (a3 + 3) & 3u;
}
return result;
}

original_code:
unsigned long int createHomeEasyCommand(unsigned long int id, char section, unsigned char nb, unsigned char on)
{
    unsigned long int command = id << 6;
    char formatedSection = (section<='Z' ? section : section + 'A' - 'a');
    command |= (formatedSection == 'G' ? 0x20 : 0);
    command |= (on ? 0x10 : 0);
    command |= ((formatedSection == 'G' ? 0 : formatedSection - 'A') << 2) & 0x0c;
    command |= (formatedSection == 'G' ? 0 : nb-1) & 0x03;;
    return command;
}

canonical_original_code:
unsigned long createHomeEasyCommand(unsigned long id, char section, unsigned char nb, unsigned char on)
{
    unsigned long command = id << 6;
    char formatedSection = (section<='Z' ? section : section + 'A' - 'a');
    command |= (formatedSection == 'G' ? 0x20 : 0);
    command |= (on ? 0x10 : 0);
    command |= ((formatedSection == 'G' ? 0 : formatedSection - 'A') << 2) & 0x0c;
    command |= (formatedSection == 'G' ? 0 : nb-1) & 0x03;;
    return command;
}

variable_types:
id
unsigned long

variable_types: section char

variable_types:
nb
unsigned char

variable_types:
on
unsigned char

variable_types:
command
unsigned long

variable_types: formatedSection char


getHomeEasyId

decompiled_code:
unsigned __int64 __fastcall getHomeEasyId(unsigned __int64 a1)
{
return a1 >> 6;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1)
{
return a1 >> 6;
}

original_code:
unsigned long int getHomeEasyId(unsigned long int frame)
{
    return frame >> 6;
}

canonical_original_code:
unsigned long getHomeEasyId(unsigned long frame)
{
    return frame >> 6;
}


getHomeEasyInfo

decompiled_code:
void __fastcall getHomeEasyInfo(unsigned __int64 a1, unsigned __int64 *a2, _BYTE *a3, _BYTE *a4, _BYTE *a5)
{
if ( a2 )
*a2 = getHomeEasyId(a1);
if ( a3 )
*a3 = (((unsigned __int8)a1 >> 4) ^ 1) & 1;
if ( a4 )
{
if ( (a1 & 0x20) != 0 )
{
*a4 = 71;
if ( !a5 )
return;
LABEL_8:
*a5 = 0;
return;
}
*a4 = (((unsigned __int8)a1 >> 2) & 3) + 65;
if ( a5 )
*a5 = (a1 & 3) + 1;
}
else if ( a5 )
{
if ( (a1 & 0x20) == 0 )
{
*a5 = (a1 & 3) + 1;
return;
}
goto LABEL_8;
}
}

original_code:
void getHomeEasyInfo(unsigned long int frame, unsigned long int* id, unsigned char* onOff, unsigned char* section, unsigned char* number)
{
    unsigned char data = (unsigned char)(frame & 0x0000007f);
    if (id) {
        *id = getHomeEasyId(frame);
    }
    if (onOff) {
        *onOff = ((data & 0x10) == 0);
    }
    if (section) {
        if ((data & 0x20) == 0x20) {
            *section = 'G';
        } else {
            *section = ((data & 0x0f) >> 2) + 'A';
        }
    }
    if (number) {
        if ((data & 0x20) != 0x20) {
            *number = 1 + (data & 0x03);
        } else {
            *number=0;
        }
    }
}

canonical_original_code:
void getHomeEasyInfo(unsigned long frame, unsigned long *id, unsigned char *onOff, unsigned char *section, unsigned char *number)
{
    unsigned char data = (unsigned char)(frame & 0x0000007f);
    if (id) {
        *id = getHomeEasyId(frame);
    }
    if (onOff) {
        *onOff = ((data & 0x10) == 0);
    }
    if (section) {
        if ((data & 0x20) == 0x20) {
            *section = 'G';
        } else {
            *section = ((data & 0x0f) >> 2) + 'A';
        }
    }
    if (number) {
        if ((data & 0x20) != 0x20) {
            *number = 1 + (data & 0x03);
        } else {
            *number=0;
        }
    }
}

variable_types:
id
unsigned long *

variable_types:
onOff
unsigned char *

variable_types:
section
unsigned char *

variable_types:
number
unsigned char *

variable_types:
data
unsigned char


setHomeEasyTransmittorPin

decompiled_code:
void __fastcall setHomeEasyTransmittorPin(char a1)
{
homeEasyPinOut = a1;
}

canonical_decompiled_code:
void __fastcall func12(char a1)
{
homeEasyPinOut = a1;
}

original_code:
void setHomeEasyTransmittorPin(unsigned char pinNumber)
{
    homeEasyPinOut = pinNumber;
}

variable_types:
pinNumber
unsigned char


getHomeEasyTransmittorPin

decompiled_code:
__int64 getHomeEasyTransmittorPin()
{
return (unsigned __int8)homeEasyPinOut;
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned __int8)homeEasyPinOut;
}

original_code:
unsigned char getHomeEasyTransmittorPin()
{
    return homeEasyPinOut;
}


setHomeEasyReceptorPin

decompiled_code:
void __fastcall setHomeEasyReceptorPin(char a1)
{
homeEasyPinIn = a1;
}

canonical_decompiled_code:
void __fastcall func14(char a1)
{
homeEasyPinIn = a1;
}

original_code:
void setHomeEasyReceptorPin(unsigned char pinNumber)
{
    homeEasyPinIn = pinNumber;
}


getHomeEasyReceptorPin

decompiled_code:
__int64 getHomeEasyReceptorPin()
{
return (unsigned __int8)homeEasyPinIn;
}

canonical_decompiled_code:
__int64 func15()
{
return (unsigned __int8)homeEasyPinIn;
}

original_code:
unsigned char getHomeEasyReceptorPin()
{
    return homeEasyPinIn;
}


initIO

decompiled_code:
__int64 initIO()
{
unsigned int v0; // er12

v0 = wiringPiSetup();
if ( v0 == -1 )
printf("GPIO setup failed %d\n", 0xFFFFFFFFLL);
return v0;
}

canonical_decompiled_code:
__int64 func16()
{
unsigned int v0; // er12

v0 = func0();
if ( v0 == -1 )
printf("GPIO setup failed %d\n", 0xFFFFFFFFLL);
return v0;
}

original_code:
int initIO()
{
    int status;
    status = wiringPiSetup();
    if (status != -1) {
        pinMode(homeEasyPinIn, 0);
        pinMode(homeEasyPinOut, 1);
    } else {
        printf("GPIO setup failed %d\n", status);
    }
    return status;
}

variable_types: status int


sendHomeEasyBit

decompiled_code:
void sendHomeEasyBit()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void sendHomeEasyBit(unsigned char bit)
{
    digitalWrite(homeEasyPinOut, 1);
    delayMicroseconds(timings[bit][0]);
    digitalWrite(homeEasyPinOut, 0);
    delayMicroseconds(timings[bit][1]);
    digitalWrite(homeEasyPinOut, 1);
}

variable_types:
bit
unsigned char


sendHomeEasyByte

decompiled_code:
void sendHomeEasyByte()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
void sendHomeEasyByte(unsigned char byte)
{
    int i;
    for(i=0x80;i>0; i>>=1) {
     sendHomeEasyBit((byte & i) == i);
    }
}

variable_types:
byte
unsigned char

variable_types: i int


sendHomeEasyBytes

decompiled_code:
void __fastcall sendHomeEasyBytes(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax

if ( a2 )
{
LODWORD(v2) = 0;
do
v2 = (unsigned int)(v2 + 1);
while ( v2 < a2 );
}
}

canonical_decompiled_code:
void __fastcall func19(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax

if ( a2 )
{
LODWORD(v2) = 0;
do
v2 = (unsigned int)(v2 + 1);
while ( v2 < a2 );
}
}

original_code:
void sendHomeEasyBytes(BYTE_BUFFER buffer)
{
    unsigned int i;
    for(i=0; i<buffer.size; i++) {
        sendHomeEasyByte(buffer.data[i]);
    }
}

canonical_original_code:
void sendHomeEasyBytes(struct BYTE_BUFFER buffer)
{
    unsigned int i;
    for(i=0; i<buffer.size; i++) {
        sendHomeEasyByte(buffer.data[i]);
    }
}

variable_types: struct BYTE_BUFFER { char *data; unsigned long size; }

variable_types:
i
unsigned int


sendFrame

decompiled_code:
__int64 __fastcall sendFrame(__int64 a1, unsigned __int64 a2, int a3)
{
int v4; // ecx

cpuMode(0LL);
if ( a3 )
{
do
sendHomeEasyBytes(a1, a2);
while ( a3 != v4 );
}
return cpuMode(1LL);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, unsigned __int64 a2, int a3)
{
int v4; // ecx

cpuMode(0LL);
if ( a3 )
{
do
func19(a1, a2);
while ( a3 != v4 );
}
return cpuMode(1LL);
}

original_code:
void sendFrame(BYTE_BUFFER frame, unsigned int repeat)
{
    unsigned int i;
    cpuMode(0);
    sendHomeEasyBit(2);
    sendHomeEasyBit(3);
    for(i=0; i<repeat; i++) {
        sendHomeEasyBytes(frame);
        sendHomeEasyBit(4);
    }
    digitalWrite(homeEasyPinOut, 0);
    cpuMode(1);
}

canonical_original_code:
void sendFrame(struct BYTE_BUFFER frame, unsigned int repeat)
{
    unsigned int i;
    cpuMode(0);
    sendHomeEasyBit(2);
    sendHomeEasyBit(3);
    for(i=0; i<repeat; i++) {
        sendHomeEasyBytes(frame);
        sendHomeEasyBit(4);
    }
    digitalWrite(homeEasyPinOut, 0);
    cpuMode(1);
}

variable_types:
repeat
unsigned int

user_defined_types: struct BYTE_BUFFER { char *data; unsigned long size; }


sendHomeEasyCommand

decompiled_code:
__int64 __fastcall sendHomeEasyCommand(__int64 a1, char a2, char a3, char a4, unsigned __int8 a5)
{
__int64 v6; // rax
__int64 v7; // r12
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rbp

v6 = createHomeEasyCommand(a1, a2, a3, a4);
v7 = homeEasyEncode(v6);
v9 = v8;
sendFrame(v7, v8, a5);
return destroyByteBuffer(v7, v9);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, char a2, char a3, char a4, unsigned __int8 a5)
{
__int64 v6; // rax
__int64 v7; // r12
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rbp

v6 = func9(a1, a2, a3, a4);
v7 = func8(v6);
v9 = v8;
func20(v7, v8, a5);
return destroyByteBuffer(v7, v9);
}

original_code:
void sendHomeEasyCommand(unsigned long int id, char section, unsigned char nb, unsigned char on, unsigned char repeat)
{
    unsigned long int command;
    BYTE_BUFFER encoded;
    command = createHomeEasyCommand(id, section, nb, on);
    encoded = homeEasyEncode(command);
    sendFrame(encoded, repeat);
    destroyByteBuffer(encoded);
}

canonical_original_code:
void sendHomeEasyCommand(unsigned long id, char section, unsigned char nb, unsigned char on, unsigned char repeat)
{
    unsigned long command;
    struct BYTE_BUFFER encoded;
    command = createHomeEasyCommand(id, section, nb, on);
    encoded = homeEasyEncode(command);
    sendFrame(encoded, repeat);
    destroyByteBuffer(encoded);
}

variable_types:
id
unsigned long

variable_types: section char

variable_types:
nb
unsigned char

variable_types:
repeat
unsigned char


frameSize

decompiled_code:
__int64 __fastcall frameSize(char *a1, _DWORD *a2, _DWORD *a3)
{
char v4; // dl
__int64 result; // rax
__int64 v6; // rdx

if ( a2 )
*a2 = 0;
v4 = *a1;
result = 0LL;
if ( *a1 == 1 )
{
do
result = (unsigned int)(result + 1);
while ( a1[result] );
if ( !a2 )
goto LABEL_5;
*a2 = result;
v4 = a1[result];
}
if ( !v4 )
{
do
{
LABEL_5:
v6 = (unsigned int)(result + 1);
result = v6;
}
while ( !a1[v6] );
}
if ( a3 )
*a3 = result - *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(char *a1, _DWORD *a2, _DWORD *a3)
{
char v4; // dl
__int64 result; // rax
__int64 v6; // rdx

if ( a2 )
*a2 = 0;
v4 = *a1;
result = 0LL;
if ( *a1 == 1 )
{
do
result = (unsigned int)(result + 1);
while ( a1[result] );
if ( !a2 )
goto LABEL_5;
*a2 = result;
v4 = a1[result];
}
if ( !v4 )
{
do
{
LABEL_5:
v6 = (unsigned int)(result + 1);
result = v6;
}
while ( !a1[v6] );
}
if ( a3 )
*a3 = result - *a2;
return result;
}

original_code:
unsigned int frameSize(unsigned char* data, unsigned int* high, unsigned int* low)
{
    unsigned int i=0;
    if (high) *high = 0;
    if (data[i] == 1) {
        for(i=0; data[i]; i++) ;
        if (high) *high = i;
    }
    for(; !data[i]; i++) ;
    if (low) *low = i - *high;
    return i;
}

canonical_original_code:
unsigned int frameSize(unsigned char *data, unsigned int *high, unsigned int *low)
{
    unsigned int i = 0;
    if (high) *high = 0;
    if (data[i] == 1) {
        for(i=0; data[i]; i++) ;
        if (high) *high = i;
    }
    for(; !data[i]; i++) ;
    if (low) *low = i - *high;
    return i;
}

variable_types:
data
unsigned char *

variable_types:
high
unsigned int *

variable_types:
low
unsigned int *

return_type: unsigned int


testByteBuffer

decompiled_code:
__int64 testByteBuffer()
{
__int64 v0; // rdx
__int16 v2; // [rsp+Dh] [rbp-1Bh] BYREF
char v3; // [rsp+Fh] [rbp-19h]
__int64 v4; // [rsp+10h] [rbp-18h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h]

v2 = -4147;
v3 = 18;
printf("\n=== %s ===\n", "testByteBuffer");
v4 = createByteBuffer();
v5 = v0;
pushByte(&v4, 171LL);
pushBytes(&v4, &v2, 3LL);
pushWord(&v4, 13398LL);
printf("Should: AB CD EF 12 34 56\nGet: ");
printfByteBuffer(v4, v5);
return destroyByteBuffer(v4, v5);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdx
__int16 v2; // [rsp+Dh] [rbp-1Bh] BYREF
char v3; // [rsp+Fh] [rbp-19h]
__int64 v4; // [rsp+10h] [rbp-18h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h]

v2 = -4147;
v3 = 18;
printf("\n=== %s ===\n", "testByteBuffer");
v4 = createByteBuffer();
v5 = v0;
pushByte(&v4, 171LL);
pushBytes(&v4, &v2, 3LL);
pushWord(&v4, 13398LL);
printf("Should: AB CD EF 12 34 56\nGet: ");
printfByteBuffer(v4, v5);
return destroyByteBuffer(v4, v5);
}

original_code:
void testByteBuffer()
{
    BYTE_BUFFER buffer;
    char bytes[] = {0xcd, 0xef, 0x12};
    printf("\n=== %s ===\n", __FUNCTION__);
    buffer = createByteBuffer();
    pushByte(&buffer, 0xab);
    pushBytes(&buffer, bytes, 3);
    pushWord(&buffer, 0x3456);
    printf("Should: AB CD EF 12 34 56\nGet: ");
    printfByteBuffer(buffer);
    destroyByteBuffer(buffer);
}

canonical_original_code:
void testByteBuffer()
{
    struct BYTE_BUFFER buffer;
    char bytes[] = {0xcd, 0xef, 0x12};
    printf("\n=== %s ===\n", __FUNCTION__);
    buffer = createByteBuffer();
    pushByte(&buffer, 0xab);
    pushBytes(&buffer, bytes, 3);
    pushWord(&buffer, 0x3456);
    printf("Should: AB CD EF 12 34 56\nGet: ");
    printfByteBuffer(buffer);
    destroyByteBuffer(buffer);
}

variable_types:
bytes
char []


testPrintBits

decompiled_code:
__int64 testPrintBits()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+10h] [rbp-18h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h]

v3 = 0xF0DEBC9A78563412LL;
printf("\n=== %s ===\n", "testPrintBits");
v0 = createByteBuffer();
v5 = v1;
v4 = v0;
pushBytes(&v4, &v3, 8LL);
printfBitBuffer(v4, v5);
return destroyByteBuffer(v4, v5);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+10h] [rbp-18h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h]

v3 = 0xF0DEBC9A78563412LL;
printf("\n=== %s ===\n", "testPrintBits");
v0 = createByteBuffer();
v5 = v1;
v4 = v0;
pushBytes(&v4, &v3, 8LL);
printfBitBuffer(v4, v5);
return destroyByteBuffer(v4, v5);
}

original_code:
void testPrintBits()
{
    BYTE_BUFFER buffer;
    char bytes[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
    printf("\n=== %s ===\n", __FUNCTION__);
    buffer = createByteBuffer();
    pushBytes(&buffer, bytes, 8);
    printfBitBuffer(buffer);
    destroyByteBuffer(buffer);
}

canonical_original_code:
void testPrintBits()
{
    struct BYTE_BUFFER buffer;
    char bytes[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
    printf("\n=== %s ===\n", __FUNCTION__);
    buffer = createByteBuffer();
    pushBytes(&buffer, bytes, 8);
    printfBitBuffer(buffer);
    destroyByteBuffer(buffer);
}


testGetId

decompiled_code:
int testGetId()
{
__int64 v0; // rax

printf("\n=== %s ===\n", "testGetId");
v0 = getHomeEasyId(673776026LL);
return printf("Should 00A0A406\nGet %08X\n", v0);
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax

printf("\n=== %s ===\n", "testGetId");
v0 = getHomeEasyId(673776026LL);
return printf("Should 00A0A406\nGet %08X\n", v0);
}

original_code:
void testGetId()
{
    unsigned long int id;
    unsigned long int frame = 0x2829019a;
    printf("\n=== %s ===\n", __FUNCTION__);
    id = getHomeEasyId(frame);
    printf("Should 00A0A406\nGet %08X\n", id);
}

canonical_original_code:
void testGetId()
{
    unsigned long id;
    unsigned long frame = 0x2829019a;
    printf("\n=== %s ===\n", __FUNCTION__);
    id = getHomeEasyId(frame);
    printf("Should 00A0A406\nGet %08X\n", id);
}

variable_types:
frame
unsigned long


testEncode

decompiled_code:
int testEncode()
{
unsigned __int16 v0; // ax

printf("\n=== %s ===\n", "testEncode");
v0 = encodeByte(40LL);
return printf("Input: %02X\nShould: 0x5995\nGet: %04X\n", 40LL, v0);
}

canonical_decompiled_code:
int func3()
{
unsigned __int16 v0; // ax

printf("\n=== %s ===\n", "testEncode");
v0 = encodeByte(40LL);
return printf("Input: %02X\nShould: 0x5995\nGet: %04X\n", 40LL, v0);
}

original_code:
void testEncode()
{
    unsigned char srcByte = 0x28;
    unsigned short int encWord;
    printf("\n=== %s ===\n", __FUNCTION__);
    encWord = encodeByte(srcByte);
    printf("Input: %02X\nShould: 0x5995\nGet: %04X\n", srcByte, encWord);
}

canonical_original_code:
void testEncode()
{
    unsigned char srcByte = 0x28;
    unsigned short encWord;
    printf("\n=== %s ===\n", __FUNCTION__);
    encWord = encodeByte(srcByte);
    printf("Input: %02X\nShould: 0x5995\nGet: %04X\n", srcByte, encWord);
}

variable_types:
srcByte
unsigned char

variable_types:
encWord
unsigned short