decompiled_code:
__int64 __fastcall list_channels(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned __int8 v3; // r15
int v4; // er13
unsigned __int8 v5; // bl
int v6; // er13
int v7; // ebp
unsigned __int8 v8; // si
unsigned __int8 v9; // r12
int v10; // er13
__int64 result; // rax
__int16 v12; // ax
int v13; // er14
unsigned __int8 v14; // [rsp+Bh] [rbp-203Dh]
char v16; // [rsp+10h] [rbp-2038h] BYREF
unsigned __int8 v17; // [rsp+11h] [rbp-2037h]
unsigned __int8 v18; // [rsp+12h] [rbp-2036h]
unsigned __int8 v19; // [rsp+17h] [rbp-2031h]
char s[4152]; // [rsp+1010h] [rbp-1038h] BYREF

snprintf(s, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
puts("Channels on this mutiplex:\n");
puts("ID\tChannel");
puts("==\t=======");
v3 = 0;
do
{
if ( !(unsigned __int8)read_sdt(s, a3, &v16, v3) )
fatal("Unable to read SDT");
v14 = v19;
result = v18;
v13 = (unsigned __int16)(((v17 << 8) & 0xF00) + v18 + 3) - 4;
if ( v13 > 11 )
{
v6 = 11;
LODWORD(result) = 11;
do
{
printf(
"%u\t",
(unsigned __int16)((unsigned __int8)*(&v16 + (int)result + 1) + ((unsigned __int8)*(&v16 + (int)result) << 8)));
v7 = (unsigned __int8)*(&v16 + (unsigned __int16)(v6 + 3)) << 8;
LOWORD(v7) = ((unsigned __int8)*(&v16 + (unsigned __int16)(v6 + 3)) << 8) & 0xF00;
v12 = *(&v17 + (unsigned __int16)(v6 + 3));
v6 += 5;
for ( LOWORD(v7) = v12 + v7; (_WORD)v7; LOWORD(v7) = v7 - 2 )
{
v8 = *(&v16 + (unsigned __int16)v6);
v9 = *(&v17 + (unsigned __int16)v6);
if ( v8 == 72 )
{
v4 = (unsigned __int8)*(&v16 + (unsigned __int16)(v6 + 3)) + v6 + 3;
v5 = *(&v16 + (unsigned __int16)(v4 + 1));
v4 += 2;
printf("%.*s\n", v5, &v16 + (unsigned __int16)v4);
v6 = v5 + v4;
}
else
{
v10 = v6 + 2;
vverbose("desc_tag: %u", v8);
vhexdump(&v16 + (unsigned __int16)v10, v9);
v6 = v9 + v10;
}
v7 -= v9;
}
result = (unsigned __int16)v6;
}
while ( (unsigned __int16)v6 < v13 );
}
++v3;
}
while ( v14 >= v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned __int8 v3; // r15
int v4; // er13
unsigned __int8 v5; // bl
int v6; // er13
int v7; // ebp
unsigned __int8 v8; // si
unsigned __int8 v9; // r12
int v10; // er13
__int64 result; // rax
__int16 v12; // ax
int v13; // er14
unsigned __int8 v14; // [rsp+Bh] [rbp-203Dh]
char v16; // [rsp+10h] [rbp-2038h] BYREF
unsigned __int8 v17; // [rsp+11h] [rbp-2037h]
unsigned __int8 v18; // [rsp+12h] [rbp-2036h]
unsigned __int8 v19; // [rsp+17h] [rbp-2031h]
char s[4152]; // [rsp+1010h] [rbp-1038h] BYREF

snprintf(s, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
puts("Channels on this mutiplex:\n");
puts("ID\tChannel");
puts("==\t=======");
v3 = 0;
do
{
if ( !(unsigned __int8)read_sdt(s, a3, &v16, v3) )
fatal("Unable to read SDT");
v14 = v19;
result = v18;
v13 = (unsigned __int16)(((v17 << 8) & 0xF00) + v18 + 3) - 4;
if ( v13 > 11 )
{
v6 = 11;
LODWORD(result) = 11;
do
{
printf(
"%u\t",
(unsigned __int16)((unsigned __int8)*(&v16 + (int)result + 1) + ((unsigned __int8)*(&v16 + (int)result) << 8)));
v7 = (unsigned __int8)*(&v16 + (unsigned __int16)(v6 + 3)) << 8;
LOWORD(v7) = ((unsigned __int8)*(&v16 + (unsigned __int16)(v6 + 3)) << 8) & 0xF00;
v12 = *(&v17 + (unsigned __int16)(v6 + 3));
v6 += 5;
for ( LOWORD(v7) = v12 + v7; (_WORD)v7; LOWORD(v7) = v7 - 2 )
{
v8 = *(&v16 + (unsigned __int16)v6);
v9 = *(&v17 + (unsigned __int16)v6);
if ( v8 == 72 )
{
v4 = (unsigned __int8)*(&v16 + (unsigned __int16)(v6 + 3)) + v6 + 3;
v5 = *(&v16 + (unsigned __int16)(v4 + 1));
v4 += 2;
printf("%.*s\n", v5, &v16 + (unsigned __int16)v4);
v6 = v5 + v4;
}
else
{
v10 = v6 + 2;
vverbose("desc_tag: %u", v8);
vhexdump(&v16 + (unsigned __int16)v10, v9);
v6 = v9 + v10;
}
v7 -= v9;
}
result = (unsigned __int16)v6;
}
while ( (unsigned __int16)v6 < v13 );
}
++v3;
}
while ( v14 >= v3 );
return result;
}

original_code:
void
list_channels(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 uint16_t size;
 uint16_t offset;
 uint16_t service_id;
 uint16_t desc_loop_length;
 uint8_t desc_tag;
 uint8_t desc_length;
 uint8_t name_len;
 uint8_t sn, lsn;
 snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 printf("Channels on this mutiplex:\n\n");
 printf("ID\tChannel\n");
 printf("==\t=======\n");
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn))
   fatal("Unable to read SDT");
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
   printf("%u\t", service_id);
   offset += 3;
   desc_loop_length = ((sdt[offset] & 0x0f) << 8) + sdt[offset+1];
   offset += 2;
   while(desc_loop_length != 0)
   {
    desc_tag = sdt[offset];
    desc_length = sdt[offset+1];
    offset += 2;
    desc_loop_length -= 2;
    if(desc_tag == 0x48)
    {
     offset += 1;
     name_len = sdt[offset];
     offset += 1 + name_len;
     name_len = sdt[offset];
     offset += 1;
     printf("%.*s\n", name_len, &sdt[offset]);
     offset += name_len;
    }
    else
    {
     vverbose("desc_tag: %u", desc_tag);
     vhexdump(&sdt[offset], desc_length);
     offset += desc_length;
    }
    desc_loop_length -= desc_length;
   }
  }
 }
 return;
}

