Unique

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

result = calloc(1uLL, 0x28uLL);
*result = 1;
return result;
}

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

result = calloc(1uLL, 0x28uLL);
*result = 1;
return result;
}

original_code:
Constraint_t *Unique(void) {
   Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_UNIQUE;
   return con;
}

canonical_original_code:
struct Constraint_t *Unique() {
   struct Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_UNIQUE;
   return con;
}

user_defined_types: enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 }

user_defined_types: struct CondComp { struct Expression_s *expr1; }

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


decompiled_code:
void __fastcall Column_freeList(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[4];
free(*v2);
deleteConstraint_ts((__int64)v2[2]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[4];
free(*v2);
func1((__int64)v2[2]);
free(v2);
}
while ( v1 );
}
}

original_code:
void Column_freeList(Column_t *column) {
   if (column) {
      Column_t *next = column->next;
      free(column->name);
      deleteConstraint_ts(column->constraints);
      free(column);
      Column_freeList(next);
   }
}

canonical_original_code:
void Column_freeList(struct Column_t *column) {
   if (column) {
      struct Column_t *next = column->next;
      free(column->name);
      deleteConstraint_ts(column->constraints);
      free(column);
      Column_freeList(next);
   }
}

variable_types: struct Column_t { char *name; enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } type; struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; 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; } *default_val; unsigned int size; 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 *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; } *check; } constraint; struct Constraint_t *next; } *constraints; unsigned long offset; struct Column_t *next; } *

return_type: void

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: struct Constraint_t { enum constraint_type t; union { struct ForeignKeyRef_t ref; struct Literal_t *default_val; unsigned int size; struct Condition_t *check; } constraint; struct Constraint_t *next; }

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

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


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

v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
while ( *(_DWORD *)v1 != 7 )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
goto LABEL_6;
}
result = *(unsigned int *)(v1 + 8);
}
else
{
LABEL_6:
result = *(unsigned int *)(a1 + 8);
if ( (unsigned int)result <= 3 )
result = CSWTCH_14[result];
}
return result;
}

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

v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
while ( *(_DWORD *)v1 != 7 )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
goto LABEL_6;
}
result = *(unsigned int *)(v1 + 8);
}
else
{
LABEL_6:
result = *(unsigned int *)(a1 + 8);
if ( (unsigned int)result <= 3 )
result = CSWTCH_14[result];
}
return result;
}

original_code:
size_t Column_getSize(Column_t *col) {
   Constraint_t *cons = col->constraints;
   while (cons) {
      if (cons->t == CONS_SIZE)
         return cons->constraint.size;
      cons = cons->next;
   }
   switch (col->type) {
      case TYPE_CHAR: return sizeof(char);
      case TYPE_DOUBLE: return sizeof(double);
      case TYPE_INT: return sizeof(int);
      case TYPE_TEXT: return 250;
   }
}

canonical_original_code:
unsigned long Column_getSize(struct Column_t *col) {
   struct Constraint_t *cons = col->constraints;
   while (cons) {
      if (cons->t == CONS_SIZE)
         return cons->constraint.size;
      cons = cons->next;
   }
   switch (col->type) {
      case TYPE_CHAR: return sizeof(char);
      case TYPE_DOUBLE: return sizeof(double);
      case TYPE_INT: return sizeof(int);
      case TYPE_TEXT: return 250;
   }
}

variable_types: struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; 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; } *default_val; unsigned int size; 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 *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; } *check; } constraint; struct Constraint_t *next; } *

return_type: unsigned long


decompiled_code:
// attributes: thunk
__int64 __fastcall Column_getOffsets(__int64 a1)
{
return Column_getOffsets_r_constprop_0(a1);
}

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

original_code:
void Column_getOffsets(Column_t *cols) {
   Column_getOffsets_r(cols, 0);
}

canonical_original_code:
void Column_getOffsets(struct Column_t *cols) {
   Column_getOffsets_r(cols, 0);
}

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

user_defined_types: struct ForeignKeyRef_t { char *col_name; }

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

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 }

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 }


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

result = a2;
if ( a1 )
{
*(_QWORD *)(a1 + 32) = a2;
result = a1;
}
return result;
}

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

result = a2;
if ( a1 )
{
*(_QWORD *)(a1 + 32) = a2;
result = a1;
}
return result;
}

original_code:
Constraint_t *Constraint_append(Constraint_t *constraints, Constraint_t *constraint) {
   if (constraints == ((void *)0))
      constraints = constraint;
   else
      constraints->next = constraint;
   return constraints;
}

canonical_original_code:
struct Constraint_t *Constraint_append(struct Constraint_t *constraints, struct Constraint_t *constraint) {
   if (constraints == ((void *)0))
      constraints = constraint;
   else
      constraints->next = constraint;
   return constraints;
}

variable_types:
constraints
struct Constraint_t *

variable_types:
constraint
struct Constraint_t *

return_type: struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; 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; } *default_val; unsigned int size; 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 *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; } *check; } constraint; struct Constraint_t *next; } *

user_defined_types: struct CondComp { struct Expression_s *expr1; }

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


decompiled_code:
__int64 __fastcall Column_addConstraint(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r8

v2 = Constraint_append(*(_QWORD *)(a1 + 16), a2);
*(_QWORD *)(v3 + 16) = v2;
return v3;
}

