decompiled_code:
__int64 __fastcall net_node_add_input_buffer(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // r12
int v3; // eax
__int64 v4; // rdi
char v6[232]; // [rsp+0h] [rbp-E8h] BYREF

v1 = list_count(*(_QWORD *)(a1 + 56));
snprintf(v6, 0xC8uLL, "in_buf_%d", v1);
v2 = net_buffer_create(*(_QWORD *)a1, a1, *(unsigned int *)(a1 + 48), v6);
v3 = list_count(*(_QWORD *)(a1 + 56));
v4 = *(_QWORD *)(a1 + 56);
*(_DWORD *)(v2 + 24) = v3;
list_add(v4, v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // r12
int v3; // eax
__int64 v4; // rdi
char v6[232]; // [rsp+0h] [rbp-E8h] BYREF

v1 = list_count(*(_QWORD *)(a1 + 56));
snprintf(v6, 0xC8uLL, "in_buf_%d", v1);
v2 = net_buffer_create(*(_QWORD *)a1, a1, *(unsigned int *)(a1 + 48), v6);
v3 = list_count(*(_QWORD *)(a1 + 56));
v4 = *(_QWORD *)(a1 + 56);
*(_DWORD *)(v2 + 24) = v3;
list_add(v4, v2);
return v2;
}

original_code:
struct net_buffer_t *net_node_add_input_buffer(struct net_node_t *node)
{
 struct net_buffer_t *buffer;
 char name[200];
 snprintf(name, sizeof(name), "in_buf_%d", list_count(node->input_buffer_list));
 buffer = net_buffer_create(node->net, node, node->input_buffer_size, name);
 buffer->index = list_count(node->input_buffer_list);
 list_add(node->input_buffer_list, buffer);
 return buffer;
}

variable_types:
node
struct net_node_t *

variable_types: struct net_buffer_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *

variable_types:
name
char [200]


decompiled_code:
__int64 __fastcall net_node_add_output_buffer(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // r12
int v3; // eax
__int64 v4; // rdi
char v6[232]; // [rsp+0h] [rbp-E8h] BYREF

v1 = list_count(*(_QWORD *)(a1 + 64));
snprintf(v6, 0xC8uLL, "out_buf_%d", v1);
v2 = net_buffer_create(*(_QWORD *)a1, a1, *(unsigned int *)(a1 + 52), v6);
v3 = list_count(*(_QWORD *)(a1 + 64));
v4 = *(_QWORD *)(a1 + 64);
*(_DWORD *)(v2 + 24) = v3;
list_add(v4, v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // r12
int v3; // eax
__int64 v4; // rdi
char v6[232]; // [rsp+0h] [rbp-E8h] BYREF

v1 = list_count(*(_QWORD *)(a1 + 64));
snprintf(v6, 0xC8uLL, "out_buf_%d", v1);
v2 = net_buffer_create(*(_QWORD *)a1, a1, *(unsigned int *)(a1 + 52), v6);
v3 = list_count(*(_QWORD *)(a1 + 64));
v4 = *(_QWORD *)(a1 + 64);
*(_DWORD *)(v2 + 24) = v3;
list_add(v4, v2);
return v2;
}

original_code:
struct net_buffer_t *net_node_add_output_buffer(struct net_node_t *node)
{
 struct net_buffer_t *buffer;
 char name[200];
 snprintf(name, sizeof(name), "out_buf_%d", list_count(node->output_buffer_list));
 buffer = net_buffer_create(node->net, node, node->output_buffer_size, name);
 buffer->index = list_count(node->output_buffer_list);
 list_add(node->output_buffer_list, buffer);
 return buffer;
}

return_type: struct net_buffer_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *

user_defined_types: struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; }

user_defined_types: struct net_t { char *name; long long msg_id_counter; struct list_t *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t *routing_table; struct net_msg_t *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; }

user_defined_types: struct linked_list_t { int count; int error_code; struct linked_list_elem_t *head; int current_index; }

user_defined_types: struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t *entries; int has_cycle; }

user_defined_types: struct net_routing_table_entry_t { int cost; struct net_node_t *next_node; struct net_buffer_t *output_buffer; }

user_defined_types: struct net_node_t { struct net_t *net; enum net_node_kind_t kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; }


decompiled_code:
__int64 __fastcall net_node_schedule(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
int v3; // eax
__int64 v4; // rdx
int v5; // ebp
int v6; // eax
int v7; // er14
__int64 v8; // r15
__int64 v9; // rbx
__int64 v10; // rax
int v12; // [rsp+4h] [rbp-44h]
__int64 v13; // [rsp+8h] [rbp-40h]

v13 = *(_QWORD *)(*a1 + 40LL);
if ( *(_QWORD **)(a2 + 8) != a1 )
_assert_fail("output_buffer->node == node", "node.c", 0xB4u, "net_node_schedule");
v2 = list_get(a1[8], *(unsigned int *)(a2 + 24));
if ( v2 != a2 )
_assert_fail(
"list_get(node->output_buffer_list, output_buffer->index) == output_buffer",
"node.c",
0xB5u,
"net_node_schedule");
if ( *(_QWORD *)(v2 + 72) == esim_cycle )
return *(_QWORD *)(v2 + 80);
*(_QWORD *)(a2 + 72) = esim_cycle;
v3 = list_count(a1[7]);
v4 = *(_QWORD *)(a2 + 80);
v5 = v3;
v6 = 0;
if ( v4 )
v6 = *(_DWORD *)(v4 + 24);
if ( *(_QWORD *)(a2 + 48) < esim_cycle && (v7 = v6 + 1, v12 = v6 + v5 + 1, v5 > 0) )
{
while ( 1 )
{
v8 = list_get(a1[7], (unsigned int)(v7 % v5));
v9 = list_get(*(_QWORD *)(v8 + 64), 0LL);
if ( v9 )
{
if ( *(_QWORD *)(v9 + 32) < esim_cycle && esim_cycle > *(_QWORD *)(v8 + 40) )
{
v10 = *(_QWORD *)(net_routing_table_lookup(v13, a1, *(_QWORD *)(v9 + 48)) + 16);
if ( !v10 )
_assert_fail("entry->output_buffer", "node.c", 0xDEu, "net_node_schedule");
if ( v10 == a2 && *(_DWORD *)(a2 + 32) + *(_DWORD *)(v9 + 16) <= *(_DWORD *)(a2 + 28) )
break;
}
}
if ( ++v7 == v12 )
goto LABEL_19;
}
*(_QWORD *)(a2 + 80) = v8;
}
else
{
LABEL_19:
*(_QWORD *)(a2 + 80) = 0LL;
v8 = 0LL;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
int v3; // eax
__int64 v4; // rdx
int v5; // ebp
int v6; // eax
int v7; // er14
__int64 v8; // r15
__int64 v9; // rbx
__int64 v10; // rax
int v12; // [rsp+4h] [rbp-44h]
__int64 v13; // [rsp+8h] [rbp-40h]

v13 = *(_QWORD *)(*a1 + 40LL);
if ( *(_QWORD **)(a2 + 8) != a1 )
_assert_fail("output_buffer->node == node", "node.c", 0xB4u, "net_node_schedule");
v2 = list_get(a1[8], *(unsigned int *)(a2 + 24));
if ( v2 != a2 )
_assert_fail(
"list_get(node->output_buffer_list, output_buffer->index) == output_buffer",
"node.c",
0xB5u,
"net_node_schedule");
if ( *(_QWORD *)(v2 + 72) == esim_cycle )
return *(_QWORD *)(v2 + 80);
*(_QWORD *)(a2 + 72) = esim_cycle;
v3 = list_count(a1[7]);
v4 = *(_QWORD *)(a2 + 80);
v5 = v3;
v6 = 0;
if ( v4 )
v6 = *(_DWORD *)(v4 + 24);
if ( *(_QWORD *)(a2 + 48) < esim_cycle && (v7 = v6 + 1, v12 = v6 + v5 + 1, v5 > 0) )
{
while ( 1 )
{
v8 = list_get(a1[7], (unsigned int)(v7 % v5));
v9 = list_get(*(_QWORD *)(v8 + 64), 0LL);
if ( v9 )
{
if ( *(_QWORD *)(v9 + 32) < esim_cycle && esim_cycle > *(_QWORD *)(v8 + 40) )
{
v10 = *(_QWORD *)(net_routing_table_lookup(v13, a1, *(_QWORD *)(v9 + 48)) + 16);
if ( !v10 )
_assert_fail("entry->output_buffer", "node.c", 0xDEu, "net_node_schedule");
if ( v10 == a2 && *(_DWORD *)(a2 + 32) + *(_DWORD *)(v9 + 16) <= *(_DWORD *)(a2 + 28) )
break;
}
}
if ( ++v7 == v12 )
goto LABEL_19;
}
*(_QWORD *)(a2 + 80) = v8;
}
else
{
LABEL_19:
*(_QWORD *)(a2 + 80) = 0LL;
v8 = 0LL;
}
return v8;
}

original_code:
struct net_buffer_t *net_node_schedule(struct net_node_t *node,
 struct net_buffer_t *output_buffer)
{
 struct net_t *net = node->net;
 struct net_routing_table_t *routing_table = net->routing_table;
 struct net_routing_table_entry_t *entry;
 struct net_buffer_t *input_buffer;
 struct net_msg_t *msg;
 int last_input_buffer_index;
 int input_buffer_index;
 int input_buffer_count;
 int i;
 ((void) sizeof ((output_buffer->node == node) ? 1 : 0), __extension__ ({ if (output_buffer->node == node) ; else __assert_fail ("output_buffer->node == node", "node.c", 180, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((list_get(node->output_buffer_list, output_buffer->index) == output_buffer) ? 1 : 0), __extension__ ({ if (list_get(node->output_buffer_list, output_buffer->index) == output_buffer) ; else __assert_fail ("list_get(node->output_buffer_list, output_buffer->index) == output_buffer", "node.c", 181, __extension__ __PRETTY_FUNCTION__); }));
 if (output_buffer->sched_when == esim_cycle)
  return output_buffer->sched_buffer;
 output_buffer->sched_when = esim_cycle;
 input_buffer_count = list_count(node->input_buffer_list);
 last_input_buffer_index = output_buffer->sched_buffer ?
  output_buffer->sched_buffer->index : 0;
 if (output_buffer->write_busy >= esim_cycle)
 {
  output_buffer->sched_buffer = ((void *)0);
  return ((void *)0);
 }
 for (i = 0; i < input_buffer_count; i++)
 {
  input_buffer_index = (last_input_buffer_index + i + 1) % input_buffer_count;
  input_buffer = list_get(node->input_buffer_list, input_buffer_index);
  msg = list_get(input_buffer->msg_list, 0);
  if (!msg)
   continue;
  if (msg->busy >= esim_cycle)
   continue;
  if (input_buffer->read_busy >= esim_cycle)
   continue;
  entry = net_routing_table_lookup(routing_table, node, msg->dst_node);
  ((void) sizeof ((entry->output_buffer) ? 1 : 0), __extension__ ({ if (entry->output_buffer) ; else __assert_fail ("entry->output_buffer", "node.c", 222, __extension__ __PRETTY_FUNCTION__); }));
  if (entry->output_buffer != output_buffer)
   continue;
  if (output_buffer->count + msg->size > output_buffer->size)
   continue;
  output_buffer->sched_buffer = input_buffer;
  return input_buffer;
 }
 output_buffer->sched_buffer = ((void *)0);
 return ((void *)0);
}

variable_types: struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *

variable_types: struct net_routing_table_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t *next_node; struct net_buffer_t *output_buffer; } *entries; int has_cycle; } *

variable_types: struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t *output_buffer; } *

variable_types: struct net_msg_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *

variable_types: i int


decompiled_code:
_DWORD *evg_opencl_sampler_create()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 20LL, "opencl-sampler.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_sampler_create");
v1 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 9LL);
v0[1] = 1;
*v0 = v1;
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 20LL, "opencl-sampler.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_sampler_create");
v1 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 9LL);
v0[1] = 1;
*v0 = v1;
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

