decompiled_code:
unsigned __int64 __fastcall log_from_worker(__int64 a1, unsigned int *a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdx
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
v2 = *(_QWORD *)(a1 + 8);
if ( v2 <= 0xF )
{
kore_log(5u, (__int64)"too short worker log received (%zu < %zu)", v2, 0x10uLL);
}
else
{
v3 = kore_worker_name(*((unsigned __int16 *)a2 + 2));
if ( !kore_foreground && fp == stdout )
_syslog_chk(*a2, 1LL, "proc=%s log=[%.*s]", v3, a2[2], a2 + 4);
else
log_print(*a2, (__int64)"proc=%s log=[%.*s]\n", v3, a2[2], a2 + 4);
}
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, unsigned int *a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdx
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
v2 = *(_QWORD *)(a1 + 8);
if ( v2 <= 0xF )
{
func3(5u, (__int64)"too short worker log received (%zu < %zu)", v2, 0x10uLL);
}
else
{
v3 = kore_worker_name(*((unsigned __int16 *)a2 + 2));
if ( !kore_foreground && fp == stdout )
_syslog_chk(*a2, 1LL, "proc=%s log=[%.*s]", v3, a2[2], a2 + 4);
else
func0(*a2, (__int64)"proc=%s log=[%.*s]\n", v3, a2[2], a2 + 4);
}
return v5 - __readfsqword(0x28u);
}

original_code:
static void
log_from_worker(struct kore_msg *msg, const void *data)
{
 const char *name;
 const struct kore_wlog *wlog;
 if (msg->length < sizeof(*wlog)) {
  kore_log(5,
      "too short worker log received (%zu < %zu)",
      msg->length, sizeof(*wlog));
  return;
 }
 wlog = data;
 name = kore_worker_name(wlog->wid);
 if (kore_foreground || fp != stdout) {
  log_print(wlog->prio, "proc=%s log=[%.*s]\n",
      name, (int)wlog->loglen, wlog->logmsg);
 } else {
  syslog(wlog->prio, "proc=%s log=[%.*s]",
      name, (int)wlog->loglen, wlog->logmsg);
 }
}

canonical_original_code:
static void log_from_worker(struct kore_msg *msg, void *data)
{
 char *name;
 struct kore_wlog *wlog;
 if (msg->length < sizeof(*wlog)) {
  kore_log(5,
      "too short worker log received (%zu < %zu)",
      msg->length, sizeof(*wlog));
  return;
 }
 wlog = data;
 name = kore_worker_name(wlog->wid);
 if (kore_foreground || fp != stdout) {
  log_print(wlog->prio, "proc=%s log=[%.*s]\n",
      name, (int)wlog->loglen, wlog->logmsg);
 } else {
  syslog(wlog->prio, "proc=%s log=[%.*s]",
      name, (int)wlog->loglen, wlog->logmsg);
 }
}

variable_types: struct kore_msg { unsigned int id; unsigned int src; unsigned int dst; unsigned long length; } *

variable_types:
data
void *

variable_types: struct kore_wlog { int prio; unsigned int wid; unsigned long loglen; char logmsg[]; } *


repo: jorisvink/kore

decompiled_code:
unsigned __int64 __fastcall websocket_frame_build(__int64 a1, char a2, __int64 a3, unsigned __int64 a4)
{
char v7[17]; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned __int8 v8; // [rsp+1Dh] [rbp-2Bh] BYREF
char v9[2]; // [rsp+1Eh] [rbp-2Ah] BYREF
char v10[8]; // [rsp+20h] [rbp-28h] BYREF
unsigned __int64 v11; // [rsp+28h] [rbp-20h]

v7[0] = a2;
v11 = __readfsqword(0x28u);
if ( a4 <= 0x7D )
v8 = a4;
else
v8 = (a4 > 0xFFFF) + 126;
v7[0] |= 0x80u;
kore_buf_append(a1, v7, 1LL);
v8 &= 0x7Fu;
kore_buf_append(a1, &v8, 1LL);
if ( v8 > 0x7Du )
{
if ( v8 == 126 )
{
net_write16(v9, (unsigned __int16)a4);
kore_buf_append(a1, v9, 2LL);
}
else if ( v8 == 127 )
{
net_write64(v10, a4);
kore_buf_append(a1, v10, 8LL);
}
}
if ( a3 && a4 )
kore_buf_append(a1, a3, a4);
return v11 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, char a2, __int64 a3, unsigned __int64 a4)
{
char v7[17]; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned __int8 v8; // [rsp+1Dh] [rbp-2Bh] BYREF
char v9[2]; // [rsp+1Eh] [rbp-2Ah] BYREF
char v10[8]; // [rsp+20h] [rbp-28h] BYREF
unsigned __int64 v11; // [rsp+28h] [rbp-20h]

v7[0] = a2;
v11 = __readfsqword(0x28u);
if ( a4 <= 0x7D )
v8 = a4;
else
v8 = (a4 > 0xFFFF) + 126;
v7[0] |= 0x80u;
kore_buf_append(a1, v7, 1LL);
v8 &= 0x7Fu;
kore_buf_append(a1, &v8, 1LL);
if ( v8 > 0x7Du )
{
if ( v8 == 126 )
{
net_write16(v9, (unsigned __int16)a4);
kore_buf_append(a1, v9, 2LL);
}
else if ( v8 == 127 )
{
net_write64(v10, a4);
kore_buf_append(a1, v10, 8LL);
}
}
if ( a3 && a4 )
kore_buf_append(a1, a3, a4);
return v11 - __readfsqword(0x28u);
}

original_code:
static void
websocket_frame_build(struct kore_buf *frame, u_int8_t op, const void *data,
    size_t len)
{
 u_int8_t len_1;
 u_int16_t len16;
 u_int64_t len64;
 if (len > 125) {
  if (len <= (0x7fff * 2 + 1))
   len_1 = 126;
  else
   len_1 = 127;
 } else {
  len_1 = len;
 }
 op |= (1 << 7);
 kore_buf_append(frame, &op, sizeof(op));
 len_1 &= ~(1 << 7);
 kore_buf_append(frame, &len_1, sizeof(len_1));
 if (len_1 > 125) {
  switch (len_1) {
  case 126:
   net_write16((u_int8_t *)&len16, len);
   kore_buf_append(frame, &len16, sizeof(len16));
   break;
  case 127:
   net_write64((u_int8_t *)&len64, len);
   kore_buf_append(frame, &len64, sizeof(len64));
   break;
  }
 }
 if (data != ((void *)0) && len > 0)
  kore_buf_append(frame, data, len);
}

canonical_original_code:
static void websocket_frame_build(struct kore_buf *frame, unsigned int op, void *data, unsigned long len)
{
 unsigned int len_1;
 unsigned int len16;
 unsigned int len64;
 if (len > 125) {
  if (len <= (0x7fff * 2 + 1))
   len_1 = 126;
  else
   len_1 = 127;
 } else {
  len_1 = len;
 }
 op |= (1 << 7);
 kore_buf_append(frame, &op, sizeof(op));
 len_1 &= ~(1 << 7);
 kore_buf_append(frame, &len_1, sizeof(len_1));
 if (len_1 > 125) {
  switch (len_1) {
  case 126:
   net_write16((unsigned int *)&len16, len);
   kore_buf_append(frame, &len16, sizeof(len16));
   break;
  case 127:
   net_write64((unsigned int *)&len64, len);
   kore_buf_append(frame, &len64, sizeof(len64));
   break;
  }
 }
 if (data != ((void *)0) && len > 0)
  kore_buf_append(frame, data, len);
}

variable_types: struct kore_buf { unsigned int *data; int flags; unsigned long length; unsigned long offset; } *

variable_types:
op
unsigned int

variable_types:
len
unsigned long

return_type: void


decompiled_code:
unsigned __int64 kore_auth_init()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
auth_list = 0LL;
*(&auth_list + 1) = (__int64)&auth_list;
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func0()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
auth_list = 0LL;
*(&auth_list + 1) = (__int64)&auth_list;
return v1 - __readfsqword(0x28u);
}

original_code:
void
kore_auth_init(void)
{
 do { (&auth_list)->tqh_first = ((void *)0); (&auth_list)->tqh_last = &(&auth_list)->tqh_first; } while ( 0);
}

canonical_original_code:
void kore_auth_init()
{
 do { (&auth_list)->tqh_first = ((void *)0); (&auth_list)->tqh_last = &(&auth_list)->tqh_first; } while ( 0);
}


decompiled_code:
unsigned __int64 kore_module_init()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
modules = 0LL;
qword_698 = (__int64)&modules;
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func4()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
modules = 0LL;
qword_698 = (__int64)&modules;
return v1 - __readfsqword(0x28u);
}

original_code:
void
kore_module_init(void)
{
 do { (&modules)->tqh_first = ((void *)0); (&modules)->tqh_last = &(&modules)->tqh_first; } while ( 0);
}

canonical_original_code:
void kore_module_init()
{
 do { (&modules)->tqh_first = ((void *)0); (&modules)->tqh_last = &(&modules)->tqh_first; } while ( 0);
}


decompiled_code:
_BOOL8 kore_module_loaded()
{
return modules != 0;
}

canonical_decompiled_code:
_BOOL8 func9()
{
return modules != 0;
}

original_code:
int
kore_module_loaded(void)
{
 if (((&modules)->tqh_first == ((void *)0)))
  return (0);
 return (1);
}

canonical_original_code:
int kore_module_loaded()
{
 if (((&modules)->tqh_first == ((void *)0)))
  return (0);
 return (1);
}

return_type: int


usage

decompiled_code:
size_t usage()
{
return fwrite("usage: caches [-d] cache-descriptions-file memory-trace-file\n", 1uLL, 0x3EuLL, stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite("usage: caches [-d] cache-descriptions-file memory-trace-file\n", 1uLL, 0x3EuLL, stderr);
}

original_code:
void usage(void)
{
    fprintf (stderr,"usage: caches [-d] cache-descriptions-file  memory-trace-file\n");
}

canonical_original_code:
void usage()
{
    fprintf (stderr,"usage: caches [-d] cache-descriptions-file  memory-trace-file\n");
}


scanargs

decompiled_code:
__int64 __fastcall scanargs(__int64 a1)
{
unsigned __int8 *v1; // rbx
__int64 result; // rax

v1 = (unsigned __int8 *)(a1 + 1);
for ( result = *(unsigned __int8 *)(a1 + 1); (_BYTE)result; result = *v1 )
{
if ( (_BYTE)result != 68 )
{
fprintf(stderr, "caches: Bad option %c\n", (unsigned int)(char)result);
usage();
exit(1);
}
debug = 1;
debug_file = (__int64)fopen("DEBUG_LOG", "w");
if ( !debug_file )
{
fwrite("Cannot open DEBUG_LOG\n", 1uLL, 0x16uLL, stderr);
debug = 0;
}
++v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned __int8 *v1; // rbx
__int64 result; // rax

v1 = (unsigned __int8 *)(a1 + 1);
for ( result = *(unsigned __int8 *)(a1 + 1); (_BYTE)result; result = *v1 )
{
if ( (_BYTE)result != 68 )
{
fprintf(stderr, "caches: Bad option %c\n", (unsigned int)(char)result);
func0();
exit(1);
}
debug = 1;
debug_file = (__int64)fopen("DEBUG_LOG", "w");
if ( !debug_file )
{
fwrite("Cannot open DEBUG_LOG\n", 1uLL, 0x16uLL, stderr);
debug = 0;
}
++v1;
}
return result;
}

original_code:
void scanargs(String s)
{
    while (*++s != '\0')
        switch (*s)
            {
            case 'D':
                debug = 1;
                if (debug)
                    {
                        debug_file = fopen("DEBUG_LOG", "w");
                        if (debug_file == ((void *)0))
                            {
                                fprintf(stderr, "Cannot open DEBUG_LOG\n");
                                debug = 0;
                            }
                    }
                break;
            default:
                fprintf (stderr,"caches: Bad option %c\n", *s);
                usage();
                exit(1);
            }
}

canonical_original_code:
void scanargs(char *s)
{
    while (*++s != '\0')
        switch (*s)
            {
            case 'D':
                debug = 1;
                if (debug)
                    {
                        debug_file = fopen("DEBUG_LOG", "w");
                        if (debug_file == ((void *)0))
                            {
                                fprintf(stderr, "Cannot open DEBUG_LOG\n");
                                debug = 0;
                            }
                    }
                break;
            default:
                fprintf (stderr,"caches: Bad option %c\n", *s);
                usage();
                exit(1);
            }
}

variable_types:
s
char *


main

canonical_name: main

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

v3 = argc - 1;
v4 = (__int64 *)(argv + 1);
if ( argc - 1 > 1 )
{
while ( *(_BYTE *)*v4 == 45 )
{
scanargs(*v4);
--v3;
++v4;
if ( v3 == 1 )
goto LABEL_4;
}
}
if ( v3 == 2 )
{
Read_Cache_Descriptions(*v4, argv, envp);
Init_Caches();
Simulate_Caches(v4[1]);
Print_Cache_Statistics();
Delete_Caches();
exit(0);
}
LABEL_4:
usage();
exit(-1);
}

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

v3 = argc - 1;
v4 = (__int64 *)(argv + 1);
if ( argc - 1 > 1 )
{
while ( *(_BYTE *)*v4 == 45 )
{
func1(*v4);
--v3;
++v4;
if ( v3 == 1 )
goto LABEL_4;
}
}
if ( v3 == 2 )
{
Read_Cache_Descriptions(*v4, argv, envp);
Init_Caches();
Simulate_Caches(v4[1]);
Print_Cache_Statistics();
Delete_Caches();
exit(0);
}
LABEL_4:
func0();
exit(-1);
}