canonical_original_code:
void list_channels(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 unsigned short size;
 unsigned short offset;
 unsigned short service_id;
 unsigned short desc_loop_length;
 unsigned char desc_tag;
 unsigned char desc_length;
 unsigned char name_len;
 unsigned char sn; unsigned char lsn;
 snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 printf("Channels on this mutiplex:\n\n");
 printf("ID\tChannel\n");
 printf("==\t=======\n");
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn))
   fatal("Unable to read SDT");
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
   printf("%u\t", service_id);
   offset += 3;
   desc_loop_length = ((sdt[offset] & 0x0f) << 8) + sdt[offset+1];
   offset += 2;
   while(desc_loop_length != 0)
   {
    desc_tag = sdt[offset];
    desc_length = sdt[offset+1];
    offset += 2;
    desc_loop_length -= 2;
    if(desc_tag == 0x48)
    {
     offset += 1;
     name_len = sdt[offset];
     offset += 1 + name_len;
     name_len = sdt[offset];
     offset += 1;
     printf("%.*s\n", name_len, &sdt[offset]);
     offset += name_len;
    }
    else
    {
     vverbose("desc_tag: %u", desc_tag);
     vhexdump(&sdt[offset], desc_length);
     offset += desc_length;
    }
    desc_loop_length -= desc_length;
   }
  }
 }
 return;
}

variable_types:
adapter
unsigned int

variable_types:
demux
unsigned int

variable_types:
timeout
unsigned int

variable_types:
sdt
unsigned char [4096]

variable_types:
size
unsigned short

variable_types:
offset
unsigned short

variable_types:
sn
unsigned char

variable_types:
lsn
unsigned char


repo: thiakil/rb-download

decompiled_code:
__int64 __fastcall get_first_service_id(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned __int8 v4; // r12
const char *v5; // rdx
unsigned __int16 v6; // bp
unsigned __int8 v7; // r14
unsigned int v8; // ebx
_BYTE v10[11]; // [rsp+0h] [rbp-2028h] BYREF
unsigned __int8 v11; // [rsp+Bh] [rbp-201Dh]
unsigned __int8 v12; // [rsp+Ch] [rbp-201Ch]
char s[4136]; // [rsp+1000h] [rbp-1028h] BYREF

snprintf(s, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
v4 = 0;
do
{
if ( !(unsigned __int8)read_sdt(s, a3, v10, v4) )
{
error((int)"Unable to read SDT", a3, v5);
return 0;
}
v6 = ((v10[1] << 8) & 0xF00) + v10[2] + 3;
v7 = v10[7];
while ( v6 > 0xFu )
{
v8 = v12 + (v11 << 8);
fprintf(stderr, "%d\n", (unsigned __int16)(v12 + (v11 << 8)));
if ( (_WORD)v8 )
return v8;
}
++v4;
}
while ( v7 >= v4 );
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned __int8 v4; // r12
const char *v5; // rdx
unsigned __int16 v6; // bp
unsigned __int8 v7; // r14
unsigned int v8; // ebx
_BYTE v10[11]; // [rsp+0h] [rbp-2028h] BYREF
unsigned __int8 v11; // [rsp+Bh] [rbp-201Dh]
unsigned __int8 v12; // [rsp+Ch] [rbp-201Ch]
char s[4136]; // [rsp+1000h] [rbp-1028h] BYREF

snprintf(s, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
v4 = 0;
do
{
if ( !(unsigned __int8)read_sdt(s, a3, v10, v4) )
{
error((int)"Unable to read SDT", a3, v5);
return 0;
}
v6 = ((v10[1] << 8) & 0xF00) + v10[2] + 3;
v7 = v10[7];
while ( v6 > 0xFu )
{
v8 = v12 + (v11 << 8);
fprintf(stderr, "%d\n", (unsigned __int16)(v12 + (v11 << 8)));
if ( (_WORD)v8 )
return v8;
}
++v4;
}
while ( v7 >= v4 );
return 0;
}

original_code:
uint16_t
get_first_service_id(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 uint16_t size;
 uint16_t offset;
 uint16_t service_id;
 uint8_t sn, lsn;
  snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn)){
   error("Unable to read SDT");
   return 0;
  }
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
      fprintf(stderr, "%d\n", service_id);
      if (service_id > 0)
        return service_id;
    }
  }
  return 0;
}

canonical_original_code:
unsigned short get_first_service_id(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 unsigned short size;
 unsigned short offset;
 unsigned short service_id;
 unsigned char sn; unsigned char lsn;
  snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn)){
   error("Unable to read SDT");
   return 0;
  }
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
      fprintf(stderr, "%d\n", service_id);
      if (service_id > 0)
        return service_id;
    }
  }
  return 0;
}

