decompiled_code:
__int64 __fastcall queue_insert(int a1, __int64 a2)
{
char *v2; // r12
__int64 result; // rax
_QWORD *v4; // rax
char *v5; // rdx

v2 = (char *)qs;
if ( !qs )
_assert_fail("qs", "queue.c", 0x50u, "queue_insert");
result = 0LL;
if ( current <= a1 )
{
if ( max < a1 )
{
if ( MAXCOST <= a1 )
return result;
max = a1;
}
v4 = malloc(0x10uLL);
if ( v4 )
{
*v4 = a2;
v5 = &v2[8 * a1];
v4[1] = *(_QWORD *)v5;
*(_QWORD *)v5 = v4;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
char *v2; // r12
__int64 result; // rax
_QWORD *v4; // rax
char *v5; // rdx

v2 = (char *)qs;
if ( !qs )
_assert_fail("qs", "queue.c", 0x50u, "queue_insert");
result = 0LL;
if ( current <= a1 )
{
if ( max < a1 )
{
if ( MAXCOST <= a1 )
return result;
max = a1;
}
v4 = malloc(0x10uLL);
if ( v4 )
{
*v4 = a2;
v5 = &v2[8 * a1];
v4[1] = *(_QWORD *)v5;
*(_QWORD *)v5 = v4;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
_Bool queue_insert (int cost, void *val)
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  if (cost < current)
    return 0;
  if (cost > max)
    {
      if (cost >= MAXCOST)
 return 0;
      max = cost;
    }
  entry *e = (entry *) malloc (sizeof (entry));
  if (!e) return 0;
  e->value = val;
  e->next = qs [cost];
  qs [cost] = e;
  return 1;
}

canonical_original_code:
_Bool queue_insert(int cost, void *val)
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  if (cost < current)
    return 0;
  if (cost > max)
    {
      if (cost >= MAXCOST)
 return 0;
      max = cost;
    }
  struct _entry *e = (entry *) malloc (sizeof (entry));
  if (!e) return 0;
  e->value = val;
  e->next = qs [cost];
  qs [cost] = e;
  return 1;
}

variable_types: cost int

variable_types:
val
void *


repo: jukaiser/sscs

decompiled_code:
__int64 queue_grabfront()
{
int v0; // edx
__int64 v1; // rax
char v2; // r8
__int64 v3; // rbx
__int64 **v4; // rax
__int64 *v5; // rdi

if ( !qs )
_assert_fail("qs", "queue.c", 0x6Du, "queue_grabfront");
v0 = current;
if ( current > max )
return 0LL;
v1 = current;
v2 = 0;
while ( !*((_QWORD *)qs + v1) )
{
v0 = ++v1;
v2 = 1;
if ( max < (int)v1 )
{
current = v0;
return 0LL;
}
}
if ( v2 )
current = v0;
if ( max < (int)v1 )
return 0LL;
v4 = (__int64 **)((char *)qs + 8 * (int)v1);
v5 = *v4;
v3 = **v4;
*v4 = (__int64 *)(*v4)[1];
free(v5);
return v3;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // edx
__int64 v1; // rax
char v2; // r8
__int64 v3; // rbx
__int64 **v4; // rax
__int64 *v5; // rdi

if ( !qs )
_assert_fail("qs", "queue.c", 0x6Du, "queue_grabfront");
v0 = current;
if ( current > max )
return 0LL;
v1 = current;
v2 = 0;
while ( !*((_QWORD *)qs + v1) )
{
v0 = ++v1;
v2 = 1;
if ( max < (int)v1 )
{
current = v0;
return 0LL;
}
}
if ( v2 )
current = v0;
if ( max < (int)v1 )
return 0LL;
v4 = (__int64 **)((char *)qs + 8 * (int)v1);
v5 = *v4;
v3 = **v4;
*v4 = (__int64 *)(*v4)[1];
free(v5);
return v3;
}

original_code:
void *queue_grabfront (void)
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 109, __extension__ __PRETTY_FUNCTION__); }));
  while (current <= max && !qs [current])
     {
     current++;
     }
  if (current > max) return ((void *)0);
  entry *e = qs [current];
  void *v = e->value;
  qs [current] = e->next;
  free (e);
  return v;
}

canonical_original_code:
void *queue_grabfront()
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 109, __extension__ __PRETTY_FUNCTION__); }));
  while (current <= max && !qs [current])
     {
     current++;
     }
  if (current > max) return ((void *)0);
  struct _entry *e = qs [current];
  void *v = e->value;
  qs [current] = e->next;
  free (e);
  return v;
}

variable_types: struct _entry { void *value; struct _entry *next; } *

variable_types:
v
void *

return_type: void *


