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


repo: jessealama/ladr

decompiled_code:
__int64 __fastcall get_i3list_from_ibuf(__int64 a1)
{
int v1; // eax
int v2; // er15
__int64 v3; // rbx
int i; // er14
unsigned int v5; // ebp
unsigned int v6; // er12
unsigned int v7; // eax

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
int v2; // er15
__int64 v3; // rbx
int i; // er14
unsigned int v5; // ebp
unsigned int v6; // er12
unsigned int v7; // eax

v1 = ((__int64 (*)(void))ibuf_xread)();
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0LL;
for ( i = 0; i != v2; ++i )
{
v5 = ibuf_xread(a1);
v6 = ibuf_xread(a1);
v7 = ibuf_xread(a1);
v3 = i3list_append(v3, v5, v6, v7);
}
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;
}

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

variable_types: i int

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

variable_types: n int


decompiled_code:
__int64 __fastcall get_ilist_from_ibuf(__int64 a1)
{
int v1; // eax
int v2; // er12
__int64 v3; // rbx
int i; // ebp
unsigned int v5; // eax

v1 = ibuf_xread(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0LL;
for ( i = 0; i != v2; ++i )
{
v5 = ibuf_xread(a1);
v3 = ilist_append(v3, v5);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // eax
int v2; // er12
__int64 v3; // rbx
int i; // ebp
unsigned int v5; // eax

v1 = ibuf_xread(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = 0LL;
for ( i = 0; i != v2; ++i )
{
v5 = ibuf_xread(a1);
v3 = ilist_append(v3, v5);
}
return v3;
}

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

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

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


decompiled_code:
__int64 __fastcall get_just_from_ibuf(__int64 a1)
{
int v1; // eax
int v2; // er15
int v3; // er13
__int64 v4; // r12
unsigned int v5; // ebp
unsigned int *v6; // rbx
_DWORD *v7; // rbp
__int64 v8; // rbp
__int64 v9; // rbp
__int64 v10; // rbp

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;
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:
v7 = (_DWORD *)get_parajust();
*((_QWORD *)v6 + 2) = v7;
*v7 = ibuf_xread(a1);
v8 = *((_QWORD *)v6 + 2);
*(_QWORD *)(v8 + 8) = get_ilist_from_ibuf(a1);
v9 = *((_QWORD *)v6 + 2);
*(_DWORD *)(v9 + 4) = ibuf_xread(a1);
v10 = *((_QWORD *)v6 + 2);
*(_QWORD *)(v10 + 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;
}
v4 = append_just(v4, v6);
++v3;
}
while ( v2 != v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // eax
int v2; // er15
int v3; // er13
__int64 v4; // r12
unsigned int v5; // ebp
unsigned int *v6; // rbx
_DWORD *v7; // rbp
__int64 v8; // rbp
__int64 v9; // rbp
__int64 v10; // rbp

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;
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:
v7 = (_DWORD *)get_parajust();
*((_QWORD *)v6 + 2) = v7;
*v7 = ibuf_xread(a1);
v8 = *((_QWORD *)v6 + 2);
*(_QWORD *)(v8 + 8) = func5(a1);
v9 = *((_QWORD *)v6 + 2);
*(_DWORD *)(v9 + 4) = ibuf_xread(a1);
v10 = *((_QWORD *)v6 + 2);
*(_QWORD *)(v10 + 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;
}
v4 = append_just(v4, v6);
++v3;
}
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; // ebx
unsigned int v3; // ebp
__int64 v4; // rbp
__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);
++v5;
}
while ( *(unsigned __int8 *)(v4 + 4) > (int)v5 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // ebp
__int64 v4; // rbp
__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);
++v5;
}
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: arity int


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

canonical_decompiled_code:
__int64 func3()
{
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;
}

return_type: int


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

canonical_decompiled_code:
__int64 func4()
{
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 func5()
{
__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 func6(__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++;
}

return_type: void

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 func8()
{
return func7(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:
__int64 init_di_tree()
{
return get_di_tree();
}

canonical_decompiled_code:
__int64 func9()
{
return func5();
}

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:
__int64 __fastcall di_tree_delete(int *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // edx
__int64 v6; // rbp
__int64 v7; // rax
__int64 result; // rax
int v9; // edx

if ( !a1 )
{
v7 = plist_remove(*(_QWORD *)(a2 + 16), a3);
*(_QWORD *)(a2 + 16) = v7;
return v7 != 0;
}
v4 = *(_QWORD *)(a2 + 16);
if ( v4 )
{
v5 = *a1;
v6 = 0LL;
while ( v5 > *(_DWORD *)v4 )
{
v6 = v4;
if ( !*(_QWORD *)(v4 + 8) )
goto LABEL_16;
v4 = *(_QWORD *)(v4 + 8);
}
if ( v5 == *(_DWORD *)v4 )
goto LABEL_11;
}
else
{
LABEL_16:
v6 = v4;
v4 = 0LL;
}
fatal_error("di_tree_delete, node not found");
LABEL_11:
v9 = di_tree_delete(*((_QWORD *)a1 + 1), v4, a3);
result = 1LL;
if ( !v9 )
{
if ( v6 )
*(_QWORD *)(v6 + 8) = *(_QWORD *)(v4 + 8);
else
*(_QWORD *)(a2 + 16) = *(_QWORD *)(v4 + 8);
free_di_tree(v4);
result = *(_QWORD *)(a2 + 16) != 0LL;
}
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 }

return_type: 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; // rbx
__int64 v4; // rdi

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

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 func14()
{
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; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 v1; // rbx

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

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: 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(__int64 a1)
{
__int64 result; // rax

Chunk_mem -= *(_DWORD *)a1;
free_mem(*(_QWORD *)(a1 + 8));
result = free_mem(a1);
++Fpa_chunk_frees;
return result;
}

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

Chunk_mem -= *(_DWORD *)a1;
free_mem(*(_QWORD *)(a1 + 8));
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; }

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


original_code:
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

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

variable_types: n int


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);
*(_DWORD *)(result + 12) = 4;
++Fpa_list_gets;
return result;
}

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

result = get_cmem(3LL);
*(_DWORD *)(result + 12) = 4;
++Fpa_list_gets;
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);
}

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

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


