decompiled_code:
void __fastcall Create_free(void *ptr)
{
if ( *(_DWORD *)ptr )
Index_free(*((void **)ptr + 1));
else
Table_free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
if ( *(_DWORD *)ptr )
func12(*((void **)ptr + 1));
else
func6(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Create_free(Create_t *cre) {
   if (cre->t == CREATE_TABLE)
      Table_free(cre->table);
   else
      Index_free(cre->index);
   free(cre);
}

canonical_original_code:
void Create_free(struct Create_s *cre) {
   if (cre->t == CREATE_TABLE)
      Table_free(cre->table);
   else
      Index_free(cre->index);
   free(cre);
}

user_defined_types: enum CreateType { CREATE_TABLE=0, CREATE_INDEX=1 }

user_defined_types: struct Column_t { char *name; enum data_type type; struct Constraint_t *constraints; unsigned long offset; struct Column_t *next; }

user_defined_types: enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 }

user_defined_types: enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 }

user_defined_types: struct CondBinary { struct Condition_t *cond1; }

user_defined_types: struct CondUnary { struct Condition_t *cond; }

user_defined_types: struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; }

user_defined_types: enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 }

user_defined_types: struct ExprBinary { struct Expression_s *expr1; }

user_defined_types: struct ExprUnary { struct Expression_s *expr; }

user_defined_types: enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 }


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

result = a1;
*(_QWORD *)(a1 + 40) = a2;
return result;
}

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

result = a1;
*(_QWORD *)(a1 + 40) = a2;
return result;
}

original_code:
static Expression_t *app_exp(Expression_t *e1, Expression_t *e2) {
   e1->next = e2;
   return e1;
}

canonical_original_code:
static struct Expression_s *app_exp(struct Expression_s *e1, struct Expression_s *e2) {
   e1->next = e2;
   return e1;
}

return_type: struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *

user_defined_types: struct Expression_s { enum ExprType t; union { struct ExprTerm term; struct ExprBinary binary; struct ExprUnary unary; } expr; char *alias; struct Expression_s *next; }

user_defined_types: struct ExprTerm { enum TermType t; union { char *id; struct Literal_t *val; struct ColumnReference_t *ref; struct Func f; }; }

user_defined_types: struct Func { enum FuncType t; struct Expression_s *expr; }

user_defined_types: struct Literal_t { enum data_type t; union LitVal val; struct Literal_t *next; }


TermNull

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

result = calloc(1uLL, 0x30uLL);
result[2] = 2;
return result;
}

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

result = calloc(1uLL, 0x30uLL);
result[2] = 2;
return result;
}

original_code:
Expression_t *TermNull(void) {
   Expression_t *new_expr = (Expression_t *)calloc(1, sizeof(Expression_t));
   new_expr->t = EXPR_TERM;
   new_expr->expr.term.t = TERM_NULL;
   return new_expr;
}

canonical_original_code:
struct Expression_s *TermNull() {
   struct Expression_s *new_expr = (Expression_t *)calloc(1, sizeof(Expression_t));
   new_expr->t = EXPR_TERM;
   new_expr->expr.term.t = TERM_NULL;
   return new_expr;
}

variable_types: struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *


decompiled_code:
int __fastcall Expression_print(unsigned int *a1, __int64 a2, int a3, int a4, int a5, int a6)
{
unsigned int *v6; // rbx
int result; // eax
const char *v8; // rsi

v6 = a1;
if ( *a1 )
{
LODWORD(a1) = 40;
putchar(40);
a2 = *v6;
switch ( (int)a2 )
{
case 0:
goto LABEL_2;
case 1:
Expression_print(*((_QWORD *)v6 + 1));
printf(" + ");
result = Expression_print(*((_QWORD *)v6 + 2));
break;
case 2:
Expression_print(*((_QWORD *)v6 + 1));
printf(" - ");
result = Expression_print(*((_QWORD *)v6 + 2));
break;
case 3:
Expression_print(*((_QWORD *)v6 + 1));
printf(" * ");
result = Expression_print(*((_QWORD *)v6 + 2));
break;
case 4:
Expression_print(*((_QWORD *)v6 + 1));
printf(" / ");
result = Expression_print(*((_QWORD *)v6 + 2));
break;
case 5:
Expression_print(*((_QWORD *)v6 + 1));
printf(" || ");
result = Expression_print(*((_QWORD *)v6 + 2));
break;
case 6:
putchar(45);
result = Expression_print(*((_QWORD *)v6 + 1));
break;
default:
result = printf("(Unknown expression type '%d')", a2);
break;
}
}
else
{
LABEL_2:
result = Term_print((_DWORD)a1, a2, a3, a4, a5, a6, *((_QWORD *)v6 + 1), *((_QWORD *)v6 + 2), *((_QWORD *)v6 + 3));
}
if ( *v6 )
result = putchar(41);
v8 = (const char *)*((_QWORD *)v6 + 4);
if ( v8 )
result = printf(" as %s", v8);
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1, __int64 a2, int a3, int a4, int a5, int a6)
{
unsigned int *v6; // rbx
int result; // eax
const char *v8; // rsi

v6 = a1;
if ( *a1 )
{
LODWORD(a1) = 40;
putchar(40);
a2 = *v6;
switch ( (int)a2 )
{
case 0:
goto LABEL_2;
case 1:
func2(*((_QWORD *)v6 + 1));
printf(" + ");
result = func2(*((_QWORD *)v6 + 2));
break;
case 2:
func2(*((_QWORD *)v6 + 1));
printf(" - ");
result = func2(*((_QWORD *)v6 + 2));
break;
case 3:
func2(*((_QWORD *)v6 + 1));
printf(" * ");
result = func2(*((_QWORD *)v6 + 2));
break;
case 4:
func2(*((_QWORD *)v6 + 1));
printf(" / ");
result = func2(*((_QWORD *)v6 + 2));
break;
case 5:
func2(*((_QWORD *)v6 + 1));
printf(" || ");
result = func2(*((_QWORD *)v6 + 2));
break;
case 6:
putchar(45);
result = func2(*((_QWORD *)v6 + 1));
break;
default:
result = printf("(Unknown expression type '%d')", a2);
break;
}
}
else
{
LABEL_2:
result = func4((_DWORD)a1, a2, a3, a4, a5, a6, *((_QWORD *)v6 + 1), *((_QWORD *)v6 + 2), *((_QWORD *)v6 + 3));
}
if ( *v6 )
result = putchar(41);
v8 = (const char *)*((_QWORD *)v6 + 4);
if ( v8 )
result = printf(" as %s", v8);
return result;
}

