decompiled_code:
void __fastcall heap_time_policy(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 24) = a2;
*(_DWORD *)(a1 + 12) = 0;
}

original_code:
void heap_time_policy(struct heap_t *heap, enum heap_time_policy_enum policy)
{
 heap->time_policy = policy;
 heap->error = 0;
}

variable_types: enum heap_time_policy_enum { heap_time_policy_fifo=0, heap_time_policy_lifo=1 }


original_code:
long long heap_first(struct heap_t *heap, void **data)
{
 if (!heap->count) {
  heap->error = 3;
  if (data)
   *data = ((void *)0);
  return 0;
 }
 heap->current = 0;
 heap->error = 0;
 if (data)
  *data = heap->elem[0].data;
 return heap->elem[0].value;
}

variable_types: struct heap_t { int size; int error; long long time; enum heap_time_policy_enum { heap_time_policy_fifo=0, heap_time_policy_lifo=1 } time_policy; struct heap_elem_t { long long time; void *data; } *elem; } *

variable_types:
data
void **

return_type: long long

user_defined_types: struct heap_t { int size; int error; long long time; enum heap_time_policy_enum time_policy; struct heap_elem_t *elem; }


original_code:
long long heap_next(struct heap_t *heap, void **data)
{
 if (heap->current >= heap->count - 1) {
  heap->error = 3;
  if (data)
   *data = ((void *)0);
  return 0;
 }
 heap->current++;
 heap->error = 0;
 if (data)
  *data = heap->elem[heap->current].data;
 return heap->elem[heap->current].value;
}

user_defined_types: enum heap_time_policy_enum { heap_time_policy_fifo=0, heap_time_policy_lifo=1 }

user_defined_types: struct heap_elem_t { long long time; void *data; }


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

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

original_code:
void evg_opencl_event_free(struct evg_opencl_event_t *event)
{
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, event);
 (mhandle_free(event, "opencl-event.c" ":" "53"));
}

variable_types: struct evg_opencl_event_t { unsigned int id; int ref_count; enum evg_opencl_event_kind_t { EVG_OPENCL_EVENT_NONE=0, EVG_OPENCL_EVENT_NDRANGE_KERNEL=1, EVG_OPENCL_EVENT_TASK=2, EVG_OPENCL_EVENT_NATIVE_KERNEL=3, EVG_OPENCL_EVENT_READ_BUFFER=4, EVG_OPENCL_EVENT_WRITE_BUFFER=5, EVG_OPENCL_EVENT_MAP_BUFFER=6, EVG_OPENCL_EVENT_UNMAP_MEM_OBJECT=7, EVG_OPENCL_EVENT_READ_BUFFER_RECT=8, EVG_OPENCL_EVENT_WRITE_BUFFER_RECT=9, EVG_OPENCL_EVENT_READ_IMAGE=10, EVG_OPENCL_EVENT_WRITE_IMAGE=11, EVG_OPENCL_EVENT_MAP_IMAGE=12, EVG_OPENCL_EVENT_COPY_BUFFER=13, EVG_OPENCL_EVENT_COPY_IMAGE=14, EVG_OPENCL_EVENT_COPY_BUFFER_RECT=15, EVG_OPENCL_EVENT_COPY_BUFFER_TO_IMAGE=16, EVG_OPENCL_EVENT_COPY_IMAGE_TO_BUFFER=17, EVG_OPENCL_EVENT_MARKER=18, EVG_OPENCL_EVENT_COUNT=19 } kind; enum evg_opencl_event_status_t { EVG_OPENCL_EVENT_STATUS_NONE=0, EVG_OPENCL_EVENT_STATUS_QUEUED=1, EVG_OPENCL_EVENT_STATUS_SUBMITTED=2, EVG_OPENCL_EVENT_STATUS_RUNNING=3, EVG_OPENCL_EVENT_STATUS_COMPLETE=4 } status; long long time_queued; long long time_submit; long long time_start; long long time_end; } *

return_type: void

