decompiled_code:
__int64 __fastcall get_index_prev_path(const char **a1, const char *a2)
{
int v2; // er13
unsigned int v4; // er12

v2 = count;
if ( count <= 0 )
return 0xFFFFFFFFLL;
v4 = 0;
while ( strcmp(*a1, a2) )
{
++v4;
a1 += 2;
if ( v4 == v2 )
return 0xFFFFFFFFLL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char **a1, const char *a2)
{
int v2; // er13
unsigned int v4; // er12

v2 = count;
if ( count <= 0 )
return 0xFFFFFFFFLL;
v4 = 0;
while ( strcmp(*a1, a2) )
{
++v4;
a1 += 2;
if ( v4 == v2 )
return 0xFFFFFFFFLL;
}
return v4;
}

original_code:
int get_index_prev_path(prev_path *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int get_index_prev_path(struct prev_path *a, char *dpid) {
 int i;
 for(i = 0; i < count; i++) {
  if(strcmp(a[i].dpid,dpid) == 0){
   return i;
  }
 }
 return -1;
}

user_defined_types: struct prev_path { char *dpid; char *path_dpid; }


decompiled_code:
int print_init_djk()
{
int result; // eax
__int64 v1; // rbp
__int64 v2; // rbx

puts("\n STRUCT ARRAY VALUES: ");
printf("\n Count value in print - %d", (unsigned int)count);
result = count;
if ( count > 0 )
{
v1 = 0LL;
do
{
v2 = v1++;
v2 *= 16LL;
printf("PREV dpid - %s\tW - %s\n", *(const char **)(v2 + prev), *(const char **)(v2 + prev + 8));
printf("DONE dpid - %s W - %d\n", *(const char **)(v2 + done), *(unsigned int *)(v2 + done + 8));
result = printf("DIST dpid - %s W - %d\n", *(const char **)(dist + v2), *(unsigned int *)(dist + v2 + 8));
}
while ( count > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax
__int64 v1; // rbp
__int64 v2; // rbx

puts("\n STRUCT ARRAY VALUES: ");
printf("\n Count value in print - %d", (unsigned int)count);
result = count;
if ( count > 0 )
{
v1 = 0LL;
do
{
v2 = v1++;
v2 *= 16LL;
printf("PREV dpid - %s\tW - %s\n", *(const char **)(v2 + prev), *(const char **)(v2 + prev + 8));
printf("DONE dpid - %s W - %d\n", *(const char **)(v2 + done), *(unsigned int *)(v2 + done + 8));
result = printf("DIST dpid - %s W - %d\n", *(const char **)(dist + v2), *(unsigned int *)(dist + v2 + 8));
}
while ( count > (int)v1 );
}
return result;
}

original_code:
void print_init_djk(void){
 int i;
 printf("\n STRUCT ARRAY VALUES: \n");
 printf("\n Count value in print - %d",count);
 for(i = 0; i < count; i++) {
  printf("PREV dpid - %s	W - %s\n",prev[i].dpid,prev[i].path_dpid);
  printf("DONE dpid - %s  W - %d\n",done[i].dpid,done[i].w);
  printf("DIST dpid - %s  W - %d\n",dist[i].dpid,dist[i].w);
 }
}

canonical_original_code:
void print_init_djk(){
 int i;
 printf("\n STRUCT ARRAY VALUES: \n");
 printf("\n Count value in print - %d",count);
 for(i = 0; i < count; i++) {
  printf("PREV dpid - %s	W - %s\n",prev[i].dpid,prev[i].path_dpid);
  printf("DONE dpid - %s  W - %d\n",done[i].dpid,done[i].w);
  printf("DIST dpid - %s  W - %d\n",dist[i].dpid,dist[i].w);
 }
}

variable_types: i int

return_type: void


decompiled_code:
int print_array_list()
{
int result; // eax
__int64 v1; // rbx
__int64 v2; // rax

result = count;
if ( count > 0 )
{
v1 = 0LL;
do
{
v2 = v1++;
result = printf("dpid - %s w - %d\n", *(const char **)(dist + 16 * v2), *(unsigned int *)(dist + 16 * v2 + 8));
}
while ( count > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
__int64 v1; // rbx
__int64 v2; // rax

result = count;
if ( count > 0 )
{
v1 = 0LL;
do
{
v2 = v1++;
result = printf("dpid - %s w - %d\n", *(const char **)(dist + 16 * v2), *(unsigned int *)(dist + 16 * v2 + 8));
}
while ( count > (int)v1 );
}
return result;
}

original_code:
void print_array_list(list_array *a){
 int i = 0;
 for(i = 0; i < count; i++)
  printf("dpid - %s w - %d\n",dist[i].dpid,dist[i].w);
}

canonical_original_code:
void print_array_list(struct list *a){
 int i = 0;
 for(i = 0; i < count; i++)
  printf("dpid - %s w - %d\n",dist[i].dpid,dist[i].w);
}

variable_types:
a
struct list { char *dpid; int w; } *


dijkstra

decompiled_code:
__int64 __fastcall dijkstra(const char *a1)
{
__int64 result; // rax
int v2; // er13
__int64 v3; // rcx
__int64 v4; // rax
__int64 v5; // rcx
__int64 i; // r12
__int64 j; // rbx
const char *v8; // rbp
__int64 v9; // r15
int v10; // er14
const char **v11; // rbp
const char *v12; // rsi
char *s2; // [rsp+0h] [rbp-48h]
int v14; // [rsp+Ch] [rbp-3Ch]

s2 = (char *)malloc(0x30uLL);
count = num_switches(graph);
prev = (__int64)init_prev_path();
done = (__int64)init_list_array(0);
dist = (__int64)init_list_array(9999);
v14 = set_val_list_array(dist, a1, 0);
if ( v14 )
{
printf("\n Error in setting dist list array value to - %d\n", 0LL);
exit(0);
}
result = (unsigned int)count;
if ( count > 1 )
{
do
{
v2 = 9999;
if ( (int)result > 0 )
{
v3 = (unsigned int)(result - 1);
v4 = 8LL;
v2 = 9999;
v5 = 16 * v3 + 24;
do
{
if ( *(_DWORD *)(dist + v4) < v2 && !*(_DWORD *)(done + v4) )
{
v2 = *(_DWORD *)(dist + v4);
s2 = *(char **)(dist + v4 - 8);
}
v4 += 16LL;
}
while ( v5 != v4 );
}
set_val_list_array(done, s2, 1);
for ( i = graph; i; i = *(_QWORD *)(i + 8) )
{
if ( !strcmp(*(const char **)i, s2) )
{
for ( j = *(_QWORD *)(i + 16); j; j = *(_QWORD *)(j + 16) )
{
v8 = *(const char **)j;
if ( !(unsigned int)get_val_list_array(done, *(const char **)j) )
{
v9 = dist;
v10 = v2 + *(_DWORD *)(j + 8);
if ( v10 < (int)get_val_list_array(dist, v8) )
{
if ( (unsigned int)set_val_list_array(v9, v8, v10) )
{
puts("\n Error in setting dist value");
exit(0);
}
v11 = (const char **)prev;
v12 = *(const char **)j;
*(_DWORD *)(j + 12) = *(_DWORD *)(j + 8);
v11[2 * (int)get_index_prev_path(v11, v12) + 1] = s2;
}
}
}
}
}
result = (unsigned int)count;
++v14;
}
while ( count - 1 > v14 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
__int64 result; // rax
int v2; // er13
__int64 v3; // rcx
__int64 v4; // rax
__int64 v5; // rcx
__int64 i; // r12
__int64 j; // rbx
const char *v8; // rbp
__int64 v9; // r15
int v10; // er14
const char **v11; // rbp
const char *v12; // rsi
char *s2; // [rsp+0h] [rbp-48h]
int v14; // [rsp+Ch] [rbp-3Ch]

s2 = (char *)malloc(0x30uLL);
count = func0(graph);
prev = (__int64)func1();
done = (__int64)init_list_array(0);
dist = (__int64)init_list_array(9999);
v14 = func2(dist, a1, 0);
if ( v14 )
{
printf("\n Error in setting dist list array value to - %d\n", 0LL);
exit(0);
}
result = (unsigned int)count;
if ( count > 1 )
{
do
{
v2 = 9999;
if ( (int)result > 0 )
{
v3 = (unsigned int)(result - 1);
v4 = 8LL;
v2 = 9999;
v5 = 16 * v3 + 24;
do
{
if ( *(_DWORD *)(dist + v4) < v2 && !*(_DWORD *)(done + v4) )
{
v2 = *(_DWORD *)(dist + v4);
s2 = *(char **)(dist + v4 - 8);
}
v4 += 16LL;
}
while ( v5 != v4 );
}
func2(done, s2, 1);
for ( i = graph; i; i = *(_QWORD *)(i + 8) )
{
if ( !strcmp(*(const char **)i, s2) )
{
for ( j = *(_QWORD *)(i + 16); j; j = *(_QWORD *)(j + 16) )
{
v8 = *(const char **)j;
if ( !(unsigned int)func3(done, *(const char **)j) )
{
v9 = dist;
v10 = v2 + *(_DWORD *)(j + 8);
if ( v10 < (int)func3(dist, v8) )
{
if ( (unsigned int)func2(v9, v8, v10) )
{
puts("\n Error in setting dist value");
exit(0);
}
v11 = (const char **)prev;
v12 = *(const char **)j;
*(_DWORD *)(j + 12) = *(_DWORD *)(j + 8);
v11[2 * (int)func4(v11, v12) + 1] = s2;
}
}
}
}
}
result = (unsigned int)count;
++v14;
}
while ( count - 1 > v14 );
}
return result;
}

original_code:
void dijkstra(char *dpid){
 int cnt,inter_dist,i;
 int result;
 topo_graph *temp;
 char *element = (char *)malloc(48*sizeof(char));
 count = num_switches(graph);
 prev = init_prev_path();
 done = init_list_array(0);
 dist = init_list_array(9999);
 int value = 0;
 cnt = 0;
 result = set_val_list_array(dist,dpid,value);
 if(result != 0){
                 printf("\n Error in setting dist list array value to - %d\n",value);
                 exit(0);
         }
 while(cnt < count-1){
  inter_dist = 9999;
  for(i = 0; i < count; i++){
   if(dist[i].w < inter_dist && !done[i].w){
    inter_dist = dist[i].w;
    element = dist[i].dpid;
   }
  }
  set_val_list_array(done,element,1);
  if(result != 0){
                   printf("\n Error in setting done list array value to - 1\n");
                   exit(0);
           }
  temp = graph;
  while(temp != ((void *)0)){
   if(strcmp(temp->sdpid,element) == 0){
    adj_node *iter_adjnodes;
    iter_adjnodes = temp->adjnode;
    while(iter_adjnodes != ((void *)0)){
     if(!get_val_list_array(done,iter_adjnodes->ddpid)){
      if((inter_dist + iter_adjnodes->w) < get_val_list_array(dist,iter_adjnodes->ddpid)){
       value = inter_dist + iter_adjnodes->w;
       if(set_val_list_array(dist,iter_adjnodes->ddpid,value)){
        printf("\n Error in setting dist value\n");
        exit(0);
       }
       iter_adjnodes->min = iter_adjnodes->w;
       int prev_index = get_index_prev_path(prev,iter_adjnodes->ddpid);
       prev[prev_index].path_dpid = element;
      }
     }
     iter_adjnodes = iter_adjnodes->next_adjnode;
    }
   }
   temp = temp->next_element;
  }
  cnt++;
 }
}

canonical_original_code:
void dijkstra(char *dpid){
 int cnt; int inter_dist; int i;
 int result;
 struct topo_graph *temp;
 char *element = (char *)malloc(48*sizeof(char));
 count = num_switches(graph);
 prev = init_prev_path();
 done = init_list_array(0);
 dist = init_list_array(9999);
 int value = 0;
 cnt = 0;
 result = set_val_list_array(dist,dpid,value);
 if(result != 0){
                 printf("\n Error in setting dist list array value to - %d\n",value);
                 exit(0);
         }
 while(cnt < count-1){
  inter_dist = 9999;
  for(i = 0; i < count; i++){
   if(dist[i].w < inter_dist && !done[i].w){
    inter_dist = dist[i].w;
    element = dist[i].dpid;
   }
  }
  set_val_list_array(done,element,1);
  if(result != 0){
                   printf("\n Error in setting done list array value to - 1\n");
                   exit(0);
           }
  temp = graph;
  while(temp != ((void *)0)){
   if(strcmp(temp->sdpid,element) == 0){
    struct adj_node *iter_adjnodes;
    iter_adjnodes = temp->adjnode;
    while(iter_adjnodes != ((void *)0)){
     if(!get_val_list_array(done,iter_adjnodes->ddpid)){
      if((inter_dist + iter_adjnodes->w) < get_val_list_array(dist,iter_adjnodes->ddpid)){
       value = inter_dist + iter_adjnodes->w;
       if(set_val_list_array(dist,iter_adjnodes->ddpid,value)){
        printf("\n Error in setting dist value\n");
        exit(0);
       }
       iter_adjnodes->min = iter_adjnodes->w;
       int prev_index = get_index_prev_path(prev,iter_adjnodes->ddpid);
       prev[prev_index].path_dpid = element;
      }
     }
     iter_adjnodes = iter_adjnodes->next_adjnode;
    }
   }
   temp = temp->next_element;
  }
  cnt++;
 }
}

variable_types:
dpid
char *

variable_types: cnt int

variable_types: result int

variable_types: struct topo_graph { char *sdpid; struct topo_graph *next_element; struct adj_node { char *ddpid; int w; int min; struct adj_node *next_adjnode; } *adjnode; } *

variable_types:
element
char *

variable_types: value int

user_defined_types: struct topo_graph { char *sdpid; struct topo_graph *next_element; struct adj_node *adjnode; }


decompiled_code:
int __fastcall print_dijkstra(const char *a1)
{
__int64 v1; // rbp
int result; // eax
__int64 v3; // rbx
const char *v4; // rsi

v1 = prev;
result = get_index_prev_path((const char **)prev, a1);
v3 = 16LL * result;
if ( *(_QWORD *)(v1 + v3 + 8) )
{
print_dijkstra();
result = prev;
v4 = *(const char **)(prev + v3 + 8);
if ( v4 )
result = printf("%s -> %s", v4, a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
__int64 v1; // rbp
int result; // eax
__int64 v3; // rbx
const char *v4; // rsi

v1 = prev;
result = func4((const char **)prev, a1);
v3 = 16LL * result;
if ( *(_QWORD *)(v1 + v3 + 8) )
{
func8();
result = prev;
v4 = *(const char **)(prev + v3 + 8);
if ( v4 )
result = printf("%s -> %s", v4, a1);
}
return result;
}

original_code:
void print_dijkstra(char *dpid){
 int prev_index = get_index_prev_path(prev,dpid);
 if(prev[prev_index].path_dpid != ((void *)0)){
  print_dijkstra(prev[prev_index].path_dpid);
 }
 if(prev[prev_index].path_dpid != ((void *)0)){
  printf("%s -> %s",prev[prev_index].path_dpid,dpid);
 }
}


decompiled_code:
__int64 __fastcall add_entry(const char *a1, const char *a2, const char *a3, int a4)
{
__int64 v4; // rbx
_QWORD *v5; // rdx
__int64 v6; // rax
__int64 result; // rax

v4 = att_point;
if ( att_point )
{
v5 = create_att_point_element(a1, a2, a3, a4);
do
{
v6 = v4;
v4 = *(_QWORD *)(v4 + 32);
}
while ( v4 );
*(_QWORD *)(v6 + 32) = v5;
result = 0LL;
}
else
{
att_point = (__int64)create_att_point_element(a1, a2, a3, a4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2, const char *a3, int a4)
{
__int64 v4; // rbx
_QWORD *v5; // rdx
__int64 v6; // rax
__int64 result; // rax

v4 = att_point;
if ( att_point )
{
v5 = create_att_point_element(a1, a2, a3, a4);
do
{
v6 = v4;
v4 = *(_QWORD *)(v4 + 32);
}
while ( v4 );
*(_QWORD *)(v6 + 32) = v5;
result = 0LL;
}
else
{
att_point = (__int64)create_att_point_element(a1, a2, a3, a4);
result = 0LL;
}
return result;
}

original_code:
int add_entry(char *ipv4, char *mac, char *dpid, int port){
 if(att_point == ((void *)0)){
  attachment_point *temp = create_att_point_element(ipv4,mac,dpid,port);
  att_point = temp;
  return 0;
 }
 else {
  attachment_point *current, *temp1;
  current = att_point;
  temp1 = create_att_point_element(ipv4,mac,dpid,port);
  while(current->next_attachment_point != ((void *)0)){
   current = current->next_attachment_point;
  }
  current->next_attachment_point = temp1;
  return 0;
 }
}

canonical_original_code:
int add_entry(char *ipv4, char *mac, char *dpid, int port){
 if(att_point == ((void *)0)){
  struct attachment_point *temp = create_att_point_element(ipv4,mac,dpid,port);
  att_point = temp;
  return 0;
 }
 else {
  struct attachment_point *current; struct attachment_point *temp1;
  current = att_point;
  temp1 = create_att_point_element(ipv4,mac,dpid,port);
  while(current->next_attachment_point != ((void *)0)){
   current = current->next_attachment_point;
  }
  current->next_attachment_point = temp1;
  return 0;
 }
}

variable_types:
mac
char *

variable_types: port int

variable_types: struct attachment_point { char *ipv4; char *mac; char *dpid; int port; struct attachment_point *next_attachment_point; } *

return_type: int


decompiled_code:
__int64 __fastcall find_dpid(char *s2)
{
__int64 v1; // r12

v1 = att_point;
if ( att_point )
{
while ( strcmp(*(const char **)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 16);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
__int64 v1; // r12

v1 = att_point;
if ( att_point )
{
while ( strcmp(*(const char **)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 16);
}
return v1;
}

original_code:
char *find_dpid(char *ipv4){
 attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  if(strcmp(temp->ipv4,ipv4) == 0){
   return temp->dpid;
  }
  temp = temp->next_attachment_point;
 }
 return ((void *)0);
}

canonical_original_code:
char *find_dpid(char *ipv4){
 struct attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  if(strcmp(temp->ipv4,ipv4) == 0){
   return temp->dpid;
  }
  temp = temp->next_attachment_point;
 }
 return ((void *)0);
}

return_type: char *

user_defined_types: struct attachment_point { char *ipv4; char *mac; char *dpid; int port; struct attachment_point *next_attachment_point; }


decompiled_code:
__int64 print_att_point()
{
__int64 i; // rbx

for ( i = att_point; i; i = *(_QWORD *)(i + 32) )
printf(
"IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",
*(const char **)i,
*(const char **)(i + 8),
*(const char **)(i + 16),
*(unsigned int *)(i + 24));
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 i; // rbx

for ( i = att_point; i; i = *(_QWORD *)(i + 32) )
printf(
"IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",
*(const char **)i,
*(const char **)(i + 8),
*(const char **)(i + 16),
*(unsigned int *)(i + 24));
return 0LL;
}

original_code:
int print_att_point(void){
 attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  printf("IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",temp->ipv4,temp->mac,temp->dpid,temp->port);
  temp = temp->next_attachment_point;
 }
 return 0;
}

canonical_original_code:
int print_att_point(){
 struct attachment_point *temp;
 temp = att_point;
 while(temp != ((void *)0)){
  printf("IPv4 = %s, MAC = %s, DPID = %s, Port = %d\n",temp->ipv4,temp->mac,temp->dpid,temp->port);
  temp = temp->next_attachment_point;
 }
 return 0;
}


a

repo: mbolewar/csource

decompiled_code:
int a()
{
return puts("function a");
}

canonical_decompiled_code:
int func7()
{
return puts("function a");
}

original_code:
void
a() {
 printf("function a\n");
}

canonical_original_code:
void a() {
 printf("function a\n");
}


b

decompiled_code:
int b()
{
return puts("function b");
}

canonical_decompiled_code:
int func8()
{
return puts("function b");
}

original_code:
void
b() {
 printf("function b\n");
}

canonical_original_code:
void b() {
 printf("function b\n");
}


c

decompiled_code:
int c()
{
return puts("function c");
}

canonical_decompiled_code:
int func9()
{
return puts("function c");
}

original_code:
void
c() {
 printf("function c\n");
}

canonical_original_code:
void c() {
 printf("function c\n");
}


decompiled_code:
__int64 __fastcall Camera_Basic_map(__int64 a1, __int64 a2, double a3, double a4)
{
__int64 v4; // rbp
double v5; // xmm0_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-70h]
char v9[32]; // [rsp+10h] [rbp-68h] BYREF
char v10[72]; // [rsp+30h] [rbp-48h] BYREF

Vector_cross(v9, a1 + 56, a1 + 32);
Vector_normalize(a1 + 56);
Vector_normalize(a1 + 32);
Vector_normalize(v9);
v4 = a2 + 24;
v8 = a3 + a3;
Vector_assign(a2, a1 + 8);
v5 = tan(0.5 * *(double *)(a1 + 80));
Vector_scalar_mult(a2 + 24, v9, (v8 - 1.0) * v5);
v6 = tan(0.5 * *(double *)(a1 + 88));
Vector_scalar_mult(v10, a1 + 32, v6 * (a4 + a4 - 1.0));
Vector_add(v4, v4, v10);
return Vector_add(v4, v4, a1 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, double a3, double a4)
{
__int64 v4; // rbp
double v5; // xmm0_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-70h]
char v9[32]; // [rsp+10h] [rbp-68h] BYREF
char v10[72]; // [rsp+30h] [rbp-48h] BYREF

Vector_cross(v9, a1 + 56, a1 + 32);
Vector_normalize(a1 + 56);
Vector_normalize(a1 + 32);
Vector_normalize(v9);
v4 = a2 + 24;
v8 = a3 + a3;
Vector_assign(a2, a1 + 8);
v5 = tan(0.5 * *(double *)(a1 + 80));
Vector_scalar_mult(a2 + 24, v9, (v8 - 1.0) * v5);
v6 = tan(0.5 * *(double *)(a1 + 88));
Vector_scalar_mult(v10, a1 + 32, v6 * (a4 + a4 - 1.0));
Vector_add(v4, v4, v10);
return Vector_add(v4, v4, a1 + 56);
}

original_code:
void Camera_Basic_map(const Camera* _cam, double x, double y, Ray* ray) {
    Camera_Basic* cam = (Camera_Basic*) _cam;
    Vector right;
    Vector tmp;
    Vector_cross(&right, &cam->forward, &cam->up);
    Vector_normalize(&cam->forward);
    Vector_normalize(&cam->up);
    Vector_normalize(&right);
    x = x*2 - 1;
    y = y*2 - 1;
    Vector_assign(&ray->o, &cam->pos);
    Vector_scalar_mult(&ray->d, &right, x*tan(cam->fov_x/2));
    Vector_scalar_mult(&tmp, &cam->up, y*tan(cam->fov_y/2));
    Vector_add(&ray->d, &ray->d, &tmp);
    Vector_add(&ray->d, &ray->d, &cam->forward);
}

canonical_original_code:
void Camera_Basic_map(struct Camera_struct *_cam, double x, double y, struct Ray *ray) {
    struct Camera_Basic *cam = (Camera_Basic*) _cam;
    struct Vector right;
    struct Vector tmp;
    Vector_cross(&right, &cam->forward, &cam->up);
    Vector_normalize(&cam->forward);
    Vector_normalize(&cam->up);
    Vector_normalize(&right);
    x = x*2 - 1;
    y = y*2 - 1;
    Vector_assign(&ray->o, &cam->pos);
    Vector_scalar_mult(&ray->d, &right, x*tan(cam->fov_x/2));
    Vector_scalar_mult(&tmp, &cam->up, y*tan(cam->fov_y/2));
    Vector_add(&ray->d, &ray->d, &tmp);
    Vector_add(&ray->d, &ray->d, &cam->forward);
}

variable_types: struct Camera_struct { struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray { struct Vector { double x; } o; struct Vector d; } *r); } func; struct Vector pos; } *

variable_types: x double

variable_types: y double

variable_types:
ray
struct Ray *

variable_types: struct Camera_Basic { struct camera_func_table { void (*map)(struct Camera_struct { struct camera_func_table func; struct Vector { double x; } pos; } *cam, double x, double y, struct Ray { struct Vector o; struct Vector d; } *r); } func; struct Vector pos; struct Vector up; struct Vector forward; double fov_x; } *

variable_types:
right
struct Vector { double x; }

variable_types:
tmp
struct Vector { double x; }

user_defined_types: struct Camera_struct { struct camera_func_table func; struct Vector pos; }

user_defined_types: struct Camera_Basic { struct camera_func_table func; struct Vector pos; struct Vector up; struct Vector forward; double fov_x; }

user_defined_types: struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray *r); }


original_code:
void Camera_Basic_zoom(Camera* _cam, double x, double y, double zoom_factor) {
    Camera_Basic* cam = (Camera_Basic*) _cam;
    Ray ray;
    const Vector const_up = (Vector) {0, 0, 1};
    (cam)->func.map((Camera*) cam, x, y, &ray);
    cam->forward = ray.d;
    Vector_cross(&cam->up, &const_up, &cam->forward);
    Vector_cross(&cam->up, &cam->forward, &cam->up);
    cam->fov_x /= zoom_factor;
    cam->fov_y /= zoom_factor;
    if (cam->fov_x >= 3.141592653589793238462643383279 -0.5) cam->fov_x = 3.141592653589793238462643383279 -0.5;
    if (cam->fov_y >= 3.141592653589793238462643383279 -0.5) cam->fov_y = 3.141592653589793238462643383279 -0.5;
}

canonical_original_code:
void Camera_Basic_zoom(struct Camera_struct *_cam, double x, double y, double zoom_factor) {
    struct Camera_Basic *cam = (Camera_Basic*) _cam;
    struct Ray ray;
    struct Vector const_up = (Vector) {0, 0, 1};
    (cam)->func.map((struct Camera_struct *) cam, x, y, &ray);
    cam->forward = ray.d;
    Vector_cross(&cam->up, &const_up, &cam->forward);
    Vector_cross(&cam->up, &cam->forward, &cam->up);
    cam->fov_x /= zoom_factor;
    cam->fov_y /= zoom_factor;
    if (cam->fov_x >= 3.141592653589793238462643383279 -0.5) cam->fov_x = 3.141592653589793238462643383279 -0.5;
    if (cam->fov_y >= 3.141592653589793238462643383279 -0.5) cam->fov_y = 3.141592653589793238462643383279 -0.5;
}

variable_types: struct Ray { struct Vector { double x; } o; struct Vector d; }

user_defined_types: struct Ray { struct Vector o; struct Vector d; }


decompiled_code:
_QWORD *Scene_new()
{
_QWORD *v0; // r12

v0 = malloc(8uLL);
*v0 = List_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = malloc(8uLL);
*v0 = List_new();
return v0;
}

original_code:
Scene* Scene_new() {
    Scene* s = (Scene*) malloc(sizeof(Scene));
    s->objects = List_new();
    return s;
}

canonical_original_code:
struct Scene *Scene_new() {
    struct Scene *s = (Scene*) malloc(sizeof(Scene));
    s->objects = List_new();
    return s;
}

variable_types: struct Scene { struct List { struct ListNode_struct { void *data; struct ListNode_struct *next; } *head; struct ListNode_struct *tail; unsigned int length; } *objects; } *

user_defined_types: struct List { struct ListNode_struct *head; struct ListNode_struct *tail; unsigned int length; }


decompiled_code:
__int64 __fastcall Scene_add_object(_QWORD *a1)
{
return List_append(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
return List_append(*a1);
}

original_code:
void Scene_add_object(Scene* scene, Object* obj) {
    List_append(scene->objects, (void*) obj);
}

canonical_original_code:
void Scene_add_object(struct Scene *scene, struct Object_struct *obj) {
    List_append(scene->objects, (void *) obj);
}

variable_types: struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect); } func; } *mat; } *

user_defined_types: struct Object_struct { struct object_func_table func; struct Material_struct *mat; }

user_defined_types: struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); }

user_defined_types: struct Material_struct { struct material_func_table func; }

user_defined_types: struct material_func_table { struct material_transmit (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect); }

user_defined_types: struct ListNode_struct { void *data; struct ListNode_struct *next; }

user_defined_types: struct material_transmit { struct Color diffuse; struct Color ambient; struct Color reflect; struct Color refract; }


decompiled_code:
void __fastcall Scene_free(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx

v2 = *(_QWORD **)ptr;
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
Object_free(*v3);
v3 = (_QWORD *)v3[1];
}
while ( v3 );
v2 = *(_QWORD **)ptr;
}
List_free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx

v2 = *(_QWORD **)ptr;
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
Object_free(*v3);
v3 = (_QWORD *)v3[1];
}
while ( v3 );
v2 = *(_QWORD **)ptr;
}
List_free(v2);
free(ptr);
}

