GetRHSPattern

decompiled_code:
__int64 __fastcall GetRHSPattern(__int64 a1, __int64 a2, unsigned __int16 *a3, _DWORD *a4, unsigned int a5, int a6, int a7, unsigned int a8)
{
__int64 v10; // r14
__int64 v11; // rax
__int64 v12; // r15
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // r14
__int64 v17; // rax
__int64 v18; // rax
__int64 i; // [rsp+0h] [rbp-68h]
__int64 v20; // [rsp+0h] [rbp-68h]
__int64 v22; // [rsp+10h] [rbp-58h]
__int64 v23; // [rsp+18h] [rbp-50h]
int v24; // [rsp+28h] [rbp-40h] BYREF
int v25[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

*a4 = 0;
if ( a6 )
((void (*)(void))GetToken)();
if ( !a7 )
goto LABEL_6;
if ( *a3 == a8 )
return 0LL;
if ( *a3 != 170 )
{
SyntaxErrorMessage(a1, "RHS patterns");
*a4 = 1;
v23 = 0LL;
}
else
{
LABEL_6:
GetToken(a1, a2, a3);
if ( *a3 != 2
|| (v10 = *((_QWORD *)a3 + 1), !strcmp(*(const char **)(v10 + 24), "="))
|| !strcmp(*(const char **)(v10 + 24), ":") )
{
SyntaxErrorMessage(a1, "first field of a RHS pattern");
*a4 = 1;
v23 = 0LL;
}
else if ( (unsigned int)ReservedPatternSymbol(a1, *(_QWORD *)(v10 + 24), 0LL) )
{
ReservedPatternSymbolErrorMsg(a1, *(_QWORD *)(v10 + 24), "a relation name");
*a4 = 1;
v23 = 0LL;
}
else if ( (unsigned int)FindModuleSeparator(*(_QWORD *)(v10 + 24)) )
{
IllegalModuleSpecifierMessage(a1);
*a4 = 1;
v23 = 0LL;
}
else
{
v11 = FindImportedConstruct(a1, "deftemplate", 0LL, *(_QWORD *)(v10 + 24), &v24, 1LL, 0LL);
v12 = v11;
if ( v24 > 1 )
{
AmbiguousReferenceErrorMessage(a1, "deftemplate", *(_QWORD *)(v10 + 24));
*a4 = 1;
v23 = 0LL;
}
else
{
if ( !v11 )
{
if ( (unsigned int)Bloaded(a1) && !*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
{
NoSuchTemplateError(a1, *(_QWORD *)(v10 + 24));
*a4 = 1;
return v12;
}
v20 = *(_QWORD *)(v10 + 24);
v14 = EnvGetCurrentModule(a1);
if ( (unsigned int)FindImportExportConflict(a1, "deftemplate", v14, v20) )
{
ImportExportConflictMessage(a1, "implied deftemplate", *(_QWORD *)(v10 + 24), 0LL, 0LL);
*a4 = 1;
return v12;
}
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
goto LABEL_14;
v12 = CreateImpliedDeftemplate(a1, v10, 1LL);
if ( !v12 )
goto LABEL_14;
}
if ( (*(_BYTE *)(v12 + 56) & 1) == 0 )
{
v23 = GenConstant(a1, 63LL, v12);
*(_QWORD *)(v23 + 24) = ParseAssertTemplate(a1, a2, a3, a4, a8, a5, v12);
if ( *a4 )
{
ReturnExpression(a1, v23);
v23 = 0LL;
}
}
else
{
LABEL_14:
v23 = GenConstant(a1, 63LL, v12);
SavePPBuffer(a1, " ");
v22 = 0LL;
for ( i = 0LL; ; i = v16 )
{
v15 = GetAssertArgument(a1, a2, a3, a4, a8, a5, v25);
v16 = v15;
if ( !v15 )
break;
if ( v22 )
*(_QWORD *)(i + 24) = v15;
else
v22 = v15;
SavePPBuffer(a1, " ");
}
if ( *a4 )
{
if ( v25[0] )
SyntaxErrorMessage(a1, "RHS patterns");
ReturnExpression(a1, v23);
ReturnExpression(a1, v22);
v23 = 0LL;
}
else
{
PPBackup(a1);
PPBackup(a1);
SavePPBuffer(a1, *((_QWORD *)a3 + 2));
v17 = AddBitMap(a1, &unk_A8B, 1LL);
v18 = GenConstant(a1, 62LL, v17);
*(_QWORD *)(v23 + 24) = v18;
*(_QWORD *)(v18 + 16) = v22;
}
}
}
}
}
return v23;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned __int16 *a3, _DWORD *a4, unsigned int a5, int a6, int a7, unsigned int a8)
{
__int64 v10; // r14
__int64 v11; // rax
__int64 v12; // r15
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // r14
__int64 v17; // rax
__int64 v18; // rax
__int64 i; // [rsp+0h] [rbp-68h]
__int64 v20; // [rsp+0h] [rbp-68h]
__int64 v22; // [rsp+10h] [rbp-58h]
__int64 v23; // [rsp+18h] [rbp-50h]
int v24; // [rsp+28h] [rbp-40h] BYREF
int v25[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

*a4 = 0;
if ( a6 )
((void (*)(void))GetToken)();
if ( !a7 )
goto LABEL_6;
if ( *a3 == a8 )
return 0LL;
if ( *a3 != 170 )
{
SyntaxErrorMessage(a1, "RHS patterns");
*a4 = 1;
v23 = 0LL;
}
else
{
LABEL_6:
GetToken(a1, a2, a3);
if ( *a3 != 2
|| (v10 = *((_QWORD *)a3 + 1), !strcmp(*(const char **)(v10 + 24), "="))
|| !strcmp(*(const char **)(v10 + 24), ":") )
{
SyntaxErrorMessage(a1, "first field of a RHS pattern");
*a4 = 1;
v23 = 0LL;
}
else if ( (unsigned int)ReservedPatternSymbol(a1, *(_QWORD *)(v10 + 24), 0LL) )
{
ReservedPatternSymbolErrorMsg(a1, *(_QWORD *)(v10 + 24), "a relation name");
*a4 = 1;
v23 = 0LL;
}
else if ( (unsigned int)FindModuleSeparator(*(_QWORD *)(v10 + 24)) )
{
IllegalModuleSpecifierMessage(a1);
*a4 = 1;
v23 = 0LL;
}
else
{
v11 = FindImportedConstruct(a1, "deftemplate", 0LL, *(_QWORD *)(v10 + 24), &v24, 1LL, 0LL);
v12 = v11;
if ( v24 > 1 )
{
AmbiguousReferenceErrorMessage(a1, "deftemplate", *(_QWORD *)(v10 + 24));
*a4 = 1;
v23 = 0LL;
}
else
{
if ( !v11 )
{
if ( (unsigned int)Bloaded(a1) && !*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
{
func0(a1, *(_QWORD *)(v10 + 24));
*a4 = 1;
return v12;
}
v20 = *(_QWORD *)(v10 + 24);
v14 = EnvGetCurrentModule(a1);
if ( (unsigned int)FindImportExportConflict(a1, "deftemplate", v14, v20) )
{
ImportExportConflictMessage(a1, "implied deftemplate", *(_QWORD *)(v10 + 24), 0LL, 0LL);
*a4 = 1;
return v12;
}
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
goto LABEL_14;
v12 = CreateImpliedDeftemplate(a1, v10, 1LL);
if ( !v12 )
goto LABEL_14;
}
if ( (*(_BYTE *)(v12 + 56) & 1) == 0 )
{
v23 = GenConstant(a1, 63LL, v12);
*(_QWORD *)(v23 + 24) = ParseAssertTemplate(a1, a2, a3, a4, a8, a5, v12);
if ( *a4 )
{
ReturnExpression(a1, v23);
v23 = 0LL;
}
}
else
{
LABEL_14:
v23 = GenConstant(a1, 63LL, v12);
SavePPBuffer(a1, " ");
v22 = 0LL;
for ( i = 0LL; ; i = v16 )
{
v15 = func1(a1, a2, a3, a4, a8, a5, v25);
v16 = v15;
if ( !v15 )
break;
if ( v22 )
*(_QWORD *)(i + 24) = v15;
else
v22 = v15;
SavePPBuffer(a1, " ");
}
if ( *a4 )
{
if ( v25[0] )
SyntaxErrorMessage(a1, "RHS patterns");
ReturnExpression(a1, v23);
ReturnExpression(a1, v22);
v23 = 0LL;
}
else
{
PPBackup(a1);
PPBackup(a1);
SavePPBuffer(a1, *((_QWORD *)a3 + 2));
v17 = AddBitMap(a1, &unk_A8B, 1LL);
v18 = GenConstant(a1, 62LL, v17);
*(_QWORD *)(v23 + 24) = v18;
*(_QWORD *)(v18 + 16) = v22;
}
}
}
}
}
return v23;
}

original_code:
struct expr *GetRHSPattern(
  void *theEnv,
  char *readSource,
  struct token *tempToken,
  int *error,
  int constantsOnly,
  int readFirstParen,
  int checkFirstParen,
  int endType)
  {
   struct expr *lastOne = ((void *)0);
   struct expr *nextOne, *firstOne, *argHead = ((void *)0);
   int printError, count;
   struct deftemplate *theDeftemplate;
   struct symbolHashNode *templateName;
   *error = 0;
   if (readFirstParen) GetToken(theEnv,readSource,tempToken);
   if (checkFirstParen)
     {
      if (tempToken->type == endType) return(((void *)0));
      if (tempToken->type != 170)
        {
         SyntaxErrorMessage(theEnv,"RHS patterns");
         *error = 1;
         return(((void *)0));
        }
     }
   GetToken(theEnv,readSource,tempToken);
   if (tempToken->type != 2)
     {
      SyntaxErrorMessage(theEnv,"first field of a RHS pattern");
      *error = 1;
      return(((void *)0));
     }
   else if ((strcmp((((struct symbolHashNode *) (tempToken->value))->contents),"=") == 0) ||
            (strcmp((((struct symbolHashNode *) (tempToken->value))->contents),":") == 0))
     {
      SyntaxErrorMessage(theEnv,"first field of a RHS pattern");
      *error = 1;
      return(((void *)0));
     }
   templateName = (struct symbolHashNode *) tempToken->value;
   if (ReservedPatternSymbol(theEnv,(((struct symbolHashNode *) (templateName))->contents),((void *)0)))
     {
      ReservedPatternSymbolErrorMsg(theEnv,(((struct symbolHashNode *) (templateName))->contents),"a relation name");
      *error = 1;
      return(((void *)0));
     }
   if (FindModuleSeparator((((struct symbolHashNode *) (templateName))->contents)))
     {
      IllegalModuleSpecifierMessage(theEnv);
      *error = 1;
      return(((void *)0));
     }
   theDeftemplate = (struct deftemplate *)
                    FindImportedConstruct(theEnv,"deftemplate",((void *)0),(((struct symbolHashNode *) (templateName))->contents),
                                          &count,1,((void *)0));
   if (count > 1)
     {
      AmbiguousReferenceErrorMessage(theEnv,"deftemplate",(((struct symbolHashNode *) (templateName))->contents));
      *error = 1;
      return(((void *)0));
     }
   if (theDeftemplate == ((void *)0))
     {
      if ((Bloaded(theEnv)) && (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode))
        {
         NoSuchTemplateError(theEnv,(((struct symbolHashNode *) (templateName))->contents));
         *error = 1;
         return(((void *)0));
        }
      if (FindImportExportConflict(theEnv,"deftemplate",((struct defmodule *) EnvGetCurrentModule(theEnv)),(((struct symbolHashNode *) (templateName))->contents)))
        {
         ImportExportConflictMessage(theEnv,"implied deftemplate",(((struct symbolHashNode *) (templateName))->contents),((void *)0),((void *)0));
         *error = 1;
         return(((void *)0));
        }
      if (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode)
        { theDeftemplate = CreateImpliedDeftemplate(theEnv,(SYMBOL_HN *) templateName,1); }
     }
   if ((theDeftemplate != ((void *)0)) && (theDeftemplate->implied == 0))
     {
      firstOne = GenConstant(theEnv,63,theDeftemplate);
      firstOne->nextArg = ParseAssertTemplate(theEnv,readSource,tempToken,
                                              error,endType,
                                              constantsOnly,theDeftemplate);
      if (*error)
        {
         ReturnExpression(theEnv,firstOne);
         firstOne = ((void *)0);
        }
      return(firstOne);
     }
   firstOne = GenConstant(theEnv,63,theDeftemplate);
   SavePPBuffer(theEnv," ");
   while ((nextOne = GetAssertArgument(theEnv,readSource,tempToken,
                                        error,endType,constantsOnly,&printError)) != ((void *)0))
     {
      if (argHead == ((void *)0)) argHead = nextOne;
      else lastOne->nextArg = nextOne;
      lastOne = nextOne;
      SavePPBuffer(theEnv," ");
     }
   if (*error)
     {
      if (printError) SyntaxErrorMessage(theEnv,"RHS patterns");
      ReturnExpression(theEnv,firstOne);
      ReturnExpression(theEnv,argHead);
      return(((void *)0));
     }
   PPBackup(theEnv);
   PPBackup(theEnv);
   SavePPBuffer(theEnv,tempToken->printForm);
   firstOne->nextArg = GenConstant(theEnv,62,AddBitMap(theEnv,(void *) "\0",1));
   firstOne->nextArg->argList = argHead;
   return(firstOne);
  }

canonical_original_code:
struct expr *GetRHSPattern(void *theEnv, char *readSource, struct token *tempToken, int *error, int constantsOnly, int readFirstParen, int checkFirstParen, int endType)
  {
   struct expr *lastOne = ((void *)0);
   struct expr *nextOne; struct expr *firstOne; struct expr *argHead = ((void *)0);
   int printError; int count;
   struct deftemplate *theDeftemplate;
   struct symbolHashNode *templateName;
   *error = 0;
   if (readFirstParen) GetToken(theEnv,readSource,tempToken);
   if (checkFirstParen)
     {
      if (tempToken->type == endType) return(((void *)0));
      if (tempToken->type != 170)
        {
         SyntaxErrorMessage(theEnv,"RHS patterns");
         *error = 1;
         return(((void *)0));
        }
     }
   GetToken(theEnv,readSource,tempToken);
   if (tempToken->type != 2)
     {
      SyntaxErrorMessage(theEnv,"first field of a RHS pattern");
      *error = 1;
      return(((void *)0));
     }
   else if ((strcmp((((struct symbolHashNode *) (tempToken->value))->contents),"=") == 0) ||
            (strcmp((((struct symbolHashNode *) (tempToken->value))->contents),":") == 0))
     {
      SyntaxErrorMessage(theEnv,"first field of a RHS pattern");
      *error = 1;
      return(((void *)0));
     }
   templateName = (struct symbolHashNode *) tempToken->value;
   if (ReservedPatternSymbol(theEnv,(((struct symbolHashNode *) (templateName))->contents),((void *)0)))
     {
      ReservedPatternSymbolErrorMsg(theEnv,(((struct symbolHashNode *) (templateName))->contents),"a relation name");
      *error = 1;
      return(((void *)0));
     }
   if (FindModuleSeparator((((struct symbolHashNode *) (templateName))->contents)))
     {
      IllegalModuleSpecifierMessage(theEnv);
      *error = 1;
      return(((void *)0));
     }
   theDeftemplate = (struct deftemplate *)
                    FindImportedConstruct(theEnv,"deftemplate",((void *)0),(((struct symbolHashNode *) (templateName))->contents),
                                          &count,1,((void *)0));
   if (count > 1)
     {
      AmbiguousReferenceErrorMessage(theEnv,"deftemplate",(((struct symbolHashNode *) (templateName))->contents));
      *error = 1;
      return(((void *)0));
     }
   if (theDeftemplate == ((void *)0))
     {
      if ((Bloaded(theEnv)) && (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode))
        {
         NoSuchTemplateError(theEnv,(((struct symbolHashNode *) (templateName))->contents));
         *error = 1;
         return(((void *)0));
        }
      if (FindImportExportConflict(theEnv,"deftemplate",((struct defmodule *) EnvGetCurrentModule(theEnv)),(((struct symbolHashNode *) (templateName))->contents)))
        {
         ImportExportConflictMessage(theEnv,"implied deftemplate",(((struct symbolHashNode *) (templateName))->contents),((void *)0),((void *)0));
         *error = 1;
         return(((void *)0));
        }
      if (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode)
        { theDeftemplate = CreateImpliedDeftemplate(theEnv,(struct symbolHashNode *) templateName,1); }
     }
   if ((theDeftemplate != ((void *)0)) && (theDeftemplate->implied == 0))
     {
      firstOne = GenConstant(theEnv,63,theDeftemplate);
      firstOne->nextArg = ParseAssertTemplate(theEnv,readSource,tempToken,
                                              error,endType,
                                              constantsOnly,theDeftemplate);
      if (*error)
        {
         ReturnExpression(theEnv,firstOne);
         firstOne = ((void *)0);
        }
      return(firstOne);
     }
   firstOne = GenConstant(theEnv,63,theDeftemplate);
   SavePPBuffer(theEnv," ");
   while ((nextOne = GetAssertArgument(theEnv,readSource,tempToken,
                                        error,endType,constantsOnly,&printError)) != ((void *)0))
     {
      if (argHead == ((void *)0)) argHead = nextOne;
      else lastOne->nextArg = nextOne;
      lastOne = nextOne;
      SavePPBuffer(theEnv," ");
     }
   if (*error)
     {
      if (printError) SyntaxErrorMessage(theEnv,"RHS patterns");
      ReturnExpression(theEnv,firstOne);
      ReturnExpression(theEnv,argHead);
      return(((void *)0));
     }
   PPBackup(theEnv);
   PPBackup(theEnv);
   SavePPBuffer(theEnv,tempToken->printForm);
   firstOne->nextArg = GenConstant(theEnv,62,AddBitMap(theEnv,(void *) "\0",1));
   firstOne->nextArg->argList = argHead;
   return(firstOne);
  }

variable_types:
readSource
char *

variable_types: readFirstParen int

variable_types: checkFirstParen int

variable_types: printError int

variable_types: count int

variable_types: 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 { 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 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 { 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 *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; } *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 { 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 { unsigned int busyCount; short depth; unsigned long multifieldLength; struct multifield *next; struct field { unsigned short type; void *value; } theFields[1]; } theProposition; } *factList; struct fact *lastFact; } *

user_defined_types: struct token { unsigned short type; void *value; char *printForm; }

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 constructData { int ClearReadyInProgress; int ClearInProgress; int ResetReadyInProgress; int ResetInProgress; struct callFunctionItem *ListOfSaveFunctions; int PrintWhileLoading; unsigned int WatchCompilations; struct construct *ListOfConstructs; struct callFunctionItem *ListOfResetFunctions; struct callFunctionItem *ListOfClearFunctions; struct callFunctionItem *ListOfClearReadyFunctions; int Executing; int (*BeforeResetFunction)(void *); int CheckSyntaxMode; }

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

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 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 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 callFunctionItem { char *name; void (*func)(void *); int priority; struct callFunctionItem *next; short environmentAware; }

user_defined_types: struct construct { char *constructName; char *pluralName; int (*parseFunction)(void *, char *); void *(*findFunction)(void *, char *); struct symbolHashNode *(*getConstructNameFunction)(struct constructHeader *); char *(*getPPFormFunction)(void *, struct constructHeader *); struct defmoduleItemHeader *(*getModuleItemFunction)(struct constructHeader *); void *(*getNextItemFunction)(void *, void *); void (*setNextItemFunction)(struct constructHeader *, struct constructHeader *); int (*isConstructDeletableFunction)(void *, void *); int (*deleteFunction)(void *, void *); void (*freeFunction)(void *, void *); struct construct *next; }

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 multifield { unsigned int busyCount; short depth; unsigned long multifieldLength; struct multifield *next; struct field theFields[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 patternEntity { struct patternEntityRecord *theInfo; void *dependents; unsigned int busyCount; long timeTag; }

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


BuildRHSAssert

repo: jarcec/rbclips

decompiled_code:
__int64 __fastcall BuildRHSAssert(__int64 a1, __int64 a2, unsigned __int16 *a3, _DWORD *a4, int a5, int a6, __int64 a7)
{
__int64 v9; // r12
__int64 v10; // rbx
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v16; // [rsp+10h] [rbp-48h]

*a4 = 0;
if ( !a6 && *a3 == 171 )
{
v16 = 0LL;
if ( a5 )
{
*a4 = 1;
SyntaxErrorMessage(a1, a7);
v16 = 0LL;
}
}
else
{
v16 = 0LL;
v9 = 0LL;
while ( 1 )
{
v10 = GetRHSPattern(a1, a2, a3, a4, 0, a6, 1, 0xABu);
if ( !v10 )
break;
PPCRAndIndent(a1);
v11 = FindFunction(a1, "assert");
v12 = GenConstant(a1, 30LL, v11);
*(_QWORD *)(v12 + 16) = v10;
if ( v9 )
*(_QWORD *)(v9 + 24) = v12;
else
v16 = v12;
v9 = v12;
a6 = 1;
}
if ( *a4 )
{
ReturnExpression(a1, v16);
v16 = 0LL;
}
else
{
if ( *a3 == 171 )
{
PPBackup(a1);
PPBackup(a1);
SavePPBuffer(a1, ")");
}
if ( v16 )
{
if ( *(_QWORD *)(v16 + 24) )
{
v13 = FindFunction(a1, "progn");
v14 = GenConstant(a1, 30LL, v13);
*(_QWORD *)(v14 + 16) = v16;
v16 = v14;
}
}
else if ( a5 )
{
*a4 = 1;
SyntaxErrorMessage(a1, a7);
}
}
}
return v16;
}

original_code:
struct expr *BuildRHSAssert(
  void *theEnv,
  char *logicalName,
  struct token *theToken,
  int *error,
  int atLeastOne,
  int readFirstParen,
  char *whereParsed)
  {
   struct expr *lastOne, *nextOne, *assertList, *stub;
   *error = 0;
   if (readFirstParen == 0)
     {
      if (theToken->type == 171)
        {
         if (atLeastOne)
           {
            *error = 1;
            SyntaxErrorMessage(theEnv,whereParsed);
           }
         return(((void *)0));
        }
     }
   lastOne = assertList = ((void *)0);
   while ((nextOne = GetRHSPattern(theEnv,logicalName,theToken,
                                   error,0,readFirstParen,
                                   1,171)) != ((void *)0))
     {
      PPCRAndIndent(theEnv);
      stub = GenConstant(theEnv,30,(void *) FindFunction(theEnv,"assert"));
      stub->argList = nextOne;
      nextOne = stub;
      if (lastOne == ((void *)0))
        { assertList = nextOne; }
      else
        { lastOne->nextArg = nextOne; }
      lastOne = nextOne;
      readFirstParen = 1;
     }
   if (*error)
     {
      ReturnExpression(theEnv,assertList);
      return(((void *)0));
     }
   if (theToken->type == 171)
     {
      PPBackup(theEnv);
      PPBackup(theEnv);
      SavePPBuffer(theEnv,")");
     }
   if (assertList == ((void *)0))
     {
      if (atLeastOne)
        {
         *error = 1;
         SyntaxErrorMessage(theEnv,whereParsed);
        }
      return(((void *)0));
     }
   if (assertList->nextArg != ((void *)0))
     {
      stub = GenConstant(theEnv,30,(void *) FindFunction(theEnv,"progn"));
      stub->argList = assertList;
      assertList = stub;
     }
   return(assertList);
  }

canonical_original_code:
struct expr *BuildRHSAssert(void *theEnv, char *logicalName, struct token *theToken, int *error, int atLeastOne, int readFirstParen, char *whereParsed)
  {
   struct expr *lastOne; struct expr *nextOne; struct expr *assertList; struct expr *stub;
   *error = 0;
   if (readFirstParen == 0)
     {
      if (theToken->type == 171)
        {
         if (atLeastOne)
           {
            *error = 1;
            SyntaxErrorMessage(theEnv,whereParsed);
           }
         return(((void *)0));
        }
     }
   lastOne = assertList = ((void *)0);
   while ((nextOne = GetRHSPattern(theEnv,logicalName,theToken,
                                   error,0,readFirstParen,
                                   1,171)) != ((void *)0))
     {
      PPCRAndIndent(theEnv);
      stub = GenConstant(theEnv,30,(void *) FindFunction(theEnv,"assert"));
      stub->argList = nextOne;
      nextOne = stub;
      if (lastOne == ((void *)0))
        { assertList = nextOne; }
      else
        { lastOne->nextArg = nextOne; }
      lastOne = nextOne;
      readFirstParen = 1;
     }
   if (*error)
     {
      ReturnExpression(theEnv,assertList);
      return(((void *)0));
     }
   if (theToken->type == 171)
     {
      PPBackup(theEnv);
      PPBackup(theEnv);
      SavePPBuffer(theEnv,")");
     }
   if (assertList == ((void *)0))
     {
      if (atLeastOne)
        {
         *error = 1;
         SyntaxErrorMessage(theEnv,whereParsed);
        }
      return(((void *)0));
     }
   if (assertList->nextArg != ((void *)0))
     {
      stub = GenConstant(theEnv,30,(void *) FindFunction(theEnv,"progn"));
      stub->argList = assertList;
      assertList = stub;
     }
   return(assertList);
  }

variable_types:
theEnv
void *

variable_types:
logicalName
char *

variable_types: struct token { unsigned short type; void *value; char *printForm; } *

variable_types:
error
int *

variable_types: atLeastOne int

variable_types:
whereParsed
char *

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


StringToFact

decompiled_code:
__int64 __fastcall StringToFact(__int64 a1, __int64 a2)
{
__int64 v2; // r14
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // r13
__int64 v6; // rbx
unsigned int v7; // ebp
__int64 v8; // rax
_WORD v10[8]; // [rsp+0h] [rbp-98h] BYREF
__int64 v11; // [rsp+10h] [rbp-88h]
int v12; // [rsp+3Ch] [rbp-5Ch] BYREF
unsigned __int16 v13[44]; // [rsp+40h] [rbp-58h] BYREF

v12 = 0;
SetEvaluationError(a1, 0LL);
OpenStringSource(a1, "assert_str", a2, 0LL);
v2 = GetRHSPattern(a1, (__int64)"assert_str", v13, &v12, 0, 1, 1, 0xABu);
CloseStringSource(a1, "assert_str");
if ( !v2 )
{
if ( !v12 )
{
SyntaxErrorMessage(a1, "RHS patterns");
ReturnExpression(a1, 0LL);
return 0LL;
}
goto LABEL_13;
}
if ( v12 )
{
LABEL_13:
ReturnExpression(a1, v2);
return 0LL;
}
if ( (unsigned int)ExpressionContainsVariables(v2, 0LL) )
{
LocalVariableErrorMessage(a1, "the assert-string function");
SetEvaluationError(a1, 1LL);
ReturnExpression(a1, v2);
v5 = 0LL;
}
else
{
v3 = *(_QWORD *)(v2 + 24);
if ( v3 )
{
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)(v4 + 1);
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
}
else
{
v4 = 0LL;
}
v5 = CreateFactBySize(a1, v4);
*(_QWORD *)(v5 + 32) = *(_QWORD *)(v2 + 8);
ExpressionInstall(a1, v2);
v6 = *(_QWORD *)(v2 + 24);
if ( v6 )
{
v7 = 0;
do
{
EvaluateExpression(a1, v6, v10);
v8 = v5 + 16LL * v7;
*(_WORD *)(v8 + 120) = v10[4];
*(_QWORD *)(v8 + 128) = v11;
++v7;
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
}
ExpressionDeinstall(a1, v2);
ReturnExpression(a1, v2);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // r14
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // r13
__int64 v6; // rbx
unsigned int v7; // ebp
__int64 v8; // rax
_WORD v10[8]; // [rsp+0h] [rbp-98h] BYREF
__int64 v11; // [rsp+10h] [rbp-88h]
int v12; // [rsp+3Ch] [rbp-5Ch] BYREF
unsigned __int16 v13[44]; // [rsp+40h] [rbp-58h] BYREF

v12 = 0;
SetEvaluationError(a1, 0LL);
OpenStringSource(a1, "assert_str", a2, 0LL);
v2 = func2(a1, (__int64)"assert_str", v13, &v12, 0, 1, 1, 0xABu);
CloseStringSource(a1, "assert_str");
if ( !v2 )
{
if ( !v12 )
{
SyntaxErrorMessage(a1, "RHS patterns");
ReturnExpression(a1, 0LL);
return 0LL;
}
goto LABEL_13;
}
if ( v12 )
{
LABEL_13:
ReturnExpression(a1, v2);
return 0LL;
}
if ( (unsigned int)ExpressionContainsVariables(v2, 0LL) )
{
LocalVariableErrorMessage(a1, "the assert-string function");
SetEvaluationError(a1, 1LL);
ReturnExpression(a1, v2);
v5 = 0LL;
}
else
{
v3 = *(_QWORD *)(v2 + 24);
if ( v3 )
{
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)(v4 + 1);
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
}
else
{
v4 = 0LL;
}
v5 = CreateFactBySize(a1, v4);
*(_QWORD *)(v5 + 32) = *(_QWORD *)(v2 + 8);
ExpressionInstall(a1, v2);
v6 = *(_QWORD *)(v2 + 24);
if ( v6 )
{
v7 = 0;
do
{
EvaluateExpression(a1, v6, v10);
v8 = v5 + 16LL * v7;
*(_WORD *)(v8 + 120) = v10[4];
*(_QWORD *)(v8 + 128) = v11;
++v7;
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
}
ExpressionDeinstall(a1, v2);
ReturnExpression(a1, v2);
}
return v5;
}

original_code:
struct fact *StringToFact(
  void *theEnv,
  char *str)
  {
   struct token theToken;
   struct fact *factPtr;
   unsigned numberOfFields = 0, whichField;
   struct expr *assertArgs, *tempPtr;
   int error = 0;
   DATA_OBJECT theResult;
   SetEvaluationError(theEnv,0);
   OpenStringSource(theEnv,"assert_str",str,0);
   assertArgs = GetRHSPattern(theEnv,"assert_str",&theToken,
                              &error,0,1,
                              1,171);
   CloseStringSource(theEnv,"assert_str");
   if ((assertArgs == ((void *)0)) && (! error))
     {
      SyntaxErrorMessage(theEnv,"RHS patterns");
      ReturnExpression(theEnv,assertArgs);
      return(((void *)0));
     }
   if (error)
     {
      ReturnExpression(theEnv,assertArgs);
      return(((void *)0));
     }
   if (ExpressionContainsVariables(assertArgs,0))
     {
      LocalVariableErrorMessage(theEnv,"the assert-string function");
      SetEvaluationError(theEnv,1);
      ReturnExpression(theEnv,assertArgs);
      return(((void *)0));
     }
   for (tempPtr = assertArgs->nextArg; tempPtr != ((void *)0); tempPtr = tempPtr->nextArg)
     { numberOfFields++; }
   factPtr = (struct fact *) CreateFactBySize(theEnv,numberOfFields);
   factPtr->whichDeftemplate = (struct deftemplate *) assertArgs->value;
   ExpressionInstall(theEnv,assertArgs);
   whichField = 0;
   for (tempPtr = assertArgs->nextArg; tempPtr != ((void *)0); tempPtr = tempPtr->nextArg)
     {
      EvaluateExpression(theEnv,tempPtr,&theResult);
      factPtr->theProposition.theFields[whichField].type = theResult.type;
      factPtr->theProposition.theFields[whichField].value = theResult.value;
      whichField++;
     }
   ExpressionDeinstall(theEnv,assertArgs);
   ReturnExpression(theEnv,assertArgs);
   return(factPtr);
  }

canonical_original_code:
struct fact *StringToFact(void *theEnv, char *str)
  {
   struct token theToken;
   struct fact *factPtr;
   unsigned int numberOfFields = 0; unsigned int whichField;
   struct expr *assertArgs; struct expr *tempPtr;
   int error = 0;
   struct dataObject theResult;
   SetEvaluationError(theEnv,0);
   OpenStringSource(theEnv,"assert_str",str,0);
   assertArgs = GetRHSPattern(theEnv,"assert_str",&theToken,
                              &error,0,1,
                              1,171);
   CloseStringSource(theEnv,"assert_str");
   if ((assertArgs == ((void *)0)) && (! error))
     {
      SyntaxErrorMessage(theEnv,"RHS patterns");
      ReturnExpression(theEnv,assertArgs);
      return(((void *)0));
     }
   if (error)
     {
      ReturnExpression(theEnv,assertArgs);
      return(((void *)0));
     }
   if (ExpressionContainsVariables(assertArgs,0))
     {
      LocalVariableErrorMessage(theEnv,"the assert-string function");
      SetEvaluationError(theEnv,1);
      ReturnExpression(theEnv,assertArgs);
      return(((void *)0));
     }
   for (tempPtr = assertArgs->nextArg; tempPtr != ((void *)0); tempPtr = tempPtr->nextArg)
     { numberOfFields++; }
   factPtr = (struct fact *) CreateFactBySize(theEnv,numberOfFields);
   factPtr->whichDeftemplate = (struct deftemplate *) assertArgs->value;
   ExpressionInstall(theEnv,assertArgs);
   whichField = 0;
   for (tempPtr = assertArgs->nextArg; tempPtr != ((void *)0); tempPtr = tempPtr->nextArg)
     {
      EvaluateExpression(theEnv,tempPtr,&theResult);
      factPtr->theProposition.theFields[whichField].type = theResult.type;
      factPtr->theProposition.theFields[whichField].value = theResult.value;
      whichField++;
     }
   ExpressionDeinstall(theEnv,assertArgs);
   ReturnExpression(theEnv,assertArgs);
   return(factPtr);
  }

variable_types:
str
char *

variable_types: struct token { unsigned short type; void *value; char *printForm; }

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:
numberOfFields
unsigned int

variable_types:
whichField
unsigned int

variable_types: error int

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 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 genericMatch { union { void *theValue; struct alphaMatch *theMatch; } gm; }

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


GetNextPatternNode

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

result = a1[7];
if ( !result )
{
while ( 1 )
{
result = a1[10];
if ( result )
break;
a1 = (_QWORD *)a1[8];
if ( !a1 )
return 0LL;
}
}
return result;
}

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

result = a1[7];
if ( !result )
{
while ( 1 )
{
result = a1[10];
if ( result )
break;
a1 = (_QWORD *)a1[8];
if ( !a1 )
return 0LL;
}
}
return result;
}

original_code:
static struct factPatternNode *GetNextPatternNode(
  struct factPatternNode *thePattern)
  {
   if (thePattern->nextLevel != ((void *)0)) return(thePattern->nextLevel);
   while (thePattern->rightNode == ((void *)0))
     {
      thePattern = thePattern->lastLevel;
      if (thePattern == ((void *)0)) return(((void *)0));
     }
   return(thePattern->rightNode);
  }

canonical_original_code:
static struct factPatternNode *GetNextPatternNode(struct factPatternNode *thePattern)
  {
   if (thePattern->nextLevel != ((void *)0)) return(thePattern->nextLevel);
   while (thePattern->rightNode == ((void *)0))
     {
      thePattern = thePattern->lastLevel;
      if (thePattern == ((void *)0)) return(((void *)0));
     }
   return(thePattern->rightNode);
  }

variable_types:
thePattern
struct factPatternNode *

return_type: 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 { 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; } *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 { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *networkTest; void *rightSideEntryStructure; struct joinNode *nextLevel; struct joinNode *lastLevel; struct joinNode *rightDriveNode; struct joinNode *rightMatchNode; struct defrule { 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; 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; } *

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

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


BeforePatternNetworkToCode

decompiled_code:
__int64 __fastcall BeforePatternNetworkToCode(__int64 a1)
{
__int64 result; // rax
int v2; // er15
int v3; // ebp
__int64 v4; // r13
__int64 v5; // r14
_QWORD *v6; // rdi
__int64 v7; // rbx
__int64 v9; // [rsp+18h] [rbp-40h]

result = EnvGetNextDefmodule(a1, 0LL);
v9 = result;
if ( result )
{
v2 = 0;
v3 = 0;
do
{
EnvSetCurrentModule(a1, v9);
v4 = EnvGetNextDeftemplate(a1, 0LL);
if ( v4 )
{
v5 = v2;
do
{
v2 = v5 + 1;
*(_QWORD *)(v4 + 24) = v5;
v6 = *(_QWORD **)(v4 + 72);
if ( v6 )
{
v7 = v3;
do
{
v3 = v7 + 1;
v6[4] = v7;
v6 = (_QWORD *)GetNextPatternNode(v6);
++v7;
}
while ( v6 );
}
v4 = EnvGetNextDeftemplate(a1, v4);
++v5;
}
while ( v4 );
}
result = EnvGetNextDefmodule(a1, v9);
v9 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int v2; // er15
int v3; // ebp
__int64 v4; // r13
__int64 v5; // r14
_QWORD *v6; // rdi
__int64 v7; // rbx
__int64 v9; // [rsp+18h] [rbp-40h]

result = EnvGetNextDefmodule(a1, 0LL);
v9 = result;
if ( result )
{
v2 = 0;
v3 = 0;
do
{
EnvSetCurrentModule(a1, v9);
v4 = EnvGetNextDeftemplate(a1, 0LL);
if ( v4 )
{
v5 = v2;
do
{
v2 = v5 + 1;
*(_QWORD *)(v4 + 24) = v5;
v6 = *(_QWORD **)(v4 + 72);
if ( v6 )
{
v7 = v3;
do
{
v3 = v7 + 1;
v6[4] = v7;
v6 = (_QWORD *)func0(v6);
++v7;
}
while ( v6 );
}
v4 = EnvGetNextDeftemplate(a1, v4);
++v5;
}
while ( v4 );
}
result = EnvGetNextDefmodule(a1, v9);
v9 = result;
}
while ( result );
}
return result;
}

original_code:
static void BeforePatternNetworkToCode(
  void *theEnv)
  {
   int whichPattern = 0;
   int whichDeftemplate = 0;
   struct defmodule *theModule;
   struct deftemplate *theDeftemplate;
   struct factPatternNode *thePattern;
   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,((void *)0));
        theModule != ((void *)0);
        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
     {
      EnvSetCurrentModule(theEnv,(void *) theModule);
      for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,((void *)0));
           theDeftemplate != ((void *)0);
           theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate))
        {
         theDeftemplate->header.bsaveID = whichDeftemplate++;
         for (thePattern = theDeftemplate->patternNetwork;
              thePattern != ((void *)0);
              thePattern = GetNextPatternNode(thePattern))
           { thePattern->bsaveID = whichPattern++; }
        }
     }
  }

canonical_original_code:
static void BeforePatternNetworkToCode(void *theEnv)
  {
   int whichPattern = 0;
   int whichDeftemplate = 0;
   struct defmodule *theModule;
   struct deftemplate *theDeftemplate;
   struct factPatternNode *thePattern;
   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,((void *)0));
        theModule != ((void *)0);
        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
     {
      EnvSetCurrentModule(theEnv,(void *) theModule);
      for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,((void *)0));
           theDeftemplate != ((void *)0);
           theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate))
        {
         theDeftemplate->header.bsaveID = whichDeftemplate++;
         for (thePattern = theDeftemplate->patternNetwork;
              thePattern != ((void *)0);
              thePattern = GetNextPatternNode(thePattern))
           { thePattern->bsaveID = whichPattern++; }
        }
     }
  }