original_code:
void Expression_print(Expression_t *expr) {
   if (expr->t != EXPR_TERM) printf("(");
   switch (expr->t) {
      case EXPR_CONCAT:
         Expression_print(expr->expr.binary.expr1);
         printf(" || ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_PLUS:
         Expression_print(expr->expr.binary.expr1);
         printf(" + ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_MINUS:
         Expression_print(expr->expr.binary.expr1);
         printf(" - ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_MULTIPLY:
         Expression_print(expr->expr.binary.expr1);
         printf(" * ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_DIVIDE:
         Expression_print(expr->expr.binary.expr1);
         printf(" / ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_NEG:
         printf("-");
         Expression_print(expr->expr.unary.expr);
         break;
      case EXPR_TERM:
         Term_print(expr->expr.term);
         break;
      default:
         printf("(Unknown expression type '%d')", expr->t);
   }
   if (expr->t != EXPR_TERM) printf(")");
   if (expr->alias) printf(" as %s", expr->alias);
}

canonical_original_code:
void Expression_print(struct Expression_s *expr) {
   if (expr->t != EXPR_TERM) printf("(");
   switch (expr->t) {
      case EXPR_CONCAT:
         Expression_print(expr->expr.binary.expr1);
         printf(" || ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_PLUS:
         Expression_print(expr->expr.binary.expr1);
         printf(" + ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_MINUS:
         Expression_print(expr->expr.binary.expr1);
         printf(" - ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_MULTIPLY:
         Expression_print(expr->expr.binary.expr1);
         printf(" * ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_DIVIDE:
         Expression_print(expr->expr.binary.expr1);
         printf(" / ");
         Expression_print(expr->expr.binary.expr2);
         break;
      case EXPR_NEG:
         printf("-");
         Expression_print(expr->expr.unary.expr);
         break;
      case EXPR_TERM:
         Term_print(expr->expr.term);
         break;
      default:
         printf("(Unknown expression type '%d')", expr->t);
   }
   if (expr->t != EXPR_TERM) printf(")");
   if (expr->alias) printf(" as %s", expr->alias);
}

return_type: void

user_defined_types: struct ColumnReference_t { char *tableName; }

user_defined_types: enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 }

user_defined_types: union LitVal { int ival; double dval; char cval; char *strval; }


decompiled_code:
__int64 __fastcall Expression_type(__int64 a1)
{
int v1; // ebp
__int64 result; // rax
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9

if ( !*(_DWORD *)a1 )
return *(unsigned int *)(a1 + 8);
if ( *(_DWORD *)a1 == 6 )
return Expression_type(*(_QWORD *)(a1 + 8));
v1 = Expression_type(*(_QWORD *)(a1 + 8));
result = Expression_type(*(_QWORD *)(a1 + 16));
if ( v1 != (_DWORD)result )
{
fwrite("Type mismatch on binary expression:\n", 1uLL, 0x24uLL, stderr);
Expression_print(*(unsigned int **)(a1 + 8), 1LL, v3, v4, v5, v6);
fwrite("\nis not the same type as\n", 1uLL, 0x19uLL, stderr);
Expression_print(*(unsigned int **)(a1 + 16), 1LL, v7, v8, v9, v10);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebp
__int64 result; // rax
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9

if ( !*(_DWORD *)a1 )
return *(unsigned int *)(a1 + 8);
if ( *(_DWORD *)a1 == 6 )
return func3(*(_QWORD *)(a1 + 8));
v1 = func3(*(_QWORD *)(a1 + 8));
result = func3(*(_QWORD *)(a1 + 16));
if ( v1 != (_DWORD)result )
{
fwrite("Type mismatch on binary expression:\n", 1uLL, 0x24uLL, stderr);
func2(*(unsigned int **)(a1 + 8), 1LL, v3, v4, v5, v6);
fwrite("\nis not the same type as\n", 1uLL, 0x19uLL, stderr);
func2(*(unsigned int **)(a1 + 16), 1LL, v7, v8, v9, v10);
exit(1);
}
return result;
}

original_code:
enum TermType Expression_type(Expression_t *expr) {
   enum TermType t1, t2;
   switch (expr->t) {
      case EXPR_TERM:
         return expr->expr.term.t;
      case EXPR_NEG:
         return Expression_type(expr->expr.unary.expr);
      default:
         t1 = Expression_type(expr->expr.binary.expr1);
         t2 = Expression_type(expr->expr.binary.expr2);
         if (t1 != t2) {
            fprintf(stderr, "Type mismatch on binary expression:\n");
            Expression_print(expr->expr.binary.expr1);
            fprintf(stderr, "\nis not the same type as\n");
            Expression_print(expr->expr.binary.expr2);
            exit(1);
         }
         return t1;
   }
}

canonical_original_code:
enum TermType Expression_type(struct Expression_s *expr) {
   enum TermType t1; enum TermType t2;
   switch (expr->t) {
      case EXPR_TERM:
         return expr->expr.term.t;
      case EXPR_NEG:
         return Expression_type(expr->expr.unary.expr);
      default:
         t1 = Expression_type(expr->expr.binary.expr1);
         t2 = Expression_type(expr->expr.binary.expr2);
         if (t1 != t2) {
            fprintf(stderr, "Type mismatch on binary expression:\n");
            Expression_print(expr->expr.binary.expr1);
            fprintf(stderr, "\nis not the same type as\n");
            Expression_print(expr->expr.binary.expr2);
            exit(1);
         }
         return t1;
   }
}

variable_types: enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 }


decompiled_code:
int __fastcall Term_print(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char **a8, unsigned int *a9)
{
int result; // eax
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9
int v14; // edx
int v15; // ecx
int v16; // er8
int v17; // er9
int v18; // edx
int v19; // ecx
int v20; // er8
int v21; // er9
int v22; // edx
int v23; // ecx
int v24; // er8
int v25; // er9
int v26; // edx
int v27; // ecx
int v28; // er8
int v29; // er9

switch ( a7 )
{
case 0:
result = Literal_print(a8);
break;
case 1:
result = printf("%s", (const char *)a8);
break;
case 2:
result = printf("NULL");
break;
case 3:
if ( *a8 )
printf("%s.", *a8);
result = printf("%s", a8[1]);
break;
case 4:
switch ( (int)a8 )
{
case 0:
printf("MAX(");
Expression_print(a9, a2, v18, v19, v20, v21);
result = putchar(41);
break;
case 1:
printf("MIN(");
Expression_print(a9, a2, v22, v23, v24, v25);
result = putchar(41);
break;
case 2:
printf("COUNT(");
Expression_print(a9, a2, v14, v15, v16, v17);
result = putchar(41);
break;
case 3:
printf("AVG(");
Expression_print(a9, a2, v10, v11, v12, v13);
result = putchar(41);
break;
case 4:
printf("SUM(");
Expression_print(a9, a2, v26, v27, v28, v29);
result = putchar(41);
break;
default:
result = printf("Unknown function");
break;
}
break;
default:
result = printf("Unknown term type");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char **a8, unsigned int *a9)
{
int result; // eax
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9
int v14; // edx
int v15; // ecx
int v16; // er8
int v17; // er9
int v18; // edx
int v19; // ecx
int v20; // er8
int v21; // er9
int v22; // edx
int v23; // ecx
int v24; // er8
int v25; // er9
int v26; // edx
int v27; // ecx
int v28; // er8
int v29; // er9

switch ( a7 )
{
case 0:
result = Literal_print(a8);
break;
case 1:
result = printf("%s", (const char *)a8);
break;
case 2:
result = printf("NULL");
break;
case 3:
if ( *a8 )
printf("%s.", *a8);
result = printf("%s", a8[1]);
break;
case 4:
switch ( (int)a8 )
{
case 0:
printf("MAX(");
func2(a9, a2, v18, v19, v20, v21);
result = putchar(41);
break;
case 1:
printf("MIN(");
func2(a9, a2, v22, v23, v24, v25);
result = putchar(41);
break;
case 2:
printf("COUNT(");
func2(a9, a2, v14, v15, v16, v17);
result = putchar(41);
break;
case 3:
printf("AVG(");
func2(a9, a2, v10, v11, v12, v13);
result = putchar(41);
break;
case 4:
printf("SUM(");
func2(a9, a2, v26, v27, v28, v29);
result = putchar(41);
break;
default:
result = printf("Unknown function");
break;
}
break;
default:
result = printf("Unknown term type");
break;
}
return result;
}

original_code:
static void Term_print(ExprTerm term) {
   switch (term.t) {
      case TERM_ID:
         printf("%s", term.id);
         break;
      case TERM_LITERAL:
         Literal_print(term.val);
         break;
      case TERM_NULL:
         printf("NULL");
         break;
      case TERM_COLREF:
         if (term.ref->tableName)
            printf("%s.", term.ref->tableName);
         printf("%s", term.ref->columnName);
         break;
      case TERM_FUNC:
         switch (term.f.t) {
            case FUNC_AVG:
               printf("AVG(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_COUNT:
               printf("COUNT(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_MAX:
               printf("MAX(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_MIN:
               printf("MIN(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_SUM:
               printf("SUM(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            default:
               printf("Unknown function");
         }
         break;
      default:
         printf("Unknown term type");
   }
}

canonical_original_code:
static void Term_print(struct ExprTerm term) {
   switch (term.t) {
      case TERM_ID:
         printf("%s", term.id);
         break;
      case TERM_LITERAL:
         Literal_print(term.val);
         break;
      case TERM_NULL:
         printf("NULL");
         break;
      case TERM_COLREF:
         if (term.ref->tableName)
            printf("%s.", term.ref->tableName);
         printf("%s", term.ref->columnName);
         break;
      case TERM_FUNC:
         switch (term.f.t) {
            case FUNC_AVG:
               printf("AVG(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_COUNT:
               printf("COUNT(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_MAX:
               printf("MAX(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_MIN:
               printf("MIN(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            case FUNC_SUM:
               printf("SUM(");
               Expression_print(term.f.expr);
               printf(")");
               break;
            default:
               printf("Unknown function");
         }
         break;
      default:
         printf("Unknown term type");
   }
}

variable_types: struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr; } f; }; }


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

result = a2;
if ( a1 )
{
v3 = append_expression(*(_QWORD *)(a1 + 40));
result = app_exp(a1, v3);
}
return result;
}

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

result = a2;
if ( a1 )
{
v3 = func5(*(_QWORD *)(a1 + 40));
result = func0(a1, v3);
}
return result;
}

original_code:
Expression_t *append_expression(Expression_t *e1, Expression_t *e2) {
   if (!e1) return e2;
   return app_exp(e1, append_expression(e1->next, e2));
}

canonical_original_code:
struct Expression_s *append_expression(struct Expression_s *e1, struct Expression_s *e2) {
   if (!e1) return e2;
   return app_exp(e1, append_expression(e1->next, e2));
}


decompiled_code:
int __fastcall Expression_printList(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9

v2 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
Expression_print((unsigned int *)v2, a2, v3, v4, v5, v6);
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
break;
printf(", ");
}
}
return putchar(93);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9

v2 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
func2((unsigned int *)v2, a2, v3, v4, v5, v6);
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
break;
printf(", ");
}
}
return putchar(93);
}

original_code:
void Expression_printList (Expression_t *expr) {
   int first = 1;
   printf("[");
   while (expr) {
      if (first) first = 0; else printf(", ");
      Expression_print(expr);
      expr = expr->next;
   }
   printf("]");
}

canonical_original_code:
void Expression_printList(struct Expression_s *expr) {
   int first = 1;
   printf("[");
   while (expr) {
      if (first) first = 0; else printf(", ");
      Expression_print(expr);
      expr = expr->next;
   }
   printf("]");
}

variable_types: first int


decompiled_code:
__int64 __fastcall add_alias(__int64 a1, const char *a2)
{
if ( a2 )
*(_QWORD *)(a1 + 32) = strdup(a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
if ( a2 )
*(_QWORD *)(a1 + 32) = strdup(a2);
return a1;
}

original_code:
Expression_t *add_alias(Expression_t *expr, const char *alias) {
   if (alias) expr->alias = strdup(alias);
   return expr;
}

canonical_original_code:
struct Expression_s *add_alias(struct Expression_s *expr, char *alias) {
   if (alias) expr->alias = strdup(alias);
   return expr;
}

variable_types:
expr
struct Expression_s *

variable_types:
alias
char *


decompiled_code:
void __fastcall Expression_free(void *ptr, __int64 a2, int a3, int a4, int a5, int a6)
{
__int64 v7; // rsi
void *v8; // rdi

v7 = *(unsigned int *)ptr;
switch ( (int)v7 )
{
case 0:
Term_free((int)ptr, v7, a3, a4, a5, a6, *((_QWORD *)ptr + 1), *((void **)ptr + 2), *((void **)ptr + 3));
break;
case 1:
case 2:
case 3:
case 4:
case 5:
Expression_free(*((void **)ptr + 1));
Expression_free(*((void **)ptr + 2));
break;
case 6:
Expression_free(*((void **)ptr + 1));
break;
default:
printf("Can't delete unknown expression type '%d')", v7);
break;
}
v8 = (void *)*((_QWORD *)ptr + 4);
if ( v8 )
free(v8);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr, __int64 a2, int a3, int a4, int a5, int a6)
{
__int64 v7; // rsi
void *v8; // rdi

v7 = *(unsigned int *)ptr;
switch ( (int)v7 )
{
case 0:
func9((int)ptr, v7, a3, a4, a5, a6, *((_QWORD *)ptr + 1), *((void **)ptr + 2), *((void **)ptr + 3));
break;
case 1:
case 2:
case 3:
case 4:
case 5:
func8(*((void **)ptr + 1));
func8(*((void **)ptr + 2));
break;
case 6:
func8(*((void **)ptr + 1));
break;
default:
printf("Can't delete unknown expression type '%d')", v7);
break;
}
v8 = (void *)*((_QWORD *)ptr + 4);
if ( v8 )
free(v8);
free(ptr);
}

original_code:
void Expression_free(Expression_t *expr) {
   switch (expr->t) {
      case EXPR_CONCAT:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_PLUS:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_MINUS:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_MULTIPLY:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_DIVIDE:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_NEG:
         Expression_free(expr->expr.unary.expr);
         break;
      case EXPR_TERM:
         Term_free(expr->expr.term);
         break;
      default:
         printf("Can't delete unknown expression type '%d')", expr->t);
   }
   if (expr->alias) free(expr->alias);
   free(expr);
}

canonical_original_code:
void Expression_free(struct Expression_s *expr) {
   switch (expr->t) {
      case EXPR_CONCAT:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_PLUS:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_MINUS:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_MULTIPLY:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_DIVIDE:
         Expression_free(expr->expr.binary.expr1);
         Expression_free(expr->expr.binary.expr2);
         break;
      case EXPR_NEG:
         Expression_free(expr->expr.unary.expr);
         break;
      case EXPR_TERM:
         Term_free(expr->expr.term);
         break;
      default:
         printf("Can't delete unknown expression type '%d')", expr->t);
   }
   if (expr->alias) free(expr->alias);
   free(expr);
}


decompiled_code:
void __fastcall Term_free(int a1, __int64 a2, int a3, int a4, int a5, int a6, int a7, void *ptr, void *a9)
{
switch ( a7 )
{
case 0:
Literal_free(ptr);
break;
case 1:
free(ptr);
break;
case 2:
return;
case 3:
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(*((void **)ptr + 1));
break;
case 4:
switch ( (int)ptr )
{
case 0:
case 1:
case 2:
case 3:
case 4:
Expression_free(a9, a2, a3, a4, a5, a6);
break;
default:
puts("Can't delete unknown function");
break;
}
goto LABEL_9;
default:
LABEL_9:
printf("Can't delete, unknown term type");
break;
}
}

canonical_decompiled_code:
void __fastcall func9(int a1, __int64 a2, int a3, int a4, int a5, int a6, int a7, void *ptr, void *a9)
{
switch ( a7 )
{
case 0:
Literal_free(ptr);
break;
case 1:
free(ptr);
break;
case 2:
return;
case 3:
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(*((void **)ptr + 1));
break;
case 4:
switch ( (int)ptr )
{
case 0:
case 1:
case 2:
case 3:
case 4:
func8(a9, a2, a3, a4, a5, a6);
break;
default:
puts("Can't delete unknown function");
break;
}
goto LABEL_9;
default:
LABEL_9:
printf("Can't delete, unknown term type");
break;
}
}

original_code:
static void Term_free(ExprTerm term) {
   switch (term.t) {
      case TERM_ID:
         free(term.id);
         break;
      case TERM_LITERAL:
         Literal_free(term.val);
         break;
      case TERM_NULL:
         break;
      case TERM_COLREF:
         if (term.ref->tableName)
            free(term.ref->tableName);
         free(term.ref->columnName);
         break;
      case TERM_FUNC:
         switch (term.f.t) {
            case FUNC_AVG:
               Expression_free(term.f.expr);
               break;
            case FUNC_COUNT:
               Expression_free(term.f.expr);
               break;
            case FUNC_MAX:
               Expression_free(term.f.expr);
               break;
            case FUNC_MIN:
               Expression_free(term.f.expr);
               break;
            case FUNC_SUM:
               Expression_free(term.f.expr);
               break;
            default:
               printf("Can't delete unknown function\n");
         }
      default:
         printf("Can't delete, unknown term type");
   }
}

canonical_original_code:
static void Term_free(struct ExprTerm term) {
   switch (term.t) {
      case TERM_ID:
         free(term.id);
         break;
      case TERM_LITERAL:
         Literal_free(term.val);
         break;
      case TERM_NULL:
         break;
      case TERM_COLREF:
         if (term.ref->tableName)
            free(term.ref->tableName);
         free(term.ref->columnName);
         break;
      case TERM_FUNC:
         switch (term.f.t) {
            case FUNC_AVG:
               Expression_free(term.f.expr);
               break;
            case FUNC_COUNT:
               Expression_free(term.f.expr);
               break;
            case FUNC_MAX:
               Expression_free(term.f.expr);
               break;
            case FUNC_MIN:
               Expression_free(term.f.expr);
               break;
            case FUNC_SUM:
               Expression_free(term.f.expr);
               break;
            default:
               printf("Can't delete unknown function\n");
         }
      default:
         printf("Can't delete, unknown term type");
   }
}


decompiled_code:
void Expression_freeList()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void Expression_freeList(Expression_t *expr) {
}

canonical_original_code:
void Expression_freeList(struct Expression_s *expr) {
}


decompiled_code:
int __fastcall Insert_print(_QWORD *a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

v1 = a1[2];
printf("Insert ");
putchar(91);
if ( v1 )
{
while ( 1 )
{
Literal_print(v1);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
printf(", ");
}
}
printf("] into ");
RA_print(*a1);
v2 = a1[1];
if ( v2 )
{
printf(" using columns [");
while ( 1 )
{
printf("%s", *(const char **)v2);
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
break;
printf(", ");
}
putchar(93);
}
return puts(&s);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

v1 = a1[2];
printf("Insert ");
putchar(91);
if ( v1 )
{
while ( 1 )
{
Literal_print(v1);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
printf(", ");
}
}
printf("] into ");
RA_print(*a1);
v2 = a1[1];
if ( v2 )
{
printf(" using columns [");
while ( 1 )
{
printf("%s", *(const char **)v2);
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
break;
printf(", ");
}
putchar(93);
}
return puts(&s);
}

original_code:
void Insert_print(Insert_t *insert) {
   Literal_t *val = insert->values;
   int first = 1;
   printf("Insert ");
   printf("[");
   while (val) {
      if (first) {
         first = 0;
      } else {
         printf(", ");
      }
      Literal_print(val);
      val = val->next;
   }
   printf("] into ");
   RA_print(insert->ra);
   if (insert->col_names) {
      StrList_t *list = insert->col_names;
      first = 1;
      printf(" using columns [");
      while (list) {
         if (first) {
            first = 0;
         } else {
            printf(", ");
         }
         printf("%s", list->str);
         list = list->next;
      }
      printf("]");
   }
   puts("");
}

canonical_original_code:
void Insert_print(struct Insert_t *insert) {
   struct Literal_t *val = insert->values;
   int first = 1;
   printf("Insert ");
   printf("[");
   while (val) {
      if (first) {
         first = 0;
      } else {
         printf(", ");
      }
      Literal_print(val);
      val = val->next;
   }
   printf("] into ");
   RA_print(insert->ra);
   if (insert->col_names) {
      struct StrList_t *list = insert->col_names;
      first = 1;
      printf(" using columns [");
      while (list) {
         if (first) {
            first = 0;
         } else {
            printf(", ");
         }
         printf("%s", list->str);
         list = list->next;
      }
      printf("]");
   }
   puts("");
}

variable_types: struct Insert_t { struct RA_s { enum RA_Type { RA_TABLE=0, RA_SIGMA=1, RA_PI=2, RA_UNION=3, RA_DIFFERENCE=4, RA_CROSS=5, RA_RHO_TABLE=6, RA_RHO_EXPR=7 } t; union { struct { char *name; } table; struct { struct RA_s *ra; struct Condition_t { enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 } t; union { struct CondComp { struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr1; } comp; struct CondBinary { struct Condition_t *cond1; } binary; struct CondUnary { struct Condition_t *cond; } unary; struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; } in; } cond; } *cond; } sigma; struct { struct RA_s *ra; struct Expression_s *expr_list; } pi; struct { struct RA_s *ra1; } binary; struct { struct RA_s *ra; struct Expression_s *to_rename; char *new_name; } rho; }; struct List_s { unsigned long size; struct ListNode_s { void *data; struct ListNode_s *next; } *front; void (*del)(void *); 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; char *(*toString)(void *); int (*compare)(void *, void *); void (*print)(void *); void *(*copy)(void *); unsigned long elem_size; char *name; } columns; } *ra; struct StrList_t { char *str; struct StrList_t *next; } *col_names; struct Literal_t *values; } *

user_defined_types: struct Insert_t { struct RA_s *ra; struct StrList_t *col_names; struct Literal_t *values; }

user_defined_types: struct RA_s { enum RA_Type t; union { struct { char *name; } table; struct { struct RA_s *ra; struct Condition_t *cond; } sigma; struct { struct RA_s *ra; struct Expression_s *expr_list; } pi; struct { struct RA_s *ra1; } binary; struct { struct RA_s *ra; struct Expression_s *to_rename; char *new_name; } rho; }; struct List_s columns; }

user_defined_types: struct List_s { unsigned long size; struct ListNode_s *front; void (*del)(void *); union pthread_mutex_t lock; char *(*toString)(void *); int (*compare)(void *, void *); void (*print)(void *); void *(*copy)(void *); unsigned long elem_size; char *name; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; 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; }

user_defined_types: struct Condition_t { enum CondType t; union { struct CondComp comp; struct CondBinary binary; struct CondUnary unary; struct CondIn in; } cond; }

user_defined_types: struct CondComp { struct Expression_s *expr1; }


decompiled_code:
void __fastcall Insert_free(void *ptr)
{
if ( ptr )
{
RA_free(*(_QWORD *)ptr);
StrList_free(*((_QWORD *)ptr + 1));
Literal_free(*((_QWORD *)ptr + 2));
free(ptr);
}
else
{
fwrite("Warning: Insert_free called on null pointer\n", 1uLL, 0x2CuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
RA_free(*(_QWORD *)ptr);
StrList_free(*((_QWORD *)ptr + 1));
Literal_free(*((_QWORD *)ptr + 2));
free(ptr);
}
else
{
fwrite("Warning: Insert_free called on null pointer\n", 1uLL, 0x2CuLL, stderr);
}
}

original_code:
void Insert_free(Insert_t *insert) {
   if (!insert) {
      fprintf(stderr, "Warning: Insert_free called on null pointer\n");
      return;
   }
   RA_free(insert->ra);
   StrList_free(insert->col_names);
   Literal_free(insert->values);
   free(insert);
}

canonical_original_code:
void Insert_free(struct Insert_t *insert) {
   if (!insert) {
      fprintf(stderr, "Warning: Insert_free called on null pointer\n");
      return;
   }
   RA_free(insert->ra);
   StrList_free(insert->col_names);
   Literal_free(insert->values);
   free(insert);
}

user_defined_types: struct StrList_t { char *str; struct StrList_t *next; }

user_defined_types: enum RA_Type { RA_TABLE=0, RA_SIGMA=1, RA_PI=2, RA_UNION=3, RA_DIFFERENCE=4, RA_CROSS=5, RA_RHO_TABLE=6, RA_RHO_EXPR=7 }

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

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

user_defined_types: enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 }

user_defined_types: struct CondBinary { struct Condition_t *cond1; }

user_defined_types: struct CondUnary { struct Condition_t *cond; }

user_defined_types: struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; }

user_defined_types: enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 }

user_defined_types: struct ExprBinary { struct Expression_s *expr1; }

user_defined_types: enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 }


deleteDelete

decompiled_code:
void __fastcall deleteDelete(void *ptr)
{
Condition_free(*((_QWORD *)ptr + 1));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
Condition_free(*((_QWORD *)ptr + 1));
free(*(void **)ptr);
free(ptr);
}

original_code:
void deleteDelete(Delete_t *del) {
   Condition_free(del->where);
   free(del->table_name);
   free(del);
}

canonical_original_code:
void deleteDelete(struct Delete_t *del) {
   Condition_free(del->where);
   free(del->table_name);
   free(del);
}

variable_types: struct Delete_t { char *table_name; struct Condition_t { enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 } t; union { struct CondComp { struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr1; } comp; struct CondBinary { struct Condition_t *cond1; } binary; struct CondUnary { struct Condition_t *cond; } unary; struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; } in; } cond; } *where; } *

user_defined_types: struct Delete_t { char *table_name; struct Condition_t *where; }

user_defined_types: struct Expression_s { enum ExprType t; union { struct ExprTerm term; struct ExprBinary binary; struct ExprUnary unary; } expr; char *alias; struct Expression_s *next; }

user_defined_types: struct ExprTerm { enum TermType t; union { char *id; struct Literal_t *val; struct ColumnReference_t *ref; struct Func f; }; }

user_defined_types: struct Func { enum FuncType t; struct Expression_s *expr; }

user_defined_types: struct Literal_t { enum data_type t; union LitVal val; struct Literal_t *next; }


decompiled_code:
int __fastcall Delete_print(__int64 a1)
{
printf("Delete from %s where ", *(const char **)a1);
Condition_print(*(_QWORD *)(a1 + 8));
return puts(&s);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
printf("Delete from %s where ", *(const char **)a1);
Condition_print(*(_QWORD *)(a1 + 8));
return puts(&s);
}

original_code:
void Delete_print(Delete_t *del) {
   printf("Delete from %s where ", del->table_name);
   Condition_print(del->where);
   puts("");
}

canonical_original_code:
void Delete_print(struct Delete_t *del) {
   printf("Delete from %s where ", del->table_name);
   Condition_print(del->where);
   puts("");
}

user_defined_types: struct Condition_t { enum CondType t; union { struct CondComp comp; struct CondBinary binary; struct CondUnary unary; struct CondIn in; } cond; }

user_defined_types: struct CondComp { struct Expression_s *expr1; }

user_defined_types: struct ExprUnary { struct Expression_s *expr; }

user_defined_types: enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 }

user_defined_types: struct ColumnReference_t { char *tableName; }

user_defined_types: enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 }

user_defined_types: union LitVal { int ival; double dval; char cval; char *strval; }


decompiled_code:
void __fastcall Delete_free(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
free(*(void **)ptr);
v2 = *((_QWORD *)ptr + 1);
if ( v2 )
Condition_free(v2);
free(ptr);
}
else
{
fwrite("Warning: Delete_free called on null pointer\n", 1uLL, 0x2CuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
free(*(void **)ptr);
v2 = *((_QWORD *)ptr + 1);
if ( v2 )
Condition_free(v2);
free(ptr);
}
else
{
fwrite("Warning: Delete_free called on null pointer\n", 1uLL, 0x2CuLL, stderr);
}
}

original_code:
void Delete_free(Delete_t *del) {
   if (!del) {
      fprintf(stderr, "Warning: Delete_free called on null pointer\n");
      return;
   }
   free(del->table_name);
   if (del->where)
      Condition_free(del->where);
   free(del);
}

canonical_original_code:
void Delete_free(struct Delete_t *del) {
   if (!del) {
      fprintf(stderr, "Warning: Delete_free called on null pointer\n");
      return;
   }
   free(del->table_name);
   if (del->where)
      Condition_free(del->where);
   free(del);
}

user_defined_types: enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 }

