original_code:
static struct Node *balance_node (struct Dict *tree, struct Node *high)
{
 struct Node *mid = ((void *)0);
 struct Node *low = ((void *)0);
 if ((high->balance == +2) && (high->child[1]->balance >= 0)) {
  mid = high->child[1];
  low = mid->child[1];
  mid->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = mid; break;
   case 0: mid->parent->child[0] = mid; break;
   case 1: mid->parent->child[1] = mid; break;
  }
  high->child[1] = mid->child[0];
  if (mid->child[0]) mid->child[0]->parent = high;
  mid->child[0] = high;
  high->parent = mid;
  high->balance = high->balance - 1 - ((mid->balance)>(0) ? (mid->balance) : (0));
  mid->balance = mid->balance - 1 + ((high->balance)<(0) ? (high->balance) : (0));
  return mid;
 }
 else if ((high->balance == -2) && (high->child[0]->balance <= 0)) {
  mid = high->child[0];
  low = mid->child[0];
  mid->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = mid; break;
   case 0: mid->parent->child[0] = mid; break;
   case 1: mid->parent->child[1] = mid; break;
  }
  high->child[0] = mid->child[1];
  if (mid->child[1]) mid->child[1]->parent = high;
  mid->child[1] = high;
  high->parent = mid;
  high->balance = high->balance + 1 - ((mid->balance)<(0) ? (mid->balance) : (0));
  mid->balance = mid->balance + 1 + ((high->balance)>(0) ? (high->balance) : (0));
  return mid;
 }
 else if ((high->balance == +2) && (high->child[1]->balance == -1)) {
  mid = high->child[1];
  low = mid->child[0];
  low->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = low; break;
   case 0: low->parent->child[0] = low; break;
   case 1: low->parent->child[1] = low; break;
  }
  high->child[1] = low->child[0];
  if (low->child[0]) low->child[0]->parent = high;
  mid->child[0] = low->child[1];
  if (low->child[1]) low->child[1]->parent = mid;
  low->child[0] = high;
  high->parent = low;
  low->child[1] = mid;
  mid->parent = low;
  high->balance = -((low->balance)>(0) ? (low->balance) : (0));
  mid->balance = -((low->balance)<(0) ? (low->balance) : (0));
  low->balance = 0;
  return low;
 }
 else if ((high->balance == -2) && (high->child[0]->balance == +1)) {
  mid = high->child[0];
  low = mid->child[1];
  low->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = low; break;
   case 0: low->parent->child[0] = low; break;
   case 1: low->parent->child[1] = low; break;
  }
  high->child[0] = low->child[1];
  if (low->child[1]) low->child[1]->parent = high;
  mid->child[1] = low->child[0];
  if (low->child[0]) low->child[0]->parent = mid;
  low->child[1] = high;
  high->parent = low;
  low->child[0] = mid;
  mid->parent = low;
  high->balance = -((low->balance)<(0) ? (low->balance) : (0));
  mid->balance = -((low->balance)>(0) ? (low->balance) : (0));
  low->balance = 0;
  return low;
 } else {
  ((void) sizeof (("This shouldn't happen in balance_node()") ? 1 : 0), __extension__ ({ if ("This shouldn't happen in balance_node()") ; else __assert_fail ("\"This shouldn't happen in balance_node()\"", "dict.c", 194, __extension__ __PRETTY_FUNCTION__); }));
  return ((void *)0);
 }
}

canonical_original_code:
static struct Node *balance_node(struct Dict *tree, struct Node *high)
{
 struct Node *mid = ((void *)0);
 struct Node *low = ((void *)0);
 if ((high->balance == +2) && (high->child[1]->balance >= 0)) {
  mid = high->child[1];
  low = mid->child[1];
  mid->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = mid; break;
   case 0: mid->parent->child[0] = mid; break;
   case 1: mid->parent->child[1] = mid; break;
  }
  high->child[1] = mid->child[0];
  if (mid->child[0]) mid->child[0]->parent = high;
  mid->child[0] = high;
  high->parent = mid;
  high->balance = high->balance - 1 - ((mid->balance)>(0) ? (mid->balance) : (0));
  mid->balance = mid->balance - 1 + ((high->balance)<(0) ? (high->balance) : (0));
  return mid;
 }
 else if ((high->balance == -2) && (high->child[0]->balance <= 0)) {
  mid = high->child[0];
  low = mid->child[0];
  mid->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = mid; break;
   case 0: mid->parent->child[0] = mid; break;
   case 1: mid->parent->child[1] = mid; break;
  }
  high->child[0] = mid->child[1];
  if (mid->child[1]) mid->child[1]->parent = high;
  mid->child[1] = high;
  high->parent = mid;
  high->balance = high->balance + 1 - ((mid->balance)<(0) ? (mid->balance) : (0));
  mid->balance = mid->balance + 1 + ((high->balance)>(0) ? (high->balance) : (0));
  return mid;
 }
 else if ((high->balance == +2) && (high->child[1]->balance == -1)) {
  mid = high->child[1];
  low = mid->child[0];
  low->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = low; break;
   case 0: low->parent->child[0] = low; break;
   case 1: low->parent->child[1] = low; break;
  }
  high->child[1] = low->child[0];
  if (low->child[0]) low->child[0]->parent = high;
  mid->child[0] = low->child[1];
  if (low->child[1]) low->child[1]->parent = mid;
  low->child[0] = high;
  high->parent = low;
  low->child[1] = mid;
  mid->parent = low;
  high->balance = -((low->balance)>(0) ? (low->balance) : (0));
  mid->balance = -((low->balance)<(0) ? (low->balance) : (0));
  low->balance = 0;
  return low;
 }
 else if ((high->balance == -2) && (high->child[0]->balance == +1)) {
  mid = high->child[0];
  low = mid->child[1];
  low->parent = high->parent;
  switch (parent_side (high)) {
   case -1: tree->root = low; break;
   case 0: low->parent->child[0] = low; break;
   case 1: low->parent->child[1] = low; break;
  }
  high->child[0] = low->child[1];
  if (low->child[1]) low->child[1]->parent = high;
  mid->child[1] = low->child[0];
  if (low->child[0]) low->child[0]->parent = mid;
  low->child[1] = high;
  high->parent = low;
  low->child[0] = mid;
  mid->parent = low;
  high->balance = -((low->balance)<(0) ? (low->balance) : (0));
  mid->balance = -((low->balance)>(0) ? (low->balance) : (0));
  low->balance = 0;
  return low;
 } else {
  ((void) sizeof (("This shouldn't happen in balance_node()") ? 1 : 0), __extension__ ({ if ("This shouldn't happen in balance_node()") ; else __assert_fail ("\"This shouldn't happen in balance_node()\"", "dict.c", 194, __extension__ __PRETTY_FUNCTION__); }));
  return ((void *)0);
 }
}

variable_types: struct Dict { struct Node *root; int len; } *

variable_types:
high
struct Node *

return_type: struct Node { struct Node *parent; struct Node *child[2]; char balance; char *key; void *obj; } *


repo: pcercuei/glfrontier

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

v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
free(ptr);
}

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

v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
static void free_node (struct Node *node)
{
 if (node->key) free (node->key);
 free (node);
}

canonical_original_code:
static void free_node(struct Node *node)
{
 if (node->key) free (node->key);
 free (node);
}

variable_types: struct Node { struct Node *parent; struct Node *child[2]; char balance; char *key; void *obj; } *

return_type: void


decompiled_code:
void __fastcall node_recurse_free(_QWORD *a1)
{
if ( a1[1] )
node_recurse_free();
if ( a1[2] )
node_recurse_free();
free_node(a1);
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
if ( a1[1] )
func3();
if ( a1[2] )
func3();
func2(a1);
}

original_code:
static void node_recurse_free (struct Node *node)
{
 if (node->child[0]) {
  node_recurse_free (node->child[0]);
 }
 if (node->child[1]) {
  node_recurse_free (node->child[1]);
 }
 free_node (node);
}

canonical_original_code:
static void node_recurse_free(struct Node *node)
{
 if (node->child[0]) {
  node_recurse_free (node->child[0]);
 }
 if (node->child[1]) {
  node_recurse_free (node->child[1]);
 }
 free_node (node);
}

user_defined_types: struct Node { struct Node *parent; struct Node *child[2]; char balance; char *key; void *obj; }


decompiled_code:
void *alloc_node()
{
return calloc(0x30uLL, 1uLL);
}

canonical_decompiled_code:
void *func4()
{
return calloc(0x30uLL, 1uLL);
}

original_code:
static struct Node *alloc_node ()
{
 struct Node *node = (struct Node *) malloc (sizeof (struct Node));
 memset (node, 0, sizeof (struct Node));
 return node;
}

canonical_original_code:
static struct Node *alloc_node()
{
 struct Node *node = (struct Node *) malloc (sizeof (struct Node));
 memset (node, 0, sizeof (struct Node));
 return node;
}


decompiled_code:
char *__fastcall set_node(__int64 a1, const char *a2, __int64 a3)
{
size_t v4; // rax
char *v5; // rax
char *result; // rax

v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
*(_QWORD *)(a1 + 32) = v5;
result = strcpy(v5, a2);
*(_QWORD *)(a1 + 40) = a3;
return result;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1, const char *a2, __int64 a3)
{
size_t v4; // rax
char *v5; // rax
char *result; // rax

v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
*(_QWORD *)(a1 + 32) = v5;
result = strcpy(v5, a2);
*(_QWORD *)(a1 + 40) = a3;
return result;
}

original_code:
static void set_node (struct Node *node, const char *key, void *obj)
{
 node->key = (char *) malloc (strlen(key)+1);
 strcpy (node->key, key);
 node->obj = obj;
}

canonical_original_code:
static void set_node(struct Node *node, char *key, void *obj)
{
 node->key = (char *) malloc (strlen(key)+1);
 strcpy (node->key, key);
 node->obj = obj;
}

variable_types:
key
char *

variable_types:
obj
void *


decompiled_code:
void __fastcall dict_init(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
void dict_init (struct Dict *tree)
{
 tree->root = ((void *)0);
 tree->len = 0;
}

canonical_original_code:
void dict_init(struct Dict *tree)
{
 tree->root = ((void *)0);
 tree->len = 0;
}

variable_types: struct Dict { struct Node { struct Node *parent; struct Node *child[2]; char balance; char *key; void *obj; } *root; int len; } *

user_defined_types: struct Dict { struct Node *root; int len; }


decompiled_code:
void __fastcall dict_free(_QWORD **a1)
{
node_recurse_free(*a1);
}

canonical_decompiled_code:
void __fastcall func7(_QWORD **a1)
{
func3(*a1);
}

original_code:
void dict_free (struct Dict *tree)
{
 node_recurse_free (tree->root);
}

canonical_original_code:
void dict_free(struct Dict *tree)
{
 node_recurse_free (tree->root);
}


decompiled_code:
__int64 __fastcall dict_get(__int64 *a1, const char *a2)
{
__int64 i; // r12
int v3; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
while ( 1 )
{
v3 = strcmp(*(const char **)(i + 32), a2);
if ( v3 >= 0 )
break;
i = *(_QWORD *)(i + 8);
if ( !i )
return i;
}
if ( !v3 )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, const char *a2)
{
__int64 i; // r12
int v3; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
while ( 1 )
{
v3 = strcmp(*(const char **)(i + 32), a2);
if ( v3 >= 0 )
break;
i = *(_QWORD *)(i + 8);
if ( !i )
return i;
}
if ( !v3 )
break;
}
return i;
}

original_code:
struct Node *dict_get (struct Dict *tree, const char *key)
{
 int cmp;
 struct Node *parent = ((void *)0);
 struct Node *node;
 if (tree->root == ((void *)0)) {
  return ((void *)0);
 }
 node = tree->root;
 while (1) {
  if ((parent) && (node == ((void *)0)))
   return ((void *)0);
  cmp = strcmp (node->key, key);
  if (cmp < 0) {
   parent = node;
   node = node->child[0];
  } else if (cmp > 0) {
   parent = node;
   node = node->child[1];
  } else {
   return node;
  }
 }
}

