decompiled_code:
__int64 __fastcall avl_item_at_position(__int64 a1, double a2)
{
int v2; // edx
double v3; // xmm0_8
int v4; // eax
int v5; // esi
__m128d v7; // xmm4
__m128d v8; // xmm1

if ( a1 && a2 > 0.0 && a2 <= 1.0 )
{
v2 = *(_DWORD *)(a1 + 8);
v3 = a2 * (double)v2;
if ( COERCE_DOUBLE(*(_QWORD *)&v3 & LC12) < 4.503599627370496e15 )
{
v7.m128d_f64[0] = v3;
v5 = 1;
v8.m128d_f64[0] = (double)(int)v3;
v4 = (int)COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v8.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v7, v8) & LC10)) | ~LC12 & *(_QWORD *)&v3);
if ( v4 > 0 )
goto LABEL_6;
}
else
{
v4 = (int)v3;
v5 = 1;
if ( (int)v3 > 0 )
{
LABEL_6:
if ( v2 <= v4 )
v4 = *(_DWORD *)(a1 + 8);
v5 = v4;
return avl_nth_item(a1, v5);
}
}
return avl_nth_item(a1, v5);
}
return 0LL;
}

original_code:
void *avl_item_at_position(Avl_node p, double pos)
{
  if (p == ((void *)0) || pos <= 0.0 || pos > 1.0)
    return ((void *)0);
  else {
    int n = (int) ceil(pos * p->size);
    n = (n < 1 ? 1 : (n > p->size ? p->size : n));
    return avl_nth_item(p, n);
  }
}

canonical_original_code:
void *avl_item_at_position(struct avl_node *p, double pos)
{
  if (p == ((void *)0) || pos <= 0.0 || pos > 1.0)
    return ((void *)0);
  else {
    int n = (int) ceil(pos * p->size);
    n = (n < 1 ? 1 : (n > p->size ? p->size : n));
    return avl_nth_item(p, n);
  }
}

variable_types: pos double


repo: jessealama/ladr

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

if ( a1 )
{
avl_zap(*(_QWORD *)(a1 + 16));
avl_zap(*(_QWORD *)(a1 + 24));
result = free_avl_node(a1);
}
return result;
}

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

if ( a1 )
{
func18(*(_QWORD *)(a1 + 16));
func18(*(_QWORD *)(a1 + 24));
result = func1(a1);
}
return result;
}

original_code:
void avl_zap(Avl_node p)
{
  if (p != ((void *)0)) {
    avl_zap(p->left);
    avl_zap(p->right);
    free_avl_node(p);
  }
}

canonical_original_code:
void avl_zap(struct avl_node *p)
{
  if (p != ((void *)0)) {
    avl_zap(p->left);
    avl_zap(p->right);
    free_avl_node(p);
  }
}

variable_types: struct avl_node { void *item; int size; int height; struct avl_node *left; } *

return_type: void


decompiled_code:
void __fastcall avl_check(const void **a1, unsigned int (__fastcall *a2)(_QWORD, const void *))
{
_QWORD *v2; // rax
_QWORD *v3; // rdx
__int64 v4; // rdx
int v5; // eax
const void *v6; // rdx
__int64 v7; // r8
int v8; // er9
int v9; // esi
int v10; // ecx
bool v11; // cc
int v12; // eax
__int64 v13; // rsi
__int64 v14; // rdx
int v15; // eax
__int64 v16; // r8
int v17; // ecx

if ( !a1 )
return;
avl_check(a1[2]);
avl_check(a1[3]);
v2 = a1[2];
if ( v2 && a2(*v2, *a1) != 2 )
{
printf("error: left not smaller: %p\n", *a1);
fprintf(stderr, "error: left not smaller: %p\n", *a1);
v3 = a1[3];
if ( v3 )
{
LABEL_5:
if ( a2(*v3, *a1) != 3 )
{
printf("error: right not greater: %p\n", *a1);
fprintf(stderr, "error: right not greater: %p\n", *a1);
}
goto LABEL_7;
}
}
else
{
v3 = a1[3];
if ( v3 )
goto LABEL_5;
}
LABEL_7:
avl_height((__int64)a1[2]);
v5 = avl_height(v4);
v9 = v5 + 1;
v11 = v10 <= v5;
v12 = v10 + 1;
if ( v11 )
v12 = v9;
if ( v8 != v12 )
{
printf("error: height wrong: %p\n", *a1);
fprintf(stderr, "error: height wrong: %p\n", *a1);
v7 = (__int64)a1[2];
v6 = a1[3];
}
v13 = (__int64)v6;
avl_size(v7);
v15 = avl_size(v14);
if ( *((_DWORD *)a1 + 2) == v17 + v15 + 1 )
{
if ( balance_ok_isra_0(v16, v13) )
return;
LABEL_19:
printf("error: unbalanced: %p\n", *a1);
fprintf(stderr, "error: unbalanced: %p\n", *a1);
return;
}
printf("error: size wrong: %p\n", *a1);
fprintf(stderr, "error: size wrong: %p\n", *a1);
if ( !balance_ok_isra_0((__int64)a1[2], (__int64)a1[3]) )
goto LABEL_19;
}

canonical_decompiled_code:
void __fastcall func19(const void **a1, unsigned int (__fastcall *a2)(_QWORD, const void *))
{
_QWORD *v2; // rax
_QWORD *v3; // rdx
__int64 v4; // rdx
int v5; // eax
const void *v6; // rdx
__int64 v7; // r8
int v8; // er9
int v9; // esi
int v10; // ecx
bool v11; // cc
int v12; // eax
__int64 v13; // rsi
__int64 v14; // rdx
int v15; // eax
__int64 v16; // r8
int v17; // ecx

if ( !a1 )
return;
func19(a1[2]);
func19(a1[3]);
v2 = a1[2];
if ( v2 && a2(*v2, *a1) != 2 )
{
printf("error: left not smaller: %p\n", *a1);
fprintf(stderr, "error: left not smaller: %p\n", *a1);
v3 = a1[3];
if ( v3 )
{
LABEL_5:
if ( a2(*v3, *a1) != 3 )
{
printf("error: right not greater: %p\n", *a1);
fprintf(stderr, "error: right not greater: %p\n", *a1);
}
goto LABEL_7;
}
}
else
{
v3 = a1[3];
if ( v3 )
goto LABEL_5;
}
LABEL_7:
func4((__int64)a1[2]);
v5 = func4(v4);
v9 = v5 + 1;
v11 = v10 <= v5;
v12 = v10 + 1;
if ( v11 )
v12 = v9;
if ( v8 != v12 )
{
printf("error: height wrong: %p\n", *a1);
fprintf(stderr, "error: height wrong: %p\n", *a1);
v7 = (__int64)a1[2];
v6 = a1[3];
}
v13 = (__int64)v6;
func6(v7);
v15 = func6(v14);
if ( *((_DWORD *)a1 + 2) == v17 + v15 + 1 )
{
if ( func5(v16, v13) )
return;
LABEL_19:
printf("error: unbalanced: %p\n", *a1);
fprintf(stderr, "error: unbalanced: %p\n", *a1);
return;
}
printf("error: size wrong: %p\n", *a1);
fprintf(stderr, "error: size wrong: %p\n", *a1);
if ( !func5((__int64)a1[2], (__int64)a1[3]) )
goto LABEL_19;
}

original_code:
void avl_check(Avl_node p,
        Ordertype (*compare) (void *, void *))
{
  if (p != ((void *)0)) {
    avl_check(p->left, compare);
    avl_check(p->right, compare);
    if (p->left && (*compare)(p->left->item, p->item) != LESS_THAN) {
      printf("error: left not smaller: %p\n", p->item);
      fprintf(stderr, "error: left not smaller: %p\n", p->item);
    }
    if (p->right && (*compare)(p->right->item, p->item) != GREATER_THAN) {
      printf("error: right not greater: %p\n", p->item);
      fprintf(stderr, "error: right not greater: %p\n", p->item);
    }
    if (p->height != ((avl_height(p->left)) > (avl_height(p->right)) ? (avl_height(p->left)) : (avl_height(p->right))) + 1) {
      printf("error: height wrong: %p\n", p->item);
      fprintf(stderr, "error: height wrong: %p\n", p->item);
    }
    if (p->size != (avl_size(p->left) + avl_size(p->right)) + 1) {
      printf("error: size wrong: %p\n", p->item);
      fprintf(stderr, "error: size wrong: %p\n", p->item);
    }
    if (!balance_ok(p)) {
      printf("error: unbalanced: %p\n", p->item);
      fprintf(stderr, "error: unbalanced: %p\n", p->item);
    }
  }
}

canonical_original_code:
void avl_check(struct avl_node *p, enum Ordertype (*compare)(void *, void *))
{
  if (p != ((void *)0)) {
    avl_check(p->left, compare);
    avl_check(p->right, compare);
    if (p->left && (*compare)(p->left->item, p->item) != LESS_THAN) {
      printf("error: left not smaller: %p\n", p->item);
      fprintf(stderr, "error: left not smaller: %p\n", p->item);
    }
    if (p->right && (*compare)(p->right->item, p->item) != GREATER_THAN) {
      printf("error: right not greater: %p\n", p->item);
      fprintf(stderr, "error: right not greater: %p\n", p->item);
    }
    if (p->height != ((avl_height(p->left)) > (avl_height(p->right)) ? (avl_height(p->left)) : (avl_height(p->right))) + 1) {
      printf("error: height wrong: %p\n", p->item);
      fprintf(stderr, "error: height wrong: %p\n", p->item);
    }
    if (p->size != (avl_size(p->left) + avl_size(p->right)) + 1) {
      printf("error: size wrong: %p\n", p->item);
      fprintf(stderr, "error: size wrong: %p\n", p->item);
    }
    if (!balance_ok(p)) {
      printf("error: unbalanced: %p\n", p->item);
      fprintf(stderr, "error: unbalanced: %p\n", p->item);
    }
  }
}

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

user_defined_types: struct avl_node { void *item; int size; int height; struct avl_node *left; }


decompiled_code:
int __fastcall p_avl(unsigned int *a1, int a2)
{
int v2; // er14
unsigned int v3; // er13
unsigned int *i; // r12
int v5; // ebp
int j; // ebx
int k; // ebx

v2 = a2;
v3 = a2;
for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v5 = v3++;
v2 = v3;
p_avl(*((_QWORD *)i + 3), v3);
if ( v5 > 0 )
{
for ( j = 0; j != v5; ++j )
printf(" ");
}
printf("%4d\n", *i);
}
if ( v2 > 0 )
{
for ( k = 0; k != v2; ++k )
printf(" ");
}
return puts("----");
}

canonical_decompiled_code:
int __fastcall func20(unsigned int *a1, int a2)
{
int v2; // er14
unsigned int v3; // er13
unsigned int *i; // r12
int v5; // ebp
int j; // ebx
int k; // ebx

v2 = a2;
v3 = a2;
for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v5 = v3++;
v2 = v3;
func20(*((_QWORD *)i + 3), v3);
if ( v5 > 0 )
{
for ( j = 0; j != v5; ++j )
printf(" ");
}
printf("%4d\n", *i);
}
if ( v2 > 0 )
{
for ( k = 0; k != v2; ++k )
printf(" ");
}
return puts("----");
}

original_code:
void p_avl(Avl_node p, int level)
{
  int i;
  if (p == ((void *)0)) {
    for (i = 0; i < level; i++)
      printf("    ");
    printf("----\n");
  }
  else {
    p_avl(p->right, level+1);
    for (i = 0; i < level; i++)
      printf("    ");
    printf("%4d\n", (int) p->item);
    p_avl(p->left, level+1);
  }
}

canonical_original_code:
void p_avl(struct avl_node *p, int level)
{
  int i;
  if (p == ((void *)0)) {
    for (i = 0; i < level; i++)
      printf("    ");
    printf("----\n");
  }
  else {
    p_avl(p->right, level+1);
    for (i = 0; i < level; i++)
      printf("    ");
    printf("%4d\n", (int) p->item);
    p_avl(p->left, level+1);
  }
}

variable_types: level int

variable_types: i int


original_code:
Flatterm fapply_demod(Term t, Context c)
{
  Flatterm f;
  if (((t)->private_symbol >= 0)) {
    f = copy_flatterm((Flatterm) c->terms[((t)->private_symbol)]);
    f->reduced_flag = TRUE;
  }
  else {
    int n = 1;
    int i;
    Flatterm end;
    f = get_flatterm();
    f->private_symbol = t->private_symbol;
    ((f)->arity) = ((t)->arity);
    end = f;
    for (i = 0; i < ((t)->arity); i++) {
      Flatterm a = fapply_demod(((t)->args[i]), c);
      n += a->size;
      end->next = a;
      a->prev = end;
      end = a->end;
    }
    f->size = n;
    f->end = end;
  }
  return f;
}

canonical_original_code:
struct flatterm *fapply_demod(struct term *t, struct context *c)
{
  struct flatterm *f;
  if (((t)->private_symbol >= 0)) {
    f = copy_flatterm((struct flatterm *) c->terms[((t)->private_symbol)]);
    f->reduced_flag = TRUE;
  }
  else {
    int n = 1;
    int i;
    struct flatterm *end;
    f = get_flatterm();
    f->private_symbol = t->private_symbol;
    ((f)->arity) = ((t)->arity);
    end = f;
    for (i = 0; i < ((t)->arity); i++) {
      struct flatterm *a = fapply_demod(((t)->args[i]), c);
      n += a->size;
      end->next = a;
      a->prev = end;
      end = a->end;
    }
    f->size = n;
    f->end = end;
  }
  return f;
}

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

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

variable_types: struct flatterm { short private_symbol; unsigned char arity; struct flatterm *prev; int size; struct discrim { struct discrim *next; union { struct discrim *kids; struct plist { void *v; struct plist *next; } *data; } u; short symbol; char type; } *alternative; int varnum_bound_to; enum BOOL { FALSE=0, TRUE=1 } reduced_flag; } *

variable_types: n int

user_defined_types: struct flatterm { short private_symbol; unsigned char arity; struct flatterm *prev; int size; struct discrim *alternative; int varnum_bound_to; enum BOOL reduced_flag; }

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


