decompiled_code:
__int64 __fastcall weight_beta_check(_DWORD *a1)
{
_DWORD *v1; // rbp
int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
char v5[32]; // [rsp+8h] [rbp-20h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
_DWORD *v1; // rbp
int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
char v5[32]; // [rsp+8h] [rbp-20h] BYREF

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

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


repo: jessealama/ladr

decompiled_code:
__int64 __fastcall weight_rule_check(__int64 a1)
{
_DWORD **v1; // rax
__int64 result; // rax

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

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

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

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

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

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 apply_depth(int *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r12
int v5; // ebp
int v6; // eax

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

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r12
int v5; // ebp
int v6; // eax

v2 = *a1;
if ( (int)v2 >= 0 )
return term_depth(*(_QWORD *)(a2 + 8 * v2));
result = 0LL;
if ( *((_BYTE *)a1 + 4) )
{
v4 = 0LL;
v5 = 0;
do
{
v6 = func2(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4), a2);
if ( v5 < v6 )
v5 = v6;
++v4;
}
while ( *((unsigned __int8 *)a1 + 4) > (int)v4 );
result = (unsigned int)(v5 + 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: i int

variable_types: d int

return_type: int


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

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

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

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

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

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


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

return_type: void


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

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

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

if ( Renamable_flip_flag == -1 )
result = 0LL;
else
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)
{
__int64 v2; // r13
__int64 v3; // rbp
_QWORD *v4; // rax
__int64 v5; // rcx
unsigned int v6; // er12

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // r13
__int64 v3; // rbp
_QWORD *v4; // rax
__int64 v5; // rcx
unsigned int v6; // er12

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

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

if ( (unsigned int)eq_term() && Oriented_flag != -1 )
result = term_flag(a1);
else
result = 0LL;
return result;
}

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

if ( (unsigned int)eq_term() && Oriented_flag != -1 )
result = term_flag(a1);
else
result = 0LL;
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)
{
int v2; // edx
__int64 result; // rax
int v4; // ebp
__int64 v5; // r13
__int64 v6; // r12
__int64 v7; // rbx

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

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

v2 = *(_DWORD *)a2;
if ( *(int *)a1 >= 0 )
return v2 >= 0;
result = 0LL;
if ( v2 < 0 && *(_DWORD *)a1 == v2 )
{
v4 = *(unsigned __int8 *)(a1 + 4);
if ( *(_BYTE *)(a1 + 4) )
{
v5 = *(_QWORD *)(a2 + 8);
v6 = *(_QWORD *)(a1 + 8);
v7 = 0LL;
while ( 1 )
{
result = func7(*(_QWORD *)(v6 + 8 * v7), *(_QWORD *)(v5 + 8 * v7));
if ( !(_DWORD)result )
break;
if ( v4 <= (int)++v7 )
goto LABEL_8;
}
}
else
{
LABEL_8:
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;
  }
}


decompiled_code:
__int64 __fastcall top_flip(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rcx
_QWORD *v3; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rcx
_QWORD *v3; // rdx

if ( *(_BYTE *)(a1 + 4) != 2 )
fatal_error("top_flip, arity != 2");
result = get_rigid_term_like(a1);
v2 = *(_QWORD **)(a1 + 8);
v3 = *(_QWORD **)(result + 8);
*v3 = v2[1];
v3[1] = *v2;
*(_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 *

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:
// attributes: thunk
__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 v2; // rax
__int64 v3; // rdi
__int64 v4; // r12

v2 = get_literals();
v3 = *(_QWORD *)(a1 + 8);
v4 = v2;
*(_DWORD *)v2 = *(_DWORD *)a1;
*(_QWORD *)(v2 + 8) = top_flip(v3);
return v4;
}

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)
{
if ( *a1 >= 0 )
return 0LL;
if ( (unsigned int)args_distinct_vars() && (unsigned int)variables_subset(a2, a1) )
return (unsigned int)symbol_occurrences(a2, (unsigned int)-*a1) == 0;
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(int *a1, __int64 a2)
{
if ( *a1 >= 0 )
return 0LL;
if ( (unsigned int)args_distinct_vars() && (unsigned int)variables_subset(a2, a1) )
return (unsigned int)symbol_occurrences(a2, (unsigned int)-*a1) == 0;
return 0LL;
}

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; // er8
_BOOL4 v6; // er8

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

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

v3 = *a1;
if ( v3 >= 0
|| !(unsigned int)is_unfold_symbol((unsigned int)-v3)
|| (v6 = func16(a1, (__int64)a2), result = 3LL, !v6) )
{
if ( *a2 >= 0
|| !(unsigned int)is_unfold_symbol((unsigned int)-*a2)
|| (v5 = func16(a2, (__int64)a1), result = 2LL, !v5) )
{
result = 0LL;
}
}
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 v2; // eax
__int64 v4; // rsi
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v4; // rsi
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rsi

v2 = *(_DWORD *)a2;
v4 = (unsigned int)-*(_DWORD *)a2;
if ( v2 >= 0 )
return ibuf_write(a1, v4);
result = ibuf_write(a1, v4);
v6 = 0LL;
if ( *(_BYTE *)(a2 + 4) )
{
do
{
v7 = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v6++);
func0(a1, v7);
result = *(unsigned __int8 *)(a2 + 4);
}
while ( (int)result > (int)v6 );
}
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; } *


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

v2 = a2;
v3 = just_count(a2);
for ( result = ibuf_write(a1, v3); v2; v2 = (unsigned int **)v2[1] )
{
ibuf_write(a1, *(unsigned int *)v2);
result = *(unsigned int *)v2;
switch ( *(_DWORD *)v2 )
{
case 0:
case 1:
continue;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 0x16:
case 0x17:
case 0x18:
result = ibuf_write(a1, *((unsigned int *)v2 + 4));
break;
case 9:
case 0xA:
case 0xB:
case 0xC:
case 0xD:
case 0x15:
result = put_ilist_to_ibuf(a1, v2[2]);
break;
case 0xE:
case 0xF:
case 0x10:
case 0x11:
ibuf_write(a1, *v2[2]);
put_ilist_to_ibuf(a1, *((unsigned int **)v2[2] + 1));
ibuf_write(a1, v2[2][1]);
result = put_ilist_to_ibuf(a1, *((unsigned int **)v2[2] + 2));
break;
case 0x14:
result = put_i3list_to_ibuf(a1, v2[2]);
break;
default:
result = fatal_error("put_just_to_ibuf, unknown type");
break;
}
}
return result;
}

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

v2 = a2;
v3 = just_count(a2);
for ( result = ibuf_write(a1, v3); v2; v2 = (unsigned int **)v2[1] )
{
ibuf_write(a1, *(unsigned int *)v2);
result = *(unsigned int *)v2;
switch ( *(_DWORD *)v2 )
{
case 0:
case 1:
continue;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 0x16:
case 0x17:
case 0x18:
result = ibuf_write(a1, *((unsigned int *)v2 + 4));
break;
case 9:
case 0xA:
case 0xB:
case 0xC:
case 0xD:
case 0x15:
result = func2(a1, v2[2]);
break;
case 0xE:
case 0xF:
case 0x10:
case 0x11:
ibuf_write(a1, *v2[2]);
func2(a1, *((unsigned int **)v2[2] + 1));
ibuf_write(a1, v2[2][1]);
result = func2(a1, *((unsigned int **)v2[2] + 2));
break;
case 0x14:
result = func1(a1, v2[2]);
break;
default:
result = fatal_error("put_just_to_ibuf, unknown type");
break;
}
}
return result;
}

original_code:
static
void put_just_to_ibuf(Ibuffer ibuf, Just j)
{
  ibuf_write(ibuf, just_count(j));
  for (; j; j = j->next) {
    ibuf_write(ibuf, j->type);
    switch (j->type) {
    case INPUT_JUST:
    case GOAL_JUST:
      break;
    case CLAUSIFY_JUST:
    case DENY_JUST:
    case COPY_JUST:
    case BACK_DEMOD_JUST:
    case BACK_UNIT_DEL_JUST:
    case FLIP_JUST:
    case XX_JUST:
    case MERGE_JUST:
    case NEW_SYMBOL_JUST:
      ibuf_write(ibuf, j->u.id);
      break;
    case BINARY_RES_JUST:
    case HYPER_RES_JUST:
    case UR_RES_JUST:
    case UNIT_DEL_JUST:
    case FACTOR_JUST:
    case XXRES_JUST:
      put_ilist_to_ibuf(ibuf, j->u.lst);
      break;
    case DEMOD_JUST:
      put_i3list_to_ibuf(ibuf, j->u.demod);
      break;
    case PARA_JUST:
    case PARA_FX_JUST:
    case PARA_IX_JUST:
    case PARA_FX_IX_JUST:
      ibuf_write(ibuf, j->u.para->from_id);
      put_ilist_to_ibuf(ibuf, j->u.para->from_pos);
      ibuf_write(ibuf, j->u.para->into_id);
      put_ilist_to_ibuf(ibuf, j->u.para->into_pos);
      break;
    default: fatal_error("put_just_to_ibuf, unknown type");
    }
  }
}

canonical_original_code:
static void put_just_to_ibuf(struct ibuffer *ibuf, struct just *j)
{
  ibuf_write(ibuf, just_count(j));
  for (; j; j = j->next) {
    ibuf_write(ibuf, j->type);
    switch (j->type) {
    case INPUT_JUST:
    case GOAL_JUST:
      break;
    case CLAUSIFY_JUST:
    case DENY_JUST:
    case COPY_JUST:
    case BACK_DEMOD_JUST:
    case BACK_UNIT_DEL_JUST:
    case FLIP_JUST:
    case XX_JUST:
    case MERGE_JUST:
    case NEW_SYMBOL_JUST:
      ibuf_write(ibuf, j->u.id);
      break;
    case BINARY_RES_JUST:
    case HYPER_RES_JUST:
    case UR_RES_JUST:
    case UNIT_DEL_JUST:
    case FACTOR_JUST:
    case XXRES_JUST:
      put_ilist_to_ibuf(ibuf, j->u.lst);
      break;
    case DEMOD_JUST:
      put_i3list_to_ibuf(ibuf, j->u.demod);
      break;
    case PARA_JUST:
    case PARA_FX_JUST:
    case PARA_IX_JUST:
    case PARA_FX_IX_JUST:
      ibuf_write(ibuf, j->u.para->from_id);
      put_ilist_to_ibuf(ibuf, j->u.para->from_pos);
      ibuf_write(ibuf, j->u.para->into_id);
      put_ilist_to_ibuf(ibuf, j->u.para->into_pos);
      break;
    default: fatal_error("put_just_to_ibuf, unknown type");
    }
  }
}

