emitStmt

decompiled_code:
__int64 emitStmt(int a1, const char *a2, ...)
{
char *v2; // r12
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_B2B, v2, "\n");
}

canonical_decompiled_code:
__int64 func3(int a1, const char *a2, ...)
{
char *v2; // r12
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_B2B, 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

repo: a-krebs/YACC

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

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

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

return_type: void


emitLabel

decompiled_code:
__int64 emitLabel(int a1, const char *a2, ...)
{
char *v2; // r12
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_B2B + 3, v2, "\n");
}

canonical_decompiled_code:
__int64 func6(int a1, const char *a2, ...)
{
char *v2; // r12
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_B2B + 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");
}

variable_types: len int

variable_types:
s
char *

variable_types:
stmt
char *


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)
{
__int64 v1; // rax

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

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

v1 = *(int *)(a1 + 20);
if ( (int)v1 < 0 )
err(1, "Peeking at label stack without having any labels reserved.");
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4 * 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];
}

return_type: int

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];
result = 0LL;
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 15) = 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];
result = 0LL;
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 15) = 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
int v3; // ecx
__int64 v4; // rdx

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

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

if ( !a1 )
err(1, "Trying to puch to NULL labelStack");
if ( a2 <= 0 )
err(1, "Trying to reserve less than 1 label");
LODWORD(result) = *(_DWORD *)(a1 + 20) + 1;
if ( *(_DWORD *)(a1 + 16) == (_DWORD)result )
{
func9(a1);
LODWORD(result) = *(_DWORD *)(a1 + 20) + 1;
}
v3 = *(_DWORD *)a1;
v4 = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 20) = result;
result = (int)result;
*(_DWORD *)(v4 + 4LL * (int)result) = v3;
*(_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; // r12

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

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

v0 = calloc(1uLL, 0x18uLL);
if ( !v0 )
err(1, "Failed to allocate memory for label stack!");
v0[5] = -1;
v1 = v0;
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 )
{
result = getType(a1);
if ( (_DWORD)result != 4 )
goto LABEL_4;
LABEL_9:
*a2 = 1;
return result;
}
emitPushSymbolValue();
result = getType(a1);
if ( (_DWORD)result == 4 )
goto LABEL_9;
LABEL_4:
if ( (_DWORD)result == 5 )
{
*a2 = 2;
}
else if ( (_DWORD)result == 2 )
{
*a2 = 3;
}
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 )
{
result = getType(a1);
if ( (_DWORD)result != 4 )
goto LABEL_4;
LABEL_9:
*a2 = 1;
return result;
}
emitPushSymbolValue();
result = getType(a1);
if ( (_DWORD)result == 4 )
goto LABEL_9;
LABEL_4:
if ( (_DWORD)result == 5 )
{
*a2 = 2;
}
else if ( (_DWORD)result == 2 )
{
*a2 = 3;
}
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; }

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


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


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: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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


simpleTypeLookup

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

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

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

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

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


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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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


createScalarList

decompiled_code:
__int64 __fastcall createScalarList(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // r12
__int64 result; // rax
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);
result = 0LL;
}
else
{
v1 = getPreDefInt(preDefTypeSymbols);
v2 = newConstProxySym(a1, v5, v1);
if ( (unsigned int)addToSymbolTable(symbolTable, v2) )
symbolTableInsertFailure();
v3 = newElementArray();
appendElement(v3, v2);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // r12
__int64 result; // rax
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);
result = 0LL;
}
else
{
v1 = getPreDefInt(preDefTypeSymbols);
v2 = newConstProxySym(a1, v5, v1);
if ( (unsigned int)addToSymbolTable(symbolTable, v2) )
symbolTableInsertFailure();
v3 = newElementArray();
appendElement(v3, v2);
result = v3;
}
return result;
}

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


createScalarListType

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

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

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

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

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

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

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

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

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

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

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

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

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

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


createArrayType

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

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

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

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

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

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

variable_types:
index
struct Symbol *

variable_types:
base
struct Symbol *

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

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

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

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

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

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

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


assertArrIndexType

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


createRangeType