original_code:
void discrim_flat_cancel(Discrim_pos pos)
{
  Flatterm f = pos->backtrack;
  Flatterm query = (Flatterm) pos->query;
  while (f != query->prev) {
    if (f->varnum_bound_to >= 0) {
      pos->subst->terms[f->varnum_bound_to] = ((void *)0);
      f->varnum_bound_to = -1;
    }
    f->alternative = ((void *)0);
    f = f->prev;
  }
  free_discrim_pos(pos);
}

canonical_original_code:
void discrim_flat_cancel(struct discrim_pos *pos)
{
  struct flatterm *f = pos->backtrack;
  struct flatterm *query = (Flatterm) pos->query;
  while (f != query->prev) {
    if (f->varnum_bound_to >= 0) {
      pos->subst->terms[f->varnum_bound_to] = ((void *)0);
      f->varnum_bound_to = -1;
    }
    f->alternative = ((void *)0);
    f = f->prev;
  }
  free_discrim_pos(pos);
}

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

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

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


fdemodulate

decompiled_code:
__int64 __fastcall fdemodulate(__int64 a1, __int64 a2, _DWORD *a3, int *a4, int *a5, _QWORD *a6, unsigned int a7)
{
__int64 v10; // r12
__int64 v11; // rax
int v12; // er15
__int64 v13; // rbp
int v14; // eax
int v15; // er15
__int64 v16; // r12
__int64 v17; // rdi
__int64 v18; // r14
int v22[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v10 = term_to_flatterm();
v11 = get_context();
v12 = *(_DWORD *)(v10 + 32);
v13 = v11;
v14 = *a4;
v22[0] = v12;
if ( v14 != 0x7FFFFFFF )
{
v15 = v14 + v12;
v16 = fdemod(v10, a2, v13, a3, v15, v22, a5, a6, a7);
free_context(v13);
if ( v22[0] > v15 )
*a4 = -1;
v17 = v16;
if ( *a6 )
goto LABEL_5;
LABEL_8:
zap_flatterm(v17);
return a1;
}
v16 = fdemod(v10, a2, v13, a3, 0x7FFFFFFF, v22, a5, a6, a7);
free_context(v13);
v17 = v16;
if ( !*a6 )
goto LABEL_8;
LABEL_5:
v18 = flatterm_to_term(v17);
zap_flatterm(v16);
zap_term(a1);
return v18;
}

original_code:
Term fdemodulate(Term t, Discrim root,
   int *step_limit, int *increase_limit, int *sequence,
   I3list *just_head, BOOL lex_order_vars)
{
  Flatterm f = term_to_flatterm(t);
  Context subst = get_context();
  int current_size = f->size;
  int size_limit = (*increase_limit==0x7fffffff) ? 0x7fffffff : current_size + *increase_limit;
  Flatterm f2 = fdemod(f, root, subst, step_limit,
         size_limit, &current_size,
         sequence, just_head, lex_order_vars);
  free_context(subst);
  if (current_size > size_limit)
    *increase_limit = -1;
  if (*just_head == ((void *)0)) {
    zap_flatterm(f2);
    return t;
  }
  else {
    Term t2 = flatterm_to_term(f2);
    zap_flatterm(f2);
    zap_term(t);
    return t2;
  }
}

canonical_original_code:
struct term *fdemodulate(struct term *t, struct discrim *root, int *step_limit, int *increase_limit, int *sequence, struct i3list **just_head, enum BOOL lex_order_vars)
{
  struct flatterm *f = term_to_flatterm(t);
  struct context *subst = get_context();
  int current_size = f->size;
  int size_limit = (*increase_limit==0x7fffffff) ? 0x7fffffff : current_size + *increase_limit;
  struct flatterm *f2 = fdemod(f, root, subst, step_limit,
         size_limit, &current_size,
         sequence, just_head, lex_order_vars);
  free_context(subst);
  if (current_size > size_limit)
    *increase_limit = -1;
  if (*just_head == ((void *)0)) {
    zap_flatterm(f2);
    return t;
  }
  else {
    struct term *t2 = flatterm_to_term(f2);
    zap_flatterm(f2);
    zap_term(t);
    return t2;
  }
}

variable_types:
t
struct term *

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

variable_types:
sequence
int *

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

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


decompiled_code:
__int64 fdemod_attempts()
{
return (unsigned int)Fdemod_attempts;
}

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

original_code:
int fdemod_attempts()
{
  return Fdemod_attempts;
}

return_type: int


decompiled_code:
__int64 fdemod_rewrites()
{
return (unsigned int)Fdemod_rewrites;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)Fdemod_rewrites;
}

original_code:
int fdemod_rewrites()
{
  return Fdemod_rewrites;
}


original_code:
static
double complexity2(int *s, int n)
{
  int c = 1;
  int b = 1;
  int a, k, kmax;
  a = k = kmax = 0;
  while (b+k < n) {
    if (s[a+k] == s[b+k]) {
      k++;
    }
    else {
      kmax = ((k) > (kmax) ? (k) : (kmax));
      a++;
      if (a != b)
 k = 0;
      else {
 c++;
 b += (kmax+1);
 a = k = kmax = 0;
      }
    }
  }
  return ((double) c) / n;
}

canonical_original_code:
static double complexity2(int *s, int n)
{
  int c = 1;
  int b = 1;
  int a; int k; int kmax;
  a = k = kmax = 0;
  while (b+k < n) {
    if (s[a+k] == s[b+k]) {
      k++;
    }
    else {
      kmax = ((k) > (kmax) ? (k) : (kmax));
      a++;
      if (a != b)
 k = 0;
      else {
 c++;
 b += (kmax+1);
 a = k = kmax = 0;
      }
    }
  }
  return ((double) c) / n;
}

variable_types:
s
int *

variable_types: c int

variable_types: b int

variable_types: a int

variable_types: k int

variable_types: kmax int

return_type: double


decompiled_code:
__int64 __fastcall complex4_compare(__int64 a1, unsigned int *a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v7; // rbp
__int64 v8; // rsi
__int64 v9; // rdi

result = *a2;
if ( *(_DWORD *)a1 == (_DWORD)result )
{
++*a3;
if ( *(_BYTE *)(a1 + 4) )
{
v7 = 0LL;
do
{
v8 = *(_QWORD *)(*((_QWORD *)a2 + 1) + 8 * v7);
v9 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7++);
complex4_compare(v9, v8, a3);
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v7 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int *a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v7; // rbp
__int64 v8; // rsi
__int64 v9; // rdi

result = *a2;
if ( *(_DWORD *)a1 == (_DWORD)result )
{
++*a3;
if ( *(_BYTE *)(a1 + 4) )
{
v7 = 0LL;
do
{
v8 = *(_QWORD *)(*((_QWORD *)a2 + 1) + 8 * v7);
v9 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7++);
func1(v9, v8, a3);
result = *(unsigned __int8 *)(a1 + 4);
}
while ( (int)result > (int)v7 );
}
}
return result;
}

original_code:
static
void complex4_compare(Term a, Term b, int *n)
{
  if ((-((a)->private_symbol)) == (-((b)->private_symbol))) {
    int i;
    (*n)++;
    for (i = 0; i < ((a)->arity); i++)
      complex4_compare(((a)->args[i]), ((b)->args[i]), n);
  }
}

canonical_original_code:
static void complex4_compare(struct term *a, struct term *b, int *n)
{
  if ((-((a)->private_symbol)) == (-((b)->private_symbol))) {
    int i;
    (*n)++;
    for (i = 0; i < ((a)->arity); i++)
      complex4_compare(((a)->args[i]), ((b)->args[i]), n);
  }
}

variable_types:
b
struct term *

variable_types:
n
int *

variable_types: i int

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


decompiled_code:
__int64 __fastcall complex4_p2(__int64 a1, __int64 a2, _DWORD *a3)
{
__int64 v4; // rbx
int v5; // er8
unsigned int v6; // er8

if ( a1 == a2 )
return 0LL;
if ( *(_BYTE *)(a2 + 4) )
{
v4 = 0LL;
do
{
v5 = complex4_p2(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v4), a3);
if ( *(unsigned __int8 *)(a2 + 4) <= (int)v4 + 1 )
break;
++v4;
}
while ( v5 );
}
complex4_compare(a1, (unsigned int *)a2, a3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, _DWORD *a3)
{
__int64 v4; // rbx
int v5; // er8
unsigned int v6; // er8

if ( a1 == a2 )
return 0LL;
if ( *(_BYTE *)(a2 + 4) )
{
v4 = 0LL;
do
{
v5 = func2(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v4), a3);
if ( *(unsigned __int8 *)(a2 + 4) <= (int)v4 + 1 )
break;
++v4;
}
while ( v5 );
}
func1(a1, (unsigned int *)a2, a3);
return v6;
}

original_code:
static
BOOL complex4_p2(Term s, Term t, int *n)
{
  if (s == t)
    return FALSE;
  else {
    int i;
    BOOL go;
    for (i = 0, go = TRUE; i < ((t)->arity) && go; i++)
      go = complex4_p2(s, ((t)->args[i]), n);
    complex4_compare(s, t, n);
    return go;
  }
}

canonical_original_code:
static enum BOOL complex4_p2(struct term *s, struct term *t, int *n)
{
  if (s == t)
    return FALSE;
  else {
    int i;
    enum BOOL go;
    for (i = 0, go = TRUE; i < ((t)->arity) && go; i++)
      go = complex4_p2(s, ((t)->args[i]), n);
    complex4_compare(s, t, n);
    return go;
  }
}

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

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


original_code:
static
void complex4_p1(Term s, Term t, int *n)
{
  BOOL dummy;
  int i;
  for (i = 0; i < ((s)->arity); i++)
    complex4_p1(((s)->args[i]), t, n);
  dummy = complex4_p2(s, t, n);
}

canonical_original_code:
static void complex4_p1(struct term *s, struct term *t, int *n)
{
  enum BOOL dummy;
  int i;
  for (i = 0; i < ((s)->arity); i++)
    complex4_p1(((s)->args[i]), t, n);
  dummy = complex4_p2(s, t, n);
}

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


decompiled_code:
__int64 __fastcall complex4_devar(__int64 a1, unsigned int a2)
{
int v3; // edi
__int64 v4; // rbx
_QWORD *v5; // r12
__int64 result; // rax
__int64 v7; // r12

v3 = *(_DWORD *)a1;
if ( v3 >= 0 )
{
v7 = get_rigid_term_dangerously(a2 + v3, 0LL);
free_term(a1);
result = v7;
}
else
{
v4 = 0LL;
if ( *(_BYTE *)(a1 + 4) )
{
do
{
v5 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v4++);
*v5 = complex4_devar(*v5, a2);
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v4 );
}
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
int v3; // edi
__int64 v4; // rbx
_QWORD *v5; // r12
__int64 result; // rax
__int64 v7; // r12

v3 = *(_DWORD *)a1;
if ( v3 >= 0 )
{
v7 = get_rigid_term_dangerously(a2 + v3, 0LL);
free_term(a1);
result = v7;
}
else
{
v4 = 0LL;
if ( *(_BYTE *)(a1 + 4) )
{
do
{
v5 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v4++);
*v5 = func5(*v5, a2);
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v4 );
}
result = a1;
}
return result;
}

original_code:
static
Term complex4_devar(Term t, int base)
{
  if (((t)->private_symbol >= 0)) {
    Term new = get_rigid_term_dangerously(base + ((t)->private_symbol), 0);
    free_term(t);
    return new;
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = complex4_devar(((t)->args[i]), base);
    return t;
  }
}

canonical_original_code:
static struct term *complex4_devar(struct term *t, int base)
{
  if (((t)->private_symbol >= 0)) {
    struct term *new = get_rigid_term_dangerously(base + ((t)->private_symbol), 0);
    free_term(t);
    return new;
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = complex4_devar(((t)->args[i]), base);
    return t;
  }
}

variable_types:
t
struct term *

variable_types: base int

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 complex4_revar(__int64 a1, int a2)
{
int v3; // edi
char v4; // al
int v5; // edi
__int64 v7; // rbx
_QWORD *v8; // r12
__int64 v9; // [rsp+8h] [rbp-30h]

v3 = *(_DWORD *)a1;
v4 = *(_BYTE *)(a1 + 4);
if ( v3 >= 0 )
{
if ( !v4 )
return a1;
LABEL_6:
v7 = 0LL;
do
{
v8 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7++);
*v8 = complex4_revar(*v8, (unsigned int)a2);
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v7 );
return a1;
}
if ( v4 )
goto LABEL_6;
v5 = -v3;
if ( v5 < a2 )
return a1;
v9 = get_variable_term((unsigned int)(v5 - a2));
free_term(a1);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v3; // edi
char v4; // al
int v5; // edi
__int64 v7; // rbx
_QWORD *v8; // r12
__int64 v9; // [rsp+8h] [rbp-30h]

v3 = *(_DWORD *)a1;
v4 = *(_BYTE *)(a1 + 4);
if ( v3 >= 0 )
{
if ( !v4 )
return a1;
LABEL_6:
v7 = 0LL;
do
{
v8 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7++);
*v8 = func6(*v8, (unsigned int)a2);
}
while ( *(unsigned __int8 *)(a1 + 4) > (int)v7 );
return a1;
}
if ( v4 )
goto LABEL_6;
v5 = -v3;
if ( v5 < a2 )
return a1;
v9 = get_variable_term((unsigned int)(v5 - a2));
free_term(a1);
return v9;
}

original_code:
static
Term complex4_revar(Term t, int base)
{
  if (((t)->private_symbol < 0 && (t)->arity == 0) && (-((t)->private_symbol)) >= base) {
    Term var = get_variable_term((-((t)->private_symbol)) - base);
    free_term(t);
    return var;
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = complex4_revar(((t)->args[i]), base);
    return t;
  }
}

canonical_original_code:
static struct term *complex4_revar(struct term *t, int base)
{
  if (((t)->private_symbol < 0 && (t)->arity == 0) && (-((t)->private_symbol)) >= base) {
    struct term *var = get_variable_term((-((t)->private_symbol)) - base);
    free_term(t);
    return var;
  }
  else {
    int i;
    for (i = 0; i < ((t)->arity); i++)
      ((t)->args[i]) = complex4_revar(((t)->args[i]), base);
    return t;
  }
}