original_code:
int main(int argc, String *argv)
{
    argc--, argv++;
    while ((argc > 1) && (**argv == '-'))
        {
            scanargs(*argv);
            argc--, argv++;
        }
    if (argc != 2)
        {
            usage();
            exit(-1);
        }
    Read_Cache_Descriptions(argv[0]);
    Init_Caches();
    Simulate_Caches(argv[1]);
    Print_Cache_Statistics();
    Delete_Caches();
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    argc--, argv++;
    while ((argc > 1) && (**argv == '-'))
        {
            scanargs(*argv);
            argc--, argv++;
        }
    if (argc != 2)
        {
            usage();
            exit(-1);
        }
    Read_Cache_Descriptions(argv[0]);
    Init_Caches();
    Simulate_Caches(argv[1]);
    Print_Cache_Statistics();
    Delete_Caches();
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
char *__fastcall print_sets_and_ways(__int64 a1)
{
__int64 v1; // rcx
const char *v2; // rdx
int v3; // eax

v1 = *(unsigned int *)(a1 + 24);
v2 = "direct-mapped";
if ( (_DWORD)v1 == 1 )
return (char *)v2;
v3 = *(_DWORD *)(a1 + 20);
v2 = "fully associative";
if ( (_DWORD)v1 == v3 )
return (char *)v2;
sprintf(buffer_1, "%d sets of %d ways", (unsigned int)(v3 / (int)v1), v1);
return buffer_1;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
__int64 v1; // rcx
const char *v2; // rdx
int v3; // eax

v1 = *(unsigned int *)(a1 + 24);
v2 = "direct-mapped";
if ( (_DWORD)v1 == 1 )
return (char *)v2;
v3 = *(_DWORD *)(a1 + 20);
v2 = "fully associative";
if ( (_DWORD)v1 == v3 )
return (char *)v2;
sprintf(buffer_1, "%d sets of %d ways", (unsigned int)(v3 / (int)v1), v1);
return buffer_1;
}

original_code:
String print_sets_and_ways(CDS *cds)
{
    if (cds->number_of_ways == 1) return("direct-mapped");
    if (cds->number_of_ways == cds->number_of_cache_entries) return("fully associative");
    static char buffer[64];
    sprintf (buffer, "%d sets of %d ways",
             cds->number_of_cache_entries/cds->number_of_ways, cds->number_of_ways);
    return(buffer);
}

canonical_original_code:
char *print_sets_and_ways(struct CDS *cds)
{
    if (cds->number_of_ways == 1) return("direct-mapped");
    if (cds->number_of_ways == cds->number_of_cache_entries) return("fully associative");
    static char buffer[64];
    sprintf (buffer, "%d sets of %d ways",
             cds->number_of_cache_entries/cds->number_of_ways, cds->number_of_ways);
    return(buffer);
}

variable_types: struct CDS { struct CDS *next; char *name; int cache_line_size; int number_of_cache_entries; int number_of_ways; short write_back; enum CRP { CRP_FIFO=0, CRP_LRU=1, CRP_LFU=2, CRP_RANDOM=3 } replacement_policy; int LFU_Decay_Interval; struct cache_line { short valid; int tag; short dirty; int replacement_data; unsigned char *actual_data; } *c; int number_of_memory_reference; int number_of_type[3]; int number_total_cache_access; int number_cache_hits; int number_cache_misses; int number_memory_reads; int number_memory_writes; } *

variable_types:
buffer
char [64]

return_type: char *

user_defined_types: struct CDS { struct CDS *next; char *name; int cache_line_size; int number_of_cache_entries; int number_of_ways; short write_back; enum CRP replacement_policy; int LFU_Decay_Interval; struct cache_line *c; int number_of_memory_reference; int number_of_type[3]; int number_total_cache_access; int number_cache_hits; int number_cache_misses; int number_memory_reads; int number_memory_writes; }


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

result = "Store";
if ( a1 != 1 )
{
result = "Fetch";
if ( a1 != 2 )
{
result = "invalid";
if ( !a1 )
result = "Load";
}
}
return result;
}

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

result = "Store";
if ( a1 != 1 )
{
result = "Fetch";
if ( a1 != 2 )
{
result = "invalid";
if ( !a1 )
result = "Load";
}
}
return result;
}

original_code:
String memory_reference_type_name(enum memory_access_type type)
{
    switch(type)
        {
        case MAT_FETCH: return("Fetch");
        case MAT_LOAD: return("Load");
        case MAT_STORE: return("Store");
        }
    return("invalid");
}

canonical_original_code:
char *memory_reference_type_name(enum memory_access_type type)
{
    switch(type)
        {
        case MAT_FETCH: return("Fetch");
        case MAT_LOAD: return("Load");
        case MAT_STORE: return("Store");
        }
    return("invalid");
}

variable_types: enum memory_access_type { MAT_LOAD=0, MAT_STORE=1, MAT_FETCH=2 }