variable_types: struct just { enum Just_type { INPUT_JUST=0, GOAL_JUST=1, DENY_JUST=2, CLAUSIFY_JUST=3, COPY_JUST=4, BACK_DEMOD_JUST=5, BACK_UNIT_DEL_JUST=6, NEW_SYMBOL_JUST=7, EXPAND_DEF_JUST=8, BINARY_RES_JUST=9, HYPER_RES_JUST=10, UR_RES_JUST=11, FACTOR_JUST=12, XXRES_JUST=13, PARA_JUST=14, PARA_FX_JUST=15, PARA_IX_JUST=16, PARA_FX_IX_JUST=17, INSTANCE_JUST=18, PROPOSITIONAL_JUST=19, DEMOD_JUST=20, UNIT_DEL_JUST=21, FLIP_JUST=22, XX_JUST=23, MERGE_JUST=24, EVAL_JUST=25, IVY_JUST=26, UNKNOWN_JUST=27 } type; struct just *next; union { int id; struct ilist { int i; struct ilist *next; } *lst; struct parajust { int from_id; int into_id; struct ilist *from_pos; struct ilist *into_pos; } *para; struct i3list { int i; int j; int k; struct i3list *next; } *demod; struct instancejust { int parent_id; struct plist { void *v; struct plist *next; } *pairs; } *instance; struct ivyjust { enum Just_type { INPUT_JUST=0, GOAL_JUST=1, DENY_JUST=2, CLAUSIFY_JUST=3, COPY_JUST=4, BACK_DEMOD_JUST=5, BACK_UNIT_DEL_JUST=6, NEW_SYMBOL_JUST=7, EXPAND_DEF_JUST=8, BINARY_RES_JUST=9, HYPER_RES_JUST=10, UR_RES_JUST=11, FACTOR_JUST=12, XXRES_JUST=13, PARA_JUST=14, PARA_FX_JUST=15, PARA_IX_JUST=16, PARA_FX_IX_JUST=17, INSTANCE_JUST=18, PROPOSITIONAL_JUST=19, DEMOD_JUST=20, UNIT_DEL_JUST=21, FLIP_JUST=22, XX_JUST=23, MERGE_JUST=24, EVAL_JUST=25, IVY_JUST=26, UNKNOWN_JUST=27 } type; int parent1; int parent2; struct ilist *pos1; struct ilist *pos2; struct plist *pairs; } *ivy; } u; } *

user_defined_types: struct just { enum Just_type type; struct just *next; union { int id; struct ilist *lst; struct parajust *para; struct i3list *demod; struct instancejust *instance; struct ivyjust *ivy; } u; }

user_defined_types: struct instancejust { int parent_id; struct plist *pairs; }

user_defined_types: struct ivyjust { enum Just_type type; int parent1; int parent2; struct ilist *pos1; struct ilist *pos2; struct plist *pairs; }