decompiled_code:
__int64 __fastcall createRangeType(__int64 *a1, __int64 *a2)
{
__int64 v4; // rdi
__int64 v5; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 *a2)
{
__int64 v4; // rdi
__int64 v5; // rsi

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

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

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

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

variable_types:
upper
struct treeNode *

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

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

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

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

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

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

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

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


createRecordType

decompiled_code:
__int64 __fastcall createRecordType(__int64 a1)
{
__int64 v2; // r13
unsigned int v3; // ebx
__int64 v4; // rax
const char **v5; // rdi
const char **v6; // rax
const char **v7; // r14
const char *v8; // r12
__int64 v9; // rax
__int64 v10; // r15
__int64 result; // rax
int v12; // [rsp+0h] [rbp-48h]
int v13; // [rsp+4h] [rbp-44h]
__int64 v14; // [rsp+8h] [rbp-40h]

v14 = newRecordTypeSym(0LL);
v2 = ***(_QWORD ***)(v14 + 16);
v13 = getCurrentLexLevel(v2);
if ( *(_DWORD *)(a1 + 12) )
{
v12 = 0;
v3 = 0;
while ( 1 )
{
while ( 1 )
{
v6 = (const char **)getElementAt(a1, v3);
v7 = v6;
if ( !v6 )
goto LABEL_6;
v8 = *v6;
v5 = v6;
if ( *v6 )
break;
LABEL_5:
freeProxySymbol(v5);
LABEL_6:
if ( *(_DWORD *)(a1 + 12) <= ++v3 )
goto LABEL_12;
}
v9 = getTypeSym(v6);
v10 = newVariableSym(v8, v9);
v12 += *(_DWORD *)(v10 + 36);
*(_DWORD *)(v10 + 24) = v13;
if ( getLocalSymbol(v2) )
break;
if ( (unsigned int)addToSymbolTable(v2, v10) )
goto LABEL_4;
++v3;
v12 += *(_DWORD *)(v10 + 36);
setSymbolOffset(v10, v2);
if ( *(_DWORD *)(a1 + 12) <= v3 )
goto LABEL_12;
}
v4 = customErrorString("Record field with name %s already defined.", v8);
recordError(v4, yylineno, colno, 2LL);
LABEL_4:
v5 = v7;
goto LABEL_5;
}
v12 = 0;
LABEL_12:
result = v14;
*(_DWORD *)(v14 + 36) = v12;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v2; // r13
unsigned int v3; // ebx
__int64 v4; // rax
const char **v5; // rdi
const char **v6; // rax
const char **v7; // r14
const char *v8; // r12
__int64 v9; // rax
__int64 v10; // r15
__int64 result; // rax
int v12; // [rsp+0h] [rbp-48h]
int v13; // [rsp+4h] [rbp-44h]
__int64 v14; // [rsp+8h] [rbp-40h]

v14 = newRecordTypeSym(0LL);
v2 = ***(_QWORD ***)(v14 + 16);
v13 = getCurrentLexLevel(v2);
if ( *(_DWORD *)(a1 + 12) )
{
v12 = 0;
v3 = 0;
while ( 1 )
{
while ( 1 )
{
v6 = (const char **)getElementAt(a1, v3);
v7 = v6;
if ( !v6 )
goto LABEL_6;
v8 = *v6;
v5 = v6;
if ( *v6 )
break;
LABEL_5:
freeProxySymbol(v5);
LABEL_6:
if ( *(_DWORD *)(a1 + 12) <= ++v3 )
goto LABEL_12;
}
v9 = getTypeSym(v6);
v10 = newVariableSym(v8, v9);
v12 += *(_DWORD *)(v10 + 36);
*(_DWORD *)(v10 + 24) = v13;
if ( getLocalSymbol(v2) )
break;
if ( (unsigned int)addToSymbolTable(v2, v10) )
goto LABEL_4;
++v3;
v12 += *(_DWORD *)(v10 + 36);
setSymbolOffset(v10, v2);
if ( *(_DWORD *)(a1 + 12) <= v3 )
goto LABEL_12;
}
v4 = customErrorString("Record field with name %s already defined.", v8);
recordError(v4, yylineno, colno, 2LL);
LABEL_4:
v5 = v7;
goto LABEL_5;
}
v12 = 0;
LABEL_12:
result = v14;
*(_DWORD *)(v14 + 36) = v12;
return result;
}

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

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

variable_types:
fields
struct ElementArray *

variable_types: recordLexLvl int

variable_types: recordSize int

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

variable_types:
fieldId
char *

variable_types: i int

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


createRecordMemberList

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

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

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

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

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

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

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

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


appendToRecordMemberList

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

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

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

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

variable_types:
array
struct ElementArray *

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

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

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

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


newRecordFieldProxy

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

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

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

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

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

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

variable_types:
id
char *

variable_types:
type
struct Symbol *

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


emitPushVarAddress

decompiled_code:
void __fastcall emitPushVarAddress(__int64 a1)
{
int v1; // eax
__int64 v2; // rcx
__int64 v3; // rdx

if ( a1 && !doNotEmit )
{
if ( (unsigned int)getType() - 1 <= 7 )
{
v1 = isByReference(a1);
v2 = *(unsigned int *)(a1 + 24);
v3 = *(unsigned int *)(a1 + 32);
if ( v1 )
emitStmt(128LL, "PUSH %d[%d]", v3, v2);
else
emitStmt(128LL, "PUSHA %d[%d]", v3, v2);
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
int v1; // eax
__int64 v2; // rcx
__int64 v3; // rdx

if ( a1 && !doNotEmit )
{
if ( (unsigned int)getType() - 1 <= 7 )
{
v1 = isByReference(a1);
v2 = *(unsigned int *)(a1 + 24);
v3 = *(unsigned int *)(a1 + 32);
if ( v1 )
emitStmt(128LL, "PUSH %d[%d]", v3, v2);
else
emitStmt(128LL, "PUSHA %d[%d]", v3, v2);
}
}
else
{
doNotEmit = 1;
}
}

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

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

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

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

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

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

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

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

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

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


emitPushVarValue

decompiled_code:
void __fastcall emitPushVarValue(__int64 a1)
{
unsigned int v1; // eax
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rdx
int v5; // eax

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

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
unsigned int v1; // eax
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rdx
int v5; // eax

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

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

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

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

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

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

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

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

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

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

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


emitPushStructuredVarValue

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

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

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

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

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

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

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


emitPushAddressValue

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

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

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

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

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

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

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

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

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

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

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

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

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

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


emitPushRecordFieldAddress

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

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

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

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

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

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

variable_types:
field
struct Symbol *

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

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

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

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

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

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

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

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


emitPushStringLiteralValue

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

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

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

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

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

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

variable_types:
str
char *

variable_types: strlen int

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


emitPushAnonConstValue

decompiled_code:
void __fastcall emitPushAnonConstValue(__int64 a1)
{
__int64 v1; // rdx
double *v2; // rax

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

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
__int64 v1; // rdx
double *v2; // rax

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

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

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

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

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

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

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

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

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

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

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


emitPushConstValue

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

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

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

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

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

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

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

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

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

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

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

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

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

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


emitPushSymbolValue

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

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

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

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

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

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

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


emitArrayElementLocation

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

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

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

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

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

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

variable_types:
indices
struct Symbol *

variable_types: onceThrough int

variable_types: lowVal int

variable_types: baseTypeSize int

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

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

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

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

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

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

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

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