decompiled_code:
void __fastcall Arena_dispose(__int64 *a1)
{
if ( !a1 || !*a1 )
Except_raise(&Assert_Failed, "src/arena.c", 47LL);
Arena_free(*a1);
free((void *)*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(__int64 *a1)
{
if ( !a1 || !*a1 )
Except_raise(&Assert_Failed, "src/arena.c", 47LL);
func2(*a1);
free((void *)*a1);
*a1 = 0LL;
}

original_code:
void Arena_dispose(Arena_T *ap) {
 ((void)((ap && *ap)||(Except_raise(&(Assert_Failed), "src/arena.c", 47),0)));
 Arena_free(*ap);
 free(*ap);
 *ap = ((void *)0);
}

canonical_original_code:
void Arena_dispose(struct Arena_T **ap) {
 ((void)((ap && *ap)||(Except_raise(&(Assert_Failed), "src/arena.c", 47),0)));
 Arena_free(*ap);
 free(*ap);
 *ap = ((void *)0);
}

variable_types: struct Arena_T { struct Arena_T *prev; char *avail; char *limit; } **


decompiled_code:
void __fastcall __noreturn Except_raise(const char **a1, const char *a2, int a3)
{
__int64 v4; // rdi

v4 = Except_stack;
if ( a1 )
{
if ( Except_stack )
{
*(_QWORD *)(Except_stack + 224) = a1;
*(_QWORD *)(v4 + 208) = a2;
*(_DWORD *)(v4 + 216) = a3;
Except_stack = *(_QWORD *)v4;
longjmp((struct __jmp_buf_tag *)(v4 + 8), 1);
}
fwrite("Uncaught exception", 1uLL, 0x12uLL, stderr);
if ( *a1 )
fprintf(stderr, " %s", *a1);
else
fprintf(stderr, " at 0x%p", a1);
if ( a2 )
{
if ( a3 > 0 )
fprintf(stderr, " raised at %s:%d\n", a2, (unsigned int)a3);
}
fwrite("aborting...\n", 1uLL, 0xCuLL, stderr);
fflush(stderr);
abort();
}
Except_raise(&Assert_Failed, "src/except.c", 19LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char **a1, const char *a2, int a3)
{
__int64 v4; // rdi

v4 = Except_stack;
if ( a1 )
{
if ( Except_stack )
{
*(_QWORD *)(Except_stack + 224) = a1;
*(_QWORD *)(v4 + 208) = a2;
*(_DWORD *)(v4 + 216) = a3;
Except_stack = *(_QWORD *)v4;
longjmp((struct __jmp_buf_tag *)(v4 + 8), 1);
}
fwrite("Uncaught exception", 1uLL, 0x12uLL, stderr);
if ( *a1 )
fprintf(stderr, " %s", *a1);
else
fprintf(stderr, " at 0x%p", a1);
if ( a2 )
{
if ( a3 > 0 )
fprintf(stderr, " raised at %s:%d\n", a2, (unsigned int)a3);
}
fwrite("aborting...\n", 1uLL, 0xCuLL, stderr);
fflush(stderr);
abort();
}
func0(&Assert_Failed, "src/except.c", 19LL);
}

original_code:
void Except_raise(const Except_T *e, const char *file,
 int line) {
 Except_Frame *p = Except_stack;
 ((void)((e)||(Except_raise(&(Assert_Failed), "src/except.c", 19),0)));
 if (p == ((void *)0)) {
  fprintf(stderr, "Uncaught exception");
  if (e->reason)
   fprintf(stderr, " %s", e->reason);
  else
   fprintf(stderr, " at 0x%p", e);
  if (file && line > 0)
   fprintf(stderr, " raised at %s:%d\n", file, line);
  fprintf(stderr, "aborting...\n");
  fflush(stderr);
  abort();
 }
 p->exception = e;
 p->file = file;
 p->line = line;
 Except_stack = Except_stack->prev;
 longjmp(p->env, Except_raised);
}

canonical_original_code:
void Except_raise(struct Except_T *e, char *file, int line) {
 struct Except_Frame *p = Except_stack;
 ((void)((e)||(Except_raise(&(Assert_Failed), "src/except.c", 19),0)));
 if (p == ((void *)0)) {
  fprintf(stderr, "Uncaught exception");
  if (e->reason)
   fprintf(stderr, " %s", e->reason);
  else
   fprintf(stderr, " at 0x%p", e);
  if (file && line > 0)
   fprintf(stderr, " raised at %s:%d\n", file, line);
  fprintf(stderr, "aborting...\n");
  fflush(stderr);
  abort();
 }
 p->exception = e;
 p->file = file;
 p->line = line;
 Except_stack = Except_stack->prev;
 longjmp(p->env, Except_raised);
}

variable_types:
e
struct Except_T { char *reason; } *

variable_types:
file
char *

variable_types: line int

variable_types: struct Except_Frame { struct Except_Frame *prev; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } env[1]; char *file; int line; struct Except_T { char *reason; } *exception; } *

return_type: void

user_defined_types: struct Except_Frame { struct Except_Frame *prev; struct __jmp_buf_tag env[1]; char *file; int line; struct Except_T *exception; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code:
int Arith_max(int x, int y) {
 return x > y ? x : y;
}

variable_types: x int

variable_types: y int

return_type: int


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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
int Arith_min(int x, int y) {
 return x > y ? y : x;
}


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

if ( a1 < 0 == a2 < 0 || !(a1 % a2) )
result = (unsigned int)(a1 / a2);
else
result = (unsigned int)(a1 / a2 - 1);
return result;
}

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

if ( a1 < 0 == a2 < 0 || !(a1 % a2) )
result = (unsigned int)(a1 / a2);
else
result = (unsigned int)(a1 / a2 - 1);
return result;
}

original_code:
int Arith_div(int x, int y) {
 if (-13/5 == -2
 && (x < 0) != (y < 0) && x%y != 0)
  return x/y - 1;
 else
  return x/y;
}


decompiled_code:
__int64 __fastcall Arith_mod(int a1, int a2)
{
unsigned int v2; // edx

if ( a1 < 0 == a2 < 0 || !(a1 % a2) )
v2 = a1 % a2;
else
v2 = a2 + a1 % a2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
unsigned int v2; // edx

if ( a1 < 0 == a2 < 0 || !(a1 % a2) )
v2 = a1 % a2;
else
v2 = a2 + a1 % a2;
return v2;
}

original_code:
int Arith_mod(int x, int y) {
 if (-13/5 == -2
 && (x < 0) != (y < 0) && x%y != 0)
  return x%y + y;
 else
  return x%y;
}


decompiled_code:
// attributes: thunk
__int64 __fastcall Arith_floor(int a1, int a2)
{
return Arith_div(a1, a2);
}

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

original_code:
int Arith_floor(int x, int y) {
 return Arith_div(x, y);
}


decompiled_code:
__int64 __fastcall Arith_ceiling(int a1, int a2)
{
return (unsigned int)Arith_div(a1, a2) - ((a1 % a2 == 0) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
return (unsigned int)func2(a1, a2) - ((a1 % a2 == 0) - 1);
}

original_code:
int Arith_ceiling(int x, int y) {
 return Arith_div(x, y) + (x%y != 0);
}


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

result = Mem_alloc(16LL, "src/stack.c", 16LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
return result;
}

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

result = Mem_alloc(16LL, "src/stack.c", 16LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
return result;
}

original_code:
Stack_T Stack_new(void) {
 Stack_T stk;
 ((stk) = Mem_alloc(((long)sizeof *(stk)), "src/stack.c", 16));
 stk->count = 0;
 stk->head = ((void *)0);
 return stk;
}

canonical_original_code:
struct Stack_T *Stack_new() {
 struct Stack_T *stk;
 ((stk) = Mem_alloc(((long)sizeof *(stk)), "src/stack.c", 16));
 stk->count = 0;
 stk->head = ((void *)0);
 return stk;
}

variable_types: struct Stack_T { int count; struct elem { void *x; struct elem *link; } *head; } *

user_defined_types: struct Stack_T { int count; struct elem *head; }


decompiled_code:
_BOOL8 __fastcall Stack_empty(_DWORD *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/stack.c", 22LL);
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/stack.c", 22LL);
return *a1 == 0;
}

original_code:
int Stack_empty(Stack_T stk) {
 ((void)((stk)||(Except_raise(&(Assert_Failed), "src/stack.c", 22),0)));
 return stk->count == 0;
}

canonical_original_code:
int Stack_empty(struct Stack_T *stk) {
 ((void)((stk)||(Except_raise(&(Assert_Failed), "src/stack.c", 22),0)));
 return stk->count == 0;
}

user_defined_types: struct elem { void *x; struct elem *link; }


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

if ( !a1 )
Except_raise(&Assert_Failed, "src/stack.c", 37LL);
if ( *(int *)a1 <= 0 )
Except_raise(&Assert_Failed, "src/stack.c", 38LL);
v2 = *(__int64 **)(a1 + 8);
*(_QWORD *)(a1 + 8) = v2[1];
--*(_DWORD *)a1;
v3 = *v2;
Mem_free(v2, "src/stack.c", 43LL);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 *v2; // rdi
__int64 v3; // rbx

if ( !a1 )
Except_raise(&Assert_Failed, "src/stack.c", 37LL);
if ( *(int *)a1 <= 0 )
Except_raise(&Assert_Failed, "src/stack.c", 38LL);
v2 = *(__int64 **)(a1 + 8);
*(_QWORD *)(a1 + 8) = v2[1];
--*(_DWORD *)a1;
v3 = *v2;
Mem_free(v2, "src/stack.c", 43LL);
return v3;
}

original_code:
void *Stack_pop(Stack_T stk) {
 void *x;
 struct elem *t;
 ((void)((stk)||(Except_raise(&(Assert_Failed), "src/stack.c", 37),0)));
 ((void)((stk->count > 0)||(Except_raise(&(Assert_Failed), "src/stack.c", 38),0)));
 t = stk->head;
 stk->head = t->link;
 stk->count--;
 x = t->x;
 ((void)(Mem_free((t), "src/stack.c", 43), (t) = 0));
 return x;
}

canonical_original_code:
void *Stack_pop(struct Stack_T *stk) {
 void *x;
 struct elem *t;
 ((void)((stk)||(Except_raise(&(Assert_Failed), "src/stack.c", 37),0)));
 ((void)((stk->count > 0)||(Except_raise(&(Assert_Failed), "src/stack.c", 38),0)));
 t = stk->head;
 stk->head = t->link;
 stk->count--;
 x = t->x;
 ((void)(Mem_free((t), "src/stack.c", 43), (t) = 0));
 return x;
}

variable_types:
x
void *

variable_types: struct elem { void *x; struct elem *link; } *

return_type: void *


expand

decompiled_code:
unsigned __int64 __fastcall expand(int *a1)
{
int v1; // ebp
unsigned __int64 result; // rax
char *v3; // rsi

v1 = *a1;
Array_resize(a1, (unsigned int)(2 * *a1));
result = (unsigned int)a1[5];
if ( (int)result > 0 )
{
v3 = (char *)(*((_QWORD *)a1 + 1) + 8LL * (int)result);
result = (unsigned __int64)memcpy(&v3[8 * v1], v3, 8LL * (v1 - (int)result));
a1[5] += v1;
}
return result;
}

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

v1 = *a1;
Array_resize(a1, (unsigned int)(2 * *a1));
result = (unsigned int)a1[5];
if ( (int)result > 0 )
{
v3 = (char *)(*((_QWORD *)a1 + 1) + 8LL * (int)result);
result = (unsigned __int64)memcpy(&v3[8 * v1], v3, 8LL * (v1 - (int)result));
a1[5] += v1;
}
return result;
}

original_code:
static void expand(Seq_T seq) {
 int n = seq->array.length;
 Array_resize(&seq->array, 2*n);
 if (seq->head > 0)
  {
   void **old = &((void **)seq->array.array)[seq->head];
   memcpy(old+n, old, (n - seq->head)*sizeof (void *));
   seq->head += n;
  }
}

canonical_original_code:
static void expand(struct Seq_T *seq) {
 int n = seq->array.length;
 Array_resize(&seq->array, 2*n);
 if (seq->head > 0)
  {
   void **old = &((void **)seq->array.array)[seq->head];
   memcpy(old+n, old, (n - seq->head)*sizeof (void *));
   seq->head += n;
  }
}

variable_types: struct Seq_T { struct Array_T { int length; int size; char *array; } array; int length; int head; } *

variable_types: n int

variable_types:
old
void **

user_defined_types: struct Seq_T { struct Array_T array; int length; int head; }


decompiled_code:
__int64 __fastcall Seq_new(int a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // rax

v1 = a1;
if ( a1 < 0 )
{
Except_raise(&Assert_Failed, "src/seq.c", 28LL);
v2 = Mem_calloc(1LL, 24LL, "src/seq.c", 29LL);
}
else
{
v2 = Mem_calloc(1LL, 24LL, "src/seq.c", 29LL);
if ( !a1 )
v1 = 16;
}
v3 = Mem_alloc(8LL * v1, "src/seq.c", 33LL);
ArrayRep_init(v2, (unsigned int)v1, 8LL, v3);
return v2;
}

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

v1 = a1;
if ( a1 < 0 )
{
Except_raise(&Assert_Failed, "src/seq.c", 28LL);
v2 = Mem_calloc(1LL, 24LL, "src/seq.c", 29LL);
}
else
{
v2 = Mem_calloc(1LL, 24LL, "src/seq.c", 29LL);
if ( !a1 )
v1 = 16;
}
v3 = Mem_alloc(8LL * v1, "src/seq.c", 33LL);
ArrayRep_init(v2, (unsigned int)v1, 8LL, v3);
return v2;
}