decompiled_code:
__int64 __fastcall get_i3list_from_ibuf(__int64 a1)
{
int v1; // eax
int v2; // er13
__int64 v3; // rbp
int v4; // er15
unsigned int v5; // er12
unsigned int v6; // er14
unsigned int v7; // eax

v1 = ((__int64 (*)(void))ibuf_xread)();
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0LL;
v4 = 0;
do
{
++v4;
v5 = ibuf_xread(a1);
v6 = ibuf_xread(a1);
v7 = ibuf_xread(a1);
v3 = i3list_append(v3, v5, v6, v7);
}
while ( v2 != v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
int v2; // er13
__int64 v3; // rbp
int v4; // er15
unsigned int v5; // er12
unsigned int v6; // er14
unsigned int v7; // eax

v1 = ((__int64 (*)(void))ibuf_xread)();
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0LL;
v4 = 0;
do
{
++v4;
v5 = ibuf_xread(a1);
v6 = ibuf_xread(a1);
v7 = ibuf_xread(a1);
v3 = i3list_append(v3, v5, v6, v7);
}
while ( v2 != v4 );
return v3;
}

original_code:
static
I3list get_i3list_from_ibuf(Ibuffer ibuf)
{
  int i;
  I3list p = ((void *)0);
  int n = ibuf_xread(ibuf);
  for (i = 0; i < n; i++) {
    int i1 = ibuf_xread(ibuf);
    int i2 = ibuf_xread(ibuf);
    int i3 = ibuf_xread(ibuf);
    p = i3list_append(p, i1, i2, i3);
  }
  return p;
}

canonical_original_code:
static struct i3list *get_i3list_from_ibuf(struct ibuffer *ibuf)
{
  int i;
  struct i3list *p = ((void *)0);
  int n = ibuf_xread(ibuf);
  for (i = 0; i < n; i++) {
    int i1 = ibuf_xread(ibuf);
    int i2 = ibuf_xread(ibuf);
    int i3 = ibuf_xread(ibuf);
    p = i3list_append(p, i1, i2, i3);
  }
  return p;
}

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


decompiled_code:
__int64 __fastcall get_ilist_from_ibuf(__int64 a1)
{
int v1; // eax
int v2; // ebx
__int64 v3; // rbp
int v4; // er13
unsigned int v5; // eax
__int64 result; // rax

v1 = ibuf_xread(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0LL;
v4 = 0;
do
{
++v4;
v5 = ibuf_xread(a1);
result = ilist_append(v3, v5);
v3 = result;
}
while ( v2 != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // eax
int v2; // ebx
__int64 v3; // rbp
int v4; // er13
unsigned int v5; // eax
__int64 result; // rax

v1 = ibuf_xread(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0LL;
v4 = 0;
do
{
++v4;
v5 = ibuf_xread(a1);
result = ilist_append(v3, v5);
v3 = result;
}
while ( v2 != v4 );
return result;
}

original_code:
static
Ilist get_ilist_from_ibuf(Ibuffer ibuf)
{
  int i;
  Ilist p = ((void *)0);
  int n = ibuf_xread(ibuf);
  for (i = 0; i < n; i++)
    p = ilist_append(p, ibuf_xread(ibuf));
  return p;
}

canonical_original_code:
static struct ilist *get_ilist_from_ibuf(struct ibuffer *ibuf)
{
  int i;
  struct ilist *p = ((void *)0);
  int n = ibuf_xread(ibuf);
  for (i = 0; i < n; i++)
    p = ilist_append(p, ibuf_xread(ibuf));
  return p;
}

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


decompiled_code:
__int64 __fastcall get_just_from_ibuf(__int64 a1)
{
int v1; // eax
int v2; // er15
int v3; // ebx
__int64 v4; // r13
unsigned int v5; // er12
unsigned int *v6; // rax
unsigned int *v7; // rbp
_DWORD *v9; // rax
__int64 v10; // r12
__int64 v11; // r12
__int64 v12; // r12

v1 = ibuf_xread(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0;
v4 = 0LL;
do
{
v5 = ibuf_xread(a1);
v6 = (unsigned int *)get_just();
*v6 = v5;
v7 = v6;
switch ( v5 )
{
case 0u:
case 1u:
break;
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
case 0x16u:
case 0x17u:
case 0x18u:
v6[4] = ibuf_xread(a1);
break;
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0x15u:
*((_QWORD *)v6 + 2) = get_ilist_from_ibuf(a1);
break;
case 0xEu:
case 0xFu:
case 0x10u:
case 0x11u:
v9 = (_DWORD *)get_parajust();
*((_QWORD *)v7 + 2) = v9;
*v9 = ibuf_xread(a1);
v10 = *((_QWORD *)v7 + 2);
*(_QWORD *)(v10 + 8) = get_ilist_from_ibuf(a1);
v11 = *((_QWORD *)v7 + 2);
*(_DWORD *)(v11 + 4) = ibuf_xread(a1);
v12 = *((_QWORD *)v7 + 2);
*(_QWORD *)(v12 + 16) = get_ilist_from_ibuf(a1);
break;
case 0x14u:
*((_QWORD *)v6 + 2) = get_i3list_from_ibuf(a1);
break;
default:
printf("unknown just type: %d\n", v5);
fatal_error("get_just_from_ibuf, unknown just");
break;
}
++v3;
v4 = append_just(v4, v7);
}
while ( v2 != v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // eax
int v2; // er15
int v3; // ebx
__int64 v4; // r13
unsigned int v5; // er12
unsigned int *v6; // rax
unsigned int *v7; // rbp
_DWORD *v9; // rax
__int64 v10; // r12
__int64 v11; // r12
__int64 v12; // r12

v1 = ibuf_xread(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0;
v4 = 0LL;
do
{
v5 = ibuf_xread(a1);
v6 = (unsigned int *)get_just();
*v6 = v5;
v7 = v6;
switch ( v5 )
{
case 0u:
case 1u:
break;
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
case 0x16u:
case 0x17u:
case 0x18u:
v6[4] = ibuf_xread(a1);
break;
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0x15u:
*((_QWORD *)v6 + 2) = func5(a1);
break;
case 0xEu:
case 0xFu:
case 0x10u:
case 0x11u:
v9 = (_DWORD *)get_parajust();
*((_QWORD *)v7 + 2) = v9;
*v9 = ibuf_xread(a1);
v10 = *((_QWORD *)v7 + 2);
*(_QWORD *)(v10 + 8) = func5(a1);
v11 = *((_QWORD *)v7 + 2);
*(_DWORD *)(v11 + 4) = ibuf_xread(a1);
v12 = *((_QWORD *)v7 + 2);
*(_QWORD *)(v12 + 16) = func5(a1);
break;
case 0x14u:
*((_QWORD *)v6 + 2) = func4(a1);
break;
default:
printf("unknown just type: %d\n", v5);
fatal_error("get_just_from_ibuf, unknown just");
break;
}
++v3;
v4 = append_just(v4, v7);
}
while ( v2 != v3 );
return v4;
}

original_code:
static
Just get_just_from_ibuf(Ibuffer ibuf)
{
  Just j_collect = ((void *)0);
  int i;
  int n = ibuf_xread(ibuf);
  for (i = 0; i < n; i++) {
    int type = ibuf_xread(ibuf);
    Just j = get_just();
    j->type = type;
    switch (type) {
    case INPUT_JUST:
    case GOAL_JUST:
      break;
    case CLAUSIFY_JUST:
    case DENY_JUST:
    case COPY_JUST:
    case BACK_DEMOD_JUST:
    case BACK_UNIT_DEL_JUST:
    case FLIP_JUST:
    case XX_JUST:
    case MERGE_JUST:
    case NEW_SYMBOL_JUST:
      j->u.id = ibuf_xread(ibuf);
      break;
    case BINARY_RES_JUST:
    case HYPER_RES_JUST:
    case UR_RES_JUST:
    case UNIT_DEL_JUST:
    case FACTOR_JUST:
    case XXRES_JUST:
      j->u.lst = get_ilist_from_ibuf(ibuf);
      break;
    case DEMOD_JUST:
      j->u.demod = get_i3list_from_ibuf(ibuf);
      break;
    case PARA_JUST:
    case PARA_FX_JUST:
    case PARA_IX_JUST:
    case PARA_FX_IX_JUST:
      j->u.para = get_parajust();
      j->u.para->from_id = ibuf_xread(ibuf);
      j->u.para->from_pos = get_ilist_from_ibuf(ibuf);
      j->u.para->into_id = ibuf_xread(ibuf);
      j->u.para->into_pos = get_ilist_from_ibuf(ibuf);
      break;
    default:
      printf("unknown just type: %d\n", type);
      fatal_error("get_just_from_ibuf, unknown just");
    }
    j_collect = append_just(j_collect, j);
  }
  return j_collect;
}

canonical_original_code:
static struct just *get_just_from_ibuf(struct ibuffer *ibuf)
{
  struct just *j_collect = ((void *)0);
  int i;
  int n = ibuf_xread(ibuf);
  for (i = 0; i < n; i++) {
    int type = ibuf_xread(ibuf);
    struct just *j = get_just();
    j->type = type;
    switch (type) {
    case INPUT_JUST:
    case GOAL_JUST:
      break;
    case CLAUSIFY_JUST:
    case DENY_JUST:
    case COPY_JUST:
    case BACK_DEMOD_JUST:
    case BACK_UNIT_DEL_JUST:
    case FLIP_JUST:
    case XX_JUST:
    case MERGE_JUST:
    case NEW_SYMBOL_JUST:
      j->u.id = ibuf_xread(ibuf);
      break;
    case BINARY_RES_JUST:
    case HYPER_RES_JUST:
    case UR_RES_JUST:
    case UNIT_DEL_JUST:
    case FACTOR_JUST:
    case XXRES_JUST:
      j->u.lst = get_ilist_from_ibuf(ibuf);
      break;
    case DEMOD_JUST:
      j->u.demod = get_i3list_from_ibuf(ibuf);
      break;
    case PARA_JUST:
    case PARA_FX_JUST:
    case PARA_IX_JUST:
    case PARA_FX_IX_JUST:
      j->u.para = get_parajust();
      j->u.para->from_id = ibuf_xread(ibuf);
      j->u.para->from_pos = get_ilist_from_ibuf(ibuf);
      j->u.para->into_id = ibuf_xread(ibuf);
      j->u.para->into_pos = get_ilist_from_ibuf(ibuf);
      break;
    default:
      printf("unknown just type: %d\n", type);
      fatal_error("get_just_from_ibuf, unknown just");
    }
    j_collect = append_just(j_collect, j);
  }
  return j_collect;
}

variable_types: type int

return_type: struct just { enum Just_type { INPUT_JUST=0, GOAL_JUST=1, DENY_JUST=2, CLAUSIFY_JUST=3, COPY_JUST=4, BACK_DEMOD_JUST=5, BACK_UNIT_DEL_JUST=6, NEW_SYMBOL_JUST=7, EXPAND_DEF_JUST=8, BINARY_RES_JUST=9, HYPER_RES_JUST=10, UR_RES_JUST=11, FACTOR_JUST=12, XXRES_JUST=13, PARA_JUST=14, PARA_FX_JUST=15, PARA_IX_JUST=16, PARA_FX_IX_JUST=17, INSTANCE_JUST=18, PROPOSITIONAL_JUST=19, DEMOD_JUST=20, UNIT_DEL_JUST=21, FLIP_JUST=22, XX_JUST=23, MERGE_JUST=24, EVAL_JUST=25, IVY_JUST=26, UNKNOWN_JUST=27 } type; struct just *next; union { int id; struct ilist { int i; struct ilist *next; } *lst; struct parajust { int from_id; int into_id; struct ilist *from_pos; struct ilist *into_pos; } *para; struct i3list { int i; int j; int k; struct i3list *next; } *demod; struct instancejust { int parent_id; struct plist { void *v; struct plist *next; } *pairs; } *instance; struct ivyjust { enum Just_type { INPUT_JUST=0, GOAL_JUST=1, DENY_JUST=2, CLAUSIFY_JUST=3, COPY_JUST=4, BACK_DEMOD_JUST=5, BACK_UNIT_DEL_JUST=6, NEW_SYMBOL_JUST=7, EXPAND_DEF_JUST=8, BINARY_RES_JUST=9, HYPER_RES_JUST=10, UR_RES_JUST=11, FACTOR_JUST=12, XXRES_JUST=13, PARA_JUST=14, PARA_FX_JUST=15, PARA_IX_JUST=16, PARA_FX_IX_JUST=17, INSTANCE_JUST=18, PROPOSITIONAL_JUST=19, DEMOD_JUST=20, UNIT_DEL_JUST=21, FLIP_JUST=22, XX_JUST=23, MERGE_JUST=24, EVAL_JUST=25, IVY_JUST=26, UNKNOWN_JUST=27 } type; int parent1; int parent2; struct ilist *pos1; struct ilist *pos2; struct plist *pairs; } *ivy; } u; } *


decompiled_code:
__int64 __fastcall get_term_from_ibuf(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v3; // er13
__int64 v4; // r12
__int64 v5; // rbx
_QWORD *v6; // r13

v1 = ibuf_xread(a1);
v2 = v1;
if ( v1 <= 0 )
return get_variable_term((unsigned int)-v1);
v3 = sn_to_arity((unsigned int)v1);
if ( v3 == -1 )
{
printf("bad symnum: %d\n", v2);
fatal_error("get_term_from_ibuf, symbol not in symbol table");
}
v4 = get_rigid_term_dangerously(v2, v3);
if ( *(_BYTE *)(v4 + 4) )
{
v5 = 0LL;
do
{
v6 = (_QWORD *)(*(_QWORD *)(v4 + 8) + 8 * v5++);
*v6 = get_term_from_ibuf(a1);
}
while ( *(unsigned __int8 *)(v4 + 4) > (int)v5 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v3; // er13
__int64 v4; // r12
__int64 v5; // rbx
_QWORD *v6; // r13

v1 = ibuf_xread(a1);
v2 = v1;
if ( v1 <= 0 )
return get_variable_term((unsigned int)-v1);
v3 = sn_to_arity((unsigned int)v1);
if ( v3 == -1 )
{
printf("bad symnum: %d\n", v2);
fatal_error("get_term_from_ibuf, symbol not in symbol table");
}
v4 = get_rigid_term_dangerously(v2, v3);
if ( *(_BYTE *)(v4 + 4) )
{
v5 = 0LL;
do
{
v6 = (_QWORD *)(*(_QWORD *)(v4 + 8) + 8 * v5++);
*v6 = func7(a1);
}
while ( *(unsigned __int8 *)(v4 + 4) > (int)v5 );
}
return v4;
}

original_code:
static
Term get_term_from_ibuf(Ibuffer ibuf)
{
  int a = ibuf_xread(ibuf);
  if (a <= 0)
    return get_variable_term(-a);
  else {
    Term t;
    int i;
    int arity = sn_to_arity(a);
    if (arity == -1) {
      printf("bad symnum: %d\n", a);
      fatal_error("get_term_from_ibuf, symbol not in symbol table");
    }
    t = get_rigid_term_dangerously(a, arity);
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = get_term_from_ibuf(ibuf);
    return t;
  }
}

canonical_original_code:
static struct term *get_term_from_ibuf(struct ibuffer *ibuf)
{
  int a = ibuf_xread(ibuf);
  if (a <= 0)
    return get_variable_term(-a);
  else {
    struct term *t;
    int i;
    int arity = sn_to_arity(a);
    if (arity == -1) {
      printf("bad symnum: %d\n", a);
      fatal_error("get_term_from_ibuf, symbol not in symbol table");
    }
    t = get_rigid_term_dangerously(a, arity);
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = get_term_from_ibuf(ibuf);
    return t;
  }
}

variable_types: a 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: i int

variable_types: arity int


decompiled_code:
__int64 nonunit_fsub_tests()
{
return (unsigned int)Nonunit_fsub_tests;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)Nonunit_fsub_tests;
}

original_code:
int nonunit_fsub_tests(void)
{
  return Nonunit_fsub_tests;
}

canonical_original_code:
int nonunit_fsub_tests()
{
  return Nonunit_fsub_tests;
}


decompiled_code:
__int64 nonunit_bsub_tests()
{
return (unsigned int)Nonunit_bsub_tests;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)Nonunit_bsub_tests;
}

original_code:
int nonunit_bsub_tests(void)
{
  return Nonunit_bsub_tests;
}

canonical_original_code:
int nonunit_bsub_tests()
{
  return Nonunit_bsub_tests;
}


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

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

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

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

original_code:
Di_tree get_di_tree(void)
{
  Di_tree p = get_cmem(((sizeof(struct di_tree))%(sizeof(void *)) == 0 ? (sizeof(struct di_tree))/(sizeof(void *)) : (sizeof(struct di_tree))/(sizeof(void *)) + 1));
  Di_tree_gets++;
  return(p);
}

canonical_original_code:
struct di_tree *get_di_tree()
{
  struct di_tree *p = get_cmem(((sizeof(struct di_tree))%(sizeof(void *)) == 0 ? (sizeof(struct di_tree))/(sizeof(void *)) : (sizeof(struct di_tree))/(sizeof(void *)) + 1));
  Di_tree_gets++;
  return(p);
}

variable_types: struct di_tree { int label; struct di_tree *next; union { struct di_tree *kids; struct plist { void *v; struct plist *next; } *data; } u; } *

user_defined_types: struct di_tree { int label; struct di_tree *next; union { struct di_tree *kids; struct plist *data; } u; }


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

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

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

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

original_code:
void free_di_tree(Di_tree p)
{
  free_mem(p, ((sizeof(struct di_tree))%(sizeof(void *)) == 0 ? (sizeof(struct di_tree))/(sizeof(void *)) : (sizeof(struct di_tree))/(sizeof(void *)) + 1));
  Di_tree_frees++;
}

canonical_original_code:
void free_di_tree(struct di_tree *p)
{
  free_mem(p, ((sizeof(struct di_tree))%(sizeof(void *)) == 0 ? (sizeof(struct di_tree))/(sizeof(void *)) : (sizeof(struct di_tree))/(sizeof(void *)) + 1));
  Di_tree_frees++;
}

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


decompiled_code:
int p_di_tree_mem()
{
return fprint_di_tree_mem(stdout, 1);
}

canonical_decompiled_code:
int func9()
{
return func8(stdout, 1);
}

original_code:
void p_di_tree_mem(void)
{
  fprint_di_tree_mem(stdout, TRUE);
}

canonical_original_code:
void p_di_tree_mem()
{
  fprint_di_tree_mem(stdout, TRUE);
}


decompiled_code:
// attributes: thunk
__int64 init_di_tree()
{
return get_di_tree();
}

canonical_decompiled_code:
__int64 func10()
{
return func6();
}

original_code:
Di_tree init_di_tree(void)
{
  return get_di_tree();
}

canonical_original_code:
struct di_tree *init_di_tree()
{
  return get_di_tree();
}

return_type: struct di_tree { int label; struct di_tree *next; union { struct di_tree *kids; struct plist { void *v; struct plist *next; } *data; } u; } *


decompiled_code:
_BOOL8 __fastcall di_tree_delete(int *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // edx
__int64 v6; // rbx
int v7; // er8
_BOOL8 result; // rax
__int64 v9; // rax
__int64 v10; // rax

v4 = *(_QWORD *)(a2 + 16);
if ( a1 )
{
if ( v4 )
{
v5 = *a1;
v6 = 0LL;
while ( v5 > *(_DWORD *)v4 )
{
v6 = v4;
if ( !*(_QWORD *)(v4 + 8) )
{
v4 = 0LL;
goto LABEL_8;
}
v4 = *(_QWORD *)(v4 + 8);
}
if ( v5 == *(_DWORD *)v4 )
goto LABEL_9;
}
else
{
v6 = 0LL;
}
LABEL_8:
fatal_error("di_tree_delete, node not found");
LABEL_9:
v7 = di_tree_delete(*((_QWORD *)a1 + 1), v4, a3);
result = 1LL;
if ( !v7 )
{
v9 = *(_QWORD *)(v4 + 8);
if ( v6 )
*(_QWORD *)(v6 + 8) = v9;
else
*(_QWORD *)(a2 + 16) = v9;
free_di_tree(v4);
result = *(_QWORD *)(a2 + 16) != 0LL;
}
}
else
{
v10 = plist_remove(v4, a3);
*(_QWORD *)(a2 + 16) = v10;
result = v10 != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(int *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // edx
__int64 v6; // rbx
int v7; // er8
_BOOL8 result; // rax
__int64 v9; // rax
__int64 v10; // rax

v4 = *(_QWORD *)(a2 + 16);
if ( a1 )
{
if ( v4 )
{
v5 = *a1;
v6 = 0LL;
while ( v5 > *(_DWORD *)v4 )
{
v6 = v4;
if ( !*(_QWORD *)(v4 + 8) )
{
v4 = 0LL;
goto LABEL_8;
}
v4 = *(_QWORD *)(v4 + 8);
}
if ( v5 == *(_DWORD *)v4 )
goto LABEL_9;
}
else
{
v6 = 0LL;
}
LABEL_8:
fatal_error("di_tree_delete, node not found");
LABEL_9:
v7 = func11(*((_QWORD *)a1 + 1), v4, a3);
result = 1LL;
if ( !v7 )
{
v9 = *(_QWORD *)(v4 + 8);
if ( v6 )
*(_QWORD *)(v6 + 8) = v9;
else
*(_QWORD *)(a2 + 16) = v9;
func7(v4);
result = *(_QWORD *)(a2 + 16) != 0LL;
}
}
else
{
v10 = plist_remove(v4, a3);
*(_QWORD *)(a2 + 16) = v10;
result = v10 != 0;
}
return result;
}

original_code:
BOOL di_tree_delete(Ilist vec, Di_tree node, void *datum)
{
  if (vec == ((void *)0)) {
    node->u.data = plist_remove(node->u.data, datum);
    return node->u.data != ((void *)0);
  }
  else {
    BOOL keep;
    Di_tree prev = ((void *)0);
    Di_tree curr = node->u.kids;
    while (curr && vec->i > curr->label) {
      prev = curr;
      curr = curr->next;
    }
    if (curr == ((void *)0) || vec->i != curr->label)
      fatal_error("di_tree_delete, node not found");
    keep = di_tree_delete(vec->next, curr, datum);
    if (keep)
      return TRUE;
    else {
      if (prev)
 prev->next = curr->next;
      else
 node->u.kids = curr->next;
      free_di_tree(curr);
      return node->u.kids != ((void *)0);
    }
  }
}

canonical_original_code:
enum BOOL di_tree_delete(struct ilist *vec, struct di_tree *node, void *datum)
{
  if (vec == ((void *)0)) {
    node->u.data = plist_remove(node->u.data, datum);
    return node->u.data != ((void *)0);
  }
  else {
    enum BOOL keep;
    struct di_tree *prev = ((void *)0);
    struct di_tree *curr = node->u.kids;
    while (curr && vec->i > curr->label) {
      prev = curr;
      curr = curr->next;
    }
    if (curr == ((void *)0) || vec->i != curr->label)
      fatal_error("di_tree_delete, node not found");
    keep = di_tree_delete(vec->next, curr, datum);
    if (keep)
      return TRUE;
    else {
      if (prev)
 prev->next = curr->next;
      else
 node->u.kids = curr->next;
      free_di_tree(curr);
      return node->u.kids != ((void *)0);
    }
  }
}

variable_types:
datum
void *

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

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


decompiled_code:
__int64 __fastcall zap_di_tree(__int64 a1, int a2)
{
__int64 v3; // rbp
__int64 v4; // rdi
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 16);
if ( a2 )
{
while ( v3 )
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 8);
zap_di_tree(v4, (unsigned int)(a2 - 1));
}
result = free_di_tree(a1);
}
else
{
zap_plist(*(_QWORD *)(a1 + 16));
result = free_di_tree(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
__int64 v3; // rbp
__int64 v4; // rdi
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 16);
if ( a2 )
{
while ( v3 )
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 8);
func12(v4, (unsigned int)(a2 - 1));
}
result = func7(a1);
}
else
{
zap_plist(*(_QWORD *)(a1 + 16));
result = func7(a1);
}
return result;
}

original_code:
void zap_di_tree(Di_tree node, int depth)
{
  if (depth == 0)
    zap_plist(node->u.data);
  else {
    Di_tree kid = node->u.kids;
    while (kid) {
      Di_tree tmp = kid;
      kid = kid->next;
      zap_di_tree(tmp, depth-1);
    }
  }
  free_di_tree(node);
}

canonical_original_code:
void zap_di_tree(struct di_tree *node, int depth)
{
  if (depth == 0)
    zap_plist(node->u.data);
  else {
    struct di_tree *kid = node->u.kids;
    while (kid) {
      struct di_tree *tmp = kid;
      kid = kid->next;
      zap_di_tree(tmp, depth-1);
    }
  }
  free_di_tree(node);
}

variable_types: depth int


decompiled_code:
__int64 mega_sub_calls()
{
return 4294 * Sub_calls_overflows + Sub_calls / 0xF4240u;
}

canonical_decompiled_code:
__int64 func16()
{
return 4294 * Sub_calls_overflows + Sub_calls / 0xF4240u;
}

original_code:
unsigned mega_sub_calls(void)
{
  return
    (Sub_calls / 1000000) +
    (((0x7fffffff * 2U + 1U) / 1000000) * Sub_calls_overflows);
}

canonical_original_code:
unsigned int mega_sub_calls()
{
  return
    (Sub_calls / 1000000) +
    (((0x7fffffff * 2U + 1U) / 1000000) * Sub_calls_overflows);
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall get_fpa_chunk(unsigned int a1)
{
__int64 v1; // r12
__int64 v2; // rax
__int64 result; // rax

v1 = get_cmem(5LL);
v2 = get_cmem(a1);
*(_DWORD *)v1 = a1;
*(_QWORD *)(v1 + 8) = v2;
result = v1;
Chunk_mem += a1;
++Fpa_chunk_gets;
return result;
}

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

v1 = get_cmem(5LL);
v2 = get_cmem(a1);
*(_DWORD *)v1 = a1;
*(_QWORD *)(v1 + 8) = v2;
result = v1;
Chunk_mem += a1;
++Fpa_chunk_gets;
return result;
}

original_code:
static
Fpa_chunk get_fpa_chunk(int n)
{
  Fpa_chunk p = get_cmem(((sizeof(struct fpa_chunk))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_chunk))/(sizeof(void *)) : (sizeof(struct fpa_chunk))/(sizeof(void *)) + 1));
  p->d = get_cmem(n);
  Chunk_mem += n;
  p->size = n;
  Fpa_chunk_gets++;
  return(p);
}

canonical_original_code:
static struct fpa_chunk *get_fpa_chunk(int n)
{
  struct fpa_chunk *p = get_cmem(((sizeof(struct fpa_chunk))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_chunk))/(sizeof(void *)) : (sizeof(struct fpa_chunk))/(sizeof(void *)) + 1));
  p->d = get_cmem(n);
  Chunk_mem += n;
  p->size = n;
  Fpa_chunk_gets++;
  return(p);
}

variable_types: n int

variable_types: struct fpa_chunk { int size; struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } **d; int n; struct fpa_list { struct fpa_chunk *chunks; int num_chunks; int chunksize; int num_terms; } *head; struct fpa_chunk *next; } *

