decompiled_code:
void __fastcall tl_add_token(_QWORD **a1, _QWORD *a2)
{
_QWORD *v2; // rbx
_QWORD *v3; // rbp

if ( a2 )
{
v2 = (_QWORD *)*a2;
if ( *a2 )
{
do
{
v3 = *a1;
*v3 = g_list_append(**a1, *v2);
v2 = (_QWORD *)v2[1];
}
while ( v2 );
}
tl_unref((__int64)a2);
}
}

canonical_decompiled_code:
void __fastcall func4(_QWORD **a1, _QWORD *a2)
{
_QWORD *v2; // rbx
_QWORD *v3; // rbp

if ( a2 )
{
v2 = (_QWORD *)*a2;
if ( *a2 )
{
do
{
v3 = *a1;
*v3 = g_list_append(**a1, *v2);
v2 = (_QWORD *)v2[1];
}
while ( v2 );
}
func3((__int64)a2);
}
}

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 *


repo: lpereira/compilador-tosco

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

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

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

v4 = g_malloc0(24LL);
*(_DWORD *)v4 = 32;
*(_QWORD *)(v4 + 8) = &unk_E2;
*(_DWORD *)(v4 + 16) = a2;
*(_DWORD *)(v4 + 20) = a3;
result = g_list_append(*a1, v4);
*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: struct _TokenList { struct _GList { void *data; struct _GList *next; struct _GList *prev; } *tokens; int ref_count; } *

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

return_type: void

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

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


decompiled_code:
__int64 compiler_do()
{
__int64 v0; // rbx
__int64 v1; // rbp
double v2; // xmm0_8
double v3; // xmm5_8
double v4; // xmm6_8
double v5; // rbx
double v6; // rbp
double v8; // [rsp+0h] [rbp-98h]
double v9; // [rsp+8h] [rbp-90h]
double v10; // [rsp+10h] [rbp-88h]
double v11; // [rsp+18h] [rbp-80h]
double v12; // [rsp+20h] [rbp-78h]
double v13; // [rsp+28h] [rbp-70h]
struct timeval v14; // [rsp+30h] [rbp-68h] BYREF
struct timeval v15; // [rsp+40h] [rbp-58h] BYREF
struct timeval v16; // [rsp+50h] [rbp-48h] BYREF
struct timeval v17; // [rsp+60h] [rbp-38h] BYREF
struct timeval tv; // [rsp+70h] [rbp-28h] BYREF

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

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
__int64 v1; // rbp
double v2; // xmm0_8
double v3; // xmm5_8
double v4; // xmm6_8
double v5; // rbx
double v6; // rbp
double v8; // [rsp+0h] [rbp-98h]
double v9; // [rsp+8h] [rbp-90h]
double v10; // [rsp+10h] [rbp-88h]
double v11; // [rsp+18h] [rbp-80h]
double v12; // [rsp+20h] [rbp-78h]
double v13; // [rsp+28h] [rbp-70h]
struct timeval v14; // [rsp+30h] [rbp-68h] BYREF
struct timeval v15; // [rsp+40h] [rbp-58h] BYREF
struct timeval v16; // [rsp+50h] [rbp-48h] BYREF
struct timeval v17; // [rsp+60h] [rbp-38h] BYREF
struct timeval tv; // [rsp+70h] [rbp-28h] BYREF

gettimeofday(&tv, 0LL);
v0 = lex();
gettimeofday(&v17, 0LL);
v1 = ast(v0);
gettimeofday(&v16, 0LL);
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
optimize(v1);
gettimeofday(&v14, 0LL);
}
codegen(v1);
gettimeofday(&v15, 0LL);
tl_destroy(v0);
if ( HIDWORD(params) )
{
v2 = (double)(LODWORD(v17.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v17.tv_sec) - LODWORD(tv.tv_sec));
v3 = (double)(LODWORD(v16.tv_usec) - LODWORD(v17.tv_usec)) / 1000000.0
+ (double)(LODWORD(v16.tv_sec) - LODWORD(v17.tv_sec));
v8 = v3;
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
{
v13 = (double)(LODWORD(v14.tv_usec) - LODWORD(v16.tv_usec)) / 1000000.0
+ (double)(LODWORD(v14.tv_sec) - LODWORD(v16.tv_sec));
v9 = (double)(LODWORD(v15.tv_usec) - LODWORD(v14.tv_usec)) / 1000000.0
+ (double)(LODWORD(v15.tv_sec) - LODWORD(v14.tv_sec));
v4 = v3 + v2 + v9 + v13;
v10 = v4;
v11 = v3 * 100.0 / v4;
v12 = v9 * 100.0 / v4;
v5 = 100.0 * v13 / v4;
v6 = v11 + v2 * 100.0 / v4 + v12 + v5;
}
else
{
v9 = (double)(LODWORD(v15.tv_usec) - LODWORD(v16.tv_usec)) / 1000000.0
+ (double)(LODWORD(v15.tv_sec) - LODWORD(v16.tv_sec));
v10 = v3 + v2 + v9 + 0.0;
v11 = v3 * 100.0 / v10;
v12 = 100.0 * v9 / v10;
v6 = v11 + v2 * 100.0 / v10 + v12;
v13 = 0.0;
v5 = 0.0;
}
fprintf(stderr, format);
fprintf(stderr, aAn, v8, v11);
if ( (*((_BYTE *)&params + 20) & 1) != 0 )
fprintf(stderr, aOtimiza, v13, v5);
fprintf(stderr, aGera, v9, v12);
fprintf(stderr, "Total|%fs|%f\n", v10, v6);
}
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 _GNode { void *data; struct _GNode *next; struct _GNode *prev; struct _GNode *parent; struct _GNode *children; } *

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

return_type: int

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


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

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


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; // rbp
__int64 i; // rbp
__int64 *v7; // rax
const char ***v8; // rdx
__int64 v9; // rax
const char **v10; // r13
_DWORD *v11; // r14
__int16 v12; // bp
__int16 v13; // dx
__int64 v14; // rsi
__int64 v15; // r13
__int64 v16; // rax
unsigned int v17; // ebp
__int64 v18; // rax

