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

if ( !*(_DWORD *)(a1 + 28) && (*(_BYTE *)(a1 + 16) & 6) == 0 && layout_rule != a1 )
{
result = *(unsigned int *)(a1 + 72);
if ( (_DWORD)result )
*(_DWORD *)(a1 + 36) = 1;
}
return result;
}

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

if ( !*(_DWORD *)(a1 + 28) && (*(_BYTE *)(a1 + 16) & 6) == 0 && layout_rule != a1 )
{
result = *(unsigned int *)(a1 + 72);
if ( (_DWORD)result )
*(_DWORD *)(a1 + 36) = 1;
}
return result;
}

original_code:
static void decide_placeholder_rule (rule srule)
 { if (srule -> ext) return;
   if (srule -> kind & 2) return;
   if (srule -> kind & 4) return;
   if (srule == layout_rule) return;
   if (!srule -> reachable) return;
   srule -> placeholder = 1;
 }

canonical_original_code:
static void decide_placeholder_rule(struct rule_rec *srule)
 { if (srule -> ext) return;
   if (srule -> kind & 2) return;
   if (srule -> kind & 4) return;
   if (srule == layout_rule) return;
   if (!srule -> reachable) return;
   srule -> placeholder = 1;
 }

variable_types: struct rule_rec { char *nonterminal; struct alt_list_rec { int size; int room; struct alt_rec { struct pos_list_rec { int size; int room; struct pos_rec { int kind; struct expr_rec { int tag; union { struct affix_rec { char *name; int type; struct affix_rec *next; struct value_rec { int admin_nr; int ref_count; void *dptr; int tag; union { char *str; int inum; double rnum; struct value_list_rec { int size; int room; struct value_rec **array; } *tuple; int slat; struct int_list_rec { int size; int room; int *array; } *elat; struct value_rec *free; } u; } *val; int ref_count; int reachable; int tag; union { struct variable_rec { char *nonterminal; char *suffix; struct meta_rule_rec { char *nonterminal; struct meta_alt_list_rec { int size; int room; struct meta_alt_rec { struct expr_rec *e; int number; } **array; } *alts; int ext; int type; int kind; int empty; int number; struct value_rec *mvalue; int reachable; struct element_def_rec { char *eltnm; int number; int eltnr; struct element_set_rec { int number; struct element_def_list_rec { int size; int room; struct element_def_rec **array; } *defs; } *set; } *lat_repr; int needs_rec; int needs_recbup; } *def; } var; char *str; int inum; double rnum; struct cset_rec { int kind; char *str; } *semi; struct element_rec { char *eltnm; struct element_def_rec *def; } elt; struct expr_rec *cexpr; } u; } *single; struct affix_list_rec { int size; int room; struct affix_rec **array; } *compos; struct affix_list_rec *concat; struct affix_list_rec *uni; } u; } *ex; int type; struct element_def_rec *lat_repr; } **array; } *display; struct member_list_rec { int size; int room; struct member_rec { int empty; int followlayout; char *first; int number; int sonnr; int tag; union { struct call_rec { char *nonterminal; struct pos_list_rec *display; struct rule_rec *def; } call; char *terminal; struct semiterminal_rec { struct cset_rec *set; struct pos_list_rec *display; } semi; } u; } **array; } *members; int number; int nodenr; int nrsons; struct affix_rec *locals; int empty; char *first; char *director; int rule_nr; } **array; } *alts; int kind; int empty; int lex; int ext; int number; int placeholder; int startswithlayout; int endsinlayout; char *first; char *follow; struct pos_list_rec *proto_display; int reachable; int has_sons; int goal; struct lextree_rec { char *remainder; struct lexend_list_rec { int size; int room; struct lexend_rec { int nodenr; struct int_list_rec *valuenrs; } **array; } *prods; struct lextree_list_rec { int size; int room; struct lextree_rec **array; } *tails; } *rev_tree; } *

user_defined_types: struct rule_rec { char *nonterminal; struct alt_list_rec *alts; int kind; int empty; int lex; int ext; int number; int placeholder; int startswithlayout; int endsinlayout; char *first; char *follow; struct pos_list_rec *proto_display; int reachable; int has_sons; int goal; struct lextree_rec *rev_tree; }

user_defined_types: struct alt_list_rec { int size; int room; struct alt_rec **array; }

user_defined_types: struct lextree_rec { char *remainder; struct lexend_list_rec *prods; struct lextree_list_rec *tails; }

user_defined_types: struct lexend_list_rec { int size; int room; struct lexend_rec **array; }

user_defined_types: struct pos_list_rec { int size; int room; struct pos_rec **array; }

user_defined_types: struct pos_rec { int kind; struct expr_rec *ex; int type; struct element_def_rec *lat_repr; }

user_defined_types: struct member_rec { int empty; int followlayout; char *first; int number; int sonnr; int tag; union { struct call_rec call; char *terminal; struct semiterminal_rec semi; } u; }

user_defined_types: struct variable_rec { char *nonterminal; char *suffix; struct meta_rule_rec *def; }

user_defined_types: struct meta_alt_list_rec { int size; int room; struct meta_alt_rec **array; }

user_defined_types: struct element_def_rec { char *eltnm; int number; int eltnr; struct element_set_rec *set; }

user_defined_types: struct element_set_rec { int number; struct element_def_list_rec *defs; }


repo: tjordanchat/eag

decompiled_code:
__int64 decide_placeholders()
{
__int64 result; // rax
__int64 v1; // rcx

result = nr_of_rules;
if ( nr_of_rules > 0 )
{
v1 = 0LL;
do
result = decide_placeholder_rule(*(_QWORD *)(all_rules + 8 * v1));
while ( nr_of_rules > (int)v1 );
}
return result;
}

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

result = nr_of_rules;
if ( nr_of_rules > 0 )
{
v1 = 0LL;
do
result = func0(*(_QWORD *)(all_rules + 8 * v1));
while ( nr_of_rules > (int)v1 );
}
return result;
}

original_code:
void decide_placeholders ()
 { int ix;
   for (ix = 0; ix < nr_of_rules; ix++)
      decide_placeholder_rule (all_rules[ix]);
 }

canonical_original_code:
void decide_placeholders()
 { int ix;
   for (ix = 0; ix < nr_of_rules; ix++)
      decide_placeholder_rule (all_rules[ix]);
 }

variable_types: ix int

return_type: void


decompiled_code:
__int64 __fastcall scan_integer_value(int *a1, __int64 a2, const char *a3, int *a4)
{
int v4; // eax
__int64 result; // rax
const char *v7; // rdx

v4 = *a1 + 1;
*a1 = v4;
if ( v4 == (_DWORD)a2 )
syntax_error((int)"missing integer argument", a2, a3);
result = strtol(*(const char **)&a3[8 * v4], 0LL, 0);
if ( (int)result <= 0 )
syntax_error((int)"illegal value", 0LL, v7);
if ( *a4 >= 0 && *a4 >= (int)result )
return warning("specified value < default value, no effect");
*a4 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2, const char *a3, int *a4)
{
int v4; // eax
__int64 result; // rax
const char *v7; // rdx

v4 = *a1 + 1;
*a1 = v4;
if ( v4 == (_DWORD)a2 )
func2((int)"missing integer argument", a2, a3);
result = strtol(*(const char **)&a3[8 * v4], 0LL, 0);
if ( (int)result <= 0 )
func2((int)"illegal value", 0LL, v7);
if ( *a4 >= 0 && *a4 >= (int)result )
return warning("specified value < default value, no effect");
*a4 = result;
return result;
}

original_code:
static void scan_integer_value (int *i, int argc, char **argv, int *trgt)
 { int value;
   *i += 1;
   if (*i == argc) syntax_error ("missing integer argument");
   value = strtol (argv[*i], (char **)((void *)0), 0);
   if (value <= 0) syntax_error ("illegal value");
   if (*trgt < 0) *trgt = value;
   else if (value > *trgt) *trgt = value;
   else warning ("specified value < default value, no effect");
 }

canonical_original_code:
static void scan_integer_value(int *i, int argc, char **argv, int *trgt)
 { int value;
   *i += 1;
   if (*i == argc) syntax_error ("missing integer argument");
   value = strtol (argv[*i], (char **)((void *)0), 0);
   if (value <= 0) syntax_error ("illegal value");
   if (*trgt < 0) *trgt = value;
   else if (value > *trgt) *trgt = value;
   else warning ("specified value < default value, no effect");
 }

variable_types:
i
int *

variable_types: argc int

variable_types:
argv
char **

variable_types:
trgt
int *

variable_types: value int


canonical_decompiled_code:
void func0()
{
strstore_size = 100000;
tstack_size = 10000;
qstack_size = 100000;
pbuffer_size = 100000;
ubuffer_size = 100000;
max_nr_parses = -1;
}

original_code:
static void init_options ()
 { strstore_size = 100000;
   tstack_size = 10000;
   qstack_size = 100000;
   pbuffer_size = 100000;
   ubuffer_size = 100000;
   max_nr_parses = -1;
 }

canonical_original_code:
static void init_options()
 { strstore_size = 100000;
   tstack_size = 10000;
   qstack_size = 100000;
   pbuffer_size = 100000;
   ubuffer_size = 100000;
   max_nr_parses = -1;
 }


decompiled_code:
void __noreturn print_usage()
{
wlog("usage: transducer [flags] [filename]");
wlog("or: editor [flags] [Xtoolkitoptions] [filename]");
wlog("-h: provide this help");
wlog("-v: verbose");
wlog("-db: enable debugging");
wlog("-fv: full verbose");
wlog("-ps [size]: use size as parse buffer size");
wlog("-qs [size]: use size as continuation stack size");
wlog("-ss [size]: use size as string store size");
wlog("-ts [size]: use size as tree stack size");
wlog("-us [size]: use size as unparse buffer size (editor only)");
wlog("-P number: maximum number of parses");
exit(4);
}

canonical_decompiled_code:
void __noreturn func1()
{
wlog("usage: transducer [flags] [filename]");
wlog("or: editor [flags] [Xtoolkitoptions] [filename]");
wlog("-h: provide this help");
wlog("-v: verbose");
wlog("-db: enable debugging");
wlog("-fv: full verbose");
wlog("-ps [size]: use size as parse buffer size");
wlog("-qs [size]: use size as continuation stack size");
wlog("-ss [size]: use size as string store size");
wlog("-ts [size]: use size as tree stack size");
wlog("-us [size]: use size as unparse buffer size (editor only)");
wlog("-P number: maximum number of parses");
exit(4);
}

original_code:
static void print_usage ()
 { wlog ("usage: transducer [flags] [filename]");
   wlog ("or:    editor [flags] [Xtoolkitoptions] [filename]");
   wlog ("-h:  provide this help");
   wlog ("-v:  verbose");
   wlog ("-db: enable debugging");
   wlog ("-fv: full verbose");
   wlog ("-ps [size]: use size as parse buffer size");
   wlog ("-qs [size]: use size as continuation stack size");
   wlog ("-ss [size]: use size as string store size");
   wlog ("-ts [size]: use size as tree stack size");
   wlog ("-us [size]: use size as unparse buffer size (editor only)");
   wlog ("-P number:  maximum number of parses");
   exit (4);
 }

canonical_original_code:
static void print_usage()
 { wlog ("usage: transducer [flags] [filename]");
   wlog ("or:    editor [flags] [Xtoolkitoptions] [filename]");
   wlog ("-h:  provide this help");
   wlog ("-v:  verbose");
   wlog ("-db: enable debugging");
   wlog ("-fv: full verbose");
   wlog ("-ps [size]: use size as parse buffer size");
   wlog ("-qs [size]: use size as continuation stack size");
   wlog ("-ss [size]: use size as string store size");
   wlog ("-ts [size]: use size as tree stack size");
   wlog ("-us [size]: use size as unparse buffer size (editor only)");
   wlog ("-P number:  maximum number of parses");
   exit (4);
 }


decompiled_code:
void __fastcall __noreturn syntax_error(int errnum, __int64 a2, const char *a3)
{
error((int)"error on command line: %s", errnum, a3);
print_usage();
}

canonical_decompiled_code:
void __fastcall __noreturn func2(int errnum, __int64 a2, const char *a3)
{
error((int)"error on command line: %s", errnum, a3);
func1();
}

original_code:
static void syntax_error (string error_string)
 { error ("error on command line: %s", error_string);
   print_usage ();
 }

canonical_original_code:
static void syntax_error(char *error_string)
 { error ("error on command line: %s", error_string);
   print_usage ();
 }


warshall

original_code:
char *warshall (int n, char *rel)
 { char *result = (char *) ckcalloc (n*n, sizeof (char));
   int i,j,k;
   for (i=0; i<n; i++)
      for (j=0; j<n; j++) result[i * n + j] = rel[i * n + j];
   for (k=0; k<n; k++)
      for (i=0; i<n; i++)
  for (j=0; j<n; j++)
     result[i * n + j] = result[i * n + j] ||
   (result[i * n + k] && result [k * n + j]);
   return (result);
 }

canonical_original_code:
char *warshall(int n, char *rel)
 { char *result = (char *) ckcalloc (n*n, sizeof (char));
   int i; int j; int k;
   for (i=0; i<n; i++)
      for (j=0; j<n; j++) result[i * n + j] = rel[i * n + j];
   for (k=0; k<n; k++)
      for (i=0; i<n; i++)
  for (j=0; j<n; j++)
     result[i * n + j] = result[i * n + j] ||
   (result[i * n + k] && result [k * n + j]);
   return (result);
 }

variable_types: n int

variable_types:
rel
char *

variable_types:
result
char *

variable_types: i int

variable_types: j int

variable_types: k int

return_type: char *