original_code:
struct evg_opencl_sampler_t *evg_opencl_sampler_create()
{
 struct evg_opencl_sampler_t *sampler;
 sampler = (mhandle_calloc(1, sizeof(struct evg_opencl_sampler_t), "opencl-sampler.c" ":" "34"));
 if (!sampler)
  fatal("%s: out of memory", __FUNCTION__);
 sampler->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo,
  evg_opencl_object_sampler);
 sampler->ref_count = 1;
 evg_opencl_repo_add_object(evg_emu->opencl_repo, sampler);
 return sampler;
}

variable_types: struct evg_opencl_sampler_t { unsigned int id; int ref_count; unsigned int normalized_coords; unsigned int filter_mode; unsigned int addressing_mode; } *


decompiled_code:
__int64 __fastcall evg_opencl_sampler_free(__int64 a1)
{
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
return mhandle_free(a1, "opencl-sampler.c:52");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
return mhandle_free(a1, "opencl-sampler.c:52");
}

original_code:
void evg_opencl_sampler_free(struct evg_opencl_sampler_t *sampler)
{
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, sampler);
 (mhandle_free(sampler, "opencl-sampler.c" ":" "52"));
}

return_type: void

user_defined_types: struct evg_opencl_sampler_t { unsigned int id; int ref_count; unsigned int normalized_coords; unsigned int filter_mode; unsigned int addressing_mode; }


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

for ( result = *(_QWORD *)(a1 + 8LL * ((a2 >> 4) & 0x1F) + 16); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == (a2 & 0xFFFFFFF0) )
break;
}
return result;
}

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

for ( result = *(_QWORD *)(a1 + 8LL * ((a2 >> 4) & 0x1F) + 16); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == (a2 & 0xFFFFFFF0) )
break;
}
return result;
}

original_code:
static struct spec_mem_page_t *spec_mem_page_get(struct spec_mem_t *spec_mem, uint32_t addr)
{
 struct spec_mem_page_t *page;
 int index;
 addr &= (~((1 << 4) - 1));
 index = (addr >> 4) % 32;
 page = spec_mem->pages[index];
 while (page && page->addr != addr)
  page = page->next;
 return page;
}

canonical_original_code:
static struct spec_mem_page_t *spec_mem_page_get(struct spec_mem_t *spec_mem, unsigned int addr)
{
 struct spec_mem_page_t *page;
 int index;
 addr &= (~((1 << 4) - 1));
 index = (addr >> 4) % 32;
 page = spec_mem->pages[index];
 while (page && page->addr != addr)
  page = page->next;
 return page;
}

variable_types: struct spec_mem_t { struct mem_t { int num_links; struct mem_page_t { unsigned int tag; enum mem_access_t { mem_access_none=0, mem_access_read=1, mem_access_write=2, mem_access_exec=4, mem_access_init=8, mem_access_modif=16 } perm; struct mem_page_t *next; unsigned char *data; } *pages[1024]; int safe; unsigned int heap_break; unsigned int last_address; } *mem; int page_count; struct spec_mem_page_t *pages[32]; } *

variable_types:
addr
unsigned int

variable_types: struct spec_mem_page_t { unsigned int addr; unsigned char data[-1]; struct spec_mem_page_t *next; } *

variable_types: index int

user_defined_types: struct spec_mem_t { struct mem_t *mem; int page_count; struct spec_mem_page_t *pages[32]; }

user_defined_types: struct mem_t { int num_links; struct mem_page_t *pages[1024]; int safe; unsigned int heap_break; unsigned int last_address; }

user_defined_types: struct mem_page_t { unsigned int tag; enum mem_access_t perm; struct mem_page_t *next; unsigned char *data; }


decompiled_code:
unsigned int *__fastcall spec_mem_page_create(__int64 *a1, unsigned int a2)
{
__int64 v2; // r13
unsigned int *v3; // rax
unsigned int *v4; // r12
__int64 v5; // rax
unsigned int *result; // rax

v2 = *a1;
v3 = (unsigned int *)mhandle_calloc(1LL, 32LL, "spec-mem.c:57");
*v3 = a2 & 0xFFFFFFF0;
v4 = v3;
*(_DWORD *)(v2 + 8200) = 0;
mem_read(v2, a2 & 0xFFFFFFF0, 16LL, v3 + 1);
*(_DWORD *)(v2 + 8200) = mem_safe_mode;
v5 = ((a2 >> 4) & 0x1F) + 2LL;
*((_QWORD *)v4 + 3) = a1[v5];
a1[v5] = (__int64)v4;
result = v4;
++*((_DWORD *)a1 + 2);
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func1(__int64 *a1, unsigned int a2)
{
__int64 v2; // r13
unsigned int *v3; // rax
unsigned int *v4; // r12
__int64 v5; // rax
unsigned int *result; // rax

v2 = *a1;
v3 = (unsigned int *)mhandle_calloc(1LL, 32LL, "spec-mem.c:57");
*v3 = a2 & 0xFFFFFFF0;
v4 = v3;
*(_DWORD *)(v2 + 8200) = 0;
mem_read(v2, a2 & 0xFFFFFFF0, 16LL, v3 + 1);
*(_DWORD *)(v2 + 8200) = mem_safe_mode;
v5 = ((a2 >> 4) & 0x1F) + 2LL;
*((_QWORD *)v4 + 3) = a1[v5];
a1[v5] = (__int64)v4;
result = v4;
++*((_DWORD *)a1 + 2);
return result;
}

original_code:
static struct spec_mem_page_t *spec_mem_page_create(struct spec_mem_t *spec_mem, uint32_t addr)
{
 struct mem_t *mem = spec_mem->mem;
 struct spec_mem_page_t *page;
 int index;
 addr &= (~((1 << 4) - 1));
 index = (addr >> 4) % 32;
 page = (mhandle_calloc(1, sizeof(struct spec_mem_page_t), "spec-mem.c" ":" "57"));
 page->addr = addr;
 mem->safe = 0;
 mem_read(mem, addr, (1 << 4), page->data);
 mem->safe = mem_safe_mode;
 page->next = spec_mem->pages[index];
 spec_mem->pages[index] = page;
 spec_mem->page_count++;
 return page;
}

canonical_original_code:
static struct spec_mem_page_t *spec_mem_page_create(struct spec_mem_t *spec_mem, unsigned int addr)
{
 struct mem_t *mem = spec_mem->mem;
 struct spec_mem_page_t *page;
 int index;
 addr &= (~((1 << 4) - 1));
 index = (addr >> 4) % 32;
 page = (mhandle_calloc(1, sizeof(struct spec_mem_page_t), "spec-mem.c" ":" "57"));
 page->addr = addr;
 mem->safe = 0;
 mem_read(mem, addr, (1 << 4), page->data);
 mem->safe = mem_safe_mode;
 page->next = spec_mem->pages[index];
 spec_mem->pages[index] = page;
 spec_mem->page_count++;
 return page;
}

variable_types: struct mem_t { int num_links; struct mem_page_t { unsigned int tag; enum mem_access_t { mem_access_none=0, mem_access_read=1, mem_access_write=2, mem_access_exec=4, mem_access_init=8, mem_access_modif=16 } perm; struct mem_page_t *next; unsigned char *data; } *pages[1024]; int safe; unsigned int heap_break; unsigned int last_address; } *

return_type: struct spec_mem_page_t { unsigned int addr; unsigned char data[-1]; struct spec_mem_page_t *next; } *


decompiled_code:
__int64 __fastcall spec_mem_access_aligned(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
__int64 v5; // r12
__int64 result; // rax
_DWORD *v7; // rcx
int v8; // er8
__int64 v9; // rbp
_DWORD *v10; // rdx
unsigned __int64 v11; // rcx
char *v12; // rdx
char *v13; // r13
unsigned int v14; // er12
unsigned int v15; // er12
__int64 v16; // rdx
unsigned __int64 v17; // rsi
char *v18; // r13
unsigned int v19; // er12
__int64 v20; // rdx
unsigned int v21; // er12
__int64 v22; // rcx
__int64 v23; // rbx

v5 = a3;
result = spec_mem_page_get(a1, a2);
if ( !result )
{
if ( v8 == 1 )
{
v23 = *(_QWORD *)a1;
*(_DWORD *)(v23 + 8200) = 0;
mem_read(v23, a2, (unsigned int)v5, v7);
result = mem_safe_mode;
*(_DWORD *)(v23 + 8200) = mem_safe_mode;
return result;
}
if ( *(int *)(a1 + 8) > 99 )
return result;
v9 = a2 & 0xF;
result = (__int64)spec_mem_page_create((__int64 *)a1, a2);
if ( (unsigned int)(v5 + v9) <= 0x10 )
{
LABEL_4:
v10 = (_DWORD *)(result + v9 + 4);
if ( (unsigned int)v5 < 8 )
{
if ( (v5 & 4) != 0 )
{
*v10 = *(_DWORD *)a4;
result = *(unsigned int *)&a4[v5 - 4];
*(_DWORD *)((char *)v10 + v5 - 4) = result;
}
else if ( (_DWORD)v5 )
{
result = (unsigned __int8)*a4;
*(_BYTE *)v10 = result;
if ( (v5 & 2) != 0 )
{
result = *(unsigned __int16 *)&a4[v5 - 2];
*(_WORD *)((char *)v10 + v5 - 2) = result;
}
}
}
else
{
*(_QWORD *)v10 = *(_QWORD *)a4;
result = (unsigned int)v5;
*(_QWORD *)((char *)v10 + (unsigned int)v5 - 8) = *(_QWORD *)&a4[(unsigned int)v5 - 8];
v11 = (unsigned __int64)(v10 + 2) & 0xFFFFFFFFFFFFFFF8LL;
v12 = (char *)v10 - v11;
v13 = (char *)(a4 - v12);
v14 = ((_DWORD)v12 + v5) & 0xFFFFFFF8;
if ( v14 >= 8 )
{
v15 = v14 & 0xFFFFFFF8;
LODWORD(result) = 0;
do
{
v16 = (unsigned int)result;
result = (unsigned int)(result + 8);
*(_QWORD *)(v11 + v16) = *(_QWORD *)&v13[v16];
}
while ( (unsigned int)result < v15 );
}
}
return result;
}
LABEL_21:
_assert_fail("offset + size <= SPEC_MEM_PAGE_SIZE", "spec-mem.c", 0x6Fu, "spec_mem_access_aligned");
}
v9 = a2 & 0xF;
if ( (unsigned int)(v5 + v9) > 0x10 )
goto LABEL_21;
if ( v8 != 1 )
goto LABEL_4;
result += v9 + 4;
if ( (unsigned int)v5 < 8 )
{
if ( (v5 & 4) != 0 )
{
*v7 = *(_DWORD *)result;
result = *(unsigned int *)(result + v5 - 4);
*(_DWORD *)((char *)v7 + v5 - 4) = result;
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)v7 = *(_BYTE *)result;
if ( (v5 & 2) != 0 )
{
result = *(unsigned __int16 *)(result + v5 - 2);
*(_WORD *)((char *)v7 + v5 - 2) = result;
}
}
}
else
{
v17 = (unsigned __int64)(a4 + 8) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)v7 = *(_QWORD *)result;
*(_QWORD *)&a4[(unsigned int)v5 - 8] = *(_QWORD *)(result + (unsigned int)v5 - 8);
v18 = &a4[-v17];
result -= (__int64)v18;
v19 = ((_DWORD)v18 + v5) & 0xFFFFFFF8;
v20 = result;
if ( v19 >= 8 )
{
v21 = v19 & 0xFFFFFFF8;
LODWORD(result) = 0;
do
{
v22 = (unsigned int)result;
result = (unsigned int)(result + 8);
*(_QWORD *)(v17 + v22) = *(_QWORD *)(v20 + v22);
}
while ( (unsigned int)result < v21 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
__int64 v5; // r12
__int64 result; // rax
_DWORD *v7; // rcx
int v8; // er8
__int64 v9; // rbp
_DWORD *v10; // rdx
unsigned __int64 v11; // rcx
char *v12; // rdx
char *v13; // r13
unsigned int v14; // er12
unsigned int v15; // er12
__int64 v16; // rdx
unsigned __int64 v17; // rsi
char *v18; // r13
unsigned int v19; // er12
__int64 v20; // rdx
unsigned int v21; // er12
__int64 v22; // rcx
__int64 v23; // rbx

v5 = a3;
result = func0(a1, a2);
if ( !result )
{
if ( v8 == 1 )
{
v23 = *(_QWORD *)a1;
*(_DWORD *)(v23 + 8200) = 0;
mem_read(v23, a2, (unsigned int)v5, v7);
result = mem_safe_mode;
*(_DWORD *)(v23 + 8200) = mem_safe_mode;
return result;
}
if ( *(int *)(a1 + 8) > 99 )
return result;
v9 = a2 & 0xF;
result = (__int64)func1((__int64 *)a1, a2);
if ( (unsigned int)(v5 + v9) <= 0x10 )
{
LABEL_4:
v10 = (_DWORD *)(result + v9 + 4);
if ( (unsigned int)v5 < 8 )
{
if ( (v5 & 4) != 0 )
{
*v10 = *(_DWORD *)a4;
result = *(unsigned int *)&a4[v5 - 4];
*(_DWORD *)((char *)v10 + v5 - 4) = result;
}
else if ( (_DWORD)v5 )
{
result = (unsigned __int8)*a4;
*(_BYTE *)v10 = result;
if ( (v5 & 2) != 0 )
{
result = *(unsigned __int16 *)&a4[v5 - 2];
*(_WORD *)((char *)v10 + v5 - 2) = result;
}
}
}
else
{
*(_QWORD *)v10 = *(_QWORD *)a4;
result = (unsigned int)v5;
*(_QWORD *)((char *)v10 + (unsigned int)v5 - 8) = *(_QWORD *)&a4[(unsigned int)v5 - 8];
v11 = (unsigned __int64)(v10 + 2) & 0xFFFFFFFFFFFFFFF8LL;
v12 = (char *)v10 - v11;
v13 = (char *)(a4 - v12);
v14 = ((_DWORD)v12 + v5) & 0xFFFFFFF8;
if ( v14 >= 8 )
{
v15 = v14 & 0xFFFFFFF8;
LODWORD(result) = 0;
do
{
v16 = (unsigned int)result;
result = (unsigned int)(result + 8);
*(_QWORD *)(v11 + v16) = *(_QWORD *)&v13[v16];
}
while ( (unsigned int)result < v15 );
}
}
return result;
}
LABEL_21:
_assert_fail("offset + size <= SPEC_MEM_PAGE_SIZE", "spec-mem.c", 0x6Fu, "spec_mem_access_aligned");
}
v9 = a2 & 0xF;
if ( (unsigned int)(v5 + v9) > 0x10 )
goto LABEL_21;
if ( v8 != 1 )
goto LABEL_4;
result += v9 + 4;
if ( (unsigned int)v5 < 8 )
{
if ( (v5 & 4) != 0 )
{
*v7 = *(_DWORD *)result;
result = *(unsigned int *)(result + v5 - 4);
*(_DWORD *)((char *)v7 + v5 - 4) = result;
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)v7 = *(_BYTE *)result;
if ( (v5 & 2) != 0 )
{
result = *(unsigned __int16 *)(result + v5 - 2);
*(_WORD *)((char *)v7 + v5 - 2) = result;
}
}
}
else
{
v17 = (unsigned __int64)(a4 + 8) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)v7 = *(_QWORD *)result;
*(_QWORD *)&a4[(unsigned int)v5 - 8] = *(_QWORD *)(result + (unsigned int)v5 - 8);
v18 = &a4[-v17];
result -= (__int64)v18;
v19 = ((_DWORD)v18 + v5) & 0xFFFFFFF8;
v20 = result;
if ( v19 >= 8 )
{
v21 = v19 & 0xFFFFFFF8;
LODWORD(result) = 0;
do
{
v22 = (unsigned int)result;
result = (unsigned int)(result + 8);
*(_QWORD *)(v17 + v22) = *(_QWORD *)(v20 + v22);
}
while ( (unsigned int)result < v21 );
}
}
return result;
}