decompiled_code:
__int64 __fastcall fpalist_insert(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx

result = (__int64)flist_insert(*(signed int **)a1, a2, a1);
*(_QWORD *)a1 = result;
++*(_DWORD *)(a1 + 16);
v3 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) == v3 && v3 <= 511 )
{
*(_QWORD *)a1 = double_chunksize(result, a2);
*(_DWORD *)(a1 + 12) *= 2;
result = (unsigned int)(*(_DWORD *)(a1 + 8) / 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:
__int64 __fastcall fpalist_delete(__int64 a1, __int64 a2)
{
__int64 result; // rax

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

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

result = func5(*(int **)a1, a2, a1);
*(_QWORD *)a1 = result;
--*(_DWORD *)(a1 + 16);
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)
{
if ( !a1 )
return 0LL;
if ( a2 == -1 )
return a1;
if ( *(_DWORD *)a1 <= a2 + 1 )
return next_fpos(*(_QWORD *)(a1 + 32), 0xFFFFFFFFLL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
if ( a2 == -1 )
return a1;
if ( *(_DWORD *)a1 <= a2 + 1 )
return func12(*(_QWORD *)(a1 + 32), 0xFFFFFFFFLL);
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(a1);
}
return result;
}

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

if ( a1 )
{
func14(*(_QWORD *)(a1 + 32));
result = func2(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 *i; // r12
__int64 result; // rax
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // r13

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

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

for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 4) )
{
result = *i;
v3 = *i - i[4];
if ( (int)result > v3 )
{
v4 = 8LL * v3;
do
{
v5 = *(_QWORD *)(*((_QWORD *)i + 1) + v4);
printf(" : ");
result = fprint_term(stdout, v5);
++v3;
v4 += 8LL;
}
while ( (int)*i > v3 );
}
}
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: 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);
}

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


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

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

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

result = get_rigid_term("$cons", 2LL);
**(_QWORD **)(result + 8) = a1;
*(_QWORD *)(*(_QWORD *)(result + 8) + 8LL) = 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)
{
__int64 v2; // rbx
__int64 v4; // rax

v2 = a2;
if ( (unsigned int)cons_term((_DWORD *)a1) )
{
v4 = listterm_cons(**(_QWORD **)(a1 + 8), a2);
v2 = rev2(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), v4);
}
return v2;
}

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)
{
int v1; // edx
__int64 result; // rax

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

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

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

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; // r12

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; // r12

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)
{
int v1; // edx
__int64 result; // rax

v1 = cons_term((_DWORD *)a1);
result = 0LL;
if ( v1 )
result = (unsigned int)listterm_length(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) + 1;
return result;
}

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

v1 = func2((_DWORD *)a1);
result = 0LL;
if ( v1 )
result = (unsigned int)func7(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) + 1;
return result;
}

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)
{
if ( !(unsigned int)cons_term((_DWORD *)a1) )
return 0LL;
if ( a2 == 1 )
return **(_QWORD **)(a1 + 8);
return listterm_i(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), (unsigned int)(a2 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
if ( !(unsigned int)func2((_DWORD *)a1) )
return 0LL;
if ( a2 == 1 )
return **(_QWORD **)(a1 + 8);
return func8(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL), (unsigned int)(a2 - 1));
}

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
int v3; // edx

result = cons_term((_DWORD *)a2);
if ( (_DWORD)result )
{
v3 = term_ident(a1, **(_QWORD **)(a2 + 8));
result = 1LL;
if ( !v3 )
result = listterm_member(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL));
}
return result;
}

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

result = func2((_DWORD *)a2);
if ( (_DWORD)result )
{
v3 = term_ident(a1, **(_QWORD **)(a2 + 8));
result = 1LL;
if ( !v3 )
result = func9(a1, *(_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; // rbx
__int64 v2; // rbp

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

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

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

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; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = func0();
v2 = func3(a1, v1);
func11(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:
__int64 get_symbol_data()
{
__int64 result; // rax

result = tp_alloc(32LL);
*(_DWORD *)result = 0;
*(_DWORD *)(result + 4) = 0;
*(_DWORD *)(result + 8) = 0;
*(_DWORD *)(result + 12) = 0;
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 20) = 0;
*(_QWORD *)(result + 24) = 0LL;
return result;
}

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

result = tp_alloc(32LL);
*(_DWORD *)result = 0;
*(_DWORD *)(result + 4) = 0;
*(_DWORD *)(result + 8) = 0;
*(_DWORD *)(result + 12) = 0;
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 20) = 0;
*(_QWORD *)(result + 24) = 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:
__int64 __fastcall insert_mace4_sym(unsigned int *a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
__int64 v5; // rbx

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);
v5 = (__int64)a1;
}
else
{
v5 = get_symbol_data();
*(_DWORD *)v5 = a2;
*(_DWORD *)(v5 + 8) = sn_to_arity(a2);
*(_DWORD *)(v5 + 12) = a3;
if ( (unsigned int)is_skolem(a2) )
*(_DWORD *)(v5 + 20) = 2;
*(_QWORD *)(v5 + 24) = a1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
__int64 v5; // rbx

if ( a1 && (v4 = sn_to_lex_val(a2), v4 >= (int)sn_to_lex_val(*a1)) )
{
*((_QWORD *)a1 + 3) = func1(*((_QWORD *)a1 + 3), a2, a3);
v5 = (__int64)a1;
}
else
{
v5 = func0();
*(_DWORD *)v5 = a2;
*(_DWORD *)(v5 + 8) = sn_to_arity(a2);
*(_DWORD *)(v5 + 12) = a3;
if ( (unsigned int)is_skolem(a2) )
*(_DWORD *)(v5 + 20) = 2;
*(_QWORD *)(v5 + 24) = a1;
}
return v5;
}

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()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 result; // rax

v0 = get_symbol_data();
v1 = eq_sym();
*(_DWORD *)v0 = str_to_sn(v1, 2LL);
*(_DWORD *)(v0 + 8) = 2;
*(_DWORD *)(v0 + 12) = 1;
*(_DWORD *)(v0 + 20) = 1;
result = Symbols;
*(_QWORD *)(v0 + 24) = Symbols;
Symbols = v0;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 result; // rax

v0 = func0();
v1 = eq_sym();
*(_DWORD *)v0 = str_to_sn(v1, 2LL);
*(_DWORD *)(v0 + 8) = 2;
*(_DWORD *)(v0 + 12) = 1;
*(_DWORD *)(v0 + 20) = 1;
result = Symbols;
*(_QWORD *)(v0 + 24) = Symbols;
Symbols = v0;
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;
}