return_type: unsigned short


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

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

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

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

original_code:
static Literal_t *Literal_app(Literal_t *lit1, Literal_t *lit2) {
   lit1->next = lit2;
   return lit1;
}

canonical_original_code:
static struct Literal_t *Literal_app(struct Literal_t *lit1, struct Literal_t *lit2) {
   lit1->next = lit2;
   return lit1;
}

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

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


litDouble

decompiled_code:
double *__fastcall litDouble(double a1)
{
double *result; // rax

result = (double *)calloc(1uLL, 0x18uLL);
*(_DWORD *)result = 1;
result[1] = a1;
return result;
}

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

result = (double *)calloc(1uLL, 0x18uLL);
*(_DWORD *)result = 1;
result[1] = a1;
return result;
}

original_code:
Literal_t *litDouble(double d) {
   Literal_t *lval = (Literal_t *)calloc(1, sizeof(Literal_t));
   lval->t = TYPE_DOUBLE;
   lval->val.dval = d;
   return lval;
}

canonical_original_code:
struct Literal_t *litDouble(double d) {
   struct Literal_t *lval = (Literal_t *)calloc(1, sizeof(Literal_t));
   lval->t = TYPE_DOUBLE;
   lval->val.dval = d;
   return lval;
}

variable_types: d double

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


decompiled_code:
int __fastcall Literal_print(unsigned int *a1)
{
const char *v1; // rax
unsigned int v2; // eax
int result; // eax
__int64 v4; // [rsp+0h] [rbp-78h] BYREF

v1 = (const char *)typeToString(*a1, &v4);
printf("%s ", v1);
v2 = *a1;
if ( *a1 == 2 )
return printf("'%c'", (unsigned int)*((char *)a1 + 8));
if ( v2 > 2 )
{
if ( v2 == 3 )
result = printf("\"%s\"", *((const char **)a1 + 1));
else
result = printf("(unknown type)");
}
else if ( v2 )
{
result = printf("%f", *((double *)a1 + 1));
}
else
{
result = printf("%d", a1[2]);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1)
{
const char *v1; // rax
unsigned int v2; // eax
int result; // eax
__int64 v4; // [rsp+0h] [rbp-78h] BYREF

v1 = (const char *)typeToString(*a1, &v4);
printf("%s ", v1);
v2 = *a1;
if ( *a1 == 2 )
return printf("'%c'", (unsigned int)*((char *)a1 + 8));
if ( v2 > 2 )
{
if ( v2 == 3 )
result = printf("\"%s\"", *((const char **)a1 + 1));
else
result = printf("(unknown type)");
}
else if ( v2 )
{
result = printf("%f", *((double *)a1 + 1));
}
else
{
result = printf("%d", a1[2]);
}
return result;
}

original_code:
void Literal_print(Literal_t *val) {
   char buf[100];
   printf("%s ", typeToString(val->t, buf));
   switch (val->t) {
      case TYPE_INT:
         printf("%d", val->val.ival);
         break;
      case TYPE_DOUBLE:
         printf("%f", val->val.dval);
         break;
      case TYPE_CHAR:
         printf("'%c'", val->val.cval);
         break;
      case TYPE_TEXT:
         printf("\"%s\"", val->val.strval);
         break;
      default:
         printf("(unknown type)");
   }
}

canonical_original_code:
void Literal_print(struct Literal_t *val) {
   char buf[100];
   printf("%s ", typeToString(val->t, buf));
   switch (val->t) {
      case TYPE_INT:
         printf("%d", val->val.ival);
         break;
      case TYPE_DOUBLE:
         printf("%f", val->val.dval);
         break;
      case TYPE_CHAR:
         printf("'%c'", val->val.cval);
         break;
      case TYPE_TEXT:
         printf("\"%s\"", val->val.strval);
         break;
      default:
         printf("(unknown type)");
   }
}

variable_types:
buf
char [100]

return_type: void

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


decompiled_code:
int __fastcall Literal_printList(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
Literal_print((unsigned int *)v1);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
func2((unsigned int *)v1);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

original_code:
void Literal_printList(Literal_t *val_list) {
   int first = 1;
   printf("[");
   while (val_list) {
      if (first) first = 0; else printf(", ");
      Literal_print(val_list);
      val_list = val_list->next;
   }
   printf("]");
}

canonical_original_code:
void Literal_printList(struct Literal_t *val_list) {
   int first = 1;
   printf("[");
   while (val_list) {
      if (first) first = 0; else printf(", ");
      Literal_print(val_list);
      val_list = val_list->next;
   }
   printf("]");
}

variable_types: first int


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

result = a2;
if ( a1 )
{
v3 = Literal_append(*(_QWORD *)(a1 + 16));
result = Literal_app(a1, v3);
}
return result;
}

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

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

original_code:
Literal_t *Literal_append(Literal_t *lit1, Literal_t *lit2) {
   if (!lit1) return lit2;
   return Literal_app(lit1, Literal_append(lit1->next, lit2));
}

canonical_original_code:
struct Literal_t *Literal_append(struct Literal_t *lit1, struct Literal_t *lit2) {
   if (!lit1) return lit2;
   return Literal_app(lit1, Literal_append(lit1->next, lit2));
}


decompiled_code:
void __fastcall Literal_free(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Literal_free(Literal_t *lval) {
   if (lval->t == TYPE_TEXT)
      free(lval->val.strval);
   free(lval);
}

canonical_original_code:
void Literal_free(struct Literal_t *lval) {
   if (lval->t == TYPE_TEXT)
      free(lval->val.strval);
   free(lval);
}


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

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

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

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

original_code:
void Literal_freeList(Literal_t *lval) {
   Literal_t *temp;
   while (lval) {
      temp = lval;
      lval = lval->next;
      free(temp);
   }
}

canonical_original_code:
void Literal_freeList(struct Literal_t *lval) {
   struct Literal_t *temp;
   while (lval) {
      temp = lval;
      lval = lval->next;
      free(temp);
   }
}


decompiled_code:
void __fastcall vector_resize(_QWORD *a1, unsigned __int64 a2)
{
size_t i; // rbx
void *v3; // r12
void *v4; // r13

if ( a2 <= 1 )
{
i = 1LL;
}
else
{
for ( i = 1LL; i < a2; i *= 2LL )
;
}
v3 = calloc(i, 8uLL);
v4 = (void *)a1[2];
memcpy(v3, v4, 8LL * *a1);
free(v4);
a1[2] = v3;
a1[1] = i;
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, unsigned __int64 a2)
{
size_t i; // rbx
void *v3; // r12
void *v4; // r13

if ( a2 <= 1 )
{
i = 1LL;
}
else
{
for ( i = 1LL; i < a2; i *= 2LL )
;
}
v3 = calloc(i, 8uLL);
v4 = (void *)a1[2];
memcpy(v3, v4, 8LL * *a1);
free(v4);
a1[2] = v3;
a1[1] = i;
}

original_code:
static void vector_resize(vector_t *vec, size_t new_size) {
   size_t max_size = 1;
   while (max_size < new_size)
      max_size *= 2;
   void **temp = (void **)calloc(max_size, sizeof(void *));
   memcpy(temp, vec->data, vec->size * sizeof(void *));
   free(vec->data);
   vec->data = temp;
   vec->max_size = max_size;
}

canonical_original_code:
static void vector_resize(struct vector_s *vec, unsigned long new_size) {
   unsigned long max_size = 1;
   while (max_size < new_size)
      max_size *= 2;
   void **temp = (void **)calloc(max_size, sizeof(void *));
   memcpy(temp, vec->data, vec->size * sizeof(void *));
   free(vec->data);
   vec->data = temp;
   vec->max_size = max_size;
}

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

variable_types:
temp
void **


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

if ( *a1 <= a2 )
{
LODWORD(v3) = fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", a2);
}
else
{
v3 = a1[2];
*(_QWORD *)(v3 + 8 * a2) = a3;
}
return v3;
}

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

if ( *a1 <= a2 )
{
LODWORD(v3) = fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", a2);
}
else
{
v3 = a1[2];
*(_QWORD *)(v3 + 8 * a2) = a3;
}
return v3;
}

