decompiled_code:
void __fastcall MIPS_free_list(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
MIPS_free_instr(v1);
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 7);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
MIPS_free_instr(v1);
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 7);
free(v2);
}
}

original_code:
void MIPS_free_list(MIPS_list* codes)
{
    while (codes != ((void *)0))
    {
        MIPS_free_instr(&codes->instr);
        MIPS_list* tmp = codes;
        codes = codes->next;
        free(tmp);
    }
}

canonical_original_code:
void MIPS_free_list(struct MIPS_list *codes)
{
    while (codes != ((void *)0))
    {
        MIPS_free_instr(&codes->instr);
        struct MIPS_list *tmp = codes;
        codes = codes->next;
        free(tmp);
    }
}

user_defined_types: enum MIPS_opcode { MIPS_add=0, MIPS_sub=1, MIPS_addi=2, MIPS_mult=3, MIPS_div=4, MIPS_lw=5, MIPS_lb=6, MIPS_sw=7, MIPS_sb=8, MIPS_mfhi=9, MIPS_mflo=10, MIPS_and=11, MIPS_andi=12, MIPS_or=13, MIPS_ori=14, MIPS_slt=15, MIPS_slti=16, MIPS_bgt=17, MIPS_bge=18, MIPS_blt=19, MIPS_ble=20, MIPS_sll=21, MIPS_srl=22, MIPS_beq=23, MIPS_bne=24, MIPS_jal=25, MIPS_jr=26, MIPS_b=27, MIPS_la=28, MIPS_li=29 }

user_defined_types: enum MIPS_operand_type { MIPS_OPERAND_NONE=0, MIPS_REG=1, MIPS_IMM_32=2, MIPS_IMM_8=3, MIPS_OFFSET=4, MIPS_SYMBOL=5 }


repo: marcinlos/cmm-compiler

decompiled_code:
__int64 __fastcall out_data(__int64 a1)
{
int v1; // eax
char *v3; // rbx
char v4[128]; // [rsp+0h] [rbp-108h] BYREF
char s[136]; // [rsp+80h] [rbp-88h] BYREF

sprintf(s, "%s:\t\t", *(const char **)(a1 + 8));
v1 = *(_DWORD *)(a1 + 16);
if ( v1 )
{
if ( v1 == 1 )
{
v3 = (char *)escape_alloc(*(_QWORD *)(a1 + 24));
sprintf(v4, ".ascii \"%s\"", v3);
free(v3);
strcat(s, v4);
}
}
else
{
sprintf(v4, ".space %d", *(unsigned int *)(a1 + 24));
strcat(s, v4);
}
return single_line(s);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
char *v3; // rbx
char v4[128]; // [rsp+0h] [rbp-108h] BYREF
char s[136]; // [rsp+80h] [rbp-88h] BYREF

sprintf(s, "%s:\t\t", *(const char **)(a1 + 8));
v1 = *(_DWORD *)(a1 + 16);
if ( v1 )
{
if ( v1 == 1 )
{
v3 = (char *)escape_alloc(*(_QWORD *)(a1 + 24));
sprintf(v4, ".ascii \"%s\"", v3);
free(v3);
strcat(s, v4);
}
}
else
{
sprintf(v4, ".space %d", *(unsigned int *)(a1 + 24));
strcat(s, v4);
}
return single_line(s);
}

original_code:
static line_list* out_data(ir_item* item)
{
    char buffer[128];
    char data[128];
    sprintf(buffer, "%s:\t\t", item->name);
    switch (item->data_type)
    {
    case DATA_RAW:
        sprintf(data, ".space %d", item->bytes);
        strcat(buffer, data);
        break;
    case DATA_STRING:
    {
        char* escaped = escape_alloc(item->text);
        sprintf(data, ".ascii \"%s\"", escaped);
        free(escaped);
        strcat(buffer, data);
        break;
    }
    }
    return single_line(buffer);
}

canonical_original_code:
static struct line_list *out_data(struct ir_item *item)
{
    char buffer[128];
    char data[128];
    sprintf(buffer, "%s:\t\t", item->name);
    switch (item->data_type)
    {
    case DATA_RAW:
        sprintf(data, ".space %d", item->bytes);
        strcat(buffer, data);
        break;
    case DATA_STRING:
    {
        char *escaped = escape_alloc(item->text);
        sprintf(data, ".ascii \"%s\"", escaped);
        free(escaped);
        strcat(buffer, data);
        break;
    }
    }
    return single_line(buffer);
}

variable_types: struct ir_item { enum ir_type { IR_EMPTY=0, IR_DATA=1, IR_BINOP=2, IR_UNOP=3, IR_COPY=4, IR_GOTO=5, IR_BRANCH=6, IR_LABEL=7, IR_LIDX=8, IR_RIDX=9, IR_ADDR=10, IR_LDEREF=11, IR_RDEREF=12, IR_ENTER=13, IR_LEAVE=14, IR_PARAM=15, IR_CALL=16, IR_RET=17, IR_RET_VAL=18, IR_RETRIEVE=19 } type; union { struct { struct address { enum addr_type { ADDR_EMPTY=0, ADDR_SYMBOL=1, ADDR_SYMBOL_NAME=2, ADDR_IMM_INT=3, ADDR_IMM_CHAR=4, ADDR_IMM_STRING=5 } type; union { int integer; char character; char *string; struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *symbol; char *symbol_name; }; } x; union { enum ir_binop { IR_PLUS=0, IR_MINUS=1, IR_TIMES=2, IR_DIV=3, IR_AND=4, IR_OR=5 } binop; enum ir_unop { IR_NEG=0 } unop; enum ir_relop { IR_EQ=0, IR_NEQ=1, IR_GT=2, IR_GTE=3, IR_LT=4, IR_LTE=5 } relop; }; }; struct { char *name; enum ir_data { DATA_RAW=0, DATA_STRING=1 } data_type; union { int bytes; char *text; }; }; struct { char *label; int offset; }; }; } *

variable_types:
buffer
char [128]

variable_types:
data
char [128]

variable_types:
escaped
char *

return_type: struct line_list { char *line; struct line_list *next; } *

user_defined_types: struct ir_item { enum ir_type type; union { struct { struct address x; union { enum ir_binop binop; enum ir_unop unop; enum ir_relop relop; }; }; struct { char *name; enum ir_data data_type; union { int bytes; char *text; }; }; struct { char *label; int offset; }; }; }

user_defined_types: struct address { enum addr_type type; union { int integer; char character; char *string; struct symbol_info *symbol; char *symbol_name; }; }

user_defined_types: struct symbol_info { enum symbol_type symbol_type; char *name; struct scope_info *scope; union { struct { struct type var_type; struct codegen_info codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; }

user_defined_types: struct type { enum basic_type type; int elements; }

user_defined_types: struct codegen_info { enum storage_type storage; int size; union { int reg; int offset; }; }


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

result = (unsigned int)*a1;
switch ( *a1 )
{
case 2:
result = MIPS_make_binop();
break;
case 3:
result = MIPS_make_unop();
break;
case 4:
result = MIPS_make_copy();
break;
case 5:
result = MIPS_make_goto();
break;
case 6:
result = MIPS_make_branch();
break;
case 8:
result = MIPS_make_lidx();
break;
case 9:
result = MIPS_make_ridx();
break;
case 0xA:
result = MIPS_make_addr();
break;
case 0xB:
result = MIPS_make_lderef();
break;
case 0xC:
result = MIPS_make_rderef();
break;
case 0xD:
result = MIPS_make_enter();
break;
case 0xE:
result = MIPS_make_leave();
break;
case 0xF:
result = MIPS_make_param();
break;
case 0x10:
result = MIPS_make_call();
break;
case 0x11:
result = MIPS_make_ret();
break;
case 0x12:
result = MIPS_make_ret_val();
break;
case 0x13:
result = MIPS_make_retrieve();
break;
default:
return result;
}
return result;
}

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

result = (unsigned int)*a1;
switch ( *a1 )
{
case 2:
result = MIPS_make_binop();
break;
case 3:
result = MIPS_make_unop();
break;
case 4:
result = MIPS_make_copy();
break;
case 5:
result = MIPS_make_goto();
break;
case 6:
result = MIPS_make_branch();
break;
case 8:
result = MIPS_make_lidx();
break;
case 9:
result = MIPS_make_ridx();
break;
case 0xA:
result = MIPS_make_addr();
break;
case 0xB:
result = MIPS_make_lderef();
break;
case 0xC:
result = MIPS_make_rderef();
break;
case 0xD:
result = MIPS_make_enter();
break;
case 0xE:
result = MIPS_make_leave();
break;
case 0xF:
result = MIPS_make_param();
break;
case 0x10:
result = MIPS_make_call();
break;
case 0x11:
result = MIPS_make_ret();
break;
case 0x12:
result = MIPS_make_ret_val();
break;
case 0x13:
result = MIPS_make_retrieve();
break;
default:
return result;
}
return result;
}

original_code:
static MIPS_list* MIPS_translate(ir_item* item)
{
    switch (item->type)
    {
    case IR_BINOP: return MIPS_make_binop(item);
    case IR_UNOP: return MIPS_make_unop(item);
    case IR_COPY: return MIPS_make_copy(item);
    case IR_GOTO: return MIPS_make_goto(item);
    case IR_BRANCH: return MIPS_make_branch(item);
    case IR_LIDX: return MIPS_make_lidx(item);
    case IR_RIDX: return MIPS_make_ridx(item);
    case IR_ADDR: return MIPS_make_addr(item);
    case IR_LDEREF: return MIPS_make_lderef(item);
    case IR_RDEREF: return MIPS_make_rderef(item);
    case IR_ENTER: return MIPS_make_enter(item);
    case IR_LEAVE: return MIPS_make_leave(item);
    case IR_PARAM: return MIPS_make_param(item);
    case IR_CALL: return MIPS_make_call(item);
    case IR_RET: return MIPS_make_ret(item);
    case IR_RET_VAL: return MIPS_make_ret_val(item);
    case IR_RETRIEVE: return MIPS_make_retrieve(item);
    }
}

canonical_original_code:
static struct MIPS_list *MIPS_translate(struct ir_item *item)
{
    switch (item->type)
    {
    case IR_BINOP: return MIPS_make_binop(item);
    case IR_UNOP: return MIPS_make_unop(item);
    case IR_COPY: return MIPS_make_copy(item);
    case IR_GOTO: return MIPS_make_goto(item);
    case IR_BRANCH: return MIPS_make_branch(item);
    case IR_LIDX: return MIPS_make_lidx(item);
    case IR_RIDX: return MIPS_make_ridx(item);
    case IR_ADDR: return MIPS_make_addr(item);
    case IR_LDEREF: return MIPS_make_lderef(item);
    case IR_RDEREF: return MIPS_make_rderef(item);
    case IR_ENTER: return MIPS_make_enter(item);
    case IR_LEAVE: return MIPS_make_leave(item);
    case IR_PARAM: return MIPS_make_param(item);
    case IR_CALL: return MIPS_make_call(item);
    case IR_RET: return MIPS_make_ret(item);
    case IR_RET_VAL: return MIPS_make_ret_val(item);
    case IR_RETRIEVE: return MIPS_make_retrieve(item);
    }
}

return_type: struct MIPS_list { struct MIPS_instruction { enum MIPS_opcode { MIPS_add=0, MIPS_sub=1, MIPS_addi=2, MIPS_mult=3, MIPS_div=4, MIPS_lw=5, MIPS_lb=6, MIPS_sw=7, MIPS_sb=8, MIPS_mfhi=9, MIPS_mflo=10, MIPS_and=11, MIPS_andi=12, MIPS_or=13, MIPS_ori=14, MIPS_slt=15, MIPS_slti=16, MIPS_bgt=17, MIPS_bge=18, MIPS_blt=19, MIPS_ble=20, MIPS_sll=21, MIPS_srl=22, MIPS_beq=23, MIPS_bne=24, MIPS_jal=25, MIPS_jr=26, MIPS_b=27, MIPS_la=28, MIPS_li=29 } opcode; struct MIPS_operand { enum MIPS_operand_type { MIPS_OPERAND_NONE=0, MIPS_REG=1, MIPS_IMM_32=2, MIPS_IMM_8=3, MIPS_OFFSET=4, MIPS_SYMBOL=5 } type; union { int reg; int imm32; char imm8; int offset; char *symbol; }; } x; } instr; struct MIPS_list *next; } *

