decompiled_code:
char **__fastcall main_define(char *a1, char *a2)
{
char **result; // rax

result = function_define("main", "([Ljava/lang/String;)V", a1, a2);
*(_DWORD *)a2 = 1;
return result;
}

canonical_decompiled_code:
char **__fastcall func6(char *a1, char *a2)
{
char **result; // rax

result = func3("main", "([Ljava/lang/String;)V", a1, a2);
*(_DWORD *)a2 = 1;
return result;
}

original_code:
void main_define(char *parameter, Statement *statement){
    function_define("main", "([Ljava/lang/String;)V", parameter, statement);
    statement->type = MAIN_STATEMENT;
}

canonical_original_code:
void main_define(char *parameter, struct Statement *statement){
    function_define("main", "([Ljava/lang/String;)V", parameter, statement);
    statement->type = MAIN_STATEMENT;
}


repo: demmys/desk

decompiled_code:
__int64 get_current_classfile()
{
return static_current_classfile;
}

canonical_decompiled_code:
__int64 func0()
{
return static_current_classfile;
}

canonical_original_code:
struct ClassFile *get_current_classfile(){
    return static_current_classfile;
}

return_type: struct ClassFile { unsigned int magic; unsigned short minor_version; unsigned short major_version; unsigned short constant_pool_count; struct ConstantInfo_tag { enum ConstantInfoTag { CONSTANT_Utf8=1, CONSTANT_Integer=3, CONSTANT_Float=4, CONSTANT_Long=5, CONSTANT_Double=6, CONSTANT_Class=7, CONSTANT_String=8, CONSTANT_Fieldref=9, CONSTANT_Methodref=10, CONSTANT_InterfaceMethodref=11, CONSTANT_NameAndType=12 } tag; union { unsigned short cp_index; struct ReferenceInfo { unsigned short class_index; unsigned short name_and_type_index; } reference_info; unsigned int bytes; struct LongBytes { unsigned int high_bytes; unsigned int low_bytes; } long_bytes; struct NameAndTypeInfo { unsigned short name_index; unsigned short descriptor_index; } name_and_type_info; struct Utf8Info { unsigned short length; char *value; } utf8_info; } u; struct ConstantInfo_tag *prev; struct ConstantInfo_tag *next; } *constant_pool; unsigned short access_flags; unsigned short this_class_index; unsigned short super_class_index; unsigned short interfaces_count; struct Definition_tag { unsigned short access_flags; unsigned short name_index; unsigned short descriptor_index; unsigned short attributes_count; struct AttributeInfo_tag { enum AttributeTag { ATTRIBUTE_ConstantValue=1, ATTRIBUTE_Code=2, ATTRIBUTE_Exceptions=3, ATTRIBUTE_InnerClasses=4, ATTRIBUTE_Synthetic=5, ATTRIBUTE_SourceFile=6, ATTRIBUTE_LineNumberTable=7, ATTRIBUTE_LocalVariableTable=8, ATTRIBUTE_Deprecated=9 } tag; unsigned short attribute_name_index; unsigned int attribute_length; union { unsigned short cp_index; struct CodeAttribute { unsigned short max_stack; unsigned short max_locals; unsigned int code_length; struct Code_tag { enum CodeTag { CODE_OPERATOR=0, CODE_OPERAND_BYTE=1, CODE_OPERAND_SHORT=2 } tag; union { struct OpcodeInfo { unsigned char byte; char *mnemonic; unsigned char operand_count; char *operands_type; unsigned short max_stack; unsigned short max_locals; } *opcode; unsigned char operand_byte; unsigned short operand_short; } u; struct Code_tag *prev; struct Code_tag *next; } *code; unsigned short exception_table_length; struct Exception_tag { unsigned short start_pc; unsigned short end_pc; unsigned short handler_pc; unsigned short catch_type; struct Exception_tag *prev; struct Exception_tag *next; } *exception_table; unsigned short attributes_count; struct AttributeInfo_tag *attributes; unsigned short this_class_index; char *parameter_name; } code_attribute; struct ExceptionsAttribute { unsigned short number_of_exceptions; struct ExceptionIndex_tag { unsigned short exception_index; struct ExceptionIndex_tag *prev; struct ExceptionIndex_tag *next; } *exception_index_table; } exceptions_attribute; struct InnerClassesAttribute { unsigned short number_of_classes; struct InnerClass_tag { unsigned short inner_class_info_index; unsigned short outer_class_info_index; unsigned short inner_name_index; unsigned short inner_class_access_flags; } *classes; } inner_classes_attribute; unsigned char dummy; struct LineNumberTableAttribute { unsigned short line_number_table_length; struct LineNumber_tag { unsigned short start_pc; unsigned short line_number; struct LineNumber_tag *prev; struct LineNumber_tag *next; } *line_number_table; } line_number_table_attribute; struct LocalVariableTableAttribute { unsigned short local_variable_table_length; struct LocalVariable_tag { unsigned short start_pc; unsigned short length; unsigned short name_index; unsigned short descriptor_index; unsigned short index; struct LocalVariable_tag *prev; struct LocalVariable_tag *next; } *local_variable_table; } local_variable_table_attribute; } u; struct AttributeInfo_tag *prev; struct AttributeInfo_tag *next; } *attributes; struct Definition_tag *prev; struct Definition_tag *next; } *interfaces; unsigned short fields_count; struct Definition_tag *fields; unsigned short methods_count; struct Definition_tag *methods; unsigned short attributes_count; struct AttributeInfo_tag *source_file; char *emit_file; struct Storage { struct MemoryPage_tag { int cell_num; int use_cell_num; struct MemoryPage_tag *next; union Cell { long l_dummy; double d_dummy; void *p_dummy; } cell[1]; } *page_list; int current_page_size; } *classfile_storage; } *

user_defined_types: struct ClassFile { unsigned int magic; unsigned short minor_version; unsigned short major_version; unsigned short constant_pool_count; struct ConstantInfo_tag *constant_pool; unsigned short access_flags; unsigned short this_class_index; unsigned short super_class_index; unsigned short interfaces_count; struct Definition_tag *interfaces; unsigned short fields_count; struct Definition_tag *fields; unsigned short methods_count; struct Definition_tag *methods; unsigned short attributes_count; struct AttributeInfo_tag *source_file; char *emit_file; struct Storage *classfile_storage; }

user_defined_types: struct ConstantInfo_tag { enum ConstantInfoTag tag; union { unsigned short cp_index; struct ReferenceInfo reference_info; unsigned int bytes; struct LongBytes long_bytes; struct NameAndTypeInfo name_and_type_info; struct Utf8Info utf8_info; } u; struct ConstantInfo_tag *prev; struct ConstantInfo_tag *next; }

user_defined_types: struct Definition_tag { unsigned short access_flags; unsigned short name_index; unsigned short descriptor_index; unsigned short attributes_count; struct AttributeInfo_tag *attributes; struct Definition_tag *prev; struct Definition_tag *next; }

user_defined_types: struct Storage { struct MemoryPage_tag *page_list; int current_page_size; }

user_defined_types: struct AttributeInfo_tag { enum AttributeTag tag; unsigned short attribute_name_index; unsigned int attribute_length; union { unsigned short cp_index; struct CodeAttribute code_attribute; struct ExceptionsAttribute exceptions_attribute; struct InnerClassesAttribute inner_classes_attribute; unsigned char dummy; struct LineNumberTableAttribute line_number_table_attribute; struct LocalVariableTableAttribute local_variable_table_attribute; } u; struct AttributeInfo_tag *prev; struct AttributeInfo_tag *next; }

user_defined_types: struct MemoryPage_tag { int cell_num; int use_cell_num; struct MemoryPage_tag *next; union Cell cell[1]; }

user_defined_types: struct CodeAttribute { unsigned short max_stack; unsigned short max_locals; unsigned int code_length; struct Code_tag *code; unsigned short exception_table_length; struct Exception_tag *exception_table; unsigned short attributes_count; struct AttributeInfo_tag *attributes; unsigned short this_class_index; char *parameter_name; }

user_defined_types: struct ExceptionsAttribute { unsigned short number_of_exceptions; struct ExceptionIndex_tag *exception_index_table; }

user_defined_types: struct InnerClassesAttribute { unsigned short number_of_classes; struct InnerClass_tag *classes; }

user_defined_types: struct LineNumberTableAttribute { unsigned short line_number_table_length; struct LineNumber_tag *line_number_table; }

user_defined_types: struct LocalVariableTableAttribute { unsigned short local_variable_table_length; struct LocalVariable_tag *local_variable_table; }

user_defined_types: struct Code_tag { enum CodeTag tag; union { struct OpcodeInfo *opcode; unsigned char operand_byte; unsigned short operand_short; } u; struct Code_tag *prev; struct Code_tag *next; }


decompiled_code:
__int64 __fastcall classfile_storage_malloc(__int64 a1)
{
return storage_malloc(*(_QWORD *)(static_current_classfile + 96), a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return storage_malloc(*(_QWORD *)(static_current_classfile + 96), a1);
}

original_code:
void *classfile_storage_malloc(size_t size){
    void *p;
    p = storage_malloc(static_current_classfile->classfile_storage, size);
    return p;
}

canonical_original_code:
void *classfile_storage_malloc(unsigned long size){
    void *p;
    p = storage_malloc(static_current_classfile->classfile_storage, size);
    return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 create_class_file()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = open_storage(0LL);
result = storage_malloc(v0, 104LL);
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)result = 0x320000CAFEBABELL;
*(_WORD *)(result + 8) = 0;
*(_QWORD *)(result + 24) = 33LL;
*(_WORD *)(result + 40) = 0;
*(_WORD *)(result + 56) = 0;
*(_QWORD *)(result + 64) = 0LL;
*(_WORD *)(result + 72) = 0;
*(_QWORD *)(result + 80) = 0LL;
*(_QWORD *)(result + 88) = 0LL;
*(_QWORD *)(result + 96) = v0;
static_current_classfile = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = open_storage(0LL);
result = storage_malloc(v0, 104LL);
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)result = 0x320000CAFEBABELL;
*(_WORD *)(result + 8) = 0;
*(_QWORD *)(result + 24) = 33LL;
*(_WORD *)(result + 40) = 0;
*(_WORD *)(result + 56) = 0;
*(_QWORD *)(result + 64) = 0LL;
*(_WORD *)(result + 72) = 0;
*(_QWORD *)(result + 80) = 0LL;
*(_QWORD *)(result + 88) = 0LL;
*(_QWORD *)(result + 96) = v0;
static_current_classfile = result;
return result;
}

original_code:
ClassFile *create_class_file(){
    Storage *storage;
    ClassFile *cf;
    storage = open_storage(0);
    cf = storage_malloc(storage, sizeof(ClassFile));
    cf->magic = 0xcafebabe;
    cf->minor_version = 0;
    cf->major_version = 50;
    cf ->constant_pool_count = 0;
    cf->constant_pool = ((void *)0);
    cf->access_flags = ACC_SUPER | ACC_PUBLIC;
    cf->this_class_index = 0;
    cf->super_class_index = 0;
    cf->interfaces_count = 0;
    cf->fields_count= 0;
    cf->methods_count = 0;
    cf->methods = ((void *)0);
    cf->attributes_count = 0;
    cf->source_file = ((void *)0);
    cf->emit_file = ((void *)0);
    cf->classfile_storage = storage;
    static_current_classfile = cf;
    return cf;
}

canonical_original_code:
struct ClassFile *create_class_file(){
    struct Storage *storage;
    struct ClassFile *cf;
    storage = open_storage(0);
    cf = storage_malloc(storage, sizeof(ClassFile));
    cf->magic = 0xcafebabe;
    cf->minor_version = 0;
    cf->major_version = 50;
    cf ->constant_pool_count = 0;
    cf->constant_pool = ((void *)0);
    cf->access_flags = ACC_SUPER | ACC_PUBLIC;
    cf->this_class_index = 0;
    cf->super_class_index = 0;
    cf->interfaces_count = 0;
    cf->fields_count= 0;
    cf->methods_count = 0;
    cf->methods = ((void *)0);
    cf->attributes_count = 0;
    cf->source_file = ((void *)0);
    cf->emit_file = ((void *)0);
    cf->classfile_storage = storage;
    static_current_classfile = cf;
    return cf;
}