original_code:
Column_t *Column_addConstraint(Column_t *column, Constraint_t *constraints) {
   column->constraints = Constraint_append(column->constraints, constraints);
   return column;
}

canonical_original_code:
struct Column_t *Column_addConstraint(struct Column_t *column, struct Constraint_t *constraints) {
   column->constraints = Constraint_append(column->constraints, constraints);
   return column;
}

variable_types:
column
struct Column_t *

return_type: struct Column_t { char *name; enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } type; struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; 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; } *default_val; unsigned int size; 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 *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; } *check; } constraint; struct Constraint_t *next; } *constraints; unsigned long offset; struct Column_t *next; } *

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: struct Constraint_t { enum constraint_type t; union { struct ForeignKeyRef_t ref; struct Literal_t *default_val; unsigned int size; struct Condition_t *check; } constraint; struct Constraint_t *next; }

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

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


decompiled_code:
int __fastcall Constraint_print(__int64 a1)
{
int result; // eax

switch ( *(_DWORD *)a1 )
{
case 0:
result = printf("Not null");
break;
case 1:
result = printf("Unique");
break;
case 2:
result = printf("Primary Key");
break;
case 3:
result = printf("Foreign key (%s, %s)", *(const char **)(a1 + 16), *(const char **)(a1 + 24));
break;
case 4:
printf("Default: ");
result = Literal_print(*(_QWORD *)(a1 + 8));
break;
case 5:
result = printf("Auto increment");
break;
case 6:
printf("Check: ");
result = Condition_print(*(_QWORD *)(a1 + 8));
break;
case 7:
result = printf("Size: %u", *(unsigned int *)(a1 + 8));
break;
default:
result = printf("Unknown constraint type");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
int result; // eax

switch ( *(_DWORD *)a1 )
{
case 0:
result = printf("Not null");
break;
case 1:
result = printf("Unique");
break;
case 2:
result = printf("Primary Key");
break;
case 3:
result = printf("Foreign key (%s, %s)", *(const char **)(a1 + 16), *(const char **)(a1 + 24));
break;
case 4:
printf("Default: ");
result = Literal_print(*(_QWORD *)(a1 + 8));
break;
case 5:
result = printf("Auto increment");
break;
case 6:
printf("Check: ");
result = Condition_print(*(_QWORD *)(a1 + 8));
break;
case 7:
result = printf("Size: %u", *(unsigned int *)(a1 + 8));
break;
default:
result = printf("Unknown constraint type");
break;
}
return result;
}

original_code:
void Constraint_print(void *constraint_voidp) {
   Constraint_t *constraint = (Constraint_t *)constraint_voidp;
   switch(constraint->t) {
      case CONS_DEFAULT:
         printf("Default: ");
         Literal_print(constraint->constraint.default_val);
         break;
      case CONS_PRIMARY_KEY:
         printf("Primary Key");
         break;
      case CONS_UNIQUE:
         printf("Unique");
         break;
      case CONS_FOREIGN_KEY:
         printf("Foreign key (%s, %s)", constraint->constraint.ref.table_name,
                                          constraint->constraint.ref.table_col_name);
         break;
      case CONS_AUTO_INCREMENT:
         printf("Auto increment");
         break;
      case CONS_NOT_NULL:
         printf("Not null");
         break;
      case CONS_CHECK:
         printf("Check: ");
         Condition_print(constraint->constraint.check);
         break;
      case CONS_SIZE:
         printf("Size: %u", constraint->constraint.size);
         break;
      default:
         printf("Unknown constraint type");
   }
}

canonical_original_code:
void Constraint_print(void *constraint_voidp) {
   struct Constraint_t *constraint = (Constraint_t *)constraint_voidp;
   switch(constraint->t) {
      case CONS_DEFAULT:
         printf("Default: ");
         Literal_print(constraint->constraint.default_val);
         break;
      case CONS_PRIMARY_KEY:
         printf("Primary Key");
         break;
      case CONS_UNIQUE:
         printf("Unique");
         break;
      case CONS_FOREIGN_KEY:
         printf("Foreign key (%s, %s)", constraint->constraint.ref.table_name,
                                          constraint->constraint.ref.table_col_name);
         break;
      case CONS_AUTO_INCREMENT:
         printf("Auto increment");
         break;
      case CONS_NOT_NULL:
         printf("Not null");
         break;
      case CONS_CHECK:
         printf("Check: ");
         Condition_print(constraint->constraint.check);
         break;
      case CONS_SIZE:
         printf("Size: %u", constraint->constraint.size);
         break;
      default:
         printf("Unknown constraint type");
   }
}

user_defined_types: enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 }

user_defined_types: struct ForeignKeyRef_t { char *col_name; }

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

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

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


decompiled_code:
int __fastcall Constraint_printList(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
printf(" [");
while ( 1 )
{
Constraint_print(v1);
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
break;
printf(", ");
}
result = putchar(93);
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
printf(" [");
while ( 1 )
{
func14(v1);
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
break;
printf(", ");
}
result = putchar(93);
}
return result;
}

