SavePPBuffer

original_code:
void SavePPBuffer(
  void *theEnv,
  char *str)
  {
   long int longSize;
   int normalSize;
   int increment;
   if ((((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferStatus == 0) || (! ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled))
     { return; }
   increment = 512;
   if (((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos > increment)
     {
      increment = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos * 3;
      if (increment < 0)
        { increment = 512; }
     }
   normalSize = (int) strlen(str);
   longSize = (long) normalSize;
   longSize += (long) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos + ((long) increment) + 1L;
   normalSize += ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos + increment + 1;
   if (normalSize != longSize) return;
   if ((int) strlen(str) + ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos + 1 >= (int) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax)
     {
      ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer = (char *) genrealloc(theEnv,((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer,(unsigned) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax,
                                     (unsigned) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax + increment);
      ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax += (unsigned int) increment;
     }
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBackupTwice = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBackupOnce;
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBackupOnce = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos;
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer = AppendToString(theEnv,str,((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer,&((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos,&((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax);
  }

canonical_original_code:
void SavePPBuffer(void *theEnv, char *str)
  {
   long longSize;
   int normalSize;
   int increment;
   if ((((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferStatus == 0) || (! ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled))
     { return; }
   increment = 512;
   if (((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos > increment)
     {
      increment = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos * 3;
      if (increment < 0)
        { increment = 512; }
     }
   normalSize = (int) strlen(str);
   longSize = (long) normalSize;
   longSize += (long) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos + ((long) increment) + 1L;
   normalSize += ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos + increment + 1;
   if (normalSize != longSize) return;
   if ((int) strlen(str) + ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos + 1 >= (int) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax)
     {
      ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer = (char *) genrealloc(theEnv,((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer,(unsigned int) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax,
                                     (unsigned int) ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax + increment);
      ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax += (unsigned int) increment;
     }
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBackupTwice = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBackupOnce;
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBackupOnce = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos;
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer = AppendToString(theEnv,str,((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer,&((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferPos,&((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferMax);
  }

variable_types:
str
char *

variable_types: longSize long

variable_types: normalSize int

variable_types: increment int


CopyPPBuffer

repo: jarcec/rbclips

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

v1 = strlen(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL) + 32LL));
v2 = (char *)gm2(a1, (unsigned int)(v1 + 1));
return strcpy(v2, *(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL) + 32LL));
}

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

v1 = strlen(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL) + 32LL));
v2 = (char *)gm2(a1, (unsigned int)(v1 + 1));
return strcpy(v2, *(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL) + 32LL));
}

original_code:
char *CopyPPBuffer(
  void *theEnv)
  {
   unsigned length;
   char *newString;
   length = (1 + strlen(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer)) * (int) sizeof (char);
   newString = (char *) gm2(theEnv,length);
   strcpy(newString,((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer);
   return(newString);
  }

canonical_original_code:
char *CopyPPBuffer(void *theEnv)
  {
   unsigned int length;
   char *newString;
   length = (1 + strlen(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer)) * (int) sizeof (char);
   newString = (char *) gm2(theEnv,length);
   strcpy(newString,((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer);
   return(newString);
  }

variable_types:
theEnv
void *

variable_types:
length
unsigned int

variable_types:
newString
char *

return_type: char *

user_defined_types: struct prettyPrintData { int PPBufferStatus; int PPBufferEnabled; int IndentationDepth; int PPBufferPos; unsigned int PPBufferMax; int PPBackupOnce; int PPBackupTwice; char *PrettyPrintBuffer; }

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


GetPPBuffer

decompiled_code:
__int64 __fastcall GetPPBuffer(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL) + 32LL);
}

original_code:
char *GetPPBuffer(
  void *theEnv)
  {
   return(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer);
  }

canonical_original_code:
char *GetPPBuffer(void *theEnv)
  {
   return(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PrettyPrintBuffer);
  }


PPCRAndIndent

decompiled_code:
__int64 __fastcall PPCRAndIndent(__int64 a1)
{
__int64 result; // rax
_DWORD *v2; // rcx
int v3; // eax
char *v4; // rdx
int v5; // eax
char v6; // [rsp+0h] [rbp-88h] BYREF
char v7; // [rsp+1h] [rbp-87h] BYREF

result = *(_QWORD *)(a1 + 32);
v2 = *(_DWORD **)(result + 416);
if ( *v2 && v2[1] )
{
v3 = v2[2];
v6 = 10;
if ( v3 <= 0 )
{
v5 = 1;
}
else
{
v4 = &v7;
v5 = 1;
do
{
*v4 = 32;
++v5;
++v4;
}
while ( v2[2] >= v5 );
}
*(&v6 + v5) = 0;
result = SavePPBuffer(a1, &v6);
}
return result;
}

original_code:
void PPCRAndIndent(
  void *theEnv)
  {
   int i;
   char buffer[120];
   if ((((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferStatus == 0) ||
       (! ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled))
     { return; }
   buffer[0] = '\n';
   for (i = 1 ; i <= ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth ; i++)
     { buffer[i] = ' '; }
   buffer[i] = '\0';
   SavePPBuffer(theEnv,buffer);
  }

canonical_original_code:
void PPCRAndIndent(void *theEnv)
  {
   int i;
   char buffer[120];
   if ((((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferStatus == 0) ||
       (! ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled))
     { return; }
   buffer[0] = '\n';
   for (i = 1 ; i <= ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth ; i++)
     { buffer[i] = ' '; }
   buffer[i] = '\0';
   SavePPBuffer(theEnv,buffer);
  }

variable_types: i int

variable_types:
buffer
char [120]

return_type: void


IncrementIndentDepth

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL);
*(_DWORD *)(result + 8) += a2;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL);
*(_DWORD *)(result + 8) += a2;
return result;
}

original_code:
void IncrementIndentDepth(
  void *theEnv,
  int value)
  {
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth += value;
  }

canonical_original_code:
void IncrementIndentDepth(void *theEnv, int value)
  {
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth += value;
  }

variable_types: value int


DecrementIndentDepth

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL);
*(_DWORD *)(result + 8) -= a2;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL);
*(_DWORD *)(result + 8) -= a2;
return result;
}

original_code:
void DecrementIndentDepth(
  void *theEnv,
  int value)
  {
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth -= value;
  }

canonical_original_code:
void DecrementIndentDepth(void *theEnv, int value)
  {
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth -= value;
  }


SetIndentDepth

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL);
*(_DWORD *)(result + 8) = a2;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL);
*(_DWORD *)(result + 8) = a2;
return result;
}

original_code:
void SetIndentDepth(
  void *theEnv,
  int value)
  {
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth = value;
  }

canonical_original_code:
void SetIndentDepth(void *theEnv, int value)
  {
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->IndentationDepth = value;
  }


GetPPBufferStatus

decompiled_code:
__int64 __fastcall GetPPBufferStatus(__int64 a1)
{
return **(unsigned int **)(*(_QWORD *)(a1 + 32) + 416LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return **(unsigned int **)(*(_QWORD *)(a1 + 32) + 416LL);
}

original_code:
int GetPPBufferStatus(
  void *theEnv)
  {
   return(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferStatus);
  }

canonical_original_code:
int GetPPBufferStatus(void *theEnv)
  {
   return(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferStatus);
  }

return_type: int


SetPPBufferEnabled

decompiled_code:
__int64 __fastcall SetPPBufferEnabled(__int64 a1, int a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL);
v3 = *(_DWORD *)(v2 + 4);
*(_DWORD *)(v2 + 4) = a2;
return v3;
}

original_code:
int SetPPBufferEnabled(
  void *theEnv,
  int value)
  {
   int oldValue;
   oldValue = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled;
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled = value;
   return(oldValue);
  }

canonical_original_code:
int SetPPBufferEnabled(void *theEnv, int value)
  {
   int oldValue;
   oldValue = ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled;
   ((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled = value;
   return(oldValue);
  }

variable_types: oldValue int


GetPPBufferEnabled

decompiled_code:
__int64 __fastcall GetPPBufferEnabled(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL) + 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 416LL) + 4LL);
}

original_code:
int GetPPBufferEnabled(
  void *theEnv)
  {
   return(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled);
  }

canonical_original_code:
int GetPPBufferEnabled(void *theEnv)
  {
   return(((struct prettyPrintData *) (((struct environmentData *) theEnv)->theData[52]))->PPBufferEnabled);
  }


DefruleCommands

decompiled_code:
__int64 __fastcall DefruleCommands(__int64 a1)
{
EnvDefineFunction2(a1, "run", 118LL, &RunCommand, "RunCommand", &LC0);
EnvDefineFunction2(a1, "halt", 118LL, &HaltCommand, "HaltCommand", "00");
EnvDefineFunction2(a1, "focus", 98LL, &FocusCommand, "FocusCommand", "1*w");
EnvDefineFunction2(a1, "clear-focus-stack", 118LL, &ClearFocusStackCommand, "ClearFocusStackCommand", "00");
EnvDefineFunction2(a1, "get-focus-stack", 109LL, &GetFocusStackFunction, "GetFocusStackFunction", "00");
EnvDefineFunction2(a1, "pop-focus", 119LL, &PopFocusFunction, "PopFocusFunction", "00");
EnvDefineFunction2(a1, "get-focus", 119LL, &GetFocusFunction, "GetFocusFunction", "00");
EnvDefineFunction2(a1, "set-break", 118LL, &SetBreakCommand, "SetBreakCommand", "11w");
EnvDefineFunction2(a1, "remove-break", 118LL, &RemoveBreakCommand, "RemoveBreakCommand", "*1w");
EnvDefineFunction2(a1, "show-breaks", 118LL, &ShowBreaksCommand, "ShowBreaksCommand", "01w");
EnvDefineFunction2(a1, "matches", 118LL, MatchesCommand, "MatchesCommand", "11w");
EnvDefineFunction2(a1, "list-focus-stack", 118LL, &ListFocusStackCommand, "ListFocusStackCommand", "00");
EnvDefineFunction2(a1, "dependencies", 118LL, &DependenciesCommand, "DependenciesCommand", "11h");
EnvDefineFunction2(a1, "dependents", 118LL, &DependentsCommand, "DependentsCommand", "11h");
EnvDefineFunction2(a1, "get-incremental-reset", 98LL, &GetIncrementalResetCommand, "GetIncrementalResetCommand", "00");
EnvDefineFunction2(a1, "set-incremental-reset", 98LL, &SetIncrementalResetCommand, "SetIncrementalResetCommand", "11");
EnvDefineFunction2(a1, "get-strategy", 119LL, &GetStrategyCommand, "GetStrategyCommand", "00");
return EnvDefineFunction2(a1, "set-strategy", 119LL, &SetStrategyCommand, "SetStrategyCommand", "11w");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
EnvDefineFunction2(a1, "run", 118LL, &RunCommand, "RunCommand", &LC0);
EnvDefineFunction2(a1, "halt", 118LL, &HaltCommand, "HaltCommand", "00");
EnvDefineFunction2(a1, "focus", 98LL, &FocusCommand, "FocusCommand", "1*w");
EnvDefineFunction2(a1, "clear-focus-stack", 118LL, &ClearFocusStackCommand, "ClearFocusStackCommand", "00");
EnvDefineFunction2(a1, "get-focus-stack", 109LL, &GetFocusStackFunction, "GetFocusStackFunction", "00");
EnvDefineFunction2(a1, "pop-focus", 119LL, &PopFocusFunction, "PopFocusFunction", "00");
EnvDefineFunction2(a1, "get-focus", 119LL, &GetFocusFunction, "GetFocusFunction", "00");
EnvDefineFunction2(a1, "set-break", 118LL, &SetBreakCommand, "SetBreakCommand", "11w");
EnvDefineFunction2(a1, "remove-break", 118LL, &RemoveBreakCommand, "RemoveBreakCommand", "*1w");
EnvDefineFunction2(a1, "show-breaks", 118LL, &ShowBreaksCommand, "ShowBreaksCommand", "01w");
EnvDefineFunction2(a1, "matches", 118LL, MatchesCommand, "MatchesCommand", "11w");
EnvDefineFunction2(a1, "list-focus-stack", 118LL, &ListFocusStackCommand, "ListFocusStackCommand", "00");
EnvDefineFunction2(a1, "dependencies", 118LL, &DependenciesCommand, "DependenciesCommand", "11h");
EnvDefineFunction2(a1, "dependents", 118LL, &DependentsCommand, "DependentsCommand", "11h");
EnvDefineFunction2(a1, "get-incremental-reset", 98LL, &GetIncrementalResetCommand, "GetIncrementalResetCommand", "00");
EnvDefineFunction2(a1, "set-incremental-reset", 98LL, &SetIncrementalResetCommand, "SetIncrementalResetCommand", "11");
EnvDefineFunction2(a1, "get-strategy", 119LL, &GetStrategyCommand, "GetStrategyCommand", "00");
return EnvDefineFunction2(a1, "set-strategy", 119LL, &SetStrategyCommand, "SetStrategyCommand", "11w");
}

original_code:
void DefruleCommands(
  void *theEnv)
  {
   EnvDefineFunction2(theEnv,"run",'v', (int (*)(void *)) RunCommand,"RunCommand", "*1i");
   EnvDefineFunction2(theEnv,"halt",'v', (int (*)(void *)) HaltCommand,"HaltCommand","00");
   EnvDefineFunction2(theEnv,"focus",'b', (int (*)(void *)) FocusCommand,"FocusCommand", "1*w");
   EnvDefineFunction2(theEnv,"clear-focus-stack",'v',(int (*)(void *)) ClearFocusStackCommand,
                                       "ClearFocusStackCommand","00");
   EnvDefineFunction2(theEnv,"get-focus-stack",'m',(int (*)(void *)) GetFocusStackFunction,
                                     "GetFocusStackFunction","00");
   EnvDefineFunction2(theEnv,"pop-focus",'w',(int (*)(void *)) PopFocusFunction,
                               "PopFocusFunction","00");
   EnvDefineFunction2(theEnv,"get-focus",'w',(int (*)(void *)) GetFocusFunction,
                               "GetFocusFunction","00");
   EnvDefineFunction2(theEnv,"set-break",'v', (int (*)(void *)) SetBreakCommand,
                               "SetBreakCommand","11w");
   EnvDefineFunction2(theEnv,"remove-break",'v', (int (*)(void *)) RemoveBreakCommand,
                                  "RemoveBreakCommand", "*1w");
   EnvDefineFunction2(theEnv,"show-breaks",'v', (int (*)(void *)) ShowBreaksCommand,
                                 "ShowBreaksCommand", "01w");
   EnvDefineFunction2(theEnv,"matches",'v',(int (*)(void *)) MatchesCommand,"MatchesCommand","11w");
   EnvDefineFunction2(theEnv,"list-focus-stack",'v', (int (*)(void *)) ListFocusStackCommand,
                                      "ListFocusStackCommand", "00");
   EnvDefineFunction2(theEnv,"dependencies", 'v', (int (*)(void *)) DependenciesCommand,
                                   "DependenciesCommand", "11h");
   EnvDefineFunction2(theEnv,"dependents", 'v', (int (*)(void *)) DependentsCommand,
                                   "DependentsCommand", "11h");
   EnvDefineFunction2(theEnv,"get-incremental-reset",'b',
                   GetIncrementalResetCommand,"GetIncrementalResetCommand","00");
   EnvDefineFunction2(theEnv,"set-incremental-reset",'b',
                   SetIncrementalResetCommand,"SetIncrementalResetCommand","11");
   EnvDefineFunction2(theEnv,"get-strategy", 'w', (int (*)(void *)) GetStrategyCommand, "GetStrategyCommand", "00");
   EnvDefineFunction2(theEnv,"set-strategy", 'w', (int (*)(void *)) SetStrategyCommand, "SetStrategyCommand", "11w");
  }

canonical_original_code:
void DefruleCommands(void *theEnv)
  {
   EnvDefineFunction2(theEnv,"run",'v', (int (*)(void *)) RunCommand,"RunCommand", "*1i");
   EnvDefineFunction2(theEnv,"halt",'v', (int (*)(void *)) HaltCommand,"HaltCommand","00");
   EnvDefineFunction2(theEnv,"focus",'b', (int (*)(void *)) FocusCommand,"FocusCommand", "1*w");
   EnvDefineFunction2(theEnv,"clear-focus-stack",'v',(int (*)(void *)) ClearFocusStackCommand,
                                       "ClearFocusStackCommand","00");
   EnvDefineFunction2(theEnv,"get-focus-stack",'m',(int (*)(void *)) GetFocusStackFunction,
                                     "GetFocusStackFunction","00");
   EnvDefineFunction2(theEnv,"pop-focus",'w',(int (*)(void *)) PopFocusFunction,
                               "PopFocusFunction","00");
   EnvDefineFunction2(theEnv,"get-focus",'w',(int (*)(void *)) GetFocusFunction,
                               "GetFocusFunction","00");
   EnvDefineFunction2(theEnv,"set-break",'v', (int (*)(void *)) SetBreakCommand,
                               "SetBreakCommand","11w");
   EnvDefineFunction2(theEnv,"remove-break",'v', (int (*)(void *)) RemoveBreakCommand,
                                  "RemoveBreakCommand", "*1w");
   EnvDefineFunction2(theEnv,"show-breaks",'v', (int (*)(void *)) ShowBreaksCommand,
                                 "ShowBreaksCommand", "01w");
   EnvDefineFunction2(theEnv,"matches",'v',(int (*)(void *)) MatchesCommand,"MatchesCommand","11w");
   EnvDefineFunction2(theEnv,"list-focus-stack",'v', (int (*)(void *)) ListFocusStackCommand,
                                      "ListFocusStackCommand", "00");
   EnvDefineFunction2(theEnv,"dependencies", 'v', (int (*)(void *)) DependenciesCommand,
                                   "DependenciesCommand", "11h");
   EnvDefineFunction2(theEnv,"dependents", 'v', (int (*)(void *)) DependentsCommand,
                                   "DependentsCommand", "11h");
   EnvDefineFunction2(theEnv,"get-incremental-reset",'b',
                   GetIncrementalResetCommand,"GetIncrementalResetCommand","00");
   EnvDefineFunction2(theEnv,"set-incremental-reset",'b',
                   SetIncrementalResetCommand,"SetIncrementalResetCommand","11");
   EnvDefineFunction2(theEnv,"get-strategy", 'w', (int (*)(void *)) GetStrategyCommand, "GetStrategyCommand", "00");
   EnvDefineFunction2(theEnv,"set-strategy", 'w', (int (*)(void *)) SetStrategyCommand, "SetStrategyCommand", "11w");
  }


EnvMatches

decompiled_code:
__int64 __fastcall EnvMatches(__int64 a1, _QWORD *a2)
{
__int64 v2; // r13
int v3; // ebx
unsigned __int64 v4; // rsi
__int64 v5; // rax
const char **v6; // rdx
__int64 v7; // rcx
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rcx
__int64 v12; // r14
int v14; // ebx
unsigned __int64 v15; // rsi
__int64 v16; // rax
__int64 v17; // rdx
__int64 v18; // r13
int v19; // er12
__int64 v20; // r14
int v21; // ebx
__int64 v22; // rsi
__int64 v23; // rdx
__int64 v24; // rcx
__int64 v25; // rbp
_QWORD *v26; // [rsp+0h] [rbp-58h]
unsigned int v27; // [rsp+Ch] [rbp-4Ch]
_QWORD *v28; // [rsp+18h] [rbp-40h]

v28 = a2;
v26 = a2;
if ( a2 )
{
while ( 1 )
{
v2 = v26[11];
v3 = GetPatternNumberFromJoin(v2);
v4 = (unsigned int)(24 * v3);
v27 = 24 * v3;
v5 = genalloc(a1, v4);
v7 = (unsigned int)(v3 - 1);
v8 = v5;
v9 = v2;
if ( v2 )
{
do
{
while ( 1 )
{
v6 = *(const char ***)(v9 + 32);
if ( (*(_BYTE *)v9 & 4) != 0 )
break;
v4 = (unsigned __int64)*v6;
v9 = *(_QWORD *)(v9 + 48);
v6 = (const char **)(int)v7;
v7 = (unsigned int)(v7 - 1);
*(_QWORD *)(v8 + 8LL * (_QWORD)v6) = v4;
if ( !v9 )
goto LABEL_7;
}
v9 = *(_QWORD *)(v9 + 32);
}
while ( v6 );
}
LABEL_7:
v10 = 1LL;
if ( v3 > 0 )
break;
LABEL_16:
genfree(a1, v8, v27, v7);
v14 = *(_BYTE *)(v2 + 1) >> 1;
v15 = 24 * (unsigned int)(unsigned __int8)v14;
v27 = 24 * (unsigned __int8)v14;
v8 = genalloc(a1, v15);
v16 = v14 - 1;
if ( v14 )
{
do
{
v17 = *(_QWORD *)(v2 + 16);
v2 = *(_QWORD *)(v2 + 48);
*(_QWORD *)(v8 + 8 * v16--) = v17;
}
while ( (_DWORD)v16 != -1 );
if ( v14 != 1 )
{
v18 = 2LL;
while ( (unsigned int)GetHaltExecution(a1, v15, v17, v11) != 1 )
{
v19 = 0;
EnvPrintRouter(a1, "wdisplay", "Partial matches for CEs 1 - ");
PrintLongInteger(a1, "wdisplay", v18);
v15 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", "\n");
v20 = *(_QWORD *)(v8 + 8 * v18 - 8);
if ( v20 )
{
while ( (unsigned int)GetHaltExecution(a1, "wdisplay", v17, v11) != 1 )
{
if ( (*(_BYTE *)v20 & 0x20) == 0 )
{
++v19;
PrintPartialMatch(a1, "wdisplay", v20);
v15 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", "\n");
}
v20 = *(_QWORD *)(v20 + 8);
if ( !v20 )
{
if ( !v19 )
goto LABEL_36;
goto LABEL_28;
}
}
goto LABEL_13;
}
LABEL_36:
v15 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", " None\n");
LABEL_28:
if ( ++v18 == (unsigned int)(v14 - 2) + 3LL )
goto LABEL_29;
}
goto LABEL_13;
}
}
LABEL_29:
genfree(a1, v8, v27, v11);
v26 = (_QWORD *)v26[12];
if ( !v26 )
goto LABEL_30;
}
while ( (unsigned int)GetHaltExecution(a1, v4, v6, v7) != 1 )
{
EnvPrintRouter(a1, "wdisplay", "Matches for Pattern ");
PrintLongInteger(a1, "wdisplay", v10);
EnvPrintRouter(a1, "wdisplay", "\n");
v12 = *(_QWORD *)(v8 + 8 * v10 - 8);
if ( v12 )
{
while ( (unsigned int)GetHaltExecution(a1, "wdisplay", v6, v7) != 1 )
{
PrintPartialMatch(a1, "wdisplay", v12);
v4 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", "\n");
v12 = *(_QWORD *)(v12 + 8);
if ( !v12 )
goto LABEL_15;
}
break;
}
v4 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", " None\n");
LABEL_15:
if ( v3 + 1 == ++v10 )
goto LABEL_16;
}
LABEL_13:
genfree(a1, v8, v27, v11);
}
else
{
LABEL_30:
v21 = 1;
EnvPrintRouter(a1, "wdisplay", "Activations\n");
v22 = 0LL;
v25 = EnvGetNextActivation(a1, 0LL);
if ( v25 )
{
while ( (unsigned int)GetHaltExecution(a1, v22, v23, v24) != 1 )
{
if ( **(_QWORD **)v25 == *v28 )
{
v21 = 0;
PrintPartialMatch(a1, "wdisplay", *(_QWORD *)(v25 + 8));
EnvPrintRouter(a1, "wdisplay", "\n");
}
v22 = v25;
v25 = EnvGetNextActivation(a1, v25);
if ( !v25 )
{
if ( !v21 )
return 1LL;
goto LABEL_38;
}
}
}
else
{
LABEL_38:
EnvPrintRouter(a1, "wdisplay", " None\n");
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
__int64 v2; // r13
int v3; // ebx
unsigned __int64 v4; // rsi
__int64 v5; // rax
const char **v6; // rdx
__int64 v7; // rcx
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rcx
__int64 v12; // r14
int v14; // ebx
unsigned __int64 v15; // rsi
__int64 v16; // rax
__int64 v17; // rdx
__int64 v18; // r13
int v19; // er12
__int64 v20; // r14
int v21; // ebx
__int64 v22; // rsi
__int64 v23; // rdx
__int64 v24; // rcx
__int64 v25; // rbp
_QWORD *v26; // [rsp+0h] [rbp-58h]
unsigned int v27; // [rsp+Ch] [rbp-4Ch]
_QWORD *v28; // [rsp+18h] [rbp-40h]

v28 = a2;
v26 = a2;
if ( a2 )
{
while ( 1 )
{
v2 = v26[11];
v3 = GetPatternNumberFromJoin(v2);
v4 = (unsigned int)(24 * v3);
v27 = 24 * v3;
v5 = genalloc(a1, v4);
v7 = (unsigned int)(v3 - 1);
v8 = v5;
v9 = v2;
if ( v2 )
{
do
{
while ( 1 )
{
v6 = *(const char ***)(v9 + 32);
if ( (*(_BYTE *)v9 & 4) != 0 )
break;
v4 = (unsigned __int64)*v6;
v9 = *(_QWORD *)(v9 + 48);
v6 = (const char **)(int)v7;
v7 = (unsigned int)(v7 - 1);
*(_QWORD *)(v8 + 8LL * (_QWORD)v6) = v4;
if ( !v9 )
goto LABEL_7;
}
v9 = *(_QWORD *)(v9 + 32);
}
while ( v6 );
}
LABEL_7:
v10 = 1LL;
if ( v3 > 0 )
break;
LABEL_16:
genfree(a1, v8, v27, v7);
v14 = *(_BYTE *)(v2 + 1) >> 1;
v15 = 24 * (unsigned int)(unsigned __int8)v14;
v27 = 24 * (unsigned __int8)v14;
v8 = genalloc(a1, v15);
v16 = v14 - 1;
if ( v14 )
{
do
{
v17 = *(_QWORD *)(v2 + 16);
v2 = *(_QWORD *)(v2 + 48);
*(_QWORD *)(v8 + 8 * v16--) = v17;
}
while ( (_DWORD)v16 != -1 );
if ( v14 != 1 )
{
v18 = 2LL;
while ( (unsigned int)GetHaltExecution(a1, v15, v17, v11) != 1 )
{
v19 = 0;
EnvPrintRouter(a1, "wdisplay", "Partial matches for CEs 1 - ");
PrintLongInteger(a1, "wdisplay", v18);
v15 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", "\n");
v20 = *(_QWORD *)(v8 + 8 * v18 - 8);
if ( v20 )
{
while ( (unsigned int)GetHaltExecution(a1, "wdisplay", v17, v11) != 1 )
{
if ( (*(_BYTE *)v20 & 0x20) == 0 )
{
++v19;
PrintPartialMatch(a1, "wdisplay", v20);
v15 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", "\n");
}
v20 = *(_QWORD *)(v20 + 8);
if ( !v20 )
{
if ( !v19 )
goto LABEL_36;
goto LABEL_28;
}
}
goto LABEL_13;
}
LABEL_36:
v15 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", " None\n");
LABEL_28:
if ( ++v18 == (unsigned int)(v14 - 2) + 3LL )
goto LABEL_29;
}
goto LABEL_13;
}
}
LABEL_29:
genfree(a1, v8, v27, v11);
v26 = (_QWORD *)v26[12];
if ( !v26 )
goto LABEL_30;
}
while ( (unsigned int)GetHaltExecution(a1, v4, v6, v7) != 1 )
{
EnvPrintRouter(a1, "wdisplay", "Matches for Pattern ");
PrintLongInteger(a1, "wdisplay", v10);
EnvPrintRouter(a1, "wdisplay", "\n");
v12 = *(_QWORD *)(v8 + 8 * v10 - 8);
if ( v12 )
{
while ( (unsigned int)GetHaltExecution(a1, "wdisplay", v6, v7) != 1 )
{
PrintPartialMatch(a1, "wdisplay", v12);
v4 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", "\n");
v12 = *(_QWORD *)(v12 + 8);
if ( !v12 )
goto LABEL_15;
}
break;
}
v4 = (unsigned __int64)"wdisplay";
EnvPrintRouter(a1, "wdisplay", " None\n");
LABEL_15:
if ( v3 + 1 == ++v10 )
goto LABEL_16;
}
LABEL_13:
genfree(a1, v8, v27, v11);
}
else
{
LABEL_30:
v21 = 1;
EnvPrintRouter(a1, "wdisplay", "Activations\n");
v22 = 0LL;
v25 = EnvGetNextActivation(a1, 0LL);
if ( v25 )
{
while ( (unsigned int)GetHaltExecution(a1, v22, v23, v24) != 1 )
{
if ( **(_QWORD **)v25 == *v28 )
{
v21 = 0;
PrintPartialMatch(a1, "wdisplay", *(_QWORD *)(v25 + 8));
EnvPrintRouter(a1, "wdisplay", "\n");
}
v22 = v25;
v25 = EnvGetNextActivation(a1, v25);
if ( !v25 )
{
if ( !v21 )
return 1LL;
goto LABEL_38;
}
}
}
else
{
LABEL_38:
EnvPrintRouter(a1, "wdisplay", " None\n");
}
}
return 1LL;
}

original_code:
int EnvMatches(
  void *theEnv,
  void *theRule)
  {
   struct defrule *rulePtr, *tmpPtr;
   struct partialMatch *listOfMatches, **theStorage;
   struct joinNode *theJoin, *lastJoin;
   int i, depth;
   ACTIVATION *agendaPtr;
   int flag;
   int matchesDisplayed;
   for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr;
        rulePtr != ((void *)0);
        rulePtr = rulePtr->disjunct)
     {
      lastJoin = rulePtr->lastJoin;
      depth = GetPatternNumberFromJoin(lastJoin);
      theStorage = (struct partialMatch **)
                   genalloc(theEnv,(unsigned) (depth * sizeof(struct partialMatch)));
      theJoin = lastJoin;
      i = depth - 1;
      while (theJoin != ((void *)0))
        {
         if (theJoin->joinFromTheRight)
           { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; }
         else
           {
            theStorage[i] = ((struct patternNodeHeader *) theJoin->rightSideEntryStructure)->alphaMemory;
            i--;
            theJoin = theJoin->lastLevel;
           }
        }
      for (i = 0; i < depth; i++)
        {
         if (GetHaltExecution(theEnv) == 1)
           {
            genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch)));
            return(1);
           }
         EnvPrintRouter(theEnv,"wdisplay","Matches for Pattern ");
         PrintLongInteger(theEnv,"wdisplay",(long int) i + 1);
         EnvPrintRouter(theEnv,"wdisplay","\n");
         listOfMatches = theStorage[i];
         if (listOfMatches == ((void *)0)) EnvPrintRouter(theEnv,"wdisplay"," None\n");
         while (listOfMatches != ((void *)0))
           {
            if (GetHaltExecution(theEnv) == 1)
              {
               genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch)));
               return(1);
              }
            PrintPartialMatch(theEnv,"wdisplay",listOfMatches);
            EnvPrintRouter(theEnv,"wdisplay","\n");
            listOfMatches = listOfMatches->next;
           }
        }
      genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch)));
      depth = lastJoin->depth;
      theStorage = (struct partialMatch **) genalloc(theEnv,(unsigned) (depth * sizeof(struct partialMatch)));
      theJoin = lastJoin;
      for (i = depth - 1; i >= 0; i--)
        {
         theStorage[i] = theJoin->beta;
         theJoin = theJoin->lastLevel;
        }
      for (i = 1; i < depth; i++)
        {
         if (GetHaltExecution(theEnv) == 1)
           {
            genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch)));
            return(1);
           }
         matchesDisplayed = 0;
         EnvPrintRouter(theEnv,"wdisplay","Partial matches for CEs 1 - ");
         PrintLongInteger(theEnv,"wdisplay",(long int) i + 1);
         EnvPrintRouter(theEnv,"wdisplay","\n");
         listOfMatches = theStorage[i];
         while (listOfMatches != ((void *)0))
           {
            if (GetHaltExecution(theEnv) == 1)
              {
               genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch)));
               return(1);
              }
            if (listOfMatches->counterf == 0)
              {
               matchesDisplayed++;
               PrintPartialMatch(theEnv,"wdisplay",listOfMatches);
               EnvPrintRouter(theEnv,"wdisplay","\n");
              }
            listOfMatches = listOfMatches->next;
           }
         if (matchesDisplayed == 0) { EnvPrintRouter(theEnv,"wdisplay"," None\n"); }
        }
      genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch)));
     }
   rulePtr = tmpPtr;
   EnvPrintRouter(theEnv,"wdisplay","Activations\n");
   flag = 1;
   for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,((void *)0));
        agendaPtr != ((void *)0);
        agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr))
     {
      if (GetHaltExecution(theEnv) == 1) return(1);
      if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name)
        {
         flag = 0;
         PrintPartialMatch(theEnv,"wdisplay",(((struct activation *) agendaPtr)->basis));
         EnvPrintRouter(theEnv,"wdisplay","\n");
        }
     }
   if (flag) EnvPrintRouter(theEnv,"wdisplay"," None\n");
   return(1);
  }