original_code:
Seq_T Seq_new(int hint) {
 Seq_T seq;
 ((void)((hint >= 0)||(Except_raise(&(Assert_Failed), "src/seq.c", 28),0)));
 ((seq) = Mem_calloc((1), ((long)sizeof *(seq)), "src/seq.c", 29));
 if (hint == 0)
  hint = 16;
 ArrayRep_init(&seq->array, hint, sizeof (void *),
  Mem_alloc((hint*sizeof (void *)), "src/seq.c", 33));
 return seq;
}

canonical_original_code:
struct Seq_T *Seq_new(int hint) {
 struct Seq_T *seq;
 ((void)((hint >= 0)||(Except_raise(&(Assert_Failed), "src/seq.c", 28),0)));
 ((seq) = Mem_calloc((1), ((long)sizeof *(seq)), "src/seq.c", 29));
 if (hint == 0)
  hint = 16;
 ArrayRep_init(&seq->array, hint, sizeof (void *),
  Mem_alloc((hint*sizeof (void *)), "src/seq.c", 33));
 return seq;
}

variable_types: hint int

return_type: struct Seq_T { struct Array_T { int length; int size; char *array; } array; int length; int head; } *


decompiled_code:
__int64 __fastcall Seq_free(_QWORD *a1)
{
if ( !a1 || !*a1 )
Except_raise(&Assert_Failed, "src/seq.c", 46LL);
return Array_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
if ( !a1 || !*a1 )
Except_raise(&Assert_Failed, "src/seq.c", 46LL);
return Array_free(a1);
}

original_code:
void Seq_free(Seq_T *seq) {
 ((void)((seq && *seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 46),0)));
 ((void)(((void *)*seq == (void *)&(*seq)->array)||(Except_raise(&(Assert_Failed), "src/seq.c", 47),0)));
 Array_free((Array_T *)seq);
}

canonical_original_code:
void Seq_free(struct Seq_T **seq) {
 ((void)((seq && *seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 46),0)));
 ((void)(((void *)*seq == (void *)&(*seq)->array)||(Except_raise(&(Assert_Failed), "src/seq.c", 47),0)));
 Array_free((struct Array_T **)seq);
}

variable_types: struct Seq_T { struct Array_T { int length; int size; char *array; } array; int length; int head; } **


decompiled_code:
__int64 __fastcall Seq_length(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/seq.c", 51LL);
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/seq.c", 51LL);
return *(unsigned int *)(a1 + 16);
}

original_code:
int Seq_length(Seq_T seq) {
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 51),0)));
 return seq->length;
}

canonical_original_code:
int Seq_length(struct Seq_T *seq) {
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 51),0)));
 return seq->length;
}

user_defined_types: struct Array_T { int length; int size; char *array; }


decompiled_code:
__int64 __fastcall Seq_get(__int64 a1, int a2)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/seq.c", 55LL);
if ( a2 < 0 || *(_DWORD *)(a1 + 16) <= a2 )
Except_raise(&Assert_Failed, "src/seq.c", 56LL);
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * ((*(_DWORD *)(a1 + 20) + a2) % *(_DWORD *)a1));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/seq.c", 55LL);
if ( a2 < 0 || *(_DWORD *)(a1 + 16) <= a2 )
Except_raise(&Assert_Failed, "src/seq.c", 56LL);
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * ((*(_DWORD *)(a1 + 20) + a2) % *(_DWORD *)a1));
}

original_code:
void *Seq_get(Seq_T seq, int i) {
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 55),0)));
 ((void)((i >= 0 && i < seq->length)||(Except_raise(&(Assert_Failed), "src/seq.c", 56),0)));
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length];
}

canonical_original_code:
void *Seq_get(struct Seq_T *seq, int i) {
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 55),0)));
 ((void)((i >= 0 && i < seq->length)||(Except_raise(&(Assert_Failed), "src/seq.c", 56),0)));
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length];
}

variable_types: i int


decompiled_code:
__int64 __fastcall Seq_put(__int64 a1, int a2, __int64 a3)
{
__int64 *v4; // rax
__int64 v5; // rdx

if ( !a1 )
Except_raise(&Assert_Failed, "src/seq.c", 62LL);
if ( a2 < 0 || *(_DWORD *)(a1 + 16) <= a2 )
Except_raise(&Assert_Failed, "src/seq.c", 63LL);
v4 = (__int64 *)(*(_QWORD *)(a1 + 8) + 8LL * ((*(_DWORD *)(a1 + 20) + a2) % *(_DWORD *)a1));
v5 = *v4;
*v4 = a3;
return v5;
}

original_code:
void *Seq_put(Seq_T seq, int i, void *x) {
 void *prev;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 62),0)));
 ((void)((i >= 0 && i < seq->length)||(Except_raise(&(Assert_Failed), "src/seq.c", 63),0)));
 prev = ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length];
 ((void **)seq->array.array)[
  (seq->head + i)%seq->array.length] = x;
 return prev;
}

canonical_original_code:
void *Seq_put(struct Seq_T *seq, int i, void *x) {
 void *prev;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 62),0)));
 ((void)((i >= 0 && i < seq->length)||(Except_raise(&(Assert_Failed), "src/seq.c", 63),0)));
 prev = ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length];
 ((void **)seq->array.array)[
  (seq->head + i)%seq->array.length] = x;
 return prev;
}

variable_types:
prev
void *


decompiled_code:
__int64 __fastcall Seq_remhi(__int64 a1)
{
int v1; // eax

if ( !a1 )
Except_raise(&Assert_Failed, "src/seq.c", 72LL);
if ( *(int *)(a1 + 16) <= 0 )
Except_raise(&Assert_Failed, "src/seq.c", 73LL);
v1 = *(_DWORD *)(a1 + 16) - 1;
*(_DWORD *)(a1 + 16) = v1;
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * ((*(_DWORD *)(a1 + 20) + v1) % *(_DWORD *)a1));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // eax

if ( !a1 )
Except_raise(&Assert_Failed, "src/seq.c", 72LL);
if ( *(int *)(a1 + 16) <= 0 )
Except_raise(&Assert_Failed, "src/seq.c", 73LL);
v1 = *(_DWORD *)(a1 + 16) - 1;
*(_DWORD *)(a1 + 16) = v1;
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * ((*(_DWORD *)(a1 + 20) + v1) % *(_DWORD *)a1));
}

original_code:
void *Seq_remhi(Seq_T seq) {
 int i;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 72),0)));
 ((void)((seq->length > 0)||(Except_raise(&(Assert_Failed), "src/seq.c", 73),0)));
 i = --seq->length;
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length];
}

canonical_original_code:
void *Seq_remhi(struct Seq_T *seq) {
 int i;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 72),0)));
 ((void)((seq->length > 0)||(Except_raise(&(Assert_Failed), "src/seq.c", 73),0)));
 i = --seq->length;
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length];
}


original_code:
void *Seq_remlo(Seq_T seq) {
 int i = 0;
 void *x;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 81),0)));
 ((void)((seq->length > 0)||(Except_raise(&(Assert_Failed), "src/seq.c", 82),0)));
 x = ((void **)seq->array.array)[
      (seq->head + i)%seq->array.length];
 seq->head = (seq->head + 1)%seq->array.length;
 --seq->length;
 return x;
}

canonical_original_code:
void *Seq_remlo(struct Seq_T *seq) {
 int i = 0;
 void *x;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 81),0)));
 ((void)((seq->length > 0)||(Except_raise(&(Assert_Failed), "src/seq.c", 82),0)));
 x = ((void **)seq->array.array)[
      (seq->head + i)%seq->array.length];
 seq->head = (seq->head + 1)%seq->array.length;
 --seq->length;
 return x;
}


original_code:
void *Seq_addhi(Seq_T seq, void *x) {
 int i;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 91),0)));
 if (seq->length == seq->array.length)
  expand(seq);
 i = seq->length++;
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length] = x;
}

canonical_original_code:
void *Seq_addhi(struct Seq_T *seq, void *x) {
 int i;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 91),0)));
 if (seq->length == seq->array.length)
  expand(seq);
 i = seq->length++;
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length] = x;
}


original_code:
void *Seq_addlo(Seq_T seq, void *x) {
 int i = 0;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 100),0)));
 if (seq->length == seq->array.length)
  expand(seq);
 if (--seq->head < 0)
  seq->head = seq->array.length - 1;
 seq->length++;
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length] = x;
}

canonical_original_code:
void *Seq_addlo(struct Seq_T *seq, void *x) {
 int i = 0;
 ((void)((seq)||(Except_raise(&(Assert_Failed), "src/seq.c", 100),0)));
 if (seq->length == seq->array.length)
  expand(seq);
 if (--seq->head < 0)
  seq->head = seq->array.length - 1;
 seq->length++;
 return ((void **)seq->array.array)[
         (seq->head + i)%seq->array.length] = x;
}


original_code:
unsigned long XP_fromint(int n, XP_T z, unsigned long u) {
 int i = 0;
 do
  z[i++] = u%(1<<8);
 while ((u /= (1<<8)) > 0 && i < n);
 for ( ; i < n; i++)
  z[i] = 0;
 return u;
}

canonical_original_code:
unsigned long XP_fromint(int n, unsigned char *z, unsigned long u) {
 int i = 0;
 do
  z[i++] = u%(1<<8);
 while ((u /= (1<<8)) > 0 && i < n);
 for ( ; i < n; i++)
  z[i] = 0;
 return u;
}

variable_types:
z
unsigned char *

variable_types:
u
unsigned long

return_type: unsigned long


original_code:
unsigned long XP_toint(int n, XP_T x) {
 unsigned long u = 0;
 int i = (int)sizeof u;
 if (i > n)
  i = n;
 while (--i >= 0)
  u = (1<<8)*u + x[i];
 return u;
}

canonical_original_code:
unsigned long XP_toint(int n, unsigned char *x) {
 unsigned long u = 0;
 int i = (int)sizeof u;
 if (i > n)
  i = n;
 while (--i >= 0)
  u = (1<<8)*u + x[i];
 return u;
}

variable_types:
x
unsigned char *


decompiled_code:
__int64 __fastcall XP_length(int a1, __int64 a2)
{
__int64 result; // rax
_BYTE *v3; // rdx

result = (unsigned int)a1;
if ( a1 > 1 )
{
v3 = (_BYTE *)(a2 + a1 - 1);
do
{
if ( *v3 )
break;
result = (unsigned int)(result - 1);
--v3;
}
while ( (_DWORD)result != 1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 result; // rax
_BYTE *v3; // rdx

result = (unsigned int)a1;
if ( a1 > 1 )
{
v3 = (_BYTE *)(a2 + a1 - 1);
do
{
if ( *v3 )
break;
result = (unsigned int)(result - 1);
--v3;
}
while ( (_DWORD)result != 1 );
}
return result;
}

original_code:
int XP_length(int n, XP_T x) {
 while (n > 1 && x[n-1] == 0)
  n--;
 return n;
}

canonical_original_code:
int XP_length(int n, unsigned char *x) {
 while (n > 1 && x[n-1] == 0)
  n--;
 return n;
}


decompiled_code:
__int64 __fastcall XP_add(int a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax
__int64 i; // rcx
int v8; // eax

result = a5;
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
v8 = *(unsigned __int8 *)(a4 + i) + *(unsigned __int8 *)(a3 + i) + result;
*(_BYTE *)(a2 + i) = v8 % 256;
result = (unsigned int)(v8 / 256);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax
__int64 i; // rcx
int v8; // eax

result = a5;
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
v8 = *(unsigned __int8 *)(a4 + i) + *(unsigned __int8 *)(a3 + i) + result;
*(_BYTE *)(a2 + i) = v8 % 256;
result = (unsigned int)(v8 / 256);
}
}
return result;
}

original_code:
int XP_add(int n, XP_T z, XP_T x, XP_T y, int carry) {
 int i;
 for (i = 0; i < n; i++) {
  carry += x[i] + y[i];
  z[i] = carry%(1<<8);
  carry /= (1<<8);
 }
 return carry;
}

canonical_original_code:
int XP_add(int n, unsigned char *z, unsigned char *x, unsigned char *y, int carry) {
 int i;
 for (i = 0; i < n; i++) {
  carry += x[i] + y[i];
  z[i] = carry%(1<<8);
  carry /= (1<<8);
 }
 return carry;
}

variable_types:
y
unsigned char *

variable_types: carry int


original_code:
int XP_sub(int n, XP_T z, XP_T x, XP_T y, int borrow) {
 int i;
 for (i = 0; i < n; i++) {
  int d = (x[i] + (1<<8)) - borrow - y[i];
  z[i] = d%(1<<8);
  borrow = 1 - d/(1<<8);
 }
 return borrow;
}

canonical_original_code:
int XP_sub(int n, unsigned char *z, unsigned char *x, unsigned char *y, int borrow) {
 int i;
 for (i = 0; i < n; i++) {
  int d = (x[i] + (1<<8)) - borrow - y[i];
  z[i] = d%(1<<8);
  borrow = 1 - d/(1<<8);
 }
 return borrow;
}

variable_types: borrow int

variable_types: d int