decompiled_code:
const char *__fastcall CRP_name(__int64 a1)
{
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v1 = *(_DWORD *)(a1 + 32);
if ( v1 == 2 )
{
sprintf(buffer_0, "LFU (decay=%d)", *(unsigned int *)(a1 + 36));
result = buffer_0;
}
else if ( v1 > 2 )
{
v2 = v1 == 3;
result = "Invalid policy";
if ( v2 )
result = "RANDOM";
}
else
{
v2 = v1 == 0;
result = "LRU";
if ( v2 )
result = "FIFO";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(__int64 a1)
{
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v1 = *(_DWORD *)(a1 + 32);
if ( v1 == 2 )
{
sprintf(buffer_0, "LFU (decay=%d)", *(unsigned int *)(a1 + 36));
result = buffer_0;
}
else if ( v1 > 2 )
{
v2 = v1 == 3;
result = "Invalid policy";
if ( v2 )
result = "RANDOM";
}
else
{
v2 = v1 == 0;
result = "LRU";
if ( v2 )
result = "FIFO";
}
return result;
}

original_code:
String CRP_name(CDS *cds)
{
    switch(cds->replacement_policy)
        {
        case CRP_FIFO: return("FIFO");
        case CRP_LRU: return("LRU");
        case CRP_RANDOM: return("RANDOM");
        case CRP_LFU:
            {
                static char buffer[64];
                sprintf(buffer, "LFU (decay=%d)", cds->LFU_Decay_Interval);
                return(buffer);
            }
        };
    return("Invalid policy");
}

canonical_original_code:
char *CRP_name(struct CDS *cds)
{
    switch(cds->replacement_policy)
        {
        case CRP_FIFO: return("FIFO");
        case CRP_LRU: return("LRU");
        case CRP_RANDOM: return("RANDOM");
        case CRP_LFU:
            {
                static char buffer[64];
                sprintf(buffer, "LFU (decay=%d)", cds->LFU_Decay_Interval);
                return(buffer);
            }
        };
    return("Invalid policy");
}

user_defined_types: enum CRP { CRP_FIFO=0, CRP_LRU=1, CRP_LFU=2, CRP_RANDOM=3 }

user_defined_types: struct cache_line { short valid; int tag; short dirty; int replacement_data; unsigned char *actual_data; }


decompiled_code:
int __fastcall debug_print_cds(__int64 a1)
{
char *v1; // rax
const char *v2; // rcx
const char *v3; // rax

fprintf(debug_file, "%s: Total number of entries: %d\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 20));
v1 = print_sets_and_ways(a1);
fprintf(debug_file, "%s: %s\n", *(const char **)(a1 + 8), v1);
fprintf(debug_file, "%s: Each cache line is %d bytes\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 16));
v2 = "write-back";
if ( !*(_WORD *)(a1 + 28) )
v2 = "write-thru";
fprintf(debug_file, "%s: Cache is %s\n", *(const char **)(a1 + 8), v2);
v3 = CRP_name(a1);
return fprintf(debug_file, "%s: With a %s replacement policy\n", *(const char **)(a1 + 8), v3);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
char *v1; // rax
const char *v2; // rcx
const char *v3; // rax

fprintf(debug_file, "%s: Total number of entries: %d\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 20));
v1 = func0(a1);
fprintf(debug_file, "%s: %s\n", *(const char **)(a1 + 8), v1);
fprintf(debug_file, "%s: Each cache line is %d bytes\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 16));
v2 = "write-back";
if ( !*(_WORD *)(a1 + 28) )
v2 = "write-thru";
fprintf(debug_file, "%s: Cache is %s\n", *(const char **)(a1 + 8), v2);
v3 = func2(a1);
return fprintf(debug_file, "%s: With a %s replacement policy\n", *(const char **)(a1 + 8), v3);
}

original_code:
void debug_print_cds(CDS *cds)
{
    fprintf(debug_file, "%s: Total number of entries: %d\n", cds->name, cds->number_of_cache_entries);
    fprintf(debug_file, "%s: %s\n", cds->name, print_sets_and_ways(cds));
    fprintf(debug_file, "%s: Each cache line is %d bytes\n", cds->name, cds->cache_line_size);
    fprintf(debug_file, "%s: Cache is %s\n", cds->name, cds->write_back ? "write-back" : "write-thru");
    fprintf(debug_file, "%s: With a %s replacement policy\n", cds->name, CRP_name(cds));
}

canonical_original_code:
void debug_print_cds(struct CDS *cds)
{
    fprintf(debug_file, "%s: Total number of entries: %d\n", cds->name, cds->number_of_cache_entries);
    fprintf(debug_file, "%s: %s\n", cds->name, print_sets_and_ways(cds));
    fprintf(debug_file, "%s: Each cache line is %d bytes\n", cds->name, cds->cache_line_size);
    fprintf(debug_file, "%s: Cache is %s\n", cds->name, cds->write_back ? "write-back" : "write-thru");
    fprintf(debug_file, "%s: With a %s replacement policy\n", cds->name, CRP_name(cds));
}


percent

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

result = a2;
if ( a2 )
result = (unsigned int)(100 * a1 / (int)a2);
return result;
}

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

result = a2;
if ( a2 )
result = (unsigned int)(100 * a1 / (int)a2);
return result;
}

original_code:
int percent(int a, int b)
{
    if (b == 0) return(0);
    int n = (a*100/b);
    return(n);
}

variable_types: a int

variable_types: b int

variable_types: n int


decompiled_code:
int __fastcall Print_Cache_Statistics_for_one_cache(__int64 a1)
{
const char *v1; // r12
const char *v2; // rbp
char *v3; // rax
const char *v4; // r12
const char *v5; // rbp
const char *v6; // rax
unsigned int v7; // eax
unsigned int v9; // eax

v1 = CRP_name(a1);
v2 = "write-back";
if ( !*(_WORD *)(a1 + 28) )
v2 = "write-thru";
v3 = print_sets_and_ways(a1);
fprintf(
stdout,
"%s: %d entries of lines of %d bytes; %s, %s, %s\n",
*(const char **)(a1 + 8),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 16),
v3,
v2,
v1);
v4 = memory_reference_type_name(1);
v5 = memory_reference_type_name(0);
v6 = memory_reference_type_name(2);
fprintf(
stdout,
" %d addresses (%d %s, %d %s, %d %s)\n",
*(unsigned int *)(a1 + 48),
*(unsigned int *)(a1 + 60),
v6,
*(unsigned int *)(a1 + 52),
v5,
*(unsigned int *)(a1 + 56),
v4);
LODWORD(v5) = *(_DWORD *)(a1 + 68);
v7 = percent((int)v5, *(_DWORD *)(a1 + 64));
fprintf(
stdout,
" %d hits (%d%%), %d misses, %d memory reads, %d memory writes\n",
(unsigned int)v5,
v7,
*(unsigned int *)(a1 + 72),
*(unsigned int *)(a1 + 76),
*(unsigned int *)(a1 + 80));
if ( *(_WORD *)(a1 + 28) )
{
v9 = number_dirty_lines(a1);
fprintf(stdout, " %d dirty cache lines remain\n", v9);
}
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
const char *v1; // r12
const char *v2; // rbp
char *v3; // rax
const char *v4; // r12
const char *v5; // rbp
const char *v6; // rax
unsigned int v7; // eax
unsigned int v9; // eax

v1 = func2(a1);
v2 = "write-back";
if ( !*(_WORD *)(a1 + 28) )
v2 = "write-thru";
v3 = func0(a1);
fprintf(
stdout,
"%s: %d entries of lines of %d bytes; %s, %s, %s\n",
*(const char **)(a1 + 8),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 16),
v3,
v2,
v1);
v4 = func1(1);
v5 = func1(0);
v6 = func1(2);
fprintf(
stdout,
" %d addresses (%d %s, %d %s, %d %s)\n",
*(unsigned int *)(a1 + 48),
*(unsigned int *)(a1 + 60),
v6,
*(unsigned int *)(a1 + 52),
v5,
*(unsigned int *)(a1 + 56),
v4);
LODWORD(v5) = *(_DWORD *)(a1 + 68);
v7 = func4((int)v5, *(_DWORD *)(a1 + 64));
fprintf(
stdout,
" %d hits (%d%%), %d misses, %d memory reads, %d memory writes\n",
(unsigned int)v5,
v7,
*(unsigned int *)(a1 + 72),
*(unsigned int *)(a1 + 76),
*(unsigned int *)(a1 + 80));
if ( *(_WORD *)(a1 + 28) )
{
v9 = number_dirty_lines(a1);
fprintf(stdout, " %d dirty cache lines remain\n", v9);
}
return fputc(10, stdout);
}

original_code:
void Print_Cache_Statistics_for_one_cache(CDS *cds)
{
    fprintf(stdout, "%s: %d entries of lines of %d bytes; %s, %s, %s\n",
            cds->name, cds->number_of_cache_entries, cds->cache_line_size,
            print_sets_and_ways(cds),
            cds->write_back ? "write-back" : "write-thru",
            CRP_name(cds));
    fprintf(stdout, "      %d addresses (%d %s, %d %s, %d %s)\n",
            cds->number_of_memory_reference,
            cds->number_of_type[MAT_FETCH], memory_reference_type_name(MAT_FETCH),
            cds->number_of_type[MAT_LOAD], memory_reference_type_name(MAT_LOAD),
            cds->number_of_type[MAT_STORE], memory_reference_type_name(MAT_STORE));
    fprintf(stdout, "      %d hits (%d%%), %d misses, %d memory reads, %d memory writes\n",
            cds->number_cache_hits, percent(cds->number_cache_hits, cds->number_total_cache_access),
            cds->number_cache_misses,
            cds->number_memory_reads, cds->number_memory_writes);
    if (cds->write_back)
        fprintf(stdout, "      %d dirty cache lines remain\n", number_dirty_lines(cds));
    fprintf(stdout, "\n");
}

canonical_original_code:
void Print_Cache_Statistics_for_one_cache(struct CDS *cds)
{
    fprintf(stdout, "%s: %d entries of lines of %d bytes; %s, %s, %s\n",
            cds->name, cds->number_of_cache_entries, cds->cache_line_size,
            print_sets_and_ways(cds),
            cds->write_back ? "write-back" : "write-thru",
            CRP_name(cds));
    fprintf(stdout, "      %d addresses (%d %s, %d %s, %d %s)\n",
            cds->number_of_memory_reference,
            cds->number_of_type[MAT_FETCH], memory_reference_type_name(MAT_FETCH),
            cds->number_of_type[MAT_LOAD], memory_reference_type_name(MAT_LOAD),
            cds->number_of_type[MAT_STORE], memory_reference_type_name(MAT_STORE));
    fprintf(stdout, "      %d hits (%d%%), %d misses, %d memory reads, %d memory writes\n",
            cds->number_cache_hits, percent(cds->number_cache_hits, cds->number_total_cache_access),
            cds->number_cache_misses,
            cds->number_memory_reads, cds->number_memory_writes);
    if (cds->write_back)
        fprintf(stdout, "      %d dirty cache lines remain\n", number_dirty_lines(cds));
    fprintf(stdout, "\n");
}


decompiled_code:
int Print_Cache_Statistics()
{
_QWORD *v0; // rbx
int result; // eax

v0 = CDS_root;
if ( CDS_root )
{
do
{
result = Print_Cache_Statistics_for_one_cache((__int64)v0);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
return result;
}

canonical_decompiled_code:
int func6()
{
_QWORD *v0; // rbx
int result; // eax

v0 = CDS_root;
if ( CDS_root )
{
do
{
result = func5((__int64)v0);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
return result;
}

original_code:
void Print_Cache_Statistics(void)
{
    CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            Print_Cache_Statistics_for_one_cache(cds);
            cds = cds->next;
        }
}

canonical_original_code:
void Print_Cache_Statistics()
{
    struct CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            Print_Cache_Statistics_for_one_cache(cds);
            cds = cds->next;
        }
}


decompiled_code:
void *__fastcall init_cache(__int64 a1)
{
void *result; // rax

result = calloc(*(int *)(a1 + 20), 0x18uLL);
*(_QWORD *)(a1 + 40) = result;
return result;
}

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

result = calloc(*(int *)(a1 + 20), 0x18uLL);
*(_QWORD *)(a1 + 40) = result;
return result;
}

original_code:
void init_cache(CDS *cds)
{
    cds->c = calloc(cds->number_of_cache_entries, sizeof(cache_line));
}

canonical_original_code:
void init_cache(struct CDS *cds)
{
    cds->c = calloc(cds->number_of_cache_entries, sizeof(cache_line));
}


decompiled_code:
void *Init_Caches()
{
_QWORD *v0; // rbx
void *result; // rax

v0 = CDS_root;
if ( CDS_root )
{
do
{
result = init_cache((__int64)v0);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
return result;
}

canonical_decompiled_code:
void *func8()
{
_QWORD *v0; // rbx
void *result; // rax

v0 = CDS_root;
if ( CDS_root )
{
do
{
result = func7((__int64)v0);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
return result;
}

original_code:
void Init_Caches(void)
{
    CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            init_cache(cds);
            cds = cds->next;
        }
}

canonical_original_code:
void Init_Caches()
{
    struct CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            init_cache(cds);
            cds = cds->next;
        }
}


decompiled_code:
void Init_caches_for_trace()
{
_DWORD *v0; // rbx

v0 = CDS_root;
if ( CDS_root )
{
do
{
init_cache_for_trace(v0);
v0 = *(_DWORD **)v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func10()
{
_DWORD *v0; // rbx

v0 = CDS_root;
if ( CDS_root )
{
do
{
func9(v0);
v0 = *(_DWORD **)v0;
}
while ( v0 );
}
}

original_code:
void Init_caches_for_trace(void)
{
    CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            init_cache_for_trace(cds);
            cds = cds->next;
        }
}

canonical_original_code:
void Init_caches_for_trace()
{
    struct CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            init_cache_for_trace(cds);
            cds = cds->next;
        }
}


decompiled_code:
void __fastcall delete_cache(void *ptr)
{
free(*((void **)ptr + 5));
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
free(*((void **)ptr + 5));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void delete_cache(CDS *cds)
{
    free(cds->c);
    free(cds->name);
    free(cds);
}

canonical_original_code:
void delete_cache(struct CDS *cds)
{
    free(cds->c);
    free(cds->name);
    free(cds);
}


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

v0 = CDS_root;
if ( CDS_root )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
delete_cache(v1);
}
while ( v0 );
}
}

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

v0 = CDS_root;
if ( CDS_root )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
func11(v1);
}
while ( v0 );
}
}

original_code:
void Delete_Caches(void)
{
    CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            CDS *old = cds;
            cds = cds->next;
            delete_cache(old);
        }
}

canonical_original_code:
void Delete_Caches()
{
    struct CDS *cds = CDS_root;
    while (cds != ((void *)0))
        {
            struct CDS *old = cds;
            cds = cds->next;
            delete_cache(old);
        }
}


decompiled_code:
_DWORD *new_token()
{
_DWORD *v0; // rbx

v0 = malloc(0x10uLL);
v0[2] = 128;
*(_QWORD *)v0 = malloc(0x80uLL);
return v0;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rbx

v0 = malloc(0x10uLL);
v0[2] = 128;
*(_QWORD *)v0 = malloc(0x80uLL);
return v0;
}

original_code:
Token *new_token(void)
{
    Token *t = ((Token *)(malloc(sizeof(Token))));
    t->length = 128;
    t->string = ((String)(malloc(t->length)));
    return(t);
}

canonical_original_code:
struct Token *new_token()
{
    struct Token *t = ((Token *)(malloc(sizeof(Token))));
    t->length = 128;
    t->string = ((String)(malloc(t->length)));
    return(t);
}

variable_types: struct Token { char *string; int length; } *


decompiled_code:
void __fastcall delete_token(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void delete_token(Token *t)
{
    free(t->string);
    free(t);
}

canonical_original_code:
void delete_token(struct Token *t)
{
    free(t->string);
    free(t);
}

user_defined_types: struct Token { char *string; int length; }


decompiled_code:
void *__fastcall put_char_in_token_at(__int64 a1, char a2, int a3)
{
int v5; // esi
void *result; // rax
int v7; // esi
void *v8; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 <= a3 )
{
v7 = 2 * v5;
*(_DWORD *)(a1 + 8) = v7;
v8 = realloc(*(void **)a1, v7);
*(_QWORD *)a1 = v8;
if ( !v8 )
{
fwrite("Hell has frozen over!!!\n", 1uLL, 0x18uLL, stderr);
exit(-1);
}
}
result = *(void **)a1;
*(_BYTE *)(*(_QWORD *)a1 + a3) = a2;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, char a2, int a3)
{
int v5; // esi
void *result; // rax
int v7; // esi
void *v8; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 <= a3 )
{
v7 = 2 * v5;
*(_DWORD *)(a1 + 8) = v7;
v8 = realloc(*(void **)a1, v7);
*(_QWORD *)a1 = v8;
if ( !v8 )
{
fwrite("Hell has frozen over!!!\n", 1uLL, 0x18uLL, stderr);
exit(-1);
}
}
result = *(void **)a1;
*(_BYTE *)(*(_QWORD *)a1 + a3) = a2;
return result;
}

original_code:
void put_char_in_token_at(Token *t, char c, int i)
{
    if (i >= t->length)
        {
            t->length = 2 * t->length;
            t->string = realloc(t->string, t->length);
            if (t->string == ((void *)0))
                {
                    fprintf(stderr, "Hell has frozen over!!!\n");
                    exit(-1);
                }
        }
    t->string[i] = c;
}

canonical_original_code:
void put_char_in_token_at(struct Token *t, char c, int i)
{
    if (i >= t->length)
        {
            t->length = 2 * t->length;
            t->string = realloc(t->string, t->length);
            if (t->string == ((void *)0))
                {
                    fprintf(stderr, "Hell has frozen over!!!\n");
                    exit(-1);
                }
        }
    t->string[i] = c;
}

variable_types: c char

variable_types: i int