user_defined_types: struct MIPS_list { struct MIPS_instruction instr; struct MIPS_list *next; }

user_defined_types: enum ir_type { IR_EMPTY=0, IR_DATA=1, IR_BINOP=2, IR_UNOP=3, IR_COPY=4, IR_GOTO=5, IR_BRANCH=6, IR_LABEL=7, IR_LIDX=8, IR_RIDX=9, IR_ADDR=10, IR_LDEREF=11, IR_RDEREF=12, IR_ENTER=13, IR_LEAVE=14, IR_PARAM=15, IR_CALL=16, IR_RET=17, IR_RET_VAL=18, IR_RETRIEVE=19 }

user_defined_types: struct MIPS_instruction { enum MIPS_opcode opcode; struct MIPS_operand x; }

user_defined_types: struct MIPS_operand { enum MIPS_operand_type type; union { int reg; int imm32; char imm8; int offset; char *symbol; }; }

user_defined_types: enum ir_data { DATA_RAW=0, DATA_STRING=1 }

user_defined_types: enum addr_type { ADDR_EMPTY=0, ADDR_SYMBOL=1, ADDR_SYMBOL_NAME=2, ADDR_IMM_INT=3, ADDR_IMM_CHAR=4, ADDR_IMM_STRING=5 }

user_defined_types: enum ir_binop { IR_PLUS=0, IR_MINUS=1, IR_TIMES=2, IR_DIV=3, IR_AND=4, IR_OR=5 }

user_defined_types: enum ir_relop { IR_EQ=0, IR_NEQ=1, IR_GT=2, IR_GTE=3, IR_LT=4, IR_LTE=5 }

user_defined_types: enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 }

user_defined_types: struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; }

user_defined_types: enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 }

user_defined_types: enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 }


original_code:
line_list* ir_output(ir_item item)
{
    switch (item.type)
    {
    case IR_EMPTY: return ((void *)0);
    case IR_DATA: return out_data(&item);
    case IR_LABEL: return out_label(&item);
    }
    MIPS_list* list = MIPS_translate(&item), *mp = list;
    line_list* lines = ((void *)0), *end = lines;
    char buffer[128];
    while (mp != ((void *)0))
    {
        MIPS_write_instr(buffer, mp->instr);
        end = append_line(end, buffer);
        if (lines == ((void *)0))
            lines = end;
        mp = mp->next;
    }
    MIPS_free_list(list);
    return lines;
}

canonical_original_code:
struct line_list *ir_output(struct ir_item item)
{
    switch (item.type)
    {
    case IR_EMPTY: return ((void *)0);
    case IR_DATA: return out_data(&item);
    case IR_LABEL: return out_label(&item);
    }
    struct MIPS_list *list = MIPS_translate(&item); struct MIPS_list *mp = list;
    struct line_list *lines = ((void *)0); struct line_list *end = lines;
    char buffer[128];
    while (mp != ((void *)0))
    {
        MIPS_write_instr(buffer, mp->instr);
        end = append_line(end, buffer);
        if (lines == ((void *)0))
            lines = end;
        mp = mp->next;
    }
    MIPS_free_list(list);
    return lines;
}

variable_types: struct ir_item { enum ir_type { IR_EMPTY=0, IR_DATA=1, IR_BINOP=2, IR_UNOP=3, IR_COPY=4, IR_GOTO=5, IR_BRANCH=6, IR_LABEL=7, IR_LIDX=8, IR_RIDX=9, IR_ADDR=10, IR_LDEREF=11, IR_RDEREF=12, IR_ENTER=13, IR_LEAVE=14, IR_PARAM=15, IR_CALL=16, IR_RET=17, IR_RET_VAL=18, IR_RETRIEVE=19 } type; union { struct { struct address { enum addr_type { ADDR_EMPTY=0, ADDR_SYMBOL=1, ADDR_SYMBOL_NAME=2, ADDR_IMM_INT=3, ADDR_IMM_CHAR=4, ADDR_IMM_STRING=5 } type; union { int integer; char character; char *string; struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *symbol; char *symbol_name; }; } x; union { enum ir_binop { IR_PLUS=0, IR_MINUS=1, IR_TIMES=2, IR_DIV=3, IR_AND=4, IR_OR=5 } binop; enum ir_unop { IR_NEG=0 } unop; enum ir_relop { IR_EQ=0, IR_NEQ=1, IR_GT=2, IR_GTE=3, IR_LT=4, IR_LTE=5 } relop; }; }; struct { char *name; enum ir_data { DATA_RAW=0, DATA_STRING=1 } data_type; union { int bytes; char *text; }; }; struct { char *label; int offset; }; }; }

variable_types: struct MIPS_list { struct MIPS_instruction { enum MIPS_opcode { MIPS_add=0, MIPS_sub=1, MIPS_addi=2, MIPS_mult=3, MIPS_div=4, MIPS_lw=5, MIPS_lb=6, MIPS_sw=7, MIPS_sb=8, MIPS_mfhi=9, MIPS_mflo=10, MIPS_and=11, MIPS_andi=12, MIPS_or=13, MIPS_ori=14, MIPS_slt=15, MIPS_slti=16, MIPS_bgt=17, MIPS_bge=18, MIPS_blt=19, MIPS_ble=20, MIPS_sll=21, MIPS_srl=22, MIPS_beq=23, MIPS_bne=24, MIPS_jal=25, MIPS_jr=26, MIPS_b=27, MIPS_la=28, MIPS_li=29 } opcode; struct MIPS_operand { enum MIPS_operand_type { MIPS_OPERAND_NONE=0, MIPS_REG=1, MIPS_IMM_32=2, MIPS_IMM_8=3, MIPS_OFFSET=4, MIPS_SYMBOL=5 } type; union { int reg; int imm32; char imm8; int offset; char *symbol; }; } x; } instr; struct MIPS_list *next; } *

variable_types: struct line_list { char *line; struct line_list *next; } *

user_defined_types: struct ir_item { enum ir_type type; union { struct { struct address x; union { enum ir_binop binop; enum ir_unop unop; enum ir_relop relop; }; }; struct { char *name; enum ir_data data_type; union { int bytes; char *text; }; }; struct { char *label; int offset; }; }; }


decompiled_code:
const char *__fastcall basic_type_string(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "void";
break;
case 1:
case 3:
result = "int";
break;
case 2:
case 4:
result = "char";
break;
default:
_assert_fail("0 && \"basic_type_string: invalid basic type\"", "types.c", 0x24u, "basic_type_string");
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "void";
break;
case 1:
case 3:
result = "int";
break;
case 2:
case 4:
result = "char";
break;
default:
_assert_fail("0 && \"basic_type_string: invalid basic type\"", "types.c", 0x24u, "basic_type_string");
}
return result;
}

original_code:
static const char* basic_type_string(basic_type b)
{
    switch (b)
    {
    case T_VOID:
        return "void";
    case T_INT:
    case T_INT_ARRAY:
        return "int";
    case T_CHAR:
    case T_CHAR_ARRAY:
        return "char";
    default:
        ((void) sizeof ((0 && "basic_type_string: invalid basic type") ? 1 : 0), __extension__ ({ if (0 && "basic_type_string: invalid basic type") ; else __assert_fail ("0 && \"basic_type_string: invalid basic type\"", "types.c", 36, __extension__ __PRETTY_FUNCTION__); }));
        return ((void *)0);
    }
}

canonical_original_code:
static char *basic_type_string(enum basic_type b)
{
    switch (b)
    {
    case T_VOID:
        return "void";
    case T_INT:
    case T_INT_ARRAY:
        return "int";
    case T_CHAR:
    case T_CHAR_ARRAY:
        return "char";
    default:
        ((void) sizeof ((0 && "basic_type_string: invalid basic type") ? 1 : 0), __extension__ ({ if (0 && "basic_type_string: invalid basic type") ; else __assert_fail ("0 && \"basic_type_string: invalid basic type\"", "types.c", 36, __extension__ __PRETTY_FUNCTION__); }));
        return ((void *)0);
    }
}

variable_types: enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 }

return_type: char *


decompiled_code:
__int64 __fastcall type_from_ast(int a1)
{
char v1; // al

v1 = 2;
if ( a1 != 1 )
{
if ( a1 == 2 )
{
v1 = 0;
}
else if ( !a1 )
{
v1 = 1;
}
}
return v1 & 3;
}

original_code:
type type_from_ast(value_type t)
{
    basic_type basic;
    switch (t)
    {
    case TYPE_VOID: basic = T_VOID; break;
    case TYPE_INT: basic = T_INT; break;
    case TYPE_CHAR: basic = T_CHAR; break;
    }
    type tt;
    tt.type = basic;
    return tt;
}

canonical_original_code:
struct type type_from_ast(enum value_type t)
{
    enum basic_type basic;
    switch (t)
    {
    case TYPE_VOID: basic = T_VOID; break;
    case TYPE_INT: basic = T_INT; break;
    case TYPE_CHAR: basic = T_CHAR; break;
    }
    struct type tt;
    tt.type = basic;
    return tt;
}

variable_types: enum value_type { TYPE_INT=0, TYPE_CHAR=1, TYPE_VOID=2 }

variable_types: struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; }


decompiled_code:
_BOOL8 __fastcall type_is_array(int a1)
{
return (unsigned int)(a1 - 3) <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
return (unsigned int)(a1 - 3) <= 1;
}

original_code:
int type_is_array(type t)
{
    return t.type == T_INT_ARRAY || t.type == T_CHAR_ARRAY;
}

canonical_original_code:
int type_is_array(struct type t)
{
    return t.type == T_INT_ARRAY || t.type == T_CHAR_ARRAY;
}

return_type: int


decompiled_code:
__int64 __fastcall type_print(char *s, __int64 a2)
{
const char *v2; // rax
char *v3; // rbx

v2 = basic_type_string(a2);
v3 = &s[sprintf(s, "%s", v2)];
if ( type_is_array(a2) )
v3 += sprintf(v3, "[%d]", a2 >> 32);
return v3 - s;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, __int64 a2)
{
const char *v2; // rax
char *v3; // rbx

v2 = func0(a2);
v3 = &s[sprintf(s, "%s", v2)];
if ( func2(a2) )
v3 += sprintf(v3, "[%d]", a2 >> 32);
return v3 - s;
}

original_code:
int type_print(char* buffer, type t)
{
    const char* b = basic_type_string(t.type);
    char* p = buffer;
    p += sprintf(buffer, "%s", b);
    if (type_is_array(t))
    {
        p += sprintf(p, "[%d]", t.elements);
    }
    return p - buffer;
}

canonical_original_code:
int type_print(char *buffer, struct type t)
{
    char *b = basic_type_string(t.type);
    char *p = buffer;
    p += sprintf(buffer, "%s", b);
    if (type_is_array(t))
    {
        p += sprintf(p, "[%d]", t.elements);
    }
    return p - buffer;
}

variable_types:
buffer
char *

variable_types:
b
char *

variable_types:
p
char *


decompiled_code:
_QWORD *ir_empty_list()
{
_QWORD *result; // rax

result = malloc(0x48uLL);
result[8] = 0LL;
return result;
}

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

result = malloc(0x48uLL);
result[8] = 0LL;
return result;
}

original_code:
ir_list* ir_empty_list(void)
{
    ir_list* node = malloc(sizeof(ir_list));
    node->next = ((void *)0);
    return node;
}

canonical_original_code:
struct ir_list *ir_empty_list()
{
    struct ir_list *node = malloc(sizeof(ir_list));
    node->next = ((void *)0);
    return node;
}

variable_types: struct ir_list { struct ir_item { enum ir_type { IR_EMPTY=0, IR_DATA=1, IR_BINOP=2, IR_UNOP=3, IR_COPY=4, IR_GOTO=5, IR_BRANCH=6, IR_LABEL=7, IR_LIDX=8, IR_RIDX=9, IR_ADDR=10, IR_LDEREF=11, IR_RDEREF=12, IR_ENTER=13, IR_LEAVE=14, IR_PARAM=15, IR_CALL=16, IR_RET=17, IR_RET_VAL=18, IR_RETRIEVE=19 } type; union { struct { struct address { enum addr_type { ADDR_EMPTY=0, ADDR_SYMBOL=1, ADDR_SYMBOL_NAME=2, ADDR_IMM_INT=3, ADDR_IMM_CHAR=4, ADDR_IMM_STRING=5 } type; union { int integer; char character; char *string; struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *symbol; char *symbol_name; }; } x; union { enum ir_binop { IR_PLUS=0, IR_MINUS=1, IR_TIMES=2, IR_DIV=3, IR_AND=4, IR_OR=5 } binop; enum ir_unop { IR_NEG=0 } unop; enum ir_relop { IR_EQ=0, IR_NEQ=1, IR_GT=2, IR_GTE=3, IR_LT=4, IR_LTE=5 } relop; }; }; struct { char *name; enum ir_data { DATA_RAW=0, DATA_STRING=1 } data_type; union { int bytes; char *text; }; }; struct { char *label; int offset; }; }; } item; struct ir_list *next; } *

