decompiled_code:
__int64 __fastcall vm_prn(int *a1)
{
__int64 v1; // rbp

v1 = g_strdup_printf(&unk_9D3, (unsigned int)a1[*a1 + 1]);
(*((void (__fastcall **)(_QWORD, __int64))a1 + 32773))(*((_QWORD *)a1 + 32774), v1);
--*a1;
return g_free(v1);
}

original_code:
static void vm_prn(VM *vm, VMInstruction *i)
{
  gchar *tmp;
  tmp = g_strdup_printf("%d", vm->memory[vm->stack_top]);
  vm->write_function(vm->write_function_data, tmp);
  vm->stack_top--;
  g_free(tmp);
}

canonical_original_code:
static void vm_prn(struct _VM *vm, struct _VMInstruction *i)
{
  char *tmp;
  tmp = g_strdup_printf("%d", vm->memory[vm->stack_top]);
  vm->write_function(vm->write_function_data, tmp);
  vm->stack_top--;
  g_free(tmp);
}

variable_types:
tmp
char *


repo: lpereira/compilador-tosco

decompiled_code:
__int64 __fastcall vm_rd(int *a1)
{
const char *v1; // rax
int v2; // er8
__int64 result; // rax

++*a1;
v1 = (const char *)(*((__int64 (__fastcall **)(_QWORD))a1 + 32772))(*((_QWORD *)a1 + 32775));
v2 = atoi(v1);
result = *a1;
a1[result + 1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(int *a1)
{
const char *v1; // rax
int v2; // er8
__int64 result; // rax

++*a1;
v1 = (const char *)(*((__int64 (__fastcall **)(_QWORD))a1 + 32772))(*((_QWORD *)a1 + 32775));
v2 = atoi(v1);
result = *a1;
a1[result + 1] = v2;
return result;
}

original_code:
static void vm_rd(VM *vm, VMInstruction *i)
{
  vm->stack_top++;
  vm->memory[vm->stack_top] = atoi(vm->read_function(vm->read_function_data));
}

canonical_original_code:
static void vm_rd(struct _VM *vm, struct _VMInstruction *i)
{
  vm->stack_top++;
  vm->memory[vm->stack_top] = atoi(vm->read_function(vm->read_function_data));
}

variable_types: struct _VM { int stack_top; int memory[65536]; struct _GList { void *data; struct _GList *next; struct _GList *prev; } *program; int running; char *(*read_function)(void *data); void (*write_function)(void *data, char *string); void *write_function_data; } *

variable_types: struct _VMInstruction { enum VMOpcode { OP_LABEL=0, OP_LDC=1, OP_LDV=2, OP_ADD=3, OP_SUB=4, OP_MULT=5, OP_DIVI=6, OP_INV=7, OP_AND=8, OP_OR=9, OP_NEG=10, OP_CME=11, OP_CMA=12, OP_CEQ=13, OP_CDIF=14, OP_CMEQ=15, OP_CMAQ=16, OP_JMP=17, OP_JMPF=18, OP_ALLOC=19, OP_DALLOC=20, OP_START=21, OP_HLT=22, OP_CALL=23, OP_RETURN=24, OP_RETURNF=25, OP_RD=26, OP_PRN=27, OP_STR=28, N_OP=29 } opcode; unsigned int param1; char *sparam1; char *label_name; void *data; } *

return_type: void

user_defined_types: struct _VM { int stack_top; int memory[65536]; struct _GList *program; int running; char *(*read_function)(void *data); void (*write_function)(void *data, char *string); void *write_function_data; }

user_defined_types: struct _VMInstruction { enum VMOpcode opcode; unsigned int param1; char *sparam1; char *label_name; void *data; }


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

result = g_list_nth(*((_QWORD *)a1 + 32769), (unsigned int)(a1[*a1 + 1] - 1));
--*a1;
*((_QWORD *)a1 + 32770) = result;
return result;
}

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

result = g_list_nth(*((_QWORD *)a1 + 32769), (unsigned int)(a1[*a1 + 1] - 1));
--*a1;
*((_QWORD *)a1 + 32770) = result;
return result;
}

original_code:
static void vm_return(VM *vm, VMInstruction *i)
{
  vm->instruction_pointer = g_list_nth(vm->program, vm->memory[vm->stack_top] - 1);
  vm->stack_top--;
}

canonical_original_code:
static void vm_return(struct _VM *vm, struct _VMInstruction *i)
{
  vm->instruction_pointer = g_list_nth(vm->program, vm->memory[vm->stack_top] - 1);
  vm->stack_top--;
}

user_defined_types: enum VMOpcode { OP_LABEL=0, OP_LDC=1, OP_LDV=2, OP_ADD=3, OP_SUB=4, OP_MULT=5, OP_DIVI=6, OP_INV=7, OP_AND=8, OP_OR=9, OP_NEG=10, OP_CME=11, OP_CMA=12, OP_CEQ=13, OP_CDIF=14, OP_CMEQ=15, OP_CMAQ=16, OP_JMP=17, OP_JMPF=18, OP_ALLOC=19, OP_DALLOC=20, OP_START=21, OP_HLT=22, OP_CALL=23, OP_RETURN=24, OP_RETURNF=25, OP_RD=26, OP_PRN=27, OP_STR=28, N_OP=29 }

user_defined_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; }