canonical_original_code:
struct Node *dict_get(struct Dict *tree, char *key)
{
 int cmp;
 struct Node *parent = ((void *)0);
 struct Node *node;
 if (tree->root == ((void *)0)) {
  return ((void *)0);
 }
 node = tree->root;
 while (1) {
  if ((parent) && (node == ((void *)0)))
   return ((void *)0);
  cmp = strcmp (node->key, key);
  if (cmp < 0) {
   parent = node;
   node = node->child[0];
  } else if (cmp > 0) {
   parent = node;
   node = node->child[1];
  } else {
   return node;
  }
 }
}

variable_types: cmp int


original_code:
void dict_remove (struct Dict *tree, const char *key)
{
 int side;
 struct Node *to_remove;
 struct Node *iter;
 struct Node *rem_pos;
 int rem_dir;
 to_remove = dict_get (tree, key);
 if (to_remove == ((void *)0)) return;
 side = parent_side (to_remove);
 if ((to_remove->child[0] == ((void *)0)) && (to_remove->child[1] == ((void *)0))) {
  if (side == -1) {
   tree->root = ((void *)0);
  } else {
   to_remove->parent->child[side] = ((void *)0);
  }
  rem_pos = to_remove->parent;
  rem_dir = side;
 } else if (to_remove->child[0] == ((void *)0)) {
  if (side == -1) {
   tree->root = to_remove->child[1];
  } else {
   to_remove->parent->child[side] = to_remove->child[1];
  }
  to_remove->child[1]->parent = to_remove->parent;
  rem_pos = to_remove->parent;
  rem_dir = side;
 } else if (to_remove->child[1] == ((void *)0)) {
  if (side == -1) {
   tree->root = to_remove->child[0];
  } else {
   to_remove->parent->child[side] = to_remove->child[0];
  }
  to_remove->child[0]->parent = to_remove->parent;
  rem_pos = to_remove->parent;
  rem_dir = side;
 } else {
  iter = to_remove->child[0];
  while (iter->child[1]) {
   iter = iter->child[1];
  }
  if (iter->child[0]) {
   iter->child[0]->parent = iter->parent;
   iter->parent->child[parent_side (iter)] = iter->child[0];
   iter->child[0] = ((void *)0);
  } else {
   iter->parent->child[parent_side (iter)] = ((void *)0);
  }
  rem_pos = iter->parent;
  rem_dir = 1;
  if (rem_pos == to_remove) {
   rem_pos = iter;
   rem_dir = 0;
  }
  switch (parent_side (to_remove)) {
   case -1:
    tree->root = iter;
    iter->parent = ((void *)0);
    break;
   case 0:
    iter->parent = to_remove->parent;
    iter->parent->child[0] = iter;
    break;
   case 1:
    iter->parent = to_remove->parent;
    iter->parent->child[1] = iter;
    break;
  }
  if ((to_remove->child[0] != ((void *)0)) &&
      (to_remove->child[0] != iter)) {
   iter->child[0] = to_remove->child[0];
   iter->child[0]->parent = iter;
  } else {
   iter->child[0] = ((void *)0);
  }
  if ((to_remove->child[1] != ((void *)0)) &&
      (to_remove->child[1] != iter)) {
   iter->child[1] = to_remove->child[1];
   iter->child[1]->parent = iter;
  } else {
   iter->child[1] = ((void *)0);
  }
  iter->balance = to_remove->balance;
 }
 iter = rem_pos;
 ((void) sizeof ((iter != to_remove) ? 1 : 0), __extension__ ({ if (iter != to_remove) ; else __assert_fail ("iter != to_remove", "dict.c", 323, __extension__ __PRETTY_FUNCTION__); }));
 while (iter) {
  switch (rem_dir) {
   case 0: side = -1; break;
   case 1: side = 1; break;
  }
  iter->balance -= side;
  if (abs (iter->balance) >= 2) {
   iter = balance_node (tree, iter);
   if (iter->balance != 0) return;
  } else if (abs (iter->balance) == 1) {
   break;
  }
  rem_dir = parent_side (iter);
  iter = iter->parent;
 }
 free_node (to_remove);
}

canonical_original_code:
void dict_remove(struct Dict *tree, char *key)
{
 int side;
 struct Node *to_remove;
 struct Node *iter;
 struct Node *rem_pos;
 int rem_dir;
 to_remove = dict_get (tree, key);
 if (to_remove == ((void *)0)) return;
 side = parent_side (to_remove);
 if ((to_remove->child[0] == ((void *)0)) && (to_remove->child[1] == ((void *)0))) {
  if (side == -1) {
   tree->root = ((void *)0);
  } else {
   to_remove->parent->child[side] = ((void *)0);
  }
  rem_pos = to_remove->parent;
  rem_dir = side;
 } else if (to_remove->child[0] == ((void *)0)) {
  if (side == -1) {
   tree->root = to_remove->child[1];
  } else {
   to_remove->parent->child[side] = to_remove->child[1];
  }
  to_remove->child[1]->parent = to_remove->parent;
  rem_pos = to_remove->parent;
  rem_dir = side;
 } else if (to_remove->child[1] == ((void *)0)) {
  if (side == -1) {
   tree->root = to_remove->child[0];
  } else {
   to_remove->parent->child[side] = to_remove->child[0];
  }
  to_remove->child[0]->parent = to_remove->parent;
  rem_pos = to_remove->parent;
  rem_dir = side;
 } else {
  iter = to_remove->child[0];
  while (iter->child[1]) {
   iter = iter->child[1];
  }
  if (iter->child[0]) {
   iter->child[0]->parent = iter->parent;
   iter->parent->child[parent_side (iter)] = iter->child[0];
   iter->child[0] = ((void *)0);
  } else {
   iter->parent->child[parent_side (iter)] = ((void *)0);
  }
  rem_pos = iter->parent;
  rem_dir = 1;
  if (rem_pos == to_remove) {
   rem_pos = iter;
   rem_dir = 0;
  }
  switch (parent_side (to_remove)) {
   case -1:
    tree->root = iter;
    iter->parent = ((void *)0);
    break;
   case 0:
    iter->parent = to_remove->parent;
    iter->parent->child[0] = iter;
    break;
   case 1:
    iter->parent = to_remove->parent;
    iter->parent->child[1] = iter;
    break;
  }
  if ((to_remove->child[0] != ((void *)0)) &&
      (to_remove->child[0] != iter)) {
   iter->child[0] = to_remove->child[0];
   iter->child[0]->parent = iter;
  } else {
   iter->child[0] = ((void *)0);
  }
  if ((to_remove->child[1] != ((void *)0)) &&
      (to_remove->child[1] != iter)) {
   iter->child[1] = to_remove->child[1];
   iter->child[1]->parent = iter;
  } else {
   iter->child[1] = ((void *)0);
  }
  iter->balance = to_remove->balance;
 }
 iter = rem_pos;
 ((void) sizeof ((iter != to_remove) ? 1 : 0), __extension__ ({ if (iter != to_remove) ; else __assert_fail ("iter != to_remove", "dict.c", 323, __extension__ __PRETTY_FUNCTION__); }));
 while (iter) {
  switch (rem_dir) {
   case 0: side = -1; break;
   case 1: side = 1; break;
  }
  iter->balance -= side;
  if (abs (iter->balance) >= 2) {
   iter = balance_node (tree, iter);
   if (iter->balance != 0) return;
  } else if (abs (iter->balance) == 1) {
   break;
  }
  rem_dir = parent_side (iter);
  iter = iter->parent;
 }
 free_node (to_remove);
}

variable_types: side int


original_code:
int dict_set (struct Dict *tree, const char *key, void *obj)
{
 int cmp = 0;
 int side;
 struct Node *parent = ((void *)0);
 struct Node *node;
 if (tree->root == ((void *)0)) {
  tree->root = alloc_node ();
  set_node (tree->root, key, obj);
  tree->len++;
  return 1;
 }
 node = tree->root;
 while (1) {
  if ((parent) && (node == ((void *)0)))
   break;
  cmp = strcmp (node->key, key);
  if (cmp < 0) {
   parent = node;
   node = node->child[0];
  } else if (cmp > 0) {
   parent = node;
   node = node->child[1];
  } else {
   node->obj = obj;
   return 0;
  }
 }
 node = alloc_node ();
 set_node (node, key, obj);
 tree->len++;
 if (cmp < 0) {
  parent->child[0] = node;
 } else {
  parent->child[1] = node;
 }
 node->parent = parent;
 while (parent) {
  if (parent->child[0] == node) {
   side = -1;
  } else {
   side = +1;
  }
  parent->balance += side;
  if (abs (parent->balance) >= 2) {
   parent = balance_node (tree, parent);
   if (parent->balance == 0) return 1;
  } else if (parent->balance == 0) {
   break;
  }
  node = parent;
  parent = node->parent;
 }
 return 1;
}

canonical_original_code:
int dict_set(struct Dict *tree, char *key, void *obj)
{
 int cmp = 0;
 int side;
 struct Node *parent = ((void *)0);
 struct Node *node;
 if (tree->root == ((void *)0)) {
  tree->root = alloc_node ();
  set_node (tree->root, key, obj);
  tree->len++;
  return 1;
 }
 node = tree->root;
 while (1) {
  if ((parent) && (node == ((void *)0)))
   break;
  cmp = strcmp (node->key, key);
  if (cmp < 0) {
   parent = node;
   node = node->child[0];
  } else if (cmp > 0) {
   parent = node;
   node = node->child[1];
  } else {
   node->obj = obj;
   return 0;
  }
 }
 node = alloc_node ();
 set_node (node, key, obj);
 tree->len++;
 if (cmp < 0) {
  parent->child[0] = node;
 } else {
  parent->child[1] = node;
 }
 node->parent = parent;
 while (parent) {
  if (parent->child[0] == node) {
   side = -1;
  } else {
   side = +1;
  }
  parent->balance += side;
  if (abs (parent->balance) >= 2) {
   parent = balance_node (tree, parent);
   if (parent->balance == 0) return 1;
  } else if (parent->balance == 0) {
   break;
  }
  node = parent;
  parent = node->parent;
 }
 return 1;
}

return_type: int


repo: pcercuei/libxdgmime

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

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

original_code:
static int
icon_entry_cmp (const void *v1, const void *v2)
{
  return strcmp (((XdgIcon *)v1)->mime_type, ((XdgIcon *)v2)->mime_type);
}

canonical_original_code:
static int icon_entry_cmp(void *v1, void *v2)
{
  return strcmp (((struct XdgIcon *)v1)->mime_type, ((struct XdgIcon *)v2)->mime_type);
}

user_defined_types: struct XdgIcon { char *mime_type; char *icon_name; }


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

original_code:
static int
alias_entry_cmp (const void *v1, const void *v2)
{
  return strcmp (((XdgAlias *)v1)->alias, ((XdgAlias *)v2)->alias);
}

canonical_original_code:
static int alias_entry_cmp(void *v1, void *v2)
{
  return strcmp (((struct XdgAlias *)v1)->alias, ((struct XdgAlias *)v2)->alias);
}

user_defined_types: struct XdgAlias { char *alias; char *mime_type; }


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

original_code:
static int
parent_entry_cmp (const void *v1, const void *v2)
{
  return strcmp (((XdgMimeParents *)v1)->mime, ((XdgMimeParents *)v2)->mime);
}

canonical_original_code:
static int parent_entry_cmp(void *v1, void *v2)
{
  return strcmp (((struct XdgMimeParents *)v1)->mime, ((struct XdgMimeParents *)v2)->mime);
}

user_defined_types: struct XdgMimeParents { char *mime; char **parents; int n_parents; }


main

canonical_name: main

repo: pclewis/dc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
FILE *v4; // rbp
unsigned __int8 v5; // al
int v6; // eax

