getSubrangeBaseTypeSym

decompiled_code:
__int64 __fastcall getSubrangeBaseTypeSym(__int64 a1)
{
int v1; // edx
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = getType();
result = 0LL;
if ( v1 == 10 )
result = *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // edx
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = getType();
result = 0LL;
if ( v1 == 10 )
result = *(_QWORD *)(*(_QWORD *)getTypePtr(a1) + 8LL);
return result;
}

original_code:
Symbol * getSubrangeBaseTypeSym(Symbol *sr) {
 if (!sr) return ((void *)0);
 if (getType(sr) != SUBRANGE_T) return ((void *)0);
 return getTypePtr(sr)->Subrange->baseTypeSym;
}

canonical_original_code:
struct Symbol *getSubrangeBaseTypeSym(struct Symbol *sr) {
 if (!sr) return ((void *)0);
 if (getType(sr) != SUBRANGE_T) return ((void *)0);
 return getTypePtr(sr)->Subrange->baseTypeSym;
}

variable_types:
sr
struct Symbol *

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

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

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


freeProxySymbol

repo: a-krebs/YACC

decompiled_code:
void __fastcall freeProxySymbol(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
free(a1);
}

original_code:
void freeProxySymbol(ProxySymbol *p) {
 free(p);
}

canonical_original_code:
void freeProxySymbol(struct Symbol *p) {
 free(p);
}

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

return_type: void

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

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


isConstResultSym

decompiled_code:
__int64 __fastcall isConstResultSym(__int64 a1)
{
unsigned int *v1; // rax

v1 = *(unsigned int **)(a1 + 16);
if ( !v1 )
err(1, "kindPtr is NULL");
return *v1;
}

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

v1 = *(unsigned int **)(a1 + 16);
if ( !v1 )
err(1, "kindPtr is NULL");
return *v1;
}

original_code:
int isConstResultSym(ProxySymbol *s){
 if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
 return s->kindPtr.ConstKind->constResultFlag;
}

canonical_original_code:
int isConstResultSym(struct Symbol *s){
 if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
 return s->kindPtr.ConstKind->constResultFlag;
}

return_type: int

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

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

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

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


getTypeSym

decompiled_code:
__int64 __fastcall getTypeSym(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 *v3; // rax
__int64 *v4; // rax
__int64 *v5; // rax

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
err(1, "kindPtr is NULL");
result = *(_QWORD *)(v1 + 8);
break;
case 1:
v4 = *(__int64 **)(a1 + 16);
if ( !v4 )
err(1, "kindPtr is NULL");
result = *v4;
break;
case 2:
v3 = *(__int64 **)(a1 + 16);
if ( !v3 )
err(1, "kindPtr is NULL");
result = *v3;
break;
case 3:
result = 0LL;
break;
case 4:
if ( !*(_QWORD *)(a1 + 16) )
err(1, "kindPtr is NULL");
result = a1;
break;
case 5:
v5 = *(__int64 **)(a1 + 16);
if ( !v5 )
err(1, "kindPtr is NULL");
result = *v5;
break;
default:
err(1, "Unknown kind set on given symbol");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 *v3; // rax
__int64 *v4; // rax
__int64 *v5; // rax

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
err(1, "kindPtr is NULL");
result = *(_QWORD *)(v1 + 8);
break;
case 1:
v4 = *(__int64 **)(a1 + 16);
if ( !v4 )
err(1, "kindPtr is NULL");
result = *v4;
break;
case 2:
v3 = *(__int64 **)(a1 + 16);
if ( !v3 )
err(1, "kindPtr is NULL");
result = *v3;
break;
case 3:
result = 0LL;
break;
case 4:
if ( !*(_QWORD *)(a1 + 16) )
err(1, "kindPtr is NULL");
result = a1;
break;
case 5:
v5 = *(__int64 **)(a1 + 16);
if ( !v5 )
err(1, "kindPtr is NULL");
result = *v5;
break;
default:
err(1, "Unknown kind set on given symbol");
}
return result;
}

