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) + 480LL) + 24LL), 24LL, UpdateDefglobalModule);
return BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL), 32LL, UpdateDefglobal);
}

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) + 480LL) + 24LL), 24LL, UpdateDefglobalModule);
return BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL), 32LL, UpdateDefglobal);
}

original_code:
static void BloadBinaryItem(
  void *theEnv)
  {
   unsigned long int space;
   GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long int));
   BloadandRefresh(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules,
                   (unsigned) sizeof(struct bsaveDefglobalModule),
                   UpdateDefglobalModule);
   BloadandRefresh(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals,
                   (unsigned) sizeof(struct bsaveDefglobal),
                   UpdateDefglobal);
  }

canonical_original_code:
static void BloadBinaryItem(void *theEnv)
  {
   unsigned long space;
   GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long));
   BloadandRefresh(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules,
                   (unsigned int) sizeof(struct bsaveDefglobalModule),
                   UpdateDefglobalModule);
   BloadandRefresh(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals,
                   (unsigned int) sizeof(struct bsaveDefglobal),
                   UpdateDefglobal);
  }

user_defined_types: struct defglobalBinaryData { struct defglobal *DefglobalArray; long NumberOfDefglobals; struct defglobalModule *ModuleArray; long NumberOfDefglobalModules; }

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

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

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


BsaveFind

repo: jarcec/rbclips

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

SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 24LL));
SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL));
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL) = 0LL;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 24LL) = 0LL;
result = EnvGetNextDefmodule(a1, 0LL);
for ( i = result; result; i = result )
{
EnvSetCurrentModule(a1, i);
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 24LL);
for ( j = EnvGetNextDefglobal(a1, 0LL); j; j = EnvGetNextDefglobal(a1, j) )
{
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL);
MarkConstructHeaderNeededItems(j);
}
result = EnvGetNextDefmodule(a1, i);
}
return result;
}

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

SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 24LL));
SaveBloadCount(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL));
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL) = 0LL;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 24LL) = 0LL;
result = EnvGetNextDefmodule(a1, 0LL);
for ( i = result; result; i = result )
{
EnvSetCurrentModule(a1, i);
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 24LL);
for ( j = EnvGetNextDefglobal(a1, 0LL); j; j = EnvGetNextDefglobal(a1, j) )
{
++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 480LL) + 8LL);
MarkConstructHeaderNeededItems(j);
}
result = EnvGetNextDefmodule(a1, i);
}
return result;
}

original_code:
static void BsaveFind(
  void *theEnv)
  {
   struct defglobal *defglobalPtr;
   struct defmodule *theModule;
   SaveBloadCount(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules);
   SaveBloadCount(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals);
   ((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals = 0;
   ((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules = 0;
   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,((void *)0));
        theModule != ((void *)0);
        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
     {
      EnvSetCurrentModule(theEnv,(void *) theModule);
      ((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules++;
      for (defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,((void *)0));
           defglobalPtr != ((void *)0);
           defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,defglobalPtr))
        {
         MarkConstructHeaderNeededItems(&defglobalPtr->header,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals++);
        }
     }
  }

canonical_original_code:
static void BsaveFind(void *theEnv)
  {
   struct defglobal *defglobalPtr;
   struct defmodule *theModule;
   SaveBloadCount(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules);
   SaveBloadCount(theEnv,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals);
   ((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals = 0;
   ((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules = 0;
   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,((void *)0));
        theModule != ((void *)0);
        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
     {
      EnvSetCurrentModule(theEnv,(void *) theModule);
      ((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobalModules++;
      for (defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,((void *)0));
           defglobalPtr != ((void *)0);
           defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,defglobalPtr))
        {
         MarkConstructHeaderNeededItems(&defglobalPtr->header,((struct defglobalBinaryData *) (((struct environmentData *) theEnv)->theData[60]))->NumberOfDefglobals++);
        }
     }
  }

variable_types:
theEnv
void *

variable_types: struct defglobal { 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; unsigned int watch; unsigned int inScope; long busyCount; struct dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; } current; struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *initial; } *

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

return_type: void

user_defined_types: struct defglobal { struct constructHeader header; unsigned int watch; unsigned int inScope; long busyCount; struct dataObject current; struct expr *initial; }

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 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 defglobalModule { struct defmoduleItemHeader header; }

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

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


DecrementDeftemplateBusyCount

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL);
if ( !*(_DWORD *)(result + 4) )
--*(_QWORD *)(a2 + 64);
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL);
if ( !*(_DWORD *)(result + 4) )
--*(_QWORD *)(a2 + 64);
return result;
}

original_code:
void DecrementDeftemplateBusyCount(
  void *theEnv,
  void *vTheTemplate)
  {
   struct deftemplate *theTemplate = (struct deftemplate *) vTheTemplate;
   if (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->ClearInProgress) theTemplate->busyCount--;
  }

canonical_original_code:
void DecrementDeftemplateBusyCount(void *theEnv, void *vTheTemplate)
  {
   struct deftemplate *theTemplate = (struct deftemplate *) vTheTemplate;
   if (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->ClearInProgress) theTemplate->busyCount--;
  }

variable_types:
vTheTemplate
void *

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

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

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

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

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

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

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


IncrementDeftemplateBusyCount

decompiled_code:
void __fastcall IncrementDeftemplateBusyCount(__int64 a1, __int64 a2)
{
++*(_QWORD *)(a2 + 64);
}

original_code:
void IncrementDeftemplateBusyCount(
  void *theEnv,
  void *vTheTemplate)
  {
   struct deftemplate *theTemplate = (struct deftemplate *) vTheTemplate;
   theTemplate->busyCount++;
  }

canonical_original_code:
void IncrementDeftemplateBusyCount(void *theEnv, void *vTheTemplate)
  {
   struct deftemplate *theTemplate = (struct deftemplate *) vTheTemplate;
   theTemplate->busyCount++;
  }

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 constructHeader { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader *whichModule; long bsaveID; struct constructHeader *next; struct userData *usrData; }

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 defmoduleItemHeader { struct defmodule *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; }

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

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

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

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 multifieldMarker { int whichField; union { void *whichSlot; short whichSlotNumber; } where; long startPosition; long endPosition; struct multifieldMarker *next; }

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


DestroyDeftemplate

original_code:
static void DestroyDeftemplate(
  void *theEnv,
  void *vTheConstruct)
  {
   struct deftemplate *theConstruct = (struct deftemplate *) vTheConstruct;
   struct templateSlot *slotPtr, *nextSlot;
   if (theConstruct == ((void *)0)) return;
   slotPtr = theConstruct->slotList;
   while (slotPtr != ((void *)0))
     {
      nextSlot = slotPtr->next;
      (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) slotPtr, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct templateSlot)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct templateSlot)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
      slotPtr = nextSlot;
     }
   DestroyFactPatternNetwork(theEnv,theConstruct->patternNetwork);
   DeinstallConstructHeader(theEnv,&theConstruct->header);
   (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) theConstruct, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deftemplate)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deftemplate)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
  }

