decompiled_code:
__int64 __fastcall amd_opengl_shader_set_isa_buffer(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // ebx
__int64 v4; // rdx
__int64 result; // rax

v1 = 0;
if ( *(_QWORD *)(a1 + 16) )
{
while ( (int)list_count(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL)) > v1 )
{
v2 = list_get(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL), (unsigned int)v1);
if ( !strcmp(*(const char **)v2, ".text") )
{
v3 = get_isa_offset((int *)a1);
elf_buffer_seek(*(_QWORD *)(a1 + 16) + 8LL, *(unsigned int *)(*(_QWORD *)(v2 + 8) + 16LL));
v4 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(v4 + 8) + v3 + (__int64)*(int *)(v4 + 20);
*(_DWORD *)(a1 + 32) = *(_DWORD *)(v4 + 16) - v3;
*(_DWORD *)(a1 + 36) = 0;
return 1LL;
}
++v1;
}
result = 0LL;
}
else
{
fatal("No internal ELF for this shader!");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // ebx
__int64 v4; // rdx
__int64 result; // rax

v1 = 0;
if ( *(_QWORD *)(a1 + 16) )
{
while ( (int)list_count(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL)) > v1 )
{
v2 = list_get(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL), (unsigned int)v1);
if ( !strcmp(*(const char **)v2, ".text") )
{
v3 = func0((int *)a1);
elf_buffer_seek(*(_QWORD *)(a1 + 16) + 8LL, *(unsigned int *)(*(_QWORD *)(v2 + 8) + 16LL));
v4 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(v4 + 8) + v3 + (__int64)*(int *)(v4 + 20);
*(_DWORD *)(a1 + 32) = *(_DWORD *)(v4 + 16) - v3;
*(_DWORD *)(a1 + 36) = 0;
return 1LL;
}
++v1;
}
result = 0LL;
}
else
{
fatal("No internal ELF for this shader!");
result = 0LL;
}
return result;
}

original_code:
static int amd_opengl_shader_set_isa_buffer(struct evg_opengl_shader_t *opengl_shader)
{
 struct elf_section_t *internal_section;
 int isa_offset;
 int i;
 if (!&opengl_shader->isa_buffer)
  fatal("%s: shader error", __FUNCTION__);
  if (opengl_shader->internal_elf_file)
  {
   for (i = 0; i < list_count(opengl_shader->internal_elf_file->section_list); i++)
   {
    internal_section = list_get(opengl_shader->internal_elf_file->section_list, i);
    if (!strcmp(internal_section->name,".text"))
    {
     isa_offset = get_isa_offset(opengl_shader);
     elf_buffer_seek(&opengl_shader->internal_elf_file->buffer, internal_section->header->sh_offset);
     opengl_shader->isa_buffer.ptr = opengl_shader->internal_elf_file->buffer.ptr + opengl_shader->internal_elf_file->buffer.pos + isa_offset;
     opengl_shader->isa_buffer.size = opengl_shader->internal_elf_file->buffer.size - isa_offset;
     opengl_shader->isa_buffer.pos = 0;
     return 1;
    }
   }
  }
  else
   fatal("No internal ELF for this shader!");
  return 0;
}


decompiled_code:
__int64 __fastcall internal_elf_file_create(__int64 a1)
{
__int64 v1; // r13
int i; // ebp
const char **v3; // rbx
char *v4; // rbp
unsigned int v5; // eax

for ( i = 0; (int)list_count(*(_QWORD *)(a1 + 32)) > i; ++i )
{
v3 = (const char **)list_get(*(_QWORD *)(a1 + 32), (unsigned int)i);
if ( !strcmp(*v3, "binary") )
{
elf_buffer_seek(a1 + 8, *((unsigned int *)v3[1] + 4));
v4 = (char *)mhandle_calloc(1LL, *((unsigned int *)v3[1] + 5), "opengl-bin-file.c:203");
memcpy(v4, (const void *)(*(_QWORD *)(a1 + 8) + *(int *)(a1 + 20)), *((unsigned int *)v3[1] + 5));
v5 = (unsigned int)search_elf_magic(v4);
v1 = elf_file_create_from_buffer(&v4[v5 - (_DWORD)v4], *((_DWORD *)v3[1] + 5) - (v5 - (unsigned int)v4), *v3);
mhandle_free(v4, "opengl-bin-file.c:212");
return v1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // r13
int i; // ebp
const char **v3; // rbx
char *v4; // rbp
unsigned int v5; // eax

for ( i = 0; (int)list_count(*(_QWORD *)(a1 + 32)) > i; ++i )
{
v3 = (const char **)list_get(*(_QWORD *)(a1 + 32), (unsigned int)i);
if ( !strcmp(*v3, "binary") )
{
elf_buffer_seek(a1 + 8, *((unsigned int *)v3[1] + 4));
v4 = (char *)mhandle_calloc(1LL, *((unsigned int *)v3[1] + 5), "opengl-bin-file.c:203");
memcpy(v4, (const void *)(*(_QWORD *)(a1 + 8) + *(int *)(a1 + 20)), *((unsigned int *)v3[1] + 5));
v5 = (unsigned int)func3(v4);
v1 = elf_file_create_from_buffer(&v4[v5 - (_DWORD)v4], *((_DWORD *)v3[1] + 5) - (v5 - (unsigned int)v4), *v3);
mhandle_free(v4, "opengl-bin-file.c:212");
return v1;
}
}
return v1;
}

original_code:
static struct elf_file_t *internal_elf_file_create(struct elf_file_t *external_elf_file)
{
 struct elf_section_t *external_section;
 void *section_buf;
 struct elf_file_t *internal_elf_file;
 int internal_elf_offset;
 void *internal_elf_base;
 int internal_elf_size;
 int i;
 for (i = 0; i < list_count(external_elf_file->section_list); i++)
 {
  external_section = list_get(external_elf_file->section_list, i);
  if (!strcmp(external_section->name,"binary"))
  {
   elf_buffer_seek(&external_elf_file->buffer, external_section->header->sh_offset);
   section_buf = (mhandle_calloc(1, external_section->header->sh_size, "opengl-bin-file.c" ":" "203"));
   memcpy(section_buf, external_elf_file->buffer.ptr + external_elf_file->buffer.pos, external_section->header->sh_size);
   internal_elf_offset = (int)(search_elf_magic(section_buf) - section_buf);
   internal_elf_base = section_buf + internal_elf_offset;
   internal_elf_size = external_section->header->sh_size - internal_elf_offset;
   internal_elf_file = elf_file_create_from_buffer(internal_elf_base, internal_elf_size, external_section->name);
   (mhandle_free(section_buf, "opengl-bin-file.c" ":" "212"));
   break;
  }
 }
 return internal_elf_file;
}

variable_types: struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; } *

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

variable_types: i int

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

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


decompiled_code:
__int64 __fastcall amd_opengl_shader_create_from_buffer(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
__int64 v8; // rbx
__int64 v9; // rax

v8 = mhandle_calloc(1LL, 40LL, "opengl-bin-file.c:346");
if ( !v8 )
fatal("%s: out of memory", "amd_opengl_shader_create_from_buffer");
v9 = external_elf_file_create(a1, a2, a3, a4, a5);
*(_QWORD *)(v8 + 8) = v9;
*(_QWORD *)(v8 + 16) = internal_elf_file_create(v9);
if ( !(unsigned int)amd_opengl_shader_set_shader_kind(v8, a2) )
fatal("Set Shader kind fail!");
if ( !(unsigned int)amd_opengl_shader_set_isa_buffer(v8) )
fatal("Set ISA info fail!");
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
__int64 v8; // rbx
__int64 v9; // rax

v8 = mhandle_calloc(1LL, 40LL, "opengl-bin-file.c:346");
if ( !v8 )
fatal("%s: out of memory", "amd_opengl_shader_create_from_buffer");
v9 = func4(a1, a2, a3, a4, a5);
*(_QWORD *)(v8 + 8) = v9;
*(_QWORD *)(v8 + 16) = func11(v9);
if ( !(unsigned int)func1(v8, a2) )
fatal("Set Shader kind fail!");
if ( !(unsigned int)func10(v8) )
fatal("Set ISA info fail!");
return v8;
}

original_code:
static struct evg_opengl_shader_t *amd_opengl_shader_create_from_buffer(void *ptr, int size, struct list_t *elf_offset_list, int elf_file_index, char *name)
{
 struct evg_opengl_shader_t *opengl_shader;
 opengl_shader = (mhandle_calloc(1, sizeof(struct evg_opengl_shader_t), "opengl-bin-file.c" ":" "346"));
 if (!opengl_shader)
  fatal("%s: out of memory", __FUNCTION__);
 opengl_shader->external_elf_file = external_elf_file_create(ptr, size, elf_offset_list, elf_file_index, name);
 opengl_shader->internal_elf_file = internal_elf_file_create(opengl_shader->external_elf_file);
 if(!amd_opengl_shader_set_shader_kind(opengl_shader))
  fatal("Set Shader kind fail!");
 if(!amd_opengl_shader_set_isa_buffer(opengl_shader))
  fatal("Set ISA info fail!");
 return opengl_shader;
}

variable_types:
ptr
void *

variable_types: size int

variable_types:
name
char *

variable_types: struct evg_opengl_shader_t { enum evg_opengl_shader_kind_t { EVG_OPENGL_SHADER_VERTEX=0, EVG_OPENGL_SHADER_FRAGMENT=1, EVG_OPENGL_SHADER_GEOMETRY=2, EVG_OPENGL_SHADER_EVALUATION=3, EVG_OPENGL_SHADER_CONTROL=4 } shader_kind; struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *external_elf_file; struct elf_file_t *internal_elf_file; struct elf_buffer_t isa_buffer; } *

user_defined_types: struct evg_opengl_shader_t { enum evg_opengl_shader_kind_t shader_kind; struct elf_file_t *external_elf_file; struct elf_file_t *internal_elf_file; struct elf_buffer_t isa_buffer; }


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

while ( (unsigned int)list_count(a1) )
{
v1 = list_remove_at(a1, 0LL);
mhandle_free(v1, "opengl-bin-file.c:82");
}
return list_free(a1);
}

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

while ( (unsigned int)list_count(a1) )
{
v1 = list_remove_at(a1, 0LL);
mhandle_free(v1, "opengl-bin-file.c:82");
}
return list_free(a1);
}

original_code:
static void elf_file_list_free(struct list_t * elf_file_list)
{
 while (list_count(elf_file_list))
  (mhandle_free(list_remove_at(elf_file_list, 0), "opengl-bin-file.c" ":" "82"));
 list_free(elf_file_list);
}

