decompiled_code:
void __fastcall clock_stop(__int64 a1)
{
int v1; // eax
int v2; // eax
struct rusage v3; // [rsp+0h] [rbp-98h] BYREF

if ( Clocks_enabled )
{
v1 = *(_DWORD *)(a1 + 16);
if ( v1 <= 0 )
{
fprintf(stderr, "WARNING, clock_stop: clock %s not running.\n", *(const char **)a1);
}
else
{
v2 = v1 - 1;
*(_DWORD *)(a1 + 16) = v2;
if ( !v2 )
{
getrusage(RUSAGE_SELF, &v3);
*(_DWORD *)(a1 + 8) = *(_DWORD *)(a1 + 8)
+ v3.ru_utime.tv_usec / 1000
+ 1000 * LODWORD(v3.ru_utime.tv_sec)
- *(_DWORD *)(a1 + 12);
}
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
int v1; // eax
int v2; // eax
struct rusage v3; // [rsp+0h] [rbp-98h] BYREF

if ( Clocks_enabled )
{
v1 = *(_DWORD *)(a1 + 16);
if ( v1 <= 0 )
{
fprintf(stderr, "WARNING, clock_stop: clock %s not running.\n", *(const char **)a1);
}
else
{
v2 = v1 - 1;
*(_DWORD *)(a1 + 16) = v2;
if ( !v2 )
{
getrusage(RUSAGE_SELF, &v3);
*(_DWORD *)(a1 + 8) = *(_DWORD *)(a1 + 8)
+ v3.ru_utime.tv_usec / 1000
+ 1000 * LODWORD(v3.ru_utime.tv_sec)
- *(_DWORD *)(a1 + 12);
}
}
}
}

original_code:
void clock_stop(Clock p)
{
  if (Clocks_enabled) {
    if (p->level <= 0)
      fprintf(stderr,"WARNING, clock_stop: clock %s not running.\n",p->name);
    else {
      p->level--;
      if (p->level == 0) {
 unsigned msec;
 { struct rusage r; getrusage(RUSAGE_SELF, &r); msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
 p->accum_msec += msec - p->curr_msec;
      }
    }
  }
}

canonical_original_code:
void clock_stop(struct clock *p)
{
  if (Clocks_enabled) {
    if (p->level <= 0)
      fprintf(stderr,"WARNING, clock_stop: clock %s not running.\n",p->name);
    else {
      p->level--;
      if (p->level == 0) {
 unsigned int msec;
 { struct rusage r; getrusage(RUSAGE_SELF, &r); msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
 p->accum_msec += msec - p->curr_msec;
      }
    }
  }
}

variable_types:
msec
unsigned int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


repo: jessealama/ladr

decompiled_code:
__int64 __fastcall clock_milliseconds(_DWORD *a1)
{
unsigned int v1; // ebp
struct rusage v3; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
return 0;
v1 = a1[2];
if ( a1[4] )
{
getrusage(RUSAGE_SELF, &v3);
v1 = 1000 * LODWORD(v3.ru_utime.tv_sec) + SLODWORD(v3.ru_utime.tv_usec) / 1000 + v1 - a1[3];
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1)
{
unsigned int v1; // ebp
struct rusage v3; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
return 0;
v1 = a1[2];
if ( a1[4] )
{
getrusage(RUSAGE_SELF, &v3);
v1 = 1000 * LODWORD(v3.ru_utime.tv_sec) + SLODWORD(v3.ru_utime.tv_usec) / 1000 + v1 - a1[3];
}
return v1;
}

original_code:
unsigned clock_milliseconds(Clock p)
{
  if (p == ((void *)0))
    return 0;
  else {
    int i = p->accum_msec;
    if (p->level == 0)
      return i;
    else {
      int msec;
      { struct rusage r; getrusage(RUSAGE_SELF, &r); msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
      return i + (msec - p->curr_msec);
    }
  }
}

canonical_original_code:
unsigned int clock_milliseconds(struct clock *p)
{
  if (p == ((void *)0))
    return 0;
  else {
    int i = p->accum_msec;
    if (p->level == 0)
      return i;
    else {
      int msec;
      { struct rusage r; getrusage(RUSAGE_SELF, &r); msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
      return i + (msec - p->curr_msec);
    }
  }
}

variable_types: struct clock { char *name; unsigned int accum_msec; unsigned int curr_msec; int level; } *

variable_types: i int

variable_types: msec int

variable_types: struct rusage { struct timeval { long tv_sec; long tv_usec; } ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }

return_type: unsigned int

user_defined_types: struct rusage { struct timeval ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }


decompiled_code:
double __fastcall clock_seconds(_DWORD *a1)
{
int v1; // ebp
struct rusage v3; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
return 0.0;
v1 = a1[2];
if ( !a1[4] )
return (double)v1 / 1000.0;
getrusage(RUSAGE_SELF, &v3);
return (double)(1000 * LODWORD(v3.ru_utime.tv_sec) + SLODWORD(v3.ru_utime.tv_usec) / 1000 + v1 - a1[3]) / 1000.0;
}

canonical_decompiled_code:
double __fastcall func6(_DWORD *a1)
{
int v1; // ebp
struct rusage v3; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
return 0.0;
v1 = a1[2];
if ( !a1[4] )
return (double)v1 / 1000.0;
getrusage(RUSAGE_SELF, &v3);
return (double)(1000 * LODWORD(v3.ru_utime.tv_sec) + SLODWORD(v3.ru_utime.tv_usec) / 1000 + v1 - a1[3]) / 1000.0;
}

original_code:
double clock_seconds(Clock p)
{
  if (p == ((void *)0))
    return 0.0;
  else {
    int i = p->accum_msec;
    if (p->level == 0)
      return (i / 1000.0);
    else {
      int msec;
      { struct rusage r; getrusage(RUSAGE_SELF, &r); msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
      return (i + (msec - p->curr_msec)) / 1000.0;
    }
  }
}

canonical_original_code:
double clock_seconds(struct clock *p)
{
  if (p == ((void *)0))
    return 0.0;
  else {
    int i = p->accum_msec;
    if (p->level == 0)
      return (i / 1000.0);
    else {
      int msec;
      { struct rusage r; getrusage(RUSAGE_SELF, &r); msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
      return (i + (msec - p->curr_msec)) / 1000.0;
    }
  }
}

return_type: double

user_defined_types: struct clock { char *name; unsigned int accum_msec; unsigned int curr_msec; int level; }


decompiled_code:
_BOOL8 __fastcall clock_running(__int64 a1)
{
return *(_DWORD *)(a1 + 16) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return *(_DWORD *)(a1 + 16) > 0;
}

original_code:
BOOL clock_running(Clock p)
{
  return p->level > 0;
}

canonical_original_code:
enum BOOL clock_running(struct clock *p)
{
  return p->level > 0;
}

return_type: enum BOOL { FALSE=0, TRUE=1 }


original_code:
void clock_reset(Clock p)
{
  if (p != ((void *)0)) {
    p->level = 0;
    p->accum_msec = 0;
  }
}

canonical_original_code:
void clock_reset(struct clock *p)
{
  if (p != ((void *)0)) {
    p->level = 0;
    p->accum_msec = 0;
  }
}

return_type: void


decompiled_code:
char *get_date()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
return asctime(v0);
}

canonical_decompiled_code:
char *func10()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
return asctime(v0);
}

original_code:
char * get_date(void)
{
  time_t i = time(((void *)0));
  return asctime(localtime(&i));
}

canonical_original_code:
char *get_date()
{
  long i = time(((void *)0));
  return asctime(localtime(&i));
}

variable_types: i long

return_type: char *


decompiled_code:
__int64 user_time()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return 1000 * LODWORD(v1.ru_utime.tv_sec) + LODWORD(v1.ru_utime.tv_usec) / 0x3E8;
}

canonical_decompiled_code:
__int64 func11()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return 1000 * LODWORD(v1.ru_utime.tv_sec) + LODWORD(v1.ru_utime.tv_usec) / 0x3E8;
}

original_code:
unsigned user_time()
{
  struct rusage r;
  unsigned sec, usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_utime.tv_sec;
  usec = r.ru_utime.tv_usec;
  return((sec * 1000) + (usec / 1000));
}

canonical_original_code:
unsigned int user_time()
{
  struct rusage r;
  unsigned int sec; unsigned int usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_utime.tv_sec;
  usec = r.ru_utime.tv_usec;
  return((sec * 1000) + (usec / 1000));
}

variable_types:
sec
unsigned int

variable_types:
usec
unsigned int


decompiled_code:
double user_seconds()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return (double)SLODWORD(v1.ru_utime.tv_usec) / 1000000.0 + (double)SLODWORD(v1.ru_utime.tv_sec);
}

canonical_decompiled_code:
double func12()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return (double)SLODWORD(v1.ru_utime.tv_usec) / 1000000.0 + (double)SLODWORD(v1.ru_utime.tv_sec);
}

original_code:
double user_seconds()
{
  struct rusage r;
  unsigned sec, usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_utime.tv_sec;
  usec = r.ru_utime.tv_usec;
  return(sec + (usec / 1000000.0));
}

canonical_original_code:
double user_seconds()
{
  struct rusage r;
  unsigned int sec; unsigned int usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_utime.tv_sec;
  usec = r.ru_utime.tv_usec;
  return(sec + (usec / 1000000.0));
}


decompiled_code:
__int64 system_time()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return 1000 * LODWORD(v1.ru_stime.tv_sec) + LODWORD(v1.ru_stime.tv_usec) / 0x3E8;
}

canonical_decompiled_code:
__int64 func13()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return 1000 * LODWORD(v1.ru_stime.tv_sec) + LODWORD(v1.ru_stime.tv_usec) / 0x3E8;
}

original_code:
unsigned system_time()
{
  struct rusage r;
  unsigned sec, usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_stime.tv_sec;
  usec = r.ru_stime.tv_usec;
  return((sec * 1000) + (usec / 1000));
}

canonical_original_code:
unsigned int system_time()
{
  struct rusage r;
  unsigned int sec; unsigned int usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_stime.tv_sec;
  usec = r.ru_stime.tv_usec;
  return((sec * 1000) + (usec / 1000));
}


decompiled_code:
double system_seconds()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return (double)SLODWORD(v1.ru_stime.tv_usec) / 1000000.0 + (double)SLODWORD(v1.ru_stime.tv_sec);
}

canonical_decompiled_code:
double func14()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
return (double)SLODWORD(v1.ru_stime.tv_usec) / 1000000.0 + (double)SLODWORD(v1.ru_stime.tv_sec);
}

original_code:
double system_seconds()
{
  struct rusage r;
  unsigned sec, usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_stime.tv_sec;
  usec = r.ru_stime.tv_usec;
  return(sec + (usec / 1000000.0));
}

canonical_original_code:
double system_seconds()
{
  struct rusage r;
  unsigned int sec; unsigned int usec;
  getrusage(RUSAGE_SELF, &r);
  sec = r.ru_stime.tv_sec;
  usec = r.ru_stime.tv_usec;
  return(sec + (usec / 1000000.0));
}


decompiled_code:
time_t absolute_wallclock()
{
return time(0LL);
}

canonical_decompiled_code:
time_t func15()
{
return time(0LL);
}

original_code:
unsigned absolute_wallclock(void)
{
  time_t t = time((time_t *) ((void *)0));
  return (unsigned) t;
}

canonical_original_code:
unsigned int absolute_wallclock()
{
  long t = time((time_t *) ((void *)0));
  return (unsigned int) t;
}

variable_types: t long


decompiled_code:
time_t init_wallclock()
{
time_t result; // rax

result = absolute_wallclock();
Wall_start = result;
return result;
}

canonical_decompiled_code:
time_t func16()
{
time_t result; // rax

result = func15();
Wall_start = result;
return result;
}

original_code:
void init_wallclock()
{
  Wall_start = absolute_wallclock();
}


wallclock

decompiled_code:
__int64 wallclock()
{
return (unsigned int)absolute_wallclock() - Wall_start;
}

canonical_decompiled_code:
__int64 func17()
{
return (unsigned int)func15() - Wall_start;
}

original_code:
unsigned wallclock()
{
  return absolute_wallclock() - Wall_start;
}

canonical_original_code:
unsigned int wallclock()
{
  return absolute_wallclock() - Wall_start;
}


decompiled_code:
void disable_clocks()
{
Clocks_enabled = 0;
}

canonical_decompiled_code:
void func18()
{
Clocks_enabled = 0;
}

original_code:
void disable_clocks(void)
{
  Clocks_enabled = FALSE;
}

canonical_original_code:
void disable_clocks()
{
  Clocks_enabled = FALSE;
}


decompiled_code:
void enable_clocks()
{
Clocks_enabled = 1;
}

canonical_decompiled_code:
void func19()
{
Clocks_enabled = 1;
}

original_code:
void enable_clocks(void)
{
  Clocks_enabled = TRUE;
}

canonical_original_code:
void enable_clocks()
{
  Clocks_enabled = TRUE;
}


decompiled_code:
__int64 clocks_enabled()
{
return (unsigned int)Clocks_enabled;
}

canonical_decompiled_code:
__int64 func20()
{
return (unsigned int)Clocks_enabled;
}

original_code:
BOOL clocks_enabled(void)
{
  return Clocks_enabled;
}

canonical_original_code:
enum BOOL clocks_enabled()
{
  return Clocks_enabled;
}


