getArrayTerminalTypeSym

decompiled_code:
__int64 __fastcall getArrayTerminalTypeSym(__int64 a1)
{
__int64 v1; // rbp

if ( !a1 )
return 0LL;
v1 = a1;
if ( (unsigned int)((__int64 (*)(void))getType)() != 1 )
return 0LL;
do
v1 = **(_QWORD **)getTypePtr(v1);
while ( (unsigned int)getType(v1) == 1 );
return v1;
}

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

if ( !a1 )
return 0LL;
v1 = a1;
if ( (unsigned int)((__int64 (*)(void))getType)() != 1 )
return 0LL;
do
v1 = **(_QWORD **)getTypePtr(v1);
while ( (unsigned int)getType(v1) == 1 );
return v1;
}

original_code:
Symbol *getArrayTerminalTypeSym(Symbol *s)
{
 Symbol *baseSym = ((void *)0);
 if (!s) return ((void *)0);
 if (getType(s) != ARRAY_T) return ((void *)0);
 baseSym = getTypePtr(s)->Array->baseTypeSym;
 while (getType(baseSym) == ARRAY_T) {
  baseSym = getTypePtr(baseSym)->Array->baseTypeSym;
 }
 return baseSym;
}

canonical_original_code:
struct Symbol *getArrayTerminalTypeSym(struct Symbol *s)
{
 struct Symbol *baseSym = ((void *)0);
 if (!s) return ((void *)0);
 if (getType(s) != ARRAY_T) return ((void *)0);
 baseSym = getTypePtr(s)->Array->baseTypeSym;
 while (getType(baseSym) == ARRAY_T) {
  baseSym = getTypePtr(baseSym)->Array->baseTypeSym;
 }
 return baseSym;
}

variable_types: struct Symbol { char *name; enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 } kind; union kind_union { struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value { struct Boolean { int value; } Boolean; struct Char { unsigned char value; } Char; struct Integer { int value; } Integer; struct Real { double value; } Real; struct String { char *str; unsigned int strlen; } String; } value; } *ConstKind; struct FunctionKind { struct Symbol *typeSym; struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *params; char *label; int invocationInstance; } *FuncKind; struct ParamKind { struct Symbol *typeSym; int byRef; } *ParamKind; struct ProcedureKind { struct ElementArray *params; char *label; } *ProcKind; struct TypeKind { union type_union { struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; } *Array; struct Function { struct ParamArray { struct Param { char *name; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; struct Symbol *typeSym; } **data; unsigned int len; unsigned int nElements; } *params; struct Symbol *returnTypeSym; char *label; } *Function; struct Procedure { struct ParamArray *params; char *label; } *Procedure; struct Record { struct hash { struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; } *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; } *hash; } *Record; struct Scalar { struct ElementArray *consts; } *Scalar; struct StringType { unsigned int strlen; } *String; struct Subrange { int high; int low; struct Symbol *baseTypeSym; } *Subrange; } typePtr; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; } *TypeKind; struct VariableKind { struct Symbol *typeSym; int byRef; } *VarKind; } kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; } *

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }


getArrayBaseSym

repo: a-krebs/YACC

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

if ( !a1 )
return 0LL;
if ( (unsigned int)getType(a1) != 1 )
return 0LL;
v1 = getTypeSym(a1);
return **(_QWORD **)getTypePtr(v1);
}

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

if ( !a1 )
return 0LL;
if ( (unsigned int)getType(a1) != 1 )
return 0LL;
v1 = getTypeSym(a1);
return **(_QWORD **)getTypePtr(v1);
}

original_code:
Symbol *getArrayBaseSym(Symbol *s)
{
 if (!s) return ((void *)0);
 if (getType(s) != ARRAY_T) return ((void *)0);
 return getTypePtr(getTypeSym((s)))->Array->baseTypeSym;
}

canonical_original_code:
struct Symbol *getArrayBaseSym(struct Symbol *s)
{
 if (!s) return ((void *)0);
 if (getType(s) != ARRAY_T) return ((void *)0);
 return getTypePtr(getTypeSym((s)))->Array->baseTypeSym;
}

variable_types:
s
struct Symbol *

return_type: struct Symbol { char *name; enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 } kind; union kind_union { struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value { struct Boolean { int value; } Boolean; struct Char { unsigned char value; } Char; struct Integer { int value; } Integer; struct Real { double value; } Real; struct String { char *str; unsigned int strlen; } String; } value; } *ConstKind; struct FunctionKind { struct Symbol *typeSym; struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *params; char *label; int invocationInstance; } *FuncKind; struct ParamKind { struct Symbol *typeSym; int byRef; } *ParamKind; struct ProcedureKind { struct ElementArray *params; char *label; } *ProcKind; struct TypeKind { union type_union { struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; } *Array; struct Function { struct ParamArray { struct Param { char *name; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; struct Symbol *typeSym; } **data; unsigned int len; unsigned int nElements; } *params; struct Symbol *returnTypeSym; char *label; } *Function; struct Procedure { struct ParamArray *params; char *label; } *Procedure; struct Record { struct hash { struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; } *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; } *hash; } *Record; struct Scalar { struct ElementArray *consts; } *Scalar; struct StringType { unsigned int strlen; } *String; struct Subrange { int high; int low; struct Symbol *baseTypeSym; } *Subrange; } typePtr; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; } *TypeKind; struct VariableKind { struct Symbol *typeSym; int byRef; } *VarKind; } kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; } *

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


isValidArrayAccess