user_defined_types: struct evg_opencl_event_t { unsigned int id; int ref_count; enum evg_opencl_event_kind_t kind; enum evg_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 evg_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_9;
}
if ( a2 > 0x1282 )
{
if ( a2 == 4739 )
{
v6 = a1 + 40;
goto LABEL_9;
}
LABEL_14:
fatal(
"%s: invalid or not implemented value for 'name' (0x%x)\n%s",
"evg_opencl_event_get_profiling_info",
a2,
evg_err_opencl_param_note);
_assert_fail("info", "opencl-event.c", 0x5Cu, "evg_opencl_event_get_profiling_info");
}
if ( a2 == 4736 )
{
v6 = a1 + 16;
goto LABEL_9;
}
if ( a2 != 4737 )
goto LABEL_14;
v6 = a1 + 24;
LABEL_9:
if ( a4 && a5 > 7 )
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_9;
}
if ( a2 > 0x1282 )
{
if ( a2 == 4739 )
{
v6 = a1 + 40;
goto LABEL_9;
}
LABEL_14:
fatal(
"%s: invalid or not implemented value for 'name' (0x%x)\n%s",
"evg_opencl_event_get_profiling_info",
a2,
evg_err_opencl_param_note);
_assert_fail("info", "opencl-event.c", 0x5Cu, "evg_opencl_event_get_profiling_info");
}
if ( a2 == 4736 )
{
v6 = a1 + 16;
goto LABEL_9;
}
if ( a2 != 4737 )
goto LABEL_14;
v6 = a1 + 24;
LABEL_9:
if ( a4 && a5 > 7 )
mem_write(a3, a4, 8LL, v6);
return 8LL;
}

original_code:
uint32_t evg_opencl_event_get_profiling_info(struct evg_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, evg_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 evg_opencl_event_get_profiling_info(struct evg_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, evg_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 evg_opencl_event_kind_t { EVG_OPENCL_EVENT_NONE=0, EVG_OPENCL_EVENT_NDRANGE_KERNEL=1, EVG_OPENCL_EVENT_TASK=2, EVG_OPENCL_EVENT_NATIVE_KERNEL=3, EVG_OPENCL_EVENT_READ_BUFFER=4, EVG_OPENCL_EVENT_WRITE_BUFFER=5, EVG_OPENCL_EVENT_MAP_BUFFER=6, EVG_OPENCL_EVENT_UNMAP_MEM_OBJECT=7, EVG_OPENCL_EVENT_READ_BUFFER_RECT=8, EVG_OPENCL_EVENT_WRITE_BUFFER_RECT=9, EVG_OPENCL_EVENT_READ_IMAGE=10, EVG_OPENCL_EVENT_WRITE_IMAGE=11, EVG_OPENCL_EVENT_MAP_IMAGE=12, EVG_OPENCL_EVENT_COPY_BUFFER=13, EVG_OPENCL_EVENT_COPY_IMAGE=14, EVG_OPENCL_EVENT_COPY_BUFFER_RECT=15, EVG_OPENCL_EVENT_COPY_BUFFER_TO_IMAGE=16, EVG_OPENCL_EVENT_COPY_IMAGE_TO_BUFFER=17, EVG_OPENCL_EVENT_MARKER=18, EVG_OPENCL_EVENT_COUNT=19 }

user_defined_types: enum evg_opencl_event_status_t { EVG_OPENCL_EVENT_STATUS_NONE=0, EVG_OPENCL_EVENT_STATUS_QUEUED=1, EVG_OPENCL_EVENT_STATUS_SUBMITTED=2, EVG_OPENCL_EVENT_STATUS_RUNNING=3, EVG_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 evg_opencl_event_timer()
{
return 1000 * esim_real_time();
}

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

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

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


decompiled_code:
_QWORD *evg_opencl_repo_create()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)mhandle_calloc(1LL, 8LL, "opencl-repo.c:40");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_repo_create");
*v0 = linked_list_create();
return v0;
}

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

v0 = (_QWORD *)mhandle_calloc(1LL, 8LL, "opencl-repo.c:40");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_repo_create");
*v0 = linked_list_create();
return v0;
}

original_code:
struct evg_opencl_repo_t *evg_opencl_repo_create(void)
{
 struct evg_opencl_repo_t *repo;
 repo = (mhandle_calloc(1, sizeof(struct evg_opencl_repo_t), "opencl-repo.c" ":" "40"));
 if (!repo)
  fatal("%s: out of memory", __FUNCTION__);
 repo->object_list = linked_list_create();
 return repo;
}

canonical_original_code:
struct evg_opencl_repo_t *evg_opencl_repo_create()
{
 struct evg_opencl_repo_t *repo;
 repo = (mhandle_calloc(1, sizeof(struct evg_opencl_repo_t), "opencl-repo.c" ":" "40"));
 if (!repo)
  fatal("%s: out of memory", __FUNCTION__);
 repo->object_list = linked_list_create();
 return repo;
}

variable_types: struct evg_opencl_repo_t { 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; } *object_list; } *

user_defined_types: struct evg_opencl_repo_t { struct linked_list_t *object_list; }

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 evg_opencl_repo_free(_QWORD *a1)
{
linked_list_free(*a1);
return mhandle_free(a1, "opencl-repo.c:55");
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
linked_list_free(*a1);
return mhandle_free(a1, "opencl-repo.c:55");
}