original_code:
void Scene_free(Scene* s) {
    Object* obj;
    ListNode* node = s->objects->head;
    while (node) {
        obj = (Object*) node->data;
        Object_free(obj);
        node = node->next;
    }
    List_free(s->objects);
    free(s);
}

canonical_original_code:
void Scene_free(struct Scene *s) {
    struct Object_struct *obj;
    struct ListNode_struct *node = s->objects->head;
    while (node) {
        obj = (struct Object_struct *) node->data;
        Object_free(obj);
        node = node->next;
    }
    List_free(s->objects);
    free(s);
}

variable_types: struct ListNode_struct { void *data; struct ListNode_struct *next; } *

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


decompiled_code:
__int64 __fastcall Object_Sphere_normal(__int64 a1, __int64 a2, __int64 a3)
{
return Vector_subtract(a3, a2, a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return Vector_subtract(a3, a2, a1 + 32);
}

original_code:
void Object_Sphere_normal(const Object* obj, const Point* intersect, Vector* normal) {
    Object_Sphere* s = (Object_Sphere*) obj;
    Vector_subtract(normal, intersect, &s->pos);
}

canonical_original_code:
void Object_Sphere_normal(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal) {
    struct Object_Sphere *s = (Object_Sphere*) obj;
    Vector_subtract(normal, intersect, &s->pos);
}

variable_types:
intersect
struct Vector *

variable_types:
normal
struct Vector *

variable_types: struct Object_Sphere { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct { struct object_func_table func; struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector { double x; } *intersect); } func; } *mat; } *obj, struct Ray { struct Vector o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; struct Vector pos; double r; } *