user_defined_types: struct ir_list { struct ir_item item; struct ir_list *next; }

user_defined_types: struct address { enum addr_type type; union { int integer; char character; char *string; struct symbol_info *symbol; char *symbol_name; }; }


decompiled_code:
void __fastcall ir_free_list(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
ir_free_item(v1);
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 8);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
ir_free_item(v1);
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 8);
free(v2);
}
}

original_code:
void ir_free_list(ir_list* codes)
{
    while (codes != ((void *)0))
    {
        ir_free_item(&codes->item);
        ir_list* tmp = codes;
        codes = codes->next;
        free(tmp);
    }
}

canonical_original_code:
void ir_free_list(struct ir_list *codes)
{
    while (codes != ((void *)0))
    {
        ir_free_item(&codes->item);
        struct ir_list *tmp = codes;
        codes = codes->next;
        free(tmp);
    }
}

return_type: void

user_defined_types: struct symbol_info { enum symbol_type symbol_type; char *name; struct scope_info *scope; union { struct { struct type var_type; struct codegen_info codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; }

user_defined_types: struct type { enum basic_type type; int elements; }


consumer

repo: marciso/bqueue-code

decompiled_code:
void *__fastcall consumer(void *a1)
{
unsigned int v1; // ebp
pthread_barrier_t *v2; // r12
unsigned int v3; // er14
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // rdx
__int64 v8; // rdx
cpu_set_t v10; // [rsp+0h] [rbp-B8h] BYREF
char v11[48]; // [rsp+88h] [rbp-30h] BYREF

v1 = *(_DWORD *)a1;
v2 = (pthread_barrier_t *)*((_QWORD *)a1 + 1);
v3 = *((_DWORD *)a1 + 4);
memset(&v10, 0, sizeof(v10));
if ( v1 <= 0x3FF )
v10.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
printf("consumer %d: ---%d----\n", v1, 2 * v1);
if ( sched_setaffinity(0, 0x80uLL, &v10) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
puts("Consumer created...");
pthread_barrier_wait(v2);
qword_880[8216 * v1] = read_tsc();
v4 = 200000000LL;
do
{
while ( (unsigned int)dequeue((char *)&queues + 65728 * v1, v11) )
;
--v4;
}
while ( v4 );
v5 = read_tsc();
v6 = 8216LL * v1;
qword_888[v6] = v5;
v7 = (0x5798EE063611088DLL * (unsigned __int128)(unsigned __int64)(v5 - qword_880[v6])) >> 64;
printf("consumer: %ld cycles/op\n", (v7 + ((unsigned __int64)(v5 - qword_880[v6] - v7) >> 1)) >> 27);
v8 = (0x5798EE063611088DLL * (unsigned __int128)(unsigned __int64)(qword_888[v6] - qword_880[v6])) >> 64;
results[2 * v3] = (v8 + ((unsigned __int64)(qword_888[v6] - qword_880[v6] - v8) >> 1)) >> 27;
pthread_barrier_wait(v2);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unsigned int v1; // ebp
pthread_barrier_t *v2; // r12
unsigned int v3; // er14
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // rdx
__int64 v8; // rdx
cpu_set_t v10; // [rsp+0h] [rbp-B8h] BYREF
char v11[48]; // [rsp+88h] [rbp-30h] BYREF

v1 = *(_DWORD *)a1;
v2 = (pthread_barrier_t *)*((_QWORD *)a1 + 1);
v3 = *((_DWORD *)a1 + 4);
memset(&v10, 0, sizeof(v10));
if ( v1 <= 0x3FF )
v10.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
printf("consumer %d: ---%d----\n", v1, 2 * v1);
if ( sched_setaffinity(0, 0x80uLL, &v10) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
puts("Consumer created...");
pthread_barrier_wait(v2);
qword_880[8216 * v1] = read_tsc();
v4 = 200000000LL;
do
{
while ( (unsigned int)dequeue((char *)&queues + 65728 * v1, v11) )
;
--v4;
}
while ( v4 );
v5 = read_tsc();
v6 = 8216LL * v1;
qword_888[v6] = v5;
v7 = (0x5798EE063611088DLL * (unsigned __int128)(unsigned __int64)(v5 - qword_880[v6])) >> 64;
printf("consumer: %ld cycles/op\n", (v7 + ((unsigned __int64)(v5 - qword_880[v6] - v7) >> 1)) >> 27);
v8 = (0x5798EE063611088DLL * (unsigned __int128)(unsigned __int64)(qword_888[v6] - qword_880[v6])) >> 64;
results[2 * v3] = (v8 + ((unsigned __int64)(qword_888[v6] - qword_880[v6] - v8) >> 1)) >> 27;
pthread_barrier_wait(v2);
}
return 0LL;
}

original_code:
void * consumer(void *arg)
{
 uint32_t cpu_id, r;
 uint64_t value;
 cpu_set_t cur_mask;
 uint64_t i;
 struct init_info * init = (struct init_info *) arg;
 cpu_id = init->cpu_id;
 pthread_barrier_t *barrier = init->barrier;
  r = init->r;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (cpu_id); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("consumer %d:  ---%d----\n", cpu_id, 2*cpu_id);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ((void *)0);
 }
 printf("Consumer created...\n");
 pthread_barrier_wait(barrier);
 queues[cpu_id].start_c = read_tsc();
 for (i = 1; i <= 200000000; i++) {
  while( dequeue(&queues[cpu_id], &value) != 0 );
 }
 queues[cpu_id].stop_c = read_tsc();
 printf("consumer: %" "l" "d" " cycles/op\n",
  ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1)));
  results[r].cons = ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1));
 pthread_barrier_wait(barrier);
 return ((void *)0);
}

canonical_original_code:
void *consumer(void *arg)
{
 unsigned int cpu_id; unsigned int r;
 unsigned long value;
 struct cpu_set_t cur_mask;
 unsigned long i;
 struct init_info *init = (struct init_info *) arg;
 cpu_id = init->cpu_id;
 union pthread_barrier_t *barrier = init->barrier;
  r = init->r;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (cpu_id); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("consumer %d:  ---%d----\n", cpu_id, 2*cpu_id);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ((void *)0);
 }
 printf("Consumer created...\n");
 pthread_barrier_wait(barrier);
 queues[cpu_id].start_c = read_tsc();
 for (i = 1; i <= 200000000; i++) {
  while( dequeue(&queues[cpu_id], &value) != 0 );
 }
 queues[cpu_id].stop_c = read_tsc();
 printf("consumer: %" "l" "d" " cycles/op\n",
  ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1)));
  results[r].cons = ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1));
 pthread_barrier_wait(barrier);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types:
r
unsigned int

variable_types:
value
unsigned long

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types:
i
unsigned long

variable_types: struct init_info { unsigned int cpu_id; union pthread_barrier_t { char __size[32]; long __align; } *barrier; unsigned int r; } *

return_type: void *

user_defined_types: struct init_info { unsigned int cpu_id; union pthread_barrier_t *barrier; unsigned int r; }


producer

decompiled_code:
void __fastcall producer(__int64 a1, unsigned int a2, unsigned int a3)
{
pthread_barrier_t *v3; // r15
__int64 i; // rbp
char *v5; // r12
unsigned __int64 v6; // rbx
__int64 v7; // [rsp+0h] [rbp-C8h]
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

v3 = *(pthread_barrier_t **)(a1 + 8);
memset(&cpuset.__bits[1], 0, 0x78uLL);
cpuset.__bits[0] = 1LL;
printf("producer %d: ---%d----\n", 0LL, 1LL);
if ( sched_setaffinity(0, 0x80uLL, &cpuset) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
pthread_barrier_wait(v3);
v7 = read_tsc();
for ( i = 1LL; i != 200000513; ++i )
{
v5 = (char *)&unk_108C0;
if ( a2 > 1 )
{
do
{
while ( (unsigned int)enqueue(v5, i) )
;
v5 += 65728;
}
while ( v5 != (char *)&unk_20980 + 65728 * a2 - 131456 );
}
}
v6 = (read_tsc() - v7) / (unsigned __int64)(200000001 * a2 - 200000001);
printf("producer %ld cycles/op\n", v6);
results[2 * a3 + 1] = v6;
pthread_barrier_wait(v3);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
pthread_barrier_t *v3; // r15
__int64 i; // rbp
char *v5; // r12
unsigned __int64 v6; // rbx
__int64 v7; // [rsp+0h] [rbp-C8h]
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

v3 = *(pthread_barrier_t **)(a1 + 8);
memset(&cpuset.__bits[1], 0, 0x78uLL);
cpuset.__bits[0] = 1LL;
printf("producer %d: ---%d----\n", 0LL, 1LL);
if ( sched_setaffinity(0, 0x80uLL, &cpuset) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
pthread_barrier_wait(v3);
v7 = read_tsc();
for ( i = 1LL; i != 200000513; ++i )
{
v5 = (char *)&unk_108C0;
if ( a2 > 1 )
{
do
{
while ( (unsigned int)enqueue(v5, i) )
;
v5 += 65728;
}
while ( v5 != (char *)&unk_20980 + 65728 * a2 - 131456 );
}
}
v6 = (read_tsc() - v7) / (unsigned __int64)(200000001 * a2 - 200000001);
printf("producer %ld cycles/op\n", v6);
results[2 * a3 + 1] = v6;
pthread_barrier_wait(v3);
}
}

original_code:
void producer(void *arg, uint32_t num, uint32_t r)
{
 uint64_t start_p;
 uint64_t stop_p;
 uint64_t i;
 int32_t j;
 cpu_set_t cur_mask;
 struct init_info * init = (struct init_info *) arg;
 pthread_barrier_t *barrier = init->barrier;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (0); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("producer %d:  ---%d----\n", 0, 1);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ;
 }
 pthread_barrier_wait(barrier);
 start_p = read_tsc();
 for (i = 1; i <= 200000000 + ((1024 * 8)/16); i++) {
  for (j=1; j<num; j++) {
   while ( enqueue(&queues[j], (uint64_t)i) != 0);
  }
 }
 stop_p = read_tsc();
 printf("producer %" "l" "d" " cycles/op\n", (stop_p - start_p) / ((200000000 + 1)*(num -1)));
  results[r].prod = (stop_p - start_p) / ((200000000 + 1)*(num -1));
 pthread_barrier_wait(barrier);
}

canonical_original_code:
void producer(void *arg, unsigned int num, unsigned int r)
{
 unsigned long start_p;
 unsigned long stop_p;
 unsigned long i;
 int j;
 struct cpu_set_t cur_mask;
 struct init_info *init = (struct init_info *) arg;
 union pthread_barrier_t *barrier = init->barrier;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (0); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("producer %d:  ---%d----\n", 0, 1);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ;
 }
 pthread_barrier_wait(barrier);
 start_p = read_tsc();
 for (i = 1; i <= 200000000 + ((1024 * 8)/16); i++) {
  for (j=1; j<num; j++) {
   while ( enqueue(&queues[j], (unsigned long)i) != 0);
  }
 }
 stop_p = read_tsc();
 printf("producer %" "l" "d" " cycles/op\n", (stop_p - start_p) / ((200000000 + 1)*(num -1)));
  results[r].prod = (stop_p - start_p) / ((200000000 + 1)*(num -1));
 pthread_barrier_wait(barrier);
}

variable_types:
num
unsigned int

variable_types: j int

variable_types: union pthread_barrier_t { char __size[32]; long __align; } *

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
signed int v3; // er12
int v4; // eax
unsigned int v5; // eax
const char *v6; // rbx
int v7; // er13
unsigned __int64 v9; // rbx
int v10; // ebp
int v11; // eax
pthread_barrier_t v12; // [rsp+0h] [rbp-88h] BYREF
pthread_attr_t attr; // [rsp+20h] [rbp-68h] BYREF
pthread_t newthread[6]; // [rsp+58h] [rbp-30h] BYREF

