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

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 87);
}
else if ( (unsigned __int8)(a1 - 65) <= 0x19u )
{
result = (unsigned int)(a1 - 29);
}
else if ( (_BYTE)a1 == 45 )
{
result = 62LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( (_BYTE)a1 == 61 )
result = 63LL;
}
}
return result;
}

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

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 87);
}
else if ( (unsigned __int8)(a1 - 65) <= 0x19u )
{
result = (unsigned int)(a1 - 29);
}
else if ( (_BYTE)a1 == 45 )
{
result = 62LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( (_BYTE)a1 == 61 )
result = 63LL;
}
}
return result;
}

original_code:
static uint8_t base64_fromdigit(char dig)
{
    if (dig >= '0' && dig <= '9')
    {
        return dig - '0';
    }
    if (dig >= 'a' && dig <= 'z')
    {
        return dig - 'a' + 10;
    }
    if (dig >= 'A' && dig <= 'Z')
    {
        return dig - 'A' + 10 + 26;
    }
    if (dig == '-')
    {
        return 0x3E;
    }
    if (dig == '=')
    {
        return 0x3F;
    }
    return (uint8_t)(-1);
}

canonical_original_code:
static unsigned char base64_fromdigit(char dig)
{
    if (dig >= '0' && dig <= '9')
    {
        return dig - '0';
    }
    if (dig >= 'a' && dig <= 'z')
    {
        return dig - 'a' + 10;
    }
    if (dig >= 'A' && dig <= 'Z')
    {
        return dig - 'A' + 10 + 26;
    }
    if (dig == '-')
    {
        return 0x3E;
    }
    if (dig == '=')
    {
        return 0x3F;
    }
    return (unsigned char)(-1);
}

variable_types: dig char


decompiled_code:
unsigned __int64 __fastcall base64_encode(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // r9
char v4; // al
char v5; // al
__int64 v6; // r8
__int64 v7; // r11

v3 = 0LL;
do
{
v4 = read_bits(a1, v3);
v5 = base64_todigit(v4);
*(_BYTE *)(v6 - 1) = v5;
}
while ( v6 != v7 );
return (8 * a2 - 1) / 6uLL + 1;
}

original_code:
size_t base64_encode(const uint8_t *in, size_t insize, char *out)
{
    size_t outsize = (insize*8 - 1) / 6 + 1;
    for (size_t i = 0; i < outsize; i++)
    {
        uint8_t val = read_bits(in, 6 * i);
        out[i] = base64_todigit(val);
    }
    return outsize;
}

canonical_original_code:
unsigned long base64_encode(unsigned char *in, unsigned long insize, char *out)
{
    unsigned long outsize = (insize*8 - 1) / 6 + 1;
    for (unsigned long i = 0; i < outsize; i++)
    {
        unsigned char val = read_bits(in, 6 * i);
        out[i] = base64_todigit(val);
    }
    return outsize;
}

variable_types:
in
unsigned char *

variable_types:
insize
unsigned long

variable_types:
out
char *

variable_types:
outsize
unsigned long

variable_types:
i
unsigned long

variable_types:
val
unsigned char

return_type: unsigned long


decompiled_code:
__int64 __fastcall base64_decode(char *a1, __int64 a2, __int64 a3)
{
char *v4; // rbx
unsigned __int64 i; // rbp
unsigned __int8 v6; // al

if ( !a2 )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
v4 = a1;
for ( i = 0LL; ; i += 6LL )
{
v6 = base64_fromdigit(*v4);
if ( v6 == 0xFF )
break;
++v4;
write_bits(a3, i, v6);
if ( v4 == &a1[a2] )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
}
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2, __int64 a3)
{
char *v4; // rbx
unsigned __int64 i; // rbp
unsigned __int8 v6; // al

if ( !a2 )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
v4 = a1;
for ( i = 0LL; ; i += 6LL )
{
v6 = func3(*v4);
if ( v6 == 0xFF )
break;
++v4;
func1(a3, i, v6);
if ( v4 == &a1[a2] )
return ((unsigned __int64)(6 * a2 - 1) >> 3) + 1;
}
return -1LL;
}

original_code:
size_t base64_decode(const char *in, size_t insize, uint8_t *out)
{
    for (size_t i = 0; i < insize; i++)
    {
        uint8_t val = base64_fromdigit(in[i]);
        if (val == (uint8_t)(-1))
        {
            return (size_t)-1;
        }
        write_bits(out, i*6, val);
    }
    return (6*insize - 1) / 8 + 1;
}

canonical_original_code:
unsigned long base64_decode(char *in, unsigned long insize, unsigned char *out)
{
    for (unsigned long i = 0; i < insize; i++)
    {
        unsigned char val = base64_fromdigit(in[i]);
        if (val == (unsigned char)(-1))
        {
            return (unsigned long)-1;
        }
        write_bits(out, i*6, val);
    }
    return (6*insize - 1) / 8 + 1;
}

variable_types:
in
char *

variable_types:
out
unsigned char *