decompiled_code:
__int64 __fastcall XP_sum(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7; // rsi
int v8; // eax

result = a4;
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(a3 + v7) + (_DWORD)result;
*(_BYTE *)(a2 + v7) = v8 % 256;
result = (unsigned int)(v8 / 256);
++v7;
}
while ( v7 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7; // rsi
int v8; // eax

result = a4;
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(a3 + v7) + (_DWORD)result;
*(_BYTE *)(a2 + v7) = v8 % 256;
result = (unsigned int)(v8 / 256);
++v7;
}
while ( v7 != a1 );
}
return result;
}

original_code:
int XP_sum(int n, XP_T z, XP_T x, int y) {
 int i;
 for (i = 0; i < n; i++) {
  y += x[i];
  z[i] = y%(1<<8);
  y /= (1<<8);
 }
 return y;
}

canonical_original_code:
int XP_sum(int n, unsigned char *z, unsigned char *x, int y) {
 int i;
 for (i = 0; i < n; i++) {
  y += x[i];
  z[i] = y%(1<<8);
  y /= (1<<8);
 }
 return y;
}

variable_types: y int


decompiled_code:
__int64 __fastcall XP_diff(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7; // rcx
int v8; // edx

result = a4;
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(a3 + v7) + 256 - result;
*(_BYTE *)(a2 + v7) = *(_BYTE *)(a3 + v7) - result;
result = (unsigned int)(1 - v8 / 256);
++v7;
}
while ( v7 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7; // rcx
int v8; // edx

result = a4;
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(a3 + v7) + 256 - result;
*(_BYTE *)(a2 + v7) = *(_BYTE *)(a3 + v7) - result;
result = (unsigned int)(1 - v8 / 256);
++v7;
}
while ( v7 != a1 );
}
return result;
}

canonical_original_code:
int XP_diff(int n, unsigned char *z, unsigned char *x, int y) {
 int i;
 for (i = 0; i < n; i++) {
  int d = (x[i] + (1<<8)) - y;
  z[i] = d%(1<<8);
  y = 1 - d/(1<<8);
 }
 return y;
}


decompiled_code:
__int64 __fastcall XP_neg(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7; // rsi
int v8; // eax

result = a4;
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = (unsigned __int8)~*(_BYTE *)(a3 + v7) + (_DWORD)result;
*(_BYTE *)(a2 + v7) = v8 % 256;
result = (unsigned int)(v8 / 256);
++v7;
}
while ( v7 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7; // rsi
int v8; // eax

result = a4;
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = (unsigned __int8)~*(_BYTE *)(a3 + v7) + (_DWORD)result;
*(_BYTE *)(a2 + v7) = v8 % 256;
result = (unsigned int)(v8 / 256);
++v7;
}
while ( v7 != a1 );
}
return result;
}

original_code:
int XP_neg(int n, XP_T z, XP_T x, int carry) {
 int i;
 for (i = 0; i < n; i++) {
  carry += (unsigned char)~x[i];
  z[i] = carry%(1<<8);
  carry /= (1<<8);
 }
 return carry;
}

canonical_original_code:
int XP_neg(int n, unsigned char *z, unsigned char *x, int carry) {
 int i;
 for (i = 0; i < n; i++) {
  carry += (unsigned char)~x[i];
  z[i] = carry%(1<<8);
  carry /= (1<<8);
 }
 return carry;
}


original_code:
int XP_mul(XP_T z, int n, XP_T x, int m, XP_T y) {
 int i, j, carryout = 0;
 for (i = 0; i < n; i++) {
  unsigned carry = 0;
  for (j = 0; j < m; j++) {
   carry += x[i]*y[j] + z[i+j];
   z[i+j] = carry%(1<<8);
   carry /= (1<<8);
  }
  for ( ; j < n + m - i; j++) {
   carry += z[i+j];
   z[i+j] = carry%(1<<8);
   carry /= (1<<8);
  }
  carryout |= carry;
 }
 return carryout;
}

canonical_original_code:
int XP_mul(unsigned char *z, int n, unsigned char *x, int m, unsigned char *y) {
 int i; int j; int carryout = 0;
 for (i = 0; i < n; i++) {
  unsigned int carry = 0;
  for (j = 0; j < m; j++) {
   carry += x[i]*y[j] + z[i+j];
   z[i+j] = carry%(1<<8);
   carry /= (1<<8);
  }
  for ( ; j < n + m - i; j++) {
   carry += z[i+j];
   z[i+j] = carry%(1<<8);
   carry /= (1<<8);
  }
  carryout |= carry;
 }
 return carryout;
}

variable_types: m int

variable_types: j int

variable_types: carryout int

variable_types:
carry
unsigned int


decompiled_code:
__int64 __fastcall XP_product(int a1, __int64 a2, __int64 a3, int a4)
{
__int64 v5; // rdx
__int64 result; // rax
unsigned int v7; // eax

if ( a1 <= 0 )
return 0LL;
v5 = 0LL;
LODWORD(result) = 0;
do
{
v7 = a4 * *(unsigned __int8 *)(a3 + v5) + result;
*(_BYTE *)(a2 + v5) = v7;
result = v7 >> 8;
++v5;
}
while ( v5 != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2, __int64 a3, int a4)
{
__int64 v5; // rdx
__int64 result; // rax
unsigned int v7; // eax

if ( a1 <= 0 )
return 0LL;
v5 = 0LL;
LODWORD(result) = 0;
do
{
v7 = a4 * *(unsigned __int8 *)(a3 + v5) + result;
*(_BYTE *)(a2 + v5) = v7;
result = v7 >> 8;
++v5;
}
while ( v5 != a1 );
return result;
}

original_code:
int XP_product(int n, XP_T z, XP_T x, int y) {
 int i;
 unsigned carry = 0;
 for (i = 0; i < n; i++) {
  carry += x[i]*y;
  z[i] = carry%(1<<8);
  carry /= (1<<8);
 }
 return carry;
}

canonical_original_code:
int XP_product(int n, unsigned char *z, unsigned char *x, int y) {
 int i;
 unsigned int carry = 0;
 for (i = 0; i < n; i++) {
  carry += x[i]*y;
  z[i] = carry%(1<<8);
  carry /= (1<<8);
 }
 return carry;
}

variable_types: n int


decompiled_code:
__int64 __fastcall XP_quotient(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rdi
unsigned int v6; // edx
unsigned int v7; // eax

LODWORD(v5) = a1 - 1;
if ( (int)v5 < 0 )
return 0;
v5 = (int)v5;
v6 = 0;
do
{
v7 = (v6 << 8) + *(unsigned __int8 *)(a3 + v5);
v6 = v7 % a4;
*(_BYTE *)(a2 + v5--) = v7 / a4;
}
while ( (int)v5 >= 0 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rdi
unsigned int v6; // edx
unsigned int v7; // eax

LODWORD(v5) = a1 - 1;
if ( (int)v5 < 0 )
return 0;
v5 = (int)v5;
v6 = 0;
do
{
v7 = (v6 << 8) + *(unsigned __int8 *)(a3 + v5);
v6 = v7 % a4;
*(_BYTE *)(a2 + v5--) = v7 / a4;
}
while ( (int)v5 >= 0 );
return v6;
}

original_code:
int XP_quotient(int n, XP_T z, XP_T x, int y) {
 int i;
 unsigned carry = 0;
 for (i = n - 1; i >= 0; i--) {
  carry = carry*(1<<8) + x[i];
  z[i] = carry/y;
  carry %= y;
 }
 return carry;
}

canonical_original_code:
int XP_quotient(int n, unsigned char *z, unsigned char *x, int y) {
 int i;
 unsigned int carry = 0;
 for (i = n - 1; i >= 0; i--) {
  carry = carry*(1<<8) + x[i];
  z[i] = carry/y;
  carry %= y;
 }
 return carry;
}


original_code:
int XP_div(int n, XP_T q, XP_T x, int m, XP_T y, XP_T r, XP_T tmp) {
 int nx = n, my = m;
 n = XP_length(n, x);
 m = XP_length(m, y);
 if (m == 1) {
  if (y[0] == 0)
   return 0;
  r[0] = XP_quotient(nx, q, x, y[0]);
  memset(r + 1, '\0', my - 1);
 } else if (m > n) {
  memset(q, '\0', nx);
  memcpy(r, x, n);
  memset(r + n, '\0', my - n);
 } else {
  int k;
  unsigned char *rem = tmp, *dq = tmp + n + 1;
  ((void)((2 <= m && m <= n)||(Except_raise(&(Assert_Failed), "src/xp.c", 129),0)));
  memcpy(rem, x, n);
  rem[n] = 0;
  for (k = n - m; k >= 0; k--) {
   int qk;
   {
    int i;
    ((void)((2 <= m && m <= k+m && k+m <= n)||(Except_raise(&(Assert_Failed), "src/xp.c", 136),0)));
    {
     int km = k + m;
     unsigned long y2 = y[m-1]*(1<<8) + y[m-2];
     unsigned long r3 = rem[km]*((1<<8)*(1<<8)) +
      rem[km-1]*(1<<8) + rem[km-2];
     qk = r3/y2;
     if (qk >= (1<<8))
      qk = (1<<8) - 1;
    }
    dq[m] = XP_product(m, dq, y, qk);
    for (i = m; i > 0; i--)
     if (rem[i+k] != dq[i])
      break;
    if (rem[i+k] < dq[i])
     dq[m] = XP_product(m, dq, y, --qk);
   }
   q[k] = qk;
   {
    int borrow;
    ((void)((0 <= k && k <= k+m)||(Except_raise(&(Assert_Failed), "src/xp.c", 156),0)));
    borrow = XP_sub(m + 1, &rem[k], &rem[k], dq, 0);
    ((void)((borrow == 0)||(Except_raise(&(Assert_Failed), "src/xp.c", 158),0)));
   }
  }
  memcpy(r, rem, m);
  {
   int i;
   for (i = n-m+1; i < nx; i++)
    q[i] = 0;
   for (i = m; i < my; i++)
    r[i] = 0;
  }
 }
 return 1;
}

canonical_original_code:
int XP_div(int n, unsigned char *q, unsigned char *x, int m, unsigned char *y, unsigned char *r, unsigned char *tmp) {
 int nx = n; int my = m;
 n = XP_length(n, x);
 m = XP_length(m, y);
 if (m == 1) {
  if (y[0] == 0)
   return 0;
  r[0] = XP_quotient(nx, q, x, y[0]);
  memset(r + 1, '\0', my - 1);
 } else if (m > n) {
  memset(q, '\0', nx);
  memcpy(r, x, n);
  memset(r + n, '\0', my - n);
 } else {
  int k;
  unsigned char *rem = tmp; unsigned char *dq = tmp + n + 1;
  ((void)((2 <= m && m <= n)||(Except_raise(&(Assert_Failed), "src/xp.c", 129),0)));
  memcpy(rem, x, n);
  rem[n] = 0;
  for (k = n - m; k >= 0; k--) {
   int qk;
   {
    int i;
    ((void)((2 <= m && m <= k+m && k+m <= n)||(Except_raise(&(Assert_Failed), "src/xp.c", 136),0)));
    {
     int km = k + m;
     unsigned long y2 = y[m-1]*(1<<8) + y[m-2];
     unsigned long r3 = rem[km]*((1<<8)*(1<<8)) +
      rem[km-1]*(1<<8) + rem[km-2];
     qk = r3/y2;
     if (qk >= (1<<8))
      qk = (1<<8) - 1;
    }
    dq[m] = XP_product(m, dq, y, qk);
    for (i = m; i > 0; i--)
     if (rem[i+k] != dq[i])
      break;
    if (rem[i+k] < dq[i])
     dq[m] = XP_product(m, dq, y, --qk);
   }
   q[k] = qk;
   {
    int borrow;
    ((void)((0 <= k && k <= k+m)||(Except_raise(&(Assert_Failed), "src/xp.c", 156),0)));
    borrow = XP_sub(m + 1, &rem[k], &rem[k], dq, 0);
    ((void)((borrow == 0)||(Except_raise(&(Assert_Failed), "src/xp.c", 158),0)));
   }
  }
  memcpy(r, rem, m);
  {
   int i;
   for (i = n-m+1; i < nx; i++)
    q[i] = 0;
   for (i = m; i < my; i++)
    r[i] = 0;
  }
 }
 return 1;
}

variable_types:
q
unsigned char *

variable_types:
r
unsigned char *

variable_types:
tmp
unsigned char *

variable_types: nx int

variable_types: my int

variable_types: k int

variable_types:
rem
unsigned char *

variable_types:
dq
unsigned char *

variable_types: qk int

variable_types: km int


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

v3 = a1 - 1;
if ( v3 > 0 )
{
v4 = v3;
do
{
v3 = v4;
if ( *(_BYTE *)(a2 + v4) != *(_BYTE *)(a3 + v4) )
break;
v3 = --v4;
}
while ( (int)v4 > 0 );
}
return *(unsigned __int8 *)(a2 + v3) - (unsigned int)*(unsigned __int8 *)(a3 + v3);
}

original_code:
int XP_cmp(int n, XP_T x, XP_T y) {
 int i = n - 1;
 while (i > 0 && x[i] == y[i])
  i--;
 return x[i] - y[i];
}

canonical_original_code:
int XP_cmp(int n, unsigned char *x, unsigned char *y) {
 int i = n - 1;
 while (i > 0 && x[i] == y[i])
  i--;
 return x[i] - y[i];
}

variable_types:
x
unsigned char *

variable_types:
y
unsigned char *

variable_types: i int


original_code:
void XP_lshift(int n, XP_T z, int m, XP_T x, int s, int fill) {
 fill = fill ? 0xFF : 0;
 {
  int i, j = n - 1;
  if (n > m)
   i = m - 1;
  else
   i = n - s/8 - 1;
  for ( ; j >= m + s/8; j--)
   z[j] = 0;
  for ( ; i >= 0; i--, j--)
   z[j] = x[i];
  for ( ; j >= 0; j--)
   z[j] = fill;
 }
 s %= 8;
 if (s > 0)
  {
   XP_product(n, z, z, 1<<s);
   z[0] |= fill>>(8-s);
  }
}

canonical_original_code:
void XP_lshift(int n, unsigned char *z, int m, unsigned char *x, int s, int fill) {
 fill = fill ? 0xFF : 0;
 {
  int i; int j = n - 1;
  if (n > m)
   i = m - 1;
  else
   i = n - s/8 - 1;
  for ( ; j >= m + s/8; j--)
   z[j] = 0;
  for ( ; i >= 0; i--, j--)
   z[j] = x[i];
  for ( ; j >= 0; j--)
   z[j] = fill;
 }
 s %= 8;
 if (s > 0)
  {
   XP_product(n, z, z, 1<<s);
   z[0] |= fill>>(8-s);
  }
}

variable_types:
z
unsigned char *

variable_types: m int

variable_types: s int

variable_types: fill int

variable_types: j int


original_code:
void XP_rshift(int n, XP_T z, int m, XP_T x, int s, int fill) {
 fill = fill ? 0xFF : 0;
 {
  int i, j = 0;
  for (i = s/8; i < m && j < n; i++, j++)
   z[j] = x[i];
  for ( ; j < n; j++)
   z[j] = fill;
 }
 s %= 8;
 if (s > 0)
  {
   XP_quotient(n, z, z, 1<<s);
   z[n-1] |= fill<<(8-s);
  }
}

canonical_original_code:
void XP_rshift(int n, unsigned char *z, int m, unsigned char *x, int s, int fill) {
 fill = fill ? 0xFF : 0;
 {
  int i; int j = 0;
  for (i = s/8; i < m && j < n; i++, j++)
   z[j] = x[i];
  for ( ; j < n; j++)
   z[j] = fill;
 }
 s %= 8;
 if (s > 0)
  {
   XP_quotient(n, z, z, 1<<s);
   z[n-1] |= fill<<(8-s);
  }
}

variable_types: n int


decompiled_code:
__int64 __fastcall XP_fromstr(int a1, __int64 a2, char *a3, int a4, char **a5)
{
char v7; // bp
const unsigned __int16 **v8; // r15
char *v9; // rbx
unsigned __int16 v10; // ax
char v12; // al
unsigned int v13; // [rsp+0h] [rbp-48h]

if ( !a3 )
Except_raise(&Assert_Failed, "src/xp.c", 229LL);
if ( (unsigned int)(a4 - 2) > 0x22 )
Except_raise(&Assert_Failed, "src/xp.c", 230LL);
v7 = *a3;
if ( !*a3 )
goto LABEL_9;
v8 = _ctype_b_loc();
v9 = a3;
while ( 1 )
{
v10 = (*v8)[v7];
if ( (v10 & 0x2000) == 0 )
break;
v7 = *++v9;
if ( !*v9 )
goto LABEL_9;
}
if ( v7 && (v10 & 8) != 0 && map[v7 - 48] < a4 )
{
v12 = *v9;
if ( *v9 )
{
while ( ((*v8)[v12] & 8) != 0 )
{
if ( map[v12 - 48] >= a4 )
{
v13 = 0;
goto LABEL_23;
}
v13 = XP_product(a1, a2, a2, a4);
if ( !v13 )
{
XP_sum(a1, a2, a2, map[*v9++ - 48]);
v12 = *v9;
if ( *v9 )
continue;
}
goto LABEL_23;
}
v13 = 0;
}
LABEL_23:
if ( a5 )
*a5 = v9;
}
else
{
LABEL_9:
v13 = 0;
if ( a5 )
*a5 = a3;
}
return v13;
}

original_code:
int XP_fromstr(int n, XP_T z, const char *str,
 int base, char **end) {
 const char *p = str;
 ((void)((p)||(Except_raise(&(Assert_Failed), "src/xp.c", 229),0)));
 ((void)((base >= 2 && base <= 36)||(Except_raise(&(Assert_Failed), "src/xp.c", 230),0)));
 while (*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace))
  p++;
 if ((*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalnum) && map[*p-'0'] < base)) {
  int carry;
  for ( ; (*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalnum) && map[*p-'0'] < base); p++) {
   carry = XP_product(n, z, z, base);
   if (carry)
    break;
   XP_sum(n, z, z, map[*p-'0']);
  }
  if (end)
   *end = (char *)p;
  return carry;
 } else {
  if (end)
   *end = (char *)str;
  return 0;
 }
}