original_code:
static void spec_mem_access_aligned(struct spec_mem_t *spec_mem, uint32_t addr, int size,
 void *buf, enum mem_access_t access)
{
 struct mem_t *mem = spec_mem->mem;
 struct spec_mem_page_t *page;
 uint32_t offset;
 page = spec_mem_page_get(spec_mem, addr);
 if (!page)
 {
  if (access == mem_access_read)
  {
   mem->safe = 0;
   mem_read(mem, addr, size, buf);
   mem->safe = mem_safe_mode;
   return;
  }
  else
  {
   if (spec_mem->page_count >= 100)
    return;
   page = spec_mem_page_create(spec_mem, addr);
  }
 }
 offset = addr & ~(~((1 << 4) - 1));
 ((void) sizeof ((offset + size <= (1 << 4)) ? 1 : 0), __extension__ ({ if (offset + size <= (1 << 4)) ; else __assert_fail ("offset + size <= SPEC_MEM_PAGE_SIZE", "spec-mem.c", 111, __extension__ __PRETTY_FUNCTION__); }));
 if (access == mem_access_read)
  memcpy(buf, page->data + offset, size);
 else
  memcpy(page->data + offset, buf, size);
}

canonical_original_code:
static void spec_mem_access_aligned(struct spec_mem_t *spec_mem, unsigned int addr, int size, void *buf, enum mem_access_t access)
{
 struct mem_t *mem = spec_mem->mem;
 struct spec_mem_page_t *page;
 unsigned int offset;
 page = spec_mem_page_get(spec_mem, addr);
 if (!page)
 {
  if (access == mem_access_read)
  {
   mem->safe = 0;
   mem_read(mem, addr, size, buf);
   mem->safe = mem_safe_mode;
   return;
  }
  else
  {
   if (spec_mem->page_count >= 100)
    return;
   page = spec_mem_page_create(spec_mem, addr);
  }
 }
 offset = addr & ~(~((1 << 4) - 1));
 ((void) sizeof ((offset + size <= (1 << 4)) ? 1 : 0), __extension__ ({ if (offset + size <= (1 << 4)) ; else __assert_fail ("offset + size <= SPEC_MEM_PAGE_SIZE", "spec-mem.c", 111, __extension__ __PRETTY_FUNCTION__); }));
 if (access == mem_access_read)
  memcpy(buf, page->data + offset, size);
 else
  memcpy(page->data + offset, buf, size);
}

variable_types: struct spec_mem_t { struct mem_t { int num_links; struct mem_page_t { unsigned int tag; enum mem_access_t { mem_access_none=0, mem_access_read=1, mem_access_write=2, mem_access_exec=4, mem_access_init=8, mem_access_modif=16 } perm; struct mem_page_t *next; unsigned char *data; } *pages[1024]; int safe; unsigned int heap_break; unsigned int last_address; } *mem; int page_count; struct spec_mem_page_t { unsigned int addr; unsigned char data[-1]; struct spec_mem_page_t *next; } *pages[32]; } *

variable_types: size int

variable_types:
buf
void *

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall spec_mem_access(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
unsigned int v6; // ebp
unsigned int v7; // esi
unsigned int v8; // ebx
__int64 result; // rax

if ( a3 )
{
v6 = a3;
do
{
v7 = a2;
v8 = 16 - (a2 & 0xF);
if ( v8 > v6 )
v8 = v6;
a2 += v8;
spec_mem_access_aligned(a1, v7, v8, a4);
result = v8;
a4 += v8;
v6 -= v8;
}
while ( v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
unsigned int v6; // ebp
unsigned int v7; // esi
unsigned int v8; // ebx
__int64 result; // rax

if ( a3 )
{
v6 = a3;
do
{
v7 = a2;
v8 = 16 - (a2 & 0xF);
if ( v8 > v6 )
v8 = v6;
a2 += v8;
func2(a1, v7, v8, a4);
result = v8;
a4 += v8;
v6 -= v8;
}
while ( v6 );
}
return result;
}

original_code:
static void spec_mem_access(struct spec_mem_t *spec_mem, uint32_t addr, int size,
 void *buf, enum mem_access_t access)
{
 uint32_t offset;
 int chunksize;
 while (size)
 {
  offset = addr & ((1 << 4) - 1);
  chunksize = ((size) < ((1 << 4) - offset) ? (size) : ((1 << 4) - offset));
  spec_mem_access_aligned(spec_mem, addr, chunksize, buf, access);
  size -= chunksize;
  buf += chunksize;
  addr += chunksize;
 }
}

canonical_original_code:
static void spec_mem_access(struct spec_mem_t *spec_mem, unsigned int addr, int size, void *buf, enum mem_access_t access)
{
 unsigned int offset;
 int chunksize;
 while (size)
 {
  offset = addr & ((1 << 4) - 1);
  chunksize = ((size) < ((1 << 4) - offset) ? (size) : ((1 << 4) - offset));
  spec_mem_access_aligned(spec_mem, addr, chunksize, buf, access);
  size -= chunksize;
  buf += chunksize;
  addr += chunksize;
 }
}

variable_types: enum mem_access_t { mem_access_none=0, mem_access_read=1, mem_access_write=2, mem_access_exec=4, mem_access_init=8, mem_access_modif=16 }

variable_types: chunksize int

user_defined_types: struct spec_mem_page_t { unsigned int addr; unsigned char data[-1]; struct spec_mem_page_t *next; }


decompiled_code:
__int64 __fastcall spec_mem_read(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
return spec_mem_access(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
return func3(a1, a2, a3, a4);
}

original_code:
void spec_mem_read(struct spec_mem_t *spec_mem, uint32_t addr, int size, void *buf)
{
 spec_mem_access(spec_mem, addr, size, buf, mem_access_read);
}

canonical_original_code:
void spec_mem_read(struct spec_mem_t *spec_mem, unsigned int addr, int size, void *buf)
{
 spec_mem_access(spec_mem, addr, size, buf, mem_access_read);
}

user_defined_types: enum mem_access_t { mem_access_none=0, mem_access_read=1, mem_access_write=2, mem_access_exec=4, mem_access_init=8, mem_access_modif=16 }


decompiled_code:
__int64 __fastcall spec_mem_write(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
return spec_mem_access(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3, char *a4)
{
return func3(a1, a2, a3, a4);
}

original_code:
void spec_mem_write(struct spec_mem_t *spec_mem, uint32_t addr, int size, void *buf)
{
 spec_mem_access(spec_mem, addr, size, buf, mem_access_write);
}

canonical_original_code:
void spec_mem_write(struct spec_mem_t *spec_mem, unsigned int addr, int size, void *buf)
{
 spec_mem_access(spec_mem, addr, size, buf, mem_access_write);
}


original_code:
void spec_mem_clear(struct spec_mem_t *spec_mem)
{
 struct spec_mem_page_t *page, *next;
 int i;
 for (i = 0; i < 32; i++)
 {
  page = spec_mem->pages[i];
  while (page)
  {
   next = page->next;
   (mhandle_free(page, "spec-mem.c" ":" "189"));
   page = next;
  }
  spec_mem->pages[i] = ((void *)0);
 }
 spec_mem->page_count = 0;
}

canonical_original_code:
void spec_mem_clear(struct spec_mem_t *spec_mem)
{
 struct spec_mem_page_t *page; struct spec_mem_page_t *next;
 int i;
 for (i = 0; i < 32; i++)
 {
  page = spec_mem->pages[i];
  while (page)
  {
   next = page->next;
   (mhandle_free(page, "spec-mem.c" ":" "189"));
   page = next;
  }
  spec_mem->pages[i] = ((void *)0);
 }
 spec_mem->page_count = 0;
}


decompiled_code:
__int64 __fastcall spec_mem_free(__int64 a1)
{
spec_mem_clear(a1);
return mhandle_free(a1, "spec-mem.c:162");
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
func6(a1);
return mhandle_free(a1, "spec-mem.c:162");
}

original_code:
void spec_mem_free(struct spec_mem_t *spec_mem)
{
 spec_mem_clear(spec_mem);
 (mhandle_free(spec_mem, "spec-mem.c" ":" "162"));
}


decompiled_code:
__int64 __fastcall net_link_free(__int64 a1)
{
mhandle_free(*(_QWORD *)(a1 + 8), "link.c:77");
return mhandle_free(a1, "link.c:78");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
mhandle_free(*(_QWORD *)(a1 + 8), "link.c:77");
return mhandle_free(a1, "link.c:78");
}

original_code:
void net_link_free(struct net_link_t *link)
{
 (mhandle_free(link->name, "link.c" ":" "77"));
 (mhandle_free(link, "link.c" ":" "78"));
}

variable_types: struct net_link_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *

user_defined_types: struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; }


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

if ( a1 - 1 > 0x29 )
result = (char *)map_value(&x86_uinst_dep_map, a1);
else
result = (&x86_uinst_dep_name)[a1];
return result;
}

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

if ( a1 - 1 > 0x29 )
result = (char *)map_value(&x86_uinst_dep_map, a1);
else
result = (&x86_uinst_dep_name)[a1];
return result;
}

original_code:
static char *x86_uinst_dep_name_get(int dep)
{
 if ((((dep) >= x86_dep_int_first && (dep) <= x86_dep_int_last) || ((dep) >= x86_dep_fp_first && (dep) <= x86_dep_fp_last) || ((dep) >= x86_dep_xmm_first && (dep) <= x86_dep_xmm_last)))
  return x86_uinst_dep_name[dep];
 else
  return map_value(&x86_uinst_dep_map, dep);
}

variable_types: dep int

return_type: char *


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

result = list_create();
x86_uinst_list = result;
return result;
}

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

