emitArrayAssignment

decompiled_code:
__int64 __fastcall emitArrayAssignment(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rdx

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

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

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

variable_types:
y
struct Symbol *

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

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

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

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

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

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

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

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


emitAssignmentOp

repo: a-krebs/YACC

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

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

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

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

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

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

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

return_type: void

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

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

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

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


getPreDefBool

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

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

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

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

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


getPreDefChar

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

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

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

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

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

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

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

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

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


getPreDefInt

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

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

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

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

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

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

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

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

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

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

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

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


getPreDefReal

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

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

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

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

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

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

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

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

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

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

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

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


createPreDefType

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

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

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

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

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

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

variable_types:
name
char *

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

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

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


initializePreDefTypes

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

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

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

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

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

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

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

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

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

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

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


createPreDefFunc

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

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

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

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

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

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

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

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

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

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

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

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

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

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


initializePreDefProc

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

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

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

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

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

return_type: int

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

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


initializePreDefFunc

decompiled_code:
__int64 initializePreDefFunc()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rsi
__int64 v12; // rax

v0 = createPreDefFunc("odd");
addToSymbolTable(symbolTable, v0);
v1 = createPreDefFunc("abs");
addToSymbolTable(symbolTable, v1);
v2 = createPreDefFunc("sqr");
addToSymbolTable(symbolTable, v2);
v3 = createPreDefFunc("sqrt");
addToSymbolTable(symbolTable, v3);
v4 = createPreDefFunc("sin");
addToSymbolTable(symbolTable, v4);
v5 = createPreDefFunc("exp");
addToSymbolTable(symbolTable, v5);
v6 = createPreDefFunc("ln");
addToSymbolTable(symbolTable, v6);
v7 = createPreDefFunc("trunc");
addToSymbolTable(symbolTable, v7);
v8 = createPreDefFunc("round");
addToSymbolTable(symbolTable, v8);
v9 = createPreDefFunc("ord");
addToSymbolTable(symbolTable, v9);
v10 = createPreDefFunc("chr");
addToSymbolTable(symbolTable, v10);
v11 = createPreDefFunc("succ");
addToSymbolTable(symbolTable, v11);
v12 = createPreDefFunc("pred");
addToSymbolTable(symbolTable, v12);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rsi
__int64 v12; // rax

v0 = func6("odd");
addToSymbolTable(symbolTable, v0);
v1 = func6("abs");
addToSymbolTable(symbolTable, v1);
v2 = func6("sqr");
addToSymbolTable(symbolTable, v2);
v3 = func6("sqrt");
addToSymbolTable(symbolTable, v3);
v4 = func6("sin");
addToSymbolTable(symbolTable, v4);
v5 = func6("exp");
addToSymbolTable(symbolTable, v5);
v6 = func6("ln");
addToSymbolTable(symbolTable, v6);
v7 = func6("trunc");
addToSymbolTable(symbolTable, v7);
v8 = func6("round");
addToSymbolTable(symbolTable, v8);
v9 = func6("ord");
addToSymbolTable(symbolTable, v9);
v10 = func6("chr");
addToSymbolTable(symbolTable, v10);
v11 = func6("succ");
addToSymbolTable(symbolTable, v11);
v12 = func6("pred");
addToSymbolTable(symbolTable, v12);
return 0LL;
}

original_code:
int initializePreDefFunc() {
 struct Symbol *symbol;
 symbol = createPreDefFunc("odd");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("abs");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("sqr");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("sqrt");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("sin");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("exp");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("ln");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("trunc");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("round");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("ord");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("chr");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("succ");
 addToSymbolTable(symbolTable, symbol);
 symbol = createPreDefFunc("pred");
 addToSymbolTable(symbolTable, symbol);
 return 0;
}

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

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

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

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

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

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


createNewBoolConst

decompiled_code:
__int64 __fastcall createNewBoolConst(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rax

v2 = createConstSymbol();
v3 = getPreDefBool(preDefTypeSymbols);
setInnerTypeSymbol(v2, v3);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 16LL) = a2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rax

v2 = createConstSymbol();
v3 = func0(preDefTypeSymbols);
setInnerTypeSymbol(v2, v3);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 16LL) = a2;
return v2;
}

original_code:
Symbol *createNewBoolConst(char *name, int val) {
 Symbol *symbol = ((void *)0);
 symbol = createConstSymbol(name);
 setInnerTypeSymbol(symbol, getPreDefBool(preDefTypeSymbols));
 symbol->kindPtr.ConstKind->value.Boolean.value = val;
 return symbol;
}

canonical_original_code:
struct Symbol *createNewBoolConst(char *name, int val) {
 struct Symbol *symbol = ((void *)0);
 symbol = createConstSymbol(name);
 setInnerTypeSymbol(symbol, getPreDefBool(preDefTypeSymbols));
 symbol->kindPtr.ConstKind->value.Boolean.value = val;
 return symbol;
}

variable_types: val 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 ProcedureKind { struct ElementArray *params; char *label; }

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

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

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

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

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

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


createNewIntConst

decompiled_code:
__int64 __fastcall createNewIntConst(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rax

v2 = createConstSymbol();
v3 = getPreDefInt(preDefTypeSymbols);
setInnerTypeSymbol(v2, v3);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 16LL) = a2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rax

v2 = createConstSymbol();
v3 = func2(preDefTypeSymbols);
setInnerTypeSymbol(v2, v3);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 16LL) = a2;
return v2;
}

original_code:
Symbol *createNewIntConst(char *name, int val) {
 Symbol *symbol = ((void *)0);
 symbol = createConstSymbol(name);
 setInnerTypeSymbol(symbol, getPreDefInt(preDefTypeSymbols));
 symbol->kindPtr.ConstKind->value.Integer.value = val;
 return symbol;
}

canonical_original_code:
struct Symbol *createNewIntConst(char *name, int val) {
 struct Symbol *symbol = ((void *)0);
 symbol = createConstSymbol(name);
 setInnerTypeSymbol(symbol, getPreDefInt(preDefTypeSymbols));
 symbol->kindPtr.ConstKind->value.Integer.value = val;
 return symbol;
}

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


initializePreDefConstants