user_defined_types: struct fpa_chunk { int size; struct term **d; int n; struct fpa_list *head; struct fpa_chunk *next; }


original_code:
static
Fpa_chunk flist_insert(Fpa_chunk f, Term x, Fpa_list head)
{
  if (f == ((void *)0)) {
    f = get_fpa_chunk(head->chunksize);
    head->num_chunks++;
    (f)->d[(f)->size - 1] = x;
    f->n = 1;
  }
  else if (f->n == f->size) {
    if (((((Term) x)->u.id) < (((Term) (f)->d[(f)->size - 1])->u.id)))
      f->next = flist_insert(f->next, x, head);
    else if (x == (f)->d[(f)->size - 1])
      fatal_error("flist_insert, item already here (1)");
    else if (((((Term) x)->u.id) > (((Term) (f)->d[(f)->size - (f)->n])->u.id))) {
      Fpa_chunk f2 = flist_insert(((void *)0), x, head);
      f2->next = f;
      f = f2;
    }
    else {
      Fpa_chunk f2 = get_fpa_chunk(f->size);
      int move = f2->size / 2;
      int i, j;
      head->num_chunks++;
      for (i = 0, j = f->size - move; i < move; i++, j++) {
 f2->d[j] = f->d[i];
 f->d[i] = ((void *)0);
      }
      f2->n = move;
      f->n = f->size - move;
      f2->next = f;
      f = flist_insert(f2, x, head);
    }
  }
  else {
    if (f->next && ((((Term) x)->u.id) <= (((Term) (f->next)->d[(f->next)->size - (f->next)->n])->u.id)))
      f->next = flist_insert(f->next, x, head);
    else {
      int n = f->n;
      int i = f->size - n;
      while (i < f->size && ((((Term) x)->u.id) < (((Term) f->d[i])->u.id)))
 i++;
      if (i < f->size && x == f->d[i])
 fatal_error("flist_insert, item already here (2)");
      if (i == f->size - n) {
 f->d[i-1] = x;
 f->n = n+1;
      }
      else {
 int j;
 for (j = f->size-n; j < i; j++)
   f->d[j-1] = f->d[j];
 f->d[i-1] = x;
 f->n = n+1;
      }
    }
  }
  return f;
}