decompiled_code:
__int64 __fastcall isValidArrayAccess(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // r13
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rax
int v7; // eax
__int64 v8; // r14
__int64 v9; // rax
unsigned int v10; // eax
__int64 v11; // r13
unsigned int v12; // eax
__int64 v13; // rax
__int64 v14; // rdx
const char *v15; // rdi
__int64 v16; // rsi
__int64 v17; // rax
__int64 result; // rax
unsigned int v19; // eax
__int64 v20; // rax

if ( !a1 || (v2 = a2) == 0LL )
err(1, "Tried to do array access with NULL args.");
v3 = getTypeSym(a1);
if ( (unsigned int)getType(v3) == 1 )
{
v4 = getArrayIndexSym(v3);
while ( (unsigned int)getType(v3) == 1 )
{
v7 = getType(v4);
if ( v7 == 8 )
{
if ( !(unsigned int)isConstInScalar(v2, v4) )
{
LABEL_11:
v10 = getType(v2);
v11 = typeToString(v10);
v12 = getType(v4);
v13 = typeToString(v12);
v14 = v11;
v15 = "Invalid array subscript. Expected type %s but got %s";
v16 = v13;
goto LABEL_12;
}
}
else if ( v7 == 10 )
{
v8 = getTypeSym(v2);
v9 = getSubrangeBaseTypeSym(v4);
if ( !(unsigned int)areSameType(v9, v8) )
goto LABEL_11;
}
else
{
v5 = getTypeSym(v2);
if ( !(unsigned int)areSameType(v4, v5) )
goto LABEL_11;
}
v3 = getArrayBaseSym(v3);
v6 = getArrayIndexSym(v3);
v2 = (_QWORD *)v2[6];
v4 = v6;
if ( !v2 )
{
result = newProxySymFromSym(v3);
*(_DWORD *)(result + 40) = 1;
return result;
}
}
recordError("Illegal array access -- too many indices.", yylineno, colno, 2LL);
result = 0LL;
}
else
{
v19 = getType(v3);
v20 = typeToString(v19);
v16 = *a2;
v15 = "Tried to index into %s, which is of type %s, and not an array type.";
v14 = v20;
LABEL_12:
v17 = customErrorString(v15, v16, v14);
recordError(v17, yylineno, colno, 2LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // r13
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rax
int v7; // eax
__int64 v8; // r14
__int64 v9; // rax
unsigned int v10; // eax
__int64 v11; // r13
unsigned int v12; // eax
__int64 v13; // rax
__int64 v14; // rdx
const char *v15; // rdi
__int64 v16; // rsi
__int64 v17; // rax
__int64 result; // rax
unsigned int v19; // eax
__int64 v20; // rax

if ( !a1 || (v2 = a2) == 0LL )
err(1, "Tried to do array access with NULL args.");
v3 = getTypeSym(a1);
if ( (unsigned int)getType(v3) == 1 )
{
v4 = func0(v3);
while ( (unsigned int)getType(v3) == 1 )
{
v7 = getType(v4);
if ( v7 == 8 )
{
if ( !(unsigned int)isConstInScalar(v2, v4) )
{
LABEL_11:
v10 = getType(v2);
v11 = typeToString(v10);
v12 = getType(v4);
v13 = typeToString(v12);
v14 = v11;
v15 = "Invalid array subscript. Expected type %s but got %s";
v16 = v13;
goto LABEL_12;
}
}
else if ( v7 == 10 )
{
v8 = getTypeSym(v2);
v9 = getSubrangeBaseTypeSym(v4);
if ( !(unsigned int)areSameType(v9, v8) )
goto LABEL_11;
}
else
{
v5 = getTypeSym(v2);
if ( !(unsigned int)areSameType(v4, v5) )
goto LABEL_11;
}
v3 = func3(v3);
v6 = func0(v3);
v2 = (_QWORD *)v2[6];
v4 = v6;
if ( !v2 )
{
result = newProxySymFromSym(v3);
*(_DWORD *)(result + 40) = 1;
return result;
}
}
recordError("Illegal array access -- too many indices.", yylineno, colno, 2LL);
result = 0LL;
}
else
{
v19 = getType(v3);
v20 = typeToString(v19);
v16 = *a2;
v15 = "Tried to index into %s, which is of type %s, and not an array type.";
v14 = v20;
LABEL_12:
v17 = customErrorString(v15, v16, v14);
recordError(v17, yylineno, colno, 2LL);
result = 0LL;
}
return result;
}

original_code:
Symbol *isValidArrayAccess(ProxySymbol *var, ProxySymbol *indices) {
 Symbol *arrayTypeSym = ((void *)0);
 Symbol *indexTypeSym = ((void *)0);
 Symbol *returnTypeSym = ((void *)0);
 Symbol *arg = indices;
 int typeErr = 0;
 if ((var == ((void *)0))||(indices == ((void *)0))) {
  err(1, "Tried to do array access with NULL args.");
 }
 arrayTypeSym = getTypeSym(var);
 if (getType(arrayTypeSym) != ARRAY_T) {
  errMsg = customErrorString("Tried to index into %s, which is "
      "of type %s, and not an array type.",
      arg->name,
      typeToString(getType(arrayTypeSym)));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 indexTypeSym = getArrayIndexSym(arrayTypeSym);
 while ( (arg) && (getType(arrayTypeSym) == ARRAY_T)) {
  switch (getType(indexTypeSym)) {
  case SCALAR_T:
   if (!isConstInScalar(arg, indexTypeSym))
       typeErr = 1;
   break;
  case SUBRANGE_T:
   if (!areSameType(
       getSubrangeBaseTypeSym(indexTypeSym),
       getTypeSym(arg))) typeErr = 1;
   break;
  default:
   if (!areSameType(indexTypeSym,
        getTypeSym(arg))) typeErr = 1;
   break;
  }
  if (typeErr) {
   errMsg = customErrorString("Invalid array "
       "subscript.  Expected type %s "
       "but got %s",
           typeToString(getType(indexTypeSym)),
           typeToString(getType(arg)));
   recordError(errMsg, yylineno, colno, SEMANTIC);
   return ((void *)0);
  }
  typeErr = 0;
  arrayTypeSym = getArrayBaseSym(arrayTypeSym);
  indexTypeSym = getArrayIndexSym(arrayTypeSym);
  arg = arg->next;
 }
 if (arg) {
  recordError("Illegal array access -- too many indices.",
      yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 returnTypeSym = newProxySymFromSym(arrayTypeSym);
 returnTypeSym->isAddress = 1;
 return returnTypeSym;
}

canonical_original_code:
struct Symbol *isValidArrayAccess(struct Symbol *var, struct Symbol *indices) {
 struct Symbol *arrayTypeSym = ((void *)0);
 struct Symbol *indexTypeSym = ((void *)0);
 struct Symbol *returnTypeSym = ((void *)0);
 struct Symbol *arg = indices;
 int typeErr = 0;
 if ((var == ((void *)0))||(indices == ((void *)0))) {
  err(1, "Tried to do array access with NULL args.");
 }
 arrayTypeSym = getTypeSym(var);
 if (getType(arrayTypeSym) != ARRAY_T) {
  errMsg = customErrorString("Tried to index into %s, which is "
      "of type %s, and not an array type.",
      arg->name,
      typeToString(getType(arrayTypeSym)));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 indexTypeSym = getArrayIndexSym(arrayTypeSym);
 while ( (arg) && (getType(arrayTypeSym) == ARRAY_T)) {
  switch (getType(indexTypeSym)) {
  case SCALAR_T:
   if (!isConstInScalar(arg, indexTypeSym))
       typeErr = 1;
   break;
  case SUBRANGE_T:
   if (!areSameType(
       getSubrangeBaseTypeSym(indexTypeSym),
       getTypeSym(arg))) typeErr = 1;
   break;
  default:
   if (!areSameType(indexTypeSym,
        getTypeSym(arg))) typeErr = 1;
   break;
  }
  if (typeErr) {
   errMsg = customErrorString("Invalid array "
       "subscript.  Expected type %s "
       "but got %s",
           typeToString(getType(indexTypeSym)),
           typeToString(getType(arg)));
   recordError(errMsg, yylineno, colno, SEMANTIC);
   return ((void *)0);
  }
  typeErr = 0;
  arrayTypeSym = getArrayBaseSym(arrayTypeSym);
  indexTypeSym = getArrayIndexSym(arrayTypeSym);
  arg = arg->next;
 }
 if (arg) {
  recordError("Illegal array access -- too many indices.",
      yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 returnTypeSym = newProxySymFromSym(arrayTypeSym);
 returnTypeSym->isAddress = 1;
 return returnTypeSym;
}

variable_types:
var
struct Symbol *

variable_types:
indices
struct Symbol *

variable_types: typeErr int

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


getArrayHighIndexValue

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

v1 = *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
if ( (unsigned int)getType(v1) == 10 )
result = **(unsigned int **)getTypePtr(v1);
else
result = (unsigned int)(*(_DWORD *)(**(_QWORD **)getTypePtr(v1) + 12LL) - 1);
return result;
}

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

v1 = *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
if ( (unsigned int)getType(v1) == 10 )
result = **(unsigned int **)getTypePtr(v1);
else
result = (unsigned int)(*(_DWORD *)(**(_QWORD **)getTypePtr(v1) + 12LL) - 1);
return result;
}

original_code:
int getArrayHighIndexValue(Symbol *arrayType)
{
 Symbol *indexType = ((void *)0);
 indexType = getTypePtr(arrayType)->Array->indexTypeSym;
 if (getType(indexType) == SUBRANGE_T) {
  return getTypePtr(indexType)->Subrange->high;
 } else return ((getTypePtr(indexType)->Scalar->consts->nElements) - 1);
}

canonical_original_code:
int getArrayHighIndexValue(struct Symbol *arrayType)
{
 struct Symbol *indexType = ((void *)0);
 indexType = getTypePtr(arrayType)->Array->indexTypeSym;
 if (getType(indexType) == SUBRANGE_T) {
  return getTypePtr(indexType)->Subrange->high;
 } else return ((getTypePtr(indexType)->Scalar->consts->nElements) - 1);
}

return_type: int

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


getArrayLowIndexValue

decompiled_code:
__int64 __fastcall getArrayLowIndexValue(__int64 a1)
{
__int64 v1; // rbp
int v2; // er8
__int64 result; // rax

if ( !a1 )
{
fwrite("Trying to get low index value of a NULL symbol.\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
if ( (unsigned int)getType(a1) != 1 )
{
fwrite("Trying to low index value of a symbol which is not an array\n", 1uLL, 0x3CuLL, stderr);
exit(1);
}
v1 = *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
v2 = getType(v1);
result = 0LL;
if ( v2 == 10 )
result = *(unsigned int *)(*(_QWORD *)getTypePtr(v1) + 4LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbp
int v2; // er8
__int64 result; // rax

if ( !a1 )
{
fwrite("Trying to get low index value of a NULL symbol.\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
if ( (unsigned int)getType(a1) != 1 )
{
fwrite("Trying to low index value of a symbol which is not an array\n", 1uLL, 0x3CuLL, stderr);
exit(1);
}
v1 = *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
v2 = getType(v1);
result = 0LL;
if ( v2 == 10 )
result = *(unsigned int *)(*(_QWORD *)getTypePtr(v1) + 4LL);
return result;
}

original_code:
int getArrayLowIndexValue(Symbol *arrayType)
{
 Symbol *indexType = ((void *)0);
 if (!arrayType) {
  fprintf(stderr, "Trying to get low index value of a NULL symbol"
      ".\n");
  exit(1);
 }
 if (getType(arrayType) != ARRAY_T) {
  fprintf(stderr, "Trying to low index value of a symbol which is"
      " not an array\n");
  exit(1);
 }
 indexType = getTypePtr(arrayType)->Array->indexTypeSym;
 if (getType(indexType) == SUBRANGE_T) {
  return getTypePtr(indexType)->Subrange->low;
 } else return 0;
}

canonical_original_code:
int getArrayLowIndexValue(struct Symbol *arrayType)
{
 struct Symbol *indexType = ((void *)0);
 if (!arrayType) {
  fprintf(stderr, "Trying to get low index value of a NULL symbol"
      ".\n");
  exit(1);
 }
 if (getType(arrayType) != ARRAY_T) {
  fprintf(stderr, "Trying to low index value of a symbol which is"
      " not an array\n");
  exit(1);
 }
 indexType = getTypePtr(arrayType)->Array->indexTypeSym;
 if (getType(indexType) == SUBRANGE_T) {
  return getTypePtr(indexType)->Subrange->low;
 } else return 0;
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


getArrayLength

decompiled_code:
__int64 __fastcall getArrayLength(__int64 a1)
{
int v1; // ebx

v1 = getArrayHighIndexValue(a1);
return v1 - (unsigned int)getArrayLowIndexValue(a1) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebx

v1 = func5(a1);
return v1 - (unsigned int)func6(a1) + 1;
}

original_code:
int getArrayLength(Symbol *s)
{
 return (getArrayHighIndexValue(s) - getArrayLowIndexValue(s))+1;
}

canonical_original_code:
int getArrayLength(struct Symbol *s)
{
 return (getArrayHighIndexValue(s) - getArrayLowIndexValue(s))+1;
}

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


createConstSymbol

decompiled_code:
__int64 __fastcall createConstSymbol(__int64 a1)
{
return createSymbol(symbolTable, a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return createSymbol(symbolTable, a1, 0LL, 0LL);
}

canonical_original_code:
struct Symbol *createConstSymbol(char *id) {
 return createSymbol(symbolTable, id, CONST_KIND, 0);
}

variable_types:
id
char *

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


createFuncSymbol

decompiled_code:
__int64 __fastcall createFuncSymbol(__int64 a1)
{
return createSymbol(symbolTable, a1, 1LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return createSymbol(symbolTable, a1, 1LL, 0LL);
}

canonical_original_code:
struct Symbol *createFuncSymbol(char *id) {
 return createSymbol(symbolTable, id, FUNC_KIND, 0);
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


createParamSymbol

decompiled_code:
__int64 __fastcall createParamSymbol(__int64 a1)
{
return createSymbol(symbolTable, a1, 2LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return createSymbol(symbolTable, a1, 2LL, 0LL);
}

canonical_original_code:
struct Symbol *createParamSymbol(char *id) {
 return createSymbol(symbolTable, id, PARAM_KIND, 0);
}

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


createProcSymbol

decompiled_code:
__int64 __fastcall createProcSymbol(__int64 a1)
{
return createSymbol(symbolTable, a1, 3LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return createSymbol(symbolTable, a1, 3LL, 0LL);
}

canonical_original_code:
struct Symbol *createProcSymbol(char *id) {
 return createSymbol(symbolTable, id, PROC_KIND, 0);
}

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


createVarSymbol

decompiled_code:
__int64 __fastcall createVarSymbol(__int64 a1)
{
return createSymbol(symbolTable, a1, 5LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return createSymbol(symbolTable, a1, 5LL, 0LL);
}

canonical_original_code:
struct Symbol *createVarSymbol(char *id) {
 return createSymbol(symbolTable, id, VAR_KIND, 0);
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


createTypeSymbol

decompiled_code:
__int64 __fastcall createTypeSymbol(__int64 a1, unsigned int a2)
{
return createSymbol(symbolTable, a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
return createSymbol(symbolTable, a1, 4LL, a2);
}

canonical_original_code:
struct Symbol *createTypeSymbol(char *id, int typeOriginator) {
 return createSymbol(symbolTable, id, TYPE_KIND, typeOriginator);
}

variable_types: typeOriginator int

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


getSubrangeBaseTypeSym

decompiled_code:
__int64 __fastcall getSubrangeBaseTypeSym(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( (unsigned int)getType() == 10 )
return *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( (unsigned int)getType() == 10 )
return *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
return 0LL;
}

original_code:
Symbol * getSubrangeBaseTypeSym(Symbol *sr) {
 if (!sr) return ((void *)0);
 if (getType(sr) != SUBRANGE_T) return ((void *)0);
 return getTypePtr(sr)->Subrange->baseTypeSym;
}

canonical_original_code:
struct Symbol *getSubrangeBaseTypeSym(struct Symbol *sr) {
 if (!sr) return ((void *)0);
 if (getType(sr) != SUBRANGE_T) return ((void *)0);
 return getTypePtr(sr)->Subrange->baseTypeSym;
}

variable_types:
sr
struct Symbol *

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


freeProxySymbol

decompiled_code:
// attributes: thunk
void freeProxySymbol(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func7(void *ptr)
{
free(ptr);
}

original_code:
void freeProxySymbol(ProxySymbol *p) {
 free(p);
}

canonical_original_code:
void freeProxySymbol(struct Symbol *p) {
 free(p);
}

return_type: void

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


isConstResultSym

decompiled_code:
__int64 __fastcall isConstResultSym(__int64 a1)
{
unsigned int *v1; // rax

v1 = *(unsigned int **)(a1 + 16);
if ( !v1 )
err(1, "kindPtr is NULL");
return *v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int *v1; // rax

v1 = *(unsigned int **)(a1 + 16);
if ( !v1 )
err(1, "kindPtr is NULL");
return *v1;
}

original_code:
int isConstResultSym(ProxySymbol *s){
 if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
 return s->kindPtr.ConstKind->constResultFlag;
}

canonical_original_code:
int isConstResultSym(struct Symbol *s){
 if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
 return s->kindPtr.ConstKind->constResultFlag;
}

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


getTypeSym

decompiled_code:
__int64 __fastcall getTypeSym(__int64 a1)
{
__int64 *v1; // rax
__int64 result; // rax
__int64 v3; // rax

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
v3 = *(_QWORD *)(a1 + 16);
if ( !v3 )
goto LABEL_12;
result = *(_QWORD *)(v3 + 8);
break;
case 1:
case 2:
case 5:
v1 = *(__int64 **)(a1 + 16);
if ( !v1 )
goto LABEL_12;
result = *v1;
break;
case 3:
return 0LL;
case 4:
if ( !*(_QWORD *)(a1 + 16) )
LABEL_12:
err(1, "kindPtr is NULL");
result = a1;
break;
default:
err(1, "Unknown kind set on given symbol");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 *v1; // rax
__int64 result; // rax
__int64 v3; // rax

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
v3 = *(_QWORD *)(a1 + 16);
if ( !v3 )
goto LABEL_12;
result = *(_QWORD *)(v3 + 8);
break;
case 1:
case 2:
case 5:
v1 = *(__int64 **)(a1 + 16);
if ( !v1 )
goto LABEL_12;
result = *v1;
break;
case 3:
return 0LL;
case 4:
if ( !*(_QWORD *)(a1 + 16) )
LABEL_12:
err(1, "kindPtr is NULL");
result = a1;
break;
default:
err(1, "Unknown kind set on given symbol");
}
return result;
}

original_code:
Symbol *getTypeSym(Symbol *s) {
 if (!s) return ((void *)0);
 switch (s->kind) {
 case CONST_KIND:
  if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ConstKind->typeSym;
 case PARAM_KIND:
  if (s->kindPtr.ParamKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ParamKind->typeSym;
 case PROC_KIND:
  return ((void *)0);
 case FUNC_KIND:
  if (s->kindPtr.FuncKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.FuncKind->typeSym;
 case TYPE_KIND:
  if (s->kindPtr.TypeKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s;
 case VAR_KIND:
  if (s->kindPtr.VarKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.VarKind->typeSym;
 default:
  err(1, "Unknown kind set on given symbol");
  return ((void *)0);
 }
}

canonical_original_code:
struct Symbol *getTypeSym(struct Symbol *s) {
 if (!s) return ((void *)0);
 switch (s->kind) {
 case CONST_KIND:
  if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ConstKind->typeSym;
 case PARAM_KIND:
  if (s->kindPtr.ParamKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ParamKind->typeSym;
 case PROC_KIND:
  return ((void *)0);
 case FUNC_KIND:
  if (s->kindPtr.FuncKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.FuncKind->typeSym;
 case TYPE_KIND:
  if (s->kindPtr.TypeKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s;
 case VAR_KIND:
  if (s->kindPtr.VarKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.VarKind->typeSym;
 default:
  err(1, "Unknown kind set on given symbol");
  return ((void *)0);
 }
}

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


isByReference

decompiled_code:
__int64 __fastcall isByReference(__int64 a1)
{
int v1; // eax
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 2 || v1 == 5 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 16) + 8LL);
else
result = 0LL;
return result;
}

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

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 2 || v1 == 5 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 16) + 8LL);
else
result = 0LL;
return result;
}

original_code:
int isByReference(Symbol *s)
{
 if (!s) return 0;
 if ((s->kind == PARAM_KIND)) return s->kindPtr.ParamKind->byRef;
 if (s->kind == VAR_KIND) return s->kindPtr.VarKind->byRef;
 return 0;
}

canonical_original_code:
int isByReference(struct Symbol *s)
{
 if (!s) return 0;
 if ((s->kind == PARAM_KIND)) return s->kindPtr.ParamKind->byRef;
 if (s->kind == VAR_KIND) return s->kindPtr.VarKind->byRef;
 return 0;
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


addToSymbolTable

decompiled_code:
__int64 __fastcall addToSymbolTable(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er12

v2 = createHashElement(a1, *a2, a2);
setSymbolSize(a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er12

v2 = createHashElement(a1, *a2, a2);
setSymbolSize(a2);
return v2;
}

original_code:
int addToSymbolTable(struct hash *table, Symbol *symbol) {
 int retval = 0;
 retval = createHashElement(table, symbol->name, symbol);
 setSymbolSize(symbol);
 return retval;
}

canonical_original_code:
int addToSymbolTable(struct hash *table, struct Symbol *symbol) {
 int retval = 0;
 retval = createHashElement(table, symbol->name, symbol);
 setSymbolSize(symbol);
 return retval;
}

variable_types: struct hash { struct hashElement { char *key; struct Symbol { char *name; enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 } kind; union kind_union { struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value { struct Boolean { int value; } Boolean; struct Char { unsigned char value; } Char; struct Integer { int value; } Integer; struct Real { double value; } Real; struct String { char *str; unsigned int strlen; } String; } value; } *ConstKind; struct FunctionKind { struct Symbol *typeSym; struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *params; char *label; int invocationInstance; } *FuncKind; struct ParamKind { struct Symbol *typeSym; int byRef; } *ParamKind; struct ProcedureKind { struct ElementArray *params; char *label; } *ProcKind; struct TypeKind { union type_union { struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; } *Array; struct Function { struct ParamArray { struct Param { char *name; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; struct Symbol *typeSym; } **data; unsigned int len; unsigned int nElements; } *params; struct Symbol *returnTypeSym; char *label; } *Function; struct Procedure { struct ParamArray *params; char *label; } *Procedure; struct Record { struct hash *hash; } *Record; struct Scalar { struct ElementArray *consts; } *Scalar; struct StringType { unsigned int strlen; } *String; struct Subrange { int high; int low; struct Symbol *baseTypeSym; } *Subrange; } typePtr; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; } *TypeKind; struct VariableKind { struct Symbol *typeSym; int byRef; } *VarKind; } kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; } *symbol; struct hashElement *prev; struct hashElement *next; } *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; } *

variable_types:
symbol
struct Symbol *

variable_types: retval int

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


dumpStmtLL

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

if ( a1 )
result = writeStmtLL(stderr, a1);
return result;
}

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

if ( a1 )
result = func0(stderr, a1);
return result;
}

original_code:
void
dumpStmtLL(StmtLL *ll)
{
 if (!ll) return;
 writeStmtLL(stderr, ll);
}

canonical_original_code:
void dumpStmtLL(struct stmtll *ll)
{
 if (!ll) return;
 writeStmtLL(stderr, ll);
}

variable_types: struct stmtll { char *stmt; struct stmtll *next; } *


freeStmtLL

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

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

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

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void
freeStmtLL(StmtLL *ll)
{
 StmtLL *copy;
 while (ll) {
  copy = ll;
  ll = ll->next;
  free(copy->stmt);
  free(copy);
 }
}

canonical_original_code:
void freeStmtLL(struct stmtll *ll)
{
 struct stmtll *copy;
 while (ll) {
  copy = ll;
  ll = ll->next;
  free(copy->stmt);
  free(copy);
 }
}

user_defined_types: struct stmtll { char *stmt; struct stmtll *next; }


newConstProxySym

decompiled_code:
__int64 __fastcall newConstProxySym(__int64 a1, char *a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
char v6; // bp
__int64 result; // rax
unsigned int v8; // er13
__int64 v9; // rbp
__int64 v10; // rax

if ( !a2 || !a3 )
err(1, "Passed NULL arguments to newConstProxySym");
v4 = createConstSymbol();
v5 = v4;
if ( !v4 )
err(1, "Failed to allocate memory for new constant proxy symbol!");
setInnerTypeSymbol(v4, a3);
**(_DWORD **)(v5 + 16) = 0;
switch ( (unsigned int)getType(a3) )
{
case 2u:
case 4u:
goto LABEL_6;
case 3u:
v6 = *a2;
*(_BYTE *)getConstVal(v5) = v6;
LABEL_6:
*(_DWORD *)getConstVal(v5) = *(_DWORD *)a2;
result = v5;
break;
case 5u:
*(_QWORD *)getConstVal(v5) = *(_QWORD *)a2;
result = v5;
break;
case 9u:
v8 = *((_DWORD *)a2 + 2);
v9 = *(_QWORD *)a2;
v10 = getConstVal(v5);
setStringStr(v10, v9, v8);
result = v5;
break;
default:
err(1, "Called newConstProxySym with invalid typeSym (can't get inner type)");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
char v6; // bp
__int64 result; // rax
unsigned int v8; // er13
__int64 v9; // rbp
__int64 v10; // rax

if ( !a2 || !a3 )
err(1, "Passed NULL arguments to newConstProxySym");
v4 = createConstSymbol();
v5 = v4;
if ( !v4 )
err(1, "Failed to allocate memory for new constant proxy symbol!");
setInnerTypeSymbol(v4, a3);
**(_DWORD **)(v5 + 16) = 0;
switch ( (unsigned int)getType(a3) )
{
case 2u:
case 4u:
goto LABEL_6;
case 3u:
v6 = *a2;
*(_BYTE *)getConstVal(v5) = v6;
LABEL_6:
*(_DWORD *)getConstVal(v5) = *(_DWORD *)a2;
result = v5;
break;
case 5u:
*(_QWORD *)getConstVal(v5) = *(_QWORD *)a2;
result = v5;
break;
case 9u:
v8 = *((_DWORD *)a2 + 2);
v9 = *(_QWORD *)a2;
v10 = getConstVal(v5);
setStringStr(v10, v9, v8);
result = v5;
break;
default:
err(1, "Called newConstProxySym with invalid typeSym (can't get inner type)");
}
return result;
}

original_code:
ProxySymbol *newConstProxySym(char *id, void * result, Symbol *typeSym)
{
 Symbol *constSym = ((void *)0);
 double *doubleResult;
 int *intResult;
 char *charResult;
 struct String *stringResult;
 if ((result == ((void *)0)) || (typeSym == ((void *)0))) {
  err(1, "Passed NULL arguments to newConstProxySym");
 }
 constSym = createConstSymbol(id);
 if (!constSym) {
  err(1, "Failed to allocate memory for new constant proxy "
      "symbol!");
 }
 setInnerTypeSymbol(constSym, typeSym);
 constSym->kindPtr.ConstKind->constResultFlag = 0;
 switch (getType(typeSym)) {
 case BOOLEAN_T:
  intResult = (int *) result;
  getConstVal(constSym)->Boolean.value = *intResult;
  break;
 case CHAR_T:
  charResult = (char *) result;
  getConstVal(constSym)->Char.value = *charResult;
 case INTEGER_T:
  intResult = (int *) result;
  getConstVal(constSym)->Integer.value = *intResult;
  break;
 case REAL_T:
  doubleResult = (double *) result;
  getConstVal(constSym)->Real.value = *doubleResult;
  break;
 case STRING_T:
  stringResult = (struct String *) result;
  setStringStr(
      &getConstVal(constSym)->String,
      stringResult->str,
      stringResult->strlen);
  break;
 default:
  err(1, "Called newConstProxySym with invalid "
      "typeSym (can't get inner type)");
 }
 return (ProxySymbol *) constSym;
}

canonical_original_code:
struct Symbol *newConstProxySym(char *id, void *result, struct Symbol *typeSym)
{
 struct Symbol *constSym = ((void *)0);
 double *doubleResult;
 int *intResult;
 char *charResult;
 struct String *stringResult;
 if ((result == ((void *)0)) || (typeSym == ((void *)0))) {
  err(1, "Passed NULL arguments to newConstProxySym");
 }
 constSym = createConstSymbol(id);
 if (!constSym) {
  err(1, "Failed to allocate memory for new constant proxy "
      "symbol!");
 }
 setInnerTypeSymbol(constSym, typeSym);
 constSym->kindPtr.ConstKind->constResultFlag = 0;
 switch (getType(typeSym)) {
 case BOOLEAN_T:
  intResult = (int *) result;
  getConstVal(constSym)->Boolean.value = *intResult;
  break;
 case CHAR_T:
  charResult = (char *) result;
  getConstVal(constSym)->Char.value = *charResult;
 case INTEGER_T:
  intResult = (int *) result;
  getConstVal(constSym)->Integer.value = *intResult;
  break;
 case REAL_T:
  doubleResult = (double *) result;
  getConstVal(constSym)->Real.value = *doubleResult;
  break;
 case STRING_T:
  stringResult = (struct String *) result;
  setStringStr(
      &getConstVal(constSym)->String,
      stringResult->str,
      stringResult->strlen);
  break;
 default:
  err(1, "Called newConstProxySym with invalid "
      "typeSym (can't get inner type)");
 }
 return (struct Symbol *) constSym;
}

variable_types:
result
void *

variable_types:
typeSym
struct Symbol *

variable_types:
doubleResult
double *

variable_types:
intResult
int *

variable_types:
charResult
char *

variable_types: struct String { char *str; unsigned int strlen; } *

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }


emitBabyTree

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

result = doNotEmit;
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 <= 310 )
{
if ( a2 <= 295 )
{
switch ( a2 )
{
case -3:
result = emitPushRecordFieldAddress(a1, a3);
break;
case -2:
result = emitArrayElementLocation(a1, a3);
break;
case -4:
if ( a1 )
{
result = emitFuncInvok(a1, *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL));
}
else if ( a3 )
{
result = emitFuncInvok(a3, *(_QWORD *)(*(_QWORD *)(a3 + 16) + 8LL));
}
break;
}
}
else
{
switch ( a2 )
{
case 297:
result = emitMultiplication(a1, a3);
break;
case 298:
result = emitDivision(a1, a3, 298LL);
break;
case 299:
result = emitDivision(a1, a3, 299LL);
break;
case 300:
result = emitMod(a1, a3);
break;
case 301:
result = emitAnd(a1, a3);
break;
case 302:
if ( a1 && a3 )
result = emitAddition(a1, a3);
else
result = emitUnaryPlus();
break;
case 303:
if ( a1 && a3 )
result = emitSubtraction(a1, a3);
else
result = emitUnaryMinus();
break;
case 304:
result = emitOr(a1, a3);
break;
case 305:
result = emitEqualsOp(a1, a3);
break;
case 306:
result = emitInequalityOp(a1, a3);
break;
case 307:
result = emitLTOp(a1, a3);
break;
case 308:
result = emitLTEOp(a1, a3);
break;
case 309:
result = emitGTOp(a1, a3);
break;
case 310:
result = emitGTEOp(a1, a3);
break;
default:
if ( !a1 )
a1 = a3;
result = emitNot(a1);
break;
}
}
}
return result;
}

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

result = doNotEmit;
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 <= 310 )
{
if ( a2 <= 295 )
{
switch ( a2 )
{
case -3:
result = emitPushRecordFieldAddress(a1, a3);
break;
case -2:
result = emitArrayElementLocation(a1, a3);
break;
case -4:
if ( a1 )
{
result = emitFuncInvok(a1, *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL));
}
else if ( a3 )
{
result = emitFuncInvok(a3, *(_QWORD *)(*(_QWORD *)(a3 + 16) + 8LL));
}
break;
}
}
else
{
switch ( a2 )
{
case 297:
result = emitMultiplication(a1, a3);
break;
case 298:
result = emitDivision(a1, a3, 298LL);
break;
case 299:
result = emitDivision(a1, a3, 299LL);
break;
case 300:
result = emitMod(a1, a3);
break;
case 301:
result = emitAnd(a1, a3);
break;
case 302:
if ( a1 && a3 )
result = emitAddition(a1, a3);
else
result = emitUnaryPlus();
break;
case 303:
if ( a1 && a3 )
result = emitSubtraction(a1, a3);
else
result = emitUnaryMinus();
break;
case 304:
result = emitOr(a1, a3);
break;
case 305:
result = emitEqualsOp(a1, a3);
break;
case 306:
result = emitInequalityOp(a1, a3);
break;
case 307:
result = emitLTOp(a1, a3);
break;
case 308:
result = emitLTEOp(a1, a3);
break;
case 309:
result = emitGTOp(a1, a3);
break;
case 310:
result = emitGTEOp(a1, a3);
break;
default:
if ( !a1 )
a1 = a3;
result = emitNot(a1);
break;
}
}
}
return result;
}

original_code:
void emitBabyTree(Symbol *x, int opToken, Symbol *y) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (opToken) {
 case 305:
  emitEqualsOp(x, y);
  break;
 case 306:
  emitInequalityOp(x, y);
  break;
 case 308:
  emitLTEOp(x, y);
  break;
 case 307:
  emitLTOp(x, y);
  break;
 case 310:
  emitGTEOp(x, y);
  break;
 case 309:
  emitGTOp(x, y);
  break;
 case 302:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryPlus(y);
   }
   else {
    emitUnaryPlus(x);
   }
  }
  else {
   emitAddition(x, y);
  }
  break;
 }
 case 303:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryMinus(y);
   }
   else {
    emitUnaryMinus(x);
   }
  }
  else {
   emitSubtraction(x, y);
  }
  break;
 }
 case 304:
  emitOr(x, y);
  break;
 case 298:
  emitDivision(x, y, opToken);
  break;
 case 299:
  emitDivision(x, y, opToken);
  break;
 case 297:
  emitMultiplication(x, y);
  break;
 case 300:
  emitMod(x, y);
  break;
 case 301:
  emitAnd(x, y);
  break;
 case 296:
  if (x) emitNot(x);
  else emitNot(y);
  break;
 case -2:
  emitArrayElementLocation(x, y);
  break;
 case -3:
  emitPushRecordFieldAddress(x, y);
  break;
 case -4:
 {
  if (x) {
   emitFuncInvok(x, x->kindPtr.FuncKind->params);
  } else if (y) {
   emitFuncInvok(y, y->kindPtr.FuncKind->params);
  }
  break;
 }
 default:
  break;
 }
}

canonical_original_code:
void emitBabyTree(struct Symbol *x, int opToken, struct Symbol *y) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (opToken) {
 case 305:
  emitEqualsOp(x, y);
  break;
 case 306:
  emitInequalityOp(x, y);
  break;
 case 308:
  emitLTEOp(x, y);
  break;
 case 307:
  emitLTOp(x, y);
  break;
 case 310:
  emitGTEOp(x, y);
  break;
 case 309:
  emitGTOp(x, y);
  break;
 case 302:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryPlus(y);
   }
   else {
    emitUnaryPlus(x);
   }
  }
  else {
   emitAddition(x, y);
  }
  break;
 }
 case 303:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryMinus(y);
   }
   else {
    emitUnaryMinus(x);
   }
  }
  else {
   emitSubtraction(x, y);
  }
  break;
 }
 case 304:
  emitOr(x, y);
  break;
 case 298:
  emitDivision(x, y, opToken);
  break;
 case 299:
  emitDivision(x, y, opToken);
  break;
 case 297:
  emitMultiplication(x, y);
  break;
 case 300:
  emitMod(x, y);
  break;
 case 301:
  emitAnd(x, y);
  break;
 case 296:
  if (x) emitNot(x);
  else emitNot(y);
  break;
 case -2:
  emitArrayElementLocation(x, y);
  break;
 case -3:
  emitPushRecordFieldAddress(x, y);
  break;
 case -4:
 {
  if (x) {
   emitFuncInvok(x, x->kindPtr.FuncKind->params);
  } else if (y) {
   emitFuncInvok(y, y->kindPtr.FuncKind->params);
  }
  break;
 }
 default:
  break;
 }
}

