decompiled_code:
__int64 __fastcall si_opencl_program_read_symbol(__int64 a1, const char *a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v5; // rbx
__int64 v6; // rbp
__int64 v7; // rax
int v8; // edx
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 16);
if ( !v3 )
_assert_fail("elf_file", "opencl-program.c", 0x6Eu, "si_opencl_program_read_symbol");
v5 = elf_symbol_get_by_name(*(_QWORD *)(a1 + 16));
if ( !v5 )
fatal(
"%s: ELF symbol '%s' not found.\n%s",
"si_opencl_program_read_symbol",
a2,
"\tThe ELF file analyzer is trying to find a name in the ELF symbol table.\n"
"\tIf it is not found, it probably means that your application is requesting\n"
"\texecution of a kernel function that is not present in the encoded binary.\n"
"\tPlease, check the parameters passed to the 'clCreateKernel' function in\n"
"\tyour application.\n"
"\tThis could be also a symptom of compiling an OpenCL kernel source on a\n"
"\tmachine with an installation of the APP SDK (using 'm2s-opencl-kc') but\n"
"\twith an incorrect or missing installation of the GPU driver. In this case,\n"
"\tthe tool will still compile the kernel into LLVM, but the ISA section will\n"
"\tbe missing in the kernel binary.\n");
v6 = list_get(*(_QWORD *)(v3 + 32), *(unsigned int *)(v5 + 16));
if ( !v6 )
_assert_fail("section", "opencl-program.c", 0x76u, "si_opencl_program_read_symbol");
v7 = *(unsigned int *)(v5 + 8);
v8 = *(_DWORD *)(v5 + 12);
if ( (unsigned int)(v7 + v8) > *(_DWORD *)(*(_QWORD *)(v6 + 8) + 20LL) )
{
fatal(
"%s: ELF symbol '%s' exceeds section '%s' boundaries.\n%s",
"si_opencl_program_read_symbol",
*(const char **)v5,
*(const char **)v6,
"\tThe ELF file analyzer is trying to find a name in the ELF symbol table.\n"
"\tIf it is not found, it probably means that your application is requesting\n"
"\texecution of a kernel function that is not present in the encoded binary.\n"
"\tPlease, check the parameters passed to the 'clCreateKernel' function in\n"
"\tyour application.\n"
"\tThis could be also a symptom of compiling an OpenCL kernel source on a\n"
"\tmachine with an installation of the APP SDK (using 'm2s-opencl-kc') but\n"
"\twith an incorrect or missing installation of the GPU driver. In this case,\n"
"\tthe tool will still compile the kernel into LLVM, but the ISA section will\n"
"\tbe missing in the kernel binary.\n");
v7 = *(unsigned int *)(v5 + 8);
v8 = *(_DWORD *)(v5 + 12);
}
result = *(_QWORD *)(v6 + 16) + v7;
*(_DWORD *)(a3 + 8) = v8;
*(_QWORD *)a3 = result;
*(_DWORD *)(a3 + 12) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v5; // rbx
__int64 v6; // rbp
__int64 v7; // rax
int v8; // edx
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 16);
if ( !v3 )
_assert_fail("elf_file", "opencl-program.c", 0x6Eu, "si_opencl_program_read_symbol");
v5 = elf_symbol_get_by_name(*(_QWORD *)(a1 + 16));
if ( !v5 )
fatal(
"%s: ELF symbol '%s' not found.\n%s",
"si_opencl_program_read_symbol",
a2,
"\tThe ELF file analyzer is trying to find a name in the ELF symbol table.\n"
"\tIf it is not found, it probably means that your application is requesting\n"
"\texecution of a kernel function that is not present in the encoded binary.\n"
"\tPlease, check the parameters passed to the 'clCreateKernel' function in\n"
"\tyour application.\n"
"\tThis could be also a symptom of compiling an OpenCL kernel source on a\n"
"\tmachine with an installation of the APP SDK (using 'm2s-opencl-kc') but\n"
"\twith an incorrect or missing installation of the GPU driver. In this case,\n"
"\tthe tool will still compile the kernel into LLVM, but the ISA section will\n"
"\tbe missing in the kernel binary.\n");
v6 = list_get(*(_QWORD *)(v3 + 32), *(unsigned int *)(v5 + 16));
if ( !v6 )
_assert_fail("section", "opencl-program.c", 0x76u, "si_opencl_program_read_symbol");
v7 = *(unsigned int *)(v5 + 8);
v8 = *(_DWORD *)(v5 + 12);
if ( (unsigned int)(v7 + v8) > *(_DWORD *)(*(_QWORD *)(v6 + 8) + 20LL) )
{
fatal(
"%s: ELF symbol '%s' exceeds section '%s' boundaries.\n%s",
"si_opencl_program_read_symbol",
*(const char **)v5,
*(const char **)v6,
"\tThe ELF file analyzer is trying to find a name in the ELF symbol table.\n"
"\tIf it is not found, it probably means that your application is requesting\n"
"\texecution of a kernel function that is not present in the encoded binary.\n"
"\tPlease, check the parameters passed to the 'clCreateKernel' function in\n"
"\tyour application.\n"
"\tThis could be also a symptom of compiling an OpenCL kernel source on a\n"
"\tmachine with an installation of the APP SDK (using 'm2s-opencl-kc') but\n"
"\twith an incorrect or missing installation of the GPU driver. In this case,\n"
"\tthe tool will still compile the kernel into LLVM, but the ISA section will\n"
"\tbe missing in the kernel binary.\n");
v7 = *(unsigned int *)(v5 + 8);
v8 = *(_DWORD *)(v5 + 12);
}
result = *(_QWORD *)(v6 + 16) + v7;
*(_DWORD *)(a3 + 8) = v8;
*(_QWORD *)a3 = result;
*(_DWORD *)(a3 + 12) = 0;
return result;
}

