decompiled_code:
__int64 __fastcall dir_entry_clear_all_sharers(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v4; // r12
__int64 result; // rax
int v7; // ecx
int v8; // edx
int v9; // edx
__int64 v10; // [rsp-10h] [rbp-38h]

v4 = a4;
result = dir_entry_get(a1, a2, a3, a4);
v7 = *((_DWORD *)a1 + 2);
*(_DWORD *)(result + 4) = 0;
v8 = v7 + 14;
if ( v7 + 7 >= 0 )
v8 = v7 + 7;
v9 = v8 >> 3;
if ( v7 > 0 )
result = (__int64)memset((void *)(result + 8), 0, (unsigned int)(v9 - 1) + 1LL);
if ( mem_trace_category )
{
_trace(mem_trace_category, 1LL, "mem.clear_all_sharers dir=\"%s\" x=%d y=%d z=%d\n", *a1, a2, a3, v4);
result = v10;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v4; // r12
__int64 result; // rax
int v7; // ecx
int v8; // edx
int v9; // edx
__int64 v10; // [rsp-10h] [rbp-38h]

v4 = a4;
result = func1(a1, a2, a3, a4);
v7 = *((_DWORD *)a1 + 2);
*(_DWORD *)(result + 4) = 0;
v8 = v7 + 14;
if ( v7 + 7 >= 0 )
v8 = v7 + 7;
v9 = v8 >> 3;
if ( v7 > 0 )
result = (__int64)memset((void *)(result + 8), 0, (unsigned int)(v9 - 1) + 1LL);
if ( mem_trace_category )
{
_trace(mem_trace_category, 1LL, "mem.clear_all_sharers dir=\"%s\" x=%d y=%d z=%d\n", *a1, a2, a3, v4);
result = v10;
}
return result;
}

original_code:
void dir_entry_clear_all_sharers(struct dir_t *dir, int x, int y, int z)
{
 struct dir_entry_t *dir_entry;
 int i;
 dir_entry = dir_entry_get(dir, x, y, z);
 dir_entry->num_sharers = 0;
 for (i = 0; i < ((dir->num_nodes + 7) / 8); i++)
  dir_entry->sharer[i] = 0;
 ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.clear_all_sharers dir=\"%s\" x=%d y=%d z=%d\n", dir->name, x, y, z) : (void) 0);
}

variable_types: i int

user_defined_types: struct dir_entry_t { int owner; int num_sharers; unsigned char sharer[]; }

user_defined_types: enum mod_access_kind_t { mod_access_invalid=0, mod_access_load=1, mod_access_store=2, mod_access_nc_store=3 }

user_defined_types: enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 }

user_defined_types: enum mod_message_type_t { message_none=0, message_clear_owner=1 }

user_defined_types: enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 }

user_defined_types: enum mod_kind_t { mod_kind_invalid=0, mod_kind_cache=1, mod_kind_main_memory=2, mod_kind_local_memory=3 }

user_defined_types: enum mod_range_kind_t { mod_range_invalid=0, mod_range_bounds=1, mod_range_interleaved=2 }

user_defined_types: struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; }

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 cache_set_t { struct cache_block_t *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; }

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 cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t state; }


decompiled_code:
_BOOL8 __fastcall dir_entry_is_sharer(_DWORD *a1, int a2, int a3, int a4, int a5)
{
if ( a5 < 0 || a1[2] <= a5 )
_assert_fail("IN_RANGE(node, 0, dir->num_nodes - 1)", "directory.c", 0xC3u, "dir_entry_is_sharer");
return ((1 << (a5 & 7)) & *(unsigned __int8 *)((a5 >> 3) + dir_entry_get(a1, a2, a3, a4) + 8)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1, int a2, int a3, int a4, int a5)
{
if ( a5 < 0 || a1[2] <= a5 )
_assert_fail("IN_RANGE(node, 0, dir->num_nodes - 1)", "directory.c", 0xC3u, "dir_entry_is_sharer");
return ((1 << (a5 & 7)) & *(unsigned __int8 *)((a5 >> 3) + func1(a1, a2, a3, a4) + 8)) != 0;
}

original_code:
int dir_entry_is_sharer(struct dir_t *dir, int x, int y, int z, int node)
{
 struct dir_entry_t *dir_entry;
 ((void) sizeof ((((node)>=(0)&&(node)<=(dir->num_nodes - 1))) ? 1 : 0), __extension__ ({ if (((node)>=(0)&&(node)<=(dir->num_nodes - 1))) ; else __assert_fail ("IN_RANGE(node, 0, dir->num_nodes - 1)", "directory.c", 195, __extension__ __PRETTY_FUNCTION__); }));
 dir_entry = dir_entry_get(dir, x, y, z);
 return (dir_entry->sharer[node / 8] & (1 << (node % 8))) > 0;
}

variable_types: struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t { long long id; enum mod_access_kind_t { mod_access_invalid=0, mod_access_load=1, mod_access_store=2, mod_access_nc_store=3 } access_kind; int *witness_ptr; 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; } *event_queue; void *event_queue_item; struct mod_t { enum mod_kind_t { mod_kind_invalid=0, mod_kind_cache=1, mod_kind_main_memory=2, mod_kind_local_memory=3 } kind; char *name; int block_size; int log_block_size; int latency; int dir_latency; int mshr_size; int level; enum mod_range_kind_t { mod_range_invalid=0, mod_range_bounds=1, mod_range_interleaved=2 } range_kind; union { struct { unsigned int low; unsigned int high; } bounds; struct { unsigned int mod; unsigned int div; unsigned int eq; } interleaved; } range; struct mod_port_t { int locked; long long lock_when; struct mod_stack_t *stack; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; } *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 } policy; struct cache_set_t { struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; } *sets; unsigned int block_mask; int log_block_size; } *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; 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 *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; } *high_net; struct net_t *low_net; struct net_node_t *high_net_node; struct net_node_t *low_net_node; struct mod_stack_t *access_list_head; struct mod_stack_t *access_list_tail; int access_list_count; int access_list_max; struct mod_stack_t *write_access_list_head; struct mod_stack_t *write_access_list_tail; int write_access_list_count; int write_access_list_max; int access_list_coalesced_count; struct { struct mod_stack_t *bucket_list_head; struct mod_stack_t *bucket_list_tail; int bucket_list_count; int bucket_list_max; } access_hash_table[17]; int color; long long accesses; long long hits; long long reads; long long effective_reads; long long effective_read_hits; long long writes; long long effective_writes; long long effective_write_hits; long long nc_writes; long long effective_nc_writes; long long effective_nc_write_hits; long long evictions; long long blocking_reads; long long non_blocking_reads; long long read_hits; long long blocking_writes; long long non_blocking_writes; long long write_hits; long long blocking_nc_writes; long long non_blocking_nc_writes; long long nc_write_hits; long long read_retries; long long write_retries; long long nc_write_retries; long long no_retry_accesses; long long no_retry_hits; long long no_retry_reads; long long no_retry_read_hits; long long no_retry_writes; long long no_retry_write_hits; long long no_retry_nc_writes; long long no_retry_nc_write_hits; } *mod; struct mod_t *target_mod; struct mod_t *except_mod; struct mod_t *peer; struct mod_port_t *port; unsigned int addr; int tag; int set; int way; int state; int src_set; int src_way; int src_tag; enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 } request_dir; enum mod_message_type_t { message_none=0, message_clear_owner=1 } message; enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 } reply; int reply_size; int retain_owner; int pending; struct mod_stack_t *access_list_prev; struct mod_stack_t *access_list_next; struct mod_stack_t *write_access_list_prev; struct mod_stack_t *write_access_list_next; struct mod_stack_t *bucket_list_prev; struct mod_stack_t *bucket_list_next; int hit; int err; int shared; int read; int write; int nc_write; int blocking; int writeback; int eviction; int retry; int coalesced; int port_locked; struct net_msg_t *msg; int waiting_list_event; struct mod_stack_t *waiting_list_prev; struct mod_stack_t *waiting_list_next; int port_waiting_list_event; struct mod_stack_t *port_waiting_list_prev; struct mod_stack_t *port_waiting_list_next; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct mod_stack_t *master_stack; int dir_lock_event; struct mod_stack_t *dir_lock_next; struct mod_stack_t *ret_stack; int ret_event; } *lock_queue; } *dir_lock; unsigned char data[]; } *

variable_types: x int

variable_types: y int

variable_types: z int

variable_types: node int

variable_types: struct dir_entry_t { int owner; int num_sharers; unsigned char sharer[]; } *

return_type: int

user_defined_types: struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t *dir_lock; unsigned char data[]; }

user_defined_types: struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t *lock_queue; }

user_defined_types: struct mod_stack_t { long long id; enum mod_access_kind_t access_kind; int *witness_ptr; struct linked_list_t *event_queue; void *event_queue_item; struct mod_t *mod; struct mod_t *target_mod; struct mod_t *except_mod; struct mod_t *peer; struct mod_port_t *port; unsigned int addr; int tag; int set; int way; int state; int src_set; int src_way; int src_tag; enum mod_request_dir_t request_dir; enum mod_message_type_t message; enum mod_reply_type_t reply; int reply_size; int retain_owner; int pending; struct mod_stack_t *access_list_prev; struct mod_stack_t *access_list_next; struct mod_stack_t *write_access_list_prev; struct mod_stack_t *write_access_list_next; struct mod_stack_t *bucket_list_prev; struct mod_stack_t *bucket_list_next; int hit; int err; int shared; int read; int write; int nc_write; int blocking; int writeback; int eviction; int retry; int coalesced; int port_locked; struct net_msg_t *msg; int waiting_list_event; struct mod_stack_t *waiting_list_prev; struct mod_stack_t *waiting_list_next; int port_waiting_list_event; struct mod_stack_t *port_waiting_list_prev; struct mod_stack_t *port_waiting_list_next; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct mod_stack_t *master_stack; int dir_lock_event; struct mod_stack_t *dir_lock_next; struct mod_stack_t *ret_stack; int ret_event; }

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 mod_t { enum mod_kind_t kind; char *name; int block_size; int log_block_size; int latency; int dir_latency; int mshr_size; int level; enum mod_range_kind_t range_kind; union { struct { unsigned int low; unsigned int high; } bounds; struct { unsigned int mod; unsigned int div; unsigned int eq; } interleaved; } range; struct mod_port_t *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; struct net_t *high_net; struct net_t *low_net; struct net_node_t *high_net_node; struct net_node_t *low_net_node; struct mod_stack_t *access_list_head; struct mod_stack_t *access_list_tail; int access_list_count; int access_list_max; struct mod_stack_t *write_access_list_head; struct mod_stack_t *write_access_list_tail; int write_access_list_count; int write_access_list_max; int access_list_coalesced_count; struct { struct mod_stack_t *bucket_list_head; struct mod_stack_t *bucket_list_tail; int bucket_list_count; int bucket_list_max; } access_hash_table[17]; int color; long long accesses; long long hits; long long reads; long long effective_reads; long long effective_read_hits; long long writes; long long effective_writes; long long effective_write_hits; long long nc_writes; long long effective_nc_writes; long long effective_nc_write_hits; long long evictions; long long blocking_reads; long long non_blocking_reads; long long read_hits; long long blocking_writes; long long non_blocking_writes; long long write_hits; long long blocking_nc_writes; long long non_blocking_nc_writes; long long nc_write_hits; long long read_retries; long long write_retries; long long nc_write_retries; long long no_retry_accesses; long long no_retry_hits; long long no_retry_reads; long long no_retry_read_hits; long long no_retry_writes; long long no_retry_write_hits; long long no_retry_nc_writes; long long no_retry_nc_write_hits; }