variable_types: whichPattern int

variable_types: whichDeftemplate int

variable_types: struct defmodule { 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 *theModule; struct constructHeader { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader *whichModule; long bsaveID; struct constructHeader *next; struct userData { unsigned char dataID; struct userData *next; } *usrData; } *firstItem; struct constructHeader *lastItem; } **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; } *

variable_types: 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 { 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; } *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 { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *networkTest; void *rightSideEntryStructure; struct joinNode *nextLevel; struct joinNode *lastLevel; struct joinNode *rightDriveNode; struct joinNode *rightMatchNode; struct defrule { 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; 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; } *

return_type: void

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 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 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 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 field { unsigned short type; void *value; }


UpdateDeffacts

original_code:
static void UpdateDeffacts(
  void *theEnv,
  void *buf,
  long obji)
  {
   struct bsaveDeffacts *bdp;
   bdp = (struct bsaveDeffacts *) buf;
   UpdateConstructHeader(theEnv,&bdp->header,&((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray[obji].header,
                         (int) sizeof(struct deffactsModule),(void *) ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->ModuleArray,
                         (int) sizeof(struct deffacts),(void *) ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray);
   ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray[obji].assertList = ((struct expr *) (((bdp->assertList) == -1L) ? ((void *)0) : &((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[bdp->assertList]));
  }

canonical_original_code:
static void UpdateDeffacts(void *theEnv, void *buf, long obji)
  {
   struct bsaveDeffacts *bdp;
   bdp = (struct bsaveDeffacts *) buf;
   UpdateConstructHeader(theEnv,&bdp->header,&((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray[obji].header,
                         (int) sizeof(struct deffactsModule),(void *) ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->ModuleArray,
                         (int) sizeof(struct deffacts),(void *) ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray);
   ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray[obji].assertList = ((struct expr *) (((bdp->assertList) == -1L) ? ((void *)0) : &((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionArray[bdp->assertList]));
  }

variable_types:
theEnv
void *

variable_types:
buf
void *

variable_types: obji long

variable_types: struct bsaveDeffacts { struct bsaveConstructHeader { long name; long whichModule; long next; } header; long assertList; } *

user_defined_types: struct deffactsModule { struct defmoduleItemHeader header; }

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

user_defined_types: struct bsaveDeffacts { struct bsaveConstructHeader header; long assertList; }

user_defined_types: struct deffactsBinaryData { struct deffacts *DeffactsArray; long NumberOfDeffacts; struct deffactsModule *ModuleArray; long NumberOfDeffactsModules; }

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 expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; }

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 environmentCleanupFunction { char *name; void (*func)(void *); int priority; struct environmentCleanupFunction *next; }

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

user_defined_types: struct portItem { struct symbolHashNode *moduleName; struct symbolHashNode *constructType; struct symbolHashNode *constructName; struct portItem *next; }

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


UpdateDeffactsModule

decompiled_code:
__int64 __fastcall UpdateDeffactsModule(__int64 a1, __int64 a2, __int64 a3)
{
return UpdateDefmoduleItemHeader(
a1,
a2,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 16LL) + 24 * a3,
56LL,
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 208LL));
}

original_code:
static void UpdateDeffactsModule(
  void *theEnv,
  void *buf,
  long obji)
  {
   struct bsaveDeffactsModule *bdmPtr;
   bdmPtr = (struct bsaveDeffactsModule *) buf;
   UpdateDefmoduleItemHeader(theEnv,&bdmPtr->header,&((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->ModuleArray[obji].header,
                             (int) sizeof(struct deffacts),(void *) ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray);
  }

canonical_original_code:
static void UpdateDeffactsModule(void *theEnv, void *buf, long obji)
  {
   struct bsaveDeffactsModule *bdmPtr;
   bdmPtr = (struct bsaveDeffactsModule *) buf;
   UpdateDefmoduleItemHeader(theEnv,&bdmPtr->header,&((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->ModuleArray[obji].header,
                             (int) sizeof(struct deffacts),(void *) ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->DeffactsArray);
  }

variable_types: struct bsaveDeffactsModule { struct bsaveDefmoduleItemHeader { long theModule; long firstItem; long lastItem; } header; } *

user_defined_types: struct bsaveDeffactsModule { struct bsaveDefmoduleItemHeader header; }

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


DeffactsBinarySetup

decompiled_code:
__int64 __fastcall DeffactsBinarySetup(__int64 a1)
{
AllocateEnvironmentData(a1, 26LL, 32LL, DeallocateDeffactsBloadData);
return AddBinaryItem(
a1,
"deffacts",
0LL,
BsaveFind,
BsaveExpressions,
BsaveStorage,
BsaveBinaryItem,
BloadStorage,
BloadBinaryItem,
ClearBload);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
AllocateEnvironmentData(a1, 26LL, 32LL, DeallocateDeffactsBloadData);
return AddBinaryItem(
a1,
"deffacts",
0LL,
BsaveFind,
BsaveExpressions,
BsaveStorage,
BsaveBinaryItem,
BloadStorage,
BloadBinaryItem,
ClearBload);
}

original_code:
void DeffactsBinarySetup(
  void *theEnv)
  {
   AllocateEnvironmentData(theEnv,26,sizeof(struct deffactsBinaryData),DeallocateDeffactsBloadData);
   AddBinaryItem(theEnv,"deffacts",0,BsaveFind,BsaveExpressions,
                             BsaveStorage,BsaveBinaryItem,
                             BloadStorage,BloadBinaryItem,
                             ClearBload);
  }

canonical_original_code:
void DeffactsBinarySetup(void *theEnv)
  {
   AllocateEnvironmentData(theEnv,26,sizeof(struct deffactsBinaryData),DeallocateDeffactsBloadData);
   AddBinaryItem(theEnv,"deffacts",0,BsaveFind,BsaveExpressions,
                             BsaveStorage,BsaveBinaryItem,
                             BloadStorage,BloadBinaryItem,
                             ClearBload);
  }

user_defined_types: struct deffactsModule { struct defmoduleItemHeader header; }


BloadDeffactsModuleReference

decompiled_code:
__int64 __fastcall BloadDeffactsModuleReference(__int64 a1, int a2)
{
return *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 16LL) + 24LL * a2;
}

original_code:
void *BloadDeffactsModuleReference(
  void *theEnv,
  int theIndex)
  {
   return ((void *) &((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->ModuleArray[theIndex]);
  }

canonical_original_code:
void *BloadDeffactsModuleReference(void *theEnv, int theIndex)
  {
   return ((void *) &((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->ModuleArray[theIndex]);
  }

variable_types: theIndex int

return_type: void *

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


BloadBinaryItem

decompiled_code:
__int64 __fastcall BloadBinaryItem(__int64 a1)
{
char v2[16]; // [rsp+8h] [rbp-10h] BYREF

GenReadBinary(a1, v2, 8LL);
BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL), 24LL, UpdateDeffactsModule);
return BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL), 32LL, UpdateDeffacts);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char v2[16]; // [rsp+8h] [rbp-10h] BYREF

GenReadBinary(a1, v2, 8LL);
BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL), 24LL, UpdateDeffactsModule);
return BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL), 32LL, UpdateDeffacts);
}

original_code:
static void BloadBinaryItem(
  void *theEnv)
  {
   unsigned long int space;
   GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long int));
   BloadandRefresh(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules,
                   (unsigned) sizeof(struct bsaveDeffactsModule),
                   UpdateDeffactsModule);
   BloadandRefresh(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts,
                   (unsigned) sizeof(struct bsaveDeffacts),
                   UpdateDeffacts);
  }

canonical_original_code:
static void BloadBinaryItem(void *theEnv)
  {
   unsigned long space;
   GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long));
   BloadandRefresh(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules,
                   (unsigned int) sizeof(struct bsaveDeffactsModule),
                   UpdateDeffactsModule);
   BloadandRefresh(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts,
                   (unsigned int) sizeof(struct bsaveDeffacts),
                   UpdateDeffacts);
  }

variable_types:
space
unsigned long

user_defined_types: struct bsaveDeffacts { struct bsaveConstructHeader header; long assertList; }

user_defined_types: struct bsaveDefmoduleItemHeader { long theModule; long firstItem; long lastItem; }

user_defined_types: struct bsaveConstructHeader { long name; long whichModule; long next; }


BsaveFind

decompiled_code:
__int64 __fastcall BsaveFind(__int64 a1)
{
__int64 result; // rax
__int64 i; // r12
__int64 j; // rbx

SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL));
SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL));
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL) = 0LL;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL) = 0LL;
result = EnvGetNextDefmodule(a1, 0LL);
for ( i = result; result; i = result )
{
EnvSetCurrentModule(a1, i);
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL);
for ( j = EnvGetNextDeffacts(a1, 0LL); j; j = EnvGetNextDeffacts(a1, j) )
{
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL);
MarkConstructHeaderNeededItems(j);
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 64LL) += ExpressionSize(*(_QWORD *)(j + 48));
MarkNeededItems(a1, *(_QWORD *)(j + 48));
}
result = EnvGetNextDefmodule(a1, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
__int64 i; // r12
__int64 j; // rbx

SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL));
SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL));
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL) = 0LL;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL) = 0LL;
result = EnvGetNextDefmodule(a1, 0LL);
for ( i = result; result; i = result )
{
EnvSetCurrentModule(a1, i);
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 24LL);
for ( j = EnvGetNextDeffacts(a1, 0LL); j; j = EnvGetNextDeffacts(a1, j) )
{
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 208LL) + 8LL);
MarkConstructHeaderNeededItems(j);
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 64LL) += ExpressionSize(*(_QWORD *)(j + 48));
MarkNeededItems(a1, *(_QWORD *)(j + 48));
}
result = EnvGetNextDefmodule(a1, i);
}
return result;
}