decompiled_code:
__int64 initializePreDefConstants()
{
__int64 v0; // rbp
__int64 v1; // rbp
__int64 v2; // rbp

emitBlankLine();
emitSepLine();
emitBlankLine();
emitComment("Pre-defined constants to follow");
emitBlankLine();
emitSepLine();
emitBlankLine();
v0 = createNewBoolConst((__int64)"true", 1);
addToSymbolTable(symbolTable, v0);
setSymbolOffset(v0, symbolTable);
emitConstDecl(v0);
v1 = createNewBoolConst((__int64)"false", 0);
addToSymbolTable(symbolTable, v1);
setSymbolOffset(v1, symbolTable);
emitConstDecl(v1);
v2 = createNewIntConst((__int64)"maxint", 0x7FFFFFFF);
addToSymbolTable(symbolTable, v2);
setSymbolOffset(v2, symbolTable);
emitConstDecl(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rbp
__int64 v1; // rbp
__int64 v2; // rbp

emitBlankLine();
emitSepLine();
emitBlankLine();
emitComment("Pre-defined constants to follow");
emitBlankLine();
emitSepLine();
emitBlankLine();
v0 = func9((__int64)"true", 1);
addToSymbolTable(symbolTable, v0);
setSymbolOffset(v0, symbolTable);
emitConstDecl(v0);
v1 = func9((__int64)"false", 0);
addToSymbolTable(symbolTable, v1);
setSymbolOffset(v1, symbolTable);
emitConstDecl(v1);
v2 = func10((__int64)"maxint", 0x7FFFFFFF);
addToSymbolTable(symbolTable, v2);
setSymbolOffset(v2, symbolTable);
emitConstDecl(v2);
return 0LL;
}

original_code:
int initializePreDefConstants() {
 Symbol *symbol = ((void *)0);
 emitBlankLine();
 emitSepLine();
 emitBlankLine();
 emitComment("Pre-defined constants to follow");
 emitBlankLine();
 emitSepLine();
 emitBlankLine();
 symbol = createNewBoolConst("true", 1);
 addToSymbolTable(symbolTable, symbol);
 setSymbolOffset(symbol, symbolTable);
 emitConstDecl(symbol);
 symbol = createNewBoolConst("false", 0);
 addToSymbolTable(symbolTable, symbol);
 setSymbolOffset(symbol, symbolTable);
 emitConstDecl(symbol);
 symbol = createNewIntConst("maxint", 2147483647);
 addToSymbolTable(symbolTable, symbol);
 setSymbolOffset(symbol, symbolTable);
 emitConstDecl(symbol);
 return 0;
}

canonical_original_code:
int initializePreDefConstants() {
 struct Symbol *symbol = ((void *)0);
 emitBlankLine();
 emitSepLine();
 emitBlankLine();
 emitComment("Pre-defined constants to follow");
 emitBlankLine();
 emitSepLine();
 emitBlankLine();
 symbol = createNewBoolConst("true", 1);
 addToSymbolTable(symbolTable, symbol);
 setSymbolOffset(symbol, symbolTable);
 emitConstDecl(symbol);
 symbol = createNewBoolConst("false", 0);
 addToSymbolTable(symbolTable, symbol);
 setSymbolOffset(symbol, symbolTable);
 emitConstDecl(symbol);
 symbol = createNewIntConst("maxint", 2147483647);
 addToSymbolTable(symbolTable, symbol);
 setSymbolOffset(symbol, symbolTable);
 emitConstDecl(symbol);
 return 0;
}

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

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

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

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

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

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


isValidProcInvocation

decompiled_code:
__int64 __fastcall isValidProcInvocation(const char **a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er8
__int64 v4; // rcx
unsigned int v5; // er12
__int64 v6; // r14
__int64 v7; // rbp
unsigned int v8; // er13
__int64 v10; // rax
unsigned int v11; // eax
const char *v12; // rbx
unsigned int v13; // eax
const char *v14; // rax
__int64 v15; // rax

if ( *((_DWORD *)a1 + 2) != 3 )
{
v10 = customErrorString("Identifier %s cannot be called as a procedure.", *a1);
goto LABEL_13;
}
v2 = *(_QWORD *)a1[2];
if ( v2 )
{
v3 = *(_DWORD *)(v2 + 12);
v4 = *(unsigned int *)(a2 + 12);
if ( v3 == (_DWORD)v4 )
{
v5 = 0;
if ( (_DWORD)v4 )
{
while ( (unsigned int)v4 > v5 )
{
v6 = *(_QWORD *)getElementAt(a2, v5);
v7 = getElementAt(v2, v5);
v8 = isAssignmentCompat(v7, v6);
if ( !v8 )
{
v11 = getType(v6);
v12 = (const char *)typeToString(v11);
v13 = getType(v7);
v14 = (const char *)typeToString(v13);
v15 = customErrorString(
"Procedure %s expects argument of type %s at index %d, but got argument of type %s",
*a1,
v14,
v5,
v12);
e = recordError(v15, yylineno, colno, 2LL);
return v8;
}
if ( *(_DWORD *)(v2 + 12) <= ++v5 )
return 1;
LODWORD(v4) = *(_DWORD *)(a2 + 12);
}
}
return 1;
}
v10 = customErrorString("Procedure %s expects %d parameters, got %d", *a1, v3, v4);
LABEL_13:
v8 = 0;
e = recordError(v10, yylineno, colno, 2LL);
return v8;
}
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er8
__int64 v4; // rcx
unsigned int v5; // er12
__int64 v6; // r14
__int64 v7; // rbp
unsigned int v8; // er13
__int64 v10; // rax
unsigned int v11; // eax
const char *v12; // rbx
unsigned int v13; // eax
const char *v14; // rax
__int64 v15; // rax

if ( *((_DWORD *)a1 + 2) != 3 )
{
v10 = customErrorString("Identifier %s cannot be called as a procedure.", *a1);
goto LABEL_13;
}
v2 = *(_QWORD *)a1[2];
if ( v2 )
{
v3 = *(_DWORD *)(v2 + 12);
v4 = *(unsigned int *)(a2 + 12);
if ( v3 == (_DWORD)v4 )
{
v5 = 0;
if ( (_DWORD)v4 )
{
while ( (unsigned int)v4 > v5 )
{
v6 = *(_QWORD *)getElementAt(a2, v5);
v7 = getElementAt(v2, v5);
v8 = isAssignmentCompat(v7, v6);
if ( !v8 )
{
v11 = getType(v6);
v12 = (const char *)typeToString(v11);
v13 = getType(v7);
v14 = (const char *)typeToString(v13);
v15 = customErrorString(
"Procedure %s expects argument of type %s at index %d, but got argument of type %s",
*a1,
v14,
v5,
v12);
e = recordError(v15, yylineno, colno, 2LL);
return v8;
}
if ( *(_DWORD *)(v2 + 12) <= ++v5 )
return 1;
LODWORD(v4) = *(_DWORD *)(a2 + 12);
}
}
return 1;
}
v10 = customErrorString("Procedure %s expects %d parameters, got %d", *a1, v3, v4);
LABEL_13:
v8 = 0;
e = recordError(v10, yylineno, colno, 2LL);
return v8;
}
return 1;
}

original_code:
int isValidProcInvocation(Symbol *s, struct ElementArray *ea)
{
 struct ElementArray *params = ((void *)0);
 Symbol *passedParam, *expectedParam = ((void *)0);
 int i;
 if (s->kind != PROC_KIND) {
  errMsg = customErrorString("Identifier %s cannot be called "
      "as a procedure.", s->name);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 params = s->kindPtr.ProcKind->params;
 if (!params) {
  return 1;
 } else if (params->nElements != ea->nElements) {
  errMsg = customErrorString("Procedure %s expects %d "
      "parameters, got %d", s->name, params->nElements,
      ea->nElements);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 for (i = 0; (i < params->nElements) && (i < ea->nElements); i++) {
  passedParam = ((struct treeNode *)getElementAt(ea, i))->symbol;
  expectedParam = (Symbol *) getElementAt(params, i);
  if (!isAssignmentCompat(expectedParam, passedParam)) {
   errMsg = customErrorString("Procedure %s expects "
       "argument of type %s at index %d, but got "
       "argument of type %s", s->name,
       typeToString(getType(expectedParam)), i,
       typeToString(getType(passedParam)));
   e = recordError(errMsg, yylineno, colno,
        SEMANTIC);
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int isValidProcInvocation(struct Symbol *s, struct ElementArray *ea)
{
 struct ElementArray *params = ((void *)0);
 struct Symbol *passedParam; struct Symbol *expectedParam = ((void *)0);
 int i;
 if (s->kind != PROC_KIND) {
  errMsg = customErrorString("Identifier %s cannot be called "
      "as a procedure.", s->name);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 params = s->kindPtr.ProcKind->params;
 if (!params) {
  return 1;
 } else if (params->nElements != ea->nElements) {
  errMsg = customErrorString("Procedure %s expects %d "
      "parameters, got %d", s->name, params->nElements,
      ea->nElements);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 for (i = 0; (i < params->nElements) && (i < ea->nElements); i++) {
  passedParam = ((struct treeNode *)getElementAt(ea, i))->symbol;
  expectedParam = (struct Symbol *) getElementAt(params, i);
  if (!isAssignmentCompat(expectedParam, passedParam)) {
   errMsg = customErrorString("Procedure %s expects "
       "argument of type %s at index %d, but got "
       "argument of type %s", s->name,
       typeToString(getType(expectedParam)), i,
       typeToString(getType(passedParam)));
   e = recordError(errMsg, yylineno, colno,
        SEMANTIC);
   return 0;
  }
 }
 return 1;
}

variable_types:
ea
struct ElementArray *

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

variable_types: i int

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

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

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

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

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

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

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

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

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


isValidFuncInvocation

decompiled_code:
__int64 __fastcall isValidFuncInvocation(const char **a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er12
__int64 v6; // r13
__int64 v7; // rbp
unsigned int v8; // eax
const char *v9; // rbx
unsigned int v10; // eax
const char *v11; // rax
__int64 v12; // rax

if ( *((_DWORD *)a1 + 2) != 1 )
{
v12 = customErrorString("Identifier %s cannot be called as a function.", *a1);
goto LABEL_9;
}
v2 = *((_QWORD *)a1[2] + 1);
if ( v2 )
{
v3 = *(unsigned int *)(v2 + 12);
v4 = *(unsigned int *)(a2 + 12);
if ( (_DWORD)v3 == (_DWORD)v4 )
{
v5 = 0;
if ( !(_DWORD)v3 )
return getTypeSym(a1);
while ( 1 )
{
v6 = *(_QWORD *)getElementAt(a2, v5);
v7 = getElementAt(v2, v5);
if ( !(unsigned int)isAssignmentCompat(v7, v6) )
break;
if ( ++v5 >= *(_DWORD *)(v2 + 12) )
return getTypeSym(a1);
}
v8 = getType(v6);
v9 = (const char *)typeToString(v8);
v10 = getType(v7);
v11 = (const char *)typeToString(v10);
v12 = customErrorString(
"Procedure %s expects argument of type %s at index %d, but got argument of type %s",
*a1,
v11,
v5,
v9);
}
else
{
v12 = customErrorString("Procedure %s expects %d parameters, got %d", *a1, v3, v4);
}
LABEL_9:
e = recordError(v12, yylineno, colno, 2LL);
return 0LL;
}
return getTypeSym(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er12
__int64 v6; // r13
__int64 v7; // rbp
unsigned int v8; // eax
const char *v9; // rbx
unsigned int v10; // eax
const char *v11; // rax
__int64 v12; // rax

if ( *((_DWORD *)a1 + 2) != 1 )
{
v12 = customErrorString("Identifier %s cannot be called as a function.", *a1);
goto LABEL_9;
}
v2 = *((_QWORD *)a1[2] + 1);
if ( v2 )
{
v3 = *(unsigned int *)(v2 + 12);
v4 = *(unsigned int *)(a2 + 12);
if ( (_DWORD)v3 == (_DWORD)v4 )
{
v5 = 0;
if ( !(_DWORD)v3 )
return getTypeSym(a1);
while ( 1 )
{
v6 = *(_QWORD *)getElementAt(a2, v5);
v7 = getElementAt(v2, v5);
if ( !(unsigned int)isAssignmentCompat(v7, v6) )
break;
if ( ++v5 >= *(_DWORD *)(v2 + 12) )
return getTypeSym(a1);
}
v8 = getType(v6);
v9 = (const char *)typeToString(v8);
v10 = getType(v7);
v11 = (const char *)typeToString(v10);
v12 = customErrorString(
"Procedure %s expects argument of type %s at index %d, but got argument of type %s",
*a1,
v11,
v5,
v9);
}
else
{
v12 = customErrorString("Procedure %s expects %d parameters, got %d", *a1, v3, v4);
}
LABEL_9:
e = recordError(v12, yylineno, colno, 2LL);
return 0LL;
}
return getTypeSym(a1);
}

original_code:
Symbol *
isValidFuncInvocation(Symbol *s, struct ElementArray *ea)
{
 struct ElementArray *params = ((void *)0);
 Symbol *passedParam, *expectedParam = ((void *)0);
 int i;
 if (s->kind != FUNC_KIND) {
  errMsg = customErrorString("Identifier %s cannot be "
    "called as a function.", s->name);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 params = s->kindPtr.FuncKind->params;
 if (!params) {
  return getTypeSym(s);
 } else if (params->nElements != ea->nElements) {
  errMsg = customErrorString("Procedure %s expects %d "
      "parameters, got %d", s->name, params->nElements,
      ea->nElements);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 for (i = 0; i < params->nElements; i++) {
  passedParam = ((struct treeNode *)getElementAt(ea, i))->symbol;
  expectedParam = (Symbol *) getElementAt(params, i);
  if (!isAssignmentCompat(expectedParam,passedParam)) {
   errMsg = customErrorString("Procedure %s expects "
       "argument of type %s at index %d, but got "
       "argument of type %s", s->name,
       typeToString(getType(expectedParam)),i,
       typeToString(getType(passedParam)));
   e = recordError(errMsg, yylineno, colno, SEMANTIC);
   return ((void *)0);
  }
 }
 return getTypeSym(s);
}

canonical_original_code:
struct Symbol *isValidFuncInvocation(struct Symbol *s, struct ElementArray *ea)
{
 struct ElementArray *params = ((void *)0);
 struct Symbol *passedParam; struct Symbol *expectedParam = ((void *)0);
 int i;
 if (s->kind != FUNC_KIND) {
  errMsg = customErrorString("Identifier %s cannot be "
    "called as a function.", s->name);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 params = s->kindPtr.FuncKind->params;
 if (!params) {
  return getTypeSym(s);
 } else if (params->nElements != ea->nElements) {
  errMsg = customErrorString("Procedure %s expects %d "
      "parameters, got %d", s->name, params->nElements,
      ea->nElements);
  e = recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 for (i = 0; i < params->nElements; i++) {
  passedParam = ((struct treeNode *)getElementAt(ea, i))->symbol;
  expectedParam = (struct Symbol *) getElementAt(params, i);
  if (!isAssignmentCompat(expectedParam,passedParam)) {
   errMsg = customErrorString("Procedure %s expects "
       "argument of type %s at index %d, but got "
       "argument of type %s", s->name,
       typeToString(getType(expectedParam)),i,
       typeToString(getType(passedParam)));
   e = recordError(errMsg, yylineno, colno, SEMANTIC);
   return ((void *)0);
  }
 }
 return getTypeSym(s);
}

variable_types:
s
struct Symbol *

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


isIOProc

decompiled_code:
_BOOL8 __fastcall isIOProc(__int64 a1)
{
_BOOL4 v1; // er8
const char *v2; // r9

v1 = 0;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) == 3 )
{
v2 = *(const char **)a1;
if ( !strcmp(*(const char **)a1, "read")
|| !strcmp(v2, "readln")
|| !strcmp(v2, "write")
|| !strcmp(v2, "writeln") )
{
v1 = *(_DWORD *)(a1 + 24) == 0;
}
}
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
_BOOL4 v1; // er8
const char *v2; // r9

v1 = 0;
if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) == 3 )
{
v2 = *(const char **)a1;
if ( !strcmp(*(const char **)a1, "read")
|| !strcmp(v2, "readln")
|| !strcmp(v2, "write")
|| !strcmp(v2, "writeln") )
{
v1 = *(_DWORD *)(a1 + 24) == 0;
}
}
}
return v1;
}

original_code:
int
isIOProc(Symbol *s) {
 if (!s) return 0;
 if (s->kind != PROC_KIND) return 0;
 if ( ( (strcmp(s->name, "read") == 0) ||
      (strcmp(s->name, "readln") == 0) ||
      (strcmp(s->name, "write") == 0) ||
      (strcmp(s->name, "writeln") == 0) ) &&
  (s->lvl == 0) ) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int isIOProc(struct Symbol *s) {
 if (!s) return 0;
 if (s->kind != PROC_KIND) return 0;
 if ( ( (strcmp(s->name, "read") == 0) ||
      (strcmp(s->name, "readln") == 0) ||
      (strcmp(s->name, "write") == 0) ||
      (strcmp(s->name, "writeln") == 0) ) &&
  (s->lvl == 0) ) {
  return 1;
 }
 return 0;
}

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

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

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

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

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

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


isPreDefFunc

decompiled_code:
_BOOL8 __fastcall isPreDefFunc(__int64 a1)
{
_BOOL8 result; // rax
const char *v2; // rbp
int v3; // er8

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 8) == 1 )
{
if ( (v2 = *(const char **)a1, !strcmp(*(const char **)a1, "abs"))
|| !strcmp(v2, "sqr")
|| !strcmp(v2, "sin")
|| !strcmp(v2, "exp")
|| *v2 == 108 && v2[1] == 110 && !v2[2]
|| !strcmp(v2, "sqrt")
|| !strcmp(v2, "trunc")
|| !strcmp(v2, "round")
|| !strcmp(v2, "chr")
|| !strcmp(v2, "odd")
|| !strcmp(v2, "ord")
|| !strcmp(v2, "succ")
|| (v3 = strcmp(v2, "pred"), result = 0LL, !v3) )
{
result = *(_DWORD *)(a1 + 24) == 0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
_BOOL8 result; // rax
const char *v2; // rbp
int v3; // er8

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 8) == 1 )
{
if ( (v2 = *(const char **)a1, !strcmp(*(const char **)a1, "abs"))
|| !strcmp(v2, "sqr")
|| !strcmp(v2, "sin")
|| !strcmp(v2, "exp")
|| *v2 == 108 && v2[1] == 110 && !v2[2]
|| !strcmp(v2, "sqrt")
|| !strcmp(v2, "trunc")
|| !strcmp(v2, "round")
|| !strcmp(v2, "chr")
|| !strcmp(v2, "odd")
|| !strcmp(v2, "ord")
|| !strcmp(v2, "succ")
|| (v3 = strcmp(v2, "pred"), result = 0LL, !v3) )
{
result = *(_DWORD *)(a1 + 24) == 0;
}
}
return result;
}

original_code:
int isPreDefFunc(Symbol *s) {
 char *name = ((void *)0);
 if (!s) return 0;
 if (s->kind != FUNC_KIND) return 0;
 name = s->name;
 if ( ( (strcmp(name, "abs") == 0) ||
  (strcmp(name, "sqr") == 0) ||
  (strcmp(name, "sin") == 0) ||
  (strcmp(name, "exp") == 0) ||
  (strcmp(name, "ln") == 0) ||
  (strcmp(name, "sqrt") == 0) ||
  (strcmp(name, "trunc") == 0) ||
  (strcmp(name, "round") == 0) ||
  (strcmp(name, "chr") == 0) ||
  (strcmp(name, "odd") == 0) ||
  (strcmp(name, "ord") == 0) ||
  (strcmp(name, "succ") == 0) ||
  (strcmp(name, "pred") == 0) ) &&
   s->lvl == 0) {
     return 1;
 }
 return 0;
}

canonical_original_code:
int isPreDefFunc(struct Symbol *s) {
 char *name = ((void *)0);
 if (!s) return 0;
 if (s->kind != FUNC_KIND) return 0;
 name = s->name;
 if ( ( (strcmp(name, "abs") == 0) ||
  (strcmp(name, "sqr") == 0) ||
  (strcmp(name, "sin") == 0) ||
  (strcmp(name, "exp") == 0) ||
  (strcmp(name, "ln") == 0) ||
  (strcmp(name, "sqrt") == 0) ||
  (strcmp(name, "trunc") == 0) ||
  (strcmp(name, "round") == 0) ||
  (strcmp(name, "chr") == 0) ||
  (strcmp(name, "odd") == 0) ||
  (strcmp(name, "ord") == 0) ||
  (strcmp(name, "succ") == 0) ||
  (strcmp(name, "pred") == 0) ) &&
   s->lvl == 0) {
     return 1;
 }
 return 0;
}

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

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

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

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

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

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

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

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


getPreDefFuncReturnType

decompiled_code:
__int64 __fastcall getPreDefFuncReturnType(const char **a1, __int64 a2, __int64 a3)
{
const char *v4; // rax
bool v5; // dl
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
bool v14; // cf
bool v15; // zf
const char *v17; // rdi
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
const char *v22; // rsi
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
bool v26; // cf
bool v27; // zf
const char *v28; // rdi
bool v29; // cf
bool v30; // zf
const char *v31; // rdi
__int64 v32; // rcx
const char *v33; // rsi
bool v34; // cf
bool v35; // zf
const char *v36; // rsi
const char *v37; // rdi
__int64 v38; // rcx

if ( !a1 )
return 0LL;
v4 = *a1;
if ( !strcmp(*a1, "abs") )
return a2;
if ( !strcmp(v4, "sqr") )
return a2;
if ( !strcmp(v4, "succ") )
return a2;
v5 = strcmp(v4, "pred") != 0;
v6 = 0;
v7 = !v5;
if ( !v5 )
return a2;
v8 = "sin";
v9 = 4LL;
v10 = v4;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
LOBYTE(a3) = (!v6 && !v7) - v6;
v11 = 0;
v12 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
v13 = "exp";
v9 = 4LL;
v10 = v4;
do
{
if ( !v9 )
break;
v11 = *v10 < (unsigned int)*v13;
v12 = *v10++ == *v13++;
--v9;
}
while ( v12 );
LOBYTE(a3) = (!v11 && !v12) - v11;
if ( !(_BYTE)a3 )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
v14 = *v4 < 0x6Cu;
v15 = *v4 == 108;
if ( *v4 == 108 )
{
v14 = v4[1] < 0x6Eu;
v15 = v4[1] == 110;
if ( v4[1] == 110 )
{
v14 = 0;
v15 = v4[2] == 0;
if ( !v4[2] )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
}
}
v17 = "sqrt";
v9 = 5LL;
v10 = v4;
do
{
if ( !v9 )
break;
v14 = *v10 < (unsigned int)*v17;
v15 = *v10++ == *v17++;
--v9;
}
while ( v15 );
LOBYTE(a3) = (!v14 && !v15) - v14;
v18 = 0;
v19 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
v20 = "trunc";
v21 = 6LL;
v22 = v4;
do
{
if ( !v21 )
break;
v18 = *v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
LOBYTE(a3) = (!v18 && !v19) - v18;
v23 = 0;
v24 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefInt(preDefTypeSymbols, v22, a3, v21, a2);
v25 = "round";
v21 = 6LL;
v22 = v4;
do
{
if ( !v21 )
break;
v23 = *v22 < (unsigned int)*v25;
v24 = *v22++ == *v25++;
--v21;
}
while ( v24 );
LOBYTE(a3) = (!v23 && !v24) - v23;
v26 = 0;
v27 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefInt(preDefTypeSymbols, v22, a3, v21, a2);
v28 = "ord";
v21 = 4LL;
v22 = v4;
do
{
if ( !v21 )
break;
v26 = *v22 < (unsigned int)*v28;
v27 = *v22++ == *v28++;
--v21;
}
while ( v27 );
LOBYTE(a3) = (!v26 && !v27) - v26;
v29 = 0;
v30 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefInt(preDefTypeSymbols, v22, a3, v21, a2);
v31 = "chr";
v32 = 4LL;
v33 = v4;
do
{
if ( !v32 )
break;
v29 = *v33 < (unsigned int)*v31;
v30 = *v33++ == *v31++;
--v32;
}
while ( v30 );
LOBYTE(a3) = (!v29 && !v30) - v29;
v34 = 0;
v35 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
v36 = v4;
v37 = "odd";
v38 = 4LL;
do
{
if ( !v38 )
break;
v34 = *v36 < (unsigned int)*v37;
v35 = *v36++ == *v37++;
--v38;
}
while ( v35 );
a2 = 0LL;
if ( (!v34 && !v35) == v34 )
return getPreDefBool(preDefTypeSymbols, v36, a3, v38, 0LL);
return a2;
}
return getPreDefChar(preDefTypeSymbols, v33, a3, v32, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char **a1, __int64 a2, __int64 a3)
{
const char *v4; // rax
bool v5; // dl
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
bool v14; // cf
bool v15; // zf
const char *v17; // rdi
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
const char *v22; // rsi
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
bool v26; // cf
bool v27; // zf
const char *v28; // rdi
bool v29; // cf
bool v30; // zf
const char *v31; // rdi
__int64 v32; // rcx
const char *v33; // rsi
bool v34; // cf
bool v35; // zf
const char *v36; // rsi
const char *v37; // rdi
__int64 v38; // rcx

if ( !a1 )
return 0LL;
v4 = *a1;
if ( !strcmp(*a1, "abs") )
return a2;
if ( !strcmp(v4, "sqr") )
return a2;
if ( !strcmp(v4, "succ") )
return a2;
v5 = strcmp(v4, "pred") != 0;
v6 = 0;
v7 = !v5;
if ( !v5 )
return a2;
v8 = "sin";
v9 = 4LL;
v10 = v4;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
LOBYTE(a3) = (!v6 && !v7) - v6;
v11 = 0;
v12 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
v13 = "exp";
v9 = 4LL;
v10 = v4;
do
{
if ( !v9 )
break;
v11 = *v10 < (unsigned int)*v13;
v12 = *v10++ == *v13++;
--v9;
}
while ( v12 );
LOBYTE(a3) = (!v11 && !v12) - v11;
if ( !(_BYTE)a3 )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
v14 = *v4 < 0x6Cu;
v15 = *v4 == 108;
if ( *v4 == 108 )
{
v14 = v4[1] < 0x6Eu;
v15 = v4[1] == 110;
if ( v4[1] == 110 )
{
v14 = 0;
v15 = v4[2] == 0;
if ( !v4[2] )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
}
}
v17 = "sqrt";
v9 = 5LL;
v10 = v4;
do
{
if ( !v9 )
break;
v14 = *v10 < (unsigned int)*v17;
v15 = *v10++ == *v17++;
--v9;
}
while ( v15 );
LOBYTE(a3) = (!v14 && !v15) - v14;
v18 = 0;
v19 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefReal(preDefTypeSymbols, v10, a3, v9, a2);
v20 = "trunc";
v21 = 6LL;
v22 = v4;
do
{
if ( !v21 )
break;
v18 = *v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
LOBYTE(a3) = (!v18 && !v19) - v18;
v23 = 0;
v24 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefInt(preDefTypeSymbols, v22, a3, v21, a2);
v25 = "round";
v21 = 6LL;
v22 = v4;
do
{
if ( !v21 )
break;
v23 = *v22 < (unsigned int)*v25;
v24 = *v22++ == *v25++;
--v21;
}
while ( v24 );
LOBYTE(a3) = (!v23 && !v24) - v23;
v26 = 0;
v27 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefInt(preDefTypeSymbols, v22, a3, v21, a2);
v28 = "ord";
v21 = 4LL;
v22 = v4;
do
{
if ( !v21 )
break;
v26 = *v22 < (unsigned int)*v28;
v27 = *v22++ == *v28++;
--v21;
}
while ( v27 );
LOBYTE(a3) = (!v26 && !v27) - v26;
v29 = 0;
v30 = (_BYTE)a3 == 0;
if ( !(_BYTE)a3 )
return getPreDefInt(preDefTypeSymbols, v22, a3, v21, a2);
v31 = "chr";
v32 = 4LL;
v33 = v4;
do
{
if ( !v32 )
break;
v29 = *v33 < (unsigned int)*v31;
v30 = *v33++ == *v31++;
--v32;
}
while ( v30 );
LOBYTE(a3) = (!v29 && !v30) - v29;
v34 = 0;
v35 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
v36 = v4;
v37 = "odd";
v38 = 4LL;
do
{
if ( !v38 )
break;
v34 = *v36 < (unsigned int)*v37;
v35 = *v36++ == *v37++;
--v38;
}
while ( v35 );
a2 = 0LL;
if ( (!v34 && !v35) == v34 )
return getPreDefBool(preDefTypeSymbols, v36, a3, v38, 0LL);
return a2;
}
return getPreDefChar(preDefTypeSymbols, v33, a3, v32, a2);
}

original_code:
Symbol *getPreDefFuncReturnType(Symbol *s, Symbol *argTypeSym) {
 char *name = ((void *)0);
 if (!s) return ((void *)0);
 name = s->name;
 if (
     (strcmp(name, "abs") == 0) ||
     (strcmp(name, "sqr") == 0) ||
     (strcmp(name, "succ") == 0) ||
     (strcmp(name, "pred") == 0)
 ) {
  return argTypeSym;
 } else if (
     (strcmp(name, "sin") == 0) ||
     (strcmp(name, "exp") == 0) ||
     (strcmp(name, "ln") == 0) ||
     (strcmp(name, "sqrt") == 0)
 ) {
  return getPreDefReal(preDefTypeSymbols);
 } else if (
     (strcmp(name, "trunc") == 0) ||
     (strcmp(name, "round") == 0) ||
     (strcmp(name, "ord") == 0)
 ){
  return getPreDefInt(preDefTypeSymbols);
 } else if (
     (strcmp(name, "chr") == 0)
 ){
  return getPreDefChar(preDefTypeSymbols);
 } else if (
     (strcmp(name, "odd") == 0)
 ){
  return getPreDefBool(preDefTypeSymbols);
 }
 return ((void *)0);
}

canonical_original_code:
struct Symbol *getPreDefFuncReturnType(struct Symbol *s, struct Symbol *argTypeSym) {
 char *name = ((void *)0);
 if (!s) return ((void *)0);
 name = s->name;
 if (
     (strcmp(name, "abs") == 0) ||
     (strcmp(name, "sqr") == 0) ||
     (strcmp(name, "succ") == 0) ||
     (strcmp(name, "pred") == 0)
 ) {
  return argTypeSym;
 } else if (
     (strcmp(name, "sin") == 0) ||
     (strcmp(name, "exp") == 0) ||
     (strcmp(name, "ln") == 0) ||
     (strcmp(name, "sqrt") == 0)
 ) {
  return getPreDefReal(preDefTypeSymbols);
 } else if (
     (strcmp(name, "trunc") == 0) ||
     (strcmp(name, "round") == 0) ||
     (strcmp(name, "ord") == 0)
 ){
  return getPreDefInt(preDefTypeSymbols);
 } else if (
     (strcmp(name, "chr") == 0)
 ){
  return getPreDefChar(preDefTypeSymbols);
 } else if (
     (strcmp(name, "odd") == 0)
 ){
  return getPreDefBool(preDefTypeSymbols);
 }
 return ((void *)0);
}

variable_types:
argTypeSym
struct Symbol *

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


paramToVar

decompiled_code:
__int64 __fastcall paramToVar(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // r12

if ( !a1 )
return 0LL;
v1 = getTypeSym(a1);
v2 = newVariableSym(*a1, v1);
if ( !v2 )
return 0LL;
if ( (unsigned int)isByReference(a1) )
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 8LL) = 1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // r12

if ( !a1 )
return 0LL;
v1 = getTypeSym(a1);
v2 = newVariableSym(*a1, v1);
if ( !v2 )
return 0LL;
if ( (unsigned int)isByReference(a1) )
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 8LL) = 1;
return v2;
}

original_code:
Symbol *
paramToVar(Symbol *param)
{
 Symbol *s = ((void *)0);
 if (!param) return ((void *)0);
 Symbol *typeSym = getTypeSym(param);
 s = newVariableSym(param->name, typeSym);
 if (!s) return ((void *)0);
 if (isByReference(param)) s->kindPtr.VarKind->byRef = 1;
 return s;
}

canonical_original_code:
struct Symbol *paramToVar(struct Symbol *param)
{
 struct Symbol *s = ((void *)0);
 if (!param) return ((void *)0);
 struct Symbol *typeSym = getTypeSym(param);
 s = newVariableSym(param->name, typeSym);
 if (!s) return ((void *)0);
 if (isByReference(param)) s->kindPtr.VarKind->byRef = 1;
 return s;
}

variable_types:
param
struct Symbol *

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

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

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

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

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

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


isElementArraySimple

decompiled_code:
__int64 __fastcall isElementArraySimple(__int64 a1)
{
unsigned int v2; // ebx
int v3; // eax
__int64 v4; // rdi

if ( !*(_DWORD *)(a1 + 12) )
return 1LL;
v2 = 0;
do
{
v4 = getElementAt(a1, v2);
if ( *(_DWORD *)(v4 + 8) != 4 )
return 0LL;
v3 = getType(v4);
if ( (unsigned int)(v3 - 2) > 3 && v3 != 9 )
return 0LL;
++v2;
}
while ( *(_DWORD *)(a1 + 12) > v2 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v2; // ebx
int v3; // eax
__int64 v4; // rdi

if ( !*(_DWORD *)(a1 + 12) )
return 1LL;
v2 = 0;
do
{
v4 = getElementAt(a1, v2);
if ( *(_DWORD *)(v4 + 8) != 4 )
return 0LL;
v3 = getType(v4);
if ( (unsigned int)(v3 - 2) > 3 && v3 != 9 )
return 0LL;
++v2;
}
while ( *(_DWORD *)(a1 + 12) > v2 );
return 1LL;
}

original_code:
int isElementArraySimple(struct ElementArray *elementArray) {
 struct Symbol *symbol;
 type_t symbolsType;
 for (int i = 0; i < elementArray->nElements; ++i) {
  symbol = (struct Symbol *) getElementAt(elementArray, i);
  if ( symbol->kind != TYPE_KIND ) {
   return 0;
  }
  symbolsType = getType(symbol);
  if ( symbolsType != BOOLEAN_T
   && symbolsType != CHAR_T
   && symbolsType != INTEGER_T
   && symbolsType != REAL_T
   && symbolsType != STRING_T ) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int isElementArraySimple(struct ElementArray *elementArray) {
 struct Symbol *symbol;
 enum type_t symbolsType;
 for (int i = 0; i < elementArray->nElements; ++i) {
  symbol = (struct Symbol *) getElementAt(elementArray, i);
  if ( symbol->kind != TYPE_KIND ) {
   return 0;
  }
  symbolsType = getType(symbol);
  if ( symbolsType != BOOLEAN_T
   && symbolsType != CHAR_T
   && symbolsType != INTEGER_T
   && symbolsType != REAL_T
   && symbolsType != STRING_T ) {
   return 0;
  }
 }
 return 1;
}

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

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

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

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

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

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

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


isArgTypeValidInIOFunc

decompiled_code:
__int64 __fastcall isArgTypeValidInIOFunc(const char **a1, __int64 a2)
{
const char *v2; // r12
int v3; // eax
int v4; // er13
int v5; // ebp
__int64 result; // rax
__int64 v7; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = *a1;
v3 = getType(a2);
v4 = *(_DWORD *)(a2 + 8);
v5 = v3;
if ( v3 == 1 )
{
v7 = getArrayBaseSym(a2);
if ( (unsigned int)getType(v7) == 3 )
v5 = 3;
}
if ( !strcmp(v2, "read") || !strcmp(v2, "readln") )
{
if ( v4 == 4 )
return *(_DWORD *)(a2 + 40) != 0;
if ( v4 )
return v5 == 9 || (unsigned int)(v5 - 3) <= 2;
return 0LL;
}
if ( !strcmp(v2, "writeln") )
return v5 == 9 || (unsigned int)(v5 - 3) <= 2;
result = 1LL;
if ( !strcmp(v2, "write") )
return v5 == 9 || (unsigned int)(v5 - 3) <= 2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char **a1, __int64 a2)
{
const char *v2; // r12
int v3; // eax
int v4; // er13
int v5; // ebp
__int64 result; // rax
__int64 v7; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = *a1;
v3 = getType(a2);
v4 = *(_DWORD *)(a2 + 8);
v5 = v3;
if ( v3 == 1 )
{
v7 = getArrayBaseSym(a2);
if ( (unsigned int)getType(v7) == 3 )
v5 = 3;
}
if ( !strcmp(v2, "read") || !strcmp(v2, "readln") )
{
if ( v4 == 4 )
return *(_DWORD *)(a2 + 40) != 0;
if ( v4 )
return v5 == 9 || (unsigned int)(v5 - 3) <= 2;
return 0LL;
}
if ( !strcmp(v2, "writeln") )
return v5 == 9 || (unsigned int)(v5 - 3) <= 2;
result = 1LL;
if ( !strcmp(v2, "write") )
return v5 == 9 || (unsigned int)(v5 - 3) <= 2;
return result;
}

original_code:
int isArgTypeValidInIOFunc(Symbol *s, Symbol *arg) {
 char *name = ((void *)0);
 type_t type;
 type_t arrayBaseType;
 kind_t kind;
 if(!s || !arg) return 0;
 name = s->name;
 type = getType(arg);
 kind = arg->kind;
 if (type == ARRAY_T) {
   arrayBaseType = getType(getArrayBaseSym(arg));
   if (arrayBaseType == CHAR_T) {
    type = arrayBaseType;
   }
 }
 if ((strcmp(name, "read") == 0) ||
  (strcmp(name, "readln") == 0)
 ) {
  if (kind == TYPE_KIND) {
   if (!(arg->isAddress)) {
    return 0;
   }
  } else if (kind == CONST_KIND) {
    return 0;
  } else if ((type != CHAR_T) && (type != INTEGER_T) &&
     (type != REAL_T) && (type != STRING_T) )
       {
   return 0;
  }
 } else if ((strcmp(name, "writeln") == 0) ||
            (strcmp(name, "write") == 0 )
 ) {
  if( (type != CHAR_T) && (type != INTEGER_T) &&
      (type != REAL_T) && (type != STRING_T) ) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int isArgTypeValidInIOFunc(struct Symbol *s, struct Symbol *arg) {
 char *name = ((void *)0);
 enum type_t type;
 enum type_t arrayBaseType;
 enum kind_t kind;
 if(!s || !arg) return 0;
 name = s->name;
 type = getType(arg);
 kind = arg->kind;
 if (type == ARRAY_T) {
   arrayBaseType = getType(getArrayBaseSym(arg));
   if (arrayBaseType == CHAR_T) {
    type = arrayBaseType;
   }
 }
 if ((strcmp(name, "read") == 0) ||
  (strcmp(name, "readln") == 0)
 ) {
  if (kind == TYPE_KIND) {
   if (!(arg->isAddress)) {
    return 0;
   }
  } else if (kind == CONST_KIND) {
    return 0;
  } else if ((type != CHAR_T) && (type != INTEGER_T) &&
     (type != REAL_T) && (type != STRING_T) )
       {
   return 0;
  }
 } else if ((strcmp(name, "writeln") == 0) ||
            (strcmp(name, "write") == 0 )
 ) {
  if( (type != CHAR_T) && (type != INTEGER_T) &&
      (type != REAL_T) && (type != STRING_T) ) {
   return 0;
  }
 }
 return 1;
}

variable_types:
arg
struct Symbol *

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


isValidIOProcInvocation

decompiled_code:
__int64 __fastcall isValidIOProcInvocation(const char **a1, __int64 a2)
{
int v2; // er14
unsigned int v3; // ebx
__int64 v4; // r15
unsigned int v5; // ebp
const char *v6; // r15
const char *v7; // rax
__int64 v8; // rax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

v2 = *(_DWORD *)(a2 + 12);
if ( v2 <= 0 )
return 1;
v10 = 1;
v3 = 0;
do
{
while ( 1 )
{
v4 = *(_QWORD *)getElementAt(a2, v3);
v5 = getType(v4);
if ( !(unsigned int)isArgTypeValidInIOFunc(a1, v4) )
break;
if ( v2 == ++v3 )
return v10;
}
v6 = *a1;
++v3;
v7 = (const char *)typeToString(v5);
v8 = customErrorString("Invalid argument of type %s passed to procedure %s.", v7, v6);
recordError(v8, yylineno, colno, 2LL);
v10 = 0;
}
while ( v2 != v3 );
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char **a1, __int64 a2)
{
int v2; // er14
unsigned int v3; // ebx
__int64 v4; // r15
unsigned int v5; // ebp
const char *v6; // r15
const char *v7; // rax
__int64 v8; // rax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

v2 = *(_DWORD *)(a2 + 12);
if ( v2 <= 0 )
return 1;
v10 = 1;
v3 = 0;
do
{
while ( 1 )
{
v4 = *(_QWORD *)getElementAt(a2, v3);
v5 = getType(v4);
if ( !(unsigned int)func7(a1, v4) )
break;
if ( v2 == ++v3 )
return v10;
}
v6 = *a1;
++v3;
v7 = (const char *)typeToString(v5);
v8 = customErrorString("Invalid argument of type %s passed to procedure %s.", v7, v6);
recordError(v8, yylineno, colno, 2LL);
v10 = 0;
}
while ( v2 != v3 );
return v10;
}

original_code:
int
isValidIOProcInvocation(Symbol *s, struct ElementArray *ea)
{
 Symbol *param = ((void *)0);
 type_t type;
 int i, nArgs, valid = 1;
 nArgs = ea->nElements;
 for (i = 0; i < nArgs; i++) {
  param = ((struct treeNode *)getElementAt(ea, i))->symbol;
  type = getType(param);
  if (!isArgTypeValidInIOFunc(s, param)) {
   errMsg = customErrorString("Invalid argument "
       "of type %s passed to procedure %s.",
       typeToString(type), s->name);
   recordError(errMsg, yylineno, colno, SEMANTIC);
   valid = 0;
  }
 }
 if (!valid) return 0;
 return 1;
}

canonical_original_code:
int isValidIOProcInvocation(struct Symbol *s, struct ElementArray *ea)
{
 struct Symbol *param = ((void *)0);
 enum type_t type;
 int i; int nArgs; int valid = 1;
 nArgs = ea->nElements;
 for (i = 0; i < nArgs; i++) {
  param = ((struct treeNode *)getElementAt(ea, i))->symbol;
  type = getType(param);
  if (!isArgTypeValidInIOFunc(s, param)) {
   errMsg = customErrorString("Invalid argument "
       "of type %s passed to procedure %s.",
       typeToString(type), s->name);
   recordError(errMsg, yylineno, colno, SEMANTIC);
   valid = 0;
  }
 }
 if (!valid) return 0;
 return 1;
}

variable_types: nArgs int

variable_types: valid 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 treeNode { struct Symbol *symbol; int opToken; struct treeNode *parent; struct treeNode *left; struct treeNode *right; }

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

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

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

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

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

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


isArgTypeValidInPreDefFunc

decompiled_code:
__int64 __fastcall isArgTypeValidInPreDefFunc(__int64 *a1, __int64 a2)
{
__int64 v2; // r13
unsigned int v3; // er12
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = *a1;
v3 = getType(a2);
if ( !strcmp((const char *)v2, "abs")
|| !strcmp((const char *)v2, "sqr")
|| !strcmp((const char *)v2, "sin")
|| !strcmp((const char *)v2, "exp")
|| *(_BYTE *)v2 == 108 && *(_BYTE *)(v2 + 1) == 110 && !*(_BYTE *)(v2 + 2)
|| !strcmp((const char *)v2, "sqrt")
|| !strcmp((const char *)v2, "trunc")
|| !strcmp((const char *)v2, "round") )
{
return v3 - 4 <= 1;
}
if ( !strcmp((const char *)v2, "chr") || !strcmp((const char *)v2, "odd") )
return v3 == 4;
if ( strcmp((const char *)v2, "ord") && strcmp((const char *)v2, "succ") && strcmp((const char *)v2, "pred") )
return 0LL;
if ( (unsigned int)isScalarMember(a2) || (unsigned int)isScalarVar(a2) )
result = 1LL;
else
result = (unsigned int)isOrdinal(v3) != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, __int64 a2)
{
__int64 v2; // r13
unsigned int v3; // er12
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = *a1;
v3 = getType(a2);
if ( !strcmp((const char *)v2, "abs")
|| !strcmp((const char *)v2, "sqr")
|| !strcmp((const char *)v2, "sin")
|| !strcmp((const char *)v2, "exp")
|| *(_BYTE *)v2 == 108 && *(_BYTE *)(v2 + 1) == 110 && !*(_BYTE *)(v2 + 2)
|| !strcmp((const char *)v2, "sqrt")
|| !strcmp((const char *)v2, "trunc")
|| !strcmp((const char *)v2, "round") )
{
return v3 - 4 <= 1;
}
if ( !strcmp((const char *)v2, "chr") || !strcmp((const char *)v2, "odd") )
return v3 == 4;
if ( strcmp((const char *)v2, "ord") && strcmp((const char *)v2, "succ") && strcmp((const char *)v2, "pred") )
return 0LL;
if ( (unsigned int)isScalarMember(a2) || (unsigned int)isScalarVar(a2) )
result = 1LL;
else
result = (unsigned int)isOrdinal(v3) != 0;
return result;
}

original_code:
int isArgTypeValidInPreDefFunc(Symbol *s, Symbol *arg) {
 char *name = ((void *)0);
 type_t type;
 if (!s || !arg) return 0;
 name = s->name;
 type = getType(arg);
 if (
     (strcmp(name, "abs") == 0) ||
     (strcmp(name, "sqr") == 0) ||
     (strcmp(name, "sin") == 0) ||
     (strcmp(name, "exp") == 0) ||
     (strcmp(name, "ln") == 0) ||
     (strcmp(name, "sqrt") == 0)
 ) {
  if ((type == INTEGER_T) || (type == REAL_T)) {
   return 1;
  }
 } else if (
     (strcmp(name, "trunc") == 0) ||
     (strcmp(name, "round") == 0)
 ){
  if (type == REAL_T || type == INTEGER_T) return 1;
 } else if (
     (strcmp(name, "chr") == 0) ||
     (strcmp(name, "odd") == 0)
 ){
  if (type == INTEGER_T) return 1;
 } else if (
     (strcmp(name, "ord") == 0) ||
     (strcmp(name, "succ") == 0) ||
     (strcmp(name, "pred") == 0)
 ){
  if (isScalarMember(arg)) return 1;
  if (isScalarVar(arg)) return 1;
  if (isOrdinal(type)) return 1;
 }
 return 0;
}

canonical_original_code:
int isArgTypeValidInPreDefFunc(struct Symbol *s, struct Symbol *arg) {
 char *name = ((void *)0);
 enum type_t type;
 if (!s || !arg) return 0;
 name = s->name;
 type = getType(arg);
 if (
     (strcmp(name, "abs") == 0) ||
     (strcmp(name, "sqr") == 0) ||
     (strcmp(name, "sin") == 0) ||
     (strcmp(name, "exp") == 0) ||
     (strcmp(name, "ln") == 0) ||
     (strcmp(name, "sqrt") == 0)
 ) {
  if ((type == INTEGER_T) || (type == REAL_T)) {
   return 1;
  }
 } else if (
     (strcmp(name, "trunc") == 0) ||
     (strcmp(name, "round") == 0)
 ){
  if (type == REAL_T || type == INTEGER_T) return 1;
 } else if (
     (strcmp(name, "chr") == 0) ||
     (strcmp(name, "odd") == 0)
 ){
  if (type == INTEGER_T) return 1;
 } else if (
     (strcmp(name, "ord") == 0) ||
     (strcmp(name, "succ") == 0) ||
     (strcmp(name, "pred") == 0)
 ){
  if (isScalarMember(arg)) return 1;
  if (isScalarVar(arg)) return 1;
  if (isOrdinal(type)) return 1;
 }
 return 0;
}

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

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

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

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

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

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

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

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


isValidPreDefFuncInvocation

decompiled_code:
__int64 __fastcall isValidPreDefFuncInvocation(const char **a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rdx
__int64 v7; // rax
unsigned int v8; // eax
const char *v9; // rax

v2 = *(unsigned int *)(a2 + 12);
if ( (_DWORD)v2 == 1 )
{
v3 = *(_QWORD *)getElementAt(a2, 0LL);
v4 = getTypeSym(v3);
if ( (unsigned int)isArgTypeValidInPreDefFunc((__int64 *)a1, v3) )
return getPreDefFuncReturnType(a1, v4, v5);
v8 = getType(v4);
v9 = (const char *)typeToString(v8);
v7 = customErrorString("Function %s cannot be called with argument of type %s.", *a1, v9);
}
else
{
v7 = customErrorString("Function %s expected 1 argument but %d given.", *a1, v2);
}
recordError(v7, yylineno, colno, 2LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char **a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rdx
__int64 v7; // rax
unsigned int v8; // eax
const char *v9; // rax

v2 = *(unsigned int *)(a2 + 12);
if ( (_DWORD)v2 == 1 )
{
v3 = *(_QWORD *)getElementAt(a2, 0LL);
v4 = getTypeSym(v3);
if ( (unsigned int)func9((__int64 *)a1, v3) )
return func4(a1, v4, v5);
v8 = getType(v4);
v9 = (const char *)typeToString(v8);
v7 = customErrorString("Function %s cannot be called with argument of type %s.", *a1, v9);
}
else
{
v7 = customErrorString("Function %s expected 1 argument but %d given.", *a1, v2);
}
recordError(v7, yylineno, colno, 2LL);
return 0LL;
}

original_code:
ProxySymbol *isValidPreDefFuncInvocation(Symbol *s, struct ElementArray *ea)
{
 Symbol *param = ((void *)0);
 Symbol * type;
 int i = 0;
 int nArgs = 0;
 nArgs = ea->nElements;
 if (nArgs != 1) {
  errMsg = customErrorString("Function %s expected "
      "1 argument but %d given.", s->name, nArgs);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 param = ((struct treeNode *)getElementAt(ea, i))->symbol;
 type = getTypeSym(param);
 if (isArgTypeValidInPreDefFunc(s, param)) {
  return getPreDefFuncReturnType(s, type);
 } else {
  errMsg = customErrorString("Function %s cannot be "
      "called with argument of type %s.", s->name,
      typeToString(getType(type)));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
}

canonical_original_code:
struct Symbol *isValidPreDefFuncInvocation(struct Symbol *s, struct ElementArray *ea)
{
 struct Symbol *param = ((void *)0);
 struct Symbol *type;
 int i = 0;
 int nArgs = 0;
 nArgs = ea->nElements;
 if (nArgs != 1) {
  errMsg = customErrorString("Function %s expected "
      "1 argument but %d given.", s->name, nArgs);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
 param = ((struct treeNode *)getElementAt(ea, i))->symbol;
 type = getTypeSym(param);
 if (isArgTypeValidInPreDefFunc(s, param)) {
  return getPreDefFuncReturnType(s, type);
 } else {
  errMsg = customErrorString("Function %s cannot be "
      "called with argument of type %s.", s->name,
      typeToString(getType(type)));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return 0;
 }
}

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


getArrayIndexSym

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

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

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

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

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

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

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


getArrayDim

decompiled_code:
__int64 __fastcall getArrayDim(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdi
unsigned int v3; // er12

v1 = getArrayIndexSym(a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = 0;
do
{
++v3;
v2 = getArrayIndexSym(v2);
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdi
unsigned int v3; // er12

v1 = func0(a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = 0;
do
{
++v3;
v2 = func0(v2);
}
while ( v2 );
return v3;
}

original_code:
int getArrayDim(Symbol *s)
{
 Symbol *nextIndexSym = ((void *)0);
 int dim = 0;
 nextIndexSym = getArrayIndexSym(s);
 while (nextIndexSym != ((void *)0)) {
  dim++;
  nextIndexSym = getArrayIndexSym(nextIndexSym);
 }
 return dim;
}

canonical_original_code:
int getArrayDim(struct Symbol *s)
{
 struct Symbol *nextIndexSym = ((void *)0);
 int dim = 0;
 nextIndexSym = getArrayIndexSym(s);
 while (nextIndexSym != ((void *)0)) {
  dim++;
  nextIndexSym = getArrayIndexSym(nextIndexSym);
 }
 return dim;
}

variable_types: dim 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 VariableKind { struct Symbol *typeSym; int byRef; }

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

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

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

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

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

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