user_defined_types: struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t policy; struct cache_set_t *sets; unsigned int block_mask; int log_block_size; }

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; }

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; }


decompiled_code:
__int64 __fastcall dir_entry_dump_sharers(_DWORD *a1, int a2, int a3, int a4)
{
__int64 v6; // rax
unsigned int v7; // er15
__int64 result; // rax
int v9; // ebx

v6 = dir_entry_get(a1, a2, a3, a4);
v7 = mem_debug_category;
if ( !mem_debug_category )
{
result = (unsigned int)a1[2];
if ( (int)result <= 0 )
return result;
goto LABEL_3;
}
result = _debug(mem_debug_category, " %d sharers: { ", *(unsigned int *)(v6 + 4));
v7 = mem_debug_category;
if ( (int)a1[2] > 0 )
{
LABEL_3:
v9 = 0;
do
{
while ( 1 )
{
result = dir_entry_is_sharer(a1, a2, a3, a4, v9);
if ( (_DWORD)result )
{
if ( v7 )
break;
}
if ( a1[2] <= ++v9 )
goto LABEL_8;
}
result = _debug(v7, "%d ", (unsigned int)v9++);
v7 = mem_debug_category;
}
while ( a1[2] > v9 );
}
LABEL_8:
if ( v7 )
result = _debug(v7, "}\n");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, int a2, int a3, int a4)
{
__int64 v6; // rax
unsigned int v7; // er15
__int64 result; // rax
int v9; // ebx

v6 = func1(a1, a2, a3, a4);
v7 = mem_debug_category;
if ( !mem_debug_category )
{
result = (unsigned int)a1[2];
if ( (int)result <= 0 )
return result;
goto LABEL_3;
}
result = _debug(mem_debug_category, " %d sharers: { ", *(unsigned int *)(v6 + 4));
v7 = mem_debug_category;
if ( (int)a1[2] > 0 )
{
LABEL_3:
v9 = 0;
do
{
while ( 1 )
{
result = func6(a1, a2, a3, a4, v9);
if ( (_DWORD)result )
{
if ( v7 )
break;
}
if ( a1[2] <= ++v9 )
goto LABEL_8;
}
result = _debug(v7, "%d ", (unsigned int)v9++);
v7 = mem_debug_category;
}
while ( a1[2] > v9 );
}
LABEL_8:
if ( v7 )
result = _debug(v7, "}\n");
return result;
}

original_code:
void dir_entry_dump_sharers(struct dir_t *dir, int x, int y, int z)
{
 struct dir_entry_t *dir_entry;
 int i;
 dir_entry = dir_entry_get(dir, x, y, z);
 ((mem_debug_category) ? __debug((mem_debug_category), "  %d sharers: { ", dir_entry->num_sharers) : (void) 0);
 for (i = 0; i < dir->num_nodes; i++)
  if (dir_entry_is_sharer(dir, x, y, z, i))
   ((mem_debug_category) ? __debug((mem_debug_category), "%d ", i) : (void) 0);
 ((mem_debug_category) ? __debug((mem_debug_category), "}\n") : (void) 0);
}

return_type: void

user_defined_types: struct dir_entry_t { int owner; int num_sharers; unsigned char sharer[]; }

user_defined_types: enum mod_access_kind_t { mod_access_invalid=0, mod_access_load=1, mod_access_store=2, mod_access_nc_store=3 }

user_defined_types: enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 }

user_defined_types: enum mod_message_type_t { message_none=0, message_clear_owner=1 }

user_defined_types: enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 }

user_defined_types: struct mod_port_t { int locked; long long lock_when; struct mod_stack_t *stack; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; }

user_defined_types: enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 }

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

user_defined_types: 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; }

user_defined_types: enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 }

user_defined_types: enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 }

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; }


original_code:
int dir_entry_group_shared_or_owned(struct dir_t *dir, int x, int y)
{
 struct dir_entry_t *dir_entry;
 int z;
 for (z = 0; z < dir->zsize; z++)
 {
  dir_entry = ((struct dir_entry_t *) (((void *) &dir->data) + (sizeof(struct dir_entry_t) + ((dir->num_nodes + 7) / 8)) * ((x) * dir->ysize * dir->zsize + (y) * dir->zsize + (z))));
  if (dir_entry->num_sharers || ((dir_entry)->owner >= 0))
   return 1;
 }
 return 0;
}

user_defined_types: struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t *dir_lock; unsigned char data[]; }

user_defined_types: struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t *lock_queue; }

user_defined_types: struct mod_stack_t { long long id; enum mod_access_kind_t access_kind; int *witness_ptr; struct linked_list_t *event_queue; void *event_queue_item; struct mod_t *mod; struct mod_t *target_mod; struct mod_t *except_mod; struct mod_t *peer; struct mod_port_t *port; unsigned int addr; int tag; int set; int way; int state; int src_set; int src_way; int src_tag; enum mod_request_dir_t request_dir; enum mod_message_type_t message; enum mod_reply_type_t reply; int reply_size; int retain_owner; int pending; struct mod_stack_t *access_list_prev; struct mod_stack_t *access_list_next; struct mod_stack_t *write_access_list_prev; struct mod_stack_t *write_access_list_next; struct mod_stack_t *bucket_list_prev; struct mod_stack_t *bucket_list_next; int hit; int err; int shared; int read; int write; int nc_write; int blocking; int writeback; int eviction; int retry; int coalesced; int port_locked; struct net_msg_t *msg; int waiting_list_event; struct mod_stack_t *waiting_list_prev; struct mod_stack_t *waiting_list_next; int port_waiting_list_event; struct mod_stack_t *port_waiting_list_prev; struct mod_stack_t *port_waiting_list_next; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct mod_stack_t *master_stack; int dir_lock_event; struct mod_stack_t *dir_lock_next; struct mod_stack_t *ret_stack; int ret_event; }

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 mod_t { enum mod_kind_t kind; char *name; int block_size; int log_block_size; int latency; int dir_latency; int mshr_size; int level; enum mod_range_kind_t range_kind; union { struct { unsigned int low; unsigned int high; } bounds; struct { unsigned int mod; unsigned int div; unsigned int eq; } interleaved; } range; struct mod_port_t *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; struct net_t *high_net; struct net_t *low_net; struct net_node_t *high_net_node; struct net_node_t *low_net_node; struct mod_stack_t *access_list_head; struct mod_stack_t *access_list_tail; int access_list_count; int access_list_max; struct mod_stack_t *write_access_list_head; struct mod_stack_t *write_access_list_tail; int write_access_list_count; int write_access_list_max; int access_list_coalesced_count; struct { struct mod_stack_t *bucket_list_head; struct mod_stack_t *bucket_list_tail; int bucket_list_count; int bucket_list_max; } access_hash_table[17]; int color; long long accesses; long long hits; long long reads; long long effective_reads; long long effective_read_hits; long long writes; long long effective_writes; long long effective_write_hits; long long nc_writes; long long effective_nc_writes; long long effective_nc_write_hits; long long evictions; long long blocking_reads; long long non_blocking_reads; long long read_hits; long long blocking_writes; long long non_blocking_writes; long long write_hits; long long blocking_nc_writes; long long non_blocking_nc_writes; long long nc_write_hits; long long read_retries; long long write_retries; long long nc_write_retries; long long no_retry_accesses; long long no_retry_hits; long long no_retry_reads; long long no_retry_read_hits; long long no_retry_writes; long long no_retry_write_hits; long long no_retry_nc_writes; long long no_retry_nc_write_hits; }

user_defined_types: enum mod_kind_t { mod_kind_invalid=0, mod_kind_cache=1, mod_kind_main_memory=2, mod_kind_local_memory=3 }

user_defined_types: enum mod_range_kind_t { mod_range_invalid=0, mod_range_bounds=1, mod_range_interleaved=2 }

user_defined_types: struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; }

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 cache_set_t { struct cache_block_t *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; }

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 cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t state; }


decompiled_code:
__int64 __fastcall dir_lock_get(__int64 a1, int a2, int a3)
{
int v4; // edx
int v5; // edx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // r12

if ( *(_DWORD *)(a1 + 12) <= a2 || (v4 = *(_DWORD *)(a1 + 16), v4 <= a3) )
_assert_fail("x < dir->xsize && y < dir->ysize", "directory.c", 0xDAu, "dir_lock_get");
v5 = a3 + a2 * v4;
v6 = *(_QWORD *)(a1 + 24);
v7 = 3LL * v5;
v8 = v6 + 8 * v7;
if ( !mem_debug_category )
return v6 + 8 * v7;
_debug(mem_debug_category, " %lld dir_lock retrieve\n", esim_cycle);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // edx
int v5; // edx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // r12

if ( *(_DWORD *)(a1 + 12) <= a2 || (v4 = *(_DWORD *)(a1 + 16), v4 <= a3) )
_assert_fail("x < dir->xsize && y < dir->ysize", "directory.c", 0xDAu, "dir_lock_get");
v5 = a3 + a2 * v4;
v6 = *(_QWORD *)(a1 + 24);
v7 = 3LL * v5;
v8 = v6 + 8 * v7;
if ( !mem_debug_category )
return v6 + 8 * v7;
_debug(mem_debug_category, " %lld dir_lock retrieve\n", esim_cycle);
return v8;
}

original_code:
struct dir_lock_t *dir_lock_get(struct dir_t *dir, int x, int y)
{
 struct dir_lock_t *dir_lock;
 ((void) sizeof ((x < dir->xsize && y < dir->ysize) ? 1 : 0), __extension__ ({ if (x < dir->xsize && y < dir->ysize) ; else __assert_fail ("x < dir->xsize && y < dir->ysize", "directory.c", 218, __extension__ __PRETTY_FUNCTION__); }));
 dir_lock = &dir->dir_lock[x * dir->ysize + y];
 ((mem_debug_category) ? __debug((mem_debug_category), "  %lld dir_lock retrieve\n", esim_cycle) : (void) 0);
 return dir_lock;
}