original_code:
void Constraint_printList(Constraint_t *constraints) {
   int first = 1;
   if (constraints) {
      printf(" [");
      for (; constraints; constraints = constraints->next) {
         if (first) {
            first = 0;
         } else {
            printf(", ");
         }
         Constraint_print(constraints);
      }
      printf("]");
   }
}

canonical_original_code:
void Constraint_printList(struct Constraint_t *constraints) {
   int first = 1;
   if (constraints) {
      printf(" [");
      for (; constraints; constraints = constraints->next) {
         if (first) {
            first = 0;
         } else {
            printf(", ");
         }
         Constraint_print(constraints);
      }
      printf("]");
   }
}

variable_types: first int

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:
void __fastcall Column_setSize(__int64 a1)
{
size_constraint = a1;
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
size_constraint = a1;
}

original_code:
void Column_setSize(ssize_t size) {
   size_constraint = size;
}

canonical_original_code:
void Column_setSize(long size) {
   size_constraint = size;
}

variable_types: size long


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

if ( !a1 )
return a2;
v2 = Column_append(*(_QWORD *)(a1 + 32));
return app_col(a1, v2);
}

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

if ( !a1 )
return a2;
v2 = func17(*(_QWORD *)(a1 + 32));
return func0(a1, v2);
}

original_code:
Column_t *Column_append(Column_t *col1, Column_t *col2) {
   if (!col1) return col2;
   return app_col(col1, Column_append(col1->next, col2));
}

canonical_original_code:
struct Column_t *Column_append(struct Column_t *col1, struct Column_t *col2) {
   if (!col1) return col2;
   return app_col(col1, Column_append(col1->next, col2));
}

user_defined_types: struct CondComp { struct Expression_s *expr1; }

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 ColumnReference_t { char *tableName; }

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


decompiled_code:
int __fastcall Column_compareByName(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func18(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
int Column_compareByName(const void *c1, const void *c2) {
   return strcmp(((Column_t *)c1)->name, ((Column_t *)c2)->name);
}

canonical_original_code:
int Column_compareByName(void *c1, void *c2) {
   return strcmp(((struct Column_t *)c1)->name, ((struct Column_t *)c2)->name);
}

return_type: int

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: struct Constraint_t { enum constraint_type t; union { struct ForeignKeyRef_t ref; struct Literal_t *default_val; unsigned int size; struct Condition_t *check; } constraint; struct Constraint_t *next; }

user_defined_types: enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 }

user_defined_types: struct ForeignKeyRef_t { char *col_name; }

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

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


decompiled_code:
__int64 __fastcall Table_addPrimaryKey(__int64 a1, const char *a2)
{
__int64 v2; // r12
__int64 v4; // rax
__int64 v5; // rdi

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 32);
if ( !v2 )
return v2;
}
v4 = PrimaryKey();
v5 = v2;
v2 = a1;
Column_addConstraint(v5, v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
__int64 v2; // r12
__int64 v4; // rax
__int64 v5; // rdi

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 32);
if ( !v2 )
return v2;
}
v4 = PrimaryKey();
v5 = v2;
v2 = a1;
Column_addConstraint(v5, v4);
}
return v2;
}

original_code:
static Table_t *Table_addPrimaryKey(Table_t *table, const char *col_name) {
   Column_t *col = table->columns;
   for (; col; col = col->next) {
      if (!strcmp(col->name, col_name)) {
         Column_addConstraint(col, PrimaryKey());
         return table;
      }
   }
   return ((void *)0);
}

canonical_original_code:
static struct Table_s *Table_addPrimaryKey(struct Table_s *table, char *col_name) {
   struct Column_t *col = table->columns;
   for (; col; col = col->next) {
      if (!strcmp(col->name, col_name)) {
         Column_addConstraint(col, PrimaryKey());
         return table;
      }
   }
   return ((void *)0);
}

variable_types:
table
struct Table_s *

return_type: struct Table_s { char *name; struct Column_t { char *name; enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } type; struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; 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; } *default_val; unsigned int size; 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 *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; } *check; } constraint; struct Constraint_t *next; } *constraints; unsigned long offset; struct Column_t *next; } *columns; } *

user_defined_types: struct Table_s { char *name; struct Column_t *columns; }