decompiled_code:
int __fastcall define_key_value_pair(__int64 a1, const char **a2, const char **a3)
{
const char *v5; // r12
void *v6; // rdi
char *v7; // rax
const char *v8; // r13
const char *v9; // r13
const char *v10; // r13

if ( debug )
fprintf(debug_file, "define %s = %s \n", *a2, *a3);
v5 = *a2;
if ( strcasestr(*a2, "name") )
{
v6 = *(void **)(a1 + 8);
if ( v6 )
free(v6);
v7 = (char *)remember_string(*a3);
*(_QWORD *)(a1 + 8) = v7;
return (int)v7;
}
if ( strcasestr(v5, "line") && strcasestr(v5, "size") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 16) = (_DWORD)v7;
return (int)v7;
}
if ( strcasestr(v5, "entries") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 20) = (_DWORD)v7;
return (int)v7;
}
if ( strcasestr(v5, "ways") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 24) = (_DWORD)v7;
return (int)v7;
}
if ( strcasestr(v5, "write") )
{
if ( strcasestr(v5, "back") )
{
v8 = *a3;
v7 = strcasestr(*a3, "true");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 1;
return (int)v7;
}
v7 = strcasestr(v8, "false");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 0;
return (int)v7;
}
if ( !strcasestr(v5, "thru") )
goto LABEL_23;
v9 = *a3;
goto LABEL_39;
}
if ( strcasestr(v5, "thru") )
{
v9 = *a3;
v7 = strcasestr(*a3, "true");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 0;
return (int)v7;
}
LABEL_39:
v7 = strcasestr(v9, "false");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 1;
return (int)v7;
}
goto LABEL_23;
}
}
LABEL_23:
if ( strcasestr(v5, "policy") || strcasestr(v5, "replace") )
{
v10 = *a3;
v7 = strcasestr(*a3, "LRU");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 1;
return (int)v7;
}
v7 = strcasestr(v10, "LFU");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 2;
return (int)v7;
}
v7 = strcasestr(v10, "random");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 3;
return (int)v7;
}
v7 = strcasestr(v10, "FIFO");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 0;
return (int)v7;
}
}
if ( strcasestr(v5, "decay") && strcasestr(v5, "interval") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 36) = (_DWORD)v7;
}
else
{
LODWORD(v7) = fprintf(stderr, "don't understand %s = %s\n", v5, *a3);
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, const char **a2, const char **a3)
{
const char *v5; // r12
void *v6; // rdi
char *v7; // rax
const char *v8; // r13
const char *v9; // r13
const char *v10; // r13

if ( debug )
fprintf(debug_file, "define %s = %s \n", *a2, *a3);
v5 = *a2;
if ( strcasestr(*a2, "name") )
{
v6 = *(void **)(a1 + 8);
if ( v6 )
free(v6);
v7 = (char *)remember_string(*a3);
*(_QWORD *)(a1 + 8) = v7;
return (int)v7;
}
if ( strcasestr(v5, "line") && strcasestr(v5, "size") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 16) = (_DWORD)v7;
return (int)v7;
}
if ( strcasestr(v5, "entries") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 20) = (_DWORD)v7;
return (int)v7;
}
if ( strcasestr(v5, "ways") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 24) = (_DWORD)v7;
return (int)v7;
}
if ( strcasestr(v5, "write") )
{
if ( strcasestr(v5, "back") )
{
v8 = *a3;
v7 = strcasestr(*a3, "true");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 1;
return (int)v7;
}
v7 = strcasestr(v8, "false");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 0;
return (int)v7;
}
if ( !strcasestr(v5, "thru") )
goto LABEL_23;
v9 = *a3;
goto LABEL_39;
}
if ( strcasestr(v5, "thru") )
{
v9 = *a3;
v7 = strcasestr(*a3, "true");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 0;
return (int)v7;
}
LABEL_39:
v7 = strcasestr(v9, "false");
if ( v7 )
{
*(_WORD *)(a1 + 28) = 1;
return (int)v7;
}
goto LABEL_23;
}
}
LABEL_23:
if ( strcasestr(v5, "policy") || strcasestr(v5, "replace") )
{
v10 = *a3;
v7 = strcasestr(*a3, "LRU");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 1;
return (int)v7;
}
v7 = strcasestr(v10, "LFU");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 2;
return (int)v7;
}
v7 = strcasestr(v10, "random");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 3;
return (int)v7;
}
v7 = strcasestr(v10, "FIFO");
if ( v7 )
{
*(_DWORD *)(a1 + 32) = 0;
return (int)v7;
}
}
if ( strcasestr(v5, "decay") && strcasestr(v5, "interval") )
{
LODWORD(v7) = atoi(*a3);
*(_DWORD *)(a1 + 36) = (_DWORD)v7;
}
else
{
LODWORD(v7) = fprintf(stderr, "don't understand %s = %s\n", v5, *a3);
}
return (int)v7;
}

original_code:
void define_key_value_pair(CDS *cds, Token *key, Token *value)
{
    if (debug) fprintf(debug_file, "define %s = %s \n", key->string, value->string);
    if (strcasestr(key->string, "name") != ((void *)0))
        {
            if (cds->name != ((void *)0)) free(cds->name);
            cds->name = remember_string(value->string);
            return;
        }
    if ((strcasestr(key->string, "line") != ((void *)0)) && (strcasestr(key->string, "size") != ((void *)0)))
        {
            int n = atoi(value->string);
            cds->cache_line_size = n;
            return;
        }
    if (strcasestr(key->string, "entries") != ((void *)0))
        {
            int n = atoi(value->string);
            cds->number_of_cache_entries = n;
            return;
        }
    if (strcasestr(key->string, "ways") != ((void *)0))
        {
            int n = atoi(value->string);
            cds->number_of_ways = n;
            return;
        }
    if ((strcasestr(key->string, "write") != ((void *)0)) && (strcasestr(key->string, "back") != ((void *)0)))
        {
            if (strcasestr(value->string, "true") != ((void *)0))
                {
                    cds->write_back = 1;
                    return;
                }
            if (strcasestr(value->string, "false") != ((void *)0))
                {
                    cds->write_back = 0;
                    return;
                }
        }
    if ((strcasestr(key->string, "write") != ((void *)0)) && (strcasestr(key->string, "thru") != ((void *)0)))
        {
            if (strcasestr(value->string, "true") != ((void *)0))
                {
                    cds->write_back = 0;
                    return;
                }
            if (strcasestr(value->string, "false") != ((void *)0))
                {
                    cds->write_back = 1;
                    return;
                }
        }
    if ((strcasestr(key->string, "policy") != ((void *)0)) || (strcasestr(key->string, "replace") != ((void *)0)))
        {
            if (strcasestr(value->string, "LRU") != ((void *)0))
                {
                    cds->replacement_policy = CRP_LRU;
                    return;
                }
            if (strcasestr(value->string, "LFU") != ((void *)0))
                {
                    cds->replacement_policy = CRP_LFU;
                    return;
                }
            if (strcasestr(value->string, "random") != ((void *)0))
                {
                    cds->replacement_policy = CRP_RANDOM;
                    return;
                }
            if (strcasestr(value->string, "FIFO") != ((void *)0))
                {
                    cds->replacement_policy = CRP_FIFO;
                    return;
                }
        }
    if ((strcasestr(key->string, "decay") != ((void *)0)) && (strcasestr(key->string, "interval") != ((void *)0)))
        {
            int n = atoi(value->string);
            cds->LFU_Decay_Interval = n;
            return;
        }
    fprintf(stderr, "don't understand %s = %s\n",key->string, value->string);
}

canonical_original_code:
void define_key_value_pair(struct CDS *cds, struct Token *key, struct Token *value)
{
    if (debug) fprintf(debug_file, "define %s = %s \n", key->string, value->string);
    if (strcasestr(key->string, "name") != ((void *)0))
        {
            if (cds->name != ((void *)0)) free(cds->name);
            cds->name = remember_string(value->string);
            return;
        }
    if ((strcasestr(key->string, "line") != ((void *)0)) && (strcasestr(key->string, "size") != ((void *)0)))
        {
            int n = atoi(value->string);
            cds->cache_line_size = n;
            return;
        }
    if (strcasestr(key->string, "entries") != ((void *)0))
        {
            int n = atoi(value->string);
            cds->number_of_cache_entries = n;
            return;
        }
    if (strcasestr(key->string, "ways") != ((void *)0))
        {
            int n = atoi(value->string);
            cds->number_of_ways = n;
            return;
        }
    if ((strcasestr(key->string, "write") != ((void *)0)) && (strcasestr(key->string, "back") != ((void *)0)))
        {
            if (strcasestr(value->string, "true") != ((void *)0))
                {
                    cds->write_back = 1;
                    return;
                }
            if (strcasestr(value->string, "false") != ((void *)0))
                {
                    cds->write_back = 0;
                    return;
                }
        }
    if ((strcasestr(key->string, "write") != ((void *)0)) && (strcasestr(key->string, "thru") != ((void *)0)))
        {
            if (strcasestr(value->string, "true") != ((void *)0))
                {
                    cds->write_back = 0;
                    return;
                }
            if (strcasestr(value->string, "false") != ((void *)0))
                {
                    cds->write_back = 1;
                    return;
                }
        }
    if ((strcasestr(key->string, "policy") != ((void *)0)) || (strcasestr(key->string, "replace") != ((void *)0)))
        {
            if (strcasestr(value->string, "LRU") != ((void *)0))
                {
                    cds->replacement_policy = CRP_LRU;
                    return;
                }
            if (strcasestr(value->string, "LFU") != ((void *)0))
                {
                    cds->replacement_policy = CRP_LFU;
                    return;
                }
            if (strcasestr(value->string, "random") != ((void *)0))
                {
                    cds->replacement_policy = CRP_RANDOM;
                    return;
                }
            if (strcasestr(value->string, "FIFO") != ((void *)0))
                {
                    cds->replacement_policy = CRP_FIFO;
                    return;
                }
        }
    if ((strcasestr(key->string, "decay") != ((void *)0)) && (strcasestr(key->string, "interval") != ((void *)0)))
        {
            int n = atoi(value->string);
            cds->LFU_Decay_Interval = n;
            return;
        }
    fprintf(stderr, "don't understand %s = %s\n",key->string, value->string);
}

variable_types:
value
struct Token *


decompiled_code:
__int64 __fastcall which_power(int a1)
{
int v1; // eax
unsigned int v2; // edx

if ( a1 <= 1 )
return 0;
v1 = 1;
v2 = 0;
do
{
v1 *= 2;
++v2;
}
while ( a1 > v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
unsigned int v2; // edx

if ( a1 <= 1 )
return 0;
v1 = 1;
v2 = 0;
do
{
v1 *= 2;
++v2;
}
while ( a1 > v1 );
return v2;
}

original_code:
int which_power(int n)
{
    int i = 0;
    int t = 1;
    while (n > t)
        {
            t += t;
            i += 1;
        }
    return(i);
}

variable_types: t int


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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((1 << a1) - 1);
return result;
}

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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((1 << a1) - 1);
return result;
}

original_code:
unsigned int mask_of(int n)
{
    int m;
    if (n <= 0) return(0);
    m = (1 << n) - 1;
    return(m);
}

variable_types: m int

return_type: unsigned int


ishex

decompiled_code:
_BOOL8 __fastcall ishex(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)(a1 - 48) > 9 )
result = (a1 & 0xFFFFFFDF) - 65 <= 5;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)(a1 - 48) > 9 )
result = (a1 & 0xFFFFFFDF) - 65 <= 5;
return result;
}

variable_types: c int

return_type: short


hexvalue

decompiled_code:
__int64 __fastcall hexvalue(int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 97) <= 5 )
{
result = (unsigned int)(a1 - 87);
}
else
{
v2 = a1 - 65;
v3 = a1 - 55;
v4 = v2 < 6;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 97) <= 5 )
{
result = (unsigned int)(a1 - 87);
}
else
{
v2 = a1 - 65;
v3 = a1 - 55;
v4 = v2 < 6;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}


decvalue

decompiled_code:
__int64 __fastcall decvalue(int a1)
{
unsigned int v1; // edi
__int64 result; // rax

v1 = a1 - 48;
result = 0xFFFFFFFFLL;
if ( v1 < 0xA )
result = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int v1; // edi
__int64 result; // rax

v1 = a1 - 48;
result = 0xFFFFFFFFLL;
if ( v1 < 0xA )
result = v1;
return result;
}


decompiled_code:
char *__fastcall remember_string(char *src)
{
size_t v1; // rax
char *v2; // rbp

if ( !src )
return 0LL;
v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strcpy(v2, src);
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
size_t v1; // rax
char *v2; // rbp

if ( !src )
return 0LL;
v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strcpy(v2, src);
return v2;
}

original_code:
String remember_string(const String name)
{
    size_t n;
    String p;
    if (name == ((void *)0)) return(((void *)0));
    n = strlen(name) + 1;
    p = ((String)(malloc(n)));
    strcpy(p, name);
    return(p);
}

canonical_original_code:
char *remember_string(char *name)
{
    unsigned long n;
    char *p;
    if (name == ((void *)0)) return(((void *)0));
    n = strlen(name) + 1;
    p = ((String)(malloc(n)));
    strcpy(p, name);
    return(p);
}

variable_types:
name
char *

variable_types:
n
unsigned long

variable_types:
p
char *


cylinderInterseption

repo: josemoO/RayTracing