canonical_original_code:
static struct fpa_chunk *flist_insert(struct fpa_chunk *f, struct term *x, struct fpa_list *head)
{
  if (f == ((void *)0)) {
    f = get_fpa_chunk(head->chunksize);
    head->num_chunks++;
    (f)->d[(f)->size - 1] = x;
    f->n = 1;
  }
  else if (f->n == f->size) {
    if (((((struct term *) x)->u.id) < (((Term) (f)->d[(f)->size - 1])->u.id)))
      f->next = flist_insert(f->next, x, head);
    else if (x == (f)->d[(f)->size - 1])
      fatal_error("flist_insert, item already here (1)");
    else if (((((struct term *) x)->u.id) > (((Term) (f)->d[(f)->size - (f)->n])->u.id))) {
      struct fpa_chunk *f2 = flist_insert(((void *)0), x, head);
      f2->next = f;
      f = f2;
    }
    else {
      struct fpa_chunk *f2 = get_fpa_chunk(f->size);
      int move = f2->size / 2;
      int i; int j;
      head->num_chunks++;
      for (i = 0, j = f->size - move; i < move; i++, j++) {
 f2->d[j] = f->d[i];
 f->d[i] = ((void *)0);
      }
      f2->n = move;
      f->n = f->size - move;
      f2->next = f;
      f = flist_insert(f2, x, head);
    }
  }
  else {
    if (f->next && ((((struct term *) x)->u.id) <= (((Term) (f->next)->d[(f->next)->size - (f->next)->n])->u.id)))
      f->next = flist_insert(f->next, x, head);
    else {
      int n = f->n;
      int i = f->size - n;
      while (i < f->size && ((((struct term *) x)->u.id) < (((struct term *) f->d[i])->u.id)))
 i++;
      if (i < f->size && x == f->d[i])
 fatal_error("flist_insert, item already here (2)");
      if (i == f->size - n) {
 f->d[i-1] = x;
 f->n = n+1;
      }
      else {
 int j;
 for (j = f->size-n; j < i; j++)
   f->d[j-1] = f->d[j];
 f->d[i-1] = x;
 f->n = n+1;
      }
    }
  }
  return f;
}

variable_types:
f
struct fpa_chunk *

variable_types:
x
struct term *

variable_types:
head
struct fpa_list *

variable_types: move int

variable_types: j int

return_type: struct fpa_chunk { int size; struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } **d; int n; struct fpa_list { struct fpa_chunk *chunks; int num_chunks; int chunksize; int num_terms; } *head; struct fpa_chunk *next; } *


decompiled_code:
__int64 __fastcall free_fpa_chunk(int *a1)
{
int v2; // esi
__int64 v3; // rdi
__int64 result; // rax

v2 = *a1;
v3 = *((_QWORD *)a1 + 1);
Chunk_mem -= v2;
free_mem(v3);
result = free_mem(a1);
++Fpa_chunk_frees;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1)
{
int v2; // esi
__int64 v3; // rdi
__int64 result; // rax

v2 = *a1;
v3 = *((_QWORD *)a1 + 1);
Chunk_mem -= v2;
free_mem(v3);
result = free_mem(a1);
++Fpa_chunk_frees;
return result;
}

original_code:
static
void free_fpa_chunk(Fpa_chunk p)
{
  Chunk_mem -= p->size;
  free_mem(p->d, p->size);
  free_mem(p, ((sizeof(struct fpa_chunk))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_chunk))/(sizeof(void *)) : (sizeof(struct fpa_chunk))/(sizeof(void *)) + 1));
  Fpa_chunk_frees++;
}

canonical_original_code:
static void free_fpa_chunk(struct fpa_chunk *p)
{
  Chunk_mem -= p->size;
  free_mem(p->d, p->size);
  free_mem(p, ((sizeof(struct fpa_chunk))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_chunk))/(sizeof(void *)) : (sizeof(struct fpa_chunk))/(sizeof(void *)) + 1));
  Fpa_chunk_frees++;
}

user_defined_types: struct fpa_list { struct fpa_chunk *chunks; int num_chunks; int chunksize; int num_terms; }


original_code:
static
Fpa_chunk double_chunksize(Fpa_chunk f)
{
  if (f == ((void *)0))
    return ((void *)0);
  else if (f->next == ((void *)0)) {
    fatal_error("double_chunksize, parity error");
    return ((void *)0);
  }
  else {
    int newsize = f->size * 2;
    Fpa_chunk g = f->next;
    Fpa_chunk new = get_fpa_chunk(newsize);
    int i = newsize - (f->n + g->n);
    int j;
    for (j = f->size - f->n; j < f->size; j++)
      new->d[i++] = f->d[j];
    for (j = g->size - g->n; j < g->size; j++)
      new->d[i++] = g->d[j];
    new->n = f->n + g->n;
    new->head = f->head;
    new->next = double_chunksize(g->next);
    free_fpa_chunk(f);
    free_fpa_chunk(g);
    return new;
  }
}

canonical_original_code:
static struct fpa_chunk *double_chunksize(struct fpa_chunk *f)
{
  if (f == ((void *)0))
    return ((void *)0);
  else if (f->next == ((void *)0)) {
    fatal_error("double_chunksize, parity error");
    return ((void *)0);
  }
  else {
    int newsize = f->size * 2;
    struct fpa_chunk *g = f->next;
    struct fpa_chunk *new = get_fpa_chunk(newsize);
    int i = newsize - (f->n + g->n);
    int j;
    for (j = f->size - f->n; j < f->size; j++)
      new->d[i++] = f->d[j];
    for (j = g->size - g->n; j < g->size; j++)
      new->d[i++] = g->d[j];
    new->n = f->n + g->n;
    new->head = f->head;
    new->next = double_chunksize(g->next);
    free_fpa_chunk(f);
    free_fpa_chunk(g);
    return new;
  }
}

variable_types: newsize int


consolidate