decompiled_code:
__int64 __fastcall vm_returnf(int *a1, __int64 a2)
{
int v2; // er12
__int64 result; // rax

v2 = a1[*(unsigned int *)(a2 + 4) + 1];
*(_DWORD *)(a2 + 8) = 1;
vm_dalloc(a1, a2);
vm_return(a1);
LODWORD(result) = *a1 + 1;
*a1 = result;
result = (int)result;
a1[(int)result + 1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func25(int *a1, __int64 a2)
{
int v2; // er12
__int64 result; // rax

v2 = a1[*(unsigned int *)(a2 + 4) + 1];
*(_DWORD *)(a2 + 8) = 1;
func18(a1, a2);
func24(a1);
LODWORD(result) = *a1 + 1;
*a1 = result;
result = (int)result;
a1[(int)result + 1] = v2;
return result;
}

original_code:
static void vm_returnf(VM *vm, VMInstruction *i)
{
  gint return_value;
  return_value = vm->memory[i->param1];
  i->param2 = 1;
  vm_dalloc(vm, i);
  vm_return(vm, i);
  vm->memory[++vm->stack_top] = return_value;
}

canonical_original_code:
static void vm_returnf(struct _VM *vm, struct _VMInstruction *i)
{
  int return_value;
  return_value = vm->memory[i->param1];
  i->param2 = 1;
  vm_dalloc(vm, i);
  vm_return(vm, i);
  vm->memory[++vm->stack_top] = return_value;
}


decompiled_code:
__int64 __fastcall vm_jmp(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = g_list_nth(*(_QWORD *)(a1 + 262152), (unsigned int)(*(_DWORD *)(a2 + 4) - 1));
*(_QWORD *)(a1 + 262160) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = g_list_nth(*(_QWORD *)(a1 + 262152), (unsigned int)(*(_DWORD *)(a2 + 4) - 1));
*(_QWORD *)(a1 + 262160) = result;
return result;
}

original_code:
static void vm_jmp(VM *vm, VMInstruction *i)
{
  vm->instruction_pointer = g_list_nth(vm->program, i->param1 - 1);
}

canonical_original_code:
static void vm_jmp(struct _VM *vm, struct _VMInstruction *i)
{
  vm->instruction_pointer = g_list_nth(vm->program, i->param1 - 1);
}


decompiled_code:
__int64 __fastcall vm_jmpf(int *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *a1;
if ( a1[v2 + 1] )
{
result = (unsigned int)(v2 - 1);
}
else
{
vm_jmp((__int64)a1, a2);
result = (unsigned int)(*a1 - 1);
}
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func27(int *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *a1;
if ( a1[v2 + 1] )
{
result = (unsigned int)(v2 - 1);
}
else
{
func26((__int64)a1, a2);
result = (unsigned int)(*a1 - 1);
}
*a1 = result;
return result;
}

original_code:
static void vm_jmpf(VM *vm, VMInstruction *i)
{
  if (vm->memory[vm->stack_top] == 0) {
    vm_jmp(vm, i);
  }
  vm->stack_top--;
}

canonical_original_code:
static void vm_jmpf(struct _VM *vm, struct _VMInstruction *i)
{
  if (vm->memory[vm->stack_top] == 0) {
    vm_jmp(vm, i);
  }
  vm->stack_top--;
}


original_code:
static void vm_call(VM *vm, VMInstruction *i)
{
  vm->stack_top++;
  vm->memory[vm->stack_top] = g_list_position(vm->program,
                                              vm->instruction_pointer) + 1;
  vm_jmp(vm, i);
}

canonical_original_code:
static void vm_call(struct _VM *vm, struct _VMInstruction *i)
{
  vm->stack_top++;
  vm->memory[vm->stack_top] = g_list_position(vm->program,
                                              vm->instruction_pointer) + 1;
  vm_jmp(vm, i);
}


decompiled_code:
int __fastcall vm_default_write_function(__int64 a1, const char *a2)
{
return printf(">>> %s\n", a2);
}

canonical_decompiled_code:
int __fastcall func29(__int64 a1, const char *a2)
{
return printf(">>> %s\n", a2);
}

original_code:
static void
vm_default_write_function(gpointer data, char *string)
{
  printf(">>> %s\n", string);
}

canonical_original_code:
static void vm_default_write_function(void *data, char *string)
{
  printf(">>> %s\n", string);
}

variable_types:
data
void *

variable_types:
string
char *


decompiled_code:
char *vm_default_read_function()
{
printf("<<< ");
fgets(buffer_0, 128, stdin);
return buffer_0;
}

canonical_decompiled_code:
char *func30()
{
printf("<<< ");
fgets(buffer_0, 128, stdin);
return buffer_0;
}

original_code:
static gchar *
vm_default_read_function(gpointer data)
{
  static char buffer[128];
  printf("<<< ");
  fgets(buffer, 128, stdin);
  return buffer;
}

canonical_original_code:
static char *vm_default_read_function(void *data)
{
  static char buffer[128];
  printf("<<< ");
  fgets(buffer, 128, stdin);
  return buffer;
}

variable_types:
buffer
char [128]

return_type: char *


decompiled_code:
// attributes: thunk
__int64 __fastcall vm_destroy(__int64 a1)
{
return g_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func31(__int64 a1)
{
return g_free(a1);
}

original_code:
void
vm_destroy(VM *vm)
{
  g_free(vm);
}

canonical_original_code:
void vm_destroy(struct _VM *vm)
{
  g_free(vm);
}


original_code:
void
vm_reset(VM *vm)
{
  vm->running = (0);
  vm->stack_top = -1;
  vm->instruction_pointer = vm->program;
  memset(vm->memory, 0, sizeof(vm->memory));
}

canonical_original_code:
void vm_reset(struct _VM *vm)
{
  vm->running = (0);
  vm->stack_top = -1;
  vm->instruction_pointer = vm->program;
  memset(vm->memory, 0, sizeof(vm->memory));
}


original_code:
void
vm_object_unload(VM *vm)
{
  VMInstruction *instruction;
  GList *list;
  for (list = vm->program; list; list = list->next) {
    instruction = (VMInstruction *)list->data;
    g_free(instruction->sparam1);
    g_free(instruction->sparam2);
    g_free(instruction->label_name);
    g_free(instruction);
  }
  g_list_free(vm->program);
  vm->program = ((void *)0);
}

canonical_original_code:
void vm_object_unload(struct _VM *vm)
{
  struct _VMInstruction *instruction;
  struct _GList *list;
  for (list = vm->program; list; list = list->next) {
    instruction = (struct _VMInstruction *)list->data;
    g_free(instruction->sparam1);
    g_free(instruction->sparam2);
    g_free(instruction->label_name);
    g_free(instruction);
  }
  g_list_free(vm->program);
  vm->program = ((void *)0);
}

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *


original_code:
void
vm_step(VM *vm)
{
  VMInstruction *instruction;
  if (!vm->program || !vm->instruction_pointer)
    return;
  if ((instruction = (VMInstruction *)vm->instruction_pointer->data)) {
    vm->instruction_pointer = vm->instruction_pointer->next;
    instructions[instruction->opcode].callback(vm, instruction);
  }
}

canonical_original_code:
void vm_step(struct _VM *vm)
{
  struct _VMInstruction *instruction;
  if (!vm->program || !vm->instruction_pointer)
    return;
  if ((instruction = (struct _VMInstruction *)vm->instruction_pointer->data)) {
    vm->instruction_pointer = vm->instruction_pointer->next;
    instructions[instruction->opcode].callback(vm, instruction);
  }
}


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

result = (_QWORD *)g_malloc0(16LL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = (_QWORD *)g_malloc0(16LL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
SymbolTable *
symbol_table_new(void)
{
  SymbolTable *st;
  st = ((SymbolTable *) g_malloc0_n ((1), sizeof (SymbolTable)));
  st->root = ((void *)0);
  st->current_level = ((void *)0);
  return st;
}

canonical_original_code:
struct _SymbolTable *symbol_table_new()
{
  struct _SymbolTable *st;
  st = ((struct _SymbolTable *) g_malloc0_n ((1), sizeof (SymbolTable)));
  st->root = ((void *)0);
  st->current_level = ((void *)0);
  return st;
}

variable_types: struct _SymbolTable { struct _GNode { void *data; struct _GNode *next; struct _GNode *prev; struct _GNode *parent; struct _GNode *children; } *root; struct _GNode *current_level; } *

user_defined_types: struct _SymbolTable { struct _GNode *root; struct _GNode *current_level; }


decompiled_code:
__int64 __fastcall symbol_table_is_defined(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
int v4; // ebp

v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
return 0LL;
v4 = a3;
if ( !a3 )
return 0LL;
while ( !symbol_table_get_node_at_context_constprop_0_isra_0(*(_QWORD *)(v3 + 32), a2) )
{
v3 = *(_QWORD *)(v3 + 24);
if ( v3 )
{
if ( --v4 )
continue;
}
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
int v4; // ebp

v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
return 0LL;
v4 = a3;
if ( !a3 )
return 0LL;
while ( !func0(*(_QWORD *)(v3 + 32), a2) )
{
v3 = *(_QWORD *)(v3 + 24);
if ( v3 )
{
if ( --v4 )
continue;
}
return 0LL;
}
return 1LL;
}

original_code:
gboolean
symbol_table_is_defined(SymbolTable *st, gchar *name, gint level)
{
  GNode *l;
  for (l = st->current_level; l && level--; l = l->parent) {
    if (symbol_table_get_node_at_context(st, l, name)) {
        return (!(0));
    }
  }
  return (0);
}

canonical_original_code:
int symbol_table_is_defined(struct _SymbolTable *st, char *name, int level)
{
  struct _GNode *l;
  for (l = st->current_level; l && level--; l = l->parent) {
    if (symbol_table_get_node_at_context(st, l, name)) {
        return (!(0));
    }
  }
  return (0);
}

variable_types:
name
char *

variable_types: level int

variable_types: struct _GNode { void *data; struct _GNode *next; struct _GNode *prev; struct _GNode *parent; struct _GNode *children; } *

return_type: int


decompiled_code:
__int64 __fastcall symbol_table_lookup_symbol(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax

v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = symbol_table_get_node_at_context_constprop_0_isra_0(*(_QWORD *)(v2 + 32), a2);
if ( v3 )
break;
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return *(_QWORD *)v3;
}

original_code:
Symbol *
symbol_table_lookup_symbol(SymbolTable *st, gchar *name)
{
  GNode *level, *node;
  for (level = st->current_level; level; level = level->parent) {
    if ((node = symbol_table_get_node_at_context(st, level, name))) {
       return (Symbol *)node->data;
    }
  }
  return ((void *)0);
}

canonical_original_code:
struct _Symbol *symbol_table_lookup_symbol(struct _SymbolTable *st, char *name)
{
  struct _GNode *level; struct _GNode *node;
  for (level = st->current_level; level; level = level->parent) {
    if ((node = symbol_table_get_node_at_context(st, level, name))) {
       return (struct _Symbol *)node->data;
    }
  }
  return ((void *)0);
}

return_type: struct _Symbol { char *name; enum SymbolType { ST_NONE=0, ST_VARIABLE=1, ST_FUNCTION=2, ST_PROCEDURE=3, ST_PROGRAM=4 } type; enum SymbolSubType { SST_NONE=0, SST_INTEGER=1, SST_BOOLEAN=2 } subtype; int memory_address; } *

user_defined_types: struct _GNode { void *data; struct _GNode *next; struct _GNode *prev; struct _GNode *parent; struct _GNode *children; }

user_defined_types: struct _Symbol { char *name; enum SymbolType type; enum SymbolSubType subtype; int memory_address; }


decompiled_code:
_BOOL8 __fastcall symbol_table_is_installed(__int64 a1, __int64 a2)
{
return symbol_table_lookup_symbol(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, __int64 a2)
{
return func6(a1, a2) != 0;
}

original_code:
gboolean
symbol_table_is_installed(SymbolTable *st, gchar *name)
{
  return symbol_table_lookup_symbol(st, name) != ((void *)0);
}

canonical_original_code:
int symbol_table_is_installed(struct _SymbolTable *st, char *name)
{
  return symbol_table_lookup_symbol(st, name) != ((void *)0);
}


decompiled_code:
__int64 __fastcall symbol_table_get_attribute_int(__int64 a1, __int64 a2, int a3)
{
unsigned int *v4; // rax

v4 = (unsigned int *)symbol_table_lookup_symbol(a1, a2);
if ( !v4 )
return 0LL;
if ( a3 == 1 )
return v4[3];
if ( a3 == 2 )
return v4[4];
if ( a3 )
return 0LL;
return v4[2];
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, int a3)
{
unsigned int *v4; // rax

v4 = (unsigned int *)func6(a1, a2);
if ( !v4 )
return 0LL;
if ( a3 == 1 )
return v4[3];
if ( a3 == 2 )
return v4[4];
if ( a3 )
return 0LL;
return v4[2];
}

original_code:
gint
symbol_table_get_attribute_int(SymbolTable *st, gchar *name, SymbolTableField field)
{
  Symbol *symbol;
  if ((symbol = symbol_table_lookup_symbol(st, name))) {
    switch (field) {
    case STF_TYPE:
      return symbol->type;
    case STF_SUBTYPE:
      return symbol->subtype;
    case STF_MEMORY_ADDRESS:
      return symbol->memory_address;
    default: return 0;
    }
  }
  return 0;
}

canonical_original_code:
int symbol_table_get_attribute_int(struct _SymbolTable *st, char *name, enum SymbolTableField field)
{
  struct _Symbol *symbol;
  if ((symbol = symbol_table_lookup_symbol(st, name))) {
    switch (field) {
    case STF_TYPE:
      return symbol->type;
    case STF_SUBTYPE:
      return symbol->subtype;
    case STF_MEMORY_ADDRESS:
      return symbol->memory_address;
    default: return 0;
    }
  }
  return 0;
}

variable_types: enum SymbolTableField { STF_TYPE=0, STF_SUBTYPE=1, STF_MEMORY_ADDRESS=2 }

variable_types: struct _Symbol { char *name; enum SymbolType { ST_NONE=0, ST_VARIABLE=1, ST_FUNCTION=2, ST_PROCEDURE=3, ST_PROGRAM=4 } type; enum SymbolSubType { SST_NONE=0, SST_INTEGER=1, SST_BOOLEAN=2 } subtype; int memory_address; } *


decompiled_code:
void __fastcall symbol_table_context_enter(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rax

v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
v4 = symbol_table_get_node_at_current_context_isra_0(v3, a2);
if ( v4 )
*(_QWORD *)(a1 + 8) = v4;
}
}

original_code:
void
symbol_table_context_enter(SymbolTable *st, gchar *context)
{
  GNode *node;
  if (!st->current_level) {
    return;
  }
  if ((node = symbol_table_get_node_at_current_context(st, context))) {
    st->current_level = node;
  }
}

canonical_original_code:
void symbol_table_context_enter(struct _SymbolTable *st, char *context)
{
  struct _GNode *node;
  if (!st->current_level) {
    return;
  }
  if ((node = symbol_table_get_node_at_current_context(st, context))) {
    st->current_level = node;
  }
}

variable_types:
context
char *


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

result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void
symbol_table_context_leave(SymbolTable *st)
{
  st->current_level = st->current_level->parent;
}

canonical_original_code:
void symbol_table_context_leave(struct _SymbolTable *st)
{
  st->current_level = st->current_level->parent;
}


decompiled_code:
__int64 __fastcall symbol_table_get_context_level(__int64 a1)
{
return g_node_depth(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return g_node_depth(*(_QWORD *)(a1 + 8));
}

original_code:
gint
symbol_table_get_context_level(SymbolTable *st)
{
  return g_node_depth(st->current_level);
}

canonical_original_code:
int symbol_table_get_context_level(struct _SymbolTable *st)
{
  return g_node_depth(st->current_level);
}


decompiled_code:
int __fastcall symbol_table_print(__int64 **a1)
{
return symbol_table_print_func_isra_0(*a1);
}

canonical_decompiled_code:
int __fastcall func13(__int64 **a1)
{
return func1(*a1);
}

original_code:
void
symbol_table_print(SymbolTable *st)
{
  symbol_table_print_func(st, st->root);
}

canonical_original_code:
void symbol_table_print(struct _SymbolTable *st)
{
  symbol_table_print_func(st, st->root);
}


decompiled_code:
// attributes: thunk
int __fastcall symbol_table_free(__int64 **a1)
{
return symbol_table_print(a1);
}

canonical_decompiled_code:
int __fastcall func14(__int64 **a1)
{
return func13(a1);
}

original_code:
void
symbol_table_free(SymbolTable *st)
{
  symbol_table_print(st);
}

canonical_original_code:
void symbol_table_free(struct _SymbolTable *st)
{
  symbol_table_print(st);
}


decompiled_code:
__int64 symbol_table_test_main()
{
__int64 v0; // rbp

v0 = lex();
ast(v0);
tl_unref(v0);
symbol_table_print(symbol_table);
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 v0; // rbp

v0 = lex();
ast(v0);
tl_unref(v0);
func13(symbol_table);
return 0LL;
}

original_code:
int
symbol_table_test_main(int argc, char **argv)
{
    GNode *root;
    TokenList *token_list;
    token_list = lex();
    root = ast(token_list);
    tl_unref(token_list);
    symbol_table_print(symbol_table);
    return 0;
}

canonical_original_code:
int symbol_table_test_main(int argc, char **argv)
{
    struct _GNode *root;
    struct _TokenList *token_list;
    token_list = lex();
    root = ast(token_list);
    tl_unref(token_list);
    symbol_table_print(symbol_table);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct _TokenList { struct _GList { void *data; struct _GList *next; struct _GList *prev; } *tokens; int ref_count; } *

user_defined_types: struct _TokenList { struct _GList *tokens; int ref_count; }


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

result = g_slist_prepend(char_buf, a1);
char_buf = result;
return result;
}

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

result = g_slist_prepend(char_buf, a1);
char_buf = result;
return result;
}

original_code:
void
char_buf_put_char(char ch)
{
 char_buf = g_slist_prepend(char_buf, ((gpointer) (glong) ((gint)ch)));
}

canonical_original_code:
void char_buf_put_char(char ch)
{
 char_buf = g_slist_prepend(char_buf, ((gpointer) (glong) ((int)ch)));
}

variable_types: ch char


decompiled_code:
__int64 __fastcall char_buf_put_string(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 v2; // rdi
__int64 v3; // rax
char v4; // si
__int64 result; // rax

if ( *a1 )
{
v1 = a1;
v2 = 0LL;
do
{
v3 = g_slist_append(v2);
v4 = *++v1;
v2 = v3;
}
while ( v4 );
}
else
{
v2 = 0LL;
}
result = g_slist_concat(v2, char_buf);
char_buf = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 v2; // rdi
__int64 v3; // rax
char v4; // si
__int64 result; // rax

if ( *a1 )
{
v1 = a1;
v2 = 0LL;
do
{
v3 = g_slist_append(v2);
v4 = *++v1;
v2 = v3;
}
while ( v4 );
}
else
{
v2 = 0LL;
}
result = g_slist_concat(v2, char_buf);
char_buf = result;
return result;
}

original_code:
void
char_buf_put_string(gchar *string)
{
 GSList *temp = ((void *)0);
 while (*string) {
  temp = g_slist_append(temp, ((gpointer) (glong) ((gint)*string++)));
 }
 char_buf = g_slist_concat(temp, char_buf);
}

canonical_original_code:
void char_buf_put_string(char *string)
{
 struct _GSList *temp = ((void *)0);
 while (*string) {
  temp = g_slist_append(temp, ((gpointer) (glong) ((gint)*string++)));
 }
 char_buf = g_slist_concat(temp, char_buf);
}

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


decompiled_code:
int char_buf_get()
{
__int64 v0; // rbp
__int64 v1; // rbx
int result; // eax
FILE *v3; // rdi
int v4; // eax

if ( char_buf )
{
v0 = *(_QWORD *)(char_buf + 8);
v1 = *(_QWORD *)char_buf;
g_slist_free_1();
char_buf = v0;
result = v1;
}
else
{
v3 = (FILE *)char_buf_input;
if ( !char_buf_input )
v3 = stdin;
v4 = fgetc(v3);
result = tolower(v4);
}
return result;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rbp
__int64 v1; // rbx
int result; // eax
FILE *v3; // rdi
int v4; // eax

if ( char_buf )
{
v0 = *(_QWORD *)(char_buf + 8);
v1 = *(_QWORD *)char_buf;
g_slist_free_1();
char_buf = v0;
result = v1;
}
else
{
v3 = (FILE *)char_buf_input;
if ( !char_buf_input )
v3 = stdin;
v4 = fgetc(v3);
result = tolower(v4);
}
return result;
}

original_code:
int
char_buf_get(void)
{
 int ch;
 if ((char_buf == ((void *)0))) {
  ch = tolower(fgetc(char_buf_input ? char_buf_input : stdin));
 } else {
  GSList *next;
  ch = ((gint) (glong) (char_buf->data));
  next = char_buf->next;
  g_slist_free_1(char_buf);
  char_buf = next;
 }
 return ch;
}

canonical_original_code:
int char_buf_get()
{
 int ch;
 if ((char_buf == ((void *)0))) {
  ch = tolower(fgetc(char_buf_input ? char_buf_input : stdin));
 } else {
  struct _GSList *next;
  ch = ((gint) (glong) (char_buf->data));
  next = char_buf->next;
  g_slist_free_1(char_buf);
  char_buf = next;
 }
 return ch;
}

variable_types: ch int

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


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

result = (_QWORD *)g_malloc0(16LL);
*result = 0LL;
return result;
}

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

result = (_QWORD *)g_malloc0(16LL);
*result = 0LL;
return result;
}

original_code:
TokenList *
tl_new(void)
{
 TokenList *tl;
 tl = ((TokenList *) g_malloc0_n ((1), sizeof (TokenList)));
 tl->tokens = ((void *)0);
 return tl;
}

canonical_original_code:
struct _TokenList *tl_new()
{
 struct _TokenList *tl;
 tl = ((struct _TokenList *) g_malloc0_n ((1), sizeof (TokenList)));
 tl->tokens = ((void *)0);
 return tl;
}

return_type: struct _TokenList { struct _GList { void *data; struct _GList *next; struct _GList *prev; } *tokens; int ref_count; } *


decompiled_code:
void __fastcall tl_ref(__int64 a1)
{
++*(_DWORD *)(a1 + 8);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
++*(_DWORD *)(a1 + 8);
}

original_code:
void
tl_ref(TokenList * t)
{
 t->ref_count++;
}

canonical_original_code:
void tl_ref(struct _TokenList *t)
{
 t->ref_count++;
}


decompiled_code:
__int64 __fastcall tl_destroy(_QWORD *a1)
{
g_list_free(*a1);
return g_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
g_list_free(*a1);
return g_free(a1);
}

original_code:
void
tl_destroy(TokenList * tl)
{
 g_list_free(tl->tokens);
 g_free(tl);
}

canonical_original_code:
void tl_destroy(struct _TokenList *tl)
{
 g_list_free(tl->tokens);
 g_free(tl);
}


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

if ( a1 )
{
if ( --*(_DWORD *)(a1 + 8) < 0 )
result = tl_destroy((_QWORD *)a1);
}
return result;
}

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

if ( a1 )
{
if ( --*(_DWORD *)(a1 + 8) < 0 )
result = func2((_QWORD *)a1);
}
return result;
}

original_code:
void
tl_unref(TokenList * t)
{
 if (t && --t->ref_count < 0) {
  tl_destroy(t);
 }
}

canonical_original_code:
void tl_unref(struct _TokenList *t)
{
 if (t && --t->ref_count < 0) {
  tl_destroy(t);
 }
}


original_code:
void
tl_add_token(TokenList ** token_list, TokenList * t)
{
 GList *token;
 if (t) {
  for (token = t->tokens; token; token = token->next) {
   (*token_list)->tokens = g_list_append((*token_list)->tokens, token->data);
  }
  tl_unref(t);
 }
}

canonical_original_code:
void tl_add_token(struct _TokenList **token_list, struct _TokenList *t)
{
 struct _GList *token;
 if (t) {
  for (token = t->tokens; token; token = token->next) {
   (*token_list)->tokens = g_list_append((*token_list)->tokens, token->data);
  }
  tl_unref(t);
 }
}

variable_types: struct _TokenList { struct _GList { void *data; struct _GList *next; struct _GList *prev; } *tokens; int ref_count; } **

variable_types:
t
struct _TokenList *


decompiled_code:
__int64 __fastcall tl_add_semicolon(__int64 *a1, int a2, int a3)
{
__int64 v5; // rax
__int64 v6; // rdi
__int64 result; // rax

v5 = g_malloc0(24LL);
v6 = *a1;
*(_DWORD *)(v5 + 16) = a2;
*(_DWORD *)(v5 + 20) = a3;
*(_DWORD *)v5 = 32;
*(_QWORD *)(v5 + 8) = &unk_110;
result = g_list_append(v6, v5);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, int a2, int a3)
{
__int64 v5; // rax
__int64 v6; // rdi
__int64 result; // rax

v5 = g_malloc0(24LL);
v6 = *a1;
*(_DWORD *)(v5 + 16) = a2;
*(_DWORD *)(v5 + 20) = a3;
*(_DWORD *)v5 = 32;
*(_QWORD *)(v5 + 8) = &unk_110;
result = g_list_append(v6, v5);
*a1 = result;
return result;
}

original_code:
void
tl_add_semicolon(TokenList *token_list, gint line, gint column)
{
 Token *token;
 token = ((Token *) g_malloc0_n ((1), sizeof (Token)));
 token->type = T_SEMICOLON;
 token->id = ";";
 token->line = line;
 token->column = column;
 token_list->tokens = g_list_append(token_list->tokens, token);
}

canonical_original_code:
void tl_add_semicolon(struct _TokenList *token_list, int line, int column)
{
 struct _Token *token;
 token = ((struct _Token *) g_malloc0_n ((1), sizeof (Token)));
 token->type = T_SEMICOLON;
 token->id = ";";
 token->line = line;
 token->column = column;
 token_list->tokens = g_list_append(token_list->tokens, token);
}

variable_types: line int

variable_types: column int

variable_types: struct _Token { enum TokenType { T_NONE=0, T_COMMA=1, T_THEN=2, T_ATTRIB=3, T_BOOLEAN=4, T_CLOSEPAREN=5, T_COLON=6, T_DIVIDE=7, T_DO=8, T_ELSE=9, T_FALSE=10, T_END=11, T_FUNCTION=12, T_IF=13, T_BEGIN=14, T_INTEGER=15, T_MINUS=16, T_MULTIPLY=17, T_NOT=18, T_OP_DIFFERENT=19, T_OPENPAREN=20, T_OP_EQUAL=21, T_OP_GT=22, T_OP_GEQ=23, T_OP_LT=24, T_OP_LEQ=25, T_OR=26, T_PERIOD=27, T_PLUS=28, T_PROCEDURE=29, T_PROGRAM=30, T_READ=31, T_SEMICOLON=32, T_AND=33, T_TRUE=34, T_VAR=35, T_WHILE=36, T_WRITE=37, T_IDENTIFIER=38, T_NUMBER=39, T_FUNCTION_RETURN=40, T_FUNCTION_CALL=41, T_PROCEDURE_CALL=42, T_UNARY_MINUS=43, T_FOR=44, T_STEP=45, T_UNARY_PLUS=46, T_MAIN_BEGIN=47 } type; char *id; int line; } *

user_defined_types: struct _Token { enum TokenType type; char *id; int line; }


decompiled_code:
__int64 compiler_do()
{
__int64 v0; // rbp
__int64 v1; // r12
double v2; // xmm7_8
double v3; // xmm6_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm3_8
double v7; // xmm9_8
double v8; // xmm5_8
double v9; // xmm2_8
double v10; // xmm3_8
double v11; // xmm4_8
double v12; // rbp
double v13; // xmm5_8
double v14; // xmm4_8
double v16; // [rsp+8h] [rbp-A0h]
double v17; // [rsp+10h] [rbp-98h]
double v18; // [rsp+30h] [rbp-78h]
double v19; // [rsp+38h] [rbp-70h]
struct timeval tv; // [rsp+40h] [rbp-68h] BYREF
struct timeval v21; // [rsp+50h] [rbp-58h] BYREF
struct timeval v22; // [rsp+60h] [rbp-48h] BYREF
struct timeval v23; // [rsp+70h] [rbp-38h] BYREF
struct timeval v24; // [rsp+80h] [rbp-28h] BYREF

gettimeofday(&tv, 0LL);
v0 = lex();
gettimeofday(&v21, 0LL);
v1 = ast(v0);
gettimeofday(&v22, 0LL);
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
optimize(v1);
gettimeofday(&v24, 0LL);
}
codegen(v1);
gettimeofday(&v23, 0LL);
tl_destroy(v0);
if ( HIDWORD(params) )
{
v2 = (double)(LODWORD(v21.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v21.tv_sec) - LODWORD(tv.tv_sec));
v3 = (double)(LODWORD(v22.tv_usec) - LODWORD(v21.tv_usec)) / 1000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
v4 = v2 * 100.0;
v5 = v2 + v3;
v6 = v3 * 100.0;
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
v8 = (double)(LODWORD(v23.tv_usec) - LODWORD(v24.tv_usec)) / 1000000.0
+ (double)(LODWORD(v23.tv_sec) - LODWORD(v24.tv_sec));
v7 = (double)(LODWORD(v24.tv_usec) - LODWORD(v22.tv_usec)) / 1000000.0
+ (double)(LODWORD(v24.tv_sec) - LODWORD(v22.tv_sec));
v9 = v5 + v8 + v7;
v10 = v6 / v9;
v11 = v8 * 100.0 / v9;
v19 = 100.0 * v7 / v9;
v12 = v4 / v9 + v10 + v11 + v19;
}
else
{
v7 = 0.0;
v19 = 0.0;
v8 = (double)(LODWORD(v23.tv_usec) - LODWORD(v22.tv_usec)) / 1000000.0
+ (double)(LODWORD(v23.tv_sec) - LODWORD(v22.tv_sec));
v9 = v5 + v8 + 0.0;
v10 = v6 / v9;
v11 = 100.0 * v8 / v9;
v12 = v4 / v9 + v10 + v11;
}
v18 = v11;
v17 = v8;
v16 = (double)(LODWORD(v22.tv_usec) - LODWORD(v21.tv_usec)) / 1000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
fprintf(stderr, format, v2);
fprintf(stderr, aAn, v16, v10);
v13 = v17;
v14 = v18;
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
fprintf(stderr, aOtimiza, v7, v19);
v14 = v18;
v13 = v17;
}
fprintf(stderr, aGera, v13, v14);
fprintf(stderr, "Total|%fs|%f\n", v9, v12);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
__int64 v1; // r12
double v2; // xmm7_8
double v3; // xmm6_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm3_8
double v7; // xmm9_8
double v8; // xmm5_8
double v9; // xmm2_8
double v10; // xmm3_8
double v11; // xmm4_8
double v12; // rbp
double v13; // xmm5_8
double v14; // xmm4_8
double v16; // [rsp+8h] [rbp-A0h]
double v17; // [rsp+10h] [rbp-98h]
double v18; // [rsp+30h] [rbp-78h]
double v19; // [rsp+38h] [rbp-70h]
struct timeval tv; // [rsp+40h] [rbp-68h] BYREF
struct timeval v21; // [rsp+50h] [rbp-58h] BYREF
struct timeval v22; // [rsp+60h] [rbp-48h] BYREF
struct timeval v23; // [rsp+70h] [rbp-38h] BYREF
struct timeval v24; // [rsp+80h] [rbp-28h] BYREF

gettimeofday(&tv, 0LL);
v0 = lex();
gettimeofday(&v21, 0LL);
v1 = ast(v0);
gettimeofday(&v22, 0LL);
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
optimize(v1);
gettimeofday(&v24, 0LL);
}
codegen(v1);
gettimeofday(&v23, 0LL);
tl_destroy(v0);
if ( HIDWORD(params) )
{
v2 = (double)(LODWORD(v21.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v21.tv_sec) - LODWORD(tv.tv_sec));
v3 = (double)(LODWORD(v22.tv_usec) - LODWORD(v21.tv_usec)) / 1000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
v4 = v2 * 100.0;
v5 = v2 + v3;
v6 = v3 * 100.0;
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
v8 = (double)(LODWORD(v23.tv_usec) - LODWORD(v24.tv_usec)) / 1000000.0
+ (double)(LODWORD(v23.tv_sec) - LODWORD(v24.tv_sec));
v7 = (double)(LODWORD(v24.tv_usec) - LODWORD(v22.tv_usec)) / 1000000.0
+ (double)(LODWORD(v24.tv_sec) - LODWORD(v22.tv_sec));
v9 = v5 + v8 + v7;
v10 = v6 / v9;
v11 = v8 * 100.0 / v9;
v19 = 100.0 * v7 / v9;
v12 = v4 / v9 + v10 + v11 + v19;
}
else
{
v7 = 0.0;
v19 = 0.0;
v8 = (double)(LODWORD(v23.tv_usec) - LODWORD(v22.tv_usec)) / 1000000.0
+ (double)(LODWORD(v23.tv_sec) - LODWORD(v22.tv_sec));
v9 = v5 + v8 + 0.0;
v10 = v6 / v9;
v11 = 100.0 * v8 / v9;
v12 = v4 / v9 + v10 + v11;
}
v18 = v11;
v17 = v8;
v16 = (double)(LODWORD(v22.tv_usec) - LODWORD(v21.tv_usec)) / 1000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
fprintf(stderr, format, v2);
fprintf(stderr, aAn, v16, v10);
v13 = v17;
v14 = v18;
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
fprintf(stderr, aOtimiza, v7, v19);
v14 = v18;
v13 = v17;
}
fprintf(stderr, aGera, v13, v14);
fprintf(stderr, "Total|%fs|%f\n", v9, v12);
}
return 0LL;
}