canonical_original_code:
int XP_fromstr(int n, unsigned char *z, char *str, int base, char **end) {
 char *p = str;
 ((void)((p)||(Except_raise(&(Assert_Failed), "src/xp.c", 229),0)));
 ((void)((base >= 2 && base <= 36)||(Except_raise(&(Assert_Failed), "src/xp.c", 230),0)));
 while (*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace))
  p++;
 if ((*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalnum) && map[*p-'0'] < base)) {
  int carry;
  for ( ; (*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalnum) && map[*p-'0'] < base); p++) {
   carry = XP_product(n, z, z, base);
   if (carry)
    break;
   XP_sum(n, z, z, map[*p-'0']);
  }
  if (end)
   *end = (char *)p;
  return carry;
 } else {
  if (end)
   *end = (char *)str;
  return 0;
 }
}

variable_types:
str
char *

variable_types: base int

variable_types:
end
char **

variable_types:
p
char *

variable_types: carry int


original_code:
List_T List_copy(List_T list) {
 List_T head, *p = &head;
 for ( ; list; list = list->rest) {
  ((*p) = Mem_alloc(((long)sizeof *(*p)), "src/list.c", 38));
  (*p)->first = list->first;
  p = &(*p)->rest;
 }
 *p = ((void *)0);
 return head;
}

canonical_original_code:
struct List_T *List_copy(struct List_T *list) {
 struct List_T *head; struct List_T **p = &head;
 for ( ; list; list = list->rest) {
  ((*p) = Mem_alloc(((long)sizeof *(*p)), "src/list.c", 38));
  (*p)->first = list->first;
  p = &(*p)->rest;
 }
 *p = ((void *)0);
 return head;
}

variable_types:
list
struct List_T *

variable_types: struct List_T { struct List_T *rest; void *first; } **


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

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

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

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

original_code:
int List_length(List_T list) {
 int n;
 for (n = 0; list; list = list->rest)
  n++;
 return n;
}

canonical_original_code:
int List_length(struct List_T *list) {
 int n;
 for (n = 0; list; list = list->rest)
  n++;
 return n;
}

variable_types: struct List_T { struct List_T *rest; void *first; } *


decompiled_code:
__int64 __fastcall List_map(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
_QWORD *v3; // rbx
__int64 result; // rax

v3 = a1;
if ( !a2 )
result = Except_raise(&Assert_Failed, "src/list.c", 80LL);
if ( a1 )
{
do
{
result = a2(v3 + 1, a3);
v3 = (_QWORD *)*v3;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
_QWORD *v3; // rbx
__int64 result; // rax

v3 = a1;
if ( !a2 )
result = Except_raise(&Assert_Failed, "src/list.c", 80LL);
if ( a1 )
{
do
{
result = a2(v3 + 1, a3);
v3 = (_QWORD *)*v3;
}
while ( v3 );
}
return result;
}

original_code:
void List_map(List_T list,
 void apply(void **x, void *cl), void *cl) {
 ((void)((apply)||(Except_raise(&(Assert_Failed), "src/list.c", 80),0)));
 for ( ; list; list = list->rest)
  apply(&list->first, cl);
}

canonical_original_code:
void List_map(struct List_T *list, void apply(void **x, void *cl), void *cl) {
 ((void)((apply)||(Except_raise(&(Assert_Failed), "src/list.c", 80),0)));
 for ( ; list; list = list->rest)
  apply(&list->first, cl);
}

variable_types:
apply
void (void **x, void *cl)

variable_types:
cl
void *

user_defined_types: struct List_T { struct List_T *rest; void *first; }


strhash

decompiled_code:
__int64 __fastcall strhash(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++a1;
v2 = v1 + 2 * v2;
v1 = *a1;
}
while ( *a1 );
return v2;
}

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++a1;
v2 = v1 + 2 * v2;
v1 = *a1;
}
while ( *a1 );
return v2;
}

original_code:
unsigned strhash(const void *x) {
 const char *str = x;
 unsigned h = 0;
 while (*str)
  h = (h<<1) + *str++;
 return h;
}

canonical_original_code:
unsigned int strhash(void *x) {
 char *str = x;
 unsigned int h = 0;
 while (*str)
  h = (h<<1) + *str++;
 return h;
}

variable_types:
x
void *

variable_types:
h
unsigned int

return_type: unsigned int


compare