original_code:
static
Fpa_chunk consolidate(Fpa_chunk f, Fpa_list head)
{
  if (f->next && f->n + f->next->n <= f->size) {
    Fpa_chunk f2 = f->next;
    int i;
    for (i = 0; i < f->n; i++)
      f2->d[f->size - (f2->n + i + 1)] = f->d[f->size - (i+1)];
    f2->n = f->n + f2->n;
    free_fpa_chunk(f);
    head->num_chunks--;
    return f2;
  }
  else
    return f;
}

canonical_original_code:
static struct fpa_chunk *consolidate(struct fpa_chunk *f, struct fpa_list *head)
{
  if (f->next && f->n + f->next->n <= f->size) {
    struct fpa_chunk *f2 = f->next;
    int i;
    for (i = 0; i < f->n; i++)
      f2->d[f->size - (f2->n + i + 1)] = f->d[f->size - (i+1)];
    f2->n = f->n + f2->n;
    free_fpa_chunk(f);
    head->num_chunks--;
    return f2;
  }
  else
    return f;
}


original_code:
static
Fpa_chunk flist_delete(Fpa_chunk f, Term x, Fpa_list head)
{
  if (f == ((void *)0))
    fatal_error("flist_delete, item not found (1)");
  if (((((Term) x)->u.id) < (((Term) (f)->d[(f)->size - 1])->u.id)))
    f->next = flist_delete(f->next, x, head);
  else {
    int n = f->n;
    int i = f->size - n;
    int j;
    while (i < f->size && ((((Term) x)->u.id) < (((Term) f->d[i])->u.id)))
      i++;
    if (x != f->d[i])
      fatal_error("flist_delete, item not found (2)");
    for (j = i; j > f->size-n; j--)
      f->d[j] = f->d[j-1];
    f->d[j] = ((void *)0);
    f->n = n-1;
    if (f->n == 0) {
      Fpa_chunk next = f->next;
      head->num_chunks--;
      free_fpa_chunk(f);
      f = next;
    }
    else {
      f = consolidate(f, head);
    }
  }
  return f;
}

canonical_original_code:
static struct fpa_chunk *flist_delete(struct fpa_chunk *f, struct term *x, struct fpa_list *head)
{
  if (f == ((void *)0))
    fatal_error("flist_delete, item not found (1)");
  if (((((struct term *) x)->u.id) < (((Term) (f)->d[(f)->size - 1])->u.id)))
    f->next = flist_delete(f->next, x, head);
  else {
    int n = f->n;
    int i = f->size - n;
    int j;
    while (i < f->size && ((((struct term *) x)->u.id) < (((struct term *) f->d[i])->u.id)))
      i++;
    if (x != f->d[i])
      fatal_error("flist_delete, item not found (2)");
    for (j = i; j > f->size-n; j--)
      f->d[j] = f->d[j-1];
    f->d[j] = ((void *)0);
    f->n = n-1;
    if (f->n == 0) {
      struct fpa_chunk *next = f->next;
      head->num_chunks--;
      free_fpa_chunk(f);
      f = next;
    }
    else {
      f = consolidate(f, head);
    }
  }
  return f;
}


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

result = free_mem(a1);
++Fpa_list_frees;
return result;
}

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

result = free_mem(a1);
++Fpa_list_frees;
return result;
}

original_code:
static
void free_fpa_list(Fpa_list p)
{
  free_mem(p, ((sizeof(struct fpa_list))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_list))/(sizeof(void *)) : (sizeof(struct fpa_list))/(sizeof(void *)) + 1));
  Fpa_list_frees++;
}

canonical_original_code:
static void free_fpa_list(struct fpa_list *p)
{
  free_mem(p, ((sizeof(struct fpa_list))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_list))/(sizeof(void *)) : (sizeof(struct fpa_list))/(sizeof(void *)) + 1));
  Fpa_list_frees++;
}

variable_types: struct fpa_list { struct fpa_chunk { int size; struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } **d; int n; struct fpa_list *head; struct fpa_chunk *next; } *chunks; int num_chunks; int chunksize; int num_terms; } *


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

result = get_cmem(3LL);
++Fpa_list_gets;
*(_DWORD *)(result + 12) = 4;
return result;
}

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

result = get_cmem(3LL);
++Fpa_list_gets;
*(_DWORD *)(result + 12) = 4;
return result;
}

original_code:
Fpa_list get_fpa_list()
{
  Fpa_list p = get_cmem(((sizeof(struct fpa_list))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_list))/(sizeof(void *)) : (sizeof(struct fpa_list))/(sizeof(void *)) + 1));
  p->chunksize = 4;
  Fpa_list_gets++;
  return(p);
}

canonical_original_code:
struct fpa_list *get_fpa_list()
{
  struct fpa_list *p = get_cmem(((sizeof(struct fpa_list))%(sizeof(void *)) == 0 ? (sizeof(struct fpa_list))/(sizeof(void *)) : (sizeof(struct fpa_list))/(sizeof(void *)) + 1));
  p->chunksize = 4;
  Fpa_list_gets++;
  return(p);
}

return_type: struct fpa_list { struct fpa_chunk { int size; struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } **d; int n; struct fpa_list *head; struct fpa_chunk *next; } *chunks; int num_chunks; int chunksize; int num_terms; } *


decompiled_code:
int p_fpalist_mem()
{
return fprint_fpalist_mem(stdout, 1);
}

original_code:
void p_fpalist_mem()
{
  fprint_fpalist_mem(stdout, TRUE);
}


decompiled_code:
__int64 __fastcall fpalist_insert(__int64 a1, __int64 a2)
{
signed int *v3; // rax
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rax
int v7; // edx

v3 = flist_insert(*(signed int **)a1, a2, a1);
++*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = v3;
v4 = (__int64)v3;
result = *(unsigned int *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) == (_DWORD)result && (int)result <= 511 )
{
v6 = double_chunksize(v4);
v7 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 12) *= 2;
*(_QWORD *)a1 = v6;
result = (unsigned int)(v7 / 2);
*(_DWORD *)(a1 + 8) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
signed int *v3; // rax
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rax
int v7; // edx

v3 = func1(*(signed int **)a1, a2, a1);
++*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = v3;
v4 = (__int64)v3;
result = *(unsigned int *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) == (_DWORD)result && (int)result <= 511 )
{
v6 = func3(v4);
v7 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 12) *= 2;
*(_QWORD *)a1 = v6;
result = (unsigned int)(v7 / 2);
*(_DWORD *)(a1 + 8) = result;
}
return result;
}

original_code:
void fpalist_insert(Fpa_list p, Term t)
{
  p->chunks = flist_insert(p->chunks, t, p);
  p->num_terms++;
  if (p->num_chunks == p->chunksize && p->chunksize < 512) {
    p->chunks = double_chunksize(p->chunks);
    p->chunksize = p->chunksize * 2;
    p->num_chunks = p->num_chunks / 2;
  }
}

canonical_original_code:
void fpalist_insert(struct fpa_list *p, struct term *t)
{
  p->chunks = flist_insert(p->chunks, t, p);
  p->num_terms++;
  if (p->num_chunks == p->chunksize && p->chunksize < 512) {
    p->chunks = double_chunksize(p->chunks);
    p->chunksize = p->chunksize * 2;
    p->num_chunks = p->num_chunks / 2;
  }
}

variable_types:
t
struct term *


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

result = flist_delete(*(int **)a1, a2, a1);
--*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = result;
return result;
}

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

result = func5(*(int **)a1, a2, a1);
--*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void fpalist_delete(Fpa_list p, Term t)
{
  p->chunks = flist_delete(p->chunks, t, p);
  p->num_terms--;
}

canonical_original_code:
void fpalist_delete(struct fpa_list *p, struct term *t)
{
  p->chunks = flist_delete(p->chunks, t, p);
  p->num_terms--;
}


decompiled_code:
__int64 __fastcall next_fpos(__int64 a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( a2 == -1 )
break;
if ( a2 + 1 < *(_DWORD *)a1 )
return a1;
a1 = *(_QWORD *)(a1 + 32);
a2 = -1;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( a2 == -1 )
break;
if ( a2 + 1 < *(_DWORD *)a1 )
return a1;
a1 = *(_QWORD *)(a1 + 32);
a2 = -1;
}
return a1;
}

original_code:
struct fposition next_fpos(struct fposition p)
{
  if (p.f == ((void *)0))
    return (struct fposition) {((void *)0), 0};
  else if (p.i == -1)
    return (struct fposition) {p.f, p.f->size - p.f->n};
  else {
    int i = p.i+1;
    if (i < (p.f)->size)
      return (struct fposition) {p.f, i};
    else
      return next_fpos((struct fposition) {(p.f)->next, -1});
  }
}

variable_types:
p
struct fposition

return_type: struct fposition { struct fpa_chunk { int size; struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } **d; int n; struct fpa_list { struct fpa_chunk *chunks; int num_chunks; int chunksize; int num_terms; } *head; struct fpa_chunk *next; } *f; int i; }

user_defined_types: struct fposition { struct fpa_chunk *f; int i; }


decompiled_code:
__int64 __fastcall first_fpos(__int64 *a1)
{
return next_fpos(*a1, -1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 *a1)
{
return func12(*a1, -1);
}

original_code:
struct fposition first_fpos(Fpa_list f)
{
  return next_fpos((struct fposition) {f->chunks, -1});
}

canonical_original_code:
struct fposition first_fpos(struct fpa_list *f)
{
  return next_fpos((struct fposition) {f->chunks, -1});
}

variable_types:
f
struct fpa_list *


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

if ( a1 )
{
zap_fpa_chunks(*(_QWORD *)(a1 + 32));
result = free_fpa_chunk((int *)a1);
}
return result;
}

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

if ( a1 )
{
func14(*(_QWORD *)(a1 + 32));
result = func2((int *)a1);
}
return result;
}

original_code:
void zap_fpa_chunks(Fpa_chunk p)
{
  if (p != ((void *)0)) {
    zap_fpa_chunks(p->next);
    free_fpa_chunk(p);
  }
}

