original_code:
static struct mmu_page_t *mmu_get_page(int address_space_index, unsigned int vtladdr)
{
 struct mmu_page_t *prev, *page;
 unsigned int tag;
 int index;
 index = ((vtladdr >> mmu_log_page_size) + address_space_index * 23) % (1 << 10);
 tag = vtladdr & ~mmu_page_mask;
 prev = ((void *)0);
 page = mmu->page_hash_table[index];
 while (page)
 {
  if (page->vtl_addr == tag && page->address_space_index == address_space_index)
   break;
  prev = page;
  page = page->next;
 }
 if (!page)
 {
  page = (mhandle_calloc(1, sizeof(struct mmu_page_t), "mmu.c" ":" "105"));
  if (!page)
   fatal("%s: out of memory", __FUNCTION__);
  page->vtl_addr = tag;
  page->address_space_index = address_space_index;
  page->phy_addr = list_count(mmu->page_list) << mmu_log_page_size;
  list_add(mmu->page_list, page);
  page->next = mmu->page_hash_table[index];
  mmu->page_hash_table[index] = page;
  prev = ((void *)0);
 }
 if (prev)
 {
  prev->next = page->next;
  page->next = mmu->page_hash_table[index];
  mmu->page_hash_table[index] = page;
 }
 return page;
}

canonical_original_code:
static struct mmu_page_t *mmu_get_page(int address_space_index, unsigned int vtladdr)
{
 struct mmu_page_t *prev; struct mmu_page_t *page;
 unsigned int tag;
 int index;
 index = ((vtladdr >> mmu_log_page_size) + address_space_index * 23) % (1 << 10);
 tag = vtladdr & ~mmu_page_mask;
 prev = ((void *)0);
 page = mmu->page_hash_table[index];
 while (page)
 {
  if (page->vtl_addr == tag && page->address_space_index == address_space_index)
   break;
  prev = page;
  page = page->next;
 }
 if (!page)
 {
  page = (mhandle_calloc(1, sizeof(struct mmu_page_t), "mmu.c" ":" "105"));
  if (!page)
   fatal("%s: out of memory", __FUNCTION__);
  page->vtl_addr = tag;
  page->address_space_index = address_space_index;
  page->phy_addr = list_count(mmu->page_list) << mmu_log_page_size;
  list_add(mmu->page_list, page);
  page->next = mmu->page_hash_table[index];
  mmu->page_hash_table[index] = page;
  prev = ((void *)0);
 }
 if (prev)
 {
  prev->next = page->next;
  page->next = mmu->page_hash_table[index];
  mmu->page_hash_table[index] = page;
 }
 return page;
}

variable_types:
vtladdr
unsigned int

variable_types:
tag
unsigned int

variable_types: index int

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


decompiled_code:
__int64 mmu_done()
{
int v0; // ebx
__int64 v1; // rsi
__int64 v2; // rax

v0 = 0;
mmu_dump_report();
while ( (int)list_count(*(_QWORD *)mmu) > v0 )
{
v1 = (unsigned int)v0++;
v2 = list_get(*(_QWORD *)mmu, v1);
mhandle_free(v2, "mmu.c:197");
}
list_free(*(_QWORD *)mmu);
return mhandle_free(mmu, "mmu.c:201");
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
__int64 v1; // rsi
__int64 v2; // rax

v0 = 0;
func3();
while ( (int)list_count(*(_QWORD *)mmu) > v0 )
{
v1 = (unsigned int)v0++;
v2 = list_get(*(_QWORD *)mmu, v1);
mhandle_free(v2, "mmu.c:197");
}
list_free(*(_QWORD *)mmu);
return mhandle_free(mmu, "mmu.c:201");
}

original_code:
void mmu_done()
{
 int i;
 mmu_dump_report();
 for (i = 0; i < list_count(mmu->page_list); i++)
  (mhandle_free(list_get(mmu->page_list, i), "mmu.c" ":" "197"));
 list_free(mmu->page_list);
 (mhandle_free(mmu, "mmu.c" ":" "201"));
}

variable_types: i int

return_type: void


decompiled_code:
__int64 mmu_address_space_new()
{
return (unsigned int)mmu_address_space_index_3++;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)mmu_address_space_index_3++;
}

original_code:
int mmu_address_space_new(void)
{
 static int mmu_address_space_index;
 return mmu_address_space_index++;
}

canonical_original_code:
int mmu_address_space_new()
{
 static int mmu_address_space_index;
 return mmu_address_space_index++;
}

return_type: int


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

v2 = a2 & mmu_page_mask;
v3 = mmu_get_page(a1, a2);
if ( !v3 )
_assert_fail("page", "mmu.c", 0x106u, "mmu_translate");
return *(_DWORD *)(v3 + 16) | (unsigned int)v2;
}

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

v2 = a2 & mmu_page_mask;
v3 = func1(a1, a2);
if ( !v3 )
_assert_fail("page", "mmu.c", 0x106u, "mmu_translate");
return *(_DWORD *)(v3 + 16) | (unsigned int)v2;
}

original_code:
unsigned int mmu_translate(int address_space_index, unsigned int vtl_addr)
{
 struct mmu_page_t *page;
 unsigned int offset;
 unsigned int phy_addr;
 offset = vtl_addr & mmu_page_mask;
 page = mmu_get_page(address_space_index, vtl_addr);
 ((void) sizeof ((page) ? 1 : 0), __extension__ ({ if (page) ; else __assert_fail ("page", "mmu.c", 262, __extension__ __PRETTY_FUNCTION__); }));
 phy_addr = page->phy_addr | offset;
 return phy_addr;
}

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

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall mmu_valid_phy_addr(unsigned int a1)
{
return **(_DWORD **)mmu > (int)(a1 >> mmu_log_page_size);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(unsigned int a1)
{
return **(_DWORD **)mmu > (int)(a1 >> mmu_log_page_size);
}

original_code:
int mmu_valid_phy_addr(unsigned int phy_addr)
{
 int index;
 index = phy_addr >> mmu_log_page_size;
 return index < mmu->page_list->count;
}


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

v0 = (_DWORD *)mhandle_calloc(1LL, 20LL, "opencl-sampler.c:34");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_sampler_create");
v1 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 9LL);
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, 20LL, "opencl-sampler.c:34");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_sampler_create");
v1 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 9LL);
v0[1] = 1;
*v0 = v1;
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

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

variable_types: struct si_opencl_sampler_t { unsigned int id; int ref_count; unsigned int normalized_coords; unsigned int filter_mode; unsigned int addressing_mode; } *


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

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

original_code:
void si_opencl_sampler_free(struct si_opencl_sampler_t *sampler)
{
 si_opencl_repo_remove_object(si_emu->opencl_repo, sampler);
 (mhandle_free(sampler, "opencl-sampler.c" ":" "52"));
}

user_defined_types: struct si_opencl_sampler_t { unsigned int id; int ref_count; unsigned int normalized_coords; unsigned int filter_mode; unsigned int addressing_mode; }


decompiled_code:
void frm_gpu_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void frm_gpu_init(void)
{
}

canonical_original_code:
void frm_gpu_init()
{
}


decompiled_code:
void frm_gpu_done()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void frm_gpu_done(void)
{
}

canonical_original_code:
void frm_gpu_done()
{
}


decompiled_code:
__int64 evg_opencl_program_create()
{
__int64 v0; // r12
int v1; // ebx
int v2; // eax
__int64 v3; // rax
__int64 i; // rdi

v0 = mhandle_calloc(1LL, 32LL, "opencl-program.c:35");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_program_create");
v1 = 25;
v2 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 5LL);
*(_DWORD *)(v0 + 4) = 1;
*(_DWORD *)v0 = v2;
v3 = list_create_with_size(25LL);
*(_QWORD *)(v0 + 24) = v3;
for ( i = v3; ; i = *(_QWORD *)(v0 + 24) )
{
list_add(i, 0LL);
if ( !--v1 )
break;
}
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r12
int v1; // ebx
int v2; // eax
__int64 v3; // rax
__int64 i; // rdi

v0 = mhandle_calloc(1LL, 32LL, "opencl-program.c:35");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_program_create");
v1 = 25;
v2 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 5LL);
*(_DWORD *)(v0 + 4) = 1;
*(_DWORD *)v0 = v2;
v3 = list_create_with_size(25LL);
*(_QWORD *)(v0 + 24) = v3;
for ( i = v3; ; i = *(_QWORD *)(v0 + 24) )
{
list_add(i, 0LL);
if ( !--v1 )
break;
}
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

original_code:
struct evg_opencl_program_t *evg_opencl_program_create()
{
 struct evg_opencl_program_t *program;
 int i;
 program = (mhandle_calloc(1, sizeof(struct evg_opencl_program_t), "opencl-program.c" ":" "35"));
 if (!program)
  fatal("%s: out of memory", __FUNCTION__);
 program->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo,
  evg_opencl_object_program);
 program->ref_count = 1;
 program->constant_buffer_list = list_create_with_size(25);
 for(i = 0; i < 25; i++)
  list_add(program->constant_buffer_list, ((void *)0));
 evg_opencl_repo_add_object(evg_emu->opencl_repo, program);
 return program;
}

variable_types: struct evg_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; } *

user_defined_types: struct evg_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_section_t { char *name; struct Elf32_Shdr *header; struct elf_buffer_t buffer; }


decompiled_code:
__int64 __fastcall evg_opencl_program_free(__int64 a1)
{
list_free(*(_QWORD *)(a1 + 24));
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
return mhandle_free(a1, "opencl-program.c:63");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
list_free(*(_QWORD *)(a1 + 24));
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
return mhandle_free(a1, "opencl-program.c:63");
}

