decompiled_code:
__int64 arm_file_desc_table_create()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = mhandle_calloc(1LL, 16LL, "file.c:76");
if ( !v0 )
fatal("%s: out of memory", "arm_file_desc_table_create");
*(_QWORD *)(v0 + 8) = list_create();
v1 = arm_file_desc_create(2, 0, 0, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v1);
v2 = arm_file_desc_create(2, 1, 1, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v2);
v3 = arm_file_desc_create(2, 2, 2, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v3);
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = mhandle_calloc(1LL, 16LL, "file.c:76");
if ( !v0 )
fatal("%s: out of memory", "arm_file_desc_table_create");
*(_QWORD *)(v0 + 8) = list_create();
v1 = func1(2, 0, 0, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v1);
v2 = func1(2, 1, 1, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v2);
v3 = func1(2, 2, 2, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v3);
return v0;
}

original_code:
struct arm_file_desc_table_t *arm_file_desc_table_create(void)
{
 struct arm_file_desc_table_t *table;
 struct arm_file_desc_t *desc;
 table = (mhandle_calloc(1, sizeof(struct arm_file_desc_table_t), "file.c" ":" "76"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 table->arm_file_desc_list = list_create();
 desc = arm_file_desc_create(arm_file_desc_std, 0, 0, 0, ((void *)0));
 list_add(table->arm_file_desc_list, desc);
 desc = arm_file_desc_create(arm_file_desc_std, 1, 1, 0, ((void *)0));
 list_add(table->arm_file_desc_list, desc);
 desc = arm_file_desc_create(arm_file_desc_std, 2, 2, 0, ((void *)0));
 list_add(table->arm_file_desc_list, desc);
 return table;
}

canonical_original_code:
struct arm_file_desc_table_t *arm_file_desc_table_create()
{
 struct arm_file_desc_table_t *table;
 struct arm_file_desc_t *desc;
 table = (mhandle_calloc(1, sizeof(struct arm_file_desc_table_t), "file.c" ":" "76"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 table->arm_file_desc_list = list_create();
 desc = arm_file_desc_create(arm_file_desc_std, 0, 0, 0, ((void *)0));
 list_add(table->arm_file_desc_list, desc);
 desc = arm_file_desc_create(arm_file_desc_std, 1, 1, 0, ((void *)0));
 list_add(table->arm_file_desc_list, desc);
 desc = arm_file_desc_create(arm_file_desc_std, 2, 2, 0, ((void *)0));
 list_add(table->arm_file_desc_list, desc);
 return table;
}

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

user_defined_types: struct arm_file_desc_table_t { int num_links; struct list_t *arm_file_desc_list; }

user_defined_types: enum arm_file_desc_kind_t { arm_file_desc_invalid=0, arm_file_desc_regular=1, arm_file_desc_std=2, arm_file_desc_pipe=3, arm_file_desc_virtual=4, arm_file_desc_gpu=5, arm_file_desc_socket=6 }


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

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
_assert_fail("!table->num_links", "file.c", 0x6Au, "arm_file_desc_table_free");
while ( (int)list_count(*(_QWORD *)(a1 + 8)) > v1 )
{
v2 = list_get(*(_QWORD *)(a1 + 8), (unsigned int)v1);
if ( v2 )
arm_file_desc_free(v2);
++v1;
}
list_free(*(_QWORD *)(a1 + 8));
return mhandle_free(a1, "file.c:118");
}

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

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
_assert_fail("!table->num_links", "file.c", 0x6Au, "arm_file_desc_table_free");
while ( (int)list_count(*(_QWORD *)(a1 + 8)) > v1 )
{
v2 = list_get(*(_QWORD *)(a1 + 8), (unsigned int)v1);
if ( v2 )
func0(v2);
++v1;
}
list_free(*(_QWORD *)(a1 + 8));
return mhandle_free(a1, "file.c:118");
}

original_code:
void arm_file_desc_table_free(struct arm_file_desc_table_t *table)
{
 int i;
 struct arm_file_desc_t *desc;
 ((void) sizeof ((!table->num_links) ? 1 : 0), __extension__ ({ if (!table->num_links) ; else __assert_fail ("!table->num_links", "file.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < list_count(table->arm_file_desc_list); i++)
 {
  desc = list_get(table->arm_file_desc_list, i);
  if (desc)
   arm_file_desc_free(desc);
 }
 list_free(table->arm_file_desc_list);
 (mhandle_free(table, "file.c" ":" "118"));
}

variable_types: i int

variable_types: struct arm_file_desc_t { enum arm_file_desc_kind_t { arm_file_desc_invalid=0, arm_file_desc_regular=1, arm_file_desc_std=2, arm_file_desc_pipe=3, arm_file_desc_virtual=4, arm_file_desc_gpu=5, arm_file_desc_socket=6 } kind; int guest_fd; int host_fd; int flags; char *path; } *

return_type: void

user_defined_types: struct arm_file_desc_t { enum arm_file_desc_kind_t kind; int guest_fd; int host_fd; int flags; char *path; }

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


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

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("fdt->num_links >= 0", "file.c", 0x83u, "arm_file_desc_table_unlink");
if ( !v1 )
return arm_file_desc_table_free((__int64)a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

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

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("fdt->num_links >= 0", "file.c", 0x83u, "arm_file_desc_table_unlink");
if ( !v1 )
return func3((__int64)a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

original_code:
void arm_file_desc_table_unlink(struct arm_file_desc_table_t *fdt)
{
 ((void) sizeof ((fdt->num_links >= 0) ? 1 : 0), __extension__ ({ if (fdt->num_links >= 0) ; else __assert_fail ("fdt->num_links >= 0", "file.c", 131, __extension__ __PRETTY_FUNCTION__); }));
 if (fdt->num_links)
  fdt->num_links--;
 else
  arm_file_desc_table_free(fdt);
}


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

v2 = list_get(*(_QWORD *)(a1 + 8), a2);
if ( v2 )
result = *(unsigned int *)(v2 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

v2 = list_get(*(_QWORD *)(a1 + 8), a2);
if ( v2 )
result = *(unsigned int *)(v2 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int arm_file_desc_table_get_host_fd(struct arm_file_desc_table_t *table, int guest_fd)
{
 struct arm_file_desc_t *desc;
 desc = list_get(table->arm_file_desc_list, guest_fd);
 return desc ? desc->host_fd : -1;
}

return_type: int


decompiled_code:
__int64 __fastcall arm_file_desc_table_get_guest_fd(__int64 a1, int a2)
{
unsigned int i; // ebx

for ( i = 0; (int)list_count(*(_QWORD *)(a1 + 8)) > (int)i; ++i )
{
if ( *(_DWORD *)(list_get(*(_QWORD *)(a1 + 8), i) + 8) == a2 )
return i;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
unsigned int i; // ebx

for ( i = 0; (int)list_count(*(_QWORD *)(a1 + 8)) > (int)i; ++i )
{
if ( *(_DWORD *)(list_get(*(_QWORD *)(a1 + 8), i) + 8) == a2 )
return i;
}
return (unsigned int)-1;
}

original_code:
int arm_file_desc_table_get_guest_fd(struct arm_file_desc_table_t *table, int host_fd)
{
 struct arm_file_desc_t *desc;
 int i;
 for (i = 0; i < list_count(table->arm_file_desc_list); i++)
 {
  desc = list_get(table->arm_file_desc_list, i);
  if (desc->host_fd == host_fd)
   return i;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall arm_file_desc_table_entry_get(__int64 a1, __int64 a2)
{
return list_get(*(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return list_get(*(_QWORD *)(a1 + 8), a2);
}

original_code:
struct arm_file_desc_t *arm_file_desc_table_entry_get(struct arm_file_desc_table_t *table, int index)
{
 return list_get(table->arm_file_desc_list, index);
}

variable_types: index int

return_type: struct arm_file_desc_t { enum arm_file_desc_kind_t { arm_file_desc_invalid=0, arm_file_desc_regular=1, arm_file_desc_std=2, arm_file_desc_pipe=3, arm_file_desc_virtual=4, arm_file_desc_gpu=5, arm_file_desc_socket=6 } kind; int guest_fd; int host_fd; int flags; char *path; } *


decompiled_code:
__int64 __fastcall arm_file_desc_table_entry_new_guest_fd(__int64 a1, int a2, int a3, int a4, __int64 a5, int a6)
{
int i; // ebx
int v11; // eax
int j; // ebx
__int64 v13; // rbx

for ( i = 0; ; ++i )
{
v11 = list_count(*(_QWORD *)(a1 + 8));
if ( a3 >= 0 || v11 <= i )
break;
if ( !list_get(*(_QWORD *)(a1 + 8), (unsigned int)i) )
a3 = i;
}
if ( a3 < 0 )
{
a3 = list_count(*(_QWORD *)(a1 + 8));
list_add(*(_QWORD *)(a1 + 8), 0LL);
}
for ( j = list_count(*(_QWORD *)(a1 + 8)); a3 >= j; ++j )
list_add(*(_QWORD *)(a1 + 8), 0LL);
v13 = arm_file_desc_create(a2, a3, a4, a6, a5);
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a3, v13);
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, int a3, int a4, __int64 a5, int a6)
{
int i; // ebx
int v11; // eax
int j; // ebx
__int64 v13; // rbx

for ( i = 0; ; ++i )
{
v11 = list_count(*(_QWORD *)(a1 + 8));
if ( a3 >= 0 || v11 <= i )
break;
if ( !list_get(*(_QWORD *)(a1 + 8), (unsigned int)i) )
a3 = i;
}
if ( a3 < 0 )
{
a3 = list_count(*(_QWORD *)(a1 + 8));
list_add(*(_QWORD *)(a1 + 8), 0LL);
}
for ( j = list_count(*(_QWORD *)(a1 + 8)); a3 >= j; ++j )
list_add(*(_QWORD *)(a1 + 8), 0LL);
v13 = func1(a2, a3, a4, a6, a5);
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a3, v13);
return v13;
}

original_code:
struct arm_file_desc_t *arm_file_desc_table_entry_new_guest_fd(struct arm_file_desc_table_t *table,
 enum arm_file_desc_kind_t kind, int guest_fd, int host_fd, char *path, int flags)
{
 struct arm_file_desc_t *desc;
 int i;
 for (i = 0; i < list_count(table->arm_file_desc_list) && guest_fd < 0; i++)
  if (!list_get(table->arm_file_desc_list, i))
   guest_fd = i;
 if (guest_fd < 0)
 {
  guest_fd = list_count(table->arm_file_desc_list);
  list_add(table->arm_file_desc_list, ((void *)0));
 }
 for (i = list_count(table->arm_file_desc_list); i <= guest_fd; ++i) {
  list_add(table->arm_file_desc_list, ((void *)0));
 }
 desc = arm_file_desc_create(kind, guest_fd, host_fd, flags, path);
 list_set(table->arm_file_desc_list, guest_fd, desc);
 return desc;
}

variable_types: enum arm_file_desc_kind_t { arm_file_desc_invalid=0, arm_file_desc_regular=1, arm_file_desc_std=2, arm_file_desc_pipe=3, arm_file_desc_virtual=4, arm_file_desc_gpu=5, arm_file_desc_socket=6 }

variable_types:
path
char *

variable_types: flags int


decompiled_code:
__int64 __fastcall arm_file_desc_table_entry_new(__int64 a1, int a2, int a3, __int64 a4, int a5)
{
return arm_file_desc_table_entry_new_guest_fd(a1, a2, -1, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, int a3, __int64 a4, int a5)
{
return func10(a1, a2, -1, a3, a4, a5);
}

original_code:
struct arm_file_desc_t *arm_file_desc_table_entry_new(struct arm_file_desc_table_t *table,
 enum arm_file_desc_kind_t kind, int host_fd, char *path, int flags)
{
 return arm_file_desc_table_entry_new_guest_fd(table, kind, -1, host_fd, path, flags);
}


decompiled_code:
__int64 __fastcall arm_file_desc_table_entry_free(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx

result = list_get(*(_QWORD *)(a1 + 8), a2);
if ( result )
{
v3 = result;
if ( *(_DWORD *)result == 4 )
{
if ( unlink(*(const char **)(result + 16)) )
warning("%s: temporary host virtual arm_file could not be deleted", *(const char **)(v3 + 16));
}
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a2, 0LL);
result = arm_file_desc_free(v3);
}
return result;
}

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

result = list_get(*(_QWORD *)(a1 + 8), a2);
if ( result )
{
v3 = result;
if ( *(_DWORD *)result == 4 )
{
if ( unlink(*(const char **)(result + 16)) )
warning("%s: temporary host virtual arm_file could not be deleted", *(const char **)(v3 + 16));
}
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a2, 0LL);
result = func0(v3);
}
return result;
}

original_code:
void arm_file_desc_table_entry_free(struct arm_file_desc_table_t *table, int index)
{
 struct arm_file_desc_t *desc;
 desc = list_get(table->arm_file_desc_list, index);
 if (!desc)
  return;
 if (desc->kind == arm_file_desc_virtual)
 {
  if (unlink(desc->path))
   warning("%s: temporary host virtual arm_file could not be deleted",
    desc->path);
 }
 list_set(table->arm_file_desc_list, index, ((void *)0));
 arm_file_desc_free(desc);
}


decompiled_code:
double __fastcall exp_random(double a1)
{
int v1; // eax

v1 = random();
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(1.0 - (double)v1 / 2147483647.0)) ^ LC2) / a1;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
int v1; // eax

v1 = random();
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(1.0 - (double)v1 / 2147483647.0)) ^ LC2) / a1;
}

original_code:
static double exp_random(double lambda)
{
 double x = (double) random() / 2147483647;
 return log(1 - x) / -lambda;
}

variable_types: lambda double

variable_types: x double

return_type: double


decompiled_code:
void net_init()
{
EV_NET_SEND = esim_register_event_with_name(&net_event_handler, "net_send");
EV_NET_OUTPUT_BUFFER = esim_register_event_with_name(&net_event_handler, "net_output_buffer");
EV_NET_INPUT_BUFFER = esim_register_event_with_name(&net_event_handler, "net_input_buffer");
EV_NET_RECEIVE = esim_register_event_with_name(&net_event_handler, "net_receive");
net_config_load();
if ( *(_BYTE *)net_report_file_name )
{
net_report_file = file_open_for_write();
if ( !net_report_file )
fatal("%s: cannot write on network report file", (const char *)net_report_file_name);
}
}

canonical_decompiled_code:
void func2()
{
EV_NET_SEND = esim_register_event_with_name(&net_event_handler, "net_send");
EV_NET_OUTPUT_BUFFER = esim_register_event_with_name(&net_event_handler, "net_output_buffer");
EV_NET_INPUT_BUFFER = esim_register_event_with_name(&net_event_handler, "net_input_buffer");
EV_NET_RECEIVE = esim_register_event_with_name(&net_event_handler, "net_receive");
func1();
if ( *(_BYTE *)net_report_file_name )
{
net_report_file = file_open_for_write();
if ( !net_report_file )
fatal("%s: cannot write on network report file", (const char *)net_report_file_name);
}
}

original_code:
void net_init(void)
{
 EV_NET_SEND = esim_register_event_with_name(net_event_handler, "net_send");
 EV_NET_OUTPUT_BUFFER = esim_register_event_with_name(net_event_handler, "net_output_buffer");
 EV_NET_INPUT_BUFFER = esim_register_event_with_name(net_event_handler, "net_input_buffer");
 EV_NET_RECEIVE = esim_register_event_with_name(net_event_handler, "net_receive");
 net_config_load();
 if (*net_report_file_name)
 {
  net_report_file = file_open_for_write(net_report_file_name);
  if (!net_report_file)
   fatal("%s: cannot write on network report file",
    net_report_file_name);
 }
}

canonical_original_code:
void net_init()
{
 EV_NET_SEND = esim_register_event_with_name(net_event_handler, "net_send");
 EV_NET_OUTPUT_BUFFER = esim_register_event_with_name(net_event_handler, "net_output_buffer");
 EV_NET_INPUT_BUFFER = esim_register_event_with_name(net_event_handler, "net_input_buffer");
 EV_NET_RECEIVE = esim_register_event_with_name(net_event_handler, "net_receive");
 net_config_load();
 if (*net_report_file_name)
 {
  net_report_file = file_open_for_write(net_report_file_name);
  if (!net_report_file)
   fatal("%s: cannot write on network report file",
    net_report_file_name);
 }
}


decompiled_code:
__int64 net_done()
{
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( net_table )
{
hash_table_find_first(net_table, v1);
while ( v1[0] )
{
if ( net_report_file )
net_dump_report();
net_free(v1[0]);
hash_table_find_next(net_table, v1);
}
hash_table_free(net_table);
}
return file_close(net_report_file);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( net_table )
{
hash_table_find_first(net_table, v1);
while ( v1[0] )
{
if ( net_report_file )
net_dump_report();
net_free(v1[0]);
hash_table_find_next(net_table, v1);
}
hash_table_free(net_table);
}
return file_close(net_report_file);
}

original_code:
void net_done(void)
{
 struct net_t *net;
 if (net_table)
 {
  for (hash_table_find_first(net_table, (void **) &net); net;
   hash_table_find_next(net_table, (void **) &net))
  {
   if (net_report_file)
    net_dump_report(net, net_report_file);
   net_free(net);
  }
  hash_table_free(net_table);
 }
 file_close(net_report_file);
}

canonical_original_code:
void net_done()
{
 struct net_t *net;
 if (net_table)
 {
  for (hash_table_find_first(net_table, (void **) &net); net;
   hash_table_find_next(net_table, (void **) &net))
  {
   if (net_report_file)
    net_dump_report(net, net_report_file);
   net_free(net);
  }
  hash_table_free(net_table);
 }
 file_close(net_report_file);
}

variable_types: struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *

user_defined_types: struct net_t { char *name; long long msg_id_counter; struct list_t *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t *routing_table; struct net_msg_t *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; }

user_defined_types: struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t *entries; int has_cycle; }

user_defined_types: struct net_routing_table_entry_t { int cost; struct net_node_t *next_node; struct net_buffer_t *output_buffer; }

user_defined_types: struct net_node_t { struct net_t *net; enum net_node_kind_t kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; }

user_defined_types: struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; }

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


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

result = net_table;
if ( net_table )
result = hash_table_get(net_table, a1);
return result;
}

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

result = net_table;
if ( net_table )
result = hash_table_get(net_table, a1);
return result;
}

original_code:
struct net_t *net_find(char *name)
{
 if (!net_table)
  return ((void *)0);
 return hash_table_get(net_table, name);
}

variable_types:
name
char *

return_type: struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *


decompiled_code:
__int64 net_find_first()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-10h] BYREF

result = net_table;
if ( net_table )
{
hash_table_find_first(net_table, &v1);
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-10h] BYREF

result = net_table;
if ( net_table )
{
hash_table_find_first(net_table, &v1);
result = v1;
}
return result;
}

original_code:
struct net_t *net_find_first(void)
{
 struct net_t *net;
 if (!net_table)
  return ((void *)0);
 hash_table_find_first(net_table, (void **) &net);
 return net;
}

canonical_original_code:
struct net_t *net_find_first()
{
 struct net_t *net;
 if (!net_table)
  return ((void *)0);
 hash_table_find_first(net_table, (void **) &net);
 return net;
}

user_defined_types: struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; }

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

