printDFG

decompiled_code:
int __fastcall printDFG(__int64 a1)
{
const char *v1; // rdx
__int64 v2; // r12
const char *v3; // rdx
__int64 v4; // r12
const char *v5; // rdx
__int64 v6; // r12
int result; // eax
__int64 v8; // r14
__int64 v9; // r12
const char *v10; // rdx
__int64 v11; // r15

fprintf(stdout, "Name = %s\n", (const char *)a1);
fprintf(stdout, "Date = %s\n\n", (const char *)(a1 + 100));
fwrite("Inputs = { ", 1uLL, 0xBuLL, stdout);
v1 = **(const char ***)(a1 + 200);
if ( v1 )
{
v2 = 8LL;
do
{
fprintf(stdout, "%s, ", v1);
v1 = *(const char **)(*(_QWORD *)(a1 + 200) + v2);
v2 += 8LL;
}
while ( v1 );
}
fwrite("}\n", 1uLL, 2uLL, stdout);
fwrite("Outputs = { ", 1uLL, 0xCuLL, stdout);
v3 = **(const char ***)(a1 + 208);
if ( v3 )
{
v4 = 8LL;
do
{
fprintf(stdout, "%s, ", v3);
v3 = *(const char **)(*(_QWORD *)(a1 + 208) + v4);
v4 += 8LL;
}
while ( v3 );
}
fwrite("}\n", 1uLL, 2uLL, stdout);
fwrite("regs = { ", 1uLL, 9uLL, stdout);
v5 = **(const char ***)(a1 + 216);
if ( v5 )
{
v6 = 8LL;
do
{
fprintf(stdout, "%s, ", v5);
v5 = *(const char **)(*(_QWORD *)(a1 + 216) + v6);
v6 += 8LL;
}
while ( v5 );
}
fwrite("}\n", 1uLL, 2uLL, stdout);
fprintf(stdout, "There are %d regs", *(unsigned int *)(a1 + 224));
fwrite("\nNODES:\n", 1uLL, 8uLL, stdout);
result = *(_DWORD *)(a1 + 228);
if ( result > 0 )
{
v8 = 0LL;
do
{
v9 = 216 * v8;
fprintf(stdout, "\tName = %s\n", (const char *)(216 * v8 + *(_QWORD *)(a1 + 232)));
fwrite("\tInputs = { ", 1uLL, 0xCuLL, stdout);
v10 = **(const char ***)(*(_QWORD *)(a1 + 232) + 216 * v8 + 104);
if ( v10 )
{
v11 = 8LL;
do
{
fprintf(stdout, "%s, ", v10);
v10 = *(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 232) + v9 + 104) + v11);
v11 += 8LL;
}
while ( v10 );
}
++v8;
fwrite("}\n", 1uLL, 2uLL, stdout);
fprintf(stdout, "\tOutput = %s\n", (const char *)(v9 + *(_QWORD *)(a1 + 232) + 112));
result = fprintf(stdout, "\tType = %d\n\n", *(unsigned int *)(*(_QWORD *)(a1 + 232) + v9 + 100));
}
while ( *(_DWORD *)(a1 + 228) > (int)v8 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
const char *v1; // rdx
__int64 v2; // r12
const char *v3; // rdx
__int64 v4; // r12
const char *v5; // rdx
__int64 v6; // r12
int result; // eax
__int64 v8; // r14
__int64 v9; // r12
const char *v10; // rdx
__int64 v11; // r15

fprintf(stdout, "Name = %s\n", (const char *)a1);
fprintf(stdout, "Date = %s\n\n", (const char *)(a1 + 100));
fwrite("Inputs = { ", 1uLL, 0xBuLL, stdout);
v1 = **(const char ***)(a1 + 200);
if ( v1 )
{
v2 = 8LL;
do
{
fprintf(stdout, "%s, ", v1);
v1 = *(const char **)(*(_QWORD *)(a1 + 200) + v2);
v2 += 8LL;
}
while ( v1 );
}
fwrite("}\n", 1uLL, 2uLL, stdout);
fwrite("Outputs = { ", 1uLL, 0xCuLL, stdout);
v3 = **(const char ***)(a1 + 208);
if ( v3 )
{
v4 = 8LL;
do
{
fprintf(stdout, "%s, ", v3);
v3 = *(const char **)(*(_QWORD *)(a1 + 208) + v4);
v4 += 8LL;
}
while ( v3 );
}
fwrite("}\n", 1uLL, 2uLL, stdout);
fwrite("regs = { ", 1uLL, 9uLL, stdout);
v5 = **(const char ***)(a1 + 216);
if ( v5 )
{
v6 = 8LL;
do
{
fprintf(stdout, "%s, ", v5);
v5 = *(const char **)(*(_QWORD *)(a1 + 216) + v6);
v6 += 8LL;
}
while ( v5 );
}
fwrite("}\n", 1uLL, 2uLL, stdout);
fprintf(stdout, "There are %d regs", *(unsigned int *)(a1 + 224));
fwrite("\nNODES:\n", 1uLL, 8uLL, stdout);
result = *(_DWORD *)(a1 + 228);
if ( result > 0 )
{
v8 = 0LL;
do
{
v9 = 216 * v8;
fprintf(stdout, "\tName = %s\n", (const char *)(216 * v8 + *(_QWORD *)(a1 + 232)));
fwrite("\tInputs = { ", 1uLL, 0xCuLL, stdout);
v10 = **(const char ***)(*(_QWORD *)(a1 + 232) + 216 * v8 + 104);
if ( v10 )
{
v11 = 8LL;
do
{
fprintf(stdout, "%s, ", v10);
v10 = *(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 232) + v9 + 104) + v11);
v11 += 8LL;
}
while ( v10 );
}
++v8;
fwrite("}\n", 1uLL, 2uLL, stdout);
fprintf(stdout, "\tOutput = %s\n", (const char *)(v9 + *(_QWORD *)(a1 + 232) + 112));
result = fprintf(stdout, "\tType = %d\n\n", *(unsigned int *)(*(_QWORD *)(a1 + 232) + v9 + 100));
}
while ( *(_DWORD *)(a1 + 228) > (int)v8 );
}
return result;
}

original_code:
void printDFG(DFG * task_schedule){
    int i, j;
    fprintf(stdout, "Name = %s\n", task_schedule->name);
    fprintf(stdout, "Date = %s\n\n", task_schedule->date);
    fprintf(stdout, "Inputs = { ");
    for(i=0; task_schedule->inputs[i] != ((void *)0); i++)
        fprintf(stdout, "%s, ", task_schedule->inputs[i]);
    fprintf(stdout, "}\n");
    fprintf(stdout, "Outputs = { ");
    for(i=0; task_schedule->outputs[i] != ((void *)0); i++)
        fprintf(stdout, "%s, ", task_schedule->outputs[i]);
    fprintf(stdout, "}\n");
    fprintf(stdout, "regs = { ");
    for(i=0; task_schedule->regs[i] != ((void *)0); i++)
        fprintf(stdout, "%s, ", task_schedule->regs[i]);
    fprintf(stdout, "}\n");
    fprintf(stdout, "There are %d regs", task_schedule->num_regs);
    fprintf(stdout, "\nNODES:\n");
    for(i = 0; i < task_schedule->num_nodes; i++){
        fprintf(stdout, "\tName = %s\n", task_schedule->node[i].name);
        fprintf(stdout, "\tInputs = { ");
        for(j=0; task_schedule->node[i].inputs[j]!= ((void *)0); j++)
            fprintf(stdout, "%s, ", task_schedule->node[i].inputs[j]);
        fprintf(stdout, "}\n");
        fprintf(stdout, "\tOutput = %s\n", task_schedule->node[i].output);
        fprintf(stdout, "\tType = %d\n\n", task_schedule->node[i].task_type);
    }
}

canonical_original_code:
void printDFG(struct DFG *task_schedule){
    int i; int j;
    fprintf(stdout, "Name = %s\n", task_schedule->name);
    fprintf(stdout, "Date = %s\n\n", task_schedule->date);
    fprintf(stdout, "Inputs = { ");
    for(i=0; task_schedule->inputs[i] != ((void *)0); i++)
        fprintf(stdout, "%s, ", task_schedule->inputs[i]);
    fprintf(stdout, "}\n");
    fprintf(stdout, "Outputs = { ");
    for(i=0; task_schedule->outputs[i] != ((void *)0); i++)
        fprintf(stdout, "%s, ", task_schedule->outputs[i]);
    fprintf(stdout, "}\n");
    fprintf(stdout, "regs = { ");
    for(i=0; task_schedule->regs[i] != ((void *)0); i++)
        fprintf(stdout, "%s, ", task_schedule->regs[i]);
    fprintf(stdout, "}\n");
    fprintf(stdout, "There are %d regs", task_schedule->num_regs);
    fprintf(stdout, "\nNODES:\n");
    for(i = 0; i < task_schedule->num_nodes; i++){
        fprintf(stdout, "\tName = %s\n", task_schedule->node[i].name);
        fprintf(stdout, "\tInputs = { ");
        for(j=0; task_schedule->node[i].inputs[j]!= ((void *)0); j++)
            fprintf(stdout, "%s, ", task_schedule->node[i].inputs[j]);
        fprintf(stdout, "}\n");
        fprintf(stdout, "\tOutput = %s\n", task_schedule->node[i].output);
        fprintf(stdout, "\tType = %d\n\n", task_schedule->node[i].task_type);
    }
}

user_defined_types: struct Node { char name[100]; int task_type; char **inputs; char output[100]; }


freeArchLibrary

repo: Ratchette/CommonParser

original_code:
void freeArchLibrary(Architecture_Library * arch_library){
    int i;
    for(i = 0; i < arch_library->num_tasks; i++)
        free((arch_library->task[i]).impl);
    free(arch_library->task);
}

canonical_original_code:
void freeArchLibrary(struct Architecture_Library *arch_library){
    int i;
    for(i = 0; i < arch_library->num_tasks; i++)
        free((arch_library->task[i]).impl);
    free(arch_library->task);
}

variable_types: struct Architecture_Library { char name[100]; char date[100]; int num_tasks; struct Task_Type { char name[100]; int id; int num_impl; struct Implementation { char name[100]; int columns; int rows; int config_time; int config_power; int exec_time; int exec_power; char mode[100]; } *impl; } *task; } *

variable_types: i int

return_type: void

user_defined_types: struct Architecture_Library { char name[100]; char date[100]; int num_tasks; struct Task_Type *task; }

user_defined_types: struct Task_Type { char name[100]; int id; int num_impl; struct Implementation *impl; }


printArchLibrary

original_code:
void printArchLibrary(Architecture_Library * arch_library){
    int i, j;
    fprintf(stdout, "Name = %s\n", arch_library->name);
    fprintf(stdout, "Date = %s\n", arch_library->date);
    fprintf(stdout, "TASKS: \n\n");
    for(i = 0; i < arch_library->num_tasks; i++){
        fprintf(stdout, "\tname = %s\n", arch_library->task[i].name);
        fprintf(stdout, "\tid = %d\n", arch_library->task[i].id);
        fprintf(stdout, "\tARCHITECTURES: \n\n");
        for(j = 0; j < (arch_library->task[i]).num_impl; j++){
            fprintf(stdout, "\t\tname = %s\n", arch_library->task[i].impl[j].name);
            fprintf(stdout, "\t\t%d\t%d\t%d\t%d\t%d\t%d\n",
                    ((arch_library->task[i]).impl[j]).columns,
                    ((arch_library->task[i]).impl[j]).rows,
                    ((arch_library->task[i]).impl[j]).config_time,
                    ((arch_library->task[i]).impl[j]).exec_time,
                    ((arch_library->task[i]).impl[j]).config_power,
                    ((arch_library->task[i]).impl[j]).exec_power);
        }
        fprintf(stdout, "\n");
    }
    fprintf(stdout, "\n");
}

canonical_original_code:
void printArchLibrary(struct Architecture_Library *arch_library){
    int i; int j;
    fprintf(stdout, "Name = %s\n", arch_library->name);
    fprintf(stdout, "Date = %s\n", arch_library->date);
    fprintf(stdout, "TASKS: \n\n");
    for(i = 0; i < arch_library->num_tasks; i++){
        fprintf(stdout, "\tname = %s\n", arch_library->task[i].name);
        fprintf(stdout, "\tid = %d\n", arch_library->task[i].id);
        fprintf(stdout, "\tARCHITECTURES: \n\n");
        for(j = 0; j < (arch_library->task[i]).num_impl; j++){
            fprintf(stdout, "\t\tname = %s\n", arch_library->task[i].impl[j].name);
            fprintf(stdout, "\t\t%d\t%d\t%d\t%d\t%d\t%d\n",
                    ((arch_library->task[i]).impl[j]).columns,
                    ((arch_library->task[i]).impl[j]).rows,
                    ((arch_library->task[i]).impl[j]).config_time,
                    ((arch_library->task[i]).impl[j]).exec_time,
                    ((arch_library->task[i]).impl[j]).config_power,
                    ((arch_library->task[i]).impl[j]).exec_power);
        }
        fprintf(stdout, "\n");
    }
    fprintf(stdout, "\n");
}

variable_types: j int

user_defined_types: struct Implementation { char name[100]; int columns; int rows; int config_time; int config_power; int exec_time; int exec_power; char mode[100]; }


freeHardwareLibrary

original_code:
void freeHardwareLibrary(Hardware * hardware_library){
    int i;
    for(i = 0; i < hardware_library->num_setups; i++)
        free(hardware_library->setups[i].prr_config_time);
    free(hardware_library->setups);
}

canonical_original_code:
void freeHardwareLibrary(struct Hardware *hardware_library){
    int i;
    for(i = 0; i < hardware_library->num_setups; i++)
        free(hardware_library->setups[i].prr_config_time);
    free(hardware_library->setups);
}

variable_types: struct Hardware { char name[100]; char date[100]; int num_setups; struct Processing_Elelements { int num_prrs; int num_gpps; int *prr_config_time; char name[100]; } *setups; } *

user_defined_types: struct Hardware { char name[100]; char date[100]; int num_setups; struct Processing_Elelements *setups; }


printHardwareLibrary

