doTypeDecl

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

if ( getLocalSymbol(symbolTable, a1) )
{
v2 = customErrorString("The identifier %s is already defined at this scope.", a1);
result = recordError(v2, yylineno, colno, 2LL);
}
else
{
result = newTypeSymFromSym(a1, a2);
if ( result )
{
result = addToSymbolTable(symbolTable, result);
if ( (_DWORD)result )
err(1, "Could not insert symbol into symbol table");
}
}
return result;
}

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

if ( getLocalSymbol(symbolTable, a1) )
{
v2 = customErrorString("The identifier %s is already defined at this scope.", a1);
result = recordError(v2, yylineno, colno, 2LL);
}
else
{
result = newTypeSymFromSym(a1, a2);
if ( result )
{
result = addToSymbolTable(symbolTable, result);
if ( (_DWORD)result )
err(1, "Could not insert symbol into symbol table");
}
}
return result;
}

original_code:
void doTypeDecl(char *id, Symbol *type) {
 Symbol * s = ((void *)0);
 s = getLocalSymbol(symbolTable, id);
 if (s != ((void *)0)) {
  errMsg = customErrorString("The identifier %s is already "
    "defined at this scope.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return;
 }
 s = newTypeSymFromSym(id, type);
 if (s == ((void *)0)) {
  return;
 }
 if (addToSymbolTable(symbolTable, s) != 0) {
  err(1, "Could not insert symbol into symbol table");
 }
}

canonical_original_code:
void doTypeDecl(char *id, struct Symbol *type) {
 struct Symbol *s = ((void *)0);
 s = getLocalSymbol(symbolTable, id);
 if (s != ((void *)0)) {
  errMsg = customErrorString("The identifier %s is already "
    "defined at this scope.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return;
 }
 s = newTypeSymFromSym(id, type);
 if (s == ((void *)0)) {
  return;
 }
 if (addToSymbolTable(symbolTable, s) != 0) {
  err(1, "Could not insert symbol into symbol table");
 }
}

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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


exitVarDeclPart

repo: a-krebs/YACC

decompiled_code:
__int64 exitVarDeclPart()
{
unsigned int v0; // eax

reserveLabels(mainLabelStack, 1LL);
emitBlankLine();
emitComment("End of var decls, jump over any other proc or func decls");
v0 = peekLabelStackTop(mainLabelStack);
emitStmt(128LL, "GOTO %s_%d", "MAIN", v0);
return emitBlankLine();
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax

reserveLabels(mainLabelStack, 1LL);
emitBlankLine();
emitComment("End of var decls, jump over any other proc or func decls");
v0 = peekLabelStackTop(mainLabelStack);
emitStmt(128LL, "GOTO %s_%d", "MAIN", v0);
return emitBlankLine();
}

original_code:
void exitVarDeclPart(void) {
 reserveLabels(mainLabelStack, 1);
 emitBlankLine();
 emitComment("End of var decls, jump over any other proc or func decls");
 emitStmt(128, "GOTO %s_%d",
     "MAIN", peekLabelStackTop(mainLabelStack));
 emitBlankLine();
}

canonical_original_code:
void exitVarDeclPart() {
 reserveLabels(mainLabelStack, 1);
 emitBlankLine();
 emitComment("End of var decls, jump over any other proc or func decls");
 emitStmt(128, "GOTO %s_%d",
     "MAIN", peekLabelStackTop(mainLabelStack));
 emitBlankLine();
}

return_type: void


doVarDecl

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

v2 = a2;
if ( getLocalSymbol(symbolTable, a1) )
{
alreadyDefinedError(a1);
v2 = 0LL;
}
else if ( a1 && a2 )
{
v3 = newVariableSym(a1, a2);
v4 = v3;
if ( v3 )
{
addToSymbolTable(symbolTable, v3);
setSymbolOffset(v4, symbolTable);
emitVarDecl(v4);
if ( (unsigned int)getType(a2) == 6 )
*(_DWORD *)(v4 + 44) = 1;
}
}
else
{
v2 = 0LL;
}
return v2;
}

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

v2 = a2;
if ( getLocalSymbol(symbolTable, a1) )
{
alreadyDefinedError(a1);
v2 = 0LL;
}
else if ( a1 && a2 )
{
v3 = newVariableSym(a1, a2);
v4 = v3;
if ( v3 )
{
addToSymbolTable(symbolTable, v3);
setSymbolOffset(v4, symbolTable);
emitVarDecl(v4);
if ( (unsigned int)getType(a2) == 6 )
*(_DWORD *)(v4 + 44) = 1;
}
}
else
{
v2 = 0LL;
}
return v2;
}

original_code:
Symbol *doVarDecl(char *id, Symbol *type) {
 Symbol *s = ((void *)0);
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  alreadyDefinedError(id);
  return ((void *)0);
 }
 if ((!id) || !(type)) return ((void *)0);
 s = newVariableSym(id, type);
 if (s) {
  addToSymbolTable(symbolTable, s);
  setSymbolOffset(s, symbolTable);
  emitVarDecl(s);
  if (getType(type) == RECORD_T) s->isRecordHead = 1;
 }
 return type;
}

canonical_original_code:
struct Symbol *doVarDecl(char *id, struct Symbol *type) {
 struct Symbol *s = ((void *)0);
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  alreadyDefinedError(id);
  return ((void *)0);
 }
 if ((!id) || !(type)) return ((void *)0);
 s = newVariableSym(id, type);
 if (s) {
  addToSymbolTable(symbolTable, s);
  setSymbolOffset(s, symbolTable);
  emitVarDecl(s);
  if (getType(type) == RECORD_T) s->isRecordHead = 1;
 }
 return type;
}

variable_types:
id
char *

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


exitProcOrFuncDecl

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

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 3 )
{
emitEndProc();
}
else if ( v1 == 1 )
{
emitEndFunc();
}
}
return popLexLevel(symbolTable);
}

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

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 3 )
{
emitEndProc();
}
else if ( v1 == 1 )
{
emitEndFunc();
}
}
return popLexLevel(symbolTable);
}

original_code:
void exitProcOrFuncDecl(Symbol *symbol) {
 if (symbol != ((void *)0)) {
  if (symbol->kind == PROC_KIND) {
    emitEndProc(symbol);
  }
  else if (symbol->kind == FUNC_KIND) {
    emitEndFunc(symbol);
  }
 }
 popLexLevel(symbolTable);
}

canonical_original_code:
void exitProcOrFuncDecl(struct Symbol *symbol) {
 if (symbol != ((void *)0)) {
  if (symbol->kind == PROC_KIND) {
    emitEndProc(symbol);
  }
  else if (symbol->kind == FUNC_KIND) {
    emitEndFunc(symbol);
  }
 }
 popLexLevel(symbolTable);
}

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 ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

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

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

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


enterProcDecl