canonical_original_code:
void zap_fpa_chunks(struct fpa_chunk *p)
{
  if (p != ((void *)0)) {
    zap_fpa_chunks(p->next);
    free_fpa_chunk(p);
  }
}


decompiled_code:
__int64 __fastcall zap_fpalist(__int64 *a1)
{
zap_fpa_chunks(*a1);
return free_fpa_list((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 *a1)
{
func14(*a1);
return func6((__int64)a1);
}

original_code:
void zap_fpalist(Fpa_list p)
{
  zap_fpa_chunks(p->chunks);
  free_fpa_list(p);
}

canonical_original_code:
void zap_fpalist(struct fpa_list *p)
{
  zap_fpa_chunks(p->chunks);
  free_fpa_list(p);
}


decompiled_code:
_BOOL8 __fastcall fpalist_empty(_QWORD *a1)
{
_BOOL8 result; // rax

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

canonical_decompiled_code:
_BOOL8 __fastcall func16(_QWORD *a1)
{
_BOOL8 result; // rax

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

original_code:
BOOL fpalist_empty(Fpa_list p)
{
  return !p || p->chunks == ((void *)0);
}

canonical_original_code:
enum BOOL fpalist_empty(struct fpa_list *p)
{
  return !p || p->chunks == ((void *)0);
}


decompiled_code:
__int64 __fastcall p_fpa_list(unsigned int *a1)
{
unsigned int *v1; // r12
__int64 result; // rax
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // r13

if ( a1 )
{
v1 = a1;
do
{
result = *v1;
v3 = *v1 - v1[4];
if ( (int)result > v3 )
{
v4 = 8LL * v3;
do
{
++v3;
v5 = *(_QWORD *)(*((_QWORD *)v1 + 1) + v4);
v4 += 8LL;
printf(" : ");
result = fprint_term(stdout, v5);
}
while ( (int)*v1 > v3 );
}
v1 = (unsigned int *)*((_QWORD *)v1 + 4);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int *a1)
{
unsigned int *v1; // r12
__int64 result; // rax
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // r13

if ( a1 )
{
v1 = a1;
do
{
result = *v1;
v3 = *v1 - v1[4];
if ( (int)result > v3 )
{
v4 = 8LL * v3;
do
{
++v3;
v5 = *(_QWORD *)(*((_QWORD *)v1 + 1) + v4);
v4 += 8LL;
printf(" : ");
result = fprint_term(stdout, v5);
}
while ( (int)*v1 > v3 );
}
v1 = (unsigned int *)*((_QWORD *)v1 + 4);
}
while ( v1 );
}
return result;
}

original_code:
void p_fpa_list(Fpa_chunk c)
{
  for (; c; c = c->next) {
    int i;
    for (i = c->size-c->n; i < c->size; i++) {
      Term t = c->d[i];
      printf(" : ");
      fprint_term(stdout, t);
    }
  }
}

canonical_original_code:
void p_fpa_list(struct fpa_chunk *c)
{
  for (; c; c = c->next) {
    int i;
    for (i = c->size-c->n; i < c->size; i++) {
      struct term *t = c->d[i];
      printf(" : ");
      fprint_term(stdout, t);
    }
  }
}

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


decompiled_code:
__int64 get_nil_term()
{
return get_rigid_term("$nil", 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
return get_rigid_term("$nil", 0LL);
}

original_code:
Term get_nil_term()
{
  return get_rigid_term("$nil", 0);
}

canonical_original_code:
struct term *get_nil_term()
{
  return get_rigid_term("$nil", 0);
}


decompiled_code:
__int64 __fastcall listterm_cons(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rdx

result = get_rigid_term("$cons", 2LL);
v3 = *(_QWORD **)(result + 8);
*v3 = a1;
v3[1] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rdx

result = get_rigid_term("$cons", 2LL);
v3 = *(_QWORD **)(result + 8);
*v3 = a1;
v3[1] = a2;
return result;
}

original_code:
Term listterm_cons(Term t1, Term t2)
{
  Term c = get_rigid_term("$cons", 2);
  ((c)->args[0]) = t1;
  ((c)->args[1]) = t2;
  return c;
}

canonical_original_code:
struct term *listterm_cons(struct term *t1, struct term *t2)
{
  struct term *c = get_rigid_term("$cons", 2);
  ((c)->args[0]) = t1;
  ((c)->args[1]) = t2;
  return c;
}


decompiled_code:
__int64 __fastcall cons_term(_DWORD *a1)
{
return is_symbol((unsigned int)-*a1, "$cons", 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
return is_symbol((unsigned int)-*a1, "$cons", 2LL);
}

original_code:
BOOL cons_term(Term t)
{
  return is_symbol((-((t)->private_symbol)), "$cons", 2);
}

canonical_original_code:
enum BOOL cons_term(struct term *t)
{
  return is_symbol((-((t)->private_symbol)), "$cons", 2);
}


decompiled_code:
__int64 __fastcall rev2(__int64 a1, __int64 a2)
{
while ( (unsigned int)cons_term((_DWORD *)a1) )
{
a2 = listterm_cons(**(_QWORD **)(a1 + 8), a2);
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
while ( (unsigned int)func2((_DWORD *)a1) )
{
a2 = func1(**(_QWORD **)(a1 + 8), a2);
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}
return a2;
}

original_code:
static
Term rev2(Term t, Term done)
{
  if (!cons_term(t))
    return done;
  else
    return rev2(((t)->args[1]), listterm_cons(((t)->args[0]), done));
}

canonical_original_code:
static struct term *rev2(struct term *t, struct term *done)
{
  if (!cons_term(t))
    return done;
  else
    return rev2(((t)->args[1]), listterm_cons(((t)->args[0]), done));
}

variable_types:
done
struct term *


decompiled_code:
__int64 __fastcall nil_term(_DWORD *a1)
{
return is_symbol((unsigned int)-*a1, "$nil", 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1)
{
return is_symbol((unsigned int)-*a1, "$nil", 0LL);
}

original_code:
BOOL nil_term(Term t)
{
  return is_symbol((-((t)->private_symbol)), "$nil", 0);
}

canonical_original_code:
enum BOOL nil_term(struct term *t)
{
  return is_symbol((-((t)->private_symbol)), "$nil", 0);
}


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

while ( !(unsigned int)nil_term((_DWORD *)a1) )
{
result = cons_term((_DWORD *)a1);
if ( !(_DWORD)result )
return result;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}
return 1LL;
}

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

while ( !(unsigned int)func4((_DWORD *)a1) )
{
result = func2((_DWORD *)a1);
if ( !(_DWORD)result )
return result;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}
return 1LL;
}

original_code:
BOOL proper_listterm(Term t)
{
  if (nil_term(t))
    return TRUE;
  else if (cons_term(t))
    return proper_listterm(((t)->args[1]));
  else
    return FALSE;
}

canonical_original_code:
enum BOOL proper_listterm(struct term *t)
{
  if (nil_term(t))
    return TRUE;
  else if (cons_term(t))
    return proper_listterm(((t)->args[1]));
  else
    return FALSE;
}


decompiled_code:
__int64 __fastcall listterm_append(__int64 a1, __int64 a2)
{
__int64 v3; // rbx

if ( !(unsigned int)cons_term((_DWORD *)a1) )
return listterm_cons(a2, a1);
v3 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v3 + 8) = listterm_append(*(_QWORD *)(v3 + 8), a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v3; // rbx

if ( !(unsigned int)func2((_DWORD *)a1) )
return func1(a2, a1);
v3 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v3 + 8) = func6(*(_QWORD *)(v3 + 8), a2);
return a1;
}

original_code:
Term listterm_append(Term list, Term element)
{
  if (!cons_term(list))
    return listterm_cons(element, list);
  else {
    ((list)->args[1]) = listterm_append(((list)->args[1]), element);
    return list;
  }
}

canonical_original_code:
struct term *listterm_append(struct term *list, struct term *element)
{
  if (!cons_term(list))
    return listterm_cons(element, list);
  else {
    ((list)->args[1]) = listterm_append(((list)->args[1]), element);
    return list;
  }
}

variable_types:
list
struct term *

variable_types:
element
struct term *


decompiled_code:
__int64 __fastcall listterm_length(__int64 a1)
{
unsigned int v2; // ebx
unsigned int v3; // er12

v2 = 0;
while ( 1 )
{
v3 = v2++;
if ( !(unsigned int)cons_term((_DWORD *)a1) )
break;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v2; // ebx
unsigned int v3; // er12

v2 = 0;
while ( 1 )
{
v3 = v2++;
if ( !(unsigned int)func2((_DWORD *)a1) )
break;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}
return v3;
}

original_code:
int listterm_length(Term t)
{
  if (!cons_term(t))
    return 0;
  else {
    return 1 + listterm_length(((t)->args[1]));
  }
}

canonical_original_code:
int listterm_length(struct term *t)
{
  if (!cons_term(t))
    return 0;
  else {
    return 1 + listterm_length(((t)->args[1]));
  }
}


decompiled_code:
__int64 __fastcall listterm_i(__int64 a1, int a2)
{
_QWORD *v4; // rax

while ( 1 )
{
if ( !(unsigned int)cons_term((_DWORD *)a1) )
return 0LL;
v4 = *(_QWORD **)(a1 + 8);
if ( a2 == 1 )
break;
a1 = v4[1];
--a2;
}
return *v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
_QWORD *v4; // rax

while ( 1 )
{
if ( !(unsigned int)func2((_DWORD *)a1) )
return 0LL;
v4 = *(_QWORD **)(a1 + 8);
if ( a2 == 1 )
break;
a1 = v4[1];
--a2;
}
return *v4;
}

original_code:
Term listterm_i(Term lst, int i)
{
  if (!cons_term(lst))
    return ((void *)0);
  else if (i == 1)
    return ((lst)->args[0]);
  else
    return listterm_i(((lst)->args[1]), i-1);
}

canonical_original_code:
struct term *listterm_i(struct term *lst, int i)
{
  if (!cons_term(lst))
    return ((void *)0);
  else if (i == 1)
    return ((lst)->args[0]);
  else
    return listterm_i(((lst)->args[1]), i-1);
}

variable_types:
lst
struct term *


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

while ( 1 )
{
result = cons_term((_DWORD *)a2);
if ( !(_DWORD)result )
break;
if ( (unsigned int)term_ident(a1, **(_QWORD **)(a2 + 8)) )
return 1LL;
a2 = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL);
}
return result;
}

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

while ( 1 )
{
result = func2((_DWORD *)a2);
if ( !(_DWORD)result )
break;
if ( (unsigned int)term_ident(a1, **(_QWORD **)(a2 + 8)) )
return 1LL;
a2 = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL);
}
return result;
}

original_code:
BOOL listterm_member(Term t, Term lst)
{
  if (cons_term(lst)) {
    if (term_ident(t, ((lst)->args[0])))
      return TRUE;
    else
      return listterm_member(t, ((lst)->args[1]));
  }
  else
    return FALSE;
}

canonical_original_code:
enum BOOL listterm_member(struct term *t, struct term *lst)
{
  if (cons_term(lst)) {
    if (term_ident(t, ((lst)->args[0])))
      return TRUE;
    else
      return listterm_member(t, ((lst)->args[1]));
  }
  else
    return FALSE;
}


decompiled_code:
__int64 __fastcall listterm_to_tlist(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx

v1 = 0LL;
v2 = a1;
if ( (unsigned int)proper_listterm(a1) )
{
while ( (unsigned int)cons_term((_DWORD *)v2) )
{
v1 = plist_append(v1, **(_QWORD **)(v2 + 8));
v2 = *(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx

v1 = 0LL;
v2 = a1;
if ( (unsigned int)func5(a1) )
{
while ( (unsigned int)func2((_DWORD *)v2) )
{
v1 = plist_append(v1, **(_QWORD **)(v2 + 8));
v2 = *(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL);
}
}
return v1;
}

original_code:
Plist listterm_to_tlist(Term t)
{
  if (!proper_listterm(t))
    return ((void *)0);
  else {
    Plist p = ((void *)0);
    while (cons_term(t)) {
      p = plist_append(p, ((t)->args[0]));
      t = ((t)->args[1]);
    }
    return p;
  }
}

canonical_original_code:
struct plist *listterm_to_tlist(struct term *t)
{
  if (!proper_listterm(t))
    return ((void *)0);
  else {
    struct plist *p = ((void *)0);
    while (cons_term(t)) {
      p = plist_append(p, ((t)->args[0]));
      t = ((t)->args[1]);
    }
    return p;
  }
}

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


decompiled_code:
__int64 __fastcall listterm_zap(__int64 a1)
{
if ( !(unsigned int)cons_term((_DWORD *)a1) )
return zap_term(a1);
listterm_zap(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
return free_term(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( !(unsigned int)func2((_DWORD *)a1) )
return zap_term(a1);
func11(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
return free_term(a1);
}

original_code:
void listterm_zap(Term t)
{
  if (!cons_term(t))
    zap_term(t);
  else {
    listterm_zap(((t)->args[1]));
    free_term(t);
  }
}

canonical_original_code:
void listterm_zap(struct term *t)
{
  if (!cons_term(t))
    zap_term(t);
  else {
    listterm_zap(((t)->args[1]));
    free_term(t);
  }
}


decompiled_code:
__int64 __fastcall listterm_reverse(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = get_nil_term();
v2 = rev2(a1, v1);
listterm_zap(a1);
return v2;
}

original_code:
Term listterm_reverse(Term t)
{
  Term reversed = rev2(t, get_nil_term());
  listterm_zap(t);
  return reversed;
}

canonical_original_code:
struct term *listterm_reverse(struct term *t)
{
  struct term *reversed = rev2(t, get_nil_term());
  listterm_zap(t);
  return reversed;
}


decompiled_code:
_QWORD *get_symbol_data()
{
_QWORD *result; // rax

result = (_QWORD *)tp_alloc(32LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

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

result = (_QWORD *)tp_alloc(32LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

original_code:
Symbol_data get_symbol_data(void)
{
  Symbol_data p = tp_alloc(sizeof(struct symbol_data));
  p->sn = 0;
  p->mace_sn = 0;
  p->arity = 0;
  p->type = 0;
  p->base = 0;
  p->attribute = ORDINARY_SYMBOL;
  p->next = ((void *)0);
  return(p);
}

canonical_original_code:
struct symbol_data *get_symbol_data()
{
  struct symbol_data *p = tp_alloc(sizeof(struct symbol_data));
  p->sn = 0;
  p->mace_sn = 0;
  p->arity = 0;
  p->type = 0;
  p->base = 0;
  p->attribute = ORDINARY_SYMBOL;
  p->next = ((void *)0);
  return(p);
}

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


decompiled_code:
unsigned int *__fastcall insert_mace4_sym(unsigned int *a1, unsigned int a2, unsigned int a3)
{
int v4; // er12
_QWORD *v5; // rax
_QWORD *v6; // r12
int v7; // eax
unsigned int *result; // rax

if ( a1 && (v4 = sn_to_lex_val(a2), v4 >= (int)sn_to_lex_val(*a1)) )
{
*((_QWORD *)a1 + 3) = insert_mace4_sym(*((_QWORD *)a1 + 3), a2, a3);
result = a1;
}
else
{
v5 = get_symbol_data();
*(_DWORD *)v5 = a2;
v6 = v5;
v7 = sn_to_arity(a2);
*((_DWORD *)v6 + 3) = a3;
*((_DWORD *)v6 + 2) = v7;
if ( (unsigned int)is_skolem(a2) )
*((_DWORD *)v6 + 5) = 2;
v6[3] = a1;
result = (unsigned int *)v6;
}
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func1(unsigned int *a1, unsigned int a2, unsigned int a3)
{
int v4; // er12
_QWORD *v5; // rax
_QWORD *v6; // r12
int v7; // eax
unsigned int *result; // rax

if ( a1 && (v4 = sn_to_lex_val(a2), v4 >= (int)sn_to_lex_val(*a1)) )
{
*((_QWORD *)a1 + 3) = func1(*((_QWORD *)a1 + 3), a2, a3);
result = a1;
}
else
{
v5 = func0();
*(_DWORD *)v5 = a2;
v6 = v5;
v7 = sn_to_arity(a2);
*((_DWORD *)v6 + 3) = a3;
*((_DWORD *)v6 + 2) = v7;
if ( (unsigned int)is_skolem(a2) )
*((_DWORD *)v6 + 5) = 2;
v6[3] = a1;
result = (unsigned int *)v6;
}
return result;
}

original_code:
static
Symbol_data insert_mace4_sym(Symbol_data syms, int sn, int type)
{
  if (syms == ((void *)0) || sn_to_lex_val(sn) < sn_to_lex_val(syms->sn)) {
    Symbol_data new = get_symbol_data();
    new->sn = sn;
    new->arity = sn_to_arity(sn);
    new->type = type;
    if (is_skolem(sn))
      new->attribute = SKOLEM_SYMBOL;
    new->next = syms;
    return new;
  }
  else {
    syms->next = insert_mace4_sym(syms->next, sn, type);
    return syms;
  }
}

canonical_original_code:
static struct symbol_data *insert_mace4_sym(struct symbol_data *syms, int sn, int type)
{
  if (syms == ((void *)0) || sn_to_lex_val(sn) < sn_to_lex_val(syms->sn)) {
    struct symbol_data *new = get_symbol_data();
    new->sn = sn;
    new->arity = sn_to_arity(sn);
    new->type = type;
    if (is_skolem(sn))
      new->attribute = SKOLEM_SYMBOL;
    new->next = syms;
    return new;
  }
  else {
    syms->next = insert_mace4_sym(syms->next, sn, type);
    return syms;
  }
}

variable_types:
syms
struct symbol_data *

variable_types: sn int

variable_types: type int

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


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

for ( result = Symbols; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = Symbols; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
Symbol_data find_symbol_data(int sn)
{
  Symbol_data p = Symbols;
  while (p != ((void *)0) && p->sn != sn)
    p = p->next;
  return p;
}

canonical_original_code:
struct symbol_data *find_symbol_data(int sn)
{
  struct symbol_data *p = Symbols;
  while (p != ((void *)0) && p->sn != sn)
    p = p->next;
  return p;
}

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


decompiled_code:
__int64 init_built_in_symbols()
{
_QWORD *v0; // rbx
__int64 v1; // rax
int v2; // eax
__int64 result; // rax

v0 = get_symbol_data();
v1 = eq_sym();
v2 = str_to_sn(v1, 2LL);
*((_DWORD *)v0 + 5) = 1;
*(_DWORD *)v0 = v2;
v0[1] = 0x100000002LL;
result = Symbols;
Symbols = v0;
v0[3] = result;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // rbx
__int64 v1; // rax
int v2; // eax
__int64 result; // rax

v0 = func0();
v1 = eq_sym();
v2 = str_to_sn(v1, 2LL);
*((_DWORD *)v0 + 5) = 1;
*(_DWORD *)v0 = v2;
v0[1] = 0x100000002LL;
result = Symbols;
Symbols = v0;
v0[3] = result;
return result;
}

original_code:
void init_built_in_symbols(void)
{
  Symbol_data s;
  s = get_symbol_data();
  s->sn = str_to_sn(eq_sym(), 2);
  s->arity = 2;
  s->type = RELATION;
  s->attribute = EQUALITY_SYMBOL;
  s->next = Symbols;
  Symbols = s;
}

canonical_original_code:
void init_built_in_symbols()
{
  struct symbol_data *s;
  s = get_symbol_data();
  s->sn = str_to_sn(eq_sym(), 2);
  s->arity = 2;
  s->type = RELATION;
  s->attribute = EQUALITY_SYMBOL;
  s->next = Symbols;
  Symbols = s;
}