v3 = 2;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
v4 = atoi(*(const char **)&argc);
v3 = v4;
if ( v4 <= 1 )
{
*(_QWORD *)&argc = "Minimum core number is 2";
puts("Minimum core number is 2");
v3 = 2;
}
else if ( v4 > 32 )
{
argv = (const char **)(&loc_1C + 4);
*(_QWORD *)&argc = "Maximum core number is %d\n";
printf("Maximum core number is %d\n", 32LL);
v3 = 32;
}
}
v5 = read_tsc(*(_QWORD *)&argc, argv, envp);
srand(v5);
v6 = (const char *)&queues;
do
{
queue_init(v6);
v6 += 65728;
}
while ( "consumer %d: ---%d----\n" != v6 );
if ( pthread_barrier_init(&v12, 0LL, v3) )
goto LABEL_9;
v7 = pthread_attr_init(&attr);
if ( v7 )
goto LABEL_9;
v9 = (unsigned int)((_DWORD)&info + 24);
v10 = 1;
if ( v3 <= 1 )
goto LABEL_17;
do
{
*(_DWORD *)v9 = v10;
*(_QWORD *)(v9 + 8) = &v12;
*(_DWORD *)(v9 + 16) = 0;
v11 = pthread_create(newthread, &attr, consumer, (void *)v9);
++v10;
v9 += 24LL;
}
while ( v3 != v10 );
if ( v11 )
{
LABEL_9:
perror("BW");
v7 = 1;
}
else
{
LABEL_17:
info = 0;
*((_QWORD *)&info + 1) = &v12;
*(&info + 4) = 0;
producer((__int64)&info, v3, 0);
puts(".");
puts("Done!");
printf("producers: ");
printf("%ld ", results[1]);
printf("\nconsumers: ");
printf("%ld ", results[0]);
putchar(10);
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
signed int v3; // er12
int v4; // eax
unsigned int v5; // eax
const char *v6; // rbx
int v7; // er13
unsigned __int64 v9; // rbx
int v10; // ebp
int v11; // eax
pthread_barrier_t v12; // [rsp+0h] [rbp-88h] BYREF
pthread_attr_t attr; // [rsp+20h] [rbp-68h] BYREF
pthread_t newthread[6]; // [rsp+58h] [rbp-30h] BYREF

v3 = 2;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
v4 = atoi(*(const char **)&argc);
v3 = v4;
if ( v4 <= 1 )
{
*(_QWORD *)&argc = "Minimum core number is 2";
puts("Minimum core number is 2");
v3 = 2;
}
else if ( v4 > 32 )
{
argv = (const char **)(&loc_1C + 4);
*(_QWORD *)&argc = "Maximum core number is %d\n";
printf("Maximum core number is %d\n", 32LL);
v3 = 32;
}
}
v5 = read_tsc(*(_QWORD *)&argc, argv, envp);
srand(v5);
v6 = (const char *)&queues;
do
{
queue_init(v6);
v6 += 65728;
}
while ( "consumer %d: ---%d----\n" != v6 );
if ( pthread_barrier_init(&v12, 0LL, v3) )
goto LABEL_9;
v7 = pthread_attr_init(&attr);
if ( v7 )
goto LABEL_9;
v9 = (unsigned int)((_DWORD)&info + 24);
v10 = 1;
if ( v3 <= 1 )
goto LABEL_17;
do
{
*(_DWORD *)v9 = v10;
*(_QWORD *)(v9 + 8) = &v12;
*(_DWORD *)(v9 + 16) = 0;
v11 = pthread_create(newthread, &attr, consumer, (void *)v9);
++v10;
v9 += 24LL;
}
while ( v3 != v10 );
if ( v11 )
{
LABEL_9:
perror("BW");
v7 = 1;
}
else
{
LABEL_17:
info = 0;
*((_QWORD *)&info + 1) = &v12;
*(&info + 4) = 0;
func1((__int64)&info, v3, 0);
puts(".");
puts("Done!");
printf("producers: ");
printf("%ld ", results[1]);
printf("\nconsumers: ");
printf("%ld ", results[0]);
putchar(10);
}
return v7;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t consumer_thread;
 pthread_attr_t consumer_attr;
 pthread_barrier_t barrier;
 int error , i, max_th = 2, c;
 if (argc > 1) {
  max_th = atoi(argv[1]);
 }
 if (max_th < 2) {
  max_th = 2;
  printf("Minimum core number is 2\n");
 }
 if (max_th > 32) {
  max_th = 32;
  printf("Maximum core number is %d\n", max_th);
 }
 srand((unsigned int)read_tsc());
 for (i=0; i<32; i++) {
  queue_init(&queues[i]);
 }
 error = pthread_barrier_init(&barrier, ((void *)0), max_th);
 if (error != 0) {
  perror("BW");
  return 1;
 }
 error = pthread_attr_init(&consumer_attr);
 if (error != 0) {
  perror("BW");
  return 1;
 }
  for(c = 0; c < (1); ++c ) {
    for (i=1; i<max_th; i++) {
      (info[i].cpu_id) = i;
      (info[i].barrier) = &barrier;
      (info[i].r) = c;
      error = pthread_create(&consumer_thread, &consumer_attr,
            consumer, (&info[i]));
    }
    if (error != 0) {
      perror("BW");
      return 1;
    }
    (info[0].cpu_id) = 0;
    (info[0].barrier) = &barrier;
    (info[0].r) = c;
    producer((&info[0]), max_th, c);
    printf(".\n");
  }
 printf("Done!\n");
  printf("producers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].prod); }
  printf("\nconsumers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].cons); }
  printf("\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long consumer_thread;
 union pthread_attr_t consumer_attr;
 union pthread_barrier_t barrier;
 int error; int i; int max_th = 2; int c;
 if (argc > 1) {
  max_th = atoi(argv[1]);
 }
 if (max_th < 2) {
  max_th = 2;
  printf("Minimum core number is 2\n");
 }
 if (max_th > 32) {
  max_th = 32;
  printf("Maximum core number is %d\n", max_th);
 }
 srand((unsigned int)read_tsc());
 for (i=0; i<32; i++) {
  queue_init(&queues[i]);
 }
 error = pthread_barrier_init(&barrier, ((void *)0), max_th);
 if (error != 0) {
  perror("BW");
  return 1;
 }
 error = pthread_attr_init(&consumer_attr);
 if (error != 0) {
  perror("BW");
  return 1;
 }
  for(c = 0; c < (1); ++c ) {
    for (i=1; i<max_th; i++) {
      (info[i].cpu_id) = i;
      (info[i].barrier) = &barrier;
      (info[i].r) = c;
      error = pthread_create(&consumer_thread, &consumer_attr,
            consumer, (&info[i]));
    }
    if (error != 0) {
      perror("BW");
      return 1;
    }
    (info[0].cpu_id) = 0;
    (info[0].barrier) = &barrier;
    (info[0].r) = c;
    producer((&info[0]), max_th, c);
    printf(".\n");
  }
 printf("Done!\n");
  printf("producers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].prod); }
  printf("\nconsumers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].cons); }
  printf("\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: union pthread_barrier_t { char __size[32]; long __align; }

variable_types: error int

variable_types: i int

variable_types: c int


decompiled_code:
void *__fastcall queue_init(void *a1)
{
return memset(a1, 0, 0x100C0uLL);
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
return memset(a1, 0, 0x100C0uLL);
}

original_code:
void queue_init(struct queue_t *q)
{
 memset(q, 0, sizeof(struct queue_t));
}

variable_types: struct queue_t { unsigned int head; unsigned int tail; unsigned long start_c; unsigned long stop_c; unsigned long data[-1]; } *


enqueue

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

if ( *(_QWORD *)&a1[2 * *a1 + 48] )
return 0xFFFFFFFFLL;
*(_QWORD *)&a1[2 * (*a1)++ + 48] = a2;
result = 0LL;
if ( *a1 > 0x1FFFu )
*a1 = 0;
return result;
}

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

if ( *(_QWORD *)&a1[2 * *a1 + 48] )
return 0xFFFFFFFFLL;
*(_QWORD *)&a1[2 * (*a1)++ + 48] = a2;
result = 0LL;
if ( *a1 > 0x1FFFu )
*a1 = 0;
return result;
}

original_code:
int enqueue(struct queue_t * q, uint64_t value)
{
 if ( q->data[q->head] )
  return -1;
 q->data[q->head] = value;
 q->head ++;
 if ( q->head >= (1024 * 8) ) {
  q->head = 0;
 }
 return 0;
}

canonical_original_code:
int enqueue(struct queue_t *q, unsigned long value)
{
 if ( q->data[q->head] )
  return -1;
 q->data[q->head] = value;
 q->head ++;
 if ( q->head >= (1024 * 8) ) {
  q->head = 0;
 }
 return 0;
}

user_defined_types: struct queue_t { unsigned int head; unsigned int tail; unsigned long start_c; unsigned long stop_c; unsigned long data[-1]; }


dequeue

original_code:
int dequeue(struct queue_t * q, uint64_t * value)
{
 if ( !q->data[q->tail] )
  return -2;
 *value = q->data[q->tail];
 q->data[q->tail] = ELEMENT_ZERO;
 q->tail ++;
 if ( q->tail >= (1024 * 8) )
  q->tail = 0;
 return 0;
}

canonical_original_code:
int dequeue(struct queue_t *q, unsigned long *value)
{
 if ( !q->data[q->tail] )
  return -2;
 *value = q->data[q->tail];
 q->data[q->tail] = ELEMENT_ZERO;
 q->tail ++;
 if ( q->tail >= (1024 * 8) )
  q->tail = 0;
 return 0;
}

variable_types:
value
unsigned long *


myrand

original_code:
int myrand(unsigned long * next) {
 *next = *next * 1103515245 + 12345;
 return((unsigned)(*next/65536) % 32768);
}

canonical_original_code:
int myrand(unsigned long *next) {
 *next = *next * 1103515245 + 12345;
 return((unsigned int)(*next/65536) % 32768);
}

variable_types:
next
unsigned long *


decompiled_code:
unsigned int P1L()
{
puts("Sono il processo P1L");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func8()
{
puts("Sono il processo P1L");
return sleep(1u);
}

original_code: void P1L() { puts("Sono il processo " "P1L" ); sleep(1); }


decompiled_code:
unsigned int P1R()
{
puts("Sono il processo P1R");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func9()
{
puts("Sono il processo P1R");
return sleep(1u);
}

original_code: void P1R() { puts("Sono il processo " "P1R" ); sleep(1); }


decompiled_code:
unsigned int P2L()
{
puts("Sono il processo P2L");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func11()
{
puts("Sono il processo P2L");
return sleep(1u);
}

original_code: void P2L() { puts("Sono il processo " "P2L" ); sleep(1); }


decompiled_code:
unsigned int P2R()
{
puts("Sono il processo P2R");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func12()
{
puts("Sono il processo P2R");
return sleep(1u);
}

original_code: void P2R() { puts("Sono il processo " "P2R" ); sleep(1); }


decompiled_code:
unsigned int P1()
{
puts("Sono il processo P1");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func7()
{
puts("Sono il processo P1");
return sleep(1u);
}

original_code: void P1() { puts("Sono il processo " "P1" ); sleep(1); }


decompiled_code:
unsigned int P2()
{
puts("Sono il processo P2");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func10()
{
puts("Sono il processo P2");
return sleep(1u);
}

original_code: void P2() { puts("Sono il processo " "P2" ); sleep(1); }


decompiled_code:
unsigned int P3()
{
puts("Sono il processo P3");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func13()
{
puts("Sono il processo P3");
return sleep(1u);
}

original_code: void P3() { puts("Sono il processo " "P3" ); sleep(1); }


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int i; // ebx
int v5; // ebp
int v7[5]; // [rsp+0h] [rbp-88h] BYREF
char v8; // [rsp+14h] [rbp-74h] BYREF
__int64 v9[7]; // [rsp+20h] [rbp-68h]
__WAIT_STATUS stat_loc; // [rsp+5Ch] [rbp-2Ch] BYREF

v9[0] = (__int64)P1;
v9[1] = (__int64)P1R;
v9[2] = (__int64)P1L;
v9[3] = (__int64)P2;
v9[4] = (__int64)P2R;
v9[5] = (__int64)P2L;
v9[6] = (__int64)P3;
v7[0] = 1;
v7[1] = 3;
v7[2] = 4;
v7[3] = 6;
v7[4] = 7;
v3 = (char *)v7;
for ( i = 0; ; i = v5 )
{
v5 = *(_DWORD *)v3;
if ( *(_DWORD *)v3 > i )
break;
v5 = i;
do
LABEL_5:
*(_QWORD *)&argc = &stat_loc;
while ( wait((__WAIT_STATUS)&stat_loc) != -1 );
v3 += 4;
if ( v3 == &v8 )
return 0;
}
while ( fork() )
{
if ( ++i == v5 )
goto LABEL_5;
}
((void (__fastcall *)(_QWORD, const char **))v9[i])(*(_QWORD *)&argc, argv);
return 0;
}

original_code:
int main(int argc, char**argv){
  int i, j, st;
  func tree[] = { P1, P1R, P1L, P2, P2R, P2L, P3 };
  int idx[] = { 1, 3, 4, 6, 7 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
 tree[j]();
 return 0;
      }
    }
    while( wait(&st) != -1 ) ;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int j; int st;
  void (*tree[])() = { P1, P1R, P1L, P2, P2R, P2L, P3 };
  int idx[] = { 1, 3, 4, 6, 7 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
 tree[j]();
 return 0;
      }
    }
    while( wait(&st) != -1 ) ;
  }
  return 0;
}

variable_types:
argv
char **

variable_types: st int

variable_types:
tree
void (*[])()

variable_types:
idx
int []


original_code:
void
heap_fix_up (
  heap_t *hp,
  int idx
)
{
  int *qp=hp->qp, *pq=hp->pq;
  int i=qp[idx], p=(((i) - 1) / 2), t;
  char *iv, *pv;
  while (i > 0) {
    iv =(char*) hp->data + hp->elem_size * pq[i];
    pv = (char*)hp->data + hp->elem_size * pq[p];
    if ((*hp->cmp)((void*)iv, (void*)pv) <= 0) {
      return;
    }
    t = pq[i]; pq[i] = pq[p]; pq[p] = t;
    qp[pq[i]] = i; qp[pq[p]] = p;
    i = p; p = (((p) - 1) / 2);
  }
}

canonical_original_code:
void heap_fix_up(struct heap_s *hp, int idx)
{
  int *qp = hp->qp; int *pq = hp->pq;
  int i = qp[idx]; int p = (((i) - 1) / 2); int t;
  char *iv; char *pv;
  while (i > 0) {
    iv =(char *) hp->data + hp->elem_size * pq[i];
    pv = (char *)hp->data + hp->elem_size * pq[p];
    if ((*hp->cmp)((void *)iv, (void *)pv) <= 0) {
      return;
    }
    t = pq[i]; pq[i] = pq[p]; pq[p] = t;
    qp[pq[i]] = i; qp[pq[p]] = p;
    i = p; p = (((p) - 1) / 2);
  }
}

variable_types: struct heap_s { void *data; int num; int size; int elem_size; int (*cmp)(void *lv, void *rv); int *qp; int *pq; } *

variable_types: idx int

variable_types:
qp
int *

variable_types:
pq
int *

variable_types: p int

variable_types: t int

variable_types:
iv
char *

variable_types:
pv
char *


original_code:
void
heap_insert (
  heap_t *hp,
  int idx
)
{
  ((hp->qp[idx]<0) ? (void) (0) : __assert_fail ("hp->qp[idx]<0", "heap.c", 155, __extension__ __PRETTY_FUNCTION__));
  hp->qp[idx] = hp->num;
  hp->pq[hp->num++] = idx;
  heap_fix_up(hp, idx);
}

canonical_original_code:
void heap_insert(struct heap_s *hp, int idx)
{
  ((hp->qp[idx]<0) ? (void) (0) : __assert_fail ("hp->qp[idx]<0", "heap.c", 155, __extension__ __PRETTY_FUNCTION__));
  hp->qp[idx] = hp->num;
  hp->pq[hp->num++] = idx;
  heap_fix_up(hp, idx);
}

user_defined_types: struct heap_s { void *data; int num; int size; int elem_size; int (*cmp)(void *lv, void *rv); int *qp; int *pq; }


original_code:
void
heap_fix_down (
  heap_t *hp,
  int idx
)
{
  int *qp=hp->qp, *pq=hp->pq;
  int i=hp->qp[idx], l, p, r, t;
  char *iv, *lv, *rv;
  do {
    p = i; l = (2 * (i) + 1); r = (2 * (i) + 2);
    iv = (char*)hp->data + hp->elem_size * pq[i];
    if (l < hp->num) {
      lv = (char*)hp->data + hp->elem_size * pq[l];
      if ((*hp->cmp)((void*)lv, (void*)iv) > 0) {
        i = l; iv = lv;
      }
    }
    if (r < hp->num) {
      rv = (char*)hp->data + hp->elem_size * pq[r];
      if ((*hp->cmp)((void*)rv, (void*)iv) > 0) {
        i = r; iv = rv;
      }
    }
    if (i != p) {
      t = pq[i]; pq[i] = pq[p]; pq[p] = t;
      qp[pq[i]] = i, qp[pq[p]] = p;
    }
  } while (i != p);
}

canonical_original_code:
void heap_fix_down(struct heap_s *hp, int idx)
{
  int *qp = hp->qp; int *pq = hp->pq;
  int i = hp->qp[idx]; int l; int p; int r; int t;
  char *iv; char *lv; char *rv;
  do {
    p = i; l = (2 * (i) + 1); r = (2 * (i) + 2);
    iv = (char *)hp->data + hp->elem_size * pq[i];
    if (l < hp->num) {
      lv = (char *)hp->data + hp->elem_size * pq[l];
      if ((*hp->cmp)((void *)lv, (void *)iv) > 0) {
        i = l; iv = lv;
      }
    }
    if (r < hp->num) {
      rv = (char *)hp->data + hp->elem_size * pq[r];
      if ((*hp->cmp)((void *)rv, (void *)iv) > 0) {
        i = r; iv = rv;
      }
    }
    if (i != p) {
      t = pq[i]; pq[i] = pq[p]; pq[p] = t;
      qp[pq[i]] = i, qp[pq[p]] = p;
    }
  } while (i != p);
}

variable_types: i int

variable_types: l int

variable_types: r int

variable_types:
lv
char *

variable_types:
rv
char *


original_code:
int
heap_remove (
  heap_t *hp,
  int idx
)
{
  int i, pos=hp->qp[idx];
  char *iv, *xv;
  ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "heap.c", 177, __extension__ __PRETTY_FUNCTION__));
  i = hp->pq[--hp->num];
  hp->pq[pos] = i;
  hp->qp[i] = pos;
  hp->qp[idx] = -1;
  if (hp->num>1 && i!=idx) {
    iv = (char*)hp->data + hp->elem_size * i;
    xv = (char*)hp->data + hp->elem_size * idx;
    if ((*hp->cmp)((void*)iv, (void*)xv) > 0) {
      heap_fix_up(hp, i);
    } else {
      heap_fix_down(hp, i);
    }
  }
  return idx;
}

canonical_original_code:
int heap_remove(struct heap_s *hp, int idx)
{
  int i; int pos = hp->qp[idx];
  char *iv; char *xv;
  ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "heap.c", 177, __extension__ __PRETTY_FUNCTION__));
  i = hp->pq[--hp->num];
  hp->pq[pos] = i;
  hp->qp[i] = pos;
  hp->qp[idx] = -1;
  if (hp->num>1 && i!=idx) {
    iv = (char *)hp->data + hp->elem_size * i;
    xv = (char *)hp->data + hp->elem_size * idx;
    if ((*hp->cmp)((void *)iv, (void *)xv) > 0) {
      heap_fix_up(hp, i);
    } else {
      heap_fix_down(hp, i);
    }
  }
  return idx;
}

variable_types: pos int

variable_types:
xv
char *


decompiled_code:
__int64 __fastcall heap_extract(__int64 a1)
{
return heap_remove(a1, **(_DWORD **)(a1 + 40));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return func4(a1, **(_DWORD **)(a1 + 40));
}

original_code:
int
heap_extract (
  heap_t *hp
)
{
  return heap_remove(hp, hp->pq[0]);
}

canonical_original_code:
int heap_extract(struct heap_s *hp)
{
  return heap_remove(hp, hp->pq[0]);
}


decompiled_code:
_BOOL8 __fastcall heap_is_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

original_code:
int
heap_is_empty (
  heap_t *hp
)
{
  return !hp->num;
}

canonical_original_code:
int heap_is_empty(struct heap_s *hp)
{
  return !hp->num;
}


decompiled_code:
_BOOL8 __fastcall is_in_heap(__int64 a1, int a2)
{
return *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, int a2)
{
return *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2) >= 0;
}

original_code:
int
is_in_heap (
  heap_t *hp,
  int idx
)
{
  return hp->qp[idx] >= 0;
}

canonical_original_code:
int is_in_heap(struct heap_s *hp, int idx)
{
  return hp->qp[idx] >= 0;
}


decompiled_code:
__int64 __fastcall heap_free(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}
return 0LL;
}

original_code:
heap_t *
heap_free (
  heap_t *hp
)
{
  if (hp) {
    free(hp->qp);
    free(hp->pq);
    free(hp);
  }
  return ((void *)0);
}

canonical_original_code:
struct heap_s *heap_free(struct heap_s *hp)
{
  if (hp) {
    free(hp->qp);
    free(hp->pq);
    free(hp);
  }
  return ((void *)0);
}

variable_types:
hp
struct heap_s *

return_type: struct heap_s { void *data; int num; int size; int elem_size; int (*cmp)(void *lv, void *rv); int *qp; int *pq; } *


QuickSort

original_code:
void QuickSort(int *list, int beg, int end)
{
  int piv; int tmp;
  int l,r,p;
  while (beg<end){
    l = beg; p = (beg+end)/2; r = end;
    piv = list[p];
    while (1){
      while ( (l<=r) && ( ((list[l])-(piv)) <= 0 ) ) l++;
      while ( (l<=r) && ( ((list[r])-(piv)) > 0 ) ) r--;
      if (l>r) break;
      tmp=list[l]; list[l]=list[r]; list[r]=tmp;
      if (p==r) p=l;
      l++; r--;
    }
    list[p]=list[r]; list[r]=piv;
    r--;
    if ((r-beg)<(end-l)){
      QuickSort(list, beg, r);
      beg=l;
    }
    else{
      QuickSort(list, l, end);
      end=r;
    }
  }
}

canonical_original_code:
void QuickSort(int *list, int beg, int end)
{
  int piv; int tmp;
  int l; int r; int p;
  while (beg<end){
    l = beg; p = (beg+end)/2; r = end;
    piv = list[p];
    while (1){
      while ( (l<=r) && ( ((list[l])-(piv)) <= 0 ) ) l++;
      while ( (l<=r) && ( ((list[r])-(piv)) > 0 ) ) r--;
      if (l>r) break;
      tmp=list[l]; list[l]=list[r]; list[r]=tmp;
      if (p==r) p=l;
      l++; r--;
    }
    list[p]=list[r]; list[r]=piv;
    r--;
    if ((r-beg)<(end-l)){
      QuickSort(list, beg, r);
      beg=l;
    }
    else{
      QuickSort(list, l, end);
      end=r;
    }
  }
}

variable_types:
list
int *

variable_types: beg int

variable_types: end int

variable_types: piv int

variable_types: tmp int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **v3; // r13
void *v4; // rax
void **v5; // rbp
pthread_t *v6; // r14
unsigned int v7; // er12
char *v8; // rbx
size_t v9; // rax
char *v10; // rbx
size_t v11; // rax
pthread_t *newthread; // [rsp+0h] [rbp-58h]
int v14; // [rsp+Ch] [rbp-4Ch]
void **ptr; // [rsp+10h] [rbp-48h]
void *v16; // [rsp+18h] [rbp-40h]

v14 = atoi(argv[3]);
v3 = (void **)malloc(16LL * v14);
ptr = v3;
v4 = malloc(8LL * v14);
v16 = v4;
if ( v14 > 0 )
{
v5 = v3;
v6 = (pthread_t *)v4;
newthread = (pthread_t *)v4;
v7 = 0;
do
{
v8 = (char *)malloc(0x64uLL);
*v3 = v8;
strcpy(v8, argv[1]);
v9 = strlen(v8);
sprintf(&v8[v9], "%d.txt", ++v7);
v10 = (char *)malloc(0x64uLL);
v3[1] = v10;
strcpy(v10, argv[2]);
v11 = strlen(v10);
sprintf(&v10[v11], "%d.txt", v7);
pthread_create(newthread, 0LL, ordina, v3);
v3 += 2;
++newthread;
}
while ( v7 != v14 );
do
{
pthread_join(*v6, 0LL);
free(*v5);
free(v5[1]);
++v6;
v5 += 2;
}
while ( v5 != &ptr[2 * (unsigned int)(v14 - 1) + 2] );
}
free(ptr);
free(v16);
return 0;
}