canonical_original_code:
int EnvMatches(void *theEnv, void *theRule)
  {
   struct defrule *rulePtr; struct defrule *tmpPtr;
   struct partialMatch *listOfMatches; struct partialMatch **theStorage;
   struct joinNode *theJoin; struct joinNode *lastJoin;
   int i; int depth;
   struct activation *agendaPtr;
   int flag;
   int matchesDisplayed;
   for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr;
        rulePtr != ((void *)0);
        rulePtr = rulePtr->disjunct)
     {
      lastJoin = rulePtr->lastJoin;
      depth = GetPatternNumberFromJoin(lastJoin);
      theStorage = (struct partialMatch **)
                   genalloc(theEnv,(unsigned int) (depth * sizeof(struct partialMatch)));
      theJoin = lastJoin;
      i = depth - 1;
      while (theJoin != ((void *)0))
        {
         if (theJoin->joinFromTheRight)
           { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; }
         else
           {
            theStorage[i] = ((struct patternNodeHeader *) theJoin->rightSideEntryStructure)->alphaMemory;
            i--;
            theJoin = theJoin->lastLevel;
           }
        }
      for (i = 0; i < depth; i++)
        {
         if (GetHaltExecution(theEnv) == 1)
           {
            genfree(theEnv,theStorage,(unsigned int) (depth * sizeof(struct partialMatch)));
            return(1);
           }
         EnvPrintRouter(theEnv,"wdisplay","Matches for Pattern ");
         PrintLongInteger(theEnv,"wdisplay",(long) i + 1);
         EnvPrintRouter(theEnv,"wdisplay","\n");
         listOfMatches = theStorage[i];
         if (listOfMatches == ((void *)0)) EnvPrintRouter(theEnv,"wdisplay"," None\n");
         while (listOfMatches != ((void *)0))
           {
            if (GetHaltExecution(theEnv) == 1)
              {
               genfree(theEnv,theStorage,(unsigned int) (depth * sizeof(struct partialMatch)));
               return(1);
              }
            PrintPartialMatch(theEnv,"wdisplay",listOfMatches);
            EnvPrintRouter(theEnv,"wdisplay","\n");
            listOfMatches = listOfMatches->next;
           }
        }
      genfree(theEnv,theStorage,(unsigned int) (depth * sizeof(struct partialMatch)));
      depth = lastJoin->depth;
      theStorage = (struct partialMatch **) genalloc(theEnv,(unsigned int) (depth * sizeof(struct partialMatch)));
      theJoin = lastJoin;
      for (i = depth - 1; i >= 0; i--)
        {
         theStorage[i] = theJoin->beta;
         theJoin = theJoin->lastLevel;
        }
      for (i = 1; i < depth; i++)
        {
         if (GetHaltExecution(theEnv) == 1)
           {
            genfree(theEnv,theStorage,(unsigned int) (depth * sizeof(struct partialMatch)));
            return(1);
           }
         matchesDisplayed = 0;
         EnvPrintRouter(theEnv,"wdisplay","Partial matches for CEs 1 - ");
         PrintLongInteger(theEnv,"wdisplay",(long) i + 1);
         EnvPrintRouter(theEnv,"wdisplay","\n");
         listOfMatches = theStorage[i];
         while (listOfMatches != ((void *)0))
           {
            if (GetHaltExecution(theEnv) == 1)
              {
               genfree(theEnv,theStorage,(unsigned int) (depth * sizeof(struct partialMatch)));
               return(1);
              }
            if (listOfMatches->counterf == 0)
              {
               matchesDisplayed++;
               PrintPartialMatch(theEnv,"wdisplay",listOfMatches);
               EnvPrintRouter(theEnv,"wdisplay","\n");
              }
            listOfMatches = listOfMatches->next;
           }
         if (matchesDisplayed == 0) { EnvPrintRouter(theEnv,"wdisplay"," None\n"); }
        }
      genfree(theEnv,theStorage,(unsigned int) (depth * sizeof(struct partialMatch)));
     }
   rulePtr = tmpPtr;
   EnvPrintRouter(theEnv,"wdisplay","Activations\n");
   flag = 1;
   for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,((void *)0));
        agendaPtr != ((void *)0);
        agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr))
     {
      if (GetHaltExecution(theEnv) == 1) return(1);
      if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name)
        {
         flag = 0;
         PrintPartialMatch(theEnv,"wdisplay",(((struct activation *) agendaPtr)->basis));
         EnvPrintRouter(theEnv,"wdisplay","\n");
        }
     }
   if (flag) EnvPrintRouter(theEnv,"wdisplay"," None\n");
   return(1);
  }