canonical_original_code:
static void DestroyDeftemplate(void *theEnv, void *vTheConstruct)
  {
   struct deftemplate *theConstruct = (struct deftemplate *) vTheConstruct;
   struct templateSlot *slotPtr; struct templateSlot *nextSlot;
   if (theConstruct == ((void *)0)) return;
   slotPtr = theConstruct->slotList;
   while (slotPtr != ((void *)0))
     {
      nextSlot = slotPtr->next;
      (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) slotPtr, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct templateSlot)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct templateSlot)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
      slotPtr = nextSlot;
     }
   DestroyFactPatternNetwork(theEnv,theConstruct->patternNetwork);
   DeinstallConstructHeader(theEnv,&theConstruct->header);
   (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) theConstruct, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deftemplate)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deftemplate)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
  }

variable_types:
vTheConstruct
void *

variable_types: struct templateSlot { struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *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; } *

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 memoryData { long MemoryAmount; long MemoryCalls; int ConserveMemory; int (*OutOfMemoryFunction)(void *, unsigned long); struct memoryPtr *TempMemoryPtr; struct memoryPtr **MemoryTable; unsigned int TempSize; unsigned long TempSize2; }

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

user_defined_types: struct memoryPtr { struct memoryPtr *next; }

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

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 partialMatch { unsigned int betaMemory; unsigned int busy; unsigned int activationf; unsigned int dependentsf; unsigned int notOriginf; unsigned int counterf; unsigned int bcount; struct partialMatch *next; struct genericMatch binds[1]; }

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

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


DestroyDeftemplateAction

decompiled_code:
void __fastcall DestroyDeftemplateAction(__int64 a1, __int64 a2)
{
if ( a2 )
DestroyDeftemplate(a1, a2);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
if ( a2 )
func3(a1, a2);
}

original_code:
static void DestroyDeftemplateAction(
  void *theEnv,
  struct constructHeader *theConstruct,
  void *buffer)
  {
   struct deftemplate *theDeftemplate = (struct deftemplate *) theConstruct;
   if (theDeftemplate == ((void *)0)) return;
   DestroyDeftemplate(theEnv,theDeftemplate);
  }

canonical_original_code:
static void DestroyDeftemplateAction(void *theEnv, struct constructHeader *theConstruct, void *buffer)
  {
   struct deftemplate *theDeftemplate = (struct deftemplate *) theConstruct;
   if (theDeftemplate == ((void *)0)) return;
   DestroyDeftemplate(theEnv,theDeftemplate);
  }

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

variable_types:
buffer
void *

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 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 defmoduleItemHeader { struct defmodule *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; }

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

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

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

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

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


ReturnModule

original_code:
static void ReturnModule(
  void *theEnv,
  void *theItem)
  {
   FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,((struct defclassData *) (((struct environmentData *) theEnv)->theData[21]))->DefclassConstruct);
   DeleteSlotName(theEnv,FindIDSlotNameHash(theEnv,0));
   DeleteSlotName(theEnv,FindIDSlotNameHash(theEnv,1));
   (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) theItem, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct defclassModule)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct defclassModule)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
  }

canonical_original_code:
static void ReturnModule(void *theEnv, void *theItem)
  {
   FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,((struct defclassData *) (((struct environmentData *) theEnv)->theData[21]))->DefclassConstruct);
   DeleteSlotName(theEnv,FindIDSlotNameHash(theEnv,0));
   DeleteSlotName(theEnv,FindIDSlotNameHash(theEnv,1));
   (((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = (struct memoryPtr *) theItem, ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct defclassModule)], ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct defclassModule)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr);
  }

variable_types:
theItem
void *

user_defined_types: struct defclassModule { struct defmoduleItemHeader header; }

user_defined_types: struct defclassData { struct construct *DefclassConstruct; int DefclassModuleIndex; struct entityRecord DefclassEntityRecord; struct defclass *PrimitiveClassMap[9]; struct defclass **ClassIDMap; struct defclass **ClassTable; unsigned short MaxClassID; unsigned short AvailClassID; struct slotName **SlotNameTable; struct symbolHashNode *ISA_SYMBOL; struct symbolHashNode *NAME_SYMBOL; struct symbolHashNode *INITIAL_OBJECT_SYMBOL; unsigned int WatchInstances; unsigned int WatchSlots; unsigned short CTID; struct token ObjectParseToken; unsigned short ClassDefaultsMode; }

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

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 defclass { struct constructHeader header; unsigned int installed; unsigned int system; unsigned int abstract; unsigned int reactive; unsigned int traceInstances; unsigned int traceSlots; unsigned short id; unsigned int busy; struct packedClassLinks directSuperclasses; struct slotDescriptor *slots; unsigned int *slotNameMap; unsigned int slotCount; struct instance *instanceList; struct messageHandler *handlers; unsigned int *handlerOrderMap; unsigned int handlerCount; struct defclass *nxtHash; struct bitMapHashNode *scopeMap; char traversalRecord[32]; }

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 portItem { struct symbolHashNode *moduleName; struct symbolHashNode *constructType; struct symbolHashNode *constructName; struct portItem *next; }

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

user_defined_types: struct packedClassLinks { unsigned short classCount; struct defclass **classArray; }

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

user_defined_types: struct slotDescriptor { unsigned int shared; unsigned int multiple; unsigned int composite; unsigned int noInherit; unsigned int noWrite; unsigned int initializeOnly; unsigned int dynamicDefault; unsigned int defaultSpecified; unsigned int noDefault; unsigned int reactive; unsigned int publicVisibility; unsigned int createReadAccessor; unsigned int createWriteAccessor; unsigned int overrideMessageSpecified; struct defclass *cls; struct slotName *slotName; struct symbolHashNode *overrideMessage; void *defaultValue; struct constraintRecord *constraint; unsigned int sharedCount; long bsaveIndex; struct instanceSlot sharedValue; }

user_defined_types: struct instance { struct patternEntity header; void *partialMatchList; struct instanceSlot *basisSlots; unsigned int installed; unsigned int garbage; unsigned int initSlotsCalled; unsigned int initializeInProgress; unsigned int reteSynchronized; struct symbolHashNode *name; int depth; unsigned int hashTableIndex; unsigned int busy; struct defclass *cls; struct instance *prvClass; struct instanceSlot **slotAddresses; }

user_defined_types: struct messageHandler { unsigned int system; unsigned int type; unsigned int mark; unsigned int trace; unsigned int busy; struct symbolHashNode *name; struct defclass *cls; int minParams; struct expr *actions; char *ppForm; struct userData *usrData; }

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

user_defined_types: struct instanceSlot { struct slotDescriptor *desc; unsigned int valueRequired; unsigned int override; unsigned int type; void *value; }

user_defined_types: struct slotName { unsigned int hashTableIndex; struct symbolHashNode *name; struct slotName *nxt; long bsaveIndex; }

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


EnvIsDeftemplateDeletable

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