if ( argc == 2 )
{
v4 = (FILE *)fopen_safe((char)argv[1]);
if ( v4 )
{
while ( 1 )
{
v6 = fgetc(v4);
if ( v6 == -1 )
break;
v5 = reverseBits((unsigned __int8)v6);
fputc(v5, stdout);
}
fclose(v4);
result = 0;
}
else
{
result = 1;
}
}
else
{
fprintf(stderr, "Usage: %s [f1]\n", *argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
FILE *v4; // rbp
unsigned __int8 v5; // al
int v6; // eax

if ( argc == 2 )
{
v4 = (FILE *)fopen_safe((char)argv[1]);
if ( v4 )
{
while ( 1 )
{
v6 = fgetc(v4);
if ( v6 == -1 )
break;
v5 = func7((unsigned __int8)v6);
fputc(v5, stdout);
}
fclose(v4);
result = 0;
}
else
{
result = 1;
}
}
else
{
fprintf(stderr, "Usage: %s [f1]\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 int status = 1;
 if(argc < 3) {
  printf("Usage: %s keyfile...\n", argv[0]);
  goto done;
 }
 Relation *relation = calloc(1, sizeof(Relation));
 for(int i = 1; i < argc; ++i) {
  relate(relation, argv[i]);
 }
 for(size_t ki = 0; ki < 240; ++ki) {
  for(int bi = 0; bi < 8; ++bi) {
   for(int bv = 0; bv < 2; ++bv) {
    if( relation->cnt[ki][bi][bv] < 2) {
     printf("Didn't see enough key index %zu bit %d with value %d\n", ki, bi, bv);
     continue;
    }
    for(size_t si = 0; si < 240; ++si) {
     for(int sb = 0; sb < 8; ++sb) {
      if(((relation->related[ki][bi][bv][si]&(1<<(sb)))!=0))
       printf("key %zu bit %d = %d, scr %zu bit %d = %d, cnt=%d\n", ki, bi, bv, si, sb, ((relation->value[ki][bi][bv][si]&(1<<(sb)))!=0) ? 1 : 0, relation->cnt[ki][bi][bv]);
     }
    }
   }
  }
 }
 printf("Welp.\n");
 status = 0;
 done:
 return status;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int status = 1;
 if(argc < 3) {
  printf("Usage: %s keyfile...\n", argv[0]);
  goto done;
 }
 struct Relation *relation = calloc(1, sizeof(Relation));
 for(int i = 1; i < argc; ++i) {
  relate(relation, argv[i]);
 }
 for(unsigned long ki = 0; ki < 240; ++ki) {
  for(int bi = 0; bi < 8; ++bi) {
   for(int bv = 0; bv < 2; ++bv) {
    if( relation->cnt[ki][bi][bv] < 2) {
     printf("Didn't see enough key index %zu bit %d with value %d\n", ki, bi, bv);
     continue;
    }
    for(unsigned long si = 0; si < 240; ++si) {
     for(int sb = 0; sb < 8; ++sb) {
      if(((relation->related[ki][bi][bv][si]&(1<<(sb)))!=0))
       printf("key %zu bit %d = %d, scr %zu bit %d = %d, cnt=%d\n", ki, bi, bv, si, sb, ((relation->value[ki][bi][bv][si]&(1<<(sb)))!=0) ? 1 : 0, relation->cnt[ki][bi][bv]);
     }
    }
   }
  }
 }
 printf("Welp.\n");
 status = 0;
 done:
 return status;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: status int

variable_types: struct Relation { int cnt[240][8][2]; unsigned char value[240][8][2][240]; unsigned char related[240][8][2][240]; } *

variable_types: i int

variable_types:
ki
unsigned long

variable_types: bi int

variable_types: bv int

variable_types:
si
unsigned long

variable_types: sb int


reverseBits

original_code:
static inline uint8_t reverseBits(uint8_t b) {
 return ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}

canonical_original_code:
static inline unsigned char reverseBits(unsigned char b) {
 return ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}

variable_types:
b
unsigned char

return_type: unsigned char


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void die(const char *fmt, ...) {
 va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
 exit(1);
}

canonical_original_code:
void die(char *fmt, ...) {
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
 exit(1);
}

variable_types:
fmt
char *


decompiled_code:
void *__fastcall realloc_safe(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
die("Realloc failed. Requested size: %zu", a2);
return result;
}

canonical_decompiled_code:
void *__fastcall func15(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
func8("Realloc failed. Requested size: %zu", a2);
return result;
}

original_code:
void *realloc_safe(void *ptr, size_t size) {
 void *result = realloc(ptr, size);
 if(result == ((void *)0)) die("Realloc failed. Requested size: %zu", size);
 return result;
}

canonical_original_code:
void *realloc_safe(void *ptr, unsigned long size) {
 void *result = realloc(ptr, size);
 if(result == ((void *)0)) die("Realloc failed. Requested size: %zu", size);
 return result;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
result
void *

return_type: void *


decompiled_code:
void *__fastcall calloc_safe(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
die("Calloc failed. Requested size: %zu", a2 * a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func16(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
func8("Calloc failed. Requested size: %zu", a2 * a1);
return result;
}

original_code:
void *calloc_safe(size_t nmemb, size_t size) {
 void *result = calloc(nmemb, size);
 if(result == ((void *)0)) die("Calloc failed. Requested size: %zu", nmemb*size);
 return result;
}

canonical_original_code:
void *calloc_safe(unsigned long nmemb, unsigned long size) {
 void *result = calloc(nmemb, size);
 if(result == ((void *)0)) die("Calloc failed. Requested size: %zu", nmemb*size);
 return result;
}

variable_types:
nmemb
unsigned long


main

repo: pcx/misc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
int *v4; // rax
int *v5; // r13
unsigned int v6; // ebx
int v7; // er12
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // ebx
char *v11; // r8
char *v13; // r8
char *v14; // r8

v3 = (_QWORD *)Stack_create(argc, argv, envp);
v4 = __errno_location();
v5 = v4;
if ( v3 )
{
v6 = 1;
fprintf(stderr, "[INFO] (%s:%d) Created an empty stack data structure.\n", "src/stack_example.c", 13LL);
do
{
v7 = ((__int64 (__fastcall *)(_QWORD *, _QWORD))v3[2])(v3, v6);
if ( v7 )
{
v14 = "None";
if ( *v5 )
v14 = strerror(*v5);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Failed to push onto stack.\n", "src/stack_example.c", 17LL, v14);
*v5 = 0;
goto LABEL_12;
}
++v6;
}
while ( v6 != 7 );
v8 = ((__int64 (__fastcall *)(_QWORD))v3[4])(*v3);
fprintf(
stderr,
"[INFO] (%s:%d) Pushed numbers 1-6 onto the stack. Stack size is now %d.\n",
"src/stack_example.c",
19LL,
v8);
fprintf(stderr, "[INFO] (%s:%d) Now emptying stack by poping all its elements:\n", "src/stack_example.c", 21LL);
while ( 1 )
{
v10 = ((__int64 (__fastcall *)(_QWORD *))v3[3])(v3);
if ( *v5 )
{
if ( !strerror(*v5) )
break;
}
v9 = ((__int64 (__fastcall *)(_QWORD))v3[4])(*v3);
fprintf(stderr, "[INFO] (%s:%d) Popped %d. Stack size is now %d.\n", "src/stack_example.c", 29LL, v10, v9);
if ( !*v3 )
{
fprintf(stderr, "[INFO] (%s:%d) Stack is now empty. Bye bye.\n", "src/stack_example.c", 31LL);
free(v3);
return v7;
}
}
v11 = "None";
if ( *v5 )
v11 = strerror(*v5);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) Failed to pop off the stack. Something's wrong.\n",
"src/stack_example.c",
26LL,
v11);
*v5 = 0;
LABEL_12:
v7 = -1;
free(v3);
}
else
{
v13 = "None";
if ( *v4 )
v13 = strerror(*v4);
v7 = -1;
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/stack_example.c", 12LL, v13);
*v5 = 0;
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
int *v4; // rax
int *v5; // r13
unsigned int v6; // ebx
int v7; // er12
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // ebx
char *v11; // r8
char *v13; // r8
char *v14; // r8

v3 = (_QWORD *)func7(argc, argv, envp);
v4 = __errno_location();
v5 = v4;
if ( v3 )
{
v6 = 1;
fprintf(stderr, "[INFO] (%s:%d) Created an empty stack data structure.\n", "src/stack_example.c", 13LL);
do
{
v7 = ((__int64 (__fastcall *)(_QWORD *, _QWORD))v3[2])(v3, v6);
if ( v7 )
{
v14 = "None";
if ( *v5 )
v14 = strerror(*v5);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Failed to push onto stack.\n", "src/stack_example.c", 17LL, v14);
*v5 = 0;
goto LABEL_12;
}
++v6;
}
while ( v6 != 7 );
v8 = ((__int64 (__fastcall *)(_QWORD))v3[4])(*v3);
fprintf(
stderr,
"[INFO] (%s:%d) Pushed numbers 1-6 onto the stack. Stack size is now %d.\n",
"src/stack_example.c",
19LL,
v8);
fprintf(stderr, "[INFO] (%s:%d) Now emptying stack by poping all its elements:\n", "src/stack_example.c", 21LL);
while ( 1 )
{
v10 = ((__int64 (__fastcall *)(_QWORD *))v3[3])(v3);
if ( *v5 )
{
if ( !strerror(*v5) )
break;
}
v9 = ((__int64 (__fastcall *)(_QWORD))v3[4])(*v3);
fprintf(stderr, "[INFO] (%s:%d) Popped %d. Stack size is now %d.\n", "src/stack_example.c", 29LL, v10, v9);
if ( !*v3 )
{
fprintf(stderr, "[INFO] (%s:%d) Stack is now empty. Bye bye.\n", "src/stack_example.c", 31LL);
free(v3);
return v7;
}
}
v11 = "None";
if ( *v5 )
v11 = strerror(*v5);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) Failed to pop off the stack. Something's wrong.\n",
"src/stack_example.c",
26LL,
v11);
*v5 = 0;
LABEL_12:
v7 = -1;
free(v3);
}
else
{
v13 = "None";
if ( *v4 )
v13 = strerror(*v4);
v7 = -1;
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/stack_example.c", 12LL, v13);
*v5 = 0;
}
return v7;
}

original_code:
int main(int argc, char **argv)
{
     LinkedStack *st = Stack_create();
     if(!((st))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/stack_example.c", 12, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     fprintf(stderr, "[INFO] (%s:%d) " "Created an empty stack data structure." "\n", "src/stack_example.c", 13);
     for(int i = 1; i <= 6; i++) {
   if(st->push(&(st->_head), i) != 0)
        { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Failed to push onto stack." "\n", "src/stack_example.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     }
     fprintf(stderr, "[INFO] (%s:%d) " "Pushed numbers 1-6 onto the stack. Stack size is now %d." "\n", "src/stack_example.c", 19, st->size(st->_head));
     fprintf(stderr, "[INFO] (%s:%d) " "Now emptying stack by poping all its elements:" "\n", "src/stack_example.c", 21);
     int i, v = 0;
     for(i = 1; ; i++) {
   v = st->pop(&(st->_head));
   if(!((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))) {
        { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Failed to pop off the stack. Something's wrong." "\n", "src/stack_example.c", 26, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   }
   fprintf(stderr, "[INFO] (%s:%d) " "Popped %d. Stack size is now %d." "\n", "src/stack_example.c", 29, v, st->size(st->_head));
   if(!st->_head) {
        fprintf(stderr, "[INFO] (%s:%d) " "Stack is now empty. Bye bye." "\n", "src/stack_example.c", 31);
        break;
   }
     }
     if(st) free(st);
     return 0;
error:
     if(st) free(st);
     return -1;
}

canonical_original_code:
int main(int argc, char **argv)
{
     struct LinkedStack *st = Stack_create();
     if(!((st))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/stack_example.c", 12, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     fprintf(stderr, "[INFO] (%s:%d) " "Created an empty stack data structure." "\n", "src/stack_example.c", 13);
     for(int i = 1; i <= 6; i++) {
   if(st->push(&(st->_head), i) != 0)
        { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Failed to push onto stack." "\n", "src/stack_example.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     }
     fprintf(stderr, "[INFO] (%s:%d) " "Pushed numbers 1-6 onto the stack. Stack size is now %d." "\n", "src/stack_example.c", 19, st->size(st->_head));
     fprintf(stderr, "[INFO] (%s:%d) " "Now emptying stack by poping all its elements:" "\n", "src/stack_example.c", 21);
     int i; int v = 0;
     for(i = 1; ; i++) {
   v = st->pop(&(st->_head));
   if(!((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))) {
        { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Failed to pop off the stack. Something's wrong." "\n", "src/stack_example.c", 26, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   }
   fprintf(stderr, "[INFO] (%s:%d) " "Popped %d. Stack size is now %d." "\n", "src/stack_example.c", 29, v, st->size(st->_head));
   if(!st->_head) {
        fprintf(stderr, "[INFO] (%s:%d) " "Stack is now empty. Bye bye." "\n", "src/stack_example.c", 31);
        break;
   }
     }
     if(st) free(st);
     return 0;
error:
     if(st) free(st);
     return -1;
}

variable_types:
argv
char **

variable_types: struct LinkedStack { struct linked_element { int val; _Bool set; struct linked_element *next; } *_head; int (*head)(struct linked_element *el); int (*push)(struct linked_element **el, int i); int (*pop)(struct linked_element **el); int (*size)(struct linked_element *el); } *

variable_types: v int

user_defined_types: struct LinkedStack { struct linked_element *_head; int (*head)(struct linked_element *el); int (*push)(struct linked_element **el, int i); int (*pop)(struct linked_element **el); int (*size)(struct linked_element *el); }


decompiled_code:
_QWORD *Stack_create()
{
_QWORD *v0; // r12
_BYTE *v1; // rax
int *v3; // rax
char *v4; // r8
int *v5; // rbx
int *v6; // rax
char *v7; // r8
int *v8; // rbx
void *v9; // rdi

v0 = malloc(0x28uLL);
if ( v0 )
{
v1 = malloc(0x18uLL);
*v0 = v1;
if ( v1 )
{
*(_DWORD *)v1 = 0;
v1[4] = 0;
*((_QWORD *)v1 + 1) = 0LL;
*((_QWORD *)v1 + 2) = 0LL;
v0[1] = head;
v0[2] = push;
v0[3] = pop;
v0[4] = size;
}
else
{
v6 = __errno_location();
v7 = "None";
v8 = v6;
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/stack.c", 15LL, v7);
*v8 = 0;
v9 = v0;
v0 = 0LL;
free(v9);
}
}
else
{
v3 = __errno_location();
v4 = "None";
v5 = v3;
if ( *v3 )
v4 = strerror(*v3);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/stack.c", 12LL, v4);
*v5 = 0;
}
return v0;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // r12
_BYTE *v1; // rax
int *v3; // rax
char *v4; // r8
int *v5; // rbx
int *v6; // rax
char *v7; // r8
int *v8; // rbx
void *v9; // rdi

v0 = malloc(0x28uLL);
if ( v0 )
{
v1 = malloc(0x18uLL);
*v0 = v1;
if ( v1 )
{
*(_DWORD *)v1 = 0;
v1[4] = 0;
*((_QWORD *)v1 + 1) = 0LL;
*((_QWORD *)v1 + 2) = 0LL;
v0[1] = head;
v0[2] = push;
v0[3] = pop;
v0[4] = size;
}
else
{
v6 = __errno_location();
v7 = "None";
v8 = v6;
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/stack.c", 15LL, v7);
*v8 = 0;
v9 = v0;
v0 = 0LL;
free(v9);
}
}
else
{
v3 = __errno_location();
v4 = "None";
v5 = v3;
if ( *v3 )
v4 = strerror(*v3);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/stack.c", 12LL, v4);
*v5 = 0;
}
return v0;
}

original_code:
LinkedStack *Stack_create()
{
     LinkedStack *st = (LinkedStack *) malloc(sizeof(LinkedStack));
     if(!((st))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/stack.c", 12, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     st->_head = (linked_element *) malloc(sizeof(linked_element));
     if(!((st->_head))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/stack.c", 15, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     st->_head->val = 0;
     st->_head->set = 0;
     st->_head->next = ((void *)0);
     st->_head->prev = ((void *)0);
     st->head = head;
     st->push = push;
     st->pop = pop;
     st->size = size;
     return st;
error:
     if(st) free(st);
     return ((void *)0);
}

canonical_original_code:
struct LinkedStack *Stack_create()
{
     struct LinkedStack *st = (LinkedStack *) malloc(sizeof(LinkedStack));
     if(!((st))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/stack.c", 12, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     st->_head = (struct linked_element *) malloc(sizeof(linked_element));
     if(!((st->_head))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/stack.c", 15, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     st->_head->val = 0;
     st->_head->set = 0;
     st->_head->next = ((void *)0);
     st->_head->prev = ((void *)0);
     st->head = head;
     st->push = push;
     st->pop = pop;
     st->size = size;
     return st;
error:
     if(st) free(st);
     return ((void *)0);
}

return_type: struct LinkedStack { struct linked_element { int val; _Bool set; struct linked_element *next; } *_head; int (*head)(struct linked_element *el); int (*push)(struct linked_element **el, int i); int (*pop)(struct linked_element **el); int (*size)(struct linked_element *el); } *


head

decompiled_code:
__int64 __fastcall head(unsigned int *a1)
{
int *v2; // rax
char *v3; // r8
int *v4; // rbx

if ( a1 )
return *a1;
v2 = __errno_location();
v3 = "None";
v4 = v2;
if ( *v2 )
v3 = strerror(*v2);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) Cannot access property of a null pointer.\n",
"src/linked_list.c",
14LL,
v3);
*v4 = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
int *v2; // rax
char *v3; // r8
int *v4; // rbx

if ( a1 )
return *a1;
v2 = __errno_location();
v3 = "None";
v4 = v2;
if ( *v2 )
v3 = strerror(*v2);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) Cannot access property of a null pointer.\n",
"src/linked_list.c",
14LL,
v3);
*v4 = 0;
return 0xFFFFFFFFLL;
}

original_code:
int head(linked_element *el)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Cannot access property of a null pointer." "\n", "src/linked_list.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     return el->val;
error:
     return -1;
}

canonical_original_code:
int head(struct linked_element *el)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Cannot access property of a null pointer." "\n", "src/linked_list.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     return el->val;
error:
     return -1;
}

variable_types: struct linked_element { int val; _Bool set; struct linked_element *next; } *


size

decompiled_code:
__int64 __fastcall size(__int64 a1)
{
unsigned int i; // er8
__int64 v2; // rax

i = 0;
if ( a1 )
{
v2 = *(_QWORD *)(a1 + 8);
for ( i = 1; v2; ++i )
v2 = *(_QWORD *)(v2 + 8);
}
return i;
}

original_code:
int size(linked_element *el)
{
     if(!el) {
   return 0;
     } else {
   int i = 1;
   while(1) {
        if(el->next) {
      i++;
      el = el->next;
        } else {
      break;
        }
   }
   return i;
     }
}

canonical_original_code:
int size(struct linked_element *el)
{
     if(!el) {
   return 0;
     } else {
   int i = 1;
   while(1) {
        if(el->next) {
      i++;
      el = el->next;
        } else {
      break;
        }
   }
   return i;
     }
}

user_defined_types: struct linked_element { int val; _Bool set; struct linked_element *next; }


push

decompiled_code:
__int64 __fastcall push(__int64 *a1, int a2)
{
__int64 v2; // rbp
__int64 result; // rax
_QWORD *v4; // rax
int *v5; // rax
char *v6; // r8
int *v7; // rbx
int *v8; // rax
char *v9; // r8
int *v10; // rax
char *v11; // r8

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( !*(_BYTE *)(v2 + 4) )
{
*(_DWORD *)v2 = a2;
result = 0LL;
*(_BYTE *)(v2 + 4) = 1;
return result;
}
v4 = malloc(0x18uLL);
if ( v4 )
{
v4[2] = 0LL;
v4[1] = v2;
*(_DWORD *)v4 = a2;
*((_BYTE *)v4 + 4) = 1;
*(_QWORD *)(v2 + 16) = v4;
*a1 = (__int64)v4;
return 0LL;
}
v10 = __errno_location();
v11 = "None";
v7 = v10;
if ( *v10 )
v11 = strerror(*v10);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 50LL, v11);
}
else
{
v5 = __errno_location();
v6 = "None";
v7 = v5;
if ( *v5 )
v6 = strerror(*v5);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 43LL, v6);
}
}
else
{
v8 = __errno_location();
v9 = "None";
v7 = v8;
if ( *v8 )
v9 = strerror(*v8);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 40LL, v9);
}
*v7 = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, int a2)
{
__int64 v2; // rbp
__int64 result; // rax
_QWORD *v4; // rax
int *v5; // rax
char *v6; // r8
int *v7; // rbx
int *v8; // rax
char *v9; // r8
int *v10; // rax
char *v11; // r8

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( !*(_BYTE *)(v2 + 4) )
{
*(_DWORD *)v2 = a2;
result = 0LL;
*(_BYTE *)(v2 + 4) = 1;
return result;
}
v4 = malloc(0x18uLL);
if ( v4 )
{
v4[2] = 0LL;
v4[1] = v2;
*(_DWORD *)v4 = a2;
*((_BYTE *)v4 + 4) = 1;
*(_QWORD *)(v2 + 16) = v4;
*a1 = (__int64)v4;
return 0LL;
}
v10 = __errno_location();
v11 = "None";
v7 = v10;
if ( *v10 )
v11 = strerror(*v10);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 50LL, v11);
}
else
{
v5 = __errno_location();
v6 = "None";
v7 = v5;
if ( *v5 )
v6 = strerror(*v5);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 43LL, v6);
}
}
else
{
v8 = __errno_location();
v9 = "None";
v7 = v8;
if ( *v8 )
v9 = strerror(*v8);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 40LL, v9);
}
*v7 = 0;
return 0xFFFFFFFFLL;
}