decompiled_code:
void __fastcall cylinderInterseption(long double *a1, long double *a2, long double *a3, __int64 a4)
{
long double v4; // fst7
long double v5; // fst5
long double v6; // fst6
long double v7; // fst4
long double v8; // fst2
long double v9; // fst3
long double v10; // fst3
long double v11; // fst2
long double v12; // fst7
double v13; // xmm11_8
double v14; // xmm13_8
double v15; // xmm12_8
long double v16; // rt0
long double v17; // fst1
double v18; // xmm10_8
double v19; // xmm3_8
long double v20; // rt1
long double v21; // fst1
long double v22; // fst3
long double v23; // fst2
long double v24; // fst5
double v25; // xmm0_8
long double v26; // rt1
double v27; // xmm9_8
double v28; // xmm7_8
double v29; // xmm2_8
double v30; // xmm6_8
long double v31; // fst2
double v32; // xmm11_8
double v33; // xmm11_8
double v34; // xmm13_8
long double v35; // fst4
long double v36; // fst6
double v37; // xmm3_8
double v38; // xmm10_8
double v41; // xmm1_8
double v42; // r14
long double v43; // fst7
long double v44; // fst6
long double v45; // fst5
long double v46; // fst4
long double v47; // fst3
long double v48; // fst2
long double v49; // rt1
long double v50; // fst3
long double v51; // fst6
long double v52; // fst7
long double v53; // fst5
long double v54; // fst6
long double v55; // fst4
long double v56; // fst3
long double v57; // rt2
long double v58; // fst1
long double v59; // fst7
long double v60; // fst6
long double v61; // fst5
long double v62; // fst4
long double v63; // fst3
long double v64; // fst2
long double v65; // rt0
long double v66; // fst3
long double v67; // fst6
long double v68; // fst7
long double v69; // fst5
long double v70; // fst6
long double v71; // fst4
long double v72; // fst3
long double v73; // rt1
long double v74; // fst1
long double v75; // rtt
long double v76; // rt0
_BYTE v77[1280]; // [rsp-500h] [rbp-1028h] BYREF
long double v78; // [rsp+0h] [rbp-B28h]
long double v79; // [rsp+10h] [rbp-B18h]
long double v80; // [rsp+20h] [rbp-B08h]
long double v81; // [rsp+30h] [rbp-AF8h]
long double v82; // [rsp+40h] [rbp-AE8h]
long double v83; // [rsp+50h] [rbp-AD8h]
long double v84; // [rsp+60h] [rbp-AC8h]
long double v85; // [rsp+70h] [rbp-AB8h]
long double v86; // [rsp+80h] [rbp-AA8h]
long double v87; // [rsp+90h] [rbp-A98h]
long double v88; // [rsp+A0h] [rbp-A88h]
long double v89; // [rsp+B0h] [rbp-A78h]
long double v90; // [rsp+C0h] [rbp-A68h]
double v91; // [rsp+D8h] [rbp-A50h]
long double v92; // [rsp+E0h] [rbp-A48h]
long double v93; // [rsp+F0h] [rbp-A38h]
_BYTE v94[1280]; // [rsp+100h] [rbp-A28h] BYREF
_BYTE v95[1280]; // [rsp+600h] [rbp-528h] BYREF

v4 = *a2;
v78 = a3[44];
v5 = a3[45];
v6 = a3[46];
*(double *)&v79 = v78 * v4 + a2[1] * v5 + a2[2] * v6;
v7 = *(double *)&v79;
v91 = *(double *)&v79;
v8 = (*a1 - a3[32]) * v78 + (a1[1] - a3[33]) * v5;
v9 = a1[2];
v79 = a3[34];
v10 = (double)(v8 + (v9 - v79) * v6);
v92 = v7;
v11 = v4;
v12 = v78 * v7;
v13 = v11;
*(double *)&v80 = v5 * v7;
v14 = *(double *)&v80;
v15 = a2[1];
v16 = v5 * v7;
v17 = v7 * v6;
*(double *)&v80 = v17;
v18 = v17;
*(double *)&v80 = a2[2];
v19 = *(double *)&v80;
v81 = v11;
v20 = v17;
v83 = v11 + v11;
v93 = v10;
v21 = v10;
v22 = v78;
*(double *)&v78 = v21;
v82 = v12;
v85 = a2[1] + a2[1];
v23 = v5;
v24 = v20;
v80 = v23 * (double)v21;
v86 = a2[2] + a2[2];
v87 = v20 + v20;
*(double *)&v84 = *a1;
v25 = *(double *)&v84;
v26 = v6 * (double)v21;
v27 = a3[32];
v84 = v22 * v21;
*(double *)&v88 = v84;
v88 = *a1 + *a1;
*(double *)&v89 = a1[1];
v28 = *(double *)&v89;
v29 = a3[33];
*(double *)&v89 = v80;
v30 = v80;
v89 = a1[1] + a1[1];
v31 = a1[2];
v90 = v31 + v31;
*(double *)&v81 = v81 * -2.0 * v12 + (double)v12 * (double)v12 + v13 * v13;
v32 = *(double *)&v81;
*(double *)&v81 = v16 * (a2[1] * -2.0) + v14 * v14 + v15 * v15;
v33 = v32 + *(double *)&v81;
*(double *)&v81 = v24 * (-2.0 * a2[2]) + v18 * v18 + v19 * v19;
v34 = v33 + *(double *)&v81;
*(double *)&v82 = v33 + *(double *)&v81;
*(double *)&v81 = *a1 * v83 - a3[32] * v83 - v83 * v84 - *a1 * (v12 + v12) + a3[32] * (v12 + v12) + (v12 + v12) * v84;
v35 = a1[1] * v85 - a3[33] * v85 - v85 * v80 - a1[1] * (v16 + v16) + a3[33] * (v16 + v16) + (v16 + v16) * v80;
v36 = v80;
*(double *)&v80 = v35;
*(double *)&v80 = v79 * v87 + a1[2] * v86 - v86 * v79 - v86 * v26 - a1[2] * v87 + v87 * v26;
*(double *)&v81 = *(double *)&v81 + (double)v35 + *(double *)&v80;
v37 = a3[31];
v38 = *(double *)&v81 * *(double *)&v81
- ((double)(v84 * (a3[32] + a3[32]) + v25 * v25 + v27 * v27 + (double)v84 * (double)v84 - a3[32] * v88 - v88 * v84)
+ (double)(v36 * (a3[33] + a3[33]) + v29 * v29 + v28 * v28 + v30 * v30 - a3[33] * v89 - v89 * v36)
+ (double)(v26 * (v79 + v79)
+ (double)v79 * (double)v79
+ (double)v31 * (double)v31
+ (double)v26 * (double)v26
- v90 * v79
- v90 * v26)
- v37 * v37)
* (v34
* 4.0);
*(double *)&v79 = v38;
if ( v38 > 0.0005 )
{
if ( v38 < 0.0 )
{
*(double *)&v82 = *(double *)&v82 + *(double *)&v82;
*(double *)&v80 = (sqrt(*(double *)&v79) - *(double *)&v81) / *(double *)&v82;
*(_QWORD *)&v42 = *(_QWORD *)&v81 ^ LC4;
v41 = sqrt(*(double *)&v79);
}
else
{
v41 = sqrt(v38);
*(double *)&v82 = v34 + v34;
*(double *)&v80 = (v41 - *(double *)&v81) / (v34 + v34);
*(_QWORD *)&v42 = *(_QWORD *)&v81 ^ LC4;
}
*(double *)&v79 = (v42 - v41) / *(double *)&v82;
if ( *(double *)&v80 > 0.0005 )
{
v43 = *a1;
v44 = *a2;
v45 = a1[1];
v46 = a2[1];
v47 = a1[2];
v82 = a2[2];
qmemcpy(v95, a3, 0x4C0uLL);
v48 = a3[48];
if ( 0.0 == v48 && a3[49] == 0.0 )
{
v49 = v47;
v50 = v44;
v51 = v49;
LABEL_11:
v52 = v43 + v50 * *(double *)&v80;
v53 = v45 + v46 * *(double *)&v80;
v54 = v51 + v82 * *(double *)&v80;
v55 = v92 * *(double *)&v80 + v93;
v56 = a3[31];
v57 = (v53 - (a3[45] * v55 + a3[33])) / v56;
v58 = v55 * a3[46] + a3[34];
*(long double *)&v95[1168] = (v52 - (a3[44] * v55 + a3[32])) / v56;
*(long double *)&v95[1184] = v57;
*(long double *)&v95[1200] = (v54 - v58) / v56;
*(long double *)&v95[1120] = *(long double *)&v95[1168];
*(long double *)&v95[1136] = v57;
*(long double *)&v95[1152] = *(long double *)&v95[1200];
*(long double *)&v95[1216] = *(double *)&v80;
*(long double *)&v95[1232] = v52;
*(long double *)&v95[1248] = v53;
*(long double *)&v95[1264] = v54;
qmemcpy(v77, v95, sizeof(v77));
insertInOrder(a4);
goto LABEL_12;
}
*(double *)&v81 = v91 * *(double *)&v80 + *(double *)&v78;
if ( a3[49] >= *(double *)&v81 && *(double *)&v81 >= v48 )
{
v75 = v47;
v50 = v44;
v51 = v75;
goto LABEL_11;
}
}
LABEL_12:
if ( *(double *)&v79 <= 0.0005 )
return;
v59 = *a1;
v60 = *a2;
v61 = a1[1];
v62 = a2[1];
v63 = a1[2];
v80 = a2[2];
qmemcpy(v94, a3, 0x4C0uLL);
v64 = a3[48];
if ( 0.0 == v64 && a3[49] == 0.0 )
{
v65 = v63;
v66 = v60;
v67 = v65;
}
else
{
*(double *)&v78 = v91 * *(double *)&v79 + *(double *)&v78;
if ( a3[49] < *(double *)&v78 || *(double *)&v78 < v64 )
return;
v76 = v63;
v66 = v60;
v67 = v76;
}
v68 = v59 + v66 * *(double *)&v79;
v69 = v61 + v62 * *(double *)&v79;
v70 = v67 + v80 * *(double *)&v79;
v71 = v92 * *(double *)&v79 + v93;
v72 = a3[31];
v73 = (v69 - (a3[45] * v71 + a3[33])) / v72;
v74 = v71 * a3[46] + a3[34];
*(long double *)&v94[1168] = (v68 - (a3[44] * v71 + a3[32])) / v72;
*(long double *)&v94[1184] = v73;
*(long double *)&v94[1200] = (v70 - v74) / v72;
*(long double *)&v94[1120] = *(long double *)&v94[1168];
*(long double *)&v94[1136] = v73;
*(long double *)&v94[1152] = *(long double *)&v94[1200];
*(long double *)&v94[1216] = *(double *)&v79;
*(long double *)&v94[1232] = v68;
*(long double *)&v94[1248] = v69;
*(long double *)&v94[1264] = v70;
qmemcpy(v77, v94, sizeof(v77));
insertInOrder(a4);
}
}