result = ConstructsDeletable();
if ( (_DWORD)result )
{
result = 0LL;
if ( *(__int64 *)(a2 + 64) <= 0 )
result = *(_QWORD *)(a2 + 72) == 0LL;
}
return result;
}

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

result = ConstructsDeletable();
if ( (_DWORD)result )
{
result = 0LL;
if ( *(__int64 *)(a2 + 64) <= 0 )
result = *(_QWORD *)(a2 + 72) == 0LL;
}
return result;
}

original_code:
int EnvIsDeftemplateDeletable(
  void *theEnv,
  void *vTheDeftemplate)
  {
   struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
   if (! ConstructsDeletable(theEnv))
     { return 0; }
   if (theDeftemplate->busyCount > 0) return(0);
   if (theDeftemplate->patternNetwork != ((void *)0)) return(0);
   return(1);
  }

canonical_original_code:
int EnvIsDeftemplateDeletable(void *theEnv, void *vTheDeftemplate)
  {
   struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
   if (! ConstructsDeletable(theEnv))
     { return 0; }
   if (theDeftemplate->busyCount > 0) return(0);
   if (theDeftemplate->patternNetwork != ((void *)0)) return(0);
   return(1);
  }

variable_types:
vTheDeftemplate
void *

return_type: int

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 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 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 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 partialMatch { unsigned int betaMemory; unsigned int busy; unsigned int activationf; unsigned int dependentsf; unsigned int notOriginf; unsigned int counterf; unsigned int bcount; struct partialMatch *next; struct genericMatch binds[1]; }

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

user_defined_types: struct field { unsigned short type; void *value; }

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

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

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 alphaMatch { struct patternEntity *matchingItem; struct multifieldMarker *markers; struct alphaMatch *next; }

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

user_defined_types: struct multifieldMarker { int whichField; union { void *whichSlot; short whichSlotNumber; } where; long startPosition; long endPosition; struct multifieldMarker *next; }

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

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


EnvGetNextFactInTemplate

decompiled_code:
__int64 __fastcall EnvGetNextFactInTemplate(__int64 a1, __int64 a2, __int64 a3)
{
if ( !a3 )
return *(_QWORD *)(a2 + 80);
if ( *(char *)(a3 + 57) < 0 )
return 0LL;
return *(_QWORD *)(a3 + 88);
}

original_code:
void *EnvGetNextFactInTemplate(
  void *theEnv,
  void *theTemplate,
  void *factPtr)
  {
   if (factPtr == ((void *)0))
     { return((void *) ((struct deftemplate *) theTemplate)->factList); }
   if (((struct fact *) factPtr)->garbage) return(((void *)0));
   return((void *) ((struct fact *) factPtr)->nextTemplateFact);
  }

canonical_original_code:
void *EnvGetNextFactInTemplate(void *theEnv, void *theTemplate, void *factPtr)
  {
   if (factPtr == ((void *)0))
     { return((void *) ((struct deftemplate *) theTemplate)->factList); }
   if (((struct fact *) factPtr)->garbage) return(((void *)0));
   return((void *) ((struct fact *) factPtr)->nextTemplateFact);
  }

variable_types:
theTemplate
void *

variable_types:
factPtr
void *

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 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 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 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 userData { unsigned char dataID; struct userData *next; }

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

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


DefaultCompareSwapFunction

original_code:
static int DefaultCompareSwapFunction(
  void *theEnv,
  DATA_OBJECT *item1,
  DATA_OBJECT *item2)
  {
   DATA_OBJECT returnValue;
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList = GenConstant(theEnv,item1->type,item1->value);
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList->nextArg = GenConstant(theEnv,item2->type,item2->value);
   ExpressionInstall(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction);
   EvaluateExpression(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction,&returnValue);
   ExpressionDeinstall(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction);
   ReturnExpression(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList);
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList = ((void *)0);
   if ((((returnValue).type) == 2) &&
       (((returnValue).value) == ((struct symbolData *) (((struct environmentData *) theEnv)->theData[49]))->FalseSymbolHN))
     { return(0); }
   return(1);
  }