decompiled_code:
__int64 __fastcall Table_addForeignKey(__int64 a1, int a2, int a3, int a4, int a5, int a6, char *s2)
{
__int64 v8; // rbp
const char *v9; // rdi
__int64 v10; // rdx
__int64 v11; // rax
__int64 result; // rax

if ( a1 )
{
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
{
while ( 1 )
{
v9 = *(const char **)v8;
if ( !strcmp(*(const char **)v8, s2) )
break;
v8 = *(_QWORD *)(v8 + 32);
if ( !v8 )
goto LABEL_7;
}
v11 = ForeignKey(v9, s2, v10);
Column_addConstraint(v8, v11);
result = a1;
}
else
{
LABEL_7:
fprintf(stderr, "Error: column %s not in table\n", s2);
result = a1;
}
}
else
{
fwrite("Error: table is null\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, int a4, int a5, int a6, char *s2)
{
__int64 v8; // rbp
const char *v9; // rdi
__int64 v10; // rdx
__int64 v11; // rax
__int64 result; // rax

if ( a1 )
{
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
{
while ( 1 )
{
v9 = *(const char **)v8;
if ( !strcmp(*(const char **)v8, s2) )
break;
v8 = *(_QWORD *)(v8 + 32);
if ( !v8 )
goto LABEL_7;
}
v11 = ForeignKey(v9, s2, v10);
Column_addConstraint(v8, v11);
result = a1;
}
else
{
LABEL_7:
fprintf(stderr, "Error: column %s not in table\n", s2);
result = a1;
}
}
else
{
fwrite("Error: table is null\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
Table_t *Table_addForeignKey(Table_t *table, ForeignKeyRef_t fkr) {
   if (table != ((void *)0)) {
      Column_t *col = table->columns;
      for (; col; col=col->next) {
         if (!strcmp(col->name, fkr.col_name)) {
            Column_addConstraint(col, ForeignKey(fkr));
            return table;
         }
      }
      fprintf(stderr, "Error: column %s not in table\n", fkr.col_name);
      return table;
   }
   fprintf(stderr, "Error: table is null\n");
   return table;
}

canonical_original_code:
struct Table_s *Table_addForeignKey(struct Table_s *table, struct ForeignKeyRef_t fkr) {
   if (table != ((void *)0)) {
      struct Column_t *col = table->columns;
      for (; col; col=col->next) {
         if (!strcmp(col->name, fkr.col_name)) {
            Column_addConstraint(col, ForeignKey(fkr));
            return table;
         }
      }
      fprintf(stderr, "Error: column %s not in table\n", fkr.col_name);
      return table;
   }
   fprintf(stderr, "Error: table is null\n");
   return table;
}

variable_types:
fkr
struct ForeignKeyRef_t

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

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

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 }


decompiled_code:
__int64 __fastcall Table_addKeyDecs(__int64 a1, const char *a2, int a3, int a4, int a5, int a6)
{
const char *v6; // rbp
const char **i; // rbx

if ( a2 )
{
v6 = a2;
do
{
while ( 1 )
{
if ( !*(_DWORD *)v6 )
{
for ( i = (const char **)*((_QWORD *)v6 + 1); i; i = (const char **)i[1] )
{
a2 = *i;
if ( !Table_addPrimaryKey(a1, *i) )
{
a2 = "Error: column '%s' not found\n";
fprintf(stderr, "Error: column '%s' not found\n", *i);
}
}
goto LABEL_4;
}
if ( *(_DWORD *)v6 == 1 )
break;
LODWORD(a2) = 1;
fwrite("Unknown declaration type\n", 1uLL, 0x19uLL, stderr);
LABEL_4:
v6 = (const char *)*((_QWORD *)v6 + 4);
if ( !v6 )
return a1;
}
if ( Table_addForeignKey(a1, (int)a2, a3, a4, a5, a6, *((char **)v6 + 1)) )
goto LABEL_4;
a2 = "Error: column '%s' not found\n";
fprintf(stderr, "Error: column '%s' not found\n", *((const char **)v6 + 1));
v6 = (const char *)*((_QWORD *)v6 + 4);
}
while ( v6 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, int a3, int a4, int a5, int a6)
{
const char *v6; // rbp
const char **i; // rbx

if ( a2 )
{
v6 = a2;
do
{
while ( 1 )
{
if ( !*(_DWORD *)v6 )
{
for ( i = (const char **)*((_QWORD *)v6 + 1); i; i = (const char **)i[1] )
{
a2 = *i;
if ( !func0(a1, *i) )
{
a2 = "Error: column '%s' not found\n";
fprintf(stderr, "Error: column '%s' not found\n", *i);
}
}
goto LABEL_4;
}
if ( *(_DWORD *)v6 == 1 )
break;
LODWORD(a2) = 1;
fwrite("Unknown declaration type\n", 1uLL, 0x19uLL, stderr);
LABEL_4:
v6 = (const char *)*((_QWORD *)v6 + 4);
if ( !v6 )
return a1;
}
if ( func1(a1, (int)a2, a3, a4, a5, a6, *((char **)v6 + 1)) )
goto LABEL_4;
a2 = "Error: column '%s' not found\n";
fprintf(stderr, "Error: column '%s' not found\n", *((const char **)v6 + 1));
v6 = (const char *)*((_QWORD *)v6 + 4);
}
while ( v6 );
}
return a1;
}

original_code:
Table_t *Table_addKeyDecs(Table_t *table, KeyDec_t *decs) {
   StrList_t *slist;
   for (; decs; decs = decs->next) {
      switch (decs->t) {
         case KEY_DEC_PRIMARY:
            for (slist = decs->dec.primary_keys; slist; slist = slist->next) {
               if (!Table_addPrimaryKey(table, slist->str))
                  fprintf(stderr, "Error: column '%s' not found\n", slist->str);
            }
            break;
         case KEY_DEC_FOREIGN:
            if (!Table_addForeignKey(table, decs->dec.fkey))
               fprintf(stderr, "Error: column '%s' not found\n", decs->dec.fkey.col_name);
            break;
         default:
            fprintf(stderr, "Unknown declaration type\n");
      }
   }
   return table;
}

canonical_original_code:
struct Table_s *Table_addKeyDecs(struct Table_s *table, struct KeyDec_s *decs) {
   struct StrList_t *slist;
   for (; decs; decs = decs->next) {
      switch (decs->t) {
         case KEY_DEC_PRIMARY:
            for (slist = decs->dec.primary_keys; slist; slist = slist->next) {
               if (!Table_addPrimaryKey(table, slist->str))
                  fprintf(stderr, "Error: column '%s' not found\n", slist->str);
            }
            break;
         case KEY_DEC_FOREIGN:
            if (!Table_addForeignKey(table, decs->dec.fkey))
               fprintf(stderr, "Error: column '%s' not found\n", decs->dec.fkey.col_name);
            break;
         default:
            fprintf(stderr, "Unknown declaration type\n");
      }
   }
   return table;
}

variable_types: struct KeyDec_s { enum key_dec_type { KEY_DEC_PRIMARY=0, KEY_DEC_FOREIGN=1 } t; union { struct StrList_t { char *str; struct StrList_t *next; } *primary_keys; struct ForeignKeyRef_t fkey; } dec; struct KeyDec_s *next; } *

user_defined_types: struct KeyDec_s { enum key_dec_type t; union { struct StrList_t *primary_keys; struct ForeignKeyRef_t fkey; } dec; struct KeyDec_s *next; }

user_defined_types: struct CondComp { struct Expression_s *expr1; }

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

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


decompiled_code:
__int64 __fastcall Table_make(__int64 a1, __int64 a2, const char *a3)
{
_QWORD *v4; // rax
__int64 v5; // rbp
int v6; // edx
int v7; // ecx
int v8; // er8
int v9; // er9

v4 = calloc(1uLL, 0x10uLL);
*v4 = a1;
v5 = (__int64)v4;
v4[1] = a2;
Column_getOffsets(a2);
return Table_addKeyDecs(v5, a3, v6, v7, v8, v9);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, const char *a3)
{
_QWORD *v4; // rax
__int64 v5; // rbp
int v6; // edx
int v7; // ecx
int v8; // er8
int v9; // er9

v4 = calloc(1uLL, 0x10uLL);
*v4 = a1;
v5 = (__int64)v4;
v4[1] = a2;
Column_getOffsets(a2);
return func2(v5, a3, v6, v7, v8, v9);
}

original_code:
Table_t *Table_make(char *name, Column_t *columns, KeyDec_t *decs) {
   Table_t *new_table = (Table_t *)calloc(1, sizeof(Table_t));
   new_table->name = name;
   new_table->columns = columns;
   Column_getOffsets(columns);
   return Table_addKeyDecs(new_table, decs);
}

canonical_original_code:
struct Table_s *Table_make(char *name, struct Column_t *columns, struct KeyDec_s *decs) {
   struct Table_s *new_table = (Table_t *)calloc(1, sizeof(Table_t));
   new_table->name = name;
   new_table->columns = columns;
   Column_getOffsets(columns);
   return Table_addKeyDecs(new_table, decs);
}

variable_types:
name
char *

variable_types:
columns
struct Column_t *

variable_types: struct Table_s { char *name; struct Column_t { char *name; enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } type; struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; 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; } *default_val; unsigned int size; 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 *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; } *check; } constraint; struct Constraint_t *next; } *constraints; unsigned long offset; struct Column_t *next; } *columns; } *

user_defined_types: enum key_dec_type { KEY_DEC_PRIMARY=0, KEY_DEC_FOREIGN=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: struct StrList_t { char *str; struct StrList_t *next; }

user_defined_types: struct Constraint_t { enum constraint_type t; union { struct ForeignKeyRef_t ref; struct Literal_t *default_val; unsigned int size; struct Condition_t *check; } constraint; struct Constraint_t *next; }

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

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


decompiled_code:
__int64 __fastcall Table_addPrimaryKeys(__int64 a1, __int64 a2)
{
unsigned int i; // ebx
const char *v4; // r12

for ( i = 0; ; ++i )
{
if ( i >= (unsigned __int64)vector_size(a2) )
return a1;
v4 = (const char *)vector_getAt(a2, i);
a1 = Table_addPrimaryKey(a1, v4);
if ( !a1 )
break;
}
fprintf(stderr, "Error: column '%s' not found\n", v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int i; // ebx
const char *v4; // r12

for ( i = 0; ; ++i )
{
if ( i >= (unsigned __int64)vector_size(a2) )
return a1;
v4 = (const char *)vector_getAt(a2, i);
a1 = func0(a1, v4);
if ( !a1 )
break;
}
fprintf(stderr, "Error: column '%s' not found\n", v4);
return 0LL;
}

original_code:
Table_t *Table_addPrimaryKeys(Table_t *table, vector_t *col_names) {
   unsigned i;
   for (i=0; i < vector_size(col_names); ++i) {
      const char *col_name = (const char *)vector_getAt(col_names, i);
      table = Table_addPrimaryKey(table, col_name);
      if (!table) {
         fprintf(stderr, "Error: column '%s' not found\n", col_name);
         return ((void *)0);
      }
   }
   return table;
}

canonical_original_code:
struct Table_s *Table_addPrimaryKeys(struct Table_s *table, struct vector_s *col_names) {
   unsigned int i;
   for (i=0; i < vector_size(col_names); ++i) {
      char *col_name = (const char *)vector_getAt(col_names, i);
      table = Table_addPrimaryKey(table, col_name);
      if (!table) {
         fprintf(stderr, "Error: column '%s' not found\n", col_name);
         return ((void *)0);
      }
   }
   return table;
}

variable_types: struct vector_s { unsigned long size; void **data; void (*free)(void *); } *

variable_types:
i
unsigned int

user_defined_types: struct Table_s { char *name; struct Column_t *columns; }

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

user_defined_types: enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 }

user_defined_types: struct ForeignKeyRef_t { char *col_name; }

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

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 ColumnReference_t { char *tableName; }

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


decompiled_code:
void __fastcall Table_free(void *ptr)
{
Column_freeList(*((_QWORD *)ptr + 1));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
Column_freeList(*((_QWORD *)ptr + 1));
free(*(void **)ptr);
free(ptr);
}

original_code:
void Table_free(void *table_vptr) {
   Table_t *table = (Table_t *)table_vptr;
   Column_freeList(table->columns);
   free(table->name);
   free(table);
}

canonical_original_code:
void Table_free(void *table_vptr) {
   struct Table_s *table = (Table_t *)table_vptr;
   Column_freeList(table->columns);
   free(table->name);
   free(table);
}

user_defined_types: struct CondComp { struct Expression_s *expr1; }

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

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: 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 ExprTerm { enum TermType t; union { char *id; struct Literal_t *val; struct ColumnReference_t *ref; struct Func f; }; }

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 }

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


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

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

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

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

original_code:
void TableReference_free(TableReference_t *tref) {
   if (!tref) {
      fprintf(stderr, "Warning: TableReference_free called on null pointer\n");
      return;
   }
   free(tref->table_name);
   if (tref->alias)
      free(tref->alias);
   free(tref);
}

canonical_original_code:
void TableReference_free(struct TableReference_s *tref) {
   if (!tref) {
      fprintf(stderr, "Warning: TableReference_free called on null pointer\n");
      return;
   }
   free(tref->table_name);
   if (tref->alias)
      free(tref->alias);
   free(tref);
}

variable_types: struct TableReference_s { char *table_name; } *


decompiled_code:
int __fastcall Table_print(__int64 a1)
{
const char **v1; // rbx
int v2; // ebp
const char *v3; // rax
const char *v4; // rax
_BYTE v6[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = *(const char ***)(a1 + 8);
printf("Table %s (\n", *(const char **)a1);
if ( v1 )
{
v2 = 9;
v3 = (const char *)typeToString(*((unsigned int *)v1 + 2), v6);
printf("\t%s %s", *v1, v3);
Constraint_printList(v1[2]);
do
{
v1 = (const char **)v1[4];
if ( !v1 )
break;
puts(",");
v4 = (const char *)typeToString(*((unsigned int *)v1 + 2), v6);
printf("\t%s %s", *v1, v4);
Constraint_printList(v1[2]);
--v2;
}
while ( v2 );
}
return puts("\n)");
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
const char **v1; // rbx
int v2; // ebp
const char *v3; // rax
const char *v4; // rax
_BYTE v6[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = *(const char ***)(a1 + 8);
printf("Table %s (\n", *(const char **)a1);
if ( v1 )
{
v2 = 9;
v3 = (const char *)typeToString(*((unsigned int *)v1 + 2), v6);
printf("\t%s %s", *v1, v3);
Constraint_printList(v1[2]);
do
{
v1 = (const char **)v1[4];
if ( !v1 )
break;
puts(",");
v4 = (const char *)typeToString(*((unsigned int *)v1 + 2), v6);
printf("\t%s %s", *v1, v4);
Constraint_printList(v1[2]);
--v2;
}
while ( v2 );
}
return puts("\n)");
}

original_code:
void Table_print(Table_t *table) {
   Column_t *col = table->columns;
   int first = 1, count = 0;
   char buf[100];
   printf("Table %s (\n", table->name);
   for (; col; col = col->next) {
      if (first) first = 0; else printf(",\n");
      printf("\t%s %s", col->name, typeToString(col->type, buf));
      Constraint_printList(col->constraints);
      if (++count == 10) break;
   }
   printf("\n)\n");
}

canonical_original_code:
void Table_print(struct Table_s *table) {
   struct Column_t *col = table->columns;
   int first = 1; int count = 0;
   char buf[100];
   printf("Table %s (\n", table->name);
   for (; col; col = col->next) {
      if (first) first = 0; else printf(",\n");
      printf("\t%s %s", col->name, typeToString(col->type, buf));
      Constraint_printList(col->constraints);
      if (++count == 10) break;
   }
   printf("\n)\n");
}

variable_types: count int

variable_types:
buf
char [100]

user_defined_types: struct Table_s { char *name; struct Column_t *columns; }

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: struct Constraint_t { enum constraint_type t; union { struct ForeignKeyRef_t ref; struct Literal_t *default_val; unsigned int size; struct Condition_t *check; } constraint; struct Constraint_t *next; }

user_defined_types: enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 }

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

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


decompiled_code:
__int64 __fastcall KeyDec_append(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 32) = a2;
return a1;
}

original_code:
KeyDec_t *KeyDec_append(KeyDec_t *decs, KeyDec_t *dec) {
   decs->next = dec;
   return decs;
}

canonical_original_code:
struct KeyDec_s *KeyDec_append(struct KeyDec_s *decs, struct KeyDec_s *dec) {
   decs->next = dec;
   return decs;
}

variable_types:
decs
struct KeyDec_s *

variable_types:
dec
struct KeyDec_s *

return_type: struct KeyDec_s { enum key_dec_type { KEY_DEC_PRIMARY=0, KEY_DEC_FOREIGN=1 } t; union { struct StrList_t { char *str; struct StrList_t *next; } *primary_keys; struct ForeignKeyRef_t { char *col_name; } fkey; } dec; struct KeyDec_s *next; } *

user_defined_types: struct KeyDec_s { enum key_dec_type t; union { struct StrList_t *primary_keys; struct ForeignKeyRef_t fkey; } dec; struct KeyDec_s *next; }


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

original_code:
Index_t *Index_makeUnique(Index_t *idx) {
   idx->unique = 1;
   return idx;
}

canonical_original_code:
struct Index_s *Index_makeUnique(struct Index_s *idx) {
   idx->unique = 1;
   return idx;
}

variable_types:
idx
struct Index_s *

return_type: struct Index_s { char *name; int unique; } *


decompiled_code:
int __fastcall Index_print(__int64 a1)
{
printf("Index '%s' on %s (%s)", *(const char **)(a1 + 16), *(const char **)(a1 + 8), *(const char **)(a1 + 16));
if ( *(_DWORD *)(a1 + 24) )
printf(", unique");
return puts(&byte_69A);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
printf("Index '%s' on %s (%s)", *(const char **)(a1 + 16), *(const char **)(a1 + 8), *(const char **)(a1 + 16));
if ( *(_DWORD *)(a1 + 24) )
printf(", unique");
return puts(&byte_69A);
}

original_code:
void Index_print(Index_t *idx) {
   printf("Index '%s' on %s (%s)", idx->column_name,
                                     idx->table_name,
                                     idx->column_name);
   if (idx->unique) printf(", unique");
   puts("");
}

canonical_original_code:
void Index_print(struct Index_s *idx) {
   printf("Index '%s' on %s (%s)", idx->column_name,
                                     idx->table_name,
                                     idx->column_name);
   if (idx->unique) printf(", unique");
   puts("");
}

variable_types: struct Index_s { char *name; int unique; } *


decompiled_code:
void __fastcall Index_free(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Index_free(Index_t *idx) {
   free(idx->name);
   free(idx->column_name);
   free(idx->table_name);
   free(idx);
}

canonical_original_code:
void Index_free(struct Index_s *idx) {
   free(idx->name);
   free(idx->column_name);
   free(idx->table_name);
   free(idx);
}

user_defined_types: struct Index_s { char *name; int unique; }


decompiled_code:
int __fastcall Create_print(int *a1)
{
int v1; // eax
__int64 v2; // rdi
int result; // eax

v1 = *a1;
v2 = *((_QWORD *)a1 + 1);
if ( v1 )
result = Index_print(v2);
else
result = Table_print(v2);
return result;
}

canonical_decompiled_code:
int __fastcall func13(int *a1)
{
int v1; // eax
__int64 v2; // rdi
int result; // eax

v1 = *a1;
v2 = *((_QWORD *)a1 + 1);
if ( v1 )
result = func11(v2);
else
result = func8(v2);
return result;
}

original_code:
void Create_print(Create_t *cre) {
   if (cre->t == CREATE_TABLE)
      Table_print(cre->table);
   else
      Index_print(cre->index);
}

canonical_original_code:
void Create_print(struct Create_s *cre) {
   if (cre->t == CREATE_TABLE)
      Table_print(cre->table);
   else
      Index_print(cre->index);
}

variable_types: struct Create_s { enum CreateType { CREATE_TABLE=0, CREATE_INDEX=1 } t; union { struct Table_s { char *name; struct Column_t { char *name; enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } type; struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; 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; } *default_val; unsigned int size; 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 *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; } *check; } constraint; struct Constraint_t *next; } *constraints; unsigned long offset; struct Column_t *next; } *columns; } *table; struct Index_s { char *name; int unique; } *index; }; } *