result = list_create();
x86_uinst_list = result;
return result;
}

original_code:
void x86_uinst_init(void)
{
 x86_uinst_list = list_create();
}

canonical_original_code:
void x86_uinst_init()
{
 x86_uinst_list = list_create();
}


decompiled_code:
__int64 x86_uinst_create()
{
__int64 v0; // r12

v0 = mhandle_calloc(1LL, 56LL, "uinst.c:535");
if ( !v0 )
fatal("%s: out of memory", "x86_uinst_create");
*(_QWORD *)(v0 + 32) = v0 + 4;
*(_QWORD *)(v0 + 40) = v0 + 16;
return v0;
}

original_code:
struct x86_uinst_t *x86_uinst_create(void)
{
 struct x86_uinst_t *uinst;
 uinst = (mhandle_calloc(1, sizeof(struct x86_uinst_t), "uinst.c" ":" "535"));
 if (!uinst)
  fatal("%s: out of memory", __FUNCTION__);
 uinst->idep = uinst->dep;
 uinst->odep = &uinst->dep[3];
 return uinst;
}

canonical_original_code:
struct x86_uinst_t *x86_uinst_create()
{
 struct x86_uinst_t *uinst;
 uinst = (mhandle_calloc(1, sizeof(struct x86_uinst_t), "uinst.c" ":" "535"));
 if (!uinst)
  fatal("%s: out of memory", __FUNCTION__);
 uinst->idep = uinst->dep;
 uinst->odep = &uinst->dep[3];
 return uinst;
}

variable_types: struct x86_uinst_t { enum x86_uinst_opcode_t { x86_uinst_nop=0, x86_uinst_move=1, x86_uinst_add=2, x86_uinst_sub=3, x86_uinst_mult=4, x86_uinst_div=5, x86_uinst_effaddr=6, x86_uinst_and=7, x86_uinst_or=8, x86_uinst_xor=9, x86_uinst_not=10, x86_uinst_shift=11, x86_uinst_sign=12, x86_uinst_fp_move=13, x86_uinst_fp_sign=14, x86_uinst_fp_round=15, x86_uinst_fp_add=16, x86_uinst_fp_sub=17, x86_uinst_fp_comp=18, x86_uinst_fp_mult=19, x86_uinst_fp_div=20, x86_uinst_fp_exp=21, x86_uinst_fp_log=22, x86_uinst_fp_sin=23, x86_uinst_fp_cos=24, x86_uinst_fp_sincos=25, x86_uinst_fp_tan=26, x86_uinst_fp_atan=27, x86_uinst_fp_sqrt=28, x86_uinst_fp_push=29, x86_uinst_fp_pop=30, x86_uinst_xmm_and=31, x86_uinst_xmm_or=32, x86_uinst_xmm_xor=33, x86_uinst_xmm_not=34, x86_uinst_xmm_shift=35, x86_uinst_xmm_sign=36, x86_uinst_xmm_add=37, x86_uinst_xmm_sub=38, x86_uinst_xmm_comp=39, x86_uinst_xmm_mult=40, x86_uinst_xmm_div=41, x86_uinst_xmm_fp_add=42, x86_uinst_xmm_fp_sub=43, x86_uinst_xmm_fp_comp=44, x86_uinst_xmm_fp_mult=45, x86_uinst_xmm_fp_div=46, x86_uinst_xmm_fp_sqrt=47, x86_uinst_xmm_move=48, x86_uinst_xmm_shuf=49, x86_uinst_xmm_conv=50, x86_uinst_load=51, x86_uinst_store=52, x86_uinst_call=53, x86_uinst_ret=54, x86_uinst_jump=55, x86_uinst_branch=56, x86_uinst_ibranch=57, x86_uinst_syscall=58, x86_uinst_opcode_count=59 } opcode; enum x86_dep_t { x86_dep_none=0, x86_dep_eax=1, x86_dep_ecx=2, x86_dep_edx=3, x86_dep_ebx=4, x86_dep_esp=5, x86_dep_ebp=6, x86_dep_esi=7, x86_dep_edi=8, x86_dep_es=9, x86_dep_cs=10, x86_dep_ss=11, x86_dep_ds=12, x86_dep_fs=13, x86_dep_gs=14, x86_dep_zps=15, x86_dep_of=16, x86_dep_cf=17, x86_dep_df=18, x86_dep_aux=19, x86_dep_aux2=20, x86_dep_ea=21, x86_dep_data=22, x86_dep_int_first=expr, x86_dep_int_last=expr, x86_dep_int_count=expr, x86_dep_flag_first=expr, x86_dep_flag_last=expr, x86_dep_flag_count=expr, x86_dep_st0=23, x86_dep_st1=24, x86_dep_st2=25, x86_dep_st3=26, x86_dep_st4=27, x86_dep_st5=28, x86_dep_st6=29, x86_dep_st7=30, x86_dep_fpst=31, x86_dep_fpcw=32, x86_dep_fpaux=33, x86_dep_fp_first=expr, x86_dep_fp_last=expr, x86_dep_fp_count=expr, x86_dep_fp_stack_first=expr, x86_dep_fp_stack_last=expr, x86_dep_fp_stack_count=expr, x86_dep_xmm0=34, x86_dep_xmm1=35, x86_dep_xmm2=36, x86_dep_xmm3=37, x86_dep_xmm4=38, x86_dep_xmm5=39, x86_dep_xmm6=40, x86_dep_xmm7=41, x86_dep_xmm_data=42, x86_dep_xmm_first=expr, x86_dep_xmm_last=expr, x86_dep_xmm_count=expr, x86_dep_rm8=256, x86_dep_rm16=257, x86_dep_rm32=258, x86_dep_ir8=512, x86_dep_ir16=513, x86_dep_ir32=514, x86_dep_r8=768, x86_dep_r16=769, x86_dep_r32=770, x86_dep_sreg=1024, x86_dep_mem8=1280, x86_dep_mem16=1281, x86_dep_mem32=1282, x86_dep_mem64=1283, x86_dep_mem80=1284, x86_dep_mem128=1285, x86_dep_easeg=1537, x86_dep_eabas=1538, x86_dep_eaidx=1539, x86_dep_sti=1792, x86_dep_xmmm32=2048, x86_dep_xmmm64=2049, x86_dep_xmmm128=2050, x86_dep_xmm=2304 } dep[-1]; enum x86_dep_t { x86_dep_none=0, x86_dep_eax=1, x86_dep_ecx=2, x86_dep_edx=3, x86_dep_ebx=4, x86_dep_esp=5, x86_dep_ebp=6, x86_dep_esi=7, x86_dep_edi=8, x86_dep_es=9, x86_dep_cs=10, x86_dep_ss=11, x86_dep_ds=12, x86_dep_fs=13, x86_dep_gs=14, x86_dep_zps=15, x86_dep_of=16, x86_dep_cf=17, x86_dep_df=18, x86_dep_aux=19, x86_dep_aux2=20, x86_dep_ea=21, x86_dep_data=22, x86_dep_int_first=expr, x86_dep_int_last=expr, x86_dep_int_count=expr, x86_dep_flag_first=expr, x86_dep_flag_last=expr, x86_dep_flag_count=expr, x86_dep_st0=23, x86_dep_st1=24, x86_dep_st2=25, x86_dep_st3=26, x86_dep_st4=27, x86_dep_st5=28, x86_dep_st6=29, x86_dep_st7=30, x86_dep_fpst=31, x86_dep_fpcw=32, x86_dep_fpaux=33, x86_dep_fp_first=expr, x86_dep_fp_last=expr, x86_dep_fp_count=expr, x86_dep_fp_stack_first=expr, x86_dep_fp_stack_last=expr, x86_dep_fp_stack_count=expr, x86_dep_xmm0=34, x86_dep_xmm1=35, x86_dep_xmm2=36, x86_dep_xmm3=37, x86_dep_xmm4=38, x86_dep_xmm5=39, x86_dep_xmm6=40, x86_dep_xmm7=41, x86_dep_xmm_data=42, x86_dep_xmm_first=expr, x86_dep_xmm_last=expr, x86_dep_xmm_count=expr, x86_dep_rm8=256, x86_dep_rm16=257, x86_dep_rm32=258, x86_dep_ir8=512, x86_dep_ir16=513, x86_dep_ir32=514, x86_dep_r8=768, x86_dep_r16=769, x86_dep_r32=770, x86_dep_sreg=1024, x86_dep_mem8=1280, x86_dep_mem16=1281, x86_dep_mem32=1282, x86_dep_mem64=1283, x86_dep_mem80=1284, x86_dep_mem128=1285, x86_dep_easeg=1537, x86_dep_eabas=1538, x86_dep_eaidx=1539, x86_dep_sti=1792, x86_dep_xmmm32=2048, x86_dep_xmmm64=2049, x86_dep_xmmm128=2050, x86_dep_xmm=2304 } *idep; enum x86_dep_t { x86_dep_none=0, x86_dep_eax=1, x86_dep_ecx=2, x86_dep_edx=3, x86_dep_ebx=4, x86_dep_esp=5, x86_dep_ebp=6, x86_dep_esi=7, x86_dep_edi=8, x86_dep_es=9, x86_dep_cs=10, x86_dep_ss=11, x86_dep_ds=12, x86_dep_fs=13, x86_dep_gs=14, x86_dep_zps=15, x86_dep_of=16, x86_dep_cf=17, x86_dep_df=18, x86_dep_aux=19, x86_dep_aux2=20, x86_dep_ea=21, x86_dep_data=22, x86_dep_int_first=expr, x86_dep_int_last=expr, x86_dep_int_count=expr, x86_dep_flag_first=expr, x86_dep_flag_last=expr, x86_dep_flag_count=expr, x86_dep_st0=23, x86_dep_st1=24, x86_dep_st2=25, x86_dep_st3=26, x86_dep_st4=27, x86_dep_st5=28, x86_dep_st6=29, x86_dep_st7=30, x86_dep_fpst=31, x86_dep_fpcw=32, x86_dep_fpaux=33, x86_dep_fp_first=expr, x86_dep_fp_last=expr, x86_dep_fp_count=expr, x86_dep_fp_stack_first=expr, x86_dep_fp_stack_last=expr, x86_dep_fp_stack_count=expr, x86_dep_xmm0=34, x86_dep_xmm1=35, x86_dep_xmm2=36, x86_dep_xmm3=37, x86_dep_xmm4=38, x86_dep_xmm5=39, x86_dep_xmm6=40, x86_dep_xmm7=41, x86_dep_xmm_data=42, x86_dep_xmm_first=expr, x86_dep_xmm_last=expr, x86_dep_xmm_count=expr, x86_dep_rm8=256, x86_dep_rm16=257, x86_dep_rm32=258, x86_dep_ir8=512, x86_dep_ir16=513, x86_dep_ir32=514, x86_dep_r8=768, x86_dep_r16=769, x86_dep_r32=770, x86_dep_sreg=1024, x86_dep_mem8=1280, x86_dep_mem16=1281, x86_dep_mem32=1282, x86_dep_mem64=1283, x86_dep_mem80=1284, x86_dep_mem128=1285, x86_dep_easeg=1537, x86_dep_eabas=1538, x86_dep_eaidx=1539, x86_dep_sti=1792, x86_dep_xmmm32=2048, x86_dep_xmmm64=2049, x86_dep_xmmm128=2050, x86_dep_xmm=2304 } *odep; unsigned int address; int size; } *