canonical_original_code:
static int DefaultCompareSwapFunction(void *theEnv, struct dataObject *item1, struct dataObject *item2)
  {
   struct dataObject returnValue;
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList = GenConstant(theEnv,item1->type,item1->value);
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList->nextArg = GenConstant(theEnv,item2->type,item2->value);
   ExpressionInstall(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction);
   EvaluateExpression(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction,&returnValue);
   ExpressionDeinstall(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction);
   ReturnExpression(theEnv,((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList);
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->argList = ((void *)0);
   if ((((returnValue).type) == 2) &&
       (((returnValue).value) == ((struct symbolData *) (((struct environmentData *) theEnv)->theData[49]))->FalseSymbolHN))
     { return(0); }
   return(1);
  }

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

user_defined_types: struct sortFunctionData { struct expr *SortComparisonFunction; }

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 symbolData { void *TrueSymbolHN; void *FalseSymbolHN; void *PositiveInfinity; void *NegativeInfinity; void *Zero; struct symbolHashNode **SymbolTable; struct floatHashNode **FloatTable; struct integerHashNode **IntegerTable; struct bitMapHashNode **BitMapTable; struct ephemeron *EphemeralSymbolList; struct ephemeron *EphemeralFloatList; struct ephemeron *EphemeralIntegerList; struct ephemeron *EphemeralBitMapList; long NumberOfSymbols; long NumberOfFloats; long NumberOfIntegers; long NumberOfBitMaps; struct symbolHashNode **SymbolArray; struct floatHashNode **FloatArray; struct integerHashNode **IntegerArray; struct bitMapHashNode **BitMapArray; }

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

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

user_defined_types: struct ephemeron { struct genericHashNode *associatedValue; struct ephemeron *next; }

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

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

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

user_defined_types: struct genericHashNode { struct genericHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int needed; unsigned int bucket; }


DoMergeSort

decompiled_code:
void __fastcall DoMergeSort(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4, unsigned __int64 a5, unsigned __int64 a6, unsigned __int64 a7, unsigned int (__fastcall *a8)(__int64, unsigned __int64, unsigned __int64))
{
unsigned __int64 v11; // r15
unsigned __int64 v12; // r14
int v13; // er9
unsigned __int64 v14; // r15
unsigned __int64 v15; // r14
unsigned __int64 v16; // r15
unsigned __int64 v17; // r12
__int64 v18; // rbx
int v19; // er9
unsigned __int64 v20; // rbx
__int64 v21; // rbp
__int64 v22; // r12
__int64 v24; // [rsp+28h] [rbp-80h]
__int64 v25; // [rsp+30h] [rbp-78h]
unsigned __int64 v26; // [rsp+38h] [rbp-70h]
char v27[104]; // [rsp+40h] [rbp-68h] BYREF

if ( a4 != a5 )
{
if ( a4 + 1 == a5 )
{
v11 = a2 + 48 * a5;
v12 = a2 + 48 * a4;
if ( a8(a1, v12, v11) )
{
TransferDataObjectValues(v27, v12);
TransferDataObjectValues(v12, v11);
TransferDataObjectValues(v11, v27);
}
}
else
{
v13 = a4 + ((a5 + 2 - a4) >> 1);
DoMergeSort(a1, a2, a3, a4, v13 - 1, v13, a5, (__int64)a8);
}
}
if ( a6 == a7 )
{
a6 = a7;
}
else if ( a6 + 1 == a7 )
{
v14 = a2 + 48 * a7;
v15 = a2 + 48 * a6;
if ( a8(a1, v15, v14) )
{
TransferDataObjectValues(v27, v15);
TransferDataObjectValues(v15, v14);
TransferDataObjectValues(v14, v27);
}
}
else
{
v19 = a6 + ((a7 + 2 - a6) >> 1);
DoMergeSort(a1, a2, a3, a6, v19 - 1, v19, a7, (__int64)a8);
}
if ( a4 <= a7 )
{
v16 = a4 + 1;
v25 = 48 * a4;
v24 = 48 * a4 + a3;
v17 = a4;
v26 = a4;
v18 = v24;
while ( 1 )
{
if ( a5 < v17 || a7 >= a6 && a8(a1, a2 + 48 * v17, a2 + 48 * a6) )
TransferDataObjectValues(v18, a2 + 48 * a6++);
else
TransferDataObjectValues(v18, a2 + 48 * v17++);
v18 += 48LL;
if ( v16 > a7 )
break;
++v16;
}
v20 = v26;
v21 = v25 + a2;
v22 = v24;
do
{
TransferDataObjectValues(v21, v22);
++v20;
v21 += 48LL;
v22 += 48LL;
}
while ( a7 >= v20 );
}
}

original_code:
static void DoMergeSort(
  void *theEnv,
  DATA_OBJECT *theList,
  DATA_OBJECT *tempList,
  unsigned long s1,
  unsigned long e1,
  unsigned long s2,
  unsigned long e2,
  int (*swapFunction)(void *,DATA_OBJECT *,DATA_OBJECT *))
  {
   DATA_OBJECT temp;
   unsigned long middle, size;
   unsigned long c1, c2, mergePoint;
   if (s1 == e1)
     { }
   else if ((s1 + 1) == e1)
     {
      if ((*swapFunction)(theEnv,&theList[s1],&theList[e1]))
        {
         TransferDataObjectValues(&temp,&theList[s1]);
         TransferDataObjectValues(&theList[s1],&theList[e1]);
         TransferDataObjectValues(&theList[e1],&temp);
        }
     }
   else
     {
      size = ((e1 - s1) + 1);
      middle = s1 + ((size + 1) / 2);
      DoMergeSort(theEnv,theList,tempList,s1,middle-1,middle,e1,swapFunction);
     }
   if (s2 == e2)
     { }
   else if ((s2 + 1) == e2)
     {
      if ((*swapFunction)(theEnv,&theList[s2],&theList[e2]))
        {
         TransferDataObjectValues(&temp,&theList[s2]);
         TransferDataObjectValues(&theList[s2],&theList[e2]);
         TransferDataObjectValues(&theList[e2],&temp);
        }
     }
   else
     {
      size = ((e2 - s2) + 1);
      middle = s2 + ((size + 1) / 2);
      DoMergeSort(theEnv,theList,tempList,s2,middle-1,middle,e2,swapFunction);
     }
   mergePoint = s1;
   c1 = s1;
   c2 = s2;
   while (mergePoint <= e2)
     {
      if (c1 > e1)
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c2]);
         c2++;
         mergePoint++;
        }
      else if (c2 > e2)
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c1]);
         c1++;
         mergePoint++;
        }
      else if ((*swapFunction)(theEnv,&theList[c1],&theList[c2]))
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c2]);
         c2++;
         mergePoint++;
        }
      else
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c1]);
         c1++;
         mergePoint++;
        }
     }
   for (c1 = s1; c1 <= e2; c1++)
     { TransferDataObjectValues(&theList[c1],&tempList[c1]); }
  }

canonical_original_code:
static void DoMergeSort(void *theEnv, struct dataObject *theList, struct dataObject *tempList, unsigned long s1, unsigned long e1, unsigned long s2, unsigned long e2, int (*swapFunction)(void *, struct dataObject *, struct dataObject *))
  {
   struct dataObject temp;
   unsigned long middle; unsigned long size;
   unsigned long c1; unsigned long c2; unsigned long mergePoint;
   if (s1 == e1)
     { }
   else if ((s1 + 1) == e1)
     {
      if ((*swapFunction)(theEnv,&theList[s1],&theList[e1]))
        {
         TransferDataObjectValues(&temp,&theList[s1]);
         TransferDataObjectValues(&theList[s1],&theList[e1]);
         TransferDataObjectValues(&theList[e1],&temp);
        }
     }
   else
     {
      size = ((e1 - s1) + 1);
      middle = s1 + ((size + 1) / 2);
      DoMergeSort(theEnv,theList,tempList,s1,middle-1,middle,e1,swapFunction);
     }
   if (s2 == e2)
     { }
   else if ((s2 + 1) == e2)
     {
      if ((*swapFunction)(theEnv,&theList[s2],&theList[e2]))
        {
         TransferDataObjectValues(&temp,&theList[s2]);
         TransferDataObjectValues(&theList[s2],&theList[e2]);
         TransferDataObjectValues(&theList[e2],&temp);
        }
     }
   else
     {
      size = ((e2 - s2) + 1);
      middle = s2 + ((size + 1) / 2);
      DoMergeSort(theEnv,theList,tempList,s2,middle-1,middle,e2,swapFunction);
     }
   mergePoint = s1;
   c1 = s1;
   c2 = s2;
   while (mergePoint <= e2)
     {
      if (c1 > e1)
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c2]);
         c2++;
         mergePoint++;
        }
      else if (c2 > e2)
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c1]);
         c1++;
         mergePoint++;
        }
      else if ((*swapFunction)(theEnv,&theList[c1],&theList[c2]))
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c2]);
         c2++;
         mergePoint++;
        }
      else
        {
         TransferDataObjectValues(&tempList[mergePoint],&theList[c1]);
         c1++;
         mergePoint++;
        }
     }
   for (c1 = s1; c1 <= e2; c1++)
     { TransferDataObjectValues(&theList[c1],&tempList[c1]); }
  }

variable_types:
tempList
struct dataObject *

variable_types: int (*)(void *, struct dataObject *, struct dataObject *)

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

variable_types:
middle
unsigned long

variable_types:
size
unsigned long

variable_types:
mergePoint
unsigned long


SortFunctionDefinitions

decompiled_code:
__int64 __fastcall SortFunctionDefinitions(__int64 a1)
{
AllocateEnvironmentData(a1, 7LL, 8LL, 0LL);
return EnvDefineFunction2(a1, "sort", 117LL, SortFunction, "SortFunction", "1**w");
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
AllocateEnvironmentData(a1, 7LL, 8LL, 0LL);
return EnvDefineFunction2(a1, "sort", 117LL, SortFunction, "SortFunction", "1**w");
}

