createScalarListType

decompiled_code:
__int64 __fastcall createScalarListType(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v1 = newAnonScalarListTypeSym();
v2 = v1;
if ( !v1 )
err(1, "Failed to create scalar list symbol.");
if ( (unsigned int)addToSymbolTable(symbolTable, v1) )
symbolTableInsertFailure();
setSymbolOffset(v2, symbolTable);
return v2;
}

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

if ( !a1 )
return 0LL;
v1 = newAnonScalarListTypeSym();
v2 = v1;
if ( !v1 )
err(1, "Failed to create scalar list symbol.");
if ( (unsigned int)addToSymbolTable(symbolTable, v1) )
symbolTableInsertFailure();
setSymbolOffset(v2, symbolTable);
return v2;
}

original_code:
Symbol *createScalarListType(struct ElementArray *ea) {
 Symbol *s = ((void *)0);
 if (!ea) return ((void *)0);
 s = newAnonScalarListTypeSym(ea);
 if (s == ((void *)0)) {
  err(1, "Failed to create scalar list symbol.");
 }
 if (addToSymbolTable(symbolTable, s) != 0) {
  symbolTableInsertFailure();
 }
 setSymbolOffset(s, symbolTable);
 return s;
}

canonical_original_code:
struct Symbol *createScalarListType(struct ElementArray *ea) {
 struct Symbol *s = ((void *)0);
 if (!ea) return ((void *)0);
 s = newAnonScalarListTypeSym(ea);
 if (s == ((void *)0)) {
  err(1, "Failed to create scalar list symbol.");
 }
 if (addToSymbolTable(symbolTable, s) != 0) {
  symbolTableInsertFailure();
 }
 setSymbolOffset(s, symbolTable);
 return s;
}

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: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

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


createArrayType

repo: a-krebs/YACC

decompiled_code:
__int64 __fastcall createArrayType(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx

v2 = newAnonArraySym(a2, a1);
v3 = v2;
if ( v2 && (unsigned int)addToSymbolTable(symbolTable, v2) )
symbolTableInsertFailure();
return v3;
}

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

v2 = newAnonArraySym(a2, a1);
v3 = v2;
if ( v2 && (unsigned int)addToSymbolTable(symbolTable, v2) )
symbolTableInsertFailure();
return v3;
}

original_code:
Symbol *createArrayType(Symbol *index, Symbol *base) {
 Symbol * newArraySym = ((void *)0);
 newArraySym = newAnonArraySym(base, index);
 if (newArraySym == ((void *)0)) {
  return ((void *)0);
 }
 if (addToSymbolTable(symbolTable, newArraySym) != 0) {
  symbolTableInsertFailure();
 }
 return newArraySym;
}

canonical_original_code:
struct Symbol *createArrayType(struct Symbol *index, struct Symbol *base) {
 struct Symbol *newArraySym = ((void *)0);
 newArraySym = newAnonArraySym(base, index);
 if (newArraySym == ((void *)0)) {
  return ((void *)0);
 }
 if (addToSymbolTable(symbolTable, newArraySym) != 0) {
  symbolTableInsertFailure();
 }
 return newArraySym;
}

variable_types:
index
struct Symbol *

variable_types:
base
struct Symbol *

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


assertArrIndexType

decompiled_code:
__int64 __fastcall assertArrIndexType(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
const char *v3; // rax
__int64 v4; // rax

v1 = a1;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) == 4 )
{
v2 = getType();
if ( (v2 & 0xFFFFFFFD) != 8 && v2 - 2 > 1 )
{
v3 = (const char *)typeToString(v2);
v4 = customErrorString("Invalid array index type %s. Must be of type SUBRANGE or of type SCALAR", v3);
recordError(v4, yylineno, colno, 2LL);
v1 = 0LL;
}
}
else
{
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
const char *v3; // rax
__int64 v4; // rax

v1 = a1;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) == 4 )
{
v2 = getType();
if ( (v2 & 0xFFFFFFFD) != 8 && v2 - 2 > 1 )
{
v3 = (const char *)typeToString(v2);
v4 = customErrorString("Invalid array index type %s. Must be of type SUBRANGE or of type SCALAR", v3);
recordError(v4, yylineno, colno, 2LL);
v1 = 0LL;
}
}
else
{
v1 = 0LL;
}
}
return v1;
}