canonical_original_code:
static void elf_file_list_free(struct list_t *elf_file_list)
{
 while (list_count(elf_file_list))
  (mhandle_free(list_remove_at(elf_file_list, 0), "opengl-bin-file.c" ":" "82"));
 list_free(elf_file_list);
}

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

return_type: void


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

while ( (unsigned int)list_count(a1) )
{
v1 = list_remove_at(a1, 0LL);
mhandle_free(v1, "opengl-bin-file.c:148");
}
return elf_file_list_free(a1);
}

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

while ( (unsigned int)list_count(a1) )
{
v1 = list_remove_at(a1, 0LL);
mhandle_free(v1, "opengl-bin-file.c:148");
}
return func13(a1);
}

original_code:
static void external_elf_file_list_free(struct list_t *elf_external_file_list)
{
 while(list_count(elf_external_file_list))
  (mhandle_free(list_remove_at(elf_external_file_list,0), "opengl-bin-file.c" ":" "148"));
 elf_file_list_free(elf_external_file_list);
}

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


decompiled_code:
__int64 __fastcall evg_opengl_bin_file_free(_QWORD *a1)
{
__int64 v1; // rax

while ( (unsigned int)list_count(a1[1]) )
{
v1 = list_remove_at(a1[1], 0LL);
amd_opengl_shader_free(v1);
}
list_free(a1[1]);
mhandle_free(*a1, "opengl-bin-file.c:426");
return mhandle_free(a1, "opengl-bin-file.c:427");
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1)
{
__int64 v1; // rax

while ( (unsigned int)list_count(a1[1]) )
{
v1 = list_remove_at(a1[1], 0LL);
func7(v1);
}
list_free(a1[1]);
mhandle_free(*a1, "opengl-bin-file.c:426");
return mhandle_free(a1, "opengl-bin-file.c:427");
}

original_code:
void evg_opengl_bin_file_free(struct evg_opengl_bin_file_t *bin_file)
{
 while (list_count(bin_file->shader_list))
  amd_opengl_shader_free(list_remove_at(bin_file->shader_list, 0));
 list_free(bin_file->shader_list);
 (mhandle_free(bin_file->name, "opengl-bin-file.c" ":" "426"));
 (mhandle_free(bin_file, "opengl-bin-file.c" ":" "427"));
}

variable_types: struct evg_opengl_bin_file_t { char *name; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *shader_list; } *

user_defined_types: struct evg_opengl_bin_file_t { char *name; struct list_t *shader_list; }


decompiled_code:
__int64 __fastcall mod_handler_local_mem_load(int a1, _QWORD *a2)
{
__int64 v2; // rbp
_QWORD *v3; // rax
_QWORD *v4; // r12
__int64 result; // rax
__int64 v6; // rax
__int64 v7; // r12
_QWORD *v8; // rax
__int64 v9; // rax
_DWORD *v10; // rax

v2 = a2[5];
if ( EV_MOD_LOCAL_MEM_LOAD == a1 )
{
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s load\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.new_access name=\"A-%lld\" type=\"load\" state=\"%s:load\" addr=0x%x\n",
*a2,
*(const char **)(v2 + 8),
*((unsigned int *)a2 + 20));
mod_access_start(v2, a2, 1LL);
v6 = mod_can_coalesce(v2, 1LL, *((unsigned int *)a2 + 20), a2);
v7 = v6;
if ( v6 )
{
++*(_QWORD *)(v2 + 696);
mod_coalesce(v2, v6, a2);
result = mod_stack_wait_in_stack(a2, v7, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_FINISH);
}
else
{
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK, a2, 0LL);
}
}
else if ( EV_MOD_LOCAL_MEM_LOAD_LOCK == a1 )
{
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s load lock\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:load_lock\"\n",
*a2,
*(const char **)(v2 + 8));
v3 = (_QWORD *)mod_in_flight_write(v2, a2);
v4 = v3;
if ( v3 )
{
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for write %lld\n", *a2, *v3);
return mod_stack_wait_in_stack(a2, v4, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK);
}
v8 = (_QWORD *)mod_in_flight_address(v2, *((unsigned int *)a2 + 20), a2);
v4 = v8;
if ( v8 )
{
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for access %lld\n", *a2, *v8);
return mod_stack_wait_in_stack(a2, v4, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK);
}
v9 = mod_stack_create(*a2, v2, *((unsigned int *)a2 + 20), (unsigned int)EV_MOD_LOCAL_MEM_LOAD_FINISH, a2);
*(_BYTE *)(v9 + 184) |= 8u;
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK, v9, 0LL);
}
else
{
if ( EV_MOD_LOCAL_MEM_LOAD_FINISH != a1 )
abort();
if ( mem_debug_category )
_debug(
mem_debug_category,
"%lld %lld 0x%x %s load finish\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
{
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:load_finish\"\n",
*a2,
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(mem_trace_category, 1LL, "mem.end_access name=\"A-%lld\"\n", *a2);
}
v10 = (_DWORD *)a2[2];
if ( v10 )
++*v10;
if ( a2[3] && a2[4] )
linked_list_add();
mod_access_finish(v2, a2);
result = mod_stack_return(a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, _QWORD *a2)
{
__int64 v2; // rbp
_QWORD *v3; // rax
_QWORD *v4; // r12
__int64 result; // rax
__int64 v6; // rax
__int64 v7; // r12
_QWORD *v8; // rax
__int64 v9; // rax
_DWORD *v10; // rax

v2 = a2[5];
if ( EV_MOD_LOCAL_MEM_LOAD == a1 )
{
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s load\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.new_access name=\"A-%lld\" type=\"load\" state=\"%s:load\" addr=0x%x\n",
*a2,
*(const char **)(v2 + 8),
*((unsigned int *)a2 + 20));
mod_access_start(v2, a2, 1LL);
v6 = mod_can_coalesce(v2, 1LL, *((unsigned int *)a2 + 20), a2);
v7 = v6;
if ( v6 )
{
++*(_QWORD *)(v2 + 696);
mod_coalesce(v2, v6, a2);
result = mod_stack_wait_in_stack(a2, v7, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_FINISH);
}
else
{
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK, a2, 0LL);
}
}
else if ( EV_MOD_LOCAL_MEM_LOAD_LOCK == a1 )
{
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s load lock\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:load_lock\"\n",
*a2,
*(const char **)(v2 + 8));
v3 = (_QWORD *)mod_in_flight_write(v2, a2);
v4 = v3;
if ( v3 )
{
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for write %lld\n", *a2, *v3);
return mod_stack_wait_in_stack(a2, v4, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK);
}
v8 = (_QWORD *)mod_in_flight_address(v2, *((unsigned int *)a2 + 20), a2);
v4 = v8;
if ( v8 )
{
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for access %lld\n", *a2, *v8);
return mod_stack_wait_in_stack(a2, v4, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK);
}
v9 = mod_stack_create(*a2, v2, *((unsigned int *)a2 + 20), (unsigned int)EV_MOD_LOCAL_MEM_LOAD_FINISH, a2);
*(_BYTE *)(v9 + 184) |= 8u;
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK, v9, 0LL);
}
else
{
if ( EV_MOD_LOCAL_MEM_LOAD_FINISH != a1 )
abort();
if ( mem_debug_category )
_debug(
mem_debug_category,
"%lld %lld 0x%x %s load finish\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
{
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:load_finish\"\n",
*a2,
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(mem_trace_category, 1LL, "mem.end_access name=\"A-%lld\"\n", *a2);
}
v10 = (_DWORD *)a2[2];
if ( v10 )
++*v10;
if ( a2[3] && a2[4] )
linked_list_add();
mod_access_finish(v2, a2);
result = mod_stack_return(a2);
}
return result;
}

original_code:
void mod_handler_local_mem_load(int event, void *data)
{
 struct mod_stack_t *stack = data;
 struct mod_stack_t *new_stack;
 struct mod_t *mod = stack->mod;
 if (event == EV_MOD_LOCAL_MEM_LOAD)
 {
  struct mod_stack_t *master_stack;
  ((mem_debug_category) ? __debug((mem_debug_category), "  %lld %lld 0x%x %s load\n", esim_cycle, stack->id, stack->addr, mod->name) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.new_access name=\"A-%lld\" type=\"load\" " "state=\"%s:load\" addr=0x%x\n", stack->id, mod->name, stack->addr) : (void) 0);
  mod_access_start(mod, stack, mod_access_load);
  master_stack = mod_can_coalesce(mod, mod_access_load, stack->addr, stack);
  if (master_stack)
  {
   mod->reads++;
   mod_coalesce(mod, master_stack, stack);
   mod_stack_wait_in_stack(stack, master_stack, EV_MOD_LOCAL_MEM_LOAD_FINISH);
   return;
  }
  esim_schedule_event(EV_MOD_LOCAL_MEM_LOAD_LOCK, stack, 0);
  return;
 }
 if (event == EV_MOD_LOCAL_MEM_LOAD_LOCK)
 {
  struct mod_stack_t *older_stack;
  ((mem_debug_category) ? __debug((mem_debug_category), "  %lld %lld 0x%x %s load lock\n", esim_cycle, stack->id, stack->addr, mod->name) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.access name=\"A-%lld\" state=\"%s:load_lock\"\n", stack->id, mod->name) : (void) 0);
  older_stack = mod_in_flight_write(mod, stack);
  if (older_stack)
  {
   ((mem_debug_category) ? __debug((mem_debug_category), "    %lld wait for write %lld\n", stack->id, older_stack->id) : (void) 0);
   mod_stack_wait_in_stack(stack, older_stack, EV_MOD_LOCAL_MEM_LOAD_LOCK);
   return;
  }
  older_stack = mod_in_flight_address(mod, stack->addr, stack);
  if (older_stack)
  {
   ((mem_debug_category) ? __debug((mem_debug_category), "    %lld wait for access %lld\n", stack->id, older_stack->id) : (void) 0);
   mod_stack_wait_in_stack(stack, older_stack, EV_MOD_LOCAL_MEM_LOAD_LOCK);
   return;
  }
  new_stack = mod_stack_create(stack->id, mod, stack->addr,
   EV_MOD_LOCAL_MEM_LOAD_FINISH, stack);
  new_stack->read = 1;
  esim_schedule_event(EV_MOD_LOCAL_MEM_FIND_AND_LOCK, new_stack, 0);
  return;
 }
 if (event == EV_MOD_LOCAL_MEM_LOAD_FINISH)
 {
  ((mem_debug_category) ? __debug((mem_debug_category), "%lld %lld 0x%x %s load finish\n", esim_cycle, stack->id, stack->addr, mod->name) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.access name=\"A-%lld\" state=\"%s:load_finish\"\n", stack->id, mod->name) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.end_access name=\"A-%lld\"\n", stack->id) : (void) 0);
                if (stack->witness_ptr) {
                        (*stack->witness_ptr)++;
  }
  if (stack->event_queue && stack->event_queue_item)
   linked_list_add(stack->event_queue, stack->event_queue_item);
  mod_access_finish(mod, stack);
  mod_stack_return(stack);
  return;
 }
 abort();
}