original_code:
void vector_setAt(vector_t *vector, size_t i, void *data) {
   if (i < vector->size)
      vector->data[i] = data;
   else
      fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", i);
}

canonical_original_code:
void vector_setAt(struct vector_s *vector, unsigned long i, void *data) {
   if (i < vector->size)
      vector->data[i] = data;
   else
      fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", i);
}

variable_types:
i
unsigned long

variable_types:
data
void *

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


decompiled_code:
__int64 __fastcall vector_pop(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdx
unsigned __int64 v2; // rax
__int64 v3; // rbx
unsigned __int64 v4; // rsi

v1 = a1[2];
v2 = *a1 - 1;
*a1 = v2;
v3 = *(_QWORD *)(v1 + 8 * v2);
v4 = a1[1] >> 1;
if ( v2 <= v4 )
vector_resize(a1, v4);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdx
unsigned __int64 v2; // rax
__int64 v3; // rbx
unsigned __int64 v4; // rsi

v1 = a1[2];
v2 = *a1 - 1;
*a1 = v2;
v3 = *(_QWORD *)(v1 + 8 * v2);
v4 = a1[1] >> 1;
if ( v2 <= v4 )
func0(a1, v4);
return v3;
}

original_code:
void *vector_pop(vector_t *vec) {
   void *ret = vec->data[--vec->size];
   if (vec->size <= (vec->max_size)/2)
      vector_resize(vec, (vec->max_size)/2);
   return ret;
}

canonical_original_code:
void *vector_pop(struct vector_s *vec) {
   void *ret = vec->data[--vec->size];
   if (vec->size <= (vec->max_size)/2)
      vector_resize(vec, (vec->max_size)/2);
   return ret;
}

variable_types:
ret
void *

return_type: void *


decompiled_code:
__int64 __fastcall vector_getAt(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 > a2 )
return *(_QWORD *)(a1[2] + 8 * a2);
fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 > a2 )
return *(_QWORD *)(a1[2] + 8 * a2);
fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", a2);
return 0LL;
}

original_code:
void *vector_getAt(vector_t *vec, size_t i) {
   if (i < vec->size)
      return vec->data[i];
   fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", i);
   return ((void *)0);
}

canonical_original_code:
void *vector_getAt(struct vector_s *vec, unsigned long i) {
   if (i < vec->size)
      return vec->data[i];
   fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", i);
   return ((void *)0);
}


decompiled_code:
__int64 __fastcall vector_size(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
size_t vector_size(vector_t *vector) {
   return vector->size;
}

canonical_original_code:
unsigned long vector_size(struct vector_s *vector) {
   return vector->size;
}

return_type: unsigned long


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

if ( *a1 )
{
v2 = 0LL;
do
result = a2(*(_QWORD *)(a1[2] + 8 * v2++));
while ( *a1 > v2 );
}
return result;
}

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

if ( *a1 )
{
v2 = 0LL;
do
result = a2(*(_QWORD *)(a1[2] + 8 * v2++));
while ( *a1 > v2 );
}
return result;
}

original_code:
void vector_print(vector_t *vector, void (*print) (void *)) {
   size_t i;
   for (i=0; i<vector->size; ++i) {
      print(vector->data[i]);
   }
}

canonical_original_code:
void vector_print(struct vector_s *vector, void (*print)(void *)) {
   unsigned long i;
   for (i=0; i<vector->size; ++i) {
      print(vector->data[i]);
   }
}

variable_types:
print
void (*)(void *)