decompiled_code:
__int64 __fastcall parse_constant(const char *a1, char **a2)
{
char *v2; // r12
char v3; // bp
const unsigned __int16 **v4; // r15
__int64 v5; // rbx
int v6; // eax
const __int32_t *v7; // rdx
const char *v8; // rdi
char **v9; // rbx
__int64 result; // rax
char s2[67]; // [rsp+15h] [rbp-43h] BYREF

v2 = *a2;
v3 = **a2;
if ( v3 )
{
v4 = __ctype_b_loc();
v5 = 0LL;
do
{
v6 = v5;
if ( ((*v4)[v3] & 8) == 0 )
break;
if ( (int)v5 > 9 )
break;
v7 = *__ctype_toupper_loc();
*a2 = ++v2;
v6 = v5 + 1;
s2[v5] = v7[*(v2 - 1)];
v3 = *v2;
++v5;
}
while ( *v2 );
}
else
{
v6 = 0;
}
s2[v6] = 0;
if ( *v2 )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", a1, s2);
v8 = constants;
if ( constants )
{
v9 = &constants;
while ( strcmp(v8, s2) )
{
v9 += 2;
v8 = *v9;
if ( !*v9 )
goto LABEL_12;
}
result = *((unsigned int *)v9 + 2);
}
else
{
LABEL_12:
fprintf(stderr, "config: Variable '%s': constant %s unknown!\n", a1, s2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, char **a2)
{
char *v2; // r12
char v3; // bp
const unsigned __int16 **v4; // r15
__int64 v5; // rbx
int v6; // eax
const __int32_t *v7; // rdx
const char *v8; // rdi
char **v9; // rbx
__int64 result; // rax
char s2[67]; // [rsp+15h] [rbp-43h] BYREF

v2 = *a2;
v3 = **a2;
if ( v3 )
{
v4 = __ctype_b_loc();
v5 = 0LL;
do
{
v6 = v5;
if ( ((*v4)[v3] & 8) == 0 )
break;
if ( (int)v5 > 9 )
break;
v7 = *__ctype_toupper_loc();
*a2 = ++v2;
v6 = v5 + 1;
s2[v5] = v7[*(v2 - 1)];
v3 = *v2;
++v5;
}
while ( *v2 );
}
else
{
v6 = 0;
}
s2[v6] = 0;
if ( *v2 )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", a1, s2);
v8 = constants;
if ( constants )
{
v9 = &constants;
while ( strcmp(v8, s2) )
{
v9 += 2;
v8 = *v9;
if ( !*v9 )
goto LABEL_12;
}
result = *((unsigned int *)v9 + 2);
}
else
{
LABEL_12:
fprintf(stderr, "config: Variable '%s': constant %s unknown!\n", a1, s2);
result = 0LL;
}
return result;
}

original_code:
static int parse_constant (const char *var, const char **val)
{
  char buf [11];
  int i = 0;
  named_const *c;
  while (**val && ((*__ctype_b_loc ())[(int) ((**val))] & (unsigned short int) _ISalnum) && i < 10)
    buf [i++] = toupper (*((*val)++));
  buf [i] = '\0';
  if (**val)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", var, buf);
  for (c = constants; c->name; c++)
    if (strcmp (c->name, buf) == 0)
      return c->value;
  fprintf (stderr, "config: Variable '%s': constant %s unknown!\n", var, buf);
  return 0;
}

canonical_original_code:
static int parse_constant(char *var, char **val)
{
  char buf[11];
  int i = 0;
  struct named_const *c;
  while (**val && ((*__ctype_b_loc ())[(int) ((**val))] & (unsigned short) _ISalnum) && i < 10)
    buf [i++] = toupper (*((*val)++));
  buf [i] = '\0';
  if (**val)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", var, buf);
  for (c = constants; c->name; c++)
    if (strcmp (c->name, buf) == 0)
      return c->value;
  fprintf (stderr, "config: Variable '%s': constant %s unknown!\n", var, buf);
  return 0;
}

variable_types:
var
char *

variable_types:
val
char **

variable_types:
buf
char [11]

variable_types: i int

variable_types: struct named_const { char *name; int value; } *

return_type: int


decompiled_code:
unsigned int __fastcall handle_num(const char *a1, unsigned int *a2, char *a3)
{
char v3; // r12
unsigned int result; // eax
char *nptr; // [rsp+8h] [rbp-30h] BYREF
char *endptr; // [rsp+18h] [rbp-20h] BYREF

nptr = a3;
if ( (*a3 & 0xDF) == 80 )
{
nptr = a3 + 1;
}
else
{
v3 = *a3;
if ( ((*__ctype_b_loc())[v3] & 0x400) != 0 )
{
result = parse_constant(a1, &nptr);
*a2 = result;
return result;
}
}
result = strtol(nptr, &endptr, 0);
*a2 = result;
if ( *endptr )
result = fprintf(
stderr,
"config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n",
a1,
endptr,
result);
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func8(const char *a1, unsigned int *a2, char *a3)
{
char v3; // r12
unsigned int result; // eax
char *nptr; // [rsp+8h] [rbp-30h] BYREF
char *endptr; // [rsp+18h] [rbp-20h] BYREF

nptr = a3;
if ( (*a3 & 0xDF) == 80 )
{
nptr = a3 + 1;
}
else
{
v3 = *a3;
if ( ((*__ctype_b_loc())[v3] & 0x400) != 0 )
{
result = func7(a1, &nptr);
*a2 = result;
return result;
}
}
result = strtol(nptr, &endptr, 0);
*a2 = result;
if ( *endptr )
result = fprintf(
stderr,
"config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n",
a1,
endptr,
result);
return result;
}

original_code:
static void handle_num (const char *var, int *v_ptr, const char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short int) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
}

canonical_original_code:
static void handle_num(char *var, int *v_ptr, char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
}

variable_types:
val
char *

variable_types:
end
char *

return_type: void


decompiled_code:
__int64 __fastcall handle_bool(const char *a1, bool *a2, char *a3)
{
char v3; // bp
bool v4; // cl
__int64 result; // rax
char *nptr; // [rsp+8h] [rbp-30h] BYREF
char *endptr; // [rsp+18h] [rbp-20h] BYREF

nptr = a3;
if ( (*a3 & 0xDF) == 80 )
{
nptr = a3 + 1;
}
else
{
v3 = *a3;
if ( ((*__ctype_b_loc())[v3] & 0x400) != 0 )
{
result = parse_constant(a1, &nptr);
*a2 = (_DWORD)result != 0;
return result;
}
}
v4 = strtol(nptr, &endptr, 0) != 0;
*a2 = v4;
if ( !*endptr )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", a1, v4);
result = strtol(nptr, 0LL, 10);
*a2 = result != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, bool *a2, char *a3)
{
char v3; // bp
bool v4; // cl
__int64 result; // rax
char *nptr; // [rsp+8h] [rbp-30h] BYREF
char *endptr; // [rsp+18h] [rbp-20h] BYREF

nptr = a3;
if ( (*a3 & 0xDF) == 80 )
{
nptr = a3 + 1;
}
else
{
v3 = *a3;
if ( ((*__ctype_b_loc())[v3] & 0x400) != 0 )
{
result = func7(a1, &nptr);
*a2 = (_DWORD)result != 0;
return result;
}
}
v4 = strtol(nptr, &endptr, 0) != 0;
*a2 = v4;
if ( !*endptr )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", a1, v4);
result = strtol(nptr, 0LL, 10);
*a2 = result != 0;
return result;
}

original_code:
static void handle_bool (const char *var, _Bool *v_ptr, const char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short int) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (!*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", var, *v_ptr);
  *v_ptr = (strtol (val, ((void *)0), 10) != 0);
}

canonical_original_code:
static void handle_bool(char *var, _Bool *v_ptr, char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (!*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", var, *v_ptr);
  *v_ptr = (strtol (val, ((void *)0), 10) != 0);
}


decompiled_code:
int __fastcall handle_array(const char *a1, char **a2, int *a3, __int64 a4)
{
char *v6; // rbx
size_t v7; // rax
char *v8; // rax
char v9; // bp
const unsigned __int16 **v10; // r14
int v11; // ecx
char *v12; // rdx
int v13; // eax
int v14; // er14
_BYTE *v15; // rax
int v16; // ebp
char *v17; // rax
int v18; // edi
int v19; // esi
char *v21[2]; // [rsp+8h] [rbp-50h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v6 = (char *)a4;
v21[0] = (char *)a4;
if ( *(_BYTE *)a4 == 91 )
{
v14 = strtol((const char *)(a4 + 1), v21, 0);
if ( v14 > 0 )
{
v15 = skip_ws(v21[0]);
v21[0] = v15;
if ( *v15 != 37 )
goto LABEL_10;
v16 = strtol(v15 + 1, v21, 0);
if ( v14 < v16 )
{
v15 = skip_ws(v21[0]);
v21[0] = v15;
if ( *v15 == 93 )
{
if ( v15[1] )
fprintf(stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", a1, v15 + 1);
v17 = (char *)calloc(v16, 4uLL);
*a2 = v17;
if ( !v17 )
{
perror("config::handle_array() - calloc");
exit(1);
}
v18 = v14;
v19 = 1;
do
{
v8 = *a2;
*(_DWORD *)&(*a2)[4 * (v14 % v16)] = v19++;
v14 += v18;
}
while ( v16 >= v19 );
*a3 = v16;
return (int)v8;
}
LABEL_10:
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", a1, v15);
return (int)v8;
}
}
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", a1, v21[0]);
return (int)v8;
}
v7 = strlen((const char *)a4);
v8 = (char *)calloc((v7 >> 1) + 1, 4uLL);
*a2 = v8;
if ( !v8 )
{
perror("config::handle_array() - calloc");
exit(1);
}
*a3 = 0;
endptr = v6;
v9 = *v6;
if ( *v6 )
{
v10 = __ctype_b_loc();
while ( ((*v10)[v9] & 0x800) != 0 )
{
v11 = strtol(v6, &endptr, 0);
v12 = *a2;
v13 = (*a3)++;
*(_DWORD *)&v12[4 * v13] = v11;
v8 = skip_ws(endptr);
v6 = v8;
endptr = v8;
v9 = *v8;
if ( !*v8 )
return (int)v8;
}
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", a1, v6, *a2);
}
return (int)v8;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, char **a2, int *a3, __int64 a4)
{
char *v6; // rbx
size_t v7; // rax
char *v8; // rax
char v9; // bp
const unsigned __int16 **v10; // r14
int v11; // ecx
char *v12; // rdx
int v13; // eax
int v14; // er14
_BYTE *v15; // rax
int v16; // ebp
char *v17; // rax
int v18; // edi
int v19; // esi
char *v21[2]; // [rsp+8h] [rbp-50h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v6 = (char *)a4;
v21[0] = (char *)a4;
if ( *(_BYTE *)a4 == 91 )
{
v14 = strtol((const char *)(a4 + 1), v21, 0);
if ( v14 > 0 )
{
v15 = skip_ws(v21[0]);
v21[0] = v15;
if ( *v15 != 37 )
goto LABEL_10;
v16 = strtol(v15 + 1, v21, 0);
if ( v14 < v16 )
{
v15 = skip_ws(v21[0]);
v21[0] = v15;
if ( *v15 == 93 )
{
if ( v15[1] )
fprintf(stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", a1, v15 + 1);
v17 = (char *)calloc(v16, 4uLL);
*a2 = v17;
if ( !v17 )
{
perror("config::handle_array() - calloc");
exit(1);
}
v18 = v14;
v19 = 1;
do
{
v8 = *a2;
*(_DWORD *)&(*a2)[4 * (v14 % v16)] = v19++;
v14 += v18;
}
while ( v16 >= v19 );
*a3 = v16;
return (int)v8;
}
LABEL_10:
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", a1, v15);
return (int)v8;
}
}
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", a1, v21[0]);
return (int)v8;
}
v7 = strlen((const char *)a4);
v8 = (char *)calloc((v7 >> 1) + 1, 4uLL);
*a2 = v8;
if ( !v8 )
{
perror("config::handle_array() - calloc");
exit(1);
}
*a3 = 0;
endptr = v6;
v9 = *v6;
if ( *v6 )
{
v10 = __ctype_b_loc();
while ( ((*v10)[v9] & 0x800) != 0 )
{
v11 = strtol(v6, &endptr, 0);
v12 = *a2;
v13 = (*a3)++;
*(_DWORD *)&v12[4 * v13] = v11;
v8 = skip_ws(endptr);
v6 = v8;
endptr = v8;
v9 = *v8;
if ( !*v8 )
return (int)v8;
}
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", a1, v6, *a2);
}
return (int)v8;
}

original_code:
static void handle_array (const char *var, int **v_ptr, int *n_ptr, char *val)
{
  char *end;
  if (*val == '[')
    {
      int step, nLanes, k;
      step = strtol (val+1, &val, 0);
      if (step <= 0)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != '%')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      nLanes = strtol (val+1, &val, 0);
      if (nLanes <= step)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != ']')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      if (val [1])
 fprintf (stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", var, val+1);
      *v_ptr = calloc (nLanes, sizeof (int));
      if (!*v_ptr)
 {
   perror ("config::handle_array() - calloc");
   exit (1);
 }
      for (k = 1; k <= nLanes; k++)
 (*v_ptr) [(k*step)%nLanes] = k;
      *n_ptr = nLanes;
      return;
    }
  *v_ptr = calloc (1+strlen (val)/2, sizeof (int));
  if (!*v_ptr)
    {
      perror ("config::handle_array() - calloc");
      exit (1);
    }
  *n_ptr = 0;
  end = val;
  while (*end)
    {
      if (!((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISdigit))
 {
   fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
   return;
 }
      (*v_ptr) [(*n_ptr)++] = strtol (end, &end, 0);
      end = skip_ws (end);
    }
}

canonical_original_code:
static void handle_array(char *var, int **v_ptr, int *n_ptr, char *val)
{
  char *end;
  if (*val == '[')
    {
      int step; int nLanes; int k;
      step = strtol (val+1, &val, 0);
      if (step <= 0)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != '%')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      nLanes = strtol (val+1, &val, 0);
      if (nLanes <= step)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != ']')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      if (val [1])
 fprintf (stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", var, val+1);
      *v_ptr = calloc (nLanes, sizeof (int));
      if (!*v_ptr)
 {
   perror ("config::handle_array() - calloc");
   exit (1);
 }
      for (k = 1; k <= nLanes; k++)
 (*v_ptr) [(k*step)%nLanes] = k;
      *n_ptr = nLanes;
      return;
    }
  *v_ptr = calloc (1+strlen (val)/2, sizeof (int));
  if (!*v_ptr)
    {
      perror ("config::handle_array() - calloc");
      exit (1);
    }
  *n_ptr = 0;
  end = val;
  while (*end)
    {
      if (!((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISdigit))
 {
   fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
   return;
 }
      (*v_ptr) [(*n_ptr)++] = strtol (end, &end, 0);
      end = skip_ws (end);
    }
}

variable_types: step int

variable_types: nLanes int

variable_types: k int


repo: jukarimov/gtfinder

decompiled_code:
__int64 shutdown_file_chooser()
{
gtk_widget_destroy(window);
return gtk_main_quit();
}

canonical_decompiled_code:
__int64 func0()
{
gtk_widget_destroy(window);
return gtk_main_quit();
}

original_code:
void shutdown_file_chooser()
{
    gtk_widget_destroy(window);
    gtk_main_quit();
    return;
}


shutdown

decompiled_code:
__int64 shutdown()
{
gtk_widget_destroy(window);
return gtk_main_quit();
}

original_code:
void shutdown()
{
 gtk_widget_destroy(window);
 gtk_main_quit();
 return;
}


main

canonical_name: main

repo: jules-vanneste/PJE

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v4; // ax
unsigned __int16 v5; // bx
int v6; // eax
int v7; // ebp
char *v8; // r13
unsigned __int8 v9; // r12
unsigned __int16 v10; // ax
int v11; // [rsp+8h] [rbp-630h]
int v12; // [rsp+Ch] [rbp-62Ch]
__int64 v13; // [rsp+18h] [rbp-620h] BYREF
char v14[1560]; // [rsp+20h] [rbp-618h] BYREF

init_signals(argc, argv, envp);
v12 = init_terminal(&hContext, &hCard);
if ( v12 )
return -1;
if ( (unsigned int)open_tunnel(&tunnel) != -1 )
{
puts("SCARD host adapter is now ready to accept connections");
while ( 1 )
{
v6 = utun_read(&tunnel, v14, 1500LL);
v7 = v6;
if ( v6 < 0 )
break;
v13 = 0LL;
if ( v6 )
{
v11 = utun_select(&tunnel);
printf("send %d bytes\n", (unsigned int)v7);
v8 = v14;
while ( 1 )
{
v9 = -1;
if ( v7 <= 255 )
v9 = v7;
v10 = send_apdu(hContext, hCard, v8, v9, &v13, (unsigned int)v11);
v5 = v10;
if ( (unsigned __int8)v10 <= 0x8Fu )
break;
v8 += v9;
v7 -= v9;
if ( v7 <= 0 )
goto LABEL_7;
}
printf("Error: %02x%02x\n", (unsigned __int8)v10, HIBYTE(v10));
LABEL_7:
if ( v11 <= 0 )
{
while ( HIBYTE(v5) )
{
v4 = recv_apdu(hContext, hCard, &tunnel, v5, &v13);
v5 = v4;
if ( (unsigned __int8)v4 <= 0x8Fu )
{
printf("Error: %02x%02x\n", (unsigned __int8)v4, HIBYTE(v4));
break;
}
}
if ( v13 )
check_terminal_status(hContext, hCard);
}
memset(v14, 0, 0x5E0uLL);
}
}
}
close_tunnel(&tunnel);
release_terminal(&hContext, &hCard);
return v12;
}

original_code:
int main(int argc, char *argv[]) {
 init_signals();
 if(init_terminal(&hContext,&hCard))
  return -1;
    else {
  if(open_tunnel(&tunnel) !=-1) {
   int output_len;
   raw_packet packet;
   short sw = 0x9000 ;
   printf("SCARD host adapter is now ready to accept connections\n");
   while((output_len = utun_read(&tunnel, packet.raw, 1500)) >= 0) {
    LONG card_status = 0;
    int select_ret;
    BYTE *packet_ptr;
    if(output_len == 0)
     continue;
    select_ret = utun_select(&tunnel);
    printf("send %d bytes\n",output_len);
    packet_ptr = packet.raw;
    do {
     unsigned char curr_len = output_len > 255 ? 255 : output_len;
     sw = send_apdu(hContext,hCard,packet_ptr,curr_len,&card_status,select_ret);
     if(((sw) & 0xFF) < 0x90) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
     packet_ptr += curr_len;
     output_len -= curr_len;
    } while(output_len > 0);
    if(select_ret>0) {
     memset(&packet,0,sizeof(raw_packet));
     continue;
    }
    while((((sw)>>8) & 0xFF)) {
     sw = recv_apdu(hContext,hCard,&tunnel,sw,&card_status);
     if(((sw) & 0xFF) < 0x90 ) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
    }
    if(card_status) {
     check_terminal_status(hContext,hCard);
    }
    memset(&packet,0,sizeof(raw_packet));
   }
  }
 }
 close_tunnel(&tunnel);
 release_terminal(&hContext,&hCard);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 init_signals();
 if(init_terminal(&hContext,&hCard))
  return -1;
    else {
  if(open_tunnel(&tunnel) !=-1) {
   int output_len;
   union raw_packet packet;
   short sw = 0x9000;
   printf("SCARD host adapter is now ready to accept connections\n");
   while((output_len = utun_read(&tunnel, packet.raw, 1500)) >= 0) {
    long card_status = 0;
    int select_ret;
    unsigned char *packet_ptr;
    if(output_len == 0)
     continue;
    select_ret = utun_select(&tunnel);
    printf("send %d bytes\n",output_len);
    packet_ptr = packet.raw;
    do {
     unsigned char curr_len = output_len > 255 ? 255 : output_len;
     sw = send_apdu(hContext,hCard,packet_ptr,curr_len,&card_status,select_ret);
     if(((sw) & 0xFF) < 0x90) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
     packet_ptr += curr_len;
     output_len -= curr_len;
    } while(output_len > 0);
    if(select_ret>0) {
     memset(&packet,0,sizeof(raw_packet));
     continue;
    }
    while((((sw)>>8) & 0xFF)) {
     sw = recv_apdu(hContext,hCard,&tunnel,sw,&card_status);
     if(((sw) & 0xFF) < 0x90 ) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
    }
    if(card_status) {
     check_terminal_status(hContext,hCard);
    }
    memset(&packet,0,sizeof(raw_packet));
   }
  }
 }
 close_tunnel(&tunnel);
 release_terminal(&hContext,&hCard);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: union raw_packet { struct { struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } ip; } fmt; unsigned char raw[-1]; }

variable_types: sw short

user_defined_types: union raw_packet { struct { struct iphdr ip; } fmt; unsigned char raw[-1]; }


decompiled_code:
__int64 __fastcall utun_open(unsigned int *a1, const char *a2, const char *a3, unsigned __int64 a4)
{
int v6; // eax
unsigned int v7; // ebx
char s[256]; // [rsp+0h] [rbp-158h] BYREF
__int64 v10[11]; // [rsp+100h] [rbp-58h] BYREF

v6 = open("/dev/net/tun", 2);
if ( v6 < 0 )
{
printf("Unable to open %s\n", "/dev/net/tun");
v7 = -1;
}
else
{
v7 = v6;
v10[0] = 0LL;
v10[1] = 0LL;
v10[2] = 4097LL;
v10[3] = 0LL;
v10[4] = 0LL;
if ( ioctl(v6, 0x400454CAuLL, v10) < 0 )
{
close(v7);
v7 = -1;
}
else
{
if ( a4 <= 0x64 )
a4 = 1500LL;
snprintf(s, 0x100uLL, "ifconfig %s %s pointopoint %s mtu %d", (const char *)v10, a2, a3, a4);
system(s);
*a1 = v7;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, const char *a2, const char *a3, unsigned __int64 a4)
{
int v6; // eax
unsigned int v7; // ebx
char s[256]; // [rsp+0h] [rbp-158h] BYREF
__int64 v10[11]; // [rsp+100h] [rbp-58h] BYREF

v6 = open("/dev/net/tun", 2);
if ( v6 < 0 )
{
printf("Unable to open %s\n", "/dev/net/tun");
v7 = -1;
}
else
{
v7 = v6;
v10[0] = 0LL;
v10[1] = 0LL;
v10[2] = 4097LL;
v10[3] = 0LL;
v10[4] = 0LL;
if ( ioctl(v6, 0x400454CAuLL, v10) < 0 )
{
close(v7);
v7 = -1;
}
else
{
if ( a4 <= 0x64 )
a4 = 1500LL;
snprintf(s, 0x100uLL, "ifconfig %s %s pointopoint %s mtu %d", (const char *)v10, a2, a3, a4);
system(s);
*a1 = v7;
}
}
return v7;
}

original_code:
int utun_open (utun *t, char *ip_src, char *ip_dest, unsigned long mtu)
{
    struct ifreq ifr;
    int fd, err;
    char buf[256] ;
    if( (fd = open("/dev/net/tun", 02)) < 0 )
    {
        printf("Unable to open %s\n","/dev/net/tun");
        return -1;
    }
    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_ifru.ifru_flags = 0x0001|0x1000 ;
    if( (err = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr)) < 0 )
    {
        close(fd);
        return -1;
    }
    snprintf(buf,256, "ifconfig %s %s pointopoint %s mtu %d", ifr.ifr_ifrn.ifrn_name, ip_src, ip_dest, mtu>100?mtu:1500);
    system(buf);
    t->fd= fd;
    return fd;
}

canonical_original_code:
int utun_open(struct tun_t *t, char *ip_src, char *ip_dest, unsigned long mtu)
{
    struct ifreq ifr;
    int fd; int err;
    char buf[256];
    if( (fd = open("/dev/net/tun", 02)) < 0 )
    {
        printf("Unable to open %s\n","/dev/net/tun");
        return -1;
    }
    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_ifru.ifru_flags = 0x0001|0x1000 ;
    if( (err = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr)) < 0 )
    {
        close(fd);
        return -1;
    }
    snprintf(buf,256, "ifconfig %s %s pointopoint %s mtu %d", ifr.ifr_ifrn.ifrn_name, ip_src, ip_dest, mtu>100?mtu:1500);
    system(buf);
    t->fd= fd;
    return fd;
}

variable_types:
t
struct tun_t { int fd; } *

variable_types:
mtu
unsigned long

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

variable_types: fd int

variable_types: err int

variable_types:
buf
char [256]

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
ssize_t __fastcall utun_write(int *a1, const void *a2, int a3)
{
return write(*a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func1(int *a1, const void *a2, int a3)
{
return write(*a1, a2, a3);
}

original_code:
int utun_write (utun *t, unsigned char *buf, int len)
{
    return write(t->fd,buf,len);
}

canonical_original_code:
int utun_write(struct tun_t *t, unsigned char *buf, int len)
{
    return write(t->fd,buf,len);
}

variable_types:
buf
unsigned char *

variable_types: len int


decompiled_code:
ssize_t __fastcall utun_read(int *a1, void *a2, int a3)
{
return read(*a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int *a1, void *a2, int a3)
{
return read(*a1, a2, a3);
}

original_code:
int utun_read (utun *t, unsigned char *buf, int len)
{
    return read(t->fd,buf,len);
}

canonical_original_code:
int utun_read(struct tun_t *t, unsigned char *buf, int len)
{
    return read(t->fd,buf,len);
}


decompiled_code:
int __fastcall utun_close(int *a1)
{
int result; // eax

result = close(*a1);
*a1 = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func3(int *a1)
{
int result; // eax

result = close(*a1);
*a1 = -1;
return result;
}

original_code:
void utun_close (utun *t)
{
    close(t->fd);
    t->fd= -1;
}

canonical_original_code:
void utun_close(struct tun_t *t)
{
    close(t->fd);
    t->fd= -1;
}


decompiled_code:
int __fastcall utun_select(int *a1)
{
int v1; // edi
fd_set v3; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&v3, 0, sizeof(v3));
v1 = *a1;
v3.fds_bits[v1 / 64] |= 1LL << (v1 % 64);
return select(v1 + 1, &v3, 0LL, 0LL, &timeout);
}

canonical_decompiled_code:
int __fastcall func4(int *a1)
{
int v1; // edi
fd_set v3; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&v3, 0, sizeof(v3));
v1 = *a1;
v3.fds_bits[v1 / 64] |= 1LL << (v1 % 64);
return select(v1 + 1, &v3, 0LL, 0LL, &timeout);
}

original_code:
int utun_select(utun *t)
{
    struct timeval tv;
    fd_set fd_readset;
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_readset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fd_readset)->__fds_bits)[((t->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((t->fd) % (8 * (int) sizeof (__fd_mask)))))));
    return select(t->fd + 1, &fd_readset, ((void *)0), ((void *)0), &tv);
}

canonical_original_code:
int utun_select(struct tun_t *t)
{
    struct timeval tv;
    struct fd_set fd_readset;
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_readset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fd_readset)->__fds_bits)[((t->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((t->fd) % (8 * (int) sizeof (__fd_mask)))))));
    return select(t->fd + 1, &fd_readset, ((void *)0), ((void *)0), &tv);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall send_apdu(__int64 a1, __int64 a2, const void *a3, unsigned int a4, __int64 *a5, char a6)
{
size_t v9; // r13
_BYTE *v10; // rbx
__int64 v11; // rax
unsigned int v12; // ebx
const char *v13; // rax
__int64 v16; // [rsp+18h] [rbp-620h] BYREF
char v17[1560]; // [rsp+20h] [rbp-618h] BYREF

v9 = (int)(a4 + 5);
v16 = 1503LL;
v10 = malloc(v9);
*v10 = 0x80;
v10[1] = 1;
v10[2] = 0;
v10[3] = a6;
v10[4] = a4;
memcpy(v10 + 5, a3, (int)a4);
v11 = SCardTransmit(a2, &g_rgSCardT0Pci, v10, v9, 0LL, v17, &v16);
*a5 = v11;
v12 = *(unsigned __int16 *)((char *)&v16 + v16 + 6);
v13 = (const char *)pcsc_stringify_error(v11);
printf(" %d bytes. %02x%02x. %s \n", a4, (unsigned __int8)v12, BYTE1(v12), v13);
if ( *a5 )
{
v12 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v12 = 144;
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, const void *a3, unsigned int a4, __int64 *a5, char a6)
{
size_t v9; // r13
_BYTE *v10; // rbx
__int64 v11; // rax
unsigned int v12; // ebx
const char *v13; // rax
__int64 v16; // [rsp+18h] [rbp-620h] BYREF
char v17[1560]; // [rsp+20h] [rbp-618h] BYREF

v9 = (int)(a4 + 5);
v16 = 1503LL;
v10 = malloc(v9);
*v10 = 0x80;
v10[1] = 1;
v10[2] = 0;
v10[3] = a6;
v10[4] = a4;
memcpy(v10 + 5, a3, (int)a4);
v11 = SCardTransmit(a2, &g_rgSCardT0Pci, v10, v9, 0LL, v17, &v16);
*a5 = v11;
v12 = *(unsigned __int16 *)((char *)&v16 + v16 + 6);
v13 = (const char *)pcsc_stringify_error(v11);
printf(" %d bytes. %02x%02x. %s \n", a4, (unsigned __int8)v12, BYTE1(v12), v13);
if ( *a5 )
{
v12 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v12 = 144;
}
return v12;
}

original_code:
short send_apdu(SCARDCONTEXT hContext,SCARDHANDLE hCard,char *paquet,int len,LONG *rv,int P2) {
 short sw;
 BYTE pbRecvBuffer[1500 +1+2];
 BYTE *pbSendBuffer;
 DWORD dwSendLength = len + 5;
 DWORD dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer = malloc(dwSendLength);
 pbSendBuffer[0] = 0x80;
 pbSendBuffer[1] = 0x01;
 pbSendBuffer[2] = 0x00;
 pbSendBuffer[3] = P2;
 pbSendBuffer[4] = len;
 memcpy(pbSendBuffer+5,paquet,len);
 *rv = SCardTransmit(hCard,
  (&g_rgSCardT0Pci),
  pbSendBuffer,
  dwSendLength,
  ((void *)0),
  pbRecvBuffer,
  &dwRecvLength);
 sw = *((short*)(pbRecvBuffer+dwRecvLength-2));
 printf("   %d bytes. %02x%02x. %s \n", len, ((sw) & 0xFF),(((sw)>>8) & 0xFF), pcsc_stringify_error(*rv));
 if(*rv) {
  if(check_terminal_status(hContext,hCard)==-1)
   return -1;
  else
   return 0x90;
 }
 return sw;
}

canonical_original_code:
short send_apdu(long hContext, long hCard, char *paquet, int len, long *rv, int P2) {
 short sw;
 unsigned char pbRecvBuffer[-1];
 unsigned char *pbSendBuffer;
 unsigned long dwSendLength = len + 5;
 unsigned long dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer = malloc(dwSendLength);
 pbSendBuffer[0] = 0x80;
 pbSendBuffer[1] = 0x01;
 pbSendBuffer[2] = 0x00;
 pbSendBuffer[3] = P2;
 pbSendBuffer[4] = len;
 memcpy(pbSendBuffer+5,paquet,len);
 *rv = SCardTransmit(hCard,
  (&g_rgSCardT0Pci),
  pbSendBuffer,
  dwSendLength,
  ((void *)0),
  pbRecvBuffer,
  &dwRecvLength);
 sw = *((short *)(pbRecvBuffer+dwRecvLength-2));
 printf("   %d bytes. %02x%02x. %s \n", len, ((sw) & 0xFF),(((sw)>>8) & 0xFF), pcsc_stringify_error(*rv));
 if(*rv) {
  if(check_terminal_status(hContext,hCard)==-1)
   return -1;
  else
   return 0x90;
 }
 return sw;
}

variable_types: hContext long

variable_types: hCard long

variable_types:
paquet
char *

variable_types:
rv
long *

variable_types:
pbRecvBuffer
unsigned char [-1]

variable_types:
pbSendBuffer
unsigned char *

variable_types:
dwSendLength
unsigned long

variable_types:
dwRecvLength
unsigned long

return_type: short


decompiled_code:
__int64 __fastcall recv_apdu(__int64 a1, __int64 a2, __int64 a3, __int64 a4, _QWORD *a5)
{
char v5; // ch
unsigned __int16 v7; // bx
int v8; // ebp
char *v9; // r12
const char *v10; // rax
unsigned int v11; // er15
__int64 v14; // [rsp+10h] [rbp-638h] BYREF
char v15[5]; // [rsp+1Bh] [rbp-62Dh] BYREF
char v16[1504]; // [rsp+20h] [rbp-628h] BYREF
char v17[72]; // [rsp+600h] [rbp-48h] BYREF

HIBYTE(v7) = v5;
v14 = 1503LL;
v15[0] = 0x80;
v15[1] = 2;
v15[2] = 0;
v15[3] = 0;
v8 = -1;
v9 = v16;
while ( 1 )
{
v15[4] = HIBYTE(v7);
*a5 = SCardTransmit(a2, &g_rgSCardT0Pci, v15, 5LL, v17, v9, &v14);
v7 = *(_WORD *)&v9[v14 - 2];
v11 = v7;
if ( v8 == -1 )
{
v8 = (unsigned __int8)v9[3] + ((unsigned __int8)v9[2] << 8);
printf("recv %d bytes\n", (unsigned int)v8);
}
v10 = (const char *)pcsc_stringify_error(*a5);
printf(" %d bytes. %02x%02x. %s\n", v14 - 2, (unsigned __int8)v7, HIBYTE(v7), v10);
if ( *a5 )
break;
v8 = v8 - v14 + 2;
v9 = &v9[v14 - 2];
if ( v8 <= 0 )
{
utun_write(a3, v16, v9 - v16);
return v11;
}
}
v11 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v11 = 144;
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, _QWORD *a5)
{
char v5; // ch
unsigned __int16 v7; // bx
int v8; // ebp
char *v9; // r12
const char *v10; // rax
unsigned int v11; // er15
__int64 v14; // [rsp+10h] [rbp-638h] BYREF
char v15[5]; // [rsp+1Bh] [rbp-62Dh] BYREF
char v16[1504]; // [rsp+20h] [rbp-628h] BYREF
char v17[72]; // [rsp+600h] [rbp-48h] BYREF

HIBYTE(v7) = v5;
v14 = 1503LL;
v15[0] = 0x80;
v15[1] = 2;
v15[2] = 0;
v15[3] = 0;
v8 = -1;
v9 = v16;
while ( 1 )
{
v15[4] = HIBYTE(v7);
*a5 = SCardTransmit(a2, &g_rgSCardT0Pci, v15, 5LL, v17, v9, &v14);
v7 = *(_WORD *)&v9[v14 - 2];
v11 = v7;
if ( v8 == -1 )
{
v8 = (unsigned __int8)v9[3] + ((unsigned __int8)v9[2] << 8);
printf("recv %d bytes\n", (unsigned int)v8);
}
v10 = (const char *)pcsc_stringify_error(*a5);
printf(" %d bytes. %02x%02x. %s\n", v14 - 2, (unsigned __int8)v7, HIBYTE(v7), v10);
if ( *a5 )
break;
v8 = v8 - v14 + 2;
v9 = &v9[v14 - 2];
if ( v8 <= 0 )
{
utun_write(a3, v16, v9 - v16);
return v11;
}
}
v11 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v11 = 144;
return v11;
}

original_code:
short recv_apdu(SCARDCONTEXT hContext,SCARDHANDLE hCard,utun *t,unsigned short sw,LONG *rv) {
 SCARD_IO_REQUEST pioRecvPci;
 BYTE pbRecvBuffer[1500 +1+2];
 BYTE pbSendBuffer[5];
 BYTE *recvBuffPtr = pbRecvBuffer;
 int packet_length = -1;
 DWORD dwSendLength = 5;
 DWORD dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer[0]= 0x80;
 pbSendBuffer[1]= 0x02;
 pbSendBuffer[2]= 0x00;
 pbSendBuffer[3]= 0x00;
 pbSendBuffer[4]= (((sw)>>8) & 0xFF);
 do {
  pbSendBuffer[4]= (((sw)>>8) & 0xFF);
  *rv = SCardTransmit(hCard, (&g_rgSCardT0Pci),
   pbSendBuffer,
   dwSendLength,
   &pioRecvPci,
   recvBuffPtr,
   &dwRecvLength);
  sw = *((short*)(recvBuffPtr+dwRecvLength-2));
  if(packet_length == -1) {
   packet_length = (recvBuffPtr[2] << 8) + recvBuffPtr[3];
   printf("recv %d bytes\n",packet_length);
  }
  printf("   %d bytes. %02x%02x. %s\n",dwRecvLength-2,((sw) & 0xFF),(((sw)>>8) & 0xFF),pcsc_stringify_error(*rv));
  if(*rv) {
   if(check_terminal_status(hContext,hCard)==-1)
    return -1;
   else
    return 0x90;
  }
  packet_length -= dwRecvLength -2;
  recvBuffPtr += dwRecvLength-2;
 } while(packet_length > 0);
 utun_write(t, pbRecvBuffer,recvBuffPtr-pbRecvBuffer);
 return sw;
}

canonical_original_code:
short recv_apdu(long hContext, long hCard, struct tun_t *t, unsigned short sw, long *rv) {
 struct _SCARD_IO_REQUEST pioRecvPci;
 unsigned char pbRecvBuffer[-1];
 unsigned char pbSendBuffer[5];
 unsigned char *recvBuffPtr = pbRecvBuffer;
 int packet_length = -1;
 unsigned long dwSendLength = 5;
 unsigned long dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer[0]= 0x80;
 pbSendBuffer[1]= 0x02;
 pbSendBuffer[2]= 0x00;
 pbSendBuffer[3]= 0x00;
 pbSendBuffer[4]= (((sw)>>8) & 0xFF);
 do {
  pbSendBuffer[4]= (((sw)>>8) & 0xFF);
  *rv = SCardTransmit(hCard, (&g_rgSCardT0Pci),
   pbSendBuffer,
   dwSendLength,
   &pioRecvPci,
   recvBuffPtr,
   &dwRecvLength);
  sw = *((short *)(recvBuffPtr+dwRecvLength-2));
  if(packet_length == -1) {
   packet_length = (recvBuffPtr[2] << 8) + recvBuffPtr[3];
   printf("recv %d bytes\n",packet_length);
  }
  printf("   %d bytes. %02x%02x. %s\n",dwRecvLength-2,((sw) & 0xFF),(((sw)>>8) & 0xFF),pcsc_stringify_error(*rv));
  if(*rv) {
   if(check_terminal_status(hContext,hCard)==-1)
    return -1;
   else
    return 0x90;
  }
  packet_length -= dwRecvLength -2;
  recvBuffPtr += dwRecvLength-2;
 } while(packet_length > 0);
 utun_write(t, pbRecvBuffer,recvBuffPtr-pbRecvBuffer);
 return sw;
}

variable_types:
t
struct tun_t { int fd; } *

variable_types:
sw
unsigned short

variable_types: struct _SCARD_IO_REQUEST { unsigned long dwProtocol; unsigned long cbPciLength; }

variable_types:
pbSendBuffer
unsigned char [5]

variable_types:
recvBuffPtr
unsigned char *


decompiled_code:
__int64 __fastcall init_terminal(_QWORD *a1, _QWORD *a2)
{
void *v2; // r12
__int64 v3; // rax
__int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // rbx
__int64 v7; // rax
__int64 v8; // rax
unsigned int v9; // ebx
unsigned __int64 i; // rbx
__int64 result; // rax
unsigned int v12; // ebx
const char *v13; // rax
const char *v14; // rax
const char *v15; // rax
const char *v16; // rax
char v17[40]; // [rsp+0h] [rbp-88h] BYREF
char v18[8]; // [rsp+28h] [rbp-60h] BYREF
char v19[8]; // [rsp+30h] [rbp-58h] BYREF
char v20[8]; // [rsp+38h] [rbp-50h] BYREF
unsigned __int64 v21; // [rsp+40h] [rbp-48h] BYREF
size_t size[8]; // [rsp+48h] [rbp-40h] BYREF

SCardEstablishContext(2LL, 0LL, 0LL, a1);
SCardListReaders(*a1, 0LL, 0LL, size);
v2 = malloc(size[0]);
v3 = SCardListReaders(*a1, 0LL, v2, size);
if ( v3 )
{
v12 = v3;
v13 = (const char *)pcsc_stringify_error(v3);
printf("ListReader error: %s\n", v13);
free(v2);
result = v12;
}
else
{
printf("Reader=%s\n", (const char *)v2);
v4 = SCardEstablishContext(2LL, 0LL, 0LL, a1);
v5 = v4;
if ( v4 )
{
v14 = (const char *)pcsc_stringify_error(v4);
printf("Connect to reader error: %s\n", v14);
free(v2);
result = v5;
}
else
{
v6 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v20);
if ( v6 == 2148532236LL || v6 == 2148532329LL )
{
printf("Please insert a card in terminal \"%s\"\n", (const char *)v2);
do
{
do
{
usleep(0x64u);
v7 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v20);
v6 = v7;
}
while ( v7 == 2148532236LL );
}
while ( v7 == 2148532329LL );
}
if ( v6 )
{
v15 = (const char *)pcsc_stringify_error(v6);
printf("Connect to card error: %s : err=%X\n", v15, v6);
free(v2);
result = (unsigned int)v6;
}
else
{
v21 = 33LL;
v8 = SCardStatus(*a2, 0LL, v18, v19, v20, v17, &v21);
v9 = v8;
if ( v8 )
{
v16 = (const char *)pcsc_stringify_error(v8);
printf("Reading ATR error: %s\n", v16);
free(v2);
result = v9;
}
else
{
printf("Reading ATR: ");
if ( v21 )
{
for ( i = 0LL; i < v21; ++i )
printf("%.2X ", (unsigned __int8)v17[i]);
}
putchar(10);
free(v2);
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
void *v2; // r12
__int64 v3; // rax
__int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // rbx
__int64 v7; // rax
__int64 v8; // rax
unsigned int v9; // ebx
unsigned __int64 i; // rbx
__int64 result; // rax
unsigned int v12; // ebx
const char *v13; // rax
const char *v14; // rax
const char *v15; // rax
const char *v16; // rax
char v17[40]; // [rsp+0h] [rbp-88h] BYREF
char v18[8]; // [rsp+28h] [rbp-60h] BYREF
char v19[8]; // [rsp+30h] [rbp-58h] BYREF
char v20[8]; // [rsp+38h] [rbp-50h] BYREF
unsigned __int64 v21; // [rsp+40h] [rbp-48h] BYREF
size_t size[8]; // [rsp+48h] [rbp-40h] BYREF

SCardEstablishContext(2LL, 0LL, 0LL, a1);
SCardListReaders(*a1, 0LL, 0LL, size);
v2 = malloc(size[0]);
v3 = SCardListReaders(*a1, 0LL, v2, size);
if ( v3 )
{
v12 = v3;
v13 = (const char *)pcsc_stringify_error(v3);
printf("ListReader error: %s\n", v13);
free(v2);
result = v12;
}
else
{
printf("Reader=%s\n", (const char *)v2);
v4 = SCardEstablishContext(2LL, 0LL, 0LL, a1);
v5 = v4;
if ( v4 )
{
v14 = (const char *)pcsc_stringify_error(v4);
printf("Connect to reader error: %s\n", v14);
free(v2);
result = v5;
}
else
{
v6 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v20);
if ( v6 == 2148532236LL || v6 == 2148532329LL )
{
printf("Please insert a card in terminal \"%s\"\n", (const char *)v2);
do
{
do
{
usleep(0x64u);
v7 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v20);
v6 = v7;
}
while ( v7 == 2148532236LL );
}
while ( v7 == 2148532329LL );
}
if ( v6 )
{
v15 = (const char *)pcsc_stringify_error(v6);
printf("Connect to card error: %s : err=%X\n", v15, v6);
free(v2);
result = (unsigned int)v6;
}
else
{
v21 = 33LL;
v8 = SCardStatus(*a2, 0LL, v18, v19, v20, v17, &v21);
v9 = v8;
if ( v8 )
{
v16 = (const char *)pcsc_stringify_error(v8);
printf("Reading ATR error: %s\n", v16);
free(v2);
result = v9;
}
else
{
printf("Reading ATR: ");
if ( v21 )
{
for ( i = 0LL; i < v21; ++i )
printf("%.2X ", (unsigned __int8)v17[i]);
}
putchar(10);
free(v2);
result = 0LL;
}
}
}
}
return result;
}

original_code:
int init_terminal(
        SCARDCONTEXT *hContext,
        SCARDHANDLE *hCard)
{
    LONG rv;
    LPSTR mszReaders;
    DWORD dwReaders;
    DWORD dwAtrLen,dwProtocol,dwState,dwReaderLen;
    BYTE pbAtr[33];
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    rv = SCardListReaders(*hContext, ((void *)0), ((void *)0), &dwReaders);
    mszReaders = malloc(sizeof(char)*dwReaders);
    rv = SCardListReaders(*hContext, ((void *)0), mszReaders, &dwReaders);
    if(rv)
    {
        printf("ListReader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    printf("Reader=%s\n",mszReaders);
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    if(rv)
    {
        printf("Connect to reader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    rv = SCardConnect(*hContext, mszReaders, 0x0002,
                       0x0001, hCard, &dwProtocol);
    if(rv == 0x8010000C
        || rv == 0x80100069
        )
    {
        printf("Please insert a card in terminal \"%s\"\n",mszReaders);
    }
    while(rv == 0x8010000C
        || rv == 0x80100069)
    {
        usleep(100);
        rv = SCardConnect(*hContext, mszReaders, 0x0002,
                           0x0001, hCard, &dwProtocol);
    }
    if(rv)
    {
        printf("Connect to card error: %s : err=%X\n",pcsc_stringify_error(rv),rv);
        free(mszReaders);
        return rv;
    }
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(*hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(rv)
    {
        printf("Reading ATR error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    else
    {
        int i;
        printf("Reading ATR: ");
        for(i=0;i<dwAtrLen;i++)
            printf("%.2X ",pbAtr[i]);
        printf("\n");
    }
    free(mszReaders);
    return rv;
}

canonical_original_code:
int init_terminal(long *hContext, long *hCard)
{
    long rv;
    char *mszReaders;
    unsigned long dwReaders;
    unsigned long dwAtrLen; unsigned long dwProtocol; unsigned long dwState; unsigned long dwReaderLen;
    unsigned char pbAtr[33];
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    rv = SCardListReaders(*hContext, ((void *)0), ((void *)0), &dwReaders);
    mszReaders = malloc(sizeof(char)*dwReaders);
    rv = SCardListReaders(*hContext, ((void *)0), mszReaders, &dwReaders);
    if(rv)
    {
        printf("ListReader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    printf("Reader=%s\n",mszReaders);
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    if(rv)
    {
        printf("Connect to reader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    rv = SCardConnect(*hContext, mszReaders, 0x0002,
                       0x0001, hCard, &dwProtocol);
    if(rv == 0x8010000C
        || rv == 0x80100069
        )
    {
        printf("Please insert a card in terminal \"%s\"\n",mszReaders);
    }
    while(rv == 0x8010000C
        || rv == 0x80100069)
    {
        usleep(100);
        rv = SCardConnect(*hContext, mszReaders, 0x0002,
                           0x0001, hCard, &dwProtocol);
    }
    if(rv)
    {
        printf("Connect to card error: %s : err=%X\n",pcsc_stringify_error(rv),rv);
        free(mszReaders);
        return rv;
    }
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(*hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(rv)
    {
        printf("Reading ATR error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    else
    {
        int i;
        printf("Reading ATR: ");
        for(i=0;i<dwAtrLen;i++)
            printf("%.2X ",pbAtr[i]);
        printf("\n");
    }
    free(mszReaders);
    return rv;
}

variable_types:
hContext
long *

variable_types:
hCard
long *

variable_types: rv long

variable_types:
mszReaders
char *

variable_types:
dwReaders
unsigned long

variable_types:
dwAtrLen
unsigned long

variable_types:
dwProtocol
unsigned long

variable_types:
dwState
unsigned long

variable_types:
dwReaderLen
unsigned long

variable_types:
pbAtr
unsigned char [33]

variable_types: i int


decompiled_code:
int __fastcall release_terminal(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rax
const char *v5; // rax
const char *v6; // rax

v2 = SCardDisconnect(*a2, 2LL);
if ( v2 )
{
v5 = (const char *)pcsc_stringify_error(v2);
printf("Disconnect=%s\n", v5);
}
v3 = SCardReleaseContext(*a1);
if ( v3 )
{
v6 = (const char *)pcsc_stringify_error(v3);
printf("Release=%s\n", v6);
}
return puts("...Exiting ");
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rax
const char *v5; // rax
const char *v6; // rax

v2 = SCardDisconnect(*a2, 2LL);
if ( v2 )
{
v5 = (const char *)pcsc_stringify_error(v2);
printf("Disconnect=%s\n", v5);
}
v3 = SCardReleaseContext(*a1);
if ( v3 )
{
v6 = (const char *)pcsc_stringify_error(v3);
printf("Release=%s\n", v6);
}
return puts("...Exiting ");
}

original_code:
void release_terminal(
        SCARDCONTEXT *hContext,
        SCARDHANDLE *hCard)
{
    LONG rv;
    rv = SCardDisconnect(*hCard, 0x0002);
    if(rv)printf("Disconnect=%s\n",pcsc_stringify_error(rv));
    rv = SCardReleaseContext(*hContext);
    if(rv)printf("Release=%s\n",pcsc_stringify_error(rv));
    printf("...Exiting \n");
}

canonical_original_code:
void release_terminal(long *hContext, long *hCard)
{
    long rv;
    rv = SCardDisconnect(*hCard, 0x0002);
    if(rv)printf("Disconnect=%s\n",pcsc_stringify_error(rv));
    rv = SCardReleaseContext(*hContext);
    if(rv)printf("Release=%s\n",pcsc_stringify_error(rv));
    printf("...Exiting \n");
}


decompiled_code:
__int64 __fastcall check_terminal_status(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx
const char *v4; // rax
char v6[48]; // [rsp+8h] [rbp-68h] BYREF
char v7[8]; // [rsp+38h] [rbp-38h] BYREF
__int64 v8; // [rsp+40h] [rbp-30h] BYREF
char v9[8]; // [rsp+48h] [rbp-28h] BYREF
__int64 v10[4]; // [rsp+50h] [rbp-20h] BYREF

v10[0] = 33LL;
SCardStatus(a2, 0LL, v7, &v8, v9, v6, v10);
if ( v8 )
{
printf("State= %X, Possible diagnostic :\n", v8);
if ( (v8 & 2) != 0 )
puts("There is no card in the reader.");
if ( (v8 & 4) != 0 )
puts("There is a card in the reader, but it has not been moved into position for use.");
}
if ( (v8 & 8) != 0 )
puts("There is a card in the reader in position for use. The card is not powered.");
if ( (v8 & 0x10) != 0 )
puts("Power is being provided to the card, but the reader driver is unaware of the mode of the card.");
if ( (v8 & 0x20) != 0 )
puts("The card has been reset and is awaiting PTS negotiation.");
if ( (v8 & 0x40) != 0 )
puts("The card has been reset and specific communication protocols have been established.");
v2 = 0;
while ( 1 )
{
++v2;
printf("Trying to reconnect in %ds...\n", 3LL);
sleep(3u);
printf("Trying to reconnect... %d/%d\n", v2, 100LL);
v3 = SCardReconnect(a2, 2LL, 1LL, 1LL, v9);
v4 = (const char *)pcsc_stringify_error(v3);
puts(v4);
if ( !v3 )
break;
if ( v2 == 100 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx
const char *v4; // rax
char v6[48]; // [rsp+8h] [rbp-68h] BYREF
char v7[8]; // [rsp+38h] [rbp-38h] BYREF
__int64 v8; // [rsp+40h] [rbp-30h] BYREF
char v9[8]; // [rsp+48h] [rbp-28h] BYREF
__int64 v10[4]; // [rsp+50h] [rbp-20h] BYREF

v10[0] = 33LL;
SCardStatus(a2, 0LL, v7, &v8, v9, v6, v10);
if ( v8 )
{
printf("State= %X, Possible diagnostic :\n", v8);
if ( (v8 & 2) != 0 )
puts("There is no card in the reader.");
if ( (v8 & 4) != 0 )
puts("There is a card in the reader, but it has not been moved into position for use.");
}
if ( (v8 & 8) != 0 )
puts("There is a card in the reader in position for use. The card is not powered.");
if ( (v8 & 0x10) != 0 )
puts("Power is being provided to the card, but the reader driver is unaware of the mode of the card.");
if ( (v8 & 0x20) != 0 )
puts("The card has been reset and is awaiting PTS negotiation.");
if ( (v8 & 0x40) != 0 )
puts("The card has been reset and specific communication protocols have been established.");
v2 = 0;
while ( 1 )
{
++v2;
printf("Trying to reconnect in %ds...\n", 3LL);
sleep(3u);
printf("Trying to reconnect... %d/%d\n", v2, 100LL);
v3 = SCardReconnect(a2, 2LL, 1LL, 1LL, v9);
v4 = (const char *)pcsc_stringify_error(v3);
puts(v4);
if ( !v3 )
break;
if ( v2 == 100 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int check_terminal_status(SCARDCONTEXT hContext,SCARDHANDLE hCard)
{
    LONG rv;
    DWORD dwAtrLen,dwProtocol,dwState,dwReaderLen;
    BYTE pbAtr[33];
    int c= 0;
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(dwState)
        printf("State= %X, Possible diagnostic :\n",dwState);
    if((dwState & 0x0002) == 0x0002 )
        printf("There is no card in the reader.\n");
    if((dwState & 0x0004) == 0x0004)
        printf("There is a card in the reader, but it has not been moved into position for use.\n");
    if((dwState & 0x0008) == 0x0008)
        printf("There is a card in the reader in position for use. The card is not powered.\n");
    if((dwState & 0x0010) == 0x0010)
        printf("Power is being provided to the card, but the reader driver is unaware of the mode of the card.\n");
    if((dwState & 0x0020) == 0x0020 )
        printf("The card has been reset and is awaiting PTS negotiation.\n");
    if((dwState & 0x0040) == 0x0040)
        printf("The card has been reset and specific communication protocols have been established.\n");
    rv= 1;
    while(rv != 0x00000000)
    {
        if(c==100)
            return -1;
        c++;
        printf("Trying to reconnect in %ds...\n",3);
        sleep(3);
        printf("Trying to reconnect... %d/%d\n",c,100);
        rv= SCardReconnect(hCard, 0x0002, 0x0001,
                           0x0001, &dwProtocol);
        printf("%s\n",pcsc_stringify_error(rv));
    }
    return 0;
}

canonical_original_code:
int check_terminal_status(long hContext, long hCard)
{
    long rv;
    unsigned long dwAtrLen; unsigned long dwProtocol; unsigned long dwState; unsigned long dwReaderLen;
    unsigned char pbAtr[33];
    int c = 0;
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(dwState)
        printf("State= %X, Possible diagnostic :\n",dwState);
    if((dwState & 0x0002) == 0x0002 )
        printf("There is no card in the reader.\n");
    if((dwState & 0x0004) == 0x0004)
        printf("There is a card in the reader, but it has not been moved into position for use.\n");
    if((dwState & 0x0008) == 0x0008)
        printf("There is a card in the reader in position for use. The card is not powered.\n");
    if((dwState & 0x0010) == 0x0010)
        printf("Power is being provided to the card, but the reader driver is unaware of the mode of the card.\n");
    if((dwState & 0x0020) == 0x0020 )
        printf("The card has been reset and is awaiting PTS negotiation.\n");
    if((dwState & 0x0040) == 0x0040)
        printf("The card has been reset and specific communication protocols have been established.\n");
    rv= 1;
    while(rv != 0x00000000)
    {
        if(c==100)
            return -1;
        c++;
        printf("Trying to reconnect in %ds...\n",3);
        sleep(3);
        printf("Trying to reconnect... %d/%d\n",c,100);
        rv= SCardReconnect(hCard, 0x0002, 0x0001,
                           0x0001, &dwProtocol);
        printf("%s\n",pcsc_stringify_error(rv));
    }
    return 0;
}

variable_types: hContext long

variable_types: hCard long

variable_types: c int


decompiled_code:
void __fastcall __noreturn test_and_close(unsigned int a1)
{
if ( a1 == 2 || a1 == 15 )
{
fprintf(stderr, "Recv signal %d\n", a1);
fflush(stderr);
close_tunnel(&tunnel);
release_terminal(&hContext, &hCard);
}
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
if ( a1 == 2 || a1 == 15 )
{
fprintf(stderr, "Recv signal %d\n", a1);
fflush(stderr);
close_tunnel(&tunnel);
release_terminal(&hContext, &hCard);
}
exit(0);
}

original_code:
static void test_and_close(int sig_ptr)
{
  switch(sig_ptr)
  {
  case 2:
  case 15:
      fprintf(stderr, "Recv signal %d\n", sig_ptr);
      fflush(stderr);
      close_tunnel(&tunnel);
      release_terminal(&hContext,&hCard);
      break;
  default:
      break;
  }
  exit(0);
}


decompiled_code:
__sighandler_t init_signals()
{
int *v0; // rbx
__sighandler_t result; // rax

v0 = (int *)&signals;
do
result = signal(*v0++, (__sighandler_t)test_and_close);
while ( v0 != (int *)(unsigned int)((_DWORD)&signals + 24) );
return result;
}

canonical_decompiled_code:
__sighandler_t func1()
{
int *v0; // rbx
__sighandler_t result; // rax

v0 = (int *)&signals;
do
result = signal(*v0++, (__sighandler_t)test_and_close);
while ( v0 != (int *)(unsigned int)((_DWORD)&signals + 24) );
return result;
}

original_code:
void init_signals(void)
{
  int i;
  for (i=0 ; i < 6 ; i++)
    signal( signals[i], test_and_close) ;
}

canonical_original_code:
void init_signals()
{
  int i;
  for (i=0 ; i < 6 ; i++)
    signal( signals[i], test_and_close) ;
}


decompiled_code:
int __fastcall print_packet(__int64 a1, __int64 a2)
{
int v3; // ebp
const unsigned __int16 **v4; // r14
__int64 v5; // rbx
int j; // ebp
unsigned __int8 v7; // di
bool v8; // al
__int64 v9; // rbx
bool v10; // al
int i; // [rsp+8h] [rbp-40h]

printf("Dumping %dbytes\n", a2);
if ( (int)a2 > 0 )
{
for ( i = 0; (((_DWORD)a2 - 1) & 0xFFFFFFF0) + 16 != i; i += 16 )
{
printf("%.4X: ", (unsigned int)i);
if ( (int)a2 <= i )
{
v3 = 0;
}
else
{
v9 = i + 1;
v3 = 0;
do
{
printf("%.2X", *(unsigned __int8 *)(a1 + v9 - 1));
++v3;
v10 = (int)a2 > (int)v9++;
}
while ( v10 && v3 <= 15 );
if ( v3 > 15 )
{
printf(" ");
LABEL_6:
v4 = _ctype_b_loc();
v5 = i + 1;
j = 0;
do
{
v7 = *(_BYTE *)(a1 + v5 - 1);
if ( ((*v4)[v7] & 0x8000u) == 0 )
v7 = 46;
putchar(v7);
++j;
v8 = (int)a2 > (int)v5++;
}
while ( v8 && j <= 15 );
if ( j > 15 )
goto LABEL_11;
goto LABEL_18;
}
}
do
{
printf(" ");
++v3;
}
while ( v3 <= 15 );
printf(" ");
if ( (int)a2 > i )
goto LABEL_6;
for ( j = 0; j <= 15; ++j )
LABEL_18:
putchar(32);
LABEL_11:
putchar(10);
}
}
putchar(10);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
int v3; // ebp
const unsigned __int16 **v4; // r14
__int64 v5; // rbx
int j; // ebp
unsigned __int8 v7; // di
bool v8; // al
__int64 v9; // rbx
bool v10; // al
int i; // [rsp+8h] [rbp-40h]

printf("Dumping %dbytes\n", a2);
if ( (int)a2 > 0 )
{
for ( i = 0; (((_DWORD)a2 - 1) & 0xFFFFFFF0) + 16 != i; i += 16 )
{
printf("%.4X: ", (unsigned int)i);
if ( (int)a2 <= i )
{
v3 = 0;
}
else
{
v9 = i + 1;
v3 = 0;
do
{
printf("%.2X", *(unsigned __int8 *)(a1 + v9 - 1));
++v3;
v10 = (int)a2 > (int)v9++;
}
while ( v10 && v3 <= 15 );
if ( v3 > 15 )
{
printf(" ");
LABEL_6:
v4 = _ctype_b_loc();
v5 = i + 1;
j = 0;
do
{
v7 = *(_BYTE *)(a1 + v5 - 1);
if ( ((*v4)[v7] & 0x8000u) == 0 )
v7 = 46;
putchar(v7);
++j;
v8 = (int)a2 > (int)v5++;
}
while ( v8 && j <= 15 );
if ( j > 15 )
goto LABEL_11;
goto LABEL_18;
}
}
do
{
printf(" ");
++v3;
}
while ( v3 <= 15 );
printf(" ");
if ( (int)a2 > i )
goto LABEL_6;
for ( j = 0; j <= 15; ++j )
LABEL_18:
putchar(32);
LABEL_11:
putchar(10);
}
}
putchar(10);
return fflush(stdout);
}

original_code:
void print_packet(const unsigned char *ptr,int len)
{
    int i,j;
    printf("Dumping %dbytes\n",len);
    for(i=0;i<len;i++)
    {
        printf("%.4X: ",i);
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%.2X",ptr[i+j]);
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf("  ");
        }
        printf("  ");
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%c",((*__ctype_b_loc ())[(int) ((ptr[i+j]))] & (unsigned short int) _ISgraph)?ptr[i+j]:'.');
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf(" ");
        }
        printf("\n");
        i+=15;
    }
    printf("\n");
    fflush(stdout);
}

canonical_original_code:
void print_packet(unsigned char *ptr, int len)
{
    int i; int j;
    printf("Dumping %dbytes\n",len);
    for(i=0;i<len;i++)
    {
        printf("%.4X: ",i);
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%.2X",ptr[i+j]);
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf("  ");
        }
        printf("  ");
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%c",((*__ctype_b_loc ())[(int) ((ptr[i+j]))] & (unsigned short) _ISgraph)?ptr[i+j]:'.');
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf(" ");
        }
        printf("\n");
        i+=15;
    }
    printf("\n");
    fflush(stdout);
}

variable_types:
ptr
unsigned char *

variable_types: len int

variable_types: j int


original_code:
int open_tunnel(utun *tunnel)
{
    return utun_open(tunnel,"192.168.1.5", "192.168.1.6",1500);
}

canonical_original_code:
int open_tunnel(struct tun_t *tunnel)
{
    return utun_open(tunnel,"192.168.1.5", "192.168.1.6",1500);
}

variable_types:
tunnel
struct tun_t { int fd; } *


decompiled_code:
__int64 close_tunnel()
{
return utun_close();
}

canonical_decompiled_code:
__int64 func1()
{
return utun_close();
}

original_code:
void close_tunnel(utun *tunnel)
{
    utun_close(tunnel);
}

canonical_original_code:
void close_tunnel(struct tun_t *tunnel)
{
    utun_close(tunnel);
}


repo: juliords/mycompiler

decompiled_code:
__int64 next_label()
{
return (unsigned int)++l_0;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)++l_0;
}

original_code:
int next_label()
{
 static int l = 0;
 return ++l;
}

variable_types: l int


decompiled_code:
__int64 __fastcall float_to_int(__m128i a1)
{
return (unsigned int)_mm_cvtsi128_si32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__m128i a1)
{
return (unsigned int)_mm_cvtsi128_si32(a1);
}

original_code:
int float_to_int(float f)
{
 union
 {
  int i;
  float f;
 } v;
 v.f = f;
 return v.i;
}

variable_types: f float

variable_types:
v
union { int i; float f; }


decompiled_code:
__int64 __fastcall multiple_of_n(signed int a1, int a2)
{
int v2; // edx
unsigned int v3; // esi
__int64 result; // rax

v2 = a1 % a2;
v3 = a1 + a2 - a1 % a2;
result = (unsigned int)a1;
if ( v2 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(signed int a1, int a2)
{
int v2; // edx
unsigned int v3; // esi
__int64 result; // rax

v2 = a1 % a2;
v3 = a1 + a2 - a1 % a2;
result = (unsigned int)a1;
if ( v2 )
result = v3;
return result;
}

original_code:
int multiple_of_n(int i, int n)
{
 if(i % n == 0) return i;
 return i + (n - (i % n));
}

variable_types: n int


decompiled_code:
_BOOL8 __fastcall is_char(_DWORD *a1)
{
_BOOL8 result; // rax

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

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1)
{
_BOOL8 result; // rax

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

original_code:
int is_char(TypeNode* t)
{
 if(t && t->prim == TypeChar && t->dims == 0)
  return 1;
 return 0;
}

canonical_original_code:
int is_char(struct TypeNode *t)
{
 if(t && t->prim == TypeChar && t->dims == 0)
  return 1;
 return 0;
}

variable_types: struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *

user_defined_types: struct TypeNode { enum BaseType prim; int dims; }


decompiled_code:
__int64 __fastcall max_esp(__int64 a1, unsigned int a2)
{
_QWORD *v2; // rbx
signed int v3; // ebp
__int64 v4; // r12
unsigned int v5; // ebp
_QWORD *i; // rbx

if ( !a1 )
return 0;
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v3 = a2;
do
{
v4 = *v2;
if ( is_char(*(_DWORD **)(*v2 + 8LL)) )
++v3;
else
v3 = multiple_of_n(v3, 4) + 4;
*(_DWORD *)(v4 + 28) = v3;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
}
else
{
v3 = a2;
}
v5 = multiple_of_n(v3, 4);
for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)i[1] )
{
if ( *(_DWORD *)*i == 5 )
max_esp(*(_QWORD *)(*i + 8LL), a2);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
_QWORD *v2; // rbx
signed int v3; // ebp
__int64 v4; // r12
unsigned int v5; // ebp
_QWORD *i; // rbx

if ( !a1 )
return 0;
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v3 = a2;
do
{
v4 = *v2;
if ( func3(*(_DWORD **)(*v2 + 8LL)) )
++v3;
else
v3 = func2(v3, 4) + 4;
*(_DWORD *)(v4 + 28) = v3;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
}
else
{
v3 = a2;
}
v5 = func2(v3, 4);
for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)i[1] )
{
if ( *(_DWORD *)*i == 5 )
func4(*(_QWORD *)(*i + 8LL), a2);
}
return v5;
}

original_code:
int max_esp(BlockNode *blk, int esp)
{
 ListNode *lst;
 int max = esp;
 if(!blk) return 0;
 for(lst = blk->var; lst; lst = lst->next)
 {
  DecVarNode *v = (DecVarNode*)lst->data;
  if(is_char(v->type))
  {
   max += 1;
  }
  else
  {
   max = multiple_of_n(max, 4);
   max += 4;
  }
  v->stack_offset = max;
 }
 max = multiple_of_n(max, 4);
 for(lst = blk->cmd; lst; lst = lst->next)
 {
  CmdNode *cmd = (CmdNode*)lst->data;
  if(cmd->type == CmdBlock)
  {
   int t = max_esp(cmd->u.b.block, esp);
   if(t > max) t = max;
  }
 }
 return max;
}

canonical_original_code:
int max_esp(struct BlockNode *blk, int esp)
{
 struct ListNode *lst;
 int max = esp;
 if(!blk) return 0;
 for(lst = blk->var; lst; lst = lst->next)
 {
  struct DecVarNode *v = (DecVarNode*)lst->data;
  if(is_char(v->type))
  {
   max += 1;
  }
  else
  {
   max = multiple_of_n(max, 4);
   max += 4;
  }
  v->stack_offset = max;
 }
 max = multiple_of_n(max, 4);
 for(lst = blk->cmd; lst; lst = lst->next)
 {
  struct CmdNode *cmd = (CmdNode*)lst->data;
  if(cmd->type == CmdBlock)
  {
   int t = max_esp(cmd->u.b.block, esp);
   if(t > max) t = max;
  }
 }
 return max;
}

variable_types: struct BlockNode { struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *var; struct ListNode *cmd; } *

variable_types: esp int

variable_types: max int

variable_types: struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *name; int nref; int stack_offset; } *

variable_types: struct CmdNode { enum CmdType { CmdIf=0, CmdWhile=1, CmdAssig=2, CmdRet=3, CmdCall=4, CmdBlock=5 } type; union { struct { struct ExpNode { enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 } type; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *atype; union { struct { struct VarNode { enum VarType { VarId=0, VarArray=1 } type; struct TypeNode *atype; union { struct { char *id; struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode *type; char *name; int nref; int stack_offset; } *dec; } b; struct { struct ExpNode *exp; struct VarNode *var; } d; } u; } *var; } var; struct { enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 } type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 } type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 } type; struct ExpNode *exp; } un; struct { struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; } *cond; struct CmdNode *cmd_if; struct CmdNode *cmd_else; } i; struct { struct ExpNode *cond; struct CmdNode *cmd; } w; struct { struct VarNode *var; struct ExpNode *exp; } a; struct { struct ExpNode *exp; } r; struct { struct BlockNode *block; } b; struct { struct CallNode *call; } c; } u; } *

variable_types: t int

user_defined_types: struct DecVarNode { enum DecVarType context; struct TypeNode *type; char *name; int nref; int stack_offset; }

user_defined_types: struct CmdNode { enum CmdType type; union { struct { struct ExpNode *cond; struct CmdNode *cmd_if; struct CmdNode *cmd_else; } i; struct { struct ExpNode *cond; struct CmdNode *cmd; } w; struct { struct VarNode *var; struct ExpNode *exp; } a; struct { struct ExpNode *exp; } r; struct { struct BlockNode *block; } b; struct { struct CallNode *call; } c; } u; }

user_defined_types: struct ExpNode { enum ExpType type; struct TypeNode *atype; union { struct { struct VarNode *var; } var; struct { enum PrimitiveType type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType type; struct ExpNode *exp; } un; struct { struct CallNode *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; }

user_defined_types: struct VarNode { enum VarType type; struct TypeNode *atype; union { struct { char *id; struct DecVarNode *dec; } b; struct { struct ExpNode *exp; struct VarNode *var; } d; } u; }

user_defined_types: struct CallNode { char *id; struct ListNode *exp; struct DecFuncNode *dec; }

user_defined_types: struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode *block; int nref; }


asmDecVarNode

decompiled_code:
void __fastcall asmDecVarNode(_QWORD *a1)
{
_QWORD *i; // rbx
_DWORD *v2; // rbp
__int64 v3; // rdx

for ( i = a1; i; i = (_QWORD *)i[1] )
{
v2 = (_DWORD *)*i;
if ( !*(_DWORD *)*i )
{
v3 = !is_char(*((_DWORD **)v2 + 1)) ? 4 : 1;
printf("\t.comm\t%s,%d,%d\n", *((const char **)v2 + 2), v3, (unsigned int)v3);
}
}
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
_QWORD *i; // rbx
_DWORD *v2; // rbp
__int64 v3; // rdx

for ( i = a1; i; i = (_QWORD *)i[1] )
{
v2 = (_DWORD *)*i;
if ( !*(_DWORD *)*i )
{
v3 = !func3(*((_DWORD **)v2 + 1)) ? 4 : 1;
printf("\t.comm\t%s,%d,%d\n", *((const char **)v2 + 2), v3, (unsigned int)v3);
}
}
}

original_code:
void asmDecVarNode(ListNode* p)
{
 ListNode* l;
 if(!p) return;
 for(l = p; l; l = l->next)
 {
  DecVarNode *v = (DecVarNode*)l->data;
  if(v->context == DecVarGlobal)
  {
   int s;
   if(is_char(v->type)) s = 1;
   else s = 4;
   printf("\t.comm\t%s,%d,%d\n", v->name, s, s);
  }
 }
}

canonical_original_code:
void asmDecVarNode(struct ListNode *p)
{
 struct ListNode *l;
 if(!p) return;
 for(l = p; l; l = l->next)
 {
  struct DecVarNode *v = (DecVarNode*)l->data;
  if(v->context == DecVarGlobal)
  {
   int s;
   if(is_char(v->type)) s = 1;
   else s = 4;
   printf("\t.comm\t%s,%d,%d\n", v->name, s, s);
  }
 }
}

variable_types: struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *

variable_types: s int

user_defined_types: enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 }

user_defined_types: enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 }


asmExpNode

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

if ( a1 )
{
result = *a1;
switch ( *a1 )
{
case 0u:
result = asmVarNode(*((_QWORD *)a1 + 2));
break;
case 2u:
asmExpNode(*((_QWORD *)a1 + 3));
result = asmExpNode(*((_QWORD *)a1 + 4));
break;
case 3u:
case 5u:
result = asmExpNode(*((_QWORD *)a1 + 3));
break;
case 4u:
result = asmCallNode(*((_QWORD *)a1 + 2));
break;
case 6u:
result = asmExpNode(*((_QWORD *)a1 + 2));
break;
default:
return result;
}
}
return result;
}

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

if ( a1 )
{
result = *a1;
switch ( *a1 )
{
case 0u:
result = func8(*((_QWORD *)a1 + 2));
break;
case 2u:
func7(*((_QWORD *)a1 + 3));
result = func7(*((_QWORD *)a1 + 4));
break;
case 3u:
case 5u:
result = func7(*((_QWORD *)a1 + 3));
break;
case 4u:
result = func6(*((_QWORD *)a1 + 2));
break;
case 6u:
result = func7(*((_QWORD *)a1 + 2));
break;
default:
return result;
}
}
return result;
}

original_code:
void asmExpNode(ExpNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case ExpVar:
   asmVarNode(p->u.var.var);
   break;
  case ExpConst:
   switch(p->u.prim.type)
   {
    case PrimInt:
     break;
    case PrimFloat:
     break;
    case PrimChar:
     break;
    case PrimStr:
     break;
   }
   break;
  case ExpBin:
   asmExpNode(p->u.bin.left);
   switch(p->u.bin.type)
   {
    case ExpBinPlus: break;
    case ExpBinMinus: break;
    case ExpBinMult: break;
    case ExpBinDiv: break;
    case ExpBinEQ: break;
    case ExpBinLE: break;
    case ExpBinGE: break;
    case ExpBinLT: break;
    case ExpBinGT: break;
    case ExpBinAnd: break;
    case ExpBinOr: break;
   }
   asmExpNode(p->u.bin.right);
   break;
  case ExpUn:
   switch(p->u.un.type)
   {
    case ExpUnMinus: break;
    case ExpUnNot: break;
   }
   asmExpNode(p->u.un.exp);
   break;
  case ExpCall:
   asmCallNode(p->u.call.call);
   break;
  case ExpNew:
   asmExpNode(p->u.enew.exp);
   break;
  case ExpCast:
   asmExpNode(p->u.cast.exp);
 }
}

canonical_original_code:
void asmExpNode(struct ExpNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case ExpVar:
   asmVarNode(p->u.var.var);
   break;
  case ExpConst:
   switch(p->u.prim.type)
   {
    case PrimInt:
     break;
    case PrimFloat:
     break;
    case PrimChar:
     break;
    case PrimStr:
     break;
   }
   break;
  case ExpBin:
   asmExpNode(p->u.bin.left);
   switch(p->u.bin.type)
   {
    case ExpBinPlus: break;
    case ExpBinMinus: break;
    case ExpBinMult: break;
    case ExpBinDiv: break;
    case ExpBinEQ: break;
    case ExpBinLE: break;
    case ExpBinGE: break;
    case ExpBinLT: break;
    case ExpBinGT: break;
    case ExpBinAnd: break;
    case ExpBinOr: break;
   }
   asmExpNode(p->u.bin.right);
   break;
  case ExpUn:
   switch(p->u.un.type)
   {
    case ExpUnMinus: break;
    case ExpUnNot: break;
   }
   asmExpNode(p->u.un.exp);
   break;
  case ExpCall:
   asmCallNode(p->u.call.call);
   break;
  case ExpNew:
   asmExpNode(p->u.enew.exp);
   break;
  case ExpCast:
   asmExpNode(p->u.cast.exp);
 }
}

variable_types: struct ExpNode { enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 } type; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *atype; union { struct { struct VarNode { enum VarType { VarId=0, VarArray=1 } type; struct TypeNode *atype; union { struct { char *id; struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode *type; char *name; int nref; int stack_offset; } *dec; } b; struct { struct ExpNode *exp; struct VarNode *var; } d; } u; } *var; } var; struct { enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 } type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 } type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 } type; struct ExpNode *exp; } un; struct { struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; } *


asmVarNode

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

if ( a1 )
{
if ( *(_DWORD *)a1 == 1 )
{
asmVarNode(*(_QWORD *)(a1 + 24));
result = asmExpNode(*(unsigned int **)(a1 + 16));
}
}
return result;
}

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

if ( a1 )
{
if ( *(_DWORD *)a1 == 1 )
{
func8(*(_QWORD *)(a1 + 24));
result = func7(*(unsigned int **)(a1 + 16));
}
}
return result;
}

