original_code:
void list_add(struct list_t *list, void *elem)
{
 if (list->count == list->size)
  list_grow(list);
 list->elem[list->tail] = elem;
 list->tail = (list->tail + 1) % list->size;
 list->count++;
 list->error_code = LIST_ERR_OK;
}

variable_types:
elem
void *


original_code:
void *list_get(struct list_t *list, int index)
{
 if (index < 0 || index >= list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return ((void *)0);
 }
 index = (index + list->head) % list->size;
 list->error_code = LIST_ERR_OK;
 return list->elem[index];
}

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

variable_types: index int

return_type: void *


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

result = (unsigned int)a2;
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
{
*(_DWORD *)(a1 + 4) = 1;
}
else
{
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(result + 8LL * ((*(_DWORD *)(a1 + 12) + a2) % *(_DWORD *)(a1 + 8))) = a3;
*(_DWORD *)(a1 + 4) = 0;
}
return result;
}

original_code:
void list_set(struct list_t *list, int index, void *elem)
{
 if (index < 0 || index >= list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return;
 }
 index = (index + list->head) % list->size;
 list->elem[index] = elem;
 list->error_code = LIST_ERR_OK;
}

return_type: void

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


original_code:
void list_insert(struct list_t *list, int index, void *elem)
{
 int shiftcount;
 int pos;
 int i;
 if (index < 0 || index > list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return;
 }
 if (list->count == list->size)
  list_grow(list);
 if (index > list->count / 2)
 {
  shiftcount = list->count - index;
  for (i = 0, pos = list->tail;
    i < shiftcount;
    i++, pos = (((pos - 1) + list->size) % list->size))
   list->elem[pos] = list->elem[(((pos - 1) + list->size) % list->size)];
  list->tail = (list->tail + 1) % list->size;
 }
 else
 {
  for (i = 0, pos = list->head;
    i < index;
    i++, pos = (pos + 1) % list->size)
   list->elem[(((pos - 1) + list->size) % list->size)] = list->elem[pos];
  list->head = (((list->head - 1) + list->size) % list->size);
 }
 list->elem[(list->head + index) % list->size] = elem;
 list->count++;
 list->error_code = LIST_ERR_OK;
}

variable_types: shiftcount int

variable_types: pos int

variable_types: i int


decompiled_code:
__int64 __fastcall list_index_of(__int64 a1, __int64 a2)
{
int v2; // ecx
int v3; // edx
unsigned int v4; // er8
__int64 result; // rax

v2 = *(_DWORD *)a1;
v3 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 4) = 0;
if ( v2 <= 0 )
{
LABEL_6:
*(_DWORD *)(a1 + 4) = 2;
result = 0xFFFFFFFFLL;
}
else
{
v4 = 0;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL * v3) != a2 )
{
++v4;
v3 = (v3 + 1) % *(_DWORD *)(a1 + 8);
if ( v4 == v2 )
goto LABEL_6;
}
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v2; // ecx
int v3; // edx
unsigned int v4; // er8
__int64 result; // rax

v2 = *(_DWORD *)a1;
v3 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 4) = 0;
if ( v2 <= 0 )
{
LABEL_6:
*(_DWORD *)(a1 + 4) = 2;
result = 0xFFFFFFFFLL;
}
else
{
v4 = 0;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL * v3) != a2 )
{
++v4;
v3 = (v3 + 1) % *(_DWORD *)(a1 + 8);
if ( v4 == v2 )
goto LABEL_6;
}
result = v4;
}
return result;
}

original_code:
int list_index_of(struct list_t *list, void *elem)
{
 int pos;
 int i;
 list->error_code = LIST_ERR_OK;
 for (i = 0, pos = list->head;
  i < list->count;
  i++, pos = (pos + 1) % list->size)
 {
  if (list->elem[pos] == elem)
   return i;
 }
 list->error_code = LIST_ERR_NOT_FOUND;
 return -1;
}

return_type: int