decompiled_code:
__int64 __fastcall compare(const void *a1, const void *a2)
{
return Str_cmp(*(_QWORD *)a1, 1LL, 0LL, *(_QWORD *)a2, 1LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
return Str_cmp(*(_QWORD *)a1, 1LL, 0LL, *(_QWORD *)a2, 1LL, 0LL);
}

original_code:
int compare(const void *x, const void *y) {
 return Str_cmp(*(char **)x, 1, 0, *(char **)y, 1, 0);
}

canonical_original_code:
int compare(void *x, void *y) {
 return Str_cmp(*(char **)x, 1, 0, *(char **)y, 1, 0);
}

variable_types:
y
void *


getword

decompiled_code:
__int64 __fastcall getword(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v7; // rdx

if ( !a1 )
Except_raise(&Assert_Failed, "examples/kref.c", 25LL);
if ( !a2 )
Except_raise(&Assert_Failed, "examples/kref.c", 26LL);
if ( !a3 )
Except_raise(&Assert_Failed, "examples/kref.c", 27LL);
if ( !a4 )
Except_raise(&Assert_Failed, "examples/kref.c", 28LL);
result = Str_rupto(a1, 1LL, (unsigned int)*a2, a3);
if ( (int)result > 0 )
{
v7 = (unsigned int)(result + 1);
*a2 = v7;
result = Str_rmany(a1, 1LL, v7, a4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v7; // rdx

if ( !a1 )
Except_raise(&Assert_Failed, "examples/kref.c", 25LL);
if ( !a2 )
Except_raise(&Assert_Failed, "examples/kref.c", 26LL);
if ( !a3 )
Except_raise(&Assert_Failed, "examples/kref.c", 27LL);
if ( !a4 )
Except_raise(&Assert_Failed, "examples/kref.c", 28LL);
result = Str_rupto(a1, 1LL, (unsigned int)*a2, a3);
if ( (int)result > 0 )
{
v7 = (unsigned int)(result + 1);
*a2 = v7;
result = Str_rmany(a1, 1LL, v7, a4);
}
return result;
}

original_code:
int getword(char *line, int *i, char *first, char *rest) {
 int j;
 ((void)((line)||(Except_raise(&(Assert_Failed), "examples/kref.c", 25),0)));
 ((void)((i)||(Except_raise(&(Assert_Failed), "examples/kref.c", 26),0)));
 ((void)((first)||(Except_raise(&(Assert_Failed), "examples/kref.c", 27),0)));
 ((void)((rest)||(Except_raise(&(Assert_Failed), "examples/kref.c", 28),0)));
 if ((j = Str_rupto(line, 1, *i, first)) > 0)
  j = Str_rmany(line, 1, *i = j + 1, rest);
 return j;
}

variable_types:
line
char *

variable_types:
i
int *

variable_types:
first
char *

variable_types:
rest
char *


memcmp

decompiled_code:
__int64 __fastcall memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
unsigned __int8 v7; // cl

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(_BYTE *)(a2 + v5);
if ( v6 != v7 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return v6 - (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
unsigned __int8 v7; // cl

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(_BYTE *)(a2 + v5);
if ( v6 != v7 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return v6 - (unsigned int)v7;
}

original_code:
int memcmp(const void *s1, const void *s2, size_t n) {
 const unsigned char *cs1 = s1, *cs2 = s2;
 for ( ; n-- > 0; cs1++, cs2++)
  if (*cs1 != *cs2)
   return *cs1 - *cs2;
 return 0;
}

canonical_original_code:
int memcmp(void *s1, void *s2, unsigned long n) {
 unsigned char *cs1 = s1; unsigned char *cs2 = s2;
 for ( ; n-- > 0; cs1++, cs2++)
  if (*cs1 != *cs2)
   return *cs1 - *cs2;
 return 0;
}

variable_types:
n
unsigned long


original_code:
const char *Atom_new(const char *str, int len) {
 unsigned long h;
 int i;
 struct atom *p;
 ((void)((str)||(Except_raise(&(Assert_Failed), "src/atom.c", 83),0)));
 ((void)((len >= 0)||(Except_raise(&(Assert_Failed), "src/atom.c", 84),0)));
 for (h = 0, i = 0; i < len; i++)
  h = (h<<1) + scatter[(unsigned char)str[i]];
 h &= ((sizeof (buckets))/(sizeof ((buckets)[0])))-1;
 for (p = buckets[h]; p; p = p->link)
  if (len == p->len) {
   for (i = 0; i < len && p->str[i] == str[i]; )
    i++;
   if (i == len)
    return p->str;
  }
 p = Mem_alloc((sizeof (*p) + len + 1), "src/atom.c", 95);
 p->len = len;
 p->str = (char *)(p + 1);
 if (len > 0)
  memcpy(p->str, str, len);
 p->str[len] = '\0';
 p->link = buckets[h];
 buckets[h] = p;
 return p->str;
}

canonical_original_code:
char *Atom_new(char *str, int len) {
 unsigned long h;
 int i;
 struct atom *p;
 ((void)((str)||(Except_raise(&(Assert_Failed), "src/atom.c", 83),0)));
 ((void)((len >= 0)||(Except_raise(&(Assert_Failed), "src/atom.c", 84),0)));
 for (h = 0, i = 0; i < len; i++)
  h = (h<<1) + scatter[(unsigned char)str[i]];
 h &= ((sizeof (buckets))/(sizeof ((buckets)[0])))-1;
 for (p = buckets[h]; p; p = p->link)
  if (len == p->len) {
   for (i = 0; i < len && p->str[i] == str[i]; )
    i++;
   if (i == len)
    return p->str;
  }
 p = Mem_alloc((sizeof (*p) + len + 1), "src/atom.c", 95);
 p->len = len;
 p->str = (char *)(p + 1);
 if (len > 0)
  memcpy(p->str, str, len);
 p->str[len] = '\0';
 p->link = buckets[h];
 buckets[h] = p;
 return p->str;
}

variable_types:
str
char *

variable_types: len int

variable_types:
h
unsigned long

variable_types: i int

variable_types: struct atom { struct atom *link; int len; char *str; } *

return_type: char *


decompiled_code:
__int64 __fastcall Atom_string(void *src)
{
int v1; // eax

if ( !src )
Except_raise(&Assert_Failed, "src/atom.c", 59LL);
v1 = strlen((const char *)src);
return Atom_new(src, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src)
{
int v1; // eax

if ( !src )
Except_raise(&Assert_Failed, "src/atom.c", 59LL);
v1 = strlen((const char *)src);
return func0(src, v1);
}

original_code:
const char *Atom_string(const char *str) {
 ((void)((str)||(Except_raise(&(Assert_Failed), "src/atom.c", 59),0)));
 return Atom_new(str, strlen(str));
}

canonical_original_code:
char *Atom_string(char *str) {
 ((void)((str)||(Except_raise(&(Assert_Failed), "src/atom.c", 59),0)));
 return Atom_new(str, strlen(str));
}


original_code:
const char *Atom_int(long n) {
 char str[43];
 char *s = str + sizeof str;
 unsigned long m;
 if (n == (-0x7fffffffffffffffL - 1L))
  m = 0x7fffffffffffffffL + 1UL;
 else if (n < 0)
  m = -n;
 else
  m = n;
 do
  *--s = m%10 + '0';
 while ((m /= 10) > 0);
 if (n < 0)
  *--s = '-';
 return Atom_new(s, (str + sizeof str) - s);
}

variable_types: n long

variable_types:
str
char [43]

variable_types:
s
char *

variable_types:
m
unsigned long


decompiled_code:
__int64 __fastcall Atom_length(__int64 *a1)
{
char *v1; // rdx
__int64 **v3; // rax

if ( !a1 )
Except_raise(&Assert_Failed, "src/atom.c", 108LL);
v1 = (char *)buckets;
while ( 1 )
{
v3 = *(__int64 ***)v1;
if ( *(_QWORD *)v1 )
break;
LABEL_5:
v1 += 8;
if ( v1 == "src/atom.c" )
{
Except_raise(&Assert_Failed, "src/atom.c", 113LL);
return 0LL;
}
}
while ( v3[2] != a1 )
{
v3 = (__int64 **)*v3;
if ( !v3 )
goto LABEL_5;
}
return *((unsigned int *)v3 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
char *v1; // rdx
__int64 **v3; // rax

if ( !a1 )
Except_raise(&Assert_Failed, "src/atom.c", 108LL);
v1 = (char *)buckets;
while ( 1 )
{
v3 = *(__int64 ***)v1;
if ( *(_QWORD *)v1 )
break;
LABEL_5:
v1 += 8;
if ( v1 == "src/atom.c" )
{
Except_raise(&Assert_Failed, "src/atom.c", 113LL);
return 0LL;
}
}
while ( v3[2] != a1 )
{
v3 = (__int64 **)*v3;
if ( !v3 )
goto LABEL_5;
}
return *((unsigned int *)v3 + 2);
}

original_code:
int Atom_length(const char *str) {
 struct atom *p;
 int i;
 ((void)((str)||(Except_raise(&(Assert_Failed), "src/atom.c", 108),0)));
 for (i = 0; i < ((sizeof (buckets))/(sizeof ((buckets)[0]))); i++)
  for (p = buckets[i]; p; p = p->link)
   if (p->str == str)
    return p->len;
 ((void)((0)||(Except_raise(&(Assert_Failed), "src/atom.c", 113),0)));
 return 0;
}

canonical_original_code:
int Atom_length(char *str) {
 struct atom *p;
 int i;
 ((void)((str)||(Except_raise(&(Assert_Failed), "src/atom.c", 108),0)));
 for (i = 0; i < ((sizeof (buckets))/(sizeof ((buckets)[0]))); i++)
  for (p = buckets[i]; p; p = p->link)
   if (p->str == str)
    return p->len;
 ((void)((0)||(Except_raise(&(Assert_Failed), "src/atom.c", 113),0)));
 return 0;
}

user_defined_types: struct atom { struct atom *link; int len; char *str; }


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

if ( !a1 )
result = Except_raise(&Assert_Failed, "src/array.c", 21LL);
if ( a4 && a2 > 0 )
{
if ( a3 > 0 )
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
goto LABEL_15;
}
}
else if ( a2 || a4 )
{
Except_raise(&Assert_Failed, "src/array.c", 22LL);
if ( a3 > 0 )
goto LABEL_13;
}
else if ( a3 > 0 )
{
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = a3;
a4 = 0LL;
goto LABEL_15;
}
Except_raise(&Assert_Failed, "src/array.c", 23LL);
LABEL_13:
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
result = 0LL;
if ( a2 <= 0 )
a4 = 0LL;
LABEL_15:
*(_QWORD *)(a1 + 8) = a4;
return result;
}

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

if ( !a1 )
result = Except_raise(&Assert_Failed, "src/array.c", 21LL);
if ( a4 && a2 > 0 )
{
if ( a3 > 0 )
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
goto LABEL_15;
}
}
else if ( a2 || a4 )
{
Except_raise(&Assert_Failed, "src/array.c", 22LL);
if ( a3 > 0 )
goto LABEL_13;
}
else if ( a3 > 0 )
{
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = a3;
a4 = 0LL;
goto LABEL_15;
}
Except_raise(&Assert_Failed, "src/array.c", 23LL);
LABEL_13:
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
result = 0LL;
if ( a2 <= 0 )
a4 = 0LL;
LABEL_15:
*(_QWORD *)(a1 + 8) = a4;
return result;
}

original_code:
void ArrayRep_init(Array_T array, int length, int size,
 void *ary) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 21),0)));
 ((void)((ary && length>0 || length==0 && ary==((void *)0))||(Except_raise(&(Assert_Failed), "src/array.c", 22),0)));
 ((void)((size > 0)||(Except_raise(&(Assert_Failed), "src/array.c", 23),0)));
 array->length = length;
 array->size = size;
 if (length > 0)
  array->array = ary;
 else
  array->array = ((void *)0);
}

canonical_original_code:
void ArrayRep_init(struct Array_T *array, int length, int size, void *ary) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 21),0)));
 ((void)((ary && length>0 || length==0 && ary==((void *)0))||(Except_raise(&(Assert_Failed), "src/array.c", 22),0)));
 ((void)((size > 0)||(Except_raise(&(Assert_Failed), "src/array.c", 23),0)));
 array->length = length;
 array->size = size;
 if (length > 0)
  array->array = ary;
 else
  array->array = ((void *)0);
}

variable_types: struct Array_T { int length; int size; char *array; } *

variable_types: length int

variable_types: size int

variable_types:
ary
void *


decompiled_code:
__int64 __fastcall Array_get(__int64 a1, int a2)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 37LL);
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
Except_raise(&Assert_Failed, "src/array.c", 38LL);
return *(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 37LL);
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
Except_raise(&Assert_Failed, "src/array.c", 38LL);
return *(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * a2;
}

original_code:
void *Array_get(Array_T array, int i) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 37),0)));
 ((void)((i >= 0 && i < array->length)||(Except_raise(&(Assert_Failed), "src/array.c", 38),0)));
 return array->array + i*array->size;
}

canonical_original_code:
void *Array_get(struct Array_T *array, int i) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 37),0)));
 ((void)((i >= 0 && i < array->length)||(Except_raise(&(Assert_Failed), "src/array.c", 38),0)));
 return array->array + i*array->size;
}


decompiled_code:
const void *__fastcall Array_put(__int64 a1, int a2, const void *a3)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 42LL);
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
Except_raise(&Assert_Failed, "src/array.c", 43LL);
if ( !a3 )
Except_raise(&Assert_Failed, "src/array.c", 44LL);
memcpy((void *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * a2), a3, *(int *)(a1 + 4));
return a3;
}

canonical_decompiled_code:
const void *__fastcall func4(__int64 a1, int a2, const void *a3)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 42LL);
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
Except_raise(&Assert_Failed, "src/array.c", 43LL);
if ( !a3 )
Except_raise(&Assert_Failed, "src/array.c", 44LL);
memcpy((void *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * a2), a3, *(int *)(a1 + 4));
return a3;
}

original_code:
void *Array_put(Array_T array, int i, void *elem) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 42),0)));
 ((void)((i >= 0 && i < array->length)||(Except_raise(&(Assert_Failed), "src/array.c", 43),0)));
 ((void)((elem)||(Except_raise(&(Assert_Failed), "src/array.c", 44),0)));
 memcpy(array->array + i*array->size, elem,
  array->size);
 return elem;
}

canonical_original_code:
void *Array_put(struct Array_T *array, int i, void *elem) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 42),0)));
 ((void)((i >= 0 && i < array->length)||(Except_raise(&(Assert_Failed), "src/array.c", 43),0)));
 ((void)((elem)||(Except_raise(&(Assert_Failed), "src/array.c", 44),0)));
 memcpy(array->array + i*array->size, elem,
  array->size);
 return elem;
}

variable_types:
elem
void *


decompiled_code:
__int64 __fastcall Array_length(unsigned int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 50LL);
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 50LL);
return *a1;
}

original_code:
int Array_length(Array_T array) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 50),0)));
 return array->length;
}

canonical_original_code:
int Array_length(struct Array_T *array) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 50),0)));
 return array->length;
}


decompiled_code:
__int64 __fastcall Array_size(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 54LL);
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 54LL);
return *(unsigned int *)(a1 + 4);
}

original_code:
int Array_size(Array_T array) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 54),0)));
 return array->size;
}

canonical_original_code:
int Array_size(struct Array_T *array) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 54),0)));
 return array->size;
}


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

if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 58LL);
if ( a2 < 0 )
{
Except_raise(&Assert_Failed, "src/array.c", 59LL);
}
else if ( !a2 )
{
result = Mem_free(*(_QWORD *)(a1 + 8), "src/array.c", 61LL);
*(_QWORD *)(a1 + 8) = 0LL;
goto LABEL_8;
}
if ( *(_DWORD *)a1 )
result = Mem_resize(*(_QWORD *)(a1 + 8), *(_DWORD *)(a1 + 4) * a2, "src/array.c", 65LL);
else
result = Mem_alloc(*(_DWORD *)(a1 + 4) * a2, "src/array.c", 63LL);
*(_QWORD *)(a1 + 8) = result;
LABEL_8:
*(_DWORD *)a1 = a2;
return result;
}

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

if ( !a1 )
Except_raise(&Assert_Failed, "src/array.c", 58LL);
if ( a2 < 0 )
{
Except_raise(&Assert_Failed, "src/array.c", 59LL);
}
else if ( !a2 )
{
result = Mem_free(*(_QWORD *)(a1 + 8), "src/array.c", 61LL);
*(_QWORD *)(a1 + 8) = 0LL;
goto LABEL_8;
}
if ( *(_DWORD *)a1 )
result = Mem_resize(*(_QWORD *)(a1 + 8), *(_DWORD *)(a1 + 4) * a2, "src/array.c", 65LL);
else
result = Mem_alloc(*(_DWORD *)(a1 + 4) * a2, "src/array.c", 63LL);
*(_QWORD *)(a1 + 8) = result;
LABEL_8:
*(_DWORD *)a1 = a2;
return result;
}

original_code:
void Array_resize(Array_T array, int length) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 58),0)));
 ((void)((length >= 0)||(Except_raise(&(Assert_Failed), "src/array.c", 59),0)));
 if (length == 0)
  ((void)(Mem_free((array->array), "src/array.c", 61), (array->array) = 0));
 else if (array->length == 0)
  array->array = Mem_alloc((length*array->size), "src/array.c", 63);
 else
  ((array->array) = Mem_resize((array->array), (length*array->size), "src/array.c", 65));
 array->length = length;
}

canonical_original_code:
void Array_resize(struct Array_T *array, int length) {
 ((void)((array)||(Except_raise(&(Assert_Failed), "src/array.c", 58),0)));
 ((void)((length >= 0)||(Except_raise(&(Assert_Failed), "src/array.c", 59),0)));
 if (length == 0)
  ((void)(Mem_free((array->array), "src/array.c", 61), (array->array) = 0));
 else if (array->length == 0)
  array->array = Mem_alloc((length*array->size), "src/array.c", 63);
 else
  ((array->array) = Mem_resize((array->array), (length*array->size), "src/array.c", 65));
 array->length = length;
}