original_code:
void asmVarNode(VarNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case VarId:
   break;
  case VarArray:
   asmVarNode(p->u.d.var);
   asmExpNode(p->u.d.exp);
   break;
 }
}

canonical_original_code:
void asmVarNode(struct VarNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case VarId:
   break;
  case VarArray:
   asmVarNode(p->u.d.var);
   asmExpNode(p->u.d.exp);
   break;
 }
}

variable_types: struct VarNode { enum VarType { VarId=0, VarArray=1 } type; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *atype; union { struct { char *id; struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode *type; char *name; int nref; int stack_offset; } *dec; } b; struct { struct ExpNode { enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 } type; struct TypeNode *atype; union { struct { struct VarNode *var; } var; struct { enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 } type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 } type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 } type; struct ExpNode *exp; } un; struct { struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; } *exp; struct VarNode *var; } d; } u; } *


asmCmdNode

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

if ( a1 )
{
result = *(unsigned int *)a1;
switch ( *(_DWORD *)a1 )
{
case 0:
asmExpNode(a1[1]);
result = asmCmdNode(a1[2]);
v2 = a1[3];
if ( v2 )
result = asmCmdNode(v2);
break;
case 1:
asmExpNode(a1[1]);
result = asmCmdNode(a1[2]);
break;
case 2:
asmVarNode((__int64)a1[1]);
result = asmExpNode(a1[2]);
break;
case 3:
v3 = a1[1];
if ( v3 )
result = asmExpNode(v3);
break;
case 4:
result = asmCallNode((__int64)a1[1]);
break;
case 5:
result = asmBlockNode(a1[1]);
break;
default:
return result;
}
}
return result;
}

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