original_code:
void *list_remove_at(struct list_t *list, int index)
{
 int shiftcount;
 int pos;
 int i;
 void *elem;
 if (index < 0 || index >= list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return ((void *)0);
 }
 elem = list->elem[(list->head + index) % list->size];
 if (index > list->count / 2)
 {
  shiftcount = list->count - index - 1;
  for (i = 0, pos = (list->head + index) % list->size;
    i < shiftcount;
    i++, pos = (pos + 1) % list->size)
   list->elem[pos] = list->elem[(pos + 1) % list->size];
  list->elem[pos] = ((void *)0);
  list->tail = (((list->tail - 1) + list->size) % list->size);
 }
 else
 {
  for (i = 0, pos = (list->head + index) % list->size;
    i < index;
    i++, pos = (((pos - 1) + list->size) % list->size))
   list->elem[pos] = list->elem[(((pos - 1) + list->size) % list->size)];
  list->elem[list->head] = ((void *)0);
  list->head = (list->head + 1) % list->size;
 }
 list->count--;
 list->error_code = LIST_ERR_OK;
 return elem;
}


decompiled_code:
__int64 __fastcall list_remove(__int64 a1, __int64 a2)
{
int v2; // esi
__int64 result; // rax

v2 = list_index_of(a1, a2);
if ( *(_DWORD *)(a1 + 4) )
result = 0LL;
else
result = list_remove_at(a1, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // esi
__int64 result; // rax

v2 = func10(a1, a2);
if ( *(_DWORD *)(a1 + 4) )
result = 0LL;
else
result = func11(a1, v2);
return result;
}

original_code:
void *list_remove(struct list_t *list, void *elem)
{
 int index;
 index = list_index_of(list, elem);
 if (list->error_code)
  return ((void *)0);
 return list_remove_at(list, index);
}


decompiled_code:
__int64 __fastcall list_sort(_DWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64))
{
__int64 result; // rax

if ( *a1 )
result = sort((__int64)a1, 0, *a1 - 1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64))
{
__int64 result; // rax

if ( *a1 )
result = func0((__int64)a1, 0, *a1 - 1, a2);
return result;
}

original_code:
void list_sort(struct list_t *list, int (*comp)(const void *, const void *))
{
 if (list->count)
  sort(list, 0, list->count - 1, comp);
}

canonical_original_code:
void list_sort(struct list_t *list, int (*comp)(void *, void *))
{
 if (list->count)
  sort(list, 0, list->count - 1, comp);
}

variable_types:
comp
int (*)(void *, void *)