strncmp

decompiled_code:
__int64 __fastcall strncmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
unsigned __int8 v7; // cl

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(_BYTE *)(a2 + v5);
if ( v6 != v7 )
return v6 - (unsigned int)v7;
if ( !v6 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
unsigned __int8 v7; // cl

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(_BYTE *)(a2 + v5);
if ( v6 != v7 )
return v6 - (unsigned int)v7;
if ( !v6 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return 0LL;
}

original_code:
int strncmp(const char *s1, const char *s2, size_t n) {
 for ( ; n-- > 0; s1++, s2++)
  if (*s1 != *s2)
   return (unsigned char)*s1 - (unsigned char)*s2;
  else if (*s1 == 0)
   return 0;
 return 0;
}

canonical_original_code:
int strncmp(char *s1, char *s2, unsigned long n) {
 for ( ; n-- > 0; s1++, s2++)
  if (*s1 != *s2)
   return (unsigned char)*s1 - (unsigned char)*s2;
  else if (*s1 == 0)
   return 0;
 return 0;
}


assert

decompiled_code:
void __fastcall __noreturn assert(int a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/assert.c", 5LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/assert.c", 5LL);
}

original_code:
void (assert)(int e) {
 ((void)((e)||(Except_raise(&(Assert_Failed), "src/assert.c", 5),0)));
}

canonical_original_code:
void assert(int e) {
 ((void)((e)||(Except_raise(&(Assert_Failed), "src/assert.c", 5),0)));
}

variable_types: e int


unsafe

decompiled_code:
__int64 __fastcall unsafe(int *a1)
{
int v1; // eax
int v2; // ecx

v1 = *a1 + 1;
do
v2 = v1++;
while ( v1 != *a1 + 30001 );
*a1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v1; // eax
int v2; // ecx

v1 = *a1 + 1;
do
v2 = v1++;
while ( v1 != *a1 + 30001 );
*a1 = v2;
return 0LL;
}

original_code:
int unsafe(void *cl) {
 int i, *ip = cl;
 for (i = 0; i < 30000; i++)
  *ip = *ip + 1;
 return 0;
}

canonical_original_code:
int unsafe(void *cl) {
 int i; int *ip = cl;
 for (i = 0; i < 30000; i++)
  *ip = *ip + 1;
 return 0;
}

variable_types:
cl
void *

variable_types:
ip
int *


safe

decompiled_code:
__int64 __fastcall safe(__int64 *a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = 30000;
do
{
v2 = *a1;
Sem_wait(*a1);
++*(_DWORD *)a1[1];
Sem_signal(v2);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = 30000;
do
{
v2 = *a1;
Sem_wait(*a1);
++*(_DWORD *)a1[1];
Sem_signal(v2);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
int safe(void *cl) {
 struct args *p = cl;
 int i;
 for (i = 0; i < 30000; i++)
  do { Sem_T *_yymutex = &(*p->mutex); Sem_wait(_yymutex);
   *p->ip = *p->ip + 1;
  Sem_signal(_yymutex); } while (0);
 return 0;
}

canonical_original_code:
int safe(void *cl) {
 struct args *p = cl;
 int i;
 for (i = 0; i < 30000; i++)
  do { struct Sem_T *_yymutex = &(*p->mutex); Sem_wait(_yymutex);
   *p->ip = *p->ip + 1;
  Sem_signal(_yymutex); } while (0);
 return 0;
}

variable_types: struct args { struct Sem_T { int count; void *queue; } *mutex; int *ip; } *

user_defined_types: struct args { struct Sem_T *mutex; int *ip; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int i; // ebx
unsigned int v5; // er12
int j; // ebx
char *v8; // [rsp+0h] [rbp-38h] BYREF
int *v9; // [rsp+8h] [rbp-30h]
char v10[40]; // [rsp+10h] [rbp-28h] BYREF

if ( (unsigned int)Thread_init(1LL, 0LL, envp) != 1 )
Except_raise(&Assert_Failed, "examples/spin.c", 32LL);
if ( argc <= 1 )
{
n = 0;
v3 = 5;
}
else
{
v3 = atoi(argv[1]);
n = 0;
if ( v3 <= 0 )
{
Thread_join(0LL);
v5 = 30000 * v3;
Fmt_print("%d == %d\n", (unsigned int)n, (unsigned int)(30000 * v3));
n = 0;
Sem_init(v10, 1LL);
v8 = v10;
v9 = &n;
goto LABEL_9;
}
}
for ( i = 0; i < v3; ++i )
Thread_new(unsafe, &n, 0LL, 0LL);
Thread_join(0LL);
v5 = 30000 * v3;
Fmt_print("%d == %d\n", (unsigned int)n, (unsigned int)(30000 * v3));
n = 0;
Sem_init(v10, 1LL);
v8 = v10;
v9 = &n;
for ( j = 0; j < v3; ++j )
Thread_new(safe, &v8, 16LL, 0LL);
LABEL_9:
Thread_join(0LL);
Fmt_print("%d == %d\n", (unsigned int)n, v5);
Thread_exit(0LL);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int m = 5, preempt;
 preempt = Thread_init(1, ((void *)0));
 ((void)((preempt == 1)||(Except_raise(&(Assert_Failed), "examples/spin.c", 32),0)));
 if (argc >= 2)
  m = atoi(argv[1]);
 n = 0;
 {
  int i;
  for (i = 0; i < m; i++)
   Thread_new(unsafe, &n, 0, ((void *)0));
  Thread_join(((void *)0));
 }
 Fmt_print("%d == %d\n", n, 30000*m);
 n = 0;
 {
  int i;
  struct args args;
  Sem_T mutex;
  Sem_init(&mutex, 1);
  args.mutex = &mutex;
  args.ip = &n;
  for (i = 0; i < m; i++)
   Thread_new(safe, &args, sizeof args, ((void *)0));
  Thread_join(((void *)0));
 }
 Fmt_print("%d == %d\n", n, 30000*m);
 Thread_exit(0);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int m = 5; int preempt;
 preempt = Thread_init(1, ((void *)0));
 ((void)((preempt == 1)||(Except_raise(&(Assert_Failed), "examples/spin.c", 32),0)));
 if (argc >= 2)
  m = atoi(argv[1]);
 n = 0;
 {
  int i;
  for (i = 0; i < m; i++)
   Thread_new(unsafe, &n, 0, ((void *)0));
  Thread_join(((void *)0));
 }
 Fmt_print("%d == %d\n", n, 30000*m);
 n = 0;
 {
  int i;
  struct args args;
  struct Sem_T mutex;
  Sem_init(&mutex, 1);
  args.mutex = &mutex;
  args.ip = &n;
  for (i = 0; i < m; i++)
   Thread_new(safe, &args, sizeof args, ((void *)0));
  Thread_join(((void *)0));
 }
 Fmt_print("%d == %d\n", n, 30000*m);
 Thread_exit(0);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: m int

variable_types: preempt int

variable_types: struct args { struct Sem_T { int count; void *queue; } *mutex; int *ip; }


decompiled_code:
__int64 __fastcall Integer_get(unsigned int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "examples/integer.c", 17LL);
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "examples/integer.c", 17LL);
return *a1;
}

original_code:
int Integer_get(Integer_T integer) {
 ((void)((integer)||(Except_raise(&(Assert_Failed), "examples/integer.c", 17),0)));
 return *integer;
}

canonical_original_code:
int Integer_get(int *integer) {
 ((void)((integer)||(Except_raise(&(Assert_Failed), "examples/integer.c", 17),0)));
 return *integer;
}

variable_types:
integer
int *


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

if ( !a1 )
Except_raise(&Assert_Failed, "examples/integer.c", 24LL);
result = (unsigned int)*a1;
*a1 = a2;
return result;
}

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

if ( !a1 )
Except_raise(&Assert_Failed, "examples/integer.c", 24LL);
result = (unsigned int)*a1;
*a1 = a2;
return result;
}

original_code:
int Integer_put(Integer_T integer, int n) {
 int prev;
 ((void)((integer)||(Except_raise(&(Assert_Failed), "examples/integer.c", 24),0)));
 prev = *integer;
 *integer = n;
 return prev;
}

canonical_original_code:
int Integer_put(int *integer, int n) {
 int prev;
 ((void)((integer)||(Except_raise(&(Assert_Failed), "examples/integer.c", 24),0)));
 prev = *integer;
 *integer = n;
 return prev;
}

variable_types: n int

variable_types: prev int


decompiled_code:
__int64 __fastcall Integer_cmp(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

if ( !a1 )
Except_raise(&Assert_Failed, "examples/integer.c", 31LL);
if ( !a2 )
Except_raise(&Assert_Failed, "examples/integer.c", 32LL);
result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 > *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

if ( !a1 )
Except_raise(&Assert_Failed, "examples/integer.c", 31LL);
if ( !a2 )
Except_raise(&Assert_Failed, "examples/integer.c", 32LL);
result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 > *a2;
return result;
}

original_code:
int Integer_cmp(Integer_T i1, Integer_T i2) {
 ((void)((i1)||(Except_raise(&(Assert_Failed), "examples/integer.c", 31),0)));
 ((void)((i2)||(Except_raise(&(Assert_Failed), "examples/integer.c", 32),0)));
 if (*i1 < *i2)
  return -1;
 else if (*i1 > *i2)
  return +1;
 else
  return 0;
}

canonical_original_code:
int Integer_cmp(int *i1, int *i2) {
 ((void)((i1)||(Except_raise(&(Assert_Failed), "examples/integer.c", 31),0)));
 ((void)((i2)||(Except_raise(&(Assert_Failed), "examples/integer.c", 32),0)));
 if (*i1 < *i2)
  return -1;
 else if (*i1 > *i2)
  return +1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall Integer_fmt(__int64 a1, int *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6, unsigned int a7)
{
unsigned int v11; // eax
unsigned int **v12; // rdx
unsigned int *v13; // rbx
unsigned int v14; // eax
char v16[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !a2 || !a5 )
Except_raise(&Assert_Failed, "examples/integer.c", 48LL);
v11 = *a2;
if ( (unsigned int)*a2 > 0x2F )
{
v12 = (unsigned int **)*((_QWORD *)a2 + 1);
*((_QWORD *)a2 + 1) = v12 + 1;
}
else
{
v12 = (unsigned int **)(*((_QWORD *)a2 + 2) + v11);
*a2 = v11 + 8;
}
v13 = *v12;
if ( !*v12 )
Except_raise(&Assert_Failed, "examples/integer.c", 50LL);
v14 = Fmt_sfmt(v16, 44LL, "%d", *v13);
return Fmt_putd(v16, v14, a3, a4, a5, a6, a7);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6, unsigned int a7)
{
unsigned int v11; // eax
unsigned int **v12; // rdx
unsigned int *v13; // rbx
unsigned int v14; // eax
char v16[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !a2 || !a5 )
Except_raise(&Assert_Failed, "examples/integer.c", 48LL);
v11 = *a2;
if ( (unsigned int)*a2 > 0x2F )
{
v12 = (unsigned int **)*((_QWORD *)a2 + 1);
*((_QWORD *)a2 + 1) = v12 + 1;
}
else
{
v12 = (unsigned int **)(*((_QWORD *)a2 + 2) + v11);
*a2 = v11 + 8;
}
v13 = *v12;
if ( !*v12 )
Except_raise(&Assert_Failed, "examples/integer.c", 50LL);
v14 = Fmt_sfmt(v16, 44LL, "%d", *v13);
return Fmt_putd(v16, v14, a3, a4, a5, a6, a7);
}

original_code:
void Integer_fmt(int code, va_list_box *box,
 int put(int c, void *cl), void *cl,
 unsigned char flags[], int width, int precision) {
 char buf[44];
 Integer_T integer;
 ((void)((box && flags)||(Except_raise(&(Assert_Failed), "examples/integer.c", 48),0)));
 integer = __builtin_va_arg(box->ap,Integer_T);
 ((void)((integer)||(Except_raise(&(Assert_Failed), "examples/integer.c", 50),0)));
  Fmt_putd(buf, Fmt_sfmt(buf, sizeof buf, "%d", *integer),
  put, cl, flags, width, precision);
}

canonical_original_code:
void Integer_fmt(int code, struct va_list_box *box, int put(int c, void *cl), void *cl, unsigned char flags[], int width, int precision) {
 char buf[44];
 int *integer;
 ((void)((box && flags)||(Except_raise(&(Assert_Failed), "examples/integer.c", 48),0)));
 integer = __builtin_va_arg(box->ap,Integer_T);
 ((void)((integer)||(Except_raise(&(Assert_Failed), "examples/integer.c", 50),0)));
  Fmt_putd(buf, Fmt_sfmt(buf, sizeof buf, "%d", *integer),
  put, cl, flags, width, precision);
}

variable_types: code int

variable_types: struct va_list_box { __builtin_va_list ap; } *

variable_types:
put
int (int c, void *cl)

variable_types:
flags
unsigned char []

variable_types: width int

variable_types: precision int

variable_types:
buf
char [44]


dirname

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

v3 = Str_rchr(a1, a2, a3, 47LL);
if ( v3 <= 0 )
result = Str_dup(&unk_172, 1LL, 0LL, 1LL);
else
result = Str_dup(a1, (unsigned int)a2, (unsigned int)(v3 + 1), 1LL);
return result;
}

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

