newProcSym

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

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

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

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

original_code:
Symbol *newProcSym(char *id, struct ElementArray *ea) {
 Symbol *s = createProcSymbol(id);
 s->kindPtr.ProcKind->params = ea;
 return s;
}

canonical_original_code:
struct Symbol *newProcSym(char *id, struct ElementArray *ea) {
 struct Symbol *s = createProcSymbol(id);
 s->kindPtr.ProcKind->params = ea;
 return s;
}

variable_types:
ea
struct ElementArray *

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

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

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

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

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

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

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

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


newFuncSym

repo: a-krebs/YACC

decompiled_code:
__int64 __fastcall newFuncSym(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbx

v6 = createFuncSymbol(a2);
*(_QWORD *)(*(_QWORD *)(v6 + 16) + 8LL) = a4;
setInnerTypeSymbol(v6, a3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbx

v6 = createFuncSymbol(a2);
*(_QWORD *)(*(_QWORD *)(v6 + 16) + 8LL) = a4;
setInnerTypeSymbol(v6, a3);
return v6;
}

original_code:
Symbol *newFuncSym(
    int lvl, char *id, Symbol *typeSym, struct ElementArray *ea)
{
 Symbol *s = createFuncSymbol(id);
 s->kindPtr.FuncKind->params = ea;
 setInnerTypeSymbol(s, typeSym);
 return s;
}

canonical_original_code:
struct Symbol *newFuncSym(int lvl, char *id, struct Symbol *typeSym, struct ElementArray *ea)
{
 struct Symbol *s = createFuncSymbol(id);
 s->kindPtr.FuncKind->params = ea;
 setInnerTypeSymbol(s, typeSym);
 return s;
}

variable_types: lvl int

variable_types:
id
char *

variable_types:
typeSym
struct Symbol *

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

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

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

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


newRecordTypeSym

decompiled_code:
__int64 __fastcall newRecordTypeSym(__int64 a1)
{
__int64 v1; // rbx
_QWORD *v2; // rbp

v1 = createTypeSymbol(a1, 1LL);
*(_DWORD *)(*(_QWORD *)(v1 + 16) + 8LL) = 6;
v2 = *(_QWORD **)(v1 + 16);
*v2 = newRecord();
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbx
_QWORD *v2; // rbp

v1 = createTypeSymbol(a1, 1LL);
*(_DWORD *)(*(_QWORD *)(v1 + 16) + 8LL) = 6;
v2 = *(_QWORD **)(v1 + 16);
*v2 = newRecord();
return v1;
}

original_code:
Symbol *newRecordTypeSym(char *id) {
 Symbol *newRecType = createTypeSymbol(id, 1);
 newRecType->kindPtr.TypeKind->type = RECORD_T;
 newRecType->kindPtr.TypeKind->typePtr.Record = newRecord();
 return newRecType;
}

canonical_original_code:
struct Symbol *newRecordTypeSym(char *id) {
 struct Symbol *newRecType = createTypeSymbol(id, 1);
 newRecType->kindPtr.TypeKind->type = RECORD_T;
 newRecType->kindPtr.TypeKind->typePtr.Record = newRecord();
 return newRecType;
}

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


newSubrangeSym

decompiled_code:
__int64 __fastcall newSubrangeSym(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // er13
unsigned int v4; // eax
unsigned int v5; // eax
unsigned __int8 v6; // r12
int v7; // er12
_QWORD *v8; // r13
int v9; // er12
int v10; // er12

if ( !a1 || !a2 )
return 0LL;
if ( *(_DWORD *)(a1 + 8) )
return 0LL;
v2 = 0LL;
if ( !*(_DWORD *)(a2 + 8) )
{
v3 = ((__int64 (*)(void))getType)();
if ( v3 == (unsigned int)getType(a2) )
{
v4 = getType(a1);
if ( (unsigned int)isOrdinal(v4) )
{
v5 = getType(a1);
if ( v5 == 4 )
{
v9 = *(_DWORD *)getConstVal(a1);
if ( v9 > *(_DWORD *)getConstVal(a2) )
return 0LL;
}
else if ( v5 > 4 )
{
if ( v5 == 8 )
{
v7 = *(_DWORD *)getConstVal(a1);
if ( v7 > *(_DWORD *)getConstVal(a2) )
return 0LL;
}
}
else if ( v5 == 2 )
{
v10 = *(_DWORD *)getConstVal(a1);
if ( v10 > *(_DWORD *)getConstVal(a2) )
return 0LL;
}
else if ( v5 == 3 )
{
v6 = *(_BYTE *)getConstVal(a1);
if ( v6 > *(_BYTE *)getConstVal(a2) )
return 0LL;
}
v2 = createTypeSymbol(0LL, 1LL);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 8LL) = 10;
v8 = *(_QWORD **)(v2 + 16);
*v8 = newSubrange(a1, a2);
return v2;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // er13
unsigned int v4; // eax
unsigned int v5; // eax
unsigned __int8 v6; // r12
int v7; // er12
_QWORD *v8; // r13
int v9; // er12
int v10; // er12

if ( !a1 || !a2 )
return 0LL;
if ( *(_DWORD *)(a1 + 8) )
return 0LL;
v2 = 0LL;
if ( !*(_DWORD *)(a2 + 8) )
{
v3 = ((__int64 (*)(void))getType)();
if ( v3 == (unsigned int)getType(a2) )
{
v4 = getType(a1);
if ( (unsigned int)isOrdinal(v4) )
{
v5 = getType(a1);
if ( v5 == 4 )
{
v9 = *(_DWORD *)getConstVal(a1);
if ( v9 > *(_DWORD *)getConstVal(a2) )
return 0LL;
}
else if ( v5 > 4 )
{
if ( v5 == 8 )
{
v7 = *(_DWORD *)getConstVal(a1);
if ( v7 > *(_DWORD *)getConstVal(a2) )
return 0LL;
}
}
else if ( v5 == 2 )
{
v10 = *(_DWORD *)getConstVal(a1);
if ( v10 > *(_DWORD *)getConstVal(a2) )
return 0LL;
}
else if ( v5 == 3 )
{
v6 = *(_BYTE *)getConstVal(a1);
if ( v6 > *(_BYTE *)getConstVal(a2) )
return 0LL;
}
v2 = createTypeSymbol(0LL, 1LL);
*(_DWORD *)(*(_QWORD *)(v2 + 16) + 8LL) = 10;
v8 = *(_QWORD **)(v2 + 16);
*v8 = newSubrange(a1, a2);
return v2;
}
}
}
return v2;
}

original_code:
Symbol *newSubrangeSym(ProxySymbol *constSymLow, ProxySymbol *constSymHigh) {
 Symbol *newSubrangeSym = ((void *)0);
 if ((!constSymLow) || (!constSymHigh)) {
  return ((void *)0);
 }
 if ((constSymLow->kind != CONST_KIND) ||
     (constSymHigh->kind != CONST_KIND)) {
  return ((void *)0);
 }
 if (getType(constSymLow) != getType(constSymHigh)) {
  return ((void *)0);
 }
 if (!isOrdinal(getType(constSymLow))) {
  return ((void *)0);
 }
 switch(getType(constSymLow)) {
 case SCALAR_T:
  if (getConstVal(constSymLow)->Integer.value >
      getConstVal(constSymHigh)->Integer.value) return ((void *)0);
  break;
 case INTEGER_T:
  if (getConstVal(constSymLow)->Integer.value >
      getConstVal(constSymHigh)->Integer.value) return ((void *)0);
  break;
 case BOOLEAN_T:
  if (getConstVal(constSymLow)->Boolean.value >
      getConstVal(constSymHigh)->Boolean.value) return ((void *)0);
  break;
 case CHAR_T:
  if (getConstVal(constSymLow)->Char.value >
      getConstVal(constSymHigh)->Char.value) return ((void *)0);
  break;
 default:
  break;
 }
 newSubrangeSym = createTypeSymbol(((void *)0), 1);
 newSubrangeSym->kindPtr.TypeKind->type = SUBRANGE_T;
 newSubrangeSym->kindPtr.TypeKind->typePtr.Subrange = newSubrange(
          constSymLow,
          constSymHigh);
 return newSubrangeSym;
}

canonical_original_code:
struct Symbol *newSubrangeSym(struct Symbol *constSymLow, struct Symbol *constSymHigh) {
 struct Symbol *newSubrangeSym = ((void *)0);
 if ((!constSymLow) || (!constSymHigh)) {
  return ((void *)0);
 }
 if ((constSymLow->kind != CONST_KIND) ||
     (constSymHigh->kind != CONST_KIND)) {
  return ((void *)0);
 }
 if (getType(constSymLow) != getType(constSymHigh)) {
  return ((void *)0);
 }
 if (!isOrdinal(getType(constSymLow))) {
  return ((void *)0);
 }
 switch(getType(constSymLow)) {
 case SCALAR_T:
  if (getConstVal(constSymLow)->Integer.value >
      getConstVal(constSymHigh)->Integer.value) return ((void *)0);
  break;
 case INTEGER_T:
  if (getConstVal(constSymLow)->Integer.value >
      getConstVal(constSymHigh)->Integer.value) return ((void *)0);
  break;
 case BOOLEAN_T:
  if (getConstVal(constSymLow)->Boolean.value >
      getConstVal(constSymHigh)->Boolean.value) return ((void *)0);
  break;
 case CHAR_T:
  if (getConstVal(constSymLow)->Char.value >
      getConstVal(constSymHigh)->Char.value) return ((void *)0);
  break;
 default:
  break;
 }
 newSubrangeSym = createTypeSymbol(((void *)0), 1);
 newSubrangeSym->kindPtr.TypeKind->type = SUBRANGE_T;
 newSubrangeSym->kindPtr.TypeKind->typePtr.Subrange = newSubrange(
          constSymLow,
          constSymHigh);
 return newSubrangeSym;
}

variable_types:
constSymLow
struct Symbol *

variable_types:
constSymHigh
struct Symbol *

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

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

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

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

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

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


newTypeSymFromSym

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

if ( !a2 )
return 0LL;
if ( *(_DWORD *)(a2 + 8) == 4 )
{
if ( !a1 )
err(1, "Trying to create named type symbol but name is NULL.");
v2 = createTypeSymbol(a1, 0LL);
*(_QWORD *)(v2 + 16) = *(_QWORD *)(a2 + 16);
if ( (unsigned int)getType(v2) == 6 )
*(_DWORD *)(v2 + 36) = *(_DWORD *)(a2 + 36);
}
else
{
v4 = customErrorString("Identifier %s is not a type.", *(const char **)a2);
recordError(v4, yylineno, colno, 2LL);
v2 = 0LL;
}
return v2;
}

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

if ( !a2 )
return 0LL;
if ( *(_DWORD *)(a2 + 8) == 4 )
{
if ( !a1 )
err(1, "Trying to create named type symbol but name is NULL.");
v2 = createTypeSymbol(a1, 0LL);
*(_QWORD *)(v2 + 16) = *(_QWORD *)(a2 + 16);
if ( (unsigned int)getType(v2) == 6 )
*(_DWORD *)(v2 + 36) = *(_DWORD *)(a2 + 36);
}
else
{
v4 = customErrorString("Identifier %s is not a type.", *(const char **)a2);
recordError(v4, yylineno, colno, 2LL);
v2 = 0LL;
}
return v2;
}

original_code:
Symbol *newTypeSymFromSym(char *id, Symbol *typeSym) {
 Symbol *newTypeSym = ((void *)0);
 if (!typeSym) {
  return ((void *)0);
 }
 if (typeSym->kind != TYPE_KIND) {
  errMsg = customErrorString("Identifier %s is not a type.",
      typeSym->name);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (!id) {
  err(1, "Trying to create named type symbol "
      "but name is NULL.");
 }
 newTypeSym = createTypeSymbol(id, 0);
 newTypeSym->kindPtr = typeSym->kindPtr;
 if (getType(newTypeSym) == RECORD_T) {
  newTypeSym->size = typeSym->size;
 }
 return newTypeSym;
}

canonical_original_code:
struct Symbol *newTypeSymFromSym(char *id, struct Symbol *typeSym) {
 struct Symbol *newTypeSym = ((void *)0);
 if (!typeSym) {
  return ((void *)0);
 }
 if (typeSym->kind != TYPE_KIND) {
  errMsg = customErrorString("Identifier %s is not a type.",
      typeSym->name);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (!id) {
  err(1, "Trying to create named type symbol "
      "but name is NULL.");
 }
 newTypeSym = createTypeSymbol(id, 0);
 newTypeSym->kindPtr = typeSym->kindPtr;
 if (getType(newTypeSym) == RECORD_T) {
  newTypeSym->size = typeSym->size;
 }
 return newTypeSym;
}

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

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

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

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

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

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

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

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


makeArrayIndexSym

decompiled_code:
__int64 __fastcall makeArrayIndexSym(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // rbx
int v12; // [rsp+8h] [rbp-20h] BYREF
int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1;
v2 = getType(a1);
if ( v2 == 2 )
{
v13[0] = 0;
v4 = getTypeSym(a1);
v5 = newConstProxySym(0LL, v13, v4);
v12 = 1;
v6 = getTypeSym(a1);
v7 = newConstProxySym(0LL, &v12, v6);
v1 = newSubrangeSym(v5, v7);
}
else if ( v2 == 3 )
{
v13[0] = 0;
v8 = getTypeSym(a1);
v9 = newConstProxySym(0LL, v13, v8);
v12 = 255;
v10 = getTypeSym(a1);
v11 = newConstProxySym(0LL, &v12, v10);
*(_BYTE *)getConstVal(v11) = -1;
v1 = newSubrangeSym(v9, v11);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // rbx
int v12; // [rsp+8h] [rbp-20h] BYREF
int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = a1;
v2 = getType(a1);
if ( v2 == 2 )
{
v13[0] = 0;
v4 = getTypeSym(a1);
v5 = newConstProxySym(0LL, v13, v4);
v12 = 1;
v6 = getTypeSym(a1);
v7 = newConstProxySym(0LL, &v12, v6);
v1 = func7(v5, v7);
}
else if ( v2 == 3 )
{
v13[0] = 0;
v8 = getTypeSym(a1);
v9 = newConstProxySym(0LL, v13, v8);
v12 = 255;
v10 = getTypeSym(a1);
v11 = newConstProxySym(0LL, &v12, v10);
*(_BYTE *)getConstVal(v11) = -1;
v1 = func7(v9, v11);
}
return v1;
}

original_code:
Symbol *makeArrayIndexSym(Symbol *indexTypeSym)
{
 Symbol *lowSym, *highSym;
 int low, high;
 switch (getType(indexTypeSym)) {
 case BOOLEAN_T:
  low = 0;
  lowSym = newConstProxySym(((void *)0), &low,
      getTypeSym(indexTypeSym));
  high = 1;
  highSym = newConstProxySym(((void *)0), &high,
      getTypeSym(indexTypeSym));
  return newSubrangeSym(lowSym, highSym);
 case CHAR_T:
  low = 0;
  lowSym = newConstProxySym(((void *)0), &low,
      getTypeSym(indexTypeSym));
  high = 255;
  highSym = newConstProxySym(((void *)0), &high,
      getTypeSym(indexTypeSym));
  getConstVal(highSym)->Char.value = '\xff';
  return newSubrangeSym(lowSym, highSym);
 default:
  return indexTypeSym;
 }
 return ((void *)0);
}

canonical_original_code:
struct Symbol *makeArrayIndexSym(struct Symbol *indexTypeSym)
{
 struct Symbol *lowSym; struct Symbol *highSym;
 int low; int high;
 switch (getType(indexTypeSym)) {
 case BOOLEAN_T:
  low = 0;
  lowSym = newConstProxySym(((void *)0), &low,
      getTypeSym(indexTypeSym));
  high = 1;
  highSym = newConstProxySym(((void *)0), &high,
      getTypeSym(indexTypeSym));
  return newSubrangeSym(lowSym, highSym);
 case CHAR_T:
  low = 0;
  lowSym = newConstProxySym(((void *)0), &low,
      getTypeSym(indexTypeSym));
  high = 255;
  highSym = newConstProxySym(((void *)0), &high,
      getTypeSym(indexTypeSym));
  getConstVal(highSym)->Char.value = '\xff';
  return newSubrangeSym(lowSym, highSym);
 default:
  return indexTypeSym;
 }
 return ((void *)0);
}

variable_types:
indexTypeSym
struct Symbol *

variable_types: low int

variable_types: high int

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

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

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

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

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

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

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

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


newAnonArraySym

decompiled_code:
__int64 __fastcall newAnonArraySym(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned int v6; // eax
const char *v7; // rax
__int64 v8; // rax

if ( a1 && a2 )
{
if ( *(_DWORD *)(a1 + 8) == 4 )
{
if ( (unsigned int)getType(a2) == 8
|| (unsigned int)getType(a2) == 10
|| (unsigned int)getType(a2) == 2
|| (unsigned int)getType(a2) == 3 )
{
v2 = makeArrayIndexSym(a2);
result = createArrayTypeSymbol(0LL, 1LL, a1, v2);
if ( !result )
err(1, "Failed to allocate memory for new array!");
}
else
{
v6 = getType(a2);
v7 = (const char *)typeToString(v6);
v8 = customErrorString("Trying to index array using non-index type %s", v7);
recordError(v8, yylineno, colno, 2LL);
result = 0LL;
}
}
else
{
v5 = customErrorString("Cannot create array with given base type");
recordError(v5, yylineno, colno, 2LL);
result = 0LL;
}
}
else
{
v4 = customErrorString("Cannot define array. Base type or index type incorrect or undefined.");
recordError(v4, yylineno, colno, 2LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned int v6; // eax
const char *v7; // rax
__int64 v8; // rax

if ( a1 && a2 )
{
if ( *(_DWORD *)(a1 + 8) == 4 )
{
if ( (unsigned int)getType(a2) == 8
|| (unsigned int)getType(a2) == 10
|| (unsigned int)getType(a2) == 2
|| (unsigned int)getType(a2) == 3 )
{
v2 = func9(a2);
result = func0(0LL, 1LL, a1, v2);
if ( !result )
err(1, "Failed to allocate memory for new array!");
}
else
{
v6 = getType(a2);
v7 = (const char *)typeToString(v6);
v8 = customErrorString("Trying to index array using non-index type %s", v7);
recordError(v8, yylineno, colno, 2LL);
result = 0LL;
}
}
else
{
v5 = customErrorString("Cannot create array with given base type");
recordError(v5, yylineno, colno, 2LL);
result = 0LL;
}
}
else
{
v4 = customErrorString("Cannot define array. Base type or index type incorrect or undefined.");
recordError(v4, yylineno, colno, 2LL);
result = 0LL;
}
return result;
}

original_code:
Symbol *newAnonArraySym(Symbol *baseTypeSym, Symbol *indexTypeSym) {
 Symbol *newArraySym = ((void *)0), *index;
 if ((!baseTypeSym) || (!indexTypeSym)) {
  errMsg = customErrorString("Cannot define array. "
      "Base type or index type incorrect or undefined.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if ((baseTypeSym->kind != TYPE_KIND) ||
     (baseTypeSym->kind != TYPE_KIND)) {
  errMsg = customErrorString("Cannot create array with given "
      "base type");
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (((getType(indexTypeSym)) != SCALAR_T) &&
     ((getType(indexTypeSym)) != SUBRANGE_T) &&
     ((getType(indexTypeSym))!= BOOLEAN_T) &&
     ((getType(indexTypeSym)) != CHAR_T)) {
  errMsg = customErrorString("Trying to index array using non-"
      "index type %s", typeToString(getType(indexTypeSym)));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 index = makeArrayIndexSym(indexTypeSym);
 newArraySym = createArrayTypeSymbol(
      ((void *)0), 1, baseTypeSym, index);
 if (!newArraySym) {
  err(1, "Failed to allocate memory for new array!");
 }
 return newArraySym;
}

canonical_original_code:
struct Symbol *newAnonArraySym(struct Symbol *baseTypeSym, struct Symbol *indexTypeSym) {
 struct Symbol *newArraySym = ((void *)0); struct Symbol *index;
 if ((!baseTypeSym) || (!indexTypeSym)) {
  errMsg = customErrorString("Cannot define array. "
      "Base type or index type incorrect or undefined.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if ((baseTypeSym->kind != TYPE_KIND) ||
     (baseTypeSym->kind != TYPE_KIND)) {
  errMsg = customErrorString("Cannot create array with given "
      "base type");
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (((getType(indexTypeSym)) != SCALAR_T) &&
     ((getType(indexTypeSym)) != SUBRANGE_T) &&
     ((getType(indexTypeSym))!= BOOLEAN_T) &&
     ((getType(indexTypeSym)) != CHAR_T)) {
  errMsg = customErrorString("Trying to index array using non-"
      "index type %s", typeToString(getType(indexTypeSym)));
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 index = makeArrayIndexSym(indexTypeSym);
 newArraySym = createArrayTypeSymbol(
      ((void *)0), 1, baseTypeSym, index);
 if (!newArraySym) {
  err(1, "Failed to allocate memory for new array!");
 }
 return newArraySym;
}

variable_types:
baseTypeSym
struct Symbol *

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


newAnonScalarListTypeSym

decompiled_code:
__int64 __fastcall newAnonScalarListTypeSym(__int64 a1)
{
if ( !a1 )
err(1, "Trying to create anon scalar list with NULL list of scalars.");
return createScalarListTypeSymbol(0LL, 1LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( !a1 )
err(1, "Trying to create anon scalar list with NULL list of scalars.");
return func1(0LL, 1LL, a1);
}

original_code:
Symbol *newAnonScalarListTypeSym(struct ElementArray *ea) {
 Symbol *newAnonScalarList = ((void *)0);
 if (ea == ((void *)0)) {
  err(1, "Trying to create anon scalar list with "
      "NULL list of scalars.");
 }
 newAnonScalarList = createScalarListTypeSymbol(
     ((void *)0), 1, ea);
 return newAnonScalarList;
}

canonical_original_code:
struct Symbol *newAnonScalarListTypeSym(struct ElementArray *ea) {
 struct Symbol *newAnonScalarList = ((void *)0);
 if (ea == ((void *)0)) {
  err(1, "Trying to create anon scalar list with "
      "NULL list of scalars.");
 }
 newAnonScalarList = createScalarListTypeSymbol(
     ((void *)0), 1, ea);
 return newAnonScalarList;
}

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

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

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

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

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

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

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

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


newStringTypeSym

decompiled_code:
__int64 __fastcall newStringTypeSym(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp

v1 = createTypeSymbol(0LL, 1LL);
v2 = getKindPtrForTypeKind(v1);
*(_DWORD *)(v2 + 8) = 9;
*(_QWORD *)v2 = newStringType(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp

v1 = createTypeSymbol(0LL, 1LL);
v2 = getKindPtrForTypeKind(v1);
*(_DWORD *)(v2 + 8) = 9;
*(_QWORD *)v2 = newStringType(a1);
return v1;
}

original_code:
Symbol *newStringTypeSym(int strlen) {
 Symbol *newStringSym = createTypeSymbol(((void *)0), 1);
 struct TypeKind *kindPtr = getKindPtrForTypeKind(newStringSym);
 kindPtr->type = STRING_T;
 kindPtr->typePtr.String = newStringType(strlen);
 return newStringSym;
}

canonical_original_code:
struct Symbol *newStringTypeSym(int strlen) {
 struct Symbol *newStringSym = createTypeSymbol(((void *)0), 1);
 struct TypeKind *kindPtr = getKindPtrForTypeKind(newStringSym);
 kindPtr->type = STRING_T;
 kindPtr->typePtr.String = newStringType(strlen);
 return newStringSym;
}

variable_types: strlen int

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

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

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

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


isConstInScalar

decompiled_code:
_BOOL8 __fastcall isConstInScalar(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax
__int64 v3; // rax
__int64 v4; // rbp

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v3 = getTypeSym(a1);
v4 = getTypePtr(v3);
result = v4 == getTypePtr(a2);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax
__int64 v3; // rax
__int64 v4; // rbp

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v3 = getTypeSym(a1);
v4 = getTypePtr(v3);
result = v4 == getTypePtr(a2);
}
return result;
}

original_code:
int
isConstInScalar(Symbol *constSym, Symbol *scalarSymType)
{
 if (!(constSym) || !(scalarSymType)) return 0;
 if (getTypePtr(getTypeSym(constSym)) != getTypePtr(scalarSymType)) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int isConstInScalar(struct Symbol *constSym, struct Symbol *scalarSymType)
{
 if (!(constSym) || !(scalarSymType)) return 0;
 if (getTypePtr(getTypeSym(constSym)) != getTypePtr(scalarSymType)) {
  return 0;
 }
 return 1;
}

variable_types:
scalarSymType
struct Symbol *

return_type: int

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

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

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

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

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

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

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

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


setSymbolOffset

decompiled_code:
void __fastcall setSymbolOffset(__int64 a1, __int64 a2)
{
if ( a1 )
{
*(_DWORD *)(a1 + 32) = getOffset(a2);
addToOffset(a2, *(unsigned int *)(a1 + 36));
}
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2)
{
if ( a1 )
{
*(_DWORD *)(a1 + 32) = getOffset(a2);
addToOffset(a2, *(unsigned int *)(a1 + 36));
}
}

original_code:
void setSymbolOffset(Symbol *s, struct hash *table)
{
 if (!s) return;
 s->offset = getOffset(table);
 addToOffset(table, s->size);
}

canonical_original_code:
void setSymbolOffset(struct Symbol *s, struct hash *table)
{
 if (!s) return;
 s->offset = getOffset(table);
 addToOffset(table, s->size);
}

variable_types:
table
struct hash *

return_type: void

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

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

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

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


setParamOffset

decompiled_code:
__int64 __fastcall setParamOffset(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
int v3; // er13
__int64 v4; // rbx
__int64 result; // rax

if ( *(_DWORD *)(a2 + 12) )
{
v2 = 0;
v3 = 0;
do
{
v4 = getElementAt(a2, v2);
if ( (unsigned int)isByReference(v4) )
++v3;
else
v3 += *(_DWORD *)(v4 + 36);
if ( !strcmp(*(const char **)v4, *(const char **)a1) )
break;
++v2;
}
while ( *(_DWORD *)(a2 + 12) > v2 );
}
else
{
v3 = 0;
}
result = (unsigned int)(-2 - v3);
*(_DWORD *)(a1 + 32) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
int v3; // er13
__int64 v4; // rbx
__int64 result; // rax

if ( *(_DWORD *)(a2 + 12) )
{
v2 = 0;
v3 = 0;
do
{
v4 = getElementAt(a2, v2);
if ( (unsigned int)isByReference(v4) )
++v3;
else
v3 += *(_DWORD *)(v4 + 36);
if ( !strcmp(*(const char **)v4, *(const char **)a1) )
break;
++v2;
}
while ( *(_DWORD *)(a2 + 12) > v2 );
}
else
{
v3 = 0;
}
result = (unsigned int)(-2 - v3);
*(_DWORD *)(a1 + 32) = result;
return result;
}

original_code:
void setParamOffset(Symbol *s, struct ElementArray *params)
{
 Symbol *param = ((void *)0);
 int offset = 0, i;
 for (i = 0; i < params->nElements; i++) {
  param = getElementAt(params, i);
  if (isByReference(param)) offset += 1;
  else offset += param->size;
  if (strcmp(param->name, s->name) == 0) {
   break;
  }
 }
 offset += 2;
 offset *= -1;
 s->offset = offset;
}

canonical_original_code:
void setParamOffset(struct Symbol *s, struct ElementArray *params)
{
 struct Symbol *param = ((void *)0);
 int offset = 0; int i;
 for (i = 0; i < params->nElements; i++) {
  param = getElementAt(params, i);
  if (isByReference(param)) offset += 1;
  else offset += param->size;
  if (strcmp(param->name, s->name) == 0) {
   break;
  }
 }
 offset += 2;
 offset *= -1;
 s->offset = offset;
}

variable_types:
params
struct ElementArray *

variable_types: offset int

variable_types: i int

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

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

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

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

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

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

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

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


emitArithmeticPrep

decompiled_code:
void __fastcall emitArithmeticPrep(const char **a1, const char **a2, _DWORD *a3, int a4)
{
if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
if ( *((_DWORD *)a1 + 10) )
{
((void (*)(void))emitPushAddressValue)();
}
else if ( *((_DWORD *)a1 + 2) != 4 )
{
((void (*)(void))emitPushSymbolValue)();
}
if ( *((_DWORD *)a2 + 10) )
{
emitPushAddressValue(a2);
}
else if ( *((_DWORD *)a2 + 2) != 4 )
{
emitPushSymbolValue(a2);
}
if ( (unsigned int)getType(a1) == 4 && (unsigned int)getType(a2) == 4 )
{
if ( a4 == 298 )
{
emitComment("Converting %s to a real value.", *a1);
emitStmt(128LL, "ADJUST -1");
emitStmt(128LL, "ITOR");
emitStmt(128LL, "ADJUST 1");
emitComment("Converting %s to a real value.", *a2);
emitStmt(128LL, "ITOR");
*a3 = 1;
}
else
{
*a3 = 0;
}
}
else if ( (unsigned int)getType(a1) == 5 && (unsigned int)getType(a2) == 5 )
{
*a3 = 1;
}
else if ( (unsigned int)getType(a1) == 4 && (unsigned int)getType(a2) == 5 )
{
emitComment("Converting %s to a real value.", *a1);
emitStmt(128LL, "ADJUST -1");
emitStmt(128LL, "ITOR");
emitStmt(128LL, "ADJUST 1");
*a3 = 1;
}
else if ( (unsigned int)getType(a1) == 5 && (unsigned int)getType(a2) == 4 )
{
emitComment("Converting %s to a real value.", *a2);
emitStmt(128LL, "ITOR");
*a3 = 1;
}
}
else
{
doNotEmit = 1;
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func0(const char **a1, const char **a2, _DWORD *a3, int a4)
{
if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
if ( *((_DWORD *)a1 + 10) )
{
((void (*)(void))emitPushAddressValue)();
}
else if ( *((_DWORD *)a1 + 2) != 4 )
{
((void (*)(void))emitPushSymbolValue)();
}
if ( *((_DWORD *)a2 + 10) )
{
emitPushAddressValue(a2);
}
else if ( *((_DWORD *)a2 + 2) != 4 )
{
emitPushSymbolValue(a2);
}
if ( (unsigned int)getType(a1) == 4 && (unsigned int)getType(a2) == 4 )
{
if ( a4 == 298 )
{
emitComment("Converting %s to a real value.", *a1);
emitStmt(128LL, "ADJUST -1");
emitStmt(128LL, "ITOR");
emitStmt(128LL, "ADJUST 1");
emitComment("Converting %s to a real value.", *a2);
emitStmt(128LL, "ITOR");
*a3 = 1;
}
else
{
*a3 = 0;
}
}
else if ( (unsigned int)getType(a1) == 5 && (unsigned int)getType(a2) == 5 )
{
*a3 = 1;
}
else if ( (unsigned int)getType(a1) == 4 && (unsigned int)getType(a2) == 5 )
{
emitComment("Converting %s to a real value.", *a1);
emitStmt(128LL, "ADJUST -1");
emitStmt(128LL, "ITOR");
emitStmt(128LL, "ADJUST 1");
*a3 = 1;
}
else if ( (unsigned int)getType(a1) == 5 && (unsigned int)getType(a2) == 4 )
{
emitComment("Converting %s to a real value.", *a2);
emitStmt(128LL, "ITOR");
*a3 = 1;
}
}
else
{
doNotEmit = 1;
}
}
else
{
doNotEmit = 1;
}
}

original_code:
static void emitArithmeticPrep(Symbol *x, Symbol *y, int *result, int opToken)
{
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 if (x->isAddress) {
  emitPushAddressValue(x);
 } else if (x->kind != TYPE_KIND){
  emitPushSymbolValue(x);
 }
 if (y->isAddress) {
  emitPushAddressValue(y);
 } else if (y->kind != TYPE_KIND){
  emitPushSymbolValue(y);
 }
 if ((getType(x) == INTEGER_T) && (getType(y) == INTEGER_T)) {
  if ( opToken == 298 ) {
   emitComment("Converting %s to a real value.", x->name);
   emitStmt(128, "ADJUST -1");
   emitStmt(128, "ITOR");
   emitStmt(128, "ADJUST 1");
   emitComment("Converting %s to a real value.", y->name);
   emitStmt(128, "ITOR");
   *result = 1;
   return;
  }
  *result = 0;
 } else if ((getType(x) == REAL_T) && (getType(y) == REAL_T)) {
  *result = 1;
 } else if ((getType(x) == INTEGER_T) && (getType(y) == REAL_T)) {
  emitComment("Converting %s to a real value.", x->name);
  emitStmt(128, "ADJUST -1");
  emitStmt(128, "ITOR");
  emitStmt(128, "ADJUST 1");
  *result = 1;
 } else if ((getType(x) == REAL_T) && (getType(y) == INTEGER_T)) {
  emitComment("Converting %s to a real value.", y->name);
  emitStmt(128, "ITOR");
  *result = 1;
 }
}

canonical_original_code:
static void emitArithmeticPrep(struct Symbol *x, struct Symbol *y, int *result, int opToken)
{
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 if (x->isAddress) {
  emitPushAddressValue(x);
 } else if (x->kind != TYPE_KIND){
  emitPushSymbolValue(x);
 }
 if (y->isAddress) {
  emitPushAddressValue(y);
 } else if (y->kind != TYPE_KIND){
  emitPushSymbolValue(y);
 }
 if ((getType(x) == INTEGER_T) && (getType(y) == INTEGER_T)) {
  if ( opToken == 298 ) {
   emitComment("Converting %s to a real value.", x->name);
   emitStmt(128, "ADJUST -1");
   emitStmt(128, "ITOR");
   emitStmt(128, "ADJUST 1");
   emitComment("Converting %s to a real value.", y->name);
   emitStmt(128, "ITOR");
   *result = 1;
   return;
  }
  *result = 0;
 } else if ((getType(x) == REAL_T) && (getType(y) == REAL_T)) {
  *result = 1;
 } else if ((getType(x) == INTEGER_T) && (getType(y) == REAL_T)) {
  emitComment("Converting %s to a real value.", x->name);
  emitStmt(128, "ADJUST -1");
  emitStmt(128, "ITOR");
  emitStmt(128, "ADJUST 1");
  *result = 1;
 } else if ((getType(x) == REAL_T) && (getType(y) == INTEGER_T)) {
  emitComment("Converting %s to a real value.", y->name);
  emitStmt(128, "ITOR");
  *result = 1;
 }
}

variable_types:
y
struct Symbol *

variable_types:
result
int *

variable_types: opToken int

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

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

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

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

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

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

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

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


emitITOR

decompiled_code:
void __fastcall emitITOR(const char **a1)
{
const char *v1; // rbp
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rcx
const char *v5; // r8

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
v1 = *a1;
v2 = getType(a1);
v3 = (const char *)typeToString(v2);
emitComment("Perform ITOR of %s %s and %s %s", v3, v1, v4, v5);
if ( (unsigned int)getType(a1) == 4 )
{
emitPushVarValue(a1);
emitStmt(128LL, "ITOR");
}
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func1(const char **a1)
{
const char *v1; // rbp
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rcx
const char *v5; // r8

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
v1 = *a1;
v2 = getType(a1);
v3 = (const char *)typeToString(v2);
emitComment("Perform ITOR of %s %s and %s %s", v3, v1, v4, v5);
if ( (unsigned int)getType(a1) == 4 )
{
emitPushVarValue(a1);
emitStmt(128LL, "ITOR");
}
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitITOR(Symbol *x) {
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Perform ITOR of %s %s and %s %s",
      typeToString(getType(x)), x->name);
 if ( getType(x) == INTEGER_T) {
  emitPushVarValue(x);
  emitStmt(128, "ITOR");
 }
}

canonical_original_code:
void emitITOR(struct Symbol *x) {
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Perform ITOR of %s %s and %s %s",
      typeToString(getType(x)), x->name);
 if ( getType(x) == INTEGER_T) {
  emitPushVarValue(x);
  emitStmt(128, "ITOR");
 }
}

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

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

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

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


emitRTOI

decompiled_code:
void __fastcall emitRTOI(const char **a1)
{
const char *v1; // rbp
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rcx
const char *v5; // r8

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
v1 = *a1;
v2 = getType(a1);
v3 = (const char *)typeToString(v2);
emitComment("Perform RTOI of %s %s and %s %s", v3, v1, v4, v5);
if ( (unsigned int)getType(a1) == 5 )
{
emitPushVarValue(a1);
emitStmt(128LL, "RTOI");
}
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func2(const char **a1)
{
const char *v1; // rbp
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rcx
const char *v5; // r8

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
v1 = *a1;
v2 = getType(a1);
v3 = (const char *)typeToString(v2);
emitComment("Perform RTOI of %s %s and %s %s", v3, v1, v4, v5);
if ( (unsigned int)getType(a1) == 5 )
{
emitPushVarValue(a1);
emitStmt(128LL, "RTOI");
}
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitRTOI(Symbol *x) {
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Perform RTOI of %s %s and %s %s",
      typeToString(getType(x)), x->name);
 if ( getType(x) == REAL_T) {
  emitPushVarValue(x);
  emitStmt(128, "RTOI");
 }
}

canonical_original_code:
void emitRTOI(struct Symbol *x) {
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Perform RTOI of %s %s and %s %s",
      typeToString(getType(x)), x->name);
 if ( getType(x) == REAL_T) {
  emitPushVarValue(x);
  emitStmt(128, "RTOI");
 }
}

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

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

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

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


emitArithmCheckAndComment

decompiled_code:
void __fastcall emitArithmCheckAndComment(const char **a1, const char **a2, const char *a3)
{
const char *v4; // r13
unsigned int v5; // eax
const char *v6; // r12
const char *v7; // r14
unsigned int v8; // eax
const char *v9; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
v4 = *a2;
v5 = getType(a2);
v6 = (const char *)typeToString(v5);
v7 = *a1;
v8 = getType(a1);
v9 = (const char *)typeToString(v8);
emitComment("Perform %s of %s %s and %s %s", a3, v9, v7, v6, v4);
}
else
{
doNotEmit = 1;
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func3(const char **a1, const char **a2, const char *a3)
{
const char *v4; // r13
unsigned int v5; // eax
const char *v6; // r12
const char *v7; // r14
unsigned int v8; // eax
const char *v9; // rax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
v4 = *a2;
v5 = getType(a2);
v6 = (const char *)typeToString(v5);
v7 = *a1;
v8 = getType(a1);
v9 = (const char *)typeToString(v8);
emitComment("Perform %s of %s %s and %s %s", a3, v9, v7, v6, v4);
}
else
{
doNotEmit = 1;
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitArithmCheckAndComment(Symbol *x, Symbol *y, char *opName) {
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Perform %s of %s %s and %s %s",
  opName,
      typeToString(getType(x)), x->name,
      typeToString(getType(y)), y->name);
}

canonical_original_code:
void emitArithmCheckAndComment(struct Symbol *x, struct Symbol *y, char *opName) {
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Perform %s of %s %s and %s %s",
  opName,
      typeToString(getType(x)), x->name,
      typeToString(getType(y)), y->name);
}

variable_types:
opName
char *

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: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

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

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

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

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


emitMod

decompiled_code:
__int64 __fastcall emitMod(const char **a1, const char **a2)
{
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

emitArithmCheckAndComment(a1, a2, "mod");
emitArithmeticPrep(a1, a2, v3, -1);
return emitStmt(128LL, "MOD");
}

canonical_decompiled_code:
__int64 __fastcall func4(const char **a1, const char **a2)
{
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

func3(a1, a2, "mod");
func0(a1, a2, v3, -1);
return emitStmt(128LL, "MOD");
}

original_code:
void emitMod(Symbol *x, Symbol *y) {
 int result;
 emitArithmCheckAndComment(x, y, "mod");
 emitArithmeticPrep(x, y, &result, -1);
 emitStmt(128, "MOD");
}

canonical_original_code:
void emitMod(struct Symbol *x, struct Symbol *y) {
 int result;
 emitArithmCheckAndComment(x, y, "mod");
 emitArithmeticPrep(x, y, &result, -1);
 emitStmt(128, "MOD");
}

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

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

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

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

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

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


genericArithConstruct

decompiled_code:
__int64 __fastcall genericArithConstruct(const char **a1, const char **a2, const char *a3, __int64 a4, __int64 a5, int a6)
{
__int64 result; // rax
unsigned int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

emitArithmCheckAndComment(a1, a2, a3);
emitArithmeticPrep(a1, a2, v10, a6);
result = v10[0];
if ( !v10[0] )
return emitStmt(128LL, a4);
if ( v10[0] == 1 )
result = emitStmt(128LL, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1, const char **a2, const char *a3, __int64 a4, __int64 a5, int a6)
{
__int64 result; // rax
unsigned int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

func3(a1, a2, a3);
func0(a1, a2, v10, a6);
result = v10[0];
if ( !v10[0] )
return emitStmt(128LL, a4);
if ( v10[0] == 1 )
result = emitStmt(128LL, a5);
return result;
}

original_code:
void genericArithConstruct(Symbol *x, Symbol *y, char *opName,
 char *ascIntName, char *ascRealName, int opToken)
{
 int result;
 emitArithmCheckAndComment(x, y, opName);
 emitArithmeticPrep(x, y, &result, opToken);
 if ( result == 0) {
  emitStmt(128, ascIntName);
 }
 else if (result == 1) {
  emitStmt(128, ascRealName);
 } else {
 }
}

canonical_original_code:
void genericArithConstruct(struct Symbol *x, struct Symbol *y, char *opName, char *ascIntName, char *ascRealName, int opToken)
{
 int result;
 emitArithmCheckAndComment(x, y, opName);
 emitArithmeticPrep(x, y, &result, opToken);
 if ( result == 0) {
  emitStmt(128, ascIntName);
 }
 else if (result == 1) {
  emitStmt(128, ascRealName);
 } else {
 }
}

variable_types:
ascIntName
char *

variable_types:
ascRealName
char *

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

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

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

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


emitAddition

decompiled_code:
__int64 __fastcall emitAddition(const char **a1, const char **a2)
{
return genericArithConstruct(a1, a2, "addition", (__int64)"ADDI", (__int64)"ADDR", -1);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char **a1, const char **a2)
{
return func5(a1, a2, "addition", (__int64)"ADDI", (__int64)"ADDR", -1);
}

original_code:
void emitAddition(Symbol *x, Symbol *y) {
 genericArithConstruct(x, y, "addition", "ADDI", "ADDR", -1);
}

canonical_original_code:
void emitAddition(struct Symbol *x, struct Symbol *y) {
 genericArithConstruct(x, y, "addition", "ADDI", "ADDR", -1);
}

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

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

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

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

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

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

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

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


emitSubtraction

decompiled_code:
__int64 __fastcall emitSubtraction(const char **a1, const char **a2)
{
return genericArithConstruct(a1, a2, "subtraction", (__int64)"SUBI", (__int64)"SUBR", -1);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char **a1, const char **a2)
{
return func5(a1, a2, "subtraction", (__int64)"SUBI", (__int64)"SUBR", -1);
}

original_code:
void emitSubtraction(Symbol *x, Symbol *y) {
 genericArithConstruct(x, y, "subtraction", "SUBI", "SUBR", -1);
}

canonical_original_code:
void emitSubtraction(struct Symbol *x, struct Symbol *y) {
 genericArithConstruct(x, y, "subtraction", "SUBI", "SUBR", -1);
}

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

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

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

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

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

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

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

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


emitMultiplication

decompiled_code:
__int64 __fastcall emitMultiplication(const char **a1, const char **a2)
{
return genericArithConstruct(a1, a2, "mulitplication", (__int64)"MULI", (__int64)"MULR", -1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char **a1, const char **a2)
{
return func5(a1, a2, "mulitplication", (__int64)"MULI", (__int64)"MULR", -1);
}

original_code:
void emitMultiplication(Symbol *x, Symbol *y) {
 genericArithConstruct(x, y, "mulitplication", "MULI", "MULR", -1);
}

canonical_original_code:
void emitMultiplication(struct Symbol *x, struct Symbol *y) {
 genericArithConstruct(x, y, "mulitplication", "MULI", "MULR", -1);
}

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

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

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

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


emitDivision

decompiled_code:
__int64 __fastcall emitDivision(const char **a1, const char **a2, int a3)
{
return genericArithConstruct(a1, a2, "division", (__int64)"DIVI", (__int64)"DIVR", a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char **a1, const char **a2, int a3)
{
return func5(a1, a2, "division", (__int64)"DIVI", (__int64)"DIVR", a3);
}

original_code:
void emitDivision(Symbol *x, Symbol *y, int opToken) {
 genericArithConstruct(x, y, "division", "DIVI", "DIVR", opToken);
}

canonical_original_code:
void emitDivision(struct Symbol *x, struct Symbol *y, int opToken) {
 genericArithConstruct(x, y, "division", "DIVI", "DIVR", opToken);
}

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: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

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

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

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

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


getAscFileName

decompiled_code:
char *__fastcall getAscFileName(char *src)
{
int v1; // ebx
char *v2; // rbp

v1 = strlen(src) + 1;
v2 = 0LL;
if ( v1 > 4 )
{
v2 = (char *)calloc(v1, 1uLL);
strncpy(v2, src, v1);
*(_DWORD *)&v2[v1 - 5] = 1668505902;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
int v1; // ebx
char *v2; // rbp

v1 = strlen(src) + 1;
v2 = 0LL;
if ( v1 > 4 )
{
v2 = (char *)calloc(v1, 1uLL);
strncpy(v2, src, v1);
*(_DWORD *)&v2[v1 - 5] = 1668505902;
}
return v2;
}

original_code:
char *getAscFileName(char *palFileName)
{
  int len = 0;
  char *ascFileName = ((void *)0);
  len = strlen(palFileName) + 1;
  if (len < 5) return ((void *)0);
  ascFileName = calloc(len, sizeof(char));
  strncpy(ascFileName, palFileName, len);
  strncpy(ascFileName + len - 5, ".asc", 4);
  return ascFileName;
}

variable_types:
palFileName
char *

variable_types: len int

variable_types:
ascFileName
char *

return_type: char *


emitStr

decompiled_code:
__int64 __fastcall emitStr(__int64 a1, const char *a2, const char *a3, const char *a4)
{
int v6; // ebx
int v7; // er15
int v8; // er12
char *v9; // rax
char *v10; // rbp

v6 = strlen(a2);
v7 = strlen(a3);
v8 = strlen(a4);
v9 = (char *)calloc(v7 + v6 + v8 + 1, 1uLL);
if ( !v9 )
err(1, "Failed to allocate memory for asc statement.");
v10 = v9;
strncpy(v9, a2, v6);
strncpy(&v10[v6], a3, v7);
strncpy(&v10[v6 + (__int64)v7], a4, v8);
return appendStmt(a1, v10);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, const char *a3, const char *a4)
{
int v6; // ebx
int v7; // er15
int v8; // er12
char *v9; // rax
char *v10; // rbp

v6 = strlen(a2);
v7 = strlen(a3);
v8 = strlen(a4);
v9 = (char *)calloc(v7 + v6 + v8 + 1, 1uLL);
if ( !v9 )
err(1, "Failed to allocate memory for asc statement.");
v10 = v9;
strncpy(v9, a2, v6);
strncpy(&v10[v6], a3, v7);
strncpy(&v10[v6 + (__int64)v7], a4, v8);
return appendStmt(a1, v10);
}

original_code:
void emitStr(StmtLL **ll, char *prefix, char *s, char *suffix) {
 char *stmt = ((void *)0);
 int prefixLen = 0;
 int sLen = 0;
 int suffixLen = 0;
 int stmtLen = 0;
 prefixLen = strlen(prefix);
 sLen = strlen(s);
 suffixLen = strlen(suffix);
 stmtLen = prefixLen + sLen + suffixLen;
 stmt = calloc(stmtLen + 1, sizeof(char));
 if (!(stmt)) err(1,
     "Failed to allocate memory for asc statement.");
 strncpy(stmt, prefix, prefixLen);
 strncpy(stmt + prefixLen, s, sLen);
 strncpy(stmt + prefixLen + sLen, suffix, suffixLen);
 appendStmt(ll, stmt);
}

canonical_original_code:
void emitStr(struct stmtll **ll, char *prefix, char *s, char *suffix) {
 char *stmt = ((void *)0);
 int prefixLen = 0;
 int sLen = 0;
 int suffixLen = 0;
 int stmtLen = 0;
 prefixLen = strlen(prefix);
 sLen = strlen(s);
 suffixLen = strlen(suffix);
 stmtLen = prefixLen + sLen + suffixLen;
 stmt = calloc(stmtLen + 1, sizeof(char));
 if (!(stmt)) err(1,
     "Failed to allocate memory for asc statement.");
 strncpy(stmt, prefix, prefixLen);
 strncpy(stmt + prefixLen, s, sLen);
 strncpy(stmt + prefixLen + sLen, suffix, suffixLen);
 appendStmt(ll, stmt);
}

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

variable_types:
prefix
char *

variable_types:
s
char *

variable_types:
suffix
char *

variable_types:
stmt
char *

variable_types: prefixLen int

variable_types: sLen int

variable_types: suffixLen int

variable_types: stmtLen int


emitComment

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

va_start(arg, format);
memset(cmt_0, 0, 0x400uLL);
vsnprintf(cmt_0, 0x3FFuLL, format, arg);
return emitStr((__int64)&stmts, "\t\t# ", cmt_0, "\n");
}

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

va_start(arg, format);
memset(cmt_0, 0, 0x400uLL);
vsnprintf(cmt_0, 0x3FFuLL, format, arg);
return func1((__int64)&stmts, "\t\t# ", cmt_0, "\n");
}

original_code:
void emitComment(char *s, ...)
{
 static char cmt[1024];
 va_list args;
 memset(cmt, 0, 1024);
 __builtin_va_start(args,s);
 vsnprintf(cmt, 1024 - 1, s, args);
 __builtin_va_end(args);
 emitStr(&stmts, "\t\t# ", cmt, "\n");
}

canonical_original_code:
void emitComment(char *s, ...)
{
 static char cmt[1024];
 __builtin_va_list args;
 memset(cmt, 0, 1024);
 __builtin_va_start(args,s);
 vsnprintf(cmt, 1024 - 1, s, args);
 __builtin_va_end(args);
 emitStr(&stmts, "\t\t# ", cmt, "\n");
}

variable_types:
cmt
char [1024]


emitStmt

decompiled_code:
__int64 emitStmt(int a1, const char *a2, ...)
{
char *v2; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v2 = (char *)calloc(a1 + 1, 1uLL);
vsnprintf(v2, a1, a2, arg);
return emitStr((__int64)&stmts, (const char *)&off_AEB, v2, "\n");
}

canonical_decompiled_code:
__int64 func3(int a1, const char *a2, ...)
{
char *v2; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v2 = (char *)calloc(a1 + 1, 1uLL);
vsnprintf(v2, a1, a2, arg);
return func1((__int64)&stmts, (const char *)&off_AEB, v2, "\n");
}

original_code:
void emitStmt(int len, char *s, ...)
{
 va_list args;
 char *stmt = ((void *)0);
 stmt = calloc(len + 1, sizeof(char));
 __builtin_va_start(args,s);
 vsnprintf(stmt, len, s, args);
 __builtin_va_end(args);
 emitStr(&stmts, "\t\t", stmt, "\n");
}

canonical_original_code:
void emitStmt(int len, char *s, ...)
{
 __builtin_va_list args;
 char *stmt = ((void *)0);
 stmt = calloc(len + 1, sizeof(char));
 __builtin_va_start(args,s);
 vsnprintf(stmt, len, s, args);
 __builtin_va_end(args);
 emitStr(&stmts, "\t\t", stmt, "\n");
}


emitBlankLine

decompiled_code:
__int64 emitBlankLine()
{
return emitStr((__int64)&stmts, (const char *)&off_AEB + 3, (const char *)&off_AEB + 3, "\n");
}

canonical_decompiled_code:
__int64 func4()
{
return func1((__int64)&stmts, (const char *)&off_AEB + 3, (const char *)&off_AEB + 3, "\n");
}

original_code:
void emitBlankLine() {
 emitStr(&stmts, "", "", "\n");
}


emitLabel

decompiled_code:
__int64 emitLabel(int a1, const char *a2, ...)
{
char *v2; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v2 = (char *)calloc(a1 + 1, 1uLL);
vsnprintf(v2, a1, a2, arg);
return emitStr((__int64)&stmts, (const char *)&off_AEB + 3, v2, "\n");
}

canonical_decompiled_code:
__int64 func6(int a1, const char *a2, ...)
{
char *v2; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v2 = (char *)calloc(a1 + 1, 1uLL);
vsnprintf(v2, a1, a2, arg);
return func1((__int64)&stmts, (const char *)&off_AEB + 3, v2, "\n");
}

original_code:
void emitLabel(int len, char *s, ...)
{
 va_list args;
 char *stmt = ((void *)0);
 stmt = calloc(len + 1, sizeof(char));
 __builtin_va_start(args,s);
 vsnprintf(stmt, len, s, args);
 __builtin_va_end(args);
 emitStr(&stmts, "", stmt, "\n");
}

canonical_original_code:
void emitLabel(int len, char *s, ...)
{
 __builtin_va_list args;
 char *stmt = ((void *)0);
 stmt = calloc(len + 1, sizeof(char));
 __builtin_va_start(args,s);
 vsnprintf(stmt, len, s, args);
 __builtin_va_end(args);
 emitStr(&stmts, "", stmt, "\n");
}


popLabels

decompiled_code:
void __fastcall popLabels(__int64 a1)
{
--*(_DWORD *)(a1 + 20);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
--*(_DWORD *)(a1 + 20);
}

original_code:
void popLabels(struct labelStack *stack) {
 stack->ltop -= 1;
}

variable_types: struct labelStack { int label; int *stack; int stackSize; int ltop; } *


peekLabelStackTop

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

v1 = *(_DWORD *)(a1 + 20);
if ( v1 < 0 )
err(1, "Peeking at label stack without having any labels reserved.");
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * v1);
}

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

v1 = *(_DWORD *)(a1 + 20);
if ( v1 < 0 )
err(1, "Peeking at label stack without having any labels reserved.");
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * v1);
}

original_code:
int peekLabelStackTop(struct labelStack *stack) {
 if (stack->ltop < 0) {
  err(1, "Peeking at label stack without having any "
      "labels reserved.");
 }
 return stack->stack[stack->ltop];
}

user_defined_types: struct labelStack { int label; int *stack; int stackSize; int ltop; }


growLabelStack

decompiled_code:
__int64 __fastcall growLabelStack(__int64 a1)
{
int v1; // eax
char *v2; // rax
char *v3; // rcx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v1 + 128;
v2 = (char *)realloc(*(void **)(a1 + 8), 4LL * (v1 + 128));
*(_QWORD *)(a1 + 8) = v2;
if ( !v2 )
err(1, "Failed to allocate memory for label stack!");
v3 = &v2[4 * *(int *)(a1 + 16) - 512];
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 15) = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 128) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // eax
char *v2; // rax
char *v3; // rcx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v1 + 128;
v2 = (char *)realloc(*(void **)(a1 + 8), 4LL * (v1 + 128));
*(_QWORD *)(a1 + 8) = v2;
if ( !v2 )
err(1, "Failed to allocate memory for label stack!");
v3 = &v2[4 * *(int *)(a1 + 16) - 512];
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 15) = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 128) >> 3));
return result;
}

original_code:
void growLabelStack(struct labelStack *stack) {
 stack->stackSize += 128;
 stack->stack = realloc(stack->stack, stack->stackSize*sizeof(int));
 if (stack->stack == ((void *)0)) {
  err(1, "Failed to allocate memory for label stack!");
 }
 memset(
     stack->stack + stack->stackSize - 128,
     0,
     128);
}


reserveLabels

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

if ( !a1 )
err(1, "Trying to puch to NULL labelStack");
if ( a2 <= 0 )
err(1, "Trying to reserve less than 1 label");
if ( *(_DWORD *)(a1 + 16) == *(_DWORD *)(a1 + 20) + 1 )
growLabelStack(a1);
LODWORD(result) = *(_DWORD *)(a1 + 20) + 1;
*(_DWORD *)(a1 + 20) = result;
result = (int)result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * (int)result) = *(_DWORD *)a1;
*(_DWORD *)a1 += a2;
return result;
}

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

if ( !a1 )
err(1, "Trying to puch to NULL labelStack");
if ( a2 <= 0 )
err(1, "Trying to reserve less than 1 label");
if ( *(_DWORD *)(a1 + 16) == *(_DWORD *)(a1 + 20) + 1 )
func9(a1);
LODWORD(result) = *(_DWORD *)(a1 + 20) + 1;
*(_DWORD *)(a1 + 20) = result;
result = (int)result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * (int)result) = *(_DWORD *)a1;
*(_DWORD *)a1 += a2;
return result;
}

original_code:
void reserveLabels(struct labelStack *stack, int n) {
 if (stack == ((void *)0)) {
  err(1, "Trying to puch to NULL labelStack");
 }
 if (n < 1) {
  err(1, "Trying to reserve less than 1 label");
 }
 if (stack->stackSize == (stack->ltop + 1)) {
  growLabelStack(stack);
 }
 stack->ltop += 1;
 stack->stack[stack->ltop] = stack->label;
 stack->label += n;
}

variable_types: n int


newLabelStack

decompiled_code:
_DWORD *newLabelStack()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = calloc(1uLL, 0x18uLL);
if ( !v0 )
err(1, "Failed to allocate memory for label stack!");
v1 = v0;
v0[5] = -1;
growLabelStack((__int64)v0);
return v1;
}