original_code:
int push(linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 40, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 43, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     if(!_el->set) {
   _el->val = i;
   _el->set = 1;
     } else {
   linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 50, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->prev = ((void *)0);
   el_new->next = _el;
   el_new->val = i;
   el_new->set = 1;
   _el->prev = el_new;
   *el = el_new;
     }
     return 0;
error:
     return -1;
}

canonical_original_code:
int push(struct linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 40, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 43, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     if(!_el->set) {
   _el->val = i;
   _el->set = 1;
     } else {
   struct linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 50, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->prev = ((void *)0);
   el_new->next = _el;
   el_new->val = i;
   el_new->set = 1;
   _el->prev = el_new;
   *el = el_new;
     }
     return 0;
error:
     return -1;
}

variable_types: struct linked_element { int val; _Bool set; struct linked_element *next; } **


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

for ( result = a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

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

for ( result = a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

original_code:
linked_element *get_tail(linked_element *el)
{
     while(1) {
   if(el && el->next) {
        el = el->next;
   } else {
        return el;
   }
     }
}

canonical_original_code:
struct linked_element *get_tail(struct linked_element *el)
{
     while(1) {
   if(el && el->next) {
        el = el->next;
   } else {
        return el;
   }
     }
}

variable_types:
el
struct linked_element *

return_type: struct linked_element { int val; _Bool set; struct linked_element *next; } *


inject

decompiled_code:
__int64 __fastcall inject(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rbx
_QWORD *v5; // rax
int *v7; // rax
char *v8; // r8
int *v9; // rbx
int *v10; // rax
char *v11; // r8
int *v12; // rax
char *v13; // r8

if ( !a1 )
{
v12 = __errno_location();
v13 = "None";
v9 = v12;
if ( *v12 )
v13 = strerror(*v12);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 85LL, v13);
goto LABEL_11;
}
v2 = *a1;
if ( !v2 )
{
v7 = __errno_location();
v8 = "None";
v9 = v7;
if ( *v7 )
v8 = strerror(*v7);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 88LL, v8);
goto LABEL_11;
}
v3 = get_tail(v2);
v4 = v3;
if ( !v3 )
{
if ( malloc(0x18uLL) )
return 0LL;
LABEL_13:
v10 = __errno_location();
v11 = "None";
v9 = v10;
if ( *v10 )
v11 = strerror(*v10);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 97LL, v11);
LABEL_11:
*v9 = 0;
return 1LL;
}
if ( *(_BYTE *)(v3 + 4) )
{
v5 = malloc(0x18uLL);
if ( v5 )
{
v5[1] = 0LL;
*(_DWORD *)v5 = a2;
*((_BYTE *)v5 + 4) = 1;
v5[2] = v4;
*(_QWORD *)(v4 + 8) = v5;
return 0LL;
}
goto LABEL_13;
}
*(_DWORD *)v3 = a2;
*(_BYTE *)(v3 + 4) = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rbx
_QWORD *v5; // rax
int *v7; // rax
char *v8; // r8
int *v9; // rbx
int *v10; // rax
char *v11; // r8
int *v12; // rax
char *v13; // r8