decompiled_code:
__int64 __fastcall hmac_init(void *src, size_t n)
{
__int64 i; // rax

g_k_opad = 0LL;
xmmword_130 = 0LL;
xmmword_140 = 0LL;
xmmword_150 = 0LL;
if ( n <= 0x40 )
{
memcpy(&g_k_opad, src, n);
}
else
{
hash_init();
hash_update(src, n);
hash_final(&g_k_opad);
}
hash_init();
for ( i = 0LL; i != 64; ++i )
*((_BYTE *)&g_k_opad + i) ^= 0x36u;
return hash_update(&g_k_opad, 64LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src, size_t n)
{
__int64 i; // rax

g_k_opad = 0LL;
xmmword_130 = 0LL;
xmmword_140 = 0LL;
xmmword_150 = 0LL;
if ( n <= 0x40 )
{
memcpy(&g_k_opad, src, n);
}
else
{
hash_init();
hash_update(src, n);
hash_final(&g_k_opad);
}
hash_init();
for ( i = 0LL; i != 64; ++i )
*((_BYTE *)&g_k_opad + i) ^= 0x36u;
return hash_update(&g_k_opad, 64LL);
}

original_code:
void hmac_init(const void* key, size_t key_len)
{
  memset(g_k_opad, 0, sizeof(g_k_opad));
  if (key_len > sizeof(g_k_opad)) {
    hash_init();
    hash_update(key, key_len);
    hash_final(g_k_opad);
  } else {
    memcpy(g_k_opad, key, key_len);
  }
  hash_init();
  for (size_t n = 0; n < sizeof(g_k_opad); ++n) {
    g_k_opad[n] ^= 0x36;
  }
  hash_update(g_k_opad, sizeof(g_k_opad));
}

canonical_original_code:
void hmac_init(void *key, unsigned long key_len)
{
  memset(g_k_opad, 0, sizeof(g_k_opad));
  if (key_len > sizeof(g_k_opad)) {
    hash_init();
    hash_update(key, key_len);
    hash_final(g_k_opad);
  } else {
    memcpy(g_k_opad, key, key_len);
  }
  hash_init();
  for (unsigned long n = 0; n < sizeof(g_k_opad); ++n) {
    g_k_opad[n] ^= 0x36;
  }
  hash_update(g_k_opad, sizeof(g_k_opad));
}

variable_types:
key
void *

variable_types:
n
unsigned long


decompiled_code:
// attributes: thunk
__int64 __fastcall hmac_update(__int64 a1, __int64 a2)
{
return hash_update(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return hash_update(a1, a2);
}

original_code:
void hmac_update(const uint8_t *msg, size_t len)
{
  hash_update(msg, len);
}

canonical_original_code:
void hmac_update(unsigned char *msg, unsigned long len)
{
  hash_update(msg, len);
}

variable_types:
msg
unsigned char *

variable_types:
len
unsigned long


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

hash_final(a1);
hash_init();
for ( i = 0LL; i != 64; ++i )
*((_BYTE *)&g_k_opad + i) ^= 0x6Au;
hash_update(a1, 20LL);
result = hash_final(a1);
g_k_opad = 0LL;
xmmword_130 = 0LL;
xmmword_140 = 0LL;
xmmword_150 = 0LL;
return result;
}

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

hash_final(a1);
hash_init();
for ( i = 0LL; i != 64; ++i )
*((_BYTE *)&g_k_opad + i) ^= 0x6Au;
hash_update(a1, 20LL);
result = hash_final(a1);
g_k_opad = 0LL;
xmmword_130 = 0LL;
xmmword_140 = 0LL;
xmmword_150 = 0LL;
return result;
}

original_code:
void hmac_final(uint8_t hmac[20])
{
  hash_final(hmac);
  hash_init();
  for (size_t n = 0; n < sizeof(g_k_opad); ++n) {
    g_k_opad[n] ^= (0x36 ^ 0x5C);
  }
  hash_update(hmac, 20);
  hash_final(hmac);
  memset(g_k_opad, 0, sizeof(g_k_opad));
}

canonical_original_code:
void hmac_final(unsigned char hmac[20])
{
  hash_final(hmac);
  hash_init();
  for (unsigned long n = 0; n < sizeof(g_k_opad); ++n) {
    g_k_opad[n] ^= (0x36 ^ 0x5C);
  }
  hash_update(hmac, 20);
  hash_final(hmac);
  memset(g_k_opad, 0, sizeof(g_k_opad));
}

variable_types:
hmac
unsigned char [20]