original_code:
static void BsaveFind(
  void *theEnv)
  {
   struct deffacts *theDeffacts;
   struct defmodule *theModule;
   SaveBloadCount(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules);
   SaveBloadCount(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts);
   ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts = 0;
   ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules = 0;
   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,((void *)0));
        theModule != ((void *)0);
        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
     {
      EnvSetCurrentModule(theEnv,(void *) theModule);
      ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules++;
      for (theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,((void *)0));
           theDeffacts != ((void *)0);
           theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,theDeffacts))
        {
         MarkConstructHeaderNeededItems(&theDeffacts->header,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts++);
         ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount += ExpressionSize(theDeffacts->assertList);
         MarkNeededItems(theEnv,theDeffacts->assertList);
        }
     }
  }

canonical_original_code:
static void BsaveFind(void *theEnv)
  {
   struct deffacts *theDeffacts;
   struct defmodule *theModule;
   SaveBloadCount(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules);
   SaveBloadCount(theEnv,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts);
   ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts = 0;
   ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules = 0;
   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,((void *)0));
        theModule != ((void *)0);
        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
     {
      EnvSetCurrentModule(theEnv,(void *) theModule);
      ((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffactsModules++;
      for (theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,((void *)0));
           theDeffacts != ((void *)0);
           theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,theDeffacts))
        {
         MarkConstructHeaderNeededItems(&theDeffacts->header,((struct deffactsBinaryData *) (((struct environmentData *) theEnv)->theData[26]))->NumberOfDeffacts++);
         ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount += ExpressionSize(theDeffacts->assertList);
         MarkNeededItems(theEnv,theDeffacts->assertList);
        }
     }
  }

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 deffactsBinaryData { struct deffacts *DeffactsArray; long NumberOfDeffacts; struct deffactsModule *ModuleArray; long NumberOfDeffactsModules; }

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