variable_types:
theRule
void *

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

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: depth int

variable_types: struct activation { 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; } *theRule; struct partialMatch *basis; int salience; unsigned long timetag; struct partialMatch *sortedBasis; int randomID; struct activation *prev; struct activation *next; } *

variable_types: flag int

variable_types: matchesDisplayed int

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

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

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

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

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

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

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

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


MatchesCommand

decompiled_code:
__int64 __fastcall MatchesCommand(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
_QWORD *v3; // rsi

result = GetConstructName(a1, "matches", "rule name");
if ( result )
{
v2 = result;
v3 = (_QWORD *)EnvFindDefrule(a1, result);
if ( v3 )
result = EnvMatches(a1, v3);
else
result = CantFindItemErrorMessage(a1, "defrule", v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
_QWORD *v3; // rsi

result = GetConstructName(a1, "matches", "rule name");
if ( result )
{
v2 = result;
v3 = (_QWORD *)EnvFindDefrule(a1, result);
if ( v3 )
result = func1(a1, v3);
else
result = CantFindItemErrorMessage(a1, "defrule", v2);
}
return result;
}

original_code:
void MatchesCommand(
  void *theEnv)
  {
   char *ruleName;
   void *rulePtr;
   ruleName = GetConstructName(theEnv,"matches","rule name");
   if (ruleName == ((void *)0)) return;
   rulePtr = EnvFindDefrule(theEnv,ruleName);
   if (rulePtr == ((void *)0))
     {
      CantFindItemErrorMessage(theEnv,"defrule",ruleName);
      return;
     }
   EnvMatches(theEnv,rulePtr);
  }

canonical_original_code:
void MatchesCommand(void *theEnv)
  {
   char *ruleName;
   void *rulePtr;
   ruleName = GetConstructName(theEnv,"matches","rule name");
   if (ruleName == ((void *)0)) return;
   rulePtr = EnvFindDefrule(theEnv,ruleName);
   if (rulePtr == ((void *)0))
     {
      CantFindItemErrorMessage(theEnv,"defrule",ruleName);
      return;
     }
   EnvMatches(theEnv,rulePtr);
  }

variable_types:
ruleName
char *

variable_types:
rulePtr
void *


FindEnvironment

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

for ( result = *((_QWORD *)EnvironmentHashTable + a1 % 0x83); result; result = *(_QWORD *)(result + 56) )
{
if ( *(_QWORD *)(result + 8) == a1 )
break;
}
return result;
}

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

for ( result = *((_QWORD *)EnvironmentHashTable + a1 % 0x83); result; result = *(_QWORD *)(result + 56) )
{
if ( *(_QWORD *)(result + 8) == a1 )
break;
}
return result;
}