decompiled_code:
int __fastcall vector_printStrings(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
const char *v2; // rax

printf("string_vec[");
v1 = 0LL;
if ( *a1 )
{
while ( 1 )
{
v2 = (const char *)vector_getAt(a1, v1);
printf("%s", v2);
if ( *a1 <= ++v1 )
break;
if ( v1 )
printf(", ");
}
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
const char *v2; // rax

printf("string_vec[");
v1 = 0LL;
if ( *a1 )
{
while ( 1 )
{
v2 = (const char *)func4(a1, v1);
printf("%s", v2);
if ( *a1 <= ++v1 )
break;
if ( v1 )
printf(", ");
}
}
return puts("]");
}

original_code:
void vector_printStrings(vector_t *vector) {
   size_t i;
   printf("string_vec[");
   for (i=0; i<vector->size; ++i) {
      if (i != 0) printf(", ");
      printf("%s", (char *)vector_getAt(vector, i));
   }
   printf("]\n");
}

canonical_original_code:
void vector_printStrings(struct vector_s *vector) {
   unsigned long i;
   printf("string_vec[");
   for (i=0; i<vector->size; ++i) {
      if (i != 0) printf(", ");
      printf("%s", (char *)vector_getAt(vector, i));
   }
   printf("]\n");
}


decompiled_code:
void __fastcall vector_clear(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
void (*v2)(void); // rax

if ( a1 )
{
if ( *a1 )
{
v1 = 0LL;
do
{
if ( *(_QWORD *)(a1[2] + 8 * v1) )
{
v2 = (void (*)(void))a1[3];
if ( v2 )
v2();
}
++v1;
}
while ( *a1 > v1 );
}
*a1 = 0LL;
a1[1] = 0LL;
}
}

original_code:
void vector_clear(vector_t *vector) {
   size_t i;
   if (!vector) return;
   for (i = 0; i < vector->size; ++i) {
      if (vector->data[i] && vector->free) {
         vector->free(vector->data[i]);
      }
   }
   vector->size = 0;
   vector->max_size = 0;
}

canonical_original_code:
void vector_clear(struct vector_s *vector) {
   unsigned long i;
   if (!vector) return;
   for (i = 0; i < vector->size; ++i) {
      if (vector->data[i] && vector->free) {
         vector->free(vector->data[i]);
      }
   }
   vector->size = 0;
   vector->max_size = 0;
}


decompiled_code:
void __fastcall vector_setDeleteFunc(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void vector_setDeleteFunc(vector_t *vector, void (*free) (void *)) {
   if (vector)
      vector->free = free;
}

canonical_original_code:
void vector_setDeleteFunc(struct vector_s *vector, void (*free)(void *)) {
   if (vector)
      vector->free = free;
}

variable_types:
free
void (*)(void *)


original_code:
char *random_str() {
   size_t size = rand() % 15, i;
   char *str = (char *)malloc(size + 6);
   sprintf(str, "%4d ", word_count++);
   for (i=5; i<size+5; ++i)
      str[i] = (rand() % 26) + 'a';
   str[i] = '\0';
   return str;
}

canonical_original_code:
char *random_str() {
   unsigned long size = rand() % 15; unsigned long i;
   char *str = (char *)malloc(size + 6);
   sprintf(str, "%4d ", word_count++);
   for (i=5; i<size+5; ++i)
      str[i] = (rand() % 26) + 'a';
   str[i] = '\0';
   return str;
}

variable_types:
size
unsigned long

variable_types:
str
char *

return_type: char *


decompiled_code:
__int64 __fastcall vec_main(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
unsigned __int64 *v8; // rbx
unsigned __int64 v9; // rbp
const char *v10; // rax
int v11; // er12
char *v12; // rbp
int v13; // ebp
const char *v14; // rax

v8 = vector_withData(3uLL, a1, a2, a3, a4, a5, a6, a7, a8, "hello", "hi", "how are you");
if ( *v8 )
{
v9 = 0LL;
do
{
v10 = (const char *)vector_getAt(v8, v9);
puts(v10);
++v9;
}
while ( *v8 > v9 );
}
v11 = 1000;
do
{
v12 = random_str();
printf("pushing %s, size is %lu, max_size %lu\n", v12, *v8, v8[1]);
vector_push(v8, (__int64)v12);
--v11;
}
while ( v11 );
printf("printing vector %lu %lu\n", *v8, v8[1]);
fflush(stdout);
v13 = 500;
do
{
v14 = (const char *)vector_pop(v8);
printf("popped %s, size is %lu, max_size %lu\n", v14, *v8, v8[1]);
--v13;
}
while ( v13 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
unsigned __int64 *v8; // rbx
unsigned __int64 v9; // rbp
const char *v10; // rax
int v11; // er12
char *v12; // rbp
int v13; // ebp
const char *v14; // rax

v8 = func1(3uLL, a1, a2, a3, a4, a5, a6, a7, a8, "hello", "hi", "how are you");
if ( *v8 )
{
v9 = 0LL;
do
{
v10 = (const char *)func4(v8, v9);
puts(v10);
++v9;
}
while ( *v8 > v9 );
}
v11 = 1000;
do
{
v12 = func10();
printf("pushing %s, size is %lu, max_size %lu\n", v12, *v8, v8[1]);
vector_push(v8, (__int64)v12);
--v11;
}
while ( v11 );
printf("printing vector %lu %lu\n", *v8, v8[1]);
fflush(stdout);
v13 = 500;
do
{
v14 = (const char *)func3(v8);
printf("popped %s, size is %lu, max_size %lu\n", v14, *v8, v8[1]);
--v13;
}
while ( v13 );
return 0LL;
}

original_code:
int vec_main(int argc, char const *argv[])
{
   vector_t *vec = vector_withData(3, "hello", "hi", "how are you");
   int i;
   for (i=0; i<vec->size; ++i)
      printf("%s\n", (char *)vector_getAt(vec, i));
   for (i=0; i<1000; ++i) {
      char *str = random_str();
      printf("pushing %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
      vector_push(vec, str);
   }
   printf("printing vector %lu %lu\n", vec->size, vec->max_size); fflush(stdout);
   for (i=0; i<500; ++i) {
      char *str = (char *)vector_pop(vec);
      printf("popped %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
   }
   return 0;
}

canonical_original_code:
int vec_main(int argc, char *argv[])
{
   struct vector_s *vec = vector_withData(3, "hello", "hi", "how are you");
   int i;
   for (i=0; i<vec->size; ++i)
      printf("%s\n", (char *)vector_getAt(vec, i));
   for (i=0; i<1000; ++i) {
      char *str = random_str();
      printf("pushing %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
      vector_push(vec, str);
   }
   printf("printing vector %lu %lu\n", vec->size, vec->max_size); fflush(stdout);
   for (i=0; i<500; ++i) {
      char *str = (char *)vector_pop(vec);
      printf("popped %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
   }
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

return_type: int


decompiled_code:
void __fastcall vector_free(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void vector_free(vector_t *vector) {
   free(vector->data);
}

canonical_original_code:
void vector_free(struct vector_s *vector) {
   free(vector->data);
}


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

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

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

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

original_code:
static StrList_t *StrList_app(StrList_t *list1, StrList_t *list2) {
   list1->next = list2;
   return list1;
}

canonical_original_code:
static struct StrList_t *StrList_app(struct StrList_t *list1, struct StrList_t *list2) {
   list1->next = list2;
   return list1;
}

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


typeToString

decompiled_code:
char *__fastcall typeToString(unsigned int a1, char *a2)
{
char *result; // rax

result = a2;
if ( a1 == 2 )
{
strcpy(a2, "char");
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
strcpy(a2, "text");
}
else if ( a1 )
{
strcpy(a2, "double");
}
else
{
*(_DWORD *)a2 = 7630441;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int a1, char *a2)
{
char *result; // rax

result = a2;
if ( a1 == 2 )
{
strcpy(a2, "char");
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
strcpy(a2, "text");
}
else if ( a1 )
{
strcpy(a2, "double");
}
else
{
*(_DWORD *)a2 = 7630441;
}
return result;
}

original_code:
char *typeToString(enum data_type type, char *buf) {
   switch (type) {
      case TYPE_INT:
         sprintf(buf, "int");
         break;
      case TYPE_DOUBLE:
         sprintf(buf, "double");
         break;
      case TYPE_CHAR:
         sprintf(buf, "char");
         break;
      case TYPE_TEXT:
         sprintf(buf, "text");
         break;
   }
   return buf;
}

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

variable_types:
buf
char *


decompiled_code:
int __fastcall StrList_print(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
printf("%s", *(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

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

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
printf("%s", *(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

original_code:
void StrList_print(StrList_t *list) {
   int first = 1;
   printf("[");
   while (list) {
      if (first) first=0; else printf(", ");
      printf("%s", list->str);
      list = list->next;
   }
   printf("]");
}

canonical_original_code:
void StrList_print(struct StrList_t *list) {
   int first = 1;
   printf("[");
   while (list) {
      if (first) first=0; else printf(", ");
      printf("%s", list->str);
      list = list->next;
   }
   printf("]");
}

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


upInd

decompiled_code:
int upInd()
{
++ind;
return putchar(10);
}

canonical_decompiled_code:
int func4()
{
++ind;
return putchar(10);
}

original_code:
void upInd() {
   ind++;
   printf("\n");
}

canonical_original_code:
void upInd() {
   ind++;
   printf("\n");
}


downInd

decompiled_code:
int downInd()
{
int result; // eax

--ind;
result = putchar(10);
if ( ind < 0 )
result = printf("error, ind is < 0");
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

--ind;
result = putchar(10);
if ( ind < 0 )
result = printf("error, ind is < 0");
return result;
}

original_code:
void downInd() {
   ind--;
   printf("\n");
   if (ind < 0) printf("error, ind is < 0");
}


decompiled_code:
int indent_print(char *format, ...)
{
int v1; // ebx
__int16 v3[2500]; // [rsp+0h] [rbp-1468h] BYREF
gcc_va_list arg; // [rsp+1388h] [rbp-E0h] BYREF

v1 = 0;
if ( ind > 0 )
{
do
{
if ( v1 )
*(__int16 *)((char *)v3 + strlen((const char *)v3)) = 9;
else
v3[0] = 9;
++v1;
}
while ( ind > v1 );
}
else
{
ind = 0;
}
va_start(arg, format);
vsnprintf((char *)v3 + ind, 0x1388uLL, format, arg);
fputs((const char *)v3, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int func6(char *format, ...)
{
int v1; // ebx
__int16 v3[2500]; // [rsp+0h] [rbp-1468h] BYREF
gcc_va_list arg; // [rsp+1388h] [rbp-E0h] BYREF

v1 = 0;
if ( ind > 0 )
{
do
{
if ( v1 )
*(__int16 *)((char *)v3 + strlen((const char *)v3)) = 9;
else
v3[0] = 9;
++v1;
}
while ( ind > v1 );
}
else
{
ind = 0;
}
va_start(arg, format);
vsnprintf((char *)v3 + ind, 0x1388uLL, format, arg);
fputs((const char *)v3, stdout);
return fflush(stdout);
}

original_code:
void indent_print(const char *format,...)
{
   int i;
   va_list argptr;
   char buffer[5000];
   if (ind < 1) ind = 0;
   for (i=0; i<ind; ++i) {
      if (i == 0)
         sprintf(buffer, "\t");
      else
         strcat(buffer, "\t");
   }
   __builtin_va_start(argptr,format);
   vsnprintf(buffer + ind, 5000, format, argptr);
   __builtin_va_end(argptr);
   fputs(buffer, stdout);
   fflush(stdout);
}

canonical_original_code:
void indent_print(char *format, ...)
{
   int i;
   __builtin_va_list argptr;
   char buffer[5000];
   if (ind < 1) ind = 0;
   for (i=0; i<ind; ++i) {
      if (i == 0)
         sprintf(buffer, "\t");
      else
         strcat(buffer, "\t");
   }
   __builtin_va_start(argptr,format);
   vsnprintf(buffer + ind, 5000, format, argptr);
   __builtin_va_end(argptr);
   fputs(buffer, stdout);
   fflush(stdout);
}

variable_types:
format
char *

variable_types:
buffer
char [5000]


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

result = a2;
if ( a1 )
{
v3 = StrList_append(*(_QWORD *)(a1 + 8));
result = StrList_app(a1, v3);
}
return result;
}

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

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

original_code:
StrList_t *StrList_append(StrList_t *list1, StrList_t *list2) {
   if (!list1) return list2;
   return StrList_app(list1, StrList_append(list1->next, list2));
}

canonical_original_code:
struct StrList_t *StrList_append(struct StrList_t *list1, struct StrList_t *list2) {
   if (!list1) return list2;
   return StrList_app(list1, StrList_append(list1->next, list2));
}

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


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

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

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

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

original_code:
static Column_t *app_col(Column_t *col1, Column_t *col2) {
   col1->next = col2;
   return col1;
}

canonical_original_code:
static struct Column_t *app_col(struct Column_t *col1, struct Column_t *col2) {
   col1->next = col2;
   return col1;
}

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 Condition_t { enum CondType t; union { struct CondComp comp; struct CondBinary binary; struct CondUnary unary; struct CondIn in; } cond; }

user_defined_types: struct CondComp { struct Expression_s *expr1; }

user_defined_types: struct 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 deleteConstraint_ts(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 32);
if ( *(_DWORD *)a1 == 4 )
{
Literal_free(*(_QWORD *)(a1 + 8));
}
else if ( *(_DWORD *)a1 == 6 )
{
Condition_free(*(_QWORD *)(a1 + 8));
}
deleteConstraint_ts(v1);
}
}

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

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 32);
if ( *(_DWORD *)a1 == 4 )
{
Literal_free(*(_QWORD *)(a1 + 8));
}
else if ( *(_DWORD *)a1 == 6 )
{
Condition_free(*(_QWORD *)(a1 + 8));
}
func1(v1);
}
}

original_code:
static void deleteConstraint_ts(Constraint_t *constraint) {
   if (constraint) {
      Constraint_t *next = constraint->next;
      switch (constraint->t) {
         case CONS_DEFAULT:
            Literal_free(constraint->constraint.default_val);
            break;
         case CONS_CHECK:
            Condition_free(constraint->constraint.check);
            break;
         default:
            break;
      }
      deleteConstraint_ts(next);
   }
}

canonical_original_code:
static void deleteConstraint_ts(struct Constraint_t *constraint) {
   if (constraint) {
      struct Constraint_t *next = constraint->next;
      switch (constraint->t) {
         case CONS_DEFAULT:
            Literal_free(constraint->constraint.default_val);
            break;
         case CONS_CHECK:
            Condition_free(constraint->constraint.check);
            break;
         default:
            break;
      }
      deleteConstraint_ts(next);
   }
}

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


NotNull

decompiled_code:
void *NotNull()
{
return calloc(1uLL, 0x28uLL);
}

canonical_decompiled_code:
void *func2()
{
return calloc(1uLL, 0x28uLL);
}

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

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

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


AutoIncrement

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

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

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

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

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

canonical_original_code:
struct Constraint_t *AutoIncrement() {
   struct Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_AUTO_INCREMENT;
   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 ForeignKeyRef_t { char *col_name; }

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 }


PrimaryKey

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

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

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

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

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

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

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

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


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:
__int64 __fastcall Column_freeList(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 32);
free(*(void **)a1);
deleteConstraint_ts(*(_QWORD *)(a1 + 16));
free((void *)a1);
result = Column_freeList(v1);
}
return result;
}

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

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 32);
free(*(void **)a1);
func1(*(_QWORD *)(a1 + 16));
free((void *)a1);
result = func7(v1);
}
return result;
}

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

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


decompiled_code:
unsigned __int64 __fastcall Column_getSize(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx
unsigned __int64 result; // rax

v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
while ( *(_DWORD *)v1 != 7 )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
goto LABEL_4;
}
result = *(unsigned int *)(v1 + 8);
}
else
{
LABEL_4:
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 2 )
{
result = 1LL;
}
else if ( v2 > 2 )
{
result = 250LL;
}
else
{
result = (-(__int64)(v2 == 0) & 0xFFFFFFFFFFFFFFFCLL) + 8;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx
unsigned __int64 result; // rax

v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
while ( *(_DWORD *)v1 != 7 )
{
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
goto LABEL_4;
}
result = *(unsigned int *)(v1 + 8);
}
else
{
LABEL_4:
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 2 )
{
result = 1LL;
}
else if ( v2 > 2 )
{
result = 250LL;
}
else
{
result = (-(__int64)(v2 == 0) & 0xFFFFFFFFFFFFFFFCLL) + 8;
}
}
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;
   }
}

user_defined_types: struct ForeignKeyRef_t { char *col_name; }

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:
void __fastcall Column_getOffsets(__int64 a1)
{
Column_getOffsets_r(a1, 0LL);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
func9(a1, 0LL);
}

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: 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 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 *

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

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


decompiled_code:
__int64 __fastcall Column_addConstraint(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) = Constraint_append(*(_QWORD *)(a1 + 16), a2);
return a1;
}

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 *

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 ForeignKeyRef_t { char *col_name; }

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


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: 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 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:
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 result; // rax
__int64 v3; // rax

result = a2;
if ( a1 )
{
v3 = Column_append(*(_QWORD *)(a1 + 32));
result = app_col(a1, v3);
}
return result;
}

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

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

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 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 ForeignKeyRef_t { char *col_name; }

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: union LitVal { int ival; double dval; char cval; char *strval; }

