decompiled_code:
__int64 __fastcall in_array(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // r8
unsigned int i; // eax
int v5; // ecx

if ( a1 <= 0 )
return 0LL;
v1 = new_array_of_size();
v2 = *(_QWORD *)(v1 + 8);
v3 = v1;
for ( i = 1; i <= a1; ++i )
{
v5 = 3 * i;
v2 += 4LL;
*(_DWORD *)(v2 - 4) = v5;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // r8
unsigned int i; // eax
int v5; // ecx

if ( a1 <= 0 )
return 0LL;
v1 = new_array_of_size();
v2 = *(_QWORD *)(v1 + 8);
v3 = v1;
for ( i = 1; i <= a1; ++i )
{
v5 = 3 * i;
v2 += 4LL;
*(_DWORD *)(v2 - 4) = v5;
}
return v3;
}

original_code:
array *in_array(int freevars) {
  array *rv=((void *)0);
  if (freevars>0) {
    unsigned int i=1;
    rv=new_array_of_size(freevars);
    for (; i<=freevars; i++)
      rv->content[i-1]=((i-1)*3+3);
  }
  return rv;
}

canonical_original_code:
struct array *in_array(int freevars) {
  struct array *rv = ((void *)0);
  if (freevars>0) {
    unsigned int i = 1;
    rv=new_array_of_size(freevars);
    for (; i<=freevars; i++)
      rv->content[i-1]=((i-1)*3+3);
  }
  return rv;
}

variable_types: struct array { unsigned int length; int *content; } *

variable_types:
i
unsigned int


repo: kuebler/enum

original_code:
sat_state assume_exactly(solver *s, int *assumptions, int n, int length) {
  int i=0;
  for (; i<length; i++) {
    s->assume((i<n ? assumptions[i] : -assumptions[i]));
  }
  return s->sat();
}

canonical_original_code:
enum sat_state assume_exactly(struct solver *s, int *assumptions, int n, int length) {
  int i = 0;
  for (; i<length; i++) {
    s->assume((i<n ? assumptions[i] : -assumptions[i]));
  }
  return s->sat();
}

variable_types: struct solver { void (*add)(int lit); enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 } (*sat)(); enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 } (*sat_assum)(int *, int); enum lit_value { L_FALSE=-1, L_UNKNOWN=0, L_TRUE=1 } (*lit_deref)(int); void (*assume)(int); } *

variable_types:
assumptions
int *

variable_types: n int

variable_types: length int

variable_types: i int

user_defined_types: struct solver { void (*add)(int lit); enum sat_state (*sat)(); enum sat_state (*sat_assum)(int *, int); enum lit_value (*lit_deref)(int); void (*assume)(int); }


enumerate

original_code:
void enumerate(solver *s, array *sout, int freevars, int count) {
  sat_state rv=s->sat();
  int i=freevars, fvclause[freevars];
  mpz_t models, inc;
  if (freevars <= 0 || rv==ST_UNSAT) {
    if (rv==ST_UNSAT)
      puts("rv==ST_UNSAT");
    if (freevars<=0)
      puts("freevars<=0");
    printf("%s\n", rv==ST_SAT ? (count ? "T\nc INFINITE" : "T")
                              : (rv==ST_UNSAT ? (count ? "F\n c 0" : "F")
                                              : "?"));
    return;
  }
  __gmpz_init(models); __gmpz_init(inc);
  for (; i>=0; i--)
    while (assume_exactly(s, sout->content, i, freevars)==ST_SAT) {
      int j=1, cnt=0;
      if (i==freevars) {
        puts("T");
        if (count)
          do { __gmpz_set_ui(inc, 1UL); __gmpz_mul_2exp(inc, inc, i); __gmpz_add(models, models, inc); __gmp_printf("c currently found %Zd models\n", models); } while (0);
        __gmpz_clears(models, inc, ((void *)0));
        return;
      }
      for (; j<=freevars; j++)
        if (s->lit_deref(((j-1)*3+3))!=L_TRUE) {
          if (s->lit_deref(((j-1)*3+1))==L_TRUE) {
            printf("%d ", j);
            fvclause[cnt++]=((j-1)*3+2);
          }
          else {
            printf("-%d ", j);
            fvclause[cnt++]=((j-1)*3+1);
          }
        }
      putchar('\n');
      for (j=0; j<cnt; j++)
        s->add(fvclause[j]);
      s->add(0);
      if (count)
        do { __gmpz_set_ui(inc, 1UL); __gmpz_mul_2exp(inc, inc, i); __gmpz_add(models, models, inc); __gmp_printf("c currently found %Zd models\n", models); } while (0);
    }
  __gmpz_clears(models, inc, ((void *)0));
}

canonical_original_code:
void enumerate(struct solver *s, struct array *sout, int freevars, int count) {
  enum sat_state rv = s->sat();
  int i = freevars; int fvclause[-1];
  struct __mpz_struct models[1]; struct __mpz_struct inc[1];
  if (freevars <= 0 || rv==ST_UNSAT) {
    if (rv==ST_UNSAT)
      puts("rv==ST_UNSAT");
    if (freevars<=0)
      puts("freevars<=0");
    printf("%s\n", rv==ST_SAT ? (count ? "T\nc INFINITE" : "T")
                              : (rv==ST_UNSAT ? (count ? "F\n c 0" : "F")
                                              : "?"));
    return;
  }
  __gmpz_init(models); __gmpz_init(inc);
  for (; i>=0; i--)
    while (assume_exactly(s, sout->content, i, freevars)==ST_SAT) {
      int j = 1; int cnt = 0;
      if (i==freevars) {
        puts("T");
        if (count)
          do { __gmpz_set_ui(inc, 1UL); __gmpz_mul_2exp(inc, inc, i); __gmpz_add(models, models, inc); __gmp_printf("c currently found %Zd models\n", models); } while (0);
        __gmpz_clears(models, inc, ((void *)0));
        return;
      }
      for (; j<=freevars; j++)
        if (s->lit_deref(((j-1)*3+3))!=L_TRUE) {
          if (s->lit_deref(((j-1)*3+1))==L_TRUE) {
            printf("%d ", j);
            fvclause[cnt++]=((j-1)*3+2);
          }
          else {
            printf("-%d ", j);
            fvclause[cnt++]=((j-1)*3+1);
          }
        }
      putchar('\n');
      for (j=0; j<cnt; j++)
        s->add(fvclause[j]);
      s->add(0);
      if (count)
        do { __gmpz_set_ui(inc, 1UL); __gmpz_mul_2exp(inc, inc, i); __gmpz_add(models, models, inc); __gmp_printf("c currently found %Zd models\n", models); } while (0);
    }
  __gmpz_clears(models, inc, ((void *)0));
}

variable_types: freevars int

variable_types: count int

variable_types: enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 }

variable_types:
fvclause
int [-1]

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types: j int

variable_types: cnt int

return_type: void

user_defined_types: struct array { unsigned int length; int *content; }

user_defined_types: enum lit_value { L_FALSE=-1, L_UNKNOWN=0, L_TRUE=1 }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v3 = parse_dimacs(stdin, &picosat, v5);
enumerate((__int64)&picosat, v3, v5[0], 1);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v3 = func15(stdin, &picosat, v5);
func17((__int64)&picosat, v3, v5[0], 1);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int freevars=0;
    array *sout=parse_dimacs(stdin, &picosat, &freevars);
  enumerate(&picosat, sout, freevars, 1);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int freevars = 0;
    struct array *sout = parse_dimacs(stdin, &picosat, &freevars);
  enumerate(&picosat, sout, freevars, 1);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


space

decompiled_code:
__int64 __fastcall space(int a1)
{
unsigned int v1; // er12
int i; // ebx

v1 = 0;
if ( a1 > 1 )
{
for ( i = a1; i > 1; i -= i / 2 )
v1 += space((unsigned int)(i >> 1)) + i;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // er12
int i; // ebx

v1 = 0;
if ( a1 > 1 )
{
for ( i = a1; i > 1; i -= i / 2 )
v1 += func0((unsigned int)(i >> 1)) + i;
}
return v1;
}

original_code:
int space(int n) {
  if (n<2)
    return 0;
  else
    return n+space(n/2)+space(n-(n/2));
}


decompiled_code:
__int64 __fastcall add_out_implications(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
__int64 v5; // r15
__int64 v7; // rbx

v5 = a4;
v7 = a5 + a4;
add_clause(
a1,
(unsigned int)-*(_DWORD *)(*(_QWORD *)(a2 + 8) + 4 * v5),
*(unsigned int *)(*(_QWORD *)(a3 + 8) + 4 * v5),
0LL);
return add_clause(
a1,
(unsigned int)-*(_DWORD *)(*(_QWORD *)(a3 + 8) + 4 * v7),
*(unsigned int *)(*(_QWORD *)(a2 + 8) + 4 * v5),
0LL);
}

original_code:
void add_out_implications(solver *s, array *in, array *o, int i, int len) {
  add_clause(s, -(in)->content[i], (o)->content[i], 0);
  add_clause(s, -(o)->content[len+i], (in)->content[i], 0);
}

canonical_original_code:
void add_out_implications(struct solver *s, struct array *in, struct array *o, int i, int len) {
  add_clause(s, -(in)->content[i], (o)->content[i], 0);
  add_clause(s, -(o)->content[len+i], (in)->content[i], 0);
}

variable_types:
o
struct array *

variable_types: len int

user_defined_types: enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 }


totalitarize

original_code:
void totalitarize(solver *solver, array *in0, array *in1, array *out) {
  array *i0=((in0)->length>(in1)->length ? in0 : in1), *i1=((in0)->length<=(in1)->length ? in0 : in1);
  unsigned int i, j, len0=i0->length, len1=i1->length;
  for (i=0; i<len0; i++) {
    for (j=0; j<len1; j++)
      if (i+j < len0+len1) {
        add_clause(solver,
            -(i0)->content[i], -(i1)->content[j], (out)->content[i+j+1], 0);
        add_clause(solver, -(out)->content[i+j], (i0)->content[i], (i1)->content[j], 0);
      }
    add_out_implications(solver, i0, out, i, len1);
    if (i<len1)
      add_out_implications(solver, i1, out, i, len0);
  }
}

canonical_original_code:
void totalitarize(struct solver *solver, struct array *in0, struct array *in1, struct array *out) {
  struct array *i0 = ((in0)->length>(in1)->length ? in0 : in1); struct array *i1 = ((in0)->length<=(in1)->length ? in0 : in1);
  unsigned int i; unsigned int j; unsigned int len0 = i0->length; unsigned int len1 = i1->length;
  for (i=0; i<len0; i++) {
    for (j=0; j<len1; j++)
      if (i+j < len0+len1) {
        add_clause(solver,
            -(i0)->content[i], -(i1)->content[j], (out)->content[i+j+1], 0);
        add_clause(solver, -(out)->content[i+j], (i0)->content[i], (i1)->content[j], 0);
      }
    add_out_implications(solver, i0, out, i, len1);
    if (i<len1)
      add_out_implications(solver, i1, out, i, len0);
  }
}

variable_types: struct array { unsigned int length; int *content; } *

variable_types:
out
struct array *

variable_types:
i
unsigned int

variable_types:
j
unsigned int


auxsorter

decompiled_code:
__int64 __fastcall auxsorter(__int64 a1, __int64 a2, __int64 a3, int a4, unsigned int a5)
{
__int64 v5; // r13
int v6; // ebx
__int64 v8; // rax
__int64 v9; // rsi
int v10; // ebx
__int64 v11; // r14
__int64 v12; // r15
unsigned int v13; // eax
unsigned int *v14; // rsi
unsigned int *v15; // r12
__int64 v17; // rax
__int64 v20; // [rsp+18h] [rbp-40h]

v5 = a4;
v6 = a5 - a4;
if ( (int)(a5 - a4) <= 1 )
{
v17 = new_array();
*(_DWORD *)v17 = 1;
v11 = v17;
*(_QWORD *)(v17 + 8) = *(_QWORD *)(a2 + 8) + 4 * v5;
}
else
{
v8 = take(a3, (unsigned int)v6);
v9 = (unsigned int)v6;
v10 = v6 >> 1;
v11 = v8;
v12 = drop(a3, v9);
v13 = space(v10);
v20 = drop(v12, v13);
v14 = (unsigned int *)auxsorter(a1, a2, v12, (unsigned int)v5, (unsigned int)(v10 + v5));
v15 = (unsigned int *)auxsorter(a1, a2, v20, (unsigned int)(v10 + v5), a5);
totalitarize(a1, v14, v15, v11);
delete_array(v12);
delete_array(v14);
delete_array(v20);
delete_array(v15);
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, int a4, unsigned int a5)
{
__int64 v5; // r13
int v6; // ebx
__int64 v8; // rax
__int64 v9; // rsi
int v10; // ebx
__int64 v11; // r14
__int64 v12; // r15
unsigned int v13; // eax
unsigned int *v14; // rsi
unsigned int *v15; // r12
__int64 v17; // rax
__int64 v20; // [rsp+18h] [rbp-40h]

v5 = a4;
v6 = a5 - a4;
if ( (int)(a5 - a4) <= 1 )
{
v17 = new_array();
*(_DWORD *)v17 = 1;
v11 = v17;
*(_QWORD *)(v17 + 8) = *(_QWORD *)(a2 + 8) + 4 * v5;
}
else
{
v8 = take(a3, (unsigned int)v6);
v9 = (unsigned int)v6;
v10 = v6 >> 1;
v11 = v8;
v12 = drop(a3, v9);
v13 = func0(v10);
v20 = drop(v12, v13);
v14 = (unsigned int *)func3(a1, a2, v12, (unsigned int)v5, (unsigned int)(v10 + v5));
v15 = (unsigned int *)func3(a1, a2, v20, (unsigned int)(v10 + v5), a5);
func2(a1, v14, v15, v11);
delete_array(v12);
delete_array(v14);
delete_array(v20);
delete_array(v15);
}
return v11;
}

original_code:
array *auxsorter(solver *solver, array *in, array *out, int start, int end)
{
  array *this_out, *left_out, *right_out;
  if (end-start > 1) {
    this_out=take(out, end-start);
    left_out=drop(out, end-start);
    right_out=drop(left_out, space((end-start)/2));
    array *left=auxsorter(solver, in, left_out, start, start+(end-start)/2);
    array *right=auxsorter(solver, in, right_out, start+(end-start)/2, end);
    totalitarize(solver, left, right, this_out);
    delete_array(left_out); delete_array(left);
    delete_array(right_out); delete_array(right);
  } else {
    this_out=new_array();
    this_out->length=1;
    this_out->content=&in->content[start];
  }
  return this_out;
}

canonical_original_code:
struct array *auxsorter(struct solver *solver, struct array *in, struct array *out, int start, int end)
{
  struct array *this_out; struct array *left_out; struct array *right_out;
  if (end-start > 1) {
    this_out=take(out, end-start);
    left_out=drop(out, end-start);
    right_out=drop(left_out, space((end-start)/2));
    struct array *left = auxsorter(solver, in, left_out, start, start+(end-start)/2);
    struct array *right = auxsorter(solver, in, right_out, start+(end-start)/2, end);
    totalitarize(solver, left, right, this_out);
    delete_array(left_out); delete_array(left);
    delete_array(right_out); delete_array(right);
  } else {
    this_out=new_array();
    this_out->length=1;
    this_out->content=&in->content[start];
  }
  return this_out;
}

variable_types: struct solver { void (*add)(int lit); enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 } (*sat)(); enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 } (*sat_assum)(int *, int); enum lit_value { L_FALSE=-1, L_UNKNOWN=0, L_TRUE=1 } (*lit_deref)(int); void (*assume)(int); } *

