ClearDeffacts

decompiled_code:
__int64 __fastcall ClearDeffacts(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rdx
__int64 *v6; // rbp
__int64 v7; // rax

v1 = FindFunction(a1, "assert");
v2 = GenConstant(a1, 30LL, v1);
v3 = EnvFindDeftemplate(a1, "initial-fact");
*(_QWORD *)(v2 + 16) = GenConstant(a1, 63LL, v3);
ExpressionInstall(a1, v2);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL);
v5 = *(_QWORD *)(*(_QWORD *)(v4 + 40) + 448LL);
if ( v5 )
{
*(_QWORD *)(v4 + 32) = v5;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 40LL) + 448LL) = **(_QWORD **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 32LL);
v6 = *(__int64 **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 32LL);
}
else
{
v6 = (__int64 *)genalloc(a1, 56LL);
}
v6[2] = GetDeffactsModuleItem(a1, 0LL);
v7 = EnvAddSymbol(a1, "initial-fact");
*v6 = v7;
++*(_QWORD *)(v7 + 8);
v6[6] = PackExpression(a1, v2);
v6[4] = 0LL;
v6[1] = 0LL;
v6[5] = 0LL;
ReturnExpression(a1, v2);
return AddConstructToModule(v6);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rdx
__int64 *v6; // rbp
__int64 v7; // rax

v1 = FindFunction(a1, "assert");
v2 = GenConstant(a1, 30LL, v1);
v3 = EnvFindDeftemplate(a1, "initial-fact");
*(_QWORD *)(v2 + 16) = GenConstant(a1, 63LL, v3);
ExpressionInstall(a1, v2);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL);
v5 = *(_QWORD *)(*(_QWORD *)(v4 + 40) + 448LL);
if ( v5 )
{
*(_QWORD *)(v4 + 32) = v5;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 40LL) + 448LL) = **(_QWORD **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 32LL);
v6 = *(__int64 **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 32LL);
}
else
{
v6 = (__int64 *)genalloc(a1, 56LL);
}
v6[2] = GetDeffactsModuleItem(a1, 0LL);
v7 = EnvAddSymbol(a1, "initial-fact");
*v6 = v7;
++*(_QWORD *)(v7 + 8);
v6[6] = PackExpression(a1, v2);
v6[4] = 0LL;
v6[1] = 0LL;
v6[5] = 0LL;
ReturnExpression(a1, v2);
return AddConstructToModule(v6);
}

original_code:
static void ClearDeffacts(
  void *theEnv)
  {
   struct expr *stub;
   struct deffacts *newDeffacts;
   stub = GenConstant(theEnv,30,FindFunction(theEnv,"assert"));
   stub->argList = GenConstant(theEnv,63,EnvFindDeftemplate(theEnv,"initial-fact"));
   ExpressionInstall(theEnv,stub);
   newDeffacts = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] == ((void *)0)) ? ((struct deffacts *) genalloc(theEnv,(unsigned) sizeof(struct deffacts))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct deffacts *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
   newDeffacts->header.whichModule =
      (struct defmoduleItemHeader *) GetDeffactsModuleItem(theEnv,((void *)0));
   newDeffacts->header.name = (SYMBOL_HN *) EnvAddSymbol(theEnv,"initial-fact");
   (((SYMBOL_HN *) newDeffacts->header.name)->count++);
   newDeffacts->assertList = PackExpression(theEnv,stub);
   newDeffacts->header.next = ((void *)0);
   newDeffacts->header.ppForm = ((void *)0);
   newDeffacts->header.usrData = ((void *)0);
   ReturnExpression(theEnv,stub);
   AddConstructToModule(&newDeffacts->header);
  }

canonical_original_code:
static void ClearDeffacts(void *theEnv)
  {
   struct expr *stub;
   struct deffacts *newDeffacts;
   stub = GenConstant(theEnv,30,FindFunction(theEnv,"assert"));
   stub->argList = GenConstant(theEnv,63,EnvFindDeftemplate(theEnv,"initial-fact"));
   ExpressionInstall(theEnv,stub);
   newDeffacts = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] == ((void *)0)) ? ((struct deffacts *) genalloc(theEnv,(unsigned int) sizeof(struct deffacts))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct deffacts *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
   newDeffacts->header.whichModule =
      (struct defmoduleItemHeader *) GetDeffactsModuleItem(theEnv,((void *)0));
   newDeffacts->header.name = (struct symbolHashNode *) EnvAddSymbol(theEnv,"initial-fact");
   (((struct symbolHashNode *) newDeffacts->header.name)->count++);
   newDeffacts->assertList = PackExpression(theEnv,stub);
   newDeffacts->header.next = ((void *)0);
   newDeffacts->header.ppForm = ((void *)0);
   newDeffacts->header.usrData = ((void *)0);
   ReturnExpression(theEnv,stub);
   AddConstructToModule(&newDeffacts->header);
  }

variable_types: struct deffacts { struct constructHeader { struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *name; char *ppForm; struct defmoduleItemHeader { struct defmodule { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader **itemsArray; struct portItem { struct symbolHashNode *moduleName; struct symbolHashNode *constructType; struct symbolHashNode *constructName; struct portItem *next; } *importList; struct portItem *exportList; unsigned int visitedFlag; long bsaveID; struct userData { unsigned char dataID; struct userData *next; } *usrData; struct defmodule *next; } *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; } *whichModule; long bsaveID; struct constructHeader *next; struct userData *usrData; } header; struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *assertList; } *

user_defined_types: struct deffacts { struct constructHeader header; struct expr *assertList; }

user_defined_types: struct memoryData { long MemoryAmount; long MemoryCalls; int ConserveMemory; int (*OutOfMemoryFunction)(void *, unsigned long); struct memoryPtr *TempMemoryPtr; struct memoryPtr **MemoryTable; unsigned int TempSize; unsigned long TempSize2; }

user_defined_types: struct environmentData { unsigned int initialized; unsigned long environmentIndex; void *context; void *routerContext; void **theData; void (**cleanupFunctions)(void *); struct environmentCleanupFunction *listOfCleanupEnvironmentFunctions; struct environmentData *next; }

user_defined_types: struct defmoduleItemHeader { struct defmodule *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; }

user_defined_types: struct memoryPtr { struct memoryPtr *next; }

user_defined_types: struct environmentCleanupFunction { char *name; void (*func)(void *); int priority; struct environmentCleanupFunction *next; }

user_defined_types: struct defmodule { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader **itemsArray; struct portItem *importList; struct portItem *exportList; unsigned int visitedFlag; long bsaveID; struct userData *usrData; struct defmodule *next; }


ResetDeffactsAction

repo: jarcec/rbclips

decompiled_code:
__int64 __fastcall ResetDeffactsAction(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp-48h] [rbp-48h] BYREF

if ( *(_QWORD *)(a2 + 48) )
{
SetEvaluationError(a1, 0LL);
result = EvaluateExpression(a1, *(_QWORD *)(a2 + 48), &v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp-48h] [rbp-48h] BYREF

if ( *(_QWORD *)(a2 + 48) )
{
SetEvaluationError(a1, 0LL);
result = EvaluateExpression(a1, *(_QWORD *)(a2 + 48), &v3);
}
return result;
}

original_code:
static void ResetDeffactsAction(
  void *theEnv,
  struct constructHeader *theConstruct,
  void *buffer)
  {
   DATA_OBJECT result;
   struct deffacts *theDeffacts = (struct deffacts *) theConstruct;
   if (theDeffacts->assertList == ((void *)0)) return;
   SetEvaluationError(theEnv,0);
   EvaluateExpression(theEnv,theDeffacts->assertList,&result);
  }

canonical_original_code:
static void ResetDeffactsAction(void *theEnv, struct constructHeader *theConstruct, void *buffer)
  {
   struct dataObject result;
   struct deffacts *theDeffacts = (struct deffacts *) theConstruct;
   if (theDeffacts->assertList == ((void *)0)) return;
   SetEvaluationError(theEnv,0);
   EvaluateExpression(theEnv,theDeffacts->assertList,&result);
  }

variable_types:
theEnv
void *

variable_types: struct constructHeader { struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *name; char *ppForm; struct defmoduleItemHeader { struct defmodule { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader **itemsArray; struct portItem { struct symbolHashNode *moduleName; struct symbolHashNode *constructType; struct symbolHashNode *constructName; struct portItem *next; } *importList; struct portItem *exportList; unsigned int visitedFlag; long bsaveID; struct userData { unsigned char dataID; struct userData *next; } *usrData; struct defmodule *next; } *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; } *whichModule; long bsaveID; struct constructHeader *next; struct userData *usrData; } *

variable_types:
buffer
void *

variable_types: struct dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; }

return_type: void

user_defined_types: struct constructHeader { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader *whichModule; long bsaveID; struct constructHeader *next; struct userData *usrData; }

user_defined_types: struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; }


DeffactsBasicCommands