if ( a1 )
{
v4 = *(_QWORD *)(a1 + 32);
if ( v4 )
{
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 || *v11 == 43 )
{
v12 = atoi(*(const char **)(v9 + 8));
v13 = atoi(v10[1]);
switch ( *v11 )
{
case 7:
if ( v13 )
{
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v12 / v13));
goto LABEL_15;
}
return;
case 0x10:
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v12 - v13));
goto LABEL_15;
case 0x11:
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v13 * v12));
goto LABEL_15;
case 0x13:
v14 = g_strdup_printf(&unk_30E, v12 != v13);
goto LABEL_15;
case 0x15:
v14 = g_strdup_printf(&unk_30E, v12 == v13);
goto LABEL_15;
case 0x16:
v14 = g_strdup_printf(&unk_30E, v12 > v13);
goto LABEL_15;
case 0x17:
v14 = g_strdup_printf(&unk_30E, v12 >= v13);
goto LABEL_15;
case 0x18:
v14 = g_strdup_printf(&unk_30E, v12 < v13);
goto LABEL_15;
case 0x19:
v14 = g_strdup_printf(&unk_30E, v12 <= v13);
goto LABEL_15;
case 0x1C:
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v13 + v12));
goto LABEL_15;
case 0x2B:
v14 = g_strdup_printf(&unk_30E, (unsigned int)-v12);
LABEL_15:
if ( !v14 )
return;
v15 = ast_node_new(39LL);
if ( !v15 )
return;
v16 = *(_QWORD *)(a2 + 32);
if ( !v16 )
return;
if ( a1 == v16 )
{
v17 = 0;
}
else
{
v17 = 0;
do
{
v16 = *(_QWORD *)(v16 + 8);
++v17;
if ( !v16 )
return;
}
while ( a1 != v16 );
}
g_node_destroy(a1);
v18 = g_node_new(v15);
g_node_insert(a2, v17, v18);
break;
default:
return;
}
}
}
}
}
}
else
{
fold_constants(v4, a1);
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 v5; // rbp
__int64 i; // rbp
__int64 *v7; // rax
const char ***v8; // rdx
__int64 v9; // rax
const char **v10; // r13
_DWORD *v11; // r14
__int16 v12; // bp
__int16 v13; // dx
__int64 v14; // rsi
__int64 v15; // r13
__int64 v16; // rax
unsigned int v17; // ebp
__int64 v18; // rax

if ( a1 )
{
v4 = *(_QWORD *)(a1 + 32);
if ( v4 )
{
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 || *v11 == 43 )
{
v12 = atoi(*(const char **)(v9 + 8));
v13 = atoi(v10[1]);
switch ( *v11 )
{
case 7:
if ( v13 )
{
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v12 / v13));
goto LABEL_15;
}
return;
case 0x10:
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v12 - v13));
goto LABEL_15;
case 0x11:
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v13 * v12));
goto LABEL_15;
case 0x13:
v14 = g_strdup_printf(&unk_30E, v12 != v13);
goto LABEL_15;
case 0x15:
v14 = g_strdup_printf(&unk_30E, v12 == v13);
goto LABEL_15;
case 0x16:
v14 = g_strdup_printf(&unk_30E, v12 > v13);
goto LABEL_15;
case 0x17:
v14 = g_strdup_printf(&unk_30E, v12 >= v13);
goto LABEL_15;
case 0x18:
v14 = g_strdup_printf(&unk_30E, v12 < v13);
goto LABEL_15;
case 0x19:
v14 = g_strdup_printf(&unk_30E, v12 <= v13);
goto LABEL_15;
case 0x1C:
v14 = g_strdup_printf(&unk_30E, (unsigned int)(v13 + v12));
goto LABEL_15;
case 0x2B:
v14 = g_strdup_printf(&unk_30E, (unsigned int)-v12);
LABEL_15:
if ( !v14 )
return;
v15 = ast_node_new(39LL);
if ( !v15 )
return;
v16 = *(_QWORD *)(a2 + 32);
if ( !v16 )
return;
if ( a1 == v16 )
{
v17 = 0;
}
else
{
v17 = 0;
do
{
v16 = *(_QWORD *)(v16 + 8);
++v17;
if ( !v16 )
return;
}
while ( a1 != v16 );
}
g_node_destroy(a1);
v18 = g_node_new(v15);
g_node_insert(a2, v17, v18);
break;
default:
return;
}
}
}
}
}
}
else
{
func0(v4, a1);
}
}
}
}

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:
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 _GNode { void *data; struct _GNode *next; struct _GNode *prev; struct _GNode *parent; struct _GNode *children; }

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