decompiled_code:
__int64 __fastcall collect_mace4_syms(__int64 a1, int a2)
{
__int64 v2; // r15
__int64 v3; // r14
unsigned int *v4; // rbx
int v5; // er12
unsigned int v6; // ebp
__int64 v7; // rax
int v8; // eax
unsigned int *v9; // rbx
unsigned int v10; // ebp
__int64 v11; // rax
const char *v12; // rax

v2 = fsym_set_in_topforms();
v3 = rsym_set_in_topforms(a1);
lex_order(v2, v3, 0LL, 0LL, &lex_compare_arity_0123);
if ( v2 )
{
v4 = (unsigned int *)v2;
v5 = -1;
do
{
v6 = *v4;
v7 = sn_to_str(*v4);
v8 = natural_string(v7);
if ( v8 < 0 )
{
if ( !a2 || !(unsigned int)arith_op_sn(v6) )
Symbols = insert_mace4_sym(Symbols, v6, 0);
}
else if ( v5 < v8 )
{
v5 = v8;
}
v4 = (unsigned int *)*((_QWORD *)v4 + 1);
}
while ( v4 );
}
else
{
v5 = -1;
}
if ( v3 )
{
v9 = (unsigned int *)v3;
do
{
v10 = *v9;
v11 = sn_to_str(*v9);
if ( (int)natural_string(v11) < 0 )
{
if ( !(unsigned int)is_eq_symbol(v10) && (!a2 || !(unsigned int)arith_rel_sn(v10)) )
Symbols = insert_mace4_sym(Symbols, v10, 1u);
}
else
{
v12 = (const char *)sn_to_str(v10);
printf("\nThe bad symbol is: %s\n", v12);
fatal_error("collect_mace4_syms, relation symbol is domain element");
}
v9 = (unsigned int *)*((_QWORD *)v9 + 1);
}
while ( v9 );
}
zap_ilist(v2);
zap_ilist(v3);
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 v2; // r15
__int64 v3; // r14
unsigned int *v4; // rbx
int v5; // er12
unsigned int v6; // ebp
__int64 v7; // rax
int v8; // eax
unsigned int *v9; // rbx
unsigned int v10; // ebp
__int64 v11; // rax
const char *v12; // rax

v2 = fsym_set_in_topforms();
v3 = rsym_set_in_topforms(a1);
lex_order(v2, v3, 0LL, 0LL, &lex_compare_arity_0123);
if ( v2 )
{
v4 = (unsigned int *)v2;
v5 = -1;
do
{
v6 = *v4;
v7 = sn_to_str(*v4);
v8 = natural_string(v7);
if ( v8 < 0 )
{
if ( !a2 || !(unsigned int)arith_op_sn(v6) )
Symbols = func1(Symbols, v6, 0);
}
else if ( v5 < v8 )
{
v5 = v8;
}
v4 = (unsigned int *)*((_QWORD *)v4 + 1);
}
while ( v4 );
}
else
{
v5 = -1;
}
if ( v3 )
{
v9 = (unsigned int *)v3;
do
{
v10 = *v9;
v11 = sn_to_str(*v9);
if ( (int)natural_string(v11) < 0 )
{
if ( !(unsigned int)is_eq_symbol(v10) && (!a2 || !(unsigned int)arith_rel_sn(v10)) )
Symbols = func1(Symbols, v10, 1u);
}
else
{
v12 = (const char *)sn_to_str(v10);
printf("\nThe bad symbol is: %s\n", v12);
fatal_error("collect_mace4_syms, relation symbol is domain element");
}
v9 = (unsigned int *)*((_QWORD *)v9 + 1);
}
while ( v9 );
}
zap_ilist(v2);
zap_ilist(v3);
return (unsigned int)v5;
}

original_code:
int collect_mace4_syms(Plist clauses, BOOL arithmetic)
{
  Ilist fsyms, rsyms, p;
  int max_domain = -1;
  fsyms = fsym_set_in_topforms(clauses);
  rsyms = rsym_set_in_topforms(clauses);
  lex_order(fsyms, rsyms, ((void *)0), ((void *)0), lex_compare_arity_0123);
  for (p = fsyms; p; p = p->next) {
    int sn = p->i;
    int dom = natural_string(sn_to_str(sn));
    if (dom >= 0)
      max_domain = ((dom) > (max_domain) ? dom : max_domain);
    else if (arithmetic && arith_op_sn(sn))
      ;
    else
      Symbols = insert_mace4_sym(Symbols, sn, FUNCTION);
  }
  for (p = rsyms; p; p = p->next) {
    int sn = p->i;
    int dom = natural_string(sn_to_str(sn));
    if (dom >= 0) {
      printf("\nThe bad symbol is: %s\n", sn_to_str(sn));
      fatal_error("collect_mace4_syms, relation symbol is domain element");
    }
    else if (is_eq_symbol(sn) || (arithmetic && arith_rel_sn(sn)))
      ;
    else
      Symbols = insert_mace4_sym(Symbols, sn, RELATION);
  }
  zap_ilist(fsyms);
  zap_ilist(rsyms);
  return max_domain;
}

canonical_original_code:
int collect_mace4_syms(struct plist *clauses, enum BOOL arithmetic)
{
  struct ilist *fsyms; struct ilist *rsyms; struct ilist *p;
  int max_domain = -1;
  fsyms = fsym_set_in_topforms(clauses);
  rsyms = rsym_set_in_topforms(clauses);
  lex_order(fsyms, rsyms, ((void *)0), ((void *)0), lex_compare_arity_0123);
  for (p = fsyms; p; p = p->next) {
    int sn = p->i;
    int dom = natural_string(sn_to_str(sn));
    if (dom >= 0)
      max_domain = ((dom) > (max_domain) ? dom : max_domain);
    else if (arithmetic && arith_op_sn(sn))
      ;
    else
      Symbols = insert_mace4_sym(Symbols, sn, FUNCTION);
  }
  for (p = rsyms; p; p = p->next) {
    int sn = p->i;
    int dom = natural_string(sn_to_str(sn));
    if (dom >= 0) {
      printf("\nThe bad symbol is: %s\n", sn_to_str(sn));
      fatal_error("collect_mace4_syms, relation symbol is domain element");
    }
    else if (is_eq_symbol(sn) || (arithmetic && arith_rel_sn(sn)))
      ;
    else
      Symbols = insert_mace4_sym(Symbols, sn, RELATION);
  }
  zap_ilist(fsyms);
  zap_ilist(rsyms);
  return max_domain;
}

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

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

variable_types: dom int


decompiled_code:
void __fastcall p_symbol_data(unsigned int *a1)
{
__int64 v1; // r14
__int64 v2; // r13
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // er15
const char *v7; // rax

if ( a1 )
{
v1 = a1[5];
v2 = a1[3];
v3 = a1[4];
v4 = a1[1];
v5 = *a1;
v6 = a1[2];
v7 = (const char *)sn_to_str(*a1);
printf("%s/%d, sn=%d, mace_sn=%d, base=%d, type=%d, attribute=%d.\n", v7, v6, v5, v4, v3, v2, v1);
}
}

canonical_decompiled_code:
void __fastcall func5(unsigned int *a1)
{
__int64 v1; // r14
__int64 v2; // r13
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // er15
const char *v7; // rax

if ( a1 )
{
v1 = a1[5];
v2 = a1[3];
v3 = a1[4];
v4 = a1[1];
v5 = *a1;
v6 = a1[2];
v7 = (const char *)sn_to_str(*a1);
printf("%s/%d, sn=%d, mace_sn=%d, base=%d, type=%d, attribute=%d.\n", v7, v6, v5, v4, v3, v2, v1);
}
}