original_code:
void SortFunctionDefinitions(
  void *theEnv)
  {
   AllocateEnvironmentData(theEnv,7,sizeof(struct sortFunctionData),((void *)0));
   EnvDefineFunction2(theEnv,"sort",'u', (int (*)(void *)) SortFunction,"SortFunction","1**w");
  }

canonical_original_code:
void SortFunctionDefinitions(void *theEnv)
  {
   AllocateEnvironmentData(theEnv,7,sizeof(struct sortFunctionData),((void *)0));
   EnvDefineFunction2(theEnv,"sort",'u', (int (*)(void *)) SortFunction,"SortFunction","1**w");
  }

variable_types:
theEnv
void *


MergeSort

decompiled_code:
void __fastcall MergeSort(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned int (__fastcall *a4)(__int64, unsigned __int64, unsigned __int64))
{
__int64 v6; // r13

if ( a2 > 1 )
{
v6 = genalloc(a1, (unsigned int)(48 * a2));
DoMergeSort(a1, a3, v6, 0LL, ((a2 + 1) >> 1) - 1, (a2 + 1) >> 1, a2 - 1, a4);
genfree(a1, v6, (unsigned int)(48 * a2));
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned int (__fastcall *a4)(__int64, unsigned __int64, unsigned __int64))
{
__int64 v6; // r13

if ( a2 > 1 )
{
v6 = genalloc(a1, (unsigned int)(48 * a2));
func1(a1, a3, v6, 0LL, ((a2 + 1) >> 1) - 1, (a2 + 1) >> 1, a2 - 1, a4);
genfree(a1, v6, (unsigned int)(48 * a2));
}
}

original_code:
void MergeSort(
  void *theEnv,
  unsigned long listSize,
  DATA_OBJECT *theList,
  int (*swapFunction)(void *,DATA_OBJECT *,DATA_OBJECT *))
  {
   DATA_OBJECT *tempList;
   unsigned long middle;
   if (listSize <= 1) return;
   tempList = (DATA_OBJECT *) genalloc(theEnv,listSize * sizeof(DATA_OBJECT));
   middle = (listSize + 1) / 2;
   DoMergeSort(theEnv,theList,tempList,0,middle-1,middle,listSize - 1,swapFunction);
   genfree(theEnv,tempList,listSize * sizeof(DATA_OBJECT));
  }

canonical_original_code:
void MergeSort(void *theEnv, unsigned long listSize, struct dataObject *theList, int (*swapFunction)(void *, struct dataObject *, struct dataObject *))
  {
   struct dataObject *tempList;
   unsigned long middle;
   if (listSize <= 1) return;
   tempList = (struct dataObject *) genalloc(theEnv,listSize * sizeof(DATA_OBJECT));
   middle = (listSize + 1) / 2;
   DoMergeSort(theEnv,theList,tempList,0,middle-1,middle,listSize - 1,swapFunction);
   genfree(theEnv,tempList,listSize * sizeof(DATA_OBJECT));
  }

variable_types:
listSize
unsigned long


SortFunction

decompiled_code:
__int64 __fastcall SortFunction(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // er12
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rbp
int v7; // er13
__int64 v8; // r14
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // r11
__int64 v12; // rcx
__int64 v13; // rbp
__int64 v14; // rsi
__int64 v15; // rax
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // r14
__int64 v19; // rbp
__int64 i; // r12
__int64 j; // r12
__int64 v22; // rax
__int64 v23; // rbp
__int64 v24; // rdx
__int64 v25; // rsi
__int64 v26; // r9
__int64 v27; // [rsp+0h] [rbp-98h]
__int64 v29; // [rsp+10h] [rbp-88h]
__int64 v30; // [rsp+18h] [rbp-80h]
unsigned int v31; // [rsp+28h] [rbp-70h]
char v32[16]; // [rsp+30h] [rbp-68h] BYREF
__int64 v33; // [rsp+40h] [rbp-58h]

*(_WORD *)(a2 + 8) = 2;
*(_QWORD *)(a2 + 16) = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 392LL) + 8LL);
result = EnvArgCountCheck(a1, "sort", 1LL, 1LL);
if ( (_DWORD)result != -1 )
{
v3 = result;
v4 = (int)result;
result = EnvArgTypeCheck(a1, "sort", 1LL, 2LL, v32);
if ( (_DWORD)result )
{
v27 = FunctionReferenceExpression(a1, *(_QWORD *)(v33 + 24));
if ( v27 )
{
if ( *(_WORD *)v27 == 30
&& ((v9 = *(_QWORD *)(v27 + 8), (int)GetMinimumArgs(v9) > 2)
|| !(unsigned int)GetMaximumArgs(v9)
|| (unsigned int)GetMaximumArgs(v9) == 1) )
{
ExpectedTypeError1(a1, "sort", 1LL, "function name expecting two arguments");
result = ReturnExpression(a1, v27);
}
else if ( *(_WORD *)v27 == 32
&& ((v10 = *(_QWORD *)(v27 + 8), *(int *)(v10 + 72) > 2) || *(_DWORD *)(v10 + 76) <= 1u) )
{
ExpectedTypeError1(a1, "sort", 1LL, "deffunction name expecting two arguments");
result = ReturnExpression(a1, v27);
}
else if ( v4 == 1 )
{
EnvSetMultifieldErrorValue(a1, a2);
result = ReturnExpression(a1, v27);
}
else
{
v31 = 16 * (3 * v4 - 3);
v5 = genalloc(a1, v31);
v30 = v5;
if ( v4 <= 1 )
goto LABEL_24;
v6 = v5;
v7 = 0;
v8 = 2LL;
do
{
EnvRtnUnknown(a1, (unsigned int)v8, v6);
if ( *(_WORD *)(v6 + 8) == 4 )
v7 = *(_DWORD *)(v6 + 32) + v7 + 1 - *(_DWORD *)(v6 + 24);
else
++v7;
++v8;
v6 += 48LL;
}
while ( v8 != v3 + 1LL );
if ( v7 )
{
v26 = genalloc(a1, (unsigned int)(48 * v7));
v29 = v26;
v16 = v30 + 8;
v15 = 0LL;
do
{
if ( *(_WORD *)v16 == 4 )
{
v11 = *(_QWORD *)(v16 + 16);
if ( v11 <= *(_QWORD *)(v16 + 24) )
{
v12 = 16 * v11 + *(_QWORD *)(v16 + 8);
v13 = v15;
v14 = v26 + 48 * v15 + 8;
do
{
*(_WORD *)v14 = *(_WORD *)(v12 + 24);
*(_QWORD *)(v14 + 8) = *(_QWORD *)(v12 + 32);
++v15;
v12 += 16LL;
v14 += 48LL;
}
while ( v11 + v15 - v13 <= *(_QWORD *)(v16 + 24) );
}
}
else
{
v17 = v26 + 48 * v15;
*(_WORD *)(v17 + 8) = *(_WORD *)v16;
*(_QWORD *)(v17 + 16) = *(_QWORD *)(v16 + 8);
++v15;
}
v16 += 48LL;
}
while ( v16 != v30 + 48LL * v3 - 40 );
genfree(a1, v30, v31);
*(_QWORD *)(v27 + 24) = **(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL);
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) = v27;
if ( v7 <= 0 )
{
MergeSort(
a1,
v7,
v29,
(unsigned int (__fastcall *)(__int64, unsigned __int64, unsigned __int64))DefaultCompareSwapFunction);
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) = *(_QWORD *)(**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) + 24LL);
*(_QWORD *)(v27 + 24) = 0LL;
ReturnExpression(a1, v27);
v23 = EnvCreateMultifield(a1, v7);
}
else
{
v18 = v29;
v19 = v29;
for ( i = 0LL; i != v7; ++i )
{
ValueInstall(a1, v18);
v18 += 48LL;
}
MergeSort(
a1,
v7,
v29,
(unsigned int (__fastcall *)(__int64, unsigned __int64, unsigned __int64))DefaultCompareSwapFunction);
for ( j = 0LL; j != v7; ++j )
{
ValueDeinstall(a1, v19);
v19 += 48LL;
}
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) = *(_QWORD *)(**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) + 24LL);
*(_QWORD *)(v27 + 24) = 0LL;
ReturnExpression(a1, v27);
v22 = EnvCreateMultifield(a1, v7);
v23 = v22;
v24 = v29 + 8;
v25 = v22 + 16LL * v7;
do
{
*(_WORD *)(v22 + 24) = *(_WORD *)v24;
*(_QWORD *)(v22 + 32) = *(_QWORD *)(v24 + 8);
v24 += 48LL;
v22 += 16LL;
}
while ( v22 != v25 );
}
genfree(a1, v29, (unsigned int)(48 * v7));
result = a2;
*(_WORD *)(a2 + 8) = 4;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = v7 - 1;
*(_QWORD *)(a2 + 16) = v23;
}
else
{
LABEL_24:
genfree(a1, v30, v31);
EnvSetMultifieldErrorValue(a1, a2);
result = ReturnExpression(a1, v27);
}
}
}
else
{
result = ExpectedTypeError1(a1, "sort", 1LL, "function name, deffunction name, or defgeneric name");
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // er12
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rbp
int v7; // er13
__int64 v8; // r14
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // r11
__int64 v12; // rcx
__int64 v13; // rbp
__int64 v14; // rsi
__int64 v15; // rax
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // r14
__int64 v19; // rbp
__int64 i; // r12
__int64 j; // r12
__int64 v22; // rax
__int64 v23; // rbp
__int64 v24; // rdx
__int64 v25; // rsi
__int64 v26; // r9
__int64 v27; // [rsp+0h] [rbp-98h]
__int64 v29; // [rsp+10h] [rbp-88h]
__int64 v30; // [rsp+18h] [rbp-80h]
unsigned int v31; // [rsp+28h] [rbp-70h]
char v32[16]; // [rsp+30h] [rbp-68h] BYREF
__int64 v33; // [rsp+40h] [rbp-58h]

*(_WORD *)(a2 + 8) = 2;
*(_QWORD *)(a2 + 16) = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 392LL) + 8LL);
result = EnvArgCountCheck(a1, "sort", 1LL, 1LL);
if ( (_DWORD)result != -1 )
{
v3 = result;
v4 = (int)result;
result = EnvArgTypeCheck(a1, "sort", 1LL, 2LL, v32);
if ( (_DWORD)result )
{
v27 = FunctionReferenceExpression(a1, *(_QWORD *)(v33 + 24));
if ( v27 )
{
if ( *(_WORD *)v27 == 30
&& ((v9 = *(_QWORD *)(v27 + 8), (int)GetMinimumArgs(v9) > 2)
|| !(unsigned int)GetMaximumArgs(v9)
|| (unsigned int)GetMaximumArgs(v9) == 1) )
{
ExpectedTypeError1(a1, "sort", 1LL, "function name expecting two arguments");
result = ReturnExpression(a1, v27);
}
else if ( *(_WORD *)v27 == 32
&& ((v10 = *(_QWORD *)(v27 + 8), *(int *)(v10 + 72) > 2) || *(_DWORD *)(v10 + 76) <= 1u) )
{
ExpectedTypeError1(a1, "sort", 1LL, "deffunction name expecting two arguments");
result = ReturnExpression(a1, v27);
}
else if ( v4 == 1 )
{
EnvSetMultifieldErrorValue(a1, a2);
result = ReturnExpression(a1, v27);
}
else
{
v31 = 16 * (3 * v4 - 3);
v5 = genalloc(a1, v31);
v30 = v5;
if ( v4 <= 1 )
goto LABEL_24;
v6 = v5;
v7 = 0;
v8 = 2LL;
do
{
EnvRtnUnknown(a1, (unsigned int)v8, v6);
if ( *(_WORD *)(v6 + 8) == 4 )
v7 = *(_DWORD *)(v6 + 32) + v7 + 1 - *(_DWORD *)(v6 + 24);
else
++v7;
++v8;
v6 += 48LL;
}
while ( v8 != v3 + 1LL );
if ( v7 )
{
v26 = genalloc(a1, (unsigned int)(48 * v7));
v29 = v26;
v16 = v30 + 8;
v15 = 0LL;
do
{
if ( *(_WORD *)v16 == 4 )
{
v11 = *(_QWORD *)(v16 + 16);
if ( v11 <= *(_QWORD *)(v16 + 24) )
{
v12 = 16 * v11 + *(_QWORD *)(v16 + 8);
v13 = v15;
v14 = v26 + 48 * v15 + 8;
do
{
*(_WORD *)v14 = *(_WORD *)(v12 + 24);
*(_QWORD *)(v14 + 8) = *(_QWORD *)(v12 + 32);
++v15;
v12 += 16LL;
v14 += 48LL;
}
while ( v11 + v15 - v13 <= *(_QWORD *)(v16 + 24) );
}
}
else
{
v17 = v26 + 48 * v15;
*(_WORD *)(v17 + 8) = *(_WORD *)v16;
*(_QWORD *)(v17 + 16) = *(_QWORD *)(v16 + 8);
++v15;
}
v16 += 48LL;
}
while ( v16 != v30 + 48LL * v3 - 40 );
genfree(a1, v30, v31);
*(_QWORD *)(v27 + 24) = **(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL);
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) = v27;
if ( v7 <= 0 )
{
func3(
a1,
v7,
v29,
(unsigned int (__fastcall *)(__int64, unsigned __int64, unsigned __int64))DefaultCompareSwapFunction);
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) = *(_QWORD *)(**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) + 24LL);
*(_QWORD *)(v27 + 24) = 0LL;
ReturnExpression(a1, v27);
v23 = EnvCreateMultifield(a1, v7);
}
else
{
v18 = v29;
v19 = v29;
for ( i = 0LL; i != v7; ++i )
{
ValueInstall(a1, v18);
v18 += 48LL;
}
func3(
a1,
v7,
v29,
(unsigned int (__fastcall *)(__int64, unsigned __int64, unsigned __int64))DefaultCompareSwapFunction);
for ( j = 0LL; j != v7; ++j )
{
ValueDeinstall(a1, v19);
v19 += 48LL;
}
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) = *(_QWORD *)(**(_QWORD **)(*(_QWORD *)(a1 + 32) + 56LL) + 24LL);
*(_QWORD *)(v27 + 24) = 0LL;
ReturnExpression(a1, v27);
v22 = EnvCreateMultifield(a1, v7);
v23 = v22;
v24 = v29 + 8;
v25 = v22 + 16LL * v7;
do
{
*(_WORD *)(v22 + 24) = *(_WORD *)v24;
*(_QWORD *)(v22 + 32) = *(_QWORD *)(v24 + 8);
v24 += 48LL;
v22 += 16LL;
}
while ( v22 != v25 );
}
genfree(a1, v29, (unsigned int)(48 * v7));
result = a2;
*(_WORD *)(a2 + 8) = 4;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = v7 - 1;
*(_QWORD *)(a2 + 16) = v23;
}
else
{
LABEL_24:
genfree(a1, v30, v31);
EnvSetMultifieldErrorValue(a1, a2);
result = ReturnExpression(a1, v27);
}
}
}
else
{
result = ExpectedTypeError1(a1, "sort", 1LL, "function name, deffunction name, or defgeneric name");
}
}
}
return result;
}