original_code:
static struct environmentData *FindEnvironment(
  unsigned long environmentIndex)
  {
   struct environmentData *theEnvironment;
   unsigned long hashValue;
   hashValue = environmentIndex % 131;
   for (theEnvironment = EnvironmentHashTable[hashValue];
        theEnvironment != ((void *)0);
        theEnvironment = theEnvironment->next)
     {
      if (theEnvironment->environmentIndex == environmentIndex)
        { return(theEnvironment); }
     }
   return(((void *)0));
  }

canonical_original_code:
static struct environmentData *FindEnvironment(unsigned long environmentIndex)
  {
   struct environmentData *theEnvironment;
   unsigned long hashValue;
   hashValue = environmentIndex % 131;
   for (theEnvironment = EnvironmentHashTable[hashValue];
        theEnvironment != ((void *)0);
        theEnvironment = theEnvironment->next)
     {
      if (theEnvironment->environmentIndex == environmentIndex)
        { return(theEnvironment); }
     }
   return(((void *)0));
  }

variable_types:
environmentIndex
unsigned long

variable_types: struct environmentData { unsigned int initialized; unsigned long environmentIndex; void *context; void *routerContext; void **theData; void (**cleanupFunctions)(void *); struct environmentCleanupFunction { char *name; void (*func)(void *); int priority; struct environmentCleanupFunction *next; } *listOfCleanupEnvironmentFunctions; struct environmentData *next; } *