original_code:
void p_symbol_data(Symbol_data s)
{
  if (s != ((void *)0))
    printf("%s/%d, sn=%d, mace_sn=%d, base=%d, type=%d, attribute=%d.\n",
    sn_to_str(s->sn), s->arity,
    s->sn, s->mace_sn, s->base, s->type, s->attribute);
}

canonical_original_code:
void p_symbol_data(struct symbol_data *s)
{
  if (s != ((void *)0))
    printf("%s/%d, sn=%d, mace_sn=%d, base=%d, type=%d, attribute=%d.\n",
    sn_to_str(s->sn), s->arity,
    s->sn, s->mace_sn, s->base, s->type, s->attribute);
}


decompiled_code:
__int64 __fastcall find_symbol_node(int a1)
{
__int64 v1; // rax
__int64 v2; // rcx

v1 = Symbols;
v2 = 0LL;
if ( !Symbols )
return Symbols;
while ( *(_DWORD *)(v1 + 16) <= a1 )
{
v2 = v1;
if ( !*(_QWORD *)(v1 + 24) )
break;
v1 = *(_QWORD *)(v1 + 24);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // rax
__int64 v2; // rcx

v1 = Symbols;
v2 = 0LL;
if ( !Symbols )
return Symbols;
while ( *(_DWORD *)(v1 + 16) <= a1 )
{
v2 = v1;
if ( !*(_QWORD *)(v1 + 24) )
break;
v1 = *(_QWORD *)(v1 + 24);
}
return v2;
}

original_code:
Symbol_data find_symbol_node(int id)
{
  Symbol_data prev = ((void *)0);
  Symbol_data curr = Symbols;
  while (curr != ((void *)0) && curr->base <= id) {
    prev = curr;
    curr = curr->next;
  }
  return prev;
}

canonical_original_code:
struct symbol_data *find_symbol_node(int id)
{
  struct symbol_data *prev = ((void *)0);
  struct symbol_data *curr = Symbols;
  while (curr != ((void *)0) && curr->base <= id) {
    prev = curr;
    curr = curr->next;
  }
  return prev;
}

variable_types: id int


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

result = 2LL;
if ( *(_DWORD *)(*(_QWORD *)(Cells + 56LL * a1 + 48) + 12LL) != 1 )
result = Domain_size;
return result;
}

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

result = 2LL;
if ( *(_DWORD *)(*(_QWORD *)(Cells + 56LL * a1 + 48) + 12LL) != 1 )
result = Domain_size;
return result;
}

original_code:
int id_to_domain_size(int id)
{
  Symbol_data s = Cells[id].symbol;
  return (s->type == RELATION ? 2 : Domain_size);
}

canonical_original_code:
int id_to_domain_size(int id)
{
  struct symbol_data *s = Cells[id].symbol;
  return (s->type == RELATION ? 2 : Domain_size);
}


decompiled_code:
__int64 __fastcall max_index(int a1, __int64 a2)
{
unsigned int v2; // er13
int v3; // edi
int v4; // ebp
int v5; // ebx
int v6; // er12
int v7; // eax
int v8; // eax
int v9; // edx

v2 = Domain_size;
v3 = a1 - *(_DWORD *)(a2 + 16);
v4 = *(_DWORD *)(a2 + 8) - 1;
if ( v4 < 0 )
{
v6 = -1;
}
else
{
v5 = v3;
v6 = -1;
do
{
v7 = int_power(v2, (unsigned int)v4);
v9 = v5 % v7;
v8 = v5 / v7;
if ( v6 < v8 )
v6 = v8;
v5 = v9;
--v4;
}
while ( v4 != -1 );
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
unsigned int v2; // er13
int v3; // edi
int v4; // ebp
int v5; // ebx
int v6; // er12
int v7; // eax
int v8; // eax
int v9; // edx

v2 = Domain_size;
v3 = a1 - *(_DWORD *)(a2 + 16);
v4 = *(_DWORD *)(a2 + 8) - 1;
if ( v4 < 0 )
{
v6 = -1;
}
else
{
v5 = v3;
v6 = -1;
do
{
v7 = int_power(v2, (unsigned int)v4);
v9 = v5 % v7;
v8 = v5 / v7;
if ( v6 < v8 )
v6 = v8;
v5 = v9;
--v4;
}
while ( v4 != -1 );
}
return (unsigned int)v6;
}

original_code:
int max_index(int id, Symbol_data s)
{
  int max = -1;
  int n = Domain_size;
  int x = id - s->base;
  int i;
  for (i = s->arity - 1; i >= 0; i--) {
    int p = int_power(n, i);
    int e = x / p;
    max = ((e) > (max) ? e : max);
    x = x % p;
  }
  return max;
}

canonical_original_code:
int max_index(int id, struct symbol_data *s)
{
  int max = -1;
  int n = Domain_size;
  int x = id - s->base;
  int i;
  for (i = s->arity - 1; i >= 0; i--) {
    int p = int_power(n, i);
    int e = x / p;
    max = ((e) > (max) ? e : max);
    x = x % p;
  }
  return max;
}

variable_types: max int

variable_types: n int

variable_types: x int

variable_types: i int

variable_types: p int

variable_types: e int


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = (_QWORD *)*a1;
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = (_QWORD *)*a1;
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

original_code:
static
int mlist_length(void **p)
{
  int n;
  for (n = 0; p; p = *p, n++);
  return n;
}

variable_types:
p
void **


palloc

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

result = 0LL;
if ( a1 )
{
if ( !Block || Block + 20971520 - Block_pos < a1 )
{
if ( a1 > 0x1400000 )
{
printf("palloc, n=%d\n", (unsigned int)a1);
fatal_error("palloc, request too big; reset MALLOC_MEGS");
}
else if ( Max_megs_check && 4 * (5 * Malloc_calls + 5) > Max_megs )
{
if ( Exit_proc )
Exit_proc();
else
fatal_error("palloc, Max_megs parameter exceeded");
}
else
{
Block = (__int64)malloc(0x1400000uLL);
Block_pos = Block;
++Malloc_calls;
if ( !Block )
fatal_error("palloc, operating system is out of memory");
}
}
result = Block_pos;
Block_pos += a1;
Bytes_palloced += a1;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
if ( !Block || Block + 20971520 - Block_pos < a1 )
{
if ( a1 > 0x1400000 )
{
printf("palloc, n=%d\n", (unsigned int)a1);
fatal_error("palloc, request too big; reset MALLOC_MEGS");
}
else if ( Max_megs_check && 4 * (5 * Malloc_calls + 5) > Max_megs )
{
if ( Exit_proc )
Exit_proc();
else
fatal_error("palloc, Max_megs parameter exceeded");
}
else
{
Block = (__int64)malloc(0x1400000uLL);
Block_pos = Block;
++Malloc_calls;
if ( !Block )
fatal_error("palloc, operating system is out of memory");
}
}
result = Block_pos;
Block_pos += a1;
Bytes_palloced += a1;
}
return result;
}