variable_types:
dir
struct dir_t *

variable_types: struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t { long long id; enum mod_access_kind_t { mod_access_invalid=0, mod_access_load=1, mod_access_store=2, mod_access_nc_store=3 } access_kind; int *witness_ptr; 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; } *event_queue; void *event_queue_item; struct mod_t { enum mod_kind_t { mod_kind_invalid=0, mod_kind_cache=1, mod_kind_main_memory=2, mod_kind_local_memory=3 } kind; char *name; int block_size; int log_block_size; int latency; int dir_latency; int mshr_size; int level; enum mod_range_kind_t { mod_range_invalid=0, mod_range_bounds=1, mod_range_interleaved=2 } range_kind; union { struct { unsigned int low; unsigned int high; } bounds; struct { unsigned int mod; unsigned int div; unsigned int eq; } interleaved; } range; struct mod_port_t { int locked; long long lock_when; struct mod_stack_t *stack; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; } *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t *dir_lock; unsigned char data[]; } *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 } policy; struct cache_set_t { struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; } *sets; unsigned int block_mask; int log_block_size; } *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; 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 *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; } *high_net; struct net_t *low_net; struct net_node_t *high_net_node; struct net_node_t *low_net_node; struct mod_stack_t *access_list_head; struct mod_stack_t *access_list_tail; int access_list_count; int access_list_max; struct mod_stack_t *write_access_list_head; struct mod_stack_t *write_access_list_tail; int write_access_list_count; int write_access_list_max; int access_list_coalesced_count; struct { struct mod_stack_t *bucket_list_head; struct mod_stack_t *bucket_list_tail; int bucket_list_count; int bucket_list_max; } access_hash_table[17]; int color; long long accesses; long long hits; long long reads; long long effective_reads; long long effective_read_hits; long long writes; long long effective_writes; long long effective_write_hits; long long nc_writes; long long effective_nc_writes; long long effective_nc_write_hits; long long evictions; long long blocking_reads; long long non_blocking_reads; long long read_hits; long long blocking_writes; long long non_blocking_writes; long long write_hits; long long blocking_nc_writes; long long non_blocking_nc_writes; long long nc_write_hits; long long read_retries; long long write_retries; long long nc_write_retries; long long no_retry_accesses; long long no_retry_hits; long long no_retry_reads; long long no_retry_read_hits; long long no_retry_writes; long long no_retry_write_hits; long long no_retry_nc_writes; long long no_retry_nc_write_hits; } *mod; struct mod_t *target_mod; struct mod_t *except_mod; struct mod_t *peer; struct mod_port_t *port; unsigned int addr; int tag; int set; int way; int state; int src_set; int src_way; int src_tag; enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 } request_dir; enum mod_message_type_t { message_none=0, message_clear_owner=1 } message; enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 } reply; int reply_size; int retain_owner; int pending; struct mod_stack_t *access_list_prev; struct mod_stack_t *access_list_next; struct mod_stack_t *write_access_list_prev; struct mod_stack_t *write_access_list_next; struct mod_stack_t *bucket_list_prev; struct mod_stack_t *bucket_list_next; int hit; int err; int shared; int read; int write; int nc_write; int blocking; int writeback; int eviction; int retry; int coalesced; int port_locked; struct net_msg_t *msg; int waiting_list_event; struct mod_stack_t *waiting_list_prev; struct mod_stack_t *waiting_list_next; int port_waiting_list_event; struct mod_stack_t *port_waiting_list_prev; struct mod_stack_t *port_waiting_list_next; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct mod_stack_t *master_stack; int dir_lock_event; struct mod_stack_t *dir_lock_next; struct mod_stack_t *ret_stack; int ret_event; } *lock_queue; } *

user_defined_types: struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t policy; struct cache_set_t *sets; unsigned int block_mask; int log_block_size; }

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; }

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; }


decompiled_code:
__int64 __fastcall dir_entry_lock(__int64 a1, unsigned int a2, __int64 a3, int a4, __int64 *a5)
{
int v5; // eax
__int64 v7; // rbp
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rax
int v11; // edx
_QWORD *v12; // rax
__int64 v13; // rdx
_QWORD *v14; // rsi

if ( *(_DWORD *)(a1 + 12) <= (signed int)a2 || (v5 = *(_DWORD *)(a1 + 16), v5 <= (int)a3) )
_assert_fail("x < dir->xsize && y < dir->ysize", "directory.c", 0xE7u, "dir_entry_lock");
v7 = *(_QWORD *)(a1 + 24) + 24LL * (int)(a3 + a2 * v5);
if ( *(_DWORD *)v7 )
{
v10 = a5[37];
v11 = *((_DWORD *)a5 + 23);
a5[36] = 0LL;
*((_DWORD *)a5 + 70) = a4;
*(_DWORD *)(v10 + 92) = v11;
v12 = *(_QWORD **)(v7 + 16);
if ( v12 )
{
while ( 1 )
{
v13 = *v12;
v14 = v12;
v12 = (_QWORD *)v12[36];
if ( *a5 <= v13 )
break;
if ( !v12 )
goto LABEL_14;
}
if ( v12 )
a5[36] = (__int64)v12;
LABEL_14:
v14[36] = a5;
}
else
{
*(_QWORD *)(v7 + 16) = a5;
}
result = mem_debug_category;
if ( mem_debug_category )
{
_debug(mem_debug_category, " 0x%x access suspended\n", *((unsigned int *)a5 + 21));
result = 0LL;
}
}
else
{
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.new_access_block cache=\"%s\" access=\"A-%lld\" set=%d way=%d\n",
*(const char **)a1,
*a5,
a2,
a3);
v8 = *a5;
*(_DWORD *)v7 = 1;
*(_QWORD *)(v7 + 8) = v8;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2, __int64 a3, int a4, __int64 *a5)
{
int v5; // eax
__int64 v7; // rbp
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rax
int v11; // edx
_QWORD *v12; // rax
__int64 v13; // rdx
_QWORD *v14; // rsi

if ( *(_DWORD *)(a1 + 12) <= (signed int)a2 || (v5 = *(_DWORD *)(a1 + 16), v5 <= (int)a3) )
_assert_fail("x < dir->xsize && y < dir->ysize", "directory.c", 0xE7u, "dir_entry_lock");
v7 = *(_QWORD *)(a1 + 24) + 24LL * (int)(a3 + a2 * v5);
if ( *(_DWORD *)v7 )
{
v10 = a5[37];
v11 = *((_DWORD *)a5 + 23);
a5[36] = 0LL;
*((_DWORD *)a5 + 70) = a4;
*(_DWORD *)(v10 + 92) = v11;
v12 = *(_QWORD **)(v7 + 16);
if ( v12 )
{
while ( 1 )
{
v13 = *v12;
v14 = v12;
v12 = (_QWORD *)v12[36];
if ( *a5 <= v13 )
break;
if ( !v12 )
goto LABEL_14;
}
if ( v12 )
a5[36] = (__int64)v12;
LABEL_14:
v14[36] = a5;
}
else
{
*(_QWORD *)(v7 + 16) = a5;
}
result = mem_debug_category;
if ( mem_debug_category )
{
_debug(mem_debug_category, " 0x%x access suspended\n", *((unsigned int *)a5 + 21));
result = 0LL;
}
}
else
{
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.new_access_block cache=\"%s\" access=\"A-%lld\" set=%d way=%d\n",
*(const char **)a1,
*a5,
a2,
a3);
v8 = *a5;
*(_DWORD *)v7 = 1;
*(_QWORD *)(v7 + 8) = v8;
result = 1LL;
}
return result;
}

original_code:
int dir_entry_lock(struct dir_t *dir, int x, int y, int event, struct mod_stack_t *stack)
{
 struct dir_lock_t *dir_lock;
 struct mod_stack_t *lock_queue_iter;
 ((void) sizeof ((x < dir->xsize && y < dir->ysize) ? 1 : 0), __extension__ ({ if (x < dir->xsize && y < dir->ysize) ; else __assert_fail ("x < dir->xsize && y < dir->ysize", "directory.c", 231, __extension__ __PRETTY_FUNCTION__); }));
 dir_lock = &dir->dir_lock[x * dir->ysize + y];
 if (dir_lock->lock)
 {
  stack->dir_lock_next = ((void *)0);
  stack->dir_lock_event = event;
  stack->ret_stack->way = stack->way;
  if (!dir_lock->lock_queue)
  {
   dir_lock->lock_queue = stack;
  }
  else
  {
   lock_queue_iter = dir_lock->lock_queue;
   while (stack->id > lock_queue_iter->id)
   {
    if (!lock_queue_iter->dir_lock_next)
     break;
    lock_queue_iter = lock_queue_iter->dir_lock_next;
   }
   if (!lock_queue_iter->dir_lock_next)
   {
    lock_queue_iter->dir_lock_next = stack;
   }
   else
   {
    stack->dir_lock_next = lock_queue_iter->dir_lock_next;
    lock_queue_iter->dir_lock_next = stack;
   }
  }
  ((mem_debug_category) ? __debug((mem_debug_category), "    0x%x access suspended\n", stack->tag) : (void) 0);
  return 0;
 }
 ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.new_access_block cache=\"%s\" access=\"A-%lld\" set=%d way=%d\n", dir->name, stack->id, x, y) : (void) 0);
 dir_lock->lock = 1;
 dir_lock->stack_id = stack->id;
 return 1;
}

variable_types: event int

variable_types:
stack
struct mod_stack_t *