user_defined_types: struct Object_Sphere { struct object_func_table func; struct Material_struct *mat; struct Vector pos; double r; }


original_code:
_Bool Object_Sphere_ray_intersect(const Object* obj, const Ray* r, Point* intersect) {
    const Object_Sphere* s = (Object_Sphere*) obj;
    Vector ray_origin;
    Vector_subtract(&ray_origin, &r->o, &s->pos);
    double a = Vector_mag(&r->d) * Vector_mag(&r->d);
    double b = -2 * Vector_dot(&ray_origin, &r->d);
    double c = Vector_mag(&ray_origin) * Vector_mag(&ray_origin) - (s->r * s->r);
    double det = b*b - 4*a*c;
    if (det < 0) {
        return 0;
    }
    double t1 = ( b + sqrt(det) ) / (2*a);
    double t2 = ( b - sqrt(det) ) / (2*a);
    double t;
    if (t1 <= 10*( 1.0e-5 )) {
        t = t2;
    } else if (t2 <= 10*( 1.0e-5 )) {
        t = t1;
    } else {
        t = t1<t2 ? t1 : t2;
    }
    if (t <= 10*( 1.0e-5 )) {
        return 0;
    }
    if (t < 10*( 1.0e-5 )) {
        return 0;
    }
    intersect->x = r->o.x + t*r->d.x;
    intersect->y = r->o.y + t*r->d.y;
    intersect->z = r->o.z + t*r->d.z;
    if (fabs(intersect->x - r->o.x) < 10*( 1.0e-5 ) && fabs(intersect->y - r->o.y) < 10*( 1.0e-5 ) && fabs(intersect->z - r->o.z) < 10*( 1.0e-5 ))
    {
        return 0;
    }
    return 1;
}

canonical_original_code:
_Bool Object_Sphere_ray_intersect(struct Object_struct *obj, struct Ray *r, struct Vector *intersect) {
    struct Object_Sphere *s = (Object_Sphere*) obj;
    struct Vector ray_origin;
    Vector_subtract(&ray_origin, &r->o, &s->pos);
    double a = Vector_mag(&r->d) * Vector_mag(&r->d);
    double b = -2 * Vector_dot(&ray_origin, &r->d);
    double c = Vector_mag(&ray_origin) * Vector_mag(&ray_origin) - (s->r * s->r);
    double det = b*b - 4*a*c;
    if (det < 0) {
        return 0;
    }
    double t1 = ( b + sqrt(det) ) / (2*a);
    double t2 = ( b - sqrt(det) ) / (2*a);
    double t;
    if (t1 <= 10*( 1.0e-5 )) {
        t = t2;
    } else if (t2 <= 10*( 1.0e-5 )) {
        t = t1;
    } else {
        t = t1<t2 ? t1 : t2;
    }
    if (t <= 10*( 1.0e-5 )) {
        return 0;
    }
    if (t < 10*( 1.0e-5 )) {
        return 0;
    }
    intersect->x = r->o.x + t*r->d.x;
    intersect->y = r->o.y + t*r->d.y;
    intersect->z = r->o.z + t*r->d.z;
    if (fabs(intersect->x - r->o.x) < 10*( 1.0e-5 ) && fabs(intersect->y - r->o.y) < 10*( 1.0e-5 ) && fabs(intersect->z - r->o.z) < 10*( 1.0e-5 ))
    {
        return 0;
    }
    return 1;
}

variable_types:
r
struct Ray *

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: det double

variable_types: t double


decompiled_code:
bool __fastcall Object_Sphere_inside(__int64 a1)
{
return *(double *)(a1 + 56) * *(double *)(a1 + 56) + 0.00001 >= Vector_dist_squared(a1 + 32);
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1)
{
return *(double *)(a1 + 56) * *(double *)(a1 + 56) + 0.00001 >= Vector_dist_squared(a1 + 32);
}

original_code:
_Bool Object_Sphere_inside(const Object* obj, const Point* point) {
    Object_Sphere* s = (Object_Sphere*) obj;
    return Vector_dist_squared(&s->pos, point) <= s->r * s->r + ( 1.0e-5 );
}

canonical_original_code:
_Bool Object_Sphere_inside(struct Object_struct *obj, struct Vector *point) {
    struct Object_Sphere *s = (Object_Sphere*) obj;
    return Vector_dist_squared(&s->pos, point) <= s->r * s->r + ( 1.0e-5 );
}

variable_types:
point
struct Vector *