original_code:
void si_opencl_program_read_symbol(struct si_opencl_program_t *program, char *symbol_name,
 struct elf_buffer_t *buffer)
{
 struct elf_file_t *elf_file;
 struct elf_symbol_t *symbol;
 struct elf_section_t *section;
 elf_file = program->elf_file;
 ((void) sizeof ((elf_file) ? 1 : 0), __extension__ ({ if (elf_file) ; else __assert_fail ("elf_file", "opencl-program.c", 110, __extension__ __PRETTY_FUNCTION__); }));
 symbol = elf_symbol_get_by_name(elf_file, symbol_name);
 if (!symbol)
  fatal("%s: ELF symbol '%s' not found.\n%s", __FUNCTION__,
   symbol_name, err_si_opencl_elf_symbol);
 section = list_get(elf_file->section_list, symbol->section);
 ((void) sizeof ((section) ? 1 : 0), __extension__ ({ if (section) ; else __assert_fail ("section", "opencl-program.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 if (symbol->value + symbol->size > section->header->sh_size)
  fatal("%s: ELF symbol '%s' exceeds section '%s' boundaries.\n%s",
   __FUNCTION__, symbol->name, section->name, err_si_opencl_elf_symbol);
 buffer->ptr = section->buffer.ptr + symbol->value;
 buffer->size = symbol->size;
 buffer->pos = 0;
}

variable_types:
buffer
struct elf_buffer_t *

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

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

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


decompiled_code:
__int64 __fastcall si_opencl_program_initialize_constant_buffers(__int64 a1)
{
unsigned int v2; // ebx
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rsi
__int64 v9; // rdi
__int64 v10; // rsi
__int64 result; // rax
const char **v12; // r12
__int64 v13; // [rsp+0h] [rbp-108h] BYREF
unsigned int v14; // [rsp+8h] [rbp-100h]
char s[248]; // [rsp+10h] [rbp-F8h] BYREF

v2 = 2;
v3 = *(_QWORD *)(a1 + 16);
do
{
sprintf(s, "__OpenCL_%d_global", v2);
result = elf_symbol_get_by_name(v3);
v12 = (const char **)result;
if ( !result )
break;
if ( si_opencl_debug_category )
_debug(
si_opencl_debug_category,
" constant buffer '%s' found with size %d\n",
*(const char **)result,
*(unsigned int *)(result + 12));
si_opencl_program_read_symbol(a1, *v12, (__int64)&v13);
v4 = si_opencl_mem_create();
v5 = v14;
*(_DWORD *)(v4 + 8) = 0;
v6 = v4;
*(_DWORD *)(v4 + 12) = v5;
*(_QWORD *)(v4 + 52) = 0LL;
v7 = si_emu;
v8 = *(unsigned int *)(si_emu + 136LL);
v9 = *(_QWORD *)(si_emu + 128LL);
*(_DWORD *)(v6 + 60) = v8;
*(_DWORD *)(v7 + 136) = v5 + v8;
mem_write(v9, v8, v5, v13);
v10 = v2++;
result = list_set(*(_QWORD *)(a1 + 24), v10, v6);
}
while ( v2 != 25 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v2; // ebx
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rsi
__int64 v9; // rdi
__int64 v10; // rsi
__int64 result; // rax
const char **v12; // r12
__int64 v13; // [rsp+0h] [rbp-108h] BYREF
unsigned int v14; // [rsp+8h] [rbp-100h]
char s[248]; // [rsp+10h] [rbp-F8h] BYREF

v2 = 2;
v3 = *(_QWORD *)(a1 + 16);
do
{
sprintf(s, "__OpenCL_%d_global", v2);
result = elf_symbol_get_by_name(v3);
v12 = (const char **)result;
if ( !result )
break;
if ( si_opencl_debug_category )
_debug(
si_opencl_debug_category,
" constant buffer '%s' found with size %d\n",
*(const char **)result,
*(unsigned int *)(result + 12));
func3(a1, *v12, (__int64)&v13);
v4 = si_opencl_mem_create();
v5 = v14;
*(_DWORD *)(v4 + 8) = 0;
v6 = v4;
*(_DWORD *)(v4 + 12) = v5;
*(_QWORD *)(v4 + 52) = 0LL;
v7 = si_emu;
v8 = *(unsigned int *)(si_emu + 136LL);
v9 = *(_QWORD *)(si_emu + 128LL);
*(_DWORD *)(v6 + 60) = v8;
*(_DWORD *)(v7 + 136) = v5 + v8;
mem_write(v9, v8, v5, v13);
v10 = v2++;
result = list_set(*(_QWORD *)(a1 + 24), v10, v6);
}
while ( v2 != 25 );
return result;
}

original_code:
void si_opencl_program_initialize_constant_buffers(struct si_opencl_program_t *program)
{
 struct elf_file_t *elf_file;
 struct elf_symbol_t *elf_symbol;
 struct elf_buffer_t elf_buffer;
 struct si_opencl_mem_t *mem;
 char symbol_name[200];
 int i;
 elf_file = program->elf_file;
 for (i = 2; i < 25; i++)
 {
  sprintf(symbol_name, "__OpenCL_%d_global", i);
  elf_symbol = elf_symbol_get_by_name(elf_file, symbol_name);
                if (elf_symbol == ((void *)0)) {
   break;
  }
  ((si_opencl_debug_category) ? __debug((si_opencl_debug_category), "  constant buffer '%s' found with size %d\n", elf_symbol->name, elf_symbol->size) : (void) 0);
  si_opencl_program_read_symbol(program, elf_symbol->name, &elf_buffer);
  mem = si_opencl_mem_create();
  mem->type = 0;
  mem->size = elf_buffer.size;
  mem->flags = 0;
  mem->host_ptr = 0;
  mem->device_ptr = si_emu->global_mem_top;
  si_emu->global_mem_top += mem->size;
  mem_write(si_emu->global_mem, mem->device_ptr, mem->size, elf_buffer.ptr);
  list_set(program->constant_buffer_list, i, mem);
 }
}

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

variable_types: struct si_opencl_mem_t { unsigned int id; int ref_count; unsigned int type; unsigned int size; unsigned int height; unsigned int width; unsigned int depth; unsigned int num_pixels; unsigned int pixel_size; unsigned int num_channels_per_pixel; unsigned int map_flags; unsigned int map_offset; unsigned int map_cb; unsigned int flags; unsigned int host_ptr; unsigned int device_ptr; } *

variable_types: i int

return_type: void

user_defined_types: struct si_opencl_program_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; struct elf_file_t *elf_file; struct list_t *constant_buffer_list; }

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

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

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


decompiled_code:
__int64 __fastcall x86_cpu_commit_core(signed int a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rcx
int v5; // esi
int v6; // er12
int v7; // ebx
int v8; // er12
int v9; // ecx
__int64 v10; // r13
__int64 v11; // rdi
int v12; // edx

result = x86_cpu_commit_kind;
if ( x86_cpu_commit_kind )
{
if ( x86_cpu_commit_kind == 1 )
{
v3 = 1824LL * a1;
v4 = v3 + *x86_cpu;
v5 = *(_DWORD *)(v4 + 108);
v6 = (v5 + 1) % x86_cpu_num_threads;
if ( v5 != v6 )
{
while ( !(unsigned int)x86_cpu_can_commit_thread(a1, v6) )
{
v4 = v3 + *x86_cpu;
v6 = (v6 + 1) % x86_cpu_num_threads;
if ( *(_DWORD *)(v4 + 108) == v6 )
goto LABEL_4;
}
v4 = *x86_cpu + v3;
}
LABEL_4:
*(_DWORD *)(v4 + 108) = v6;
result = x86_cpu_commit_thread(a1, v6, x86_cpu_commit_width);
}
}
else
{
v7 = x86_cpu_commit_width;
v8 = x86_cpu_num_threads;
if ( x86_cpu_commit_width && x86_cpu_num_threads )
{
v9 = x86_cpu_num_threads;
v10 = 1824LL * a1;
while ( 1 )
{
--v8;
v11 = v10 + *x86_cpu;
v12 = (*(_DWORD *)(v11 + 108) + 1) % v9;
*(_DWORD *)(v11 + 108) = v12;
result = x86_cpu_can_commit_thread(a1, v12);
if ( (_DWORD)result )
{
--v7;
result = x86_cpu_commit_thread(a1, *(_DWORD *)(*x86_cpu + v10 + 108), 1);
v8 = x86_cpu_num_threads;
}
if ( !v7 || !v8 )
break;
v9 = x86_cpu_num_threads;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(signed int a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rcx
int v5; // esi
int v6; // er12
int v7; // ebx
int v8; // er12
int v9; // ecx
__int64 v10; // r13
__int64 v11; // rdi
int v12; // edx

result = x86_cpu_commit_kind;
if ( x86_cpu_commit_kind )
{
if ( x86_cpu_commit_kind == 1 )
{
v3 = 1824LL * a1;
v4 = v3 + *x86_cpu;
v5 = *(_DWORD *)(v4 + 108);
v6 = (v5 + 1) % x86_cpu_num_threads;
if ( v5 != v6 )
{
while ( !(unsigned int)func0(a1, v6) )
{
v4 = v3 + *x86_cpu;
v6 = (v6 + 1) % x86_cpu_num_threads;
if ( *(_DWORD *)(v4 + 108) == v6 )
goto LABEL_4;
}
v4 = *x86_cpu + v3;
}
LABEL_4:
*(_DWORD *)(v4 + 108) = v6;
result = func1(a1, v6, x86_cpu_commit_width);
}
}
else
{
v7 = x86_cpu_commit_width;
v8 = x86_cpu_num_threads;
if ( x86_cpu_commit_width && x86_cpu_num_threads )
{
v9 = x86_cpu_num_threads;
v10 = 1824LL * a1;
while ( 1 )
{
--v8;
v11 = v10 + *x86_cpu;
v12 = (*(_DWORD *)(v11 + 108) + 1) % v9;
*(_DWORD *)(v11 + 108) = v12;
result = func0(a1, v12);
if ( (_DWORD)result )
{
--v7;
result = func1(a1, *(_DWORD *)(*x86_cpu + v10 + 108), 1);
v8 = x86_cpu_num_threads;
}
if ( !v7 || !v8 )
break;
v9 = x86_cpu_num_threads;
}
}
}
return result;
}

original_code:
static void x86_cpu_commit_core(int core)
{
 int pass, quant, new;
 switch (x86_cpu_commit_kind)
 {
 case x86_cpu_commit_kind_shared:
  pass = x86_cpu_num_threads;
  quant = x86_cpu_commit_width;
  while (quant && pass)
  {
   (x86_cpu->core[core]).commit_current = ((x86_cpu->core[core]).commit_current + 1) % x86_cpu_num_threads;
   if (x86_cpu_can_commit_thread(core, (x86_cpu->core[core]).commit_current))
   {
    x86_cpu_commit_thread(core, (x86_cpu->core[core]).commit_current, 1);
    quant--;
    pass = x86_cpu_num_threads;
   }
   else
    pass--;
  }
  break;
 case x86_cpu_commit_kind_timeslice:
  new = ((x86_cpu->core[core]).commit_current + 1) % x86_cpu_num_threads;
  while (new != (x86_cpu->core[core]).commit_current && !x86_cpu_can_commit_thread(core, new))
   new = (new + 1) % x86_cpu_num_threads;
  (x86_cpu->core[core]).commit_current = new;
  x86_cpu_commit_thread(core, new, x86_cpu_commit_width);
  break;
 }
}

canonical_original_code:
static void x86_cpu_commit_core(int core)
{
 int pass; int quant; int new;
 switch (x86_cpu_commit_kind)
 {
 case x86_cpu_commit_kind_shared:
  pass = x86_cpu_num_threads;
  quant = x86_cpu_commit_width;
  while (quant && pass)
  {
   (x86_cpu->core[core]).commit_current = ((x86_cpu->core[core]).commit_current + 1) % x86_cpu_num_threads;
   if (x86_cpu_can_commit_thread(core, (x86_cpu->core[core]).commit_current))
   {
    x86_cpu_commit_thread(core, (x86_cpu->core[core]).commit_current, 1);
    quant--;
    pass = x86_cpu_num_threads;
   }
   else
    pass--;
  }
  break;
 case x86_cpu_commit_kind_timeslice:
  new = ((x86_cpu->core[core]).commit_current + 1) % x86_cpu_num_threads;
  while (new != (x86_cpu->core[core]).commit_current && !x86_cpu_can_commit_thread(core, new))
   new = (new + 1) % x86_cpu_num_threads;
  (x86_cpu->core[core]).commit_current = new;
  x86_cpu_commit_thread(core, new, x86_cpu_commit_width);
  break;
 }
}

variable_types: core int

variable_types: pass int

variable_types: quant int

variable_types: new int


decompiled_code:
__int64 x86_cpu_commit()
{
__int64 result; // rax
int v1; // ebx
signed int v2; // edi

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

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

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

original_code:
void x86_cpu_commit()
{
 int core;
 x86_cpu->stage = "commit";
 for (core = 0; core < x86_cpu_num_cores; core++)
  x86_cpu_commit_core(core);
}


decompiled_code:
_DWORD *evg_opencl_context_create()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 16LL, "opencl-context.c:35");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_context_create");
v1 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 3LL);
v0[1] = 1;
*v0 = v1;
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

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

v0 = (_DWORD *)mhandle_calloc(1LL, 16LL, "opencl-context.c:35");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_context_create");
v1 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 3LL);
v0[1] = 1;
*v0 = v1;
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

original_code:
struct evg_opencl_context_t *evg_opencl_context_create()
{
 struct evg_opencl_context_t *context;
 context = (mhandle_calloc(1, sizeof(struct evg_opencl_context_t), "opencl-context.c" ":" "35"));
 if (!context)
  fatal("%s: out of memory", __FUNCTION__);
 context->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo,
  evg_opencl_object_context);
 context->ref_count = 1;
 evg_opencl_repo_add_object(evg_emu->opencl_repo, context);
 return context;
}

variable_types: struct evg_opencl_context_t { unsigned int id; int ref_count; unsigned int platform_id; unsigned int device_id; } *


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

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

original_code:
void evg_opencl_context_free(struct evg_opencl_context_t *context)
{
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, context);
 (mhandle_free(context, "opencl-context.c" ":" "54"));
}

user_defined_types: struct evg_opencl_context_t { unsigned int id; int ref_count; unsigned int platform_id; unsigned int device_id; }


decompiled_code:
__int64 __fastcall evg_opencl_context_get_info(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
int *v6; // rcx
int v8; // [rsp+Ch] [rbp-Ch] BYREF

v8 = 1;
if ( (_DWORD)a2 == 4225 )
{
v6 = (int *)(a1 + 12);
}
else
{
if ( (_DWORD)a2 != 4227 )
{
fatal(
"opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
a2,
evg_err_opencl_param_note);
_assert_fail("info", "opencl-context.c", 0x56u, "evg_opencl_context_get_info");
}
v6 = &v8;
}
if ( !a4 || a5 <= 3 )
return 4LL;
mem_write(a3, a4, 4LL, v6);
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
int *v6; // rcx
int v8; // [rsp+Ch] [rbp-Ch] BYREF

v8 = 1;
if ( (_DWORD)a2 == 4225 )
{
v6 = (int *)(a1 + 12);
}
else
{
if ( (_DWORD)a2 != 4227 )
{
fatal(
"opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
a2,
evg_err_opencl_param_note);
_assert_fail("info", "opencl-context.c", 0x56u, "evg_opencl_context_get_info");
}
v6 = &v8;
}
if ( !a4 || a5 <= 3 )
return 4LL;
mem_write(a3, a4, 4LL, v6);
return 4LL;
}

original_code:
uint32_t evg_opencl_context_get_info(struct evg_opencl_context_t *context, uint32_t name, struct mem_t *mem, uint32_t addr, uint32_t size)
{
 uint32_t num_devices = 1;
 uint32_t size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1081:
  size_ret = 4;
  info = &context->device_id;
  break;
 case 0x1083:
  size_ret = 4;
  info = &num_devices;
  break;
 case 0x1080:
 case 0x1082:
 default:
  fatal("opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-context.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int evg_opencl_context_get_info(struct evg_opencl_context_t *context, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 unsigned int num_devices = 1;
 unsigned int size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1081:
  size_ret = 4;
  info = &context->device_id;
  break;
 case 0x1083:
  size_ret = 4;
  info = &num_devices;
  break;
 case 0x1080:
 case 0x1082:
 default:
  fatal("opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-context.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

variable_types:
name
unsigned int

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

variable_types:
addr
unsigned int

variable_types:
size
unsigned int

variable_types:
info
void *

return_type: unsigned int

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

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


decompiled_code:
__int64 __fastcall evg_opencl_context_set_properties(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // ebx
__int64 result; // rax
__int64 v5; // rax
unsigned int v6; // [rsp+0h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+4h] [rbp-1Ch] BYREF

if ( a3 )
{
v3 = a3;
do
{
while ( 1 )
{
mem_read(a2, v3, 4LL, &v6);
result = v6;
if ( !v6 )
return result;
mem_read(a2, v3 + 4, 4LL, v7);
v3 += 8;
if ( v6 == 4228 )
break;
result = fatal("opencl_context_read_properties: invalid property (0x%x)\n", v6);
LABEL_4:
if ( !v3 )
return result;
}
v5 = evg_emu;
*(_DWORD *)(a1 + 8) = v7[0];
result = evg_opencl_repo_get_object(*(_QWORD *)(v5 + 8), 1LL);
if ( !evg_opencl_debug_category )
goto LABEL_4;
result = _debug(evg_opencl_debug_category, " property CL_CONTEXT_PLATFORM assigned: 0x%x\n", v7[0]);
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // ebx
__int64 result; // rax
__int64 v5; // rax
unsigned int v6; // [rsp+0h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+4h] [rbp-1Ch] BYREF

if ( a3 )
{
v3 = a3;
do
{
while ( 1 )
{
mem_read(a2, v3, 4LL, &v6);
result = v6;
if ( !v6 )
return result;
mem_read(a2, v3 + 4, 4LL, v7);
v3 += 8;
if ( v6 == 4228 )
break;
result = fatal("opencl_context_read_properties: invalid property (0x%x)\n", v6);
LABEL_4:
if ( !v3 )
return result;
}
v5 = evg_emu;
*(_DWORD *)(a1 + 8) = v7[0];
result = evg_opencl_repo_get_object(*(_QWORD *)(v5 + 8), 1LL);
if ( !evg_opencl_debug_category )
goto LABEL_4;
result = _debug(evg_opencl_debug_category, " property CL_CONTEXT_PLATFORM assigned: 0x%x\n", v7[0]);
}
while ( v3 );
}
return result;
}

original_code:
void evg_opencl_context_set_properties(struct evg_opencl_context_t *context,
  struct mem_t *mem, unsigned int addr)
{
 unsigned int property;
 unsigned int value;
 while (addr)
 {
  mem_read(mem, addr, 4, &property);
  if (!property)
   break;
  mem_read(mem, addr + 4, 4, &value);
  addr += 8;
  switch (property)
  {
  case 0x1084:
   context->platform_id = value;
   evg_opencl_repo_get_object(evg_emu->opencl_repo, evg_opencl_object_platform, value);
   ((evg_opencl_debug_category) ? __debug((evg_opencl_debug_category), "    property CL_CONTEXT_PLATFORM assigned: 0x%x\n", value) : (void) 0);
   break;
  default:
   fatal("opencl_context_read_properties: invalid property (0x%x)\n", property);
  }
 }
}

variable_types:
property
unsigned int

variable_types:
value
unsigned int

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


original_code:
struct net_msg_t *net_msg_create(struct net_t *net, struct net_node_t *src_node,
 struct net_node_t *dst_node, int size)
{
 struct net_msg_t *msg;
 msg = (mhandle_calloc(1, sizeof(struct net_msg_t), "message.c" ":" "33"));
 if (!msg)
  fatal("%s: out of memory", __FUNCTION__);
 msg->net = net;
 msg->src_node = src_node;
 msg->dst_node = dst_node;
 msg->size = size;
 msg->id = ++net->msg_id_counter;
 msg->send_cycle = esim_cycle;
 if (size < 1)
  panic("%s: bad size", __FUNCTION__);
 return msg;
}

variable_types:
net
struct net_t *

variable_types: size int

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

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: 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_msg_free(__int64 a1)
{
return mhandle_free(a1, "message.c:54");
}

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

original_code:
void net_msg_free(struct net_msg_t *msg)
{
 (mhandle_free(msg, "message.c" ":" "54"));
}

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

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 __fastcall net_stack_create(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // r12
__int64 result; // rax

v4 = mhandle_calloc(1LL, 32LL, "message.c:70");
if ( !v4 )
fatal("%s: out of memory", "net_stack_create");
*(_QWORD *)v4 = a1;
result = v4;
*(_DWORD *)(v4 + 16) = a2;
*(_QWORD *)(v4 + 24) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // r12
__int64 result; // rax

v4 = mhandle_calloc(1LL, 32LL, "message.c:70");
if ( !v4 )
fatal("%s: out of memory", "net_stack_create");
*(_QWORD *)v4 = a1;
result = v4;
*(_DWORD *)(v4 + 16) = a2;
*(_QWORD *)(v4 + 24) = a3;
return result;
}

original_code:
struct net_stack_t *net_stack_create(struct net_t *net,
 int retevent, void *retstack)
{
 struct net_stack_t *stack;
 stack = (mhandle_calloc(1, sizeof(struct net_stack_t), "message.c" ":" "70"));
 if (!stack)
  fatal("%s: out of memory", __FUNCTION__);
 stack->net = net;
 stack->ret_event = retevent;
 stack->ret_stack = retstack;
 return stack;
}

variable_types: retevent int

variable_types:
retstack
void *

variable_types: struct net_stack_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t { struct net_t *net; char *name; struct net_node_t *src_node; struct net_node_t *dst_node; struct net_buffer_t *dst_buffer; struct net_buffer_t *src_buffer; int bandwidth; long long busy; int virtual_channel; long long sched_when; struct net_buffer_t *sched_buffer; long long busy_cycles; long long transferred_bytes; long long transferred_msgs; } *link; struct list_t *msg_list; long long sched_when; struct net_buffer_t *sched_buffer; struct linked_list_t { 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; struct net_msg_t *msg; int ret_event; struct net_stack_t *ret_stack; } *

user_defined_types: struct net_stack_t { struct net_t *net; struct net_msg_t *msg; int ret_event; struct net_stack_t *ret_stack; }


decompiled_code:
__int64 __fastcall net_stack_return(__int64 a1)
{
__int64 v1; // r12
unsigned int v2; // ebp

v1 = *(_QWORD *)(a1 + 24);
v2 = *(_DWORD *)(a1 + 16);
mhandle_free(a1, "message.c:89");
return esim_schedule_event(v2, v1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // r12
unsigned int v2; // ebp

v1 = *(_QWORD *)(a1 + 24);
v2 = *(_DWORD *)(a1 + 16);
mhandle_free(a1, "message.c:89");
return esim_schedule_event(v2, v1, 0LL);
}

original_code:
void net_stack_return(struct net_stack_t *stack)
{
 int retevent = stack->ret_event;
 struct net_stack_t *retstack = stack->ret_stack;
 (mhandle_free(stack, "message.c" ":" "89"));
 esim_schedule_event(retevent, retstack, 0);
}


original_code:
void net_event_handler(int event, void *data)
{
 struct net_stack_t *stack = data;
 struct net_t *net = stack->net;
 struct net_routing_table_t *routing_table = net->routing_table;
 struct net_msg_t *msg = stack->msg;
 struct net_node_t *src_node = msg->src_node;
 struct net_node_t *dst_node = msg->dst_node;
 struct net_node_t *node = msg->node;
 struct net_buffer_t *buffer = msg->buffer;
 if (event == EV_NET_SEND)
 {
  struct net_routing_table_entry_t *entry;
  struct net_buffer_t *output_buffer;
  ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"send\" " "net=\"%s\" " "msg=%lld " "size=%d " "src=\"%s\" " "dst=\"%s\"\n", net->name, msg->id, msg->size, src_node->name, dst_node->name) : (void) 0);
  entry = net_routing_table_lookup(routing_table, src_node, dst_node);
  output_buffer = entry->output_buffer;
  if (!output_buffer)
   fatal("%s: no route from %s to %s.\n%s", net->name, src_node->name,
    dst_node->name, err_net_no_route);
  if (output_buffer->write_busy >= esim_cycle)
   panic("%s: output buffer busy.\n%s", __FUNCTION__, err_net_can_send);
  if (msg->size > output_buffer->size)
   panic("%s: message does not fit in buffer.\n%s", __FUNCTION__, err_net_can_send);
  if (output_buffer->count + msg->size > output_buffer->size)
   panic("%s: output buffer full.\n%s", __FUNCTION__, err_net_can_send);
  net_buffer_insert(output_buffer, msg);
  output_buffer->write_busy = esim_cycle;
  msg->node = src_node;
  msg->buffer = output_buffer;
  msg->busy = esim_cycle;
  esim_schedule_event(EV_NET_OUTPUT_BUFFER, stack, 1);
 }
 else if (event == EV_NET_OUTPUT_BUFFER)
 {
  struct net_link_t *link;
  struct net_buffer_t *input_buffer;
  int lat;
  ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"obuf\" " "net=\"%s\" " "msg=%lld " "node=\"%s\" " "buf=\"%s\"\n", net->name, msg->id, node->name, buffer->name) : (void) 0);
  ((void) sizeof ((list_count(buffer->msg_list)) ? 1 : 0), __extension__ ({ if (list_count(buffer->msg_list)) ; else __assert_fail ("list_count(buffer->msg_list)", "message.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  if (list_get(buffer->msg_list, 0) != msg)
  {
   net_buffer_wait(buffer, event, stack);
   return;
  }
  if (buffer->read_busy >= esim_cycle)
  {
   esim_schedule_event(event, stack, buffer->read_busy - esim_cycle + 1);
   return;
  }
  link = buffer->link;
  if (link->busy >= esim_cycle)
  {
   esim_schedule_event(event, stack, link->busy - esim_cycle + 1);
   return;
  }
  if (link->virtual_channel > 1)
  {
   struct net_buffer_t *temp_buffer;
   temp_buffer = net_link_arbitrator_vc(link, node);
   if (temp_buffer != buffer)
   {
    ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"arbitrator stall\" " "net=\"%s\" " "msg=%lld " "why=\"sched\"\n", net->name, msg->id) : (void) 0);
    esim_schedule_event(event, stack, 1);
    return;
   }
  }
  ((void) sizeof ((buffer == link->src_buffer) ? 1 : 0), __extension__ ({ if (buffer == link->src_buffer) ; else __assert_fail ("buffer == link->src_buffer", "message.c", 211, __extension__ __PRETTY_FUNCTION__); }));
  input_buffer = link->dst_buffer;
  if (input_buffer->write_busy >= esim_cycle)
  {
   esim_schedule_event(event, stack, input_buffer->write_busy - esim_cycle + 1);
   return;
  }
  if (msg->size > input_buffer->size)
   fatal("%s: message does not fit in buffer.\n%s",
    net->name, err_net_large_message);
  if (input_buffer->count + msg->size > input_buffer->size)
  {
   net_buffer_wait(input_buffer, event, stack);
   return;
  }
  lat = (msg->size - 1) / link->bandwidth + 1;
  ((void) sizeof ((lat > 0) ? 1 : 0), __extension__ ({ if (lat > 0) ; else __assert_fail ("lat > 0", "message.c", 231, __extension__ __PRETTY_FUNCTION__); }));
  buffer->read_busy = esim_cycle + lat - 1;
  link->busy = esim_cycle + lat - 1;
  input_buffer->write_busy = esim_cycle + lat - 1;
  ((void) sizeof ((msg->busy < esim_cycle) ? 1 : 0), __extension__ ({ if (msg->busy < esim_cycle) ; else __assert_fail ("msg->busy < esim_cycle", "message.c", 237, __extension__ __PRETTY_FUNCTION__); }));
  net_buffer_extract(buffer, msg);
  net_buffer_insert(input_buffer, msg);
  msg->node = input_buffer->node;
  msg->buffer = input_buffer;
  msg->busy = esim_cycle + lat - 1;
  link->busy_cycles += lat;
  link->transferred_bytes += msg->size;
  link->transferred_msgs++;
  node->bytes_sent += msg->size;
  node->msgs_sent++;
  input_buffer->node->bytes_received += msg->size;
  input_buffer->node->msgs_received++;
  esim_schedule_event(EV_NET_INPUT_BUFFER, stack, lat);
 }
 else if (event == EV_NET_INPUT_BUFFER)
 {
  struct net_routing_table_entry_t *entry;
  struct net_buffer_t *output_buffer;
  int lat;
  ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"ibuf\" " "net=\"%s\" " "msg=%lld " "node=\"%s\" " "buf=\"%s\"\n", net->name, msg->id, node->name, buffer->name) : (void) 0);
  ((void) sizeof ((list_count(buffer->msg_list)) ? 1 : 0), __extension__ ({ if (list_count(buffer->msg_list)) ; else __assert_fail ("list_count(buffer->msg_list)", "message.c", 276, __extension__ __PRETTY_FUNCTION__); }));
  if (list_get(buffer->msg_list, 0) != msg)
  {
   ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"stall\" " "net=\"%s\" " "msg=%lld " "why=\"not-head\"\n", net->name, msg->id) : (void) 0);
   net_buffer_wait(buffer, event, stack);
   return;
  }
  if (node == msg->dst_node)
  {
   esim_schedule_event(EV_NET_RECEIVE, stack, 0);
   return;
  }
  if (buffer->read_busy >= esim_cycle)
  {
   ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"stall\" " "net=\"%s\" " "msg=%lld " "why=\"src-busy\"\n", net->name, msg->id) : (void) 0);
   esim_schedule_event(event, stack, buffer->read_busy - esim_cycle + 1);
   return;
  }
  entry = net_routing_table_lookup(routing_table, node, dst_node);
  output_buffer = entry->output_buffer;
  if (!output_buffer)
   fatal("%s: no route from %s to %s.\n%s", net->name,
    node->name, dst_node->name, err_net_no_route);
  if (output_buffer->write_busy >= esim_cycle)
  {
   ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"stall\" " "net=\"%s\" " "msg=%lld " "why=\"dst-busy\"\n", net->name, msg->id) : (void) 0);
   esim_schedule_event(event, stack, output_buffer->write_busy - esim_cycle + 1);
   return;
  }
  if (msg->size > output_buffer->size)
   fatal("%s: message does not fit in buffer.\n%s",
    net->name, err_net_large_message);
  if (output_buffer->count + msg->size > output_buffer->size)
  {
   ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"stall\" " "net=\"%s\" " "msg=%lld " "why=\"dst-full\"\n", net->name, msg->id) : (void) 0);
   net_buffer_wait(output_buffer, event, stack);
   return;
  }
  if (net_node_schedule(node, output_buffer) != buffer)
  {
   ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"stall\" " "net=\"%s\" " "msg=%lld " "why=\"sched\"\n", net->name, msg->id) : (void) 0);
   esim_schedule_event(event, stack, 1);
   return;
  }
  ((void) sizeof ((node->kind != net_node_end) ? 1 : 0), __extension__ ({ if (node->kind != net_node_end) ; else __assert_fail ("node->kind != net_node_end", "message.c", 364, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((node->bandwidth > 0) ? 1 : 0), __extension__ ({ if (node->bandwidth > 0) ; else __assert_fail ("node->bandwidth > 0", "message.c", 365, __extension__ __PRETTY_FUNCTION__); }));
  lat = (msg->size - 1) / node->bandwidth + 1;
  ((void) sizeof ((lat > 0) ? 1 : 0), __extension__ ({ if (lat > 0) ; else __assert_fail ("lat > 0", "message.c", 367, __extension__ __PRETTY_FUNCTION__); }));
  buffer->read_busy = esim_cycle + lat - 1;
  output_buffer->write_busy = esim_cycle + lat - 1;
  ((void) sizeof ((msg->busy < esim_cycle) ? 1 : 0), __extension__ ({ if (msg->busy < esim_cycle) ; else __assert_fail ("msg->busy < esim_cycle", "message.c", 372, __extension__ __PRETTY_FUNCTION__); }));
  net_buffer_extract(buffer, msg);
  net_buffer_insert(output_buffer, msg);
  msg->buffer = output_buffer;
  msg->busy = esim_cycle + lat - 1;
  esim_schedule_event(EV_NET_OUTPUT_BUFFER, stack, lat);
 }
 else if (event == EV_NET_RECEIVE)
 {
  ((net_debug_category) ? __debug((net_debug_category), "msg " "a=\"receive\" " "net=\"%s\" " "msg=%lld " "node=\"%s\"\n", net->name, msg->id, dst_node->name) : (void) 0);
  net->transfers++;
  net->lat_acc += esim_cycle - msg->send_cycle;
  net->msg_size_acc += msg->size;
  if (stack->ret_event == ESIM_EV_NONE)
   net_receive(net, node, msg);
  net_stack_return(stack);
 }
 else
 {
  panic("%s: unknown event", __FUNCTION__);
 }
}

variable_types: event int

variable_types:
data
void *

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_routing_table_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 *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 { 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; } *src_node; struct net_node_t *dst_node; void *data; struct net_node_t *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; } *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; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t *next_node; struct net_buffer_t *output_buffer; } *entries; int has_cycle; } *

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

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