original_code:
Symbol *assertArrIndexType(Symbol *index_type) {
 type_t sym_t;
 if (!index_type) return ((void *)0);
 if (index_type->kind != TYPE_KIND) return ((void *)0);
 sym_t = getType(index_type);
 if ( (sym_t != SUBRANGE_T) && (sym_t != SCALAR_T) && (sym_t != CHAR_T)
     && (sym_t != BOOLEAN_T)) {
  errMsg = customErrorString("Invalid array index type %s. "
      " Must be of type SUBRANGE or of type SCALAR",
      typeToString(sym_t));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 return index_type;
}

canonical_original_code:
struct Symbol *assertArrIndexType(struct Symbol *index_type) {
 enum type_t sym_t;
 if (!index_type) return ((void *)0);
 if (index_type->kind != TYPE_KIND) return ((void *)0);
 sym_t = getType(index_type);
 if ( (sym_t != SUBRANGE_T) && (sym_t != SCALAR_T) && (sym_t != CHAR_T)
     && (sym_t != BOOLEAN_T)) {
  errMsg = customErrorString("Invalid array index type %s. "
      " Must be of type SUBRANGE or of type SCALAR",
      typeToString(sym_t));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 return index_type;
}

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: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }


createRangeType

decompiled_code:
__int64 __fastcall createRangeType(__int64 *a1, _QWORD *a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
result = *a1;
if ( *a1 )
{
if ( *a2 )
{
if ( *(_DWORD *)(result + 8) || *(_DWORD *)(*a2 + 8LL) )
recordError("Cannot define array indices using non-constant expressions.", yylineno, colno, 2LL);
result = newSubrangeSym(*a1, *a2);
}
else
{
result = 0LL;
}
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
result = *a1;
if ( *a1 )
{
if ( *a2 )
{
if ( *(_DWORD *)(result + 8) || *(_DWORD *)(*a2 + 8LL) )
recordError("Cannot define array indices using non-constant expressions.", yylineno, colno, 2LL);
result = newSubrangeSym(*a1, *a2);
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
Symbol *createRangeType(struct treeNode *lower, struct treeNode *upper) {
 Symbol *s = ((void *)0);
 if (!(lower) || !(upper)) return ((void *)0);
 if (!(lower->symbol) || !(upper->symbol)) return ((void *)0);
 if ( (lower->symbol->kind != CONST_KIND) || (upper->symbol->kind
     != CONST_KIND)) {
  recordError("Cannot define array indices using non-constant "
  "expressions.", yylineno, colno, SEMANTIC);
 }
 s = newSubrangeSym(lower->symbol, upper->symbol);
 return s;
}

canonical_original_code:
struct Symbol *createRangeType(struct treeNode *lower, struct treeNode *upper) {
 struct Symbol *s = ((void *)0);
 if (!(lower) || !(upper)) return ((void *)0);
 if (!(lower->symbol) || !(upper->symbol)) return ((void *)0);
 if ( (lower->symbol->kind != CONST_KIND) || (upper->symbol->kind
     != CONST_KIND)) {
  recordError("Cannot define array indices using non-constant "
  "expressions.", yylineno, colno, SEMANTIC);
 }
 s = newSubrangeSym(lower->symbol, upper->symbol);
 return s;
}

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

variable_types:
upper
struct treeNode *

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


createRecordType

decompiled_code:
__int64 __fastcall createRecordType(__int64 a1)
{
unsigned int v1; // er12
const char **v2; // rax
const char **v3; // rbx
const char *v4; // r13
__int64 v5; // rax
__int64 v6; // rbp
int v7; // er15
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // [rsp+8h] [rbp-50h]
int v11; // [rsp+10h] [rbp-48h]
int v12; // [rsp+14h] [rbp-44h]
__int64 v13; // [rsp+18h] [rbp-40h]

v13 = newRecordTypeSym(0LL);
v10 = ***(_QWORD ***)(v13 + 16);
v12 = getCurrentLexLevel(v10);
if ( *(_DWORD *)(a1 + 12) )
{
v1 = 0;
v11 = 0;
do
{
v2 = (const char **)getElementAt(a1, v1);
v3 = v2;
if ( v2 )
{
v4 = *v2;
if ( *v2 )
{
v5 = getTypeSym(v2);
v6 = newVariableSym(v4, v5);
*(_DWORD *)(v6 + 24) = v12;
v7 = *(_DWORD *)(v6 + 36) + v11;
v11 = v7;
if ( getLocalSymbol(v10) )
{
v8 = customErrorString("Record field with name %s already defined.", v4);
recordError(v8, yylineno, colno, 2LL);
freeProxySymbol(v3);
}
else if ( (unsigned int)addToSymbolTable(v10, v6) )
{
freeProxySymbol(v3);
}
else
{
v11 = *(_DWORD *)(v6 + 36) + v7;
setSymbolOffset(v6, v10);
}
}
else
{
freeProxySymbol(v2);
}
}
++v1;
}
while ( *(_DWORD *)(a1 + 12) > v1 );
}
else
{
v11 = 0;
}
result = v13;
*(_DWORD *)(v13 + 36) = v11;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // er12
const char **v2; // rax
const char **v3; // rbx
const char *v4; // r13
__int64 v5; // rax
__int64 v6; // rbp
int v7; // er15
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // [rsp+8h] [rbp-50h]
int v11; // [rsp+10h] [rbp-48h]
int v12; // [rsp+14h] [rbp-44h]
__int64 v13; // [rsp+18h] [rbp-40h]

v13 = newRecordTypeSym(0LL);
v10 = ***(_QWORD ***)(v13 + 16);
v12 = getCurrentLexLevel(v10);
if ( *(_DWORD *)(a1 + 12) )
{
v1 = 0;
v11 = 0;
do
{
v2 = (const char **)getElementAt(a1, v1);
v3 = v2;
if ( v2 )
{
v4 = *v2;
if ( *v2 )
{
v5 = getTypeSym(v2);
v6 = newVariableSym(v4, v5);
*(_DWORD *)(v6 + 24) = v12;
v7 = *(_DWORD *)(v6 + 36) + v11;
v11 = v7;
if ( getLocalSymbol(v10) )
{
v8 = customErrorString("Record field with name %s already defined.", v4);
recordError(v8, yylineno, colno, 2LL);
freeProxySymbol(v3);
}
else if ( (unsigned int)addToSymbolTable(v10, v6) )
{
freeProxySymbol(v3);
}
else
{
v11 = *(_DWORD *)(v6 + 36) + v7;
setSymbolOffset(v6, v10);
}
}
else
{
freeProxySymbol(v2);
}
}
++v1;
}
while ( *(_DWORD *)(a1 + 12) > v1 );
}
else
{
v11 = 0;
}
result = v13;
*(_DWORD *)(v13 + 36) = v11;
return result;
}

original_code:
Symbol *createRecordType(struct ElementArray *fields) {
 Symbol *recType = ((void *)0);
 Symbol *newField = ((void *)0);
 int recordLexLvl = -1, recordSize = 0;
 ProxySymbol *f = ((void *)0);
 struct hash *recHash = ((void *)0);
 char *fieldId;
 recType = newRecordTypeSym(((void *)0));
 recHash = recType->kindPtr.TypeKind->typePtr.Record->hash;
 recordLexLvl = getCurrentLexLevel(recHash);
 for (int i = 0; i < fields->nElements; i++) {
  f = getElementAt(fields, i);
  if (!f) continue;
  fieldId = f->name;
  if (!fieldId) {
   freeProxySymbol(f);
   continue;
  }
  newField = newVariableSym(fieldId, getTypeSym(f));
  newField->lvl = recordLexLvl;
  recordSize += newField->size;
  if (getLocalSymbol(recHash, fieldId) != ((void *)0)) {
   errMsg = customErrorString(
       "Record field with name %s already defined.",
       fieldId);
   recordError(errMsg, yylineno, colno, SEMANTIC);
   freeProxySymbol(f);
   continue;
  }
  if (addToSymbolTable(recHash, newField) != 0) {
   freeProxySymbol(f);
   continue;
  }
  recordSize += newField->size;
  setSymbolOffset(newField, recHash);
 }
 recType->size = recordSize;
 return recType;
}

canonical_original_code:
struct Symbol *createRecordType(struct ElementArray *fields) {
 struct Symbol *recType = ((void *)0);
 struct Symbol *newField = ((void *)0);
 int recordLexLvl = -1; int recordSize = 0;
 struct Symbol *f = ((void *)0);
 struct hash *recHash = ((void *)0);
 char *fieldId;
 recType = newRecordTypeSym(((void *)0));
 recHash = recType->kindPtr.TypeKind->typePtr.Record->hash;
 recordLexLvl = getCurrentLexLevel(recHash);
 for (int i = 0; i < fields->nElements; i++) {
  f = getElementAt(fields, i);
  if (!f) continue;
  fieldId = f->name;
  if (!fieldId) {
   freeProxySymbol(f);
   continue;
  }
  newField = newVariableSym(fieldId, getTypeSym(f));
  newField->lvl = recordLexLvl;
  recordSize += newField->size;
  if (getLocalSymbol(recHash, fieldId) != ((void *)0)) {
   errMsg = customErrorString(
       "Record field with name %s already defined.",
       fieldId);
   recordError(errMsg, yylineno, colno, SEMANTIC);
   freeProxySymbol(f);
   continue;
  }
  if (addToSymbolTable(recHash, newField) != 0) {
   freeProxySymbol(f);
   continue;
  }
  recordSize += newField->size;
  setSymbolOffset(newField, recHash);
 }
 recType->size = recordSize;
 return recType;
}

variable_types:
fields
struct ElementArray *

variable_types: recordLexLvl int

variable_types: recordSize int

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

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


createRecordMemberList

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

v1 = newElementArray();
growElementArray(v1);
if ( a1 )
appendElement(v1, a1);
return v1;
}

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

v1 = newElementArray();
growElementArray(v1);
if ( a1 )
appendElement(v1, a1);
return v1;
}

original_code:
struct ElementArray *createRecordMemberList(ProxySymbol *field) {
 struct ElementArray *ea = ((void *)0);
 ea = newElementArray();
 growElementArray(ea);
 if (field) {
  appendElement(ea, field);
 }
 return ea;
}

canonical_original_code:
struct ElementArray *createRecordMemberList(struct Symbol *field) {
 struct ElementArray *ea = ((void *)0);
 ea = newElementArray();
 growElementArray(ea);
 if (field) {
  appendElement(ea, field);
 }
 return ea;
}

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 *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: struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *

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

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


appendToRecordMemberList

decompiled_code:
__int64 __fastcall appendToRecordMemberList(__int64 a1, __int64 a2)
{
if ( a1 && a2 )
appendElement(a1, a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
if ( a1 && a2 )
appendElement(a1, a2);
return a1;
}

original_code:
struct ElementArray *appendToRecordMemberList(
    struct ElementArray *array, ProxySymbol *field) {
 if (!array) return ((void *)0);
 if (field) {
  appendElement(array, field);
 }
 return array;
}

canonical_original_code:
struct ElementArray *appendToRecordMemberList(struct ElementArray *array, struct Symbol *field) {
 if (!array) return ((void *)0);
 if (field) {
  appendElement(array, field);
 }
 return array;
}

variable_types:
array
struct ElementArray *

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

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

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 Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

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


newRecordFieldProxy

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

if ( a2 && a1 )
result = newVariableSym(a1, a2);
else
result = 0LL;
return result;
}

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

if ( a2 && a1 )
result = newVariableSym(a1, a2);
else
result = 0LL;
return result;
}

original_code:
ProxySymbol *newRecordFieldProxy(char *id, Symbol *type) {
 ProxySymbol *newField = ((void *)0);
 if (!id) return ((void *)0);
 if (!type) return ((void *)0);
 newField = newVariableSym(id, type);
 return newField;
}

canonical_original_code:
struct Symbol *newRecordFieldProxy(char *id, struct Symbol *type) {
 struct Symbol *newField = ((void *)0);
 if (!id) return ((void *)0);
 if (!type) return ((void *)0);
 newField = newVariableSym(id, type);
 return newField;
}

variable_types:
id
char *

variable_types:
type
struct Symbol *

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: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: struct ElementArray { void **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; }


emitPushVarAddress

decompiled_code:
void __fastcall emitPushVarAddress(__int64 a1)
{
if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( (unsigned int)getType() - 1 <= 7 )
{
if ( (unsigned int)isByReference(a1) )
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
else
emitStmt(128LL, "PUSHA %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( (unsigned int)getType() - 1 <= 7 )
{
if ( (unsigned int)isByReference(a1) )
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
else
emitStmt(128LL, "PUSHA %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitPushVarAddress(Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch(getType(s)) {
 case ARRAY_T:
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case REAL_T:
 case RECORD_T:
 case SCALARINT_T:
 case SCALAR_T:
 {
  if (!isByReference(s)) {
   emitStmt(128, "PUSHA %d[%d]", s->offset,
       s->lvl);
  } else {
   emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
  }
  break;
 }
 default:
  return;
  break;
 }
}

canonical_original_code:
void emitPushVarAddress(struct Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch(getType(s)) {
 case ARRAY_T:
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case REAL_T:
 case RECORD_T:
 case SCALARINT_T:
 case SCALAR_T:
 {
  if (!isByReference(s)) {
   emitStmt(128, "PUSHA %d[%d]", s->offset,
       s->lvl);
  } else {
   emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
  }
  break;
 }
 default:
  return;
  break;
 }
}

return_type: void

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 TypeKind { union type_union typePtr; enum type_t type; }

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


emitPushVarValue

decompiled_code:
void __fastcall emitPushVarValue(__int64 a1)
{
unsigned int v1; // eax

if ( !a1 )
{
doNotEmit = 1;
return;
}
if ( doNotEmit )
{
doNotEmit = 1;
return;
}
v1 = getType();
if ( v1 > 5 )
{
if ( v1 != 8 )
return;
LABEL_11:
if ( (unsigned int)isByReference(a1) )
{
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
emitStmt(128LL, "PUSHI");
return;
}
LABEL_12:
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
return;
}
if ( v1 > 1 )
goto LABEL_11;
if ( v1 == 1 )
{
if ( !(unsigned int)isByReference(a1) )
{
emitStmt(128LL, "PUSHA %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
return;
}
goto LABEL_12;
}
}

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

if ( !a1 )
{
doNotEmit = 1;
return;
}
if ( doNotEmit )
{
doNotEmit = 1;
return;
}
v1 = getType();
if ( v1 > 5 )
{
if ( v1 != 8 )
return;
LABEL_11:
if ( (unsigned int)isByReference(a1) )
{
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
emitStmt(128LL, "PUSHI");
return;
}
LABEL_12:
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
return;
}
if ( v1 > 1 )
goto LABEL_11;
if ( v1 == 1 )
{
if ( !(unsigned int)isByReference(a1) )
{
emitStmt(128LL, "PUSHA %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
return;
}
goto LABEL_12;
}
}

original_code:
void emitPushVarValue(Symbol *s)
{
  do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (getType(s)) {
 case ARRAY_T:
  if (!isByReference(s)) {
    emitStmt(128, "PUSHA %d[%d]", s->offset, s->lvl);
   } else {
    emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
  }
  break;
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case REAL_T:
 case SCALAR_T:
 {
  if (!isByReference(s)) {
    emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
   } else {
    emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
    emitStmt(128, "PUSHI");
  }
  break;
 }
 case STRING_T:
  break;
 default:
  return;
 }
}

canonical_original_code:
void emitPushVarValue(struct Symbol *s)
{
  do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (getType(s)) {
 case ARRAY_T:
  if (!isByReference(s)) {
    emitStmt(128, "PUSHA %d[%d]", s->offset, s->lvl);
   } else {
    emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
  }
  break;
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case REAL_T:
 case SCALAR_T:
 {
  if (!isByReference(s)) {
    emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
   } else {
    emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
    emitStmt(128, "PUSHI");
  }
  break;
 }
 case STRING_T:
  break;
 default:
  return;
 }
}

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

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 String { char *str; unsigned int strlen; }

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

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


emitPushStructuredVarValue

decompiled_code:
__int64 __fastcall emitPushStructuredVarValue(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

if ( a1 )
{
v1 = doNotEmit;
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
result = emitComment("Pushing values of array %s onto stack", *(const char **)a1);
if ( *(int *)(a1 + 36) > 0 )
{
do
result = emitStmt(
128LL,
"PUSH %d[%d]",
(unsigned int)(*(_DWORD *)(a1 + 32) + v1++),
*(unsigned int *)(a1 + 24));
while ( *(_DWORD *)(a1 + 36) > v1 );
}
}
}
else
{
doNotEmit = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

if ( a1 )
{
v1 = doNotEmit;
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
result = emitComment("Pushing values of array %s onto stack", *(const char **)a1);
if ( *(int *)(a1 + 36) > 0 )
{
do
result = emitStmt(
128LL,
"PUSH %d[%d]",
(unsigned int)(*(_DWORD *)(a1 + 32) + v1++),
*(unsigned int *)(a1 + 24));
while ( *(_DWORD *)(a1 + 36) > v1 );
}
}
}
else
{
doNotEmit = 1;
}
return result;
}

original_code:
void emitPushStructuredVarValue(Symbol *s)
{
 int i;
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Pushing values of array %s onto stack", s->name);
 for (i = 0; i < s->size; i++) {
  emitStmt(128, "PUSH %d[%d]", s->offset + i,
      s->lvl);
 }
}

canonical_original_code:
void emitPushStructuredVarValue(struct Symbol *s)
{
 int i;
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Pushing values of array %s onto stack", s->name);
 for (i = 0; i < s->size; i++) {
  emitStmt(128, "PUSH %d[%d]", s->offset + i,
      s->lvl);
 }
}

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: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: struct ElementArray { void **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; }


emitPushAddressValue

decompiled_code:
void __fastcall emitPushAddressValue(__int64 a1)
{
unsigned int v1; // eax
int v2; // ebp

if ( !a1 )
{
doNotEmit = 1;
return;
}
if ( doNotEmit )
{
doNotEmit = 1;
return;
}
v1 = getType();
if ( v1 == 6 )
goto LABEL_12;
if ( v1 > 6 )
{
if ( v1 == 7 )
goto LABEL_9;
return;
}
if ( v1 == 1 )
{
LABEL_12:
if ( *(int *)(a1 + 36) > 1 )
{
v2 = 1;
do
{
emitComment("Array/Record %s location %d below on stack", *(const char **)a1, (unsigned int)(v2 - 1));
emitComment("need to push corresponding value");
if ( *(_DWORD *)(a1 + 36) > v2 )
{
emitStmt(128LL, "DUP");
emitStmt(128LL, "ADJUST -1");
}
emitStmt(128LL, "PUSHI");
if ( *(_DWORD *)(a1 + 36) > v2 )
{
emitComment("Set up next iteration.");
emitStmt(128LL, "ADJUST 1");
emitStmt(128LL, "CONSTI 1");
emitStmt(128LL, "ADDI");
}
++v2;
}
while ( *(_DWORD *)(a1 + 36) > v2 );
}
return;
}
if ( v1 - 2 <= 3 )
LABEL_9:
emitStmt(128LL, "PUSHI");
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned int v1; // eax
int v2; // ebp

if ( !a1 )
{
doNotEmit = 1;
return;
}
if ( doNotEmit )
{
doNotEmit = 1;
return;
}
v1 = getType();
if ( v1 == 6 )
goto LABEL_12;
if ( v1 > 6 )
{
if ( v1 == 7 )
goto LABEL_9;
return;
}
if ( v1 == 1 )
{
LABEL_12:
if ( *(int *)(a1 + 36) > 1 )
{
v2 = 1;
do
{
emitComment("Array/Record %s location %d below on stack", *(const char **)a1, (unsigned int)(v2 - 1));
emitComment("need to push corresponding value");
if ( *(_DWORD *)(a1 + 36) > v2 )
{
emitStmt(128LL, "DUP");
emitStmt(128LL, "ADJUST -1");
}
emitStmt(128LL, "PUSHI");
if ( *(_DWORD *)(a1 + 36) > v2 )
{
emitComment("Set up next iteration.");
emitStmt(128LL, "ADJUST 1");
emitStmt(128LL, "CONSTI 1");
emitStmt(128LL, "ADDI");
}
++v2;
}
while ( *(_DWORD *)(a1 + 36) > v2 );
}
return;
}
if ( v1 - 2 <= 3 )
LABEL_9:
emitStmt(128LL, "PUSHI");
}

original_code:
void emitPushAddressValue(Symbol *s)
{
 int i;
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (getType(s)) {
 case ARRAY_T:
 case RECORD_T:
  for (i = 1; i < s->size; i++) {
   emitComment("Array/Record %s location %d below on "
   "stack", s->name, i - 1);
   emitComment("need to push corresponding value");
   if (i < s->size) {
    emitStmt(128, "DUP");
    emitStmt(128, "ADJUST -1");
   }
   emitStmt(128, "PUSHI");
   if (i < s->size) {
    emitComment("Set up next iteration.");
    emitStmt(128, "ADJUST 1");
    emitStmt(128, "CONSTI 1");
    emitStmt(128, "ADDI");
   }
  }
  break;
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case SCALARINT_T:
 case REAL_T:
  emitStmt(128, "PUSHI");
  break;
 case SCALAR_T:
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitPushAddressValue(struct Symbol *s)
{
 int i;
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (getType(s)) {
 case ARRAY_T:
 case RECORD_T:
  for (i = 1; i < s->size; i++) {
   emitComment("Array/Record %s location %d below on "
   "stack", s->name, i - 1);
   emitComment("need to push corresponding value");
   if (i < s->size) {
    emitStmt(128, "DUP");
    emitStmt(128, "ADJUST -1");
   }
   emitStmt(128, "PUSHI");
   if (i < s->size) {
    emitComment("Set up next iteration.");
    emitStmt(128, "ADJUST 1");
    emitStmt(128, "CONSTI 1");
    emitStmt(128, "ADDI");
   }
  }
  break;
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case SCALARINT_T:
 case REAL_T:
  emitStmt(128, "PUSHI");
  break;
 case SCALAR_T:
  break;
 default:
  break;
 }
}

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 TypeKind { union type_union typePtr; enum type_t type; }

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


emitPushRecordFieldAddress

decompiled_code:
__int64 __fastcall emitPushRecordFieldAddress(const char **a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
emitComment("Calculating offset of record field %s in record %s", *(const char **)a2, *a1);
if ( *((_DWORD *)a1 + 11) )
{
emitComment("%s is a record head, so we push its address", *a1);
emitStmt(128LL, "PUSHA %d[%d]", *((unsigned int *)a1 + 8), *((unsigned int *)a1 + 6));
}
emitStmt(128LL, "CONSTI %d", *(unsigned int *)(a2 + 32));
result = emitStmt(128LL, "ADDI", *(unsigned int *)(a2 + 32));
}
else
{
doNotEmit = 1;
}
}
else
{
doNotEmit = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char **a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
emitComment("Calculating offset of record field %s in record %s", *(const char **)a2, *a1);
if ( *((_DWORD *)a1 + 11) )
{
emitComment("%s is a record head, so we push its address", *a1);
emitStmt(128LL, "PUSHA %d[%d]", *((unsigned int *)a1 + 8), *((unsigned int *)a1 + 6));
}
emitStmt(128LL, "CONSTI %d", *(unsigned int *)(a2 + 32));
result = emitStmt(128LL, "ADDI", *(unsigned int *)(a2 + 32));
}
else
{
doNotEmit = 1;
}
}
else
{
doNotEmit = 1;
}
return result;
}

original_code:
void emitPushRecordFieldAddress(Symbol *record, Symbol *field)
{
 do { if(!(record) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(field) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Calculating offset of record field %s in record %s",
     field->name, record->name);
 if (record->isRecordHead) {
  emitComment("%s is a record head, so we push its "
      "address", record->name);
  emitStmt(128, "PUSHA %d[%d]", record->offset,
      record->lvl);
 }
 emitStmt(128, "CONSTI %d", field->offset);
 emitStmt(128, "ADDI", field->offset);
}

canonical_original_code:
void emitPushRecordFieldAddress(struct Symbol *record, struct Symbol *field)
{
 do { if(!(record) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(field) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Calculating offset of record field %s in record %s",
     field->name, record->name);
 if (record->isRecordHead) {
  emitComment("%s is a record head, so we push its "
      "address", record->name);
  emitStmt(128, "PUSHA %d[%d]", record->offset,
      record->lvl);
 }
 emitStmt(128, "CONSTI %d", field->offset);
 emitStmt(128, "ADDI", field->offset);
}

variable_types:
field
struct Symbol *

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

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 String { char *str; unsigned int strlen; }

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

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


emitPushStringLiteralValue

decompiled_code:
__int64 __fastcall emitPushStringLiteralValue(__int64 a1)
{
char *v1; // rbp
int v2; // er12
char *v3; // rbx
__int64 v4; // rbp

v1 = *(char **)((__int64 (*)(void))getConstVal)();
v2 = *(_DWORD *)(getConstVal(a1) + 8);
emitComment("Allocating memory for string literal.");
emitStmt(128LL, "ALLOC %d", (unsigned int)v2);
emitComment("We now push the values in the string constant ");
emitComment("onto the stack.");
if ( v2 > 0 )
{
v3 = v1;
v4 = (__int64)&v1[v2 - 1 + 1];
do
emitStmt(128LL, "CONSTI %d", (unsigned int)*v3++);
while ( v3 != (char *)v4 );
}
emitComment("We push the length of the string onto the stack");
emitStmt(128LL, "CONSTI %d", (unsigned int)v2);
emitComment("We call the pre-defined function which will store the ");
emitComment("appropriate values at the allocated memory location");
emitStmt(128LL, "CALL 0, __store_string_values");
emitComment("On return, we leave the allocated address on the stack");
emitStmt(128LL, "ADJUST -%d", (unsigned int)(v2 + 1));
emitComment("Now we change the address we save such that elements");
emitComment("appear in increasing order from this address so it is");
emitComment("as if they were on the stack (for compatability reasons)");
emitStmt(128LL, "CONSTI -%d", (unsigned int)(v2 - 1));
return emitStmt(128LL, "ADDI");
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
char *v1; // rbp
int v2; // er12
char *v3; // rbx
__int64 v4; // rbp

v1 = *(char **)((__int64 (*)(void))getConstVal)();
v2 = *(_DWORD *)(getConstVal(a1) + 8);
emitComment("Allocating memory for string literal.");
emitStmt(128LL, "ALLOC %d", (unsigned int)v2);
emitComment("We now push the values in the string constant ");
emitComment("onto the stack.");
if ( v2 > 0 )
{
v3 = v1;
v4 = (__int64)&v1[v2 - 1 + 1];
do
emitStmt(128LL, "CONSTI %d", (unsigned int)*v3++);
while ( v3 != (char *)v4 );
}
emitComment("We push the length of the string onto the stack");
emitStmt(128LL, "CONSTI %d", (unsigned int)v2);
emitComment("We call the pre-defined function which will store the ");
emitComment("appropriate values at the allocated memory location");
emitStmt(128LL, "CALL 0, __store_string_values");
emitComment("On return, we leave the allocated address on the stack");
emitStmt(128LL, "ADJUST -%d", (unsigned int)(v2 + 1));
emitComment("Now we change the address we save such that elements");
emitComment("appear in increasing order from this address so it is");
emitComment("as if they were on the stack (for compatability reasons)");
emitStmt(128LL, "CONSTI -%d", (unsigned int)(v2 - 1));
return emitStmt(128LL, "ADDI");
}

original_code:
void emitPushStringLiteralValue(Symbol *s)
{
 char *str;
 int i, strlen;
 str = getConstVal(s)->String.str;
 strlen = getConstVal(s)->String.strlen;
 emitComment("Allocating memory for string literal.");
 emitStmt(128, "ALLOC %d", strlen);
 emitComment("We now push the values in the string constant ");
 emitComment("onto the stack.");
 for (i = 0; i < strlen; i++) {
  emitStmt(128, "CONSTI %d", *(str + i));
 }
 emitComment("We push the length of the string onto the stack");
 emitStmt(128, "CONSTI %d", strlen);
 emitComment("We call the pre-defined function which will store the ");
 emitComment("appropriate values at the allocated memory location");
 emitStmt(128, "CALL 0, __store_string_values");
 emitComment("On return, we leave the allocated address on the stack");
 emitStmt(128, "ADJUST -%d", strlen + 1);
 emitComment("Now we change the address we save such that elements");
 emitComment("appear in increasing order from this address so it is");
 emitComment("as if they were on the stack (for compatability reasons)");
 emitStmt(128, "CONSTI -%d", strlen - 1);
 emitStmt(128, "ADDI");
}

canonical_original_code:
void emitPushStringLiteralValue(struct Symbol *s)
{
 char *str;
 int i; int strlen;
 str = getConstVal(s)->String.str;
 strlen = getConstVal(s)->String.strlen;
 emitComment("Allocating memory for string literal.");
 emitStmt(128, "ALLOC %d", strlen);
 emitComment("We now push the values in the string constant ");
 emitComment("onto the stack.");
 for (i = 0; i < strlen; i++) {
  emitStmt(128, "CONSTI %d", *(str + i));
 }
 emitComment("We push the length of the string onto the stack");
 emitStmt(128, "CONSTI %d", strlen);
 emitComment("We call the pre-defined function which will store the ");
 emitComment("appropriate values at the allocated memory location");
 emitStmt(128, "CALL 0, __store_string_values");
 emitComment("On return, we leave the allocated address on the stack");
 emitStmt(128, "ADJUST -%d", strlen + 1);
 emitComment("Now we change the address we save such that elements");
 emitComment("appear in increasing order from this address so it is");
 emitComment("as if they were on the stack (for compatability reasons)");
 emitStmt(128, "CONSTI -%d", strlen - 1);
 emitStmt(128, "ADDI");
}

variable_types:
str
char *

variable_types: strlen 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: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: struct ElementArray { void **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; }


emitPushAnonConstValue

decompiled_code:
void __fastcall emitPushAnonConstValue(__int64 a1)
{
unsigned int *v1; // rax
unsigned __int8 *v2; // rax
double *v3; // rax
unsigned int *v4; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
switch ( (unsigned int)getType() )
{
case 2u:
case 4u:
v1 = (unsigned int *)getConstVal(a1);
emitStmt(128LL, "CONSTI %d", *v1);
break;
case 3u:
v2 = (unsigned __int8 *)getConstVal(a1);
emitStmt(128LL, "CONSTI %d", *v2);
break;
case 5u:
v3 = (double *)getConstVal(a1);
emitStmt(128LL, "CONSTR %f", *v3);
break;
case 7u:
v4 = (unsigned int *)getConstVal(a1);
emitStmt(128LL, "CONSTI %d", *v4);
break;
case 9u:
emitPushStringLiteralValue(a1);
break;
default:
return;
}
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
unsigned int *v1; // rax
unsigned __int8 *v2; // rax
double *v3; // rax
unsigned int *v4; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
switch ( (unsigned int)getType() )
{
case 2u:
case 4u:
v1 = (unsigned int *)getConstVal(a1);
emitStmt(128LL, "CONSTI %d", *v1);
break;
case 3u:
v2 = (unsigned __int8 *)getConstVal(a1);
emitStmt(128LL, "CONSTI %d", *v2);
break;
case 5u:
v3 = (double *)getConstVal(a1);
emitStmt(128LL, "CONSTR %f", *v3);
break;
case 7u:
v4 = (unsigned int *)getConstVal(a1);
emitStmt(128LL, "CONSTI %d", *v4);
break;
case 9u:
func5(a1);
break;
default:
return;
}
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitPushAnonConstValue(Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (getType(s)) {
 case BOOLEAN_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Boolean.value);
  break;
 case CHAR_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Char.value);
  break;
 case INTEGER_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Integer.value);
  break;
 case REAL_T:
  emitStmt(128, "CONSTR %f",
      getConstVal(s)->Real.value);
  break;
 case SCALARINT_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Integer.value);
  break;
 case STRING_T:
  emitPushStringLiteralValue(s);
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitPushAnonConstValue(struct Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (getType(s)) {
 case BOOLEAN_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Boolean.value);
  break;
 case CHAR_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Char.value);
  break;
 case INTEGER_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Integer.value);
  break;
 case REAL_T:
  emitStmt(128, "CONSTR %f",
      getConstVal(s)->Real.value);
  break;
 case SCALARINT_T:
  emitStmt(128, "CONSTI %d",
      getConstVal(s)->Integer.value);
  break;
 case STRING_T:
  emitPushStringLiteralValue(s);
  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; } *

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 TypeKind { union type_union typePtr; enum type_t type; }


emitPushConstValue

decompiled_code:
void __fastcall emitPushConstValue(__int64 a1)
{
unsigned int v1; // eax
const char *v2; // rax
unsigned int v3; // eax
const char *v4; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( *(_QWORD *)a1 )
{
v1 = getType();
v2 = (const char *)typeToString(v1);
emitComment("Pushing value of const %s of type %s onto stack.", *(const char **)a1, v2);
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}
else
{
v3 = getType();
v4 = (const char *)typeToString(v3);
emitComment("Pushing anonymous constant value of type %s", v4);
emitPushAnonConstValue(a1);
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
unsigned int v1; // eax
const char *v2; // rax
unsigned int v3; // eax
const char *v4; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( *(_QWORD *)a1 )
{
v1 = getType();
v2 = (const char *)typeToString(v1);
emitComment("Pushing value of const %s of type %s onto stack.", *(const char **)a1, v2);
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}
else
{
v3 = getType();
v4 = (const char *)typeToString(v3);
emitComment("Pushing anonymous constant value of type %s", v4);
func6(a1);
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitPushConstValue(Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 if (s->name) {
  emitComment("Pushing value of const %s of type %s onto stack.",
      s->name, typeToString(getType(s)));
  emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
 } else {
  emitComment("Pushing anonymous constant value of type %s",
      typeToString(getType(s)));
  emitPushAnonConstValue(s);
 }
}

canonical_original_code:
void emitPushConstValue(struct Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 if (s->name) {
  emitComment("Pushing value of const %s of type %s onto stack.",
      s->name, typeToString(getType(s)));
  emitStmt(128, "PUSH %d[%d]", s->offset, s->lvl);
 } else {
  emitComment("Pushing anonymous constant value of type %s",
      typeToString(getType(s)));
  emitPushAnonConstValue(s);
 }
}

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

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


emitPushSymbolValue

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

if ( !a1 || doNotEmit )
{
doNotEmit = 1;
}
else
{
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 4 )
{
if ( *(_DWORD *)(a1 + 40) )
emitStmt(128LL, "PUSHI");
}
else if ( v1 == 5 )
{
emitPushVarValue(a1);
}
else
{
if ( v1 )
{
fprintf(
stderr,
"Trying to push value of a symbol which cannot possibly have a value. Yylineno sez %d\n",
yylineno);
exit(1);
}
emitPushConstValue(a1);
}
}
}

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

if ( !a1 || doNotEmit )
{
doNotEmit = 1;
}
else
{
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 4 )
{
if ( *(_DWORD *)(a1 + 40) )
emitStmt(128LL, "PUSHI");
}
else if ( v1 == 5 )
{
func1(a1);
}
else
{
if ( v1 )
{
fprintf(
stderr,
"Trying to push value of a symbol which cannot possibly have a value. Yylineno sez %d\n",
yylineno);
exit(1);
}
func7(a1);
}
}
}

original_code:
void emitPushSymbolValue(Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (s->kind) {
 case CONST_KIND:
  emitPushConstValue(s);
  break;
 case VAR_KIND:
  emitPushVarValue(s);
  break;
 case TYPE_KIND:
  if (s->isAddress) {
   emitStmt(128, "PUSHI");
  } else {
  }
  break;
 default:
  fprintf(stderr, "Trying to push value of a symbol which cannot "
      "possibly have a value.  Yylineno sez %d\n", yylineno);
  exit(1);
 }
}

canonical_original_code:
void emitPushSymbolValue(struct Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (s->kind) {
 case CONST_KIND:
  emitPushConstValue(s);
  break;
 case VAR_KIND:
  emitPushVarValue(s);
  break;
 case TYPE_KIND:
  if (s->isAddress) {
   emitStmt(128, "PUSHI");
  } else {
  }
  break;
 default:
  fprintf(stderr, "Trying to push value of a symbol which cannot "
      "possibly have a value.  Yylineno sez %d\n", yylineno);
  exit(1);
 }
}

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: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

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


emitArrayElementLocation

decompiled_code:
__int64 __fastcall emitArrayElementLocation(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
int v5; // er12
int v6; // eax
int v7; // eax
int v8; // eax
unsigned int v9; // eax
__int64 v10; // rax

v2 = a2;
v3 = getTypeSym();
if ( a2 )
{
v4 = v3;
v5 = 0;
do
{
if ( !givenArgs[2] )
{
emitComment("Doing array bounds checking.");
v6 = *(_DWORD *)(v2 + 8);
if ( v6 != 5 && (v6 || (unsigned int)isConstResultSym(v2)) )
{
emitStmt(128LL, "DUP");
emitStmt(128LL, "DUP");
}
else
{
emitPushSymbolValue(v2);
emitPushSymbolValue(v2);
emitPushSymbolValue(v2);
}
emitComment("Checking < high bound");
v7 = getArrayHighIndexValue(v4);
emitStmt(128LL, "CONSTI %d", (unsigned int)(v7 + 1));
emitStmt(128LL, "LTI");
emitStmt(128LL, "IFZ __array_error");
emitComment("Checking > low bound");
v8 = getArrayLowIndexValue(v4);
emitStmt(128LL, "CONSTI %d", (unsigned int)(v8 - 1));
emitStmt(128LL, "GTI");
emitStmt(128LL, "IFZ __array_error");
}
emitComment("Pushing index_val - index_lowerbound_val for");
emitComment("location calculation.");
if ( (*(_DWORD *)(v2 + 8) || !(unsigned int)isConstResultSym(v2)) && givenArgs[2] )
emitPushSymbolValue(v2);
v9 = getArrayLowIndexValue(v4);
emitStmt(128LL, "CONSTI %d", v9);
emitStmt(128LL, "SUBI");
emitComment("Pushing size of base type.");
v10 = getArrayBaseSym(v4);
emitStmt(128LL, "CONSTI %d", *(unsigned int *)(v10 + 36));
emitStmt(128LL, "MULI");
if ( v5 )
emitStmt(128LL, "ADDI");
v2 = *(_QWORD *)(v2 + 48);
v4 = getArrayBaseSym(v4);
v5 = 1;
}
while ( v2 );
}
if ( *(_DWORD *)(a1 + 8) == 5 && !*(_DWORD *)(a1 + 40) )
{
emitComment("We now push the base address of the array");
emitPushVarAddress(a1);
}
return emitStmt(128LL, "ADDI");
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
int v5; // er12
int v6; // eax
int v7; // eax
int v8; // eax
unsigned int v9; // eax
__int64 v10; // rax

v2 = a2;
v3 = getTypeSym();
if ( a2 )
{
v4 = v3;
v5 = 0;
do
{
if ( !givenArgs[2] )
{
emitComment("Doing array bounds checking.");
v6 = *(_DWORD *)(v2 + 8);
if ( v6 != 5 && (v6 || (unsigned int)isConstResultSym(v2)) )
{
emitStmt(128LL, "DUP");
emitStmt(128LL, "DUP");
}
else
{
func8(v2);
func8(v2);
func8(v2);
}
emitComment("Checking < high bound");
v7 = getArrayHighIndexValue(v4);
emitStmt(128LL, "CONSTI %d", (unsigned int)(v7 + 1));
emitStmt(128LL, "LTI");
emitStmt(128LL, "IFZ __array_error");
emitComment("Checking > low bound");
v8 = getArrayLowIndexValue(v4);
emitStmt(128LL, "CONSTI %d", (unsigned int)(v8 - 1));
emitStmt(128LL, "GTI");
emitStmt(128LL, "IFZ __array_error");
}
emitComment("Pushing index_val - index_lowerbound_val for");
emitComment("location calculation.");
if ( (*(_DWORD *)(v2 + 8) || !(unsigned int)isConstResultSym(v2)) && givenArgs[2] )
func8(v2);
v9 = getArrayLowIndexValue(v4);
emitStmt(128LL, "CONSTI %d", v9);
emitStmt(128LL, "SUBI");
emitComment("Pushing size of base type.");
v10 = getArrayBaseSym(v4);
emitStmt(128LL, "CONSTI %d", *(unsigned int *)(v10 + 36));
emitStmt(128LL, "MULI");
if ( v5 )
emitStmt(128LL, "ADDI");
v2 = *(_QWORD *)(v2 + 48);
v4 = getArrayBaseSym(v4);
v5 = 1;
}
while ( v2 );
}
if ( *(_DWORD *)(a1 + 8) == 5 && !*(_DWORD *)(a1 + 40) )
{
emitComment("We now push the base address of the array");
func0(a1);
}
return emitStmt(128LL, "ADDI");
}

original_code:
void emitArrayElementLocation(Symbol* arrayBase, Symbol *indices)
{
 Symbol *arrayType = ((void *)0);
 int onceThrough = 0, lowVal, baseTypeSize;
 arrayType = getTypeSym(arrayBase);
 while (indices) {
  if (!(givenArgs.a)) {
   emitComment("Doing array bounds checking.");
   if ( (indices->kind == VAR_KIND) || (indices->kind
       == CONST_KIND && !isConstResultSym(indices)) ) {
    emitPushSymbolValue(indices);
    emitPushSymbolValue(indices);
    emitPushSymbolValue(indices);
   } else {
    emitStmt(128, "DUP");
    emitStmt(128, "DUP");
   }
   emitComment("Checking < high bound");
   emitStmt(128, "CONSTI %d",
       getArrayHighIndexValue(arrayType) + 1);
   emitStmt(128, "LTI");
   emitStmt(128, "IFZ __array_error");
   emitComment("Checking > low bound");
   emitStmt(128, "CONSTI %d",
       getArrayLowIndexValue(arrayType) - 1);
   emitStmt(128, "GTI");
   emitStmt(128, "IFZ __array_error");
  }
  emitComment("Pushing index_val - index_lowerbound_val for");
  emitComment("location calculation.");
  if ( (!(indices->kind == CONST_KIND &&
      isConstResultSym(indices))) && (givenArgs.a))
   emitPushSymbolValue(indices);
  lowVal = getArrayLowIndexValue(arrayType);
  emitStmt(128, "CONSTI %d", lowVal);
  emitStmt(128, "SUBI");
  emitComment("Pushing size of base type.");
  baseTypeSize = getArrayBaseSym(arrayType)->size;
  emitStmt(128, "CONSTI %d", baseTypeSize);
  emitStmt(128, "MULI");
  if (onceThrough) emitStmt(128, "ADDI");
  else onceThrough = 1;
  indices = indices->next;
  arrayType = getArrayBaseSym(arrayType);
 }
 if (arrayBase->kind == VAR_KIND && !(arrayBase->isAddress)) {
  emitComment("We now push the base address of the array");
  emitPushVarAddress(arrayBase);
 }
 emitStmt(128, "ADDI");
}

canonical_original_code:
void emitArrayElementLocation(struct Symbol *arrayBase, struct Symbol *indices)
{
 struct Symbol *arrayType = ((void *)0);
 int onceThrough = 0; int lowVal; int baseTypeSize;
 arrayType = getTypeSym(arrayBase);
 while (indices) {
  if (!(givenArgs.a)) {
   emitComment("Doing array bounds checking.");
   if ( (indices->kind == VAR_KIND) || (indices->kind
       == CONST_KIND && !isConstResultSym(indices)) ) {
    emitPushSymbolValue(indices);
    emitPushSymbolValue(indices);
    emitPushSymbolValue(indices);
   } else {
    emitStmt(128, "DUP");
    emitStmt(128, "DUP");
   }
   emitComment("Checking < high bound");
   emitStmt(128, "CONSTI %d",
       getArrayHighIndexValue(arrayType) + 1);
   emitStmt(128, "LTI");
   emitStmt(128, "IFZ __array_error");
   emitComment("Checking > low bound");
   emitStmt(128, "CONSTI %d",
       getArrayLowIndexValue(arrayType) - 1);
   emitStmt(128, "GTI");
   emitStmt(128, "IFZ __array_error");
  }
  emitComment("Pushing index_val - index_lowerbound_val for");
  emitComment("location calculation.");
  if ( (!(indices->kind == CONST_KIND &&
      isConstResultSym(indices))) && (givenArgs.a))
   emitPushSymbolValue(indices);
  lowVal = getArrayLowIndexValue(arrayType);
  emitStmt(128, "CONSTI %d", lowVal);
  emitStmt(128, "SUBI");
  emitComment("Pushing size of base type.");
  baseTypeSize = getArrayBaseSym(arrayType)->size;
  emitStmt(128, "CONSTI %d", baseTypeSize);
  emitStmt(128, "MULI");
  if (onceThrough) emitStmt(128, "ADDI");
  else onceThrough = 1;
  indices = indices->next;
  arrayType = getArrayBaseSym(arrayType);
 }
 if (arrayBase->kind == VAR_KIND && !(arrayBase->isAddress)) {
  emitComment("We now push the base address of the array");
  emitPushVarAddress(arrayBase);
 }
 emitStmt(128, "ADDI");
}

variable_types:
indices
struct Symbol *

variable_types: onceThrough int

variable_types: lowVal int

variable_types: baseTypeSize 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 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: struct ElementArray { void **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; }


emitArrayAssignment

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

if ( a2[2] == 5 )
{
if ( (unsigned int)isByReference(a2) )
emitStmt(128LL, "PUSH %d[%d]", (unsigned int)a2[8], (unsigned int)a2[6]);
else
emitStmt(128LL, "PUSHA %d[%d]", (unsigned int)a2[8], (unsigned int)a2[6]);
}
else if ( !(unsigned int)isConstResultSym(a2) && !a2[2] )
{
emitPushSymbolValue((__int64)a2);
}
emitComment("Calling pre-defined function __do_array_assignment");
emitComment("First, we place the array size on the stack.");
v2 = getTypeSym(a1);
emitStmt(128LL, "CONSTI %d", *(unsigned int *)(v2 + 36));
emitStmt(128LL, "CALL 0, __do_array_assignment");
emitComment("Array assignment done; kick local params off the stack");
return emitStmt(128LL, "ADJUST -3");
}

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

if ( a2[2] == 5 )
{
if ( (unsigned int)isByReference(a2) )
emitStmt(128LL, "PUSH %d[%d]", (unsigned int)a2[8], (unsigned int)a2[6]);
else
emitStmt(128LL, "PUSHA %d[%d]", (unsigned int)a2[8], (unsigned int)a2[6]);
}
else if ( !(unsigned int)isConstResultSym(a2) && !a2[2] )
{
func8((__int64)a2);
}
emitComment("Calling pre-defined function __do_array_assignment");
emitComment("First, we place the array size on the stack.");
v2 = getTypeSym(a1);
emitStmt(128LL, "CONSTI %d", *(unsigned int *)(v2 + 36));
emitStmt(128LL, "CALL 0, __do_array_assignment");
emitComment("Array assignment done; kick local params off the stack");
return emitStmt(128LL, "ADJUST -3");
}