original_code:
void evg_opencl_repo_free(struct evg_opencl_repo_t *repo)
{
 linked_list_free(repo->object_list);
 (mhandle_free(repo, "opencl-repo.c" ":" "55"));
}

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


decompiled_code:
__int64 __fastcall evg_opencl_repo_add_object(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp

v2 = *a1;
linked_list_find(*a1);
if ( !*(_DWORD *)(v2 + 4) )
fatal("%s: object already exists", "evg_opencl_repo_add_object");
return linked_list_add(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp

v2 = *a1;
linked_list_find(*a1);
if ( !*(_DWORD *)(v2 + 4) )
fatal("%s: object already exists", "evg_opencl_repo_add_object");
return linked_list_add(v2, a2);
}

original_code:
void evg_opencl_repo_add_object(struct evg_opencl_repo_t *repo,
 void *object)
{
 struct linked_list_t *object_list = repo->object_list;
 linked_list_find(object_list, object);
 if (!object_list->error_code)
  fatal("%s: object already exists", __FUNCTION__);
 linked_list_add(object_list, object);
}

variable_types:
object
void *

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


decompiled_code:
__int64 __fastcall evg_opencl_repo_remove_object(_QWORD *a1)
{
__int64 v1; // rbx

v1 = *a1;
linked_list_find(*a1);
if ( *(_DWORD *)(v1 + 4) )
fatal("%s: object does not exist", "evg_opencl_repo_remove_object");
return linked_list_remove(v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rbx

v1 = *a1;
linked_list_find(*a1);
if ( *(_DWORD *)(v1 + 4) )
fatal("%s: object does not exist", "evg_opencl_repo_remove_object");
return linked_list_remove(v1);
}

original_code:
void evg_opencl_repo_remove_object(struct evg_opencl_repo_t *repo,
 void *object)
{
 struct linked_list_t *object_list = repo->object_list;
 linked_list_find(object_list, object);
 if (object_list->error_code)
  fatal("%s: object does not exist", __FUNCTION__);
 linked_list_remove(object_list);
}


decompiled_code:
__int64 __fastcall evg_opencl_repo_new_object_id(__int64 a1, int a2)
{
unsigned int v2; // ebx

v2 = evg_opencl_object_id_counter_2++ | (a2 << 16);
if ( (unsigned int)evg_opencl_object_id_counter_2 > 0xFFFF )
fatal("%s: limit of OpenCL objects exceeded\n", "evg_opencl_repo_new_object_id");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
unsigned int v2; // ebx

v2 = evg_opencl_object_id_counter_2++ | (a2 << 16);
if ( (unsigned int)evg_opencl_object_id_counter_2 > 0xFFFF )
fatal("%s: limit of OpenCL objects exceeded\n", "evg_opencl_repo_new_object_id");
return v2;
}

original_code:
unsigned int evg_opencl_repo_new_object_id(struct evg_opencl_repo_t *repo,
 enum evg_opencl_object_type_t type)
{
 static unsigned int evg_opencl_object_id_counter;
 unsigned int object_id;
 object_id = (type << 16) | evg_opencl_object_id_counter;
 evg_opencl_object_id_counter++;
 if (evg_opencl_object_id_counter > 0xffff)
  fatal("%s: limit of OpenCL objects exceeded\n", __FUNCTION__);
 return object_id;
}

variable_types: enum evg_opencl_object_type_t { evg_opencl_object_invalid=0, evg_opencl_object_platform=1, evg_opencl_object_device=2, evg_opencl_object_context=3, evg_opencl_object_command_queue=4, evg_opencl_object_program=5, evg_opencl_object_kernel=6, evg_opencl_object_mem=7, evg_opencl_object_event=8, evg_opencl_object_sampler=9 }


decompiled_code:
__int64 evg_opencl_command_queue_create()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 32LL, "opencl-command-queue.c:36");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_command_queue_create");
*(_DWORD *)v0 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 4LL);
*(_DWORD *)(v0 + 4) = 1;
*(_QWORD *)(v0 + 24) = linked_list_create();
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 32LL, "opencl-command-queue.c:36");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_command_queue_create");
*(_DWORD *)v0 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 4LL);
*(_DWORD *)(v0 + 4) = 1;
*(_QWORD *)(v0 + 24) = linked_list_create();
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