original_code:
static int compiler_do(void)
{
 GNode *root;
 TokenList *token_list;
 struct timeval tv_start, tv_lex, tv_ast, tv_codegen, tv_opt;
 gdouble time_lex, time_ast, time_codegen, time_total, time_opt;
 gdouble p_lex, p_ast, p_codegen, p_total, p_opt = 0.0;
 gettimeofday(&tv_start, ((void *)0));
 token_list = lex();
 gettimeofday(&tv_lex, ((void *)0));
 root = ast(token_list);
 gettimeofday(&tv_ast, ((void *)0));
 if (params.optimization_level & 1) {
  optimize(root);
  gettimeofday(&tv_opt, ((void *)0));
 }
 codegen(root);
 gettimeofday(&tv_codegen, ((void *)0));
 tl_destroy(token_list);
 if (params.show_time) {
  time_lex = ((tv_lex.tv_sec - tv_start.tv_sec) + ((tv_lex.tv_usec - tv_start.tv_usec) / 1e6));
  time_ast = ((tv_ast.tv_sec - tv_lex.tv_sec) + ((tv_ast.tv_usec - tv_lex.tv_usec) / 1e6));
  if (params.optimization_level & 1) {
   time_opt = ((tv_opt.tv_sec - tv_ast.tv_sec) + ((tv_opt.tv_usec - tv_ast.tv_usec) / 1e6));
   time_codegen = ((tv_codegen.tv_sec - tv_opt.tv_sec) + ((tv_codegen.tv_usec - tv_opt.tv_usec) / 1e6));
  } else {
   time_opt = 0.0f;
   time_codegen = ((tv_codegen.tv_sec - tv_ast.tv_sec) + ((tv_codegen.tv_usec - tv_ast.tv_usec) / 1e6));
  }
  time_total = time_lex + time_ast + time_codegen + time_opt;
  p_lex = (time_lex * 100.0f) / time_total;
  p_ast = (time_ast * 100.0f) / time_total;
  p_codegen = (time_codegen * 100.0f) / time_total;
  p_total = p_lex + p_ast + p_codegen;
  if (params.optimization_level & 1) {
   p_opt = (time_opt * 100.0f) / time_total;
   p_total += p_opt;
  }
  fprintf(stderr, "Análise Léxica e Sintática|%fs|%0f\n", time_lex, p_lex);
  fprintf(stderr, "Análise Semântica|%fs|%f\n", time_ast, p_ast);
  if (params.optimization_level & 1)
   fprintf(stderr, "Otimização|%fs|%0f\n", time_opt, p_opt);
  fprintf(stderr, "Geração de Código|%fs|%f\n", time_codegen, p_codegen);
  fprintf(stderr, "Total|%fs|%f\n", time_total, p_total);
 }
 return 0;
}