user_defined_types: struct CondComp { struct Expression_s *expr1; }


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

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 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 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 Table_addPrimaryKey(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rax

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

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

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 32);
if ( !v2 )
return v2;
}
v3 = PrimaryKey();
Column_addConstraint(v2, v3);
v2 = a1;
}
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; }

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


decompiled_code:
__int64 __fastcall Table_addForeignKey(__int64 a1, int a2, int a3, int a4, int a5, int a6, char *s2)
{
__int64 v8; // rbx
const char *v9; // rdi
__int64 v10; // rdx
__int64 v12; // 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_5;
}
v12 = ForeignKey(v9, s2, v10);
Column_addConstraint(v8, v12);
}
else
{
LABEL_5:
fprintf(stderr, "Error: column %s not in table\n", s2);
}
}
else
{
fwrite("Error: table is null\n", 1uLL, 0x15uLL, stderr);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, int a4, int a5, int a6, char *s2)
{
__int64 v8; // rbx
const char *v9; // rdi
__int64 v10; // rdx
__int64 v12; // 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_5;
}
v12 = ForeignKey(v9, s2, v10);
Column_addConstraint(v8, v12);
}
else
{
LABEL_5:
fprintf(stderr, "Error: column %s not in table\n", s2);
}
}
else
{
fwrite("Error: table is null\n", 1uLL, 0x15uLL, stderr);
}
return a1;
}

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 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 CondUnary { struct Condition_t *cond; }

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

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