decompiled_code:
__int64 __fastcall random_term(int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6)
{
int v8; // eax
int v9; // ecx
int v10; // edx
unsigned int v11; // eax
__int64 v12; // r13
unsigned int v13; // esi
__int64 v14; // rcx
int v15; // er15
__int16 *v16; // rdx
__int64 v17; // rbx
_QWORD *v18; // r14
unsigned int v23; // [rsp+Ch] [rbp-7Ch]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

if ( a6 )
{
v8 = rand();
v9 = a5 + a4 + a3 + a1 + a2;
}
else
{
v8 = rand();
v9 = a1 + a2;
}
v10 = v8 % v9;
if ( v8 % v9 < a1 )
return get_variable_term((unsigned int)v10);
v11 = a1 + a2;
if ( (int)(a1 + a2) <= v10 )
{
v13 = v11 + a3;
if ( (int)(v11 + a3) <= v10 )
{
if ( (int)(v13 + a4) <= v10 )
{
v14 = v10 - (v13 + a4);
v15 = 3;
v16 = aHfga;
}
else
{
v14 = v10 - v13;
v15 = 2;
v16 = &aHfga[1];
}
}
else
{
v14 = v10 - v11;
v15 = 1;
v16 = &aHfga[2];
}
sprintf(s, "%s%d", (const char *)v16, v14);
v12 = get_rigid_term(s, (unsigned int)v15);
v17 = 0LL;
v23 = a6 - 1;
do
{
v18 = (_QWORD *)(*(_QWORD *)(v12 + 8) + 8 * v17);
*v18 = random_term((unsigned int)a1, a2, a3, a4, a5, v23);
++v17;
}
while ( v15 > (int)v17 );
}
else
{
sprintf(s, "%s%d", (const char *)&aHfga[3], (unsigned int)(v10 - a1));
v12 = get_rigid_term(s, 0LL);
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6)
{
int v8; // eax
int v9; // ecx
int v10; // edx
unsigned int v11; // eax
__int64 v12; // r13
unsigned int v13; // esi
__int64 v14; // rcx
int v15; // er15
__int16 *v16; // rdx
__int64 v17; // rbx
_QWORD *v18; // r14
unsigned int v23; // [rsp+Ch] [rbp-7Ch]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

if ( a6 )
{
v8 = rand();
v9 = a5 + a4 + a3 + a1 + a2;
}
else
{
v8 = rand();
v9 = a1 + a2;
}
v10 = v8 % v9;
if ( v8 % v9 < a1 )
return get_variable_term((unsigned int)v10);
v11 = a1 + a2;
if ( (int)(a1 + a2) <= v10 )
{
v13 = v11 + a3;
if ( (int)(v11 + a3) <= v10 )
{
if ( (int)(v13 + a4) <= v10 )
{
v14 = v10 - (v13 + a4);
v15 = 3;
v16 = aHfga;
}
else
{
v14 = v10 - v13;
v15 = 2;
v16 = &aHfga[1];
}
}
else
{
v14 = v10 - v11;
v15 = 1;
v16 = &aHfga[2];
}
sprintf(s, "%s%d", (const char *)v16, v14);
v12 = get_rigid_term(s, (unsigned int)v15);
v17 = 0LL;
v23 = a6 - 1;
do
{
v18 = (_QWORD *)(*(_QWORD *)(v12 + 8) + 8 * v17);
*v18 = func0((unsigned int)a1, a2, a3, a4, a5, v23);
++v17;
}
while ( v15 > (int)v17 );
}
else
{
sprintf(s, "%s%d", (const char *)&aHfga[3], (unsigned int)(v10 - a1));
v12 = get_rigid_term(s, 0LL);
}
return v12;
}

original_code:
Term random_term(int v, int a0, int a1, int a2, int a3,
   int max_depth)
{
  int n, arity, j;
  char *s, symbol[51];
  if (max_depth == 0)
    n = rand() % (v+a0);
  else
    n = rand() % (v+a0+a1+a2+a3);
  if (n < v) {
    arity = -1;
    j = n;
  }
  else if (n < v+a0) {
    arity = 0;
    j = n - v;
  }
  else if (n < v+a0+a1) {
    arity = 1;
    j = n - (v+a0);
  }
  else if (n < v+a0+a1+a2) {
    arity = 2;
    j = n - (v+a0+a1);
  }
  else {
    arity = 3;
    j = n - (v+a0+a1+a2);
  }
  if (arity == -1) {
    return get_variable_term(j);
  }
  else {
    int i;
    Term t;
    switch (arity) {
    case 0: s = "a"; break;
    case 1: s = "g"; break;
    case 2: s = "f"; break;
    case 3: s = "h"; break;
    default: s = "?"; break;
    }
    sprintf(symbol, "%s%d", s, j);
    t = get_rigid_term(symbol, arity);
    for (i = 0; i < arity; i++)
      ((t)->args[i]) = random_term(v, a0, a1, a2, a3, max_depth-1);
    return t;
  }
}

canonical_original_code:
struct term *random_term(int v, int a0, int a1, int a2, int a3, int max_depth)
{
  int n; int arity; int j;
  char *s; char symbol[51];
  if (max_depth == 0)
    n = rand() % (v+a0);
  else
    n = rand() % (v+a0+a1+a2+a3);
  if (n < v) {
    arity = -1;
    j = n;
  }
  else if (n < v+a0) {
    arity = 0;
    j = n - v;
  }
  else if (n < v+a0+a1) {
    arity = 1;
    j = n - (v+a0);
  }
  else if (n < v+a0+a1+a2) {
    arity = 2;
    j = n - (v+a0+a1);
  }
  else {
    arity = 3;
    j = n - (v+a0+a1+a2);
  }
  if (arity == -1) {
    return get_variable_term(j);
  }
  else {
    int i;
    struct term *t;
    switch (arity) {
    case 0: s = "a"; break;
    case 1: s = "g"; break;
    case 2: s = "f"; break;
    case 3: s = "h"; break;
    default: s = "?"; break;
    }
    sprintf(symbol, "%s%d", s, j);
    t = get_rigid_term(symbol, arity);
    for (i = 0; i < arity; i++)
      ((t)->args[i]) = random_term(v, a0, a1, a2, a3, max_depth-1);
    return t;
  }
}

variable_types: v int

variable_types: n int

variable_types: arity int

variable_types: j int

variable_types:
s
char *

variable_types:
symbol
char [51]

variable_types: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *


decompiled_code:
int *__fastcall random_nonvariable_term(int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6)
{
int *i; // rdi

for ( i = (int *)random_term(a1, a2, a3, a4, a5, a6); *i >= 0; i = (int *)random_term(a1, a2, a3, a4, a5, a6) )
zap_term(i);
return i;
}

canonical_decompiled_code:
int *__fastcall func1(int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6)
{
int *i; // rdi

for ( i = (int *)func0(a1, a2, a3, a4, a5, a6); *i >= 0; i = (int *)func0(a1, a2, a3, a4, a5, a6) )
zap_term(i);
return i;
}

original_code:
Term random_nonvariable_term(int v, int a0, int a1, int a2, int a3,
        int max_depth)
{
  Term t = random_term(v, a0, a1, a2, a3, max_depth);
  while (((t)->private_symbol >= 0)) {
    zap_term(t);
    t = random_term(v, a0, a1, a2, a3, max_depth);
  }
  return t;
}

canonical_original_code:
struct term *random_nonvariable_term(int v, int a0, int a1, int a2, int a3, int max_depth)
{
  struct term *t = random_term(v, a0, a1, a2, a3, max_depth);
  while (((t)->private_symbol >= 0)) {
    zap_term(t);
    t = random_term(v, a0, a1, a2, a3, max_depth);
  }
  return t;
}

return_type: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *


decompiled_code:
__int64 __fastcall random_complex_term(int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6)
{
__int64 i; // rdi

for ( i = random_term(a1, a2, a3, a4, a5, a6);
*(int *)i >= 0 || !*(_BYTE *)(i + 4);
i = random_term(a1, a2, a3, a4, a5, a6) )
{
zap_term(i);
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6)
{
__int64 i; // rdi

for ( i = func0(a1, a2, a3, a4, a5, a6);
*(int *)i >= 0 || !*(_BYTE *)(i + 4);
i = func0(a1, a2, a3, a4, a5, a6) )
{
zap_term(i);
}
return i;
}

original_code:
Term random_complex_term(int v, int a0, int a1, int a2, int a3,
        int max_depth)
{
  Term t = random_term(v, a0, a1, a2, a3, max_depth);
  while (((t)->private_symbol >= 0)|| ((t)->private_symbol < 0 && (t)->arity == 0)) {
    zap_term(t);
    t = random_term(v, a0, a1, a2, a3, max_depth);
  }
  return t;
}

canonical_original_code:
struct term *random_complex_term(int v, int a0, int a1, int a2, int a3, int max_depth)
{
  struct term *t = random_term(v, a0, a1, a2, a3, max_depth);
  while (((t)->private_symbol >= 0)|| ((t)->private_symbol < 0 && (t)->arity == 0)) {
    zap_term(t);
    t = random_term(v, a0, a1, a2, a3, max_depth);
  }
  return t;
}

user_defined_types: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; }


original_code:
Ilist random_path(int length_max, int value_max)
{
  Ilist first, current, new;
  int length = (rand() % length_max) + 1;
  int i, value;
  first = current = ((void *)0);
  for (i = 0; i < length; i++) {
    value = (rand() % value_max) + 1;
    new = get_ilist();
    new->i = value;
    new->next = ((void *)0);
    if (first == ((void *)0))
      first = new;
    else
      current->next = new;
    current = new;
  }
  return first;
}

canonical_original_code:
struct ilist *random_path(int length_max, int value_max)
{
  struct ilist *first; struct ilist *current; struct ilist *new;
  int length = (rand() % length_max) + 1;
  int i; int value;
  first = current = ((void *)0);
  for (i = 0; i < length; i++) {
    value = (rand() % value_max) + 1;
    new = get_ilist();
    new->i = value;
    new->next = ((void *)0);
    if (first == ((void *)0))
      first = new;
    else
      current->next = new;
    current = new;
  }
  return first;
}

variable_types: struct ilist { int i; struct ilist *next; } *

variable_types: length int

variable_types: value int


decompiled_code:
__int64 __fastcall random_op_term(int a1)
{
__int64 v1; // rbp
int v2; // er12
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbx
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v11; // rax
__int64 v12; // r13
__int64 v13; // r12
_QWORD *v14; // r14

if ( !initialized_1 )
{
symnum_0[0] = str_to_sn(&aHfga[3], 0LL);
dword_6C4 = str_to_sn("->", 2LL);
dword_6C8 = str_to_sn(asc_71C, 2LL);
dword_6CC = str_to_sn(&asc_71C[1], 2LL);
dword_6D0 = str_to_sn(&asc_71C[2], 1LL);
dword_6D4 = str_to_sn(&asc_71C[3], 2LL);
dword_6D8 = str_to_sn(&asc_71C[4], 2LL);
dword_6DC = str_to_sn(&asc_71C[5], 2LL);
dword_6E0 = str_to_sn(&asc_71C[6], 1LL);
dword_6E4 = str_to_sn("$cons", 2LL);
dword_6E8 = str_to_sn("$nil", 0LL);
dword_6EC = str_to_sn("$quantified", 1LL);
dword_6F0 = str_to_sn(&aHfga[1], 2LL);
initialized_1 = 1;
}
if ( !a1 )
return get_rigid_term("b", 0LL);
v1 = (unsigned int)symnum_0[rand() % 13];
v2 = sn_to_arity(v1);
if ( (unsigned int)is_symbol((unsigned int)v1, "$quantified", 1LL) )
{
v3 = get_rigid_term("$quantified", 1LL);
v4 = get_rigid_term("all", 0LL);
v5 = get_rigid_term("x", 0LL);
v6 = random_op_term((unsigned int)(a1 - 1));
v7 = get_nil_term();
v8 = listterm_cons(v6, v7);
v9 = listterm_cons(v5, v8);
**(_QWORD **)(v3 + 8) = listterm_cons(v4, v9);
}
else
{
v11 = sn_to_str((unsigned int)v1);
v3 = get_rigid_term(v11, (unsigned int)v2);
if ( v2 > 0 )
{
v12 = 8LL * (unsigned int)v2;
v13 = 0LL;
do
{
v14 = (_QWORD *)(*(_QWORD *)(v3 + 8) + v13);
*v14 = random_op_term((unsigned int)(a1 - 1));
v13 += 8LL;
}
while ( v13 != v12 );
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // rbp
int v2; // er12
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbx
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v11; // rax
__int64 v12; // r13
__int64 v13; // r12
_QWORD *v14; // r14

if ( !initialized_1 )
{
symnum_0[0] = str_to_sn(&aHfga[3], 0LL);
dword_6C4 = str_to_sn("->", 2LL);
dword_6C8 = str_to_sn(asc_71C, 2LL);
dword_6CC = str_to_sn(&asc_71C[1], 2LL);
dword_6D0 = str_to_sn(&asc_71C[2], 1LL);
dword_6D4 = str_to_sn(&asc_71C[3], 2LL);
dword_6D8 = str_to_sn(&asc_71C[4], 2LL);
dword_6DC = str_to_sn(&asc_71C[5], 2LL);
dword_6E0 = str_to_sn(&asc_71C[6], 1LL);
dword_6E4 = str_to_sn("$cons", 2LL);
dword_6E8 = str_to_sn("$nil", 0LL);
dword_6EC = str_to_sn("$quantified", 1LL);
dword_6F0 = str_to_sn(&aHfga[1], 2LL);
initialized_1 = 1;
}
if ( !a1 )
return get_rigid_term("b", 0LL);
v1 = (unsigned int)symnum_0[rand() % 13];
v2 = sn_to_arity(v1);
if ( (unsigned int)is_symbol((unsigned int)v1, "$quantified", 1LL) )
{
v3 = get_rigid_term("$quantified", 1LL);
v4 = get_rigid_term("all", 0LL);
v5 = get_rigid_term("x", 0LL);
v6 = func6((unsigned int)(a1 - 1));
v7 = get_nil_term();
v8 = listterm_cons(v6, v7);
v9 = listterm_cons(v5, v8);
**(_QWORD **)(v3 + 8) = listterm_cons(v4, v9);
}
else
{
v11 = sn_to_str((unsigned int)v1);
v3 = get_rigid_term(v11, (unsigned int)v2);
if ( v2 > 0 )
{
v12 = 8LL * (unsigned int)v2;
v13 = 0LL;
do
{
v14 = (_QWORD *)(*(_QWORD *)(v3 + 8) + v13);
*v14 = func6((unsigned int)(a1 - 1));
v13 += 8LL;
}
while ( v13 != v12 );
}
}
return v3;
}

original_code:
Term random_op_term(int depth)
{
  static int initialized = 0;
  static int symnum[13];
  if (!initialized) {
    symnum[0] = str_to_sn("a", 0);
    symnum[1] = str_to_sn("->", 2);
    symnum[2] = str_to_sn("|", 2);
    symnum[3] = str_to_sn("&", 2);
    symnum[4] = str_to_sn("~", 1);
    symnum[5] = str_to_sn("=", 2);
    symnum[6] = str_to_sn("+", 2);
    symnum[7] = str_to_sn("*", 2);
    symnum[8] = str_to_sn("\'", 1);
    symnum[9] = str_to_sn("$cons", 2);
    symnum[10] = str_to_sn("$nil", 0);
    symnum[11] = str_to_sn("$quantified", 1);
    symnum[12] = str_to_sn("f", 2);
    initialized = 1;
  }
  if (depth == 0)
    return get_rigid_term("b", 0);
  else {
    Term t;
    int arity, i, sn;
    sn = symnum[rand() % 13];
    arity = sn_to_arity(sn);
    if (is_symbol(sn, "$quantified", 1)) {
      Term q = get_rigid_term("$quantified", 1);
      Term a = get_rigid_term("all", 0);
      Term x = get_rigid_term("x", 0);
      Term r = random_op_term(depth-1);
      Term t = get_nil_term();
      t = listterm_cons(r, t);
      t = listterm_cons(x, t);
      t = listterm_cons(a, t);
      ((q)->args[0]) = t;
      return q;
    }
    else {
      t = get_rigid_term(sn_to_str(sn), arity);
      for (i = 0; i < arity; i++)
 ((t)->args[i]) = random_op_term(depth-1);
      return t;
    }
  }
}

canonical_original_code:
struct term *random_op_term(int depth)
{
  static int initialized = 0;
  static int symnum[13];
  if (!initialized) {
    symnum[0] = str_to_sn("a", 0);
    symnum[1] = str_to_sn("->", 2);
    symnum[2] = str_to_sn("|", 2);
    symnum[3] = str_to_sn("&", 2);
    symnum[4] = str_to_sn("~", 1);
    symnum[5] = str_to_sn("=", 2);
    symnum[6] = str_to_sn("+", 2);
    symnum[7] = str_to_sn("*", 2);
    symnum[8] = str_to_sn("\'", 1);
    symnum[9] = str_to_sn("$cons", 2);
    symnum[10] = str_to_sn("$nil", 0);
    symnum[11] = str_to_sn("$quantified", 1);
    symnum[12] = str_to_sn("f", 2);
    initialized = 1;
  }
  if (depth == 0)
    return get_rigid_term("b", 0);
  else {
    struct term *t;
    int arity; int i; int sn;
    sn = symnum[rand() % 13];
    arity = sn_to_arity(sn);
    if (is_symbol(sn, "$quantified", 1)) {
      struct term *q = get_rigid_term("$quantified", 1);
      struct term *a = get_rigid_term("all", 0);
      struct term *x = get_rigid_term("x", 0);
      struct term *r = random_op_term(depth-1);
      struct term *t = get_nil_term();
      t = listterm_cons(r, t);
      t = listterm_cons(x, t);
      t = listterm_cons(a, t);
      ((q)->args[0]) = t;
      return q;
    }
    else {
      t = get_rigid_term(sn_to_str(sn), arity);
      for (i = 0; i < arity; i++)
 ((t)->args[i]) = random_op_term(depth-1);
      return t;
    }
  }
}

variable_types: depth int

variable_types: initialized int

variable_types:
symnum
int [13]

variable_types: i int

variable_types: sn int


original_code:
void random_permutation(int *a, int size)
{
  int n, i, x;
  for (i = 0; i < size; i++)
    a[i] = -1;
  n = 0;
  while (n < size) {
    x = rand() % size;
    if (a[x] == -1)
      a[x] = n++;
    else {
      i = x+1;
      while (i < size && a[i] != -1)
 i++;
      if (i < size)
 a[i] = n++;
      else {
 i = x-1;
 while (i >= 0 && a[i] != -1)
   i--;
 if (i < 0) {
   fatal_error("random_permutation.");
 }
 a[i] = n++;
      }
    }
  }
}

canonical_original_code:
void random_permutation(int *a, int size)
{
  int n; int i; int x;
  for (i = 0; i < size; i++)
    a[i] = -1;
  n = 0;
  while (n < size) {
    x = rand() % size;
    if (a[x] == -1)
      a[x] = n++;
    else {
      i = x+1;
      while (i < size && a[i] != -1)
 i++;
      if (i < size)
 a[i] = n++;
      else {
 i = x-1;
 while (i >= 0 && a[i] != -1)
   i--;
 if (i < 0) {
   fatal_error("random_permutation.");
 }
 a[i] = n++;
      }
    }
  }
}

variable_types:
a
int *

variable_types: size int

variable_types: x int


flatten

original_code:
void flatten(Term t, Term *a, int *ip)
{
  Term t1;
  int sn, i;
  sn = (-((t)->private_symbol));
  for (i = 0; i < ((t)->arity); i++) {
    t1 = ((t)->args[i]);
    if ((-((t1)->private_symbol)) == sn)
      flatten(t1, a, ip);
    else {
      if (*ip >= 2500) {
 fprint_term(stdout, t);
 fatal_error("flatten, too many arguments.");
      }
      a[*ip] = t1;
      (*ip)++;
    }
  }
}

canonical_original_code:
void flatten(struct term *t, struct term **a, int *ip)
{
  struct term *t1;
  int sn; int i;
  sn = (-((t)->private_symbol));
  for (i = 0; i < ((t)->arity); i++) {
    t1 = ((t)->args[i]);
    if ((-((t1)->private_symbol)) == sn)
      flatten(t1, a, ip);
    else {
      if (*ip >= 2500) {
 fprint_term(stdout, t);
 fatal_error("flatten, too many arguments.");
      }
      a[*ip] = t1;
      (*ip)++;
    }
  }
}

variable_types:
a
struct term **

variable_types:
ip
int *


original_code:
void ac_canonical2(Term t, int bit,
     Ordertype (*term_compare_proc) (Term, Term))
{
  Term args[2500], work[2500];
  Term t1;
  int n, i;
  if (is_assoc_comm((-((t)->private_symbol)))) {
    n = 0;
    flatten(t, args, &n);
    for (i = 0; i < n; i++)
      if (bit == -1 || !term_flag(args[i], bit))
 ac_canonical2(args[i], bit, term_compare_proc);
    merge_sort_recurse((void **) args, (void **) work, 0, n-1,
        (Ordertype (*)(void*,void*)) term_compare_proc);
    right_associate(t);
    for (t1 = t, i = 0; i < n-2; t1 = ((t1)->args[1]), i++) {
      ((t1)->args[0]) = args[i];
      if (bit != -1)
 term_flag_clear(t1, bit);
    }
    ((t1)->args[0]) = args[n-2];
    ((t1)->args[1]) = args[n-1];
  }
  else {
    for (i = 0; i < ((t)->arity); i++)
      ac_canonical2(((t)->args[i]), bit, term_compare_proc);
  }
}

canonical_original_code:
void ac_canonical2(struct term *t, int bit, enum Ordertype (*term_compare_proc)(struct term *, struct term *))
{
  struct term *args[2500]; struct term *work[2500];
  struct term *t1;
  int n; int i;
  if (is_assoc_comm((-((t)->private_symbol)))) {
    n = 0;
    flatten(t, args, &n);
    for (i = 0; i < n; i++)
      if (bit == -1 || !term_flag(args[i], bit))
 ac_canonical2(args[i], bit, term_compare_proc);
    merge_sort_recurse((void **) args, (void **) work, 0, n-1,
        (enum Ordertype (*)(void *, void *)) term_compare_proc);
    right_associate(t);
    for (t1 = t, i = 0; i < n-2; t1 = ((t1)->args[1]), i++) {
      ((t1)->args[0]) = args[i];
      if (bit != -1)
 term_flag_clear(t1, bit);
    }
    ((t1)->args[0]) = args[n-2];
    ((t1)->args[1]) = args[n-1];
  }
  else {
    for (i = 0; i < ((t)->arity); i++)
      ac_canonical2(((t)->args[i]), bit, term_compare_proc);
  }
}

variable_types: bit int

variable_types: enum Ordertype { NOT_COMPARABLE=0, SAME_AS=1, LESS_THAN=2, GREATER_THAN=3, LESS_THAN_OR_SAME_AS=4, GREATER_THAN_OR_SAME_AS=5, NOT_LESS_THAN=6, NOT_GREATER_THAN=7 } (*)(struct term *, struct term *)

variable_types: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *[2500]

variable_types: n int


decompiled_code:
__int64 __fastcall ac_canonical(__int64 a1, unsigned int a2)
{
return ac_canonical2(a1, a2, (__int64)&term_compare_ncv);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
return func2(a1, a2, (__int64)&term_compare_ncv);
}

original_code:
void ac_canonical(Term t, int bit)
{
  ac_canonical2(t, bit, term_compare_ncv);
}

canonical_original_code:
void ac_canonical(struct term *t, int bit)
{
  ac_canonical2(t, bit, term_compare_ncv);
}

variable_types: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *


decompiled_code:
__int64 __fastcall check_ac_canonical(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

v1 = copy_term();
ac_canonical(v1, 0xFFFFFFFF);
v2 = term_ident(a1, v1);
zap_term(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

v1 = copy_term();
func3(v1, 0xFFFFFFFF);
v2 = term_ident(a1, v1);
zap_term(v1);
return v2;
}

original_code:
int check_ac_canonical(Term t)
{
  int rc;
  Term t1 = copy_term(t);
  ac_canonical(t1, -1);
  rc = term_ident(t, t1);
  zap_term(t1);
  return(rc);
}

canonical_original_code:
int check_ac_canonical(struct term *t)
{
  int rc;
  struct term *t1 = copy_term(t);
  ac_canonical(t1, -1);
  rc = term_ident(t, t1);
  zap_term(t1);
  return(rc);
}

variable_types: rc int

return_type: int


prime

decompiled_code:
__int64 __fastcall prime(int a1)
{
int *v1; // rax
int v2; // edx
int v3; // esi
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

if ( !initialized_1 )
{
v1 = (int *)&unk_128;
do
*v1++ = 1;
while ( v1 != &initialized_1 );
v2 = 2;
v3 = 4;
do
{
v4 = v3;
if ( v3 <= 999 )
{
do
{
a_0[v4] = 0;
v4 += v2;
}
while ( (int)v4 <= 999 );
}
v5 = v2 + 1;
do
v2 = v5++;
while ( !*(_DWORD *)(4 * v5 + 0x11C) );
v3 = v2 * v2;
}
while ( v2 * v2 <= 999 );
initialized_1 = 1;
}
if ( a1 > 1000 )
exit(1);
result = 0LL;
if ( a1 > 1 )
result = (unsigned int)a_0[a1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int *v1; // rax
int v2; // edx
int v3; // esi
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

if ( !initialized_1 )
{
v1 = (int *)&unk_128;
do
*v1++ = 1;
while ( v1 != &initialized_1 );
v2 = 2;
v3 = 4;
do
{
v4 = v3;
if ( v3 <= 999 )
{
do
{
a_0[v4] = 0;
v4 += v2;
}
while ( (int)v4 <= 999 );
}
v5 = v2 + 1;
do
v2 = v5++;
while ( !*(_DWORD *)(4 * v5 + 0x11C) );
v3 = v2 * v2;
}
while ( v2 * v2 <= 999 );
initialized_1 = 1;
}
if ( a1 > 1000 )
exit(1);
result = 0LL;
if ( a1 > 1 )
result = (unsigned int)a_0[a1];
return result;
}

original_code:
BOOL prime(int n)
{
  static BOOL a[1000 +1];
  static BOOL initialized = FALSE;
  if (!initialized) {
    int i, p;
    for (i = 2; i <= 1000; i++)
      a[i] = TRUE;
    p = 2;
    while (p*p < 1000) {
      int j = p*p;
      while (j < 1000) {
 a[j] = FALSE;
 j = j + p;
      }
      do p++; while (a[p] == FALSE);
    }
    initialized = TRUE;
  }
  if (n > 1000)
    exit(1);
  else if (n < 2)
    return FALSE;
  else
    return a[n];
}

canonical_original_code:
enum BOOL prime(int n)
{
  static enum BOOL a[-1];
  static enum BOOL initialized = FALSE;
  if (!initialized) {
    int i; int p;
    for (i = 2; i <= 1000; i++)
      a[i] = TRUE;
    p = 2;
    while (p*p < 1000) {
      int j = p*p;
      while (j < 1000) {
 a[j] = FALSE;
 j = j + p;
      }
      do p++; while (a[p] == FALSE);
    }
    initialized = TRUE;
  }
  if (n > 1000)
    exit(1);
  else if (n < 2)
    return FALSE;
  else
    return a[n];
}

variable_types:
a
enum BOOL { FALSE=0, TRUE=1 } [-1]

variable_types:
initialized
enum BOOL { FALSE=0, TRUE=1 }

variable_types: p int

variable_types: j int


original_code:
void random_permutation(int *a, int n)
{
  int i, t, k;
  for (i = 0; i < n; i++)
    a[i] = i;
  for (i = n-1; i >= 0; i--) {
    k = rand() % (i+1);
    t = a[i];
    a[i] = a[k];
    a[k] = t;
  }
}

canonical_original_code:
void random_permutation(int *a, int n)
{
  int i; int t; int k;
  for (i = 0; i < n; i++)
    a[i] = i;
  for (i = n-1; i >= 0; i--) {
    k = rand() % (i+1);
    t = a[i];
    a[i] = a[k];
    a[k] = t;
  }
}

variable_types: i int

variable_types: t int

variable_types: k int


decompiled_code:
__int64 __fastcall set_of_more_occurrences(_QWORD *a1, int a2, _QWORD *a3, int a4)
{
__int64 v4; // r15
__int64 v5; // r12
__int64 i; // rbx
int v7; // ebx
__int64 v9; // [rsp+18h] [rbp-50h]

if ( a2 <= 0 )
return 0LL;
v4 = 0LL;
v9 = 0LL;
do
{
v5 = a1[v4];
if ( !(_DWORD)v4 )
goto LABEL_10;
for ( i = 0LL; !(unsigned int)term_ident(v5, a1[i]); ++i )
{
if ( (_DWORD)v4 - 1 == i )
goto LABEL_10;
}
if ( (_DWORD)i == (_DWORD)v4 )
{
LABEL_10:
v7 = num_occurrences(v5, a1, a2);
if ( v7 > (int)num_occurrences(v5, a3, a4) )
v9 = plist_prepend(v9, v5);
}
++v4;
}
while ( v4 != a2 );
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2, _QWORD *a3, int a4)
{
__int64 v4; // r15
__int64 v5; // r12
__int64 i; // rbx
int v7; // ebx
__int64 v9; // [rsp+18h] [rbp-50h]

if ( a2 <= 0 )
return 0LL;
v4 = 0LL;
v9 = 0LL;
do
{
v5 = a1[v4];
if ( !(_DWORD)v4 )
goto LABEL_10;
for ( i = 0LL; !(unsigned int)term_ident(v5, a1[i]); ++i )
{
if ( (_DWORD)v4 - 1 == i )
goto LABEL_10;
}
if ( (_DWORD)i == (_DWORD)v4 )
{
LABEL_10:
v7 = func0(v5, a1, a2);
if ( v7 > (int)func0(v5, a3, a4) )
v9 = plist_prepend(v9, v5);
}
++v4;
}
while ( v4 != a2 );
return v9;
}

original_code:
static
Plist set_of_more_occurrences(Term a1[], int n1, Term a2[], int n2)
{
  Plist answer = ((void *)0);
  int i, j;
  for (i = 0; i < n1; i++) {
    Term e1 = a1[i];
    for (j = 0; j != i && !term_ident(e1, a1[j]); j++);
    if (i == j && num_occurrences(e1,a1,n1) > num_occurrences(e1,a2,n2))
      answer = plist_prepend(answer, e1);
  }
  return answer;
}

canonical_original_code:
static struct plist *set_of_more_occurrences(struct term *a1[], int n1, struct term *a2[], int n2)
{
  struct plist *answer = ((void *)0);
  int i; int j;
  for (i = 0; i < n1; i++) {
    struct term *e1 = a1[i];
    for (j = 0; j != i && !term_ident(e1, a1[j]); j++);
    if (i == j && num_occurrences(e1,a1,n1) > num_occurrences(e1,a2,n2))
      answer = plist_prepend(answer, e1);
  }
  return answer;
}

variable_types: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *[]

variable_types: struct plist { void *v; struct plist *next; } *


decompiled_code:
__int64 __fastcall greater_multiset(_QWORD *a1, int a2, _QWORD *a3, int a4, __int64 (__fastcall *a5)(_QWORD, _QWORD, _QWORD), unsigned int a6)
{
__int64 v9; // r15
__int64 v10; // rax
unsigned int v11; // ebp
_QWORD *v12; // r12
_QWORD *v14; // rbx
unsigned int v15; // eax
__int64 v17; // [rsp+8h] [rbp-40h]

v9 = set_of_more_occurrences(a1, a2, a3, a4);
v10 = set_of_more_occurrences(a3, a4, a1, a2);
v17 = v10;
v11 = 0;
if ( v9 )
{
v12 = (_QWORD *)v10;
v11 = 1;
if ( v10 )
{
do
{
v14 = (_QWORD *)v9;
do
{
v15 = a5(*v14, *v12, a6);
v11 = v15;
v14 = (_QWORD *)v14[1];
}
while ( v14 && !v15 );
v12 = (_QWORD *)v12[1];
}
while ( v12 && v15 );
}
}
zap_plist(v9);
zap_plist(v17);
return v11;
}

original_code:
BOOL greater_multiset(Term a1[], int n1, Term a2[], int n2,
        BOOL (*comp_proc) (Term, Term, BOOL),
        BOOL lex_order_vars)
{
  Plist s1, s2, p1, p2;
  BOOL ok;
  s1 = set_of_more_occurrences(a1, n1, a2, n2);
  s2 = set_of_more_occurrences(a2, n2, a1, n1);
  if (s1 == ((void *)0))
    ok = FALSE;
  else {
    for (p2 = s2, ok = TRUE; p2 && ok; p2 = p2->next)
      for (p1 = s1, ok = FALSE; p1 && !ok; p1 = p1->next)
 ok = (*comp_proc)(p1->v, p2->v, lex_order_vars);
  }
  zap_plist(s1);
  zap_plist(s2);
  return ok;
}

canonical_original_code:
enum BOOL greater_multiset(struct term *a1[], int n1, struct term *a2[], int n2, enum BOOL (*comp_proc)(struct term *, struct term *, enum BOOL), enum BOOL lex_order_vars)
{
  struct plist *s1; struct plist *s2; struct plist *p1; struct plist *p2;
  enum BOOL ok;
  s1 = set_of_more_occurrences(a1, n1, a2, n2);
  s2 = set_of_more_occurrences(a2, n2, a1, n1);
  if (s1 == ((void *)0))
    ok = FALSE;
  else {
    for (p2 = s2, ok = TRUE; p2 && ok; p2 = p2->next)
      for (p1 = s1, ok = FALSE; p1 && !ok; p1 = p1->next)
 ok = (*comp_proc)(p1->v, p2->v, lex_order_vars);
  }
  zap_plist(s1);
  zap_plist(s2);
  return ok;
}

variable_types: enum BOOL { FALSE=0, TRUE=1 } (*)(struct term *, struct term *, enum BOOL { FALSE=0, TRUE=1 })

variable_types:
ok
enum BOOL { FALSE=0, TRUE=1 }

user_defined_types: struct plist { void *v; struct plist *next; }


decompiled_code:
__int64 __fastcall num_occurrences(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rbx
__int64 v4; // r13
unsigned int v5; // ebp

if ( a3 <= 0 )
return 0;
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v5 = 0;
do
v5 -= ((unsigned int)term_ident(*v3++, a1) == 0) - 1;
while ( v3 != (_QWORD *)v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rbx
__int64 v4; // r13
unsigned int v5; // ebp

if ( a3 <= 0 )
return 0;
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v5 = 0;
do
v5 -= ((unsigned int)term_ident(*v3++, a1) == 0) - 1;
while ( v3 != (_QWORD *)v4 );
return v5;
}

original_code:
static
int num_occurrences(Term t, Term a[], int n)
{
  int i, count;
  for (i = 0, count = 0; i < n; i++)
    if (term_ident(a[i], t))
      count++;
  return count;
}

canonical_original_code:
static int num_occurrences(struct term *t, struct term *a[], int n)
{
  int i; int count;
  for (i = 0, count = 0; i < n; i++)
    if (term_ident(a[i], t))
      count++;
  return count;
}

variable_types:
a
struct term *[]

variable_types: count int


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

result = 0LL;
if ( Symbols_size > a1 )
{
result = 1LL;
if ( !*(_QWORD *)(Rules + 8LL * a1) )
result = *(_DWORD *)(Op_codes + 4LL * a1) != 0;
}
return result;
}

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

result = 0LL;
if ( Symbols_size > a1 )
{
result = 1LL;
if ( !*(_QWORD *)(Rules + 8LL * a1) )
result = *(_DWORD *)(Op_codes + 4LL * a1) != 0;
}
return result;
}

canonical_original_code:
enum BOOL evaluable_predicate(int symnum)
{
  if (symnum >= Symbols_size)
    return FALSE;
  else if (Rules[symnum])
    return TRUE;
  else if (Op_codes[symnum])
    return TRUE;
  else
    return FALSE;
}

variable_types: symnum int


decompiled_code:
__int64 __fastcall dollar_eval(__int64 a1)
{
int v1; // eax
__int64 v2; // rsi
__int64 v3; // rdx
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax
__int64 v14; // rdi
int v15; // eax
int v16; // eax
int v17; // eax
__int64 v18; // rdx
int v19; // eax
int v20; // eax
int v21; // eax
int v22; // eax
int v23; // eax
int v24; // eax
int v25; // eax
int v26; // eax
int v27; // eax
__int64 v28; // rdx
int v29; // eax
int v30; // eax
unsigned int v31; // eax
int v32; // eax
int v33; // eax
int v34; // eax
int v35; // eax
int v36; // eax
__int64 v37; // rax
_BOOL8 v38; // rdi
unsigned int v39; // eax
int v41; // [rsp+0h] [rbp-14h] BYREF
int v42; // [rsp+4h] [rbp-10h] BYREF
int v43[3]; // [rsp+8h] [rbp-Ch] BYREF

if ( *(int *)a1 <= 0 )
{
v1 = -*(_DWORD *)a1;
if ( v1 >= Symbols_size )
return 0LL;
v2 = *(unsigned int *)(Op_codes + 4LL * v1);
v3 = 0LL;
if ( (_DWORD)v2 )
{
switch ( (int)v2 )
{
case 1:
v4 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v4 )
{
v5 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v5 )
v3 = int_to_term((unsigned int)(v41 + v43[0]));
}
return v3;
case 2:
v6 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v6 )
{
v7 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v7 )
v3 = int_to_term((unsigned int)(v43[0] * v41));
}
return v3;
case 3:
v8 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v8 )
{
v9 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v9 )
v3 = int_to_term((unsigned int)(v41 / v43[0]));
}
return v3;
case 4:
v10 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v10 )
{
v11 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v11 )
v3 = int_to_term((unsigned int)(v41 % v43[0]));
}
return v3;
case 5:
v12 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v12 )
{
v13 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v13 )
{
v14 = (unsigned int)v41;
if ( v43[0] <= v41 )
v14 = (unsigned int)v43[0];
v3 = int_to_term(v14);
}
}
return v3;
case 6:
v15 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v15 )
{
v16 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v16 )
v3 = int_to_term((unsigned int)v43[0]);
}
return v3;
case 7:
v17 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v17 )
v3 = int_to_term(abs32(v41));
return v3;
case 8:
if ( (unsigned int)term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL) )
return int_to_term((unsigned int)-v41);
v19 = term_to_bool(**(_QWORD **)(a1 + 8), &v42, v18);
v3 = 0LL;
if ( v19 )
v3 = bool_to_term(v42 == 0);
return v3;
case 9:
v20 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v20 )
{
v21 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v21 )
v3 = bool_to_term(v41 < v43[0]);
}
return v3;
case 10:
v22 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v22 )
{
v23 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v23 )
v3 = bool_to_term(v41 <= v43[0]);
}
return v3;
case 11:
v24 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v24 )
{
v25 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v25 )
v3 = bool_to_term(v41 > v43[0]);
}
return v3;
case 12:
v26 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v26 )
{
v27 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v27 )
v3 = bool_to_term(v41 >= v43[0]);
}
return v3;
case 13:
v33 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v33 == 2);
case 14:
v34 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term((unsigned int)(v34 - 1) <= 1);
case 15:
v35 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v35 == 3);
case 16:
v36 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term((v36 & 0xFFFFFFFD) == 1);
case 17:
case 19:
if ( (unsigned int)term_to_bool(**(_QWORD **)(a1 + 8), &v42, 0LL) )
{
if ( v42 )
goto LABEL_45;
}
else
{
v29 = term_to_bool(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, v28);
v3 = 0LL;
if ( !v29 )
return v3;
if ( v43[0] )
return copy_term(**(_QWORD **)(a1 + 8), v43, 0LL);
}
return bool_to_term(0LL);
case 18:
case 20:
if ( !(unsigned int)term_to_bool(**(_QWORD **)(a1 + 8), &v42, 0LL) )
{
v30 = term_to_bool(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, v28);
v3 = 0LL;
if ( !v30 )
return v3;
if ( !v43[0] )
return copy_term(**(_QWORD **)(a1 + 8), v43, 0LL);
return bool_to_term(1LL);
}
if ( v42 )
return bool_to_term(1LL);
LABEL_45:
v3 = copy_term(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), &v42, v28);
break;
case 22:
v31 = term_ident(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v31);
case 23:
v32 = term_ident(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v32 == 0);
case 24:
return bool_to_term(***(_DWORD ***)(a1 + 8) >= 0);
case 25:
v37 = **(_QWORD **)(a1 + 8);
v38 = 0LL;
if ( *(int *)v37 < 0 )
v38 = *(_BYTE *)(v37 + 4) == 0;
return bool_to_term(v38);
case 26:
v39 = ground_term(**(_QWORD **)(a1 + 8), v2, 0LL);
return bool_to_term(v39);
default:
printf("bad opcode is %d\n", v2);
fatal_error("dollar_eval: bad opcode");
return 0LL;
}
}
return v3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
__int64 v2; // rsi
__int64 v3; // rdx
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax
__int64 v14; // rdi
int v15; // eax
int v16; // eax
int v17; // eax
__int64 v18; // rdx
int v19; // eax
int v20; // eax
int v21; // eax
int v22; // eax
int v23; // eax
int v24; // eax
int v25; // eax
int v26; // eax
int v27; // eax
__int64 v28; // rdx
int v29; // eax
int v30; // eax
unsigned int v31; // eax
int v32; // eax
int v33; // eax
int v34; // eax
int v35; // eax
int v36; // eax
__int64 v37; // rax
_BOOL8 v38; // rdi
unsigned int v39; // eax
int v41; // [rsp+0h] [rbp-14h] BYREF
int v42; // [rsp+4h] [rbp-10h] BYREF
int v43[3]; // [rsp+8h] [rbp-Ch] BYREF