decompiled_code:
double __fastcall clause_complexity(__int64 a1, int a2, int a3)
{
__int64 v4; // rbp
double v6; // [rsp+8h] [rbp-20h]

v4 = lits_to_term();
*(_QWORD *)&v6 = term_complexity(v4, a2, a3);
free_lits_to_term(v4);
return v6;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 v4; // rbp
double v6; // [rsp+8h] [rbp-20h]

v4 = lits_to_term();
*(_QWORD *)&v6 = term_complexity(v4, a2, a3);
free_lits_to_term(v4);
return v6;
}

original_code:
double clause_complexity(Literals lits, int func, int adjustment)
{
  Term t = lits_to_term(lits);
  double x = term_complexity(t, func, adjustment);
  free_lits_to_term(t);
  return x;
}

canonical_original_code:
double clause_complexity(struct literals *lits, int func, int adjustment)
{
  struct term *t = lits_to_term(lits);
  double x = term_complexity(t, func, adjustment);
  free_lits_to_term(t);
  return x;
}

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

variable_types: func int

variable_types: adjustment int

variable_types: x double

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


username

decompiled_code:
char *username()
{
__uid_t v0; // eax
struct passwd *v1; // rax
char *v2; // r8

v0 = getuid();
v1 = getpwuid(v0);
v2 = (char *)&unk_E0;
if ( v1 )
v2 = v1->pw_name;
return v2;
}

canonical_decompiled_code:
char *func0()
{
__uid_t v0; // eax
struct passwd *v1; // rax
char *v2; // r8

v0 = getuid();
v1 = getpwuid(v0);
v2 = (char *)&unk_E0;
if ( v1 )
v2 = v1->pw_name;
return v2;
}

original_code:
char *username(void)
{
  struct passwd *p;
  p = getpwuid(getuid());
  return(p ? p->pw_name : "???");
}

canonical_original_code:
char *username()
{
  struct passwd *p;
  p = getpwuid(getuid());
  return(p ? p->pw_name : "???");
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

return_type: char *


hostname

decompiled_code:
char *hostname()
{
if ( gethostname(host_0, 0x40uLL) )
strcpy(host_0, "???");
return host_0;
}

canonical_decompiled_code:
char *func1()
{
if ( gethostname(host_0, 0x40uLL) )
strcpy(host_0, "???");
return host_0;
}

original_code:
char *hostname(void)
{
  static char host[64];
  if (gethostname(host, 64) != 0)
    strcpy(host, "???");
  return(host);
}

canonical_original_code:
char *hostname()
{
  static char host[64];
  if (gethostname(host, 64) != 0)
    strcpy(host, "???");
  return(host);
}

variable_types:
host
char [64]


decompiled_code:
// attributes: thunk
__pid_t my_process_id(void)
{
return getpid();
}

canonical_decompiled_code:
__pid_t func2(void)
{
return getpid();
}

original_code:
int my_process_id(void)
{
  return getpid();
}

canonical_original_code:
int my_process_id()
{
  return getpid();
}


decompiled_code:
__int64 get_bits()
{
return 64LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 64LL;
}

original_code:
int get_bits(void)
{
  return sizeof(long) == 8 && sizeof(void *) == 8 ? 64 : 32;
}

canonical_original_code:
int get_bits()
{
  return sizeof(long) == 8 && sizeof(void *) == 8 ? 64 : 32;
}


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

result = get_cmem(14LL);
++Chunk_gets;
return result;
}

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

result = get_cmem(14LL);
++Chunk_gets;
return result;
}

original_code:
static
Chunk get_chunk(void)
{
  Chunk p = get_cmem(((sizeof(struct chunk))%(sizeof(void *)) == 0 ? (sizeof(struct chunk))/(sizeof(void *)) : (sizeof(struct chunk))/(sizeof(void *)) + 1));
  Chunk_gets++;
  return(p);
}

canonical_original_code:
static struct chunk *get_chunk()
{
  struct chunk *p = get_cmem(((sizeof(struct chunk))%(sizeof(void *)) == 0 ? (sizeof(struct chunk))/(sizeof(void *)) : (sizeof(struct chunk))/(sizeof(void *)) + 1));
  Chunk_gets++;
  return(p);
}

variable_types: struct chunk { char s[100]; struct chunk *next; } *


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

result = free_mem(a1, 14LL);
++Chunk_frees;
return result;
}

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

result = free_mem(a1, 14LL);
++Chunk_frees;
return result;
}

original_code:
static
void free_chunk(Chunk p)
{
  free_mem(p, ((sizeof(struct chunk))%(sizeof(void *)) == 0 ? (sizeof(struct chunk))/(sizeof(void *)) : (sizeof(struct chunk))/(sizeof(void *)) + 1));
  Chunk_frees++;
}

canonical_original_code:
static void free_chunk(struct chunk *p)
{
  free_mem(p, ((sizeof(struct chunk))%(sizeof(void *)) == 0 ? (sizeof(struct chunk))/(sizeof(void *)) : (sizeof(struct chunk))/(sizeof(void *)) + 1));
  Chunk_frees++;
}

user_defined_types: struct chunk { char s[100]; struct chunk *next; }


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

result = free_mem(a1, 2LL);
++String_buf_frees;
return result;
}

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

result = free_mem(a1, 2LL);
++String_buf_frees;
return result;
}

original_code:
static
void free_string_buf(String_buf p)
{
  free_mem(p, ((sizeof(struct string_buf))%(sizeof(void *)) == 0 ? (sizeof(struct string_buf))/(sizeof(void *)) : (sizeof(struct string_buf))/(sizeof(void *)) + 1));
  String_buf_frees++;
}

canonical_original_code:
static void free_string_buf(struct string_buf *p)
{
  free_mem(p, ((sizeof(struct string_buf))%(sizeof(void *)) == 0 ? (sizeof(struct string_buf))/(sizeof(void *)) : (sizeof(struct string_buf))/(sizeof(void *)) + 1));
  String_buf_frees++;
}

variable_types: struct string_buf { struct chunk { char s[100]; struct chunk *next; } *first; int size; } *

user_defined_types: struct string_buf { struct chunk *first; int size; }


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

result = get_cmem(2LL);
++String_buf_gets;
return result;
}

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

result = get_cmem(2LL);
++String_buf_gets;
return result;
}

original_code:
String_buf get_string_buf(void)
{
  String_buf p = get_cmem(((sizeof(struct string_buf))%(sizeof(void *)) == 0 ? (sizeof(struct string_buf))/(sizeof(void *)) : (sizeof(struct string_buf))/(sizeof(void *)) + 1));
  String_buf_gets++;
  return(p);
}

canonical_original_code:
struct string_buf *get_string_buf()
{
  struct string_buf *p = get_cmem(((sizeof(struct string_buf))%(sizeof(void *)) == 0 ? (sizeof(struct string_buf))/(sizeof(void *)) : (sizeof(struct string_buf))/(sizeof(void *)) + 1));
  String_buf_gets++;
  return(p);
}

return_type: struct string_buf { struct chunk { char s[100]; struct chunk *next; } *first; int size; } *


decompiled_code:
int p_strbuf_mem()
{
return fprint_strbuf_mem(stdout, 1);
}

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

original_code:
void p_strbuf_mem()
{
  fprint_strbuf_mem(stdout, 1);
}


decompiled_code:
int __fastcall p_sb(__int64 *a1)
{
fprint_sb(stdout, a1);
putchar(10);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func7(__int64 *a1)
{
func6(stdout, a1);
putchar(10);
return fflush(stdout);
}

original_code:
void p_sb(String_buf sb)
{
  fprint_sb(stdout, sb);
  printf("\n");
  fflush(stdout);
}

canonical_original_code:
void p_sb(struct string_buf *sb)
{
  fprint_sb(stdout, sb);
  printf("\n");
  fflush(stdout);
}


original_code:
void sb_append(String_buf sb, char *s)
{
  int i;
  int n = sb->size;
  Chunk last = sb->first;
  while (last != ((void *)0) && last->next != ((void *)0))
    last = last->next;
  for (i = 0; s[i] != '\0'; i++) {
    if (n % 100 == 0) {
      Chunk new = get_chunk();
      if (last != ((void *)0))
 last->next = new;
      else
 sb->first = new;
      last = new;
    }
    last->s[n % 100] = s[i];
    n++;
  }
  sb->size = n;
}

canonical_original_code:
void sb_append(struct string_buf *sb, char *s)
{
  int i;
  int n = sb->size;
  struct chunk *last = sb->first;
  while (last != ((void *)0) && last->next != ((void *)0))
    last = last->next;
  for (i = 0; s[i] != '\0'; i++) {
    if (n % 100 == 0) {
      struct chunk *new = get_chunk();
      if (last != ((void *)0))
 last->next = new;
      else
 sb->first = new;
      last = new;
    }
    last->s[n % 100] = s[i];
    n++;
  }
  sb->size = n;
}

variable_types:
s
char *

variable_types: n int


decompiled_code:
__int64 __fastcall init_string_buf(char *a1)
{
__int64 v1; // r12

v1 = get_string_buf();
sb_append(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
__int64 v1; // r12

v1 = func3();
func8(v1, a1);
return v1;
}

original_code:
String_buf init_string_buf(char *s)
{
  String_buf p = get_string_buf();
  sb_append(p, s);
  return(p);
}

canonical_original_code:
struct string_buf *init_string_buf(char *s)
{
  struct string_buf *p = get_string_buf();
  sb_append(p, s);
  return(p);
}


decompiled_code:
__int64 __fastcall sb_append_char(__int64 a1, char a2)
{
int v2; // er12
__int64 i; // rbx
int v4; // ebp
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
for ( i = *(_QWORD *)a1; ; i = *(_QWORD *)(i + 104) )
{
if ( !i )
{
v4 = v2 % 100;
if ( v2 % 100 )
sb_append_char_cold();
result = get_chunk();
*(_QWORD *)a1 = result;
i = result;
goto LABEL_7;
}
if ( !*(_QWORD *)(i + 104) )
break;
}
result = (unsigned int)(100 * (v2 / 100));
v4 = v2 % 100;
if ( !(v2 % 100) )
{
result = get_chunk();
*(_QWORD *)(i + 104) = result;
i = result;
}
LABEL_7:
*(_BYTE *)(i + v4) = a2;
*(_DWORD *)(a1 + 8) = v2 + 1;
return result;
}

original_code:
void sb_append_char(String_buf sb, char c)
{
  int n = sb->size;
  Chunk last = sb->first;
  while (last != ((void *)0) && last->next != ((void *)0))
    last = last->next;
  if (n % 100 == 0) {
    Chunk new = get_chunk();
    if (last != ((void *)0))
      last->next = new;
    else
      sb->first = new;
    last = new;
  }
  last->s[n % 100] = c;
  n++;
  sb->size = n;
}

canonical_original_code:
void sb_append_char(struct string_buf *sb, char c)
{
  int n = sb->size;
  struct chunk *last = sb->first;
  while (last != ((void *)0) && last->next != ((void *)0))
    last = last->next;
  if (n % 100 == 0) {
    struct chunk *new = get_chunk();
    if (last != ((void *)0))
      last->next = new;
    else
      sb->first = new;
    last = new;
  }
  last->s[n % 100] = c;
  n++;
  sb->size = n;
}

variable_types: c char


original_code:
void sb_replace_char(String_buf sb, int i, char c)
{
  if (i < 0 || i >= sb->size)
    return;
  else {
    Chunk h = sb->first;
    int j;
    for (j = 0; j < i / 100; j++)
      h = h->next;
    h->s[i % 100] = c;
  }
}

canonical_original_code:
void sb_replace_char(struct string_buf *sb, int i, char c)
{
  if (i < 0 || i >= sb->size)
    return;
  else {
    struct chunk *h = sb->first;
    int j;
    for (j = 0; j < i / 100; j++)
      h = h->next;
    h->s[i % 100] = c;
  }
}

variable_types: i int

variable_types: j int


original_code:
char sb_char(String_buf sb, int n)
{
  if (n < 0 || n >= sb->size)
    return '\0';
  else {
    Chunk h = sb->first;
    int i;
    for (i = 0; i < n / 100; i++)
      h = h->next;
    return h->s[n % 100];
  }
}

canonical_original_code:
char sb_char(struct string_buf *sb, int n)
{
  if (n < 0 || n >= sb->size)
    return '\0';
  else {
    struct chunk *h = sb->first;
    int i;
    for (i = 0; i < n / 100; i++)
      h = h->next;
    return h->s[n % 100];
  }
}

return_type: char


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

for ( i = 0; ; ++i )
{
result = sb_char(a2, i);
if ( !(_BYTE)result )
break;
sb_append_char(a1, result);
}
return result;
}

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

for ( i = 0; ; ++i )
{
result = func12(a2, i);
if ( !(_BYTE)result )
break;
func10(a1, result);
}
return result;
}

original_code:
void sb_cat_copy(String_buf sb1, String_buf sb2)
{
  int i;
  char c;
  for (i = 0; (c = sb_char(sb2, i)); i++)
    sb_append_char(sb1, c);
}

canonical_original_code:
void sb_cat_copy(struct string_buf *sb1, struct string_buf *sb2)
{
  int i;
  char c;
  for (i = 0; (c = sb_char(sb2, i)); i++)
    sb_append_char(sb1, c);
}


decompiled_code:
__int64 __fastcall zap_string_buf(__int64 *a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

v2 = *a1;
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 104);
free_chunk(v3);
}
return free_string_buf((__int64)a1);
}

original_code:
void zap_string_buf(String_buf sb)
{
  Chunk curr, prev;
  curr = sb->first;
  while (curr != ((void *)0)) {
    prev = curr;
    curr = curr->next;
    free_chunk(prev);
  }
  free_string_buf(sb);
}

canonical_original_code:
void zap_string_buf(struct string_buf *sb)
{
  struct chunk *curr; struct chunk *prev;
  curr = sb->first;
  while (curr != ((void *)0)) {
    prev = curr;
    curr = curr->next;
    free_chunk(prev);
  }
  free_string_buf(sb);
}