original_code:
struct evg_opencl_command_queue_t *evg_opencl_command_queue_create()
{
 struct evg_opencl_command_queue_t *command_queue;
 command_queue = (mhandle_calloc(1, sizeof(struct evg_opencl_command_queue_t), "opencl-command-queue.c" ":" "36"));
 if (!command_queue)
  fatal("%s: out of memory", __FUNCTION__);
 command_queue->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo,
  evg_opencl_object_command_queue);
 command_queue->ref_count = 1;
 command_queue->command_list = linked_list_create();
 evg_opencl_repo_add_object(evg_emu->opencl_repo, command_queue);
 return command_queue;
}

variable_types: struct evg_opencl_command_queue_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; unsigned int properties; 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; } *command_list; } *

user_defined_types: struct evg_opencl_command_queue_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; unsigned int properties; struct linked_list_t *command_list; }


decompiled_code:
__int64 __fastcall evg_opencl_command_queue_free(__int64 a1)
{
if ( (unsigned int)linked_list_count(*(_QWORD *)(a1 + 24)) )
fatal("%s: freed command queue is not empty", "evg_opencl_command_queue_free");
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
linked_list_free(*(_QWORD *)(a1 + 24));
return mhandle_free(a1, "opencl-command-queue.c:62");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( (unsigned int)linked_list_count(*(_QWORD *)(a1 + 24)) )
fatal("%s: freed command queue is not empty", "evg_opencl_command_queue_free");
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
linked_list_free(*(_QWORD *)(a1 + 24));
return mhandle_free(a1, "opencl-command-queue.c:62");
}

original_code:
void evg_opencl_command_queue_free(struct evg_opencl_command_queue_t *command_queue)
{
 if (linked_list_count(command_queue->command_list))
  fatal("%s: freed command queue is not empty", __FUNCTION__);
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, command_queue);
 linked_list_free(command_queue->command_list);
 (mhandle_free(command_queue, "opencl-command-queue.c" ":" "62"));
}