variable_types: struct net_routing_table_entry_t { int cost; 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 *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 { 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; } *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; } *next_node; struct net_buffer_t *output_buffer; } *

variable_types: struct net_link_t { struct net_t { char *name; long long msg_id_counter; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *node_list; int node_count; int end_node_count; struct list_t *link_list; struct net_routing_table_t { struct net_t *net; int dim; struct net_routing_table_entry_t { int cost; struct net_node_t { struct net_t *net; enum net_node_kind_t { net_node_invalid=0, net_node_end=1, net_node_switch=2, net_node_bus=3 } kind; int index; char *name; void *user_data; int bandwidth; long long bus_busy; int input_buffer_size; int output_buffer_size; struct list_t *input_buffer_list; struct list_t *output_buffer_list; long long bytes_received; long long msgs_received; long long bytes_sent; long long msgs_sent; } *next_node; struct net_buffer_t { struct net_t *net; struct net_node_t *node; char *name; int index; int size; int count; long long read_busy; long long write_busy; struct net_link_t *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; 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; } *

variable_types: lat int


decompiled_code:
void __fastcall trace_init(const char *a1)
{
__int64 v1; // rbp

if ( a1 && *a1 )
{
trace_file = gzopen(a1, &unk_380);
if ( !trace_file )
fatal("%s: cannot open trace file", a1);
trace_category_list = list_create();
v1 = mhandle_calloc(1LL, 4LL, "trace.c:67");
if ( !v1 )
fatal("%s: out of memory", "trace_init");
list_add(trace_category_list, v1);
}
}

canonical_decompiled_code:
void __fastcall func0(const char *a1)
{
__int64 v1; // rbp

if ( a1 && *a1 )
{
trace_file = gzopen(a1, &unk_380);
if ( !trace_file )
fatal("%s: cannot open trace file", a1);
trace_category_list = list_create();
v1 = mhandle_calloc(1LL, 4LL, "trace.c:67");
if ( !v1 )
fatal("%s: out of memory", "trace_init");
list_add(trace_category_list, v1);
}
}

original_code:
void trace_init(char *file_name)
{
 struct trace_category_t *c;
 if (!file_name || !*file_name)
  return;
 trace_file = gzopen(file_name, "wt");
 if (!trace_file)
  fatal("%s: cannot open trace file", file_name);
 trace_category_list = list_create();
 c = (mhandle_calloc(1, sizeof(struct trace_category_t), "trace.c" ":" "67"));
 if (!c)
  fatal("%s: out of memory", __FUNCTION__);
 list_add(trace_category_list, c);
}

variable_types: struct trace_category_t { enum trace_status_t { trace_status_invalid=0, trace_status_on=1, trace_status_off=2 } status; } *

user_defined_types: struct trace_category_t { enum trace_status_t status; }


decompiled_code:
void trace_done()
{
__int64 i; // rdi
__int64 v1; // rax

if ( trace_file )
{
gzclose();
for ( i = trace_category_list; *(_DWORD *)trace_category_list; i = trace_category_list )
{
v1 = list_remove_at(i, 0LL);
mhandle_free(v1, "trace.c:85");
}
list_free();
}
}

canonical_decompiled_code:
void func1()
{
__int64 i; // rdi
__int64 v1; // rax

if ( trace_file )
{
gzclose();
for ( i = trace_category_list; *(_DWORD *)trace_category_list; i = trace_category_list )
{
v1 = list_remove_at(i, 0LL);
mhandle_free(v1, "trace.c:85");
}
list_free();
}
}

original_code:
void trace_done(void)
{
 if (!trace_file)
  return;
 gzclose(trace_file);
 while (trace_category_list->count)
  (mhandle_free(list_remove_at(trace_category_list, 0), "trace.c" ":" "85"));
 list_free(trace_category_list);
}

canonical_original_code:
void trace_done()
{
 if (!trace_file)
  return;
 gzclose(trace_file);
 while (trace_category_list->count)
  (mhandle_free(list_remove_at(trace_category_list, 0), "trace.c" ":" "85"));
 list_free(trace_category_list);
}


decompiled_code:
__int64 trace_new_category()
{
_DWORD *v0; // rbp

if ( !trace_file )
return 0LL;
v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "trace.c:100");
if ( !v0 )
fatal("%s: out of memory", "trace_new_category");
*v0 = 1;
list_add(trace_category_list, v0);
return (unsigned int)list_count(trace_category_list) - 1;
}

canonical_decompiled_code:
__int64 func2()
{
_DWORD *v0; // rbp

if ( !trace_file )
return 0LL;
v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "trace.c:100");
if ( !v0 )
fatal("%s: out of memory", "trace_new_category");
*v0 = 1;
list_add(trace_category_list, v0);
return (unsigned int)list_count(trace_category_list) - 1;
}

original_code:
int trace_new_category(void)
{
 struct trace_category_t *c;
 if (!trace_file)
  return 0;
 c = (mhandle_calloc(1, sizeof(struct trace_category_t), "trace.c" ":" "100"));
 if (!c)
  fatal("%s: out of memory", __FUNCTION__);
 c->status = trace_status_on;
 list_add(trace_category_list, c);
 return list_count(trace_category_list) - 1;
}

canonical_original_code:
int trace_new_category()
{
 struct trace_category_t *c;
 if (!trace_file)
  return 0;
 c = (mhandle_calloc(1, sizeof(struct trace_category_t), "trace.c" ":" "100"));
 if (!c)
  fatal("%s: out of memory", __FUNCTION__);
 c->status = trace_status_on;
 list_add(trace_category_list, c);
 return list_count(trace_category_list) - 1;
}

return_type: int

user_defined_types: enum trace_status_t { trace_status_invalid=0, trace_status_on=1, trace_status_off=2 }


decompiled_code:
__int64 arm_cpu_run()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
int arm_cpu_run(void)
{
 return 0;
}

canonical_original_code:
int arm_cpu_run()
{
 return 0;
}


decompiled_code:
__int64 arm_regs_create()
{
__int64 v0; // r12

v0 = mhandle_calloc(1LL, 404LL, "regs.c:26");
if ( !v0 )
fatal("%s: out of memory", "arm_regs_create");
*(_BYTE *)(v0 + 64) = *(_BYTE *)(v0 + 64) & 0xE0 | 0x10;
return v0;
}

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

v0 = mhandle_calloc(1LL, 404LL, "regs.c:26");
if ( !v0 )
fatal("%s: out of memory", "arm_regs_create");
*(_BYTE *)(v0 + 64) = *(_BYTE *)(v0 + 64) & 0xE0 | 0x10;
return v0;
}

original_code:
struct arm_regs_t *arm_regs_create()
{
 struct arm_regs_t *regs;
 regs = (mhandle_calloc(1, sizeof(struct arm_regs_t), "regs.c" ":" "26"));
 if(!regs)
  fatal("%s: out of memory", __FUNCTION__);
 regs->cpsr.mode = 0x10;
 return regs;
}

variable_types: struct arm_regs_t { unsigned int r0; unsigned int r4; unsigned int sl; struct arm_cpsr_reg_t { unsigned int mode; unsigned int thumb; unsigned int fiq; unsigned int irq; unsigned int _reserved0; unsigned int jaz; unsigned int _reserved1; unsigned int q; unsigned int v; unsigned int C; unsigned int z; unsigned int n; } cpsr; struct arm_cpsr_reg_t spsr; struct arm_coproc_regs_t { unsigned int c0_cpuid; unsigned int c0_cachetype; unsigned int c0_ccsid[16]; unsigned int c0_clid; unsigned int c0_cssel; unsigned int c0_c1[8]; unsigned int c0_c2[8]; unsigned int c1_sys; unsigned int c1_coproc; unsigned int c1_xscaleauxcr; unsigned int c1_scr; unsigned int c2_base0; unsigned int c2_base1; unsigned int c2_control; unsigned int c2_mask; unsigned int c2_base_mask; unsigned int c2_data; unsigned int c2_insn; unsigned int c3; unsigned int c5_insn; unsigned int c5_data; unsigned int c6_region[8]; unsigned int c6_insn; unsigned int c6_data; unsigned int c7_par; unsigned int c9_insn; unsigned int c9_data; unsigned int c9_pmcr; unsigned int c9_pmcnten; unsigned int c9_pmovsr; unsigned int c9_pmxevtyper; unsigned int c9_pmuserenr; unsigned int c9_pminten; unsigned int c13_fcse; unsigned int c13_context; unsigned int c13_tls1; unsigned int c13_tls2; unsigned int c13_tls3; unsigned int c15_cpar; unsigned int c15_ticonfig; unsigned int c15_i_max; unsigned int c15_i_min; unsigned int c15_threadid; unsigned int c15_config_base_address; unsigned int c15_diagnostic; unsigned int c15_power_diagnostic; unsigned int c15_power_control; } cp15; } *

user_defined_types: struct arm_regs_t { unsigned int r0; unsigned int r4; unsigned int sl; struct arm_cpsr_reg_t cpsr; struct arm_cpsr_reg_t spsr; struct arm_coproc_regs_t cp15; }


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

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

original_code:
void arm_regs_free(struct arm_regs_t *regs)
{
 (mhandle_free(regs, "regs.c" ":" "37"));
}

user_defined_types: struct arm_cpsr_reg_t { unsigned int mode; unsigned int thumb; unsigned int fiq; unsigned int irq; unsigned int _reserved0; unsigned int jaz; unsigned int _reserved1; unsigned int q; unsigned int v; unsigned int C; unsigned int z; unsigned int n; }

user_defined_types: struct arm_coproc_regs_t { unsigned int c0_cpuid; unsigned int c0_cachetype; unsigned int c0_ccsid[16]; unsigned int c0_clid; unsigned int c0_cssel; unsigned int c0_c1[8]; unsigned int c0_c2[8]; unsigned int c1_sys; unsigned int c1_coproc; unsigned int c1_xscaleauxcr; unsigned int c1_scr; unsigned int c2_base0; unsigned int c2_base1; unsigned int c2_control; unsigned int c2_mask; unsigned int c2_base_mask; unsigned int c2_data; unsigned int c2_insn; unsigned int c3; unsigned int c5_insn; unsigned int c5_data; unsigned int c6_region[8]; unsigned int c6_insn; unsigned int c6_data; unsigned int c7_par; unsigned int c9_insn; unsigned int c9_data; unsigned int c9_pmcr; unsigned int c9_pmcnten; unsigned int c9_pmovsr; unsigned int c9_pmxevtyper; unsigned int c9_pmuserenr; unsigned int c9_pminten; unsigned int c13_fcse; unsigned int c13_context; unsigned int c13_tls1; unsigned int c13_tls2; unsigned int c13_tls3; unsigned int c15_cpar; unsigned int c15_ticonfig; unsigned int c15_i_max; unsigned int c15_i_min; unsigned int c15_threadid; unsigned int c15_config_base_address; unsigned int c15_diagnostic; unsigned int c15_power_diagnostic; unsigned int c15_power_control; }


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

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

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

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

original_code:
void arm_regs_copy(struct arm_regs_t *dst, struct arm_regs_t *src)
{
 memcpy(dst, src, sizeof(struct arm_regs_t));
}

variable_types:
src
struct arm_regs_t *


decompiled_code:
_DWORD *si_opencl_context_create()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 16LL, "opencl-context.c:35");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_context_create");
v1 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 3LL);
v0[1] = 1;
*v0 = v1;
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

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