if ( a1 )
{
result = *(unsigned int *)a1;
switch ( *(_DWORD *)a1 )
{
case 0:
func7(a1[1]);
result = func9(a1[2]);
v2 = a1[3];
if ( v2 )
result = func9(v2);
break;
case 1:
func7(a1[1]);
result = func9(a1[2]);
break;
case 2:
func8((__int64)a1[1]);
result = func7(a1[2]);
break;
case 3:
v3 = a1[1];
if ( v3 )
result = func7(v3);
break;
case 4:
result = func6((__int64)a1[1]);
break;
case 5:
result = func10(a1[1]);
break;
default:
return result;
}
}
return result;
}

original_code:
void asmCmdNode(CmdNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case CmdIf:
   asmExpNode(p->u.i.cond);
   asmCmdNode(p->u.i.cmd_if);
   if(p->u.i.cmd_else)
   {
    asmCmdNode(p->u.i.cmd_else);
   }
   break;
  case CmdWhile:
   asmExpNode(p->u.w.cond);
   asmCmdNode(p->u.w.cmd);
   break;
  case CmdAssig:
   asmVarNode(p->u.a.var);
   asmExpNode(p->u.a.exp);
   break;
  case CmdRet:
   if(p->u.r.exp)
   {
    asmExpNode(p->u.r.exp);
   }
   break;
  case CmdCall:
   asmCallNode(p->u.c.call);
   break;
  case CmdBlock:
   asmBlockNode(p->u.b.block);
   break;
 }
}