variable_types: event int

variable_types:
data
void *

variable_types: struct mod_stack_t { long long id; enum mod_access_kind_t { mod_access_invalid=0, mod_access_load=1, mod_access_store=2, mod_access_nc_store=3 } access_kind; int *witness_ptr; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *event_queue; void *event_queue_item; struct mod_t { enum mod_kind_t { mod_kind_invalid=0, mod_kind_cache=1, mod_kind_main_memory=2, mod_kind_local_memory=3 } kind; char *name; int block_size; int log_block_size; int latency; int dir_latency; int mshr_size; int level; enum mod_range_kind_t { mod_range_invalid=0, mod_range_bounds=1, mod_range_interleaved=2 } range_kind; union { struct { unsigned int low; unsigned int high; } bounds; struct { unsigned int mod; unsigned int div; unsigned int eq; } interleaved; } range; struct mod_port_t { int locked; long long lock_when; struct mod_stack_t *stack; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; } *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t *lock_queue; } *dir_lock; unsigned char data[]; } *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 } policy; struct cache_set_t { struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; } *sets; unsigned int block_mask; int log_block_size; } *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *high_net; struct net_t *low_net; struct net_node_t *high_net_node; struct net_node_t *low_net_node; struct mod_stack_t *access_list_head; struct mod_stack_t *access_list_tail; int access_list_count; int access_list_max; struct mod_stack_t *write_access_list_head; struct mod_stack_t *write_access_list_tail; int write_access_list_count; int write_access_list_max; int access_list_coalesced_count; struct { struct mod_stack_t *bucket_list_head; struct mod_stack_t *bucket_list_tail; int bucket_list_count; int bucket_list_max; } access_hash_table[17]; int color; long long accesses; long long hits; long long reads; long long effective_reads; long long effective_read_hits; long long writes; long long effective_writes; long long effective_write_hits; long long nc_writes; long long effective_nc_writes; long long effective_nc_write_hits; long long evictions; long long blocking_reads; long long non_blocking_reads; long long read_hits; long long blocking_writes; long long non_blocking_writes; long long write_hits; long long blocking_nc_writes; long long non_blocking_nc_writes; long long nc_write_hits; long long read_retries; long long write_retries; long long nc_write_retries; long long no_retry_accesses; long long no_retry_hits; long long no_retry_reads; long long no_retry_read_hits; long long no_retry_writes; long long no_retry_write_hits; long long no_retry_nc_writes; long long no_retry_nc_write_hits; } *mod; struct mod_t *target_mod; struct mod_t *except_mod; struct mod_t *peer; struct mod_port_t *port; unsigned int addr; int tag; int set; int way; int state; int src_set; int src_way; int src_tag; enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 } request_dir; enum mod_message_type_t { message_none=0, message_clear_owner=1 } message; enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 } reply; int reply_size; int retain_owner; int pending; struct mod_stack_t *access_list_prev; struct mod_stack_t *access_list_next; struct mod_stack_t *write_access_list_prev; struct mod_stack_t *write_access_list_next; struct mod_stack_t *bucket_list_prev; struct mod_stack_t *bucket_list_next; int hit; int err; int shared; int read; int write; int nc_write; int blocking; int writeback; int eviction; int retry; int coalesced; int port_locked; struct net_msg_t *msg; int waiting_list_event; struct mod_stack_t *waiting_list_prev; struct mod_stack_t *waiting_list_next; int port_waiting_list_event; struct mod_stack_t *port_waiting_list_prev; struct mod_stack_t *port_waiting_list_next; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct mod_stack_t *master_stack; int dir_lock_event; struct mod_stack_t *dir_lock_next; struct mod_stack_t *ret_stack; int ret_event; } *

variable_types: 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 { 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 *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 { 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 *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *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; } *stack; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; } *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t *lock_queue; } *dir_lock; unsigned char data[]; } *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 } policy; struct cache_set_t { struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; } *sets; unsigned int block_mask; int log_block_size; } *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; struct net_t *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_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 linked_list_t { int count; int error_code; struct linked_list_elem_t *head; int current_index; }

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 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 mod_handler_local_mem_find_and_lock(int a1, _QWORD *a2)
{
__int64 v2; // rbp
__int64 v3; // r12
__int64 result; // rax
__int64 v5; // r12
_DWORD *v6; // rax

v2 = a2[5];
if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK == a1 )
{
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock\"\n",
*a2,
*(const char **)(v2 + 8));
result = mod_lock_port(v2, a2, (unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_PORT);
}
else if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_PORT == a1 )
{
v5 = a2[37];
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock port\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock_port\"\n",
*a2,
*(const char **)(v2 + 8));
*(_BYTE *)(v5 + 185) |= 8u;
++*(_QWORD *)(v2 + 680);
if ( (a2[23] & 8) != 0 )
{
++*(_QWORD *)(v2 + 696);
++*(_QWORD *)(v2 + 704);
}
else
{
++*(_QWORD *)(v2 + 720);
++*(_QWORD *)(v2 + 728);
v6 = (_DWORD *)a2[2];
if ( v6 )
{
++*v6;
a2[2] = 0LL;
}
}
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_ACTION, a2, *(unsigned int *)(v2 + 24));
}
else if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_ACTION == a1 )
{
v3 = a2[9];
if ( !v3 )
_assert_fail("port", "local-mem-protocol.c", 0x130u, "mod_handler_local_mem_find_and_lock");
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock action\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 21),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock_action\"\n",
*a2,
*(const char **)(v2 + 8));
mod_unlock_port(v2, v3, a2);
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH, a2, 0LL);
}
else
{
if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH != a1 )
abort();
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock finish (err=%d)\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 21),
*(const char **)(v2 + 8),
(unsigned int)(*((unsigned __int8 *)a2 + 184) << 30 >> 31));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock_finish\"\n",
*a2,
*(const char **)(v2 + 8));
result = mod_stack_return(a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _QWORD *a2)
{
__int64 v2; // rbp
__int64 v3; // r12
__int64 result; // rax
__int64 v5; // r12
_DWORD *v6; // rax

v2 = a2[5];
if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK == a1 )
{
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock\"\n",
*a2,
*(const char **)(v2 + 8));
result = mod_lock_port(v2, a2, (unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_PORT);
}
else if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_PORT == a1 )
{
v5 = a2[37];
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock port\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 20),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock_port\"\n",
*a2,
*(const char **)(v2 + 8));
*(_BYTE *)(v5 + 185) |= 8u;
++*(_QWORD *)(v2 + 680);
if ( (a2[23] & 8) != 0 )
{
++*(_QWORD *)(v2 + 696);
++*(_QWORD *)(v2 + 704);
}
else
{
++*(_QWORD *)(v2 + 720);
++*(_QWORD *)(v2 + 728);
v6 = (_DWORD *)a2[2];
if ( v6 )
{
++*v6;
a2[2] = 0LL;
}
}
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_ACTION, a2, *(unsigned int *)(v2 + 24));
}
else if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_ACTION == a1 )
{
v3 = a2[9];
if ( !v3 )
_assert_fail("port", "local-mem-protocol.c", 0x130u, "mod_handler_local_mem_find_and_lock");
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock action\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 21),
*(const char **)(v2 + 8));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock_action\"\n",
*a2,
*(const char **)(v2 + 8));
mod_unlock_port(v2, v3, a2);
result = esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH, a2, 0LL);
}
else
{
if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH != a1 )
abort();
if ( mem_debug_category )
_debug(
mem_debug_category,
" %lld %lld 0x%x %s find and lock finish (err=%d)\n",
esim_cycle,
*a2,
*((unsigned int *)a2 + 21),
*(const char **)(v2 + 8),
(unsigned int)(*((unsigned __int8 *)a2 + 184) << 30 >> 31));
if ( mem_trace_category )
_trace(
mem_trace_category,
1LL,
"mem.access name=\"A-%lld\" state=\"%s:find_and_lock_finish\"\n",
*a2,
*(const char **)(v2 + 8));
result = mod_stack_return(a2);
}
return result;
}

original_code:
void mod_handler_local_mem_find_and_lock(int event, void *data)
{
 struct mod_stack_t *stack = data;
 struct mod_stack_t *ret = stack->ret_stack;
 struct mod_t *mod = stack->mod;
 if (event == EV_MOD_LOCAL_MEM_FIND_AND_LOCK)
 {
  ((mem_debug_category) ? __debug((mem_debug_category), "  %lld %lld 0x%x %s find and lock\n", esim_cycle, stack->id, stack->addr, mod->name) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.access name=\"A-%lld\" state=\"%s:find_and_lock\"\n", stack->id, mod->name) : (void) 0);
  mod_lock_port(mod, stack, EV_MOD_LOCAL_MEM_FIND_AND_LOCK_PORT);
  return;
 }
 if (event == EV_MOD_LOCAL_MEM_FIND_AND_LOCK_PORT)
 {
  ((mem_debug_category) ? __debug((mem_debug_category), "  %lld %lld 0x%x %s find and lock port\n", esim_cycle, stack->id, stack->addr, mod->name) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.access name=\"A-%lld\" state=\"%s:find_and_lock_port\"\n", stack->id, mod->name) : (void) 0);
  ret->port_locked = 1;
  mod->accesses++;
  if (stack->read)
  {
   mod->reads++;
   mod->effective_reads++;
  }
  else
  {
   mod->writes++;
   mod->effective_writes++;
   if (stack->witness_ptr)
   {
    (*stack->witness_ptr)++;
    stack->witness_ptr = ((void *)0);
   }
  }
  esim_schedule_event(EV_MOD_LOCAL_MEM_FIND_AND_LOCK_ACTION, stack, mod->latency);
  return;
 }
 if (event == EV_MOD_LOCAL_MEM_FIND_AND_LOCK_ACTION)
 {
  struct mod_port_t *port = stack->port;
  ((void) sizeof ((port) ? 1 : 0), __extension__ ({ if (port) ; else __assert_fail ("port", "local-mem-protocol.c", 304, __extension__ __PRETTY_FUNCTION__); }));
  ((mem_debug_category) ? __debug((mem_debug_category), "  %lld %lld 0x%x %s find and lock action\n", esim_cycle, stack->id, stack->tag, mod->name) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.access name=\"A-%lld\" state=\"%s:find_and_lock_action\"\n", stack->id, mod->name) : (void) 0);
  mod_unlock_port(mod, port, stack);
  esim_schedule_event(EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH, stack, 0);
  return;
 }
 if (event == EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH)
 {
  ((mem_debug_category) ? __debug((mem_debug_category), "  %lld %lld 0x%x %s find and lock finish (err=%d)\n", esim_cycle, stack->id, stack->tag, mod->name, stack->err) : (void) 0);
  ((mem_trace_category) ? __trace((mem_trace_category), 1, "mem.access name=\"A-%lld\" state=\"%s:find_and_lock_finish\"\n", stack->id, mod->name) : (void) 0);
  mod_stack_return(stack);
  return;
 }
 abort();
}