decompiled_code:
int __fastcall string_compare(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int string_compare(const void *a, const void *b)
{
    const char *a1 = *((const char **)a);
    const char *b1 = *((const char **)b);
    return strcmp(a1, b1);
}

canonical_original_code:
static int string_compare(void *a, void *b)
{
    char *a1 = *((const char **)a);
    char *b1 = *((const char **)b);
    return strcmp(a1, b1);
}

variable_types:
a
void *

variable_types:
b
void *

return_type: int


decompiled_code:
__int64 __fastcall match_suffix(char *s, char *s2)
{
size_t v2; // r12
size_t v3; // rax
unsigned int v4; // er8

v2 = strlen(s2);
v3 = strlen(s);
v4 = 0;
if ( v2 < v3 )
LOBYTE(v4) = strcmp(&s[v3 - v2], s2) == 0;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s, char *s2)
{
size_t v2; // r12
size_t v3; // rax
unsigned int v4; // er8

v2 = strlen(s2);
v3 = strlen(s);
v4 = 0;
if ( v2 < v3 )
LOBYTE(v4) = strcmp(&s[v3 - v2], s2) == 0;
return v4;
}

original_code:
static _Bool match_suffix(const char *name, const char *suffix)
{
    size_t suffix_len = strlen(suffix);
    size_t name_len = strlen(name);
    if (name_len <= suffix_len)
    {
        return 0;
    }
    return (strcmp(name + name_len - suffix_len, suffix) == 0);
}

canonical_original_code:
static _Bool match_suffix(char *name, char *suffix)
{
    unsigned long suffix_len = strlen(suffix);
    unsigned long name_len = strlen(name);
    if (name_len <= suffix_len)
    {
        return 0;
    }
    return (strcmp(name + name_len - suffix_len, suffix) == 0);
}

variable_types:
name
char *

variable_types:
suffix
char *


decompiled_code:
__int64 __fastcall should_optimise(char *s)
{
__int64 result; // rax

result = match_suffix(s, ".html");
if ( !(_BYTE)result )
{
result = match_suffix(s, ".css");
if ( !(_BYTE)result )
result = match_suffix(s, ".js");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s)
{
__int64 result; // rax

result = func8(s, ".html");
if ( !(_BYTE)result )
{
result = func8(s, ".css");
if ( !(_BYTE)result )
result = func8(s, ".js");
}
return result;
}

original_code:
static _Bool should_optimise(const char *name)
{
    return (match_suffix(name, ".html") ||
            match_suffix(name, ".css") ||
            match_suffix(name, ".js"));
}

canonical_original_code:
static _Bool should_optimise(char *name)
{
    return (match_suffix(name, ".html") ||
            match_suffix(name, ".css") ||
            match_suffix(name, ".js"));
}


decompiled_code:
int __fastcall print_symbol(char *a1)
{
int result; // eax
char v2; // bl
_BYTE *v3; // rbp
const unsigned __int16 **v4; // r12

result = fwrite("data_", 1uLL, 5uLL, _bss_start);
v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = __ctype_b_loc();
do
{
while ( ((*v4)[v2] & 8) != 0 )
{
++v3;
result = fputc(v2, _bss_start);
v2 = *(v3 - 1);
if ( !v2 )
return result;
}
++v3;
result = fputc(95, _bss_start);
v2 = *(v3 - 1);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *a1)
{
int result; // eax
char v2; // bl
_BYTE *v3; // rbp
const unsigned __int16 **v4; // r12

result = fwrite("data_", 1uLL, 5uLL, _bss_start);
v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = __ctype_b_loc();
do
{
while ( ((*v4)[v2] & 8) != 0 )
{
++v3;
result = fputc(v2, _bss_start);
v2 = *(v3 - 1);
if ( !v2 )
return result;
}
++v3;
result = fputc(95, _bss_start);
v2 = *(v3 - 1);
}
while ( v2 );
}
return result;
}

original_code:
static void print_symbol(const char *name)
{
    fputs("data_", stdout);
    for (int i = 0; name[i]; i++)
    {
        if (((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short int) _ISalnum))
        {
            fputc(name[i], stdout);
        }
        else
        {
            fputc('_', stdout);
        }
    }
}

canonical_original_code:
static void print_symbol(char *name)
{
    fputs("data_", stdout);
    for (int i = 0; name[i]; i++)
    {
        if (((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short) _ISalnum))
        {
            fputc(name[i], stdout);
        }
        else
        {
            fputc('_', stdout);
        }
    }
}

variable_types: i int

return_type: void


original_code:
static int128_t aes_expandkey_assist(int128_t a, int128_t b)
{
    b = __builtin_ia32_pshufd(b, 0xFF);
    int128_t c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    return c ^ a ^ b;
}

canonical_original_code:
static long long aes_expandkey_assist(long long a, long long b)
{
    b = __builtin_ia32_pshufd(b, 0xFF);
    long long c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    a = c ^ a;
    c = __builtin_ia32_pslldqi128((a), (4) * 8);
    return c ^ a ^ b;
}

variable_types:
a
long long

variable_types:
b
long long

variable_types:
c
long long

return_type: long long


decompiled_code:
_BOOL8 aes_hardware_test()
{
_RAX = 1LL;
__asm { cpuid }
return (_RCX & 0x2000000) != 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
_RAX = 1LL;
__asm { cpuid }
return (_RCX & 0x2000000) != 0;
}

original_code:
extern _Bool aes_hardware_test(void)
{
    unsigned a, b, c, d;
    __asm__ __volatile__ ("cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (1));
    return ((c & 0x02000000) != 0);
}

canonical_original_code:
extern _Bool aes_hardware_test()
{
    unsigned int a; unsigned int b; unsigned int c; unsigned int d;
    __asm__ __volatile__ ("cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (1));
    return ((c & 0x02000000) != 0);
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int


decompiled_code:
__int64 __fastcall cktp_calculate_checksum(__int64 a1, __int16 a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
char v4; // ah

if ( !a2 )
return 0LL;
v2 = 0;
v3 = a1 + (unsigned __int16)(a2 - 1) + 1;
do
{
v4 = BYTE1(v2);
++a1;
v2 <<= 8;
LOWORD(v2) = crc16_table[(unsigned __int8)(*(_BYTE *)(a1 - 1) ^ v4)] ^ v2;
}
while ( v3 != a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int16 a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
char v4; // ah

if ( !a2 )
return 0LL;
v2 = 0;
v3 = a1 + (unsigned __int16)(a2 - 1) + 1;
do
{
v4 = BYTE1(v2);
++a1;
v2 <<= 8;
LOWORD(v2) = crc16_table[(unsigned __int8)(*(_BYTE *)(a1 - 1) ^ v4)] ^ v2;
}
while ( v3 != a1 );
return v2;
}

original_code:
uint16_t cktp_calculate_checksum(uint8_t *data, uint16_t length)
{
    uint16_t remainder = 0;
    for (uint16_t i = 0; i < length; i++)
    {
        uint8_t byte = data[i] ^ (remainder >> 8*(sizeof(uint16_t)-1));
        remainder = crc16_table[byte] ^ (remainder << 8);
    }
    return remainder;
}

canonical_original_code:
unsigned short cktp_calculate_checksum(unsigned char *data, unsigned short length)
{
    unsigned short remainder = 0;
    for (unsigned short i = 0; i < length; i++)
    {
        unsigned char byte = data[i] ^ (remainder >> 8*(sizeof(uint16_t)-1));
        remainder = crc16_table[byte] ^ (remainder << 8);
    }
    return remainder;
}

variable_types:
data
unsigned char *

variable_types:
length
unsigned short

variable_types:
remainder
unsigned short

variable_types:
i
unsigned short

variable_types:
byte
unsigned char

return_type: unsigned short


decompiled_code:
const char *__fastcall cktp_error_to_string(unsigned __int8 a1)
{
const char *result; // rax

result = "Unknown error";
if ( a1 <= 3u )
result = CSWTCH_3[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned __int8 a1)
{
const char *result; // rax

result = "Unknown error";
if ( a1 <= 3u )
result = CSWTCH_3[a1];
return result;
}

original_code:
const char *cktp_error_to_string(uint8_t err)
{
    switch (err)
    {
        case 0x00:
            return "Success";
        case 0x01:
            return "Not authenticated";
        case 0x02:
            return "Operation not supported";
        case 0x03:
            return "Invalid argument";
        default:
            return "Unknown error";
    }
}

canonical_original_code:
char *cktp_error_to_string(unsigned char err)
{
    switch (err)
    {
        case 0x00:
            return "Success";
        case 0x01:
            return "Not authenticated";
        case 0x02:
            return "Operation not supported";
        case 0x03:
            return "Invalid argument";
        default:
            return "Unknown error";
    }
}

variable_types:
err
unsigned char

return_type: char *


main

canonical_name: main

repo: bastibl/bame

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
int v5; // ebx
unsigned int v6; // eax
int v7; // esi
unsigned int v8; // eax
char v9; // al

v3 = 1;
v4 = 3;
v5 = 7;
init_curses(argc, argv, envp);
signal(2, sig_handler);
signal(15, sig_handler);
v6 = time(0LL);
srand(v6);
if ( pthread_mutex_init(&mutex, 0LL) )
{
puts("can't create mutex");
pthread_cancel(thread);
endwin();
}
else
{
do
{
v7 = v4;
v8 = 1 << v5--;
v4 += 7;
mvprintw(20, v7, "% 3u", v8);
}
while ( v5 != -1 );
mvprintw(3, 1, "-----------------------------------------");
while ( 1 )
{
reset_game();
v3 = pthread_create(&thread, 0LL, input_thread, 0LL);
if ( v3 )
break;
while ( go_on )
{
usleep(delay);
add_row();
}
pthread_cancel(thread);
mvprintw(2, 1, "press space for new game, or 'q' to exit");
while ( 1 )
{
v9 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( (v9 & 0xDF) == 0 )
break;
if ( v9 == 113 )
{
endwin();
return v3;
}
}
}
v3 = 1;
printf("can't create thread");
endwin();
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
int v5; // ebx
unsigned int v6; // eax
int v7; // esi
unsigned int v8; // eax
char v9; // al

v3 = 1;
v4 = 3;
v5 = 7;
func8(argc, argv, envp);
signal(2, sig_handler);
signal(15, sig_handler);
v6 = time(0LL);
srand(v6);
if ( pthread_mutex_init(&mutex, 0LL) )
{
puts("can't create mutex");
pthread_cancel(thread);
endwin();
}
else
{
do
{
v7 = v4;
v8 = 1 << v5--;
v4 += 7;
mvprintw(20, v7, "% 3u", v8);
}
while ( v5 != -1 );
mvprintw(3, 1, "-----------------------------------------");
while ( 1 )
{
func12();
v3 = pthread_create(&thread, 0LL, input_thread, 0LL);
if ( v3 )
break;
while ( go_on )
{
usleep(delay);
func13();
}
pthread_cancel(thread);
mvprintw(2, 1, "press space for new game, or 'q' to exit");
while ( 1 )
{
v9 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( (v9 & 0xDF) == 0 )
break;
if ( v9 == 113 )
{
endwin();
return v3;
}
}
}
v3 = 1;
printf("can't create thread");
endwin();
}
return v3;
}

original_code:
int
main(int argc, char **arvc) {
 init_curses();
 signal(2, sig_handler);
 signal(15, sig_handler);
 srand((unsigned) time(((void *)0)));
 if(pthread_mutex_init(&mutex, ((void *)0))) {
  printf("can't create mutex\n");
  pthread_cancel(thread);
  endwin();
  return 1;
 }
 int i;
 for(i = 7; i >= 0; i--) {
  mvprintw(15 + 5, (7 - i) * 7 + 3 , "% 3u", 1<<i);
 }
 mvprintw(3, 1, "-----------------------------------------");
 char c;
 while(1) {
  reset_game();
  if(pthread_create(&thread, ((void *)0), input_thread, ((void *)0))) {
   printf("can't create thread");
   endwin();
   return 1;
  }
  while(go_on) {
   usleep(delay);
   add_row();
  }
  pthread_cancel(thread);
  mvprintw(2, 1, "press space for new game, or 'q' to exit");
  while(c = wgetch(stdscr)) {
   if(c == ' ') {
    break;
   }
   if(c == 'q') {
    goto out;
   }
  }
 }
out:
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char **arvc) {
 init_curses();
 signal(2, sig_handler);
 signal(15, sig_handler);
 srand((unsigned int) time(((void *)0)));
 if(pthread_mutex_init(&mutex, ((void *)0))) {
  printf("can't create mutex\n");
  pthread_cancel(thread);
  endwin();
  return 1;
 }
 int i;
 for(i = 7; i >= 0; i--) {
  mvprintw(15 + 5, (7 - i) * 7 + 3 , "% 3u", 1<<i);
 }
 mvprintw(3, 1, "-----------------------------------------");
 char c;
 while(1) {
  reset_game();
  if(pthread_create(&thread, ((void *)0), input_thread, ((void *)0))) {
   printf("can't create thread");
   endwin();
   return 1;
  }
  while(go_on) {
   usleep(delay);
   add_row();
  }
  pthread_cancel(thread);
  mvprintw(2, 1, "press space for new game, or 'q' to exit");
  while(c = wgetch(stdscr)) {
   if(c == ' ') {
    break;
   }
   if(c == 'q') {
    goto out;
   }
  }
 }
out:
 endwin();
 return 0;
}

variable_types: argc int

variable_types:
arvc
char **

variable_types: c char


decompiled_code:
void __noreturn sig_handler()
{
endwin();
puts("blame exiting...cya");
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
endwin();
puts("blame exiting...cya");
exit(0);
}

original_code:
static void
sig_handler(int s) {
 endwin();
 printf("blame exiting...cya\n");
 exit(0);
}

variable_types: s int


decompiled_code:
int init_curses()
{
initscr();
curs_set(0);
noecho();
cbreak();
start_color();
use_default_colors();
init_pair(1, 7, -1);
init_pair(2, 7, 1);
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
return mvprintw(0, 0, "..:: B-A-M-E ::..");
}

canonical_decompiled_code:
int func8()
{
initscr();
curs_set(0);
noecho();
cbreak();
start_color();
use_default_colors();
init_pair(1, 7, -1);
init_pair(2, 7, 1);
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
return mvprintw(0, 0, "..:: B-A-M-E ::..");
}


decompiled_code:
int update_score()
{
return mvprintw(1, 0, "score: % 10u level: % 2u", (unsigned int)score, (unsigned int)level);
}

canonical_decompiled_code:
int func9()
{
return mvprintw(1, 0, "score: % 10u level: % 2u", (unsigned int)score, (unsigned int)level);
}

original_code:
void
update_score() {
 mvprintw(1, 0, "score: % 10u   level:  % 2u", score, level);
}


decompiled_code:
int print_current()
{
unsigned int v0; // ebx
bool v1; // cf
int v2; // eax

v0 = 7;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 19, 1);
printw(" | ");
do
{
while ( 1 )
{
v2 = (unsigned __int16)cur_line;
if ( !_bittest(&v2, v0) )
break;
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200uLL, 0LL);
printw("__");
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
printw(" | ");
v1 = v0-- == 0;
if ( v1 )
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}
printw("__ | ");
v1 = v0-- == 0;
}
while ( !v1 );
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

canonical_decompiled_code:
int func10()
{
unsigned int v0; // ebx
bool v1; // cf
int v2; // eax

v0 = 7;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 19, 1);
printw(" | ");
do
{
while ( 1 )
{
v2 = (unsigned __int16)cur_line;
if ( !_bittest(&v2, v0) )
break;
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200uLL, 0LL);
printw("__");
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
printw(" | ");
v1 = v0-- == 0;
if ( v1 )
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}
printw("__ | ");
v1 = v0-- == 0;
}
while ( !v1 );
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

variable_types: i int

variable_types: line int


decompiled_code:
int print_rows()
{
int v0; // ebp
int v1; // ebx
__int64 v2; // rsi

v0 = 18;
v1 = row_index;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 18, 5);
do
{
v2 = *((unsigned int *)&rows + v1);
if ( (_DWORD)v2 )
printw("% 6u", v2);
else
printw(" ");
--v0;
v1 = (v1 + 1) % 15;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v0, 5);
}
while ( v0 != 3 );
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

canonical_decompiled_code:
int func11()
{
int v0; // ebp
int v1; // ebx
__int64 v2; // rsi

v0 = 18;
v1 = row_index;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 18, 5);
do
{
v2 = *((unsigned int *)&rows + v1);
if ( (_DWORD)v2 )
printw("% 6u", v2);
else
printw(" ");
--v0;
v1 = (v1 + 1) % 15;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v0, 5);
}
while ( v0 != 3 );
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

original_code:
void
print_rows() {
 int i;
 int index = row_index;
 int line = 15 + 3;
 int col = 5;
 wmove(stdscr,(line),(col));
 for(i = 0; i < 15; i++) {
  if(!rows[index]) {
   printw("      ");
  } else {
   printw("% 6u", rows[index]);
  }
  index = (index + 1) % 15;
  wmove(stdscr,(--line),(col));
 }
 wrefresh(stdscr);
}

variable_types: index int

variable_types: col int


decompiled_code:
int reset_game()
{
int result; // eax

score = 0;
update_score();
qword_4041B0 = 0LL;
cur_line = 0;
rows = 0LL;
xmmword_404190 = 0LL;
xmmword_4041A0 = 0LL;
dword_4041B8 = 0;
row_index = 0;
print_current();
print_rows();
go_on = 1;
result = mvprintw(2, 0, " ");
delay = 2500000;
lines_in_level = 0;
level = 0;
return result;
}

canonical_decompiled_code:
int func12()
{
int result; // eax

score = 0;
func9();
qword_4041B0 = 0LL;
cur_line = 0;
rows = 0LL;
xmmword_404190 = 0LL;
xmmword_4041A0 = 0LL;
dword_4041B8 = 0;
row_index = 0;
func10();
func11();
go_on = 1;
result = mvprintw(2, 0, " ");
delay = 2500000;
lines_in_level = 0;
level = 0;
return result;
}

original_code:
void
reset_game() {
 int i;
 score = 0;
 update_score();
 for(i = 0; i < 15; i++) {
  rows[i] = 0;
 }
 row_index = 0;
 cur_line = 0;
 print_current();
 print_rows();
 go_on = 1;
 mvprintw(2,0,"                                           ");
 delay = 2500 * 1000;
 lines_in_level = 0;
 level = 0;
}


decompiled_code:
int add_row()
{
int result; // eax
int v1; // esi
__int64 v2; // rbx
int v3; // edx
int v4; // eax

result = row_index;
v1 = 15;
while ( 1 )
{
v2 = result;
if ( !*((_DWORD *)&rows + result) )
break;
result = (result + 1) % 15;
if ( !--v1 )
{
go_on = 0;
return result;
}
}
v3 = rand() % 255 + 1;
v4 = lines_in_level + 1;
*((_DWORD *)&rows + v2) = v3;
lines_in_level = v4;
if ( v4 == 18 )
{
delay -= 100000;
++level;
lines_in_level = 0;
}
return print_rows();
}

canonical_decompiled_code:
int func13()
{
int result; // eax
int v1; // esi
__int64 v2; // rbx
int v3; // edx
int v4; // eax

result = row_index;
v1 = 15;
while ( 1 )
{
v2 = result;
if ( !*((_DWORD *)&rows + result) )
break;
result = (result + 1) % 15;
if ( !--v1 )
{
go_on = 0;
return result;
}
}
v3 = rand() % 255 + 1;
v4 = lines_in_level + 1;
*((_DWORD *)&rows + v2) = v3;
lines_in_level = v4;
if ( v4 == 18 )
{
delay -= 100000;
++level;
lines_in_level = 0;
}
return func11();
}

original_code:
void
add_row() {
 int i = 15;
 int index = row_index;
 while(i) {
  if(!rows[index]) {
   rows[index] = (rand() % 255) + 1;
   break;
  }
  i--;
  index = (index + 1) % 15;
 }
 if(!i) {
  go_on = i;
  return;
 }
 lines_in_level++;
 if(lines_in_level == 18) {
  delay -= 100 * 1000;
  lines_in_level = 0;
  level++;
 }
 print_rows();
}


decompiled_code:
int delete_row()
{
int v0; // edx

v0 = row_index;
*((_DWORD *)&rows + (unsigned int)row_index) = 0;
row_index = (v0 + 1) % 0xFu;
return print_rows();
}

canonical_decompiled_code:
int func14()
{
int v0; // edx

v0 = row_index;
*((_DWORD *)&rows + (unsigned int)row_index) = 0;
row_index = (v0 + 1) % 0xFu;
return func11();
}

original_code:
void
delete_row() {
 rows[row_index] = 0;
 row_index = (row_index + 1) % 15;
 print_rows();
}


decompiled_code:
int check_row()
{
int v0; // eax

v0 = *((_DWORD *)&rows + (unsigned int)row_index);
if ( v0 && v0 == (unsigned __int16)cur_line )
{
score += 10;
update_score();
cur_line = 0;
delete_row();
}
return print_current();
}

canonical_decompiled_code:
int func15()
{
int v0; // eax

v0 = *((_DWORD *)&rows + (unsigned int)row_index);
if ( v0 && v0 == (unsigned __int16)cur_line )
{
score += 10;
func9();
cur_line = 0;
func14();
}
return func10();
}

original_code:
void
check_row() {
 if(rows[row_index] && (rows[row_index] == cur_line)) {
  score += 10;
  update_score();
  cur_line = 0;
  delete_row();
 }
 print_current();
}


decompiled_code:
void __fastcall input_thread(void *a1)
{
while ( 1 )
{
switch ( (unsigned __int8)wgetch(stdscr__NCURSES6_TINFO_5_0_19991023) )
{
case ';':
cur_line ^= 1u;
check_row();
continue;
case 'a':
cur_line ^= 0x80u;
check_row();
continue;
case 'd':
cur_line ^= 0x20u;
check_row();
continue;
case 'f':
cur_line ^= 0x10u;
check_row();
continue;
case 'j':
cur_line ^= 8u;
check_row();
continue;
case 'k':
cur_line ^= 4u;
check_row();
continue;
case 'l':
cur_line ^= 2u;
check_row();
continue;
case 'q':
go_on = 0;
goto LABEL_3;
case 's':
cur_line ^= 0x40u;
check_row();
continue;
default:
LABEL_3:
check_row();
break;
}
}
}

canonical_decompiled_code:
void __fastcall func16(void *a1)
{
while ( 1 )
{
switch ( (unsigned __int8)wgetch(stdscr__NCURSES6_TINFO_5_0_19991023) )
{
case ';':
cur_line ^= 1u;
func15();
continue;
case 'a':
cur_line ^= 0x80u;
func15();
continue;
case 'd':
cur_line ^= 0x20u;
func15();
continue;
case 'f':
cur_line ^= 0x10u;
func15();
continue;
case 'j':
cur_line ^= 8u;
func15();
continue;
case 'k':
cur_line ^= 4u;
func15();
continue;
case 'l':
cur_line ^= 2u;
func15();
continue;
case 'q':
go_on = 0;
goto LABEL_3;
case 's':
cur_line ^= 0x40u;
func15();
continue;
default:
LABEL_3:
func15();
break;
}
}
}

original_code:
void*
input_thread(void *args) {
 char c;
 while(1) {
  c = wgetch(stdscr);
  switch(c) {
   case 'a':
    cur_line ^= 1 << 7;
    break;
   case 's':
    cur_line ^= 1 << 6;
    break;
   case 'd':
    cur_line ^= 1 << 5;
    break;
   case 'f':
    cur_line ^= 1 << 4;
    break;
   case 'j':
    cur_line ^= 1 << 3;
    break;
   case 'k':
    cur_line ^= 1 << 2;
    break;
   case 'l':
    cur_line ^= 1 << 1;
    break;
   case ';':
    cur_line ^= 1 << 0;
    break;
   case 'q':
    go_on = 0;
    break;
  }
  check_row();
 }
}

canonical_original_code:
void *input_thread(void *args) {
 char c;
 while(1) {
  c = wgetch(stdscr);
  switch(c) {
   case 'a':
    cur_line ^= 1 << 7;
    break;
   case 's':
    cur_line ^= 1 << 6;
    break;
   case 'd':
    cur_line ^= 1 << 5;
    break;
   case 'f':
    cur_line ^= 1 << 4;
    break;
   case 'j':
    cur_line ^= 1 << 3;
    break;
   case 'k':
    cur_line ^= 1 << 2;
    break;
   case 'l':
    cur_line ^= 1 << 1;
    break;
   case ';':
    cur_line ^= 1 << 0;
    break;
   case 'q':
    go_on = 0;
    break;
  }
  check_row();
 }
}

variable_types:
args
void *

return_type: void *


repo: bauerca/gridfloat

original_code:
void gf_init_data(int types, size_t sz, gf_data *data) {
    memset((void *)data, 0, sizeof(gf_data));
    if (types & ELEVATION)
        data->elev = (float *)malloc(sz * sizeof(float));
    if (types & GRADX)
        data->gradx = (double *)malloc(sz * sizeof(double));
    if (types & GRADY)
        data->grady = (double *)malloc(sz * sizeof(double));
    if (types & SHADE)
        data->shade = (unsigned char *)malloc(sz * sizeof(unsigned char));
}

canonical_original_code:
void gf_init_data(int types, unsigned long sz, struct gf_data *data) {
    memset((void *)data, 0, sizeof(gf_data));
    if (types & ELEVATION)
        data->elev = (float *)malloc(sz * sizeof(float));
    if (types & GRADX)
        data->gradx = (double *)malloc(sz * sizeof(double));
    if (types & GRADY)
        data->grady = (double *)malloc(sz * sizeof(double));
    if (types & SHADE)
        data->shade = (unsigned char *)malloc(sz * sizeof(unsigned char));
}

variable_types: types int

variable_types:
sz
unsigned long

variable_types: struct gf_data { float *elev; double *gradx; double *grady; unsigned char *shade; } *


original_code:
void gf_init_grid_point(gf_grid *grid, double lat, double lng, double width, double height, int nlat, int nlng) {
    grid->ny = nlat;
    grid->nx = nlng;
    grid->left = lng - 0.5 * width;
    grid->right = lng + 0.5 * width;
    grid->bottom = lat - 0.5 * height;
    grid->top = lat + 0.5 * height;
    grid->dx = (grid->right - grid->left) / ((double)(grid->nx - 1));
    grid->dy = (grid->top - grid->bottom) / ((double)(grid->ny - 1));
}

canonical_original_code:
void gf_init_grid_point(struct gf_grid *grid, double lat, double lng, double width, double height, int nlat, int nlng) {
    grid->ny = nlat;
    grid->nx = nlng;
    grid->left = lng - 0.5 * width;
    grid->right = lng + 0.5 * width;
    grid->bottom = lat - 0.5 * height;
    grid->top = lat + 0.5 * height;
    grid->dx = (grid->right - grid->left) / ((double)(grid->nx - 1));
    grid->dy = (grid->top - grid->bottom) / ((double)(grid->ny - 1));
}

variable_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; } *

variable_types: lat double

variable_types: lng double

variable_types: width double

variable_types: height double

variable_types: nlat int

variable_types: nlng int


decompiled_code:
void __fastcall gf_init_bounds_point(double *a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm2_8
double v6; // xmm3_8

v5 = a4 * 0.5;
v6 = a5 * 0.5;
*a1 = a3 - v5;
a1[1] = v5 + a3;
a1[2] = a2 - v6;
a1[3] = v6 + a2;
}

canonical_decompiled_code:
void __fastcall func2(double *a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm2_8
double v6; // xmm3_8

v5 = a4 * 0.5;
v6 = a5 * 0.5;
*a1 = a3 - v5;
a1[1] = v5 + a3;
a1[2] = a2 - v6;
a1[3] = v6 + a2;
}

original_code:
void gf_init_bounds_point(gf_bounds *b, double lat, double lng, double w, double h) {
    b->left = lng - 0.5 * w;
    b->right = lng + 0.5 * w;
    b->bottom = lat - 0.5 * h;
    b->top = lat + 0.5 * h;
}

canonical_original_code:
void gf_init_bounds_point(struct gf_bounds *b, double lat, double lng, double w, double h) {
    b->left = lng - 0.5 * w;
    b->right = lng + 0.5 * w;
    b->bottom = lat - 0.5 * h;
    b->top = lat + 0.5 * h;
}

variable_types: struct gf_bounds { double left; double right; double bottom; double top; } *

variable_types: w double

variable_types: h double


decompiled_code:
void __fastcall gf_init_grid_bounds(__int64 a1, int a2, int a3, double a4, double a5, double a6, double a7)
{
gf_init_grid_point(a1, a2, a3, (a7 + a6) * 0.5, 0.5 * (a5 + a4), a5 - a4, a7 - a6);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2, int a3, double a4, double a5, double a6, double a7)
{
func1(a1, a2, a3, (a7 + a6) * 0.5, 0.5 * (a5 + a4), a5 - a4, a7 - a6);
}

original_code:
void gf_init_grid_bounds(gf_grid *grid, double left, double right, double bottom, double top, int nlat, int nlng) {
    gf_init_grid_point(grid, 0.5 * (top + bottom), 0.5 * (left + right), right - left, top - bottom, nlat, nlng);
}

canonical_original_code:
void gf_init_grid_bounds(struct gf_grid *grid, double left, double right, double bottom, double top, int nlat, int nlng) {
    gf_init_grid_point(grid, 0.5 * (top + bottom), 0.5 * (left + right), right - left, top - bottom, nlat, nlng);
}

variable_types: left double

variable_types: right double

variable_types: bottom double

variable_types: top double

user_defined_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; }


original_code:
void gf_lengths(double lat, double lng, double dlat, double dlng, double ecc, double *dx, double *dy) {
    double theta, dtheta, dphi;
    theta = 3.14159265 * lat / 180.0;
    dtheta = 3.14159265 * dlat / 180.0;
    dphi = 3.14159265 * dlng / 180.0;
    if (ecc == 0.0) {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta);
    } else {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta) / sqrt(1.0 - (ecc * sin(theta)) * (ecc * sin(theta)));
    }
}