v0 = (_DWORD *)mhandle_calloc(1LL, 16LL, "opencl-context.c:35");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_context_create");
v1 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 3LL);
v0[1] = 1;
*v0 = v1;
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

original_code:
struct si_opencl_context_t *si_opencl_context_create()
{
 struct si_opencl_context_t *context;
 context = (mhandle_calloc(1, sizeof(struct si_opencl_context_t), "opencl-context.c" ":" "35"));
 if (!context)
  fatal("%s: out of memory", __FUNCTION__);
 context->id = si_opencl_repo_new_object_id(si_emu->opencl_repo,
  si_opencl_object_context);
 context->ref_count = 1;
 si_opencl_repo_add_object(si_emu->opencl_repo, context);
 return context;
}

variable_types: struct si_opencl_context_t { unsigned int id; int ref_count; unsigned int platform_id; unsigned int device_id; } *


decompiled_code:
__int64 __fastcall si_opencl_context_free(__int64 a1)
{
si_opencl_repo_remove_object(*(_QWORD *)(si_emu + 8LL), a1);
return mhandle_free(a1, "opencl-context.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-context.c:54");
}

original_code:
void si_opencl_context_free(struct si_opencl_context_t *context)
{
 si_opencl_repo_remove_object(si_emu->opencl_repo, context);
 (mhandle_free(context, "opencl-context.c" ":" "54"));
}

