DeallocateDeffunctionBloadData

decompiled_code:
__int64 __fastcall DeallocateDeffunctionBloadData(__int64 a1)
{
_QWORD *v1; // rcx
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rdx

v1 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 192LL);
v2 = 88LL * v1[1];
if ( !v2 )
{
result = v1[2];
v4 = 24 * result;
if ( !(24 * result) )
return result;
return genlongfree(a1, v1[3], v4);
}
genlongfree(a1, *v1, v2);
v1 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 192LL);
result = v1[2];
v4 = 24 * result;
if ( 24 * result )
return genlongfree(a1, v1[3], v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_QWORD *v1; // rcx
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rdx

v1 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 192LL);
v2 = 88LL * v1[1];
if ( !v2 )
{
result = v1[2];
v4 = 24 * result;
if ( !(24 * result) )
return result;
return genlongfree(a1, v1[3], v4);
}
genlongfree(a1, *v1, v2);
v1 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 192LL);
result = v1[2];
v4 = 24 * result;
if ( 24 * result )
return genlongfree(a1, v1[3], v4);
return result;
}

original_code:
static void DeallocateDeffunctionBloadData(
  void *theEnv)
  {
   unsigned long space;
   space = ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionCount * sizeof(struct deffunctionStruct);
   if (space != 0) genlongfree(theEnv,(void *) ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionArray,space);
   space = ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleCount * sizeof(struct deffunctionModule);
   if (space != 0) genlongfree(theEnv,(void *) ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleArray,space);
  }

canonical_original_code:
static void DeallocateDeffunctionBloadData(void *theEnv)
  {
   unsigned long space;
   space = ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionCount * sizeof(struct deffunctionStruct);
   if (space != 0) genlongfree(theEnv,(void *) ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionArray,space);
   space = ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleCount * sizeof(struct deffunctionModule);
   if (space != 0) genlongfree(theEnv,(void *) ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleArray,space);
  }

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

user_defined_types: struct deffunctionModule { struct defmoduleItemHeader header; }

user_defined_types: struct deffunctionBinaryData { struct deffunctionStruct *DeffunctionArray; long DeffunctionCount; long ModuleCount; struct deffunctionModule *ModuleArray; }

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

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


BloadDeffunctions

repo: jarcec/rbclips

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

GenReadBinary(a1, v2, 8LL);
BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 192LL) + 16LL), 24LL, UpdateDeffunctionModule);
return BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 192LL) + 8LL), 56LL, UpdateDeffunction);
}

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

GenReadBinary(a1, v2, 8LL);
BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 192LL) + 16LL), 24LL, UpdateDeffunctionModule);
return BloadandRefresh(a1, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 192LL) + 8LL), 56LL, UpdateDeffunction);
}