variable_types: struct Symbol { char *name; enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 } kind; union kind_union { struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value { struct Boolean { int value; } Boolean; struct Char { unsigned char value; } Char; struct Integer { int value; } Integer; struct Real { double value; } Real; struct String { char *str; unsigned int strlen; } String; } value; } *ConstKind; struct FunctionKind { struct Symbol *typeSym; struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *params; char *label; int invocationInstance; } *FuncKind; struct ParamKind { struct Symbol *typeSym; int byRef; } *ParamKind; struct ProcedureKind { struct ElementArray *params; char *label; } *ProcKind; struct TypeKind { union type_union { struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; } *Array; struct Function { struct ParamArray { struct Param { char *name; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; struct Symbol *typeSym; } **data; unsigned int len; unsigned int nElements; } *params; struct Symbol *returnTypeSym; char *label; } *Function; struct Procedure { struct ParamArray *params; char *label; } *Procedure; struct Record { struct hash { struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; } *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; } *hash; } *Record; struct Scalar { struct ElementArray *consts; } *Scalar; struct StringType { unsigned int strlen; } *String; struct Subrange { int high; int low; struct Symbol *baseTypeSym; } *Subrange; } typePtr; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; } *TypeKind; struct VariableKind { struct Symbol *typeSym; int byRef; } *VarKind; } kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; } *