variable_types: struct mod_stack_t { long long id; enum mod_access_kind_t { mod_access_invalid=0, mod_access_load=1, mod_access_store=2, mod_access_nc_store=3 } access_kind; int *witness_ptr; 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; } *event_queue; void *event_queue_item; struct mod_t { enum mod_kind_t { mod_kind_invalid=0, mod_kind_cache=1, mod_kind_main_memory=2, mod_kind_local_memory=3 } kind; char *name; int block_size; int log_block_size; int latency; int dir_latency; int mshr_size; int level; enum mod_range_kind_t { mod_range_invalid=0, mod_range_bounds=1, mod_range_interleaved=2 } range_kind; union { struct { unsigned int low; unsigned int high; } bounds; struct { unsigned int mod; unsigned int div; unsigned int eq; } interleaved; } range; struct mod_port_t { int locked; long long lock_when; struct mod_stack_t *stack; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; } *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t *lock_queue; } *dir_lock; unsigned char data[]; } *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 } policy; struct cache_set_t { struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; } *sets; unsigned int block_mask; int log_block_size; } *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; 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 *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; } *high_net; struct net_t *low_net; struct net_node_t *high_net_node; struct net_node_t *low_net_node; struct mod_stack_t *access_list_head; struct mod_stack_t *access_list_tail; int access_list_count; int access_list_max; struct mod_stack_t *write_access_list_head; struct mod_stack_t *write_access_list_tail; int write_access_list_count; int write_access_list_max; int access_list_coalesced_count; struct { struct mod_stack_t *bucket_list_head; struct mod_stack_t *bucket_list_tail; int bucket_list_count; int bucket_list_max; } access_hash_table[17]; int color; long long accesses; long long hits; long long reads; long long effective_reads; long long effective_read_hits; long long writes; long long effective_writes; long long effective_write_hits; long long nc_writes; long long effective_nc_writes; long long effective_nc_write_hits; long long evictions; long long blocking_reads; long long non_blocking_reads; long long read_hits; long long blocking_writes; long long non_blocking_writes; long long write_hits; long long blocking_nc_writes; long long non_blocking_nc_writes; long long nc_write_hits; long long read_retries; long long write_retries; long long nc_write_retries; long long no_retry_accesses; long long no_retry_hits; long long no_retry_reads; long long no_retry_read_hits; long long no_retry_writes; long long no_retry_write_hits; long long no_retry_nc_writes; long long no_retry_nc_write_hits; } *mod; struct mod_t *target_mod; struct mod_t *except_mod; struct mod_t *peer; struct mod_port_t *port; unsigned int addr; int tag; int set; int way; int state; int src_set; int src_way; int src_tag; enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 } request_dir; enum mod_message_type_t { message_none=0, message_clear_owner=1 } message; enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 } reply; int reply_size; int retain_owner; int pending; struct mod_stack_t *access_list_prev; struct mod_stack_t *access_list_next; struct mod_stack_t *write_access_list_prev; struct mod_stack_t *write_access_list_next; struct mod_stack_t *bucket_list_prev; struct mod_stack_t *bucket_list_next; int hit; int err; int shared; int read; int write; int nc_write; int blocking; int writeback; int eviction; int retry; int coalesced; int port_locked; struct net_msg_t *msg; int waiting_list_event; struct mod_stack_t *waiting_list_prev; struct mod_stack_t *waiting_list_next; int port_waiting_list_event; struct mod_stack_t *port_waiting_list_prev; struct mod_stack_t *port_waiting_list_next; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct mod_stack_t *master_stack; int dir_lock_event; struct mod_stack_t *dir_lock_next; struct mod_stack_t *ret_stack; int ret_event; } *


decompiled_code:
__int64 __fastcall dir_entry_unlock(__int64 a1, unsigned int a2, unsigned int a3)
{
int v3; // eax
__int64 v4; // r12
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // r13
__int64 v9; // rsi
__int64 v10; // [rsp-10h] [rbp-38h]

if ( *(_DWORD *)(a1 + 12) <= (signed int)a2 || (v3 = *(_DWORD *)(a1 + 16), v4 = a3, v3 <= (int)a3) )
_assert_fail("x < dir->xsize && y < dir->ysize", "directory.c", 0x124u, "dir_entry_unlock");
v6 = 3LL * (int)(a3 + a2 * v3);
result = *(_QWORD *)(a1 + 24);
v8 = result + 8 * v6;
v9 = *(_QWORD *)(v8 + 16);
if ( v9 )
{
esim_schedule_event(*(unsigned int *)(v9 + 280), v9, 1LL);
if ( mem_debug_category )
_debug(mem_debug_category, " 0x%x access resumed\n", *(unsigned int *)(*(_QWORD *)(v8 + 16) + 84LL));
result = *(_QWORD *)(*(_QWORD *)(v8 + 16) + 288LL);
*(_QWORD *)(v8 + 16) = result;
}
if ( mem_trace_category )
{
_trace(
mem_trace_category,
1LL,
"mem.end_access_block cache=\"%s\" access=\"A-%lld\" set=%d way=%d\n",
*(const char **)a1,
*(_QWORD *)(v8 + 8),
a2,
v4);
result = v10;
}
*(_DWORD *)v8 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2, unsigned int a3)
{
int v3; // eax
__int64 v4; // r12
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // r13
__int64 v9; // rsi
__int64 v10; // [rsp-10h] [rbp-38h]

if ( *(_DWORD *)(a1 + 12) <= (signed int)a2 || (v3 = *(_DWORD *)(a1 + 16), v4 = a3, v3 <= (int)a3) )
_assert_fail("x < dir->xsize && y < dir->ysize", "directory.c", 0x124u, "dir_entry_unlock");
v6 = 3LL * (int)(a3 + a2 * v3);
result = *(_QWORD *)(a1 + 24);
v8 = result + 8 * v6;
v9 = *(_QWORD *)(v8 + 16);
if ( v9 )
{
esim_schedule_event(*(unsigned int *)(v9 + 280), v9, 1LL);
if ( mem_debug_category )
_debug(mem_debug_category, " 0x%x access resumed\n", *(unsigned int *)(*(_QWORD *)(v8 + 16) + 84LL));
result = *(_QWORD *)(*(_QWORD *)(v8 + 16) + 288LL);
*(_QWORD *)(v8 + 16) = result;
}
if ( mem_trace_category )
{
_trace(
mem_trace_category,
1LL,
"mem.end_access_block cache=\"%s\" access=\"A-%lld\" set=%d way=%d\n",
*(const char **)a1,
*(_QWORD *)(v8 + 8),
a2,
v4);
result = v10;
}
*(_DWORD *)v8 = 0;
return result;
}

original_code:
void dir_entry_unlock(struct dir_t *dir, int x, int y)
{
 struct dir_lock_t *dir_lock;
 ((void) sizeof ((x < dir->xsize && y < dir->ysize) ? 1 : 0), __extension__ ({ if (x < dir->xsize && y < dir->ysize) ; else __assert_fail ("x < dir->xsize && y < dir->ysize", "directory.c", 292, __extension__ __PRETTY_FUNCTION__); }));
 dir_lock = &dir->dir_lock[x * dir->ysize + y];
 if (dir_lock->lock_queue)
 {
  esim_schedule_event(dir_lock->lock_queue->dir_lock_event, dir_lock->lock_queue, 1);
  ((mem_debug_category) ? __debug((mem_debug_category), "    0x%x access resumed\n", dir_lock->lock_queue->tag) : (void) 0);
  dir_lock->lock_queue = dir_lock->lock_queue->dir_lock_next;
 }
 ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.end_access_block cache=\"%s\" access=\"A-%lld\" set=%d way=%d\n", dir->name, dir_lock->stack_id, x, y) : (void) 0);
 dir_lock->lock = 0;
}

user_defined_types: enum mod_access_kind_t { mod_access_invalid=0, mod_access_load=1, mod_access_store=2, mod_access_nc_store=3 }

user_defined_types: enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 }

user_defined_types: enum mod_message_type_t { message_none=0, message_clear_owner=1 }

user_defined_types: enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 }

user_defined_types: struct mod_port_t { int locked; long long lock_when; struct mod_stack_t *stack; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; }

user_defined_types: enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 }

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

user_defined_types: 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; }

user_defined_types: enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 }

user_defined_types: enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 }

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:
__int64 __fastcall si_calc_get_work_groups_per_wavefront_pool(int a1, int a2, int a3)
{
int v4; // er8
int v5; // ecx
int v6; // edx
int v7; // eax
unsigned int v8; // esi
int v9; // edi
__int64 result; // rax
int v11; // esi

if ( si_emu_wavefront_size <= 0 )
_assert_fail("si_emu_wavefront_size > 0", "calc.c", 0x2Cu, "si_calc_get_work_groups_per_wavefront_pool");
v4 = (si_emu_wavefront_size + a1 - 1) / si_emu_wavefront_size;
v5 = si_gpu_max_wavefronts_per_wavefront_pool / v4;
v6 = si_gpu_register_alloc_size - 1;
v7 = -si_gpu_register_alloc_size;
if ( si_gpu_register_alloc_granularity == 1 )
v8 = v4 * (v7 & (a2 * si_emu_wavefront_size + v6));
else
v8 = v7 & (a2 * a1 + v6);
v9 = si_gpu_max_work_groups_per_wavefront_pool;
if ( v8 )
v9 = si_gpu_num_registers / v8;
result = si_gpu_max_work_groups_per_wavefront_pool;
v11 = -si_gpu_local_mem_alloc_size & (si_gpu_local_mem_alloc_size + a3 - 1);
if ( v11 )
result = (unsigned int)(si_gpu_local_mem_size / v11);
if ( v5 > si_gpu_max_work_groups_per_wavefront_pool )
v5 = si_gpu_max_work_groups_per_wavefront_pool;
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
unsigned int v8; // esi
int v9; // edi
__int64 result; // rax
int v11; // esi

if ( si_emu_wavefront_size <= 0 )
_assert_fail("si_emu_wavefront_size > 0", "calc.c", 0x2Cu, "si_calc_get_work_groups_per_wavefront_pool");
v4 = (si_emu_wavefront_size + a1 - 1) / si_emu_wavefront_size;
v5 = si_gpu_max_wavefronts_per_wavefront_pool / v4;
v6 = si_gpu_register_alloc_size - 1;
v7 = -si_gpu_register_alloc_size;
if ( si_gpu_register_alloc_granularity == 1 )
v8 = v4 * (v7 & (a2 * si_emu_wavefront_size + v6));
else
v8 = v7 & (a2 * a1 + v6);
v9 = si_gpu_max_work_groups_per_wavefront_pool;
if ( v8 )
v9 = si_gpu_num_registers / v8;
result = si_gpu_max_work_groups_per_wavefront_pool;
v11 = -si_gpu_local_mem_alloc_size & (si_gpu_local_mem_alloc_size + a3 - 1);
if ( v11 )
result = (unsigned int)(si_gpu_local_mem_size / v11);
if ( v5 > si_gpu_max_work_groups_per_wavefront_pool )
v5 = si_gpu_max_work_groups_per_wavefront_pool;
if ( v9 > v5 )
v9 = v5;
if ( (int)result > v9 )
result = (unsigned int)v9;
return result;
}