original_code:
static void BloadDeffunctions(
  void *theEnv)
  {
   unsigned long space;
   GenReadBinary(theEnv,(void *) &space,(unsigned long) sizeof(unsigned long));
   BloadandRefresh(theEnv,((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleCount,sizeof(BSAVE_DEFFUNCTION_MODULE),UpdateDeffunctionModule);
   BloadandRefresh(theEnv,((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionCount,sizeof(BSAVE_DEFFUNCTION),UpdateDeffunction);
  }

canonical_original_code:
static void BloadDeffunctions(void *theEnv)
  {
   unsigned long space;
   GenReadBinary(theEnv,(void *) &space,(unsigned long) sizeof(unsigned long));
   BloadandRefresh(theEnv,((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleCount,sizeof(BSAVE_DEFFUNCTION_MODULE),UpdateDeffunctionModule);
   BloadandRefresh(theEnv,((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionCount,sizeof(BSAVE_DEFFUNCTION),UpdateDeffunction);
  }

variable_types:
theEnv
void *

variable_types:
space
unsigned long

return_type: void

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

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

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


UpdateDeffunctionModule

decompiled_code:
__int64 __fastcall UpdateDeffunctionModule(__int64 a1, __int64 a2, __int64 a3)
{
return UpdateDefmoduleItemHeader(
a1,
a2,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 192LL) + 24LL) + 24 * a3,
88LL,
**(_QWORD **)(*(_QWORD *)(a1 + 32) + 192LL));
}

original_code:
static void UpdateDeffunctionModule(
  void *theEnv,
  void *buf,
  long obji)
  {
   BSAVE_DEFFUNCTION_MODULE *bdptr;
   bdptr = (BSAVE_DEFFUNCTION_MODULE *) buf;
   UpdateDefmoduleItemHeader(theEnv,&bdptr->header,&((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleArray[obji].header,
                             (int) sizeof(DEFFUNCTION),(void *) ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionArray);
  }

canonical_original_code:
static void UpdateDeffunctionModule(void *theEnv, void *buf, long obji)
  {
   struct bsaveDeffunctionModule *bdptr;
   bdptr = (struct bsaveDeffunctionModule *) buf;
   UpdateDefmoduleItemHeader(theEnv,&bdptr->header,&((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleArray[obji].header,
                             (int) sizeof(DEFFUNCTION),(void *) ((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionArray);
  }

variable_types:
buf
void *

variable_types: obji long

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

user_defined_types: struct bsaveDeffunctionModule { struct bsaveDefmoduleItemHeader header; }


MarkDeffunctionItems

decompiled_code:
__int64 __fastcall MarkDeffunctionItems(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rsi

++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 192LL) + 8LL);
MarkConstructHeaderNeededItems(a2);
v2 = ExpressionSize(*(_QWORD *)(a2 + 64));
v3 = *(_QWORD *)(a2 + 64);
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 64LL) += v2;
return MarkNeededItems(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rsi

++*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 192LL) + 8LL);
MarkConstructHeaderNeededItems(a2);
v2 = ExpressionSize(*(_QWORD *)(a2 + 64));
v3 = *(_QWORD *)(a2 + 64);
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 360LL) + 64LL) += v2;
return MarkNeededItems(a1, v3);
}

original_code:
static void MarkDeffunctionItems(
  void *theEnv,
  struct constructHeader *theDeffunction,
  void *userBuffer)
  {
   MarkConstructHeaderNeededItems(theDeffunction,((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionCount++);
   ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount += ExpressionSize(((DEFFUNCTION *) theDeffunction)->code);
   MarkNeededItems(theEnv,((DEFFUNCTION *) theDeffunction)->code);
  }

canonical_original_code:
static void MarkDeffunctionItems(void *theEnv, struct constructHeader *theDeffunction, void *userBuffer)
  {
   MarkConstructHeaderNeededItems(theDeffunction,((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->DeffunctionCount++);
   ((struct expressionData *) (((struct environmentData *) theEnv)->theData[45]))->ExpressionCount += ExpressionSize(((struct deffunctionStruct *) theDeffunction)->code);
   MarkNeededItems(theEnv,((struct deffunctionStruct *) theDeffunction)->code);
  }

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:
userBuffer
void *

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

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

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


SetupDeffunctionsBload

decompiled_code:
__int64 __fastcall SetupDeffunctionsBload(__int64 a1)
{
AllocateEnvironmentData(a1, 24LL, 32LL, DeallocateDeffunctionBloadData);
return AddBinaryItem(
a1,
"deffunctions",
0LL,
BsaveDeffunctionFind,
BsaveDeffunctionExpressions,
BsaveStorageDeffunctions,
BsaveDeffunctions,
BloadStorageDeffunctions,
BloadDeffunctions,
ClearDeffunctionBload);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
AllocateEnvironmentData(a1, 24LL, 32LL, DeallocateDeffunctionBloadData);
return AddBinaryItem(
a1,
"deffunctions",
0LL,
BsaveDeffunctionFind,
BsaveDeffunctionExpressions,
BsaveStorageDeffunctions,
BsaveDeffunctions,
BloadStorageDeffunctions,
BloadDeffunctions,
ClearDeffunctionBload);
}

original_code:
void SetupDeffunctionsBload(
  void *theEnv)
  {
   AllocateEnvironmentData(theEnv,24,sizeof(struct deffunctionBinaryData),DeallocateDeffunctionBloadData);
   AddBinaryItem(theEnv,"deffunctions",0,BsaveDeffunctionFind,BsaveDeffunctionExpressions,
                             BsaveStorageDeffunctions,BsaveDeffunctions,
                             BloadStorageDeffunctions,BloadDeffunctions,
                             ClearDeffunctionBload);
  }

canonical_original_code:
void SetupDeffunctionsBload(void *theEnv)
  {
   AllocateEnvironmentData(theEnv,24,sizeof(struct deffunctionBinaryData),DeallocateDeffunctionBloadData);
   AddBinaryItem(theEnv,"deffunctions",0,BsaveDeffunctionFind,BsaveDeffunctionExpressions,
                             BsaveStorageDeffunctions,BsaveDeffunctions,
                             BloadStorageDeffunctions,BloadDeffunctions,
                             ClearDeffunctionBload);
  }


BloadDeffunctionModuleReference

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

original_code:
void *BloadDeffunctionModuleReference(
  void *theEnv,
  int theIndex)
  {
   return ((void *) &((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleArray[theIndex]);
  }

canonical_original_code:
void *BloadDeffunctionModuleReference(void *theEnv, int theIndex)
  {
   return ((void *) &((struct deffunctionBinaryData *) (((struct environmentData *) theEnv)->theData[24]))->ModuleArray[theIndex]);
  }

variable_types: theIndex int

return_type: void *


ParseDeffacts

decompiled_code:
__int64 __fastcall ParseDeffacts(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
__int64 *v7; // r14
__int64 v8; // rax
__int64 v9; // rax
__int64 v12; // [rsp-8h] [rbp-60h]
int v13; // [rsp+Ch] [rbp-4Ch] BYREF
char v14[72]; // [rsp+10h] [rbp-48h] BYREF

v13 = 0;
SetPPBufferStatus(a1, 1LL);
FlushPPBuffer(a1);
SetIndentDepth(a1, 3LL);
SavePPBuffer(a1, "(deffacts ");
if ( (unsigned int)Bloaded(a1) == 1 && !*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
{
CannotLoadWithBloadMessage(a1, "deffacts");
return 1LL;
}
v2 = GetConstructNameAndComment(a1, a2, v14, "deffacts", &EnvFindDeffacts, &EnvUndeffacts, "$", 1LL, 1LL, 1LL);
if ( !v2 )
return 1;
v3 = BuildRHSAssert(a1, a2, v14, &v13, 0LL, 0LL, "deffacts");
if ( v13 == 1 )
return 1;
if ( (unsigned int)ExpressionContainsVariables(v3, 0LL, v12) )
{
LocalVariableErrorMessage(a1, "a deffacts construct");
ReturnExpression(a1, v3);
return 1;
}
SavePPBuffer(a1, "\n");
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
{
ReturnExpression(a1, v3);
return 0;
}
ExpressionInstall(a1, v3);
v4 = *(_QWORD *)(a1 + 32);
v5 = *(_QWORD *)(v4 + 472);
v6 = *(_QWORD *)(*(_QWORD *)(v5 + 40) + 448LL);
if ( v6 )
{
*(_QWORD *)(v5 + 32) = v6;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 472) + 40LL) + 448LL) = **(_QWORD **)(*(_QWORD *)(v4 + 472) + 32LL);
v7 = *(__int64 **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 32LL);
}
else
{
v7 = (__int64 *)genalloc(a1, 56LL);
}
*v7 = v2;
++*(_QWORD *)(v2 + 8);
v7[6] = PackExpression(a1, v3);
v8 = FindModuleItem(a1, "deffacts");
v9 = GetModuleItem(a1, 0LL, *(unsigned int *)(v8 + 8));
v7[4] = 0LL;
v7[2] = v9;
v7[5] = 0LL;
ReturnExpression(a1, v3);
if ( (unsigned int)EnvGetConserveMemory(a1) == 1 )
v7[1] = 0LL;
else
v7[1] = CopyPPBuffer(a1);
AddConstructToModule(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
__int64 *v7; // r14
__int64 v8; // rax
__int64 v9; // rax
__int64 v12; // [rsp-8h] [rbp-60h]
int v13; // [rsp+Ch] [rbp-4Ch] BYREF
char v14[72]; // [rsp+10h] [rbp-48h] BYREF

v13 = 0;
SetPPBufferStatus(a1, 1LL);
FlushPPBuffer(a1);
SetIndentDepth(a1, 3LL);
SavePPBuffer(a1, "(deffacts ");
if ( (unsigned int)Bloaded(a1) == 1 && !*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
{
CannotLoadWithBloadMessage(a1, "deffacts");
return 1LL;
}
v2 = GetConstructNameAndComment(a1, a2, v14, "deffacts", &EnvFindDeffacts, &EnvUndeffacts, "$", 1LL, 1LL, 1LL);
if ( !v2 )
return 1;
v3 = BuildRHSAssert(a1, a2, v14, &v13, 0LL, 0LL, "deffacts");
if ( v13 == 1 )
return 1;
if ( (unsigned int)ExpressionContainsVariables(v3, 0LL, v12) )
{
LocalVariableErrorMessage(a1, "a deffacts construct");
ReturnExpression(a1, v3);
return 1;
}
SavePPBuffer(a1, "\n");
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 336LL) + 80LL) )
{
ReturnExpression(a1, v3);
return 0;
}
ExpressionInstall(a1, v3);
v4 = *(_QWORD *)(a1 + 32);
v5 = *(_QWORD *)(v4 + 472);
v6 = *(_QWORD *)(*(_QWORD *)(v5 + 40) + 448LL);
if ( v6 )
{
*(_QWORD *)(v5 + 32) = v6;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 472) + 40LL) + 448LL) = **(_QWORD **)(*(_QWORD *)(v4 + 472) + 32LL);
v7 = *(__int64 **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 472LL) + 32LL);
}
else
{
v7 = (__int64 *)genalloc(a1, 56LL);
}
*v7 = v2;
++*(_QWORD *)(v2 + 8);
v7[6] = PackExpression(a1, v3);
v8 = FindModuleItem(a1, "deffacts");
v9 = GetModuleItem(a1, 0LL, *(unsigned int *)(v8 + 8));
v7[4] = 0LL;
v7[2] = v9;
v7[5] = 0LL;
ReturnExpression(a1, v3);
if ( (unsigned int)EnvGetConserveMemory(a1) == 1 )
v7[1] = 0LL;
else
v7[1] = CopyPPBuffer(a1);
AddConstructToModule(v7);
return 0LL;
}

original_code:
int ParseDeffacts(
  void *theEnv,
  char *readSource)
  {
   SYMBOL_HN *deffactsName;
   struct expr *temp;
   struct deffacts *newDeffacts;
   int deffactsError;
   struct token inputToken;
   deffactsError = 0;
   SetPPBufferStatus(theEnv,1);
   FlushPPBuffer(theEnv);
   SetIndentDepth(theEnv,3);
   SavePPBuffer(theEnv,"(deffacts ");
   if ((Bloaded(theEnv) == 1) && (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode))
     {
      CannotLoadWithBloadMessage(theEnv,"deffacts");
      return(1);
     }
   deffactsName = GetConstructNameAndComment(theEnv,readSource,&inputToken,"deffacts",
                                             EnvFindDeffacts,EnvUndeffacts,"$",1,
                                             1,1);
   if (deffactsName == ((void *)0)) { return(1); }
   temp = BuildRHSAssert(theEnv,readSource,&inputToken,&deffactsError,0,0,"deffacts");
   if (deffactsError == 1) { return(1); }
   if (ExpressionContainsVariables(temp,0))
     {
      LocalVariableErrorMessage(theEnv,"a deffacts construct");
      ReturnExpression(theEnv,temp);
      return(1);
     }
   SavePPBuffer(theEnv,"\n");
   if (((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode)
     {
      ReturnExpression(theEnv,temp);
      return(0);
     }
   ExpressionInstall(theEnv,temp);
   newDeffacts = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] == ((void *)0)) ? ((struct deffacts *) genalloc(theEnv,(unsigned) sizeof(struct deffacts))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct deffacts *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
   newDeffacts->header.name = deffactsName;
   (((SYMBOL_HN *) deffactsName)->count++);
   newDeffacts->assertList = PackExpression(theEnv,temp);
   newDeffacts->header.whichModule = (struct defmoduleItemHeader *)
                              GetModuleItem(theEnv,((void *)0),FindModuleItem(theEnv,"deffacts")->moduleIndex);
   newDeffacts->header.next = ((void *)0);
   newDeffacts->header.usrData = ((void *)0);
   ReturnExpression(theEnv,temp);
   if (EnvGetConserveMemory(theEnv) == 1)
     { newDeffacts->header.ppForm = ((void *)0); }
   else
     { newDeffacts->header.ppForm = CopyPPBuffer(theEnv); }
   AddConstructToModule(&newDeffacts->header);
   return(0);
  }

canonical_original_code:
int ParseDeffacts(void *theEnv, char *readSource)
  {
   struct symbolHashNode *deffactsName;
   struct expr *temp;
   struct deffacts *newDeffacts;
   int deffactsError;
   struct token inputToken;
   deffactsError = 0;
   SetPPBufferStatus(theEnv,1);
   FlushPPBuffer(theEnv);
   SetIndentDepth(theEnv,3);
   SavePPBuffer(theEnv,"(deffacts ");
   if ((Bloaded(theEnv) == 1) && (! ((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode))
     {
      CannotLoadWithBloadMessage(theEnv,"deffacts");
      return(1);
     }
   deffactsName = GetConstructNameAndComment(theEnv,readSource,&inputToken,"deffacts",
                                             EnvFindDeffacts,EnvUndeffacts,"$",1,
                                             1,1);
   if (deffactsName == ((void *)0)) { return(1); }
   temp = BuildRHSAssert(theEnv,readSource,&inputToken,&deffactsError,0,0,"deffacts");
   if (deffactsError == 1) { return(1); }
   if (ExpressionContainsVariables(temp,0))
     {
      LocalVariableErrorMessage(theEnv,"a deffacts construct");
      ReturnExpression(theEnv,temp);
      return(1);
     }
   SavePPBuffer(theEnv,"\n");
   if (((struct constructData *) (((struct environmentData *) theEnv)->theData[42]))->CheckSyntaxMode)
     {
      ReturnExpression(theEnv,temp);
      return(0);
     }
   ExpressionInstall(theEnv,temp);
   newDeffacts = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] == ((void *)0)) ? ((struct deffacts *) genalloc(theEnv,(unsigned int) sizeof(struct deffacts))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct deffacts)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct deffacts *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
   newDeffacts->header.name = deffactsName;
   (((struct symbolHashNode *) deffactsName)->count++);
   newDeffacts->assertList = PackExpression(theEnv,temp);
   newDeffacts->header.whichModule = (struct defmoduleItemHeader *)
                              GetModuleItem(theEnv,((void *)0),FindModuleItem(theEnv,"deffacts")->moduleIndex);
   newDeffacts->header.next = ((void *)0);
   newDeffacts->header.usrData = ((void *)0);
   ReturnExpression(theEnv,temp);
   if (EnvGetConserveMemory(theEnv) == 1)
     { newDeffacts->header.ppForm = ((void *)0); }
   else
     { newDeffacts->header.ppForm = CopyPPBuffer(theEnv); }
   AddConstructToModule(&newDeffacts->header);
   return(0);
  }

variable_types:
readSource
char *

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

variable_types: deffactsError int

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

return_type: int

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

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


ReplaceTemplateNameWithReference

decompiled_code:
__int64 __fastcall ReplaceTemplateNameWithReference(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // r13
__int64 v5; // rax
int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = 1;
if ( *(_WORD *)a2 != 2 )
return v2;
v4 = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 24LL);
v5 = FindImportedConstruct(a1, "deftemplate", 0LL, v4, v6, 1LL, 0LL);
if ( !v5 )
{
v2 = 0;
CantFindItemErrorMessage(a1, "deftemplate", v4);
return v2;
}
if ( v6[0] > 1 )
{
v2 = 0;
AmbiguousReferenceErrorMessage(a1, "deftemplate", v4);
return v2;
}
*(_QWORD *)(a2 + 8) = v5;
result = 1LL;
*(_WORD *)a2 = 63;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // r13
__int64 v5; // rax
int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = 1;
if ( *(_WORD *)a2 != 2 )
return v2;
v4 = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 24LL);
v5 = FindImportedConstruct(a1, "deftemplate", 0LL, v4, v6, 1LL, 0LL);
if ( !v5 )
{
v2 = 0;
CantFindItemErrorMessage(a1, "deftemplate", v4);
return v2;
}
if ( v6[0] > 1 )
{
v2 = 0;
AmbiguousReferenceErrorMessage(a1, "deftemplate", v4);
return v2;
}
*(_QWORD *)(a2 + 8) = v5;
result = 1LL;
*(_WORD *)a2 = 63;
return result;
}

original_code:
static int ReplaceTemplateNameWithReference(
  void *theEnv,
  EXPRESSION *theExp)
  {
   char *theTemplateName;
   void *theDeftemplate;
   int count;
   if (theExp->type == 2)
     {
      theTemplateName = (((struct symbolHashNode *) (theExp->value))->contents);
      theDeftemplate = (struct deftemplate *)
                       FindImportedConstruct(theEnv,"deftemplate",((void *)0),theTemplateName,
                                             &count,1,((void *)0));
      if (theDeftemplate == ((void *)0))
        {
         CantFindItemErrorMessage(theEnv,"deftemplate",theTemplateName);
         return(0);
        }
      if (count > 1)
        {
         AmbiguousReferenceErrorMessage(theEnv,"deftemplate",theTemplateName);
         return(0);
        }
      theExp->type = 63;
      theExp->value = theDeftemplate;
     }
   return(1);
  }

canonical_original_code:
static int ReplaceTemplateNameWithReference(void *theEnv, struct expr *theExp)
  {
   char *theTemplateName;
   void *theDeftemplate;
   int count;
   if (theExp->type == 2)
     {
      theTemplateName = (((struct symbolHashNode *) (theExp->value))->contents);
      theDeftemplate = (struct deftemplate *)
                       FindImportedConstruct(theEnv,"deftemplate",((void *)0),theTemplateName,
                                             &count,1,((void *)0));
      if (theDeftemplate == ((void *)0))
        {
         CantFindItemErrorMessage(theEnv,"deftemplate",theTemplateName);
         return(0);
        }
      if (count > 1)
        {
         AmbiguousReferenceErrorMessage(theEnv,"deftemplate",theTemplateName);
         return(0);
        }
      theExp->type = 63;
      theExp->value = theDeftemplate;
     }
   return(1);
  }

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

variable_types:
theTemplateName
char *

variable_types:
theDeftemplate
void *

variable_types: count int

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

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


ReplaceSlotReference

decompiled_code:
int __fastcall ReplaceSlotReference(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
const char *v5; // rbp
size_t v6; // rax
size_t v7; // r15
int v8; // ebx
__int64 v9; // r14
const char *v10; // r13
unsigned int v11; // ebp
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rbx
__int64 v15; // rax
__int64 v16; // rsi
__int64 v17; // rdx
__int64 v18; // rbx
unsigned __int16 v23; // [rsp+30h] [rbp-58h] BYREF
__int64 v24; // [rsp+38h] [rbp-50h]

v5 = *(const char **)(*(_QWORD *)(a3 + 8) + 24LL);
LODWORD(v6) = strlen(v5);
if ( (unsigned int)v6 > 2 )
{
v7 = (unsigned int)(v6 - 2);
while ( 1 )
{
if ( v5[v7] == 58 )
{
LODWORD(v6) = a2;
v8 = 0;
v9 = a2;
if ( a2 )
break;
}
LABEL_3:
if ( !--v7 )
return v6;
}
while ( 1 )
{
v10 = *(const char **)(*(_QWORD *)(v9 + 8) + 24LL);
v6 = strlen(v10);
if ( v6 == v7 )
{
LODWORD(v6) = strncmp(v10, v5, v7);
if ( !(_DWORD)v6 )
break;
}
v9 = *(_QWORD *)(v9 + 24);
++v8;
if ( !v9 )
goto LABEL_3;
}
OpenStringSource(a1, "query-var", &v5[(unsigned int)(v7 + 1)], 0LL);
v11 = GetPPBufferStatus(a1);
SetPPBufferStatus(a1, 0LL);
GetToken(a1, "query-var", &v23);
SetPPBufferStatus(a1, v11);
CloseStringSource(a1, "query-var");
*(_WORD *)a3 = 30;
*(_QWORD *)(a3 + 8) = a4;
v12 = EnvAddLong(a1, a5);
*(_QWORD *)(a3 + 16) = GenConstant(a1, 1LL, v12);
v13 = EnvAddLong(a1, v8);
v14 = *(_QWORD *)(a3 + 16);
v15 = GenConstant(a1, 1LL, v13);
v16 = v23;
v17 = v24;
*(_QWORD *)(v14 + 24) = v15;
v18 = *(_QWORD *)(*(_QWORD *)(a3 + 16) + 24LL);
v6 = GenConstant(a1, v16, v17);
*(_QWORD *)(v18 + 24) = v6;
}
return v6;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
const char *v5; // rbp
size_t v6; // rax
size_t v7; // r15
int v8; // ebx
__int64 v9; // r14
const char *v10; // r13
unsigned int v11; // ebp
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rbx
__int64 v15; // rax
__int64 v16; // rsi
__int64 v17; // rdx
__int64 v18; // rbx
unsigned __int16 v23; // [rsp+30h] [rbp-58h] BYREF
__int64 v24; // [rsp+38h] [rbp-50h]

v5 = *(const char **)(*(_QWORD *)(a3 + 8) + 24LL);
LODWORD(v6) = strlen(v5);
if ( (unsigned int)v6 > 2 )
{
v7 = (unsigned int)(v6 - 2);
while ( 1 )
{
if ( v5[v7] == 58 )
{
LODWORD(v6) = a2;
v8 = 0;
v9 = a2;
if ( a2 )
break;
}
LABEL_3:
if ( !--v7 )
return v6;
}
while ( 1 )
{
v10 = *(const char **)(*(_QWORD *)(v9 + 8) + 24LL);
v6 = strlen(v10);
if ( v6 == v7 )
{
LODWORD(v6) = strncmp(v10, v5, v7);
if ( !(_DWORD)v6 )
break;
}
v9 = *(_QWORD *)(v9 + 24);
++v8;
if ( !v9 )
goto LABEL_3;
}
OpenStringSource(a1, "query-var", &v5[(unsigned int)(v7 + 1)], 0LL);
v11 = GetPPBufferStatus(a1);
SetPPBufferStatus(a1, 0LL);
GetToken(a1, "query-var", &v23);
SetPPBufferStatus(a1, v11);
CloseStringSource(a1, "query-var");
*(_WORD *)a3 = 30;
*(_QWORD *)(a3 + 8) = a4;
v12 = EnvAddLong(a1, a5);
*(_QWORD *)(a3 + 16) = GenConstant(a1, 1LL, v12);
v13 = EnvAddLong(a1, v8);
v14 = *(_QWORD *)(a3 + 16);
v15 = GenConstant(a1, 1LL, v13);
v16 = v23;
v17 = v24;
*(_QWORD *)(v14 + 24) = v15;
v18 = *(_QWORD *)(*(_QWORD *)(a3 + 16) + 24LL);
v6 = GenConstant(a1, v16, v17);
*(_QWORD *)(v18 + 24) = v6;
}
return v6;
}

original_code:
static void ReplaceSlotReference(
  void *theEnv,
  EXPRESSION *vlist,
  EXPRESSION *theExp,
  struct FunctionDefinition *func,
  int ndepth)
  {
   unsigned len;
   int posn,oldpp;
   register unsigned i;
   register char *str;
   EXPRESSION *eptr;
   struct token itkn;
   str = (((struct symbolHashNode *) (theExp->value))->contents);
   len = strlen(str);
   if (len < 3)
     return;
   for (i = len-2 ; i >= 1 ; i--)
     {
      if ((str[i] == ':') ? (i >= 1) : 0)
        {
         eptr = vlist;
         posn = 0;
         while (eptr && ((i != strlen((((struct symbolHashNode *) (eptr->value))->contents))) ||
                         strncmp((((struct symbolHashNode *) (eptr->value))->contents),str,
                                 (size_t) i)))
           {
            eptr = eptr->nextArg;
            posn++;
           }
         if (eptr != ((void *)0))
           {
            OpenStringSource(theEnv,"query-var",str+i+1,0);
            oldpp = GetPPBufferStatus(theEnv);
            SetPPBufferStatus(theEnv,0);
            GetToken(theEnv,"query-var",&itkn);
            SetPPBufferStatus(theEnv,oldpp);
            CloseStringSource(theEnv,"query-var");
            theExp->type = 30;
            theExp->value = (void *) func;
            theExp->argList = GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) ndepth));
            theExp->argList->nextArg =
              GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) posn));
            theExp->argList->nextArg->nextArg = GenConstant(theEnv,itkn.type,itkn.value);
            break;
           }
        }
     }
  }