user_defined_types: struct x86_uinst_t { enum x86_uinst_opcode_t opcode; enum x86_dep_t dep[-1]; enum x86_dep_t *idep; enum x86_dep_t *odep; unsigned int address; int size; }


decompiled_code:
__int64 __fastcall x86_uinst_free(__int64 a1)
{
return mhandle_free(a1, "uinst.c:546");
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return mhandle_free(a1, "uinst.c:546");
}

original_code:
void x86_uinst_free(struct x86_uinst_t *uinst)
{
 (mhandle_free(uinst, "uinst.c" ":" "546"));
}

user_defined_types: enum x86_uinst_opcode_t { x86_uinst_nop=0, x86_uinst_move=1, x86_uinst_add=2, x86_uinst_sub=3, x86_uinst_mult=4, x86_uinst_div=5, x86_uinst_effaddr=6, x86_uinst_and=7, x86_uinst_or=8, x86_uinst_xor=9, x86_uinst_not=10, x86_uinst_shift=11, x86_uinst_sign=12, x86_uinst_fp_move=13, x86_uinst_fp_sign=14, x86_uinst_fp_round=15, x86_uinst_fp_add=16, x86_uinst_fp_sub=17, x86_uinst_fp_comp=18, x86_uinst_fp_mult=19, x86_uinst_fp_div=20, x86_uinst_fp_exp=21, x86_uinst_fp_log=22, x86_uinst_fp_sin=23, x86_uinst_fp_cos=24, x86_uinst_fp_sincos=25, x86_uinst_fp_tan=26, x86_uinst_fp_atan=27, x86_uinst_fp_sqrt=28, x86_uinst_fp_push=29, x86_uinst_fp_pop=30, x86_uinst_xmm_and=31, x86_uinst_xmm_or=32, x86_uinst_xmm_xor=33, x86_uinst_xmm_not=34, x86_uinst_xmm_shift=35, x86_uinst_xmm_sign=36, x86_uinst_xmm_add=37, x86_uinst_xmm_sub=38, x86_uinst_xmm_comp=39, x86_uinst_xmm_mult=40, x86_uinst_xmm_div=41, x86_uinst_xmm_fp_add=42, x86_uinst_xmm_fp_sub=43, x86_uinst_xmm_fp_comp=44, x86_uinst_xmm_fp_mult=45, x86_uinst_xmm_fp_div=46, x86_uinst_xmm_fp_sqrt=47, x86_uinst_xmm_move=48, x86_uinst_xmm_shuf=49, x86_uinst_xmm_conv=50, x86_uinst_load=51, x86_uinst_store=52, x86_uinst_call=53, x86_uinst_ret=54, x86_uinst_jump=55, x86_uinst_branch=56, x86_uinst_ibranch=57, x86_uinst_syscall=58, x86_uinst_opcode_count=59 }


decompiled_code:
__int64 x86_uinst_clear()
{
__int64 v0; // rax
__int64 result; // rax

while ( 1 )
{
result = list_count(x86_uinst_list);
if ( !(_DWORD)result )
break;
v0 = list_remove_at(x86_uinst_list, 0LL);
x86_uinst_free(v0);
}
x86_uinst_effaddr_emitted = 0;
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rax
__int64 result; // rax

while ( 1 )
{
result = list_count(x86_uinst_list);
if ( !(_DWORD)result )
break;
v0 = list_remove_at(x86_uinst_list, 0LL);
func9(v0);
}
x86_uinst_effaddr_emitted = 0;
return result;
}

original_code:
void x86_uinst_clear(void)
{
 while (list_count(x86_uinst_list))
  x86_uinst_free(list_remove_at(x86_uinst_list, 0));
 x86_uinst_effaddr_emitted = 0;
}

canonical_original_code:
void x86_uinst_clear()
{
 while (list_count(x86_uinst_list))
  x86_uinst_free(list_remove_at(x86_uinst_list, 0));
 x86_uinst_effaddr_emitted = 0;
}


decompiled_code:
__int64 x86_uinst_done()
{
x86_uinst_clear();
return list_free(x86_uinst_list);
}

canonical_decompiled_code:
__int64 func13()
{
func12();
return list_free(x86_uinst_list);
}

original_code:
void x86_uinst_done(void)
{
 x86_uinst_clear();
 list_free(x86_uinst_list);
}

canonical_original_code:
void x86_uinst_done()
{
 x86_uinst_clear();
 list_free(x86_uinst_list);
}


original_code:
void x86_uinst_dump_buf(struct x86_uinst_t *uinst, char *buf, int size)
{
 char *comma;
 enum x86_dep_t dep;
 int dep_count;
 int i;
 str_printf(&buf, &size, "%s ", x86_uinst_info[uinst->opcode].name);
 comma = "";
 dep_count = 0;
 for (i = 0; i < 4; i++)
 {
  dep = uinst->odep[i];
  if (!dep)
   continue;
  dep_count++;
  str_printf(&buf, &size, "%s%s", comma, x86_uinst_dep_name_get(dep));
  comma = ",";
 }
 if (!dep_count)
  str_printf(&buf, &size, "-");
 str_printf(&buf, &size, "/");
 comma = "";
 dep_count = 0;
 for (i = 0; i < 3; i++)
 {
  dep = uinst->idep[i];
  if (!dep)
   continue;
  dep_count++;
  str_printf(&buf, &size, "%s%s", comma, x86_uinst_dep_name_get(dep));
  comma = ",";
 }
 if (!dep_count)
  str_printf(&buf, &size, "-");
 if (uinst->size)
  str_printf(&buf, &size, " [0x%x,%d]", uinst->address, uinst->size);
}

variable_types:
buf
char *

variable_types:
comma
char *


decompiled_code:
void __fastcall repos_free(void *a1)
{
repos_free_dump(a1, 0LL);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
func0(a1, 0LL);
}

original_code:
void repos_free(struct repos_t *repos)
{
 repos_free_dump(repos, ((void *)0));
}

variable_types: struct repos_t { char *name; int id; int object_size; void *alloc_head; void *dealloc_head; } *