original_code:
void evg_opencl_program_free(struct evg_opencl_program_t *program)
{
 list_free(program->constant_buffer_list);
 if (program->elf_file)
  elf_file_free(program->elf_file);
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, program);
 (mhandle_free(program, "opencl-program.c" ":" "63"));
}

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

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

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

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


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

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
_assert_fail("program->elf_file", "opencl-program.c", 0x4Du, "evg_opencl_program_build");
result = *(_QWORD *)(v1 + 24);
if ( *(_WORD *)(result + 18) != 1009 )
result = fatal(
"%s: invalid binary file.\n%s",
"evg_opencl_program_build",
"\tYour application tried to load a pre-compiled OpenCL kernel binary which\n"
"\tdoes not contain code in the Evergreen ISA. Please, check that the off-line\n"
"\tcompilation of your kernel targets this GPU architecture supported by\n"
"\tMulti2Sim.\n");
return result;
}

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

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
_assert_fail("program->elf_file", "opencl-program.c", 0x4Du, "evg_opencl_program_build");
result = *(_QWORD *)(v1 + 24);
if ( *(_WORD *)(result + 18) != 1009 )
result = fatal(
"%s: invalid binary file.\n%s",
"evg_opencl_program_build",
"\tYour application tried to load a pre-compiled OpenCL kernel binary which\n"
"\tdoes not contain code in the Evergreen ISA. Please, check that the off-line\n"
"\tcompilation of your kernel targets this GPU architecture supported by\n"
"\tMulti2Sim.\n");
return result;
}

original_code:
void evg_opencl_program_build(struct evg_opencl_program_t *program)
{
 ((void) sizeof ((program->elf_file) ? 1 : 0), __extension__ ({ if (program->elf_file) ; else __assert_fail ("program->elf_file", "opencl-program.c", 77, __extension__ __PRETTY_FUNCTION__); }));
 if (program->elf_file->header->e_machine != 0x3f1)
  fatal("%s: invalid binary file.\n%s", __FUNCTION__,
   err_evg_opencl_evergreen_format);
}


decompiled_code:
__int64 __fastcall evg_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, "evg_opencl_program_read_symbol");
v5 = elf_symbol_get_by_name(*(_QWORD *)(a1 + 16));
if ( !v5 )
fatal(
"%s: ELF symbol '%s' not found.\n%s",
"evg_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, "evg_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",
"evg_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, "evg_opencl_program_read_symbol");
v5 = elf_symbol_get_by_name(*(_QWORD *)(a1 + 16));
if ( !v5 )
fatal(
"%s: ELF symbol '%s' not found.\n%s",
"evg_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, "evg_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",
"evg_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 evg_opencl_program_read_symbol(struct evg_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_evg_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_evg_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 evg_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 ( evg_opencl_debug_category )
_debug(
evg_opencl_debug_category,
" constant buffer '%s' found with size %d\n",
*(const char **)result,
*(unsigned int *)(result + 12));
evg_opencl_program_read_symbol(a1, *v12, (__int64)&v13);
v4 = evg_opencl_mem_create();
v5 = v14;
*(_DWORD *)(v4 + 8) = 0;
v6 = v4;
*(_DWORD *)(v4 + 12) = v5;
*(_QWORD *)(v4 + 40) = 0LL;
v7 = evg_emu;
v8 = *(unsigned int *)(evg_emu + 288LL);
v9 = *(_QWORD *)(evg_emu + 280LL);
*(_DWORD *)(v6 + 48) = v8;
*(_DWORD *)(v7 + 288) = 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 ( evg_opencl_debug_category )
_debug(
evg_opencl_debug_category,
" constant buffer '%s' found with size %d\n",
*(const char **)result,
*(unsigned int *)(result + 12));
func3(a1, *v12, (__int64)&v13);
v4 = evg_opencl_mem_create();
v5 = v14;
*(_DWORD *)(v4 + 8) = 0;
v6 = v4;
*(_DWORD *)(v4 + 12) = v5;
*(_QWORD *)(v4 + 40) = 0LL;
v7 = evg_emu;
v8 = *(unsigned int *)(evg_emu + 288LL);
v9 = *(_QWORD *)(evg_emu + 280LL);
*(_DWORD *)(v6 + 48) = v8;
*(_DWORD *)(v7 + 288) = 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 evg_opencl_program_initialize_constant_buffers(struct evg_opencl_program_t *program)
{
 struct elf_file_t *elf_file;
 struct elf_symbol_t *elf_symbol;
 struct elf_buffer_t elf_buffer;
 struct evg_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;
  }
  ((evg_opencl_debug_category) ? __debug((evg_opencl_debug_category), "  constant buffer '%s' found with size %d\n", elf_symbol->name, elf_symbol->size) : (void) 0);
  evg_opencl_program_read_symbol(program, elf_symbol->name, &elf_buffer);
  mem = evg_opencl_mem_create();
  mem->type = 0;
  mem->size = elf_buffer.size;
  mem->flags = 0;
  mem->host_ptr = 0;
  mem->device_ptr = evg_emu->global_mem_top;
  evg_emu->global_mem_top += mem->size;
  mem_write(evg_emu->global_mem, mem->device_ptr, mem->size, elf_buffer.ptr);
  list_set(program->constant_buffer_list, i, mem);
 }
}

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

variable_types: struct evg_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 flags; unsigned int host_ptr; unsigned int device_ptr; } *

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


decompiled_code:
void evg_periodic_report_init()
{
;
}

original_code:
void evg_periodic_report_init(void)
{
}

canonical_original_code:
void evg_periodic_report_init()
{
}


decompiled_code:
__int64 evg_periodic_report_done()
{
return str_free(evg_periodic_report_file_name);
}

canonical_decompiled_code:
__int64 func1()
{
return str_free(evg_periodic_report_file_name);
}

original_code:
void evg_periodic_report_done(void)
{
 str_free(evg_periodic_report_file_name);
}

canonical_original_code:
void evg_periodic_report_done()
{
 str_free(evg_periodic_report_file_name);
}


decompiled_code:
__int64 evg_emu_done()
{
if ( evg_emu_report_file )
fclose(evg_emu_report_file);
while ( *(_DWORD *)(evg_emu + 48) )
evg_ndrange_free(*(_QWORD *)(evg_emu + 32));
evg_opencl_repo_free_all_objects(*(_QWORD *)(evg_emu + 8));
evg_opencl_repo_free(*(_QWORD *)(evg_emu + 8));
evg_disasm_done();
evg_isa_done();
mem_free(*(_QWORD *)(evg_emu + 128));
mem_free(*(_QWORD *)(evg_emu + 280));
m2s_timer_free(*(_QWORD *)evg_emu);
return mhandle_free(evg_emu, "emu.c:118");
}

canonical_decompiled_code:
__int64 func1()
{
if ( evg_emu_report_file )
fclose(evg_emu_report_file);
while ( *(_DWORD *)(evg_emu + 48) )
evg_ndrange_free(*(_QWORD *)(evg_emu + 32));
evg_opencl_repo_free_all_objects(*(_QWORD *)(evg_emu + 8));
evg_opencl_repo_free(*(_QWORD *)(evg_emu + 8));
evg_disasm_done();
evg_isa_done();
mem_free(*(_QWORD *)(evg_emu + 128));
mem_free(*(_QWORD *)(evg_emu + 280));
m2s_timer_free(*(_QWORD *)evg_emu);
return mhandle_free(evg_emu, "emu.c:118");
}

original_code:
void evg_emu_done()
{
 if (evg_emu_report_file)
  fclose(evg_emu_report_file);
 while (evg_emu->ndrange_list_count)
  evg_ndrange_free(evg_emu->ndrange_list_head);
 evg_opencl_repo_free_all_objects(evg_emu->opencl_repo);
 evg_opencl_repo_free(evg_emu->opencl_repo);
 evg_disasm_done();
 evg_isa_done();
 mem_free(evg_emu->const_mem);
 mem_free(evg_emu->global_mem);
 m2s_timer_free(evg_emu->timer);
 (mhandle_free(evg_emu, "emu.c" ":" "118"));
}


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

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

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

variable_types: pid int


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

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

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

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

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

variable_types:
path
char *

variable_types: struct evg_bin_file_t { struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *elf_file; struct list_t *enc_dict; struct evg_bin_enc_dict_entry_t { struct evg_bin_enc_dict_entry_header_t { unsigned int d_machine; unsigned int d_type; unsigned int d_offset; unsigned int d_size; unsigned int d_flags; } *header; struct elf_buffer_t pt_load_buffer; struct elf_buffer_t pt_note_buffer; struct elf_buffer_t sec_text_buffer; struct elf_buffer_t sec_data_buffer; struct elf_buffer_t sec_symtab_buffer; struct elf_buffer_t sec_strtab_buffer; struct evg_bin_enc_dict_entry_consts_t { float float_consts[256][4]; unsigned int int_consts[32][4]; unsigned int bool_consts[32]; } *consts; int num_gpr_used; int lds_size_used; int stack_size_used; } *enc_dict_entry_evergreen; } *

user_defined_types: struct evg_bin_file_t { struct elf_file_t *elf_file; struct list_t *enc_dict; struct evg_bin_enc_dict_entry_t *enc_dict_entry_evergreen; }

user_defined_types: struct evg_bin_enc_dict_entry_t { struct evg_bin_enc_dict_entry_header_t *header; struct elf_buffer_t pt_load_buffer; struct elf_buffer_t pt_note_buffer; struct elf_buffer_t sec_text_buffer; struct elf_buffer_t sec_data_buffer; struct elf_buffer_t sec_symtab_buffer; struct elf_buffer_t sec_strtab_buffer; struct evg_bin_enc_dict_entry_consts_t *consts; int num_gpr_used; int lds_size_used; int stack_size_used; }