decompiled_code:
__int64 __fastcall sb_cat(__int64 a1, __int64 *a2)
{
sb_cat_copy(a1, a2);
return zap_string_buf(a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 *a2)
{
func13(a1, a2);
return func14(a2);
}

original_code:
void sb_cat(String_buf sb1, String_buf sb2)
{
  sb_cat_copy(sb1, sb2);
  zap_string_buf(sb2);
}

canonical_original_code:
void sb_cat(struct string_buf *sb1, struct string_buf *sb2)
{
  sb_cat_copy(sb1, sb2);
  zap_string_buf(sb2);
}


decompiled_code:
__int64 __fastcall sb_size(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int sb_size(String_buf sb)
{
  return sb->size;
}

canonical_original_code:
int sb_size(struct string_buf *sb)
{
  return sb->size;
}


decompiled_code:
void __fastcall sb_append_int(__int64 a1, unsigned int a2)
{
char *v2; // rax
__int64 v3; // [rsp+0h] [rbp-28h] BYREF

v2 = (char *)int_to_str(a2, &v3, 25LL);
sb_append(a1, v2);
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, unsigned int a2)
{
char *v2; // rax
__int64 v3; // [rsp+0h] [rbp-28h] BYREF

v2 = (char *)int_to_str(a2, &v3, 25LL);
func8(a1, v2);
}

original_code:
void sb_append_int(String_buf sb, int i)
{
  char s[25];
  sb_append(sb, int_to_str(i, s, 25));
}

canonical_original_code:
void sb_append_int(struct string_buf *sb, int i)
{
  char s[25];
  sb_append(sb, int_to_str(i, s, 25));
}

variable_types:
s
char [25]


original_code:
static
int nterm_id(Term t)
{
  int id = Sn_to_mace_sn[(-((t)->private_symbol))]->base;
  int mult = 1;
  int i;
  for (i = ((t)->arity)-1; i >= 0; i--) {
    if (((((t)->args[i]))->private_symbol >= 0))
      id += ((((t)->args[i]))->private_symbol) * mult;
    mult *= Domain_size;
  }
  return id;
}

canonical_original_code:
static int nterm_id(struct term *t)
{
  int id = Sn_to_mace_sn[(-((t)->private_symbol))]->base;
  int mult = 1;
  int i;
  for (i = ((t)->arity)-1; i >= 0; i--) {
    if (((((t)->args[i]))->private_symbol >= 0))
      id += ((((t)->args[i]))->private_symbol) * mult;
    mult *= Domain_size;
  }
  return id;
}

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

variable_types: mult int


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

v1 = *(unsigned int **)(Cells + 56LL * a1 + 16);
if ( v1 )
result = *v1;
else
result = 0xFFFFFFFFLL;
return result;
}

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

v1 = *(unsigned int **)(Cells + 56LL * a1 + 16);
if ( v1 )
result = *v1;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int id2val(int id)
{
  return (Cells[id].value == ((void *)0) ? -1 : ((Cells[id].value)->private_symbol));
}


decompiled_code:
// attributes: thunk
__int64 __fastcall f0_val(int a1)
{
return id2val(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return func0(a1);
}

original_code:
static
int f0_val(int base)
{
  int id = (base);
  return id2val(id);
}

variable_types: base int


decompiled_code:
__int64 __fastcall f1_val(int a1, int a2)
{
return id2val(a2 + a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return func0(a2 + a1);
}

original_code:
static
int f1_val(int base, int i)
{
  int id = (base) + (i);
  return id2val(id);
}


decompiled_code:
__int64 __fastcall f2_val(int a1, int a2, int a3)
{
return id2val(a1 + Domain_size * a2 + a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3)
{
return func0(a1 + Domain_size * a2 + a3);
}

original_code:
static
int f2_val(int base, int i, int j)
{
  int id = (base) + (i)*Domain_size + (j);
  return id2val(id);
}


decompiled_code:
__int64 __fastcall eterms_count(__int64 a1)
{
int v1; // eax
unsigned int v2; // er8

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
unsigned int v2; // er8

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

original_code:
static
int eterms_count(Term t)
{
  return (t == ((void *)0) ? 0 : 1 + eterms_count(t->u.vp));
}

canonical_original_code:
static int eterms_count(struct term *t)
{
  return (t == ((void *)0) ? 0 : 1 + eterms_count(t->u.vp));
}


decompiled_code:
void __fastcall p_model(int a1, double a2)
{
int v2; // ebx
unsigned int *v3; // rbp
const char *v4; // rsi
int v5; // eax
const char *v6; // rax
const char *v7; // r13
unsigned int v8; // esi
const char *v9; // r12
const char *v10; // r13
const char *v11; // r14
int v12; // er13
unsigned int v13; // er14
int i; // er12
__int64 v15; // r15
unsigned int *v16; // rax
unsigned int j; // er15
__int64 v18; // rsi
int v19; // er15
unsigned int v20; // er12
int v21; // er15
int v22; // eax
const char *v23; // r14
const char *v24; // r12
unsigned int v25; // er15
__int64 v26; // rsi
int v27; // er15
int v28; // er15
int v29; // eax
char *format; // [rsp+0h] [rbp-48h]

v2 = Domain_size;
if ( a1 )
{
print_separator(stdout, "MODEL", 1LL);
user_seconds();
printf("\n%% Model %d at %.2f seconds.\n", Total_models, a2);
v3 = (unsigned int *)Symbols;
if ( !Symbols )
goto LABEL_39;
while ( 1 )
{
while ( 1 )
{
LABEL_7:
v6 = (const char *)sn_to_str(*v3);
v7 = v6;
if ( v3[5] == 1 )
goto LABEL_6;
v8 = v3[2];
if ( !v8 )
break;
if ( v8 == 1 )
{
if ( v2 > 10 )
{
format = (char *)&unk_E6E;
v23 = (const char *)&unk_E66;
v24 = (const char *)&unk_E6A;
do
{
LABEL_41:
v25 = 0;
printf("\n %s :\n", v7);
printf(" ");
do
{
v26 = v25++;
printf(v24, v26);
}
while ( v2 != v25 );
v27 = 0;
printf("\n ---");
do
{
++v27;
printf(v23);
}
while ( v2 != v27 );
v28 = 0;
printf("\n ");
do
{
while ( 1 )
{
v29 = f1_val(v3[4], v28);
if ( v29 < 0 )
break;
++v28;
printf(v24, (unsigned int)v29);
if ( v2 == v28 )
goto LABEL_49;
}
++v28;
printf(format, (unsigned int)v29);
}
while ( v2 != v28 );
LABEL_49:
putchar(10);
}
while ( v2 > v2 + 1 );
goto LABEL_6;
}
if ( v2 > 0 )
{
format = " -";
v23 = "--";
v24 = "%2d";
goto LABEL_41;
}
}
else
{
if ( v8 != 2 )
{
v12 = int_power(Domain_size);
v13 = variable_style();
set_variable_style(2LL);
if ( v12 > 0 )
{
for ( i = 0; i != v12; ++i )
{
while ( 1 )
{
v15 = 56LL * (int)(i + v3[4]);
fwrite_term(stdout, *(_QWORD *)(Cells + v15 + 8));
v16 = *(unsigned int **)(Cells + v15 + 16);
if ( !v16 )
break;
++i;
printf(" = %d.\n", *v16);
if ( v12 == i )
goto LABEL_22;
}
puts(" = -.");
}
}
LABEL_22:
set_variable_style(v13);
goto LABEL_6;
}
if ( v2 > 10 )
{
printf("\n %s :\n", v6);
v9 = (const char *)&unk_E66;
printf(" |");
v10 = (const char *)&unk_E6A;
v11 = (const char *)&unk_E6E;
goto LABEL_24;
}
printf("\n %s :\n", v6);
printf(" |");
if ( v2 > 0 )
{
v9 = "--";
v10 = "%2d";
v11 = " -";
LABEL_24:
for ( j = 0; j != v2; ++j )
{
v18 = j;
printf(v10, v18);
}
v19 = 0;
printf("\n --+");
do
{
++v19;
printf(v9);
}
while ( v2 != v19 );
v20 = 0;
putchar(10);
do
{
v21 = 0;
printf("%5d |", v20);
do
{
while ( 1 )
{
v22 = f2_val(v3[4], v20, v21);
if ( v22 < 0 )
break;
++v21;
printf(v10, (unsigned int)v22);
if ( v2 == v21 )
goto LABEL_33;
}
++v21;
printf(v11, (unsigned int)v22);
}
while ( v2 != v21 );
LABEL_33:
++v20;
putchar(10);
}
while ( v2 != v20 );
goto LABEL_6;
}
printf("\n --+");
putchar(10);
}
LABEL_6:
v3 = (unsigned int *)*((_QWORD *)v3 + 3);
if ( !v3 )
goto LABEL_15;
}
v4 = v6;
v5 = f0_val(v3[4]);
if ( v5 >= 0 )
{
printf("\n %s : %d\n", v4, (unsigned int)v5);
goto LABEL_6;
}
printf("\n %s : -\n", v4);
v3 = (unsigned int *)*((_QWORD *)v3 + 3);
if ( !v3 )
{
LABEL_15:
if ( !a1 )
return;
LABEL_39:
print_separator(stdout, "end of model", 1LL);
return;
}
}
}
v3 = (unsigned int *)Symbols;
if ( Symbols )
goto LABEL_7;
}

canonical_decompiled_code:
void __fastcall func5(int a1, double a2)
{
int v2; // ebx
unsigned int *v3; // rbp
const char *v4; // rsi
int v5; // eax
const char *v6; // rax
const char *v7; // r13
unsigned int v8; // esi
const char *v9; // r12
const char *v10; // r13
const char *v11; // r14
int v12; // er13
unsigned int v13; // er14
int i; // er12
__int64 v15; // r15
unsigned int *v16; // rax
unsigned int j; // er15
__int64 v18; // rsi
int v19; // er15
unsigned int v20; // er12
int v21; // er15
int v22; // eax
const char *v23; // r14
const char *v24; // r12
unsigned int v25; // er15
__int64 v26; // rsi
int v27; // er15
int v28; // er15
int v29; // eax
char *format; // [rsp+0h] [rbp-48h]

v2 = Domain_size;
if ( a1 )
{
print_separator(stdout, "MODEL", 1LL);
user_seconds();
printf("\n%% Model %d at %.2f seconds.\n", Total_models, a2);
v3 = (unsigned int *)Symbols;
if ( !Symbols )
goto LABEL_39;
while ( 1 )
{
while ( 1 )
{
LABEL_7:
v6 = (const char *)sn_to_str(*v3);
v7 = v6;
if ( v3[5] == 1 )
goto LABEL_6;
v8 = v3[2];
if ( !v8 )
break;
if ( v8 == 1 )
{
if ( v2 > 10 )
{
format = (char *)&unk_E6E;
v23 = (const char *)&unk_E66;
v24 = (const char *)&unk_E6A;
do
{
LABEL_41:
v25 = 0;
printf("\n %s :\n", v7);
printf(" ");
do
{
v26 = v25++;
printf(v24, v26);
}
while ( v2 != v25 );
v27 = 0;
printf("\n ---");
do
{
++v27;
printf(v23);
}
while ( v2 != v27 );
v28 = 0;
printf("\n ");
do
{
while ( 1 )
{
v29 = func2(v3[4], v28);
if ( v29 < 0 )
break;
++v28;
printf(v24, (unsigned int)v29);
if ( v2 == v28 )
goto LABEL_49;
}
++v28;
printf(format, (unsigned int)v29);
}
while ( v2 != v28 );
LABEL_49:
putchar(10);
}
while ( v2 > v2 + 1 );
goto LABEL_6;
}
if ( v2 > 0 )
{
format = " -";
v23 = "--";
v24 = "%2d";
goto LABEL_41;
}
}
else
{
if ( v8 != 2 )
{
v12 = int_power(Domain_size);
v13 = variable_style();
set_variable_style(2LL);
if ( v12 > 0 )
{
for ( i = 0; i != v12; ++i )
{
while ( 1 )
{
v15 = 56LL * (int)(i + v3[4]);
fwrite_term(stdout, *(_QWORD *)(Cells + v15 + 8));
v16 = *(unsigned int **)(Cells + v15 + 16);
if ( !v16 )
break;
++i;
printf(" = %d.\n", *v16);
if ( v12 == i )
goto LABEL_22;
}
puts(" = -.");
}
}
LABEL_22:
set_variable_style(v13);
goto LABEL_6;
}
if ( v2 > 10 )
{
printf("\n %s :\n", v6);
v9 = (const char *)&unk_E66;
printf(" |");
v10 = (const char *)&unk_E6A;
v11 = (const char *)&unk_E6E;
goto LABEL_24;
}
printf("\n %s :\n", v6);
printf(" |");
if ( v2 > 0 )
{
v9 = "--";
v10 = "%2d";
v11 = " -";
LABEL_24:
for ( j = 0; j != v2; ++j )
{
v18 = j;
printf(v10, v18);
}
v19 = 0;
printf("\n --+");
do
{
++v19;
printf(v9);
}
while ( v2 != v19 );
v20 = 0;
putchar(10);
do
{
v21 = 0;
printf("%5d |", v20);
do
{
while ( 1 )
{
v22 = func3(v3[4], v20, v21);
if ( v22 < 0 )
break;
++v21;
printf(v10, (unsigned int)v22);
if ( v2 == v21 )
goto LABEL_33;
}
++v21;
printf(v11, (unsigned int)v22);
}
while ( v2 != v21 );
LABEL_33:
++v20;
putchar(10);
}
while ( v2 != v20 );
goto LABEL_6;
}
printf("\n --+");
putchar(10);
}
LABEL_6:
v3 = (unsigned int *)*((_QWORD *)v3 + 3);
if ( !v3 )
goto LABEL_15;
}
v4 = v6;
v5 = func1(v3[4]);
if ( v5 >= 0 )
{
printf("\n %s : %d\n", v4, (unsigned int)v5);
goto LABEL_6;
}
printf("\n %s : -\n", v4);
v3 = (unsigned int *)*((_QWORD *)v3 + 3);
if ( !v3 )
{
LABEL_15:
if ( !a1 )
return;
LABEL_39:
print_separator(stdout, "end of model", 1LL);
return;
}
}
}
v3 = (unsigned int *)Symbols;
if ( Symbols )
goto LABEL_7;
}

original_code:
void p_model(BOOL print_head)
{
  Symbol_data p;
  int n = Domain_size;
  if (print_head) {
    print_separator(stdout, "MODEL", TRUE);
    printf("\n%% Model %d at %.2f seconds.\n",
    Total_models, user_seconds());
  }
  for (p = Symbols; p != ((void *)0); p = p->next) {
    char *name = sn_to_str(p->sn);
    if (p->attribute != EQUALITY_SYMBOL) {
      if (p->arity == 0) {
 int v = f0_val(p->base);
 if (v < 0)
   printf("\n %s : -\n", name);
 else
   printf("\n %s : %d\n", name, v);
      }
      else if (p->arity == 1) {
 char *s1 = n <= 10 ? "%2d" : "%3d";
 char *s2 = n <= 10 ? "--" : "---";
 char *s3 = n <= 10 ? " -" : "  -";
 int i;
 for (i = 0; i < n; i++) {
   printf("\n %s :\n", name);
   printf("       ");
   for (i = 0; i < n; i++)
     printf(s1, i);
   printf("\n    ---");
   for (i = 0; i < n; i++)
     printf(s2);
   printf("\n       ");
   for (i = 0; i < n; i++) {
     int v = f1_val(p->base, i);
     if (v < 0)
       printf(s3);
     else
       printf(s1, v);
   }
   printf("\n");
 }
      }
      else if (p->arity == 2) {
 char *s1 = n <= 10 ? "%2d" : "%3d";
 char *s2 = n <= 10 ? "--" : "---";
 char *s3 = n <= 10 ? " -" : "  -";
 int i, j;
 printf("\n %s :\n", name);
 printf("      |");
 for (i = 0; i < n; i++)
   printf(s1, i);
 printf("\n    --+");
 for (i = 0; i < n; i++)
   printf(s2);
 printf("\n");
 for (i = 0; i < n; i++) {
   printf("%5d |", i);
   for (j = 0; j < n; j++) {
     int v = f2_val(p->base, i, j);
     if (v < 0)
       printf(s3);
     else
       printf(s1, v);
   }
   printf("\n");
 }
      }
      else {
 int n = int_power(Domain_size, p->arity);
 int i;
 Variable_style save_style = variable_style();
 set_variable_style(INTEGER_STYLE);
 for (i = 0; i < n; i++) {
   int id = p->base + i;
   fwrite_term(stdout, Cells[id].eterm);
   if (Cells[id].value == ((void *)0))
     printf(" = -.\n");
   else
     printf(" = %d.\n", ((Cells[id].value)->private_symbol));
 }
 set_variable_style(save_style);
      }
    }
  }
  if (print_head)
    print_separator(stdout, "end of model", TRUE);
}

canonical_original_code:
void p_model(enum BOOL print_head)
{
  struct symbol_data *p;
  int n = Domain_size;
  if (print_head) {
    print_separator(stdout, "MODEL", TRUE);
    printf("\n%% Model %d at %.2f seconds.\n",
    Total_models, user_seconds());
  }
  for (p = Symbols; p != ((void *)0); p = p->next) {
    char *name = sn_to_str(p->sn);
    if (p->attribute != EQUALITY_SYMBOL) {
      if (p->arity == 0) {
 int v = f0_val(p->base);
 if (v < 0)
   printf("\n %s : -\n", name);
 else
   printf("\n %s : %d\n", name, v);
      }
      else if (p->arity == 1) {
 char *s1 = n <= 10 ? "%2d" : "%3d";
 char *s2 = n <= 10 ? "--" : "---";
 char *s3 = n <= 10 ? " -" : "  -";
 int i;
 for (i = 0; i < n; i++) {
   printf("\n %s :\n", name);
   printf("       ");
   for (i = 0; i < n; i++)
     printf(s1, i);
   printf("\n    ---");
   for (i = 0; i < n; i++)
     printf(s2);
   printf("\n       ");
   for (i = 0; i < n; i++) {
     int v = f1_val(p->base, i);
     if (v < 0)
       printf(s3);
     else
       printf(s1, v);
   }
   printf("\n");
 }
      }
      else if (p->arity == 2) {
 char *s1 = n <= 10 ? "%2d" : "%3d";
 char *s2 = n <= 10 ? "--" : "---";
 char *s3 = n <= 10 ? " -" : "  -";
 int i; int j;
 printf("\n %s :\n", name);
 printf("      |");
 for (i = 0; i < n; i++)
   printf(s1, i);
 printf("\n    --+");
 for (i = 0; i < n; i++)
   printf(s2);
 printf("\n");
 for (i = 0; i < n; i++) {
   printf("%5d |", i);
   for (j = 0; j < n; j++) {
     int v = f2_val(p->base, i, j);
     if (v < 0)
       printf(s3);
     else
       printf(s1, v);
   }
   printf("\n");
 }
      }
      else {
 int n = int_power(Domain_size, p->arity);
 int i;
 enum Variable_style save_style = variable_style();
 set_variable_style(INTEGER_STYLE);
 for (i = 0; i < n; i++) {
   int id = p->base + i;
   fwrite_term(stdout, Cells[id].eterm);
   if (Cells[id].value == ((void *)0))
     printf(" = -.\n");
   else
     printf(" = %d.\n", ((Cells[id].value)->private_symbol));
 }
 set_variable_style(save_style);
      }
    }
  }
  if (print_head)
    print_separator(stdout, "end of model", TRUE);
}

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

variable_types:
name
char *

variable_types: v int

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


decompiled_code:
__int64 interp_term()
{
__int64 v0; // rax
unsigned int *v1; // rbp
__int64 v2; // r13
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rdi
__int64 *v6; // r15
__int64 v7; // rax
int v8; // esi
int v9; // er15
__int64 v10; // r14
int v11; // er15
__int64 v12; // rax
__int64 v14; // rbx
unsigned int *v15; // rax
const char *v16; // rdi
unsigned int v17; // eax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rbp
unsigned int v21; // eax

v0 = get_nil_term();
v1 = (unsigned int *)Symbols;
v2 = v0;
if ( Symbols )
{
do
{
while ( v1[5] == 1 )
{
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
if ( !v1 )
goto LABEL_16;
}
v3 = get_rigid_term_dangerously(*v1, v1[2]);
if ( (int)v1[2] > 0 )
{
v4 = 0LL;
do
{
v5 = (unsigned int)v4;
v6 = (__int64 *)(*(_QWORD *)(v3 + 8) + 8 * v4++);
v7 = get_variable_term(v5);
v8 = v1[2];
*v6 = v7;
}
while ( v8 > (int)v4 );
}
v9 = int_power(Domain_size);
v10 = get_nil_term();
v11 = v9 - 1;
if ( v11 >= 0 )
{
do
{
v14 = 56LL * (int)(v11 + v1[4]);
v15 = *(unsigned int **)(Cells + v14 + 16);
if ( !v15 )
{
fatal_error("interp_term, incomplete interpretation");
v15 = *(unsigned int **)(Cells + v14 + 16);
}
v12 = nat_to_term(*v15);
v10 = listterm_cons(v12, v10);
}
while ( v11-- != 0 );
}
v16 = "relation";
if ( !v1[3] )
v16 = "function";
v17 = str_to_sn(v16, 2LL);
v18 = build_binary_term(v17, v3, v10);
v19 = listterm_cons(v18, v2);
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
v2 = v19;
}
while ( v1 );
}
LABEL_16:
v20 = nat_to_term(Domain_size);
v21 = str_to_sn("interpretation", 2LL);
return build_binary_term(v21, v20, v2);
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
unsigned int *v1; // rbp
__int64 v2; // r13
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rdi
__int64 *v6; // r15
__int64 v7; // rax
int v8; // esi
int v9; // er15
__int64 v10; // r14
int v11; // er15
__int64 v12; // rax
__int64 v14; // rbx
unsigned int *v15; // rax
const char *v16; // rdi
unsigned int v17; // eax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rbp
unsigned int v21; // eax

v0 = get_nil_term();
v1 = (unsigned int *)Symbols;
v2 = v0;
if ( Symbols )
{
do
{
while ( v1[5] == 1 )
{
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
if ( !v1 )
goto LABEL_16;
}
v3 = get_rigid_term_dangerously(*v1, v1[2]);
if ( (int)v1[2] > 0 )
{
v4 = 0LL;
do
{
v5 = (unsigned int)v4;
v6 = (__int64 *)(*(_QWORD *)(v3 + 8) + 8 * v4++);
v7 = get_variable_term(v5);
v8 = v1[2];
*v6 = v7;
}
while ( v8 > (int)v4 );
}
v9 = int_power(Domain_size);
v10 = get_nil_term();
v11 = v9 - 1;
if ( v11 >= 0 )
{
do
{
v14 = 56LL * (int)(v11 + v1[4]);
v15 = *(unsigned int **)(Cells + v14 + 16);
if ( !v15 )
{
fatal_error("interp_term, incomplete interpretation");
v15 = *(unsigned int **)(Cells + v14 + 16);
}
v12 = nat_to_term(*v15);
v10 = listterm_cons(v12, v10);
}
while ( v11-- != 0 );
}
v16 = "relation";
if ( !v1[3] )
v16 = "function";
v17 = str_to_sn(v16, 2LL);
v18 = build_binary_term(v17, v3, v10);
v19 = listterm_cons(v18, v2);
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
v2 = v19;
}
while ( v1 );
}
LABEL_16:
v20 = nat_to_term(Domain_size);
v21 = str_to_sn("interpretation", 2LL);
return build_binary_term(v21, v20, v2);
}

original_code:
Term interp_term(void)
{
  Symbol_data s;
  Term symlist = get_nil_term();
  for (s = Symbols; s != ((void *)0); s = s->next) {
    if (s->attribute != EQUALITY_SYMBOL) {
      int i, n;
      Term entry, symterm, tableterm;
      symterm = get_rigid_term_dangerously(s->sn, s->arity);
      for (i = 0; i < s->arity; i++)
 ((symterm)->args[i]) = get_variable_term(i);
      n = int_power(Domain_size, s->arity);
      tableterm = get_nil_term();
      for (i = n-1; i >= 0; i--) {
 int id = s->base + i;
 Term it;
 if (Cells[id].value == ((void *)0))
   fatal_error("interp_term, incomplete interpretation");
 it = nat_to_term(((Cells[id].value)->private_symbol));
 tableterm = listterm_cons(it, tableterm);
      }
      entry = build_binary_term(str_to_sn(s->type == FUNCTION ? "function" : "relation", 2),
    symterm, tableterm);
      symlist = listterm_cons(entry, symlist);
    }
  }
  return build_binary_term(str_to_sn("interpretation", 2),
      nat_to_term(Domain_size),
      symlist);
}

canonical_original_code:
struct term *interp_term()
{
  struct symbol_data *s;
  struct term *symlist = get_nil_term();
  for (s = Symbols; s != ((void *)0); s = s->next) {
    if (s->attribute != EQUALITY_SYMBOL) {
      int i; int n;
      struct term *entry; struct term *symterm; struct term *tableterm;
      symterm = get_rigid_term_dangerously(s->sn, s->arity);
      for (i = 0; i < s->arity; i++)
 ((symterm)->args[i]) = get_variable_term(i);
      n = int_power(Domain_size, s->arity);
      tableterm = get_nil_term();
      for (i = n-1; i >= 0; i--) {
 int id = s->base + i;
 struct term *it;
 if (Cells[id].value == ((void *)0))
   fatal_error("interp_term, incomplete interpretation");
 it = nat_to_term(((Cells[id].value)->private_symbol));
 tableterm = listterm_cons(it, tableterm);
      }
      entry = build_binary_term(str_to_sn(s->type == FUNCTION ? "function" : "relation", 2),
    symterm, tableterm);
      symlist = listterm_cons(entry, symlist);
    }
  }
  return build_binary_term(str_to_sn("interpretation", 2),
      nat_to_term(Domain_size),
      symlist);
}

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:
int __fastcall p_matom(__int64 a1)
{
int v1; // edx
int result; // eax

if ( a1 )
{
v1 = *(unsigned __int8 *)(a1 + 5);
if ( _bittest(&v1, Negation_flag) )
{
if ( Eq_sn + *(_DWORD *)a1 )
{
printf("~(");
fwrite_term(stdout, a1);
putchar(41);
}
else
{
fwrite_term(stdout, **(_QWORD **)(a1 + 8));
printf(" != ");
fwrite_term(stdout, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
}
result = puts(".");
}
else
{
fwrite_term(stdout, a1);
result = puts(".");
}
}
else
{
printf("(NULL)");
result = puts(".");
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
int v1; // edx
int result; // eax

if ( a1 )
{
v1 = *(unsigned __int8 *)(a1 + 5);
if ( _bittest(&v1, Negation_flag) )
{
if ( Eq_sn + *(_DWORD *)a1 )
{
printf("~(");
fwrite_term(stdout, a1);
putchar(41);
}
else
{
fwrite_term(stdout, **(_QWORD **)(a1 + 8));
printf(" != ");
fwrite_term(stdout, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL));
}
result = puts(".");
}
else
{
fwrite_term(stdout, a1);
result = puts(".");
}
}
else
{
printf("(NULL)");
result = puts(".");
}
return result;
}

original_code:
void p_matom(Term atom)
{
  if (atom == ((void *)0))
    printf("(NULL)");
  else if (!(((atom->private_flags & 1 << Negation_flag))))
    fwrite_term(stdout, atom);
  else if (((-(((Term) atom)->private_symbol)) == Eq_sn)){
    fwrite_term(stdout, ((atom)->args[0]));
    printf(" != ");
    fwrite_term(stdout, ((atom)->args[1]));
  }
  else {
    printf("~(");
    fwrite_term(stdout, atom);
    printf(")");
  }
  printf(".\n");
}

canonical_original_code:
void p_matom(struct term *atom)
{
  if (atom == ((void *)0))
    printf("(NULL)");
  else if (!(((atom->private_flags & 1 << Negation_flag))))
    fwrite_term(stdout, atom);
  else if (((-(((struct term *) atom)->private_symbol)) == Eq_sn)){
    fwrite_term(stdout, ((atom)->args[0]));
    printf(" != ");
    fwrite_term(stdout, ((atom)->args[1]));
  }
  else {
    printf("~(");
    fwrite_term(stdout, atom);
    printf(")");
  }
  printf(".\n");
}


decompiled_code:
int __fastcall p_mclause(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // r12
int v4; // edx

printf(
"numlits=%d, active=%ld, subsumed=%d: ",
*(unsigned int *)(a1 + 20),
*(_QWORD *)(a1 + 24),
*(unsigned int *)(a1 + 16));
result = *(_DWORD *)(a1 + 20);
if ( result > 0 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
v4 = *(unsigned __int8 *)(v3 + 5);
if ( _bittest(&v4, Negation_flag) )
{
printf("~(");
fwrite_term(stdout, v3);
putchar(41);
if ( *(_DWORD *)(a1 + 20) - 1 <= (int)v2 )
goto LABEL_7;
LABEL_4:
++v2;
result = printf(" | ");
if ( *(_DWORD *)(a1 + 20) <= (int)v2 )
return result;
}
else
{
fwrite_term(stdout, *(_QWORD *)(*(_QWORD *)a1 + 8 * v2));
if ( *(_DWORD *)(a1 + 20) - 1 > (int)v2 )
goto LABEL_4;
LABEL_7:
++v2;
result = puts(".");
if ( *(_DWORD *)(a1 + 20) <= (int)v2 )
return result;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // r12
int v4; // edx

printf(
"numlits=%d, active=%ld, subsumed=%d: ",
*(unsigned int *)(a1 + 20),
*(_QWORD *)(a1 + 24),
*(unsigned int *)(a1 + 16));
result = *(_DWORD *)(a1 + 20);
if ( result > 0 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
v4 = *(unsigned __int8 *)(v3 + 5);
if ( _bittest(&v4, Negation_flag) )
{
printf("~(");
fwrite_term(stdout, v3);
putchar(41);
if ( *(_DWORD *)(a1 + 20) - 1 <= (int)v2 )
goto LABEL_7;
LABEL_4:
++v2;
result = printf(" | ");
if ( *(_DWORD *)(a1 + 20) <= (int)v2 )
return result;
}
else
{
fwrite_term(stdout, *(_QWORD *)(*(_QWORD *)a1 + 8 * v2));
if ( *(_DWORD *)(a1 + 20) - 1 > (int)v2 )
goto LABEL_4;
LABEL_7:
++v2;
result = puts(".");
if ( *(_DWORD *)(a1 + 20) <= (int)v2 )
return result;
}
}
}
return result;
}

original_code:
void p_mclause(Mclause c)
{
  int i;
  printf("numlits=%d, active=%ld, subsumed=%d: ",
  c->numlits, c->u.active, c->subsumed);
  for (i = 0; i < c->numlits; i++) {
    Term atom = ((c)->lits[i]);
    if (!(((atom->private_flags & 1 << Negation_flag))))
      fwrite_term(stdout, atom);
    else {
      printf("~(");
      fwrite_term(stdout, atom);
      printf(")");
    }
    if (i < c->numlits-1)
      printf(" | ");
    else
      printf(".\n");
  }
}

canonical_original_code:
void p_mclause(struct mclause *c)
{
  int i;
  printf("numlits=%d, active=%ld, subsumed=%d: ",
  c->numlits, c->u.active, c->subsumed);
  for (i = 0; i < c->numlits; i++) {
    struct term *atom = ((c)->lits[i]);
    if (!(((atom->private_flags & 1 << Negation_flag))))
      fwrite_term(stdout, atom);
    else {
      printf("~(");
      fwrite_term(stdout, atom);
      printf(")");
    }
    if (i < c->numlits-1)
      printf(" | ");
    else
      printf(".\n");
  }
}

variable_types: struct mclause { struct term { int private_symbol; unsigned char arity; unsigned char private_flags; struct term **args; void *container; union { unsigned int id; void *vp; } u; } **lits; struct mclause *next; enum BOOL { FALSE=0, TRUE=1 } subsumed; int numlits; union { long active; void *for_padding_only; } u; } *

user_defined_types: struct mclause { struct term **lits; struct mclause *next; enum BOOL subsumed; int numlits; union { long active; void *for_padding_only; } u; }


decompiled_code:
int p_eterms()
{
int result; // eax
__int64 v1; // r12
int v2; // ebp
__int64 v3; // rsi
unsigned int v4; // er13
__int64 v5; // rsi
__int64 v6; // rbx

puts("\n------- Cells --------");
result = Number_of_cells;
if ( Number_of_cells > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(Cells + v1 + 24);
result = eterms_count(v3);
v4 = result;
if ( result > 0 )
break;
++v2;
v1 += 56LL;
if ( Number_of_cells <= v2 )
return result;
}
fwrite_term(stdout, v3);
printf(": %d occ, id=%d, val=", v4, (unsigned int)v2);
v5 = *(_QWORD *)(Cells + v1 + 16);
if ( v5 )
fwrite_term(stdout, v5);
else
printf("NULL");
v6 = 0LL;
printf(", pvals=");
while ( (int)id_to_domain_size((unsigned int)v2) > (int)v6 )
{
if ( *(_QWORD *)(*(_QWORD *)(Cells + v1 + 32) + 8 * v6) )
printf("%2d", (unsigned int)v6);
else
printf(" -");
++v6;
}
++v2;
v1 += 56LL;
result = putchar(10);
}
while ( Number_of_cells > v2 );
}
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax
__int64 v1; // r12
int v2; // ebp
__int64 v3; // rsi
unsigned int v4; // er13
__int64 v5; // rsi
__int64 v6; // rbx

puts("\n------- Cells --------");
result = Number_of_cells;
if ( Number_of_cells > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(Cells + v1 + 24);
result = func4(v3);
v4 = result;
if ( result > 0 )
break;
++v2;
v1 += 56LL;
if ( Number_of_cells <= v2 )
return result;
}
fwrite_term(stdout, v3);
printf(": %d occ, id=%d, val=", v4, (unsigned int)v2);
v5 = *(_QWORD *)(Cells + v1 + 16);
if ( v5 )
fwrite_term(stdout, v5);
else
printf("NULL");
v6 = 0LL;
printf(", pvals=");
while ( (int)id_to_domain_size((unsigned int)v2) > (int)v6 )
{
if ( *(_QWORD *)(*(_QWORD *)(Cells + v1 + 32) + 8 * v6) )
printf("%2d", (unsigned int)v6);
else
printf(" -");
++v6;
}
++v2;
v1 += 56LL;
result = putchar(10);
}
while ( Number_of_cells > v2 );
}
return result;
}

original_code:
void p_eterms(void)
{
  int i, j;
  printf("\n------- Cells --------\n");
  for (i = 0; i < Number_of_cells; i++) {
    int n = eterms_count(Cells[i].occurrences);
    if (n > 0) {
      fwrite_term(stdout, Cells[i].occurrences);
      printf(": %d occ, id=%d, val=", n, i);
      if (Cells[i].value == ((void *)0))
 printf("NULL");
      else
 fwrite_term(stdout, Cells[i].value);
      printf(", pvals=");
      for (j = 0; j < id_to_domain_size(i); j++) {
 if (Cells[i].possible[j] == ((void *)0))
   printf(" -");
 else
   printf("%2d", j);
      }
      printf("\n");
    }
  }
}

canonical_original_code:
void p_eterms()
{
  int i; int j;
  printf("\n------- Cells --------\n");
  for (i = 0; i < Number_of_cells; i++) {
    int n = eterms_count(Cells[i].occurrences);
    if (n > 0) {
      fwrite_term(stdout, Cells[i].occurrences);
      printf(": %d occ, id=%d, val=", n, i);
      if (Cells[i].value == ((void *)0))
 printf("NULL");
      else
 fwrite_term(stdout, Cells[i].value);
      printf(", pvals=");
      for (j = 0; j < id_to_domain_size(i); j++) {
 if (Cells[i].possible[j] == ((void *)0))
   printf(" -");
 else
   printf("%2d", j);
      }
      printf("\n");
    }
  }
}


decompiled_code:
__int64 __fastcall p_stats(double a1)
{
print_separator(stdout, "STATISTICS", 1LL);
printf("\nFor domain size %d.\n\n", Domain_size);
clock_seconds(Mace4_clock);
printf("Current CPU time: %.2f seconds ", a1);
user_seconds();
printf("(total CPU time: %.2f seconds).\n", a1);
printf("Ground clauses: seen=%u, kept=%u.\n", Mstats[8], Mstats[9]);
printf(
"Selections=%u, assignments=%u, propagations=%u, current_models=%u.\n",
Mstats[1],
Mstats[2],
Mstats[3],
Mstats[0]);
printf("Rewrite_terms=%u, rewrite_bools=%u, indexes=%u.\n", Mstats[5], Mstats[6], Mstats[7]);
printf("Rules_from_neg_clauses=%u, cross_offs=%d.\n", Mstats[10], Mstats[4]);
return print_separator(stdout, "end of statistics", 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(double a1)
{
print_separator(stdout, "STATISTICS", 1LL);
printf("\nFor domain size %d.\n\n", Domain_size);
clock_seconds(Mace4_clock);
printf("Current CPU time: %.2f seconds ", a1);
user_seconds();
printf("(total CPU time: %.2f seconds).\n", a1);
printf("Ground clauses: seen=%u, kept=%u.\n", Mstats[8], Mstats[9]);
printf(
"Selections=%u, assignments=%u, propagations=%u, current_models=%u.\n",
Mstats[1],
Mstats[2],
Mstats[3],
Mstats[0]);
printf("Rewrite_terms=%u, rewrite_bools=%u, indexes=%u.\n", Mstats[5], Mstats[6], Mstats[7]);
printf("Rules_from_neg_clauses=%u, cross_offs=%d.\n", Mstats[10], Mstats[4]);
return print_separator(stdout, "end of statistics", 1LL);
}

original_code:
void p_stats(void)
{
  print_separator(stdout, "STATISTICS", TRUE);
  printf("\nFor domain size %d.\n\n",Domain_size);
  printf("Current CPU time: %.2f seconds ", clock_seconds(Mace4_clock));
  printf("(total CPU time: %.2f seconds).\n",user_seconds());
  printf("Ground clauses: seen=%u, kept=%u.\n",
  Mstats.ground_clauses_seen, Mstats.ground_clauses_kept);
  printf("Selections=%u, assignments=%u, propagations=%u, current_models=%u.\n",
  Mstats.selections, Mstats.assignments, Mstats.propagations, Mstats.current_models);
  printf("Rewrite_terms=%u, rewrite_bools=%u, indexes=%u.\n",
  Mstats.rewrite_terms, Mstats.rewrite_bools, Mstats.indexes);
  printf("Rules_from_neg_clauses=%u, cross_offs=%d.\n",
  Mstats.rules_from_neg, Mstats.cross_offs);
  print_separator(stdout, "end of statistics", TRUE);
}

canonical_original_code:
void p_stats()
{
  print_separator(stdout, "STATISTICS", TRUE);
  printf("\nFor domain size %d.\n\n",Domain_size);
  printf("Current CPU time: %.2f seconds ", clock_seconds(Mace4_clock));
  printf("(total CPU time: %.2f seconds).\n",user_seconds());
  printf("Ground clauses: seen=%u, kept=%u.\n",
  Mstats.ground_clauses_seen, Mstats.ground_clauses_kept);
  printf("Selections=%u, assignments=%u, propagations=%u, current_models=%u.\n",
  Mstats.selections, Mstats.assignments, Mstats.propagations, Mstats.current_models);
  printf("Rewrite_terms=%u, rewrite_bools=%u, indexes=%u.\n",
  Mstats.rewrite_terms, Mstats.rewrite_bools, Mstats.indexes);
  printf("Rules_from_neg_clauses=%u, cross_offs=%d.\n",
  Mstats.rules_from_neg, Mstats.cross_offs);
  print_separator(stdout, "end of statistics", TRUE);
}


decompiled_code:
__int64 p_mem()
{
unsigned int v0; // eax

puts("\n------------- memory usage (for entire run) -------------------");
v0 = megs_malloced();
printf("\nTotal malloced: %d megabytes\n", v0);
fprint_strbuf_mem(stdout, 1LL);
fprint_parse_mem(stdout, 0LL);
fprint_glist_mem(stdout, 0LL);
fprint_term_mem(stdout, 0LL);
fprint_topform_mem(stdout, 0LL);
fprint_clist_mem(stdout, 0LL);
fprint_mclause_mem(stdout, 0LL);
fprint_mstate_mem(stdout, 0LL);
fprint_estack_mem(stdout, 0LL);
return memory_report(stdout);
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax

puts("\n------------- memory usage (for entire run) -------------------");
v0 = megs_malloced();
printf("\nTotal malloced: %d megabytes\n", v0);
fprint_strbuf_mem(stdout, 1LL);
fprint_parse_mem(stdout, 0LL);
fprint_glist_mem(stdout, 0LL);
fprint_term_mem(stdout, 0LL);
fprint_topform_mem(stdout, 0LL);
fprint_clist_mem(stdout, 0LL);
fprint_mclause_mem(stdout, 0LL);
fprint_mstate_mem(stdout, 0LL);
fprint_estack_mem(stdout, 0LL);
return memory_report(stdout);
}

original_code:
void p_mem(void)
{
  printf("\n------------- memory usage (for entire run) -------------------\n");
  printf("\nTotal malloced: %d megabytes\n", megs_malloced());
  fprint_strbuf_mem(stdout, 1);
  fprint_parse_mem(stdout, 0);
  fprint_glist_mem(stdout, 0);
  fprint_term_mem(stdout, 0);
  fprint_topform_mem(stdout, 0);
  fprint_clist_mem(stdout, 0);
  fprint_mclause_mem(stdout, 0);
  fprint_mstate_mem(stdout, 0);
  fprint_estack_mem(stdout, 0);
  memory_report(stdout);
}

canonical_original_code:
void p_mem()
{
  printf("\n------------- memory usage (for entire run) -------------------\n");
  printf("\nTotal malloced: %d megabytes\n", megs_malloced());
  fprint_strbuf_mem(stdout, 1);
  fprint_parse_mem(stdout, 0);
  fprint_glist_mem(stdout, 0);
  fprint_term_mem(stdout, 0);
  fprint_topform_mem(stdout, 0);
  fprint_clist_mem(stdout, 0);
  fprint_mclause_mem(stdout, 0);
  fprint_mstate_mem(stdout, 0);
  fprint_estack_mem(stdout, 0);
  memory_report(stdout);
}


decompiled_code:
void reset_current_stats()
{
*(_QWORD *)Mstats = 0LL;
*(_QWORD *)&Mstats[2] = 0LL;
*(_QWORD *)&Mstats[4] = 0LL;
*(_QWORD *)&Mstats[6] = 0LL;
*(_QWORD *)&Mstats[8] = 0LL;
*(_QWORD *)&Mstats[10] = 0LL;
*(_QWORD *)&Mstats[12] = 0LL;
*(_QWORD *)&Mstats[14] = 0LL;
*(_QWORD *)&Mstats[16] = 0LL;
*(_QWORD *)&Mstats[18] = 0LL;
*(_QWORD *)&Mstats[20] = 0LL;
Mstats[22] = 0;
}

canonical_decompiled_code:
void func13()
{
*(_QWORD *)Mstats = 0LL;
*(_QWORD *)&Mstats[2] = 0LL;
*(_QWORD *)&Mstats[4] = 0LL;
*(_QWORD *)&Mstats[6] = 0LL;
*(_QWORD *)&Mstats[8] = 0LL;
*(_QWORD *)&Mstats[10] = 0LL;
*(_QWORD *)&Mstats[12] = 0LL;
*(_QWORD *)&Mstats[14] = 0LL;
*(_QWORD *)&Mstats[16] = 0LL;
*(_QWORD *)&Mstats[18] = 0LL;
*(_QWORD *)&Mstats[20] = 0LL;
Mstats[22] = 0;
}

original_code:
void reset_current_stats(void)
{
  Mstats.current_models = 0;
  Mstats.selections = 0;
  Mstats.assignments = 0;
  Mstats.propagations = 0;
  Mstats.cross_offs = 0;
  Mstats.rewrite_terms = 0;
  Mstats.rewrite_bools = 0;
  Mstats.indexes = 0;
  Mstats.ground_clauses_seen = 0;
  Mstats.ground_clauses_kept = 0;
  Mstats.rules_from_neg = 0;
  Mstats.neg_elim_attempts = 0;
  Mstats.neg_elim_agone = 0;
  Mstats.neg_elim_egone = 0;
  Mstats.neg_assign_attempts = 0;
  Mstats.neg_assign_agone = 0;
  Mstats.neg_assign_egone = 0;
  Mstats.neg_near_assign_attempts = 0;
  Mstats.neg_near_assign_agone = 0;
  Mstats.neg_near_assign_egone = 0;
  Mstats.neg_near_elim_attempts = 0;
  Mstats.neg_near_elim_agone = 0;
  Mstats.neg_near_elim_egone = 0;
}

canonical_original_code:
void reset_current_stats()
{
  Mstats.current_models = 0;
  Mstats.selections = 0;
  Mstats.assignments = 0;
  Mstats.propagations = 0;
  Mstats.cross_offs = 0;
  Mstats.rewrite_terms = 0;
  Mstats.rewrite_bools = 0;
  Mstats.indexes = 0;
  Mstats.ground_clauses_seen = 0;
  Mstats.ground_clauses_kept = 0;
  Mstats.rules_from_neg = 0;
  Mstats.neg_elim_attempts = 0;
  Mstats.neg_elim_agone = 0;
  Mstats.neg_elim_egone = 0;
  Mstats.neg_assign_attempts = 0;
  Mstats.neg_assign_agone = 0;
  Mstats.neg_assign_egone = 0;
  Mstats.neg_near_assign_attempts = 0;
  Mstats.neg_near_assign_agone = 0;
  Mstats.neg_near_assign_egone = 0;
  Mstats.neg_near_elim_attempts = 0;
  Mstats.neg_near_elim_agone = 0;
  Mstats.neg_near_elim_egone = 0;
}


decompiled_code:
__int64 __fastcall char_array_ident(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

original_code:
static
int char_array_ident(char *s, char *t, int n)
{
  int i;
  for (i = 0; i < n; i++)
    if (s[i] != t[i])
      return 0;
  return 1;
}

variable_types:
t
char *


decompiled_code:
__int64 __fastcall char_array_find(__int64 a1, int a2, __int64 a3, int a4)
{
__int64 v7; // r8
unsigned int v8; // er12
__int64 v9; // r8
int v10; // er9

if ( a2 > a4 )
return 0xFFFFFFFFLL;
v7 = 0LL;
while ( 1 )
{
v8 = v7;
if ( (unsigned int)char_array_ident(a3 + v7, a1, a2) )
break;
v7 = v9 + 1;
if ( v10 < (int)v7 )
return 0xFFFFFFFFLL;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3, int a4)
{
__int64 v7; // r8
unsigned int v8; // er12
__int64 v9; // r8
int v10; // er9

if ( a2 > a4 )
return 0xFFFFFFFFLL;
v7 = 0LL;
while ( 1 )
{
v8 = v7;
if ( (unsigned int)func0(a3 + v7, a1, a2) )
break;
v7 = v9 + 1;
if ( v10 < (int)v7 )
return 0xFFFFFFFFLL;
}
return v8;
}

original_code:
static
int char_array_find(char *b, int nb, char *a, int na)
{
  if (nb <= na) {
    int i;
    for (i = 0; i <= na - nb; i++) {
      if (char_array_ident(a+i, b, nb))
 return i;
    }
  }
  return -1;
}

variable_types:
b
char *

variable_types: nb int

variable_types:
a
char *


decompiled_code:
double __fastcall complexity_1(const char *a1)
{
int v1; // eax
double result; // xmm0_8
int v3; // er14
int v4; // ebx
int v5; // ebp
int v6; // eax
int v7; // ebp
int v8; // er15
int v9; // [rsp+Ch] [rbp-4Ch]
int v10; // [rsp+10h] [rbp-48h]
int v11; // [rsp+14h] [rbp-44h]
int v12; // [rsp+18h] [rbp-40h]

v1 = strlen(a1);
result = 0.0;
v12 = v1;
if ( v1 > 2 )
{
v10 = v1 - 1;
if ( v1 != 3 )
{
v11 = 0;
v3 = v1;
v4 = 2;
do
{
v5 = v3 - v4;
if ( v3 - v4 > v4 )
v5 = v4;
if ( v5 <= 1 )
goto LABEL_17;
v6 = v5 + 1;
v7 = 2;
v8 = 0;
v9 = v6;
do
{
if ( (int)char_array_find((__int64)&a1[v4], v7, (__int64)a1, v3) < v4 )
v8 = v7;
++v7;
}
while ( v9 != v7 );
if ( v8 )
{
v11 += v8;
v4 += v8;
}
else
{
LABEL_17:
++v4;
}
}
while ( v4 < v10 );
result = (double)v11;
}
result = result / (double)(v12 - 2);
}
return result;
}

original_code:
static
double complexity_1(char *s)
{
  int length = strlen(s);
  int min = 2;
  int index = min;
  int total = 0;
  if (length < 3)
    return 0.0;
  while (index <= length-2) {
    int flen = 0;
    int maxlook = (length - index);
    int window;
    if (maxlook > index)
      maxlook = index;
    for (window = min; window < maxlook+1; window++) {
      char *tocheck = s + index;
      int ind = char_array_find(tocheck, window, s, length);
      if (ind < index)
 flen = window;
    }
    if (flen == 0)
      index += 1;
    else {
      index += flen;
      total += flen;
    }
  }
  return ((double) total) / (length-2);
}

variable_types:
s
char *

variable_types: length int

variable_types: min int

variable_types: index int

variable_types: total int

variable_types: flen int

variable_types: maxlook int

variable_types: window int

variable_types:
tocheck
char *

variable_types: ind int


decompiled_code:
double test1()
{
char *v0; // rbp
double v2; // [rsp+8h] [rbp-10h]

v0 = (char *)term_to_string();
v2 = complexity_1(v0);
free(v0);
return v2;
}

canonical_decompiled_code:
double func3()
{
char *v0; // rbp
double v2; // [rsp+8h] [rbp-10h]

v0 = (char *)term_to_string();
v2 = func2(v0);
free(v0);
return v2;
}

original_code:
static
double test1(Term t)
{
  char *s = term_to_string(t);
  double c = complexity_1(s);
  free(s);
  return c;
}

canonical_original_code:
static double test1(struct term *t)
{
  char *s = term_to_string(t);
  double c = complexity_1(s);
  free(s);
  return c;
}

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: c double


decompiled_code:
double __fastcall call_weight(__int64 a1)
{
if ( (unsigned int)str_ident(a1, "test1") )
return test1();
fatal_error("call_weight, unknown function");
return 0.0;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1)
{
if ( (unsigned int)str_ident(a1, "test1") )
return func3();
fatal_error("call_weight, unknown function");
return 0.0;
}

original_code:
double call_weight(char *func, Term t)
{
  if (str_ident(func, "test1"))
    return test1(t);
  else {
    fatal_error("call_weight, unknown function");
    return 0;
  }
}

canonical_original_code:
double call_weight(char *func, struct term *t)
{
  if (str_ident(func, "test1"))
    return test1(t);
  else {
    fatal_error("call_weight, unknown function");
    return 0;
  }
}

variable_types:
func
char *


decompiled_code:
__int64 demod_attempts()
{
return (unsigned int)Demod_attempts;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)Demod_attempts;
}

original_code:
int demod_attempts()
{
  return Demod_attempts;
}


decompiled_code:
__int64 demod_rewrites()
{
return (unsigned int)Demod_rewrites;
}

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

original_code:
int demod_rewrites()
{
  return Demod_rewrites;
}


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

if ( Maximal_flag != -1 )
fatal_error("init_maximal, called more than once");
Maximal_flag = claim_term_flag();
Maximal_signed_flag = claim_term_flag();
result = claim_term_flag();
Selected_flag = result;
return result;
}

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

if ( Maximal_flag != -1 )
fatal_error("init_maximal, called more than once");
Maximal_flag = claim_term_flag();
Maximal_signed_flag = claim_term_flag();
result = claim_term_flag();
Selected_flag = result;
return result;
}

original_code:
void init_maximal(void)
{
  if (Maximal_flag != -1)
    fatal_error("init_maximal, called more than once");
  Maximal_flag = claim_term_flag();
  Maximal_signed_flag = claim_term_flag();
  Selected_flag = claim_term_flag();
}

canonical_original_code:
void init_maximal()
{
  if (Maximal_flag != -1)
    fatal_error("init_maximal, called more than once");
  Maximal_flag = claim_term_flag();
  Maximal_signed_flag = claim_term_flag();
  Selected_flag = claim_term_flag();
}


decompiled_code:
__int64 __fastcall max_lit_test(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( !a1 )
return 1LL;
v2 = a1;
do
{
if ( a2 != v2 && (unsigned int)greater_literals_isra_0(*(_DWORD **)(v2 + 8), *(_DWORD **)(a2 + 8)) )
return 0LL;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return 1LL;
}

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

if ( !a1 )
return 1LL;
v2 = a1;
do
{
if ( a2 != v2 && (unsigned int)func0(*(_DWORD **)(v2 + 8), *(_DWORD **)(a2 + 8)) )
return 0LL;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return 1LL;
}

original_code:
BOOL max_lit_test(Literals lits, Literals lit)
{
  Literals l2 = lits;
  BOOL maximal = TRUE;
  while (l2 && maximal) {
    if (lit != l2 && greater_literals(l2, lit))
      maximal = FALSE;
    else
      l2 = l2->next;
  }
  return maximal;
}

canonical_original_code:
enum BOOL max_lit_test(struct literals *lits, struct literals *lit)
{
  struct literals *l2 = lits;
  enum BOOL maximal = TRUE;
  while (l2 && maximal) {
    if (lit != l2 && greater_literals(l2, lit))
      maximal = FALSE;
    else
      l2 = l2->next;
  }
  return maximal;
}

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

variable_types:
lit
struct literals *

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


decompiled_code:
__int64 __fastcall max_signed_lit_test(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( !a1 )
return 1LL;
v2 = a1;
do
{
if ( a2 != v2
&& *(_DWORD *)a2 == *(_DWORD *)v2
&& (unsigned int)greater_literals_isra_0(*(_DWORD **)(v2 + 8), *(_DWORD **)(a2 + 8)) )
{
return 0LL;
}
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return 1LL;
}

original_code:
BOOL max_signed_lit_test(Literals lits, Literals lit)
{
  Literals l2 = lits;
  BOOL maximal = TRUE;
  while (l2 && maximal) {
    if (lit != l2 && lit->sign == l2->sign && greater_literals(l2, lit))
      maximal = FALSE;
    else
      l2 = l2->next;
  }
  return maximal;
}

canonical_original_code:
enum BOOL max_signed_lit_test(struct literals *lits, struct literals *lit)
{
  struct literals *l2 = lits;
  enum BOOL maximal = TRUE;
  while (l2 && maximal) {
    if (lit != l2 && lit->sign == l2->sign && greater_literals(l2, lit))
      maximal = FALSE;
    else
      l2 = l2->next;
  }
  return maximal;
}


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

if ( Maximal_flag == -1 )
fatal_error("mark_maximal_literals, init_maximal() was not called");
if ( a1 )
{
v1 = a1;
while ( 1 )
{
if ( (unsigned int)max_lit_test(a1, v1) )
{
term_flag_set(*(_QWORD *)(v1 + 8), (unsigned int)Maximal_flag);
if ( (unsigned int)max_signed_lit_test(a1, v1) )
goto LABEL_9;
LABEL_6:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return;
}
else
{
if ( !(unsigned int)max_signed_lit_test(a1, v1) )
goto LABEL_6;
LABEL_9:
term_flag_set(*(_QWORD *)(v1 + 8), (unsigned int)Maximal_signed_flag);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return;
}
}
}
}

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

if ( Maximal_flag == -1 )
fatal_error("mark_maximal_literals, init_maximal() was not called");
if ( a1 )
{
v1 = a1;
while ( 1 )
{
if ( (unsigned int)func2(a1, v1) )
{
term_flag_set(*(_QWORD *)(v1 + 8), (unsigned int)Maximal_flag);
if ( (unsigned int)func3(a1, v1) )
goto LABEL_9;
LABEL_6:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return;
}
else
{
if ( !(unsigned int)func3(a1, v1) )
goto LABEL_6;
LABEL_9:
term_flag_set(*(_QWORD *)(v1 + 8), (unsigned int)Maximal_signed_flag);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return;
}
}
}
}

original_code:
void mark_maximal_literals(Literals lits)
{
  Literals lit;
  if (Maximal_flag == -1)
    fatal_error("mark_maximal_literals, init_maximal() was not called");
  for (lit = lits; lit; lit = lit->next) {
    if (max_lit_test(lits, lit))
      term_flag_set(lit->atom, Maximal_flag);
    if (max_signed_lit_test(lits, lit))
      term_flag_set(lit->atom, Maximal_signed_flag);
  }
}

canonical_original_code:
void mark_maximal_literals(struct literals *lits)
{
  struct literals *lit;
  if (Maximal_flag == -1)
    fatal_error("mark_maximal_literals, init_maximal() was not called");
  for (lit = lits; lit; lit = lit->next) {
    if (max_lit_test(lits, lit))
      term_flag_set(lit->atom, Maximal_flag);
    if (max_signed_lit_test(lits, lit))
      term_flag_set(lit->atom, Maximal_signed_flag);
  }
}


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

if ( a3 )
result = max_lit_test(a1, a2);
else
result = term_flag(*(_QWORD *)(a2 + 8), (unsigned int)Maximal_flag);
return result;
}

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

if ( a3 )
result = func2(a1, a2);
else
result = term_flag(*(_QWORD *)(a2 + 8), (unsigned int)Maximal_flag);
return result;
}

original_code:
BOOL maximal_literal(Literals lits, Literals lit, int check)
{
  if (check == FLAG_CHECK)
    return term_flag(lit->atom, Maximal_flag);
  else
    return max_lit_test(lits, lit);
}

canonical_original_code:
enum BOOL maximal_literal(struct literals *lits, struct literals *lit, int check)
{
  if (check == FLAG_CHECK)
    return term_flag(lit->atom, Maximal_flag);
  else
    return max_lit_test(lits, lit);
}

variable_types: check int


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

if ( a3 )
result = max_signed_lit_test(a1, a2);
else
result = term_flag(*(_QWORD *)(a2 + 8), (unsigned int)Maximal_signed_flag);
return result;
}

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

if ( a3 )
result = func3(a1, a2);
else
result = term_flag(*(_QWORD *)(a2 + 8), (unsigned int)Maximal_signed_flag);
return result;
}