original_code:
void *repos_create_object(struct repos_t *repos)
{
 void *obj, *next_obj;
 struct objtail_t *objtail, *next_objtail;
 if (!repos->dealloc_head)
 {
  obj = calloc(1, repos->object_size + sizeof(struct objtail_t));
  if (!obj)
   fatal("%s: out of memory", __FUNCTION__);
  objtail = obj + repos->object_size;
  objtail->id = repos->id;
  repos->dealloc_head = obj;
 }
 obj = repos->dealloc_head;
 objtail = obj + repos->object_size;
 ((void) sizeof ((!objtail->prev) ? 1 : 0), __extension__ ({ if (!objtail->prev) ; else __assert_fail ("!objtail->prev", "repos.c", 135, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!objtail->status) ? 1 : 0), __extension__ ({ if (!objtail->status) ; else __assert_fail ("!objtail->status", "repos.c", 136, __extension__ __PRETTY_FUNCTION__); }));
 next_obj = objtail->next;
 next_objtail = next_obj + repos->object_size;
 if (next_obj)
  next_objtail->prev = ((void *)0);
 repos->dealloc_head = next_obj;
 memset(obj, 0, repos->object_size);
 next_obj = repos->alloc_head;
 next_objtail = next_obj + repos->object_size;
 if (next_obj)
  next_objtail->prev = obj;
 objtail->next = next_obj;
 objtail->status = 1;
 repos->alloc_head = obj;
 return obj;
}

canonical_original_code:
void *repos_create_object(struct repos_t *repos)
{
 void *obj; void *next_obj;
 struct objtail_t *objtail; struct objtail_t *next_objtail;
 if (!repos->dealloc_head)
 {
  obj = calloc(1, repos->object_size + sizeof(struct objtail_t));
  if (!obj)
   fatal("%s: out of memory", __FUNCTION__);
  objtail = obj + repos->object_size;
  objtail->id = repos->id;
  repos->dealloc_head = obj;
 }
 obj = repos->dealloc_head;
 objtail = obj + repos->object_size;
 ((void) sizeof ((!objtail->prev) ? 1 : 0), __extension__ ({ if (!objtail->prev) ; else __assert_fail ("!objtail->prev", "repos.c", 135, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!objtail->status) ? 1 : 0), __extension__ ({ if (!objtail->status) ; else __assert_fail ("!objtail->status", "repos.c", 136, __extension__ __PRETTY_FUNCTION__); }));
 next_obj = objtail->next;
 next_objtail = next_obj + repos->object_size;
 if (next_obj)
  next_objtail->prev = ((void *)0);
 repos->dealloc_head = next_obj;
 memset(obj, 0, repos->object_size);
 next_obj = repos->alloc_head;
 next_objtail = next_obj + repos->object_size;
 if (next_obj)
  next_objtail->prev = obj;
 objtail->next = next_obj;
 objtail->status = 1;
 repos->alloc_head = obj;
 return obj;
}

variable_types:
obj
void *

variable_types: struct objtail_t { int id; int status; void *prev; void *next; } *

return_type: void *

user_defined_types: struct repos_t { char *name; int id; int object_size; void *alloc_head; void *dealloc_head; }


decompiled_code:
_BOOL8 __fastcall repos_allocated_object(__int64 a1, __int64 a2)
{
_DWORD *v2; // rsi
_BOOL8 result; // rax

if ( !a2 )
return 0LL;
v2 = (_DWORD *)(*(int *)(a1 + 12) + a2);
result = 0LL;
if ( *v2 == *(_DWORD *)(a1 + 8) )
result = v2[1] != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, __int64 a2)
{
_DWORD *v2; // rsi
_BOOL8 result; // rax

if ( !a2 )
return 0LL;
v2 = (_DWORD *)(*(int *)(a1 + 12) + a2);
result = 0LL;
if ( *v2 == *(_DWORD *)(a1 + 8) )
result = v2[1] != 0;
return result;
}

original_code:
int repos_allocated_object(struct repos_t *repos, void *obj)
{
 struct objtail_t *objtail;
 if (!obj)
  return 0;
 objtail = obj + repos->object_size;
 return objtail->id == repos->id && objtail->status;
}

return_type: int

user_defined_types: struct objtail_t { int id; int status; void *prev; void *next; }


decompiled_code:
void __fastcall repos_free_object(const char **a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rsi
__int64 v6; // rcx
const char *v7; // rdx
const char *v8; // rax

if ( a2 )
{
if ( !repos_allocated_object((__int64)a1, a2) )
panic("%s.repos_free_object: invalid object\n", *a1);
v3 = *((int *)a1 + 3);
v4 = a2 + v3;
v5 = a2 + v3;
if ( !*(_DWORD *)(a2 + v3 + 4) )
{
panic("%s.repos_free_object: object not allocated\n", *a1);
v3 = *((int *)a1 + 3);
v5 = a2 + v3;
}
v6 = *(_QWORD *)(v4 + 8);
v7 = *(const char **)(v4 + 16);
if ( v6 )
*(_QWORD *)(v6 + v3 + 16) = v7;
if ( v7 )
*(_QWORD *)&v7[v3 + 8] = v6;
if ( a1[2] == (const char *)a2 )
a1[2] = v7;
v8 = a1[3];
if ( v8 )
*(_QWORD *)(v5 + 8) = a2;
*(_QWORD *)(v4 + 8) = 0LL;
*(_QWORD *)(v4 + 16) = v8;
*(_DWORD *)(v4 + 4) = 0;
a1[3] = (const char *)a2;
}
}

original_code:
void repos_free_object(struct repos_t *repos, void *obj)
{
 struct objtail_t *objtail, *prev_objtail, *next_objtail;
 void *prev_obj, *next_obj;
 if (!obj)
  return;
 if (!repos_allocated_object(repos, obj))
  panic("%s.repos_free_object: invalid object\n",
   repos->name);
 objtail = obj + repos->object_size;
 if (!objtail->status)
  panic("%s.repos_free_object: object not allocated\n",
   repos->name);
 prev_obj = objtail->prev;
 prev_objtail = prev_obj + repos->object_size;
 next_obj = objtail->next;
 next_objtail = next_obj + repos->object_size;
 if (prev_obj)
  prev_objtail->next = next_obj;
 if (next_obj)
  next_objtail->prev = prev_obj;
 if (repos->alloc_head == obj)
  repos->alloc_head = next_obj;
 next_obj = repos->dealloc_head;
 next_objtail = obj + repos->object_size;
 if (next_obj)
  next_objtail->prev = obj;
 objtail->prev = ((void *)0);
 objtail->next = next_obj;
 objtail->status = 0;
 repos->dealloc_head = obj;
}

canonical_original_code:
void repos_free_object(struct repos_t *repos, void *obj)
{
 struct objtail_t *objtail; struct objtail_t *prev_objtail; struct objtail_t *next_objtail;
 void *prev_obj; void *next_obj;
 if (!obj)
  return;
 if (!repos_allocated_object(repos, obj))
  panic("%s.repos_free_object: invalid object\n",
   repos->name);
 objtail = obj + repos->object_size;
 if (!objtail->status)
  panic("%s.repos_free_object: object not allocated\n",
   repos->name);
 prev_obj = objtail->prev;
 prev_objtail = prev_obj + repos->object_size;
 next_obj = objtail->next;
 next_objtail = next_obj + repos->object_size;
 if (prev_obj)
  prev_objtail->next = next_obj;
 if (next_obj)
  next_objtail->prev = prev_obj;
 if (repos->alloc_head == obj)
  repos->alloc_head = next_obj;
 next_obj = repos->dealloc_head;
 next_objtail = obj + repos->object_size;
 if (next_obj)
  next_objtail->prev = obj;
 objtail->prev = ((void *)0);
 objtail->next = next_obj;
 objtail->status = 0;
 repos->dealloc_head = obj;
}


decompiled_code:
__int64 x86_opengl_missing()
{
return fatal(
"support for OpenGL not available.\n%s",
"\tMulti2Sim has been compiled without support for OpenGL applicationn.\n"
"\tThe OpenGL headers and OpenGL Utility Toolkit (GLUT) is required in\n"
"\tyour system to allow for simulation of guest OpenGL programs.\n"
"\t 1) Install the development packages for GLUT. Under Debian-based\n"
"\t Linux distributions, this package is listed as 'freeglut3-dev'.\n"
"\t 2) Re-run the './configure' script\n"
"\t 3) Recompile the simulator: make clean && make\n");
}

canonical_decompiled_code:
__int64 func0()
{
return fatal(
"support for OpenGL not available.\n%s",
"\tMulti2Sim has been compiled without support for OpenGL applicationn.\n"
"\tThe OpenGL headers and OpenGL Utility Toolkit (GLUT) is required in\n"
"\tyour system to allow for simulation of guest OpenGL programs.\n"
"\t 1) Install the development packages for GLUT. Under Debian-based\n"
"\t Linux distributions, this package is listed as 'freeglut3-dev'.\n"
"\t 2) Re-run the './configure' script\n"
"\t 3) Recompile the simulator: make clean && make\n");
}

original_code:
static void x86_opengl_missing(void)
{
 fatal("support for OpenGL not available.\n%s",
  x86_opengl_err_missing);
}

canonical_original_code:
static void x86_opengl_missing()
{
 fatal("support for OpenGL not available.\n%s",
  x86_opengl_err_missing);
}


decompiled_code:
void x86_opengl_init()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void x86_opengl_init(void)
{
}

canonical_original_code:
void x86_opengl_init()
{
}


decompiled_code:
void x86_opengl_done()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void x86_opengl_done(void)
{
}

canonical_original_code:
void x86_opengl_done()
{
}


decompiled_code:
__int64 __fastcall x86_cpu_issue_thread_lsq(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // eax

v3 = x86_cpu_issue_lq(a1, a2, a3);
return x86_cpu_issue_sq(a1, a2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // eax

v3 = func0(a1, a2, a3);
return func1(a1, a2, v3);
}

original_code:
static int x86_cpu_issue_thread_lsq(int core, int thread, int quant)
{
 quant = x86_cpu_issue_lq(core, thread, quant);
 quant = x86_cpu_issue_sq(core, thread, quant);
 return quant;
}

variable_types: core int

variable_types: thread int

variable_types: quant int


decompiled_code:
// attributes: thunk
__int64 __fastcall x86_cpu_issue_thread_iq(unsigned int a1, unsigned int a2, unsigned int a3)
{
return x86_cpu_issue_iq(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2, unsigned int a3)
{
return func3(a1, a2, a3);
}

original_code:
static int x86_cpu_issue_thread_iq(int core, int thread, int quant)
{
 quant = x86_cpu_issue_iq(core, thread, quant);
 return quant;
}


decompiled_code:
__int64 __fastcall x86_cpu_issue_core(signed int a1)
{
__int64 result; // rax
int v3; // er12
unsigned int v4; // er8
__int64 v5; // rbp
int j; // edi
__int64 v7; // rcx
int v8; // edx
unsigned int v9; // eax
int v10; // er12
unsigned int v11; // er8
int k; // edi
__int64 v13; // rcx
int v14; // edx
int v15; // er12
unsigned int v16; // er9
__int64 v17; // rbp
int v18; // edi
int v19; // eax
__int64 v20; // rcx
int v21; // edx
unsigned int v22; // eax
unsigned int v23; // er8
int v24; // er12
int i; // edi
__int64 v26; // rcx
int v27; // edx

if ( x86_cpu_issue_kind )
{
if ( x86_cpu_issue_kind == 1 )
{
v15 = x86_cpu_num_threads;
v16 = x86_cpu_issue_width;
v17 = 1824LL * a1;
v18 = x86_cpu_num_threads;
while ( 1 )
{
v20 = v17 + *x86_cpu;
v21 = (*(_DWORD *)(v20 + 104) + 1) % v18;
*(_DWORD *)(v20 + 104) = v21;
v22 = x86_cpu_issue_thread_lsq(a1, v21, v16);
v23 = x86_cpu_issue_width;
v16 = v22;
if ( !--v15 )
break;
v18 = x86_cpu_num_threads;
v19 = x86_cpu_num_threads;
if ( x86_cpu_issue_width != v16 )
goto LABEL_17;
}
v19 = x86_cpu_num_threads;
LABEL_17:
v24 = v19;
for ( i = v19; ; i = x86_cpu_num_threads )
{
v26 = v17 + *x86_cpu;
v27 = (*(_DWORD *)(v26 + 104) + 1) % i;
*(_DWORD *)(v26 + 104) = v27;
result = x86_cpu_issue_thread_iq(a1, v27, v23);
v23 = result;
if ( !--v24 || x86_cpu_issue_width != (_DWORD)result )
break;
}
}
else
{
result = panic("%s: invalid issue kind", "x86_cpu_issue_core");
}
}
else
{
v3 = x86_cpu_num_threads;
v4 = x86_cpu_issue_width;
v5 = 1824LL * a1;
for ( j = x86_cpu_num_threads; ; j = x86_cpu_num_threads )
{
v7 = v5 + *x86_cpu;
v8 = (*(_DWORD *)(v7 + 104) + 1) % j;
*(_DWORD *)(v7 + 104) = v8;
v9 = x86_cpu_issue_thread_lsq(a1, v8, v4);
v4 = v9;
if ( !--v3 || !v9 )
break;
}
v10 = x86_cpu_num_threads;
v11 = x86_cpu_issue_width;
for ( k = x86_cpu_num_threads; ; k = x86_cpu_num_threads )
{
v13 = v5 + *x86_cpu;
v14 = (*(_DWORD *)(v13 + 104) + 1) % k;
*(_DWORD *)(v13 + 104) = v14;
result = x86_cpu_issue_thread_iq(a1, v14, v11);
v11 = result;
if ( !--v10 || !(_DWORD)result )
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(signed int a1)
{
__int64 result; // rax
int v3; // er12
unsigned int v4; // er8
__int64 v5; // rbp
int j; // edi
__int64 v7; // rcx
int v8; // edx
unsigned int v9; // eax
int v10; // er12
unsigned int v11; // er8
int k; // edi
__int64 v13; // rcx
int v14; // edx
int v15; // er12
unsigned int v16; // er9
__int64 v17; // rbp
int v18; // edi
int v19; // eax
__int64 v20; // rcx
int v21; // edx
unsigned int v22; // eax
unsigned int v23; // er8
int v24; // er12
int i; // edi
__int64 v26; // rcx
int v27; // edx

if ( x86_cpu_issue_kind )
{
if ( x86_cpu_issue_kind == 1 )
{
v15 = x86_cpu_num_threads;
v16 = x86_cpu_issue_width;
v17 = 1824LL * a1;
v18 = x86_cpu_num_threads;
while ( 1 )
{
v20 = v17 + *x86_cpu;
v21 = (*(_DWORD *)(v20 + 104) + 1) % v18;
*(_DWORD *)(v20 + 104) = v21;
v22 = func2(a1, v21, v16);
v23 = x86_cpu_issue_width;
v16 = v22;
if ( !--v15 )
break;
v18 = x86_cpu_num_threads;
v19 = x86_cpu_num_threads;
if ( x86_cpu_issue_width != v16 )
goto LABEL_17;
}
v19 = x86_cpu_num_threads;
LABEL_17:
v24 = v19;
for ( i = v19; ; i = x86_cpu_num_threads )
{
v26 = v17 + *x86_cpu;
v27 = (*(_DWORD *)(v26 + 104) + 1) % i;
*(_DWORD *)(v26 + 104) = v27;
result = func4(a1, v27, v23);
v23 = result;
if ( !--v24 || x86_cpu_issue_width != (_DWORD)result )
break;
}
}
else
{
result = panic("%s: invalid issue kind", "x86_cpu_issue_core");
}
}
else
{
v3 = x86_cpu_num_threads;
v4 = x86_cpu_issue_width;
v5 = 1824LL * a1;
for ( j = x86_cpu_num_threads; ; j = x86_cpu_num_threads )
{
v7 = v5 + *x86_cpu;
v8 = (*(_DWORD *)(v7 + 104) + 1) % j;
*(_DWORD *)(v7 + 104) = v8;
v9 = func2(a1, v8, v4);
v4 = v9;
if ( !--v3 || !v9 )
break;
}
v10 = x86_cpu_num_threads;
v11 = x86_cpu_issue_width;
for ( k = x86_cpu_num_threads; ; k = x86_cpu_num_threads )
{
v13 = v5 + *x86_cpu;
v14 = (*(_DWORD *)(v13 + 104) + 1) % k;
*(_DWORD *)(v13 + 104) = v14;
result = func4(a1, v14, v11);
v11 = result;
if ( !--v10 || !(_DWORD)result )
break;
}
}
return result;
}

original_code:
static void x86_cpu_issue_core(int core)
{
 int skip, quant;
 switch (x86_cpu_issue_kind)
 {
 case x86_cpu_issue_kind_shared:
 {
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_lsq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant);
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_iq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant);
  break;
 }
 case x86_cpu_issue_kind_timeslice:
 {
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_lsq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant == x86_cpu_issue_width);
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_iq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant == x86_cpu_issue_width);
  break;
 }
 default:
  panic("%s: invalid issue kind", __FUNCTION__);
 }
}

canonical_original_code:
static void x86_cpu_issue_core(int core)
{
 int skip; int quant;
 switch (x86_cpu_issue_kind)
 {
 case x86_cpu_issue_kind_shared:
 {
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_lsq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant);
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_iq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant);
  break;
 }
 case x86_cpu_issue_kind_timeslice:
 {
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_lsq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant == x86_cpu_issue_width);
  quant = x86_cpu_issue_width;
  skip = x86_cpu_num_threads;
  do {
   (x86_cpu->core[core]).issue_current = ((x86_cpu->core[core]).issue_current + 1) % x86_cpu_num_threads;
   quant = x86_cpu_issue_thread_iq(core, (x86_cpu->core[core]).issue_current, quant);
   skip--;
  } while (skip && quant == x86_cpu_issue_width);
  break;
 }
 default:
  panic("%s: invalid issue kind", __FUNCTION__);
 }
}