original_code:
int main(int argc, char** argv){
  char *pointer;
  files *args;
  int tot, i;
  pthread_t *tid;
  tot=atoi(argv[3]);
  args=malloc(sizeof(files)*tot);
  tid=malloc(sizeof(pthread_t)*tot);
  for(i=0;i<tot;i++){
    args[i].nome_r=malloc(sizeof(char)*100);
    strcpy(args[i].nome_r,argv[1]);
    pointer=strchr(args[i].nome_r,'\0');
    sprintf(pointer,"%d.txt",i+1);
    args[i].nome_w=malloc(sizeof(char)*100);
    strcpy(args[i].nome_w,argv[2]);
    pointer=strchr(args[i].nome_w,'\0');
    sprintf(pointer,"%d.txt",i+1);
    pthread_create(&tid[i],((void *)0),ordina,(void*) &args[i]);
  }
  for(i=0; i<tot; i++){
    pthread_join(tid[i], ((void *)0));
    free(args[i].nome_r);
    free(args[i].nome_w);
  }
  free(args);
  free(tid);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  char *pointer;
  struct Files *args;
  int tot; int i;
  unsigned long *tid;
  tot=atoi(argv[3]);
  args=malloc(sizeof(files)*tot);
  tid=malloc(sizeof(pthread_t)*tot);
  for(i=0;i<tot;i++){
    args[i].nome_r=malloc(sizeof(char)*100);
    strcpy(args[i].nome_r,argv[1]);
    pointer=strchr(args[i].nome_r,'\0');
    sprintf(pointer,"%d.txt",i+1);
    args[i].nome_w=malloc(sizeof(char)*100);
    strcpy(args[i].nome_w,argv[2]);
    pointer=strchr(args[i].nome_w,'\0');
    sprintf(pointer,"%d.txt",i+1);
    pthread_create(&tid[i],((void *)0),ordina,(void *) &args[i]);
  }
  for(i=0; i<tot; i++){
    pthread_join(tid[i], ((void *)0));
    free(args[i].nome_r);
    free(args[i].nome_w);
  }
  free(args);
  free(tid);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
pointer
char *

variable_types: struct Files { char *nome_r; char *nome_w; } *

variable_types: tot int

variable_types:
tid
unsigned long *


p

decompiled_code:
__int64 p()
{
return 1LL;
}

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

original_code:
int p() {
  return 1;
}

canonical_original_code:
int p() {
  return 1;
}


argSplit

decompiled_code:
char *__fastcall argSplit(const char *a1)
{
const char *v1; // rbx
int v2; // edx
char i; // al
char *v4; // rax
char *result; // rax
size_t v6; // rbx
size_t v7; // rbx

if ( a1 )
{
v1 = a1;
v2 = i_3;
if ( i_3 )
{
*a1 = 0;
v1 = a1 + 1;
}
for ( i = *v1; *v1 == 32; i = *v1 )
++v1;
if ( i == 10 || !i )
{
*v1 = 0;
v7 = 8LL * (v2 + 1);
result = (char *)malloc(v7);
r_2 = (__int64)result;
*(_QWORD *)&result[v7 - 8] = 0LL;
}
else
{
i_3 = v2 + 1;
v4 = strchr(v1, 32);
argSplit(v4);
--i_3;
result = (char *)r_2;
*(_QWORD *)(r_2 + 8LL * i_3) = v1;
}
}
else
{
v6 = 8LL * (i_3 + 1);
result = (char *)malloc(v6);
r_2 = (__int64)result;
*(_QWORD *)&result[v6 - 8] = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1)
{
const char *v1; // rbx
int v2; // edx
char i; // al
char *v4; // rax
char *result; // rax
size_t v6; // rbx
size_t v7; // rbx

if ( a1 )
{
v1 = a1;
v2 = i_3;
if ( i_3 )
{
*a1 = 0;
v1 = a1 + 1;
}
for ( i = *v1; *v1 == 32; i = *v1 )
++v1;
if ( i == 10 || !i )
{
*v1 = 0;
v7 = 8LL * (v2 + 1);
result = (char *)malloc(v7);
r_2 = (__int64)result;
*(_QWORD *)&result[v7 - 8] = 0LL;
}
else
{
i_3 = v2 + 1;
v4 = strchr(v1, 32);
func8(v4);
--i_3;
result = (char *)r_2;
*(_QWORD *)(r_2 + 8LL * i_3) = v1;
}
}
else
{
v6 = 8LL * (i_3 + 1);
result = (char *)malloc(v6);
r_2 = (__int64)result;
*(_QWORD *)&result[v6 - 8] = 0LL;
}
return result;
}

original_code:
char** argSplit(char*str) {
  static char **r;
  static int i = 0;
  if(str == ((void *)0)){
    r = malloc((i+1) * sizeof(char**));
    r[i] = ((void *)0);
    return r;
  }
  if(i){
    *str= '\0';
    str++;
  }
  while(*str == ' ')
    str++;
  if(*str == '\n' || *str == '\0'){
    *str = '\0';
    r = malloc((i+1) * sizeof(char**));
    r[i] = ((void *)0);
    return r;
  }
  i++;
  (void)argSplit(strchr(str, ' '));
  i--;
  r[i] = str;
  return r;
}

canonical_original_code:
char **argSplit(char *str) {
  static char **r;
  static int i = 0;
  if(str == ((void *)0)){
    r = malloc((i+1) * sizeof(char **));
    r[i] = ((void *)0);
    return r;
  }
  if(i){
    *str= '\0';
    str++;
  }
  while(*str == ' ')
    str++;
  if(*str == '\n' || *str == '\0'){
    *str = '\0';
    r = malloc((i+1) * sizeof(char **));
    r[i] = ((void *)0);
    return r;
  }
  i++;
  (void)argSplit(strchr(str, ' '));
  i--;
  r[i] = str;
  return r;
}

variable_types:
str
char *

variable_types:
r
char **

variable_types: i int

return_type: char **


heapcmp

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

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

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

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

original_code:
static int heapcmp (void *a, void *b){
 if(*(int*)a == -1 || *(int*)b == -1)
  return 1;
 return *(int*)a - *(int*)b;
}

canonical_original_code:
static int heapcmp(void *a, void *b){
 if(*(int *)a == -1 || *(int *)b == -1)
  return 1;
 return *(int *)a - *(int *)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
unsigned __int64 __fastcall edge_new(unsigned int a1, unsigned int a2)
{
return __PAIR64__(a2, a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
return __PAIR64__(a2, a1);
}

original_code:
edge edge_new(int from, int to, int w){
 edge r;
 r.from = from;
 r.to = to;
 r.w = w;
 return r;
}

canonical_original_code:
struct edge edge_new(int from, int to, int w){
 struct edge r;
 r.from = from;
 r.to = to;
 r.w = w;
 return r;
}

variable_types: from int

variable_types: to int

variable_types: w int

variable_types: struct edge { unsigned int from; float w; }


decompiled_code:
unsigned __int64 __fastcall graph_insert(__int64 a1, unsigned __int64 a2, float a3)
{
unsigned __int64 result; // rax
unsigned __int64 v4; // rcx

result = HIDWORD(a2);
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x34u, "graph_insert");
v4 = *(_QWORD *)(a1 + 8);
if ( (unsigned int)a2 >= v4 || v4 <= HIDWORD(a2) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x35u, "graph_insert");
if ( (*(_BYTE *)(a1 + 24) & 1) != 0 )
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = (int)a3;
else
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = 1;
if ( (_DWORD)a2 == HIDWORD(a2) )
*(_BYTE *)(a1 + 24) |= 2u;
++*(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned __int64 a2, float a3)
{
unsigned __int64 result; // rax
unsigned __int64 v4; // rcx

result = HIDWORD(a2);
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x34u, "graph_insert");
v4 = *(_QWORD *)(a1 + 8);
if ( (unsigned int)a2 >= v4 || v4 <= HIDWORD(a2) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x35u, "graph_insert");
if ( (*(_BYTE *)(a1 + 24) & 1) != 0 )
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = (int)a3;
else
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = 1;
if ( (_DWORD)a2 == HIDWORD(a2) )
*(_BYTE *)(a1 + 24) |= 2u;
++*(_QWORD *)(a1 + 16);
return result;
}

original_code:
void graph_insert(graph g, edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 52, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 53, __extension__ __PRETTY_FUNCTION__));
 if(g->orientato)
  g->adj[e.from][e.to] = e.w;
 else
  g->adj[e.from][e.to] = 1;
 if(e.from == e.to)
  g->has_gaps = 1;
 g->e++;
}

canonical_original_code:
void graph_insert(struct graph *g, struct edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 52, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 53, __extension__ __PRETTY_FUNCTION__));
 if(g->orientato)
  g->adj[e.from][e.to] = e.w;
 else
  g->adj[e.from][e.to] = 1;
 if(e.from == e.to)
  g->has_gaps = 1;
 g->e++;
}