original_code:
Symbol *getTypeSym(Symbol *s) {
 if (!s) return ((void *)0);
 switch (s->kind) {
 case CONST_KIND:
  if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ConstKind->typeSym;
 case PARAM_KIND:
  if (s->kindPtr.ParamKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ParamKind->typeSym;
 case PROC_KIND:
  return ((void *)0);
 case FUNC_KIND:
  if (s->kindPtr.FuncKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.FuncKind->typeSym;
 case TYPE_KIND:
  if (s->kindPtr.TypeKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s;
 case VAR_KIND:
  if (s->kindPtr.VarKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.VarKind->typeSym;
 default:
  err(1, "Unknown kind set on given symbol");
  return ((void *)0);
 }
}

canonical_original_code:
struct Symbol *getTypeSym(struct Symbol *s) {
 if (!s) return ((void *)0);
 switch (s->kind) {
 case CONST_KIND:
  if (s->kindPtr.ConstKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ConstKind->typeSym;
 case PARAM_KIND:
  if (s->kindPtr.ParamKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.ParamKind->typeSym;
 case PROC_KIND:
  return ((void *)0);
 case FUNC_KIND:
  if (s->kindPtr.FuncKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.FuncKind->typeSym;
 case TYPE_KIND:
  if (s->kindPtr.TypeKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s;
 case VAR_KIND:
  if (s->kindPtr.VarKind == ((void *)0)) { err(1, "kindPtr is NULL");};
  return s->kindPtr.VarKind->typeSym;
 default:
  err(1, "Unknown kind set on given symbol");
  return ((void *)0);
 }
}

variable_types:
s
struct Symbol *

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

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

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


isByReference

decompiled_code:
__int64 __fastcall isByReference(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 2 )
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 8LL);
v2 = 0;
if ( v1 == 5 )
v2 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 2 )
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 8LL);
v2 = 0;
if ( v1 == 5 )
v2 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
return v2;
}

original_code:
int isByReference(Symbol *s)
{
 if (!s) return 0;
 if ((s->kind == PARAM_KIND)) return s->kindPtr.ParamKind->byRef;
 if (s->kind == VAR_KIND) return s->kindPtr.VarKind->byRef;
 return 0;
}

canonical_original_code:
int isByReference(struct Symbol *s)
{
 if (!s) return 0;
 if ((s->kind == PARAM_KIND)) return s->kindPtr.ParamKind->byRef;
 if (s->kind == VAR_KIND) return s->kindPtr.VarKind->byRef;
 return 0;
}

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

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

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

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

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

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

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

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


addToSymbolTable

decompiled_code:
__int64 __fastcall addToSymbolTable(__int64 a1, _QWORD *a2)
{
unsigned int v2; // ebp

v2 = createHashElement(a1, *a2, a2);
setSymbolSize(a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _QWORD *a2)
{
unsigned int v2; // ebp

v2 = createHashElement(a1, *a2, a2);
setSymbolSize(a2);
return v2;
}

original_code:
int addToSymbolTable(struct hash *table, Symbol *symbol) {
 int retval = 0;
 retval = createHashElement(table, symbol->name, symbol);
 setSymbolSize(symbol);
 return retval;
}

canonical_original_code:
int addToSymbolTable(struct hash *table, struct Symbol *symbol) {
 int retval = 0;
 retval = createHashElement(table, symbol->name, symbol);
 setSymbolSize(symbol);
 return retval;
}

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:
symbol
struct Symbol *

variable_types: retval int


dumpStmtLL

decompiled_code:
int __fastcall dumpStmtLL(__int64 a1)
{
int result; // eax

if ( a1 )
result = writeStmtLL(stderr, a1);
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int result; // eax

if ( a1 )
result = func0(stderr, a1);
return result;
}

original_code:
void
dumpStmtLL(StmtLL *ll)
{
 if (!ll) return;
 writeStmtLL(stderr, ll);
}

canonical_original_code:
void dumpStmtLL(struct stmtll *ll)
{
 if (!ll) return;
 writeStmtLL(stderr, ll);
}

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


freeStmtLL

decompiled_code:
void __fastcall freeStmtLL(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void
freeStmtLL(StmtLL *ll)
{
 StmtLL *copy;
 while (ll) {
  copy = ll;
  ll = ll->next;
  free(copy->stmt);
  free(copy);
 }
}

canonical_original_code:
void freeStmtLL(struct stmtll *ll)
{
 struct stmtll *copy;
 while (ll) {
  copy = ll;
  ll = ll->next;
  free(copy->stmt);
  free(copy);
 }
}

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


newConstProxySym

decompiled_code:
__int64 __fastcall newConstProxySym(__int64 a1, char *a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // rbx
char v6; // bp
unsigned int v8; // er13
__int64 v9; // rbp
__int64 v10; // rax

if ( !a2 || !a3 )
err(1, "Passed NULL arguments to newConstProxySym");
v4 = createConstSymbol();
v5 = v4;
if ( !v4 )
err(1, "Failed to allocate memory for new constant proxy symbol!");
setInnerTypeSymbol(v4, a3);
**(_DWORD **)(v5 + 16) = 0;
switch ( (unsigned int)getType(a3) )
{
case 2u:
case 4u:
goto LABEL_8;
case 3u:
v6 = *a2;
*(_BYTE *)getConstVal(v5) = v6;
LABEL_8:
*(_DWORD *)getConstVal(v5) = *(_DWORD *)a2;
break;
case 5u:
*(_QWORD *)getConstVal(v5) = *(_QWORD *)a2;
break;
case 9u:
v8 = *((_DWORD *)a2 + 2);
v9 = *(_QWORD *)a2;
v10 = getConstVal(v5);
setStringStr(v10, v9, v8);
break;
default:
err(1, "Called newConstProxySym with invalid typeSym (can't get inner type)");
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // rbx
char v6; // bp
unsigned int v8; // er13
__int64 v9; // rbp
__int64 v10; // rax

if ( !a2 || !a3 )
err(1, "Passed NULL arguments to newConstProxySym");
v4 = createConstSymbol();
v5 = v4;
if ( !v4 )
err(1, "Failed to allocate memory for new constant proxy symbol!");
setInnerTypeSymbol(v4, a3);
**(_DWORD **)(v5 + 16) = 0;
switch ( (unsigned int)getType(a3) )
{
case 2u:
case 4u:
goto LABEL_8;
case 3u:
v6 = *a2;
*(_BYTE *)getConstVal(v5) = v6;
LABEL_8:
*(_DWORD *)getConstVal(v5) = *(_DWORD *)a2;
break;
case 5u:
*(_QWORD *)getConstVal(v5) = *(_QWORD *)a2;
break;
case 9u:
v8 = *((_DWORD *)a2 + 2);
v9 = *(_QWORD *)a2;
v10 = getConstVal(v5);
setStringStr(v10, v9, v8);
break;
default:
err(1, "Called newConstProxySym with invalid typeSym (can't get inner type)");
}
return v5;
}

original_code:
ProxySymbol *newConstProxySym(char *id, void * result, Symbol *typeSym)
{
 Symbol *constSym = ((void *)0);
 double *doubleResult;
 int *intResult;
 char *charResult;
 struct String *stringResult;
 if ((result == ((void *)0)) || (typeSym == ((void *)0))) {
  err(1, "Passed NULL arguments to newConstProxySym");
 }
 constSym = createConstSymbol(id);
 if (!constSym) {
  err(1, "Failed to allocate memory for new constant proxy "
      "symbol!");
 }
 setInnerTypeSymbol(constSym, typeSym);
 constSym->kindPtr.ConstKind->constResultFlag = 0;
 switch (getType(typeSym)) {
 case BOOLEAN_T:
  intResult = (int *) result;
  getConstVal(constSym)->Boolean.value = *intResult;
  break;
 case CHAR_T:
  charResult = (char *) result;
  getConstVal(constSym)->Char.value = *charResult;
 case INTEGER_T:
  intResult = (int *) result;
  getConstVal(constSym)->Integer.value = *intResult;
  break;
 case REAL_T:
  doubleResult = (double *) result;
  getConstVal(constSym)->Real.value = *doubleResult;
  break;
 case STRING_T:
  stringResult = (struct String *) result;
  setStringStr(
      &getConstVal(constSym)->String,
      stringResult->str,
      stringResult->strlen);
  break;
 default:
  err(1, "Called newConstProxySym with invalid "
      "typeSym (can't get inner type)");
 }
 return (ProxySymbol *) constSym;
}

canonical_original_code:
struct Symbol *newConstProxySym(char *id, void *result, struct Symbol *typeSym)
{
 struct Symbol *constSym = ((void *)0);
 double *doubleResult;
 int *intResult;
 char *charResult;
 struct String *stringResult;
 if ((result == ((void *)0)) || (typeSym == ((void *)0))) {
  err(1, "Passed NULL arguments to newConstProxySym");
 }
 constSym = createConstSymbol(id);
 if (!constSym) {
  err(1, "Failed to allocate memory for new constant proxy "
      "symbol!");
 }
 setInnerTypeSymbol(constSym, typeSym);
 constSym->kindPtr.ConstKind->constResultFlag = 0;
 switch (getType(typeSym)) {
 case BOOLEAN_T:
  intResult = (int *) result;
  getConstVal(constSym)->Boolean.value = *intResult;
  break;
 case CHAR_T:
  charResult = (char *) result;
  getConstVal(constSym)->Char.value = *charResult;
 case INTEGER_T:
  intResult = (int *) result;
  getConstVal(constSym)->Integer.value = *intResult;
  break;
 case REAL_T:
  doubleResult = (double *) result;
  getConstVal(constSym)->Real.value = *doubleResult;
  break;
 case STRING_T:
  stringResult = (struct String *) result;
  setStringStr(
      &getConstVal(constSym)->String,
      stringResult->str,
      stringResult->strlen);
  break;
 default:
  err(1, "Called newConstProxySym with invalid "
      "typeSym (can't get inner type)");
 }
 return (struct Symbol *) constSym;
}

variable_types:
id
char *

variable_types:
result
void *

variable_types:
typeSym
struct Symbol *

variable_types:
doubleResult
double *

variable_types:
intResult
int *

variable_types:
charResult
char *

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

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

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

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

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

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


emitBabyTree

decompiled_code:
void __fastcall emitBabyTree(__int64 a1, int a2, __int64 a3)
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 <= 310 )
{
if ( a2 <= 295 )
{
switch ( a2 )
{
case -3:
emitPushRecordFieldAddress(a1, a3);
break;
case -2:
emitArrayElementLocation(a1, a3);
break;
case -4:
if ( a1 )
{
emitFuncInvok(a1, *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL));
}
else if ( a3 )
{
emitFuncInvok(a3, *(_QWORD *)(*(_QWORD *)(a3 + 16) + 8LL));
}
break;
}
}
else
{
switch ( a2 )
{
case 296:
if ( a1 )
emitNot(a1);
else
emitNot(a3);
break;
case 297:
emitMultiplication(a1, a3);
break;
case 298:
emitDivision(a1, a3, 298LL);
break;
case 299:
emitDivision(a1, a3, 299LL);
break;
case 300:
emitMod(a1, a3);
break;
case 301:
emitAnd(a1, a3);
break;
case 302:
if ( a1 && a3 )
{
emitAddition(a1, a3);
}
else if ( a1 )
{
emitUnaryPlus(a1);
}
else
{
emitUnaryPlus(a3);
}
break;
case 303:
if ( a1 && a3 )
{
emitSubtraction(a1, a3);
}
else if ( a1 )
{
emitUnaryMinus(a1);
}
else
{
emitUnaryMinus(a3);
}
break;
case 304:
emitOr(a1, a3);
break;
case 305:
emitEqualsOp(a1, a3);
break;
case 306:
emitInequalityOp(a1, a3);
break;
case 307:
emitLTOp(a1, a3);
break;
case 308:
emitLTEOp(a1, a3);
break;
case 309:
emitGTOp(a1, a3);
break;
case 310:
emitGTEOp(a1, a3);
break;
default:
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, __int64 a3)
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 <= 310 )
{
if ( a2 <= 295 )
{
switch ( a2 )
{
case -3:
emitPushRecordFieldAddress(a1, a3);
break;
case -2:
emitArrayElementLocation(a1, a3);
break;
case -4:
if ( a1 )
{
emitFuncInvok(a1, *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL));
}
else if ( a3 )
{
emitFuncInvok(a3, *(_QWORD *)(*(_QWORD *)(a3 + 16) + 8LL));
}
break;
}
}
else
{
switch ( a2 )
{
case 296:
if ( a1 )
emitNot(a1);
else
emitNot(a3);
break;
case 297:
emitMultiplication(a1, a3);
break;
case 298:
emitDivision(a1, a3, 298LL);
break;
case 299:
emitDivision(a1, a3, 299LL);
break;
case 300:
emitMod(a1, a3);
break;
case 301:
emitAnd(a1, a3);
break;
case 302:
if ( a1 && a3 )
{
emitAddition(a1, a3);
}
else if ( a1 )
{
emitUnaryPlus(a1);
}
else
{
emitUnaryPlus(a3);
}
break;
case 303:
if ( a1 && a3 )
{
emitSubtraction(a1, a3);
}
else if ( a1 )
{
emitUnaryMinus(a1);
}
else
{
emitUnaryMinus(a3);
}
break;
case 304:
emitOr(a1, a3);
break;
case 305:
emitEqualsOp(a1, a3);
break;
case 306:
emitInequalityOp(a1, a3);
break;
case 307:
emitLTOp(a1, a3);
break;
case 308:
emitLTEOp(a1, a3);
break;
case 309:
emitGTOp(a1, a3);
break;
case 310:
emitGTEOp(a1, a3);
break;
default:
return;
}
}
}
}

original_code:
void emitBabyTree(Symbol *x, int opToken, Symbol *y) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (opToken) {
 case 305:
  emitEqualsOp(x, y);
  break;
 case 306:
  emitInequalityOp(x, y);
  break;
 case 308:
  emitLTEOp(x, y);
  break;
 case 307:
  emitLTOp(x, y);
  break;
 case 310:
  emitGTEOp(x, y);
  break;
 case 309:
  emitGTOp(x, y);
  break;
 case 302:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryPlus(y);
   }
   else {
    emitUnaryPlus(x);
   }
  }
  else {
   emitAddition(x, y);
  }
  break;
 }
 case 303:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryMinus(y);
   }
   else {
    emitUnaryMinus(x);
   }
  }
  else {
   emitSubtraction(x, y);
  }
  break;
 }
 case 304:
  emitOr(x, y);
  break;
 case 298:
  emitDivision(x, y, opToken);
  break;
 case 299:
  emitDivision(x, y, opToken);
  break;
 case 297:
  emitMultiplication(x, y);
  break;
 case 300:
  emitMod(x, y);
  break;
 case 301:
  emitAnd(x, y);
  break;
 case 296:
  if (x) emitNot(x);
  else emitNot(y);
  break;
 case -2:
  emitArrayElementLocation(x, y);
  break;
 case -3:
  emitPushRecordFieldAddress(x, y);
  break;
 case -4:
 {
  if (x) {
   emitFuncInvok(x, x->kindPtr.FuncKind->params);
  } else if (y) {
   emitFuncInvok(y, y->kindPtr.FuncKind->params);
  }
  break;
 }
 default:
  break;
 }
}

canonical_original_code:
void emitBabyTree(struct Symbol *x, int opToken, struct Symbol *y) {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 switch (opToken) {
 case 305:
  emitEqualsOp(x, y);
  break;
 case 306:
  emitInequalityOp(x, y);
  break;
 case 308:
  emitLTEOp(x, y);
  break;
 case 307:
  emitLTOp(x, y);
  break;
 case 310:
  emitGTEOp(x, y);
  break;
 case 309:
  emitGTOp(x, y);
  break;
 case 302:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryPlus(y);
   }
   else {
    emitUnaryPlus(x);
   }
  }
  else {
   emitAddition(x, y);
  }
  break;
 }
 case 303:
 {
  if ( (!x) || (!y) ) {
   if (!x) {
    emitUnaryMinus(y);
   }
   else {
    emitUnaryMinus(x);
   }
  }
  else {
   emitSubtraction(x, y);
  }
  break;
 }
 case 304:
  emitOr(x, y);
  break;
 case 298:
  emitDivision(x, y, opToken);
  break;
 case 299:
  emitDivision(x, y, opToken);
  break;
 case 297:
  emitMultiplication(x, y);
  break;
 case 300:
  emitMod(x, y);
  break;
 case 301:
  emitAnd(x, y);
  break;
 case 296:
  if (x) emitNot(x);
  else emitNot(y);
  break;
 case -2:
  emitArrayElementLocation(x, y);
  break;
 case -3:
  emitPushRecordFieldAddress(x, y);
  break;
 case -4:
 {
  if (x) {
   emitFuncInvok(x, x->kindPtr.FuncKind->params);
  } else if (y) {
   emitFuncInvok(y, y->kindPtr.FuncKind->params);
  }
  break;
 }
 default:
  break;
 }
}