variable_types: struct ClassFile { unsigned int magic; unsigned short minor_version; unsigned short major_version; unsigned short constant_pool_count; struct ConstantInfo_tag { enum ConstantInfoTag { CONSTANT_Utf8=1, CONSTANT_Integer=3, CONSTANT_Float=4, CONSTANT_Long=5, CONSTANT_Double=6, CONSTANT_Class=7, CONSTANT_String=8, CONSTANT_Fieldref=9, CONSTANT_Methodref=10, CONSTANT_InterfaceMethodref=11, CONSTANT_NameAndType=12 } tag; union { unsigned short cp_index; struct ReferenceInfo { unsigned short class_index; unsigned short name_and_type_index; } reference_info; unsigned int bytes; struct LongBytes { unsigned int high_bytes; unsigned int low_bytes; } long_bytes; struct NameAndTypeInfo { unsigned short name_index; unsigned short descriptor_index; } name_and_type_info; struct Utf8Info { unsigned short length; char *value; } utf8_info; } u; struct ConstantInfo_tag *prev; struct ConstantInfo_tag *next; } *constant_pool; unsigned short access_flags; unsigned short this_class_index; unsigned short super_class_index; unsigned short interfaces_count; struct Definition_tag { unsigned short access_flags; unsigned short name_index; unsigned short descriptor_index; unsigned short attributes_count; struct AttributeInfo_tag { enum AttributeTag { ATTRIBUTE_ConstantValue=1, ATTRIBUTE_Code=2, ATTRIBUTE_Exceptions=3, ATTRIBUTE_InnerClasses=4, ATTRIBUTE_Synthetic=5, ATTRIBUTE_SourceFile=6, ATTRIBUTE_LineNumberTable=7, ATTRIBUTE_LocalVariableTable=8, ATTRIBUTE_Deprecated=9 } tag; unsigned short attribute_name_index; unsigned int attribute_length; union { unsigned short cp_index; struct CodeAttribute { unsigned short max_stack; unsigned short max_locals; unsigned int code_length; struct Code_tag { enum CodeTag { CODE_OPERATOR=0, CODE_OPERAND_BYTE=1, CODE_OPERAND_SHORT=2 } tag; union { struct OpcodeInfo { unsigned char byte; char *mnemonic; unsigned char operand_count; char *operands_type; unsigned short max_stack; unsigned short max_locals; } *opcode; unsigned char operand_byte; unsigned short operand_short; } u; struct Code_tag *prev; struct Code_tag *next; } *code; unsigned short exception_table_length; struct Exception_tag { unsigned short start_pc; unsigned short end_pc; unsigned short handler_pc; unsigned short catch_type; struct Exception_tag *prev; struct Exception_tag *next; } *exception_table; unsigned short attributes_count; struct AttributeInfo_tag *attributes; unsigned short this_class_index; char *parameter_name; } code_attribute; struct ExceptionsAttribute { unsigned short number_of_exceptions; struct ExceptionIndex_tag { unsigned short exception_index; struct ExceptionIndex_tag *prev; struct ExceptionIndex_tag *next; } *exception_index_table; } exceptions_attribute; struct InnerClassesAttribute { unsigned short number_of_classes; struct InnerClass_tag { unsigned short inner_class_info_index; unsigned short outer_class_info_index; unsigned short inner_name_index; unsigned short inner_class_access_flags; } *classes; } inner_classes_attribute; unsigned char dummy; struct LineNumberTableAttribute { unsigned short line_number_table_length; struct LineNumber_tag { unsigned short start_pc; unsigned short line_number; struct LineNumber_tag *prev; struct LineNumber_tag *next; } *line_number_table; } line_number_table_attribute; struct LocalVariableTableAttribute { unsigned short local_variable_table_length; struct LocalVariable_tag { unsigned short start_pc; unsigned short length; unsigned short name_index; unsigned short descriptor_index; unsigned short index; struct LocalVariable_tag *prev; struct LocalVariable_tag *next; } *local_variable_table; } local_variable_table_attribute; } u; struct AttributeInfo_tag *prev; struct AttributeInfo_tag *next; } *attributes; struct Definition_tag *prev; struct Definition_tag *next; } *interfaces; unsigned short fields_count; struct Definition_tag *fields; unsigned short methods_count; struct Definition_tag *methods; unsigned short attributes_count; struct AttributeInfo_tag *source_file; char *emit_file; struct Storage { struct MemoryPage_tag { int cell_num; int use_cell_num; struct MemoryPage_tag *next; union Cell { long l_dummy; double d_dummy; void *p_dummy; } cell[1]; } *page_list; int current_page_size; } *classfile_storage; } *


decompiled_code:
__int64 __fastcall dispose_classfile(__int64 a1)
{
return dispose_storage(*(_QWORD *)(a1 + 96));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return dispose_storage(*(_QWORD *)(a1 + 96));
}

original_code:
void dispose_classfile(ClassFile *cf){
    dispose_storage(cf->classfile_storage);
}

canonical_original_code:
void dispose_classfile(struct ClassFile *cf){
    dispose_storage(cf->classfile_storage);
}

return_type: void

user_defined_types: enum ConstantInfoTag { CONSTANT_Utf8=1, CONSTANT_Integer=3, CONSTANT_Float=4, CONSTANT_Long=5, CONSTANT_Double=6, CONSTANT_Class=7, CONSTANT_String=8, CONSTANT_Fieldref=9, CONSTANT_Methodref=10, CONSTANT_InterfaceMethodref=11, CONSTANT_NameAndType=12 }

user_defined_types: struct ReferenceInfo { unsigned short class_index; unsigned short name_and_type_index; }

user_defined_types: struct LongBytes { unsigned int high_bytes; unsigned int low_bytes; }

user_defined_types: struct NameAndTypeInfo { unsigned short name_index; unsigned short descriptor_index; }

user_defined_types: struct Utf8Info { unsigned short length; char *value; }

user_defined_types: enum AttributeTag { ATTRIBUTE_ConstantValue=1, ATTRIBUTE_Code=2, ATTRIBUTE_Exceptions=3, ATTRIBUTE_InnerClasses=4, ATTRIBUTE_Synthetic=5, ATTRIBUTE_SourceFile=6, ATTRIBUTE_LineNumberTable=7, ATTRIBUTE_LocalVariableTable=8, ATTRIBUTE_Deprecated=9 }

user_defined_types: union Cell { long l_dummy; double d_dummy; void *p_dummy; }

user_defined_types: struct Exception_tag { unsigned short start_pc; unsigned short end_pc; unsigned short handler_pc; unsigned short catch_type; struct Exception_tag *prev; struct Exception_tag *next; }

user_defined_types: struct ExceptionIndex_tag { unsigned short exception_index; struct ExceptionIndex_tag *prev; struct ExceptionIndex_tag *next; }

user_defined_types: struct InnerClass_tag { unsigned short inner_class_info_index; unsigned short outer_class_info_index; unsigned short inner_name_index; unsigned short inner_class_access_flags; }

user_defined_types: struct LineNumber_tag { unsigned short start_pc; unsigned short line_number; struct LineNumber_tag *prev; struct LineNumber_tag *next; }

user_defined_types: struct LocalVariable_tag { unsigned short start_pc; unsigned short length; unsigned short name_index; unsigned short descriptor_index; unsigned short index; struct LocalVariable_tag *prev; struct LocalVariable_tag *next; }

user_defined_types: enum CodeTag { CODE_OPERATOR=0, CODE_OPERAND_BYTE=1, CODE_OPERAND_SHORT=2 }

user_defined_types: struct OpcodeInfo { unsigned char byte; char *mnemonic; unsigned char operand_count; char *operands_type; unsigned short max_stack; unsigned short max_locals; }


decompiled_code:
void __noreturn compile_error(int a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, (&compile_error_format)[a1], arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(int a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, (&compile_error_format)[a1], arg);
exit(1);
}

original_code:
void compile_error(CompileErrorType type, ...){
    va_list args;
    __builtin_va_start(args,type);
    vfprintf(stderr, compile_error_format[type], args);
    exit(1);
    __builtin_va_end(args);
}

canonical_original_code:
void compile_error(enum CompileErrorType type, ...){
    __builtin_va_list args;
    __builtin_va_start(args,type);
    vfprintf(stderr, compile_error_format[type], args);
    exit(1);
    __builtin_va_end(args);
}

variable_types: enum CompileErrorType { ERROR_NO_INPUT_FILES=1, ERROR_NO_SUCH_FILE=2, ERROR_UNSUPPORTED_FILE_NAME=3, ERROR_UNSUPPORTED_FILE_EXTENSION=4, ERROR_PARSE=5, ERROR_FUNCTION_ALREADY_DEFINED=6, ERROR_FUNCTION_NOT_DEFINED=7, ERROR_FUNCTION_PATTERN_ALREADY_DEFINED=8, ERROR_NOT_DEFINED_LOCAL_VALIABLE=9, ERROR_FUNCTION_WITH_ARG_NOT_DEFINED=10 }


decompiled_code:
void __noreturn system_error(int a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, system_error_format[a1], arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(int a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, system_error_format[a1], arg);
exit(1);
}

original_code:
void system_error(SystemErrorType type, ...){
    va_list args;
    __builtin_va_start(args,type);
    vfprintf(stderr, system_error_format[type], args);
    exit(1);
    __builtin_va_end(args);
}

canonical_original_code:
void system_error(enum SystemErrorType type, ...){
    __builtin_va_list args;
    __builtin_va_start(args,type);
    vfprintf(stderr, system_error_format[type], args);
    exit(1);
    __builtin_va_end(args);
}

variable_types: enum SystemErrorType { ERROR_INVALID_CP_INDEX=1, ERROR_UNKNOWN_CONSTANT_TAG=2 }


original_code:
void *storage_malloc(Storage *storage, size_t size){
    int cell_num, alloc_cell_num;
    MemoryPage *new_page;
    void *p;
    cell_num = ((size - 1) / sizeof(Cell)) + 1;
    if(storage->page_list && (storage->page_list->use_cell_num + cell_num) < storage->page_list->cell_num){
        p = &(storage->page_list->cell[storage->page_list->use_cell_num]);
        storage->page_list->use_cell_num += cell_num;
    } else{
        alloc_cell_num = (((cell_num) > (storage->current_page_size)) ? (cell_num) : (storage->current_page_size));
        new_page = malloc(sizeof(MemoryPage) + sizeof(Cell) * (alloc_cell_num - 1));
        new_page->next = storage->page_list;
        new_page->cell_num = alloc_cell_num;
        storage->page_list = new_page;
        p = &(new_page->cell[0]);
        new_page->use_cell_num = cell_num;
    }
    return p;
}

canonical_original_code:
void *storage_malloc(struct Storage *storage, unsigned long size){
    int cell_num; int alloc_cell_num;
    struct MemoryPage_tag *new_page;
    void *p;
    cell_num = ((size - 1) / sizeof(Cell)) + 1;
    if(storage->page_list && (storage->page_list->use_cell_num + cell_num) < storage->page_list->cell_num){
        p = &(storage->page_list->cell[storage->page_list->use_cell_num]);
        storage->page_list->use_cell_num += cell_num;
    } else{
        alloc_cell_num = (((cell_num) > (storage->current_page_size)) ? (cell_num) : (storage->current_page_size));
        new_page = malloc(sizeof(MemoryPage) + sizeof(Cell) * (alloc_cell_num - 1));
        new_page->next = storage->page_list;
        new_page->cell_num = alloc_cell_num;
        storage->page_list = new_page;
        p = &(new_page->cell[0]);
        new_page->use_cell_num = cell_num;
    }
    return p;
}

variable_types: struct Storage { struct MemoryPage_tag { int cell_num; int use_cell_num; struct MemoryPage_tag *next; union Cell { long l_dummy; double d_dummy; void *p_dummy; } cell[1]; } *page_list; int current_page_size; } *

user_defined_types: struct Storage { struct MemoryPage_tag *page_list; int current_page_size; }

user_defined_types: struct MemoryPage_tag { int cell_num; int use_cell_num; struct MemoryPage_tag *next; union Cell cell[1]; }


decompiled_code:
void __fastcall dispose_storage(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
*(_QWORD *)ptr = v2;
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
*(_QWORD *)ptr = v2;
}
while ( v2 );
}
free(ptr);
}

original_code:
void dispose_storage(Storage *storage){
    MemoryPage *temp;
    while(storage->page_list){
        temp = storage->page_list->next;
        free(storage->page_list);
        storage->page_list = temp;
    }
    free(storage);
}

canonical_original_code:
void dispose_storage(struct Storage *storage){
    struct MemoryPage_tag *temp;
    while(storage->page_list){
        temp = storage->page_list->next;
        free(storage->page_list);
        storage->page_list = temp;
    }
    free(storage);
}

variable_types: struct MemoryPage_tag { int cell_num; int use_cell_num; struct MemoryPage_tag *next; union Cell { long l_dummy; double d_dummy; void *p_dummy; } cell[1]; } *


main

canonical_name: main

repo: demonicblue/netdriver

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // r12
char *v5; // rbx
int v6; // eax
int v7; // ebp
int v8; // ebp
int v9; // er12
size_t v10; // r14
__int64 v11; // r13
unsigned int v12; // eax
void *v13; // r15
__int64 v14; // rbx
__m128i *v16; // r15
int *v17; // rax
char *v18; // rax
int fds[2]; // [rsp+18h] [rbp-70h] BYREF
__m128i v20; // [rsp+20h] [rbp-68h] BYREF
int buf[2]; // [rsp+30h] [rbp-58h] BYREF
__int64 v22; // [rsp+38h] [rbp-50h]
__int64 v23; // [rsp+40h] [rbp-48h]
unsigned int v24; // [rsp+48h] [rbp-40h]