original_code:
BOOL maximal_signed_literal(Literals lits, Literals lit, int check)
{
  if (check == FLAG_CHECK)
    return term_flag(lit->atom, Maximal_signed_flag);
  else
    return max_signed_lit_test(lits, lit);
}

canonical_original_code:
enum BOOL maximal_signed_literal(struct literals *lits, struct literals *lit, int check)
{
  if (check == FLAG_CHECK)
    return term_flag(lit->atom, Maximal_signed_flag);
  else
    return max_signed_lit_test(lits, lit);
}


decompiled_code:
__int64 __fastcall number_of_maximal_literals(__int64 a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
int v4; // eax

if ( !a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
v4 = maximal_literal(a1, v2, a2);
v2 = *(_QWORD *)(v2 + 16);
v3 -= (v4 == 0) - 1;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
int v4; // eax

if ( !a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
v4 = func5(a1, v2, a2);
v2 = *(_QWORD *)(v2 + 16);
v3 -= (v4 == 0) - 1;
}
while ( v2 );
return v3;
}

original_code:
int number_of_maximal_literals(Literals lits, int check)
{
  int n = 0;
  Literals lit;
  for (lit = lits; lit; lit = lit->next) {
    if (maximal_literal(lits, lit, check))
      n++;
  }
  return n;
}

canonical_original_code:
int number_of_maximal_literals(struct literals *lits, int check)
{
  int n = 0;
  struct literals *lit;
  for (lit = lits; lit; lit = lit->next) {
    if (maximal_literal(lits, lit, check))
      n++;
  }
  return n;
}

variable_types: n int


decompiled_code:
__int64 __fastcall mark_selected_literal(__int64 a1)
{
return term_flag_set(*(_QWORD *)(a1 + 8), (unsigned int)Selected_flag);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return term_flag_set(*(_QWORD *)(a1 + 8), (unsigned int)Selected_flag);
}

original_code:
void mark_selected_literal(Literals lit)
{
  term_flag_set(lit->atom, Selected_flag);
}

canonical_original_code:
void mark_selected_literal(struct literals *lit)
{
  term_flag_set(lit->atom, Selected_flag);
}


decompiled_code:
void __fastcall mark_selected_literals(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( Selected_flag == -1 )
fatal_error("mark_selected_literals, init_maximal() was not called");
if ( a1 )
{
v2 = a1;
do
{
while ( *(_DWORD *)v2
|| !(unsigned int)str_ident(a2, "all_negative")
&& (!(unsigned int)str_ident(a2, "max_negative") || !(unsigned int)maximal_signed_literal(a1, v2, 0)) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return;
}
mark_selected_literal(v2);
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( Selected_flag == -1 )
fatal_error("mark_selected_literals, init_maximal() was not called");
if ( a1 )
{
v2 = a1;
do
{
while ( *(_DWORD *)v2
|| !(unsigned int)str_ident(a2, "all_negative")
&& (!(unsigned int)str_ident(a2, "max_negative") || !(unsigned int)func6(a1, v2, 0)) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return;
}
func8(v2);
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
}

original_code:
void mark_selected_literals(Literals lits, char *selection)
{
  Literals lit;
  if (Selected_flag == -1)
    fatal_error("mark_selected_literals, init_maximal() was not called");
  for (lit = lits; lit; lit = lit->next) {
    if (!lit->sign) {
      if (str_ident(selection, "all_negative"))
 mark_selected_literal(lit);
      else if (str_ident(selection, "max_negative")) {
 if (maximal_signed_literal(lits, lit, FLAG_CHECK))
   mark_selected_literal(lit);
      }
    }
  }
}

canonical_original_code:
void mark_selected_literals(struct literals *lits, char *selection)
{
  struct literals *lit;
  if (Selected_flag == -1)
    fatal_error("mark_selected_literals, init_maximal() was not called");
  for (lit = lits; lit; lit = lit->next) {
    if (!lit->sign) {
      if (str_ident(selection, "all_negative"))
 mark_selected_literal(lit);
      else if (str_ident(selection, "max_negative")) {
 if (maximal_signed_literal(lits, lit, FLAG_CHECK))
   mark_selected_literal(lit);
      }
    }
  }
}

variable_types:
selection
char *


decompiled_code:
__int64 __fastcall selected_literal(__int64 a1)
{
return term_flag(*(_QWORD *)(a1 + 8), (unsigned int)Selected_flag);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return term_flag(*(_QWORD *)(a1 + 8), (unsigned int)Selected_flag);
}

original_code:
BOOL selected_literal(Literals lit)
{
  return term_flag(lit->atom, Selected_flag);
}

canonical_original_code:
enum BOOL selected_literal(struct literals *lit)
{
  return term_flag(lit->atom, Selected_flag);
}


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

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

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

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

original_code:
BOOL exists_selected_literal(Literals lits)
{
  Literals lit;
  for (lit = lits; lit; lit = lit->next)
    if (selected_literal(lit))
      return TRUE;
  return FALSE;
}

canonical_original_code:
enum BOOL exists_selected_literal(struct literals *lits)
{
  struct literals *lit;
  for (lit = lits; lit; lit = lit->next)
    if (selected_literal(lit))
      return TRUE;
  return FALSE;
}


decompiled_code:
void __fastcall copy_selected_literal_marks(__int64 a1, __int64 a2)
{
if ( a1 && a2 )
{
copy_selected_literal_marks(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
if ( (unsigned int)selected_literal(a1) )
mark_selected_literal(a2);
}
}

original_code:
void copy_selected_literal_marks(Literals a, Literals b)
{
  if (!a || !b)
    return;
  else {
    copy_selected_literal_marks(a->next, b->next);
    if (selected_literal(a))
      mark_selected_literal(b);
  }
}

canonical_original_code:
void copy_selected_literal_marks(struct literals *a, struct literals *b)
{
  if (!a || !b)
    return;
  else {
    copy_selected_literal_marks(a->next, b->next);
    if (selected_literal(a))
      mark_selected_literal(b);
  }
}

variable_types:
b
struct literals *


decompiled_code:
_QWORD *ibuf_init()
{
_QWORD *v0; // r12
void *v1; // rax
_QWORD *result; // rax

v0 = malloc(0x18uLL);
v1 = malloc(0x27100uLL);
*v0 = 0LL;
v0[2] = v1;
result = v0;
*((_DWORD *)v0 + 2) = 40000;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
void *v1; // rax
_QWORD *result; // rax

v0 = malloc(0x18uLL);
v1 = malloc(0x27100uLL);
*v0 = 0LL;
v0[2] = v1;
result = v0;
*((_DWORD *)v0 + 2) = 40000;
return result;
}

original_code:
Ibuffer ibuf_init(void)
{
  Ibuffer ibuf = malloc(sizeof(struct ibuffer));
  ibuf->buf = malloc(40000 * sizeof(int));
  ibuf->size = 40000;
  ibuf->write_position = 0;
  ibuf->read_position = 0;
  return ibuf;
}

canonical_original_code:
struct ibuffer *ibuf_init()
{
  struct ibuffer *ibuf = malloc(sizeof(struct ibuffer));
  ibuf->buf = malloc(40000 * sizeof(int));
  ibuf->size = 40000;
  ibuf->write_position = 0;
  ibuf->read_position = 0;
  return ibuf;
}

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


decompiled_code:
void __fastcall ibuf_free(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void ibuf_free(Ibuffer ibuf)
{
  free(ibuf->buf);
  free(ibuf);
}

canonical_original_code:
void ibuf_free(struct ibuffer *ibuf)
{
  free(ibuf->buf);
  free(ibuf);
}

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


decompiled_code:
__int64 __fastcall ibuf_write(int *a1, int a2)
{
__int64 result; // rax
__int64 v5; // rsi
_DWORD *v6; // rbp
_DWORD *v7; // rax
__int64 v8; // rcx
_DWORD *v9; // rdi
__int64 i; // rax

result = *a1;
v5 = (unsigned int)a1[2];
if ( (int)result >= (int)v5 )
{
printf("ibuf_write, increasing buf size from %d to %d\n", v5, (unsigned int)(2 * v5));
v7 = malloc(8LL * (_DWORD)v5);
v8 = a1[2];
v9 = (_DWORD *)*((_QWORD *)a1 + 2);
v6 = v7;
if ( (int)v8 > 0 )
{
for ( i = 0LL; i != v8; ++i )
v6[i] = v9[i];
}
free(v9);
*((_QWORD *)a1 + 2) = v6;
result = *a1;
a1[2] = 2 * v5;
}
else
{
v6 = (_DWORD *)*((_QWORD *)a1 + 2);
}
v6[result] = a2;
++*a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, int a2)
{
__int64 result; // rax
__int64 v5; // rsi
_DWORD *v6; // rbp
_DWORD *v7; // rax
__int64 v8; // rcx
_DWORD *v9; // rdi
__int64 i; // rax

result = *a1;
v5 = (unsigned int)a1[2];
if ( (int)result >= (int)v5 )
{
printf("ibuf_write, increasing buf size from %d to %d\n", v5, (unsigned int)(2 * v5));
v7 = malloc(8LL * (_DWORD)v5);
v8 = a1[2];
v9 = (_DWORD *)*((_QWORD *)a1 + 2);
v6 = v7;
if ( (int)v8 > 0 )
{
for ( i = 0LL; i != v8; ++i )
v6[i] = v9[i];
}
free(v9);
*((_QWORD *)a1 + 2) = v6;
result = *a1;
a1[2] = 2 * v5;
}
else
{
v6 = (_DWORD *)*((_QWORD *)a1 + 2);
}
v6[result] = a2;
++*a1;
return result;
}

original_code:
void ibuf_write(Ibuffer ibuf, int i)
{
  if (ibuf->write_position >= ibuf->size) {
    int size2 = ibuf->size * 2;
    int *buf2, i;
    printf("ibuf_write, increasing buf size from %d to %d\n",
    ibuf->size, size2);
    buf2 = malloc(size2 * sizeof(int));
    for (i = 0; i < ibuf->size; i++)
      buf2[i] = ibuf->buf[i];
    free(ibuf->buf);
    ibuf->buf = buf2;
    ibuf->size = size2;
  }
  ibuf->buf[ibuf->write_position] = i;
  ibuf->write_position++;
}

canonical_original_code:
void ibuf_write(struct ibuffer *ibuf, int i)
{
  if (ibuf->write_position >= ibuf->size) {
    int size2 = ibuf->size * 2;
    int *buf2; int i;
    printf("ibuf_write, increasing buf size from %d to %d\n",
    ibuf->size, size2);
    buf2 = malloc(size2 * sizeof(int));
    for (i = 0; i < ibuf->size; i++)
      buf2[i] = ibuf->buf[i];
    free(ibuf->buf);
    ibuf->buf = buf2;
    ibuf->size = size2;
  }
  ibuf->buf[ibuf->write_position] = i;
  ibuf->write_position++;
}

variable_types: i int


decompiled_code:
__int64 __fastcall ibuf_write_block(int *a1, int *a2, int a3)
{
__int64 v3; // r12
int *v4; // rbx
int v5; // esi
__int64 result; // rax

if ( a3 > 0 )
{
v3 = (__int64)&a2[a3 - 1 + 1];
v4 = a2;
do
{
v5 = *v4++;
result = ibuf_write(a1, v5);
}
while ( v4 != (int *)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, int *a2, int a3)
{
__int64 v3; // r12
int *v4; // rbx
int v5; // esi
__int64 result; // rax

if ( a3 > 0 )
{
v3 = (__int64)&a2[a3 - 1 + 1];
v4 = a2;
do
{
v5 = *v4++;
result = func2(a1, v5);
}
while ( v4 != (int *)v3 );
}
return result;
}

original_code:
void ibuf_write_block(Ibuffer ibuf, int *a, int n)
{
  int i;
  for (i = 0; i < n; i++)
    ibuf_write(ibuf, a[i]);
}

canonical_original_code:
void ibuf_write_block(struct ibuffer *ibuf, int *a, int n)
{
  int i;
  for (i = 0; i < n; i++)
    ibuf_write(ibuf, a[i]);
}

variable_types:
a
int *