variable_types:
hashValue
unsigned long


RemoveEnvironmentCleanupFunctions

decompiled_code:
void __fastcall RemoveEnvironmentCleanupFunctions(__int64 a1)
{
_QWORD *i; // rbx
void *v3; // rdi

for ( i = *(_QWORD **)(a1 + 48); i; *(_QWORD *)(a1 + 48) = i )
{
v3 = i;
i = (_QWORD *)i[3];
free(v3);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
_QWORD *i; // rbx
void *v3; // rdi

for ( i = *(_QWORD **)(a1 + 48); i; *(_QWORD *)(a1 + 48) = i )
{
v3 = i;
i = (_QWORD *)i[3];
free(v3);
}
}

original_code:
static void RemoveEnvironmentCleanupFunctions(
  struct environmentData *theEnv)
  {
   struct environmentCleanupFunction *nextPtr;
   while (theEnv->listOfCleanupEnvironmentFunctions != ((void *)0))
     {
      nextPtr = theEnv->listOfCleanupEnvironmentFunctions->next;
      free(theEnv->listOfCleanupEnvironmentFunctions);
      theEnv->listOfCleanupEnvironmentFunctions = nextPtr;
     }
  }

canonical_original_code:
static void RemoveEnvironmentCleanupFunctions(struct environmentData *theEnv)
  {
   struct environmentCleanupFunction *nextPtr;
   while (theEnv->listOfCleanupEnvironmentFunctions != ((void *)0))
     {
      nextPtr = theEnv->listOfCleanupEnvironmentFunctions->next;
      free(theEnv->listOfCleanupEnvironmentFunctions);
      theEnv->listOfCleanupEnvironmentFunctions = nextPtr;
     }
  }

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


InitializeEnvironmentHashTable

decompiled_code:
void InitializeEnvironmentHashTable()
{
if ( !EnvironmentHashTable )
{
EnvironmentHashTable = calloc(0x418uLL, 1uLL);
if ( !EnvironmentHashTable )
puts("\n[ENVRNMNT4] Unable to initialize environment hash table.");
}
}

canonical_decompiled_code:
void func2()
{
if ( !EnvironmentHashTable )
{
EnvironmentHashTable = calloc(0x418uLL, 1uLL);
if ( !EnvironmentHashTable )
puts("\n[ENVRNMNT4] Unable to initialize environment hash table.");
}
}

original_code:
static void InitializeEnvironmentHashTable()
  {
   int i;
   if (EnvironmentHashTable != ((void *)0))
     { return; }
   EnvironmentHashTable = (struct environmentData **)
                          malloc(sizeof (struct environmentData *) * 131);
   if (EnvironmentHashTable == ((void *)0))
     {
      printf("\n[ENVRNMNT4] Unable to initialize environment hash table.\n");
      return;
     }
   for (i = 0; i < 131; i++) EnvironmentHashTable[i] = ((void *)0);
  }

variable_types: i int


AllocateEnvironmentData

decompiled_code:
__int64 __fastcall AllocateEnvironmentData(__int64 a1, __int64 a2, size_t a3, __int64 a4)
{
void **v5; // r15
__int64 result; // rax
void *v9; // rdi

if ( a3 )
{
if ( (unsigned int)a2 > 0x63 )
{
printf("\n[ENVRNMNT2] Environment data position %d exceeds the maximum allowed.\n", a2);
result = 0LL;
}
else
{
v5 = (void **)(*(_QWORD *)(a1 + 32) + 8LL * (unsigned int)a2);
if ( *v5 )
{
printf("\n[ENVRNMNT3] Environment data position %d already allocated.\n", a2);
result = 0LL;
}
else
{
*v5 = malloc(a3);
v9 = *(void **)(*(_QWORD *)(a1 + 32) + 8LL * (unsigned int)a2);
if ( v9 )
{
memset(v9, 0, a3);
*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * (unsigned int)a2) = a4;
result = 1LL;
}
else
{
printf("\n[ENVRNMNT4] Environment data position %d could not be allocated.\n", (unsigned int)a2);
result = 0LL;
}
}
}
}
else
{
printf("\n[ENVRNMNT1] Environment data position %d allocated with size of 0 or less.\n", a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, size_t a3, __int64 a4)
{
void **v5; // r15
__int64 result; // rax
void *v9; // rdi

if ( a3 )
{
if ( (unsigned int)a2 > 0x63 )
{
printf("\n[ENVRNMNT2] Environment data position %d exceeds the maximum allowed.\n", a2);
result = 0LL;
}
else
{
v5 = (void **)(*(_QWORD *)(a1 + 32) + 8LL * (unsigned int)a2);
if ( *v5 )
{
printf("\n[ENVRNMNT3] Environment data position %d already allocated.\n", a2);
result = 0LL;
}
else
{
*v5 = malloc(a3);
v9 = *(void **)(*(_QWORD *)(a1 + 32) + 8LL * (unsigned int)a2);
if ( v9 )
{
memset(v9, 0, a3);
*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * (unsigned int)a2) = a4;
result = 1LL;
}
else
{
printf("\n[ENVRNMNT4] Environment data position %d could not be allocated.\n", (unsigned int)a2);
result = 0LL;
}
}
}
}
else
{
printf("\n[ENVRNMNT1] Environment data position %d allocated with size of 0 or less.\n", a2);
result = 0LL;
}
return result;
}

original_code:
int AllocateEnvironmentData(
  void *vtheEnvironment,
  unsigned int position,
  unsigned long size,
  void (*cleanupFunction)(void *))
  {
   struct environmentData *theEnvironment = (struct environmentData *) vtheEnvironment;
   if (size <= 0)
     {
      printf("\n[ENVRNMNT1] Environment data position %d allocated with size of 0 or less.\n",position);
      return(0);
     }
   if (position >= 100)
     {
      printf("\n[ENVRNMNT2] Environment data position %d exceeds the maximum allowed.\n",position);
      return(0);
     }
   if (theEnvironment->theData[position] != ((void *)0))
     {
      printf("\n[ENVRNMNT3] Environment data position %d already allocated.\n",position);
      return(0);
     }
   theEnvironment->theData[position] = malloc(size);
   if (theEnvironment->theData[position] == ((void *)0))
     {
      printf("\n[ENVRNMNT4] Environment data position %d could not be allocated.\n",position);
      return(0);
     }
   memset(theEnvironment->theData[position],0,size);
   theEnvironment->cleanupFunctions[position] = cleanupFunction;
   return(1);
  }

canonical_original_code:
int AllocateEnvironmentData(void *vtheEnvironment, unsigned int position, unsigned long size, void (*cleanupFunction)(void *))
  {
   struct environmentData *theEnvironment = (struct environmentData *) vtheEnvironment;
   if (size <= 0)
     {
      printf("\n[ENVRNMNT1] Environment data position %d allocated with size of 0 or less.\n",position);
      return(0);
     }
   if (position >= 100)
     {
      printf("\n[ENVRNMNT2] Environment data position %d exceeds the maximum allowed.\n",position);
      return(0);
     }
   if (theEnvironment->theData[position] != ((void *)0))
     {
      printf("\n[ENVRNMNT3] Environment data position %d already allocated.\n",position);
      return(0);
     }
   theEnvironment->theData[position] = malloc(size);
   if (theEnvironment->theData[position] == ((void *)0))
     {
      printf("\n[ENVRNMNT4] Environment data position %d could not be allocated.\n",position);
      return(0);
     }
   memset(theEnvironment->theData[position],0,size);
   theEnvironment->cleanupFunctions[position] = cleanupFunction;
   return(1);
  }

variable_types:
vtheEnvironment
void *

variable_types:
position
unsigned int

variable_types:
size
unsigned long

variable_types:
cleanupFunction
void (*)(void *)


CreateEnvironment

decompiled_code:
_QWORD *CreateEnvironment()
{
return CreateEnvironmentDriver(0LL, 0LL, 0LL, 0LL);
}

canonical_decompiled_code:
_QWORD *func6()
{
return CreateEnvironmentDriver(0LL, 0LL, 0LL, 0LL);
}

original_code:
void *CreateEnvironment()
  {
   return CreateEnvironmentDriver(((void *)0),((void *)0),((void *)0),((void *)0));
  }

return_type: void *


SetCurrentEnvironment

decompiled_code:
void __fastcall SetCurrentEnvironment(__int64 a1)
{
CurrentEnvironment = a1;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
CurrentEnvironment = a1;
}

original_code:
void SetCurrentEnvironment(
  void *theEnvironment)
  {
   CurrentEnvironment = (struct environmentData *) theEnvironment;
  }

canonical_original_code:
void SetCurrentEnvironment(void *theEnvironment)
  {
   CurrentEnvironment = (struct environmentData *) theEnvironment;
  }

variable_types:
theEnvironment
void *


SetCurrentEnvironmentByIndex

decompiled_code:
__int64 __fastcall SetCurrentEnvironmentByIndex(unsigned __int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = FindEnvironment(a1);
result = 0LL;
if ( v1 )
{
SetCurrentEnvironment(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = func0(a1);
result = 0LL;
if ( v1 )
{
func7(v1);
result = 1LL;
}
return result;
}

original_code:
int SetCurrentEnvironmentByIndex(
  unsigned long environmentIndex)
  {
   struct environmentData *theEnvironment;
   theEnvironment = FindEnvironment(environmentIndex);
   if (theEnvironment == ((void *)0))
     { return(0); }
   SetCurrentEnvironment(theEnvironment);
   return(1);
  }

canonical_original_code:
int SetCurrentEnvironmentByIndex(unsigned long environmentIndex)
  {
   struct environmentData *theEnvironment;
   theEnvironment = FindEnvironment(environmentIndex);
   if (theEnvironment == ((void *)0))
     { return(0); }
   SetCurrentEnvironment(theEnvironment);
   return(1);
  }


GetEnvironmentByIndex

decompiled_code:
// attributes: thunk
__int64 __fastcall GetEnvironmentByIndex(unsigned __int64 a1)
{
return FindEnvironment(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int64 a1)
{
return func0(a1);
}

original_code:
void *GetEnvironmentByIndex(
  unsigned long environmentIndex)
  {
   struct environmentData *theEnvironment;
   theEnvironment = FindEnvironment(environmentIndex);
   return(theEnvironment);
  }

canonical_original_code:
void *GetEnvironmentByIndex(unsigned long environmentIndex)
  {
   struct environmentData *theEnvironment;
   theEnvironment = FindEnvironment(environmentIndex);
   return(theEnvironment);
  }


GetCurrentEnvironment

decompiled_code:
__int64 GetCurrentEnvironment()
{
return CurrentEnvironment;
}

canonical_decompiled_code:
__int64 func10()
{
return CurrentEnvironment;
}

original_code:
void *GetCurrentEnvironment()
  {
   return(CurrentEnvironment);
  }


GetEnvironmentIndex

decompiled_code:
__int64 __fastcall GetEnvironmentIndex(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
unsigned long GetEnvironmentIndex(
  void *theEnvironment)
  {
   return(((struct environmentData *) theEnvironment)->environmentIndex);
  }

canonical_original_code:
unsigned long GetEnvironmentIndex(void *theEnvironment)
  {
   return(((struct environmentData *) theEnvironment)->environmentIndex);
  }

return_type: unsigned long


GetEnvironmentContext

decompiled_code:
__int64 __fastcall GetEnvironmentContext(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
void *GetEnvironmentContext(
  void *theEnvironment)
  {
   return(((struct environmentData *) theEnvironment)->context);
  }

canonical_original_code:
void *GetEnvironmentContext(void *theEnvironment)
  {
   return(((struct environmentData *) theEnvironment)->context);
  }


SetEnvironmentContext

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

result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = a2;
return result;
}

original_code:
void *SetEnvironmentContext(
  void *theEnvironment,
  void *theContext)
  {
   void *oldContext;
   oldContext = ((struct environmentData *) theEnvironment)->context;
   ((struct environmentData *) theEnvironment)->context = theContext;
   return oldContext;
  }

canonical_original_code:
void *SetEnvironmentContext(void *theEnvironment, void *theContext)
  {
   void *oldContext;
   oldContext = ((struct environmentData *) theEnvironment)->context;
   ((struct environmentData *) theEnvironment)->context = theContext;
   return oldContext;
  }

variable_types:
theContext
void *

variable_types:
oldContext
void *


GetEnvironmentRouterContext

decompiled_code:
__int64 __fastcall GetEnvironmentRouterContext(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
void *GetEnvironmentRouterContext(
  void *theEnvironment)
  {
   return(((struct environmentData *) theEnvironment)->routerContext);
  }

canonical_original_code:
void *GetEnvironmentRouterContext(void *theEnvironment)
  {
   return(((struct environmentData *) theEnvironment)->routerContext);
  }


SetEnvironmentRouterContext

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

result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = a2;
return result;
}

original_code:
void *SetEnvironmentRouterContext(
  void *theEnvironment,
  void *theRouterContext)
  {
   void *oldRouterContext;
   oldRouterContext = ((struct environmentData *) theEnvironment)->routerContext;
   ((struct environmentData *) theEnvironment)->routerContext = theRouterContext;
   return oldRouterContext;
  }

canonical_original_code:
void *SetEnvironmentRouterContext(void *theEnvironment, void *theRouterContext)
  {
   void *oldRouterContext;
   oldRouterContext = ((struct environmentData *) theEnvironment)->routerContext;
   ((struct environmentData *) theEnvironment)->routerContext = theRouterContext;
   return oldRouterContext;
  }

variable_types:
theRouterContext
void *

variable_types:
oldRouterContext
void *


DestroyEnvironment

decompiled_code:
__int64 __fastcall DestroyEnvironment(void *ptr)
{
__int64 v1; // rax
__int64 v4; // rbx
__int64 v5; // r13
char *v6; // rdi
void (__fastcall *v7)(void *); // rax
__int64 i; // rbx
unsigned int v9; // er12
__int64 v10; // rbx
char *v11; // r8
void *v12; // rdi

v1 = *((_QWORD *)ptr + 4);
if ( **(_QWORD **)(v1 + 352) || **(_QWORD **)(v1 + 144) )
return 0LL;
v4 = 0LL;
v5 = *(_QWORD *)(v1 + 472);
EnvReleaseMem(ptr, -1LL, 0LL);
v6 = (char *)*((_QWORD *)ptr + 5);
do
{
v7 = *(void (__fastcall **)(void *))&v6[v4];
if ( v7 )
{
v7(ptr);
v6 = (char *)*((_QWORD *)ptr + 5);
}
v4 += 8LL;
}
while ( v4 != 800 );
free(v6);
for ( i = *((_QWORD *)ptr + 6); i; i = *(_QWORD *)(i + 24) )
(*(void (__fastcall **)(void *))(i + 8))(ptr);
RemoveEnvironmentCleanupFunctions((__int64)ptr);
EnvReleaseMem(ptr, -1LL, 0LL);
RemoveHashedEnvironment_isra_0((__int64)ptr);
if ( *(_QWORD *)v5 || (v9 = 1, *(_QWORD *)(v5 + 8)) )
{
v9 = 0;
puts("\n[ENVRNMNT8] Environment data not fully deallocated.");
}
v10 = 0LL;
free(*(void **)(v5 + 40));
v11 = (char *)*((_QWORD *)ptr + 4);
do
{
v12 = *(void **)&v11[v10];
if ( v12 )
{
free(v12);
*(_QWORD *)(*((_QWORD *)ptr + 4) + v10) = 0LL;
v11 = (char *)*((_QWORD *)ptr + 4);
}
v10 += 8LL;
}
while ( v10 != 800 );
free(v11);
if ( (void *)CurrentEnvironment == ptr )
CurrentEnvironment = 0LL;
free(ptr);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func16(void *ptr)
{
__int64 v1; // rax
__int64 v4; // rbx
__int64 v5; // r13
char *v6; // rdi
void (__fastcall *v7)(void *); // rax
__int64 i; // rbx
unsigned int v9; // er12
__int64 v10; // rbx
char *v11; // r8
void *v12; // rdi

v1 = *((_QWORD *)ptr + 4);
if ( **(_QWORD **)(v1 + 352) || **(_QWORD **)(v1 + 144) )
return 0LL;
v4 = 0LL;
v5 = *(_QWORD *)(v1 + 472);
EnvReleaseMem(ptr, -1LL, 0LL);
v6 = (char *)*((_QWORD *)ptr + 5);
do
{
v7 = *(void (__fastcall **)(void *))&v6[v4];
if ( v7 )
{
v7(ptr);
v6 = (char *)*((_QWORD *)ptr + 5);
}
v4 += 8LL;
}
while ( v4 != 800 );
free(v6);
for ( i = *((_QWORD *)ptr + 6); i; i = *(_QWORD *)(i + 24) )
(*(void (__fastcall **)(void *))(i + 8))(ptr);
func1((__int64)ptr);
EnvReleaseMem(ptr, -1LL, 0LL);
func4((__int64)ptr);
if ( *(_QWORD *)v5 || (v9 = 1, *(_QWORD *)(v5 + 8)) )
{
v9 = 0;
puts("\n[ENVRNMNT8] Environment data not fully deallocated.");
}
v10 = 0LL;
free(*(void **)(v5 + 40));
v11 = (char *)*((_QWORD *)ptr + 4);
do
{
v12 = *(void **)&v11[v10];
if ( v12 )
{
free(v12);
*(_QWORD *)(*((_QWORD *)ptr + 4) + v10) = 0LL;
v11 = (char *)*((_QWORD *)ptr + 4);
}
v10 += 8LL;
}
while ( v10 != 800 );
free(v11);
if ( (void *)CurrentEnvironment == ptr )
CurrentEnvironment = 0LL;
free(ptr);
return v9;
}

original_code:
int DestroyEnvironment(
  void *vtheEnvironment)
  {
   struct environmentCleanupFunction *cleanupPtr;
   int i;
   struct memoryData *theMemData;
   int rv = 1;
   struct environmentData *theEnvironment = (struct environmentData *) vtheEnvironment;
   if (((struct evaluationData *) (((struct environmentData *) theEnvironment)->theData[44]))->CurrentExpression != ((void *)0))
     { return(0); }
   if (((struct engineData *) (((struct environmentData *) theEnvironment)->theData[18]))->ExecutingRule != ((void *)0))
     { return(0); }
   theMemData = ((struct memoryData *) (((struct environmentData *) theEnvironment)->theData[59]));
   EnvReleaseMem(theEnvironment,-1,0);
   for (i = 0; i < 100; i++)
     {
      if (theEnvironment->cleanupFunctions[i] != ((void *)0))
        { (*theEnvironment->cleanupFunctions[i])(theEnvironment); }
     }
   free(theEnvironment->cleanupFunctions);
   for (cleanupPtr = theEnvironment->listOfCleanupEnvironmentFunctions;
        cleanupPtr != ((void *)0);
        cleanupPtr = cleanupPtr->next)
     { (*cleanupPtr->func)(theEnvironment); }
   RemoveEnvironmentCleanupFunctions(theEnvironment);
   EnvReleaseMem(theEnvironment,-1,0);
   RemoveHashedEnvironment(theEnvironment);
   if ((theMemData->MemoryAmount != 0) || (theMemData->MemoryCalls != 0))
     {
      printf("\n[ENVRNMNT8] Environment data not fully deallocated.\n");
      rv = 0;
     }
   free(theMemData->MemoryTable);
   for (i = 0; i < 100; i++)
     {
      if (theEnvironment->theData[i] != ((void *)0))
        {
         free(theEnvironment->theData[i]);
         theEnvironment->theData[i] = ((void *)0);
        }
     }
   free(theEnvironment->theData);
   if (CurrentEnvironment == theEnvironment)
     { CurrentEnvironment = ((void *)0); }
   free(theEnvironment);
   return(rv);
  }

canonical_original_code:
int DestroyEnvironment(void *vtheEnvironment)
  {
   struct environmentCleanupFunction *cleanupPtr;
   int i;
   struct memoryData *theMemData;
   int rv = 1;
   struct environmentData *theEnvironment = (struct environmentData *) vtheEnvironment;
   if (((struct evaluationData *) (((struct environmentData *) theEnvironment)->theData[44]))->CurrentExpression != ((void *)0))
     { return(0); }
   if (((struct engineData *) (((struct environmentData *) theEnvironment)->theData[18]))->ExecutingRule != ((void *)0))
     { return(0); }
   theMemData = ((struct memoryData *) (((struct environmentData *) theEnvironment)->theData[59]));
   EnvReleaseMem(theEnvironment,-1,0);
   for (i = 0; i < 100; i++)
     {
      if (theEnvironment->cleanupFunctions[i] != ((void *)0))
        { (*theEnvironment->cleanupFunctions[i])(theEnvironment); }
     }
   free(theEnvironment->cleanupFunctions);
   for (cleanupPtr = theEnvironment->listOfCleanupEnvironmentFunctions;
        cleanupPtr != ((void *)0);
        cleanupPtr = cleanupPtr->next)
     { (*cleanupPtr->func)(theEnvironment); }
   RemoveEnvironmentCleanupFunctions(theEnvironment);
   EnvReleaseMem(theEnvironment,-1,0);
   RemoveHashedEnvironment(theEnvironment);
   if ((theMemData->MemoryAmount != 0) || (theMemData->MemoryCalls != 0))
     {
      printf("\n[ENVRNMNT8] Environment data not fully deallocated.\n");
      rv = 0;
     }
   free(theMemData->MemoryTable);
   for (i = 0; i < 100; i++)
     {
      if (theEnvironment->theData[i] != ((void *)0))
        {
         free(theEnvironment->theData[i]);
         theEnvironment->theData[i] = ((void *)0);
        }
     }
   free(theEnvironment->theData);
   if (CurrentEnvironment == theEnvironment)
     { CurrentEnvironment = ((void *)0); }
   free(theEnvironment);
   return(rv);
  }

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

variable_types: rv int

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 evaluationData { struct expr *CurrentExpression; int EvaluationError; int HaltExecution; int CurrentEvaluationDepth; struct entityRecord *PrimitivesArray[150]; }

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

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

user_defined_types: struct userData { unsigned char dataID; struct userData *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 dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; }

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

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


DeallocateEnvironmentData

decompiled_code:
__int64 DeallocateEnvironmentData()
{
__int64 v0; // r13
unsigned int v1; // er12
char *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v0 = 0LL;
v1 = 1;
v2 = (char *)EnvironmentHashTable;
do
{
v3 = *(_QWORD **)&v2[v0];
if ( v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[7];
if ( !(unsigned int)DestroyEnvironment(v4) )
v1 = 0;
}
while ( v3 );
v2 = (char *)EnvironmentHashTable;
}
v0 += 8LL;
}
while ( v0 != 1048 );
free(v2);
return v1;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 v0; // r13
unsigned int v1; // er12
char *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v0 = 0LL;
v1 = 1;
v2 = (char *)EnvironmentHashTable;
do
{
v3 = *(_QWORD **)&v2[v0];
if ( v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[7];
if ( !(unsigned int)func16(v4) )
v1 = 0;
}
while ( v3 );
v2 = (char *)EnvironmentHashTable;
}
v0 += 8LL;
}
while ( v0 != 1048 );
free(v2);
return v1;
}

original_code:
int DeallocateEnvironmentData()
  {
   struct environmentData *theEnvironment, *nextEnvironment;
   int i, rv = 1;
   for (i = 0; i < 131; i++)
     {
      for (theEnvironment = EnvironmentHashTable[i];
           theEnvironment != ((void *)0);
          )
        {
         nextEnvironment = theEnvironment->next;
         if (! DestroyEnvironment(theEnvironment))
           { rv = 0; }
         theEnvironment = nextEnvironment;
        }
     }
   free(EnvironmentHashTable);
   return(rv);
  }

canonical_original_code:
int DeallocateEnvironmentData()
  {
   struct environmentData *theEnvironment; struct environmentData *nextEnvironment;
   int i; int rv = 1;
   for (i = 0; i < 131; i++)
     {
      for (theEnvironment = EnvironmentHashTable[i];
           theEnvironment != ((void *)0);
          )
        {
         nextEnvironment = theEnvironment->next;
         if (! DestroyEnvironment(theEnvironment))
           { rv = 0; }
         theEnvironment = nextEnvironment;
        }
     }
   free(EnvironmentHashTable);
   return(rv);
  }

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


AddEnvironmentCleanupFunction

original_code:
int AddEnvironmentCleanupFunction(
  void *vtheEnv,
  char *name,
  void (*functionPtr)(void *),
  int priority)
  {
   struct environmentCleanupFunction *newPtr, *currentPtr, *lastPtr = ((void *)0);
   struct environmentData *theEnv = (struct environmentData *) vtheEnv;
   newPtr = (struct environmentCleanupFunction *) malloc(sizeof(struct environmentCleanupFunction));
   if (newPtr == ((void *)0))
     { return(0); }
   newPtr->name = name;
   newPtr->func = functionPtr;
   newPtr->priority = priority;
   if (theEnv->listOfCleanupEnvironmentFunctions == ((void *)0))
     {
      newPtr->next = ((void *)0);
      theEnv->listOfCleanupEnvironmentFunctions = newPtr;
      return(1);
     }
   currentPtr = theEnv->listOfCleanupEnvironmentFunctions;
   while ((currentPtr != ((void *)0)) ? (priority < currentPtr->priority) : 0)
     {
      lastPtr = currentPtr;
      currentPtr = currentPtr->next;
     }
   if (lastPtr == ((void *)0))
     {
      newPtr->next = theEnv->listOfCleanupEnvironmentFunctions;
      theEnv->listOfCleanupEnvironmentFunctions = newPtr;
     }
   else
     {
      newPtr->next = currentPtr;
      lastPtr->next = newPtr;
     }
   return(1);
  }

canonical_original_code:
int AddEnvironmentCleanupFunction(void *vtheEnv, char *name, void (*functionPtr)(void *), int priority)
  {
   struct environmentCleanupFunction *newPtr; struct environmentCleanupFunction *currentPtr; struct environmentCleanupFunction *lastPtr = ((void *)0);
   struct environmentData *theEnv = (struct environmentData *) vtheEnv;
   newPtr = (struct environmentCleanupFunction *) malloc(sizeof(struct environmentCleanupFunction));
   if (newPtr == ((void *)0))
     { return(0); }
   newPtr->name = name;
   newPtr->func = functionPtr;
   newPtr->priority = priority;
   if (theEnv->listOfCleanupEnvironmentFunctions == ((void *)0))
     {
      newPtr->next = ((void *)0);
      theEnv->listOfCleanupEnvironmentFunctions = newPtr;
      return(1);
     }
   currentPtr = theEnv->listOfCleanupEnvironmentFunctions;
   while ((currentPtr != ((void *)0)) ? (priority < currentPtr->priority) : 0)
     {
      lastPtr = currentPtr;
      currentPtr = currentPtr->next;
     }
   if (lastPtr == ((void *)0))
     {
      newPtr->next = theEnv->listOfCleanupEnvironmentFunctions;
      theEnv->listOfCleanupEnvironmentFunctions = newPtr;
     }
   else
     {
      newPtr->next = currentPtr;
      lastPtr->next = newPtr;
     }
   return(1);
  }

variable_types:
vtheEnv
void *

variable_types:
name
char *

variable_types:
functionPtr
void (*)(void *)

variable_types: priority int


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

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

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 *

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

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


ReplaceInstanceVariables

decompiled_code:
int __fastcall ReplaceInstanceVariables(__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-instance)");
v16 = FindFunction(a1, "(query-instance-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) = ReplaceInstanceVariables(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 ReplaceInstanceVariables(
  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-instance)");
   rslot_func = FindFunction(theEnv,"(query-instance-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))
           ReplaceInstanceVariables(theEnv,vlist,bexp->argList,sdirect,ndepth+1);
         else
           ReplaceInstanceVariables(theEnv,vlist,bexp->argList,sdirect,ndepth);
        }
      bexp = bexp->nextArg;
     }
  }

canonical_original_code:
static void ReplaceInstanceVariables(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-instance)");
   rslot_func = FindFunction(theEnv,"(query-instance-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))
           ReplaceInstanceVariables(theEnv,vlist,bexp->argList,sdirect,ndepth+1);
         else
           ReplaceInstanceVariables(theEnv,vlist,bexp->argList,sdirect,ndepth);
        }
      bexp = bexp->nextArg;
     }
  }

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