if ( !a1 )
{
v12 = __errno_location();
v13 = "None";
v9 = v12;
if ( *v12 )
v13 = strerror(*v12);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 85LL, v13);
goto LABEL_11;
}
v2 = *a1;
if ( !v2 )
{
v7 = __errno_location();
v8 = "None";
v9 = v7;
if ( *v7 )
v8 = strerror(*v7);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 88LL, v8);
goto LABEL_11;
}
v3 = func11(v2);
v4 = v3;
if ( !v3 )
{
if ( malloc(0x18uLL) )
return 0LL;
LABEL_13:
v10 = __errno_location();
v11 = "None";
v9 = v10;
if ( *v10 )
v11 = strerror(*v10);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 97LL, v11);
LABEL_11:
*v9 = 0;
return 1LL;
}
if ( *(_BYTE *)(v3 + 4) )
{
v5 = malloc(0x18uLL);
if ( v5 )
{
v5[1] = 0LL;
*(_DWORD *)v5 = a2;
*((_BYTE *)v5 + 4) = 1;
v5[2] = v4;
*(_QWORD *)(v4 + 8) = v5;
return 0LL;
}
goto LABEL_13;
}
*(_DWORD *)v3 = a2;
*(_BYTE *)(v3 + 4) = 1;
return 0LL;
}

original_code:
int inject(linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 85, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 88, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *tail_element = get_tail(_el);
     if(tail_element && !tail_element->set) {
   tail_element->val = i;
   tail_element->set = 1;
   return 0;
     } else {
   linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 97, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->next = ((void *)0);
   el_new->val = i;
   el_new->set = 1;
   if(!tail_element) {
        el_new->prev = ((void *)0);
        tail_element = el_new;
   } else {
        el_new->prev = tail_element;
        tail_element->next = el_new;
   }
   return 0;
     }
error:
     return 1;
}

canonical_original_code:
int inject(struct linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 85, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 88, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *tail_element = get_tail(_el);
     if(tail_element && !tail_element->set) {
   tail_element->val = i;
   tail_element->set = 1;
   return 0;
     } else {
   struct linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 97, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->next = ((void *)0);
   el_new->val = i;
   el_new->set = 1;
   if(!tail_element) {
        el_new->prev = ((void *)0);
        tail_element = el_new;
   } else {
        el_new->prev = tail_element;
        tail_element->next = el_new;
   }
   return 0;
     }
error:
     return 1;
}

variable_types: i int


pop

decompiled_code:
__int64 __fastcall pop(void **a1)
{
int *v1; // r8
unsigned int v2; // er12
int *v4; // rax
char *v5; // r8
int *v6; // r12
int *v7; // rax
char *v8; // r8
int *v9; // rax
char *v10; // r8

if ( !a1 )
{
v9 = __errno_location();
v10 = "None";
v6 = v9;
if ( *v9 )
v10 = strerror(*v9);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 117LL, v10);
goto LABEL_9;
}
v1 = (int *)*a1;
if ( !*a1 )
{
v7 = __errno_location();
v8 = "None";
v6 = v7;
if ( *v7 )
v8 = strerror(*v7);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty ponter to linked_element.\n", "src/linked_list.c", 120LL, v8);
goto LABEL_9;
}
if ( !*((_BYTE *)v1 + 4) )
{
v4 = __errno_location();
v5 = "None";
v6 = v4;
if ( *v4 )
v5 = strerror(*v4);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) _el->set should not be false. Something's wrong.\n",
"src/linked_list.c",
130LL,
v5);
LABEL_9:
*v6 = 0;
return (unsigned int)-1;
}
v2 = *v1;
*a1 = (void *)*((_QWORD *)v1 + 1);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(void **a1)
{
int *v1; // r8
unsigned int v2; // er12
int *v4; // rax
char *v5; // r8
int *v6; // r12
int *v7; // rax
char *v8; // r8
int *v9; // rax
char *v10; // r8

if ( !a1 )
{
v9 = __errno_location();
v10 = "None";
v6 = v9;
if ( *v9 )
v10 = strerror(*v9);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 117LL, v10);
goto LABEL_9;
}
v1 = (int *)*a1;
if ( !*a1 )
{
v7 = __errno_location();
v8 = "None";
v6 = v7;
if ( *v7 )
v8 = strerror(*v7);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty ponter to linked_element.\n", "src/linked_list.c", 120LL, v8);
goto LABEL_9;
}
if ( !*((_BYTE *)v1 + 4) )
{
v4 = __errno_location();
v5 = "None";
v6 = v4;
if ( *v4 )
v5 = strerror(*v4);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) _el->set should not be false. Something's wrong.\n",
"src/linked_list.c",
130LL,
v5);
LABEL_9:
*v6 = 0;
return (unsigned int)-1;
}
v2 = *v1;
*a1 = (void *)*((_QWORD *)v1 + 1);
free(v1);
return v2;
}

original_code:
int pop(linked_element **el)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 117, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty ponter to linked_element." "\n", "src/linked_list.c", 120, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     int i = 0;
     if(_el->set) {
   i = _el->val;
   *el = _el->next? _el->next: ((void *)0);
   free(_el);
   return i;
     } else {
   { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "_el->set should not be false. Something's wrong." "\n", "src/linked_list.c", 130, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     }
error:
     return -1;
}

canonical_original_code:
int pop(struct linked_element **el)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 117, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty ponter to linked_element." "\n", "src/linked_list.c", 120, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     int i = 0;
     if(_el->set) {
   i = _el->val;
   *el = _el->next? _el->next: ((void *)0);
   free(_el);
   return i;
     } else {
   { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "_el->set should not be false. Something's wrong." "\n", "src/linked_list.c", 130, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     }
error:
     return -1;
}


getFileSize

decompiled_code:
__off_t __fastcall getFileSize(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)fstat(a1, &v2) == -1 )
result = -1LL;
else
result = v2.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func7(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func12(a1, &v2) == -1 )
result = -1LL;
else
result = v2.st_size;
return result;
}

original_code:
off_t getFileSize(int fd) {
 struct stat statInfo;
 if (fstat(fd, &statInfo) == -1) {
  return -1;
 }
 return statInfo.st_size;
}

canonical_original_code:
long getFileSize(int fd) {
 struct stat statInfo;
 if (fstat(fd, &statInfo) == -1) {
  return -1;
 }
 return statInfo.st_size;
}

variable_types: fd int

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

return_type: long

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


setupClient

decompiled_code:
__int64 __fastcall setupClient(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int *v6; // rax
char *v7; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v6 = __errno_location();
v4 = -1;
v7 = strerror(*v6);
fprintf(_bss_start, "getaddrinfo failed: %s\n", v7);
}
else
{
v2 = pai;
if ( pai )
{
do
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
{
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
return v4;
}
close(v4);
}
v2 = v2->ai_next;
}
while ( v2 );
v2 = pai;
}
v4 = -1;
freeaddrinfo(v2);
fwrite("failed to setup client\n", 1uLL, 0x17uLL, _bss_start);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int *v6; // rax
char *v7; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v6 = __errno_location();
v4 = -1;
v7 = strerror(*v6);
fprintf(_bss_start, "getaddrinfo failed: %s\n", v7);
}
else
{
v2 = pai;
if ( pai )
{
do
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
{
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
return v4;
}
close(v4);
}
v2 = v2->ai_next;
}
while ( v2 );
v2 = pai;
}
v4 = -1;
freeaddrinfo(v2);
fwrite("failed to setup client\n", 1uLL, 0x17uLL, _bss_start);
}
return v4;
}