canonical_original_code:
void asmCmdNode(struct CmdNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case CmdIf:
   asmExpNode(p->u.i.cond);
   asmCmdNode(p->u.i.cmd_if);
   if(p->u.i.cmd_else)
   {
    asmCmdNode(p->u.i.cmd_else);
   }
   break;
  case CmdWhile:
   asmExpNode(p->u.w.cond);
   asmCmdNode(p->u.w.cmd);
   break;
  case CmdAssig:
   asmVarNode(p->u.a.var);
   asmExpNode(p->u.a.exp);
   break;
  case CmdRet:
   if(p->u.r.exp)
   {
    asmExpNode(p->u.r.exp);
   }
   break;
  case CmdCall:
   asmCallNode(p->u.c.call);
   break;
  case CmdBlock:
   asmBlockNode(p->u.b.block);
   break;
 }
}

user_defined_types: enum CmdType { CmdIf=0, CmdWhile=1, CmdAssig=2, CmdRet=3, CmdCall=4, CmdBlock=5 }

user_defined_types: enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 }

user_defined_types: enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 }

user_defined_types: enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 }

user_defined_types: enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 }

user_defined_types: struct ListNode { void *data; struct ListNode *next; struct ListNode *last; }

user_defined_types: struct BlockNode { struct ListNode *var; struct ListNode *cmd; }