canonical_decompiled_code:
void __fastcall func0(long double *a1, long double *a2, long double *a3, __int64 a4)
{
long double v4; // fst7
long double v5; // fst5
long double v6; // fst6
long double v7; // fst4
long double v8; // fst2
long double v9; // fst3
long double v10; // fst3
long double v11; // fst2
long double v12; // fst7
double v13; // xmm11_8
double v14; // xmm13_8
double v15; // xmm12_8
long double v16; // rt0
long double v17; // fst1
double v18; // xmm10_8
double v19; // xmm3_8
long double v20; // rt1
long double v21; // fst1
long double v22; // fst3
long double v23; // fst2
long double v24; // fst5
double v25; // xmm0_8
long double v26; // rt1
double v27; // xmm9_8
double v28; // xmm7_8
double v29; // xmm2_8
double v30; // xmm6_8
long double v31; // fst2
double v32; // xmm11_8
double v33; // xmm11_8
double v34; // xmm13_8
long double v35; // fst4
long double v36; // fst6
double v37; // xmm3_8
double v38; // xmm10_8
double v41; // xmm1_8
double v42; // r14
long double v43; // fst7
long double v44; // fst6
long double v45; // fst5
long double v46; // fst4
long double v47; // fst3
long double v48; // fst2
long double v49; // rt1
long double v50; // fst3
long double v51; // fst6
long double v52; // fst7
long double v53; // fst5
long double v54; // fst6
long double v55; // fst4
long double v56; // fst3
long double v57; // rt2
long double v58; // fst1
long double v59; // fst7
long double v60; // fst6
long double v61; // fst5
long double v62; // fst4
long double v63; // fst3
long double v64; // fst2
long double v65; // rt0
long double v66; // fst3
long double v67; // fst6
long double v68; // fst7
long double v69; // fst5
long double v70; // fst6
long double v71; // fst4
long double v72; // fst3
long double v73; // rt1
long double v74; // fst1
long double v75; // rtt
long double v76; // rt0
_BYTE v77[1280]; // [rsp-500h] [rbp-1028h] BYREF
long double v78; // [rsp+0h] [rbp-B28h]
long double v79; // [rsp+10h] [rbp-B18h]
long double v80; // [rsp+20h] [rbp-B08h]
long double v81; // [rsp+30h] [rbp-AF8h]
long double v82; // [rsp+40h] [rbp-AE8h]
long double v83; // [rsp+50h] [rbp-AD8h]
long double v84; // [rsp+60h] [rbp-AC8h]
long double v85; // [rsp+70h] [rbp-AB8h]
long double v86; // [rsp+80h] [rbp-AA8h]
long double v87; // [rsp+90h] [rbp-A98h]
long double v88; // [rsp+A0h] [rbp-A88h]
long double v89; // [rsp+B0h] [rbp-A78h]
long double v90; // [rsp+C0h] [rbp-A68h]
double v91; // [rsp+D8h] [rbp-A50h]
long double v92; // [rsp+E0h] [rbp-A48h]
long double v93; // [rsp+F0h] [rbp-A38h]
_BYTE v94[1280]; // [rsp+100h] [rbp-A28h] BYREF
_BYTE v95[1280]; // [rsp+600h] [rbp-528h] BYREF

v4 = *a2;
v78 = a3[44];
v5 = a3[45];
v6 = a3[46];
*(double *)&v79 = v78 * v4 + a2[1] * v5 + a2[2] * v6;
v7 = *(double *)&v79;
v91 = *(double *)&v79;
v8 = (*a1 - a3[32]) * v78 + (a1[1] - a3[33]) * v5;
v9 = a1[2];
v79 = a3[34];
v10 = (double)(v8 + (v9 - v79) * v6);
v92 = v7;
v11 = v4;
v12 = v78 * v7;
v13 = v11;
*(double *)&v80 = v5 * v7;
v14 = *(double *)&v80;
v15 = a2[1];
v16 = v5 * v7;
v17 = v7 * v6;
*(double *)&v80 = v17;
v18 = v17;
*(double *)&v80 = a2[2];
v19 = *(double *)&v80;
v81 = v11;
v20 = v17;
v83 = v11 + v11;
v93 = v10;
v21 = v10;
v22 = v78;
*(double *)&v78 = v21;
v82 = v12;
v85 = a2[1] + a2[1];
v23 = v5;
v24 = v20;
v80 = v23 * (double)v21;
v86 = a2[2] + a2[2];
v87 = v20 + v20;
*(double *)&v84 = *a1;
v25 = *(double *)&v84;
v26 = v6 * (double)v21;
v27 = a3[32];
v84 = v22 * v21;
*(double *)&v88 = v84;
v88 = *a1 + *a1;
*(double *)&v89 = a1[1];
v28 = *(double *)&v89;
v29 = a3[33];
*(double *)&v89 = v80;
v30 = v80;
v89 = a1[1] + a1[1];
v31 = a1[2];
v90 = v31 + v31;
*(double *)&v81 = v81 * -2.0 * v12 + (double)v12 * (double)v12 + v13 * v13;
v32 = *(double *)&v81;
*(double *)&v81 = v16 * (a2[1] * -2.0) + v14 * v14 + v15 * v15;
v33 = v32 + *(double *)&v81;
*(double *)&v81 = v24 * (-2.0 * a2[2]) + v18 * v18 + v19 * v19;
v34 = v33 + *(double *)&v81;
*(double *)&v82 = v33 + *(double *)&v81;
*(double *)&v81 = *a1 * v83 - a3[32] * v83 - v83 * v84 - *a1 * (v12 + v12) + a3[32] * (v12 + v12) + (v12 + v12) * v84;
v35 = a1[1] * v85 - a3[33] * v85 - v85 * v80 - a1[1] * (v16 + v16) + a3[33] * (v16 + v16) + (v16 + v16) * v80;
v36 = v80;
*(double *)&v80 = v35;
*(double *)&v80 = v79 * v87 + a1[2] * v86 - v86 * v79 - v86 * v26 - a1[2] * v87 + v87 * v26;
*(double *)&v81 = *(double *)&v81 + (double)v35 + *(double *)&v80;
v37 = a3[31];
v38 = *(double *)&v81 * *(double *)&v81
- ((double)(v84 * (a3[32] + a3[32]) + v25 * v25 + v27 * v27 + (double)v84 * (double)v84 - a3[32] * v88 - v88 * v84)
+ (double)(v36 * (a3[33] + a3[33]) + v29 * v29 + v28 * v28 + v30 * v30 - a3[33] * v89 - v89 * v36)
+ (double)(v26 * (v79 + v79)
+ (double)v79 * (double)v79
+ (double)v31 * (double)v31
+ (double)v26 * (double)v26
- v90 * v79
- v90 * v26)
- v37 * v37)
* (v34
* 4.0);
*(double *)&v79 = v38;
if ( v38 > 0.0005 )
{
if ( v38 < 0.0 )
{
*(double *)&v82 = *(double *)&v82 + *(double *)&v82;
*(double *)&v80 = (sqrt(*(double *)&v79) - *(double *)&v81) / *(double *)&v82;
*(_QWORD *)&v42 = *(_QWORD *)&v81 ^ LC4;
v41 = sqrt(*(double *)&v79);
}
else
{
v41 = sqrt(v38);
*(double *)&v82 = v34 + v34;
*(double *)&v80 = (v41 - *(double *)&v81) / (v34 + v34);
*(_QWORD *)&v42 = *(_QWORD *)&v81 ^ LC4;
}
*(double *)&v79 = (v42 - v41) / *(double *)&v82;
if ( *(double *)&v80 > 0.0005 )
{
v43 = *a1;
v44 = *a2;
v45 = a1[1];
v46 = a2[1];
v47 = a1[2];
v82 = a2[2];
qmemcpy(v95, a3, 0x4C0uLL);
v48 = a3[48];
if ( 0.0 == v48 && a3[49] == 0.0 )
{
v49 = v47;
v50 = v44;
v51 = v49;
LABEL_11:
v52 = v43 + v50 * *(double *)&v80;
v53 = v45 + v46 * *(double *)&v80;
v54 = v51 + v82 * *(double *)&v80;
v55 = v92 * *(double *)&v80 + v93;
v56 = a3[31];
v57 = (v53 - (a3[45] * v55 + a3[33])) / v56;
v58 = v55 * a3[46] + a3[34];
*(long double *)&v95[1168] = (v52 - (a3[44] * v55 + a3[32])) / v56;
*(long double *)&v95[1184] = v57;
*(long double *)&v95[1200] = (v54 - v58) / v56;
*(long double *)&v95[1120] = *(long double *)&v95[1168];
*(long double *)&v95[1136] = v57;
*(long double *)&v95[1152] = *(long double *)&v95[1200];
*(long double *)&v95[1216] = *(double *)&v80;
*(long double *)&v95[1232] = v52;
*(long double *)&v95[1248] = v53;
*(long double *)&v95[1264] = v54;
qmemcpy(v77, v95, sizeof(v77));
insertInOrder(a4);
goto LABEL_12;
}
*(double *)&v81 = v91 * *(double *)&v80 + *(double *)&v78;
if ( a3[49] >= *(double *)&v81 && *(double *)&v81 >= v48 )
{
v75 = v47;
v50 = v44;
v51 = v75;
goto LABEL_11;
}
}
LABEL_12:
if ( *(double *)&v79 <= 0.0005 )
return;
v59 = *a1;
v60 = *a2;
v61 = a1[1];
v62 = a2[1];
v63 = a1[2];
v80 = a2[2];
qmemcpy(v94, a3, 0x4C0uLL);
v64 = a3[48];
if ( 0.0 == v64 && a3[49] == 0.0 )
{
v65 = v63;
v66 = v60;
v67 = v65;
}
else
{
*(double *)&v78 = v91 * *(double *)&v79 + *(double *)&v78;
if ( a3[49] < *(double *)&v78 || *(double *)&v78 < v64 )
return;
v76 = v63;
v66 = v60;
v67 = v76;
}
v68 = v59 + v66 * *(double *)&v79;
v69 = v61 + v62 * *(double *)&v79;
v70 = v67 + v80 * *(double *)&v79;
v71 = v92 * *(double *)&v79 + v93;
v72 = a3[31];
v73 = (v69 - (a3[45] * v71 + a3[33])) / v72;
v74 = v71 * a3[46] + a3[34];
*(long double *)&v94[1168] = (v68 - (a3[44] * v71 + a3[32])) / v72;
*(long double *)&v94[1184] = v73;
*(long double *)&v94[1200] = (v70 - v74) / v72;
*(long double *)&v94[1120] = *(long double *)&v94[1168];
*(long double *)&v94[1136] = v73;
*(long double *)&v94[1152] = *(long double *)&v94[1200];
*(long double *)&v94[1216] = *(double *)&v79;
*(long double *)&v94[1232] = v68;
*(long double *)&v94[1248] = v69;
*(long double *)&v94[1264] = v70;
qmemcpy(v77, v94, sizeof(v77));
insertInOrder(a4);
}
}