canonical_original_code:
void gf_lengths(double lat, double lng, double dlat, double dlng, double ecc, double *dx, double *dy) {
    double theta; double dtheta; double dphi;
    theta = 3.14159265 * lat / 180.0;
    dtheta = 3.14159265 * dlat / 180.0;
    dphi = 3.14159265 * dlng / 180.0;
    if (ecc == 0.0) {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta);
    } else {
        *dy = dtheta * 6378137.;
        *dx = dphi * 6378137. * cos(theta) / sqrt(1.0 - (ecc * sin(theta)) * (ecc * sin(theta)));
    }
}

variable_types: dlat double

variable_types: dlng double

variable_types: ecc double

variable_types:
dx
double *

variable_types:
dy
double *

variable_types: theta double

variable_types: dtheta double

variable_types: dphi double


original_code:
void gf_cellsize_meters(gf_grid *grid, double *dxm, double *dym) {
    double lat, lng;
    lat = 0.5 * (grid->top + grid->bottom);
    lng = 0.5 * (grid->left + grid->right);
    gf_lengths(lat, lng, grid->dy, grid->dx, 0.0, dxm, dym);
}

canonical_original_code:
void gf_cellsize_meters(struct gf_grid *grid, double *dxm, double *dym) {
    double lat; double lng;
    lat = 0.5 * (grid->top + grid->bottom);
    lng = 0.5 * (grid->left + grid->right);
    gf_lengths(lat, lng, grid->dy, grid->dx, 0.0, dxm, dym);
}

variable_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; } *

variable_types:
dxm
double *

variable_types:
dym
double *

variable_types: lat double

variable_types: lng double