v3 = Str_rchr(a1, a2, a3, 47LL);
if ( v3 <= 0 )
result = Str_dup(&unk_172, 1LL, 0LL, 1LL);
else
result = Str_dup(a1, (unsigned int)a2, (unsigned int)(v3 + 1), 1LL);
return result;
}

original_code:
char *dirname(char *path, int i, int j) {
 if ((j = Str_rchr(path, i, j, '/')) > 0)
  return Str_dup(path, i, j + 1, 1);
 else
  return Str_dup("./", 1, 0, 1);
}

variable_types:
path
char *

variable_types: i int

variable_types: j int


basename

decompiled_code:
__int64 __fastcall basename(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rbp
unsigned int v6; // eax

v5 = (unsigned int)Str_rchr(a1, a2, a3, 47LL) + 1;
v6 = Str_rmatch(a1, v5, 0LL, a4);
return Str_dup(a1, (unsigned int)v5, v6, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rbp
unsigned int v6; // eax

v5 = (unsigned int)Str_rchr(a1, a2, a3, 47LL) + 1;
v6 = Str_rmatch(a1, v5, 0LL, a4);
return Str_dup(a1, (unsigned int)v5, v6, 1LL);
}

original_code:
char *basename(char *path, int i, int j, const char *suffix) {
 i = Str_rchr(path, i, j, '/');
 j = Str_rmatch(path, i + 1, 0, suffix);
 return Str_dup(path, i + 1, j, 1);
}

canonical_original_code:
char *basename(char *path, int i, int j, char *suffix) {
 i = Str_rchr(path, i, j, '/');
 j = Str_rmatch(path, i + 1, 0, suffix);
 return Str_dup(path, i + 1, j, 1);
}

variable_types:
suffix
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx
const char *v4; // rax
__int64 *v6; // rbx
int v7; // ebp
const char *v8; // rax
void *v9; // rcx

if ( (int)Str_find(*argv, 1LL, 0LL, "dirname") <= 0 )
{
if ( argc > 1 )
{
v6 = (__int64 *)(argv + 1);
v7 = 2;
do
{
v9 = &unk_175;
if ( argc > v7 )
v9 = (void *)v6[1];
v8 = (const char *)basename(*v6, 1LL, 0LL, (__int64)v9);
Fmt_print("%s\n", v8);
v7 += 2;
v6 += 2;
}
while ( v7 != ((argc - 2) & 0xFFFFFFFE) + 4 );
}
}
else if ( argc > 1 )
{
v3 = (__int64 *)(argv + 1);
do
{
v4 = (const char *)dirname(*v3, 1LL, 0LL);
Fmt_print("%s\n", v4);
v3 += 2;
}
while ( v3 != (__int64 *)&argv[2 * ((unsigned int)(argc - 2) >> 1) + 3] );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx
const char *v4; // rax
__int64 *v6; // rbx
int v7; // ebp
const char *v8; // rax
void *v9; // rcx

if ( (int)Str_find(*argv, 1LL, 0LL, "dirname") <= 0 )
{
if ( argc > 1 )
{
v6 = (__int64 *)(argv + 1);
v7 = 2;
do
{
v9 = &unk_175;
if ( argc > v7 )
v9 = (void *)v6[1];
v8 = (const char *)func1(*v6, 1LL, 0LL, (__int64)v9);
Fmt_print("%s\n", v8);
v7 += 2;
v6 += 2;
}
while ( v7 != ((argc - 2) & 0xFFFFFFFE) + 4 );
}
}
else if ( argc > 1 )
{
v3 = (__int64 *)(argv + 1);
do
{
v4 = (const char *)func0(*v3, 1LL, 0LL);
Fmt_print("%s\n", v4);
v3 += 2;
}
while ( v3 != (__int64 *)&argv[2 * ((unsigned int)(argc - 2) >> 1) + 3] );
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int i;
 if (Str_find(argv[0], 1, 0, "dirname") > 0)
  for (i = 1; i < argc; i += 2)
   Fmt_print("%s\n", dirname(argv[i], 1, 0));
 else
  for (i = 1; i < argc; i += 2)
   Fmt_print("%s\n", basename(argv[i], 1, 0, i+1 < argc ? argv[i+1] : ""));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


pop

decompiled_code:
__int64 pop()
{
if ( !(unsigned int)Stack_empty(qword_628) )
return Stack_pop(qword_628);
Fmt_fprint(stderr, "?stack underflow\n");
return AP_new(0LL);
}

canonical_decompiled_code:
__int64 func0()
{
if ( !(unsigned int)Stack_empty(qword_628) )
return Stack_pop(qword_628);
Fmt_fprint(stderr, "?stack underflow\n");
return AP_new(0LL);
}

original_code:
MP_T pop(void) {
 if (Seq_length(sp) > 0)
  return Seq_remhi(sp);
 else {
  Fmt_fprint(stderr, "?stack underflow\n");
  return MP_new(0);
 }
}

canonical_original_code:
unsigned char *pop() {
 if (Seq_length(sp) > 0)
  return Seq_remhi(sp);
 else {
  Fmt_fprint(stderr, "?stack underflow\n");
  return MP_new(0);
 }
}

return_type: unsigned char *


first

decompiled_code:
__int64 __fastcall first(int a1)
{
return (*_ctype_b_loc())[a1] & 0x400;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (*_ctype_b_loc())[a1] & 0x400;
}

original_code:
int first(int c) {
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha);
}

canonical_original_code:
int first(int c) {
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha);
}

variable_types: c int


rest

original_code:
int rest(int c) {
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) || c == '_';
}

canonical_original_code:
int rest(int c) {
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) || c == '_';
}


compare