variable_types: struct mod_port_t { int locked; long long lock_when; 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 *ports; int num_ports; int num_locked_ports; struct mod_stack_t *port_waiting_list_head; struct mod_stack_t *port_waiting_list_tail; int port_waiting_list_count; int port_waiting_list_max; struct dir_t { char *name; int num_nodes; int xsize; struct dir_lock_t { int lock; long long stack_id; struct mod_stack_t *lock_queue; } *dir_lock; unsigned char data[]; } *dir; int dir_size; int dir_assoc; int dir_num_sets; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct cache_t { char *name; unsigned int num_sets; unsigned int block_size; unsigned int assoc; enum cache_policy_t { cache_policy_invalid=0, cache_policy_lru=1, cache_policy_fifo=2, cache_policy_random=3 } policy; struct cache_set_t { struct cache_block_t { struct cache_block_t *way_next; struct cache_block_t *way_prev; int tag; int transient_tag; int way; enum cache_block_state_t { cache_block_invalid=0, cache_block_noncoherent=1, cache_block_modified=2, cache_block_owned=3, cache_block_exclusive=4, cache_block_shared=5 } state; } *way_head; struct cache_block_t *way_tail; struct cache_block_t *blocks; } *sets; unsigned int block_mask; int log_block_size; } *cache; struct linked_list_t *high_mod_list; struct linked_list_t *low_mod_list; int sub_block_size; int num_sub_blocks; struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *high_net; struct net_t *low_net; struct net_node_t *high_net_node; struct net_node_t *low_net_node; struct mod_stack_t *access_list_head; struct mod_stack_t *access_list_tail; int access_list_count; int access_list_max; struct mod_stack_t *write_access_list_head; struct mod_stack_t *write_access_list_tail; int write_access_list_count; int write_access_list_max; int access_list_coalesced_count; struct { struct mod_stack_t *bucket_list_head; struct mod_stack_t *bucket_list_tail; int bucket_list_count; int bucket_list_max; } access_hash_table[17]; int color; long long accesses; long long hits; long long reads; long long effective_reads; long long effective_read_hits; long long writes; long long effective_writes; long long effective_write_hits; long long nc_writes; long long effective_nc_writes; long long effective_nc_write_hits; long long evictions; long long blocking_reads; long long non_blocking_reads; long long read_hits; long long blocking_writes; long long non_blocking_writes; long long write_hits; long long blocking_nc_writes; long long non_blocking_nc_writes; long long nc_write_hits; long long read_retries; long long write_retries; long long nc_write_retries; long long no_retry_accesses; long long no_retry_hits; long long no_retry_reads; long long no_retry_read_hits; long long no_retry_writes; long long no_retry_write_hits; long long no_retry_nc_writes; long long no_retry_nc_write_hits; } *mod; struct mod_t *target_mod; struct mod_t *except_mod; struct mod_t *peer; struct mod_port_t *port; unsigned int addr; int tag; int set; int way; int state; int src_set; int src_way; int src_tag; enum mod_request_dir_t { mod_request_invalid=0, mod_request_up_down=1, mod_request_down_up=2 } request_dir; enum mod_message_type_t { message_none=0, message_clear_owner=1 } message; enum mod_reply_type_t { reply_none=0, reply_ack=1, reply_ack_data=2, reply_ack_data_sent_to_peer=3, reply_ack_error=4 } reply; int reply_size; int retain_owner; int pending; struct mod_stack_t *access_list_prev; struct mod_stack_t *access_list_next; struct mod_stack_t *write_access_list_prev; struct mod_stack_t *write_access_list_next; struct mod_stack_t *bucket_list_prev; struct mod_stack_t *bucket_list_next; int hit; int err; int shared; int read; int write; int nc_write; int blocking; int writeback; int eviction; int retry; int coalesced; int port_locked; struct net_msg_t *msg; int waiting_list_event; struct mod_stack_t *waiting_list_prev; struct mod_stack_t *waiting_list_next; int port_waiting_list_event; struct mod_stack_t *port_waiting_list_prev; struct mod_stack_t *port_waiting_list_next; struct mod_stack_t *waiting_list_head; struct mod_stack_t *waiting_list_tail; int waiting_list_count; int waiting_list_max; struct mod_stack_t *master_stack; int dir_lock_event; struct mod_stack_t *dir_lock_next; struct mod_stack_t *ret_stack; int ret_event; } *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 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; }


original_code:
static void hash_table_grow(struct hash_table_t *table)
{
 int old_size;
 int index;
 int i;
 struct hash_table_elem_t **old_elem_vector;
 struct hash_table_elem_t *elem;
 old_size = table->size;
 old_elem_vector = table->elem_vector;
 table->size = old_size * 2;
 table->elem_vector = (mhandle_calloc(table->size, sizeof(void *), "hash-table.c" ":" "135"));
 if (!table->elem_vector)
  fatal("%s: out of memory", __FUNCTION__);
 for (i = 0; i < old_size; i++)
 {
  while ((elem = old_elem_vector[i]))
  {
   old_elem_vector[i] = elem->next;
   index = hash_table_get_index(table, elem->key);
   elem->next = table->elem_vector[index];
   table->elem_vector[index] = elem;
  }
 }
 (mhandle_free(old_elem_vector, "hash-table.c" ":" "155"));
}

variable_types: struct hash_table_t { int count; int size; int case_sensitive; int find_op; int find_index; struct hash_table_elem_t { char *key; void *data; struct hash_table_elem_t *next; } *find_elem; struct hash_table_elem_t **elem_vector; int (*str_compare_func)(char *, char *); } *

variable_types: index int

variable_types: struct hash_table_elem_t { char *key; void *data; struct hash_table_elem_t *next; } **

user_defined_types: struct hash_table_t { int count; int size; int case_sensitive; int find_op; int find_index; struct hash_table_elem_t *find_elem; struct hash_table_elem_t **elem_vector; int (*str_compare_func)(char *, char *); }


decompiled_code:
__int64 __fastcall hash_table_elem_free(_QWORD *a1)
{
mhandle_free(*a1, "hash-table.c:71");
return mhandle_free(a1, "hash-table.c:72");
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
mhandle_free(*a1, "hash-table.c:71");
return mhandle_free(a1, "hash-table.c:72");
}

original_code:
void hash_table_elem_free(struct hash_table_elem_t *elem)
{
 (mhandle_free(elem->key, "hash-table.c" ":" "71"));
 (mhandle_free(elem, "hash-table.c" ":" "72"));
}

variable_types: struct hash_table_elem_t { char *key; void *data; struct hash_table_elem_t *next; } *


decompiled_code:
__int64 __fastcall hash_table_create(int a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
int (**v4)(const char *, const char *); // rax
__int64 v5; // rax

v2 = a1;
v3 = mhandle_calloc(1LL, 48LL, "hash-table.c:185");
if ( !v3 )
fatal("%s: out of memory", "hash_table_create");
if ( a1 < 5 )
v2 = 5;
*(_DWORD *)(v3 + 4) = v2;
*(_DWORD *)(v3 + 8) = a2;
v4 = &strcmp;
if ( !a2 )
v4 = &strcasecmp;
*(_QWORD *)(v3 + 40) = v4;
v5 = mhandle_calloc(v2, 8LL, "hash-table.c:195");
*(_QWORD *)(v3 + 32) = v5;
if ( !v5 )
fatal("%s: out of memory", "hash_table_create");
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
int (**v4)(const char *, const char *); // rax
__int64 v5; // rax

v2 = a1;
v3 = mhandle_calloc(1LL, 48LL, "hash-table.c:185");
if ( !v3 )
fatal("%s: out of memory", "hash_table_create");
if ( a1 < 5 )
v2 = 5;
*(_DWORD *)(v3 + 4) = v2;
*(_DWORD *)(v3 + 8) = a2;
v4 = &strcmp;
if ( !a2 )
v4 = &strcasecmp;
*(_QWORD *)(v3 + 40) = v4;
v5 = mhandle_calloc(v2, 8LL, "hash-table.c:195");
*(_QWORD *)(v3 + 32) = v5;
if ( !v5 )
fatal("%s: out of memory", "hash_table_create");
return v3;
}

original_code:
struct hash_table_t *hash_table_create(int size, int case_sensitive)
{
 struct hash_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct hash_table_t), "hash-table.c" ":" "185"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 table->size = size < 5 ? 5 : size;
 table->case_sensitive = case_sensitive;
 table->str_compare_func = case_sensitive ? strcmp : strcasecmp;
 table->elem_vector = (mhandle_calloc(table->size, sizeof(void *), "hash-table.c" ":" "195"));
 if (!table->elem_vector)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

return_type: struct hash_table_t { int count; int size; int case_sensitive; int find_op; int find_index; struct hash_table_elem_t { char *key; void *data; struct hash_table_elem_t *next; } *find_elem; struct hash_table_elem_t **elem_vector; int (*str_compare_func)(char *, char *); } *


decompiled_code:
__int64 __fastcall hash_table_clear(__int64 a1)
{
__int64 i; // r12
__int64 v3; // r13
__int64 result; // rax
_QWORD *j; // rdi

*(_DWORD *)(a1 + 12) = 0;
for ( i = 0LL; *(_DWORD *)(a1 + 4) > (int)i; ++i )
{
result = *(_QWORD *)(a1 + 32);
for ( j = *(_QWORD **)(result + 8 * i); j; j = *(_QWORD **)(result + 8 * i) )
{
v3 = j[2];
hash_table_elem_free(j);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * i) = v3;
result = *(_QWORD *)(a1 + 32);
}
}
*(_DWORD *)a1 = 0;
return result;
}

original_code:
void hash_table_clear(struct hash_table_t *table)
{
 struct hash_table_elem_t *elem;
 struct hash_table_elem_t *elem_next;
 int i;
 table->find_op = 0;
 for (i = 0; i < table->size; i++)
 {
  while ((elem = table->elem_vector[i]))
  {
   elem_next = elem->next;
   hash_table_elem_free(elem);
   table->elem_vector[i] = elem_next;
  }
 }
 table->count = 0;
}