decompiled_code:
// attributes: thunk
__int64 __fastcall list_push(__int64 a1, __int64 a2)
{
return list_add(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return func6(a1, a2);
}

original_code:
void list_push(struct list_t *list, void *elem)
{
 list_add(list, elem);
}


decompiled_code:
__int64 __fastcall list_pop(_DWORD *a1)
{
if ( *a1 )
return list_remove_at((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1)
{
if ( *a1 )
return func11((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_pop(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_remove_at(list, list->count - 1);
}


decompiled_code:
__int64 __fastcall list_top(_DWORD *a1)
{
if ( *a1 )
return list_get((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(_DWORD *a1)
{
if ( *a1 )
return func7((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_top(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, list->count - 1);
}


decompiled_code:
__int64 __fastcall list_bottom(_DWORD *a1)
{
if ( *a1 )
return list_get((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(_DWORD *a1)
{
if ( *a1 )
return func7((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_bottom(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, 0);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall list_enqueue(__int64 a1, __int64 a2)
{
return list_push(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2)
{
return func15(a1, a2);
}

original_code:
void list_enqueue(struct list_t *list, void *elem)
{
 list_add(list, elem);
}


decompiled_code:
__int64 __fastcall list_dequeue(_DWORD *a1)
{
if ( *a1 )
return list_remove_at((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(_DWORD *a1)
{
if ( *a1 )
return func11((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_dequeue(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_remove_at(list, 0);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall list_head(_DWORD *a1)
{
return list_bottom(a1);
}

canonical_decompiled_code:
__int64 __fastcall func21(_DWORD *a1)
{
return func18(a1);
}

original_code:
void *list_head(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, 0);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall list_tail(_DWORD *a1)
{
return list_top(a1);
}

canonical_decompiled_code:
__int64 __fastcall func22(_DWORD *a1)
{
return func17(a1);
}

original_code:
void *list_tail(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, list->count - 1);
}


sort

original_code:
static void sort(struct list_t *list, int lo, int hi,
 int (*comp)(const void *, const void *))
{
 void *ptr, *tmp;
 int i = lo, j = hi;
 ptr = list->elem[((hi) + list->head) % list->size];
 do
 {
  while (comp(list->elem[((i) + list->head) % list->size], ptr) < 0)
   i++;
  while (comp(list->elem[((j) + list->head) % list->size], ptr) > 0)
   j--;
  if (i <= j)
  {
   tmp = list->elem[((i) + list->head) % list->size];
   list->elem[((i) + list->head) % list->size] = list->elem[((j) + list->head) % list->size];
   list->elem[((j) + list->head) % list->size] = tmp;
   i++, j--;
  }
 } while (i <= j);
 if (lo < j)
  sort(list, lo, j, comp);
 if (i < hi)
  sort(list, i, hi, comp);
}

canonical_original_code:
static void sort(struct list_t *list, int lo, int hi, int (*comp)(void *, void *))
{
 void *ptr; void *tmp;
 int i = lo; int j = hi;
 ptr = list->elem[((hi) + list->head) % list->size];
 do
 {
  while (comp(list->elem[((i) + list->head) % list->size], ptr) < 0)
   i++;
  while (comp(list->elem[((j) + list->head) % list->size], ptr) > 0)
   j--;
  if (i <= j)
  {
   tmp = list->elem[((i) + list->head) % list->size];
   list->elem[((i) + list->head) % list->size] = list->elem[((j) + list->head) % list->size];
   list->elem[((j) + list->head) % list->size] = tmp;
   i++, j--;
  }
 } while (i <= j);
 if (lo < j)
  sort(list, lo, j, comp);
 if (i < hi)
  sort(list, i, hi, comp);
}

variable_types: lo int

variable_types: hi int

variable_types:
ptr
void *

variable_types:
tmp
void *

variable_types: j int


decompiled_code:
__int64 __fastcall amd_opengl_shader_set_shader_kind(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // eax

v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 24LL) + 36LL);
switch ( v3 )
{
case 1:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 1 )
{
*(_DWORD *)a1 = 1;
return 1LL;
}
break;
case 2:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 2 )
{
*(_DWORD *)a1 = 0;
return 1LL;
}
break;
case 3:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 3 )
{
*(_DWORD *)a1 = 2;
return 1LL;
}
break;
case 5:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 5 )
{
*(_DWORD *)a1 = 4;
return 1LL;
}
break;
default:
if ( v3 == 6 && *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 6 )
{
*(_DWORD *)a1 = 3;
return 1LL;
}
break;
}
fatal("Unknown shader kind!\n", a2, v2);
return 1LL;
}

original_code:
static int amd_opengl_shader_set_shader_kind(struct evg_opengl_shader_t *opengl_shader)
{
 struct elf_file_t *internal_elf_file;
 struct elf_file_t *external_elf_file;
 internal_elf_file = opengl_shader->internal_elf_file;
 external_elf_file = opengl_shader->external_elf_file;
 if (internal_elf_file->header->e_flags == 0x1 && external_elf_file->header->e_flags == 0x1)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_FRAGMENT;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x2 && external_elf_file->header->e_flags == 0x2)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_VERTEX;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x3 && external_elf_file->header->e_flags == 0x3)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_GEOMETRY;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x5 && external_elf_file->header->e_flags == 0x5)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_CONTROL;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x6 && external_elf_file->header->e_flags == 0x6)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_EVALUATION;
  return 1;
 }
 else
 {
  fatal("Unknown shader kind!\n");
 }
 return 1;
}

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

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

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


decompiled_code:
__int64 __fastcall elf_file_list_create(_DWORD *a1, __int64 a2)
{
__int64 v2; // r14
_DWORD *v3; // r12
_DWORD *v4; // rbx
_DWORD *v5; // rbp
int v6; // eax

v2 = list_create();
if ( a2 != 4 )
{
v3 = (_DWORD *)((char *)a1 + a2 - 4);
v4 = a1;
do
{
while ( *v4 != 1179403647 )
{
v4 = (_DWORD *)((char *)v4 + 1);
if ( v3 == v4 )
return v2;
}
v5 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opengl-bin-file.c:66");
if ( !v5 )
fatal("%s: out of memory", "elf_file_list_create");
v6 = (int)v4;
v4 = (_DWORD *)((char *)v4 + 1);
*v5 = v6 - (_DWORD)a1;
list_add(v2, v5);
}
while ( v3 != v4 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, __int64 a2)
{
__int64 v2; // r14
_DWORD *v3; // r12
_DWORD *v4; // rbx
_DWORD *v5; // rbp
int v6; // eax

v2 = list_create();
if ( a2 != 4 )
{
v3 = (_DWORD *)((char *)a1 + a2 - 4);
v4 = a1;
do
{
while ( *v4 != 1179403647 )
{
v4 = (_DWORD *)((char *)v4 + 1);
if ( v3 == v4 )
return v2;
}
v5 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opengl-bin-file.c:66");
if ( !v5 )
fatal("%s: out of memory", "elf_file_list_create");
v6 = (int)v4;
v4 = (_DWORD *)((char *)v4 + 1);
*v5 = v6 - (_DWORD)a1;
list_add(v2, v5);
}
while ( v3 != v4 );
}
return v2;
}

original_code:
static struct list_t *elf_file_list_create(void *ptr_buffer, size_t buf_size)
{
 const char ELF_magic[4] = { 0x7F, 0x45, 0x4C, 0x46};
 struct list_t *elf_file_list;
 void *ptr_copy;
 int *offset;
 int i;
 elf_file_list = list_create();
 ptr_copy = ptr_buffer;
 for (i = 0; i < buf_size - sizeof(ELF_magic); i++)
 {
  if (memcmp(ptr_copy, ELF_magic, sizeof(ELF_magic)) == 0)
  {
   offset = (mhandle_calloc(1, sizeof(int), "opengl-bin-file.c" ":" "66"));
   if (!offset)
    fatal("%s: out of memory", __FUNCTION__);
   *offset = (int)(ptr_copy - ptr_buffer);
   list_add(elf_file_list, offset);
  }
  ptr_copy++;
 }
 return elf_file_list;
}

canonical_original_code:
static struct list_t *elf_file_list_create(void *ptr_buffer, unsigned long buf_size)
{
 char ELF_magic[4] = { 0x7F, 0x45, 0x4C, 0x46};
 struct list_t *elf_file_list;
 void *ptr_copy;
 int *offset;
 int i;
 elf_file_list = list_create();
 ptr_copy = ptr_buffer;
 for (i = 0; i < buf_size - sizeof(ELF_magic); i++)
 {
  if (memcmp(ptr_copy, ELF_magic, sizeof(ELF_magic)) == 0)
  {
   offset = (mhandle_calloc(1, sizeof(int), "opengl-bin-file.c" ":" "66"));
   if (!offset)
    fatal("%s: out of memory", __FUNCTION__);
   *offset = (int)(ptr_copy - ptr_buffer);
   list_add(elf_file_list, offset);
  }
  ptr_copy++;
 }
 return elf_file_list;
}

variable_types:
offset
int *

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


decompiled_code:
__int64 __fastcall external_elf_file_create(__int64 a1, int a2, __int64 a3, unsigned int a4, __int64 a5)
{
int *v6; // rax

v6 = (int *)list_get(a3, a4);
return elf_file_create_from_buffer(a1 + *v6, (unsigned int)(a2 - *v6), a5);
}

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

v6 = (int *)list_get(a3, a4);
return elf_file_create_from_buffer(a1 + *v6, (unsigned int)(a2 - *v6), a5);
}

original_code:
static struct elf_file_t *external_elf_file_create(void *ptr_buffer, int buf_size, struct list_t *elf_offset_list, int elf_file_index, char *name)
{
 struct elf_file_t *external_elf_file;
 int *external_elf_offset;
 void *external_elf_base;
 int external_elf_size;
 external_elf_offset = list_get(elf_offset_list,elf_file_index);
 external_elf_base = ptr_buffer + *external_elf_offset;
 external_elf_size = buf_size - *external_elf_offset;
 external_elf_file = elf_file_create_from_buffer(external_elf_base, external_elf_size, name);
 return external_elf_file;
}

variable_types:
name
char *

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


decompiled_code:
// attributes: thunk
__int64 internal_elf_file_free()
{
return elf_file_free();
}

canonical_decompiled_code:
__int64 func3()
{
return elf_file_free();
}

original_code:
static void internal_elf_file_free(struct elf_file_t *internal_elf_file)
{
 elf_file_free(internal_elf_file);
}

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

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

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


decompiled_code:
__int64 __fastcall amd_opengl_shader_free(__int64 a1)
{
internal_elf_file_free(*(_QWORD *)(a1 + 8));
internal_elf_file_free(*(_QWORD *)(a1 + 16));
return mhandle_free(a1, "opengl-bin-file.c:365");
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
func3(*(_QWORD *)(a1 + 8));
func3(*(_QWORD *)(a1 + 16));
return mhandle_free(a1, "opengl-bin-file.c:365");
}

original_code:
static void amd_opengl_shader_free(struct evg_opengl_shader_t *opengl_shader)
{
 external_elf_file_free(opengl_shader->external_elf_file);
 internal_elf_file_free(opengl_shader->internal_elf_file);
 (mhandle_free(opengl_shader, "opengl-bin-file.c" ":" "365"));
}

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


decompiled_code:
__int64 __fastcall is_external_elf(__int64 a1, const char *a2)
{
__int64 v2; // rbp
int i; // ebx
bool v4; // cf
bool v5; // zf
const char **v6; // rax
const char *v7; // rdi
__int64 v8; // rcx

v2 = elf_file_create_from_buffer(a1, a2, 0LL);
if ( (unsigned int)list_count(*(_QWORD *)(v2 + 32)) == 5 )
{
for ( i = 0; (int)list_count(*(_QWORD *)(v2 + 32)) > i; ++i )
{
v6 = (const char **)list_get(*(_QWORD *)(v2 + 32), (unsigned int)i);
v7 = "binary";
v8 = 7LL;
a2 = *v6;
do
{
if ( !v8 )
break;
v4 = *a2 < (unsigned int)*v7;
v5 = *a2++ == *v7++;
--v8;
}
while ( v5 );
if ( (!v4 && !v5) == v4 )
{
elf_file_free(v2, a2);
return 0LL;
}
}
}
elf_file_free(v2, a2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
__int64 v2; // rbp
int i; // ebx
bool v4; // cf
bool v5; // zf
const char **v6; // rax
const char *v7; // rdi
__int64 v8; // rcx

v2 = elf_file_create_from_buffer(a1, a2, 0LL);
if ( (unsigned int)list_count(*(_QWORD *)(v2 + 32)) == 5 )
{
for ( i = 0; (int)list_count(*(_QWORD *)(v2 + 32)) > i; ++i )
{
v6 = (const char **)list_get(*(_QWORD *)(v2 + 32), (unsigned int)i);
v7 = "binary";
v8 = 7LL;
a2 = *v6;
do
{
if ( !v8 )
break;
v4 = *a2 < (unsigned int)*v7;
v5 = *a2++ == *v7++;
--v8;
}
while ( v5 );
if ( (!v4 && !v5) == v4 )
{
elf_file_free(v2, a2);
return 0LL;
}
}
}
elf_file_free(v2, a2);
return 0xFFFFFFFFLL;
}

original_code:
static int is_external_elf(void *ptr_buffer, int buf_size)
{
 struct elf_file_t *elf_file;
 int i;
 struct elf_section_t *elf_section;
 elf_file = elf_file_create_from_buffer(ptr_buffer, buf_size, ((void *)0));
 if (list_count(elf_file->section_list) != 5)
 {
  elf_file_free(elf_file);
  return -1;
 }
 else
 {
  for (i = 0; i < list_count(elf_file->section_list); i++)
  {
   elf_section = list_get(elf_file->section_list, i);
   if(!strcmp(elf_section->name,"binary"))
   {
    elf_file_free(elf_file);
    return 0;
   }
  }
  elf_file_free(elf_file);
  return -1;
 }
 return -1;
}

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


decompiled_code:
__int64 __fastcall external_elf_file_list_create(_DWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
__int64 v3; // r13
int *v4; // rax
__int64 v5; // rax

v2 = 0;
v3 = elf_file_list_create(a1, a2);
while ( (int)list_count(v3) > (int)v2 )
{
v4 = (int *)list_get(v3, v2);
if ( (unsigned int)is_external_elf((__int64)a1 + *v4, (const char *)(unsigned int)(a2 - *v4)) )
{
v5 = list_remove_at(v3, v2);
mhandle_free(v5, "opengl-bin-file.c:138");
}
++v2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
__int64 v3; // r13
int *v4; // rax
__int64 v5; // rax

v2 = 0;
v3 = func1(a1, a2);
while ( (int)list_count(v3) > (int)v2 )
{
v4 = (int *)list_get(v3, v2);
if ( (unsigned int)func5((__int64)a1 + *v4, (const char *)(unsigned int)(a2 - *v4)) )
{
v5 = list_remove_at(v3, v2);
mhandle_free(v5, "opengl-bin-file.c:138");
}
++v2;
}
return v3;
}

original_code:
static struct list_t *external_elf_file_list_create(void *ptr_buffer, size_t buf_size)
{
 struct list_t *elf_file_list_external;
 int i;
 int elf_file_size;
 int *offset;
 elf_file_list_external = elf_file_list_create(ptr_buffer, buf_size);
 for (i = 0; i < list_count(elf_file_list_external); i++)
 {
  offset = list_get(elf_file_list_external, i);
  elf_file_size = buf_size - *offset;
  if (is_external_elf(ptr_buffer + *offset, elf_file_size) != 0)
   (mhandle_free(list_remove_at(elf_file_list_external, i), "opengl-bin-file.c" ":" "138"));
 }
 return elf_file_list_external;
}

canonical_original_code:
static struct list_t *external_elf_file_list_create(void *ptr_buffer, unsigned long buf_size)
{
 struct list_t *elf_file_list_external;
 int i;
 int elf_file_size;
 int *offset;
 elf_file_list_external = elf_file_list_create(ptr_buffer, buf_size);
 for (i = 0; i < list_count(elf_file_list_external); i++)
 {
  offset = list_get(elf_file_list_external, i);
  elf_file_size = buf_size - *offset;
  if (is_external_elf(ptr_buffer + *offset, elf_file_size) != 0)
   (mhandle_free(list_remove_at(elf_file_list_external, i), "opengl-bin-file.c" ":" "138"));
 }
 return elf_file_list_external;
}


decompiled_code:
__int64 __fastcall internal_elf_file_create(__int64 a1)
{
__int64 v1; // r12
int i; // ebp
__int64 v3; // rax
_QWORD *v4; // rbx
char *v6; // rbp
unsigned int v7; // eax
__int64 v8; // r12

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // r12
int i; // ebp
__int64 v3; // rax
_QWORD *v4; // rbx
char *v6; // rbp
unsigned int v7; // eax
__int64 v8; // r12

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

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

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


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 func8(__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);
}


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 func9(__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 func8(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);
}


decompiled_code:
__int64 __fastcall amd_opengl_shader_set_isa_buffer(__int64 a1)
{
int v1; // ebx
__int64 v2; // rax
int v4; // ebx
__int64 v5; // rdx
__int64 v6; // rdx
int v7; // eax

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

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 amd_opengl_shader_create_from_buffer(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
__int64 v8; // r12
__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) )
return v8;
LABEL_7:
fatal("Set ISA info fail!");
return v8;
}
if ( !(unsigned int)amd_opengl_shader_set_isa_buffer(v8) )
goto LABEL_7;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
__int64 v8; // r12
__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 = func2(a1, a2, a3, a4, a5);
*(_QWORD *)(v8 + 8) = v9;
*(_QWORD *)(v8 + 16) = func7(v9);
if ( !(unsigned int)func0(v8, a2) )
{
fatal("Set Shader kind fail!");
if ( (unsigned int)func11(v8) )
return v8;
LABEL_7:
fatal("Set ISA info fail!");
return v8;
}
if ( !(unsigned int)func11(v8) )
goto LABEL_7;
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: size int

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


decompiled_code:
__int64 __fastcall evg_opengl_bin_file_free(_QWORD *a1)
{
__int64 v2; // rax
int v3; // eax
__int64 v4; // rdi

while ( 1 )
{
v3 = list_count(a1[1]);
v4 = a1[1];
if ( !v3 )
break;
v2 = list_remove_at(v4, 0LL);
amd_opengl_shader_free(v2);
}
list_free(v4);
mhandle_free(*a1, "opengl-bin-file.c:426");
return mhandle_free(a1, "opengl-bin-file.c:427");
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
__int64 v2; // rax
int v3; // eax
__int64 v4; // rdi

while ( 1 )
{
v3 = list_count(a1[1]);
v4 = a1[1];
if ( !v3 )
break;
v2 = list_remove_at(v4, 0LL);
func4(v2);
}
list_free(v4);
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; // r12
_DWORD *v3; // rax
__int64 result; // rax
_QWORD *v5; // rax
_QWORD *v6; // r13
__int64 v7; // rax
__int64 v8; // r13
_QWORD *v9; // rax
__int64 v10; // rax
__int64 v11; // rdi

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);
v7 = mod_can_coalesce(v2, 1LL, *((unsigned int *)a2 + 20), a2);
v8 = v7;
if ( v7 )
{
++*(_QWORD *)(v2 + 696);
mod_coalesce(v2, v7, a2);
result = mod_stack_wait_in_stack(a2, v8, (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));
v5 = (_QWORD *)mod_in_flight_write(v2, a2);
v6 = v5;
if ( v5 )
{
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for write %lld\n", *a2, *v5);
}
else
{
v9 = (_QWORD *)mod_in_flight_address(v2, *((unsigned int *)a2 + 20), a2);
v6 = v9;
if ( !v9 )
{
v10 = mod_stack_create(*a2, v2, *((unsigned int *)a2 + 20), (unsigned int)EV_MOD_LOCAL_MEM_LOAD_FINISH, a2);
v11 = (unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK;
*(_BYTE *)(v10 + 184) |= 8u;
return esim_schedule_event(v11, v10, 0LL);
}
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for access %lld\n", *a2, *v9);
}
return mod_stack_wait_in_stack(a2, v6, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK);
}
if ( EV_MOD_LOCAL_MEM_LOAD_FINISH != a1 )
mod_handler_local_mem_load_cold();
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);
}
v3 = (_DWORD *)a2[2];
if ( v3 )
++*v3;
if ( a2[3] )
{
if ( 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; // r12
_DWORD *v3; // rax
__int64 result; // rax
_QWORD *v5; // rax
_QWORD *v6; // r13
__int64 v7; // rax
__int64 v8; // r13
_QWORD *v9; // rax
__int64 v10; // rax
__int64 v11; // rdi

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);
v7 = mod_can_coalesce(v2, 1LL, *((unsigned int *)a2 + 20), a2);
v8 = v7;
if ( v7 )
{
++*(_QWORD *)(v2 + 696);
mod_coalesce(v2, v7, a2);
result = mod_stack_wait_in_stack(a2, v8, (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));
v5 = (_QWORD *)mod_in_flight_write(v2, a2);
v6 = v5;
if ( v5 )
{
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for write %lld\n", *a2, *v5);
}
else
{
v9 = (_QWORD *)mod_in_flight_address(v2, *((unsigned int *)a2 + 20), a2);
v6 = v9;
if ( !v9 )
{
v10 = mod_stack_create(*a2, v2, *((unsigned int *)a2 + 20), (unsigned int)EV_MOD_LOCAL_MEM_LOAD_FINISH, a2);
v11 = (unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK;
*(_BYTE *)(v10 + 184) |= 8u;
return esim_schedule_event(v11, v10, 0LL);
}
if ( mem_debug_category )
_debug(mem_debug_category, " %lld wait for access %lld\n", *a2, *v9);
}
return mod_stack_wait_in_stack(a2, v6, (unsigned int)EV_MOD_LOCAL_MEM_LOAD_LOCK);
}
if ( EV_MOD_LOCAL_MEM_LOAD_FINISH != a1 )
func2();
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);
}
v3 = (_DWORD *)a2[2];
if ( v3 )
++*v3;
if ( a2[3] )
{
if ( 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; // r12
__int64 v3; // r13
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // r13
_DWORD *v7; // 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 )
{
v6 = 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 *)(v6 + 185) |= 8u;
++*(_QWORD *)(v2 + 680);
if ( (a2[23] & 8) != 0 )
{
++*(_QWORD *)(v2 + 696);
++*(_QWORD *)(v2 + 704);
}
else
{
++*(_QWORD *)(v2 + 720);
v7 = (_DWORD *)a2[2];
++*(_QWORD *)(v2 + 728);
if ( v7 )
{
++*v7;
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));
v4 = mem_trace_category;
if ( !mem_trace_category )
goto LABEL_7;
}
else
{
v4 = mem_trace_category;
if ( !mem_trace_category )
{
LABEL_7:
mod_unlock_port(v2, v3, a2);
return esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH, a2, 0LL);
}
}
_trace(v4, 1LL, "mem.access name=\"A-%lld\" state=\"%s:find_and_lock_action\"\n", *a2, *(const char **)(v2 + 8));
goto LABEL_7;
}
if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH != a1 )
mod_handler_local_mem_find_and_lock_cold();
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; // r12
__int64 v3; // r13
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // r13
_DWORD *v7; // 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 )
{
v6 = 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 *)(v6 + 185) |= 8u;
++*(_QWORD *)(v2 + 680);
if ( (a2[23] & 8) != 0 )
{
++*(_QWORD *)(v2 + 696);
++*(_QWORD *)(v2 + 704);
}
else
{
++*(_QWORD *)(v2 + 720);
v7 = (_DWORD *)a2[2];
++*(_QWORD *)(v2 + 728);
if ( v7 )
{
++*v7;
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));
v4 = mem_trace_category;
if ( !mem_trace_category )
goto LABEL_7;
}
else
{
v4 = mem_trace_category;
if ( !mem_trace_category )
{
LABEL_7:
mod_unlock_port(v2, v3, a2);
return esim_schedule_event((unsigned int)EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH, a2, 0LL);
}
}
_trace(v4, 1LL, "mem.access name=\"A-%lld\" state=\"%s:find_and_lock_action\"\n", *a2, *(const char **)(v2 + 8));
goto LABEL_7;
}
if ( EV_MOD_LOCAL_MEM_FIND_AND_LOCK_FINISH != a1 )
func4();
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: i 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; // r12
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");
v4 = &strcmp;
if ( a1 < 5 )
v2 = 5;
*(_DWORD *)(v3 + 8) = a2;
if ( !a2 )
v4 = &strcasecmp;
*(_DWORD *)(v3 + 4) = v2;
*(_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; // r12
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");
v4 = &strcmp;
if ( a1 < 5 )
v2 = 5;
*(_DWORD *)(v3 + 8) = a2;
if ( !a2 )
v4 = &strcasecmp;
*(_DWORD *)(v3 + 4) = v2;
*(_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 result; // rax
__int64 v3; // r13
_QWORD *i; // rbx
_QWORD *v5; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
__int64 v3; // r13
_QWORD *i; // rbx
_QWORD *v5; // rdi

result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 12) = 0;
if ( (int)result > 0 )
{
result = *(_QWORD *)(a1 + 32);
v3 = 0LL;
do
{
for ( i = *(_QWORD **)(result + 8 * v3); i; *(_QWORD *)(result + 8 * v3) = i )
{
v5 = i;
i = (_QWORD *)i[2];
func2(v5);
result = *(_QWORD *)(a1 + 32);
}
++v3;
}
while ( *(_DWORD *)(a1 + 4) > (int)v3 );
}
*(_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)
{
__int64 *v5; // rax
__int64 **v6; // rdx
int v7[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);
if ( hash_table_find(a1, a2, v7) )
return 0LL;
v5 = hash_table_elem_create((__int64)a2, a3);
v6 = (__int64 **)(*(_QWORD *)(a1 + 32) + 8LL * v7[0]);
v5[2] = (__int64)*v6;
*v6 = v5;
LODWORD(v5) = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = (_DWORD)v5;
if ( (int)v5 >= *(_DWORD *)(a1 + 4) )
_assert_fail("table->count < table->size", "hash-table.c", 0x10Eu, "hash_table_insert");
return 1LL;
}

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

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

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 *


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

if ( !a3 )
return 0LL;
v4 = hash_table_find(a1, a2, 0LL);
if ( !v4 )
return 0LL;
v4[1] = a3;
return 1LL;
}

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

if ( !a3 )
return 0LL;
v4 = hash_table_find(a1, a2, 0LL);
if ( !v4 )
return 0LL;
v4[1] = a3;
return 1LL;
}

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)
{
_QWORD *v2; // r13
const char *v3; // r12
int v5; // esi
__int64 v6; // r14
_QWORD *v7; // rbp
bool v8; // zf
__int64 v9; // rax
__int64 v10; // r12

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

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


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

*(_QWORD *)(a1 + 12) = 1LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( a2 )
*a2 = 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
v2 = *(int *)(a1 + 4);
if ( (int)v2 <= 0 )
{
LABEL_11:
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 ( v2 == ++v3 )
goto LABEL_11;
}
*(_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)
{
__int64 v2; // rcx
__int64 v3; // rax
__int64 *v4; // rdx
__int64 result; // rax

*(_QWORD *)(a1 + 12) = 1LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( a2 )
*a2 = 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
v2 = *(int *)(a1 + 4);
if ( (int)v2 <= 0 )
{
LABEL_11:
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 ( v2 == ++v3 )
goto LABEL_11;
}
*(_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 *