user_defined_types: struct CondBinary { struct Condition_t *cond1; }

user_defined_types: struct CondUnary { struct Condition_t *cond; }


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

if ( a1 )
{
switch ( *(_DWORD *)a1 )
{
case 0:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" = ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 1:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" < ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 2:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" > ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 3:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" <= ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 4:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" >= ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 5:
Condition_print(*(_QWORD *)(a1 + 8));
printf(" and ");
Condition_print(*(_QWORD *)(a1 + 16));
break;
case 6:
Condition_print(*(_QWORD *)(a1 + 8));
printf(" or ");
Condition_print(*(_QWORD *)(a1 + 16));
break;
case 7:
v1 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)v1 )
{
printf("not (");
Condition_print(*(_QWORD *)(a1 + 8));
putchar(41);
}
else
{
Expression_print(*(_QWORD *)(v1 + 8));
printf(" != ");
Expression_print(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL));
}
break;
case 8:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" in ");
Literal_printList(*(_QWORD *)(a1 + 16));
break;
default:
puts("Unknown condession type");
break;
}
}
}

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

if ( a1 )
{
switch ( *(_DWORD *)a1 )
{
case 0:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" = ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 1:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" < ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 2:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" > ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 3:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" <= ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 4:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" >= ");
Expression_print(*(_QWORD *)(a1 + 16));
break;
case 5:
func0(*(_QWORD *)(a1 + 8));
printf(" and ");
func0(*(_QWORD *)(a1 + 16));
break;
case 6:
func0(*(_QWORD *)(a1 + 8));
printf(" or ");
func0(*(_QWORD *)(a1 + 16));
break;
case 7:
v1 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)v1 )
{
printf("not (");
func0(*(_QWORD *)(a1 + 8));
putchar(41);
}
else
{
Expression_print(*(_QWORD *)(v1 + 8));
printf(" != ");
Expression_print(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL));
}
break;
case 8:
Expression_print(*(_QWORD *)(a1 + 8));
printf(" in ");
Literal_printList(*(_QWORD *)(a1 + 16));
break;
default:
puts("Unknown condession type");
break;
}
}
}