decompiled_code:
__int64 __fastcall DeffactsBasicCommands(__int64 a1)
{
EnvAddResetFunction(a1, "deffacts", ResetDeffacts, 0LL);
EnvAddClearFunction(a1, "deffacts", ClearDeffacts, 0LL);
AddSaveFunction(a1, "deffacts", SaveDeffacts, 10LL);
EnvDefineFunction2(a1, "get-deffacts-list", 109LL, GetDeffactsListFunction, "GetDeffactsListFunction", "01w");
EnvDefineFunction2(a1, "undeffacts", 118LL, UndeffactsCommand, "UndeffactsCommand", "11w");
EnvDefineFunction2(a1, "deffacts-module", 119LL, DeffactsModuleFunction, "DeffactsModuleFunction", "11w");
EnvDefineFunction2(a1, "list-deffacts", 118LL, ListDeffactsCommand, "ListDeffactsCommand", "01w");
EnvDefineFunction2(a1, "ppdeffacts", 118LL, PPDeffactsCommand, "PPDeffactsCommand", "11w");
DeffactsBinarySetup(a1);
return DeffactsCompilerSetup(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
EnvAddResetFunction(a1, "deffacts", ResetDeffacts, 0LL);
EnvAddClearFunction(a1, "deffacts", ClearDeffacts, 0LL);
AddSaveFunction(a1, "deffacts", SaveDeffacts, 10LL);
EnvDefineFunction2(a1, "get-deffacts-list", 109LL, GetDeffactsListFunction, "GetDeffactsListFunction", "01w");
EnvDefineFunction2(a1, "undeffacts", 118LL, UndeffactsCommand, "UndeffactsCommand", "11w");
EnvDefineFunction2(a1, "deffacts-module", 119LL, DeffactsModuleFunction, "DeffactsModuleFunction", "11w");
EnvDefineFunction2(a1, "list-deffacts", 118LL, ListDeffactsCommand, "ListDeffactsCommand", "01w");
EnvDefineFunction2(a1, "ppdeffacts", 118LL, PPDeffactsCommand, "PPDeffactsCommand", "11w");
DeffactsBinarySetup(a1);
return DeffactsCompilerSetup(a1);
}

original_code:
void DeffactsBasicCommands(
  void *theEnv)
  {
   EnvAddResetFunction(theEnv,"deffacts",ResetDeffacts,0);
   EnvAddClearFunction(theEnv,"deffacts",ClearDeffacts,0);
   AddSaveFunction(theEnv,"deffacts",SaveDeffacts,10);
   EnvDefineFunction2(theEnv,"get-deffacts-list",'m',(int (*)(void *)) GetDeffactsListFunction,"GetDeffactsListFunction","01w");
   EnvDefineFunction2(theEnv,"undeffacts",'v',(int (*)(void *)) UndeffactsCommand,"UndeffactsCommand","11w");
   EnvDefineFunction2(theEnv,"deffacts-module",'w',(int (*)(void *)) DeffactsModuleFunction,"DeffactsModuleFunction","11w");
   EnvDefineFunction2(theEnv,"list-deffacts",'v', (int (*)(void *)) ListDeffactsCommand,"ListDeffactsCommand","01w");
   EnvDefineFunction2(theEnv,"ppdeffacts",'v',(int (*)(void *)) PPDeffactsCommand,"PPDeffactsCommand","11w");
   DeffactsBinarySetup(theEnv);
   DeffactsCompilerSetup(theEnv);
  }

canonical_original_code:
void DeffactsBasicCommands(void *theEnv)
  {
   EnvAddResetFunction(theEnv,"deffacts",ResetDeffacts,0);
   EnvAddClearFunction(theEnv,"deffacts",ClearDeffacts,0);
   AddSaveFunction(theEnv,"deffacts",SaveDeffacts,10);
   EnvDefineFunction2(theEnv,"get-deffacts-list",'m',(int (*)(void *)) GetDeffactsListFunction,"GetDeffactsListFunction","01w");
   EnvDefineFunction2(theEnv,"undeffacts",'v',(int (*)(void *)) UndeffactsCommand,"UndeffactsCommand","11w");
   EnvDefineFunction2(theEnv,"deffacts-module",'w',(int (*)(void *)) DeffactsModuleFunction,"DeffactsModuleFunction","11w");
   EnvDefineFunction2(theEnv,"list-deffacts",'v', (int (*)(void *)) ListDeffactsCommand,"ListDeffactsCommand","01w");
   EnvDefineFunction2(theEnv,"ppdeffacts",'v',(int (*)(void *)) PPDeffactsCommand,"PPDeffactsCommand","11w");
   DeffactsBinarySetup(theEnv);
   DeffactsCompilerSetup(theEnv);
  }


AllocateExpressions

decompiled_code:
__int64 __fastcall AllocateExpressions(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rsi

GenReadBinary(a1, *(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 48LL, 8LL);
result = *(_QWORD *)(a1 + 32);
v2 = *(_QWORD *)(result + 360);
v3 = *(_QWORD *)(v2 + 48);
if ( v3 )
{
result = genlongalloc(a1, 32 * v3);
*(_QWORD *)(v2 + 56) = result;
}
else
{
*(_QWORD *)(v2 + 56) = 0LL;
}
return result;
}

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

GenReadBinary(a1, *(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 48LL, 8LL);
result = *(_QWORD *)(a1 + 32);
v2 = *(_QWORD *)(result + 360);
v3 = *(_QWORD *)(v2 + 48);
if ( v3 )
{
result = genlongalloc(a1, 32 * v3);
*(_QWORD *)(v2 + 56) = result;
}
else
{
*(_QWORD *)(v2 + 56) = 0LL;
}
return result;
}

original_code:
void AllocateExpressions(
  void *theEnv)
  {
   unsigned long space;
   GenReadBinary(theEnv,(void *) &((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions,(unsigned long) sizeof(long));
   if (((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions == 0L)
     ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray = ((void *)0);
   else
     {
      space = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions * sizeof(struct expr);
      ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray = (struct expr *) genlongalloc(theEnv,space);
     }
  }

canonical_original_code:
void AllocateExpressions(void *theEnv)
  {
   unsigned long space;
   GenReadBinary(theEnv,(void *) &((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions,(unsigned long) sizeof(long));
   if (((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions == 0L)
     ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray = ((void *)0);
   else
     {
      space = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions * sizeof(struct expr);
      ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray = (struct expr *) genlongalloc(theEnv,space);
     }
  }

variable_types:
space
unsigned long

user_defined_types: struct expressionData { void *PTR_AND; void *PTR_OR; void *PTR_EQ; void *PTR_NEQ; void *PTR_NOT; struct exprHashNode **ExpressionHashTable; long NumberOfExpressions; struct expr *ExpressionArray; long ExpressionCount; struct saved_contexts *svContexts; int ReturnContext; int BreakContext; int SequenceOpMode; }

user_defined_types: struct saved_contexts { int rtn; int brk; struct saved_contexts *nxt; }

user_defined_types: struct exprHashNode { unsigned int hashval; unsigned int count; struct expr *exp; struct exprHashNode *next; long bsaveID; }


RefreshExpressions

decompiled_code:
__int64 __fastcall RefreshExpressions(__int64 a1)
{
__int64 result; // rax

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL);
if ( *(_QWORD *)(result + 56) )
result = BloadandRefresh(a1, *(_QWORD *)(result + 48), 32LL, UpdateExpression);
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL);
if ( *(_QWORD *)(result + 56) )
result = BloadandRefresh(a1, *(_QWORD *)(result + 48), 32LL, UpdateExpression);
return result;
}

original_code:
void RefreshExpressions(
  void *theEnv)
  {
   if (((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray == ((void *)0)) return;
   BloadandRefresh(theEnv,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions,
                   (unsigned) sizeof(BSAVE_EXPRESSION),UpdateExpression);
  }

canonical_original_code:
void RefreshExpressions(void *theEnv)
  {
   if (((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray == ((void *)0)) return;
   BloadandRefresh(theEnv,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions,
                   (unsigned int) sizeof(BSAVE_EXPRESSION),UpdateExpression);
  }


ClearBloadedExpressions

decompiled_code:
__int64 __fastcall ClearBloadedExpressions(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rax
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rdx
bool v5; // cc
__int64 v6; // rdx
unsigned __int16 v7; // ax
__int64 v8; // rax
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 32);
v2 = *(_QWORD *)(v1 + 360);
if ( *(_QWORD *)(v2 + 48) )
{
v3 = 0LL;
do
{
v5 = __CFADD__(*(_QWORD *)(v2 + 56), 32 * v3) || *(_QWORD *)(v2 + 56) + 32 * v3 == 0;
v6 = *(_QWORD *)(v2 + 56) + 32 * v3;
v7 = *(_WORD *)v6;
if ( v5 )
{
switch ( v7 )
{
case 0u:
DecrementFloatCount(a1, *(_QWORD *)(v6 + 8));
break;
case 1u:
DecrementIntegerCount(a1, *(_QWORD *)(v6 + 8));
break;
case 2u:
case 3u:
case 8u:
case 0x21u:
DecrementSymbolCount(a1, *(_QWORD *)(v6 + 8));
break;
case 4u:
case 5u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
case 0x19u:
case 0x1Au:
case 0x1Bu:
case 0x1Cu:
case 0x1Du:
case 0x1Eu:
case 0x1Fu:
case 0x20u:
goto LABEL_12;
case 6u:
EnvDecrementFactCount(a1, *(_QWORD *)(v6 + 8));
break;
case 7u:
EnvDecrementInstanceCount(a1, *(_QWORD *)(v6 + 8));
break;
default:
if ( v7 != 175 )
goto LABEL_12;
break;
}
}
else
{
LABEL_12:
v8 = *(_QWORD *)(*(_QWORD *)(v1 + 352) + 8LL * v7 + 24);
if ( v8 && (*(_BYTE *)(v8 + 9) & 0x40) != 0 )
DecrementBitMapCount(a1, *(_QWORD *)(v6 + 8));
}
++v3;
v1 = *(_QWORD *)(a1 + 32);
v2 = *(_QWORD *)(v1 + 360);
v4 = *(_QWORD *)(v2 + 48);
}
while ( v4 > v3 );
if ( 32 * v4 )
genlongfree(a1, *(_QWORD *)(v2 + 56));
}
result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL);
*(_QWORD *)(result + 56) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rax
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rdx
bool v5; // cc
__int64 v6; // rdx
unsigned __int16 v7; // ax
__int64 v8; // rax
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 32);
v2 = *(_QWORD *)(v1 + 360);
if ( *(_QWORD *)(v2 + 48) )
{
v3 = 0LL;
do
{
v5 = __CFADD__(*(_QWORD *)(v2 + 56), 32 * v3) || *(_QWORD *)(v2 + 56) + 32 * v3 == 0;
v6 = *(_QWORD *)(v2 + 56) + 32 * v3;
v7 = *(_WORD *)v6;
if ( v5 )
{
switch ( v7 )
{
case 0u:
DecrementFloatCount(a1, *(_QWORD *)(v6 + 8));
break;
case 1u:
DecrementIntegerCount(a1, *(_QWORD *)(v6 + 8));
break;
case 2u:
case 3u:
case 8u:
case 0x21u:
DecrementSymbolCount(a1, *(_QWORD *)(v6 + 8));
break;
case 4u:
case 5u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
case 0x19u:
case 0x1Au:
case 0x1Bu:
case 0x1Cu:
case 0x1Du:
case 0x1Eu:
case 0x1Fu:
case 0x20u:
goto LABEL_12;
case 6u:
EnvDecrementFactCount(a1, *(_QWORD *)(v6 + 8));
break;
case 7u:
EnvDecrementInstanceCount(a1, *(_QWORD *)(v6 + 8));
break;
default:
if ( v7 != 175 )
goto LABEL_12;
break;
}
}
else
{
LABEL_12:
v8 = *(_QWORD *)(*(_QWORD *)(v1 + 352) + 8LL * v7 + 24);
if ( v8 && (*(_BYTE *)(v8 + 9) & 0x40) != 0 )
DecrementBitMapCount(a1, *(_QWORD *)(v6 + 8));
}
++v3;
v1 = *(_QWORD *)(a1 + 32);
v2 = *(_QWORD *)(v1 + 360);
v4 = *(_QWORD *)(v2 + 48);
}
while ( v4 > v3 );
if ( 32 * v4 )
genlongfree(a1, *(_QWORD *)(v2 + 56));
}
result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL);
*(_QWORD *)(result + 56) = 0LL;
return result;
}

original_code:
void ClearBloadedExpressions(
  void *theEnv)
  {
   unsigned long int i, space;
   for (i = 0; i < (unsigned long) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions; i++)
     {
      switch (((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].type)
        {
         case 2 :
         case 3 :
         case 8 :
         case 33 :
           DecrementSymbolCount(theEnv,(SYMBOL_HN *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 0 :
           DecrementFloatCount(theEnv,(FLOAT_HN *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 1 :
           DecrementIntegerCount(theEnv,(INTEGER_HN *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 6 :
           EnvDecrementFactCount(theEnv,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 7 :
           EnvDecrementInstanceCount(theEnv,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 175:
           break;
         default:
           if (((struct evaluationData *) (((struct environmentData *) theEnv)->theData[44]))->PrimitivesArray[((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].type] == ((void *)0)) break;
           if (((struct evaluationData *) (((struct environmentData *) theEnv)->theData[44]))->PrimitivesArray[((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].type]->bitMap)
             { DecrementBitMapCount(theEnv,(BITMAP_HN *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value); }
           break;
        }
     }
   space = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions * sizeof(struct expr);
   if (space != 0) genlongfree(theEnv,(void *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray,space);
   ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray = 0;
  }

canonical_original_code:
void ClearBloadedExpressions(void *theEnv)
  {
   unsigned long i; unsigned long space;
   for (i = 0; i < (unsigned long) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions; i++)
     {
      switch (((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].type)
        {
         case 2 :
         case 3 :
         case 8 :
         case 33 :
           DecrementSymbolCount(theEnv,(struct symbolHashNode *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 0 :
           DecrementFloatCount(theEnv,(struct floatHashNode *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 1 :
           DecrementIntegerCount(theEnv,(struct integerHashNode *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 6 :
           EnvDecrementFactCount(theEnv,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 7 :
           EnvDecrementInstanceCount(theEnv,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value);
           break;
         case 175:
           break;
         default:
           if (((struct evaluationData *) (((struct environmentData *) theEnv)->theData[44]))->PrimitivesArray[((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].type] == ((void *)0)) break;
           if (((struct evaluationData *) (((struct environmentData *) theEnv)->theData[44]))->PrimitivesArray[((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].type]->bitMap)
             { DecrementBitMapCount(theEnv,(struct bitMapHashNode *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[i].value); }
           break;
        }
     }
   space = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->NumberOfExpressions * sizeof(struct expr);
   if (space != 0) genlongfree(theEnv,(void *) ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray,space);
   ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray = 0;
  }

variable_types:
i
unsigned long

user_defined_types: struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; }

user_defined_types: struct floatHashNode { struct floatHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededFloat; unsigned int bucket; double contents; }

user_defined_types: struct integerHashNode { struct integerHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededInteger; unsigned int bucket; long contents; }

user_defined_types: struct evaluationData { struct expr *CurrentExpression; int EvaluationError; int HaltExecution; int CurrentEvaluationDepth; struct entityRecord *PrimitivesArray[150]; }

user_defined_types: struct bitMapHashNode { struct bitMapHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededBitMap; unsigned int bucket; char *contents; unsigned short size; }

user_defined_types: struct entityRecord { char *name; unsigned int type; unsigned int copyToEvaluate; unsigned int bitMap; unsigned int addsToRuleComplexity; void (*shortPrintFunction)(void *, char *, void *); void (*longPrintFunction)(void *, char *, void *); int (*deleteFunction)(void *, void *); int (*evaluateFunction)(void *, void *, struct dataObject *); void *(*getNextFunction)(void *, void *); void (*decrementBusyCount)(void *, void *); void (*incrementBusyCount)(void *, void *); void (*propagateDepth)(void *, void *); void (*markNeeded)(void *, void *); void (*install)(void *, void *); void (*deinstall)(void *, void *); struct userData *usrData; }

user_defined_types: struct userData { unsigned char dataID; struct userData *next; }

user_defined_types: struct dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; }


FindHashedExpressions

decompiled_code:
__int64 __fastcall FindHashedExpressions(__int64 a1)
{
__int64 i; // r12
__int64 result; // rax
_QWORD *j; // rbx
__int64 v4; // rdx

for ( i = 0LL; i != 4024; i += 8LL )
{
result = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 40LL);
for ( j = *(_QWORD **)(result + i); j; j = (_QWORD *)j[2] )
{
MarkNeededItems(a1, j[1]);
j[3] = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 64LL);
v4 = ExpressionSize(j[1]);
result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL);
*(_QWORD *)(result + 64) += v4;
}
}
return result;
}

original_code:
void FindHashedExpressions(
  void *theEnv)
  {
   register unsigned i;
   EXPRESSION_HN *exphash;
   for (i = 0 ; i < 503 ; i++)
     for (exphash = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionHashTable[i] ; exphash != ((void *)0) ; exphash = exphash->next)
       {
        MarkNeededItems(theEnv,exphash->exp);
        exphash->bsaveID = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount;
        ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount += ExpressionSize(exphash->exp);
       }
  }

canonical_original_code:
void FindHashedExpressions(void *theEnv)
  {
   register unsigned int i;
   struct exprHashNode *exphash;
   for (i = 0 ; i < 503 ; i++)
     for (exphash = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionHashTable[i] ; exphash != ((void *)0) ; exphash = exphash->next)
       {
        MarkNeededItems(theEnv,exphash->exp);
        exphash->bsaveID = ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount;
        ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount += ExpressionSize(exphash->exp);
       }
  }

variable_types:
i
unsigned int

variable_types: struct exprHashNode { unsigned int hashval; unsigned int count; struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *exp; struct exprHashNode *next; long bsaveID; } *

user_defined_types: struct environmentData { unsigned int initialized; unsigned long environmentIndex; void *context; void *routerContext; void **theData; void (**cleanupFunctions)(void *); struct environmentCleanupFunction *listOfCleanupEnvironmentFunctions; struct environmentData *next; }


FactPatternParserFind

decompiled_code:
__int64 FactPatternParserFind()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
int FactPatternParserFind(
  SYMBOL_HN *theRelation)
  {
   return(1);
  }

canonical_original_code:
int FactPatternParserFind(struct symbolHashNode *theRelation)
  {
   return(1);
  }

variable_types: struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *

return_type: int


HashFact

decompiled_code:
__int64 __fastcall HashFact(__int64 a1)
{
int v1; // ebp

v1 = HashSymbol(*(_QWORD *)(**(_QWORD **)(a1 + 32) + 24LL), 7717LL);
return abs32((int)(HashMultifield(a1 + 96, 7717LL) + v1) % 7717);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebp

v1 = HashSymbol(*(_QWORD *)(**(_QWORD **)(a1 + 32) + 24LL), 7717LL);
return abs32((int)(HashMultifield(a1 + 96, 7717LL) + v1) % 7717);
}

original_code:
int HashFact(
  struct fact *theFact)
  {
   int count = 0;
   int hashValue;
   count += (int) HashSymbol((((struct symbolHashNode *) (theFact->whichDeftemplate->header.name))->contents),
                       7717);
   count += (int) HashMultifield(&theFact->theProposition,7717);
   hashValue = (int) (count % 7717);
   if (hashValue < 0) hashValue = - hashValue;
   return(hashValue);
  }

canonical_original_code:
int HashFact(struct fact *theFact)
  {
   int count = 0;
   int hashValue;
   count += (int) HashSymbol((((struct symbolHashNode *) (theFact->whichDeftemplate->header.name))->contents),
                       7717);
   count += (int) HashMultifield(&theFact->theProposition,7717);
   hashValue = (int) (count % 7717);
   if (hashValue < 0) hashValue = - hashValue;
   return(hashValue);
  }

variable_types: struct fact { struct patternEntity { struct patternEntityRecord { struct entityRecord { char *name; unsigned int type; unsigned int copyToEvaluate; unsigned int bitMap; unsigned int addsToRuleComplexity; void (*shortPrintFunction)(void *, char *, void *); void (*longPrintFunction)(void *, char *, void *); int (*deleteFunction)(void *, void *); int (*evaluateFunction)(void *, void *, struct dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; } *); void *(*getNextFunction)(void *, void *); void (*decrementBusyCount)(void *, void *); void (*incrementBusyCount)(void *, void *); void (*propagateDepth)(void *, void *); void (*markNeeded)(void *, void *); void (*install)(void *, void *); void (*deinstall)(void *, void *); struct userData { unsigned char dataID; struct userData *next; } *usrData; } base; void (*decrementBasisCount)(void *, void *); void (*incrementBasisCount)(void *, void *); void (*matchFunction)(void *, void *); int (*synchronized)(void *, void *); } *theInfo; void *dependents; unsigned int busyCount; long timeTag; } factHeader; struct deftemplate { struct constructHeader { struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *name; char *ppForm; struct defmoduleItemHeader { struct defmodule { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader **itemsArray; struct portItem { struct symbolHashNode *moduleName; struct symbolHashNode *constructType; struct symbolHashNode *constructName; struct portItem *next; } *importList; struct portItem *exportList; unsigned int visitedFlag; long bsaveID; struct userData *usrData; struct defmodule *next; } *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; } *whichModule; long bsaveID; struct constructHeader *next; struct userData *usrData; } header; struct templateSlot { struct symbolHashNode *slotName; unsigned int multislot; unsigned int noDefault; unsigned int defaultPresent; unsigned int defaultDynamic; struct constraintRecord { unsigned int anyAllowed; unsigned int symbolsAllowed; unsigned int stringsAllowed; unsigned int floatsAllowed; unsigned int integersAllowed; unsigned int instanceNamesAllowed; unsigned int instanceAddressesAllowed; unsigned int externalAddressesAllowed; unsigned int factAddressesAllowed; unsigned int voidAllowed; unsigned int anyRestriction; unsigned int symbolRestriction; unsigned int stringRestriction; unsigned int floatRestriction; unsigned int integerRestriction; unsigned int classRestriction; unsigned int instanceNameRestriction; unsigned int multifieldsAllowed; unsigned int singlefieldsAllowed; unsigned short bsaveIndex; struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *classList; struct expr *restrictionList; struct expr *minValue; struct expr *maxValue; struct expr *minFields; struct expr *maxFields; struct constraintRecord *multifield; struct constraintRecord *next; int bucket; int count; } *constraints; struct expr *defaultList; struct templateSlot *next; } *slotList; unsigned int implied; unsigned int watch; unsigned int inScope; unsigned short numberOfSlots; long busyCount; struct factPatternNode { struct patternNodeHeader { struct partialMatch { unsigned int betaMemory; unsigned int busy; unsigned int activationf; unsigned int dependentsf; unsigned int notOriginf; unsigned int counterf; unsigned int bcount; struct partialMatch *next; struct genericMatch { union { void *theValue; struct alphaMatch { struct patternEntity *matchingItem; struct multifieldMarker { int whichField; union { void *whichSlot; short whichSlotNumber; } where; long startPosition; long endPosition; struct multifieldMarker *next; } *markers; struct alphaMatch *next; } *theMatch; } gm; } binds[1]; } *alphaMemory; struct partialMatch *endOfQueue; struct joinNode { unsigned int firstJoin; unsigned int logicalJoin; unsigned int joinFromTheRight; unsigned int patternIsNegated; unsigned int initialize; unsigned int marked; unsigned int rhsType; unsigned int depth; long bsaveID; struct partialMatch *beta; struct expr *networkTest; void *rightSideEntryStructure; struct joinNode *nextLevel; struct joinNode *lastLevel; struct joinNode *rightDriveNode; struct joinNode *rightMatchNode; struct defrule { struct constructHeader header; int salience; int localVarCnt; unsigned int complexity; unsigned int afterBreakpoint; unsigned int watchActivation; unsigned int watchFiring; unsigned int autoFocus; unsigned int executing; struct expr *dynamicSalience; struct expr *actions; struct joinNode *logicalJoin; struct joinNode *lastJoin; struct defrule *disjunct; } *ruleToActivate; } *entryJoin; unsigned int singlefieldNode; unsigned int multifieldNode; unsigned int stopNode; unsigned int initialize; unsigned int marked; unsigned int beginSlot; unsigned int endSlot; } header; long bsaveID; unsigned short whichField; unsigned short whichSlot; unsigned short leaveFields; struct expr *networkTest; struct factPatternNode *nextLevel; struct factPatternNode *lastLevel; struct factPatternNode *leftNode; struct factPatternNode *rightNode; } *patternNetwork; struct fact *factList; struct fact *lastFact; } *whichDeftemplate; void *list; long factIndex; unsigned int depth; unsigned int garbage; struct fact *previousFact; struct fact *nextFact; struct fact *previousTemplateFact; struct fact *nextTemplateFact; struct multifield { unsigned int busyCount; short depth; unsigned long multifieldLength; struct multifield *next; struct field { unsigned short type; void *value; } theFields[1]; } theProposition; } *

variable_types: count int

variable_types: hashValue int

user_defined_types: struct fact { struct patternEntity factHeader; struct deftemplate *whichDeftemplate; void *list; long factIndex; unsigned int depth; unsigned int garbage; struct fact *previousFact; struct fact *nextFact; struct fact *previousTemplateFact; struct fact *nextTemplateFact; struct multifield theProposition; }

user_defined_types: struct patternEntity { struct patternEntityRecord *theInfo; void *dependents; unsigned int busyCount; long timeTag; }

user_defined_types: struct multifield { unsigned int busyCount; short depth; unsigned long multifieldLength; struct multifield *next; struct field theFields[1]; }

user_defined_types: struct deftemplate { struct constructHeader header; struct templateSlot *slotList; unsigned int implied; unsigned int watch; unsigned int inScope; unsigned short numberOfSlots; long busyCount; struct factPatternNode *patternNetwork; struct fact *factList; struct fact *lastFact; }

user_defined_types: struct patternEntityRecord { struct entityRecord base; void (*decrementBasisCount)(void *, void *); void (*incrementBasisCount)(void *, void *); void (*matchFunction)(void *, void *); int (*synchronized)(void *, void *); }

user_defined_types: struct templateSlot { struct symbolHashNode *slotName; unsigned int multislot; unsigned int noDefault; unsigned int defaultPresent; unsigned int defaultDynamic; struct constraintRecord *constraints; struct expr *defaultList; struct templateSlot *next; }

user_defined_types: struct factPatternNode { struct patternNodeHeader header; long bsaveID; unsigned short whichField; unsigned short whichSlot; unsigned short leaveFields; struct expr *networkTest; struct factPatternNode *nextLevel; struct factPatternNode *lastLevel; struct factPatternNode *leftNode; struct factPatternNode *rightNode; }

user_defined_types: struct defmoduleItemHeader { struct defmodule *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; }

user_defined_types: struct patternNodeHeader { struct partialMatch *alphaMemory; struct partialMatch *endOfQueue; struct joinNode *entryJoin; unsigned int singlefieldNode; unsigned int multifieldNode; unsigned int stopNode; unsigned int initialize; unsigned int marked; unsigned int beginSlot; unsigned int endSlot; }

user_defined_types: struct constraintRecord { unsigned int anyAllowed; unsigned int symbolsAllowed; unsigned int stringsAllowed; unsigned int floatsAllowed; unsigned int integersAllowed; unsigned int instanceNamesAllowed; unsigned int instanceAddressesAllowed; unsigned int externalAddressesAllowed; unsigned int factAddressesAllowed; unsigned int voidAllowed; unsigned int anyRestriction; unsigned int symbolRestriction; unsigned int stringRestriction; unsigned int floatRestriction; unsigned int integerRestriction; unsigned int classRestriction; unsigned int instanceNameRestriction; unsigned int multifieldsAllowed; unsigned int singlefieldsAllowed; unsigned short bsaveIndex; struct expr *classList; struct expr *restrictionList; struct expr *minValue; struct expr *maxValue; struct expr *minFields; struct expr *maxFields; struct constraintRecord *multifield; struct constraintRecord *next; int bucket; int count; }

user_defined_types: struct partialMatch { unsigned int betaMemory; unsigned int busy; unsigned int activationf; unsigned int dependentsf; unsigned int notOriginf; unsigned int counterf; unsigned int bcount; struct partialMatch *next; struct genericMatch binds[1]; }

user_defined_types: struct joinNode { unsigned int firstJoin; unsigned int logicalJoin; unsigned int joinFromTheRight; unsigned int patternIsNegated; unsigned int initialize; unsigned int marked; unsigned int rhsType; unsigned int depth; long bsaveID; struct partialMatch *beta; struct expr *networkTest; void *rightSideEntryStructure; struct joinNode *nextLevel; struct joinNode *lastLevel; struct joinNode *rightDriveNode; struct joinNode *rightMatchNode; struct defrule *ruleToActivate; }

user_defined_types: struct genericMatch { union { void *theValue; struct alphaMatch *theMatch; } gm; }

user_defined_types: struct alphaMatch { struct patternEntity *matchingItem; struct multifieldMarker *markers; struct alphaMatch *next; }


repo: jardiacaj/uaSW

decompiled_code:
void handle_sigint()
{
finalitza = 1;
close(sock_fd);
}

canonical_decompiled_code:
void func0()
{
finalitza = 1;
close(sock_fd);
}

original_code:
void handle_sigint(int signum) {
    finalitza = 1;
    close(sock_fd);
}

variable_types: signum int


decompiled_code:
int __fastcall modificar_nombre_fils(int a1)
{
pthread_mutex_lock(&nombre_fils_mutex);
nombre_fils += a1;
return pthread_mutex_unlock(&nombre_fils_mutex);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
pthread_mutex_lock(&nombre_fils_mutex);
nombre_fils += a1;
return pthread_mutex_unlock(&nombre_fils_mutex);
}

original_code:
void modificar_nombre_fils(int variacio) {
    pthread_mutex_lock(&nombre_fils_mutex);
    nombre_fils += variacio;
    pthread_mutex_unlock(&nombre_fils_mutex);
}

variable_types: variacio int


decompiled_code:
__int64 __fastcall crear_fil(int fd, __int64 a2, __int64 a3)
{
int v5; // er8
int v6; // edx
int v7; // edi
unsigned int v8; // ebp
__int64 *v9; // rax
int v10; // ebx
__int64 v11; // rax
void *(*v12)(void *); // rdx
int *v14; // rax
char *v15; // rax
__int64 v16; // rbx

v5 = max_fils;
v6 = max_fils_sobrecarrega + max_fils;
v7 = nombre_fils;
v8 = 1;
if ( max_fils_sobrecarrega + max_fils >= nombre_fils )
{
if ( v6 <= 0 )
{
v10 = 0;
}
else
{
v9 = fils;
v10 = 0;
while ( *v9 )
{
++v10;
v9 += 2232;
if ( v6 == v10 )
return 2;
}
}
if ( v6 == v10 )
{
v8 = 2;
}
else
{
v11 = 2232LL * v10;
LODWORD(fils[v11 + 1]) = fd;
*(__int64 *)((char *)&fils[v11 + 1] + 4) = a2;
*(__int64 *)((char *)&fils[v11 + 2] + 4) = a3;
v12 = (void *(*)(void *))&atendre_connexio;
if ( v5 <= v7 )
v12 = (void *(*)(void *))&atendre_sobrecarrega;
v8 = pthread_create((pthread_t *)&fils[2232 * v10], &atributs_fils, v12, &fils[2232 * v10]);
if ( v8 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, format, (unsigned int)nombre_fils, v15);
close(fd);
v16 = 2232LL * v10;
LODWORD(fils[v16 + 1]) = 0;
fils[v16] = 0LL;
v8 = 3;
}
else
{
modificar_nombre_fils(1);
}
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2, __int64 a3)
{
int v5; // er8
int v6; // edx
int v7; // edi
unsigned int v8; // ebp
__int64 *v9; // rax
int v10; // ebx
__int64 v11; // rax
void *(*v12)(void *); // rdx
int *v14; // rax
char *v15; // rax
__int64 v16; // rbx

v5 = max_fils;
v6 = max_fils_sobrecarrega + max_fils;
v7 = nombre_fils;
v8 = 1;
if ( max_fils_sobrecarrega + max_fils >= nombre_fils )
{
if ( v6 <= 0 )
{
v10 = 0;
}
else
{
v9 = fils;
v10 = 0;
while ( *v9 )
{
++v10;
v9 += 2232;
if ( v6 == v10 )
return 2;
}
}
if ( v6 == v10 )
{
v8 = 2;
}
else
{
v11 = 2232LL * v10;
LODWORD(fils[v11 + 1]) = fd;
*(__int64 *)((char *)&fils[v11 + 1] + 4) = a2;
*(__int64 *)((char *)&fils[v11 + 2] + 4) = a3;
v12 = (void *(*)(void *))&atendre_connexio;
if ( v5 <= v7 )
v12 = (void *(*)(void *))&atendre_sobrecarrega;
v8 = pthread_create((pthread_t *)&fils[2232 * v10], &atributs_fils, v12, &fils[2232 * v10]);
if ( v8 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, format, (unsigned int)nombre_fils, v15);
close(fd);
v16 = 2232LL * v10;
LODWORD(fils[v16 + 1]) = 0;
fils[v16] = 0LL;
v8 = 3;
}
else
{
func1(1);
}
}
}
return v8;
}

original_code:
int crear_fil(int descriptor, struct sockaddr_in adreca) {
    void *(*rutina_fil)(void *);
    int i;
    if(nombre_fils > max_fils + max_fils_sobrecarrega) return 1;
    for(i=0; i < max_fils + max_fils_sobrecarrega; i++) {
        if(fils[i].pthread_obj == 0) break;
    }
    if(i == max_fils + max_fils_sobrecarrega) return 2;
    fils[i].descriptor = descriptor;
    fils[i].adreca_remota = adreca;
    if(nombre_fils < max_fils) rutina_fil = atendre_connexio;
    else rutina_fil = atendre_sobrecarrega;
    if(pthread_create(&fils[i].pthread_obj, &atributs_fils, rutina_fil, (void*) &fils[i])) {
        fprintf(stderr, "Fil principal - error al crear fil d'execució (%i fils executant-se): %s\n", nombre_fils, strerror((*__errno_location ())));
        close(descriptor);
        fils[i].descriptor = 0;
        fils[i].pthread_obj = 0;
        return 3;
    } else {
        modificar_nombre_fils(1);
        return 0;
    }
}

canonical_original_code:
int crear_fil(int descriptor, struct sockaddr_in adreca) {
    void *(*rutina_fil)(void *);
    int i;
    if(nombre_fils > max_fils + max_fils_sobrecarrega) return 1;
    for(i=0; i < max_fils + max_fils_sobrecarrega; i++) {
        if(fils[i].pthread_obj == 0) break;
    }
    if(i == max_fils + max_fils_sobrecarrega) return 2;
    fils[i].descriptor = descriptor;
    fils[i].adreca_remota = adreca;
    if(nombre_fils < max_fils) rutina_fil = atendre_connexio;
    else rutina_fil = atendre_sobrecarrega;
    if(pthread_create(&fils[i].pthread_obj, &atributs_fils, rutina_fil, (void *) &fils[i])) {
        fprintf(stderr, "Fil principal - error al crear fil d'execució (%i fils executant-se): %s\n", nombre_fils, strerror((*__errno_location ())));
        close(descriptor);
        fils[i].descriptor = 0;
        fils[i].pthread_obj = 0;
        return 3;
    } else {
        modificar_nombre_fils(1);
        return 0;
    }
}

variable_types: descriptor int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: i int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
__int64 preparar_socket()
{
int v0; // eax
unsigned int v1; // ebp
struct addrinfo *i; // rbx
int v3; // edi
const char *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int optval; // [rsp+Ch] [rbp-4Ch] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

optval = 1;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v0 = getaddrinfo(0LL, &port_escolta, &req, &servinfo);
v1 = v0;
if ( v0 )
{
v5 = gai_strerror(v0);
fprintf(stderr, "Fil principal - error al preparar addrinfo: %s\n", v5);
v1 = 1;
}
else
{
for ( i = servinfo; i; i = i->ai_next )
{
v3 = socket(i->ai_family, i->ai_socktype | 0x80000, i->ai_protocol);
sock_fd = v3;
if ( v3 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Fil principal - error al preparar el socket: %s\n", v7);
}
else
{
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 || setsockopt(sock_fd, 6, 3, &optval, 4u) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Fil principal - error al configurar el socket: %s.\n", v9);
return 2;
}
if ( bind(sock_fd, i->ai_addr, i->ai_addrlen) != -1 )
return v1;
close(sock_fd);
}
}
fprintf(stderr, "Fil principal - no s'ha pogut obrir un socket amb el port %s.\n", &port_escolta);
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
unsigned int v1; // ebp
struct addrinfo *i; // rbx
int v3; // edi
const char *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int optval; // [rsp+Ch] [rbp-4Ch] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

optval = 1;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v0 = getaddrinfo(0LL, &port_escolta, &req, &servinfo);
v1 = v0;
if ( v0 )
{
v5 = gai_strerror(v0);
fprintf(stderr, "Fil principal - error al preparar addrinfo: %s\n", v5);
v1 = 1;
}
else
{
for ( i = servinfo; i; i = i->ai_next )
{
v3 = socket(i->ai_family, i->ai_socktype | 0x80000, i->ai_protocol);
sock_fd = v3;
if ( v3 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Fil principal - error al preparar el socket: %s\n", v7);
}
else
{
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 || setsockopt(sock_fd, 6, 3, &optval, 4u) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Fil principal - error al configurar el socket: %s.\n", v9);
return 2;
}
if ( bind(sock_fd, i->ai_addr, i->ai_addrlen) != -1 )
return v1;
close(sock_fd);
}
}
fprintf(stderr, "Fil principal - no s'ha pogut obrir un socket amb el port %s.\n", &port_escolta);
v1 = 1;
}
return v1;
}

original_code:
int preparar_socket() {
    struct addrinfo *p;
    struct addrinfo hints;
    int on = 1;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 2;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = 0;
    hints.ai_flags = 0x0001;
    int retorn_gai;
    if(retorn_gai = getaddrinfo(((void *)0), port_escolta, &hints, &servinfo)) {
        fprintf(stderr, "Fil principal - error al preparar addrinfo: %s\n", gai_strerror(retorn_gai));
        return 1;
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((sock_fd = socket(p->ai_family, p->ai_socktype | SOCK_CLOEXEC, p->ai_protocol)) == -1) {
            fprintf(stderr, "Fil principal - error al preparar el socket: %s\n", strerror((*__errno_location ())));
            continue;
        }
        if(setsockopt(sock_fd, 1, 2, &on, sizeof(on)) == -1) {
            fprintf(stderr, "Fil principal - error al configurar el socket: %s.\n", strerror((*__errno_location ())));
            return 2;
        }
        if(setsockopt(sock_fd, IPPROTO_TCP, 3, &on, sizeof(on)) == -1) {
            fprintf(stderr, "Fil principal - error al configurar el socket: %s.\n", strerror((*__errno_location ())));
            return 2;
        }
        if (bind(sock_fd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sock_fd);
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "Fil principal - no s'ha pogut obrir un socket amb el port %s.\n", port_escolta);
        return 1;
    }
    return 0;
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: on int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


neteja

decompiled_code:
__int64 neteja()
{
pthread_attr_destroy(&atributs_fils);
freeaddrinfo(servinfo);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
pthread_attr_destroy(&atributs_fils);
freeaddrinfo(servinfo);
return 0LL;
}

original_code:
int neteja() {
    pthread_attr_destroy(&atributs_fils);
    freeaddrinfo(servinfo);
    return 0;
}


decompiled_code:
void __noreturn handle_sigterm()
{
fwrite("Aturant...\n", 1uLL, 0xBuLL, stdout);
neteja();
exit(0);
}

canonical_decompiled_code:
void __noreturn func5()
{
fwrite("Aturant...\n", 1uLL, 0xBuLL, stdout);
func4();
exit(0);
}

original_code:
void handle_sigterm(int signum) {
    fprintf(stdout, "Aturant...\n");
    neteja();
    exit(0);
}


decompiled_code:
__int64 preparar_pthread_attr()
{
pthread_attr_init(&atributs_fils);
pthread_attr_setstacksize(&atributs_fils, 0xC350uLL);
pthread_attr_setscope(&atributs_fils, 1);
pthread_attr_setdetachstate(&atributs_fils, 1);
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
pthread_attr_init(&atributs_fils);
pthread_attr_setstacksize(&atributs_fils, 0xC350uLL);
pthread_attr_setscope(&atributs_fils, 1);
pthread_attr_setdetachstate(&atributs_fils, 1);
return 0LL;
}

original_code:
int preparar_pthread_attr() {
    pthread_attr_init(&atributs_fils);
    pthread_attr_setstacksize (&atributs_fils, 50000);
    pthread_attr_setscope(&atributs_fils, PTHREAD_SCOPE_PROCESS);
    pthread_attr_setdetachstate(&atributs_fils, PTHREAD_CREATE_DETACHED);
    return 0;
}


daemonitza

decompiled_code:
__pid_t daemonitza()
{
__pid_t result; // eax
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax

fwrite(&unk_8844C8, 1uLL, 0x23uLL, stdout);
close(0);
if ( open("/dev/null", 2) == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "Fil principal - error al obrir /dev/null: %s\n", v2);
exit(1);
}
close(2);
if ( open(&log_errors, 1089, 416LL) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stdout, "Fil principal - error al obrir el log d'errors (%s): %s\n", &log_errors, v4);
}
close(1);
if ( open(&log_principal, 1089, 416LL) == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Fil principal - error al obrir el log principal (%s): %s\n", &log_principal, v6);
}
result = fork();
if ( result < 0 )
{
fwrite("Fil principal - error al fork inicial.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
if ( result > 0 )
exit(0);
return result;
}

canonical_decompiled_code:
__pid_t func7()
{
__pid_t result; // eax
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax

fwrite(&unk_8844C8, 1uLL, 0x23uLL, stdout);
close(0);
if ( open("/dev/null", 2) == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "Fil principal - error al obrir /dev/null: %s\n", v2);
exit(1);
}
close(2);
if ( open(&log_errors, 1089, 416LL) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stdout, "Fil principal - error al obrir el log d'errors (%s): %s\n", &log_errors, v4);
}
close(1);
if ( open(&log_principal, 1089, 416LL) == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Fil principal - error al obrir el log principal (%s): %s\n", &log_principal, v6);
}
result = fork();
if ( result < 0 )
{
fwrite("Fil principal - error al fork inicial.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
if ( result > 0 )
exit(0);
return result;
}

original_code:
void daemonitza() {
    int i;
    fprintf(stdout, "L'execució continua en segon pla.\n");
    close(0);
    if(open("/dev/null", 02) == -1) {
        fprintf(stderr, "Fil principal - error al obrir /dev/null: %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    close(2);
    if(open(log_errors, 01 | 02000 | 0100, 0400|0200|(0400 >> 3)) == -1) {
        fprintf(stdout, "Fil principal - error al obrir el log d'errors (%s): %s\n", log_errors, strerror((*__errno_location ())));
    }
    close(1);
    if(open(log_principal, 01 | 02000 | 0100, 0400|0200|(0400 >> 3)) == -1) {
        fprintf(stderr, "Fil principal - error al obrir el log principal (%s): %s\n", log_principal, strerror((*__errno_location ())));
    }
    i = fork();
    if (i < 0) {
        fprintf(stderr, "Fil principal - error al fork inicial.\n");
        exit(1);
    }
    if (i > 0) {
        exit(0);
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int *v4; // rax
char *v5; // rax
char *v6; // rax
int v7; // eax
int v8; // edi
char *v9; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
printf(aSJoanArdiacaJo, "uaSW/0.3", envp);
umask(0x17u);
signal(2, (__sighandler_t)handle_sigint);
signal(15, (__sighandler_t)handle_sigterm);
signal(13, (__sighandler_t)((char *)handle_sigint + 1));
if ( argc > 2 )
{
strncpy(&arxiu_configuracio, argv[2], 0xC8uLL);
if ( !(unsigned int)llegir_configuracio() )
{
LABEL_4:
v3 = argv[1];
if ( strcmp(v3, "n") && strcmp(v3, "normal") )
{
if ( strcmp(v3, "d") && strcmp(v3, "daemon") )
{
printf(
"Argument incorrecte: %s. Hauria de ser 'normal' per a iniciar el servidor normalment o 'daemon' per a inicia"
"r-lo en mode dimoni.",
v3);
exit(1);
}
daemonitza();
}
LABEL_9:
if ( (unsigned int)preparar_socket() )
exit(1);
if ( (unsigned int)preparar_pthread_attr() )
exit(1);
if ( listen(sock_fd, mida_cua_entrants) )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Fil principal - error al posar el socket en mode escoltar: %s\n", v5);
exit(1);
}
fprintf(stdout, "Servidor HTTP iniciat, esperant connexions entrants pel port %s...\n", &port_escolta);
if ( finalitza )
{
LABEL_28:
neteja();
puts("Sortint. S'atendran les peticions pendents.\n");
pthread_exit(0LL);
}
while ( 1 )
{
v7 = accept4(sock_fd, &addr, &addr_len, (int)&unk_80000);
if ( v7 >= 0 )
{
crear_fil(v7, *(__int64 *)&addr.sa_family, *(__int64 *)&addr.sa_data[6]);
}
else
{
v8 = *_errno_location();
if ( v8 == 9 )
{
if ( finalitza == 1 )
goto LABEL_28;
}
else if ( v8 == 95 || v8 == 88 || ((v8 - 14) & 0xFFFFFFF7) == 0 )
{
v9 = strerror(v8);
fprintf(stderr, aFilPrincipalEr_8, v9);
goto LABEL_28;
}
v6 = strerror(v8);
fprintf(stderr, aFilPrincipalEr_7, v6);
}
if ( finalitza )
goto LABEL_28;
}
}
}
else if ( !(unsigned int)llegir_configuracio() )
{
if ( argc != 2 )
goto LABEL_9;
goto LABEL_4;
}
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int *v4; // rax
char *v5; // rax
char *v6; // rax
int v7; // eax
int v8; // edi
char *v9; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
printf(aSJoanArdiacaJo, "uaSW/0.3", envp);
umask(0x17u);
signal(2, (__sighandler_t)handle_sigint);
signal(15, (__sighandler_t)handle_sigterm);
signal(13, (__sighandler_t)((char *)handle_sigint + 1));
if ( argc > 2 )
{
strncpy(&arxiu_configuracio, argv[2], 0xC8uLL);
if ( !(unsigned int)llegir_configuracio() )
{
LABEL_4:
v3 = argv[1];
if ( strcmp(v3, "n") && strcmp(v3, "normal") )
{
if ( strcmp(v3, "d") && strcmp(v3, "daemon") )
{
printf(
"Argument incorrecte: %s. Hauria de ser 'normal' per a iniciar el servidor normalment o 'daemon' per a inicia"
"r-lo en mode dimoni.",
v3);
exit(1);
}
func7();
}
LABEL_9:
if ( (unsigned int)func3() )
exit(1);
if ( (unsigned int)func6() )
exit(1);
if ( listen(sock_fd, mida_cua_entrants) )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Fil principal - error al posar el socket en mode escoltar: %s\n", v5);
exit(1);
}
fprintf(stdout, "Servidor HTTP iniciat, esperant connexions entrants pel port %s...\n", &port_escolta);
if ( finalitza )
{
LABEL_28:
func4();
puts("Sortint. S'atendran les peticions pendents.\n");
pthread_exit(0LL);
}
while ( 1 )
{
v7 = accept4(sock_fd, &addr, &addr_len, (int)&unk_80000);
if ( v7 >= 0 )
{
func2(v7, *(__int64 *)&addr.sa_family, *(__int64 *)&addr.sa_data[6]);
}
else
{
v8 = *_errno_location();
if ( v8 == 9 )
{
if ( finalitza == 1 )
goto LABEL_28;
}
else if ( v8 == 95 || v8 == 88 || ((v8 - 14) & 0xFFFFFFF7) == 0 )
{
v9 = strerror(v8);
fprintf(stderr, aFilPrincipalEr_8, v9);
goto LABEL_28;
}
v6 = strerror(v8);
fprintf(stderr, aFilPrincipalEr_7, v6);
}
if ( finalitza )
goto LABEL_28;
}
}
}
else if ( !(unsigned int)llegir_configuracio() )
{
if ( argc != 2 )
goto LABEL_9;
goto LABEL_4;
}
exit(1);
}

original_code:
int main(int argc, char** argv) {
    struct sockaddr_in adr_remota;
    socklen_t sizeof_adr_remota = sizeof adr_remota;;
    int nou_descriptor;
    printf("%s - Joan Ardiaca Jové 2010\n", "uaSW/0.3");
    umask(027);
    signal(2, handle_sigint);
    signal(15, handle_sigterm);
    signal(13, ((__sighandler_t) 1));
    if(argc > 2) strncpy(arxiu_configuracio, argv[2], sizeof(arxiu_configuracio));
    if(llegir_configuracio()) exit (1);
    if(argc > 1) {
        if(strcmp(argv[1], "n") == 0 || strcmp(argv[1], "normal") == 0) {
        } else if(strcmp(argv[1], "d") == 0 || strcmp(argv[1], "daemon") == 0) {
            daemonitza();
        } else {
            printf("Argument incorrecte: %s. Hauria de ser 'normal' per a iniciar el servidor normalment o 'daemon' per a iniciar-lo en mode dimoni.", argv[1]);
            exit(1);
        }
    }
    if(preparar_socket()) exit (1);
    if(preparar_pthread_attr()) exit (1);
    if(listen(sock_fd, mida_cua_entrants)) {
        fprintf(stderr, "Fil principal - error al posar el socket en mode escoltar: %s\n", strerror((*__errno_location ())));
        exit (1);
    }
    fprintf(stdout, "Servidor HTTP iniciat, esperant connexions entrants pel port %s...\n", port_escolta);
    while(finalitza == 0) {
        nou_descriptor = accept4(sock_fd, (struct sockaddr *) &adr_remota, &sizeof_adr_remota, SOCK_CLOEXEC);
        if(nou_descriptor < 0) {
            if((*__errno_location ()) == 9 && finalitza == 1) break;
            else if((*__errno_location ()) == 14 || (*__errno_location ()) == 22 || (*__errno_location ()) == 88 || (*__errno_location ()) == 95) {
                fprintf(stderr, "Fil principal - error irrecuperable al esperar connexió: %s\n", strerror((*__errno_location ())));
                break;
            } else fprintf(stderr, "Fil principal - error al acceptar connexió: %s\n", strerror((*__errno_location ())));
        } else {
            crear_fil(nou_descriptor, adr_remota);
        }
    }
    neteja();
    printf("Sortint. S'atendran les peticions pendents.\n\n");
    pthread_exit(((void *)0));
}

canonical_original_code:
int main(int argc, char **argv) {
    struct sockaddr_in adr_remota;
    unsigned int sizeof_adr_remota = sizeof adr_remota;;
    int nou_descriptor;
    printf("%s - Joan Ardiaca Jové 2010\n", "uaSW/0.3");
    umask(027);
    signal(2, handle_sigint);
    signal(15, handle_sigterm);
    signal(13, ((void (*)(int)) 1));
    if(argc > 2) strncpy(arxiu_configuracio, argv[2], sizeof(arxiu_configuracio));
    if(llegir_configuracio()) exit (1);
    if(argc > 1) {
        if(strcmp(argv[1], "n") == 0 || strcmp(argv[1], "normal") == 0) {
        } else if(strcmp(argv[1], "d") == 0 || strcmp(argv[1], "daemon") == 0) {
            daemonitza();
        } else {
            printf("Argument incorrecte: %s. Hauria de ser 'normal' per a iniciar el servidor normalment o 'daemon' per a iniciar-lo en mode dimoni.", argv[1]);
            exit(1);
        }
    }
    if(preparar_socket()) exit (1);
    if(preparar_pthread_attr()) exit (1);
    if(listen(sock_fd, mida_cua_entrants)) {
        fprintf(stderr, "Fil principal - error al posar el socket en mode escoltar: %s\n", strerror((*__errno_location ())));
        exit (1);
    }
    fprintf(stdout, "Servidor HTTP iniciat, esperant connexions entrants pel port %s...\n", port_escolta);
    while(finalitza == 0) {
        nou_descriptor = accept4(sock_fd, (struct sockaddr *) &adr_remota, &sizeof_adr_remota, SOCK_CLOEXEC);
        if(nou_descriptor < 0) {
            if((*__errno_location ()) == 9 && finalitza == 1) break;
            else if((*__errno_location ()) == 14 || (*__errno_location ()) == 22 || (*__errno_location ()) == 88 || (*__errno_location ()) == 95) {
                fprintf(stderr, "Fil principal - error irrecuperable al esperar connexió: %s\n", strerror((*__errno_location ())));
                break;
            } else fprintf(stderr, "Fil principal - error al acceptar connexió: %s\n", strerror((*__errno_location ())));
        } else {
            crear_fil(nou_descriptor, adr_remota);
        }
    }
    neteja();
    printf("Sortint. S'atendran les peticions pendents.\n\n");
    pthread_exit(((void *)0));
}

variable_types: argc int

variable_types:
argv
char **

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


getId

decompiled_code:
__int64 __fastcall getId(__int64 a1)
{
printf("Enter ID: ");
return _isoc99_scanf("%s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
printf("Enter ID: ");
return _isoc99_scanf("%s", a1);
}

original_code:
void getId(char* id)
{
 printf("Enter ID: ");
 scanf("%s",id);
 return;
}

canonical_original_code:
void getId(char *id)
{
 printf("Enter ID: ");
 scanf("%s",id);
 return;
}

variable_types:
id
char *


getTestSelection

decompiled_code:
__int64 getTestSelection()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Ten tests are available. Select a test: ");
_isoc99_scanf("%i", v1);
return v1[0];
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Ten tests are available. Select a test: ");
_isoc99_scanf("%i", v1);
return v1[0];
}

original_code:
int getTestSelection(){
 int selection;
 do{
  printf("Ten tests are available. Select a test: ");
  scanf("%i",&selection);
  if (!(0 < selection <= 10))
   printf("Invalid Selection. Try again.\n");
 } while (!(0 < selection <= 10));
 return selection;
}

variable_types: selection int


top

decompiled_code:
__int64 __fastcall top(__int64 *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
Node* top(Stack* stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 return stack->top;
}

canonical_original_code:
struct nodeStruct *top(struct Stack *stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 return stack->top;
}

variable_types: struct Stack { struct nodeStruct *top; int size; } *

return_type: struct nodeStruct { int number; char answer; char myAnswer; char question[200]; struct nodeStruct *next; } *


pop

decompiled_code:
__int64 __fastcall pop(__int64 *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = *a1;
if ( *a1 )
{
*a1 = *(_QWORD *)(result + 208);
--*((_DWORD *)a1 + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = *a1;
if ( *a1 )
{
*a1 = *(_QWORD *)(result + 208);
--*((_DWORD *)a1 + 2);
}
return result;
}

original_code:
Node* pop(Stack* stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 if (stack->top == ((void *)0))
  return ((void *)0);
 Node* oldTop = stack->top;
 stack->top = stack->top->next;
 stack->size--;
 return oldTop;
}

canonical_original_code:
struct nodeStruct *pop(struct Stack *stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 if (stack->top == ((void *)0))
  return ((void *)0);
 struct nodeStruct *oldTop = stack->top;
 stack->top = stack->top->next;
 stack->size--;
 return oldTop;
}

variable_types: struct nodeStruct { int number; char answer; char myAnswer; char question[200]; struct nodeStruct *next; } *

user_defined_types: struct Stack { struct nodeStruct *top; int size; }


push

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

result = *a2;
*(_QWORD *)(a1 + 208) = *a2;
*a2 = a1;
++*((_DWORD *)a2 + 2);
return result;
}

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

result = *a2;
*(_QWORD *)(a1 + 208) = *a2;
*a2 = a1;
++*((_DWORD *)a2 + 2);
return result;
}

original_code:
void push(Node* node, Stack* stack)
{
 node->next = stack->top;
 stack->top = node;
 stack->size++;
 return;
}

canonical_original_code:
void push(struct nodeStruct *node, struct Stack *stack)
{
 node->next = stack->top;
 stack->top = node;
 stack->size++;
 return;
}

user_defined_types: struct nodeStruct { int number; char answer; char myAnswer; char question[200]; struct nodeStruct *next; }


getNode

original_code:
Node* getNode(Stack* stack, int index)
{
 if (index > stack->size)
  return ((void *)0);
 Node* current = stack->top;
 for (int i = 1; i<index; i++)
  current = current->next;
 return current;
}

canonical_original_code:
struct nodeStruct *getNode(struct Stack *stack, int index)
{
 if (index > stack->size)
  return ((void *)0);
 struct nodeStruct *current = stack->top;
 for (int i = 1; i<index; i++)
  current = current->next;
 return current;
}

variable_types: index int


makeStack

decompiled_code:
_DWORD *makeStack()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

canonical_decompiled_code:
_DWORD *func10()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

original_code:
Stack* makeStack()
{
 Stack* current = malloc(sizeof(Stack));
 current->size = 0;
 current->top = ((void *)0);
 return current;
}

canonical_original_code:
struct Stack *makeStack()
{
 struct Stack *current = malloc(sizeof(Stack));
 current->size = 0;
 current->top = ((void *)0);
 return current;
}

variable_types: struct Stack { struct nodeStruct { int number; char answer; char myAnswer; char question[200]; struct nodeStruct *next; } *top; int size; } *


destroyStack

decompiled_code:
void __fastcall destroyStack(void *ptr)
{
void *v1; // rax

while ( 1 )
{
v1 = (void *)pop((__int64 *)ptr);
if ( !v1 )
break;
free(v1);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
void *v1; // rax

while ( 1 )
{
v1 = (void *)func5((__int64 *)ptr);
if ( !v1 )
break;
free(v1);
}
free(ptr);
}

original_code:
void destroyStack(Stack* stack)
{
 Node* current = ((void *)0);
 do{
  current = pop(stack);
  if (current != ((void *)0))
   free(current);
 }while (current !=((void *)0));
 free(stack);
 return;
}

canonical_original_code:
void destroyStack(struct Stack *stack)
{
 struct nodeStruct *current = ((void *)0);
 do{
  current = pop(stack);
  if (current != ((void *)0))
   free(current);
 }while (current !=((void *)0));
 free(stack);
 return;
}


MakeEmptyList

decompiled_code:
void __fastcall MakeEmptyList(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void MakeEmptyList(List L)
{
 L->Prev = ((void *)0);
 L->Next = ((void *)0);
 return;
}

canonical_original_code:
void MakeEmptyList(struct Node *L)
{
 L->Prev = ((void *)0);
 L->Next = ((void *)0);
 return;
}

variable_types: struct Node { int Element; struct Node *Prev; struct Node *Next; } *


DisplayList

decompiled_code:
unsigned int *__fastcall DisplayList(__int64 a1)
{
unsigned int *result; // rax

result = *(unsigned int **)(a1 + 16);
if ( result )
{
printf("%i\n", *result);
result = (unsigned int *)DisplayList(*(_QWORD *)(a1 + 16));
}
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func11(__int64 a1)
{
unsigned int *result; // rax

result = *(unsigned int **)(a1 + 16);
if ( result )
{
printf("%i\n", *result);
result = (unsigned int *)func11(*(_QWORD *)(a1 + 16));
}
return result;
}

original_code:
void DisplayList(List L)
{
 if (L->Next != ((void *)0)){
  printf("%i\n",L->Next->Element);
  DisplayList(L->Next);
 }
 return;
}

canonical_original_code:
void DisplayList(struct Node *L)
{
 if (L->Next != ((void *)0)){
  printf("%i\n",L->Next->Element);
  DisplayList(L->Next);
 }
 return;
}

user_defined_types: struct Node { int Element; struct Node *Prev; struct Node *Next; }


DeleteItem

decompiled_code:
void __fastcall DeleteItem(int a1, _QWORD *a2)
{
__int64 v2; // rax

if ( *(_DWORD *)a2 == a1 )
{
v2 = a2[2];
*(_QWORD *)(a2[1] + 16LL) = v2;
if ( v2 )
*(_QWORD *)(v2 + 8) = a2[1];
free(a2);
}
else if ( a2[2] )
{
DeleteItem();
}
}

original_code:
void DeleteItem(ElementType X, List L)
{
 if (L->Element == X){
  L->Prev->Next = L->Next;
  if (L->Next != ((void *)0))
   L->Next->Prev = L->Prev;
  free(L);
 }else if (L->Next != ((void *)0)) {
  DeleteItem(X,L->Next);
 }
 return;
}

canonical_original_code:
void DeleteItem(int X, struct Node *L)
{
 if (L->Element == X){
  L->Prev->Next = L->Next;
  if (L->Next != ((void *)0))
   L->Next->Prev = L->Prev;
  free(L);
 }else if (L->Next != ((void *)0)) {
  DeleteItem(X,L->Next);
 }
 return;
}

variable_types: X int


DestroyList

decompiled_code:
void __fastcall DestroyList(_QWORD *a1)
{
if ( a1[2] )
DestroyList();
free(a1);
}

canonical_decompiled_code:
void __fastcall func14(_QWORD *a1)
{
if ( a1[2] )
func14();
free(a1);
}

original_code:
void DestroyList(List L)
{
 if (L->Next != ((void *)0))
  DestroyList(L->Next);
  L->Next = ((void *)0);
 free(L);
 return;
}

canonical_original_code:
void DestroyList(struct Node *L)
{
 if (L->Next != ((void *)0))
  DestroyList(L->Next);
  L->Next = ((void *)0);
 free(L);
 return;
}


IsEmpty

decompiled_code:
_BOOL8 __fastcall IsEmpty(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
int IsEmpty(List L)
{
 if (L->Next == ((void *)0))
  return 1;
 else
  return 0;
}

canonical_original_code:
int IsEmpty(struct Node *L)
{
 if (L->Next == ((void *)0))
  return 1;
 else
  return 0;
}


IsFirst

decompiled_code:
_BOOL8 __fastcall IsFirst(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a2 + 8) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a2 + 8) == 0LL;
}

original_code:
int IsFirst(Position P, List L)
{
 if (L->Prev == ((void *)0))
  return 1;
 else
  return 0;
}

canonical_original_code:
int IsFirst(struct Node *P, struct Node *L)
{
 if (L->Prev == ((void *)0))
  return 1;
 else
  return 0;
}

variable_types:
L
struct Node *


IsLast

decompiled_code:
_BOOL8 __fastcall IsLast(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a2 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a2 + 16) == 0LL;
}

original_code:
int IsLast(Position P, List L)
{
 if (L->Next == ((void *)0))
  return 1;
 else
  return 0;
}

canonical_original_code:
int IsLast(struct Node *P, struct Node *L)
{
 if (L->Next == ((void *)0))
  return 1;
 else
  return 0;
}


FindItemPos

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

result = a2;
if ( a2 )
{
if ( *(_DWORD *)a2 != (_DWORD)a1 )
result = FindItemPos(a1, *(_QWORD *)(a2 + 16));
}
return result;
}

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

result = a2;
if ( a2 )
{
if ( *(_DWORD *)a2 != (_DWORD)a1 )
result = func18(a1, *(_QWORD *)(a2 + 16));
}
return result;
}

original_code:
Position FindItemPos(ElementType X, List L)
{
 if (L == ((void *)0))
  return ((void *)0);
 else if (L->Element == X)
  return L;
 else
  return FindItemPos(X, L->Next);
}

canonical_original_code:
struct Node *FindItemPos(int X, struct Node *L)
{
 if (L == ((void *)0))
  return ((void *)0);
 else if (L->Element == X)
  return L;
 else
  return FindItemPos(X, L->Next);
}

return_type: struct Node { int Element; struct Node *Prev; struct Node *Next; } *


DeleteList

decompiled_code:
void __fastcall DeleteList(__int64 a1)
{
DestroyList(*(_QWORD **)(a1 + 16));
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void DeleteList(List L)
{
 DestroyList(L->Next);
 L->Next = ((void *)0);
 L->Prev = ((void *)0);
 return;
}

canonical_original_code:
void DeleteList(struct Node *L)
{
 DestroyList(L->Next);
 L->Next = ((void *)0);
 L->Prev = ((void *)0);
 return;
}


UserMenu

decompiled_code:
__int64 __fastcall UserMenu(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 v2; // [rsp+0h] [rbp-78h]

puts("\nOptions:\n");
puts("1) Exit");
puts("2) Make an empty list");
puts("3) Build list using file 'prog04in.dat'");
puts("4) Display the list");
puts("5) Find an item");
puts("6) Insert an item");
puts("7) Delete an item");
puts("8) Save the list in file 'prog04out.dat'");
puts("9) Destroy the list");
printf("\nYour selection: ");
__isoc99_scanf();
result = v2;
*a1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 v2; // [rsp+0h] [rbp-78h]

puts("\nOptions:\n");
puts("1) Exit");
puts("2) Make an empty list");
puts("3) Build list using file 'prog04in.dat'");
puts("4) Display the list");
puts("5) Find an item");
puts("6) Insert an item");
puts("7) Delete an item");
puts("8) Save the list in file 'prog04out.dat'");
puts("9) Destroy the list");
printf("\nYour selection: ");
__isoc99_scanf();
result = v2;
*a1 = v2;
return result;
}

original_code:
char UserMenu(char* opt)
{
 char buffer[100];
 printf("\nOptions:\n\n");
 printf("1) Exit\n");
 printf("2) Make an empty list\n");
 printf("3) Build list using file 'prog04in.dat'\n");
 printf("4) Display the list\n");
 printf("5) Find an item\n");
 printf("6) Insert an item\n");
 printf("7) Delete an item\n");
 printf("8) Save the list in file 'prog04out.dat'\n");
 printf("9) Destroy the list\n");
 printf("\nYour selection: ");
 scanf("%s",buffer);
 *opt = buffer[0];
 return *opt;
}

canonical_original_code:
char UserMenu(char *opt)
{
 char buffer[100];
 printf("\nOptions:\n\n");
 printf("1) Exit\n");
 printf("2) Make an empty list\n");
 printf("3) Build list using file 'prog04in.dat'\n");
 printf("4) Display the list\n");
 printf("5) Find an item\n");
 printf("6) Insert an item\n");
 printf("7) Delete an item\n");
 printf("8) Save the list in file 'prog04out.dat'\n");
 printf("9) Destroy the list\n");
 printf("\nYour selection: ");
 scanf("%s",buffer);
 *opt = buffer[0];
 return *opt;
}

variable_types:
opt
char *

variable_types:
buffer
char [100]

return_type: char


ExitProg

decompiled_code:
void __noreturn ExitProg()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
exit(0);
}

original_code:
void ExitProg(void)
{
 exit(0);
 return;
}

canonical_original_code:
void ExitProg()
{
 exit(0);
 return;
}


DisplayGrade

decompiled_code:
int __fastcall DisplayGrade(char *s2, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
int result; // eax
int v8; // er12
char *v9; // rbx

result = printf("%i", (unsigned int)numStudents);
if ( numStudents > 0 )
{
v8 = 0;
v9 = &a7;
do
{
v9 = (char *)*((_QWORD *)v9 + 6);
printf("id: %s %s\n", v9 + 7, s2);
result = strcmp(v9 + 7, s2);
if ( !result )
result = printf("%s %s %s %lf %lf\n", v9, v9 + 7, v9 + 16, *((double *)v9 + 4), *((double *)v9 + 5));
++v8;
}
while ( numStudents > v8 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(char *s2, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
int result; // eax
int v8; // er12
char *v9; // rbx

result = printf("%i", (unsigned int)numStudents);
if ( numStudents > 0 )
{
v8 = 0;
v9 = &a7;
do
{
v9 = (char *)*((_QWORD *)v9 + 6);
printf("id: %s %s\n", v9 + 7, s2);
result = strcmp(v9 + 7, s2);
if ( !result )
result = printf("%s %s %s %lf %lf\n", v9, v9 + 7, v9 + 16, *((double *)v9 + 4), *((double *)v9 + 5));
++v8;
}
while ( numStudents > v8 );
}
return result;
}

original_code:
void DisplayGrade(cs460hwp hw, char* id)
{
 cs460hwp* current = &hw;
 printf("%i",numStudents);
 for (int i = 0; i < numStudents; i++){
  current = current->nextPtr;
  printf("id: %s %s\n",(*current).wsuid, id);
  if (!(strcmp((*current).wsuid,id))){
   printf("%s %s %s %lf %lf\n",(*current).course, (*current).wsuid, (*current).subdate, (*current).points1, (*current).points2);
  }
 }
 return;
}

canonical_original_code:
void DisplayGrade(struct hwpoints hw, char *id)
{
 struct hwpoints *current = &hw;
 printf("%i",numStudents);
 for (int i = 0; i < numStudents; i++){
  current = current->nextPtr;
  printf("id: %s %s\n",(*current).wsuid, id);
  if (!(strcmp((*current).wsuid,id))){
   printf("%s %s %s %lf %lf\n",(*current).course, (*current).wsuid, (*current).subdate, (*current).points1, (*current).points2);
  }
 }
 return;
}

variable_types: struct hwpoints { char course[7]; char wsuid[9]; char subdate[9]; double points1; double points2; struct hwpoints *nextPtr; } *


EmptyList

decompiled_code:
void __fastcall EmptyList(__int64 a1)
{
if ( *(_QWORD *)(a1 + 48) )
{
EmptyList();
free(*(void **)(a1 + 48));
}
}

original_code:
void EmptyList(cs460hwp* hw)
{
 if ((*hw).nextPtr != ((void *)0)){
  EmptyList((*hw).nextPtr);
  free((*hw).nextPtr);
 }
 return;
}

canonical_original_code:
void EmptyList(struct hwpoints *hw)
{
 if ((*hw).nextPtr != ((void *)0)){
  EmptyList((*hw).nextPtr);
  free((*hw).nextPtr);
 }
 return;
}

user_defined_types: struct hwpoints { char course[7]; char wsuid[9]; char subdate[9]; double points1; double points2; struct hwpoints *nextPtr; }


decompiled_code:
void wipe_options_view()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void wipe_options_view()
{
}

canonical_original_code:
void wipe_options_view()
{
}


decompiled_code:
int build_options_view()
{
return werase(stdscr);
}

canonical_decompiled_code:
int func1()
{
return werase(stdscr);
}

original_code:
void build_options_view(struct em8051 *aCPU)
{
    werase(stdscr);
}

variable_types: struct em8051 { unsigned char *mCodeMem; unsigned short mCodeMemMaxIdx; unsigned char *mExtData; unsigned short mExtDataMaxIdx; unsigned char mLowerData[128]; unsigned char *mUpperData; unsigned char mSFR[128]; unsigned short mPC; unsigned char mTickDelay; unsigned char (*op[256])(struct em8051 *aCPU); unsigned char (*dec[256])(struct em8051 *aCPU, unsigned short aPosition, char *aBuffer); void (*except)(struct em8051 *aCPU, int aCode); unsigned char (*sfrread[128])(struct em8051 *aCPU, unsigned char aRegister); void (*sfrwrite[128])(struct em8051 *aCPU, unsigned char aRegister); unsigned char (*xread)(struct em8051 *aCPU, unsigned short aAddress); void (*xwrite)(struct em8051 *aCPU, unsigned short aAddress, unsigned char aValue); unsigned char mInterruptActive; unsigned char int_a[2]; unsigned char int_psw[2]; unsigned char int_sp[2]; char serial_out[18]; unsigned char serial_out_idx; unsigned char serial_out_remaining_bits; _Bool serial_interrupt_trigger; } *


decompiled_code:
void __fastcall options_editor_keys(__int64 a1, int a2)
{
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax

if ( a2 == 260 )
{
switch ( activerow )
{
case 1:
v4 = opt_clock_select - 1;
if ( opt_clock_select - 1 < 0 )
v4 = 0;
opt_clock_select = v4;
opt_clock_hz = clockspeeds[v4];
break;
case 2:
v5 = opt_input_outputlow - 1;
if ( opt_input_outputlow - 1 < 0 )
v5 = 0;
opt_input_outputlow = v5;
break;
case 3:
opt_step_instruction = opt_step_instruction == 0;
break;
case 4:
opt_exception_iret_sp = opt_exception_iret_sp == 0;
break;
case 5:
opt_exception_iret_acc = opt_exception_iret_acc == 0;
break;
case 6:
opt_exception_iret_psw = opt_exception_iret_psw == 0;
break;
case 7:
opt_exception_acc_to_a = opt_exception_acc_to_a == 0;
break;
case 8:
opt_exception_stack = opt_exception_stack == 0;
break;
case 9:
opt_exception_invalid = opt_exception_invalid == 0;
break;
default:
return;
}
}
else
{
if ( a2 <= 260 )
{
if ( a2 == 258 )
{
v3 = activerow + 1;
if ( activerow + 1 > 9 )
v3 = 9;
activerow = v3;
}
else if ( a2 == 259 )
{
v2 = activerow - 1;
if ( activerow - 1 < 0 )
v2 = 0;
activerow = v2;
}
return;
}
if ( a2 != 261 )
return;
switch ( activerow )
{
case 1:
v6 = opt_clock_select + 1;
opt_clock_select = v6;
if ( v6 > 12 )
{
opt_clock_select = 12;
goto LABEL_31;
}
if ( v6 == 12 )
{
LABEL_31:
opt_clock_hz = emu_readhz(a1, "Enter custom clock speed", (unsigned int)opt_clock_hz);
if ( !opt_clock_hz )
opt_clock_hz = 1;
return;
}
opt_clock_hz = clockspeeds[v6];
if ( !opt_clock_hz )
opt_clock_hz = 1;
break;
case 2:
v7 = opt_input_outputlow + 1;
if ( opt_input_outputlow + 1 > 2 )
v7 = 2;
opt_input_outputlow = v7;
return;
case 3:
opt_step_instruction = opt_step_instruction == 0;
return;
case 4:
opt_exception_iret_sp = opt_exception_iret_sp == 0;
return;
case 5:
opt_exception_iret_acc = opt_exception_iret_acc == 0;
return;
case 6:
opt_exception_iret_psw = opt_exception_iret_psw == 0;
return;
case 7:
opt_exception_acc_to_a = opt_exception_acc_to_a == 0;
return;
case 8:
opt_exception_stack = opt_exception_stack == 0;
return;
case 9:
opt_exception_invalid = opt_exception_invalid == 0;
return;
default:
return;
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax

if ( a2 == 260 )
{
switch ( activerow )
{
case 1:
v4 = opt_clock_select - 1;
if ( opt_clock_select - 1 < 0 )
v4 = 0;
opt_clock_select = v4;
opt_clock_hz = clockspeeds[v4];
break;
case 2:
v5 = opt_input_outputlow - 1;
if ( opt_input_outputlow - 1 < 0 )
v5 = 0;
opt_input_outputlow = v5;
break;
case 3:
opt_step_instruction = opt_step_instruction == 0;
break;
case 4:
opt_exception_iret_sp = opt_exception_iret_sp == 0;
break;
case 5:
opt_exception_iret_acc = opt_exception_iret_acc == 0;
break;
case 6:
opt_exception_iret_psw = opt_exception_iret_psw == 0;
break;
case 7:
opt_exception_acc_to_a = opt_exception_acc_to_a == 0;
break;
case 8:
opt_exception_stack = opt_exception_stack == 0;
break;
case 9:
opt_exception_invalid = opt_exception_invalid == 0;
break;
default:
return;
}
}
else
{
if ( a2 <= 260 )
{
if ( a2 == 258 )
{
v3 = activerow + 1;
if ( activerow + 1 > 9 )
v3 = 9;
activerow = v3;
}
else if ( a2 == 259 )
{
v2 = activerow - 1;
if ( activerow - 1 < 0 )
v2 = 0;
activerow = v2;
}
return;
}
if ( a2 != 261 )
return;
switch ( activerow )
{
case 1:
v6 = opt_clock_select + 1;
opt_clock_select = v6;
if ( v6 > 12 )
{
opt_clock_select = 12;
goto LABEL_31;
}
if ( v6 == 12 )
{
LABEL_31:
opt_clock_hz = emu_readhz(a1, "Enter custom clock speed", (unsigned int)opt_clock_hz);
if ( !opt_clock_hz )
opt_clock_hz = 1;
return;
}
opt_clock_hz = clockspeeds[v6];
if ( !opt_clock_hz )
opt_clock_hz = 1;
break;
case 2:
v7 = opt_input_outputlow + 1;
if ( opt_input_outputlow + 1 > 2 )
v7 = 2;
opt_input_outputlow = v7;
return;
case 3:
opt_step_instruction = opt_step_instruction == 0;
return;
case 4:
opt_exception_iret_sp = opt_exception_iret_sp == 0;
return;
case 5:
opt_exception_iret_acc = opt_exception_iret_acc == 0;
return;
case 6:
opt_exception_iret_psw = opt_exception_iret_psw == 0;
return;
case 7:
opt_exception_acc_to_a = opt_exception_acc_to_a == 0;
return;
case 8:
opt_exception_stack = opt_exception_stack == 0;
return;
case 9:
opt_exception_invalid = opt_exception_invalid == 0;
return;
default:
return;
}
}
}

original_code:
void options_editor_keys(struct em8051 *aCPU, int ch)
{
    switch (ch)
    {
    case 0403:
        activerow--;
        if (activerow < 0)
            activerow = 0;
        break;
    case 0402:
        activerow++;
        if (activerow > 9)
            activerow = 9;
        break;
    case 0404:
        switch (activerow)
        {
        case 1:
            opt_clock_select--;
            if (opt_clock_select < 0)
                opt_clock_select = 0;
            opt_clock_hz = clockspeeds[opt_clock_select];
            break;
        case 2:
            opt_input_outputlow--;
            if (opt_input_outputlow < 0)
                opt_input_outputlow = 0;
            break;
        case 3:
            opt_step_instruction = !opt_step_instruction;
            break;
        case 4:
            opt_exception_iret_sp = !opt_exception_iret_sp;
            break;
        case 5:
            opt_exception_iret_acc = !opt_exception_iret_acc;
            break;
        case 6:
            opt_exception_iret_psw = !opt_exception_iret_psw;
            break;
        case 7:
            opt_exception_acc_to_a = !opt_exception_acc_to_a;
            break;
        case 8:
            opt_exception_stack = !opt_exception_stack;
            break;
        case 9:
            opt_exception_invalid = !opt_exception_invalid;
            break;
        }
        break;
    case 0405:
        switch (activerow)
        {
        case 1:
            opt_clock_select++;
            if (opt_clock_select > 12)
                opt_clock_select = 12;
            if (opt_clock_select == 12)
                opt_clock_hz = emu_readhz(aCPU, "Enter custom clock speed", opt_clock_hz);
            else
                opt_clock_hz = clockspeeds[opt_clock_select];
            if (opt_clock_hz == 0)
                opt_clock_hz = 1;
            break;
        case 2:
            opt_input_outputlow++;
            if (opt_input_outputlow > 2)
                opt_input_outputlow = 2;
            break;
        case 3:
            opt_step_instruction = !opt_step_instruction;
            break;
        case 4:
            opt_exception_iret_sp = !opt_exception_iret_sp;
            break;
        case 5:
            opt_exception_iret_acc = !opt_exception_iret_acc;
            break;
        case 6:
            opt_exception_iret_psw = !opt_exception_iret_psw;
            break;
        case 7:
            opt_exception_acc_to_a = !opt_exception_acc_to_a;
            break;
        case 8:
            opt_exception_stack = !opt_exception_stack;
            break;
        case 9:
            opt_exception_invalid = !opt_exception_invalid;
            break;
        }
        break;
    }
}

variable_types: ch int

user_defined_types: struct em8051 { unsigned char *mCodeMem; unsigned short mCodeMemMaxIdx; unsigned char *mExtData; unsigned short mExtDataMaxIdx; unsigned char mLowerData[128]; unsigned char *mUpperData; unsigned char mSFR[128]; unsigned short mPC; unsigned char mTickDelay; unsigned char (*op[256])(struct em8051 *aCPU); unsigned char (*dec[256])(struct em8051 *aCPU, unsigned short aPosition, char *aBuffer); void (*except)(struct em8051 *aCPU, int aCode); unsigned char (*sfrread[128])(struct em8051 *aCPU, unsigned char aRegister); void (*sfrwrite[128])(struct em8051 *aCPU, unsigned char aRegister); unsigned char (*xread)(struct em8051 *aCPU, unsigned short aAddress); void (*xwrite)(struct em8051 *aCPU, unsigned short aAddress, unsigned char aValue); unsigned char mInterruptActive; unsigned char int_a[2]; unsigned char int_psw[2]; unsigned char int_sp[2]; char serial_out[18]; unsigned char serial_out_idx; unsigned char serial_out_remaining_bits; _Bool serial_interrupt_trigger; }


decompiled_code:
int options_update()
{
int i; // ebx
const char *v1; // rcx
const char *v2; // rcx
const char *v3; // rcx
const char *v4; // rcx
const char *v5; // rcx
const char *v6; // rcx
const char *v7; // rcx

mvprintw(1, 1, "Options");
for ( i = 3; i != 23; i += 2 )
mvprintw(i, 2, " ");
wattr_on(stdscr, 0x40000uLL, 0LL);
mvprintw(3, 4, "< Hardware: 'super' 8051 >");
mvprintw(5, 4, "< Clock at % 8.3f MHz >", (float)((float)opt_clock_hz / 1000000.0));
v1 = "single instruction";
if ( !opt_step_instruction )
v1 = "single cpu cycle ";
mvprintw(9, 4, "< Step steps %s >", v1);
mvprintw(
7,
4,
"< High inputs from ports with low out level should be %c >",
(unsigned int)byte_5F7[opt_input_outputlow]);
v2 = "enabled ";
if ( !opt_exception_iret_sp )
v2 = "disabled";
mvprintw(11, 4, "< Interrupt handler sp watch exception %s >", v2);
v3 = "enabled ";
if ( !opt_exception_iret_acc )
v3 = "disabled";
mvprintw(13, 4, "< Interrupt handler acc watch exception %s >", v3);
v4 = "enabled ";
if ( !opt_exception_iret_psw )
v4 = "disabled";
mvprintw(15, 4, "< Interrupt handler psw watch exception %s >", v4);
v5 = "enabled ";
if ( !opt_exception_acc_to_a )
v5 = "disabled";
mvprintw(17, 4, "< Acc-to-a opcode exception %s >", v5);
v6 = "enabled ";
if ( !opt_exception_stack )
v6 = "disabled";
mvprintw(19, 4, "< Stack exception %s >", v6);
v7 = "enabled ";
if ( !opt_exception_invalid )
v7 = "disabled";
mvprintw(21, 4, "< Illegal opcode exception %s >", v7);
wattr_off(stdscr, 0x40000uLL, 0LL);
return mvprintw(2 * activerow + 3, 2, "->");
}

canonical_decompiled_code:
int func3()
{
int i; // ebx
const char *v1; // rcx
const char *v2; // rcx
const char *v3; // rcx
const char *v4; // rcx
const char *v5; // rcx
const char *v6; // rcx
const char *v7; // rcx

mvprintw(1, 1, "Options");
for ( i = 3; i != 23; i += 2 )
mvprintw(i, 2, " ");
wattr_on(stdscr, 0x40000uLL, 0LL);
mvprintw(3, 4, "< Hardware: 'super' 8051 >");
mvprintw(5, 4, "< Clock at % 8.3f MHz >", (float)((float)opt_clock_hz / 1000000.0));
v1 = "single instruction";
if ( !opt_step_instruction )
v1 = "single cpu cycle ";
mvprintw(9, 4, "< Step steps %s >", v1);
mvprintw(
7,
4,
"< High inputs from ports with low out level should be %c >",
(unsigned int)byte_5F7[opt_input_outputlow]);
v2 = "enabled ";
if ( !opt_exception_iret_sp )
v2 = "disabled";
mvprintw(11, 4, "< Interrupt handler sp watch exception %s >", v2);
v3 = "enabled ";
if ( !opt_exception_iret_acc )
v3 = "disabled";
mvprintw(13, 4, "< Interrupt handler acc watch exception %s >", v3);
v4 = "enabled ";
if ( !opt_exception_iret_psw )
v4 = "disabled";
mvprintw(15, 4, "< Interrupt handler psw watch exception %s >", v4);
v5 = "enabled ";
if ( !opt_exception_acc_to_a )
v5 = "disabled";
mvprintw(17, 4, "< Acc-to-a opcode exception %s >", v5);
v6 = "enabled ";
if ( !opt_exception_stack )
v6 = "disabled";
mvprintw(19, 4, "< Stack exception %s >", v6);
v7 = "enabled ";
if ( !opt_exception_invalid )
v7 = "disabled";
mvprintw(21, 4, "< Illegal opcode exception %s >", v7);
wattr_off(stdscr, 0x40000uLL, 0LL);
return mvprintw(2 * activerow + 3, 2, "->");
}

original_code:
void options_update(struct em8051 *aCPU)
{
    int i;
    mvprintw(1, 1, "Options");
    for (i = 0; i < 10; i++)
        mvprintw(i * 2 + 3, 2, "  ");
    wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((10) + 8)))), ((void *)0));
    mvprintw(3, 4, "< Hardware: 'super' 8051 >");
    mvprintw(5, 4, "< Clock at % 8.3f MHz >", opt_clock_hz / (1000*1000.0f));
    mvprintw(9, 4, "< Step steps %s >", opt_step_instruction ? "single instruction" : "single cpu cycle  ");
    mvprintw(7, 4, "< High inputs from ports with low out level should be %c >", "01?"[opt_input_outputlow]);
    mvprintw(11, 4, "< Interrupt handler sp watch exception %s >", opt_exception_iret_sp?"enabled ":"disabled");
    mvprintw(13, 4, "< Interrupt handler acc watch exception %s >", opt_exception_iret_acc?"enabled ":"disabled");
    mvprintw(15, 4, "< Interrupt handler psw watch exception %s >", opt_exception_iret_psw?"enabled ":"disabled");
    mvprintw(17, 4, "< Acc-to-a opcode exception %s >", opt_exception_acc_to_a?"enabled ":"disabled");
    mvprintw(19, 4, "< Stack exception %s >", opt_exception_stack?"enabled ":"disabled");
    mvprintw(21, 4, "< Illegal opcode exception %s >", opt_exception_invalid?"enabled ":"disabled");
    wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((10) + 8)))), ((void *)0));
    mvprintw(activerow * 2 + 3, 2, "->");
}

variable_types: i int


original_code:
static void serial_tx(struct em8051 *aCPU) {
 if (! aCPU->serial_out_remaining_bits)
        return;
 aCPU->serial_out_remaining_bits--;
 _Bool tx_bit = (aCPU->mSFR[REG_SBUF] >> aCPU->serial_out_remaining_bits);
 aCPU->mSFR[REG_P3] &= ~(1 << 1);
 if (tx_bit) aCPU->mSFR[REG_P3] |= (1 << 1);
 if (aCPU->serial_out_remaining_bits == 0) {
  aCPU->serial_out[aCPU->serial_out_idx] = aCPU->mSFR[REG_SBUF];
  aCPU->serial_out_idx = (aCPU->serial_out_idx + 1) % sizeof(aCPU->serial_out);
  aCPU->mSFR[REG_SCON] |= (1<<1);
  if (aCPU->mSFR[REG_IE] & IEMASK_ES) aCPU->serial_interrupt_trigger = 1;
 }
}