decompiled_code:
__int64 __fastcall net_buffer_extract(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // edx
const char **v4; // r12
__int64 v5; // r13

v2 = *(_DWORD *)(a1 + 32);
v3 = *(_DWORD *)(a2 + 16);
v4 = *(const char ***)a1;
v5 = *(_QWORD *)(a1 + 8);
if ( v2 < v3 )
_assert_fail("buffer->count >= msg->size", "buffer.c", 0x7Bu, "net_buffer_extract");
*(_DWORD *)(a1 + 32) = v2 - v3;
if ( !(unsigned int)list_count(*(_QWORD *)(a1 + 64)) )
panic("%s: empty message list", "net_buffer_extract");
if ( a2 != list_dequeue(*(_QWORD *)(a1 + 64)) )
panic("%s: message is not at buffer head", "net_buffer_extract");
net_buffer_update_occupancy(a1);
if ( net_debug_category )
_debug(
net_debug_category,
"buf a=\"extract\" net=\"%s\" msg=%lld node=\"%s\" buf=\"%s\"\n",
*v4,
*(_QWORD *)(a2 + 8),
*(const char **)(v5 + 16),
*(const char **)(a1 + 16));
return net_buffer_wakeup(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // edx
const char **v4; // r12
__int64 v5; // r13

v2 = *(_DWORD *)(a1 + 32);
v3 = *(_DWORD *)(a2 + 16);
v4 = *(const char ***)a1;
v5 = *(_QWORD *)(a1 + 8);
if ( v2 < v3 )
_assert_fail("buffer->count >= msg->size", "buffer.c", 0x7Bu, "net_buffer_extract");
*(_DWORD *)(a1 + 32) = v2 - v3;
if ( !(unsigned int)list_count(*(_QWORD *)(a1 + 64)) )
panic("%s: empty message list", "net_buffer_extract");
if ( a2 != list_dequeue(*(_QWORD *)(a1 + 64)) )
panic("%s: message is not at buffer head", "net_buffer_extract");
func5(a1);
if ( net_debug_category )
_debug(
net_debug_category,
"buf a=\"extract\" net=\"%s\" msg=%lld node=\"%s\" buf=\"%s\"\n",
*v4,
*(_QWORD *)(a2 + 8),
*(const char **)(v5 + 16),
*(const char **)(a1 + 16));
return func4(a1);
}

original_code:
void net_buffer_extract(struct net_buffer_t *buffer, struct net_msg_t *msg)
{
 struct net_t *net = buffer->net;
 struct net_node_t *node = buffer->node;
 ((void) sizeof ((buffer->count >= msg->size) ? 1 : 0), __extension__ ({ if (buffer->count >= msg->size) ; else __assert_fail ("buffer->count >= msg->size", "buffer.c", 123, __extension__ __PRETTY_FUNCTION__); }));
 buffer->count -= msg->size;
 if (!list_count(buffer->msg_list))
  panic("%s: empty message list", __FUNCTION__);
 if (list_dequeue(buffer->msg_list) != msg)
  panic("%s: message is not at buffer head", __FUNCTION__);
 net_buffer_update_occupancy(buffer);
 ((net_debug_category) ? __debug((net_debug_category), "buf " "a=\"extract\" " "net=\"%s\" " "msg=%lld " "node=\"%s\" " "buf=\"%s\"\n", net->name, msg->id, node->name, buffer->name) : (void) 0);
 net_buffer_wakeup(buffer);
}


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

result = mhandle_calloc(1LL, 40LL, "linked-list.c:33");
if ( !result )
{
fatal("%s: out of memory", "linked_list_create");
result = 0LL;
}
return result;
}

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

result = mhandle_calloc(1LL, 40LL, "linked-list.c:33");
if ( !result )
{
fatal("%s: out of memory", "linked_list_create");
result = 0LL;
}
return result;
}

original_code:
struct linked_list_t *linked_list_create()
{
 struct linked_list_t *list;
 list = (mhandle_calloc(1, sizeof(struct linked_list_t), "linked-list.c" ":" "33"));
 if (!list)
  fatal("%s: out of memory", __FUNCTION__);
 return list;
}

variable_types: struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *

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


decompiled_code:
__int64 __fastcall linked_list_current(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 0;
return *(unsigned int *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 0;
return *(unsigned int *)(a1 + 32);
}

original_code:
int linked_list_current(struct linked_list_t *list)
{
 list->error_code = LINKED_LIST_ERR_OK;
 return list->current_index;
}

return_type: int

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


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

if ( *(_DWORD *)(a1 + 32) == *(_DWORD *)a1 )
{
*(_DWORD *)(a1 + 4) = 1;
result = 0LL;
}
else
{
v1 = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 4) = 0;
result = *(_QWORD *)(v1 + 16);
}
return result;
}

original_code:
void *linked_list_get(struct linked_list_t *list)
{
 if (list->current_index == list->count)
 {
  list->error_code = LINKED_LIST_ERR_BOUNDS;
  return ((void *)0);
 }
 list->error_code = LINKED_LIST_ERR_OK;
 return list->current->data;
}

return_type: void *


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

result = *(unsigned int *)(a1 + 32);
if ( (_DWORD)result == *(_DWORD *)a1 )
{
*(_DWORD *)(a1 + 4) = 1;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = result + 1;
result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
*(_QWORD *)(a1 + 24) = result;
}
return result;
}

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

result = *(unsigned int *)(a1 + 32);
if ( (_DWORD)result == *(_DWORD *)a1 )
{
*(_DWORD *)(a1 + 4) = 1;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = result + 1;
result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
*(_QWORD *)(a1 + 24) = result;
}
return result;
}

original_code:
void linked_list_next(struct linked_list_t *list)
{
 if (list->current_index == list->count)
 {
  list->error_code = LINKED_LIST_ERR_BOUNDS;
  return;
 }
 list->error_code = LINKED_LIST_ERR_OK;
 list->current_index++;
 list->current = list->current->next;
}

return_type: void


decompiled_code:
__int64 __fastcall linked_list_prev(__int64 a1)
{
__int64 result; // rax
__int64 *v2; // rax

result = *(unsigned int *)(a1 + 32);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = result - 1;
v2 = *(__int64 **)(a1 + 24);
if ( v2 )
result = *v2;
else
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = result;
}
else
{
*(_DWORD *)(a1 + 4) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
__int64 *v2; // rax

result = *(unsigned int *)(a1 + 32);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = result - 1;
v2 = *(__int64 **)(a1 + 24);
if ( v2 )
result = *v2;
else
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = result;
}
else
{
*(_DWORD *)(a1 + 4) = 1;
}
return result;
}

original_code:
void linked_list_prev(struct linked_list_t *list)
{
 if (!list->current_index)
 {
  list->error_code = LINKED_LIST_ERR_BOUNDS;
  return;
 }
 list->error_code = LINKED_LIST_ERR_OK;
 list->current_index--;
 list->current = list->current ? list->current->prev :
  list->tail;
}