variable_types: skip int


decompiled_code:
__int64 x86_cpu_issue()
{
__int64 result; // rax
int v1; // ebx
signed int v2; // edi

*(_QWORD *)(x86_cpu + 32LL) = "issue";
result = x86_cpu_num_cores;
if ( x86_cpu_num_cores > 0 )
{
v1 = 0;
do
{
v2 = v1++;
result = x86_cpu_issue_core(v2);
}
while ( x86_cpu_num_cores > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
int v1; // ebx
signed int v2; // edi

*(_QWORD *)(x86_cpu + 32LL) = "issue";
result = x86_cpu_num_cores;
if ( x86_cpu_num_cores > 0 )
{
v1 = 0;
do
{
v2 = v1++;
result = func5(v2);
}
while ( x86_cpu_num_cores > v1 );
}
return result;
}

original_code:
void x86_cpu_issue()
{
 int core;
 x86_cpu->stage = "issue";
 for (core = 0; core < x86_cpu_num_cores; core++)
  x86_cpu_issue_core(core);
}


fatal

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("fatal: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
fflush(0LL);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("fatal: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
fflush(0LL);
exit(1);
}

original_code:
void fatal(char *fmt, ...)
{
 va_list va;
 __builtin_va_start(va,fmt);
 fprintf(stderr, "fatal: ");
 vfprintf(stderr, fmt, va);
 fprintf(stderr, "\n");
 fflush(((void *)0));
 exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...)
{
 __builtin_va_list va;
 __builtin_va_start(va,fmt);
 fprintf(stderr, "fatal: ");
 vfprintf(stderr, fmt, va);
 fprintf(stderr, "\n");
 fflush(((void *)0));
 exit(1);
}

variable_types:
fmt
char *


panic

decompiled_code:
void __noreturn panic(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("panic: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
fflush(0LL);
abort();
}

canonical_decompiled_code:
void __noreturn func12(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("panic: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
fflush(0LL);
abort();
}

original_code:
void panic(char *fmt, ...)
{
 va_list va;
 __builtin_va_start(va,fmt);
 fprintf(stderr, "panic: ");
 vfprintf(stderr, fmt, va);
 fprintf(stderr, "\n");
 fflush(((void *)0));
 abort();
}

canonical_original_code:
void panic(char *fmt, ...)
{
 __builtin_va_list va;
 __builtin_va_start(va,fmt);
 fprintf(stderr, "panic: ");
 vfprintf(stderr, fmt, va);
 fprintf(stderr, "\n");
 fflush(((void *)0));
 abort();
}


warning

decompiled_code:
int warning(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func13(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

original_code:
void warning(char *fmt, ...)
{
 va_list va;
 __builtin_va_start(va,fmt);
 fprintf(stderr, "warning: ");
 vfprintf(stderr, fmt, va);
 fprintf(stderr, "\n");
}

canonical_original_code:
void warning(char *fmt, ...)
{
 __builtin_va_list va;
 __builtin_va_start(va,fmt);
 fprintf(stderr, "warning: ");
 vfprintf(stderr, fmt, va);
 fprintf(stderr, "\n");
}


decompiled_code:
__int64 __fastcall evg_opencl_kernel_arg_create(char *src)
{
size_t v1; // rax
__int64 v2; // r12

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 29, "opencl-kernel.c:93");
if ( !v2 )
fatal("%s: out of memory", "evg_opencl_kernel_arg_create");
strcpy((char *)(v2 + 28), src);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
size_t v1; // rax
__int64 v2; // r12

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 29, "opencl-kernel.c:93");
if ( !v2 )
fatal("%s: out of memory", "evg_opencl_kernel_arg_create");
strcpy((char *)(v2 + 28), src);
return v2;
}

original_code:
struct evg_opencl_kernel_arg_t *evg_opencl_kernel_arg_create(char *name)
{
 struct evg_opencl_kernel_arg_t *arg;
 arg = (mhandle_calloc(1, sizeof(struct evg_opencl_kernel_arg_t) + strlen(name) + 1, "opencl-kernel.c" ":" "93"));
 if (!arg)
  fatal("%s: out of memory", __FUNCTION__);
 strcpy(arg->name, name);
 return arg;
}

variable_types:
name
char *

variable_types: struct evg_opencl_kernel_arg_t { enum evg_opencl_kernel_arg_kind_t { EVG_OPENCL_KERNEL_ARG_KIND_VALUE=1, EVG_OPENCL_KERNEL_ARG_KIND_POINTER=2, EVG_OPENCL_KERNEL_ARG_KIND_IMAGE=3, EVG_OPENCL_KERNEL_ARG_KIND_SAMPLER=4 } kind; enum evg_opencl_mem_scope_t { EVG_OPENCL_MEM_SCOPE_NONE=0, EVG_OPENCL_MEM_SCOPE_GLOBAL=1, EVG_OPENCL_MEM_SCOPE_LOCAL=2, EVG_OPENCL_MEM_SCOPE_PRIVATE=3, EVG_OPENCL_MEM_SCOPE_CONSTANT=4 } mem_scope; int uav; enum evg_opencl_kernel_arg_access_type_t { EVG_OPENCL_KERNEL_ARG_READ_ONLY=1, EVG_OPENCL_KERNEL_ARG_WRITE_ONLY=2, EVG_OPENCL_KERNEL_ARG_READ_WRITE=3 } access_type; int set; unsigned int value; unsigned int size; char name[]; } *

user_defined_types: struct evg_opencl_kernel_arg_t { enum evg_opencl_kernel_arg_kind_t kind; enum evg_opencl_mem_scope_t mem_scope; int uav; enum evg_opencl_kernel_arg_access_type_t access_type; int set; unsigned int value; unsigned int size; char name[]; }


decompiled_code:
__int64 __fastcall evg_opencl_kernel_arg_free(__int64 a1)
{
return mhandle_free(a1, "opencl-kernel.c:107");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return mhandle_free(a1, "opencl-kernel.c:107");
}

original_code:
void evg_opencl_kernel_arg_free(struct evg_opencl_kernel_arg_t *arg)
{
 (mhandle_free(arg, "opencl-kernel.c" ":" "107"));
}

user_defined_types: enum evg_opencl_kernel_arg_kind_t { EVG_OPENCL_KERNEL_ARG_KIND_VALUE=1, EVG_OPENCL_KERNEL_ARG_KIND_POINTER=2, EVG_OPENCL_KERNEL_ARG_KIND_IMAGE=3, EVG_OPENCL_KERNEL_ARG_KIND_SAMPLER=4 }

user_defined_types: enum evg_opencl_mem_scope_t { EVG_OPENCL_MEM_SCOPE_NONE=0, EVG_OPENCL_MEM_SCOPE_GLOBAL=1, EVG_OPENCL_MEM_SCOPE_LOCAL=2, EVG_OPENCL_MEM_SCOPE_PRIVATE=3, EVG_OPENCL_MEM_SCOPE_CONSTANT=4 }

user_defined_types: enum evg_opencl_kernel_arg_access_type_t { EVG_OPENCL_KERNEL_ARG_READ_ONLY=1, EVG_OPENCL_KERNEL_ARG_WRITE_ONLY=2, EVG_OPENCL_KERNEL_ARG_READ_WRITE=3 }


decompiled_code:
__int64 __fastcall evg_calc_get_work_groups_per_compute_unit(int a1, int a2, int a3)
{
int v4; // er8
int v5; // ecx
int v6; // edx
int v7; // eax
int v8; // esi
int v9; // edi
__int64 result; // rax
int v11; // esi

if ( evg_emu_wavefront_size <= 0 )
_assert_fail("evg_emu_wavefront_size > 0", "calc.c", 0x2Cu, "evg_calc_get_work_groups_per_compute_unit");
v4 = (evg_emu_wavefront_size + a1 - 1) / evg_emu_wavefront_size;
v5 = evg_gpu_max_wavefronts_per_compute_unit / v4;
v6 = evg_gpu_register_alloc_size - 1;
v7 = -evg_gpu_register_alloc_size;
if ( evg_gpu_register_alloc_granularity == 1 )
v8 = v4 * (v7 & (a2 * evg_emu_wavefront_size + v6));
else
v8 = v7 & (a2 * a1 + v6);
v9 = evg_gpu_max_work_groups_per_compute_unit;
if ( v8 )
v9 = evg_gpu_num_registers / v8;
result = evg_gpu_max_work_groups_per_compute_unit;
v11 = -evg_gpu_local_mem_alloc_size & (evg_gpu_local_mem_alloc_size + a3 - 1);
if ( v11 )
result = (unsigned int)(evg_gpu_local_mem_size / v11);
if ( v5 > evg_gpu_max_work_groups_per_compute_unit )
v5 = evg_gpu_max_work_groups_per_compute_unit;
if ( v9 > v5 )
v9 = v5;
if ( (int)result > v9 )
result = (unsigned int)v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
int v4; // er8
int v5; // ecx
int v6; // edx
int v7; // eax
int v8; // esi
int v9; // edi
__int64 result; // rax
int v11; // esi

if ( evg_emu_wavefront_size <= 0 )
_assert_fail("evg_emu_wavefront_size > 0", "calc.c", 0x2Cu, "evg_calc_get_work_groups_per_compute_unit");
v4 = (evg_emu_wavefront_size + a1 - 1) / evg_emu_wavefront_size;
v5 = evg_gpu_max_wavefronts_per_compute_unit / v4;
v6 = evg_gpu_register_alloc_size - 1;
v7 = -evg_gpu_register_alloc_size;
if ( evg_gpu_register_alloc_granularity == 1 )
v8 = v4 * (v7 & (a2 * evg_emu_wavefront_size + v6));
else
v8 = v7 & (a2 * a1 + v6);
v9 = evg_gpu_max_work_groups_per_compute_unit;
if ( v8 )
v9 = evg_gpu_num_registers / v8;
result = evg_gpu_max_work_groups_per_compute_unit;
v11 = -evg_gpu_local_mem_alloc_size & (evg_gpu_local_mem_alloc_size + a3 - 1);
if ( v11 )
result = (unsigned int)(evg_gpu_local_mem_size / v11);
if ( v5 > evg_gpu_max_work_groups_per_compute_unit )
v5 = evg_gpu_max_work_groups_per_compute_unit;
if ( v9 > v5 )
v9 = v5;
if ( (int)result > v9 )
result = (unsigned int)v9;
return result;
}

original_code:
int evg_calc_get_work_groups_per_compute_unit(int work_items_per_work_group,
 int registers_per_work_item, int local_mem_per_work_group)
{
 int wavefronts_per_work_group;
 int registers_per_work_group;
 int max_work_groups_limitted_by_max_wavefronts;
 int max_work_groups_limitted_by_num_registers;
 int max_work_groups_limitted_by_local_mem;
 int work_groups_per_compute_unit;
 ((void) sizeof ((evg_emu_wavefront_size > 0) ? 1 : 0), __extension__ ({ if (evg_emu_wavefront_size > 0) ; else __assert_fail ("evg_emu_wavefront_size > 0", "calc.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 wavefronts_per_work_group = (work_items_per_work_group + evg_emu_wavefront_size - 1) /
  evg_emu_wavefront_size;
 max_work_groups_limitted_by_max_wavefronts = evg_gpu_max_wavefronts_per_compute_unit /
  wavefronts_per_work_group;
 if (evg_gpu_register_alloc_granularity == evg_gpu_register_alloc_wavefront)
  registers_per_work_group = (((registers_per_work_item * evg_emu_wavefront_size) + ((evg_gpu_register_alloc_size)-1)) & ~((evg_gpu_register_alloc_size)-1)) * wavefronts_per_work_group;
 else
  registers_per_work_group = (((registers_per_work_item * work_items_per_work_group) + ((evg_gpu_register_alloc_size)-1)) & ~((evg_gpu_register_alloc_size)-1));
 max_work_groups_limitted_by_num_registers = registers_per_work_group ?
  evg_gpu_num_registers / registers_per_work_group :
  evg_gpu_max_work_groups_per_compute_unit;
 local_mem_per_work_group = (((local_mem_per_work_group) + ((evg_gpu_local_mem_alloc_size)-1)) & ~((evg_gpu_local_mem_alloc_size)-1));
 max_work_groups_limitted_by_local_mem = local_mem_per_work_group ?
  evg_gpu_local_mem_size / local_mem_per_work_group :
  evg_gpu_max_work_groups_per_compute_unit;
 work_groups_per_compute_unit = evg_gpu_max_work_groups_per_compute_unit;
 work_groups_per_compute_unit = ((work_groups_per_compute_unit) < (max_work_groups_limitted_by_max_wavefronts) ? (work_groups_per_compute_unit) : (max_work_groups_limitted_by_max_wavefronts));
 work_groups_per_compute_unit = ((work_groups_per_compute_unit) < (max_work_groups_limitted_by_num_registers) ? (work_groups_per_compute_unit) : (max_work_groups_limitted_by_num_registers));
 work_groups_per_compute_unit = ((work_groups_per_compute_unit) < (max_work_groups_limitted_by_local_mem) ? (work_groups_per_compute_unit) : (max_work_groups_limitted_by_local_mem));
 return work_groups_per_compute_unit;
}


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

result = (int)evg_gpu_calc_file_name;
if ( *(_BYTE *)evg_gpu_calc_file_name )
{
if ( system("which gnuplot >/dev/null 2>&1") )
fatal(
"GPU occupancy calculation plots could not be generated.\n"
"\tThe tool 'gnuplot' is required to generate GPU occupancy plots. Please\n"
"\tmake sure that it is installed on your system and retry.\n");
evg_calc_plot_work_items_per_work_group();
evg_calc_plot_registers_per_work_item();
result = evg_calc_plot_local_mem_per_work_group();
}
return result;
}

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

result = (int)evg_gpu_calc_file_name;
if ( *(_BYTE *)evg_gpu_calc_file_name )
{
if ( system("which gnuplot >/dev/null 2>&1") )
fatal(
"GPU occupancy calculation plots could not be generated.\n"
"\tThe tool 'gnuplot' is required to generate GPU occupancy plots. Please\n"
"\tmake sure that it is installed on your system and retry.\n");
func1();
func2();
result = func3();
}
return result;
}

original_code:
void evg_calc_plot(void)
{
 int ret;
 if (!*evg_gpu_calc_file_name)
  return;
 ret = system("which gnuplot >/dev/null 2>&1");
 if (ret)
  fatal("GPU occupancy calculation plots could not be generated.\n"
   "\tThe tool 'gnuplot' is required to generate GPU occupancy plots. Please\n"
   "\tmake sure that it is installed on your system and retry.\n");
 evg_calc_plot_work_items_per_work_group();
 evg_calc_plot_registers_per_work_item();
 evg_calc_plot_local_mem_per_work_group();
}

canonical_original_code:
void evg_calc_plot()
{
 int ret;
 if (!*evg_gpu_calc_file_name)
  return;
 ret = system("which gnuplot >/dev/null 2>&1");
 if (ret)
  fatal("GPU occupancy calculation plots could not be generated.\n"
   "\tThe tool 'gnuplot' is required to generate GPU occupancy plots. Please\n"
   "\tmake sure that it is installed on your system and retry.\n");
 evg_calc_plot_work_items_per_work_group();
 evg_calc_plot_registers_per_work_item();
 evg_calc_plot_local_mem_per_work_group();
}

variable_types: ret int


decompiled_code:
__int64 si_opencl_program_create()
{
__int64 v0; // r12
int v1; // ebx
int v2; // eax
__int64 v3; // rax
__int64 i; // rdi

v0 = mhandle_calloc(1LL, 32LL, "opencl-program.c:35");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_program_create");
v1 = 25;
v2 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 5LL);
*(_DWORD *)(v0 + 4) = 1;
*(_DWORD *)v0 = v2;
v3 = list_create_with_size(25LL);
*(_QWORD *)(v0 + 24) = v3;
for ( i = v3; ; i = *(_QWORD *)(v0 + 24) )
{
list_add(i, 0LL);
if ( !--v1 )
break;
}
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r12
int v1; // ebx
int v2; // eax
__int64 v3; // rax
__int64 i; // rdi

v0 = mhandle_calloc(1LL, 32LL, "opencl-program.c:35");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_program_create");
v1 = 25;
v2 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 5LL);
*(_DWORD *)(v0 + 4) = 1;
*(_DWORD *)v0 = v2;
v3 = list_create_with_size(25LL);
*(_QWORD *)(v0 + 24) = v3;
for ( i = v3; ; i = *(_QWORD *)(v0 + 24) )
{
list_add(i, 0LL);
if ( !--v1 )
break;
}
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

original_code:
struct si_opencl_program_t *si_opencl_program_create()
{
 struct si_opencl_program_t *program;
 int i;
 program = (mhandle_calloc(1, sizeof(struct si_opencl_program_t), "opencl-program.c" ":" "35"));
 if (!program)
  fatal("%s: out of memory", __FUNCTION__);
 program->id = si_opencl_repo_new_object_id(si_emu->opencl_repo,
  si_opencl_object_program);
 program->ref_count = 1;
 program->constant_buffer_list = list_create_with_size(25);
 for(i = 0; i < 25; i++)
  list_add(program->constant_buffer_list, ((void *)0));
 si_opencl_repo_add_object(si_emu->opencl_repo, program);
 return program;
}

variable_types: struct si_opencl_program_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *elf_file; struct list_t *constant_buffer_list; } *

variable_types: i int

user_defined_types: struct si_opencl_program_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; struct elf_file_t *elf_file; struct list_t *constant_buffer_list; }

user_defined_types: struct elf_file_t { char *path; struct elf_buffer_t buffer; struct Elf32_Ehdr *header; struct list_t *section_list; struct elf_section_t *string_table; struct list_t *program_header_list; struct list_t *symbol_table; }

user_defined_types: struct elf_section_t { char *name; struct Elf32_Shdr *header; struct elf_buffer_t buffer; }


decompiled_code:
__int64 __fastcall si_opencl_program_free(__int64 a1)
{
list_free(*(_QWORD *)(a1 + 24));
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
si_opencl_repo_remove_object(*(_QWORD *)(si_emu + 8LL), a1);
return mhandle_free(a1, "opencl-program.c:63");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
list_free(*(_QWORD *)(a1 + 24));
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
si_opencl_repo_remove_object(*(_QWORD *)(si_emu + 8LL), a1);
return mhandle_free(a1, "opencl-program.c:63");
}

original_code:
void si_opencl_program_free(struct si_opencl_program_t *program)
{
 list_free(program->constant_buffer_list);
 if (program->elf_file)
  elf_file_free(program->elf_file);
 si_opencl_repo_remove_object(si_emu->opencl_repo, program);
 (mhandle_free(program, "opencl-program.c" ":" "63"));
}

user_defined_types: struct elf_buffer_t { void *ptr; int size; int pos; }

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct list_t { int count; int error_code; int size; int head; int tail; void **elem; }

user_defined_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; }


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

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
_assert_fail("program->elf_file", "opencl-program.c", 0x4Du, "si_opencl_program_build");
result = *(_QWORD *)(v1 + 24);
if ( *(_WORD *)(result + 18) != 1021 )
result = fatal(
"%s: invalid binary file.\n%s",
"si_opencl_program_build",
"\tYour application tried to load a pre-compiled OpenCL kernel binary which\n"
"\tdoes not contain code in the Southern Islands ISA. Please, check that the\n"
"\toff-line compilation of your kernel targets this GPU architecture supported\n"
"\tby Multi2Sim.\n");
return result;
}

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

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
_assert_fail("program->elf_file", "opencl-program.c", 0x4Du, "si_opencl_program_build");
result = *(_QWORD *)(v1 + 24);
if ( *(_WORD *)(result + 18) != 1021 )
result = fatal(
"%s: invalid binary file.\n%s",
"si_opencl_program_build",
"\tYour application tried to load a pre-compiled OpenCL kernel binary which\n"
"\tdoes not contain code in the Southern Islands ISA. Please, check that the\n"
"\toff-line compilation of your kernel targets this GPU architecture supported\n"
"\tby Multi2Sim.\n");
return result;
}

original_code:
void si_opencl_program_build(struct si_opencl_program_t *program)
{
 ((void) sizeof ((program->elf_file) ? 1 : 0), __extension__ ({ if (program->elf_file) ; else __assert_fail ("program->elf_file", "opencl-program.c", 77, __extension__ __PRETTY_FUNCTION__); }));
 if (program->elf_file->header->e_machine != 0x3fd)
  fatal("%s: invalid binary file.\n%s", __FUNCTION__,
    err_si_opencl_southern_islands_format);
}