decompiled_code:
size_t __fastcall printHardwareLibrary(__int64 a1)
{
size_t result; // rax
__int64 v2; // r15
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rdx

fprintf(stdout, "Name = %s\n", (const char *)a1);
fprintf(stdout, "Date = %s\n", (const char *)(a1 + 100));
result = fwrite("\nHardware Configurations:\n", 1uLL, 0x1AuLL, stdout);
if ( *(int *)(a1 + 200) > 0 )
{
v2 = 0LL;
do
{
fprintf(stdout, "\tName = %s\n", (const char *)(120 * v2 + *(_QWORD *)(a1 + 208) + 16));
fprintf(stdout, "\tGPPs = %d\n", *(unsigned int *)(*(_QWORD *)(a1 + 208) + 120 * v2 + 4));
fprintf(stdout, "\tPRRs = %d\n", *(unsigned int *)(*(_QWORD *)(a1 + 208) + 120 * v2));
fwrite("\tPRR config times = { ", 1uLL, 0x16uLL, stdout);
v3 = 120 * v2 + *(_QWORD *)(a1 + 208);
if ( *(int *)v3 > 0 )
{
v4 = 0LL;
do
{
v5 = *(unsigned int *)(*(_QWORD *)(v3 + 8) + 4 * v4++);
fprintf(stdout, "%d, ", v5);
v3 = 120 * v2 + *(_QWORD *)(a1 + 208);
}
while ( *(_DWORD *)v3 > (int)v4 );
}
++v2;
result = fwrite("}\n\n", 1uLL, 3uLL, stdout);
}
while ( *(_DWORD *)(a1 + 200) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1)
{
size_t result; // rax
__int64 v2; // r15
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rdx

fprintf(stdout, "Name = %s\n", (const char *)a1);
fprintf(stdout, "Date = %s\n", (const char *)(a1 + 100));
result = fwrite("\nHardware Configurations:\n", 1uLL, 0x1AuLL, stdout);
if ( *(int *)(a1 + 200) > 0 )
{
v2 = 0LL;
do
{
fprintf(stdout, "\tName = %s\n", (const char *)(120 * v2 + *(_QWORD *)(a1 + 208) + 16));
fprintf(stdout, "\tGPPs = %d\n", *(unsigned int *)(*(_QWORD *)(a1 + 208) + 120 * v2 + 4));
fprintf(stdout, "\tPRRs = %d\n", *(unsigned int *)(*(_QWORD *)(a1 + 208) + 120 * v2));
fwrite("\tPRR config times = { ", 1uLL, 0x16uLL, stdout);
v3 = 120 * v2 + *(_QWORD *)(a1 + 208);
if ( *(int *)v3 > 0 )
{
v4 = 0LL;
do
{
v5 = *(unsigned int *)(*(_QWORD *)(v3 + 8) + 4 * v4++);
fprintf(stdout, "%d, ", v5);
v3 = 120 * v2 + *(_QWORD *)(a1 + 208);
}
while ( *(_DWORD *)v3 > (int)v4 );
}
++v2;
result = fwrite("}\n\n", 1uLL, 3uLL, stdout);
}
while ( *(_DWORD *)(a1 + 200) > (int)v2 );
}
return result;
}

original_code:
void printHardwareLibrary(Hardware * hardware_library){
    int i, j;
    fprintf(stdout, "Name = %s\n", hardware_library->name);
    fprintf(stdout, "Date = %s\n", hardware_library->date);
    fprintf(stdout, "\nHardware Configurations:\n");
    for(i = 0; i < hardware_library->num_setups; i++){
        fprintf(stdout, "\tName = %s\n", hardware_library->setups[i].name);
        fprintf(stdout, "\tGPPs = %d\n", hardware_library->setups[i].num_gpps);
        fprintf(stdout, "\tPRRs = %d\n", hardware_library->setups[i].num_prrs);
        fprintf(stdout, "\tPRR config times = { ");
        for(j=0; j < hardware_library->setups[i].num_prrs; j++)
            fprintf(stdout, "%d, ", hardware_library->setups[i].prr_config_time[j]);
        fprintf(stdout, "}\n\n");
    }
}

canonical_original_code:
void printHardwareLibrary(struct Hardware *hardware_library){
    int i; int j;
    fprintf(stdout, "Name = %s\n", hardware_library->name);
    fprintf(stdout, "Date = %s\n", hardware_library->date);
    fprintf(stdout, "\nHardware Configurations:\n");
    for(i = 0; i < hardware_library->num_setups; i++){
        fprintf(stdout, "\tName = %s\n", hardware_library->setups[i].name);
        fprintf(stdout, "\tGPPs = %d\n", hardware_library->setups[i].num_gpps);
        fprintf(stdout, "\tPRRs = %d\n", hardware_library->setups[i].num_prrs);
        fprintf(stdout, "\tPRR config times = { ");
        for(j=0; j < hardware_library->setups[i].num_prrs; j++)
            fprintf(stdout, "%d, ", hardware_library->setups[i].prr_config_time[j]);
        fprintf(stdout, "}\n\n");
    }
}

user_defined_types: struct Processing_Elelements { int num_prrs; int num_gpps; int *prr_config_time; char name[100]; }


repo: RealEnder/KSM-tools

decompiled_code:
void *hook_init()
{
void *result; // rax

kernel_pagesize = (__int64 (__fastcall *)())sysconf(30);
real_mmap = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mmap");
real_mmap2 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mmap2");
real_mremap = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mremap");
real_realloc = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "realloc");
real_calloc = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "calloc");
result = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "malloc");
real_malloc = result;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

kernel_pagesize = (__int64 (__fastcall *)())sysconf(30);
real_mmap = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mmap");
real_mmap2 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mmap2");
real_mremap = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mremap");
real_realloc = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "realloc");
real_calloc = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "calloc");
result = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "malloc");
real_malloc = result;
return result;
}

original_code:
void hook_init() {
    kernel_pagesize = (size_t) sysconf(_SC_PAGESIZE);
    real_mmap = dlsym(((void *) -1l), "mmap");
    real_mmap2 = dlsym(((void *) -1l), "mmap2");
    real_mremap = dlsym(((void *) -1l), "mremap");
    real_realloc = dlsym(((void *) -1l), "realloc");
    real_calloc = dlsym(((void *) -1l), "calloc");
    real_malloc = dlsym(((void *) -1l), "malloc");
}

canonical_original_code:
void hook_init() {
    kernel_pagesize = (unsigned long) sysconf(_SC_PAGESIZE);
    real_mmap = dlsym(((void *) -1l), "mmap");
    real_mmap2 = dlsym(((void *) -1l), "mmap2");
    real_mremap = dlsym(((void *) -1l), "mremap");
    real_realloc = dlsym(((void *) -1l), "realloc");
    real_calloc = dlsym(((void *) -1l), "calloc");
    real_malloc = dlsym(((void *) -1l), "malloc");
}


decompiled_code:
int __fastcall merge_pages(__int64 a1, __int64 a2)
{
return madvise(
(void *)(a1 & -(__int64)kernel_pagesize),
(_QWORD)kernel_pagesize
* ((a1 + a2 - (a1 & (unsigned __int64)-(__int64)kernel_pagesize)) / (unsigned __int64)kernel_pagesize + 1),
12);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2)
{
return madvise(
(void *)(a1 & -(__int64)kernel_pagesize),
(_QWORD)kernel_pagesize
* ((a1 + a2 - (a1 & (unsigned __int64)-(__int64)kernel_pagesize)) / (unsigned __int64)kernel_pagesize + 1),
12);
}

original_code:
static void merge_pages(void *address, size_t length) {
    const size_t raw_address = (size_t) address;
    const size_t page_address = raw_address & -kernel_pagesize;
    const size_t new_length = (((length + raw_address - page_address) / kernel_pagesize) + 1) * kernel_pagesize;
    madvise((void *) page_address, new_length, 12);
}

canonical_original_code:
static void merge_pages(void *address, unsigned long length) {
    unsigned long raw_address = (size_t) address;
    unsigned long page_address = raw_address & -kernel_pagesize;
    unsigned long new_length = (((length + raw_address - page_address) / kernel_pagesize) + 1) * kernel_pagesize;
    madvise((void *) page_address, new_length, 12);
}

variable_types:
address
void *

variable_types:
length
unsigned long


mmap

decompiled_code:
__int64 __fastcall mmap(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_mmap();
merge_pages(v2, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_mmap();
func7(v2, a2);
return v2;
}

original_code:
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
    void *res = real_mmap(addr, length, prot, flags, fd, offset);
    merge_pages(res, length);
    return res;
}

canonical_original_code:
void *mmap(void *addr, unsigned long length, int prot, int flags, int fd, long offset) {
    void *res = real_mmap(addr, length, prot, flags, fd, offset);
    merge_pages(res, length);
    return res;
}

variable_types:
addr
void *

variable_types: prot int

variable_types: flags int

variable_types: fd int

variable_types: offset long

variable_types:
res
void *

return_type: void *


decompiled_code:
__int64 __fastcall mmap2(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_mmap2();
merge_pages(v2, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_mmap2();
func7(v2, a2);
return v2;
}

original_code:
void *mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset) {
    void *res = real_mmap2(start, length, prot, flags, fd, pgoffset);
    merge_pages(res, length);
    return res;
}

canonical_original_code:
void *mmap2(void *start, unsigned long length, int prot, int flags, int fd, long pgoffset) {
    void *res = real_mmap2(start, length, prot, flags, fd, pgoffset);
    merge_pages(res, length);
    return res;
}

variable_types:
start
void *

variable_types: pgoffset long


realloc