decompiled_code:
void __fastcall Object_set_material(__int64 a1, __int64 a2)
{
free(*(void **)(a1 + 24));
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void Object_set_material(Object* obj, Material* mat) {
    free(obj->mat);
    obj->mat = mat;
}

canonical_original_code:
void Object_set_material(struct Object_struct *obj, struct Material_struct *mat) {
    free(obj->mat);
    obj->mat = mat;
}

variable_types:
mat
struct Material_struct *


decompiled_code:
void __fastcall Object_free(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

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

original_code:
void Object_free(Object* obj) {
    free(obj->mat);
    free(obj);
}

canonical_original_code:
void Object_free(struct Object_struct *obj) {
    free(obj->mat);
    free(obj);
}


original_code:
void Vector_cross(Vector* result, const Vector* a, const Vector* b) {
    Vector tmp;
    tmp.x = a->y*b->z - a->z*b->y;
    tmp.y = a->z*b->x - a->x*b->z;
    tmp.z = a->x*b->y - a->y*b->x;
    result->x = tmp.x;
    result->y = tmp.y;
    result->z = tmp.z;
}

canonical_original_code:
void Vector_cross(struct Vector *result, struct Vector *a, struct Vector *b) {
    struct Vector tmp;
    tmp.x = a->y*b->z - a->z*b->y;
    tmp.y = a->z*b->x - a->x*b->z;
    tmp.z = a->x*b->y - a->y*b->x;
    result->x = tmp.x;
    result->y = tmp.y;
    result->z = tmp.z;
}

variable_types:
result
struct Vector { double x; } *

variable_types:
a
struct Vector *

variable_types:
b
struct Vector *


original_code:
double Vector_mag(const Vector* v) {
    return sqrt( (v->x * v->x) + (v->y * v->y) + (v->z * v->z) );
}

canonical_original_code:
double Vector_mag(struct Vector *v) {
    return sqrt( (v->x * v->x) + (v->y * v->y) + (v->z * v->z) );
}

variable_types:
v
struct Vector { double x; } *

return_type: double


decompiled_code:
void __fastcall Vector_normalize(double *a1, double a2)
{
Vector_mag(a1);
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
}

original_code:
void Vector_normalize(Vector* v) {
    double mag = Vector_mag(v);
    v->x /= mag;
    v->y /= mag;
    v->z /= mag;
}

canonical_original_code:
void Vector_normalize(struct Vector *v) {
    double mag = Vector_mag(v);
    v->x /= mag;
    v->y /= mag;
    v->z /= mag;
}

variable_types: mag double


decompiled_code:
void __fastcall Vector_scalar_mult(double *a1, double *a2, double a3)
{
double v3; // xmm1_8
double v4; // xmm0_8

*a1 = *a2 * a3;
v3 = a2[1] * a3;
v4 = a3 * a2[2];
a1[1] = v3;
a1[2] = v4;
}

canonical_decompiled_code:
void __fastcall func3(double *a1, double *a2, double a3)
{
double v3; // xmm1_8
double v4; // xmm0_8

*a1 = *a2 * a3;
v3 = a2[1] * a3;
v4 = a3 * a2[2];
a1[1] = v3;
a1[2] = v4;
}

original_code:
void Vector_scalar_mult(Vector* result, const Vector* v, double s) {
    result->x = v->x * s;
    result->y = v->y * s;
    result->z = v->z * s;
}

canonical_original_code:
void Vector_scalar_mult(struct Vector *result, struct Vector *v, double s) {
    result->x = v->x * s;
    result->y = v->y * s;
    result->z = v->z * s;
}

variable_types:
v
struct Vector *

variable_types: s double


decompiled_code:
double __fastcall Vector_dot(double *a1, double *a2)
{
return *a1 * *a2 + a1[1] * a2[1] + a1[2] * a2[2];
}

canonical_decompiled_code:
double __fastcall func4(double *a1, double *a2)
{
return *a1 * *a2 + a1[1] * a2[1] + a1[2] * a2[2];
}

original_code:
double Vector_dot(const Vector* a, const Vector* b) {
    return (a->x * b->x) + (a->y * b->y) + (a->z * b->z);
}

canonical_original_code:
double Vector_dot(struct Vector *a, struct Vector *b) {
    return (a->x * b->x) + (a->y * b->y) + (a->z * b->z);
}

variable_types:
a
struct Vector { double x; } *


original_code:
void Vector_add(Vector* result, const Vector* a, const Vector* b) {
    result->x = a->x + b->x;
    result->y = a->y + b->y;
    result->z = a->z + b->z;
}

canonical_original_code:
void Vector_add(struct Vector *result, struct Vector *a, struct Vector *b) {
    result->x = a->x + b->x;
    result->y = a->y + b->y;
    result->z = a->z + b->z;
}


decompiled_code:
void __fastcall Vector_subtract(double *a1, double *a2, double *a3)
{
*a1 = *a2 - *a3;
a1[1] = a2[1] - a3[1];
a1[2] = a2[2] - a3[2];
}

original_code:
void Vector_subtract(Vector* result, const Vector* a, const Vector* b) {
    result->x = a->x - b->x;
    result->y = a->y - b->y;
    result->z = a->z - b->z;
}

canonical_original_code:
void Vector_subtract(struct Vector *result, struct Vector *a, struct Vector *b) {
    result->x = a->x - b->x;
    result->y = a->y - b->y;
    result->z = a->z - b->z;
}


original_code:
double Vector_dist_squared(const Vector* a, const Vector* b) {
    return (a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y) + (a->z - b->z) * (a->z - b->z);
}

canonical_original_code:
double Vector_dist_squared(struct Vector *a, struct Vector *b) {
    return (a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y) + (a->z - b->z) * (a->z - b->z);
}


decompiled_code:
_QWORD *List_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
{
puts("Could not allocate memory!");
puts(" In List_new()");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
{
puts("Could not allocate memory!");
puts(" In List_new()");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
List* List_new() {
    List* l = (List*) malloc(sizeof(List));
    if (!l) {
        printf("Could not allocate memory!\n");
        printf("    In List_new()\n");
        exit(1);
    }
    l->head = ((void *)0);
    l->tail = ((void *)0);
    l->length = 0;
    return l;
}

canonical_original_code:
struct List *List_new() {
    struct List *l = (List*) malloc(sizeof(List));
    if (!l) {
        printf("Could not allocate memory!\n");
        printf("    In List_new()\n");
        exit(1);
    }
    l->head = ((void *)0);
    l->tail = ((void *)0);
    l->length = 0;
    return l;
}

variable_types: struct List { struct ListNode_struct { void *data; struct ListNode_struct *next; } *head; struct ListNode_struct *tail; unsigned int length; } *


decompiled_code:
void __fastcall List_free(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void List_free(List* l) {
    ListNode* node = l->head;
    ListNode* next;
    while (node != ((void *)0)) {
        next = node->next;
        free(node);
        node = next;
    }
    free(l);
}

canonical_original_code:
void List_free(struct List *l) {
    struct ListNode_struct *node = l->head;
    struct ListNode_struct *next;
    while (node != ((void *)0)) {
        next = node->next;
        free(node);
        node = next;
    }
    free(l);
}

variable_types: struct ListNode_struct { void *data; struct ListNode_struct *next; } *


decompiled_code:
__int64 __fastcall Material_Solid_get_transmit(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
struct material_transmit Material_Solid_get_transmit(const Material* mat, const Object* object, const Point* intersect) {
    Material_Solid* m = (Material_Solid*) mat;
    return m->transmit;
}

canonical_original_code:
struct material_transmit Material_Solid_get_transmit(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect) {
    struct Material_Solid *m = (Material_Solid*) mat;
    return m->transmit;
}

variable_types: struct Material_struct { struct material_func_table { struct material_transmit (*get_transmit)(struct Material_struct *mat, struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; } *object, struct Vector *intersect); } func; } *

variable_types:
object
struct Object_struct *

variable_types:
intersect
struct Vector *

variable_types: struct Material_Solid { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct { struct material_func_table func; } *mat, struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; } *object, struct Vector *intersect); } func; struct material_transmit transmit; } *

user_defined_types: struct Material_Solid { struct material_func_table func; struct material_transmit transmit; }


decompiled_code:
_QWORD *Material_Solid_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
result[1] = 0xFFFFFFFFFFFFLL;
*result = Material_Solid_get_transmit;
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
result[1] = 0xFFFFFFFFFFFFLL;
*result = Material_Solid_get_transmit;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
Material* Material_Solid_new() {
    Material_Solid* m = (Material_Solid*) malloc(sizeof(Material_Solid));
    m->func = material_solid_func_table;
    m->transmit = (struct material_transmit) {
        {255, 255, 255},
        {255, 255, 255},
        {0, 0, 0},
        {0, 0, 0}
    };
    return (Material*) m;
}

canonical_original_code:
struct Material_struct *Material_Solid_new() {
    struct Material_Solid *m = (Material_Solid*) malloc(sizeof(Material_Solid));
    m->func = material_solid_func_table;
    m->transmit = (struct material_transmit) {
        {255, 255, 255},
        {255, 255, 255},
        {0, 0, 0},
        {0, 0, 0}
    };
    return (struct Material_struct *) m;
}

return_type: struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; } *object, struct Vector *intersect); } func; } *


decompiled_code:
__int64 Object_Plane_inside()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
_Bool Object_Plane_inside(const Object* obj, const Point* point) {
    return 1;
}

canonical_original_code:
_Bool Object_Plane_inside(struct Object_struct *obj, struct Vector *point) {
    return 1;
}

variable_types: struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect); } func; } *mat; } *


decompiled_code:
__int64 __fastcall Object_Plane_ray_intersect(__int64 a1, double *a2, double *a3)
{
double v4; // xmm0_8
__int64 result; // rax
double v6; // xmm0_8
double v7; // xmm1_8
double v8; // xmm0_8
char v9[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = Vector_dot(a1 + 32, a2 + 3);
if ( v4 == 0.0 )
return 0LL;
Vector_subtract(v9, a2, a1 + 56);
v6 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(Vector_dot(a1 + 32, v9)) ^ LC2) / v4;
if ( v6 <= 0.0 || v6 <= 0.00001 )
return 0LL;
result = 1LL;
*a3 = a2[3] * v6 + *a2;
v7 = a2[4] * v6 + a2[1];
v8 = v6 * a2[5] + a2[2];
a3[1] = v7;
a3[2] = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, double *a2, double *a3)
{
double v4; // xmm0_8
__int64 result; // rax
double v6; // xmm0_8
double v7; // xmm1_8
double v8; // xmm0_8
char v9[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = Vector_dot(a1 + 32, a2 + 3);
if ( v4 == 0.0 )
return 0LL;
Vector_subtract(v9, a2, a1 + 56);
v6 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(Vector_dot(a1 + 32, v9)) ^ LC2) / v4;
if ( v6 <= 0.0 || v6 <= 0.00001 )
return 0LL;
result = 1LL;
*a3 = a2[3] * v6 + *a2;
v7 = a2[4] * v6 + a2[1];
v8 = v6 * a2[5] + a2[2];
a3[1] = v7;
a3[2] = v8;
return result;
}

original_code:
_Bool Object_Plane_ray_intersect(const Object* obj, const Ray* r, Point* intersect) {
    Object_Plane* p = (Object_Plane*) obj;
    Vector tmp_vector;
    double denominator = Vector_dot(&p->norm, &r->d);
    if (denominator == 0.0) {
        return 0;
    }
    Vector_subtract(&tmp_vector, &r->o, &p->point);
    double t = -1*Vector_dot(&p->norm, &tmp_vector) / denominator;
    if (t <= 0) {
        return 0;
    }
    if (t <= ( 1.0e-5 )) {
        return 0;
    }
    intersect->x = r->o.x + t*r->d.x;
    intersect->y = r->o.y + t*r->d.y;
    intersect->z = r->o.z + t*r->d.z;
    return 1;
}

canonical_original_code:
_Bool Object_Plane_ray_intersect(struct Object_struct *obj, struct Ray *r, struct Vector *intersect) {
    struct Object_Plane *p = (Object_Plane*) obj;
    struct Vector tmp_vector;
    double denominator = Vector_dot(&p->norm, &r->d);
    if (denominator == 0.0) {
        return 0;
    }
    Vector_subtract(&tmp_vector, &r->o, &p->point);
    double t = -1*Vector_dot(&p->norm, &tmp_vector) / denominator;
    if (t <= 0) {
        return 0;
    }
    if (t <= ( 1.0e-5 )) {
        return 0;
    }
    intersect->x = r->o.x + t*r->d.x;
    intersect->y = r->o.y + t*r->d.y;
    intersect->z = r->o.z + t*r->d.z;
    return 1;
}

variable_types:
r
struct Ray *

variable_types: struct Object_Plane { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct { struct object_func_table func; struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector { double x; } *intersect); } func; } *mat; } *obj, struct Ray { struct Vector o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; struct Vector norm; struct Vector point; } *

variable_types: denominator double

variable_types: t double

user_defined_types: struct Object_Plane { struct object_func_table func; struct Material_struct *mat; struct Vector norm; struct Vector point; }


decompiled_code:
double *__fastcall Object_Plane_new(double a1)
{
double *v1; // r12

v1 = (double *)malloc(0x50uLL);
v1[7] = 0.0;
*(_QWORD *)v1 = Object_Plane_ray_intersect;
v1[8] = 0.0;
*((_QWORD *)v1 + 1) = Object_Plane_normal;
v1[4] = 0.0;
*((_QWORD *)v1 + 2) = Object_Plane_inside;
v1[5] = 0.0;
*((_QWORD *)v1 + 6) = LC1;
v1[9] = a1;
*((_QWORD *)v1 + 3) = Material_new_default();
return v1;
}

canonical_decompiled_code:
double *__fastcall func3(double a1)
{
double *v1; // r12

v1 = (double *)malloc(0x50uLL);
v1[7] = 0.0;
*(_QWORD *)v1 = Object_Plane_ray_intersect;
v1[8] = 0.0;
*((_QWORD *)v1 + 1) = Object_Plane_normal;
v1[4] = 0.0;
*((_QWORD *)v1 + 2) = Object_Plane_inside;
v1[5] = 0.0;
*((_QWORD *)v1 + 6) = LC1;
v1[9] = a1;
*((_QWORD *)v1 + 3) = Material_new_default();
return v1;
}

original_code:
Object* Object_Plane_new(double z) {
    Object_Plane* p = (Object_Plane*) malloc(sizeof(Object_Plane));
    p->func = object_plane_func_table;
    p->point = (Point) {0, 0, z};
    p->norm = (Vector) {0, 0, 1};
    p->mat = Material_new_default();
    return (Object*) p;
}

canonical_original_code:
struct Object_struct *Object_Plane_new(double z) {
    struct Object_Plane *p = (Object_Plane*) malloc(sizeof(Object_Plane));
    p->func = object_plane_func_table;
    p->point = (struct Vector) {0, 0, z};
    p->norm = (struct Vector) {0, 0, 1};
    p->mat = Material_new_default();
    return (struct Object_struct *) p;
}

variable_types: z double

return_type: struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect); } func; } *mat; } *