original_code:
void gf_print(const gf_grid *grid, gf_float *data, int xy) {
    long ni, nj, i, j, k;
    int c, nc = 1;
    ni = grid->ny;
    nj = grid->nx;
    if (xy) {
        ni = grid->nx;
        nj = grid->ny;
    }
    for (i = 0, k = 0; i < ni; ++i) {
        fprintf(stdout, "[");
        for (j = 0; j < nj; ++j) {
            if (nc > 1) {
                fprintf(stdout, "[");
            }
            for (c = 0; c < nc; ++c) {
                if (xy) {
                    k = c + nc * (i + ni * (nj - 1 - j));
                } else {
                    k = c + nc * (j + nj * i);
                }
                fprintf(stdout, "%.12e", data[k]);
                if (c < nc - 1) {
                    fprintf(stdout, ", ");
                }
            }
            if (nc > 1) {
                fprintf(stdout, "]");
            }
            if (j < nj - 1) {
                fprintf(stdout, ", ");
            }
        }
        fprintf(stdout, "]\n");
    }
}

canonical_original_code:
void gf_print(struct gf_grid *grid, float *data, int xy) {
    long ni; long nj; long i; long j; long k;
    int c; int nc = 1;
    ni = grid->ny;
    nj = grid->nx;
    if (xy) {
        ni = grid->nx;
        nj = grid->ny;
    }
    for (i = 0, k = 0; i < ni; ++i) {
        fprintf(stdout, "[");
        for (j = 0; j < nj; ++j) {
            if (nc > 1) {
                fprintf(stdout, "[");
            }
            for (c = 0; c < nc; ++c) {
                if (xy) {
                    k = c + nc * (i + ni * (nj - 1 - j));
                } else {
                    k = c + nc * (j + nj * i);
                }
                fprintf(stdout, "%.12e", data[k]);
                if (c < nc - 1) {
                    fprintf(stdout, ", ");
                }
            }
            if (nc > 1) {
                fprintf(stdout, "]");
            }
            if (j < nj - 1) {
                fprintf(stdout, ", ");
            }
        }
        fprintf(stdout, "]\n");
    }
}

variable_types:
data
float *

variable_types: xy int

variable_types: ni long

variable_types: nj long

variable_types: i long

variable_types: j long

variable_types: k long

variable_types: c int

variable_types: nc int


decompiled_code:
int __fastcall gf_print_grid_info(double *a1)
{
return fprintf(
stdout,
"grid info:\n"
" bounds:\n"
" left: %f\n"
" right: %f\n"
" bottom: %f\n"
" top: %f\n"
" cellsize: %fx%f degrees\n"
" resolution: %dx%d\n",
a1[3],
a1[4],
a1[5],
a1[6],
a1[1],
a1[2],
*(unsigned int *)a1,
*((unsigned int *)a1 + 1));
}

canonical_decompiled_code:
int __fastcall func13(double *a1)
{
return fprintf(
stdout,
"grid info:\n"
" bounds:\n"
" left: %f\n"
" right: %f\n"
" bottom: %f\n"
" top: %f\n"
" cellsize: %fx%f degrees\n"
" resolution: %dx%d\n",
a1[3],
a1[4],
a1[5],
a1[6],
a1[1],
a1[2],
*(unsigned int *)a1,
*((unsigned int *)a1 + 1));
}

original_code:
void gf_print_grid_info(gf_grid *grid) {
    fprintf(stdout,
        "grid info:\n"
        "  bounds:\n"
        "    left: %f\n"
        "    right: %f\n"
        "    bottom: %f\n"
        "    top: %f\n"
        "  cellsize: %fx%f degrees\n"
        "  resolution: %dx%d\n",
        grid->left,
        grid->right,
        grid->bottom,
        grid->top,
        grid->dx,
        grid->dy,
        grid->nx,
        grid->ny);
}

canonical_original_code:
void gf_print_grid_info(struct gf_grid *grid) {
    fprintf(stdout,
        "grid info:\n"
        "  bounds:\n"
        "    left: %f\n"
        "    right: %f\n"
        "    bottom: %f\n"
        "    top: %f\n"
        "  cellsize: %fx%f degrees\n"
        "  resolution: %dx%d\n",
        grid->left,
        grid->right,
        grid->bottom,
        grid->top,
        grid->dx,
        grid->dy,
        grid->nx,
        grid->ny);
}


original_code:
static
int gf_set_null_gradient(void **data_ptr) {
    double **grad_ptr = (double **)data_ptr;
    (*grad_ptr)[0] = -9999.0;
    (*grad_ptr)[1] = -9999.0;
    grad_ptr[0] += 2;
    return 0;
}


canonical_original_code:
int gf_biquadratic_gradient_kernel(float nine[][3], struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void **data_ptr) {
    double **dptr = (double **)data_ptr;
    double dx_m = -1.0; double dy_m = -1.0;
    int i; int k;
    double avg_w;
    double v[3];
    gf_lengths(latlng[0], latlng[1], from_grid->dy, from_grid->dx, 0.0, &dy_m, &dx_m);
    if (w[0] < 0.0) {
        k = 0;
        avg_w = 1.0 + w[0];
    } else {
        k = 1;
        avg_w = w[0];
    }
    for (i = 0; i < 3; ++i) {
        v[i] = (1.0 - avg_w) * nine[k][i] + avg_w * nine[k + 1][i];
    }
    (*dptr)[0] = ((v[0] + v[2] - 2.0 * v[1]) * w[1] + 0.5 * (v[2] - v[0])) / dx_m;
    if (w[1] < 0.0) {
        k = 0;
        avg_w = 1.0 + w[1];
    } else {
        k = 1;
        avg_w = w[1];
    }
    for (i = 0; i < 3; ++i) {
        v[i] = (1.0 - avg_w) * nine[i][k] + avg_w * nine[i][k + 1];
    }
    (*dptr)[1] = -((v[0] + v[2] - 2.0 * v[1]) * w[0] + 0.5 * (v[2] - v[0])) / dy_m;
    dptr[0] += 2;
    return 0;
}

variable_types:
nine
float [][3]

variable_types:
w
double *

variable_types:
latlng
double *

variable_types:
xtras
void *

variable_types:
dptr
double **

variable_types: i int

variable_types: k int

variable_types:
v
double [3]


decompiled_code:
__int64 __fastcall gf_set_null_png_byte(_BYTE **a1)
{
__int64 result; // rax

**a1 = 0;
result = 0LL;
++*a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE **a1)
{
__int64 result; // rax

**a1 = 0;
result = 0LL;
++*a1;
return result;
}

original_code:
static
int gf_set_null_png_byte(void **data_ptr) {
    png_byte **dptr = (png_byte **)data_ptr;
    (*dptr)[0] = 0;
    dptr[0]++;
    return 0;
}

canonical_original_code:
static int gf_set_null_png_byte(void **data_ptr) {
    unsigned char **dptr = (png_byte **)data_ptr;
    (*dptr)[0] = 0;
    dptr[0]++;
    return 0;
}

variable_types:
dptr
unsigned char **