if ( *(int *)a1 <= 0 )
{
v1 = -*(_DWORD *)a1;
if ( v1 >= Symbols_size )
return 0LL;
v2 = *(unsigned int *)(Op_codes + 4LL * v1);
v3 = 0LL;
if ( (_DWORD)v2 )
{
switch ( (int)v2 )
{
case 1:
v4 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v4 )
{
v5 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v5 )
v3 = int_to_term((unsigned int)(v41 + v43[0]));
}
return v3;
case 2:
v6 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v6 )
{
v7 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v7 )
v3 = int_to_term((unsigned int)(v43[0] * v41));
}
return v3;
case 3:
v8 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v8 )
{
v9 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v9 )
v3 = int_to_term((unsigned int)(v41 / v43[0]));
}
return v3;
case 4:
v10 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v10 )
{
v11 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v11 )
v3 = int_to_term((unsigned int)(v41 % v43[0]));
}
return v3;
case 5:
v12 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v12 )
{
v13 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v13 )
{
v14 = (unsigned int)v41;
if ( v43[0] <= v41 )
v14 = (unsigned int)v43[0];
v3 = int_to_term(v14);
}
}
return v3;
case 6:
v15 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v15 )
{
v16 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v16 )
v3 = int_to_term((unsigned int)v43[0]);
}
return v3;
case 7:
v17 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v17 )
v3 = int_to_term(abs32(v41));
return v3;
case 8:
if ( (unsigned int)term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL) )
return int_to_term((unsigned int)-v41);
v19 = term_to_bool(**(_QWORD **)(a1 + 8), &v42, v18);
v3 = 0LL;
if ( v19 )
v3 = bool_to_term(v42 == 0);
return v3;
case 9:
v20 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v20 )
{
v21 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v21 )
v3 = bool_to_term(v41 < v43[0]);
}
return v3;
case 10:
v22 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v22 )
{
v23 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v23 )
v3 = bool_to_term(v41 <= v43[0]);
}
return v3;
case 11:
v24 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v24 )
{
v25 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v25 )
v3 = bool_to_term(v41 > v43[0]);
}
return v3;
case 12:
v26 = term_to_int(**(_QWORD **)(a1 + 8), &v41, 0LL);
v3 = 0LL;
if ( v26 )
{
v27 = term_to_int(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, 0LL);
v3 = 0LL;
if ( v27 )
v3 = bool_to_term(v41 >= v43[0]);
}
return v3;
case 13:
v33 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v33 == 2);
case 14:
v34 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term((unsigned int)(v34 - 1) <= 1);
case 15:
v35 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v35 == 3);
case 16:
v36 = term_compare_basic(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term((v36 & 0xFFFFFFFD) == 1);
case 17:
case 19:
if ( (unsigned int)term_to_bool(**(_QWORD **)(a1 + 8), &v42, 0LL) )
{
if ( v42 )
goto LABEL_45;
}
else
{
v29 = term_to_bool(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, v28);
v3 = 0LL;
if ( !v29 )
return v3;
if ( v43[0] )
return copy_term(**(_QWORD **)(a1 + 8), v43, 0LL);
}
return bool_to_term(0LL);
case 18:
case 20:
if ( !(unsigned int)term_to_bool(**(_QWORD **)(a1 + 8), &v42, 0LL) )
{
v30 = term_to_bool(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v43, v28);
v3 = 0LL;
if ( !v30 )
return v3;
if ( !v43[0] )
return copy_term(**(_QWORD **)(a1 + 8), v43, 0LL);
return bool_to_term(1LL);
}
if ( v42 )
return bool_to_term(1LL);
LABEL_45:
v3 = copy_term(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), &v42, v28);
break;
case 22:
v31 = term_ident(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v31);
case 23:
v32 = term_ident(**(_QWORD **)(a1 + 8), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), 0LL);
return bool_to_term(v32 == 0);
case 24:
return bool_to_term(***(_DWORD ***)(a1 + 8) >= 0);
case 25:
v37 = **(_QWORD **)(a1 + 8);
v38 = 0LL;
if ( *(int *)v37 < 0 )
v38 = *(_BYTE *)(v37 + 4) == 0;
return bool_to_term(v38);
case 26:
v39 = ground_term(**(_QWORD **)(a1 + 8), v2, 0LL);
return bool_to_term(v39);
default:
printf("bad opcode is %d\n", v2);
fatal_error("dollar_eval: bad opcode");
return 0LL;
}
}
return v3;
}
return 0LL;
}