decompiled_code:
bool __fastcall Color_is_black(_BYTE *a1)
{
bool result; // al

result = 0;
if ( !*a1 && !a1[1] )
result = a1[2] == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func4(_BYTE *a1)
{
bool result; // al

result = 0;
if ( !*a1 && !a1[1] )
result = a1[2] == 0;
return result;
}

original_code:
_Bool Color_is_black(const Color* c) {
    return c->r == 0 &&
           c->g == 0 &&
           c->b == 0;
}

canonical_original_code:
_Bool Color_is_black(struct Color *c) {
    return c->r == 0 &&
           c->g == 0 &&
           c->b == 0;
}

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


decompiled_code:
__int64 __fastcall Canvas_Mem_get_next_row(__int64 a1)
{
return *(_QWORD *)(a1 + 48) + 3LL * (unsigned int)(*(_DWORD *)(a1 + 56) * *(_DWORD *)(a1 + 40));
}

original_code:
Color* Canvas_Mem_get_next_row(Canvas* _canvas) {
    Canvas_Mem* canvas = (Canvas_Mem*) _canvas;
    return &canvas->image[canvas->width * canvas->next_row];
}

canonical_original_code:
struct Color *Canvas_Mem_get_next_row(struct Canvas_struct *_canvas) {
    struct Canvas_Mem *canvas = (Canvas_Mem*) _canvas;
    return &canvas->image[canvas->width * canvas->next_row];
}

variable_types: struct Canvas_struct { struct canvas_func_table { _Bool (*start)(struct Canvas_struct *canvas); struct Color *(*get_next_row)(struct Canvas_struct *canvas); _Bool (*write_row)(struct Canvas_struct *canvas, struct Color *row); _Bool (*finish)(struct Canvas_struct *canvas); void (*free)(struct Canvas_struct *canvas); } func; unsigned int width; } *

variable_types: struct Canvas_Mem { struct canvas_func_table { _Bool (*start)(struct Canvas_struct { struct canvas_func_table func; unsigned int width; } *canvas); struct Color { unsigned char r; unsigned char g; unsigned char b; } *(*get_next_row)(struct Canvas_struct *canvas); _Bool (*write_row)(struct Canvas_struct *canvas, struct Color *row); _Bool (*finish)(struct Canvas_struct *canvas); void (*free)(struct Canvas_struct *canvas); } func; unsigned int width; struct Color *image; unsigned int next_row; } *

user_defined_types: struct Canvas_Mem { struct canvas_func_table func; unsigned int width; struct Color *image; unsigned int next_row; }


decompiled_code:
__int64 __fastcall Canvas_Mem_write_row(__int64 a1)
{
++*(_DWORD *)(a1 + 56);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
++*(_DWORD *)(a1 + 56);
return 1LL;
}

original_code:
_Bool Canvas_Mem_write_row(Canvas* _canvas, Color* row) {
    Canvas_Mem* canvas = (Canvas_Mem*) _canvas;
    canvas->next_row++;
    return 1;
}

canonical_original_code:
_Bool Canvas_Mem_write_row(struct Canvas_struct *_canvas, struct Color *row) {
    struct Canvas_Mem *canvas = (Canvas_Mem*) _canvas;
    canvas->next_row++;
    return 1;
}

variable_types: struct Canvas_struct { struct canvas_func_table { _Bool (*start)(struct Canvas_struct *canvas); struct Color { unsigned char r; unsigned char g; unsigned char b; } *(*get_next_row)(struct Canvas_struct *canvas); _Bool (*write_row)(struct Canvas_struct *canvas, struct Color *row); _Bool (*finish)(struct Canvas_struct *canvas); void (*free)(struct Canvas_struct *canvas); } func; unsigned int width; } *

variable_types:
row
struct Color *

user_defined_types: struct Canvas_struct { struct canvas_func_table func; unsigned int width; }

user_defined_types: struct canvas_func_table { _Bool (*start)(struct Canvas_struct *canvas); struct Color *(*get_next_row)(struct Canvas_struct *canvas); _Bool (*write_row)(struct Canvas_struct *canvas, struct Color *row); _Bool (*finish)(struct Canvas_struct *canvas); void (*free)(struct Canvas_struct *canvas); }


decompiled_code:
__int64 Canvas_Mem_finish()
{
return 1LL;
}

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

original_code:
_Bool Canvas_Mem_finish(Canvas* canvas) {
    return 1;
}

canonical_original_code:
_Bool Canvas_Mem_finish(struct Canvas_struct *canvas) {
    return 1;
}


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

if ( *(_QWORD *)(a1 + 48)
|| (v2 = malloc(3 * *(unsigned int *)(a1 + 44) * (unsigned __int64)*(unsigned int *)(a1 + 40)),
(*(_QWORD *)(a1 + 48) = v2) != 0LL) )
{
*(_DWORD *)(a1 + 56) = 0;
result = 1LL;
}
else
{
fwrite("Could not allocate memory for image!", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

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

if ( *(_QWORD *)(a1 + 48)
|| (v2 = malloc(3 * *(unsigned int *)(a1 + 44) * (unsigned __int64)*(unsigned int *)(a1 + 40)),
(*(_QWORD *)(a1 + 48) = v2) != 0LL) )
{
*(_DWORD *)(a1 + 56) = 0;
result = 1LL;
}
else
{
fwrite("Could not allocate memory for image!", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
_Bool Canvas_Mem_start(Canvas* _canvas) {
    Canvas_Mem* canvas = (Canvas_Mem*) _canvas;
    if (!canvas->image) {
        canvas->image = (Color*) malloc(sizeof(Color) * canvas->width * canvas->height);
    }
    if (!canvas->image) {
        fprintf(stderr, "Could not allocate memory for image!");
        return 0;
    }
    canvas->next_row = 0;
    return 1;
}

canonical_original_code:
_Bool Canvas_Mem_start(struct Canvas_struct *_canvas) {
    struct Canvas_Mem *canvas = (Canvas_Mem*) _canvas;
    if (!canvas->image) {
        canvas->image = (struct Color *) malloc(sizeof(Color) * canvas->width * canvas->height);
    }
    if (!canvas->image) {
        fprintf(stderr, "Could not allocate memory for image!");
        return 0;
    }
    canvas->next_row = 0;
    return 1;
}


decompiled_code:
void __fastcall Canvas_Mem_free(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void Canvas_Mem_free(Canvas* _canvas) {
    Canvas_Mem* canvas = (Canvas_Mem*) _canvas;
    if (canvas->image) {
        free(canvas->image);
    }
    free(canvas);
}

canonical_original_code:
void Canvas_Mem_free(struct Canvas_struct *_canvas) {
    struct Canvas_Mem *canvas = (Canvas_Mem*) _canvas;
    if (canvas->image) {
        free(canvas->image);
    }
    free(canvas);
}


original_code:
static Color trace_ray(Renderer_RayTraceSimple* renderer, const Scene* scene, const Ray* _r, unsigned int depth, double n1) {
    Point intersect;
    Vector norm;
    Object* obj;
    Color result = {0, 0, 0};
    struct material_transmit transmit;
    Color tmp_color;
    Ray r, tmp_ray;
    Vector_assign(&r.o, &_r->o);
    Vector_assign(&r.d, &_r->d);
    Vector_normalize(&r.d);
    obj = ray_intersect(scene, &r, &intersect);
    if (!obj || depth > renderer->max_depth) {
        return (Color) {0, 0, 0};
    }
    (obj)->func.normal((Object*) obj, &intersect, &norm);
    transmit = (obj->mat)->func.get_transmit((Material*) obj->mat, obj, &intersect);
    Vector_normalize(&norm);
    result = transmit.ambient;
    Vector light_direction = {1, 0, 1};
    Vector_normalize(&light_direction);
    tmp_ray.d = light_direction;
    tmp_ray.o = intersect;
    if (!ray_intersect(scene, &tmp_ray, ((void *)0))) {
        double angle_factor = ( (0)>(Vector_dot(&light_direction, &norm)) ? (0) : (Vector_dot(&light_direction, &norm)) );
        Color_scalar_mult(&tmp_color, &transmit.diffuse, angle_factor);
        Color_add(&result, &result, &tmp_color);
        if ((obj)->func.inside((Object*) obj, &r.o)) {
            Vector_scalar_mult(&norm, &norm, -1);
        }
    }
    if (!Color_is_black(&transmit.reflect)) {
        ray_reflect(&tmp_ray, &r, &intersect, &norm);
        tmp_color = trace_ray(renderer, scene, &tmp_ray, depth+1, n1);
        tmp_color = (Color) {
            tmp_color.r * (transmit.reflect.r / 255.0),
            tmp_color.g * (transmit.reflect.g / 255.0),
            tmp_color.b * (transmit.reflect.b / 255.0)
        };
        Color_add(&result, &result, &tmp_color);
    }
    if (!Color_is_black(&transmit.refract)) {
        Vector tmp_vector;
        Vector refracted;
        double n2;
        if (fabs(n1 - 1.000277) <= ( 1.0e-5 )) {
            n2 = 1.1;
        } else {
            n2 = 1.000277;
        }
        double ratio = n1 / n2;
        double cos_theta_i = -1 * Vector_dot(&r.d, &norm);
        double cos_theta_t = sqrt(1 - (ratio*ratio * (1- cos_theta_i*cos_theta_i )));
        if (!__builtin_isnan (cos_theta_t)) {
            Vector_scalar_mult(&refracted, &norm, ratio*cos_theta_i - cos_theta_t);
            if (cos_theta_i < 0) {
                Vector_scalar_mult(&refracted, &refracted, -1);
            }
            Vector_scalar_mult(&tmp_vector, &r.d, ratio);
            Vector_add(&refracted, &refracted, &tmp_vector);
            Vector_assign(&tmp_ray.o, &intersect);
            Vector_assign(&tmp_ray.d, &refracted);
            tmp_color = trace_ray(renderer, scene, &tmp_ray, depth+1, n2);
            Color_mult(&tmp_color, &tmp_color, &transmit.refract);
            Color_add(&result, &result, &tmp_color);
        }
    }
    return result;
}

canonical_original_code:
static struct Color trace_ray(struct Renderer_RayTraceSimple *renderer, struct Scene *scene, struct Ray *_r, unsigned int depth, double n1) {
    struct Vector intersect;
    struct Vector norm;
    struct Object_struct *obj;
    struct Color result = {0, 0, 0};
    struct material_transmit transmit;
    struct Color tmp_color;
    struct Ray r; struct Ray tmp_ray;
    Vector_assign(&r.o, &_r->o);
    Vector_assign(&r.d, &_r->d);
    Vector_normalize(&r.d);
    obj = ray_intersect(scene, &r, &intersect);
    if (!obj || depth > renderer->max_depth) {
        return (struct Color) {0, 0, 0};
    }
    (obj)->func.normal((struct Object_struct *) obj, &intersect, &norm);
    transmit = (obj->mat)->func.get_transmit((struct Material_struct *) obj->mat, obj, &intersect);
    Vector_normalize(&norm);
    result = transmit.ambient;
    struct Vector light_direction = {1, 0, 1};
    Vector_normalize(&light_direction);
    tmp_ray.d = light_direction;
    tmp_ray.o = intersect;
    if (!ray_intersect(scene, &tmp_ray, ((void *)0))) {
        double angle_factor = ( (0)>(Vector_dot(&light_direction, &norm)) ? (0) : (Vector_dot(&light_direction, &norm)) );
        Color_scalar_mult(&tmp_color, &transmit.diffuse, angle_factor);
        Color_add(&result, &result, &tmp_color);
        if ((obj)->func.inside((struct Object_struct *) obj, &r.o)) {
            Vector_scalar_mult(&norm, &norm, -1);
        }
    }
    if (!Color_is_black(&transmit.reflect)) {
        ray_reflect(&tmp_ray, &r, &intersect, &norm);
        tmp_color = trace_ray(renderer, scene, &tmp_ray, depth+1, n1);
        tmp_color = (struct Color) {
            tmp_color.r * (transmit.reflect.r / 255.0),
            tmp_color.g * (transmit.reflect.g / 255.0),
            tmp_color.b * (transmit.reflect.b / 255.0)
        };
        Color_add(&result, &result, &tmp_color);
    }
    if (!Color_is_black(&transmit.refract)) {
        struct Vector tmp_vector;
        struct Vector refracted;
        double n2;
        if (fabs(n1 - 1.000277) <= ( 1.0e-5 )) {
            n2 = 1.1;
        } else {
            n2 = 1.000277;
        }
        double ratio = n1 / n2;
        double cos_theta_i = -1 * Vector_dot(&r.d, &norm);
        double cos_theta_t = sqrt(1 - (ratio*ratio * (1- cos_theta_i*cos_theta_i )));
        if (!__builtin_isnan (cos_theta_t)) {
            Vector_scalar_mult(&refracted, &norm, ratio*cos_theta_i - cos_theta_t);
            if (cos_theta_i < 0) {
                Vector_scalar_mult(&refracted, &refracted, -1);
            }
            Vector_scalar_mult(&tmp_vector, &r.d, ratio);
            Vector_add(&refracted, &refracted, &tmp_vector);
            Vector_assign(&tmp_ray.o, &intersect);
            Vector_assign(&tmp_ray.d, &refracted);
            tmp_color = trace_ray(renderer, scene, &tmp_ray, depth+1, n2);
            Color_mult(&tmp_color, &tmp_color, &transmit.refract);
            Color_add(&result, &result, &tmp_color);
        }
    }
    return result;
}

variable_types: struct Renderer_RayTraceSimple { struct renderer_func_table { _Bool (*render)(struct Renderer_struct { struct renderer_func_table func; } *renderer, struct Scene { struct List { struct ListNode_struct { void *data; struct ListNode_struct *next; } *head; struct ListNode_struct *tail; unsigned int length; } *objects; } *scene, struct Camera_struct { struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray { struct Vector { double x; } o; struct Vector d; } *r); } func; struct Vector pos; } *camera, struct Canvas_struct { struct canvas_func_table { _Bool (*start)(struct Canvas_struct *canvas); struct Color *(*get_next_row)(struct Canvas_struct *canvas); _Bool (*write_row)(struct Canvas_struct *canvas, struct Color *row); _Bool (*finish)(struct Canvas_struct *canvas); void (*free)(struct Canvas_struct *canvas); } func; unsigned int width; } *canvas); } func; unsigned int max_depth; } *

variable_types:
scene
struct Scene *

variable_types:
depth
unsigned int

variable_types:
intersect
struct Vector { double x; }

variable_types:
norm
struct Vector { double x; }

variable_types: struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; }

variable_types:
refracted
struct Vector { double x; }

variable_types: ratio double

user_defined_types: struct Renderer_RayTraceSimple { struct renderer_func_table func; unsigned int max_depth; }

user_defined_types: struct renderer_func_table { _Bool (*render)(struct Renderer_struct *renderer, struct Scene *scene, struct Camera_struct *camera, struct Canvas_struct *canvas); }

user_defined_types: struct Camera_struct { struct camera_func_table func; struct Vector pos; }


original_code:
_Bool Renderer_RayTraceSimple_render(Renderer* _renderer, Scene* scene, Camera* cam, Canvas* canvas) {
    Renderer_RayTraceSimple* renderer = (Renderer_RayTraceSimple*) _renderer;
    Color* row;
    Ray ray;
    (canvas)->func.start((Canvas*) canvas);
    for (int y=canvas->height-1; y>=0; y--) {
        row = (canvas)->func.get_next_row((Canvas*) canvas);
        for (int x=0; x<canvas->width; x++) {
            (cam)->func.map((Camera*) cam, ((double)x)/canvas->width, ((double)y)/canvas->height, &ray);
            row[x] = trace_ray(renderer, scene, &ray, 0, 1.000277);
        }
        (canvas)->func.write_row((Canvas*) canvas, row);
    }
    (canvas)->func.finish((Canvas*) canvas);
    return 1;
}

canonical_original_code:
_Bool Renderer_RayTraceSimple_render(struct Renderer_struct *_renderer, struct Scene *scene, struct Camera_struct *cam, struct Canvas_struct *canvas) {
    struct Renderer_RayTraceSimple *renderer = (Renderer_RayTraceSimple*) _renderer;
    struct Color *row;
    struct Ray ray;
    (canvas)->func.start((struct Canvas_struct *) canvas);
    for (int y = canvas->height-1; y>=0; y--) {
        row = (canvas)->func.get_next_row((struct Canvas_struct *) canvas);
        for (int x = 0; x<canvas->width; x++) {
            (cam)->func.map((struct Camera_struct *) cam, ((double)x)/canvas->width, ((double)y)/canvas->height, &ray);
            row[x] = trace_ray(renderer, scene, &ray, 0, 1.000277);
        }
        (canvas)->func.write_row((struct Canvas_struct *) canvas, row);
    }
    (canvas)->func.finish((struct Canvas_struct *) canvas);
    return 1;
}

variable_types: struct Renderer_struct { struct renderer_func_table { _Bool (*render)(struct Renderer_struct *renderer, struct Scene { struct List { struct ListNode_struct { void *data; struct ListNode_struct *next; } *head; struct ListNode_struct *tail; unsigned int length; } *objects; } *scene, struct Camera_struct { struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray { struct Vector { double x; } o; struct Vector d; } *r); } func; struct Vector pos; } *camera, struct Canvas_struct { struct canvas_func_table { _Bool (*start)(struct Canvas_struct *canvas); struct Color { unsigned char r; unsigned char g; unsigned char b; } *(*get_next_row)(struct Canvas_struct *canvas); _Bool (*write_row)(struct Canvas_struct *canvas, struct Color *row); _Bool (*finish)(struct Canvas_struct *canvas); void (*free)(struct Canvas_struct *canvas); } func; unsigned int width; } *canvas); } func; } *

variable_types:
cam
struct Camera_struct *

variable_types:
canvas
struct Canvas_struct *

variable_types: struct Renderer_RayTraceSimple { struct renderer_func_table { _Bool (*render)(struct Renderer_struct { struct renderer_func_table func; } *renderer, struct Scene { struct List { struct ListNode_struct { void *data; struct ListNode_struct *next; } *head; struct ListNode_struct *tail; unsigned int length; } *objects; } *scene, struct Camera_struct { struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray { struct Vector { double x; } o; struct Vector d; } *r); } func; struct Vector pos; } *camera, struct Canvas_struct { struct canvas_func_table { _Bool (*start)(struct Canvas_struct *canvas); struct Color { unsigned char r; unsigned char g; unsigned char b; } *(*get_next_row)(struct Canvas_struct *canvas); _Bool (*write_row)(struct Canvas_struct *canvas, struct Color *row); _Bool (*finish)(struct Canvas_struct *canvas); void (*free)(struct Canvas_struct *canvas); } func; unsigned int width; } *canvas); } func; unsigned int max_depth; } *