decompiled_code:
__int64 __fastcall enterProcDecl(const char *a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // r14
unsigned int v4; // ebp
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
_QWORD *v10; // rbx
__int64 v11; // rax

if ( a1 )
{
v2 = a2;
if ( getLocalSymbol(symbolTable, a1) )
{
v6 = customErrorString("Name %s is already defined.", a1);
recordError(v6, yylineno, colno, 2LL);
incrementLexLevel(symbolTable);
v3 = 0LL;
}
else
{
if ( !a2 )
v2 = newElementArray();
if ( (unsigned int)hasDuplicateElement(v2) )
{
v7 = customErrorString("Procedure %s has duplicate argument names.", a1);
recordError(v7, yylineno, colno, 2LL);
}
v3 = newProcSym(a1, v2);
v4 = addToSymbolTable(symbolTable, v3);
if ( v4 )
err(1, "Could not add element to symbol table.");
incrementLexLevel(symbolTable);
if ( *(_DWORD *)(v2 + 12) )
{
do
{
v9 = getElementAt(v2, v4);
v10 = (_QWORD *)paramToVar(v9);
if ( getLocalSymbol(symbolTable, *v10) )
{
v11 = customErrorString("Name %s is already defined.", a1);
recordError(v11, yylineno, colno, 2LL);
}
else
{
addToSymbolTable(symbolTable, v10);
v8 = getElementAt(v2, v4);
setSymbolSize(v8);
setSymbolSize(v10);
setParamOffset(v10, v2);
}
++v4;
}
while ( *(_DWORD *)(v2 + 12) > v4 );
}
emitProcOrFuncDecl(v3, v2);
}
}
else
{
incrementLexLevel(symbolTable);
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // r14
unsigned int v4; // ebp
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
_QWORD *v10; // rbx
__int64 v11; // rax

if ( a1 )
{
v2 = a2;
if ( getLocalSymbol(symbolTable, a1) )
{
v6 = customErrorString("Name %s is already defined.", a1);
recordError(v6, yylineno, colno, 2LL);
incrementLexLevel(symbolTable);
v3 = 0LL;
}
else
{
if ( !a2 )
v2 = newElementArray();
if ( (unsigned int)hasDuplicateElement(v2) )
{
v7 = customErrorString("Procedure %s has duplicate argument names.", a1);
recordError(v7, yylineno, colno, 2LL);
}
v3 = newProcSym(a1, v2);
v4 = addToSymbolTable(symbolTable, v3);
if ( v4 )
err(1, "Could not add element to symbol table.");
incrementLexLevel(symbolTable);
if ( *(_DWORD *)(v2 + 12) )
{
do
{
v9 = getElementAt(v2, v4);
v10 = (_QWORD *)paramToVar(v9);
if ( getLocalSymbol(symbolTable, *v10) )
{
v11 = customErrorString("Name %s is already defined.", a1);
recordError(v11, yylineno, colno, 2LL);
}
else
{
addToSymbolTable(symbolTable, v10);
v8 = getElementAt(v2, v4);
setSymbolSize(v8);
setSymbolSize(v10);
setParamOffset(v10, v2);
}
++v4;
}
while ( *(_DWORD *)(v2 + 12) > v4 );
}
emitProcOrFuncDecl(v3, v2);
}
}
else
{
incrementLexLevel(symbolTable);
v3 = 0LL;
}
return v3;
}

original_code:
Symbol *enterProcDecl(char *id, struct ElementArray *ea) {
 Symbol *s = ((void *)0);
 Symbol *var = ((void *)0);
 if (!id) {
  incrementLexLevel(symbolTable);
  return ((void *)0);
 }
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  errMsg = customErrorString("Name %s "
      "is already defined.",id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  incrementLexLevel(symbolTable);
  return ((void *)0);
 }
 if (!ea) {
  ea = newElementArray();
 }
 if (hasDuplicateElement(ea)) {
  errMsg = customErrorString("Procedure %s has duplicate "
     "argument names.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 s = newProcSym(id, ea);
 if (addToSymbolTable(symbolTable, s) != 0) {
  err(1, "Could not add element to symbol table.");
  exit(1);
 }
 incrementLexLevel(symbolTable);
 for (int i = 0; i < ea->nElements; i++) {
  var = paramToVar(getElementAt(ea, i));
  if (!getLocalSymbol(symbolTable, var->name)) {
   addToSymbolTable(symbolTable, var);
   setSymbolSize(getElementAt(ea, i));
   setSymbolSize(var);
   setParamOffset(var, ea);
  }
  else {
   errMsg = customErrorString("Name %s "
        "is already defined.",id);
   recordError(errMsg, yylineno, colno, SEMANTIC);
  }
 }
 emitProcOrFuncDecl(s, ea);
 return s;
}

canonical_original_code:
struct Symbol *enterProcDecl(char *id, struct ElementArray *ea) {
 struct Symbol *s = ((void *)0);
 struct Symbol *var = ((void *)0);
 if (!id) {
  incrementLexLevel(symbolTable);
  return ((void *)0);
 }
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  errMsg = customErrorString("Name %s "
      "is already defined.",id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  incrementLexLevel(symbolTable);
  return ((void *)0);
 }
 if (!ea) {
  ea = newElementArray();
 }
 if (hasDuplicateElement(ea)) {
  errMsg = customErrorString("Procedure %s has duplicate "
     "argument names.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 s = newProcSym(id, ea);
 if (addToSymbolTable(symbolTable, s) != 0) {
  err(1, "Could not add element to symbol table.");
  exit(1);
 }
 incrementLexLevel(symbolTable);
 for (int i = 0; i < ea->nElements; i++) {
  var = paramToVar(getElementAt(ea, i));
  if (!getLocalSymbol(symbolTable, var->name)) {
   addToSymbolTable(symbolTable, var);
   setSymbolSize(getElementAt(ea, i));
   setSymbolSize(var);
   setParamOffset(var, ea);
  }
  else {
   errMsg = customErrorString("Name %s "
        "is already defined.",id);
   recordError(errMsg, yylineno, colno, SEMANTIC);
  }
 }
 emitProcOrFuncDecl(s, ea);
 return s;
}

variable_types:
ea
struct ElementArray *

variable_types: i int

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

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

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


enterFuncDecl

decompiled_code:
const char **__fastcall enterFuncDecl(const char *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
unsigned int v5; // er13
const char **v6; // r14
unsigned int v7; // ebp
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
const char **v13; // rbx
const char *v14; // r13
__int64 v15; // rax
__int64 v17; // rbx
int v18; // [rsp+Ch] [rbp-3Ch]

v3 = a2;
v5 = getCurrentLexLevel(symbolTable);
if ( getLocalSymbol(symbolTable, a1) )
{
v8 = customErrorString("Function with name %s is already defined.", a1);
recordError(v8, yylineno, colno, 2LL);
v6 = 0LL;
}
else
{
if ( !a2 )
v3 = newElementArray();
if ( !a3 )
{
v9 = customErrorString("Function with name %s has no return type, assuming INTEGER.", a1);
recordError(v9, yylineno, colno, 2LL);
a3 = getPreDefInt(preDefTypeSymbols);
}
if ( (unsigned int)hasDuplicateElement(v3) )
{
v10 = customErrorString("Procedure %s has duplicate argument names.", a1);
recordError(v10, yylineno, colno, 2LL);
}
v6 = (const char **)newFuncSym(v5, a1, a3, v3);
addToSymbolTable(symbolTable, v6);
incrementLexLevel(symbolTable);
if ( !*(_DWORD *)(v3 + 12) )
goto LABEL_19;
v18 = 0;
v7 = 0;
do
{
v12 = getElementAt(v3, v7);
v13 = (const char **)paramToVar(v12);
if ( !getLocalSymbol(symbolTable, *v13) )
{
addToSymbolTable(symbolTable, v13);
setSymbolSize(v13);
v11 = getElementAt(v3, v7);
setSymbolSize(v11);
setParamOffset(v13, v3);
}
v14 = *v6;
if ( !strcmp(*v13, *v6) )
{
v15 = customErrorString("Function %s has parameter with same name as function.", v14);
recordError(v15, yylineno, colno, 2LL);
v18 = 1;
}
++v7;
}
while ( *(_DWORD *)(v3 + 12) > v7 );
if ( !v18 )
{
LABEL_19:
v17 = paramToVar(v6);
addToSymbolTable(symbolTable, v17);
setParamOffset(v17, v3);
}
emitProcOrFuncDecl(v6, v3);
}
return v6;
}

canonical_decompiled_code:
const char **__fastcall func10(const char *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
unsigned int v5; // er13
const char **v6; // r14
unsigned int v7; // ebp
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
const char **v13; // rbx
const char *v14; // r13
__int64 v15; // rax
__int64 v17; // rbx
int v18; // [rsp+Ch] [rbp-3Ch]

v3 = a2;
v5 = getCurrentLexLevel(symbolTable);
if ( getLocalSymbol(symbolTable, a1) )
{
v8 = customErrorString("Function with name %s is already defined.", a1);
recordError(v8, yylineno, colno, 2LL);
v6 = 0LL;
}
else
{
if ( !a2 )
v3 = newElementArray();
if ( !a3 )
{
v9 = customErrorString("Function with name %s has no return type, assuming INTEGER.", a1);
recordError(v9, yylineno, colno, 2LL);
a3 = getPreDefInt(preDefTypeSymbols);
}
if ( (unsigned int)hasDuplicateElement(v3) )
{
v10 = customErrorString("Procedure %s has duplicate argument names.", a1);
recordError(v10, yylineno, colno, 2LL);
}
v6 = (const char **)newFuncSym(v5, a1, a3, v3);
addToSymbolTable(symbolTable, v6);
incrementLexLevel(symbolTable);
if ( !*(_DWORD *)(v3 + 12) )
goto LABEL_19;
v18 = 0;
v7 = 0;
do
{
v12 = getElementAt(v3, v7);
v13 = (const char **)paramToVar(v12);
if ( !getLocalSymbol(symbolTable, *v13) )
{
addToSymbolTable(symbolTable, v13);
setSymbolSize(v13);
v11 = getElementAt(v3, v7);
setSymbolSize(v11);
setParamOffset(v13, v3);
}
v14 = *v6;
if ( !strcmp(*v13, *v6) )
{
v15 = customErrorString("Function %s has parameter with same name as function.", v14);
recordError(v15, yylineno, colno, 2LL);
v18 = 1;
}
++v7;
}
while ( *(_DWORD *)(v3 + 12) > v7 );
if ( !v18 )
{
LABEL_19:
v17 = paramToVar(v6);
addToSymbolTable(symbolTable, v17);
setParamOffset(v17, v3);
}
emitProcOrFuncDecl(v6, v3);
}
return v6;
}

original_code:
Symbol *enterFuncDecl(char *id, struct ElementArray *ea, Symbol *typeSym) {
 Symbol *s = ((void *)0), *var = ((void *)0);
 int lvl = getCurrentLexLevel(symbolTable), i, badParamName = 0;
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  errMsg = customErrorString("Function with name %s "
      "is already defined.",id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (!ea) {
  ea = newElementArray();
 }
 if (!typeSym) {
  errMsg = customErrorString("Function with name %s "
      "has no return type, assuming INTEGER.",id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  typeSym = getPreDefInt(preDefTypeSymbols);
 }
 if (hasDuplicateElement(ea)) {
  errMsg = customErrorString("Procedure %s has duplicate "
     "argument names.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 s = newFuncSym(lvl, id, typeSym, ea);
 if (addToSymbolTable(symbolTable, s) != 0) {
 }
 incrementLexLevel(symbolTable);
 for (i = 0; i < ea->nElements; i++) {
  var = paramToVar(getElementAt(ea, i));
  if (!getLocalSymbol(symbolTable, var->name)) {
   addToSymbolTable(symbolTable, var);
   setSymbolSize(var);
   setSymbolSize(getElementAt(ea, i));
   setParamOffset(var, ea);
  }
  if (var) {
   if (strcmp(var->name, s->name) == 0) {
    errMsg = customErrorString("Function %s has "
        "parameter with same name as function.",
        s->name);
    recordError(errMsg, yylineno, colno, SEMANTIC);
    badParamName = 1;
   }
  }
 }
 if (!badParamName) {
  var = paramToVar(s);
  addToSymbolTable(symbolTable, var);
  setParamOffset(var, ea);
 }
 emitProcOrFuncDecl(s, ea);
 return s;
}

canonical_original_code:
struct Symbol *enterFuncDecl(char *id, struct ElementArray *ea, struct Symbol *typeSym) {
 struct Symbol *s = ((void *)0); struct Symbol *var = ((void *)0);
 int lvl = getCurrentLexLevel(symbolTable); int i; int badParamName = 0;
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  errMsg = customErrorString("Function with name %s "
      "is already defined.",id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (!ea) {
  ea = newElementArray();
 }
 if (!typeSym) {
  errMsg = customErrorString("Function with name %s "
      "has no return type, assuming INTEGER.",id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  typeSym = getPreDefInt(preDefTypeSymbols);
 }
 if (hasDuplicateElement(ea)) {
  errMsg = customErrorString("Procedure %s has duplicate "
     "argument names.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 s = newFuncSym(lvl, id, typeSym, ea);
 if (addToSymbolTable(symbolTable, s) != 0) {
 }
 incrementLexLevel(symbolTable);
 for (i = 0; i < ea->nElements; i++) {
  var = paramToVar(getElementAt(ea, i));
  if (!getLocalSymbol(symbolTable, var->name)) {
   addToSymbolTable(symbolTable, var);
   setSymbolSize(var);
   setSymbolSize(getElementAt(ea, i));
   setParamOffset(var, ea);
  }
  if (var) {
   if (strcmp(var->name, s->name) == 0) {
    errMsg = customErrorString("Function %s has "
        "parameter with same name as function.",
        s->name);
    recordError(errMsg, yylineno, colno, SEMANTIC);
    badParamName = 1;
   }
  }
 }
 if (!badParamName) {
  var = paramToVar(s);
  addToSymbolTable(symbolTable, var);
  setParamOffset(var, ea);
 }
 emitProcOrFuncDecl(s, ea);
 return s;
}

variable_types:
typeSym
struct Symbol *

variable_types: lvl int

variable_types: badParamName int

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 FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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


createParmList

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

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

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

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

original_code:
struct ElementArray *createParmList(Symbol *parm) {
 struct ElementArray *ea = ((void *)0);
 if (!parm) return ((void *)0);
 ea = newElementArray();
 growElementArray(ea);
 appendElement(ea, parm);
 return ea;
}

canonical_original_code:
struct ElementArray *createParmList(struct Symbol *parm) {
 struct ElementArray *ea = ((void *)0);
 if (!parm) return ((void *)0);
 ea = newElementArray();
 growElementArray(ea);
 appendElement(ea, parm);
 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 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 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; }


appendParmToParmList

decompiled_code:
__int64 __fastcall appendParmToParmList(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
appendElement(a1, a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
appendElement(a1, a2);
return a1;
}

original_code:
struct ElementArray *appendParmToParmList(
    struct ElementArray *ea, Symbol *parm) {
 if ( !(ea) || !(parm) ) return ((void *)0);
 appendElement(ea, parm);
 return ea;
}

canonical_original_code:
struct ElementArray *appendParmToParmList(struct ElementArray *ea, struct Symbol *parm) {
 if ( !(ea) || !(parm) ) return ((void *)0);
 appendElement(ea, parm);
 return ea;
}

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

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 Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

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


createNewParm

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

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

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

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

original_code:
Symbol *createNewParm(char *id, Symbol *type) {
 if ((!id) || (!type)) return ((void *)0);
 return newParamSym(id, type);
}

canonical_original_code:
struct Symbol *createNewParm(char *id, struct Symbol *type) {
 if ((!id) || (!type)) return ((void *)0);
 return newParamSym(id, type);
}

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 FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


createNewVarParm

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

result = createNewParm(a1, a2);
if ( result )
*(_DWORD *)(*(_QWORD *)(result + 16) + 8LL) = 1;
return result;
}

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

result = func13(a1, a2);
if ( result )
*(_DWORD *)(*(_QWORD *)(result + 16) + 8LL) = 1;
return result;
}

original_code:
Symbol *createNewVarParm(char *id, Symbol *type) {
 Symbol *s = createNewParm(id, type);
 if (s) s->kindPtr.ParamKind->byRef = 1;
 return s;
}

canonical_original_code:
struct Symbol *createNewVarParm(char *id, struct Symbol *type) {
 struct Symbol *s = createNewParm(id, type);
 if (s) s->kindPtr.ParamKind->byRef = 1;
 return s;
}

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 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 StringType { unsigned int strlen; }

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

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


getSizeOfParams

decompiled_code:
__int64 __fastcall getSizeOfParams(__int64 a1)
{
int v1; // eax
__int64 v2; // r12
unsigned int v3; // ebp
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rbx
int v7; // eax

v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 3 )
{
v2 = **(_QWORD **)(a1 + 16);
}
else
{
v2 = 0LL;
if ( v1 == 1 )
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
}
if ( !*(_DWORD *)(v2 + 12) )
return 0;
v3 = 0;
v4 = 0;
do
{
v5 = getElementAt(v2, v3);
if ( (unsigned int)isByReference(v5) )
{
++v4;
}
else if ( *(_DWORD *)(v5 + 8) )
{
v6 = getTypeSym(v5);
v7 = getType(v6);
if ( (unsigned int)(v7 - 1) <= 4 || v7 == 7 )
{
++v4;
}
else if ( (unsigned int)(v7 - 8) <= 1 || v7 == 6 )
{
v4 += *(_DWORD *)(v6 + 36);
}
}
else
{
++v4;
}
++v3;
}
while ( *(_DWORD *)(v2 + 12) > v3 );
return v4;
}

original_code:
int getSizeOfParams(Symbol *procOrFuncSymbol) {
 struct ElementArray *params = ((void *)0);
 Symbol *param = ((void *)0);
 int size = 0;
 type_t type;
 if (procOrFuncSymbol->kind == PROC_KIND) {
   params = procOrFuncSymbol->kindPtr.ProcKind->params;
 }
 else if (procOrFuncSymbol->kind == FUNC_KIND) {
  params = procOrFuncSymbol->kindPtr.FuncKind->params;
 }
 for (int i = 0; i < params->nElements; ++i) {
  param = getElementAt(params, i);
  if ( isByReference(param) ) {
   size++;
   continue;
  }
  if ( param->kind == CONST_KIND ) {
   size++;
   continue;
  }
  param = getTypeSym(param);
  type = getType(param);
  if ( type == BOOLEAN_T
   || type == CHAR_T
   || type == INTEGER_T
   || type == REAL_T
   || type == SCALARINT_T
   || type == ARRAY_T )
  {
   size++;
   continue;
  }
  if ( type == RECORD_T
   || type == SCALAR_T
   || type == STRING_T
   ) {
   size = size + param->size;
  }
 }
 return size;
}

canonical_original_code:
int getSizeOfParams(struct Symbol *procOrFuncSymbol) {
 struct ElementArray *params = ((void *)0);
 struct Symbol *param = ((void *)0);
 int size = 0;
 enum type_t type;
 if (procOrFuncSymbol->kind == PROC_KIND) {
   params = procOrFuncSymbol->kindPtr.ProcKind->params;
 }
 else if (procOrFuncSymbol->kind == FUNC_KIND) {
  params = procOrFuncSymbol->kindPtr.FuncKind->params;
 }
 for (int i = 0; i < params->nElements; ++i) {
  param = getElementAt(params, i);
  if ( isByReference(param) ) {
   size++;
   continue;
  }
  if ( param->kind == CONST_KIND ) {
   size++;
   continue;
  }
  param = getTypeSym(param);
  type = getType(param);
  if ( type == BOOLEAN_T
   || type == CHAR_T
   || type == INTEGER_T
   || type == REAL_T
   || type == SCALARINT_T
   || type == ARRAY_T )
  {
   size++;
   continue;
  }
  if ( type == RECORD_T
   || type == SCALAR_T
   || type == STRING_T
   ) {
   size = size + param->size;
  }
 }
 return size;
}

variable_types: size int

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 }

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 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 Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

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

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


emitProcOrFuncEndCommon

decompiled_code:
void __fastcall emitProcOrFuncEndCommon(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
v2 = getOffset(symbolTable);
v3 = *(_DWORD *)(a1 + 24) + 1;
emitStmt(128LL, "ADJUST %d", (unsigned int)-v2);
emitStmt(128LL, "RET %d", v3);
emitComment(a2);
emitStmt(128LL, (const char *)&unk_6D1);
emitStmt(128LL, (const char *)&unk_6D1);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
v2 = getOffset(symbolTable);
v3 = *(_DWORD *)(a1 + 24) + 1;
emitStmt(128LL, "ADJUST %d", (unsigned int)-v2);
emitStmt(128LL, "RET %d", v3);
emitComment(a2);
emitStmt(128LL, (const char *)&unk_6D1);
emitStmt(128LL, (const char *)&unk_6D1);
}
}

original_code:
void emitProcOrFuncEndCommon(Symbol *symbol, char *msg) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 int adjustCount = 0;
 int lexLevel = 0;
 adjustCount = getOffset(symbolTable) * -1;
 lexLevel = symbol->lvl + 1;
 emitStmt(128, "ADJUST %d", adjustCount);
 emitStmt(128, "RET %d", lexLevel);
 emitComment(msg);
 emitStmt(128, "");
 emitStmt(128, "");
}

canonical_original_code:
void emitProcOrFuncEndCommon(struct Symbol *symbol, char *msg) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 int adjustCount = 0;
 int lexLevel = 0;
 adjustCount = getOffset(symbolTable) * -1;
 lexLevel = symbol->lvl + 1;
 emitStmt(128, "ADJUST %d", adjustCount);
 emitStmt(128, "RET %d", lexLevel);
 emitComment(msg);
 emitStmt(128, "");
 emitStmt(128, "");
}

variable_types:
msg
char *

variable_types: adjustCount int

variable_types: lexLevel int

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 FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


emitEndProc

decompiled_code:
void __fastcall emitEndProc(__int64 a1)
{
emitProcOrFuncEndCommon(a1, (__int64)"Procedure end.");
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
func1(a1, (__int64)"Procedure end.");
}

original_code:
void emitEndProc(Symbol *symbol) {
 emitProcOrFuncEndCommon(symbol, "Procedure end.");
}

canonical_original_code:
void emitEndProc(struct Symbol *symbol) {
 emitProcOrFuncEndCommon(symbol, "Procedure end.");
}

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 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 StringType { unsigned int strlen; }

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

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


emitEndFunc

decompiled_code:
void __fastcall emitEndFunc(__int64 a1)
{
if ( doNotEmit )
doNotEmit = 1;
else
emitProcOrFuncEndCommon(a1, (__int64)"Function end.");
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
if ( doNotEmit )
doNotEmit = 1;
else
func1(a1, (__int64)"Function end.");
}

original_code:
void emitEndFunc(Symbol *symbol) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitProcOrFuncEndCommon(symbol, "Function end.");
}

canonical_original_code:
void emitEndFunc(struct Symbol *symbol) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitProcOrFuncEndCommon(symbol, "Function end.");
}

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 Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

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

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


createProcOrFunctionLabel

decompiled_code:
char *__fastcall createProcOrFunctionLabel(const char **a1)
{
unsigned int v1; // ebx
int v2; // eax
char *v3; // rbp
const char *v4; // r12
size_t v5; // rbx
size_t v6; // rax
char *v7; // rbx

reserveLabels(procOrFuncStack, 1LL);
v1 = peekLabelStackTop(procOrFuncStack);
v2 = snprintf(0LL, 0LL, "%i", v1);
v3 = (char *)calloc(1uLL, v2 + 1);
sprintf(v3, "%i", v1);
v4 = *a1;
v5 = strlen(*a1);
v6 = strlen(v3);
v7 = (char *)calloc(1uLL, v5 + v6 + 2);
strcat(v7, v4);
*(_WORD *)&v7[strlen(v7)] = 95;
strcat(v7, v3);
free(v3);
return v7;
}

canonical_decompiled_code:
char *__fastcall func4(const char **a1)
{
unsigned int v1; // ebx
int v2; // eax
char *v3; // rbp
const char *v4; // r12
size_t v5; // rbx
size_t v6; // rax
char *v7; // rbx

reserveLabels(procOrFuncStack, 1LL);
v1 = peekLabelStackTop(procOrFuncStack);
v2 = snprintf(0LL, 0LL, "%i", v1);
v3 = (char *)calloc(1uLL, v2 + 1);
sprintf(v3, "%i", v1);
v4 = *a1;
v5 = strlen(*a1);
v6 = strlen(v3);
v7 = (char *)calloc(1uLL, v5 + v6 + 2);
strcat(v7, v4);
*(_WORD *)&v7[strlen(v7)] = 95;
strcat(v7, v3);
free(v3);
return v7;
}

original_code:
char *createProcOrFunctionLabel(Symbol *symbol) {
 char *tempName = ((void *)0);
 char *name = ((void *)0);
 int labelCount;
 int size;
 reserveLabels(procOrFuncStack, 1);
 labelCount = peekLabelStackTop(procOrFuncStack);
 size = snprintf(((void *)0), 0, "%i", labelCount);
        tempName = calloc(1, size + 1);
        sprintf(tempName, "%i", labelCount);
        name = calloc(1, (strlen(symbol->name) + 2 + strlen(tempName) ));
        strcat(name, symbol->name);
        strcat(name, "_");
        strcat(name, tempName);
        free(tempName);
        return name;
}

canonical_original_code:
char *createProcOrFunctionLabel(struct Symbol *symbol) {
 char *tempName = ((void *)0);
 char *name = ((void *)0);
 int labelCount;
 int size;
 reserveLabels(procOrFuncStack, 1);
 labelCount = peekLabelStackTop(procOrFuncStack);
 size = snprintf(((void *)0), 0, "%i", labelCount);
        tempName = calloc(1, size + 1);
        sprintf(tempName, "%i", labelCount);
        name = calloc(1, (strlen(symbol->name) + 2 + strlen(tempName) ));
        strcat(name, symbol->name);
        strcat(name, "_");
        strcat(name, tempName);
        free(tempName);
        return name;
}

variable_types:
tempName
char *

variable_types:
name
char *

variable_types: labelCount int

return_type: char *

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 FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


emitProcOrFuncDecl

decompiled_code:
void __fastcall emitProcOrFuncDecl(__int64 a1)
{
char *v1; // rbp
int v2; // eax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitStmt(128LL, (const char *)&unk_6D1);
emitStmt(128LL, (const char *)&unk_6D1);
v1 = createProcOrFunctionLabel((const char **)a1);
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 3 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) = v1;
emitComment("Procedure start: %s", v1);
}
else if ( v2 == 1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 16LL) = v1;
emitComment("Function start: %s", v1);
}
emitLabel(128LL, v1);
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
char *v1; // rbp
int v2; // eax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitStmt(128LL, (const char *)&unk_6D1);
emitStmt(128LL, (const char *)&unk_6D1);
v1 = func4((const char **)a1);
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 3 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) = v1;
emitComment("Procedure start: %s", v1);
}
else if ( v2 == 1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 16LL) = v1;
emitComment("Function start: %s", v1);
}
emitLabel(128LL, v1);
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitProcOrFuncDecl(Symbol *symbol, struct ElementArray *ea) {
  do { if(!(symbol) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
  emitStmt(128, "");
  emitStmt(128, "");
  char *label = createProcOrFunctionLabel(symbol);
  if (symbol->kind == PROC_KIND) {
   symbol->kindPtr.ProcKind->label = label;
  emitComment("Procedure start: %s", label);
 }
 else if (symbol->kind == FUNC_KIND) {
  symbol->kindPtr.FuncKind->label = label;
   emitComment("Function start: %s", label);
 }
  emitLabel(128, label);
}

canonical_original_code:
void emitProcOrFuncDecl(struct Symbol *symbol, struct ElementArray *ea) {
  do { if(!(symbol) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
  emitStmt(128, "");
  emitStmt(128, "");
  char *label = createProcOrFunctionLabel(symbol);
  if (symbol->kind == PROC_KIND) {
   symbol->kindPtr.ProcKind->label = label;
  emitComment("Procedure start: %s", label);
 }
 else if (symbol->kind == FUNC_KIND) {
  symbol->kindPtr.FuncKind->label = label;
   emitComment("Function start: %s", label);
 }
  emitLabel(128, label);
}

variable_types:
label
char *

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 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 StringType { unsigned int strlen; }

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

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


emitStructuredType

decompiled_code:
__int64 __fastcall emitStructuredType(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
signed int i; // ebx

result = isByReference(a2);
if ( (_DWORD)result )
{
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a2 + 32), *(unsigned int *)(a2 + 24));
result = emitStmt(128LL, "PUSHI");
}
else
{
for ( i = 0; (int)a1[9] > i; ++i )
result = emitStmt(128LL, "PUSH %d[%d]", a1[8] + i, a1[6]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
signed int i; // ebx

result = isByReference(a2);
if ( (_DWORD)result )
{
emitStmt(128LL, "PUSH %d[%d]", *(unsigned int *)(a2 + 32), *(unsigned int *)(a2 + 24));
result = emitStmt(128LL, "PUSHI");
}
else
{
for ( i = 0; (int)a1[9] > i; ++i )
result = emitStmt(128LL, "PUSH %d[%d]", a1[8] + i, a1[6]);
}
return result;
}

original_code:
void emitStructuredType(Symbol *arg, Symbol *param) {
 int offset = arg->offset;
 if ( isByReference(param) ) {
   emitStmt(128, "PUSH %d[%d]", param->offset, param->lvl);
   emitStmt(128, "PUSHI");
   return;
 }
 for (int i = 0; i < arg->size; ++i){
  offset = arg->offset + i;
  emitStmt(128, "PUSH %d[%d]", offset, arg->lvl);
 }
}

canonical_original_code:
void emitStructuredType(struct Symbol *arg, struct Symbol *param) {
 int offset = arg->offset;
 if ( isByReference(param) ) {
   emitStmt(128, "PUSH %d[%d]", param->offset, param->lvl);
   emitStmt(128, "PUSHI");
   return;
 }
 for (int i = 0; i < arg->size; ++i){
  offset = arg->offset + i;
  emitStmt(128, "PUSH %d[%d]", offset, arg->lvl);
 }
}

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

variable_types:
param
struct Symbol *

variable_types: offset 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: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


getProcOrFuncParams

decompiled_code:
__int64 __fastcall getProcOrFuncParams(__int64 a1)
{
int v1; // eax
__int64 v2; // rdx

v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 3 )
return **(_QWORD **)(a1 + 16);
v2 = 0LL;
if ( v1 == 1 )
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
return v2;
}

original_code:
struct ElementArray *getProcOrFuncParams(Symbol *procOrFuncSymbol) {
 struct ElementArray *params = ((void *)0);
 if (procOrFuncSymbol->kind == PROC_KIND) {
   params = procOrFuncSymbol->kindPtr.ProcKind->params;
 }
 else if (procOrFuncSymbol->kind == FUNC_KIND) {
  params = procOrFuncSymbol->kindPtr.FuncKind->params;
 }
 return params;
}

canonical_original_code:
struct ElementArray *getProcOrFuncParams(struct Symbol *procOrFuncSymbol) {
 struct ElementArray *params = ((void *)0);
 if (procOrFuncSymbol->kind == PROC_KIND) {
   params = procOrFuncSymbol->kindPtr.ProcKind->params;
 }
 else if (procOrFuncSymbol->kind == FUNC_KIND) {
  params = procOrFuncSymbol->kindPtr.FuncKind->params;
 }
 return params;
}

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 kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

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: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

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


emitPushParamValue

decompiled_code:
void __fastcall emitPushParamValue(__int64 a1, int a2)
{
int v2; // eax

if ( !a2 )
{
v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
{
if ( v2 != 5 )
{
if ( *(_DWORD *)(a1 + 40) || (unsigned int)getType(a1) == 1 || (unsigned int)getType(a1) == 6 )
emitPushAddressValue(a1);
return;
}
if ( (unsigned int)getType(a1) == 1 || (unsigned int)getType(a1) == 6 )
{
emitPushStructuredVarValue(a1);
return;
}
}
else if ( (unsigned int)isConstResultSym() )
{
return;
}
emitPushSymbolValue(a1);
return;
}
if ( *(_DWORD *)(a1 + 8) == 5 && !*(_DWORD *)(a1 + 40) )
emitPushVarAddress();
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
int v2; // eax

if ( !a2 )
{
v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
{
if ( v2 != 5 )
{
if ( *(_DWORD *)(a1 + 40) || (unsigned int)getType(a1) == 1 || (unsigned int)getType(a1) == 6 )
emitPushAddressValue(a1);
return;
}
if ( (unsigned int)getType(a1) == 1 || (unsigned int)getType(a1) == 6 )
{
emitPushStructuredVarValue(a1);
return;
}
}
else if ( (unsigned int)isConstResultSym() )
{
return;
}
emitPushSymbolValue(a1);
return;
}
if ( *(_DWORD *)(a1 + 8) == 5 && !*(_DWORD *)(a1 + 40) )
emitPushVarAddress();
}

original_code:
void emitPushParamValue(Symbol *s, int byRef)
{
 if (!byRef) {
  if (s->kind == CONST_KIND) {
   if (!isConstResultSym(s)) {
    emitPushSymbolValue(s);
   }
   return;
  }
  if (s->kind == VAR_KIND) {
   if ( (getType(s) == ARRAY_T) || (getType(s) ==
       RECORD_T) ) {
   emitPushStructuredVarValue(s);
   } else {
    emitPushSymbolValue(s);
   }
   return;
  }
  if ( (s->isAddress) || getType(s) == ARRAY_T || getType(s) ==
      (RECORD_T) ) {
   emitPushAddressValue(s);
  }
 } else {
  if (s->kind == CONST_KIND) {
  }
  if (s->kind == VAR_KIND) {
   if (!s->isAddress) emitPushVarAddress(s);
  }
 }
}

canonical_original_code:
void emitPushParamValue(struct Symbol *s, int byRef)
{
 if (!byRef) {
  if (s->kind == CONST_KIND) {
   if (!isConstResultSym(s)) {
    emitPushSymbolValue(s);
   }
   return;
  }
  if (s->kind == VAR_KIND) {
   if ( (getType(s) == ARRAY_T) || (getType(s) ==
       RECORD_T) ) {
   emitPushStructuredVarValue(s);
   } else {
    emitPushSymbolValue(s);
   }
   return;
  }
  if ( (s->isAddress) || getType(s) == ARRAY_T || getType(s) ==
      (RECORD_T) ) {
   emitPushAddressValue(s);
  }
 } else {
  if (s->kind == CONST_KIND) {
  }
  if (s->kind == VAR_KIND) {
   if (!s->isAddress) emitPushVarAddress(s);
  }
 }
}

variable_types: byRef int

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


emitFuncInvok

decompiled_code:
void __fastcall emitFuncInvok(__int64 a1, __int64 a2)
{
const char *v2; // r12

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitStmt(128LL, (const char *)&unk_6D1);
emitComment("Start function invocation '%s':", *(const char **)a1);
if ( (unsigned int)isPreDefFunc(a1) )
{
emitPreDefFunc(a1, a2);
}
else
{
v2 = *(const char **)(*(_QWORD *)(a1 + 16) + 16LL);
emitComment("Make room for return value.");
emitStmt(128LL, "CONSTI 0");
emitProcOrFuncInvokCommon(a1, a2, v2);
}
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2)
{
const char *v2; // r12

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitStmt(128LL, (const char *)&unk_6D1);
emitComment("Start function invocation '%s':", *(const char **)a1);
if ( (unsigned int)isPreDefFunc(a1) )
{
emitPreDefFunc(a1, a2);
}
else
{
v2 = *(const char **)(*(_QWORD *)(a1 + 16) + 16LL);
emitComment("Make room for return value.");
emitStmt(128LL, "CONSTI 0");
emitProcOrFuncInvokCommon(a1, a2, v2);
}
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitFuncInvok(Symbol *symbol, struct ElementArray *params) {
 char *label;
 do { if(!(symbol) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
  emitStmt(128, "");
  emitComment("Start function invocation '%s':", symbol->name);
 if (isPreDefFunc(symbol)) {
  emitPreDefFunc(symbol, params);
  return;
 }
 label = symbol->kindPtr.FuncKind->label;
 emitComment("Make room for return value.");
 emitStmt(128, "CONSTI 0");
  emitProcOrFuncInvokCommon(symbol, params, label);
}

canonical_original_code:
void emitFuncInvok(struct Symbol *symbol, struct ElementArray *params) {
 char *label;
 do { if(!(symbol) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
  emitStmt(128, "");
  emitComment("Start function invocation '%s':", symbol->name);
 if (isPreDefFunc(symbol)) {
  emitPreDefFunc(symbol, params);
  return;
 }
 label = symbol->kindPtr.FuncKind->label;
 emitComment("Make room for return value.");
 emitStmt(128, "CONSTI 0");
  emitProcOrFuncInvokCommon(symbol, params, label);
}

variable_types:
params
struct ElementArray *

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 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 StringType { unsigned int strlen; }

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

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


proxyIntLiteral

decompiled_code:
__int64 __fastcall proxyIntLiteral(__int64 a1)
{
__int64 v1; // rax
__int64 v3; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
if ( (unsigned __int64)(a1 + 0x7FFFFFFF) > 0xFFFFFFFE )
{
v3 = customErrorString("%ld is larger than maxint, which is: %d", a1, 0x7FFFFFFFLL);
recordError(v3, yylineno, colno, 2LL);
}
v4[0] = a1;
v1 = getPreDefInt(preDefTypeSymbols);
return newConstProxySym(0LL, v4, v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v3; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
if ( (unsigned __int64)(a1 + 0x7FFFFFFF) > 0xFFFFFFFE )
{
v3 = customErrorString("%ld is larger than maxint, which is: %d", a1, 0x7FFFFFFFLL);
recordError(v3, yylineno, colno, 2LL);
}
v4[0] = a1;
v1 = getPreDefInt(preDefTypeSymbols);
return newConstProxySym(0LL, v4, v1);
}

original_code:
ProxySymbol *proxyIntLiteral(long int value) {
 Symbol *newConstProxy = ((void *)0);
 int intValue = 0;
 if (value > 2147483647 || value < -2147483647) {
  errMsg = customErrorString("%ld is larger than maxint, "
      "which is: %d", value, 2147483647);
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 intValue = value;
 Symbol *integerType = getPreDefInt(preDefTypeSymbols);
 newConstProxy = newConstProxySym(((void *)0), &intValue, integerType);
 return newConstProxy;
}

canonical_original_code:
struct Symbol *proxyIntLiteral(long value) {
 struct Symbol *newConstProxy = ((void *)0);
 int intValue = 0;
 if (value > 2147483647 || value < -2147483647) {
  errMsg = customErrorString("%ld is larger than maxint, "
      "which is: %d", value, 2147483647);
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 intValue = value;
 struct Symbol *integerType = getPreDefInt(preDefTypeSymbols);
 newConstProxy = newConstProxySym(((void *)0), &intValue, integerType);
 return newConstProxy;
}

variable_types: value long

variable_types: intValue 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: 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 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: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

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


proxyRealLiteral

decompiled_code:
__int64 __fastcall proxyRealLiteral(double a1)
{
__int64 v1; // rax
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v1 = getPreDefReal(preDefTypeSymbols);
return newConstProxySym(0LL, v3, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1)
{
__int64 v1; // rax
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v1 = getPreDefReal(preDefTypeSymbols);
return newConstProxySym(0LL, v3, v1);
}

original_code:
ProxySymbol *proxyRealLiteral(double value) {
 Symbol *realType = getPreDefReal(preDefTypeSymbols);
 Symbol *newConstProxy = ((void *)0);
 newConstProxy = newConstProxySym(((void *)0), &value, realType);
 return newConstProxy;
}

canonical_original_code:
struct Symbol *proxyRealLiteral(double value) {
 struct Symbol *realType = getPreDefReal(preDefTypeSymbols);
 struct Symbol *newConstProxy = ((void *)0);
 newConstProxy = newConstProxySym(((void *)0), &value, realType);
 return newConstProxy;
}

variable_types: value double

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


proxyCharLiteral

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

v1 = getPreDefChar(preDefTypeSymbols);
return newConstProxySym(0LL, a1, v1);
}

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

v1 = getPreDefChar(preDefTypeSymbols);
return newConstProxySym(0LL, a1, v1);
}

original_code:
ProxySymbol *proxyCharLiteral(struct String s) {
 Symbol *charType = getPreDefChar(preDefTypeSymbols);
 Symbol *newConstProxy = ((void *)0);
 newConstProxy = newConstProxySym(((void *)0), s.str, charType);
 return newConstProxy;
}

canonical_original_code:
struct Symbol *proxyCharLiteral(struct String s) {
 struct Symbol *charType = getPreDefChar(preDefTypeSymbols);
 struct Symbol *newConstProxy = ((void *)0);
 newConstProxy = newConstProxySym(((void *)0), s.str, charType);
 return newConstProxy;
}

variable_types:
s
struct String

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 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 StringType { unsigned int strlen; }

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

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


proxyStringLiteral

decompiled_code:
__int64 __fastcall proxyStringLiteral(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v5[5]; // [rsp+0h] [rbp-28h] BYREF

v5[0] = a1;
v5[1] = a2;
v2 = newStringTypeSym((unsigned int)a2);
v3 = newConstProxySym(0LL, v5, v2);
addToSymbolTable(symbolTable, v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v5[5]; // [rsp+0h] [rbp-28h] BYREF

v5[0] = a1;
v5[1] = a2;
v2 = newStringTypeSym((unsigned int)a2);
v3 = newConstProxySym(0LL, v5, v2);
addToSymbolTable(symbolTable, v2);
return v3;
}

original_code:
Symbol *proxyStringLiteral(struct String s) {
 Symbol *typeSym = ((void *)0);
 ProxySymbol *proxy = ((void *)0);
 typeSym = newStringTypeSym(s.strlen);
 proxy = newConstProxySym(((void *)0), &s, typeSym);
 addToSymbolTable(symbolTable, typeSym);
 return proxy;
}

canonical_original_code:
struct Symbol *proxyStringLiteral(struct String s) {
 struct Symbol *typeSym = ((void *)0);
 struct Symbol *proxy = ((void *)0);
 typeSym = newStringTypeSym(s.strlen);
 proxy = newConstProxySym(((void *)0), &s, typeSym);
 addToSymbolTable(symbolTable, typeSym);
 return proxy;
}

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 kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

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: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

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


setSymbolName

decompiled_code:
void __fastcall setSymbolName(char **a1, const char *a2)
{
size_t v3; // r12
char *v4; // rdi

if ( a2 )
{
v3 = strlen(a2);
v4 = (char *)calloc(1uLL, v3 + 1);
*a1 = v4;
if ( !v4 )
err(1, "Failed to allocate memory for symbol name!");
strncpy(v4, a2, v3);
}
else
{
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(char **a1, const char *a2)
{
size_t v3; // r12
char *v4; // rdi

if ( a2 )
{
v3 = strlen(a2);
v4 = (char *)calloc(1uLL, v3 + 1);
*a1 = v4;
if ( !v4 )
err(1, "Failed to allocate memory for symbol name!");
strncpy(v4, a2, v3);
}
else
{
*a1 = 0LL;
}
}

original_code:
void setSymbolName(Symbol *s, char *id) {
 size_t len;
 if (id == ((void *)0)) {
  s->name = ((void *)0);
  return;
 }
 len = strlen(id) + 1;
 s->name = calloc(1, sizeof(char)*len);
 if (!s->name) {
  err(1, "Failed to allocate memory for symbol name!");
  exit(1);
 }
 strncpy(s->name, id, len - 1);
}

canonical_original_code:
void setSymbolName(struct Symbol *s, char *id) {
 unsigned long len;
 if (id == ((void *)0)) {
  s->name = ((void *)0);
  return;
 }
 len = strlen(id) + 1;
 s->name = calloc(1, sizeof(char)*len);
 if (!s->name) {
  err(1, "Failed to allocate memory for symbol name!");
  exit(1);
 }
 strncpy(s->name, id, len - 1);
}

variable_types:
id
char *

variable_types:
len
unsigned long

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


allocateSymbol

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

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

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

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

original_code:
Symbol *allocateSymbol() {
 Symbol *symbol = ((void *)0);
 symbol = calloc(1, sizeof(Symbol));
 if ( symbol == ((void *)0) ) {
  err(1, "Could not alloc memory for symbol.");
  exit(1);
 }
 return symbol;
}

canonical_original_code:
struct Symbol *allocateSymbol() {
 struct Symbol *symbol = ((void *)0);
 symbol = calloc(1, sizeof(Symbol));
 if ( symbol == ((void *)0) ) {
  err(1, "Could not alloc memory for symbol.");
  exit(1);
 }
 return symbol;
}

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

user_defined_types: union 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 StringType { unsigned int strlen; }

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

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


createSymbol

decompiled_code:
char **__fastcall createSymbol(__int64 a1, const char *a2, int a3, int a4)
{
char **v6; // rax
char **v7; // rbx

v6 = (char **)allocateSymbol();
if ( !v6 )
err(1, "Could not create new symbol.");
v7 = v6;
setSymbolName(v6, a2);
*((_DWORD *)v7 + 2) = a3;
allocateKindPtr(v7);
*((_DWORD *)v7 + 6) = getCurrentLexLevel(a1);
*((_DWORD *)v7 + 7) = a4;
*((_DWORD *)v7 + 11) = 0;
v7[6] = 0LL;
return v7;
}

canonical_decompiled_code:
char **__fastcall func2(__int64 a1, const char *a2, int a3, int a4)
{
char **v6; // rax
char **v7; // rbx

v6 = (char **)func1();
if ( !v6 )
err(1, "Could not create new symbol.");
v7 = v6;
func0(v6, a2);
*((_DWORD *)v7 + 2) = a3;
allocateKindPtr(v7);
*((_DWORD *)v7 + 6) = getCurrentLexLevel(a1);
*((_DWORD *)v7 + 7) = a4;
*((_DWORD *)v7 + 11) = 0;
v7[6] = 0LL;
return v7;
}

original_code:
Symbol *createSymbol(
    struct hash *table, char *id, kind_t kind, int typeOriginator)
{
 Symbol *symbol = allocateSymbol();
 if (symbol == ((void *)0)) {
  err(1, "Could not create new symbol.");
  exit(1);
 }
 setSymbolName(symbol, id);
 symbol->kind = kind;
 allocateKindPtr(symbol);
 symbol->lvl = getCurrentLexLevel(table);
 symbol->typeOriginator = typeOriginator;
 symbol->isRecordHead = 0;
 symbol->next = ((void *)0);
 return symbol;
}

canonical_original_code:
struct Symbol *createSymbol(struct hash *table, char *id, enum kind_t kind, int typeOriginator)
{
 struct Symbol *symbol = allocateSymbol();
 if (symbol == ((void *)0)) {
  err(1, "Could not create new symbol.");
  exit(1);
 }
 setSymbolName(symbol, id);
 symbol->kind = kind;
 allocateKindPtr(symbol);
 symbol->lvl = getCurrentLexLevel(table);
 symbol->typeOriginator = typeOriginator;
 symbol->isRecordHead = 0;
 symbol->next = ((void *)0);
 return symbol;
}

variable_types:
table
struct hash *

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

variable_types: typeOriginator int

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 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: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

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


setSymbolSize

decompiled_code:
void __fastcall setSymbolSize(__int64 a1)
{
if ( a1 && ((__int64 (*)(void))getTypeSym)() )
{
switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
if ( (unsigned int)getType(a1) != 8 )
goto LABEL_6;
*(_DWORD *)(a1 + 36) = 1;
break;
case 1:
case 3:
*(_DWORD *)(a1 + 36) = -1;
break;
case 2:
case 5:
if ( (unsigned int)getType(a1) == 8 )
*(_DWORD *)(a1 + 36) = 1;
else
LABEL_6:
*(_DWORD *)(a1 + 36) = *(_DWORD *)(getTypeSym(a1) + 36);
break;
case 4:
if ( (unsigned int)getType(a1) != 6 )
*(_DWORD *)(a1 + 36) = calculateSymbolSize(a1);
break;
default:
return;
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
if ( a1 && ((__int64 (*)(void))getTypeSym)() )
{
switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
if ( (unsigned int)getType(a1) != 8 )
goto LABEL_6;
*(_DWORD *)(a1 + 36) = 1;
break;
case 1:
case 3:
*(_DWORD *)(a1 + 36) = -1;
break;
case 2:
case 5:
if ( (unsigned int)getType(a1) == 8 )
*(_DWORD *)(a1 + 36) = 1;
else
LABEL_6:
*(_DWORD *)(a1 + 36) = *(_DWORD *)(getTypeSym(a1) + 36);
break;
case 4:
if ( (unsigned int)getType(a1) != 6 )
*(_DWORD *)(a1 + 36) = calculateSymbolSize(a1);
break;
default:
return;
}
}
}

original_code:
void setSymbolSize(Symbol *s)
{
 if (!s) return;
 if (!getTypeSym(s)) return;
 switch (s->kind) {
 case CONST_KIND:
  if (getType(s) == SCALAR_T) s->size = 1;
  else s->size = getTypeSym(s)->size;
  break;
 case PARAM_KIND:
 case VAR_KIND:
  if (getType(s) == SCALAR_T) s->size = 1;
  else s->size = getTypeSym(s)->size;
  break;
 case PROC_KIND:
 case FUNC_KIND:
  s->size = -1;
  break;
 case TYPE_KIND:
 {
  if (getType(s) != RECORD_T) s->size = calculateSymbolSize(s);
  break;
 }
 default:
  break;
 }
}

canonical_original_code:
void setSymbolSize(struct Symbol *s)
{
 if (!s) return;
 if (!getTypeSym(s)) return;
 switch (s->kind) {
 case CONST_KIND:
  if (getType(s) == SCALAR_T) s->size = 1;
  else s->size = getTypeSym(s)->size;
  break;
 case PARAM_KIND:
 case VAR_KIND:
  if (getType(s) == SCALAR_T) s->size = 1;
  else s->size = getTypeSym(s)->size;
  break;
 case PROC_KIND:
 case FUNC_KIND:
  s->size = -1;
  break;
 case TYPE_KIND:
 {
  if (getType(s) != RECORD_T) s->size = calculateSymbolSize(s);
  break;
 }
 default:
  break;
 }
}

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

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


createArrayTypeSymbol

decompiled_code:
__int64 __fastcall createArrayTypeSymbol(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // r13

if ( !a3 || !a4 )
err(1, "Trying to create array type with NULL index or base types. This should be caught further up in Symbols.c");
v6 = createTypeSymbol();
v7 = getKindPtrForTypeKind(v6);
*(_DWORD *)(v7 + 8) = 1;
*(_QWORD *)v7 = newArray(a3, a4);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // r13

if ( !a3 || !a4 )
err(1, "Trying to create array type with NULL index or base types. This should be caught further up in Symbols.c");
v6 = createTypeSymbol();
v7 = getKindPtrForTypeKind(v6);
*(_DWORD *)(v7 + 8) = 1;
*(_QWORD *)v7 = newArray(a3, a4);
return v6;
}

original_code:
Symbol *createArrayTypeSymbol(
   char *id, int typeOriginator, Symbol *base, Symbol *index)
{
 Symbol *symbol = ((void *)0);
 struct TypeKind *kindPtr = ((void *)0);
 if ((base == ((void *)0)) || (index == ((void *)0))) {
  err(1, "Trying to create array type with NULL "
      "index or base types. This should be caught further "
      "up in Symbols.c");
 }
 symbol = createTypeSymbol(id, typeOriginator);
 kindPtr = getKindPtrForTypeKind(symbol);
 kindPtr->type = ARRAY_T;
 kindPtr->typePtr.Array = newArray(base, index);
 return symbol;
}

canonical_original_code:
struct Symbol *createArrayTypeSymbol(char *id, int typeOriginator, struct Symbol *base, struct Symbol *index)
{
 struct Symbol *symbol = ((void *)0);
 struct TypeKind *kindPtr = ((void *)0);
 if ((base == ((void *)0)) || (index == ((void *)0))) {
  err(1, "Trying to create array type with NULL "
      "index or base types. This should be caught further "
      "up in Symbols.c");
 }
 symbol = createTypeSymbol(id, typeOriginator);
 kindPtr = getKindPtrForTypeKind(symbol);
 kindPtr->type = ARRAY_T;
 kindPtr->typePtr.Array = newArray(base, index);
 return symbol;
}

variable_types:
base
struct Symbol *

variable_types:
index
struct Symbol *

variable_types: struct TypeKind { union type_union { struct Array { 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 *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; } *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; } *

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


createScalarListTypeSymbol

decompiled_code:
__int64 __fastcall createScalarListTypeSymbol(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
unsigned int v6; // ebx
__int64 v7; // rdi

if ( !a3 )
err(1, "Trying to make a new scalar list type with empty list. This should be caught further up in Symbols.c");
v4 = createTypeSymbol();
v5 = getKindPtrForTypeKind(v4);
*(_DWORD *)(v5 + 8) = 8;
*(_QWORD *)v5 = newScalar(a3);
if ( *(_DWORD *)(a3 + 12) )
{
v6 = 0;
do
{
v7 = getElementAt(a3, v6);
if ( v7 )
setInnerTypeSymbol(v7, v4);
++v6;
}
while ( *(_DWORD *)(a3 + 12) > v6 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
unsigned int v6; // ebx
__int64 v7; // rdi

if ( !a3 )
err(1, "Trying to make a new scalar list type with empty list. This should be caught further up in Symbols.c");
v4 = createTypeSymbol();
v5 = getKindPtrForTypeKind(v4);
*(_DWORD *)(v5 + 8) = 8;
*(_QWORD *)v5 = newScalar(a3);
if ( *(_DWORD *)(a3 + 12) )
{
v6 = 0;
do
{
v7 = getElementAt(a3, v6);
if ( v7 )
setInnerTypeSymbol(v7, v4);
++v6;
}
while ( *(_DWORD *)(a3 + 12) > v6 );
}
return v4;
}

original_code:
Symbol *createScalarListTypeSymbol(
    char *id, int typeOriginator, struct ElementArray *scalars)
{
 int i = 0;
 Symbol *symbol = ((void *)0);
 Symbol *tmpConstSym = ((void *)0);
 struct TypeKind *kindPtr = ((void *)0);
 if (scalars == ((void *)0)) {
  err(1, "Trying to make a new scalar list type "
      "with empty list. This should be caught further up in "
      "Symbols.c");
 }
 symbol = createTypeSymbol(id, typeOriginator);
 kindPtr = getKindPtrForTypeKind(symbol);
 kindPtr->type = SCALAR_T;
 kindPtr->typePtr.Scalar = newScalar(scalars);
 for (i = 0; i < scalars->nElements; i++) {
  tmpConstSym = getElementAt(scalars, i);
  if (tmpConstSym == ((void *)0)) continue;
  setInnerTypeSymbol(tmpConstSym, symbol);
 }
 return symbol;
}

canonical_original_code:
struct Symbol *createScalarListTypeSymbol(char *id, int typeOriginator, struct ElementArray *scalars)
{
 int i = 0;
 struct Symbol *symbol = ((void *)0);
 struct Symbol *tmpConstSym = ((void *)0);
 struct TypeKind *kindPtr = ((void *)0);
 if (scalars == ((void *)0)) {
  err(1, "Trying to make a new scalar list type "
      "with empty list. This should be caught further up in "
      "Symbols.c");
 }
 symbol = createTypeSymbol(id, typeOriginator);
 kindPtr = getKindPtrForTypeKind(symbol);
 kindPtr->type = SCALAR_T;
 kindPtr->typePtr.Scalar = newScalar(scalars);
 for (i = 0; i < scalars->nElements; i++) {
  tmpConstSym = getElementAt(scalars, i);
  if (tmpConstSym == ((void *)0)) continue;
  setInnerTypeSymbol(tmpConstSym, symbol);
 }
 return symbol;
}

variable_types:
scalars
struct ElementArray *

variable_types: i int

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

user_defined_types: 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 FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

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


newVariableSym

decompiled_code:
__int64 __fastcall newVariableSym(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( !a2 )
return 0LL;
if ( *(_DWORD *)(a2 + 8) != 4 || !a1 )
return 0LL;
v2 = createVarSymbol();
setInnerTypeSymbol(v2, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( !a2 )
return 0LL;
if ( *(_DWORD *)(a2 + 8) != 4 || !a1 )
return 0LL;
v2 = createVarSymbol();
setInnerTypeSymbol(v2, a2);
return v2;
}

original_code:
Symbol *newVariableSym(char *id, Symbol* typeSym) {
 Symbol *newVar = ((void *)0);
 if (typeSym == ((void *)0)) {
  return ((void *)0);
 }
 if (typeSym->kind != TYPE_KIND) {
  return ((void *)0);
 }
 if (id == ((void *)0)) {
  return ((void *)0);
 }
 newVar = createVarSymbol(id);
 setInnerTypeSymbol(newVar, typeSym);
 return newVar;
}

canonical_original_code:
struct Symbol *newVariableSym(char *id, struct Symbol *typeSym) {
 struct Symbol *newVar = ((void *)0);
 if (typeSym == ((void *)0)) {
  return ((void *)0);
 }
 if (typeSym->kind != TYPE_KIND) {
  return ((void *)0);
 }
 if (id == ((void *)0)) {
  return ((void *)0);
 }
 newVar = createVarSymbol(id);
 setInnerTypeSymbol(newVar, typeSym);
 return newVar;
}

variable_types:
typeSym
struct Symbol *

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 Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


newParamSym

decompiled_code:
__int64 __fastcall newParamSym(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( !a1 || !a2 )
return 0LL;
v2 = createParamSymbol();
setInnerTypeSymbol(v2, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( !a1 || !a2 )
return 0LL;
v2 = createParamSymbol();
setInnerTypeSymbol(v2, a2);
return v2;
}

original_code:
Symbol *newParamSym(char *id, Symbol *typeSym) {
 Symbol *newParamSym = ((void *)0);
 if (!typeSym) {
  return ((void *)0);
 }
 if (!id) {
  return ((void *)0);
 }
 newParamSym = createParamSymbol(id);
 setInnerTypeSymbol(newParamSym, typeSym);
 return newParamSym;
}

canonical_original_code:
struct Symbol *newParamSym(char *id, struct Symbol *typeSym) {
 struct Symbol *newParamSym = ((void *)0);
 if (!typeSym) {
  return ((void *)0);
 }
 if (!id) {
  return ((void *)0);
 }
 newParamSym = createParamSymbol(id);
 setInnerTypeSymbol(newParamSym, typeSym);
 return newParamSym;
}

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