decompiled_code:
__int64 __fastcall fold_constants_traverse_func(unsigned int **a1)
{
unsigned int v1; // ecx

v1 = **a1;
if ( v1 > 0x28 || ((1LL << v1) & 0x11000002008LL) == 0 )
return 0LL;
fold_constants((__int64)a1, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int **a1)
{
unsigned int v1; // ecx

v1 = **a1;
if ( v1 > 0x28 || ((1LL << v1) & 0x11000002008LL) == 0 )
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()
{
char *result; // rax
unsigned int v1; // ebp
char v2[280]; // [rsp+0h] [rbp-118h] BYREF

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

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

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

variable_types:
rt
char *

variable_types:
ibuf
char [256]


decompiled_code:
int tap_output()
{
__int64 v0; // rbx
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 )
{
*(&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",
(unsigned int)tap_tests,
(unsigned int)tap_testsRead);
printf("Files=1, Tests=%u, %lu msecs\n", (unsigned int)tap_testsRead, v0);
result = puts("Result: FAIL");
}
return result;
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx
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 )
{
*(&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",
(unsigned int)tap_tests,
(unsigned int)tap_testsRead);
printf("Files=1, Tests=%u, %lu msecs\n", (unsigned int)tap_testsRead, 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, const char *a2)
{
__int64 v3; // rdx
const char *v4; // rsi

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

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

v3 = (unsigned int)++testnum_0;
v4 = "ok";
if ( !a1 )
v4 = "not ok";
return printf("%s %d - %s\n", v4, v3, 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)
{
int v1; // ecx
__int64 v3; // rbp
void *v4; // rax
__int64 v5; // rcx

v1 = dword_6D0[14 * a1];
if ( dword_6C4[14 * a1] != v1 )
return 1LL;
v3 = (unsigned int)(2 * v1);
if ( !v1 )
v3 = 16LL;
v4 = realloc((void *)qword_6C8[7 * a1], 8 * v3);
if ( !v4 )
return 0;
v5 = 7LL * a1;
dword_6D0[2 * v5] = v3;
qword_6C8[v5] = (__int64)v4;
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // ecx
__int64 v3; // rbp
void *v4; // rax
__int64 v5; // rcx

v1 = dword_6D0[14 * a1];
if ( dword_6C4[14 * a1] != v1 )
return 1LL;
v3 = (unsigned int)(2 * v1);
if ( !v1 )
v3 = 16LL;
v4 = realloc((void *)qword_6C8[7 * a1], 8 * v3);
if ( !v4 )
return 0;
v5 = 7LL * a1;
dword_6D0[2 * v5] = v3;
qword_6C8[v5] = (__int64)v4;
return 1;
}

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; // rax
__int64 v3; // rsi
unsigned int v4; // ecx

if ( !mem_limit || mem_limit >= (unsigned __int64)(mem_malloced + 0x400000) || (result = 0LL, !dword_6C4[14 * a1]) )
{
result = grow_slab_list(a1);
if ( (_DWORD)result )
{
v2 = valloc(0x400000uLL);
if ( v2 )
{
qword_6B8[7 * a1] = (__int64)v2;
dword_6C0[14 * a1] = dword_6A4[14 * a1];
v3 = qword_6C8[7 * a1];
v4 = dword_6C4[14 * a1];
dword_6C4[14 * a1] = v4 + 1;
*(_QWORD *)(v3 + 8LL * v4) = v2;
mem_malloced += 0x400000LL;
result = 1LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

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

if ( !mem_limit || mem_limit >= (unsigned __int64)(mem_malloced + 0x400000) || (result = 0LL, !dword_6C4[14 * a1]) )
{
result = func0(a1);
if ( (_DWORD)result )
{
v2 = valloc(0x400000uLL);
if ( v2 )
{
qword_6B8[7 * a1] = (__int64)v2;
dword_6C0[14 * a1] = dword_6A4[14 * a1];
v3 = qword_6C8[7 * a1];
v4 = dword_6C4[14 * a1];
dword_6C4[14 * a1] = v4 + 1;
*(_QWORD *)(v3 + 8LL * v4) = v2;
mem_malloced += 0x400000LL;
result = 1LL;
}
else
{
result = 0LL;
}
}
}
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 = (unsigned int)slabclass[14 * (int)result];
if ( v4 <= a1 )
{
if ( v4 >= a1 )
return result;
v3 = result + 1;
result = (unsigned int)(((int)result + 1 + v2) / 2);
}
else
{
v2 = result - 1;
if ( (unsigned int)slabclass[14 * (int)result - 14] < a1 )
return result;
result = (unsigned int)((v2 + v3) / 2);
}
}
while ( v3 <= v2 );
}
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 = (unsigned int)slabclass[14 * (int)result];
if ( v4 <= a1 )
{
if ( v4 >= a1 )
return result;
v3 = result + 1;
result = (unsigned int)(((int)result + 1 + v2) / 2);
}
else
{
v2 = result - 1;
if ( (unsigned int)slabclass[14 * (int)result - 14] < a1 )
return result;
result = (unsigned int)((v2 + v3) / 2);
}
}
while ( v3 <= v2 );
}
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
int v3; // er12
unsigned int v4; // ebx

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 = 1;
v4 = 16;
while ( 1 )
{
*(v2 - 13) = v4;
*(v2 - 12) = 0x400000 / v4;
pthread_spin_init(v2, 0);
v4 = (int)((double)(int)v4 * a2);
++v3;
if ( v4 > 0x200000 || v3 > 199 )
break;
if ( (v4 & 7) != 0 )
v4 = (v4 & 0xFFFFFFF8) + 8;
v2 += 14;
}
power_largest = v3;
slabclass[14 * v3] = 0x400000;
dword_6A4[14 * v3] = 1;
return pthread_spin_init(&dword_6D4[14 * v3], 0);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, double a2)
{
pthread_spinlock_t *v2; // rbp
int v3; // er12
unsigned int v4; // ebx

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 = 1;
v4 = 16;
while ( 1 )
{
*(v2 - 13) = v4;
*(v2 - 12) = 0x400000 / v4;
pthread_spin_init(v2, 0);
v4 = (int)((double)(int)v4 * a2);
++v3;
if ( v4 > 0x200000 || v3 > 199 )
break;
if ( (v4 & 7) != 0 )
v4 = (v4 & 0xFFFFFFF8) + 8;
v2 += 14;
}
power_largest = v3;
slabclass[14 * v3] = 0x400000;
dword_6A4[14 * v3] = 1;
return pthread_spin_init(&dword_6D4[14 * v3], 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 func6()
{
;
}

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; // rbx

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; // rbx

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)
{
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);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(pthread_mutex_t *mutex)
{
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);
return 0LL;
}

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
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

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

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

pthread_mutex_init(&lock, 0LL);
if ( stat(file, &v3) )
{
log_fd = open(file, 525378, 420LL);
return (unsigned int)(log_fd >> 31);
}
v1 = v3.st_mode & 0xF000;
if ( v1 == 0x8000 || v1 == 0x2000 )
{
log_fd = open(file, 525314);
return (unsigned int)(log_fd >> 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]; }


decompiled_code:
__int64 log_mesg(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
__int64 v5; // r13
const char *v7; // r14
unsigned int v8; // er15
int v9; // ebx
int v10; // ebx
size_t v11; // rax
char s[32]; // [rsp+0h] [rbp-2168h] BYREF
struct tm tp; // [rsp+20h] [rbp-2148h] BYREF
time_t timer; // [rsp+60h] [rbp-2108h] BYREF
gcc_va_list arg; // [rsp+68h] [rbp-2100h] BYREF
char buf[8192]; // [rsp+80h] [rbp-20E8h] BYREF

v5 = a3;
if ( a4 == 4 )
{
v7 = "error";
}
else if ( a4 > 4 )
{
v7 = "what's this";
if ( a4 == 8 )
v7 = "info ";
}
else
{
if ( a4 == 1 )
return 0LL;
v7 = "what's this";
if ( a4 == 2 )
v7 = "warn ";
}
v8 = syscall(186LL);
timer = time(0LL);
localtime_r(&timer, &tp);
snprintf(
s,
0x1EuLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
va_start(arg, a5);
v9 = snprintf(buf, 0x2000uLL, "[%s] [%s] (#%d %s %s:%d) ", s, v7, v8, a2, a1, v5);
v10 = vsnprintf(&buf[v9], 0x2000LL - v9, a5, arg) + v9;
if ( v10 > 8190 )
v10 = 8190;
buf[v10] = 10;
buf[v10 + 1] = 0;
pthread_mutex_lock(&lock);
v11 = strlen(buf);
write(log_fd, buf, v11);
pthread_mutex_unlock(&lock);
return 0LL;
}

canonical_decompiled_code:
__int64 func1(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
__int64 v5; // r13
const char *v7; // r14
unsigned int v8; // er15
int v9; // ebx
int v10; // ebx
size_t v11; // rax
char s[32]; // [rsp+0h] [rbp-2168h] BYREF
struct tm tp; // [rsp+20h] [rbp-2148h] BYREF
time_t timer; // [rsp+60h] [rbp-2108h] BYREF
gcc_va_list arg; // [rsp+68h] [rbp-2100h] BYREF
char buf[8192]; // [rsp+80h] [rbp-20E8h] BYREF

v5 = a3;
if ( a4 == 4 )
{
v7 = "error";
}
else if ( a4 > 4 )
{
v7 = "what's this";
if ( a4 == 8 )
v7 = "info ";
}
else
{
if ( a4 == 1 )
return 0LL;
v7 = "what's this";
if ( a4 == 2 )
v7 = "warn ";
}
v8 = syscall(186LL);
timer = time(0LL);
localtime_r(&timer, &tp);
snprintf(
s,
0x1EuLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
va_start(arg, a5);
v9 = snprintf(buf, 0x2000uLL, "[%s] [%s] (#%d %s %s:%d) ", s, v7, v8, a2, a1, v5);
v10 = vsnprintf(&buf[v9], 0x2000LL - v9, a5, arg) + v9;
if ( v10 > 8190 )
v10 = 8190;
buf[v10] = 10;
buf[v10 + 1] = 0;
pthread_mutex_lock(&lock);
v11 = strlen(buf);
write(log_fd, buf, v11);
pthread_mutex_unlock(&lock);
return 0LL;
}

original_code:
int
log_mesg(const char *codefile, const char *func, int linenum, uint32_t mesg_level, const char *fmt, ...)
{
    char line[8192];
    va_list ap;
    char *level;
    time_t now;
    struct tm t;
    char time_string[30];
    int printed_len;
    int process_id;
    switch (mesg_level)
    {
    case 0x1:
        return 0;
        level = "debug";
        break;
    case 0x2:
        level = "warn ";
        break;
    case 0x4:
        level = "error";
        break;
    case 0x8:
        level = "info ";
        break;
    default:
        level = "what's this";
        break;
    }
    process_id = (int)syscall(186);
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(time_string, sizeof time_string, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    __builtin_va_start(ap,fmt);
    printed_len = snprintf(line, sizeof(line), "[%s] [%s] (#%d %s %s:%d) ", time_string, level, process_id, func, codefile, linenum);
    printed_len += vsnprintf(line + printed_len, sizeof(line) - printed_len, fmt, ap);
    __builtin_va_end(ap);
    if (printed_len > 8192 - 2)
        printed_len = 8192 - 2;
    line[ printed_len ] = '\n';
    line[ printed_len + 1 ] = '\0';
    pthread_mutex_lock(&lock);
    ssize_t writesize = write(log_fd, line, strlen(line));
    (void) writesize;
    pthread_mutex_unlock(&lock);
    return 0;
}

canonical_original_code:
int log_mesg(char *codefile, char *func, int linenum, unsigned int mesg_level, char *fmt, ...)
{
    char line[8192];
    __builtin_va_list ap;
    char *level;
    long now;
    struct tm t;
    char time_string[30];
    int printed_len;
    int process_id;
    switch (mesg_level)
    {
    case 0x1:
        return 0;
        level = "debug";
        break;
    case 0x2:
        level = "warn ";
        break;
    case 0x4:
        level = "error";
        break;
    case 0x8:
        level = "info ";
        break;
    default:
        level = "what's this";
        break;
    }
    process_id = (int)syscall(186);
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(time_string, sizeof time_string, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    __builtin_va_start(ap,fmt);
    printed_len = snprintf(line, sizeof(line), "[%s] [%s] (#%d %s %s:%d) ", time_string, level, process_id, func, codefile, linenum);
    printed_len += vsnprintf(line + printed_len, sizeof(line) - printed_len, fmt, ap);
    __builtin_va_end(ap);
    if (printed_len > 8192 - 2)
        printed_len = 8192 - 2;
    line[ printed_len ] = '\n';
    line[ printed_len + 1 ] = '\0';
    pthread_mutex_lock(&lock);
    long writesize = write(log_fd, line, strlen(line));
    (void) writesize;
    pthread_mutex_unlock(&lock);
    return 0;
}

variable_types:
codefile
char *

variable_types:
func
char *

variable_types: linenum int

variable_types:
fmt
char *

variable_types:
line
char [8192]

variable_types:
level
char *

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: writesize long


decompiled_code:
__int64 log_close()
{
pthread_mutex_destroy(&lock);
close(log_fd);
log_fd = -1;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
pthread_mutex_destroy(&lock);
close(log_fd);
log_fd = -1;
return 0LL;
}

original_code:
int
log_close()
{
    pthread_mutex_destroy(&lock);
    close(log_fd);
    log_fd = -1;
    return 0;
}


decompiled_code:
char *__fastcall get_time_string(char *s)
{
struct tm v2; // [rsp+0h] [rbp-48h] BYREF
time_t timer; // [rsp+38h] [rbp-10h] BYREF

timer = time(0LL);
localtime_r(&timer, &v2);
snprintf(
s,
0x14uLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(v2.tm_year + 1900),
(unsigned int)(v2.tm_mon + 1),
(unsigned int)v2.tm_mday,
(unsigned int)v2.tm_hour,
(unsigned int)v2.tm_min,
(unsigned int)v2.tm_sec);
s[19] = 0;
return s;
}

canonical_decompiled_code:
char *__fastcall func4(char *s)
{
struct tm v2; // [rsp+0h] [rbp-48h] BYREF
time_t timer; // [rsp+38h] [rbp-10h] BYREF

timer = time(0LL);
localtime_r(&timer, &v2);
snprintf(
s,
0x14uLL,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(v2.tm_year + 1900),
(unsigned int)(v2.tm_mon + 1),
(unsigned int)v2.tm_mday,
(unsigned int)v2.tm_hour,
(unsigned int)v2.tm_min,
(unsigned int)v2.tm_sec);
s[19] = 0;
return s;
}

original_code:
const char *
get_time_string(char *string)
{
    time_t now;
    struct tm t;
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(string, 20, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    string[19] = '\0';
    return string;
}

canonical_original_code:
char *get_time_string(char *string)
{
    long now;
    struct tm t;
    now = time(((void *)0));
    localtime_r(&now, &t);
    snprintf(string, 20, "%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    string[19] = '\0';
    return string;
}

variable_types:
string
char *

return_type: char *

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
__int64 __fastcall crc32_calc(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
unsigned int v3; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = -1;
do
v3 = crc32_tab[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( v2 != a1 );
}
else
{
v3 = -1;
}
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
unsigned int v3; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = -1;
do
v3 = crc32_tab[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( v2 != a1 );
}
else
{
v3 = -1;
}
return ~v3;
}

original_code:
uint32_t
crc32_calc(const char *buf, size_t size)
{
    const unsigned char *p;
    uint32_t crc;
    p = (const unsigned char *)buf;
    crc = ~0U;
    while (size--)
        crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
    return crc ^ ~0U;
}

canonical_original_code:
unsigned int crc32_calc(char *buf, unsigned long size)
{
    unsigned char *p;
    unsigned int crc;
    p = (unsigned char *)buf;
    crc = ~0U;
    while (size--)
        crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
    return crc ^ ~0U;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types:
p
unsigned char *

variable_types:
crc
unsigned int


decompiled_code:
bool __fastcall is_valid_name(char *a1)
{
char v1; // dl
int v2; // ecx
bool result; // al

v1 = *a1;
v2 = 1;
if ( *a1 )
{
while ( 1 )
{
result = v1 == 95 || (unsigned __int8)(v1 - 97) <= 0x19u || (unsigned __int8)(v1 - 48) <= 9u;
if ( !result )
break;
v1 = *++a1;
if ( !*a1 )
goto LABEL_5;
if ( ++v2 == 32 )
return 0;
}
}
else
{
v2 = 0;
LABEL_5:
result = v2 > 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(char *a1)
{
char v1; // dl
int v2; // ecx
bool result; // al

v1 = *a1;
v2 = 1;
if ( *a1 )
{
while ( 1 )
{
result = v1 == 95 || (unsigned __int8)(v1 - 97) <= 0x19u || (unsigned __int8)(v1 - 48) <= 9u;
if ( !result )
break;
v1 = *++a1;
if ( !*a1 )
goto LABEL_5;
if ( ++v2 == 32 )
return 0;
}
}
else
{
v2 = 0;
LABEL_5:
result = v2 > 0;
}
return result;
}

original_code:
_Bool is_valid_name(const char *name) {
    int len = 0;
    while (*name) {
        char ch = *name;
        if (++len < 32 && ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch == '_'))) {
            name++;
            continue;
        }
        return 0;
    }
    return len > 0 && name[0] != '_';
}

canonical_original_code:
_Bool is_valid_name(char *name) {
    int len = 0;
    while (*name) {
        char ch = *name;
        if (++len < 32 && ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch == '_'))) {
            name++;
            continue;
        }
        return 0;
    }
    return len > 0 && name[0] != '_';
}

variable_types:
name
char *

variable_types: len int

variable_types: ch char


decompiled_code:
__int64 randu64()
{
int v0; // ebx
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/urandom", 0x80000);
read(v0, &buf, 8uLL);
close(v0);
return buf;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/urandom", 0x80000);
read(v0, &buf, 8uLL);
close(v0);
return buf;
}

original_code:
uint64_t randu64() {
    uint64_t result;
    int fd = open("/dev/urandom", 00 | 02000000);
    ssize_t readsize = read(fd, &result, sizeof(result));
    (void) readsize;
    close(fd);
    return result;
}

canonical_original_code:
unsigned long randu64() {
    unsigned long result;
    int fd = open("/dev/urandom", 00 | 02000000);
    long readsize = read(fd, &result, sizeof(result));
    (void) readsize;
    close(fd);
    return result;
}

variable_types:
result
unsigned long

variable_types: fd int

variable_types: readsize long

return_type: unsigned long


decompiled_code:
void __fastcall stat_add(int a1, unsigned __int64 a2)
{
_InterlockedAdd64(&stats[a1], a2);
}

canonical_decompiled_code:
void __fastcall func0(int a1, unsigned __int64 a2)
{
_InterlockedAdd64(&stats[a1], a2);
}

original_code:
void stat_add(int key, uint64_t value) {
    __sync_add_and_fetch(&stats[key], value);
}

canonical_original_code:
void stat_add(int key, unsigned long value) {
    __sync_add_and_fetch(&stats[key], value);
}

variable_types: key int

variable_types:
value
unsigned long


repo: lrem/splay

decompiled_code:
__int64 __fastcall compare_int(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int compare_int(void *l, void *r) {
    return *((int*)l) - *((int*)r);
}

canonical_original_code:
int compare_int(void *l, void *r) {
    return *((int *)l) - *((int *)r);
}

variable_types:
l
void *

variable_types:
r
void *


output

decompiled_code:
int __fastcall output(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // r12
__int64 v3; // rbx

for ( i = first(); i; i = next(i) )
printf("%d ", **(unsigned int **)(i + 24));
putchar(10);
v2 = contents(a1);
if ( *(int *)(a1 + 16) > 0 )
{
v3 = 0LL;
do
printf("%d ", **(unsigned int **)(v2 + 8 * v3++));
while ( *(_DWORD *)(a1 + 16) > (int)v3 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // r12
__int64 v3; // rbx

for ( i = func12(); i; i = next(i) )
printf("%d ", **(unsigned int **)(i + 24));
putchar(10);
v2 = func9(a1);
if ( *(int *)(a1 + 16) > 0 )
{
v3 = 0LL;
do
printf("%d ", **(unsigned int **)(v2 + 8 * v3++));
while ( *(_DWORD *)(a1 + 16) > (int)v3 );
}
return putchar(10);
}

original_code:
void output(splay_tree *tree) {
    splay_node *node = first(tree);
    while(node != ((void *)0)) {
        printf("%d ", *(int*)node->value);
        node = next(node);
    }
    printf("\n");
    void **t = contents(tree);
    for(int i = 0; i < tree->size; i++) {
        printf("%d ", *(int*)t[i]);
    }
    printf("\n");
}

canonical_original_code:
void output(struct splay_tree *tree) {
    struct splay_node *node = first(tree);
    while(node != ((void *)0)) {
        printf("%d ", *(int *)node->value);
        node = next(node);
    }
    printf("\n");
    void **t = contents(tree);
    for(int i = 0; i < tree->size; i++) {
        printf("%d ", *(int *)t[i]);
    }
    printf("\n");
}

variable_types: struct splay_tree { struct splay_node { struct splay_node *parent; void *value; } *root; int (*comp)(void *left, void *right); int size; } *

variable_types:
t
void **

variable_types: i int

user_defined_types: struct splay_tree { struct splay_node *root; int (*comp)(void *left, void *right); int size; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // rbp
char *v5; // r12
unsigned int v6; // er14
__int64 v7; // rax
unsigned int v8; // er12
__int64 v9; // rax
int v11[7]; // [rsp+0h] [rbp-48h] BYREF
char v12[44]; // [rsp+1Ch] [rbp-2Ch] BYREF

v3 = new_tree(compare_int, argv, envp);
v11[0] = 3;
v11[1] = 4;
v11[2] = 1;
v11[3] = 2;
v11[4] = 8;
v11[5] = 5;
v11[6] = 7;
output(v3);
v4 = (char *)v11;
v5 = (char *)v11;
do
{
insert(v3, v5);
v6 = **(_DWORD **)(last(v3) + 24);
v7 = first(v3);
printf("+%d: min %d max %d\n", *(unsigned int *)v5, **(unsigned int **)(v7 + 24), v6);
output(v3);
v5 += 4;
}
while ( v5 != v12 );
do
{
delete(v3, v4);
printf("-%d: ", *(unsigned int *)v4);
if ( first(v3) )
{
v8 = **(_DWORD **)(last(v3) + 24);
v9 = first(v3);
printf("min %d max %d\n", **(unsigned int **)(v9 + 24), v8);
}
else
{
puts("EMPTY");
}
output(v3);
v4 += 4;
}
while ( v4 != v12 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // rbp
char *v5; // r12
unsigned int v6; // er14
__int64 v7; // rax
unsigned int v8; // er12
__int64 v9; // rax
int v11[7]; // [rsp+0h] [rbp-48h] BYREF
char v12[44]; // [rsp+1Ch] [rbp-2Ch] BYREF

v3 = new_tree(compare_int, argv, envp);
v11[0] = 3;
v11[1] = 4;
v11[2] = 1;
v11[3] = 2;
v11[4] = 8;
v11[5] = 5;
v11[6] = 7;
func8(v3);
v4 = (char *)v11;
v5 = (char *)v11;
do
{
insert(v3, v5);
v6 = **(_DWORD **)(func16(v3) + 24);
v7 = func12(v3);
printf("+%d: min %d max %d\n", *(unsigned int *)v5, **(unsigned int **)(v7 + 24), v6);
func8(v3);
v5 += 4;
}
while ( v5 != v12 );
do
{
func14(v3, v4);
printf("-%d: ", *(unsigned int *)v4);
if ( func12(v3) )
{
v8 = **(_DWORD **)(func16(v3) + 24);
v9 = func12(v3);
printf("min %d max %d\n", **(unsigned int **)(v9 + 24), v8);
}
else
{
puts("EMPTY");
}
func8(v3);
v4 += 4;
}
while ( v4 != v12 );
return 0;
}

original_code:
int main() {
    splay_tree *tree = new_tree(&compare_int);
    int values[] = {3, 4, 1, 2, 8, 5, 7};
    output(tree);
    for(int i = 0; i < 7; i++) {
        insert(tree, &values[i]);
        printf("+%d: min %d max %d\n", values[i],
                *(int*)first(tree)->value, *(int*)last(tree)->value);
        output(tree);
    }
    for(int i = 0; i < 7; i++) {
        delete(tree, &values[i]);
        printf("-%d: ", values[i]);
        if(first(tree) == ((void *)0)) {
            printf("EMPTY\n");
        } else {
            printf("min %d max %d\n",
                    *(int*)first(tree)->value, *(int*)last(tree)->value);
        }
        output(tree);
    }
    return 0;
}

canonical_original_code:
int main() {
    struct splay_tree *tree = new_tree(&compare_int);
    int values[] = {3, 4, 1, 2, 8, 5, 7};
    output(tree);
    for(int i = 0; i < 7; i++) {
        insert(tree, &values[i]);
        printf("+%d: min %d max %d\n", values[i],
                *(int *)first(tree)->value, *(int *)last(tree)->value);
        output(tree);
    }
    for(int i = 0; i < 7; i++) {
        delete(tree, &values[i]);
        printf("-%d: ", values[i]);
        if(first(tree) == ((void *)0)) {
            printf("EMPTY\n");
        } else {
            printf("min %d max %d\n",
                    *(int *)first(tree)->value, *(int *)last(tree)->value);
        }
        output(tree);
    }
    return 0;
}

variable_types:
values
int []

user_defined_types: struct splay_node { struct splay_node *parent; void *value; }


contents

decompiled_code:
char *__fastcall contents(__int64 a1)
{
int v2; // edi
char *result; // rax
char *v4; // [rsp+8h] [rbp-10h] BYREF

v2 = *(_DWORD *)(a1 + 16);
result = 0LL;
if ( v2 )
{
v4 = (char *)malloc(8LL * v2);
store(*(_QWORD **)a1, &v4);
result = &v4[-8 * *(int *)(a1 + 16)];
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
int v2; // edi
char *result; // rax
char *v4; // [rsp+8h] [rbp-10h] BYREF

v2 = *(_DWORD *)(a1 + 16);
result = 0LL;
if ( v2 )
{
v4 = (char *)malloc(8LL * v2);
store(*(_QWORD **)a1, &v4);
result = &v4[-8 * *(int *)(a1 + 16)];
}
return result;
}

original_code:
extern void* contents(splay_tree *tree) {
    if(tree->size == 0)
        return ((void *)0);
    void **out = malloc(tree->size * sizeof(void*));
    void ***tmp = &out;
    store(tree->root, tmp);
    return out - tree->size;
}

canonical_original_code:
extern void *contents(struct splay_tree *tree) {
    if(tree->size == 0)
        return ((void *)0);
    void **out = malloc(tree->size * sizeof(void*));
    void ***tmp = &out;
    store(tree->root, tmp);
    return out - tree->size;
}

variable_types:
out
void **

variable_types:
tmp
void ***

return_type: void *


leftmost

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

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

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

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

original_code:
splay_node* leftmost(splay_node *node) {
    splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->left;
    }
    return parent;
}

canonical_original_code:
struct splay_node *leftmost(struct splay_node *node) {
    struct splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->left;
    }
    return parent;
}

variable_types:
node
struct splay_node *

variable_types: struct splay_node { struct splay_node *parent; void *value; } *


first

decompiled_code:
__int64 __fastcall first(__int64 *a1)
{
return leftmost(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1)
{
return func11(*a1);
}

original_code:
extern splay_node* first(splay_tree *tree) {
    return leftmost(tree->root);
}

canonical_original_code:
extern struct splay_node *first(struct splay_tree *tree) {
    return leftmost(tree->root);
}

variable_types: struct splay_tree { struct splay_node *root; int (*comp)(void *left, void *right); int size; } *

return_type: struct splay_node { struct splay_node *parent; void *value; } *


original_code:
extern void delete_hint(splay_tree *tree, splay_node *node) {
    if(node == ((void *)0))
        return;
    splay(tree, node);
    if(node->left == ((void *)0)) {
        tree->root = node->right;
        if(tree->root != ((void *)0))
            tree->root->parent = ((void *)0);
    } else if(node->right == ((void *)0)) {
        tree->root = node->left;
        tree->root->parent = ((void *)0);
    } else {
        splay_node *x = leftmost(node->right);
        if(x->parent != node) {
            x->parent->left = x->right;
            if(x->right != ((void *)0))
                x->right->parent = x->parent;
            x->right = node->right;
            x->right->parent = x;
        }
        tree->root = x;
        x->parent = ((void *)0);
        x->left = node->left;
        x->left->parent = x;
    }
    free(node);
    tree->size--;
    check_sanity(tree);
}

canonical_original_code:
extern void delete_hint(struct splay_tree *tree, struct splay_node *node) {
    if(node == ((void *)0))
        return;
    splay(tree, node);
    if(node->left == ((void *)0)) {
        tree->root = node->right;
        if(tree->root != ((void *)0))
            tree->root->parent = ((void *)0);
    } else if(node->right == ((void *)0)) {
        tree->root = node->left;
        tree->root->parent = ((void *)0);
    } else {
        struct splay_node *x = leftmost(node->right);
        if(x->parent != node) {
            x->parent->left = x->right;
            if(x->right != ((void *)0))
                x->right->parent = x->parent;
            x->right = node->right;
            x->right->parent = x;
        }
        tree->root = x;
        x->parent = ((void *)0);
        x->left = node->left;
        x->left->parent = x;
    }
    free(node);
    tree->size--;
    check_sanity(tree);
}


delete

decompiled_code:
void __fastcall delete(__int64 a1, __int64 a2)
{
__int64 **v2; // rax

v2 = find(a1, a2);
delete_hint(a1, (__int64)v2);
}

original_code:
extern void delete(splay_tree *tree, void *value) {
    splay_node *node = find(tree, value);
    delete_hint(tree, node);
}

canonical_original_code:
extern void delete(struct splay_tree *tree, void *value) {
    struct splay_node *node = find(tree, value);
    delete_hint(tree, node);
}

variable_types:
value
void *


rightmost

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

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

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

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

original_code:
splay_node* rightmost(splay_node *node) {
    splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->right;
    }
    return parent;
}

canonical_original_code:
struct splay_node *rightmost(struct splay_node *node) {
    struct splay_node *parent = ((void *)0);
    while(node != ((void *)0)) {
        parent = node;
        node = node->right;
    }
    return parent;
}


last

decompiled_code:
__int64 __fastcall last(__int64 *a1)
{
return rightmost(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1)
{
return func15(*a1);
}

original_code:
extern splay_node* last(splay_tree *tree) {
    return rightmost(tree->root);
}

canonical_original_code:
extern struct splay_node *last(struct splay_tree *tree) {
    return rightmost(tree->root);
}


decompiled_code:
void check_sanity()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void check_sanity(splay_tree *tree) {
}

canonical_original_code:
void check_sanity(struct splay_tree *tree) {
}


original_code:
static bbus_hashmap* create_hashmap(enum bbus_hmap_type type, size_t size)
{
 bbus_hashmap* hmap;
 unsigned i;
 hmap = bbus_malloc(sizeof(struct __bbus_hashmap));
 if (hmap == ((void *)0))
  return ((void *)0);
 hmap->buckets = bbus_malloc(size * sizeof(struct entry_list));
 if (hmap->buckets == ((void *)0)) {
  bbus_free(hmap);
  return ((void *)0);
 }
 for (i = 0; i < size; ++i) {
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
 hmap->size = size;
 hmap->numstored = 0;
 hmap->type = type;
 return hmap;
}

canonical_original_code:
static struct __bbus_hashmap *create_hashmap(enum bbus_hmap_type type, unsigned long size)
{
 struct __bbus_hashmap *hmap;
 unsigned int i;
 hmap = bbus_malloc(sizeof(struct __bbus_hashmap));
 if (hmap == ((void *)0))
  return ((void *)0);
 hmap->buckets = bbus_malloc(size * sizeof(struct entry_list));
 if (hmap->buckets == ((void *)0)) {
  bbus_free(hmap);
  return ((void *)0);
 }
 for (i = 0; i < size; ++i) {
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
 hmap->size = size;
 hmap->numstored = 0;
 hmap->type = type;
 return hmap;
}

variable_types:
size
unsigned long

variable_types: struct __bbus_hashmap { unsigned long size; unsigned long numstored; struct entry_list { struct map_entry { struct map_entry *next; struct map_entry *prev; void *key; unsigned long ksize; void *val; } *head; struct map_entry *tail; } *buckets; enum bbus_hmap_type { BBUS_HMAP_KEYUINT=1, BBUS_HMAP_KEYSTR=2 } type; } *

variable_types:
i
unsigned int

user_defined_types: struct __bbus_hashmap { unsigned long size; unsigned long numstored; struct entry_list *buckets; enum bbus_hmap_type type; }

user_defined_types: struct entry_list { struct map_entry *head; struct map_entry *tail; }


decompiled_code:
__int64 dump_append(char **a1, size_t *a2, const char *a3, ...)
{
int v3; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
v3 = vsnprintf(*a1, *a2, a3, arg);
if ( v3 >= *(_DWORD *)a2 )
{
_bbus_seterr(10004LL);
result = 0xFFFFFFFFLL;
}
else
{
*a1 += v3;
*a2 -= v3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2(char **a1, size_t *a2, const char *a3, ...)
{
int v3; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
v3 = vsnprintf(*a1, *a2, a3, arg);
if ( v3 >= *(_DWORD *)a2 )
{
_bbus_seterr(10004LL);
result = 0xFFFFFFFFLL;
}
else
{
*a1 += v3;
*a2 -= v3;
result = 0LL;
}
return result;
}

original_code:
static int __attribute__((format(printf, 3, 4))) dump_append(char** buf,
  size_t* bufsize, const char* fmt, ...)
{
 int r;
 va_list va;
 __builtin_va_start(va,fmt);
 r = vsnprintf(*buf, *bufsize, fmt, va);
 if (r >= (int)(*bufsize)) {
  __bbus_seterr(10004);
  return -1;
 }
 *buf += r;
 *bufsize -= r;
 return 0;
}

canonical_original_code:
static int dump_append(char **buf, unsigned long *bufsize, char *fmt, ...)
{
 int r;
 __builtin_va_list va;
 __builtin_va_start(va,fmt);
 r = vsnprintf(*buf, *bufsize, fmt, va);
 if (r >= (int)(*bufsize)) {
  __bbus_seterr(10004);
  return -1;
 }
 *buf += r;
 *bufsize -= r;
 return 0;
}

variable_types:
buf
char **

variable_types:
bufsize
unsigned long *

variable_types:
fmt
char *

variable_types: r int


decompiled_code:
__int64 __fastcall bbus_hmap_create(int a1)
{
return create_hashmap(a1, 0x20uLL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return func1(a1, 0x20uLL);
}

original_code:
bbus_hashmap* bbus_hmap_create(enum bbus_hmap_type type)
{
 return create_hashmap(type, 32);
}

canonical_original_code:
struct __bbus_hashmap *bbus_hmap_create(enum bbus_hmap_type type)
{
 return create_hashmap(type, 32);
}

return_type: struct __bbus_hashmap { unsigned long size; unsigned long numstored; struct entry_list { struct map_entry { struct map_entry *next; struct map_entry *prev; void *key; unsigned long ksize; void *val; } *head; struct map_entry *tail; } *buckets; enum bbus_hmap_type { BBUS_HMAP_KEYUINT=1, BBUS_HMAP_KEYSTR=2 } type; } *


decompiled_code:
__int64 __fastcall bbus_hmap_reset(_QWORD *a1)
{
unsigned int v1; // er14
__int64 v2; // r12
__int64 v3; // r12
_QWORD *v4; // rbx
_QWORD *v5; // rbp
__int64 result; // rax

if ( *a1 )
{
v1 = 0;
v2 = 0LL;
do
{
v3 = 16 * v2;
v4 = *(_QWORD **)(a1[2] + v3);
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)*v4;
bbus_free(v5[2]);
bbus_free(v5);
}
*(_QWORD *)(a1[2] + v3) = 0LL;
result = a1[2];
*(_QWORD *)(result + v3 + 8) = 0LL;
v2 = ++v1;
}
while ( (unsigned __int64)v1 < *a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
unsigned int v1; // er14
__int64 v2; // r12
__int64 v3; // r12
_QWORD *v4; // rbx
_QWORD *v5; // rbp
__int64 result; // rax

if ( *a1 )
{
v1 = 0;
v2 = 0LL;
do
{
v3 = 16 * v2;
v4 = *(_QWORD **)(a1[2] + v3);
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)*v4;
bbus_free(v5[2]);
bbus_free(v5);
}
*(_QWORD *)(a1[2] + v3) = 0LL;
result = a1[2];
*(_QWORD *)(result + v3 + 8) = 0LL;
v2 = ++v1;
}
while ( (unsigned __int64)v1 < *a1 );
}
return result;
}

original_code:
void bbus_hmap_reset(bbus_hashmap* hmap)
{
 unsigned i;
 struct map_entry* el;
 struct map_entry* tmpel;
 for (i = 0; i < hmap->size; ++i) {
  el = hmap->buckets[i].head;
  while (el != ((void *)0)) {
   tmpel = el;
   el = el->next;
   bbus_free(tmpel->key);
   bbus_free(tmpel);
  }
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
}

canonical_original_code:
void bbus_hmap_reset(struct __bbus_hashmap *hmap)
{
 unsigned int i;
 struct map_entry *el;
 struct map_entry *tmpel;
 for (i = 0; i < hmap->size; ++i) {
  el = hmap->buckets[i].head;
  while (el != ((void *)0)) {
   tmpel = el;
   el = el->next;
   bbus_free(tmpel->key);
   bbus_free(tmpel);
  }
  hmap->buckets[i].head = ((void *)0);
  hmap->buckets[i].tail = ((void *)0);
 }
}

variable_types: struct map_entry { struct map_entry *next; struct map_entry *prev; void *key; unsigned long ksize; void *val; } *

user_defined_types: enum bbus_hmap_type { BBUS_HMAP_KEYUINT=1, BBUS_HMAP_KEYSTR=2 }


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

if ( a1 )
{
bbus_hmap_reset(a1);
bbus_free(a1[2]);
result = bbus_free(a1);
}
return result;
}

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

if ( a1 )
{
func4(a1);
bbus_free(a1[2]);
result = bbus_free(a1);
}
return result;
}

original_code:
void bbus_hmap_free(bbus_hashmap* hmap)
{
 if (hmap) {
  bbus_hmap_reset(hmap);
  bbus_free(hmap->buckets);
  bbus_free(hmap);
 }
}

canonical_original_code:
void bbus_hmap_free(struct __bbus_hashmap *hmap)
{
 if (hmap) {
  bbus_hmap_reset(hmap);
  bbus_free(hmap->buckets);
  bbus_free(hmap);
 }
}

user_defined_types: struct map_entry { struct map_entry *next; struct map_entry *prev; void *key; unsigned long ksize; void *val; }