CheckArgumentAgainstRestriction

decompiled_code:
__int64 __fastcall CheckArgumentAgainstRestriction(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r13
__int64 v5; // rbp
__int64 v6; // r12
unsigned int v7; // ebp

v4 = ExpressionToConstraintRecord();
v5 = ArgumentTypeToConstraintRecord(a1, a3);
v6 = IntersectConstraints(a1, v4, v5);
RemoveConstraint(a1, v4);
RemoveConstraint(a1, v5);
if ( (unsigned int)UnmatchableConstraint(v6) )
{
RemoveConstraint(a1, v6);
v7 = 1;
}
else
{
v7 = 0;
RemoveConstraint(a1, v6);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r13
__int64 v5; // rbp
__int64 v6; // r12
unsigned int v7; // ebp

v4 = ExpressionToConstraintRecord();
v5 = ArgumentTypeToConstraintRecord(a1, a3);
v6 = IntersectConstraints(a1, v4, v5);
RemoveConstraint(a1, v4);
RemoveConstraint(a1, v5);
if ( (unsigned int)UnmatchableConstraint(v6) )
{
RemoveConstraint(a1, v6);
v7 = 1;
}
else
{
v7 = 0;
RemoveConstraint(a1, v6);
}
return v7;
}

original_code:
int CheckArgumentAgainstRestriction(
  void *theEnv,
  struct expr *theExpression,
  int theRestriction)
  {
   CONSTRAINT_RECORD *cr1, *cr2, *cr3;
   cr1 = ExpressionToConstraintRecord(theEnv,theExpression);
   cr2 = ArgumentTypeToConstraintRecord(theEnv,theRestriction);
   cr3 = IntersectConstraints(theEnv,cr1,cr2);
   RemoveConstraint(theEnv,cr1);
   RemoveConstraint(theEnv,cr2);
   if (UnmatchableConstraint(cr3))
     {
      RemoveConstraint(theEnv,cr3);
      return(1);
     }
   RemoveConstraint(theEnv,cr3);
   return(0);
  }

canonical_original_code:
int CheckArgumentAgainstRestriction(void *theEnv, struct expr *theExpression, int theRestriction)
  {
   struct constraintRecord *cr1; struct constraintRecord *cr2; struct constraintRecord *cr3;
   cr1 = ExpressionToConstraintRecord(theEnv,theExpression);
   cr2 = ArgumentTypeToConstraintRecord(theEnv,theRestriction);
   cr3 = IntersectConstraints(theEnv,cr1,cr2);
   RemoveConstraint(theEnv,cr1);
   RemoveConstraint(theEnv,cr2);
   if (UnmatchableConstraint(cr3))
     {
      RemoveConstraint(theEnv,cr3);
      return(1);
     }
   RemoveConstraint(theEnv,cr3);
   return(0);
  }

variable_types: theRestriction int

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

return_type: int

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


ConstantExpression

decompiled_code:
__int64 __fastcall ConstantExpression(__int64 a1)
{
if ( !a1 )
return 1LL;
do
{
if ( (unsigned __int16)(*(_WORD *)a1 - 7) > 1u && *(_WORD *)a1 > 3u )
return 0LL;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
return 1LL;
do
{
if ( (unsigned __int16)(*(_WORD *)a1 - 7) > 1u && *(_WORD *)a1 > 3u )
return 0LL;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return 1LL;
}

original_code:
int ConstantExpression(
  struct expr *testPtr)
  {
   while (testPtr != ((void *)0))
     {
      if ((testPtr->type != 2) && (testPtr->type != 3) &&
          (testPtr->type != 8) && (testPtr->type != 7) &&
          (testPtr->type != 1) && (testPtr->type != 0))
        { return(0); }
      testPtr = testPtr->nextArg;
     }
   return(1);
  }

canonical_original_code:
int ConstantExpression(struct expr *testPtr)
  {
   while (testPtr != ((void *)0))
     {
      if ((testPtr->type != 2) && (testPtr->type != 3) &&
          (testPtr->type != 8) && (testPtr->type != 7) &&
          (testPtr->type != 1) && (testPtr->type != 0))
        { return(0); }
      testPtr = testPtr->nextArg;
     }
   return(1);
  }

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


ConstantType

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

if ( a1 > 3 )
result = (unsigned int)(a1 - 7) <= 1;
else
result = a1 >= 0;
return result;
}

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

if ( a1 > 3 )
result = (unsigned int)(a1 - 7) <= 1;
else
result = a1 >= 0;
return result;
}

original_code:
int ConstantType(
  int theType)
  {
   switch (theType)
     {
      case 2:
      case 3:
      case 1:
      case 0:
      case 8:
      case 7:
        return(1);
     }
   return(0);
  }

canonical_original_code:
int ConstantType(int theType)
  {
   switch (theType)
     {
      case 2:
      case 3:
      case 1:
      case 0:
      case 8:
      case 7:
        return(1);
     }
   return(0);
  }

variable_types: theType int


CountArguments

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

original_code:
int CountArguments(
  struct expr *testPtr)
  {
   int size = 0;
   while (testPtr != ((void *)0))
     {
      size++;
      testPtr = testPtr->nextArg;
     }
   return(size);
  }

canonical_original_code:
int CountArguments(struct expr *testPtr)
  {
   int size = 0;
   while (testPtr != ((void *)0))
     {
      size++;
      testPtr = testPtr->nextArg;
     }
   return(size);
  }

variable_types: size int

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


GenConstant

original_code:
struct expr *GenConstant(
  void *theEnv,
  unsigned short type,
  void *value)
  {
   struct expr *top;
   top = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] == ((void *)0)) ? ((struct expr *) genalloc(theEnv,(unsigned) sizeof(struct expr))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct expr *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
   top->nextArg = ((void *)0);
   top->argList = ((void *)0);
   top->type = type;
   top->value = value;
   return(top);
  }