original_code:
static
void *palloc(size_t n)
{
  if (n == 0)
    return ((void *)0);
  else {
    void *chunk;
    size_t malloc_bytes = 20*1024*1024;
    if (Block==((void *)0) || Block + malloc_bytes - Block_pos < n) {
      if (n > malloc_bytes) {
 printf("palloc, n=%d\n", (int) n);
 fatal_error("palloc, request too big; reset MALLOC_MEGS");
      }
      else if (Max_megs_check && (Malloc_calls+1)*20 > Max_megs) {
 if (Exit_proc)
   (*Exit_proc)();
 else
   fatal_error("palloc, Max_megs parameter exceeded");
      }
      else {
 Block_pos = Block = malloc(malloc_bytes);
 Malloc_calls++;
 if (Block_pos == ((void *)0))
   fatal_error("palloc, operating system is out of memory");
      }
    }
    chunk = Block_pos;
    Block_pos += n;
    Bytes_palloced += n;
    return(chunk);
  }
}

canonical_original_code:
static void *palloc(unsigned long n)
{
  if (n == 0)
    return ((void *)0);
  else {
    void *chunk;
    unsigned long malloc_bytes = 20*1024*1024;
    if (Block==((void *)0) || Block + malloc_bytes - Block_pos < n) {
      if (n > malloc_bytes) {
 printf("palloc, n=%d\n", (int) n);
 fatal_error("palloc, request too big; reset MALLOC_MEGS");
      }
      else if (Max_megs_check && (Malloc_calls+1)*20 > Max_megs) {
 if (Exit_proc)
   (*Exit_proc)();
 else
   fatal_error("palloc, Max_megs parameter exceeded");
      }
      else {
 Block_pos = Block = malloc(malloc_bytes);
 Malloc_calls++;
 if (Block_pos == ((void *)0))
   fatal_error("palloc, operating system is out of memory");
      }
    }
    chunk = Block_pos;
    Block_pos += n;
    Bytes_palloced += n;
    return(chunk);
  }
}

variable_types:
n
unsigned long

variable_types:
chunk
void *

return_type: void *


decompiled_code:
void __fastcall free_mem(_QWORD *a1, unsigned int a2)
{
if ( a2 )
{
if ( a2 > 0x1F3 )
{
free(a1);
}
else
{
*a1 = M[a2];
M[a2] = (__int64)a1;
}
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, unsigned int a2)
{
if ( a2 )
{
if ( a2 > 0x1F3 )
{
free(a1);
}
else
{
*a1 = M[a2];
M[a2] = (__int64)a1;
}
}
}

original_code:
void free_mem(void *q, unsigned n)
{
  if (n == 0)
    ;
  else {
    void **p = q;
    if (n >= 500)
      free(p);
    else {
      *p = M[n];
      M[n] = p;
    }
  }
}

canonical_original_code:
void free_mem(void *q, unsigned int n)
{
  if (n == 0)
    ;
  else {
    void **p = q;
    if (n >= 500)
      free(p);
    else {
      *p = M[n];
      M[n] = p;
    }
  }
}

variable_types:
q
void *

variable_types:
n
unsigned int


decompiled_code:
__int64 megs_malloced()
{
return (unsigned int)(20 * Malloc_calls);
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)(20 * Malloc_calls);
}

original_code:
int megs_malloced(void)
{
  return Malloc_calls * 20;
}

canonical_original_code:
int megs_malloced()
{
  return Malloc_calls * 20;
}


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

result = 0x7FFFFFFFLL;
if ( a1 == -1 )
a1 = 0x7FFFFFFF;
Max_megs = a1;
return result;
}

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

result = 0x7FFFFFFFLL;
if ( a1 == -1 )
a1 = 0x7FFFFFFF;
Max_megs = a1;
return result;
}

original_code:
void set_max_megs(int megs)
{
  Max_megs = (megs == -1 ? 0x7fffffff : megs);
}

variable_types: megs int


decompiled_code:
__int64 bytes_palloced()
{
return (unsigned int)Bytes_palloced;
}

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

original_code:
int bytes_palloced(void)
{
  return Bytes_palloced;
}

canonical_original_code:
int bytes_palloced()
{
  return Bytes_palloced;
}