original_code:
void SortFunction(
  void *theEnv,
  DATA_OBJECT_PTR returnValue)
  {
   long argumentCount, i, j, k = 0;
   DATA_OBJECT *theArguments, *theArguments2;
   DATA_OBJECT theArg;
   struct multifield *theMultifield, *tempMultifield;
   char *functionName;
   struct expr *functionReference;
   int argumentSize = 0;
   struct FunctionDefinition *fptr;
   DEFFUNCTION *dptr;
   ((returnValue)->type = (unsigned short) (2));
   ((returnValue)->value = (void *) (((struct symbolData *) (((struct environmentData *) theEnv)->theData[49]))->FalseSymbolHN));
   if ((argumentCount = EnvArgCountCheck(theEnv,"sort",1,1)) == -1)
     { return; }
   if (EnvArgTypeCheck(theEnv,"sort",1,2,&theArg) == 0)
     { return; }
   functionName = (((struct symbolHashNode *) (theArg.value))->contents);
   functionReference = FunctionReferenceExpression(theEnv,functionName);
   if (functionReference == ((void *)0))
     {
      ExpectedTypeError1(theEnv,"sort",1,"function name, deffunction name, or defgeneric name");
      return;
     }
   if (functionReference->type == 30)
     {
      fptr = (struct FunctionDefinition *) functionReference->value;
      if ((GetMinimumArgs(fptr) > 2) ||
          (GetMaximumArgs(fptr) == 0) ||
          (GetMaximumArgs(fptr) == 1))
        {
         ExpectedTypeError1(theEnv,"sort",1,"function name expecting two arguments");
         ReturnExpression(theEnv,functionReference);
         return;
        }
     }
   if (functionReference->type == 32)
     {
      dptr = (DEFFUNCTION *) functionReference->value;
      if ((dptr->minNumberOfParameters > 2) ||
          (dptr->maxNumberOfParameters == 0) ||
          (dptr->maxNumberOfParameters == 1))
        {
         ExpectedTypeError1(theEnv,"sort",1,"deffunction name expecting two arguments");
         ReturnExpression(theEnv,functionReference);
         return;
        }
     }
   if (argumentCount == 1)
     {
      EnvSetMultifieldErrorValue(theEnv,returnValue);
      ReturnExpression(theEnv,functionReference);
      return;
     }
   theArguments = (DATA_OBJECT *) genalloc(theEnv,(argumentCount - 1) * sizeof(DATA_OBJECT));
   for (i = 2; i <= argumentCount; i++)
     {
      EnvRtnUnknown(theEnv,i,&theArguments[i-2]);
      if (((theArguments[i-2]).type) == 4)
        { argumentSize += (((&theArguments[i-2])->end - (&theArguments[i-2])->begin) + 1); }
      else
        { argumentSize++; }
     }
   if (argumentSize == 0)
     {
      genfree(theEnv,theArguments,(argumentCount - 1) * sizeof(DATA_OBJECT));
      EnvSetMultifieldErrorValue(theEnv,returnValue);
      ReturnExpression(theEnv,functionReference);
      return;
     }
   theArguments2 = (DATA_OBJECT *) genalloc(theEnv,argumentSize * sizeof(DATA_OBJECT));
   for (i = 2; i <= argumentCount; i++)
     {
      if (((theArguments[i-2]).type) == 4)
        {
         tempMultifield = (struct multifield *) ((theArguments[i-2]).value);
         for (j = ((theArguments[i-2]).begin + 1); j <= ((theArguments[i-2]).end + 1); j++, k++)
           {
            ((theArguments2[k]).type = (unsigned short) ((((struct field *) ((struct multifield *) (tempMultifield))->theFields)[j-1].type)));
            ((theArguments2[k]).value = (void *) ((((struct field *) ((struct multifield *) (tempMultifield))->theFields)[j-1].value)));
           }
        }
      else
        {
         ((theArguments2[k]).type = (unsigned short) (((theArguments[i-2]).type)));
         ((theArguments2[k]).value = (void *) (((theArguments[i-2]).value)));
         k++;
        }
     }
   genfree(theEnv,theArguments,(argumentCount - 1) * sizeof(DATA_OBJECT));
   functionReference->nextArg = ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction;
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction = functionReference;
   for (i = 0; i < argumentSize; i++)
     { ValueInstall(theEnv,&theArguments2[i]); }
   MergeSort(theEnv,(unsigned long) argumentSize,theArguments2,DefaultCompareSwapFunction);
   for (i = 0; i < argumentSize; i++)
     { ValueDeinstall(theEnv,&theArguments2[i]); }
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction = ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->nextArg;
   functionReference->nextArg = ((void *)0);
   ReturnExpression(theEnv,functionReference);
   theMultifield = (struct multifield *) EnvCreateMultifield(theEnv,(unsigned long) argumentSize);
   for (i = 0; i < argumentSize; i++)
     {
      (((struct field *) ((struct multifield *) (theMultifield))->theFields)[i+1 -1].type = (unsigned short) (((theArguments2[i]).type)));
      (((struct field *) ((struct multifield *) (theMultifield))->theFields)[i+1 -1].value = (void *) (((theArguments2[i]).value)));
     }
   genfree(theEnv,theArguments2,argumentSize * sizeof(DATA_OBJECT));
   ((returnValue)->type = (unsigned short) (4));
   ((returnValue)->begin = (long) ((1) - 1));
   ((returnValue)->end = (long) ((argumentSize) - 1));
   ((returnValue)->value = (void *) ((void *) theMultifield));
  }