user_defined_types: struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; }

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 net_find_next()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-10h] BYREF

result = net_table;
if ( net_table )
{
hash_table_find_next(net_table, &v1);
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-10h] BYREF

result = net_table;
if ( net_table )
{
hash_table_find_next(net_table, &v1);
result = v1;
}
return result;
}

original_code:
struct net_t *net_find_next(void)
{
 struct net_t *net;
 if (!net_table)
  return ((void *)0);
 hash_table_find_next(net_table, (void **) &net);
 return net;
}

canonical_original_code:
struct net_t *net_find_next()
{
 struct net_t *net;
 if (!net_table)
  return ((void *)0);
 hash_table_find_next(net_table, (void **) &net);
 return net;
}


decompiled_code:
void __fastcall __noreturn net_sim(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rdx
__int64 v3; // rcx
unsigned int i; // er14
double *v5; // r15
__int64 v6; // r13
__int64 v7; // rbx
int v8; // eax
__int64 v9; // rax
__int64 v10; // rbx
__int64 v11; // [rsp+8h] [rbp-40h]

debug_init();
esim_init();
net_init();
net_debug_category = debug_new_category(a1);
if ( !*(_BYTE *)net_sim_network_name )
panic("%s: no network", "net_sim");
v1 = net_find((__int64)net_sim_network_name);
if ( !v1 )
fatal("%s: network does not exist", (const char *)net_sim_network_name);
v11 = mhandle_calloc(*(int *)(v1 + 24), 8LL, "netlib.c:361");
if ( !v11 )
fatal("%s: out of memory", "net_sim");
esim_process_events();
while ( esim_cycle < net_max_cycles )
{
v5 = (double *)v11;
for ( i = 0; *(_DWORD *)(v1 + 24) > (signed int)i; ++v5 )
{
v6 = list_get(*(_QWORD *)(v1 + 16), i, v2, v3);
if ( *(_DWORD *)(v6 + 8) == 1 && *v5 <= (double)esim_cycle )
{
do
{
do
{
v7 = random();
v8 = list_count(*(_QWORD *)(v1 + 16));
v9 = list_get(*(_QWORD *)(v1 + 16), (unsigned int)(v7 % v8), v7 % v8, v8);
v10 = v9;
}
while ( *(_DWORD *)(v9 + 8) != 1 );
}
while ( v6 == v9 );
while ( (double)esim_cycle > *v5 )
{
*v5 = exp_random(*(double *)&net_injection_rate) + *v5;
if ( (unsigned int)net_can_send(v1, v6, v10, (unsigned int)net_msg_size) )
net_send(v1, v6, v10, (unsigned int)net_msg_size);
}
}
++i;
}
if ( net_debug_category )
_debug((unsigned int)net_debug_category, "___ cycle %lld ___\n", esim_cycle);
esim_process_events();
}
while ( (unsigned int)esim_event_count() )
esim_process_events();
mhandle_free(v11, "netlib.c:412");
net_done();
esim_done();
debug_done();
_mhandle_done();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rdx
__int64 v3; // rcx
unsigned int i; // er14
double *v5; // r15
__int64 v6; // r13
__int64 v7; // rbx
int v8; // eax
__int64 v9; // rax
__int64 v10; // rbx
__int64 v11; // [rsp+8h] [rbp-40h]

debug_init();
esim_init();
func2();
net_debug_category = debug_new_category(a1);
if ( !*(_BYTE *)net_sim_network_name )
panic("%s: no network", "net_sim");
v1 = func4((__int64)net_sim_network_name);
if ( !v1 )
fatal("%s: network does not exist", (const char *)net_sim_network_name);
v11 = mhandle_calloc(*(int *)(v1 + 24), 8LL, "netlib.c:361");
if ( !v11 )
fatal("%s: out of memory", "net_sim");
esim_process_events();
while ( esim_cycle < net_max_cycles )
{
v5 = (double *)v11;
for ( i = 0; *(_DWORD *)(v1 + 24) > (signed int)i; ++v5 )
{
v6 = list_get(*(_QWORD *)(v1 + 16), i, v2, v3);
if ( *(_DWORD *)(v6 + 8) == 1 && *v5 <= (double)esim_cycle )
{
do
{
do
{
v7 = random();
v8 = list_count(*(_QWORD *)(v1 + 16));
v9 = list_get(*(_QWORD *)(v1 + 16), (unsigned int)(v7 % v8), v7 % v8, v8);
v10 = v9;
}
while ( *(_DWORD *)(v9 + 8) != 1 );
}
while ( v6 == v9 );
while ( (double)esim_cycle > *v5 )
{
*v5 = func0(*(double *)&net_injection_rate) + *v5;
if ( (unsigned int)net_can_send(v1, v6, v10, (unsigned int)net_msg_size) )
net_send(v1, v6, v10, (unsigned int)net_msg_size);
}
}
++i;
}
if ( net_debug_category )
_debug((unsigned int)net_debug_category, "___ cycle %lld ___\n", esim_cycle);
esim_process_events();
}
while ( (unsigned int)esim_event_count() )
esim_process_events();
mhandle_free(v11, "netlib.c:412");
func3();
esim_done();
debug_done();
_mhandle_done();
exit(0);
}