canonical_original_code:
static void ReplaceSlotReference(void *theEnv, struct expr *vlist, struct expr *theExp, struct FunctionDefinition *func, int ndepth)
  {
   unsigned int len;
   int posn; int oldpp;
   register unsigned int i;
   register char *str;
   struct expr *eptr;
   struct token itkn;
   str = (((struct symbolHashNode *) (theExp->value))->contents);
   len = strlen(str);
   if (len < 3)
     return;
   for (i = len-2 ; i >= 1 ; i--)
     {
      if ((str[i] == ':') ? (i >= 1) : 0)
        {
         eptr = vlist;
         posn = 0;
         while (eptr && ((i != strlen((((struct symbolHashNode *) (eptr->value))->contents))) ||
                         strncmp((((struct symbolHashNode *) (eptr->value))->contents),str,
                                 (unsigned long) i)))
           {
            eptr = eptr->nextArg;
            posn++;
           }
         if (eptr != ((void *)0))
           {
            OpenStringSource(theEnv,"query-var",str+i+1,0);
            oldpp = GetPPBufferStatus(theEnv);
            SetPPBufferStatus(theEnv,0);
            GetToken(theEnv,"query-var",&itkn);
            SetPPBufferStatus(theEnv,oldpp);
            CloseStringSource(theEnv,"query-var");
            theExp->type = 30;
            theExp->value = (void *) func;
            theExp->argList = GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) ndepth));
            theExp->argList->nextArg =
              GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) posn));
            theExp->argList->nextArg->nextArg = GenConstant(theEnv,itkn.type,itkn.value);
            break;
           }
        }
     }
  }