decompiled_code:
__int64 __fastcall sha1_f(unsigned __int8 a1, int a2, unsigned int a3, int a4)
{
if ( a1 <= 0x13u )
return a4 ^ a2 & (a4 ^ a3);
if ( (unsigned __int8)(a1 - 40) > 0x13u )
return a2 ^ a4 ^ a3;
return a4 & a3 | a2 & (a4 | a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, int a2, unsigned int a3, int a4)
{
if ( a1 <= 0x13u )
return a4 ^ a2 & (a4 ^ a3);
if ( (unsigned __int8)(a1 - 40) > 0x13u )
return a2 ^ a4 ^ a3;
return a4 & a3 | a2 & (a4 | a3);
}

original_code:
static uint32_t sha1_f(uint8_t t, uint32_t B, uint32_t C, uint32_t D)
{
  if (t <= 19) {
    return (B & C) | (~B & D);
  } else if (t <= 39) {
    return B ^ C ^ D;
  } else if (t <= 59) {
    return (B & C) | (B & D) | (C & D);
  } else {
    return B ^ C ^ D;
  }
}

canonical_original_code:
static unsigned int sha1_f(unsigned char t, unsigned int B, unsigned int C, unsigned int D)
{
  if (t <= 19) {
    return (B & C) | (~B & D);
  } else if (t <= 39) {
    return B ^ C ^ D;
  } else if (t <= 59) {
    return (B & C) | (B & D) | (C & D);
  } else {
    return B ^ C ^ D;
  }
}

variable_types:
t
unsigned char

variable_types:
B
unsigned int

variable_types:
C
unsigned int

variable_types:
D
unsigned int

return_type: unsigned int


original_code:
static uint32_t sha1_K(uint8_t t)
{
  if(t <= 19) {
    return 0x5A827999;
  } else if (t <= 39) {
    return 0x6ED9EBA1;
  } else if (t <= 59) {
    return 0x8F1BBCDC;
  } else {
    return 0xCA62C1D6;
  }
}

canonical_original_code:
static unsigned int sha1_K(unsigned char t)
{
  if(t <= 19) {
    return 0x5A827999;
  } else if (t <= 39) {
    return 0x6ED9EBA1;
  } else if (t <= 59) {
    return 0x8F1BBCDC;
  } else {
    return 0xCA62C1D6;
  }
}


decompiled_code:
__int64 sha1_padding()
{
char v0; // al
unsigned __int8 v1; // cl
__int64 v2; // rsi
__int64 v3; // rax
char *v4; // rdx
unsigned __int64 v5; // rcx
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // edx
__int64 v9; // rsi
int v10; // eax
int v11; // edx
int v12; // edx
unsigned __int8 v13; // cl
__int64 result; // rax
int v15; // edx
unsigned __int8 v16; // dl
__int64 v17; // rax
__int64 v18; // rdx
char *v19; // rcx
unsigned __int8 v20; // dl
__int64 v21; // rax
char *v22; // rcx
unsigned __int64 v23; // rsi
unsigned int v24; // edx
unsigned int v25; // edx
unsigned int v26; // eax
__int64 v27; // rcx

v0 = byte_748;
v1 = byte_748 + 1;
if ( (unsigned __int8)byte_748 <= 0x36u )
{
byte_708[(unsigned __int8)byte_748] = 0x80;
v2 = v1 + 104LL;
v3 = (unsigned __int8)(55 - v0);
v4 = &byte_708[v1];
if ( (unsigned int)v3 < 8 )
{
if ( (v3 & 4) != 0 )
{
*(_DWORD *)((char *)&g_sha1 + v2) = 0;
*(_DWORD *)&v4[v3 - 4] = 0;
}
else if ( (_DWORD)v3 )
{
*((_BYTE *)&g_sha1 + v2) = 0;
if ( (v3 & 2) != 0 )
*(_WORD *)&v4[v3 - 2] = 0;
}
}
else
{
*(__int64 *)((char *)&g_sha1 + v2) = 0LL;
*(_QWORD *)&v4[v3 - 8] = 0LL;
v5 = (unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL;
v6 = ((_DWORD)v4 - v5 + v3) & 0xFFFFFFF8;
if ( v6 >= 8 )
{
v7 = v6 & 0xFFFFFFF8;
v8 = 0;
do
{
v9 = v8;
v8 += 8;
*(_QWORD *)(v5 + v9) = 0LL;
}
while ( v8 < v7 );
}
}
goto LABEL_6;
}
v15 = (unsigned __int8)byte_748++;
byte_708[v15] = 0x80;
if ( v1 <= 0x3Fu )
{
v16 = 62 - v0;
v17 = (unsigned __int8)(v0 + 105);
v18 = v16 + 1LL;
v19 = (char *)&g_sha1 + v17;
if ( (unsigned int)v18 >= 8 )
{
*(__int64 *)((char *)&g_sha1 + v17) = 0LL;
*(_QWORD *)&v19[v18 - 8] = 0LL;
memset(
(void *)((unsigned __int64)(v19 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v18 + (_DWORD)v19 - (((_DWORD)v19 + 8) & 0xFFFFFFF8)) >> 3));
byte_748 = 64;
}
else
{
if ( (v18 & 4) != 0 )
{
*(_DWORD *)((char *)&g_sha1 + v17) = 0;
*(_DWORD *)&v19[v18 - 4] = 0;
}
else if ( (_DWORD)v18 )
{
*((_BYTE *)&g_sha1 + v17) = 0;
if ( (v18 & 2) != 0 )
*(_WORD *)&v19[v18 - 2] = 0;
}
byte_748 = 64;
}
}
sha1_process_isra_0();
v10 = (unsigned __int8)byte_748;
if ( (unsigned __int8)byte_748 <= 0x37u )
{
v20 = 56 - byte_748;
v21 = (unsigned __int8)(byte_748 + 104);
v22 = (char *)&g_sha1 + v21;
if ( (unsigned __int8)(56 - byte_748) < 8u )
{
if ( (v20 & 4) != 0 )
{
*(_DWORD *)((char *)&g_sha1 + v21) = 0;
*(_DWORD *)&v22[v20 - 4] = 0;
}
else if ( v20 )
{
*((_BYTE *)&g_sha1 + v21) = 0;
if ( (v20 & 2) != 0 )
*(_WORD *)&v22[v20 - 2] = 0;
}
goto LABEL_6;
}
*(__int64 *)((char *)&g_sha1 + v21) = 0LL;
*(_QWORD *)&v22[v20 - 8] = 0LL;
v23 = (unsigned __int64)(v22 + 8) & 0xFFFFFFFFFFFFFFF8LL;
v24 = ((_DWORD)v22 - v23 + v20) & 0xFFFFFFF8;
if ( v24 < 8 )
{
LABEL_6:
v10 = 56;
goto LABEL_7;
}
v25 = v24 & 0xFFFFFFF8;
v26 = 0;
do
{
v27 = v26;
v26 += 8;
*(_QWORD *)(v23 + v27) = 0LL;
}
while ( v26 < v25 );
v10 = 56;
}
LABEL_7:
v11 = dword_74C;
byte_708[(unsigned __int8)v10] = HIBYTE(dword_74C);
byte_708[(unsigned __int8)(v10 + 1)] = BYTE2(v11);
byte_708[(unsigned __int8)(v10 + 2)] = BYTE1(v11);
byte_708[(unsigned __int8)(v10 + 3)] = v11;
v12 = dword_750;
byte_708[(unsigned __int8)(v10 + 4)] = HIBYTE(dword_750);
byte_708[(unsigned __int8)(v10 + 5)] = BYTE2(v12);
byte_708[(unsigned __int8)(v10 + 6)] = BYTE1(v12);
v13 = v10 + 7;
result = (unsigned int)(v10 + 8);
byte_748 = result;
byte_708[v13] = v12;
return result;
}

original_code:
static void sha1_padding(void)
{
  uint8_t temp;
  if(g_sha1.msg_idx + 1 + 8 < 64 ) {
      g_sha1.msg[g_sha1.msg_idx++] = 0x80;
      while(g_sha1.msg_idx <= 55) {
          g_sha1.msg[g_sha1.msg_idx++] = 0x00;
      }
  } else {
      g_sha1.msg[g_sha1.msg_idx++] = 0x80;
      while(g_sha1.msg_idx <= 63) {
          g_sha1.msg[g_sha1.msg_idx++] = 0x00;
      }
      sha1_process();
      while(g_sha1.msg_idx <= 55) {
          g_sha1.msg[g_sha1.msg_idx++] = 0x00;
      }
  }
  temp = 4;
  do {
      temp--;
      g_sha1.msg[g_sha1.msg_idx++] = (g_sha1.len_upper >> 8*temp) & 0xFF;
  } while(temp != 0 );
  temp = 4;
  do {
      temp--;
      g_sha1.msg[g_sha1.msg_idx++] = (g_sha1.len_lower >> 8*temp) & 0xFF;
  } while (temp != 0 );
}

canonical_original_code:
static void sha1_padding()
{
  unsigned char temp;
  if(g_sha1.msg_idx + 1 + 8 < 64 ) {
      g_sha1.msg[g_sha1.msg_idx++] = 0x80;
      while(g_sha1.msg_idx <= 55) {
          g_sha1.msg[g_sha1.msg_idx++] = 0x00;
      }
  } else {
      g_sha1.msg[g_sha1.msg_idx++] = 0x80;
      while(g_sha1.msg_idx <= 63) {
          g_sha1.msg[g_sha1.msg_idx++] = 0x00;
      }
      sha1_process();
      while(g_sha1.msg_idx <= 55) {
          g_sha1.msg[g_sha1.msg_idx++] = 0x00;
      }
  }
  temp = 4;
  do {
      temp--;
      g_sha1.msg[g_sha1.msg_idx++] = (g_sha1.len_upper >> 8*temp) & 0xFF;
  } while(temp != 0 );
  temp = 4;
  do {
      temp--;
      g_sha1.msg[g_sha1.msg_idx++] = (g_sha1.len_lower >> 8*temp) & 0xFF;
  } while (temp != 0 );
}

variable_types:
temp
unsigned char


decompiled_code:
__int64 __fastcall sha1_input(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
__int64 result; // rax
char v5; // dl
char v6; // cl
bool v7; // zf

if ( a2 )
{
v2 = a1 + a2;
v3 = a1;
do
{
while ( 1 )
{
result = (unsigned __int8)byte_748;
++v3;
v5 = ++byte_748;
v6 = *(_BYTE *)(v3 - 1);
v7 = dword_750 == -8;
dword_750 += 8;
byte_708[result] = v6;
if ( v7 )
dword_74C += 8;
if ( v5 == 64 )
break;
if ( v2 == v3 )
return result;
}
result = sha1_process_isra_0();
}
while ( v2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
__int64 result; // rax
char v5; // dl
char v6; // cl
bool v7; // zf

if ( a2 )
{
v2 = a1 + a2;
v3 = a1;
do
{
while ( 1 )
{
result = (unsigned __int8)byte_748;
++v3;
v5 = ++byte_748;
v6 = *(_BYTE *)(v3 - 1);
v7 = dword_750 == -8;
dword_750 += 8;
byte_708[result] = v6;
if ( v7 )
dword_74C += 8;
if ( v5 == 64 )
break;
if ( v2 == v3 )
return result;
}
result = func3();
}
while ( v2 != v3 );
}
return result;
}

original_code:
static void sha1_input( const uint8_t *msg, unsigned int len)
{
    while (len--) {
        g_sha1.msg[g_sha1.msg_idx++] = *msg++;
        g_sha1.len_lower += 8;
        if(g_sha1.len_lower == 0) {
            g_sha1.len_upper += 8;
        }
        if(g_sha1.msg_idx == 64) {
            sha1_process();
        }
    }
}

canonical_original_code:
static void sha1_input(unsigned char *msg, unsigned int len)
{
    while (len--) {
        g_sha1.msg[g_sha1.msg_idx++] = *msg++;
        g_sha1.len_lower += 8;
        if(g_sha1.len_lower == 0) {
            g_sha1.len_upper += 8;
        }
        if(g_sha1.msg_idx == 64) {
            sha1_process();
        }
    }
}

variable_types:
len
unsigned int


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

memset(&dword_6B0, 0, 0xA0uLL);
dword_6B0 = -1009589776;
g_sha1 = 0xEFCDAB8967452301LL;
result = 0x1032547698BADCFELL;
qword_6A8 = 0x1032547698BADCFELL;
*(&dword_6B0 + 40) = 0;
return result;
}

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

memset(&dword_6B0, 0, 0xA0uLL);
dword_6B0 = -1009589776;
g_sha1 = 0xEFCDAB8967452301LL;
result = 0x1032547698BADCFELL;
qword_6A8 = 0x1032547698BADCFELL;
*(&dword_6B0 + 40) = 0;
return result;
}


decompiled_code:
__int64 __fastcall hash_update(__int64 a1, unsigned __int64 a2)
{
__int64 v4; // rbp
__int64 v5; // rdi
__int64 result; // rax

do
{
v4 = 64LL;
v5 = a1;
if ( a2 <= 0x40 )
v4 = a2;
a1 += v4;
result = sha1_input(v5, v4);
a2 -= v4;
}
while ( a2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int64 a2)
{
__int64 v4; // rbp
__int64 v5; // rdi
__int64 result; // rax

do
{
v4 = 64LL;
v5 = a1;
if ( a2 <= 0x40 )
v4 = a2;
a1 += v4;
result = func5(v5, v4);
a2 -= v4;
}
while ( a2 );
return result;
}

original_code:
void hash_update(const uint8_t *msg, size_t len)
{
    do {
        size_t block_len = (len > 64)? 64 : len;
        sha1_input(msg, block_len);
        msg += block_len;
        len -= block_len;
    } while (len > 0);
}

canonical_original_code:
void hash_update(unsigned char *msg, unsigned long len)
{
    do {
        unsigned long block_len = (len > 64)? 64 : len;
        sha1_input(msg, block_len);
        msg += block_len;
        len -= block_len;
    } while (len > 0);
}


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

sha1_padding();
sha1_process_isra_0();
for ( i = 0LL; i != 20; i += 4LL )
{
*(_BYTE *)(a1 + i) = *((_BYTE *)&g_sha1 + i + 3);
*(_BYTE *)(a1 + i + 1) = *(_WORD *)((char *)&g_sha1 + i + 2);
*(_BYTE *)(a1 + i + 2) = BYTE1(*(_DWORD *)((char *)&g_sha1 + i));
*(_BYTE *)(a1 + i + 3) = *(_DWORD *)((char *)&g_sha1 + i);
}
result = 0LL;
memset(&g_sha1, 0, 0xB0uLL);
*((_DWORD *)&g_sha1 + 44) = 0;
return result;
}

original_code:
void hash_final(uint8_t digest[20])
{
    sha1_padding();
    sha1_process();
    uint8_t *dst = digest;
    for (uint8_t i = 0; i < 5; i++) {
        *dst++ = g_sha1.H[i] >> 24;
        *dst++ = g_sha1.H[i] >> 16;
        *dst++ = g_sha1.H[i] >> 8;
        *dst++ = g_sha1.H[i];
    }
    memset(&g_sha1, 0, sizeof(g_sha1));
}

canonical_original_code:
void hash_final(unsigned char digest[20])
{
    sha1_padding();
    sha1_process();
    unsigned char *dst = digest;
    for (unsigned char i = 0; i < 5; i++) {
        *dst++ = g_sha1.H[i] >> 24;
        *dst++ = g_sha1.H[i] >> 16;
        *dst++ = g_sha1.H[i] >> 8;
        *dst++ = g_sha1.H[i];
    }
    memset(&g_sha1, 0, sizeof(g_sha1));
}

variable_types:
digest
unsigned char [20]

variable_types:
dst
unsigned char *

variable_types:
i
unsigned char


delitem

repo: tkln/mcwm

original_code:
void delitem(struct item **mainlist, struct item *item)
{
    struct item *ml = *mainlist;
    if (((void *)0) == mainlist || ((void *)0) == *mainlist || ((void *)0) == item)
    {
        return;
    }
    if (item == *mainlist)
    {
        *mainlist = ml->next;
    }
    else
    {
        item->prev->next = item->next;
        if (((void *)0) != item->next)
        {
            item->next->prev = item->prev;
        }
    }
    free(item);
}

variable_types: struct item { void *data; struct item *prev; struct item *next; } **

variable_types:
item
struct item *


freeitem

decompiled_code:
void __fastcall freeitem(_QWORD *a1, _DWORD *a2, void **a3)
{
if ( a1 && *a1 && a3 )
{
if ( *a3 )
{
free(*a3);
*a3 = 0LL;
}
delitem(a1, a3);
if ( a2 )
--*a2;
}
}

original_code:
void freeitem(struct item **list, int *stored,
              struct item *item)
{
    if (((void *)0) == list || ((void *)0) == *list || ((void *)0) == item)
    {
        return;
    }
    if (((void *)0) != item->data)
    {
        free(item->data);
        item->data = ((void *)0);
    }
    delitem(list, item);
    if (((void *)0) != stored)
    {
        (*stored) --;
    }
}

variable_types:
stored
int *

user_defined_types: struct item { void *data; struct item *prev; struct item *next; }


main

canonical_name: main

repo: tkooda/dvb-pids

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
unsigned int v5; // er13
char *v6; // rdi
unsigned int v7; // ebx
char *v8; // rdi
unsigned int v9; // er14
unsigned int v10; // eax
int v11; // er13
const char **v12; // rbx
const char **v13; // rbp
unsigned int v14; // er12
int result; // eax
char v16[48]; // [rsp+0h] [rbp-88h] BYREF
char s[88]; // [rsp+30h] [rbp-58h] BYREF

if ( argc <= 2 )
{
printf("usage: %s <frequency> <pid> [pid..]\n", *argv);
result = 1;
}
else
{
v4 = getenv("DVB_ADAPTER");
if ( v4 )
v5 = atoi(v4);
else
v5 = 0;
v6 = getenv("DVB_FRONTEND");
if ( v6 )
v7 = atoi(v6);
else
v7 = 0;
v8 = getenv("DVB_DEMUX");
if ( v8 )
v9 = atoi(v8);
else
v9 = 0;
snprintf(v16, 0x20uLL, "/dev/dvb/adapter%d/frontend%d", v5, v7);
snprintf(s, 0x20uLL, "/dev/dvb/adapter%d/demux%d", v5, v9);
printf("frontend: '%s'\n", v16);
printf("demux: '%s'\n", s);
v10 = atoi(argv[1]);
v11 = setup_frontend(v16, v10);
if ( v11 < 0 )
{
fwrite("error: failed setting up frontend\n", 1uLL, 0x22uLL, stderr);
result = 2;
}
else
{
v12 = argv + 2;
v13 = &argv[(unsigned int)(argc - 3) + 3];
while ( 1 )
{
v14 = atoi(*v12);
if ( v14 - 1 > 0x1FFD )
{
fprintf(stderr, "error: pid out of range: %d\n", v14);
return 2;
}
if ( (int)add_pes_filter(s) < 0 )
break;
if ( ++v12 == v13 )
loop_status(v11);
}
fprintf(stderr, "error: failed adding pes filter for pid %d ('%s')\n", v14, *v12);
result = 2;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
unsigned int v5; // er13
char *v6; // rdi
unsigned int v7; // ebx
char *v8; // rdi
unsigned int v9; // er14
unsigned int v10; // eax
int v11; // er13
const char **v12; // rbx
const char **v13; // rbp
unsigned int v14; // er12
int result; // eax
char v16[48]; // [rsp+0h] [rbp-88h] BYREF
char s[88]; // [rsp+30h] [rbp-58h] BYREF

if ( argc <= 2 )
{
printf("usage: %s <frequency> <pid> [pid..]\n", *argv);
result = 1;
}
else
{
v4 = getenv("DVB_ADAPTER");
if ( v4 )
v5 = atoi(v4);
else
v5 = 0;
v6 = getenv("DVB_FRONTEND");
if ( v6 )
v7 = atoi(v6);
else
v7 = 0;
v8 = getenv("DVB_DEMUX");
if ( v8 )
v9 = atoi(v8);
else
v9 = 0;
snprintf(v16, 0x20uLL, "/dev/dvb/adapter%d/frontend%d", v5, v7);
snprintf(s, 0x20uLL, "/dev/dvb/adapter%d/demux%d", v5, v9);
printf("frontend: '%s'\n", v16);
printf("demux: '%s'\n", s);
v10 = atoi(argv[1]);
v11 = func7(v16, v10);
if ( v11 < 0 )
{
fwrite("error: failed setting up frontend\n", 1uLL, 0x22uLL, stderr);
result = 2;
}
else
{
v12 = argv + 2;
v13 = &argv[(unsigned int)(argc - 3) + 3];
while ( 1 )
{
v14 = atoi(*v12);
if ( v14 - 1 > 0x1FFD )
{
fprintf(stderr, "error: pid out of range: %d\n", v14);
return 2;
}
if ( (int)func8(s) < 0 )
break;
if ( ++v12 == v13 )
func9(v11);
}
fprintf(stderr, "error: failed adding pes filter for pid %d ('%s')\n", v14, *v12);
result = 2;
}
}
return result;
}

original_code:
int main( int argc, char **argv ) {
  int id_adapter = 0;
  int id_frontend = 0;
  int id_demux = 0;
  char *env_tmp;
  char dev_frontend[ 33 ];
  char dev_demux[ 33 ];
  __u32 fe_frequency;
  int fd_frontend;
  int pid;
  int i;
  if ( argc < 3 ) {
    printf( "usage: %s <frequency> <pid> [pid..]\n", argv[0] );
    return( 1 );
  }
  env_tmp = getenv( "DVB_ADAPTER" );
  if ( env_tmp ) id_adapter = atoi( env_tmp );
  env_tmp = getenv( "DVB_FRONTEND" );
  if ( env_tmp ) id_frontend = atoi( env_tmp );
  env_tmp = getenv( "DVB_DEMUX" );
  if ( env_tmp ) id_demux = atoi( env_tmp );
  if ( snprintf( dev_frontend, 32, "/dev/dvb/adapter" "%d/frontend%d",
   id_adapter, id_frontend ) <= 0 ) {
    return( 3 );
  }
  if ( snprintf( dev_demux, 32, "/dev/dvb/adapter" "%d/demux%d",
   id_adapter, id_demux ) <= 0 ) {
    return( 3 );
  }
  printf( "frontend: '%s'\n", dev_frontend );
  printf( "demux: '%s'\n", dev_demux );
  fe_frequency = atoi( argv[1] );
  fd_frontend = setup_frontend( dev_frontend, fe_frequency );
  if ( fd_frontend < 0 ) {
    fprintf( stderr, "error: " "failed setting up frontend\n" );
    return( 2 );
  }
  for ( i = 2; i < argc; i++ ) {
    pid = atoi( argv[i] );
    if ( pid <= 0 || pid >= 0x1fff ) {
      fprintf( stderr, "error: " "pid out of range: %d\n", pid );
      return( 2 );
    }
    if ( add_pes_filter( dev_demux, pid ) < 0 ) {
      fprintf( stderr, "error: " "failed adding pes filter for pid %d ('%s')\n",
        pid, argv[i] );
      return( 2 );
    }
  }
  loop_status( fd_frontend );
  return( 0 );
}

canonical_original_code:
int main(int argc, char **argv) {
  int id_adapter = 0;
  int id_frontend = 0;
  int id_demux = 0;
  char *env_tmp;
  char dev_frontend[33];
  char dev_demux[33];
  unsigned int fe_frequency;
  int fd_frontend;
  int pid;
  int i;
  if ( argc < 3 ) {
    printf( "usage: %s <frequency> <pid> [pid..]\n", argv[0] );
    return( 1 );
  }
  env_tmp = getenv( "DVB_ADAPTER" );
  if ( env_tmp ) id_adapter = atoi( env_tmp );
  env_tmp = getenv( "DVB_FRONTEND" );
  if ( env_tmp ) id_frontend = atoi( env_tmp );
  env_tmp = getenv( "DVB_DEMUX" );
  if ( env_tmp ) id_demux = atoi( env_tmp );
  if ( snprintf( dev_frontend, 32, "/dev/dvb/adapter" "%d/frontend%d",
   id_adapter, id_frontend ) <= 0 ) {
    return( 3 );
  }
  if ( snprintf( dev_demux, 32, "/dev/dvb/adapter" "%d/demux%d",
   id_adapter, id_demux ) <= 0 ) {
    return( 3 );
  }
  printf( "frontend: '%s'\n", dev_frontend );
  printf( "demux: '%s'\n", dev_demux );
  fe_frequency = atoi( argv[1] );
  fd_frontend = setup_frontend( dev_frontend, fe_frequency );
  if ( fd_frontend < 0 ) {
    fprintf( stderr, "error: " "failed setting up frontend\n" );
    return( 2 );
  }
  for ( i = 2; i < argc; i++ ) {
    pid = atoi( argv[i] );
    if ( pid <= 0 || pid >= 0x1fff ) {
      fprintf( stderr, "error: " "pid out of range: %d\n", pid );
      return( 2 );
    }
    if ( add_pes_filter( dev_demux, pid ) < 0 ) {
      fprintf( stderr, "error: " "failed adding pes filter for pid %d ('%s')\n",
        pid, argv[i] );
      return( 2 );
    }
  }
  loop_status( fd_frontend );
  return( 0 );
}

variable_types: argc int

variable_types:
argv
char **

variable_types: pid int

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall setup_frontend(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
int v5[18]; // [rsp+0h] [rbp-48h] BYREF

v2 = open(a1, 2);
if ( v2 < 0 )
{
v3 = -1;
fprintf(stderr, "error: failed opening '%s'\n", a1);
}
else
{
v3 = v2;
v5[0] = a2;
v5[2] = 7;
printf("tuning: %i Hz\n", a2);
if ( ioctl(v3, 0x40246F4CuLL, v5) < 0 )
{
v3 = -1;
fwrite("error: ioctl(FE_SET_FRONTEND) failed\n", 1uLL, 0x25uLL, stderr);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
int v5[18]; // [rsp+0h] [rbp-48h] BYREF

v2 = open(a1, 2);
if ( v2 < 0 )
{
v3 = -1;
fprintf(stderr, "error: failed opening '%s'\n", a1);
}
else
{
v3 = v2;
v5[0] = a2;
v5[2] = 7;
printf("tuning: %i Hz\n", a2);
if ( ioctl(v3, 0x40246F4CuLL, v5) < 0 )
{
v3 = -1;
fwrite("error: ioctl(FE_SET_FRONTEND) failed\n", 1uLL, 0x25uLL, stderr);
}
}
return v3;
}

original_code:
int setup_frontend( char *dev_frontend, int fe_frequency ) {
  struct dvb_frontend_parameters fe_params;
  int fd;
  if ( ( fd = open( dev_frontend, 02 ) ) < 0 ) {
    fprintf( stderr, "error: " "failed opening '%s'\n", dev_frontend );
    return( -1 );
  }
  fe_params.frequency = fe_frequency;
  fe_params.u.vsb.modulation = VSB_8;
  printf( "tuning: %i Hz\n", fe_frequency );
  if ( ioctl( fd, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((76)) << 0) | ((((sizeof(struct dvb_frontend_parameters)))) << ((0 +8)+8))), &fe_params ) < 0) {
    fprintf( stderr, "error: " "ioctl(FE_SET_FRONTEND) failed\n" );
    return( -1 );
  }
  return( fd );
}

canonical_original_code:
int setup_frontend(char *dev_frontend, int fe_frequency) {
  struct dvb_frontend_parameters fe_params;
  int fd;
  if ( ( fd = open( dev_frontend, 02 ) ) < 0 ) {
    fprintf( stderr, "error: " "failed opening '%s'\n", dev_frontend );
    return( -1 );
  }
  fe_params.frequency = fe_frequency;
  fe_params.u.vsb.modulation = VSB_8;
  printf( "tuning: %i Hz\n", fe_frequency );
  if ( ioctl( fd, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((76)) << 0) | ((((sizeof(struct dvb_frontend_parameters)))) << ((0 +8)+8))), &fe_params ) < 0) {
    fprintf( stderr, "error: " "ioctl(FE_SET_FRONTEND) failed\n" );
    return( -1 );
  }
  return( fd );
}

variable_types: struct dvb_frontend_parameters { unsigned int frequency; enum fe_spectral_inversion { INVERSION_OFF=0, INVERSION_ON=1, INVERSION_AUTO=2 } inversion; union { struct dvb_qpsk_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; } qpsk; struct dvb_qam_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } qam; struct dvb_ofdm_parameters { enum fe_bandwidth { BANDWIDTH_8_MHZ=0, BANDWIDTH_7_MHZ=1, BANDWIDTH_6_MHZ=2, BANDWIDTH_AUTO=3, BANDWIDTH_5_MHZ=4, BANDWIDTH_10_MHZ=5, BANDWIDTH_1_712_MHZ=6 } bandwidth; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_HP; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_LP; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } constellation; enum fe_transmit_mode { TRANSMISSION_MODE_2K=0, TRANSMISSION_MODE_8K=1, TRANSMISSION_MODE_AUTO=2, TRANSMISSION_MODE_4K=3, TRANSMISSION_MODE_1K=4, TRANSMISSION_MODE_16K=5, TRANSMISSION_MODE_32K=6, TRANSMISSION_MODE_C1=7, TRANSMISSION_MODE_C3780=8 } transmission_mode; enum fe_guard_interval { GUARD_INTERVAL_1_32=0, GUARD_INTERVAL_1_16=1, GUARD_INTERVAL_1_8=2, GUARD_INTERVAL_1_4=3, GUARD_INTERVAL_AUTO=4, GUARD_INTERVAL_1_128=5, GUARD_INTERVAL_19_128=6, GUARD_INTERVAL_19_256=7, GUARD_INTERVAL_PN420=8, GUARD_INTERVAL_PN595=9, GUARD_INTERVAL_PN945=10 } guard_interval; enum fe_hierarchy { HIERARCHY_NONE=0, HIERARCHY_1=1, HIERARCHY_2=2, HIERARCHY_4=3, HIERARCHY_AUTO=4 } hierarchy_information; } ofdm; struct dvb_vsb_parameters { enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } vsb; } u; }