user_defined_types: struct si_opencl_context_t { unsigned int id; int ref_count; unsigned int platform_id; unsigned int device_id; }


decompiled_code:
__int64 __fastcall si_opencl_context_get_info(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
int *v6; // rcx
int v8; // [rsp+Ch] [rbp-Ch] BYREF

v8 = 1;
if ( (_DWORD)a2 == 4225 )
{
v6 = (int *)(a1 + 12);
}
else
{
if ( (_DWORD)a2 != 4227 )
{
fatal(
"opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
a2,
si_err_opencl_param_note);
_assert_fail("info", "opencl-context.c", 0x56u, "si_opencl_context_get_info");
}
v6 = &v8;
}
if ( !a4 || a5 <= 3 )
return 4LL;
mem_write(a3, a4, 4LL, v6);
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
int *v6; // rcx
int v8; // [rsp+Ch] [rbp-Ch] BYREF

v8 = 1;
if ( (_DWORD)a2 == 4225 )
{
v6 = (int *)(a1 + 12);
}
else
{
if ( (_DWORD)a2 != 4227 )
{
fatal(
"opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
a2,
si_err_opencl_param_note);
_assert_fail("info", "opencl-context.c", 0x56u, "si_opencl_context_get_info");
}
v6 = &v8;
}
if ( !a4 || a5 <= 3 )
return 4LL;
mem_write(a3, a4, 4LL, v6);
return 4LL;
}