decompiled_code:
__int64 __fastcall tp_alloc(unsigned __int64 a1)
{
if ( (a1 & 7) != 0 )
a1 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
return palloc(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
if ( (a1 & 7) != 0 )
a1 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
return func1(a1);
}

original_code:
void *tp_alloc(size_t n)
{
  if (n % sizeof(void *) != 0) {
    n += (sizeof(void *) - (n % sizeof(void *)));
  }
  return palloc(n);
}

canonical_original_code:
void *tp_alloc(unsigned long n)
{
  if (n % sizeof(void *) != 0) {
    n += (sizeof(void *) - (n % sizeof(void *)));
  }
  return palloc(n);
}


decompiled_code:
__int64 mega_mem_calls()
{
return 4294 * Mem_calls_overflows + Mem_calls / 0xF4240u;
}

canonical_decompiled_code:
__int64 func9()
{
return 4294 * Mem_calls_overflows + Mem_calls / 0xF4240u;
}

original_code:
unsigned mega_mem_calls(void)
{
  return
    (Mem_calls / 1000000) +
    (((0x7fffffff * 2U + 1U) / 1000000) * Mem_calls_overflows);
}

canonical_original_code:
unsigned int mega_mem_calls()
{
  return
    (Mem_calls / 1000000) +
    (((0x7fffffff * 2U + 1U) / 1000000) * Mem_calls_overflows);
}


decompiled_code:
void disable_max_megs()
{
Max_megs_check = 0;
}

canonical_decompiled_code:
void func10()
{
Max_megs_check = 0;
}

original_code:
void disable_max_megs(void)
{
  Max_megs_check = FALSE;
}

canonical_original_code:
void disable_max_megs()
{
  Max_megs_check = FALSE;
}


decompiled_code:
void enable_max_megs()
{
Max_megs_check = 1;
}

canonical_decompiled_code:
void func11()
{
Max_megs_check = 1;
}

original_code:
void enable_max_megs(void)
{
  Max_megs_check = TRUE;
}

canonical_original_code:
void enable_max_megs()
{
  Max_megs_check = TRUE;
}


decompiled_code:
__int64 __fastcall fill_in_arrays(unsigned int *a1, unsigned int a2, int a3)
{
__int64 result; // rax
__int64 v4; // rax
int v5; // ecx
__int64 v6; // rbp
unsigned int v7; // er12
__int64 v8; // rax
int v9; // ecx

result = *a1;
if ( (int)result < 0 )
{
result = (unsigned int)-(int)result;
if ( Work_size > (int)result )
{
if ( a2 )
{
v4 = 4LL * (int)result;
++*(_DWORD *)(Pos_occurrences + v4);
result = Pos_maxdepth + v4;
v5 = a3;
if ( *(_DWORD *)result >= a3 )
v5 = *(_DWORD *)result;
*(_DWORD *)result = v5;
}
else
{
v8 = 4LL * (int)result;
++*(_DWORD *)(Neg_occurrences + v8);
result = Neg_maxdepth + v8;
v9 = a3;
if ( *(_DWORD *)result >= a3 )
v9 = *(_DWORD *)result;
*(_DWORD *)result = v9;
}
}
v6 = 0LL;
v7 = a3 + 1;
if ( *((_BYTE *)a1 + 4) )
{
do
{
fill_in_arrays(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v6++), a2, v7);
result = *((unsigned __int8 *)a1 + 4);
}
while ( (int)result > (int)v6 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, unsigned int a2, int a3)
{
__int64 result; // rax
__int64 v4; // rax
int v5; // ecx
__int64 v6; // rbp
unsigned int v7; // er12
__int64 v8; // rax
int v9; // ecx

result = *a1;
if ( (int)result < 0 )
{
result = (unsigned int)-(int)result;
if ( Work_size > (int)result )
{
if ( a2 )
{
v4 = 4LL * (int)result;
++*(_DWORD *)(Pos_occurrences + v4);
result = Pos_maxdepth + v4;
v5 = a3;
if ( *(_DWORD *)result >= a3 )
v5 = *(_DWORD *)result;
*(_DWORD *)result = v5;
}
else
{
v8 = 4LL * (int)result;
++*(_DWORD *)(Neg_occurrences + v8);
result = Neg_maxdepth + v8;
v9 = a3;
if ( *(_DWORD *)result >= a3 )
v9 = *(_DWORD *)result;
*(_DWORD *)result = v9;
}
}
v6 = 0LL;
v7 = a3 + 1;
if ( *((_BYTE *)a1 + 4) )
{
do
{
func0(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v6++), a2, v7);
result = *((unsigned __int8 *)a1 + 4);
}
while ( (int)result > (int)v6 );
}
}
return result;
}

original_code:
static
void fill_in_arrays(Term t, BOOL sign, int depth)
{
  if (!((t)->private_symbol >= 0)) {
    int sn = (-((t)->private_symbol));
    int i;
    if (sn >= Work_size) {
      ;
    }
    else if (sign) {
      Pos_occurrences[sn]++;
      Pos_maxdepth[sn] = ((depth) > (Pos_maxdepth[sn]) ? (depth) : (Pos_maxdepth[sn]));
    }
    else {
      Neg_occurrences[sn]++;
      Neg_maxdepth[sn] = ((depth) > (Neg_maxdepth[sn]) ? (depth) : (Neg_maxdepth[sn]));
    }
    for (i = 0; i < ((t)->arity); i++)
      fill_in_arrays(((t)->args[i]), sign, depth+1);
  }
}

canonical_original_code:
static void fill_in_arrays(struct term *t, enum BOOL sign, int depth)
{
  if (!((t)->private_symbol >= 0)) {
    int sn = (-((t)->private_symbol));
    int i;
    if (sn >= Work_size) {
      ;
    }
    else if (sign) {
      Pos_occurrences[sn]++;
      Pos_maxdepth[sn] = ((depth) > (Pos_maxdepth[sn]) ? (depth) : (Pos_maxdepth[sn]));
    }
    else {
      Neg_occurrences[sn]++;
      Neg_maxdepth[sn] = ((depth) > (Neg_maxdepth[sn]) ? (depth) : (Neg_maxdepth[sn]));
    }
    for (i = 0; i < ((t)->arity); i++)
      fill_in_arrays(((t)->args[i]), sign, depth+1);
  }
}

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:
sign
enum BOOL { FALSE=0, TRUE=1 }

variable_types: depth int

variable_types: sn int


decompiled_code:
void *__fastcall init_features(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
size_t v4; // rbx
void *result; // rax

Work_size = greatest_symnum() + 1;
v2 = ilist_copy(a1);
v3 = ilist_copy(a2);
Feature_symbols = ilist_cat(v3, v2);
v4 = Work_size;
Pos_occurrences = (__int64)calloc(Work_size, 4uLL);
Neg_occurrences = (__int64)calloc(v4, 4uLL);
Pos_maxdepth = (__int64)calloc(v4, 4uLL);
result = calloc(v4, 4uLL);
Neg_maxdepth = (__int64)result;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
size_t v4; // rbx
void *result; // rax

Work_size = greatest_symnum() + 1;
v2 = ilist_copy(a1);
v3 = ilist_copy(a2);
Feature_symbols = ilist_cat(v3, v2);
v4 = Work_size;
Pos_occurrences = (__int64)calloc(Work_size, 4uLL);
Neg_occurrences = (__int64)calloc(v4, 4uLL);
Pos_maxdepth = (__int64)calloc(v4, 4uLL);
result = calloc(v4, 4uLL);
Neg_maxdepth = (__int64)result;
return result;
}

original_code:
void init_features(Ilist fsyms, Ilist rsyms)
{
  Work_size = greatest_symnum() + 1;
  Feature_symbols = ilist_cat(ilist_copy(rsyms), ilist_copy(fsyms));
  Pos_occurrences = calloc(Work_size, sizeof(int));
  Neg_occurrences = calloc(Work_size, sizeof(int));
  Pos_maxdepth = calloc(Work_size, sizeof(int));
  Neg_maxdepth = calloc(Work_size, sizeof(int));
}

canonical_original_code:
void init_features(struct ilist *fsyms, struct ilist *rsyms)
{
  Work_size = greatest_symnum() + 1;
  Feature_symbols = ilist_cat(ilist_copy(rsyms), ilist_copy(fsyms));
  Pos_occurrences = calloc(Work_size, sizeof(int));
  Neg_occurrences = calloc(Work_size, sizeof(int));
  Pos_maxdepth = calloc(Work_size, sizeof(int));
  Neg_maxdepth = calloc(Work_size, sizeof(int));
}

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

variable_types:
rsyms
struct ilist *


features

decompiled_code:
__int64 __fastcall features(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
__int64 v3; // rbp
unsigned int v4; // eax
__int64 i; // rbp
int *v6; // rbx
__int64 v8; // rax
__int64 v9; // rax

v1 = a1;
v2 = positive_literals();
v3 = ilist_prepend(0LL, v2);
v4 = negative_literals(a1);
for ( i = ilist_prepend(v3, v4); v1; v1 = *(_QWORD *)(v1 + 16) )
fill_in_arrays(*(unsigned int **)(v1 + 8), *(_DWORD *)v1, 0);
v6 = (int *)Feature_symbols;
if ( Feature_symbols )
{
do
{
v8 = ilist_prepend(i, *(unsigned int *)(Pos_occurrences + 4LL * *v6));
i = ilist_prepend(v8, *(unsigned int *)(Neg_occurrences + 4LL * *v6));
if ( (unsigned int)function_symbol((unsigned int)*v6) )
{
v9 = ilist_prepend(i, *(unsigned int *)(Pos_maxdepth + 4LL * *v6));
i = ilist_prepend(v9, *(unsigned int *)(Neg_maxdepth + 4LL * *v6));
}
*(_DWORD *)(Pos_occurrences + 4LL * *v6) = 0;
*(_DWORD *)(Neg_occurrences + 4LL * *v6) = 0;
*(_DWORD *)(Pos_maxdepth + 4LL * *v6) = 0;
*(_DWORD *)(Neg_maxdepth + 4LL * *v6) = 0;
v6 = (int *)*((_QWORD *)v6 + 1);
}
while ( v6 );
}
return reverse_ilist(i);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
__int64 v3; // rbp
unsigned int v4; // eax
__int64 i; // rbp
int *v6; // rbx
__int64 v8; // rax
__int64 v9; // rax

v1 = a1;
v2 = positive_literals();
v3 = ilist_prepend(0LL, v2);
v4 = negative_literals(a1);
for ( i = ilist_prepend(v3, v4); v1; v1 = *(_QWORD *)(v1 + 16) )
func0(*(unsigned int **)(v1 + 8), *(_DWORD *)v1, 0);
v6 = (int *)Feature_symbols;
if ( Feature_symbols )
{
do
{
v8 = ilist_prepend(i, *(unsigned int *)(Pos_occurrences + 4LL * *v6));
i = ilist_prepend(v8, *(unsigned int *)(Neg_occurrences + 4LL * *v6));
if ( (unsigned int)function_symbol((unsigned int)*v6) )
{
v9 = ilist_prepend(i, *(unsigned int *)(Pos_maxdepth + 4LL * *v6));
i = ilist_prepend(v9, *(unsigned int *)(Neg_maxdepth + 4LL * *v6));
}
*(_DWORD *)(Pos_occurrences + 4LL * *v6) = 0;
*(_DWORD *)(Neg_occurrences + 4LL * *v6) = 0;
*(_DWORD *)(Pos_maxdepth + 4LL * *v6) = 0;
*(_DWORD *)(Neg_maxdepth + 4LL * *v6) = 0;
v6 = (int *)*((_QWORD *)v6 + 1);
}
while ( v6 );
}
return reverse_ilist(i);
}

original_code:
Ilist features(Literals lits)
{
  Ilist f = ((void *)0);
  Ilist p;
  Literals lit;
  f = ilist_prepend(f, positive_literals(lits));
  f = ilist_prepend(f, negative_literals(lits));
  for (lit = lits; lit; lit = lit->next) {
    fill_in_arrays(lit->atom, lit->sign, 0);
  }
  for (p = Feature_symbols; p; p = p->next) {
    f = ilist_prepend(f, Pos_occurrences[p->i]);
    f = ilist_prepend(f, Neg_occurrences[p->i]);
    if (function_symbol(p->i)) {
      f = ilist_prepend(f, Pos_maxdepth[p->i]);
      f = ilist_prepend(f, Neg_maxdepth[p->i]);
    }
    Pos_occurrences[p->i] = 0;
    Neg_occurrences[p->i] = 0;
    Pos_maxdepth[p->i] = 0;
    Neg_maxdepth[p->i] = 0;
  }
  f = reverse_ilist(f);
  return f;
}

canonical_original_code:
struct ilist *features(struct literals *lits)
{
  struct ilist *f = ((void *)0);
  struct ilist *p;
  struct literals *lit;
  f = ilist_prepend(f, positive_literals(lits));
  f = ilist_prepend(f, negative_literals(lits));
  for (lit = lits; lit; lit = lit->next) {
    fill_in_arrays(lit->atom, lit->sign, 0);
  }
  for (p = Feature_symbols; p; p = p->next) {
    f = ilist_prepend(f, Pos_occurrences[p->i]);
    f = ilist_prepend(f, Neg_occurrences[p->i]);
    if (function_symbol(p->i)) {
      f = ilist_prepend(f, Pos_maxdepth[p->i]);
      f = ilist_prepend(f, Neg_maxdepth[p->i]);
    }
    Pos_occurrences[p->i] = 0;
    Neg_occurrences[p->i] = 0;
    Pos_maxdepth[p->i] = 0;
    Neg_maxdepth[p->i] = 0;
  }
  f = reverse_ilist(f);
  return f;
}

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

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

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


decompiled_code:
__int64 feature_length()
{
unsigned int *v0; // rbp
unsigned int v1; // ebx
int v2; // edx
unsigned int v3; // eax

v0 = (unsigned int *)Feature_symbols;
if ( !Feature_symbols )
return 2;
v1 = 2;
do
{
v2 = function_symbol(*v0);
v3 = v1 + 2;
v1 += 4;
if ( !v2 )
v1 = v3;
v0 = (unsigned int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int *v0; // rbp
unsigned int v1; // ebx
int v2; // edx
unsigned int v3; // eax

v0 = (unsigned int *)Feature_symbols;
if ( !Feature_symbols )
return 2;
v1 = 2;
do
{
v2 = function_symbol(*v0);
v3 = v1 + 2;
v1 += 4;
if ( !v2 )
v1 = v3;
v0 = (unsigned int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
return v1;
}

original_code:
int feature_length(void)
{
  int n = 2;
  Ilist p;
  for (p = Feature_symbols; p; p = p->next) {
    n += 2;
    if (function_symbol(p->i))
      n += 2;
  }
  return n;
}

canonical_original_code:
int feature_length()
{
  int n = 2;
  struct ilist *p;
  for (p = Feature_symbols; p; p = p->next) {
    n += 2;
    if (function_symbol(p->i))
      n += 2;
  }
  return n;
}

variable_types: n int


original_code:
BOOL features_less_or_equal(Ilist c, Ilist d)
{
  while (c && d && c->i <= d->i) {
    c = c->next;
    d = d->next;
  }
  return !c && !d;
}

canonical_original_code:
enum BOOL features_less_or_equal(struct ilist *c, struct ilist *d)
{
  while (c && d && c->i <= d->i) {
    c = c->next;
    d = d->next;
  }
  return !c && !d;
}

variable_types:
d
struct ilist *


decompiled_code:
int __fastcall p_features(unsigned int *a1)
{
__int64 v1; // rax
unsigned int *v2; // rbx
unsigned int *v3; // rbp
const char *v4; // rax

printf(" pos_lits=%d, neg_lits=%d\n", *a1, **((unsigned int **)a1 + 1));
v1 = *((_QWORD *)a1 + 1);
v2 = *(unsigned int **)(v1 + 8);
v3 = (unsigned int *)Feature_symbols;
if ( Feature_symbols )
{
do
{
v4 = (const char *)sn_to_str(*v3);
printf(" symbol %s: ", v4);
printf("pos_occ=%d, neg_occ=%d", *v2, **((unsigned int **)v2 + 1));
v2 = *(unsigned int **)(*((_QWORD *)v2 + 1) + 8LL);
if ( (unsigned int)function_symbol(*v3) )
{
printf(", pos_max=%d, neg_max=%d", *v2, **((unsigned int **)v2 + 1));
v2 = *(unsigned int **)(*((_QWORD *)v2 + 1) + 8LL);
}
LODWORD(v1) = putchar(10);
v3 = (unsigned int *)*((_QWORD *)v3 + 1);
}
while ( v3 );
}
return v1;
}

canonical_decompiled_code:
int __fastcall func5(unsigned int *a1)
{
__int64 v1; // rax
unsigned int *v2; // rbx
unsigned int *v3; // rbp
const char *v4; // rax

printf(" pos_lits=%d, neg_lits=%d\n", *a1, **((unsigned int **)a1 + 1));
v1 = *((_QWORD *)a1 + 1);
v2 = *(unsigned int **)(v1 + 8);
v3 = (unsigned int *)Feature_symbols;
if ( Feature_symbols )
{
do
{
v4 = (const char *)sn_to_str(*v3);
printf(" symbol %s: ", v4);
printf("pos_occ=%d, neg_occ=%d", *v2, **((unsigned int **)v2 + 1));
v2 = *(unsigned int **)(*((_QWORD *)v2 + 1) + 8LL);
if ( (unsigned int)function_symbol(*v3) )
{
printf(", pos_max=%d, neg_max=%d", *v2, **((unsigned int **)v2 + 1));
v2 = *(unsigned int **)(*((_QWORD *)v2 + 1) + 8LL);
}
LODWORD(v1) = putchar(10);
v3 = (unsigned int *)*((_QWORD *)v3 + 1);
}
while ( v3 );
}
return v1;
}

original_code:
void p_features(Ilist f)
{
  Ilist p;
  printf("  pos_lits=%d, neg_lits=%d\n", f->i, f->next->i);
  f = f->next->next;
  for (p = Feature_symbols; p; p = p->next) {
    printf("  symbol %s: ", sn_to_str(p->i));
    printf("pos_occ=%d, neg_occ=%d", f->i, f->next->i);
    f = f->next->next;
    if (function_symbol(p->i)) {
      printf(", pos_max=%d, neg_max=%d", f->i, f->next->i);
      f = f->next->next;
    }
    printf("\n");
  }
}

canonical_original_code:
void p_features(struct ilist *f)
{
  struct ilist *p;
  printf("  pos_lits=%d, neg_lits=%d\n", f->i, f->next->i);
  f = f->next->next;
  for (p = Feature_symbols; p; p = p->next) {
    printf("  symbol %s: ", sn_to_str(p->i));
    printf("pos_occ=%d, neg_occ=%d", f->i, f->next->i);
    f = f->next->next;
    if (function_symbol(p->i)) {
      printf(", pos_max=%d, neg_max=%d", f->i, f->next->i);
      f = f->next->next;
    }
    printf("\n");
  }
}


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

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

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

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

original_code:
static
Clock get_clock(void)
{
  Clock p = get_cmem(((sizeof(struct clock))%(sizeof(void *)) == 0 ? (sizeof(struct clock))/(sizeof(void *)) : (sizeof(struct clock))/(sizeof(void *)) + 1));
  Clock_gets++;
  return(p);
}

canonical_original_code:
static struct clock *get_clock()
{
  struct clock *p = get_cmem(((sizeof(struct clock))%(sizeof(void *)) == 0 ? (sizeof(struct clock))/(sizeof(void *)) : (sizeof(struct clock))/(sizeof(void *)) + 1));
  Clock_gets++;
  return(p);
}

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


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

if ( a1 )
{
result = free_mem(a1, 3LL);
++Clock_frees;
}
return result;
}

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

if ( a1 )
{
result = free_mem(a1, 3LL);
++Clock_frees;
}
return result;
}

original_code:
void free_clock(Clock p)
{
  if (p != ((void *)0)) {
    free_mem(p, ((sizeof(struct clock))%(sizeof(void *)) == 0 ? (sizeof(struct clock))/(sizeof(void *)) : (sizeof(struct clock))/(sizeof(void *)) + 1));
    Clock_frees++;
  }
}

canonical_original_code:
void free_clock(struct clock *p)
{
  if (p != ((void *)0)) {
    free_mem(p, ((sizeof(struct clock))%(sizeof(void *)) == 0 ? (sizeof(struct clock))/(sizeof(void *)) : (sizeof(struct clock))/(sizeof(void *)) + 1));
    Clock_frees++;
  }
}

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


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

result = get_clock();
*(_QWORD *)result = a1;
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 8) = 0;
return result;
}

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

result = func0();
*(_QWORD *)result = a1;
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 8) = 0;
return result;
}