variable_types: opToken int

variable_types:
y
struct Symbol *

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

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

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

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

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

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

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

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


postOrderWalk

decompiled_code:
__int64 __fastcall postOrderWalk(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // rax

if ( a1[3] )
{
if ( *((_DWORD *)a1 + 2) == -3 )
{
v4 = ((__int64 (*)(void))postOrderWalk)();
emitBabyTree(v4, *((_DWORD *)a1 + 2), *a1);
}
else
{
v1 = ((__int64 (*)(void))postOrderWalk)();
v2 = postOrderWalk(a1[4]);
emitBabyTree(v1, *((_DWORD *)a1 + 2), v2);
}
result = *a1;
}
else
{
if ( *((_DWORD *)a1 + 2) == -4 )
{
emitBabyTree(*a1, -4, 0LL);
*a1 = getTypeSym(*a1);
}
result = *a1;
}
return result;
}

original_code:
Symbol *postOrderWalk(struct treeNode *node) {
 Symbol *x = ((void *)0);
 Symbol *y = ((void *)0);
 if (node->left == ((void *)0)) {
  if (node->opToken == -4) {
   emitBabyTree(node->symbol, node->opToken, ((void *)0));
   node->symbol = getTypeSym(node->symbol);
  }
  return node->symbol;
 } else if (node->opToken == -3) {
  x = postOrderWalk(node->left);
  emitBabyTree(x, node->opToken, node->symbol);
  return node->symbol;
 } else {
  x = postOrderWalk(node->left);
  y = postOrderWalk(node->right);
  emitBabyTree(x, node->opToken, y);
  return node->symbol;
 }
}

canonical_original_code:
struct Symbol *postOrderWalk(struct treeNode *node) {
 struct Symbol *x = ((void *)0);
 struct Symbol *y = ((void *)0);
 if (node->left == ((void *)0)) {
  if (node->opToken == -4) {
   emitBabyTree(node->symbol, node->opToken, ((void *)0));
   node->symbol = getTypeSym(node->symbol);
  }
  return node->symbol;
 } else if (node->opToken == -3) {
  x = postOrderWalk(node->left);
  emitBabyTree(x, node->opToken, node->symbol);
  return node->symbol;
 } else {
  x = postOrderWalk(node->left);
  y = postOrderWalk(node->right);
  emitBabyTree(x, node->opToken, y);
  return node->symbol;
 }
}

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

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

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

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

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

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

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

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

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


allocateTreeNode

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

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

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

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

original_code:
struct treeNode *allocateTreeNode() {
 struct treeNode *node = calloc(1, sizeof(struct treeNode));
 if ( node == ((void *)0) ) {
  err(1, "Could not alloc memory for tree node.");
  exit(1);
 }
 return node;
}

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

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

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


createErrorString

decompiled_code:
int __fastcall createErrorString(char **a1, const char **a2)
{
size_t v2; // rbp
char *v3; // rax

v2 = strlen(*a2) + 64;
v3 = (char *)calloc(1uLL, v2);
*a1 = v3;
if ( !v3 )
err(1, "Failed to allocate memory to create err msg");
return snprintf(v3, v2, "Error: %s (line %d, col %d)", *a2, *((unsigned int *)a2 + 2), *((unsigned int *)a2 + 3));
}

canonical_decompiled_code:
int __fastcall func0(char **a1, const char **a2)
{
size_t v2; // rbp
char *v3; // rax

v2 = strlen(*a2) + 64;
v3 = (char *)calloc(1uLL, v2);
*a1 = v3;
if ( !v3 )
err(1, "Failed to allocate memory to create err msg");
return snprintf(v3, v2, "Error: %s (line %d, col %d)", *a2, *((unsigned int *)a2 + 2), *((unsigned int *)a2 + 3));
}

original_code:
void createErrorString(char **buf, struct Error *e)
{
 int extraChars = 64;
 size_t size = sizeof(char)*(strlen(e->msg) + extraChars);
 if (!e) return;
 *buf = calloc(1, size);
 if (!*buf) {
  err(1, "Failed to allocate memory to create err msg");
  return;
 }
 snprintf(*buf, size, "Error: %s (line %d, col %d)",
   e->msg, e->lineno, e->colno);
}

canonical_original_code:
void createErrorString(char **buf, struct Error *e)
{
 int extraChars = 64;
 unsigned long size = sizeof(char)*(strlen(e->msg) + extraChars);
 if (!e) return;
 *buf = calloc(1, size);
 if (!*buf) {
  err(1, "Failed to allocate memory to create err msg");
  return;
 }
 snprintf(*buf, size, "Error: %s (line %d, col %d)",
   e->msg, e->lineno, e->colno);
}

variable_types:
buf
char **

variable_types: struct Error { char *msg; int lineno; int colno; enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 } type; } *

variable_types: extraChars int

variable_types:
size
unsigned long

user_defined_types: struct Error { char *msg; int lineno; int colno; enum ErrorType type; }


customErrorString

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

va_start(arg, format);
vsnprintf(msg_0, 0x3FFuLL, format, arg);
byte_69F = 0;
return msg_0;
}

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

va_start(arg, format);
vsnprintf(msg_0, 0x3FFuLL, format, arg);
byte_69F = 0;
return msg_0;
}

original_code:
char *
customErrorString(char * errMsg, ...)
{
 static char msg[1024];
 va_list args;
 __builtin_va_start(args,errMsg);
 vsnprintf(msg, 1024 -1, errMsg, args);
 __builtin_va_end(args);
 msg[1024 - 1] = '\0';
 return msg;
}

canonical_original_code:
char *customErrorString(char *errMsg, ...)
{
 static char msg[1024];
 __builtin_va_list args;
 __builtin_va_start(args,errMsg);
 vsnprintf(msg, 1024 -1, errMsg, args);
 __builtin_va_end(args);
 msg[1024 - 1] = '\0';
 return msg;
}

variable_types:
errMsg
char *

variable_types:
msg
char [1024]

return_type: char *


freeError

decompiled_code:
void __fastcall freeError(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void freeError(struct Error *e)
{
 if (!e) return;
 if (e->msg) free(e->msg);
 free(e);
}

user_defined_types: enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 }


getErrorTypeString

decompiled_code:
const char *__fastcall getErrorTypeString(int a1)
{
const char *result; // rax

result = "Syntax";
if ( a1 != 1 )
{
result = "Semantic";
if ( a1 != 2 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(int a1)
{
const char *result; // rax

result = "Syntax";
if ( a1 != 1 )
{
result = "Semantic";
if ( a1 != 2 )
result = 0LL;
}
return result;
}

original_code:
char *getErrorTypeString(enum ErrorType type)
{
 if (type == SYNTAX) {
  return "Syntax";
 } else if (type == SEMANTIC) {
  return "Semantic";
 } else {
  return ((void *)0);
 }
}

variable_types: enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 }


printError

decompiled_code:
void __fastcall printError(__int64 a1)
{
unsigned int v1; // ebp
const char *v2; // rax

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 8);
v2 = getErrorTypeString(*(_DWORD *)(a1 + 16));
fprintf(stdout, "%d %s Error: %s (%d, %d)\n", v1, v2, *(const char **)a1, v1, *(unsigned int *)(a1 + 12));
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
unsigned int v1; // ebp
const char *v2; // rax

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 8);
v2 = func3(*(_DWORD *)(a1 + 16));
fprintf(stdout, "%d %s Error: %s (%d, %d)\n", v1, v2, *(const char **)a1, v1, *(unsigned int *)(a1 + 12));
}
}

original_code:
void printError(struct Error *e)
{
 if (!e) return;
 fprintf(stdout, "%d %s Error: %s (%d, %d)\n",
     e->lineno,
     getErrorTypeString(e->type),
     e->msg,
     e->lineno,
     e->colno);
}


opError