variable_types:
in
struct array *

variable_types: start int

variable_types: end int

return_type: struct array { unsigned int length; int *content; } *


decompiled_code:
__int64 __fastcall get_out(int a1, int a2)
{
unsigned int v3; // eax
__int64 v4; // r8
__int64 v5; // rsi
unsigned int v6; // eax
__int64 v7; // rdx
int v8; // ecx

v3 = space(a1);
v4 = new_array_of_size(v3);
if ( *(_DWORD *)v4 )
{
v5 = *(_QWORD *)(v4 + 8);
v6 = 0;
do
{
v7 = v6;
v8 = a2 + v6++;
*(_DWORD *)(v5 + 4 * v7) = v8;
}
while ( *(_DWORD *)v4 > v6 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
unsigned int v3; // eax
__int64 v4; // r8
__int64 v5; // rsi
unsigned int v6; // eax
__int64 v7; // rdx
int v8; // ecx

v3 = func0(a1);
v4 = new_array_of_size(v3);
if ( *(_DWORD *)v4 )
{
v5 = *(_QWORD *)(v4 + 8);
v6 = 0;
do
{
v7 = v6;
v8 = a2 + v6++;
*(_DWORD *)(v5 + 4 * v7) = v8;
}
while ( *(_DWORD *)v4 > v6 );
}
return v4;
}

original_code:
array *get_out(int in_length, unsigned int start) {
  array *rv=new_array_of_size(space(in_length));
  unsigned int i=0;
  for (; i<rv->length; i++)
    rv->content[i]=start+i;
  return rv;
}

canonical_original_code:
struct array *get_out(int in_length, unsigned int start) {
  struct array *rv = new_array_of_size(space(in_length));
  unsigned int i = 0;
  for (; i<rv->length; i++)
    rv->content[i]=start+i;
  return rv;
}

variable_types:
start
unsigned int


sorter

decompiled_code:
__int64 __fastcall sorter(__int64 a1, int *a2, int a3)
{
__int64 v3; // r13
__int64 v4; // rbp

if ( !a1 )
_assert_fail("solver!=NULL", "bailleuxboufkhad.c", 0x64u, "sorter");
if ( !a2 )
_assert_fail("in!=NULL", "bailleuxboufkhad.c", 0x65u, "sorter");
v3 = get_out(*a2, a3);
v4 = auxsorter(a1, (__int64)a2, v3, 0, *a2);
delete_array_complete(v3);
return delete_array(v4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int *a2, int a3)
{
__int64 v3; // r13
__int64 v4; // rbp

if ( !a1 )
_assert_fail("solver!=NULL", "bailleuxboufkhad.c", 0x64u, "sorter");
if ( !a2 )
_assert_fail("in!=NULL", "bailleuxboufkhad.c", 0x65u, "sorter");
v3 = func4(*a2, a3);
v4 = func3(a1, (__int64)a2, v3, 0, *a2);
delete_array_complete(v3);
return delete_array(v4);
}

original_code:
void sorter(solver *solver, array *in, unsigned int offset) {
  ((void) sizeof ((solver!=((void *)0)) ? 1 : 0), __extension__ ({ if (solver!=((void *)0)) ; else __assert_fail ("solver!=NULL", "bailleuxboufkhad.c", 100, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((in!=((void *)0)) ? 1 : 0), __extension__ ({ if (in!=((void *)0)) ; else __assert_fail ("in!=NULL", "bailleuxboufkhad.c", 101, __extension__ __PRETTY_FUNCTION__); }));
  array *out=get_out(in->length, offset),
        *rv;
  rv=auxsorter(solver, in, out, 0, in->length);
  delete_array_complete(out);
  delete_array(rv);
}

canonical_original_code:
void sorter(struct solver *solver, struct array *in, unsigned int offset) {
  ((void) sizeof ((solver!=((void *)0)) ? 1 : 0), __extension__ ({ if (solver!=((void *)0)) ; else __assert_fail ("solver!=NULL", "bailleuxboufkhad.c", 100, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((in!=((void *)0)) ? 1 : 0), __extension__ ({ if (in!=((void *)0)) ; else __assert_fail ("in!=NULL", "bailleuxboufkhad.c", 101, __extension__ __PRETTY_FUNCTION__); }));
  struct array *out = get_out(in->length, offset); struct array *rv;
  rv=auxsorter(solver, in, out, 0, in->length);
  delete_array_complete(out);
  delete_array(rv);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall non_deleting_sorter(__int64 a1, int *a2, int a3)
{
__int64 v3; // r13
__int64 v4; // r12

if ( !a1 )
_assert_fail("solver!=NULL", "bailleuxboufkhad.c", 0x71u, "non_deleting_sorter");
if ( !a2 )
_assert_fail("in!=NULL", "bailleuxboufkhad.c", 0x72u, "non_deleting_sorter");
v3 = get_out(*a2, a3);
v4 = auxsorter(a1, (__int64)a2, v3, 0, *a2);
delete_array(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int *a2, int a3)
{
__int64 v3; // r13
__int64 v4; // r12

if ( !a1 )
_assert_fail("solver!=NULL", "bailleuxboufkhad.c", 0x71u, "non_deleting_sorter");
if ( !a2 )
_assert_fail("in!=NULL", "bailleuxboufkhad.c", 0x72u, "non_deleting_sorter");
v3 = func4(*a2, a3);
v4 = func3(a1, (__int64)a2, v3, 0, *a2);
delete_array(v3);
return v4;
}

original_code:
array *non_deleting_sorter(solver *solver, array *in, unsigned int offset) {
  ((void) sizeof ((solver!=((void *)0)) ? 1 : 0), __extension__ ({ if (solver!=((void *)0)) ; else __assert_fail ("solver!=NULL", "bailleuxboufkhad.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((in!=((void *)0)) ? 1 : 0), __extension__ ({ if (in!=((void *)0)) ; else __assert_fail ("in!=NULL", "bailleuxboufkhad.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  array *out=get_out(in->length, offset),
        *rv;
  rv=auxsorter(solver, in, out, 0, in->length);
  delete_array(out);
  return rv;
}

canonical_original_code:
struct array *non_deleting_sorter(struct solver *solver, struct array *in, unsigned int offset) {
  ((void) sizeof ((solver!=((void *)0)) ? 1 : 0), __extension__ ({ if (solver!=((void *)0)) ; else __assert_fail ("solver!=NULL", "bailleuxboufkhad.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((in!=((void *)0)) ? 1 : 0), __extension__ ({ if (in!=((void *)0)) ; else __assert_fail ("in!=NULL", "bailleuxboufkhad.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  struct array *out = get_out(in->length, offset); struct array *rv;
  rv=auxsorter(solver, in, out, 0, in->length);
  delete_array(out);
  return rv;
}


decompiled_code:
__int64 __fastcall get_in(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rax
__int64 v4; // r8
_DWORD *v5; // rax
int v6; // edi

v2 = a2;
v3 = new_array_of_size(a1);
v4 = v3;
if ( (_DWORD)a1 )
{
v5 = *(_DWORD **)(v3 + 8);
v6 = a1 + a2;
do
*v5++ = v2++;
while ( v2 != v6 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rax
__int64 v4; // r8
_DWORD *v5; // rax
int v6; // edi

v2 = a2;
v3 = new_array_of_size(a1);
v4 = v3;
if ( (_DWORD)a1 )
{
v5 = *(_DWORD **)(v3 + 8);
v6 = a1 + a2;
do
*v5++ = v2++;
while ( v2 != v6 );
}
return v4;
}

original_code:
array *get_in(unsigned int length, unsigned int offset) {
  array *rv=new_array_of_size(length);
  unsigned int i=0;
  for (; i<length; i++)
    rv->content[i]=offset+i;
  return rv;
}

canonical_original_code:
struct array *get_in(unsigned int length, unsigned int offset) {
  struct array *rv = new_array_of_size(length);
  unsigned int i = 0;
  for (; i<length; i++)
    rv->content[i]=offset+i;
  return rv;
}

variable_types:
length
unsigned int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "usage:\n\t%s <inputlength>\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
fprintf(stderr, "usage:\n\t%s <inputlength>\n", a1);
exit(1);
}

original_code:
void usage(char *name) {
  fprintf(stderr, "usage:\n\t%s <inputlength>\n", name);
  exit(1);
}

variable_types:
name
char *


decompiled_code:
int __fastcall print_array(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 v3; // rcx
void *v4; // rdx

putchar(91);
v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v3 = v2;
v4 = &unk_1F5;
if ( v1 - 1 > v2 )
v4 = &unk_1F3;
++v2;
printf("%d%s", *(unsigned int *)(*((_QWORD *)a1 + 1) + 4 * v3), v4);
v1 = *a1;
}
while ( *a1 > v2 );
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func0(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 v3; // rcx
void *v4; // rdx

putchar(91);
v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v3 = v2;
v4 = &unk_1F5;
if ( v1 - 1 > v2 )
v4 = &unk_1F3;
++v2;
printf("%d%s", *(unsigned int *)(*((_QWORD *)a1 + 1) + 4 * v3), v4);
v1 = *a1;
}
while ( *a1 > v2 );
}
return puts("]");
}

original_code:
void print_array(array *arr) {
  unsigned int i;
  (void)putchar('[');
  for (i=0; i<arr->length; i++)
    printf("%d%s", arr->content[i], i<arr->length-1 ? " " : "");
  (void)puts("]");
}

canonical_original_code:
void print_array(struct array *arr) {
  unsigned int i;
  (void)putchar('[');
  for (i=0; i<arr->length; i++)
    printf("%d%s", arr->content[i], i<arr->length-1 ? " " : "");
  (void)puts("]");
}


decompiled_code:
void *new_array()
{
void *result; // rax

result = malloc(0x10uLL);
if ( !result )
_assert_fail("rv!=NULL", "array.c", 0x18u, "new_array");
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

result = malloc(0x10uLL);
if ( !result )
_assert_fail("rv!=NULL", "array.c", 0x18u, "new_array");
return result;
}

original_code:
array *new_array(void) {
  array *rv=(array *)malloc(sizeof(array));
  ((void) sizeof ((rv!=((void *)0)) ? 1 : 0), __extension__ ({ if (rv!=((void *)0)) ; else __assert_fail ("rv!=NULL", "array.c", 24, __extension__ __PRETTY_FUNCTION__); }));
  return rv;
}

canonical_original_code:
struct array *new_array() {
  struct array *rv = (array *)malloc(sizeof(array));
  ((void) sizeof ((rv!=((void *)0)) ? 1 : 0), __extension__ ({ if (rv!=((void *)0)) ; else __assert_fail ("rv!=NULL", "array.c", 24, __extension__ __PRETTY_FUNCTION__); }));
  return rv;
}


decompiled_code:
// attributes: thunk
void delete_array(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func2(void *ptr)
{
free(ptr);
}

original_code:
void delete_array(array *arr) {
  free(arr);
}

canonical_original_code:
void delete_array(struct array *arr) {
  free(arr);
}


decompiled_code:
void __fastcall delete_array_complete(void *ptr)
{
void *v2; // rdi

if ( !ptr )
_assert_fail("arr!=NULL", "array.c", 0x3Cu, "delete_array_complete");
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
delete_array(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void *v2; // rdi

if ( !ptr )
_assert_fail("arr!=NULL", "array.c", 0x3Cu, "delete_array_complete");
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
func2(ptr);
}

original_code:
void delete_array_complete(array *arr) {
  ((void) sizeof ((arr!=((void *)0)) ? 1 : 0), __extension__ ({ if (arr!=((void *)0)) ; else __assert_fail ("arr!=NULL", "array.c", 60, __extension__ __PRETTY_FUNCTION__); }));
  if (arr->content!=((void *)0))
    free(arr->content);
  delete_array(arr);
}

canonical_original_code:
void delete_array_complete(struct array *arr) {
  ((void) sizeof ((arr!=((void *)0)) ? 1 : 0), __extension__ ({ if (arr!=((void *)0)) ; else __assert_fail ("arr!=NULL", "array.c", 60, __extension__ __PRETTY_FUNCTION__); }));
  if (arr->content!=((void *)0))
    free(arr->content);
  delete_array(arr);
}


decompiled_code:
__int64 add_clause(__int64 (**a1)(void), double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned int v10; // eax
int v11; // edi
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( 1 )
{
v10 = va[0].gp_offset;
if ( va[0].gp_offset > 0x2F )
break;
va[0].gp_offset += 8;
if ( !*(_DWORD *)((char *)va[0].reg_save_area + v10) )
return (*a1)();
LABEL_3:
(*a1)();
}
v11 = *(_DWORD *)va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v11 )
goto LABEL_3;
return (*a1)();
}

canonical_decompiled_code:
__int64 func0(__int64 (**a1)(void), double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned int v10; // eax
int v11; // edi
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
while ( 1 )
{
v10 = va[0].gp_offset;
if ( va[0].gp_offset > 0x2F )
break;
va[0].gp_offset += 8;
if ( !*(_DWORD *)((char *)va[0].reg_save_area + v10) )
return (*a1)();
LABEL_3:
(*a1)();
}
v11 = *(_DWORD *)va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v11 )
goto LABEL_3;
return (*a1)();
}

original_code:
void add_clause(solver *s, ...) {
  va_list vargs;
  int curr;
  __builtin_va_start(vargs,s);
  while ((curr=__builtin_va_arg(vargs,int))!=0)
    s->add(curr);
  __builtin_va_end(vargs);
  s->add(0);
}

canonical_original_code:
void add_clause(struct solver *s, ...) {
  __builtin_va_list vargs;
  int curr;
  __builtin_va_start(vargs,s);
  while ((curr=__builtin_va_arg(vargs,int))!=0)
    s->add(curr);
  __builtin_va_end(vargs);
  s->add(0);
}

variable_types: curr int


decompiled_code:
int __fastcall print_add(unsigned int a1)
{
const char *v1; // rdx

v1 = (const char *)&unk_CC;
if ( a1 )
v1 = (const char *)&unk_CE;
return printf("%d%s", a1, v1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
const char *v1; // rdx

v1 = (const char *)&unk_CC;
if ( a1 )
v1 = (const char *)&unk_CE;
return printf("%d%s", a1, v1);
}

original_code:
void print_add(int lit) {
  printf("%d%s", lit, lit==0 ? "\n" : " ");
}

variable_types: lit int


decompiled_code:
__int64 print_sat()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
sat_state print_sat(void) {
  return ST_UNKNOWN;
}

canonical_original_code:
enum sat_state print_sat() {
  return ST_UNKNOWN;
}

return_type: enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 }


decompiled_code:
__int64 __fastcall print_sat_assum(const void *a1, __int64 a2)
{
printf("#assumptions: %d (%p)\n", a2, a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const void *a1, __int64 a2)
{
printf("#assumptions: %d (%p)\n", a2, a1);
return 0LL;
}

canonical_original_code:
enum sat_state print_sat_assum(int *assumptions, int length) {
  printf("#assumptions: %d (%p)\n", length, assumptions);
  return ST_UNKNOWN;
}

variable_types:
assumptions
int *

variable_types: length int


initParse

repo: lijnk/hasm

decompiled_code:
size_t __fastcall initParse(const char *a1)
{
size_t result; // rax

parser_stream = (__int64)a1;
parser_cur = 0;
parser_com = 0LL;
result = strlen(a1);
parser_ln = 0;
parser_sz = result;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
size_t result; // rax

parser_stream = (__int64)a1;
parser_cur = 0;
parser_com = 0LL;
result = strlen(a1);
parser_ln = 0;
parser_sz = result;
return result;
}

original_code:
void initParse(char* stream)
{
  _parser_stream = stream;
  _parser_cur = 0;
  _parser_com = ((void *)0);
  _parser_sz = strlen(stream);
  _parser_ln = 0;
}

canonical_original_code:
void initParse(char *stream)
{
  _parser_stream = stream;
  _parser_cur = 0;
  _parser_com = ((void *)0);
  _parser_sz = strlen(stream);
  _parser_ln = 0;
}

variable_types:
stream
char *


hasMoreCommands

decompiled_code:
bool hasMoreCommands()
{
return parser_cur < parser_sz;
}

canonical_decompiled_code:
bool func1()
{
return parser_cur < parser_sz;
}

original_code:
_Bool hasMoreCommands()
{
  if(_parser_cur < _parser_sz)
    return 1;
  return 0;
}


resetCmd

decompiled_code:
void resetCmd()
{
if ( parser_com )
{
free(parser_com);
parser_com = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
if ( parser_com )
{
free(parser_com);
parser_com = 0LL;
}
}

original_code:
void resetCmd()
{
  if(_parser_com != ((void *)0))
  {
    free(_parser_com);
    _parser_com = ((void *)0);
  }
}


advance

decompiled_code:
char advance()
{
int v0; // ebx
const char *v1; // r12
char *v2; // rbp
char *v3; // rax
char *v4; // rbx
size_t v5; // rbx
char *v6; // rbp
unsigned int v7; // edx
int v8; // edi
__int64 v9; // rax
char *v10; // rax
char *v11; // rax
int v12; // esi
__int64 v13; // rdx
char *v14; // rcx
unsigned int i; // eax
char v16; // dl
char result; // al

while ( 1 )
{
resetCmd();
v0 = parser_stream;
v1 = (const char *)(parser_stream + parser_cur);
v2 = strchr(v1, 10);
if ( !v2 )
v2 = (char *)&v1[strlen(v1)];
parser_cur = (_DWORD)v2 - v0 + 1;
v3 = strstr(v1, "//");
v4 = v3;
if ( !v3 || v2 <= v3 )
v4 = v2;
v5 = v4 - v1;
v6 = (char *)malloc(v5);
strncpy(v6, v1, v5);
if ( v5 )
{
v7 = 0;
v8 = 0;
v9 = 0LL;
do
{
v10 = &v6[v9];
if ( (*v10 & 0xFB) == 9 || *v10 == 32 )
{
*v10 = 32;
++v8;
}
v9 = ++v7;
}
while ( v7 < v5 );
v11 = (char *)malloc(v5 + 1 - v8);
v12 = 0;
v13 = 0LL;
parser_com = v11;
v14 = v11;
for ( i = 0; i < v5; v13 = ++i )
{
while ( 1 )
{
v16 = v6[v13];
if ( v16 == 32 )
break;
v14[i - v12] = v16;
v14 = parser_com;
v13 = ++i;
if ( i >= v5 )
goto LABEL_15;
}
++v12;
}
LABEL_15:
v5 -= v12;
}
else
{
parser_com = (char *)malloc(1uLL);
v14 = parser_com;
}
v14[v5] = 0;
++parser_ln;
free(v6);
result = (char)parser_com;
if ( *parser_com )
return result;
result = hasMoreCommands();
if ( !result )
return result;
resetCmd();
}
}

canonical_decompiled_code:
char func3()
{
int v0; // ebx
const char *v1; // r12
char *v2; // rbp
char *v3; // rax
char *v4; // rbx
size_t v5; // rbx
char *v6; // rbp
unsigned int v7; // edx
int v8; // edi
__int64 v9; // rax
char *v10; // rax
char *v11; // rax
int v12; // esi
__int64 v13; // rdx
char *v14; // rcx
unsigned int i; // eax
char v16; // dl
char result; // al

while ( 1 )
{
func2();
v0 = parser_stream;
v1 = (const char *)(parser_stream + parser_cur);
v2 = strchr(v1, 10);
if ( !v2 )
v2 = (char *)&v1[strlen(v1)];
parser_cur = (_DWORD)v2 - v0 + 1;
v3 = strstr(v1, "//");
v4 = v3;
if ( !v3 || v2 <= v3 )
v4 = v2;
v5 = v4 - v1;
v6 = (char *)malloc(v5);
strncpy(v6, v1, v5);
if ( v5 )
{
v7 = 0;
v8 = 0;
v9 = 0LL;
do
{
v10 = &v6[v9];
if ( (*v10 & 0xFB) == 9 || *v10 == 32 )
{
*v10 = 32;
++v8;
}
v9 = ++v7;
}
while ( v7 < v5 );
v11 = (char *)malloc(v5 + 1 - v8);
v12 = 0;
v13 = 0LL;
parser_com = v11;
v14 = v11;
for ( i = 0; i < v5; v13 = ++i )
{
while ( 1 )
{
v16 = v6[v13];
if ( v16 == 32 )
break;
v14[i - v12] = v16;
v14 = parser_com;
v13 = ++i;
if ( i >= v5 )
goto LABEL_15;
}
++v12;
}
LABEL_15:
v5 -= v12;
}
else
{
parser_com = (char *)malloc(1uLL);
v14 = parser_com;
}
v14[v5] = 0;
++parser_ln;
free(v6);
result = (char)parser_com;
if ( *parser_com )
return result;
result = func1();
if ( !result )
return result;
func2();
}
}

original_code:
void advance()
{
  resetCmd();
  char* sp = _parser_stream+_parser_cur;
  char* ep = strchr(sp, '\n');
  char* res;
  size_t size;
  if(ep == ((void *)0))
    ep = strchr(sp, 0);
  _parser_cur = (ep-_parser_stream) + 1;
  char* tp = strstr(sp, "//");
  if((tp != ((void *)0)) && (tp < ep))
    ep = tp;
  size = ep-sp;
  res = (char*) malloc(sizeof(char)*size);
  strncpy(res, sp, size);
  int ws = 0;
  unsigned int i = 0;
  for(i = 0; i < size; i++)
  {
    if(res[i] == ' ' || res[i] == '\t' || res[i] == '\r')
    {
      ws++;
      res[i] = ' ';
    }
  }
  _parser_com = (char*) malloc(sizeof(char)*(size-ws+1));
  ws = 0;
  for(i = 0; i<size; i++)
  {
    if(res[i] == ' ')
      ws++;
    else
      _parser_com[i-ws] = res[i];
  }
  _parser_com[size-ws] = 0;
  _parser_ln++;
  free(res);
  if(_parser_com[0] == 0 && hasMoreCommands())
  {
    resetCmd();
    advance();
    return;
  }
}

canonical_original_code:
void advance()
{
  resetCmd();
  char *sp = _parser_stream+_parser_cur;
  char *ep = strchr(sp, '\n');
  char *res;
  unsigned long size;
  if(ep == ((void *)0))
    ep = strchr(sp, 0);
  _parser_cur = (ep-_parser_stream) + 1;
  char *tp = strstr(sp, "//");
  if((tp != ((void *)0)) && (tp < ep))
    ep = tp;
  size = ep-sp;
  res = (char *) malloc(sizeof(char)*size);
  strncpy(res, sp, size);
  int ws = 0;
  unsigned int i = 0;
  for(i = 0; i < size; i++)
  {
    if(res[i] == ' ' || res[i] == '\t' || res[i] == '\r')
    {
      ws++;
      res[i] = ' ';
    }
  }
  _parser_com = (char *) malloc(sizeof(char)*(size-ws+1));
  ws = 0;
  for(i = 0; i<size; i++)
  {
    if(res[i] == ' ')
      ws++;
    else
      _parser_com[i-ws] = res[i];
  }
  _parser_com[size-ws] = 0;
  _parser_ln++;
  free(res);
  if(_parser_com[0] == 0 && hasMoreCommands())
  {
    resetCmd();
    advance();
    return;
  }
}

variable_types:
sp
char *

variable_types:
ep
char *

variable_types:
res
char *

variable_types:
size
unsigned long

variable_types:
tp
char *

variable_types: ws int


commandType

decompiled_code:
__int64 commandType()
{
const char *v0; // rbp
__int64 result; // rax
char *v2; // r8
size_t v3; // r8

v0 = parser_com;
result = 0LL;
if ( *parser_com != 64 )
{
if ( *parser_com != 40 || (v3 = strlen(parser_com), result = 1LL, v0[v3 - 1] != 41) )
{
v2 = strchr(v0, 61);
result = 2LL;
if ( !v2 )
result = (unsigned int)(strchr(v0, 59) == 0LL) + 2;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
const char *v0; // rbp
__int64 result; // rax
char *v2; // r8
size_t v3; // r8

v0 = parser_com;
result = 0LL;
if ( *parser_com != 64 )
{
if ( *parser_com != 40 || (v3 = strlen(parser_com), result = 1LL, v0[v3 - 1] != 41) )
{
v2 = strchr(v0, 61);
result = 2LL;
if ( !v2 )
result = (unsigned int)(strchr(v0, 59) == 0LL) + 2;
}
}
return result;
}

original_code:
int commandType()
{
  if(_parser_com[0] == '@')
    return A_COMMAND;
  if(_parser_com[0] == '(' && _parser_com[strlen(_parser_com)-1] == ')')
    return L_COMMAND;
  if(strchr(_parser_com, '=') != ((void *)0) || strchr(_parser_com, ';') != ((void *)0))
    return C_COMMAND;
  return U_COMMAND;
}


parseSymbol

decompiled_code:
size_t __fastcall parseSymbol(char *dest)
{
size_t result; // rax
char *v2; // rbp
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax

result = commandType();
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
v4 = parser_com;
v5 = strlen(parser_com);
strncpy(dest, v4 + 1, v5 - 2);
result = strlen(parser_com);
dest[result - 2] = 0;
}
}
else
{
v2 = parser_com;
v3 = strlen(parser_com);
strncpy(dest, v2 + 1, v3 - 1);
result = strlen(parser_com);
dest[result - 1] = 0;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func5(char *dest)
{
size_t result; // rax
char *v2; // rbp
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax

result = func4();
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
v4 = parser_com;
v5 = strlen(parser_com);
strncpy(dest, v4 + 1, v5 - 2);
result = strlen(parser_com);
dest[result - 2] = 0;
}
}
else
{
v2 = parser_com;
v3 = strlen(parser_com);
strncpy(dest, v2 + 1, v3 - 1);
result = strlen(parser_com);
dest[result - 1] = 0;
}
return result;
}

original_code:
void parseSymbol(char* d)
{
  if(commandType() == A_COMMAND)
  {
    strncpy(d, _parser_com+1, strlen(_parser_com)-1);
    d[strlen(_parser_com)-1] = 0;
  }
  else if(commandType() == L_COMMAND)
  {
    strncpy(d, _parser_com+1, strlen(_parser_com)-2);
    d[strlen(_parser_com)-2] = 0;
  }
}

canonical_original_code:
void parseSymbol(char *d)
{
  if(commandType() == A_COMMAND)
  {
    strncpy(d, _parser_com+1, strlen(_parser_com)-1);
    d[strlen(_parser_com)-1] = 0;
  }
  else if(commandType() == L_COMMAND)
  {
    strncpy(d, _parser_com+1, strlen(_parser_com)-2);
    d[strlen(_parser_com)-2] = 0;
  }
}

variable_types:
d
char *


parseDest

decompiled_code:
char *__fastcall parseDest(char *dest)
{
const char *v1; // r12
char *result; // rax
char *v3; // rbx

v1 = parser_com;
result = strchr(parser_com, 61);
if ( result )
{
v3 = result;
result = strncpy(dest, v1, result - v1);
dest[v3 - parser_com] = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(char *dest)
{
const char *v1; // r12
char *result; // rax
char *v3; // rbx

v1 = parser_com;
result = strchr(parser_com, 61);
if ( result )
{
v3 = result;
result = strncpy(dest, v1, result - v1);
dest[v3 - parser_com] = 0;
}
return result;
}

original_code:
void parseDest(char* d)
{
  char* tp = strchr(_parser_com, '=');
  if(tp != ((void *)0))
  {
    strncpy(d, _parser_com, tp-_parser_com);
    d[tp-_parser_com] = 0;
  }
}

canonical_original_code:
void parseDest(char *d)
{
  char *tp = strchr(_parser_com, '=');
  if(tp != ((void *)0))
  {
    strncpy(d, _parser_com, tp-_parser_com);
    d[tp-_parser_com] = 0;
  }
}


parseComp

decompiled_code:
char *__fastcall parseComp(char *dest)
{
const char *v1; // r13
char *v2; // rbx
char *v3; // rax
const char *v4; // r12
signed __int64 v5; // rbx
char *result; // rax

v1 = parser_com;
v2 = strchr(parser_com, 61);
v3 = strchr(v1, 59);
v4 = v2 + 1;
if ( !v2 )
v4 = v1;
if ( !v3 )
v3 = (char *)&v1[strlen(v1)];
v5 = v3 - v4;
result = strncpy(dest, v4, v3 - v4);
dest[v5] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *dest)
{
const char *v1; // r13
char *v2; // rbx
char *v3; // rax
const char *v4; // r12
signed __int64 v5; // rbx
char *result; // rax

v1 = parser_com;
v2 = strchr(parser_com, 61);
v3 = strchr(v1, 59);
v4 = v2 + 1;
if ( !v2 )
v4 = v1;
if ( !v3 )
v3 = (char *)&v1[strlen(v1)];
v5 = v3 - v4;
result = strncpy(dest, v4, v3 - v4);
dest[v5] = 0;
return result;
}

original_code:
void parseComp(char* d)
{
  char* tp1 = strchr(_parser_com, '=');
  char* tp2 = strchr(_parser_com, ';');
  if(tp1 == ((void *)0))
    tp1 = _parser_com;
  else
    tp1++;
  if(tp2 == ((void *)0))
    tp2 = _parser_com + strlen(_parser_com);
  strncpy(d, tp1, tp2-tp1);
  d[tp2-tp1] = 0;
}

canonical_original_code:
void parseComp(char *d)
{
  char *tp1 = strchr(_parser_com, '=');
  char *tp2 = strchr(_parser_com, ';');
  if(tp1 == ((void *)0))
    tp1 = _parser_com;
  else
    tp1++;
  if(tp2 == ((void *)0))
    tp2 = _parser_com + strlen(_parser_com);
  strncpy(d, tp1, tp2-tp1);
  d[tp2-tp1] = 0;
}


parseJump

decompiled_code:
char *__fastcall parseJump(char *dest)
{
char *result; // rax

result = strchr(parser_com, 59);
if ( result )
return strcpy(dest, result + 1);
*dest = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *dest)
{
char *result; // rax

result = strchr(parser_com, 59);
if ( result )
return strcpy(dest, result + 1);
*dest = 0;
return result;
}

original_code:
void parseJump(char* d)
{
  char* tp = strchr(_parser_com, ';');
  if(tp != ((void *)0))
    strcpy(d, tp+1);
  else
    strcpy(d, "");
}

canonical_original_code:
void parseJump(char *d)
{
  char *tp = strchr(_parser_com, ';');
  if(tp != ((void *)0))
    strcpy(d, tp+1);
  else
    strcpy(d, "");
}


parseBin

decompiled_code:
void __fastcall parseBin(_WORD *a1, __int16 a2)
{
*a1 = a2;
}

canonical_decompiled_code:
void __fastcall func9(_WORD *a1, __int16 a2)
{
*a1 = a2;
}

original_code:
void parseBin(unsigned char* o, unsigned short int v)
{
 o[0] = (char) (v & 0xFF);
 o[1] = (char) ((v >> 8) & 0xFF);
}

canonical_original_code:
void parseBin(unsigned char *o, unsigned short v)
{
 o[0] = (char) (v & 0xFF);
 o[1] = (char) ((v >> 8) & 0xFF);
}

variable_types:
o
unsigned char *

variable_types:
v
unsigned short


killNode

decompiled_code:
void __fastcall killNode(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
killNode();
free(*(void **)a1);
free((void *)a1);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
func0();
free(*(void **)a1);
free((void *)a1);
}

original_code:
void killNode(bucket* n)
{
  if(n->next != ((void *)0))
    killNode(n->next);
  free(n->sym);
  free(n);
  return;
}

canonical_original_code:
void killNode(struct node *n)
{
  if(n->next != ((void *)0))
    killNode(n->next);
  free(n->sym);
  free(n);
  return;
}

variable_types: struct node { char *sym; int address; struct node *next; } *


clearHash

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

v1 = a1;
do
{
if ( *v1 )
killNode(*v1);
++v1;
}
while ( v1 != a1 + 31 );
}

original_code:
void clearHash(bucket** tbl)
{
  for(int i = 0; i<31; i++)
  {
    if(tbl[i] == ((void *)0))
      continue;
    killNode(tbl[i]);
  }
}

canonical_original_code:
void clearHash(struct node **tbl)
{
  for(int i = 0; i<31; i++)
  {
    if(tbl[i] == ((void *)0))
      continue;
    killNode(tbl[i]);
  }
}

variable_types: struct node { char *sym; int address; struct node *next; } **

variable_types: i int


iterateHash

original_code:
void iterateHash(bucket** tbl)
{
  bucket* tmp;
  for(int i = 0; i<31; i++)
  {
    tmp = tbl[i];
    while(tmp != ((void *)0))
    {
      printf("----------------\n");
      printf("Key: %s, Val: %d\n", tmp->sym, tmp->address);
      printf("Next: %p\n", (void*)tmp->next);
      tmp = tmp->next;
    }
  }
  printf("===================\n");
}

canonical_original_code:
void iterateHash(struct node **tbl)
{
  struct node *tmp;
  for(int i = 0; i<31; i++)
  {
    tmp = tbl[i];
    while(tmp != ((void *)0))
    {
      printf("----------------\n");
      printf("Key: %s, Val: %d\n", tmp->sym, tmp->address);
      printf("Next: %p\n", (void *)tmp->next);
      tmp = tmp->next;
    }
  }
  printf("===================\n");
}

user_defined_types: struct node { char *sym; int address; struct node *next; }


toNum

decompiled_code:
__int64 __fastcall toNum(const char *a1)
{
size_t v1; // rsi
size_t v2; // rax
unsigned int v3; // ecx
int v4; // edx
unsigned int v5; // er8
int v6; // eax
unsigned __int8 v7; // al

v1 = strlen(a1);
v2 = (unsigned int)(v1 - 1);
if ( v1 <= v2 )
return 0;
v3 = v1 - 1;
v4 = 1;
v5 = 0;
while ( 1 )
{
v7 = a1[v2] - 48;
if ( v7 > 9u )
break;
v6 = v4 * (char)v7;
v4 *= 10;
v5 += v6;
v2 = --v3;
if ( v1 <= v3 )
return v5;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
size_t v1; // rsi
size_t v2; // rax
unsigned int v3; // ecx
int v4; // edx
unsigned int v5; // er8
int v6; // eax
unsigned __int8 v7; // al

v1 = strlen(a1);
v2 = (unsigned int)(v1 - 1);
if ( v1 <= v2 )
return 0;
v3 = v1 - 1;
v4 = 1;
v5 = 0;
while ( 1 )
{
v7 = a1[v2] - 48;
if ( v7 > 9u )
break;
v6 = v4 * (char)v7;
v4 *= 10;
v5 += v6;
v2 = --v3;
if ( v1 <= v3 )
return v5;
}
return (unsigned int)-1;
}

original_code:
int toNum(char* s)
{
  int res = 0;
  int mul = 1;
  for(unsigned int i = strlen(s)-1; i < strlen(s); i--)
  {
    if(s[i] < 48 || s[i] > 57)
      return -1;
    res += (s[i] - 48) * mul;
    mul *= 10;
  }
  return res;
}

canonical_original_code:
int toNum(char *s)
{
  int res = 0;
  int mul = 1;
  for(unsigned int i = strlen(s)-1; i < strlen(s); i--)
  {
    if(s[i] < 48 || s[i] > 57)
      return -1;
    res += (s[i] - 48) * mul;
    mul *= 10;
  }
  return res;
}

variable_types:
s
char *

variable_types: res int

variable_types: mul int

variable_types:
i
unsigned int


debugString

decompiled_code:
int __fastcall debugString(char *s)
{
unsigned int v1; // ebx
__int64 v2; // rsi

v1 = 0;
printf("DEBUG:");
while ( v1 < strlen(s) )
{
v2 = (unsigned int)s[v1++];
printf(" %d", v2);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(char *s)
{
unsigned int v1; // ebx
__int64 v2; // rsi

v1 = 0;
printf("DEBUG:");
while ( v1 < strlen(s) )
{
v2 = (unsigned int)s[v1++];
printf(" %d", v2);
}
return putchar(10);
}

original_code:
void debugString(char* s)
{
  printf("DEBUG:");
  for(unsigned int i=0; i<strlen(s); i++)
  {
    printf(" %d", s[i]);
  }
  printf("\n");
}

canonical_original_code:
void debugString(char *s)
{
  printf("DEBUG:");
  for(unsigned int i = 0; i<strlen(s); i++)
  {
    printf(" %d", s[i]);
  }
  printf("\n");
}


hash

decompiled_code:
__int64 __fastcall hash(const char *a1)
{
size_t v1; // rax
int v2; // ecx
unsigned __int64 v3; // rsi
unsigned int i; // eax
int v5; // edx

v1 = strlen(a1);
v2 = 0;
v3 = v1;
for ( i = 0; i < v3; ++i )
{
v5 = a1[i];
v2 += v5;
}
return (unsigned int)(v2 % 31);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
size_t v1; // rax
int v2; // ecx
unsigned __int64 v3; // rsi
unsigned int i; // eax
int v5; // edx

v1 = strlen(a1);
v2 = 0;
v3 = v1;
for ( i = 0; i < v3; ++i )
{
v5 = a1[i];
v2 += v5;
}
return (unsigned int)(v2 % 31);
}

original_code:
int hash(char* key)
{
  int res = 0;
  for(unsigned int i = 0; i < strlen(key); i++)
  {
    res += key[i];
  }
  return res % 31;
}

canonical_original_code:
int hash(char *key)
{
  int res = 0;
  for(unsigned int i = 0; i < strlen(key); i++)
  {
    res += key[i];
  }
  return res % 31;
}

variable_types:
key
char *


contains

decompiled_code:
__int64 __fastcall contains(__int64 a1, const char *a2)
{
__int64 i; // r12

for ( i = *(_QWORD *)(a1 + 8LL * (int)hash(a2)); i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
__int64 i; // r12

for ( i = *(_QWORD *)(a1 + 8LL * (int)func5(a2)); i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

original_code:
bucket* contains(bucket** tbl, char* sym)
{
  bucket* tmp = tbl[hash(sym)];
  while(tmp != ((void *)0))
  {
    if(strcmp(sym, tmp->sym) == 0)
      break;
    tmp = tmp->next;
  }
  return tmp;
}

canonical_original_code:
struct node *contains(struct node **tbl, char *sym)
{
  struct node *tmp = tbl[hash(sym)];
  while(tmp != ((void *)0))
  {
    if(strcmp(sym, tmp->sym) == 0)
      break;
    tmp = tmp->next;
  }
  return tmp;
}

variable_types:
tbl
struct node **

variable_types:
sym
char *

return_type: struct node { char *sym; int address; struct node *next; } *


strdup

decompiled_code:
void *__fastcall strdup(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src);
v2 = malloc((int)v1 + 1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1 + 1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func7(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src);
v2 = malloc((int)v1 + 1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1 + 1);
return v3;
}

original_code:
char* strdup(char* str)
{
  int n = strlen(str) + 1;
  char* dup = malloc(n);
  if(dup)
    strcpy(dup, str);
  return dup;
}

canonical_original_code:
char *strdup(char *str)
{
  int n = strlen(str) + 1;
  char *dup = malloc(n);
  if(dup)
    strcpy(dup, str);
  return dup;
}

variable_types:
str
char *

variable_types: n int

variable_types:
dup
char *

return_type: char *


addEntry

decompiled_code:
__int64 __fastcall addEntry(__int64 a1, char *a2, int a3)
{
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbx
_QWORD *v7; // r14
void *v8; // rax
int v9; // eax

v4 = *(_QWORD *)a1;
result = contains(*(_QWORD *)a1, a2);
if ( !result )
{
v6 = *(_QWORD *)(v4 + 8LL * (int)hash(a2));
v7 = malloc(0x18uLL);
v8 = strdup(a2);
v7[2] = 0LL;
*v7 = v8;
if ( a3 == -1 )
{
v9 = *(_DWORD *)(a1 + 8);
*((_DWORD *)v7 + 2) = v9;
*(_DWORD *)(a1 + 8) = v9 + 1;
}
else
{
*((_DWORD *)v7 + 2) = a3;
}
if ( v6 )
{
do
{
result = v6;
v6 = *(_QWORD *)(v6 + 16);
}
while ( v6 );
*(_QWORD *)(result + 16) = v7;
}
else
{
result = (int)hash(a2);
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (int)result) = v7;
}
}
return result;
}

original_code:
void addEntry(SymbolTable* tbl, char* sym, int addr)
{
  bucket* tmp = contains(tbl->table, sym);
  bucket* new;
  if(tmp == ((void *)0))
  {
    tmp = tbl->table[hash(sym)];
    new = (bucket*) malloc(sizeof(bucket));
    new->sym = strdup(sym);
    new->next = ((void *)0);
    if(addr == -1)
      new->address = tbl->count++;
    else
      new->address = addr;
    if(tmp == ((void *)0))
    {
      tbl->table[hash(sym)] = new;
      return;
    }
    while(tmp->next != ((void *)0))
    {
      tmp = tmp->next;
    }
    tmp->next = new;
  }
}

canonical_original_code:
void addEntry(struct head *tbl, char *sym, int addr)
{
  struct node *tmp = contains(tbl->table, sym);
  struct node *new;
  if(tmp == ((void *)0))
  {
    tmp = tbl->table[hash(sym)];
    new = (struct node *) malloc(sizeof(bucket));
    new->sym = strdup(sym);
    new->next = ((void *)0);
    if(addr == -1)
      new->address = tbl->count++;
    else
      new->address = addr;
    if(tmp == ((void *)0))
    {
      tbl->table[hash(sym)] = new;
      return;
    }
    while(tmp->next != ((void *)0))
    {
      tmp = tmp->next;
    }
    tmp->next = new;
  }
}

variable_types: struct head { struct node { char *sym; int address; struct node *next; } **table; int count; } *

variable_types: addr int

user_defined_types: struct head { struct node **table; int count; }


initTable

decompiled_code:
__int64 __fastcall initTable(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 16;
*(_QWORD *)a1 = calloc(0x1FuLL, 8uLL);
addEntry(a1, "SP", 0);
addEntry(a1, "LCL", 1);
addEntry(a1, "ARG", 2);
addEntry(a1, "THIS", 3);
addEntry(a1, "THAT", 4);
addEntry(a1, "SCREEN", 0x4000);
addEntry(a1, "KBD", 24576);
addEntry(a1, "R0", 0);
addEntry(a1, "R1", 1);
addEntry(a1, "R2", 2);
addEntry(a1, "R3", 3);
addEntry(a1, "R4", 4);
addEntry(a1, "R5", 5);
addEntry(a1, "R6", 6);
addEntry(a1, "R7", 7);
addEntry(a1, "R8", 8);
addEntry(a1, "R9", 9);
addEntry(a1, "R10", 10);
addEntry(a1, "R11", 11);
addEntry(a1, "R12", 12);
addEntry(a1, "R13", 13);
addEntry(a1, "R14", 14);
return addEntry(a1, "R15", 15);
}

original_code:
void initTable(SymbolTable* tbl)
{
  tbl->count = 16;
  tbl->table = (bucket**) calloc(31, sizeof(bucket*));
  addEntry(tbl, "SP", 0x0000);
  addEntry(tbl, "LCL", 0x0001);
  addEntry(tbl, "ARG", 0x0002);
  addEntry(tbl, "THIS", 0x0003);
  addEntry(tbl, "THAT", 0x0004);
  addEntry(tbl, "SCREEN", 0x4000);
  addEntry(tbl, "KBD", 0x6000);
  addEntry(tbl, "R0", 0x0000);
  addEntry(tbl, "R1", 0x0001);
  addEntry(tbl, "R2", 0x0002);
  addEntry(tbl, "R3", 0x0003);
  addEntry(tbl, "R4", 0x0004);
  addEntry(tbl, "R5", 0x0005);
  addEntry(tbl, "R6", 0x0006);
  addEntry(tbl, "R7", 0x0007);
  addEntry(tbl, "R8", 0x0008);
  addEntry(tbl, "R9", 0x0009);
  addEntry(tbl, "R10", 0x000a);
  addEntry(tbl, "R11", 0x000b);
  addEntry(tbl, "R12", 0x000c);
  addEntry(tbl, "R13", 0x000d);
  addEntry(tbl, "R14", 0x000e);
  addEntry(tbl, "R15", 0x000f);
}

canonical_original_code:
void initTable(struct head *tbl)
{
  tbl->count = 16;
  tbl->table = (struct node **) calloc(31, sizeof(struct node *));
  addEntry(tbl, "SP", 0x0000);
  addEntry(tbl, "LCL", 0x0001);
  addEntry(tbl, "ARG", 0x0002);
  addEntry(tbl, "THIS", 0x0003);
  addEntry(tbl, "THAT", 0x0004);
  addEntry(tbl, "SCREEN", 0x4000);
  addEntry(tbl, "KBD", 0x6000);
  addEntry(tbl, "R0", 0x0000);
  addEntry(tbl, "R1", 0x0001);
  addEntry(tbl, "R2", 0x0002);
  addEntry(tbl, "R3", 0x0003);
  addEntry(tbl, "R4", 0x0004);
  addEntry(tbl, "R5", 0x0005);
  addEntry(tbl, "R6", 0x0006);
  addEntry(tbl, "R7", 0x0007);
  addEntry(tbl, "R8", 0x0008);
  addEntry(tbl, "R9", 0x0009);
  addEntry(tbl, "R10", 0x000a);
  addEntry(tbl, "R11", 0x000b);
  addEntry(tbl, "R12", 0x000c);
  addEntry(tbl, "R13", 0x000d);
  addEntry(tbl, "R14", 0x000e);
  addEntry(tbl, "R15", 0x000f);
}


getAddress

decompiled_code:
__int64 __fastcall getAddress(__int64 a1, char *a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // [rsp+Ch] [rbp-1Ch]

if ( (unsigned __int8)(*a2 - 48) > 9u || (result = toNum(a2), (_DWORD)result == -2) )
{
v3 = contains(*(_QWORD *)a1, a2);
if ( v3 )
{
result = *(unsigned int *)(v3 + 8);
}
else
{
v4 = *(_DWORD *)(a1 + 8);
addEntry(a1, a2, -1);
result = v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char *a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // [rsp+Ch] [rbp-1Ch]

if ( (unsigned __int8)(*a2 - 48) > 9u || (result = func3(a2), (_DWORD)result == -2) )
{
v3 = func6(*(_QWORD *)a1, a2);
if ( v3 )
{
result = *(unsigned int *)(v3 + 8);
}
else
{
v4 = *(_DWORD *)(a1 + 8);
func8(a1, a2, -1);
result = v4;
}
}
return result;
}

original_code:
int getAddress(SymbolTable* tbl, char* sym)
{
  bucket *tmp;
  int res = -2;
  if(sym[0] > 47 && sym[0] < 58)
    res = toNum(sym);
  if(res != -2)
    return res;
  if((tmp = contains(tbl->table, sym)) == ((void *)0))
  {
    res = tbl->count;
    addEntry(tbl, sym, -1);
    return res;
  }
  return tmp->address;
}

canonical_original_code:
int getAddress(struct head *tbl, char *sym)
{
  struct node *tmp;
  int res = -2;
  if(sym[0] > 47 && sym[0] < 58)
    res = toNum(sym);
  if(res != -2)
    return res;
  if((tmp = contains(tbl->table, sym)) == ((void *)0))
  {
    res = tbl->count;
    addEntry(tbl, sym, -1);
    return res;
  }
  return tmp->address;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r14
const char *v4; // r12
char *v5; // r13
char *v6; // rbp

if ( argc <= 1 )
return 1;
v3 = argv + 1;
do
{
v4 = *v3++;
v5 = (char *)(strrchr(v4, 46) - v4);
v6 = (char *)calloc((size_t)(v5 + 6), 1uLL);
strncpy(v6, v4, (size_t)v5);
strcat(v6, ".rom");
assemble(v4, v6);
free(v6);
}
while ( &argv[(unsigned int)(argc - 2) + 2] != v3 );
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc < 2)
    return 1;
  for(int i=1; i<argc; i++)
  {
    char* tp = strrchr(argv[i], '.');
    char* ofn = calloc((tp-argv[i]) + 6, sizeof(char));
    strncpy(ofn, argv[i], tp-argv[i]);
    strcat(ofn, ".rom");
    assemble(argv[i], ofn);
    free(ofn);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc < 2)
    return 1;
  for(int i = 1; i<argc; i++)
  {
    char *tp = strrchr(argv[i], '.');
    char *ofn = calloc((tp-argv[i]) + 6, sizeof(char));
    strncpy(ofn, argv[i], tp-argv[i]);
    strcat(ofn, ".rom");
    assemble(argv[i], ofn);
    free(ofn);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
tp
char *

variable_types:
ofn
char *


destCode

decompiled_code:
__int64 __fastcall destCode(char *s)
{
__int16 v1; // bx

v1 = 4 * (strchr(s, 65) != 0LL);
if ( strchr(s, 68) )
v1 += 2;
return (unsigned int)(8 * (__int16)(v1 - ((strchr(s, 77) == 0LL) - 1)));
}

original_code:
short int destCode(char* m)
{
  short int res = 0;
  if(strchr(m, 'A'))
    res += 4;
  if(strchr(m, 'D'))
    res += 2;
  if(strchr(m, 'M'))
    res += 1;
  return res << 3;
}

canonical_original_code:
short destCode(char *m)
{
  short res = 0;
  if(strchr(m, 'A'))
    res += 4;
  if(strchr(m, 'D'))
    res += 2;
  if(strchr(m, 'M'))
    res += 1;
  return res << 3;
}

variable_types:
m
char *

variable_types: res short

return_type: short


compCode

decompiled_code:
__int64 __fastcall compCode(char *s)
{
char v1; // bp
size_t v2; // r12
char *v3; // r13
char *v4; // rax
char *v5; // rdx
int v6; // eax
unsigned int v7; // er8
int v9; // eax
char v10; // dl
char v11; // cl
bool v12; // cc
int v13; // eax
int v14; // eax
char v15; // cl
int v16; // eax
int v17; // ecx
int v18; // ecx
int v19; // eax
unsigned int v20; // eax
int v21; // eax

v1 = *s;
if ( !*s )
return (unsigned int)-1;
v2 = strlen(s);
if ( v2 > 3 )
return (unsigned int)-1;
v3 = strchr(s, 65);
v4 = strchr(s, 77);
v5 = v4;
if ( v3 )
{
v6 = 0;
if ( v5 )
return (unsigned int)-1;
}
else
{
v6 = v4 != 0LL ? 0x40 : 0;
}
switch ( v1 )
{
case '!':
goto LABEL_14;
case '-':
++v6;
LABEL_14:
if ( v2 <= 1 )
return (unsigned int)-1;
v9 = v6 + 1;
goto LABEL_16;
case '0':
goto LABEL_11;
case '1':
v6 += 21;
LABEL_11:
if ( v2 > 1 )
return (unsigned int)-1;
return (unsigned int)((v6 + 42) << 6);
case 'A':
case 'M':
v9 = v6 | 0x30;
goto LABEL_31;
case 'D':
v9 = v6 | 0xC;
LABEL_31:
if ( v2 <= 1 )
return (unsigned int)(v9 << 6);
LABEL_16:
v10 = s[1];
if ( v10 <= 77 )
{
v7 = -1;
if ( v10 <= 37 )
return v7;
switch ( v10 )
{
case '&':
goto LABEL_20;
case '+':
case '-':
v9 |= 2u;
goto LABEL_20;
case '1':
goto LABEL_34;
case 'A':
case 'D':
case 'M':
if ( (v9 & 1) != 0 )
{
if ( v2 == 3 )
return (unsigned int)-1;
v17 = v9;
v9 |= 0x30u;
v18 = v17 | 0xC;
if ( v10 == 68 )
v9 = v18;
return (unsigned int)(v9 << 6);
}
LABEL_34:
if ( v2 != 3 && (v9 & 2) != 0 )
{
if ( v10 == 68 )
{
v9 |= 0xCu;
return (unsigned int)(v9 << 6);
}
if ( v10 > 68 )
{
if ( v10 != 77 )
return (unsigned int)-1;
LABEL_43:
v9 |= 0x30u;
return (unsigned int)(v9 << 6);
}
if ( v10 == 49 )
{
v9 |= 0x38u;
return (unsigned int)(v9 << 6);
}
if ( v10 == 65 )
goto LABEL_43;
}
break;
default:
return (unsigned int)-1;
}
return (unsigned int)-1;
}
if ( v10 != 124 )
return (unsigned int)-1;
LABEL_20:
if ( v2 == 2 )
return (unsigned int)(v9 << 6);
if ( (v9 & 0xC) != 12 )
{
if ( (v9 & 0x30) != 48 )
return (unsigned int)-1;
v11 = s[2];
if ( v11 != 49 )
{
if ( v11 != 68 )
return (unsigned int)-1;
LABEL_25:
v12 = v10 <= 45;
if ( v10 == 45 )
{
v19 = ((_WORD)v9 << 6) & 0x11C0;
HIWORD(v7) = HIWORD(v19);
LOWORD(v7) = v19 | 0x140;
return v7;
}
goto LABEL_26;
}
if ( v10 != 43 )
{
LABEL_60:
v20 = v9 << 6;
v7 = -1;
if ( v10 == 45 )
v7 = v20;
return v7;
}
v9 |= 5u;
return (unsigned int)(v9 << 6);
}
v15 = s[2];
if ( v15 == 68 )
{
if ( (v9 & 0x30) != 48 )
return (unsigned int)-1;
goto LABEL_25;
}
if ( v15 > 68 )
{
if ( v15 != 77 )
return (unsigned int)-1;
}
else
{
if ( v15 == 49 )
{
if ( v10 != 43 )
goto LABEL_60;
v9 |= 0x11u;
return (unsigned int)(v9 << 6);
}
if ( v15 != 65 )
return (unsigned int)-1;
}
v12 = v10 <= 45;
if ( v10 == 45 )
{
v16 = ((_WORD)v9 << 6) & 0x14C0;
HIWORD(v7) = HIWORD(v16);
LOWORD(v7) = v16 | 0x440;
return v7;
}
LABEL_26:
if ( v12 )
{
if ( v10 == 38 )
{
v21 = v9 << 6;
HIWORD(v7) = HIWORD(v21);
LOWORD(v7) = v21 & 0x1000;
}
else
{
if ( v10 != 43 )
return (unsigned int)-1;
v13 = v9 << 6;
HIWORD(v7) = HIWORD(v13);
LOWORD(v7) = v13 & 0x1080;
}
return v7;
}
if ( v10 == 124 )
{
v14 = ((_WORD)v9 << 6) & 0x1000;
HIWORD(v7) = HIWORD(v14);
LOWORD(v7) = v14 | 0x540;
return v7;
}
return (unsigned int)-1;
default:
return (unsigned int)-1;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s)
{
char v1; // bp
size_t v2; // r12
char *v3; // r13
char *v4; // rax
char *v5; // rdx
int v6; // eax
unsigned int v7; // er8
int v9; // eax
char v10; // dl
char v11; // cl
bool v12; // cc
int v13; // eax
int v14; // eax
char v15; // cl
int v16; // eax
int v17; // ecx
int v18; // ecx
int v19; // eax
unsigned int v20; // eax
int v21; // eax

v1 = *s;
if ( !*s )
return (unsigned int)-1;
v2 = strlen(s);
if ( v2 > 3 )
return (unsigned int)-1;
v3 = strchr(s, 65);
v4 = strchr(s, 77);
v5 = v4;
if ( v3 )
{
v6 = 0;
if ( v5 )
return (unsigned int)-1;
}
else
{
v6 = v4 != 0LL ? 0x40 : 0;
}
switch ( v1 )
{
case '!':
goto LABEL_14;
case '-':
++v6;
LABEL_14:
if ( v2 <= 1 )
return (unsigned int)-1;
v9 = v6 + 1;
goto LABEL_16;
case '0':
goto LABEL_11;
case '1':
v6 += 21;
LABEL_11:
if ( v2 > 1 )
return (unsigned int)-1;
return (unsigned int)((v6 + 42) << 6);
case 'A':
case 'M':
v9 = v6 | 0x30;
goto LABEL_31;
case 'D':
v9 = v6 | 0xC;
LABEL_31:
if ( v2 <= 1 )
return (unsigned int)(v9 << 6);
LABEL_16:
v10 = s[1];
if ( v10 <= 77 )
{
v7 = -1;
if ( v10 <= 37 )
return v7;
switch ( v10 )
{
case '&':
goto LABEL_20;
case '+':
case '-':
v9 |= 2u;
goto LABEL_20;
case '1':
goto LABEL_34;
case 'A':
case 'D':
case 'M':
if ( (v9 & 1) != 0 )
{
if ( v2 == 3 )
return (unsigned int)-1;
v17 = v9;
v9 |= 0x30u;
v18 = v17 | 0xC;
if ( v10 == 68 )
v9 = v18;
return (unsigned int)(v9 << 6);
}
LABEL_34:
if ( v2 != 3 && (v9 & 2) != 0 )
{
if ( v10 == 68 )
{
v9 |= 0xCu;
return (unsigned int)(v9 << 6);
}
if ( v10 > 68 )
{
if ( v10 != 77 )
return (unsigned int)-1;
LABEL_43:
v9 |= 0x30u;
return (unsigned int)(v9 << 6);
}
if ( v10 == 49 )
{
v9 |= 0x38u;
return (unsigned int)(v9 << 6);
}
if ( v10 == 65 )
goto LABEL_43;
}
break;
default:
return (unsigned int)-1;
}
return (unsigned int)-1;
}
if ( v10 != 124 )
return (unsigned int)-1;
LABEL_20:
if ( v2 == 2 )
return (unsigned int)(v9 << 6);
if ( (v9 & 0xC) != 12 )
{
if ( (v9 & 0x30) != 48 )
return (unsigned int)-1;
v11 = s[2];
if ( v11 != 49 )
{
if ( v11 != 68 )
return (unsigned int)-1;
LABEL_25:
v12 = v10 <= 45;
if ( v10 == 45 )
{
v19 = ((_WORD)v9 << 6) & 0x11C0;
HIWORD(v7) = HIWORD(v19);
LOWORD(v7) = v19 | 0x140;
return v7;
}
goto LABEL_26;
}
if ( v10 != 43 )
{
LABEL_60:
v20 = v9 << 6;
v7 = -1;
if ( v10 == 45 )
v7 = v20;
return v7;
}
v9 |= 5u;
return (unsigned int)(v9 << 6);
}
v15 = s[2];
if ( v15 == 68 )
{
if ( (v9 & 0x30) != 48 )
return (unsigned int)-1;
goto LABEL_25;
}
if ( v15 > 68 )
{
if ( v15 != 77 )
return (unsigned int)-1;
}
else
{
if ( v15 == 49 )
{
if ( v10 != 43 )
goto LABEL_60;
v9 |= 0x11u;
return (unsigned int)(v9 << 6);
}
if ( v15 != 65 )
return (unsigned int)-1;
}
v12 = v10 <= 45;
if ( v10 == 45 )
{
v16 = ((_WORD)v9 << 6) & 0x14C0;
HIWORD(v7) = HIWORD(v16);
LOWORD(v7) = v16 | 0x440;
return v7;
}
LABEL_26:
if ( v12 )
{
if ( v10 == 38 )
{
v21 = v9 << 6;
HIWORD(v7) = HIWORD(v21);
LOWORD(v7) = v21 & 0x1000;
}
else
{
if ( v10 != 43 )
return (unsigned int)-1;
v13 = v9 << 6;
HIWORD(v7) = HIWORD(v13);
LOWORD(v7) = v13 & 0x1080;
}
return v7;
}
if ( v10 == 124 )
{
v14 = ((_WORD)v9 << 6) & 0x1000;
HIWORD(v7) = HIWORD(v14);
LOWORD(v7) = v14 | 0x540;
return v7;
}
return (unsigned int)-1;
default:
return (unsigned int)-1;
}
}

original_code:
short int compCode(char* m)
{
  if(strlen(m) < 1 || strlen(m) > 3)
    return -1;
  char* p = strchr(m, 'A');
  int res = 0;
  if(!((p != ((void *)0)) && ((p = strchr(m, 'M')) != ((void *)0))))
  {
    if((p = strchr(m, 'M')) != ((void *)0))
      res |= 64;
  }
  else
    return -1;
  switch(m[0])
  {
    case '1':
      res += 21;
    case '0':
      if(strlen(m) > 1)
        return -1;
      res += 42;
      return res << 6;
    case '-':
      res++;
    case '!':
      if(strlen(m) < 2)
        return -1;
      res++;
      break;
    case 'D':
      res |= 12;
      break;
    case 'M':
    case 'A':
      res |= 48;
      break;
    default:
      return -1;
  }
  if(strlen(m) < 2)
    return res << 6;
  switch(m[1])
  {
    case 'D':
    case 'M':
    case 'A':
      if((res & 1) == 1)
      {
        if(strlen(m) > 2)
   return -1;
        if(m[1] == 'D')
   res |= 12;
 else
   res |= 48;
 break;
      }
    case '1':
      if(strlen(m) > 2)
        return -1;
      if((res & 2) != 0)
      {
        switch(m[1])
 {
   case 'D':
     res |= 12;
     break;
   case 'M':
   case 'A':
     res |= 48;
     break;
   case '1':
     res |= 56;
     break;
   default:
     return -1;
 }
 break;
      }
      return -1;
    case '-':
    case '+':
      res |= 2;
      break;
    case '|':
    case '&':
      break;
    default:
      return -1;
  }
  if(strlen(m) < 3)
    return res << 6;
  if(((res & 12) != 12) && ((res & 48) != 48))
    return -1;
  switch(m[2])
  {
    case '1':
      switch(m[1])
      {
        case '+':
   if((res & 12) == 12)
     res |= 17;
   else if((res & 48) == 48)
     res |= 5;
   return res << 6;
 case '-':
   return res << 6;
 default:
   return -1;
      }
      break;
    case 'D':
      if((res & 48) != 48)
        return -1;
      switch(m[1])
      {
        case '+':
   res &= 66;
   return res << 6;
 case '-':
   res |= 5;
   res &= 71;
   return res << 6;
 case '|':
   res &= 64;
   res |= 21;
   return res << 6;
 case '&':
   res &= 64;
   return res << 6;
 default:
   return -1;
      }
    case 'M':
    case 'A':
      if((res & 12) != 12)
        return -1;
      switch(m[1])
      {
        case '+':
   res &= 66;
   return res << 6;
 case '-':
   res |= 17;
   res &= 83;
   return res << 6;
 case '|':
   res &= 64;
   res |= 21;
   return res << 6;
 case '&':
   res &= 64;
   return res << 6;
 default:
   return -1;
      }
    default:
      return -1;
  }
}

canonical_original_code:
short compCode(char *m)
{
  if(strlen(m) < 1 || strlen(m) > 3)
    return -1;
  char *p = strchr(m, 'A');
  int res = 0;
  if(!((p != ((void *)0)) && ((p = strchr(m, 'M')) != ((void *)0))))
  {
    if((p = strchr(m, 'M')) != ((void *)0))
      res |= 64;
  }
  else
    return -1;
  switch(m[0])
  {
    case '1':
      res += 21;
    case '0':
      if(strlen(m) > 1)
        return -1;
      res += 42;
      return res << 6;
    case '-':
      res++;
    case '!':
      if(strlen(m) < 2)
        return -1;
      res++;
      break;
    case 'D':
      res |= 12;
      break;
    case 'M':
    case 'A':
      res |= 48;
      break;
    default:
      return -1;
  }
  if(strlen(m) < 2)
    return res << 6;
  switch(m[1])
  {
    case 'D':
    case 'M':
    case 'A':
      if((res & 1) == 1)
      {
        if(strlen(m) > 2)
   return -1;
        if(m[1] == 'D')
   res |= 12;
 else
   res |= 48;
 break;
      }
    case '1':
      if(strlen(m) > 2)
        return -1;
      if((res & 2) != 0)
      {
        switch(m[1])
 {
   case 'D':
     res |= 12;
     break;
   case 'M':
   case 'A':
     res |= 48;
     break;
   case '1':
     res |= 56;
     break;
   default:
     return -1;
 }
 break;
      }
      return -1;
    case '-':
    case '+':
      res |= 2;
      break;
    case '|':
    case '&':
      break;
    default:
      return -1;
  }
  if(strlen(m) < 3)
    return res << 6;
  if(((res & 12) != 12) && ((res & 48) != 48))
    return -1;
  switch(m[2])
  {
    case '1':
      switch(m[1])
      {
        case '+':
   if((res & 12) == 12)
     res |= 17;
   else if((res & 48) == 48)
     res |= 5;
   return res << 6;
 case '-':
   return res << 6;
 default:
   return -1;
      }
      break;
    case 'D':
      if((res & 48) != 48)
        return -1;
      switch(m[1])
      {
        case '+':
   res &= 66;
   return res << 6;
 case '-':
   res |= 5;
   res &= 71;
   return res << 6;
 case '|':
   res &= 64;
   res |= 21;
   return res << 6;
 case '&':
   res &= 64;
   return res << 6;
 default:
   return -1;
      }
    case 'M':
    case 'A':
      if((res & 12) != 12)
        return -1;
      switch(m[1])
      {
        case '+':
   res &= 66;
   return res << 6;
 case '-':
   res |= 17;
   res &= 83;
   return res << 6;
 case '|':
   res &= 64;
   res |= 21;
   return res << 6;
 case '&':
   res &= 64;
   return res << 6;
 default:
   return -1;
      }
    default:
      return -1;
  }
}

variable_types:
p
char *

variable_types: res int


jumpCode

decompiled_code:
__int64 __fastcall jumpCode(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx
unsigned int v3; // er12
char *s2[11]; // [rsp+0h] [rbp-58h]

v1 = (const char *)&unk_6D0;
v2 = 0LL;
s2[0] = (char *)&unk_6D0;
s2[1] = (char *)&unk_6D1;
s2[2] = (char *)&unk_6D5;
s2[3] = (char *)&unk_6D9;
s2[4] = (char *)&unk_6DD;
s2[5] = (char *)&unk_6E1;
s2[6] = (char *)&unk_6E5;
s2[7] = (char *)&unk_6E9;
while ( 1 )
{
v3 = v2;
if ( !strcmp(s1, v1) )
break;
if ( ++v2 == 8 )
return (unsigned int)-1;
v1 = s2[v2];
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx
unsigned int v3; // er12
char *s2[11]; // [rsp+0h] [rbp-58h]

v1 = (const char *)&unk_6D0;
v2 = 0LL;
s2[0] = (char *)&unk_6D0;
s2[1] = (char *)&unk_6D1;
s2[2] = (char *)&unk_6D5;
s2[3] = (char *)&unk_6D9;
s2[4] = (char *)&unk_6DD;
s2[5] = (char *)&unk_6E1;
s2[6] = (char *)&unk_6E5;
s2[7] = (char *)&unk_6E9;
while ( 1 )
{
v3 = v2;
if ( !strcmp(s1, v1) )
break;
if ( ++v2 == 8 )
return (unsigned int)-1;
v1 = s2[v2];
}
return v3;
}

original_code:
short int jumpCode(char* m)
{
  char* jop[] = {
    "",
    "JGT",
    "JEQ",
    "JGE",
    "JLT",
    "JNE",
    "JLE",
    "JMP"
  };
  for(short int i=0; i<8; i++)
    if(strcmp(m, jop[i]) == 0)
      return i;
  return -1;
}

canonical_original_code:
short jumpCode(char *m)
{
  char *jop[] = {
    "",
    "JGT",
    "JEQ",
    "JGE",
    "JLT",
    "JNE",
    "JLE",
    "JMP"
  };
  for(short i = 0; i<8; i++)
    if(strcmp(m, jop[i]) == 0)
      return i;
  return -1;
}

variable_types:
jop
char *[]

variable_types: i short


firstPass

decompiled_code:
__int64 __fastcall firstPass(const char *a1, const char *a2)
{
unsigned int v2; // er12
const char *v3; // rbx
int v4; // edx
int v5; // eax
size_t v6; // rax
char *v7; // rbp

v2 = 0;
v3 = a1;
while ( (unsigned __int8)hasMoreCommands() )
{
while ( 1 )
{
advance(a1, a2);
v5 = commandType();
if ( v5 != 1 )
break;
v6 = strlen(parser_com);
v7 = (char *)calloc(v6 - 1, 1uLL);
parseSymbol(v7);
a2 = v7;
addEntry(v3, v7, v2);
a1 = v7;
free(v7);
if ( !(unsigned __int8)hasMoreCommands() )
goto LABEL_7;
}
v4 = (v5 == 0) + v2++;
if ( v5 != 2 )
v2 = v4;
}
LABEL_7:
parser_cur = 0;
parser_ln = 0;
resetCmd();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
unsigned int v2; // er12
const char *v3; // rbx
int v4; // edx
int v5; // eax
size_t v6; // rax
char *v7; // rbp

v2 = 0;
v3 = a1;
while ( (unsigned __int8)hasMoreCommands() )
{
while ( 1 )
{
advance(a1, a2);
v5 = commandType();
if ( v5 != 1 )
break;
v6 = strlen(parser_com);
v7 = (char *)calloc(v6 - 1, 1uLL);
parseSymbol(v7);
a2 = v7;
addEntry(v3, v7, v2);
a1 = v7;
free(v7);
if ( !(unsigned __int8)hasMoreCommands() )
goto LABEL_7;
}
v4 = (v5 == 0) + v2++;
if ( v5 != 2 )
v2 = v4;
}
LABEL_7:
parser_cur = 0;
parser_ln = 0;
resetCmd();
return v2;
}

original_code:
int firstPass(SymbolTable* symtbl)
{
  int res = 0;
  while(hasMoreCommands())
  {
    advance();
    char* tmp;
    switch(commandType())
    {
      case A_COMMAND:
        res++;
        break;
      case L_COMMAND:
        tmp = (char*) calloc(strlen(_parser_com) - 1, sizeof(char));
 parseSymbol(tmp);
 addEntry(symtbl, tmp, res);
 free(tmp);
        break;
      case C_COMMAND:
        res++;
        break;
    }
  }
  _parser_cur = 0;
  _parser_ln = 0;
  resetCmd();
  return res;
}

canonical_original_code:
int firstPass(struct head *symtbl)
{
  int res = 0;
  while(hasMoreCommands())
  {
    advance();
    char *tmp;
    switch(commandType())
    {
      case A_COMMAND:
        res++;
        break;
      case L_COMMAND:
        tmp = (char *) calloc(strlen(_parser_com) - 1, sizeof(char));
 parseSymbol(tmp);
 addEntry(symtbl, tmp, res);
 free(tmp);
        break;
      case C_COMMAND:
        res++;
        break;
    }
  }
  _parser_cur = 0;
  _parser_ln = 0;
  resetCmd();
  return res;
}

variable_types:
tmp
char *


error

decompiled_code:
int error(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
if ( errflag < a1 )
errflag = a1;
return result;
}

canonical_decompiled_code:
int func1(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
if ( errflag < a1 )
errflag = a1;
return result;
}

original_code:
void error(int sev, char* msg, ...)
{
  va_list arg;
  __builtin_va_start(arg,msg);
  vfprintf(stderr, msg, arg);
  __builtin_va_end(arg);
  if(sev > errflag)
    errflag = sev;
}

canonical_original_code:
void error(int sev, char *msg, ...)
{
  __builtin_va_list arg;
  __builtin_va_start(arg,msg);
  vfprintf(stderr, msg, arg);
  __builtin_va_end(arg);
  if(sev > errflag)
    errflag = sev;
}

variable_types: sev int

variable_types:
msg
char *


secondPass

decompiled_code:
__int64 __fastcall secondPass(const char *a1, unsigned __int64 a2)
{
const char *v2; // r13
int v3; // ebx
size_t v4; // rax
char *v5; // r12
__int16 v6; // r15
__int16 v7; // r15
__int16 v8; // r14
__int64 v9; // rax
char *v10; // rbp
int v11; // eax
size_t v12; // rax
char *v13; // r14
__int64 v14; // rax
unsigned __int64 v16; // [rsp+8h] [rbp-40h]

v2 = a1;
v3 = 0;
v16 = a2;
while ( (unsigned __int8)hasMoreCommands() )
{
advance(a1, (const char *)a2);
a2 = 1LL;
v10 = (char *)calloc(3uLL, 1uLL);
v11 = commandType();
if ( v11 )
{
if ( v11 == 2 )
{
v4 = strlen(parser_com);
v5 = (char *)calloc(v4, 1uLL);
parseDest(v5);
v6 = destCode(v5);
parseJump(v5);
if ( (unsigned __int16)jumpCode(v5) == 0xFFFF )
error(2, "%s:%d: Error: Invalid Jump command `%s'\n", (const char *)fn, parser_ln, v5);
v7 = v6 - 0x2000;
v8 = jumpCode(v5);
parseComp(v5);
if ( (unsigned __int16)compCode(v5) == 0xFFFF )
error(2, "%s:%d: Error: Invalid Code command `%s'\n", (const char *)fn, parser_ln, v5);
a2 = (unsigned __int16)(compCode(v5) + v7 + v8);
parseBin(v10, a2);
v9 = v3;
v3 += 2;
*(_WORD *)(v16 + v9) = *(_WORD *)v10;
free(v5);
}
}
else
{
v12 = strlen(parser_com);
v13 = (char *)calloc(v12, 1uLL);
parseSymbol(v13);
if ( (unsigned int)getAddress(v2, v13) == -1 )
error(2, "%s:%d: Error: Invalid Label `%s'/n", (const char *)fn, parser_ln, v13);
a2 = (unsigned __int16)getAddress(v2, v13);
parseBin(v10, a2);
v14 = v3;
v3 += 2;
*(_WORD *)(v16 + v14) = *(_WORD *)v10;
free(v13);
}
a1 = v10;
free(v10);
}
return resetCmd();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, unsigned __int64 a2)
{
const char *v2; // r13
int v3; // ebx
size_t v4; // rax
char *v5; // r12
__int16 v6; // r15
__int16 v7; // r15
__int16 v8; // r14
__int64 v9; // rax
char *v10; // rbp
int v11; // eax
size_t v12; // rax
char *v13; // r14
__int64 v14; // rax
unsigned __int64 v16; // [rsp+8h] [rbp-40h]

v2 = a1;
v3 = 0;
v16 = a2;
while ( (unsigned __int8)hasMoreCommands() )
{
advance(a1, (const char *)a2);
a2 = 1LL;
v10 = (char *)calloc(3uLL, 1uLL);
v11 = commandType();
if ( v11 )
{
if ( v11 == 2 )
{
v4 = strlen(parser_com);
v5 = (char *)calloc(v4, 1uLL);
parseDest(v5);
v6 = destCode(v5);
parseJump(v5);
if ( (unsigned __int16)jumpCode(v5) == 0xFFFF )
func1(2, "%s:%d: Error: Invalid Jump command `%s'\n", (const char *)fn, parser_ln, v5);
v7 = v6 - 0x2000;
v8 = jumpCode(v5);
parseComp(v5);
if ( (unsigned __int16)compCode(v5) == 0xFFFF )
func1(2, "%s:%d: Error: Invalid Code command `%s'\n", (const char *)fn, parser_ln, v5);
a2 = (unsigned __int16)(compCode(v5) + v7 + v8);
parseBin(v10, a2);
v9 = v3;
v3 += 2;
*(_WORD *)(v16 + v9) = *(_WORD *)v10;
free(v5);
}
}
else
{
v12 = strlen(parser_com);
v13 = (char *)calloc(v12, 1uLL);
parseSymbol(v13);
if ( (unsigned int)getAddress(v2, v13) == -1 )
func1(2, "%s:%d: Error: Invalid Label `%s'/n", (const char *)fn, parser_ln, v13);
a2 = (unsigned __int16)getAddress(v2, v13);
parseBin(v10, a2);
v14 = v3;
v3 += 2;
*(_WORD *)(v16 + v14) = *(_WORD *)v10;
free(v13);
}
a1 = v10;
free(v10);
}
return resetCmd();
}

original_code:
void secondPass(SymbolTable* symtbl, unsigned char* out)
{
 int outp = 0;
  while(hasMoreCommands())
  {
    advance();
    unsigned short op = 0;
    unsigned char* bin = (unsigned char*) calloc(3, sizeof(char));
    char* tmp;
    switch(commandType())
    {
      case A_COMMAND:
        tmp = (char*) calloc(strlen(_parser_com), sizeof(char));
    parseSymbol(tmp);
    if(getAddress(symtbl, tmp) == -1)
     error(2, "%s:%d: Error: Invalid Label `%s'/n", fn, _parser_ln, tmp);
        op = getAddress(symtbl, tmp);
    parseBin(bin, op);
    memcpy(out + outp, bin, 2);
    outp += 2;
    free(tmp);
        break;
      case C_COMMAND:
        tmp = (char*) calloc(strlen(_parser_com), sizeof(char));
    parseDest(tmp);
    op += destCode(tmp);
    parseJump(tmp);
    if(jumpCode(tmp) == -1)
     error(2, "%s:%d: Error: Invalid Jump command `%s'\n", fn, _parser_ln, tmp);
        op += jumpCode(tmp);
        parseComp(tmp);
    if(compCode(tmp) == -1)
      error(2, "%s:%d: Error: Invalid Code command `%s'\n", fn, _parser_ln, tmp);
    op += compCode(tmp);
    op += 57344;
    parseBin(bin, op);
    memcpy(out + outp, bin, 2);
    outp += 2;
    free(tmp);
        break;
    }
    free(bin);
  }
  resetCmd();
}

canonical_original_code:
void secondPass(struct head *symtbl, unsigned char *out)
{
 int outp = 0;
  while(hasMoreCommands())
  {
    advance();
    unsigned short op = 0;
    unsigned char *bin = (unsigned char*) calloc(3, sizeof(char));
    char *tmp;
    switch(commandType())
    {
      case A_COMMAND:
        tmp = (char *) calloc(strlen(_parser_com), sizeof(char));
    parseSymbol(tmp);
    if(getAddress(symtbl, tmp) == -1)
     error(2, "%s:%d: Error: Invalid Label `%s'/n", fn, _parser_ln, tmp);
        op = getAddress(symtbl, tmp);
    parseBin(bin, op);
    memcpy(out + outp, bin, 2);
    outp += 2;
    free(tmp);
        break;
      case C_COMMAND:
        tmp = (char *) calloc(strlen(_parser_com), sizeof(char));
    parseDest(tmp);
    op += destCode(tmp);
    parseJump(tmp);
    if(jumpCode(tmp) == -1)
     error(2, "%s:%d: Error: Invalid Jump command `%s'\n", fn, _parser_ln, tmp);
        op += jumpCode(tmp);
        parseComp(tmp);
    if(compCode(tmp) == -1)
      error(2, "%s:%d: Error: Invalid Code command `%s'\n", fn, _parser_ln, tmp);
    op += compCode(tmp);
    op += 57344;
    parseBin(bin, op);
    memcpy(out + outp, bin, 2);
    outp += 2;
    free(tmp);
        break;
    }
    free(bin);
  }
  resetCmd();
}

variable_types:
out
unsigned char *

variable_types: outp int

variable_types:
op
unsigned short

variable_types:
bin
unsigned char *


repo: litaocheng/apue-exercise

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

result = malloc(0x30uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 10) = 0;
}
return result;
}

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

result = malloc(0x30uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 10) = 0;
}
return result;
}

original_code:
list_st * list_new()
{
    list_st * l;
    l = malloc(sizeof(list_st));
    if (!l) return ((void *)0);
    l->head = l->tail = ((void *)0);
    l->dup = ((void *)0);
    l->free = ((void *)0);
    l->match = ((void *)0);
    l->len = 0;
    return l;
}

canonical_original_code:
struct list_st *list_new()
{
    struct list_st *l;
    l = malloc(sizeof(list_st));
    if (!l) return ((void *)0);
    l->head = l->tail = ((void *)0);
    l->dup = ((void *)0);
    l->free = ((void *)0);
    l->match = ((void *)0);
    l->len = 0;
    return l;
}

variable_types: struct list_st { struct list_node_st { struct list_node_st *next; struct list_node_st *prev; void *value; } *head; struct list_node_st *tail; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *value); unsigned int len; } *

user_defined_types: struct list_st { struct list_node_st *head; struct list_node_st *tail; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *value); unsigned int len; }


decompiled_code:
void __fastcall list_free(void *ptr)
{
_QWORD *v1; // rbp
void (__fastcall *v2)(_QWORD); // rax
_QWORD *v3; // rbx

if ( !ptr )
__assert_fail("l", "list.c", 0x1Au, "list_free");
v1 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
while ( 1 )
{
v2 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 3);
if ( v2 )
v2(v1[2]);
v3 = (_QWORD *)*v1;
free(v1);
if ( !v3 )
break;
v1 = v3;
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
_QWORD *v1; // rbp
void (__fastcall *v2)(_QWORD); // rax
_QWORD *v3; // rbx

if ( !ptr )
__assert_fail("l", "list.c", 0x1Au, "list_free");
v1 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
while ( 1 )
{
v2 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 3);
if ( v2 )
v2(v1[2]);
v3 = (_QWORD *)*v1;
free(v1);
if ( !v3 )
break;
v1 = v3;
}
}
free(ptr);
}

original_code:
void list_free(list_st * l)
{
    ((void) sizeof ((l) ? 1 : 0), __extension__ ({ if (l) ; else __assert_fail ("l", "list.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    list_node_st *cur;
    list_node_st *node = l->head;
    while (node) {
        if (l->free)
            l->free(node->value);
        cur = node;
        node = node->next;
        free(cur);
    }
    free(l);
}

canonical_original_code:
void list_free(struct list_st *l)
{
    ((void) sizeof ((l) ? 1 : 0), __extension__ ({ if (l) ; else __assert_fail ("l", "list.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    struct list_node_st *cur;
    struct list_node_st *node = l->head;
    while (node) {
        if (l->free)
            l->free(node->value);
        cur = node;
        node = node->next;
        free(cur);
    }
    free(l);
}

variable_types: struct list_node_st { struct list_node_st *next; struct list_node_st *prev; void *value; } *


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

result = *(_QWORD *)(a1 + 8);
if ( result )
{
*a2 = *(_QWORD *)(result + 16);
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 8);
if ( result == *(_QWORD *)a1 )
*(_QWORD *)a1 = 0LL;
--*(_DWORD *)(a1 + 40);
result = a1;
}
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( result )
{
*a2 = *(_QWORD *)(result + 16);
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 8);
if ( result == *(_QWORD *)a1 )
*(_QWORD *)a1 = 0LL;
--*(_DWORD *)(a1 + 40);
result = a1;
}
return result;
}

original_code:
list_st * list_pop_tail(list_st *l, void **value)
{
    list_node_st *node;
    if (l->tail == ((void *)0)) {
        return ((void *)0);
    } else {
        node = l->tail;
        *value = node->value;
        l->tail = node->prev;
        if (node == l->head)
            l->head = ((void *)0);
    }
    l->len--;
    return l;
}

canonical_original_code:
struct list_st *list_pop_tail(struct list_st *l, void **value)
{
    struct list_node_st *node;
    if (l->tail == ((void *)0)) {
        return ((void *)0);
    } else {
        node = l->tail;
        *value = node->value;
        l->tail = node->prev;
        if (node == l->head)
            l->head = ((void *)0);
    }
    l->len--;
    return l;
}

variable_types:
l
struct list_st *

variable_types:
value
void **

return_type: struct list_st { struct list_node_st { struct list_node_st *next; struct list_node_st *prev; void *value; } *head; struct list_node_st *tail; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *value); unsigned int len; } *


original_code:
list_st * list_delete(list_st *l, list_node_st *node)
{
    ((void) sizeof ((node) ? 1 : 0), __extension__ ({ if (node) ; else __assert_fail ("node", "list.c", 147, __extension__ __PRETTY_FUNCTION__); }));
    if (node->prev)
        node->prev->next = node->next;
    if(node->next)
        node->next->prev = node->prev;
    if (l->head == node) {
        l->head = node->next;
    }
    if (l->tail == node) {
        l->tail = node->prev;
    }
    if (l->free) l->free(node->value);
    free(node);
    l->len--;
    return l;
}

canonical_original_code:
struct list_st *list_delete(struct list_st *l, struct list_node_st *node)
{
    ((void) sizeof ((node) ? 1 : 0), __extension__ ({ if (node) ; else __assert_fail ("node", "list.c", 147, __extension__ __PRETTY_FUNCTION__); }));
    if (node->prev)
        node->prev->next = node->next;
    if(node->next)
        node->next->prev = node->prev;
    if (l->head == node) {
        l->head = node->next;
    }
    if (l->tail == node) {
        l->tail = node->prev;
    }
    if (l->free) l->free(node->value);
    free(node);
    l->len--;
    return l;
}

variable_types:
node
struct list_node_st *

user_defined_types: struct list_node_st { struct list_node_st *next; struct list_node_st *prev; void *value; }


decompiled_code:
// attributes: thunk
void list_iter_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func12(void *ptr)
{
free(ptr);
}

original_code:
void list_iter_free(list_iter_st *iter)
{
    free(iter);
}

canonical_original_code:
void list_iter_free(struct list_iter_st *iter)
{
    free(iter);
}

variable_types: struct list_iter_st { struct list_node_st { struct list_node_st *next; struct list_node_st *prev; void *value; } *node; int direction; } *

user_defined_types: struct list_iter_st { struct list_node_st *node; int direction; }


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

result = *a1;
*(_DWORD *)(a2 + 8) = 1;
*(_QWORD *)a2 = result;
return result;
}

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

result = *a1;
*(_DWORD *)(a2 + 8) = 1;
*(_QWORD *)a2 = result;
return result;
}

original_code:
void list_iter_rewind(list_st *l, list_iter_st *iter)
{
    iter->node = l->head;
    iter->direction = 1;
}

canonical_original_code:
void list_iter_rewind(struct list_st *l, struct list_iter_st *iter)
{
    iter->node = l->head;
    iter->direction = 1;
}

variable_types: struct list_iter_st { struct list_node_st *node; int direction; } *


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

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

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

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

original_code:
void list_iter_rewind_tail(list_st *l, list_iter_st *iter)
{
    iter->node = l->tail;
    iter->direction = 0;
}

canonical_original_code:
void list_iter_rewind_tail(struct list_st *l, struct list_iter_st *iter)
{
    iter->node = l->tail;
    iter->direction = 0;
}


decompiled_code:
void __fastcall print_list(__int64 a1)
{
unsigned int v1; // ebp
_DWORD *v2; // r12
__int64 v3; // rsi
_QWORD *v4; // rax

v1 = 0;
v2 = list_iter_new((_QWORD *)a1, 1);
printf("list (%d) =>\n", *(unsigned int *)(a1 + 40));
while ( 1 )
{
v4 = list_iter_next((__int64)v2);
if ( !v4 )
break;
v3 = v1++;
printf(" [%d] = %s\n", v3, (const char *)v4[2]);
}
list_iter_free(v2);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
unsigned int v1; // ebp
_DWORD *v2; // r12
__int64 v3; // rsi
_QWORD *v4; // rax

v1 = 0;
v2 = list_iter_new((_QWORD *)a1, 1);
printf("list (%d) =>\n", *(unsigned int *)(a1 + 40));
while ( 1 )
{
v4 = list_iter_next((__int64)v2);
if ( !v4 )
break;
v3 = v1++;
printf(" [%d] = %s\n", v3, (const char *)v4[2]);
}
func12(v2);
}

original_code:
void print_list(list_st *l)
{
    list_iter_st *iter;
    list_node_st *node;
    int i = 0;
    iter = list_iter_new(l, 1);
    printf("list (%d) =>\n", ((l)->len));
    while (node = list_iter_next(iter)) {
        printf(" [%d] = %s\n", i++, (char *)node->value);
    }
    list_iter_free(iter);
}

canonical_original_code:
void print_list(struct list_st *l)
{
    struct list_iter_st *iter;
    struct list_node_st *node;
    int i = 0;
    iter = list_iter_new(l, 1);
    printf("list (%d) =>\n", ((l)->len));
    while (node = list_iter_next(iter)) {
        printf(" [%d] = %s\n", i++, (char *)node->value);
    }
    list_iter_free(iter);
}

variable_types: i int


decompiled_code:
void __fastcall print_list_reverse(__int64 a1)
{
_DWORD *v1; // rbp
unsigned int v2; // ebx
_QWORD *v3; // rax

v1 = list_iter_new((_QWORD *)a1, 1);
list_iter_rewind_tail(a1, (__int64)v1);
v2 = *(_DWORD *)(a1 + 40);
printf("list (%d) reverse =>\n", v2);
while ( 1 )
{
v3 = list_iter_next((__int64)v1);
if ( !v3 )
break;
printf(" [%d] = %s\n", --v2, (const char *)v3[2]);
}
list_iter_free(v1);
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1)
{
_DWORD *v1; // rbp
unsigned int v2; // ebx
_QWORD *v3; // rax

v1 = list_iter_new((_QWORD *)a1, 1);
func14(a1, (__int64)v1);
v2 = *(_DWORD *)(a1 + 40);
printf("list (%d) reverse =>\n", v2);
while ( 1 )
{
v3 = list_iter_next((__int64)v1);
if ( !v3 )
break;
printf(" [%d] = %s\n", --v2, (const char *)v3[2]);
}
func12(v1);
}

original_code:
void print_list_reverse(list_st *l)
{
    int i = 0;
    list_iter_st *iter;
    list_node_st *node;
    iter = list_iter_new(l, 1);
    list_iter_rewind_tail(l, iter);
    i = ((l)->len);
    printf("list (%d) reverse =>\n", ((l)->len));
    while (node = list_iter_next(iter)) {
        printf(" [%d] = %s\n", --i, (char *)node->value);
    }
    list_iter_free(iter);
}

canonical_original_code:
void print_list_reverse(struct list_st *l)
{
    int i = 0;
    struct list_iter_st *iter;
    struct list_node_st *node;
    iter = list_iter_new(l, 1);
    list_iter_rewind_tail(l, iter);
    i = ((l)->len);
    printf("list (%d) reverse =>\n", ((l)->len));
    while (node = list_iter_next(iter)) {
        printf(" [%d] = %s\n", --i, (char *)node->value);
    }
    list_iter_free(iter);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
const char *v7[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = (_QWORD *)list_new(argc, argv, envp);
list_push_head(v3, "element0");
list_push_tail(v3, "element1");
print_list(v3);
list_pop_head(v3, v7);
printf("pop head value is %s\n", v7[0]);
list_pop_tail(v3, v7);
printf("pop tail value is %s\n", v7[0]);
print_list(v3);
list_push_head(v3, "element2");
if ( !list_insert(v3, *v3, "element3", 1LL) )
__assert_fail("list_insert(list, list_head(list), (void *)v[3], 1)", "list.c", 0x14Au, "main");
list_push_tail(v3, "element4");
list_push_head(v3, "element5");
print_list(v3);
print_list_reverse(v3);
v4 = list_find(v3, "element3");
if ( !list_delete(v3, v4) )
__assert_fail("list_delete(list, node)", "list.c", 0x151u, "main");
print_list(v3);
v5 = list_index(v3, 0LL);
printf("node is %s\n", *(const char **)(v5 + 16));
list_free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
const char *v7[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = (_QWORD *)func7(argc, argv, envp);
list_push_head(v3, "element0");
func9(v3, "element1");
func16(v3);
list_pop_head(v3, v7);
printf("pop head value is %s\n", v7[0]);
func10(v3, v7);
printf("pop tail value is %s\n", v7[0]);
func16(v3);
list_push_head(v3, "element2");
if ( !list_insert(v3, *v3, "element3", 1LL) )
__assert_fail("list_insert(list, list_head(list), (void *)v[3], 1)", "list.c", 0x14Au, "main");
func9(v3, "element4");
list_push_head(v3, "element5");
func16(v3);
func17(v3);
v4 = list_find(v3, "element3");
if ( !func11(v3, v4) )
__assert_fail("list_delete(list, node)", "list.c", 0x151u, "main");
func16(v3);
v5 = list_index(v3, 0LL);
printf("node is %s\n", *(const char **)(v5 + 16));
func8(v3);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
    const char * v[] = {
        "element0",
        "element1",
        "element2",
        "element3",
        "element4",
        "element5"
    };
    void *value;
    list_st * list;
    list_node_st *node;
    list = list_new();
    list_push_head(list, (void *)v[0]);
    list_push_tail(list, (void *)v[1]);
    print_list(list);
    list_pop_head(list, &value);
    printf("pop head value is %s\n", (const char*)value);
    list_pop_tail(list, &value);
    printf("pop tail value is %s\n", (const char*)value);
    print_list(list);
    list_push_head(list, (void *)v[2]);
    ((void) sizeof ((list_insert(list, ((list)->head), (void *)v[3], 1)) ? 1 : 0), __extension__ ({ if (list_insert(list, ((list)->head), (void *)v[3], 1)) ; else __assert_fail ("list_insert(list, list_head(list), (void *)v[3], 1)", "list.c", 330, __extension__ __PRETTY_FUNCTION__); }));
    list_push_tail(list, (void*)v[4]);
    list_push_head(list, (void*)v[5]);
    print_list(list);
    print_list_reverse(list);
    node = list_find(list, (void *)v[3]);
    ((void) sizeof ((list_delete(list, node)) ? 1 : 0), __extension__ ({ if (list_delete(list, node)) ; else __assert_fail ("list_delete(list, node)", "list.c", 337, __extension__ __PRETTY_FUNCTION__); }));
    print_list(list);
    node = list_index(list, 0);
    printf("node is %s\n", (const char*)node->value);
    list_free(list);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *v[] = {
        "element0",
        "element1",
        "element2",
        "element3",
        "element4",
        "element5"
    };
    void *value;
    struct list_st *list;
    struct list_node_st *node;
    list = list_new();
    list_push_head(list, (void *)v[0]);
    list_push_tail(list, (void *)v[1]);
    print_list(list);
    list_pop_head(list, &value);
    printf("pop head value is %s\n", (char *)value);
    list_pop_tail(list, &value);
    printf("pop tail value is %s\n", (char *)value);
    print_list(list);
    list_push_head(list, (void *)v[2]);
    ((void) sizeof ((list_insert(list, ((list)->head), (void *)v[3], 1)) ? 1 : 0), __extension__ ({ if (list_insert(list, ((list)->head), (void *)v[3], 1)) ; else __assert_fail ("list_insert(list, list_head(list), (void *)v[3], 1)", "list.c", 330, __extension__ __PRETTY_FUNCTION__); }));
    list_push_tail(list, (void *)v[4]);
    list_push_head(list, (void *)v[5]);
    print_list(list);
    print_list_reverse(list);
    node = list_find(list, (void *)v[3]);
    ((void) sizeof ((list_delete(list, node)) ? 1 : 0), __extension__ ({ if (list_delete(list, node)) ; else __assert_fail ("list_delete(list, node)", "list.c", 337, __extension__ __PRETTY_FUNCTION__); }));
    print_list(list);
    node = list_index(list, 0);
    printf("node is %s\n", (char *)node->value);
    list_free(list);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
v
char *[]

variable_types:
value
void *


decompiled_code:
void __fastcall queue_free(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void queue_free(queue_st * q)
{
    if (!q) return;
    free(q);
}

canonical_original_code:
void queue_free(struct queue_st *q)
{
    if (!q) return;
    free(q);
}

variable_types: struct queue_st { void **queue; void **queuet; unsigned long queues; unsigned long queuen; void **tail; void **head; unsigned long n; } *


decompiled_code:
__int64 __fastcall queue_push(__int64 a1, const void *a2, size_t a3)
{
void **v3; // rax
unsigned __int64 v4; // rax
unsigned int v5; // er8

if ( a1 && a2 )
{
if ( *(_QWORD *)(a1 + 16) != a3 )
return (unsigned int)-2;
v3 = *(void ***)(a1 + 32);
if ( !v3 )
{
v3 = *(void ***)a1;
*(_QWORD *)(a1 + 40) = *(_QWORD *)a1;
*(_QWORD *)(a1 + 32) = v3;
LABEL_6:
memcpy(*v3, a2, a3);
v4 = *(_QWORD *)(a1 + 32);
++*(_QWORD *)(a1 + 48);
v5 = 0;
v4 += 8LL;
*(_QWORD *)(a1 + 32) = v4;
if ( v4 >= *(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 32) = *(_QWORD *)a1;
return v5;
}
if ( v3 != *(void ***)(a1 + 40) )
goto LABEL_6;
fwrite("queue is full\n", 1uLL, 0xEuLL, _bss_start);
return (unsigned int)-3;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2, size_t a3)
{
void **v3; // rax
unsigned __int64 v4; // rax
unsigned int v5; // er8

if ( a1 && a2 )
{
if ( *(_QWORD *)(a1 + 16) != a3 )
return (unsigned int)-2;
v3 = *(void ***)(a1 + 32);
if ( !v3 )
{
v3 = *(void ***)a1;
*(_QWORD *)(a1 + 40) = *(_QWORD *)a1;
*(_QWORD *)(a1 + 32) = v3;
LABEL_6:
memcpy(*v3, a2, a3);
v4 = *(_QWORD *)(a1 + 32);
++*(_QWORD *)(a1 + 48);
v5 = 0;
v4 += 8LL;
*(_QWORD *)(a1 + 32) = v4;
if ( v4 >= *(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 32) = *(_QWORD *)a1;
return v5;
}
if ( v3 != *(void ***)(a1 + 40) )
goto LABEL_6;
fwrite("queue is full\n", 1uLL, 0xEuLL, _bss_start);
return (unsigned int)-3;
}
return 0xFFFFFFFFLL;
}

original_code:
int queue_push(queue_st * q, void * data, size_t size)
{
    void * p;
    if (!q || !data) return -1;
    if (size != q->queues) return -2;
    if (q->tail == ((void *)0)) {
        q->tail = q->head = q->queue;
    } else if (q->tail == q->head) {
        fprintf(stderr, "queue is full\n");
        return -3;
    }
    memcpy(*(q->tail), data, size);
    q->tail++;
    q->n++;
    if (q->tail >= q->queuet) {
        q->tail = q->queue;
    }
    return 0;
}

canonical_original_code:
int queue_push(struct queue_st *q, void *data, unsigned long size)
{
    void *p;
    if (!q || !data) return -1;
    if (size != q->queues) return -2;
    if (q->tail == ((void *)0)) {
        q->tail = q->head = q->queue;
    } else if (q->tail == q->head) {
        fprintf(stderr, "queue is full\n");
        return -3;
    }
    memcpy(*(q->tail), data, size);
    q->tail++;
    q->n++;
    if (q->tail >= q->queuet) {
        q->tail = q->queue;
    }
    return 0;
}

variable_types:
data
void *

variable_types:
size
unsigned long

variable_types:
p
void *

user_defined_types: struct queue_st { void **queue; void **queuet; unsigned long queues; unsigned long queuen; void **tail; void **head; unsigned long n; }


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

if ( a1 )
result = *(_QWORD *)(a1 + 48);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 48);
else
result = 0LL;
return result;
}

original_code:
size_t queue_len(queue_st *q)
{
    if (!q) return 0;
    return q->n;
}

canonical_original_code:
unsigned long queue_len(struct queue_st *q)
{
    if (!q) return 0;
    return q->n;
}

return_type: unsigned long