original_code:
void net_sim(char *debug_file_name)
{
 struct net_t *net;
 double *inject_time;
 debug_init();
 esim_init();
 net_init();
 net_debug_category = debug_new_category(debug_file_name);
 if (!*net_sim_network_name)
  panic("%s: no network", __FUNCTION__);
 net = net_find(net_sim_network_name);
 if (!net)
  fatal("%s: network does not exist", net_sim_network_name);
 inject_time = (mhandle_calloc(net->node_count, sizeof(double), "netlib.c" ":" "361"));
 if (!inject_time)
  fatal("%s: out of memory", __FUNCTION__);
 esim_process_events();
 while (esim_cycle < net_max_cycles)
 {
  struct net_node_t *node;
  struct net_node_t *dst_node;
  int i;
  for (i = 0; i < net->node_count; i++)
  {
   node = list_get(net->node_list, i);
   if (node->kind != net_node_end)
    continue;
   if (inject_time[i] > esim_cycle)
    continue;
   do {
    dst_node = list_get(net->node_list, random() %
     list_count(net->node_list));
   } while (dst_node->kind != net_node_end || dst_node == node);
   while (inject_time[i] < esim_cycle)
   {
    inject_time[i] += exp_random(net_injection_rate);
    if (net_can_send(net, node, dst_node, net_msg_size))
     net_send(net, node, dst_node, net_msg_size);
   }
  }
  ((net_debug_category) ? __debug((net_debug_category), "___ cycle %lld ___\n", esim_cycle) : (void) 0);
  esim_process_events();
 }
 while (esim_event_count())
  esim_process_events();
 (mhandle_free(inject_time, "netlib.c" ":" "412"));
 net_done();
 esim_done();
 debug_done();
 __mhandle_done();
 exit(0);
}

variable_types: struct net_node_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *


decompiled_code:
__int64 __fastcall esim_event_info_create(int a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // rax

v4 = mhandle_calloc(1LL, 24LL, "esim.c:150");
if ( !v4 )
fatal("%s: out of memory", "esim_event_info_create");
*(_DWORD *)v4 = a1;
*(_QWORD *)(v4 + 16) = a3;
v5 = mhandle_strdup(a2, "esim.c:157");
*(_QWORD *)(v4 + 8) = v5;
if ( !v5 )
fatal("%s: out of memory", "esim_event_info_create");
return v4;
}

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

v4 = mhandle_calloc(1LL, 24LL, "esim.c:150");
if ( !v4 )
fatal("%s: out of memory", "esim_event_info_create");
*(_DWORD *)v4 = a1;
*(_QWORD *)(v4 + 16) = a3;
v5 = mhandle_strdup(a2, "esim.c:157");
*(_QWORD *)(v4 + 8) = v5;
if ( !v5 )
fatal("%s: out of memory", "esim_event_info_create");
return v4;
}

original_code:
struct esim_event_info_t *esim_event_info_create(int id,
 char *name, esim_event_handler_t handler)
{
 struct esim_event_info_t *event_info;
 event_info = (mhandle_calloc(1, sizeof(struct esim_event_info_t), "esim.c" ":" "150"));
 if (!event_info)
  fatal("%s: out of memory", __FUNCTION__);
 event_info->id = id;
 event_info->handler = handler;
 event_info->name = (mhandle_strdup(name, "esim.c" ":" "157"));
 if (!event_info->name)
  fatal("%s: out of memory", __FUNCTION__);
 return event_info;
}

canonical_original_code:
struct esim_event_info_t *esim_event_info_create(int id, char *name, void (*handler)(int event, void *data))
{
 struct esim_event_info_t *event_info;
 event_info = (mhandle_calloc(1, sizeof(struct esim_event_info_t), "esim.c" ":" "150"));
 if (!event_info)
  fatal("%s: out of memory", __FUNCTION__);
 event_info->id = id;
 event_info->handler = handler;
 event_info->name = (mhandle_strdup(name, "esim.c" ":" "157"));
 if (!event_info->name)
  fatal("%s: out of memory", __FUNCTION__);
 return event_info;
}

variable_types: id int

variable_types:
handler
void (*)(int event, void *data)

variable_types: struct esim_event_info_t { int id; char *name; void (*handler)(int event, void *data); } *


decompiled_code:
__int64 __fastcall esim_event_info_free(__int64 a1)
{
mhandle_free(*(_QWORD *)(a1 + 8), "esim.c:168");
return mhandle_free(a1, "esim.c:169");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
mhandle_free(*(_QWORD *)(a1 + 8), "esim.c:168");
return mhandle_free(a1, "esim.c:169");
}

original_code:
void esim_event_info_free(struct esim_event_info_t *event_info)
{
 (mhandle_free(event_info->name, "esim.c" ":" "168"));
 (mhandle_free(event_info, "esim.c" ":" "169"));
}

user_defined_types: struct esim_event_info_t { int id; char *name; void (*handler)(int event, void *data); }


decompiled_code:
__int64 __fastcall esim_event_create(int a1, __int64 a2)
{
__int64 v2; // rbx

v2 = mhandle_calloc(1LL, 16LL, "esim.c:191");
if ( !v2 )
fatal("%s: out of memory", "esim_event_create");
*(_DWORD *)v2 = a1;
*(_QWORD *)(v2 + 8) = a2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 v2; // rbx

v2 = mhandle_calloc(1LL, 16LL, "esim.c:191");
if ( !v2 )
fatal("%s: out of memory", "esim_event_create");
*(_DWORD *)v2 = a1;
*(_QWORD *)(v2 + 8) = a2;
return v2;
}

original_code:
struct esim_event_t *esim_event_create(int id, void *data)
{
 struct esim_event_t *event;
 event = (mhandle_calloc(1, sizeof(struct esim_event_t), "esim.c" ":" "191"));
 if (!event)
  fatal("%s: out of memory", __FUNCTION__);
 event->id = id;
 event->data = data;
 return event;
}

variable_types:
data
void *

variable_types: struct esim_event_t { int id; void *data; } *


decompiled_code:
__int64 __fastcall esim_event_free(__int64 a1)
{
return mhandle_free(a1, "esim.c:206");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return mhandle_free(a1, "esim.c:206");
}

original_code:
void esim_event_free(struct esim_event_t *event)
{
 (mhandle_free(event, "esim.c" ":" "206"));
}

user_defined_types: struct esim_event_t { int id; void *data; }


decompiled_code:
__int64 esim_done()
{
int i; // ebx
__int64 v1; // rax

for ( i = 0; (int)list_count(esim_event_info_list) > i; ++i )
{
v1 = list_get(esim_event_info_list, (unsigned int)i);
esim_event_info_free(v1);
}
list_free(esim_event_info_list);
heap_free(esim_event_heap);
linked_list_free(esim_end_event_list);
return m2s_timer_free(esim_timer);
}

canonical_decompiled_code:
__int64 func4()
{
int i; // ebx
__int64 v1; // rax

for ( i = 0; (int)list_count(esim_event_info_list) > i; ++i )
{
v1 = list_get(esim_event_info_list, (unsigned int)i);
func1(v1);
}
list_free(esim_event_info_list);
heap_free(esim_event_heap);
linked_list_free(esim_end_event_list);
return m2s_timer_free(esim_timer);
}

original_code:
void esim_done()
{
 int id;
 for ((id) = 0; (id) < list_count((esim_event_info_list)); (id)++)
  esim_event_info_free(list_get(esim_event_info_list, id));
 list_free(esim_event_info_list);
 heap_free(esim_event_heap);
 linked_list_free(esim_end_event_list);
 m2s_timer_free(esim_timer);
}


decompiled_code:
__int64 esim_drain_heap()
{
int v0; // ebp
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rax
void (__fastcall *v4)(_QWORD, _QWORD); // rax
unsigned int *v5; // [rsp+8h] [rbp-20h] BYREF

v0 = 0;
while ( 1 )
{
v1 = heap_extract(esim_event_heap, &v5);
result = heap_error(esim_event_heap);
if ( (_DWORD)result )
break;
++v0;
esim_cycle = v1;
v3 = list_get(esim_event_info_list, *v5);
if ( !v3 || (v4 = *(void (__fastcall **)(_QWORD, _QWORD))(v3 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0xEDu, "esim_drain_heap");
v4(*v5, *((_QWORD *)v5 + 1));
esim_event_free((__int64)v5);
if ( v0 == 10000000 )
{
esim_dump(stderr, 0x14u);
fatal(
"%s: number of finalization events exceeds %d.\n%s",
"esim_drain_heap",
10000000LL,
"\tThe finalization process of the event-driven simulation is trying to\n"
"\tempty the event heap by scheduling all pending events. If the number of\n"
"\tscheduled events during this process is too high, it could mean that\n"
"\tsome event is recursively scheduling other events, avoiding correct\n"
"\tfinalization of the simulation. Please contact development@multi2sim.org\n"
"\tto report this error.\n");
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // ebp
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rax
void (__fastcall *v4)(_QWORD, _QWORD); // rax
unsigned int *v5; // [rsp+8h] [rbp-20h] BYREF

v0 = 0;
while ( 1 )
{
v1 = heap_extract(esim_event_heap, &v5);
result = heap_error(esim_event_heap);
if ( (_DWORD)result )
break;
++v0;
esim_cycle = v1;
v3 = list_get(esim_event_info_list, *v5);
if ( !v3 || (v4 = *(void (__fastcall **)(_QWORD, _QWORD))(v3 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0xEDu, "esim_drain_heap");
v4(*v5, *((_QWORD *)v5 + 1));
func3((__int64)v5);
if ( v0 == 10000000 )
{
func5(stderr, 0x14u);
fatal(
"%s: number of finalization events exceeds %d.\n%s",
"esim_drain_heap",
10000000LL,
"\tThe finalization process of the event-driven simulation is trying to\n"
"\tempty the event heap by scheduling all pending events. If the number of\n"
"\tscheduled events during this process is too high, it could mean that\n"
"\tsome event is recursively scheduling other events, avoiding correct\n"
"\tfinalization of the simulation. Please contact development@multi2sim.org\n"
"\tto report this error.\n");
}
}
return result;
}

original_code:
static void esim_drain_heap(void)
{
 int count = 0;
 struct esim_event_t *event;
 struct esim_event_info_t *event_info;
 long long cycle;
 while (1)
 {
  cycle = heap_extract(esim_event_heap, (void **) &event);
  if (heap_error(esim_event_heap))
   break;
  count++;
  esim_cycle = cycle;
  event_info = list_get(esim_event_info_list, event->id);
  ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 237, __extension__ __PRETTY_FUNCTION__); }));
  event_info->handler(event->id, event->data);
  esim_event_free(event);
  if (count == 10000000)
  {
   esim_dump(stderr, 20);
   fatal("%s: number of finalization events exceeds %d.\n%s",
    __FUNCTION__, 10000000,
    esim_err_finalization);
  }
 }
}

canonical_original_code:
static void esim_drain_heap()
{
 int count = 0;
 struct esim_event_t *event;
 struct esim_event_info_t *event_info;
 long long cycle;
 while (1)
 {
  cycle = heap_extract(esim_event_heap, (void **) &event);
  if (heap_error(esim_event_heap))
   break;
  count++;
  esim_cycle = cycle;
  event_info = list_get(esim_event_info_list, event->id);
  ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 237, __extension__ __PRETTY_FUNCTION__); }));
  event_info->handler(event->id, event->data);
  esim_event_free(event);
  if (count == 10000000)
  {
   esim_dump(stderr, 20);
   fatal("%s: number of finalization events exceeds %d.\n%s",
    __FUNCTION__, 10000000,
    esim_err_finalization);
  }
 }
}