variable_types: opToken int

variable_types:
y
struct Symbol *

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


postOrderWalk

decompiled_code:
__int64 __fastcall postOrderWalk(__int64 *a1)
{
int v1; // edx
__int64 v2; // rbp
__int64 v3; // rax
__int64 result; // rax
__int64 v5; // rax

v1 = *((_DWORD *)a1 + 2);
if ( a1[3] )
{
if ( v1 == -3 )
{
v5 = ((__int64 (*)(void))postOrderWalk)();
emitBabyTree(v5, *((_DWORD *)a1 + 2), *a1);
result = *a1;
}
else
{
v2 = ((__int64 (*)(void))postOrderWalk)();
v3 = postOrderWalk(a1[4]);
emitBabyTree(v2, *((_DWORD *)a1 + 2), v3);
result = *a1;
}
}
else
{
result = *a1;
if ( v1 == -4 )
{
emitBabyTree(*a1, -4, 0LL);
result = getTypeSym(*a1);
*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
int v1; // edx
__int64 v2; // rbp
__int64 v3; // rax
__int64 result; // rax
__int64 v5; // rax

v1 = *((_DWORD *)a1 + 2);
if ( a1[3] )
{
if ( v1 == -3 )
{
v5 = ((__int64 (*)(void))postOrderWalk)();
func0(v5, *((_DWORD *)a1 + 2), *a1);
result = *a1;
}
else
{
v2 = ((__int64 (*)(void))postOrderWalk)();
v3 = func1(a1[4]);
func0(v2, *((_DWORD *)a1 + 2), v3);
result = *a1;
}
}
else
{
result = *a1;
if ( v1 == -4 )
{
func0(*a1, -4, 0LL);
result = getTypeSym(*a1);
*a1 = result;
}
}
return result;
}

original_code:
Symbol *postOrderWalk(struct treeNode *node) {
 Symbol *x = ((void *)0);
 Symbol *y = ((void *)0);
 if (node->left == ((void *)0)) {
  if (node->opToken == -4) {
   emitBabyTree(node->symbol, node->opToken, ((void *)0));
   node->symbol = getTypeSym(node->symbol);
  }
  return node->symbol;
 } else if (node->opToken == -3) {
  x = postOrderWalk(node->left);
  emitBabyTree(x, node->opToken, node->symbol);
  return node->symbol;
 } else {
  x = postOrderWalk(node->left);
  y = postOrderWalk(node->right);
  emitBabyTree(x, node->opToken, y);
  return node->symbol;
 }
}

canonical_original_code:
struct Symbol *postOrderWalk(struct treeNode *node) {
 struct Symbol *x = ((void *)0);
 struct Symbol *y = ((void *)0);
 if (node->left == ((void *)0)) {
  if (node->opToken == -4) {
   emitBabyTree(node->symbol, node->opToken, ((void *)0));
   node->symbol = getTypeSym(node->symbol);
  }
  return node->symbol;
 } else if (node->opToken == -3) {
  x = postOrderWalk(node->left);
  emitBabyTree(x, node->opToken, node->symbol);
  return node->symbol;
 } else {
  x = postOrderWalk(node->left);
  y = postOrderWalk(node->right);
  emitBabyTree(x, node->opToken, y);
  return node->symbol;
 }
}

variable_types: struct treeNode { struct Symbol *symbol; int opToken; struct treeNode *parent; struct treeNode *left; struct treeNode *right; } *

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


allocateTreeNode

decompiled_code:
void *allocateTreeNode()
{
void *result; // rax

result = calloc(1uLL, 0x28uLL);
if ( !result )
err(1, "Could not alloc memory for tree node.");
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

result = calloc(1uLL, 0x28uLL);
if ( !result )
err(1, "Could not alloc memory for tree node.");
return result;
}

original_code:
struct treeNode *allocateTreeNode() {
 struct treeNode *node = calloc(1, sizeof(struct treeNode));
 if ( node == ((void *)0) ) {
  err(1, "Could not alloc memory for tree node.");
  exit(1);
 }
 return node;
}

variable_types: struct treeNode { struct Symbol { char *name; enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 } kind; union kind_union { struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value { struct Boolean { int value; } Boolean; struct Char { unsigned char value; } Char; struct Integer { int value; } Integer; struct Real { double value; } Real; struct String { char *str; unsigned int strlen; } String; } value; } *ConstKind; struct FunctionKind { struct Symbol *typeSym; struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *params; char *label; int invocationInstance; } *FuncKind; struct ParamKind { struct Symbol *typeSym; int byRef; } *ParamKind; struct ProcedureKind { struct ElementArray *params; char *label; } *ProcKind; struct TypeKind { union type_union { struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; } *Array; struct Function { struct ParamArray { struct Param { char *name; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; struct Symbol *typeSym; } **data; unsigned int len; unsigned int nElements; } *params; struct Symbol *returnTypeSym; char *label; } *Function; struct Procedure { struct ParamArray *params; char *label; } *Procedure; struct Record { struct hash { struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; } *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; } *hash; } *Record; struct Scalar { struct ElementArray *consts; } *Scalar; struct StringType { unsigned int strlen; } *String; struct Subrange { int high; int low; struct Symbol *baseTypeSym; } *Subrange; } typePtr; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; } *TypeKind; struct VariableKind { struct Symbol *typeSym; int byRef; } *VarKind; } kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; } *symbol; int opToken; struct treeNode *parent; struct treeNode *left; struct treeNode *right; } *