variable_types: struct graph { int **adj; unsigned long v; unsigned long e; unsigned int orientato; int connesso; } *

user_defined_types: struct edge { unsigned int from; float w; }


decompiled_code:
__int64 __fastcall graph_remove(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rcx
__int64 result; // rax

if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x41u, "graph_remove");
v2 = *(_QWORD *)(a1 + 8);
if ( (unsigned int)a2 >= v2 || (result = HIDWORD(a2), v2 <= HIDWORD(a2)) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x42u, "graph_remove");
*(_BYTE *)(a1 + 24) |= 0xCu;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = 0;
--*(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rcx
__int64 result; // rax

if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x41u, "graph_remove");
v2 = *(_QWORD *)(a1 + 8);
if ( (unsigned int)a2 >= v2 || (result = HIDWORD(a2), v2 <= HIDWORD(a2)) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x42u, "graph_remove");
*(_BYTE *)(a1 + 24) |= 0xCu;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = 0;
--*(_QWORD *)(a1 + 16);
return result;
}

original_code:
void graph_remove(graph g, edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 65, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 66, __extension__ __PRETTY_FUNCTION__));
 g->connesso = -1;
 g->adj[e.from][e.to] = 0;
 g->e--;
}

canonical_original_code:
void graph_remove(struct graph *g, struct edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 65, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 66, __extension__ __PRETTY_FUNCTION__));
 g->connesso = -1;
 g->adj[e.from][e.to] = 0;
 g->e--;
}

user_defined_types: struct graph { int **adj; unsigned long v; unsigned long e; unsigned int orientato; int connesso; }


decompiled_code:
void __fastcall graph_free(void *ptr)
{
if ( !ptr )
_assert_fail("g != NULL", "graph.c", 0x4Bu, "graph_free");
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( !ptr )
_assert_fail("g != NULL", "graph.c", 0x4Bu, "graph_free");
free(*(void **)ptr);
free(ptr);
}

original_code:
void graph_free(graph g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 75, __extension__ __PRETTY_FUNCTION__));
 free(g->adj);
 free(g);
}

canonical_original_code:
void graph_free(struct graph *g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 75, __extension__ __PRETTY_FUNCTION__));
 free(g->adj);
 free(g);
}


decompiled_code:
__int64 __fastcall graph_vertex(__int64 a1)
{
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x52u, "graph_vertex");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x52u, "graph_vertex");
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t graph_vertex(graph g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 82, __extension__ __PRETTY_FUNCTION__));
 return g->v;
}

canonical_original_code:
unsigned long graph_vertex(struct graph *g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 82, __extension__ __PRETTY_FUNCTION__));
 return g->v;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall graph_is_connected(__int64 a1)
{
return (unsigned int)((char)(16 * *(_BYTE *)(a1 + 24)) >> 6);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return (unsigned int)((char)(16 * *(_BYTE *)(a1 + 24)) >> 6);
}

original_code:
int graph_is_connected(graph g){
 return g->connesso;
}

canonical_original_code:
int graph_is_connected(struct graph *g){
 return g->connesso;
}