user_defined_types: struct ExprBinary { struct Expression_s *expr1; }

user_defined_types: struct ExprUnary { struct Expression_s *expr; }

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


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

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

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

for ( i = a2; i; i = (const char *)*((_QWORD *)i + 4) )
{
if ( *(_DWORD *)i )
{
if ( *(_DWORD *)i == 1 )
{
if ( !func1(a1, (int)a2, a3, a4, a5, a6, *((char **)i + 1)) )
{
a2 = "Error: column '%s' not found\n";
fprintf(stderr, "Error: column '%s' not found\n", *((const char **)i + 1));
}
}
else
{
LODWORD(a2) = 1;
fwrite("Unknown declaration type\n", 1uLL, 0x19uLL, stderr);
}
}
else
{
for ( j = (const char **)*((_QWORD *)i + 1); j; j = (const char **)j[1] )
{
a2 = *j;
if ( !func0(a1, *j) )
{
a2 = "Error: column '%s' not found\n";
fprintf(stderr, "Error: column '%s' not found\n", *j);
}
}
}
}
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 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 ForeignKeyRef_t { char *col_name; }

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: union LitVal { int ival; double dval; char cval; char *strval; }

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 Table_make(__int64 a1, __int64 a2, const char *a3)
{
_QWORD *v4; // rbx
int v5; // edx
int v6; // ecx
int v7; // er8
int v8; // er9

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

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

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

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: struct Table_s { char *name; struct Column_t *columns; }

user_defined_types: enum key_dec_type { KEY_DEC_PRIMARY=0, KEY_DEC_FOREIGN=1 }

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 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 Table_addPrimaryKeys(__int64 a1, __int64 a2)
{
unsigned int i; // er12
const char *v4; // rbp

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

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

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

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: 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: enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 }

user_defined_types: struct CondBinary { struct Condition_t *cond1; }

user_defined_types: struct CondUnary { struct Condition_t *cond; }

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

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

user_defined_types: struct ExprBinary { struct Expression_s *expr1; }

user_defined_types: struct ExprUnary { struct Expression_s *expr; }

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


decompiled_code:
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 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 ForeignKeyRef_t { char *col_name; }

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: union LitVal { int ival; double dval; char cval; char *strval; }

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 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)
{
__int64 v1; // rbx
int v2; // ebp
const char *v3; // rax
__int64 v5; // [rsp+0h] [rbp-88h] BYREF

v1 = *(_QWORD *)(a1 + 8);
printf("Table %s (\n", *(const char **)a1);
v2 = 10;
if ( v1 )
{
while ( 1 )
{
v3 = (const char *)typeToString(*(unsigned int *)(v1 + 8), &v5);
printf("\t%s %s", *(const char **)v1, v3);
Constraint_printList(*(_QWORD *)(v1 + 16));
if ( !--v2 )
break;
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
break;
puts(",");
}
}
return puts("\n)");
}

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

v1 = *(_QWORD *)(a1 + 8);
printf("Table %s (\n", *(const char **)a1);
v2 = 10;
if ( v1 )
{
while ( 1 )
{
v3 = (const char *)typeToString(*(unsigned int *)(v1 + 8), &v5);
printf("\t%s %s", *(const char **)v1, v3);
Constraint_printList(*(_QWORD *)(v1 + 16));
if ( !--v2 )
break;
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
break;
puts(",");
}
}
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 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 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 KeyDec_append(__int64 a1, __int64 a2)
{
__int64 result; // rax

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

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

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

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)
{
__int64 result; // rax

result = a1;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

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

result = a1;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

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

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

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(__int64 a1)
{
int result; // eax

if ( *(_DWORD *)a1 )
result = Index_print(*(_QWORD *)(a1 + 8));
else
result = Table_print(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( *(_DWORD *)a1 )
result = func11(*(_QWORD *)(a1 + 8));
else
result = func8(*(_QWORD *)(a1 + 8));
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 Table_s { char *name; struct Column_t *columns; }