decompiled_code:
__int64 __fastcall gf_relief_shade_kernel(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double *a5, _BYTE **a6)
{
double v8; // xmm0_8
double v9; // xmm1_8
double v10; // xmm3_8
double v11; // xmm2_8
double v12; // xmm2_8
int v13; // edx
double v14; // xmm0_8
__int64 result; // rax
double v16; // xmm0_8
double *v17; // [rsp+8h] [rbp-30h] BYREF
double v18; // [rsp+10h] [rbp-28h] BYREF
double v19; // [rsp+18h] [rbp-20h]

v18 = *(double *)&LC0;
v19 = *(double *)&LC0;
v17 = &v18;
gf_biquadratic_gradient_kernel(a1, a2, a3, a4, 0LL, &v17);
v8 = v18;
if ( v18 == -9999.0 || (v9 = v19, v19 == -9999.0) )
{
fwrite("gf_relief_shade_kernel: Something wrong. Please report.\n", 1uLL, 0x38uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v10 = *(double *)&LC2;
v11 = v18 * v18 + 1.0 + v19 * v19;
if ( v11 < 0.0 )
{
v16 = sqrt(v11);
v9 = v19;
v12 = v16;
v8 = v18;
v10 = *(double *)&LC2;
}
else
{
v12 = sqrt(v11);
}
LOBYTE(v13) = 0;
v14 = COERCE_DOUBLE(*(_QWORD *)&v8 ^ LC4) / v12 * *a5
+ 0.0
+ COERCE_DOUBLE(*(_QWORD *)&v9 ^ LC4) / v12 * a5[1]
+ v10 / v12 * a5[2];
if ( v14 > 0.0 )
v13 = (int)(v14 * 255.0);
**a6 = v13;
result = 0LL;
++*a6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double *a5, _BYTE **a6)
{
double v8; // xmm0_8
double v9; // xmm1_8
double v10; // xmm3_8
double v11; // xmm2_8
double v12; // xmm2_8
int v13; // edx
double v14; // xmm0_8
__int64 result; // rax
double v16; // xmm0_8
double *v17; // [rsp+8h] [rbp-30h] BYREF
double v18; // [rsp+10h] [rbp-28h] BYREF
double v19; // [rsp+18h] [rbp-20h]

v18 = *(double *)&LC0;
v19 = *(double *)&LC0;
v17 = &v18;
gf_biquadratic_gradient_kernel(a1, a2, a3, a4, 0LL, &v17);
v8 = v18;
if ( v18 == -9999.0 || (v9 = v19, v19 == -9999.0) )
{
fwrite("gf_relief_shade_kernel: Something wrong. Please report.\n", 1uLL, 0x38uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v10 = *(double *)&LC2;
v11 = v18 * v18 + 1.0 + v19 * v19;
if ( v11 < 0.0 )
{
v16 = sqrt(v11);
v9 = v19;
v12 = v16;
v8 = v18;
v10 = *(double *)&LC2;
}
else
{
v12 = sqrt(v11);
}
LOBYTE(v13) = 0;
v14 = COERCE_DOUBLE(*(_QWORD *)&v8 ^ LC4) / v12 * *a5
+ 0.0
+ COERCE_DOUBLE(*(_QWORD *)&v9 ^ LC4) / v12 * a5[1]
+ v10 / v12 * a5[2];
if ( v14 > 0.0 )
v13 = (int)(v14 * 255.0);
**a6 = v13;
result = 0LL;
++*a6;
}
return result;
}

original_code:
int gf_relief_shade_kernel(gf_float nine[][3], const gf_grid *from_grid, double *w, double *latlng, void *xtras, void **data_ptr) {
    int i;
    png_byte **shade_ptr = (png_byte **)data_ptr;
    double grad[2] = {-9999.0, -9999.0}, *grad_view, n_surf[3], *n_sun, norm, shade;
    grad_view = grad;
    n_sun = (double *)xtras;
    gf_biquadratic_gradient_kernel(nine, from_grid, w, latlng, (void *)((void *)0), (void **)&grad_view);
    if (grad[0] == -9999.0 || grad[1] == -9999.0) {
        fprintf(stderr, "gf_relief_shade_kernel: Something wrong. Please report.\n");
        return -1;
    }
    norm = sqrt(1.0 + grad[0] * grad[0] + grad[1] * grad[1]);
    n_surf[0] = -grad[0] / norm;
    n_surf[1] = -grad[1] / norm;
    n_surf[2] = 1.0 / norm;
    shade = 0.0;
    for (i = 0; i < 3; ++i) {
        shade += n_sun[i] * n_surf[i];
    }
    (*shade_ptr)[0] = (int)(255.0 * (shade > 0.0 ? shade : 0.0));
    shade_ptr[0]++;
    return 0;
}

canonical_original_code:
int gf_relief_shade_kernel(float nine[][3], struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void **data_ptr) {
    int i;
    unsigned char **shade_ptr = (png_byte **)data_ptr;
    double grad[2] = {-9999.0, -9999.0}; double *grad_view; double n_surf[3]; double *n_sun; double norm; double shade;
    grad_view = grad;
    n_sun = (double *)xtras;
    gf_biquadratic_gradient_kernel(nine, from_grid, w, latlng, (void *)((void *)0), (void **)&grad_view);
    if (grad[0] == -9999.0 || grad[1] == -9999.0) {
        fprintf(stderr, "gf_relief_shade_kernel: Something wrong. Please report.\n");
        return -1;
    }
    norm = sqrt(1.0 + grad[0] * grad[0] + grad[1] * grad[1]);
    n_surf[0] = -grad[0] / norm;
    n_surf[1] = -grad[1] / norm;
    n_surf[2] = 1.0 / norm;
    shade = 0.0;
    for (i = 0; i < 3; ++i) {
        shade += n_sun[i] * n_surf[i];
    }
    (*shade_ptr)[0] = (int)(255.0 * (shade > 0.0 ? shade : 0.0));
    shade_ptr[0]++;
    return 0;
}

variable_types: struct gf_grid { int nx; int ny; double dx; double dy; double left; double right; double bottom; double top; } *

variable_types:
grad
double [2]

variable_types: norm double

variable_types: shade double


decompiled_code:
size_t print_usage()
{
return fwrite(
"Summary:\n"
" Extract subgrids of data from a GridFloat file. GridFloat\n"
" is a simple format commonly used by the USGS for packaging\n"
" elevation data. A header file with geolocation metadata is\n"
" required for making queries based on latitude/longitude.\n"
"\n"
"Usage:\n"
" gridfloat [options] FLOATFILE HEADERFILE\n"
" gridfloat [options] FLOAT_HEADER_PREFIX\n"
"\n"
" where, for the first case, FLOATFILE should have\n"
" extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
" and FLOATFILE have the same filename prefix, then you\n"
" can use the second case.\n"
"\n"
"Options:\n"
" -h: Print this help message.\n"
" -i: Print helpful info derived from GridFloat header file.\n"
" -R: Resolution of extraction. If a single integer is\n"
" supplied, then the resolution is the same in both\n"
" directions. Otherwise, the format is (by example):\n"
" '-R 128x256' where the first number is the resolution\n"
" in the x-direction (along lines of latitude).\n"
" -l: Left bound for extraction.\n"
" -r: Right bound for extraction.\n"
" -b: Bottom bound for extraction.\n"
" -t: Top bound for extraction.\n"
" -B: Specify extraction bounds using a comma-separated\n"
" list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
" '-B -123.112,-123.110,42.100,42.101'.\n"
" -n: Longitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-n 42'.\n"
" -w: Latitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-w 123' (notice there is no minus\n"
" sign here).\n"
" -p: Lat/Lng midpoint of extraction. Must use with '-s'\n"
" option. Example: '-p -123,42'.\n"
" -s: Size of box (in degrees) around midpoint. Used with '-p'\n"
" and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
" If a rectangular size is requested, the first number refers\n"
" to the width of the box (along x; i.e. along lines of\n"
" latitude).\n"
" -T: Transpose and invert along y before printing the array\n"
" (so that a[i, j] gives longitude increasing with i and\n"
" latitude increasing with j).\n"
" -o: Output subgrid data to a file. Detects output format based\n"
" on file extension. Supported: (.png, .stl). For a .png\n"
" extension, see \"PNG output options\" below. Otherwise,\n"
" gridfloat will assume you want to save another GridFloat\n"
" file. In this case, it will write the appropriate data\n"
" and header files, appending .flt and .hdr, respectively,\n"
" to the argument of -o.\n"
"\n"
"PNG output options:\n"
" When png output is specified, gridfloat automatically renders\n"
" a shaded relief map. The following options determine which\n"
" slopes are sunny.\n"
"\n"
" -A: Azimuthal angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is East, 90 North, etc.\n"
" Default: 45 (NE).\n"
" -P: Polar angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is on horizon, 90 when\n"
" directly overhead. Default: 30.\n"
"\n"
"Examples:\n"
" All of the following are equivalent and simply print data\n"
" to stdout.\n"
"\n"
" gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
" gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
" gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
" gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
"\n",
1uLL,
0xC45uLL,
stdout);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"Summary:\n"
" Extract subgrids of data from a GridFloat file. GridFloat\n"
" is a simple format commonly used by the USGS for packaging\n"
" elevation data. A header file with geolocation metadata is\n"
" required for making queries based on latitude/longitude.\n"
"\n"
"Usage:\n"
" gridfloat [options] FLOATFILE HEADERFILE\n"
" gridfloat [options] FLOAT_HEADER_PREFIX\n"
"\n"
" where, for the first case, FLOATFILE should have\n"
" extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
" and FLOATFILE have the same filename prefix, then you\n"
" can use the second case.\n"
"\n"
"Options:\n"
" -h: Print this help message.\n"
" -i: Print helpful info derived from GridFloat header file.\n"
" -R: Resolution of extraction. If a single integer is\n"
" supplied, then the resolution is the same in both\n"
" directions. Otherwise, the format is (by example):\n"
" '-R 128x256' where the first number is the resolution\n"
" in the x-direction (along lines of latitude).\n"
" -l: Left bound for extraction.\n"
" -r: Right bound for extraction.\n"
" -b: Bottom bound for extraction.\n"
" -t: Top bound for extraction.\n"
" -B: Specify extraction bounds using a comma-separated\n"
" list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
" '-B -123.112,-123.110,42.100,42.101'.\n"
" -n: Longitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-n 42'.\n"
" -w: Latitude midpoint of extraction. Must use with '-s'\n"
" option. Example: '-w 123' (notice there is no minus\n"
" sign here).\n"
" -p: Lat/Lng midpoint of extraction. Must use with '-s'\n"
" option. Example: '-p -123,42'.\n"
" -s: Size of box (in degrees) around midpoint. Used with '-p'\n"
" and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
" If a rectangular size is requested, the first number refers\n"
" to the width of the box (along x; i.e. along lines of\n"
" latitude).\n"
" -T: Transpose and invert along y before printing the array\n"
" (so that a[i, j] gives longitude increasing with i and\n"
" latitude increasing with j).\n"
" -o: Output subgrid data to a file. Detects output format based\n"
" on file extension. Supported: (.png, .stl). For a .png\n"
" extension, see \"PNG output options\" below. Otherwise,\n"
" gridfloat will assume you want to save another GridFloat\n"
" file. In this case, it will write the appropriate data\n"
" and header files, appending .flt and .hdr, respectively,\n"
" to the argument of -o.\n"
"\n"
"PNG output options:\n"
" When png output is specified, gridfloat automatically renders\n"
" a shaded relief map. The following options determine which\n"
" slopes are sunny.\n"
"\n"
" -A: Azimuthal angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is East, 90 North, etc.\n"
" Default: 45 (NE).\n"
" -P: Polar angle (in degrees) of view toward sun (for\n"
" relief shading). 0 means sun is on horizon, 90 when\n"
" directly overhead. Default: 30.\n"
"\n"
"Examples:\n"
" All of the following are equivalent and simply print data\n"
" to stdout.\n"
"\n"
" gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
" gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
" gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
" gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
"\n",
1uLL,
0xC45uLL,
stdout);
}

original_code:
void print_usage(void) {
    fprintf(stdout,
        "Summary:\n"
        "  Extract subgrids of data from a GridFloat file. GridFloat\n"
        "  is a simple format commonly used by the USGS for packaging\n"
        "  elevation data. A header file with geolocation metadata is\n"
        "  required for making queries based on latitude/longitude.\n"
        "\n"
        "Usage:\n"
        "  gridfloat [options] FLOATFILE HEADERFILE\n"
        "  gridfloat [options] FLOAT_HEADER_PREFIX\n"
        "\n"
        "  where, for the first case, FLOATFILE should have\n"
        "  extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
        "  and FLOATFILE have the same filename prefix, then you\n"
        "  can use the second case.\n"
        "\n"
        "Options:\n"
        "  -h:  Print this help message.\n"
        "  -i:  Print helpful info derived from GridFloat header file.\n"
        "  -R:  Resolution of extraction. If a single integer is\n"
        "       supplied, then the resolution is the same in both\n"
        "       directions. Otherwise, the format is (by example):\n"
        "       '-R 128x256' where the first number is the resolution\n"
        "       in the x-direction (along lines of latitude).\n"
        "  -l:  Left bound for extraction.\n"
        "  -r:  Right bound for extraction.\n"
        "  -b:  Bottom bound for extraction.\n"
        "  -t:  Top bound for extraction.\n"
        "  -B:  Specify extraction bounds using a comma-separated\n"
        "       list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
        "       '-B -123.112,-123.110,42.100,42.101'.\n"
        "  -n:  Longitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-n 42'.\n"
        "  -w:  Latitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-w 123' (notice there is no minus\n"
        "       sign here).\n"
        "  -p:  Lat/Lng midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-p -123,42'.\n"
        "  -s:  Size of box (in degrees) around midpoint. Used with '-p'\n"
        "       and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
        "       If a rectangular size is requested, the first number refers\n"
        "       to the width of the box (along x; i.e. along lines of\n"
        "       latitude).\n"
        "  -T:  Transpose and invert along y before printing the array\n"
        "       (so that a[i, j] gives longitude increasing with i and\n"
        "       latitude increasing with j).\n"
        "  -o:  Output subgrid data to a file. Detects output format based\n"
        "       on file extension. Supported: (.png, .stl). For a .png\n"
        "       extension, see \"PNG output options\" below. Otherwise,\n"
        "       gridfloat will assume you want to save another GridFloat\n"
        "       file. In this case, it will write the appropriate data\n"
        "       and header files, appending .flt and .hdr, respectively,\n"
        "       to the argument of -o.\n"
        "\n"
        "PNG output options:\n"
        "  When png output is specified, gridfloat automatically renders\n"
        "  a shaded relief map. The following options determine which\n"
        "  slopes are sunny.\n"
        "\n"
        "  -A:  Azimuthal angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is East, 90 North, etc.\n"
        "       Default: 45 (NE).\n"
        "  -P:  Polar angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is on horizon, 90 when\n"
        "       directly overhead. Default: 30.\n"
        "\n"
        "Examples:\n"
        "  All of the following are equivalent and simply print data\n"
        "  to stdout.\n"
        "\n"
        "  gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
        "  gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
        "  gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
        "  gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
        "\n"
    );
}

canonical_original_code:
void print_usage() {
    fprintf(stdout,
        "Summary:\n"
        "  Extract subgrids of data from a GridFloat file. GridFloat\n"
        "  is a simple format commonly used by the USGS for packaging\n"
        "  elevation data. A header file with geolocation metadata is\n"
        "  required for making queries based on latitude/longitude.\n"
        "\n"
        "Usage:\n"
        "  gridfloat [options] FLOATFILE HEADERFILE\n"
        "  gridfloat [options] FLOAT_HEADER_PREFIX\n"
        "\n"
        "  where, for the first case, FLOATFILE should have\n"
        "  extension .flt and HEADERFILE .hdr. If both HEADERFILE\n"
        "  and FLOATFILE have the same filename prefix, then you\n"
        "  can use the second case.\n"
        "\n"
        "Options:\n"
        "  -h:  Print this help message.\n"
        "  -i:  Print helpful info derived from GridFloat header file.\n"
        "  -R:  Resolution of extraction. If a single integer is\n"
        "       supplied, then the resolution is the same in both\n"
        "       directions. Otherwise, the format is (by example):\n"
        "       '-R 128x256' where the first number is the resolution\n"
        "       in the x-direction (along lines of latitude).\n"
        "  -l:  Left bound for extraction.\n"
        "  -r:  Right bound for extraction.\n"
        "  -b:  Bottom bound for extraction.\n"
        "  -t:  Top bound for extraction.\n"
        "  -B:  Specify extraction bounds using a comma-separated\n"
        "       list of the form LEFT,RIGHT,BOTTOM,TOP. E.g.\n"
        "       '-B -123.112,-123.110,42.100,42.101'.\n"
        "  -n:  Longitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-n 42'.\n"
        "  -w:  Latitude midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-w 123' (notice there is no minus\n"
        "       sign here).\n"
        "  -p:  Lat/Lng midpoint of extraction. Must use with '-s'\n"
        "       option. Example: '-p -123,42'.\n"
        "  -s:  Size of box (in degrees) around midpoint. Used with '-p'\n"
        "       and '-n','-w' options. Examples: '-s 1.0x1.0' or just '-s 1'.\n"
        "       If a rectangular size is requested, the first number refers\n"
        "       to the width of the box (along x; i.e. along lines of\n"
        "       latitude).\n"
        "  -T:  Transpose and invert along y before printing the array\n"
        "       (so that a[i, j] gives longitude increasing with i and\n"
        "       latitude increasing with j).\n"
        "  -o:  Output subgrid data to a file. Detects output format based\n"
        "       on file extension. Supported: (.png, .stl). For a .png\n"
        "       extension, see \"PNG output options\" below. Otherwise,\n"
        "       gridfloat will assume you want to save another GridFloat\n"
        "       file. In this case, it will write the appropriate data\n"
        "       and header files, appending .flt and .hdr, respectively,\n"
        "       to the argument of -o.\n"
        "\n"
        "PNG output options:\n"
        "  When png output is specified, gridfloat automatically renders\n"
        "  a shaded relief map. The following options determine which\n"
        "  slopes are sunny.\n"
        "\n"
        "  -A:  Azimuthal angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is East, 90 North, etc.\n"
        "       Default: 45 (NE).\n"
        "  -P:  Polar angle (in degrees) of view toward sun (for\n"
        "       relief shading). 0 means sun is on horizon, 90 when\n"
        "       directly overhead. Default: 30.\n"
        "\n"
        "Examples:\n"
        "  All of the following are equivalent and simply print data\n"
        "  to stdout.\n"
        "\n"
        "  gridfloat -l -123 -r -122 -b 42 -t 43 file.{hdr,flt}\n"
        "  gridfloat -B -123,-122,42,43 file.{hdr,flt}\n"
        "  gridfloat -p -122.5,42.5 -s 1 file.{hdr,flt}\n"
        "  gridfloat -w 122.5 -n 42.5 -s 1x1 file.{hdr,flt}\n"
        "\n"
    );
}


original_code:
int gf_bilinear_interpolate_kernel(gf_float *quad, const gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    gf_float *dptr = (gf_float *)data_ptr;
    dptr[0] = (1.0 - w[0]) * (1.0 - w[1]) * quad[0] +
              (1.0 - w[0]) * w[1] * quad[1] +
                     w[0] * (1.0 - w[1]) * quad[2] +
                     w[0] * w[1] * quad[3];
    return 0;
}

canonical_original_code:
int gf_bilinear_interpolate_kernel(float *quad, struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    float *dptr = (gf_float *)data_ptr;
    dptr[0] = (1.0 - w[0]) * (1.0 - w[1]) * quad[0] +
              (1.0 - w[0]) * w[1] * quad[1] +
                     w[0] * (1.0 - w[1]) * quad[2] +
                     w[0] * w[1] * quad[3];
    return 0;
}

variable_types:
quad
float *

variable_types:
dptr
float *


original_code:
int gf_bilinear_gradient_kernel(gf_float *quad, const gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    double *grad_ptr = (double *)data_ptr;
    double dx_m = -1, dy_m = -1;
    gf_lengths(latlng[0], latlng[1], from_grid->dy, from_grid->dx, 0.0, &dy_m, &dx_m);
    grad_ptr[0] = (((1.0 - w[0]) * quad[1] + w[0] * quad[3]) -
                   ((1.0 - w[0]) * quad[0] + w[0] * quad[2])) / dx_m;
    grad_ptr[1] = (((1.0 - w[1]) * quad[0] + w[1] * quad[2]) -
                   ((1.0 - w[1]) * quad[1] + w[1] * quad[3])) / dy_m;
    return 0;
}

canonical_original_code:
int gf_bilinear_gradient_kernel(float *quad, struct gf_grid *from_grid, double *w, double *latlng, void *xtras, void *data_ptr) {
    double *grad_ptr = (double *)data_ptr;
    double dx_m = -1; double dy_m = -1;
    gf_lengths(latlng[0], latlng[1], from_grid->dy, from_grid->dx, 0.0, &dy_m, &dx_m);
    grad_ptr[0] = (((1.0 - w[0]) * quad[1] + w[0] * quad[3]) -
                   ((1.0 - w[0]) * quad[0] + w[0] * quad[2])) / dx_m;
    grad_ptr[1] = (((1.0 - w[1]) * quad[0] + w[1] * quad[2]) -
                   ((1.0 - w[1]) * quad[1] + w[1] * quad[3])) / dy_m;
    return 0;
}


original_code:
static
void calc_normal(float v1[3], float v2[3], float v3[3], float normal[3]) {
    int i;
    float vec1[3], vec2[3];
    float norm;
    for (i = 0; i < 3; i++) {
        vec1[i] = v2[i] - v1[i];
        vec2[i] = v3[i] - v1[i];
    }
    normal[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
    normal[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
    normal[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
    norm = sqrt(
        normal[0] * normal[0] +
        normal[1] * normal[1] +
        normal[2] * normal[2]);
    for (i = 0; i < 3; i++) {
        normal[i] /= norm;
    }
}

canonical_original_code:
static void calc_normal(float v1[3], float v2[3], float v3[3], float normal[3]) {
    int i;
    float vec1[3]; float vec2[3];
    float norm;
    for (i = 0; i < 3; i++) {
        vec1[i] = v2[i] - v1[i];
        vec2[i] = v3[i] - v1[i];
    }
    normal[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
    normal[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
    normal[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
    norm = sqrt(
        normal[0] * normal[0] +
        normal[1] * normal[1] +
        normal[2] * normal[2]);
    for (i = 0; i < 3; i++) {
        normal[i] /= norm;
    }
}

variable_types:
normal
float [3]

variable_types: norm float


repo: bblum/landslide

decompiled_code:
int __fastcall open_fifo(__int64 a1, const char *a2, int a3)
{
int result; // eax

*(_QWORD *)(a1 + 8) = a2;
result = open(a2, a3 | 0x80000);
*(_DWORD *)a1 = result;
if ( result < 0 )
_assert_fail("f->fd >= 0 && \"failed open fifo file\"", "io.c", 0x7Eu, "open_fifo");
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2, int a3)
{
int result; // eax

*(_QWORD *)(a1 + 8) = a2;
result = open(a2, a3 | 0x80000);
*(_DWORD *)a1 = result;
if ( result < 0 )
_assert_fail("f->fd >= 0 && \"failed open fifo file\"", "io.c", 0x7Eu, "open_fifo");
return result;
}

original_code:
void open_fifo(struct file *f, char *name, int flags)
{
 f->filename = name;
 f->fd = open(f->filename, flags | 02000000);
 ((f->fd >= 0 && "failed open fifo file") ? (void) (0) : __assert_fail ("f->fd >= 0 && \"failed open fifo file\"", "io.c", 126, __extension__ __PRETTY_FUNCTION__));
}

variable_types: struct file { int fd; char *filename; } *

variable_types:
name
char *

variable_types: flags int


decompiled_code:
int __fastcall unset_cloexec(int fd)
{
int v1; // eax
int result; // eax

v1 = fcntl(fd, 1);
if ( v1 == -1 )
_assert_fail("flags != -1 && \"couldn't get flags to unset cloexec\"", "io.c", 0x8Du, "unset_cloexec");
result = fcntl(fd, 2, v1 & 0xFFF7FFFF);
if ( result )
_assert_fail("result == 0 && \"couldn't set flags to unset cloexec\"", "io.c", 0x8Fu, "unset_cloexec");
return result;
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
int v1; // eax
int result; // eax

v1 = fcntl(fd, 1);
if ( v1 == -1 )
_assert_fail("flags != -1 && \"couldn't get flags to unset cloexec\"", "io.c", 0x8Du, "unset_cloexec");
result = fcntl(fd, 2, v1 & 0xFFF7FFFF);
if ( result )
_assert_fail("result == 0 && \"couldn't set flags to unset cloexec\"", "io.c", 0x8Fu, "unset_cloexec");
return result;
}

original_code:
void unset_cloexec(int fd)
{
 int flags = fcntl(fd, 1);
 ((flags != -1 && "couldn't get flags to unset cloexec") ? (void) (0) : __assert_fail ("flags != -1 && \"couldn't get flags to unset cloexec\"", "io.c", 141, __extension__ __PRETTY_FUNCTION__));
 int result = fcntl(fd, 2, flags & ~02000000);
 ((result == 0 && "couldn't set flags to unset cloexec") ? (void) (0) : __assert_fail ("result == 0 && \"couldn't set flags to unset cloexec\"", "io.c", 143, __extension__ __PRETTY_FUNCTION__));
}

variable_types: fd int

variable_types: result int


decompiled_code:
void log_msg(const char *a1, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2E0h] BYREF
char s[256]; // [rsp+20h] [rbp-2C8h] BYREF
char buf[256]; // [rsp+120h] [rbp-1C8h] BYREF

if ( logging_inited && logging_active )
{
va_start(arg, a2);
vsnprintf(s, 0x100uLL, a2, arg);
if ( a1 )
snprintf(buf, 0x100uLL, "[%s] %s", a1, s);
else
snprintf(buf, 0x100uLL, "%s", s);
v2 = strlen(buf);
if ( (int)write(log_file, buf, v2) < 0 )
fwrite("\x1B[01m\x1B[31mWARNING: couldn't write to log file\n", 1uLL, 0x2EuLL, stderr);
}
}

canonical_decompiled_code:
void func2(const char *a1, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2E0h] BYREF
char s[256]; // [rsp+20h] [rbp-2C8h] BYREF
char buf[256]; // [rsp+120h] [rbp-1C8h] BYREF

if ( logging_inited && logging_active )
{
va_start(arg, a2);
vsnprintf(s, 0x100uLL, a2, arg);
if ( a1 )
snprintf(buf, 0x100uLL, "[%s] %s", a1, s);
else
snprintf(buf, 0x100uLL, "%s", s);
v2 = strlen(buf);
if ( (int)write(log_file, buf, v2) < 0 )
fwrite("\x1B[01m\x1B[31mWARNING: couldn't write to log file\n", 1uLL, 0x2EuLL, stderr);
}
}

original_code:
void log_msg(const char *pfx, const char *format, ...)
{
 if (logging_inited && logging_active) {
  va_list ap;
  char line_buf[256];
  char line_buf2[256];
  __builtin_va_start(ap,format);
  vsnprintf(line_buf, 256, format, ap);
  __builtin_va_end(ap);
  if (pfx != ((void *)0)) {
   snprintf(line_buf2, 256, "[%s] %s", pfx, line_buf);
  } else {
   snprintf(line_buf2, 256, "%s", line_buf);
  }
  int ret = write(log_file.fd, line_buf2, strlen(line_buf2));
  if (ret < 0) {
   fprintf(stderr, "\033[01m" "\033[31m"
    "WARNING: couldn't write to log file\n");
  }
 }
}

canonical_original_code:
void log_msg(char *pfx, char *format, ...)
{
 if (logging_inited && logging_active) {
  __builtin_va_list ap;
  char line_buf[256];
  char line_buf2[256];
  __builtin_va_start(ap,format);
  vsnprintf(line_buf, 256, format, ap);
  __builtin_va_end(ap);
  if (pfx != ((void *)0)) {
   snprintf(line_buf2, 256, "[%s] %s", pfx, line_buf);
  } else {
   snprintf(line_buf2, 256, "%s", line_buf);
  }
  int ret = write(log_file.fd, line_buf2, strlen(line_buf2));
  if (ret < 0) {
   fprintf(stderr, "\033[01m" "\033[31m"
    "WARNING: couldn't write to log file\n");
  }
 }
}

variable_types:
pfx
char *

variable_types:
format
char *

variable_types: ret int


decompiled_code:
void __fastcall delete_file(unsigned int *a1, char a2)
{
int v2; // ebp
int *v3; // rax
int *v4; // r13
int v5; // ebp
char *v6; // rax
char *v7; // rax
int v8; // ebp
char *v9; // rax
char *v10; // rax

if ( !*((_QWORD *)a1 + 1) )
_assert_fail("f->filename != NULL", "io.c", 0x58u, "delete_file");
v2 = close(*a1);
v3 = _errno_location();
v4 = v3;
if ( v2 )
{
v5 = *v3;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed close fd %d\n", *a1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed close fd %d\n", *a1);
v6 = strerror(v5);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v6);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v7 = strerror(v5);
log_msg("ERR", "Error: %s\n", v7);
if ( !a2 )
goto LABEL_4;
}
else if ( !a2 )
{
goto LABEL_4;
}
if ( remove(*((const char **)a1 + 1)) )
{
v8 = *v4;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", *((const char **)a1 + 1));
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed remove '%s'\n", *((const char **)a1 + 1));
v9 = strerror(v8);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v9);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v10 = strerror(v8);
log_msg("ERR", "Error: %s\n", v10);
}
LABEL_4:
free(*((void **)a1 + 1));
*((_QWORD *)a1 + 1) = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(unsigned int *a1, char a2)
{
int v2; // ebp
int *v3; // rax
int *v4; // r13
int v5; // ebp
char *v6; // rax
char *v7; // rax
int v8; // ebp
char *v9; // rax
char *v10; // rax

if ( !*((_QWORD *)a1 + 1) )
_assert_fail("f->filename != NULL", "io.c", 0x58u, "delete_file");
v2 = close(*a1);
v3 = _errno_location();
v4 = v3;
if ( v2 )
{
v5 = *v3;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed close fd %d\n", *a1);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed close fd %d\n", *a1);
v6 = strerror(v5);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v6);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v7 = strerror(v5);
func2("ERR", "Error: %s\n", v7);
if ( !a2 )
goto LABEL_4;
}
else if ( !a2 )
{
goto LABEL_4;
}
if ( remove(*((const char **)a1 + 1)) )
{
v8 = *v4;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", *((const char **)a1 + 1));
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed remove '%s'\n", *((const char **)a1 + 1));
v9 = strerror(v8);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v9);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v10 = strerror(v8);
func2("ERR", "Error: %s\n", v10);
}
LABEL_4:
free(*((void **)a1 + 1));
*((_QWORD *)a1 + 1) = 0LL;
}

original_code:
void delete_file(struct file *f, _Bool do_remove)
{
 ((f->filename != ((void *)0)) ? (void) (0) : __assert_fail ("f->filename != NULL", "io.c", 88, __extension__ __PRETTY_FUNCTION__));
 do { int __ret = close(f->fd); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed close fd %d\n", f->fd); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed close fd %d\n", f->fd); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 if (do_remove) {
  do { int __ret = remove(f->filename); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed remove '%s'\n", (f->filename)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed remove '%s'\n", (f->filename)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 }
 free(f->filename);
 f->filename = ((void *)0);
}


decompiled_code:
char *__fastcall create_fifo(const char *a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // ebx
int *v4; // rax
int *v5; // rbp
int v6; // eax
int v7; // er13
int v8; // ebx
char *v9; // r12
int v10; // eax
int v11; // ebp
char *v12; // rax
char *v13; // rax
char *v15; // rax
char *v16; // rax
int v17; // er15
char *v18; // rax
char *v19; // rax
char v20[312]; // [rsp+0h] [rbp-138h] BYREF

v2 = timestamp();
snprintf(v20, 0x100uLL, "/dev/shm/%s-%u-%lu.fifo", a1, a2, v2);
v3 = mkfifo(v20, 0x1C0u);
v4 = _errno_location();
v5 = v4;
if ( v3 )
{
v15 = strerror(*v4);
fprintf(stderr, "\x1B[01m\x1B[31mfailed to create a fifo file for communication with landslide: %s\n", v15);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v16 = strerror(*v5);
log_msg("ERR", "failed to create a fifo file for communication with landslide: %s\n", v16);
_assert_fail("ret == 0 && \"failed create fifo file\"", "io.c", 0x72u, "create_fifo");
}
v6 = strlen(v20);
v7 = v6 + 1;
v8 = v6;
v9 = (char *)malloc(v6 + 1);
if ( !v9 )
{
v17 = *v5;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "malloc failed");
v18 = strerror(v17);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v18);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v19 = strerror(v17);
log_msg("ERR", "Error: %s\n", v19);
}
v10 = snprintf(v9, v7, "%s", v20);
if ( v7 <= v10 )
v10 = v7;
if ( v10 != v8 )
{
v11 = *v5;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[01m\x1B[31mscprintf failed", 1uLL, 0x19uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "scprintf failed");
v12 = strerror(v11);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v12);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v13 = strerror(v11);
log_msg("ERR", "Error: %s\n", v13);
}
return v9;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // ebx
int *v4; // rax
int *v5; // rbp
int v6; // eax
int v7; // er13
int v8; // ebx
char *v9; // r12
int v10; // eax
int v11; // ebp
char *v12; // rax
char *v13; // rax
char *v15; // rax
char *v16; // rax
int v17; // er15
char *v18; // rax
char *v19; // rax
char v20[312]; // [rsp+0h] [rbp-138h] BYREF

v2 = timestamp();
snprintf(v20, 0x100uLL, "/dev/shm/%s-%u-%lu.fifo", a1, a2, v2);
v3 = mkfifo(v20, 0x1C0u);
v4 = _errno_location();
v5 = v4;
if ( v3 )
{
v15 = strerror(*v4);
fprintf(stderr, "\x1B[01m\x1B[31mfailed to create a fifo file for communication with landslide: %s\n", v15);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v16 = strerror(*v5);
func2("ERR", "failed to create a fifo file for communication with landslide: %s\n", v16);
_assert_fail("ret == 0 && \"failed create fifo file\"", "io.c", 0x72u, "create_fifo");
}
v6 = strlen(v20);
v7 = v6 + 1;
v8 = v6;
v9 = (char *)malloc(v6 + 1);
if ( !v9 )
{
v17 = *v5;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "malloc failed");
v18 = strerror(v17);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v18);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v19 = strerror(v17);
func2("ERR", "Error: %s\n", v19);
}
v10 = snprintf(v9, v7, "%s", v20);
if ( v7 <= v10 )
v10 = v7;
if ( v10 != v8 )
{
v11 = *v5;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == __len");
fwrite("\x1B[01m\x1B[31mscprintf failed", 1uLL, 0x19uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "scprintf failed");
v12 = strerror(v11);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v12);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v13 = strerror(v11);
func2("ERR", "Error: %s\n", v13);
}
return v9;
}