decompiled_code:
void __fastcall __noreturn evg_emu_opengl_disasm(const char *a1, int a2)
{
__int64 v2; // r13
__int64 v3; // rbp
unsigned int v4; // eax
int v5; // eax
__int64 v6; // rbx
unsigned int v7; // eax
unsigned int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

evg_disasm_init();
v2 = read_buffer(a1, v8);
if ( !v2 )
fatal("%s:Invalid file!", a1);
v3 = evg_opengl_bin_file_create(v2, v8[0], a1);
free_buffer(v2);
v4 = list_count(*(_QWORD *)(v3 + 8));
printf("This shader binary contains %d shaders\n\n", v4);
v5 = list_count(*(_QWORD *)(v3 + 8));
if ( a2 <= 0 || v5 < a2 )
{
v7 = list_count(*(_QWORD *)(v3 + 8));
fatal("Shader index out of range! Please choose <index> from 1 ~ %d", v7);
}
v6 = list_get(*(_QWORD *)(v3 + 8), (unsigned int)(a2 - 1));
printf("**\n** Disassembly for shader %d\n**\n\n", (unsigned int)a2);
evg_disasm_buffer(v6 + 24, stdout);
puts("\n\n");
evg_opengl_bin_file_free(v3);
evg_disasm_done();
_mhandle_done();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(const char *a1, int a2)
{
__int64 v2; // r13
__int64 v3; // rbp
unsigned int v4; // eax
int v5; // eax
__int64 v6; // rbx
unsigned int v7; // eax
unsigned int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

evg_disasm_init();
v2 = read_buffer(a1, v8);
if ( !v2 )
fatal("%s:Invalid file!", a1);
v3 = evg_opengl_bin_file_create(v2, v8[0], a1);
free_buffer(v2);
v4 = list_count(*(_QWORD *)(v3 + 8));
printf("This shader binary contains %d shaders\n\n", v4);
v5 = list_count(*(_QWORD *)(v3 + 8));
if ( a2 <= 0 || v5 < a2 )
{
v7 = list_count(*(_QWORD *)(v3 + 8));
fatal("Shader index out of range! Please choose <index> from 1 ~ %d", v7);
}
v6 = list_get(*(_QWORD *)(v3 + 8), (unsigned int)(a2 - 1));
printf("**\n** Disassembly for shader %d\n**\n\n", (unsigned int)a2);
evg_disasm_buffer(v6 + 24, stdout);
puts("\n\n");
evg_opengl_bin_file_free(v3);
evg_disasm_done();
_mhandle_done();
exit(0);
}

original_code:
void evg_emu_opengl_disasm(char *path, int opengl_shader_index)
{
 void *file_buffer;
 int file_size;
 struct evg_opengl_bin_file_t *amd_opengl_bin;
 struct evg_opengl_shader_t *amd_opengl_shader;
 evg_disasm_init();
 file_buffer = read_buffer(path, &file_size);
 if(!file_buffer)
  fatal("%s:Invalid file!", path);
 amd_opengl_bin = evg_opengl_bin_file_create(file_buffer, file_size, path);
 free_buffer(file_buffer);
 printf("This shader binary contains %d shaders\n\n", list_count(amd_opengl_bin->shader_list));
 if (opengl_shader_index > list_count(amd_opengl_bin->shader_list) || opengl_shader_index <= 0 )
 {
  fatal("Shader index out of range! Please choose <index> from 1 ~ %d", list_count(amd_opengl_bin->shader_list));
 }
 amd_opengl_shader = list_get(amd_opengl_bin->shader_list, opengl_shader_index -1 );
 printf("**\n** Disassembly for shader %d\n**\n\n", opengl_shader_index);
 evg_disasm_buffer(&amd_opengl_shader->isa_buffer, stdout);
 printf("\n\n\n");
 evg_opengl_bin_file_free(amd_opengl_bin);
 evg_disasm_done();
 __mhandle_done();
 exit(0);
}

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

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

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

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


decompiled_code:
__int64 si_uop_done()
{
return repos_free(gpu_uop_repos);
}

canonical_decompiled_code:
__int64 func1()
{
return repos_free(gpu_uop_repos);
}

original_code:
void si_uop_done()
{
 repos_free(gpu_uop_repos);
}


decompiled_code:
__int64 __fastcall x86_cpu_decode_core(unsigned int a1)
{
__int64 result; // rax
int v2; // ebx
unsigned int v3; // esi

result = x86_cpu_num_threads;
if ( x86_cpu_num_threads > 0 )
{
v2 = 0;
do
{
v3 = v2++;
result = x86_cpu_decode_thread(a1, v3);
}
while ( x86_cpu_num_threads > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax
int v2; // ebx
unsigned int v3; // esi

result = x86_cpu_num_threads;
if ( x86_cpu_num_threads > 0 )
{
v2 = 0;
do
{
v3 = v2++;
result = func0(a1, v3);
}
while ( x86_cpu_num_threads > v2 );
}
return result;
}

original_code:
static void x86_cpu_decode_core(int core)
{
 int thread;
 for (thread = 0; thread < x86_cpu_num_threads; thread++)
  x86_cpu_decode_thread(core, thread);
}

variable_types: core int

variable_types: thread int


decompiled_code:
__int64 x86_cpu_decode()
{
__int64 result; // rax
int v1; // ebx
unsigned int v2; // edi

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

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // ebx
unsigned int v2; // edi

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

original_code:
void x86_cpu_decode()
{
 int core;
 x86_cpu->stage = "decode";
 for (core = 0; core < x86_cpu_num_cores; core++)
  x86_cpu_decode_core(core);
}


decompiled_code:
__int64 evg_uop_done()
{
return repos_free(gpu_uop_repos);
}

canonical_decompiled_code:
__int64 func2()
{
return repos_free(gpu_uop_repos);
}

original_code:
void evg_uop_done()
{
 repos_free(gpu_uop_repos);
}


decompiled_code:
__int64 __fastcall evg_uop_dump_dep_list(__int64 a1, int a2, _DWORD *a3, int a4)
{
const __int16 *v6; // r12
__int64 v7; // rbp
const char *v8; // rcx
__int64 v9; // rdx
const char *v10; // rax
int v12; // [rsp+4h] [rbp-F4h] BYREF
__int64 v13; // [rsp+8h] [rbp-F0h] BYREF
char s[232]; // [rsp+10h] [rbp-E8h] BYREF

v13 = a1;
v12 = a2;
str_printf(&v13, &v12, "{");
if ( a4 > 0 )
{
v6 = (const __int16 *)&unk_784;
v7 = (__int64)&a3[a4 - 1 + 1];
do
{
v9 = (unsigned int)(*a3 - 1);
if ( (unsigned int)v9 <= 0x7F )
{
sprintf(s, "R%d", v9);
}
else
{
v10 = (const char *)map_value(&gpu_uop_dep_map_2);
strcpy(s, v10);
}
v8 = (const char *)v6;
++a3;
v6 = asc_790;
str_printf(&v13, &v12, "%s%s", v8, s);
}
while ( a3 != (_DWORD *)v7 );
}
return str_printf(&v13, &v12, (const char *)&asc_790[1]);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, _DWORD *a3, int a4)
{
const __int16 *v6; // r12
__int64 v7; // rbp
const char *v8; // rcx
__int64 v9; // rdx
const char *v10; // rax
int v12; // [rsp+4h] [rbp-F4h] BYREF
__int64 v13; // [rsp+8h] [rbp-F0h] BYREF
char s[232]; // [rsp+10h] [rbp-E8h] BYREF

v13 = a1;
v12 = a2;
str_printf(&v13, &v12, "{");
if ( a4 > 0 )
{
v6 = (const __int16 *)&unk_784;
v7 = (__int64)&a3[a4 - 1 + 1];
do
{
v9 = (unsigned int)(*a3 - 1);
if ( (unsigned int)v9 <= 0x7F )
{
sprintf(s, "R%d", v9);
}
else
{
v10 = (const char *)map_value(&gpu_uop_dep_map_2);
strcpy(s, v10);
}
v8 = (const char *)v6;
++a3;
v6 = asc_790;
str_printf(&v13, &v12, "%s%s", v8, s);
}
while ( a3 != (_DWORD *)v7 );
}
return str_printf(&v13, &v12, (const char *)&asc_790[1]);
}

original_code:
void evg_uop_dump_dep_list(char *buf, int size, int *dep_list, int dep_count)
{
 static struct string_map_t gpu_uop_dep_map = {
  4, {
   { "none", 0 },
   { "LDS", 131 },
   { "PS", 130 },
   { "PV", 129 }
  }
 };
 char *comma = "";
 char str[200];
 int i;
 str_printf(&buf, &size, "{");
 for (i = 0; i < dep_count; i++)
 {
  if (((dep_list[i])>=(1)&&(dep_list[i])<=(128)))
   sprintf(str, "R%d", dep_list[i] - 1);
  else
   strcpy(str, map_value(&gpu_uop_dep_map, dep_list[i]));
  str_printf(&buf, &size, "%s%s", comma, str);
  comma = ",";
 }
 str_printf(&buf, &size, "}");
}

variable_types:
buf
char *

variable_types: size int

variable_types: struct string_map_t { int count; struct { char *string; int value; } map[]; }

variable_types:
comma
char *

variable_types:
str
char [200]

variable_types: i int


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

v0 = (_DWORD *)mhandle_calloc(1LL, 52LL, "opencl-mem.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_mem_create");
v1 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 7LL);
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, 52LL, "opencl-mem.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_mem_create");
v1 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 7LL);
v0[1] = 1;
*v0 = v1;
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

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

return_type: struct evg_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 flags; unsigned int host_ptr; unsigned int device_ptr; } *


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

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

original_code:
void evg_opencl_mem_free(struct evg_opencl_mem_t *mem)
{
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, mem);
 (mhandle_free(mem, "opencl-mem.c" ":" "52"));
}

user_defined_types: struct evg_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 flags; unsigned int host_ptr; unsigned int device_ptr; }


decompiled_code:
__int64 __fastcall matrix_free(__int64 a1)
{
__int64 v2; // rdi

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
mhandle_free(v2, "matrix.c:69");
return mhandle_free(a1, "matrix.c:70");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // rdi

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
mhandle_free(v2, "matrix.c:69");
return mhandle_free(a1, "matrix.c:70");
}

original_code:
void matrix_free(struct matrix_t *matrix)
{
 if (matrix->elem)
  (mhandle_free(matrix->elem, "matrix.c" ":" "69"));
 (mhandle_free(matrix, "matrix.c" ":" "70"));
}

variable_types: struct matrix_t { int num_rows; int num_cols; void **elem; } *


original_code:
void matrix_set(struct matrix_t *matrix, int row, int col, void *value)
{
 if (row < 0 || row >= matrix->num_rows)
  return;
 if (col < 0 || col >= matrix->num_cols)
  return;
 matrix->elem[row * matrix->num_cols + col] = value;
}

variable_types: row int

variable_types: col int

variable_types:
value
void *

user_defined_types: struct matrix_t { int num_rows; int num_cols; void **elem; }


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

if ( a2 < 0 || *(_DWORD *)a1 <= a2 || a3 < 0 || (v3 = *(_DWORD *)(a1 + 4), v3 <= a3) )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v3 * a2 + a3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
int v3; // eax
__int64 result; // rax