variable_types: y int

variable_types: x int

user_defined_types: struct Ray { struct Vector o; struct Vector d; }

user_defined_types: struct camera_func_table { void (*map)(struct Camera_struct *cam, double x, double y, struct Ray *r); }

user_defined_types: struct List { struct ListNode_struct *head; struct ListNode_struct *tail; unsigned int length; }


decompiled_code:
__int64 __fastcall Material_Checker_get_transmit(__int64 a1, __int64 a2, double *a3)
{
double v4; // xmm0_8
unsigned int v5; // ebx
double v7; // [rsp+0h] [rbp-48h]
double v8; // [rsp+8h] [rbp-40h]
__int64 v9; // [rsp+24h] [rbp-24h]

v4 = round(*a3);
v5 = *(_DWORD *)(a1 + 8);
v8 = v4;
v7 = round(a3[1]);
if ( (((unsigned __int8)((int)round(a3[2]) / v5) + (unsigned __int8)((int)v7 / v5) + (unsigned __int8)((int)v8 / v5)) & 1) != 0 )
v9 = *(_QWORD *)(a1 + 12);
else
v9 = *(_QWORD *)(a1 + 24);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, double *a3)
{
double v4; // xmm0_8
unsigned int v5; // ebx
double v7; // [rsp+0h] [rbp-48h]
double v8; // [rsp+8h] [rbp-40h]
__int64 v9; // [rsp+24h] [rbp-24h]

v4 = round(*a3);
v5 = *(_DWORD *)(a1 + 8);
v8 = v4;
v7 = round(a3[1]);
if ( (((unsigned __int8)((int)round(a3[2]) / v5) + (unsigned __int8)((int)v7 / v5) + (unsigned __int8)((int)v8 / v5)) & 1) != 0 )
v9 = *(_QWORD *)(a1 + 12);
else
v9 = *(_QWORD *)(a1 + 24);
return v9;
}

original_code:
struct material_transmit Material_Checker_get_transmit(const Material* _m, const Object* object, const Point* intersect) {
    Material_Checker* m = (Material_Checker*) _m;
    if (( ((int) round(intersect->x)) / m->scale + ((int) round(intersect->y)) / m->scale + ((int) round(intersect->z)) / m->scale) % 2)
    {
        return m->tile1_transmit;
    } else {
        return m->tile2_transmit;
    }
}

canonical_original_code:
struct material_transmit Material_Checker_get_transmit(struct Material_struct *_m, struct Object_struct *object, struct Vector *intersect) {
    struct Material_Checker *m = (Material_Checker*) _m;
    if (( ((int) round(intersect->x)) / m->scale + ((int) round(intersect->y)) / m->scale + ((int) round(intersect->z)) / m->scale) % 2)
    {
        return m->tile1_transmit;
    } else {
        return m->tile2_transmit;
    }
}

variable_types: struct Material_struct { struct material_func_table { struct material_transmit (*get_transmit)(struct Material_struct *mat, struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; } *object, struct Vector *intersect); } func; } *

variable_types:
object
struct Object_struct *

variable_types:
intersect
struct Vector *

variable_types: struct Material_Checker { struct material_func_table { struct material_transmit { struct Color { unsigned char r; unsigned char g; unsigned char b; } diffuse; struct Color ambient; struct Color reflect; struct Color refract; } (*get_transmit)(struct Material_struct { struct material_func_table func; } *mat, struct Object_struct { struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray { struct Vector { double x; } o; struct Vector d; } *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); } func; struct Material_struct *mat; } *object, struct Vector *intersect); } func; unsigned int scale; struct material_transmit tile1_transmit; struct material_transmit tile2_transmit; } *

user_defined_types: struct Material_Checker { struct material_func_table func; unsigned int scale; struct material_transmit tile1_transmit; struct material_transmit tile2_transmit; }

user_defined_types: struct Object_struct { struct object_func_table func; struct Material_struct *mat; }

user_defined_types: struct object_func_table { _Bool (*ray_intersect)(struct Object_struct *obj, struct Ray *ray, struct Vector *intersect); void (*normal)(struct Object_struct *obj, struct Vector *intersect, struct Vector *normal); _Bool (*inside)(struct Object_struct *obj, struct Vector *point); }


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

result = (char *)malloc(0x28uLL);
*((_DWORD *)result + 2) = a1;
*(_QWORD *)result = Material_Checker_get_transmit;
*(_QWORD *)(result + 12) = 0LL;
*((_DWORD *)result + 5) = 0;
*((_QWORD *)result + 3) = 0xFFFFFF000000LL;
*((_DWORD *)result + 8) = 0;
return result;
}

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

result = (char *)malloc(0x28uLL);
*((_DWORD *)result + 2) = a1;
*(_QWORD *)result = Material_Checker_get_transmit;
*(_QWORD *)(result + 12) = 0LL;
*((_DWORD *)result + 5) = 0;
*((_QWORD *)result + 3) = 0xFFFFFF000000LL;
*((_DWORD *)result + 8) = 0;
return result;
}

original_code:
Material* Material_Checker_new(unsigned int scale) {
    Material_Checker* m = (Material_Checker*) malloc(sizeof(Material_Checker));
    m->func = material_checker_func_table;
    m->scale = scale;
    m->tile1_transmit = (struct material_transmit) {
        {0, 0, 0},
        {0, 0, 0},
        {0, 0, 0},
        {0, 0, 0}
    };
    m->tile2_transmit = (struct material_transmit) {
        {0, 0, 0},
        {255 ,255, 255},
        {0, 0, 0},
        {0, 0, 0}
    };
    return (Material*) m;
}

canonical_original_code:
struct Material_struct *Material_Checker_new(unsigned int scale) {
    struct Material_Checker *m = (Material_Checker*) malloc(sizeof(Material_Checker));
    m->func = material_checker_func_table;
    m->scale = scale;
    m->tile1_transmit = (struct material_transmit) {
        {0, 0, 0},
        {0, 0, 0},
        {0, 0, 0},
        {0, 0, 0}
    };
    m->tile2_transmit = (struct material_transmit) {
        {0, 0, 0},
        {255 ,255, 255},
        {0, 0, 0},
        {0, 0, 0}
    };
    return (struct Material_struct *) m;
}

variable_types:
scale
unsigned int

user_defined_types: struct material_transmit { struct Color diffuse; struct Color ambient; struct Color reflect; struct Color refract; }

user_defined_types: struct Material_struct { struct material_func_table func; }

user_defined_types: struct material_func_table { struct material_transmit (*get_transmit)(struct Material_struct *mat, struct Object_struct *object, struct Vector *intersect); }


decompiled_code:
__int64 Material_new_default()
{
return Material_Solid_new();
}

canonical_decompiled_code:
__int64 func0()
{
return Material_Solid_new();
}

original_code:
Material* Material_new_default() {
    return (Material*) Material_Solid_new();
}

canonical_original_code:
struct Material_struct *Material_new_default() {
    return (struct Material_struct *) Material_Solid_new();
}

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


original_code:
void ray_reflect(
        Ray* result,
        const Ray* r,
        const Point* intersect,
        const Vector* norm) {
    result->o.x = intersect->x;
    result->o.y = intersect->y;
    result->o.z = intersect->z;
    double dot_norm_ray = Vector_dot(norm, &r->d);
    double norm_mag_squared = Vector_mag(norm) * Vector_mag(norm);
    double double_proj_mag = 2 * dot_norm_ray / norm_mag_squared;
    result->d.x = r->d.x - double_proj_mag*norm->x;
    result->d.y = r->d.y - double_proj_mag*norm->y;
    result->d.z = r->d.z - double_proj_mag*norm->z;
}

canonical_original_code:
void ray_reflect(struct Ray *result, struct Ray *r, struct Vector *intersect, struct Vector *norm) {
    result->o.x = intersect->x;
    result->o.y = intersect->y;
    result->o.z = intersect->z;
    double dot_norm_ray = Vector_dot(norm, &r->d);
    double norm_mag_squared = Vector_mag(norm) * Vector_mag(norm);
    double double_proj_mag = 2 * dot_norm_ray / norm_mag_squared;
    result->d.x = r->d.x - double_proj_mag*norm->x;
    result->d.y = r->d.y - double_proj_mag*norm->y;
    result->d.z = r->d.z - double_proj_mag*norm->z;
}

variable_types: struct Ray { struct Vector { double x; } o; struct Vector d; } *

variable_types:
r
struct Ray *

variable_types:
norm
struct Vector *


main

canonical_name: main

repo: mbrunton/graph

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // r12
__int64 v6; // rax