variable_types: count int

variable_types:
cycle
long long


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

v2 = list_count(esim_event_info_list);
v3 = esim_event_info_create(v2, a2, a1);
list_add(esim_event_info_list, v3);
return v2;
}

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

v2 = list_count(esim_event_info_list);
v3 = func0(v2, a2, a1);
list_add(esim_event_info_list, v3);
return v2;
}

original_code:
int esim_register_event_with_name(esim_event_handler_t handler, char *name)
{
 struct esim_event_info_t *event_info;
 int id;
 id = list_count(esim_event_info_list);
 event_info = esim_event_info_create(id, name, handler);
 list_add(esim_event_info_list, event_info);
 return id;
}

canonical_original_code:
int esim_register_event_with_name(void (*handler)(int event, void *data), char *name)
{
 struct esim_event_info_t *event_info;
 int id;
 id = list_count(esim_event_info_list);
 event_info = esim_event_info_create(id, name, handler);
 list_add(esim_event_info_list, event_info);
 return id;
}


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

esim_event_info_list = list_create();
esim_event_heap = heap_create(20LL);
esim_end_event_list = linked_list_create();
esim_timer = m2s_timer_create(0LL);
m2s_timer_start(esim_timer);
esim_register_event_with_name(0LL, (__int64)"esim_invalid");
result = esim_register_event_with_name(0LL, (__int64)"esim_none");
ESIM_EV_NONE = result;
return result;
}

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

esim_event_info_list = list_create();
esim_event_heap = heap_create(20LL);
esim_end_event_list = linked_list_create();
esim_timer = m2s_timer_create(0LL);
m2s_timer_start(esim_timer);
func7(0LL, (__int64)"esim_invalid");
result = func7(0LL, (__int64)"esim_none");
ESIM_EV_NONE = result;
return result;
}

original_code:
void esim_init()
{
 esim_event_info_list = list_create();
 esim_event_heap = heap_create(20);
 esim_end_event_list = linked_list_create();
 esim_timer = m2s_timer_create(((void *)0));
 m2s_timer_start(esim_timer);
 ESIM_EV_INVALID = esim_register_event_with_name(((void *)0), "esim_invalid");
 ESIM_EV_NONE = esim_register_event_with_name(((void *)0), "esim_none");
}