if ( a2 < 0 || *(_DWORD *)a1 <= a2 || a3 < 0 || (v3 = *(_DWORD *)(a1 + 4), v3 <= a3) )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v3 * a2 + a3));
return result;
}

original_code:
void *matrix_get(struct matrix_t *matrix, int row, int col)
{
 if (row < 0 || row >= matrix->num_rows)
  return ((void *)0);
 if (col < 0 || col >= matrix->num_cols)
  return ((void *)0);
 return matrix->elem[row * matrix->num_cols + col];
}

return_type: void *


decompiled_code:
void *__fastcall matrix_clear(__int64 a1)
{
void *result; // rax

if ( *(_QWORD *)(a1 + 8) )
result = memset(*(void **)(a1 + 8), 0, 8LL * *(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
return result;
}

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

if ( *(_QWORD *)(a1 + 8) )
result = memset(*(void **)(a1 + 8), 0, 8LL * *(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
return result;
}

original_code:
void matrix_clear(struct matrix_t *matrix)
{
 if (matrix->elem)
  memset(matrix->elem, 0, matrix->num_rows * matrix->num_cols * sizeof(void *));
}


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

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

original_code:
int matrix_get_num_rows(struct matrix_t *matrix)
{
 return matrix->num_rows;
}


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

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

original_code:
int matrix_get_num_cols(struct matrix_t *matrix)
{
 return matrix->num_cols;
}


grow

original_code:
static int grow(struct buffer_t *buffer, int size)
{
 void *data;
 if (size < buffer->size)
  return 0;
 data = (mhandle_calloc(1, size, "buffer.c" ":" "47"));
 if (!data)
  return 0;
 memcpy(data, buffer->data + buffer->head, buffer->size - buffer->head);
 memcpy(data + buffer->size - buffer->head, buffer->data, buffer->head);
 (mhandle_free(buffer->data, "buffer.c" ":" "56"));
 buffer->data = data;
 buffer->size = size;
 buffer->head = 0;
 buffer->tail = buffer->count;
 return 1;
}

variable_types: struct buffer_t { void *data; int count; int head; } *

variable_types:
data
void *


decompiled_code:
__int64 __fastcall buffer_free(_QWORD *a1)
{
mhandle_free(*a1, "buffer.c:88");
return mhandle_free(a1, "buffer.c:89");
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
mhandle_free(*a1, "buffer.c:88");
return mhandle_free(a1, "buffer.c:89");
}

original_code:
void buffer_free(struct buffer_t *buffer)
{
 (mhandle_free(buffer->data, "buffer.c" ":" "88"));
 (mhandle_free(buffer, "buffer.c" ":" "89"));
}

user_defined_types: struct buffer_t { void *data; int count; int head; }


original_code:
int buffer_read(struct buffer_t *buffer, void *dest, int size)
{
 int right, left;
 size = ((size)<(buffer->count)?(size):(buffer->count));
 right = ((buffer->size - buffer->head)<(size)?(buffer->size - buffer->head):(size));
 left = size - right;
 memcpy(dest, buffer->data + buffer->head, right);
 memcpy(dest + right, buffer->data, left);
 buffer->head = (buffer->head + size) % buffer->size;
 buffer->count -= size;
 return size;
}

canonical_original_code:
int buffer_read(struct buffer_t *buffer, void *dest, int size)
{
 int right; int left;
 size = ((size)<(buffer->count)?(size):(buffer->count));
 right = ((buffer->size - buffer->head)<(size)?(buffer->size - buffer->head):(size));
 left = size - right;
 memcpy(dest, buffer->data + buffer->head, right);
 memcpy(dest + right, buffer->data, left);
 buffer->head = (buffer->head + size) % buffer->size;
 buffer->count -= size;
 return size;
}

variable_types:
dest
void *

variable_types: right int

variable_types: left int


original_code:
int buffer_write(struct buffer_t *buffer, void *dest, int size)
{
 int right, left;
 while (buffer->count + size > buffer->size)
  if (!grow(buffer, ((buffer->count + size)>(buffer->size * 2)?(buffer->count + size):(buffer->size * 2))))
   return 0;
 right = ((buffer->size - buffer->tail)<(size)?(buffer->size - buffer->tail):(size));
 left = size - right;
 memcpy(buffer->data + buffer->tail, dest, right);
 memcpy(buffer->data, dest + right, left);
 buffer->tail = (buffer->tail + size) % buffer->size;
 buffer->count += size;
 return size;
}

canonical_original_code:
int buffer_write(struct buffer_t *buffer, void *dest, int size)
{
 int right; int left;
 while (buffer->count + size > buffer->size)
  if (!grow(buffer, ((buffer->count + size)>(buffer->size * 2)?(buffer->count + size):(buffer->size * 2))))
   return 0;
 right = ((buffer->size - buffer->tail)<(size)?(buffer->size - buffer->tail):(size));
 left = size - right;
 memcpy(buffer->data + buffer->tail, dest, right);
 memcpy(buffer->data, dest + right, left);
 buffer->tail = (buffer->tail + size) % buffer->size;
 buffer->count += size;
 return size;
}


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

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

original_code:
int buffer_count(struct buffer_t *buffer)
{
 return buffer->count;
}


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

v0 = (_DWORD *)mhandle_calloc(1LL, 64LL, "opencl-mem.c:34");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_mem_create");
v1 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 7LL);
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, 64LL, "opencl-mem.c:34");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_mem_create");
v1 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 7LL);
v0[1] = 1;
*v0 = v1;
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

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

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


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

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

original_code:
void si_opencl_mem_free(struct si_opencl_mem_t *mem)
{
 si_opencl_repo_remove_object(si_emu->opencl_repo, mem);
 (mhandle_free(mem, "opencl-mem.c" ":" "52"));
}

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


decompiled_code:
__int64 frm_emu_done()
{
frm_cuda_object_free_all();
linked_list_free(frm_cuda_object_list);
frm_isa_done();
mem_free(*(_QWORD *)(frm_emu + 96));
mem_free(*(_QWORD *)(frm_emu + 232));
return mhandle_free(frm_emu, "emu.c:85");
}

canonical_decompiled_code:
__int64 func1()
{
frm_cuda_object_free_all();
linked_list_free(frm_cuda_object_list);
frm_isa_done();
mem_free(*(_QWORD *)(frm_emu + 96));
mem_free(*(_QWORD *)(frm_emu + 232));
return mhandle_free(frm_emu, "emu.c:85");
}

original_code:
void frm_emu_done(void)
{
 frm_cuda_object_free_all();
 linked_list_free(frm_cuda_object_list);
 frm_isa_done();
        mem_free(frm_emu->const_mem);
        mem_free(frm_emu->global_mem);
        (mhandle_free(frm_emu, "emu.c" ":" "85"));
}

canonical_original_code:
void frm_emu_done()
{
 frm_cuda_object_free_all();
 linked_list_free(frm_cuda_object_list);
 frm_isa_done();
        mem_free(frm_emu->const_mem);
        mem_free(frm_emu->global_mem);
        (mhandle_free(frm_emu, "emu.c" ":" "85"));
}


decompiled_code:
_BOOL8 __fastcall x86_cpu_pipeline_empty(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
_BOOL8 result; // rax

v2 = 1904LL * a2;
v3 = v2 + *(_QWORD *)(*x86_cpu + 1824LL * a1);
if ( *(_DWORD *)(v3 + 12) || (unsigned int)list_count(*(_QWORD *)(v3 + 56)) )
result = 0LL;
else
result = (unsigned int)list_count(*(_QWORD *)(*(_QWORD *)(*x86_cpu + 1824LL * a1) + v2 + 64)) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
_BOOL8 result; // rax

v2 = 1904LL * a2;
v3 = v2 + *(_QWORD *)(*x86_cpu + 1824LL * a1);
if ( *(_DWORD *)(v3 + 12) || (unsigned int)list_count(*(_QWORD *)(v3 + 56)) )
result = 0LL;
else
result = (unsigned int)list_count(*(_QWORD *)(*(_QWORD *)(*x86_cpu + 1824LL * a1) + v2 + 64)) == 0;
return result;
}

original_code:
int x86_cpu_pipeline_empty(int core, int thread)
{
 return !(x86_cpu->core[core].thread[thread]).rob_count && !list_count((x86_cpu->core[core].thread[thread]).fetch_queue) &&
  !list_count((x86_cpu->core[core].thread[thread]).uop_queue);
}

variable_types: core int

variable_types: thread int


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

result = 1LL;
if ( *a1 >= *a2 )
result = (unsigned int)-(*a1 > *a2);
return result;
}

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

result = 1LL;
if ( *a1 >= *a2 )
result = (unsigned int)-(*a1 > *a2);
return result;
}

original_code:
static int frm_warp_divergence_compare(const void *elem1, const void *elem2)
{
 const int count1 = * (const int *) elem1;
 const int count2 = * (const int *) elem2;
 if (count1 < count2)
  return 1;
 else if (count1 > count2)
  return -1;
 return 0;
}

canonical_original_code:
static int frm_warp_divergence_compare(void *elem1, void *elem2)
{
 int count1 = * (const int *) elem1;
 int count2 = * (const int *) elem2;
 if (count1 < count2)
  return 1;
 else if (count1 > count2)
  return -1;
 return 0;
}


repo: raphui/rnk

decompiled_code:
char *__fastcall elf_get_section(int a1)
{
return (char *)buff + section_size * a1 + (unsigned __int64)*(unsigned int *)(ehdr + 32);
}

canonical_decompiled_code:
char *__fastcall func7(int a1)
{
return (char *)buff + section_size * a1 + (unsigned __int64)*(unsigned int *)(ehdr + 32);
}

original_code:
static Elf32_Shdr *elf_get_section(int num)
{
 return (Elf32_Shdr *)(buff + ehdr->e_shoff + num * section_size);
}

canonical_original_code:
static struct Elf32_Shdr *elf_get_section(int num)
{
 return (struct Elf32_Shdr *)(buff + ehdr->e_shoff + num * section_size);
}

variable_types: num int

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


original_code:
static unsigned int hash_str(char *str)
{
 unsigned int hash = 5381;
 int c;
 while ((c = *str++))
  hash = ((hash << 5) + hash) + c;
 return hash;
}

variable_types:
str
char *

variable_types:
hash
unsigned int

variable_types: c int


cmpasc

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