user_defined_types: struct hash_table_elem_t { char *key; void *data; struct hash_table_elem_t *next; }


decompiled_code:
__int64 __fastcall hash_table_free(__int64 a1)
{
hash_table_clear(a1);
mhandle_free(*(_QWORD *)(a1 + 32), "hash-table.c:210");
return mhandle_free(a1, "hash-table.c:211");
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
func4(a1);
mhandle_free(*(_QWORD *)(a1 + 32), "hash-table.c:210");
return mhandle_free(a1, "hash-table.c:211");
}

original_code:
void hash_table_free(struct hash_table_t *table)
{
 hash_table_clear(table);
 (mhandle_free(table->elem_vector, "hash-table.c" ":" "210"));
 (mhandle_free(table, "hash-table.c" ":" "211"));
}


decompiled_code:
__int64 __fastcall hash_table_insert(__int64 a1, const char *a2, __int64 a3)
{
_QWORD *v4; // rdx
__int64 result; // rax
__int64 *v6; // rax
__int64 v7; // rdx
int v8[7]; // [rsp+0h] [rbp-1Ch] BYREF

*(_DWORD *)(a1 + 12) = 0;
if ( !a3 )
return 0LL;
if ( *(_DWORD *)a1 >= *(_DWORD *)(a1 + 4) / 2 )
hash_table_grow(a1);
v4 = hash_table_find(a1, a2, v8);
result = 0LL;
if ( !v4 )
{
v6 = hash_table_elem_create((__int64)a2, a3);
v7 = v8[0];
v6[2] = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * v8[0]);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v7) = v6;
LODWORD(v6) = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = (_DWORD)v6;
if ( (int)v6 >= *(_DWORD *)(a1 + 4) )
_assert_fail("table->count < table->size", "hash-table.c", 0x10Eu, "hash_table_insert");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, __int64 a3)
{
_QWORD *v4; // rdx
__int64 result; // rax
__int64 *v6; // rax
__int64 v7; // rdx
int v8[7]; // [rsp+0h] [rbp-1Ch] BYREF

*(_DWORD *)(a1 + 12) = 0;
if ( !a3 )
return 0LL;
if ( *(_DWORD *)a1 >= *(_DWORD *)(a1 + 4) / 2 )
func1(a1);
v4 = hash_table_find(a1, a2, v8);
result = 0LL;
if ( !v4 )
{
v6 = hash_table_elem_create((__int64)a2, a3);
v7 = v8[0];
v6[2] = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * v8[0]);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v7) = v6;
LODWORD(v6) = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = (_DWORD)v6;
if ( (int)v6 >= *(_DWORD *)(a1 + 4) )
_assert_fail("table->count < table->size", "hash-table.c", 0x10Eu, "hash_table_insert");
result = 1LL;
}
return result;
}

original_code:
int hash_table_insert(struct hash_table_t *table, char *key, void *data)
{
 struct hash_table_elem_t *elem;
 int index;
 table->find_op = 0;
 if (!data)
  return 0;
 if (table->count >= table->size / 2)
  hash_table_grow(table);
 elem = hash_table_find(table, key, &index);
 if (elem)
  return 0;
 elem = hash_table_elem_create(key, data);
 elem->next = table->elem_vector[index];
 table->elem_vector[index] = elem;
 table->count++;
 ((void) sizeof ((table->count < table->size) ? 1 : 0), __extension__ ({ if (table->count < table->size) ; else __assert_fail ("table->count < table->size", "hash-table.c", 270, __extension__ __PRETTY_FUNCTION__); }));
 return 1;
}

variable_types:
key
char *

return_type: int