canonical_original_code:
void SortFunction(void *theEnv, struct dataObject *returnValue)
  {
   long argumentCount; long i; long j; long k = 0;
   struct dataObject *theArguments; struct dataObject *theArguments2;
   struct dataObject theArg;
   struct multifield *theMultifield; struct multifield *tempMultifield;
   char *functionName;
   struct expr *functionReference;
   int argumentSize = 0;
   struct FunctionDefinition *fptr;
   struct deffunctionStruct *dptr;
   ((returnValue)->type = (unsigned short) (2));
   ((returnValue)->value = (void *) (((struct symbolData *) (((struct environmentData *) theEnv)->theData[49]))->FalseSymbolHN));
   if ((argumentCount = EnvArgCountCheck(theEnv,"sort",1,1)) == -1)
     { return; }
   if (EnvArgTypeCheck(theEnv,"sort",1,2,&theArg) == 0)
     { return; }
   functionName = (((struct symbolHashNode *) (theArg.value))->contents);
   functionReference = FunctionReferenceExpression(theEnv,functionName);
   if (functionReference == ((void *)0))
     {
      ExpectedTypeError1(theEnv,"sort",1,"function name, deffunction name, or defgeneric name");
      return;
     }
   if (functionReference->type == 30)
     {
      fptr = (struct FunctionDefinition *) functionReference->value;
      if ((GetMinimumArgs(fptr) > 2) ||
          (GetMaximumArgs(fptr) == 0) ||
          (GetMaximumArgs(fptr) == 1))
        {
         ExpectedTypeError1(theEnv,"sort",1,"function name expecting two arguments");
         ReturnExpression(theEnv,functionReference);
         return;
        }
     }
   if (functionReference->type == 32)
     {
      dptr = (struct deffunctionStruct *) functionReference->value;
      if ((dptr->minNumberOfParameters > 2) ||
          (dptr->maxNumberOfParameters == 0) ||
          (dptr->maxNumberOfParameters == 1))
        {
         ExpectedTypeError1(theEnv,"sort",1,"deffunction name expecting two arguments");
         ReturnExpression(theEnv,functionReference);
         return;
        }
     }
   if (argumentCount == 1)
     {
      EnvSetMultifieldErrorValue(theEnv,returnValue);
      ReturnExpression(theEnv,functionReference);
      return;
     }
   theArguments = (struct dataObject *) genalloc(theEnv,(argumentCount - 1) * sizeof(DATA_OBJECT));
   for (i = 2; i <= argumentCount; i++)
     {
      EnvRtnUnknown(theEnv,i,&theArguments[i-2]);
      if (((theArguments[i-2]).type) == 4)
        { argumentSize += (((&theArguments[i-2])->end - (&theArguments[i-2])->begin) + 1); }
      else
        { argumentSize++; }
     }
   if (argumentSize == 0)
     {
      genfree(theEnv,theArguments,(argumentCount - 1) * sizeof(DATA_OBJECT));
      EnvSetMultifieldErrorValue(theEnv,returnValue);
      ReturnExpression(theEnv,functionReference);
      return;
     }
   theArguments2 = (struct dataObject *) genalloc(theEnv,argumentSize * sizeof(DATA_OBJECT));
   for (i = 2; i <= argumentCount; i++)
     {
      if (((theArguments[i-2]).type) == 4)
        {
         tempMultifield = (struct multifield *) ((theArguments[i-2]).value);
         for (j = ((theArguments[i-2]).begin + 1); j <= ((theArguments[i-2]).end + 1); j++, k++)
           {
            ((theArguments2[k]).type = (unsigned short) ((((struct field *) ((struct multifield *) (tempMultifield))->theFields)[j-1].type)));
            ((theArguments2[k]).value = (void *) ((((struct field *) ((struct multifield *) (tempMultifield))->theFields)[j-1].value)));
           }
        }
      else
        {
         ((theArguments2[k]).type = (unsigned short) (((theArguments[i-2]).type)));
         ((theArguments2[k]).value = (void *) (((theArguments[i-2]).value)));
         k++;
        }
     }
   genfree(theEnv,theArguments,(argumentCount - 1) * sizeof(DATA_OBJECT));
   functionReference->nextArg = ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction;
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction = functionReference;
   for (i = 0; i < argumentSize; i++)
     { ValueInstall(theEnv,&theArguments2[i]); }
   MergeSort(theEnv,(unsigned long) argumentSize,theArguments2,DefaultCompareSwapFunction);
   for (i = 0; i < argumentSize; i++)
     { ValueDeinstall(theEnv,&theArguments2[i]); }
   ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction = ((struct sortFunctionData *) (((struct environmentData *) theEnv)->theData[7]))->SortComparisonFunction->nextArg;
   functionReference->nextArg = ((void *)0);
   ReturnExpression(theEnv,functionReference);
   theMultifield = (struct multifield *) EnvCreateMultifield(theEnv,(unsigned long) argumentSize);
   for (i = 0; i < argumentSize; i++)
     {
      (((struct field *) ((struct multifield *) (theMultifield))->theFields)[i+1 -1].type = (unsigned short) (((theArguments2[i]).type)));
      (((struct field *) ((struct multifield *) (theMultifield))->theFields)[i+1 -1].value = (void *) (((theArguments2[i]).value)));
     }
   genfree(theEnv,theArguments2,argumentSize * sizeof(DATA_OBJECT));
   ((returnValue)->type = (unsigned short) (4));
   ((returnValue)->begin = (long) ((1) - 1));
   ((returnValue)->end = (long) ((argumentSize) - 1));
   ((returnValue)->value = (void *) ((void *) theMultifield));
  }