user_defined_types: struct Create_s { enum CreateType t; union { struct Table_s *table; struct Index_s *index; }; }

user_defined_types: struct CondComp { struct Expression_s *expr1; }


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

v2 = (void *)*((_QWORD *)ptr + 1);
if ( *(_DWORD *)ptr )
Index_free(v2);
else
Table_free(v2);
free(ptr);
}

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

v2 = (void *)*((_QWORD *)ptr + 1);
if ( *(_DWORD *)ptr )
func12(v2);
else
func6(v2);
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 ForeignKeyRef_t { char *col_name; }

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

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: 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: 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 ColumnReference_t { char *tableName; }

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


decompiled_code:
__int64 __fastcall app_exp(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 40) = a2;
return a1;
}

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 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, __int64 a3, int a4, int a5, int a6)
{
unsigned int v6; // edx
unsigned int *v7; // rbx
int result; // eax
const char *v9; // rsi

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

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

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

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 }

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


decompiled_code:
__int64 __fastcall Expression_type(_DWORD *a1)
{
_DWORD *v1; // rbx
int v2; // eax
int v3; // ebp
__int64 result; // rax
__int64 v5; // rdx
int v6; // ecx
int v7; // er8
int v8; // er9
__int64 v9; // rdx
int v10; // ecx
int v11; // er8
int v12; // er9

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

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
_DWORD *v1; // rbx
int v2; // eax
int v3; // ebp
__int64 result; // rax
__int64 v5; // rdx
int v6; // ecx
int v7; // er8
int v8; // er9
__int64 v9; // rdx
int v10; // ecx
int v11; // er8
int v12; // er9

v1 = a1;
v2 = *a1;
if ( !*a1 )
return (unsigned int)v1[2];
while ( v2 == 6 )
{
v1 = (_DWORD *)*((_QWORD *)v1 + 1);
v2 = *v1;
if ( !*v1 )
return (unsigned int)v1[2];
}
v3 = func3(*((_QWORD *)v1 + 1));
result = func3(*((_QWORD *)v1 + 2));
if ( v3 != (_DWORD)result )
{
fwrite("Type mismatch on binary expression:\n", 1uLL, 0x24uLL, stderr);
func2(*((unsigned int **)v1 + 1), 1LL, v5, v6, v7, v8);
fwrite("\nis not the same type as\n", 1uLL, 0x19uLL, stderr);
func2(*((unsigned int **)v1 + 2), 1LL, v9, v10, v11, v12);
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)
{
const char *v9; // rsi
int result; // eax
__int64 v11; // rdx
int v12; // ecx
int v13; // er8
int v14; // er9

switch ( a7 )
{
case 0:
result = Literal_print(a8);
break;
case 1:
v9 = (const char *)a8;
goto LABEL_5;
case 2:
result = printf("NULL");
break;
case 3:
if ( *a8 )
printf("%s.", *a8);
v9 = a8[1];
LABEL_5:
result = printf("%s", v9);
break;
case 4:
switch ( (int)a8 )
{
case 0:
printf("MAX(");
goto LABEL_13;
case 1:
printf("MIN(");
goto LABEL_13;
case 2:
printf("COUNT(");
goto LABEL_13;
case 3:
printf("AVG(");
goto LABEL_13;
case 4:
printf("SUM(");
LABEL_13:
Expression_print(a9, a2, v11, v12, v13, v14);
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)
{
const char *v9; // rsi
int result; // eax
__int64 v11; // rdx
int v12; // ecx
int v13; // er8
int v14; // er9

switch ( a7 )
{
case 0:
result = Literal_print(a8);
break;
case 1:
v9 = (const char *)a8;
goto LABEL_5;
case 2:
result = printf("NULL");
break;
case 3:
if ( *a8 )
printf("%s.", *a8);
v9 = a8[1];
LABEL_5:
result = printf("%s", v9);
break;
case 4:
switch ( (int)a8 )
{
case 0:
printf("MAX(");
goto LABEL_13;
case 1:
printf("MIN(");
goto LABEL_13;
case 2:
printf("COUNT(");
goto LABEL_13;
case 3:
printf("AVG(");
goto LABEL_13;
case 4:
printf("SUM(");
LABEL_13:
func2(a9, a2, v11, v12, v13, v14);
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 v2; // rax

if ( !a1 )
return a2;
v2 = append_expression(*(_QWORD *)(a1 + 40));
return app_exp(a1, v2);
}

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

if ( !a1 )
return a2;
v2 = func5(*(_QWORD *)(a1 + 40));
return func0(a1, v2);
}

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
__int64 v3; // rdx
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
__int64 v3; // rdx
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 v6; // rsi
void *v8; // rdi

v6 = *(unsigned int *)ptr;
if ( (unsigned int)v6 > 5 )
{
if ( (_DWORD)v6 == 6 )
Expression_free(*((void **)ptr + 1));
else
printf("Can't delete unknown expression type '%d')", v6);
}
else if ( (_DWORD)v6 )
{
Expression_free(*((void **)ptr + 1));
Expression_free(*((void **)ptr + 2));
}
else
{
Term_free((int)ptr, 0, a3, a4, a5, a6, *((_QWORD *)ptr + 1), *((void **)ptr + 2), *((void **)ptr + 3));
}
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 v6; // rsi
void *v8; // rdi

v6 = *(unsigned int *)ptr;
if ( (unsigned int)v6 > 5 )
{
if ( (_DWORD)v6 == 6 )
func8(*((void **)ptr + 1));
else
printf("Can't delete unknown expression type '%d')", v6);
}
else if ( (_DWORD)v6 )
{
func8(*((void **)ptr + 1));
func8(*((void **)ptr + 2));
}
else
{
func9((int)ptr, 0, a3, a4, a5, a6, *((_QWORD *)ptr + 1), *((void **)ptr + 2), *((void **)ptr + 3));
}
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_3;
default:
LABEL_3:
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_3;
default:
LABEL_3:
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 )
return puts(&s);
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 )
return puts(&s);
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: 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: 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: union LitVal { int ival; double dval; char cval; char *strval; }


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

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: enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 }


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 CondComp { struct Expression_s *expr1; }

user_defined_types: struct CondBinary { struct Condition_t *cond1; }