original_code:
void Condition_print(Condition_t *cond) {
   if (!cond) return;
   switch(cond->t) {
      case RA_COND_EQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" = ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LT:
         Expression_print(cond->cond.comp.expr1);
         printf(" < ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GT:
         Expression_print(cond->cond.comp.expr1);
         printf(" > ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" <= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" >= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
         Condition_print(cond->cond.binary.cond1);
         printf(" and ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_OR:
         Condition_print(cond->cond.binary.cond1);
         printf(" or ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         if (cond->cond.unary.cond->t == RA_COND_EQ) {
            Expression_print(cond->cond.unary.cond->cond.comp.expr1);
            printf(" != ");
            Expression_print(cond->cond.unary.cond->cond.comp.expr2);
         } else {
            printf("not (");
            Condition_print(cond->cond.unary.cond);
            printf(")");
         }
         break;
      case RA_COND_IN:
         Expression_print(cond->cond.in.expr);
         printf(" in ");
         Literal_printList(cond->cond.in.values_list);
         break;
      default:
         puts("Unknown condession type");
   }
}

canonical_original_code:
void Condition_print(struct Condition_t *cond) {
   if (!cond) return;
   switch(cond->t) {
      case RA_COND_EQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" = ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LT:
         Expression_print(cond->cond.comp.expr1);
         printf(" < ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GT:
         Expression_print(cond->cond.comp.expr1);
         printf(" > ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" <= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" >= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
         Condition_print(cond->cond.binary.cond1);
         printf(" and ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_OR:
         Condition_print(cond->cond.binary.cond1);
         printf(" or ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         if (cond->cond.unary.cond->t == RA_COND_EQ) {
            Expression_print(cond->cond.unary.cond->cond.comp.expr1);
            printf(" != ");
            Expression_print(cond->cond.unary.cond->cond.comp.expr2);
         } else {
            printf("not (");
            Condition_print(cond->cond.unary.cond);
            printf(")");
         }
         break;
      case RA_COND_IN:
         Expression_print(cond->cond.in.expr);
         printf(" in ");
         Literal_printList(cond->cond.in.values_list);
         break;
      default:
         puts("Unknown condession type");
   }
}

variable_types: struct Condition_t { enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 } t; union { struct CondComp { struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr1; } comp; struct CondBinary { struct Condition_t *cond1; } binary; struct CondUnary { struct Condition_t *cond; } unary; struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; } in; } cond; } *


decompiled_code:
void __fastcall Condition_free(void *ptr)
{
unsigned int v1; // eax

v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 7 )
{
Condition_free(*((void **)ptr + 1));
}
else if ( v1 > 7 )
{
if ( v1 == 8 )
{
Literal_freeList(*((_QWORD *)ptr + 2));
Expression_freeList(*((_QWORD *)ptr + 1));
}
}
else if ( v1 <= 4 )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
}
else
{
Condition_free(*((void **)ptr + 1));
Condition_free(*((void **)ptr + 2));
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
unsigned int v1; // eax

v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 7 )
{
func1(*((void **)ptr + 1));
}
else if ( v1 > 7 )
{
if ( v1 == 8 )
{
Literal_freeList(*((_QWORD *)ptr + 2));
Expression_freeList(*((_QWORD *)ptr + 1));
}
}
else if ( v1 <= 4 )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
}
else
{
func1(*((void **)ptr + 1));
func1(*((void **)ptr + 2));
}
free(ptr);
}

original_code:
void Condition_free(Condition_t *cond) {
   switch (cond->t) {
      case RA_COND_EQ:
      case RA_COND_LEQ:
      case RA_COND_GEQ:
      case RA_COND_GT:
      case RA_COND_LT:
         free(cond->cond.comp.expr1);
         free(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
      case RA_COND_OR:
         Condition_free(cond->cond.binary.cond1);
         Condition_free(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         Condition_free(cond->cond.unary.cond);
         break;
      case RA_COND_IN:
         Literal_freeList(cond->cond.in.values_list);
         Expression_freeList(cond->cond.in.expr);
         break;
   }
   free(cond);
}

canonical_original_code:
void Condition_free(struct Condition_t *cond) {
   switch (cond->t) {
      case RA_COND_EQ:
      case RA_COND_LEQ:
      case RA_COND_GEQ:
      case RA_COND_GT:
      case RA_COND_LT:
         free(cond->cond.comp.expr1);
         free(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
      case RA_COND_OR:
         Condition_free(cond->cond.binary.cond1);
         Condition_free(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         Condition_free(cond->cond.unary.cond);
         break;
      case RA_COND_IN:
         Literal_freeList(cond->cond.in.values_list);
         Expression_freeList(cond->cond.in.expr);
         break;
   }
   free(cond);
}

user_defined_types: struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; }

user_defined_types: enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 }

user_defined_types: struct ExprBinary { struct Expression_s *expr1; }


repo: thlorenz/cre-downloader

decompiled_code:
__int64 __fastcall name_from_url(const char *a1)
{
signed int v1; // eax
__int64 v3[1025]; // [rsp+0h] [rbp-2008h] BYREF

v1 = (unsigned int)strdup(a1);
return v3[(int)(strsplit(v1, v3, &unk_1B1) - 1)];
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
signed int v1; // eax
__int64 v3[1025]; // [rsp+0h] [rbp-2008h] BYREF

v1 = (unsigned int)strdup(a1);
return v3[(int)(strsplit(v1, v3, &unk_1B1) - 1)];
}

original_code:
char* name_from_url(char* url) {
  char* parts[1024];
  char *s = strdup(url);
  int len = strsplit(s, parts, "/");
  return parts[len -1];
}

canonical_original_code:
char *name_from_url(char *url) {
  char *parts[1024];
  char *s = strdup(url);
  int len = strsplit(s, parts, "/");
  return parts[len -1];
}

variable_types:
url
char *

variable_types:
parts
char *[1024]

variable_types:
s
char *

variable_types: len int

return_type: char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
int v5; // eax
char *v6; // rbx
char *v7; // rbp
__int64 v9[4]; // [rsp+0h] [rbp-2048h] BYREF
char v10[8232]; // [rsp+20h] [rbp-2028h] BYREF

v3 = 1;
if ( argc > 1 )
v3 = strtol(argv[1], 0LL, 10);
v4 = 0x7FFFFFFF;
if ( argc > 2 )
v4 = strtol(argv[2], 0LL, 10);
download_url_buffer(v9, "http://cre.fm/archiv", envp);
v5 = get_links(v9[0], v10);
if ( v4 > v5 )
v4 = v5 + 1;
printf("Downloading episodes %d-%d\n", (unsigned int)v3, (unsigned int)v4);
if ( v3 < v4 )
{
v6 = &v10[8 * v3];
v7 = &v10[8 * v3 + 8 + 8 * (unsigned __int64)(unsigned int)(~v3 + v4)];
do
{
download_episode(*((const char **)v6 - 1));
v6 += 8;
}
while ( v6 != v7 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
int v5; // eax
char *v6; // rbx
char *v7; // rbp
__int64 v9[4]; // [rsp+0h] [rbp-2048h] BYREF
char v10[8232]; // [rsp+20h] [rbp-2028h] BYREF

v3 = 1;
if ( argc > 1 )
v3 = strtol(argv[1], 0LL, 10);
v4 = 0x7FFFFFFF;
if ( argc > 2 )
v4 = strtol(argv[2], 0LL, 10);
download_url_buffer(v9, "http://cre.fm/archiv", envp);
v5 = get_links(v9[0], v10);
if ( v4 > v5 )
v4 = v5 + 1;
printf("Downloading episodes %d-%d\n", (unsigned int)v3, (unsigned int)v4);
if ( v3 < v4 )
{
v6 = &v10[8 * v3];
v7 = &v10[8 * v3 + 8 + 8 * (unsigned __int64)(unsigned int)(~v3 + v4)];
do
{
func1(*((const char **)v6 - 1));
v6 += 8;
}
while ( v6 != v7 );
}
return 0;
}

original_code:
int main(int argc, const char *argv[]) {
  char *links[1024];
  int from_episode = 1;
  int to_episode = 0x7fffffff;
  if (argc > 1) from_episode = strtol(argv[1], ((void *)0), 10);
  if (argc > 2) to_episode = strtol(argv[2], ((void *)0), 10);
  DownloadResult res = download_url_buffer("http://cre.fm/archiv");
  int len = get_links(res.html, links);
  to_episode = (((to_episode)<(len + 1))?(to_episode):(len + 1));
  printf("Downloading episodes %d-%d\n", from_episode, to_episode);
  from_episode--;
  to_episode--;
  for (int i = from_episode; i < to_episode; i++) {
    download_episode(links[i]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char *links[1024];
  int from_episode = 1;
  int to_episode = 0x7fffffff;
  if (argc > 1) from_episode = strtol(argv[1], ((void *)0), 10);
  if (argc > 2) to_episode = strtol(argv[2], ((void *)0), 10);
  struct DownloadResult res = download_url_buffer("http://cre.fm/archiv");
  int len = get_links(res.html, links);
  to_episode = (((to_episode)<(len + 1))?(to_episode):(len + 1));
  printf("Downloading episodes %d-%d\n", from_episode, to_episode);
  from_episode--;
  to_episode--;
  for (int i = from_episode; i < to_episode; i++) {
    download_episode(links[i]);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
links
char *[1024]

variable_types: struct DownloadResult { char *html; unsigned long size; long status; }

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall get_episode(char *a1)
{
char v1; // bl
char *v2; // rbp
const unsigned __int16 *v3; // rsi
__int64 result; // rax
int v5; // edx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = *_ctype_b_loc();
LODWORD(result) = 0;
v5 = 0;
do
{
if ( (v3[v1] & 0x800) != 0 )
{
++v5;
result = (unsigned int)(v1 + 10 * result - 48);
if ( v5 == 3 )
return result;
}
else
{
LODWORD(result) = 0;
v5 = 0;
}
v1 = *v2++;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // bl
char *v2; // rbp
const unsigned __int16 *v3; // rsi
__int64 result; // rax
int v5; // edx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = *_ctype_b_loc();
LODWORD(result) = 0;
v5 = 0;
do
{
if ( (v3[v1] & 0x800) != 0 )
{
++v5;
result = (unsigned int)(v1 + 10 * result - 48);
if ( v5 == 3 )
return result;
}
else
{
LODWORD(result) = 0;
v5 = 0;
}
v1 = *v2++;
}
while ( v1 );
return 0LL;
}

original_code:
static int get_episode(const char* s) {
  char c;
  int count = 0;
  int episode = 0;
  while((c = *(s++)) != '\0') {
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
      count++;
      episode = episode * 10 + (c - '0');
    } else {
      episode = count = 0;
    }
    if (count == 3) return episode;
  }
  return 0;
}

canonical_original_code:
static int get_episode(char *s) {
  char c;
  int count = 0;
  int episode = 0;
  while((c = *(s++)) != '\0') {
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
      count++;
      episode = episode * 10 + (c - '0');
    } else {
      episode = count = 0;
    }
    if (count == 3) return episode;
  }
  return 0;
}

variable_types: c char

variable_types: count int

variable_types: episode int


decompiled_code:
__int64 __fastcall compare_links(char **a1, char **a2)
{
int v2; // ebx

v2 = get_episode(*a1);
return v2 - (unsigned int)get_episode(*a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(char **a1, char **a2)
{
int v2; // ebx

v2 = func0(*a1);
return v2 - (unsigned int)func0(*a2);
}

original_code:
int compare_links(const void* a, const void* b) {
  const char **ia = (const char **)a;
  const char **ib = (const char **)b;
  int ep1 = get_episode(*ia);
  int ep2 = get_episode(*ib);
  return ep1 - ep2;
}

canonical_original_code:
int compare_links(void *a, void *b) {
  char **ia = (const char **)a;
  char **ib = (const char **)b;
  int ep1 = get_episode(*ia);
  int ep2 = get_episode(*ib);
  return ep1 - ep2;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
ia
char **

variable_types:
ib
char **


decompiled_code:
size_t __fastcall write_chunk_to_memory(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
char *v6; // rax
size_t v7; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_QWORD *)(a4 + 8) + v5;
*(_QWORD *)(a4 + 8) = v7;
*(_BYTE *)(*(_QWORD *)a4 + v7) = 0;
}
else
{
puts("not enough memory (realloc returned NULL)");
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
size_t __fastcall func0(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
char *v6; // rax
size_t v7; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_QWORD *)(a4 + 8) + v5;
*(_QWORD *)(a4 + 8) = v7;
*(_BYTE *)(*(_QWORD *)a4 + v7) = 0;
}
else
{
puts("not enough memory (realloc returned NULL)");
v5 = 0LL;
}
return v5;
}

original_code:
static size_t write_chunk_to_memory(void *contents, size_t size, size_t nmemb, void *userp) {
  size_t realsize = size * nmemb;
  MemoryStruct *mem = (MemoryStruct *)userp;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if(mem->memory == ((void *)0)) {
    printf("not enough memory (realloc returned NULL)\n");
    return 0;
  }
  memcpy(&(mem->memory[mem->size]), contents, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;
  return realsize;
}

canonical_original_code:
static unsigned long write_chunk_to_memory(void *contents, unsigned long size, unsigned long nmemb, void *userp) {
  unsigned long realsize = size * nmemb;
  struct MemoryStruct *mem = (MemoryStruct *)userp;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if(mem->memory == ((void *)0)) {
    printf("not enough memory (realloc returned NULL)\n");
    return 0;
  }
  memcpy(&(mem->memory[mem->size]), contents, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;
  return realsize;
}

variable_types:
contents
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userp
void *

variable_types:
realsize
unsigned long

variable_types: struct MemoryStruct { char *memory; unsigned long size; } *

return_type: unsigned long


strsplit

decompiled_code:
__int64 __fastcall strsplit(char *a1, _QWORD *a2, const char *a3)
{
char *v4; // rbx
__int64 i; // rbx
unsigned int v6; // er13
char *v7; // rdi

v4 = strtok(a1, a3);
*a2 = (int)strdup(v4);
if ( !v4 )
return 1;
for ( i = 1LL; ; ++i )
{
v6 = i;
v7 = strtok(0LL, a3);
if ( !v7 )
break;
a2[i] = (int)strdup(v7);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _QWORD *a2, const char *a3)
{
char *v4; // rbx
__int64 i; // rbx
unsigned int v6; // er13
char *v7; // rdi

v4 = strtok(a1, a3);
*a2 = (int)strdup(v4);
if ( !v4 )
return 1;
for ( i = 1LL; ; ++i )
{
v6 = i;
v7 = strtok(0LL, a3);
if ( !v7 )
break;
a2[i] = (int)strdup(v7);
}
return v6;
}

original_code:
int strsplit (char *str, char *parts[], char *delimiter) {
  char *pch;
  int i = 0;
  pch = strtok(str, delimiter);
  parts[i++] = strdup(pch);
  while (pch) {
    pch = strtok(((void *)0), delimiter);
    if (((void *)0) == pch) break;
    parts[i++] = strdup(pch);
  }
  free(pch);
  return i;
}

canonical_original_code:
int strsplit(char *str, char *parts[], char *delimiter) {
  char *pch;
  int i = 0;
  pch = strtok(str, delimiter);
  parts[i++] = strdup(pch);
  while (pch) {
    pch = strtok(((void *)0), delimiter);
    if (((void *)0) == pch) break;
    parts[i++] = strdup(pch);
  }
  free(pch);
  return i;
}

variable_types:
str
char *

variable_types:
parts
char *[]

variable_types:
delimiter
char *

variable_types:
pch
char *


isJobNull

repo: thomascampbelladams/dash

decompiled_code:
_BOOL8 __fastcall isJobNull(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return a1 == 0;
}

original_code: int isJobNull(JobPtr job){ return job == ((void *)0); }

canonical_original_code: int isJobNull(struct job *job){ return job == ((void *)0); }

variable_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *


isJobRunning

decompiled_code:
_BOOL8 __fastcall isJobRunning(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 1;
}

original_code: int isJobRunning(JobPtr job){ return job->running == 1;}

canonical_original_code: int isJobRunning(struct job *job){ return job->running == 1;}

user_defined_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; }


isJobStopped

decompiled_code:
_BOOL8 __fastcall isJobStopped(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 2;
}

original_code: int isJobStopped(JobPtr job){ return job->running == 2; }

canonical_original_code: int isJobStopped(struct job *job){ return job->running == 2; }


isJobInBackground

decompiled_code:
_BOOL8 __fastcall isJobInBackground(__int64 a1)
{
return *(_DWORD *)(a1 + 24) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 24) == 1;
}

original_code: int isJobInBackground(JobPtr job) { return job->background == 1; }

canonical_original_code: int isJobInBackground(struct job *job) { return job->background == 1; }


isJobDone

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

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

original_code: int isJobDone(JobPtr job) { return job->running == 0; }

canonical_original_code: int isJobDone(struct job *job) { return job->running == 0; }


getStatusString

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

result = "Running";
if ( a1 != 1 )
{
result = "Stopped";
if ( a1 != 2 )
{
result = "Invalid";
if ( !a1 )
result = "Done ";
}
}
return result;
}

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

result = "Running";
if ( a1 != 1 )
{
result = "Stopped";
if ( a1 != 2 )
{
result = "Invalid";
if ( !a1 )
result = "Done ";
}
}
return result;
}

original_code:
char *getStatusString(int status){
 char *running;
 switch(status){
         case 0:
   running = "Done   ";
   break;
  case 1:
          running = "Running";
          break;
  case 2:
          running = "Stopped";
          break;
  default:
          running = "Invalid";
          break;
 }
 return running;
}

variable_types: status int

variable_types:
running
char *


toString

decompiled_code:
char *__fastcall toString(__int64 a1)
{
const char *v1; // r12
size_t v2; // rax
char *v3; // rbp

v1 = getStatusString(*(_DWORD *)(a1 + 20));
v2 = strlen(*(const char **)(a1 + 8));
v3 = (char *)buddy_malloc(v2 + 25);
sprintf(v3, "[%i] %s %s\n", *(unsigned int *)(a1 + 4), v1, *(const char **)(a1 + 8));
return v3;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
const char *v1; // r12
size_t v2; // rax
char *v3; // rbp

v1 = func6(*(_DWORD *)(a1 + 20));
v2 = strlen(*(const char **)(a1 + 8));
v3 = (char *)buddy_malloc(v2 + 25);
sprintf(v3, "[%i] %s %s\n", *(unsigned int *)(a1 + 4), v1, *(const char **)(a1 + 8));
return v3;
}

original_code:
char *toString(JobPtr node)
{
 char *temp;
 char *running;
 running = getStatusString(node->running);
 temp = (char *)buddy_malloc(sizeof(char)*strlen(node->command)+1+20 +4);
 sprintf(temp, "[%i] %s %s\n", node->jobNu, running, node->command);
 return temp;
}

canonical_original_code:
char *toString(struct job *node)
{
 char *temp;
 char *running;
 running = getStatusString(node->running);
 temp = (char *)buddy_malloc(sizeof(char)*strlen(node->command)+1+20 +4);
 sprintf(temp, "[%i] %s %s\n", node->jobNu, running, node->command);
 return temp;
}

variable_types:
temp
char *


freeJob

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

if ( a1 )
{
buddy_free(*(_QWORD *)(a1 + 8));
result = buddy_free(a1);
}
return result;
}

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

if ( a1 )
{
buddy_free(*(_QWORD *)(a1 + 8));
result = buddy_free(a1);
}
return result;
}

original_code:
void freeJob(JobPtr job)
{
 if (job == ((void *)0)) return;
 buddy_free(job->command);
 buddy_free(job);
}

canonical_original_code:
void freeJob(struct job *job)
{
 if (job == ((void *)0)) return;
 buddy_free(job->command);
 buddy_free(job);
}


freeArguments

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

if ( a1 > 0 )
{
v4 = a2;
do
result = buddy_free(*v4++);
while ( v4 != &a2[(unsigned int)(a1 - 1) + 1] );
}
if ( a3 )
result = buddy_free(a3);
return result;
}

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

if ( a1 > 0 )
{
v4 = a2;
do
result = buddy_free(*v4++);
while ( v4 != &a2[(unsigned int)(a1 - 1) + 1] );
}
if ( a3 )
result = buddy_free(a3);
return result;
}

original_code:
void freeArguments(int count, char** args, char* bufCopy){
    int i;
    for(i=0; i< count; i++){
    buddy_free(args[i]);
    }
    if(bufCopy != ((void *)0)) buddy_free(bufCopy);
}

canonical_original_code:
void freeArguments(int count, char **args, char *bufCopy){
    int i;
    for(i=0; i< count; i++){
    buddy_free(args[i]);
    }
    if(bufCopy != ((void *)0)) buddy_free(bufCopy);
}

variable_types: count int

variable_types:
args
char **

variable_types:
bufCopy
char *

variable_types: i int


changeDir

decompiled_code:
int __fastcall changeDir(__int64 a1)
{
const char *v2; // rdi
int result; // eax
__uid_t v4; // eax
char *v5; // rbx

v2 = *(const char **)(a1 + 8);
if ( v2 )
{
result = chdir(v2);
if ( result < 0 )
result = err_ret("couldn't change to directory: %s", *(const char **)(a1 + 8));
}
else
{
v4 = getuid();
v5 = getpwuid(v4)->pw_dir;
result = chdir(v5);
if ( result < 0 )
result = err_ret("couldn't change to home directory: %s", v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
const char *v2; // rdi
int result; // eax
__uid_t v4; // eax
char *v5; // rbx

v2 = *(const char **)(a1 + 8);
if ( v2 )
{
result = chdir(v2);
if ( result < 0 )
result = err_ret("couldn't change to directory: %s", *(const char **)(a1 + 8));
}
else
{
v4 = getuid();
v5 = getpwuid(v4)->pw_dir;
result = chdir(v5);
if ( result < 0 )
result = err_ret("couldn't change to home directory: %s", v5);
}
return result;
}

original_code:
void changeDir(char** arguments)
{
 if(arguments[1] == ((void *)0))
 {
  struct passwd * userData = getpwuid(getuid());
  char * path = userData->pw_dir;
  if(chdir(path) < 0)
  {
   err_ret("couldn't change to home directory: %s", path);
  }
 }
 else
 {
  if(chdir(arguments[1]) < 0)
  {
   err_ret("couldn't change to directory: %s", arguments[1]);
  }
 }
}

canonical_original_code:
void changeDir(char **arguments)
{
 if(arguments[1] == ((void *)0))
 {
  struct passwd *userData = getpwuid(getuid());
  char *path = userData->pw_dir;
  if(chdir(path) < 0)
  {
   err_ret("couldn't change to home directory: %s", path);
  }
 }
 else
 {
  if(chdir(arguments[1]) < 0)
  {
   err_ret("couldn't change to directory: %s", arguments[1]);
  }
 }
}

variable_types:
arguments
char **

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
path
char *


fg

decompiled_code:
__int64 __fastcall fg(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er14
_QWORD *v9; // rbx
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnJobNu(a2, v8);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInForeground(v9, a2);
}
}
else
{
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnRunning(a2, 1LL);
if ( (unsigned int)isNodeNull(v9) )
{
v9 = (_QWORD *)searchOnRunning(a2, 2LL);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInForeground(v9, a2);
}
}
else
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInForeground(v9, a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er14
_QWORD *v9; // rbx
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnJobNu(a2, v8);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInForeground(v9, a2);
}
}
else
{
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnRunning(a2, 1LL);
if ( (unsigned int)isNodeNull(v9) )
{
v9 = (_QWORD *)searchOnRunning(a2, 2LL);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInForeground(v9, a2);
}
}
else
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInForeground(v9, a2);
}
}
return result;
}