original_code:
int si_calc_get_work_groups_per_wavefront_pool(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_wavefront_pool;
 ((void) sizeof ((si_emu_wavefront_size > 0) ? 1 : 0), __extension__ ({ if (si_emu_wavefront_size > 0) ; else __assert_fail ("si_emu_wavefront_size > 0", "calc.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 wavefronts_per_work_group = (work_items_per_work_group + si_emu_wavefront_size - 1) /
  si_emu_wavefront_size;
 max_work_groups_limitted_by_max_wavefronts = si_gpu_max_wavefronts_per_wavefront_pool /
  wavefronts_per_work_group;
 if (si_gpu_register_alloc_granularity == si_gpu_register_alloc_wavefront)
  registers_per_work_group = (((registers_per_work_item * si_emu_wavefront_size) + ((si_gpu_register_alloc_size)-1)) & ~((si_gpu_register_alloc_size)-1)) * wavefronts_per_work_group;
 else
  registers_per_work_group = (((registers_per_work_item * work_items_per_work_group) + ((si_gpu_register_alloc_size)-1)) & ~((si_gpu_register_alloc_size)-1));
 max_work_groups_limitted_by_num_registers = registers_per_work_group ?
  si_gpu_num_registers / registers_per_work_group :
  si_gpu_max_work_groups_per_wavefront_pool;
 local_mem_per_work_group = (((local_mem_per_work_group) + ((si_gpu_local_mem_alloc_size)-1)) & ~((si_gpu_local_mem_alloc_size)-1));
 max_work_groups_limitted_by_local_mem = local_mem_per_work_group ?
  si_gpu_local_mem_size / local_mem_per_work_group :
  si_gpu_max_work_groups_per_wavefront_pool;
 work_groups_per_wavefront_pool = si_gpu_max_work_groups_per_wavefront_pool;
 work_groups_per_wavefront_pool = ((work_groups_per_wavefront_pool) < (max_work_groups_limitted_by_max_wavefronts) ? (work_groups_per_wavefront_pool) : (max_work_groups_limitted_by_max_wavefronts));
 work_groups_per_wavefront_pool= ((work_groups_per_wavefront_pool) < (max_work_groups_limitted_by_num_registers) ? (work_groups_per_wavefront_pool) : (max_work_groups_limitted_by_num_registers));
 work_groups_per_wavefront_pool = ((work_groups_per_wavefront_pool) < (max_work_groups_limitted_by_local_mem) ? (work_groups_per_wavefront_pool) : (max_work_groups_limitted_by_local_mem));
 return work_groups_per_wavefront_pool;
}


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

result = (int)si_gpu_calc_file_name;
if ( *(_BYTE *)si_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");
si_calc_plot_work_items_per_work_group();
si_calc_plot_registers_per_work_item();
result = si_calc_plot_local_mem_per_work_group();
}
return result;
}

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

result = (int)si_gpu_calc_file_name;
if ( *(_BYTE *)si_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 si_calc_plot(void)
{
 int ret;
 if (!*si_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");
 si_calc_plot_work_items_per_work_group();
 si_calc_plot_registers_per_work_item();
 si_calc_plot_local_mem_per_work_group();
}

canonical_original_code:
void si_calc_plot()
{
 int ret;
 if (!*si_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");
 si_calc_plot_work_items_per_work_group();
 si_calc_plot_registers_per_work_item();
 si_calc_plot_local_mem_per_work_group();
}

variable_types: ret int


decompiled_code:
__int64 __fastcall si_opencl_event_free(__int64 a1)
{
si_opencl_repo_remove_object(*(_QWORD *)(si_emu + 8LL), a1);
return mhandle_free(a1, "opencl-event.c:53");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
si_opencl_repo_remove_object(*(_QWORD *)(si_emu + 8LL), a1);
return mhandle_free(a1, "opencl-event.c:53");
}

original_code:
void si_opencl_event_free(struct si_opencl_event_t *event)
{
 si_opencl_repo_remove_object(si_emu->opencl_repo, event);
 (mhandle_free(event, "opencl-event.c" ":" "53"));
}

variable_types: struct si_opencl_event_t { unsigned int id; int ref_count; enum si_opencl_event_kind_t { SI_OPENCL_EVENT_NONE=0, SI_OPENCL_EVENT_NDRANGE_KERNEL=1, SI_OPENCL_EVENT_TASK=2, SI_OPENCL_EVENT_NATIVE_KERNEL=3, SI_OPENCL_EVENT_READ_BUFFER=4, SI_OPENCL_EVENT_WRITE_BUFFER=5, SI_OPENCL_EVENT_MAP_BUFFER=6, SI_OPENCL_EVENT_UNMAP_MEM_OBJECT=7, SI_OPENCL_EVENT_READ_BUFFER_RECT=8, SI_OPENCL_EVENT_WRITE_BUFFER_RECT=9, SI_OPENCL_EVENT_READ_IMAGE=10, SI_OPENCL_EVENT_WRITE_IMAGE=11, SI_OPENCL_EVENT_MAP_IMAGE=12, SI_OPENCL_EVENT_COPY_BUFFER=13, SI_OPENCL_EVENT_COPY_IMAGE=14, SI_OPENCL_EVENT_COPY_BUFFER_RECT=15, SI_OPENCL_EVENT_COPY_BUFFER_TO_IMAGE=16, SI_OPENCL_EVENT_COPY_IMAGE_TO_BUFFER=17, SI_OPENCL_EVENT_MARKER=18, SI_OPENCL_EVENT_COUNT=19 } kind; enum si_opencl_event_status_t { SI_OPENCL_EVENT_STATUS_NONE=0, SI_OPENCL_EVENT_STATUS_QUEUED=1, SI_OPENCL_EVENT_STATUS_SUBMITTED=2, SI_OPENCL_EVENT_STATUS_RUNNING=3, SI_OPENCL_EVENT_STATUS_COMPLETE=4 } status; long long time_queued; long long time_submit; long long time_start; long long time_end; } *

user_defined_types: struct si_opencl_event_t { unsigned int id; int ref_count; enum si_opencl_event_kind_t kind; enum si_opencl_event_status_t status; long long time_queued; long long time_submit; long long time_start; long long time_end; }


decompiled_code:
__int64 __fastcall si_opencl_event_get_profiling_info(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v6; // rcx

if ( a2 == 4738 )
{
v6 = a1 + 32;
goto LABEL_6;
}
if ( a2 > 0x1282 )
{
if ( a2 == 4739 )
{
v6 = a1 + 40;
goto LABEL_6;
}
LABEL_14:
fatal(
"%s: invalid or not implemented value for 'name' (0x%x)\n%s",
"si_opencl_event_get_profiling_info",
a2,
si_err_opencl_param_note);
_assert_fail("info", "opencl-event.c", 0x5Cu, "si_opencl_event_get_profiling_info");
}
if ( a2 == 4736 )
{
v6 = a1 + 16;
goto LABEL_6;
}
if ( a2 != 4737 )
goto LABEL_14;
v6 = a1 + 24;
LABEL_6:
if ( !a4 || a5 <= 7 )
return 8LL;
mem_write(a3, a4, 8LL, v6);
return 8LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v6; // rcx

if ( a2 == 4738 )
{
v6 = a1 + 32;
goto LABEL_6;
}
if ( a2 > 0x1282 )
{
if ( a2 == 4739 )
{
v6 = a1 + 40;
goto LABEL_6;
}
LABEL_14:
fatal(
"%s: invalid or not implemented value for 'name' (0x%x)\n%s",
"si_opencl_event_get_profiling_info",
a2,
si_err_opencl_param_note);
_assert_fail("info", "opencl-event.c", 0x5Cu, "si_opencl_event_get_profiling_info");
}
if ( a2 == 4736 )
{
v6 = a1 + 16;
goto LABEL_6;
}
if ( a2 != 4737 )
goto LABEL_14;
v6 = a1 + 24;
LABEL_6:
if ( !a4 || a5 <= 7 )
return 8LL;
mem_write(a3, a4, 8LL, v6);
return 8LL;
}

original_code:
uint32_t si_opencl_event_get_profiling_info(struct si_opencl_event_t *event, uint32_t name,
 struct mem_t *mem, uint32_t addr, uint32_t size)
{
 uint32_t size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1280:
  size_ret = 8;
  info = &event->time_queued;
  break;
 case 0x1281:
  size_ret = 8;
  info = &event->time_submit;
  break;
 case 0x1282:
  size_ret = 8;
  info = &event->time_start;
  break;
 case 0x1283:
  size_ret = 8;
  info = &event->time_end;
  break;
 default:
  fatal("%s: invalid or not implemented value for 'name' (0x%x)\n%s",
   __FUNCTION__, name, si_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-event.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int si_opencl_event_get_profiling_info(struct si_opencl_event_t *event, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 unsigned int size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1280:
  size_ret = 8;
  info = &event->time_queued;
  break;
 case 0x1281:
  size_ret = 8;
  info = &event->time_submit;
  break;
 case 0x1282:
  size_ret = 8;
  info = &event->time_start;
  break;
 case 0x1283:
  size_ret = 8;
  info = &event->time_end;
  break;
 default:
  fatal("%s: invalid or not implemented value for 'name' (0x%x)\n%s",
   __FUNCTION__, name, si_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-event.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

variable_types:
name
unsigned int

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; } *

variable_types:
addr
unsigned int

variable_types:
size
unsigned int

variable_types:
info
void *

return_type: unsigned int

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: enum si_opencl_event_kind_t { SI_OPENCL_EVENT_NONE=0, SI_OPENCL_EVENT_NDRANGE_KERNEL=1, SI_OPENCL_EVENT_TASK=2, SI_OPENCL_EVENT_NATIVE_KERNEL=3, SI_OPENCL_EVENT_READ_BUFFER=4, SI_OPENCL_EVENT_WRITE_BUFFER=5, SI_OPENCL_EVENT_MAP_BUFFER=6, SI_OPENCL_EVENT_UNMAP_MEM_OBJECT=7, SI_OPENCL_EVENT_READ_BUFFER_RECT=8, SI_OPENCL_EVENT_WRITE_BUFFER_RECT=9, SI_OPENCL_EVENT_READ_IMAGE=10, SI_OPENCL_EVENT_WRITE_IMAGE=11, SI_OPENCL_EVENT_MAP_IMAGE=12, SI_OPENCL_EVENT_COPY_BUFFER=13, SI_OPENCL_EVENT_COPY_IMAGE=14, SI_OPENCL_EVENT_COPY_BUFFER_RECT=15, SI_OPENCL_EVENT_COPY_BUFFER_TO_IMAGE=16, SI_OPENCL_EVENT_COPY_IMAGE_TO_BUFFER=17, SI_OPENCL_EVENT_MARKER=18, SI_OPENCL_EVENT_COUNT=19 }

user_defined_types: enum si_opencl_event_status_t { SI_OPENCL_EVENT_STATUS_NONE=0, SI_OPENCL_EVENT_STATUS_QUEUED=1, SI_OPENCL_EVENT_STATUS_SUBMITTED=2, SI_OPENCL_EVENT_STATUS_RUNNING=3, SI_OPENCL_EVENT_STATUS_COMPLETE=4 }

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:
__int64 si_opencl_event_timer()
{
return 1000 * esim_real_time();
}

canonical_decompiled_code:
__int64 func2()
{
return 1000 * esim_real_time();
}

original_code:
long long si_opencl_event_timer(void)
{
 return esim_real_time() * 1000;
}

canonical_original_code:
long long si_opencl_event_timer()
{
 return esim_real_time() * 1000;
}

return_type: long long


original_code:
struct cache_t *cache_create(char *name, unsigned int num_sets, unsigned int block_size,
 unsigned int assoc, enum cache_policy_t policy)
{
 struct cache_t *cache;
 struct cache_block_t *block;
 unsigned int set, way;
 cache = (mhandle_calloc(1, sizeof(struct cache_t), "cache.c" ":" "127"));
 if (!cache)
  fatal("%s: out of memory", __FUNCTION__);
 cache->name = (mhandle_strdup(name, "cache.c" ":" "132"));
 if (!cache->name)
  fatal("%s: out of memory", __FUNCTION__);
 cache->num_sets = num_sets;
 cache->block_size = block_size;
 cache->assoc = assoc;
 cache->policy = policy;
 ((void) sizeof ((!(num_sets & (num_sets - 1))) ? 1 : 0), __extension__ ({ if (!(num_sets & (num_sets - 1))) ; else __assert_fail ("!(num_sets & (num_sets - 1))", "cache.c", 143, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!(block_size & (block_size - 1))) ? 1 : 0), __extension__ ({ if (!(block_size & (block_size - 1))) ; else __assert_fail ("!(block_size & (block_size - 1))", "cache.c", 144, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!(assoc & (assoc - 1))) ? 1 : 0), __extension__ ({ if (!(assoc & (assoc - 1))) ; else __assert_fail ("!(assoc & (assoc - 1))", "cache.c", 145, __extension__ __PRETTY_FUNCTION__); }));
 cache->log_block_size = log_base2(block_size);
 cache->block_mask = block_size - 1;
 cache->sets = (mhandle_calloc(num_sets, sizeof(struct cache_set_t), "cache.c" ":" "150"));
 if (!cache->sets)
  fatal("%s: out of memory", __FUNCTION__);
 for (set = 0; set < num_sets; set++)
 {
  cache->sets[set].blocks = (mhandle_calloc(assoc, sizeof(struct cache_block_t), "cache.c" ":" "158"));
  if (!cache->sets[set].blocks)
   fatal("%s: out of memory", __FUNCTION__);
  cache->sets[set].way_head = &cache->sets[set].blocks[0];
  cache->sets[set].way_tail = &cache->sets[set].blocks[assoc - 1];
  for (way = 0; way < assoc; way++)
  {
   block = &cache->sets[set].blocks[way];
   block->way = way;
   block->way_prev = way ? &cache->sets[set].blocks[way - 1] : ((void *)0);
   block->way_next = way < assoc - 1 ? &cache->sets[set].blocks[way + 1] : ((void *)0);
  }
 }
 return cache;
}

canonical_original_code:
struct cache_t *cache_create(char *name, unsigned int num_sets, unsigned int block_size, unsigned int assoc, enum cache_policy_t policy)
{
 struct cache_t *cache;
 struct cache_block_t *block;
 unsigned int set; unsigned int way;
 cache = (mhandle_calloc(1, sizeof(struct cache_t), "cache.c" ":" "127"));
 if (!cache)
  fatal("%s: out of memory", __FUNCTION__);
 cache->name = (mhandle_strdup(name, "cache.c" ":" "132"));
 if (!cache->name)
  fatal("%s: out of memory", __FUNCTION__);
 cache->num_sets = num_sets;
 cache->block_size = block_size;
 cache->assoc = assoc;
 cache->policy = policy;
 ((void) sizeof ((!(num_sets & (num_sets - 1))) ? 1 : 0), __extension__ ({ if (!(num_sets & (num_sets - 1))) ; else __assert_fail ("!(num_sets & (num_sets - 1))", "cache.c", 143, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!(block_size & (block_size - 1))) ? 1 : 0), __extension__ ({ if (!(block_size & (block_size - 1))) ; else __assert_fail ("!(block_size & (block_size - 1))", "cache.c", 144, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!(assoc & (assoc - 1))) ? 1 : 0), __extension__ ({ if (!(assoc & (assoc - 1))) ; else __assert_fail ("!(assoc & (assoc - 1))", "cache.c", 145, __extension__ __PRETTY_FUNCTION__); }));
 cache->log_block_size = log_base2(block_size);
 cache->block_mask = block_size - 1;
 cache->sets = (mhandle_calloc(num_sets, sizeof(struct cache_set_t), "cache.c" ":" "150"));
 if (!cache->sets)
  fatal("%s: out of memory", __FUNCTION__);
 for (set = 0; set < num_sets; set++)
 {
  cache->sets[set].blocks = (mhandle_calloc(assoc, sizeof(struct cache_block_t), "cache.c" ":" "158"));
  if (!cache->sets[set].blocks)
   fatal("%s: out of memory", __FUNCTION__);
  cache->sets[set].way_head = &cache->sets[set].blocks[0];
  cache->sets[set].way_tail = &cache->sets[set].blocks[assoc - 1];
  for (way = 0; way < assoc; way++)
  {
   block = &cache->sets[set].blocks[way];
   block->way = way;
   block->way_prev = way ? &cache->sets[set].blocks[way - 1] : ((void *)0);
   block->way_next = way < assoc - 1 ? &cache->sets[set].blocks[way + 1] : ((void *)0);
  }
 }
 return cache;
}

variable_types:
name
char *

variable_types:
assoc
unsigned int

variable_types: struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 } policy; struct cache_set_t { struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; } *sets; unsigned int block_mask; int log_block_size; } *

variable_types:
set
unsigned int

variable_types:
way
unsigned int

user_defined_types: struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t policy; struct cache_set_t *sets; unsigned int block_mask; int log_block_size; }

user_defined_types: struct cache_set_t { struct cache_block_t *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; }

user_defined_types: struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t state; }


decompiled_code:
__int64 __fastcall cache_free(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax

if ( *(_DWORD *)(a1 + 8) )
{
v1 = 0;
do
{
v2 = v1++;
mhandle_free(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 24 * v2 + 16), "cache.c:184");
}
while ( *(_DWORD *)(a1 + 8) > v1 );
}
mhandle_free(*(_QWORD *)(a1 + 24), "cache.c:185");
mhandle_free(*(_QWORD *)a1, "cache.c:186");
return mhandle_free(a1, "cache.c:187");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax

if ( *(_DWORD *)(a1 + 8) )
{
v1 = 0;
do
{
v2 = v1++;
mhandle_free(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 24 * v2 + 16), "cache.c:184");
}
while ( *(_DWORD *)(a1 + 8) > v1 );
}
mhandle_free(*(_QWORD *)(a1 + 24), "cache.c:185");
mhandle_free(*(_QWORD *)a1, "cache.c:186");
return mhandle_free(a1, "cache.c:187");
}

original_code:
void cache_free(struct cache_t *cache)
{
 unsigned int set;
 for (set = 0; set < cache->num_sets; set++)
  (mhandle_free(cache->sets[set].blocks, "cache.c" ":" "184"));
 (mhandle_free(cache->sets, "cache.c" ":" "185"));
 (mhandle_free(cache->name, "cache.c" ":" "186"));
 (mhandle_free(cache, "cache.c" ":" "187"));
}


decompiled_code:
__int64 __fastcall cache_decode_address(_DWORD *a1, unsigned int a2, int *a3, _DWORD *a4, int *a5)
{
int v7; // ecx
__int64 result; // rax

if ( a3 )
{
v7 = a1[9];
result = (a2 >> v7) / a1[2];
*a3 = (a2 >> v7) % a1[2];
}
if ( a4 )
{
result = a2 & ~a1[8];
*a4 = result;
}
if ( a5 )
*a5 = a1[8] & a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, unsigned int a2, int *a3, _DWORD *a4, int *a5)
{
int v7; // ecx
__int64 result; // rax

if ( a3 )
{
v7 = a1[9];
result = (a2 >> v7) / a1[2];
*a3 = (a2 >> v7) % a1[2];
}
if ( a4 )
{
result = a2 & ~a1[8];
*a4 = result;
}
if ( a5 )
*a5 = a1[8] & a2;
return result;
}

original_code:
void cache_decode_address(struct cache_t *cache, unsigned int addr, int *set_ptr, int *tag_ptr,
 unsigned int *offset_ptr)
{
 if (set_ptr) *(set_ptr) = ((addr >> cache->log_block_size) % cache->num_sets);
 if (tag_ptr) *(tag_ptr) = (addr & ~cache->block_mask);
 if (offset_ptr) *(offset_ptr) = (addr & cache->block_mask);
}


original_code:
int cache_find_block(struct cache_t *cache, unsigned int addr, int *set_ptr, int *way_ptr,
 int *state_ptr)
{
 int set, tag, way;
 tag = addr & ~cache->block_mask;
 set = (addr >> cache->log_block_size) % cache->num_sets;
 if (set_ptr) *(set_ptr) = (set);
 if (state_ptr) *(state_ptr) = (0);
 for (way = 0; way < cache->assoc; way++)
  if (cache->sets[set].blocks[way].tag == tag && cache->sets[set].blocks[way].state)
   break;
 if (way == cache->assoc)
  return 0;
 if (way_ptr) *(way_ptr) = (way);
 if (state_ptr) *(state_ptr) = (cache->sets[set].blocks[way].state);
 return 1;
}

canonical_original_code:
int cache_find_block(struct cache_t *cache, unsigned int addr, int *set_ptr, int *way_ptr, int *state_ptr)
{
 int set; int tag; int way;
 tag = addr & ~cache->block_mask;
 set = (addr >> cache->log_block_size) % cache->num_sets;
 if (set_ptr) *(set_ptr) = (set);
 if (state_ptr) *(state_ptr) = (0);
 for (way = 0; way < cache->assoc; way++)
  if (cache->sets[set].blocks[way].tag == tag && cache->sets[set].blocks[way].state)
   break;
 if (way == cache->assoc)
  return 0;
 if (way_ptr) *(way_ptr) = (way);
 if (state_ptr) *(state_ptr) = (cache->sets[set].blocks[way].state);
 return 1;
}

variable_types: set int

variable_types: tag int

variable_types: way int


decompiled_code:
void __fastcall cache_set_block(__int64 a1, int a2, int a3, unsigned int a4, unsigned int a5)
{
__int64 v6; // rbx
__int64 v7; // r13
__int64 v9; // rbx
__int64 v10; // rbp
__int64 v11; // rdi
__int64 v12; // rsi
const char *v13; // rax

if ( a2 < 0 || *(_DWORD *)(a1 + 8) <= (unsigned int)a2 )
_assert_fail("set >= 0 && set < cache->num_sets", "cache.c", 0xEAu, "cache_set_block");
v6 = a3;
if ( a3 < 0 || *(_DWORD *)(a1 + 16) <= (unsigned int)a3 )
_assert_fail("way >= 0 && way < cache->assoc", "cache.c", 0xEBu, "cache_set_block");
v7 = a4;
if ( mem_trace_category )
{
v13 = (const char *)map_value(&cache_block_state_map, a5);
_trace(
mem_trace_category,
1LL,
"mem.set_block cache=\"%s\" set=%d way=%d tag=0x%x state=\"%s\"\n",
*(const char **)a1,
(unsigned int)a2,
(unsigned int)v6,
v7,
v13);
}
v9 = 32 * v6;
v10 = 24LL * a2;
v11 = v10 + *(_QWORD *)(a1 + 24);
v12 = v9 + *(_QWORD *)(v11 + 16);
if ( *(_DWORD *)(a1 + 20) == 2 && *(_DWORD *)(v12 + 16) != (_DWORD)v7 )
{
cache_update_waylist_constprop_0((__int64 **)v11, (__int64 *)v12);
v12 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + v10 + 16) + v9;
}
*(_DWORD *)(v12 + 16) = v7;
*(_DWORD *)(v12 + 28) = a5;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2, int a3, unsigned int a4, unsigned int a5)
{
__int64 v6; // rbx
__int64 v7; // r13
__int64 v9; // rbx
__int64 v10; // rbp
__int64 v11; // rdi
__int64 v12; // rsi
const char *v13; // rax

if ( a2 < 0 || *(_DWORD *)(a1 + 8) <= (unsigned int)a2 )
_assert_fail("set >= 0 && set < cache->num_sets", "cache.c", 0xEAu, "cache_set_block");
v6 = a3;
if ( a3 < 0 || *(_DWORD *)(a1 + 16) <= (unsigned int)a3 )
_assert_fail("way >= 0 && way < cache->assoc", "cache.c", 0xEBu, "cache_set_block");
v7 = a4;
if ( mem_trace_category )
{
v13 = (const char *)map_value(&cache_block_state_map, a5);
_trace(
mem_trace_category,
1LL,
"mem.set_block cache=\"%s\" set=%d way=%d tag=0x%x state=\"%s\"\n",
*(const char **)a1,
(unsigned int)a2,
(unsigned int)v6,
v7,
v13);
}
v9 = 32 * v6;
v10 = 24LL * a2;
v11 = v10 + *(_QWORD *)(a1 + 24);
v12 = v9 + *(_QWORD *)(v11 + 16);
if ( *(_DWORD *)(a1 + 20) == 2 && *(_DWORD *)(v12 + 16) != (_DWORD)v7 )
{
cache_update_waylist_constprop_0((__int64 **)v11, (__int64 *)v12);
v12 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + v10 + 16) + v9;
}
*(_DWORD *)(v12 + 16) = v7;
*(_DWORD *)(v12 + 28) = a5;
}

original_code:
void cache_set_block(struct cache_t *cache, int set, int way, int tag, int state)
{
 ((void) sizeof ((set >= 0 && set < cache->num_sets) ? 1 : 0), __extension__ ({ if (set >= 0 && set < cache->num_sets) ; else __assert_fail ("set >= 0 && set < cache->num_sets", "cache.c", 234, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((way >= 0 && way < cache->assoc) ? 1 : 0), __extension__ ({ if (way >= 0 && way < cache->assoc) ; else __assert_fail ("way >= 0 && way < cache->assoc", "cache.c", 235, __extension__ __PRETTY_FUNCTION__); }));
 ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.set_block cache=\"%s\" set=%d way=%d tag=0x%x state=\"%s\"\n", cache->name, set, way, tag, map_value(&cache_block_state_map, state)) : (void) 0);
 if (cache->policy == cache_policy_fifo
  && cache->sets[set].blocks[way].tag != tag)
  cache_update_waylist(&cache->sets[set],
   &cache->sets[set].blocks[way],
   cache_waylist_head);
 cache->sets[set].blocks[way].tag = tag;
 cache->sets[set].blocks[way].state = state;
}

variable_types: state int


decompiled_code:
__int64 __fastcall cache_get_block(__int64 a1, int a2, int a3, _DWORD *a4, _DWORD *a5)
{
__int64 result; // rax

if ( a2 < 0 || *(_DWORD *)(a1 + 8) <= (unsigned int)a2 )
_assert_fail("set >= 0 && set < cache->num_sets", "cache.c", 0xFDu, "cache_get_block");
if ( a3 < 0 || *(_DWORD *)(a1 + 16) <= (unsigned int)a3 )
_assert_fail("way >= 0 && way < cache->assoc", "cache.c", 0xFEu, "cache_get_block");
if ( a4 )
{
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 24LL * a2 + 16) + 32LL * a3 + 16);
*a4 = result;
}
if ( a5 )
{
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 24LL * a2 + 16) + 32LL * a3 + 28);
*a5 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3, _DWORD *a4, _DWORD *a5)
{
__int64 result; // rax

if ( a2 < 0 || *(_DWORD *)(a1 + 8) <= (unsigned int)a2 )
_assert_fail("set >= 0 && set < cache->num_sets", "cache.c", 0xFDu, "cache_get_block");
if ( a3 < 0 || *(_DWORD *)(a1 + 16) <= (unsigned int)a3 )
_assert_fail("way >= 0 && way < cache->assoc", "cache.c", 0xFEu, "cache_get_block");
if ( a4 )
{
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 24LL * a2 + 16) + 32LL * a3 + 16);
*a4 = result;
}
if ( a5 )
{
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 24LL * a2 + 16) + 32LL * a3 + 28);
*a5 = result;
}
return result;
}