variable_types:
theExp
struct expr *

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 *(*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: ndepth int

variable_types:
len
unsigned int

variable_types: posn int

variable_types: oldpp int

variable_types:
i
unsigned int

variable_types:
str
char *

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

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

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


ReplaceFactVariables

decompiled_code:
int __fastcall ReplaceFactVariables(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, int a5)
{
__int64 v8; // rax
__int64 v9; // r15
__int64 v10; // r8
int v11; // ecx
__int64 v12; // rax
__int64 v13; // rax
__int64 v15; // [rsp+8h] [rbp-50h]
__int64 v16; // [rsp+10h] [rbp-48h]
int v17; // [rsp+1Ch] [rbp-3Ch]

v15 = FindFunction(a1, "(query-fact)");
v16 = FindFunction(a1, "(query-fact-slot)");
LODWORD(v8) = a5 + 1;
while ( a3 )
{
if ( *(_WORD *)a3 == 35 )
{
if ( a2 )
{
v8 = a2;
v11 = 0;
while ( *(_QWORD *)(v8 + 8) != *(_QWORD *)(a3 + 8) )
{
v8 = *(_QWORD *)(v8 + 24);
++v11;
if ( !v8 )
goto LABEL_14;
}
v17 = v11;
*(_WORD *)a3 = 30;
*(_QWORD *)(a3 + 8) = v15;
v12 = EnvAddLong(a1, a5);
v9 = GenConstant(a1, 1LL, v12);
v13 = EnvAddLong(a1, v17);
*(_QWORD *)(v9 + 24) = GenConstant(a1, 1LL, v13);
*(_QWORD *)(a3 + 16) = v9;
LABEL_4:
if ( (unsigned int)IsQueryFunction(a3) )
v10 = (unsigned int)(a5 + 1);
LODWORD(v8) = ReplaceFactVariables(a1, a2, v9, a4, v10);
goto LABEL_7;
}
LABEL_14:
if ( a4 == 1 )
LODWORD(v8) = ReplaceSlotReference(a1, a2, a3, v16, a5);
}
v9 = *(_QWORD *)(a3 + 16);
if ( v9 )
goto LABEL_4;
LABEL_7:
a3 = *(_QWORD *)(a3 + 24);
}
return v8;
}

original_code:
static void ReplaceFactVariables(
  void *theEnv,
  EXPRESSION *vlist,
  EXPRESSION *bexp,
  int sdirect,
  int ndepth)
  {
   EXPRESSION *eptr;
   struct FunctionDefinition *rindx_func,*rslot_func;
   int posn;
   rindx_func = FindFunction(theEnv,"(query-fact)");
   rslot_func = FindFunction(theEnv,"(query-fact-slot)");
   while (bexp != ((void *)0))
     {
      if (bexp->type == 35)
        {
         eptr = vlist;
         posn = 0;
         while ((eptr != ((void *)0)) ? (eptr->value != bexp->value) : 0)
           {
            eptr = eptr->nextArg;
            posn++;
           }
         if (eptr != ((void *)0))
           {
            bexp->type = 30;
            bexp->value = (void *) rindx_func;
            eptr = GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) ndepth));
            eptr->nextArg = GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) posn));
            bexp->argList = eptr;
           }
         else if (sdirect == 1)
           { ReplaceSlotReference(theEnv,vlist,bexp,rslot_func,ndepth); }
        }
      if (bexp->argList != ((void *)0))
        {
         if (IsQueryFunction(bexp))
           { ReplaceFactVariables(theEnv,vlist,bexp->argList,sdirect,ndepth+1); }
         else
           { ReplaceFactVariables(theEnv,vlist,bexp->argList,sdirect,ndepth); }
        }
      bexp = bexp->nextArg;
     }
  }