canonical_original_code:
static int compiler_do()
{
 struct _GNode *root;
 struct _TokenList *token_list;
 struct timeval tv_start; struct timeval tv_lex; struct timeval tv_ast; struct timeval tv_codegen; struct timeval tv_opt;
 double time_lex; double time_ast; double time_codegen; double time_total; double time_opt;
 double p_lex; double p_ast; double p_codegen; double p_total; double p_opt = 0.0;
 gettimeofday(&tv_start, ((void *)0));
 token_list = lex();
 gettimeofday(&tv_lex, ((void *)0));
 root = ast(token_list);
 gettimeofday(&tv_ast, ((void *)0));
 if (params.optimization_level & 1) {
  optimize(root);
  gettimeofday(&tv_opt, ((void *)0));
 }
 codegen(root);
 gettimeofday(&tv_codegen, ((void *)0));
 tl_destroy(token_list);
 if (params.show_time) {
  time_lex = ((tv_lex.tv_sec - tv_start.tv_sec) + ((tv_lex.tv_usec - tv_start.tv_usec) / 1e6));
  time_ast = ((tv_ast.tv_sec - tv_lex.tv_sec) + ((tv_ast.tv_usec - tv_lex.tv_usec) / 1e6));
  if (params.optimization_level & 1) {
   time_opt = ((tv_opt.tv_sec - tv_ast.tv_sec) + ((tv_opt.tv_usec - tv_ast.tv_usec) / 1e6));
   time_codegen = ((tv_codegen.tv_sec - tv_opt.tv_sec) + ((tv_codegen.tv_usec - tv_opt.tv_usec) / 1e6));
  } else {
   time_opt = 0.0f;
   time_codegen = ((tv_codegen.tv_sec - tv_ast.tv_sec) + ((tv_codegen.tv_usec - tv_ast.tv_usec) / 1e6));
  }
  time_total = time_lex + time_ast + time_codegen + time_opt;
  p_lex = (time_lex * 100.0f) / time_total;
  p_ast = (time_ast * 100.0f) / time_total;
  p_codegen = (time_codegen * 100.0f) / time_total;
  p_total = p_lex + p_ast + p_codegen;
  if (params.optimization_level & 1) {
   p_opt = (time_opt * 100.0f) / time_total;
   p_total += p_opt;
  }
  fprintf(stderr, "Análise Léxica e Sintática|%fs|%0f\n", time_lex, p_lex);
  fprintf(stderr, "Análise Semântica|%fs|%f\n", time_ast, p_ast);
  if (params.optimization_level & 1)
   fprintf(stderr, "Otimização|%fs|%0f\n", time_opt, p_opt);
  fprintf(stderr, "Geração de Código|%fs|%f\n", time_codegen, p_codegen);
  fprintf(stderr, "Total|%fs|%f\n", time_total, p_total);
 }
 return 0;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


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

result = (_QWORD *)g_malloc0(8LL);
*result = 0LL;
return result;
}

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

result = (_QWORD *)g_malloc0(8LL);
*result = 0LL;
return result;
}

original_code:
Stack*
stack_new(void)
{
 Stack *stack;
 stack = ((Stack *) g_malloc0_n ((1), sizeof (Stack)));
 stack->_stack = ((void *)0);
 return stack;
}

canonical_original_code:
struct _Stack *stack_new()
{
 struct _Stack *stack;
 stack = ((struct _Stack *) g_malloc0_n ((1), sizeof (Stack)));
 stack->_stack = ((void *)0);
 return stack;
}

variable_types: struct _Stack { struct _GSList { void *data; struct _GSList *next; } *_stack; } *

user_defined_types: struct _Stack { struct _GSList *_stack; }


decompiled_code:
__int64 __fastcall stack_free(_QWORD *a1)
{
if ( !a1 )
return g_return_if_fail_warning(0LL, "stack_free", "stack");
g_slist_free(*a1);
return g_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( !a1 )
return g_return_if_fail_warning(0LL, "stack_free", "stack");
g_slist_free(*a1);
return g_free(a1);
}

original_code:
void
stack_free(Stack *stack)
{
 do{ if (stack) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "stack"); return; }; }while (0);
 g_slist_free(stack->_stack);
 g_free(stack);
}

canonical_original_code:
void stack_free(struct _Stack *stack)
{
 do{ if (stack) { } else { g_return_if_fail_warning (((char *) 0), ((char *) (__func__)), "stack"); return; }; }while (0);
 g_slist_free(stack->_stack);
 g_free(stack);
}


decompiled_code:
_BOOL8 __fastcall stack_is_empty(_QWORD *a1)
{
if ( a1 )
return *a1 == 0LL;
g_return_if_fail_warning(0LL, "stack_is_empty", "stack");
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
if ( a1 )
return *a1 == 0LL;
g_return_if_fail_warning(0LL, "stack_is_empty", "stack");
return 1LL;
}

original_code:
gboolean
stack_is_empty(Stack *stack)
{
 do{ if (stack) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "stack"); return ((!(0))); }; }while (0);
 return stack->_stack == ((void *)0);
}

canonical_original_code:
int stack_is_empty(struct _Stack *stack)
{
 do{ if (stack) { } else { g_return_if_fail_warning (((char *) 0), ((char *) (__func__)), "stack"); return ((!(0))); }; }while (0);
 return stack->_stack == ((void *)0);
}


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

if ( !a1 )
return g_return_if_fail_warning(0LL, "stack_push", "stack");
result = g_slist_prepend(*a1);
*a1 = result;
return result;
}

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

if ( !a1 )
return g_return_if_fail_warning(0LL, "stack_push", "stack");
result = g_slist_prepend(*a1);
*a1 = result;
return result;
}

original_code:
void
stack_push(Stack *stack, gpointer data)
{
 do{ if (stack) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "stack"); return; }; }while (0);
 stack->_stack = g_slist_prepend(stack->_stack, data);
}

canonical_original_code:
void stack_push(struct _Stack *stack, void *data)
{
 do{ if (stack) { } else { g_return_if_fail_warning (((char *) 0), ((char *) (__func__)), "stack"); return; }; }while (0);
 stack->_stack = g_slist_prepend(stack->_stack, data);
}

variable_types:
data
void *


decompiled_code:
void __fastcall fold_constants(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 v5; // rbx
__int64 i; // rbx
__int64 *v7; // rax
const char ***v8; // rdx
__int64 v9; // rax
const char **v10; // r14
_DWORD *v11; // r15
__int64 v12; // rdx
__int16 v13; // r13
__int64 v14; // rax
__int64 v15; // r13
__int64 v16; // rax
unsigned int v17; // er14
__int16 v18; // bx
int v19; // ecx
unsigned __int64 v20; // rdx
__int64 v21; // rax

while ( a1 )
{
v4 = *(_QWORD *)(a1 + 32);
if ( !v4 )
break;
v5 = *(_QWORD *)(v4 + 8);
if ( v5 )
{
fold_constants(v4, a1);
fold_constants(v5, a1);
for ( i = *(_QWORD *)(v5 + 32); i; i = *(_QWORD *)(i + 8) )
fold_constants(i, a1);
v7 = *(__int64 **)(a1 + 32);
if ( v7 )
{
v8 = (const char ***)v7[1];
if ( v8 )
{
v9 = *v7;
if ( *(_DWORD *)v9 == 39 )
{
v10 = *v8;
v11 = *(_DWORD **)a1;
if ( *(_DWORD *)*v8 == 39 )
{
v18 = atoi(*(const char **)(v9 + 8));
v13 = v18;
v12 = (unsigned int)atoi(v10[1]);
switch ( *v11 )
{
case 7:
if ( !(_WORD)v12 )
return;
v19 = (__int16)v12;
v20 = (unsigned __int64)v18 >> 32;
LODWORD(v20) = v18 % v19;
v14 = g_strdup_printf(&unk_2FF, (unsigned int)(v18 / v19), v20);
break;
case 0x10:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)(v18 - (__int16)v12), (unsigned int)(__int16)v12);
break;
case 0x11:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)((__int16)v12 * v18), (unsigned int)(__int16)v12);
break;
case 0x13:
v14 = g_strdup_printf(&unk_2FF, (_WORD)v12 != (unsigned __int16)v18, v12);
break;
case 0x15:
v14 = g_strdup_printf(&unk_2FF, (_WORD)v12 == (unsigned __int16)v18, v12);
break;
case 0x16:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 < v18, v12);
break;
case 0x17:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 <= v18, v12);
break;
case 0x18:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 > v18, v12);
break;
case 0x19:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 >= v18, v12);
break;
case 0x1C:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)((__int16)v12 + v18), (unsigned int)(__int16)v12);
break;
case 0x2B:
goto LABEL_15;
default:
return;
}
}
else
{
if ( *v11 != 43 )
return;
v13 = atoi(*(const char **)(v9 + 8));
LABEL_15:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)-v13, v12);
}
if ( v14 )
{
v15 = ast_node_new(39LL, v14);
if ( v15 )
{
v16 = *(_QWORD *)(a2 + 32);
if ( v16 )
{
v17 = 0;
if ( a1 == v16 )
{
LABEL_36:
g_node_destroy(a1);
v21 = g_node_new(v15);
g_node_insert(a2, v17, v21);
}
else
{
while ( 1 )
{
v16 = *(_QWORD *)(v16 + 8);
++v17;
if ( !v16 )
break;
if ( a1 == v16 )
goto LABEL_36;
}
}
}
}
}
}
}
}
return;
}
a2 = a1;
a1 = *(_QWORD *)(a1 + 32);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 v5; // rbx
__int64 i; // rbx
__int64 *v7; // rax
const char ***v8; // rdx
__int64 v9; // rax
const char **v10; // r14
_DWORD *v11; // r15
__int64 v12; // rdx
__int16 v13; // r13
__int64 v14; // rax
__int64 v15; // r13
__int64 v16; // rax
unsigned int v17; // er14
__int16 v18; // bx
int v19; // ecx
unsigned __int64 v20; // rdx
__int64 v21; // rax

while ( a1 )
{
v4 = *(_QWORD *)(a1 + 32);
if ( !v4 )
break;
v5 = *(_QWORD *)(v4 + 8);
if ( v5 )
{
func0(v4, a1);
func0(v5, a1);
for ( i = *(_QWORD *)(v5 + 32); i; i = *(_QWORD *)(i + 8) )
func0(i, a1);
v7 = *(__int64 **)(a1 + 32);
if ( v7 )
{
v8 = (const char ***)v7[1];
if ( v8 )
{
v9 = *v7;
if ( *(_DWORD *)v9 == 39 )
{
v10 = *v8;
v11 = *(_DWORD **)a1;
if ( *(_DWORD *)*v8 == 39 )
{
v18 = atoi(*(const char **)(v9 + 8));
v13 = v18;
v12 = (unsigned int)atoi(v10[1]);
switch ( *v11 )
{
case 7:
if ( !(_WORD)v12 )
return;
v19 = (__int16)v12;
v20 = (unsigned __int64)v18 >> 32;
LODWORD(v20) = v18 % v19;
v14 = g_strdup_printf(&unk_2FF, (unsigned int)(v18 / v19), v20);
break;
case 0x10:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)(v18 - (__int16)v12), (unsigned int)(__int16)v12);
break;
case 0x11:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)((__int16)v12 * v18), (unsigned int)(__int16)v12);
break;
case 0x13:
v14 = g_strdup_printf(&unk_2FF, (_WORD)v12 != (unsigned __int16)v18, v12);
break;
case 0x15:
v14 = g_strdup_printf(&unk_2FF, (_WORD)v12 == (unsigned __int16)v18, v12);
break;
case 0x16:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 < v18, v12);
break;
case 0x17:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 <= v18, v12);
break;
case 0x18:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 > v18, v12);
break;
case 0x19:
v14 = g_strdup_printf(&unk_2FF, (__int16)v12 >= v18, v12);
break;
case 0x1C:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)((__int16)v12 + v18), (unsigned int)(__int16)v12);
break;
case 0x2B:
goto LABEL_15;
default:
return;
}
}
else
{
if ( *v11 != 43 )
return;
v13 = atoi(*(const char **)(v9 + 8));
LABEL_15:
v14 = g_strdup_printf(&unk_2FF, (unsigned int)-v13, v12);
}
if ( v14 )
{
v15 = ast_node_new(39LL, v14);
if ( v15 )
{
v16 = *(_QWORD *)(a2 + 32);
if ( v16 )
{
v17 = 0;
if ( a1 == v16 )
{
LABEL_36:
g_node_destroy(a1);
v21 = g_node_new(v15);
g_node_insert(a2, v17, v21);
}
else
{
while ( 1 )
{
v16 = *(_QWORD *)(v16 + 8);
++v17;
if ( !v16 )
break;
if ( a1 == v16 )
goto LABEL_36;
}
}
}
}
}
}
}
}
return;
}
a2 = a1;
a1 = *(_QWORD *)(a1 + 32);
}
}