decompiled_code:
__int64 __fastcall esim_register_event(__int64 a1)
{
unsigned int v1; // eax
char v3[120]; // [rsp+0h] [rbp-78h] BYREF

v1 = list_count(esim_event_info_list);
snprintf(v3, 0x64uLL, "event_%d", v1);
return esim_register_event_with_name(a1, (__int64)v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned int v1; // eax
char v3[120]; // [rsp+0h] [rbp-78h] BYREF

v1 = list_count(esim_event_info_list);
snprintf(v3, 0x64uLL, "event_%d", v1);
return func7(a1, (__int64)v3);
}

original_code:
int esim_register_event(esim_event_handler_t handler)
{
 char name[100];
 int id;
 id = list_count(esim_event_info_list);
 snprintf(name, sizeof name, "event_%d", id);
 return esim_register_event_with_name(handler, name);
}

canonical_original_code:
int esim_register_event(void (*handler)(int event, void *data))
{
 char name[100];
 int id;
 id = list_count(esim_event_info_list);
 snprintf(name, sizeof name, "event_%d", id);
 return esim_register_event_with_name(handler, name);
}

variable_types:
name
char [100]


decompiled_code:
void __fastcall esim_schedule_event(int a1, __int64 a2, int a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 v6; // rax

if ( !esim_lock_schedule )
{
v4 = esim_cycle;
if ( a1 < 0 || (int)list_count(esim_event_info_list) <= a1 )
panic("%s: unknown event", "esim_schedule_event");
v5 = v4 + a3;
if ( esim_cycle > v5 )
panic("%s: event scheduled in the past", "esim_schedule_event");
if ( !a1 )
panic("%s: invalid event (forgot call to 'esim_register_event'?)", "esim_schedule_event");
if ( ESIM_EV_NONE != a1 )
{
v6 = esim_event_create(a1, a2);
heap_insert(esim_event_heap, v5, v6);
if ( !esim_overload_shown && (int)heap_count(esim_event_heap) > 9999 )
{
esim_overload_shown = 1;
warning(
"%s: number of in-flight events exceeds %d.\n%s",
"esim_schedule_event",
10000LL,
"\tAn excessive number of events are currently in-flight in the event-\n"
"\tdriven simulation library. This is probably the result of a timing\n"
"\tmodel uncontrollably issuing events (typically a processor pipeline\n"
"\tissuing memory accesses without checking for a limit in the number\n"
"\tof in-flight accesses).\n"
"\tIf you still believe that this is an expected number of in-flight\n"
"\tevents, please increase the value of macro ESIM_OVERLOAD_EVENTS to\n"
"\tavoid this warning.\n");
}
}
}
}

canonical_decompiled_code:
void __fastcall func10(int a1, __int64 a2, int a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 v6; // rax

if ( !esim_lock_schedule )
{
v4 = esim_cycle;
if ( a1 < 0 || (int)list_count(esim_event_info_list) <= a1 )
panic("%s: unknown event", "esim_schedule_event");
v5 = v4 + a3;
if ( esim_cycle > v5 )
panic("%s: event scheduled in the past", "esim_schedule_event");
if ( !a1 )
panic("%s: invalid event (forgot call to 'esim_register_event'?)", "esim_schedule_event");
if ( ESIM_EV_NONE != a1 )
{
v6 = func2(a1, a2);
heap_insert(esim_event_heap, v5, v6);
if ( !esim_overload_shown && (int)heap_count(esim_event_heap) > 9999 )
{
esim_overload_shown = 1;
warning(
"%s: number of in-flight events exceeds %d.\n%s",
"esim_schedule_event",
10000LL,
"\tAn excessive number of events are currently in-flight in the event-\n"
"\tdriven simulation library. This is probably the result of a timing\n"
"\tmodel uncontrollably issuing events (typically a processor pipeline\n"
"\tissuing memory accesses without checking for a limit in the number\n"
"\tof in-flight accesses).\n"
"\tIf you still believe that this is an expected number of in-flight\n"
"\tevents, please increase the value of macro ESIM_OVERLOAD_EVENTS to\n"
"\tavoid this warning.\n");
}
}
}
}

original_code:
void esim_schedule_event(int id, void *data, int after)
{
 struct esim_event_t *event;
 long long when = esim_cycle + after;
 if (esim_lock_schedule)
  return;
 if (id < 0 || id >= list_count(esim_event_info_list))
  panic("%s: unknown event", __FUNCTION__);
 if (when < esim_cycle)
  panic("%s: event scheduled in the past", __FUNCTION__);
 if (!id)
  panic("%s: invalid event (forgot call to 'esim_register_event'?)", __FUNCTION__);
 if (id == ESIM_EV_NONE)
  return;
 event = esim_event_create(id, data);
 heap_insert(esim_event_heap, when, event);
 if (!esim_overload_shown && heap_count(esim_event_heap) >= 10000)
 {
  esim_overload_shown = 1;
  warning("%s: number of in-flight events exceeds %d.\n%s",
   __FUNCTION__, 10000, esim_err_overload);
 }
}

variable_types: after int

variable_types:
when
long long


decompiled_code:
void __fastcall esim_schedule_end_event(int a1, __int64 a2)
{
__int64 v2; // rax

if ( !esim_lock_schedule )
{
if ( a1 < 0 || (int)list_count(esim_event_info_list) <= a1 )
panic("%s: unknown event", "esim_schedule_end_event");
if ( !a1 )
panic("%s: invalid event (forgot call to 'esim_register_event'?)", "esim_schedule_end_event");
if ( ESIM_EV_NONE != a1 )
{
v2 = esim_event_create(a1, a2);
linked_list_add(esim_end_event_list, v2);
}
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, __int64 a2)
{
__int64 v2; // rax

if ( !esim_lock_schedule )
{
if ( a1 < 0 || (int)list_count(esim_event_info_list) <= a1 )
panic("%s: unknown event", "esim_schedule_end_event");
if ( !a1 )
panic("%s: invalid event (forgot call to 'esim_register_event'?)", "esim_schedule_end_event");
if ( ESIM_EV_NONE != a1 )
{
v2 = func2(a1, a2);
linked_list_add(esim_end_event_list, v2);
}
}
}

original_code:
void esim_schedule_end_event(int id, void *data)
{
 struct esim_event_t *event;
 if (esim_lock_schedule)
  return;
 if (id < 0 || id >= list_count(esim_event_info_list))
  panic("%s: unknown event", __FUNCTION__);
 if (!id)
  panic("%s: invalid event (forgot call to 'esim_register_event'?)", __FUNCTION__);
 if (id == ESIM_EV_NONE)
  return;
 event = esim_event_create(id, data);
 linked_list_add(esim_end_event_list, event);
}


decompiled_code:
void __fastcall esim_execute_event(int a1, __int64 a2)
{
__int64 v2; // rax
void (__fastcall *v3)(_QWORD, __int64); // rax

if ( !esim_lock_schedule )
{
if ( a1 < 0 || (int)list_count(esim_event_info_list) <= a1 )
panic("%s: unkown event", "esim_execute_event");
if ( !a1 )
panic("%s: invalid event (forgot to call to 'esim_register_event'?)", "esim_execute_event");
if ( ESIM_EV_NONE != a1 )
{
v2 = list_get(esim_event_info_list, (unsigned int)a1);
if ( !v2 || (v3 = *(void (__fastcall **)(_QWORD, __int64))(v2 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x1CEu, "esim_execute_event");
v3((unsigned int)a1, a2);
}
}
}

canonical_decompiled_code:
void __fastcall func12(int a1, __int64 a2)
{
__int64 v2; // rax
void (__fastcall *v3)(_QWORD, __int64); // rax

if ( !esim_lock_schedule )
{
if ( a1 < 0 || (int)list_count(esim_event_info_list) <= a1 )
panic("%s: unkown event", "esim_execute_event");
if ( !a1 )
panic("%s: invalid event (forgot to call to 'esim_register_event'?)", "esim_execute_event");
if ( ESIM_EV_NONE != a1 )
{
v2 = list_get(esim_event_info_list, (unsigned int)a1);
if ( !v2 || (v3 = *(void (__fastcall **)(_QWORD, __int64))(v2 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x1CEu, "esim_execute_event");
v3((unsigned int)a1, a2);
}
}
}

original_code:
void esim_execute_event(int id, void *data)
{
 struct esim_event_info_t *event_info;
 if (esim_lock_schedule)
  return;
 if (id < 0 || id >= list_count(esim_event_info_list))
  panic("%s: unkown event", __FUNCTION__);
 if (!id)
  panic("%s: invalid event (forgot to call to 'esim_register_event'?)", __FUNCTION__);
 if (id == ESIM_EV_NONE)
  return;
 event_info = list_get(esim_event_info_list, id);
 ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 462, __extension__ __PRETTY_FUNCTION__); }));
 event_info->handler(id, data);
}


decompiled_code:
__int64 esim_process_events()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rax
void (__fastcall *v3)(_QWORD, _QWORD); // rax
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

while ( 1 )
{
v0 = heap_peek(esim_event_heap, &v4);
result = heap_error(esim_event_heap);
if ( (_DWORD)result )
break;
result = esim_cycle;
if ( esim_cycle > v0 )
_assert_fail("when >= esim_cycle", "esim.c", 0x1E4u, "esim_process_events");
if ( esim_cycle != v0 )
break;
heap_extract(esim_event_heap, 0LL);
v2 = list_get(esim_event_info_list, *v4);
if ( !v2 || (v3 = *(void (__fastcall **)(_QWORD, _QWORD))(v2 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x1EBu, "esim_process_events");
v3(*v4, *((_QWORD *)v4 + 1));
esim_event_free((__int64)v4);
}
++esim_cycle;
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rax
void (__fastcall *v3)(_QWORD, _QWORD); // rax
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

while ( 1 )
{
v0 = heap_peek(esim_event_heap, &v4);
result = heap_error(esim_event_heap);
if ( (_DWORD)result )
break;
result = esim_cycle;
if ( esim_cycle > v0 )
_assert_fail("when >= esim_cycle", "esim.c", 0x1E4u, "esim_process_events");
if ( esim_cycle != v0 )
break;
heap_extract(esim_event_heap, 0LL);
v2 = list_get(esim_event_info_list, *v4);
if ( !v2 || (v3 = *(void (__fastcall **)(_QWORD, _QWORD))(v2 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x1EBu, "esim_process_events");
v3(*v4, *((_QWORD *)v4 + 1));
func3((__int64)v4);
}
++esim_cycle;
return result;
}

original_code:
void esim_process_events()
{
 long long when;
 struct esim_event_t *event;
 struct esim_event_info_t *event_info;
 while (1)
 {
  when = heap_peek(esim_event_heap, (void **) &event);
  if (heap_error(esim_event_heap))
   break;
  ((void) sizeof ((when >= esim_cycle) ? 1 : 0), __extension__ ({ if (when >= esim_cycle) ; else __assert_fail ("when >= esim_cycle", "esim.c", 484, __extension__ __PRETTY_FUNCTION__); }));
  if (when != esim_cycle)
   break;
  heap_extract(esim_event_heap, ((void *)0));
  event_info = list_get(esim_event_info_list, event->id);
  ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 491, __extension__ __PRETTY_FUNCTION__); }));
  event_info->handler(event->id, event->data);
  esim_event_free(event);
 }
 esim_cycle++;
}


decompiled_code:
__int64 esim_process_all_events()
{
unsigned int *v0; // rbx
__int64 v1; // rax
void (__fastcall *v2)(_QWORD, _QWORD); // rax

esim_drain_heap();
while ( (unsigned int)linked_list_count(esim_end_event_list) )
{
linked_list_head(esim_end_event_list);
v0 = (unsigned int *)linked_list_get(esim_end_event_list);
linked_list_remove(esim_end_event_list);
v1 = list_get(esim_event_info_list, *v0);
if ( !v1 || (v2 = *(void (__fastcall **)(_QWORD, _QWORD))(v1 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x208u, "esim_process_all_events");
v2(*v0, *((_QWORD *)v0 + 1));
esim_event_free((__int64)v0);
}
return esim_drain_heap();
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int *v0; // rbx
__int64 v1; // rax
void (__fastcall *v2)(_QWORD, _QWORD); // rax

func6();
while ( (unsigned int)linked_list_count(esim_end_event_list) )
{
linked_list_head(esim_end_event_list);
v0 = (unsigned int *)linked_list_get(esim_end_event_list);
linked_list_remove(esim_end_event_list);
v1 = list_get(esim_event_info_list, *v0);
if ( !v1 || (v2 = *(void (__fastcall **)(_QWORD, _QWORD))(v1 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x208u, "esim_process_all_events");
v2(*v0, *((_QWORD *)v0 + 1));
func3((__int64)v0);
}
return func6();
}

original_code:
void esim_process_all_events(void)
{
 struct esim_event_t *event;
 struct esim_event_info_t *event_info;
 esim_drain_heap();
 while (linked_list_count(esim_end_event_list))
 {
  linked_list_head(esim_end_event_list);
  event = linked_list_get(esim_end_event_list);
  linked_list_remove(esim_end_event_list);
  event_info = list_get(esim_event_info_list, event->id);
  ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 520, __extension__ __PRETTY_FUNCTION__); }));
  event_info->handler(event->id, event->data);
  esim_event_free(event);
 }
 esim_drain_heap();
}

canonical_original_code:
void esim_process_all_events()
{
 struct esim_event_t *event;
 struct esim_event_info_t *event_info;
 esim_drain_heap();
 while (linked_list_count(esim_end_event_list))
 {
  linked_list_head(esim_end_event_list);
  event = linked_list_get(esim_end_event_list);
  linked_list_remove(esim_end_event_list);
  event_info = list_get(esim_event_info_list, event->id);
  ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 520, __extension__ __PRETTY_FUNCTION__); }));
  event_info->handler(event->id, event->data);
  esim_event_free(event);
 }
 esim_drain_heap();
}