original_code:
void fg(char** arguments, ListPtr l, int count, char* bufCopy)
{
 int isArgumentNull = arguments[1] == ((void *)0);
 if(isArgumentNull)
 {
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnRunning(l, 1);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
  else{
   NodePtr n = searchOnRunning(l, 2);
   if(!isNodeNull(n))
   {
    JobPtr j = n->data;
    if(!isJobNull(j)) continueJobInForeground(n, l);
   }
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
 }
}

canonical_original_code:
void fg(char **arguments, struct list *l, int count, char *bufCopy)
{
 int isArgumentNull = arguments[1] == ((void *)0);
 if(isArgumentNull)
 {
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnRunning(l, 1);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
  else{
   struct node *n = searchOnRunning(l, 2);
   if(!isNodeNull(n))
   {
    struct job *j = n->data;
    if(!isJobNull(j)) continueJobInForeground(n, l);
   }
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
 }
}

variable_types: struct list { int size; struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *head; struct node *tail; } *

variable_types: isArgumentNull int

variable_types: jobNumber int

user_defined_types: struct list { int size; struct node *head; struct node *tail; }

user_defined_types: struct node { struct job *data; struct node *next; struct node *prev; }


bgS

decompiled_code:
__int64 __fastcall bgS(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er14
_QWORD *v9; // rbx
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnJobNu(a2, v8);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInBackground(v9, a2);
}
}
else
{
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnRunning(a2, 2LL);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInBackground(v9, a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er14
_QWORD *v9; // rbx
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnJobNu(a2, v8);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInBackground(v9, a2);
}
}
else
{
freeArguments(a3, a1, a4);
v9 = (_QWORD *)searchOnRunning(a2, 2LL);
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v9);
if ( !(_DWORD)result )
return continueJobInBackground(v9, a2);
}
}
return result;
}