original_code:
static void
fold_constants(GNode *node, GNode *parent)
{
    GNode *lchild, *rchild, *child;
    ASTNode *lan, *ran, *nan, *replace = ((void *)0);
    if (!node || !(lchild = node->children))
        return;
    if (!(rchild = node->children->next)) {
        fold_constants(lchild, node);
        return;
    }
    fold_constants(lchild, node);
    fold_constants(rchild, node);
    for (child = rchild->children; child; child = child->next)
        fold_constants(child, node);
    if (!(lchild = node->children) || !(rchild = lchild->next))
        return;
    lan = (ASTNode *)lchild->data;
    ran = (ASTNode *)rchild->data;
    nan = (ASTNode *)node->data;
    if ((lan->token == T_NUMBER && ran->token == T_NUMBER) ||
        (nan->token == T_UNARY_MINUS && lan->token == T_NUMBER)) {
        short p1, p2;
        gchar *r = ((void *)0);
        p1 = lan ? atoi((char *)lan->data) : 0;
        p2 = ran ? atoi((char *)ran->data) : 0;
        switch (nan->token) {
            case T_UNARY_MINUS:
                r = g_strdup_printf("%d", - p1);
                break;
            case T_PLUS:
                r = g_strdup_printf("%d", p1 + p2);
                break;
            case T_MINUS:
                r = g_strdup_printf("%d", p1 - p2);
                break;
            case T_MULTIPLY:
                r = g_strdup_printf("%d", p1 * p2);
                break;
            case T_DIVIDE:
                if (p2) {
                    r = g_strdup_printf("%d", p1 / p2);
                }
                break;
            case T_OP_DIFFERENT:
                r = g_strdup_printf("%d", p1 != p2);
                break;
            case T_OP_EQUAL:
                r = g_strdup_printf("%d", p1 == p2);
                break;
            case T_OP_GT:
                r = g_strdup_printf("%d", p1 > p2);
                break;
            case T_OP_GEQ:
                r = g_strdup_printf("%d", p1 >= p2);
                break;
            case T_OP_LT:
                r = g_strdup_printf("%d", p1 < p2);
                break;
            case T_OP_LEQ:
                r = g_strdup_printf("%d", p1 <= p2);
                break;
            default:
                ;
        }
        if (r) {
            replace = ast_node_new(T_NUMBER, r);
        }
    }
    if (replace) {
        GNode *temp;
        gint position = 0;
        for (temp = parent->children; temp; temp = temp->next, position++) {
            if (temp == node) {
                g_node_destroy(node);
                g_node_insert(parent, position, g_node_new(replace));
                return;
            }
        }
    }
}

canonical_original_code:
static void fold_constants(struct _GNode *node, struct _GNode *parent)
{
    struct _GNode *lchild; struct _GNode *rchild; struct _GNode *child;
    struct _ASTNode *lan; struct _ASTNode *ran; struct _ASTNode *nan; struct _ASTNode *replace = ((void *)0);
    if (!node || !(lchild = node->children))
        return;
    if (!(rchild = node->children->next)) {
        fold_constants(lchild, node);
        return;
    }
    fold_constants(lchild, node);
    fold_constants(rchild, node);
    for (child = rchild->children; child; child = child->next)
        fold_constants(child, node);
    if (!(lchild = node->children) || !(rchild = lchild->next))
        return;
    lan = (struct _ASTNode *)lchild->data;
    ran = (struct _ASTNode *)rchild->data;
    nan = (struct _ASTNode *)node->data;
    if ((lan->token == T_NUMBER && ran->token == T_NUMBER) ||
        (nan->token == T_UNARY_MINUS && lan->token == T_NUMBER)) {
        short p1; short p2;
        char *r = ((void *)0);
        p1 = lan ? atoi((char *)lan->data) : 0;
        p2 = ran ? atoi((char *)ran->data) : 0;
        switch (nan->token) {
            case T_UNARY_MINUS:
                r = g_strdup_printf("%d", - p1);
                break;
            case T_PLUS:
                r = g_strdup_printf("%d", p1 + p2);
                break;
            case T_MINUS:
                r = g_strdup_printf("%d", p1 - p2);
                break;
            case T_MULTIPLY:
                r = g_strdup_printf("%d", p1 * p2);
                break;
            case T_DIVIDE:
                if (p2) {
                    r = g_strdup_printf("%d", p1 / p2);
                }
                break;
            case T_OP_DIFFERENT:
                r = g_strdup_printf("%d", p1 != p2);
                break;
            case T_OP_EQUAL:
                r = g_strdup_printf("%d", p1 == p2);
                break;
            case T_OP_GT:
                r = g_strdup_printf("%d", p1 > p2);
                break;
            case T_OP_GEQ:
                r = g_strdup_printf("%d", p1 >= p2);
                break;
            case T_OP_LT:
                r = g_strdup_printf("%d", p1 < p2);
                break;
            case T_OP_LEQ:
                r = g_strdup_printf("%d", p1 <= p2);
                break;
            default:
                ;
        }
        if (r) {
            replace = ast_node_new(T_NUMBER, r);
        }
    }
    if (replace) {
        struct _GNode *temp;
        int position = 0;
        for (temp = parent->children; temp; temp = temp->next, position++) {
            if (temp == node) {
                g_node_destroy(node);
                g_node_insert(parent, position, g_node_new(replace));
                return;
            }
        }
    }
}

variable_types: struct _GNode { void *data; struct _GNode *next; struct _GNode *prev; struct _GNode *parent; struct _GNode *children; } *

variable_types:
parent
struct _GNode *

variable_types: struct _ASTNode { enum TokenType { T_NONE=0, T_COMMA=1, T_THEN=2, T_ATTRIB=3, T_BOOLEAN=4, T_CLOSEPAREN=5, T_COLON=6, T_DIVIDE=7, T_DO=8, T_ELSE=9, T_FALSE=10, T_END=11, T_FUNCTION=12, T_IF=13, T_BEGIN=14, T_INTEGER=15, T_MINUS=16, T_MULTIPLY=17, T_NOT=18, T_OP_DIFFERENT=19, T_OPENPAREN=20, T_OP_EQUAL=21, T_OP_GT=22, T_OP_GEQ=23, T_OP_LT=24, T_OP_LEQ=25, T_OR=26, T_PERIOD=27, T_PLUS=28, T_PROCEDURE=29, T_PROGRAM=30, T_READ=31, T_SEMICOLON=32, T_AND=33, T_TRUE=34, T_VAR=35, T_WHILE=36, T_WRITE=37, T_IDENTIFIER=38, T_NUMBER=39, T_FUNCTION_RETURN=40, T_FUNCTION_CALL=41, T_PROCEDURE_CALL=42, T_UNARY_MINUS=43, T_FOR=44, T_STEP=45, T_UNARY_PLUS=46, T_MAIN_BEGIN=47 } token; void *data; } *

variable_types:
r
char *

variable_types: position int

user_defined_types: struct _ASTNode { enum TokenType token; void *data; }


decompiled_code:
__int64 __fastcall fold_constants_traverse_func(unsigned int **a1)
{
unsigned __int64 v1; // rax
__int64 v2; // rdx

v1 = **a1;
if ( (unsigned int)v1 > 0x28 )
return 0LL;
v2 = 0x11000002008LL;
if ( !_bittest64(&v2, v1) )
return 0LL;
fold_constants((__int64)a1, 0LL);
return 0LL;
}

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

v1 = **a1;
if ( (unsigned int)v1 > 0x28 )
return 0LL;
v2 = 0x11000002008LL;
if ( !_bittest64(&v2, v1) )
return 0LL;
func0((__int64)a1, 0LL);
return 0LL;
}

original_code:
static gboolean
fold_constants_traverse_func(GNode *node,
                             gpointer data)
{
    ASTNode *ast_node = (ASTNode *)node->data;
    switch (ast_node->token) {
      case T_ATTRIB:
      case T_IF:
      case T_WHILE:
      case T_FUNCTION_RETURN:
          fold_constants(node, ((void *)0));
      default:
          ;
    }
    return (0);
}

canonical_original_code:
static int fold_constants_traverse_func(struct _GNode *node, void *data)
{
    struct _ASTNode *ast_node = (ASTNode *)node->data;
    switch (ast_node->token) {
      case T_ATTRIB:
      case T_IF:
      case T_WHILE:
      case T_FUNCTION_RETURN:
          fold_constants(node, ((void *)0));
      default:
          ;
    }
    return (0);
}

user_defined_types: enum TokenType { T_NONE=0, T_COMMA=1, T_THEN=2, T_ATTRIB=3, T_BOOLEAN=4, T_CLOSEPAREN=5, T_COLON=6, T_DIVIDE=7, T_DO=8, T_ELSE=9, T_FALSE=10, T_END=11, T_FUNCTION=12, T_IF=13, T_BEGIN=14, T_INTEGER=15, T_MINUS=16, T_MULTIPLY=17, T_NOT=18, T_OP_DIFFERENT=19, T_OPENPAREN=20, T_OP_EQUAL=21, T_OP_GT=22, T_OP_GEQ=23, T_OP_LT=24, T_OP_LEQ=25, T_OR=26, T_PERIOD=27, T_PLUS=28, T_PROCEDURE=29, T_PROGRAM=30, T_READ=31, T_SEMICOLON=32, T_AND=33, T_TRUE=34, T_VAR=35, T_WHILE=36, T_WRITE=37, T_IDENTIFIER=38, T_NUMBER=39, T_FUNCTION_RETURN=40, T_FUNCTION_CALL=41, T_PROCEDURE_CALL=42, T_UNARY_MINUS=43, T_FOR=44, T_STEP=45, T_UNARY_PLUS=46, T_MAIN_BEGIN=47 }


optimize