original_code:
void cylinderInterseption(VECTOR *eyePosition, VECTOR *rayFromEyeDirection, OBJECT *cylinder, LIST_NODE_PTR *intersections) {
    INTERSECTION intersectionOne, intersectionTwo;
    double a_partCommon, b_partCommon;
    double ax, bx, cx, ay, by, cy, az, bz, cz;
    int insertIntersectionOne = 0, insertIntersectionTwo = 0;
    a_partCommon = rayFromEyeDirection->x * cylinder->cylinder.vectorQ.x + rayFromEyeDirection->y * cylinder->cylinder.vectorQ.y + rayFromEyeDirection->z * cylinder->cylinder.vectorQ.z;
    b_partCommon = cylinder->cylinder.vectorQ.x * (eyePosition->x - cylinder->cylinder.position.x) +
            cylinder->cylinder.vectorQ.y * (eyePosition->y - cylinder->cylinder.position.y) +
            cylinder->cylinder.vectorQ.z * (eyePosition->z - cylinder->cylinder.position.z);
    ax = -2 * rayFromEyeDirection->x * (a_partCommon * cylinder->cylinder.vectorQ.x) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.x, 2) + pow(rayFromEyeDirection->x, 2);
    ay = -2 * rayFromEyeDirection->y * (a_partCommon * cylinder->cylinder.vectorQ.y) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.y, 2) + pow(rayFromEyeDirection->y, 2);
    az = -2 * rayFromEyeDirection->z * (a_partCommon * cylinder->cylinder.vectorQ.z) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.z, 2) + pow(rayFromEyeDirection->z, 2);
    bx = 2 * rayFromEyeDirection->x * eyePosition->x - 2 * rayFromEyeDirection->x * cylinder->cylinder.position.x - 2 * rayFromEyeDirection->x * (b_partCommon * cylinder->cylinder.vectorQ.x)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * eyePosition->x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * cylinder->cylinder.position.x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * (b_partCommon * cylinder->cylinder.vectorQ.x);
    by = 2 * rayFromEyeDirection->y * eyePosition->y - 2 * rayFromEyeDirection->y * cylinder->cylinder.position.y - 2 * rayFromEyeDirection->y * (b_partCommon * cylinder->cylinder.vectorQ.y)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * eyePosition->y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * cylinder->cylinder.position.y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * (b_partCommon * cylinder->cylinder.vectorQ.y);
    bz = 2 * rayFromEyeDirection->z * eyePosition->z - 2 * rayFromEyeDirection->z * cylinder->cylinder.position.z - 2 * rayFromEyeDirection->z * (b_partCommon * cylinder->cylinder.vectorQ.z)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * eyePosition->z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * cylinder->cylinder.position.z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * (b_partCommon * cylinder->cylinder.vectorQ.z);
    cx = pow(eyePosition->x, 2) + pow(cylinder->cylinder.position.x, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.x, 2)
            - 2 * eyePosition->x * cylinder->cylinder.position.x - 2 * eyePosition->x * (b_partCommon * cylinder->cylinder.vectorQ.x) + 2 * cylinder->cylinder.position.x * (b_partCommon * cylinder->cylinder.vectorQ.x);
    cy = pow(eyePosition->y, 2) + pow(cylinder->cylinder.position.y, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.y, 2)
            - 2 * eyePosition->y * cylinder->cylinder.position.y - 2 * eyePosition->y * (b_partCommon * cylinder->cylinder.vectorQ.y) + 2 * cylinder->cylinder.position.y * (b_partCommon * cylinder->cylinder.vectorQ.y);
    cz = pow(eyePosition->z, 2) + pow(cylinder->cylinder.position.z, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.z, 2)
            - 2 * eyePosition->z * cylinder->cylinder.position.z - 2 * eyePosition->z * (b_partCommon * cylinder->cylinder.vectorQ.z) + 2 * cylinder->cylinder.position.z * (b_partCommon * cylinder->cylinder.vectorQ.z);
    double a_final, b_final, c_final, discriminating, t1, t2;
    a_final = ax + ay + az;
    b_final = bx + by + bz;
    c_final = (cx + cy + cz) - pow(cylinder->cylinder.radius, 2);
    discriminating = pow(b_final, 2) - 4 * a_final * c_final;
    if (discriminating > 0.0005) {
        t1 = (-1 * b_final + sqrt(discriminating)) / (2 * a_final);
        t2 = (-1 * b_final - sqrt(discriminating)) / (2 * a_final);
        if (t1 > 0.0005) {
            intersectionOne.intersection.x = eyePosition->x + t1 * rayFromEyeDirection->x;
            intersectionOne.intersection.y = eyePosition->y + t1 * rayFromEyeDirection->y;
            intersectionOne.intersection.z = eyePosition->z + t1 * rayFromEyeDirection->z;
            intersectionOne.t = t1;
            intersectionOne.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t1 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionOne = 1;
                }
            } else {
                insertIntersectionOne = 1;
            }
            if (insertIntersectionOne == 1) {
                intersectionOne.object.normal.x = (intersectionOne.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.y = (intersectionOne.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.z = (intersectionOne.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.dependedNormal = intersectionOne.object.normal;
                insertInOrder(intersections, intersectionOne);
            }
        }
        if (t2 > 0.0005) {
            intersectionTwo.intersection.x = eyePosition->x + t2 * rayFromEyeDirection->x;
            intersectionTwo.intersection.y = eyePosition->y + t2 * rayFromEyeDirection->y;
            intersectionTwo.intersection.z = eyePosition->z + t2 * rayFromEyeDirection->z;
            intersectionTwo.t = t2;
            intersectionTwo.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t2 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionTwo = 1;
                }
            } else {
                insertIntersectionTwo = 1;
            }
            if (insertIntersectionTwo == 1) {
                intersectionTwo.object.normal.x = (intersectionTwo.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.y = (intersectionTwo.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.z = (intersectionTwo.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.dependedNormal = intersectionTwo.object.normal;
                insertInOrder(intersections, intersectionTwo);
            }
        }
    }
}

canonical_original_code:
void cylinderInterseption(struct VECTOR *eyePosition, struct VECTOR *rayFromEyeDirection, struct OBJECT *cylinder, struct listNode **intersections) {
    struct INTERSECTION intersectionOne; struct INTERSECTION intersectionTwo;
    double a_partCommon; double b_partCommon;
    double ax; double bx; double cx; double ay; double by; double cy; double az; double bz; double cz;
    int insertIntersectionOne = 0; int insertIntersectionTwo = 0;
    a_partCommon = rayFromEyeDirection->x * cylinder->cylinder.vectorQ.x + rayFromEyeDirection->y * cylinder->cylinder.vectorQ.y + rayFromEyeDirection->z * cylinder->cylinder.vectorQ.z;
    b_partCommon = cylinder->cylinder.vectorQ.x * (eyePosition->x - cylinder->cylinder.position.x) +
            cylinder->cylinder.vectorQ.y * (eyePosition->y - cylinder->cylinder.position.y) +
            cylinder->cylinder.vectorQ.z * (eyePosition->z - cylinder->cylinder.position.z);
    ax = -2 * rayFromEyeDirection->x * (a_partCommon * cylinder->cylinder.vectorQ.x) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.x, 2) + pow(rayFromEyeDirection->x, 2);
    ay = -2 * rayFromEyeDirection->y * (a_partCommon * cylinder->cylinder.vectorQ.y) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.y, 2) + pow(rayFromEyeDirection->y, 2);
    az = -2 * rayFromEyeDirection->z * (a_partCommon * cylinder->cylinder.vectorQ.z) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.z, 2) + pow(rayFromEyeDirection->z, 2);
    bx = 2 * rayFromEyeDirection->x * eyePosition->x - 2 * rayFromEyeDirection->x * cylinder->cylinder.position.x - 2 * rayFromEyeDirection->x * (b_partCommon * cylinder->cylinder.vectorQ.x)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * eyePosition->x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * cylinder->cylinder.position.x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * (b_partCommon * cylinder->cylinder.vectorQ.x);
    by = 2 * rayFromEyeDirection->y * eyePosition->y - 2 * rayFromEyeDirection->y * cylinder->cylinder.position.y - 2 * rayFromEyeDirection->y * (b_partCommon * cylinder->cylinder.vectorQ.y)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * eyePosition->y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * cylinder->cylinder.position.y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * (b_partCommon * cylinder->cylinder.vectorQ.y);
    bz = 2 * rayFromEyeDirection->z * eyePosition->z - 2 * rayFromEyeDirection->z * cylinder->cylinder.position.z - 2 * rayFromEyeDirection->z * (b_partCommon * cylinder->cylinder.vectorQ.z)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * eyePosition->z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * cylinder->cylinder.position.z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * (b_partCommon * cylinder->cylinder.vectorQ.z);
    cx = pow(eyePosition->x, 2) + pow(cylinder->cylinder.position.x, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.x, 2)
            - 2 * eyePosition->x * cylinder->cylinder.position.x - 2 * eyePosition->x * (b_partCommon * cylinder->cylinder.vectorQ.x) + 2 * cylinder->cylinder.position.x * (b_partCommon * cylinder->cylinder.vectorQ.x);
    cy = pow(eyePosition->y, 2) + pow(cylinder->cylinder.position.y, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.y, 2)
            - 2 * eyePosition->y * cylinder->cylinder.position.y - 2 * eyePosition->y * (b_partCommon * cylinder->cylinder.vectorQ.y) + 2 * cylinder->cylinder.position.y * (b_partCommon * cylinder->cylinder.vectorQ.y);
    cz = pow(eyePosition->z, 2) + pow(cylinder->cylinder.position.z, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.z, 2)
            - 2 * eyePosition->z * cylinder->cylinder.position.z - 2 * eyePosition->z * (b_partCommon * cylinder->cylinder.vectorQ.z) + 2 * cylinder->cylinder.position.z * (b_partCommon * cylinder->cylinder.vectorQ.z);
    double a_final; double b_final; double c_final; double discriminating; double t1; double t2;
    a_final = ax + ay + az;
    b_final = bx + by + bz;
    c_final = (cx + cy + cz) - pow(cylinder->cylinder.radius, 2);
    discriminating = pow(b_final, 2) - 4 * a_final * c_final;
    if (discriminating > 0.0005) {
        t1 = (-1 * b_final + sqrt(discriminating)) / (2 * a_final);
        t2 = (-1 * b_final - sqrt(discriminating)) / (2 * a_final);
        if (t1 > 0.0005) {
            intersectionOne.intersection.x = eyePosition->x + t1 * rayFromEyeDirection->x;
            intersectionOne.intersection.y = eyePosition->y + t1 * rayFromEyeDirection->y;
            intersectionOne.intersection.z = eyePosition->z + t1 * rayFromEyeDirection->z;
            intersectionOne.t = t1;
            intersectionOne.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t1 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionOne = 1;
                }
            } else {
                insertIntersectionOne = 1;
            }
            if (insertIntersectionOne == 1) {
                intersectionOne.object.normal.x = (intersectionOne.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.y = (intersectionOne.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.z = (intersectionOne.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.dependedNormal = intersectionOne.object.normal;
                insertInOrder(intersections, intersectionOne);
            }
        }
        if (t2 > 0.0005) {
            intersectionTwo.intersection.x = eyePosition->x + t2 * rayFromEyeDirection->x;
            intersectionTwo.intersection.y = eyePosition->y + t2 * rayFromEyeDirection->y;
            intersectionTwo.intersection.z = eyePosition->z + t2 * rayFromEyeDirection->z;
            intersectionTwo.t = t2;
            intersectionTwo.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t2 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionTwo = 1;
                }
            } else {
                insertIntersectionTwo = 1;
            }
            if (insertIntersectionTwo == 1) {
                intersectionTwo.object.normal.x = (intersectionTwo.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.y = (intersectionTwo.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.z = (intersectionTwo.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.dependedNormal = intersectionTwo.object.normal;
                insertInOrder(intersections, intersectionTwo);
            }
        }
    }
}

variable_types: struct VECTOR { long double x; long double y; long double z; } *

variable_types:
rayFromEyeDirection
struct VECTOR *

variable_types: struct OBJECT { struct RGB { float r; float g; float b; } color; long double diffusionCoefficient_Kd; long double ambientLightingCoefficient_Ka; long double specularReflexionCoeffient_Ks; long double specularReflexionRefinement_Kn; long double O1; long double O2; long double O3; long double translucencyCoefficient_kt; long double componentD; long double dependedComponentD; enum OBJECT_TYPE { LIGHT=0, SPHERE=1, POLYGON=2, DISK=3, CYLINDER=4, CONE=5, PLANE=6 } type; struct OBJECT_SPHERE { long double radius; struct VECTOR position; } sphere; struct OBJECT_POLYGON { void *listOfPointsPtr; void *listOfPointsSplashPtr; } polygon; struct OBJECT_DISK { long double radiusOne; long double radiusTwo; struct VECTOR position; struct POINT { long double x; long double y; long double z; } point1; struct POINT point2; struct POINT point3; } disk; struct OBJECT_CYLINDER { long double radius; struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; } cylinder; struct OBJECT_CONE { struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; long double uRatio; long double vRatio; } cone; struct VECTOR normal; struct VECTOR dependedNormal; } *

variable_types: struct listNode { struct NODE_DATA { struct OBJECT object; struct LIGHT_POINT { struct VECTOR position; long double intensity_Ip; long double c1; long double c2; long double c3; } light; struct POINT point; struct INTERSECTION { struct OBJECT object; long double t; struct VECTOR intersection; } intersection; } data; struct listNode *nextPtr; } **

variable_types: struct INTERSECTION { struct OBJECT { struct RGB { float r; float g; float b; } color; long double diffusionCoefficient_Kd; long double ambientLightingCoefficient_Ka; long double specularReflexionCoeffient_Ks; long double specularReflexionRefinement_Kn; long double O1; long double O2; long double O3; long double translucencyCoefficient_kt; long double componentD; long double dependedComponentD; enum OBJECT_TYPE { LIGHT=0, SPHERE=1, POLYGON=2, DISK=3, CYLINDER=4, CONE=5, PLANE=6 } type; struct OBJECT_SPHERE { long double radius; struct VECTOR { long double x; long double y; long double z; } position; } sphere; struct OBJECT_POLYGON { void *listOfPointsPtr; void *listOfPointsSplashPtr; } polygon; struct OBJECT_DISK { long double radiusOne; long double radiusTwo; struct VECTOR position; struct POINT { long double x; long double y; long double z; } point1; struct POINT point2; struct POINT point3; } disk; struct OBJECT_CYLINDER { long double radius; struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; } cylinder; struct OBJECT_CONE { struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; long double uRatio; long double vRatio; } cone; struct VECTOR normal; struct VECTOR dependedNormal; } object; long double t; struct VECTOR intersection; }

variable_types: ax double

variable_types: bx double

variable_types: cx double

variable_types: ay double

variable_types: by double

variable_types: cy double

variable_types: az double

variable_types: bz double

variable_types: cz double

variable_types: insertIntersectionOne int

variable_types: insertIntersectionTwo int

variable_types: discriminating double

user_defined_types: struct OBJECT { struct RGB color; long double diffusionCoefficient_Kd; long double ambientLightingCoefficient_Ka; long double specularReflexionCoeffient_Ks; long double specularReflexionRefinement_Kn; long double O1; long double O2; long double O3; long double translucencyCoefficient_kt; long double componentD; long double dependedComponentD; enum OBJECT_TYPE type; struct OBJECT_SPHERE sphere; struct OBJECT_POLYGON polygon; struct OBJECT_DISK disk; struct OBJECT_CYLINDER cylinder; struct OBJECT_CONE cone; struct VECTOR normal; struct VECTOR dependedNormal; }

user_defined_types: struct OBJECT_DISK { long double radiusOne; long double radiusTwo; struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; }

user_defined_types: struct listNode { struct NODE_DATA data; struct listNode *nextPtr; }

user_defined_types: struct NODE_DATA { struct OBJECT object; struct LIGHT_POINT light; struct POINT point; struct INTERSECTION intersection; }


testsimple

repo: josephburns/map

decompiled_code:
__int64 testsimple()
{
void *ptr; // [rsp+0h] [rbp-18h] BYREF
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = 0LL;
ptr = 0LL;
puts("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n");
map_init(v2, 0LL);
kv_put(v2, "fred", "flinstone");
kv_get(v2[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %s\n", (const char *)ptr);
free(ptr);
}
ptr = 0LL;
kv_put(v2, "fred", "flanders");
kv_get(v2[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %s\n", (const char *)ptr);
free(ptr);
}
ptr = 0LL;
kv_remove(v2[0], "fred");
kv_get(v2[0], "fred", &ptr);
if ( ptr )
free(ptr);
else
printf("after remove: get fred = %s\n", "(null)");
ptr = 0LL;
return map_destroy(v2[0]);
}

canonical_decompiled_code:
__int64 func0()
{
void *ptr; // [rsp+0h] [rbp-18h] BYREF
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = 0LL;
ptr = 0LL;
puts("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n");
map_init(v2, 0LL);
kv_put(v2, "fred", "flinstone");
kv_get(v2[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %s\n", (const char *)ptr);
free(ptr);
}
ptr = 0LL;
kv_put(v2, "fred", "flanders");
kv_get(v2[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %s\n", (const char *)ptr);
free(ptr);
}
ptr = 0LL;
kv_remove(v2[0], "fred");
kv_get(v2[0], "fred", &ptr);
if ( ptr )
free(ptr);
else
printf("after remove: get fred = %s\n", "(null)");
ptr = 0LL;
return map_destroy(v2[0]);
}

original_code:
void testsimple(void) {
 map *testmap = ((void *)0);
 char *getresult = ((void *)0);
 status code1, code2, code3, code4;
 printf("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   code2 = kv_put(&testmap,"fred","flinstone");
   code3 = kv_get(testmap,"fred", (void**)&getresult);
   if(getresult != ((void *)0)) {
      printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   code2 = kv_put(&testmap,"fred","flanders");
   code3 = kv_get(testmap,"fred", (void**)&getresult);
   if(getresult != ((void *)0)) {
    printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
 kv_remove(testmap,"fred");
   code3= kv_get(testmap,"fred", (void**)&getresult);
   if(getresult == ((void *)0)) {
      printf("after remove: get fred = %s\n", ((getresult!=((void *)0))?getresult:"(null)"));
   }
   else free(getresult);
   getresult = ((void *)0);
 code4 = map_destroy(testmap);
}

canonical_original_code:
void testsimple() {
 struct map *testmap = ((void *)0);
 char *getresult = ((void *)0);
 enum status code1; enum status code2; enum status code3; enum status code4;
 printf("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   code2 = kv_put(&testmap,"fred","flinstone");
   code3 = kv_get(testmap,"fred", (void **)&getresult);
   if(getresult != ((void *)0)) {
      printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   code2 = kv_put(&testmap,"fred","flanders");
   code3 = kv_get(testmap,"fred", (void **)&getresult);
   if(getresult != ((void *)0)) {
    printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
 kv_remove(testmap,"fred");
   code3= kv_get(testmap,"fred", (void **)&getresult);
   if(getresult == ((void *)0)) {
      printf("after remove: get fred = %s\n", ((getresult!=((void *)0))?getresult:"(null)"));
   }
   else free(getresult);
   getresult = ((void *)0);
 code4 = map_destroy(testmap);
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } *

variable_types:
getresult
char *

user_defined_types: struct map { struct bucket *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status type; }

user_defined_types: struct bucket { struct kvpair *start; unsigned long index; long count; }


testsimplelong

decompiled_code:
__int64 testsimplelong()
{
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
void *ptr; // [rsp+10h] [rbp-18h] BYREF
__int64 v3[2]; // [rsp+18h] [rbp-10h] BYREF

v3[0] = 0LL;
v1 = 35LL;
puts("\n\nTesting chptr-long map simple map functions...\n");
map_init(v3, 1LL);
kv_put(v3, "fred", &v1);
kv_get(v3[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
v1 = 53LL;
kv_put(v3, "fred", &v1);
kv_get(v3[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
kv_remove(v3[0], "fred");
kv_get(v3[0], "fred", &ptr);
if ( ptr )
{
puts("remove failed!");
free(ptr);
}
else
{
puts("get fred after remove = (null)");
}
ptr = 0LL;
return map_destroy(v3[0]);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
void *ptr; // [rsp+10h] [rbp-18h] BYREF
__int64 v3[2]; // [rsp+18h] [rbp-10h] BYREF

v3[0] = 0LL;
v1 = 35LL;
puts("\n\nTesting chptr-long map simple map functions...\n");
map_init(v3, 1LL);
kv_put(v3, "fred", &v1);
kv_get(v3[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
v1 = 53LL;
kv_put(v3, "fred", &v1);
kv_get(v3[0], "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
kv_remove(v3[0], "fred");
kv_get(v3[0], "fred", &ptr);
if ( ptr )
{
puts("remove failed!");
free(ptr);
}
else
{
puts("get fred after remove = (null)");
}
ptr = 0LL;
return map_destroy(v3[0]);
}

original_code:
void testsimplelong(void) {
   map *testmap = ((void *)0);
   long *getresult, putarg = 35;
   status code1,code2,code3,code4;
   printf("\n\nTesting chptr-long map simple map functions...\n\n");
   code1 = map_init(&testmap, CHPTR_LONG);
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void**)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   putarg = 53;
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void**)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   kv_remove(testmap,"fred");
   code3 = kv_get(testmap, "fred", (void**)&getresult);
   if(getresult==((void *)0)) {
      printf("get fred after remove = (null)\n");
   }
   else {
      printf("remove failed!\n");
      free(getresult);
   }
   getresult = ((void *)0);
   code4 = map_destroy(testmap);
}

canonical_original_code:
void testsimplelong() {
   struct map *testmap = ((void *)0);
   long *getresult; long putarg = 35;
   enum status code1; enum status code2; enum status code3; enum status code4;
   printf("\n\nTesting chptr-long map simple map functions...\n\n");
   code1 = map_init(&testmap, CHPTR_LONG);
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void **)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   putarg = 53;
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void **)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   kv_remove(testmap,"fred");
   code3 = kv_get(testmap, "fred", (void **)&getresult);
   if(getresult==((void *)0)) {
      printf("get fred after remove = (null)\n");
   }
   else {
      printf("remove failed!\n");
      free(getresult);
   }
   getresult = ((void *)0);
   code4 = map_destroy(testmap);
}

variable_types:
getresult
long *

variable_types: putarg long

variable_types: enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 }

user_defined_types: struct kvpair { void *key; void *value; struct kvpair *next; }


testnotsosimple

decompiled_code:
__int64 testnotsosimple()
{
__int64 v0; // r12
char *v1; // r14
char *v2; // rax
char *v3; // r13
char *v4; // rbx
char *v5; // rbp
__int64 v6; // r12
char v7; // cl
unsigned __int64 v8; // rbx
unsigned int i; // [rsp+4h] [rbp-54h]
__int64 v11; // [rsp+8h] [rbp-50h]
void *ptr; // [rsp+10h] [rbp-48h] BYREF
__int64 v13[8]; // [rsp+18h] [rbp-40h] BYREF

ptr = 0LL;
puts("\n\ntesting keys...\n");
map_init(v13, 0LL);
for ( i = 0; i != 25; ++i )
{
v0 = random() % 25;
v11 = (int)v0 + 1;
v1 = (char *)malloc((int)v0 + 2);
v2 = (char *)malloc((int)v0 + 2);
v3 = v2;
if ( (int)v0 + 1 > 0 )
{
v4 = v2;
v5 = v1;
v6 = (__int64)&v2[(unsigned int)v0 + 1];
do
{
v7 = random() % 26 + 97;
*v4 = v7;
*v5 = v7;
++v4;
++v5;
}
while ( v4 != (char *)v6 );
}
v3[v11] = 0;
v1[v11] = 0;
printf("%d - inserting key: %s, value: %s\n", i, v1, v3);
kv_put(v13, v1, v3);
if ( v1 )
free(v1);
if ( v3 )
free(v3);
}
map_keys(v13[0], &ptr);
if ( *(_QWORD *)(v13[0] + 16) )
{
v8 = 0LL;
do
{
printf("key %d: %s\n", (unsigned int)v8, *((const char **)ptr + v8));
++v8;
}
while ( *(_QWORD *)(v13[0] + 16) > v8 );
}
if ( ptr )
free(ptr);
return map_destroy(v13[0]);
}

original_code:
void testnotsosimple(void) {
 map *testmap;
 int i,j,k,t;
   int code1,code2,code3;
 char *key=((void *)0),*value=((void *)0),**thekeys=((void *)0);
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char*)malloc(sizeof(char) * t + 1);
  value = (char*)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = *(value+k) = 97 + j;
      }
  *(key+t) = *(value+t) = 0x00;
      printf("%d - inserting key: %s, value: %s\n",i,key,value);
  code2 = kv_put(&testmap,key,value);
      if(key!=((void *)0))
         free((void*)key);
      if(value!=((void *)0))
         free((void*)value);
      key = value = ((void *)0);
 }
 map_keys(testmap,(void***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

canonical_original_code:
void testnotsosimple() {
 struct map *testmap;
 int i; int j; int k; int t;
   int code1; int code2; int code3;
 char *key = ((void *)0); char *value = ((void *)0); char **thekeys = ((void *)0);
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char *)malloc(sizeof(char) * t + 1);
  value = (char *)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = *(value+k) = 97 + j;
      }
  *(key+t) = *(value+t) = 0x00;
      printf("%d - inserting key: %s, value: %s\n",i,key,value);
  code2 = kv_put(&testmap,key,value);
      if(key!=((void *)0))
         free((void *)key);
      if(value!=((void *)0))
         free((void *)value);
      key = value = ((void *)0);
 }
 map_keys(testmap,(void ***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: t int

variable_types:
key
char *

variable_types:
value
char *

variable_types:
thekeys
char **

user_defined_types: enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 }


testnotsosimplelong

decompiled_code:
__int64 testnotsosimplelong()
{
unsigned int i; // er13
__int64 v1; // rbx
__int64 v2; // r15
char *v3; // rax
char *v4; // rbp
char *v5; // r14
__int64 v6; // rbx
__int64 v7; // rcx
unsigned __int64 v8; // rbx
int v10; // [rsp+Ch] [rbp-5Ch]
__int64 v11; // [rsp+18h] [rbp-50h] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF
__int64 v13[8]; // [rsp+28h] [rbp-40h] BYREF

ptr = 0LL;
puts("\n\ntesting keys...\n");
map_init(v13, 1LL);
for ( i = 0; i != 25; ++i )
{
v1 = random() % 25;
v2 = (int)v1 + 1;
v3 = (char *)malloc((int)v1 + 2);
v4 = v3;
if ( (int)v1 + 1 > 0 )
{
v5 = v3;
v6 = (__int64)&v3[(unsigned int)v1 + 1];
do
{
v7 = random() % 26;
*v5++ = v7 + 97;
}
while ( (char *)v6 != v5 );
v10 = v7;
}
v11 = v10;
v4[v2] = 0;
printf("%d - inserting key: %s, value: %ld\n", i, v4, v10);
kv_put(v13, v4, &v11);
if ( v4 )
free(v4);
}
map_keys(v13[0], &ptr);
if ( *(_QWORD *)(v13[0] + 16) )
{
v8 = 0LL;
do
{
printf("key %d: %s\n", (unsigned int)v8, *((const char **)ptr + v8));
++v8;
}
while ( *(_QWORD *)(v13[0] + 16) > v8 );
}
if ( ptr )
free(ptr);
return map_destroy(v13[0]);
}

original_code:
void testnotsosimplelong(void) {
 map *testmap;
 int i,j,k,t;
   int code1,code2,code3;
 char *key=((void *)0),**thekeys=((void *)0);
   long value;
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_LONG);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char*)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = 97 + j;
      }
      value = (long)j;
  *(key+t) = 0x00;
      printf("%d - inserting key: %s, value: %ld\n",i,key,value);
  code2 = kv_put(&testmap,key,&value);
      if(key!=((void *)0))
         free((void*)key);
      key = ((void *)0);
 }
 map_keys(testmap,(void***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

canonical_original_code:
void testnotsosimplelong() {
 struct map *testmap;
 int i; int j; int k; int t;
   int code1; int code2; int code3;
 char *key = ((void *)0); char **thekeys = ((void *)0);
   long value;
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_LONG);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char *)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = 97 + j;
      }
      value = (long)j;
  *(key+t) = 0x00;
      printf("%d - inserting key: %s, value: %ld\n",i,key,value);
  code2 = kv_put(&testmap,key,&value);
      if(key!=((void *)0))
         free((void *)key);
      key = ((void *)0);
 }
 map_keys(testmap,(void ***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

variable_types: value long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
testsimple(argc, argv, envp);
testnotsosimple();
testsimplelong();
testnotsosimplelong();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
func2();
func1();
func3();
return 0;
}

original_code:
int main(void) {
   testsimple();
   testnotsosimple();
   testsimplelong();
   testnotsosimplelong();
   return 0;
}

canonical_original_code:
int main() {
   testsimple();
   testnotsosimple();
   testsimplelong();
   testnotsosimplelong();
   return 0;
}