original_code:
void emitArrayAssignment(Symbol *x, Symbol *y)
{
 if (y->kind == VAR_KIND) {
  if (!isByReference(y)) {
    emitStmt(128, "PUSHA %d[%d]", y->offset, y->lvl);
   } else {
    emitStmt(128, "PUSH %d[%d]", y->offset, y->lvl);
  }
 }
 else if ( !isConstResultSym(y) && y->kind == CONST_KIND ) {
  emitPushSymbolValue(y);
 }
 emitComment("Calling pre-defined function __do_array_assignment");
 emitComment("First, we place the array size on the stack.");
 emitStmt(128, "CONSTI %d", getTypeSym(x)->size);
 emitStmt(128, "CALL 0, __do_array_assignment");
 emitComment("Array assignment done; kick local params off the stack");
 emitStmt(128, "ADJUST -3");
}

canonical_original_code:
void emitArrayAssignment(struct Symbol *x, struct Symbol *y)
{
 if (y->kind == VAR_KIND) {
  if (!isByReference(y)) {
    emitStmt(128, "PUSHA %d[%d]", y->offset, y->lvl);
   } else {
    emitStmt(128, "PUSH %d[%d]", y->offset, y->lvl);
  }
 }
 else if ( !isConstResultSym(y) && y->kind == CONST_KIND ) {
  emitPushSymbolValue(y);
 }
 emitComment("Calling pre-defined function __do_array_assignment");
 emitComment("First, we place the array size on the stack.");
 emitStmt(128, "CONSTI %d", getTypeSym(x)->size);
 emitStmt(128, "CALL 0, __do_array_assignment");
 emitComment("Array assignment done; kick local params off the stack");
 emitStmt(128, "ADJUST -3");
}