original_code:
Term dollar_eval(Term t)
{
  if ((-((t)->private_symbol)) < 0 || (-((t)->private_symbol)) >= Symbols_size)
    return ((void *)0);
  else {
    int op_code = Op_codes[(-((t)->private_symbol))];
    if (op_code == 0)
      return ((void *)0);
    else {
      int i0, i1;
      BOOL b0, b1;
      Term result = ((void *)0);
      switch (op_code) {
      case SUM_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 + i1);
 break;
      case PROD_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 * i1);
 break;
      case DIV_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 / i1);
 break;
      case MOD_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 % i1);
 break;
      case MIN_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 < i1 ? i0 : i1);
 break;
      case MAX_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 > i1 ? i1 : i1);
 break;
      case ABS_OP:
 if (term_to_int(((t)->args[0]), &i0))
   result = int_to_term(i0 >= 0 ? i0 : -i0);
 break;
      case NEG_OP:
 if (term_to_int(((t)->args[0]), &i0))
   result = int_to_term(-i0);
 else if (term_to_bool(((t)->args[0]), &b0))
   result = bool_to_term(!b0);
 break;
      case LT_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 < i1);
 break;
      case LE_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 <= i1);
 break;
      case GT_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 > i1);
 break;
      case GE_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 >= i1);
 break;
      case AND_OP:
      case AND2_OP:
 if (term_to_bool(((t)->args[0]), &b0)) {
   if (b0)
     result = copy_term(((t)->args[1]));
   else
     result = bool_to_term(FALSE);
 }
 else if (term_to_bool(((t)->args[1]), &b1)) {
   if (b1)
     result = copy_term(((t)->args[0]));
   else
     result = bool_to_term(FALSE);
 }
 break;
      case OR_OP:
      case OR2_OP:
 if (term_to_bool(((t)->args[0]), &b0)) {
   if (b0)
     result = bool_to_term(TRUE);
   else
     result = copy_term(((t)->args[1]));
 }
 else if (term_to_bool(((t)->args[1]), &b1)) {
   if (b1)
     result = bool_to_term(TRUE);
   else
     result = copy_term(((t)->args[0]));
 }
 break;
      case ID_OP:
 result = bool_to_term(term_ident(((t)->args[0]), ((t)->args[1])));
 break;
      case NID_OP:
 result = bool_to_term(!term_ident(((t)->args[0]), ((t)->args[1])));
 break;
      case LLT_OP:
 result = bool_to_term(term_compare_basic(((t)->args[0]),((t)->args[1])) == LESS_THAN);
 break;
      case LLE_OP: {
 Ordertype r = term_compare_basic(((t)->args[0]),((t)->args[1]));
 result = bool_to_term(r == LESS_THAN || r == SAME_AS);
 break;
      }
      case LGT_OP:
 result = bool_to_term(term_compare_basic(((t)->args[0]),((t)->args[1])) == GREATER_THAN);
 break;
      case LGE_OP: {
 Ordertype r = term_compare_basic(((t)->args[0]),((t)->args[1]));
 result = bool_to_term(r == GREATER_THAN || r == SAME_AS);
 break;
      }
      case VAR_OP:
 result = bool_to_term(((((t)->args[0]))->private_symbol >= 0));
 break;
      case CONST_OP:
 result = bool_to_term(((((t)->args[0]))->private_symbol < 0 && (((t)->args[0]))->arity == 0));
 break;
      case GROUND_OP:
 result = bool_to_term(ground_term(((t)->args[0])));
 break;
      default:
 printf("bad opcode is %d\n", op_code);
 fatal_error("dollar_eval: bad opcode");
      }
      return result;
    }
  }
}