user_defined_types: struct treeNode { struct Symbol *symbol; int opToken; struct treeNode *parent; struct treeNode *left; struct treeNode *right; }

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }


createErrorString

decompiled_code:
int __fastcall createErrorString(char **a1, const char **a2)
{
size_t v2; // rbp
char *v3; // rax

v2 = strlen(*a2) + 64;
v3 = (char *)calloc(1uLL, v2);
*a1 = v3;
if ( !v3 )
err(1, "Failed to allocate memory to create err msg");
return snprintf(v3, v2, "Error: %s (line %d, col %d)", *a2, *((unsigned int *)a2 + 2), *((unsigned int *)a2 + 3));
}

canonical_decompiled_code:
int __fastcall func0(char **a1, const char **a2)
{
size_t v2; // rbp
char *v3; // rax

v2 = strlen(*a2) + 64;
v3 = (char *)calloc(1uLL, v2);
*a1 = v3;
if ( !v3 )
err(1, "Failed to allocate memory to create err msg");
return snprintf(v3, v2, "Error: %s (line %d, col %d)", *a2, *((unsigned int *)a2 + 2), *((unsigned int *)a2 + 3));
}

original_code:
void createErrorString(char **buf, struct Error *e)
{
 int extraChars = 64;
 size_t size = sizeof(char)*(strlen(e->msg) + extraChars);
 if (!e) return;
 *buf = calloc(1, size);
 if (!*buf) {
  err(1, "Failed to allocate memory to create err msg");
  return;
 }
 snprintf(*buf, size, "Error: %s (line %d, col %d)",
   e->msg, e->lineno, e->colno);
}