decompiled_code:
__int64 __fastcall linked_list_next_circular(unsigned int *a1)
{
__int64 result; // rax
int v2; // edx
__int64 v3; // rax

result = *a1;
if ( (_DWORD)result )
{
v2 = a1[8];
if ( v2 >= (int)result - 1 )
{
result = *((_QWORD *)a1 + 1);
a1[8] = 0;
}
else
{
v3 = *((_QWORD *)a1 + 3);
a1[8] = v2 + 1;
result = *(_QWORD *)(v3 + 8);
}
a1[1] = 0;
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[1] = 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
__int64 result; // rax
int v2; // edx
__int64 v3; // rax

result = *a1;
if ( (_DWORD)result )
{
v2 = a1[8];
if ( v2 >= (int)result - 1 )
{
result = *((_QWORD *)a1 + 1);
a1[8] = 0;
}
else
{
v3 = *((_QWORD *)a1 + 3);
a1[8] = v2 + 1;
result = *(_QWORD *)(v3 + 8);
}
a1[1] = 0;
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[1] = 2;
}
return result;
}

original_code:
void linked_list_next_circular(struct linked_list_t *list)
{
 if (!list->count)
 {
  list->error_code = LINKED_LIST_ERR_EMPTY;
  return;
 }
 if (list->current_index >= list->count - 1)
 {
  list->current_index = 0;
  list->current = list->head;
 }
 else
 {
  list->current_index++;
  list->current = list->current->next;
 }
 list->error_code = LINKED_LIST_ERR_OK;
}


decompiled_code:
__int64 __fastcall linked_list_prev_circular(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // edx
__int64 *v3; // rax

result = *a1;
if ( (_DWORD)result )
{
v2 = a1[8];
if ( v2 )
{
v3 = (__int64 *)*((_QWORD *)a1 + 3);
a1[8] = v2 - 1;
if ( v3 )
result = *v3;
else
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
a1[1] = 0;
}
else
{
a1[1] = 0;
a1[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
}
else
{
a1[1] = 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // edx
__int64 *v3; // rax

result = *a1;
if ( (_DWORD)result )
{
v2 = a1[8];
if ( v2 )
{
v3 = (__int64 *)*((_QWORD *)a1 + 3);
a1[8] = v2 - 1;
if ( v3 )
result = *v3;
else
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
a1[1] = 0;
}
else
{
a1[1] = 0;
a1[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
}
else
{
a1[1] = 2;
}
return result;
}

original_code:
void linked_list_prev_circular(struct linked_list_t *list)
{
 if (!list->count)
 {
  list->error_code = LINKED_LIST_ERR_EMPTY;
  return;
 }
 if (!list->current_index)
 {
  list->current_index = list->count - 1;
  list->current = list->tail;
 }
 else
 {
  list->current_index--;
  list->current = list->current ? list->current->prev :
   list->tail;
 }
 list->error_code = LINKED_LIST_ERR_OK;
}


decompiled_code:
__int64 __fastcall linked_list_head(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
if ( (_DWORD)result )
{
result = *((_QWORD *)a1 + 1);
a1[1] = 0;
a1[8] = 0;
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[1] = 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
if ( (_DWORD)result )
{
result = *((_QWORD *)a1 + 1);
a1[1] = 0;
a1[8] = 0;
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[1] = 2;
}
return result;
}

original_code:
void linked_list_head(struct linked_list_t *list)
{
 if (!list->count)
 {
  list->error_code = LINKED_LIST_ERR_EMPTY;
  return;
 }
 list->error_code = LINKED_LIST_ERR_OK;
 list->current_index = 0;
 list->current = list->head;
}


decompiled_code:
__int64 __fastcall linked_list_tail(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
if ( (_DWORD)result )
{
a1[1] = 0;
a1[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[1] = 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
if ( (_DWORD)result )
{
a1[1] = 0;
a1[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[1] = 2;
}
return result;
}

original_code:
void linked_list_tail(struct linked_list_t *list)
{
 if (!list->count)
 {
  list->error_code = LINKED_LIST_ERR_EMPTY;
  return;
 }
 list->current_index = list->count - 1;
 list->current = list->tail;
 list->error_code = LINKED_LIST_ERR_OK;
}


decompiled_code:
__int64 __fastcall linked_list_out(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
a1[1] = 0;
*((_QWORD *)a1 + 3) = 0LL;
a1[8] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
a1[1] = 0;
*((_QWORD *)a1 + 3) = 0LL;
a1[8] = result;
return result;
}

original_code:
void linked_list_out(struct linked_list_t *list)
{
 list->error_code = LINKED_LIST_ERR_OK;
 list->current_index = list->count;
 list->current = ((void *)0);
}


original_code:
void linked_list_goto(struct linked_list_t *list, int index)
{
 if (index < 0 || index > list->count)
 {
  list->error_code = LINKED_LIST_ERR_BOUNDS;
  return;
 }
 list->error_code = LINKED_LIST_ERR_OK;
 while (list->current_index < index)
 {
  list->current_index++;
  list->current = list->current->next;
 }
 while (list->current_index > index)
 {
  list->current_index--;
  list->current = list->current ? list->current->prev :
   list->tail;
 }
}

variable_types: index int


decompiled_code:
__int64 __fastcall linked_list_find(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = 0;
*(_QWORD *)(a1 + 24) = result;
if ( result )
{
while ( *(_QWORD *)(result + 16) != a2 )
{
result = *(_QWORD *)(result + 8);
++*(_DWORD *)(a1 + 32);
*(_QWORD *)(a1 + 24) = result;
if ( !result )
goto LABEL_6;
}
}
else
{
LABEL_6:
*(_DWORD *)(a1 + 4) = 3;
}
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = 0;
*(_QWORD *)(a1 + 24) = result;
if ( result )
{
while ( *(_QWORD *)(result + 16) != a2 )
{
result = *(_QWORD *)(result + 8);
++*(_DWORD *)(a1 + 32);
*(_QWORD *)(a1 + 24) = result;
if ( !result )
goto LABEL_6;
}
}
else
{
LABEL_6:
*(_DWORD *)(a1 + 4) = 3;
}
return result;
}

original_code:
void linked_list_find(struct linked_list_t *list, void *data)
{
 list->error_code = LINKED_LIST_ERR_OK;
 list->current_index = 0;
 list->current = list->head;
 while (list->current && list->current->data != data)
 {
  list->current_index++;
  list->current = list->current->next;
 }
 if (!list->current)
  list->error_code = LINKED_LIST_ERR_NOT_FOUND;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall linked_list_count(unsigned int *a1)
{
a1[1] = 0;
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1)
{
a1[1] = 0;
return *a1;
}

original_code:
int linked_list_count(struct linked_list_t *list)
{
 list->error_code = LINKED_LIST_ERR_OK;
 return list->count;
}


decompiled_code:
_BOOL8 __fastcall linked_list_is_end(_DWORD *a1)
{
bool v1; // zf

v1 = a1[8] == *a1;
a1[1] = 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(_DWORD *a1)
{
bool v1; // zf

v1 = a1[8] == *a1;
a1[1] = 0;
return v1;
}

original_code:
int linked_list_is_end(struct linked_list_t *list)
{
 list->error_code = LINKED_LIST_ERR_OK;
 return list->current_index == list->count;
}


decompiled_code:
__int64 __fastcall linked_list_add(unsigned int *a1, __int64 a2)
{
linked_list_out(a1);
linked_list_insert((int *)a1, a2);
return linked_list_out(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int *a1, __int64 a2)
{
func10(a1);
func15((int *)a1, a2);
return func10(a1);
}

original_code:
void linked_list_add(struct linked_list_t *list, void *data)
{
 linked_list_out(list);
 linked_list_insert(list, data);
 linked_list_out(list);
}


original_code:
void linked_list_remove(struct linked_list_t *list)
{
 struct linked_list_elem_t *elem;
 if (list->current_index == list->count)
 {
  list->error_code = LINKED_LIST_ERR_BOUNDS;
  return;
 }
 elem = list->current;
 if (list->count == 1)
 {
  list->tail = ((void *)0);
  list->head = ((void *)0);
 }
 else if (elem == list->head)
 {
  elem->next->prev = ((void *)0);
  list->head = elem->next;
 }
 else if (elem == list->tail)
 {
  elem->prev->next = ((void *)0);
  list->tail = elem->prev;
 }
 else
 {
  elem->prev->next = elem->next;
  elem->next->prev = elem->prev;
 }
 ((void) sizeof ((list->count > 0) ? 1 : 0), __extension__ ({ if (list->count > 0) ; else __assert_fail ("list->count > 0", "linked-list.c", 322, __extension__ __PRETTY_FUNCTION__); }));
 list->error_code = LINKED_LIST_ERR_OK;
 list->count--;
 list->current = elem->next;
 (mhandle_free(elem, "linked-list.c" ":" "326"));
}

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


decompiled_code:
__int64 __fastcall linked_list_clear(__int64 a1)
{
__int64 i; // rbx
__int64 v3; // rdi
__int64 result; // rax

for ( i = *(_QWORD *)(a1 + 8); i; result = mhandle_free(v3, "linked-list.c:339") )
{
v3 = i;
i = *(_QWORD *)(i + 8);
}
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
return result;
}

original_code:
void linked_list_clear(struct linked_list_t *list)
{
 struct linked_list_elem_t *elem, *next;
 elem = list->head;
 while (elem)
 {
  next = elem->next;
  (mhandle_free(elem, "linked-list.c" ":" "339"));
  elem = next;
 }
 list->error_code = LINKED_LIST_ERR_OK;
 list->current_index = 0;
 list->count = 0;
 list->tail = ((void *)0);
 list->head = ((void *)0);
 list->current = ((void *)0);
}

canonical_original_code:
void linked_list_clear(struct linked_list_t *list)
{
 struct linked_list_elem_t *elem; struct linked_list_elem_t *next;
 elem = list->head;
 while (elem)
 {
  next = elem->next;
  (mhandle_free(elem, "linked-list.c" ":" "339"));
  elem = next;
 }
 list->error_code = LINKED_LIST_ERR_OK;
 list->current_index = 0;
 list->count = 0;
 list->tail = ((void *)0);
 list->head = ((void *)0);
 list->current = ((void *)0);
}


decompiled_code:
__int64 __fastcall linked_list_free(__int64 a1)
{
linked_list_clear(a1);
return mhandle_free(a1, "linked-list.c:46");
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
func18(a1);
return mhandle_free(a1, "linked-list.c:46");
}

original_code:
void linked_list_free(struct linked_list_t *list)
{
 linked_list_clear(list);
 (mhandle_free(list, "linked-list.c" ":" "46"));
}


original_code:
void linked_list_sort(struct linked_list_t *list, int (*comp)(const void *, const void *))
{
 struct linked_list_elem_t **array;
 int i;
 list->error_code = LINKED_LIST_ERR_OK;
 if (!list->count)
  return;
 array = (mhandle_calloc(list->count, sizeof(struct linked_list_elem_t *), "linked-list.c" ":" "389"));
 if (!array)
  fatal("%s: out of memory", __FUNCTION__);
 list->current = list->head;
 for (i = 0; i < list->count; i++)
 {
  array[i] = list->current;
  list->current = list->current->next;
 }
 sort(array, 0, list->count - 1, comp);
 list->head = array[0];
 list->tail = array[list->count - 1];
 for (i = 0; i < list->count; i++)
 {
  array[i]->prev = i > 0 ? array[i - 1] : ((void *)0);
  array[i]->next = i < list->count - 1 ? array[i + 1] : ((void *)0);
 }
 (mhandle_free(array, "linked-list.c" ":" "412"));
 list->current_index = 0;
 list->current = list->head;
}

canonical_original_code:
void linked_list_sort(struct linked_list_t *list, int (*comp)(void *, void *))
{
 struct linked_list_elem_t **array;
 int i;
 list->error_code = LINKED_LIST_ERR_OK;
 if (!list->count)
  return;
 array = (mhandle_calloc(list->count, sizeof(struct linked_list_elem_t *), "linked-list.c" ":" "389"));
 if (!array)
  fatal("%s: out of memory", __FUNCTION__);
 list->current = list->head;
 for (i = 0; i < list->count; i++)
 {
  array[i] = list->current;
  list->current = list->current->next;
 }
 sort(array, 0, list->count - 1, comp);
 list->head = array[0];
 list->tail = array[list->count - 1];
 for (i = 0; i < list->count; i++)
 {
  array[i]->prev = i > 0 ? array[i - 1] : ((void *)0);
  array[i]->next = i < list->count - 1 ? array[i + 1] : ((void *)0);
 }
 (mhandle_free(array, "linked-list.c" ":" "412"));
 list->current_index = 0;
 list->current = list->head;
}

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

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

variable_types: i int


original_code:
int linked_list_sorted(struct linked_list_t *list,
 int (*comp)(const void *, const void *))
{
 struct linked_list_elem_t *elem, *prev;
 int i = 0;
 list->error_code = LINKED_LIST_ERR_OK;
 if (!list->head)
  return 1;
 prev = list->head;
 elem = list->head->next;
 while (elem)
 {
  i++;
  if (comp(prev->data, elem->data) > 0)
   return 0;
  prev = elem;
  elem = elem->next;
 }
 return 1;
}

canonical_original_code:
int linked_list_sorted(struct linked_list_t *list, int (*comp)(void *, void *))
{
 struct linked_list_elem_t *elem; struct linked_list_elem_t *prev;
 int i = 0;
 list->error_code = LINKED_LIST_ERR_OK;
 if (!list->head)
  return 1;
 prev = list->head;
 elem = list->head->next;
 while (elem)
 {
  i++;
  if (comp(prev->data, elem->data) > 0)
   return 0;
  prev = elem;
  elem = elem->next;
 }
 return 1;
}


sort

original_code:
static void sort(struct linked_list_elem_t **array, int lo, int hi, int (*comp)(const void *, const void *))
{
 struct linked_list_elem_t *ptr, *tmp;
 int i = lo, j = hi;
 ptr = array[(lo + hi) / 2];
 do {
  while (comp(array[i]->data, ptr->data) < 0)
   i++;
  while (comp(array[j]->data, ptr->data) > 0)
   j--;
  if (i <= j) {
   tmp = array[i];
   array[i] = array[j];
   array[j] = tmp;
   i++, j--;
  }
 } while (i <= j);
 if (lo < j)
  sort(array, lo, j, comp);
 if (i < hi)
  sort(array, i, hi, comp);
}

canonical_original_code:
static void sort(struct linked_list_elem_t **array, int lo, int hi, int (*comp)(void *, void *))
{
 struct linked_list_elem_t *ptr; struct linked_list_elem_t *tmp;
 int i = lo; int j = hi;
 ptr = array[(lo + hi) / 2];
 do {
  while (comp(array[i]->data, ptr->data) < 0)
   i++;
  while (comp(array[j]->data, ptr->data) > 0)
   j--;
  if (i <= j) {
   tmp = array[i];
   array[i] = array[j];
   array[j] = tmp;
   i++, j--;
  }
 } while (i <= j);
 if (lo < j)
  sort(array, lo, j, comp);
 if (i < hi)
  sort(array, i, hi, comp);
}

variable_types: lo int

variable_types: hi int

variable_types: j int


decompiled_code:
_DWORD *si_opencl_device_create()
{
_DWORD *v0; // r12

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opencl-device.c:36");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_device_create");
*v0 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 2LL);
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

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

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opencl-device.c:36");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_device_create");
*v0 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 2LL);
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

original_code:
struct si_opencl_device_t *si_opencl_device_create()
{
 struct si_opencl_device_t *device;
 device = (mhandle_calloc(1, sizeof(struct si_opencl_device_t), "opencl-device.c" ":" "36"));
 if (!device)
  fatal("%s: out of memory", __FUNCTION__);
 device->id = si_opencl_repo_new_object_id(si_emu->opencl_repo,
  si_opencl_object_device);
 si_opencl_repo_add_object(si_emu->opencl_repo, device);
 return device;
}

variable_types: struct si_opencl_device_t { unsigned int id; } *


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

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

original_code:
void si_opencl_device_free(struct si_opencl_device_t *device)
{
 si_opencl_repo_remove_object(si_emu->opencl_repo, device);
 (mhandle_free(device, "opencl-device.c" ":" "54"));
}

user_defined_types: struct si_opencl_device_t { unsigned int id; }


decompiled_code:
__int64 __fastcall si_opencl_device_get_info(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
char *v7; // r14
unsigned int v8; // er13
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // eax
int v16; // eax
unsigned int v17; // [rsp+Ch] [rbp-2Ch]
unsigned int v18; // [rsp+Ch] [rbp-2Ch]
unsigned int v19; // [rsp+Ch] [rbp-2Ch]
unsigned int v20; // [rsp+Ch] [rbp-2Ch]
unsigned int v21; // [rsp+Ch] [rbp-2Ch]
unsigned int v22; // [rsp+Ch] [rbp-2Ch]
unsigned int v23; // [rsp+Ch] [rbp-2Ch]

switch ( (int)a2 )
{
case 4096:
v7 = (char *)&si_gpu_device_type;
v8 = 4;
break;
case 4097:
v7 = (char *)&si_gpu_device_vendor_id;
v8 = 4;
break;
case 4098:
v7 = (char *)&si_gpu_num_compute_units;
v8 = 4;
break;
case 4099:
v7 = (char *)&si_gpu_work_item_dimensions;
v8 = 4;
break;
case 4100:
v7 = (char *)&si_gpu_work_group_size;
v8 = 4;
break;
case 4101:
v7 = (char *)&si_gpu_work_item_sizes;
v8 = 12;
break;
case 4102:
case 4103:
case 4104:
case 4105:
case 4106:
case 4107:
case 4150:
case 4151:
case 4152:
case 4153:
case 4154:
case 4155:
v7 = (char *)&si_gpu_num_stream_cores;
v8 = 4;
break;
case 4108:
v7 = (char *)&si_gpu_max_clock_frequency;
v8 = 4;
break;
case 4109:
v7 = (char *)&si_gpu_address_bits;
v8 = 4;
break;
case 4110:
v7 = (char *)&si_gpu_max_read_image_args;
v8 = 4;
break;
case 4111:
v7 = (char *)&si_gpu_max_write_image_args;
v8 = 4;
break;
case 4112:
v7 = (char *)&si_gpu_max_mem_alloc_size;
v8 = 8;
break;
case 4113:
v7 = (char *)&si_gpu_image2d_max_width;
v8 = 4;
break;
case 4114:
v7 = (char *)&si_gpu_image2d_max_height;
v8 = 4;
break;
case 4115:
v7 = (char *)&si_gpu_image3d_max_width;
v8 = 4;
break;
case 4116:
v7 = (char *)&si_gpu_image3d_max_height;
v8 = 4;
break;
case 4117:
v7 = (char *)&si_gpu_image3d_max_depth;
v8 = 4;
break;
case 4118:
v7 = (char *)&si_gpu_image_support;
v8 = 4;
break;
case 4119:
v7 = (char *)&si_gpu_max_parameter_size;
v8 = 4;
break;
case 4120:
v7 = (char *)&si_gpu_max_samplers;
v8 = 4;
break;
case 4121:
v7 = (char *)&si_gpu_mem_base_addr_align;
v8 = 4;
break;
case 4122:
v7 = (char *)&si_gpu_min_data_type_align_size;
v8 = 4;
break;
case 4123:
v7 = (char *)&si_gpu_single_fp_config;
v8 = 4;
break;
case 4124:
v7 = (char *)&si_gpu_global_mem_cache_type;
v8 = 4;
break;
case 4125:
v7 = (char *)&si_gpu_global_mem_cacheline_size;
v8 = 4;
break;
case 4126:
v7 = (char *)&si_gpu_global_mem_cache_size;
v8 = 8;
break;
case 4127:
v7 = (char *)&si_gpu_global_mem_size;
v8 = 8;
break;
case 4128:
v7 = (char *)&si_gpu_max_constant_buffer_size;
v8 = 8;
break;
case 4129:
v7 = (char *)&si_gpu_max_constant_args;
v8 = 4;
break;
case 4130:
v7 = (char *)&si_gpu_local_mem_type;
v8 = 4;
break;
case 4131:
v7 = (char *)&si_gpu_local_mem_size;
v8 = 8;
break;
case 4132:
v7 = (char *)&si_gpu_error_correction_support;
v8 = 4;
break;
case 4133:
v7 = (char *)&si_gpu_profiling_timer_resolution;
v8 = 4;
break;
case 4134:
v7 = (char *)&si_gpu_endian_little;
v8 = 4;
break;
case 4135:
v7 = (char *)&si_gpu_device_available;
v8 = 4;
break;
case 4136:
v7 = (char *)&si_gpu_compiler_available;
v8 = 4;
break;
case 4137:
v7 = (char *)&si_gpu_execution_capabilities;
v8 = 4;
break;
case 4138:
v7 = (char *)&si_gpu_queue_properties;
v8 = 4;
break;
case 4139:
v7 = si_gpu_device_name;
v19 = a5;
v12 = strlen(si_gpu_device_name);
a5 = v19;
v8 = v12 + 1;
break;
case 4140:
v7 = si_gpu_device_vendor;
v18 = a5;
v11 = strlen(si_gpu_device_vendor);
a5 = v18;
v8 = v11 + 1;
break;
case 4141:
v7 = si_gpu_driver_version;
v23 = a5;
v16 = strlen(si_gpu_driver_version);
a5 = v23;
v8 = v16 + 1;
break;
case 4142:
v7 = si_gpu_device_profile;
v22 = a5;
v15 = strlen(si_gpu_device_profile);
a5 = v22;
v8 = v15 + 1;
break;
case 4143:
v7 = si_gpu_device_version;
v21 = a5;
v14 = strlen(si_gpu_device_version);
a5 = v21;
v8 = v14 + 1;
break;
case 4144:
v7 = si_gpu_device_extensions;
v20 = a5;
v13 = strlen(si_gpu_device_extensions);
a5 = v20;
v8 = v13 + 1;
break;
case 4145:
v7 = (char *)&si_gpu_platform;
v8 = 4;
break;
case 4146:
v7 = (char *)&si_gpu_double_fp_config;
v8 = 4;
break;
case 4148:
case 4156:
v7 = (char *)&si_gpu_vector_width_half;
v8 = 4;
break;
case 4149:
v7 = (char *)&si_gpu_host_unified_memory;
v8 = 4;
break;
case 4157:
v7 = si_gpu_opencl_version;
v17 = a5;
v10 = strlen(si_gpu_opencl_version);
a5 = v17;
v8 = v10 + 1;
break;
case 4158:
v7 = (char *)&si_gpu_linker_available;
v8 = 4;
break;
default:
fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s", a2, si_err_opencl_note);
_assert_fail("info", "opencl-device.c", 0x157u, "si_opencl_device_get_info");
}
if ( a4 && a5 >= v8 )
mem_write(a3, a4, v8, v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
char *v7; // r14
unsigned int v8; // er13
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // eax
int v16; // eax
unsigned int v17; // [rsp+Ch] [rbp-2Ch]
unsigned int v18; // [rsp+Ch] [rbp-2Ch]
unsigned int v19; // [rsp+Ch] [rbp-2Ch]
unsigned int v20; // [rsp+Ch] [rbp-2Ch]
unsigned int v21; // [rsp+Ch] [rbp-2Ch]
unsigned int v22; // [rsp+Ch] [rbp-2Ch]
unsigned int v23; // [rsp+Ch] [rbp-2Ch]

switch ( (int)a2 )
{
case 4096:
v7 = (char *)&si_gpu_device_type;
v8 = 4;
break;
case 4097:
v7 = (char *)&si_gpu_device_vendor_id;
v8 = 4;
break;
case 4098:
v7 = (char *)&si_gpu_num_compute_units;
v8 = 4;
break;
case 4099:
v7 = (char *)&si_gpu_work_item_dimensions;
v8 = 4;
break;
case 4100:
v7 = (char *)&si_gpu_work_group_size;
v8 = 4;
break;
case 4101:
v7 = (char *)&si_gpu_work_item_sizes;
v8 = 12;
break;
case 4102:
case 4103:
case 4104:
case 4105:
case 4106:
case 4107:
case 4150:
case 4151:
case 4152:
case 4153:
case 4154:
case 4155:
v7 = (char *)&si_gpu_num_stream_cores;
v8 = 4;
break;
case 4108:
v7 = (char *)&si_gpu_max_clock_frequency;
v8 = 4;
break;
case 4109:
v7 = (char *)&si_gpu_address_bits;
v8 = 4;
break;
case 4110:
v7 = (char *)&si_gpu_max_read_image_args;
v8 = 4;
break;
case 4111:
v7 = (char *)&si_gpu_max_write_image_args;
v8 = 4;
break;
case 4112:
v7 = (char *)&si_gpu_max_mem_alloc_size;
v8 = 8;
break;
case 4113:
v7 = (char *)&si_gpu_image2d_max_width;
v8 = 4;
break;
case 4114:
v7 = (char *)&si_gpu_image2d_max_height;
v8 = 4;
break;
case 4115:
v7 = (char *)&si_gpu_image3d_max_width;
v8 = 4;
break;
case 4116:
v7 = (char *)&si_gpu_image3d_max_height;
v8 = 4;
break;
case 4117:
v7 = (char *)&si_gpu_image3d_max_depth;
v8 = 4;
break;
case 4118:
v7 = (char *)&si_gpu_image_support;
v8 = 4;
break;
case 4119:
v7 = (char *)&si_gpu_max_parameter_size;
v8 = 4;
break;
case 4120:
v7 = (char *)&si_gpu_max_samplers;
v8 = 4;
break;
case 4121:
v7 = (char *)&si_gpu_mem_base_addr_align;
v8 = 4;
break;
case 4122:
v7 = (char *)&si_gpu_min_data_type_align_size;
v8 = 4;
break;
case 4123:
v7 = (char *)&si_gpu_single_fp_config;
v8 = 4;
break;
case 4124:
v7 = (char *)&si_gpu_global_mem_cache_type;
v8 = 4;
break;
case 4125:
v7 = (char *)&si_gpu_global_mem_cacheline_size;
v8 = 4;
break;
case 4126:
v7 = (char *)&si_gpu_global_mem_cache_size;
v8 = 8;
break;
case 4127:
v7 = (char *)&si_gpu_global_mem_size;
v8 = 8;
break;
case 4128:
v7 = (char *)&si_gpu_max_constant_buffer_size;
v8 = 8;
break;
case 4129:
v7 = (char *)&si_gpu_max_constant_args;
v8 = 4;
break;
case 4130:
v7 = (char *)&si_gpu_local_mem_type;
v8 = 4;
break;
case 4131:
v7 = (char *)&si_gpu_local_mem_size;
v8 = 8;
break;
case 4132:
v7 = (char *)&si_gpu_error_correction_support;
v8 = 4;
break;
case 4133:
v7 = (char *)&si_gpu_profiling_timer_resolution;
v8 = 4;
break;
case 4134:
v7 = (char *)&si_gpu_endian_little;
v8 = 4;
break;
case 4135:
v7 = (char *)&si_gpu_device_available;
v8 = 4;
break;
case 4136:
v7 = (char *)&si_gpu_compiler_available;
v8 = 4;
break;
case 4137:
v7 = (char *)&si_gpu_execution_capabilities;
v8 = 4;
break;
case 4138:
v7 = (char *)&si_gpu_queue_properties;
v8 = 4;
break;
case 4139:
v7 = si_gpu_device_name;
v19 = a5;
v12 = strlen(si_gpu_device_name);
a5 = v19;
v8 = v12 + 1;
break;
case 4140:
v7 = si_gpu_device_vendor;
v18 = a5;
v11 = strlen(si_gpu_device_vendor);
a5 = v18;
v8 = v11 + 1;
break;
case 4141:
v7 = si_gpu_driver_version;
v23 = a5;
v16 = strlen(si_gpu_driver_version);
a5 = v23;
v8 = v16 + 1;
break;
case 4142:
v7 = si_gpu_device_profile;
v22 = a5;
v15 = strlen(si_gpu_device_profile);
a5 = v22;
v8 = v15 + 1;
break;
case 4143:
v7 = si_gpu_device_version;
v21 = a5;
v14 = strlen(si_gpu_device_version);
a5 = v21;
v8 = v14 + 1;
break;
case 4144:
v7 = si_gpu_device_extensions;
v20 = a5;
v13 = strlen(si_gpu_device_extensions);
a5 = v20;
v8 = v13 + 1;
break;
case 4145:
v7 = (char *)&si_gpu_platform;
v8 = 4;
break;
case 4146:
v7 = (char *)&si_gpu_double_fp_config;
v8 = 4;
break;
case 4148:
case 4156:
v7 = (char *)&si_gpu_vector_width_half;
v8 = 4;
break;
case 4149:
v7 = (char *)&si_gpu_host_unified_memory;
v8 = 4;
break;
case 4157:
v7 = si_gpu_opencl_version;
v17 = a5;
v10 = strlen(si_gpu_opencl_version);
a5 = v17;
v8 = v10 + 1;
break;
case 4158:
v7 = (char *)&si_gpu_linker_available;
v8 = 4;
break;
default:
fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s", a2, si_err_opencl_note);
_assert_fail("info", "opencl-device.c", 0x157u, "si_opencl_device_get_info");
}
if ( a4 && a5 >= v8 )
mem_write(a3, a4, v8, v7);
return v8;
}

original_code:
uint32_t si_opencl_device_get_info(struct si_opencl_device_t *device, uint32_t name, struct mem_t *mem, uint32_t addr, uint32_t size)
{
 uint32_t size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1000:
  size_ret = 4;
  info = &si_gpu_device_type;
  break;
 case 0x1001:
  size_ret = 4;
  info = &si_gpu_device_vendor_id;
  break;
 case 0x1002:
  size_ret = 4;
  info = &si_gpu_num_compute_units;
  break;
 case 0x1003:
  size_ret = 4;
  info = &si_gpu_work_item_dimensions;
  break;
 case 0x1004:
  size_ret = 4;
  info = &si_gpu_work_group_size;
  break;
 case 0x1005:
  size_ret = 12;
  info = si_gpu_work_item_sizes;
  break;
 case 0x1006:
 case 0x1007:
 case 0x1008:
 case 0x1009:
 case 0x100a:
 case 0x100b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x100c:
  size_ret = 4;
  info = &si_gpu_max_clock_frequency;
  break;
 case 0x100d:
  size_ret = 4;
  info = &si_gpu_address_bits;
  break;
 case 0x100e:
  size_ret = 4;
  info = &si_gpu_max_read_image_args;
  break;
 case 0x100f:
  size_ret = 4;
  info = &si_gpu_max_write_image_args;
  break;
 case 0x1010:
  size_ret = 8;
  info = &si_gpu_max_mem_alloc_size;
  break;
 case 0x1011:
  size_ret = 4;
  info = &si_gpu_image2d_max_width;
  break;
 case 0x1012:
  size_ret = 4;
  info = &si_gpu_image2d_max_height;
  break;
 case 0x1013:
  size_ret = 4;
  info = &si_gpu_image3d_max_width;
  break;
 case 0x1014:
  size_ret = 4;
  info = &si_gpu_image3d_max_height;
  break;
 case 0x1015:
  size_ret = 4;
  info = &si_gpu_image3d_max_depth;
  break;
 case 0x1016:
  size_ret = 4;
  info = &si_gpu_image_support;
  break;
 case 0x1017:
  size_ret = 4;
  info = &si_gpu_max_parameter_size;
  break;
 case 0x1018:
  size_ret = 4;
  info = &si_gpu_max_samplers;
  break;
 case 0x1019:
  size_ret = 4;
  info = &si_gpu_mem_base_addr_align;
  break;
 case 0x101a:
  size_ret = 4;
  info = &si_gpu_min_data_type_align_size;
  break;
 case 0x101b:
  size_ret = 4;
  info = &si_gpu_single_fp_config;
  break;
 case 0x101c:
  size_ret = 4;
  info = &si_gpu_global_mem_cache_type;
  break;
 case 0x101d:
  size_ret = 4;
  info = &si_gpu_global_mem_cacheline_size;
  break;
 case 0x101e:
  size_ret = 8;
  info = &si_gpu_global_mem_cache_size;
  break;
 case 0x101f:
  size_ret = 8;
  info = &si_gpu_global_mem_size;
  break;
 case 0x1020:
  size_ret = 8;
  info = &si_gpu_max_constant_buffer_size;
  break;
 case 0x1021:
  size_ret = 4;
  info = &si_gpu_max_constant_args;
  break;
 case 0x1022:
  size_ret = 4;
  info = &si_gpu_local_mem_type;
  break;
 case 0x1023:
  size_ret = 8;
  info = &si_gpu_local_mem_size;
  break;
 case 0x1024:
  size_ret = 4;
  info = &si_gpu_error_correction_support;
  break;
 case 0x1025:
  size_ret = 4;
  info = &si_gpu_profiling_timer_resolution;
  break;
 case 0x1026:
  size_ret = 4;
  info = &si_gpu_endian_little;
  break;
 case 0x1027:
  size_ret = 4;
  info = &si_gpu_device_available;
  break;
 case 0x1028:
  size_ret = 4;
  info = &si_gpu_compiler_available;
  break;
 case 0x1029:
  size_ret = 4;
  info = &si_gpu_execution_capabilities;
  break;
 case 0x102a:
  size_ret = 4;
  info = &si_gpu_queue_properties;
  break;
 case 0x102b:
  size_ret = strlen(si_gpu_device_name) + 1;
  info = si_gpu_device_name;
  break;
 case 0x102c:
  size_ret = strlen(si_gpu_device_vendor) + 1;
  info = si_gpu_device_vendor;
  break;
 case 0x102d:
  size_ret = strlen(si_gpu_driver_version) + 1;
  info = si_gpu_driver_version;
  break;
 case 0x102e:
  size_ret = strlen(si_gpu_device_profile) + 1;
  info = si_gpu_device_profile;
  break;
 case 0x102f:
  size_ret = strlen(si_gpu_device_version) + 1;
  info = si_gpu_device_version;
  break;
 case 0x1030:
  size_ret = strlen(si_gpu_device_extensions) + 1;
  info = si_gpu_device_extensions;
  break;
 case 0x1031:
  size_ret = 4;
  info = &si_gpu_platform;
  break;
 case 0x1032:
  size_ret = 4;
  info = &si_gpu_double_fp_config;
  break;
 case 0x1034:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x1035:
  size_ret = 4;
  info = &si_gpu_host_unified_memory;
  break;
 case 0x1036:
 case 0x1037:
 case 0x1038:
 case 0x1039:
 case 0x103a:
 case 0x103b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x103c:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x103d:
  size_ret = strlen(si_gpu_opencl_version) + 1;
  info = si_gpu_opencl_version;
  break;
 case 0x103e:
  size_ret = 4;
  info = &si_gpu_linker_available;
  break;
 default:
  fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, si_err_opencl_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-device.c", 343, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int si_opencl_device_get_info(struct si_opencl_device_t *device, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 unsigned int size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1000:
  size_ret = 4;
  info = &si_gpu_device_type;
  break;
 case 0x1001:
  size_ret = 4;
  info = &si_gpu_device_vendor_id;
  break;
 case 0x1002:
  size_ret = 4;
  info = &si_gpu_num_compute_units;
  break;
 case 0x1003:
  size_ret = 4;
  info = &si_gpu_work_item_dimensions;
  break;
 case 0x1004:
  size_ret = 4;
  info = &si_gpu_work_group_size;
  break;
 case 0x1005:
  size_ret = 12;
  info = si_gpu_work_item_sizes;
  break;
 case 0x1006:
 case 0x1007:
 case 0x1008:
 case 0x1009:
 case 0x100a:
 case 0x100b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x100c:
  size_ret = 4;
  info = &si_gpu_max_clock_frequency;
  break;
 case 0x100d:
  size_ret = 4;
  info = &si_gpu_address_bits;
  break;
 case 0x100e:
  size_ret = 4;
  info = &si_gpu_max_read_image_args;
  break;
 case 0x100f:
  size_ret = 4;
  info = &si_gpu_max_write_image_args;
  break;
 case 0x1010:
  size_ret = 8;
  info = &si_gpu_max_mem_alloc_size;
  break;
 case 0x1011:
  size_ret = 4;
  info = &si_gpu_image2d_max_width;
  break;
 case 0x1012:
  size_ret = 4;
  info = &si_gpu_image2d_max_height;
  break;
 case 0x1013:
  size_ret = 4;
  info = &si_gpu_image3d_max_width;
  break;
 case 0x1014:
  size_ret = 4;
  info = &si_gpu_image3d_max_height;
  break;
 case 0x1015:
  size_ret = 4;
  info = &si_gpu_image3d_max_depth;
  break;
 case 0x1016:
  size_ret = 4;
  info = &si_gpu_image_support;
  break;
 case 0x1017:
  size_ret = 4;
  info = &si_gpu_max_parameter_size;
  break;
 case 0x1018:
  size_ret = 4;
  info = &si_gpu_max_samplers;
  break;
 case 0x1019:
  size_ret = 4;
  info = &si_gpu_mem_base_addr_align;
  break;
 case 0x101a:
  size_ret = 4;
  info = &si_gpu_min_data_type_align_size;
  break;
 case 0x101b:
  size_ret = 4;
  info = &si_gpu_single_fp_config;
  break;
 case 0x101c:
  size_ret = 4;
  info = &si_gpu_global_mem_cache_type;
  break;
 case 0x101d:
  size_ret = 4;
  info = &si_gpu_global_mem_cacheline_size;
  break;
 case 0x101e:
  size_ret = 8;
  info = &si_gpu_global_mem_cache_size;
  break;
 case 0x101f:
  size_ret = 8;
  info = &si_gpu_global_mem_size;
  break;
 case 0x1020:
  size_ret = 8;
  info = &si_gpu_max_constant_buffer_size;
  break;
 case 0x1021:
  size_ret = 4;
  info = &si_gpu_max_constant_args;
  break;
 case 0x1022:
  size_ret = 4;
  info = &si_gpu_local_mem_type;
  break;
 case 0x1023:
  size_ret = 8;
  info = &si_gpu_local_mem_size;
  break;
 case 0x1024:
  size_ret = 4;
  info = &si_gpu_error_correction_support;
  break;
 case 0x1025:
  size_ret = 4;
  info = &si_gpu_profiling_timer_resolution;
  break;
 case 0x1026:
  size_ret = 4;
  info = &si_gpu_endian_little;
  break;
 case 0x1027:
  size_ret = 4;
  info = &si_gpu_device_available;
  break;
 case 0x1028:
  size_ret = 4;
  info = &si_gpu_compiler_available;
  break;
 case 0x1029:
  size_ret = 4;
  info = &si_gpu_execution_capabilities;
  break;
 case 0x102a:
  size_ret = 4;
  info = &si_gpu_queue_properties;
  break;
 case 0x102b:
  size_ret = strlen(si_gpu_device_name) + 1;
  info = si_gpu_device_name;
  break;
 case 0x102c:
  size_ret = strlen(si_gpu_device_vendor) + 1;
  info = si_gpu_device_vendor;
  break;
 case 0x102d:
  size_ret = strlen(si_gpu_driver_version) + 1;
  info = si_gpu_driver_version;
  break;
 case 0x102e:
  size_ret = strlen(si_gpu_device_profile) + 1;
  info = si_gpu_device_profile;
  break;
 case 0x102f:
  size_ret = strlen(si_gpu_device_version) + 1;
  info = si_gpu_device_version;
  break;
 case 0x1030:
  size_ret = strlen(si_gpu_device_extensions) + 1;
  info = si_gpu_device_extensions;
  break;
 case 0x1031:
  size_ret = 4;
  info = &si_gpu_platform;
  break;
 case 0x1032:
  size_ret = 4;
  info = &si_gpu_double_fp_config;
  break;
 case 0x1034:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x1035:
  size_ret = 4;
  info = &si_gpu_host_unified_memory;
  break;
 case 0x1036:
 case 0x1037:
 case 0x1038:
 case 0x1039:
 case 0x103a:
 case 0x103b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x103c:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x103d:
  size_ret = strlen(si_gpu_opencl_version) + 1;
  info = si_gpu_opencl_version;
  break;
 case 0x103e:
  size_ret = 4;
  info = &si_gpu_linker_available;
  break;
 default:
  fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, si_err_opencl_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-device.c", 343, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

variable_types:
name
unsigned int

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

variable_types:
addr
unsigned int

variable_types:
size
unsigned int

variable_types:
info
void *

return_type: unsigned int

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

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


decompiled_code:
__int64 x86_glut_missing()
{
return fatal(
"support for GLUT not available.\n"
"\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
"\tinstalled in your system to simulate OpenGL programs.\n"
"\t 1) Install the development packages for GLUT. Under Debian-based\n"
"\t Linux distributions, this package is listed as 'freeglut3-dev'.\n"
"\t 2) Re-run the './configure' script\n"
"\t 3) Recompile the simulator: make clean && make\n");
}

canonical_decompiled_code:
__int64 func0()
{
return fatal(
"support for GLUT not available.\n"
"\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
"\tinstalled in your system to simulate OpenGL programs.\n"
"\t 1) Install the development packages for GLUT. Under Debian-based\n"
"\t Linux distributions, this package is listed as 'freeglut3-dev'.\n"
"\t 2) Re-run the './configure' script\n"
"\t 3) Recompile the simulator: make clean && make\n");
}

original_code:
static void x86_glut_missing(void)
{
 fatal("support for GLUT not available.\n"
  "\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
  "\tinstalled in your system to simulate OpenGL programs.\n"
  "\t  1) Install the development packages for GLUT. Under Debian-based\n"
  "\t     Linux distributions, this package is listed as 'freeglut3-dev'.\n"
  "\t  2) Re-run the './configure' script\n"
  "\t  3) Recompile the simulator: make clean && make\n");
}

canonical_original_code:
static void x86_glut_missing()
{
 fatal("support for GLUT not available.\n"
  "\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
  "\tinstalled in your system to simulate OpenGL programs.\n"
  "\t  1) Install the development packages for GLUT. Under Debian-based\n"
  "\t     Linux distributions, this package is listed as 'freeglut3-dev'.\n"
  "\t  2) Re-run the './configure' script\n"
  "\t  3) Recompile the simulator: make clean && make\n");
}


decompiled_code:
void x86_glut_init()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void x86_glut_init(void)
{
}

canonical_original_code:
void x86_glut_init()
{
}


decompiled_code:
void x86_glut_done()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void x86_glut_done(void)
{
}

canonical_original_code:
void x86_glut_done()
{
}


decompiled_code:
void x86_glut_frame_buffer_init()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void x86_glut_frame_buffer_init(void)
{
}

canonical_original_code:
void x86_glut_frame_buffer_init()
{
}


decompiled_code:
void x86_glut_frame_buffer_done()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void x86_glut_frame_buffer_done(void)
{
}

canonical_original_code:
void x86_glut_frame_buffer_done()
{
}


decompiled_code:
// attributes: thunk
__int64 x86_glut_frame_buffer_clear()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func6()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_clear(void)
{
 x86_glut_missing();
}

canonical_original_code:
void x86_glut_frame_buffer_clear()
{
 x86_glut_missing();
}


decompiled_code:
// attributes: thunk
__int64 x86_glut_frame_buffer_pixel()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func7()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_pixel(int x, int y, int color)
{
 x86_glut_missing();
}

variable_types: x int

variable_types: y int

variable_types: color int


decompiled_code:
// attributes: thunk
__int64 x86_glut_frame_buffer_resize()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func8()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_resize(int width, int height)
{
 x86_glut_missing();
}

variable_types: width int

variable_types: height int


decompiled_code:
// attributes: thunk
__int64 x86_glut_frame_buffer_get_size()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func9()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_get_size(int *width, int *height)
{
 x86_glut_missing();
}

variable_types:
width
int *

variable_types:
height
int *


decompiled_code:
// attributes: thunk
__int64 x86_glut_frame_buffer_flush_request()
{
return x86_glut_frame_buffer_clear();
}

canonical_decompiled_code:
__int64 func10()
{
return func6();
}

original_code:
void x86_glut_frame_buffer_flush_request(void)
{
 x86_glut_missing();
}

canonical_original_code:
void x86_glut_frame_buffer_flush_request()
{
 x86_glut_missing();
}


decompiled_code:
// attributes: thunk
__int64 x86_glut_frame_buffer_flush_if_requested()
{
return x86_glut_frame_buffer_clear();
}

canonical_decompiled_code:
__int64 func11()
{
return func6();
}

original_code:
void x86_glut_frame_buffer_flush_if_requested(void)
{
 x86_glut_missing();
}

canonical_original_code:
void x86_glut_frame_buffer_flush_if_requested()
{
 x86_glut_missing();
}


decompiled_code:
__int64 x86_regs_create()
{
return mhandle_calloc(1LL, 318LL, "regs.c:26");
}

canonical_decompiled_code:
__int64 func0()
{
return mhandle_calloc(1LL, 318LL, "regs.c:26");
}

original_code:
struct x86_regs_t *x86_regs_create()
{
 struct x86_regs_t *regs;
 regs = (mhandle_calloc(1, sizeof(struct x86_regs_t), "regs.c" ":" "26"));
 return regs;
}

variable_types: struct x86_regs_t { unsigned int eax; unsigned int esp; unsigned short es; unsigned int eip; unsigned int eflags; struct { unsigned char value[10]; int valid; } fpu_stack[8]; int fpu_top; int fpu_code; unsigned short fpu_ctrl; unsigned char xmm[8][16]; } *


decompiled_code:
__int64 __fastcall x86_regs_free(__int64 a1)
{
return mhandle_free(a1, "regs.c:33");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return mhandle_free(a1, "regs.c:33");
}

original_code:
void x86_regs_free(struct x86_regs_t *regs)
{
 (mhandle_free(regs, "regs.c" ":" "33"));
}

user_defined_types: struct x86_regs_t { unsigned int eax; unsigned int esp; unsigned short es; unsigned int eip; unsigned int eflags; struct { unsigned char value[10]; int valid; } fpu_stack[8]; int fpu_top; int fpu_code; unsigned short fpu_ctrl; unsigned char xmm[8][16]; }


decompiled_code:
__int64 __fastcall x86_regs_copy(__int64 a1, _QWORD *a2)
{
__int64 v3; // rdi
__int64 result; // rax

v3 = a1 + 8;
*(_QWORD *)(v3 - 8) = *a2;
result = *(_QWORD *)((char *)a2 + 310);
*(_QWORD *)(v3 + 302) = result;
qmemcpy(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
(char *)a2 - (a1 - (v3 & 0xFFFFFFFFFFFFFFF8LL)),
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 318) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
__int64 v3; // rdi
__int64 result; // rax

v3 = a1 + 8;
*(_QWORD *)(v3 - 8) = *a2;
result = *(_QWORD *)((char *)a2 + 310);
*(_QWORD *)(v3 + 302) = result;
qmemcpy(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
(char *)a2 - (a1 - (v3 & 0xFFFFFFFFFFFFFFF8LL)),
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 318) >> 3));
return result;
}

original_code:
void x86_regs_copy(struct x86_regs_t *dst, struct x86_regs_t *src)
{
 memcpy(dst, src, sizeof(struct x86_regs_t));
}

variable_types:
src
struct x86_regs_t *


decompiled_code:
_DWORD *evg_opencl_platform_create()
{
_DWORD *v0; // r12

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opencl-platform.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_platform_create");
*v0 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 1LL);
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

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

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opencl-platform.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_platform_create");
*v0 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 1LL);
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

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

variable_types: struct evg_opencl_platform_t { unsigned int id; } *


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

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

original_code:
void evg_opencl_platform_free(struct evg_opencl_platform_t *platform)
{
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, platform);
 (mhandle_free(platform, "opencl-platform.c" ":" "51"));
}

user_defined_types: struct evg_opencl_platform_t { unsigned int id; }


decompiled_code:
__int64 __fastcall evg_opencl_platform_get_info(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v5; // rax
const char *v6; // r14
unsigned int v10; // er12

v5 = (unsigned int)(a2 - 2304);
if ( (unsigned int)v5 > 4 )
{
fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s", a2, evg_err_opencl_param_note);
_assert_fail("info", "opencl-platform.c", 0x5Fu, "evg_opencl_platform_get_info");
}
v6 = CSWTCH_8[v5];
v10 = strlen(v6) + 1;
if ( !a4 || v10 > a5 )
return v10;
mem_write(a3, a4, v10, v6);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v5; // rax
const char *v6; // r14
unsigned int v10; // er12

v5 = (unsigned int)(a2 - 2304);
if ( (unsigned int)v5 > 4 )
{
fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s", a2, evg_err_opencl_param_note);
_assert_fail("info", "opencl-platform.c", 0x5Fu, "evg_opencl_platform_get_info");
}
v6 = CSWTCH_8[v5];
v10 = strlen(v6) + 1;
if ( !a4 || v10 > a5 )
return v10;
mem_write(a3, a4, v10, v6);
return v10;
}

original_code:
uint32_t evg_opencl_platform_get_info(struct evg_opencl_platform_t *platform, uint32_t name, struct mem_t *mem, uint32_t addr, uint32_t size)
{
 char *platform_profile = "FULL_PROFILE";
 char *platform_version = "OpenCL 1.1 Multi2Sim-v" "4.0";
 char *platform_name = "Multi2Sim";
 char *platform_vendor = "www.multi2sim.org";
 char *platform_extensions = "";
 uint32_t size_ret = 0;
 char *info;
 switch (name) {
 case 0x900:
  info = platform_profile;
  break;
 case 0x901:
  info = platform_version;
  break;
 case 0x902:
  info = platform_name;
  break;
 case 0x903:
  info = platform_vendor;
  break;
 case 0x904:
  info = platform_extensions;
  break;
 default:
  info = ((void *)0);
  fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-platform.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 size_ret = strlen(info) + 1;
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int evg_opencl_platform_get_info(struct evg_opencl_platform_t *platform, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 char *platform_profile = "FULL_PROFILE";
 char *platform_version = "OpenCL 1.1 Multi2Sim-v" "4.0";
 char *platform_name = "Multi2Sim";
 char *platform_vendor = "www.multi2sim.org";
 char *platform_extensions = "";
 unsigned int size_ret = 0;
 char *info;
 switch (name) {
 case 0x900:
  info = platform_profile;
  break;
 case 0x901:
  info = platform_version;
  break;
 case 0x902:
  info = platform_name;
  break;
 case 0x903:
  info = platform_vendor;
  break;
 case 0x904:
  info = platform_extensions;
  break;
 default:
  info = ((void *)0);
  fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-platform.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 size_ret = strlen(info) + 1;
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

variable_types:
info
char *

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


decompiled_code:
__int64 __fastcall sim_signal_name(unsigned int a1)
{
return map_value(&signal_map, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return map_value(&signal_map, a1);
}

original_code:
char *sim_signal_name(int signum)
{
 return map_value(&signal_map, signum);
}

variable_types: signum int

return_type: char *


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

result = 0LL;
if ( (unsigned int)(a2 - 1) <= 0x3F )
result = (*a1 >> ((unsigned __int8)a2 - 1)) & 1LL;
return result;
}

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

result = 0LL;
if ( (unsigned int)(a2 - 1) <= 0x3F )
result = (*a1 >> ((unsigned __int8)a2 - 1)) & 1LL;
return result;
}

original_code:
int sim_sigset_member(unsigned long long *sim_sigset, int sig)
{
 if (sig < 1 || sig > 64)
  return 0;
 return (*sim_sigset & (1ULL << (sig - 1))) > 0;
}

variable_types: sig int


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

result = mhandle_calloc(1LL, 40LL, "signal.c:167");
if ( !result )
{
fatal("%s: out of memory", "signal_mask_table_create");
result = 0LL;
}
return result;
}

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

result = mhandle_calloc(1LL, 40LL, "signal.c:167");
if ( !result )
{
fatal("%s: out of memory", "signal_mask_table_create");
result = 0LL;
}
return result;
}

original_code:
struct signal_mask_table_t *signal_mask_table_create(void)
{
 struct signal_mask_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_mask_table_t), "signal.c" ":" "167"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

canonical_original_code:
struct signal_mask_table_t *signal_mask_table_create()
{
 struct signal_mask_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_mask_table_t), "signal.c" ":" "167"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

variable_types: struct signal_mask_table_t { unsigned long long pending; unsigned long long blocked; unsigned long long backup; struct x86_regs_t { unsigned int eax; unsigned int esp; unsigned short es; unsigned int eip; unsigned int eflags; struct { unsigned char value[10]; int valid; } fpu_stack[8]; int fpu_top; int fpu_code; unsigned short fpu_ctrl; unsigned char xmm[8][16]; } *regs; unsigned int pretcode; } *

user_defined_types: struct signal_mask_table_t { unsigned long long pending; unsigned long long blocked; unsigned long long backup; struct x86_regs_t *regs; unsigned int pretcode; }


decompiled_code:
__int64 __fastcall signal_mask_table_free(__int64 a1)
{
return mhandle_free(a1, "signal.c:177");
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return mhandle_free(a1, "signal.c:177");
}

original_code:
void signal_mask_table_free(struct signal_mask_table_t *table)
{
 (mhandle_free(table, "signal.c" ":" "177"));
}


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

result = mhandle_calloc(1LL, 1544LL, "signal.c:192");
if ( !result )
{
fatal("%s: out of memory", "signal_handler_table_create");
result = 0LL;
}
return result;
}

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

result = mhandle_calloc(1LL, 1544LL, "signal.c:192");
if ( !result )
{
fatal("%s: out of memory", "signal_handler_table_create");
result = 0LL;
}
return result;
}

original_code:
struct signal_handler_table_t *signal_handler_table_create(void)
{
 struct signal_handler_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_handler_table_t), "signal.c" ":" "192"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

canonical_original_code:
struct signal_handler_table_t *signal_handler_table_create()
{
 struct signal_handler_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_handler_table_t), "signal.c" ":" "192"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

variable_types: struct signal_handler_table_t { int num_links; struct sim_sigaction { unsigned int handler; unsigned int flags; unsigned int restorer; unsigned long long mask; } sigaction[64]; } *

user_defined_types: struct signal_handler_table_t { int num_links; struct sim_sigaction sigaction[64]; }


decompiled_code:
__int64 __fastcall signal_handler_table_free(_DWORD *a1)
{
if ( *a1 )
_assert_fail("!table->num_links", "signal.c", 0xCBu, "signal_handler_table_free");
return mhandle_free(a1, "signal.c:204");
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1)
{
if ( *a1 )
_assert_fail("!table->num_links", "signal.c", 0xCBu, "signal_handler_table_free");
return mhandle_free(a1, "signal.c:204");
}

original_code:
void signal_handler_table_free(struct signal_handler_table_t *table)
{
 ((void) sizeof ((!table->num_links) ? 1 : 0), __extension__ ({ if (!table->num_links) ; else __assert_fail ("!table->num_links", "signal.c", 203, __extension__ __PRETTY_FUNCTION__); }));
 (mhandle_free(table, "signal.c" ":" "204"));
}

user_defined_types: struct sim_sigaction { unsigned int handler; unsigned int flags; unsigned int restorer; unsigned long long mask; }


decompiled_code:
__int64 __fastcall signal_handler_table_unlink(int *a1)
{
int v1; // eax
__int64 result; // rax

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("table->num_links >= 0", "signal.c", 0xD9u, "signal_handler_table_unlink");
if ( !v1 )
return signal_handler_table_free(a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1)
{
int v1; // eax
__int64 result; // rax

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("table->num_links >= 0", "signal.c", 0xD9u, "signal_handler_table_unlink");
if ( !v1 )
return func10(a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

original_code:
void signal_handler_table_unlink(struct signal_handler_table_t *table)
{
 ((void) sizeof ((table->num_links >= 0) ? 1 : 0), __extension__ ({ if (table->num_links >= 0) ; else __assert_fail ("table->num_links >= 0", "signal.c", 217, __extension__ __PRETTY_FUNCTION__); }));
 if (table->num_links)
  table->num_links--;
 else
  signal_handler_table_free(table);
}


decompiled_code:
__suseconds_t m2s_timer_now()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static long long m2s_timer_now(void)
{
 struct timeval tv;
 long long value;
 gettimeofday(&tv, ((void *)0));
 value = (long long) tv.tv_sec * 1000000 + tv.tv_usec;
 return value;
}

canonical_original_code:
static long long m2s_timer_now()
{
 struct timeval tv;
 long long value;
 gettimeofday(&tv, ((void *)0));
 value = (long long) tv.tv_sec * 1000000 + tv.tv_usec;
 return value;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
value
long long

return_type: long long


decompiled_code:
__int64 __fastcall m2s_timer_create(void *a1)
{
void *v1; // rbp
__int64 v2; // r12
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "timer.c:74");
if ( !v2 )
fatal("%s: out of memory", "m2s_timer_create");
*(_DWORD *)(v2 + 8) = 1;
if ( !a1 )
v1 = &unk_1A6;
v3 = mhandle_strdup(v1, "timer.c:80");
*(_QWORD *)v2 = v3;
if ( !v3 )
fatal("%s: out of memory", "m2s_timer_create");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1)
{
void *v1; // rbp
__int64 v2; // r12
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "timer.c:74");
if ( !v2 )
fatal("%s: out of memory", "m2s_timer_create");
*(_DWORD *)(v2 + 8) = 1;
if ( !a1 )
v1 = &unk_1A6;
v3 = mhandle_strdup(v1, "timer.c:80");
*(_QWORD *)v2 = v3;
if ( !v3 )
fatal("%s: out of memory", "m2s_timer_create");
return v2;
}

original_code:
struct m2s_timer_t *m2s_timer_create(char *name)
{
 struct m2s_timer_t *timer;
 timer = (mhandle_calloc(1, sizeof(struct m2s_timer_t), "timer.c" ":" "74"));
 if (!timer)
  fatal("%s: out of memory", __FUNCTION__);
 timer->state = m2s_timer_state_stopped;
 timer->name = (mhandle_strdup(name ? name : "", "timer.c" ":" "80"));
 if (!timer->name)
  fatal("%s: out of memory", __FUNCTION__);
 return timer;
}

variable_types:
name
char *

variable_types: struct m2s_timer_t { char *name; enum m2s_timer_state_t { m2s_timer_state_invalid=0, m2s_timer_state_stopped=1, m2s_timer_state_running=2 } state; long long start_value; long long total_value; } *

user_defined_types: struct m2s_timer_t { char *name; enum m2s_timer_state_t state; long long start_value; long long total_value; }


decompiled_code:
__int64 __fastcall m2s_timer_free(_QWORD *a1)
{
mhandle_free(*a1, "timer.c:91");
return mhandle_free(a1, "timer.c:92");
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
mhandle_free(*a1, "timer.c:91");
return mhandle_free(a1, "timer.c:92");
}

original_code:
void m2s_timer_free(struct m2s_timer_t *timer)
{
 (mhandle_free(timer->name, "timer.c" ":" "91"));
 (mhandle_free(timer, "timer.c" ":" "92"));
}

user_defined_types: enum m2s_timer_state_t { m2s_timer_state_invalid=0, m2s_timer_state_stopped=1, m2s_timer_state_running=2 }


original_code:
void m2s_timer_start(struct m2s_timer_t *timer)
{
 if (timer->state == m2s_timer_state_running)
  return;
 timer->state = m2s_timer_state_running;
 timer->start_value = m2s_timer_now();
}


original_code:
void m2s_timer_stop(struct m2s_timer_t *timer)
{
 long long ellapsed;
 if (timer->state == m2s_timer_state_stopped)
  return;
 ellapsed = m2s_timer_now() - timer->start_value;
 timer->state = m2s_timer_state_stopped;
 timer->total_value += ellapsed;
}

variable_types:
ellapsed
long long


decompiled_code:
__suseconds_t __fastcall m2s_timer_reset(__int64 a1)
{
__suseconds_t result; // rax

*(_QWORD *)(a1 + 24) = 0LL;
result = m2s_timer_now();
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
__suseconds_t __fastcall func5(__int64 a1)
{
__suseconds_t result; // rax

*(_QWORD *)(a1 + 24) = 0LL;
result = func0();
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void m2s_timer_reset(struct m2s_timer_t *timer)
{
 timer->total_value = 0;
 timer->start_value = m2s_timer_now();
}


decompiled_code:
__suseconds_t __fastcall m2s_timer_get_value(__int64 a1)
{
__suseconds_t result; // rax

if ( *(_DWORD *)(a1 + 8) == 1 )
result = *(_QWORD *)(a1 + 24);
else
result = *(_QWORD *)(a1 + 24) + m2s_timer_now() - *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__suseconds_t __fastcall func6(__int64 a1)
{
__suseconds_t result; // rax

if ( *(_DWORD *)(a1 + 8) == 1 )
result = *(_QWORD *)(a1 + 24);
else
result = *(_QWORD *)(a1 + 24) + func0() - *(_QWORD *)(a1 + 16);
return result;
}

original_code:
long long m2s_timer_get_value(struct m2s_timer_t *timer)
{
 long long ellapsed;
 if (timer->state == m2s_timer_state_stopped)
  return timer->total_value;
 ellapsed = m2s_timer_now() - timer->start_value;
 return timer->total_value + ellapsed;
}


decompiled_code:
__int64 __fastcall m2s_timer_get_state(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

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

original_code:
enum m2s_timer_state_t m2s_timer_get_state(struct m2s_timer_t *timer)
{
 return timer->state;
}

return_type: enum m2s_timer_state_t { m2s_timer_state_invalid=0, m2s_timer_state_stopped=1, m2s_timer_state_running=2 }


decompiled_code:
__int64 __fastcall m2s_timer_get_name(__int64 a1)
{
return *(_QWORD *)a1;
}

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

original_code:
char *m2s_timer_get_name(struct m2s_timer_t *timer)
{
 return timer->name;
}


original_code:
static void mark_corruption(void *ptr, unsigned long size)
{
 unsigned long i;
 for (i = 0; i < 2; i++)
  ((unsigned char *) ptr)[i] = 0x5a;
 for (i = 2 + size; i < (2 * 2) + size; i++)
  ((unsigned char *) ptr)[i] = 0xa5;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
i
unsigned long


outofmem

decompiled_code:
void __fastcall __noreturn outofmem(const char *a1)
{
fprintf(stderr, "\nfatal: %s: out of memory\n", a1);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "\nfatal: %s: out of memory\n", a1);
abort();
}

original_code:
static void outofmem(char *at)
{
 fprintf(stderr, "\nfatal: %s: out of memory\n", at);
 abort();
}

variable_types:
at
char *


initialize

decompiled_code:
unsigned __int64 initialize()
{
unsigned __int64 result; // rax

result = (unsigned int)initialized;
if ( !initialized )
{
initialized = 1;
result = (unsigned __int64)calloc(0x3E8uLL, 0x20uLL);
ht_size = 1000;
ht = (void *)result;
ht_count = 0;
if ( !result )
outofmem("lib mhandle (initialize)");
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func2()
{
unsigned __int64 result; // rax

result = (unsigned int)initialized;
if ( !initialized )
{
initialized = 1;
result = (unsigned __int64)calloc(0x3E8uLL, 0x20uLL);
ht_size = 1000;
ht = (void *)result;
ht_count = 0;
if ( !result )
func1("lib mhandle (initialize)");
}
return result;
}

original_code:
static void initialize()
{
 if (initialized)
  return;
 initialized = 1;
 ht = (struct item_t *) calloc(1000, sizeof(struct item_t));
 ht_size = 1000;
 ht_count = 0;
 if (!ht)
  outofmem("lib mhandle (initialize)");
}

user_defined_types: struct item_t { void *ptr; unsigned long size; char *at; int removed; int active; }


decompiled_code:
void ht_grow()
{
char *v0; // r12
int v1; // ebp
char *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi
__int64 v5; // rdx
__int64 v6; // rdi

v0 = (char *)ht;
v1 = ht_size;
ht_size *= 2;
ht = calloc(ht_size, 0x20uLL);
if ( !ht )
outofmem("lib mhandle (resizing hash table)");
if ( v1 > 0 )
{
v2 = v0;
v3 = (__int64)&v0[32 * (v1 - 1) + 32];
do
{
while ( (v2[24] & 3) != 2 )
{
v2 += 32;
if ( v2 == (char *)v3 )
goto LABEL_7;
}
v4 = *((_QWORD *)v2 + 1);
v5 = *((_QWORD *)v2 + 2);
v2 += 32;
v6 = *((_QWORD *)v2 - 4);
--ht_count;
mem_busy -= v4;
ht_insert(v6, v4, v5);
}
while ( v2 != (char *)v3 );
}
LABEL_7:
free(v0);
}

original_code:
static void ht_grow()
{
 int old_size, i;
 struct item_t *old_ht;
 old_size = ht_size;
 old_ht = ht;
 ht_size = ht_size * 2;
 ht = (struct item_t *) calloc(ht_size, sizeof(struct item_t));
 if (!ht)
  outofmem("lib mhandle (resizing hash table)");
 for (i = 0; i < old_size; i++) {
  if (old_ht[i].active && !old_ht[i].removed) {
   ht_count--;
   mem_busy -= old_ht[i].size;
   ht_insert(old_ht[i].ptr, old_ht[i].size, old_ht[i].at);
  }
 }
 free(old_ht);
}

canonical_original_code:
static void ht_grow()
{
 int old_size; int i;
 struct item_t *old_ht;
 old_size = ht_size;
 old_ht = ht;
 ht_size = ht_size * 2;
 ht = (struct item_t *) calloc(ht_size, sizeof(struct item_t));
 if (!ht)
  outofmem("lib mhandle (resizing hash table)");
 for (i = 0; i < old_size; i++) {
  if (old_ht[i].active && !old_ht[i].removed) {
   ht_count--;
   mem_busy -= old_ht[i].size;
   ht_insert(old_ht[i].ptr, old_ht[i].size, old_ht[i].at);
  }
 }
 free(old_ht);
}

variable_types: i int

variable_types: struct item_t { void *ptr; unsigned long size; char *at; int removed; int active; } *


decompiled_code:
__int64 __fastcall ht_insert(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v3; // er9
int v6; // edi
unsigned __int64 v7; // rdx
char *i; // rcx
int v9; // eax
__int64 result; // rax

v3 = ht_count;
v6 = ht_size;
if ( ht_size / 2 <= ht_count )
{
ht_grow();
v6 = ht_size;
v3 = ht_count;
}
v7 = a1 % v6;
for ( i = (char *)ht + 32 * (int)v7; (i[24] & 3) == 2; i = (char *)ht + 32 * (int)v7 )
LODWORD(v7) = ((int)v7 + 1) % v6;
v9 = (unsigned __int8)i[24];
*(_QWORD *)i = a1;
*((_QWORD *)i + 1) = a2;
*((_QWORD *)i + 2) = a3;
result = v9 & 0xFFFFFFFC | 2;
mem_busy += a2;
i[24] = result;
ht_count = v3 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v3; // er9
int v6; // edi
unsigned __int64 v7; // rdx
char *i; // rcx
int v9; // eax
__int64 result; // rax

v3 = ht_count;
v6 = ht_size;
if ( ht_size / 2 <= ht_count )
{
func3();
v6 = ht_size;
v3 = ht_count;
}
v7 = a1 % v6;
for ( i = (char *)ht + 32 * (int)v7; (i[24] & 3) == 2; i = (char *)ht + 32 * (int)v7 )
LODWORD(v7) = ((int)v7 + 1) % v6;
v9 = (unsigned __int8)i[24];
*(_QWORD *)i = a1;
*((_QWORD *)i + 1) = a2;
*((_QWORD *)i + 2) = a3;
result = v9 & 0xFFFFFFFC | 2;
mem_busy += a2;
i[24] = result;
ht_count = v3 + 1;
return result;
}

original_code:
static void ht_insert(void *ptr, unsigned long size, char *at)
{
 int idx;
 if (ht_count >= ht_size / 2)
  ht_grow();
 idx = (unsigned long) ptr % ht_size;
 while (ht[idx].active && !ht[idx].removed)
  idx = (idx + 1) % ht_size;
 ht[idx].ptr = ptr;
 ht[idx].size = size;
 ht[idx].at = at;
 ht[idx].active = 1;
 ht[idx].removed = 0;
 mem_busy += size;
 ht_count++;
}

variable_types: idx int


decompiled_code:
unsigned __int64 __fastcall check_corruption(_BYTE *a1, __int64 a2, const char *a3, __int64 a4, __int64 a5)
{
unsigned __int64 result; // rax
unsigned __int64 v7; // rdx
_BOOL8 v8; // rcx
__int64 v9; // rdx
FILE *v10; // r10
int v11; // er12
int v12; // ebx
int v13; // ebp
__int64 v14; // rax
char *v15; // rcx
unsigned __int64 v16; // rsi
const char *v17; // rcx

result = a2 + 2;
v7 = a2 + 4;
if ( a1[1] != 90 )
{
v8 = 1LL;
if ( v7 <= result )
goto LABEL_21;
if ( a1[a2 + 2] != 0xA5 )
goto LABEL_4;
LABEL_15:
if ( a1[a2 + 3] == 0xA5 )
goto LABEL_16;
LABEL_4:
v9 = ht_size;
v10 = stderr;
v11 = 2;
if ( !ht_size )
check_corruption_cold(a1, a2, ht_size, v8, a5, a3);
goto LABEL_5;
}
v8 = *a1 != 90;
if ( v7 > result )
{
if ( a1[a2 + 2] != 0xA5 )
goto LABEL_4;
goto LABEL_15;
}
LABEL_16:
if ( v8 )
{
LABEL_21:
v9 = ht_size;
v10 = stderr;
v11 = 1;
if ( !ht_size )
{
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, "before", a1);
goto LABEL_23;
}
LABEL_5:
v12 = -1;
v13 = -1;
v14 = 0LL;
v15 = (char *)ht;
do
{
if ( (v15[24] & 3) == 2 )
{
v16 = *(_QWORD *)v15;
if ( *(_QWORD *)v15 < (unsigned __int64)a1 && (v13 == -1 || v16 > *((_QWORD *)ht + 4 * v13)) )
v13 = v14;
if ( v16 > (unsigned __int64)a1 && (v12 == -1 || v16 < *((_QWORD *)ht + 4 * v12)) )
v12 = v14;
}
++v14;
v15 += 32;
}
while ( v14 != v9 );
v17 = "after";
if ( v11 == 1 )
v17 = "before";
fprintf(v10, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, v17, a1);
if ( v13 >= 0 )
fprintf(stderr, "\tprev block: %s (%p)\n", *((const char **)ht + 4 * v13 + 2), *((const void **)ht + 4 * v13));
if ( v12 >= 0 )
fprintf(stderr, "\tnext block: %s (%p)\n", *((const char **)ht + 4 * v12 + 2), *((const void **)ht + 4 * v12));
LABEL_23:
abort();
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_BYTE *a1, __int64 a2, const char *a3, __int64 a4, __int64 a5)
{
unsigned __int64 result; // rax
unsigned __int64 v7; // rdx
_BOOL8 v8; // rcx
__int64 v9; // rdx
FILE *v10; // r10
int v11; // er12
int v12; // ebx
int v13; // ebp
__int64 v14; // rax
char *v15; // rcx
unsigned __int64 v16; // rsi
const char *v17; // rcx

result = a2 + 2;
v7 = a2 + 4;
if ( a1[1] != 90 )
{
v8 = 1LL;
if ( v7 <= result )
goto LABEL_21;
if ( a1[a2 + 2] != 0xA5 )
goto LABEL_4;
LABEL_15:
if ( a1[a2 + 3] == 0xA5 )
goto LABEL_16;
LABEL_4:
v9 = ht_size;
v10 = stderr;
v11 = 2;
if ( !ht_size )
func12(a1, a2, ht_size, v8, a5, a3);
goto LABEL_5;
}
v8 = *a1 != 90;
if ( v7 > result )
{
if ( a1[a2 + 2] != 0xA5 )
goto LABEL_4;
goto LABEL_15;
}
LABEL_16:
if ( v8 )
{
LABEL_21:
v9 = ht_size;
v10 = stderr;
v11 = 1;
if ( !ht_size )
{
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, "before", a1);
goto LABEL_23;
}
LABEL_5:
v12 = -1;
v13 = -1;
v14 = 0LL;
v15 = (char *)ht;
do
{
if ( (v15[24] & 3) == 2 )
{
v16 = *(_QWORD *)v15;
if ( *(_QWORD *)v15 < (unsigned __int64)a1 && (v13 == -1 || v16 > *((_QWORD *)ht + 4 * v13)) )
v13 = v14;
if ( v16 > (unsigned __int64)a1 && (v12 == -1 || v16 < *((_QWORD *)ht + 4 * v12)) )
v12 = v14;
}
++v14;
v15 += 32;
}
while ( v14 != v9 );
v17 = "after";
if ( v11 == 1 )
v17 = "before";
fprintf(v10, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, v17, a1);
if ( v13 >= 0 )
fprintf(stderr, "\tprev block: %s (%p)\n", *((const char **)ht + 4 * v13 + 2), *((const void **)ht + 4 * v13));
if ( v12 >= 0 )
fprintf(stderr, "\tnext block: %s (%p)\n", *((const char **)ht + 4 * v12 + 2), *((const void **)ht + 4 * v12));
LABEL_23:
abort();
}
return result;
}

original_code:
static void check_corruption(void *ptr, unsigned long size, char *at)
{
 unsigned long i;
 int corrupt = 0, prev, next;
 for (i = 0; i < 2; i++)
  if (((unsigned char *) ptr)[i] != 0x5a)
   corrupt = 1;
 for (i = 2 + size; i < (2 * 2) + size; i++)
  if (((unsigned char *) ptr)[i] != 0xa5)
   corrupt = 2;
 if (!corrupt)
  return;
 prev = next = -1;
 for (i = 0; i < ht_size; i++) {
  if (ht[i].active && !ht[i].removed) {
   if (ht[i].ptr < ptr && (prev == -1 || ht[i].ptr > ht[prev].ptr))
    prev = i;
   if (ht[i].ptr > ptr && (next == -1 || ht[i].ptr < ht[next].ptr))
    next = i;
  }
 }
 fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n",
  at, corrupt == 1 ? "before" : "after", ptr);
 if (prev >= 0)
  fprintf(stderr, "\tprev block: %s (%p)\n", ht[prev].at, ht[prev].ptr);
 if (next >= 0)
  fprintf(stderr, "\tnext block: %s (%p)\n", ht[next].at, ht[next].ptr);
 abort();
}

canonical_original_code:
static void check_corruption(void *ptr, unsigned long size, char *at)
{
 unsigned long i;
 int corrupt = 0; int prev; int next;
 for (i = 0; i < 2; i++)
  if (((unsigned char *) ptr)[i] != 0x5a)
   corrupt = 1;
 for (i = 2 + size; i < (2 * 2) + size; i++)
  if (((unsigned char *) ptr)[i] != 0xa5)
   corrupt = 2;
 if (!corrupt)
  return;
 prev = next = -1;
 for (i = 0; i < ht_size; i++) {
  if (ht[i].active && !ht[i].removed) {
   if (ht[i].ptr < ptr && (prev == -1 || ht[i].ptr > ht[prev].ptr))
    prev = i;
   if (ht[i].ptr > ptr && (next == -1 || ht[i].ptr < ht[next].ptr))
    next = i;
  }
 }
 fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n",
  at, corrupt == 1 ? "before" : "after", ptr);
 if (prev >= 0)
  fprintf(stderr, "\tprev block: %s (%p)\n", ht[prev].at, ht[prev].ptr);
 if (next >= 0)
  fprintf(stderr, "\tnext block: %s (%p)\n", ht[next].at, ht[next].ptr);
 abort();
}

variable_types: corrupt int

variable_types: prev int

variable_types: next int


decompiled_code:
__int64 __fastcall ht_remove(unsigned __int64 a1, const char *a2)
{
unsigned __int64 i; // rdx
__int64 v3; // rbx
char v4; // al
char *v5; // rbx
__int64 result; // rax

for ( i = a1 % ht_size; ; LODWORD(i) = ((int)i + 1) % ht_size )
{
v3 = 32LL * (int)i;
v4 = *((_BYTE *)ht + v3 + 24);
if ( *(_QWORD *)((char *)ht + v3) == a1 && (v4 & 3) == 2 )
break;
if ( (v4 & 2) == 0 )
{
fprintf(stderr, "\n%s: free: invalid pointer %p\n", a2, (const void *)a1);
abort();
}
}
check_corruption((_BYTE *)a1, *(_QWORD *)((char *)ht + v3 + 8), a2, (__int64)ht + v3, (__int64)ht);
v5 = (char *)ht + v3;
--ht_count;
result = *((_QWORD *)v5 + 1);
v5[24] |= 1u;
mem_busy -= result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 a1, const char *a2)
{
unsigned __int64 i; // rdx
__int64 v3; // rbx
char v4; // al
char *v5; // rbx
__int64 result; // rax

for ( i = a1 % ht_size; ; LODWORD(i) = ((int)i + 1) % ht_size )
{
v3 = 32LL * (int)i;
v4 = *((_BYTE *)ht + v3 + 24);
if ( *(_QWORD *)((char *)ht + v3) == a1 && (v4 & 3) == 2 )
break;
if ( (v4 & 2) == 0 )
{
fprintf(stderr, "\n%s: free: invalid pointer %p\n", a2, (const void *)a1);
abort();
}
}
func5((_BYTE *)a1, *(_QWORD *)((char *)ht + v3 + 8), a2, (__int64)ht + v3, (__int64)ht);
v5 = (char *)ht + v3;
--ht_count;
result = *((_QWORD *)v5 + 1);
v5[24] |= 1u;
mem_busy -= result;
return result;
}

original_code:
static unsigned long ht_remove(void *ptr, char *at)
{
 int idx;
 idx = (unsigned long) ptr % ht_size;
 while (ht[idx].ptr != ptr || !ht[idx].active || ht[idx].removed) {
  if (!ht[idx].active) {
   fprintf(stderr, "\n%s: free: invalid pointer %p\n",
    at, ptr);
   abort();
  }
  idx = (idx + 1) % ht_size;
 }
 check_corruption(ptr, ht[idx].size, at);
 ht[idx].removed = 1;
 mem_busy -= ht[idx].size;
 ht_count--;
 return ht[idx].size;
}

return_type: unsigned long


decompiled_code:
void __fastcall mhandle_free(__int64 a1, const char *a2)
{
__int64 v2; // rax

if ( a1 )
{
initialize();
v2 = ht_remove(a1 - 2, a2);
memset((void *)(a1 - 2), 0, v2 + 4);
free((void *)(a1 - 2));
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, const char *a2)
{
__int64 v2; // rax

if ( a1 )
{
func2();
v2 = func6(a1 - 2, a2);
memset((void *)(a1 - 2), 0, v2 + 4);
free((void *)(a1 - 2));
}
}

original_code:
void mhandle_free(void *ptr, char *at)
{
 unsigned long size;
 if (!ptr)
  return;
 initialize();
 ptr -= 2;
 size = ht_remove(ptr, at);
 bzero(ptr, size + (2 * 2));
 free(ptr);
}


decompiled_code:
char *__fastcall mhandle_strdup(void *src, const char *a2)
{
size_t v2; // rbx
size_t v3; // r13
_WORD *v4; // rax
char *v5; // r15
_WORD *v6; // rbp

v2 = strlen((const char *)src);
v3 = v2 + 1;
initialize();
v4 = malloc(v2 + 5);
if ( !v4 )
outofmem(a2);
v5 = (char *)(v4 + 1);
v6 = v4;
memcpy(v4 + 1, src, v3);
mark_corruption(v6, v3);
ht_insert((unsigned __int64)v6, v3, (__int64)a2);
return v5;
}

canonical_decompiled_code:
char *__fastcall func8(void *src, const char *a2)
{
size_t v2; // rbx
size_t v3; // r13
_WORD *v4; // rax
char *v5; // r15
_WORD *v6; // rbp

v2 = strlen((const char *)src);
v3 = v2 + 1;
func2();
v4 = malloc(v2 + 5);
if ( !v4 )
func1(a2);
v5 = (char *)(v4 + 1);
v6 = v4;
memcpy(v4 + 1, src, v3);
func0(v6, v3);
func4((unsigned __int64)v6, v3, (__int64)a2);
return v5;
}

original_code:
char *mhandle_strdup(const char *s, char *at)
{
 char *ptr;
 unsigned long size = strlen(s) + 1;
 initialize();
 ptr = malloc(size + (2 * 2));
 if (!ptr)
  outofmem(at);
 memcpy(ptr + 2, s, size);
 mark_corruption(ptr, size);
 ht_insert(ptr, size, at);
 return ptr + 2;
}

canonical_original_code:
char *mhandle_strdup(char *s, char *at)
{
 char *ptr;
 unsigned long size = strlen(s) + 1;
 initialize();
 ptr = malloc(size + (2 * 2));
 if (!ptr)
  outofmem(at);
 memcpy(ptr + 2, s, size);
 mark_corruption(ptr, size);
 ht_insert(ptr, size, at);
 return ptr + 2;
}

variable_types:
s
char *

variable_types:
ptr
char *


decompiled_code:
__int64 si_emu_done()
{
if ( si_emu_report_file )
fclose(si_emu_report_file);
si_opencl_repo_free_all_objects(*(_QWORD *)(si_emu + 8));
si_opencl_repo_free(*(_QWORD *)(si_emu + 8));
si_disasm_done();
si_isa_done();
mem_free(*(_QWORD *)(si_emu + 128));
m2s_timer_free(*(_QWORD *)si_emu);
return mhandle_free(si_emu, "emu.c:114");
}

canonical_decompiled_code:
__int64 func1()
{
if ( si_emu_report_file )
fclose(si_emu_report_file);
si_opencl_repo_free_all_objects(*(_QWORD *)(si_emu + 8));
si_opencl_repo_free(*(_QWORD *)(si_emu + 8));
si_disasm_done();
si_isa_done();
mem_free(*(_QWORD *)(si_emu + 128));
m2s_timer_free(*(_QWORD *)si_emu);
return mhandle_free(si_emu, "emu.c:114");
}

original_code:
void si_emu_done()
{
 if (si_emu_report_file)
  fclose(si_emu_report_file);
 si_opencl_repo_free_all_objects(si_emu->opencl_repo);
 si_opencl_repo_free(si_emu->opencl_repo);
 si_disasm_done();
 si_isa_done();
 mem_free(si_emu->global_mem);
 m2s_timer_free(si_emu->timer);
 (mhandle_free(si_emu, "emu.c" ":" "114"));
}


decompiled_code:
__int64 __fastcall si_emu_libopencl_failed(unsigned int a1)
{
return warning(
"context %d finished after failing to access OpenCL library.\n"
"\tMulti2Sim has detected several attempts to access 'libm2s-opencl.so' by your\n"
"\tapplication's dynamic linker. Please, make sure that this file is available\n"
"\teither in any shared library path, in the current working directory, or in\n"
"\tany directory pointed by the environment variable LD_LIBRARY_PATH. See the\n"
"\tMulti2Sim Guide for further details (www.multi2sim.org).\n",
a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return warning(
"context %d finished after failing to access OpenCL library.\n"
"\tMulti2Sim has detected several attempts to access 'libm2s-opencl.so' by your\n"
"\tapplication's dynamic linker. Please, make sure that this file is available\n"
"\teither in any shared library path, in the current working directory, or in\n"
"\tany directory pointed by the environment variable LD_LIBRARY_PATH. See the\n"
"\tMulti2Sim Guide for further details (www.multi2sim.org).\n",
a1);
}

original_code:
void si_emu_libopencl_failed(int pid)
{
 warning("context %d finished after failing to access OpenCL library.\n"
  "\tMulti2Sim has detected several attempts to access 'libm2s-opencl.so' by your\n"
  "\tapplication's dynamic linker. Please, make sure that this file is available\n"
  "\teither in any shared library path, in the current working directory, or in\n"
  "\tany directory pointed by the environment variable LD_LIBRARY_PATH. See the\n"
  "\tMulti2Sim Guide for further details (www.multi2sim.org).\n",
  pid);
}

variable_types: pid int


decompiled_code:
void __fastcall __noreturn si_emu_disasm(__int64 a1)
{
int v1; // ebp
__int64 v2; // r13
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // r14
int v6; // eax
__int64 v7; // r12
char v8[248]; // [rsp+0h] [rbp-F8h] BYREF

si_disasm_init();
v1 = 0;
v2 = elf_file_create_from_path(a1);
while ( (int)list_count(*(_QWORD *)(v2 + 56)) > v1 )
{
v3 = (const char **)list_get(*(_QWORD *)(v2 + 56), (unsigned int)v1);
v4 = list_get(*(_QWORD *)(v2 + 32), *((unsigned int *)v3 + 4));
if ( v4 && (unsigned int)str_prefix(*v3, "__OpenCL_") )
{
if ( (unsigned int)str_suffix(*v3, "_kernel") )
{
v5 = *v3;
v6 = strlen(*v3);
str_substr(v8, 200LL, v5, 9LL, (unsigned int)(v6 - 16));
v7 = si_bin_file_create(*(_QWORD *)(v4 + 16) + *((unsigned int *)v3 + 2), *((unsigned int *)v3 + 3), v8);
printf("**\n** Disassembly for '__kernel %s'\n**\n\n", v8);
si_disasm_buffer(*(_QWORD *)(v7 + 16) + 40LL, stdout);
puts(s);
si_bin_file_free(v7);
}
}
++v1;
}
elf_file_free(v2);
si_disasm_done();
_mhandle_done();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(__int64 a1)
{
int v1; // ebp
__int64 v2; // r13
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // r14
int v6; // eax
__int64 v7; // r12
char v8[248]; // [rsp+0h] [rbp-F8h] BYREF

si_disasm_init();
v1 = 0;
v2 = elf_file_create_from_path(a1);
while ( (int)list_count(*(_QWORD *)(v2 + 56)) > v1 )
{
v3 = (const char **)list_get(*(_QWORD *)(v2 + 56), (unsigned int)v1);
v4 = list_get(*(_QWORD *)(v2 + 32), *((unsigned int *)v3 + 4));
if ( v4 && (unsigned int)str_prefix(*v3, "__OpenCL_") )
{
if ( (unsigned int)str_suffix(*v3, "_kernel") )
{
v5 = *v3;
v6 = strlen(*v3);
str_substr(v8, 200LL, v5, 9LL, (unsigned int)(v6 - 16));
v7 = si_bin_file_create(*(_QWORD *)(v4 + 16) + *((unsigned int *)v3 + 2), *((unsigned int *)v3 + 3), v8);
printf("**\n** Disassembly for '__kernel %s'\n**\n\n", v8);
si_disasm_buffer(*(_QWORD *)(v7 + 16) + 40LL, stdout);
puts(s);
si_bin_file_free(v7);
}
}
++v1;
}
elf_file_free(v2);
si_disasm_done();
_mhandle_done();
exit(0);
}

original_code:
void si_emu_disasm(char *path)
{
 struct elf_file_t *elf_file;
 struct elf_symbol_t *symbol;
 struct elf_section_t *section;
 struct si_bin_file_t *amd_bin;
 char kernel_name[200];
 int i;
 si_disasm_init();
 elf_file = elf_file_create_from_path(path);
 for (i = 0; i < list_count(elf_file->symbol_table); i++)
 {
  symbol = list_get(elf_file->symbol_table, i);
  section = list_get(elf_file->section_list, symbol->section);
  if (!section)
   continue;
  if (str_prefix(symbol->name, "__OpenCL_") && str_suffix(symbol->name, "_kernel"))
  {
   str_substr(kernel_name, sizeof(kernel_name), symbol->name, 9, strlen(symbol->name) - 16);
   amd_bin = si_bin_file_create(section->buffer.ptr + symbol->value, symbol->size, kernel_name);
   printf("**\n** Disassembly for '__kernel %s'\n**\n\n", kernel_name);
   si_disasm_buffer(&amd_bin->enc_dict_entry_southern_islands->sec_text_buffer, stdout);
   printf("\n\n\n");
   si_bin_file_free(amd_bin);
  }
 }
 elf_file_free(elf_file);
 si_disasm_done();
 __mhandle_done();
 exit(0);
}

variable_types:
path
char *

variable_types: struct elf_symbol_t { char *name; unsigned int value; unsigned int size; int section; unsigned char info; unsigned char visibility; } *

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

variable_types: struct si_bin_file_t { struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *elf_file; struct list_t *enc_dict; struct si_bin_enc_dict_entry_t { struct si_bin_enc_dict_entry_header_t { unsigned int d_machine; unsigned int d_type; unsigned int d_offset; unsigned int d_size; unsigned int d_flags; } *header; struct elf_buffer_t pt_load_buffer; struct elf_buffer_t pt_note_buffer; struct elf_buffer_t sec_text_buffer; struct elf_buffer_t sec_data_buffer; struct elf_buffer_t sec_symtab_buffer; struct elf_buffer_t sec_strtab_buffer; struct si_bin_enc_dict_entry_consts_t { float float_consts[256][4]; unsigned int int_consts[32][4]; unsigned int bool_consts[32]; } *consts; int num_gpr_used; int lds_size_used; int stack_size_used; unsigned int userElementCount; struct si_bin_enc_user_element_t { unsigned int dataClass; unsigned int apiSlot; unsigned int startUserReg; unsigned int userRegCount; } userElements[16]; struct si_bin_compute_pgm_rsrc2_t { unsigned int scrach_en; unsigned int user_sgpr; unsigned int trap_present; unsigned int tgid_x_en; unsigned int tgid_y_en; unsigned int tgid_z_en; unsigned int tg_size_en; unsigned int tidig_comp_cnt; unsigned int excp_en_msb; unsigned int lds_size; unsigned int excp_en; unsigned int; } *compute_pgm_rsrc2; } *enc_dict_entry_southern_islands; } *

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

user_defined_types: struct si_bin_file_t { struct elf_file_t *elf_file; struct list_t *enc_dict; struct si_bin_enc_dict_entry_t *enc_dict_entry_southern_islands; }

user_defined_types: struct si_bin_enc_dict_entry_t { struct si_bin_enc_dict_entry_header_t *header; struct elf_buffer_t pt_load_buffer; struct elf_buffer_t pt_note_buffer; struct elf_buffer_t sec_text_buffer; struct elf_buffer_t sec_data_buffer; struct elf_buffer_t sec_symtab_buffer; struct elf_buffer_t sec_strtab_buffer; struct si_bin_enc_dict_entry_consts_t *consts; int num_gpr_used; int lds_size_used; int stack_size_used; unsigned int userElementCount; struct si_bin_enc_user_element_t userElements[16]; struct si_bin_compute_pgm_rsrc2_t *compute_pgm_rsrc2; }


decompiled_code:
__int64 si_opencl_command_queue_create()
{
__int64 v0; // r12
int v1; // eax

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

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

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

original_code:
struct si_opencl_command_queue_t *si_opencl_command_queue_create()
{
 struct si_opencl_command_queue_t *command_queue;
 command_queue = (mhandle_calloc(1, sizeof(struct si_opencl_command_queue_t), "opencl-command-queue.c" ":" "36"));
 if (!command_queue)
  fatal("%s: out of memory", __FUNCTION__);
 command_queue->id = si_opencl_repo_new_object_id(si_emu->opencl_repo,
  si_opencl_object_command_queue);
 command_queue->ref_count = 1;
 command_queue->command_list = linked_list_create();
 si_opencl_repo_add_object(si_emu->opencl_repo, command_queue);
 return command_queue;
}

variable_types: struct si_opencl_command_queue_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; unsigned int properties; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *command_list; } *

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall list_grow(unsigned int *a1)
{
int v1; // ebp
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rdx
signed int v5; // esi
__int64 v6; // rcx
unsigned int v7; // kr00_4
__int64 result; // rax

v1 = 2 * a1[2];
v2 = mhandle_calloc(v1, 8LL, "list.c:43");
if ( !v2 )
fatal("%s: out of memory", "list_grow");
v3 = *a1;
v4 = a1[3];
if ( (int)v3 > 0 )
{
v5 = a1[2];
v6 = v2;
do
{
v6 += 8LL;
*(_QWORD *)(v6 - 8) = *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * (int)v4);
v7 = v4 + 1;
v4 = (unsigned int)(((int)v4 + 1) >> 31);
LODWORD(v4) = __SPAIR64__(v4, v7) % v5;
}
while ( v2 + 8 * v3 != v6 );
}
mhandle_free(*((_QWORD *)a1 + 3), "list.c:54", v4);
result = *a1;
*((_QWORD *)a1 + 3) = v2;
a1[2] = v1;
a1[3] = 0;
a1[4] = result;
return result;
}

original_code:
static void list_grow(struct list_t *list)
{
 void **nelem;
 int nsize, i, index;
 nsize = list->size * 2;
 nelem = (mhandle_calloc(nsize, sizeof(void *), "list.c" ":" "43"));
 if (!nelem)
  fatal("%s: out of memory", __FUNCTION__);
 for (i = list->head, index = 0;
  index < list->count;
  i = (i + 1) % list->size, index++)
  nelem[index] = list->elem[i];
 (mhandle_free(list->elem, "list.c" ":" "54"));
 list->elem = nelem;
 list->size = nsize;
 list->head = 0;
 list->tail = list->count;
}

canonical_original_code:
static void list_grow(struct list_t *list)
{
 void **nelem;
 int nsize; int i; int index;
 nsize = list->size * 2;
 nelem = (mhandle_calloc(nsize, sizeof(void *), "list.c" ":" "43"));
 if (!nelem)
  fatal("%s: out of memory", __FUNCTION__);
 for (i = list->head, index = 0;
  index < list->count;
  i = (i + 1) % list->size, index++)
  nelem[index] = list->elem[i];
 (mhandle_free(list->elem, "list.c" ":" "54"));
 list->elem = nelem;
 list->size = nsize;
 list->head = 0;
 list->tail = list->count;
}

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

variable_types:
nelem
void **

variable_types: nsize int

variable_types: index int


decompiled_code:
__int64 __fastcall list_create_with_size(int a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "list.c:101");
if ( !v2 )
fatal("%s: out of memory", "list_create_with_size");
if ( a1 < 4 )
v1 = 4;
*(_DWORD *)(v2 + 8) = v1;
v3 = mhandle_calloc(v1, 8LL, "list.c:107");
*(_QWORD *)(v2 + 24) = v3;
if ( !v3 )
fatal("%s: out of memory", "list_create_with_size");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "list.c:101");
if ( !v2 )
fatal("%s: out of memory", "list_create_with_size");
if ( a1 < 4 )
v1 = 4;
*(_DWORD *)(v2 + 8) = v1;
v3 = mhandle_calloc(v1, 8LL, "list.c:107");
*(_QWORD *)(v2 + 24) = v3;
if ( !v3 )
fatal("%s: out of memory", "list_create_with_size");
return v2;
}

original_code:
struct list_t *list_create_with_size(int size)
{
 struct list_t *list;
 list = (mhandle_calloc(1, sizeof(struct list_t), "list.c" ":" "101"));
 if (!list)
  fatal("%s: out of memory", __FUNCTION__);
 list->size = size < 4 ? 4 : size;
 list->elem = (mhandle_calloc(list->size, sizeof(void *), "list.c" ":" "107"));
 if (!list->elem)
  fatal("%s: out of memory", __FUNCTION__);
 return list;
}

variable_types: size int

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


decompiled_code:
__int64 list_create()
{
return list_create_with_size(8);
}

canonical_decompiled_code:
__int64 func3()
{
return func2(8);
}

original_code:
struct list_t *list_create(void)
{
 return list_create_with_size(8);
}

canonical_original_code:
struct list_t *list_create()
{
 return list_create_with_size(8);
}

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


decompiled_code:
__int64 __fastcall list_free(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx

mhandle_free(*(_QWORD *)(a1 + 24), "list.c:125", a3);
return mhandle_free(a1, "list.c:126", v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx

mhandle_free(*(_QWORD *)(a1 + 24), "list.c:125", a3);
return mhandle_free(a1, "list.c:126", v3);
}

original_code:
void list_free(struct list_t *list)
{
 (mhandle_free(list->elem, "list.c" ":" "125"));
 (mhandle_free(list, "list.c" ":" "126"));
}


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

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

original_code:
int list_count(struct list_t *list)
{
 return list->count;
}