canonical_original_code:
struct term *dollar_eval(struct term *t)
{
  if ((-((t)->private_symbol)) < 0 || (-((t)->private_symbol)) >= Symbols_size)
    return ((void *)0);
  else {
    int op_code = Op_codes[(-((t)->private_symbol))];
    if (op_code == 0)
      return ((void *)0);
    else {
      int i0; int i1;
      enum BOOL b0; enum BOOL b1;
      struct term *result = ((void *)0);
      switch (op_code) {
      case SUM_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 + i1);
 break;
      case PROD_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 * i1);
 break;
      case DIV_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 / i1);
 break;
      case MOD_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 % i1);
 break;
      case MIN_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 < i1 ? i0 : i1);
 break;
      case MAX_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = int_to_term(i0 > i1 ? i1 : i1);
 break;
      case ABS_OP:
 if (term_to_int(((t)->args[0]), &i0))
   result = int_to_term(i0 >= 0 ? i0 : -i0);
 break;
      case NEG_OP:
 if (term_to_int(((t)->args[0]), &i0))
   result = int_to_term(-i0);
 else if (term_to_bool(((t)->args[0]), &b0))
   result = bool_to_term(!b0);
 break;
      case LT_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 < i1);
 break;
      case LE_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 <= i1);
 break;
      case GT_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 > i1);
 break;
      case GE_OP:
 if (term_to_int(((t)->args[0]), &i0) && term_to_int(((t)->args[1]), &i1))
   result = bool_to_term(i0 >= i1);
 break;
      case AND_OP:
      case AND2_OP:
 if (term_to_bool(((t)->args[0]), &b0)) {
   if (b0)
     result = copy_term(((t)->args[1]));
   else
     result = bool_to_term(FALSE);
 }
 else if (term_to_bool(((t)->args[1]), &b1)) {
   if (b1)
     result = copy_term(((t)->args[0]));
   else
     result = bool_to_term(FALSE);
 }
 break;
      case OR_OP:
      case OR2_OP:
 if (term_to_bool(((t)->args[0]), &b0)) {
   if (b0)
     result = bool_to_term(TRUE);
   else
     result = copy_term(((t)->args[1]));
 }
 else if (term_to_bool(((t)->args[1]), &b1)) {
   if (b1)
     result = bool_to_term(TRUE);
   else
     result = copy_term(((t)->args[0]));
 }
 break;
      case ID_OP:
 result = bool_to_term(term_ident(((t)->args[0]), ((t)->args[1])));
 break;
      case NID_OP:
 result = bool_to_term(!term_ident(((t)->args[0]), ((t)->args[1])));
 break;
      case LLT_OP:
 result = bool_to_term(term_compare_basic(((t)->args[0]),((t)->args[1])) == LESS_THAN);
 break;
      case LLE_OP: {
 enum Ordertype r = term_compare_basic(((t)->args[0]),((t)->args[1]));
 result = bool_to_term(r == LESS_THAN || r == SAME_AS);
 break;
      }
      case LGT_OP:
 result = bool_to_term(term_compare_basic(((t)->args[0]),((t)->args[1])) == GREATER_THAN);
 break;
      case LGE_OP: {
 enum Ordertype r = term_compare_basic(((t)->args[0]),((t)->args[1]));
 result = bool_to_term(r == GREATER_THAN || r == SAME_AS);
 break;
      }
      case VAR_OP:
 result = bool_to_term(((((t)->args[0]))->private_symbol >= 0));
 break;
      case CONST_OP:
 result = bool_to_term(((((t)->args[0]))->private_symbol < 0 && (((t)->args[0]))->arity == 0));
 break;
      case GROUND_OP:
 result = bool_to_term(ground_term(((t)->args[0])));
 break;
      default:
 printf("bad opcode is %d\n", op_code);
 fatal_error("dollar_eval: bad opcode");
      }
      return result;
    }
  }
}

variable_types:
t
struct term *

variable_types: enum Ordertype { NOT_COMPARABLE=0, SAME_AS=1, LESS_THAN=2, GREATER_THAN=3, LESS_THAN_OR_SAME_AS=4, GREATER_THAN_OR_SAME_AS=5, NOT_LESS_THAN=6, NOT_GREATER_THAN=7 }


rewrite

decompiled_code:
__int64 __fastcall rewrite(__int64 a1, unsigned int a2, _QWORD *a3)
{
__int64 v3; // rbx
int v5; // eax
_QWORD *v6; // r13
__int64 v7; // r13
_QWORD *v8; // r14
_QWORD *v10; // rax
__int64 v11; // r13
_QWORD *v12; // r13
_QWORD *v13; // r13
_QWORD *v14; // rax
__int64 v15; // r13
_QWORD *v16; // rax
__int64 v17; // r13

v3 = a1;
if ( !(unsigned int)term_flag() && *(int *)a1 < 0 )
{
v5 = -*(_DWORD *)a1;
if ( v5 >= Symbols_size )
{
LABEL_7:
v7 = 0LL;
if ( *(_BYTE *)(a1 + 4) )
{
do
{
v8 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7);
*v8 = rewrite(*v8, a2, a3);
++v7;
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v7 );
}
v3 = rewrite_top((_DWORD *)a1, a2, a3);
term_flag_set(v3, a2);
}
else
{
switch ( *(_DWORD *)(Op_codes + 4LL * v5) )
{
case 0x11:
case 0x13:
v6 = *(_QWORD **)(a1 + 8);
*v6 = rewrite(*v6, a2, a3);
if ( (unsigned int)true_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_11;
if ( !(unsigned int)false_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_7;
zap_term(a1);
return bool_to_term(0LL);
case 0x12:
case 0x14:
v12 = *(_QWORD **)(a1 + 8);
*v12 = rewrite(*v12, a2, a3);
if ( (unsigned int)false_term(**(_QWORD **)(a1 + 8)) )
{
LABEL_11:
v10 = *(_QWORD **)(a1 + 8);
v11 = v10[1];
zap_term(*v10);
free_term(a1);
return rewrite(v11, a2, a3);
}
if ( !(unsigned int)true_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_7;
zap_term(a1);
return bool_to_term(1LL);
case 0x15:
v13 = *(_QWORD **)(a1 + 8);
*v13 = rewrite(*v13, a2, a3);
if ( (unsigned int)true_term(**(_QWORD **)(a1 + 8)) )
{
v16 = *(_QWORD **)(a1 + 8);
v17 = v16[1];
zap_term(*v16);
zap_term(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL));
free_term(a1);
v3 = rewrite(v17, a2, a3);
}
else
{
if ( !(unsigned int)false_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_7;
v14 = *(_QWORD **)(a1 + 8);
v15 = v14[2];
zap_term(*v14);
zap_term(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
free_term(a1);
v3 = rewrite(v15, a2, a3);
}
break;
default:
goto LABEL_7;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, _QWORD *a3)
{
__int64 v3; // rbx
int v5; // eax
_QWORD *v6; // r13
__int64 v7; // r13
_QWORD *v8; // r14
_QWORD *v10; // rax
__int64 v11; // r13
_QWORD *v12; // r13
_QWORD *v13; // r13
_QWORD *v14; // rax
__int64 v15; // r13
_QWORD *v16; // rax
__int64 v17; // r13

v3 = a1;
if ( !(unsigned int)term_flag() && *(int *)a1 < 0 )
{
v5 = -*(_DWORD *)a1;
if ( v5 >= Symbols_size )
{
LABEL_7:
v7 = 0LL;
if ( *(_BYTE *)(a1 + 4) )
{
do
{
v8 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7);
*v8 = func3(*v8, a2, a3);
++v7;
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v7 );
}
v3 = func2((_DWORD *)a1, a2, a3);
term_flag_set(v3, a2);
}
else
{
switch ( *(_DWORD *)(Op_codes + 4LL * v5) )
{
case 0x11:
case 0x13:
v6 = *(_QWORD **)(a1 + 8);
*v6 = func3(*v6, a2, a3);
if ( (unsigned int)true_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_11;
if ( !(unsigned int)false_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_7;
zap_term(a1);
return bool_to_term(0LL);
case 0x12:
case 0x14:
v12 = *(_QWORD **)(a1 + 8);
*v12 = func3(*v12, a2, a3);
if ( (unsigned int)false_term(**(_QWORD **)(a1 + 8)) )
{
LABEL_11:
v10 = *(_QWORD **)(a1 + 8);
v11 = v10[1];
zap_term(*v10);
free_term(a1);
return func3(v11, a2, a3);
}
if ( !(unsigned int)true_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_7;
zap_term(a1);
return bool_to_term(1LL);
case 0x15:
v13 = *(_QWORD **)(a1 + 8);
*v13 = func3(*v13, a2, a3);
if ( (unsigned int)true_term(**(_QWORD **)(a1 + 8)) )
{
v16 = *(_QWORD **)(a1 + 8);
v17 = v16[1];
zap_term(*v16);
zap_term(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL));
free_term(a1);
v3 = func3(v17, a2, a3);
}
else
{
if ( !(unsigned int)false_term(**(_QWORD **)(a1 + 8)) )
goto LABEL_7;
v14 = *(_QWORD **)(a1 + 8);
v15 = v14[2];
zap_term(*v14);
zap_term(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
free_term(a1);
v3 = func3(v15, a2, a3);
}
break;
default:
goto LABEL_7;
}
}
}
return v3;
}

original_code:
static
Term rewrite(Term t, int flag, I3list *steps)
{
  if (term_flag(t, flag) || ((t)->private_symbol >= 0))
    return t;
  else {
    int op_code = ((-((t)->private_symbol)) < Symbols_size ? Op_codes[(-((t)->private_symbol))] : -1);
    int i;
    switch (op_code) {
    case AND_OP:
    case AND2_OP:
      ((t)->args[0]) = rewrite(((t)->args[0]), flag, steps);
      if (true_term(((t)->args[0]))) {
 Term tmp = ((t)->args[1]);
 zap_term(((t)->args[0]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      else if (false_term(((t)->args[0]))) {
 zap_term(t);
 return bool_to_term(FALSE);
      }
      break;
    case OR_OP:
    case OR2_OP:
      ((t)->args[0]) = rewrite(((t)->args[0]), flag, steps);
      if (false_term(((t)->args[0]))) {
 Term tmp = ((t)->args[1]);
 zap_term(((t)->args[0]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      else if (true_term(((t)->args[0]))) {
 zap_term(t);
 return bool_to_term(TRUE);
      }
      break;
    case IF_OP:
      ((t)->args[0]) = rewrite(((t)->args[0]), flag, steps);
      if (true_term(((t)->args[0]))) {
 Term tmp = ((t)->args[1]);
 zap_term(((t)->args[0]));
 zap_term(((t)->args[2]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      else if (false_term(((t)->args[0]))) {
 Term tmp = ((t)->args[2]);
 zap_term(((t)->args[0]));
 zap_term(((t)->args[1]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      break;
    }
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = rewrite(((t)->args[i]), flag, steps);
    t = rewrite_top(t, flag, steps);
    term_flag_set(t, flag);
    return t;
  }
}

canonical_original_code:
static struct term *rewrite(struct term *t, int flag, struct i3list **steps)
{
  if (term_flag(t, flag) || ((t)->private_symbol >= 0))
    return t;
  else {
    int op_code = ((-((t)->private_symbol)) < Symbols_size ? Op_codes[(-((t)->private_symbol))] : -1);
    int i;
    switch (op_code) {
    case AND_OP:
    case AND2_OP:
      ((t)->args[0]) = rewrite(((t)->args[0]), flag, steps);
      if (true_term(((t)->args[0]))) {
 struct term *tmp = ((t)->args[1]);
 zap_term(((t)->args[0]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      else if (false_term(((t)->args[0]))) {
 zap_term(t);
 return bool_to_term(FALSE);
      }
      break;
    case OR_OP:
    case OR2_OP:
      ((t)->args[0]) = rewrite(((t)->args[0]), flag, steps);
      if (false_term(((t)->args[0]))) {
 struct term *tmp = ((t)->args[1]);
 zap_term(((t)->args[0]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      else if (true_term(((t)->args[0]))) {
 zap_term(t);
 return bool_to_term(TRUE);
      }
      break;
    case IF_OP:
      ((t)->args[0]) = rewrite(((t)->args[0]), flag, steps);
      if (true_term(((t)->args[0]))) {
 struct term *tmp = ((t)->args[1]);
 zap_term(((t)->args[0]));
 zap_term(((t)->args[2]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      else if (false_term(((t)->args[0]))) {
 struct term *tmp = ((t)->args[2]);
 zap_term(((t)->args[0]));
 zap_term(((t)->args[1]));
 free_term(t);
 return rewrite(tmp, flag, steps);
      }
      break;
    }
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = rewrite(((t)->args[i]), flag, steps);
    t = rewrite_top(t, flag, steps);
    term_flag_set(t, flag);
    return t;
  }
}

variable_types: flag int

variable_types: struct i3list { int i; int j; int k; struct i3list *next; } **

variable_types: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *


decompiled_code:
void __fastcall mace4_sig_handler(unsigned int a1)
{
printf("\nmace4_sig_handler: condition %d", a1);
switch ( a1 )
{
case 0xAu:
p_stats();
fflush(stdout);
break;
case 0xBu:
p_stats();
mace4_exit(102LL);
break;
case 2u:
p_stats();
mace4_exit(101LL);
break;
default:
fatal_error("mace4_sig_handler, unknown signal");
break;
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
printf("\nmace4_sig_handler: condition %d", a1);
switch ( a1 )
{
case 0xAu:
p_stats();
fflush(stdout);
break;
case 0xBu:
p_stats();
mace4_exit(102LL);
break;
case 2u:
p_stats();
mace4_exit(101LL);
break;
default:
fatal_error("mace4_sig_handler, unknown signal");
break;
}
}

original_code:
void mace4_sig_handler(int condition)
{
  printf("\nmace4_sig_handler: condition %d", condition);
  switch (condition) {
  case 11:
    p_stats();
    mace4_exit(MACE_SIGSEGV_EXIT);
    break;
  case 2:
    p_stats();
    mace4_exit(MACE_SIGINT_EXIT);
    break;
  case 10:
    p_stats();
    fflush(stdout);
    break;
  default: fatal_error("mace4_sig_handler, unknown signal");
  }
}

variable_types: condition int


decompiled_code:
__int64 init_attrs()
{
register_attribute("label", 1LL);
register_attribute("bsub_hint_wt", 0LL);
register_attribute("answer", 2LL);
register_attribute("action", 2LL);
return register_attribute("action2", 2LL);
}

canonical_decompiled_code:
__int64 func1()
{
register_attribute("label", 1LL);
register_attribute("bsub_hint_wt", 0LL);
register_attribute("answer", 2LL);
register_attribute("action", 2LL);
return register_attribute("action2", 2LL);
}

original_code:
void init_attrs(void)
{
  int id;
  id = register_attribute("label", STRING_ATTRIBUTE);
  id = register_attribute("bsub_hint_wt", INT_ATTRIBUTE);
  id = register_attribute("answer", TERM_ATTRIBUTE);
  id = register_attribute("action", TERM_ATTRIBUTE);
  id = register_attribute("action2", TERM_ATTRIBUTE);
}

canonical_original_code:
void init_attrs()
{
  int id;
  id = register_attribute("label", STRING_ATTRIBUTE);
  id = register_attribute("bsub_hint_wt", INT_ATTRIBUTE);
  id = register_attribute("answer", TERM_ATTRIBUTE);
  id = register_attribute("action", TERM_ATTRIBUTE);
  id = register_attribute("action2", TERM_ATTRIBUTE);
}

variable_types: id int


decompiled_code:
__int64 __fastcall read_mace4_input(unsigned int a1, __int64 a2, int a3, __int64 a4)
{
__int64 v6; // rax
__int64 v8; // [rsp+8h] [rbp-50h] BYREF
__int64 v9; // [rsp+10h] [rbp-48h] BYREF
_QWORD *v10; // [rsp+18h] [rbp-40h] BYREF
__int64 v11; // [rsp+20h] [rbp-38h] BYREF
__int64 v12[6]; // [rsp+28h] [rbp-30h] BYREF

accept_list("hints", 1LL, 1LL, &v8);
accept_list("goals", 1LL, 0LL, &v11);
accept_list("distinct", 0LL, 0LL, &v10);
accept_list(&unk_672, 1LL, 0LL, v12);
accept_list(&unk_672, 0LL, 0LL, &v9);
print_separator(stdout, "INPUT", 1LL);
read_all_input(a1, a2, stdout, 1LL, (unsigned int)(a3 == 0) + 2);
if ( v9 )
printf("%% term list(s) ignored\n");
if ( v8 )
printf("%% hints list(s) ignored\n");
process_command_line_args(a1, a2, a4);
print_separator(stdout, "end of input", 1LL);
if ( !(unsigned int)option_dependencies_state() )
{
printf("\n%% Enabling option dependencies (ignore applies only on input).\n");
enable_option_dependencies();
}
v6 = process_distinct_terms(v10);
v12[0] = plist_cat(v12[0], v6);
v12[0] = embed_formulas_in_topforms(v12[0], 1LL);
v11 = embed_formulas_in_topforms(v11, 0LL);
print_separator(stdout, "PROCESS NON-CLAUSAL FORMULAS", 1LL);
printf("\n%% Formulas that are not ordinary clauses:\n");
v12[0] = process_input_formulas(v12[0], 1LL);
v11 = process_goal_formulas(v11, 1LL);
print_separator(stdout, "end of process non-clausal formulas", 1LL);
return plist_cat(v12[0], v11);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2, int a3, __int64 a4)
{
__int64 v6; // rax
__int64 v8; // [rsp+8h] [rbp-50h] BYREF
__int64 v9; // [rsp+10h] [rbp-48h] BYREF
_QWORD *v10; // [rsp+18h] [rbp-40h] BYREF
__int64 v11; // [rsp+20h] [rbp-38h] BYREF
__int64 v12[6]; // [rsp+28h] [rbp-30h] BYREF

accept_list("hints", 1LL, 1LL, &v8);
accept_list("goals", 1LL, 0LL, &v11);
accept_list("distinct", 0LL, 0LL, &v10);
accept_list(&unk_672, 1LL, 0LL, v12);
accept_list(&unk_672, 0LL, 0LL, &v9);
print_separator(stdout, "INPUT", 1LL);
read_all_input(a1, a2, stdout, 1LL, (unsigned int)(a3 == 0) + 2);
if ( v9 )
printf("%% term list(s) ignored\n");
if ( v8 )
printf("%% hints list(s) ignored\n");
process_command_line_args(a1, a2, a4);
print_separator(stdout, "end of input", 1LL);
if ( !(unsigned int)option_dependencies_state() )
{
printf("\n%% Enabling option dependencies (ignore applies only on input).\n");
enable_option_dependencies();
}
v6 = func2(v10);
v12[0] = plist_cat(v12[0], v6);
v12[0] = embed_formulas_in_topforms(v12[0], 1LL);
v11 = embed_formulas_in_topforms(v11, 0LL);
print_separator(stdout, "PROCESS NON-CLAUSAL FORMULAS", 1LL);
printf("\n%% Formulas that are not ordinary clauses:\n");
v12[0] = process_input_formulas(v12[0], 1LL);
v11 = process_goal_formulas(v11, 1LL);
print_separator(stdout, "end of process non-clausal formulas", 1LL);
return plist_cat(v12[0], v11);
}

original_code:
static
Plist read_mace4_input(int argc, char **argv, BOOL allow_unknown_things,
        Mace_options opt)
{
  Plist wild_formulas, goals;
  Plist distinct_lists, distinct_forms;
  Plist wild_terms, hints;
  accept_list("hints", FORMULAS, TRUE, &hints);
  accept_list("goals", FORMULAS, FALSE, &goals);
  accept_list("distinct", TERMS, FALSE, &distinct_lists);
  accept_list("", FORMULAS, FALSE, &wild_formulas);
  accept_list("", TERMS, FALSE, &wild_terms);
  print_separator(stdout, "INPUT", TRUE);
  read_all_input(argc, argv, stdout, TRUE,
   allow_unknown_things ? WARN_UNKNOWN : KILL_UNKNOWN);
  if (wild_terms)
    printf("%%   term list(s) ignored\n");
  if (hints)
    printf("%%   hints list(s) ignored\n");
  process_command_line_args(argc, argv, opt);
  print_separator(stdout, "end of input", TRUE);
  if (!option_dependencies_state()) {
    printf("\n%% Enabling option dependencies (ignore applies only on input).\n");
    enable_option_dependencies();
  }
  distinct_forms = process_distinct_terms(distinct_lists);
  wild_formulas = plist_cat(wild_formulas, distinct_forms);
  wild_formulas = embed_formulas_in_topforms(wild_formulas, TRUE);
  goals = embed_formulas_in_topforms(goals, FALSE);
  print_separator(stdout, "PROCESS NON-CLAUSAL FORMULAS", TRUE);
  printf("\n%% Formulas that are not ordinary clauses:\n");
  wild_formulas = process_input_formulas(wild_formulas, TRUE);
  goals = process_goal_formulas(goals, TRUE);
  print_separator(stdout, "end of process non-clausal formulas", TRUE);
  wild_formulas = plist_cat(wild_formulas, goals);
  return wild_formulas;
}

canonical_original_code:
static struct plist *read_mace4_input(int argc, char **argv, enum BOOL allow_unknown_things, struct mace_options *opt)
{
  struct plist *wild_formulas; struct plist *goals;
  struct plist *distinct_lists; struct plist *distinct_forms;
  struct plist *wild_terms; struct plist *hints;
  accept_list("hints", FORMULAS, TRUE, &hints);
  accept_list("goals", FORMULAS, FALSE, &goals);
  accept_list("distinct", TERMS, FALSE, &distinct_lists);
  accept_list("", FORMULAS, FALSE, &wild_formulas);
  accept_list("", TERMS, FALSE, &wild_terms);
  print_separator(stdout, "INPUT", TRUE);
  read_all_input(argc, argv, stdout, TRUE,
   allow_unknown_things ? WARN_UNKNOWN : KILL_UNKNOWN);
  if (wild_terms)
    printf("%%   term list(s) ignored\n");
  if (hints)
    printf("%%   hints list(s) ignored\n");
  process_command_line_args(argc, argv, opt);
  print_separator(stdout, "end of input", TRUE);
  if (!option_dependencies_state()) {
    printf("\n%% Enabling option dependencies (ignore applies only on input).\n");
    enable_option_dependencies();
  }
  distinct_forms = process_distinct_terms(distinct_lists);
  wild_formulas = plist_cat(wild_formulas, distinct_forms);
  wild_formulas = embed_formulas_in_topforms(wild_formulas, TRUE);
  goals = embed_formulas_in_topforms(goals, FALSE);
  print_separator(stdout, "PROCESS NON-CLAUSAL FORMULAS", TRUE);
  printf("\n%% Formulas that are not ordinary clauses:\n");
  wild_formulas = process_input_formulas(wild_formulas, TRUE);
  goals = process_goal_formulas(goals, TRUE);
  print_separator(stdout, "end of process non-clausal formulas", TRUE);
  wild_formulas = plist_cat(wild_formulas, goals);
  return wild_formulas;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct mace_options { int print_models; int domain_size; int iterate; } *

return_type: struct plist { void *v; struct plist *next; } *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // rbx
__int64 v5; // rax
_BYTE v6[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = member_args(argc, argv, "-c");
init_standard_ladr();
init_mace_options(v6);
init_attrs();
if ( !(unsigned int)member_args((unsigned int)argc, argv, "help")
&& !(unsigned int)member_args((unsigned int)argc, argv, "-help") )
{
print_banner((unsigned int)argc, argv, "Mace4", "2009-11A", "November 2009", 0LL);
set_program_name("Mace4");
signal(2, (__sighandler_t)mace4_sig_handler);
signal(10, (__sighandler_t)mace4_sig_handler);
signal(11, (__sighandler_t)mace4_sig_handler);
v4 = read_mace4_input(argc, (__int64)argv, v3, (__int64)v6);
print_separator(stdout, "CLAUSES FOR SEARCH", 1LL);
fwrite_clause_list(stdout, v4, "mace4_clauses", 1LL);
print_separator(stdout, "end of clauses for search", 1LL);
v5 = mace4(v4, v6);
mace4_exit(*(unsigned int *)(v5 + 24));
exit(0);
}
usage_message(stderr, v6);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // rbx
__int64 v5; // rax
_BYTE v6[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = member_args(argc, argv, "-c");
init_standard_ladr();
init_mace_options(v6);
func1();
if ( !(unsigned int)member_args((unsigned int)argc, argv, "help")
&& !(unsigned int)member_args((unsigned int)argc, argv, "-help") )
{
print_banner((unsigned int)argc, argv, "Mace4", "2009-11A", "November 2009", 0LL);
set_program_name("Mace4");
signal(2, (__sighandler_t)mace4_sig_handler);
signal(10, (__sighandler_t)mace4_sig_handler);
signal(11, (__sighandler_t)mace4_sig_handler);
v4 = func3(argc, (__int64)argv, v3, (__int64)v6);
print_separator(stdout, "CLAUSES FOR SEARCH", 1LL);
fwrite_clause_list(stdout, v4, "mace4_clauses", 1LL);
print_separator(stdout, "end of clauses for search", 1LL);
v5 = mace4(v4, v6);
mace4_exit(*(unsigned int *)(v5 + 24));
exit(0);
}
usage_message(stderr, v6);
exit(1);
}

original_code:
int main(int argc, char **argv)
{
  struct mace_options opt;
  Plist clauses;
  Mace_results results;
  BOOL prover_compatability_mode = member_args(argc, argv, "-c");
  init_standard_ladr();
  init_mace_options(&opt);
  init_attrs();
  if (member_args(argc, argv, "help") ||
      member_args(argc, argv, "-help")) {
    usage_message(stderr, &opt);
    exit(1);
  }
  print_banner(argc, argv, "Mace4", "2009-11A", "November 2009", FALSE);
  set_program_name("Mace4");
  signal(2, mace4_sig_handler);
  signal(10, mace4_sig_handler);
  signal(11, mace4_sig_handler);
  clauses = read_mace4_input(argc, argv, prover_compatability_mode, &opt);
  print_separator(stdout, "CLAUSES FOR SEARCH", TRUE);
  fwrite_clause_list(stdout, clauses, "mace4_clauses", CL_FORM_BARE);
  print_separator(stdout, "end of clauses for search", TRUE);
  results = mace4(clauses, &opt);
  mace4_exit(results->return_code);
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct mace_options opt;
  struct plist *clauses;
  struct mace_results *results;
  enum BOOL prover_compatability_mode = member_args(argc, argv, "-c");
  init_standard_ladr();
  init_mace_options(&opt);
  init_attrs();
  if (member_args(argc, argv, "help") ||
      member_args(argc, argv, "-help")) {
    usage_message(stderr, &opt);
    exit(1);
  }
  print_banner(argc, argv, "Mace4", "2009-11A", "November 2009", FALSE);
  set_program_name("Mace4");
  signal(2, mace4_sig_handler);
  signal(10, mace4_sig_handler);
  signal(11, mace4_sig_handler);
  clauses = read_mace4_input(argc, argv, prover_compatability_mode, &opt);
  print_separator(stdout, "CLAUSES FOR SEARCH", TRUE);
  fwrite_clause_list(stdout, clauses, "mace4_clauses", CL_FORM_BARE);
  print_separator(stdout, "end of clauses for search", TRUE);
  results = mace4(clauses, &opt);
  mace4_exit(results->return_code);
  exit(0);
}

variable_types: struct mace_options { int print_models; int domain_size; int iterate; }

variable_types: struct mace_results { enum BOOL { FALSE=0, TRUE=1 } success; struct plist { void *v; struct plist *next; } *models; double user_seconds; int return_code; } *

user_defined_types: struct mace_results { enum BOOL success; struct plist *models; double user_seconds; int return_code; }


decompiled_code:
__int64 __fastcall pvalues_check(__int64 *a1, int a2)
{
__int64 *v2; // rax
__int64 v3; // rsi
__int64 v4; // rcx
__int64 result; // rax

if ( a2 <= 0 )
{
LABEL_9:
fatal_error("pvalues_check: no possible values\n");
result = 0LL;
}
else
{
v2 = a1;
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v4 = 0LL;
do
{
if ( *v2 )
{
if ( v4 )
{
v4 = 0LL;
goto LABEL_8;
}
v4 = *v2;
}
++v2;
}
while ( v2 != (__int64 *)v3 );
if ( !v4 )
goto LABEL_9;
LABEL_8:
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, int a2)
{
__int64 *v2; // rax
__int64 v3; // rsi
__int64 v4; // rcx
__int64 result; // rax

if ( a2 <= 0 )
{
LABEL_9:
fatal_error("pvalues_check: no possible values\n");
result = 0LL;
}
else
{
v2 = a1;
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v4 = 0LL;
do
{
if ( *v2 )
{
if ( v4 )
{
v4 = 0LL;
goto LABEL_8;
}
v4 = *v2;
}
++v2;
}
while ( v2 != (__int64 *)v3 );
if ( !v4 )
goto LABEL_9;
LABEL_8:
result = v4;
}
return result;
}

original_code:
static
Term pvalues_check(Term *a, int n)
{
  Term b = ((void *)0);
  int i;
  for (i = 0; i < n; i++) {
    if (a[i] != ((void *)0)) {
      if (b != ((void *)0))
 return ((void *)0);
      else
 b = a[i];
    }
  }
  if (b == ((void *)0))
    fatal_error("pvalues_check: no possible values\n");
  return b;
}

canonical_original_code:
static struct term *pvalues_check(struct term **a, int n)
{
  struct term *b = ((void *)0);
  int i;
  for (i = 0; i < n; i++) {
    if (a[i] != ((void *)0)) {
      if (b != ((void *)0))
 return ((void *)0);
      else
 b = a[i];
    }
  }
  if (b == ((void *)0))
    fatal_error("pvalues_check: no possible values\n");
  return b;
}

variable_types:
a
struct term **

variable_types: n int

variable_types: i int


eterm

decompiled_code:
__int64 __fastcall eterm(__int64 a1, _DWORD *a2)
{
unsigned int v3; // er12
int v5; // esi
__int64 v6; // rdx
int v7; // ecx
int v8; // eax

*a2 = -1;
if ( !a1 )
return 0;
v3 = 0;
if ( *(int *)a1 < 0 )
{
v3 = arith_rel_term();
if ( v3 )
{
v3 = 0;
}
else if ( !(unsigned int)arith_op_term(a1) )
{
v5 = *(_DWORD *)(*(_QWORD *)(Sn_to_mace_sn + 8LL * -*(_DWORD *)a1) + 16LL);
LODWORD(v6) = *(unsigned __int8 *)(a1 + 4) - 1;
if ( (int)v6 < 0 )
{
LABEL_11:
*a2 = v5;
v3 = 1;
}
else
{
v6 = (int)v6;
v7 = 1;
while ( 1 )
{
v8 = **(_DWORD **)(*(_QWORD *)(a1 + 8) + 8 * v6);
if ( v8 < 0 )
break;
v5 += v7 * v8;
v7 *= Domain_size;
if ( (int)--v6 < 0 )
goto LABEL_11;
}
v3 = 0;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
unsigned int v3; // er12
int v5; // esi
__int64 v6; // rdx
int v7; // ecx
int v8; // eax

*a2 = -1;
if ( !a1 )
return 0;
v3 = 0;
if ( *(int *)a1 < 0 )
{
v3 = arith_rel_term();
if ( v3 )
{
v3 = 0;
}
else if ( !(unsigned int)arith_op_term(a1) )
{
v5 = *(_DWORD *)(*(_QWORD *)(Sn_to_mace_sn + 8LL * -*(_DWORD *)a1) + 16LL);
LODWORD(v6) = *(unsigned __int8 *)(a1 + 4) - 1;
if ( (int)v6 < 0 )
{
LABEL_11:
*a2 = v5;
v3 = 1;
}
else
{
v6 = (int)v6;
v7 = 1;
while ( 1 )
{
v8 = **(_DWORD **)(*(_QWORD *)(a1 + 8) + 8 * v6);
if ( v8 < 0 )
break;
v5 += v7 * v8;
v7 *= Domain_size;
if ( (int)--v6 < 0 )
goto LABEL_11;
}
v3 = 0;
}
}
}
return v3;
}

original_code:
BOOL eterm(Term t, int *pid)
{
  *pid = -1;
  if (t == ((void *)0) || ((t)->private_symbol >= 0) || arith_rel_term(t) || arith_op_term(t))
    return FALSE;
  else {
    int i;
    int mult = 1;
    int id = Sn_to_mace_sn[(-((t)->private_symbol))]->base;
    for (i = ((t)->arity)-1; i >= 0; i--) {
      if (!((((t)->args[i]))->private_symbol >= 0))
        return FALSE;
      else
        id += ((((t)->args[i]))->private_symbol) * mult;
      mult *= Domain_size;
    }
    *pid = id;
    return TRUE;
  }
}

canonical_original_code:
enum BOOL eterm(struct term *t, int *pid)
{
  *pid = -1;
  if (t == ((void *)0) || ((t)->private_symbol >= 0) || arith_rel_term(t) || arith_op_term(t))
    return FALSE;
  else {
    int i;
    int mult = 1;
    int id = Sn_to_mace_sn[(-((t)->private_symbol))]->base;
    for (i = ((t)->arity)-1; i >= 0; i--) {
      if (!((((t)->args[i]))->private_symbol >= 0))
        return FALSE;
      else
        id += ((((t)->args[i]))->private_symbol) * mult;
      mult *= Domain_size;
    }
    *pid = id;
    return TRUE;
  }
}

variable_types:
pid
int *

variable_types: mult int


decompiled_code:
__int64 __fastcall decode_eterm_id(int a1)
{
unsigned int *v1; // r12
__int64 v2; // r13
unsigned int v3; // er14
int v4; // ebx
int v5; // ebp
int v6; // eax

v1 = *(unsigned int **)(Cells + 56LL * a1 + 48);
v2 = get_rigid_term_dangerously(*v1, v1[2]);
v3 = Domain_size;
v4 = a1 - v1[4];
v5 = v1[2] - 1;
if ( v5 >= 0 )
{
do
{
v6 = int_power(v3, (unsigned int)v5);
*(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL * (int)(v1[2] + ~v5)) = *(_QWORD *)(Domain + 8LL * (v4 / v6));
v4 %= v6;
--v5;
}
while ( v5 != -1 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int *v1; // r12
__int64 v2; // r13
unsigned int v3; // er14
int v4; // ebx
int v5; // ebp
int v6; // eax

v1 = *(unsigned int **)(Cells + 56LL * a1 + 48);
v2 = get_rigid_term_dangerously(*v1, v1[2]);
v3 = Domain_size;
v4 = a1 - v1[4];
v5 = v1[2] - 1;
if ( v5 >= 0 )
{
do
{
v6 = int_power(v3, (unsigned int)v5);
*(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL * (int)(v1[2] + ~v5)) = *(_QWORD *)(Domain + 8LL * (v4 / v6));
v4 %= v6;
--v5;
}
while ( v5 != -1 );
}
return v2;
}

original_code:
Term decode_eterm_id(int id)
{
  Symbol_data s = Cells[id].symbol;
  Term t = get_rigid_term_dangerously(s->sn, s->arity);
  int n = Domain_size;
  int x = id - s->base;
  int i;
  for (i = s->arity - 1; i >= 0; i--) {
    int p = int_power(n, i);
    int e = x / p;
    ((t)->args[(s->arity-1) - i]) = Domain[e];
    x = x % p;
  }
  return t;
}

canonical_original_code:
struct term *decode_eterm_id(int id)
{
  struct symbol_data *s = Cells[id].symbol;
  struct term *t = get_rigid_term_dangerously(s->sn, s->arity);
  int n = Domain_size;
  int x = id - s->base;
  int i;
  for (i = s->arity - 1; i >= 0; i--) {
    int p = int_power(n, i);
    int e = x / p;
    ((t)->args[(s->arity-1) - i]) = Domain[e];
    x = x % p;
  }
  return t;
}

variable_types: struct symbol_data { int sn; int mace_sn; int arity; int type; int base; int attribute; struct symbol_data *next; } *

variable_types: x int

variable_types: p int

variable_types: e int


decompiled_code:
__int64 init_standard_options()
{
__int64 result; // rax

Prolog_style_variables = init_flag("prolog_style_variables", 0LL);
init_flag("ignore_option_dependencies", 0LL);
result = init_flag("clocks", 0LL);
Clocks = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

Prolog_style_variables = init_flag("prolog_style_variables", 0LL);
init_flag("ignore_option_dependencies", 0LL);
result = init_flag("clocks", 0LL);
Clocks = result;
return result;
}

original_code:
void init_standard_options(void)
{
  Prolog_style_variables = init_flag("prolog_style_variables", FALSE);
  Ignore_option_dependencies = init_flag("ignore_option_dependencies", FALSE);
  Clocks = init_flag("clocks", FALSE);
}

canonical_original_code:
void init_standard_options()
{
  Prolog_style_variables = init_flag("prolog_style_variables", FALSE);
  Ignore_option_dependencies = init_flag("ignore_option_dependencies", FALSE);
  Clocks = init_flag("clocks", FALSE);
}


decompiled_code:
__int64 process_standard_options()
{
__int64 result; // rax

if ( (unsigned int)flag((unsigned int)Clocks) )
enable_clocks();
else
disable_clocks();
if ( (unsigned int)flag((unsigned int)Prolog_style_variables) )
result = set_variable_style(1LL);
else
result = set_variable_style(0LL);
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

if ( (unsigned int)flag((unsigned int)Clocks) )
enable_clocks();
else
disable_clocks();
if ( (unsigned int)flag((unsigned int)Prolog_style_variables) )
result = set_variable_style(1LL);
else
result = set_variable_style(0LL);
return result;
}

original_code:
void process_standard_options(void)
{
  if (flag(Clocks))
    enable_clocks();
  else
    disable_clocks();
  if (flag(Prolog_style_variables))
    set_variable_style(PROLOG_STYLE);
  else
    set_variable_style(STANDARD_STYLE);
}

canonical_original_code:
void process_standard_options()
{
  if (flag(Clocks))
    enable_clocks();
  else
    disable_clocks();
  if (flag(Prolog_style_variables))
    set_variable_style(PROLOG_STYLE);
  else
    set_variable_style(STANDARD_STYLE);
}


decompiled_code:
__int64 clocks_id()
{
return (unsigned int)Clocks;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)Clocks;
}

original_code:
int clocks_id(void)
{
  return Clocks;
}

canonical_original_code:
int clocks_id()
{
  return Clocks;
}


decompiled_code:
__int64 prolog_style_variables_id()
{
return (unsigned int)Prolog_style_variables;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)Prolog_style_variables;
}

original_code:
int prolog_style_variables_id(void)
{
  return Prolog_style_variables;
}

canonical_original_code:
int prolog_style_variables_id()
{
  return Prolog_style_variables;
}


decompiled_code:
unsigned int *__fastcall vars_to_names(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
_QWORD *v3; // r12
char *v5; // r12
void *v6; // r13
int v7; // ebp
const char *v8; // rax
char *v9; // r13
char *v10; // rbp
__int64 v11; // r12

v1 = a1;
if ( (*a1 & 0x80000000) == 0 )
{
v5 = (char *)malloc(0x19uLL);
v6 = malloc(0x19uLL);
v7 = variable_style();
v8 = (const char *)int_to_str(*a1, v6, 25LL);
v9 = (char *)v8;
switch ( v7 )
{
case 1:
strcpy(v5, "VAR_");
break;
case 2:
*v5 = 0;
break;
case 0:
strcpy(v5, "var_");
break;
}
strcat(v5, v8);
v10 = v5;
v11 = get_rigid_term(v5, 0LL);
free_term(a1);
free(v10);
free(v9);
v1 = (unsigned int *)v11;
}
else
{
v2 = 0LL;
if ( *((_BYTE *)a1 + 4) )
{
do
{
v3 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2);
*v3 = vars_to_names(*v3);
++v2;
}
while ( *((unsigned __int8 *)a1 + 4) > (int)v2 );
}
}
return v1;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
_QWORD *v3; // r12
char *v5; // r12
void *v6; // r13
int v7; // ebp
const char *v8; // rax
char *v9; // r13
char *v10; // rbp
__int64 v11; // r12

v1 = a1;
if ( (*a1 & 0x80000000) == 0 )
{
v5 = (char *)malloc(0x19uLL);
v6 = malloc(0x19uLL);
v7 = variable_style();
v8 = (const char *)int_to_str(*a1, v6, 25LL);
v9 = (char *)v8;
switch ( v7 )
{
case 1:
strcpy(v5, "VAR_");
break;
case 2:
*v5 = 0;
break;
case 0:
strcpy(v5, "var_");
break;
}
strcat(v5, v8);
v10 = v5;
v11 = get_rigid_term(v5, 0LL);
free_term(a1);
free(v10);
free(v9);
v1 = (unsigned int *)v11;
}
else
{
v2 = 0LL;
if ( *((_BYTE *)a1 + 4) )
{
do
{
v3 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2);
*v3 = func0(*v3);
++v2;
}
while ( *((unsigned __int8 *)a1 + 4) > (int)v2 );
}
}
return v1;
}

original_code:
static
Term vars_to_names(Term t)
{
  if (((t)->private_symbol >= 0)) {
    Term a;
    char *s1 = malloc(25);
    char *s2 = malloc(25);
    Variable_style v = variable_style();
    s2 = int_to_str(((t)->private_symbol), s2, 25);
    switch (v) {
    case INTEGER_STYLE: s1 = strcpy(s1, ""); break;
    case STANDARD_STYLE: s1 = strcpy(s1, "var_"); break;
    case PROLOG_STYLE: s1 = strcpy(s1, "VAR_"); break;
    }
    s1 = strcat(s1, s2);
    a = get_rigid_term(s1, 0);
    free_term(t);
    free(s1);
    free(s2);
    return a;
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = vars_to_names(((t)->args[i]));
    return t;
  }
}

canonical_original_code:
static struct term *vars_to_names(struct term *t)
{
  if (((t)->private_symbol >= 0)) {
    struct term *a;
    char *s1 = malloc(25);
    char *s2 = malloc(25);
    enum Variable_style v = variable_style();
    s2 = int_to_str(((t)->private_symbol), s2, 25);
    switch (v) {
    case INTEGER_STYLE: s1 = strcpy(s1, ""); break;
    case STANDARD_STYLE: s1 = strcpy(s1, "var_"); break;
    case PROLOG_STYLE: s1 = strcpy(s1, "VAR_"); break;
    }
    s1 = strcat(s1, s2);
    a = get_rigid_term(s1, 0);
    free_term(t);
    free(s1);
    free(s2);
    return a;
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = vars_to_names(((t)->args[i]));
    return t;
  }
}

variable_types:
t
struct term *

variable_types: struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *

variable_types: enum Variable_style { STANDARD_STYLE=0, PROLOG_STYLE=1, INTEGER_STYLE=2 }


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

if ( a1 )
{
zap_tlist(a1[1]);
zap_term(*a1);
result = free_plist(a1);
}
return result;
}

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

if ( a1 )
{
func0(a1[1]);
zap_term(*a1);
result = free_plist(a1);
}
return result;
}

original_code:
void zap_tlist(Plist p)
{
  if (p != ((void *)0)) {
    zap_tlist(p->next);
    zap_term(p->v);
    free_plist(p);
  }
}

canonical_original_code:
void zap_tlist(struct plist *p)
{
  if (p != ((void *)0)) {
    zap_tlist(p->next);
    zap_term(p->v);
    free_plist(p);
  }
}

variable_types: struct plist { void *v; struct plist *next; } *


decompiled_code:
__int64 __fastcall constants_in_term(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r12

v2 = a2;
if ( *(int *)a1 < 0 )
{
v3 = 0LL;
if ( *(_BYTE *)(a1 + 4) )
{
do
v2 = constants_in_term(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v3++), v2);
while ( *(unsigned __int8 *)(a1 + 4) > (int)v3 );
}
else if ( !(unsigned int)ilist_member(a2, (unsigned int)-*(_DWORD *)a1) )
{
v2 = ilist_prepend(a2, (unsigned int)-*(_DWORD *)a1);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r12

v2 = a2;
if ( *(int *)a1 < 0 )
{
v3 = 0LL;
if ( *(_BYTE *)(a1 + 4) )
{
do
v2 = func2(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v3++), v2);
while ( *(unsigned __int8 *)(a1 + 4) > (int)v3 );
}
else if ( !(unsigned int)ilist_member(a2, (unsigned int)-*(_DWORD *)a1) )
{
v2 = ilist_prepend(a2, (unsigned int)-*(_DWORD *)a1);
}
}
return v2;
}

original_code:
Ilist constants_in_term(Term t, Ilist p)
{
  if (((t)->private_symbol >= 0))
    return p;
  else if (((t)->private_symbol < 0 && (t)->arity == 0)) {
    if (ilist_member(p, (-((t)->private_symbol))))
      return p;
    else
      return ilist_prepend(p, (-((t)->private_symbol)));
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      p = constants_in_term(((t)->args[i]), p);
    return p;
  }
}

canonical_original_code:
struct ilist *constants_in_term(struct term *t, struct ilist *p)
{
  if (((t)->private_symbol >= 0))
    return p;
  else if (((t)->private_symbol < 0 && (t)->arity == 0)) {
    if (ilist_member(p, (-((t)->private_symbol))))
      return p;
    else
      return ilist_prepend(p, (-((t)->private_symbol)));
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      p = constants_in_term(((t)->args[i]), p);
    return p;
  }
}

variable_types:
p
struct ilist *

return_type: struct ilist { int i; struct ilist *next; } *


decompiled_code:
int p_clash_mem()
{
return fprint_clash_mem(stdout, 1);
}

canonical_decompiled_code:
int func4()
{
return func3(stdout, 1);
}

original_code:
void p_clash_mem()
{
  fprint_clash_mem(stdout, TRUE);
}


decompiled_code:
__int64 __fastcall apply_lit(unsigned int *a1)
{
__int64 v1; // rax

v1 = apply(*((_QWORD *)a1 + 1));
return new_literal(*a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
__int64 v1; // rax

v1 = apply(*((_QWORD *)a1 + 1));
return new_literal(*a1, v1);
}

original_code:
Literals apply_lit(Literals lit, Context c)
{
  return new_literal(lit->sign, apply(lit->atom, c));
}

canonical_original_code:
struct literals *apply_lit(struct literals *lit, struct context *c)
{
  return new_literal(lit->sign, apply(lit->atom, c));
}

variable_types:
lit
struct literals *

variable_types: struct context { struct term *terms[100]; struct context *contexts[100]; int multiplier; struct term *partial_term; } *

return_type: struct literals { enum BOOL { FALSE=0, TRUE=1 } sign; struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *atom; struct literals *next; } *

user_defined_types: struct literals { enum BOOL sign; struct term *atom; struct literals *next; }