decompiled_code:
__int64 esim_empty()
{
__int64 result; // rax
__int64 v1; // rax
void (__fastcall *v2)(_QWORD, _QWORD); // rax
unsigned int *v3; // [rsp+8h] [rbp-10h] BYREF

esim_lock_schedule = 1;
while ( 1 )
{
heap_extract(esim_event_heap, &v3);
result = heap_error(esim_event_heap);
if ( (_DWORD)result )
break;
v1 = list_get(esim_event_info_list, *v3);
if ( !v1 || (v2 = *(void (__fastcall **)(_QWORD, _QWORD))(v1 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x225u, "esim_empty");
v2(*v3, *((_QWORD *)v3 + 1));
esim_event_free((__int64)v3);
}
esim_lock_schedule = 0;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax
__int64 v1; // rax
void (__fastcall *v2)(_QWORD, _QWORD); // rax
unsigned int *v3; // [rsp+8h] [rbp-10h] BYREF

esim_lock_schedule = 1;
while ( 1 )
{
heap_extract(esim_event_heap, &v3);
result = heap_error(esim_event_heap);
if ( (_DWORD)result )
break;
v1 = list_get(esim_event_info_list, *v3);
if ( !v1 || (v2 = *(void (__fastcall **)(_QWORD, _QWORD))(v1 + 16)) == 0LL )
_assert_fail("event_info && event_info->handler", "esim.c", 0x225u, "esim_empty");
v2(*v3, *((_QWORD *)v3 + 1));
func3((__int64)v3);
}
esim_lock_schedule = 0;
return result;
}

original_code:
void esim_empty(void)
{
 struct esim_event_t *event;
 struct esim_event_info_t *event_info;
 esim_lock_schedule = 1;
 while (1)
 {
  heap_extract(esim_event_heap, (void **) &event);
  if (heap_error(esim_event_heap))
   break;
  event_info = list_get(esim_event_info_list, event->id);
  ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 549, __extension__ __PRETTY_FUNCTION__); }));
  event_info->handler(event->id, event->data);
  esim_event_free(event);
 }
 esim_lock_schedule = 0;
}

canonical_original_code:
void esim_empty()
{
 struct esim_event_t *event;
 struct esim_event_info_t *event_info;
 esim_lock_schedule = 1;
 while (1)
 {
  heap_extract(esim_event_heap, (void **) &event);
  if (heap_error(esim_event_heap))
   break;
  event_info = list_get(esim_event_info_list, event->id);
  ((void) sizeof ((event_info && event_info->handler) ? 1 : 0), __extension__ ({ if (event_info && event_info->handler) ; else __assert_fail ("event_info && event_info->handler", "esim.c", 549, __extension__ __PRETTY_FUNCTION__); }));
  event_info->handler(event->id, event->data);
  esim_event_free(event);
 }
 esim_lock_schedule = 0;
}


decompiled_code:
__int64 esim_event_count()
{
return heap_count(esim_event_heap);
}

canonical_decompiled_code:
__int64 func16()
{
return heap_count(esim_event_heap);
}

original_code:
int esim_event_count(void)
{
 return heap_count(esim_event_heap);
}

canonical_original_code:
int esim_event_count()
{
 return heap_count(esim_event_heap);
}


decompiled_code:
__int64 esim_real_time()
{
return m2s_timer_get_value(esim_timer);
}

canonical_decompiled_code:
__int64 func17()
{
return m2s_timer_get_value(esim_timer);
}

original_code:
long long esim_real_time(void)
{
 return m2s_timer_get_value(esim_timer);
}

canonical_original_code:
long long esim_real_time()
{
 return m2s_timer_get_value(esim_timer);
}

return_type: long long


decompiled_code:
__int64 __fastcall net_buffer_create(__int64 a1, __int64 a2, int a3, __int64 a4)
{
__int64 v6; // rbx

v6 = mhandle_calloc(1LL, 128LL, "buffer.c:33");
if ( !v6 )
fatal("%s: out of memory", "net_buffer_create");
*(_QWORD *)(v6 + 64) = list_create();
*(_QWORD *)(v6 + 88) = linked_list_create();
*(_QWORD *)v6 = a1;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = mhandle_strdup(a4, "buffer.c:42");
*(_DWORD *)(v6 + 28) = a3;
if ( a3 <= 0 )
panic("%s: invalid size", "net_buffer_create");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3, __int64 a4)
{
__int64 v6; // rbx

v6 = mhandle_calloc(1LL, 128LL, "buffer.c:33");
if ( !v6 )
fatal("%s: out of memory", "net_buffer_create");
*(_QWORD *)(v6 + 64) = list_create();
*(_QWORD *)(v6 + 88) = linked_list_create();
*(_QWORD *)v6 = a1;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = mhandle_strdup(a4, "buffer.c:42");
*(_DWORD *)(v6 + 28) = a3;
if ( a3 <= 0 )
panic("%s: invalid size", "net_buffer_create");
return v6;
}

original_code:
struct net_buffer_t *net_buffer_create(struct net_t *net, struct net_node_t *node,
 int size, char *name)
{
 struct net_buffer_t *buffer;
 buffer = (mhandle_calloc(1, sizeof(struct net_buffer_t), "buffer.c" ":" "33"));
 if (!buffer)
  fatal("%s: out of memory", __FUNCTION__);
 buffer->msg_list = list_create();
 buffer->wakeup_list = linked_list_create();
 buffer->net = net;
 buffer->node = node;
 buffer->name = (mhandle_strdup(name, "buffer.c" ":" "42"));
 buffer->size = size;
 if (size < 1)
  panic("%s: invalid size", __FUNCTION__);
 return buffer;
}

variable_types:
net
struct net_t *

variable_types:
node
struct net_node_t *

variable_types: size int

variable_types: struct net_buffer_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *


decompiled_code:
__int64 __fastcall net_buffer_free(_QWORD *a1)
{
list_free(a1[8]);
linked_list_free(a1[11]);
mhandle_free(a1[2], "buffer.c:56");
return mhandle_free(a1, "buffer.c:57");
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
list_free(a1[8]);
linked_list_free(a1[11]);
mhandle_free(a1[2], "buffer.c:56");
return mhandle_free(a1, "buffer.c:57");
}

original_code:
void net_buffer_free(struct net_buffer_t *buffer)
{
 list_free(buffer->msg_list);
 linked_list_free(buffer->wakeup_list);
 (mhandle_free(buffer->name, "buffer.c" ":" "56"));
 (mhandle_free(buffer, "buffer.c" ":" "57"));
}


decompiled_code:
void __fastcall net_buffer_wait(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx

if ( ESIM_EV_NONE != a2 )
{
if ( *(int *)(a1 + 32) <= 0 )
_assert_fail("buffer->count > 0", "buffer.c", 0xA2u, "net_buffer_wait");
v4 = mhandle_malloc(16LL, "buffer.c:163");
if ( !v4 )
fatal("%s: out of memory", "net_buffer_wait");
*(_DWORD *)v4 = a2;
*(_QWORD *)(v4 + 8) = a3;
linked_list_add(*(_QWORD *)(a1 + 88), v4);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx

if ( ESIM_EV_NONE != a2 )
{
if ( *(int *)(a1 + 32) <= 0 )
_assert_fail("buffer->count > 0", "buffer.c", 0xA2u, "net_buffer_wait");
v4 = mhandle_malloc(16LL, "buffer.c:163");
if ( !v4 )
fatal("%s: out of memory", "net_buffer_wait");
*(_DWORD *)v4 = a2;
*(_QWORD *)(v4 + 8) = a3;
linked_list_add(*(_QWORD *)(a1 + 88), v4);
}
}

original_code:
void net_buffer_wait(struct net_buffer_t *buffer, int event, void *stack)
{
 struct net_buffer_wakeup_t *wakeup;
 if (event == ESIM_EV_NONE)
  return;
 ((void) sizeof ((buffer->count > 0) ? 1 : 0), __extension__ ({ if (buffer->count > 0) ; else __assert_fail ("buffer->count > 0", "buffer.c", 162, __extension__ __PRETTY_FUNCTION__); }));
 wakeup = (mhandle_malloc(sizeof(struct net_buffer_wakeup_t), "buffer.c" ":" "163"));
 if (!wakeup)
  fatal("%s: out of memory", __FUNCTION__);
 wakeup->event = event;
 wakeup->stack = stack;
 linked_list_add(buffer->wakeup_list, wakeup);
}

variable_types: event int

variable_types:
stack
void *

variable_types: struct net_buffer_wakeup_t { int event; void *stack; } *


decompiled_code:
__int64 __fastcall net_buffer_wakeup(__int64 a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

while ( 1 )
{
result = linked_list_count(*(_QWORD *)(a1 + 88));
if ( !(_DWORD)result )
break;
linked_list_head(*(_QWORD *)(a1 + 88));
v1 = (unsigned int *)linked_list_get(*(_QWORD *)(a1 + 88));
linked_list_remove(*(_QWORD *)(a1 + 88));
esim_schedule_event(*v1, *((_QWORD *)v1 + 1), 0LL);
mhandle_free(v1, "buffer.c:188");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

while ( 1 )
{
result = linked_list_count(*(_QWORD *)(a1 + 88));
if ( !(_DWORD)result )
break;
linked_list_head(*(_QWORD *)(a1 + 88));
v1 = (unsigned int *)linked_list_get(*(_QWORD *)(a1 + 88));
linked_list_remove(*(_QWORD *)(a1 + 88));
esim_schedule_event(*v1, *((_QWORD *)v1 + 1), 0LL);
mhandle_free(v1, "buffer.c:188");
}
return result;
}

original_code:
void net_buffer_wakeup(struct net_buffer_t *buffer)
{
 struct net_buffer_wakeup_t *wakeup;
 while (linked_list_count(buffer->wakeup_list))
 {
  linked_list_head(buffer->wakeup_list);
  wakeup = linked_list_get(buffer->wakeup_list);
  linked_list_remove(buffer->wakeup_list);
  esim_schedule_event(wakeup->event, wakeup->stack, 0);
  (mhandle_free(wakeup, "buffer.c" ":" "188"));
 }
}

user_defined_types: struct net_buffer_wakeup_t { int event; void *stack; }


original_code:
void net_buffer_update_occupancy(struct net_buffer_t *buffer)
{
 long long cycles;
 cycles = esim_cycle - buffer->occupancy_measured_cycle;
 buffer->occupancy_bytes_acc += buffer->occupancy_bytes_value * cycles;
 buffer->occupancy_msgs_acc += buffer->occupancy_msgs_value * cycles;
 buffer->occupancy_bytes_value = buffer->count;
 buffer->occupancy_msgs_value = list_count(buffer->msg_list);
 buffer->occupancy_measured_cycle = esim_cycle;
}

variable_types:
cycles
long long


decompiled_code:
__int64 __fastcall net_buffer_insert(__int64 a1, __int64 a2)
{
const char **v2; // r12
__int64 v3; // r13
__int64 result; // rax

v2 = *(const char ***)a1;
v3 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 32) + *(_DWORD *)(a2 + 16) > *(_DWORD *)(a1 + 28) )
panic("%s: not enough space in buffer", "net_buffer_insert");
*(_DWORD *)(a1 + 32) += *(_DWORD *)(a2 + 16);
list_enqueue(*(_QWORD *)(a1 + 64), a2);
result = net_buffer_update_occupancy(a1);
if ( net_debug_category )
result = _debug(
net_debug_category,
"buf a=\"insert\" net=\"%s\" msg=%lld node=\"%s\" buf=\"%s\"\n",
*v2,
*(_QWORD *)(a2 + 8),
*(const char **)(v3 + 16),
*(const char **)(a1 + 16));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
const char **v2; // r12
__int64 v3; // r13
__int64 result; // rax

v2 = *(const char ***)a1;
v3 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 32) + *(_DWORD *)(a2 + 16) > *(_DWORD *)(a1 + 28) )
panic("%s: not enough space in buffer", "net_buffer_insert");
*(_DWORD *)(a1 + 32) += *(_DWORD *)(a2 + 16);
list_enqueue(*(_QWORD *)(a1 + 64), a2);
result = func5(a1);
if ( net_debug_category )
result = _debug(
net_debug_category,
"buf a=\"insert\" net=\"%s\" msg=%lld node=\"%s\" buf=\"%s\"\n",
*v2,
*(_QWORD *)(a2 + 8),
*(const char **)(v3 + 16),
*(const char **)(a1 + 16));
return result;
}