decompiled_code:
__int64 __fastcall opError(const char *a1, int a2, const char *a3)
{
__int64 *v4; // rax
__int64 v5; // rax

v4 = opToString(a2);
v5 = customErrorString(
"Invalid expression. Types %s and %s not compatible with operator %s",
a1,
a3,
(const char *)v4);
return recordError(v5, yylineno, colno, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, int a2, const char *a3)
{
__int64 *v4; // rax
__int64 v5; // rax

v4 = opToString(a2);
v5 = customErrorString(
"Invalid expression. Types %s and %s not compatible with operator %s",
a1,
a3,
(const char *)v4);
return recordError(v5, yylineno, colno, 2LL);
}

original_code:
void
opError(char *xType, int op, char *yType)
{
 errMsg = customErrorString("Invalid expression. Types %s and %s"
     " not compatible with operator %s", xType, yType,
     opToString(op));
 recordError(errMsg, yylineno, colno, SEMANTIC);
}

variable_types:
xType
char *

variable_types: op int

variable_types:
yType
char *


alreadyDefinedError

decompiled_code:
__int64 __fastcall alreadyDefinedError(const char *a1)
{
__int64 v1; // rax

v1 = customErrorString("The identifer %s is already defined at the current scope.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 v1; // rax

v1 = customErrorString("The identifer %s is already defined at the current scope.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

original_code:
void
alreadyDefinedError(char *id) {
 errMsg = customErrorString("The identifer %s is already defined at "
    "the current scope.", id);
 recordError(errMsg, yylineno, colno, SEMANTIC);
}

variable_types:
id
char *


notDefinedError

decompiled_code:
__int64 __fastcall notDefinedError(const char *a1)
{
__int64 v1; // rax

v1 = customErrorString("The identifier %s is undefined.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

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

v1 = customErrorString("The identifier %s is undefined.", a1);
return recordError(v1, yylineno, colno, 2LL);
}

original_code:
void
notDefinedError(char *id) {
 errMsg = customErrorString("The identifier %s is undefined.", id);
 recordError(errMsg, yylineno, colno, SEMANTIC);
}


symbolTableInsertFailure

decompiled_code:
void __noreturn symbolTableInsertFailure()
{
err(1, "Failed to insert into symbol table.");
}

canonical_decompiled_code:
void __noreturn func3()
{
err(1, "Failed to insert into symbol table.");
}

original_code:
void symbolTableInsertFailure() {
 err(1, "Failed to insert into symbol table.");
}


isLogicalOperator

decompiled_code:
_BOOL8 __fastcall isLogicalOperator(int a1)
{
_BOOL8 result; // rax

if ( (unsigned int)(a1 - 296) > 8 )
result = 0LL;
else
result = ((1LL << ((unsigned __int8)a1 - 40)) & 0x121) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1)
{
_BOOL8 result; // rax

if ( (unsigned int)(a1 - 296) > 8 )
result = 0LL;
else
result = ((1LL << ((unsigned __int8)a1 - 40)) & 0x121) != 0;
return result;
}

original_code:
int
isLogicalOperator(int op)
{
 switch (op) {
 case 296:
 case 301:
 case 304:
  return 1;
 default:
  return 0;
 }
}


isRelationalOperator

decompiled_code:
_BOOL8 __fastcall isRelationalOperator(int a1)
{
return (unsigned int)(a1 - 305) <= 5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1)
{
return (unsigned int)(a1 - 305) <= 5;
}

original_code:
int
isRelationalOperator(int op)
{
 switch (op) {
 case 305:
 case 306:
 case 307:
 case 308:
 case 309:
 case 310:
  return 1;
 default:
  return 0;
 }
}


isUnaryOperator

decompiled_code:
__int64 __fastcall isUnaryOperator(int a1)
{
return (a1 == 296) | (unsigned __int8)((unsigned int)(a1 - 302) <= 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return (a1 == 296) | (unsigned __int8)((unsigned int)(a1 - 302) <= 1);
}

original_code:
int
isUnaryOperator(int op)
{
 if ( (op == 302) ||
  (op == 303) ||
     (op == 296) ) {
  return 1;
 }
 return 0;
}


getStrlen

decompiled_code:
__int64 __fastcall getStrlen(__int64 a1, __int64 a2)
{
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
return a2;
}

original_code:
int getStrlen(struct String s)
{
 return s.strlen;
}

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


checkErrnoStrtoX

decompiled_code:
int *checkErrnoStrtoX()
{
int *result; // rax
char *v1; // rax
__int64 v2; // rax

result = _errno_location();
if ( *result )
{
v1 = strerror(*result);
v2 = customErrorString("Error parsing numerical constant: %s", v1);
result = (int *)recordError(v2, yylineno, colno, 2LL);
}
return result;
}

canonical_decompiled_code:
int *func8()
{
int *result; // rax
char *v1; // rax
__int64 v2; // rax

result = _errno_location();
if ( *result )
{
v1 = strerror(*result);
v2 = customErrorString("Error parsing numerical constant: %s", v1);
result = (int *)recordError(v2, yylineno, colno, 2LL);
}
return result;
}

original_code:
void checkErrnoStrtoX() {
 if ((*__errno_location ()) != 0) {
  errMsg = customErrorString("Error parsing numerical constant: "
      "%s", strerror((*__errno_location ())));
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
}


freeErrorList

decompiled_code:
void __fastcall freeErrorList(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
freeError(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
freeError(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void
freeErrorList(struct ErrorLL *ell)
{
 struct ErrorLL *copy;
 while (ell) {
  copy = ell;
  ell = ell->next;
  freeError(copy->error);
  free(copy);
 }
}

variable_types: struct ErrorLL { struct Error { char *msg; int lineno; int colno; enum ErrorType { GENERIC=0, SYNTAX=1, SEMANTIC=2 } type; } *error; struct ErrorLL *next; } *

user_defined_types: struct ErrorLL { struct Error *error; struct ErrorLL *next; }


growElementArray

decompiled_code:
void __fastcall growElementArray(__int64 a1)
{
int v1; // eax
void *v2; // rax

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = 2 * v1;
v2 = realloc(*(void **)a1, 8LL * (unsigned int)(2 * v1));
*(_QWORD *)a1 = v2;
if ( !v2 )
err(1, "Failled reallocate memory to grow elements array!");
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
int v1; // eax
void *v2; // rax

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = 2 * v1;
v2 = realloc(*(void **)a1, 8LL * (unsigned int)(2 * v1));
*(_QWORD *)a1 = v2;
if ( !v2 )
err(1, "Failled reallocate memory to grow elements array!");
}
}

original_code:
void
growElementArray(struct ElementArray *ea)
{
 if (!ea) {
  return;
 }
 ea->len = (ea->len) * 2;
 ea->data = realloc(ea->data,sizeof(void *)*(ea->len));
 if (!ea->data) {
  err(1, "Failled reallocate memory to grow elements array!");
  exit(1);
 }
}

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


appendElement

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

if ( *(_DWORD *)(a1 + 12) == *(_DWORD *)(a1 + 8) - 1 )
growElementArray(a1);
result = *(_QWORD *)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)(*(_DWORD *)(a1 + 12))++) = a2;
return result;
}

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

if ( *(_DWORD *)(a1 + 12) == *(_DWORD *)(a1 + 8) - 1 )
func0(a1);
result = *(_QWORD *)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)(*(_DWORD *)(a1 + 12))++) = a2;
return result;
}

original_code:
void
appendElement(struct ElementArray *ea, void *element)
{
 if (ea->nElements == (ea->len - 1)) {
  growElementArray(ea);
 }
 ea->data[ea->nElements] = element;
 ea->nElements++;
}

variable_types:
element
void *

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


hasDuplicateElement

decompiled_code:
__int64 __fastcall hasDuplicateElement(__int64 a1)
{
__int64 result; // rax
const char ***v2; // r15
__int64 v3; // r13
const char ***v4; // r14
const char *v5; // r12
const char ***v6; // rbx
int v7; // ebp

if ( !a1 )
err(1, "Cannot check duplicate elements in element due to NULL pointer!");
result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
{
v2 = *(const char ****)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(result - 1) + 8;
v4 = *(const char ****)a1;
while ( 2 )
{
v5 = **v4;
v6 = v2;
v7 = 0;
do
{
v7 += strcmp(v5, **v6) == 0;
if ( v7 > 1 )
return 1LL;
++v6;
}
while ( v6 != (const char ***)v3 );
if ( ++v4 != (const char ***)v3 )
continue;
break;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
const char ***v2; // r15
__int64 v3; // r13
const char ***v4; // r14
const char *v5; // r12
const char ***v6; // rbx
int v7; // ebp

if ( !a1 )
err(1, "Cannot check duplicate elements in element due to NULL pointer!");
result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
{
v2 = *(const char ****)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(result - 1) + 8;
v4 = *(const char ****)a1;
while ( 2 )
{
v5 = **v4;
v6 = v2;
v7 = 0;
do
{
v7 += strcmp(v5, **v6) == 0;
if ( v7 > 1 )
return 1LL;
++v6;
}
while ( v6 != (const char ***)v3 );
if ( ++v4 != (const char ***)v3 )
continue;
break;
}
result = 0LL;
}
return result;
}

original_code:
int
hasDuplicateElement(struct ElementArray *ea){
 int i,j,count;
 Symbol *sym1;
 Symbol *sym2;
 if(!ea){
  err(1, "Cannot check duplicate elements in element due to NULL pointer!");
  exit(1);
 }
 for(i=0; i<(ea->nElements); i++){
  count = 0;
  sym1 = ((Symbol **)ea->data)[i];
  for(j =0; j <(ea->nElements); j++){
   sym2 = ((Symbol **)ea->data)[j];
   if(strcmp(sym1->name,sym2->name)==0){
    count++;
   }
   if(count >=2){
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int hasDuplicateElement(struct ElementArray *ea){
 int i; int j; int count;
 struct Symbol *sym1;
 struct Symbol *sym2;
 if(!ea){
  err(1, "Cannot check duplicate elements in element due to NULL pointer!");
  exit(1);
 }
 for(i=0; i<(ea->nElements); i++){
  count = 0;
  sym1 = ((struct Symbol **)ea->data)[i];
  for(j =0; j <(ea->nElements); j++){
   sym2 = ((struct Symbol **)ea->data)[j];
   if(strcmp(sym1->name,sym2->name)==0){
    count++;
   }
   if(count >=2){
    return 1;
   }
  }
 }
 return 0;
}

variable_types: i int

variable_types: j int

variable_types: count int

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

user_defined_types: 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 hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }


appendElementArray

decompiled_code:
__int64 __fastcall appendElementArray(__int64 a1, _DWORD *a2)
{
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // esi
void *v6; // rax
__int64 v7; // rax

if ( !a1 || !a2 )
err(1, "One of the element arrays is a null pointer!");
v3 = *(_DWORD *)(a1 + 12);
v4 = v3;
v5 = *(_DWORD *)(a1 + 8) + a2[2];
*(_DWORD *)(a1 + 8) = v5;
*(_DWORD *)(a1 + 12) = a2[3] + v3;
v6 = realloc(*(void **)a1, 8LL * v5);
*(_QWORD *)a1 = v6;
if ( !v6 )
err(1, "Failled reallocate memory to grow elements array!");
if ( v3 < *(_DWORD *)(a1 + 12) )
{
v7 = 8LL * (int)v3;
do
{
*(_QWORD *)(*(_QWORD *)a1 + v7) = *(_QWORD *)(*(_QWORD *)a2 + v7 - 8LL * (int)v3);
++v4;
v7 += 8LL;
}
while ( *(_DWORD *)(a1 + 12) > v4 );
}
free(a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // esi
void *v6; // rax
__int64 v7; // rax

if ( !a1 || !a2 )
err(1, "One of the element arrays is a null pointer!");
v3 = *(_DWORD *)(a1 + 12);
v4 = v3;
v5 = *(_DWORD *)(a1 + 8) + a2[2];
*(_DWORD *)(a1 + 8) = v5;
*(_DWORD *)(a1 + 12) = a2[3] + v3;
v6 = realloc(*(void **)a1, 8LL * v5);
*(_QWORD *)a1 = v6;
if ( !v6 )
err(1, "Failled reallocate memory to grow elements array!");
if ( v3 < *(_DWORD *)(a1 + 12) )
{
v7 = 8LL * (int)v3;
do
{
*(_QWORD *)(*(_QWORD *)a1 + v7) = *(_QWORD *)(*(_QWORD *)a2 + v7 - 8LL * (int)v3);
++v4;
v7 += 8LL;
}
while ( *(_DWORD *)(a1 + 12) > v4 );
}
free(a2);
return a1;
}

original_code:
struct ElementArray *
appendElementArray(struct ElementArray *ea1, struct ElementArray *ea2){
 int i ;
 int appendIndex ;
 if(!ea1 || !ea2){
  err(1, "One of the element arrays is a null pointer!");
  exit(1);
 }
 appendIndex = ea1->nElements;
 ea1->len += ea2->len;
 ea1->nElements += ea2->nElements;
 ea1->data = realloc(ea1->data,sizeof(void *)*(ea1->len));
 if(!ea1->data){
  err(1, "Failled reallocate memory to grow elements array!");
  exit(1);
 }
 for(i= appendIndex; i < ea1->nElements ; i++ ){
  ea1->data[i] = ea2->data[i-appendIndex];
 }
 free(ea2);
 return ea1;
}

canonical_original_code:
struct ElementArray *appendElementArray(struct ElementArray *ea1, struct ElementArray *ea2){
 int i;
 int appendIndex;
 if(!ea1 || !ea2){
  err(1, "One of the element arrays is a null pointer!");
  exit(1);
 }
 appendIndex = ea1->nElements;
 ea1->len += ea2->len;
 ea1->nElements += ea2->nElements;
 ea1->data = realloc(ea1->data,sizeof(void *)*(ea1->len));
 if(!ea1->data){
  err(1, "Failled reallocate memory to grow elements array!");
  exit(1);
 }
 for(i= appendIndex; i < ea1->nElements ; i++ ){
  ea1->data[i] = ea2->data[i-appendIndex];
 }
 free(ea2);
 return ea1;
}

variable_types: appendIndex int

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


getElementAt

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

if ( *(_DWORD *)(a1 + 12) - 1 < a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 12) - 1 < a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
void *
getElementAt(struct ElementArray *ea, unsigned int i)
{
 if (i > (ea->nElements-1)) {
  return ((void *)0);
 }
 return ea->data[i];
}

canonical_original_code:
void *getElementAt(struct ElementArray *ea, unsigned int i)
{
 if (i > (ea->nElements-1)) {
  return ((void *)0);
 }
 return ea->data[i];
}

variable_types:
i
unsigned int

return_type: void *


freeElementArray

decompiled_code:
void __fastcall freeElementArray(void *ptr)
{
__int64 v1; // rbx

if ( *((_DWORD *)ptr + 3) != 1 )
{
v1 = 0LL;
do
{
if ( !*(_QWORD *)(*(_QWORD *)ptr + 8 * v1) )
{
free(newElementArray);
free(*(void **)(*(_QWORD *)ptr + 8 * v1));
}
++v1;
}
while ( *((_DWORD *)ptr + 3) - 1 > (unsigned int)v1 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
__int64 v1; // rbx

if ( *((_DWORD *)ptr + 3) != 1 )
{
v1 = 0LL;
do
{
if ( !*(_QWORD *)(*(_QWORD *)ptr + 8 * v1) )
{
free(newElementArray);
free(*(void **)(*(_QWORD *)ptr + 8 * v1));
}
++v1;
}
while ( *((_DWORD *)ptr + 3) - 1 > (unsigned int)v1 );
}
free(ptr);
}

original_code:
void freeElementArray(struct ElementArray *ea) {
 int i;
 for (i = 0; i < (ea->nElements-1); i++) {
  if(!ea->data[i]){
   free(((Symbol **)ea->data)[i]->name);
   free(ea->data[i]);
  }
 }
 free(ea);
}

canonical_original_code:
void freeElementArray(struct ElementArray *ea) {
 int i;
 for (i = 0; i < (ea->nElements-1); i++) {
  if(!ea->data[i]){
   free(((struct Symbol **)ea->data)[i]->name);
   free(ea->data[i]);
  }
 }
 free(ea);
}

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

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

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

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

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

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


emitAnd

decompiled_code:
void __fastcall emitAnd(__int64 a1, __int64 a2)
{
int v2[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( !a1 || doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
emitLogicalPrep(a1, a2, v2);
if ( v2[0] == 1 )
emitStmt(128LL, &unk_1B0);
}
else
{
doNotEmit = 1;
}
}

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

if ( !a1 || doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
func0(a1, a2, v2);
if ( v2[0] == 1 )
emitStmt(128LL, &unk_1B0);
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitAnd(Symbol *x, Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "AND");
  break;
 case -1:
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitAnd(struct Symbol *x, struct Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "AND");
  break;
 case -1:
  break;
 default:
  break;
 }
}

variable_types:
y
struct Symbol *

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

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

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

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


emitOr

decompiled_code:
void __fastcall emitOr(__int64 a1, __int64 a2)
{
int v2[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( !a1 || doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
emitLogicalPrep(a1, a2, v2);
if ( v2[0] == 1 )
emitStmt(128LL, &unk_1B4);
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
int v2[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( !a1 || doNotEmit )
{
doNotEmit = 1;
}
else if ( a2 )
{
func0(a1, a2, v2);
if ( v2[0] == 1 )
emitStmt(128LL, &unk_1B4);
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitOr(Symbol *x, Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "OR");
  break;
 case -1:
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitOr(struct Symbol *x, struct Symbol *y)
{
 int opType;
 do { if(!(x) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 do { if(!(y) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitLogicalPrep(x, y, &opType);
 switch (opType) {
 case 1:
  emitStmt(128, "OR");
  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: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

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

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

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

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

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

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


initialize

decompiled_code:
__int64 initialize()
{
symbolTable = createHash(&getHashedKeyNormal);
if ( !symbolTable )
err(1, "Could not create symbolTable.");
preDefTypeSymbols = initializePreDefTypes();
if ( !preDefTypeSymbols )
err(1, "Could not create pre-defined types.");
stmts = 0LL;
emitInit();
initializePreDefProc();
initializePreDefFunc();
initializePreDefConstants();
errors = 0LL;
whileLoopDepth = 0LL;
labelStack = newLabelStack();
loopLabelStack = newLabelStack();
procOrFuncStack = newLabelStack();
mainLabelStack = newLabelStack();
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
symbolTable = createHash(&getHashedKeyNormal);
if ( !symbolTable )
err(1, "Could not create symbolTable.");
preDefTypeSymbols = initializePreDefTypes();
if ( !preDefTypeSymbols )
err(1, "Could not create pre-defined types.");
stmts = 0LL;
emitInit();
initializePreDefProc();
initializePreDefFunc();
initializePreDefConstants();
errors = 0LL;
whileLoopDepth = 0LL;
labelStack = newLabelStack();
loopLabelStack = newLabelStack();
procOrFuncStack = newLabelStack();
mainLabelStack = newLabelStack();
return 0LL;
}

original_code:
int initialize() {
 symbolTable = createHash(&getHashedKeyNormal);
 if (symbolTable == ((void *)0)) {
  err(1, "Could not create symbolTable.");
  exit(1);
 }
 preDefTypeSymbols = initializePreDefTypes();
 if (preDefTypeSymbols == ((void *)0)) {
  err(1, "Could not create pre-defined types.");
  exit(1);
 }
 stmts = ((void *)0);
 emitInit();
 initializePreDefProc();
 initializePreDefFunc();
 initializePreDefConstants();
 errors = ((void *)0);
 whileLoopDepth = 0;
 labelStack = newLabelStack();
 loopLabelStack = newLabelStack();
 procOrFuncStack = newLabelStack();
 mainLabelStack = newLabelStack();
 return 0;
}


deInitialize

decompiled_code:
__int64 deInitialize()
{
destroyHash(&symbolTable);
destroyLabelStack(&labelStack);
destroyLabelStack(&loopLabelStack);
destroyLabelStack(&procOrFuncStack);
freeStmtLL(stmts);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
destroyHash(&symbolTable);
destroyLabelStack(&labelStack);
destroyLabelStack(&loopLabelStack);
destroyLabelStack(&procOrFuncStack);
freeStmtLL(stmts);
return 0LL;
}

original_code:
int deInitialize() {
 destroyHash(&symbolTable);
 destroyLabelStack(&labelStack);
 destroyLabelStack(&loopLabelStack);
 destroyLabelStack(&procOrFuncStack);
 freeStmtLL(stmts);
 return 0;
}


emitPreDefCode

decompiled_code:
__int64 emitPreDefCode()
{
emitBlankLine();
emitSepLine();
emitBlankLine();
emitComment("Pre-defined ASC functions to follow");
emitBlankLine();
emitSepLine();
emitBlankLine();
return emitPreDefAsc();
}

canonical_decompiled_code:
__int64 func0()
{
emitBlankLine();
emitSepLine();
emitBlankLine();
emitComment("Pre-defined ASC functions to follow");
emitBlankLine();
emitSepLine();
emitBlankLine();
return emitPreDefAsc();
}

original_code:
void emitPreDefCode() {
 emitBlankLine();
 emitSepLine();
 emitBlankLine();
 emitComment("Pre-defined ASC functions to follow");
 emitBlankLine();
 emitSepLine();
 emitBlankLine();
 emitPreDefAsc();
}


emitInit

decompiled_code:
__int64 emitInit()
{
emitComment("ASC code generated by Yet Another CMPUT415 Compiler.");
emitComment("May the Force be ever in your favour, Mr. Potter.");
emitComment("CMPUT 415 - Fall 2013");
return emitBlankLine();
}

canonical_decompiled_code:
__int64 func2()
{
emitComment("ASC code generated by Yet Another CMPUT415 Compiler.");
emitComment("May the Force be ever in your favour, Mr. Potter.");
emitComment("CMPUT 415 - Fall 2013");
return emitBlankLine();
}

original_code:
void emitInit() {
 emitComment("ASC code generated by Yet Another CMPUT415 Compiler.");
 emitComment("May the Force be ever in your favour, Mr. Potter.");
 emitComment("CMPUT 415 - Fall 2013");
 emitBlankLine();
}


forkAndRun

decompiled_code:
__int64 __fastcall forkAndRun(__int64 a1)
{
__pid_t v1; // eax
__int64 result; // rax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

stat_loc = 0;
v1 = fork();
if ( !v1 )
{
execlp(ASC_FEXE_NAME, ASC_FEXE_NAME, a1, 0LL);
exit(1);
}
waitpid(v1, &stat_loc, 0);
result = (unsigned int)stat_loc;
if ( (stat_loc & 0x7F) == 0 )
{
if ( BYTE1(stat_loc) )
{
fwrite(
"Failed to launch ASC interpreter, or ASC interpreter returned with error status.\n",
1uLL,
0x51uLL,
stderr);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__pid_t v1; // eax
__int64 result; // rax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

stat_loc = 0;
v1 = fork();
if ( !v1 )
{
execlp(ASC_FEXE_NAME, ASC_FEXE_NAME, a1, 0LL);
exit(1);
}
waitpid(v1, &stat_loc, 0);
result = (unsigned int)stat_loc;
if ( (stat_loc & 0x7F) == 0 )
{
if ( BYTE1(stat_loc) )
{
fwrite(
"Failed to launch ASC interpreter, or ASC interpreter returned with error status.\n",
1uLL,
0x51uLL,
stderr);
exit(1);
}
}
return result;
}

original_code:
static void forkAndRun(char *ascFileName)
{
 int status = 0;
 pid_t pid;
 pid = fork();
 if (pid == 0) {
  execlp(ASC_FEXE_NAME, ASC_FEXE_NAME, ascFileName, (char *)0);
  exit(1);
 } else {
  waitpid(pid, &status, 0);
  if (((((status) & 0x7f) == 0))
      && ((((status) & 0xff00) >> 8) != 0)) {
   fprintf(stderr,"Failed to launch ASC interpreter, or "
       "ASC interpreter returned with error status.\n");
   exit(1);
  }
 }
}

canonical_original_code:
static void forkAndRun(char *ascFileName)
{
 int status = 0;
 int pid;
 pid = fork();
 if (pid == 0) {
  execlp(ASC_FEXE_NAME, ASC_FEXE_NAME, ascFileName, (char *)0);
  exit(1);
 } else {
  waitpid(pid, &status, 0);
  if (((((status) & 0x7f) == 0))
      && ((((status) & 0xff00) >> 8) != 0)) {
   fprintf(stderr,"Failed to launch ASC interpreter, or "
       "ASC interpreter returned with error status.\n");
   exit(1);
  }
 }
}

variable_types:
ascFileName
char *

variable_types: status int

variable_types: pid int


parseInputs

decompiled_code:
__int64 __fastcall parseInputs(int argc, char **argv, __int64 a3)
{
unsigned int v5; // ebx
unsigned int v6; // ebx
int v7; // eax
__int64 v8; // rsi
__int64 v9; // r15
const char **v10; // r14
char **v11; // rbp
__int64 v12; // rbp
__int64 v13; // rax
int v15; // [rsp+Ch] [rbp-4Ch]
int v16; // [rsp+10h] [rbp-48h]
int v17; // [rsp+14h] [rbp-44h]
int v18; // [rsp+18h] [rbp-40h]
int v19; // [rsp+1Ch] [rbp-3Ch]

opterr = 0;
v16 = 0;
v15 = 0;
v18 = 0;
v19 = 0;
v17 = 0;
while ( 2 )
{
v5 = getopt(argc, argv, "Snaqc");
if ( v5 == -1 )
{
v7 = optind;
if ( optind >= argc )
{
puts("Missing file name argument.");
}
else
{
v8 = 8LL * optind;
v9 = *(__int64 *)((char *)argv + v8);
++optind;
if ( v7 + 1 < argc )
{
v10 = (const char **)((char *)argv + v8 + 8);
v11 = &(&argv[argc - v7 - 2])[(__int64)v7 + 2];
do
{
v8 = (__int64)*v10;
printf("Non-option argument %s\n", *v10++);
}
while ( v10 != (const char **)v11 );
}
v12 = getListingFileName(v9, v8);
if ( v12 )
{
v13 = getAscFileName(v9);
if ( v13 )
{
*(_DWORD *)a3 = v17;
*(_DWORD *)(a3 + 4) = v19;
*(_DWORD *)(a3 + 8) = v18;
*(_DWORD *)(a3 + 12) = v15;
*(_DWORD *)(a3 + 16) = v16;
*(_QWORD *)(a3 + 24) = v9;
*(_QWORD *)(a3 + 32) = v12;
*(_QWORD *)(a3 + 40) = v13;
v5 = 0;
}
}
}
}
else if ( v5 == 63 )
{
v6 = optopt;
if ( isprint(optopt) )
fprintf(stderr, "Unknown option `-%c'.\n", v6);
else
fprintf(stderr, "Unknown option character `\\x%x'.\n", v6);
v5 = -1;
}
else if ( v5 > 0x3F )
{
LABEL_24:
v5 = -1;
}
else
{
switch ( v5 )
{
case 'S':
v17 = 1;
continue;
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case 'b':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'o':
case 'p':
goto LABEL_24;
case 'a':
v18 = 1;
continue;
case 'c':
v16 = 1;
continue;
case 'n':
v19 = 1;
continue;
case 'q':
v15 = 1;
continue;
default:
v5 = -1;
break;
}
}
return v5;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv, __int64 a3)
{
unsigned int v5; // ebx
unsigned int v6; // ebx
int v7; // eax
__int64 v8; // rsi
__int64 v9; // r15
const char **v10; // r14
char **v11; // rbp
__int64 v12; // rbp
__int64 v13; // rax
int v15; // [rsp+Ch] [rbp-4Ch]
int v16; // [rsp+10h] [rbp-48h]
int v17; // [rsp+14h] [rbp-44h]
int v18; // [rsp+18h] [rbp-40h]
int v19; // [rsp+1Ch] [rbp-3Ch]

opterr = 0;
v16 = 0;
v15 = 0;
v18 = 0;
v19 = 0;
v17 = 0;
while ( 2 )
{
v5 = getopt(argc, argv, "Snaqc");
if ( v5 == -1 )
{
v7 = optind;
if ( optind >= argc )
{
puts("Missing file name argument.");
}
else
{
v8 = 8LL * optind;
v9 = *(__int64 *)((char *)argv + v8);
++optind;
if ( v7 + 1 < argc )
{
v10 = (const char **)((char *)argv + v8 + 8);
v11 = &(&argv[argc - v7 - 2])[(__int64)v7 + 2];
do
{
v8 = (__int64)*v10;
printf("Non-option argument %s\n", *v10++);
}
while ( v10 != (const char **)v11 );
}
v12 = getListingFileName(v9, v8);
if ( v12 )
{
v13 = getAscFileName(v9);
if ( v13 )
{
*(_DWORD *)a3 = v17;
*(_DWORD *)(a3 + 4) = v19;
*(_DWORD *)(a3 + 8) = v18;
*(_DWORD *)(a3 + 12) = v15;
*(_DWORD *)(a3 + 16) = v16;
*(_QWORD *)(a3 + 24) = v9;
*(_QWORD *)(a3 + 32) = v12;
*(_QWORD *)(a3 + 40) = v13;
v5 = 0;
}
}
}
}
else if ( v5 == 63 )
{
v6 = optopt;
if ( isprint(optopt) )
fprintf(stderr, "Unknown option `-%c'.\n", v6);
else
fprintf(stderr, "Unknown option character `\\x%x'.\n", v6);
v5 = -1;
}
else if ( v5 > 0x3F )
{
LABEL_24:
v5 = -1;
}
else
{
switch ( v5 )
{
case 'S':
v17 = 1;
continue;
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case 'b':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'o':
case 'p':
goto LABEL_24;
case 'a':
v18 = 1;
continue;
case 'c':
v16 = 1;
continue;
case 'n':
v19 = 1;
continue;
case 'q':
v15 = 1;
continue;
default:
v5 = -1;
break;
}
}
return v5;
}
}

original_code:
int parseInputs(int argc, char **argv, struct args* argStruct)
{
 int S = 0;
 int n = 0;
 int a = 0;
 int q = 0;
 int c = 0;
 char *ascFile = ((void *)0);
 char *file = ((void *)0);
 char *listing = ((void *)0);
 int index;
 int option;
 opterr = 0;
 while ((option = getopt(argc, argv, "Snaqc")) != -1) {
  switch (option) {
  case 'S':
   S = 1;
   break;
  case 'n':
   n = 1;
   break;
  case 'a':
   a = 1;
   break;
  case 'q':
   q = 1;
   break;
  case 'c':
   c = 1;
   break;
  case '?':
   if (isprint(optopt)) {
    fprintf(
        stderr,
        "Unknown option `-%c'.\n",
        optopt);
   } else {
    fprintf(
        stderr,
        "Unknown option character `\\x%x'.\n",
        optopt);
   }
  default:
   return -1;
  }
 }
 if (optind >= argc) {
  printf("Missing file name argument.\n");
  return -1;
 }
 file = argv[optind];
 optind++;
 for (index = optind; index < argc; index++) {
  printf("Non-option argument %s\n", argv[index]);
 }
 listing = getListingFileName(file);
 if (listing == ((void *)0)) {
  return -1;
 }
 ascFile = getAscFileName(file);
 if (!ascFile) return -1;
 argStruct->S = S;
 argStruct->n = n;
 argStruct->a = a;
 argStruct->q = q;
 argStruct->c = c;
 argStruct->inFile = file;
 argStruct->listingFile = listing;
 argStruct->ascFile = ascFile;
 return 0;
}

canonical_original_code:
int parseInputs(int argc, char **argv, struct args *argStruct)
{
 int S = 0;
 int n = 0;
 int a = 0;
 int q = 0;
 int c = 0;
 char *ascFile = ((void *)0);
 char *file = ((void *)0);
 char *listing = ((void *)0);
 int index;
 int option;
 opterr = 0;
 while ((option = getopt(argc, argv, "Snaqc")) != -1) {
  switch (option) {
  case 'S':
   S = 1;
   break;
  case 'n':
   n = 1;
   break;
  case 'a':
   a = 1;
   break;
  case 'q':
   q = 1;
   break;
  case 'c':
   c = 1;
   break;
  case '?':
   if (isprint(optopt)) {
    fprintf(
        stderr,
        "Unknown option `-%c'.\n",
        optopt);
   } else {
    fprintf(
        stderr,
        "Unknown option character `\\x%x'.\n",
        optopt);
   }
  default:
   return -1;
  }
 }
 if (optind >= argc) {
  printf("Missing file name argument.\n");
  return -1;
 }
 file = argv[optind];
 optind++;
 for (index = optind; index < argc; index++) {
  printf("Non-option argument %s\n", argv[index]);
 }
 listing = getListingFileName(file);
 if (listing == ((void *)0)) {
  return -1;
 }
 ascFile = getAscFileName(file);
 if (!ascFile) return -1;
 argStruct->S = S;
 argStruct->n = n;
 argStruct->a = a;
 argStruct->q = q;
 argStruct->c = c;
 argStruct->inFile = file;
 argStruct->listingFile = listing;
 argStruct->ascFile = ascFile;
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct args { int S; int n; int a; int q; int c; char *inFile; char *listingFile; char *ascFile; } *

variable_types: S int

variable_types: n int

variable_types: a int

variable_types: q int

variable_types: c int

variable_types:
ascFile
char *

variable_types:
file
char *

variable_types:
listing
char *

variable_types: index int

variable_types: option int


getListingFileName

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

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

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

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

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

variable_types:
palFileName
char *

variable_types: len int

variable_types:
listingFileName
char *


numLetters

repo: a-krebs/euler

decompiled_code:
__int64 __fastcall numLetters(int a1, __int64 a2)
{
__int64 result; // rax
int v3; // edi
int v4; // edx
int v5; // edi
int v6; // ecx
int v7; // ecx
int v8; // eax
int v9; // eax

result = (unsigned int)(a1 / 1000);
v3 = a1 % 1000;
v4 = v3 / 100;
v5 = v3 % 100;
v6 = result;
if ( (_DWORD)result )
{
result = (unsigned int)(*(_DWORD *)(a2 + 4LL * (int)result) + 8);
v6 = 1;
}
if ( v4 )
{
result = (unsigned int)(*(_DWORD *)(a2 + 4LL * v4) + result + 7);
if ( v5 <= 19 )
{
if ( !v5 )
return result;
v6 = 3;
return (unsigned int)(*(_DWORD *)(a2 + 4LL * v5) + v6 + result);
}
v6 = 3;
goto LABEL_10;
}
if ( v5 > 19 )
{
if ( v6 == 1 )
v6 = 3;
LABEL_10:
v7 = result + v6;
v8 = v5 % 10;
if ( v5 % 10 )
v8 = *(_DWORD *)(a2 + 4LL * v8);
v9 = v7 + v8;
switch ( v5 / 10 )
{
case 2:
result = (unsigned int)(v9 + 6);
break;
case 3:
result = (unsigned int)(v9 + 6);
break;
case 4:
result = (unsigned int)(v9 + 5);
break;
case 5:
result = (unsigned int)(v9 + 5);
break;
case 8:
result = (unsigned int)(v9 + 6);
break;
default:
result = (unsigned int)(v9 + *(_DWORD *)(a2 + 4LL * (v5 / 10)) + 2);
break;
}
return result;
}
if ( v5 )
{
if ( v6 == 1 )
v6 = 3;
return (unsigned int)(*(_DWORD *)(a2 + 4LL * v5) + v6 + result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2)
{
__int64 result; // rax
int v3; // edi
int v4; // edx
int v5; // edi
int v6; // ecx
int v7; // ecx
int v8; // eax
int v9; // eax

result = (unsigned int)(a1 / 1000);
v3 = a1 % 1000;
v4 = v3 / 100;
v5 = v3 % 100;
v6 = result;
if ( (_DWORD)result )
{
result = (unsigned int)(*(_DWORD *)(a2 + 4LL * (int)result) + 8);
v6 = 1;
}
if ( v4 )
{
result = (unsigned int)(*(_DWORD *)(a2 + 4LL * v4) + result + 7);
if ( v5 <= 19 )
{
if ( !v5 )
return result;
v6 = 3;
return (unsigned int)(*(_DWORD *)(a2 + 4LL * v5) + v6 + result);
}
v6 = 3;
goto LABEL_10;
}
if ( v5 > 19 )
{
if ( v6 == 1 )
v6 = 3;
LABEL_10:
v7 = result + v6;
v8 = v5 % 10;
if ( v5 % 10 )
v8 = *(_DWORD *)(a2 + 4LL * v8);
v9 = v7 + v8;
switch ( v5 / 10 )
{
case 2:
result = (unsigned int)(v9 + 6);
break;
case 3:
result = (unsigned int)(v9 + 6);
break;
case 4:
result = (unsigned int)(v9 + 5);
break;
case 5:
result = (unsigned int)(v9 + 5);
break;
case 8:
result = (unsigned int)(v9 + 6);
break;
default:
result = (unsigned int)(v9 + *(_DWORD *)(a2 + 4LL * (v5 / 10)) + 2);
break;
}
return result;
}
if ( v5 )
{
if ( v6 == 1 )
v6 = 3;
return (unsigned int)(*(_DWORD *)(a2 + 4LL * v5) + v6 + result);
}
return result;
}

original_code:
int numLetters(int n, int* lookup)
{
 int letters = 0;
 int thousands = (int)floor(n / 1000);
 n = n % 1000;
 int hundreds = (int)floor(n / 100);
 n = n % 100;
 int tens = n;
 int tmp = 0;
 int and = 0;
 if (thousands != 0)
 {
  letters += lookup[thousands];
  letters += 8;
  and = 1;
 }
 if (hundreds != 0)
 {
  letters += lookup[hundreds];
  letters += 7;
  and = 1;
 }
 if (tens > 19)
 {
  letters += (and == 1) ? 3 : 0;
  letters += (n % 10 == 0) ? 0 : lookup[n % 10];
  tmp = (int)floor(n/10);
  switch (tmp)
  {
   case 2:
    letters += 6;
    break;
   case 3:
    letters += 6;
    break;
   case 4:
    letters += 5;
    break;
   case 5:
    letters += 5;
    break;
   case 8:
    letters += 6;
    break;
   default:
    letters += lookup[tmp] + 2;
    break;
  }
 }
 else if (tens != 0)
 {
  letters += (and == 1) ? 3 : 0;
  letters += lookup[tens];
 }
 return letters;
}

canonical_original_code:
int numLetters(int n, int *lookup)
{
 int letters = 0;
 int thousands = (int)floor(n / 1000);
 n = n % 1000;
 int hundreds = (int)floor(n / 100);
 n = n % 100;
 int tens = n;
 int tmp = 0;
 int and = 0;
 if (thousands != 0)
 {
  letters += lookup[thousands];
  letters += 8;
  and = 1;
 }
 if (hundreds != 0)
 {
  letters += lookup[hundreds];
  letters += 7;
  and = 1;
 }
 if (tens > 19)
 {
  letters += (and == 1) ? 3 : 0;
  letters += (n % 10 == 0) ? 0 : lookup[n % 10];
  tmp = (int)floor(n/10);
  switch (tmp)
  {
   case 2:
    letters += 6;
    break;
   case 3:
    letters += 6;
    break;
   case 4:
    letters += 5;
    break;
   case 5:
    letters += 5;
    break;
   case 8:
    letters += 6;
    break;
   default:
    letters += lookup[tmp] + 2;
    break;
  }
 }
 else if (tens != 0)
 {
  letters += (and == 1) ? 3 : 0;
  letters += lookup[tens];
 }
 return letters;
}

variable_types:
lookup
int *

variable_types: letters int

variable_types: thousands int

variable_types: hundreds int

variable_types: tens int

variable_types: tmp int

variable_types: and int


main

canonical_name: main

original_code:
int main(int argc, char *argv[])
{
 long sum = 0;
 int from = 1;
 int to = 1000;
 if (argc == 3)
 {
  from = atoi(argv[1]);
  to = atoi(argv[2]);
 }
 int lookup[20] = {
  4,
  3,
  3,
  5,
  4,
  4,
  3,
  5,
  5,
  4,
  3,
  6,
  6,
  8,
  8,
  7,
  7,
  9,
  8,
  8,
 };
 for (int i = from; i < to + 1; i++)
 {
  sum += numLetters(i, lookup);
 }
 printf("%ld\n", sum);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sum long

variable_types: from int

variable_types: to int

variable_types:
lookup
int [20]

variable_types: i int


getLength

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

result = 1LL;
if ( a1 != 1 )
{
if ( a1 > 999999 || (result = *(unsigned int *)(a2 + 4 * a1), !(_DWORD)result) )
{
if ( (a1 & 1) != 0 )
result = (unsigned int)getLength(3 * a1 + 1, a2) + 1;
else
result = (unsigned int)getLength(a1 / 2, a2) + 1;
if ( a1 <= 999999 )
*(_DWORD *)(a2 + 4 * a1) = result;
}
}
return result;
}

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

result = 1LL;
if ( a1 != 1 )
{
if ( a1 > 999999 || (result = *(unsigned int *)(a2 + 4 * a1), !(_DWORD)result) )
{
if ( (a1 & 1) != 0 )
result = (unsigned int)func7(3 * a1 + 1, a2) + 1;
else
result = (unsigned int)func7(a1 / 2, a2) + 1;
if ( a1 <= 999999 )
*(_DWORD *)(a2 + 4 * a1) = result;
}
}
return result;
}

original_code:
int getLength(long n, int* cache)
{
 int cached = 0;
 if (n == 1) {
  return 1;
 }
 if (n <= 999999) {
  cached = cache[n];
 }
 if (cached != 0) {
  return cached;
 } else if (n % 2 == 0) {
  cached = getLength(n / 2, cache) + 1;
 } else {
  cached = getLength(3*n + 1, cache) + 1;
 }
 if (n <= 999999) {
  cache[n] = cached;
 }
 return cached;
}

canonical_original_code:
int getLength(long n, int *cache)
{
 int cached = 0;
 if (n == 1) {
  return 1;
 }
 if (n <= 999999) {
  cached = cache[n];
 }
 if (cached != 0) {
  return cached;
 } else if (n % 2 == 0) {
  cached = getLength(n / 2, cache) + 1;
 } else {
  cached = getLength(3*n + 1, cache) + 1;
 }
 if (n <= 999999) {
  cache[n] = cached;
 }
 return cached;
}

variable_types: n long

variable_types:
cache
int *

variable_types: cached int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
__int64 v4; // rbx
int v5; // ebp
__int64 v6; // r13
int v7; // eax

v3 = calloc(0xF4240uLL, 4uLL);
v4 = 999999LL;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = getLength(v4, (__int64)v3);
if ( v7 > v5 )
{
v5 = v7;
v6 = v4;
}
if ( !--v4 )
{
printf("%ld\n", v6);
free(v3);
exit(0);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
__int64 v4; // rbx
int v5; // ebp
__int64 v6; // r13
int v7; // eax

v3 = calloc(0xF4240uLL, 4uLL);
v4 = 999999LL;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = func7(v4, (__int64)v3);
if ( v7 > v5 )
{
v5 = v7;
v6 = v4;
}
if ( !--v4 )
{
printf("%ld\n", v6);
free(v3);
exit(0);
}
}
}

original_code:
int main(int argc, char *argv[])
{
 long n_longest_chain = 0;
 int longest_chain_length = 0;
 long tmp = 0;
 int* cache = calloc(999999 + 1, sizeof(int));
 for (long n = 999999; n > 0; n--) {
  tmp = getLength(n, cache);
  if (longest_chain_length < tmp) {
   n_longest_chain = n;
   longest_chain_length = tmp;
  }
 }
 printf("%ld\n", n_longest_chain);
 free(cache);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 long n_longest_chain = 0;
 int longest_chain_length = 0;
 long tmp = 0;
 int *cache = calloc(999999 + 1, sizeof(int));
 for (long n = 999999; n > 0; n--) {
  tmp = getLength(n, cache);
  if (longest_chain_length < tmp) {
   n_longest_chain = n;
   longest_chain_length = tmp;
  }
 }
 printf("%ld\n", n_longest_chain);
 free(cache);
 exit(0);
}

variable_types: tmp long


showDigits

decompiled_code:
int __fastcall showDigits(unsigned int *a1)
{
int v2; // ebp

v2 = 10;
do
{
printf("%d", *a1);
a1 = (unsigned int *)*((_QWORD *)a1 + 1);
--v2;
}
while ( v2 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
int v2; // ebp

v2 = 10;
do
{
printf("%d", *a1);
a1 = (unsigned int *)*((_QWORD *)a1 + 1);
--v2;
}
while ( v2 );
return putchar(10);
}

original_code:
void showDigits(struct digit * ptr)
{
 struct digit * head = ptr;
 for (int f = 0; f < 10; f++)
 {
  printf("%d", head->digit);
  head = head->next;
 }
 printf("\n");
}

canonical_original_code:
void showDigits(struct digit *ptr)
{
 struct digit *head = ptr;
 for (int f = 0; f < 10; f++)
 {
  printf("%d", head->digit);
  head = head->next;
 }
 printf("\n");
}

variable_types: struct digit { int digit; struct digit *next; struct digit *previous; } *

variable_types: f int


main

variable_types:
matrix
int [100][50]

variable_types: carryover int

variable_types: sum int

variable_types: d int

variable_types: n int

user_defined_types: struct digit { int digit; struct digit *next; struct digit *previous; }


printTOD

repo: a-krebs/parallel-matrix

decompiled_code:
int printTOD()
{
struct tm *v0; // rax
struct timeval v2; // [rsp+0h] [rbp-38h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
gettimeofday(&v2, 0LL);
v0 = localtime(&v2.tv_sec);
strftime(s, 0x20uLL, "%H:%M:%S", v0);
return printf("%s.%03ld\n", s, v2.tv_usec / 1000);
}

canonical_decompiled_code:
int func7()
{
struct tm *v0; // rax
struct timeval v2; // [rsp+0h] [rbp-38h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
gettimeofday(&v2, 0LL);
v0 = localtime(&v2.tv_sec);
strftime(s, 0x20uLL, "%H:%M:%S", v0);
return printf("%s.%03ld\n", s, v2.tv_usec / 1000);
}

original_code:
void printTOD() {
 char buffer[32];
 struct timeval time;
 memset(&time, 0, sizeof(struct timeval));
 gettimeofday(&time, ((void *)0));
 strftime(buffer, 32,"%H:%M:%S", localtime(&time.tv_sec));
 printf("%s.%03ld\n", buffer, time.tv_usec/1000);
}

variable_types:
buffer
char [32]

variable_types: struct timeval { long tv_sec; long tv_usec; }


timevalSubtract

original_code:
int timevalSubtract(struct timeval *result, struct timeval *x, struct timeval *y) {
 if (x->tv_usec < y->tv_usec) {
  int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
  y->tv_usec -= 1000000 * nsec;
  y->tv_sec += nsec;
 }
 if (x->tv_usec - y->tv_usec > 1000000) {
  int nsec = (x->tv_usec - y->tv_usec) / 1000000;
  y->tv_usec += 1000000 * nsec;
  y->tv_sec -= nsec;
 }
 result->tv_sec = x->tv_sec - y->tv_sec;
 result->tv_usec = x->tv_usec - y->tv_usec;
 return x->tv_sec < y->tv_sec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types:
x
struct timeval *

variable_types:
y
struct timeval *

variable_types: nsec int


printElapsedTime

decompiled_code:
int __fastcall printElapsedTime(_QWORD *a1, _QWORD *a2)
{
int result; // eax
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

if ( timevalSubtract(v3, a2, a1) )
result = printf("Time difference negative!");
else
result = printf("%ld.%06ld", v3[0], v3[1]);
return result;
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1, _QWORD *a2)
{
int result; // eax
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

if ( func8(v3, a2, a1) )
result = printf("Time difference negative!");
else
result = printf("%ld.%06ld", v3[0], v3[1]);
return result;
}

original_code:
void printElapsedTime(struct timeval *r1, struct timeval *r2) {
 struct timeval diff;
 if (timevalSubtract(&diff, r2, r1) != 0) {
  printf("Time difference negative!");
  return;
 }
 printf("%ld.%06ld", diff.tv_sec, diff.tv_usec);
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


multiply

original_code:
void multiply(int **A, int **B, int **C, int size, int rStart, int rEnd) {
 int rowC = 0;
 int colC = 0;
 int k = 0;
 int product = 0;
 for (rowC = rStart; rowC <= rEnd; rowC++) {
  for (colC = 0; colC < size; colC++) {
   product = 0;
   for (k = 0; k < size; k++) {
    product +=
        A[rowC][k] * B[k][colC];
   }
   C[rowC][colC] = product;
  }
 }
}

variable_types:
A
int **

variable_types:
B
int **

variable_types:
C
int **

variable_types: size int

variable_types: rStart int

variable_types: rEnd int

variable_types: rowC int

variable_types: colC int

variable_types: k int

variable_types: product int


printMatrix

decompiled_code:
int __fastcall printMatrix(_QWORD *a1, int a2)
{
_QWORD *v2; // rbp
__int64 v3; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = 0LL;
do
{
printf("%d\t", *(unsigned int *)(*v2 + v3));
v3 += 4LL;
}
while ( 4LL * (unsigned int)a2 != v3 );
putchar(10);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func11(_QWORD *a1, int a2)
{
_QWORD *v2; // rbp
__int64 v3; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = 0LL;
do
{
printf("%d\t", *(unsigned int *)(*v2 + v3));
v3 += 4LL;
}
while ( 4LL * (unsigned int)a2 != v3 );
putchar(10);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return putchar(10);
}

original_code:
void printMatrix(int **m, int size) {
 int row = 0;
 int col = 0;
 for (row = 0; row < size; row++) {
  for (col = 0; col < size; col++) {
   printf("%d\t", m[row][col]);
  }
  printf("\n");
 }
 printf("\n");
}

variable_types:
m
int **

variable_types: row int

variable_types: col int


freeMatrixInt

decompiled_code:
void __fastcall freeMatrixInt(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void freeMatrixInt(int **m, int size) {
 int i = 0;
 for (i = 0; i < size; i++) {
  free(m[i]);
 }
 free(m);
}

variable_types: i int


tearDownExp

decompiled_code:
void __fastcall tearDownExp(void **a1, void **a2, void **a3, int a4)
{
freeMatrixInt(*a1, a4);
freeMatrixInt(*a2, a4);
freeMatrixInt(*a3, a4);
}

canonical_decompiled_code:
void __fastcall func13(void **a1, void **a2, void **a3, int a4)
{
func12(*a1, a4);
func12(*a2, a4);
func12(*a3, a4);
}

original_code:
void tearDownExp(int ***A, int ***B, int ***C, int size) {
 freeMatrixInt(*A, size);
 freeMatrixInt(*B, size);
 freeMatrixInt(*C, size);
}

variable_types:
A
int ***

variable_types:
B
int ***

variable_types:
C
int ***


initMatrixInt

decompiled_code:
void __fastcall initMatrixInt(_QWORD *a1, int a2)
{
_QWORD *v2; // rbp
__int64 v3; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = 0LL;
do
{
*(_DWORD *)(*v2 + v3) = random();
v3 += 4LL;
}
while ( 4LL * (unsigned int)a2 != v3 );
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func14(_QWORD *a1, int a2)
{
_QWORD *v2; // rbp
__int64 v3; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = 0LL;
do
{
*(_DWORD *)(*v2 + v3) = random();
v3 += 4LL;
}
while ( 4LL * (unsigned int)a2 != v3 );
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

original_code:
void initMatrixInt(int **m, int size){
 int i = 0;
 int j = 0;
 for (i = 0; i < size; i++) {
  for (j = 0; j < size; j++) {
   m[i][j] = (int)random();
  }
 }
}

variable_types: j int


setupExp

decompiled_code:
__int64 __fastcall setupExp(_QWORD **a1, _QWORD **a2, _QWORD *a3, int a4, unsigned int a5)
{
_QWORD *v8; // rax

*a1 = allocMatrixInt(a4);
*a2 = allocMatrixInt(a4);
v8 = allocMatrixInt(a4);
*a3 = v8;
if ( !*a1 )
return 0xFFFFFFFFLL;
if ( !*a2 || !v8 )
return 0xFFFFFFFFLL;
srandom(a5);
initMatrixInt(*a1, a4);
initMatrixInt(*a2, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD **a1, _QWORD **a2, _QWORD *a3, int a4, unsigned int a5)
{
_QWORD *v8; // rax

*a1 = allocMatrixInt(a4);
*a2 = allocMatrixInt(a4);
v8 = allocMatrixInt(a4);
*a3 = v8;
if ( !*a1 )
return 0xFFFFFFFFLL;
if ( !*a2 || !v8 )
return 0xFFFFFFFFLL;
srandom(a5);
func14(*a1, a4);
func14(*a2, a4);
return 0LL;
}

original_code:
int setupExp(int ***A, int ***B, int ***C, int size, unsigned int seed) {
 *A = allocMatrixInt(size);
 *B = allocMatrixInt(size);
 *C = allocMatrixInt(size);
 if ((*A == ((void *)0)) || (*B == ((void *)0)) || (*C == ((void *)0))) {
  return -1;
 }
 srandom(seed);
 initMatrixInt(*A, size);
 initMatrixInt(*B, size);
 return 0;
}

variable_types:
seed
unsigned int