original_code:
char *create_fifo(const char *prefix, unsigned int id)
{
 char buf[256];
 ({ int __snprintf_ret = snprintf((buf), (256), "/dev/shm/" "%s-%u-%lu.fifo", prefix, id, timestamp()); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
 int ret = mkfifo(buf, 0700);
 if (ret != 0) {
  do { fprintf(stderr, "\033[01m" "\033[31m" "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); } while (0);
 }
 ((ret == 0 && "failed create fifo file") ? (void) (0) : __assert_fail ("ret == 0 && \"failed create fifo file\"", "io.c", 114, __extension__ __PRETTY_FUNCTION__));
 return ({ char *__s = (buf); __s == ((void *)0) ? ((void *)0) : ({ int __len = strlen(__s); char *__buf = ({ __typeof__(char) *__xmalloc_ptr = malloc((__len + 1) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; }); int __ret = ({ int __snprintf_ret = snprintf((__buf), (__len + 1), "%s", __s); if (__snprintf_ret > (int)(__len + 1)) { __snprintf_ret = (__len + 1); } __snprintf_ret; }); do { int __last_errno = (*__errno_location ()); if (!(__ret == __len)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == __len"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == __len"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "scprintf failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "scprintf failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __buf; }); });
}

canonical_original_code:
char *create_fifo(char *prefix, unsigned int id)
{
 char buf[256];
 ({ int __snprintf_ret = snprintf((buf), (256), "/dev/shm/" "%s-%u-%lu.fifo", prefix, id, timestamp()); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
 int ret = mkfifo(buf, 0700);
 if (ret != 0) {
  do { fprintf(stderr, "\033[01m" "\033[31m" "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed to create a fifo file for communication with " "landslide: %s\n", strerror((*__errno_location ()))); } while (0);
 }
 ((ret == 0 && "failed create fifo file") ? (void) (0) : __assert_fail ("ret == 0 && \"failed create fifo file\"", "io.c", 114, __extension__ __PRETTY_FUNCTION__));
 return ({ char *__s = (buf); __s == ((void *)0) ? ((void *)0) : ({ int __len = strlen(__s); char *__buf = ({ __typeof__(char) *__xmalloc_ptr = malloc((__len + 1) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; }); int __ret = ({ int __snprintf_ret = snprintf((__buf), (__len + 1), "%s", __s); if (__snprintf_ret > (int)(__len + 1)) { __snprintf_ret = (__len + 1); } __snprintf_ret; }); do { int __last_errno = (*__errno_location ()); if (!(__ret == __len)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == __len"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == __len"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "scprintf failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "scprintf failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __buf; }); });
}

variable_types:
prefix
char *

variable_types:
id
unsigned int

variable_types:
buf
char [256]


decompiled_code:
void __fastcall delete_unused_fifo(void *ptr)
{
int v1; // er12
char *v2; // rax
char *v3; // rax

if ( remove((const char *)ptr) )
{
v1 = *_errno_location();
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", (const char *)ptr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed remove '%s'\n", (const char *)ptr);
v2 = strerror(v1);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v3 = strerror(v1);
log_msg("ERR", "Error: %s\n", v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
int v1; // er12
char *v2; // rax
char *v3; // rax

if ( remove((const char *)ptr) )
{
v1 = *_errno_location();
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed remove '%s'\n", (const char *)ptr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed remove '%s'\n", (const char *)ptr);
v2 = strerror(v1);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v2);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v3 = strerror(v1);
func2("ERR", "Error: %s\n", v3);
}
free(ptr);
}

original_code:
void delete_unused_fifo(char *name)
{
 do { int __ret = remove(name); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed remove '%s'\n", (name)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed remove '%s'\n", (name)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 free(name);
}


decompiled_code:
void __fastcall move_file_to(__int64 a1, const char *a2)
{
const char *v2; // r14
int v3; // ebp
size_t v4; // r15
char *v5; // rbp
int *v6; // rax
int *v7; // r13
int v8; // er12
char *v9; // rax
char *v10; // rax
int v11; // er14
char *v12; // rax
char *v13; // rax

v2 = *(const char **)(a1 + 8);
v3 = strlen(v2);
v4 = v3 + (unsigned int)strlen(a2) + 2;
v5 = (char *)malloc(v4);
v6 = _errno_location();
v7 = v6;
if ( !v5 )
{
v11 = *v6;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "malloc failed");
v12 = strerror(v11);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v12);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v13 = strerror(v11);
log_msg("ERR", "Error: %s\n", v13);
v2 = *(const char **)(a1 + 8);
}
snprintf(v5, v4, "%s/%s", a2, v2);
if ( rename(*(const char **)(a1 + 8), v5) )
{
v8 = *v7;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v5);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
log_msg("ERR", "failed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v5);
v9 = strerror(v8);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v9);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v10 = strerror(v8);
log_msg("ERR", "Error: %s\n", v10);
}
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = v5;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, const char *a2)
{
const char *v2; // r14
int v3; // ebp
size_t v4; // r15
char *v5; // rbp
int *v6; // rax
int *v7; // r13
int v8; // er12
char *v9; // rax
char *v10; // rax
int v11; // er14
char *v12; // rax
char *v13; // rax

v2 = *(const char **)(a1 + 8);
v3 = strlen(v2);
v4 = v3 + (unsigned int)strlen(a2) + 2;
v5 = (char *)malloc(v4);
v6 = _errno_location();
v7 = v6;
if ( !v5 )
{
v11 = *v6;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL");
fwrite("\x1B[01m\x1B[31mmalloc failed", 1uLL, 0x17uLL, stderr);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "malloc failed");
v12 = strerror(v11);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v12);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v13 = strerror(v11);
func2("ERR", "Error: %s\n", v13);
v2 = *(const char **)(a1 + 8);
}
snprintf(v5, v4, "%s/%s", a2, v2);
if ( rename(*(const char **)(a1 + 8), v5) )
{
v8 = *v7;
fprintf(stderr, "\x1B[01m\x1B[31mAssertion failed: '%s'\n", "__ret == 0");
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "Assertion failed: '%s'\n", "__ret == 0");
fprintf(stderr, "\x1B[01m\x1B[31mfailed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v5);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
func2("ERR", "failed rename '%s' to '%s'\n", *(const char **)(a1 + 8), v5);
v9 = strerror(v8);
fprintf(stderr, "\x1B[01m\x1B[31mError: %s\n", v9);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
v10 = strerror(v8);
func2("ERR", "Error: %s\n", v10);
}
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = v5;
}

original_code:
void move_file_to(struct file *f, const char *dirpath)
{
 unsigned int length = strlen(f->filename) + strlen(dirpath) + 2;
 char *new_filename = ({ __typeof__(char) *__xmalloc_ptr = malloc((length) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; });
 ({ int __snprintf_ret = snprintf((new_filename), (length), "%s/%s", dirpath, f->filename); if (__snprintf_ret > (int)(length)) { __snprintf_ret = (length); } __snprintf_ret; });
 do { int __ret = rename((f->filename), (new_filename)); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 free(f->filename);
 f->filename = new_filename;
}

canonical_original_code:
void move_file_to(struct file *f, char *dirpath)
{
 unsigned int length = strlen(f->filename) + strlen(dirpath) + 2;
 char *new_filename = ({ __typeof__(char) *__xmalloc_ptr = malloc((length) * sizeof(char)); do { int __last_errno = (*__errno_location ()); if (!(__xmalloc_ptr != ((void *)0))) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__xmalloc_ptr != NULL"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "malloc failed"); fprintf(stderr, "\033[00m"); log_msg("ERR", "malloc failed"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); __xmalloc_ptr; });
 ({ int __snprintf_ret = snprintf((new_filename), (length), "%s/%s", dirpath, f->filename); if (__snprintf_ret > (int)(length)) { __snprintf_ret = (length); } __snprintf_ret; });
 do { int __ret = rename((f->filename), (new_filename)); do { int __last_errno = (*__errno_location ()); if (!(__ret == 0)) { do { fprintf(stderr, "\033[01m" "\033[31m" "Assertion failed: '%s'\n", "__ret == 0"); fprintf(stderr, "\033[00m"); log_msg("ERR", "Assertion failed: '%s'\n", "__ret == 0"); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); fprintf(stderr, "\033[00m"); log_msg("ERR", "failed rename '%s' to '%s'\n", (f->filename), (new_filename)); } while (0); do { fprintf(stderr, "\033[01m" "\033[31m" "Error: %s\n", strerror(__last_errno)); fprintf(stderr, "\033[00m"); log_msg("ERR", "Error: %s\n", strerror(__last_errno)); } while (0); } } while (0); } while (0);
 free(f->filename);
 f->filename = new_filename;
}

variable_types:
dirpath
char *

variable_types:
length
unsigned int


decompiled_code:
void __fastcall set_logging_options(char a1, const char *a2, const char *a3)
{
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

if ( logging_inited )
_assert_fail("!logging_inited && \"double log init\"", "io.c", 0xA4u, "set_logging_options");
logging_inited = 1;
logging_active = a1;
if ( a1 )
{
snprintf(v4, 0x100uLL, "%s.XXXXXX", a2);
create_file((__int64)&log_file, v4);
if ( *a3 )
move_file_to((__int64)&log_file, a3);
}
}

canonical_decompiled_code:
void __fastcall func8(char a1, const char *a2, const char *a3)
{
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

if ( logging_inited )
_assert_fail("!logging_inited && \"double log init\"", "io.c", 0xA4u, "set_logging_options");
logging_inited = 1;
logging_active = a1;
if ( a1 )
{
snprintf(v4, 0x100uLL, "%s.XXXXXX", a2);
func3((__int64)&log_file, v4);
if ( *a3 )
func7((__int64)&log_file, a3);
}
}

original_code:
void set_logging_options(_Bool use_log, char *filename, const char *log_dir)
{
 ((!logging_inited && "double log init") ? (void) (0) : __assert_fail ("!logging_inited && \"double log init\"", "io.c", 164, __extension__ __PRETTY_FUNCTION__));
 logging_inited = 1;
 if ((logging_active = use_log)) {
  char log_filename[256];
  ({ int __snprintf_ret = snprintf((log_filename), (256), "%s.XXXXXX", filename); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
  create_file(&log_file, log_filename);
  if (log_dir[0] != 0) {
   move_file_to(&log_file, log_dir);
  }
 }
}

canonical_original_code:
void set_logging_options(_Bool use_log, char *filename, char *log_dir)
{
 ((!logging_inited && "double log init") ? (void) (0) : __assert_fail ("!logging_inited && \"double log init\"", "io.c", 164, __extension__ __PRETTY_FUNCTION__));
 logging_inited = 1;
 if ((logging_active = use_log)) {
  char log_filename[256];
  ({ int __snprintf_ret = snprintf((log_filename), (256), "%s.XXXXXX", filename); if (__snprintf_ret > (int)(256)) { __snprintf_ret = (256); } __snprintf_ret; });
  create_file(&log_file, log_filename);
  if (log_dir[0] != 0) {
   move_file_to(&log_file, log_dir);
  }
 }
}

variable_types:
filename
char *


decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rsi
unsigned __int64 v12; // rdi
unsigned __int64 v13; // r12
unsigned __int64 v14; // rbx
unsigned __int64 v15; // rax
unsigned __int64 v16; // r13
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
const char *v22; // rbp
unsigned __int8 v23; // [rsp+2Ah] [rbp-37Eh]
unsigned __int8 v24; // [rsp+2Bh] [rbp-37Dh]
unsigned __int8 v25; // [rsp+2Ch] [rbp-37Ch]
unsigned __int8 v26; // [rsp+2Dh] [rbp-37Bh]
unsigned __int8 v27; // [rsp+2Eh] [rbp-37Ah]
unsigned __int8 v28; // [rsp+2Fh] [rbp-379h]
unsigned __int8 v29; // [rsp+30h] [rbp-378h]
unsigned __int8 v30; // [rsp+31h] [rbp-377h]
unsigned __int8 v31; // [rsp+32h] [rbp-376h]
unsigned __int8 v32; // [rsp+33h] [rbp-375h]
unsigned __int8 v33; // [rsp+34h] [rbp-374h]
unsigned __int8 v34; // [rsp+35h] [rbp-373h]
unsigned __int8 v35; // [rsp+36h] [rbp-372h]
unsigned __int8 v36; // [rsp+37h] [rbp-371h]
__int64 v37; // [rsp+38h] [rbp-370h] BYREF
unsigned __int64 v38; // [rsp+40h] [rbp-368h]
__int64 v39; // [rsp+48h] [rbp-360h]
char v40[48]; // [rsp+50h] [rbp-358h] BYREF
char haystack[256]; // [rsp+80h] [rbp-328h] BYREF
char v42[256]; // [rsp+180h] [rbp-228h] BYREF
char v43[296]; // [rsp+280h] [rbp-128h] BYREF

if ( !(unsigned __int8)get_options(*(_QWORD *)&argc, argv, haystack, "core saturation: %lu%%)\n", &v37) )
{
v22 = *argv;
if ( !strcmp(*argv, "./landslide-id") )
v22 = "./landslide";
usage(v22);
exit(2);
}
set_logging_options(v25, v43, v42);
if ( v23 )
{
fprintf(stderr, "\x1B[00m\x1B[36mwill run for at most %lu seconds\n", v37);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
}
log_msg("DBG", "will run for at most %lu seconds\n", v37);
set_job_options(haystack, v42, v23, v24, v26, v28, v29, v30, v31, v32, v33, v34, v35, v36, v27);
init_signal_handling();
start_time(1000000 * v37, (unsigned int)v38);
if ( !control_experiment && !v36 && haystack != strstr(haystack, "atomic_") )
{
v3 = create_pp_set(0LL);
v4 = new_job(v3, 0LL);
add_work(v4);
v5 = create_pp_set(4LL);
v6 = new_job(v5, 1LL);
add_work(v6);
v7 = create_pp_set(8LL);
v8 = new_job(v7, 1LL);
add_work(v8);
if ( (unsigned __int8)testing_pintos() )
{
v18 = create_pp_set(16LL);
v19 = new_job(v18, 1LL);
add_work(v19);
v20 = create_pp_set(32LL);
v21 = new_job(v20, 1LL);
add_work(v21);
}
}
v9 = create_pp_set(60LL);
v10 = new_job(v9, 1LL);
add_work(v10);
v11 = v39;
v12 = v38;
start_work(v38, v39);
wait_to_finish_work();
print_live_data_race_pps();
print_free_re_malloc_false_positives();
v13 = total_cpu_time();
v14 = 25 * (v13 / v38);
v15 = time_elapsed(v12, v11, v13 % v38);
v16 = 4 * v14 / v15;
human_friendly_time(v40, v11, 4 * v14 % v15);
printf("\x1B[01m\x1B[36mtotal CPU time consumed: ");
printf("\x1B[00m");
log_msg(0LL, "total CPU time consumed: ");
print_human_friendly_time(v40);
printf("\x1B[01m\x1B[36m (%lu usecs) (core saturation: %lu%%)\n", v13, v16);
printf("\x1B[00m");
log_msg(0LL, " (%lu usecs) (core saturation: %lu%%)\n", v13, v16);
return (unsigned __int8)found_any_bugs();
}

original_code:
int main(int argc, char **argv)
{
 char test_name[256];
 char trace_dir[256];
 unsigned long max_time;
 unsigned long num_cpus;
 _Bool verbose;
 _Bool leave_logs;
 _Bool use_wrapper_log;
 char wrapper_log[256];
 _Bool pintos;
 _Bool pathos;
 _Bool use_icb;
 _Bool preempt_everywhere;
 _Bool pure_hb;
 _Bool txn;
 _Bool txn_abort_codes;
 _Bool txn_dont_retry;
 _Bool txn_retry_sets;
 _Bool txn_weak_atomicity;
 _Bool verif_mode;
 unsigned long progress_interval;
 if (!get_options(argc, argv, test_name, 256, &max_time, &num_cpus,
    &verbose, &leave_logs, &control_experiment,
    &use_wrapper_log, wrapper_log, 256, &pintos,
    &use_icb, &preempt_everywhere, &pure_hb,
    &avoid_recompile,
    &txn, &txn_abort_codes, &txn_dont_retry,
    &txn_retry_sets, &txn_weak_atomicity,
    &verif_mode, &pathos, &progress_interval,
    trace_dir, 256, &eta_factor, &eta_threshold)) {
  usage(strcmp(argv[0], "./landslide-id") == 0 ? "./landslide" : argv[0]);
  exit(2);
 }
 set_logging_options(use_wrapper_log, wrapper_log, trace_dir);
 do { if (verbose) { fprintf(stderr, "\033[00m" "\033[36m" "will run for at most %lu seconds\n", max_time); fprintf(stderr, "\033[00m"); } log_msg("DBG", "will run for at most %lu seconds\n", max_time); } while (0);
 set_job_options(test_name, trace_dir, verbose, leave_logs, pintos, use_icb, preempt_everywhere, pure_hb, txn, txn_abort_codes, txn_dont_retry, txn_retry_sets, txn_weak_atomicity, verif_mode, pathos);
 init_signal_handling();
 start_time(max_time * 1000000, num_cpus);
 if (!control_experiment && !verif_mode &&
     !(strstr(test_name, "atomic_") == test_name)) {
  add_work(new_job(create_pp_set(((unsigned int)0x00)), 0));
  add_work(new_job(create_pp_set(((unsigned int)0x04)), 1));
  add_work(new_job(create_pp_set(((unsigned int)0x08)), 1));
  if (testing_pintos()) {
   add_work(new_job(create_pp_set(((unsigned int)0x10)), 1));
   add_work(new_job(create_pp_set(((unsigned int)0x20)), 1));
  }
 }
 add_work(new_job(create_pp_set(((unsigned int)0x04) | ((unsigned int)0x08) | ((unsigned int)0x10) | ((unsigned int)0x20)), 1));
 start_work(num_cpus, progress_interval);
 wait_to_finish_work();
 print_live_data_race_pps();
 print_free_re_malloc_false_positives();
 unsigned long cputime = total_cpu_time();
 unsigned long saturation = (cputime / num_cpus) * 100 / time_elapsed();
 struct human_friendly_time cputime_hft;
 human_friendly_time(cputime, &cputime_hft);
 do { printf("\033[01m" "\033[36m" "total CPU time consumed: "); printf("\033[00m"); log_msg(((void *)0), "total CPU time consumed: "); } while (0);
 print_human_friendly_time(&cputime_hft);
 do { printf("\033[01m" "\033[36m" " (%lu usecs) (core saturation: %lu%%)\n", cputime, saturation); printf("\033[00m"); log_msg(((void *)0), " (%lu usecs) (core saturation: %lu%%)\n", cputime, saturation); } while (0);
 return found_any_bugs() ? 1 : 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
cputime
unsigned long

variable_types:
saturation
unsigned long

variable_types: struct human_friendly_time { unsigned long secs; _Bool inf; }