decompiled_code:
__int64 __fastcall x86_cpu_dispatch_core(int a1)
{
int v1; // ebx
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // r13
_QWORD *v5; // rcx
__int64 v6; // r13
_QWORD *v7; // rsi

v1 = x86_cpu_num_threads;
v2 = x86_cpu_dispatch_width;
result = x86_cpu_dispatch_kind;
if ( x86_cpu_dispatch_kind )
{
if ( x86_cpu_dispatch_kind == 1 )
{
v6 = 1824LL * a1;
do
{
v7 = (_QWORD *)x86_cpu;
*(_DWORD *)(*x86_cpu + v6 + 100) = (*(_DWORD *)(*x86_cpu + v6 + 100) + 1) % x86_cpu_num_threads;
--v1;
}
while ( v1 && (unsigned int)x86_cpu_can_dispatch_thread(a1, *(_DWORD *)(*v7 + v6 + 100)) );
result = x86_cpu_dispatch_thread(a1, *(_DWORD *)(*x86_cpu + v6 + 100), v2);
}
}
else
{
v4 = 1824LL * a1;
do
{
v5 = (_QWORD *)x86_cpu;
*(_DWORD *)(*x86_cpu + v4 + 100) = (*(_DWORD *)(*x86_cpu + v4 + 100) + 1) % x86_cpu_num_threads;
result = x86_cpu_dispatch_thread(a1, *(_DWORD *)(*v5 + v4 + 100), 1u);
--v1;
if ( !(_DWORD)result )
{
v1 = x86_cpu_num_threads;
--v2;
}
}
while ( v2 && v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // ebx
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // r13
_QWORD *v5; // rcx
__int64 v6; // r13
_QWORD *v7; // rsi

v1 = x86_cpu_num_threads;
v2 = x86_cpu_dispatch_width;
result = x86_cpu_dispatch_kind;
if ( x86_cpu_dispatch_kind )
{
if ( x86_cpu_dispatch_kind == 1 )
{
v6 = 1824LL * a1;
do
{
v7 = (_QWORD *)x86_cpu;
*(_DWORD *)(*x86_cpu + v6 + 100) = (*(_DWORD *)(*x86_cpu + v6 + 100) + 1) % x86_cpu_num_threads;
--v1;
}
while ( v1 && (unsigned int)func0(a1, *(_DWORD *)(*v7 + v6 + 100)) );
result = func1(a1, *(_DWORD *)(*x86_cpu + v6 + 100), v2);
}
}
else
{
v4 = 1824LL * a1;
do
{
v5 = (_QWORD *)x86_cpu;
*(_DWORD *)(*x86_cpu + v4 + 100) = (*(_DWORD *)(*x86_cpu + v4 + 100) + 1) % x86_cpu_num_threads;
result = func1(a1, *(_DWORD *)(*v5 + v4 + 100), 1u);
--v1;
if ( !(_DWORD)result )
{
v1 = x86_cpu_num_threads;
--v2;
}
}
while ( v2 && v1 );
}
return result;
}

original_code:
static void x86_cpu_dispatch_core(int core)
{
 int skip = x86_cpu_num_threads;
 int quant = x86_cpu_dispatch_width;
 int remain;
 switch (x86_cpu_dispatch_kind)
 {
 case x86_cpu_dispatch_kind_shared:
  do {
   (x86_cpu->core[core]).dispatch_current = ((x86_cpu->core[core]).dispatch_current + 1) % x86_cpu_num_threads;
   remain = x86_cpu_dispatch_thread(core, (x86_cpu->core[core]).dispatch_current, 1);
   skip = remain ? skip - 1 : x86_cpu_num_threads;
   quant = remain ? quant : quant - 1;
  } while (quant && skip);
  break;
 case x86_cpu_dispatch_kind_timeslice:
  do {
   (x86_cpu->core[core]).dispatch_current = ((x86_cpu->core[core]).dispatch_current + 1) % x86_cpu_num_threads;
   skip--;
  } while (skip && x86_cpu_can_dispatch_thread(core, (x86_cpu->core[core]).dispatch_current) != x86_dispatch_stall_used);
  x86_cpu_dispatch_thread(core, (x86_cpu->core[core]).dispatch_current, quant);
  break;
 }
}

variable_types: core int

variable_types: skip int

variable_types: quant int

variable_types: remain int


decompiled_code:
__int64 x86_cpu_dispatch()
{
__int64 result; // rax
int v1; // ebx

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

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int v1; // ebx

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

original_code:
void x86_cpu_dispatch()
{
 int core;
 x86_cpu->stage = "dispatch";
 for (core = 0; core < x86_cpu_num_cores; core++)
  x86_cpu_dispatch_core(core);
}


decompiled_code:
__int64 __fastcall dir_free(_QWORD *a1)
{
mhandle_free(*a1, "directory.c:88");
mhandle_free(a1[3], "directory.c:89");
return mhandle_free(a1, "directory.c:90");
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
mhandle_free(*a1, "directory.c:88");
mhandle_free(a1[3], "directory.c:89");
return mhandle_free(a1, "directory.c:90");
}

original_code:
void dir_free(struct dir_t *dir)
{
 (mhandle_free(dir->name, "directory.c" ":" "88"));
 (mhandle_free(dir->dir_lock, "directory.c" ":" "89"));
 (mhandle_free(dir, "directory.c" ":" "90"));
}

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

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

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_get(_DWORD *a1, int a2, int a3, int a4)
{
int v4; // er8
int v5; // er9
__int64 v6; // rcx
int v7; // eax
int v8; // edx
int v9; // eax

if ( a2 < 0 || a1[3] <= a2 )
_assert_fail("IN_RANGE(x, 0, dir->xsize - 1)", "directory.c", 0x60u, "dir_entry_get");
if ( a3 < 0 || (v4 = a1[4], v4 <= a3) )
_assert_fail("IN_RANGE(y, 0, dir->ysize - 1)", "directory.c", 0x61u, "dir_entry_get");
if ( a4 < 0 || (v5 = a1[5], v5 <= a4) )
_assert_fail("IN_RANGE(z, 0, dir->zsize - 1)", "directory.c", 0x62u, "dir_entry_get");
v6 = a4 + v5 * (a3 + v4 * a2);
v7 = a1[2];
v8 = v7 + 14;
v9 = v7 + 7;
if ( v9 < 0 )
v9 = v8;
return (__int64)a1 + ((v9 >> 3) + 8) * v6 + 32;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int a2, int a3, int a4)
{
int v4; // er8
int v5; // er9
__int64 v6; // rcx
int v7; // eax
int v8; // edx
int v9; // eax

if ( a2 < 0 || a1[3] <= a2 )
_assert_fail("IN_RANGE(x, 0, dir->xsize - 1)", "directory.c", 0x60u, "dir_entry_get");
if ( a3 < 0 || (v4 = a1[4], v4 <= a3) )
_assert_fail("IN_RANGE(y, 0, dir->ysize - 1)", "directory.c", 0x61u, "dir_entry_get");
if ( a4 < 0 || (v5 = a1[5], v5 <= a4) )
_assert_fail("IN_RANGE(z, 0, dir->zsize - 1)", "directory.c", 0x62u, "dir_entry_get");
v6 = a4 + v5 * (a3 + v4 * a2);
v7 = a1[2];
v8 = v7 + 14;
v9 = v7 + 7;
if ( v9 < 0 )
v9 = v8;
return (__int64)a1 + ((v9 >> 3) + 8) * v6 + 32;
}

original_code:
struct dir_entry_t *dir_entry_get(struct dir_t *dir, int x, int y, int z)
{
 ((void) sizeof ((((x)>=(0)&&(x)<=(dir->xsize - 1))) ? 1 : 0), __extension__ ({ if (((x)>=(0)&&(x)<=(dir->xsize - 1))) ; else __assert_fail ("IN_RANGE(x, 0, dir->xsize - 1)", "directory.c", 96, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((((y)>=(0)&&(y)<=(dir->ysize - 1))) ? 1 : 0), __extension__ ({ if (((y)>=(0)&&(y)<=(dir->ysize - 1))) ; else __assert_fail ("IN_RANGE(y, 0, dir->ysize - 1)", "directory.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((((z)>=(0)&&(z)<=(dir->zsize - 1))) ? 1 : 0), __extension__ ({ if (((z)>=(0)&&(z)<=(dir->zsize - 1))) ; else __assert_fail ("IN_RANGE(z, 0, dir->zsize - 1)", "directory.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 return ((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))));
}

variable_types: x int

variable_types: y int

variable_types: z int

return_type: 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 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:
struct dir_t *dir_create(char *name, int xsize, int ysize, int zsize, int num_nodes)
{
 struct dir_t *dir;
 struct dir_entry_t *dir_entry;
 int dir_size;
 int dir_entry_size;
 int x;
 int y;
 int z;
 ((void) sizeof ((num_nodes > 0) ? 1 : 0), __extension__ ({ if (num_nodes > 0) ; else __assert_fail ("num_nodes > 0", "directory.c", 43, __extension__ __PRETTY_FUNCTION__); }));
 dir_entry_size = sizeof(struct dir_entry_t) + (num_nodes + 7) / 8;
 dir_size = sizeof(struct dir_t) + dir_entry_size * xsize * ysize * zsize;
 dir = (mhandle_calloc(1, dir_size, "directory.c" ":" "48"));
 if (!dir)
  fatal("%s: out of memory", __FUNCTION__);
 dir->name = (mhandle_strdup(name, "directory.c" ":" "53"));
 if (!dir->name)
  fatal("%s: out of memory", __FUNCTION__);
 dir->dir_lock = (mhandle_calloc(xsize * ysize, sizeof(struct dir_lock_t), "directory.c" ":" "58"));
 if (!dir->dir_lock)
  fatal("%s: out of memory", __FUNCTION__);
 dir->num_nodes = num_nodes;
 dir->xsize = xsize;
 dir->ysize = ysize;
 dir->zsize = zsize;
 for (x = 0; x < xsize; x++)
 {
  for (y = 0; y < ysize; y++)
  {
   for (z = 0; z < zsize; z++)
   {
    dir_entry = dir_entry_get(dir, x, y, z);
    dir_entry->owner = (-1);
   }
  }
 }
 return dir;
}

variable_types:
name
char *

variable_types: xsize int

variable_types: ysize int

variable_types: zsize int

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

return_type: 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[]; } *

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_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_entry_set_sharer(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
__int64 v8; // r14
__int64 v9; // rbx
__int64 v10; // rdx
__int64 result; // rax
unsigned __int8 v12; // di
int v13; // esi

if ( a5 < 0 || (v8 = a4, v9 = (unsigned int)a5, *((_DWORD *)a1 + 2) <= a5) )
_assert_fail("IN_RANGE(node, 0, dir->num_nodes - 1)", "directory.c", 0x89u, "dir_entry_set_sharer");
v10 = dir_entry_get(a1, a2, a3, a4);
result = (unsigned int)((int)v9 >> 3);
v12 = *(_BYTE *)(v10 + (int)result + 8);
v13 = v12;
if ( !_bittest(&v13, (int)v9 % 8) )
{
*(_BYTE *)(v10 + (int)result + 8) = (1 << ((int)v9 % 8)) | v12;
result = (unsigned int)(*(_DWORD *)(v10 + 4) + 1);
*(_DWORD *)(v10 + 4) = result;
if ( (int)result > *((_DWORD *)a1 + 2) )
_assert_fail("dir_entry->num_sharers <= dir->num_nodes", "directory.c", 0x91u, "dir_entry_set_sharer");
if ( mem_trace_category )
result = _trace(
mem_trace_category,
1LL,
"mem.set_sharer dir=\"%s\" x=%d y=%d z=%d sharer=%d\n",
*a1,
a2,
a3,
v8,
v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
__int64 v8; // r14
__int64 v9; // rbx
__int64 v10; // rdx
__int64 result; // rax
unsigned __int8 v12; // di
int v13; // esi

if ( a5 < 0 || (v8 = a4, v9 = (unsigned int)a5, *((_DWORD *)a1 + 2) <= a5) )
_assert_fail("IN_RANGE(node, 0, dir->num_nodes - 1)", "directory.c", 0x89u, "dir_entry_set_sharer");
v10 = func1(a1, a2, a3, a4);
result = (unsigned int)((int)v9 >> 3);
v12 = *(_BYTE *)(v10 + (int)result + 8);
v13 = v12;
if ( !_bittest(&v13, (int)v9 % 8) )
{
*(_BYTE *)(v10 + (int)result + 8) = (1 << ((int)v9 % 8)) | v12;
result = (unsigned int)(*(_DWORD *)(v10 + 4) + 1);
*(_DWORD *)(v10 + 4) = result;
if ( (int)result > *((_DWORD *)a1 + 2) )
_assert_fail("dir_entry->num_sharers <= dir->num_nodes", "directory.c", 0x91u, "dir_entry_set_sharer");
if ( mem_trace_category )
result = _trace(
mem_trace_category,
1LL,
"mem.set_sharer dir=\"%s\" x=%d y=%d z=%d sharer=%d\n",
*a1,
a2,
a3,
v8,
v9);
}
return result;
}

original_code:
void dir_entry_set_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", 137, __extension__ __PRETTY_FUNCTION__); }));
 dir_entry = dir_entry_get(dir, x, y, z);
 if (dir_entry->sharer[node / 8] & (1 << (node % 8)))
  return;
 dir_entry->sharer[node / 8] |= 1 << (node % 8);
 dir_entry->num_sharers++;
 ((void) sizeof ((dir_entry->num_sharers <= dir->num_nodes) ? 1 : 0), __extension__ ({ if (dir_entry->num_sharers <= dir->num_nodes) ; else __assert_fail ("dir_entry->num_sharers <= dir->num_nodes", "directory.c", 145, __extension__ __PRETTY_FUNCTION__); }));
 ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.set_sharer dir=\"%s\" x=%d y=%d z=%d sharer=%d\n", dir->name, x, y, z, node) : (void) 0);
}

variable_types: node 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 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: 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_clear_sharer(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v8; // r14
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rdx
__int64 result; // rax
unsigned __int8 v13; // di
int v14; // esi
int v15; // eax

v8 = a4;
v9 = a5;
v10 = dir_entry_get(a1, a2, a3, a4);
if ( (int)v9 < 0 || (v11 = v10, *((_DWORD *)a1 + 2) <= (int)v9) )
_assert_fail("IN_RANGE(node, 0, dir->num_nodes - 1)", "directory.c", 0x9Fu, "dir_entry_clear_sharer");
result = (unsigned int)((int)v9 >> 3);
v13 = *(_BYTE *)(v11 + (int)result + 8);
v14 = v13;
if ( _bittest(&v14, (int)v9 % 8) )
{
*(_BYTE *)(v11 + (int)result + 8) = __ROL4__(-2, (int)v9 % 8) & v13;
v15 = *(_DWORD *)(v11 + 4);
if ( v15 <= 0 )
_assert_fail("dir_entry->num_sharers > 0", "directory.c", 0xA5u, "dir_entry_clear_sharer");
result = (unsigned int)(v15 - 1);
*(_DWORD *)(v11 + 4) = result;
if ( mem_trace_category )
result = _trace(
mem_trace_category,
1LL,
"mem.clear_sharer dir=\"%s\" x=%d y=%d z=%d sharer=%d\n",
*a1,
a2,
a3,
v8,
v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v8; // r14
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rdx
__int64 result; // rax
unsigned __int8 v13; // di
int v14; // esi
int v15; // eax

v8 = a4;
v9 = a5;
v10 = func1(a1, a2, a3, a4);
if ( (int)v9 < 0 || (v11 = v10, *((_DWORD *)a1 + 2) <= (int)v9) )
_assert_fail("IN_RANGE(node, 0, dir->num_nodes - 1)", "directory.c", 0x9Fu, "dir_entry_clear_sharer");
result = (unsigned int)((int)v9 >> 3);
v13 = *(_BYTE *)(v11 + (int)result + 8);
v14 = v13;
if ( _bittest(&v14, (int)v9 % 8) )
{
*(_BYTE *)(v11 + (int)result + 8) = __ROL4__(-2, (int)v9 % 8) & v13;
v15 = *(_DWORD *)(v11 + 4);
if ( v15 <= 0 )
_assert_fail("dir_entry->num_sharers > 0", "directory.c", 0xA5u, "dir_entry_clear_sharer");
result = (unsigned int)(v15 - 1);
*(_DWORD *)(v11 + 4) = result;
if ( mem_trace_category )
result = _trace(
mem_trace_category,
1LL,
"mem.clear_sharer dir=\"%s\" x=%d y=%d z=%d sharer=%d\n",
*a1,
a2,
a3,
v8,
v9);
}
return result;
}

original_code:
void dir_entry_clear_sharer(struct dir_t *dir, int x, int y, int z, int node)
{
 struct dir_entry_t *dir_entry;
 dir_entry = dir_entry_get(dir, x, y, z);
 ((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", 159, __extension__ __PRETTY_FUNCTION__); }));
 if (!(dir_entry->sharer[node / 8] & (1 << (node % 8))))
  return;
 dir_entry->sharer[node / 8] &= ~(1 << (node % 8));
 ((void) sizeof ((dir_entry->num_sharers > 0) ? 1 : 0), __extension__ ({ if (dir_entry->num_sharers > 0) ; else __assert_fail ("dir_entry->num_sharers > 0", "directory.c", 165, __extension__ __PRETTY_FUNCTION__); }));
 dir_entry->num_sharers--;
 ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.clear_sharer dir=\"%s\" x=%d y=%d z=%d sharer=%d\n", dir->name, x, y, z, node) : (void) 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: 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: 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 dir_entry_clear_all_sharers(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // r13
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rcx
int v10; // eax
int v11; // edx
int v12; // eax

v6 = a4;
result = dir_entry_get(a1, a2, a3, a4);
*(_DWORD *)(result + 4) = 0;
if ( *((int *)a1 + 2) > 0 )
{
v8 = result;
v9 = 0LL;
do
{
*(_BYTE *)(v8 + v9++ + 8) = 0;
v10 = *((_DWORD *)a1 + 2);
v11 = v10 + 14;
v12 = v10 + 7;
if ( v12 < 0 )
v12 = v11;
result = (unsigned int)(v12 >> 3);
}
while ( (int)result > (int)v9 );
}
if ( mem_trace_category )
result = _trace(mem_trace_category, 1LL, "mem.clear_all_sharers dir=\"%s\" x=%d y=%d z=%d\n", *a1, a2, a3, v6);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // r13
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rcx
int v10; // eax
int v11; // edx
int v12; // eax

v6 = a4;
result = func1(a1, a2, a3, a4);
*(_DWORD *)(result + 4) = 0;
if ( *((int *)a1 + 2) > 0 )
{
v8 = result;
v9 = 0LL;
do
{
*(_BYTE *)(v8 + v9++ + 8) = 0;
v10 = *((_DWORD *)a1 + 2);
v11 = v10 + 14;
v12 = v10 + 7;
if ( v12 < 0 )
v12 = v11;
result = (unsigned int)(v12 >> 3);
}
while ( (int)result > (int)v9 );
}
if ( mem_trace_category )
result = _trace(mem_trace_category, 1LL, "mem.clear_all_sharers dir=\"%s\" x=%d y=%d z=%d\n", *a1, a2, a3, v6);
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 % 8)) & *(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 % 8)) & *(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;
}

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 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: 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: 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_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 result; // rax
int v7; // ebx

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

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

result = func1(a1, a2, a3, a4);
if ( !mem_debug_category )
{
if ( (int)a1[2] <= 0 )
return result;
goto LABEL_3;
}
result = _debug(mem_debug_category, " %d sharers: { ", *(unsigned int *)(result + 4));
if ( (int)a1[2] > 0 )
{
LABEL_3:
v7 = 0;
do
{
result = func6(a1, a2, a3, a4, v7);
if ( (_DWORD)result && mem_debug_category )
result = _debug(mem_debug_category, "%d ", (unsigned int)v7);
++v7;
}
while ( a1[2] > v7 );
}
if ( mem_debug_category )
result = _debug(mem_debug_category, "}\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);
}

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_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: 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: 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_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: enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 }

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
__int64 v5; // rbx

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 = *(_QWORD *)(a1 + 24) + 24LL * (a3 + a2 * v4);
if ( mem_debug_category )
_debug(mem_debug_category, " %lld dir_lock retrieve\n", esim_cycle);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // edx
__int64 v5; // rbx

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 = *(_QWORD *)(a1 + 24) + 24LL * (a3 + a2 * v4);
if ( mem_debug_category )
_debug(mem_debug_category, " %lld dir_lock retrieve\n", esim_cycle);
return v5;
}

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