original_code:
void bgS(char** arguments, ListPtr l, int count, char* bufCopy)
{
 int isNull = arguments[1] == ((void *)0);
 if(isNull)
        {
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnRunning(l, 2);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
}

canonical_original_code:
void bgS(char **arguments, struct list *l, int count, char *bufCopy)
{
 int isNull = arguments[1] == ((void *)0);
 if(isNull)
        {
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnRunning(l, 2);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
}

variable_types: isNull int

variable_types: struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *


getPrompt

decompiled_code:
char *getPrompt()
{
char *result; // rax

result = getenv("DASH_PROMPT");
if ( !result )
result = "%% ";
return result;
}

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

result = getenv("DASH_PROMPT");
if ( !result )
result = "%% ";
return result;
}

original_code:
char* getPrompt()
{
 char *prompt = getenv("DASH_PROMPT");
 return (prompt == ((void *)0)) ? "%% " : prompt;
}

canonical_original_code:
char *getPrompt()
{
 char *prompt = getenv("DASH_PROMPT");
 return (prompt == ((void *)0)) ? "%% " : prompt;
}

variable_types:
prompt
char *


isExitCommand

decompiled_code:
_BOOL8 __fastcall isExitCommand(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "exit") )
v1 = strcmp(a1, "logout") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "exit") )
v1 = strcmp(a1, "logout") == 0;
return v1;
}