decompiled_code:
__int64 __fastcall realloc(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_realloc();
merge_pages(v2, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_realloc();
func7(v2, a2);
return v2;
}

original_code:
void *realloc(void *addr, size_t length) {
    void *res = real_realloc(addr, length);
    merge_pages(res, length);
    return res;
}

canonical_original_code:
void *realloc(void *addr, unsigned long length) {
    void *res = real_realloc(addr, length);
    merge_pages(res, length);
    return res;
}


malloc

decompiled_code:
__int64 __fastcall malloc(__int64 a1)
{
__int64 v1; // r12

v1 = real_malloc();
merge_pages(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // r12

v1 = real_malloc();
func7(v1, a1);
return v1;
}

original_code:
void *malloc(size_t length) {
    void *res = real_malloc(length);
    merge_pages(res, length);
    return res;
}

canonical_original_code:
void *malloc(unsigned long length) {
    void *res = real_malloc(length);
    merge_pages(res, length);
    return res;
}


calloc

decompiled_code:
__int64 __fastcall calloc(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_calloc();
merge_pages(v2, a2 * a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = real_calloc();
func7(v2, a2 * a1);
return v2;
}

original_code:
void *calloc(size_t nmemb, size_t length) {
    void *res = real_calloc(nmemb, length);
    merge_pages(res, length*nmemb);
    return res;
}

canonical_original_code:
void *calloc(unsigned long nmemb, unsigned long length) {
    void *res = real_calloc(nmemb, length);
    merge_pages(res, length*nmemb);
    return res;
}

variable_types:
nmemb
unsigned long


repo: Red-Seadog/grepcss

decompiled_code:
void __fastcall add2SelectorList(_BYTE *a1)
{
__int64 v1; // rbx

v1 = nSelectors;
if ( nSelectors > 99 )
{
fwrite("Max limit reached 100 for selectorList\n", 1uLL, 0x27uLL, stderr);
exit(2);
}
if ( *a1 )
{
++nSelectors;
selectorList[v1] = addSelector();
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1)
{
__int64 v1; // rbx

v1 = nSelectors;
if ( nSelectors > 99 )
{
fwrite("Max limit reached 100 for selectorList\n", 1uLL, 0x27uLL, stderr);
exit(2);
}
if ( *a1 )
{
++nSelectors;
selectorList[v1] = addSelector();
}
}

original_code:
int add2SelectorList(char *p_token) {
 if (nSelectors > 99) {
  fprintf(stderr,"Max limit reached 100 for selectorList\n");
  exit(2);
 }
 if (*p_token) {
  selectorList[nSelectors++] = addSelector(p_token);
 }
}

return_type: int


resetSelectorList

decompiled_code:
void resetSelectorList()
{
nSelectors = 0;
}

canonical_decompiled_code:
void func1()
{
nSelectors = 0;
}

original_code:
int resetSelectorList() {
 nSelectors = 0;
}


processChar

decompiled_code:
__int64 __fastcall processChar(__int64 a1, unsigned __int64 a2, unsigned int a3, int a4, unsigned int a5)
{
unsigned int v7; // er13
bool v10; // r12
unsigned int v11; // er9
__int64 v13; // rdx
_BYTE *v14; // rax
unsigned int v15; // er9
void *v16; // rbp
__int64 v17; // rbx
__int64 v18; // rdi
__int64 v19; // rax
const char *v20; // rax
char *v21; // rdx
void *v22; // rax
bool v23; // cf
bool v24; // zf
const char *v25; // rax
const char *v26; // rdi
__int64 v27; // rcx
char *v28; // rdx
char *v29; // rdx
char *v30; // rcx
_BYTE *v31; // rax
void *v32; // rbp
__int64 v33; // rbx
__int64 v34; // rdi
__int64 v35; // rax
unsigned int v36; // [rsp+Ch] [rbp-3Ch]
unsigned int v37; // [rsp+Ch] [rbp-3Ch]
unsigned int v38; // [rsp+Ch] [rbp-3Ch]
int v39; // [rsp+Ch] [rbp-3Ch]
int v40; // [rsp+Ch] [rbp-3Ch]
int v41; // [rsp+Ch] [rbp-3Ch]
int v42; // [rsp+Ch] [rbp-3Ch]

v7 = a2;
v10 = a4 == 47;
if ( a5 == 42 && a4 == 47 )
{
insideComment = 1;
LABEL_4:
v11 = a2;
LABEL_5:
if ( a3 == 42 && v10 )
insideComment = 0;
return v11;
}
v11 = insideComment;
if ( insideComment )
goto LABEL_4;
if ( a4 == 64 )
{
v11 = 10;
insideAt = 1;
v21 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = 64;
tokenPtr = v21;
return v11;
}
v13 = (unsigned int)a2;
if ( insideAt )
{
switch ( a4 )
{
case '"':
if ( (_DWORD)a2 == 11 )
{
v42 = insideComment;
*(_BYTE *)tokenPtr = 0;
trimWhite(&tokenArea, a2, (unsigned int)a2);
v11 = v42;
v13 = 12LL;
tokenPtr = &tokenArea;
}
else
{
if ( (_DWORD)a2 != 12 )
{
fprintf(stderr, "atQuote: Unknown toestand %d near %c%c%c in file %s\n", (unsigned int)a2, a3, 34LL, a5, a1);
goto LABEL_67;
}
v40 = insideComment;
*(_BYTE *)tokenPtr = 0;
v22 = (void *)trimWhite(&tokenArea, a2, (unsigned int)a2);
a2 = (unsigned __int64)"Found FILENAME=%s\n";
tokenPtr = v22;
fprintf(stderr, "Found FILENAME=%s\n", (const char *)v22);
v11 = v40;
v13 = 13LL;
tokenPtr = &tokenArea;
}
break;
case ';':
if ( (_DWORD)a2 != 13 )
{
fprintf(
stderr,
"atSemiColon: Unknown toestand %d near %c%c%c in file %s\n",
(unsigned int)a2,
a3,
59LL,
a5,
a1);
goto LABEL_67;
}
v39 = insideComment;
*(_BYTE *)tokenPtr = 0;
trimWhite(&tokenArea, a2, (unsigned int)a2);
v11 = v39;
v13 = 13LL;
tokenPtr = &tokenArea;
break;
case ' ':
v41 = insideComment;
*(_BYTE *)tokenPtr = 0;
v25 = (const char *)trimWhite(&tokenArea, a2, (unsigned int)a2);
v26 = "@import";
v27 = 8LL;
v13 = (unsigned int)a2;
a2 = (unsigned __int64)v25;
tokenPtr = (void *)v25;
v11 = v41;
do
{
if ( !v27 )
break;
v23 = *(_BYTE *)a2 < *v26;
v24 = *(_BYTE *)a2++ == *v26++;
--v27;
}
while ( v24 );
if ( (!v23 && !v24) == v23 )
{
tokenPtr = &tokenArea;
v13 = 11LL;
}
break;
default:
v13 = (__int64)tokenPtr + 1;
*(_BYTE *)tokenPtr = a4;
tokenPtr = (void *)v13;
LODWORD(v13) = a2;
goto LABEL_37;
}
if ( insideComment )
{
v11 = v13;
goto LABEL_5;
}
if ( !insideAt )
goto LABEL_12;
LABEL_37:
if ( (_DWORD)v13 != 13 || a3 != 59 )
return (unsigned int)v13;
insideAt = 0;
return v11;
}
LABEL_12:
if ( a4 != 59 )
{
if ( a4 <= 59 )
{
if ( a4 == 44 )
{
if ( !(_DWORD)v13 )
{
*(_BYTE *)tokenPtr = 0;
tokenPtr = (void *)trimWhite(&tokenArea, a2, v13);
add2SelectorList(tokenPtr);
v11 = 0;
tokenPtr = &tokenArea;
return v11;
}
if ( (_DWORD)v13 == 2 )
{
v11 = 2;
v29 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = 44;
tokenPtr = v29;
return v11;
}
fprintf(stderr, "Comma Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 44LL, a5, a1);
goto LABEL_67;
}
if ( a4 == 58 )
{
if ( !(_DWORD)v13 )
{
v11 = 0;
v28 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = 58;
tokenPtr = v28;
return v11;
}
if ( (_DWORD)v13 == 1 )
{
*(_BYTE *)tokenPtr = 0;
v20 = (const char *)trimWhite(&tokenArea, a2, v13);
strcpy(currentPropertyName, v20);
v11 = 2;
tokenPtr = &tokenArea;
return v11;
}
fprintf(stderr, "Colon Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 58LL, a5, a1);
goto LABEL_67;
}
}
else
{
if ( a4 == 123 )
{
if ( !(_DWORD)v13 )
{
*(_BYTE *)tokenPtr = 0;
tokenPtr = (void *)trimWhite(&tokenArea, a2, v13);
add2SelectorList(tokenPtr);
v11 = 1;
tokenPtr = &tokenArea;
return v11;
}
fprintf(stderr, "AccoladeOpen Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 123LL, a5, a1);
goto LABEL_67;
}
if ( a4 == 125 )
{
if ( (_DWORD)v13 == 1 )
goto LABEL_19;
if ( (_DWORD)v13 == 2 )
{
a2 = v7;
v36 = v11;
processChar(a1, v7, a3, 59LL, 125LL);
v11 = v36;
LABEL_19:
v37 = v11;
*(_BYTE *)tokenPtr = 0;
v14 = (_BYTE *)trimWhite(&tokenArea, a2, v13);
v15 = v37;
v24 = *v14 == 0;
tokenPtr = v14;
v16 = v14;
if ( !v24 && nSelectors > 0 )
{
v17 = 0LL;
while ( 1 )
{
v18 = selectorList[v17];
v38 = v15;
++v17;
v19 = addProperty(v18, currentPropertyName);
addValue(v19, v16);
v15 = v38;
if ( nSelectors <= (int)v17 )
break;
v16 = tokenPtr;
}
}
tokenPtr = &tokenArea;
resetSelectorList();
return v11;
}
fprintf(stderr, "AccoladeClose Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 125LL, a5, a1);
LABEL_67:
exit(1);
}
}
v11 = v13;
v30 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = a4;
tokenPtr = v30;
return v11;
}
if ( (_DWORD)v13 != 2 )
{
fprintf(stderr, "SemiColon Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 59LL, a5, a1);
goto LABEL_67;
}
*(_BYTE *)tokenPtr = 0;
v31 = (_BYTE *)trimWhite(&tokenArea, a2, v13);
v24 = *v31 == 0;
tokenPtr = v31;
v32 = v31;
if ( !v24 && nSelectors > 0 )
{
v33 = 0LL;
while ( 1 )
{
v34 = selectorList[v33++];
v35 = addProperty(v34, currentPropertyName);
addValue(v35, v32);
if ( nSelectors <= (int)v33 )
break;
v32 = tokenPtr;
}
}
tokenPtr = &tokenArea;
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 a2, unsigned int a3, int a4, unsigned int a5)
{
unsigned int v7; // er13
bool v10; // r12
unsigned int v11; // er9
__int64 v13; // rdx
_BYTE *v14; // rax
unsigned int v15; // er9
void *v16; // rbp
__int64 v17; // rbx
__int64 v18; // rdi
__int64 v19; // rax
const char *v20; // rax
char *v21; // rdx
void *v22; // rax
bool v23; // cf
bool v24; // zf
const char *v25; // rax
const char *v26; // rdi
__int64 v27; // rcx
char *v28; // rdx
char *v29; // rdx
char *v30; // rcx
_BYTE *v31; // rax
void *v32; // rbp
__int64 v33; // rbx
__int64 v34; // rdi
__int64 v35; // rax
unsigned int v36; // [rsp+Ch] [rbp-3Ch]
unsigned int v37; // [rsp+Ch] [rbp-3Ch]
unsigned int v38; // [rsp+Ch] [rbp-3Ch]
int v39; // [rsp+Ch] [rbp-3Ch]
int v40; // [rsp+Ch] [rbp-3Ch]
int v41; // [rsp+Ch] [rbp-3Ch]
int v42; // [rsp+Ch] [rbp-3Ch]

v7 = a2;
v10 = a4 == 47;
if ( a5 == 42 && a4 == 47 )
{
insideComment = 1;
LABEL_4:
v11 = a2;
LABEL_5:
if ( a3 == 42 && v10 )
insideComment = 0;
return v11;
}
v11 = insideComment;
if ( insideComment )
goto LABEL_4;
if ( a4 == 64 )
{
v11 = 10;
insideAt = 1;
v21 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = 64;
tokenPtr = v21;
return v11;
}
v13 = (unsigned int)a2;
if ( insideAt )
{
switch ( a4 )
{
case '"':
if ( (_DWORD)a2 == 11 )
{
v42 = insideComment;
*(_BYTE *)tokenPtr = 0;
trimWhite(&tokenArea, a2, (unsigned int)a2);
v11 = v42;
v13 = 12LL;
tokenPtr = &tokenArea;
}
else
{
if ( (_DWORD)a2 != 12 )
{
fprintf(stderr, "atQuote: Unknown toestand %d near %c%c%c in file %s\n", (unsigned int)a2, a3, 34LL, a5, a1);
goto LABEL_67;
}
v40 = insideComment;
*(_BYTE *)tokenPtr = 0;
v22 = (void *)trimWhite(&tokenArea, a2, (unsigned int)a2);
a2 = (unsigned __int64)"Found FILENAME=%s\n";
tokenPtr = v22;
fprintf(stderr, "Found FILENAME=%s\n", (const char *)v22);
v11 = v40;
v13 = 13LL;
tokenPtr = &tokenArea;
}
break;
case ';':
if ( (_DWORD)a2 != 13 )
{
fprintf(
stderr,
"atSemiColon: Unknown toestand %d near %c%c%c in file %s\n",
(unsigned int)a2,
a3,
59LL,
a5,
a1);
goto LABEL_67;
}
v39 = insideComment;
*(_BYTE *)tokenPtr = 0;
trimWhite(&tokenArea, a2, (unsigned int)a2);
v11 = v39;
v13 = 13LL;
tokenPtr = &tokenArea;
break;
case ' ':
v41 = insideComment;
*(_BYTE *)tokenPtr = 0;
v25 = (const char *)trimWhite(&tokenArea, a2, (unsigned int)a2);
v26 = "@import";
v27 = 8LL;
v13 = (unsigned int)a2;
a2 = (unsigned __int64)v25;
tokenPtr = (void *)v25;
v11 = v41;
do
{
if ( !v27 )
break;
v23 = *(_BYTE *)a2 < *v26;
v24 = *(_BYTE *)a2++ == *v26++;
--v27;
}
while ( v24 );
if ( (!v23 && !v24) == v23 )
{
tokenPtr = &tokenArea;
v13 = 11LL;
}
break;
default:
v13 = (__int64)tokenPtr + 1;
*(_BYTE *)tokenPtr = a4;
tokenPtr = (void *)v13;
LODWORD(v13) = a2;
goto LABEL_37;
}
if ( insideComment )
{
v11 = v13;
goto LABEL_5;
}
if ( !insideAt )
goto LABEL_12;
LABEL_37:
if ( (_DWORD)v13 != 13 || a3 != 59 )
return (unsigned int)v13;
insideAt = 0;
return v11;
}
LABEL_12:
if ( a4 != 59 )
{
if ( a4 <= 59 )
{
if ( a4 == 44 )
{
if ( !(_DWORD)v13 )
{
*(_BYTE *)tokenPtr = 0;
tokenPtr = (void *)trimWhite(&tokenArea, a2, v13);
func0(tokenPtr);
v11 = 0;
tokenPtr = &tokenArea;
return v11;
}
if ( (_DWORD)v13 == 2 )
{
v11 = 2;
v29 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = 44;
tokenPtr = v29;
return v11;
}
fprintf(stderr, "Comma Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 44LL, a5, a1);
goto LABEL_67;
}
if ( a4 == 58 )
{
if ( !(_DWORD)v13 )
{
v11 = 0;
v28 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = 58;
tokenPtr = v28;
return v11;
}
if ( (_DWORD)v13 == 1 )
{
*(_BYTE *)tokenPtr = 0;
v20 = (const char *)trimWhite(&tokenArea, a2, v13);
strcpy(currentPropertyName, v20);
v11 = 2;
tokenPtr = &tokenArea;
return v11;
}
fprintf(stderr, "Colon Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 58LL, a5, a1);
goto LABEL_67;
}
}
else
{
if ( a4 == 123 )
{
if ( !(_DWORD)v13 )
{
*(_BYTE *)tokenPtr = 0;
tokenPtr = (void *)trimWhite(&tokenArea, a2, v13);
func0(tokenPtr);
v11 = 1;
tokenPtr = &tokenArea;
return v11;
}
fprintf(stderr, "AccoladeOpen Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 123LL, a5, a1);
goto LABEL_67;
}
if ( a4 == 125 )
{
if ( (_DWORD)v13 == 1 )
goto LABEL_19;
if ( (_DWORD)v13 == 2 )
{
a2 = v7;
v36 = v11;
func2(a1, v7, a3, 59LL, 125LL);
v11 = v36;
LABEL_19:
v37 = v11;
*(_BYTE *)tokenPtr = 0;
v14 = (_BYTE *)trimWhite(&tokenArea, a2, v13);
v15 = v37;
v24 = *v14 == 0;
tokenPtr = v14;
v16 = v14;
if ( !v24 && nSelectors > 0 )
{
v17 = 0LL;
while ( 1 )
{
v18 = selectorList[v17];
v38 = v15;
++v17;
v19 = addProperty(v18, currentPropertyName);
addValue(v19, v16);
v15 = v38;
if ( nSelectors <= (int)v17 )
break;
v16 = tokenPtr;
}
}
tokenPtr = &tokenArea;
func1();
return v11;
}
fprintf(stderr, "AccoladeClose Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 125LL, a5, a1);
LABEL_67:
exit(1);
}
}
v11 = v13;
v30 = (char *)tokenPtr + 1;
*(_BYTE *)tokenPtr = a4;
tokenPtr = v30;
return v11;
}
if ( (_DWORD)v13 != 2 )
{
fprintf(stderr, "SemiColon Unknown toestand %d near %c%c%c in file %s\n", v13, a3, 59LL, a5, a1);
goto LABEL_67;
}
*(_BYTE *)tokenPtr = 0;
v31 = (_BYTE *)trimWhite(&tokenArea, a2, v13);
v24 = *v31 == 0;
tokenPtr = v31;
v32 = v31;
if ( !v24 && nSelectors > 0 )
{
v33 = 0LL;
while ( 1 )
{
v34 = selectorList[v33++];
v35 = addProperty(v34, currentPropertyName);
addValue(v35, v32);
if ( nSelectors <= (int)v33 )
break;
v32 = tokenPtr;
}
}
tokenPtr = &tokenArea;
return 1;
}

original_code:
int processChar(char *p_filename, int p_toestand, int p_lastchar, int p_thischar, int p_nextchar) {
 int toestand = p_toestand;
 if (p_thischar == '/' && p_nextchar == '*') {
  insideComment = 1;
 }
 if (!insideComment && p_thischar == '@') {
  insideAt = 1;
  toestand = 10;
 }
 if (insideAt && !insideComment) {
  switch(p_thischar) {
  default:
   *tokenPtr++ = p_thischar;
   break;
  case ' ':
   *tokenPtr = '\0';
   tokenPtr = trimWhite(tokenArea);
   if (strcmp(tokenPtr,"@import") == 0) {
    tokenPtr = tokenArea;
    toestand = 11;
   }
   break;
  case '"':
   switch (toestand) {
   default:
    fprintf(stderr,"atQuote: Unknown toestand %d near %c%c%c in file %s\n",toestand,p_lastchar,p_thischar,p_nextchar,p_filename);
    exit(1);
   case 11:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    tokenPtr = tokenArea;
    toestand = 12;
    break;
   case 12:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    fprintf(stderr,"Found FILENAME=%s\n",tokenPtr);
    tokenPtr = tokenArea;
    toestand = 13;
    break;
   }
   break;
  case ';':
   switch (toestand) {
   default:
    fprintf(stderr,"atSemiColon: Unknown toestand %d near %c%c%c in file %s\n",toestand,p_lastchar,p_thischar,p_nextchar,p_filename);
    exit(1);
   case 13:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    tokenPtr = tokenArea;
    break;
   }
   break;
  }
 }
 if (!insideComment && !insideAt) {
  switch(p_thischar) {
  default:
   *tokenPtr++ = p_thischar;
   break;
  case ',':
   switch (toestand) {
   default:
    fprintf(stderr,"Comma Unknown toestand %d near %c%c%c in file %s\n",toestand,p_lastchar,p_thischar,p_nextchar,p_filename);
    exit(1);
   case 0:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    add2SelectorList(tokenPtr);
    tokenPtr = tokenArea;
    break;
   case 2:
    *tokenPtr++ = p_thischar;
    break;
   }
   break;
  case '{':
   switch(toestand) {
   default:
    fprintf(stderr,"AccoladeOpen Unknown toestand %d near %c%c%c in file %s\n",toestand,p_lastchar,p_thischar,p_nextchar,p_filename);
    exit(1);
   case 0:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    add2SelectorList(tokenPtr);
    tokenPtr = tokenArea;
    toestand = 1;
    break;
   }
   break;
  case ':':
   switch(toestand) {
   default:
    fprintf(stderr,"Colon Unknown toestand %d near %c%c%c in file %s\n",toestand,p_lastchar,p_thischar,p_nextchar,p_filename);
    exit(1);
   case 0:
    *tokenPtr++ = p_thischar;
    break;
   case 1:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    strcpy(currentPropertyName, tokenPtr);
    tokenPtr = tokenArea;
    toestand = 2;
    break;
   }
   break;
  case ';':
   switch(toestand) {
   default:
    fprintf(stderr,"SemiColon Unknown toestand %d near %c%c%c in file %s\n",toestand,p_lastchar,p_thischar,p_nextchar,p_filename);
    exit(1);
   case 2:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    if (*tokenPtr) {
     int i;
     for (i = 0; i < nSelectors; i++) {
      addValue(addProperty(selectorList[i],currentPropertyName),tokenPtr);
     }
    }
    tokenPtr = tokenArea;
    toestand = 1;
    break;
   }
   break;
  case '}':
   switch(toestand) {
   default:
    fprintf(stderr,"AccoladeClose Unknown toestand %d near %c%c%c in file %s\n",toestand,p_lastchar,p_thischar,p_nextchar,p_filename);
    exit(1);
   case 2:
{
 processChar(p_filename, p_toestand, p_lastchar, ';', p_thischar);
}
    toestand = 1;
   case 1:
    *tokenPtr = '\0';
    tokenPtr = trimWhite(tokenArea);
    if (*tokenPtr) {
     int i;
     for (i = 0; i < nSelectors; i++) {
      addValue(addProperty(selectorList[i],currentPropertyName),tokenPtr);
     }
    }
    tokenPtr = tokenArea;
    resetSelectorList();
    toestand = 0;
    break;
   }
   break;
  }
 }
 if (insideComment && p_lastchar == '*' && p_thischar == '/') {
  insideComment = 0;
 }
 if (!insideComment && insideAt && toestand == 13 && p_lastchar == ';') {
  insideAt = 0;
  toestand = 0;
 }
 return toestand;
}

variable_types: toestand int


findSelector

decompiled_code:
__int64 __fastcall findSelector(char *s2)
{
__int64 v1; // r12

v1 = firstSelector;
if ( firstSelector )
{
while ( strcmp(*(const char **)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return v1;
}
++*(_DWORD *)(v1 + 8);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
__int64 v1; // r12

v1 = firstSelector;
if ( firstSelector )
{
while ( strcmp(*(const char **)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return v1;
}
++*(_DWORD *)(v1 + 8);
}
return v1;
}

original_code:
SELECTOR_T *findSelector(char *p_token) {
 SELECTOR_T *current;
 for (current = firstSelector; current != (SELECTOR_T *)0; current = current->next) {
  int l1 = strlen(current->name);
  int l2 = strlen(p_token);
  if (!strcmp(current->name,p_token)) {
   current->aantal++;
   break;
  }
 }
 return current;
}

canonical_original_code:
struct selector_t *findSelector(char *p_token) {
 struct selector_t *current;
 for (current = firstSelector; current != (struct selector_t *)0; current = current->next) {
  int l1 = strlen(current->name);
  int l2 = strlen(p_token);
  if (!strcmp(current->name,p_token)) {
   current->aantal++;
   break;
  }
 }
 return current;
}

variable_types: struct selector_t { char *name; int aantal; struct property_t { char *name; int aantal; struct value_t { char *name; int aantal; struct value_t *next; } *values; struct property_t *next; } *properties; struct selector_t *next; } *

user_defined_types: struct selector_t { char *name; int aantal; struct property_t *properties; struct selector_t *next; }

user_defined_types: struct property_t { char *name; int aantal; struct value_t *values; struct property_t *next; }


startSelector

decompiled_code:
__int64 startSelector()
{
return firstSelector;
}

canonical_decompiled_code:
__int64 func1()
{
return firstSelector;
}

original_code:
SELECTOR_T *startSelector() {
 return firstSelector;
}

canonical_original_code:
struct selector_t *startSelector() {
 return firstSelector;
}

return_type: struct selector_t { char *name; int aantal; struct property_t { char *name; int aantal; struct value_t { char *name; int aantal; struct value_t *next; } *values; struct property_t *next; } *properties; struct selector_t *next; } *


findProperty

decompiled_code:
__int64 __fastcall findProperty(__int64 a1, const char *a2)
{
__int64 v2; // r12

v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
{
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return v2;
}
++*(_DWORD *)(v2 + 8);
}
return v2;
}

original_code:
PROPERTY_T *findProperty(SELECTOR_T *p_selector, char *p_token) {
 PROPERTY_T *current;
 for (current = p_selector->properties; current != (PROPERTY_T *)0; current = current->next) {
  if (!strcmp(current->name,p_token)) {
   current->aantal++;
   break;
  }
 }
 return current;
}

canonical_original_code:
struct property_t *findProperty(struct selector_t *p_selector, char *p_token) {
 struct property_t *current;
 for (current = p_selector->properties; current != (struct property_t *)0; current = current->next) {
  if (!strcmp(current->name,p_token)) {
   current->aantal++;
   break;
  }
 }
 return current;
}

variable_types: struct selector_t { char *name; int aantal; struct property_t *properties; struct selector_t *next; } *

variable_types: struct property_t { char *name; int aantal; struct value_t { char *name; int aantal; struct value_t *next; } *values; struct property_t *next; } *


addProperty

decompiled_code:
__int64 __fastcall addProperty(__int64 a1, char *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rbx

if ( *(_QWORD *)(a1 + 16) )
{
result = findProperty(a1, a2);
if ( !result )
{
v3 = *(_QWORD *)(a1 + 16);
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
result = (__int64)newProperty(a2);
*(_QWORD *)(v4 + 24) = result;
}
}
else
{
result = (__int64)newProperty(a2);
*(_QWORD *)(a1 + 16) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rbx

if ( *(_QWORD *)(a1 + 16) )
{
result = func0(a1, a2);
if ( !result )
{
v3 = *(_QWORD *)(a1 + 16);
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
result = (__int64)newProperty(a2);
*(_QWORD *)(v4 + 24) = result;
}
}
else
{
result = (__int64)newProperty(a2);
*(_QWORD *)(a1 + 16) = result;
}
return result;
}

original_code:
PROPERTY_T *addProperty(SELECTOR_T *p_selector, char *p_token) {
 PROPERTY_T *current;
 if (p_selector->properties == (PROPERTY_T *)0) {
  p_selector->properties = newProperty(p_token);
  return p_selector->properties;
 }
 current = findProperty(p_selector, p_token);
 if (current != (PROPERTY_T *)0) {
  return current;
 }
 for(current = p_selector->properties; current->next != (PROPERTY_T *)0; current = current->next);
 current->next = newProperty(p_token);
 return current->next;
}

canonical_original_code:
struct property_t *addProperty(struct selector_t *p_selector, char *p_token) {
 struct property_t *current;
 if (p_selector->properties == (struct property_t *)0) {
  p_selector->properties = newProperty(p_token);
  return p_selector->properties;
 }
 current = findProperty(p_selector, p_token);
 if (current != (struct property_t *)0) {
  return current;
 }
 for(current = p_selector->properties; current->next != (struct property_t *)0; current = current->next);
 current->next = newProperty(p_token);
 return current->next;
}

return_type: struct property_t { char *name; int aantal; struct value_t { char *name; int aantal; struct value_t *next; } *values; struct property_t *next; } *


rtrim

decompiled_code:
const char *__fastcall rtrim(const char *a1)
{
const char *v2; // rsi
unsigned int v3; // edi

v2 = &a1[(int)strlen(a1) - 1];
v3 = *v2;
if ( *v2 )
{
do
{
if ( !white(v3) )
break;
*v2 = 0;
v3 = *--v2;
}
while ( (_BYTE)v3 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
const char *v2; // rsi
unsigned int v3; // edi

v2 = &a1[(int)strlen(a1) - 1];
v3 = *v2;
if ( *v2 )
{
do
{
if ( !func0(v3) )
break;
*v2 = 0;
v3 = *--v2;
}
while ( (_BYTE)v3 );
}
return a1;
}

original_code:
char *rtrim(char *p_ptr) {
 char *ptr = p_ptr;
 int len = strlen(p_ptr);
 for (ptr = &p_ptr[len-1]; *ptr && white(*ptr); ptr--) {
  *ptr = '\0';
 }
 ptr = p_ptr;
 return p_ptr;
}

variable_types:
ptr
char *

variable_types: len int

return_type: char *


repo: Rerito/rbtree

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

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
result = (*(_DWORD *)(a1 - 8) <= *(_DWORD *)(*((_QWORD *)&a1 + 1) - 8LL))
- (unsigned int)(*(_DWORD *)(a1 - 8) >= *(_DWORD *)(*((_QWORD *)&a1 + 1) - 8LL));
else
result = 1LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
result = (*(_DWORD *)(a1 - 8) <= *(_DWORD *)(*((_QWORD *)&a1 + 1) - 8LL))
- (unsigned int)(*(_DWORD *)(a1 - 8) >= *(_DWORD *)(*((_QWORD *)&a1 + 1) - 8LL));
else
result = 1LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static int inttree_order(struct rb_node *n1, struct rb_node *n2)
{
 struct int_rb_node *a1 = ((void *)0), *a2 = ((void *)0);
 if(!n1 && !n2)
  return 0;
 if(!n1)
  return -1;
 if(!n2)
  return 1;
 a1 = (struct int_rb_node*)((char*)n1 - (unsigned long)&(((struct int_rb_node*)(0))->node));
 a2 = (struct int_rb_node*)((char*)n2 - (unsigned long)&(((struct int_rb_node*)(0))->node));
 return (a1->k <= a2->k) - (a2->k <= a1->k);
}

canonical_original_code:
static int inttree_order(struct rb_node *n1, struct rb_node *n2)
{
 struct int_rb_node *a1 = ((void *)0); struct int_rb_node *a2 = ((void *)0);
 if(!n1 && !n2)
  return 0;
 if(!n1)
  return -1;
 if(!n2)
  return 1;
 a1 = (struct int_rb_node *)((char *)n1 - (unsigned long)&(((struct int_rb_node *)(0))->node));
 a2 = (struct int_rb_node *)((char *)n2 - (unsigned long)&(((struct int_rb_node *)(0))->node));
 return (a1->k <= a2->k) - (a2->k <= a1->k);
}

variable_types: struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } *

variable_types: struct int_rb_node { int k; struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } node; } *

user_defined_types: struct rb_node { struct rb_node *p; enum rb_color clr; }

user_defined_types: struct int_rb_node { int k; struct rb_node node; }


decompiled_code:
void __fastcall inttree_free_node(__int64 a1)
{
if ( a1 )
free((void *)(a1 - 8));
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
if ( a1 )
free((void *)(a1 - 8));
}

original_code:
static void inttree_free_node(struct rb_node *n)
{
 if(!n)
  return;
 free((struct int_rb_node*)((char*)n - (unsigned long)&(((struct int_rb_node*)(0))->node)));
}

canonical_original_code:
static void inttree_free_node(struct rb_node *n)
{
 if(!n)
  return;
 free((struct int_rb_node *)((char *)n - (unsigned long)&(((struct int_rb_node *)(0))->node)));
}

user_defined_types: enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 }


decompiled_code:
void inttree_create()
{
_QWORD *v0; // rax

v0 = malloc(0x10uLL);
if ( v0 )
inttree_init_tree(v0);
}

canonical_decompiled_code:
void func3()
{
_QWORD *v0; // rax

v0 = malloc(0x10uLL);
if ( v0 )
func2(v0);
}

original_code:
struct rb_root *inttree_create(void)
{
 struct rb_root *tree = ((void *)0);
 if(!(tree = malloc(sizeof (struct rb_root)))) {
  return ((void *)0);
 }
 inttree_init_tree(tree);
 return tree;
}

canonical_original_code:
struct rb_root *inttree_create()
{
 struct rb_root *tree = ((void *)0);
 if(!(tree = malloc(sizeof (struct rb_root)))) {
  return ((void *)0);
 }
 inttree_init_tree(tree);
 return tree;
}

variable_types: struct rb_root { struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } *root; struct rb_tree_tmpl { struct rb_node *(*alloc_node)(__builtin_va_list); void (*free_node)(struct rb_node *); int (*ins_preprocess)(struct rb_root *, struct rb_node *); struct rb_node *(*del_preprocess)(struct rb_root *, __builtin_va_list); int (*order)(struct rb_node *, struct rb_node *); } *tmpl; } *

user_defined_types: struct rb_root { struct rb_node *root; struct rb_tree_tmpl *tmpl; }


decompiled_code:
__int64 inttree_dump()
{
__int64 result; // rax
__int64 v1; // rbp
unsigned int v2; // ebx
__int64 v3; // rsi

result = rb_leftmost();
if ( result )
{
v1 = result;
v2 = 0;
do
{
v3 = v2++;
printf("Node #%d : %d\n", v3, *(unsigned int *)(v1 - 8));
result = rb_successor(v1);
v1 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1; // rbp
unsigned int v2; // ebx
__int64 v3; // rsi

result = rb_leftmost();
if ( result )
{
v1 = result;
v2 = 0;
do
{
v3 = v2++;
printf("Node #%d : %d\n", v3, *(unsigned int *)(v1 - 8));
result = rb_successor(v1);
v1 = result;
}
while ( result );
}
return result;
}

original_code:
void inttree_dump(struct rb_root *root)
{
 int i = 0;
 struct rb_node *n = rb_leftmost(root);
 struct int_rb_node *int_n;
 while(n) {
  int_n = (struct int_rb_node*)((char*)n - (unsigned long)&(((struct int_rb_node*)(0))->node));
  printf("Node #%d : %d\n", i, int_n->k);
  n = rb_successor(n);
  i++;
 }
 return;
}

canonical_original_code:
void inttree_dump(struct rb_root *root)
{
 int i = 0;
 struct rb_node *n = rb_leftmost(root);
 struct int_rb_node *int_n;
 while(n) {
  int_n = (struct int_rb_node *)((char *)n - (unsigned long)&(((struct int_rb_node *)(0))->node));
  printf("Node #%d : %d\n", i, int_n->k);
  n = rb_successor(n);
  i++;
 }
 return;
}

variable_types: i int

user_defined_types: struct rb_tree_tmpl { struct rb_node *(*alloc_node)(__builtin_va_list); void (*free_node)(struct rb_node *); int (*ins_preprocess)(struct rb_root *, struct rb_node *); struct rb_node *(*del_preprocess)(struct rb_root *, __builtin_va_list); int (*order)(struct rb_node *, struct rb_node *); }


original_code:
static void rotate_left(struct rb_node *n, struct rb_root *root)
{
 struct rb_node *r = ((void *)0), *p = ((void *)0), *tmp = ((void *)0);
 int left = 0;
 if(!n || !n->r || !root)
  return;
 p = n->p;
 r = n->r;
 tmp = r->l;
 left = (p && (n == p->l));
 r->l = n;
 n->r = tmp;
 r->p = p;
 n->p = r;
 if(tmp)
  tmp->p = n;
 if(!p)
  root->root = r;
 else {
  if(left) {
   p->l = r;
  } else {
   p->r = r;
  }
 }
}

canonical_original_code:
static void rotate_left(struct rb_node *n, struct rb_root *root)
{
 struct rb_node *r = ((void *)0); struct rb_node *p = ((void *)0); struct rb_node *tmp = ((void *)0);
 int left = 0;
 if(!n || !n->r || !root)
  return;
 p = n->p;
 r = n->r;
 tmp = r->l;
 left = (p && (n == p->l));
 r->l = n;
 n->r = tmp;
 r->p = p;
 n->p = r;
 if(tmp)
  tmp->p = n;
 if(!p)
  root->root = r;
 else {
  if(left) {
   p->l = r;
  } else {
   p->r = r;
  }
 }
}

variable_types: struct rb_root { struct rb_node *root; struct rb_tree_tmpl { struct rb_node *(*alloc_node)(__builtin_va_list); void (*free_node)(struct rb_node *); int (*ins_preprocess)(struct rb_root *, struct rb_node *); struct rb_node *(*del_preprocess)(struct rb_root *, __builtin_va_list); int (*order)(struct rb_node *, struct rb_node *); } *tmpl; } *

variable_types: left int


original_code:
static void rotate_right(struct rb_node *n, struct rb_root *root)
{
 struct rb_node *l = ((void *)0), *tmp = ((void *)0), *p = ((void *)0);
 int left;
 if(!n || !n->l || !root)
  return;
 p = n->p;
 l = n->l;
 tmp = l->r;
 left = (p && (n == p->l));
 l->r = n;
 n->l = tmp;
 l->p = p;
 n->p = l;
 if(tmp)
  tmp->p = n;
 if(!p)
  root->root = l;
 else {
  if(left) {
   p->l = l;
  } else {
   p->r = l;
  }
 }
}

canonical_original_code:
static void rotate_right(struct rb_node *n, struct rb_root *root)
{
 struct rb_node *l = ((void *)0); struct rb_node *tmp = ((void *)0); struct rb_node *p = ((void *)0);
 int left;
 if(!n || !n->l || !root)
  return;
 p = n->p;
 l = n->l;
 tmp = l->r;
 left = (p && (n == p->l));
 l->r = n;
 n->l = tmp;
 l->p = p;
 n->p = l;
 if(tmp)
  tmp->p = n;
 if(!p)
  root->root = l;
 else {
  if(left) {
   p->l = l;
  } else {
   p->r = l;
  }
 }
}


original_code:
static int rb_delete_one_child(struct rb_node *node, struct rb_root *root)
{
 struct rb_node *p = ((void *)0), *c = ((void *)0);
 int isleft = 0;
 if(!node || !root)
  return -22;
 p = node->p;
 c = (((void *)0) == node->l) ? node->r : node->l;
 if(p) {
  if(node == p->l) {
   p->l = c;
   isleft = 1;
  } else if(node == p->r) {
   p->r = c;
  }
  if(c)
   c->p = p;
 } else {
  root->root = c;
  if(c)
   c->p = ((void *)0);
 }
 return isleft;
}

canonical_original_code:
static int rb_delete_one_child(struct rb_node *node, struct rb_root *root)
{
 struct rb_node *p = ((void *)0); struct rb_node *c = ((void *)0);
 int isleft = 0;
 if(!node || !root)
  return -22;
 p = node->p;
 c = (((void *)0) == node->l) ? node->r : node->l;
 if(p) {
  if(node == p->l) {
   p->l = c;
   isleft = 1;
  } else if(node == p->r) {
   p->r = c;
  }
  if(c)
   c->p = p;
 } else {
  root->root = c;
  if(c)
   c->p = ((void *)0);
 }
 return isleft;
}

variable_types: isleft int


original_code:
static void rb_delete_fixup(struct rb_root *root, struct rb_node *n,
  struct rb_node *p, int isleft)
{
 struct rb_node *s = ((void *)0);
 while((n != root->root) && (!n || n->clr == RB_COLOR_BLACK)) {
  if(isleft) {
   s = p->r;
   if(s && RB_COLOR_RED == s->clr) {
    s->clr = RB_COLOR_BLACK;
    p->clr = RB_COLOR_RED;
    rotate_left(p, root);
    s = p->r;
   }
   if(s && (!s->l || s->l->clr == RB_COLOR_BLACK) &&
    (!s->r || s->r->clr == RB_COLOR_BLACK)) {
    s->clr = RB_COLOR_RED;
    n = p;
    p = p->p;
    isleft = (p && n == p->l);
   } else {
    if(s && (!s->r || s->r->clr == RB_COLOR_BLACK)) {
     s->l->clr = RB_COLOR_BLACK;
     s->clr = RB_COLOR_RED;
     rotate_right(s, root);
     s = p->r;
    }
    if(s)
     s->clr = p->clr;
    p->clr = RB_COLOR_BLACK;
    if(s && s->r) {
     s->r->clr = RB_COLOR_BLACK;
    }
    rotate_left(p, root);
    break;
   }
  } else {
   s = p->l;
   if(s && RB_COLOR_RED == s->clr) {
    s->clr = RB_COLOR_BLACK;
    p->clr = RB_COLOR_RED;
    rotate_right(p, root);
    s = p->l;
   }
   if(s && (!s->l || s->l->clr == RB_COLOR_BLACK) &&
    (!s->r || s->r->clr == RB_COLOR_BLACK)) {
    s->clr = RB_COLOR_RED;
    n = p;
    p = p->p;
    isleft = (p && n == p->l);
   } else {
    if(s && (!s->l || s->l->clr == RB_COLOR_BLACK)) {
     s->r->clr = RB_COLOR_BLACK;
     s->clr = RB_COLOR_RED;
     rotate_left(s, root);
     s = p->l;
    }
    if(s)
     s->clr = p->clr;
    p->clr = RB_COLOR_BLACK;
    if(s && s->l) {
     s->l->clr = RB_COLOR_BLACK;
    }
    rotate_right(p, root);
    break;
   }
  }
 }
}

variable_types:
n
struct rb_node *

variable_types:
p
struct rb_node *


decompiled_code:
__int64 __fastcall rb_black_count(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rax
int v4; // ebp
int v5; // eax
unsigned int v6; // er12
unsigned int v7; // ebp

if ( a1 )
{
v2 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 24) == 1 )
{
v4 = 1;
}
else
{
if ( v2 && !*(_DWORD *)(v2 + 24) )
return (unsigned int)-1;
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
{
if ( !*(_DWORD *)(v3 + 24) )
return (unsigned int)-1;
}
v4 = 0;
}
v5 = ((__int64 (*)(void))rb_black_count)();
v6 = v5;
if ( v5 >= 0 )
{
v7 = v5 + v4;
v6 = -1;
if ( (unsigned int)rb_black_count(*(_QWORD *)(a1 + 16)) == v5 )
v6 = v7;
}
return v6;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rax
int v4; // ebp
int v5; // eax
unsigned int v6; // er12
unsigned int v7; // ebp

if ( a1 )
{
v2 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 24) == 1 )
{
v4 = 1;
}
else
{
if ( v2 && !*(_DWORD *)(v2 + 24) )
return (unsigned int)-1;
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
{
if ( !*(_DWORD *)(v3 + 24) )
return (unsigned int)-1;
}
v4 = 0;
}
v5 = ((__int64 (*)(void))rb_black_count)();
v6 = v5;
if ( v5 >= 0 )
{
v7 = v5 + v4;
v6 = -1;
if ( (unsigned int)func5(*(_QWORD *)(a1 + 16)) == v5 )
v6 = v7;
}
return v6;
}
return 0LL;
}

original_code:
static int rb_black_count(struct rb_node *node)
{
 int cnt = 0, tmp;
 if(!node)
  return 0;
 if(node->clr == RB_COLOR_BLACK) {
  cnt++;
 } else {
  if((node->l && node->l->clr == RB_COLOR_RED) ||
   (node->r && node->r->clr == RB_COLOR_RED)) {
   return -1;
  }
 }
 if(0 > (tmp = rb_black_count(node->l))) {
  return tmp;
 }
 if(tmp != rb_black_count(node->r)) {
  return -1;
 } else {
  return cnt + tmp;
 }
}

canonical_original_code:
static int rb_black_count(struct rb_node *node)
{
 int cnt = 0; int tmp;
 if(!node)
  return 0;
 if(node->clr == RB_COLOR_BLACK) {
  cnt++;
 } else {
  if((node->l && node->l->clr == RB_COLOR_RED) ||
   (node->r && node->r->clr == RB_COLOR_RED)) {
   return -1;
  }
 }
 if(0 > (tmp = rb_black_count(node->l))) {
  return tmp;
 }
 if(tmp != rb_black_count(node->r)) {
  return -1;
 } else {
  return cnt + tmp;
 }
}

variable_types: cnt int

variable_types: tmp int


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

if ( !a1 )
return 0LL;
for ( result = *a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

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

if ( !a1 )
return 0LL;
for ( result = *a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

original_code:
struct rb_node *rb_leftmost(struct rb_root *root)
{
 struct rb_node *n = ((void *)0);
 if(!root)
  return ((void *)0);
 n = root->root;
 while(n && n->l) {
  n = n->l;
 }
 return n;
}

return_type: struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } *


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

if ( !a1 )
return 0LL;
for ( result = *a1; result && *(_QWORD *)(result + 16); result = *(_QWORD *)(result + 16) )
;
return result;
}

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

if ( !a1 )
return 0LL;
for ( result = *a1; result && *(_QWORD *)(result + 16); result = *(_QWORD *)(result + 16) )
;
return result;
}

original_code:
struct rb_node *rb_rightmost(struct rb_root *root)
{
 struct rb_node *n = ((void *)0);
 if(!root)
  return ((void *)0);
 n = root->root;
 while(n && n->r) {
  n = n->r;
 }
 return n;
}


original_code:
int rb_balance(struct rb_node *node, struct rb_root *root)
{
 struct rb_node *g = ((void *)0), *p = ((void *)0), *u = ((void *)0);
 int uprising = 1;
 if(!node || !root) {
  return -22;
 }
 node->clr = RB_COLOR_RED;
 while(uprising) {
  if(!node->p) {
   node->clr = RB_COLOR_BLACK;
   return 0;
  }
  if(RB_COLOR_BLACK == node->p->clr) {
   return 0;
  }
  p = node->p;
  g = p->p;
  u = (p != g->l) ? g->l : g->r;
  if(u && RB_COLOR_RED == u->clr) {
   p->clr = RB_COLOR_BLACK;
   u->clr = RB_COLOR_BLACK;
   g->clr = RB_COLOR_RED;
   node = g;
  } else {
   uprising = 0;
  }
 }
 if((p->r == node) && (g->l == p)) {
  rotate_left(p, root);
  node = node->l;
  p = node->p;
  g = p->p;
 } else if((p->l == node) && (g->r == p)) {
  rotate_right(p, root);
  node = node->r;
  p = node->p;
  g = p->p;
 }
 p->clr = RB_COLOR_BLACK;
 g->clr = RB_COLOR_RED;
 if(node == p->l) {
  rotate_right(g, root);
 } else {
  rotate_left(g, root);
 }
 return 0;
}

canonical_original_code:
int rb_balance(struct rb_node *node, struct rb_root *root)
{
 struct rb_node *g = ((void *)0); struct rb_node *p = ((void *)0); struct rb_node *u = ((void *)0);
 int uprising = 1;
 if(!node || !root) {
  return -22;
 }
 node->clr = RB_COLOR_RED;
 while(uprising) {
  if(!node->p) {
   node->clr = RB_COLOR_BLACK;
   return 0;
  }
  if(RB_COLOR_BLACK == node->p->clr) {
   return 0;
  }
  p = node->p;
  g = p->p;
  u = (p != g->l) ? g->l : g->r;
  if(u && RB_COLOR_RED == u->clr) {
   p->clr = RB_COLOR_BLACK;
   u->clr = RB_COLOR_BLACK;
   g->clr = RB_COLOR_RED;
   node = g;
  } else {
   uprising = 0;
  }
 }
 if((p->r == node) && (g->l == p)) {
  rotate_left(p, root);
  node = node->l;
  p = node->p;
  g = p->p;
 } else if((p->l == node) && (g->r == p)) {
  rotate_right(p, root);
  node = node->r;
  p = node->p;
  g = p->p;
 }
 p->clr = RB_COLOR_BLACK;
 g->clr = RB_COLOR_RED;
 if(node == p->l) {
  rotate_right(g, root);
 } else {
  rotate_left(g, root);
 }
 return 0;
}

variable_types: uprising int


original_code:
int rb_insert_raw(struct rb_root *root, struct rb_node *n)
{
 int order = 0;
 struct rb_node **p = &(root->root), *parent = ((void *)0);
 while(*p) {
  parent = *p;
  order = root->tmpl->order(n, (*p));
  if(0 > order) {
   p = &((*p)->l);
  } else if(0 < order) {
   p = &((*p)->r);
  } else {
   return -61;
  }
 }
 rb_link_node(n, parent, p);
 rb_balance(n, root);
 return 0;
}

canonical_original_code:
int rb_insert_raw(struct rb_root *root, struct rb_node *n)
{
 int order = 0;
 struct rb_node **p = &(root->root); struct rb_node *parent = ((void *)0);
 while(*p) {
  parent = *p;
  order = root->tmpl->order(n, (*p));
  if(0 > order) {
   p = &((*p)->l);
  } else if(0 < order) {
   p = &((*p)->r);
  } else {
   return -61;
  }
 }
 rb_link_node(n, parent, p);
 rb_balance(n, root);
 return 0;
}

variable_types: order int

variable_types: struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } **


original_code:
int rb_insert_v(struct rb_root *tree, va_list args)
{
 int ret = 0;
 struct rb_node *node = ((void *)0);
 node = tree->tmpl->alloc_node(args);
 if(!tree || !tree->tmpl ||
  (tree->tmpl->ins_preprocess &&
    (ret = tree->tmpl->ins_preprocess(tree, node)))) {
  return (ret) ? ret : -22;
 }
 ret = rb_insert_raw(tree, node);
 if(-61 == ret) {
  tree->tmpl->free_node(node);
 }
 return 0;
}

canonical_original_code:
int rb_insert_v(struct rb_root *tree, __builtin_va_list args)
{
 int ret = 0;
 struct rb_node *node = ((void *)0);
 node = tree->tmpl->alloc_node(args);
 if(!tree || !tree->tmpl ||
  (tree->tmpl->ins_preprocess &&
    (ret = tree->tmpl->ins_preprocess(tree, node)))) {
  return (ret) ? ret : -22;
 }
 ret = rb_insert_raw(tree, node);
 if(-61 == ret) {
  tree->tmpl->free_node(node);
 }
 return 0;
}

variable_types: ret int


decompiled_code:
__int64 rb_insert(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return rb_insert_v(a1, (__int64)va);
}

canonical_decompiled_code:
__int64 func12(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func11(a1, (__int64)va);
}

original_code:
int rb_insert(struct rb_root *tree, ...)
{
 va_list args;
 int ret = 0;
 __builtin_va_start(args,tree);
 ret = rb_insert_v(tree, args);
 __builtin_va_end(args);
 return ret;
}

canonical_original_code:
int rb_insert(struct rb_root *tree, ...)
{
 __builtin_va_list args;
 int ret = 0;
 __builtin_va_start(args,tree);
 ret = rb_insert_v(tree, args);
 __builtin_va_end(args);
 return ret;
}


original_code:
void rb_erase_raw(struct rb_node *node, struct rb_root *root)
{
 struct rb_node *c = ((void *)0), *neighbor = ((void *)0), *p = ((void *)0);
 int isleft = 0;
 if(!node || !root || !root->tmpl || !root->tmpl->free_node)
  return;
 if(node->l && node->r) {
  neighbor = rb_predecessor(node);
  rb_swap_nodes(root, node, neighbor);
 }
 c = (node->l == ((void *)0)) ? node->r : node->l;
 p = node->p;
 isleft = rb_delete_one_child(node, root);
 if(RB_COLOR_BLACK == node->clr) {
  rb_delete_fixup(root, c, p, isleft);
 }
}

canonical_original_code:
void rb_erase_raw(struct rb_node *node, struct rb_root *root)
{
 struct rb_node *c = ((void *)0); struct rb_node *neighbor = ((void *)0); struct rb_node *p = ((void *)0);
 int isleft = 0;
 if(!node || !root || !root->tmpl || !root->tmpl->free_node)
  return;
 if(node->l && node->r) {
  neighbor = rb_predecessor(node);
  rb_swap_nodes(root, node, neighbor);
 }
 c = (node->l == ((void *)0)) ? node->r : node->l;
 p = node->p;
 isleft = rb_delete_one_child(node, root);
 if(RB_COLOR_BLACK == node->clr) {
  rb_delete_fixup(root, c, p, isleft);
 }
}


original_code:
void rb_erase_free(struct rb_node *node, struct rb_root *root)
{
 if(!node || !root || !root->tmpl || !root->tmpl->free_node)
  return;
 rb_erase_raw(node, root);
 root->tmpl->free_node(node);
}


original_code:
void rb_clear(struct rb_root *root)
{
 if(!root)
  return;
 while(((void *)0) != root->root) {
  rb_erase_free(root->root, root);
 }
}


decompiled_code:
__int64 __fastcall rb_merge(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__m128i *v3; // rbp

if ( !a1 )
return 4294967274LL;
if ( !a2 || a1[1] != *(_QWORD *)(a2 + 8) )
return 4294967274LL;
while ( 1 )
{
v3 = *(__m128i **)a2;
if ( !*(_QWORD *)a2 )
break;
rb_erase_raw(*(__m128i **)a2, a2);
result = rb_insert_raw(a1, v3);
if ( (_DWORD)result )
return result;
}
return 0LL;
}

original_code:
int rb_merge(struct rb_root *dst, struct rb_root *src)
{
 int err = 0;
 struct rb_node *node = ((void *)0);
 if(!dst || !src || (dst->tmpl != src->tmpl)) {
  return -22;
 }
 while(((void *)0) != src->root) {
  node = src->root;
  rb_erase_raw(node, src);
  err = rb_insert_raw(dst, node);
  if(err) {
   break;
  }
 }
 return err;
}

variable_types:
src
struct rb_root *

variable_types: err int


original_code:
struct rb_node *rb_find_v(struct rb_root *root, va_list args)
{
 int order = 0;
 struct rb_node *tgt = ((void *)0), *n = ((void *)0);
 if(!root || !root->tmpl)
  return ((void *)0);
 if(!(tgt = root->tmpl->alloc_node(args))) {
  return ((void *)0);
 }
 n = root->root;
 while(n) {
  order = root->tmpl->order(tgt, n);
  if(0 > order) {
   n = n->l;
  } else if(0 < order) {
   n = n->r;
  } else {
   root->tmpl->free_node(tgt);
   return n;
  }
 }
 root->tmpl->free_node(tgt);
 return ((void *)0);
}

canonical_original_code:
struct rb_node *rb_find_v(struct rb_root *root, __builtin_va_list args)
{
 int order = 0;
 struct rb_node *tgt = ((void *)0); struct rb_node *n = ((void *)0);
 if(!root || !root->tmpl)
  return ((void *)0);
 if(!(tgt = root->tmpl->alloc_node(args))) {
  return ((void *)0);
 }
 n = root->root;
 while(n) {
  order = root->tmpl->order(tgt, n);
  if(0 > order) {
   n = n->l;
  } else if(0 < order) {
   n = n->r;
  } else {
   root->tmpl->free_node(tgt);
   return n;
  }
 }
 root->tmpl->free_node(tgt);
 return ((void *)0);
}

variable_types: struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } *


decompiled_code:
__int64 rb_find(__int64 *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return rb_find_v(a1, (__int64)va);
}

canonical_decompiled_code:
__int64 func18(__int64 *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func17(a1, (__int64)va);
}

original_code:
struct rb_node *rb_find(struct rb_root *root, ...)
{
 va_list args;
 struct rb_node *n = ((void *)0);
 __builtin_va_start(args,root);
 n = rb_find_v(root, args);
 __builtin_va_end(args);
 return n;
}

canonical_original_code:
struct rb_node *rb_find(struct rb_root *root, ...)
{
 __builtin_va_list args;
 struct rb_node *n = ((void *)0);
 __builtin_va_start(args,root);
 n = rb_find_v(root, args);
 __builtin_va_end(args);
 return n;
}


decompiled_code:
__int64 __fastcall rb_tree_is_sane(__int64 *a1)
{
__int64 v1; // rdi
__int64 result; // rax

if ( a1 && (v1 = *a1) != 0 )
result = rb_black_count(v1);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 *a1)
{
__int64 v1; // rdi
__int64 result; // rax

if ( a1 && (v1 = *a1) != 0 )
result = func5(v1);
else
result = 0LL;
return result;
}

original_code:
int rb_tree_is_sane(struct rb_root *tree)
{
 int res = 1;
 struct rb_node *n = ((void *)0);
 if(!tree)
  return 0;
 if(!tree->root)
  return 0;
 res = rb_black_count(tree->root);
 return res;
}

variable_types: res int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
const void *v5; // rcx
const void *v6; // r8
const void *v7; // r9
__int64 v8; // rdx
__int64 v9; // rdx
const void **v10; // rax
__int64 v12[3]; // [rsp+0h] [rbp-18h] BYREF

inttree_init_tree(v12, argv, envp);
rb_insert(v12, &algn_1);
rb_insert(v12, " %d\n", v3);
rb_insert(v12, "rev is : %d (%p)\n->l : %p | ->r : %p\n", v4, v5, v6, v7);
rb_insert(v12, "s : %d\n", v8);
rb_insert(v12, "t is : %d\n", v9);
printf("Root is : %d\n", *(unsigned int *)(v12[0] - 8));
v10 = (const void **)rb_predecessor(v12[0]);
printf("Prev is : %d (%p)\n->l : %p | ->r : %p\n", *((unsigned int *)v10 - 2), v10, v10[1], v10[2]);
rb_erase_raw(v12[0], v12);
inttree_dump(v12);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct rb_root root;
 struct int_rb_node *ze_root = ((void *)0), *ze_pred = ((void *)0);
 struct rb_node *prev = ((void *)0);
 inttree_init_tree(&root);
 rb_insert(&root, 1);
 rb_insert(&root, 12);
 rb_insert(&root, 25);
 rb_insert(&root, 9);
 rb_insert(&root, 6);
 ze_root = (struct int_rb_node*)((char*)root.root - (unsigned long)&(((struct int_rb_node*)(0))->node));
 printf("Root is : %d\n", ze_root->k);
 prev = rb_predecessor(root.root);
 ze_pred = (struct int_rb_node*)((char*)prev - (unsigned long)&(((struct int_rb_node*)(0))->node));
 printf("Prev is : %d (%p)\n->l : %p | ->r : %p\n", ze_pred->k, prev, prev->l, prev->r);
 rb_erase_raw(root.root, &root);
 inttree_dump(&root);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct rb_root root;
 struct int_rb_node *ze_root = ((void *)0); struct int_rb_node *ze_pred = ((void *)0);
 struct rb_node *prev = ((void *)0);
 inttree_init_tree(&root);
 rb_insert(&root, 1);
 rb_insert(&root, 12);
 rb_insert(&root, 25);
 rb_insert(&root, 9);
 rb_insert(&root, 6);
 ze_root = (struct int_rb_node *)((char *)root.root - (unsigned long)&(((struct int_rb_node *)(0))->node));
 printf("Root is : %d\n", ze_root->k);
 prev = rb_predecessor(root.root);
 ze_pred = (struct int_rb_node *)((char *)prev - (unsigned long)&(((struct int_rb_node *)(0))->node));
 printf("Prev is : %d (%p)\n->l : %p | ->r : %p\n", ze_pred->k, prev, prev->l, prev->r);
 rb_erase_raw(root.root, &root);
 inttree_dump(&root);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct rb_root { struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } *root; struct rb_tree_tmpl { struct rb_node *(*alloc_node)(__builtin_va_list); void (*free_node)(struct rb_node *); int (*ins_preprocess)(struct rb_root *, struct rb_node *); struct rb_node *(*del_preprocess)(struct rb_root *, __builtin_va_list); int (*order)(struct rb_node *, struct rb_node *); } *tmpl; }

variable_types: struct int_rb_node { int k; struct rb_node { struct rb_node *p; enum rb_color { RB_COLOR_RED=0, RB_COLOR_BLACK=1 } clr; } node; } *


hash

repo: RiJo/hashmap

decompiled_code:
__int64 __fastcall hash(_BYTE *a1, int a2, unsigned int a3)
{
int v3; // ecx
unsigned int v4; // er9
unsigned int v5; // eax
int v6; // eax

v3 = (char)*a1;
v4 = 0;
if ( *a1 )
{
v5 = 0;
do
{
++a1;
v6 = v3 + v5;
v3 = (char)*a1;
v5 = a2 * v6;
}
while ( *a1 );
v4 = v5 % a3;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, int a2, unsigned int a3)
{
int v3; // ecx
unsigned int v4; // er9
unsigned int v5; // eax
int v6; // eax

v3 = (char)*a1;
v4 = 0;
if ( *a1 )
{
v5 = 0;
do
{
++a1;
v6 = v3 + v5;
v3 = (char)*a1;
v5 = a2 * v6;
}
while ( *a1 );
v4 = v5 % a3;
}
return v4;
}

original_code:
unsigned int hash(char *c, unsigned int step, unsigned int size) {
    unsigned int hashvalue = 0;
    if (!*c) return 0;
    do {
        hashvalue += *c++;
        hashvalue *= step;
    } while (*c);
    return (hashvalue % size);
}

variable_types:
c
char *

variable_types:
step
unsigned int

variable_types:
size
unsigned int

variable_types:
hashvalue
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall next_size(unsigned int a1)
{
unsigned int *v1; // rax
unsigned int i; // er8

v1 = (unsigned int *)&unk_CE4;
for ( i = 5; a1 >= i; i = *v1++ )
{
if ( v1 == (unsigned int *)3356 )
{
fwrite("Warning: Could not increase size more with prime numbers, doubling instead\n", 1uLL, 0x4BuLL, stderr);
return 2 * a1;
}
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned int *v1; // rax
unsigned int i; // er8

v1 = (unsigned int *)&unk_CE4;
for ( i = 5; a1 >= i; i = *v1++ )
{
if ( v1 == (unsigned int *)3356 )
{
fwrite("Warning: Could not increase size more with prime numbers, doubling instead\n", 1uLL, 0x4BuLL, stderr);
return 2 * a1;
}
}
return i;
}

original_code:
unsigned int next_size(unsigned int size) {
    unsigned int count = sizeof(sizes) / sizeof(unsigned int);
    for (unsigned int i = 0; i < count; i++) {
        if (sizes[i] > size) {
            return sizes[i];
        }
    }
    fprintf(stderr, "Warning: Could not increase size more with prime numbers, doubling instead\n");
    return size * 2;
}

variable_types:
count
unsigned int

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall get_item(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
do
{
if ( !strcmp(a2, *(const char **)v2) )
return v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
do
{
if ( !strcmp(a2, *(const char **)v2) )
return v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return 0LL;
}

original_code:
item *get_item(item *list, char *key) {
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (strcmp(key, list->key) == 0) {
        return list;
    }
    return get_item(list->next, key);
}

canonical_original_code:
struct node *get_item(struct node *list, char *key) {
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (strcmp(key, list->key) == 0) {
        return list;
    }
    return get_item(list->next, key);
}

variable_types:
list
struct node *

variable_types:
key
char *

return_type: struct node { char *key; void *value; struct node *next; } *


decompiled_code:
__int64 __fastcall remove_item(__int64 a1, const char *a2, _DWORD *a3)
{
char *v3; // r15
int v5; // eax
__int64 v6; // r14
__int64 v7; // r14

if ( !a1 )
return 0LL;
v3 = *(char **)a1;
v5 = strcmp(a2, *(const char **)a1);
v6 = *(_QWORD *)(a1 + 16);
if ( v5 )
{
v7 = a1;
*(_QWORD *)(a1 + 16) = remove_item(*(_QWORD *)(a1 + 16), a2, a3);
return v7;
}
free(v3);
free(*(void **)(a1 + 8));
free((void *)a1);
--*a3;
return v6;
}

original_code:
item *remove_item(item *list, char *key, int *count) {
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (strcmp(key, list->key) == 0) {
        item *next = list->next;
        free(list->key);
        free(list->value);
        free(list);
        (*count)--;
        ;
        return next;
    }
    list->next = remove_item(list->next, key, count);
    return list;
}

canonical_original_code:
struct node *remove_item(struct node *list, char *key, int *count) {
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (strcmp(key, list->key) == 0) {
        struct node *next = list->next;
        free(list->key);
        free(list->value);
        free(list);
        (*count)--;
        ;
        return next;
    }
    list->next = remove_item(list->next, key, count);
    return list;
}

variable_types:
count
int *

variable_types: struct node { char *key; void *value; struct node *next; } *


decompiled_code:
__int64 __fastcall remove_items(__int64 a1, void (__fastcall *a2)(void *), _DWORD *a3)
{
void *v5; // rdi

if ( !a1 )
return 0LL;
if ( *(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = remove_items();
free(*(void **)a1);
v5 = *(void **)(a1 + 8);
if ( a2 )
a2(v5);
else
free(v5);
free((void *)a1);
--*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, void (__fastcall *a2)(void *), _DWORD *a3)
{
void *v5; // rdi

if ( !a1 )
return 0LL;
if ( *(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = func4();
free(*(void **)a1);
v5 = *(void **)(a1 + 8);
if ( a2 )
a2(v5);
else
free(v5);
free((void *)a1);
--*a3;
return 0LL;
}

original_code:
item *remove_items(item *list, void (*free_value)(void *), int *count) {
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (list->next != ((void *)0)) {
        list->next = remove_items(list->next, free_value, count);
    }
    free(list->key);
    if (free_value != ((void *)0)) {
        free_value(list->value);
    }
    else {
        free(list->value);
    }
    free(list);
    (*count)--;
    ;
    return ((void *)0);
}

canonical_original_code:
struct node *remove_items(struct node *list, void (*free_value)(void *), int *count) {
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (list->next != ((void *)0)) {
        list->next = remove_items(list->next, free_value, count);
    }
    free(list->key);
    if (free_value != ((void *)0)) {
        free_value(list->value);
    }
    else {
        free(list->value);
    }
    free(list);
    (*count)--;
    ;
    return ((void *)0);
}

user_defined_types: struct node { char *key; void *value; struct node *next; }


decompiled_code:
__int64 __fastcall key_exists(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
do
{
if ( !strcmp(a2, *(const char **)v2) )
return 1LL;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
do
{
if ( !strcmp(a2, *(const char **)v2) )
return 1LL;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return 0LL;
}

original_code:
int key_exists(item *list, char *key) {
    if (list == ((void *)0)) {
        return 0;
    }
    if (strcmp(key, list->key) == 0) {
        return 1;
    }
    return key_exists(list->next, key);
}

canonical_original_code:
int key_exists(struct node *list, char *key) {
    if (list == ((void *)0)) {
        return 0;
    }
    if (strcmp(key, list->key) == 0) {
        return 1;
    }
    return key_exists(list->next, key);
}


decompiled_code:
__int64 __fastcall update_item_list(__int64 a1, __int64 a2)
{
__int64 v3; // rdi

*(_QWORD *)(a2 + 16) = 0LL;
if ( !a1 )
return a2;
if ( !strcmp(*(const char **)a2, *(const char **)a1) )
return a1;
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
{
*(_QWORD *)(a1 + 16) = update_item_list(v3, a2);
return a1;
}
*(_QWORD *)(a1 + 16) = a2;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v3; // rdi

*(_QWORD *)(a2 + 16) = 0LL;
if ( !a1 )
return a2;
if ( !strcmp(*(const char **)a2, *(const char **)a1) )
return a1;
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
{
*(_QWORD *)(a1 + 16) = func6(v3, a2);
return a1;
}
*(_QWORD *)(a1 + 16) = a2;
return a1;
}

original_code:
item *update_item_list(item *list, item *match) {
    match->next = ((void *)0);
    if (list == ((void *)0)) {
        return match;
    }
    if (strcmp(match->key, list->key) == 0) {
        return list;
    }
    if (list->next == ((void *)0)) {
        list->next = match;
        return list;
    }
    list->next = update_item_list(list->next, match);
    return list;
}

canonical_original_code:
struct node *update_item_list(struct node *list, struct node *match) {
    match->next = ((void *)0);
    if (list == ((void *)0)) {
        return match;
    }
    if (strcmp(match->key, list->key) == 0) {
        return list;
    }
    if (list->next == ((void *)0)) {
        list->next = match;
        return list;
    }
    list->next = update_item_list(list->next, match);
    return list;
}

variable_types:
match
struct node *


original_code:
int hm_clear(hashmap *map, void (*free_value)(void *)) {
    int counter = 0;
    for (int i = 0; i < map->size; i++) {
        map->items[i] = remove_items(map->items[i], free_value, &counter);
    }
    map->count += counter;
    ;
    return 1;
}

canonical_original_code:
int hm_clear(struct hashmap *map, void (*free_value)(void *)) {
    int counter = 0;
    for (int i = 0; i < map->size; i++) {
        map->items[i] = remove_items(map->items[i], free_value, &counter);
    }
    map->count += counter;
    ;
    return 1;
}

variable_types: struct hashmap { struct node { char *key; void *value; struct node *next; } **items; unsigned int count; unsigned int size; float load_factor; int hash_step; } *

variable_types: counter int

variable_types: i int

user_defined_types: struct hashmap { struct node **items; unsigned int count; unsigned int size; float load_factor; int hash_step; }


decompiled_code:
__int64 __fastcall hm_delete(void *ptr, void (__fastcall *a2)(void *))
{
hm_clear((__int64)ptr, a2);
free(*(void **)ptr);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *ptr, void (__fastcall *a2)(void *))
{
func8((__int64)ptr, a2);
free(*(void **)ptr);
free(ptr);
return 1LL;
}

original_code:
int hm_delete(hashmap *map, void (*free_value)(void *)) {
    hm_clear(map, free_value);
    free(map->items);
    free(map);
    ;
    return 1;
}

canonical_original_code:
int hm_delete(struct hashmap *map, void (*free_value)(void *)) {
    hm_clear(map, free_value);
    free(map->items);
    free(map);
    ;
    return 1;
}


decompiled_code:
__int64 __fastcall hm_get(__int64 a1, _BYTE *a2)
{
unsigned int v2; // eax
_QWORD *v3; // r11
const char *v4; // r10
__int64 result; // rax

if ( a2 )
{
v2 = hash(a2, *(_DWORD *)(a1 + 20), *(_DWORD *)(a1 + 12));
result = get_item(*(_QWORD *)(*v3 + 8LL * v2), v4);
if ( result )
result = *(_QWORD *)(result + 8);
}
else
{
fwrite("Warning: trying to read NULL key, returning NULL\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _BYTE *a2)
{
unsigned int v2; // eax
_QWORD *v3; // r11
const char *v4; // r10
__int64 result; // rax

if ( a2 )
{
v2 = func0(a2, *(_DWORD *)(a1 + 20), *(_DWORD *)(a1 + 12));
result = func2(*(_QWORD *)(*v3 + 8LL * v2), v4);
if ( result )
result = *(_QWORD *)(result + 8);
}
else
{
fwrite("Warning: trying to read NULL key, returning NULL\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
void *hm_get(hashmap *map, char *key) {
    if (key == ((void *)0)) {
        fprintf(stderr, "Warning: trying to read NULL key, returning NULL\n");
        return ((void *)0);
    }
    unsigned int index = hash(key, map->hash_step, map->size);
    item *temp = get_item(map->items[index], key);
    return (temp == ((void *)0)) ? ((void *)0) : temp->value;
}

canonical_original_code:
void *hm_get(struct hashmap *map, char *key) {
    if (key == ((void *)0)) {
        fprintf(stderr, "Warning: trying to read NULL key, returning NULL\n");
        return ((void *)0);
    }
    unsigned int index = hash(key, map->hash_step, map->size);
    struct node *temp = get_item(map->items[index], key);
    return (temp == ((void *)0)) ? ((void *)0) : temp->value;
}

variable_types:
index
unsigned int


decompiled_code:
__int64 __fastcall hm_set(__int64 a1, _BYTE *a2)
{
int v3; // eax
__int64 *v4; // rdx
__int64 *v5; // rbx
const char *v6; // r10
void *v7; // r11
_QWORD *v8; // rax
signed int v9; // edi
float v10; // xmm0_4
__int64 result; // rax
unsigned int v12; // eax
int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a2 )
{
v3 = hash(a2, *(_DWORD *)(a1 + 20), *(_DWORD *)(a1 + 12));
v4 = *(__int64 **)a1;
v13[0] = 0;
v5 = &v4[v3];
v8 = set_item(*v5, v6, v7, v13);
v9 = *(_DWORD *)(a1 + 12);
*v5 = (__int64)v8;
LODWORD(v8) = *(_DWORD *)(a1 + 8) + v13[0];
v10 = (float)(int)v8;
*(_DWORD *)(a1 + 8) = (_DWORD)v8;
result = 1LL;
if ( (float)(v10 / (float)v9) > *(float *)(a1 + 16) )
{
v12 = next_size(v9);
hm_rehash((__int64 **)a1, v12);
result = 1LL;
}
}
else
{
fwrite("Warning: trying to read NULL key, returning NULL\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _BYTE *a2)
{
int v3; // eax
__int64 *v4; // rdx
__int64 *v5; // rbx
const char *v6; // r10
void *v7; // r11
_QWORD *v8; // rax
signed int v9; // edi
float v10; // xmm0_4
__int64 result; // rax
unsigned int v12; // eax
int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a2 )
{
v3 = func0(a2, *(_DWORD *)(a1 + 20), *(_DWORD *)(a1 + 12));
v4 = *(__int64 **)a1;
v13[0] = 0;
v5 = &v4[v3];
v8 = set_item(*v5, v6, v7, v13);
v9 = *(_DWORD *)(a1 + 12);
*v5 = (__int64)v8;
LODWORD(v8) = *(_DWORD *)(a1 + 8) + v13[0];
v10 = (float)(int)v8;
*(_DWORD *)(a1 + 8) = (_DWORD)v8;
result = 1LL;
if ( (float)(v10 / (float)v9) > *(float *)(a1 + 16) )
{
v12 = func1(v9);
hm_rehash((__int64 **)a1, v12);
result = 1LL;
}
}
else
{
fwrite("Warning: trying to read NULL key, returning NULL\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int hm_set(hashmap *map, char *key, void *value) {
    if (key == ((void *)0)) {
        fprintf(stderr, "Warning: trying to read NULL key, returning NULL\n");
        return 0;
    }
    unsigned int index = hash(key, map->hash_step, map->size);
    int counter = 0;
    map->items[index] = set_item(map->items[index], key, value, &counter);
    map->count += counter;
    if ((float)map->count/(float)map->size > map->load_factor) {
        hm_rehash(map, next_size(map->size));
    }
    return 1;
}

canonical_original_code:
int hm_set(struct hashmap *map, char *key, void *value) {
    if (key == ((void *)0)) {
        fprintf(stderr, "Warning: trying to read NULL key, returning NULL\n");
        return 0;
    }
    unsigned int index = hash(key, map->hash_step, map->size);
    int counter = 0;
    map->items[index] = set_item(map->items[index], key, value, &counter);
    map->count += counter;
    if ((float)map->count/(float)map->size > map->load_factor) {
        hm_rehash(map, next_size(map->size));
    }
    return 1;
}

variable_types:
value
void *


original_code:
int hm_unset(hashmap *map, char *key) {
    unsigned int index = hash(key, map->hash_step, map->size);
    int counter = 0;
    map->items[index] = remove_item(map->items[index], key, &counter);
    map->count += counter;
    return 1;
}

canonical_original_code:
int hm_unset(struct hashmap *map, char *key) {
    unsigned int index = hash(key, map->hash_step, map->size);
    int counter = 0;
    map->items[index] = remove_item(map->items[index], key, &counter);
    map->count += counter;
    return 1;
}


decompiled_code:
__int64 __fastcall hm_isset(__int64 a1, _BYTE *a2)
{
unsigned int v2; // eax
_QWORD *v3; // r10
const char *v4; // r11

v2 = hash(a2, *(_DWORD *)(a1 + 20), *(_DWORD *)(a1 + 12));
return key_exists(*(_QWORD *)(*v3 + 8LL * v2), v4);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, _BYTE *a2)
{
unsigned int v2; // eax
_QWORD *v3; // r10
const char *v4; // r11

v2 = func0(a2, *(_DWORD *)(a1 + 20), *(_DWORD *)(a1 + 12));
return func5(*(_QWORD *)(*v3 + 8LL * v2), v4);
}

original_code:
int hm_isset(hashmap *map, char *key) {
    unsigned int index = hash(key, map->hash_step, map->size);
    return key_exists(map->items[index], key);
}

canonical_original_code:
int hm_isset(struct hashmap *map, char *key) {
    unsigned int index = hash(key, map->hash_step, map->size);
    return key_exists(map->items[index], key);
}


original_code:
void backpropagate_hidden(NN *network, float *previous_deltas, unsigned int layer) {
    ;
    ;
    if (layer == 0) {
        return;
    }
    Neuron *current_neuron;
    Synapse *synapse;
    float error, change;
    float *deltas = (float *)malloc(sizeof(float) * network->neuron_count[layer]);
    for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
        current_neuron = &network->layers[layer][neuron];
        error = 0.0;
        for (unsigned int output = 0; output > current_neuron->output_count; output++) {
            for (unsigned int previous = 0; previous < network->neuron_count[layer + 1]; previous++) {
                if (current_neuron->outputs[output]->output == network->layers[previous])
                    error += (previous_deltas[previous] * current_neuron->outputs[output]->weight);
            }
        }
        deltas[neuron] = error * neuron_dsigmoid(current_neuron);
    }
    backpropagate_hidden(network, deltas, layer - 1);
    for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
        current_neuron = &network->layers[layer][neuron];
        for (unsigned int input = 0; input < current_neuron->input_count; input++) {
            synapse = current_neuron->inputs[input];
            change = synapse->input->output * deltas[neuron];
            synapse_change(synapse, change);
        }
    }
    free(deltas);
}

canonical_original_code:
void backpropagate_hidden(struct NN *network, float *previous_deltas, unsigned int layer) {
    ;
    ;
    if (layer == 0) {
        return;
    }
    struct Neuron *current_neuron;
    struct Synapse *synapse;
    float error; float change;
    float *deltas = (float *)malloc(sizeof(float) * network->neuron_count[layer]);
    for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
        current_neuron = &network->layers[layer][neuron];
        error = 0.0;
        for (unsigned int output = 0; output > current_neuron->output_count; output++) {
            for (unsigned int previous = 0; previous < network->neuron_count[layer + 1]; previous++) {
                if (current_neuron->outputs[output]->output == network->layers[previous])
                    error += (previous_deltas[previous] * current_neuron->outputs[output]->weight);
            }
        }
        deltas[neuron] = error * neuron_dsigmoid(current_neuron);
    }
    backpropagate_hidden(network, deltas, layer - 1);
    for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
        current_neuron = &network->layers[layer][neuron];
        for (unsigned int input = 0; input < current_neuron->input_count; input++) {
            synapse = current_neuron->inputs[input];
            change = synapse->input->output * deltas[neuron];
            synapse_change(synapse, change);
        }
    }
    free(deltas);
}

variable_types: struct NN { struct Neuron { float bias; float input; float output; struct Synapse { struct Neuron *input; struct Neuron *output; float weight; float change; float momentum; float learn_rate; } **inputs; struct Synapse **outputs; unsigned int input_count; unsigned int output_count; float (*sigmoid_function)(float); float (*dsigmoid_function)(float); } **layers; struct Synapse **synapses; unsigned int layer_count; unsigned int *neuron_count; unsigned int synapse_count; } *

variable_types:
layer
unsigned int

variable_types: struct Synapse { struct Neuron { float bias; float input; float output; struct Synapse **inputs; struct Synapse **outputs; unsigned int input_count; unsigned int output_count; float (*sigmoid_function)(float); float (*dsigmoid_function)(float); } *input; struct Neuron *output; float weight; float change; float momentum; float learn_rate; } *

variable_types: error float

variable_types: change float

variable_types:
deltas
float *

variable_types:
neuron
unsigned int

variable_types:
output
unsigned int

variable_types:
previous
unsigned int

variable_types:
input
unsigned int

user_defined_types: struct NN { struct Neuron **layers; struct Synapse **synapses; unsigned int layer_count; unsigned int *neuron_count; unsigned int synapse_count; }


original_code:
void backpropagate_output(NN *network, TD *train_data) {
    ;
    ;
    unsigned int layer = network->layer_count - 1;
    Neuron *current_neuron;
    Synapse *synapse;
    float error, change;
    float *deltas;
    for (unsigned int test = 0; test < train_data->data_count; test++) {
        for (unsigned int input = 0; input < train_data->input_count; input++) {
            network->layers[0][input].input = train_data->input[test][input];
        }
        nn_calculate(network);
        deltas = (float *)malloc(sizeof(float) * network->neuron_count[layer]);
        for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
            current_neuron = &network->layers[layer][neuron];
            error = train_data->output[test][neuron] - current_neuron->output;
            deltas[neuron] = error * neuron_dsigmoid(current_neuron);
        }
        backpropagate_hidden(network, deltas, layer - 1);
        for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
            current_neuron = &network->layers[layer][neuron];
            for (unsigned int input = 0; input < current_neuron->input_count; input++) {
                synapse = current_neuron->inputs[input];
                change = synapse->input->output * deltas[neuron];
                synapse_change(synapse, change);
            }
        }
        free(deltas);
    }
}

canonical_original_code:
void backpropagate_output(struct NN *network, struct TD *train_data) {
    ;
    ;
    unsigned int layer = network->layer_count - 1;
    struct Neuron *current_neuron;
    struct Synapse *synapse;
    float error; float change;
    float *deltas;
    for (unsigned int test = 0; test < train_data->data_count; test++) {
        for (unsigned int input = 0; input < train_data->input_count; input++) {
            network->layers[0][input].input = train_data->input[test][input];
        }
        nn_calculate(network);
        deltas = (float *)malloc(sizeof(float) * network->neuron_count[layer]);
        for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
            current_neuron = &network->layers[layer][neuron];
            error = train_data->output[test][neuron] - current_neuron->output;
            deltas[neuron] = error * neuron_dsigmoid(current_neuron);
        }
        backpropagate_hidden(network, deltas, layer - 1);
        for (unsigned int neuron = 0; neuron < network->neuron_count[layer]; neuron++) {
            current_neuron = &network->layers[layer][neuron];
            for (unsigned int input = 0; input < current_neuron->input_count; input++) {
                synapse = current_neuron->inputs[input];
                change = synapse->input->output * deltas[neuron];
                synapse_change(synapse, change);
            }
        }
        free(deltas);
    }
}

variable_types: struct TD { float **input; float **output; unsigned int data_count; unsigned int input_count; unsigned int output_count; } *

variable_types: struct Neuron { float bias; float input; float output; struct Synapse { struct Neuron *input; struct Neuron *output; float weight; float change; float momentum; float learn_rate; } **inputs; struct Synapse **outputs; unsigned int input_count; unsigned int output_count; float (*sigmoid_function)(float); float (*dsigmoid_function)(float); } *

variable_types:
test
unsigned int

user_defined_types: struct Neuron { float bias; float input; float output; struct Synapse **inputs; struct Synapse **outputs; unsigned int input_count; unsigned int output_count; float (*sigmoid_function)(float); float (*dsigmoid_function)(float); }


decompiled_code:
float __fastcall nn_train(__int64 a1, __int64 a2)
{
float v3; // [rsp+Ch] [rbp-1Ch]

v3 = COERCE_FLOAT(nn_error_factor(a1, a2));
backpropagate_output(a1, a2);
return COERCE_FLOAT(nn_error_factor(a1, a2)) - v3;
}

canonical_decompiled_code:
float __fastcall func2(__int64 a1, __int64 a2)
{
float v3; // [rsp+Ch] [rbp-1Ch]

v3 = COERCE_FLOAT(nn_error_factor(a1, a2));
func1(a1, a2);
return COERCE_FLOAT(nn_error_factor(a1, a2)) - v3;
}

original_code:
float nn_train(NN *network, TD *train_data) {
    ;
    ;
    ;
    ;
    ;
    float error = nn_error_factor(network, train_data);
    backpropagate_output(network, train_data);
    return nn_error_factor(network, train_data) - error;
}

canonical_original_code:
float nn_train(struct NN *network, struct TD *train_data) {
    ;
    ;
    ;
    ;
    ;
    float error = nn_error_factor(network, train_data);
    backpropagate_output(network, train_data);
    return nn_error_factor(network, train_data) - error;
}

return_type: float

user_defined_types: struct TD { float **input; float **output; unsigned int data_count; unsigned int input_count; unsigned int output_count; }

user_defined_types: struct Synapse { struct Neuron *input; struct Neuron *output; float weight; float change; float momentum; float learn_rate; }


decompiled_code:
void __fastcall td_destroy(void *ptr)
{
int v2; // edx
void **v3; // rdi
unsigned int v4; // ebx
__int64 v5; // r12
int v6; // eax
void **v7; // rdi
unsigned int v8; // ebx
__int64 v9; // r12

v2 = *((_DWORD *)ptr + 5);
v3 = *(void ***)ptr;
if ( v2 )
{
v4 = 0;
do
{
v5 = v4++;
free(v3[v5]);
v3 = *(void ***)ptr;
*(_QWORD *)(*(_QWORD *)ptr + 8 * v5) = 0LL;
}
while ( *((_DWORD *)ptr + 5) > v4 );
}
free(v3);
v6 = *((_DWORD *)ptr + 6);
v7 = (void **)*((_QWORD *)ptr + 1);
*(_QWORD *)ptr = 0LL;
if ( v6 )
{
v8 = 0;
do
{
v9 = v8++;
free(v7[v9]);
v7 = (void **)*((_QWORD *)ptr + 1);
v7[v9] = 0LL;
}
while ( *((_DWORD *)ptr + 6) > v8 );
}
free(v7);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
int v2; // edx
void **v3; // rdi
unsigned int v4; // ebx
__int64 v5; // r12
int v6; // eax
void **v7; // rdi
unsigned int v8; // ebx
__int64 v9; // r12

v2 = *((_DWORD *)ptr + 5);
v3 = *(void ***)ptr;
if ( v2 )
{
v4 = 0;
do
{
v5 = v4++;
free(v3[v5]);
v3 = *(void ***)ptr;
*(_QWORD *)(*(_QWORD *)ptr + 8 * v5) = 0LL;
}
while ( *((_DWORD *)ptr + 5) > v4 );
}
free(v3);
v6 = *((_DWORD *)ptr + 6);
v7 = (void **)*((_QWORD *)ptr + 1);
*(_QWORD *)ptr = 0LL;
if ( v6 )
{
v8 = 0;
do
{
v9 = v8++;
free(v7[v9]);
v7 = (void **)*((_QWORD *)ptr + 1);
v7[v9] = 0LL;
}
while ( *((_DWORD *)ptr + 6) > v8 );
}
free(v7);
free(ptr);
}

original_code:
void td_destroy(TD *data) {
    ;
    unsigned int i;
    for (i = 0; i < data->input_count; i++) {
        free(data->input[i]);
        data->input[i] = ((void *)0);
    }
    free(data->input);
    data->input = ((void *)0);
    for (i = 0; i < data->output_count; i++) {
        free(data->output[i]);
        data->output[i] = ((void *)0);
    }
    free(data->output);
    data->output = ((void *)0);
    free(data);
}

canonical_original_code:
void td_destroy(struct TD *data) {
    ;
    unsigned int i;
    for (i = 0; i < data->input_count; i++) {
        free(data->input[i]);
        data->input[i] = ((void *)0);
    }
    free(data->input);
    data->input = ((void *)0);
    for (i = 0; i < data->output_count; i++) {
        free(data->output[i]);
        data->output[i] = ((void *)0);
    }
    free(data->output);
    data->output = ((void *)0);
    free(data);
}

variable_types:
i
unsigned int