canonical_original_code:
static void ReplaceFactVariables(void *theEnv, struct expr *vlist, struct expr *bexp, int sdirect, int ndepth)
  {
   struct expr *eptr;
   struct FunctionDefinition *rindx_func; struct FunctionDefinition *rslot_func;
   int posn;
   rindx_func = FindFunction(theEnv,"(query-fact)");
   rslot_func = FindFunction(theEnv,"(query-fact-slot)");
   while (bexp != ((void *)0))
     {
      if (bexp->type == 35)
        {
         eptr = vlist;
         posn = 0;
         while ((eptr != ((void *)0)) ? (eptr->value != bexp->value) : 0)
           {
            eptr = eptr->nextArg;
            posn++;
           }
         if (eptr != ((void *)0))
           {
            bexp->type = 30;
            bexp->value = (void *) rindx_func;
            eptr = GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) ndepth));
            eptr->nextArg = GenConstant(theEnv,1,(void *) EnvAddLong(theEnv,(long) posn));
            bexp->argList = eptr;
           }
         else if (sdirect == 1)
           { ReplaceSlotReference(theEnv,vlist,bexp,rslot_func,ndepth); }
        }
      if (bexp->argList != ((void *)0))
        {
         if (IsQueryFunction(bexp))
           { ReplaceFactVariables(theEnv,vlist,bexp->argList,sdirect,ndepth+1); }
         else
           { ReplaceFactVariables(theEnv,vlist,bexp->argList,sdirect,ndepth); }
        }
      bexp = bexp->nextArg;
     }
  }

variable_types:
theEnv
void *

variable_types:
bexp
struct expr *

variable_types: sdirect 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; } *


FactParseQueryNoAction