asmDecFuncNode

decompiled_code:
void __fastcall asmDecFuncNode(__int64 a1)
{
signed int v1; // eax
unsigned int v2; // eax
_QWORD *v3; // rax
int v4; // edx

if ( a1 && *(_QWORD *)(a1 + 24) )
{
printf("\n\t.globl\t%s\n", *(const char **)(a1 + 8));
printf("\t.type\t%s, @function\n", *(const char **)(a1 + 8));
printf("%s:\n", *(const char **)(a1 + 8));
printf("\tpushq\t%%rbp\n");
printf("\tmovq\t%%rsp, %%rbp\n");
v1 = max_esp(*(_QWORD *)(a1 + 24), 0);
v2 = multiple_of_n(v1, 16);
if ( v2 )
printf("\tsubq\t$%d, %%rsp\n", v2);
v3 = *(_QWORD **)(a1 + 16);
if ( v3 )
{
v4 = 8;
do
{
*(_DWORD *)(*v3 + 28LL) = v4;
v4 += 4;
v3 = (_QWORD *)v3[1];
}
while ( v3 );
}
asmBlockNode(*(_QWORD *)(a1 + 24));
puts("\tleave");
puts("\tret");
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
signed int v1; // eax
unsigned int v2; // eax
_QWORD *v3; // rax
int v4; // edx

if ( a1 && *(_QWORD *)(a1 + 24) )
{
printf("\n\t.globl\t%s\n", *(const char **)(a1 + 8));
printf("\t.type\t%s, @function\n", *(const char **)(a1 + 8));
printf("%s:\n", *(const char **)(a1 + 8));
printf("\tpushq\t%%rbp\n");
printf("\tmovq\t%%rsp, %%rbp\n");
v1 = func4(*(_QWORD *)(a1 + 24), 0);
v2 = func2(v1, 16);
if ( v2 )
printf("\tsubq\t$%d, %%rsp\n", v2);
v3 = *(_QWORD **)(a1 + 16);
if ( v3 )
{
v4 = 8;
do
{
*(_DWORD *)(*v3 + 28LL) = v4;
v4 += 4;
v3 = (_QWORD *)v3[1];
}
while ( v3 );
}
func10(*(_QWORD *)(a1 + 24));
puts("\tleave");
puts("\tret");
}
}

original_code:
void asmDecFuncNode(DecFuncNode* p)
{
 ListNode *l;
 int esp;
 if(!p || !p->block) return;
 printf("\n\t.globl\t%s\n", p->id);
 printf("\t.type\t%s, @function\n", p->id);
 printf("%s:\n", p->id);
 printf("\tpushq\t%%rbp\n");
 printf("\tmovq\t%%rsp, %%rbp\n");
 esp = multiple_of_n(max_esp(p->block, 0), 16);
 if(esp) printf("\tsubq\t$%d, %%rsp\n", esp);
 esp = 8;
 for(l = p->params; l; l = l->next)
 {
  DecVarNode *v = (DecVarNode*)l->data;
  v->stack_offset = esp;
  esp += 4;
 }
 asmBlockNode(p->block);
 printf("\tleave\n");
 printf("\tret\n");
}

canonical_original_code:
void asmDecFuncNode(struct DecFuncNode *p)
{
 struct ListNode *l;
 int esp;
 if(!p || !p->block) return;
 printf("\n\t.globl\t%s\n", p->id);
 printf("\t.type\t%s, @function\n", p->id);
 printf("%s:\n", p->id);
 printf("\tpushq\t%%rbp\n");
 printf("\tmovq\t%%rsp, %%rbp\n");
 esp = multiple_of_n(max_esp(p->block, 0), 16);
 if(esp) printf("\tsubq\t$%d, %%rsp\n", esp);
 esp = 8;
 for(l = p->params; l; l = l->next)
 {
  struct DecVarNode *v = (DecVarNode*)l->data;
  v->stack_offset = esp;
  esp += 4;
 }
 asmBlockNode(p->block);
 printf("\tleave\n");
 printf("\tret\n");
}

variable_types: struct DecFuncNode { struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *


asmDeclarationNode

decompiled_code:
void __fastcall asmDeclarationNode(__int64 a1)
{
if ( a1 )
{
if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 1 )
asmDecFuncNode(*(_QWORD *)(a1 + 8));
}
else
{
asmDecVarNode(*(_QWORD **)(a1 + 8));
}
}
}