v3 = (char *)malloc(0x3200000uLL);
v4 = argv[1];
v5 = v3;
socketpair(1, 1, 0, fds);
v6 = open(v4, 2);
if ( v6 == -1 )
err(1, "Cannot open %s", v4);
v7 = v6;
ioctl(v6, 0xAB02uLL, 52428800LL);
ioctl(v7, 0xAB04uLL);
if ( !fork() )
{
close(fds[0]);
if ( ioctl(v7, 0xAB00uLL, (unsigned int)fds[1]) != -1 )
{
v14 = (unsigned int)ioctl(v7, 0xAB03uLL);
fprintf(_bss_start, "nbd device terminated with code %d", v14);
if ( (_DWORD)v14 == -1 )
{
v17 = __errno_location();
v18 = strerror(*v17);
fprintf(_bss_start, "%s\n", v18);
}
ioctl(v7, 0xAB05uLL);
ioctl(v7, 0xAB04uLL);
exit(0);
}
err(1, "Cannot set client socket");
}
close(fds[1]);
v8 = fds[0];
v20.m128i_i32[0] = _bswap_32(1732535960LL);
v20.m128i_i32[1] = _bswap_32(0LL);
v9 = _bswap_32(627086611LL);
while ( 1 )
{
read(v8, buf, 0x1CuLL);
v20.m128i_i64[1] = v22;
v10 = (unsigned int)_bswap_32(v24);
v11 = ntohll(v23);
if ( buf[0] != v9 )
err(1, "Data integrity check failed");
v12 = _bswap_32((unsigned int)buf[1]);
if ( v12 == 2 )
break;
if ( v12 > 2 )
{
if ( v12 - 3 > 1 )
err(1, "Unexpected NBD command: %d", v12);
}
else if ( v12 )
{
v13 = malloc(v10);
read_all_isra_0(v8, v13, v10);
memcpy(&v5[v11], v13, v10);
free(v13);
write_all_isra_0(v8, &v20, 0x10uLL);
}
else
{
v16 = (__m128i *)malloc(v10 + 16);
memcpy(&v16[1], &v5[v11], v10);
*v16 = _mm_loadu_si128(&v20);
write_all_isra_0(v8, v16, v10 + 16);
free(v16);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // r12
char *v5; // rbx
int v6; // eax
int v7; // ebp
int v8; // ebp
int v9; // er12
size_t v10; // r14
__int64 v11; // r13
unsigned int v12; // eax
void *v13; // r15
__int64 v14; // rbx
__m128i *v16; // r15
int *v17; // rax
char *v18; // rax
int fds[2]; // [rsp+18h] [rbp-70h] BYREF
__m128i v20; // [rsp+20h] [rbp-68h] BYREF
int buf[2]; // [rsp+30h] [rbp-58h] BYREF
__int64 v22; // [rsp+38h] [rbp-50h]
__int64 v23; // [rsp+40h] [rbp-48h]
unsigned int v24; // [rsp+48h] [rbp-40h]

v3 = (char *)malloc(0x3200000uLL);
v4 = argv[1];
v5 = v3;
socketpair(1, 1, 0, fds);
v6 = open(v4, 2);
if ( v6 == -1 )
err(1, "Cannot open %s", v4);
v7 = v6;
ioctl(v6, 0xAB02uLL, 52428800LL);
ioctl(v7, 0xAB04uLL);
if ( !fork() )
{
close(fds[0]);
if ( ioctl(v7, 0xAB00uLL, (unsigned int)fds[1]) != -1 )
{
v14 = (unsigned int)ioctl(v7, 0xAB03uLL);
fprintf(_bss_start, "nbd device terminated with code %d", v14);
if ( (_DWORD)v14 == -1 )
{
v17 = __errno_location();
v18 = strerror(*v17);
fprintf(_bss_start, "%s\n", v18);
}
ioctl(v7, 0xAB05uLL);
ioctl(v7, 0xAB04uLL);
exit(0);
}
err(1, "Cannot set client socket");
}
close(fds[1]);
v8 = fds[0];
v20.m128i_i32[0] = func7(1732535960LL);
v20.m128i_i32[1] = func7(0LL);
v9 = func7(627086611LL);
while ( 1 )
{
read(v8, buf, 0x1CuLL);
v20.m128i_i64[1] = v22;
v10 = (unsigned int)func7(v24);
v11 = func10(v23);
if ( buf[0] != v9 )
err(1, "Data integrity check failed");
v12 = func7((unsigned int)buf[1]);
if ( v12 == 2 )
break;
if ( v12 > 2 )
{
if ( v12 - 3 > 1 )
err(1, "Unexpected NBD command: %d", v12);
}
else if ( v12 )
{
v13 = malloc(v10);
func8(v8, v13, v10);
memcpy(&v5[v11], v13, v10);
free(v13);
func9(v8, &v20, 0x10uLL);
}
else
{
v16 = (__m128i *)malloc(v10 + 16);
memcpy(&v16[1], &v5[v11], v10);
*v16 = _mm_loadu_si128(&v20);
func9(v8, v16, v10 + 16);
free(v16);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  int nbd_fd, socket_fd;
  char *dev_path;
  int fd[2];
  struct nbd_request request;
  struct nbd_reply reply;
  void *data, *chunk;
  uint32_t len, bytes_read;
  uint64_t offset;
  data = malloc(1024*1024*50);
  dev_path = argv[1];
  socketpair(1, SOCK_STREAM, 0, fd);
  nbd_fd = open(dev_path, 02);
  if(nbd_fd == -1) {
    err(1, "Cannot open %s", dev_path);
  }
  ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((2)) << 0) | ((0) << ((0 +8)+8))), 1024*1024*50);
  ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((4)) << 0) | ((0) << ((0 +8)+8))));
  if(!fork()) {
    close(fd[0]);
    socket_fd = fd[1];
    if(ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((0)) << 0) | ((0) << ((0 +8)+8))), socket_fd) == -1) {
      err(1, "Cannot set client socket");
    }
    int err = ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((3)) << 0) | ((0) << ((0 +8)+8))));
    fprintf(stderr, "nbd device terminated with code %d", err);
    if(err == -1) {
      fprintf(stderr, "%s\n", strerror((*__errno_location ())));
    }
    ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((5)) << 0) | ((0) << ((0 +8)+8))));
    ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((4)) << 0) | ((0) << ((0 +8)+8))));
    exit(0);
  }
  close(fd[1]);
  socket_fd = fd[0];
  reply.magic = htonl(0x67446698);
  reply.error = htonl(0);
  while(1) {
    bytes_read = read(socket_fd, &request, sizeof(request));
    memcpy(reply.handle, request.handle, sizeof(request.handle));
    len = ntohl(request.len);
    offset = ntohll(request.from);
    if( request.magic != htonl(0x25609513)) {
      err(1, "Data integrity check failed");
    }
    switch(ntohl(request.type)) {
      case NBD_CMD_READ:
        chunk = malloc(len + sizeof(struct nbd_reply));
        memcpy(chunk+sizeof(struct nbd_reply), (char *)data + offset, len);
        memcpy(chunk, &reply, sizeof(struct nbd_reply));
        write_all(socket_fd, chunk, len + sizeof(struct nbd_reply));
        free(chunk);
        break;
      case NBD_CMD_WRITE:
        chunk = malloc(len);
        read_all(socket_fd, chunk, len);
        memcpy((char *)data + offset, chunk, len);
        free(chunk);
        write_all(socket_fd, &reply, sizeof(struct nbd_reply));
        break;
      case NBD_CMD_DISC:
        return 0;
      case NBD_CMD_FLUSH:
        break;
      case NBD_CMD_TRIM:
        break;
      default:
        err(1, "Unexpected NBD command: %d", ntohl(request.type));
    }
  }
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int nbd_fd; int socket_fd;
  char *dev_path;
  int fd[2];
  struct nbd_request request;
  struct nbd_reply reply;
  void *data; void *chunk;
  unsigned int len; unsigned int bytes_read;
  unsigned long offset;
  data = malloc(1024*1024*50);
  dev_path = argv[1];
  socketpair(1, SOCK_STREAM, 0, fd);
  nbd_fd = open(dev_path, 02);
  if(nbd_fd == -1) {
    err(1, "Cannot open %s", dev_path);
  }
  ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((2)) << 0) | ((0) << ((0 +8)+8))), 1024*1024*50);
  ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((4)) << 0) | ((0) << ((0 +8)+8))));
  if(!fork()) {
    close(fd[0]);
    socket_fd = fd[1];
    if(ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((0)) << 0) | ((0) << ((0 +8)+8))), socket_fd) == -1) {
      err(1, "Cannot set client socket");
    }
    int err = ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((3)) << 0) | ((0) << ((0 +8)+8))));
    fprintf(stderr, "nbd device terminated with code %d", err);
    if(err == -1) {
      fprintf(stderr, "%s\n", strerror((*__errno_location ())));
    }
    ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((5)) << 0) | ((0) << ((0 +8)+8))));
    ioctl(nbd_fd, (((0U) << (((0 +8)+8)+14)) | (((0xab)) << (0 +8)) | (((4)) << 0) | ((0) << ((0 +8)+8))));
    exit(0);
  }
  close(fd[1]);
  socket_fd = fd[0];
  reply.magic = htonl(0x67446698);
  reply.error = htonl(0);
  while(1) {
    bytes_read = read(socket_fd, &request, sizeof(request));
    memcpy(reply.handle, request.handle, sizeof(request.handle));
    len = ntohl(request.len);
    offset = ntohll(request.from);
    if( request.magic != htonl(0x25609513)) {
      err(1, "Data integrity check failed");
    }
    switch(ntohl(request.type)) {
      case NBD_CMD_READ:
        chunk = malloc(len + sizeof(struct nbd_reply));
        memcpy(chunk+sizeof(struct nbd_reply), (char *)data + offset, len);
        memcpy(chunk, &reply, sizeof(struct nbd_reply));
        write_all(socket_fd, chunk, len + sizeof(struct nbd_reply));
        free(chunk);
        break;
      case NBD_CMD_WRITE:
        chunk = malloc(len);
        read_all(socket_fd, chunk, len);
        memcpy((char *)data + offset, chunk, len);
        free(chunk);
        write_all(socket_fd, &reply, sizeof(struct nbd_reply));
        break;
      case NBD_CMD_DISC:
        return 0;
      case NBD_CMD_FLUSH:
        break;
      case NBD_CMD_TRIM:
        break;
      default:
        err(1, "Unexpected NBD command: %d", ntohl(request.type));
    }
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
fd
int [2]

variable_types: struct nbd_request { unsigned int magic; unsigned int type; char handle[8]; unsigned long long from; unsigned int len; }

variable_types: struct nbd_reply { unsigned int magic; unsigned int error; char handle[8]; }

variable_types:
data
void *

variable_types:
chunk
void *

variable_types:
len
unsigned int

variable_types:
offset
unsigned long

variable_types: err int

return_type: int


ntohll

decompiled_code:
unsigned __int64 __fastcall ntohll(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

original_code:
uint64_t ntohll(uint64_t x) {
  return __builtin_bswap64(x);
}

canonical_original_code:
unsigned long ntohll(unsigned long x) {
  return __builtin_bswap64(x);
}

variable_types:
x
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall set_address(__int64 a1, __int16 a2, const char *a3, const char *a4, const char *a5)
{
struct servent *v8; // rax
__int64 result; // rax
struct hostent *v10; // rax
__int16 v11; // [rsp+0h] [rbp-2Ch] BYREF

*(_OWORD *)a1 = 0LL;
*(_WORD *)a1 = a2;
if ( a4 )
{
if ( !inet_aton(a4, (struct in_addr *)(a1 + 4)) )
{
v10 = gethostbyname(a4);
if ( !v10 )
{
fprintf(stderr, asc_258, a4);
return 1LL;
}
*(_DWORD *)(a1 + 4) = **(_DWORD **)v10->h_addr_list;
}
}
else
{
*(_DWORD *)(a1 + 4) = _bswap_32_constprop_0();
}
if ( sscanf(a3, "%d", &v11) == 1 )
{
*(_WORD *)(a1 + 2) = _bswap_16(v11);
result = 0LL;
}
else
{
v8 = getservbyname(a3, a5);
if ( v8 )
{
*(_WORD *)(a1 + 2) = v8->s_port;
result = 0LL;
}
else
{
fprintf(stderr, "Service %s inconnu \n", a3);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int16 a2, const char *a3, const char *a4, const char *a5)
{
struct servent *v8; // rax
__int64 result; // rax
struct hostent *v10; // rax
__int16 v11; // [rsp+0h] [rbp-2Ch] BYREF

*(_OWORD *)a1 = 0LL;
*(_WORD *)a1 = a2;
if ( a4 )
{
if ( !inet_aton(a4, (struct in_addr *)(a1 + 4)) )
{
v10 = gethostbyname(a4);
if ( !v10 )
{
fprintf(stderr, asc_258, a4);
return 1LL;
}
*(_DWORD *)(a1 + 4) = **(_DWORD **)v10->h_addr_list;
}
}
else
{
*(_DWORD *)(a1 + 4) = func1();
}
if ( sscanf(a3, "%d", &v11) == 1 )
{
*(_WORD *)(a1 + 2) = func0(v11);
result = 0LL;
}
else
{
v8 = getservbyname(a3, a5);
if ( v8 )
{
*(_WORD *)(a1 + 2) = v8->s_port;
result = 0LL;
}
else
{
fprintf(stderr, "Service %s inconnu \n", a3);
result = 1LL;
}
}
return result;
}

original_code:
int set_address(struct sockaddr_in * address, unsigned short int type, char* port, char* host, char* protocol)
{
 int num;
 struct hostent * hostent;
 struct servent * servent;
 memset(address, 0, sizeof (struct sockaddr_in));
 address->sin_family = type;
 if(host==((void *)0))
  address->sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 else if (inet_aton(host, & (address->sin_addr)) == 0)
 {
  if ((hostent = gethostbyname(host)) == ((void *)0))
  {
   fprintf(stderr, "hôte %s inconnu \n", host);
   return 1;
  }
  address->sin_addr.s_addr = ((struct in_addr *) (hostent->h_addr_list[0]))->s_addr;
 }
 if (sscanf(port, "%d", &num) == 1) {
  address->sin_port = htons(num);
  return 0;
 }
 if ((servent = getservbyname(port, protocol)) == ((void *)0)) {
  fprintf(stderr, "Service %s inconnu \n", port);
  return 1;
 }
 address->sin_port = servent->s_port;
 return 0;
}

canonical_original_code:
int set_address(struct sockaddr_in *address, unsigned short type, char *port, char *host, char *protocol)
{
 int num;
 struct hostent *hostent;
 struct servent *servent;
 memset(address, 0, sizeof (struct sockaddr_in));
 address->sin_family = type;
 if(host==((void *)0))
  address->sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 else if (inet_aton(host, & (address->sin_addr)) == 0)
 {
  if ((hostent = gethostbyname(host)) == ((void *)0))
  {
   fprintf(stderr, "hôte %s inconnu \n", host);
   return 1;
  }
  address->sin_addr.s_addr = ((struct in_addr *) (hostent->h_addr_list[0]))->s_addr;
 }
 if (sscanf(port, "%d", &num) == 1) {
  address->sin_port = htons(num);
  return 0;
 }
 if ((servent = getservbyname(port, protocol)) == ((void *)0)) {
  fprintf(stderr, "Service %s inconnu \n", port);
  return 1;
 }
 address->sin_port = servent->s_port;
 return 0;
}

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

variable_types:
type
unsigned short

variable_types:
port
char *

variable_types:
host
char *

variable_types:
protocol
char *

variable_types: num int

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

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; } *

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


decompiled_code:
__int64 __fastcall set_udp_address(__int64 a1, const char *a2, const char *a3)
{
return set_address(a1, 2, a2, a3, "udp");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
return func2(a1, 2, a2, a3, "udp");
}

original_code:
int set_udp_address(struct sockaddr_in * address, char* port, char* host)
{
 return set_address(address, 2, port, host, "udp");
}

canonical_original_code:
int set_udp_address(struct sockaddr_in *address, char *port, char *host)
{
 return set_address(address, 2, port, host, "udp");
}


decompiled_code:
__int64 __fastcall set_tcp_address(__int64 a1, const char *a2, const char *a3)
{
return set_address(a1, 2, a2, a3, "tcp");
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, const char *a3)
{
return func2(a1, 2, a2, a3, "tcp");
}

original_code:
int set_tcp_address(struct sockaddr_in * address, char* port, char* host)
{
 return set_address(address, 2, port, host, "tcp");
}

canonical_original_code:
int set_tcp_address(struct sockaddr_in *address, char *port, char *host)
{
 return set_address(address, 2, port, host, "tcp");
}


decompiled_code:
int sock_udp()
{
int result; // eax

result = socket(2, 2, 0);
if ( result < 0 )
{
fwrite("[E] sock_udp : address and port must not be NULL", 1uLL, 0x30uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

result = socket(2, 2, 0);
if ( result < 0 )
{
fwrite("[E] sock_udp : address and port must not be NULL", 1uLL, 0x30uLL, stderr);
exit(1);
}
return result;
}

original_code:
int sock_udp()
{
 int sock;
 if ((sock = socket(2, SOCK_DGRAM, 0)) < 0)
 {
  fprintf(stderr, "[E] sock_udp : address and port must not be NULL");
  exit(1);
 }
 return sock;
}

variable_types: sock int


decompiled_code:
int sock_tcp()
{
int result; // eax

result = socket(2, 1, 0);
if ( result < 0 )
{
fwrite("[E] sock_tcp : address and port must not be NULL", 1uLL, 0x30uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax

result = socket(2, 1, 0);
if ( result < 0 )
{
fwrite("[E] sock_tcp : address and port must not be NULL", 1uLL, 0x30uLL, stderr);
exit(1);
}
return result;
}

original_code:
int sock_tcp()
{
 int sock;
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
 {
  fprintf(stderr, "[E] sock_tcp : address and port must not be NULL");
  exit(1);
 }
 return sock;
}


decompiled_code:
__int64 __fastcall set_port(__int64 a1, const char *a2)
{
int v2; // er8
__int64 result; // rax
__int16 v4; // [rsp+Ch] [rbp-Ch] BYREF

v2 = sscanf(a2, "%d", &v4);
result = 1LL;
if ( v2 == 1 )
{
*(_WORD *)(a1 + 2) = _bswap_16(v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
int v2; // er8
__int64 result; // rax
__int16 v4; // [rsp+Ch] [rbp-Ch] BYREF

v2 = sscanf(a2, "%d", &v4);
result = 1LL;
if ( v2 == 1 )
{
*(_WORD *)(a1 + 2) = func0(v4);
result = 0LL;
}
return result;
}

original_code:
int set_port(struct sockaddr_in * address, char* port)
{
 int num;
 if (sscanf(port, "%d", &num) == 1) {
  address->sin_port = htons(num);
  return 0;
 }
 return 1;
}

canonical_original_code:
int set_port(struct sockaddr_in *address, char *port)
{
 int num;
 if (sscanf(port, "%d", &num) == 1) {
  address->sin_port = htons(num);
  return 0;
 }
 return 1;
}


decompiled_code:
_BOOL8 __fastcall receive_voip(int a1, void *a2)
{
return (int)recv(a1, a2, 0x88uLL, 64) <= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, void *a2)
{
return (int)recv(a1, a2, 0x88uLL, 64) <= 0;
}

original_code:
int receive_voip(int sock, s_voip* packetR)
{
 int nbR;
 if ((nbR = recv(sock, packetR, sizeof(s_voip), MSG_DONTWAIT)) > 0)
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int receive_voip(int sock, struct t_voip *packetR)
{
 int nbR;
 if ((nbR = recv(sock, packetR, sizeof(s_voip), MSG_DONTWAIT)) > 0)
 {
  return 0;
 }
 return 1;
}

variable_types: struct t_voip { unsigned long id; char data[128]; } *

variable_types: nbR int


original_code:
void* boucle_playback(void* arg)
{
 int rc, index;
 s_voip packetR[4];
 s_par_thread param = *((s_par_thread*)arg);
 rc=0;
 index=0;
 if(initSon(1, &(param.val), &(param.frames)) == 1)
  exit(1);
 for(int i=0;i<4;i++)
  packetR[i].id=0;
 while (1)
 {
  rc = receive_voip(param.sock, packetR + index);
  if(rc!=1)
  {
   playback(packetR[index].data);
   index = (index+1)%4;
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *boucle_playback(void *arg)
{
 int rc; int index;
 struct t_voip packetR[4];
 struct t_par_thread param = *((s_par_thread*)arg);
 rc=0;
 index=0;
 if(initSon(1, &(param.val), &(param.frames)) == 1)
  exit(1);
 for(int i = 0;i<4;i++)
  packetR[i].id=0;
 while (1)
 {
  rc = receive_voip(param.sock, packetR + index);
  if(rc!=1)
  {
   playback(packetR[index].data);
   index = (index+1)%4;
  }
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: rc int

variable_types: index int

variable_types: struct t_voip { unsigned long id; char data[128]; } [4]

variable_types: struct t_par_thread { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } destination; int sock; unsigned int val; unsigned long frames; }

variable_types: i int

user_defined_types: struct t_par_thread { struct sockaddr_in destination; int sock; unsigned int val; unsigned long frames; }


closeSon

decompiled_code:
int __fastcall closeSon(int a1)
{
printf("[I] Desallocation du handle de ");
if ( a1 )
puts("lecture");
else
puts("capture");
snd_pcm_drain(handle[a1]);
snd_pcm_close(handle[a1]);
return puts("[I] OK");
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
printf("[I] Desallocation du handle de ");
if ( a1 )
puts("lecture");
else
puts("capture");
snd_pcm_drain(handle[a1]);
snd_pcm_close(handle[a1]);
return puts("[I] OK");
}

original_code:
void closeSon(int mode)
{
 printf("[I] Desallocation du handle de ");
 if(mode==0)
  printf("capture\n");
 else
  printf("lecture\n");
 snd_pcm_drain(handle[mode]);
 snd_pcm_close(handle[mode]);
 printf("[I] OK\n");
}

variable_types: mode int


capture

decompiled_code:
int __fastcall capture(__int64 a1)
{
int result; // eax
const char *v2; // rax

result = snd_pcm_readi(handle[0], a1, frames);
if ( result == -32 )
{
fwrite("[D] overrun occurred\n", 1uLL, 0x15uLL, stderr);
result = snd_pcm_prepare(handle[0]);
}
else if ( result < 0 )
{
v2 = (const char *)snd_strerror((unsigned int)result);
result = fprintf(stderr, "[E] error from read: %s\n", v2);
}
else if ( (_DWORD)frames != result )
{
result = fprintf(stderr, "[D] short read, read %d frames\n", (unsigned int)result);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int result; // eax
const char *v2; // rax

result = snd_pcm_readi(handle[0], a1, frames);
if ( result == -32 )
{
fwrite("[D] overrun occurred\n", 1uLL, 0x15uLL, stderr);
result = snd_pcm_prepare(handle[0]);
}
else if ( result < 0 )
{
v2 = (const char *)snd_strerror((unsigned int)result);
result = fprintf(stderr, "[E] error from read: %s\n", v2);
}
else if ( (_DWORD)frames != result )
{
result = fprintf(stderr, "[D] short read, read %d frames\n", (unsigned int)result);
}
return result;
}

original_code:
void capture(char* str)
{
 int rc;
 rc = snd_pcm_readi(handle[0], str, frames);
 if (rc == -32)
 {
  fprintf(stderr, "[D] overrun occurred\n");
  snd_pcm_prepare(handle[0]);
 }
 else if (rc < 0)
  fprintf(stderr, "[E] error from read: %s\n", snd_strerror(rc));
 else if (rc != (int)frames)
  fprintf(stderr, "[D] short read, read %d frames\n", rc);
}

canonical_original_code:
void capture(char *str)
{
 int rc;
 rc = snd_pcm_readi(handle[0], str, frames);
 if (rc == -32)
 {
  fprintf(stderr, "[D] overrun occurred\n");
  snd_pcm_prepare(handle[0]);
 }
 else if (rc < 0)
  fprintf(stderr, "[E] error from read: %s\n", snd_strerror(rc));
 else if (rc != (int)frames)
  fprintf(stderr, "[D] short read, read %d frames\n", rc);
}

variable_types:
str
char *


playback

decompiled_code:
int __fastcall playback(__int64 a1)
{
int result; // eax
const char *v2; // rax

result = snd_pcm_writei(handle[1], a1, frames);
if ( result == -32 )
{
fwrite("[D] underrun occurred\n", 1uLL, 0x16uLL, stderr);
result = snd_pcm_prepare(handle[1]);
}
else if ( result < 0 )
{
v2 = (const char *)snd_strerror((unsigned int)result);
result = fprintf(stderr, "[E] error from writei: %s\n", v2);
}
else if ( (_DWORD)frames != result )
{
result = fprintf(stderr, "[D] short write, write %d frames\n", (unsigned int)result);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax
const char *v2; // rax

result = snd_pcm_writei(handle[1], a1, frames);
if ( result == -32 )
{
fwrite("[D] underrun occurred\n", 1uLL, 0x16uLL, stderr);
result = snd_pcm_prepare(handle[1]);
}
else if ( result < 0 )
{
v2 = (const char *)snd_strerror((unsigned int)result);
result = fprintf(stderr, "[E] error from writei: %s\n", v2);
}
else if ( (_DWORD)frames != result )
{
result = fprintf(stderr, "[D] short write, write %d frames\n", (unsigned int)result);
}
return result;
}

original_code:
void playback(char* str)
{
 int rc;
 rc = snd_pcm_writei(handle[1], str, frames);
 if (rc == -32)
 {
  fprintf(stderr, "[D] underrun occurred\n");
  snd_pcm_prepare(handle[1]);
 }
 else if (rc < 0)
  fprintf(stderr, "[E] error from writei: %s\n", snd_strerror(rc));
 else if (rc != (int)frames)
  fprintf(stderr, "[D] short write, write %d frames\n", rc);
}

canonical_original_code:
void playback(char *str)
{
 int rc;
 rc = snd_pcm_writei(handle[1], str, frames);
 if (rc == -32)
 {
  fprintf(stderr, "[D] underrun occurred\n");
  snd_pcm_prepare(handle[1]);
 }
 else if (rc < 0)
  fprintf(stderr, "[E] error from writei: %s\n", snd_strerror(rc));
 else if (rc != (int)frames)
  fprintf(stderr, "[D] short write, write %d frames\n", rc);
}


decompiled_code:
_BOOL8 __fastcall send_voip(int a1, const struct sockaddr *a2, const void *a3)
{
return (int)sendto(a1, a3, 0x88uLL, 0, a2, 0x10u) <= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, const struct sockaddr *a2, const void *a3)
{
return (int)sendto(a1, a3, 0x88uLL, 0, a2, 0x10u) <= 0;
}

original_code:
int send_voip(int sock, struct sockaddr_in * destination, s_voip* packetS)
{
 int nbS;
 if((nbS = sendto(sock, packetS, sizeof(s_voip), 0, (struct sockaddr *) destination, sizeof(struct sockaddr_in) )) > 0)
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int send_voip(int sock, struct sockaddr_in *destination, struct t_voip *packetS)
{
 int nbS;
 if((nbS = sendto(sock, packetS, sizeof(s_voip), 0, (struct sockaddr *) destination, sizeof(struct sockaddr_in) )) > 0)
 {
  return 0;
 }
 return 1;
}

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

variable_types: nbS int

user_defined_types: struct t_voip { unsigned long id; char data[128]; }

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


decompiled_code:
void __fastcall __noreturn boucle_capture(const __m128i *a1)
{
struct sockaddr v1[2]; // [rsp+0h] [rbp-C8h] BYREF
__m128i v2; // [rsp+20h] [rbp-A8h] BYREF
__int64 i; // [rsp+30h] [rbp-98h] BYREF
char v4[144]; // [rsp+38h] [rbp-90h] BYREF

v1[0] = (struct sockaddr)_mm_loadu_si128(a1);
v1[1] = (struct sockaddr)_mm_loadu_si128(a1 + 1);
v2 = _mm_loadu_si128(a1 + 2);
if ( (unsigned int)initSon(0LL, (char *)v2.m128i_i64 + 4, &v2.m128i_u64[1]) != 1 )
{
for ( i = 0LL; ; ++i )
{
do
capture(v4);
while ( send_voip(v2.m128i_i32[0], v1, &i) );
}
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const __m128i *a1)
{
struct sockaddr v1[2]; // [rsp+0h] [rbp-C8h] BYREF
__m128i v2; // [rsp+20h] [rbp-A8h] BYREF
__int64 i; // [rsp+30h] [rbp-98h] BYREF
char v4[144]; // [rsp+38h] [rbp-90h] BYREF

v1[0] = (struct sockaddr)_mm_loadu_si128(a1);
v1[1] = (struct sockaddr)_mm_loadu_si128(a1 + 1);
v2 = _mm_loadu_si128(a1 + 2);
if ( (unsigned int)initSon(0LL, (char *)v2.m128i_i64 + 4, &v2.m128i_u64[1]) != 1 )
{
for ( i = 0LL; ; ++i )
{
do
capture(v4);
while ( func0(v2.m128i_i32[0], v1, &i) );
}
}
exit(1);
}

original_code:
void * boucle_capture(void *arg)
{
 int rc;
 s_voip packetS;
 s_par_thread param = *((s_par_thread*)arg);
 if(initSon(0, &(param.val), &(param.frames)) == 1)
  exit(1);
 packetS.id=0;
 while(1)
 {
  capture(packetS.data);
  rc = send_voip(param.sock, &(param.destination), &packetS);
  if(rc != 1)
  packetS.id++;
 }
 return ((void *)0);
}

canonical_original_code:
void *boucle_capture(void *arg)
{
 int rc;
 struct t_voip packetS;
 struct t_par_thread param = *((s_par_thread*)arg);
 if(initSon(0, &(param.val), &(param.frames)) == 1)
  exit(1);
 packetS.id=0;
 while(1)
 {
  capture(packetS.data);
  rc = send_voip(param.sock, &(param.destination), &packetS);
  if(rc != 1)
  packetS.id++;
 }
 return ((void *)0);
}

variable_types: struct t_voip { unsigned long id; char data[128]; }


original_code:
void pack_luts_and_ffs(int lut_size)
{
    int bnum, in_blk, ipin, out_net, clock_net, in_net;
    char* tmp_name;
    for (bnum = 0; bnum < num_blocks; bnum++) {
        if (block[bnum].type == LATCH) {
            clock_net = block[bnum].nets[lut_size + 1];
            in_net = block[bnum].nets[1];
            if (net[in_net].num_pins == 2) {
                in_blk = net[in_net].pins[0];
                if (block[in_blk].type == LUT) {
                    net[in_net].pins[0] = -1;
                    out_net = block[bnum].nets[0];
                    block[in_blk].nets[0] = out_net;
                    tmp_name = block[in_blk].name;
                    block[in_blk].name = block[bnum].name;
                    block[bnum].name = tmp_name;
                    block[in_blk].nets[lut_size + 1] = clock_net;
                    block[in_blk].num_nets++;
                    block[bnum].type = EMPTY;
                    block[in_blk].type = LUT_AND_LATCH;
                    for (ipin = 0; ipin < net[out_net].num_pins; ipin++) {
                        if (net[out_net].pins[ipin] == bnum) {
                            net[out_net].pins[ipin] = in_blk;
                        }
                    }
                    for (ipin = 0; ipin < net[clock_net].num_pins; ipin++) {
                        if (net[clock_net].pins[ipin] == bnum) {
                            net[clock_net].pins[ipin] = in_blk;
                        }
                    }
                }
            }
        }
    }
}

canonical_original_code:
void pack_luts_and_ffs(int lut_size)
{
    int bnum; int in_blk; int ipin; int out_net; int clock_net; int in_net;
    char *tmp_name;
    for (bnum = 0; bnum < num_blocks; bnum++) {
        if (block[bnum].type == LATCH) {
            clock_net = block[bnum].nets[lut_size + 1];
            in_net = block[bnum].nets[1];
            if (net[in_net].num_pins == 2) {
                in_blk = net[in_net].pins[0];
                if (block[in_blk].type == LUT) {
                    net[in_net].pins[0] = -1;
                    out_net = block[bnum].nets[0];
                    block[in_blk].nets[0] = out_net;
                    tmp_name = block[in_blk].name;
                    block[in_blk].name = block[bnum].name;
                    block[bnum].name = tmp_name;
                    block[in_blk].nets[lut_size + 1] = clock_net;
                    block[in_blk].num_nets++;
                    block[bnum].type = EMPTY;
                    block[in_blk].type = LUT_AND_LATCH;
                    for (ipin = 0; ipin < net[out_net].num_pins; ipin++) {
                        if (net[out_net].pins[ipin] == bnum) {
                            net[out_net].pins[ipin] = in_blk;
                        }
                    }
                    for (ipin = 0; ipin < net[clock_net].num_pins; ipin++) {
                        if (net[clock_net].pins[ipin] == bnum) {
                            net[clock_net].pins[ipin] = in_blk;
                        }
                    }
                }
            }
        }
    }
}

variable_types: bnum int

variable_types: ipin int


original_code:
void compress_netlist(int lut_size)
{
    int inet, iblk, index, ipin, new_num_nets, new_num_blocks, max_pin;
    int* net_remap, *block_remap;
    new_num_nets = 0;
    new_num_blocks = 0;
    net_remap = my_malloc(num_nets * sizeof(int));
    block_remap = my_malloc(num_blocks * sizeof(int));
    for (inet = 0; inet < num_nets; inet++) {
        if (net[inet].pins[0] != -1) {
            net_remap[inet] = new_num_nets;
            new_num_nets++;
        } else {
            net_remap[inet] = -1;
        }
    }
    for (iblk = 0; iblk < num_blocks; iblk++) {
        if (block[iblk].type != EMPTY) {
            block_remap[iblk] = new_num_blocks;
            new_num_blocks++;
        } else {
            block_remap[iblk] = -1;
        }
    }
    if (new_num_nets != num_nets || new_num_blocks != num_blocks) {
        for (inet = 0; inet < num_nets; inet++) {
            if (net[inet].pins[0] != -1) {
                index = net_remap[inet];
                net[index] = net[inet];
                for (ipin = 0; ipin < net[index].num_pins; ipin++) {
                    net[index].pins[ipin] = block_remap[net[index].pins[ipin]];
                }
            } else {
                free(net[inet].name);
                free(net[inet].pins);
            }
        }
        num_nets = new_num_nets;
        net = (struct s_net*) my_realloc(net,
                                         num_nets * sizeof(struct s_net));
        for (iblk = 0; iblk < num_blocks; iblk++) {
            if (block[iblk].type != EMPTY) {
                index = block_remap[iblk];
                block[index] = block[iblk];
                if (block[index].type == INPAD || block[index].type == OUTPAD) {
                    max_pin = 1;
                } else {
                    max_pin = lut_size + 2;
                }
                for (ipin = 0; ipin < max_pin; ipin++) {
                    if (block[index].nets[ipin] != -1)
                        block[index].nets[ipin] =
                            net_remap[block[index].nets[ipin]];
                    else {
                        block[index].nets[ipin] = -1;
                    }
                }
            } else {
                free(block[iblk].name);
            }
        }
        num_blocks = new_num_blocks;
        block = (struct s_block*) my_realloc(block,
                                             num_blocks * sizeof(struct s_block));
    }
    num_p_inputs = 0;
    num_p_outputs = 0;
    for (iblk = 0; iblk < num_blocks; iblk++) {
        if (block[iblk].type == INPAD) {
            num_p_inputs++;
        } else if (block[iblk].type == OUTPAD) {
            num_p_outputs++;
        }
    }
    free(net_remap);
    free(block_remap);
}

canonical_original_code:
void compress_netlist(int lut_size)
{
    int inet; int iblk; int index; int ipin; int new_num_nets; int new_num_blocks; int max_pin;
    int *net_remap; int *block_remap;
    new_num_nets = 0;
    new_num_blocks = 0;
    net_remap = my_malloc(num_nets * sizeof(int));
    block_remap = my_malloc(num_blocks * sizeof(int));
    for (inet = 0; inet < num_nets; inet++) {
        if (net[inet].pins[0] != -1) {
            net_remap[inet] = new_num_nets;
            new_num_nets++;
        } else {
            net_remap[inet] = -1;
        }
    }
    for (iblk = 0; iblk < num_blocks; iblk++) {
        if (block[iblk].type != EMPTY) {
            block_remap[iblk] = new_num_blocks;
            new_num_blocks++;
        } else {
            block_remap[iblk] = -1;
        }
    }
    if (new_num_nets != num_nets || new_num_blocks != num_blocks) {
        for (inet = 0; inet < num_nets; inet++) {
            if (net[inet].pins[0] != -1) {
                index = net_remap[inet];
                net[index] = net[inet];
                for (ipin = 0; ipin < net[index].num_pins; ipin++) {
                    net[index].pins[ipin] = block_remap[net[index].pins[ipin]];
                }
            } else {
                free(net[inet].name);
                free(net[inet].pins);
            }
        }
        num_nets = new_num_nets;
        net = (struct s_net *) my_realloc(net,
                                         num_nets * sizeof(struct s_net));
        for (iblk = 0; iblk < num_blocks; iblk++) {
            if (block[iblk].type != EMPTY) {
                index = block_remap[iblk];
                block[index] = block[iblk];
                if (block[index].type == INPAD || block[index].type == OUTPAD) {
                    max_pin = 1;
                } else {
                    max_pin = lut_size + 2;
                }
                for (ipin = 0; ipin < max_pin; ipin++) {
                    if (block[index].nets[ipin] != -1)
                        block[index].nets[ipin] =
                            net_remap[block[index].nets[ipin]];
                    else {
                        block[index].nets[ipin] = -1;
                    }
                }
            } else {
                free(block[iblk].name);
            }
        }
        num_blocks = new_num_blocks;
        block = (struct s_block *) my_realloc(block,
                                             num_blocks * sizeof(struct s_block));
    }
    num_p_inputs = 0;
    num_p_outputs = 0;
    for (iblk = 0; iblk < num_blocks; iblk++) {
        if (block[iblk].type == INPAD) {
            num_p_inputs++;
        } else if (block[iblk].type == OUTPAD) {
            num_p_outputs++;
        }
    }
    free(net_remap);
    free(block_remap);
}

variable_types: inet int

variable_types: iblk int

user_defined_types: struct s_net { char *name; int num_pins; int *pins; }

user_defined_types: struct s_block { char *name; enum block_types type; int num_nets; int nets[-1]; }

user_defined_types: enum block_types { INPAD=-2, OUTPAD=-1, LUT=0, LATCH=1, EMPTY=2, LUT_AND_LATCH=3 }


decompiled_code:
__int64 __fastcall alloc_and_load_is_clock(int a1, int a2)
{
__int64 v2; // r12
signed int v3; // ecx
int v4; // er8
_DWORD *v5; // rdx
_DWORD *v6; // rax

v2 = my_calloc(num_nets, 4LL);
if ( (int)num_blocks > 0 )
{
v3 = 0;
v4 = 0;
v5 = (_DWORD *)(block + 8LL);
do
{
if ( (*v5 & 0xFFFFFFFD) == 1 )
{
v6 = (_DWORD *)(v2 + 4LL * (int)v5[a2 + 3]);
if ( !*v6 )
{
*v6 = 1;
++v4;
}
}
++v3;
v5 += 14;
}
while ( (int)num_blocks > v3 );
if ( v4 > 1 && a1 )
{
printf("Warning: circuit contains %d clocks.\n", (unsigned int)v4);
puts(" All will be marked global.");
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 v2; // r12
signed int v3; // ecx
int v4; // er8
_DWORD *v5; // rdx
_DWORD *v6; // rax

v2 = my_calloc(num_nets, 4LL);
if ( (int)num_blocks > 0 )
{
v3 = 0;
v4 = 0;
v5 = (_DWORD *)(block + 8LL);
do
{
if ( (*v5 & 0xFFFFFFFD) == 1 )
{
v6 = (_DWORD *)(v2 + 4LL * (int)v5[a2 + 3]);
if ( !*v6 )
{
*v6 = 1;
++v4;
}
}
++v3;
v5 += 14;
}
while ( (int)num_blocks > v3 );
if ( v4 > 1 && a1 )
{
printf("Warning: circuit contains %d clocks.\n", (unsigned int)v4);
puts(" All will be marked global.");
}
}
return v2;
}

original_code:
boolean* alloc_and_load_is_clock(boolean global_clocks, int lut_size)
{
    int num_clocks, bnum, clock_net;
    boolean* is_clock;
    num_clocks = 0;
    is_clock = (boolean*) my_calloc(num_nets, sizeof(boolean));
    for (bnum = 0; bnum < num_blocks; bnum++) {
        if (block[bnum].type == LATCH || block[bnum].type == LUT_AND_LATCH) {
            clock_net = block[bnum].nets[lut_size + 1];
            if (is_clock[clock_net] == FALSE) {
                is_clock[clock_net] = TRUE;
                num_clocks++;
            }
        }
    }
    if (num_clocks > 1 && global_clocks) {
        printf("Warning:  circuit contains %d clocks.\n", num_clocks);
        printf("          All will be marked global.\n");
    }
    return (is_clock);
}

canonical_original_code:
enum boolean *alloc_and_load_is_clock(enum boolean global_clocks, int lut_size)
{
    int num_clocks; int bnum; int clock_net;
    enum boolean *is_clock;
    num_clocks = 0;
    is_clock = (enum boolean *) my_calloc(num_nets, sizeof(boolean));
    for (bnum = 0; bnum < num_blocks; bnum++) {
        if (block[bnum].type == LATCH || block[bnum].type == LUT_AND_LATCH) {
            clock_net = block[bnum].nets[lut_size + 1];
            if (is_clock[clock_net] == FALSE) {
                is_clock[clock_net] = TRUE;
                num_clocks++;
            }
        }
    }
    if (num_clocks > 1 && global_clocks) {
        printf("Warning:  circuit contains %d clocks.\n", num_clocks);
        printf("          All will be marked global.\n");
    }
    return (is_clock);
}

return_type: enum boolean { FALSE=0, TRUE=1 } *


repo: deoryp/epaper

decompiled_code:
__int64 __fastcall epd_DisplayImg(unsigned __int8 a1, __int64 a2, __int64 a3)
{
epd_HwInit();
epd_PowerOn();
epd_InitializeDriver(a1);
epd_Display(a2, a3);
return epd_PowerOff();
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, __int64 a2, __int64 a3)
{
epd_HwInit();
epd_PowerOn();
epd_InitializeDriver(a1);
epd_Display(a2, a3);
return epd_PowerOff();
}

original_code:
void epd_DisplayImg(EPDType_t EPDType, uint8_t *pNewImg, uint8_t *pPrevImg)
{
 epd_HwInit();
 epd_PowerOn();
 epd_InitializeDriver(EPDType);
 epd_Display(pNewImg, pPrevImg);
 epd_PowerOff();
}

canonical_original_code:
void epd_DisplayImg(enum EPDType_t EPDType, unsigned char *pNewImg, unsigned char *pPrevImg)
{
 epd_HwInit();
 epd_PowerOn();
 epd_InitializeDriver(EPDType);
 epd_Display(pNewImg, pPrevImg);
 epd_PowerOff();
}

variable_types: enum EPDType_t { EPDType_144=0, EPDType_200=1, EPDType_270=2 }

variable_types:
pNewImg
unsigned char *

variable_types:
pPrevImg
unsigned char *


decompiled_code:
__int64 epd_cs_high()
{
return bsp_pinOut(0LL, 1LL);
}

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

original_code:
void epd_cs_high(void)
{
  bsp_pinOut(BSP_PIN_6, 1);
}

canonical_original_code:
void epd_cs_high()
{
  bsp_pinOut(BSP_PIN_6, 1);
}


decompiled_code:
__int64 epd_cs_low()
{
return bsp_pinOut(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return bsp_pinOut(0LL, 0LL);
}

original_code:
void epd_cs_low(void)
{
  bsp_pinOut(BSP_PIN_6, 0);
}

canonical_original_code:
void epd_cs_low()
{
  bsp_pinOut(BSP_PIN_6, 0);
}


decompiled_code:
__int64 epd_rst_high()
{
return bsp_pinOut(4LL, 1LL);
}

canonical_decompiled_code:
__int64 func2()
{
return bsp_pinOut(4LL, 1LL);
}

original_code:
void epd_rst_high(void)
{
  bsp_pinOut(BSP_PIN_12, 1);
}

canonical_original_code:
void epd_rst_high()
{
  bsp_pinOut(BSP_PIN_12, 1);
}


decompiled_code:
__int64 epd_rst_low()
{
return bsp_pinOut(4LL, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
return bsp_pinOut(4LL, 0LL);
}

original_code:
void epd_rst_low(void)
{
  bsp_pinOut(BSP_PIN_12, 0);
}

canonical_original_code:
void epd_rst_low()
{
  bsp_pinOut(BSP_PIN_12, 0);
}


decompiled_code:
__int64 epd_discharge_high()
{
return bsp_pinOut(6LL, 1LL);
}

canonical_decompiled_code:
__int64 func4()
{
return bsp_pinOut(6LL, 1LL);
}

original_code:
void epd_discharge_high(void)
{
  bsp_pinOut(BSP_PIN_14, 1);
}

canonical_original_code:
void epd_discharge_high()
{
  bsp_pinOut(BSP_PIN_14, 1);
}


decompiled_code:
__int64 epd_discharge_low()
{
return bsp_pinOut(6LL, 0LL);
}

canonical_decompiled_code:
__int64 func5()
{
return bsp_pinOut(6LL, 0LL);
}

original_code:
void epd_discharge_low(void)
{
  bsp_pinOut(BSP_PIN_14, 0);
}

canonical_original_code:
void epd_discharge_low()
{
  bsp_pinOut(BSP_PIN_14, 0);
}


decompiled_code:
__int64 epd_panelon_off()
{
return bsp_pinOut(5LL, 0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return bsp_pinOut(5LL, 0LL);
}

original_code:
void epd_panelon_off(void)
{
  bsp_pinOut(BSP_PIN_13, 0);
}

canonical_original_code:
void epd_panelon_off()
{
  bsp_pinOut(BSP_PIN_13, 0);
}


decompiled_code:
__int64 epd_panelon_on()
{
return bsp_pinOut(5LL, 1LL);
}

canonical_decompiled_code:
__int64 func7()
{
return bsp_pinOut(5LL, 1LL);
}

original_code:
void epd_panelon_on(void)
{
  bsp_pinOut(BSP_PIN_13, 1);
}

canonical_original_code:
void epd_panelon_on()
{
  bsp_pinOut(BSP_PIN_13, 1);
}


decompiled_code:
void epd_border_high()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void epd_border_high(void)
{
}

canonical_original_code:
void epd_border_high()
{
}


decompiled_code:
void epd_border_low()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void epd_border_low(void)
{
}

canonical_original_code:
void epd_border_low()
{
}


decompiled_code:
// attributes: thunk
__int64 epd_delay_ms()
{
return bsp_delayMs();
}

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

original_code:
void epd_delay_ms(uint32_t Time)
{
 bsp_delayMs(Time);
}

canonical_original_code:
void epd_delay_ms(unsigned int Time)
{
 bsp_delayMs(Time);
}

variable_types:
Time
unsigned int


decompiled_code:
// attributes: thunk
__int64 epd_get_temperature()
{
return bsp_getTemp();
}

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

original_code:
int16_t epd_get_temperature(void)
{
 return bsp_getTemp();
}

canonical_original_code:
short epd_get_temperature()
{
 return bsp_getTemp();
}

return_type: short


decompiled_code:
// attributes: thunk
__int64 epd_GetCurrentTimeTick()
{
return bsp_getMsTicks();
}

canonical_decompiled_code:
__int64 func12()
{
return bsp_getMsTicks();
}

original_code:
uint32_t epd_GetCurrentTimeTick(void)
{
 return bsp_getMsTicks();
}

canonical_original_code:
unsigned int epd_GetCurrentTimeTick()
{
 return bsp_getMsTicks();
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall epd_pwm_active(__int16 a1)
{
__int16 v1; // bx
__int64 result; // rax

v1 = 100 * a1;
result = bsp_pinMode(3LL, 1LL);
if ( 100 * a1 )
{
do
{
bsp_pinOut(3LL, 1LL);
bsp_delayUs(5LL);
bsp_pinOut(3LL, 0LL);
result = bsp_delayUs(5LL);
--v1;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int16 a1)
{
__int16 v1; // bx
__int64 result; // rax

v1 = 100 * a1;
result = bsp_pinMode(3LL, 1LL);
if ( 100 * a1 )
{
do
{
bsp_pinOut(3LL, 1LL);
bsp_delayUs(5LL);
bsp_pinOut(3LL, 0LL);
result = bsp_delayUs(5LL);
--v1;
}
while ( v1 );
}
return result;
}

original_code:
void epd_pwm_active(uint16_t delayInMs)
{
  uint16_t numOfIterations;
  numOfIterations = delayInMs * 100;
  bsp_pinMode(BSP_PIN_11, BSP_PINMODE_OUTPUT);
  for(; numOfIterations > 0; numOfIterations--)
  {
    bsp_pinOut(BSP_PIN_11, 1);
    bsp_delayUs(5);
    bsp_pinOut(BSP_PIN_11, 0);
    bsp_delayUs(5);
  }
}

canonical_original_code:
void epd_pwm_active(unsigned short delayInMs)
{
  unsigned short numOfIterations;
  numOfIterations = delayInMs * 100;
  bsp_pinMode(BSP_PIN_11, BSP_PINMODE_OUTPUT);
  for(; numOfIterations > 0; numOfIterations--)
  {
    bsp_pinOut(BSP_PIN_11, 1);
    bsp_delayUs(5);
    bsp_pinOut(BSP_PIN_11, 0);
    bsp_delayUs(5);
  }
}

variable_types:
delayInMs
unsigned short

variable_types:
numOfIterations
unsigned short


decompiled_code:
void epd_spi_detach()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void epd_spi_detach(void)
{
}

canonical_original_code:
void epd_spi_detach()
{
}


decompiled_code:
// attributes: thunk
__int64 epd_spi_init()
{
return bsp_spiInit();
}

canonical_decompiled_code:
__int64 func15()
{
return bsp_spiInit();
}

original_code:
void epd_spi_init (void)
{
  bsp_spiInit();
}

canonical_original_code:
void epd_spi_init()
{
  bsp_spiInit();
}


decompiled_code:
__int64 __fastcall epd_SPI_Send(char a1, __int64 a2, unsigned __int16 a3)
{
char v5[26]; // [rsp+Eh] [rbp-1Ah] BYREF

epd_cs_low();
v5[1] = a1;
v5[0] = 112;
bsp_writeToDisplay(v5, 2LL);
epd_cs_high();
bsp_delayUs(10LL);
epd_cs_low();
v5[0] = 114;
bsp_writeToDisplay(v5, 1LL);
bsp_writeToDisplay(a2, a3);
epd_cs_high();
return bsp_delayUs(10LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(char a1, __int64 a2, unsigned __int16 a3)
{
char v5[26]; // [rsp+Eh] [rbp-1Ah] BYREF

func1();
v5[1] = a1;
v5[0] = 112;
bsp_writeToDisplay(v5, 2LL);
func0();
bsp_delayUs(10LL);
func1();
v5[0] = 114;
bsp_writeToDisplay(v5, 1LL);
bsp_writeToDisplay(a2, a3);
func0();
return bsp_delayUs(10LL);
}

original_code:
void epd_SPI_Send (unsigned char Register, unsigned char *Data, unsigned Length)
{
  uint8_t buf[2];
  epd_cs_low();
  buf[0] = 0x70;
  buf[1] = Register;
  bsp_writeToDisplay(buf, 2);
  epd_cs_high();
  bsp_delayUs(10);
  epd_cs_low();
  buf[0] = 0x72;
  bsp_writeToDisplay(buf, 1);
  bsp_writeToDisplay(Data, Length);
  epd_cs_high();
  bsp_delayUs(10);
}

canonical_original_code:
void epd_SPI_Send(unsigned char Register, unsigned char *Data, unsigned int Length)
{
  unsigned char buf[2];
  epd_cs_low();
  buf[0] = 0x70;
  buf[1] = Register;
  bsp_writeToDisplay(buf, 2);
  epd_cs_high();
  bsp_delayUs(10);
  epd_cs_low();
  buf[0] = 0x72;
  bsp_writeToDisplay(buf, 1);
  bsp_writeToDisplay(Data, Length);
  epd_cs_high();
  bsp_delayUs(10);
}

variable_types:
Register
unsigned char

variable_types:
Data
unsigned char *

variable_types:
Length
unsigned int

variable_types:
buf
unsigned char [2]


decompiled_code:
__int64 __fastcall epd_SPI_Send_Byte(char a1, char a2)
{
char v3; // [rsp+Eh] [rbp-1Ah] BYREF
char v4; // [rsp+Fh] [rbp-19h]

epd_cs_low();
v4 = a1;
v3 = 112;
bsp_writeToDisplay(&v3, 2LL);
epd_cs_high();
bsp_delayUs(10LL);
epd_cs_low();
v4 = a2;
v3 = 114;
bsp_writeToDisplay(&v3, 2LL);
epd_cs_high();
return bsp_delayUs(10LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(char a1, char a2)
{
char v3; // [rsp+Eh] [rbp-1Ah] BYREF
char v4; // [rsp+Fh] [rbp-19h]

func1();
v4 = a1;
v3 = 112;
bsp_writeToDisplay(&v3, 2LL);
func0();
bsp_delayUs(10LL);
func1();
v4 = a2;
v3 = 114;
bsp_writeToDisplay(&v3, 2LL);
func0();
return bsp_delayUs(10LL);
}

original_code:
void epd_SPI_Send_Byte (uint8_t Register, uint8_t Data)
{
  uint8_t buf[2];
  epd_cs_low();
  buf[0] = 0x70;
  buf[1] = Register;
  bsp_writeToDisplay(buf, 2);
  epd_cs_high();
  bsp_delayUs(10);
  epd_cs_low();
  buf[0] = 0x72;
  buf[1] = Data;
  bsp_writeToDisplay(buf, 2);
  epd_cs_high();
  bsp_delayUs(10);
}

canonical_original_code:
void epd_SPI_Send_Byte(unsigned char Register, unsigned char Data)
{
  unsigned char buf[2];
  epd_cs_low();
  buf[0] = 0x70;
  buf[1] = Register;
  bsp_writeToDisplay(buf, 2);
  epd_cs_high();
  bsp_delayUs(10);
  epd_cs_low();
  buf[0] = 0x72;
  buf[1] = Data;
  bsp_writeToDisplay(buf, 2);
  epd_cs_high();
  bsp_delayUs(10);
}

variable_types:
Data
unsigned char


decompiled_code:
__int64 epd_InitDisplayHardware()
{
bsp_pinMode(4LL, 1LL);
bsp_pinMode(6LL, 1LL);
bsp_pinMode(0LL, 1LL);
bsp_pinMode(5LL, 1LL);
bsp_pinMode(1LL, 0LL);
epd_panelon_off();
epd_spi_init();
epd_cs_low();
epd_pwm_active(0);
epd_rst_low();
return epd_discharge_low();
}

canonical_decompiled_code:
__int64 func18()
{
bsp_pinMode(4LL, 1LL);
bsp_pinMode(6LL, 1LL);
bsp_pinMode(0LL, 1LL);
bsp_pinMode(5LL, 1LL);
bsp_pinMode(1LL, 0LL);
func6();
func15();
func1();
func13(0);
func3();
return func5();
}

original_code:
void epd_InitDisplayHardware(void)
{
  bsp_pinMode(BSP_PIN_12, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_14, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_6, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_13, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_7, BSP_PINMODE_INPUT);
  epd_panelon_off();
  epd_spi_init();
  epd_cs_low();
  epd_pwm_active(0);
  epd_rst_low();
  epd_discharge_low();
}

canonical_original_code:
void epd_InitDisplayHardware()
{
  bsp_pinMode(BSP_PIN_12, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_14, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_6, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_13, BSP_PINMODE_OUTPUT);
  bsp_pinMode(BSP_PIN_7, BSP_PINMODE_INPUT);
  epd_panelon_off();
  epd_spi_init();
  epd_cs_low();
  epd_pwm_active(0);
  epd_rst_low();
  epd_discharge_low();
}


TestPinLow

decompiled_code:
void TestPinLow()
{
;
}

canonical_decompiled_code:
void func19()
{
;
}

original_code:
void TestPinLow(void)
{
}

canonical_original_code:
void TestPinLow()
{
}


TestPinHigh

decompiled_code:
void TestPinHigh()
{
;
}

canonical_decompiled_code:
void func20()
{
;
}

original_code:
void TestPinHigh(void)
{
}

canonical_original_code:
void TestPinHigh()
{
}


TestPinTrigger

decompiled_code:
void TestPinTrigger()
{
;
}

canonical_decompiled_code:
void func21()
{
;
}

original_code:
void TestPinTrigger(void)
{
}

canonical_original_code:
void TestPinTrigger()
{
}


decompiled_code:
void TestPin2Low()
{
;
}

canonical_decompiled_code:
void func22()
{
;
}

original_code:
void TestPin2Low(void)
{
}

canonical_original_code:
void TestPin2Low()
{
}


decompiled_code:
void TestPin2High()
{
;
}

canonical_decompiled_code:
void func23()
{
;
}

original_code:
void TestPin2High(void)
{
}

canonical_original_code:
void TestPin2High()
{
}


decompiled_code:
void TestPin2Trigger()
{
;
}

canonical_decompiled_code:
void func24()
{
;
}

original_code:
void TestPin2Trigger(void)
{
}

canonical_original_code:
void TestPin2Trigger()
{
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
_BYTE v5[5848]; // [rsp+0h] [rbp-16D8h] BYREF

memset(&PreloadImage, 0xFFu, 0x16B0uLL);
memset(v5, 0xFFu, 0x16B0uLL);
puts("Starting E-paper demo");
bsp_init();
if ( argc <= 1 )
{
v3 = &PreloadImage;
while ( 1 )
{
puts("EA Image");
epd_DisplayImg(2LL, &ImageDataEA, v3);
v3 = &ImageDataPD;
bsp_delayMs(10000LL);
puts("PD Image");
epd_DisplayImg(2LL, &ImageDataPD, &ImageDataEA);
bsp_delayMs(10000LL);
}
}
printf("Image from file %s\n", argv[1]);
asciiImage_readImage(argv[1], v5, 176LL, 33LL);
epd_DisplayImg(2LL, v5, &PreloadImage);
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 uint8_t* pOldImg;
 uint8_t* pImg;
 unsigned char FileImage[176][33];
 memset((uint8_t*)&PreloadImage[0][0], 0xff, 176*33);
 pOldImg = (uint8_t*)&PreloadImage[0][0];
 memset((uint8_t*)&FileImage[0][0], 0xff, 176*33);
 pImg = (uint8_t*)&FileImage[0][0];
 printf("Starting E-paper demo\n");
 bsp_init();
 if (argc > 1) {
  printf("Image from file %s\n", argv[1]);
  asciiImage_readImage(argv[1], pImg, 176, 33);
  epd_DisplayImg(2, pImg, pOldImg);
  return 1;
 }
 while(1) {
  printf("EA Image\n");
  epd_DisplayImg(2, (uint8_t*)&ImageDataEA[0][0], pOldImg);
  pOldImg = (uint8_t*)&ImageDataEA[0][0];
  bsp_delayMs(10000);
  printf("PD Image\n");
  epd_DisplayImg(2, (uint8_t*)&ImageDataPD[0][0], pOldImg);
  pOldImg = (uint8_t*)&ImageDataPD[0][0];
  bsp_delayMs(10000);
 }
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned char *pOldImg;
 unsigned char *pImg;
 unsigned char FileImage[176][33];
 memset((unsigned char *)&PreloadImage[0][0], 0xff, 176*33);
 pOldImg = (unsigned char *)&PreloadImage[0][0];
 memset((unsigned char *)&FileImage[0][0], 0xff, 176*33);
 pImg = (unsigned char *)&FileImage[0][0];
 printf("Starting E-paper demo\n");
 bsp_init();
 if (argc > 1) {
  printf("Image from file %s\n", argv[1]);
  asciiImage_readImage(argv[1], pImg, 176, 33);
  epd_DisplayImg(2, pImg, pOldImg);
  return 1;
 }
 while(1) {
  printf("EA Image\n");
  epd_DisplayImg(2, (unsigned char *)&ImageDataEA[0][0], pOldImg);
  pOldImg = (unsigned char *)&ImageDataEA[0][0];
  bsp_delayMs(10000);
  printf("PD Image\n");
  epd_DisplayImg(2, (unsigned char *)&ImageDataPD[0][0], pOldImg);
  pOldImg = (unsigned char *)&ImageDataPD[0][0];
  bsp_delayMs(10000);
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
pOldImg
unsigned char *

variable_types:
pImg
unsigned char *

variable_types:
FileImage
unsigned char [176][33]


decompiled_code:
void __fastcall Driver_TypeSelect(char a1)
{
switch ( a1 )
{
case 1:
DataLineEven = &COG_Line;
DataLineOdd = &unk_1051;
DataLineScan = (__int64)&unk_1039;
break;
case 2:
DataLineEven = &COG_Line;
DataLineOdd = &unk_106D;
DataLineScan = (__int64)&unk_1041;
break;
case 0:
DataLineEven = &COG_Line;
DataLineOdd = &unk_1048;
DataLineScan = (__int64)&unk_1030;
break;
}
}

canonical_decompiled_code:
void __fastcall func0(char a1)
{
switch ( a1 )
{
case 1:
DataLineEven = &COG_Line;
DataLineOdd = &unk_1051;
DataLineScan = (__int64)&unk_1039;
break;
case 2:
DataLineEven = &COG_Line;
DataLineOdd = &unk_106D;
DataLineScan = (__int64)&unk_1041;
break;
case 0:
DataLineEven = &COG_Line;
DataLineOdd = &unk_1048;
DataLineScan = (__int64)&unk_1030;
break;
}
}

original_code:
static void Driver_TypeSelect(uint8_t typeIndex)
{
 switch(typeIndex)
 {
  case EPDType_144:
   DataLineEven=&COG_Line.LineDatas.COG_144LineData.Even[0];
   DataLineOdd=&COG_Line.LineDatas.COG_144LineData.Odd[0];
   DataLineScan=&COG_Line.LineDatas.COG_144LineData.Scan[0];
   break;
  case EPDType_200:
   DataLineEven=&COG_Line.LineDatas.COG_20LineData.Even[0];
   DataLineOdd=&COG_Line.LineDatas.COG_20LineData.Odd[0];
   DataLineScan=&COG_Line.LineDatas.COG_20LineData.Scan[0];
   break;
  case EPDType_270:
   DataLineEven=&COG_Line.LineDatas.COG_27LineData.Even[0];
   DataLineOdd=&COG_Line.LineDatas.COG_27LineData.Odd[0];
   DataLineScan=&COG_Line.LineDatas.COG_27LineData.Scan[0];
   break;
 }
}

canonical_original_code:
static void Driver_TypeSelect(unsigned char typeIndex)
{
 switch(typeIndex)
 {
  case EPDType_144:
   DataLineEven=&COG_Line.LineDatas.COG_144LineData.Even[0];
   DataLineOdd=&COG_Line.LineDatas.COG_144LineData.Odd[0];
   DataLineScan=&COG_Line.LineDatas.COG_144LineData.Scan[0];
   break;
  case EPDType_200:
   DataLineEven=&COG_Line.LineDatas.COG_20LineData.Even[0];
   DataLineOdd=&COG_Line.LineDatas.COG_20LineData.Odd[0];
   DataLineScan=&COG_Line.LineDatas.COG_20LineData.Scan[0];
   break;
  case EPDType_270:
   DataLineEven=&COG_Line.LineDatas.COG_27LineData.Even[0];
   DataLineOdd=&COG_Line.LineDatas.COG_27LineData.Odd[0];
   DataLineScan=&COG_Line.LineDatas.COG_27LineData.Scan[0];
   break;
 }
}

variable_types:
typeIndex
unsigned char


decompiled_code:
__int64 Display_Nothing()
{
__int64 v0; // rbx
unsigned __int16 v1; // dx
_BYTE *v2; // rdi
size_t v3; // r12
_BYTE *v4; // rbp
__int64 result; // rax
int v6; // ebx
__int64 v7; // rdx
unsigned __int16 v8; // ax
__int64 v9; // rax

v0 = (unsigned __int16)EPD_Type_Index;
v1 = COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 5];
if ( v1 )
{
v2 = DataLineEven;
v3 = v1;
v4 = DataLineOdd;
if ( DataLineOdd < (char *)DataLineEven + v1 && DataLineEven < (char *)DataLineOdd + v1 )
{
v9 = 0LL;
do
{
v2[v9] = 0;
v4[v9++] = 0;
}
while ( v1 > (unsigned __int16)v9 );
}
else
{
memset(DataLineEven, 0, v1);
memset(v4, 0, v3);
}
}
result = 5 * v0;
if ( COG_Parameters[10 * v0 + 6] )
{
v6 = 0;
do
{
epd_SPI_Send_Byte(4LL, 3LL);
v7 = v6 & 3;
v8 = (unsigned __int16)v6++ >> 2;
*(_BYTE *)(DataLineScan + v8) = ScanTable[v7];
epd_SPI_Send(10LL, &COG_Line, LOBYTE(COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 7]));
epd_SPI_Send_Byte(2LL, 47LL);
result = 5LL * (unsigned __int16)EPD_Type_Index;
}
while ( (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 6] > (unsigned __int16)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
unsigned __int16 v1; // dx
_BYTE *v2; // rdi
size_t v3; // r12
_BYTE *v4; // rbp
__int64 result; // rax
int v6; // ebx
__int64 v7; // rdx
unsigned __int16 v8; // ax
__int64 v9; // rax

v0 = (unsigned __int16)EPD_Type_Index;
v1 = COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 5];
if ( v1 )
{
v2 = DataLineEven;
v3 = v1;
v4 = DataLineOdd;
if ( DataLineOdd < (char *)DataLineEven + v1 && DataLineEven < (char *)DataLineOdd + v1 )
{
v9 = 0LL;
do
{
v2[v9] = 0;
v4[v9++] = 0;
}
while ( v1 > (unsigned __int16)v9 );
}
else
{
memset(DataLineEven, 0, v1);
memset(v4, 0, v3);
}
}
result = 5 * v0;
if ( COG_Parameters[10 * v0 + 6] )
{
v6 = 0;
do
{
epd_SPI_Send_Byte(4LL, 3LL);
v7 = v6 & 3;
v8 = (unsigned __int16)v6++ >> 2;
*(_BYTE *)(DataLineScan + v8) = ScanTable[v7];
epd_SPI_Send(10LL, &COG_Line, LOBYTE(COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 7]));
epd_SPI_Send_Byte(2LL, 47LL);
result = 5LL * (unsigned __int16)EPD_Type_Index;
}
while ( (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 6] > (unsigned __int16)v6 );
}
return result;
}

original_code:
static void Display_Nothing (void)
{
 uint16_t i;
 for (i = 0; i < COG_Parameters[EPD_Type_Index].HORIZONTAL; i++)
 {
  DataLineEven[i] = 0x00;
  DataLineOdd[i] = 0x00;
 }
 for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++)
 {
  epd_SPI_Send_Byte(0x04, 0x03);
  DataLineScan[(i>>2)] = ScanTable[(i%4)];
  epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
  epd_SPI_Send_Byte(0x02, 0x2F);
 }
}

canonical_original_code:
static void Display_Nothing()
{
 unsigned short i;
 for (i = 0; i < COG_Parameters[EPD_Type_Index].HORIZONTAL; i++)
 {
  DataLineEven[i] = 0x00;
  DataLineOdd[i] = 0x00;
 }
 for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++)
 {
  epd_SPI_Send_Byte(0x04, 0x03);
  DataLineScan[(i>>2)] = ScanTable[(i%4)];
  epd_SPI_Send(0x0a, (unsigned char *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
  epd_SPI_Send_Byte(0x02, 0x2F);
 }
}

variable_types:
i
unsigned short


decompiled_code:
__int64 Dummy_line()
{
unsigned __int64 v0; // rdx
_DWORD *v1; // rdi

v0 = LOBYTE(COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 7]);
if ( (_BYTE)v0 )
{
v1 = &COG_Line;
if ( (unsigned int)v0 >= 8 )
{
memset(&COG_Line, 0, 8 * (v0 >> 3));
v1 = (_DWORD *)((char *)&COG_Line + 8 * (v0 >> 3));
}
if ( (v0 & 4) != 0 )
{
*v1++ = 0;
if ( (v0 & 2) == 0 )
{
LABEL_6:
if ( (v0 & 1) == 0 )
goto LABEL_7;
LABEL_8:
*(_BYTE *)v1 = 0;
goto LABEL_7;
}
}
else if ( (v0 & 2) == 0 )
{
goto LABEL_6;
}
v1 = (_DWORD *)((char *)v1 + 2);
*((_WORD *)v1 - 1) = 0;
if ( (v0 & 1) == 0 )
goto LABEL_7;
goto LABEL_8;
}
LABEL_7:
epd_SPI_Send_Byte(4LL, 3LL);
epd_SPI_Send(10LL, &COG_Line, LOBYTE(COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 7]));
return epd_SPI_Send_Byte(2LL, 47LL);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned __int64 v0; // rdx
_DWORD *v1; // rdi

v0 = LOBYTE(COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 7]);
if ( (_BYTE)v0 )
{
v1 = &COG_Line;
if ( (unsigned int)v0 >= 8 )
{
memset(&COG_Line, 0, 8 * (v0 >> 3));
v1 = (_DWORD *)((char *)&COG_Line + 8 * (v0 >> 3));
}
if ( (v0 & 4) != 0 )
{
*v1++ = 0;
if ( (v0 & 2) == 0 )
{
LABEL_6:
if ( (v0 & 1) == 0 )
goto LABEL_7;
LABEL_8:
*(_BYTE *)v1 = 0;
goto LABEL_7;
}
}
else if ( (v0 & 2) == 0 )
{
goto LABEL_6;
}
v1 = (_DWORD *)((char *)v1 + 2);
*((_WORD *)v1 - 1) = 0;
if ( (v0 & 1) == 0 )
goto LABEL_7;
goto LABEL_8;
}
LABEL_7:
epd_SPI_Send_Byte(4LL, 3LL);
epd_SPI_Send(10LL, &COG_Line, LOBYTE(COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 7]));
return epd_SPI_Send_Byte(2LL, 47LL);
}

original_code:
static void Dummy_line(void)
{
 uint16_t i;
 for (i = 0; i < COG_Parameters[EPD_Type_Index].DataLineSize; i++)
 {
  COG_Line.uint8[i] = 0x00;
 }
 epd_SPI_Send_Byte(0x04, 0x03);
 epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
 epd_SPI_Send_Byte(0x02, 0x2F);
}

canonical_original_code:
static void Dummy_line()
{
 unsigned short i;
 for (i = 0; i < COG_Parameters[EPD_Type_Index].DataLineSize; i++)
 {
  COG_Line.uint8[i] = 0x00;
 }
 epd_SPI_Send_Byte(0x04, 0x03);
 epd_SPI_Send(0x0a, (unsigned char *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
 epd_SPI_Send_Byte(0x02, 0x2F);
}


decompiled_code:
unsigned __int64 __fastcall SetTemperature_Factor(unsigned __int8 a1)
{
__int16 v1; // dx
unsigned __int64 result; // rax

v1 = epd_get_temperature();
result = (unsigned __int16)COG_Parameters[10 * a1 + 9];
if ( v1 >= -10 )
{
if ( v1 >= -5 )
{
if ( v1 <= 4 )
{
result = (unsigned int)(8 * result);
StageTime = result;
}
else if ( v1 > 9 )
{
if ( v1 <= 14 )
{
result = (unsigned int)(3 * result);
StageTime = result;
}
else if ( v1 > 19 )
{
if ( v1 > 39 )
result = (unsigned int)(7 * result) / 0xAuLL;
StageTime = result;
}
else
{
result = (unsigned int)(2 * result);
StageTime = result;
}
}
else
{
result = (unsigned int)(4 * result);
StageTime = result;
}
}
else
{
result = (unsigned int)(12 * result);
StageTime = result;
}
}
else
{
result = (unsigned int)(17 * result);
StageTime = result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int8 a1)
{
__int16 v1; // dx
unsigned __int64 result; // rax

v1 = epd_get_temperature();
result = (unsigned __int16)COG_Parameters[10 * a1 + 9];
if ( v1 >= -10 )
{
if ( v1 >= -5 )
{
if ( v1 <= 4 )
{
result = (unsigned int)(8 * result);
StageTime = result;
}
else if ( v1 > 9 )
{
if ( v1 <= 14 )
{
result = (unsigned int)(3 * result);
StageTime = result;
}
else if ( v1 > 19 )
{
if ( v1 > 39 )
result = (unsigned int)(7 * result) / 0xAuLL;
StageTime = result;
}
else
{
result = (unsigned int)(2 * result);
StageTime = result;
}
}
else
{
result = (unsigned int)(4 * result);
StageTime = result;
}
}
else
{
result = (unsigned int)(12 * result);
StageTime = result;
}
}
else
{
result = (unsigned int)(17 * result);
StageTime = result;
}
return result;
}

original_code:
static void SetTemperature_Factor(uint8_t EPD_Type_Index)
{
 int16_t Temperature;
 Temperature = epd_get_temperature();
 if (Temperature < -10)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 17;
 }
 else if (Temperature < -5)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 12;
 }
 else if (Temperature < 5)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 8;
 }
 else if (Temperature < 10)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 4;
 }
 else if (Temperature < 15)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 3;
 }
 else if (Temperature < 20)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 2;
 }
 else if (Temperature < 40)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 1;
 }
 else
 {
  StageTime = (COG_Parameters[EPD_Type_Index].StageTime * 7)/10;
 }
}

canonical_original_code:
static void SetTemperature_Factor(unsigned char EPD_Type_Index)
{
 short Temperature;
 Temperature = epd_get_temperature();
 if (Temperature < -10)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 17;
 }
 else if (Temperature < -5)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 12;
 }
 else if (Temperature < 5)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 8;
 }
 else if (Temperature < 10)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 4;
 }
 else if (Temperature < 15)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 3;
 }
 else if (Temperature < 20)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 2;
 }
 else if (Temperature < 40)
 {
  StageTime = COG_Parameters[EPD_Type_Index].StageTime * 1;
 }
 else
 {
  StageTime = (COG_Parameters[EPD_Type_Index].StageTime * 7)/10;
 }
}

variable_types: Temperature short


decompiled_code:
__int64 __fastcall Display_Stage_1(__int64 a1)
{
int v1; // ebp
__int64 v2; // rax
__int64 v3; // r12
char v4; // bl
unsigned __int16 i; // r13
__int64 v6; // r11
unsigned __int16 v7; // di
_BYTE *v8; // r10
_BYTE *v9; // r9
__int64 v10; // rcx
char v11; // dl
__int64 v12; // rsi
unsigned __int16 v13; // r14
int v14; // eax
int v15; // er8
__int64 result; // rax

Currentframe = (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 8];
DisplayOrgPtr = a1;
cnt = 0;
v1 = (unsigned __int16)epd_GetCurrentTimeTick();
v2 = (unsigned __int16)EPD_Type_Index;
do
{
v3 = DisplayOrgPtr;
if ( COG_Parameters[10 * v2 + 6] )
{
v4 = -64;
for ( i = 0; ; v4 = ScanTable[i & 3] )
{
epd_SPI_Send_Byte(4LL, LOBYTE(COG_Parameters[10 * v2 + 4]));
v6 = (unsigned __int16)EPD_Type_Index;
v7 = COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 5];
if ( v7 )
{
v8 = DataLineOdd;
v9 = DataLineEven;
v10 = 0LL;
do
{
v11 = *(_BYTE *)(v3 + v10);
v12 = (unsigned __int16)(v7 - 1 - v10);
v8[v10++] = (((v11 & 2) != 0) + 2) | ((v11 & 8) == 0 ? 8 : 12) | ((v11 & 0x20) == 0 ? 32 : 48) | (((v11 >> 7) & 0x40) + 0x80);
v9[v12] = (((v11 & 0x40) != 0) + 2) | ((v11 & 0x10) == 0 ? 8 : 12) | ((v11 & 4) == 0 ? 32 : 48) | ((v11 & 1) == 0 ? 0x80 : -64);
}
while ( v7 > (unsigned __int16)v10 );
v3 += v7;
}
v13 = i++ >> 2;
*(_BYTE *)(DataLineScan + v13) = v4;
epd_SPI_Send(10LL, &COG_Line, LOBYTE(COG_Parameters[10 * v6 + 7]));
epd_SPI_Send_Byte(2LL, 47LL);
*(_BYTE *)(DataLineScan + v13) = 0;
v2 = (unsigned __int16)EPD_Type_Index;
if ( (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 6] <= i )
break;
}
}
if ( COG_Parameters[10 * v2 + 8] )
{
while ( (unsigned int)epd_GetCurrentTimeTick() - v1 < Currentframe
&& (unsigned int)epd_GetCurrentTimeTick() - v1 < Currentframe )
;
}
v14 = epd_GetCurrentTimeTick();
++cnt;
v15 = v14;
v2 = (unsigned __int16)EPD_Type_Index;
Currentframe = v15 + (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 8] - v1;
}
while ( Currentframe < (unsigned int)StageTime );
do
result = (unsigned int)epd_GetCurrentTimeTick() - v1;
while ( (unsigned int)result < StageTime );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // ebp
__int64 v2; // rax
__int64 v3; // r12
char v4; // bl
unsigned __int16 i; // r13
__int64 v6; // r11
unsigned __int16 v7; // di
_BYTE *v8; // r10
_BYTE *v9; // r9
__int64 v10; // rcx
char v11; // dl
__int64 v12; // rsi
unsigned __int16 v13; // r14
int v14; // eax
int v15; // er8
__int64 result; // rax

Currentframe = (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 8];
DisplayOrgPtr = a1;
cnt = 0;
v1 = (unsigned __int16)epd_GetCurrentTimeTick();
v2 = (unsigned __int16)EPD_Type_Index;
do
{
v3 = DisplayOrgPtr;
if ( COG_Parameters[10 * v2 + 6] )
{
v4 = -64;
for ( i = 0; ; v4 = ScanTable[i & 3] )
{
epd_SPI_Send_Byte(4LL, LOBYTE(COG_Parameters[10 * v2 + 4]));
v6 = (unsigned __int16)EPD_Type_Index;
v7 = COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 5];
if ( v7 )
{
v8 = DataLineOdd;
v9 = DataLineEven;
v10 = 0LL;
do
{
v11 = *(_BYTE *)(v3 + v10);
v12 = (unsigned __int16)(v7 - 1 - v10);
v8[v10++] = (((v11 & 2) != 0) + 2) | ((v11 & 8) == 0 ? 8 : 12) | ((v11 & 0x20) == 0 ? 32 : 48) | (((v11 >> 7) & 0x40) + 0x80);
v9[v12] = (((v11 & 0x40) != 0) + 2) | ((v11 & 0x10) == 0 ? 8 : 12) | ((v11 & 4) == 0 ? 32 : 48) | ((v11 & 1) == 0 ? 0x80 : -64);
}
while ( v7 > (unsigned __int16)v10 );
v3 += v7;
}
v13 = i++ >> 2;
*(_BYTE *)(DataLineScan + v13) = v4;
epd_SPI_Send(10LL, &COG_Line, LOBYTE(COG_Parameters[10 * v6 + 7]));
epd_SPI_Send_Byte(2LL, 47LL);
*(_BYTE *)(DataLineScan + v13) = 0;
v2 = (unsigned __int16)EPD_Type_Index;
if ( (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 6] <= i )
break;
}
}
if ( COG_Parameters[10 * v2 + 8] )
{
while ( (unsigned int)epd_GetCurrentTimeTick() - v1 < Currentframe
&& (unsigned int)epd_GetCurrentTimeTick() - v1 < Currentframe )
;
}
v14 = epd_GetCurrentTimeTick();
++cnt;
v15 = v14;
v2 = (unsigned __int16)EPD_Type_Index;
Currentframe = v15 + (unsigned __int16)COG_Parameters[10 * (unsigned __int16)EPD_Type_Index + 8] - v1;
}
while ( Currentframe < (unsigned int)StageTime );
do
result = (unsigned int)epd_GetCurrentTimeTick() - v1;
while ( (unsigned int)result < StageTime );
return result;
}

original_code:
static void Display_Stage_1 (uint8_t *PreviousPicture)
{
 uint16_t i,j,k;
 uint8_t TempByte;
 uint16_t StartClock;
    DisplayOrgPtr = PreviousPicture;
 Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime;
 cnt = 0;
 StartClock = epd_GetCurrentTimeTick();
 do
 {
     PreviousPicture = DisplayOrgPtr;
  for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++)
  {
         epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel);
         k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1;
   for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++)
   {
    TempByte = (*PreviousPicture++);
    DataLineOdd[j] = ((TempByte & 0x80) ? (0xc0) : (0x80))
         | ((TempByte & 0x20) ? (0x30) : (0x20))
         | ((TempByte & 0x08) ? (0x0C) : (0x08))
         | ((TempByte & 0x02) ? (0x03) : (0x02));
    DataLineEven[k--] = ((TempByte & 0x01) ? (0xc0) : (0x80))
         | ((TempByte & 0x04) ? (0x30) : (0x20))
         | ((TempByte & 0x10) ? (0x0C) : (0x08))
         | ((TempByte & 0x40) ? (0x03) : (0x02));
   }
   DataLineScan[(i>>2)] = ScanTable[(i%4)];
   epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
   epd_SPI_Send_Byte(0x02, 0x2F);
   DataLineScan[(i>>2)] = 0;
  }
  if(COG_Parameters[EPD_Type_Index].FrameTime>0)
  {
   while(Currentframe>(epd_GetCurrentTimeTick() - StartClock));
  }
  Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ;
  cnt++;
 }while (StageTime>Currentframe);
 while(StageTime>(epd_GetCurrentTimeTick() - StartClock));
}

canonical_original_code:
static void Display_Stage_1(unsigned char *PreviousPicture)
{
 unsigned short i; unsigned short j; unsigned short k;
 unsigned char TempByte;
 unsigned short StartClock;
    DisplayOrgPtr = PreviousPicture;
 Currentframe = (unsigned int)COG_Parameters[EPD_Type_Index].FrameTime;
 cnt = 0;
 StartClock = epd_GetCurrentTimeTick();
 do
 {
     PreviousPicture = DisplayOrgPtr;
  for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++)
  {
         epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel);
         k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1;
   for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++)
   {
    TempByte = (*PreviousPicture++);
    DataLineOdd[j] = ((TempByte & 0x80) ? (0xc0) : (0x80))
         | ((TempByte & 0x20) ? (0x30) : (0x20))
         | ((TempByte & 0x08) ? (0x0C) : (0x08))
         | ((TempByte & 0x02) ? (0x03) : (0x02));
    DataLineEven[k--] = ((TempByte & 0x01) ? (0xc0) : (0x80))
         | ((TempByte & 0x04) ? (0x30) : (0x20))
         | ((TempByte & 0x10) ? (0x0C) : (0x08))
         | ((TempByte & 0x40) ? (0x03) : (0x02));
   }
   DataLineScan[(i>>2)] = ScanTable[(i%4)];
   epd_SPI_Send(0x0a, (unsigned char *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
   epd_SPI_Send_Byte(0x02, 0x2F);
   DataLineScan[(i>>2)] = 0;
  }
  if(COG_Parameters[EPD_Type_Index].FrameTime>0)
  {
   while(Currentframe>(epd_GetCurrentTimeTick() - StartClock));
  }
  Currentframe=(unsigned int)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ;
  cnt++;
 }while (StageTime>Currentframe);
 while(StageTime>(epd_GetCurrentTimeTick() - StartClock));
}

variable_types:
PreviousPicture
unsigned char *

variable_types:
j
unsigned short

variable_types:
k
unsigned short

variable_types:
TempByte
unsigned char

variable_types:
StartClock
unsigned short