canonical_original_code:
void createErrorString(char **buf, struct Error *e)
{
 int extraChars = 64;
 unsigned long size = sizeof(char)*(strlen(e->msg) + extraChars);
 if (!e) return;
 *buf = calloc(1, size);
 if (!*buf) {
  err(1, "Failed to allocate memory to create err msg");
  return;
 }
 snprintf(*buf, size, "Error: %s (line %d, col %d)",
   e->msg, e->lineno, e->colno);
}

variable_types:
buf
char **

variable_types: struct Error { char *msg; int lineno; int colno; enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 } type; } *

variable_types: extraChars int

variable_types:
size
unsigned long

user_defined_types: struct Error { char *msg; int lineno; int colno; enum ErrorType type; }


customErrorString

decompiled_code:
char *customErrorString(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(msg_0, 0x3FFuLL, format, arg);
byte_6BF = 0;
return msg_0;
}

canonical_decompiled_code:
char *func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(msg_0, 0x3FFuLL, format, arg);
byte_6BF = 0;
return msg_0;
}

original_code:
char *
customErrorString(char * errMsg, ...)
{
 static char msg[1024];
 va_list args;
 __builtin_va_start(args,errMsg);
 vsnprintf(msg, 1024 -1, errMsg, args);
 __builtin_va_end(args);
 msg[1024 - 1] = '\0';
 return msg;
}

canonical_original_code:
char *customErrorString(char *errMsg, ...)
{
 static char msg[1024];
 __builtin_va_list args;
 __builtin_va_start(args,errMsg);
 vsnprintf(msg, 1024 -1, errMsg, args);
 __builtin_va_end(args);
 msg[1024 - 1] = '\0';
 return msg;
}

variable_types:
errMsg
char *

variable_types:
msg
char [1024]

return_type: char *


freeError

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void freeError(struct Error *e)
{
 if (!e) return;
 if (e->msg) free(e->msg);
 free(e);
}

user_defined_types: enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 }


getErrorTypeString

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

result = "Syntax";
if ( a1 != 1 )
{
result = "Semantic";
if ( a1 != 2 )
result = 0LL;
}
return result;
}

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

result = "Syntax";
if ( a1 != 1 )
{
result = "Semantic";
if ( a1 != 2 )
result = 0LL;
}
return result;
}

original_code:
char *getErrorTypeString(enum ErrorType type)
{
 if (type == SYNTAX) {
  return "Syntax";
 } else if (type == SEMANTIC) {
  return "Semantic";
 } else {
  return ((void *)0);
 }
}

variable_types: enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 }


printError