canonical_decompiled_code:
_DWORD *func11()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = calloc(1uLL, 0x18uLL);
if ( !v0 )
err(1, "Failed to allocate memory for label stack!");
v1 = v0;
v0[5] = -1;
func9((__int64)v0);
return v1;
}

original_code:
struct labelStack *newLabelStack() {
 struct labelStack *newStack = ((void *)0);
 newStack = calloc(1, sizeof(struct labelStack));
 if (newStack == ((void *)0)) {
  err(1, "Failed to allocate memory for label stack!");
 }
 newStack->ltop = -1;
 growLabelStack(newStack);
 return newStack;
}

return_type: struct labelStack { int label; int *stack; int stackSize; int ltop; } *


destroyLabelStack

decompiled_code:
void __fastcall destroyLabelStack(__int64 a1)
{
void *v1; // rbp

v1 = *(void **)a1;
free(*(void **)(*(_QWORD *)a1 + 8LL));
free(v1);
*(_QWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
void *v1; // rbp

v1 = *(void **)a1;
free(*(void **)(*(_QWORD *)a1 + 8LL));
free(v1);
*(_QWORD *)a1 = 0LL;
}

original_code:
void destroyLabelStack(struct labelStack **stack) {
 struct labelStack *s = *stack;
 free(s->stack);
 free(s);
 *stack = ((void *)0);
}

variable_types: struct labelStack { int label; int *stack; int stackSize; int ltop; } **


getAdjustCounter

decompiled_code:
__int64 getAdjustCounter()
{
return getLocalSymbolCount(symbolTable);
}

canonical_decompiled_code:
__int64 func13()
{
return getLocalSymbolCount(symbolTable);
}

original_code:
int getAdjustCounter() {
 return getLocalSymbolCount(symbolTable);
}


getReturnOffset

decompiled_code:
__int64 getReturnOffset()
{
return getLocalParamSymbolCount(symbolTable);
}

canonical_decompiled_code:
__int64 func14()
{
return getLocalParamSymbolCount(symbolTable);
}

original_code:
int getReturnOffset() {
 return getLocalParamSymbolCount(symbolTable);
}


emitUnaryPrep

decompiled_code:
__int64 __fastcall emitUnaryPrep(__int64 a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( !v2 )
return emitPushSymbolValue();
if ( v2 != 4 )
emitPushSymbolValue();
result = getType(a1);
switch ( (_DWORD)result )
{
case 4:
*a2 = 1;
break;
case 5:
*a2 = 2;
break;
case 2:
*a2 = 3;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( !v2 )
return emitPushSymbolValue();
if ( v2 != 4 )
emitPushSymbolValue();
result = getType(a1);
switch ( (_DWORD)result )
{
case 4:
*a2 = 1;
break;
case 5:
*a2 = 2;
break;
case 2:
*a2 = 3;
break;
}
return result;
}

original_code:
static void emitUnaryPrep(Symbol *x, int *opType)
{
 if (x->kind == CONST_KIND) {
  emitPushSymbolValue(x);
  return;
 }
 if (x->kind != TYPE_KIND) {
  emitPushSymbolValue(x);
 }
 switch (getType(x)) {
 case BOOLEAN_T:
  *opType = 3;
  return;
 case INTEGER_T:
  *opType = 1;
  return;
 case REAL_T:
  *opType = 2;
  return;
 default:
  return;
 }
}

canonical_original_code:
static void emitUnaryPrep(struct Symbol *x, int *opType)
{
 if (x->kind == CONST_KIND) {
  emitPushSymbolValue(x);
  return;
 }
 if (x->kind != TYPE_KIND) {
  emitPushSymbolValue(x);
 }
 switch (getType(x)) {
 case BOOLEAN_T:
  *opType = 3;
  return;
 case INTEGER_T:
  *opType = 1;
  return;
 case REAL_T:
  *opType = 2;
  return;
 default:
  return;
 }
}

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

variable_types:
opType
int *

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

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

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

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


emitUnaryPlus

decompiled_code:
__int64 __fastcall emitUnaryPlus(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

return emitUnaryPrep(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

return func0(a1, v2);
}

original_code:
void emitUnaryPlus(Symbol *x)
{
 int opType;
 emitUnaryPrep(x, &opType);
}

canonical_original_code:
void emitUnaryPlus(struct Symbol *x)
{
 int opType;
 emitUnaryPrep(x, &opType);
}

variable_types: opType int

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

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

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

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

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


emitUnaryMinus

decompiled_code:
__int64 __fastcall emitUnaryMinus(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

emitUnaryPrep(a1, v2);
result = v2[0];
if ( v2[0] == 1 )
{
emitStmt(128LL, "CONSTI -1");
result = emitStmt(128LL, "MULI");
}
else if ( v2[0] == 2 )
{
emitStmt(128LL, "CONSTR -1.0");
result = emitStmt(128LL, "MULR");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

func0(a1, v2);
result = v2[0];
if ( v2[0] == 1 )
{
emitStmt(128LL, "CONSTI -1");
result = emitStmt(128LL, "MULI");
}
else if ( v2[0] == 2 )
{
emitStmt(128LL, "CONSTR -1.0");
result = emitStmt(128LL, "MULR");
}
return result;
}

original_code:
void emitUnaryMinus(Symbol *x)
{
 int opType;
 emitUnaryPrep(x, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "CONSTI -1");
  emitStmt(128, "MULI");
  break;
 case 2:
  emitStmt(128, "CONSTR -1.0");
  emitStmt(128, "MULR");
  break;
 case -1:
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitUnaryMinus(struct Symbol *x)
{
 int opType;
 emitUnaryPrep(x, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "CONSTI -1");
  emitStmt(128, "MULI");
  break;
 case 2:
  emitStmt(128, "CONSTR -1.0");
  emitStmt(128, "MULR");
  break;
 case -1:
  break;
 default:
  break;
 }
}

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

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

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

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

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

user_defined_types: struct StringType { unsigned int strlen; }

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

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

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


emitNot

decompiled_code:
__int64 __fastcall emitNot(__int64 a1)
{
__int64 result; // rax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = emitUnaryPrep(a1, v2);
if ( v2[0] == 3 )
result = emitStmt(128LL, "NOT");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = func0(a1, v2);
if ( v2[0] == 3 )
result = emitStmt(128LL, "NOT");
return result;
}

original_code:
void emitNot(Symbol *x)
{
 int opType;
 emitUnaryPrep(x, &opType);
 switch (opType) {
 case 3:
  emitStmt(128, "NOT");
  break;
 case -1:
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitNot(struct Symbol *x)
{
 int opType;
 emitUnaryPrep(x, &opType);
 switch (opType) {
 case 3:
  emitStmt(128, "NOT");
  break;
 case -1:
  break;
 default:
  break;
 }
}

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

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

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

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

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


simpleTypeLookup

decompiled_code:
__int64 __fastcall simpleTypeLookup(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v4; // rax
__int64 v5; // rax

v1 = getGlobalSymbol(symbolTable, a1);
v2 = v1;
if ( v1 )
{
if ( *(_DWORD *)(v1 + 8) != 4 )
{
v5 = customErrorString("The identifier %s is not a type. ", *(const char **)v1);
recordError(v5, yylineno, colno, 2LL);
v2 = getTypeSym(v2);
}
}
else
{
v4 = customErrorString("The identifier %s has not been defined.", a1);
recordError(v4, yylineno, colno, 2LL);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v4; // rax
__int64 v5; // rax

v1 = getGlobalSymbol(symbolTable, a1);
v2 = v1;
if ( v1 )
{
if ( *(_DWORD *)(v1 + 8) != 4 )
{
v5 = customErrorString("The identifier %s is not a type. ", *(const char **)v1);
recordError(v5, yylineno, colno, 2LL);
v2 = getTypeSym(v2);
}
}
else
{
v4 = customErrorString("The identifier %s has not been defined.", a1);
recordError(v4, yylineno, colno, 2LL);
}
return v2;
}

original_code:
Symbol *simpleTypeLookup(char *id) {
 Symbol *s = getGlobalSymbol(symbolTable, id);
 if (!s) {
  errMsg = customErrorString("The identifier %s has not been "
    "defined.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (s->kind != TYPE_KIND) {
  errMsg = customErrorString("The identifier %s is not a type. ",
      s->name);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return getTypeSym(s);
 }
 return s;
}

canonical_original_code:
struct Symbol *simpleTypeLookup(char *id) {
 struct Symbol *s = getGlobalSymbol(symbolTable, id);
 if (!s) {
  errMsg = customErrorString("The identifier %s has not been "
    "defined.", id);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return ((void *)0);
 }
 if (s->kind != TYPE_KIND) {
  errMsg = customErrorString("The identifier %s is not a type. ",
      s->name);
  recordError(errMsg, yylineno, colno, SEMANTIC);
  return getTypeSym(s);
 }
 return s;
}

variable_types:
id
char *

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

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

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

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

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }


appendToScalarListType

decompiled_code:
__int64 __fastcall appendToScalarListType(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( getLocalSymbol(symbolTable) )
{
alreadyDefinedError(a2);
result = 0LL;
}
else
{
v2 = getPreDefInt(preDefTypeSymbols);
v3 = newConstProxySym(a2, a1 + 12, v2);
if ( (unsigned int)addToSymbolTable(symbolTable, v3) )
symbolTableInsertFailure();
appendElement(a1, v3);
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( getLocalSymbol(symbolTable) )
{
alreadyDefinedError(a2);
result = 0LL;
}
else
{
v2 = getPreDefInt(preDefTypeSymbols);
v3 = newConstProxySym(a2, a1 + 12, v2);
if ( (unsigned int)addToSymbolTable(symbolTable, v3) )
symbolTableInsertFailure();
appendElement(a1, v3);
result = a1;
}
return result;
}

original_code:
struct ElementArray *appendToScalarListType(struct ElementArray *ea,
    char *id) {
 Symbol *s = ((void *)0);
 if (!ea) return ((void *)0);
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  alreadyDefinedError(id);
  return ((void *)0);
 }
 s = (Symbol *) newConstProxySym(id, &ea->nElements,
     getPreDefInt(preDefTypeSymbols));
 if (addToSymbolTable(symbolTable, s) != 0) {
  symbolTableInsertFailure();
 }
 appendElement(ea, s);
 return ea;
}

canonical_original_code:
struct ElementArray *appendToScalarListType(struct ElementArray *ea, char *id) {
 struct Symbol *s = ((void *)0);
 if (!ea) return ((void *)0);
 s = getLocalSymbol(symbolTable, id);
 if (s) {
  alreadyDefinedError(id);
  return ((void *)0);
 }
 s = (struct Symbol *) newConstProxySym(id, &ea->nElements,
     getPreDefInt(preDefTypeSymbols));
 if (addToSymbolTable(symbolTable, s) != 0) {
  symbolTableInsertFailure();
 }
 appendElement(ea, s);
 return ea;
}

variable_types:
ea
struct ElementArray *

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

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

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

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

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

user_defined_types: struct StringType { unsigned int strlen; }

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

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

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


createScalarList

decompiled_code:
__int64 __fastcall createScalarList(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
if ( !a1 )
err(1, "Passed NULL id into createScalarList");
if ( getLocalSymbol(symbolTable) )
{
alreadyDefinedError(a1);
v3 = 0LL;
}
else
{
v1 = getPreDefInt(preDefTypeSymbols);
v2 = newConstProxySym(a1, v5, v1);
if ( (unsigned int)addToSymbolTable(symbolTable, v2) )
symbolTableInsertFailure();
v3 = newElementArray();
appendElement(v3, v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
if ( !a1 )
err(1, "Passed NULL id into createScalarList");
if ( getLocalSymbol(symbolTable) )
{
alreadyDefinedError(a1);
v3 = 0LL;
}
else
{
v1 = getPreDefInt(preDefTypeSymbols);
v2 = newConstProxySym(a1, v5, v1);
if ( (unsigned int)addToSymbolTable(symbolTable, v2) )
symbolTableInsertFailure();
v3 = newElementArray();
appendElement(v3, v2);
}
return v3;
}

original_code:
struct ElementArray * createScalarList(char *id) {
 Symbol *s = ((void *)0);
 struct ElementArray *ea = ((void *)0);
 int value = 0;
 if (id == ((void *)0)) {
  err(1, "Passed NULL id into createScalarList");
 }
 s = getLocalSymbol(symbolTable, id);
 if (s != ((void *)0)) {
  alreadyDefinedError(id);
  return ((void *)0);
 }
 s = (Symbol *) newConstProxySym(
     id, &value, getPreDefInt(preDefTypeSymbols));
 if (addToSymbolTable(symbolTable, s) != 0) {
  symbolTableInsertFailure();
 }
 ea = newElementArray();
 appendElement(ea, s);
 return ea;
}

canonical_original_code:
struct ElementArray *createScalarList(char *id) {
 struct Symbol *s = ((void *)0);
 struct ElementArray *ea = ((void *)0);
 int value = 0;
 if (id == ((void *)0)) {
  err(1, "Passed NULL id into createScalarList");
 }
 s = getLocalSymbol(symbolTable, id);
 if (s != ((void *)0)) {
  alreadyDefinedError(id);
  return ((void *)0);
 }
 s = (struct Symbol *) newConstProxySym(
     id, &value, getPreDefInt(preDefTypeSymbols));
 if (addToSymbolTable(symbolTable, s) != 0) {
  symbolTableInsertFailure();
 }
 ea = newElementArray();
 appendElement(ea, s);
 return ea;
}

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

variable_types: value int

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

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

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

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

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

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

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