original_code:
edge * graph_edges(graph g){
 int i, j, es;
 edge*e;
 if(g == ((void *)0))
  return ((void *)0);
 e = malloc(sizeof(edge) * g->e);
 for(i = es = 0; i < g->v; i++)
  for(j = 0; j < g->v; j++)
   if(g->adj[i][j]){
    e[es] = edge_new(i, j, g->adj[i][j]);
    es++;
   }
 return e;
}

canonical_original_code:
struct edge *graph_edges(struct graph *g){
 int i; int j; int es;
 struct edge *e;
 if(g == ((void *)0))
  return ((void *)0);
 e = malloc(sizeof(edge) * g->e);
 for(i = es = 0; i < g->v; i++)
  for(j = 0; j < g->v; j++)
   if(g->adj[i][j]){
    e[es] = edge_new(i, j, g->adj[i][j]);
    es++;
   }
 return e;
}

variable_types: j int

variable_types: es int

variable_types: struct edge { unsigned int from; float w; } *


decompiled_code:
void graph_dfv()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void graph_dfv(graph g, int s, void*data, void (*visit)(int, void*)){
}

canonical_original_code:
void graph_dfv(struct graph *g, int s, void *data, void (*visit)(int, void *)){
}

variable_types: s int

variable_types:
data
void *

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


decompiled_code:
_DWORD *list_alloc()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

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

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
list_t *list_alloc()
{
  list_t *lp = (list_t *)malloc(sizeof(list_t));
  if (lp != ((void *)0)) {
    lp->head = ((void *)0);
    lp->num = 0;
  }
  return lp;
}

canonical_original_code:
struct list *list_alloc()
{
  struct list *lp = (list_t *)malloc(sizeof(list_t));
  if (lp != ((void *)0)) {
    lp->head = ((void *)0);
    lp->num = 0;
  }
  return lp;
}

variable_types: struct list { struct listNode { void *data; struct listNode *next; } *head; int num; } *

user_defined_types: struct list { struct listNode *head; int num; }


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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

original_code:
int list_num(list_t *lp)
{
  return (lp ? lp->num : 0);
}

canonical_original_code:
int list_num(struct list *lp)
{
  return (lp ? lp->num : 0);
}

user_defined_types: struct listNode { void *data; struct listNode *next; }