original_code:
uint32_t si_opencl_context_get_info(struct si_opencl_context_t *context, uint32_t name, struct mem_t *mem, uint32_t addr, uint32_t size)
{
 uint32_t num_devices = 1;
 uint32_t size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1081:
  size_ret = 4;
  info = &context->device_id;
  break;
 case 0x1083:
  size_ret = 4;
  info = &num_devices;
  break;
 case 0x1080:
 case 0x1082:
 default:
  fatal("opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, si_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-context.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int si_opencl_context_get_info(struct si_opencl_context_t *context, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 unsigned int num_devices = 1;
 unsigned int size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1081:
  size_ret = 4;
  info = &context->device_id;
  break;
 case 0x1083:
  size_ret = 4;
  info = &num_devices;
  break;
 case 0x1080:
 case 0x1082:
 default:
  fatal("opencl_context_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, si_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-context.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

variable_types:
name
unsigned int

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

variable_types:
addr
unsigned int

variable_types:
size
unsigned int

variable_types:
info
void *

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

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


decompiled_code:
__int64 __fastcall si_opencl_context_set_properties(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // ebx
__int64 result; // rax
__int64 v5; // rax
unsigned int v6; // [rsp+0h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+4h] [rbp-1Ch] BYREF

if ( a3 )
{
v3 = a3;
do
{
while ( 1 )
{
mem_read(a2, v3, 4LL, &v6);
result = v6;
if ( !v6 )
return result;
mem_read(a2, v3 + 4, 4LL, v7);
v3 += 8;
if ( v6 == 4228 )
break;
result = fatal("opencl_context_read_properties: invalid property (0x%x)\n", v6);
LABEL_4:
if ( !v3 )
return result;
}
v5 = si_emu;
*(_DWORD *)(a1 + 8) = v7[0];
result = si_opencl_repo_get_object(*(_QWORD *)(v5 + 8), 1LL);
if ( !si_opencl_debug_category )
goto LABEL_4;
result = _debug(si_opencl_debug_category, " property CL_CONTEXT_PLATFORM assigned: 0x%x\n", v7[0]);
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // ebx
__int64 result; // rax
__int64 v5; // rax
unsigned int v6; // [rsp+0h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+4h] [rbp-1Ch] BYREF

if ( a3 )
{
v3 = a3;
do
{
while ( 1 )
{
mem_read(a2, v3, 4LL, &v6);
result = v6;
if ( !v6 )
return result;
mem_read(a2, v3 + 4, 4LL, v7);
v3 += 8;
if ( v6 == 4228 )
break;
result = fatal("opencl_context_read_properties: invalid property (0x%x)\n", v6);
LABEL_4:
if ( !v3 )
return result;
}
v5 = si_emu;
*(_DWORD *)(a1 + 8) = v7[0];
result = si_opencl_repo_get_object(*(_QWORD *)(v5 + 8), 1LL);
if ( !si_opencl_debug_category )
goto LABEL_4;
result = _debug(si_opencl_debug_category, " property CL_CONTEXT_PLATFORM assigned: 0x%x\n", v7[0]);
}
while ( v3 );
}
return result;
}

original_code:
void si_opencl_context_set_properties(struct si_opencl_context_t *context, struct mem_t *mem, uint32_t addr)
{
 uint32_t property;
 uint32_t value;
 while (addr)
 {
  mem_read(mem, addr, 4, &property);
  if (!property)
   break;
  mem_read(mem, addr + 4, 4, &value);
  addr += 8;
  switch (property)
  {
  case 0x1084:
   context->platform_id = value;
   si_opencl_repo_get_object(si_emu->opencl_repo, si_opencl_object_platform, value);
   ((si_opencl_debug_category) ? __debug((si_opencl_debug_category), "    property CL_CONTEXT_PLATFORM assigned: 0x%x\n", value) : (void) 0);
   break;
  default:
   fatal("opencl_context_read_properties: invalid property (0x%x)\n", property);
  }
 }
}

canonical_original_code:
void si_opencl_context_set_properties(struct si_opencl_context_t *context, struct mem_t *mem, unsigned int addr)
{
 unsigned int property;
 unsigned int value;
 while (addr)
 {
  mem_read(mem, addr, 4, &property);
  if (!property)
   break;
  mem_read(mem, addr + 4, 4, &value);
  addr += 8;
  switch (property)
  {
  case 0x1084:
   context->platform_id = value;
   si_opencl_repo_get_object(si_emu->opencl_repo, si_opencl_object_platform, value);
   ((si_opencl_debug_category) ? __debug((si_opencl_debug_category), "    property CL_CONTEXT_PLATFORM assigned: 0x%x\n", value) : (void) 0);
   break;
  default:
   fatal("opencl_context_read_properties: invalid property (0x%x)\n", property);
  }
 }
}

variable_types:
property
unsigned int

variable_types:
value
unsigned int

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


decompiled_code:
__int64 __fastcall si_opencl_kernel_arg_create(char *src)
{
size_t v1; // rax
__int64 v2; // r12

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 41, "opencl-kernel.c:80");
if ( !v2 )
fatal("%s: out of memory", "si_opencl_kernel_arg_create");
strcpy((char *)(v2 + 40), src);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
size_t v1; // rax
__int64 v2; // r12

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 41, "opencl-kernel.c:80");
if ( !v2 )
fatal("%s: out of memory", "si_opencl_kernel_arg_create");
strcpy((char *)(v2 + 40), src);
return v2;
}

original_code:
struct si_opencl_kernel_arg_t *si_opencl_kernel_arg_create(char *name)
{
 struct si_opencl_kernel_arg_t *arg;
 arg = (mhandle_calloc(1, sizeof(struct si_opencl_kernel_arg_t) + strlen(name) + 1, "opencl-kernel.c" ":" "80"));
 if (!arg)
  fatal("%s: out of memory", __FUNCTION__);
 strcpy(arg->name, name);
 return arg;
}

variable_types:
name
char *

variable_types: struct si_opencl_kernel_arg_t { enum si_opencl_kernel_arg_kind_t { SI_OPENCL_KERNEL_ARG_KIND_VALUE=1, SI_OPENCL_KERNEL_ARG_KIND_POINTER=2, SI_OPENCL_KERNEL_ARG_KIND_IMAGE=3, SI_OPENCL_KERNEL_ARG_KIND_SAMPLER=4 } kind; enum si_opencl_mem_scope_t { SI_OPENCL_MEM_SCOPE_NONE=0, SI_OPENCL_MEM_SCOPE_GLOBAL=1, SI_OPENCL_MEM_SCOPE_LOCAL=2, SI_OPENCL_MEM_SCOPE_PRIVATE=3, SI_OPENCL_MEM_SCOPE_CONSTANT=4 } mem_scope; int uav; enum si_opencl_kernel_arg_access_type_t { SI_OPENCL_KERNEL_ARG_READ_ONLY=1, SI_OPENCL_KERNEL_ARG_WRITE_ONLY=2, SI_OPENCL_KERNEL_ARG_READ_WRITE=3 } access_type; int set; unsigned int size; union { unsigned int ptr; unsigned int value[4]; } data; char name[]; } *

user_defined_types: struct si_opencl_kernel_arg_t { enum si_opencl_kernel_arg_kind_t kind; enum si_opencl_mem_scope_t mem_scope; int uav; enum si_opencl_kernel_arg_access_type_t access_type; int set; unsigned int size; union { unsigned int ptr; unsigned int value[4]; } data; char name[]; }


decompiled_code:
__int64 __fastcall si_opencl_kernel_arg_free(__int64 a1)
{
return mhandle_free(a1, "opencl-kernel.c:94");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return mhandle_free(a1, "opencl-kernel.c:94");
}

original_code:
void si_opencl_kernel_arg_free(struct si_opencl_kernel_arg_t *arg)
{
 (mhandle_free(arg, "opencl-kernel.c" ":" "94"));
}

user_defined_types: enum si_opencl_kernel_arg_kind_t { SI_OPENCL_KERNEL_ARG_KIND_VALUE=1, SI_OPENCL_KERNEL_ARG_KIND_POINTER=2, SI_OPENCL_KERNEL_ARG_KIND_IMAGE=3, SI_OPENCL_KERNEL_ARG_KIND_SAMPLER=4 }

user_defined_types: enum si_opencl_mem_scope_t { SI_OPENCL_MEM_SCOPE_NONE=0, SI_OPENCL_MEM_SCOPE_GLOBAL=1, SI_OPENCL_MEM_SCOPE_LOCAL=2, SI_OPENCL_MEM_SCOPE_PRIVATE=3, SI_OPENCL_MEM_SCOPE_CONSTANT=4 }

user_defined_types: enum si_opencl_kernel_arg_access_type_t { SI_OPENCL_KERNEL_ARG_READ_ONLY=1, SI_OPENCL_KERNEL_ARG_WRITE_ONLY=2, SI_OPENCL_KERNEL_ARG_READ_WRITE=3 }


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

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

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

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

original_code:
struct evg_opencl_device_t *evg_opencl_device_create()
{
 struct evg_opencl_device_t *device;
 device = (mhandle_calloc(1, sizeof(struct evg_opencl_device_t), "opencl-device.c" ":" "35"));
 if (!device)
  fatal("%s: out of memory", __FUNCTION__);
 device->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo,
  evg_opencl_object_device);
 evg_opencl_repo_add_object(evg_emu->opencl_repo, device);
 return device;
}

variable_types: struct evg_opencl_device_t { unsigned int id; } *


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

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

original_code:
void evg_opencl_device_free(struct evg_opencl_device_t *device)
{
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, device);
 (mhandle_free(device, "opencl-device.c" ":" "53"));
}

user_defined_types: struct evg_opencl_device_t { unsigned int id; }


decompiled_code:
__int64 __fastcall evg_opencl_device_get_info(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
__int64 v5; // r9
unsigned int v6; // eax
__int64 v7; // rsi
int *v8; // rcx
unsigned int v9; // er12
int v11; // [rsp+Ch] [rbp-3Ch] BYREF
int v12; // [rsp+10h] [rbp-38h] BYREF
int v13; // [rsp+14h] [rbp-34h] BYREF
int v14; // [rsp+18h] [rbp-30h] BYREF
int v15; // [rsp+1Ch] [rbp-2Ch] BYREF
int v16; // [rsp+20h] [rbp-28h] BYREF
int v17; // [rsp+24h] [rbp-24h] BYREF
__int64 v18; // [rsp+28h] [rbp-20h] BYREF
__int64 v19; // [rsp+34h] [rbp-14h] BYREF
int v20; // [rsp+3Ch] [rbp-Ch]

v5 = a2;
v18 = 0x80000000LL;
v6 = a2 - 4098;
v11 = 1;
v12 = 0x10000;
v13 = 3;
v14 = 1;
v15 = 0x8000;
v16 = 850;
v17 = 1;
v7 = a4;
switch ( v6 )
{
case 0u:
v8 = &v11;
v9 = 4;
break;
case 1u:
v8 = &v13;
v9 = 4;
break;
case 2u:
v8 = &v12;
v9 = 4;
break;
case 3u:
v20 = 256;
v8 = (int *)&v19;
v9 = 12;
v19 = 0x10000000100LL;
break;
case 0xAu:
v8 = &v16;
v9 = 4;
break;
case 0x14u:
v8 = &v17;
v9 = 4;
break;
case 0x1Du:
v8 = (int *)&v18;
v9 = 8;
break;
case 0x20u:
v8 = &v14;
v9 = 4;
break;
case 0x21u:
v8 = &v15;
v9 = 4;
break;
case 0x29u:
v8 = (int *)"Multi2Sim Virtual GPU Device";
v9 = 29;
break;
case 0x2Au:
v8 = (int *)"www.multi2sim.org";
v9 = 18;
break;
case 0x2Bu:
v8 = (int *)"4.0";
v9 = 4;
break;
case 0x2Du:
v8 = (int *)"OpenCL 1.1 ATI-Stream-v2.3 (451)";
v9 = 33;
break;
case 0x2Eu:
v8 = (int *)"cl_amd_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_b"
"ase_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_gl_sharing cl_ext"
"_device_fission cl_amd_device_attribute_query cl_amd_media_ops cl_amd_popcnt cl_amd_printf ";
v9 = 296;
break;
default:
fatal(
"opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
(unsigned int)v5,
evg_err_opencl_note);
_assert_fail("info", "opencl-device.c", 0xA4u, "evg_opencl_device_get_info");
}
if ( (_DWORD)v7 && v9 <= (unsigned int)a5 )
mem_write(a3, v7, v9, v8, a5, v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5)
{
__int64 v5; // r9
unsigned int v6; // eax
__int64 v7; // rsi
int *v8; // rcx
unsigned int v9; // er12
int v11; // [rsp+Ch] [rbp-3Ch] BYREF
int v12; // [rsp+10h] [rbp-38h] BYREF
int v13; // [rsp+14h] [rbp-34h] BYREF
int v14; // [rsp+18h] [rbp-30h] BYREF
int v15; // [rsp+1Ch] [rbp-2Ch] BYREF
int v16; // [rsp+20h] [rbp-28h] BYREF
int v17; // [rsp+24h] [rbp-24h] BYREF
__int64 v18; // [rsp+28h] [rbp-20h] BYREF
__int64 v19; // [rsp+34h] [rbp-14h] BYREF
int v20; // [rsp+3Ch] [rbp-Ch]

v5 = a2;
v18 = 0x80000000LL;
v6 = a2 - 4098;
v11 = 1;
v12 = 0x10000;
v13 = 3;
v14 = 1;
v15 = 0x8000;
v16 = 850;
v17 = 1;
v7 = a4;
switch ( v6 )
{
case 0u:
v8 = &v11;
v9 = 4;
break;
case 1u:
v8 = &v13;
v9 = 4;
break;
case 2u:
v8 = &v12;
v9 = 4;
break;
case 3u:
v20 = 256;
v8 = (int *)&v19;
v9 = 12;
v19 = 0x10000000100LL;
break;
case 0xAu:
v8 = &v16;
v9 = 4;
break;
case 0x14u:
v8 = &v17;
v9 = 4;
break;
case 0x1Du:
v8 = (int *)&v18;
v9 = 8;
break;
case 0x20u:
v8 = &v14;
v9 = 4;
break;
case 0x21u:
v8 = &v15;
v9 = 4;
break;
case 0x29u:
v8 = (int *)"Multi2Sim Virtual GPU Device";
v9 = 29;
break;
case 0x2Au:
v8 = (int *)"www.multi2sim.org";
v9 = 18;
break;
case 0x2Bu:
v8 = (int *)"4.0";
v9 = 4;
break;
case 0x2Du:
v8 = (int *)"OpenCL 1.1 ATI-Stream-v2.3 (451)";
v9 = 33;
break;
case 0x2Eu:
v8 = (int *)"cl_amd_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_b"
"ase_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_gl_sharing cl_ext"
"_device_fission cl_amd_device_attribute_query cl_amd_media_ops cl_amd_popcnt cl_amd_printf ";
v9 = 296;
break;
default:
fatal(
"opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
(unsigned int)v5,
evg_err_opencl_note);
_assert_fail("info", "opencl-device.c", 0xA4u, "evg_opencl_device_get_info");
}
if ( (_DWORD)v7 && v9 <= (unsigned int)a5 )
mem_write(a3, v7, v9, v8, a5, v5);
return v9;
}

original_code:
uint32_t evg_opencl_device_get_info(struct evg_opencl_device_t *device, uint32_t name, struct mem_t *mem, uint32_t addr, uint32_t size)
{
 uint32_t max_compute_units = 1;
 uint32_t max_work_group_size = 256 * 256;
 uint32_t max_work_item_dimensions = 3;
 uint32_t max_work_item_sizes[3];
 uint32_t local_mem_type = 1;
 uint32_t local_mem_size = 32 * 1024;
 uint32_t max_clock_frequency = 850;
 uint64_t global_mem_size = 1ull << 31;
 uint32_t image_support = 1;
 char *device_name = "Multi2Sim Virtual GPU Device";
 char *device_vendor = "www.multi2sim.org";
 char *device_extensions = "cl_amd_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics "
  "cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store "
  "cl_khr_gl_sharing cl_ext_device_fission cl_amd_device_attribute_query cl_amd_media_ops cl_amd_popcnt "
  "cl_amd_printf ";
 char *device_version = "OpenCL 1.1 ATI-Stream-v2.3 (451)";
 char *driver_version = "4.0";
 uint32_t size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1002:
  size_ret = 4;
  info = &max_compute_units;
  break;
 case 0x1003:
  size_ret = 4;
  info = &max_work_item_dimensions;
  break;
 case 0x1004:
  size_ret = 4;
  info = &max_work_group_size;
  break;
 case 0x1005:
  max_work_item_sizes[0] = 256;
  max_work_item_sizes[1] = 256;
  max_work_item_sizes[2] = 256;
  size_ret = 12;
  info = max_work_item_sizes;
  break;
 case 0x100c:
  size_ret = 4;
  info = &max_clock_frequency;
  break;
 case 0x1016:
  size_ret = 4;
  info = &image_support;
  break;
 case 0x101f:
  size_ret = 8;
  info = &global_mem_size;
  break;
 case 0x1022:
  size_ret = 4;
  info = &local_mem_type;
  break;
 case 0x1023:
  size_ret = 4;
  info = &local_mem_size;
  break;
 case 0x102b:
  size_ret = strlen(device_name) + 1;
  info = device_name;
  break;
 case 0x102c:
  size_ret = strlen(device_vendor) + 1;
  info = device_vendor;
  break;
 case 0x102d:
  size_ret = strlen(driver_version) + 1;
  info = driver_version;
  break;
 case 0x102f:
  size_ret = strlen(device_version) + 1;
  info = device_version;
  break;
 case 0x1030:
  size_ret = strlen(device_extensions) + 1;
  info = device_extensions;
  break;
 default:
  fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-device.c", 164, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int evg_opencl_device_get_info(struct evg_opencl_device_t *device, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 unsigned int max_compute_units = 1;
 unsigned int max_work_group_size = 256 * 256;
 unsigned int max_work_item_dimensions = 3;
 unsigned int max_work_item_sizes[3];
 unsigned int local_mem_type = 1;
 unsigned int local_mem_size = 32 * 1024;
 unsigned int max_clock_frequency = 850;
 unsigned long global_mem_size = 1ull << 31;
 unsigned int image_support = 1;
 char *device_name = "Multi2Sim Virtual GPU Device";
 char *device_vendor = "www.multi2sim.org";
 char *device_extensions = "cl_amd_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics "
  "cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store "
  "cl_khr_gl_sharing cl_ext_device_fission cl_amd_device_attribute_query cl_amd_media_ops cl_amd_popcnt "
  "cl_amd_printf ";
 char *device_version = "OpenCL 1.1 ATI-Stream-v2.3 (451)";
 char *driver_version = "4.0";
 unsigned int size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1002:
  size_ret = 4;
  info = &max_compute_units;
  break;
 case 0x1003:
  size_ret = 4;
  info = &max_work_item_dimensions;
  break;
 case 0x1004:
  size_ret = 4;
  info = &max_work_group_size;
  break;
 case 0x1005:
  max_work_item_sizes[0] = 256;
  max_work_item_sizes[1] = 256;
  max_work_item_sizes[2] = 256;
  size_ret = 12;
  info = max_work_item_sizes;
  break;
 case 0x100c:
  size_ret = 4;
  info = &max_clock_frequency;
  break;
 case 0x1016:
  size_ret = 4;
  info = &image_support;
  break;
 case 0x101f:
  size_ret = 8;
  info = &global_mem_size;
  break;
 case 0x1022:
  size_ret = 4;
  info = &local_mem_type;
  break;
 case 0x1023:
  size_ret = 4;
  info = &local_mem_size;
  break;
 case 0x102b:
  size_ret = strlen(device_name) + 1;
  info = device_name;
  break;
 case 0x102c:
  size_ret = strlen(device_vendor) + 1;
  info = device_vendor;
  break;
 case 0x102d:
  size_ret = strlen(driver_version) + 1;
  info = driver_version;
  break;
 case 0x102f:
  size_ret = strlen(device_version) + 1;
  info = device_version;
  break;
 case 0x1030:
  size_ret = strlen(device_extensions) + 1;
  info = device_extensions;
  break;
 default:
  fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-device.c", 164, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}


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

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

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

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

original_code:
struct si_opencl_platform_t *si_opencl_platform_create()
{
 struct si_opencl_platform_t *platform;
 platform = (mhandle_calloc(1, sizeof(struct si_opencl_platform_t), "opencl-platform.c" ":" "34"));
 if (!platform)
  fatal("%s: out of memory", __FUNCTION__);
 platform->id = si_opencl_repo_new_object_id(si_emu->opencl_repo,
  si_opencl_object_platform);
 si_opencl_repo_add_object(si_emu->opencl_repo, platform);
 return platform;
}

variable_types: struct si_opencl_platform_t { unsigned int id; } *


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

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

original_code:
void si_opencl_platform_free(struct si_opencl_platform_t *platform)
{
 si_opencl_repo_remove_object(si_emu->opencl_repo, platform);
 (mhandle_free(platform, "opencl-platform.c" ":" "51"));
}

user_defined_types: struct si_opencl_platform_t { unsigned int id; }


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

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

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

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

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

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

variable_types:
info
char *


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

v2 = a1[5] + a1[3] + a1[4];
v3 = a2[5] + a2[3] + a2[4];
result = (unsigned int)-(v2 != v3);
if ( v2 < v3 )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
__int64 result; // rax

v2 = a1[5] + a1[3] + a1[4];
v3 = a2[5] + a2[3] + a2[4];
result = (unsigned int)-(v2 != v3);
if ( v2 < v3 )
result = 1LL;
return result;
}

original_code:
static int mmu_page_compare(const void *ptr1, const void *ptr2)
{
 struct mmu_page_t *page1 = (struct mmu_page_t *) ptr1;
 struct mmu_page_t *page2 = (struct mmu_page_t *) ptr2;
 long long num_accesses1;
 long long num_accesses2;
 num_accesses1 = page1->num_read_accesses + page1->num_write_accesses
  + page1->num_execute_accesses;
 num_accesses2 = page2->num_read_accesses + page2->num_write_accesses
  + page2->num_execute_accesses;
 if (num_accesses1 < num_accesses2)
  return 1;
 else if (num_accesses1 == num_accesses2)
  return 0;
 else
  return -1;
}

canonical_original_code:
static int mmu_page_compare(void *ptr1, void *ptr2)
{
 struct mmu_page_t *page1 = (struct mmu_page_t *) ptr1;
 struct mmu_page_t *page2 = (struct mmu_page_t *) ptr2;
 long long num_accesses1;
 long long num_accesses2;
 num_accesses1 = page1->num_read_accesses + page1->num_write_accesses
  + page1->num_execute_accesses;
 num_accesses2 = page2->num_read_accesses + page2->num_write_accesses
  + page2->num_execute_accesses;
 if (num_accesses1 < num_accesses2)
  return 1;
 else if (num_accesses1 == num_accesses2)
  return 0;
 else
  return -1;
}

variable_types: struct mmu_page_t { struct mmu_page_t *next; int address_space_index; unsigned int vtl_addr; unsigned int phy_addr; long long num_read_accesses; long long num_write_accesses; long long num_execute_accesses; } *