decompiled_code:
__int64 __fastcall hash_table_set(__int64 a1, const char *a2, __int64 a3)
{
__int64 result; // rax
_QWORD *v5; // rax

result = 0LL;
if ( a3 )
{
v5 = hash_table_find(a1, a2, 0LL);
if ( v5 )
{
v5[1] = a3;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, __int64 a3)
{
__int64 result; // rax
_QWORD *v5; // rax

result = 0LL;
if ( a3 )
{
v5 = hash_table_find(a1, a2, 0LL);
if ( v5 )
{
v5[1] = a3;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int hash_table_set(struct hash_table_t *table, char *key, void *data)
{
 struct hash_table_elem_t *elem;
 if (!data)
  return 0;
 elem = hash_table_find(table, key, ((void *)0));
 if (!elem)
  return 0;
 elem->data = data;
 return 1;
}


decompiled_code:
__int64 __fastcall hash_table_count(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
return *a1;
}

original_code:
int hash_table_count(struct hash_table_t *table)
{
 return table->count;
}


decompiled_code:
__int64 __fastcall hash_table_remove(__int64 a1, const char *a2)
{
__int64 v2; // r14
_QWORD *v3; // rbx
_QWORD *v4; // r13
__int64 v5; // r12

*(_DWORD *)(a1 + 12) = 0;
v2 = (int)hash_table_get_index(a1, a2);
v3 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 8 * v2);
if ( !v3 )
return 0LL;
v4 = 0LL;
while ( (*(unsigned int (__fastcall **)(_QWORD, const char *))(a1 + 40))(*v3, a2) )
{
v4 = v3;
if ( !v3[2] )
return 0LL;
v3 = (_QWORD *)v3[2];
}
if ( v4 )
v4[2] = v3[2];
else
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v2) = v3[2];
v5 = v3[1];
hash_table_elem_free(v3);
if ( *(int *)a1 <= 0 )
_assert_fail("table->count > 0", "hash-table.c", 0x164u, "hash_table_remove");
--*(_DWORD *)a1;
return v5;
}

original_code:
void *hash_table_remove(struct hash_table_t *table, char *key)
{
 struct hash_table_elem_t *elem;
 struct hash_table_elem_t *elem_prev;
 int index;
 void *data;
 table->find_op = 0;
 index = hash_table_get_index(table, key);
 elem_prev = ((void *)0);
 for (elem = table->elem_vector[index]; elem; elem = elem->next)
 {
  if (!table->str_compare_func(elem->key, key))
   break;
  elem_prev = elem;
 }
 if (!elem)
  return ((void *)0);
 if (elem_prev)
  elem_prev->next = elem->next;
 else
  table->elem_vector[index] = elem->next;
 data = elem->data;
 hash_table_elem_free(elem);
 ((void) sizeof ((table->count > 0) ? 1 : 0), __extension__ ({ if (table->count > 0) ; else __assert_fail ("table->count > 0", "hash-table.c", 356, __extension__ __PRETTY_FUNCTION__); }));
 table->count--;
 return data;
}

return_type: void *


decompiled_code:
__int64 __fastcall hash_table_find_first(__int64 a1, _QWORD *a2)
{
int v2; // ecx
__int64 v3; // rax
__int64 *v4; // rdx
__int64 result; // rax

*(_DWORD *)(a1 + 12) = 1;
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
if ( a2 )
*a2 = 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
if ( v2 <= 0 )
{
LABEL_8:
panic("%s: inconsistent hash table", "hash_table_find_first");
result = 0LL;
}
else
{
v3 = 0LL;
while ( 1 )
{
v4 = *(__int64 **)(*(_QWORD *)(a1 + 32) + 8 * v3);
if ( v4 )
break;
if ( ++v3 == v2 )
goto LABEL_8;
}
*(_DWORD *)(a1 + 16) = v3;
*(_QWORD *)(a1 + 24) = v4;
if ( a2 )
*a2 = v4[1];
result = *v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _QWORD *a2)
{
int v2; // ecx
__int64 v3; // rax
__int64 *v4; // rdx
__int64 result; // rax

*(_DWORD *)(a1 + 12) = 1;
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
if ( a2 )
*a2 = 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
if ( v2 <= 0 )
{
LABEL_8:
panic("%s: inconsistent hash table", "hash_table_find_first");
result = 0LL;
}
else
{
v3 = 0LL;
while ( 1 )
{
v4 = *(__int64 **)(*(_QWORD *)(a1 + 32) + 8 * v3);
if ( v4 )
break;
if ( ++v3 == v2 )
goto LABEL_8;
}
*(_DWORD *)(a1 + 16) = v3;
*(_QWORD *)(a1 + 24) = v4;
if ( a2 )
*a2 = v4[1];
result = *v4;
}
return result;
}

original_code:
char *hash_table_find_first(struct hash_table_t *table, void **data_ptr)
{
 struct hash_table_elem_t *elem;
 int index;
 table->find_op = 1;
 table->find_index = 0;
 table->find_elem = ((void *)0);
 if (data_ptr)
  *data_ptr = ((void *)0);
 if (!table->count)
  return ((void *)0);
 for (index = 0; index < table->size; index++)
 {
  elem = table->elem_vector[index];
  if (elem)
  {
   table->find_index = index;
   table->find_elem = elem;
   if (data_ptr)
    *data_ptr = elem->data;
   return elem->key;
  }
 }
 panic("%s: inconsistent hash table", __FUNCTION__);
 return ((void *)0);
}

return_type: char *


decompiled_code:
void __fastcall x86_trace_cache_flush_trace(__int64 a1)
{
_DWORD *v1; // r8
unsigned int v3; // er10
int v4; // ecx
int v5; // ecx
int v6; // eax
unsigned int v7; // edx
int v8; // esi
__int64 v9; // r11
_DWORD *v10; // rax
int v11; // ecx
_DWORD *v12; // r9
int v13; // edi
int v14; // ecx
_DWORD *v15; // rsi

v1 = *(_DWORD **)(a1 + 8);
if ( v1[2] )
{
v3 = v1[1];
if ( !v3 )
_assert_fail("trace->tag", "trace-cache.c", 0xAAu, "x86_trace_cache_flush_trace");
if ( v1[8] )
{
v4 = v1[6];
if ( !v4 )
_assert_fail("trace->branch_count", "trace-cache.c", 0xB1u, "x86_trace_cache_flush_trace");
v5 = v4 - 1;
v1[6] = v5;
v6 = __ROL4__(-2, v5);
v1[4] &= v6;
v1[5] &= v6;
}
v7 = v3 % x86_trace_cache_num_sets;
v8 = x86_trace_cache_assoc;
if ( x86_trace_cache_assoc <= 0 )
goto LABEL_22;
v9 = 4LL * x86_trace_cache_trace_size + 36;
v10 = (_DWORD *)(*(_QWORD *)a1 + v9 * (int)(x86_trace_cache_assoc * v7));
v11 = 0;
do
{
v12 = v10;
v13 = v10[1];
if ( v3 == v13 )
{
if ( v10[4] == v1[4] && v10[5] == v1[5] )
goto LABEL_14;
}
else if ( !v13 )
{
goto LABEL_14;
}
++v11;
v10 = (_DWORD *)((char *)v10 + v9);
}
while ( v11 != x86_trace_cache_assoc );
v14 = 0;
v12 = 0LL;
do
{
v15 = (_DWORD *)(*(_QWORD *)a1 + 4 * (x86_trace_cache_trace_size + 9LL) * (int)(v14 + v7 * v8));
if ( --*v15 < 0 )
{
*v15 = x86_trace_cache_assoc - 1;
v12 = v15;
}
++v14;
v8 = x86_trace_cache_assoc;
}
while ( x86_trace_cache_assoc > v14 );
if ( !v12 )
LABEL_22:
_assert_fail("found", "trace-cache.c", 0xD9u, "x86_trace_cache_flush_trace");
LABEL_14:
*(_QWORD *)(a1 + 72) += (int)v1[2];
++*(_QWORD *)(a1 + 80);
*v1 = *v12;
memcpy(v12, v1, 4LL * x86_trace_cache_trace_size + 36);
memset(*(void **)(a1 + 8), 0, 4LL * x86_trace_cache_trace_size + 36);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
_DWORD *v1; // r8
unsigned int v3; // er10
int v4; // ecx
int v5; // ecx
int v6; // eax
unsigned int v7; // edx
int v8; // esi
__int64 v9; // r11
_DWORD *v10; // rax
int v11; // ecx
_DWORD *v12; // r9
int v13; // edi
int v14; // ecx
_DWORD *v15; // rsi

v1 = *(_DWORD **)(a1 + 8);
if ( v1[2] )
{
v3 = v1[1];
if ( !v3 )
_assert_fail("trace->tag", "trace-cache.c", 0xAAu, "x86_trace_cache_flush_trace");
if ( v1[8] )
{
v4 = v1[6];
if ( !v4 )
_assert_fail("trace->branch_count", "trace-cache.c", 0xB1u, "x86_trace_cache_flush_trace");
v5 = v4 - 1;
v1[6] = v5;
v6 = __ROL4__(-2, v5);
v1[4] &= v6;
v1[5] &= v6;
}
v7 = v3 % x86_trace_cache_num_sets;
v8 = x86_trace_cache_assoc;
if ( x86_trace_cache_assoc <= 0 )
goto LABEL_22;
v9 = 4LL * x86_trace_cache_trace_size + 36;
v10 = (_DWORD *)(*(_QWORD *)a1 + v9 * (int)(x86_trace_cache_assoc * v7));
v11 = 0;
do
{
v12 = v10;
v13 = v10[1];
if ( v3 == v13 )
{
if ( v10[4] == v1[4] && v10[5] == v1[5] )
goto LABEL_14;
}
else if ( !v13 )
{
goto LABEL_14;
}
++v11;
v10 = (_DWORD *)((char *)v10 + v9);
}
while ( v11 != x86_trace_cache_assoc );
v14 = 0;
v12 = 0LL;
do
{
v15 = (_DWORD *)(*(_QWORD *)a1 + 4 * (x86_trace_cache_trace_size + 9LL) * (int)(v14 + v7 * v8));
if ( --*v15 < 0 )
{
*v15 = x86_trace_cache_assoc - 1;
v12 = v15;
}
++v14;
v8 = x86_trace_cache_assoc;
}
while ( x86_trace_cache_assoc > v14 );
if ( !v12 )
LABEL_22:
_assert_fail("found", "trace-cache.c", 0xD9u, "x86_trace_cache_flush_trace");
LABEL_14:
*(_QWORD *)(a1 + 72) += (int)v1[2];
++*(_QWORD *)(a1 + 80);
*v1 = *v12;
memcpy(v12, v1, 4LL * x86_trace_cache_trace_size + 36);
memset(*(void **)(a1 + 8), 0, 4LL * x86_trace_cache_trace_size + 36);
}
}

original_code:
static void x86_trace_cache_flush_trace(struct x86_trace_cache_t *trace_cache)
{
 struct x86_trace_cache_entry_t *entry, *found = ((void *)0);
 struct x86_trace_cache_entry_t *trace = trace_cache->temp;
 int set;
 int way;
 if (!trace->uop_count)
  return;
 ((void) sizeof ((trace->tag) ? 1 : 0), __extension__ ({ if (trace->tag) ; else __assert_fail ("trace->tag", "trace-cache.c", 170, __extension__ __PRETTY_FUNCTION__); }));
 if (trace->target)
 {
  ((void) sizeof ((trace->branch_count) ? 1 : 0), __extension__ ({ if (trace->branch_count) ; else __assert_fail ("trace->branch_count", "trace-cache.c", 177, __extension__ __PRETTY_FUNCTION__); }));
  trace->branch_count--;
  trace->branch_mask &= ~(1 << trace->branch_count);
  trace->branch_flags &= ~(1 << trace->branch_count);
 }
 set = trace->tag % x86_trace_cache_num_sets;
 for (way = 0; way < x86_trace_cache_assoc; way++)
 {
  entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
  if (entry->tag == trace->tag && entry->branch_mask == trace->branch_mask
   && entry->branch_flags == trace->branch_flags)
  {
   found = entry;
   break;
  }
  if (!entry->tag) {
   found = entry;
   break;
  }
 }
 if (!found)
 {
  for (way = 0; way < x86_trace_cache_assoc; way++)
  {
   entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
   entry->counter--;
   if (entry->counter < 0) {
    entry->counter = x86_trace_cache_assoc - 1;
    found = entry;
   }
  }
 }
 ((void) sizeof ((found) ? 1 : 0), __extension__ ({ if (found) ; else __assert_fail ("found", "trace-cache.c", 217, __extension__ __PRETTY_FUNCTION__); }));
 trace_cache->trace_length_acc += trace->uop_count;
 trace_cache->trace_length_count++;
 trace->counter = found->counter;
 memcpy(found, trace, (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size));
 memset(trace_cache->temp, 0, (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size));
}

canonical_original_code:
static void x86_trace_cache_flush_trace(struct x86_trace_cache_t *trace_cache)
{
 struct x86_trace_cache_entry_t *entry; struct x86_trace_cache_entry_t *found = ((void *)0);
 struct x86_trace_cache_entry_t *trace = trace_cache->temp;
 int set;
 int way;
 if (!trace->uop_count)
  return;
 ((void) sizeof ((trace->tag) ? 1 : 0), __extension__ ({ if (trace->tag) ; else __assert_fail ("trace->tag", "trace-cache.c", 170, __extension__ __PRETTY_FUNCTION__); }));
 if (trace->target)
 {
  ((void) sizeof ((trace->branch_count) ? 1 : 0), __extension__ ({ if (trace->branch_count) ; else __assert_fail ("trace->branch_count", "trace-cache.c", 177, __extension__ __PRETTY_FUNCTION__); }));
  trace->branch_count--;
  trace->branch_mask &= ~(1 << trace->branch_count);
  trace->branch_flags &= ~(1 << trace->branch_count);
 }
 set = trace->tag % x86_trace_cache_num_sets;
 for (way = 0; way < x86_trace_cache_assoc; way++)
 {
  entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
  if (entry->tag == trace->tag && entry->branch_mask == trace->branch_mask
   && entry->branch_flags == trace->branch_flags)
  {
   found = entry;
   break;
  }
  if (!entry->tag) {
   found = entry;
   break;
  }
 }
 if (!found)
 {
  for (way = 0; way < x86_trace_cache_assoc; way++)
  {
   entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
   entry->counter--;
   if (entry->counter < 0) {
    entry->counter = x86_trace_cache_assoc - 1;
    found = entry;
   }
  }
 }
 ((void) sizeof ((found) ? 1 : 0), __extension__ ({ if (found) ; else __assert_fail ("found", "trace-cache.c", 217, __extension__ __PRETTY_FUNCTION__); }));
 trace_cache->trace_length_acc += trace->uop_count;
 trace_cache->trace_length_count++;
 trace->counter = found->counter;
 memcpy(found, trace, (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size));
 memset(trace_cache->temp, 0, (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size));
}

variable_types: struct x86_trace_cache_t { struct x86_trace_cache_entry_t { int counter; unsigned int tag; int uop_count; int branch_mask; unsigned int fall_through; unsigned int target; unsigned int mop_array[]; } *entry; struct x86_trace_cache_entry_t *temp; char name[20]; long long accesses; long long hits; long long committed; long long squashed; long long trace_length_acc; long long trace_length_count; } *

variable_types: set int

variable_types: way int

user_defined_types: struct x86_trace_cache_t { struct x86_trace_cache_entry_t *entry; struct x86_trace_cache_entry_t *temp; char name[20]; long long accesses; long long hits; long long committed; long long squashed; long long trace_length_acc; long long trace_length_count; }


decompiled_code:
__int64 *x86_trace_cache_create()
{
__int64 *v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
int i; // esi
int j; // ecx
int v6; // eax

v0 = (__int64 *)mhandle_calloc(1LL, 88LL, "trace-cache.c:97");
if ( !v0 )
fatal("%s: out of memory", "x86_trace_cache_create");
v1 = mhandle_calloc(
x86_trace_cache_assoc * x86_trace_cache_num_sets,
4LL * x86_trace_cache_trace_size + 36,
"trace-cache.c:102");
*v0 = v1;
if ( !v1 )
fatal("%s: out of memory", "x86_trace_cache_create");
v2 = mhandle_calloc(1LL, 4LL * x86_trace_cache_trace_size + 36, "trace-cache.c:107");
v0[1] = v2;
if ( !v2 )
fatal("%s: out of memory", "x86_trace_cache_create");
for ( i = 0; x86_trace_cache_num_sets > i; ++i )
{
v6 = x86_trace_cache_assoc;
for ( j = 0; x86_trace_cache_assoc > j; v6 = x86_trace_cache_assoc )
{
*(_DWORD *)(*v0 + 4 * (x86_trace_cache_trace_size + 9LL) * (j + i * v6)) = j;
++j;
}
}
return v0;
}

canonical_decompiled_code:
__int64 *func1()
{
__int64 *v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
int i; // esi
int j; // ecx
int v6; // eax

v0 = (__int64 *)mhandle_calloc(1LL, 88LL, "trace-cache.c:97");
if ( !v0 )
fatal("%s: out of memory", "x86_trace_cache_create");
v1 = mhandle_calloc(
x86_trace_cache_assoc * x86_trace_cache_num_sets,
4LL * x86_trace_cache_trace_size + 36,
"trace-cache.c:102");
*v0 = v1;
if ( !v1 )
fatal("%s: out of memory", "x86_trace_cache_create");
v2 = mhandle_calloc(1LL, 4LL * x86_trace_cache_trace_size + 36, "trace-cache.c:107");
v0[1] = v2;
if ( !v2 )
fatal("%s: out of memory", "x86_trace_cache_create");
for ( i = 0; x86_trace_cache_num_sets > i; ++i )
{
v6 = x86_trace_cache_assoc;
for ( j = 0; x86_trace_cache_assoc > j; v6 = x86_trace_cache_assoc )
{
*(_DWORD *)(*v0 + 4 * (x86_trace_cache_trace_size + 9LL) * (j + i * v6)) = j;
++j;
}
}
return v0;
}

original_code:
struct x86_trace_cache_t *x86_trace_cache_create()
{
 struct x86_trace_cache_t *trace_cache;
 struct x86_trace_cache_entry_t *entry;
 int set;
 int way;
 trace_cache = (mhandle_calloc(1, sizeof(struct x86_trace_cache_t), "trace-cache.c" ":" "97"));
 if (!trace_cache)
  fatal("%s: out of memory", __FUNCTION__);
 trace_cache->entry = (mhandle_calloc(x86_trace_cache_num_sets * x86_trace_cache_assoc, (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size), "trace-cache.c" ":" "102"));
 if (!trace_cache->entry)
  fatal("%s: out of memory", __FUNCTION__);
 trace_cache->temp = (mhandle_calloc(1, (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size), "trace-cache.c" ":" "107"));
 if (!trace_cache->temp)
  fatal("%s: out of memory", __FUNCTION__);
 for (set = 0; set < x86_trace_cache_num_sets; set++)
 {
  for (way = 0; way < x86_trace_cache_assoc; way++)
  {
   entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
   entry->counter = way;
  }
 }
 return trace_cache;
}

canonical_original_code:
struct x86_trace_cache_t *x86_trace_cache_create()
{
 struct x86_trace_cache_t *trace_cache;
 struct x86_trace_cache_entry_t *entry;
 int set;
 int way;
 trace_cache = (mhandle_calloc(1, sizeof(struct x86_trace_cache_t), "trace-cache.c" ":" "97"));
 if (!trace_cache)
  fatal("%s: out of memory", __FUNCTION__);
 trace_cache->entry = (mhandle_calloc(x86_trace_cache_num_sets * x86_trace_cache_assoc, (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size), "trace-cache.c" ":" "102"));
 if (!trace_cache->entry)
  fatal("%s: out of memory", __FUNCTION__);
 trace_cache->temp = (mhandle_calloc(1, (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size), "trace-cache.c" ":" "107"));
 if (!trace_cache->temp)
  fatal("%s: out of memory", __FUNCTION__);
 for (set = 0; set < x86_trace_cache_num_sets; set++)
 {
  for (way = 0; way < x86_trace_cache_assoc; way++)
  {
   entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
   entry->counter = way;
  }
 }
 return trace_cache;
}

return_type: struct x86_trace_cache_t { struct x86_trace_cache_entry_t { int counter; unsigned int tag; int uop_count; int branch_mask; unsigned int fall_through; unsigned int target; unsigned int mop_array[]; } *entry; struct x86_trace_cache_entry_t *temp; char name[20]; long long accesses; long long hits; long long committed; long long squashed; long long trace_length_acc; long long trace_length_count; } *


decompiled_code:
void x86_trace_cache_init()
{
__int64 v0; // r12
int i; // er13
__int64 v2; // r14
int j; // ebx
__int64 v4; // rbp

if ( x86_trace_cache_present )
{
fatal(
"trace cache temporarily not supported.\n"
"\tAs of SVN Rev. 330, a new mechanism has been implemented for x86 CISC\n"
"\tinstructions decoding. This is a more accurate mechanism that is not\n"
"\tcompatible with the old trace cache model. To request this update, please\n"
"\temail development@multi2sim.org, or use the Multi2Sim forum.\n");
if ( (x86_trace_cache_num_sets & (x86_trace_cache_num_sets - 1)) != 0 || !x86_trace_cache_num_sets )
fatal("trace cache sets must be power of 2 and > 0");
if ( (x86_trace_cache_assoc & (x86_trace_cache_assoc - 1)) != 0 || !x86_trace_cache_assoc )
fatal("trace cache associativity must be power of 2 and > 0");
if ( !x86_trace_cache_trace_size || !x86_trace_cache_branch_max )
fatal("trace cache: max number of branches and micro-instructions must be > 0");
if ( x86_trace_cache_branch_max > x86_trace_cache_trace_size )
fatal("max branches in trace cache cannot be greater than trace size");
if ( x86_trace_cache_branch_max > 31 )
fatal("max branches must be less than 32");
v0 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v0 += 1824LL )
{
v4 = 0LL;
for ( j = 0; x86_cpu_num_threads > j; v4 += 1904LL )
{
v2 = *(_QWORD *)(*x86_cpu + v0) + v4;
*(_QWORD *)(v2 + 104) = x86_trace_cache_create();
sprintf(
(char *)(*(_QWORD *)(*(_QWORD *)(*x86_cpu + v0) + v4 + 104) + 16LL),
"c%dt%d.trace_cache",
(unsigned int)i,
(unsigned int)j++);
}
++i;
}
}
}

canonical_decompiled_code:
void func2()
{
__int64 v0; // r12
int i; // er13
__int64 v2; // r14
int j; // ebx
__int64 v4; // rbp

if ( x86_trace_cache_present )
{
fatal(
"trace cache temporarily not supported.\n"
"\tAs of SVN Rev. 330, a new mechanism has been implemented for x86 CISC\n"
"\tinstructions decoding. This is a more accurate mechanism that is not\n"
"\tcompatible with the old trace cache model. To request this update, please\n"
"\temail development@multi2sim.org, or use the Multi2Sim forum.\n");
if ( (x86_trace_cache_num_sets & (x86_trace_cache_num_sets - 1)) != 0 || !x86_trace_cache_num_sets )
fatal("trace cache sets must be power of 2 and > 0");
if ( (x86_trace_cache_assoc & (x86_trace_cache_assoc - 1)) != 0 || !x86_trace_cache_assoc )
fatal("trace cache associativity must be power of 2 and > 0");
if ( !x86_trace_cache_trace_size || !x86_trace_cache_branch_max )
fatal("trace cache: max number of branches and micro-instructions must be > 0");
if ( x86_trace_cache_branch_max > x86_trace_cache_trace_size )
fatal("max branches in trace cache cannot be greater than trace size");
if ( x86_trace_cache_branch_max > 31 )
fatal("max branches must be less than 32");
v0 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v0 += 1824LL )
{
v4 = 0LL;
for ( j = 0; x86_cpu_num_threads > j; v4 += 1904LL )
{
v2 = *(_QWORD *)(*x86_cpu + v0) + v4;
*(_QWORD *)(v2 + 104) = func1();
sprintf(
(char *)(*(_QWORD *)(*(_QWORD *)(*x86_cpu + v0) + v4 + 104) + 16LL),
"c%dt%d.trace_cache",
(unsigned int)i,
(unsigned int)j++);
}
++i;
}
}
}

original_code:
void x86_trace_cache_init()
{
 int core;
 int thread;
 if (!x86_trace_cache_present)
  return;
 fatal("trace cache temporarily not supported.\n"
  "\tAs of SVN Rev. 330, a new mechanism has been implemented for x86 CISC\n"
  "\tinstructions decoding. This is a more accurate mechanism that is not\n"
  "\tcompatible with the old trace cache model. To request this update, please\n"
  "\temail development@multi2sim.org, or use the Multi2Sim forum.\n");
 if ((x86_trace_cache_num_sets & (x86_trace_cache_num_sets - 1)) || !x86_trace_cache_num_sets)
  fatal("trace cache sets must be power of 2 and > 0");
 if ((x86_trace_cache_assoc & (x86_trace_cache_assoc - 1)) || !x86_trace_cache_assoc)
  fatal("trace cache associativity must be power of 2 and > 0");
 if (!x86_trace_cache_trace_size || !x86_trace_cache_branch_max)
  fatal("trace cache: max number of branches and micro-instructions must be > 0");
 if (x86_trace_cache_branch_max > x86_trace_cache_trace_size)
  fatal("max branches in trace cache cannot be greater than trace size");
 if (x86_trace_cache_branch_max > 31)
  fatal("max branches must be less than 32");
 for (core = 0; core < x86_cpu_num_cores; core++) for (thread = 0; thread < x86_cpu_num_threads; thread++)
 {
  (x86_cpu->core[core].thread[thread]).trace_cache = x86_trace_cache_create();
  sprintf((x86_cpu->core[core].thread[thread]).trace_cache->name, "c%dt%d.trace_cache", core, thread);
 }
}

variable_types: core int

variable_types: thread int


decompiled_code:
__int64 __fastcall x86_trace_cache_free(_QWORD *a1)
{
mhandle_free(*a1, "trace-cache.c:128");
mhandle_free(a1[1], "trace-cache.c:129");
return mhandle_free(a1, "trace-cache.c:130");
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
mhandle_free(*a1, "trace-cache.c:128");
mhandle_free(a1[1], "trace-cache.c:129");
return mhandle_free(a1, "trace-cache.c:130");
}

original_code:
void x86_trace_cache_free(struct x86_trace_cache_t *trace_cache)
{
 (mhandle_free(trace_cache->entry, "trace-cache.c" ":" "128"));
 (mhandle_free(trace_cache->temp, "trace-cache.c" ":" "129"));
 (mhandle_free(trace_cache, "trace-cache.c" ":" "130"));
}

user_defined_types: struct x86_trace_cache_entry_t { int counter; unsigned int tag; int uop_count; int branch_mask; unsigned int fall_through; unsigned int target; unsigned int mop_array[]; }


decompiled_code:
__int64 x86_trace_cache_done()
{
__int64 v0; // rbp
int i; // er12
__int64 result; // rax
__int64 j; // rbx

if ( x86_trace_cache_present )
{
v0 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v0 += 1824LL )
{
for ( j = 0LL; x86_cpu_num_threads > (int)j; ++j )
result = x86_trace_cache_free(*(_QWORD **)(*(_QWORD *)(*x86_cpu + v0) + 1904 * j + 104));
++i;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbp
int i; // er12
__int64 result; // rax
__int64 j; // rbx

if ( x86_trace_cache_present )
{
v0 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v0 += 1824LL )
{
for ( j = 0LL; x86_cpu_num_threads > (int)j; ++j )
result = func3(*(_QWORD **)(*(_QWORD *)(*x86_cpu + v0) + 1904 * j + 104));
++i;
}
}
return result;
}

original_code:
void x86_trace_cache_done()
{
 int core;
 int thread;
 if (!x86_trace_cache_present)
  return;
 for (core = 0; core < x86_cpu_num_cores; core++) for (thread = 0; thread < x86_cpu_num_threads; thread++)
  x86_trace_cache_free((x86_cpu->core[core].thread[thread]).trace_cache);
}


decompiled_code:
__int64 __fastcall x86_trace_cache_lookup(_QWORD *a1, unsigned int a2, int a3, _DWORD *a4, _QWORD *a5, _DWORD *a6)
{
__int64 v8; // rbp
_DWORD *v9; // rdx
int v10; // ecx
_DWORD *v11; // rax
int v12; // edx
__int64 result; // rax

if ( x86_trace_cache_assoc <= 0 )
{
LABEL_17:
++a1[5];
result = 0LL;
}
else
{
v8 = 4LL * x86_trace_cache_trace_size + 36;
v9 = (_DWORD *)(*a1 + v8 * (int)(x86_trace_cache_assoc * (a2 % x86_trace_cache_num_sets)));
v10 = 0;
while ( 1 )
{
v11 = v9;
if ( v9[1] == a2 && (v9[4] & a3) == v9[5] )
break;
++v10;
v9 = (_DWORD *)((char *)v9 + v8);
if ( v10 == x86_trace_cache_assoc )
goto LABEL_17;
}
++a1[5];
++a1[6];
v12 = v9[8];
if ( !v12 || !_bittest(&a3, v11[6]) )
v12 = v11[7];
if ( a4 )
*a4 = v11[3];
if ( a5 )
*a5 = v11 + 9;
result = 1LL;
if ( a6 )
*a6 = v12;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, unsigned int a2, int a3, _DWORD *a4, _QWORD *a5, _DWORD *a6)
{
__int64 v8; // rbp
_DWORD *v9; // rdx
int v10; // ecx
_DWORD *v11; // rax
int v12; // edx
__int64 result; // rax

if ( x86_trace_cache_assoc <= 0 )
{
LABEL_17:
++a1[5];
result = 0LL;
}
else
{
v8 = 4LL * x86_trace_cache_trace_size + 36;
v9 = (_DWORD *)(*a1 + v8 * (int)(x86_trace_cache_assoc * (a2 % x86_trace_cache_num_sets)));
v10 = 0;
while ( 1 )
{
v11 = v9;
if ( v9[1] == a2 && (v9[4] & a3) == v9[5] )
break;
++v10;
v9 = (_DWORD *)((char *)v9 + v8);
if ( v10 == x86_trace_cache_assoc )
goto LABEL_17;
}
++a1[5];
++a1[6];
v12 = v9[8];
if ( !v12 || !_bittest(&a3, v11[6]) )
v12 = v11[7];
if ( a4 )
*a4 = v11[3];
if ( a5 )
*a5 = v11 + 9;
result = 1LL;
if ( a6 )
*a6 = v12;
}
return result;
}

original_code:
int x86_trace_cache_lookup(struct x86_trace_cache_t *trace_cache, uint32_t eip, int pred,
 int *ptr_mop_count, uint32_t **ptr_mop_array, uint32_t *ptr_neip)
{
 struct x86_trace_cache_entry_t *entry = ((void *)0), *found = ((void *)0);
 int set, way;
 uint32_t neip;
 set = eip % x86_trace_cache_num_sets;
 for (way = 0; way < x86_trace_cache_assoc; way++)
 {
  entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(uint32_t) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
  if (entry->tag == eip && ((pred & entry->branch_mask) == entry->branch_flags))
  {
   found = entry;
   break;
  }
 }
 trace_cache->accesses++;
 if (!found)
  return 0;
 trace_cache->hits++;
 neip = entry->target && (pred & (1 << entry->branch_count)) ?
  entry->target : entry->fall_through;
 if (ptr_mop_count) *(ptr_mop_count) = (entry->mop_count);
 if (ptr_mop_array) *(ptr_mop_array) = (entry->mop_array);
 if (ptr_neip) *(ptr_neip) = (neip);
 return 1;
}

canonical_original_code:
int x86_trace_cache_lookup(struct x86_trace_cache_t *trace_cache, unsigned int eip, int pred, int *ptr_mop_count, unsigned int **ptr_mop_array, unsigned int *ptr_neip)
{
 struct x86_trace_cache_entry_t *entry = ((void *)0); struct x86_trace_cache_entry_t *found = ((void *)0);
 int set; int way;
 unsigned int neip;
 set = eip % x86_trace_cache_num_sets;
 for (way = 0; way < x86_trace_cache_assoc; way++)
 {
  entry = ((struct x86_trace_cache_entry_t *) (((unsigned char *) trace_cache->entry) + (sizeof(struct x86_trace_cache_entry_t) + sizeof(unsigned int) * x86_trace_cache_trace_size) * ((set) * x86_trace_cache_assoc + (way))));
  if (entry->tag == eip && ((pred & entry->branch_mask) == entry->branch_flags))
  {
   found = entry;
   break;
  }
 }
 trace_cache->accesses++;
 if (!found)
  return 0;
 trace_cache->hits++;
 neip = entry->target && (pred & (1 << entry->branch_count)) ?
  entry->target : entry->fall_through;
 if (ptr_mop_count) *(ptr_mop_count) = (entry->mop_count);
 if (ptr_mop_array) *(ptr_mop_array) = (entry->mop_array);
 if (ptr_neip) *(ptr_neip) = (neip);
 return 1;
}

variable_types:
eip
unsigned int

variable_types: pred int

variable_types: struct x86_trace_cache_entry_t { int counter; unsigned int tag; int uop_count; int branch_mask; unsigned int fall_through; unsigned int target; unsigned int mop_array[]; } *

variable_types:
neip
unsigned int


decompiled_code:
__int64 __fastcall heap_grow(__int64 a1)
{
int v1; // ebp
__int64 v2; // rax

v1 = 2 * *(_DWORD *)a1;
v2 = mhandle_realloc(*(_QWORD *)(a1 + 32), 24LL * v1, "heap.c:69");
if ( !v2 )
return 0LL;
*(_QWORD *)(a1 + 32) = v2;
*(_DWORD *)a1 = v1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebp
__int64 v2; // rax

v1 = 2 * *(_DWORD *)a1;
v2 = mhandle_realloc(*(_QWORD *)(a1 + 32), 24LL * v1, "heap.c:69");
if ( !v2 )
return 0LL;
*(_QWORD *)(a1 + 32) = v2;
*(_DWORD *)a1 = v1;
return 1LL;
}

original_code:
static int heap_grow(struct heap_t *heap)
{
 struct heap_elem_t *nelem;
 int nsize = heap->size * 2;
 nelem = (mhandle_realloc(heap->elem, nsize * sizeof(struct heap_elem_t), "heap.c" ":" "69"));
 if (!nelem)
  return 0;
 heap->elem = nelem;
 heap->size = nsize;
 return 1;
}

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: nsize int

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


decompiled_code:
int *__fastcall heap_create(int a1)
{
int v1; // ebx
int *v2; // rax
int *v3; // rbp
__int64 v4; // rax

v1 = a1;
v2 = (int *)mhandle_calloc(1LL, 40LL, "heap.c:111");
v3 = v2;
if ( a1 < 10 )
v1 = 10;
*v2 = v1;
v4 = mhandle_calloc(v1, 24LL, "heap.c:113");
*((_QWORD *)v3 + 4) = v4;
if ( !v4 )
{
mhandle_free(v3, "heap.c:115");
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
int *__fastcall func3(int a1)
{
int v1; // ebx
int *v2; // rax
int *v3; // rbp
__int64 v4; // rax

v1 = a1;
v2 = (int *)mhandle_calloc(1LL, 40LL, "heap.c:111");
v3 = v2;
if ( a1 < 10 )
v1 = 10;
*v2 = v1;
v4 = mhandle_calloc(v1, 24LL, "heap.c:113");
*((_QWORD *)v3 + 4) = v4;
if ( !v4 )
{
mhandle_free(v3, "heap.c:115");
v3 = 0LL;
}
return v3;
}

original_code:
struct heap_t *heap_create(int size)
{
 struct heap_t *heap;
 heap = (mhandle_calloc(1, sizeof(struct heap_t), "heap.c" ":" "111"));
 heap->size = size < 10 ? 10 : size;
 heap->elem = (mhandle_calloc(heap->size, sizeof(struct heap_elem_t), "heap.c" ":" "113"));
 if (!heap->elem) {
  (mhandle_free(heap, "heap.c" ":" "115"));
  return ((void *)0);
 }
 return heap;
}

variable_types: size int

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


decompiled_code:
__int64 __fastcall heap_free(__int64 a1)
{
mhandle_free(*(_QWORD *)(a1 + 32), "heap.c:125");
return mhandle_free(a1, "heap.c:126");
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
mhandle_free(*(_QWORD *)(a1 + 32), "heap.c:125");
return mhandle_free(a1, "heap.c:126");
}

original_code:
void heap_free(struct heap_t *heap)
{
 (mhandle_free(heap->elem, "heap.c" ":" "125"));
 (mhandle_free(heap, "heap.c" ":" "126"));
}

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 heap_error(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int heap_error(struct heap_t *heap)
{
 return heap->error;
}


decompiled_code:
const char *__fastcall heap_error_msg(__int64 a1)
{
int v1; // edx
const char *result; // rax

v1 = *(_DWORD *)(a1 + 12);
result = "out of memory";
if ( v1 != 1 )
{
result = (const char *)&unk_4A9;
if ( v1 == 2 )
result = "heap is empty";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func6(__int64 a1)
{
int v1; // edx
const char *result; // rax

v1 = *(_DWORD *)(a1 + 12);
result = "out of memory";
if ( v1 != 1 )
{
result = (const char *)&unk_4A9;
if ( v1 == 2 )
result = "heap is empty";
}
return result;
}

original_code:
char *heap_error_msg(struct heap_t *heap)
{
 switch (heap->error) {
 case 1: return "out of memory";
 case 2: return "heap is empty";
 }
 return "";
}


decompiled_code:
__int64 __fastcall heap_count(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int heap_count(struct heap_t *heap)
{
 return heap->count;
}


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

variable_types:
data
void **

variable_types:
value
long long

return_type: long long


original_code:
long long heap_extract(struct heap_t *heap, void **data)
{
 long long value;
 value = heap_peek(heap, data);
 if (heap->error)
  return 0;
 heap->count--;
 heap->elem[0] = heap->elem[heap->count];
 heapify(heap, 0);
 return value;
}