result = *a1 > *a2;
if ( *a1 < *a2 )
result = 0xFFFFFFFFLL;
return result;
}

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

result = *a1 > *a2;
if ( *a1 < *a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int cmpasc(const void *input1, const void *input2)
{
        const int elem1 = *(int *) input1;
        const int elem2 = *(int *) input2;
        if(elem1 < elem2)
                return -1;
        if(elem1 > elem2)
                return 1;
        return 0;
}

canonical_original_code:
int cmpasc(void *input1, void *input2)
{
        int elem1 = *(int *) input1;
        int elem2 = *(int *) input2;
        if(elem1 < elem2)
                return -1;
        if(elem1 > elem2)
                return 1;
        return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
char *v4; // r12
char *v5; // r12
__int64 v6; // rsi
__int64 v7; // rsi
_BYTE v9[80]; // [rsp+0h] [rbp-68h] BYREF
char v10[24]; // [rsp+50h] [rbp-18h] BYREF

v3 = v9;
v4 = v9;
do
{
v4 += 4;
*((_DWORD *)v4 - 1) = rand() % 20;
}
while ( v4 != v10 );
v5 = v9;
printf("array: ");
do
{
v6 = *(unsigned int *)v5;
v5 += 4;
printf("%d, ", v6);
}
while ( v5 != v10 );
putchar(10);
hsort(v9, 20LL, 4LL, cmpasc);
printf("sorted output: ");
do
{
v7 = *(unsigned int *)v3;
v3 += 4;
printf("%d, ", v7);
}
while ( v3 != v10 );
putchar(10);
return 0;
}

original_code:
int main()
{
 block blk[20];
 int arr[20];
 int i;
 int output[20];
 int limit = 20 - 1, outcntr = 0;
 for(i = 0; i < 20; i++) {
  blk[i].id = 20 - i;
  arr[i] = rand() % 20;
 }
 printf("array: ");
 for(i = 0; i < 20; i++)
  printf("%d, ", arr[i]);
 printf("\n");
 hsort((void *) &arr, 20, sizeof(int), cmpasc);
 printf("sorted output: ");
 for(i = 0; i < 20; i++)
  printf("%d, ", arr[i]);
 printf("\n");
 return 0;
}

canonical_original_code:
int main()
{
 struct block blk[20];
 int arr[20];
 int i;
 int output[20];
 int limit = 20 - 1; int outcntr = 0;
 for(i = 0; i < 20; i++) {
  blk[i].id = 20 - i;
  arr[i] = rand() % 20;
 }
 printf("array: ");
 for(i = 0; i < 20; i++)
  printf("%d, ", arr[i]);
 printf("\n");
 hsort((void *) &arr, 20, sizeof(int), cmpasc);
 printf("sorted output: ");
 for(i = 0; i < 20; i++)
  printf("%d, ", arr[i]);
 printf("\n");
 return 0;
}

variable_types: struct block { int id; char name[20]; } [20]

variable_types:
arr
int [20]

variable_types: i int

variable_types:
output
int [20]

variable_types: limit int

variable_types: outcntr int


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
putchar(10);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
perror(a1);
putchar(10);
exit(1);
}

original_code:
void error(char *msg)
{
   perror(msg);
   printf("\n");
   exit(1);
}

variable_types:
msg
char *