original_code:
int setupClient(const char* address, const char* port) {
 int clientSocket = 0;
 struct addrinfo addrInfo;
 struct addrinfo* result;
 struct addrinfo* resNext;
 memset((void*)&addrInfo, 0, sizeof(struct addrinfo));
 addrInfo.ai_family = 0;
 addrInfo.ai_socktype = SOCK_STREAM;
 int ret = getaddrinfo(address, port, &addrInfo, &result);
 if (ret != 0) {
  fprintf(stderr, "getaddrinfo failed: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 for (resNext = result; resNext != ((void *)0); resNext = resNext->ai_next) {
  clientSocket = socket(resNext->ai_family, resNext->ai_socktype, resNext->ai_protocol);
  if (clientSocket == -1) {
   continue;
  }
  if (connect(clientSocket, resNext->ai_addr, resNext->ai_addrlen) == -1) {
   close(clientSocket);
   continue;
  }
  break;
 }
 freeaddrinfo(result);
 if (resNext == ((void *)0)) {
  fprintf(stderr, "failed to setup client\n");
  return -1;
 }
 return clientSocket;
}

canonical_original_code:
int setupClient(char *address, char *port) {
 int clientSocket = 0;
 struct addrinfo addrInfo;
 struct addrinfo *result;
 struct addrinfo *resNext;
 memset((void *)&addrInfo, 0, sizeof(struct addrinfo));
 addrInfo.ai_family = 0;
 addrInfo.ai_socktype = SOCK_STREAM;
 int ret = getaddrinfo(address, port, &addrInfo, &result);
 if (ret != 0) {
  fprintf(stderr, "getaddrinfo failed: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 for (resNext = result; resNext != ((void *)0); resNext = resNext->ai_next) {
  clientSocket = socket(resNext->ai_family, resNext->ai_socktype, resNext->ai_protocol);
  if (clientSocket == -1) {
   continue;
  }
  if (connect(clientSocket, resNext->ai_addr, resNext->ai_addrlen) == -1) {
   close(clientSocket);
   continue;
  }
  break;
 }
 freeaddrinfo(result);
 if (resNext == ((void *)0)) {
  fprintf(stderr, "failed to setup client\n");
  return -1;
 }
 return clientSocket;
}

variable_types:
address
char *

variable_types:
port
char *

variable_types: clientSocket int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: ret int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


getNameInDir

decompiled_code:
const char *__fastcall getNameInDir(const char *a1)
{
const char *v1; // r12
size_t v2; // rax
int v3; // edx
const char *v4; // rax
const char *v5; // rdx

v1 = a1;
v2 = strlen(a1);
v3 = v2;
v4 = &a1[v2 - 1];
if ( v3 > 0 )
{
v5 = &v4[~(unsigned __int64)(unsigned int)(v3 - 1)];
while ( *v4 != 47 )
{
if ( --v4 == v5 )
return v1;
}
v1 = v4 + 1;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func9(const char *a1)
{
const char *v1; // r12
size_t v2; // rax
int v3; // edx
const char *v4; // rax
const char *v5; // rdx

v1 = a1;
v2 = strlen(a1);
v3 = v2;
v4 = &a1[v2 - 1];
if ( v3 > 0 )
{
v5 = &v4[~(unsigned __int64)(unsigned int)(v3 - 1)];
while ( *v4 != 47 )
{
if ( --v4 == v5 )
return v1;
}
v1 = v4 + 1;
}
return v1;
}

original_code:
char* getNameInDir(char* fileName) {
 int fileNameLength = strlen(fileName);
 char* end = fileName + strlen(fileName) - 1;
 int i = 0;
 for (i = 0; i < fileNameLength; ++i) {
  if (*end == '/') {
   return ++end;
  }
  --end;
 }
 return fileName;
}

canonical_original_code:
char *getNameInDir(char *fileName) {
 int fileNameLength = strlen(fileName);
 char *end = fileName + strlen(fileName) - 1;
 int i = 0;
 for (i = 0; i < fileNameLength; ++i) {
  if (*end == '/') {
   return ++end;
  }
  --end;
 }
 return fileName;
}

variable_types:
fileName
char *

variable_types: fileNameLength int

variable_types:
end
char *

return_type: char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // ebp
const char *v5; // r13
size_t v6; // r14
int v7; // edi
int *v9; // rax
char *v10; // rdx
int v11; // edi
int v12; // edi
int *v13; // rax
char *v14; // rdx
unsigned __int16 buf[21]; // [rsp+Eh] [rbp-2Ah] BYREF

if ( argc != 4 )
{
v3 = -1;
fwrite("Usage: ./client host port file\n", 1uLL, 0x1FuLL, _bss_start);
return v3;
}
v3 = setupClient(argv[1], argv[2], envp);
if ( v3 != -1 )
{
v4 = open(argv[3], 0);
if ( v4 == -1 )
{
fprintf(_bss_start, "failed to open file %s\n", argv[3]);
v12 = v3;
v3 = -1;
close(v12);
return v3;
}
v5 = (const char *)getNameInDir(argv[3]);
v6 = getFileSize(v4);
buf[0] = strlen(v5);
if ( write(v3, buf, 2uLL) == -1 || write(v3, v5, buf[0]) == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(_bss_start, "failed to write to server: %s\n", v10);
}
else
{
if ( sendfile(v3, v4, 0LL, v6) != -1 )
{
v7 = v3;
v3 = 0;
close(v7);
close(v4);
printf("File %s was sent successfully\n", v5);
return v3;
}
v13 = __errno_location();
v14 = strerror(*v13);
fprintf(_bss_start, "failed to send file to server: %s\n", v14);
}
v11 = v3;
v3 = -1;
close(v11);
close(v4);
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // ebp
const char *v5; // r13
size_t v6; // r14
int v7; // edi
int *v9; // rax
char *v10; // rdx
int v11; // edi
int v12; // edi
int *v13; // rax
char *v14; // rdx
unsigned __int16 buf[21]; // [rsp+Eh] [rbp-2Ah] BYREF

if ( argc != 4 )
{
v3 = -1;
fwrite("Usage: ./client host port file\n", 1uLL, 0x1FuLL, _bss_start);
return v3;
}
v3 = func8(argv[1], argv[2], envp);
if ( v3 != -1 )
{
v4 = open(argv[3], 0);
if ( v4 == -1 )
{
fprintf(_bss_start, "failed to open file %s\n", argv[3]);
v12 = v3;
v3 = -1;
close(v12);
return v3;
}
v5 = (const char *)func9(argv[3]);
v6 = func7(v4);
buf[0] = strlen(v5);
if ( write(v3, buf, 2uLL) == -1 || write(v3, v5, buf[0]) == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(_bss_start, "failed to write to server: %s\n", v10);
}
else
{
if ( sendfile(v3, v4, 0LL, v6) != -1 )
{
v7 = v3;
v3 = 0;
close(v7);
close(v4);
printf("File %s was sent successfully\n", v5);
return v3;
}
v13 = __errno_location();
v14 = strerror(*v13);
fprintf(_bss_start, "failed to send file to server: %s\n", v14);
}
v11 = v3;
v3 = -1;
close(v11);
close(v4);
}
return v3;
}

original_code:
int main(int argc, char** argv) {
 if (argc != 4) {
  fprintf(stderr, "Usage: ./client host port file\n");
  return -1;
 }
 int clientSocket = setupClient(argv[1], argv[2]);
 if (clientSocket == -1) {
  return -1;
 }
 int fileToSend = open(argv[3], 00);
 if (fileToSend == -1) {
  fprintf(stderr, "failed to open file %s\n", argv[3]);
  close(clientSocket);
  return -1;
 }
 char* nameToSend = getNameInDir(argv[3]);
 off_t fileToSendLength = getFileSize(fileToSend);
 unsigned short nameToSendLength = strlen(nameToSend);
 if (write(clientSocket, &nameToSendLength, sizeof(nameToSendLength)) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (write(clientSocket, nameToSend, nameToSendLength) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (sendfile(clientSocket, fileToSend, ((void *)0), fileToSendLength) == -1) {
  fprintf(stderr, "failed to send file to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 close(clientSocket);
 close(fileToSend);
 printf("File %s was sent successfully\n", nameToSend);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc != 4) {
  fprintf(stderr, "Usage: ./client host port file\n");
  return -1;
 }
 int clientSocket = setupClient(argv[1], argv[2]);
 if (clientSocket == -1) {
  return -1;
 }
 int fileToSend = open(argv[3], 00);
 if (fileToSend == -1) {
  fprintf(stderr, "failed to open file %s\n", argv[3]);
  close(clientSocket);
  return -1;
 }
 char *nameToSend = getNameInDir(argv[3]);
 long fileToSendLength = getFileSize(fileToSend);
 unsigned short nameToSendLength = strlen(nameToSend);
 if (write(clientSocket, &nameToSendLength, sizeof(nameToSendLength)) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (write(clientSocket, nameToSend, nameToSendLength) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (sendfile(clientSocket, fileToSend, ((void *)0), fileToSendLength) == -1) {
  fprintf(stderr, "failed to send file to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 close(clientSocket);
 close(fileToSend);
 printf("File %s was sent successfully\n", nameToSend);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: fileToSend int

variable_types:
nameToSend
char *

variable_types: fileToSendLength long

variable_types:
nameToSendLength
unsigned short


original_code:
int main(void) {
    h5md_file file;
    h5md_particles_group beads;
    h5md_element obs_sin;
    hid_t vls_t;
    herr_t status;
    int i, j;
    double r[16][3];
    int species[16], dims[2];
    double mysin;
    char *boundary[] = {"periodic", "periodic", "none"};
    double edges[3] = {25, 25, 15};
    char *vls_data;
    vls_data = "Custom parameter value";
    H5open();
    file = h5md_create_file("data_use_ch5md.h5", "Pierre de Buyl", ((void *)0), "ch5md.use_h5md", "N/A");
    beads = h5md_create_particles_group(file, "beads");
    vls_t = H5Tcopy((H5open(), H5T_C_S1_g));
    H5Tset_size(vls_t, ((size_t)(-1)));
    dims[0] = 16;
    dims[1] = 3;
    beads.position = h5md_create_time_data(beads.group, "position", 2, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    for (i=0;i<16;i++) {
      r[i][0] = i;
      species[i] = 1;
    }
    h5md_create_box(&beads, 3, boundary, 1, edges, &beads.position);
    beads.species = h5md_create_fixed_data_simple(beads.group, "species", 1, dims, (H5open(), H5T_NATIVE_INT_g), species);
    i = 12345;
    h5md_create_fixed_data_scalar(file.observables, "scalar_dset", (H5open(), H5T_NATIVE_INT_g), &i);
    obs_sin = h5md_create_time_data(file.observables, "sin", 0, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    h5md_create_fixed_data_scalar(file.parameters, "custom_parameter", vls_t, &vls_data);
    for (j=0;j<2;j++) {
      for (i=0;i<16;i++) r[i][0] += 0.1*i*i;
      h5md_append(beads.position, r, j+1, (double) j+1);
      h5md_append(beads.box_edges, edges, j+1, (double) j+1);
      mysin = sin((double) j);
      h5md_append(obs_sin, &mysin, j+1, (double) j+1);
    }
    status = H5Tclose(vls_t);
    h5md_close_element(beads.position);
    h5md_close_file(file);
    H5close();
    return 0;
}

canonical_original_code:
int main() {
    struct h5md_file file;
    struct h5md_particles_group_struct beads;
    struct h5md_element_struct obs_sin;
    long vls_t;
    int status;
    int i; int j;
    double r[16][3];
    int species[16]; int dims[2];
    double mysin;
    char *boundary[] = {"periodic", "periodic", "none"};
    double edges[3] = {25, 25, 15};
    char *vls_data;
    vls_data = "Custom parameter value";
    H5open();
    file = h5md_create_file("data_use_ch5md.h5", "Pierre de Buyl", ((void *)0), "ch5md.use_h5md", "N/A");
    beads = h5md_create_particles_group(file, "beads");
    vls_t = H5Tcopy((H5open(), H5T_C_S1_g));
    H5Tset_size(vls_t, ((unsigned long)(-1)));
    dims[0] = 16;
    dims[1] = 3;
    beads.position = h5md_create_time_data(beads.group, "position", 2, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    for (i=0;i<16;i++) {
      r[i][0] = i;
      species[i] = 1;
    }
    h5md_create_box(&beads, 3, boundary, 1, edges, &beads.position);
    beads.species = h5md_create_fixed_data_simple(beads.group, "species", 1, dims, (H5open(), H5T_NATIVE_INT_g), species);
    i = 12345;
    h5md_create_fixed_data_scalar(file.observables, "scalar_dset", (H5open(), H5T_NATIVE_INT_g), &i);
    obs_sin = h5md_create_time_data(file.observables, "sin", 0, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    h5md_create_fixed_data_scalar(file.parameters, "custom_parameter", vls_t, &vls_data);
    for (j=0;j<2;j++) {
      for (i=0;i<16;i++) r[i][0] += 0.1*i*i;
      h5md_append(beads.position, r, j+1, (double) j+1);
      h5md_append(beads.box_edges, edges, j+1, (double) j+1);
      mysin = sin((double) j);
      h5md_append(obs_sin, &mysin, j+1, (double) j+1);
    }
    status = H5Tclose(vls_t);
    h5md_close_element(beads.position);
    h5md_close_file(file);
    H5close();
    return 0;
}

variable_types: struct h5md_file { long id; int version[2]; long particles; long observables; long parameters; }

variable_types: struct h5md_particles_group_struct { long group; struct h5md_element_struct { long group; long step; long time; long value; long datatype; int is_time; int current_step; struct h5md_element_struct *link; struct h5md_particles_group_struct *particles_group; } position; long box; struct h5md_element_struct box_edges; struct h5md_element_struct image; struct h5md_element_struct velocity; struct h5md_element_struct force; struct h5md_element_struct mass; struct h5md_element_struct species; struct h5md_element_struct id; struct h5md_element_struct charge; int local_size_max; }

variable_types: struct h5md_element_struct { long group; long step; long time; long value; long datatype; int is_time; int current_step; struct h5md_element_struct *link; struct h5md_particles_group_struct { long group; struct h5md_element_struct position; long box; struct h5md_element_struct box_edges; struct h5md_element_struct image; struct h5md_element_struct velocity; struct h5md_element_struct force; struct h5md_element_struct mass; struct h5md_element_struct species; struct h5md_element_struct id; struct h5md_element_struct charge; int local_size_max; } *particles_group; }

variable_types: status int

variable_types: i int

variable_types: j int

variable_types:
r
double [16][3]

variable_types:
species
int [16]

variable_types:
dims
int [2]

variable_types: mysin double

variable_types:
boundary
char *[]

variable_types:
edges
double [3]


decompiled_code:
__int64 __fastcall lcs_naive(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // er9
int v9; // eax
__int64 v10; // [rsp+0h] [rbp-48h]
int v11; // [rsp+8h] [rbp-40h]
unsigned int v12; // [rsp+Ch] [rbp-3Ch]

if ( !a3 )
return 0LL;
v5 = a4;
if ( !a4 )
return 0;
v6 = a3;
v7 = 0;
do
{
if ( *(_BYTE *)(a1 + (int)v6 - 1) == *(_BYTE *)(a2 + (int)v5 - 1) )
{
++v7;
--v5;
--v6;
}
else
{
v12 = v7;
v10 = a5;
v11 = lcs_naive(a1, a2, v6, v5 - 1);
v9 = lcs_naive(a1, a2, v6 - 1, v5);
a5 = v10;
if ( v11 <= v9 )
--v6;
if ( v11 > v9 )
--v5;
v7 = v12;
}
}
while ( v6 && v5 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // er9
int v9; // eax
__int64 v10; // [rsp+0h] [rbp-48h]
int v11; // [rsp+8h] [rbp-40h]
unsigned int v12; // [rsp+Ch] [rbp-3Ch]

if ( !a3 )
return 0LL;
v5 = a4;
if ( !a4 )
return 0;
v6 = a3;
v7 = 0;
do
{
if ( *(_BYTE *)(a1 + (int)v6 - 1) == *(_BYTE *)(a2 + (int)v5 - 1) )
{
++v7;
--v5;
--v6;
}
else
{
v12 = v7;
v10 = a5;
v11 = func7(a1, a2, v6, v5 - 1);
v9 = func7(a1, a2, v6 - 1, v5);
a5 = v10;
if ( v11 <= v9 )
--v6;
if ( v11 > v9 )
--v5;
v7 = v12;
}
}
while ( v6 && v5 );
return v7;
}

original_code:
int lcs_naive(char* X, char* Y, int m, int n, char** ans)
{
 if (m == 0 || n == 0)
        return 0;
    if(X[m-1] == Y[n-1])
        return 1 + lcs_naive(X, Y, m-1, n-1, ans);
    else
        return ((lcs_naive(X, Y, m, n-1, ans)) > (lcs_naive(X, Y, m-1, n, ans)) ? (lcs_naive(X, Y, m, n-1, ans)) : (lcs_naive(X, Y, m-1, n, ans)));
}

canonical_original_code:
int lcs_naive(char *X, char *Y, int m, int n, char **ans)
{
 if (m == 0 || n == 0)
        return 0;
    if(X[m-1] == Y[n-1])
        return 1 + lcs_naive(X, Y, m-1, n-1, ans);
    else
        return ((lcs_naive(X, Y, m, n-1, ans)) > (lcs_naive(X, Y, m-1, n, ans)) ? (lcs_naive(X, Y, m, n-1, ans)) : (lcs_naive(X, Y, m-1, n, ans)));
}

variable_types:
X
char *

variable_types:
Y
char *

variable_types: m int

variable_types: n int

variable_types:
ans
char **


decompiled_code:
void *__fastcall lcs_malloc(size_t size)
{
memusage += size;
return malloc(size);
}

canonical_decompiled_code:
void *__fastcall func8(size_t size)
{
memusage += size;
return malloc(size);
}

original_code:
void* lcs_malloc (size_t size)
{
    memusage += (long)size;
    return malloc(size);
}

canonical_original_code:
void *lcs_malloc(unsigned long size)
{
    memusage += (long)size;
    return malloc(size);
}

variable_types:
size
unsigned long


timeit

decompiled_code:
double __fastcall timeit(__int64 (__fastcall *a1)(__int64, __int64, _QWORD, _QWORD, __int64), int a2, __int64 a3, __int64 a4, unsigned int a5, unsigned int a6, __int64 a7)
{
int i; // er12
unsigned int v12; // er8
double v13; // xmm0_8
unsigned int v15; // [rsp+10h] [rbp-48h]
double v16; // [rsp+18h] [rbp-40h]

getrusage(RUSAGE_SELF, &ruse);
v16 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec));
if ( a2 <= 0 )
{
v12 = 0;
}
else
{
for ( i = 0; i != a2; ++i )
v12 = a1(a3, a4, a5, a6, a7);
}
v15 = v12;
getrusage(RUSAGE_SELF, &ruse);
v13 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec))
- v16;
printf(
"# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
v15,
(unsigned int)a2,
v13,
v13 / (double)a2);
return v13 / (double)a2;
}

canonical_decompiled_code:
double __fastcall func9(__int64 (__fastcall *a1)(__int64, __int64, _QWORD, _QWORD, __int64), int a2, __int64 a3, __int64 a4, unsigned int a5, unsigned int a6, __int64 a7)
{
int i; // er12
unsigned int v12; // er8
double v13; // xmm0_8
unsigned int v15; // [rsp+10h] [rbp-48h]
double v16; // [rsp+18h] [rbp-40h]

getrusage(RUSAGE_SELF, &ruse);
v16 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec));
if ( a2 <= 0 )
{
v12 = 0;
}
else
{
for ( i = 0; i != a2; ++i )
v12 = a1(a3, a4, a5, a6, a7);
}
v15 = v12;
getrusage(RUSAGE_SELF, &ruse);
v13 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec))
- v16;
printf(
"# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
v15,
(unsigned int)a2,
v13,
v13 / (double)a2);
return v13 / (double)a2;
}

original_code:
double timeit( int (*lcs)(char*,char*,int,int,char**),
               int ittr,
               char* s1, char* s2,
               int m, int n,
               char** ans )
{
    double start, end;
    int i=0;
    int numrecurse=0;
    start = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    while( i<ittr ){
        numrecurse = lcs(s1, s2, m, n, ans);
        i++;
    }
    end = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    double avgTime = (end-start)/ittr;
    printf("# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
            numrecurse, ittr, (end-start), avgTime);
    return avgTime;
}

canonical_original_code:
double timeit(int (*lcs)(char *, char *, int, int, char **), int ittr, char *s1, char *s2, int m, int n, char **ans)
{
    double start; double end;
    int i = 0;
    int numrecurse = 0;
    start = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    while( i<ittr ){
        numrecurse = lcs(s1, s2, m, n, ans);
        i++;
    }
    end = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    double avgTime = (end-start)/ittr;
    printf("# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
            numrecurse, ittr, (end-start), avgTime);
    return avgTime;
}

variable_types: int (*)(char *, char *, int, int, char **)

variable_types: ittr int

variable_types: start double

variable_types: end double

variable_types: numrecurse int

variable_types: avgTime double

return_type: double


canonical_decompiled_code:
void *__fastcall func7(size_t size)
{
memusage += size;
return malloc(size);
}


canonical_decompiled_code:
double __fastcall func8(__int64 (__fastcall *a1)(__int64, __int64, _QWORD, _QWORD, __int64), int a2, __int64 a3, __int64 a4, unsigned int a5, unsigned int a6, __int64 a7)
{
int i; // er12
unsigned int v12; // er8
double v13; // xmm0_8
unsigned int v15; // [rsp+10h] [rbp-48h]
double v16; // [rsp+18h] [rbp-40h]

getrusage(RUSAGE_SELF, &ruse);
v16 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec));
if ( a2 <= 0 )
{
v12 = 0;
}
else
{
for ( i = 0; i != a2; ++i )
v12 = a1(a3, a4, a5, a6, a7);
}
v15 = v12;
getrusage(RUSAGE_SELF, &ruse);
v13 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec))
- v16;
printf(
"# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
v15,
(unsigned int)a2,
v13,
v13 / (double)a2);
return v13 / (double)a2;
}

variable_types: i int


debug

decompiled_code:
int __fastcall debug(const char *a1)
{
printf(a1);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
printf(a1);
return fflush(stdout);
}

original_code:
void debug(const char* msg){
    printf(msg);fflush(stdout);
}

canonical_original_code:
void debug(char *msg){
    printf(msg);fflush(stdout);
}

variable_types:
msg
char *


decompiled_code:
int __fastcall debug_printarray(int a1, unsigned int *a2)
{
unsigned int *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a2;
putchar(91);
if ( a1 > 0 )
{
v3 = (__int64)&a2[a1 - 1 + 1];
do
{
v4 = *v2++;
printf("%d,", v4);
}
while ( v2 != (unsigned int *)v3 );
}
puts("]");
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func10(int a1, unsigned int *a2)
{
unsigned int *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a2;
putchar(91);
if ( a1 > 0 )
{
v3 = (__int64)&a2[a1 - 1 + 1];
do
{
v4 = *v2++;
printf("%d,", v4);
}
while ( v2 != (unsigned int *)v3 );
}
puts("]");
return fflush(stdout);
}

original_code:
void debug_printarray( const int l, const int* a ){
    printf("[");
    for( int i=0; i< l; i++){
        printf("%d,",a[i]);
    }
    printf("]\n");fflush(stdout);
}

canonical_original_code:
void debug_printarray(int l, int *a){
    printf("[");
    for( int i = 0; i< l; i++){
        printf("%d,",a[i]);
    }
    printf("]\n");fflush(stdout);
}

variable_types: l int

variable_types:
a
int *


algorithmA

variable_types:
A
char *

variable_types:
B
char *

variable_types:
L
int ***

variable_types:
LL
int **

variable_types: j int


algorithmB

variable_types: m int

variable_types: n int

variable_types:
K
int **


strsplit

decompiled_code:
void *__fastcall strsplit(int a1, int a2, char *a3, _QWORD *a4, _QWORD *a5)
{
char *v6; // r13
size_t v8; // r12
void *v9; // rax
void *v10; // rax

v6 = &a3[a2];
v8 = a1 - a2 + 1;
v9 = lcs_malloc(a2 + 1);
*a4 = v9;
*((_BYTE *)memcpy(v9, a3, a2) + a2) = 0;
v10 = lcs_malloc(v8);
*a5 = v10;
return memcpy(v10, v6, v8);
}

canonical_decompiled_code:
void *__fastcall func14(int a1, int a2, char *a3, _QWORD *a4, _QWORD *a5)
{
char *v6; // r13
size_t v8; // r12
void *v9; // rax
void *v10; // rax

v6 = &a3[a2];
v8 = a1 - a2 + 1;
v9 = func7(a2 + 1);
*a4 = v9;
*((_BYTE *)memcpy(v9, a3, a2) + a2) = 0;
v10 = func7(v8);
*a5 = v10;
return memcpy(v10, v6, v8);
}

original_code:
void strsplit( int len, int i, char* s, char** front, char** back ) {
    int bl = len-i+1;
    char* bs = s+( i*sizeof(char) );
    *front = (char*)lcs_malloc( (i+1)*sizeof(char) );
    memcpy( *front, s, i*sizeof(char) );
    (*front)[i] = '\0';
    *back = (char*)lcs_malloc( bl*sizeof(char) );
    memcpy( *back, bs, bl*sizeof(char) );
}

canonical_original_code:
void strsplit(int len, int i, char *s, char **front, char **back) {
    int bl = len-i+1;
    char *bs = s+( i*sizeof(char) );
    *front = (char *)lcs_malloc( (i+1)*sizeof(char) );
    memcpy( *front, s, i*sizeof(char) );
    (*front)[i] = '\0';
    *back = (char *)lcs_malloc( bl*sizeof(char) );
    memcpy( *back, bs, bl*sizeof(char) );
}

variable_types: len int

variable_types:
s
char *

variable_types:
front
char **

variable_types:
back
char **

variable_types: bl int

variable_types:
bs
char *


algorithmC

original_code:
int algorithmC( int m, int n, char* A, char* B, char** C ){
    if( n == 0 ){ return 0; }
    if( m == 1 ){
        for(int i=0; i<n; i++){
            if(A[0] == B[i]){
                const char ch[] = { B[i], '\0' };
                strcat(*C, ch);
                break;
            }
        }
        return 0;
    }
    int i = m/2;
    char *A_1i, A_mi1[m-i+1], *A_i1m;
        strsplit( m, i, A, &A_1i, &A_i1m );
        strcpy(A_mi1, A_i1m);
        strrev( A_mi1 );
    char B_n1[n];
        strcpy(B_n1, B);
        strrev( B_n1 );
    int** L = (int**)lcs_malloc( 2 * sizeof(int*) );
    algorithmB( i, n, A_1i, B, &L[0] );
    algorithmB( m-i, n, A_mi1, B_n1, &L[1] );
    int k=0,M=0;
    for(int j=0; j <= n; j++){ M = ((M) > (L[0][j] + L[1][n-j]) ? (M) : (L[0][j] + L[1][n-j])); }
    for(int j=0; j <= n; j++){ if(L[0][j]+L[1][n-j] == M){ k=j; break;} }
    free(L[0]); free(L[1]); free(L);
    char *B_1k, *B_k1n; strsplit( n, k, B, &B_1k, &B_k1n );
    int rec = algorithmC( i, k, A_1i, B_1k, C )
            + algorithmC( m-i, n-k, A_i1m, B_k1n, C );
    free( A_1i ); free( A_i1m );
    free( B_1k ); free( B_k1n );
    return rec+2;
}

canonical_original_code:
int algorithmC(int m, int n, char *A, char *B, char **C){
    if( n == 0 ){ return 0; }
    if( m == 1 ){
        for(int i = 0; i<n; i++){
            if(A[0] == B[i]){
                char ch[] = { B[i], '\0' };
                strcat(*C, ch);
                break;
            }
        }
        return 0;
    }
    int i = m/2;
    char *A_1i; char A_mi1[-1]; char *A_i1m;
        strsplit( m, i, A, &A_1i, &A_i1m );
        strcpy(A_mi1, A_i1m);
        strrev( A_mi1 );
    char B_n1[-1];
        strcpy(B_n1, B);
        strrev( B_n1 );
    int **L = (int**)lcs_malloc( 2 * sizeof(int*) );
    algorithmB( i, n, A_1i, B, &L[0] );
    algorithmB( m-i, n, A_mi1, B_n1, &L[1] );
    int k = 0; int M = 0;
    for(int j = 0; j <= n; j++){ M = ((M) > (L[0][j] + L[1][n-j]) ? (M) : (L[0][j] + L[1][n-j])); }
    for(int j = 0; j <= n; j++){ if(L[0][j]+L[1][n-j] == M){ k=j; break;} }
    free(L[0]); free(L[1]); free(L);
    char *B_1k; char *B_k1n; strsplit( n, k, B, &B_1k, &B_k1n );
    int rec = algorithmC( i, k, A_1i, B_1k, C )
            + algorithmC( m-i, n-k, A_i1m, B_k1n, C );
    free( A_1i ); free( A_i1m );
    free( B_1k ); free( B_k1n );
    return rec+2;
}

variable_types:
C
char **

variable_types: i int

variable_types:
ch
char []

variable_types:
L
int **

variable_types: k int

variable_types: M int

variable_types: rec int


Hirshberg

decompiled_code:
__int64 __fastcall Hirshberg(char *a1, char *a2, int a3, int a4, char **a5)
{
__int64 result; // rax

**a5 = 0;
if ( a3 < a4 )
result = algorithmC(a4, a3, a2, a1, a5);
else
result = algorithmC(a3, a4, a1, a2, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, char *a2, int a3, int a4, char **a5)
{
__int64 result; // rax

**a5 = 0;
if ( a3 < a4 )
result = func15(a4, a3, a2, a1, a5);
else
result = func15(a3, a4, a1, a2, a5);
return result;
}

original_code:
int Hirshberg( char* A, char* B, int m, int n, char** C ){
    int r;
    strcpy(*C, "");
    if( m >= n ) {
        r = algorithmC( m, n, A, B, C );
    }else{
        r = algorithmC( n, m, B, A, C );
    }
    return r;
}

canonical_original_code:
int Hirshberg(char *A, char *B, int m, int n, char **C){
    int r;
    strcpy(*C, "");
    if( m >= n ) {
        r = algorithmC( m, n, A, B, C );
    }else{
        r = algorithmC( n, m, B, A, C );
    }
    return r;
}

variable_types:
A
char *

variable_types:
B
char *

variable_types: r int


timeit

variable_types: int (*)(char *, char *, int, int, char **)

variable_types: ittr int

variable_types: m int

variable_types: n int

variable_types:
ans
char **

variable_types: start double

variable_types: end double

variable_types: numrecurse int

variable_types: avgTime double


decompiled_code:
__int64 __fastcall lcs_with_memo(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
__int64 v7; // r14
_QWORD *v8; // r15
__int64 result; // rax
unsigned int v10; // er11
int v11; // [rsp+0h] [rbp-4Ch]
unsigned int v12; // [rsp+Ch] [rbp-40h]
unsigned int v13; // [rsp+10h] [rbp-3Ch]

if ( !a3 )
return 0LL;
if ( !a4 )
return 0LL;
v7 = (int)a4;
v8 = (_QWORD *)(a5 + 8LL * (int)a3);
result = *(unsigned int *)(*v8 + 4LL * (int)a4);
if ( !(_DWORD)result )
{
v10 = a4 - 1;
if ( *(_BYTE *)(a1 + (int)a3 - 1) == *(_BYTE *)(a2 + (int)a4 - 1) )
{
result = (unsigned int)lcs_with_memo(a1, a2, a3 - 1, v10) + 1;
*(_DWORD *)(*v8 + 4 * v7) = result;
}
else
{
v12 = a3 - 1;
v13 = a4 - 1;
v11 = lcs_with_memo(a1, a2, a3, v10);
if ( v11 > (int)lcs_with_memo(a1, a2, v12, a4) )
result = lcs_with_memo(a1, a2, a3, v13);
else
result = lcs_with_memo(a1, a2, v12, a4);
*(_DWORD *)(*v8 + 4 * v7) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
__int64 v7; // r14
_QWORD *v8; // r15
__int64 result; // rax
unsigned int v10; // er11
int v11; // [rsp+0h] [rbp-4Ch]
unsigned int v12; // [rsp+Ch] [rbp-40h]
unsigned int v13; // [rsp+10h] [rbp-3Ch]

if ( !a3 )
return 0LL;
if ( !a4 )
return 0LL;
v7 = (int)a4;
v8 = (_QWORD *)(a5 + 8LL * (int)a3);
result = *(unsigned int *)(*v8 + 4LL * (int)a4);
if ( !(_DWORD)result )
{
v10 = a4 - 1;
if ( *(_BYTE *)(a1 + (int)a3 - 1) == *(_BYTE *)(a2 + (int)a4 - 1) )
{
result = (unsigned int)func9(a1, a2, a3 - 1, v10) + 1;
*(_DWORD *)(*v8 + 4 * v7) = result;
}
else
{
v12 = a3 - 1;
v13 = a4 - 1;
v11 = func9(a1, a2, a3, v10);
if ( v11 > (int)func9(a1, a2, v12, a4) )
result = func9(a1, a2, a3, v13);
else
result = func9(a1, a2, v12, a4);
*(_DWORD *)(*v8 + 4 * v7) = result;
}
}
return result;
}

original_code:
int lcs_with_memo( char *X, char *Y, int m, int n, int** arr )
{
    if (m == 0 || n == 0) return 0;
    if (arr[m][n]==0){
        if (X[m-1] == Y[n-1])
            arr[m][n] = 1 + lcs_with_memo(X, Y, m-1, n-1, arr);
        else
            arr[m][n] = ((lcs_with_memo(X, Y, m, n-1, arr)) > (lcs_with_memo(X, Y, m-1, n, arr)) ? (lcs_with_memo(X, Y, m, n-1, arr)) : (lcs_with_memo(X, Y, m-1, n, arr)));
    }
    return arr[m][n];
}

canonical_original_code:
int lcs_with_memo(char *X, char *Y, int m, int n, int **arr)
{
    if (m == 0 || n == 0) return 0;
    if (arr[m][n]==0){
        if (X[m-1] == Y[n-1])
            arr[m][n] = 1 + lcs_with_memo(X, Y, m-1, n-1, arr);
        else
            arr[m][n] = ((lcs_with_memo(X, Y, m, n-1, arr)) > (lcs_with_memo(X, Y, m-1, n, arr)) ? (lcs_with_memo(X, Y, m, n-1, arr)) : (lcs_with_memo(X, Y, m-1, n, arr)));
    }
    return arr[m][n];
}

variable_types:
X
char *

variable_types:
Y
char *

variable_types:
arr
int **


decompiled_code:
__int64 __fastcall lcs_memo(__int64 a1, __int64 a2, unsigned int a3, signed int a4)
{
__int64 v5; // r12
void **v6; // rax
void **v7; // rbp
__int64 v8; // rbx
void *v9; // rax
unsigned int v10; // er13
void **v11; // rbx
void **v12; // r12
void *v13; // rdi

v5 = a3;
v6 = (void **)lcs_malloc(8LL * (int)(a3 + 1));
v7 = v6;
if ( (int)v5 < 0 )
{
v10 = lcs_with_memo(a1, a2, v5, a4, (__int64)v6);
}
else
{
v8 = 0LL;
do
{
v9 = lcs_malloc(4LL * (a4 + 1));
v7[v8] = v9;
if ( a4 >= 0 )
memset(v9, 0, 4LL * (unsigned int)a4 + 4);
++v8;
}
while ( (int)v5 >= (int)v8 );
v10 = lcs_with_memo(a1, a2, v5, a4, (__int64)v7);
if ( (int)v5 > 0 )
{
v11 = v7;
v12 = &v7[v5];
do
{
v13 = *v11++;
free(v13);
}
while ( v12 != v11 );
}
}
free(v7);
return v10;
}

original_code:
int lcs_memo( char *X, char *Y, int m, int n, char** ans)
{
    int** arr = (int**)lcs_malloc((m+1) * sizeof(int*));
    for(int i=0; i <= m; i++) {
        arr[i] = (int *)lcs_malloc((n+1) * sizeof(int));
        for(int j=0; j <= n; j++){
            arr[i][j] = 0;
        }
    }
    int res = lcs_with_memo( X, Y, m, n, arr );
    for(int i=0; i < m; i++) { free(arr[i]); }
    free(arr);
    return res;
}

canonical_original_code:
int lcs_memo(char *X, char *Y, int m, int n, char **ans)
{
    int **arr = (int**)lcs_malloc((m+1) * sizeof(int*));
    for(int i = 0; i <= m; i++) {
        arr[i] = (int *)lcs_malloc((n+1) * sizeof(int));
        for(int j = 0; j <= n; j++){
            arr[i][j] = 0;
        }
    }
    int res = lcs_with_memo( X, Y, m, n, arr );
    for(int i = 0; i < m; i++) { free(arr[i]); }
    free(arr);
    return res;
}

variable_types: i int

variable_types: j int

variable_types: res int


decompiled_code:
void __fastcall print_lcs(__int64 a1, __int64 a2, int a3, int a4)
{
int v4; // esi
int v5; // eax

v4 = a3;
if ( a3 && a4 )
{
do
{
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 8LL * v4) + 4LL * a4);
if ( v5 == 1 )
{
--v4;
--a4;
if ( !v4 )
return;
}
else
{
if ( v5 == 2 )
--v4;
else
--a4;
if ( !v4 )
return;
}
}
while ( a4 );
}
}

original_code:
void print_lcs(int** b, char* X, int i, int j){
    if (i==0 || j==0)
        return;
    if (b[i][j] == 1){
        print_lcs(b,X,i-1,j-1);
    }
    else if(b[i][j] == 2){
        print_lcs(b,X,i-1,j);
    }
    else{
        print_lcs(b,X,i,j-1);
    }
}

canonical_original_code:
void print_lcs(int **b, char *X, int i, int j){
    if (i==0 || j==0)
        return;
    if (b[i][j] == 1){
        print_lcs(b,X,i-1,j-1);
    }
    else if(b[i][j] == 2){
        print_lcs(b,X,i-1,j);
    }
    else{
        print_lcs(b,X,i,j-1);
    }
}

variable_types:
b
int **


variable_types:
c
int **


repo: pdkelly/flvjoin

decompiled_code:
size_t write_flv_header()
{
__int64 ptr; // [rsp+3h] [rbp-15h] BYREF
int v2; // [rsp+Bh] [rbp-Dh]
char v3; // [rsp+Fh] [rbp-9h]

ptr = 0x501564C46LL;
v2 = 9;
v3 = 0;
if ( !quiet )
fprintf(stderr, "Writing FLV header to %s\n", filepath);
return fwrite(&ptr, 1uLL, 0xDuLL, outfile);
}

canonical_decompiled_code:
size_t func0()
{
__int64 ptr; // [rsp+3h] [rbp-15h] BYREF
int v2; // [rsp+Bh] [rbp-Dh]
char v3; // [rsp+Fh] [rbp-9h]

ptr = 0x501564C46LL;
v2 = 9;
v3 = 0;
if ( !quiet )
fprintf(stderr, "Writing FLV header to %s\n", filepath);
return fwrite(&ptr, 1uLL, 0xDuLL, outfile);
}

original_code:
static void write_flv_header(void)
{
    const unsigned char header[] = {'F', 'L', 'V', 1, 5, 0, 0, 0, 9, 0, 0, 0, 0};
    if(!quiet)
        fprintf(stderr,"Writing FLV header to %s\n", filepath);
    fwrite( header, 1, sizeof(header), outfile );
    return;
}

canonical_original_code:
static void write_flv_header()
{
    unsigned char header[] = {'F', 'L', 'V', 1, 5, 0, 0, 0, 9, 0, 0, 0, 0};
    if(!quiet)
        fprintf(stderr,"Writing FLV header to %s\n", filepath);
    fwrite( header, 1, sizeof(header), outfile );
    return;
}

variable_types:
header
unsigned char []


decompiled_code:
size_t __fastcall write_output(const void *a1, size_t a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

result = fwrite(a1, 1uLL, a2, outfile);
if ( result != a2 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR while writing to output file %s: %s\n", filepath, v4);
exit(1);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(const void *a1, size_t a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

result = fwrite(a1, 1uLL, a2, outfile);
if ( result != a2 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR while writing to output file %s: %s\n", filepath, v4);
exit(1);
}
return result;
}

original_code:
static void write_output(unsigned char *buffer, size_t bytes)
{
    if( fwrite(buffer, 1, bytes, outfile) != bytes )
    {
        fprintf(stderr, "ERROR while writing to output file %s: %s\n",
                filepath, strerror((*__errno_location ())));
        exit(1);
    }
    return;
}

canonical_original_code:
static void write_output(unsigned char *buffer, unsigned long bytes)
{
    if( fwrite(buffer, 1, bytes, outfile) != bytes )
    {
        fprintf(stderr, "ERROR while writing to output file %s: %s\n",
                filepath, strerror((*__errno_location ())));
        exit(1);
    }
    return;
}

variable_types:
buffer
unsigned char *

variable_types:
bytes
unsigned long