original_code:
void cache_get_block(struct cache_t *cache, int set, int way, int *tag_ptr, int *state_ptr)
{
 ((void) sizeof ((set >= 0 && set < cache->num_sets) ? 1 : 0), __extension__ ({ if (set >= 0 && set < cache->num_sets) ; else __assert_fail ("set >= 0 && set < cache->num_sets", "cache.c", 253, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((way >= 0 && way < cache->assoc) ? 1 : 0), __extension__ ({ if (way >= 0 && way < cache->assoc) ; else __assert_fail ("way >= 0 && way < cache->assoc", "cache.c", 254, __extension__ __PRETTY_FUNCTION__); }));
 if (tag_ptr) *(tag_ptr) = (cache->sets[set].blocks[way].tag);
 if (state_ptr) *(state_ptr) = (cache->sets[set].blocks[way].state);
}


decompiled_code:
__int64 __fastcall cache_replace_block(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rsi
unsigned int v6; // [rsp+Ch] [rbp-Ch]

if ( a2 < 0 || *(_DWORD *)(a1 + 8) <= (unsigned int)a2 )
_assert_fail("set >= 0 && set < cache->num_sets", "cache.c", 0x121u, "cache_replace_block");
v2 = *(_DWORD *)(a1 + 20);
if ( (unsigned int)(v2 - 1) <= 1 )
{
v4 = *(_QWORD *)(a1 + 24) + 24LL * a2;
v5 = *(_QWORD *)(v4 + 8);
v6 = *(_DWORD *)(v5 + 24);
cache_update_waylist_constprop_0((__int64 **)v4, (__int64 *)v5);
result = v6;
}
else
{
if ( v2 != 3 )
_assert_fail("cache->policy == cache_policy_random", "cache.c", 0x135u, "cache_replace_block");
result = (unsigned int)(random() % *(unsigned int *)(a1 + 16));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rsi
unsigned int v6; // [rsp+Ch] [rbp-Ch]

if ( a2 < 0 || *(_DWORD *)(a1 + 8) <= (unsigned int)a2 )
_assert_fail("set >= 0 && set < cache->num_sets", "cache.c", 0x121u, "cache_replace_block");
v2 = *(_DWORD *)(a1 + 20);
if ( (unsigned int)(v2 - 1) <= 1 )
{
v4 = *(_QWORD *)(a1 + 24) + 24LL * a2;
v5 = *(_QWORD *)(v4 + 8);
v6 = *(_DWORD *)(v5 + 24);
cache_update_waylist_constprop_0((__int64 **)v4, (__int64 *)v5);
result = v6;
}
else
{
if ( v2 != 3 )
_assert_fail("cache->policy == cache_policy_random", "cache.c", 0x135u, "cache_replace_block");
result = (unsigned int)(random() % *(unsigned int *)(a1 + 16));
}
return result;
}

original_code:
int cache_replace_block(struct cache_t *cache, int set)
{
 ((void) sizeof ((set >= 0 && set < cache->num_sets) ? 1 : 0), __extension__ ({ if (set >= 0 && set < cache->num_sets) ; else __assert_fail ("set >= 0 && set < cache->num_sets", "cache.c", 289, __extension__ __PRETTY_FUNCTION__); }));
 if (cache->policy == cache_policy_lru ||
  cache->policy == cache_policy_fifo)
 {
  int way = cache->sets[set].way_tail->way;
  cache_update_waylist(&cache->sets[set], cache->sets[set].way_tail,
   cache_waylist_head);
  return way;
 }
 ((void) sizeof ((cache->policy == cache_policy_random) ? 1 : 0), __extension__ ({ if (cache->policy == cache_policy_random) ; else __assert_fail ("cache->policy == cache_policy_random", "cache.c", 309, __extension__ __PRETTY_FUNCTION__); }));
 return random() % cache->assoc;
}


decompiled_code:
__int64 __fastcall cache_set_transient_tag(__int64 a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 24) + 24LL * a2;
*(_DWORD *)(*(_QWORD *)(result + 16) + 32LL * a3 + 20) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 24) + 24LL * a2;
*(_DWORD *)(*(_QWORD *)(result + 16) + 32LL * a3 + 20) = a4;
return result;
}

original_code:
void cache_set_transient_tag(struct cache_t *cache, int set, int way, int tag)
{
 struct cache_block_t *block;
 block = &cache->sets[set].blocks[way];
 block->transient_tag = tag;
}

variable_types: struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *


decompiled_code:
__int64 x86_cpu_writeback()
{
__int64 result; // rax
int v1; // ebx
unsigned int v2; // edi

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

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // ebx
unsigned int v2; // edi

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

original_code:
void x86_cpu_writeback()
{
 int core;
 x86_cpu->stage = "writeback";
 for (core = 0; core < x86_cpu_num_cores; core++)
  x86_cpu_writeback_core(core);
}

variable_types: core int


decompiled_code:
__int64 x86_fu_init()
{
__int64 result; // rax
__int64 v1; // rbp
int v2; // ebx
__int64 v3; // r12
__int64 v4; // r12
bool v5; // cc

result = x86_cpu_num_cores;
if ( x86_cpu_num_cores > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
++v2;
v3 = *x86_cpu;
result = mhandle_calloc(1LL, 1456LL, "fu.c:129");
v4 = v1 + v3;
v1 += 1824LL;
v5 = x86_cpu_num_cores <= v2;
*(_QWORD *)(v4 + 16) = result;
}
while ( !v5 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rbp
int v2; // ebx
__int64 v3; // r12
__int64 v4; // r12
bool v5; // cc

result = x86_cpu_num_cores;
if ( x86_cpu_num_cores > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
++v2;
v3 = *x86_cpu;
result = mhandle_calloc(1LL, 1456LL, "fu.c:129");
v4 = v1 + v3;
v1 += 1824LL;
v5 = x86_cpu_num_cores <= v2;
*(_QWORD *)(v4 + 16) = result;
}
while ( !v5 );
}
return result;
}

original_code:
void x86_fu_init()
{
 int core;
 for (core = 0; core < x86_cpu_num_cores; core++)
  (x86_cpu->core[core]).fu = (mhandle_calloc(1, sizeof(struct x86_fu_t), "fu.c" ":" "129"));
}

user_defined_types: struct x86_fu_t { long long cycle_when_free[-1][10]; long long accesses[-1]; long long denied[-1]; long long waiting_time[-1]; }


decompiled_code:
__int64 x86_fu_done()
{
__int64 result; // rax
__int64 v1; // rbp
int v2; // ebx
__int64 v3; // rdi

result = x86_cpu_num_cores;
if ( x86_cpu_num_cores > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
++v2;
v3 = *(_QWORD *)(*x86_cpu + v1 + 16);
v1 += 1824LL;
result = mhandle_free(v3, "fu.c:137");
}
while ( x86_cpu_num_cores > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // rbp
int v2; // ebx
__int64 v3; // rdi

result = x86_cpu_num_cores;
if ( x86_cpu_num_cores > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
++v2;
v3 = *(_QWORD *)(*x86_cpu + v1 + 16);
v1 += 1824LL;
result = mhandle_free(v3, "fu.c:137");
}
while ( x86_cpu_num_cores > v2 );
}
return result;
}

original_code:
void x86_fu_done()
{
 int core;
 for (core = 0; core < x86_cpu_num_cores; core++)
  (mhandle_free((x86_cpu->core[core]).fu, "fu.c" ":" "137"));
}


decompiled_code:
void *__fastcall x86_fu_release(int a1)
{
__int64 v1; // rbp
int *v2; // rbx
_QWORD *v3; // r13
__int64 v4; // rdx
void *result; // rax

v1 = 0LL;
v2 = x86_fu_res_pool;
v3 = (_QWORD *)x86_cpu;
do
{
v4 = *v2;
if ( (int)v4 > 0 )
result = memset((void *)(v1 + *(_QWORD *)(*v3 + 1824LL * a1 + 16)), 0, 8 * v4);
v2 += 6;
v1 += 80LL;
}
while ( v2 != &x86_fu_res_pool[84] );
return result;
}

canonical_decompiled_code:
void *__fastcall func3(int a1)
{
__int64 v1; // rbp
int *v2; // rbx
_QWORD *v3; // r13
__int64 v4; // rdx
void *result; // rax

v1 = 0LL;
v2 = x86_fu_res_pool;
v3 = (_QWORD *)x86_cpu;
do
{
v4 = *v2;
if ( (int)v4 > 0 )
result = memset((void *)(v1 + *(_QWORD *)(*v3 + 1824LL * a1 + 16)), 0, 8 * v4);
v2 += 6;
v1 += 80LL;
}
while ( v2 != &x86_fu_res_pool[84] );
return result;
}

original_code:
void x86_fu_release(int core)
{
 int i, j;
 for (i = 0; i < x86_fu_count; i++)
  for (j = 0; j < x86_fu_res_pool[i].count; j++)
   (x86_cpu->core[core]).fu->cycle_when_free[i][j] = 0;
}

canonical_original_code:
void x86_fu_release(int core)
{
 int i; int j;
 for (i = 0; i < x86_fu_count; i++)
  for (j = 0; j < x86_fu_res_pool[i].count; j++)
   (x86_cpu->core[core]).fu->cycle_when_free[i][j] = 0;
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall net_node_create(const char **a1, int a2, int a3, int a4, int a5, int a6, __int64 a7, __int64 a8)
{
__int64 v10; // r13
__int64 v11; // rax

v10 = mhandle_calloc(1LL, 104LL, "node.c:35");
if ( !v10 )
fatal("%s: out of memory", "net_node_create");
*(_QWORD *)v10 = a1;
v11 = mhandle_strdup(a7, "node.c:41");
*(_DWORD *)(v10 + 8) = a2;
*(_QWORD *)(v10 + 16) = v11;
*(_DWORD *)(v10 + 12) = a3;
*(_QWORD *)(v10 + 24) = a8;
*(_DWORD *)(v10 + 32) = a6;
*(_DWORD *)(v10 + 48) = a4;
*(_DWORD *)(v10 + 52) = a5;
if ( a2 != 1 && a6 <= 0 )
panic("%s: invalid bandwidth", "net_node_create");
if ( net_get_node_by_name(a1, a7) )
fatal("%s: duplicated node name.\n%s", *a1, err_net_node_name_duplicate);
*(_QWORD *)(v10 + 64) = list_create_with_size(4LL);
*(_QWORD *)(v10 + 56) = list_create_with_size(4LL);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, int a2, int a3, int a4, int a5, int a6, __int64 a7, __int64 a8)
{
__int64 v10; // r13
__int64 v11; // rax

v10 = mhandle_calloc(1LL, 104LL, "node.c:35");
if ( !v10 )
fatal("%s: out of memory", "net_node_create");
*(_QWORD *)v10 = a1;
v11 = mhandle_strdup(a7, "node.c:41");
*(_DWORD *)(v10 + 8) = a2;
*(_QWORD *)(v10 + 16) = v11;
*(_DWORD *)(v10 + 12) = a3;
*(_QWORD *)(v10 + 24) = a8;
*(_DWORD *)(v10 + 32) = a6;
*(_DWORD *)(v10 + 48) = a4;
*(_DWORD *)(v10 + 52) = a5;
if ( a2 != 1 && a6 <= 0 )
panic("%s: invalid bandwidth", "net_node_create");
if ( net_get_node_by_name(a1, a7) )
fatal("%s: duplicated node name.\n%s", *a1, err_net_node_name_duplicate);
*(_QWORD *)(v10 + 64) = list_create_with_size(4LL);
*(_QWORD *)(v10 + 56) = list_create_with_size(4LL);
return v10;
}

original_code:
struct net_node_t *net_node_create(struct net_t *net,
 enum net_node_kind_t kind, int index,
 int input_buffer_size, int output_buffer_size,
 int bandwidth, char *name, void *user_data)
{
 struct net_node_t *node;
 node = (mhandle_calloc(1, sizeof(struct net_node_t), "node.c" ":" "35"));
 if (!node)
  fatal("%s: out of memory", __FUNCTION__);
 node->net = net;
 node->name = (mhandle_strdup(name, "node.c" ":" "41"));
 node->kind = kind;
 node->index = index;
 node->user_data = user_data;
 node->bandwidth = bandwidth;
 node->input_buffer_size = input_buffer_size;
 node->output_buffer_size = output_buffer_size;
 if (kind != net_node_end && bandwidth < 1)
  panic("%s: invalid bandwidth", __FUNCTION__);
 if (net_get_node_by_name(net, name))
  fatal("%s: duplicated node name.\n%s", net->name,
   err_net_node_name_duplicate);
 node->output_buffer_list = list_create_with_size(4);
 node->input_buffer_list = list_create_with_size(4);
 return node;
}

variable_types:
net
struct net_t *

variable_types: index int

variable_types: bandwidth int

variable_types: 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 { int cost; struct net_node_t *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; } *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; } *

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; }

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 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_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 linked_list_t { int count; int error_code; struct linked_list_elem_t *head; int current_index; }


decompiled_code:
__int64 __fastcall net_node_free(_QWORD *a1)
{
unsigned int i; // ebx
__int64 v3; // rsi
__int64 v4; // rax
int v5; // eax
__int64 v6; // rdi
unsigned int j; // ebx
__int64 v8; // rsi
__int64 v9; // rax
int v10; // eax
__int64 v11; // rdi

for ( i = 0; ; ++i )
{
v5 = list_count(a1[7]);
v6 = a1[7];
if ( v5 <= (int)i )
break;
v3 = i;
v4 = list_get(v6, v3);
net_buffer_free(v4);
}
list_free(v6);
for ( j = 0; ; ++j )
{
v10 = list_count(a1[8]);
v11 = a1[8];
if ( v10 <= (int)j )
break;
v8 = j;
v9 = list_get(v11, v8);
net_buffer_free(v9);
}
list_free(v11);
mhandle_free(a1[2], "node.c:77");
return mhandle_free(a1, "node.c:78");
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
unsigned int i; // ebx
__int64 v3; // rsi
__int64 v4; // rax
int v5; // eax
__int64 v6; // rdi
unsigned int j; // ebx
__int64 v8; // rsi
__int64 v9; // rax
int v10; // eax
__int64 v11; // rdi

for ( i = 0; ; ++i )
{
v5 = list_count(a1[7]);
v6 = a1[7];
if ( v5 <= (int)i )
break;
v3 = i;
v4 = list_get(v6, v3);
net_buffer_free(v4);
}
list_free(v6);
for ( j = 0; ; ++j )
{
v10 = list_count(a1[8]);
v11 = a1[8];
if ( v10 <= (int)j )
break;
v8 = j;
v9 = list_get(v11, v8);
net_buffer_free(v9);
}
list_free(v11);
mhandle_free(a1[2], "node.c:77");
return mhandle_free(a1, "node.c:78");
}

original_code:
void net_node_free(struct net_node_t *node)
{
 int i;
 for (i = 0; i < list_count(node->input_buffer_list); i++)
  net_buffer_free(list_get(node->input_buffer_list, i));
 list_free(node->input_buffer_list);
 for (i = 0; i < list_count(node->output_buffer_list); i++)
  net_buffer_free(list_get(node->output_buffer_list, i));
 list_free(node->output_buffer_list);
 (mhandle_free(node->name, "node.c" ":" "77"));
 (mhandle_free(node, "node.c" ":" "78"));
}

user_defined_types: enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 }

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

user_defined_types: 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; }

user_defined_types: struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; }