original_code:
int isExitCommand(char *buf)
{
 return (strcmp(buf, "exit") == 0 || strcmp(buf, "logout") == 0);
}

variable_types:
buf
char *


isBackgroundCommand

decompiled_code:
__int64 __fastcall isBackgroundCommand(const char *a1)
{
const char *v1; // rdx
__int64 result; // rax

v1 = &a1[strlen(a1) - 1];
result = 0LL;
if ( *v1 == 38 )
{
*v1 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
const char *v1; // rdx
__int64 result; // rax

v1 = &a1[strlen(a1) - 1];
result = 0LL;
if ( *v1 == 38 )
{
*v1 = 0;
result = 1LL;
}
return result;
}

original_code:
int isBackgroundCommand(char *buf)
{
 if(buf[strlen(buf)-1] == '&')
 {
  buf[strlen(buf)-1] = '\0';
  return 1;
 }
 else
  return 0;
}


isCdCommand

decompiled_code:
_BOOL8 __fastcall isCdCommand(_BYTE *a1, const char **a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = strcmp(*a2, "cd") == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_BYTE *a1, const char **a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = strcmp(*a2, "cd") == 0;
return result;
}

original_code:
int isCdCommand(char* bufCopy, char** arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "cd") == 0);
}

canonical_original_code:
int isCdCommand(char *bufCopy, char **arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "cd") == 0);
}


isJobsCommand

decompiled_code:
_BOOL8 __fastcall isJobsCommand(const char *a1)
{
return strcmp(a1, "jobs") == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
return strcmp(a1, "jobs") == 0;
}

original_code:
int isJobsCommand(char* buf)
{
 return (strcmp(buf, "jobs") == 0);
}

canonical_original_code:
int isJobsCommand(char *buf)
{
 return (strcmp(buf, "jobs") == 0);
}


isCommandNotEmpty

decompiled_code:
_BOOL8 __fastcall isCommandNotEmpty(_BYTE *a1)
{
return *a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_BYTE *a1)
{
return *a1 != 0;
}

original_code:
int isCommandNotEmpty(char* buf)
{
 return (strlen(buf) != 0);
}

canonical_original_code:
int isCommandNotEmpty(char *buf)
{
 return (strlen(buf) != 0);
}


isFgCommand

decompiled_code:
_BOOL8 __fastcall isFgCommand(_BYTE *a1, const char **a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = strcmp(*a2, "fg") == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_BYTE *a1, const char **a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = strcmp(*a2, "fg") == 0;
return result;
}

original_code:
int isFgCommand(char* bufCopy, char** arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "fg") == 0);
}

canonical_original_code:
int isFgCommand(char *bufCopy, char **arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "fg") == 0);
}


isBgCommand

decompiled_code:
_BOOL8 __fastcall isBgCommand(_BYTE *a1, const char **a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = strcmp(*a2, "bg") == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(_BYTE *a1, const char **a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = strcmp(*a2, "bg") == 0;
return result;
}

original_code:
int isBgCommand(char* bufCopy, char** arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "bg") == 0);
}

canonical_original_code:
int isBgCommand(char *bufCopy, char **arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "bg") == 0);
}


runCommand

decompiled_code:
void __fastcall __noreturn runCommand(char **argv, const char *a2)
{
printf("%s", *argv);
execvp(*argv, argv);
err_ret("couldn't execute: %s", a2);
exit(127);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(char **argv, const char *a2)
{
printf("%s", *argv);
execvp(*argv, argv);
err_ret("couldn't execute: %s", a2);
exit(127);
}

original_code:
void runCommand(char **args, char* buf)
{
 printf("%s", args[0]);
 execvp(*args, args);
 err_ret("couldn't execute: %s", buf);
 exit(127);
}

canonical_original_code:
void runCommand(char **args, char *buf)
{
 printf("%s", args[0]);
 execvp(*args, args);
 err_ret("couldn't execute: %s", buf);
 exit(127);
}


isArgumentForShowingVersion

decompiled_code:
_BOOL8 __fastcall isArgumentForShowingVersion(__int64 a1)
{
const char *v1; // rsi
_BOOL8 result; // rax

v1 = *(const char **)(a1 + 8);
result = 0LL;
if ( v1 )
result = strcmp(v1, "v") != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int64 a1)
{
const char *v1; // rsi
_BOOL8 result; // rax

v1 = *(const char **)(a1 + 8);
result = 0LL;
if ( v1 )
result = strcmp(v1, "v") != 0;
return result;
}

original_code:
int isArgumentForShowingVersion(char **argv)
{
 return (argv[1] != ((void *)0) && strcmp(argv[1],"v"));
}

variable_types:
argv
char **


showVersionAndExit

decompiled_code:
void __noreturn showVersionAndExit()
{
printf("Version %s\n", "Unversioned directory");
exit(0);
}

canonical_decompiled_code:
void __noreturn func14()
{
printf("Version %s\n", "Unversioned directory");
exit(0);
}

original_code:
void showVersionAndExit()
{
 printf("Version %s\n", "Unversioned directory");
 exit(0);
}


stop

decompiled_code:
void stop()
{
__pid_t *v0; // rbx

if ( !node
|| (v0 = *(__pid_t **)node, (unsigned int)isJobNull(*(_QWORD *)node))
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-z\n%s", pr);
}
else
{
kill(*v0, 20);
}
}

canonical_decompiled_code:
void func0()
{
__pid_t *v0; // rbx

if ( !node
|| (v0 = *(__pid_t **)node, (unsigned int)isJobNull(*(_QWORD *)node))
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-z\n%s", pr);
}
else
{
kill(*v0, 20);
}
}

original_code:
void stop(int a){
 if(node == ((void *)0)){
         printf("\nCaught Control-z\n%s", pr);
         return;
 }
 JobPtr job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
         printf("\nCaught Control-z\n%s", pr);
 }
 else kill(job->jobid, 20);
}

canonical_original_code:
void stop(int a){
 if(node == ((void *)0)){
         printf("\nCaught Control-z\n%s", pr);
         return;
 }
 struct job *job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
         printf("\nCaught Control-z\n%s", pr);
 }
 else kill(job->jobid, 20);
}

variable_types: a int

variable_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *


interrupt

decompiled_code:
void interrupt()
{
__pid_t *v0; // rbx

if ( node )
{
v0 = *(__pid_t **)node;
if ( (unsigned int)isJobNull(*(_QWORD *)node)
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-c\n%s", pr);
printf(pr);
}
else
{
printf("Killing PID: %d", (unsigned int)*v0);
kill(*v0, 2);
}
}
else
{
printf("\nCaught Control-c\n%s", pr);
}
}

canonical_decompiled_code:
void func1()
{
__pid_t *v0; // rbx

if ( node )
{
v0 = *(__pid_t **)node;
if ( (unsigned int)isJobNull(*(_QWORD *)node)
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-c\n%s", pr);
printf(pr);
}
else
{
printf("Killing PID: %d", (unsigned int)*v0);
kill(*v0, 2);
}
}
else
{
printf("\nCaught Control-c\n%s", pr);
}
}

original_code:
void interrupt(){
 if(node == ((void *)0)){
  printf("\nCaught Control-c\n%s", pr);
  return;
 }
 JobPtr job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
  printf("\nCaught Control-c\n%s", pr);
  printf(pr);
 }
 else{
  printf("Killing PID: %d", job->jobid);
  kill(job->jobid, 2);
 }
}

canonical_original_code:
void interrupt(){
 if(node == ((void *)0)){
  printf("\nCaught Control-c\n%s", pr);
  return;
 }
 struct job *job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
  printf("\nCaught Control-c\n%s", pr);
  printf(pr);
 }
 else{
  printf("Killing PID: %d", job->jobid);
  kill(job->jobid, 2);
 }
}


initSignals

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

signal(2, (__sighandler_t)interrupt);
result = signal(20, (__sighandler_t)stop);
jumpB = a1;
node = 0LL;
return result;
}

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

signal(2, (__sighandler_t)interrupt);
result = signal(20, (__sighandler_t)stop);
jumpB = a1;
node = 0LL;
return result;
}

original_code:
void initSignals(void (*jb)(void)){
 signal(2, interrupt);
 signal(20, stop);
 jumpB = jb;
 node = ((void *)0);
}

canonical_original_code:
void initSignals(void (*jb)()){
 signal(2, interrupt);
 signal(20, stop);
 jumpB = jb;
 node = ((void *)0);
}

variable_types:
jb
void (*)()


setNode

decompiled_code:
void __fastcall setNode(__int64 a1)
{
node = a1;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
node = a1;
}

original_code: void setNode(NodePtr nodee){ node = nodee; }

canonical_original_code: void setNode(struct node *nodee){ node = nodee; }


setPrompt

decompiled_code:
void __fastcall setPrompt(char *a1)
{
pr = a1;
}

canonical_decompiled_code:
void __fastcall func4(char *a1)
{
pr = a1;
}

original_code: void setPrompt(char* prompts){ pr = prompts; }

canonical_original_code: void setPrompt(char *prompts){ pr = prompts; }

variable_types:
prompts
char *


restoreSignals

decompiled_code:
__sighandler_t restoreSignals()
{
signal(2, (__sighandler_t)interrupt);
return signal(20, (__sighandler_t)stop);
}

canonical_decompiled_code:
__sighandler_t func5()
{
signal(2, (__sighandler_t)interrupt);
return signal(20, (__sighandler_t)stop);
}

original_code:
void restoreSignals(){
    signal(2, interrupt);
 signal(20, stop);
}


markAsStopped

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

v2 = *a2;
*(_DWORD *)(v2 + 20) = 2;
printf("\n[%d] %s %s\n", *(unsigned int *)(v2 + 4), "Stopped", *(const char **)(v2 + 8));
return addAtFront(a1, node);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 *a2)
{
__int64 v2; // rax

v2 = *a2;
*(_DWORD *)(v2 + 20) = 2;
printf("\n[%d] %s %s\n", *(unsigned int *)(v2 + 4), "Stopped", *(const char **)(v2 + 8));
return addAtFront(a1, node);
}

original_code:
void markAsStopped(ListPtr l, NodePtr n){
 JobPtr job = n->data;
 job->running = 2;
 printf("\n[%d] %s %s\n", job->jobNu, "Stopped", job->command);
 addAtFront(l, node);
}

canonical_original_code:
void markAsStopped(struct list *l, struct node *n){
 struct job *job = n->data;
 job->running = 2;
 printf("\n[%d] %s %s\n", job->jobNu, "Stopped", job->command);
 addAtFront(l, node);
}

variable_types:
n
struct node *


markAsKilled