canonical_original_code:
struct expr *GenConstant(void *theEnv, unsigned short type, void *value)
  {
   struct expr *top;
   top = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] == ((void *)0)) ? ((struct expr *) genalloc(theEnv,(unsigned int) sizeof(struct expr))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct expr *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
   top->nextArg = ((void *)0);
   top->argList = ((void *)0);
   top->type = type;
   top->value = value;
   return(top);
  }

variable_types:
type
unsigned short

variable_types:
value
void *

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

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 memoryPtr { struct memoryPtr *next; }

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


CombineExpressions

original_code:
struct expr *CombineExpressions(
  void *theEnv,
  struct expr *expr1,
  struct expr *expr2)
  {
   struct expr *tempPtr;
   if (expr1 == ((void *)0)) return(expr2);
   if (expr2 == ((void *)0)) return(expr1);
   if ((expr1->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND) &&
       (expr2->value != ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND))
     {
      tempPtr = expr1->argList;
      if (tempPtr == ((void *)0))
        {
         (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr1, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
         return(expr2);
        }
      while (tempPtr->nextArg != ((void *)0))
        { tempPtr = tempPtr->nextArg; }
      tempPtr->nextArg = expr2;
      return(expr1);
     }
   if ((expr1->value != ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND) &&
       (expr2->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND))
     {
      tempPtr = expr2->argList;
      if (tempPtr == ((void *)0))
        {
         (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr2, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
         return(expr1);
        }
      expr2->argList = expr1;
      expr1->nextArg = tempPtr;
      return(expr2);
     }
   if ((expr1->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND) &&
       (expr2->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND))
     {
      tempPtr = expr1->argList;
      if (tempPtr == ((void *)0))
        {
         (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr1, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
         return(expr2);
        }
      while (tempPtr->nextArg != ((void *)0))
        { tempPtr = tempPtr->nextArg; }
      tempPtr->nextArg = expr2->argList;
      (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr2, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
      return(expr1);
     }
   tempPtr = GenConstant(theEnv,30,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND);
   tempPtr->argList = expr1;
   expr1->nextArg = expr2;
   return(tempPtr);
  }

canonical_original_code:
struct expr *CombineExpressions(void *theEnv, struct expr *expr1, struct expr *expr2)
  {
   struct expr *tempPtr;
   if (expr1 == ((void *)0)) return(expr2);
   if (expr2 == ((void *)0)) return(expr1);
   if ((expr1->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND) &&
       (expr2->value != ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND))
     {
      tempPtr = expr1->argList;
      if (tempPtr == ((void *)0))
        {
         (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr1, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
         return(expr2);
        }
      while (tempPtr->nextArg != ((void *)0))
        { tempPtr = tempPtr->nextArg; }
      tempPtr->nextArg = expr2;
      return(expr1);
     }
   if ((expr1->value != ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND) &&
       (expr2->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND))
     {
      tempPtr = expr2->argList;
      if (tempPtr == ((void *)0))
        {
         (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr2, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
         return(expr1);
        }
      expr2->argList = expr1;
      expr1->nextArg = tempPtr;
      return(expr2);
     }
   if ((expr1->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND) &&
       (expr2->value == ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND))
     {
      tempPtr = expr1->argList;
      if (tempPtr == ((void *)0))
        {
         (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr1, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
         return(expr2);
        }
      while (tempPtr->nextArg != ((void *)0))
        { tempPtr = tempPtr->nextArg; }
      tempPtr->nextArg = expr2->argList;
      (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) expr2, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct expr)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
      return(expr1);
     }
   tempPtr = GenConstant(theEnv,30,((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->PTR_AND);
   tempPtr->argList = expr1;
   expr1->nextArg = expr2;
   return(tempPtr);
  }

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


AppendExpressions

decompiled_code:
__int64 __fastcall AppendExpressions(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a1 )
return a2;
if ( !a2 )
return a1;
v2 = a1;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
*(_QWORD *)(v3 + 24) = a2;
return a1;
}

original_code:
struct expr *AppendExpressions(
  struct expr *expr1,
  struct expr *expr2)
  {
   struct expr *tempPtr;
   if (expr1 == ((void *)0)) return(expr2);
   if (expr2 == ((void *)0)) return(expr1);
   tempPtr = expr1;
   while (tempPtr->nextArg != ((void *)0)) tempPtr = tempPtr->nextArg;
   tempPtr->nextArg = expr2;
   return(expr1);
  }

canonical_original_code:
struct expr *AppendExpressions(struct expr *expr1, struct expr *expr2)
  {
   struct expr *tempPtr;
   if (expr1 == ((void *)0)) return(expr2);
   if (expr2 == ((void *)0)) return(expr1);
   tempPtr = expr1;
   while (tempPtr->nextArg != ((void *)0)) tempPtr = tempPtr->nextArg;
   tempPtr->nextArg = expr2;
   return(expr1);
  }