original_code:
void asmDeclarationNode(DeclarationNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case DecVar:
   asmDecVarNode(p->u.var);
   break;
  case DecFunc:
   asmDecFuncNode(p->u.func);
 }
}

canonical_original_code:
void asmDeclarationNode(struct DeclarationNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case DecVar:
   asmDecVarNode(p->u.var);
   break;
  case DecFunc:
   asmDecFuncNode(p->u.func);
 }
}

variable_types: struct DeclarationNode { enum DeclarationType { DecVar=0, DecFunc=1 } type; union { struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *var; struct DecFuncNode { struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *func; } u; } *

user_defined_types: struct DeclarationNode { enum DeclarationType type; union { struct ListNode *var; struct DecFuncNode *func; } u; }


catListNode

original_code:
ListNode *catListNode(ListNode *a, ListNode *b)
{
 if(!a) return b;
 if(!b) return a;
 a->last->next = b;
 a->last = b->last;
 return a;
}

canonical_original_code:
struct ListNode *catListNode(struct ListNode *a, struct ListNode *b)
{
 if(!a) return b;
 if(!b) return a;
 a->last->next = b;
 a->last = b->last;
 return a;
}

variable_types:
a
struct ListNode *

variable_types:
b
struct ListNode *

return_type: struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *


newTypeNodeTypeArray

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

result = a1;
++*(_DWORD *)(a1 + 4);
return result;
}

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