variable_types: argumentCount long

variable_types: i long

variable_types: j long

variable_types: k long

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

variable_types:
functionName
char *

variable_types: argumentSize int

variable_types: struct FunctionDefinition { struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *callFunctionName; char *actualFunctionName; char returnValueType; int (*functionPointer)(); struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *(*parser)(void *, struct expr *, char *); char *restrictions; short overloadable; short sequenceuseok; short environmentAware; short bsaveIndex; struct FunctionDefinition *next; struct userData { unsigned char dataID; struct userData *next; } *usrData; } *

variable_types: struct deffunctionStruct { 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; unsigned int busy; unsigned short trace; struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *code; int minNumberOfParameters; } *

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

user_defined_types: struct FunctionDefinition { struct symbolHashNode *callFunctionName; char *actualFunctionName; char returnValueType; int (*functionPointer)(); struct expr *(*parser)(void *, struct expr *, char *); char *restrictions; short overloadable; short sequenceuseok; short environmentAware; short bsaveIndex; struct FunctionDefinition *next; struct userData *usrData; }

user_defined_types: struct deffunctionStruct { struct constructHeader header; unsigned int busy; unsigned short trace; struct expr *code; int minNumberOfParameters; }

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 defmoduleItemHeader { struct defmodule *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; }

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