decompiled_code:
__int64 __fastcall optimize(__int64 a1)
{
return g_node_traverse(a1, 1LL, 2LL, 0xFFFFFFFFLL, fold_constants_traverse_func, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return g_node_traverse(a1, 1LL, 2LL, 0xFFFFFFFFLL, fold_constants_traverse_func, 0LL);
}

original_code:
void optimize(GNode *ast)
{
    g_node_traverse(ast,
                    G_PRE_ORDER,
                    G_TRAVERSE_NON_LEAVES,
                    -1,
                    fold_constants_traverse_func,
                    ((void *)0));
}

canonical_original_code:
void optimize(struct _GNode *ast)
{
    g_node_traverse(ast,
                    G_PRE_ORDER,
                    G_TRAVERSE_NON_LEAVES,
                    -1,
                    fold_constants_traverse_func,
                    ((void *)0));
}


repo: lpsantil/picotap

decompiled_code:
int tap_pclose()
{
gettimeofday(&tap_t1, 0LL);
return pclose(tap_f);
}

canonical_decompiled_code:
int func0()
{
gettimeofday(&tap_t1, 0LL);
return pclose(tap_f);
}

original_code:
void tap_pclose( void )
{
   gettimeofday( &tap_t1, ((void *)0) );
   pclose( tap_f );
}

canonical_original_code:
void tap_pclose()
{
   gettimeofday( &tap_t1, ((void *)0) );
   pclose( tap_f );
}


decompiled_code:
char *tap_parse()
{
__int64 v0; // rbp
char *result; // rax
unsigned int v2; // er12
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

tap_badList = 0;
tap_testsRead = 0;
tap_bad = 0;
v3[0] = 0;
tap_good = 0;
tap_tests = -1;
gettimeofday(&tap_t0, 0LL);
if ( !fgets(v3, 256, tap_f) )
_assert_fail("rt != NULL", "src/tap.c", 0x33u, "tap_parse");
_isoc99_sscanf(v3, "1..%i", &tap_tests);
if ( tap_tests <= 0 )
{
puts("Bad TAP plan");
exit(-1);
}
v0 = 0x900002600LL;
while ( 1 )
{
result = fgets(v3, 256, tap_f);
if ( !result )
break;
if ( v3[0] > 0x23u || !_bittest64(&v0, (unsigned __int8)v3[0]) )
{
v2 = ++tap_testsRead;
if ( v3 != strstr(v3, "not ok") && v3 == strstr(v3, "ok") )
{
++tap_good;
}
else
{
sprintf(v3, "%u,", v2);
strcat(&tap_badList, v3);
++tap_bad;
}
}
}
return result;
}

canonical_decompiled_code:
char *func1()
{
__int64 v0; // rbp
char *result; // rax
unsigned int v2; // er12
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

tap_badList = 0;
tap_testsRead = 0;
tap_bad = 0;
v3[0] = 0;
tap_good = 0;
tap_tests = -1;
gettimeofday(&tap_t0, 0LL);
if ( !fgets(v3, 256, tap_f) )
_assert_fail("rt != NULL", "src/tap.c", 0x33u, "tap_parse");
_isoc99_sscanf(v3, "1..%i", &tap_tests);
if ( tap_tests <= 0 )
{
puts("Bad TAP plan");
exit(-1);
}
v0 = 0x900002600LL;
while ( 1 )
{
result = fgets(v3, 256, tap_f);
if ( !result )
break;
if ( v3[0] > 0x23u || !_bittest64(&v0, (unsigned __int8)v3[0]) )
{
v2 = ++tap_testsRead;
if ( v3 != strstr(v3, "not ok") && v3 == strstr(v3, "ok") )
{
++tap_good;
}
else
{
sprintf(v3, "%u,", v2);
strcat(&tap_badList, v3);
++tap_bad;
}
}
}
return result;
}

original_code:
void tap_parse( void )
{
   char ch;
   char* rt;
   char ibuf[ 256 ];
   tap_testsRead = 0;
   tap_bad = 0;
   tap_badList[ 0 ] = ibuf[ 0 ] = '\0';
   tap_good = 0;
   tap_tests = -1;
   gettimeofday( &tap_t0, ((void *)0) );
   rt = fgets( ibuf, 256, tap_f );
   ((void) sizeof ((rt != ((void *)0)) ? 1 : 0), __extension__ ({ if (rt != ((void *)0)) ; else __assert_fail ("rt != NULL", "src/tap.c", 51, __extension__ __PRETTY_FUNCTION__); }));
   sscanf( ibuf, "1..%i", &tap_tests );
   if( tap_tests < 1 )
   {
      printf( "Bad TAP plan\n" );
      exit( -1 );
   }
   while( fgets( ibuf, 256, tap_f ) != ((void *)0) )
   {
      ch = ibuf[ 0 ];
      switch( ch )
      {
         case( '#' ):
         case( '\r' ):
         case( '\n' ):
         case( ' ' ):
         case( '\t' ):
         {
            break;
         }
         default:
         {
            tap_testsRead++;
            if( strstr( ibuf, "not ok" ) == ibuf )
            {
               sprintf( ibuf, "%u,", tap_testsRead );
               strcat( tap_badList, ibuf );
               tap_bad++;
            }
            else if( strstr( ibuf, "ok" ) != ibuf )
            {
               sprintf( ibuf, "%u,", tap_testsRead );
               strcat( tap_badList, ibuf );
               tap_bad++;
            }
            else
            {
               tap_good++;
            }
            break;
         }
      }
   }
}

canonical_original_code:
void tap_parse()
{
   char ch;
   char *rt;
   char ibuf[256];
   tap_testsRead = 0;
   tap_bad = 0;
   tap_badList[ 0 ] = ibuf[ 0 ] = '\0';
   tap_good = 0;
   tap_tests = -1;
   gettimeofday( &tap_t0, ((void *)0) );
   rt = fgets( ibuf, 256, tap_f );
   ((void) sizeof ((rt != ((void *)0)) ? 1 : 0), __extension__ ({ if (rt != ((void *)0)) ; else __assert_fail ("rt != NULL", "src/tap.c", 51, __extension__ __PRETTY_FUNCTION__); }));
   sscanf( ibuf, "1..%i", &tap_tests );
   if( tap_tests < 1 )
   {
      printf( "Bad TAP plan\n" );
      exit( -1 );
   }
   while( fgets( ibuf, 256, tap_f ) != ((void *)0) )
   {
      ch = ibuf[ 0 ];
      switch( ch )
      {
         case( '#' ):
         case( '\r' ):
         case( '\n' ):
         case( ' ' ):
         case( '\t' ):
         {
            break;
         }
         default:
         {
            tap_testsRead++;
            if( strstr( ibuf, "not ok" ) == ibuf )
            {
               sprintf( ibuf, "%u,", tap_testsRead );
               strcat( tap_badList, ibuf );
               tap_bad++;
            }
            else if( strstr( ibuf, "ok" ) != ibuf )
            {
               sprintf( ibuf, "%u,", tap_testsRead );
               strcat( tap_badList, ibuf );
               tap_bad++;
            }
            else
            {
               tap_good++;
            }
            break;
         }
      }
   }
}

variable_types:
rt
char *

variable_types:
ibuf
char [256]


decompiled_code:
int tap_output()
{
__int64 v0; // r12
__int64 v1; // rsi
int result; // eax

time_sub(&tap_t, &tap_t1, &tap_t0);
v0 = (*(&tap_t + 1) + 1000000 * tap_t) / 1000;
if ( tap_tests == tap_testsRead && tap_tests == tap_good )
{
printf("%s .. ok\n", (const char *)tap_fn);
puts("All tests successful.");
printf("Files=1, Tests=%i, %lu msecs\n", (unsigned int)tap_testsRead, v0);
result = puts("Result: PASS");
}
else
{
printf("%s .. %u subtests passed\n", (const char *)tap_fn, (unsigned int)tap_good);
putchar(10);
puts("Test Summary Report");
puts("-------------------");
printf("%s (Tests: %u Failed: %u)\n", (const char *)tap_fn, (unsigned int)tap_testsRead, (unsigned int)tap_bad);
if ( tap_badList[0] )
{
tap_badList[strlen(tap_badList) - 2] = 0;
printf("Failed tests: %s\n", tap_badList);
}
v1 = (unsigned int)tap_testsRead;
if ( tap_tests != tap_testsRead )
{
printf(
"Parse errors: Bad plan. You planned %u tests but ran %u.\n",
(unsigned int)tap_tests,
(unsigned int)tap_testsRead);
v1 = (unsigned int)tap_testsRead;
}
printf("Files=1, Tests=%u, %lu msecs\n", v1, v0);
result = puts("Result: FAIL");
}
return result;
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // r12
__int64 v1; // rsi
int result; // eax

time_sub(&tap_t, &tap_t1, &tap_t0);
v0 = (*(&tap_t + 1) + 1000000 * tap_t) / 1000;
if ( tap_tests == tap_testsRead && tap_tests == tap_good )
{
printf("%s .. ok\n", (const char *)tap_fn);
puts("All tests successful.");
printf("Files=1, Tests=%i, %lu msecs\n", (unsigned int)tap_testsRead, v0);
result = puts("Result: PASS");
}
else
{
printf("%s .. %u subtests passed\n", (const char *)tap_fn, (unsigned int)tap_good);
putchar(10);
puts("Test Summary Report");
puts("-------------------");
printf("%s (Tests: %u Failed: %u)\n", (const char *)tap_fn, (unsigned int)tap_testsRead, (unsigned int)tap_bad);
if ( tap_badList[0] )
{
tap_badList[strlen(tap_badList) - 2] = 0;
printf("Failed tests: %s\n", tap_badList);
}
v1 = (unsigned int)tap_testsRead;
if ( tap_tests != tap_testsRead )
{
printf(
"Parse errors: Bad plan. You planned %u tests but ran %u.\n",
(unsigned int)tap_tests,
(unsigned int)tap_testsRead);
v1 = (unsigned int)tap_testsRead;
}
printf("Files=1, Tests=%u, %lu msecs\n", v1, v0);
result = puts("Result: FAIL");
}
return result;
}

original_code:
void tap_output( void )
{
   unsigned long t;
   time_sub( &tap_t, &tap_t1, &tap_t0 );
   t = ( tap_t.tv_sec * 1000000 + tap_t.tv_usec ) / 1000;
   if( ( tap_tests == tap_testsRead ) &&
       ( tap_tests == tap_good ) )
   {
      printf( "%s .. ok\n", tap_fn );
      printf( "All tests successful.\n" );
      printf( "Files=1, Tests=%i, %lu msecs\n", tap_testsRead, t );
      printf( "Result: PASS\n" );
   }
   else
   {
      printf( "%s .. %u subtests passed\n", tap_fn, tap_good );
      printf( "\n" );
      printf( "Test Summary Report\n" );
      printf( "-------------------\n" );
      printf( "%s (Tests: %u Failed: %u)\n", tap_fn, tap_testsRead,
              tap_bad );
      if( strlen( tap_badList ) > 0 )
      {
         tap_badList[ strlen( tap_badList ) - 2 ] = '\0';
         printf( "Failed tests: %s\n", tap_badList );
      }
      if( tap_tests != tap_testsRead )
      {
         printf( "Parse errors: Bad plan.  You planned %u tests but ran "
                 "%u.\n", tap_tests, tap_testsRead );
      }
      printf( "Files=1, Tests=%u, %lu msecs\n", tap_testsRead, t );
      printf( "Result: FAIL\n" );
   }
}

canonical_original_code:
void tap_output()
{
   unsigned long t;
   time_sub( &tap_t, &tap_t1, &tap_t0 );
   t = ( tap_t.tv_sec * 1000000 + tap_t.tv_usec ) / 1000;
   if( ( tap_tests == tap_testsRead ) &&
       ( tap_tests == tap_good ) )
   {
      printf( "%s .. ok\n", tap_fn );
      printf( "All tests successful.\n" );
      printf( "Files=1, Tests=%i, %lu msecs\n", tap_testsRead, t );
      printf( "Result: PASS\n" );
   }
   else
   {
      printf( "%s .. %u subtests passed\n", tap_fn, tap_good );
      printf( "\n" );
      printf( "Test Summary Report\n" );
      printf( "-------------------\n" );
      printf( "%s (Tests: %u Failed: %u)\n", tap_fn, tap_testsRead,
              tap_bad );
      if( strlen( tap_badList ) > 0 )
      {
         tap_badList[ strlen( tap_badList ) - 2 ] = '\0';
         printf( "Failed tests: %s\n", tap_badList );
      }
      if( tap_tests != tap_testsRead )
      {
         printf( "Parse errors: Bad plan.  You planned %u tests but ran "
                 "%u.\n", tap_tests, tap_testsRead );
      }
      printf( "Files=1, Tests=%u, %lu msecs\n", tap_testsRead, t );
      printf( "Result: FAIL\n" );
   }
}

variable_types:
t
unsigned long


decompiled_code:
int __fastcall tap_run(const char *a1)
{
tap_fn = (__int64)a1;
tap_popen(a1);
tap_parse();
tap_pclose();
return tap_output();
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
tap_fn = (__int64)a1;
tap_popen(a1);
func1();
func0();
return func2();
}

original_code:
void tap_run( char* f )
{
   tap_fn = f;
   tap_popen( tap_fn );
   tap_parse();
   tap_pclose();
   tap_output();
}

canonical_original_code:
void tap_run(char *f)
{
   tap_fn = f;
   tap_popen( tap_fn );
   tap_parse();
   tap_pclose();
   tap_output();
}

variable_types:
f
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( argc <= 1 )
{
puts("Missing an argument");
result = -1;
}
else
{
tap_run(argv[1]);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( argc <= 1 )
{
puts("Missing an argument");
result = -1;
}
else
{
func3(argv[1]);
result = 0;
}
return result;
}

original_code:
int main( int argc, char** argv )
{
   if( argc < 2 )
   {
      printf( "Missing an argument\n" );
      return( -1 );
   }
   tap_run( argv[ 1 ] );
   return( 0 );
}

canonical_original_code:
int main(int argc, char **argv)
{
   if( argc < 2 )
   {
      printf( "Missing an argument\n" );
      return( -1 );
   }
   tap_run( argv[ 1 ] );
   return( 0 );
}

variable_types: argc int

variable_types:
argv
char **


plan

decompiled_code:
int __fastcall plan(unsigned int a1)
{
return printf("1..%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("1..%d\n", a1);
}

original_code:
void plan( unsigned int num )
{
   printf( "1..%d\n",
           num );
}

canonical_original_code:
void plan(unsigned int num)
{
   printf( "1..%d\n",
           num );
}

variable_types:
num
unsigned int


ok

decompiled_code:
int __fastcall ok(int a1, __int64 a2)
{
const char *v3; // rsi
__int64 v4; // rdx

v3 = "ok";
v4 = (unsigned int)(testnum_0 + 1);
if ( !a1 )
v3 = "not ok";
++testnum_0;
return printf("%s %d - %s\n", v3, v4, a2);
}

canonical_decompiled_code:
int __fastcall func1(int a1, __int64 a2)
{
const char *v3; // rsi
__int64 v4; // rdx

v3 = "ok";
v4 = (unsigned int)(testnum_0 + 1);
if ( !a1 )
v3 = "not ok";
++testnum_0;
return printf("%s %d - %s\n", v3, v4, a2);
}

original_code:
void ok( unsigned int ok, const char* msg )
{
   static int testnum = 0;
   printf( "%s %d - %s\n",
           ( ok ? "ok" : "not ok" ),
           ++testnum,
           msg );
}

canonical_original_code:
void ok(unsigned int ok, char *msg)
{
   static int testnum = 0;
   printf( "%s %d - %s\n",
           ( ok ? "ok" : "not ok" ),
           ++testnum,
           msg );
}

variable_types:
ok
unsigned int

variable_types:
msg
char *

variable_types: testnum int


original_code:
int time_sub( struct timeval *result,
              struct timeval *x,
              struct timeval *y )
{
   if( x->tv_usec < y->tv_usec )
   {
      int nsec = ( y->tv_usec - x->tv_usec ) / 1000000 + 1;
      y->tv_usec -= 1000000 * nsec;
      y->tv_sec += nsec;
   }
   if( x->tv_usec - y->tv_usec > 1000000 )
   {
      int nsec = ( x->tv_usec - y->tv_usec ) / 1000000;
      y->tv_usec += 1000000 * nsec;
      y->tv_sec -= nsec;
   }
   result->tv_sec = x->tv_sec - y->tv_sec;
   result->tv_usec = x->tv_usec - y->tv_usec;
   return x->tv_sec < y->tv_sec;
}

canonical_original_code:
int time_sub(struct timeval *result, struct timeval *x, struct timeval *y)
{
   if( x->tv_usec < y->tv_usec )
   {
      int nsec = ( y->tv_usec - x->tv_usec ) / 1000000 + 1;
      y->tv_usec -= 1000000 * nsec;
      y->tv_sec += nsec;
   }
   if( x->tv_usec - y->tv_usec > 1000000 )
   {
      int nsec = ( x->tv_usec - y->tv_usec ) / 1000000;
      y->tv_usec += 1000000 * nsec;
      y->tv_sec -= nsec;
   }
   result->tv_sec = x->tv_sec - y->tv_sec;
   result->tv_usec = x->tv_usec - y->tv_usec;
   return x->tv_sec < y->tv_sec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types:
x
struct timeval *

variable_types:
y
struct timeval *

variable_types: nsec int


repo: lqs/crabdb

decompiled_code:
__int64 __fastcall grow_slab_list(unsigned int a1)
{
__int64 *v1; // rdx
int v2; // eax
size_t v4; // rsi
__int64 v5; // rbx
__int64 *v6; // rbp
void *v7; // rax
unsigned int v8; // er8

v1 = &slabclass[7 * a1];
v2 = *((_DWORD *)v1 + 12);
if ( *((_DWORD *)v1 + 9) != v2 )
return 1LL;
if ( v2 )
{
v5 = (unsigned int)(2 * v2);
v4 = 8 * v5;
}
else
{
v4 = 128LL;
LODWORD(v5) = 16;
}
v6 = &slabclass[7 * a1];
v7 = realloc((void *)v6[5], v4);
if ( !v7 )
return 0;
*((_DWORD *)v6 + 12) = v5;
v8 = 1;
v6[5] = (__int64)v7;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 *v1; // rdx
int v2; // eax
size_t v4; // rsi
__int64 v5; // rbx
__int64 *v6; // rbp
void *v7; // rax
unsigned int v8; // er8

v1 = &slabclass[7 * a1];
v2 = *((_DWORD *)v1 + 12);
if ( *((_DWORD *)v1 + 9) != v2 )
return 1LL;
if ( v2 )
{
v5 = (unsigned int)(2 * v2);
v4 = 8 * v5;
}
else
{
v4 = 128LL;
LODWORD(v5) = 16;
}
v6 = &slabclass[7 * a1];
v7 = realloc((void *)v6[5], v4);
if ( !v7 )
return 0;
*((_DWORD *)v6 + 12) = v5;
v8 = 1;
v6[5] = (__int64)v7;
return v8;
}

original_code:
static int
grow_slab_list (const unsigned int id)
{
    slabclass_t *p = &slabclass[id];
    if (p->slabs == p->list_size)
    {
        size_t new_size = (p->list_size != 0) ? p->list_size * 2 : 16;
        void *new_list = realloc(p->slab_list, new_size * sizeof(void *));
        if (new_list == 0)
        {
            return 0;
        }
        p->list_size = new_size;
        p->slab_list = (void **)new_list;
    }
    return 1;
}

canonical_original_code:
static int grow_slab_list(unsigned int id)
{
    struct slabclass_t *p = &slabclass[id];
    if (p->slabs == p->list_size)
    {
        unsigned long new_size = (p->list_size != 0) ? p->list_size * 2 : 16;
        void *new_list = realloc(p->slab_list, new_size * sizeof(void *));
        if (new_list == 0)
        {
            return 0;
        }
        p->list_size = new_size;
        p->slab_list = (void **)new_list;
    }
    return 1;
}

variable_types:
id
unsigned int

variable_types: struct slabclass_t { unsigned int size; unsigned int perslab; void **slots; unsigned int sl_total; unsigned int sl_curr; void *end_page_ptr; unsigned int end_page_free; unsigned int slabs; void **slab_list; unsigned int list_size; int lock; } *


decompiled_code:
__int64 __fastcall do_slabs_newslab(unsigned int a1)
{
__int64 result; // rax
void *v2; // rdx
__int64 *v3; // rax
int v4; // ecx
__int64 v5; // rsi
__int64 v6; // rcx

if ( mem_limit && mem_limit < (unsigned __int64)(mem_malloced + 0x400000) && dword_664[14 * a1] )
return 0LL;
if ( !(unsigned int)grow_slab_list(a1) )
return 0LL;
v2 = valloc(0x400000uLL);
if ( !v2 )
return 0LL;
mem_malloced += 0x400000LL;
v3 = &slabclass[7 * a1];
v4 = *((_DWORD *)v3 + 1);
v5 = v3[5];
v3[3] = (__int64)v2;
*((_DWORD *)v3 + 8) = v4;
v6 = *((unsigned int *)v3 + 9);
*((_DWORD *)v3 + 9) = v6 + 1;
result = 1LL;
*(_QWORD *)(v5 + 8 * v6) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax
void *v2; // rdx
__int64 *v3; // rax
int v4; // ecx
__int64 v5; // rsi
__int64 v6; // rcx

if ( mem_limit && mem_limit < (unsigned __int64)(mem_malloced + 0x400000) && dword_664[14 * a1] )
return 0LL;
if ( !(unsigned int)func0(a1) )
return 0LL;
v2 = valloc(0x400000uLL);
if ( !v2 )
return 0LL;
mem_malloced += 0x400000LL;
v3 = &slabclass[7 * a1];
v4 = *((_DWORD *)v3 + 1);
v5 = v3[5];
v3[3] = (__int64)v2;
*((_DWORD *)v3 + 8) = v4;
v6 = *((unsigned int *)v3 + 9);
*((_DWORD *)v3 + 9) = v6 + 1;
result = 1LL;
*(_QWORD *)(v5 + 8 * v6) = v2;
return result;
}

original_code:
static int
do_slabs_newslab(const unsigned int id)
{
    slabclass_t *p = &slabclass[id];
    int len = (1024*1024*4);
    char *ptr;
    if (mem_limit && mem_malloced + len > mem_limit && p->slabs > 0)
        return 0;
    if (grow_slab_list(id) == 0) return 0;
    ptr = (char *)valloc((size_t)len);
    if (ptr == 0) return 0;
    p->end_page_ptr = ptr;
    p->end_page_free = p->perslab;
    p->slab_list[p->slabs++] = ptr;
    mem_malloced += len;
    return 1;
}

canonical_original_code:
static int do_slabs_newslab(unsigned int id)
{
    struct slabclass_t *p = &slabclass[id];
    int len = (1024*1024*4);
    char *ptr;
    if (mem_limit && mem_malloced + len > mem_limit && p->slabs > 0)
        return 0;
    if (grow_slab_list(id) == 0) return 0;
    ptr = (char *)valloc((unsigned long)len);
    if (ptr == 0) return 0;
    p->end_page_ptr = ptr;
    p->end_page_free = p->perslab;
    p->slab_list[p->slabs++] = ptr;
    mem_malloced += len;
    return 1;
}

variable_types: len int

variable_types:
ptr
char *

user_defined_types: struct slabclass_t { unsigned int size; unsigned int perslab; void **slots; unsigned int sl_total; unsigned int sl_curr; void *end_page_ptr; unsigned int end_page_free; unsigned int slabs; void **slab_list; unsigned int list_size; int lock; }


decompiled_code:
__int64 __fastcall slab_clsid(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // er9
unsigned __int64 v4; // rdx

result = 0LL;
if ( a1 )
{
v2 = power_largest;
result = (unsigned int)((power_largest + 1) / 2);
if ( power_largest > 0 )
{
v3 = 1;
do
{
v4 = LODWORD(slabclass[7 * (int)result]);
if ( v4 <= a1 )
{
if ( v4 >= a1 )
return result;
v3 = result + 1;
}
else
{
v2 = result - 1;
if ( LODWORD(slabclass[7 * (int)result - 7]) < a1 )
return result;
}
result = (unsigned int)((v3 + v2) / 2);
}
while ( v2 >= v3 );
}
result = (unsigned int)(power_largest + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // er9
unsigned __int64 v4; // rdx

result = 0LL;
if ( a1 )
{
v2 = power_largest;
result = (unsigned int)((power_largest + 1) / 2);
if ( power_largest > 0 )
{
v3 = 1;
do
{
v4 = LODWORD(slabclass[7 * (int)result]);
if ( v4 <= a1 )
{
if ( v4 >= a1 )
return result;
v3 = result + 1;
}
else
{
v2 = result - 1;
if ( LODWORD(slabclass[7 * (int)result - 7]) < a1 )
return result;
}
result = (unsigned int)((v3 + v2) / 2);
}
while ( v2 >= v3 );
}
result = (unsigned int)(power_largest + 1);
}
return result;
}

original_code:
unsigned int
slab_clsid(const size_t size)
{
    if (size == 0)
    {
        return 0;
    }
    int res;
    int left, right;
    left = 1;
    right = power_largest;
    res = (left + right) / 2;
    while (left <= right)
    {
        if (size < slabclass[res].size)
        {
            if (size > slabclass[res-1].size)
                return res;
            else
            {
                right = res - 1;
                res = (left + right) / 2;
                continue;
            }
        }
        else if (size > slabclass[res].size)
        {
            left = res + 1;
            res = (left + right) / 2;
            continue;
        }
        return res;
    }
    return (power_largest + 1);
}

canonical_original_code:
unsigned int slab_clsid(unsigned long size)
{
    if (size == 0)
    {
        return 0;
    }
    int res;
    int left; int right;
    left = 1;
    right = power_largest;
    res = (left + right) / 2;
    while (left <= right)
    {
        if (size < slabclass[res].size)
        {
            if (size > slabclass[res-1].size)
                return res;
            else
            {
                right = res - 1;
                res = (left + right) / 2;
                continue;
            }
        }
        else if (size > slabclass[res].size)
        {
            left = res + 1;
            res = (left + right) / 2;
            continue;
        }
        return res;
    }
    return (power_largest + 1);
}

variable_types:
size
unsigned long

variable_types: res int

variable_types: left int

variable_types: right int

return_type: unsigned int


decompiled_code:
int __fastcall slab_init(__int64 a1, double a2)
{
pthread_spinlock_t *v2; // rbp
unsigned int v3; // ebx
int v4; // er13
__int64 v5; // rax
__int64 v6; // rdi

if ( a2 <= 1.0 )
_assert_fail("factor > 1.0", "slab/slab.c", 0xB3u, "slab_init");
mem_limit = a1;
memset(slabclass, 0, 0x2BF8uLL);
v2 = &lock;
v3 = 16;
v4 = 1;
while ( 1 )
{
*(v2 - 13) = v3;
++v4;
*(v2 - 12) = 0x400000 / v3;
pthread_spin_init(v2, 0);
v3 = (int)((double)(int)v3 * a2);
if ( v4 == 200 )
break;
if ( v3 > 0x200000 )
{
v5 = v4;
v6 = 56LL * v4 + 52;
goto LABEL_9;
}
if ( (v3 & 7) != 0 )
v3 = (v3 & 0xFFFFFFF8) + 8;
v2 += 14;
}
v6 = 11252LL;
v5 = 200LL;
LABEL_9:
power_largest = v4;
slabclass[7 * v5] = 0x100400000LL;
return pthread_spin_init((pthread_spinlock_t *)((char *)slabclass + v6), 0);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, double a2)
{
pthread_spinlock_t *v2; // rbp
unsigned int v3; // ebx
int v4; // er13
__int64 v5; // rax
__int64 v6; // rdi

if ( a2 <= 1.0 )
_assert_fail("factor > 1.0", "slab/slab.c", 0xB3u, "slab_init");
mem_limit = a1;
memset(slabclass, 0, 0x2BF8uLL);
v2 = &lock;
v3 = 16;
v4 = 1;
while ( 1 )
{
*(v2 - 13) = v3;
++v4;
*(v2 - 12) = 0x400000 / v3;
pthread_spin_init(v2, 0);
v3 = (int)((double)(int)v3 * a2);
if ( v4 == 200 )
break;
if ( v3 > 0x200000 )
{
v5 = v4;
v6 = 56LL * v4 + 52;
goto LABEL_9;
}
if ( (v3 & 7) != 0 )
v3 = (v3 & 0xFFFFFFF8) + 8;
v2 += 14;
}
v6 = 11252LL;
v5 = 200LL;
LABEL_9:
power_largest = v4;
slabclass[7 * v5] = 0x100400000LL;
return pthread_spin_init((pthread_spinlock_t *)((char *)slabclass + v6), 0);
}

original_code:
void
slab_init(const size_t limit, const double factor)
{
    int i = 1 - 1;
    unsigned int size = 16;
    ((void) sizeof ((factor > 1.0) ? 1 : 0), __extension__ ({ if (factor > 1.0) ; else __assert_fail ("factor > 1.0", "slab/slab.c", 179, __extension__ __PRETTY_FUNCTION__); }));
    mem_limit = limit;
    memset(slabclass, 0, sizeof(slabclass));
    while (++i < 200 && size <= (1024*1024*4) / 2)
    {
        if (size % (sizeof(void *)))
        {
            size += (sizeof(void *)) - (size % (sizeof(void *)));
        }
        slabclass[i].size = size;
        slabclass[i].perslab = (1024*1024*4) / slabclass[i].size;
        pthread_spin_init(&(slabclass[i].lock), PTHREAD_PROCESS_PRIVATE);
        size = (int)((double)size * factor);
    }
    power_largest = i;
    slabclass[power_largest].size = (1024*1024*4);
    slabclass[power_largest].perslab = 1;
    pthread_spin_init(&(slabclass[power_largest].lock), PTHREAD_PROCESS_PRIVATE);
}

canonical_original_code:
void slab_init(unsigned long limit, double factor)
{
    int i = 1 - 1;
    unsigned int size = 16;
    ((void) sizeof ((factor > 1.0) ? 1 : 0), __extension__ ({ if (factor > 1.0) ; else __assert_fail ("factor > 1.0", "slab/slab.c", 179, __extension__ __PRETTY_FUNCTION__); }));
    mem_limit = limit;
    memset(slabclass, 0, sizeof(slabclass));
    while (++i < 200 && size <= (1024*1024*4) / 2)
    {
        if (size % (sizeof(void *)))
        {
            size += (sizeof(void *)) - (size % (sizeof(void *)));
        }
        slabclass[i].size = size;
        slabclass[i].perslab = (1024*1024*4) / slabclass[i].size;
        pthread_spin_init(&(slabclass[i].lock), PTHREAD_PROCESS_PRIVATE);
        size = (int)((double)size * factor);
    }
    power_largest = i;
    slabclass[power_largest].size = (1024*1024*4);
    slabclass[power_largest].perslab = 1;
    pthread_spin_init(&(slabclass[power_largest].lock), PTHREAD_PROCESS_PRIVATE);
}

variable_types:
limit
unsigned long

variable_types: factor double

variable_types: i int

variable_types:
size
unsigned int


decompiled_code:
void slab_stats()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void
slab_stats(void)
{
}

canonical_original_code:
void slab_stats()
{
}


decompiled_code:
pthread_mutex_t *rwlock_new()
{
pthread_mutex_t *v0; // rax
pthread_mutex_t *v1; // r12

v0 = (pthread_mutex_t *)malloc(0x70uLL);
v1 = v0;
if ( v0 )
{
*(&v0[2].__align + 2) = 0LL;
v0[2].__list.__prev = 0LL;
*(&v0[2].__align + 1) = 0LL;
pthread_mutex_init(v0, 0LL);
pthread_cond_init((pthread_cond_t *)&v1[1], 0LL);
}
return v1;
}

canonical_decompiled_code:
pthread_mutex_t *func1()
{
pthread_mutex_t *v0; // rax
pthread_mutex_t *v1; // r12

v0 = (pthread_mutex_t *)malloc(0x70uLL);
v1 = v0;
if ( v0 )
{
*(&v0[2].__align + 2) = 0LL;
v0[2].__list.__prev = 0LL;
*(&v0[2].__align + 1) = 0LL;
pthread_mutex_init(v0, 0LL);
pthread_cond_init((pthread_cond_t *)&v1[1], 0LL);
}
return v1;
}

original_code:
struct rwlock_t *
rwlock_new()
{
    struct rwlock_t *rwlock = malloc(sizeof(struct rwlock_t));
    if (rwlock == ((void *)0))
        return ((void *)0);
    rwlock->write_queue_len = 0;
    rwlock->read_queue_len = 0;
    rwlock->tobe_write_queue_len = 0;
    pthread_mutex_init(&(rwlock->lock), ((void *)0));
    pthread_cond_init(&(rwlock->condition), ((void *)0));
    return rwlock;
}

canonical_original_code:
struct rwlock_t *rwlock_new()
{
    struct rwlock_t *rwlock = malloc(sizeof(struct rwlock_t));
    if (rwlock == ((void *)0))
        return ((void *)0);
    rwlock->write_queue_len = 0;
    rwlock->read_queue_len = 0;
    rwlock->tobe_write_queue_len = 0;
    pthread_mutex_init(&(rwlock->lock), ((void *)0));
    pthread_cond_init(&(rwlock->condition), ((void *)0));
    return rwlock;
}

variable_types: struct rwlock_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } condition; unsigned long tobe_write_queue_len; unsigned long write_queue_len; unsigned long read_queue_len; } *

user_defined_types: struct rwlock_t { union pthread_mutex_t lock; union pthread_cond_t condition; unsigned long tobe_write_queue_len; unsigned long write_queue_len; unsigned long read_queue_len; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall rwlock_build(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 96) = 0LL;
*(_QWORD *)(a1 + 104) = 0LL;
*(_QWORD *)(a1 + 88) = 0LL;
pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 96) = 0LL;
*(_QWORD *)(a1 + 104) = 0LL;
*(_QWORD *)(a1 + 88) = 0LL;
pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
return 0LL;
}

original_code:
int
rwlock_build(struct rwlock_t *rwlock)
{
    if (rwlock == ((void *)0))
        return -1;
    rwlock->write_queue_len = 0;
    rwlock->read_queue_len = 0;
    rwlock->tobe_write_queue_len = 0;
    pthread_mutex_init(&(rwlock->lock), ((void *)0));
    pthread_cond_init(&(rwlock->condition), ((void *)0));
    return 0;
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall rwlock_rdlock(pthread_mutex_t *mutex)
{
if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x4Du, "rwlock_rdlock");
pthread_mutex_lock(mutex);
++mutex[2].__list.__prev;
while ( *(&mutex[2].__align + 2) )
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
pthread_mutex_unlock(mutex);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(pthread_mutex_t *mutex)
{
if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x4Du, "rwlock_rdlock");
pthread_mutex_lock(mutex);
++mutex[2].__list.__prev;
while ( *(&mutex[2].__align + 2) )
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
pthread_mutex_unlock(mutex);
return 0LL;
}

original_code:
int
rwlock_rdlock(struct rwlock_t *rwlock)
{
    ((void) sizeof ((rwlock != ((void *)0)) ? 1 : 0), __extension__ ({ if (rwlock != ((void *)0)) ; else __assert_fail ("rwlock != NULL", "slab/rwlock.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_lock(&rwlock->lock);
    rwlock->read_queue_len ++;
    while (rwlock->write_queue_len > 0)
    {
        pthread_cond_wait(&rwlock->condition, &rwlock->lock);
    }
    pthread_mutex_unlock(&rwlock->lock);
    return 0;
}


decompiled_code:
__int64 __fastcall rwlock_unrdlock(pthread_mutex_t *mutex)
{
__int64 result; // rax

if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x5Du, "rwlock_unrdlock");
pthread_mutex_lock(mutex);
if ( !--mutex[2].__list.__prev && *(&mutex[2].__align + 1) )
{
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
pthread_mutex_unlock(mutex);
result = 0LL;
}
else
{
pthread_mutex_unlock(mutex);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(pthread_mutex_t *mutex)
{
__int64 result; // rax

if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x5Du, "rwlock_unrdlock");
pthread_mutex_lock(mutex);
if ( !--mutex[2].__list.__prev && *(&mutex[2].__align + 1) )
{
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
pthread_mutex_unlock(mutex);
result = 0LL;
}
else
{
pthread_mutex_unlock(mutex);
result = 0LL;
}
return result;
}

original_code:
int
rwlock_unrdlock(struct rwlock_t *rwlock)
{
    ((void) sizeof ((rwlock != ((void *)0)) ? 1 : 0), __extension__ ({ if (rwlock != ((void *)0)) ; else __assert_fail ("rwlock != NULL", "slab/rwlock.c", 93, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_lock(&rwlock->lock);
    rwlock->read_queue_len --;
    if ((rwlock->read_queue_len == 0) && (rwlock->tobe_write_queue_len > 0))
    {
        pthread_cond_broadcast(&rwlock->condition);
    }
    pthread_mutex_unlock(&rwlock->lock);
    return 0;
}


decompiled_code:
__int64 __fastcall rwlock_wrlock(pthread_mutex_t *mutex)
{
if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x6Du, "rwlock_wrlock");
pthread_mutex_lock(mutex);
++*(&mutex[2].__align + 1);
while ( mutex[2].__list.__prev || *(&mutex[2].__align + 2) )
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
--*(&mutex[2].__align + 1);
++*(&mutex[2].__align + 2);
pthread_mutex_unlock(mutex);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(pthread_mutex_t *mutex)
{
if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x6Du, "rwlock_wrlock");
pthread_mutex_lock(mutex);
++*(&mutex[2].__align + 1);
while ( mutex[2].__list.__prev || *(&mutex[2].__align + 2) )
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
--*(&mutex[2].__align + 1);
++*(&mutex[2].__align + 2);
pthread_mutex_unlock(mutex);
return 0LL;
}

original_code:
int
rwlock_wrlock(struct rwlock_t *rwlock)
{
    ((void) sizeof ((rwlock != ((void *)0)) ? 1 : 0), __extension__ ({ if (rwlock != ((void *)0)) ; else __assert_fail ("rwlock != NULL", "slab/rwlock.c", 109, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_lock(&rwlock->lock);
    rwlock->tobe_write_queue_len ++;
    while ((rwlock->read_queue_len > 0) || (rwlock->write_queue_len > 0))
    {
        pthread_cond_wait(&rwlock->condition, &rwlock->lock);
    }
    rwlock->tobe_write_queue_len --;
    rwlock->write_queue_len ++;
    pthread_mutex_unlock(&rwlock->lock);
    return 0;
}


decompiled_code:
__int64 __fastcall rwlock_unwrlock(pthread_mutex_t *mutex)
{
if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x7Fu, "rwlock_unwrlock");
pthread_mutex_lock(mutex);
--*(&mutex[2].__align + 2);
if ( mutex[2].__list.__prev || *(&mutex[2].__align + 1) )
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
pthread_mutex_unlock(mutex);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(pthread_mutex_t *mutex)
{
if ( !mutex )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x7Fu, "rwlock_unwrlock");
pthread_mutex_lock(mutex);
--*(&mutex[2].__align + 2);
if ( mutex[2].__list.__prev || *(&mutex[2].__align + 1) )
pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
pthread_mutex_unlock(mutex);
return 0LL;
}

original_code:
int
rwlock_unwrlock(struct rwlock_t *rwlock)
{
    ((void) sizeof ((rwlock != ((void *)0)) ? 1 : 0), __extension__ ({ if (rwlock != ((void *)0)) ; else __assert_fail ("rwlock != NULL", "slab/rwlock.c", 127, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_lock(&rwlock->lock);
    rwlock->write_queue_len --;
    if ((rwlock->read_queue_len > 0) || (rwlock->tobe_write_queue_len > 0))
    {
        pthread_cond_broadcast(&rwlock->condition);
    }
    pthread_mutex_unlock(&rwlock->lock);
    return 0;
}


decompiled_code:
__int64 __fastcall rwlock_destory(__int64 a1, void (__fastcall *a2)(__int64))
{
if ( !a1 )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x8Fu, "rwlock_destory");
pthread_mutex_destroy((pthread_mutex_t *)a1);
pthread_cond_destroy((pthread_cond_t *)(a1 + 40));
a2(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, void (__fastcall *a2)(__int64))
{
if ( !a1 )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x8Fu, "rwlock_destory");
pthread_mutex_destroy((pthread_mutex_t *)a1);
pthread_cond_destroy((pthread_cond_t *)(a1 + 40));
a2(a1);
return 0LL;
}

original_code:
int
rwlock_destory(struct rwlock_t *rwlock, void (*my_free)(void *))
{
    ((void) sizeof ((rwlock != ((void *)0)) ? 1 : 0), __extension__ ({ if (rwlock != ((void *)0)) ; else __assert_fail ("rwlock != NULL", "slab/rwlock.c", 143, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_destroy(&rwlock->lock);
    pthread_cond_destroy(&rwlock->condition);
    my_free(rwlock);
    return 0;
}


decompiled_code:
__int64 __fastcall rwlock_free(void *ptr)
{
if ( !ptr )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x9Cu, "rwlock_free");
pthread_mutex_destroy((pthread_mutex_t *)ptr);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 40));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
if ( !ptr )
_assert_fail("rwlock != NULL", "slab/rwlock.c", 0x9Cu, "rwlock_free");
pthread_mutex_destroy((pthread_mutex_t *)ptr);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 40));
free(ptr);
return 0LL;
}

original_code:
int
rwlock_free(struct rwlock_t *rwlock)
{
    ((void) sizeof ((rwlock != ((void *)0)) ? 1 : 0), __extension__ ({ if (rwlock != ((void *)0)) ; else __assert_fail ("rwlock != NULL", "slab/rwlock.c", 156, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_destroy(&rwlock->lock);
    pthread_cond_destroy(&rwlock->condition);
    free(rwlock);
    return 0;
}


decompiled_code:
__int64 __fastcall log_open(char *file)
{
int v1; // eax
int v2; // eax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

pthread_mutex_init(&lock, 0LL);
if ( stat(file, &v4) )
{
v2 = open(file, 525378, 420LL);
log_fd = v2;
return (unsigned int)(v2 >> 31);
}
v1 = v4.st_mode & 0xF000;
if ( v1 == 0x8000 || v1 == 0x2000 )
{
v2 = open(file, 525314);
log_fd = v2;
return (unsigned int)(v2 >> 31);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *file)
{
int v1; // eax
int v2; // eax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

pthread_mutex_init(&lock, 0LL);
if ( stat(file, &v4) )
{
v2 = open(file, 525378, 420LL);
log_fd = v2;
return (unsigned int)(v2 >> 31);
}
v1 = v4.st_mode & 0xF000;
if ( v1 == 0x8000 || v1 == 0x2000 )
{
v2 = open(file, 525314);
log_fd = v2;
return (unsigned int)(v2 >> 31);
}
return 0xFFFFFFFFLL;
}

variable_types:
path
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }