decompiled_code:
__int64 __fastcall lex_rewritable(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbx
unsigned int v6; // ebp

v5 = apply(a3);
v6 = term_greater(a1, v5, a4);
zap_term(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbx
unsigned int v6; // ebp

v5 = apply(a3);
v6 = term_greater(a1, v5, a4);
zap_term(v5);
return v6;
}

original_code:
static
BOOL lex_rewritable(Term subject, Context subst, Term gen,
      BOOL lex_order_vars)
{
  Term instance = apply(gen, subst);
  BOOL result = term_greater(subject, instance, lex_order_vars);
  zap_term(instance);
  return result;
}

canonical_original_code:
static enum BOOL lex_rewritable(struct term *subject, struct context *subst, struct term *gen, enum BOOL lex_order_vars)
{
  struct term *instance = apply(gen, subst);
  enum BOOL result = term_greater(subject, instance, lex_order_vars);
  zap_term(instance);
  return result;
}

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

variable_types:
gen
struct term *

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


repo: jessealama/ladr

decompiled_code:
__int64 __fastcall claim_term_flag(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rcx

result = 0LL;
while ( 1 )
{
v4 = (unsigned int)result;
if ( !bits_in_use[result] )
break;
if ( ++result == 8 )
goto LABEL_4;
}
if ( (unsigned int)result > 7 )
{
LABEL_4:
fatal_error("claim_term_flag, no more flags are available", a2, a3, v4);
return 0xFFFFFFFFLL;
}
bits_in_use[(int)result] = 1;
return (unsigned int)result;
}

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

result = 0LL;
while ( 1 )
{
v4 = (unsigned int)result;
if ( !bits_in_use[result] )
break;
if ( ++result == 8 )
goto LABEL_4;
}
if ( (unsigned int)result > 7 )
{
LABEL_4:
fatal_error("claim_term_flag, no more flags are available", a2, a3, v4);
return 0xFFFFFFFFLL;
}
bits_in_use[(int)result] = 1;
return (unsigned int)result;
}

original_code:
int claim_term_flag()
{
  int i = 0;
  while (i < (sizeof(unsigned char) * 8) && bits_in_use[i])
    i++;
  if (i < (sizeof(unsigned char) * 8)) {
    bits_in_use[i] = 1;
    return i;
  }
  else {
    fatal_error("claim_term_flag, no more flags are available");
    return -1;
  }
}

variable_types: i int

return_type: int


decompiled_code:
void __fastcall release_term_flag(int a1)
{
bits_in_use[a1] = 0;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
bits_in_use[a1] = 0;
}

original_code:
void release_term_flag(int bit)
{
  bits_in_use[bit] = 0;
}

variable_types: bit int

return_type: void


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

if ( a2 <= 7 )
{
result = (unsigned int)(1 << a2);
*(_BYTE *)(a1 + 5) |= result;
}
return result;
}

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

if ( a2 <= 7 )
{
result = (unsigned int)(1 << a2);
*(_BYTE *)(a1 + 5) |= result;
}
return result;
}

original_code:
void term_flag_set(Term t, int flag)
{
  if (flag >= 0 && flag < (sizeof(unsigned char) * 8))
    (t->private_flags = (t->private_flags) | (1 << flag));
}

canonical_original_code:
void term_flag_set(struct term *t, int flag)
{
  if (flag >= 0 && flag < (sizeof(unsigned char) * 8))
    (t->private_flags = (t->private_flags) | (1 << flag));
}

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


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

if ( a2 <= 7 )
{
result = (unsigned int)__ROL4__(-2, a2);
*(_BYTE *)(a1 + 5) &= result;
}
return result;
}

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

if ( a2 <= 7 )
{
result = (unsigned int)__ROL4__(-2, a2);
*(_BYTE *)(a1 + 5) &= result;
}
return result;
}

original_code:
void term_flag_clear(Term t, int flag)
{
  if (flag >= 0 && flag < (sizeof(unsigned char) * 8))
    (t->private_flags = (t->private_flags) & ~(1 << flag));
}

canonical_original_code:
void term_flag_clear(struct term *t, int flag)
{
  if (flag >= 0 && flag < (sizeof(unsigned char) * 8))
    (t->private_flags = (t->private_flags) & ~(1 << flag));
}

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


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

result = 0LL;
if ( a2 <= 7 )
result = ((int)*(unsigned __int8 *)(a1 + 5) >> a2) & 1;
return result;
}

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

result = 0LL;
if ( a2 <= 7 )
result = ((int)*(unsigned __int8 *)(a1 + 5) >> a2) & 1;
return result;
}

original_code:
BOOL term_flag(Term t, int flag)
{
  if (flag < 0 || flag >= (sizeof(unsigned char) * 8))
    return FALSE;
  else if ((t->private_flags & 1 << flag))
    return TRUE;
  else
    return FALSE;
}

canonical_original_code:
enum BOOL term_flag(struct term *t, int flag)
{
  if (flag < 0 || flag >= (sizeof(unsigned char) * 8))
    return FALSE;
  else if ((t->private_flags & 1 << flag))
    return TRUE;
  else
    return FALSE;
}

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


decompiled_code:
__int64 term_flags()
{
return 8LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 8LL;
}

original_code:
int term_flags()
{
  return (sizeof(unsigned char) * 8);
}


original_code:
Term copy_term_with_flags(Term t)
{
  Term t2;
  if (((t)->private_symbol >= 0))
    t2 = get_variable_term(((t)->private_symbol));
  else {
    int i;
    t2 = get_rigid_term_like(t);
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = copy_term_with_flags(((t)->args[i]));
  }
  t2->private_flags = t->private_flags;
  return t2;
}

canonical_original_code:
struct term *copy_term_with_flags(struct term *t)
{
  struct term *t2;
  if (((t)->private_symbol >= 0))
    t2 = get_variable_term(((t)->private_symbol));
  else {
    int i;
    t2 = get_rigid_term_like(t);
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = copy_term_with_flags(((t)->args[i]));
  }
  t2->private_flags = t->private_flags;
  return t2;
}

variable_types:
t
struct term *

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 copy_term_with_flag(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v4; // rbp
_QWORD *v5; // r14

if ( *(int *)a1 < 0 )
{
v2 = get_rigid_term_like(a1);
if ( *(_BYTE *)(a1 + 4) )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)(*(_QWORD *)(v2 + 8) + 8 * v4);
*v5 = copy_term_with_flag(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v4++), a2);
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v4 );
}
}
else
{
v2 = get_variable_term();
}
if ( (unsigned int)term_flag(a1, a2) )
term_flag_set(v2, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v4; // rbp
_QWORD *v5; // r14

if ( *(int *)a1 < 0 )
{
v2 = get_rigid_term_like(a1);
if ( *(_BYTE *)(a1 + 4) )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)(*(_QWORD *)(v2 + 8) + 8 * v4);
*v5 = func7(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v4++), a2);
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v4 );
}
}
else
{
v2 = get_variable_term();
}
if ( (unsigned int)func4(a1, a2) )
func2(v2, a2);
return v2;
}

original_code:
Term copy_term_with_flag(Term t, int flag)
{
  Term t2;
  if (((t)->private_symbol >= 0))
    t2 = get_variable_term(((t)->private_symbol));
  else {
    int i;
    t2 = get_rigid_term_like(t);
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = copy_term_with_flag(((t)->args[i]), flag);
  }
  if (term_flag(t, flag))
    term_flag_set(t2, flag);
  return t2;
}

canonical_original_code:
struct term *copy_term_with_flag(struct term *t, int flag)
{
  struct term *t2;
  if (((t)->private_symbol >= 0))
    t2 = get_variable_term(((t)->private_symbol));
  else {
    int i;
    t2 = get_rigid_term_like(t);
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = copy_term_with_flag(((t)->args[i]), flag);
  }
  if (term_flag(t, flag))
    term_flag_set(t2, flag);
  return t2;
}


decompiled_code:
__int64 __fastcall term_flag_clear_recursively(__int64 a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // rbx

result = term_flag_clear(a1, a2);
if ( *(_BYTE *)(a1 + 4) )
{
v3 = 0LL;
do
{
term_flag_clear_recursively(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v3++), a2);
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // rbx

result = func3(a1, a2);
if ( *(_BYTE *)(a1 + 4) )
{
v3 = 0LL;
do
{
func8(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v3++), a2);
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v3 );
}
return result;
}

original_code:
void term_flag_clear_recursively(Term t, int flag)
{
  int i;
  term_flag_clear(t, flag);
  for (i = 0; i < ((t)->arity); i++)
    term_flag_clear_recursively(((t)->args[i]), flag);
}

canonical_original_code:
void term_flag_clear_recursively(struct term *t, int flag)
{
  int i;
  term_flag_clear(t, flag);
  for (i = 0; i < ((t)->arity); i++)
    term_flag_clear_recursively(((t)->args[i]), flag);
}


decompiled_code:
__int64 get_fatal_exit_code()
{
return (unsigned int)Fatal_exit_code;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)Fatal_exit_code;
}

original_code:
int get_fatal_exit_code()
{
  return Fatal_exit_code;
}


decompiled_code:
void __fastcall set_fatal_exit_code(int a1)
{
Fatal_exit_code = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
Fatal_exit_code = a1;
}

original_code:
void set_fatal_exit_code(int exit_code)
{
  Fatal_exit_code = exit_code;
}


decompiled_code:
void __fastcall __noreturn fatal_error(const char *a1)
{
fprintf(stdout, "\nFatal error: %s\n\n", a1);
fprintf(stderr, "\nFatal error: %s\n\n", a1);
exit(Fatal_exit_code);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
fprintf(stdout, "\nFatal error: %s\n\n", a1);
fprintf(stderr, "\nFatal error: %s\n\n", a1);
exit(Fatal_exit_code);
}

original_code:
void fatal_error(char *message)
{
  fprintf(stdout, "\nFatal error:  %s\n\n", message);
  fprintf(stderr, "\nFatal error:  %s\n\n", message);
  exit(Fatal_exit_code);
}

variable_types:
message
char *


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

result = get_cmem(3LL);
++Discrim_gets;
return result;
}

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

result = get_cmem(3LL);
++Discrim_gets;
return result;
}

original_code:
Discrim get_discrim(void)
{
  Discrim p = get_cmem(((sizeof(struct discrim))%(sizeof(void *)) == 0 ? (sizeof(struct discrim))/(sizeof(void *)) : (sizeof(struct discrim))/(sizeof(void *)) + 1));
  Discrim_gets++;
  return(p);
}

canonical_original_code:
struct discrim *get_discrim()
{
  struct discrim *p = get_cmem(((sizeof(struct discrim))%(sizeof(void *)) == 0 ? (sizeof(struct discrim))/(sizeof(void *)) : (sizeof(struct discrim))/(sizeof(void *)) + 1));
  Discrim_gets++;
  return(p);
}

variable_types: struct discrim { struct discrim *next; union { struct discrim *kids; struct plist { void *v; struct plist *next; } *data; } u; short symbol; char type; } *

user_defined_types: struct discrim { struct discrim *next; union { struct discrim *kids; struct plist *data; } u; short symbol; char type; }


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

result = free_mem(a1, 3LL);
++Discrim_frees;
return result;
}

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

result = free_mem(a1, 3LL);
++Discrim_frees;
return result;
}

original_code:
void free_discrim(Discrim p)
{
  free_mem(p, ((sizeof(struct discrim))%(sizeof(void *)) == 0 ? (sizeof(struct discrim))/(sizeof(void *)) : (sizeof(struct discrim))/(sizeof(void *)) + 1));
  Discrim_frees++;
}

canonical_original_code:
void free_discrim(struct discrim *p)
{
  free_mem(p, ((sizeof(struct discrim))%(sizeof(void *)) == 0 ? (sizeof(struct discrim))/(sizeof(void *)) : (sizeof(struct discrim))/(sizeof(void *)) + 1));
  Discrim_frees++;
}

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


decompiled_code:
__int64 __fastcall zap_discrim_tree(__int64 a1, int a2)
{
__int64 *v2; // rbx
int v4; // eax
__int64 *v5; // rbp
char v6; // al

if ( a2 )
{
v2 = *(__int64 **)(a1 + 8);
if ( v2 )
{
while ( 1 )
{
v6 = *((_BYTE *)v2 + 18);
if ( (unsigned __int8)(v6 - 2) > 1u && v6 )
v4 = sn_to_arity((unsigned int)*((__int16 *)v2 + 8));
else
v4 = 0;
v5 = (__int64 *)*v2;
zap_discrim_tree(v2, (unsigned int)(v4 + a2 - 1));
if ( !v5 )
break;
v2 = v5;
}
}
}
else
{
zap_plist(*(_QWORD *)(a1 + 8));
}
return free_discrim(a1);
}

original_code:
static
void zap_discrim_tree(Discrim d, int n)
{
  if (n == 0) {
    zap_plist(d->u.data);
  }
  else {
    int arity;
    Discrim k, prev;
    k = d->u.kids;
    while (k != ((void *)0)) {
      if (k->type == AC_ARG_TYPE || k->type == AC_NV_ARG_TYPE)
 arity = 0;
      else if (((k)->type == DVARIABLE))
 arity = 0;
      else
 arity = sn_to_arity(k->symbol);
      prev = k;
      k = k->next;
      zap_discrim_tree(prev, n+arity-1);
    }
  }
  free_discrim(d);
}

canonical_original_code:
static void zap_discrim_tree(struct discrim *d, int n)
{
  if (n == 0) {
    zap_plist(d->u.data);
  }
  else {
    int arity;
    struct discrim *k; struct discrim *prev;
    k = d->u.kids;
    while (k != ((void *)0)) {
      if (k->type == AC_ARG_TYPE || k->type == AC_NV_ARG_TYPE)
 arity = 0;
      else if (((k)->type == DVARIABLE))
 arity = 0;
      else
 arity = sn_to_arity(k->symbol);
      prev = k;
      k = k->next;
      zap_discrim_tree(prev, n+arity-1);
    }
  }
  free_discrim(d);
}

variable_types: n int

variable_types: arity int


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

result = get_mem(4LL);
++Discrim_pos_gets;
return result;
}

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

result = get_mem(4LL);
++Discrim_pos_gets;
return result;
}

original_code:
Discrim_pos get_discrim_pos(void)
{
  Discrim_pos p = get_mem(((sizeof(struct discrim_pos))%(sizeof(void *)) == 0 ? (sizeof(struct discrim_pos))/(sizeof(void *)) : (sizeof(struct discrim_pos))/(sizeof(void *)) + 1));
  Discrim_pos_gets++;
  return(p);
}

canonical_original_code:
struct discrim_pos *get_discrim_pos()
{
  struct discrim_pos *p = get_mem(((sizeof(struct discrim_pos))%(sizeof(void *)) == 0 ? (sizeof(struct discrim_pos))/(sizeof(void *)) : (sizeof(struct discrim_pos))/(sizeof(void *)) + 1));
  Discrim_pos_gets++;
  return(p);
}

variable_types: struct discrim_pos { void *query; struct context { struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *terms[100]; struct context *contexts[100]; int multiplier; struct term *partial_term; } *subst; struct plist { void *v; struct plist *next; } *data; void *backtrack; } *

user_defined_types: struct discrim_pos { void *query; struct context *subst; struct plist *data; void *backtrack; }

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


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

result = free_mem(a1, 4LL);
++Discrim_pos_frees;
return result;
}

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

result = free_mem(a1, 4LL);
++Discrim_pos_frees;
return result;
}

original_code:
void free_discrim_pos(Discrim_pos p)
{
  free_mem(p, ((sizeof(struct discrim_pos))%(sizeof(void *)) == 0 ? (sizeof(struct discrim_pos))/(sizeof(void *)) : (sizeof(struct discrim_pos))/(sizeof(void *)) + 1));
  Discrim_pos_frees++;
}

canonical_original_code:
void free_discrim_pos(struct discrim_pos *p)
{
  free_mem(p, ((sizeof(struct discrim_pos))%(sizeof(void *)) == 0 ? (sizeof(struct discrim_pos))/(sizeof(void *)) : (sizeof(struct discrim_pos))/(sizeof(void *)) + 1));
  Discrim_pos_frees++;
}


decompiled_code:
int p_discrim_mem()
{
return fprint_discrim_mem(stdout, 1);
}

canonical_decompiled_code:
int func6()
{
return func5(stdout, 1);
}

original_code:
void p_discrim_mem(void)
{
  fprint_discrim_mem(stdout, TRUE);
}

canonical_original_code:
void p_discrim_mem()
{
  fprint_discrim_mem(stdout, TRUE);
}


decompiled_code:
__int64 discrim_init()
{
return get_discrim();
}

canonical_decompiled_code:
__int64 func7()
{
return func0();
}

original_code:
Discrim discrim_init(void)
{
  return get_discrim();
}

canonical_original_code:
struct discrim *discrim_init()
{
  return get_discrim();
}

return_type: struct discrim { struct discrim *next; union { struct discrim *kids; struct plist { void *v; struct plist *next; } *data; } u; short symbol; char type; } *


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

if ( *(_QWORD *)(a1 + 8) )
result = fatal_error("discrim_dealloc, nonempty index.");
else
result = free_discrim(a1);
return result;
}

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

if ( *(_QWORD *)(a1 + 8) )
result = fatal_error("discrim_dealloc, nonempty index.");
else
result = func1(a1);
return result;
}

original_code:
void discrim_dealloc(Discrim d)
{
  if (d->u.kids) {
    fatal_error("discrim_dealloc, nonempty index.");
  }
  else
    free_discrim(d);
}

canonical_original_code:
void discrim_dealloc(struct discrim *d)
{
  if (d->u.kids) {
    fatal_error("discrim_dealloc, nonempty index.");
  }
  else
    free_discrim(d);
}


decompiled_code:
__int64 __fastcall destroy_discrim_tree(__int64 a1)
{
return zap_discrim_tree(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func2(a1, 1);
}

original_code:
void destroy_discrim_tree(Discrim d)
{
  zap_discrim_tree(d, 1);
}

canonical_original_code:
void destroy_discrim_tree(struct discrim *d)
{
  zap_discrim_tree(d, 1);
}


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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) == 0LL;
return result;
}

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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) == 0LL;
return result;
}

original_code:
BOOL discrim_empty(Discrim d)
{
  return (d == ((void *)0) ? TRUE : (d->u.kids == ((void *)0) ? TRUE : FALSE));
}

canonical_original_code:
enum BOOL discrim_empty(struct discrim *d)
{
  return (d == ((void *)0) ? TRUE : (d->u.kids == ((void *)0) ? TRUE : FALSE));
}


decompiled_code:
__int64 __fastcall num_crossed(int a1)
{
_QWORD *v1; // rbx
int v2; // eax
int v3; // edx
_QWORD *v4; // rax
__int64 v5; // rcx
unsigned int v6; // edx

v1 = *(_QWORD **)(Cells + 56LL * a1 + 32);
v2 = id_to_domain_size();
if ( v2 <= 0 )
return 0;
v3 = v2;
v4 = v1;
v5 = (__int64)&v1[(unsigned int)(v3 - 1) + 1];
v6 = 0;
do
v6 += *v4++ == 0LL;
while ( v4 != (_QWORD *)v5 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
_QWORD *v1; // rbx
int v2; // eax
int v3; // edx
_QWORD *v4; // rax
__int64 v5; // rcx
unsigned int v6; // edx

v1 = *(_QWORD **)(Cells + 56LL * a1 + 32);
v2 = id_to_domain_size();
if ( v2 <= 0 )
return 0;
v3 = v2;
v4 = v1;
v5 = (__int64)&v1[(unsigned int)(v3 - 1) + 1];
v6 = 0;
do
v6 += *v4++ == 0LL;
while ( v4 != (_QWORD *)v5 );
return v6;
}

original_code:
static
int num_crossed(int id)
{
  Term *p = Cells[id].possible;
  int n = 0;
  int i;
  int ds = id_to_domain_size(id);
  for (i = 0; i < ds; i++)
    if (p[i] == ((void *)0))
      n++;
  return n;
}

canonical_original_code:
static int num_crossed(int id)
{
  struct term **p = Cells[id].possible;
  int n = 0;
  int i;
  int ds = id_to_domain_size(id);
  for (i = 0; i < ds; i++)
    if (p[i] == ((void *)0))
      n++;
  return n;
}

variable_types: id int

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


decompiled_code:
__int64 __fastcall selection_measure(unsigned int a1, signed int *a2, unsigned int *a3)
{
int v4; // eax
__int64 result; // rax

v4 = parm(*(unsigned int *)(Opt + 96LL));
if ( v4 == 3 )
{
result = num_contradictions(a1, *a2);
}
else
{
if ( v4 > 3 )
{
if ( v4 == 4 )
{
result = num_crossed(a1);
goto LABEL_9;
}
}
else
{
if ( v4 == 1 )
{
result = num_occurrences(a1);
goto LABEL_9;
}
if ( v4 == 2 )
{
result = num_propagations(a1);
goto LABEL_9;
}
}
fatal_error("selection_measure: bad selection measure");
result = 0LL;
}
LABEL_9:
if ( *a2 < (int)result )
{
*a2 = result;
*a3 = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, signed int *a2, unsigned int *a3)
{
int v4; // eax
__int64 result; // rax

v4 = parm(*(unsigned int *)(Opt + 96LL));
if ( v4 == 3 )
{
result = func3(a1, *a2);
}
else
{
if ( v4 > 3 )
{
if ( v4 == 4 )
{
result = func1(a1);
goto LABEL_9;
}
}
else
{
if ( v4 == 1 )
{
result = func0(a1);
goto LABEL_9;
}
if ( v4 == 2 )
{
result = func2(a1);
goto LABEL_9;
}
}
fatal_error("selection_measure: bad selection measure");
result = 0LL;
}
LABEL_9:
if ( *a2 < (int)result )
{
*a2 = result;
*a3 = a1;
}
return result;
}

original_code:
static
void selection_measure(int id, int *max, int *max_id)
{
  int n = 0;
  switch (parm(Opt->selection_measure)) {
  case 1: n = num_occurrences(id); break;
  case 2: n = num_propagations(id); break;
  case 3: n = num_contradictions(id, *max); break;
  case 4: n = num_crossed(id); break;
  default: fatal_error("selection_measure: bad selection measure");
  }
  if (n > *max) {
    *max = n;
    *max_id = id;
  }
}

variable_types:
max
int *


decompiled_code:
__int64 __fastcall select_linear(signed int a1, signed int a2)
{
signed int v2; // ebx
__int64 i; // rax
__int64 result; // rax
__int64 v5; // rbp
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
signed int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = a1;
if ( (unsigned int)parm(*(unsigned int *)(Opt + 96LL)) )
{
v6 = -1;
v7[0] = -1;
if ( a1 <= a2 )
{
v5 = 56LL * a1;
do
{
if ( !*(_QWORD *)(Cells + v5 + 16) )
selection_measure(v2, v7, &v6);
++v2;
v5 += 56LL;
}
while ( a2 >= v2 );
}
result = v6;
}
else if ( a1 > a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
for ( i = Cells + 56LL * a1; *(_QWORD *)(i + 16); i += 56LL )
{
if ( a2 < ++v2 )
return 0xFFFFFFFFLL;
}
result = 0xFFFFFFFFLL;
if ( a2 >= v2 )
result = (unsigned int)v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(signed int a1, signed int a2)
{
signed int v2; // ebx
__int64 i; // rax
__int64 result; // rax
__int64 v5; // rbp
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
signed int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = a1;
if ( (unsigned int)parm(*(unsigned int *)(Opt + 96LL)) )
{
v6 = -1;
v7[0] = -1;
if ( a1 <= a2 )
{
v5 = 56LL * a1;
do
{
if ( !*(_QWORD *)(Cells + v5 + 16) )
func4(v2, v7, &v6);
++v2;
v5 += 56LL;
}
while ( a2 >= v2 );
}
result = v6;
}
else if ( a1 > a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
for ( i = Cells + 56LL * a1; *(_QWORD *)(i + 16); i += 56LL )
{
if ( a2 < ++v2 )
return 0xFFFFFFFFLL;
}
result = 0xFFFFFFFFLL;
if ( a2 >= v2 )
result = (unsigned int)v2;
}
return result;
}

original_code:
int select_linear(int min_id, int max_id)
{
  if (parm(Opt->selection_measure) == 0) {
    int i = min_id;
    while (i <= max_id && Cells[i].value != ((void *)0))
      i++;
    return (i > max_id ? -1 : i);
  }
  else {
    int id_of_max = -1;
    int max = -1;
    int i;
    for (i = min_id; i <= max_id; i++) {
      if (Cells[i].value == ((void *)0)) {
 selection_measure(i, &max, &id_of_max);
      }
    }
    return id_of_max;
  }
}

variable_types: max int


decompiled_code:
__int64 __fastcall select_concentric(__int64 a1, int a2)
{
int v2; // ebx
__int64 v4; // rbp
int v5; // er13
__int64 v6; // rax
signed int v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8[11]; // [rsp+4h] [rbp-2Ch] BYREF

if ( (int)a1 > a2 )
return 0xFFFFFFFFLL;
a1 = (int)a1;
while ( 1 )
{
v2 = a1;
if ( !*(_QWORD *)(*(_QWORD *)(Ordered_cells + 8 * a1) + 16LL) )
break;
if ( a2 < (int)++a1 )
return 0xFFFFFFFFLL;
}
if ( a2 < (int)a1 )
return 0xFFFFFFFFLL;
v4 = 8LL * (int)a1;
v5 = *(_DWORD *)(*(_QWORD *)(Ordered_cells + v4) + 40LL);
v7 = -1;
v8[0] = -1;
do
{
v6 = *(_QWORD *)(Ordered_cells + v4);
if ( *(_DWORD *)(v6 + 40) > v5 )
break;
if ( !*(_QWORD *)(v6 + 16) )
selection_measure(*(_DWORD *)v6, &v7, v8);
++v2;
v4 += 8LL;
}
while ( a2 >= v2 );
return v8[0];
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // ebx
__int64 v4; // rbp
int v5; // er13
__int64 v6; // rax
signed int v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8[11]; // [rsp+4h] [rbp-2Ch] BYREF

if ( (int)a1 > a2 )
return 0xFFFFFFFFLL;
a1 = (int)a1;
while ( 1 )
{
v2 = a1;
if ( !*(_QWORD *)(*(_QWORD *)(Ordered_cells + 8 * a1) + 16LL) )
break;
if ( a2 < (int)++a1 )
return 0xFFFFFFFFLL;
}
if ( a2 < (int)a1 )
return 0xFFFFFFFFLL;
v4 = 8LL * (int)a1;
v5 = *(_DWORD *)(*(_QWORD *)(Ordered_cells + v4) + 40LL);
v7 = -1;
v8[0] = -1;
do
{
v6 = *(_QWORD *)(Ordered_cells + v4);
if ( *(_DWORD *)(v6 + 40) > v5 )
break;
if ( !*(_QWORD *)(v6 + 16) )
func4(*(_DWORD *)v6, &v7, v8);
++v2;
v4 += 8LL;
}
while ( a2 >= v2 );
return v8[0];
}

original_code:
int select_concentric(int min_id, int max_id)
{
  int i = min_id;
  while (i <= max_id && Ordered_cells[i]->value != ((void *)0))
    i++;
  if (i > max_id)
    return -1;
  else {
    int n = Ordered_cells[i]->max_index;
    int max_val = -1;
    int id_of_max = -1;
    while (i <= max_id && Ordered_cells[i]->max_index <= n) {
      if (Ordered_cells[i]->value == ((void *)0))
 selection_measure(Ordered_cells[i]->id, &max_val, &id_of_max);
      i++;
    }
    return id_of_max;
  }
}


decompiled_code:
__int64 __fastcall select_cell(int a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax

v1 = parm(*(unsigned int *)(Opt + 92LL));
switch ( v1 )
{
case 1:
v2 = select_concentric(0LL, First_skolem_cell - 1);
goto LABEL_6;
case 2:
v2 = select_concentric_band(0, First_skolem_cell - 1, a1);
LABEL_6:
if ( v2 >= 0 )
return (unsigned int)v2;
goto LABEL_7;
case 0:
v2 = select_linear(0, First_skolem_cell - 1);
goto LABEL_6;
}
fatal_error("bad selection order");
v2 = -1;
LABEL_7:
v3 = parm(*(unsigned int *)(Opt + 92LL));
if ( v3 == 1 )
{
v2 = select_concentric(First_skolem_cell, Number_of_cells - 1);
}
else if ( v3 == 2 )
{
v2 = select_concentric_band(First_skolem_cell, Number_of_cells - 1, a1);
}
else if ( v3 )
{
fatal_error("bad selection order");
}
else
{
v2 = select_linear(First_skolem_cell, Number_of_cells - 1);
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax

v1 = parm(*(unsigned int *)(Opt + 92LL));
switch ( v1 )
{
case 1:
v2 = func6(0LL, First_skolem_cell - 1);
goto LABEL_6;
case 2:
v2 = func7(0, First_skolem_cell - 1, a1);
LABEL_6:
if ( v2 >= 0 )
return (unsigned int)v2;
goto LABEL_7;
case 0:
v2 = func5(0, First_skolem_cell - 1);
goto LABEL_6;
}
fatal_error("bad selection order");
v2 = -1;
LABEL_7:
v3 = parm(*(unsigned int *)(Opt + 92LL));
if ( v3 == 1 )
{
v2 = func6(First_skolem_cell, Number_of_cells - 1);
}
else if ( v3 == 2 )
{
v2 = func7(First_skolem_cell, Number_of_cells - 1, a1);
}
else if ( v3 )
{
fatal_error("bad selection order");
}
else
{
v2 = func5(First_skolem_cell, Number_of_cells - 1);
}
return (unsigned int)v2;
}

original_code:
int select_cell(int max_constrained)
{
  int id = -1;
  switch (parm(Opt->selection_order)) {
  case 0: id = select_linear(0, First_skolem_cell-1); break;
  case 1: id = select_concentric(0, First_skolem_cell-1); break;
  case 2: id = select_concentric_band(0, First_skolem_cell-1, max_constrained); break;
  default: fatal_error("bad selection order");
  }
  if (id >= 0)
    return id;
  switch (parm(Opt->selection_order)) {
  case 0: id = select_linear(First_skolem_cell, Number_of_cells-1); break;
  case 1: id = select_concentric(First_skolem_cell, Number_of_cells-1); break;
  case 2: id = select_concentric_band(First_skolem_cell, Number_of_cells-1, max_constrained); break;
  default: fatal_error("bad selection order");
  }
  return id;
}


decompiled_code:
__int64 __fastcall num_occurrences(int a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(Cells + 56LL * a1 + 24);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(Cells + 56LL * a1 + 24);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
return v2;
}

original_code:
static
int num_occurrences(int id)
{
  Term t;
  int n = 0;
  for (t = Cells[id].occurrences; t != ((void *)0); t = t->u.vp)
    n++;
  return n;
}

canonical_original_code:
static int num_occurrences(int id)
{
  struct term *t;
  int n = 0;
  for (t = Cells[id].occurrences; t != ((void *)0); t = t->u.vp)
    n++;
  return n;
}


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

if ( Nonbasic_flag != -1 )
fatal_error("init_basic_paramod, called more than once");
result = claim_term_flag();
Nonbasic_flag = result;
return result;
}

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

if ( Nonbasic_flag != -1 )
fatal_error("init_basic_paramod, called more than once");
result = claim_term_flag();
Nonbasic_flag = result;
return result;
}

original_code:
void init_basic_paramod(void)
{
  if (Nonbasic_flag != -1)
    fatal_error("init_basic_paramod, called more than once");
  Nonbasic_flag = claim_term_flag();
}

canonical_original_code:
void init_basic_paramod()
{
  if (Nonbasic_flag != -1)
    fatal_error("init_basic_paramod, called more than once");
  Nonbasic_flag = claim_term_flag();
}


decompiled_code:
void __fastcall set_basic_paramod(int a1)
{
Basic_paramodulation = a1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
Basic_paramodulation = a1;
}

original_code:
void set_basic_paramod(BOOL flag)
{
  Basic_paramodulation = flag;
}

canonical_original_code:
void set_basic_paramod(enum BOOL flag)
{
  Basic_paramodulation = flag;
}

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


decompiled_code:
__int64 basic_paramod()
{
return (unsigned int)Basic_paramodulation;
}

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

original_code:
BOOL basic_paramod(void)
{
  return Basic_paramodulation;
}

canonical_original_code:
enum BOOL basic_paramod()
{
  return Basic_paramodulation;
}


decompiled_code:
__int64 __fastcall mark_term_nonbasic(__int64 a1)
{
if ( Nonbasic_flag == -1 )
fatal_error("mark_term_nonbasic: init_basic() was not called");
return term_flag_set(a1, (unsigned int)Nonbasic_flag);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( Nonbasic_flag == -1 )
fatal_error("mark_term_nonbasic: init_basic() was not called");
return term_flag_set(a1, (unsigned int)Nonbasic_flag);
}

original_code:
void mark_term_nonbasic(Term t)
{
  if (Nonbasic_flag == -1)
    fatal_error("mark_term_nonbasic: init_basic() was not called");
  term_flag_set(t, Nonbasic_flag);
}

canonical_original_code:
void mark_term_nonbasic(struct term *t)
{
  if (Nonbasic_flag == -1)
    fatal_error("mark_term_nonbasic: init_basic() was not called");
  term_flag_set(t, Nonbasic_flag);
}


decompiled_code:
__int64 __fastcall mark_all_nonbasic(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp

if ( *(int *)a1 < 0 )
{
result = mark_term_nonbasic(a1);
if ( *(_BYTE *)(a1 + 4) )
{
v2 = 0LL;
do
{
mark_all_nonbasic(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2++));
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v2 );
}
}
return result;
}

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

if ( *(int *)a1 < 0 )
{
result = func3(a1);
if ( *(_BYTE *)(a1 + 4) )
{
v2 = 0LL;
do
{
func4(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2++));
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v2 );
}
}
return result;
}

original_code:
void mark_all_nonbasic(Term t)
{
  if (!((t)->private_symbol >= 0)) {
    int i;
    mark_term_nonbasic(t);
    for (i = 0; i < ((t)->arity); i++)
      mark_all_nonbasic(((t)->args[i]));
  }
}

canonical_original_code:
void mark_all_nonbasic(struct term *t)
{
  if (!((t)->private_symbol >= 0)) {
    int i;
    mark_term_nonbasic(t);
    for (i = 0; i < ((t)->arity); i++)
      mark_all_nonbasic(((t)->args[i]));
  }
}


decompiled_code:
__int64 __fastcall nonbasic_term(__int64 a1)
{
return term_flag(a1, (unsigned int)Nonbasic_flag);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return term_flag(a1, (unsigned int)Nonbasic_flag);
}

original_code:
BOOL nonbasic_term(Term t)
{
  return term_flag(t, Nonbasic_flag);
}

canonical_original_code:
enum BOOL nonbasic_term(struct term *t)
{
  return term_flag(t, Nonbasic_flag);
}


decompiled_code:
_BOOL8 __fastcall basic_term(__int64 a1)
{
return (unsigned int)term_flag(a1, (unsigned int)Nonbasic_flag) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return (unsigned int)term_flag(a1, (unsigned int)Nonbasic_flag) == 0;
}

original_code:
BOOL basic_term(Term t)
{
  return !term_flag(t, Nonbasic_flag);
}

canonical_original_code:
enum BOOL basic_term(struct term *t)
{
  return !term_flag(t, Nonbasic_flag);
}


decompiled_code:
__int64 nonbasic_flag()
{
return (unsigned int)Nonbasic_flag;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)Nonbasic_flag;
}

original_code:
int nonbasic_flag(void)
{
  return Nonbasic_flag;
}

canonical_original_code:
int nonbasic_flag()
{
  return Nonbasic_flag;
}


decompiled_code:
__int64 __fastcall apply_basic(int *a1, __int64 a2)
{
int *v2; // r12
__int64 v3; // rbx
int *v4; // rbp
int v5; // edi
__int64 v6; // rdi
__int64 v7; // r13
__int64 v9; // r14
_QWORD *v10; // r15

v2 = a1;
v3 = a2;
v4 = a1;
if ( a2 )
{
while ( 1 )
{
v5 = *v4;
if ( *v4 < 0 )
break;
v4 = *(int **)(v3 + 8LL * v5);
if ( !v4 )
return get_variable_term((unsigned int)(100 * *(_DWORD *)(v3 + 1600) + v5));
v3 = *(_QWORD *)(v3 + 8LL * v5 + 800);
if ( !v3 )
goto LABEL_5;
}
}
else
{
LABEL_5:
v6 = (unsigned int)*v4;
if ( (int)v6 >= 0 )
return get_variable_term(v6);
v3 = 0LL;
}
v7 = get_rigid_term_like(v4);
if ( *((_BYTE *)v4 + 4) )
{
v9 = 0LL;
do
{
v10 = (_QWORD *)(*(_QWORD *)(v7 + 8) + 8 * v9);
*v10 = apply_basic(*(_QWORD *)(*((_QWORD *)v4 + 1) + 8 * v9++), v3);
}
while ( *((unsigned __int8 *)v4 + 4) > (int)v9 );
}
if ( *v2 < 0 )
{
if ( (unsigned int)nonbasic_term((__int64)v4) )
mark_term_nonbasic(v7);
}
else
{
mark_all_nonbasic(v7);
}
return v7;
}

original_code:
Term apply_basic(Term t, Context c)
{
  Term raw = t;
  { int i; while (c!=((void *)0) && ((t)->private_symbol >= 0) && c->terms[i=((t)->private_symbol)]) { t = c->terms[i]; c = c->contexts[i]; } }
  if (((t)->private_symbol >= 0)) {
    if (!c)
      return get_variable_term(((t)->private_symbol));
    else
      return get_variable_term(c->multiplier * 100 + ((t)->private_symbol));
  }
  else {
    Term t2 = get_rigid_term_like(t);
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = apply_basic(((t)->args[i]), c);
    if (((raw)->private_symbol >= 0))
      mark_all_nonbasic(t2);
    else if (nonbasic_term(t))
      mark_term_nonbasic(t2);
    return t2;
  }
}

canonical_original_code:
struct term *apply_basic(struct term *t, struct context *c)
{
  struct term *raw = t;
  { int i; while (c!=((void *)0) && ((t)->private_symbol >= 0) && c->terms[i=((t)->private_symbol)]) { t = c->terms[i]; c = c->contexts[i]; } }
  if (((t)->private_symbol >= 0)) {
    if (!c)
      return get_variable_term(((t)->private_symbol));
    else
      return get_variable_term(c->multiplier * 100 + ((t)->private_symbol));
  }
  else {
    struct term *t2 = get_rigid_term_like(t);
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = apply_basic(((t)->args[i]), c);
    if (((raw)->private_symbol >= 0))
      mark_all_nonbasic(t2);
    else if (nonbasic_term(t))
      mark_term_nonbasic(t2);
    return t2;
  }
}

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


decompiled_code:
__int64 __fastcall apply_basic_substitute(__int64 a1, int *a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v7; // r12
__int64 v9; // rbp
_QWORD *v10; // r15

if ( a1 == a4 )
return apply_basic(a2, a3);
if ( *(int *)a1 >= 0 )
return apply_basic((int *)a1, a5);
v7 = get_rigid_term_like(a1);
if ( (unsigned int)nonbasic_term(a1) )
mark_term_nonbasic(v7);
if ( *(_BYTE *)(a1 + 4) )
{
v9 = 0LL;
do
{
v10 = (_QWORD *)(*(_QWORD *)(v7 + 8) + 8 * v9);
*v10 = apply_basic_substitute(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v9++), a2, a3, a4, a5);
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v9 );
}
return v7;
}

original_code:
Term apply_basic_substitute(Term t, Term beta, Context c_from,
       Term into_term, Context c_into)
{
  if (t == into_term)
    return apply_basic(beta, c_from);
  else if (((t)->private_symbol >= 0))
    return apply_basic(t, c_into);
  else {
    int i;
    Term t2 = get_rigid_term_like(t);
    if (nonbasic_term(t))
      mark_term_nonbasic(t2);
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = apply_basic_substitute(((t)->args[i]), beta, c_from,
        into_term, c_into);
    return t2;
  }
}

canonical_original_code:
struct term *apply_basic_substitute(struct term *t, struct term *beta, struct context *c_from, struct term *into_term, struct context *c_into)
{
  if (t == into_term)
    return apply_basic(beta, c_from);
  else if (((t)->private_symbol >= 0))
    return apply_basic(t, c_into);
  else {
    int i;
    struct term *t2 = get_rigid_term_like(t);
    if (nonbasic_term(t))
      mark_term_nonbasic(t2);
    for (i = 0; i < ((t)->arity); i++)
      ((t2)->args[i]) = apply_basic_substitute(((t)->args[i]), beta, c_from,
        into_term, c_into);
    return t2;
  }
}

variable_types:
beta
struct term *

variable_types: i int


decompiled_code:
__int64 __fastcall clear_all_nonbasic_marks(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp

if ( *(int *)a1 < 0 )
{
result = term_flag_clear(a1, (unsigned int)Nonbasic_flag);
if ( *(_BYTE *)(a1 + 4) )
{
v2 = 0LL;
do
{
clear_all_nonbasic_marks(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2++));
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v2 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp

if ( *(int *)a1 < 0 )
{
result = term_flag_clear(a1, (unsigned int)Nonbasic_flag);
if ( *(_BYTE *)(a1 + 4) )
{
v2 = 0LL;
do
{
func10(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2++));
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v2 );
}
}
return result;
}

original_code:
void clear_all_nonbasic_marks(Term t)
{
  if (!((t)->private_symbol >= 0)) {
    int i;
    term_flag_clear(t, Nonbasic_flag);
    for (i = 0; i < ((t)->arity); i++)
      clear_all_nonbasic_marks(((t)->args[i]));
  }
}

canonical_original_code:
void clear_all_nonbasic_marks(struct term *t)
{
  if (!((t)->private_symbol >= 0)) {
    int i;
    term_flag_clear(t, Nonbasic_flag);
    for (i = 0; i < ((t)->arity); i++)
      clear_all_nonbasic_marks(((t)->args[i]));
  }
}

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 p_term_basic(unsigned int *a1)
{
__int64 v1; // rsi
__int64 v3; // rbp

v1 = *a1;
if ( (int)v1 < 0 )
{
if ( basic_term((__int64)a1) )
putchar(35);
fprint_sym(stdout, -*a1);
if ( (*a1 & 0x80000000) != 0 && *((_BYTE *)a1 + 4) )
{
putchar(40);
if ( *((_BYTE *)a1 + 4) )
{
v3 = 0LL;
do
{
p_term_basic(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3));
if ( *((unsigned __int8 *)a1 + 4) - 1 > (int)v3 )
putchar(44);
++v3;
}
while ( *((unsigned __int8 *)a1 + 4) > (int)v3 );
}
putchar(41);
}
}
else
{
printf("v%d", v1);
}
return fflush(stdout);
}

original_code:
void p_term_basic(Term t)
{
  if (((t)->private_symbol >= 0))
    printf("v%d", ((t)->private_symbol));
  else {
    if (basic_term(t))
      printf("#");
    fprint_sym(stdout, (-((t)->private_symbol)));
    if (((t)->private_symbol < 0 && (t)->arity > 0)) {
      int i;
      printf("(");
      for (i = 0; i < ((t)->arity); i++) {
 p_term_basic(((t)->args[i]));
 if (i < ((t)->arity)-1)
   printf(",");
      }
      printf(")");
    }
  }
  fflush(stdout);
}

canonical_original_code:
void p_term_basic(struct term *t)
{
  if (((t)->private_symbol >= 0))
    printf("v%d", ((t)->private_symbol));
  else {
    if (basic_term(t))
      printf("#");
    fprint_sym(stdout, (-((t)->private_symbol)));
    if (((t)->private_symbol < 0 && (t)->arity > 0)) {
      int i;
      printf("(");
      for (i = 0; i < ((t)->arity); i++) {
 p_term_basic(((t)->args[i]));
 if (i < ((t)->arity)-1)
   printf(",");
      }
      printf(")");
    }
  }
  fflush(stdout);
}


decompiled_code:
_BOOL8 __fastcall str_ident(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_original_code:
enum BOOL str_ident(char *s, char *t)
{
  return strcmp(s, t) == 0;
}

variable_types:
s
char *

variable_types:
t
char *


decompiled_code:
char *__fastcall new_str_copy(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *new_str_copy(char *str)
{
  char *p = malloc(strlen(str)+1);
  strcpy(p, str);
  return p;
}

variable_types:
str
char *

variable_types:
p
char *

return_type: char *


decompiled_code:
__int64 __fastcall string_member(const char *a1, const char **a2, int a3)
{
const char **v3; // rbx
__int64 v4; // r12

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
if ( a1 && *v3 && str_ident(a1, *v3) )
return 1LL;
++v3;
}
while ( v3 != (const char **)v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char **a2, int a3)
{
const char **v3; // rbx
__int64 v4; // r12

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
if ( a1 && *v3 && func0(a1, *v3) )
return 1LL;
++v3;
}
while ( v3 != (const char **)v4 );
return 0LL;
}

canonical_original_code:
enum BOOL string_member(char *string, char **strings, int n)
{
  int i;
  for (i = 0; i < n; i++)
    if (string && strings[i] && str_ident(string, strings[i]))
      return TRUE;
  return FALSE;
}

variable_types:
string
char *

variable_types:
strings
char **

variable_types: n int


decompiled_code:
__int64 __fastcall which_string_member(const char *a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
unsigned int v5; // er14

if ( a3 <= 1 )
return (unsigned int)-1;
v3 = (unsigned int)a3;
v4 = 1LL;
while ( 1 )
{
v5 = v4;
if ( str_ident(*(const char **)(a2 + 8 * v4), a1) )
break;
if ( ++v4 == v3 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
unsigned int v5; // er14

if ( a3 <= 1 )
return (unsigned int)-1;
v3 = (unsigned int)a3;
v4 = 1LL;
while ( 1 )
{
v5 = v4;
if ( func0(*(const char **)(a2 + 8 * v4), a1) )
break;
if ( ++v4 == v3 )
return (unsigned int)-1;
}
return v5;
}

original_code:
int which_string_member(char *string, char **strings, int n)
{
  int i;
  for (i = 1; i < n; i++)
    if (str_ident(strings[i], string))
      return i;
  return -1;
}


decompiled_code:
_BOOL8 __fastcall initial_substring(char *a1, __int64 a2)
{
char v2; // dl
__int64 i; // rax
char v4; // cl

v2 = *a1;
for ( i = 0LL; v2; v2 = a1[i] )
{
v4 = *(_BYTE *)(a2 + i);
if ( v4 != v2 )
break;
if ( !v4 )
break;
++i;
}
return v2 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *a1, __int64 a2)
{
char v2; // dl
__int64 i; // rax
char v4; // cl

v2 = *a1;
for ( i = 0LL; v2; v2 = a1[i] )
{
v4 = *(_BYTE *)(a2 + i);
if ( v4 != v2 )
break;
if ( !v4 )
break;
++i;
}
return v2 == 0;
}

canonical_original_code:
enum BOOL initial_substring(char *x, char *y)
{
  while (*x && *y && *x == *y) {
    x++; y++;
  }
  return *x == '\0';
}

variable_types:
x
char *

variable_types:
y
char *


substring

decompiled_code:
_BOOL8 __fastcall substring(char *a1, _BYTE *a2)
{
_BYTE *v2; // rbx
_BOOL8 result; // rax

v2 = a2;
result = initial_substring(a1, (__int64)a2);
if ( *a2 && !result )
{
do
result = initial_substring(a1, (__int64)++v2);
while ( *v2 && !result );
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(char *a1, _BYTE *a2)
{
_BYTE *v2; // rbx
_BOOL8 result; // rax

v2 = a2;
result = func4(a1, (__int64)a2);
if ( *a2 && !result )
{
do
result = func4(a1, (__int64)++v2);
while ( *v2 && !result );
}
return result;
}

original_code:
BOOL substring(char *x, char *y)
{
  BOOL found = initial_substring(x,y);
  while (*y && !found) {
    y++;
    found = initial_substring(x,y);
  }
  return found;
}

canonical_original_code:
enum BOOL substring(char *x, char *y)
{
  enum BOOL found = initial_substring(x,y);
  while (*y && !found) {
    y++;
    found = initial_substring(x,y);
  }
  return found;
}

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


decompiled_code:
__int64 __fastcall reverse_chars(__int64 a1, int a2, int a3)
{
char *v3; // rcx
char v4; // r8
char *v5; // rax
__int64 result; // rax

if ( a2 < a3 )
{
v3 = (char *)(a1 + a2);
v4 = *v3;
v5 = (char *)(a1 + a3);
*v3 = *v5;
*v5 = v4;
result = reverse_chars(a1, (unsigned int)(a2 + 1), (unsigned int)(a3 - 1));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3)
{
char *v3; // rcx
char v4; // r8
char *v5; // rax
__int64 result; // rax

if ( a2 < a3 )
{
v3 = (char *)(a1 + a2);
v4 = *v3;
v5 = (char *)(a1 + a3);
*v3 = *v5;
*v5 = v4;
result = func6(a1, (unsigned int)(a2 + 1), (unsigned int)(a3 - 1));
}
return result;
}

original_code:
void reverse_chars(char *s, int start, int end)
{
  if (start < end) {
    char c = s[start]; s[start] = s[end]; s[end] = c;
    reverse_chars(s, start+1, end-1);
  }
}

variable_types: start int

variable_types: end int

variable_types: c char


decompiled_code:
__int64 __fastcall char_occurrences(const char *a1, unsigned __int8 a2)
{
size_t v3; // rdi
const char *v4; // rax
const char *v5; // rdi
unsigned int v6; // edx

v3 = strlen(a1);
v4 = a1;
v5 = &a1[v3];
v6 = 0;
while ( v4 != v5 )
v6 += *v4++ == a2;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, unsigned __int8 a2)
{
size_t v3; // rdi
const char *v4; // rax
const char *v5; // rdi
unsigned int v6; // edx

v3 = strlen(a1);
v4 = a1;
v5 = &a1[v3];
v6 = 0;
while ( v4 != v5 )
v6 += *v4++ == a2;
return v6;
}

original_code:
int char_occurrences(char *s, char c)
{
  int n = 0;
  int i;
  for (i = 0; i < strlen(s); i++) {
    if (s[i] == c)
      n++;
  }
  return n;
}


decompiled_code:
_BOOL8 __fastcall str_to_int(const char *a1, _DWORD *a2)
{
char *endptr; // [rsp+8h] [rbp-10h] BYREF

*a2 = strtol(a1, &endptr, 10);
return *endptr == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1, _DWORD *a2)
{
char *endptr; // [rsp+8h] [rbp-10h] BYREF

*a2 = strtol(a1, &endptr, 10);
return *endptr == 0;
}

canonical_original_code:
enum BOOL str_to_int(char *str, int *ip)
{
  char *end;
  *ip = strtol(str, &end, 10);
  if (*end != '\0')
    return FALSE;
  else
    return TRUE;
}

variable_types:
ip
int *

variable_types:
end
char *


decompiled_code:
__int64 __fastcall natural_string(const char *a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !str_to_int(a1, v2) )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( (v2[0] & 0x80000000) == 0 )
result = v2[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !func8(a1, v2) )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( (v2[0] & 0x80000000) == 0 )
result = v2[0];
return result;
}

original_code:
int natural_string(char *str)
{
  int i;
  if (!str_to_int(str, &i))
    return -1;
  else if (i < 0)
    return -1;
  else
    return i;
}

variable_types: i int


decompiled_code:
char *__fastcall int_to_str(unsigned int a1, char *a2, int a3)
{
if ( a3 <= snprintf(a2, a3, "%d", a1) )
fatal_error("float_to_str, string too small");
return a2;
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1, char *a2, int a3)
{
if ( a3 <= snprintf(a2, a3, "%d", a1) )
fatal_error("float_to_str, string too small");
return a2;
}

original_code:
char *int_to_str(int n, char *s, int size)
{
  int used = snprintf(s, size, "%d", n);
  if (used >= size)
    fatal_error("float_to_str, string too small");
  return s;
}

variable_types: size int

variable_types: used int


decompiled_code:
_BOOL8 __fastcall str_to_double(__int64 a1, double *a2)
{
_BOOL8 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

result = 0LL;
if ( *(_BYTE *)a1 == 34 && *(_BYTE *)(a1 + 1) != 34 )
{
*a2 = strtod((const char *)(a1 + 1), &endptr);
result = *endptr == 34;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, double *a2)
{
_BOOL8 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

result = 0LL;
if ( *(_BYTE *)a1 == 34 && *(_BYTE *)(a1 + 1) != 34 )
{
*a2 = strtod((const char *)(a1 + 1), &endptr);
result = *endptr == 34;
}
return result;
}

canonical_original_code:
enum BOOL str_to_double(char *s, double *dp)
{
  char *end;
  double f;
  if (*s != '\"')
    return(FALSE);
  else if (*(s+1) == '\"')
    return(FALSE);
  else {
    f = strtod(s+1, &end);
    *dp = f;
    return (*end == '\"');
  }
}

variable_types:
s
char *

variable_types:
dp
double *

variable_types: f double


decompiled_code:
char *__fastcall double_to_str(char *s, int a2, double a3)
{
int v3; // eax
int v4; // esi
char *v5; // rax
__int64 v6; // rcx
char *result; // rax

if ( a2 <= snprintf(s, a2, "%.3f", a3) )
{
fatal_error("double_to_str, string too small");
result = 0LL;
}
else
{
v3 = strlen(s);
v4 = v3;
if ( v3 > 0 )
{
v5 = &s[v3];
v6 = (__int64)&v5[-(v4 - 1) - 1];
do
{
*v5 = *(v5 - 1);
--v5;
}
while ( v5 != (char *)v6 );
}
*s = 34;
s[v4 + 1] = 34;
s[v4 + 2] = 0;
result = s;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func12(char *s, int a2, double a3)
{
int v3; // eax
int v4; // esi
char *v5; // rax
__int64 v6; // rcx
char *result; // rax

if ( a2 <= snprintf(s, a2, "%.3f", a3) )
{
fatal_error("double_to_str, string too small");
result = 0LL;
}
else
{
v3 = strlen(s);
v4 = v3;
if ( v3 > 0 )
{
v5 = &s[v3];
v6 = (__int64)&v5[-(v4 - 1) - 1];
do
{
*v5 = *(v5 - 1);
--v5;
}
while ( v5 != (char *)v6 );
}
*s = 34;
s[v4 + 1] = 34;
s[v4 + 2] = 0;
result = s;
}
return result;
}

original_code:
char *double_to_str(double d,
      char *s,
      int size)
{
  int used = snprintf(s, size, Float_format, d);
  if (used >= size) {
    fatal_error("double_to_str, string too small");
    return ((void *)0);
  }
  else {
    int i;
    int n = strlen(s);
    for (i=n; i>0; i--)
      s[i] = s[i-1];
    s[0] = '\"';
    s[n+1] = '\"';
    s[n+2] = '\0';
    return s;
  }
}

variable_types: d double


decompiled_code:
__int64 __fastcall string_of_repeated(char a1, const char *a2)
{
size_t v3; // rsi
const char *v4; // rax
const char *v5; // rsi

v3 = strlen(a2);
v4 = a2;
v5 = &a2[v3];
while ( v4 != v5 )
{
if ( *v4++ != a1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(char a1, const char *a2)
{
size_t v3; // rsi
const char *v4; // rax
const char *v5; // rsi

v3 = strlen(a2);
v4 = a2;
v5 = &a2[v3];
while ( v4 != v5 )
{
if ( *v4++ != a1 )
return 0LL;
}
return 1LL;
}

canonical_original_code:
enum BOOL string_of_repeated(char c, char *s)
{
  int i;
  for (i = 0; i < strlen(s); i++)
    if (s[i] != c)
      return FALSE;
  return TRUE;
}


decompiled_code:
int __fastcall command_line_parm(unsigned int a1, const char *a2)
{
__int64 v2; // rbx
const char *v3; // rax

v2 = (unsigned int)atoi(a2);
assign_parm(a1, v2, 1LL);
v3 = (const char *)parm_id_to_str(a1);
return printf("\n%% From the command line: assign(%s, %d).\n", v3, (unsigned int)v2);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, const char *a2)
{
__int64 v2; // rbx
const char *v3; // rax

v2 = (unsigned int)atoi(a2);
assign_parm(a1, v2, 1LL);
v3 = (const char *)parm_id_to_str(a1);
return printf("\n%% From the command line: assign(%s, %d).\n", v3, (unsigned int)v2);
}

original_code:
static
void command_line_parm(int id, char *optarg)
{
  int n = atoi(optarg);
  assign_parm(id, n, TRUE);
  printf("\n%% From the command line: assign(%s, %d).\n", parm_id_to_str(id),n);
}

variable_types: id int

variable_types:
optarg
char *


decompiled_code:
int __fastcall command_line_flag(unsigned int a1, __int64 a2)
{
const char *v2; // rax
int result; // eax
const char *v4; // rax

if ( a2 && !(unsigned int)str_ident(a2, "1") )
{
if ( (unsigned int)str_ident(a2, "0") )
{
clear_flag(a1, 1LL);
v4 = (const char *)flag_id_to_str(a1);
result = printf("\n%% From the command line: clear(%s).\n", v4);
}
else
{
result = fatal_error("Command-line flag must have 0 or 1 as the value");
}
}
else
{
set_flag(a1, 1LL);
v2 = (const char *)flag_id_to_str(a1);
result = printf("\n%% From the command line: set(%s).\n", v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, __int64 a2)
{
const char *v2; // rax
int result; // eax
const char *v4; // rax

if ( a2 && !(unsigned int)str_ident(a2, "1") )
{
if ( (unsigned int)str_ident(a2, "0") )
{
clear_flag(a1, 1LL);
v4 = (const char *)flag_id_to_str(a1);
result = printf("\n%% From the command line: clear(%s).\n", v4);
}
else
{
result = fatal_error("Command-line flag must have 0 or 1 as the value");
}
}
else
{
set_flag(a1, 1LL);
v2 = (const char *)flag_id_to_str(a1);
result = printf("\n%% From the command line: set(%s).\n", v2);
}
return result;
}

original_code:
static
void command_line_flag(int id, char *optarg)
{
  if (!optarg || str_ident(optarg, "1")) {
    set_flag(id, TRUE);
    printf("\n%% From the command line: set(%s).\n", flag_id_to_str(id));
  }
  else if (str_ident(optarg, "0")) {
    clear_flag(id, TRUE);
    printf("\n%% From the command line: clear(%s).\n", flag_id_to_str(id));
  }
  else
    fatal_error("Command-line flag must have 0 or 1 as the value");
}


decompiled_code:
__int64 __fastcall member_args(int a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
__int64 result; // rax

if ( a1 <= 1 )
return 0LL;
v4 = (_QWORD *)(a2 + 8);
while ( 1 )
{
result = str_ident(*v4, a3);
if ( (_DWORD)result )
break;
if ( ++v4 == (_QWORD *)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
__int64 result; // rax

if ( a1 <= 1 )
return 0LL;
v4 = (_QWORD *)(a2 + 8);
while ( 1 )
{
result = str_ident(*v4, a3);
if ( (_DWORD)result )
break;
if ( ++v4 == (_QWORD *)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) )
return result;
}
return 1LL;
}

canonical_original_code:
enum BOOL member_args(int argc, char **argv, char *str)
{
  int i;
  for (i = 1; i < argc; i++)
    if (str_ident(argv[i], str))
      return TRUE;
  return FALSE;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
str
char *


decompiled_code:
int __fastcall process_command_line_args(int argc, char **argv, unsigned int *a3)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "n:N:m:t:s:b:O:M:p:P:v:L:G:H:I:J:K:T:R:i:q:Q:S:cf:g");
if ( result == -1 )
return result;
switch ( result )
{
case 'G':
command_line_flag(a3[4], (__int64)optarg);
break;
case 'H':
command_line_flag(a3[5], (__int64)optarg);
break;
case 'I':
command_line_flag(a3[6], (__int64)optarg);
break;
case 'J':
command_line_flag(a3[7], (__int64)optarg);
break;
case 'K':
command_line_flag(a3[8], (__int64)optarg);
break;
case 'L':
command_line_flag(a3[2], (__int64)optarg);
break;
case 'M':
command_line_parm(a3[24], optarg);
break;
case 'N':
command_line_parm(a3[19], optarg);
break;
case 'O':
command_line_parm(a3[23], optarg);
break;
case 'P':
command_line_flag(*a3, (__int64)optarg);
break;
case 'Q':
command_line_flag(a3[14], (__int64)optarg);
break;
case 'R':
command_line_flag(a3[10], (__int64)optarg);
break;
case 'S':
command_line_flag(a3[15], (__int64)optarg);
break;
case 'T':
command_line_flag(a3[3], (__int64)optarg);
break;
case 'b':
command_line_parm(a3[27], optarg);
break;
case 'c':
case 'f':
case 'g':
continue;
case 'i':
command_line_parm(a3[21], optarg);
break;
case 'm':
command_line_parm(a3[22], optarg);
break;
case 'n':
command_line_parm(a3[17], optarg);
break;
case 'p':
command_line_flag(a3[1], (__int64)optarg);
break;
case 'q':
command_line_flag(a3[13], (__int64)optarg);
break;
case 's':
command_line_parm(a3[26], optarg);
break;
case 't':
command_line_parm(a3[25], optarg);
break;
case 'v':
command_line_flag(a3[9], (__int64)optarg);
break;
default:
usage_message(stderr, a3);
fatal_error("unrecognized command-line option or missing value (flags take 0 or 1)");
break;
}
}
}

canonical_decompiled_code:
int __fastcall func4(int argc, char **argv, unsigned int *a3)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "n:N:m:t:s:b:O:M:p:P:v:L:G:H:I:J:K:T:R:i:q:Q:S:cf:g");
if ( result == -1 )
return result;
switch ( result )
{
case 'G':
func1(a3[4], (__int64)optarg);
break;
case 'H':
func1(a3[5], (__int64)optarg);
break;
case 'I':
func1(a3[6], (__int64)optarg);
break;
case 'J':
func1(a3[7], (__int64)optarg);
break;
case 'K':
func1(a3[8], (__int64)optarg);
break;
case 'L':
func1(a3[2], (__int64)optarg);
break;
case 'M':
func0(a3[24], optarg);
break;
case 'N':
func0(a3[19], optarg);
break;
case 'O':
func0(a3[23], optarg);
break;
case 'P':
func1(*a3, (__int64)optarg);
break;
case 'Q':
func1(a3[14], (__int64)optarg);
break;
case 'R':
func1(a3[10], (__int64)optarg);
break;
case 'S':
func1(a3[15], (__int64)optarg);
break;
case 'T':
func1(a3[3], (__int64)optarg);
break;
case 'b':
func0(a3[27], optarg);
break;
case 'c':
case 'f':
case 'g':
continue;
case 'i':
func0(a3[21], optarg);
break;
case 'm':
func0(a3[22], optarg);
break;
case 'n':
func0(a3[17], optarg);
break;
case 'p':
func1(a3[1], (__int64)optarg);
break;
case 'q':
func1(a3[13], (__int64)optarg);
break;
case 's':
func0(a3[26], optarg);
break;
case 't':
func0(a3[25], optarg);
break;
case 'v':
func1(a3[9], (__int64)optarg);
break;
default:
func3(stderr, a3);
fatal_error("unrecognized command-line option or missing value (flags take 0 or 1)");
break;
}
}
}

original_code:
void process_command_line_args(int argc, char **argv,
          Mace_options opt)
{
  extern char *optarg;
  int c;
  while ((c = getopt(argc, argv,
      "n:N:m:t:s:b:O:M:p:P:v:L:G:H:I:J:K:T:R:i:q:Q:S:cf:g")) != (-1)) {
    switch (c) {
    case 'n':
      command_line_parm(opt->domain_size, optarg);
      break;
    case 'N':
      command_line_parm(opt->end_size, optarg);
      break;
    case 'm':
      command_line_parm(opt->max_models, optarg);
      break;
    case 't':
      command_line_parm(opt->max_seconds, optarg);
      break;
    case 's':
      command_line_parm(opt->max_seconds_per, optarg);
      break;
    case 'b':
      command_line_parm(opt->max_megs, optarg);
      break;
    case 'O':
      command_line_parm(opt->selection_order, optarg);
      break;
    case 'M':
      command_line_parm(opt->selection_measure, optarg);
      break;
    case 'P':
      command_line_flag(opt->print_models, optarg);
      break;
    case 'p':
      command_line_flag(opt->print_models_tabular, optarg);
      break;
    case 'v':
      command_line_flag(opt->verbose, optarg);
      break;
    case 'L':
      command_line_flag(opt->lnh, optarg);
      break;
    case 'G':
      command_line_flag(opt->negprop, optarg);
      break;
    case 'H':
      command_line_flag(opt->neg_assign, optarg);
      break;
    case 'I':
      command_line_flag(opt->neg_assign_near, optarg);
      break;
    case 'J':
      command_line_flag(opt->neg_elim, optarg);
      break;
    case 'K':
      command_line_flag(opt->neg_elim_near, optarg);
      break;
    case 'T':
      command_line_flag(opt->trace, optarg);
      break;
    case 'R':
      command_line_flag(opt->integer_ring, optarg);
      break;
    case 'i':
      command_line_parm(opt->increment, optarg);
      break;
    case 'q':
      command_line_flag(opt->iterate_primes, optarg);
      break;
    case 'Q':
      command_line_flag(opt->iterate_nonprimes, optarg);
      break;
    case 'S':
      command_line_flag(opt->skolems_last, optarg);
      break;
    case 'c':
    case 'f':
    case 'g':
      break;
    case '?':
    default:
      usage_message(stderr, opt);
      fatal_error("unrecognized command-line option or missing value (flags take 0 or 1)");
    }
  }
}

canonical_original_code:
void process_command_line_args(int argc, char **argv, struct mace_options *opt)
{
  extern char *optarg;
  int c;
  while ((c = getopt(argc, argv,
      "n:N:m:t:s:b:O:M:p:P:v:L:G:H:I:J:K:T:R:i:q:Q:S:cf:g")) != (-1)) {
    switch (c) {
    case 'n':
      command_line_parm(opt->domain_size, optarg);
      break;
    case 'N':
      command_line_parm(opt->end_size, optarg);
      break;
    case 'm':
      command_line_parm(opt->max_models, optarg);
      break;
    case 't':
      command_line_parm(opt->max_seconds, optarg);
      break;
    case 's':
      command_line_parm(opt->max_seconds_per, optarg);
      break;
    case 'b':
      command_line_parm(opt->max_megs, optarg);
      break;
    case 'O':
      command_line_parm(opt->selection_order, optarg);
      break;
    case 'M':
      command_line_parm(opt->selection_measure, optarg);
      break;
    case 'P':
      command_line_flag(opt->print_models, optarg);
      break;
    case 'p':
      command_line_flag(opt->print_models_tabular, optarg);
      break;
    case 'v':
      command_line_flag(opt->verbose, optarg);
      break;
    case 'L':
      command_line_flag(opt->lnh, optarg);
      break;
    case 'G':
      command_line_flag(opt->negprop, optarg);
      break;
    case 'H':
      command_line_flag(opt->neg_assign, optarg);
      break;
    case 'I':
      command_line_flag(opt->neg_assign_near, optarg);
      break;
    case 'J':
      command_line_flag(opt->neg_elim, optarg);
      break;
    case 'K':
      command_line_flag(opt->neg_elim_near, optarg);
      break;
    case 'T':
      command_line_flag(opt->trace, optarg);
      break;
    case 'R':
      command_line_flag(opt->integer_ring, optarg);
      break;
    case 'i':
      command_line_parm(opt->increment, optarg);
      break;
    case 'q':
      command_line_flag(opt->iterate_primes, optarg);
      break;
    case 'Q':
      command_line_flag(opt->iterate_nonprimes, optarg);
      break;
    case 'S':
      command_line_flag(opt->skolems_last, optarg);
      break;
    case 'c':
    case 'f':
    case 'g':
      break;
    case '?':
    default:
      usage_message(stderr, opt);
      fatal_error("unrecognized command-line option or missing value (flags take 0 or 1)");
    }
  }
}

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

variable_types: c int


decompiled_code:
__int64 __fastcall weight_beta_check(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
char v4[32]; // [rsp+8h] [rbp-20h] BYREF

v1 = -*(_DWORD *)a1;
if ( v1 == Sum_sn || v1 == Prod_sn || v1 == Div_sn || v1 == Min_sn || v1 == Max_sn )
{
v2 = 0;
if ( (unsigned int)weight_beta_check(**(_QWORD **)(a1 + 8)) )
v2 = weight_beta_check(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) != 0;
}
else if ( v1 == Neg_sn )
{
v2 = weight_beta_check(**(_QWORD **)(a1 + 8));
}
else
{
v2 = 1;
if ( v1 != Depth_sn && v1 != Vars_sn && v1 != Call_sn && v1 != Weight_sn )
{
v2 = term_to_number(a1, v4);
if ( v2 )
v2 = 1;
else
puts("weight_rule_check, right side of rule not understood");
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
char v4[32]; // [rsp+8h] [rbp-20h] BYREF

v1 = -*(_DWORD *)a1;
if ( v1 == Sum_sn || v1 == Prod_sn || v1 == Div_sn || v1 == Min_sn || v1 == Max_sn )
{
v2 = 0;
if ( (unsigned int)func0(**(_QWORD **)(a1 + 8)) )
v2 = func0(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) != 0;
}
else if ( v1 == Neg_sn )
{
v2 = func0(**(_QWORD **)(a1 + 8));
}
else
{
v2 = 1;
if ( v1 != Depth_sn && v1 != Vars_sn && v1 != Call_sn && v1 != Weight_sn )
{
v2 = term_to_number(a1, v4);
if ( v2 )
v2 = 1;
else
puts("weight_rule_check, right side of rule not understood");
}
}
return v2;
}

original_code:
static
BOOL weight_beta_check(Term b)
{
  if ((-((b)->private_symbol)) == Sum_sn ||
      (-((b)->private_symbol)) == Prod_sn ||
      (-((b)->private_symbol)) == Div_sn ||
      (-((b)->private_symbol)) == Min_sn ||
      (-((b)->private_symbol)) == Max_sn)
    return weight_beta_check(((b)->args[0])) && weight_beta_check(((b)->args[1]));
  else if ((-((b)->private_symbol)) == Neg_sn)
    return weight_beta_check(((b)->args[0]));
  else if ((-((b)->private_symbol)) == Depth_sn)
    return TRUE;
  else if ((-((b)->private_symbol)) == Vars_sn)
    return TRUE;
  else if ((-((b)->private_symbol)) == Call_sn)
    return TRUE;
  else if ((-((b)->private_symbol)) == Weight_sn)
    return TRUE;
  else {
    double d;
    if (term_to_number(b, &d))
      return TRUE;
    else {
      printf("weight_rule_check, right side of rule not understood\n");
      return FALSE;
    }
  }
}

canonical_original_code:
static enum BOOL weight_beta_check(struct term *b)
{
  if ((-((b)->private_symbol)) == Sum_sn ||
      (-((b)->private_symbol)) == Prod_sn ||
      (-((b)->private_symbol)) == Div_sn ||
      (-((b)->private_symbol)) == Min_sn ||
      (-((b)->private_symbol)) == Max_sn)
    return weight_beta_check(((b)->args[0])) && weight_beta_check(((b)->args[1]));
  else if ((-((b)->private_symbol)) == Neg_sn)
    return weight_beta_check(((b)->args[0]));
  else if ((-((b)->private_symbol)) == Depth_sn)
    return TRUE;
  else if ((-((b)->private_symbol)) == Vars_sn)
    return TRUE;
  else if ((-((b)->private_symbol)) == Call_sn)
    return TRUE;
  else if ((-((b)->private_symbol)) == Weight_sn)
    return TRUE;
  else {
    double d;
    if (term_to_number(b, &d))
      return TRUE;
    else {
      printf("weight_rule_check, right side of rule not understood\n");
      return FALSE;
    }
  }
}

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 weight_rule_check(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // ebx

if ( (unsigned int)is_eq_symbol((unsigned int)-*(_DWORD *)a1) )
{
v1 = *(_QWORD *)(a1 + 8);
if ( Weight_sn + **(_DWORD **)v1 )
{
puts("weight_rule_check, left side must be weight(...)");
v2 = 0;
}
else
{
v2 = weight_beta_check(*(_QWORD *)(v1 + 8));
}
}
else
{
v2 = 0;
puts("weight_rule_check, rule is not equality");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // ebx

if ( (unsigned int)is_eq_symbol((unsigned int)-*(_DWORD *)a1) )
{
v1 = *(_QWORD *)(a1 + 8);
if ( Weight_sn + **(_DWORD **)v1 )
{
puts("weight_rule_check, left side must be weight(...)");
v2 = 0;
}
else
{
v2 = func0(*(_QWORD *)(v1 + 8));
}
}
else
{
v2 = 0;
puts("weight_rule_check, rule is not equality");
}
return v2;
}

original_code:
static
BOOL weight_rule_check(Term rule)
{
  if (!is_eq_symbol((-((rule)->private_symbol)))) {
    printf("weight_rule_check, rule is not equality\n");
    return FALSE;
  }
  else if ((-((((rule)->args[0]))->private_symbol)) != Weight_sn) {
    printf("weight_rule_check, left side must be weight(...)\n");
    return FALSE;
  }
  else
    return weight_beta_check(((rule)->args[1]));
}

canonical_original_code:
static enum BOOL weight_rule_check(struct term *rule)
{
  if (!is_eq_symbol((-((rule)->private_symbol)))) {
    printf("weight_rule_check, rule is not equality\n");
    return FALSE;
  }
  else if ((-((((rule)->args[0]))->private_symbol)) != Weight_sn) {
    printf("weight_rule_check, left side must be weight(...)\n");
    return FALSE;
  }
  else
    return weight_beta_check(((rule)->args[1]));
}


decompiled_code:
__int64 __fastcall apply_depth(int *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
int v4; // ebx
int v5; // eax

if ( *a1 >= 0 )
return term_depth(*(_QWORD *)(a2 + 8LL * *a1));
result = 0LL;
if ( *((_BYTE *)a1 + 4) )
{
v3 = 0LL;
v4 = 0;
do
{
v5 = apply_depth(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3), a2);
if ( v4 < v5 )
v4 = v5;
++v3;
}
while ( *((unsigned __int8 *)a1 + 4) > (int)v3 );
result = (unsigned int)(v4 + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
int v4; // ebx
int v5; // eax

if ( *a1 >= 0 )
return term_depth(*(_QWORD *)(a2 + 8LL * *a1));
result = 0LL;
if ( *((_BYTE *)a1 + 4) )
{
v3 = 0LL;
v4 = 0;
do
{
v5 = func2(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3), a2);
if ( v4 < v5 )
v4 = v5;
++v3;
}
while ( *((unsigned __int8 *)a1 + 4) > (int)v3 );
result = (unsigned int)(v4 + 1);
}
return result;
}

original_code:
static
int apply_depth(Term t, Context subst)
{
  if (((t)->private_symbol >= 0))
    return term_depth(subst->terms[((t)->private_symbol)]);
  else if (((t)->private_symbol < 0 && (t)->arity == 0))
    return 0;
  else {
    int depth = 0;
    int i;
    for (i = 0; i < ((t)->arity); i++) {
      int d = apply_depth(((t)->args[i]), subst);
      depth = ((d) > (depth) ? (d) : (depth));
    }
    return depth + 1;
  }
}

canonical_original_code:
static int apply_depth(struct term *t, struct context *subst)
{
  if (((t)->private_symbol >= 0))
    return term_depth(subst->terms[((t)->private_symbol)]);
  else if (((t)->private_symbol < 0 && (t)->arity == 0))
    return 0;
  else {
    int depth = 0;
    int i;
    for (i = 0; i < ((t)->arity); i++) {
      int d = apply_depth(((t)->args[i]), subst);
      depth = ((d) > (depth) ? (d) : (depth));
    }
    return depth + 1;
  }
}

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

variable_types: depth int

variable_types: d int


decompiled_code:
double __fastcall weight_calc(__int64 a1, __int64 a2, double a3)
{
int v3; // eax
double v4; // rbx
__int64 v6; // rbp
__int64 v7; // rsi
double v8; // r12
double v9; // r12
double v10; // r12
double v11; // xmm0_8
int v12; // eax
double v13; // xmm0_8
int v14; // eax
__int64 v15; // rbx
int v16; // ebp
__int64 v17; // r12
__int64 v18; // rbp
double v19; // [rsp+8h] [rbp-30h]
double v20; // [rsp+8h] [rbp-30h]
double v21[4]; // [rsp+18h] [rbp-20h] BYREF

if ( *(int *)a1 >= 0 )
{
fatal_error("weight_calc, variable in rule");
v4 = *(double *)&LC16;
}
else
{
v3 = -*(_DWORD *)a1;
if ( v3 == Weight_sn )
{
v6 = apply(**(_QWORD **)(a1 + 8));
v7 = get_context();
v4 = weight(v6, v7, a3);
free_context(v7);
zap_term(v6);
}
else if ( v3 == Sum_sn )
{
v8 = weight_calc(**(_QWORD **)(a1 + 8), a2);
v4 = weight_calc(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2) + v8;
}
else if ( v3 == Prod_sn )
{
v9 = weight_calc(**(_QWORD **)(a1 + 8), a2);
v4 = weight_calc(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2) * v9;
}
else if ( v3 == Div_sn )
{
v10 = weight_calc(**(_QWORD **)(a1 + 8), a2);
v4 = v10 / weight_calc(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2);
}
else if ( v3 == Max_sn )
{
v19 = weight_calc(**(_QWORD **)(a1 + 8), a2);
v11 = weight_calc(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2);
v12 = (int)v19;
if ( (int)v19 < (int)v11 )
v12 = (int)v11;
v4 = (double)v12;
}
else if ( v3 == Min_sn )
{
v20 = weight_calc(**(_QWORD **)(a1 + 8), a2);
v13 = weight_calc(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2);
v14 = (int)v20;
if ( (int)v20 > (int)v13 )
v14 = (int)v13;
v4 = (double)v14;
}
else if ( v3 == Neg_sn )
{
*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64(weight_calc(**(_QWORD **)(a1 + 8), a2)) ^ LC18;
}
else if ( v3 == Depth_sn )
{
v4 = (double)(int)apply_depth(**(int ***)(a1 + 8), a2);
}
else if ( v3 == Vars_sn )
{
v15 = apply(**(_QWORD **)(a1 + 8));
v16 = number_of_vars_in_term(v15);
zap_term(v15);
v4 = (double)v16;
}
else if ( v3 == Call_sn )
{
v17 = term_symbol(**(_QWORD **)(a1 + 8));
v18 = apply(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
v4 = call_weight(v17, v18);
zap_term(v18);
}
else if ( (unsigned int)term_to_number(a1, v21) )
{
v4 = v21[0];
}
else
{
fatal_error("weight_calc, bad rule");
v4 = *(double *)&LC16;
}
}
return v4;
}

canonical_decompiled_code:
double __fastcall func5(__int64 a1, __int64 a2, double a3)
{
int v3; // eax
double v4; // rbx
__int64 v6; // rbp
__int64 v7; // rsi
double v8; // r12
double v9; // r12
double v10; // r12
double v11; // xmm0_8
int v12; // eax
double v13; // xmm0_8
int v14; // eax
__int64 v15; // rbx
int v16; // ebp
__int64 v17; // r12
__int64 v18; // rbp
double v19; // [rsp+8h] [rbp-30h]
double v20; // [rsp+8h] [rbp-30h]
double v21[4]; // [rsp+18h] [rbp-20h] BYREF

if ( *(int *)a1 >= 0 )
{
fatal_error("weight_calc, variable in rule");
v4 = *(double *)&LC16;
}
else
{
v3 = -*(_DWORD *)a1;
if ( v3 == Weight_sn )
{
v6 = apply(**(_QWORD **)(a1 + 8));
v7 = get_context();
v4 = func4(v6, v7, a3);
free_context(v7);
zap_term(v6);
}
else if ( v3 == Sum_sn )
{
v8 = func5(**(_QWORD **)(a1 + 8), a2);
v4 = func5(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2) + v8;
}
else if ( v3 == Prod_sn )
{
v9 = func5(**(_QWORD **)(a1 + 8), a2);
v4 = func5(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2) * v9;
}
else if ( v3 == Div_sn )
{
v10 = func5(**(_QWORD **)(a1 + 8), a2);
v4 = v10 / func5(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2);
}
else if ( v3 == Max_sn )
{
v19 = func5(**(_QWORD **)(a1 + 8), a2);
v11 = func5(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2);
v12 = (int)v19;
if ( (int)v19 < (int)v11 )
v12 = (int)v11;
v4 = (double)v12;
}
else if ( v3 == Min_sn )
{
v20 = func5(**(_QWORD **)(a1 + 8), a2);
v13 = func5(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), a2);
v14 = (int)v20;
if ( (int)v20 > (int)v13 )
v14 = (int)v13;
v4 = (double)v14;
}
else if ( v3 == Neg_sn )
{
*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64(weight_calc(**(_QWORD **)(a1 + 8), a2)) ^ LC18;
}
else if ( v3 == Depth_sn )
{
v4 = (double)(int)func2(**(int ***)(a1 + 8), a2);
}
else if ( v3 == Vars_sn )
{
v15 = apply(**(_QWORD **)(a1 + 8));
v16 = number_of_vars_in_term(v15);
zap_term(v15);
v4 = (double)v16;
}
else if ( v3 == Call_sn )
{
v17 = term_symbol(**(_QWORD **)(a1 + 8));
v18 = apply(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
v4 = call_weight(v17, v18);
zap_term(v18);
}
else if ( (unsigned int)term_to_number(a1, v21) )
{
v4 = v21[0];
}
else
{
fatal_error("weight_calc, bad rule");
v4 = *(double *)&LC16;
}
}
return v4;
}

original_code:
static
double weight_calc(Term b, Context subst)
{
  if (((b)->private_symbol >= 0)) {
    fatal_error("weight_calc, variable in rule");
    return 0;
  }
  else if ((-((b)->private_symbol)) == Weight_sn) {
    Term b_prime = apply(((b)->args[0]), subst);
    Context subst2 = get_context();
    double wt = weight(b_prime, subst2);
    free_context(subst2);
    zap_term(b_prime);
    return wt;
  }
  else if ((-((b)->private_symbol)) == Sum_sn)
    return
      weight_calc(((b)->args[0]), subst) +
      weight_calc(((b)->args[1]), subst);
  else if ((-((b)->private_symbol)) == Prod_sn)
    return
      weight_calc(((b)->args[0]), subst) *
      weight_calc(((b)->args[1]), subst);
  else if ((-((b)->private_symbol)) == Div_sn)
    return
      weight_calc(((b)->args[0]), subst) /
      weight_calc(((b)->args[1]), subst);
  else if ((-((b)->private_symbol)) == Max_sn) {
    int w1 = weight_calc(((b)->args[0]), subst);
    int w2 = weight_calc(((b)->args[1]), subst);
    return ((w1) > (w2) ? (w1) : (w2));
  }
  else if ((-((b)->private_symbol)) == Min_sn) {
    int w1 = weight_calc(((b)->args[0]), subst);
    int w2 = weight_calc(((b)->args[1]), subst);
    return ((w1) < (w2) ? (w1) : (w2));
  }
  else if ((-((b)->private_symbol)) == Neg_sn) {
    return -weight_calc(((b)->args[0]), subst);
  }
  else if ((-((b)->private_symbol)) == Depth_sn)
    return apply_depth(((b)->args[0]), subst);
  else if ((-((b)->private_symbol)) == Vars_sn) {
    Term b_prime = apply(((b)->args[0]), subst);
    int n = number_of_vars_in_term(b_prime);
    zap_term(b_prime);
    return n;
  }
  else if ((-((b)->private_symbol)) == Call_sn) {
    char *prog = term_symbol(((b)->args[0]));
    Term b_prime = apply(((b)->args[1]), subst);
    double x = call_weight(prog, b_prime);
    zap_term(b_prime);
    return x;
  }
  else {
    double wt;
    if (term_to_number(b, &wt))
      return wt;
    else {
      fatal_error("weight_calc, bad rule");
      return 0;
    }
  }
}

canonical_original_code:
static double weight_calc(struct term *b, struct context *subst)
{
  if (((b)->private_symbol >= 0)) {
    fatal_error("weight_calc, variable in rule");
    return 0;
  }
  else if ((-((b)->private_symbol)) == Weight_sn) {
    struct term *b_prime = apply(((b)->args[0]), subst);
    struct context *subst2 = get_context();
    double wt = weight(b_prime, subst2);
    free_context(subst2);
    zap_term(b_prime);
    return wt;
  }
  else if ((-((b)->private_symbol)) == Sum_sn)
    return
      weight_calc(((b)->args[0]), subst) +
      weight_calc(((b)->args[1]), subst);
  else if ((-((b)->private_symbol)) == Prod_sn)
    return
      weight_calc(((b)->args[0]), subst) *
      weight_calc(((b)->args[1]), subst);
  else if ((-((b)->private_symbol)) == Div_sn)
    return
      weight_calc(((b)->args[0]), subst) /
      weight_calc(((b)->args[1]), subst);
  else if ((-((b)->private_symbol)) == Max_sn) {
    int w1 = weight_calc(((b)->args[0]), subst);
    int w2 = weight_calc(((b)->args[1]), subst);
    return ((w1) > (w2) ? (w1) : (w2));
  }
  else if ((-((b)->private_symbol)) == Min_sn) {
    int w1 = weight_calc(((b)->args[0]), subst);
    int w2 = weight_calc(((b)->args[1]), subst);
    return ((w1) < (w2) ? (w1) : (w2));
  }
  else if ((-((b)->private_symbol)) == Neg_sn) {
    return -weight_calc(((b)->args[0]), subst);
  }
  else if ((-((b)->private_symbol)) == Depth_sn)
    return apply_depth(((b)->args[0]), subst);
  else if ((-((b)->private_symbol)) == Vars_sn) {
    struct term *b_prime = apply(((b)->args[0]), subst);
    int n = number_of_vars_in_term(b_prime);
    zap_term(b_prime);
    return n;
  }
  else if ((-((b)->private_symbol)) == Call_sn) {
    char *prog = term_symbol(((b)->args[0]));
    struct term *b_prime = apply(((b)->args[1]), subst);
    double x = call_weight(prog, b_prime);
    zap_term(b_prime);
    return x;
  }
  else {
    double wt;
    if (term_to_number(b, &wt))
      return wt;
    else {
      fatal_error("weight_calc, bad rule");
      return 0;
    }
  }
}

variable_types: struct context { struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } *terms[100]; struct context *contexts[100]; int multiplier; struct term *partial_term; } *

variable_types: wt double

variable_types: n int

variable_types:
prog
char *

variable_types: x double

return_type: double


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

if ( (Renamable_flip_flag & Oriented_flag) != -1 )
fatal_error("init_paramod, called more than once");
Renamable_flip_flag = claim_term_flag();
result = claim_term_flag();
Oriented_flag = result;
return result;
}

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

if ( (Renamable_flip_flag & Oriented_flag) != -1 )
fatal_error("init_paramod, called more than once");
Renamable_flip_flag = claim_term_flag();
result = claim_term_flag();
Oriented_flag = result;
return result;
}

original_code:
void init_paramod(void)
{
  if (Oriented_flag != -1 || Renamable_flip_flag != -1)
    fatal_error("init_paramod, called more than once");
  Renamable_flip_flag = claim_term_flag();
  Oriented_flag = claim_term_flag();
}

canonical_original_code:
void init_paramod()
{
  if (Oriented_flag != -1 || Renamable_flip_flag != -1)
    fatal_error("init_paramod, called more than once");
  Renamable_flip_flag = claim_term_flag();
  Oriented_flag = claim_term_flag();
}


decompiled_code:
__int64 __fastcall mark_renamable_flip(__int64 a1)
{
if ( Renamable_flip_flag == -1 )
fatal_error("mark_renamable_flip, init_paramod() was not called");
return term_flag_set(a1, (unsigned int)Renamable_flip_flag);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( Renamable_flip_flag == -1 )
fatal_error("mark_renamable_flip, init_paramod() was not called");
return term_flag_set(a1, (unsigned int)Renamable_flip_flag);
}

original_code:
void mark_renamable_flip(Term atom)
{
  if (Renamable_flip_flag == -1)
    fatal_error("mark_renamable_flip, init_paramod() was not called");
  term_flag_set(atom, Renamable_flip_flag);
}

canonical_original_code:
void mark_renamable_flip(struct term *atom)
{
  if (Renamable_flip_flag == -1)
    fatal_error("mark_renamable_flip, init_paramod() was not called");
  term_flag_set(atom, Renamable_flip_flag);
}


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

result = 0LL;
if ( Renamable_flip_flag != -1 )
result = term_flag();
return result;
}

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

result = 0LL;
if ( Renamable_flip_flag != -1 )
result = term_flag();
return result;
}

original_code:
BOOL renamable_flip_eq(Term atom)
{
  if (Renamable_flip_flag == -1)
    return FALSE;
  else
    return term_flag(atom, Renamable_flip_flag);
}

canonical_original_code:
enum BOOL renamable_flip_eq(struct term *atom)
{
  if (Renamable_flip_flag == -1)
    return FALSE;
  else
    return term_flag(atom, Renamable_flip_flag);
}


decompiled_code:
__int64 __fastcall renamable_flip_eq_test(__int64 a1)
{
unsigned int v1; // ebp
__int64 v3; // r12
__int64 v4; // rbx
__int64 *v5; // rax
__int64 v6; // rdx

v1 = 0;
if ( !(unsigned int)eq_term() )
{
v3 = copy_term(a1);
v4 = copy_term(a1);
v5 = *(__int64 **)(v4 + 8);
v6 = *v5;
*v5 = v5[1];
*(_QWORD *)(*(_QWORD *)(v4 + 8) + 8LL) = v6;
term_renumber_variables(v3, 100LL);
term_renumber_variables(v4, 100LL);
v1 = term_ident(v3, v4);
zap_term(v3);
zap_term(v4);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // ebp
__int64 v3; // r12
__int64 v4; // rbx
__int64 *v5; // rax
__int64 v6; // rdx

v1 = 0;
if ( !(unsigned int)eq_term() )
{
v3 = copy_term(a1);
v4 = copy_term(a1);
v5 = *(__int64 **)(v4 + 8);
v6 = *v5;
*v5 = v5[1];
*(_QWORD *)(*(_QWORD *)(v4 + 8) + 8LL) = v6;
term_renumber_variables(v3, 100LL);
term_renumber_variables(v4, 100LL);
v1 = term_ident(v3, v4);
zap_term(v3);
zap_term(v4);
}
return v1;
}

original_code:
BOOL renamable_flip_eq_test(Term atom)
{
  if (eq_term(atom))
    return FALSE;
  else {
    BOOL result;
    Term a1 = copy_term(atom);
    Term a2 = copy_term(atom);
    Term tmp = ((a2)->args[0]);
    ((a2)->args[0]) = ((a2)->args[1]);
    ((a2)->args[1]) = tmp;
    term_renumber_variables(a1, 100);
    term_renumber_variables(a2, 100);
    result = term_ident(a1,a2);
    zap_term(a1);
    zap_term(a2);
    return result;
  }
}

canonical_original_code:
enum BOOL renamable_flip_eq_test(struct term *atom)
{
  if (eq_term(atom))
    return FALSE;
  else {
    enum BOOL result;
    struct term *a1 = copy_term(atom);
    struct term *a2 = copy_term(atom);
    struct term *tmp = ((a2)->args[0]);
    ((a2)->args[0]) = ((a2)->args[1]);
    ((a2)->args[1]) = tmp;
    term_renumber_variables(a1, 100);
    term_renumber_variables(a2, 100);
    result = term_ident(a1,a2);
    zap_term(a1);
    zap_term(a2);
    return result;
  }
}

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


decompiled_code:
__int64 __fastcall mark_oriented_eq(__int64 a1)
{
if ( Oriented_flag == -1 )
fatal_error("mark_oriented_eq, init_paramod() was not called");
return term_flag_set(a1, (unsigned int)Oriented_flag);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( Oriented_flag == -1 )
fatal_error("mark_oriented_eq, init_paramod() was not called");
return term_flag_set(a1, (unsigned int)Oriented_flag);
}

original_code:
void mark_oriented_eq(Term atom)
{
  if (Oriented_flag == -1)
    fatal_error("mark_oriented_eq, init_paramod() was not called");
  term_flag_set(atom, Oriented_flag);
}

canonical_original_code:
void mark_oriented_eq(struct term *atom)
{
  if (Oriented_flag == -1)
    fatal_error("mark_oriented_eq, init_paramod() was not called");
  term_flag_set(atom, Oriented_flag);
}


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

result = eq_term();
if ( (_DWORD)result )
{
result = 0LL;
if ( Oriented_flag != -1 )
result = term_flag(a1);
}
return result;
}

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

result = eq_term();
if ( (_DWORD)result )
{
result = 0LL;
if ( Oriented_flag != -1 )
result = term_flag(a1);
}
return result;
}

original_code:
BOOL oriented_eq(Term atom)
{
  if (!eq_term(atom))
    return FALSE;
  else if (Oriented_flag == -1)
    return FALSE;
  else
    return term_flag(atom, Oriented_flag);
}

canonical_original_code:
enum BOOL oriented_eq(struct term *atom)
{
  if (!eq_term(atom))
    return FALSE;
  else if (Oriented_flag == -1)
    return FALSE;
  else
    return term_flag(atom, Oriented_flag);
}


decompiled_code:
__int64 __fastcall same_term_structure(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // ebp
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbx

if ( *(int *)a1 >= 0 )
return *(_DWORD *)a2 >= 0;
if ( *(int *)a2 >= 0 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
{
v3 = *(unsigned __int8 *)(a1 + 4);
if ( *(_BYTE *)(a1 + 4) )
{
v4 = *(_QWORD *)(a2 + 8);
v5 = *(_QWORD *)(a1 + 8);
v6 = 0LL;
while ( 1 )
{
result = same_term_structure(*(_QWORD *)(v5 + 8 * v6), *(_QWORD *)(v4 + 8 * v6));
if ( !(_DWORD)result )
break;
if ( v3 <= (int)++v6 )
return 1LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // ebp
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbx

if ( *(int *)a1 >= 0 )
return *(_DWORD *)a2 >= 0;
if ( *(int *)a2 >= 0 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
{
v3 = *(unsigned __int8 *)(a1 + 4);
if ( *(_BYTE *)(a1 + 4) )
{
v4 = *(_QWORD *)(a2 + 8);
v5 = *(_QWORD *)(a1 + 8);
v6 = 0LL;
while ( 1 )
{
result = func7(*(_QWORD *)(v5 + 8 * v6), *(_QWORD *)(v4 + 8 * v6));
if ( !(_DWORD)result )
break;
if ( v3 <= (int)++v6 )
return 1LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
BOOL same_term_structure(Term t1, Term t2)
{
  if (((t1)->private_symbol >= 0) || ((t2)->private_symbol >= 0))
    return ((t1)->private_symbol >= 0) && ((t2)->private_symbol >= 0);
  else if ((-((t1)->private_symbol)) != (-((t2)->private_symbol)))
    return FALSE;
  else {
    int i;
    for (i = 0; i < ((t1)->arity); i++)
      if (!same_term_structure(((t1)->args[i]), ((t2)->args[i])))
 return FALSE;
    return TRUE;
  }
}

canonical_original_code:
enum BOOL same_term_structure(struct term *t1, struct term *t2)
{
  if (((t1)->private_symbol >= 0) || ((t2)->private_symbol >= 0))
    return ((t1)->private_symbol >= 0) && ((t2)->private_symbol >= 0);
  else if ((-((t1)->private_symbol)) != (-((t2)->private_symbol)))
    return FALSE;
  else {
    int i;
    for (i = 0; i < ((t1)->arity); i++)
      if (!same_term_structure(((t1)->args[i]), ((t2)->args[i])))
 return FALSE;
    return TRUE;
  }
}

variable_types: i int


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

if ( *(_BYTE *)(a1 + 4) != 2 )
fatal_error("top_flip, arity != 2");
result = get_rigid_term_like(a1);
**(_QWORD **)(result + 8) = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
*(_QWORD *)(*(_QWORD *)(result + 8) + 8LL) = **(_QWORD **)(a1 + 8);
*(_BYTE *)(result + 5) = *(_BYTE *)(a1 + 5);
return result;
}

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

if ( *(_BYTE *)(a1 + 4) != 2 )
fatal_error("top_flip, arity != 2");
result = get_rigid_term_like(a1);
**(_QWORD **)(result + 8) = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
*(_QWORD *)(*(_QWORD *)(result + 8) + 8LL) = **(_QWORD **)(a1 + 8);
*(_BYTE *)(result + 5) = *(_BYTE *)(a1 + 5);
return result;
}

original_code:
Term top_flip(Term a)
{
  Term b;
  if (((a)->arity) != 2)
    fatal_error("top_flip, arity != 2");
  b = get_rigid_term_like(a);
  ((b)->args[0]) = ((a)->args[1]);
  ((b)->args[1]) = ((a)->args[0]);
  b->private_flags = a->private_flags;
  return b;
}

canonical_original_code:
struct term *top_flip(struct term *a)
{
  struct term *b;
  if (((a)->arity) != 2)
    fatal_error("top_flip, arity != 2");
  b = get_rigid_term_like(a);
  ((b)->args[0]) = ((a)->args[1]);
  ((b)->args[1]) = ((a)->args[0]);
  b->private_flags = a->private_flags;
  return b;
}

variable_types:
a
struct term *


decompiled_code:
__int64 zap_top_flip()
{
return free_term();
}

canonical_decompiled_code:
__int64 func11()
{
return free_term();
}

original_code:
void zap_top_flip(Term a)
{
  free_term(a);
}

canonical_original_code:
void zap_top_flip(struct term *a)
{
  free_term(a);
}


decompiled_code:
__int64 __fastcall literal_flip(__int64 a1)
{
__int64 v1; // rbx

v1 = get_literals();
*(_DWORD *)v1 = *(_DWORD *)a1;
*(_QWORD *)(v1 + 8) = top_flip(*(_QWORD *)(a1 + 8));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rbx

v1 = get_literals();
*(_DWORD *)v1 = *(_DWORD *)a1;
*(_QWORD *)(v1 + 8) = func10(*(_QWORD *)(a1 + 8));
return v1;
}

original_code:
Literals literal_flip(Literals a)
{
  Literals b = get_literals();
  b->sign = a->sign;
  b->atom = top_flip(a->atom);
  return b;
}

canonical_original_code:
struct literals *literal_flip(struct literals *a)
{
  struct literals *b = get_literals();
  b->sign = a->sign;
  b->atom = top_flip(a->atom);
  return b;
}

variable_types:
a
struct literals *

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


decompiled_code:
__int64 __fastcall zap_literal_flip(__int64 a1)
{
free_term(*(_QWORD *)(a1 + 8));
return free_literals(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
free_term(*(_QWORD *)(a1 + 8));
return free_literals(a1);
}

original_code:
void zap_literal_flip(Literals a)
{
  free_term(a->atom);
  free_literals(a);
}

canonical_original_code:
void zap_literal_flip(struct literals *a)
{
  free_term(a->atom);
  free_literals(a);
}


decompiled_code:
_BOOL8 __fastcall equational_def_2(int *a1, __int64 a2)
{
_BOOL8 result; // rax
int v3; // edx
int v4; // edx

result = 0LL;
if ( *a1 < 0 )
{
v3 = args_distinct_vars();
result = 0LL;
if ( v3 )
{
v4 = variables_subset(a2, a1);
result = 0LL;
if ( v4 )
result = (unsigned int)symbol_occurrences(a2, (unsigned int)-*a1) == 0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(int *a1, __int64 a2)
{
_BOOL8 result; // rax
int v3; // edx
int v4; // edx

result = 0LL;
if ( *a1 < 0 )
{
v3 = args_distinct_vars();
result = 0LL;
if ( v3 )
{
v4 = variables_subset(a2, a1);
result = 0LL;
if ( v4 )
result = (unsigned int)symbol_occurrences(a2, (unsigned int)-*a1) == 0;
}
}
return result;
}

original_code:
BOOL equational_def_2(Term alpha, Term beta)
{
  return (!((alpha)->private_symbol >= 0) &&
   args_distinct_vars(alpha) &&
   variables_subset(beta, alpha) &&
   symbol_occurrences(beta, (-((alpha)->private_symbol))) == 0);
}

canonical_original_code:
enum BOOL equational_def_2(struct term *alpha, struct term *beta)
{
  return (!((alpha)->private_symbol >= 0) &&
   args_distinct_vars(alpha) &&
   variables_subset(beta, alpha) &&
   symbol_occurrences(beta, (-((alpha)->private_symbol))) == 0);
}

variable_types:
beta
struct term *


decompiled_code:
__int64 __fastcall unfold_order(int *a1, int *a2)
{
int v3; // edi
__int64 result; // rax
_BOOL4 v5; // edx

v3 = *a1;
if ( v3 >= 0
|| !(unsigned int)is_unfold_symbol((unsigned int)-v3)
|| (v5 = equational_def_2(a1, (__int64)a2), result = 3LL, !v5) )
{
result = 0LL;
if ( *a2 < 0 )
{
result = is_unfold_symbol((unsigned int)-*a2);
if ( (_DWORD)result )
{
result = equational_def_2(a2, (__int64)a1);
if ( (_DWORD)result )
result = 2LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int *a1, int *a2)
{
int v3; // edi
__int64 result; // rax
_BOOL4 v5; // edx

v3 = *a1;
if ( v3 >= 0
|| !(unsigned int)is_unfold_symbol((unsigned int)-v3)
|| (v5 = func15(a1, (__int64)a2), result = 3LL, !v5) )
{
result = 0LL;
if ( *a2 < 0 )
{
result = is_unfold_symbol((unsigned int)-*a2);
if ( (_DWORD)result )
{
result = func15(a2, (__int64)a1);
if ( (_DWORD)result )
result = 2LL;
}
}
}
return result;
}

original_code:
Ordertype unfold_order(Term alpha, Term beta)
{
  if (!((alpha)->private_symbol >= 0) &&
      is_unfold_symbol((-((alpha)->private_symbol))) &&
      equational_def_2(alpha, beta))
    return GREATER_THAN;
  else if (!((beta)->private_symbol >= 0) &&
    is_unfold_symbol((-((beta)->private_symbol))) &&
    equational_def_2(beta, alpha))
    return LESS_THAN;
  else
    return NOT_COMPARABLE;
}

canonical_original_code:
enum Ordertype unfold_order(struct term *alpha, struct term *beta)
{
  if (!((alpha)->private_symbol >= 0) &&
      is_unfold_symbol((-((alpha)->private_symbol))) &&
      equational_def_2(alpha, beta))
    return GREATER_THAN;
  else if (!((beta)->private_symbol >= 0) &&
    is_unfold_symbol((-((beta)->private_symbol))) &&
    equational_def_2(beta, alpha))
    return LESS_THAN;
  else
    return NOT_COMPARABLE;
}

return_type: 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 }


decompiled_code:
__int64 __fastcall put_term_to_ibuf(__int64 a1, __int64 a2)
{
int v3; // esi
__int64 result; // rax
__int64 v5; // rbp

v3 = *(_DWORD *)a2;
if ( v3 >= 0 )
return ibuf_write(a1, (unsigned int)-v3);
result = ibuf_write(a1, (unsigned int)-v3);
if ( *(_BYTE *)(a2 + 4) )
{
v5 = 0LL;
do
{
put_term_to_ibuf(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v5++));
result = *(unsigned __int8 *)(a2 + 4);
}
while ( (int)result > (int)v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v3; // esi
__int64 result; // rax
__int64 v5; // rbp

v3 = *(_DWORD *)a2;
if ( v3 >= 0 )
return ibuf_write(a1, (unsigned int)-v3);
result = ibuf_write(a1, (unsigned int)-v3);
if ( *(_BYTE *)(a2 + 4) )
{
v5 = 0LL;
do
{
func0(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v5++));
result = *(unsigned __int8 *)(a2 + 4);
}
while ( (int)result > (int)v5 );
}
return result;
}

original_code:
static
void put_term_to_ibuf(Ibuffer ibuf, Term t)
{
  if (((t)->private_symbol >= 0))
    ibuf_write(ibuf, -((t)->private_symbol));
  else {
    int i;
    ibuf_write(ibuf, (-((t)->private_symbol)));
    for (i = 0; i < ((t)->arity); i++) {
      put_term_to_ibuf(ibuf, ((t)->args[i]));
    }
  }
}

canonical_original_code:
static void put_term_to_ibuf(struct ibuffer *ibuf, struct term *t)
{
  if (((t)->private_symbol >= 0))
    ibuf_write(ibuf, -((t)->private_symbol));
  else {
    int i;
    ibuf_write(ibuf, (-((t)->private_symbol)));
    for (i = 0; i < ((t)->arity); i++) {
      put_term_to_ibuf(ibuf, ((t)->args[i]));
    }
  }
}

variable_types: struct ibuffer { int write_position; int read_position; int size; int *buf; } *


decompiled_code:
__int64 __fastcall put_i3list_to_ibuf(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // rbx
unsigned int v3; // eax
__int64 result; // rax

v2 = a2;
v3 = i3list_count(a2);
for ( result = ibuf_write(a1, v3); v2; v2 = (unsigned int *)*((_QWORD *)v2 + 2) )
{
ibuf_write(a1, *v2);
ibuf_write(a1, v2[1]);
result = ibuf_write(a1, v2[2]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // rbx
unsigned int v3; // eax
__int64 result; // rax

v2 = a2;
v3 = i3list_count(a2);
for ( result = ibuf_write(a1, v3); v2; v2 = (unsigned int *)*((_QWORD *)v2 + 2) )
{
ibuf_write(a1, *v2);
ibuf_write(a1, v2[1]);
result = ibuf_write(a1, v2[2]);
}
return result;
}

original_code:
static
void put_i3list_to_ibuf(Ibuffer ibuf, I3list p)
{
  ibuf_write(ibuf, i3list_count(p));
  for (; p; p = p->next) {
    ibuf_write(ibuf, p->i);
    ibuf_write(ibuf, p->j);
    ibuf_write(ibuf, p->k);
  }
}

canonical_original_code:
static void put_i3list_to_ibuf(struct ibuffer *ibuf, struct i3list *p)
{
  ibuf_write(ibuf, i3list_count(p));
  for (; p; p = p->next) {
    ibuf_write(ibuf, p->i);
    ibuf_write(ibuf, p->j);
    ibuf_write(ibuf, p->k);
  }
}

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

user_defined_types: struct ibuffer { int write_position; int read_position; int size; int *buf; }


decompiled_code:
__int64 __fastcall put_ilist_to_ibuf(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // rbx
unsigned int v3; // eax
__int64 result; // rax

v2 = a2;
v3 = ilist_count(a2);
for ( result = ibuf_write(a1, v3); v2; v2 = (unsigned int *)*((_QWORD *)v2 + 1) )
result = ibuf_write(a1, *v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // rbx
unsigned int v3; // eax
__int64 result; // rax

v2 = a2;
v3 = ilist_count(a2);
for ( result = ibuf_write(a1, v3); v2; v2 = (unsigned int *)*((_QWORD *)v2 + 1) )
result = ibuf_write(a1, *v2);
return result;
}

original_code:
static
void put_ilist_to_ibuf(Ibuffer ibuf, Ilist p)
{
  ibuf_write(ibuf, ilist_count(p));
  for (; p; p = p->next)
    ibuf_write(ibuf, p->i);
}

canonical_original_code:
static void put_ilist_to_ibuf(struct ibuffer *ibuf, struct ilist *p)
{
  ibuf_write(ibuf, ilist_count(p));
  for (; p; p = p->next)
    ibuf_write(ibuf, p->i);
}

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