variable_types:
y
struct Symbol *

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

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


emitAssignmentOp

decompiled_code:
void __fastcall emitAssignmentOp(const char **a1, _DWORD *a2)
{
int v2; // eax
unsigned int v3; // eax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
if ( !a2 )
{
doNotEmit = 1;
return;
}
if ( (unsigned int)((__int64 (*)(void))getType)() == 1 || (unsigned int)getType(a1) == 6 )
{
emitArrayAssignment((__int64)a1, a2);
return;
}
if ( a2[10] )
{
emitComment("Value of y is address, convert to actual value");
emitPushAddressValue((__int64)a2);
}
else
{
v2 = a2[2];
if ( v2 == 5 )
{
emitComment("RHS of assignment operation is a single variable value.");
emitComment("So we push its value now as it was not pushed before.");
emitStmt(128LL, "PUSH %d[%d]", (unsigned int)a2[8], (unsigned int)a2[6]);
}
else if ( !v2 && !(unsigned int)isConstResultSym(a2) )
{
emitComment("RHS of assignment operation is a const, so its value was not");
emitComment("pushed before. So, we push it now.");
emitPushSymbolValue((__int64)a2);
}
}
emitComment("Assigning a value to %s", *a1);
v3 = getType(a1);
if ( v3 == 5 )
{
if ( (unsigned int)getType(a2) == 5 )
goto LABEL_22;
emitStmt(128LL, "ITOR");
emitStmt(128LL, "POPI");
}
else if ( v3 <= 5 )
{
if ( v3 - 2 <= 2 )
{
LABEL_22:
emitStmt(128LL, "POPI");
return;
}
}
else if ( v3 == 8 )
{
goto LABEL_22;
}
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func11(const char **a1, _DWORD *a2)
{
int v2; // eax
unsigned int v3; // eax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
if ( !a2 )
{
doNotEmit = 1;
return;
}
if ( (unsigned int)((__int64 (*)(void))getType)() == 1 || (unsigned int)getType(a1) == 6 )
{
func10((__int64)a1, a2);
return;
}
if ( a2[10] )
{
emitComment("Value of y is address, convert to actual value");
func3((__int64)a2);
}
else
{
v2 = a2[2];
if ( v2 == 5 )
{
emitComment("RHS of assignment operation is a single variable value.");
emitComment("So we push its value now as it was not pushed before.");
emitStmt(128LL, "PUSH %d[%d]", (unsigned int)a2[8], (unsigned int)a2[6]);
}
else if ( !v2 && !(unsigned int)isConstResultSym(a2) )
{
emitComment("RHS of assignment operation is a const, so its value was not");
emitComment("pushed before. So, we push it now.");
func8((__int64)a2);
}
}
emitComment("Assigning a value to %s", *a1);
v3 = getType(a1);
if ( v3 == 5 )
{
if ( (unsigned int)getType(a2) == 5 )
goto LABEL_22;
emitStmt(128LL, "ITOR");
emitStmt(128LL, "POPI");
}
else if ( v3 <= 5 )
{
if ( v3 - 2 <= 2 )
{
LABEL_22:
emitStmt(128LL, "POPI");
return;
}
}
else if ( v3 == 8 )
{
goto LABEL_22;
}
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitAssignmentOp(Symbol *x, Symbol *y)
{
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 if (getType(x) == ARRAY_T || getType(x) == RECORD_T) {
  emitArrayAssignment(x, y);
  return;
 }
 if (y->isAddress) {
  emitComment("Value of y is address, convert to actual value");
  emitPushAddressValue(y);
 } else if (y->kind == VAR_KIND) {
  emitComment("RHS of assignment operation is a single variable "
      "value.");
  emitComment("So we push its value now as it was not pushed "
      "before.");
  emitStmt(128, "PUSH %d[%d]", y->offset, y->lvl);
 } else if ( (y->kind == CONST_KIND) && !isConstResultSym(y)) {
  emitComment("RHS of assignment operation is a const, so its "
      "value was not");
  emitComment("pushed before.  So, we push it now.");
  emitPushSymbolValue(y);
 }
 emitComment("Assigning a value to %s", x->name);
 switch (getType(x)) {
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case SCALAR_T:
  emitStmt(128, "POPI");
  break;
 case REAL_T:
  if (getType(y) == REAL_T) emitStmt(128, "POPI");
  else {
   emitStmt(128, "ITOR");
   emitStmt(128, "POPI");
  }
 default:
  break;
 }
}

canonical_original_code:
void emitAssignmentOp(struct Symbol *x, struct Symbol *y)
{
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 if (getType(x) == ARRAY_T || getType(x) == RECORD_T) {
  emitArrayAssignment(x, y);
  return;
 }
 if (y->isAddress) {
  emitComment("Value of y is address, convert to actual value");
  emitPushAddressValue(y);
 } else if (y->kind == VAR_KIND) {
  emitComment("RHS of assignment operation is a single variable "
      "value.");
  emitComment("So we push its value now as it was not pushed "
      "before.");
  emitStmt(128, "PUSH %d[%d]", y->offset, y->lvl);
 } else if ( (y->kind == CONST_KIND) && !isConstResultSym(y)) {
  emitComment("RHS of assignment operation is a const, so its "
      "value was not");
  emitComment("pushed before.  So, we push it now.");
  emitPushSymbolValue(y);
 }
 emitComment("Assigning a value to %s", x->name);
 switch (getType(x)) {
 case BOOLEAN_T:
 case CHAR_T:
 case INTEGER_T:
 case SCALAR_T:
  emitStmt(128, "POPI");
  break;
 case REAL_T:
  if (getType(y) == REAL_T) emitStmt(128, "POPI");
  else {
   emitStmt(128, "ITOR");
   emitStmt(128, "POPI");
  }
 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 VariableKind { struct Symbol *typeSym; int byRef; }

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

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


getPreDefBool

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

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

canonical_original_code:
struct Symbol *getPreDefBool(struct preDefTypeSymbols *preDefTypeSymbols) {
 return preDefTypeSymbols->boolean;
}

variable_types: struct preDefTypeSymbols { struct Symbol *boolean; struct Symbol *chars; struct Symbol *integer; struct Symbol *real; } *

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 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: struct ElementArray { void **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; }


getPreDefChar

decompiled_code:
__int64 __fastcall getPreDefChar(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_original_code:
struct Symbol *getPreDefChar(struct preDefTypeSymbols *preDefTypeSymbols) {
 return preDefTypeSymbols->chars;
}

user_defined_types: struct preDefTypeSymbols { struct Symbol *boolean; struct Symbol *chars; struct Symbol *integer; struct Symbol *real; }

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

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


getPreDefInt

decompiled_code:
__int64 __fastcall getPreDefInt(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_original_code:
struct Symbol *getPreDefInt(struct preDefTypeSymbols *preDefTypeSymbols) {
 return preDefTypeSymbols->integer;
}

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: 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: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

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


getPreDefReal

decompiled_code:
__int64 __fastcall getPreDefReal(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_original_code:
struct Symbol *getPreDefReal(struct preDefTypeSymbols *preDefTypeSymbols) {
 return preDefTypeSymbols->real;
}

user_defined_types: struct preDefTypeSymbols { struct Symbol *boolean; struct Symbol *chars; struct Symbol *integer; struct Symbol *real; }

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: struct ElementArray { void **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; }


createPreDefType

decompiled_code:
__int64 __fastcall createPreDefType(const char *a1, int a2)
{
__int64 v2; // rbx

if ( strcmp(a1, "Boolean")
&& strcmp(a1, "char")
&& strcmp(a1, "integer")
&& strcmp(a1, "real")
&& strcmp(a1, "string") )
{
err(2, "createPreDefType does not support the given type.");
}
v2 = createTypeSymbol(a1, 1LL);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 8LL) = a2;
addToSymbolTable(symbolTable, v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, int a2)
{
__int64 v2; // rbx

if ( strcmp(a1, "Boolean")
&& strcmp(a1, "char")
&& strcmp(a1, "integer")
&& strcmp(a1, "real")
&& strcmp(a1, "string") )
{
err(2, "createPreDefType does not support the given type.");
}
v2 = createTypeSymbol(a1, 1LL);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 8LL) = a2;
addToSymbolTable(symbolTable, v2);
return v2;
}

original_code:
struct Symbol *createPreDefType(char *name, type_t type) {
 struct Symbol *symbol = ((void *)0);
 if (! ( (strcmp(name, "Boolean") == 0 ) ||
  ( strcmp(name, "char") == 0 ) ||
  ( strcmp(name, "integer") == 0 ) ||
  ( strcmp(name, "real") == 0 ) ||
  ( strcmp(name, "string") == 0 ) ))
 {
  err(2, "createPreDefType does not support the given type.");
  exit(1);
 }
 symbol = createTypeSymbol(name, 1);
 symbol->kindPtr.TypeKind->type = type;
 addToSymbolTable(symbolTable, symbol);
 return symbol;
}

canonical_original_code:
struct Symbol *createPreDefType(char *name, enum type_t type) {
 struct Symbol *symbol = ((void *)0);
 if (! ( (strcmp(name, "Boolean") == 0 ) ||
  ( strcmp(name, "char") == 0 ) ||
  ( strcmp(name, "integer") == 0 ) ||
  ( strcmp(name, "real") == 0 ) ||
  ( strcmp(name, "string") == 0 ) ))
 {
  err(2, "createPreDefType does not support the given type.");
  exit(1);
 }
 symbol = createTypeSymbol(name, 1);
 symbol->kindPtr.TypeKind->type = type;
 addToSymbolTable(symbolTable, symbol);
 return symbol;
}

variable_types:
name
char *

variable_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 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: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

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 String { char *str; unsigned int strlen; }

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

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


initializePreDefTypes

decompiled_code:
_QWORD *initializePreDefTypes()
{
_QWORD *v0; // rbx

v0 = calloc(1uLL, 0x20uLL);
*v0 = createPreDefType("Boolean", 2);
v0[1] = createPreDefType("char", 3);
v0[2] = createPreDefType("integer", 4);
v0[3] = createPreDefType("real", 5);
return v0;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *v0; // rbx

v0 = calloc(1uLL, 0x20uLL);
*v0 = func4("Boolean", 2);
v0[1] = func4("char", 3);
v0[2] = func4("integer", 4);
v0[3] = func4("real", 5);
return v0;
}

original_code:
struct preDefTypeSymbols *initializePreDefTypes() {
 struct preDefTypeSymbols *preDefs = calloc(
     1, sizeof(struct preDefTypeSymbols));
 preDefs->boolean = createPreDefType("Boolean", BOOLEAN_T);
 preDefs->chars = createPreDefType("char", CHAR_T);
 preDefs->integer = createPreDefType("integer", INTEGER_T);
 preDefs->real = createPreDefType("real", REAL_T);
 return preDefs;
}

variable_types: struct preDefTypeSymbols { 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; } *boolean; struct Symbol *chars; struct Symbol *integer; struct Symbol *real; } *

user_defined_types: struct preDefTypeSymbols { struct Symbol *boolean; struct Symbol *chars; struct Symbol *integer; struct Symbol *real; }

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


createPreDefFunc

decompiled_code:
__int64 createPreDefFunc()
{
__int64 v0; // rbx

v0 = createFuncSymbol();
*(_QWORD *)(*(_QWORD *)(v0 + 16) + 8LL) = 0LL;
setInnerTypeSymbol(v0, 0LL);
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx

v0 = createFuncSymbol();
*(_QWORD *)(*(_QWORD *)(v0 + 16) + 8LL) = 0LL;
setInnerTypeSymbol(v0, 0LL);
return v0;
}

original_code:
struct Symbol *createPreDefFunc(char *name) {
 struct Symbol *symbol = createFuncSymbol(name);
 symbol->kindPtr.FuncKind->params = ((void *)0);
 setInnerTypeSymbol(symbol, ((void *)0));
 return symbol;
}

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 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 Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }


initializePreDefProc

decompiled_code:
__int64 initializePreDefProc()
{
_DWORD *v0; // rax
_DWORD *v1; // rax
_DWORD *v2; // rax
_DWORD *v3; // rax

v0 = createPreDefProc((__int64)"write");
addToSymbolTable(symbolTable, v0);
v1 = createPreDefProc((__int64)"writeln");
addToSymbolTable(symbolTable, v1);
v2 = createPreDefProc((__int64)"read");
addToSymbolTable(symbolTable, v2);
v3 = createPreDefProc((__int64)"readln");
addToSymbolTable(symbolTable, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
_DWORD *v0; // rax
_DWORD *v1; // rax
_DWORD *v2; // rax
_DWORD *v3; // rax

v0 = createPreDefProc((__int64)"write");
addToSymbolTable(symbolTable, v0);
v1 = createPreDefProc((__int64)"writeln");
addToSymbolTable(symbolTable, v1);
v2 = createPreDefProc((__int64)"read");
addToSymbolTable(symbolTable, v2);
v3 = createPreDefProc((__int64)"readln");
addToSymbolTable(symbolTable, v3);
return 0LL;
}

original_code:
int initializePreDefProc() {
 struct Symbol *symbol;
 symbol = createPreDefProc("write");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefProc("writeln");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefProc("read");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefProc("readln");
 addToSymbolTable(symbolTable, symbol);
 return 0;
}

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: 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 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 String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **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; }