if ( argc != 2 )
{
fprintf(stderr, "usage: %s filename\n", *argv);
exit(1);
}
v3 = read_graph(argv[1]);
print_graph(v3);
v4 = dfs(v3);
fwrite("DFS:\n", 1uLL, 5uLL, stderr);
print_search_tree(v4);
v5 = bfs(v3);
fwrite("BFS:\n", 1uLL, 5uLL, stderr);
print_search_tree(v5);
v6 = dijkstra(v3, 0LL);
print_dist_tree(v6);
return 0;
}

original_code:
int
main(int argc, char **argv) {
    if (argc != 2) {
        fprintf(stderr, "usage: %s filename\n", argv[0]);
        exit(1);
    }
    char *filename = argv[1];
    graph_t *G = read_graph(filename);
    print_graph(G);
    search_tree_t *dfs_tree = dfs(G);
    fprintf(stderr, "DFS:\n");
    print_search_tree(dfs_tree);
    search_tree_t *bfs_tree = bfs(G);
    fprintf(stderr, "BFS:\n");
    print_search_tree(bfs_tree);
    dist_tree_t *dij_tree = dijkstra(G, 0);
    print_dist_tree(dij_tree);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if (argc != 2) {
        fprintf(stderr, "usage: %s filename\n", argv[0]);
        exit(1);
    }
    char *filename = argv[1];
    struct graph_t *G = read_graph(filename);
    print_graph(G);
    struct search_tree_t *dfs_tree = dfs(G);
    fprintf(stderr, "DFS:\n");
    print_search_tree(dfs_tree);
    struct search_tree_t *bfs_tree = bfs(G);
    fprintf(stderr, "BFS:\n");
    print_search_tree(bfs_tree);
    struct dist_tree_t *dij_tree = dijkstra(G, 0);
    print_dist_tree(dij_tree);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
filename
char *

variable_types: struct search_tree_t { struct graph_t { struct edgelist_t { struct edge_t { int u; int v; int w; struct edge_t *next; } *head; } *edgelists; int n; int directed; } *T; int *parents; int *arrival_times; int arrival_counter; int k; } *

variable_types: struct dist_tree_t { int s; int n; int *dists; int *parents; } *

user_defined_types: struct graph_t { struct edgelist_t *edgelists; int n; int directed; }

user_defined_types: struct search_tree_t { struct graph_t *T; int *parents; int *arrival_times; int arrival_counter; int k; }

user_defined_types: struct edgelist_t { struct edge_t *head; }


decompiled_code:
_QWORD *create_empty_queue()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
{
fwrite("Error: malloc failed\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
{
fwrite("Error: malloc failed\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
queue_t *
create_empty_queue(void) {
    queue_t *Q = (queue_t *) malloc(sizeof(queue_t));
    if (((void *)0) == Q) {
        fprintf(stderr, "Error: malloc failed\n");
        exit(1);
    }
    Q->head = ((void *)0);
    Q->tail = ((void *)0);
    Q->size = 0;
    return Q;
}

canonical_original_code:
struct queue_t *create_empty_queue() {
    struct queue_t *Q = (queue_t *) malloc(sizeof(queue_t));
    if (((void *)0) == Q) {
        fprintf(stderr, "Error: malloc failed\n");
        exit(1);
    }
    Q->head = ((void *)0);
    Q->tail = ((void *)0);
    Q->size = 0;
    return Q;
}

variable_types: struct queue_t { struct item_t { void *data; struct item_t *next; } *head; struct item_t *tail; int size; } *

user_defined_types: struct queue_t { struct item_t *head; struct item_t *tail; int size; }


decompiled_code:
__int64 __fastcall q_pop(__int64 **a1)
{
int v1; // eax
__int64 *v2; // r8
__int64 v3; // r12

v1 = *((_DWORD *)a1 + 4);
if ( !v1 )
{
fwrite("Error: attempting to pop empty queue\n", 1uLL, 0x25uLL, stderr);
fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 49LL);
exit(1);
}
v2 = *a1;
v3 = **a1;
if ( v1 == 1 )
{
a1[1] = 0LL;
*a1 = 0LL;
}
else
{
*a1 = (__int64 *)v2[1];
}
*((_DWORD *)a1 + 4) = v1 - 1;
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 **a1)
{
int v1; // eax
__int64 *v2; // r8
__int64 v3; // r12

v1 = *((_DWORD *)a1 + 4);
if ( !v1 )
{
fwrite("Error: attempting to pop empty queue\n", 1uLL, 0x25uLL, stderr);
fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 49LL);
exit(1);
}
v2 = *a1;
v3 = **a1;
if ( v1 == 1 )
{
a1[1] = 0LL;
*a1 = 0LL;
}
else
{
*a1 = (__int64 *)v2[1];
}
*((_DWORD *)a1 + 4) = v1 - 1;
free(v2);
return v3;
}

original_code:
void *
q_pop(queue_t *Q) {
    if (0 == Q->size) {
        fprintf(stderr, "Error: attempting to pop empty queue\n");
        fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 49);
        exit(1);
    }
    item_t *old_head = Q->head;
    void *data = Q->head->data;
    if (1 == Q->size) {
        Q->head = Q->tail = ((void *)0);
    } else {
        Q->head = Q->head->next;
    }
    Q->size--;
    free(old_head);
    return data;
}

canonical_original_code:
void *q_pop(struct queue_t *Q) {
    if (0 == Q->size) {
        fprintf(stderr, "Error: attempting to pop empty queue\n");
        fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 49);
        exit(1);
    }
    struct item_t *old_head = Q->head;
    void *data = Q->head->data;
    if (1 == Q->size) {
        Q->head = Q->tail = ((void *)0);
    } else {
        Q->head = Q->head->next;
    }
    Q->size--;
    free(old_head);
    return data;
}

variable_types: struct item_t { void *data; struct item_t *next; } *

variable_types:
data
void *

return_type: void *


decompiled_code:
__int64 __fastcall q_peek(_DWORD *a1)
{
if ( !a1[4] )
{
fwrite("Error: attempting to peek empty queue\n", 1uLL, 0x26uLL, stderr);
fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 71LL);
exit(1);
}
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
if ( !a1[4] )
{
fwrite("Error: attempting to peek empty queue\n", 1uLL, 0x26uLL, stderr);
fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 71LL);
exit(1);
}
return **(_QWORD **)a1;
}

original_code:
void *
q_peek(queue_t *Q) {
    if (0 == Q->size) {
        fprintf(stderr, "Error: attempting to peek empty queue\n");
        fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 71);
        exit(1);
    }
    return Q->head->data;
}

canonical_original_code:
void *q_peek(struct queue_t *Q) {
    if (0 == Q->size) {
        fprintf(stderr, "Error: attempting to peek empty queue\n");
        fprintf(stderr, "file: %s\tline: %d\n", "queue.c", 71);
        exit(1);
    }
    return Q->head->data;
}

user_defined_types: struct item_t { void *data; struct item_t *next; }


decompiled_code:
_BOOL8 __fastcall q_not_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 16) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 16) != 0;
}

original_code:
int
q_not_empty(queue_t *Q) {
    return Q->size != 0;
}

canonical_original_code:
int q_not_empty(struct queue_t *Q) {
    return Q->size != 0;
}


decompiled_code:
int __fastcall print_queue(unsigned int ***a1)
{
unsigned int **i; // rbx

fwrite("QUEUE PRINTOUT:\n", 1uLL, 0x10uLL, stderr);
if ( !*((_DWORD *)a1 + 4) )
fwrite("(queue empty)\n", 1uLL, 0xEuLL, stderr);
for ( i = *a1; i; i = (unsigned int **)i[1] )
fprintf(stderr, "%d\n", **i);
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int ***a1)
{
unsigned int **i; // rbx

fwrite("QUEUE PRINTOUT:\n", 1uLL, 0x10uLL, stderr);
if ( !*((_DWORD *)a1 + 4) )
fwrite("(queue empty)\n", 1uLL, 0xEuLL, stderr);
for ( i = *a1; i; i = (unsigned int **)i[1] )
fprintf(stderr, "%d\n", **i);
return fputc(10, stderr);
}

original_code:
void
print_queue(queue_t *Q) {
    fprintf(stderr, "QUEUE PRINTOUT:\n");
    if (Q->size == 0) {
        fprintf(stderr, "(queue empty)\n");
    }
    item_t *curr;
    int *value;
    for (curr = Q->head; curr != ((void *)0); curr = curr->next) {
        value = (int *) curr->data;
        fprintf(stderr, "%d\n", *value);
    }
    fprintf(stderr, "\n");
}

canonical_original_code:
void print_queue(struct queue_t *Q) {
    fprintf(stderr, "QUEUE PRINTOUT:\n");
    if (Q->size == 0) {
        fprintf(stderr, "(queue empty)\n");
    }
    struct item_t *curr;
    int *value;
    for (curr = Q->head; curr != ((void *)0); curr = curr->next) {
        value = (int *) curr->data;
        fprintf(stderr, "%d\n", *value);
    }
    fprintf(stderr, "\n");
}

variable_types:
value
int *


original_code:
void
pq_push(pq_t *Q, void *data, int priority) {
    if (Q->size >= Q->capacity) {
        fprintf(stderr, "Error: priority queue is full\n");
        fprintf(stderr, "file: %s\tline: %d\n", "priority_queue.c", 30);
    }
    int i = Q->size;
    Q->entries[i].data = data;
    Q->entries[i].p = priority;
    Q->size++;
    entry_t temp_entry;
    while ( ( ((i)-1)/2 ) >= 0 && Q->entries[i].p < Q->entries[ ( ((i)-1)/2 ) ].p ) {
        temp_entry = Q->entries[ ( ((i)-1)/2 ) ];
        Q->entries[ ( ((i)-1)/2 ) ] = Q->entries[i];
        Q->entries[i] = temp_entry;
        i = ( ((i)-1)/2 );
    }
}

canonical_original_code:
void pq_push(struct pq_t *Q, void *data, int priority) {
    if (Q->size >= Q->capacity) {
        fprintf(stderr, "Error: priority queue is full\n");
        fprintf(stderr, "file: %s\tline: %d\n", "priority_queue.c", 30);
    }
    int i = Q->size;
    Q->entries[i].data = data;
    Q->entries[i].p = priority;
    Q->size++;
    struct entry_t temp_entry;
    while ( ( ((i)-1)/2 ) >= 0 && Q->entries[i].p < Q->entries[ ( ((i)-1)/2 ) ].p ) {
        temp_entry = Q->entries[ ( ((i)-1)/2 ) ];
        Q->entries[ ( ((i)-1)/2 ) ] = Q->entries[i];
        Q->entries[i] = temp_entry;
        i = ( ((i)-1)/2 );
    }
}

variable_types: struct pq_t { unsigned long size; unsigned long capacity; struct entry_t { void *data; int p; } *entries; } *

variable_types: priority int

variable_types: i int

user_defined_types: struct pq_t { unsigned long size; unsigned long capacity; struct entry_t *entries; }


decompiled_code:
__int64 __fastcall update_priority(__int64 *a1, __int64 a2, int a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v6; // rdx

v3 = *a1;
if ( !*a1 )
goto LABEL_6;
result = a1[2];
v6 = 0LL;
while ( *(_QWORD *)result != a2 )
{
++v6;
result += 16LL;
if ( v3 == v6 )
goto LABEL_6;
}
*(_DWORD *)(result + 8) = a3;
if ( v6 == v3 )
{
LABEL_6:
fwrite("Error: could not locate item in priority queue\n", 1uLL, 0x2FuLL, stderr);
fprintf(stderr, "file: %s\tline: %d\n", "priority_queue.c", 62LL);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 a2, int a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v6; // rdx

v3 = *a1;
if ( !*a1 )
goto LABEL_6;
result = a1[2];
v6 = 0LL;
while ( *(_QWORD *)result != a2 )
{
++v6;
result += 16LL;
if ( v3 == v6 )
goto LABEL_6;
}
*(_DWORD *)(result + 8) = a3;
if ( v6 == v3 )
{
LABEL_6:
fwrite("Error: could not locate item in priority queue\n", 1uLL, 0x2FuLL, stderr);
fprintf(stderr, "file: %s\tline: %d\n", "priority_queue.c", 62LL);
exit(1);
}
return result;
}

original_code:
void
update_priority(pq_t *Q, void *data, int priority) {
    int i;
    for (i = 0; i < Q->size; i++) {
        if (Q->entries[i].data == data) {
            Q->entries[i].p = priority;
            break;
        }
    }
    if (i == Q->size) {
        fprintf(stderr, "Error: could not locate item in priority queue\n");
        fprintf(stderr, "file: %s\tline: %d\n", "priority_queue.c", 62);
        exit(1);
    }
}

canonical_original_code:
void update_priority(struct pq_t *Q, void *data, int priority) {
    int i;
    for (i = 0; i < Q->size; i++) {
        if (Q->entries[i].data == data) {
            Q->entries[i].p = priority;
            break;
        }
    }
    if (i == Q->size) {
        fprintf(stderr, "Error: could not locate item in priority queue\n");
        fprintf(stderr, "file: %s\tline: %d\n", "priority_queue.c", 62);
        exit(1);
    }
}


original_code:
void *
pq_pop(pq_t *Q) {
    if (Q->size <= 0) {
        fprintf(stderr, "Error: priority queue is empty\n");
        fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 71);
        exit(1);
    }
    void *top = Q->entries[0].data;
    Q->entries[0] = Q->entries[Q->size - 1];
    Q->entries[Q->size - 1].data = ((void *)0);
    Q->entries[Q->size - 1].p = -1;
    Q->size--;
    entry_t temp_entry;
    int min_p;
    int min_child;
    int i = 0;
    while ((1==1)) {
        if ( (2*(i) + 1) < Q->size ) {
            if ( (2*(i) + 2) < Q->size ) {
                if (Q->entries[(2*(i) + 1)].p <= Q->entries[(2*(i) + 2)].p) {
                    min_p = Q->entries[(2*(i) + 1)].p;
                    min_child = (2*(i) + 1);
                } else {
                    min_p = Q->entries[(2*(i) + 2)].p;
                    min_child = (2*(i) + 2);
                }
                if (Q->entries[i].p > min_p) {
                    temp_entry = Q->entries[min_child];
                    Q->entries[min_child] = Q->entries[i];
                    Q->entries[i] = temp_entry;
                    i = min_child;
                } else {
                    break;
                }
            } else {
                if (Q->entries[i].p > Q->entries[(2*(i) + 1)].p) {
                    temp_entry = Q->entries[(2*(i) + 1)];
                    Q->entries[(2*(i) + 1)] = Q->entries[i];
                    Q->entries[i] = Q->entries[(2*(i) + 1)];
                    i = (2*(i) + 1);
                } else {
                    break;
                }
            }
        } else {
            break;
        }
    }
    return top;
}