decompiled_code:
int __fastcall close_sock(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int __fastcall func5(int fd)
{
return close(fd);
}

original_code:
void close_sock(int sock)
{
   close(sock);
}

variable_types: sock int


swap

original_code:
static void swap(char *num1, char *num2, unsigned width) {
 char tmp;
 if (num1 != num2) {
  while (width--) {
   tmp = *num1;
   *num1++ = *num2;
   *num2++ = tmp;
      }
   }
}

canonical_original_code:
static void swap(char *num1, char *num2, unsigned int width) {
 char tmp;
 if (num1 != num2) {
  while (width--) {
   tmp = *num1;
   *num1++ = *num2;
   *num2++ = tmp;
      }
   }
}

variable_types:
width
unsigned int

variable_types: tmp char


sift

original_code:
static void sift(void *base, unsigned mid, unsigned num, unsigned width, int (*comp)(const void *, const void *))
{
 int left, right;
 int small;
 char *rchild, *lchild;
 char *midchild, *smallchild;
 while(mid < floor(num / 2)) {
  left = (mid + 1) * 2 - 1;
  right = left + 1;
  lchild = (char *) base + left * width;
  rchild = (char *) base + right * width;
  if(right < num && comp(lchild, rchild) < 0)
   small = right;
  else
   small = left;
  midchild = (char *) base + mid * width;
  smallchild = (char *) base + small * width;
  if(comp(midchild, smallchild) > 0)
   return;
  swap(midchild, smallchild, width);
  mid = small;
 }
}

canonical_original_code:
static void sift(void *base, unsigned int mid, unsigned int num, unsigned int width, int (*comp)(void *, void *))
{
 int left; int right;
 int small;
 char *rchild; char *lchild;
 char *midchild; char *smallchild;
 while(mid < floor(num / 2)) {
  left = (mid + 1) * 2 - 1;
  right = left + 1;
  lchild = (char *) base + left * width;
  rchild = (char *) base + right * width;
  if(right < num && comp(lchild, rchild) < 0)
   small = right;
  else
   small = left;
  midchild = (char *) base + mid * width;
  smallchild = (char *) base + small * width;
  if(comp(midchild, smallchild) > 0)
   return;
  swap(midchild, smallchild, width);
  mid = small;
 }
}

variable_types:
base
void *

variable_types:
mid
unsigned int

variable_types:
num
unsigned int

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

variable_types: left int

variable_types: right int

variable_types: small int

variable_types:
rchild
char *

variable_types:
lchild
char *

variable_types:
midchild
char *

variable_types:
smallchild
char *


heapify

decompiled_code:
void __fastcall heapify(__int64 a1, unsigned int a2, int a3, __int64 (__fastcall *a4)(__int64, char *))
{
unsigned int v6; // ebx

v6 = a2 >> 1;
do
sift(a1, --v6, a2, a3, a4);
while ( v6 != -1 );
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, unsigned int a2, int a3, __int64 (__fastcall *a4)(__int64, char *))
{
unsigned int v6; // ebx

v6 = a2 >> 1;
do
func1(a1, --v6, a2, a3, a4);
while ( v6 != -1 );
}

original_code:
static void heapify(void *base, unsigned num, unsigned width, int (*comp)(const void *, const void *))
{
 int mid;
 mid = floor(num / 2);
 while(mid >= 0) {
  sift(base, mid - 1, num, width, comp);
  mid--;
 }
}

canonical_original_code:
static void heapify(void *base, unsigned int num, unsigned int width, int (*comp)(void *, void *))
{
 int mid;
 mid = floor(num / 2);
 while(mid >= 0) {
  sift(base, mid - 1, num, width, comp);
  mid--;
 }
}

variable_types: mid int


hsort

decompiled_code:
void __fastcall hsort(char *a1, unsigned int a2, int a3, __int64 (__fastcall *a4)(__int64, char *))
{
unsigned int v6; // ebx
unsigned int v7; // er12
__int64 v8; // rsi
unsigned int v9; // edx

if ( a2 )
{
v6 = a2 - 1;
heapify((__int64)a1, a2, a3, a4);
v7 = a3 * (a2 - 1);
while ( 1 )
{
v8 = v7;
v7 -= a3;
swap(a1, &a1[v8], a3);
if ( !v6 )
break;
v9 = v6--;
sift((__int64)a1, 0, v9, a3, a4);
}
}
}

canonical_decompiled_code:
void __fastcall func3(char *a1, unsigned int a2, int a3, __int64 (__fastcall *a4)(__int64, char *))
{
unsigned int v6; // ebx
unsigned int v7; // er12
__int64 v8; // rsi
unsigned int v9; // edx

if ( a2 )
{
v6 = a2 - 1;
func2((__int64)a1, a2, a3, a4);
v7 = a3 * (a2 - 1);
while ( 1 )
{
v8 = v7;
v7 -= a3;
func0(a1, &a1[v8], a3);
if ( !v6 )
break;
v9 = v6--;
func1((__int64)a1, 0, v9, a3, a4);
}
}
}

original_code:
void hsort(void *base, unsigned num, unsigned width, int (*comp)(const void *, const void *))
{
 char *next;
 char *last;
 int i;
 if(num == 0)
  return;
 heapify(base, num, width, comp);
 do
 {
  next = base;
  last = (char *) base + (num - 1) * width;
  swap(next, last, width);
  num--;
  if(num > 0) {
   sift(base, 0, num, width, comp);
  }
 }while(num > 0);
}

canonical_original_code:
void hsort(void *base, unsigned int num, unsigned int width, int (*comp)(void *, void *))
{
 char *next;
 char *last;
 int i;
 if(num == 0)
  return;
 heapify(base, num, width, comp);
 do
 {
  next = base;
  last = (char *) base + (num - 1) * width;
  swap(next, last, width);
  num--;
  if(num > 0) {
   sift(base, 0, num, width, comp);
  }
 }while(num > 0);
}

variable_types:
next
char *

variable_types:
last
char *

variable_types: i int


decompiled_code:
__int64 __fastcall connect_to(int fd, char *name, __int16 a3)
{
const char *v4; // rdx
struct hostent *v5; // rbp
size_t v6; // rdx
socklen_t v7; // edx
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

v5 = gethostbyname(name);
if ( !v5 )
error((int)"No such host", (int)name, v4);
v6 = v5->h_length;
v9[0] = 0LL;
v9[0].sa_family = 2;
memmove(&v9[0].sa_data[2], *(const void **)v5->h_addr_list, v6);
*(_WORD *)v9[0].sa_data = _bswap_16(a3);
return (unsigned int)(connect(fd, v9, v7) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, char *name, __int16 a3)
{
const char *v4; // rdx
struct hostent *v5; // rbp
size_t v6; // rdx
socklen_t v7; // edx
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

v5 = gethostbyname(name);
if ( !v5 )
error((int)"No such host", (int)name, v4);
v6 = v5->h_length;
v9[0] = 0LL;
v9[0].sa_family = 2;
memmove(&v9[0].sa_data[2], *(const void **)v5->h_addr_list, v6);
*(_WORD *)v9[0].sa_data = func0(a3);
return (unsigned int)(connect(fd, v9, v7) >> 31);
}

original_code:
int connect_to(int sock, char *server_addr, int port)
{
 struct sockaddr_in sin_serversock;
 struct hostent *h_server;
  h_server = gethostbyname(server_addr);
  if(h_server == ((void *)0))
  {
    error("No such host");
  }
  bzero((char *) &sin_serversock, sizeof(sin_serversock));
  sin_serversock.sin_family = 2;
  bcopy((char *) h_server->h_addr_list[0],
    (char *) &sin_serversock.sin_addr.s_addr,
    h_server->h_length);
  sin_serversock.sin_port = htons(port);
  if(connect(sock, (struct sockaddr *) &sin_serversock, sizeof(sin_serversock)) < 0)
  {
  return -1;
  }
  return 0;
}

variable_types: sock int

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
int __fastcall read_my_ip(char *s, char *src)
{
int v2; // ebp
char v4[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v5; // [rsp+10h] [rbp-38h]
unsigned int v6; // [rsp+14h] [rbp-34h]

v2 = socket(2, 1, 0);
v5 = 2;
strncpy(v4, src, 0xFuLL);
ioctl(v2, 0x8915uLL, v4);
close(v2);
return sprintf(s, "%d.%d.%d.%d", (unsigned __int8)v6, BYTE1(v6), BYTE2(v6), HIBYTE(v6));
}

canonical_decompiled_code:
int __fastcall func2(char *s, char *src)
{
int v2; // ebp
char v4[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v5; // [rsp+10h] [rbp-38h]
unsigned int v6; // [rsp+14h] [rbp-34h]

v2 = socket(2, 1, 0);
v5 = 2;
strncpy(v4, src, 0xFuLL);
ioctl(v2, 0x8915uLL, v4);
close(v2);
return sprintf(s, "%d.%d.%d.%d", (unsigned __int8)v6, BYTE1(v6), BYTE2(v6), HIBYTE(v6));
}

original_code:
void read_my_ip(char ip[50], char *interface)
{
  int fd;
  struct ifreq ifr;
  struct sockaddr_in *client;
  fd = socket(2, SOCK_STREAM, 0);
  ifr.ifr_ifru.ifru_addr.sa_family = 2;
  strncpy(ifr.ifr_ifrn.ifrn_name, interface, 16 -1);
  ioctl(fd, 0x8915, &ifr);
  close(fd);
  client = (struct sockaddr_in *) &ifr.ifr_ifru.ifru_addr;
  sprintf(ip, "%d.%d.%d.%d", (int)(client->sin_addr.s_addr&0xFF),
     (int)((client->sin_addr.s_addr&0xFF00)>>8),
     (int)((client->sin_addr.s_addr&0xFF0000)>>16),
     (int)((client->sin_addr.s_addr&0xFF000000)>>24));
}

variable_types:
ip
char [50]

variable_types:
interface
char *

variable_types: fd int

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
int __fastcall listen_sock(int a1)
{
return listen(a1, 5);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
return listen(a1, 5);
}

original_code:
void listen_sock(int sock)
{
  listen(sock, 5);
}


decompiled_code:
int __fastcall accept_con(int a1)
{
int result; // eax
const char *v2; // rdx
int v3; // [rsp+Ch] [rbp-2Ch]
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

addr_len = 16;
result = accept(a1, &addr, &addr_len);
if ( result < 0 )
{
v3 = result;
error((int)"error while accepting connection", (int)&addr, v2);
result = v3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
int result; // eax
const char *v2; // rdx
int v3; // [rsp+Ch] [rbp-2Ch]
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

addr_len = 16;
result = accept(a1, &addr, &addr_len);
if ( result < 0 )
{
v3 = result;
error((int)"error while accepting connection", (int)&addr, v2);
result = v3;
}
return result;
}

original_code:
int accept_con(int sock)
{
  struct sockaddr_in client;
  int client_len = sizeof(client);
  int csock;
  char req_from[50];
  csock = accept(sock, (struct sockaddr *) &client, &client_len);
  if(csock < 0)
     error("error while accepting connection");
  else
  {
  }
  return csock;
}

variable_types: csock int


decompiled_code:
__int64 __fastcall my_add(int a1, int a2)
{
unsigned int v2; // er8
int v3; // eax
int v4; // esi
int v5; // edx

v2 = a2 ^ a1;
v3 = a2 ^ a1;
v4 = a1 & a2;
if ( v4 )
{
do
{
v5 = 2 * v4;
v4 = v3 & (2 * v4);
v3 ^= v5;
}
while ( v4 );
v2 = v3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
unsigned int v2; // er8
int v3; // eax
int v4; // esi
int v5; // edx

v2 = a2 ^ a1;
v3 = a2 ^ a1;
v4 = a1 & a2;
if ( v4 )
{
do
{
v5 = 2 * v4;
v4 = v3 & (2 * v4);
v3 ^= v5;
}
while ( v4 );
v2 = v3;
}
return v2;
}

original_code:
unsigned int my_add(unsigned int a, unsigned int b)
{
    int mask = 0, result = 0;
    result = a ^ b;
    mask = a & b;
    while (mask!=0) {
        int shifted = mask << 1;
        mask = result & shifted;
        result ^= shifted;
    }
    return result;
}

canonical_original_code:
unsigned int my_add(unsigned int a, unsigned int b)
{
    int mask = 0; int result = 0;
    result = a ^ b;
    mask = a & b;
    while (mask!=0) {
        int shifted = mask << 1;
        mask = result & shifted;
        result ^= shifted;
    }
    return result;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types: mask int

variable_types: result int

variable_types: shifted int


binaryCount

decompiled_code:
int __fastcall binaryCount(unsigned int a1)
{
int result; // eax

if ( a1 )
{
binaryCount(a1 >> 1);
result = printf("%d", a1 & 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
int result; // eax

if ( a1 )
{
func8(a1 >> 1);
result = printf("%d", a1 & 1);
}
return result;
}

original_code:
void binaryCount(unsigned int n){
    if (n<2 && n%2==0) {
        ;
    }
    else{
        binaryCount(n/2);
        printf("%d",n%2);
    }
}

variable_types:
n
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er10
unsigned int v4; // er9
__int64 v5; // rbp
unsigned int v7; // [rsp+8h] [rbp-10h]
unsigned int v8; // [rsp+Ch] [rbp-Ch]

printf("Please enter two numbers to sum:");
while ( (unsigned int)__isoc99_scanf() != -1 )
{
v5 = (unsigned int)my_add(v7, v8);
printf("\n%d + %d (base 10) = %d\n", v4, v3, v5);
printf("%d + %d (base 2) = ", v7, v8);
binaryCount((unsigned int)v5);
putchar(10);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er10
unsigned int v4; // er9
__int64 v5; // rbp
unsigned int v7; // [rsp+8h] [rbp-10h]
unsigned int v8; // [rsp+Ch] [rbp-Ch]

printf("Please enter two numbers to sum:");
while ( (unsigned int)__isoc99_scanf() != -1 )
{
v5 = (unsigned int)func7(v7, v8);
printf("\n%d + %d (base 10) = %d\n", v4, v3, v5);
printf("%d + %d (base 2) = ", v7, v8);
func8((unsigned int)v5);
putchar(10);
}
return 0;
}

original_code:
int main()
{
    unsigned int a, b;
    printf("Please enter two numbers to sum:");
    while (scanf("%u%u",&a, &b)!=(-1))
    {
    int result = my_add(a, b);
    printf("\n%d + %d (base 10) = %d\n", a, b, result);
    printf("%d + %d (base 2) = ", a, b);
    binaryCount(result);
    printf("\n");
    }
    return 0;
}

canonical_original_code:
int main()
{
    unsigned int a; unsigned int b;
    printf("Please enter two numbers to sum:");
    while (scanf("%u%u",&a, &b)!=(-1))
    {
    int result = my_add(a, b);
    printf("\n%d + %d (base 10) = %d\n", a, b, result);
    printf("%d + %d (base 2) = ", a, b);
    binaryCount(result);
    printf("\n");
    }
    return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char v5[1016]; // [rsp+0h] [rbp-3F8h] BYREF

puts("\nEnter A String:");
while ( 1 )
{
v3 = fgets(v5, 1000, _bss_start);
if ( !v3 )
break;
printArray(v5);
}
return (int)v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char v5[1016]; // [rsp+0h] [rbp-3F8h] BYREF

puts("\nEnter A String:");
while ( 1 )
{
v3 = fgets(v5, 1000, _bss_start);
if ( !v3 )
break;
func7(v5);
}
return (int)v3;
}

original_code:
int main()
{
 printf("\nEnter A String:\n");
 char a [1000];
 while(fgets(a, 1000, stdin))
  printArray(a);
 return 0;
}

canonical_original_code:
int main()
{
 printf("\nEnter A String:\n");
 char a[1000];
 while(fgets(a, 1000, stdin))
  printArray(a);
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
unsigned int v4; // ebp
int v6; // [rsp+Ch] [rbp-ECh] BYREF
char v7[232]; // [rsp+10h] [rbp-E8h] BYREF

puts("Enter up to 50 numbers to get a summary of them:");
LABEL_2:
v3 = v7;
v4 = 0;
while ( scanf("%d", &v6) == 1 )
{
++v4;
v3 += 4;
*((_DWORD *)v3 - 1) = v6;
if ( getchar() == 10 )
{
summary(v7, v4);
putchar(10);
goto LABEL_2;
}
}
summary(v7, v4);
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
unsigned int v4; // ebp
int v6; // [rsp+Ch] [rbp-ECh] BYREF
char v7[232]; // [rsp+10h] [rbp-E8h] BYREF

puts("Enter up to 50 numbers to get a summary of them:");
LABEL_2:
v3 = v7;
v4 = 0;
while ( scanf("%d", &v6) == 1 )
{
++v4;
v3 += 4;
*((_DWORD *)v3 - 1) = v6;
if ( getchar() == 10 )
{
func8(v7, v4);
putchar(10);
goto LABEL_2;
}
}
func8(v7, v4);
putchar(10);
return 0;
}

original_code:
int main(){
 int k;
 int length=0;
 int userArray[50];
 printf("Enter up to 50 numbers to get a summary of them:\n");
 while((scanf("%d", &k) ==1)){
  userArray[length] = k;
  length++;
  if(getchar() == '\n'){
   summary(userArray, length);
   length = 0;
   printf("\n");
  }
 }
 summary(userArray, length);
 printf("\n");
 return 0;
}

canonical_original_code:
int main(){
 int k;
 int length = 0;
 int userArray[50];
 printf("Enter up to 50 numbers to get a summary of them:\n");
 while((scanf("%d", &k) ==1)){
  userArray[length] = k;
  length++;
  if(getchar() == '\n'){
   summary(userArray, length);
   length = 0;
   printf("\n");
  }
 }
 summary(userArray, length);
 printf("\n");
 return 0;
}

variable_types: k int

variable_types: length int

variable_types:
userArray
int [50]


printArray

decompiled_code:
int __fastcall printArray(__int64 a1, int a2, int a3)
{
unsigned int *v3; // rbx
unsigned __int64 v4; // rbp
__int64 v5; // rsi
int result; // eax

if ( a3 != a2 )
{
v3 = (unsigned int *)(a1 + 4LL * a2);
v4 = a1 + 4 * (a2 + (unsigned __int64)(unsigned int)(~a2 + a3)) + 4;
do
{
v5 = *v3++;
result = printf("%d ", v5);
}
while ( v3 != (unsigned int *)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2, int a3)
{
unsigned int *v3; // rbx
unsigned __int64 v4; // rbp
__int64 v5; // rsi
int result; // eax

if ( a3 != a2 )
{
v3 = (unsigned int *)(a1 + 4LL * a2);
v4 = a1 + 4 * (a2 + (unsigned __int64)(unsigned int)(~a2 + a3)) + 4;
do
{
v5 = *v3++;
result = printf("%d ", v5);
}
while ( v3 != (unsigned int *)v4 );
}
return result;
}

original_code:
void printArray(int array[], int from, int to){
 if(from==to){
  return;
 }
 else{
  printf("%d ", array[from]);
  printArray(array, from+1, to);
 }
}

variable_types:
array
int []

variable_types: from int

variable_types: to int


summary

decompiled_code:
void __fastcall summary(__int64 a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp
__int64 v4; // rax
int v5; // edx

v2 = malloc(4LL * a2 + 1);
if ( !v2 )
{
printf("memory allocation failed!");
exit(0);
}
v3 = v2;
v4 = 0LL;
v5 = 0;
if ( a2 > 0 )
{
do
{
v5 += *(_DWORD *)(a1 + 4 * v4);
v3[v4++] = v5;
}
while ( a2 != v4 );
}
v3[a2] = 0;
printArray((__int64)v3, 0, a2);
free(v3);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp
__int64 v4; // rax
int v5; // edx

v2 = malloc(4LL * a2 + 1);
if ( !v2 )
{
printf("memory allocation failed!");
exit(0);
}
v3 = v2;
v4 = 0LL;
v5 = 0;
if ( a2 > 0 )
{
do
{
v5 += *(_DWORD *)(a1 + 4 * v4);
v3[v4++] = v5;
}
while ( a2 != v4 );
}
v3[a2] = 0;
func7((__int64)v3, 0, a2);
free(v3);
}

original_code:
void summary(int a[], int length){
 int i;
 int counter = 0;
 int *p;
 p = (int *) malloc(length * sizeof(int) + 1);
 if(!p){
  printf("memory allocation failed!");
  exit(0);
 }
 for(i=0 ; i<length ; i++){
  counter+=a[i];
  p[i] = counter;
 }
 p[length] = '\0';
 printArray(p, 0, length);
 free(p);
}

variable_types:
a
int []

variable_types: i int

variable_types: counter int

variable_types:
p
int *


repo: raspberry-alpha-omega/corn-mainline

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

result = raspi_set_gpio_level(17LL, a1);
p17 = a1;
return result;
}

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

result = raspi_set_gpio_level(17LL, a1);
p17 = a1;
return result;
}

original_code:
void pin17(enum gpio_level level) {
  raspi_set_gpio_level(17, level);
  p17 = level;
}

variable_types: enum gpio_level { GPIO_LOW=0, GPIO_HIGH=1 }


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

result = raspi_set_gpio_level(21LL, a1);
p21 = a1;
return result;
}

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

result = raspi_set_gpio_level(21LL, a1);
p21 = a1;
return result;
}

original_code:
void pin21(enum gpio_level level) {
  raspi_set_gpio_level(21, level);
  p21 = level;
}

user_defined_types: enum gpio_level { GPIO_LOW=0, GPIO_HIGH=1 }


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

result = raspi_set_gpio_level(22LL, a1);
p22 = a1;
return result;
}

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

result = raspi_set_gpio_level(22LL, a1);
p22 = a1;
return result;
}

original_code:
void pin22(enum gpio_level level) {
  raspi_set_gpio_level(22, level);
  p22 = level;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
unsigned int v4; // er13
unsigned int v5; // er12
int v6; // ebx

v3 = 0;
v4 = 0;
v5 = 0;
v6 = 16;
puts("tests go here!");
pwm_init(15LL, argv);
pwm_set_slot(0LL, pin17);
pwm_set_cycle(0LL, 8LL);
pwm_set_slot(1LL, pin21);
pwm_set_cycle(1LL, 4LL);
pwm_set_slot(2LL, pin22);
pwm_set_cycle(2LL, 2LL);
do
{
pwm_tick();
v3 += p17 == 1;
v4 += p21 == 1;
v5 += p22 == 1;
--v6;
}
while ( v6 );
printf("p17, cycle=%x total=%d\n", 8LL, v3);
printf("p21, cycle=%x total=%d\n", 4LL, v4);
printf("p22, cycle=%x total=%d\n", 2LL, v5);
return 0;
}

original_code:
int main() {
  puts("tests go here!");
  pwm_init(0b1111);
  pwm_set_slot(0, &pin17);
  pwm_set_cycle(0, 0b1000);
  pwm_set_slot(1, &pin21);
  pwm_set_cycle(1, 0b0100);
  pwm_set_slot(2, &pin22);
  pwm_set_cycle(2, 0b0010);
  int p17_total = 0;
  int p21_total = 0;
  int p22_total = 0;
  for (int i = 0; i < 16; ++i) {
    pwm_tick();
    if (p17 == GPIO_HIGH) ++ p17_total;
    if (p21 == GPIO_HIGH) ++ p21_total;
    if (p22 == GPIO_HIGH) ++ p22_total;
  }
  printf("p17, cycle=%x total=%d\n", 0b1000, p17_total);
  printf("p21, cycle=%x total=%d\n", 0b0100, p21_total);
  printf("p22, cycle=%x total=%d\n", 0b0010, p22_total);
}


decompiled_code:
void __fastcall morse_set_switch(void *a1)
{
switcher = a1;
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
switcher = a1;
}

original_code:
void morse_set_switch(switch_fn fn) {
  switcher = fn;
}

canonical_original_code:
void morse_set_switch(void (*fn)(enum gpio_level)) {
  switcher = fn;
}

variable_types: void (*)(enum gpio_level { GPIO_LOW=0, GPIO_HIGH=1 })


decompiled_code:
__int64 __fastcall switch_off(unsigned int a1)
{
switcher(0LL);
return raspi_timer_wait(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
switcher(0LL);
return raspi_timer_wait(a1);
}

original_code:
void switch_off(int duration) {
  switcher(GPIO_LOW);
  raspi_timer_wait(duration);
}

variable_types: duration int


decompiled_code:
__int64 __fastcall switch_on(unsigned int a1)
{
switcher(1LL);
return raspi_timer_wait(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
switcher(1LL);
return raspi_timer_wait(a1);
}

original_code:
void switch_on(int duration) {
  switcher(GPIO_HIGH);
  raspi_timer_wait(duration);
}


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

if ( a1 == 45 )
{
switch_on(0x6DDD0u);
result = switch_off(0x249F0u);
}
else
{
if ( a1 == 46 )
switch_on(0x249F0u);
else
raspi_timer_wait(1050000LL);
result = switch_off(0x249F0u);
}
return result;
}

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

if ( a1 == 45 )
{
func2(0x6DDD0u);
result = func1(0x249F0u);
}
else
{
if ( a1 == 46 )
func2(0x249F0u);
else
raspi_timer_wait(1050000LL);
result = func1(0x249F0u);
}
return result;
}

original_code:
void morse_glyph(char c) {
  switch(c) {
  case '.':
    switch_on(150000);
    break;
  case '-':
    switch_on((150000 * 3));
    break;
  default:
    raspi_timer_wait((150000 * 7));
    break;
  }
  switch_off(150000);
}

variable_types: c char


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

result = 0LL;
while ( LOBYTE(code[2 * result]) != a1 )
{
if ( ++result == 37 )
return result;
}
return morse_symbol((char *)code[2 * (int)result + 1]);
}

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

result = 0LL;
while ( LOBYTE(code[2 * result]) != a1 )
{
if ( ++result == 37 )
return result;
}
return func4((char *)code[2 * (int)result + 1]);
}

original_code:
void morse_char(char c) {
  for (int i = 0; i < nchars; ++i) {
    if (c == code[i].letter) {
      morse_symbol(code[i].symbol);
      return;
    }
  }
}


decompiled_code:
__int64 __fastcall morse_string(char *a1)
{
char *v1; // rbx
char i; // di
__int64 result; // rax

v1 = a1;
for ( i = *a1; i; ++v1 )
{
result = morse_char(i);
i = v1[1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
char *v1; // rbx
char i; // di
__int64 result; // rax

v1 = a1;
for ( i = *a1; i; ++v1 )
{
result = func5(i);
i = v1[1];
}
return result;
}

original_code:
void morse_string(const char* message) {
  for (char c = *message; c != 0; c = *++message) {
    morse_char(c);
  }
}

canonical_original_code:
void morse_string(char *message) {
  for (char c = *message; c != 0; c = *++message) {
    morse_char(c);
  }
}

variable_types:
message
char *


decompiled_code:
__int64 __fastcall flash_dots(int a1)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
morse_glyph(46);
}
return raspi_timer_wait(450000LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
func3(46);
}
return raspi_timer_wait(450000LL);
}

original_code:
void flash_dots(int ndots) {
  for (int i = 0; i < ndots; ++i) {
    morse_glyph('.');
  }
  raspi_timer_wait((150000 * 3));
}

variable_types: ndots int


halt

decompiled_code:
void __fastcall __noreturn halt(char *a1)
{
while ( 1 )
morse_string(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(char *a1)
{
while ( 1 )
func6(a1);
}

original_code:
void halt(const char* message) {
  for (;;) {
    morse_string(message);
  }
}

canonical_original_code:
void halt(char *message) {
  for (;;) {
    morse_string(message);
  }
}


decompiled_code:
int __fastcall raspi_set_gpio_direction(unsigned int a1, unsigned int a2)
{
return printf("%s: pin=%d dir=%d\n", "raspi_set_gpio_direction", a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, unsigned int a2)
{
return printf("%s: pin=%d dir=%d\n", "raspi_set_gpio_direction", a1, a2);
}

original_code:
void raspi_set_gpio_direction(int pin, enum gpio_direction direction) {
  printf("%s: pin=%d dir=%d\n", __FUNCTION__, pin, direction);
}

variable_types: pin int

variable_types: enum gpio_direction { GPIO_INPUT=0, GPIO_OUTPUT=1 }


decompiled_code:
int __fastcall raspi_set_gpio_level(unsigned int a1, unsigned int a2)
{
return printf("%s: pin=%d level=%d\n", "raspi_set_gpio_level", a1, a2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, unsigned int a2)
{
return printf("%s: pin=%d level=%d\n", "raspi_set_gpio_level", a1, a2);
}

original_code:
void raspi_set_gpio_level(int pin, enum gpio_level level) {
  printf("%s: pin=%d level=%d\n", __FUNCTION__, pin, level);
}


decompiled_code:
__int64 __fastcall raspi_get_gpio_level(unsigned int a1)
{
printf("%s: pin=%d\n", "raspi_get_gpio_level", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
printf("%s: pin=%d\n", "raspi_get_gpio_level", a1);
return 0LL;
}

original_code:
enum gpio_level raspi_get_gpio_level(int pin) {
  printf("%s: pin=%d\n", __FUNCTION__, pin);
  return GPIO_LOW;
}

return_type: enum gpio_level { GPIO_LOW=0, GPIO_HIGH=1 }


decompiled_code:
int __fastcall raspi_okled_set(unsigned int a1)
{
return printf("%s: level=%d\n", "raspi_okled_set", a1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
return printf("%s: level=%d\n", "raspi_okled_set", a1);
}

original_code:
void raspi_okled_set(enum gpio_level level) {
  printf("%s: level=%d\n", __FUNCTION__, level);
}


decompiled_code:
int __fastcall raspi_timer_wait(unsigned int a1)
{
return printf("%s: usec=%d\n", "raspi_timer_wait", a1);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1)
{
return printf("%s: usec=%d\n", "raspi_timer_wait", a1);
}

original_code:
void raspi_timer_wait(int usec) {
  printf("%s: usec=%d\n", __FUNCTION__, usec);
}

variable_types: usec int


decompiled_code:
int __fastcall raspi_mini_uart_send_char(char a1)
{
return printf("%s: c=%c\n", "raspi_mini_uart_send_char", (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func5(char a1)
{
return printf("%s: c=%c\n", "raspi_mini_uart_send_char", (unsigned int)a1);
}

original_code:
void raspi_mini_uart_send_char(char c) {
  printf("%s: c=%c\n", __FUNCTION__, c);
}


decompiled_code:
int __fastcall raspi_mini_uart_send_string(__int64 a1)
{
return printf("%s: s=[%c]\n", "raspi_mini_uart_send_string", a1);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
return printf("%s: s=[%c]\n", "raspi_mini_uart_send_string", a1);
}

original_code:
void raspi_mini_uart_send_string(const char* s) {
  printf("%s: s=[%c]\n", __FUNCTION__, s);
}

canonical_original_code:
void raspi_mini_uart_send_string(char *s) {
  printf("%s: s=[%c]\n", __FUNCTION__, s);
}

variable_types:
s
char *


decompiled_code:
int __fastcall raspi_mini_uart_send_hex(unsigned int a1)
{
return printf("%s: hex=[%08x]\n", "raspi_mini_uart_send_hex", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("%s: hex=[%08x]\n", "raspi_mini_uart_send_hex", a1);
}

original_code:
void raspi_mini_uart_send_hex(uint32_t n) {
  printf("%s: hex=[%08x]\n", __FUNCTION__, n);
}

canonical_original_code:
void raspi_mini_uart_send_hex(unsigned int n) {
  printf("%s: hex=[%08x]\n", __FUNCTION__, n);
}

variable_types:
n
unsigned int


decompiled_code:
int raspi_mini_uart_send_newline()
{
return printf("%s:\n", "raspi_mini_uart_send_newline");
}

canonical_decompiled_code:
int func8()
{
return printf("%s:\n", "raspi_mini_uart_send_newline");
}

original_code:
void raspi_mini_uart_send_newline(void) {
  printf("%s:\n", __FUNCTION__);
}

canonical_original_code:
void raspi_mini_uart_send_newline() {
  printf("%s:\n", __FUNCTION__);
}


decompiled_code:
int raspi_okled_init()
{
return printf("%s:\n", "raspi_okled_init");
}

canonical_decompiled_code:
int func9()
{
return printf("%s:\n", "raspi_okled_init");
}

original_code:
void raspi_okled_init() {
  printf("%s:\n", __FUNCTION__);
}


decompiled_code:
int raspi_mini_uart_init()
{
return printf("%s:\n", "raspi_mini_uart_init");
}

canonical_decompiled_code:
int func10()
{
return printf("%s:\n", "raspi_mini_uart_init");
}

original_code:
void raspi_mini_uart_init() {
  printf("%s:\n", __FUNCTION__);
}


decompiled_code:
__int64 *pwm_init()
{
__int64 *result; // rax

result = &slots;
do
{
*result = 0LL;
result += 2;
*((_DWORD *)result - 2) = 0;
*((_DWORD *)result - 1) = 0;
}
while ( result != (__int64 *)&unk_160 );
pwm_clock = 0;
pwm_mask = 255;
return result;
}

canonical_decompiled_code:
__int64 *func0()
{
__int64 *result; // rax

result = &slots;
do
{
*result = 0LL;
result += 2;
*((_DWORD *)result - 2) = 0;
*((_DWORD *)result - 1) = 0;
}
while ( result != (__int64 *)&unk_160 );
pwm_clock = 0;
pwm_mask = 255;
return result;
}

original_code:
void pwm_init(uint32_t mask) {
  for (int i = 0; i < 8; ++i) {
    slots[i].fn = 0;
    slots[i].cycle = 0;
    slots[i].state = 0;
  }
  pwm_clock = 0;
  pwm_mask = 0xFF;
}

canonical_original_code:
void pwm_init(unsigned int mask) {
  for (int i = 0; i < 8; ++i) {
    slots[i].fn = 0;
    slots[i].cycle = 0;
    slots[i].state = 0;
  }
  pwm_clock = 0;
  pwm_mask = 0xFF;
}

variable_types:
mask
unsigned int


decompiled_code:
void __fastcall pwm_set_slot(int a1, __int64 a2)
{
slots[2 * a1] = a2;
}

canonical_decompiled_code:
void __fastcall func1(int a1, __int64 a2)
{
slots[2 * a1] = a2;
}

original_code:
void pwm_set_slot(int slot, switch_fn fn) {
  slots[slot].fn = fn;
}

canonical_original_code:
void pwm_set_slot(int slot, void (*fn)(enum gpio_level)) {
  slots[slot].fn = fn;
}

variable_types: slot int


decompiled_code:
void __fastcall pwm_set_cycle(int a1, int a2)
{
dword_E8[4 * a1] = a2;
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
dword_E8[4 * a1] = a2;
}

original_code:
void pwm_set_cycle(int slot, uint32_t bits) {
  slots[slot].cycle = bits;
}

canonical_original_code:
void pwm_set_cycle(int slot, unsigned int bits) {
  slots[slot].cycle = bits;
}

variable_types:
bits
unsigned int


RegRead

repo: raspberry-alpha-omega/ledborg-source

decompiled_code:
__int64 __fastcall RegRead(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( *(_QWORD *)a1 == -1LL )
{
printf("RegRead failed due to an unmapped base (%s)!\n", (const char *)(a1 + 16));
result = 0LL;
}
else if ( *(_DWORD *)(a1 + 12) <= a2 )
{
printf("RegRead failed due to address out of bounds (%s, 0x%08X)!\n", (const char *)(a1 + 16), a2);
result = 0LL;
}
else
{
result = *(unsigned int *)(*(_QWORD *)a1 + a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( *(_QWORD *)a1 == -1LL )
{
printf("RegRead failed due to an unmapped base (%s)!\n", (const char *)(a1 + 16));
result = 0LL;
}
else if ( *(_DWORD *)(a1 + 12) <= a2 )
{
printf("RegRead failed due to address out of bounds (%s, 0x%08X)!\n", (const char *)(a1 + 16), a2);
result = 0LL;
}
else
{
result = *(unsigned int *)(*(_QWORD *)a1 + a2);
}
return result;
}

original_code:
unsigned int RegRead(raw_memory *base, unsigned int address) {
 if (base->accessor == ((void *) -1)) {
  printf("RegRead failed due to an unmapped base (%s)!\n", base->name);
  return 0;
 } else if (address >= base->length) {
  printf("RegRead failed due to address out of bounds (%s, 0x%08X)!\n", base->name, address);
  return 0;
 } else {
  unsigned int value = *((unsigned int *)(base->accessor + address));
  return value;
 }
}

canonical_original_code:
unsigned int RegRead(struct raw_memory *base, unsigned int address) {
 if (base->accessor == ((void *) -1)) {
  printf("RegRead failed due to an unmapped base (%s)!\n", base->name);
  return 0;
 } else if (address >= base->length) {
  printf("RegRead failed due to address out of bounds (%s, 0x%08X)!\n", base->name, address);
  return 0;
 } else {
  unsigned int value = *((unsigned int *)(base->accessor + address));
  return value;
 }
}

variable_types: struct raw_memory { void *accessor; unsigned int offset; unsigned int length; char name[-1]; } *

variable_types:
address
unsigned int

variable_types:
value
unsigned int