variable_types: fd int

user_defined_types: struct dvb_frontend_parameters { unsigned int frequency; enum fe_spectral_inversion inversion; union { struct dvb_qpsk_parameters qpsk; struct dvb_qam_parameters qam; struct dvb_ofdm_parameters ofdm; struct dvb_vsb_parameters vsb; } u; }

user_defined_types: struct dvb_qpsk_parameters { unsigned int symbol_rate; enum fe_code_rate fec_inner; }

user_defined_types: struct dvb_qam_parameters { unsigned int symbol_rate; enum fe_code_rate fec_inner; enum fe_modulation modulation; }

user_defined_types: struct dvb_ofdm_parameters { enum fe_bandwidth bandwidth; enum fe_code_rate code_rate_HP; enum fe_code_rate code_rate_LP; enum fe_modulation constellation; enum fe_transmit_mode transmission_mode; enum fe_guard_interval guard_interval; enum fe_hierarchy hierarchy_information; }

user_defined_types: struct dvb_vsb_parameters { enum fe_modulation modulation; }


decompiled_code:
__int64 __fastcall add_pes_filter(char *file, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
__int16 v5[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+4h] [rbp-34h]
__int64 v7; // [rsp+Ch] [rbp-2Ch]

printf("adding: pid %d (0x%04x)\n", a2, (unsigned int)a2);
v2 = open(file, 0);
if ( v2 < 0 )
{
v3 = -1;
fprintf(stderr, "error: failed opening '%s'\n", file);
}
else
{
v3 = v2;
v5[0] = a2;
v6 = 0x200000000LL;
v7 = 0x400000014LL;
if ( ioctl(v2, 0x40146F2CuLL, v5) < 0 )
{
v3 = -1;
fprintf(
stderr,
"error: ioctl(DMX_SET_PES_FILTER) for pid %d (0x%04x) failed\n",
(unsigned int)a2,
(unsigned int)a2);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *file, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
__int16 v5[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+4h] [rbp-34h]
__int64 v7; // [rsp+Ch] [rbp-2Ch]

printf("adding: pid %d (0x%04x)\n", a2, (unsigned int)a2);
v2 = open(file, 0);
if ( v2 < 0 )
{
v3 = -1;
fprintf(stderr, "error: failed opening '%s'\n", file);
}
else
{
v3 = v2;
v5[0] = a2;
v6 = 0x200000000LL;
v7 = 0x400000014LL;
if ( ioctl(v2, 0x40146F2CuLL, v5) < 0 )
{
v3 = -1;
fprintf(
stderr,
"error: ioctl(DMX_SET_PES_FILTER) for pid %d (0x%04x) failed\n",
(unsigned int)a2,
(unsigned int)a2);
}
}
return v3;
}

original_code:
int add_pes_filter( char *dev_demux, int pid ) {
  struct dmx_pes_filter_params pes_filter_params;
  int fd;
  printf( "adding: pid %d (0x%04x)\n", pid, pid );
  if ( ( fd = open( dev_demux, 00 ) ) < 0 ) {
    fprintf( stderr, "error: " "failed opening '%s'\n", dev_demux );
    return( -1 );
  }
  pes_filter_params.pid = pid;
  pes_filter_params.input = DMX_IN_FRONTEND;
  pes_filter_params.output = DMX_OUT_TS_TAP;
  pes_filter_params.pes_type = DMX_PES_OTHER;
  pes_filter_params.flags = 4;
  if ( ioctl( fd, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((44)) << 0) | ((((sizeof(struct dmx_pes_filter_params)))) << ((0 +8)+8))), &pes_filter_params ) < 0 ) {
    fprintf( stderr, "error: " "ioctl(DMX_SET_PES_FILTER) for pid "
      "%d (0x%04x) failed\n", pid, pid );
    return( -1 );
  }
  return( fd );
}

canonical_original_code:
int add_pes_filter(char *dev_demux, int pid) {
  struct dmx_pes_filter_params pes_filter_params;
  int fd;
  printf( "adding: pid %d (0x%04x)\n", pid, pid );
  if ( ( fd = open( dev_demux, 00 ) ) < 0 ) {
    fprintf( stderr, "error: " "failed opening '%s'\n", dev_demux );
    return( -1 );
  }
  pes_filter_params.pid = pid;
  pes_filter_params.input = DMX_IN_FRONTEND;
  pes_filter_params.output = DMX_OUT_TS_TAP;
  pes_filter_params.pes_type = DMX_PES_OTHER;
  pes_filter_params.flags = 4;
  if ( ioctl( fd, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((44)) << 0) | ((((sizeof(struct dmx_pes_filter_params)))) << ((0 +8)+8))), &pes_filter_params ) < 0 ) {
    fprintf( stderr, "error: " "ioctl(DMX_SET_PES_FILTER) for pid "
      "%d (0x%04x) failed\n", pid, pid );
    return( -1 );
  }
  return( fd );
}

variable_types: struct dmx_pes_filter_params { unsigned short pid; enum dmx_input { DMX_IN_FRONTEND=0, DMX_IN_DVR=1 } input; enum dmx_output { DMX_OUT_DECODER=0, DMX_OUT_TAP=1, DMX_OUT_TS_TAP=2, DMX_OUT_TSDEMUX_TAP=3 } output; enum dmx_ts_pes { DMX_PES_AUDIO0=0, DMX_PES_VIDEO0=1, DMX_PES_TELETEXT0=2, DMX_PES_SUBTITLE0=3, DMX_PES_PCR0=4, DMX_PES_AUDIO1=5, DMX_PES_VIDEO1=6, DMX_PES_TELETEXT1=7, DMX_PES_SUBTITLE1=8, DMX_PES_PCR1=9, DMX_PES_AUDIO2=10, DMX_PES_VIDEO2=11, DMX_PES_TELETEXT2=12, DMX_PES_SUBTITLE2=13, DMX_PES_PCR2=14, DMX_PES_AUDIO3=15, DMX_PES_VIDEO3=16, DMX_PES_TELETEXT3=17, DMX_PES_SUBTITLE3=18, DMX_PES_PCR3=19, DMX_PES_OTHER=20 } pes_type; unsigned int flags; }

user_defined_types: struct dmx_pes_filter_params { unsigned short pid; enum dmx_input input; enum dmx_output output; enum dmx_ts_pes pes_type; unsigned int flags; }