decompiled_code:
__int64 __fastcall FactParseQueryNoAction(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
__int64 v6; // rsi
__int64 v8; // rsi
__int16 v9[36]; // [rsp+0h] [rbp-48h] BYREF

v5 = ParseQueryRestrictions(a1, a2, a3, (__int64)v9);
if ( v5 )
{
IncrementIndentDepth(a1, 3LL);
PPCRAndIndent(a1);
if ( (unsigned int)ParseQueryTestExpression(a1, a2, a3) )
{
DecrementIndentDepth(a1, 3LL);
GetToken(a1, a3, v9);
if ( v9[0] == 171 )
{
ReplaceFactVariables(a1, v5, *(_QWORD *)(a2 + 16), 1u, 0);
v6 = v5;
v5 = a2;
}
else
{
SyntaxErrorMessage(a1, "fact-set query function");
ReturnExpression(a1, a2);
v6 = v5;
v5 = 0LL;
}
ReturnExpression(a1, v6);
}
else
{
DecrementIndentDepth(a1, 3LL);
v8 = v5;
v5 = 0LL;
ReturnExpression(a1, v8);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
__int64 v6; // rsi
__int64 v8; // rsi
__int16 v9[36]; // [rsp+0h] [rbp-48h] BYREF

v5 = func2(a1, a2, a3, (__int64)v9);
if ( v5 )
{
IncrementIndentDepth(a1, 3LL);
PPCRAndIndent(a1);
if ( (unsigned int)func3(a1, a2, a3) )
{
DecrementIndentDepth(a1, 3LL);
GetToken(a1, a3, v9);
if ( v9[0] == 171 )
{
func5(a1, v5, *(_QWORD *)(a2 + 16), 1u, 0);
v6 = v5;
v5 = a2;
}
else
{
SyntaxErrorMessage(a1, "fact-set query function");
ReturnExpression(a1, a2);
v6 = v5;
v5 = 0LL;
}
ReturnExpression(a1, v6);
}
else
{
DecrementIndentDepth(a1, 3LL);
v8 = v5;
v5 = 0LL;
ReturnExpression(a1, v8);
}
}
return v5;
}

original_code:
EXPRESSION *FactParseQueryNoAction(
  void *theEnv,
  EXPRESSION *top,
  char *readSource)
  {
   EXPRESSION *factQuerySetVars;
   struct token queryInputToken;
   factQuerySetVars = ParseQueryRestrictions(theEnv,top,readSource,&queryInputToken);
   if (factQuerySetVars == ((void *)0))
     { return(((void *)0)); }
   IncrementIndentDepth(theEnv,3);
   PPCRAndIndent(theEnv);
   if (ParseQueryTestExpression(theEnv,top,readSource) == 0)
     {
      DecrementIndentDepth(theEnv,3);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   DecrementIndentDepth(theEnv,3);
   GetToken(theEnv,readSource,&queryInputToken);
   if (((queryInputToken).type) != 171)
     {
      SyntaxErrorMessage(theEnv,"fact-set query function");
      ReturnExpression(theEnv,top);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   ReplaceFactVariables(theEnv,factQuerySetVars,top->argList,1,0);
   ReturnExpression(theEnv,factQuerySetVars);
   return(top);
  }

canonical_original_code:
struct expr *FactParseQueryNoAction(void *theEnv, struct expr *top, char *readSource)
  {
   struct expr *factQuerySetVars;
   struct token queryInputToken;
   factQuerySetVars = ParseQueryRestrictions(theEnv,top,readSource,&queryInputToken);
   if (factQuerySetVars == ((void *)0))
     { return(((void *)0)); }
   IncrementIndentDepth(theEnv,3);
   PPCRAndIndent(theEnv);
   if (ParseQueryTestExpression(theEnv,top,readSource) == 0)
     {
      DecrementIndentDepth(theEnv,3);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   DecrementIndentDepth(theEnv,3);
   GetToken(theEnv,readSource,&queryInputToken);
   if (((queryInputToken).type) != 171)
     {
      SyntaxErrorMessage(theEnv,"fact-set query function");
      ReturnExpression(theEnv,top);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   ReplaceFactVariables(theEnv,factQuerySetVars,top->argList,1,0);
   ReturnExpression(theEnv,factQuerySetVars);
   return(top);
  }

variable_types:
top
struct expr *

variable_types:
readSource
char *

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

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


FactParseQueryAction

decompiled_code:
__int64 __fastcall FactParseQueryAction(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
__int64 v6; // rsi
__int64 result; // rax
__int16 v8[36]; // [rsp+0h] [rbp-48h] BYREF

v5 = ParseQueryRestrictions(a1, a2, a3, (__int64)v8);
if ( !v5 )
return v5;
IncrementIndentDepth(a1, 3LL);
PPCRAndIndent(a1);
if ( (unsigned int)ParseQueryTestExpression(a1, a2, a3)
&& (PPCRAndIndent(a1), (unsigned int)ParseQueryActionExpression(a1, a2, a3, v5, (__int64)v8)) )
{
DecrementIndentDepth(a1, 3LL);
if ( v8[0] == 171 )
{
ReplaceFactVariables(a1, v5, *(_QWORD *)(a2 + 16), 1u, 0);
ReplaceFactVariables(a1, v5, *(_QWORD *)(*(_QWORD *)(a2 + 16) + 24LL), 0, 0);
v6 = v5;
v5 = a2;
ReturnExpression(a1, v6);
return v5;
}
SyntaxErrorMessage(a1, "fact-set query function");
ReturnExpression(a1, a2);
ReturnExpression(a1, v5);
result = 0LL;
}
else
{
DecrementIndentDepth(a1, 3LL);
ReturnExpression(a1, v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
__int64 v6; // rsi
__int64 result; // rax
__int16 v8[36]; // [rsp+0h] [rbp-48h] BYREF

v5 = func2(a1, a2, a3, (__int64)v8);
if ( !v5 )
return v5;
IncrementIndentDepth(a1, 3LL);
PPCRAndIndent(a1);
if ( (unsigned int)func3(a1, a2, a3)
&& (PPCRAndIndent(a1), (unsigned int)func6(a1, a2, a3, v5, (__int64)v8)) )
{
DecrementIndentDepth(a1, 3LL);
if ( v8[0] == 171 )
{
func5(a1, v5, *(_QWORD *)(a2 + 16), 1u, 0);
func5(a1, v5, *(_QWORD *)(*(_QWORD *)(a2 + 16) + 24LL), 0, 0);
v6 = v5;
v5 = a2;
ReturnExpression(a1, v6);
return v5;
}
SyntaxErrorMessage(a1, "fact-set query function");
ReturnExpression(a1, a2);
ReturnExpression(a1, v5);
result = 0LL;
}
else
{
DecrementIndentDepth(a1, 3LL);
ReturnExpression(a1, v5);
result = 0LL;
}
return result;
}

original_code:
EXPRESSION *FactParseQueryAction(
  void *theEnv,
  EXPRESSION *top,
  char *readSource)
  {
   EXPRESSION *factQuerySetVars;
   struct token queryInputToken;
   factQuerySetVars = ParseQueryRestrictions(theEnv,top,readSource,&queryInputToken);
   if (factQuerySetVars == ((void *)0))
     { return(((void *)0)); }
   IncrementIndentDepth(theEnv,3);
   PPCRAndIndent(theEnv);
   if (ParseQueryTestExpression(theEnv,top,readSource) == 0)
     {
      DecrementIndentDepth(theEnv,3);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   PPCRAndIndent(theEnv);
   if (ParseQueryActionExpression(theEnv,top,readSource,factQuerySetVars,&queryInputToken) == 0)
     {
      DecrementIndentDepth(theEnv,3);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   DecrementIndentDepth(theEnv,3);
   if (((queryInputToken).type) != 171)
     {
      SyntaxErrorMessage(theEnv,"fact-set query function");
      ReturnExpression(theEnv,top);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   ReplaceFactVariables(theEnv,factQuerySetVars,top->argList,1,0);
   ReplaceFactVariables(theEnv,factQuerySetVars,top->argList->nextArg,0,0);
   ReturnExpression(theEnv,factQuerySetVars);
   return(top);
  }

canonical_original_code:
struct expr *FactParseQueryAction(void *theEnv, struct expr *top, char *readSource)
  {
   struct expr *factQuerySetVars;
   struct token queryInputToken;
   factQuerySetVars = ParseQueryRestrictions(theEnv,top,readSource,&queryInputToken);
   if (factQuerySetVars == ((void *)0))
     { return(((void *)0)); }
   IncrementIndentDepth(theEnv,3);
   PPCRAndIndent(theEnv);
   if (ParseQueryTestExpression(theEnv,top,readSource) == 0)
     {
      DecrementIndentDepth(theEnv,3);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   PPCRAndIndent(theEnv);
   if (ParseQueryActionExpression(theEnv,top,readSource,factQuerySetVars,&queryInputToken) == 0)
     {
      DecrementIndentDepth(theEnv,3);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   DecrementIndentDepth(theEnv,3);
   if (((queryInputToken).type) != 171)
     {
      SyntaxErrorMessage(theEnv,"fact-set query function");
      ReturnExpression(theEnv,top);
      ReturnExpression(theEnv,factQuerySetVars);
      return(((void *)0));
     }
   ReplaceFactVariables(theEnv,factQuerySetVars,top->argList,1,0);
   ReplaceFactVariables(theEnv,factQuerySetVars,top->argList->nextArg,0,0);
   ReturnExpression(theEnv,factQuerySetVars);
   return(top);
  }

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


FindDefaultValue

decompiled_code:
__int64 __fastcall FindDefaultValue(__int64 a1, int a2, _QWORD *a3, __int64 a4)
{
unsigned __int16 *v4; // rax
__int64 result; // rax
__int64 v8; // rdx
__int64 v9; // rsi

v4 = (unsigned __int16 *)a3[2];
if ( v4 )
{
while ( *v4 != a2 )
{
v4 = (unsigned __int16 *)*((_QWORD *)v4 + 3);
if ( !v4 )
goto LABEL_6;
}
result = *((_QWORD *)v4 + 1);
}
else
{
LABEL_6:
if ( a2 != 1 )
{
if ( a2 )
return a4;
v8 = a3[3];
if ( *(_WORD *)v8 )
{
if ( *(_WORD *)v8 == 1 )
return EnvAddDouble(a1, (double)(int)*(_QWORD *)(*(_QWORD *)(v8 + 8) + 24LL));
v9 = a3[4];
if ( *(_WORD *)v9 )
{
result = a4;
if ( *(_WORD *)v9 == 1 )
result = EnvAddDouble(a1, (double)(int)*(_QWORD *)(*(_QWORD *)(v9 + 8) + 24LL));
return result;
}
return *(_QWORD *)(v9 + 8);
}
return *(_QWORD *)(v8 + 8);
}
v8 = a3[3];
if ( *(_WORD *)v8 == 1 )
return *(_QWORD *)(v8 + 8);
if ( !*(_WORD *)v8 )
return EnvAddLong(a1, (unsigned int)(int)*(double *)(*(_QWORD *)(v8 + 8) + 24LL));
v9 = a3[4];
if ( *(_WORD *)v9 == 1 )
return *(_QWORD *)(v9 + 8);
result = a4;
if ( !*(_WORD *)v9 )
result = EnvAddLong(a1, (unsigned int)(int)*(double *)(*(_QWORD *)(v9 + 8) + 24LL));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, _QWORD *a3, __int64 a4)
{
unsigned __int16 *v4; // rax
__int64 result; // rax
__int64 v8; // rdx
__int64 v9; // rsi

v4 = (unsigned __int16 *)a3[2];
if ( v4 )
{
while ( *v4 != a2 )
{
v4 = (unsigned __int16 *)*((_QWORD *)v4 + 3);
if ( !v4 )
goto LABEL_6;
}
result = *((_QWORD *)v4 + 1);
}
else
{
LABEL_6:
if ( a2 != 1 )
{
if ( a2 )
return a4;
v8 = a3[3];
if ( *(_WORD *)v8 )
{
if ( *(_WORD *)v8 == 1 )
return EnvAddDouble(a1, (double)(int)*(_QWORD *)(*(_QWORD *)(v8 + 8) + 24LL));
v9 = a3[4];
if ( *(_WORD *)v9 )
{
result = a4;
if ( *(_WORD *)v9 == 1 )
result = EnvAddDouble(a1, (double)(int)*(_QWORD *)(*(_QWORD *)(v9 + 8) + 24LL));
return result;
}
return *(_QWORD *)(v9 + 8);
}
return *(_QWORD *)(v8 + 8);
}
v8 = a3[3];
if ( *(_WORD *)v8 == 1 )
return *(_QWORD *)(v8 + 8);
if ( !*(_WORD *)v8 )
return EnvAddLong(a1, (unsigned int)(int)*(double *)(*(_QWORD *)(v8 + 8) + 24LL));
v9 = a3[4];
if ( *(_WORD *)v9 == 1 )
return *(_QWORD *)(v9 + 8);
result = a4;
if ( !*(_WORD *)v9 )
result = EnvAddLong(a1, (unsigned int)(int)*(double *)(*(_QWORD *)(v9 + 8) + 24LL));
}
return result;
}

original_code:
static void *FindDefaultValue(
  void *theEnv,
  int theType,
  CONSTRAINT_RECORD *theConstraints,
  void *standardDefault)
  {
   struct expr *theList;
   theList = theConstraints->restrictionList;
   while (theList != ((void *)0))
     {
      if (theList->type == theType) return(theList->value);
      theList = theList->nextArg;
     }
   if (theType == 1)
     {
      if (theConstraints->minValue->type == 1)
        { return(theConstraints->minValue->value); }
      else if (theConstraints->minValue->type == 0)
        { return(EnvAddLong(theEnv,(long) (((struct floatHashNode *) (theConstraints->minValue->value))->contents))); }
      else if (theConstraints->maxValue->type == 1)
        { return(theConstraints->maxValue->value); }
      else if (theConstraints->maxValue->type == 0)
        { return(EnvAddLong(theEnv,(long) (((struct floatHashNode *) (theConstraints->maxValue->value))->contents))); }
     }
   else if (theType == 0)
     {
      if (theConstraints->minValue->type == 0)
        { return(theConstraints->minValue->value); }
      else if (theConstraints->minValue->type == 1)
        { return(EnvAddDouble(theEnv,(double) (((struct integerHashNode *) (theConstraints->minValue->value))->contents))); }
      else if (theConstraints->maxValue->type == 0)
        { return(theConstraints->maxValue->value); }
      else if (theConstraints->maxValue->type == 1)
        { return(EnvAddDouble(theEnv,(double) (((struct integerHashNode *) (theConstraints->maxValue->value))->contents))); }
     }
   return(standardDefault);
  }

canonical_original_code:
static void *FindDefaultValue(void *theEnv, int theType, struct constraintRecord *theConstraints, void *standardDefault)
  {
   struct expr *theList;
   theList = theConstraints->restrictionList;
   while (theList != ((void *)0))
     {
      if (theList->type == theType) return(theList->value);
      theList = theList->nextArg;
     }
   if (theType == 1)
     {
      if (theConstraints->minValue->type == 1)
        { return(theConstraints->minValue->value); }
      else if (theConstraints->minValue->type == 0)
        { return(EnvAddLong(theEnv,(long) (((struct floatHashNode *) (theConstraints->minValue->value))->contents))); }
      else if (theConstraints->maxValue->type == 1)
        { return(theConstraints->maxValue->value); }
      else if (theConstraints->maxValue->type == 0)
        { return(EnvAddLong(theEnv,(long) (((struct floatHashNode *) (theConstraints->maxValue->value))->contents))); }
     }
   else if (theType == 0)
     {
      if (theConstraints->minValue->type == 0)
        { return(theConstraints->minValue->value); }
      else if (theConstraints->minValue->type == 1)
        { return(EnvAddDouble(theEnv,(double) (((struct integerHashNode *) (theConstraints->minValue->value))->contents))); }
      else if (theConstraints->maxValue->type == 0)
        { return(theConstraints->maxValue->value); }
      else if (theConstraints->maxValue->type == 1)
        { return(EnvAddDouble(theEnv,(double) (((struct integerHashNode *) (theConstraints->maxValue->value))->contents))); }
     }
   return(standardDefault);
  }

variable_types: theType int

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

variable_types:
standardDefault
void *

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


DestroyDefruleAction

decompiled_code:
// attributes: thunk
__int64 __fastcall DestroyDefruleAction()
{
return DestroyDefrule();
}

canonical_decompiled_code:
__int64 __fastcall func1()
{
return DestroyDefrule();
}

original_code:
static void DestroyDefruleAction(
  void *theEnv,
  struct constructHeader *theConstruct,
  void *buffer)
  {
   struct defrule *theDefrule = (struct defrule *) theConstruct;
   DestroyDefrule(theEnv,theDefrule);
  }

canonical_original_code:
static void DestroyDefruleAction(void *theEnv, struct constructHeader *theConstruct, void *buffer)
  {
   struct defrule *theDefrule = (struct defrule *) theConstruct;
   DestroyDefrule(theEnv,theDefrule);
  }

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

variable_types:
buffer
void *

variable_types: struct defrule { struct constructHeader { struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *name; char *ppForm; struct defmoduleItemHeader { struct defmodule { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader **itemsArray; struct portItem { struct symbolHashNode *moduleName; struct symbolHashNode *constructType; struct symbolHashNode *constructName; struct portItem *next; } *importList; struct portItem *exportList; unsigned int visitedFlag; long bsaveID; struct userData { 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; int salience; int localVarCnt; unsigned int complexity; unsigned int afterBreakpoint; unsigned int watchActivation; unsigned int watchFiring; unsigned int autoFocus; unsigned int executing; struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *dynamicSalience; struct expr *actions; 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 { 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]; } *beta; struct expr *networkTest; void *rightSideEntryStructure; struct joinNode *nextLevel; struct joinNode *lastLevel; struct joinNode *rightDriveNode; struct joinNode *rightMatchNode; struct defrule *ruleToActivate; } *logicalJoin; struct joinNode *lastJoin; struct defrule *disjunct; } *

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

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


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


EnvIsDefruleDeletable

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

result = ConstructsDeletable();
if ( (_DWORD)result )
{
while ( 1 )
{
if ( !a2 )
return *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 144LL) + 76LL) == 0;
if ( *(char *)(a2 + 57) < 0 )
break;
a2 = *(_QWORD *)(a2 + 96);
}
result = 0LL;
}
return result;
}

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

result = ConstructsDeletable();
if ( (_DWORD)result )
{
while ( 1 )
{
if ( !a2 )
return *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 144LL) + 76LL) == 0;
if ( *(char *)(a2 + 57) < 0 )
break;
a2 = *(_QWORD *)(a2 + 96);
}
result = 0LL;
}
return result;
}

original_code:
int EnvIsDefruleDeletable(
  void *theEnv,
  void *vTheDefrule)
  {
   struct defrule *theDefrule;
   if (! ConstructsDeletable(theEnv))
     { return 0; }
   for (theDefrule = (struct defrule *) vTheDefrule;
        theDefrule != ((void *)0);
        theDefrule = theDefrule->disjunct)
     { if (theDefrule->executing) return(0); }
   if (((struct engineData *) (((struct environmentData *) theEnv)->theData[18]))->JoinOperationInProgress) return(0);
   return(1);
  }

canonical_original_code:
int EnvIsDefruleDeletable(void *theEnv, void *vTheDefrule)
  {
   struct defrule *theDefrule;
   if (! ConstructsDeletable(theEnv))
     { return 0; }
   for (theDefrule = (struct defrule *) vTheDefrule;
        theDefrule != ((void *)0);
        theDefrule = theDefrule->disjunct)
     { if (theDefrule->executing) return(0); }
   if (((struct engineData *) (((struct environmentData *) theEnv)->theData[18]))->JoinOperationInProgress) return(0);
   return(1);
  }

variable_types:
vTheDefrule
void *

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 engineData { struct defrule *ExecutingRule; int HaltRules; struct joinNode *TheLogicalJoin; struct dependency *UnsupportedDataEntities; int alreadyEntered; struct callFunctionItem *ListOfRunFunctions; struct focus *CurrentFocus; int FocusChanged; unsigned int WatchStatistics; unsigned int WatchFocus; int IncrementalResetInProgress; int IncrementalResetFlag; int JoinOperationInProgress; struct partialMatch *GlobalLHSBinds; struct partialMatch *GlobalRHSBinds; struct joinNode *GlobalJoin; struct rdriveinfo *DriveRetractionList; struct partialMatch *GarbagePartialMatches; struct alphaMatch *GarbageAlphaMatches; int AlreadyRunning; }

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

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

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 dependency { void *dPtr; struct dependency *next; }

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

user_defined_types: struct focus { struct defmodule *theModule; struct defruleModule *theDefruleModule; struct focus *next; }

user_defined_types: struct rdriveinfo { struct partialMatch *link; struct joinNode *jlist; struct rdriveinfo *next; }

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

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 defruleModule { struct defmoduleItemHeader header; struct activation *agenda; }

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

user_defined_types: struct activation { struct defrule *theRule; struct partialMatch *basis; int salience; unsigned long timetag; struct partialMatch *sortedBasis; int randomID; struct activation *prev; struct activation *next; }

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

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


JoinNetErrorMessage

decompiled_code:
__int64 __fastcall JoinNetErrorMessage(__int64 a1, __int64 a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

PrintErrorID(a1, "DRIVE", 1LL, 1LL);
EnvPrintRouter(a1, "werror", "This error occurred in the join network\n");
sprintf(v3, " Problem resides in join #%d in rule(s):\n", *(_BYTE *)(a2 + 1) >> 1);
EnvPrintRouter(a1, "werror", v3);
TraceErrorToRule(a1, a2, " ");
return EnvPrintRouter(a1, "werror", "\n");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

PrintErrorID(a1, "DRIVE", 1LL, 1LL);
EnvPrintRouter(a1, "werror", "This error occurred in the join network\n");
sprintf(v3, " Problem resides in join #%d in rule(s):\n", *(_BYTE *)(a2 + 1) >> 1);
EnvPrintRouter(a1, "werror", v3);
TraceErrorToRule(a1, a2, " ");
return EnvPrintRouter(a1, "werror", "\n");
}

original_code:
static void JoinNetErrorMessage(
  void *theEnv,
  struct joinNode *joinPtr)
  {
   char buffer[60];
   PrintErrorID(theEnv,"DRIVE",1,1);
   EnvPrintRouter(theEnv,"werror","This error occurred in the join network\n");
   sprintf(buffer,"   Problem resides in join #%d in rule(s):\n",joinPtr->depth);
   EnvPrintRouter(theEnv,"werror",buffer);
   TraceErrorToRule(theEnv,joinPtr,"      ");
   EnvPrintRouter(theEnv,"werror","\n");
  }

canonical_original_code:
static void JoinNetErrorMessage(void *theEnv, struct joinNode *joinPtr)
  {
   char buffer[60];
   PrintErrorID(theEnv,"DRIVE",1,1);
   EnvPrintRouter(theEnv,"werror","This error occurred in the join network\n");
   sprintf(buffer,"   Problem resides in join #%d in rule(s):\n",joinPtr->depth);
   EnvPrintRouter(theEnv,"werror",buffer);
   TraceErrorToRule(theEnv,joinPtr,"      ");
   EnvPrintRouter(theEnv,"werror","\n");
  }

variable_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 { unsigned int betaMemory; unsigned int busy; unsigned int activationf; unsigned int dependentsf; unsigned int notOriginf; unsigned int counterf; unsigned int bcount; struct partialMatch *next; struct genericMatch { union { void *theValue; struct alphaMatch { struct patternEntity { struct patternEntityRecord { struct entityRecord { char *name; unsigned int type; unsigned int copyToEvaluate; unsigned int bitMap; unsigned int addsToRuleComplexity; void (*shortPrintFunction)(void *, char *, void *); void (*longPrintFunction)(void *, char *, void *); int (*deleteFunction)(void *, void *); int (*evaluateFunction)(void *, void *, struct dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; } *); void *(*getNextFunction)(void *, void *); void (*decrementBusyCount)(void *, void *); void (*incrementBusyCount)(void *, void *); void (*propagateDepth)(void *, void *); void (*markNeeded)(void *, void *); void (*install)(void *, void *); void (*deinstall)(void *, void *); struct userData { unsigned char dataID; struct userData *next; } *usrData; } base; void (*decrementBasisCount)(void *, void *); void (*incrementBasisCount)(void *, void *); void (*matchFunction)(void *, void *); int (*synchronized)(void *, void *); } *theInfo; void *dependents; unsigned int busyCount; long timeTag; } *matchingItem; struct multifieldMarker { int whichField; union { void *whichSlot; short whichSlotNumber; } where; long startPosition; long endPosition; struct multifieldMarker *next; } *markers; struct alphaMatch *next; } *theMatch; } gm; } binds[1]; } *beta; struct expr { unsigned short type; void *value; struct expr *argList; struct expr *nextArg; } *networkTest; void *rightSideEntryStructure; struct joinNode *nextLevel; struct joinNode *lastLevel; struct joinNode *rightDriveNode; struct joinNode *rightMatchNode; struct defrule { struct constructHeader { struct symbolHashNode { struct symbolHashNode *next; long count; int depth; unsigned int permanent; unsigned int markedEphemeral; unsigned int neededSymbol; unsigned int bucket; char *contents; } *name; char *ppForm; struct defmoduleItemHeader { struct defmodule { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader **itemsArray; struct portItem { struct symbolHashNode *moduleName; struct symbolHashNode *constructType; struct symbolHashNode *constructName; struct portItem *next; } *importList; struct portItem *exportList; unsigned int visitedFlag; long bsaveID; struct userData *usrData; struct defmodule *next; } *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; } *whichModule; long bsaveID; struct constructHeader *next; struct userData *usrData; } header; int salience; int localVarCnt; unsigned int complexity; unsigned int afterBreakpoint; unsigned int watchActivation; unsigned int watchFiring; unsigned int autoFocus; unsigned int executing; struct expr *dynamicSalience; struct expr *actions; struct joinNode *logicalJoin; struct joinNode *lastJoin; struct defrule *disjunct; } *ruleToActivate; } *

variable_types:
buffer
char [60]

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 defrule { struct constructHeader header; int salience; int localVarCnt; unsigned int complexity; unsigned int afterBreakpoint; unsigned int watchActivation; unsigned int watchFiring; unsigned int autoFocus; unsigned int executing; struct expr *dynamicSalience; struct expr *actions; struct joinNode *logicalJoin; struct joinNode *lastJoin; struct defrule *disjunct; }

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


PNLDrive

original_code:
void PNLDrive(
  void *theEnv,
  struct joinNode *join,
  struct partialMatch *binds)
  {
   struct joinNode *listOfJoins;
   struct alphaMatch *tempAlpha;
    tempAlpha = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct alphaMatch)] == ((void *)0)) ? ((struct alphaMatch *) genalloc(theEnv,(unsigned) sizeof(struct alphaMatch))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct alphaMatch)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct alphaMatch)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct alphaMatch *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
    tempAlpha->next = ((void *)0);
    tempAlpha->matchingItem = ((void *)0);
    tempAlpha->markers = ((void *)0);
    binds->counterf = 0;
    binds->binds[binds->bcount - 1].gm.theMatch = tempAlpha;
   if (join->ruleToActivate != ((void *)0)) AddActivation(theEnv,join->ruleToActivate,binds);
    listOfJoins = join->nextLevel;
    if (listOfJoins != ((void *)0))
      {
       if (((struct joinNode *) (listOfJoins->rightSideEntryStructure)) == join)
         { NetworkAssert(theEnv,binds,listOfJoins,1); }
       else while (listOfJoins != ((void *)0))
         {
          NetworkAssert(theEnv,binds,listOfJoins,0);
          listOfJoins = listOfJoins->rightDriveNode;
         }
      }
   }

canonical_original_code:
void PNLDrive(void *theEnv, struct joinNode *join, struct partialMatch *binds)
  {
   struct joinNode *listOfJoins;
   struct alphaMatch *tempAlpha;
    tempAlpha = ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct alphaMatch)] == ((void *)0)) ? ((struct alphaMatch *) genalloc(theEnv,(unsigned int) sizeof(struct alphaMatch))) : ((((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct alphaMatch)]), ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->MemoryTable[sizeof(struct alphaMatch)] = ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr->next, ((struct alphaMatch *) ((struct memoryData *) (((struct environmentData *) theEnv)->theData[59]))->TempMemoryPtr)));
    tempAlpha->next = ((void *)0);
    tempAlpha->matchingItem = ((void *)0);
    tempAlpha->markers = ((void *)0);
    binds->counterf = 0;
    binds->binds[binds->bcount - 1].gm.theMatch = tempAlpha;
   if (join->ruleToActivate != ((void *)0)) AddActivation(theEnv,join->ruleToActivate,binds);
    listOfJoins = join->nextLevel;
    if (listOfJoins != ((void *)0))
      {
       if (((struct joinNode *) (listOfJoins->rightSideEntryStructure)) == join)
         { NetworkAssert(theEnv,binds,listOfJoins,1); }
       else while (listOfJoins != ((void *)0))
         {
          NetworkAssert(theEnv,binds,listOfJoins,0);
          listOfJoins = listOfJoins->rightDriveNode;
         }
      }
   }