original_code:
Clock clock_init(char *str)
{
  Clock p = get_clock();
  p->name = str;
  p->level = 0;
  p->accum_msec = 0;
  return p;
}

canonical_original_code:
struct clock *clock_init(char *str)
{
  struct clock *p = get_clock();
  p->name = str;
  p->level = 0;
  p->accum_msec = 0;
  return p;
}

variable_types:
str
char *

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


decompiled_code:
__int64 __fastcall clock_start(__int64 a1)
{
__int64 result; // rax
struct rusage v2; // [rsp+0h] [rbp-98h] BYREF

if ( Clocks_enabled )
{
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
if ( (_DWORD)result == 1 )
{
getrusage(RUSAGE_SELF, &v2);
result = 0x20C49BA5E353F7CFLL * v2.ru_utime.tv_usec;
*(_DWORD *)(a1 + 12) = 1000 * LODWORD(v2.ru_utime.tv_sec) + SLODWORD(v2.ru_utime.tv_usec) / 1000;
++Clock_starts;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
struct rusage v2; // [rsp+0h] [rbp-98h] BYREF

if ( Clocks_enabled )
{
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
if ( (_DWORD)result == 1 )
{
getrusage(RUSAGE_SELF, &v2);
result = 0x20C49BA5E353F7CFLL * v2.ru_utime.tv_usec;
*(_DWORD *)(a1 + 12) = 1000 * LODWORD(v2.ru_utime.tv_sec) + SLODWORD(v2.ru_utime.tv_usec) / 1000;
++Clock_starts;
}
}
return result;
}

original_code:
void clock_start(Clock p)
{
  if (Clocks_enabled) {
    p->level++;
    if (p->level == 1) {
      { struct rusage r; getrusage(RUSAGE_SELF, &r); p->curr_msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
      Clock_starts++;
    }
  }
}

canonical_original_code:
void clock_start(struct clock *p)
{
  if (Clocks_enabled) {
    p->level++;
    if (p->level == 1) {
      { struct rusage r; getrusage(RUSAGE_SELF, &r); p->curr_msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; };
      Clock_starts++;
    }
  }
}

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

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