decompiled_code:
int __fastcall compare(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func3(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
int compare(const void *x, const void *y) {
 return strcmp(*(char **)x, *(char **)y);
}

canonical_original_code:
int compare(void *x, void *y) {
 return strcmp(*(char **)x, *(char **)y);
}

variable_types:
x
void *

variable_types:
y
void *


texthash

original_code:
unsigned texthash(const void *x) {
 int i;
 unsigned h = 0;
 const Text_T *t = x;
 for (i = 0; i < t->len; i++)
  h = (h<<1) + t->str[i];
 return h;
}

canonical_original_code:
unsigned int texthash(void *x) {
 int i;
 unsigned int h = 0;
 struct Text_T *t = x;
 for (i = 0; i < t->len; i++)
  h = (h<<1) + t->str[i];
 return h;
}

variable_types:
h
unsigned int

variable_types:
t
struct Text_T { int len; char *str; } *


textcmp

decompiled_code:
__int64 __fastcall textcmp(unsigned int *a1, unsigned int *a2)
{
return Text_cmp(*a1, *((_QWORD *)a1 + 1), *a2, *((_QWORD *)a2 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int *a2)
{
return Text_cmp(*a1, *((_QWORD *)a1 + 1), *a2, *((_QWORD *)a2 + 1));
}

original_code:
int textcmp(const void *x, const void *y) {
 return Text_cmp(*(Text_T *)x, *(Text_T *)y);
}

canonical_original_code:
int textcmp(void *x, void *y) {
 return Text_cmp(*(struct Text_T *)x, *(struct Text_T *)y);
}


repo: niedbalski/libbacktesting

decompiled_code:
__int64 __fastcall add_condition(int a1, __m128i a2)
{
int v3; // ebp
_QWORD *v4; // rbx
void *v5; // rdi
__int64 v6; // rax
__int64 result; // rax
_DWORD *v8; // rax

v3 = _mm_cvtsi128_si32(a2);
v4 = context;
v5 = (void *)*((_QWORD *)context + 2);
if ( v5 )
{
v4[2] = realloc(v5, 8LL * *((_QWORD *)context + 4) + 8);
v6 = *((_QWORD *)context + 2);
if ( v6 )
{
*(_DWORD *)(v6 + 8LL * *((_QWORD *)context + 4)) = a1;
*(_DWORD *)(*((_QWORD *)context + 2) + 8LL * *((_QWORD *)context + 4) + 4) = v3;
LABEL_4:
++*((_QWORD *)context + 4);
return 0LL;
}
result = 0xFFFFFFFFLL;
}
else
{
v8 = malloc(8uLL);
v4[2] = v8;
if ( v8 )
{
*v8 = a1;
*(_DWORD *)(v4[2] + 4LL) = v3;
goto LABEL_4;
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __m128i a2)
{
int v3; // ebp
_QWORD *v4; // rbx
void *v5; // rdi
__int64 v6; // rax
__int64 result; // rax
_DWORD *v8; // rax

v3 = _mm_cvtsi128_si32(a2);
v4 = context;
v5 = (void *)*((_QWORD *)context + 2);
if ( v5 )
{
v4[2] = realloc(v5, 8LL * *((_QWORD *)context + 4) + 8);
v6 = *((_QWORD *)context + 2);
if ( v6 )
{
*(_DWORD *)(v6 + 8LL * *((_QWORD *)context + 4)) = a1;
*(_DWORD *)(*((_QWORD *)context + 2) + 8LL * *((_QWORD *)context + 4) + 4) = v3;
LABEL_4:
++*((_QWORD *)context + 4);
return 0LL;
}
result = 0xFFFFFFFFLL;
}
else
{
v8 = malloc(8uLL);
v4[2] = v8;
if ( v8 )
{
*v8 = a1;
*(_DWORD *)(v4[2] + 4LL) = v3;
goto LABEL_4;
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static inline int add_condition(enum PRICE_CONDITION type, float value)
{
    if(context->conditions == ((void *)0)) {
        context->conditions = malloc(sizeof(price_condition));
        if(context->conditions == ((void *)0))
            return -1;
        context->conditions[0].type = type;
        context->conditions[0].value = value;
    } else {
        context->conditions = realloc(context->conditions, sizeof(price_condition) * (context->current_conditions + 1));
        if(context->conditions == ((void *)0))
            return -1;
        context->conditions[context->current_conditions].type = type;
        context->conditions[context->current_conditions].value = value;
    }
    context->current_conditions += 1;
    return 0;
}

variable_types: enum PRICE_CONDITION { LOWER_THAN=0, LOWER_AND_EQUALS_TO=1, GREATER_THAN=2, GREATER_AND_EQUALS_TO=3, EQUALS_TO=4 }

variable_types: value float


decompiled_code:
__int64 __fastcall add_lower_than_condition(__m128i a1)
{
__int64 v1; // rdx
__int64 result; // rax

if ( *((_QWORD *)context + 4) == 1LL
&& (v1 = *((_QWORD *)context + 2), (unsigned int)(*(_DWORD *)v1 - 2) <= 1)
&& *(float *)(v1 + 4) > *(float *)a1.m128i_i32 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = add_condition(0, a1);
}
return result;
}

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

if ( *((_QWORD *)context + 4) == 1LL
&& (v1 = *((_QWORD *)context + 2), (unsigned int)(*(_DWORD *)v1 - 2) <= 1)
&& *(float *)(v1 + 4) > *(float *)a1.m128i_i32 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = func0(0, a1);
}
return result;
}

original_code:
static inline int add_lower_than_condition(float value)
{
    struct price_condition previous_condition;
    if ( context->current_conditions == 1 ) {
        previous_condition = context->conditions[0];
        if ( previous_condition.type == GREATER_THAN || previous_condition.type == GREATER_AND_EQUALS_TO) {
            if ( value < previous_condition.value )
                return -1;
        }
    }
    return add_condition(LOWER_THAN, value);
}

variable_types: struct price_condition { enum PRICE_CONDITION { LOWER_THAN=0, LOWER_AND_EQUALS_TO=1, GREATER_THAN=2, GREATER_AND_EQUALS_TO=3, EQUALS_TO=4 } type; float value; }

user_defined_types: struct price_condition { enum PRICE_CONDITION type; float value; }


decompiled_code:
__int64 __fastcall add_greater_than_condition(__m128i a1)
{
__int64 v1; // rax
__int64 result; // rax

if ( *((_QWORD *)context + 4)
&& (v1 = *((_QWORD *)context + 2), *(_DWORD *)v1 <= 1u)
&& *(float *)a1.m128i_i32 > *(float *)(v1 + 4) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = add_condition(2, a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__m128i a1)
{
__int64 v1; // rax
__int64 result; // rax

if ( *((_QWORD *)context + 4)
&& (v1 = *((_QWORD *)context + 2), *(_DWORD *)v1 <= 1u)
&& *(float *)a1.m128i_i32 > *(float *)(v1 + 4) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = func0(2, a1);
}
return result;
}

original_code:
static inline int add_greater_than_condition(float value)
{
    struct price_condition previous_condition;
    if( context->current_conditions ) {
        previous_condition = context->conditions[0];
        if ( previous_condition.type == LOWER_THAN || previous_condition.type == LOWER_AND_EQUALS_TO) {
            if ( value > previous_condition.value ) {
                return -1;
            }
        }
    }
    return add_condition(GREATER_THAN, value);
}

user_defined_types: enum PRICE_CONDITION { LOWER_THAN=0, LOWER_AND_EQUALS_TO=1, GREATER_THAN=2, GREATER_AND_EQUALS_TO=3, EQUALS_TO=4 }


decompiled_code:
__int64 __fastcall add_greater_and_equals_condition(__m128i a1)
{
__int64 v1; // rax
__int64 result; // rax

if ( *((_QWORD *)context + 4) == 1LL
&& (v1 = *((_QWORD *)context + 2), *(_DWORD *)v1 <= 1u)
&& *(float *)a1.m128i_i32 >= *(float *)(v1 + 4) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = add_condition(3, a1);
}
return result;
}

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

if ( *((_QWORD *)context + 4) == 1LL
&& (v1 = *((_QWORD *)context + 2), *(_DWORD *)v1 <= 1u)
&& *(float *)a1.m128i_i32 >= *(float *)(v1 + 4) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = func0(3, a1);
}
return result;
}

original_code:
static inline int add_greater_and_equals_condition(float value)
{
    struct price_condition previous_condition;
    if( context->current_conditions == 1) {
        previous_condition = context->conditions[0];
        if ( previous_condition.type == LOWER_THAN || previous_condition.type == LOWER_AND_EQUALS_TO){
            if ( value >= previous_condition.value )
                return -1;
        }
    }
    return add_condition(GREATER_AND_EQUALS_TO, value);
}


decompiled_code:
__int64 __fastcall add_equals_condition(__m128i a1)
{
return add_condition(4, a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__m128i a1)
{
return func0(4, a1);
}

original_code:
static inline int add_equals_condition(float value) {
    return add_condition(EQUALS_TO, value);
}


decompiled_code:
void **backtest_file_get_ctx()
{
return &context;
}

canonical_decompiled_code:
void **func6()
{
return &context;
}

original_code:
file_context *backtest_file_get_ctx(void) {
    return (file_context *)&context;
}

canonical_original_code:
struct file_context *backtest_file_get_ctx() {
    return (struct file_context *)&context;
}

return_type: struct file_context { char *filename; enum FILE_TYPE { BACKTEST_FILE_CSV=0, BACKTEST_FILE_TXT=1 } file_type; struct price_condition { enum PRICE_CONDITION { LOWER_THAN=0, LOWER_AND_EQUALS_TO=1, GREATER_THAN=2, GREATER_AND_EQUALS_TO=3, EQUALS_TO=4 } type; float value; } *conditions; char *mapped; unsigned long current_conditions; unsigned long mapped_size; } *

user_defined_types: struct file_context { char *filename; enum FILE_TYPE file_type; struct price_condition *conditions; char *mapped; unsigned long current_conditions; unsigned long mapped_size; }


decompiled_code:
__int64 __fastcall backtest_evaluate_conditions(float a1)
{
__int64 v2; // rdi
__int64 v3; // rcx
__int64 v4; // rax
float v5; // xmm0_4
__int64 result; // rax

v2 = *((_QWORD *)context + 4);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *((_QWORD *)context + 2);
v4 = 0LL;
while ( 2 )
{
v5 = *(float *)(v3 + 8 * v4 + 4);
switch ( *(_DWORD *)(v3 + 8 * v4) )
{
case 0:
if ( v5 > a1 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 1:
if ( v5 >= a1 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 2:
if ( a1 > v5 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 3:
if ( a1 >= v5 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 4:
if ( v5 == a1 )
{
LABEL_4:
if ( v2 != ++v4 )
continue;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(float a1)
{
__int64 v2; // rdi
__int64 v3; // rcx
__int64 v4; // rax
float v5; // xmm0_4
__int64 result; // rax

v2 = *((_QWORD *)context + 4);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *((_QWORD *)context + 2);
v4 = 0LL;
while ( 2 )
{
v5 = *(float *)(v3 + 8 * v4 + 4);
switch ( *(_DWORD *)(v3 + 8 * v4) )
{
case 0:
if ( v5 > a1 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 1:
if ( v5 >= a1 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 2:
if ( a1 > v5 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 3:
if ( a1 >= v5 )
goto LABEL_4;
result = 0xFFFFFFFFLL;
break;
case 4:
if ( v5 == a1 )
{
LABEL_4:
if ( v2 != ++v4 )
continue;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}
}

original_code:
int backtest_evaluate_conditions(float value)
{
    price_condition condition;
    int i;
    if(! context->current_conditions ) {
        return -1;
    }
    for(i = 0; i <= context->current_conditions - 1; i++) {
        condition = context->conditions[i];
        switch(condition.type) {
        case LOWER_THAN:
            if(!(value < condition.value)) {
                return -1;
            }
            break;
        case LOWER_AND_EQUALS_TO:
            if(!(value <= condition.value)) {
                return -1;
            }
            break;
        case GREATER_THAN:
            if(!(value > condition.value)) {
                return -1;
            }
            break;
        case GREATER_AND_EQUALS_TO:
            if(!(value >= condition.value)) {
                return -1;
            }
            break;
        case EQUALS_TO:
            if(!(value == condition.value)) {
                return -1;
            }
            break;
        default:
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int backtest_evaluate_conditions(float value)
{
    struct price_condition condition;
    int i;
    if(! context->current_conditions ) {
        return -1;
    }
    for(i = 0; i <= context->current_conditions - 1; i++) {
        condition = context->conditions[i];
        switch(condition.type) {
        case LOWER_THAN:
            if(!(value < condition.value)) {
                return -1;
            }
            break;
        case LOWER_AND_EQUALS_TO:
            if(!(value <= condition.value)) {
                return -1;
            }
            break;
        case GREATER_THAN:
            if(!(value > condition.value)) {
                return -1;
            }
            break;
        case GREATER_AND_EQUALS_TO:
            if(!(value >= condition.value)) {
                return -1;
            }
            break;
        case EQUALS_TO:
            if(!(value == condition.value)) {
                return -1;
            }
            break;
        default:
            return -1;
        }
    }
    return 0;
}


decompiled_code:
__int64 __fastcall backtest_add_price_condition(int a1, float a2)
{
__int64 result; // rax

if ( *((_QWORD *)context + 4) > 1uLL && a1 != 4 )
return 0xFFFFFFFFLL;
switch ( a1 )
{
case 0:
result = add_lower_than_condition((__m128i)LODWORD(a2));
break;
case 1:
add_lower_and_equals_condition((__m128i)LODWORD(a2));
goto LABEL_6;
case 2:
LABEL_6:
result = add_greater_than_condition((__m128i)LODWORD(a2));
break;
case 3:
result = add_greater_and_equals_condition((__m128i)LODWORD(a2));
break;
case 4:
result = add_equals_condition((__m128i)LODWORD(a2));
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

if ( *((_QWORD *)context + 4) > 1uLL && a1 != 4 )
return 0xFFFFFFFFLL;
switch ( a1 )
{
case 0:
result = func1((__m128i)LODWORD(a2));
break;
case 1:
func2((__m128i)LODWORD(a2));
goto LABEL_6;
case 2:
LABEL_6:
result = func3((__m128i)LODWORD(a2));
break;
case 3:
result = func4((__m128i)LODWORD(a2));
break;
case 4:
result = func5((__m128i)LODWORD(a2));
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int backtest_add_price_condition(enum PRICE_CONDITION price_condition, float value)
{
    int ret;
    if ( context->current_conditions >= 2 && price_condition != EQUALS_TO)
        return -1;
    switch(price_condition) {
    case LOWER_THAN:
        ret = add_lower_than_condition(value);
        break;
    case LOWER_AND_EQUALS_TO:
        ret = add_lower_and_equals_condition(value);
    case GREATER_THAN:
        ret = add_greater_than_condition(value);
        break;
    case GREATER_AND_EQUALS_TO:
        ret = add_greater_and_equals_condition(value);
        break;
    case EQUALS_TO:
        ret = add_equals_condition(value);
        break;
    default:
        ret = -1;
        break;
    }
    return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall backtest_file_init(char *file, int a2)
{
unsigned int v2; // ebp
int v3; // er13
_QWORD *v4; // rbx
_DWORD *v5; // rax
struct stat v7; // [rsp+0h] [rbp-B8h] BYREF

if ( stat(file, &v7) )
return (unsigned int)-1;
v2 = 0;
if ( !v7.st_size )
return (unsigned int)-1;
v3 = open(file, 0);
if ( v3 == -1 )
return (unsigned int)-1;
v4 = malloc(0x30uLL);
context = v4;
if ( !v4 )
return (unsigned int)-1;
v4[3] = mmap(0LL, v7.st_size, 1, 2, v3, 0LL);
v5 = context;
if ( !*((_QWORD *)context + 3) )
return (unsigned int)-1;
*((_QWORD *)context + 5) = v7.st_size;
v5[2] = a2;
*((_QWORD *)v5 + 2) = 0LL;
*((_QWORD *)v5 + 4) = 0LL;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *file, int a2)
{
unsigned int v2; // ebp
int v3; // er13
_QWORD *v4; // rbx
_DWORD *v5; // rax
struct stat v7; // [rsp+0h] [rbp-B8h] BYREF

if ( stat(file, &v7) )
return (unsigned int)-1;
v2 = 0;
if ( !v7.st_size )
return (unsigned int)-1;
v3 = open(file, 0);
if ( v3 == -1 )
return (unsigned int)-1;
v4 = malloc(0x30uLL);
context = v4;
if ( !v4 )
return (unsigned int)-1;
v4[3] = mmap(0LL, v7.st_size, 1, 2, v3, 0LL);
v5 = context;
if ( !*((_QWORD *)context + 3) )
return (unsigned int)-1;
*((_QWORD *)context + 5) = v7.st_size;
v5[2] = a2;
*((_QWORD *)v5 + 2) = 0LL;
*((_QWORD *)v5 + 4) = 0LL;
return v2;
}

original_code:
int backtest_file_init(const char *filename, enum FILE_TYPE file_type)
{
    struct stat st;
    int r, fd;
    if( (r = stat(filename, &st)) != 0) {
        ;
        return -1;
    }
    if ( st.st_size == 0 ) {
        ;
        return -1;
    }
    fd = open(filename, 00);
    if ( fd == -1 ) {
        ;
        return -1;
    }
    context = malloc(sizeof(file_context));
    if(context == ((void *)0))
        return -1;
    context->mapped = (char *)mmap(((void *)0), st.st_size, 0x1, 0x02, fd, 0);
    if(context->mapped == ((void *)0)) {
        ;
        return -1;
    }
    context->mapped_size = st.st_size;
    context->file_type = file_type;
    context->conditions = ((void *)0);
    context->current_conditions = 0;
    return 0;
}

canonical_original_code:
int backtest_file_init(char *filename, enum FILE_TYPE file_type)
{
    struct stat st;
    int r; int fd;
    if( (r = stat(filename, &st)) != 0) {
        ;
        return -1;
    }
    if ( st.st_size == 0 ) {
        ;
        return -1;
    }
    fd = open(filename, 00);
    if ( fd == -1 ) {
        ;
        return -1;
    }
    context = malloc(sizeof(file_context));
    if(context == ((void *)0))
        return -1;
    context->mapped = (char *)mmap(((void *)0), st.st_size, 0x1, 0x02, fd, 0);
    if(context->mapped == ((void *)0)) {
        ;
        return -1;
    }
    context->mapped_size = st.st_size;
    context->file_type = file_type;
    context->conditions = ((void *)0);
    context->current_conditions = 0;
    return 0;
}

variable_types:
filename
char *

variable_types: enum FILE_TYPE { BACKTEST_FILE_CSV=0, BACKTEST_FILE_TXT=1 }

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: r int

variable_types: fd int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void backtest_file_destroy()
{
void *v0; // rdi
void *v1; // rdi

v0 = (void *)*((_QWORD *)context + 3);
if ( v0 )
munmap(v0, *((_QWORD *)context + 5));
v1 = (void *)*((_QWORD *)context + 2);
if ( v1 )
free(v1);
free(context);
}

canonical_decompiled_code:
void func10()
{
void *v0; // rdi
void *v1; // rdi

v0 = (void *)*((_QWORD *)context + 3);
if ( v0 )
munmap(v0, *((_QWORD *)context + 5));
v1 = (void *)*((_QWORD *)context + 2);
if ( v1 )
free(v1);
free(context);
}

original_code:
void backtest_file_destroy(void) {
    if(context->mapped)
        munmap(context->mapped, context->mapped_size);
    if(context->conditions != ((void *)0))
        free(context->conditions);
    free(context);
}

canonical_original_code:
void backtest_file_destroy() {
    if(context->mapped)
        munmap(context->mapped, context->mapped_size);
    if(context->conditions != ((void *)0))
        free(context->conditions);
    free(context);
}


decompiled_code:
__int64 __fastcall list_find(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD, __int64))
{
_QWORD *v3; // rbx
__int64 result; // rax

v3 = a1;
if ( !a1 )
return 0xFFFFFFFFLL;
while ( 1 )
{
result = a3(*v3, a2);
if ( !(_DWORD)result )
break;
v3 = (_QWORD *)v3[2];
if ( !v3 )
return 0xFFFFFFFFLL;
}
return result;
}

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

v3 = a1;
if ( !a1 )
return 0xFFFFFFFFLL;
while ( 1 )
{
result = a3(*v3, a2);
if ( !(_DWORD)result )
break;
v3 = (_QWORD *)v3[2];
if ( !v3 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int list_find(list *head, const char *key, compare_function compare)
{
    list *current;
    current = head;
    while(current != ((void *)0)) {
        if((int)compare(current->key, key) == 0)
            return 0;
        current = current->next;
    }
    return -1;
}

canonical_original_code:
int list_find(struct list *head, char *key, int (*compare)(char *primary, char *secondary))
{
    struct list *current;
    current = head;
    while(current != ((void *)0)) {
        if((int)compare(current->key, key) == 0)
            return 0;
        current = current->next;
    }
    return -1;
}

variable_types: struct list { char *key; void *value; struct list *next; } *

variable_types:
key
char *

variable_types:
compare
int (*)(char *primary, char *secondary)