decompiled_code:
void __fastcall __noreturn loop_status(int fd)
{
int v1; // ebp
char *v2; // rax
const char *v3; // rax
unsigned __int16 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned __int16 v5; // [rsp+2h] [rbp-26h] BYREF
unsigned int v6; // [rsp+4h] [rbp-24h] BYREF
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
unsigned int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 1000000;
v2 = getenv("DVB_STATUS_USECS");
if ( v2 )
{
v1 = atoi(v2);
if ( !v1 )
v1 = 1000000;
}
while ( 1 )
{
ioctl(fd, 0x80046F45uLL, &v6);
ioctl(fd, 0x80026F47uLL, &v5);
ioctl(fd, 0x80026F48uLL, &v4);
ioctl(fd, 0x80046F46uLL, &v7);
ioctl(fd, 0x80046F49uLL, v8);
v3 = "frontend: '%s'\n" + 15;
if ( (v6 & 0x10) != 0 )
v3 = "FE_HAS_LOCK";
printf("status %02x | signal %04x | snr %04x | ber %08x | unc %08x | %s\n", v6, v5, v4, v7, v8[0], v3);
usleep(v1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func9(int fd)
{
int v1; // ebp
char *v2; // rax
const char *v3; // rax
unsigned __int16 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned __int16 v5; // [rsp+2h] [rbp-26h] BYREF
unsigned int v6; // [rsp+4h] [rbp-24h] BYREF
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
unsigned int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 1000000;
v2 = getenv("DVB_STATUS_USECS");
if ( v2 )
{
v1 = atoi(v2);
if ( !v1 )
v1 = 1000000;
}
while ( 1 )
{
ioctl(fd, 0x80046F45uLL, &v6);
ioctl(fd, 0x80026F47uLL, &v5);
ioctl(fd, 0x80026F48uLL, &v4);
ioctl(fd, 0x80046F46uLL, &v7);
ioctl(fd, 0x80046F49uLL, v8);
v3 = "frontend: '%s'\n" + 15;
if ( (v6 & 0x10) != 0 )
v3 = "FE_HAS_LOCK";
printf("status %02x | signal %04x | snr %04x | ber %08x | unc %08x | %s\n", v6, v5, v4, v7, v8[0], v3);
usleep(v1);
}
}

variable_types: enum fe_status { FE_NONE=0, FE_HAS_SIGNAL=1, FE_HAS_CARRIER=2, FE_HAS_VITERBI=4, FE_HAS_SYNC=8, FE_HAS_LOCK=16, FE_TIMEDOUT=32, FE_REINIT=64 }

variable_types:
usecs
unsigned int

variable_types:
i
unsigned int


chmod

repo: tkooda/libchmod

decompiled_code:
__int64 __fastcall chmod(char *name, unsigned int a2)
{
char *v2; // rax
void *v3; // rax
void *v4; // rbp
__int64 (__fastcall *v5)(char *, _QWORD); // rbx
int v7; // eax
char *v8; // rax
char *v9; // r15
__int64 v10; // rax
char *v11; // r15
char *v12; // rax
__int64 v13; // r15
char *nptr; // [rsp+8h] [rbp-10E0h]
__int64 nptra; // [rsp+8h] [rbp-10E0h]
char *nptrb; // [rsp+8h] [rbp-10E0h]
struct stat v17; // [rsp+10h] [rbp-10D8h] BYREF
char resolved[4168]; // [rsp+A0h] [rbp-1048h] BYREF

v2 = getenv("LIBCHMOD_PATH_LIB_ORIG");
if ( !v2 || (v3 = dlopen(v2, 1), (v4 = v3) == 0LL) )
{
LABEL_21:
*__errno_location() = 12;
return 0xFFFFFFFFLL;
}
v5 = (__int64 (__fastcall *)(char *, _QWORD))dlsym(v3, "chmod");
if ( v5 )
{
if ( getenv("LIBCHMOD_PATH_REGEX") )
{
if ( !realpath(name, resolved) )
return 0xFFFFFFFFLL;
if ( !(unsigned int)match(resolved) )
return v5(name, a2);
if ( (unsigned int)stat(resolved, &v17) )
return 0xFFFFFFFFLL;
v7 = v17.st_mode & 0xF000;
if ( v7 == 0x4000 )
{
v11 = getenv("LIBCHMOD_MODE_DIR_ALLOWED");
if ( v11 )
{
v12 = getenv("LIBCHMOD_MODE_DIR_REQUIRED");
if ( v12 )
{
nptrb = v12;
v13 = strtol(v11, 0LL, 8);
v10 = strtol(nptrb, 0LL, 8);
if ( (v13 | a2) == v13 )
{
LABEL_14:
if ( (a2 | (unsigned __int64)v10) == a2 )
return v5(name, a2);
}
LABEL_15:
*__errno_location() = 1;
return 0xFFFFFFFFLL;
}
}
}
else
{
if ( v7 != 0x8000 )
return v5(name, a2);
v8 = getenv("LIBCHMOD_MODE_FILE_ALLOWED");
if ( v8 )
{
nptr = v8;
v9 = getenv("LIBCHMOD_MODE_FILE_REQUIRED");
if ( v9 )
{
nptra = strtol(nptr, 0LL, 8);
v10 = strtol(v9, 0LL, 8);
if ( (nptra | a2) == nptra )
goto LABEL_14;
goto LABEL_15;
}
}
}
}
goto LABEL_21;
}
dlclose(v4);
*__errno_location() = 12;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *name, unsigned int a2)
{
char *v2; // rax
void *v3; // rax
void *v4; // rbp
__int64 (__fastcall *v5)(char *, _QWORD); // rbx
int v7; // eax
char *v8; // rax
char *v9; // r15
__int64 v10; // rax
char *v11; // r15
char *v12; // rax
__int64 v13; // r15
char *nptr; // [rsp+8h] [rbp-10E0h]
__int64 nptra; // [rsp+8h] [rbp-10E0h]
char *nptrb; // [rsp+8h] [rbp-10E0h]
struct stat v17; // [rsp+10h] [rbp-10D8h] BYREF
char resolved[4168]; // [rsp+A0h] [rbp-1048h] BYREF

v2 = getenv("LIBCHMOD_PATH_LIB_ORIG");
if ( !v2 || (v3 = dlopen(v2, 1), (v4 = v3) == 0LL) )
{
LABEL_21:
*__errno_location() = 12;
return 0xFFFFFFFFLL;
}
v5 = (__int64 (__fastcall *)(char *, _QWORD))dlsym(v3, "chmod");
if ( v5 )
{
if ( getenv("LIBCHMOD_PATH_REGEX") )
{
if ( !realpath(name, resolved) )
return 0xFFFFFFFFLL;
if ( !(unsigned int)func6(resolved) )
return v5(name, a2);
if ( (unsigned int)func8(resolved, &v17) )
return 0xFFFFFFFFLL;
v7 = v17.st_mode & 0xF000;
if ( v7 == 0x4000 )
{
v11 = getenv("LIBCHMOD_MODE_DIR_ALLOWED");
if ( v11 )
{
v12 = getenv("LIBCHMOD_MODE_DIR_REQUIRED");
if ( v12 )
{
nptrb = v12;
v13 = strtol(v11, 0LL, 8);
v10 = strtol(nptrb, 0LL, 8);
if ( (v13 | a2) == v13 )
{
LABEL_14:
if ( (a2 | (unsigned __int64)v10) == a2 )
return v5(name, a2);
}
LABEL_15:
*__errno_location() = 1;
return 0xFFFFFFFFLL;
}
}
}
else
{
if ( v7 != 0x8000 )
return v5(name, a2);
v8 = getenv("LIBCHMOD_MODE_FILE_ALLOWED");
if ( v8 )
{
nptr = v8;
v9 = getenv("LIBCHMOD_MODE_FILE_REQUIRED");
if ( v9 )
{
nptra = strtol(nptr, 0LL, 8);
v10 = strtol(v9, 0LL, 8);
if ( (nptra | a2) == nptra )
goto LABEL_14;
goto LABEL_15;
}
}
}
}
goto LABEL_21;
}
dlclose(v4);
*__errno_location() = 12;
return 0xFFFFFFFFLL;
}

original_code:
int chmod(const char *path, mode_t mode)
{
  char *env_path_lib_orig, *env_path_regex;
  void *handle;
  int (*orig_chmod)(const char *path, mode_t mode);
  char resolved_path[4096 +1];
  struct stat st_p;
  char *env_mode_dir_required, *env_mode_dir_allowed, *env_mode_file_required, *env_mode_file_allowed;
  long long_mode_dir_required, long_mode_dir_allowed, long_mode_file_required, long_mode_file_allowed;
  char **endptr;
  long mode_l = mode;
  if ( ( env_path_lib_orig = getenv("LIBCHMOD_PATH_LIB_ORIG") ) == ((void *)0) ) {
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ( handle = dlopen(env_path_lib_orig, 0x00001) ) == ((void *)0) ) {
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ( orig_chmod = dlsym(handle, "chmod") ) == ((void *)0) ) {
    dlclose(handle);
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ( env_path_regex = getenv("LIBCHMOD_PATH_REGEX") ) == ((void *)0) ) {
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ! realpath(path, resolved_path) ) {
    return((-1));
  }
  if ( ! match(resolved_path, env_path_regex) ) {
    return orig_chmod(path, mode);
  }
  if ( stat(resolved_path, &st_p ) ) {
    return((-1));
  }
  if ( ((((st_p.st_mode)) & 0170000) == (0040000)) ) {
    if ( ( env_mode_dir_allowed = getenv("LIBCHMOD_MODE_DIR_ALLOWED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    if ( ( env_mode_dir_required = getenv("LIBCHMOD_MODE_DIR_REQUIRED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    long_mode_dir_allowed = strtol( env_mode_dir_allowed, endptr, 8 );
    long_mode_dir_required = strtol( env_mode_dir_required, endptr, 8 );
    if ( ( mode_l | long_mode_dir_allowed ) != long_mode_dir_allowed ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
    if ( ( mode_l | long_mode_dir_required ) != mode_l ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
  } else if ( ((((st_p.st_mode)) & 0170000) == (0100000)) ) {
    if ( ( env_mode_file_allowed = getenv("LIBCHMOD_MODE_FILE_ALLOWED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    if ( ( env_mode_file_required = getenv("LIBCHMOD_MODE_FILE_REQUIRED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    long_mode_file_allowed = strtol( env_mode_file_allowed, endptr, 8 );
    long_mode_file_required = strtol( env_mode_file_required, endptr, 8 );
    if ( ( mode_l | long_mode_file_allowed ) != long_mode_file_allowed ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
    if ( ( mode_l | long_mode_file_required ) != mode_l ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
  }
  return orig_chmod( path, mode );
}

canonical_original_code:
int chmod(char *path, unsigned int mode)
{
  char *env_path_lib_orig; char *env_path_regex;
  void *handle;
  int (*orig_chmod)(char *path, unsigned int mode);
  char resolved_path[-1];
  struct stat st_p;
  char *env_mode_dir_required; char *env_mode_dir_allowed; char *env_mode_file_required; char *env_mode_file_allowed;
  long long_mode_dir_required; long long_mode_dir_allowed; long long_mode_file_required; long long_mode_file_allowed;
  char **endptr;
  long mode_l = mode;
  if ( ( env_path_lib_orig = getenv("LIBCHMOD_PATH_LIB_ORIG") ) == ((void *)0) ) {
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ( handle = dlopen(env_path_lib_orig, 0x00001) ) == ((void *)0) ) {
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ( orig_chmod = dlsym(handle, "chmod") ) == ((void *)0) ) {
    dlclose(handle);
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ( env_path_regex = getenv("LIBCHMOD_PATH_REGEX") ) == ((void *)0) ) {
    (*__errno_location ()) = 12;
    return((-1));
  }
  if ( ! realpath(path, resolved_path) ) {
    return((-1));
  }
  if ( ! match(resolved_path, env_path_regex) ) {
    return orig_chmod(path, mode);
  }
  if ( stat(resolved_path, &st_p ) ) {
    return((-1));
  }
  if ( ((((st_p.st_mode)) & 0170000) == (0040000)) ) {
    if ( ( env_mode_dir_allowed = getenv("LIBCHMOD_MODE_DIR_ALLOWED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    if ( ( env_mode_dir_required = getenv("LIBCHMOD_MODE_DIR_REQUIRED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    long_mode_dir_allowed = strtol( env_mode_dir_allowed, endptr, 8 );
    long_mode_dir_required = strtol( env_mode_dir_required, endptr, 8 );
    if ( ( mode_l | long_mode_dir_allowed ) != long_mode_dir_allowed ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
    if ( ( mode_l | long_mode_dir_required ) != mode_l ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
  } else if ( ((((st_p.st_mode)) & 0170000) == (0100000)) ) {
    if ( ( env_mode_file_allowed = getenv("LIBCHMOD_MODE_FILE_ALLOWED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    if ( ( env_mode_file_required = getenv("LIBCHMOD_MODE_FILE_REQUIRED") ) == ((void *)0) ) {
      (*__errno_location ()) = 12;
      return((-1));
    }
    long_mode_file_allowed = strtol( env_mode_file_allowed, endptr, 8 );
    long_mode_file_required = strtol( env_mode_file_required, endptr, 8 );
    if ( ( mode_l | long_mode_file_allowed ) != long_mode_file_allowed ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
    if ( ( mode_l | long_mode_file_required ) != mode_l ) {
      (*__errno_location ()) = 1;
      return((-1));
    }
  }
  return orig_chmod( path, mode );
}

variable_types:
path
char *

variable_types:
mode
unsigned int

variable_types:
handle
void *

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

variable_types:
endptr
char **

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


help

repo: tled/pivot

decompiled_code:
int help()
{
puts("pivot: switching between two alternating screen rotations");
puts("usage: pivot [options] [ rotation_1 [ rotation_2 ]]");
puts(" -h, --help prints help");
puts(" -d, --display display");
puts(" -f, --force force switching");
putchar(10);
puts("rotations: left, right, normal, inverted");
puts(" default: left, normal");
putchar(10);
puts("examples:");
puts(" pivot -d :1 right");
puts(" pivot left normal");
return putchar(10);
}

canonical_decompiled_code:
int func7()
{
puts("pivot: switching between two alternating screen rotations");
puts("usage: pivot [options] [ rotation_1 [ rotation_2 ]]");
puts(" -h, --help prints help");
puts(" -d, --display display");
puts(" -f, --force force switching");
putchar(10);
puts("rotations: left, right, normal, inverted");
puts(" default: left, normal");
putchar(10);
puts("examples:");
puts(" pivot -d :1 right");
puts(" pivot left normal");
return putchar(10);
}

original_code:
void help() {
 printf("pivot: switching between two alternating  screen rotations\n");
 printf("usage: pivot [options] [ rotation_1 [ rotation_2 ]]\n");
 printf("  -h, --help     prints help\n");
 printf("  -d, --display  display\n");
 printf("  -f, --force    force switching\n");
 printf("\n");
 printf("rotations: left, right, normal, inverted\n");
 printf("  default: left, normal\n");
 printf("\n");
 printf("examples:\n");
 printf("  pivot -d :1 right\n");
 printf("  pivot left normal\n");
 printf("\n");
}


decompiled_code:
int __fastcall perform_submission(unsigned int a1, int a2, unsigned int a3)
{
int v4; // ebx
double v5; // xmm1_8
void *v6; // rbp
double v8; // [rsp+0h] [rbp-38h]

if ( a2 <= 0 )
{
v5 = 0.0;
}
else
{
v4 = 0;
v5 = 0.0;
do
{
++v4;
v6 = (void *)random_positions(a1, a3);
v8 = perform_trial(a1, a3, v6);
free(v6);
v5 = v5 + v8;
}
while ( a2 != v4 );
}
return printf("%f %d %d %d\n", v5 / (double)a2, a1, (unsigned int)a2, a3);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, int a2, unsigned int a3)
{
int v4; // ebx
double v5; // xmm1_8
void *v6; // rbp
double v8; // [rsp+0h] [rbp-38h]

if ( a2 <= 0 )
{
v5 = 0.0;
}
else
{
v4 = 0;
v5 = 0.0;
do
{
++v4;
v6 = (void *)random_positions(a1, a3);
v8 = perform_trial(a1, a3, v6);
free(v6);
v5 = v5 + v8;
}
while ( a2 != v4 );
}
return printf("%f %d %d %d\n", v5 / (double)a2, a1, (unsigned int)a2, a3);
}

original_code:
void perform_submission(int numpoints, int numtrials, int dimension) {
  double sum = 0;
  for(int i = 0; i < numtrials; i++) {
    position *positions = random_positions(numpoints, dimension);
    double val = perform_trial(numpoints, dimension, positions);
    free(positions);
    sum += val;
  }
  double avg = sum / (double)numtrials;
  printf("%f %d %d %d\n", avg, numpoints, numtrials, dimension);
}

canonical_original_code:
void perform_submission(int numpoints, int numtrials, int dimension) {
  double sum = 0;
  for(int i = 0; i < numtrials; i++) {
    struct position *positions = random_positions(numpoints, dimension);
    double val = perform_trial(numpoints, dimension, positions);
    free(positions);
    sum += val;
  }
  double avg = sum / (double)numtrials;
  printf("%f %d %d %d\n", avg, numpoints, numtrials, dimension);
}

variable_types: numpoints int

variable_types: numtrials int

variable_types: dimension int

variable_types: sum double

variable_types: struct position { double x; double y; double z; double w; } *

variable_types: val double

variable_types: avg double


decompiled_code:
int __fastcall perform_developer(unsigned int a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // ebx
double v5; // xmm1_8
void *v6; // rbp
double v8; // [rsp+0h] [rbp-38h]

printf("Running %d trials of Prim's algorithm on %d points in %d-dimensional space...\n", a2, a1, a3);
if ( (int)a2 <= 0 )
{
v5 = 0.0;
}
else
{
v4 = 0;
v5 = 0.0;
do
{
++v4;
v6 = (void *)random_positions(a1, a3);
v8 = perform_trial(a1, a3, v6);
free(v6);
printf("Trial %d, size of MST: %f\n", v4, v8);
v5 = v5 + v8;
}
while ( v4 != (_DWORD)a2 );
}
return printf("Average size of MST over %d trials: %f\n", (unsigned int)a2, v5 / (double)(int)a2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // ebx
double v5; // xmm1_8
void *v6; // rbp
double v8; // [rsp+0h] [rbp-38h]

printf("Running %d trials of Prim's algorithm on %d points in %d-dimensional space...\n", a2, a1, a3);
if ( (int)a2 <= 0 )
{
v5 = 0.0;
}
else
{
v4 = 0;
v5 = 0.0;
do
{
++v4;
v6 = (void *)random_positions(a1, a3);
v8 = perform_trial(a1, a3, v6);
free(v6);
printf("Trial %d, size of MST: %f\n", v4, v8);
v5 = v5 + v8;
}
while ( v4 != (_DWORD)a2 );
}
return printf("Average size of MST over %d trials: %f\n", (unsigned int)a2, v5 / (double)(int)a2);
}

original_code:
void perform_developer(int numpoints, int numtrials, int dimension) {
  printf("Running %d trials of Prim's algorithm on %d points in %d-dimensional space...\n", numtrials, numpoints, dimension);
  double sum = 0;
  for(int i = 0; i < numtrials; i++) {
    position *positions = random_positions(numpoints, dimension);
    double val = perform_trial(numpoints, dimension, positions);
    free(positions);
    printf("Trial %d, size of MST: %f\n", i + 1, val);
    sum += val;
  }
  double avg = sum / (double)numtrials;
  printf("Average size of MST over %d trials: %f\n", numtrials, avg);
}

canonical_original_code:
void perform_developer(int numpoints, int numtrials, int dimension) {
  printf("Running %d trials of Prim's algorithm on %d points in %d-dimensional space...\n", numtrials, numpoints, dimension);
  double sum = 0;
  for(int i = 0; i < numtrials; i++) {
    struct position *positions = random_positions(numpoints, dimension);
    double val = perform_trial(numpoints, dimension, positions);
    free(positions);
    printf("Trial %d, size of MST: %f\n", i + 1, val);
    sum += val;
  }
  double avg = sum / (double)numtrials;
  printf("Average size of MST over %d trials: %f\n", numtrials, avg);
}

variable_types: i int

user_defined_types: struct position { double x; double y; double z; double w; }


decompiled_code:
int print_usage()
{
puts("Usage:\n randmst ENV NUMPOINTS NUMTRIALS DIMENSION");
puts(" ENV # An integer on the interval [0, 2]");
puts(" # 0 -> Submission environment");
puts(" # 1 -> Developer environment");
puts(" # 2 -> Testing environment");
puts(" NUMPOINTS # The number of points in the graph");
puts(" NUMTRIALS # The number of trials to perform");
puts(" DIMENSION # The number of dimensions assigned to each node");
puts(" # 0 -> Random real on [0, 1]");
return puts(" # 2,3,4 -> n dimensions");
}

canonical_decompiled_code:
int func2()
{
puts("Usage:\n randmst ENV NUMPOINTS NUMTRIALS DIMENSION");
puts(" ENV # An integer on the interval [0, 2]");
puts(" # 0 -> Submission environment");
puts(" # 1 -> Developer environment");
puts(" # 2 -> Testing environment");
puts(" NUMPOINTS # The number of points in the graph");
puts(" NUMTRIALS # The number of trials to perform");
puts(" DIMENSION # The number of dimensions assigned to each node");
puts(" # 0 -> Random real on [0, 1]");
return puts(" # 2,3,4 -> n dimensions");
}

original_code:
void print_usage() {
  printf("Usage:\n  randmst ENV NUMPOINTS NUMTRIALS DIMENSION\n");
  printf("  ENV          # An integer on the interval [0, 2]\n");
  printf("                 # 0 -> Submission environment\n");
  printf("                 # 1 -> Developer environment\n");
  printf("                 # 2 -> Testing environment\n");
  printf("  NUMPOINTS    # The number of points in the graph\n");
  printf("  NUMTRIALS    # The number of trials to perform\n");
  printf("  DIMENSION    # The number of dimensions assigned to each node\n");
  printf("                 # 0     -> Random real on [0, 1]\n");
  printf("                 # 2,3,4 -> n dimensions\n");
}


decompiled_code:
int print_misuse()
{
puts("Unrecognizable input.");
return print_usage();
}

canonical_decompiled_code:
int func3()
{
puts("Unrecognizable input.");
return func2();
}

original_code:
void print_misuse() {
  printf("Unrecognizable input.\n");
  print_usage();
}


argtoi

decompiled_code:
__int64 __fastcall argtoi(_BYTE *a1)
{
int v1; // eax
_BYTE *v2; // rdi
unsigned int v3; // er8

v1 = (char)*a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
while ( (unsigned __int8)(v1 - 48) <= 0xAu )
{
++v2;
v3 = v1 + 10 * v3 - 48;
v1 = (char)*(v2 - 1);
if ( !*(v2 - 1) )
return v3;
}
return (unsigned int)-1;
}

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

v1 = (char)*a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
while ( (unsigned __int8)(v1 - 48) <= 0xAu )
{
++v2;
v3 = v1 + 10 * v3 - 48;
v1 = (char)*(v2 - 1);
if ( !*(v2 - 1) )
return v3;
}
return (unsigned int)-1;
}

original_code:
int argtoi(char *arg) {
  int i = 0;
  int r = 0;
  while(1) {
    char c = arg[i];
    if(c == 0) {
      break;
    } else if(c >= 48 && c <= 58) {
      r = (r * 10) + c - 48;
      i++;
    } else {
      return -1;
    }
  }
  return r;
}

variable_types:
arg
char *

variable_types: r int

variable_types: c char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ecx
unsigned int v4; // ebx
signed int v5; // ebp
int v6; // er13
unsigned int v7; // eax
unsigned int v8; // er12
unsigned int v9; // eax

if ( argc <= 1 )
goto LABEL_17;
v4 = argtoi(argv[1]);
if ( v4 > 1 || v3 != 5 )
{
if ( v4 == 2 && v3 == 2 )
{
perform_testing();
return 0;
}
goto LABEL_17;
}
v5 = argtoi(argv[2]);
v6 = argtoi(argv[3]);
v7 = argtoi(argv[4]);
v8 = v7;
if ( v5 < 0 || v6 < 0 || v7 - 2 > 2 && v7 )
{
LABEL_17:
print_misuse();
return -1;
}
v9 = time(0LL);
srand(v9);
if ( !v8 )
v8 = 1;
if ( v4 == 1 )
perform_developer(v5, (unsigned int)v6, v8);
else
perform_submission(v5, v6, v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ecx
unsigned int v4; // ebx
signed int v5; // ebp
int v6; // er13
unsigned int v7; // eax
unsigned int v8; // er12
unsigned int v9; // eax

if ( argc <= 1 )
goto LABEL_17;
v4 = func4(argv[1]);
if ( v4 > 1 || v3 != 5 )
{
if ( v4 == 2 && v3 == 2 )
{
perform_testing();
return 0;
}
goto LABEL_17;
}
v5 = func4(argv[2]);
v6 = func4(argv[3]);
v7 = func4(argv[4]);
v8 = v7;
if ( v5 < 0 || v6 < 0 || v7 - 2 > 2 && v7 )
{
LABEL_17:
func3();
return -1;
}
v9 = time(0LL);
srand(v9);
if ( !v8 )
v8 = 1;
if ( v4 == 1 )
func1(v5, (unsigned int)v6, v8);
else
func0(v5, v6, v8);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  if(argc >= 2) {
    int env = argtoi(argv[1]);
    if((env == 0 || env == 1) && argc == 5) {
      int numpoints = argtoi(argv[2]);
      int numtrials = argtoi(argv[3]);
      int dimension = argtoi(argv[4]);
      if(numpoints >=0 && numtrials >= 0 && (dimension == 0 || (dimension >= 2 && dimension <= 4))) {
        srand((unsigned)time(((void *)0)));
        if(dimension == 0) {
          dimension++;
        }
        switch(env) {
          case submission:
            perform_submission(numpoints, numtrials, dimension);
            break;
          case developer:
            perform_developer(numpoints, numtrials, dimension);
            break;
        }
        return 0;
      } else {
        print_misuse();
        return -1;
      }
    } else if(env == 2 && argc == 2) {
      perform_testing();
    } else {
      print_misuse();
      return -1;
    }
  } else {
    print_misuse();
    return -1;
  }
}

canonical_original_code:
int main(int argc, char *argv[]) {
  if(argc >= 2) {
    int env = argtoi(argv[1]);
    if((env == 0 || env == 1) && argc == 5) {
      int numpoints = argtoi(argv[2]);
      int numtrials = argtoi(argv[3]);
      int dimension = argtoi(argv[4]);
      if(numpoints >=0 && numtrials >= 0 && (dimension == 0 || (dimension >= 2 && dimension <= 4))) {
        srand((unsigned int)time(((void *)0)));
        if(dimension == 0) {
          dimension++;
        }
        switch(env) {
          case submission:
            perform_submission(numpoints, numtrials, dimension);
            break;
          case developer:
            perform_developer(numpoints, numtrials, dimension);
            break;
        }
        return 0;
      } else {
        print_misuse();
        return -1;
      }
    } else if(env == 2 && argc == 2) {
      perform_testing();
    } else {
      print_misuse();
      return -1;
    }
  } else {
    print_misuse();
    return -1;
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: env int


dist

original_code:
double dist(position a, position b, int dimension) {
  double parameter;
  switch(dimension) {
    case 1:
      parameter = pow(a.x - b.x, 2.0);
      break;
    case 2:
      parameter = pow(a.x - b.x, 2.0) + pow((a.y - b.y), 2.0);
      break;
    case 3:
      parameter = pow(a.x - b.x, 2.0) + pow((a.y - b.y), 2.0)
                + pow(a.z - b.z, 2.0);
      break;
    case 4:
      parameter = pow(a.x - b.x, 2.0) + pow((a.y - b.y), 2.0)
                + pow(a.z - b.z, 2.0) + pow((a.w - b.w), 2.0);
      break;
  }
  return sqrt(parameter);
}

canonical_original_code:
double dist(struct position a, struct position b, int dimension) {
  double parameter;
  switch(dimension) {
    case 1:
      parameter = pow(a.x - b.x, 2.0);
      break;
    case 2:
      parameter = pow(a.x - b.x, 2.0) + pow((a.y - b.y), 2.0);
      break;
    case 3:
      parameter = pow(a.x - b.x, 2.0) + pow((a.y - b.y), 2.0)
                + pow(a.z - b.z, 2.0);
      break;
    case 4:
      parameter = pow(a.x - b.x, 2.0) + pow((a.y - b.y), 2.0)
                + pow(a.z - b.z, 2.0) + pow((a.w - b.w), 2.0);
      break;
  }
  return sqrt(parameter);
}

variable_types: struct position { double x; double y; double z; double w; }

variable_types:
b
struct position

variable_types: parameter double

return_type: double


original_code:
double dist1(double x1, double x2) {
  return dist(new_position(x1, 0.0, 0.0, 0.0), new_position(x2, 0.0, 0.0, 0.0), 1);
}


decompiled_code:
void __fastcall dist2(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm5_8
double v9; // xmm1_8
double v10; // xmm4_8
double v11; // xmm0_8
double v12; // xmm4_8
double v13; // xmm5_8
__int64 v14[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v15[5]; // [rsp+20h] [rbp-28h] BYREF

new_position((double *)v14, a3, a4, 0.0, 0.0);
v9 = v8;
v11 = v10;
new_position((double *)v15, v10, v8, 0.0, 0.0);
dist(
2,
v11,
v9,
0.0,
0.0,
v12,
v13,
a7,
a8,
*(double *)v15,
*(double *)&v15[1],
*(double *)&v15[2],
*(double *)&v15[3],
*(double *)v14,
*(double *)&v14[1],
*(double *)&v14[2],
*(double *)&v14[3]);
}

original_code:
double dist2(double x1, double y1, double x2, double y2) {
  return dist(new_position(x1, y1, 0.0, 0.0), new_position(x2, y2, 0.0, 0.0), 2);
}


decompiled_code:
void __fastcall dist3(double a1, double a2, double a3, double a4, double a5, double a6)
{
double v6; // xmm4_8
double v7; // xmm5_8
__int64 v8[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v9[5]; // [rsp+20h] [rbp-28h] BYREF

new_position((double *)v8, a4, a5, a6, 0.0);
new_position((double *)v9, a1, a2, a3, 0.0);
dist(
3,
a1,
a2,
a3,
0.0,
v6,
v7,
a1,
a2,
*(double *)v9,
*(double *)&v9[1],
*(double *)&v9[2],
*(double *)&v9[3],
*(double *)v8,
*(double *)&v8[1],
*(double *)&v8[2],
*(double *)&v8[3]);
}

canonical_decompiled_code:
void __fastcall func4(double a1, double a2, double a3, double a4, double a5, double a6)
{
double v6; // xmm4_8
double v7; // xmm5_8
__int64 v8[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v9[5]; // [rsp+20h] [rbp-28h] BYREF

func0((double *)v8, a4, a5, a6, 0.0);
func0((double *)v9, a1, a2, a3, 0.0);
func1(
3,
a1,
a2,
a3,
0.0,
v6,
v7,
a1,
a2,
*(double *)v9,
*(double *)&v9[1],
*(double *)&v9[2],
*(double *)&v9[3],
*(double *)v8,
*(double *)&v8[1],
*(double *)&v8[2],
*(double *)&v8[3]);
}

original_code:
double dist3(double x1, double y1, double z1, double x2, double y2, double z2) {
  return dist(new_position(x1, y1, z1, 0.0), new_position(x2, y2, z2, 0.0), 3);
}


decompiled_code:
void __fastcall dist4(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm4_8
double v9; // xmm5_8
__int64 v10[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v11[5]; // [rsp+20h] [rbp-28h] BYREF

new_position((double *)v10, a5, a6, a7, a8);
new_position((double *)v11, a1, a2, a3, a4);
dist(
4,
a1,
a2,
a3,
a4,
v8,
v9,
a7,
a8,
*(double *)v11,
*(double *)&v11[1],
*(double *)&v11[2],
*(double *)&v11[3],
*(double *)v10,
*(double *)&v10[1],
*(double *)&v10[2],
*(double *)&v10[3]);
}

canonical_decompiled_code:
void __fastcall func5(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm4_8
double v9; // xmm5_8
__int64 v10[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v11[5]; // [rsp+20h] [rbp-28h] BYREF

func0((double *)v10, a5, a6, a7, a8);
func0((double *)v11, a1, a2, a3, a4);
func1(
4,
a1,
a2,
a3,
a4,
v8,
v9,
a7,
a8,
*(double *)v11,
*(double *)&v11[1],
*(double *)&v11[2],
*(double *)&v11[3],
*(double *)v10,
*(double *)&v10[1],
*(double *)&v10[2],
*(double *)&v10[3]);
}

original_code:
double dist4(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) {
  return dist(new_position(x1, y1, z1, w1), new_position(x2, y2, z2, w2), 4);
}


original_code:
position *random_positions(int numpoints, int dimension) {
  position *positions = (position *)malloc(sizeof(position) * numpoints);
  for(int i = 0; i < numpoints; i++) {
    positions[i].x = (double)rand() / (double)2147483647;
    positions[i].y = (double)rand() / (double)2147483647;
    positions[i].z = (double)rand() / (double)2147483647;
    positions[i].w = (double)rand() / (double)2147483647;
  }
  return positions;
}

canonical_original_code:
struct position *random_positions(int numpoints, int dimension) {
  struct position *positions = (position *)malloc(sizeof(position) * numpoints);
  for(int i = 0; i < numpoints; i++) {
    positions[i].x = (double)rand() / (double)2147483647;
    positions[i].y = (double)rand() / (double)2147483647;
    positions[i].z = (double)rand() / (double)2147483647;
    positions[i].w = (double)rand() / (double)2147483647;
  }
  return positions;
}

variable_types: numpoints int

return_type: struct position { double x; double y; double z; double w; } *


decompiled_code:
double __fastcall sum_MST(int a1, __int64 a2)
{
double *v2; // rax
double result; // xmm0_8

if ( a1 <= 0 )
return 0.0;
v2 = (double *)(a2 + 8);
result = 0.0;
do
{
result = result + *v2;
v2 += 2;
}
while ( v2 != (double *)(a2 + 16LL * (unsigned int)(a1 - 1) + 24) );
return result;
}

canonical_decompiled_code:
double __fastcall func0(int a1, __int64 a2)
{
double *v2; // rax
double result; // xmm0_8

if ( a1 <= 0 )
return 0.0;
v2 = (double *)(a2 + 8);
result = 0.0;
do
{
result = result + *v2;
v2 += 2;
}
while ( v2 != (double *)(a2 + 16LL * (unsigned int)(a1 - 1) + 24) );
return result;
}

original_code:
double sum_MST(int numpoints, node graph[]) {
  double sum_dist = 0;
  for(int i =0; i < numpoints; i++) {
    sum_dist = sum_dist + graph[i].dist;
  }
  return sum_dist;
}

canonical_original_code:
double sum_MST(int numpoints, struct node graph[]) {
  double sum_dist = 0;
  for(int i = 0; i < numpoints; i++) {
    sum_dist = sum_dist + graph[i].dist;
  }
  return sum_dist;
}

variable_types: struct node { int name; double dist; } []


original_code:
double perform_trial(int numpoints, int dimension, position *node_location) {
  init_heap_vars(numpoints, (numpoints * (numpoints - 1)) / 2);
  node *heap = (node *) malloc(sizeof(node) * numpoints);
  int location[numpoints];
  node *graph = (node *) malloc(sizeof(node) * numpoints);
  for(int i = 0; i < numpoints; i++) {
    graph[i].name = i;
    graph[i].dist = -1;
    insert_list(i);
    location[i] = -1;
    heap[i].dist = 100000;
    heap[i].name = 100000;
  }
  graph[0].dist = 0;
  insert(graph[0], heap, location);
  while(size_heap() != 0) {
    node v = delete_min(heap, location);
    if(v.dist == -100.) {
      break;
    }
    delete_list(v.name);
    list_node *ptr = get_head();
    while(ptr != ((void *)0)) {
      int current_name = ptr->name;
       double check_val = 0;
      if(dimension == 1) {
        check_val = fabs(node_location[v.name].x-node_location[current_name].x);
      } else if(dimension == 2) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.);
        check_val = sqrt(parameter);
      } else if(dimension == 3) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.)
                           + pow((node_location[v.name].z-node_location[current_name].z), 2.);
        check_val = sqrt(parameter);
      } else if(dimension == 4) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.)
                           + pow((node_location[v.name].z-node_location[current_name].z), 2.)
                           + pow((node_location[v.name].w-node_location[current_name].w), 2.);
        check_val = sqrt(parameter);
      }
      if(((graph[current_name].dist > check_val) || graph[current_name].dist == -1)) {
        graph[current_name].dist = check_val;
        node change_node = graph[current_name];
        change(change_node, heap, location);
      }
      ptr = ptr->next;
    }
  }
  double sum = sum_MST(numpoints, graph);
  free(heap);
  free(graph);
  free_list();
  return sum;
}

canonical_original_code:
double perform_trial(int numpoints, int dimension, struct position *node_location) {
  init_heap_vars(numpoints, (numpoints * (numpoints - 1)) / 2);
  struct node *heap = (node *) malloc(sizeof(node) * numpoints);
  int location[-1];
  struct node *graph = (node *) malloc(sizeof(node) * numpoints);
  for(int i = 0; i < numpoints; i++) {
    graph[i].name = i;
    graph[i].dist = -1;
    insert_list(i);
    location[i] = -1;
    heap[i].dist = 100000;
    heap[i].name = 100000;
  }
  graph[0].dist = 0;
  insert(graph[0], heap, location);
  while(size_heap() != 0) {
    struct node v = delete_min(heap, location);
    if(v.dist == -100.) {
      break;
    }
    delete_list(v.name);
    struct list_node *ptr = get_head();
    while(ptr != ((void *)0)) {
      int current_name = ptr->name;
       double check_val = 0;
      if(dimension == 1) {
        check_val = fabs(node_location[v.name].x-node_location[current_name].x);
      } else if(dimension == 2) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.);
        check_val = sqrt(parameter);
      } else if(dimension == 3) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.)
                           + pow((node_location[v.name].z-node_location[current_name].z), 2.);
        check_val = sqrt(parameter);
      } else if(dimension == 4) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.)
                           + pow((node_location[v.name].z-node_location[current_name].z), 2.)
                           + pow((node_location[v.name].w-node_location[current_name].w), 2.);
        check_val = sqrt(parameter);
      }
      if(((graph[current_name].dist > check_val) || graph[current_name].dist == -1)) {
        graph[current_name].dist = check_val;
        struct node change_node = graph[current_name];
        change(change_node, heap, location);
      }
      ptr = ptr->next;
    }
  }
  double sum = sum_MST(numpoints, graph);
  free(heap);
  free(graph);
  free_list();
  return sum;
}

variable_types: dimension int

variable_types: struct node { int name; double dist; } *

variable_types:
location
int [-1]

variable_types:
v
struct node { int name; double dist; }

variable_types: struct list_node { int name; struct list_node *next; } *


original_code:
double sort_MST(int numpoints, node graph[]) {
  node heap[numpoints];
  int location[numpoints];
  for(int i = 0; i < numpoints; i++){
    location[i] = 0;
    insert(graph[i], heap, location);
  }
  double sorted_arr[numpoints];
  for(int i = 0; i < numpoints; i++) {
    sorted_arr[i] = delete_min(heap, location).dist;
  }
  return sorted_arr[numpoints-1];
}

canonical_original_code:
double sort_MST(int numpoints, struct node graph[]) {
  struct node heap[-1];
  int location[-1];
  for(int i = 0; i < numpoints; i++){
    location[i] = 0;
    insert(graph[i], heap, location);
  }
  double sorted_arr[-1];
  for(int i = 0; i < numpoints; i++) {
    sorted_arr[i] = delete_min(heap, location).dist;
  }
  return sorted_arr[numpoints-1];
}

variable_types: struct node { int name; double dist; } [-1]

variable_types: i int


decompiled_code:
void __fastcall init_heap_vars(int a1)
{
num_nodes = a1;
d = 2;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
num_nodes = a1;
d = 2;
}

original_code:
void init_heap_vars(int numNode, int numEdge)
{
    num_nodes = numNode;
    d = 2;
}

variable_types: numNode int

variable_types: numEdge int


original_code:
node delete_min(node heap[], int location[])
{
    if(ind_last == -1)
    {
        node empty_node;
        empty_node.dist = -100.;
        empty_node.name = 0;
        return empty_node;
    }
    if(ind_last == 0)
    {
        node return_node = heap[0];
        location[return_node.name] = -1;
        ind_last = -1;
        return return_node;
    }
    node return_node = heap[0];
    location[return_node.name] = -1;
    heap[0] = heap[ind_last];
    location[heap[0].name] = 0;
    ind_last--;
    _Bool is_correct = 0;
    int cur_ind = 0;
    while(!is_correct)
    {
        int smallest_ind = cur_ind;
        for(int i = 1; i < d+1; i++)
        {
            if(cur_ind*d+i > ind_last)
                break;
            if (heap[cur_ind].dist > heap[(cur_ind*d+i)].dist)
            {
                if(heap[smallest_ind].dist > heap[(cur_ind*d+i)].dist)
                    smallest_ind = cur_ind*d+i;
            }
        }
        if(smallest_ind != cur_ind)
        {
            node temp1 = heap[cur_ind];
            node temp2 = heap[smallest_ind];
            int temp_location1 = location[temp1.name];
            int temp_location2 = location[temp2.name];
            location[heap[cur_ind].name] = temp_location2;
            location[heap[smallest_ind].name] = temp_location1;
            heap[cur_ind] = temp2;
            heap[smallest_ind] = temp1;
            cur_ind = smallest_ind;
        }
        else
            is_correct = 1;
    }
    return return_node;
}

canonical_original_code:
struct node delete_min(struct node heap[], int location[])
{
    if(ind_last == -1)
    {
        struct node empty_node;
        empty_node.dist = -100.;
        empty_node.name = 0;
        return empty_node;
    }
    if(ind_last == 0)
    {
        struct node return_node = heap[0];
        location[return_node.name] = -1;
        ind_last = -1;
        return return_node;
    }
    struct node return_node = heap[0];
    location[return_node.name] = -1;
    heap[0] = heap[ind_last];
    location[heap[0].name] = 0;
    ind_last--;
    _Bool is_correct = 0;
    int cur_ind = 0;
    while(!is_correct)
    {
        int smallest_ind = cur_ind;
        for(int i = 1; i < d+1; i++)
        {
            if(cur_ind*d+i > ind_last)
                break;
            if (heap[cur_ind].dist > heap[(cur_ind*d+i)].dist)
            {
                if(heap[smallest_ind].dist > heap[(cur_ind*d+i)].dist)
                    smallest_ind = cur_ind*d+i;
            }
        }
        if(smallest_ind != cur_ind)
        {
            struct node temp1 = heap[cur_ind];
            struct node temp2 = heap[smallest_ind];
            int temp_location1 = location[temp1.name];
            int temp_location2 = location[temp2.name];
            location[heap[cur_ind].name] = temp_location2;
            location[heap[smallest_ind].name] = temp_location1;
            heap[cur_ind] = temp2;
            heap[smallest_ind] = temp1;
            cur_ind = smallest_ind;
        }
        else
            is_correct = 1;
    }
    return return_node;
}

variable_types:
heap
struct node []

variable_types:
location
int []

return_type: struct node { int name; double dist; }


insert

original_code:
void insert(node new_node, node heap[], int location[])
{
    heap[ind_last+1] = new_node;
    ind_last++;
    location[heap[ind_last].name] = ind_last;
    _Bool is_correct = 0;
    int cur_ind = ind_last;
    while(!is_correct)
    {
        if(heap[(cur_ind-1)/d].dist > heap[cur_ind].dist)
        {
            node temp1 = heap[(cur_ind-1)/d];
            node temp2 = heap[cur_ind];
            int temp_location1 = (cur_ind-1)/d;
            int temp_location2 = cur_ind;
            location[heap[(cur_ind-1)/d].name] = temp_location2;
            location[heap[cur_ind].name] = temp_location1;
            heap[(cur_ind-1)/d] = temp2;
            heap[cur_ind] = temp1;
            cur_ind = (cur_ind -1)/d;
        }
        else
            is_correct = 1;
    }
}

canonical_original_code:
void insert(struct node new_node, struct node heap[], int location[])
{
    heap[ind_last+1] = new_node;
    ind_last++;
    location[heap[ind_last].name] = ind_last;
    _Bool is_correct = 0;
    int cur_ind = ind_last;
    while(!is_correct)
    {
        if(heap[(cur_ind-1)/d].dist > heap[cur_ind].dist)
        {
            struct node temp1 = heap[(cur_ind-1)/d];
            struct node temp2 = heap[cur_ind];
            int temp_location1 = (cur_ind-1)/d;
            int temp_location2 = cur_ind;
            location[heap[(cur_ind-1)/d].name] = temp_location2;
            location[heap[cur_ind].name] = temp_location1;
            heap[(cur_ind-1)/d] = temp2;
            heap[cur_ind] = temp1;
            cur_ind = (cur_ind -1)/d;
        }
        else
            is_correct = 1;
    }
}


change

original_code:
void change(node old_node, node heap[], int location[])
{
    if(location[old_node.name] == -1)
    {
        insert(old_node, heap, location);
        return;
    }
    heap[location[old_node.name]].dist = old_node.dist;
    _Bool is_correct = 0;
    int cur_ind = location[old_node.name];
    while(!is_correct)
    {
        if(heap[(cur_ind-1)/d].dist > heap[cur_ind].dist)
        {
            node temp1 = heap[(cur_ind-1)/d];
            node temp2 = heap[cur_ind];
            int temp_location1 = (cur_ind-1)/d;
            int temp_location2 = cur_ind;
            location[heap[(cur_ind-1)/d].name] = temp_location2;
            location[heap[cur_ind].name] = temp_location1;
            heap[(cur_ind-1)/d] = temp2;
            heap[cur_ind] = temp1;
            cur_ind = (cur_ind -1)/d;
        }
        else
            is_correct = 1;
    }
}

canonical_original_code:
void change(struct node old_node, struct node heap[], int location[])
{
    if(location[old_node.name] == -1)
    {
        insert(old_node, heap, location);
        return;
    }
    heap[location[old_node.name]].dist = old_node.dist;
    _Bool is_correct = 0;
    int cur_ind = location[old_node.name];
    while(!is_correct)
    {
        if(heap[(cur_ind-1)/d].dist > heap[cur_ind].dist)
        {
            struct node temp1 = heap[(cur_ind-1)/d];
            struct node temp2 = heap[cur_ind];
            int temp_location1 = (cur_ind-1)/d;
            int temp_location2 = cur_ind;
            location[heap[(cur_ind-1)/d].name] = temp_location2;
            location[heap[cur_ind].name] = temp_location1;
            heap[(cur_ind-1)/d] = temp2;
            heap[cur_ind] = temp1;
            cur_ind = (cur_ind -1)/d;
        }
        else
            is_correct = 1;
    }
}


decompiled_code:
__int64 size_heap()
{
return (unsigned int)(ind_last + 1);
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)(ind_last + 1);
}

original_code:
int size_heap()
{
    return ind_last + 1;
}


approx

original_code:
void approx(double a, double b) {
  ((fabs(a - b) < .001) ? (void) (0) : __assert_fail ("fabs(a - b) < .001", "test.c", 119, __extension__ __PRETTY_FUNCTION__));
}

variable_types: a double

variable_types: b double


original_code:
void perform_1d_testing() {
  position *positions;
  positions = (position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.0, 0, 0, 0);
  positions[1] = new_position(1.0, 0, 0, 0);
  approx(perform_trial(2, 1, positions), 1.0);
  positions = (position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.25, 0, 0, 0);
  positions[1] = new_position(0.85, 0, 0, 0);
  approx(perform_trial(2, 1, positions), 0.6);
  positions = (position *)malloc(sizeof(position) * 3);
  positions[0] = new_position(0.25, 0, 0, 0);
  positions[1] = new_position(0.85, 0, 0, 0);
  positions[2] = new_position(0.95, 0, 0, 0);
  approx(perform_trial(3, 1, positions), 0.7);
}

canonical_original_code:
void perform_1d_testing() {
  struct position *positions;
  positions = (struct position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.0, 0, 0, 0);
  positions[1] = new_position(1.0, 0, 0, 0);
  approx(perform_trial(2, 1, positions), 1.0);
  positions = (struct position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.25, 0, 0, 0);
  positions[1] = new_position(0.85, 0, 0, 0);
  approx(perform_trial(2, 1, positions), 0.6);
  positions = (struct position *)malloc(sizeof(position) * 3);
  positions[0] = new_position(0.25, 0, 0, 0);
  positions[1] = new_position(0.85, 0, 0, 0);
  positions[2] = new_position(0.95, 0, 0, 0);
  approx(perform_trial(3, 1, positions), 0.7);
}

variable_types: struct position { double x; double y; double z; double w; } *


original_code:
void perform_2d_testing() {
  position *positions;
  positions = (position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(1.0, 1.0, 0, 0);
  approx(perform_trial(2, 2, positions), sqrt(2.0));
  positions = (position *)malloc(sizeof(position) * 3);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(1.0, 1.0, 0, 0);
  positions[2] = new_position(1.0, 0.0, 0, 0);
  approx(perform_trial(3, 2, positions), 2.0);
  positions = (position *)malloc(sizeof(position) * 4);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(1.0, 1.0, 0, 0);
  positions[2] = new_position(1.0, 0.0, 0, 0);
  positions[3] = new_position(0.0, 1.0, 0, 0);
  approx(perform_trial(4, 2, positions), 3.0);
  positions = (position *)malloc(sizeof(position) * 4);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(0.5, 1.0, 0, 0);
  positions[2] = new_position(0.5, 0.0, 0, 0);
  positions[3] = new_position(1.0, 0.5, 0, 0);
  approx(perform_trial(4, 2, positions), .5 + 2 * sqrt(2.0) * .5);
}

canonical_original_code:
void perform_2d_testing() {
  struct position *positions;
  positions = (struct position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(1.0, 1.0, 0, 0);
  approx(perform_trial(2, 2, positions), sqrt(2.0));
  positions = (struct position *)malloc(sizeof(position) * 3);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(1.0, 1.0, 0, 0);
  positions[2] = new_position(1.0, 0.0, 0, 0);
  approx(perform_trial(3, 2, positions), 2.0);
  positions = (struct position *)malloc(sizeof(position) * 4);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(1.0, 1.0, 0, 0);
  positions[2] = new_position(1.0, 0.0, 0, 0);
  positions[3] = new_position(0.0, 1.0, 0, 0);
  approx(perform_trial(4, 2, positions), 3.0);
  positions = (struct position *)malloc(sizeof(position) * 4);
  positions[0] = new_position(0.0, 0.0, 0, 0);
  positions[1] = new_position(0.5, 1.0, 0, 0);
  positions[2] = new_position(0.5, 0.0, 0, 0);
  positions[3] = new_position(1.0, 0.5, 0, 0);
  approx(perform_trial(4, 2, positions), .5 + 2 * sqrt(2.0) * .5);
}


original_code:
void perform_3d_testing() {
  position *positions;
  positions = (position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.0, 0.0, 0.0, 0);
  positions[1] = new_position(1.0, 1.0, 1.0, 0);
  approx(perform_trial(2, 3, positions), sqrt(pow(sqrt(2.0),2.0)+1.0));
  positions = (position *)malloc(sizeof(position) * 4);
  positions[0] = new_position(0.0, 0.0, 0.0, 0);
  positions[1] = new_position(0.5, 0.5, 0.0, 0);
  positions[2] = new_position(1.0, 1.0, 0.2, 0);
  positions[3] = new_position(0.5, 1.0, 1.0, 0);
  approx(perform_trial(4, 3, positions), dist2(0.0,0.0,0.5,0.5)+dist3(0.5,0.5,0.0,1.0,1.0,0.2)
                                        +dist3(1.0,1.0,0.2,0.5,1.0,1.0));
}

canonical_original_code:
void perform_3d_testing() {
  struct position *positions;
  positions = (struct position *)malloc(sizeof(position) * 2);
  positions[0] = new_position(0.0, 0.0, 0.0, 0);
  positions[1] = new_position(1.0, 1.0, 1.0, 0);
  approx(perform_trial(2, 3, positions), sqrt(pow(sqrt(2.0),2.0)+1.0));
  positions = (struct position *)malloc(sizeof(position) * 4);
  positions[0] = new_position(0.0, 0.0, 0.0, 0);
  positions[1] = new_position(0.5, 0.5, 0.0, 0);
  positions[2] = new_position(1.0, 1.0, 0.2, 0);
  positions[3] = new_position(0.5, 1.0, 1.0, 0);
  approx(perform_trial(4, 3, positions), dist2(0.0,0.0,0.5,0.5)+dist3(0.5,0.5,0.0,1.0,1.0,0.2)
                                        +dist3(1.0,1.0,0.2,0.5,1.0,1.0));
}


canonical_original_code:
void perform_4d_testing() {
  struct position *positions;
  positions = (struct position *)malloc(sizeof(position) * 4);
  positions[0] = new_position(0.0, 0.0, 0.0, 0);
  positions[1] = new_position(0.5, 0.5, 0.0, 0);
  positions[2] = new_position(1.0, 1.0, 0.2, 0);
  positions[3] = new_position(0.5, 1.0, 1.0, 1.0);
  approx(perform_trial(4, 4, positions), dist2(0.0,0.0,0.5,0.5)+dist3(0.5,0.5,0.0,1.0,1.0,0.2)
                                        +dist4(1.0,1.0,0.2,0.0,0.5,1.0,1.0,1.0));
}


decompiled_code:
int perform_testing()
{
perform_position_testing();
perform_1d_testing();
perform_2d_testing();
perform_3d_testing();
perform_4d_testing();
return puts("All tests passed successfully!");
}

canonical_decompiled_code:
int func6()
{
func1();
func2();
func3();
func4();
func5();
return puts("All tests passed successfully!");
}

original_code:
void perform_testing() {
  perform_position_testing();
  perform_1d_testing();
  perform_2d_testing();
  perform_3d_testing();
  perform_4d_testing();
  printf("All tests passed successfully!\n");
}


decompiled_code:
void *get_head()
{
return first;
}

canonical_decompiled_code:
void *func0()
{
return first;
}

original_code:
list_node *get_head(void)
{
    list_node *ptr = first;
    return ptr;
}

canonical_original_code:
struct list_node *get_head()
{
    struct list_node *ptr = first;
    return ptr;
}

return_type: struct list_node { int name; struct list_node *next; } *


decompiled_code:
void __fastcall delete_list(int a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rcx
void *v4; // rax

if ( first )
{
v2 = first;
v3 = 0LL;
while ( 1 )
{
v4 = (void *)v2[1];
if ( *(_DWORD *)v2 == a1 )
break;
v3 = v2;
if ( !v4 )
return;
v2 = (_QWORD *)v2[1];
}
if ( first == v2 )
{
v2 = first;
first = v4;
}
else
{
v3[1] = v4;
}
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rcx
void *v4; // rax

if ( first )
{
v2 = first;
v3 = 0LL;
while ( 1 )
{
v4 = (void *)v2[1];
if ( *(_DWORD *)v2 == a1 )
break;
v3 = v2;
if ( !v4 )
return;
v2 = (_QWORD *)v2[1];
}
if ( first == v2 )
{
v2 = first;
first = v4;
}
else
{
v3[1] = v4;
}
free(v2);
}
}

original_code:
void delete_list(int delete_name)
{
    list_node *ptr = first;
    list_node *predptr = ((void *)0);
    while (ptr != ((void *)0))
    {
        if(ptr->name == delete_name)
        {
            if(ptr == first)
            {
                first = ptr->next;
                free(ptr);
            }
            else
            {
                predptr->next = ptr->next;
                free(ptr);
            }
            break;
        }
        else
        {
            predptr = ptr;
            ptr = ptr->next;
        }
    }
}

canonical_original_code:
void delete_list(int delete_name)
{
    struct list_node *ptr = first;
    struct list_node *predptr = ((void *)0);
    while (ptr != ((void *)0))
    {
        if(ptr->name == delete_name)
        {
            if(ptr == first)
            {
                first = ptr->next;
                free(ptr);
            }
            else
            {
                predptr->next = ptr->next;
                free(ptr);
            }
            break;
        }
        else
        {
            predptr = ptr;
            ptr = ptr->next;
        }
    }
}

user_defined_types: struct list_node { int name; struct list_node *next; }


decompiled_code:
int print_list()
{
unsigned int *v0; // rbx

v0 = (unsigned int *)first;
if ( first )
{
do
{
printf("%d,", *v0);
v0 = (unsigned int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
}
putchar(10);
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
unsigned int *v0; // rbx

v0 = (unsigned int *)first;
if ( first )
{
do
{
printf("%d,", *v0);
v0 = (unsigned int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
}
putchar(10);
return putchar(10);
}

original_code:
void print_list(int node_name)
{
    list_node *ptr;
    ptr = first;
    while(ptr != ((void *)0))
    {
        printf("%d,", ptr->name);
        ptr = ptr->next;
    }
    printf("\n");
    printf("\n");
}

canonical_original_code:
void print_list(int node_name)
{
    struct list_node *ptr;
    ptr = first;
    while(ptr != ((void *)0))
    {
        printf("%d,", ptr->name);
        ptr = ptr->next;
    }
    printf("\n");
    printf("\n");
}


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

v0 = first;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 1);
free(v1);
}
}

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

v0 = first;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 1);
free(v1);
}
}

original_code:
void free_list(void)
{
    list_node *ptr = first;
    while (ptr != ((void *)0))
    {
        list_node *predptr = ptr;
        ptr = ptr->next;
        free(predptr);
    }
}

canonical_original_code:
void free_list()
{
    struct list_node *ptr = first;
    while (ptr != ((void *)0))
    {
        struct list_node *predptr = ptr;
        ptr = ptr->next;
        free(predptr);
    }
}