original_code:
void net_buffer_insert(struct net_buffer_t *buffer, struct net_msg_t *msg)
{
 struct net_t *net = buffer->net;
 struct net_node_t *node = buffer->node;
 if (buffer->count + msg->size > buffer->size)
  panic("%s: not enough space in buffer", __FUNCTION__);
 buffer->count += msg->size;
 list_enqueue(buffer->msg_list, msg);
 net_buffer_update_occupancy(buffer);
 ((net_debug_category) ? __debug((net_debug_category), "buf " "a=\"insert\" " "net=\"%s\" " "msg=%lld " "node=\"%s\" " "buf=\"%s\"\n", net->name, msg->id, node->name, buffer->name) : (void) 0);
}

variable_types:
msg
struct net_msg_t *

variable_types: struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *

variable_types: struct net_node_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *wakeup_list; int occupancy_bytes_value; int occupancy_msgs_value; long long occupancy_measured_cycle; long long occupancy_bytes_acc; long long occupancy_msgs_acc; } *output_buffer; } *entries; int has_cycle; } *routing_table; struct net_msg_t { struct net_t *net; long long id; int size; long long send_cycle; long long busy; struct net_node_t *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *node; struct net_buffer_t *buffer; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; struct net_msg_t *bucket_next; } *msg_table[32]; long long transfers; long long lat_acc; long long msg_size_acc; } *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *


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

v2 = *(const char ***)a1;
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 32);
v5 = *(_DWORD *)(a2 + 16);
if ( v4 < v5 )
_assert_fail("buffer->count >= msg->size", "buffer.c", 0x7Bu, "net_buffer_extract");
*(_DWORD *)(a1 + 32) = v4 - v5;
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",
*v2,
*(_QWORD *)(a2 + 8),
*(const char **)(v3 + 16),
*(const char **)(a1 + 16));
return net_buffer_wakeup(a1);
}

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

v2 = *(const char ***)a1;
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 32);
v5 = *(_DWORD *)(a2 + 16);
if ( v4 < v5 )
_assert_fail("buffer->count >= msg->size", "buffer.c", 0x7Bu, "net_buffer_extract");
*(_DWORD *)(a1 + 32) = v4 - v5;
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",
*v2,
*(_QWORD *)(a2 + 8),
*(const char **)(v3 + 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 v0; // rbx

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

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

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

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


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


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

if ( *(_DWORD *)(a1 + 32) == *(_DWORD *)a1 )
{
*(_DWORD *)(a1 + 4) = 1;
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 16LL);
}
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;
}


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

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

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

result = *a1;
if ( (_DWORD)result )
{
v2 = a1[8];
if ( v2 < (int)result - 1 )
{
a1[8] = v2 + 1;
result = *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL);
}
else
{
a1[8] = 0;
result = *((_QWORD *)a1 + 1);
}
*((_QWORD *)a1 + 3) = result;
a1[1] = 0;
}
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 )
{
a1[8] = v2 - 1;
v3 = (__int64 *)*((_QWORD *)a1 + 3);
if ( v3 )
result = *v3;
else
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
a1[1] = 0;
}
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 )
{
a1[8] = v2 - 1;
v3 = (__int64 *)*((_QWORD *)a1 + 3);
if ( v3 )
result = *v3;
else
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
else
{
a1[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
}
a1[1] = 0;
}
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(__int64 a1)
{
__int64 result; // rax

if ( *(_DWORD *)a1 )
{
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = 0;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 24) = result;
}
else
{
*(_DWORD *)(a1 + 4) = 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[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
a1[1] = 0;
}
else
{
a1[1] = 2;
}
return result;
}

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

result = *a1;
if ( (_DWORD)result )
{
a1[8] = result - 1;
result = *((_QWORD *)a1 + 2);
*((_QWORD *)a1 + 3) = result;
a1[1] = 0;
}
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

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

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

a1[1] = 0;
result = *a1;
a1[8] = result;
*((_QWORD *)a1 + 3) = 0LL;
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

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

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

*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 32) = 0;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 24) = result;
if ( result )
{
while ( *(_QWORD *)(result + 16) != a2 )
{
++*(_DWORD *)(a1 + 32);
result = *(_QWORD *)(result + 8);
*(_QWORD *)(a1 + 24) = result;
if ( !result )
goto LABEL_4;
}
}
else
{
LABEL_4:
*(_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)
{
a1[1] = 0;
return a1[8] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(_DWORD *a1)
{
a1[1] = 0;
return a1[8] == *a1;
}

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((__int64)a1, a2);
return linked_list_out(a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int *a1, __int64 a2)
{
func10(a1);
linked_list_insert((__int64)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);
}


decompiled_code:
__int64 __fastcall linked_list_remove(unsigned int *a1)
{
__int64 result; // rax
_QWORD **v2; // rdx
_QWORD *v3; // rax

result = *a1;
if ( a1[8] == (_DWORD)result )
{
a1[1] = 1;
}
else
{
v2 = (_QWORD **)*((_QWORD *)a1 + 3);
if ( (_DWORD)result == 1 )
{
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 1) = 0LL;
}
else
{
if ( *((_QWORD ***)a1 + 1) == v2 )
{
*v2[1] = 0LL;
*((_QWORD *)a1 + 1) = v2[1];
}
else if ( *((_QWORD ***)a1 + 2) == v2 )
{
(*v2)[1] = 0LL;
*((_QWORD *)a1 + 2) = *v2;
}
else
{
v3 = v2[1];
(*v2)[1] = v3;
*v3 = *v2;
}
LODWORD(result) = *a1;
if ( (int)*a1 <= 0 )
_assert_fail("list->count > 0", "linked-list.c", 0x142u, "linked_list_remove");
}
a1[1] = 0;
*a1 = result - 1;
*((_QWORD *)a1 + 3) = v2[1];
result = mhandle_free(v2, "linked-list.c:326");
}
return result;
}

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


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 func18(__int64 a1)
{
func17(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; // rbx

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

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