variable_types:
theEnv
void *

variable_types:
binds
struct partialMatch *

variable_types: struct alphaMatch { struct patternEntity { struct patternEntityRecord { struct entityRecord { char *name; unsigned int type; unsigned int copyToEvaluate; unsigned int bitMap; unsigned int addsToRuleComplexity; void (*shortPrintFunction)(void *, char *, void *); void (*longPrintFunction)(void *, char *, void *); int (*deleteFunction)(void *, void *); int (*evaluateFunction)(void *, void *, struct dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; } *); void *(*getNextFunction)(void *, void *); void (*decrementBusyCount)(void *, void *); void (*incrementBusyCount)(void *, void *); void (*propagateDepth)(void *, void *); void (*markNeeded)(void *, void *); void (*install)(void *, void *); void (*deinstall)(void *, void *); struct userData { unsigned char dataID; struct userData *next; } *usrData; } base; void (*decrementBasisCount)(void *, void *); void (*incrementBasisCount)(void *, void *); void (*matchFunction)(void *, void *); int (*synchronized)(void *, void *); } *theInfo; void *dependents; unsigned int busyCount; long timeTag; } *matchingItem; struct multifieldMarker { int whichField; union { void *whichSlot; short whichSlotNumber; } where; long startPosition; long endPosition; struct multifieldMarker *next; } *markers; struct alphaMatch *next; } *

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

user_defined_types: struct memoryPtr { struct memoryPtr *next; }

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

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