canonical_original_code:
void *pq_pop(struct pq_t *Q) {
    if (Q->size <= 0) {
        fprintf(stderr, "Error: priority queue is empty\n");
        fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 71);
        exit(1);
    }
    void *top = Q->entries[0].data;
    Q->entries[0] = Q->entries[Q->size - 1];
    Q->entries[Q->size - 1].data = ((void *)0);
    Q->entries[Q->size - 1].p = -1;
    Q->size--;
    struct entry_t temp_entry;
    int min_p;
    int min_child;
    int i = 0;
    while ((1==1)) {
        if ( (2*(i) + 1) < Q->size ) {
            if ( (2*(i) + 2) < Q->size ) {
                if (Q->entries[(2*(i) + 1)].p <= Q->entries[(2*(i) + 2)].p) {
                    min_p = Q->entries[(2*(i) + 1)].p;
                    min_child = (2*(i) + 1);
                } else {
                    min_p = Q->entries[(2*(i) + 2)].p;
                    min_child = (2*(i) + 2);
                }
                if (Q->entries[i].p > min_p) {
                    temp_entry = Q->entries[min_child];
                    Q->entries[min_child] = Q->entries[i];
                    Q->entries[i] = temp_entry;
                    i = min_child;
                } else {
                    break;
                }
            } else {
                if (Q->entries[i].p > Q->entries[(2*(i) + 1)].p) {
                    temp_entry = Q->entries[(2*(i) + 1)];
                    Q->entries[(2*(i) + 1)] = Q->entries[i];
                    Q->entries[i] = Q->entries[(2*(i) + 1)];
                    i = (2*(i) + 1);
                } else {
                    break;
                }
            }
        } else {
            break;
        }
    }
    return top;
}

variable_types:
top
void *


decompiled_code:
__int64 __fastcall pq_peek(__int64 a1)
{
if ( !*(_QWORD *)a1 )
{
fwrite("Error: priority queue is empty\n", 1uLL, 0x1FuLL, stderr);
fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 135LL);
exit(1);
}
return **(_QWORD **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !*(_QWORD *)a1 )
{
fwrite("Error: priority queue is empty\n", 1uLL, 0x1FuLL, stderr);
fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 135LL);
exit(1);
}
return **(_QWORD **)(a1 + 16);
}

original_code:
void *
pq_peek(pq_t *Q) {
    if (Q->size <= 0) {
        fprintf(stderr, "Error: priority queue is empty\n");
        fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 135);
        exit(1);
    }
    return Q->entries[0].data;
}

canonical_original_code:
void *pq_peek(struct pq_t *Q) {
    if (Q->size <= 0) {
        fprintf(stderr, "Error: priority queue is empty\n");
        fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 135);
        exit(1);
    }
    return Q->entries[0].data;
}


decompiled_code:
__int64 __fastcall pq_peek_priority(_QWORD *a1)
{
if ( !*a1 )
{
fwrite("Error: priority queue is empty\n", 1uLL, 0x1FuLL, stderr);
fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 147LL);
exit(1);
}
return *(unsigned int *)(a1[2] + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
if ( !*a1 )
{
fwrite("Error: priority queue is empty\n", 1uLL, 0x1FuLL, stderr);
fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 147LL);
exit(1);
}
return *(unsigned int *)(a1[2] + 8LL);
}

original_code:
int
pq_peek_priority(pq_t *Q) {
    if (Q->size <= 0) {
        fprintf(stderr, "Error: priority queue is empty\n");
        fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 147);
        exit(1);
    }
    return Q->entries[0].p;
}

canonical_original_code:
int pq_peek_priority(struct pq_t *Q) {
    if (Q->size <= 0) {
        fprintf(stderr, "Error: priority queue is empty\n");
        fprintf(stderr, "file: %s\tline:%d\n", "priority_queue.c", 147);
        exit(1);
    }
    return Q->entries[0].p;
}


decompiled_code:
_BOOL8 __fastcall pq_not_empty(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int
pq_not_empty(pq_t *Q) {
    return Q->size != 0;
}

canonical_original_code:
int pq_not_empty(struct pq_t *Q) {
    return Q->size != 0;
}


decompiled_code:
int __fastcall print_pq(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rdx
__int64 v3; // rax

fwrite("PRIORITY QUEUE PRINTOUT:\n", 1uLL, 0x19uLL, stderr);
if ( *a1 || (fwrite("(queue empty)\n", 1uLL, 0xEuLL, stderr), *a1) )
{
v1 = 0LL;
do
{
v2 = (unsigned int)v1;
v3 = a1[2] + 16 * v1++;
fprintf(stderr, "item #%d: p = %d\n", v2, *(unsigned int *)(v3 + 8));
}
while ( *a1 > v1 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func6(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rdx
__int64 v3; // rax

fwrite("PRIORITY QUEUE PRINTOUT:\n", 1uLL, 0x19uLL, stderr);
if ( *a1 || (fwrite("(queue empty)\n", 1uLL, 0xEuLL, stderr), *a1) )
{
v1 = 0LL;
do
{
v2 = (unsigned int)v1;
v3 = a1[2] + 16 * v1++;
fprintf(stderr, "item #%d: p = %d\n", v2, *(unsigned int *)(v3 + 8));
}
while ( *a1 > v1 );
}
return fputc(10, stderr);
}

original_code:
void
print_pq(pq_t *Q) {
    fprintf(stderr, "PRIORITY QUEUE PRINTOUT:\n");
    if (Q->size == 0) {
        fprintf(stderr, "(queue empty)\n");
    }
    int i;
    for (i = 0; i < Q->size; i++) {
        fprintf(stderr, "item #%d: p = %d\n", i, Q->entries[i].p);
    }
    fprintf(stderr, "\n");
}

canonical_original_code:
void print_pq(struct pq_t *Q) {
    fprintf(stderr, "PRIORITY QUEUE PRINTOUT:\n");
    if (Q->size == 0) {
        fprintf(stderr, "(queue empty)\n");
    }
    int i;
    for (i = 0; i < Q->size; i++) {
        fprintf(stderr, "item #%d: p = %d\n", i, Q->entries[i].p);
    }
    fprintf(stderr, "\n");
}


printAllCredits

repo: mbrx/axe

decompiled_code:
void printAllCredits()
{
__int64 v0; // rbx
__int64 v1; // rdi
unsigned int v2; // eax

if ( nEntFiles > 0 )
{
v0 = 0LL;
do
{
printf("%s : ", *(const char **)(entFileNames + 8 * v0));
if ( !quiet )
printf("Printing credits for %s\n", *(const char **)(entFileNames + 8 * v0));
v1 = (unsigned int)v0++;
v2 = readCredits(v1);
printf("%d\n", v2);
}
while ( nEntFiles > (int)v0 );
}
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rbx
__int64 v1; // rdi
unsigned int v2; // eax

if ( nEntFiles > 0 )
{
v0 = 0LL;
do
{
printf("%s : ", *(const char **)(entFileNames + 8 * v0));
if ( !quiet )
printf("Printing credits for %s\n", *(const char **)(entFileNames + 8 * v0));
v1 = (unsigned int)v0++;
v2 = readCredits(v1);
printf("%d\n", v2);
}
while ( nEntFiles > (int)v0 );
}
}

original_code:
void printAllCredits() {
  for(int i=0;i<nEntFiles;i++) {
    printf("%s : ",entFileNames[i]);
    if(!quiet) printf("Printing credits for %s\n",entFileNames[i]);
    int credits = readCredits(i);
    printf("%d\n",credits);
  }
}

canonical_original_code:
void printAllCredits() {
  for(int i = 0;i<nEntFiles;i++) {
    printf("%s : ",entFileNames[i]);
    if(!quiet) printf("Printing credits for %s\n",entFileNames[i]);
    int credits = readCredits(i);
    printf("%d\n",credits);
  }
}

variable_types: credits int


printAllInventory

decompiled_code:
__int64 printAllInventory()
{
__int64 v0; // rbx
__int64 v1; // rdi
__int64 result; // rax

if ( nEntFiles > 0 )
{
v0 = 0LL;
do
{
puts(*(const char **)(entFileNames + 8 * v0));
if ( !quiet )
puts("<blockId> <amount>");
v1 = (unsigned int)v0++;
result = printInventory(v1);
}
while ( nEntFiles > (int)v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
__int64 v1; // rdi
__int64 result; // rax

if ( nEntFiles > 0 )
{
v0 = 0LL;
do
{
puts(*(const char **)(entFileNames + 8 * v0));
if ( !quiet )
puts("<blockId> <amount>");
v1 = (unsigned int)v0++;
result = printInventory(v1);
}
while ( nEntFiles > (int)v0 );
}
return result;
}

original_code:
void printAllInventory() {
  for(int i=0;i<nEntFiles;i++) {
    printf("%s\n",entFileNames[i]);
    if(!quiet) printf("<blockId> <amount>\n");
    printInventory(i);
  }
}

canonical_original_code:
void printAllInventory() {
  for(int i = 0;i<nEntFiles;i++) {
    printf("%s\n",entFileNames[i]);
    if(!quiet) printf("<blockId> <amount>\n");
    printInventory(i);
  }
}


printAllSector

decompiled_code:
int printAllSector()
{
int result; // eax
__int64 v1; // rbx
int v2[5]; // [rsp+0h] [rbp-14h] BYREF

result = nEntFiles;
if ( nEntFiles > 0 )
{
v1 = 0LL;
do
{
while ( 1 )
{
printf("%s : ", *(const char **)(entFileNames + 8 * v1));
if ( (unsigned int)getSector((unsigned int)v1, v2) )
break;
++v1;
result = puts("fail");
if ( nEntFiles <= (int)v1 )
return result;
}
++v1;
result = printf("%d %d %d\n", (unsigned int)v2[0], (unsigned int)v2[1], (unsigned int)v2[2]);
}
while ( nEntFiles > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
__int64 v1; // rbx
int v2[5]; // [rsp+0h] [rbp-14h] BYREF

result = nEntFiles;
if ( nEntFiles > 0 )
{
v1 = 0LL;
do
{
while ( 1 )
{
printf("%s : ", *(const char **)(entFileNames + 8 * v1));
if ( (unsigned int)getSector((unsigned int)v1, v2) )
break;
++v1;
result = puts("fail");
if ( nEntFiles <= (int)v1 )
return result;
}
++v1;
result = printf("%d %d %d\n", (unsigned int)v2[0], (unsigned int)v2[1], (unsigned int)v2[2]);
}
while ( nEntFiles > (int)v1 );
}
return result;
}

original_code:
void printAllSector() {
  int xyz[3];
  for(int i=0;i<nEntFiles;i++) {
    printf("%s : ",entFileNames[i]);
    if(getSector(i,xyz) == 0) printf("fail\n");
    else printf("%d %d %d\n",xyz[0],xyz[1],xyz[2]);
  }
}

canonical_original_code:
void printAllSector() {
  int xyz[3];
  for(int i = 0;i<nEntFiles;i++) {
    printf("%s : ",entFileNames[i]);
    if(getSector(i,xyz) == 0) printf("fail\n");
    else printf("%d %d %d\n",xyz[0],xyz[1],xyz[2]);
  }
}

variable_types:
xyz
int [3]