decompiled_code:
int __fastcall markAsKilled(__int64 a1)
{
return printf(
"\n[%d] %s %s\n",
*(unsigned int *)(*(_QWORD *)a1 + 4LL),
"Killed",
*(const char **)(*(_QWORD *)a1 + 8LL));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
return printf(
"\n[%d] %s %s\n",
*(unsigned int *)(*(_QWORD *)a1 + 4LL),
"Killed",
*(const char **)(*(_QWORD *)a1 + 8LL));
}

original_code:
void markAsKilled(NodePtr n){
 JobPtr job = n->data;
 printf("\n[%d] %s %s\n", job->jobNu, "Killed", job->command);
}

canonical_original_code:
void markAsKilled(struct node *n){
 struct job *job = n->data;
 printf("\n[%d] %s %s\n", job->jobNu, "Killed", job->command);
}


ignoreSignals

decompiled_code:
__sighandler_t ignoreSignals()
{
signal(2, handler);
return signal(20, handler);
}

canonical_decompiled_code:
__sighandler_t func8()
{
signal(2, handler);
return signal(20, handler);
}

original_code:
void ignoreSignals(){
 signal(2, ((__sighandler_t) 1));
 signal(20, ((__sighandler_t) 1));
}

canonical_original_code:
void ignoreSignals(){
 signal(2, ((void (*)(int)) 1));
 signal(20, ((void (*)(int)) 1));
}


continueJobInBackground

decompiled_code:
__int64 __fastcall continueJobInBackground(__pid_t **a1)
{
__pid_t *v1; // rax
__pid_t v2; // ebx

v1 = *a1;
v2 = **a1;
v1[5] = 1;
printf("\n[%d] %s\n", (unsigned int)v1[1], *((const char **)v1 + 1));
kill(v2, 18);
restoreSignals();
return jumpB();
}

canonical_decompiled_code:
__int64 __fastcall func9(__pid_t **a1)
{
__pid_t *v1; // rax
__pid_t v2; // ebx

v1 = *a1;
v2 = **a1;
v1[5] = 1;
printf("\n[%d] %s\n", (unsigned int)v1[1], *((const char **)v1 + 1));
kill(v2, 18);
func5();
return jumpB();
}

original_code:
void continueJobInBackground(NodePtr nodee, ListPtr jobList){
 JobPtr job = nodee->data;
 int pid = job->jobid;
 job->running = 1;
 printf("\n[%d] %s\n", job->jobNu, job->command);
 kill(pid, 18);
 restoreSignals();
 jumpB();
}

canonical_original_code:
void continueJobInBackground(struct node *nodee, struct list *jobList){
 struct job *job = nodee->data;
 int pid = job->jobid;
 job->running = 1;
 printf("\n[%d] %s\n", job->jobNu, job->command);
 kill(pid, 18);
 restoreSignals();
 jumpB();
}

variable_types: struct list { int size; struct node *head; struct node *tail; } *

variable_types: pid int


restoreSignalsAndDetermineStatus

decompiled_code:
int __fastcall restoreSignalsAndDetermineStatus(char a1, __int64 a2, __int64 *a3)
{
int result; // eax

restoreSignals();
result = (a1 & 0x7F) + 1;
if ( !__OFSUB__((a1 & 0x7F) + 1, 1) && (a1 & 0x7F) != 0 )
{
if ( a1 != 127 )
return markAsKilled((__int64)a3);
return markAsStopped(a2, a3);
}
if ( a1 == 127 )
return markAsStopped(a2, a3);
return result;
}

canonical_decompiled_code:
int __fastcall func10(char a1, __int64 a2, __int64 *a3)
{
int result; // eax

func5();
result = (a1 & 0x7F) + 1;
if ( !__OFSUB__((a1 & 0x7F) + 1, 1) && (a1 & 0x7F) != 0 )
{
if ( a1 != 127 )
return func7((__int64)a3);
return func6(a2, a3);
}
if ( a1 == 127 )
return func6(a2, a3);
return result;
}

original_code:
void restoreSignalsAndDetermineStatus(int status, ListPtr jobList, NodePtr n){
 restoreSignals();
 if((((signed char) (((status) & 0x7f) + 1) >> 1) > 0) || (((status) & 0xff) == 0x7f)){
  if((((status) & 0xff) == 0x7f)) markAsStopped(jobList, n);
  else markAsKilled(n);
 }
 else
 {
 }
}

canonical_original_code:
void restoreSignalsAndDetermineStatus(int status, struct list *jobList, struct node *n){
 restoreSignals();
 if((((char) (((status) & 0x7f) + 1) >> 1) > 0) || (((status) & 0xff) == 0x7f)){
  if((((status) & 0xff) == 0x7f)) markAsStopped(jobList, n);
  else markAsKilled(n);
 }
 else
 {
 }
}

variable_types: status int


continueJobInForeground

decompiled_code:
int __fastcall continueJobInForeground(__int64 *a1, __int64 a2)
{
__pid_t v2; // er12
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

setNode((__int64)a1);
v2 = *(_DWORD *)*a1;
stat_loc[0] = 0;
ignoreSignals();
removeNode(a2, a1);
kill(v2, 18);
if ( waitpid(v2, stat_loc, 2) < 0 )
err_sys("waitpid error");
return restoreSignalsAndDetermineStatus(stat_loc[0], a2, a1);
}

canonical_decompiled_code:
int __fastcall func11(__int64 *a1, __int64 a2)
{
__pid_t v2; // er12
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

func3((__int64)a1);
v2 = *(_DWORD *)*a1;
stat_loc[0] = 0;
func8();
removeNode(a2, a1);
kill(v2, 18);
if ( waitpid(v2, stat_loc, 2) < 0 )
err_sys("waitpid error");
return func10(stat_loc[0], a2, a1);
}

original_code:
void continueJobInForeground(NodePtr nodee, ListPtr jobList){
 setNode(nodee);
 JobPtr job = nodee->data;
 int pid = job->jobid;
 int status = 0;
 ignoreSignals();
 removeNode(jobList, nodee);
 kill(pid, 18);
 if((pid=waitpid(pid,&status,2))<0) err_sys("waitpid error");
 restoreSignalsAndDetermineStatus(status, jobList, nodee);
}

canonical_original_code:
void continueJobInForeground(struct node *nodee, struct list *jobList){
 setNode(nodee);
 struct job *job = nodee->data;
 int pid = job->jobid;
 int status = 0;
 ignoreSignals();
 removeNode(jobList, nodee);
 kill(pid, 18);
 if((pid=waitpid(pid,&status,2))<0) err_sys("waitpid error");
 restoreSignalsAndDetermineStatus(status, jobList, nodee);
}


addToAddress

decompiled_code:
__int64 __fastcall addToAddress(__int64 a1, int a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return a1 + a2;
}

original_code:
size_t addToAddress(BlockPtr block, int amount){
 size_t *iA = (size_t *) █
 size_t initialAddress = *iA;
 size_t newAddress = initialAddress + amount;
 return newAddress;
}

canonical_original_code:
unsigned long addToAddress(struct block *block, int amount){
 unsigned long *iA = (size_t *) █
 unsigned long initialAddress = *iA;
 unsigned long newAddress = initialAddress + amount;
 return newAddress;
}

variable_types: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; } *

variable_types: amount int

variable_types:
iA
unsigned long *

variable_types:
initialAddress
unsigned long

variable_types:
newAddress
unsigned long


buddy

decompiled_code:
__int64 __fastcall buddy(__int64 a1)
{
int v1; // eax

v1 = addToAddress(a1, -(int)initialBlockAddress);
return addToAddress(initialBlock, v1 ^ (unsigned int)(1 << *(_DWORD *)(a1 + 4)));
}

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

v1 = func0(a1, -(int)initialBlockAddress);
return func0(initialBlock, v1 ^ (unsigned int)(1 << *(_DWORD *)(a1 + 4)));
}

original_code:
size_t buddy(BlockPtr block){
 size_t address = addToAddress(block, -initialBlockAddress);
 return (addToAddress(initialBlock, address^(1<<block->kval)));
}

canonical_original_code:
unsigned long buddy(struct block *block){
 unsigned long address = addToAddress(block, -initialBlockAddress);
 return (addToAddress(initialBlock, address^(1<<block->kval)));
}

variable_types:
address
unsigned long

user_defined_types: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; }


initializeFreeBlock

decompiled_code:
void __fastcall initializeFreeBlock(__int64 a1, int a2, int a3, __int64 a4)
{
initializeReservedBlock((_DWORD *)a1, a2, a3);
*(_QWORD *)(a1 + 24) = a4;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2, int a3, __int64 a4)
{
func2((_DWORD *)a1, a2, a3);
*(_QWORD *)(a1 + 24) = a4;
}

original_code:
void initializeFreeBlock(BlockPtr block, int tag, int kval, BlockPtr prevBlock)
{
 initializeReservedBlock(block, tag, kval);
 block->prev = prevBlock;
}

canonical_original_code:
void initializeFreeBlock(struct block *block, int tag, int kval, struct block *prevBlock)
{
 initializeReservedBlock(block, tag, kval);
 block->prev = prevBlock;
}

variable_types: tag int

variable_types: kval int

variable_types:
prevBlock
struct block *


initial

decompiled_code:
__int64 initial()
{
void *v0; // rax
__int64 result; // rax

v0 = sbrk(0x4000000LL);
initialBlock = (__int64)v0;
blockAddress[26] = (__int64)v0;
initializeFreeBlock((__int64)v0, 0, 26, 0LL);
result = addToAddress(initialBlock, 0);
initialBlockAddress = result;
initialized = 1;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
void *v0; // rax
__int64 result; // rax

v0 = sbrk(0x4000000LL);
initialBlock = (__int64)v0;
blockAddress[26] = (__int64)v0;
func3((__int64)v0, 0, 26, 0LL);
result = func0(initialBlock, 0);
initialBlockAddress = result;
initialized = 1;
return result;
}

original_code:
void initial(){
 initialBlock = (BlockPtr) sbrk(67108864);
 blockAddress[26] = initialBlock;
 initializeFreeBlock(initialBlock, 0, 26, ((void *)0));
 initialBlockAddress = addToAddress(initialBlock, 0);
 initialized = 1;
}

canonical_original_code:
void initial(){
 initialBlock = (struct block *) sbrk(67108864);
 blockAddress[26] = initialBlock;
 initializeFreeBlock(initialBlock, 0, 26, ((void *)0));
 initialBlockAddress = addToAddress(initialBlock, 0);
 initialized = 1;
}


decompiled_code:
__int64 __fastcall buddy_getSize(__int64 a1)
{
return (unsigned int)(1 << *(_DWORD *)(a1 + 4));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return (unsigned int)(1 << *(_DWORD *)(a1 + 4));
}

original_code:
int buddy_getSize(BlockPtr block){
 return 1 << block->kval;
}

canonical_original_code:
int buddy_getSize(struct block *block){
 return 1 << block->kval;
}