ParseQueryNoAction

decompiled_code:
__int64 __fastcall ParseQueryNoAction(__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 )
{
ReplaceInstanceVariables(a1, v5, *(_QWORD *)(a2 + 16), 1u, 0);
v6 = v5;
v5 = a2;
}
else
{
SyntaxErrorMessage(a1, "instance-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, "instance-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 *ParseQueryNoAction(
  void *theEnv,
  EXPRESSION *top,
  char *readSource)
  {
   EXPRESSION *insQuerySetVars;
   struct token queryInputToken;
   insQuerySetVars = ParseQueryRestrictions(theEnv,top,readSource,&queryInputToken);
   if (insQuerySetVars == ((void *)0))
     return(((void *)0));
   IncrementIndentDepth(theEnv,3);
   PPCRAndIndent(theEnv);
   if (ParseQueryTestExpression(theEnv,top,readSource) == 0)
     {
      DecrementIndentDepth(theEnv,3);
      ReturnExpression(theEnv,insQuerySetVars);
      return(((void *)0));
     }
   DecrementIndentDepth(theEnv,3);
   GetToken(theEnv,readSource,&queryInputToken);
   if (((queryInputToken).type) != 171)
     {
      SyntaxErrorMessage(theEnv,"instance-set query function");
      ReturnExpression(theEnv,top);
      ReturnExpression(theEnv,insQuerySetVars);
      return(((void *)0));
     }
   ReplaceInstanceVariables(theEnv,insQuerySetVars,top->argList,1,0);
   ReturnExpression(theEnv,insQuerySetVars);
   return(top);
  }

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

variable_types:
top
struct expr *

variable_types:
readSource
char *

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

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