decompiled_code:
void __fastcall printError(__int64 a1)
{
const char *v1; // rax
__int64 v2; // r9
__int64 v3; // rcx

if ( a1 )
{
v1 = getErrorTypeString(*(_DWORD *)(a1 + 16));
fprintf(
stdout,
"%d %s Error: %s (%d, %d)\n",
(unsigned int)v2,
v1,
*(const char **)v3,
v2,
*(unsigned int *)(v3 + 12));
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
const char *v1; // rax
__int64 v2; // r9
__int64 v3; // rcx

if ( a1 )
{
v1 = func3(*(_DWORD *)(a1 + 16));
fprintf(
stdout,
"%d %s Error: %s (%d, %d)\n",
(unsigned int)v2,
v1,
*(const char **)v3,
v2,
*(unsigned int *)(v3 + 12));
}
}

original_code:
void printError(struct Error *e)
{
 if (!e) return;
 fprintf(stdout, "%d %s Error: %s (%d, %d)\n",
     e->lineno,
     getErrorTypeString(e->type),
     e->msg,
     e->lineno,
     e->colno);
}


opError

decompiled_code:
__int64 __fastcall opError(__int64 a1, int a2)
{
__int128 *v2; // rax
const char *v3; // r10
const char *v4; // r11
__int64 v5; // rax

v2 = opToString(a2);
v5 = customErrorString(
"Invalid expression. Types %s and %s not compatible with operator %s",
v3,
v4,
(const char *)v2);
return recordError(v5, yylineno, colno, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int128 *v2; // rax
const char *v3; // r10
const char *v4; // r11
__int64 v5; // rax

v2 = opToString(a2);
v5 = customErrorString(
"Invalid expression. Types %s and %s not compatible with operator %s",
v3,
v4,
(const char *)v2);
return recordError(v5, yylineno, colno, 2LL);
}

original_code:
void
opError(char *xType, int op, char *yType)
{
 errMsg = customErrorString("Invalid expression. Types %s and %s"
     " not compatible with operator %s", xType, yType,
     opToString(op));
 recordError(errMsg, yylineno, colno, SEMANTIC);
}

variable_types:
xType
char *

variable_types: op int

variable_types:
yType
char *


alreadyDefinedError

decompiled_code:
__int64 __fastcall alreadyDefinedError(const char *a1)
{
__int64 v1; // rax

v1 = customErrorString("The identifer %s is already defined at the current scope.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 v1; // rax

v1 = customErrorString("The identifer %s is already defined at the current scope.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

original_code:
void
alreadyDefinedError(char *id) {
 errMsg = customErrorString("The identifer %s is already defined at "
    "the current scope.", id);
 recordError(errMsg, yylineno, colno, SEMANTIC);
}

variable_types:
id
char *


notDefinedError

decompiled_code:
__int64 __fastcall notDefinedError(const char *a1)
{
__int64 v1; // rax

v1 = customErrorString("The identifier %s is undefined.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v1; // rax

v1 = customErrorString("The identifier %s is undefined.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

original_code:
void
notDefinedError(char *id) {
 errMsg = customErrorString("The identifier %s is undefined.", id);
 recordError(errMsg, yylineno, colno, SEMANTIC);
}


symbolTableInsertFailure

decompiled_code:
void __noreturn symbolTableInsertFailure()
{
err(1, "Failed to insert into symbol table.");
}

canonical_decompiled_code:
void __noreturn func3()
{
err(1, "Failed to insert into symbol table.");
}

original_code:
void symbolTableInsertFailure() {
 err(1, "Failed to insert into symbol table.");
}


isLogicalOperator

decompiled_code:
_BOOL8 __fastcall isLogicalOperator(int a1)
{
_BOOL8 result; // rax

if ( (unsigned int)(a1 - 296) > 8 )
result = 0LL;
else
result = ((1LL << ((unsigned __int8)a1 - 40)) & 0x121) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1)
{
_BOOL8 result; // rax

if ( (unsigned int)(a1 - 296) > 8 )
result = 0LL;
else
result = ((1LL << ((unsigned __int8)a1 - 40)) & 0x121) != 0;
return result;
}

original_code:
int
isLogicalOperator(int op)
{
 switch (op) {
 case 296:
 case 301:
 case 304:
  return 1;
 default:
  return 0;
 }
}


isRelationalOperator

decompiled_code:
_BOOL8 __fastcall isRelationalOperator(int a1)
{
return (unsigned int)(a1 - 305) <= 5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1)
{
return (unsigned int)(a1 - 305) <= 5;
}

original_code:
int
isRelationalOperator(int op)
{
 switch (op) {
 case 305:
 case 306:
 case 307:
 case 308:
 case 309:
 case 310:
  return 1;
 default:
  return 0;
 }
}


isUnaryOperator

decompiled_code:
__int64 __fastcall isUnaryOperator(int a1)
{
return (a1 == 296) | (unsigned __int8)((unsigned int)(a1 - 302) <= 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return (a1 == 296) | (unsigned __int8)((unsigned int)(a1 - 302) <= 1);
}

original_code:
int
isUnaryOperator(int op)
{
 if ( (op == 302) ||
  (op == 303) ||
     (op == 296) ) {
  return 1;
 }
 return 0;
}


getStrlen

decompiled_code:
__int64 __fastcall getStrlen(__int64 a1, __int64 a2)
{
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
return a2;
}

original_code:
int getStrlen(struct String s)
{
 return s.strlen;
}

variable_types: struct String { char *str; unsigned int strlen; }


checkErrnoStrtoX

decompiled_code:
int *checkErrnoStrtoX()
{
int *result; // rax
char *v1; // rax
__int64 v2; // rax

result = _errno_location();
if ( *result )
{
v1 = strerror(*result);
v2 = customErrorString("Error parsing numerical constant: %s", v1);
result = (int *)recordError(v2, yylineno, colno, 2LL);
}
return result;
}

canonical_decompiled_code:
int *func8()
{
int *result; // rax
char *v1; // rax
__int64 v2; // rax

result = _errno_location();
if ( *result )
{
v1 = strerror(*result);
v2 = customErrorString("Error parsing numerical constant: %s", v1);
result = (int *)recordError(v2, yylineno, colno, 2LL);
}
return result;
}

original_code:
void checkErrnoStrtoX() {
 if ((*__errno_location ()) != 0) {
  errMsg = customErrorString("Error parsing numerical constant: "
      "%s", strerror((*__errno_location ())));
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
}


freeErrorList

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

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
freeError(*v2);
free(v2);
}
while ( v1 );
}
}

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

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
freeError(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void
freeErrorList(struct ErrorLL *ell)
{
 struct ErrorLL *copy;
 while (ell) {
  copy = ell;
  ell = ell->next;
  freeError(copy->error);
  free(copy);
 }
}

variable_types: struct ErrorLL { struct Error { char *msg; int lineno; int colno; enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 } type; } *error; struct ErrorLL *next; } *

user_defined_types: struct ErrorLL { struct Error *error; struct ErrorLL *next; }


growElementArray

decompiled_code:
void __fastcall growElementArray(__int64 a1)
{
__int64 v1; // rsi
void *v2; // rax

if ( a1 )
{
v1 = (unsigned int)(2 * *(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = v1;
v2 = realloc(*(void **)a1, 8 * v1);
*(_QWORD *)a1 = v2;
if ( !v2 )
err(1, "Failled reallocate memory to grow elements array!");
}
}

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

if ( a1 )
{
v1 = (unsigned int)(2 * *(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = v1;
v2 = realloc(*(void **)a1, 8 * v1);
*(_QWORD *)a1 = v2;
if ( !v2 )
err(1, "Failled reallocate memory to grow elements array!");
}
}

original_code:
void
growElementArray(struct ElementArray *ea)
{
 if (!ea) {
  return;
 }
 ea->len = (ea->len) * 2;
 ea->data = realloc(ea->data,sizeof(void *)*(ea->len));
 if (!ea->data) {
  err(1, "Failled reallocate memory to grow elements array!");
  exit(1);
 }
}

variable_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *


appendElement

decompiled_code:
__int64 __fastcall appendElement(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rcx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( v2 == *(_DWORD *)(a1 + 8) - 1 )
{
growElementArray(a1);
v2 = *(_DWORD *)(a1 + 12);
}
v3 = v2;
result = v2 + 1;
*(_QWORD *)(*(_QWORD *)a1 + 8 * v3) = a2;
*(_DWORD *)(a1 + 12) = result;
return result;
}

original_code:
void
appendElement(struct ElementArray *ea, void *element)
{
 if (ea->nElements == (ea->len - 1)) {
  growElementArray(ea);
 }
 ea->data[ea->nElements] = element;
 ea->nElements++;
}

variable_types:
element
void *

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }


hasDuplicateElement

decompiled_code:
__int64 __fastcall hasDuplicateElement(__int64 a1)
{
int v1; // eax
const char ***v2; // r15
__int64 v3; // r13
const char ***v4; // r14
const char ***v5; // rbx
unsigned int v6; // er12
const char *v7; // rbp

if ( !a1 )
err(1, "Cannot check duplicate elements in element due to NULL pointer!");
v1 = *(_DWORD *)(a1 + 12);
if ( v1 )
{
v2 = *(const char ****)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
v4 = *(const char ****)a1;
do
{
v5 = v2;
v6 = 0;
v7 = **v4;
do
{
if ( !strcmp(v7, **v5) )
{
if ( v6 == 1 )
return v6;
v6 = 1;
}
++v5;
}
while ( v5 != (const char ***)v3 );
++v4;
}
while ( v4 != v5 );
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // eax
const char ***v2; // r15
__int64 v3; // r13
const char ***v4; // r14
const char ***v5; // rbx
unsigned int v6; // er12
const char *v7; // rbp

if ( !a1 )
err(1, "Cannot check duplicate elements in element due to NULL pointer!");
v1 = *(_DWORD *)(a1 + 12);
if ( v1 )
{
v2 = *(const char ****)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
v4 = *(const char ****)a1;
do
{
v5 = v2;
v6 = 0;
v7 = **v4;
do
{
if ( !strcmp(v7, **v5) )
{
if ( v6 == 1 )
return v6;
v6 = 1;
}
++v5;
}
while ( v5 != (const char ***)v3 );
++v4;
}
while ( v4 != v5 );
}
return 0;
}

original_code:
int
hasDuplicateElement(struct ElementArray *ea){
 int i,j,count;
 Symbol *sym1;
 Symbol *sym2;
 if(!ea){
  err(1, "Cannot check duplicate elements in element due to NULL pointer!");
  exit(1);
 }
 for(i=0; i<(ea->nElements); i++){
  count = 0;
  sym1 = ((Symbol **)ea->data)[i];
  for(j =0; j <(ea->nElements); j++){
   sym2 = ((Symbol **)ea->data)[j];
   if(strcmp(sym1->name,sym2->name)==0){
    count++;
   }
   if(count >=2){
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int hasDuplicateElement(struct ElementArray *ea){
 int i; int j; int count;
 struct Symbol *sym1;
 struct Symbol *sym2;
 if(!ea){
  err(1, "Cannot check duplicate elements in element due to NULL pointer!");
  exit(1);
 }
 for(i=0; i<(ea->nElements); i++){
  count = 0;
  sym1 = ((struct Symbol **)ea->data)[i];
  for(j =0; j <(ea->nElements); j++){
   sym2 = ((struct Symbol **)ea->data)[j];
   if(strcmp(sym1->name,sym2->name)==0){
    count++;
   }
   if(count >=2){
    return 1;
   }
  }
 }
 return 0;
}

variable_types: i int

variable_types: j int

variable_types: count int

variable_types: struct Symbol { char *name; enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 } kind; union kind_union { struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value { struct Boolean { int value; } Boolean; struct Char { unsigned char value; } Char; struct Integer { int value; } Integer; struct Real { double value; } Real; struct String { char *str; unsigned int strlen; } String; } value; } *ConstKind; struct FunctionKind { struct Symbol *typeSym; struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *params; char *label; int invocationInstance; } *FuncKind; struct ParamKind { struct Symbol *typeSym; int byRef; } *ParamKind; struct ProcedureKind { struct ElementArray *params; char *label; } *ProcKind; struct TypeKind { union type_union { struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; } *Array; struct Function { struct ParamArray { struct Param { char *name; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; struct Symbol *typeSym; } **data; unsigned int len; unsigned int nElements; } *params; struct Symbol *returnTypeSym; char *label; } *Function; struct Procedure { struct ParamArray *params; char *label; } *Procedure; struct Record { struct hash { struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; } *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; } *hash; } *Record; struct Scalar { struct ElementArray *consts; } *Scalar; struct StringType { unsigned int strlen; } *String; struct Subrange { int high; int low; struct Symbol *baseTypeSym; } *Subrange; } typePtr; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; } *TypeKind; struct VariableKind { struct Symbol *typeSym; int byRef; } *VarKind; } kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; } *

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


appendElementArray

decompiled_code:
char **__fastcall appendElementArray(char **a1, _DWORD *a2)
{
unsigned int v3; // ebx
__int64 v5; // rsi
unsigned int v6; // eax
char *v7; // rax
char *v8; // rdx
unsigned int v9; // eax
__int64 v10; // rdi
__int64 v11; // rax
char *v12; // rdx
__int64 v13; // rcx

if ( !a1 || !a2 )
err(1, "One of the element arrays is a null pointer!");
v3 = *((_DWORD *)a1 + 3);
v5 = (unsigned int)(*((_DWORD *)a1 + 2) + a2[2]);
v6 = v3 + a2[3];
*((_DWORD *)a1 + 2) = v5;
*((_DWORD *)a1 + 3) = v6;
v7 = (char *)realloc(*a1, 8 * v5);
*a1 = v7;
v8 = v7;
if ( !v7 )
err(1, "Failled reallocate memory to grow elements array!");
v9 = *((_DWORD *)a1 + 3);
if ( v3 < v9 )
{
v10 = 8LL * (v9 - 1 - v3) + 8;
v11 = 0LL;
while ( 1 )
{
v12 = &v8[v11];
v13 = *(_QWORD *)(*(_QWORD *)a2 + v11);
v11 += 8LL;
*(_QWORD *)&v12[8 * v3] = v13;
if ( v10 == v11 )
break;
v8 = *a1;
}
}
free(a2);
return a1;
}

canonical_decompiled_code:
char **__fastcall func3(char **a1, _DWORD *a2)
{
unsigned int v3; // ebx
__int64 v5; // rsi
unsigned int v6; // eax
char *v7; // rax
char *v8; // rdx
unsigned int v9; // eax
__int64 v10; // rdi
__int64 v11; // rax
char *v12; // rdx
__int64 v13; // rcx

if ( !a1 || !a2 )
err(1, "One of the element arrays is a null pointer!");
v3 = *((_DWORD *)a1 + 3);
v5 = (unsigned int)(*((_DWORD *)a1 + 2) + a2[2]);
v6 = v3 + a2[3];
*((_DWORD *)a1 + 2) = v5;
*((_DWORD *)a1 + 3) = v6;
v7 = (char *)realloc(*a1, 8 * v5);
*a1 = v7;
v8 = v7;
if ( !v7 )
err(1, "Failled reallocate memory to grow elements array!");
v9 = *((_DWORD *)a1 + 3);
if ( v3 < v9 )
{
v10 = 8LL * (v9 - 1 - v3) + 8;
v11 = 0LL;
while ( 1 )
{
v12 = &v8[v11];
v13 = *(_QWORD *)(*(_QWORD *)a2 + v11);
v11 += 8LL;
*(_QWORD *)&v12[8 * v3] = v13;
if ( v10 == v11 )
break;
v8 = *a1;
}
}
free(a2);
return a1;
}

original_code:
struct ElementArray *
appendElementArray(struct ElementArray *ea1, struct ElementArray *ea2){
 int i ;
 int appendIndex ;
 if(!ea1 || !ea2){
  err(1, "One of the element arrays is a null pointer!");
  exit(1);
 }
 appendIndex = ea1->nElements;
 ea1->len += ea2->len;
 ea1->nElements += ea2->nElements;
 ea1->data = realloc(ea1->data,sizeof(void *)*(ea1->len));
 if(!ea1->data){
  err(1, "Failled reallocate memory to grow elements array!");
  exit(1);
 }
 for(i= appendIndex; i < ea1->nElements ; i++ ){
  ea1->data[i] = ea2->data[i-appendIndex];
 }
 free(ea2);
 return ea1;
}

canonical_original_code:
struct ElementArray *appendElementArray(struct ElementArray *ea1, struct ElementArray *ea2){
 int i;
 int appendIndex;
 if(!ea1 || !ea2){
  err(1, "One of the element arrays is a null pointer!");
  exit(1);
 }
 appendIndex = ea1->nElements;
 ea1->len += ea2->len;
 ea1->nElements += ea2->nElements;
 ea1->data = realloc(ea1->data,sizeof(void *)*(ea1->len));
 if(!ea1->data){
  err(1, "Failled reallocate memory to grow elements array!");
  exit(1);
 }
 for(i= appendIndex; i < ea1->nElements ; i++ ){
  ea1->data[i] = ea2->data[i-appendIndex];
 }
 free(ea2);
 return ea1;
}

variable_types: appendIndex int

return_type: struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *


getElementAt

decompiled_code:
__int64 __fastcall getElementAt(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 12) - 1 < a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 12) - 1 < a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
void *
getElementAt(struct ElementArray *ea, unsigned int i)
{
 if (i > (ea->nElements-1)) {
  return ((void *)0);
 }
 return ea->data[i];
}

canonical_original_code:
void *getElementAt(struct ElementArray *ea, unsigned int i)
{
 if (i > (ea->nElements-1)) {
  return ((void *)0);
 }
 return ea->data[i];
}

variable_types:
i
unsigned int

return_type: void *


freeElementArray

decompiled_code:
void __fastcall freeElementArray(void *ptr)
{
int v1; // edx
_QWORD *v2; // rax
__int64 v3; // rdx

v1 = *((_DWORD *)ptr + 3);
if ( v1 != 1 )
{
v2 = *(_QWORD **)ptr;
v3 = *(_QWORD *)ptr + 8LL * (unsigned int)(v1 - 2) + 8;
do
{
if ( !*v2 )
BUG();
++v2;
}
while ( v2 != (_QWORD *)v3 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
int v1; // edx
_QWORD *v2; // rax
__int64 v3; // rdx

v1 = *((_DWORD *)ptr + 3);
if ( v1 != 1 )
{
v2 = *(_QWORD **)ptr;
v3 = *(_QWORD *)ptr + 8LL * (unsigned int)(v1 - 2) + 8;
do
{
if ( !*v2 )
BUG();
++v2;
}
while ( v2 != (_QWORD *)v3 );
}
free(ptr);
}

original_code:
void freeElementArray(struct ElementArray *ea) {
 int i;
 for (i = 0; i < (ea->nElements-1); i++) {
  if(!ea->data[i]){
   free(((Symbol **)ea->data)[i]->name);
   free(ea->data[i]);
  }
 }
 free(ea);
}

canonical_original_code:
void freeElementArray(struct ElementArray *ea) {
 int i;
 for (i = 0; i < (ea->nElements-1); i++) {
  if(!ea->data[i]){
   free(((struct Symbol **)ea->data)[i]->name);
   free(ea->data[i]);
  }
 }
 free(ea);
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


emitAnd

decompiled_code:
__int64 __fastcall emitAnd(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( a1 && (result = doNotEmit, !doNotEmit) && a2 )
{
result = emitLogicalPrep(a1, a2, v3);
if ( v3[0] == 1 )
result = emitStmt(128LL, &unk_210);
}
else
{
doNotEmit = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( a1 && (result = doNotEmit, !doNotEmit) && a2 )
{
result = func0(a1, a2, v3);
if ( v3[0] == 1 )
result = emitStmt(128LL, &unk_210);
}
else
{
doNotEmit = 1;
}
return result;
}

original_code:
void emitAnd(Symbol *x, Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "AND");
  break;
 case -1:
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitAnd(struct Symbol *x, struct Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "AND");
  break;
 case -1:
  break;
 default:
  break;
 }
}

variable_types:
y
struct Symbol *

variable_types: opType int

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


emitOr

decompiled_code:
__int64 __fastcall emitOr(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( a1 && (result = doNotEmit, !doNotEmit) && a2 )
{
result = emitLogicalPrep(a1, a2, v3);
if ( v3[0] == 1 )
result = emitStmt(128LL, &unk_214);
}
else
{
doNotEmit = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( a1 && (result = doNotEmit, !doNotEmit) && a2 )
{
result = func0(a1, a2, v3);
if ( v3[0] == 1 )
result = emitStmt(128LL, &unk_214);
}
else
{
doNotEmit = 1;
}
return result;
}

original_code:
void emitOr(Symbol *x, Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "OR");
  break;
 case -1:
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitOr(struct Symbol *x, struct Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "OR");
  break;
 case -1:
  break;
 default:
  break;
 }
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


initialize

decompiled_code:
__int64 initialize()
{
symbolTable = createHash(&getHashedKeyNormal);
if ( !symbolTable )
err(1, "Could not create symbolTable.");
preDefTypeSymbols = initializePreDefTypes();
if ( !preDefTypeSymbols )
err(1, "Could not create pre-defined types.");
stmts = 0LL;
emitInit();
initializePreDefProc();
initializePreDefFunc();
initializePreDefConstants();
errors = 0LL;
whileLoopDepth = 0LL;
labelStack = newLabelStack();
loopLabelStack = newLabelStack();
procOrFuncStack = newLabelStack();
mainLabelStack = newLabelStack();
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
symbolTable = createHash(&getHashedKeyNormal);
if ( !symbolTable )
err(1, "Could not create symbolTable.");
preDefTypeSymbols = initializePreDefTypes();
if ( !preDefTypeSymbols )
err(1, "Could not create pre-defined types.");
stmts = 0LL;
emitInit();
initializePreDefProc();
initializePreDefFunc();
initializePreDefConstants();
errors = 0LL;
whileLoopDepth = 0LL;
labelStack = newLabelStack();
loopLabelStack = newLabelStack();
procOrFuncStack = newLabelStack();
mainLabelStack = newLabelStack();
return 0LL;
}

original_code:
int initialize() {
 symbolTable = createHash(&getHashedKeyNormal);
 if (symbolTable == ((void *)0)) {
  err(1, "Could not create symbolTable.");
  exit(1);
 }
 preDefTypeSymbols = initializePreDefTypes();
 if (preDefTypeSymbols == ((void *)0)) {
  err(1, "Could not create pre-defined types.");
  exit(1);
 }
 stmts = ((void *)0);
 emitInit();
 initializePreDefProc();
 initializePreDefFunc();
 initializePreDefConstants();
 errors = ((void *)0);
 whileLoopDepth = 0;
 labelStack = newLabelStack();
 loopLabelStack = newLabelStack();
 procOrFuncStack = newLabelStack();
 mainLabelStack = newLabelStack();
 return 0;
}


deInitialize

decompiled_code:
__int64 deInitialize()
{
destroyHash(&symbolTable);
destroyLabelStack(&labelStack);
destroyLabelStack(&loopLabelStack);
destroyLabelStack(&procOrFuncStack);
freeStmtLL(stmts);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
destroyHash(&symbolTable);
destroyLabelStack(&labelStack);
destroyLabelStack(&loopLabelStack);
destroyLabelStack(&procOrFuncStack);
freeStmtLL(stmts);
return 0LL;
}

original_code:
int deInitialize() {
 destroyHash(&symbolTable);
 destroyLabelStack(&labelStack);
 destroyLabelStack(&loopLabelStack);
 destroyLabelStack(&procOrFuncStack);
 freeStmtLL(stmts);
 return 0;
}