decompiled_code:
__int64 __fastcall list_insert(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = newListNode(a2);
if ( !v2 )
return 0LL;
v2[1] = *(_QWORD *)a1;
*(_QWORD *)a1 = v2;
result = (unsigned int)(*(_DWORD *)(a1 + 8) + 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = newListNode(a2);
if ( !v2 )
return 0LL;
v2[1] = *(_QWORD *)a1;
*(_QWORD *)a1 = v2;
result = (unsigned int)(*(_DWORD *)(a1 + 8) + 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
int list_insert(list_t *lp, void *data)
{
  listNode_t *tmp = ((void *)0);
  if (lp == ((void *)0))
    return -1;
  tmp = newListNode(data);
  if (tmp == ((void *)0))
    return 0;
  tmp->next = lp->head;
  lp->head = tmp;
  return ++lp->num;
}

canonical_original_code:
int list_insert(struct list *lp, void *data)
{
  struct listNode *tmp = ((void *)0);
  if (lp == ((void *)0))
    return -1;
  tmp = newListNode(data);
  if (tmp == ((void *)0))
    return 0;
  tmp->next = lp->head;
  lp->head = tmp;
  return ++lp->num;
}

variable_types: struct listNode { void *data; struct listNode *next; } *


original_code:
void *list_remove(list_t *lp, void *data, int (*cmp)(void *, void *))
{
  listNode_t *prev, *succ;
  void *tmp;
  if ((list_num(lp) == 0))
    return ((void *)0);
  prev = lp->head;
  if (cmp(prev->data, data) == 0) {
    lp->num--;
    lp->head = prev->next;
    tmp = prev->data;
    free(prev);
    return tmp;
  }
  succ = prev->next;
  while (succ != ((void *)0)) {
    if (cmp(succ->data, data) == 0) {
      lp->num--;
      prev->next = succ->next;
      tmp = succ->data;
      free(succ);
      return tmp;
    }
    prev = succ;
    succ = succ->next;
  }
  return ((void *)0);
}

canonical_original_code:
void *list_remove(struct list *lp, void *data, int (*cmp)(void *, void *))
{
  struct listNode *prev; struct listNode *succ;
  void *tmp;
  if ((list_num(lp) == 0))
    return ((void *)0);
  prev = lp->head;
  if (cmp(prev->data, data) == 0) {
    lp->num--;
    lp->head = prev->next;
    tmp = prev->data;
    free(prev);
    return tmp;
  }
  succ = prev->next;
  while (succ != ((void *)0)) {
    if (cmp(succ->data, data) == 0) {
      lp->num--;
      prev->next = succ->next;
      tmp = succ->data;
      free(succ);
      return tmp;
    }
    prev = succ;
    succ = succ->next;
  }
  return ((void *)0);
}

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

variable_types:
tmp
void *


decompiled_code:
void __fastcall list_free(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *i; // rbx

if ( ptr )
{
for ( i = *(_QWORD **)ptr; *(_QWORD *)ptr; i = *(_QWORD **)ptr )
{
*(_QWORD *)ptr = i[1];
if ( a2 )
a2(*i);
free(i);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *i; // rbx

if ( ptr )
{
for ( i = *(_QWORD **)ptr; *(_QWORD *)ptr; i = *(_QWORD **)ptr )
{
*(_QWORD *)ptr = i[1];
if ( a2 )
a2(*i);
free(i);
}
free(ptr);
}
}

original_code:
void list_free(list_t *lp, void (*quit)(void *))
{
  listNode_t *tmp;
  if (lp == ((void *)0))
    return;
  while (lp->head != ((void *)0)) {
    tmp = lp->head;
    lp->head = tmp->next;
    if (quit != ((void *)0))
      (*quit)(tmp->data);
    free(tmp);
  }
  free(lp);
}

canonical_original_code:
void list_free(struct list *lp, void (*quit)(void *))
{
  struct listNode *tmp;
  if (lp == ((void *)0))
    return;
  while (lp->head != ((void *)0)) {
    tmp = lp->head;
    lp->head = tmp->next;
    if (quit != ((void *)0))
      (*quit)(tmp->data);
    free(tmp);
  }
  free(lp);
}

variable_types:
quit
void (*)(void *)


decompiled_code:
unsigned int P4()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P4 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func10()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P4 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P4() { printf("Sono il processo " "P4" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P5()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P5 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func11()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P5 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P5() { printf("Sono il processo " "P5" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P6()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P6 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func12()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P6 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P6() { printf("Sono il processo " "P6" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P7()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P7 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func13()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P7 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P7() { printf("Sono il processo " "P7" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P8()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P8 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func14()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P8 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P8() { printf("Sono il processo " "P8" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P9()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P9 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func15()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P9 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P9() { printf("Sono il processo " "P9" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P1()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P1 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func7()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P1 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P1() { printf("Sono il processo " "P1" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P2()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P2 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func8()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P2 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P2() { printf("Sono il processo " "P2" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P3()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P3 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func9()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P3 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P3() { printf("Sono il processo " "P3" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // ebx
int v5; // ebp
int v6; // er14
int v8[5]; // [rsp+0h] [rbp-98h] BYREF
char v9; // [rsp+14h] [rbp-84h] BYREF
__int64 v10[9]; // [rsp+20h] [rbp-78h]
__WAIT_STATUS stat_loc; // [rsp+6Ch] [rbp-2Ch] BYREF

v10[0] = (__int64)P1;
v10[1] = (__int64)P2;
v10[2] = (__int64)P3;
v10[3] = (__int64)P4;
v10[4] = (__int64)P5;
v10[5] = (__int64)P6;
v10[6] = (__int64)P7;
v10[7] = (__int64)P8;
v10[8] = (__int64)P9;
v8[0] = 1;
v8[1] = 3;
v8[2] = 6;
v8[3] = 8;
v8[4] = 9;
v3 = (char *)v8;
v4 = 0;
while ( 1 )
{
v5 = *(_DWORD *)v3;
if ( *(_DWORD *)v3 > v4 )
break;
do
{
LABEL_6:
*(_QWORD *)&argc = &stat_loc;
v6 = wait((__WAIT_STATUS)&stat_loc);
}
while ( v6 != -1 );
if ( *__errno_location() != 10 )
{
fwrite(&unk_402128, 1uLL, 0x16uLL, stderr);
return v6;
}
v3 += 4;
if ( v3 == &v9 )
return 0;
}
while ( 1 )
{
v6 = fork();
if ( !v6 )
break;
if ( ++v4 == v5 )
{
v4 = v5;
goto LABEL_6;
}
}
((void (__fastcall *)(_QWORD, const char **))v10[v4])(*(_QWORD *)&argc, argv);
return v6;
}

original_code:
int main(int argc, char**argv){
  int i, j, st;
  func tree[] = { P1, P2, P3, P4, P5, P6, P7, P8, P9 };
  int idx[] = { 1, 3, 6, 8, 9 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
        tree[j]();
        return 0;
      }
    }
    while( wait(&st) != -1 ) ;
    if(10 != (*__errno_location ())){
      fprintf(stderr, "C'è stato un errore.\n");
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int j; int st;
  void (*tree[])() = { P1, P2, P3, P4, P5, P6, P7, P8, P9 };
  int idx[] = { 1, 3, 6, 8, 9 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
        tree[j]();
        return 0;
      }
    }
    while( wait(&st) != -1 ) ;
    if(10 != (*__errno_location ())){
      fprintf(stderr, "C'è stato un errore.\n");
      return -1;
    }
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: st int

variable_types:
tree
void (*[])()

variable_types:
idx
int []


original_code:
static void *delete_min(bst_t **rootptr)
{
   bst_t *node;
   void *val;
   while ((*rootptr)->left != ((void *)0))
      rootptr = &((*rootptr)->left);
   node = *rootptr;
   val = node->data;
   *rootptr = (*rootptr)->right;
   free(node);
   return val;
}

canonical_original_code:
static void *delete_min(struct bst **rootptr)
{
   struct bst *node;
   void *val;
   while ((*rootptr)->left != ((void *)0))
      rootptr = &((*rootptr)->left);
   node = *rootptr;
   val = node->data;
   *rootptr = (*rootptr)->right;
   free(node);
   return val;
}

variable_types: struct bst { void *data; struct bst *left; struct bst *right; } **

variable_types:
val
void *


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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return *(_QWORD *)v1;
}

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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return *(_QWORD *)v1;
}

original_code:
void *bst_min(bst_t *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->left != ((void *)0))
      root = root->left;
   return root->data;
}

canonical_original_code:
void *bst_min(struct bst *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->left != ((void *)0))
      root = root->left;
   return root->data;
}

variable_types: struct bst { void *data; struct bst *left; struct bst *right; } *


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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return *(_QWORD *)v1;
}

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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return *(_QWORD *)v1;
}

original_code:
void *bst_max(bst_t *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->right != ((void *)0))
      root = root->right;
   return root->data;
}

canonical_original_code:
void *bst_max(struct bst *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->right != ((void *)0))
      root = root->right;
   return root->data;
}

user_defined_types: struct bst { void *data; struct bst *left; struct bst *right; }


decompiled_code:
__int64 __fastcall bst_search(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
_QWORD *v3; // rbx
int v6; // eax

v3 = a1;
if ( !a1 )
return 0LL;
do
{
v6 = a3(a2, *v3);
if ( !v6 )
return *v3;
if ( v6 < 0 )
v3 = (_QWORD *)v3[1];
else
v3 = (_QWORD *)v3[2];
}
while ( v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
_QWORD *v3; // rbx
int v6; // eax

v3 = a1;
if ( !a1 )
return 0LL;
do
{
v6 = a3(a2, *v3);
if ( !v6 )
return *v3;
if ( v6 < 0 )
v3 = (_QWORD *)v3[1];
else
v3 = (_QWORD *)v3[2];
}
while ( v3 );
return 0LL;
}

original_code:
void *bst_search(bst_t *root, void *key, int (*cmp)(void *, void *))
{
 int _cmp;
 while (root != ((void *)0)) {
  _cmp = (*cmp)(key, root->data);
  if (_cmp == 0)
   return root->data;
  if (_cmp < 0)
   root = root->left;
  else
   root = root->right;
 }
 return ((void *)0);
}

canonical_original_code:
void *bst_search(struct bst *root, void *key, int (*cmp)(void *, void *))
{
 int _cmp;
 while (root != ((void *)0)) {
  _cmp = (*cmp)(key, root->data);
  if (_cmp == 0)
   return root->data;
  if (_cmp < 0)
   root = root->left;
  else
   root = root->right;
 }
 return ((void *)0);
}

variable_types:
key
void *


decompiled_code:
__int64 __fastcall bst_visit(_QWORD *a1, __int64 a2, void (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
__int64 result; // rax

if ( a1 )
{
if ( (_DWORD)a2 == -1 )
{
a3(*a1, a4);
bst_visit(a1[1], 0xFFFFFFFFLL, a3, a4);
result = bst_visit(a1[2], 0xFFFFFFFFLL, a3, a4);
}
else
{
bst_visit(a1[1], a2, a3, a4);
if ( (_DWORD)a2 )
{
result = bst_visit(a1[2], (unsigned int)a2, a3, a4);
if ( (_DWORD)a2 == 1 )
result = ((__int64 (__fastcall *)(_QWORD, __int64))a3)(*a1, a4);
}
else
{
a3(*a1, a4);
result = bst_visit(a1[2], 0LL, a3, a4);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, void (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
__int64 result; // rax

if ( a1 )
{
if ( (_DWORD)a2 == -1 )
{
a3(*a1, a4);
func6(a1[1], 0xFFFFFFFFLL, a3, a4);
result = func6(a1[2], 0xFFFFFFFFLL, a3, a4);
}
else
{
func6(a1[1], a2, a3, a4);
if ( (_DWORD)a2 )
{
result = func6(a1[2], (unsigned int)a2, a3, a4);
if ( (_DWORD)a2 == 1 )
result = ((__int64 (__fastcall *)(_QWORD, __int64))a3)(*a1, a4);
}
else
{
a3(*a1, a4);
result = func6(a1[2], 0LL, a3, a4);
}
}
}
return result;
}

original_code:
void bst_visit(bst_t *root, int way, void (*visit)(void *, void *), void *ptr)
{
   if (root == ((void *)0))
      return;
   if (way == -1)
      (*visit)(root->data, ptr);
   bst_visit(root->left, way, visit, ptr);
   if (way == 0)
      (*visit)(root->data, ptr);
   bst_visit(root->right, way, visit, ptr);
   if (way == 1)
      (*visit)(root->data, ptr);
}

canonical_original_code:
void bst_visit(struct bst *root, int way, void (*visit)(void *, void *), void *ptr)
{
   if (root == ((void *)0))
      return;
   if (way == -1)
      (*visit)(root->data, ptr);
   bst_visit(root->left, way, visit, ptr);
   if (way == 0)
      (*visit)(root->data, ptr);
   bst_visit(root->right, way, visit, ptr);
   if (way == 1)
      (*visit)(root->data, ptr);
}

variable_types: way int

variable_types:
visit
void (*)(void *, void *)

variable_types:
ptr
void *


decompiled_code:
void __fastcall bst_free(void *ptr, void (__fastcall *a2)(_QWORD))
{
if ( ptr )
{
bst_free(*((void **)ptr + 1));
bst_free(*((void **)ptr + 2));
if ( a2 )
a2(*(_QWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr, void (__fastcall *a2)(_QWORD))
{
if ( ptr )
{
func8(*((void **)ptr + 1));
func8(*((void **)ptr + 2));
if ( a2 )
a2(*(_QWORD *)ptr);
free(ptr);
}
}

original_code:
void bst_free(bst_t *root, void (*quit)(void *))
{
   if (root == ((void *)0))
      return;
   bst_free(root->left, quit);
   bst_free(root->right, quit);
   if (quit != ((void *)0))
      (*quit)(root->data);
   free(root);
}

canonical_original_code:
void bst_free(struct bst *root, void (*quit)(void *))
{
   if (root == ((void *)0))
      return;
   bst_free(root->left, quit);
   bst_free(root->right, quit);
   if (quit != ((void *)0))
      (*quit)(root->data);
   free(root);
}


decompiled_code:
int __fastcall file_copy(int fd, int a2)
{
int v2; // eax

while ( 1 )
{
v2 = read(fd, &buff_0, 0x1000uLL);
if ( !v2 )
break;
write(a2, &buff_0, v2);
}
close(fd);
return close(a2);
}

canonical_decompiled_code:
int __fastcall func7(int fd, int a2)
{
int v2; // eax

while ( 1 )
{
v2 = read(fd, &buff_0, 0x1000uLL);
if ( !v2 )
break;
write(a2, &buff_0, v2);
}
close(fd);
return close(a2);
}

original_code:
void file_copy(int fdf, int fdt){
  static char buff[4096];
  int r;
  while((r = read(fdf, buff, 4096))){
    write(fdt, buff, r);
  }
  close(fdf);
  close(fdt);
}

variable_types: fdf int

variable_types: fdt int

variable_types:
buff
char [4096]

variable_types: r int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
puts("Utilizzo: copy <from> <to>");
else
dir_copy((char *)argv[1], (char *)argv[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
puts("Utilizzo: copy <from> <to>");
else
func9((char *)argv[1], (char *)argv[2]);
return 0;
}

original_code:
int main(int argc, char *argv[]){
  if(argc < 3){
    puts("Utilizzo: copy <from> <to>");
    return 0;
  }
  dir_copy(argv[1], argv[2]);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


find

decompiled_code:
__int64 __fastcall find(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int (__fastcall *a5)(__int64, __int64))
{
__int64 v6; // rbx

v6 = a2;
if ( !a2 )
return 0xFFFFFFFFLL;
while ( 1 )
{
a1 -= a3;
if ( !a5(a1, a4) )
break;
if ( !--v6 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v6 - 1);
}

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

v6 = a2;
if ( !a2 )
return 0xFFFFFFFFLL;
while ( 1 )
{
a1 -= a3;
if ( !a5(a1, a4) )
break;
if ( !--v6 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v6 - 1);
}

original_code:
int find(const void*haystack, size_t n, size_t s, const void *needle, int (*compare)(const void*, const void*)){
 const char*_m = (const char*)haystack;
 if(n == 0)
  return -1;
 while(n){
  _m -= s;
  if(compare(_m, needle) == 0) return n-1;
  n--;
 }
 return -1;
}

canonical_original_code:
int find(void *haystack, unsigned long n, unsigned long s, void *needle, int (*compare)(void *, void *)){
 char *_m = (const char*)haystack;
 if(n == 0)
  return -1;
 while(n){
  _m -= s;
  if(compare(_m, needle) == 0) return n-1;
  n--;
 }
 return -1;
}

variable_types:
haystack
void *

variable_types:
n
unsigned long

variable_types:
s
unsigned long

variable_types:
needle
void *

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


bracket

original_code:
const char* bracket(const char*c, double*res){
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return ((void *)0);
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c +=n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      c = bracket(c+1, &tmp);
      *res = larg + tmp;
      return c;
    case '-':
      c = bracket(c+1, &tmp);
      *res = larg - tmp;
      return c;
    default:
      error = badformat;
    }
  }
  if(*c == '\0')
    error = parmismatch;
  *res = larg;
  return c+1;
}

canonical_original_code:
char *bracket(char *c, double *res){
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return ((void *)0);
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c +=n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      c = bracket(c+1, &tmp);
      *res = larg + tmp;
      return c;
    case '-':
      c = bracket(c+1, &tmp);
      *res = larg - tmp;
      return c;
    default:
      error = badformat;
    }
  }
  if(*c == '\0')
    error = parmismatch;
  *res = larg;
  return c+1;
}

variable_types:
c
char *

variable_types:
res
double *

variable_types: tmp double

variable_types: larg double

variable_types: n int


eval

original_code:
double eval(const char*c) {
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return 0;
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c += n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      return larg + eval(c+1);
    case '-':
      return larg - eval(c+1);
    default:
      error = badformat;
    }
  }
  return larg;
}

canonical_original_code:
double eval(char *c) {
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return 0;
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c += n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      return larg + eval(c+1);
    case '-':
      return larg - eval(c+1);
    default:
      error = badformat;
    }
  }
  return larg;
}

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
double v5; // xmm0_8

v3 = 1LL;
if ( argc > 1 )
{
do
{
v5 = eval(argv[v3]);
printf("%s = %lf\n", argv[v3], v5);
if ( error )
{
printf("Errore nell'argomento %d: %s\n", (unsigned int)v3, errs_2[error - 1]);
error = 0;
}
++v3;
}
while ( v3 != argc );
}
else
{
puts("Utilizzo:\n\teval expression1 [expression2 [...] ]");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
double v5; // xmm0_8

v3 = 1LL;
if ( argc > 1 )
{
do
{
v5 = func8(argv[v3]);
printf("%s = %lf\n", argv[v3], v5);
if ( error )
{
printf("Errore nell'argomento %d: %s\n", (unsigned int)v3, errs_2[error - 1]);
error = 0;
}
++v3;
}
while ( v3 != argc );
}
else
{
puts("Utilizzo:\n\teval expression1 [expression2 [...] ]");
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  int i;
  static const char* errs [] = {
    "Stringa vuota",
    "Errore di formattazione",
    "Errore di parentesizzazione"
  };
  if(argc < 2) {
    printf("Utilizzo:\n\teval expression1 [expression2 [...] ]\n");
    return 0;
  }
  for(i = 1; i<argc; i++){
    printf("%s = %lf\n", argv[i], eval(argv[i]));
    if(error){
      printf("Errore nell'argomento %d: %s\n", i, errs[(int)error-1]);
      error = none;
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i;
  static char *errs[] = {
    "Stringa vuota",
    "Errore di formattazione",
    "Errore di parentesizzazione"
  };
  if(argc < 2) {
    printf("Utilizzo:\n\teval expression1 [expression2 [...] ]\n");
    return 0;
  }
  for(i = 1; i<argc; i++){
    printf("%s = %lf\n", argv[i], eval(argv[i]));
    if(error){
      printf("Errore nell'argomento %d: %s\n", i, errs[(int)error-1]);
      error = none;
    }
  }
  return 0;
}

variable_types: i int

variable_types:
errs
char *[]


decompiled_code:
__int64 __fastcall stack_pop(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
*a2 = *a1;
v2 = a1[1];
free(a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
*a2 = *a1;
v2 = a1[1];
free(a1);
return v2;
}

original_code:
stack_t *stack_pop(stack_t *sp, void **valptr)
{
  stack_t *node = sp;
  if (sp == ((void *)0))
     return ((void *)0);
  *valptr = sp->data;
  sp = sp->next;
  free(node);
  return sp;
}

canonical_original_code:
struct stack *stack_pop(struct stack *sp, void **valptr)
{
  struct stack *node = sp;
  if (sp == ((void *)0))
     return ((void *)0);
  *valptr = sp->data;
  sp = sp->next;
  free(node);
  return sp;
}

variable_types:
sp
struct stack *

variable_types:
valptr
void **

variable_types: struct stack { void *data; struct stack *next; } *


Queue

repo: marcobenatto/graphollock

decompiled_code:
__int64 __fastcall Queue(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

LODWORD(result) = *(_DWORD *)(a1 + 4);
if ( (int)result >= *(_DWORD *)(a1 + 8) )
{
fwrite("Don't have space enought in the queue...fisinhing....\n", 1uLL, 0x36uLL, stderr);
exit(12);
}
v3 = *(_QWORD *)(a1 + 16);
*(_DWORD *)(a1 + 4) = result + 1;
result = (int)result;
*(_DWORD *)(v3 + 4LL * (int)result) = a2;
return result;
}

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

LODWORD(result) = *(_DWORD *)(a1 + 4);
if ( (int)result >= *(_DWORD *)(a1 + 8) )
{
fwrite("Don't have space enought in the queue...fisinhing....\n", 1uLL, 0x36uLL, stderr);
exit(12);
}
v3 = *(_QWORD *)(a1 + 16);
*(_DWORD *)(a1 + 4) = result + 1;
result = (int)result;
*(_DWORD *)(v3 + 4LL * (int)result) = a2;
return result;
}

original_code:
void Queue(queue *q, int v){
 if (q->end >= q->size){
  fprintf(stderr, "Don't have space enought in the queue...fisinhing....\n");
  exit(12);
 }
 q->data[q->end++] = v;
}

canonical_original_code:
void Queue(struct queue *q, int v){
 if (q->end >= q->size){
  fprintf(stderr, "Don't have space enought in the queue...fisinhing....\n");
  exit(12);
 }
 q->data[q->end++] = v;
}

variable_types: struct queue { int start; int end; int size; int *data; } *

variable_types: v int