result = a1;
++*(_DWORD *)(a1 + 4);
return result;
}

original_code:
TypeNode* newTypeNodeTypeArray(TypeNode *t)
{
 t->dims++;
 return t;
}

canonical_original_code:
struct TypeNode *newTypeNodeTypeArray(struct TypeNode *t)
{
 t->dims++;
 return t;
}

variable_types:
t
struct TypeNode *

return_type: struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *

user_defined_types: struct TypeNode { enum BaseType prim; int dims; }


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return puts(a1);
}

original_code:
void yyerror(char *s)
{
 printf("%s\n", s);
}

variable_types:
s
char *


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
argv = (const char **)"r";
yyin = fopen(*(const char **)&argc, "r");
}
else
{
yyin = stdin;
}
v3 = yyparse(*(_QWORD *)&argc, argv, envp);
checkProgramNode(tree);
asmProgramNode(tree);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 int ret;
 if (argc < 2) yyin = stdin;
 else yyin = fopen(argv[1], "r");
 ret = yyparse();
 checkProgramNode(tree);
 asmProgramNode(tree);
 return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int


printTabs

decompiled_code:
int __fastcall printTabs(int a1)
{
int i; // ebx
int result; // eax

for ( i = a1; i; --i )
result = putchar(9);
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int i; // ebx
int result; // eax

for ( i = a1; i; --i )
result = putchar(9);
return result;
}

original_code:
void printTabs(int i)
{
 while(i--)
 {
  printf("\t");
 }
}

variable_types: i int


printTypeNode

decompiled_code:
void __fastcall printTypeNode(unsigned int *a1)
{
unsigned int v1; // eax
signed int i; // ebx

if ( a1 )
{
v1 = *a1;
if ( *a1 == 2 )
{
printf("int");
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
printf("float");
}
else if ( v1 )
{
printf("char");
}
else
{
printf("void");
}
for ( i = 0; (int)a1[1] > i; ++i )
printf("[]");
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int *a1)
{
unsigned int v1; // eax
signed int i; // ebx

if ( a1 )
{
v1 = *a1;
if ( *a1 == 2 )
{
printf("int");
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
printf("float");
}
else if ( v1 )
{
printf("char");
}
else
{
printf("void");
}
for ( i = 0; (int)a1[1] > i; ++i )
printf("[]");
}
}

original_code:
void printTypeNode(TypeNode* p)
{
 int i;
 if(!p) return;
 switch(p->prim)
 {
  case TypeInt:
   printf("int");
   break;
  case TypeChar:
   printf("char");
   break;
  case TypeFloat:
   printf("float");
   break;
  case TypeVoid:
   printf("void");
   break;
 }
 for (i = 0; i < p->dims; i++)
 {
  printf("[]");
 }
}

canonical_original_code:
void printTypeNode(struct TypeNode *p)
{
 int i;
 if(!p) return;
 switch(p->prim)
 {
  case TypeInt:
   printf("int");
   break;
  case TypeChar:
   printf("char");
   break;
  case TypeFloat:
   printf("float");
   break;
  case TypeVoid:
   printf("void");
   break;
 }
 for (i = 0; i < p->dims; i++)
 {
  printf("[]");
 }
}

variable_types: struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *


printParamNode

decompiled_code:
int __fastcall printParamNode(__int64 a1)
{
int result; // eax

if ( a1 )
{
printTypeNode(*(unsigned int **)(a1 + 8));
result = printf(" %s", *(const char **)(a1 + 16));
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax

if ( a1 )
{
func1(*(unsigned int **)(a1 + 8));
result = printf(" %s", *(const char **)(a1 + 16));
}
return result;
}

original_code:
void printParamNode(DecVarNode* p)
{
 if(!p) return;
 printTypeNode(p->type);
 printf(" %s", p->name);
}

canonical_original_code:
void printParamNode(struct DecVarNode *p)
{
 if(!p) return;
 printTypeNode(p->type);
 printf(" %s", p->name);
}

variable_types: struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *name; int nref; int stack_offset; } *

user_defined_types: struct DecVarNode { enum DecVarType context; struct TypeNode *type; char *name; int nref; int stack_offset; }


printCallNode

decompiled_code:
int __fastcall printCallNode(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

if ( a1 )
{
printf("%s(", *(const char **)a1);
v1 = *(_QWORD **)(a1 + 8);
if ( v1 )
{
while ( 1 )
{
printExpNode(*v1);
v1 = (_QWORD *)v1[1];
if ( !v1 )
break;
if ( *(_QWORD **)(a1 + 8) != v1 )
{
putchar(44);
putchar(32);
}
}
}
result = putchar(41);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

if ( a1 )
{
printf("%s(", *(const char **)a1);
v1 = *(_QWORD **)(a1 + 8);
if ( v1 )
{
while ( 1 )
{
func5(*v1);
v1 = (_QWORD *)v1[1];
if ( !v1 )
break;
if ( *(_QWORD **)(a1 + 8) != v1 )
{
putchar(44);
putchar(32);
}
}
}
result = putchar(41);
}
return result;
}

original_code:
void printCallNode(CallNode *p)
{
 ListNode *l;
 if(!p) return;
 printf("%s(", p->id);
 for(l = p->exp; l; l = l->next)
 {
  if(l != p->exp)
  {
   printf(",");
   printf(" ");
  }
  printExpNode((ExpNode*)l->data);
 }
 printf(")");
}

canonical_original_code:
void printCallNode(struct CallNode *p)
{
 struct ListNode *l;
 if(!p) return;
 printf("%s(", p->id);
 for(l = p->exp; l; l = l->next)
 {
  if(l != p->exp)
  {
   printf(",");
   printf(" ");
  }
  printExpNode((struct ExpNode *)l->data);
 }
 printf(")");
}

variable_types: struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *