decompiled_code:
__int64 __fastcall ts_bnode_walk_r(__int64 a1, char a2, __int64 *a3)
{
__int64 v4; // r14
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rsi
__int64 v9; // rsi
__int64 v11; // r13
__int64 v12; // r12
__int64 v13; // rsi
__int64 v14; // rsi
__int64 v15; // rsi
__int64 v16; // rsi
__int64 v17; // rax
__int64 v18; // r13
__int64 v19; // rbp
__int64 v20; // rsi
__int64 v21; // rax
__int64 v22; // rax
__int64 v23; // rax

if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 32LL);
*_errno_location() = 0;
if ( !a3 )
return 0LL;
goto LABEL_32;
}
if ( !a3 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 33LL);
*_errno_location() = 0;
return 0LL;
}
v4 = *a3;
v5 = a1;
if ( *a3 )
{
if ( a2 != 2 )
{
if ( a2 <= 2 )
{
if ( a2 )
{
if ( a2 == 1 )
goto LABEL_8;
LABEL_23:
v12 = 0LL;
ts_slist_free(v4);
return v12;
}
goto LABEL_25;
}
if ( a2 != 3 )
goto LABEL_23;
LABEL_17:
if ( *(_QWORD *)(v4 + 16) )
{
v11 = ts_slist_peek_head(v4);
v12 = ts_slist_pop(v11);
if ( !v12 )
goto LABEL_32;
}
else
{
v22 = ts_slist_new();
v12 = a1;
v11 = ts_slist_push(v4, v22);
}
v13 = *(_QWORD *)(v12 + 8);
if ( v13 )
ts_slist_unshift(v11, v13);
v14 = *(_QWORD *)(v12 + 16);
if ( v14 )
ts_slist_unshift(v11, v14);
return v12;
}
}
else
{
v21 = ts_slist_new();
*a3 = v21;
v4 = v21;
if ( a2 != 2 )
{
if ( a2 > 2 )
{
if ( a2 == 3 )
goto LABEL_17;
}
else
{
if ( !a2 )
{
LABEL_25:
if ( !*(_QWORD *)(v4 + 16) )
{
v12 = a1;
ts_slist_push(v4, 0LL);
goto LABEL_27;
}
v12 = ts_slist_pop(v4);
if ( v12 )
{
LABEL_27:
v15 = *(_QWORD *)(v12 + 16);
if ( v15 )
ts_slist_push(v4, v15);
v16 = *(_QWORD *)(v12 + 8);
if ( v16 )
ts_slist_push(v4, v16);
return v12;
}
LABEL_32:
v4 = *a3;
goto LABEL_33;
}
if ( a2 == 1 )
{
LABEL_8:
if ( !*(_QWORD *)(v4 + 16) )
{
v6 = ts_slist_new();
v7 = ts_slist_push(v4, v6);
ts_slist_push(v4, 0LL);
do
{
ts_slist_push(v4, v5);
v8 = *(_QWORD *)(v5 + 16);
if ( v8 )
ts_slist_unshift(v7, v8);
v9 = *(_QWORD *)(v5 + 8);
if ( v9 )
ts_slist_unshift(v7, v9);
v5 = ts_slist_pop(v7);
}
while ( v5 );
return ts_slist_pop(v4);
}
v12 = ts_slist_pop(v4);
if ( v12 )
return v12;
goto LABEL_32;
}
}
LABEL_33:
if ( !v4 )
return 0LL;
goto LABEL_23;
}
}
if ( *(_QWORD *)(v4 + 16) )
{
v17 = ts_slist_peek_tail(v4);
v18 = v17;
if ( *(_QWORD *)(v4 + 16) == 1LL )
{
v12 = ts_slist_pop(v17);
if ( v12 )
return v12;
}
v5 = ts_slist_pop(v4);
if ( !v5 )
goto LABEL_32;
}
else
{
v23 = ts_slist_new();
v18 = ts_slist_push(v4, v23);
}
while ( *(_QWORD *)(v5 + 8) )
{
ts_slist_push(v4, v5);
v5 = *(_QWORD *)(v5 + 8);
}
ts_slist_unshift(v18, v5);
do
{
if ( *(_QWORD *)(v4 + 16) <= 1uLL )
return ts_slist_pop(v18);
v19 = ts_slist_pop(v4);
ts_slist_unshift(v18, v19);
v20 = *(_QWORD *)(v19 + 16);
}
while ( !v20 );
ts_slist_push(v4, v20);
return ts_slist_pop(v18);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, __int64 *a3)
{
__int64 v4; // r14
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rsi
__int64 v9; // rsi
__int64 v11; // r13
__int64 v12; // r12
__int64 v13; // rsi
__int64 v14; // rsi
__int64 v15; // rsi
__int64 v16; // rsi
__int64 v17; // rax
__int64 v18; // r13
__int64 v19; // rbp
__int64 v20; // rsi
__int64 v21; // rax
__int64 v22; // rax
__int64 v23; // rax

if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 32LL);
*_errno_location() = 0;
if ( !a3 )
return 0LL;
goto LABEL_32;
}
if ( !a3 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 33LL);
*_errno_location() = 0;
return 0LL;
}
v4 = *a3;
v5 = a1;
if ( *a3 )
{
if ( a2 != 2 )
{
if ( a2 <= 2 )
{
if ( a2 )
{
if ( a2 == 1 )
goto LABEL_8;
LABEL_23:
v12 = 0LL;
ts_slist_free(v4);
return v12;
}
goto LABEL_25;
}
if ( a2 != 3 )
goto LABEL_23;
LABEL_17:
if ( *(_QWORD *)(v4 + 16) )
{
v11 = ts_slist_peek_head(v4);
v12 = ts_slist_pop(v11);
if ( !v12 )
goto LABEL_32;
}
else
{
v22 = ts_slist_new();
v12 = a1;
v11 = ts_slist_push(v4, v22);
}
v13 = *(_QWORD *)(v12 + 8);
if ( v13 )
ts_slist_unshift(v11, v13);
v14 = *(_QWORD *)(v12 + 16);
if ( v14 )
ts_slist_unshift(v11, v14);
return v12;
}
}
else
{
v21 = ts_slist_new();
*a3 = v21;
v4 = v21;
if ( a2 != 2 )
{
if ( a2 > 2 )
{
if ( a2 == 3 )
goto LABEL_17;
}
else
{
if ( !a2 )
{
LABEL_25:
if ( !*(_QWORD *)(v4 + 16) )
{
v12 = a1;
ts_slist_push(v4, 0LL);
goto LABEL_27;
}
v12 = ts_slist_pop(v4);
if ( v12 )
{
LABEL_27:
v15 = *(_QWORD *)(v12 + 16);
if ( v15 )
ts_slist_push(v4, v15);
v16 = *(_QWORD *)(v12 + 8);
if ( v16 )
ts_slist_push(v4, v16);
return v12;
}
LABEL_32:
v4 = *a3;
goto LABEL_33;
}
if ( a2 == 1 )
{
LABEL_8:
if ( !*(_QWORD *)(v4 + 16) )
{
v6 = ts_slist_new();
v7 = ts_slist_push(v4, v6);
ts_slist_push(v4, 0LL);
do
{
ts_slist_push(v4, v5);
v8 = *(_QWORD *)(v5 + 16);
if ( v8 )
ts_slist_unshift(v7, v8);
v9 = *(_QWORD *)(v5 + 8);
if ( v9 )
ts_slist_unshift(v7, v9);
v5 = ts_slist_pop(v7);
}
while ( v5 );
return ts_slist_pop(v4);
}
v12 = ts_slist_pop(v4);
if ( v12 )
return v12;
goto LABEL_32;
}
}
LABEL_33:
if ( !v4 )
return 0LL;
goto LABEL_23;
}
}
if ( *(_QWORD *)(v4 + 16) )
{
v17 = ts_slist_peek_tail(v4);
v18 = v17;
if ( *(_QWORD *)(v4 + 16) == 1LL )
{
v12 = ts_slist_pop(v17);
if ( v12 )
return v12;
}
v5 = ts_slist_pop(v4);
if ( !v5 )
goto LABEL_32;
}
else
{
v23 = ts_slist_new();
v18 = ts_slist_push(v4, v23);
}
while ( *(_QWORD *)(v5 + 8) )
{
ts_slist_push(v4, v5);
v5 = *(_QWORD *)(v5 + 8);
}
ts_slist_unshift(v18, v5);
do
{
if ( *(_QWORD *)(v4 + 16) <= 1uLL )
return ts_slist_pop(v18);
v19 = ts_slist_pop(v4);
ts_slist_unshift(v18, v19);
v20 = *(_QWORD *)(v19 + 16);
}
while ( !v20 );
ts_slist_push(v4, v20);
return ts_slist_pop(v18);
}

original_code:
struct ts_bnode_s *
ts_bnode_walk_r(struct ts_bnode_s *node, ts_bwalk_strategy_t strategy, void **queue) {
 struct ts_slist_s *row = ((void *)0);
 struct ts_slist_s *qlist;
 if (!(node)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 32); (*__errno_location ())=0; goto error; };
 if (!(queue)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 33); (*__errno_location ())=0; goto error; };
 if (*queue == ((void *)0)) {
  *queue = ts_slist_new();
 }
 qlist = *queue;
 switch (strategy) {
  case TS_BWALK_PREORDER:
   if (qlist->count > 0)
    node = ts_slist_pop(qlist);
   else
    ts_slist_push(qlist, ((void *)0));
   if (node == ((void *)0))
    goto error;
   if (node->gt)
    ts_slist_push(qlist, node->gt);
   if (node->lt)
    ts_slist_push(qlist, node->lt);
   return (node);
  case TS_BWALK_BREADTHFIRST:
   if (qlist->count > 0) {
    row = ts_slist_peek_head(qlist);
    node = ts_slist_pop(row);
   }
   else {
    row = ts_slist_push(qlist, ts_slist_new());
   }
   if (node == ((void *)0))
    goto error;
   if (node->lt)
    ts_slist_unshift(row, node->lt);
   if (node->gt)
    ts_slist_unshift(row, node->gt);
   return (node);
  case TS_BWALK_INORDER:
   if (qlist->count > 0) {
    row = ts_slist_peek_tail(qlist);
    if (qlist->count == 1) {
     node = ts_slist_pop(row);
     if (node)
      return(node);
    }
    node = ts_slist_pop(qlist);
   }
   else {
    row = ts_slist_push(qlist, ts_slist_new());
   }
   if (node == ((void *)0))
    goto error;
   while (node->lt) {
    ts_slist_push(qlist, node);
    node = node->lt;
   }
   ts_slist_unshift(row, node);
   while (qlist->count > 1) {
    node = ts_slist_pop(qlist);
    ts_slist_unshift(row, node);
    if (node->gt) {
     ts_slist_push(qlist, node->gt);
     node = ts_slist_pop(row);
     return (node);
    }
   }
   return (ts_slist_pop(row));
  case TS_BWALK_POSTORDER:
   if (qlist->count > 0) {
    node = ts_slist_pop(qlist);
    if (node)
     return (node);
   }
   else {
    row = ts_slist_push(qlist, ts_slist_new());
    ts_slist_push(qlist, ((void *)0));
   }
   if (node == ((void *)0))
    goto error;
ts_bwalk_postorder:
   ts_slist_push(qlist, node);
   if (node->gt) {
    ts_slist_unshift(row, node->gt);
   }
   if (node->lt) {
    ts_slist_unshift(row, node->lt);
   }
   node = ts_slist_pop(row);
   if (node == ((void *)0))
    return ts_slist_pop(qlist);
   goto ts_bwalk_postorder;
 }
error:
 if (queue && *queue)
  ts_slist_free(*queue);
 return (((void *)0));
}

canonical_original_code:
struct ts_bnode_s *ts_bnode_walk_r(struct ts_bnode_s *node, char strategy, void **queue) {
 struct ts_slist_s *row = ((void *)0);
 struct ts_slist_s *qlist;
 if (!(node)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 32); (*__errno_location ())=0; goto error; };
 if (!(queue)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 33); (*__errno_location ())=0; goto error; };
 if (*queue == ((void *)0)) {
  *queue = ts_slist_new();
 }
 qlist = *queue;
 switch (strategy) {
  case TS_BWALK_PREORDER:
   if (qlist->count > 0)
    node = ts_slist_pop(qlist);
   else
    ts_slist_push(qlist, ((void *)0));
   if (node == ((void *)0))
    goto error;
   if (node->gt)
    ts_slist_push(qlist, node->gt);
   if (node->lt)
    ts_slist_push(qlist, node->lt);
   return (node);
  case TS_BWALK_BREADTHFIRST:
   if (qlist->count > 0) {
    row = ts_slist_peek_head(qlist);
    node = ts_slist_pop(row);
   }
   else {
    row = ts_slist_push(qlist, ts_slist_new());
   }
   if (node == ((void *)0))
    goto error;
   if (node->lt)
    ts_slist_unshift(row, node->lt);
   if (node->gt)
    ts_slist_unshift(row, node->gt);
   return (node);
  case TS_BWALK_INORDER:
   if (qlist->count > 0) {
    row = ts_slist_peek_tail(qlist);
    if (qlist->count == 1) {
     node = ts_slist_pop(row);
     if (node)
      return(node);
    }
    node = ts_slist_pop(qlist);
   }
   else {
    row = ts_slist_push(qlist, ts_slist_new());
   }
   if (node == ((void *)0))
    goto error;
   while (node->lt) {
    ts_slist_push(qlist, node);
    node = node->lt;
   }
   ts_slist_unshift(row, node);
   while (qlist->count > 1) {
    node = ts_slist_pop(qlist);
    ts_slist_unshift(row, node);
    if (node->gt) {
     ts_slist_push(qlist, node->gt);
     node = ts_slist_pop(row);
     return (node);
    }
   }
   return (ts_slist_pop(row));
  case TS_BWALK_POSTORDER:
   if (qlist->count > 0) {
    node = ts_slist_pop(qlist);
    if (node)
     return (node);
   }
   else {
    row = ts_slist_push(qlist, ts_slist_new());
    ts_slist_push(qlist, ((void *)0));
   }
   if (node == ((void *)0))
    goto error;
ts_bwalk_postorder:
   ts_slist_push(qlist, node);
   if (node->gt) {
    ts_slist_unshift(row, node->gt);
   }
   if (node->lt) {
    ts_slist_unshift(row, node->lt);
   }
   node = ts_slist_pop(row);
   if (node == ((void *)0))
    return ts_slist_pop(qlist);
   goto ts_bwalk_postorder;
 }
error:
 if (queue && *queue)
  ts_slist_free(*queue);
 return (((void *)0));
}

variable_types:
node
struct ts_bnode_s *

variable_types: strategy char

variable_types:
queue
void **

return_type: struct ts_bnode_s { void *key; struct ts_bnode_s *lt; struct ts_bnode_s *gt; } *


repo: twinshadow/tslibc

decompiled_code:
void *ts_btree_new()
{
void *v0; // r12

v0 = calloc(1uLL, 0x18uLL);
if ( !v0 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 263LL);
*_errno_location() = 0;
}
return v0;
}

canonical_decompiled_code:
void *func2()
{
void *v0; // r12

v0 = calloc(1uLL, 0x18uLL);
if ( !v0 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 263LL);
*_errno_location() = 0;
}
return v0;
}

original_code:
struct ts_btree_s *
ts_btree_new(void) {
 struct ts_btree_s *tree;
 tree = calloc(1, sizeof(struct ts_btree_s));
 if (!(tree)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 263); (*__errno_location ())=0; goto error; };
 return tree;
error:
 return ((void *)0);
}

canonical_original_code:
struct ts_btree_s *ts_btree_new() {
 struct ts_btree_s *tree;
 tree = calloc(1, sizeof(struct ts_btree_s));
 if (!(tree)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 263); (*__errno_location ())=0; goto error; };
 return tree;
error:
 return ((void *)0);
}

variable_types: struct ts_btree_s { struct ts_bnode_s { void *key; struct ts_bnode_s *lt; struct ts_bnode_s *gt; } *head; unsigned long count; char (*compare)(void *a, void *b); } *

user_defined_types: struct ts_btree_s { struct ts_bnode_s *head; unsigned long count; char (*compare)(void *a, void *b); }


decompiled_code:
void __fastcall ts_btree_free(_QWORD **a1)
{
__int64 v1; // rcx
_QWORD *v2; // rdi

v1 = 272LL;
if ( a1 )
{
v2 = *a1;
if ( v2 )
{
ts_bnode_free_localalias(v2);
return;
}
v1 = 273LL;
}
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", v1);
*_errno_location() = 0;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD **a1)
{
__int64 v1; // rcx
_QWORD *v2; // rdi

v1 = 272LL;
if ( a1 )
{
v2 = *a1;
if ( v2 )
{
func0(v2);
return;
}
v1 = 273LL;
}
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", v1);
*_errno_location() = 0;
}

original_code:
void
ts_btree_free(struct ts_btree_s *tree) {
 if (!(tree)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 272); (*__errno_location ())=0; goto error; };
 if (!(tree->head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 273); (*__errno_location ())=0; goto error; };
 ts_bnode_free(tree->head);
error:
 return;
}

return_type: void

user_defined_types: struct ts_bnode_s { void *key; struct ts_bnode_s *lt; struct ts_bnode_s *gt; }


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

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
if ( ts_bnode_operate_localalias((__int64 *)a1, a2, *(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16), 1) )
{
++*(_QWORD *)(a1 + 8);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
v3 = ts_bnode_new((__int64)a2);
++*(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = v3;
result = 0LL;
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 282LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
if ( ts_bnode_operate_localalias((__int64 *)a1, a2, *(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16), 1) )
{
++*(_QWORD *)(a1 + 8);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
v3 = ts_bnode_new((__int64)a2);
++*(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = v3;
result = 0LL;
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 282LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
ts_btree_add(struct ts_btree_s *tree,
            void *data) {
 if (!(tree)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 282); (*__errno_location ())=0; goto error; };
 if (tree->head == ((void *)0)) {
  tree->head = ts_bnode_new(data);
  tree->count++;
  return (0);
 }
 if (ts_bnode_operate(&tree->head, data, tree->compare, TS_BOP_INSERT)) {
  tree->count++;
  return (0);
 }
error:
 return -1;
}

variable_types:
data
void *

return_type: int


decompiled_code:
__int64 __fastcall ts_btree_remove(__int64 a1, __int64 *a2)
{
__int64 *v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( *(_QWORD *)a1
&& (v3 = ts_bnode_operate_localalias((__int64 *)a1, a2, *(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16), 2)) != 0LL )
{
--*(_QWORD *)(a1 + 8);
ts_bnode_free_localalias(v3);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 300LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)a1
&& (v3 = ts_bnode_operate_localalias((__int64 *)a1, a2, *(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16), 2)) != 0LL )
{
--*(_QWORD *)(a1 + 8);
func0(v3);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 300LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
ts_btree_remove(struct ts_btree_s *tree,
  void *data) {
 struct ts_bnode_s *node;
 if (!(tree)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 300); (*__errno_location ())=0; goto error; };
 if (tree->head == ((void *)0))
  goto error;
 node = ts_bnode_operate(&tree->head, data, tree->compare, TS_BOP_REMOVE);
 if (node != ((void *)0)) {
  tree->count--;
  ts_bnode_free(node);
  return (0);
 }
error:
 return -1;
}

variable_types: struct ts_bnode_s { void *key; struct ts_bnode_s *lt; struct ts_bnode_s *gt; } *


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

if ( a1 )
{
if ( *(_QWORD *)a1 )
result = (unsigned int)-(*ts_bnode_lookup(
(_QWORD *)a1,
a2,
*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16),
0LL) == 0LL);
else
result = 0xFFFFFFFFLL;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 316LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)a1 )
result = (unsigned int)-(*ts_bnode_lookup(
(_QWORD *)a1,
a2,
*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16),
0LL) == 0LL);
else
result = 0xFFFFFFFFLL;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "btree.c", 316LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
ts_btree_exists(struct ts_btree_s *tree,
  void *data) {
 if (!(tree)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "btree.c", 316); (*__errno_location ())=0; goto error; };
 if (tree->head == ((void *)0))
  goto error;
 if (*ts_bnode_lookup(&tree->head, data, tree->compare, ((void *)0)))
  return (0);
error:
 return (-1);
}


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

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

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

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

original_code:
void
print_int_list(int count, int *list)
{
 int iter;
 for (iter = 0; iter < count; iter++)
 {
  printf("%02d ", list[iter]);
 }
 puts("");
}

variable_types: count int

variable_types:
list
int *

variable_types: iter int


issorted

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

if ( a1 <= 1 )
return 1LL;
v2 = (__int64)&a2[a1 - 2 + 1];
while ( a2[1] >= *a2 )
{
if ( ++a2 == (_DWORD *)v2 )
return 1LL;
}
return 0LL;
}

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

if ( a1 <= 1 )
return 1LL;
v2 = (__int64)&a2[a1 - 2 + 1];
while ( a2[1] >= *a2 )
{
if ( ++a2 == (_DWORD *)v2 )
return 1LL;
}
return 0LL;
}

original_code:
int
issorted(int count, int *list)
{
 int iter;
 for (iter = 1; iter < count; iter++)
  if (list[iter] < list[iter - 1])
   return 0;
 return 1;
}


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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

original_code:
int
compare_int(void *a, void *b) {
 if (*(int*)a == *(int*)b)
  return 0;
 else if (*(int*)a < *(int*)b)
  return -1;
 else
  return 1;
}

canonical_original_code:
int compare_int(void *a, void *b) {
 if (*(int *)a == *(int *)b)
  return 0;
 else if (*(int *)a < *(int *)b)
  return -1;
 else
  return 1;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
unsigned __int64 __fastcall ts_strnrot(int a1, char *a2, __int64 a3)
{
unsigned __int64 result; // rax
_BYTE *v4; // rbp
int v5; // esi
int v6; // er13
const char *v7; // r14
char *v8; // rbx
unsigned __int64 v9; // r15
size_t v10; // rsi
size_t v11; // r10
_BYTE *v12; // [rsp+0h] [rbp-68h]
char v13; // [rsp+10h] [rbp-58h] BYREF
const char *v14; // [rsp+18h] [rbp-50h]
const char *v15; // [rsp+20h] [rbp-48h]
char v16[64]; // [rsp+28h] [rbp-40h] BYREF

v14 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
result = (unsigned __int64)"0123456789";
v15 = "0123456789";
if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: A NULL pointer was passed in.\n", "strrot.c", 42LL);
goto LABEL_24;
}
v4 = a2;
v5 = *a2;
if ( !(_BYTE)v5 )
{
fprintf(stderr, "DEBUG: %s:%d: Empty string.\n", "strrot.c", 43LL);
goto LABEL_24;
}
v6 = a1;
if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Offset does nothing\n", "strrot.c", 44LL);
LABEL_24:
result = (unsigned __int64)_errno_location();
*(_DWORD *)result = 0;
return result;
}
if ( a3 )
{
v12 = &v4[a3];
while ( 1 )
{
v7 = "abcdefghijklmnopqrstuvwxyz";
v8 = &v13;
result = (unsigned __int64)strchr("abcdefghijklmnopqrstuvwxyz", v5);
v9 = result;
if ( !result )
goto LABEL_18;
while ( 1 )
{
v10 = strlen(v7);
if ( v6 > v10 )
{
v11 = -(__int64)v10;
if ( v6 > 0 )
v11 = v10;
v6 %= v11;
}
result = (unsigned int)(v6 + v10);
if ( v6 < 0 )
v6 += v10;
if ( v6 && v6 != v10 )
{
if ( v6 + v9 - (unsigned __int64)v7 >= v10 )
result = *(unsigned __int8 *)(v6 + v9 - v10);
else
result = *(unsigned __int8 *)(v9 + v6);
*v4 = result;
}
LABEL_18:
v8 += 8;
if ( v16 == v8 )
break;
while ( 1 )
{
v7 = *(const char **)v8;
result = (unsigned __int64)strchr(*(const char **)v8, (char)*v4);
v9 = result;
if ( result )
break;
v8 += 8;
if ( v16 == v8 )
goto LABEL_21;
}
}
LABEL_21:
if ( v12 == ++v4 )
return result;
v5 = (char)*v4;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, char *a2, __int64 a3)
{
unsigned __int64 result; // rax
_BYTE *v4; // rbp
int v5; // esi
int v6; // er13
const char *v7; // r14
char *v8; // rbx
unsigned __int64 v9; // r15
size_t v10; // rsi
size_t v11; // r10
_BYTE *v12; // [rsp+0h] [rbp-68h]
char v13; // [rsp+10h] [rbp-58h] BYREF
const char *v14; // [rsp+18h] [rbp-50h]
const char *v15; // [rsp+20h] [rbp-48h]
char v16[64]; // [rsp+28h] [rbp-40h] BYREF

v14 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
result = (unsigned __int64)"0123456789";
v15 = "0123456789";
if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: A NULL pointer was passed in.\n", "strrot.c", 42LL);
goto LABEL_24;
}
v4 = a2;
v5 = *a2;
if ( !(_BYTE)v5 )
{
fprintf(stderr, "DEBUG: %s:%d: Empty string.\n", "strrot.c", 43LL);
goto LABEL_24;
}
v6 = a1;
if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Offset does nothing\n", "strrot.c", 44LL);
LABEL_24:
result = (unsigned __int64)_errno_location();
*(_DWORD *)result = 0;
return result;
}
if ( a3 )
{
v12 = &v4[a3];
while ( 1 )
{
v7 = "abcdefghijklmnopqrstuvwxyz";
v8 = &v13;
result = (unsigned __int64)strchr("abcdefghijklmnopqrstuvwxyz", v5);
v9 = result;
if ( !result )
goto LABEL_18;
while ( 1 )
{
v10 = strlen(v7);
if ( v6 > v10 )
{
v11 = -(__int64)v10;
if ( v6 > 0 )
v11 = v10;
v6 %= v11;
}
result = (unsigned int)(v6 + v10);
if ( v6 < 0 )
v6 += v10;
if ( v6 && v6 != v10 )
{
if ( v6 + v9 - (unsigned __int64)v7 >= v10 )
result = *(unsigned __int8 *)(v6 + v9 - v10);
else
result = *(unsigned __int8 *)(v9 + v6);
*v4 = result;
}
LABEL_18:
v8 += 8;
if ( v16 == v8 )
break;
while ( 1 )
{
v7 = *(const char **)v8;
result = (unsigned __int64)strchr(*(const char **)v8, (char)*v4);
v9 = result;
if ( result )
break;
v8 += 8;
if ( v16 == v8 )
goto LABEL_21;
}
}
LABEL_21:
if ( v12 == ++v4 )
return result;
v5 = (char)*v4;
}
}
return result;
}

original_code:
void
ts_strnrot(int offset, char *str, size_t len)
{
 const char *ciphers[3] = {
  "abcdefghijklmnopqrstuvwxyz",
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
  "0123456789",
 };
 const size_t ciphers_len = (sizeof(ciphers) / sizeof(ciphers[0]));
 size_t cipher_strlen;
 size_t cipher_idx;
 char *chr_idx;
 size_t idx;
 if (!(str)) { fprintf(stderr, "DEBUG: %s:%d: " "A NULL pointer was passed in." "\n", "strrot.c", 42); (*__errno_location ())=0; goto error; };
 if (!(str[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "Empty string." "\n", "strrot.c", 43); (*__errno_location ())=0; goto error; };
 if (!(offset != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Offset does nothing" "\n", "strrot.c", 44); (*__errno_location ())=0; goto error; };
 for (idx = 0; idx < len; idx++)
 {
  for (cipher_idx = 0; cipher_idx < ciphers_len; cipher_idx++)
  {
   if (!((chr_idx = strchr(ciphers[cipher_idx], str[idx]))))
    continue;
   cipher_strlen = strlen(ciphers[cipher_idx]);
   { if ((offset) > (cipher_strlen)) (offset) %= (((offset) > 0) ? (((cipher_strlen) > 0) ? (cipher_strlen) : -(cipher_strlen)) : (((cipher_strlen) < 0) ? (cipher_strlen) : -(cipher_strlen))); if ((offset) < 0) (offset) = (cipher_strlen) - -(offset); };
   if (offset == 0 || offset == cipher_strlen)
    continue;
   str[idx] = (((chr_idx - ciphers[cipher_idx]) + offset
      < cipher_strlen)
     ? *(chr_idx + offset)
     : *(ciphers[cipher_idx] +
      (((chr_idx - ciphers[cipher_idx]) + offset) - cipher_strlen)
     )
   );
  }
 }
 goto out;
error:
out:
 return;
}

canonical_original_code:
void ts_strnrot(int offset, char *str, unsigned long len)
{
 char *ciphers[3] = {
  "abcdefghijklmnopqrstuvwxyz",
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
  "0123456789",
 };
 unsigned long ciphers_len = (sizeof(ciphers) / sizeof(ciphers[0]));
 unsigned long cipher_strlen;
 unsigned long cipher_idx;
 char *chr_idx;
 unsigned long idx;
 if (!(str)) { fprintf(stderr, "DEBUG: %s:%d: " "A NULL pointer was passed in." "\n", "strrot.c", 42); (*__errno_location ())=0; goto error; };
 if (!(str[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "Empty string." "\n", "strrot.c", 43); (*__errno_location ())=0; goto error; };
 if (!(offset != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Offset does nothing" "\n", "strrot.c", 44); (*__errno_location ())=0; goto error; };
 for (idx = 0; idx < len; idx++)
 {
  for (cipher_idx = 0; cipher_idx < ciphers_len; cipher_idx++)
  {
   if (!((chr_idx = strchr(ciphers[cipher_idx], str[idx]))))
    continue;
   cipher_strlen = strlen(ciphers[cipher_idx]);
   { if ((offset) > (cipher_strlen)) (offset) %= (((offset) > 0) ? (((cipher_strlen) > 0) ? (cipher_strlen) : -(cipher_strlen)) : (((cipher_strlen) < 0) ? (cipher_strlen) : -(cipher_strlen))); if ((offset) < 0) (offset) = (cipher_strlen) - -(offset); };
   if (offset == 0 || offset == cipher_strlen)
    continue;
   str[idx] = (((chr_idx - ciphers[cipher_idx]) + offset
      < cipher_strlen)
     ? *(chr_idx + offset)
     : *(ciphers[cipher_idx] +
      (((chr_idx - ciphers[cipher_idx]) + offset) - cipher_strlen)
     )
   );
  }
 }
 goto out;
error:
out:
 return;
}

variable_types: offset int

variable_types:
str
char *

variable_types:
len
unsigned long

variable_types:
ciphers
char *[3]

variable_types:
idx
unsigned long


decompiled_code:
unsigned __int64 __fastcall ts_strrot(int a1, char *a2)
{
__int64 v2; // rax

v2 = strnlen(a2, 0xFFFFFFFFFFFFFFFFLL);
return ts_strnrot(a1, a2, v2);
}

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

v2 = strnlen(a2, 0xFFFFFFFFFFFFFFFFLL);
return func0(a1, a2, v2);
}

original_code:
void
ts_strrot(int offset, char *str)
{
 ts_strnrot(offset, str, strnlen(str, (18446744073709551615UL)));
}


decompiled_code:
struct addrinfo *__fastcall ts_getaddr(char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
int v6; // eax
const char *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

pai = 0LL;
if ( a3 == 1 )
return (struct addrinfo *)ts_getaddr_unix(a1, a4, a5, a6);
req.ai_family = a3;
req.ai_socktype = a4;
req.ai_flags = a5;
req.ai_protocol = a6;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v6 = getaddrinfo(a1, a2, &req, &pai);
if ( !v6 )
return pai;
v8 = gai_strerror(v6);
perror(v8);
if ( !pai )
return 0LL;
if ( pai->ai_addr )
{
freeaddrinfo(pai);
return 0LL;
}
free(pai);
return 0LL;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func0(char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
int v6; // eax
const char *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

pai = 0LL;
if ( a3 == 1 )
return (struct addrinfo *)ts_getaddr_unix(a1, a4, a5, a6);
req.ai_family = a3;
req.ai_socktype = a4;
req.ai_flags = a5;
req.ai_protocol = a6;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v6 = getaddrinfo(a1, a2, &req, &pai);
if ( !v6 )
return pai;
v8 = gai_strerror(v6);
perror(v8);
if ( !pai )
return 0LL;
if ( pai->ai_addr )
{
freeaddrinfo(pai);
return 0LL;
}
free(pai);
return 0LL;
}

original_code:
struct addrinfo*
ts_getaddr(const char *address,
 const char *port,
 const int family,
 const int socktype,
 const int flags,
 const int proto)
{
 struct addrinfo hint;
 struct addrinfo *adr = ((void *)0);
 int err;
 if (family == 1) {
  return ts_getaddr_unix(address, socktype, flags, proto);
 }
 memset(&hint, 0, sizeof(hint));
 hint.ai_family = family;
 hint.ai_socktype = socktype;
 hint.ai_flags = flags;
 hint.ai_protocol = proto;
 err = getaddrinfo(address, port, &hint, &adr);
 if (err != 0)
  goto error;
 else
  goto out;
error:
 perror(gai_strerror(err));
 if (adr != ((void *)0)) {
  if (adr->ai_addr != ((void *)0))
   freeaddrinfo(adr);
  else
   free(adr);
 }
 adr = ((void *)0);
out:
 return (adr);
}

canonical_original_code:
struct addrinfo *ts_getaddr(char *address, char *port, int family, int socktype, int flags, int proto)
{
 struct addrinfo hint;
 struct addrinfo *adr = ((void *)0);
 int err;
 if (family == 1) {
  return ts_getaddr_unix(address, socktype, flags, proto);
 }
 memset(&hint, 0, sizeof(hint));
 hint.ai_family = family;
 hint.ai_socktype = socktype;
 hint.ai_flags = flags;
 hint.ai_protocol = proto;
 err = getaddrinfo(address, port, &hint, &adr);
 if (err != 0)
  goto error;
 else
  goto out;
error:
 perror(gai_strerror(err));
 if (adr != ((void *)0)) {
  if (adr->ai_addr != ((void *)0))
   freeaddrinfo(adr);
  else
   free(adr);
 }
 adr = ((void *)0);
out:
 return (adr);
}

variable_types:
address
char *

variable_types:
port
char *

variable_types: family int

variable_types: socktype int

variable_types: flags int

variable_types: proto 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: err 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; }


decompiled_code:
void __fastcall ts_memshift(unsigned __int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v5; // rcx
__int64 v6; // rcx
const char *v7; // rsi
size_t v8; // r15
size_t v9; // r13
void *v10; // rax
void *v11; // r14
size_t v12; // rbx

if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: A NULL pointer was passed in.\n", "strshift.c", 34LL);
goto LABEL_19;
}
if ( a3 <= 1 )
{
fprintf(stderr, "DEBUG: %s:%d: String too small.\n", "strshift.c", 35LL);
goto LABEL_19;
}
if ( !(_DWORD)a1 )
{
v6 = 37LL;
v7 = "DEBUG: %s:%d: Offset does nothing\n";
LABEL_18:
fprintf(stderr, v7, "strshift.c", v6);
LABEL_19:
*_errno_location() = 0;
return;
}
if ( (int)a1 > a3 )
{
v5 = -(__int64)a3;
if ( (int)a1 > 0 )
v5 = a3;
a1 = (int)a1 % v5;
}
v6 = 42LL;
if ( (a1 & 0x80000000) != 0LL )
LODWORD(a1) = a1 + a3;
v7 = "DEBUG: %s:%d: Buflen does nothing\n";
v8 = a3 - (int)a1;
v9 = v8;
if ( (int)a1 <= v8 )
v9 = (int)a1;
if ( !v9 )
goto LABEL_18;
v10 = malloc(v9);
v11 = v10;
if ( !v10 )
{
fprintf(stderr, "DEBUG: %s:%d: Out of memory.\n", "strshift.c", 44LL);
goto LABEL_19;
}
if ( (int)a1 <= v9 )
{
memcpy(v10, &a2[v8], (int)a1);
memmove(&a2[(int)a1], a2, v8);
memcpy(a2, v11, (int)a1);
}
else
{
v12 = a3 - v9;
memcpy(v10, a2, v9);
memmove(a2, &a2[v9], v12);
memcpy(&a2[v12], v11, v9);
}
free(v11);
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v5; // rcx
__int64 v6; // rcx
const char *v7; // rsi
size_t v8; // r15
size_t v9; // r13
void *v10; // rax
void *v11; // r14
size_t v12; // rbx

if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: A NULL pointer was passed in.\n", "strshift.c", 34LL);
goto LABEL_19;
}
if ( a3 <= 1 )
{
fprintf(stderr, "DEBUG: %s:%d: String too small.\n", "strshift.c", 35LL);
goto LABEL_19;
}
if ( !(_DWORD)a1 )
{
v6 = 37LL;
v7 = "DEBUG: %s:%d: Offset does nothing\n";
LABEL_18:
fprintf(stderr, v7, "strshift.c", v6);
LABEL_19:
*_errno_location() = 0;
return;
}
if ( (int)a1 > a3 )
{
v5 = -(__int64)a3;
if ( (int)a1 > 0 )
v5 = a3;
a1 = (int)a1 % v5;
}
v6 = 42LL;
if ( (a1 & 0x80000000) != 0LL )
LODWORD(a1) = a1 + a3;
v7 = "DEBUG: %s:%d: Buflen does nothing\n";
v8 = a3 - (int)a1;
v9 = v8;
if ( (int)a1 <= v8 )
v9 = (int)a1;
if ( !v9 )
goto LABEL_18;
v10 = malloc(v9);
v11 = v10;
if ( !v10 )
{
fprintf(stderr, "DEBUG: %s:%d: Out of memory.\n", "strshift.c", 44LL);
goto LABEL_19;
}
if ( (int)a1 <= v9 )
{
memcpy(v10, &a2[v8], (int)a1);
memmove(&a2[(int)a1], a2, v8);
memcpy(a2, v11, (int)a1);
}
else
{
v12 = a3 - v9;
memcpy(v10, a2, v9);
memmove(a2, &a2[v9], v12);
memcpy(&a2[v12], v11, v9);
}
free(v11);
}

original_code:
void
ts_memshift(int offset, void *ptr, size_t len)
{
 void *buf;
 size_t buflen;
 if (!(ptr)) { fprintf(stderr, "DEBUG: %s:%d: " "A NULL pointer was passed in." "\n", "strshift.c", 34); (*__errno_location ())=0; goto error; };
 if (!(len > 1)) { fprintf(stderr, "DEBUG: %s:%d: " "String too small." "\n", "strshift.c", 35); (*__errno_location ())=0; goto error; };
 if (!(offset != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Offset does nothing" "\n", "strshift.c", 37); (*__errno_location ())=0; goto error; };
 { if ((offset) > (len)) (offset) %= (((offset) > 0) ? (((len) > 0) ? (len) : -(len)) : (((len) < 0) ? (len) : -(len))); if ((offset) < 0) (offset) = (len) - -(offset); };
 if (!(offset != 0 || len != offset)) { fprintf(stderr, "DEBUG: %s:%d: " "Offset does nothing." "\n", "strshift.c", 39); (*__errno_location ())=0; goto error; };
 buflen = (offset < len - offset) ? offset : len - offset;
 if (!(buflen != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Buflen does nothing" "\n", "strshift.c", 42); (*__errno_location ())=0; goto error; };
 buf = malloc(buflen);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Out of memory." "\n", "strshift.c", 44); (*__errno_location ())=0; goto error; };
 if (buflen < offset) {
  memmove(buf, ptr, buflen);
  memmove(ptr, ptr + buflen, len - buflen);
  memmove(ptr + (len - buflen), buf, buflen);
 }
 else {
  memmove(buf, ptr + (len - offset), offset);
  memmove(ptr + offset, ptr, len - offset);
  memmove(ptr, buf, offset);
 }
 free(buf);
 goto out;
error:
out:
 return;
}

canonical_original_code:
void ts_memshift(int offset, void *ptr, unsigned long len)
{
 void *buf;
 unsigned long buflen;
 if (!(ptr)) { fprintf(stderr, "DEBUG: %s:%d: " "A NULL pointer was passed in." "\n", "strshift.c", 34); (*__errno_location ())=0; goto error; };
 if (!(len > 1)) { fprintf(stderr, "DEBUG: %s:%d: " "String too small." "\n", "strshift.c", 35); (*__errno_location ())=0; goto error; };
 if (!(offset != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Offset does nothing" "\n", "strshift.c", 37); (*__errno_location ())=0; goto error; };
 { if ((offset) > (len)) (offset) %= (((offset) > 0) ? (((len) > 0) ? (len) : -(len)) : (((len) < 0) ? (len) : -(len))); if ((offset) < 0) (offset) = (len) - -(offset); };
 if (!(offset != 0 || len != offset)) { fprintf(stderr, "DEBUG: %s:%d: " "Offset does nothing." "\n", "strshift.c", 39); (*__errno_location ())=0; goto error; };
 buflen = (offset < len - offset) ? offset : len - offset;
 if (!(buflen != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Buflen does nothing" "\n", "strshift.c", 42); (*__errno_location ())=0; goto error; };
 buf = malloc(buflen);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Out of memory." "\n", "strshift.c", 44); (*__errno_location ())=0; goto error; };
 if (buflen < offset) {
  memmove(buf, ptr, buflen);
  memmove(ptr, ptr + buflen, len - buflen);
  memmove(ptr + (len - buflen), buf, buflen);
 }
 else {
  memmove(buf, ptr + (len - offset), offset);
  memmove(ptr + offset, ptr, len - offset);
  memmove(ptr, buf, offset);
 }
 free(buf);
 goto out;
error:
out:
 return;
}

variable_types:
ptr
void *

variable_types:
buf
void *

variable_types:
buflen
unsigned long


decompiled_code:
void __fastcall ts_strshift(unsigned int a1, char *a2)
{
unsigned __int64 v2; // rax

if ( *a2 )
{
v2 = strnlen(a2, 0xFFFFFFFFFFFFFFFFLL);
ts_memshift(a1, a2, v2);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Empty string.\n", "strshift.c", 67LL);
*_errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1, char *a2)
{
unsigned __int64 v2; // rax

if ( *a2 )
{
v2 = strnlen(a2, 0xFFFFFFFFFFFFFFFFLL);
func0(a1, a2, v2);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Empty string.\n", "strshift.c", 67LL);
*_errno_location() = 0;
}
}

original_code:
void
ts_strshift(int offset, char *str)
{
 if (!(str[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "Empty string." "\n", "strshift.c", 67); (*__errno_location ())=0; goto error; };
 ts_memshift(offset, str, strnlen(str, (18446744073709551615UL)));
error:
 return;
}


original_code:
void
ts_map_free(struct ts_map_s **head) {
 struct ts_map_item_s **item;
 struct ts_map_item_s *swap = ((void *)0);
 size_t idx, count;
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 35); (*__errno_location ())=0; goto error; };
 if (!(*head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 36); (*__errno_location ())=0; goto error; };
 if ((*head)->map) {
  count = 1 << (*head)->logsize;
  for (idx = 0; idx < count; idx++) {
   item = &(*head)->map[idx];
   while (*item != ((void *)0)) {
    swap = *item;
    *item = (*item)->next;
    free(swap);
   }
  }
  free((*head)->map);
 }
 free(*head);
 *head = ((void *)0);
error:
 return;
}

canonical_original_code:
void ts_map_free(struct ts_map_s **head) {
 struct ts_map_item_s **item;
 struct ts_map_item_s *swap = ((void *)0);
 unsigned long idx; unsigned long count;
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 35); (*__errno_location ())=0; goto error; };
 if (!(*head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 36); (*__errno_location ())=0; goto error; };
 if ((*head)->map) {
  count = 1 << (*head)->logsize;
  for (idx = 0; idx < count; idx++) {
   item = &(*head)->map[idx];
   while (*item != ((void *)0)) {
    swap = *item;
    *item = (*item)->next;
    free(swap);
   }
  }
  free((*head)->map);
 }
 free(*head);
 *head = ((void *)0);
error:
 return;
}

variable_types: struct ts_map_s { unsigned short (*hash)(void *ptr, unsigned long len); struct ts_map_item_s { struct ts_map_item_s *next; unsigned short hash; void **key; void **value; } **map; unsigned long logsize; unsigned long count; unsigned long len; } **

variable_types:
count
unsigned long

user_defined_types: struct ts_map_s { unsigned short (*hash)(void *ptr, unsigned long len); struct ts_map_item_s **map; unsigned long logsize; unsigned long count; unsigned long len; }


decompiled_code:
void __fastcall ts_map_resize(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax

if ( a1 && *(_QWORD *)(a1 + 16) < a2 && 1 << a2 )
{
v2 = realloc(*(void **)(a1 + 8), 1 << a2);
if ( v2 )
{
*(_QWORD *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 32) = 1 << a2;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "map.c", 70LL);
*_errno_location() = 0;
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax

if ( a1 && *(_QWORD *)(a1 + 16) < a2 && 1 << a2 )
{
v2 = realloc(*(void **)(a1 + 8), 1 << a2);
if ( v2 )
{
*(_QWORD *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 32) = 1 << a2;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "map.c", 70LL);
*_errno_location() = 0;
}
}
}

original_code:
void
ts_map_resize(struct ts_map_s *head, size_t logsize) {
 size_t count;
 struct ts_map_item_s **buf;
 if (head == ((void *)0))
  return;
 if (head->logsize >= logsize)
  return;
 count = 1 << logsize;
 if (count < 1)
  return;
 buf = realloc(head->map, count);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 70); (*__errno_location ())=0; goto error; };
 head->map = buf;
 head->logsize = logsize;
 head->len = count;
 return;
error:
 return;
}

canonical_original_code:
void ts_map_resize(struct ts_map_s *head, unsigned long logsize) {
 unsigned long count;
 struct ts_map_item_s **buf;
 if (head == ((void *)0))
  return;
 if (head->logsize >= logsize)
  return;
 count = 1 << logsize;
 if (count < 1)
  return;
 buf = realloc(head->map, count);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 70); (*__errno_location ())=0; goto error; };
 head->map = buf;
 head->logsize = logsize;
 head->len = count;
 return;
error:
 return;
}

variable_types: struct ts_map_s { unsigned short (*hash)(void *ptr, unsigned long len); struct ts_map_item_s { struct ts_map_item_s *next; unsigned short hash; void **key; void **value; } **map; unsigned long logsize; unsigned long count; unsigned long len; } *

variable_types:
logsize
unsigned long


original_code:
void
ts_map_rem(void *ptr, size_t len, struct ts_map_s *head) {
 struct ts_map_item_s **item, *next;
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 126); (*__errno_location ())=0; goto error; }
 item = ts_map_lookup(ptr, len, head);
 if (*item == ((void *)0))
  return;
 next = (*item)->next;
 free(*item);
 head->count--;
 *item = next;
error:
 return;
}

canonical_original_code:
void ts_map_rem(void *ptr, unsigned long len, struct ts_map_s *head) {
 struct ts_map_item_s **item; struct ts_map_item_s *next;
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "map.c", 126); (*__errno_location ())=0; goto error; }
 item = ts_map_lookup(ptr, len, head);
 if (*item == ((void *)0))
  return;
 next = (*item)->next;
 free(*item);
 head->count--;
 *item = next;
error:
 return;
}

variable_types:
len
unsigned long

variable_types: struct ts_map_item_s { struct ts_map_item_s *next; unsigned short hash; void **key; void **value; } **


decompiled_code:
__int64 __fastcall ts_hash_oat(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
int v3; // eax
int v4; // edx
int v5; // eax
int v6; // eax
int v7; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = 0;
do
{
v4 = *a1++;
v5 = 1025 * (v3 + v4);
HIWORD(v4) = HIWORD(v5);
LOWORD(v4) = (unsigned __int16)v5 >> 6;
v3 = v4 ^ v5;
}
while ( v2 != a1 );
v6 = 9 * v3;
HIWORD(v7) = HIWORD(v6);
LOWORD(v7) = (unsigned __int16)v6 >> 11;
return 32769 * (v7 ^ (unsigned int)v6);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
int v3; // eax
int v4; // edx
int v5; // eax
int v6; // eax
int v7; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = 0;
do
{
v4 = *a1++;
v5 = 1025 * (v3 + v4);
HIWORD(v4) = HIWORD(v5);
LOWORD(v4) = (unsigned __int16)v5 >> 6;
v3 = v4 ^ v5;
}
while ( v2 != a1 );
v6 = 9 * v3;
HIWORD(v7) = HIWORD(v6);
LOWORD(v7) = (unsigned __int16)v6 >> 11;
return 32769 * (v7 ^ (unsigned int)v6);
}

original_code:
ts_hash_int_t
ts_hash_oat(void *key, size_t len)
{
 unsigned char *chr = key;
 ts_hash_int_t hash = 0;
 size_t idx;
 for (idx = 0; idx < len; idx++) {
  hash += chr[idx];
  hash += (hash << 10);
  hash ^= (hash >> 6);
 }
 hash += (hash << 3);
 hash ^= (hash >> 11);
 hash += (hash << 15);
 return hash;
}

canonical_original_code:
unsigned short ts_hash_oat(void *key, unsigned long len)
{
 unsigned char *chr = key;
 unsigned short hash = 0;
 unsigned long idx;
 for (idx = 0; idx < len; idx++) {
  hash += chr[idx];
  hash += (hash << 10);
  hash ^= (hash >> 6);
 }
 hash += (hash << 3);
 hash ^= (hash >> 11);
 hash += (hash << 15);
 return hash;
}

variable_types:
key
void *

variable_types:
chr
unsigned char *

variable_types:
hash
unsigned short

variable_types:
idx
unsigned long

return_type: unsigned short


decompiled_code:
void __fastcall ts_strnrev(char *a1, __int64 a2)
{
char v2; // dl
char *v3; // rax
char v4; // cl

if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "strrev.c", 33LL);
goto LABEL_10;
}
v2 = *a1;
if ( !*a1 )
{
fprintf(stderr, "DEBUG: %s:%d: String is empty\n", "strrev.c", 33LL);
LABEL_10:
*_errno_location() = 0;
return;
}
if ( a2 != 1 )
{
v3 = &a1[a2 - 1];
if ( a1 < v3 )
{
while ( 1 )
{
v4 = *v3;
++a1;
--v3;
*(a1 - 1) = v4;
v3[1] = v2;
if ( a1 >= v3 )
break;
v2 = *a1;
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(char *a1, __int64 a2)
{
char v2; // dl
char *v3; // rax
char v4; // cl

if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "strrev.c", 33LL);
goto LABEL_10;
}
v2 = *a1;
if ( !*a1 )
{
fprintf(stderr, "DEBUG: %s:%d: String is empty\n", "strrev.c", 33LL);
LABEL_10:
*_errno_location() = 0;
return;
}
if ( a2 != 1 )
{
v3 = &a1[a2 - 1];
if ( a1 < v3 )
{
while ( 1 )
{
v4 = *v3;
++a1;
--v3;
*(a1 - 1) = v4;
v3[1] = v2;
if ( a1 >= v3 )
break;
v2 = *a1;
}
}
}
}

original_code:
void
ts_strnrev(char *head, const size_t len)
{
 char *tail, swap;
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrev.c", 33); (*__errno_location ())=0; goto error; }; if (!((head)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrev.c", 33); (*__errno_location ())=0; goto error; }; } while (0);;
 for (tail = ((len - 1) == 0 ? (head) : (head) + ((len - 1) * (sizeof(char)))); head < tail; head++, tail--)
  do { (swap) = (*head); (*head) = (*tail); (*tail) = (swap); } while (0);
error:
 return;
}

canonical_original_code:
void ts_strnrev(char *head, unsigned long len)
{
 char *tail; char swap;
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrev.c", 33); (*__errno_location ())=0; goto error; }; if (!((head)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrev.c", 33); (*__errno_location ())=0; goto error; }; } while (0);;
 for (tail = ((len - 1) == 0 ? (head) : (head) + ((len - 1) * (sizeof(char)))); head < tail; head++, tail--)
  do { (swap) = (*head); (*head) = (*tail); (*tail) = (swap); } while (0);
error:
 return;
}

variable_types:
head
char *

variable_types:
tail
char *

variable_types: swap char


decompiled_code:
void __fastcall ts_strrev(char *a1)
{
const char *v1; // rsi
__int64 v2; // rax

v1 = "DEBUG: %s:%d: Value should not be NULL\n";
if ( a1 )
{
if ( *a1 )
{
v2 = strnlen(a1, 0xFFFFFFFFFFFFFFFFLL);
ts_strnrev(a1, v2);
return;
}
v1 = "DEBUG: %s:%d: String is empty\n";
}
fprintf(stderr, v1, "strrev.c", 43LL);
*_errno_location() = 0;
}

canonical_decompiled_code:
void __fastcall func1(char *a1)
{
const char *v1; // rsi
__int64 v2; // rax

v1 = "DEBUG: %s:%d: Value should not be NULL\n";
if ( a1 )
{
if ( *a1 )
{
v2 = strnlen(a1, 0xFFFFFFFFFFFFFFFFLL);
func0(a1, v2);
return;
}
v1 = "DEBUG: %s:%d: String is empty\n";
}
fprintf(stderr, v1, "strrev.c", 43LL);
*_errno_location() = 0;
}

original_code:
void
ts_strrev(char *str)
{
 do { if (!(str)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrev.c", 43); (*__errno_location ())=0; goto error; }; if (!((str)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrev.c", 43); (*__errno_location ())=0; goto error; }; } while (0);;
 ts_strnrev(str, strnlen(str, (18446744073709551615UL)));
error:
 return;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall insert_sort(void *dest, __int64 a2, size_t a3, int (__fastcall *a4)(char *, char *))
{
__int64 v4; // rcx
const char *v6; // rsi
void *v7; // r13
__int64 v8; // r12
char *v9; // r14
__int64 v12; // [rsp+8h] [rbp-50h]
char *src; // [rsp+10h] [rbp-48h]

v4 = 18LL;
if ( !dest )
goto LABEL_16;
v4 = 19LL;
if ( !a4 )
goto LABEL_16;
if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "isort.c", 20LL);
goto LABEL_18;
}
v4 = 21LL;
v6 = "DEBUG: %s:%d: Value should not be zero\n";
if ( !a3 )
{
LABEL_17:
fprintf(stderr, v6, "isort.c", v4);
LABEL_18:
*_errno_location() = 0;
return 1LL;
}
v7 = calloc(1uLL, a3);
if ( !v7 )
{
v4 = 24LL;
LABEL_16:
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
goto LABEL_17;
}
v8 = 0LL;
src = (char *)dest + a3;
while ( 1 )
{
v12 = v8 + 1;
if ( a2 == v8 + 1 )
break;
v9 = src;
while ( v8 )
{
if ( a4(v9, &v9[-a3]) >= 0 )
goto LABEL_14;
--v8;
memcpy(v7, v9, a3);
memcpy(v9, &v9[-a3], a3);
memcpy(&v9[-a3], v7, a3);
v9 -= a3;
}
if ( a4(v9, (char *)dest) < 0 )
{
memcpy(v7, v9, a3);
memcpy(v9, dest, a3);
memcpy(dest, v7, a3);
}
LABEL_14:
src += a3;
v8 = v12;
}
free(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *dest, __int64 a2, size_t a3, int (__fastcall *a4)(char *, char *))
{
__int64 v4; // rcx
const char *v6; // rsi
void *v7; // r13
__int64 v8; // r12
char *v9; // r14
__int64 v12; // [rsp+8h] [rbp-50h]
char *src; // [rsp+10h] [rbp-48h]

v4 = 18LL;
if ( !dest )
goto LABEL_16;
v4 = 19LL;
if ( !a4 )
goto LABEL_16;
if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "isort.c", 20LL);
goto LABEL_18;
}
v4 = 21LL;
v6 = "DEBUG: %s:%d: Value should not be zero\n";
if ( !a3 )
{
LABEL_17:
fprintf(stderr, v6, "isort.c", v4);
LABEL_18:
*_errno_location() = 0;
return 1LL;
}
v7 = calloc(1uLL, a3);
if ( !v7 )
{
v4 = 24LL;
LABEL_16:
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
goto LABEL_17;
}
v8 = 0LL;
src = (char *)dest + a3;
while ( 1 )
{
v12 = v8 + 1;
if ( a2 == v8 + 1 )
break;
v9 = src;
while ( v8 )
{
if ( a4(v9, &v9[-a3]) >= 0 )
goto LABEL_14;
--v8;
memcpy(v7, v9, a3);
memcpy(v9, &v9[-a3], a3);
memcpy(&v9[-a3], v7, a3);
v9 -= a3;
}
if ( a4(v9, (char *)dest) < 0 )
{
memcpy(v7, v9, a3);
memcpy(v9, dest, a3);
memcpy(dest, v7, a3);
}
LABEL_14:
src += a3;
v8 = v12;
}
free(v7);
return 0LL;
}

original_code:
ts_return_t
insert_sort(
    void *array,
    size_t count,
    size_t size,
    int (*compare)(void *a, void *b)) {
 size_t idx, sub;
 void *a, *b;
 void *swap;
 if (!(array)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "isort.c", 18); (*__errno_location ())=0; goto error; };
 if (!(compare)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "isort.c", 19); (*__errno_location ())=0; goto error; };
 if (!(count != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "isort.c", 20); (*__errno_location ())=0; goto error; };
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "isort.c", 21); (*__errno_location ())=0; goto error; };
 swap = calloc(1, size);
 if (!(swap)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "isort.c", 24); (*__errno_location ())=0; goto error; };
 for (idx = 0; idx < count; idx++) {
  for (sub = idx;
      sub > 0 &&
          compare(((sub) == 0 ? (array) : (array) + ((sub) * (size))),
    ((sub - 1) == 0 ? (array) : (array) + ((sub - 1) * (size)))) < 0;
      sub--) {
   a = ((sub) == 0 ? (array) : (array) + ((sub) * (size)));
   b = ((sub - 1) == 0 ? (array) : (array) + ((sub - 1) * (size)));
   do { memcpy(swap, a, size); memcpy(a, b, size); memcpy(b, swap, size); } while (0);
  }
 }
 if (swap)
  free(swap);
 return (TS_RETURN_OK);
error:
 return (TS_RETURN_ERROR);
}

canonical_original_code:
int insert_sort(void *array, unsigned long count, unsigned long size, int (*compare)(void *a, void *b)) {
 unsigned long idx; unsigned long sub;
 void *a; void *b;
 void *swap;
 if (!(array)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "isort.c", 18); (*__errno_location ())=0; goto error; };
 if (!(compare)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "isort.c", 19); (*__errno_location ())=0; goto error; };
 if (!(count != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "isort.c", 20); (*__errno_location ())=0; goto error; };
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "isort.c", 21); (*__errno_location ())=0; goto error; };
 swap = calloc(1, size);
 if (!(swap)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "isort.c", 24); (*__errno_location ())=0; goto error; };
 for (idx = 0; idx < count; idx++) {
  for (sub = idx;
      sub > 0 &&
          compare(((sub) == 0 ? (array) : (array) + ((sub) * (size))),
    ((sub - 1) == 0 ? (array) : (array) + ((sub - 1) * (size)))) < 0;
      sub--) {
   a = ((sub) == 0 ? (array) : (array) + ((sub) * (size)));
   b = ((sub - 1) == 0 ? (array) : (array) + ((sub - 1) * (size)));
   do { memcpy(swap, a, size); memcpy(a, b, size); memcpy(b, swap, size); } while (0);
  }
 }
 if (swap)
  free(swap);
 return (TS_RETURN_OK);
error:
 return (TS_RETURN_ERROR);
}

variable_types:
array
void *

variable_types:
size
unsigned long

variable_types:
compare
int (*)(void *a, void *b)

variable_types:
sub
unsigned long

variable_types:
a
void *

variable_types:
b
void *

variable_types:
swap
void *


decompiled_code:
char **__fastcall get_processor(const char *a1)
{
bool v1; // zf
char **result; // rax

if ( !a1 )
return 0LL;
v1 = strcmp(a1, s_processors) == 0;
result = &s_processors;
if ( !v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
char **__fastcall func0(const char *a1)
{
bool v1; // zf
char **result; // rax

if ( !a1 )
return 0LL;
v1 = strcmp(a1, s_processors) == 0;
result = &s_processors;
if ( !v1 )
result = 0LL;
return result;
}

original_code:
processor_t* get_processor(char* name)
{
    int i, n = sizeof(s_processors)/sizeof(processor_t);
    if (((void *)0) != name)
    {
        for (i = 0; i < n; i++)
        {
            if (strcmp(name, s_processors[i].name) == 0)
                return &s_processors[i];
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct processor_t *get_processor(char *name)
{
    int i; int n = sizeof(s_processors)/sizeof(processor_t);
    if (((void *)0) != name)
    {
        for (i = 0; i < n; i++)
        {
            if (strcmp(name, s_processors[i].name) == 0)
                return &s_processors[i];
        }
    }
    return ((void *)0);
}

variable_types:
name
char *

variable_types: i int

variable_types: n int

return_type: struct processor_t { char *name; int (*delay)(void *opt); int (*split)(void *opt); int (*cat)(void *opt); int (*mix)(void *opt); } *


decompiled_code:
__int64 __fastcall str2time(_BYTE *a1, float *a2)
{
const char *v2; // rbp
__int64 result; // rax
float v4; // xmm0_4
int v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = -1;
v6 = -1;
v7 = -1;
v8 = -1;
if ( !a1 )
{
printf("%s:%d Warning: str failed.\n", "str2time", 42LL);
return 0xFFFFFFFFLL;
}
v2 = &a1[*a1 == 45];
_isoc99_sscanf(v2, "%d%*c%d%*c%d%*c%d", &v5, &v6, &v7, &v8);
result = 0xFFFFFFFFLL;
if ( v5 >= 0 )
{
if ( v6 >= 0 )
{
if ( v7 >= 0 )
{
if ( v8 < 0 )
return result;
result = 0LL;
*a2 = (float)((float)((float)((float)v8 / 1000.0) + (float)v7) + (float)(60 * v6)) + (float)(3600 * v5);
if ( *a1 != 45 )
return result;
LABEL_12:
*a2 = 0.0 - *a2;
return result;
}
if ( v8 >= 0 )
return result;
v4 = atof(v2);
*a2 = v4;
LABEL_11:
result = 0LL;
if ( *a1 != 45 )
return result;
goto LABEL_12;
}
if ( v7 < 0 && v8 < 0 )
{
*a2 = (float)atoi(v2);
goto LABEL_11;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, float *a2)
{
const char *v2; // rbp
__int64 result; // rax
float v4; // xmm0_4
int v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = -1;
v6 = -1;
v7 = -1;
v8 = -1;
if ( !a1 )
{
printf("%s:%d Warning: str failed.\n", "str2time", 42LL);
return 0xFFFFFFFFLL;
}
v2 = &a1[*a1 == 45];
_isoc99_sscanf(v2, "%d%*c%d%*c%d%*c%d", &v5, &v6, &v7, &v8);
result = 0xFFFFFFFFLL;
if ( v5 >= 0 )
{
if ( v6 >= 0 )
{
if ( v7 >= 0 )
{
if ( v8 < 0 )
return result;
result = 0LL;
*a2 = (float)((float)((float)((float)v8 / 1000.0) + (float)v7) + (float)(60 * v6)) + (float)(3600 * v5);
if ( *a1 != 45 )
return result;
LABEL_12:
*a2 = 0.0 - *a2;
return result;
}
if ( v8 >= 0 )
return result;
v4 = atof(v2);
*a2 = v4;
LABEL_11:
result = 0LL;
if ( *a1 != 45 )
return result;
goto LABEL_12;
}
if ( v7 < 0 && v8 < 0 )
{
*a2 = (float)atoi(v2);
goto LABEL_11;
}
}
return result;
}

original_code:
int str2time(const char* str, float* val)
{
    int hh = -1, mm = -1, ss = -1,ff = -1;
    char* pstr = (char*)str;
    if(!(str)) { printf("%s:%d Warning: ""str"" failed.\n", __func__, 42); return (-1.0f); };
    if ('-' == *pstr)
        pstr++;
    sscanf(pstr, "%d%*c%d%*c%d%*c%d", &hh, &mm, &ss, &ff);
    if (hh >= 0 && mm >= 0 && ss >= 0 && ff >= 0)
        *val = (float)ff/1000 + ss + mm*60 + hh*3600;
    else if (hh >= 0 && mm >= 0 && ss < 0 && ff < 0)
        *val = atof(pstr);
    else if (hh >= 0 && mm < 0 && ss < 0 && ff < 0)
        *val = (float)atoi(pstr);
    else
        return -1;
    if ('-' == *str)
        *val = 0 - *val;
    return 0;
}

canonical_original_code:
int str2time(char *str, float *val)
{
    int hh = -1; int mm = -1; int ss = -1; int ff = -1;
    char *pstr = (char*)str;
    if(!(str)) { printf("%s:%d Warning: ""str"" failed.\n", __func__, 42); return (-1.0f); };
    if ('-' == *pstr)
        pstr++;
    sscanf(pstr, "%d%*c%d%*c%d%*c%d", &hh, &mm, &ss, &ff);
    if (hh >= 0 && mm >= 0 && ss >= 0 && ff >= 0)
        *val = (float)ff/1000 + ss + mm*60 + hh*3600;
    else if (hh >= 0 && mm >= 0 && ss < 0 && ff < 0)
        *val = atof(pstr);
    else if (hh >= 0 && mm < 0 && ss < 0 && ff < 0)
        *val = (float)atoi(pstr);
    else
        return -1;
    if ('-' == *str)
        *val = 0 - *val;
    return 0;
}

variable_types:
val
float *

variable_types: hh int

variable_types: mm int

variable_types: ss int

variable_types: ff int

variable_types:
pstr
char *


decompiled_code:
char *__fastcall get_format(const char *a1)
{
return strrchr(a1, 46) + 1;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1)
{
return strrchr(a1, 46) + 1;
}

original_code:
char* get_format(const char* filename)
{
    return (strrchr(filename, '.') + 1);
}

canonical_original_code:
char *get_format(char *filename)
{
    return (strrchr(filename, '.') + 1);
}

variable_types:
filename
char *

return_type: char *


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return printf(
"\n"
"Usage: %s [-t <time>] [-f <format>] [-<action>] file...\n"
"Time:\n"
" -t <time> hh:mm:ss,fff or ss.fff\n"
"Format:\n"
" -f <format> srt, idx, ssa...\n"
"Action:\n"
" -d \t delay\n"
" -s \t split\n"
" -c \t cat\n"
" -m \t mix\n"
"Example:\n"
" %s -t 12.345 -f srt -d input.srt output.srt\n"
"\n",
a1,
a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return printf(
"\n"
"Usage: %s [-t <time>] [-f <format>] [-<action>] file...\n"
"Time:\n"
" -t <time> hh:mm:ss,fff or ss.fff\n"
"Format:\n"
" -f <format> srt, idx, ssa...\n"
"Action:\n"
" -d \t delay\n"
" -s \t split\n"
" -c \t cat\n"
" -m \t mix\n"
"Example:\n"
" %s -t 12.345 -f srt -d input.srt output.srt\n"
"\n",
a1,
a1);
}

original_code:
void usage(char* appname)
{
    printf("\nUsage: %s [-t <time>] [-f <format>] [-<action>] file...\nTime:\n    -t <time>       hh:mm:ss,fff or ss.fff\nFormat:\n    -f <format>     srt, idx, ssa...\nAction:\n    -d 	            delay\n    -s 	            split\n    -c 	            cat\n    -m 	            mix\nExample:\n    %s -t 12.345 -f srt -d input.srt output.srt\n\n", appname, appname);
}

canonical_original_code:
void usage(char *appname)
{
    printf("\nUsage: %s [-t <time>] [-f <format>] [-<action>] file...\nTime:\n    -t <time>       hh:mm:ss,fff or ss.fff\nFormat:\n    -f <format>     srt, idx, ssa...\nAction:\n    -d 	            delay\n    -s 	            split\n    -c 	            cat\n    -m 	            mix\nExample:\n    %s -t 12.345 -f srt -d input.srt output.srt\n\n", appname, appname);
}

variable_types:
appname
char *


repo: twmht/simpleFTP

original_code:
unsigned short in_cksum(unsigned short *addr, int len)
{
    int nleft = len;
    int sum = 0;
    unsigned short *w = addr;
    unsigned short answer = 0;
    while (nleft > 1) {
        sum += *w++;
        nleft -= 2;
    }
    if (nleft == 1) {
        *(unsigned char *) (&answer) = *(unsigned char *) w;
        sum += answer;
    }
    sum = (sum >> 16) + (sum & 0xFFFF);
    sum += (sum >> 16);
    answer = ~sum;
    return (answer);
}

variable_types:
addr
unsigned short *

variable_types: len int

variable_types: nleft int

variable_types: sum int

variable_types:
w
unsigned short *

variable_types:
answer
unsigned short


decompiled_code:
__int64 __fastcall send_packet(__int64 a1, __int16 *a2, const struct sockaddr *a3, __int64 a4, __int16 a5)
{
__int16 v6; // cx
int v7; // er9
unsigned __int16 *v8; // r10
__int16 v9; // ax
int v10; // er9
_WORD *v11; // r10
int v12; // er11

*a2 = _bswap_16(a5);
a2[1] = 0;
a2[2] = _bswap_16(v6);
v9 = in_cksum(v8, v7);
v11[1] = v9;
if ( sendto(v12, v11, v10, 0, a3, 0x10u) >= 0 )
return 0LL;
perror("sendto");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int16 *a2, const struct sockaddr *a3, __int64 a4, __int16 a5)
{
__int16 v6; // cx
int v7; // er9
unsigned __int16 *v8; // r10
__int16 v9; // ax
int v10; // er9
_WORD *v11; // r10
int v12; // er11

*a2 = func7(a5);
a2[1] = 0;
a2[2] = func7(v6);
v9 = func8(v8, v7);
v11[1] = v9;
if ( sendto(v12, v11, v10, 0, a3, 0x10u) >= 0 )
return 0LL;
perror("sendto");
return 0xFFFFFFFFLL;
}

original_code:
int send_packet(int socketfd,struct myFtphdr *packet,struct sockaddr_in *addr,unsigned short block,short opcode,int size){
    packet->mf_opcode=htons(opcode);
    packet->mf_cksum=0;
    packet->mf_u.mf_block = htons(block);
    packet->mf_cksum=in_cksum((unsigned short *)packet,size);
    if((sendto(socketfd, packet,size ,0, (struct sockaddr *)addr, sizeof(struct sockaddr_in)))<0){
        {perror("sendto"); return -1;};
    }
    return 0;
}

canonical_original_code:
int send_packet(int socketfd, struct myFtphdr *packet, struct sockaddr_in *addr, unsigned short block, short opcode, int size){
    packet->mf_opcode=htons(opcode);
    packet->mf_cksum=0;
    packet->mf_u.mf_block = htons(block);
    packet->mf_cksum=in_cksum((unsigned short *)packet,size);
    if((sendto(socketfd, packet,size ,0, (struct sockaddr *)addr, sizeof(struct sockaddr_in)))<0){
        {perror("sendto"); return -1;};
    }
    return 0;
}

variable_types: socketfd int

variable_types: struct myFtphdr { short mf_opcode; unsigned short mf_cksum; union { unsigned short mf_block; char mf_filename[1]; } mf_u; char mf_data[1]; } *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
block
unsigned short

variable_types: opcode short

variable_types: size int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


getIFname

decompiled_code:
__int64 __fastcall getIFname(int a1, char *a2)
{
char *v3; // rbx
unsigned __int64 v4; // rdx
unsigned int v5; // er12
char *v6; // rbp
const char *v7; // rsi
int v9; // [rsp+0h] [rbp-358h] BYREF
char *v10; // [rsp+8h] [rbp-350h]
char src[840]; // [rsp+10h] [rbp-348h] BYREF

v3 = src;
v9 = 800;
v10 = src;
if ( ioctl(a1, 0x8912uLL, &v9) == -1 )
{
perror("socket");
exit(1);
}
v4 = v9 / 0x28uLL;
v5 = v4;
if ( (int)v4 > 0 )
{
v6 = &src[40 * (unsigned int)(v4 - 1) + 40];
do
{
while ( *v3 != 108 || v3[1] != 111 || v3[2] )
{
v7 = v3;
v3 += 40;
strcpy(a2, v7);
if ( v3 == v6 )
goto LABEL_9;
}
v3 += 40;
}
while ( v3 != v6 );
}
LABEL_9:
printf("The number of interface is %d ,Using %s as network interface\n", v5, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char *a2)
{
char *v3; // rbx
unsigned __int64 v4; // rdx
unsigned int v5; // er12
char *v6; // rbp
const char *v7; // rsi
int v9; // [rsp+0h] [rbp-358h] BYREF
char *v10; // [rsp+8h] [rbp-350h]
char src[840]; // [rsp+10h] [rbp-348h] BYREF

v3 = src;
v9 = 800;
v10 = src;
if ( ioctl(a1, 0x8912uLL, &v9) == -1 )
{
perror("socket");
exit(1);
}
v4 = v9 / 0x28uLL;
v5 = v4;
if ( (int)v4 > 0 )
{
v6 = &src[40 * (unsigned int)(v4 - 1) + 40];
do
{
while ( *v3 != 108 || v3[1] != 111 || v3[2] )
{
v7 = v3;
v3 += 40;
strcpy(a2, v7);
if ( v3 == v6 )
goto LABEL_9;
}
v3 += 40;
}
while ( v3 != v6 );
}
LABEL_9:
printf("The number of interface is %d ,Using %s as network interface\n", v5, a2);
return 0LL;
}

original_code:
int getIFname(int socketfd,char *device)
{
    int sock;
    struct ifconf ifconf;
    struct ifreq ifreq[20];
    int interfaces;
    int i;
    ifconf.ifc_ifcu.ifcu_buf = (char *) ifreq;
    ifconf.ifc_len = sizeof(ifreq);
    if (ioctl(socketfd, 0x8912, &ifconf) == -1){
        perror("socket");
        exit(1);
    }
    interfaces = ifconf.ifc_len / sizeof(ifreq[0]);
    int use;
    for (i = 0; i < interfaces; i++) {
        if(strcmp(ifreq[i].ifr_ifrn.ifrn_name,"lo") != 0){
            strcpy(device,ifreq[i].ifr_ifrn.ifrn_name);
        }
    }
    printf("The number of interface is %d ,Using %s as network interface\n",interfaces,device);
    return 0;
}

canonical_original_code:
int getIFname(int socketfd, char *device)
{
    int sock;
    struct ifconf ifconf;
    struct ifreq ifreq[20];
    int interfaces;
    int i;
    ifconf.ifc_ifcu.ifcu_buf = (char *) ifreq;
    ifconf.ifc_len = sizeof(ifreq);
    if (ioctl(socketfd, 0x8912, &ifconf) == -1){
        perror("socket");
        exit(1);
    }
    interfaces = ifconf.ifc_len / sizeof(ifreq[0]);
    int use;
    for (i = 0; i < interfaces; i++) {
        if(strcmp(ifreq[i].ifr_ifrn.ifrn_name,"lo") != 0){
            strcpy(device,ifreq[i].ifr_ifrn.ifrn_name);
        }
    }
    printf("The number of interface is %d ,Using %s as network interface\n",interfaces,device);
    return 0;
}

variable_types:
device
char *

variable_types: sock int

variable_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; } *ifcu_req; } ifc_ifcu; }

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; } [20]

variable_types: interfaces int

variable_types: i int

variable_types: use int

user_defined_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu; }

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


initServAddr

decompiled_code:
__int64 __fastcall initServAddr(int fd, __int16 a2, const void *a3, __int64 a4)
{
socklen_t v6; // edx
char *v7; // rax
struct sockaddr v9; // [rsp+0h] [rbp-68h] BYREF
char dest[16]; // [rsp+10h] [rbp-58h] BYREF
__m128i v11; // [rsp+20h] [rbp-48h] BYREF
__int64 v12; // [rsp+30h] [rbp-38h]

if ( setsockopt(fd, 1, 25, a3, 8u) < 0 )
{
puts("setsockopt() SO_BINDTODEVICE error!");
perror("setsockopt");
exit(1);
}
*(_QWORD *)&v9.sa_data[6] = 0LL;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = _bswap_16(a2);
*(_DWORD *)&v9.sa_data[2] = _bswap_32_constprop_0((unsigned int)fd, &v9);
if ( bind(fd, &v9, v6) < 0 )
{
puts("Bind error!");
exit(1);
}
v12 = 0LL;
*(_OWORD *)dest = 0LL;
v11 = 0LL;
strcpy(dest, (const char *)a3);
if ( ioctl(fd, 0x8915uLL, dest) < 0 )
{
puts("ioctl error!");
exit(1);
}
*(__m128i *)a4 = _mm_loadu_si128(&v11);
v7 = inet_ntoa(*(struct in_addr *)(a4 + 4));
printf("Server IP : %s\n", v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int16 a2, const void *a3, __int64 a4)
{
socklen_t v6; // edx
char *v7; // rax
struct sockaddr v9; // [rsp+0h] [rbp-68h] BYREF
char dest[16]; // [rsp+10h] [rbp-58h] BYREF
__m128i v11; // [rsp+20h] [rbp-48h] BYREF
__int64 v12; // [rsp+30h] [rbp-38h]

if ( setsockopt(fd, 1, 25, a3, 8u) < 0 )
{
puts("setsockopt() SO_BINDTODEVICE error!");
perror("setsockopt");
exit(1);
}
*(_QWORD *)&v9.sa_data[6] = 0LL;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = func0(a2);
*(_DWORD *)&v9.sa_data[2] = func1((unsigned int)fd, &v9);
if ( bind(fd, &v9, v6) < 0 )
{
puts("Bind error!");
exit(1);
}
v12 = 0LL;
*(_OWORD *)dest = 0LL;
v11 = 0LL;
strcpy(dest, (const char *)a3);
if ( ioctl(fd, 0x8915uLL, dest) < 0 )
{
puts("ioctl error!");
exit(1);
}
*(__m128i *)a4 = _mm_loadu_si128(&v11);
v7 = inet_ntoa(*(struct in_addr *)(a4 + 4));
printf("Server IP : %s\n", v7);
return 0LL;
}

original_code:
int initServAddr(int socketfd, int port, const char *device,struct sockaddr_in *addr)
{
    if (setsockopt(socketfd, 1, 25,device, sizeof(device)) < 0) {
        printf("setsockopt() SO_BINDTODEVICE error!\n");
        perror("setsockopt");
        exit(1);
    }
    struct sockaddr_in any;
    bzero(&any,sizeof(any));
    any.sin_family=2;
    any.sin_port= htons(port);
    any.sin_addr.s_addr=htonl(((in_addr_t) 0x00000000));
    if(bind(socketfd, (struct sockaddr *)(&any), sizeof(struct sockaddr_in)) < 0){
        printf("Bind error!\n");
        exit(1);
    }
    struct ifreq interface;
    bzero(&interface,sizeof(struct ifreq));
    strcpy(interface.ifr_ifrn.ifrn_name,device);
    if(ioctl(socketfd,0x8915,&interface)<0){
        printf("ioctl error!\n");
        exit(1);
    }
    memcpy(addr,(struct sockaddr_in*)&interface.ifr_ifru.ifru_addr,sizeof(interface.ifr_ifru.ifru_addr));
    printf("Server IP : %s\n", inet_ntoa(addr->sin_addr));
    return 0;
}

canonical_original_code:
int initServAddr(int socketfd, int port, char *device, struct sockaddr_in *addr)
{
    if (setsockopt(socketfd, 1, 25,device, sizeof(device)) < 0) {
        printf("setsockopt() SO_BINDTODEVICE error!\n");
        perror("setsockopt");
        exit(1);
    }
    struct sockaddr_in any;
    bzero(&any,sizeof(any));
    any.sin_family=2;
    any.sin_port= htons(port);
    any.sin_addr.s_addr=htonl(((unsigned int) 0x00000000));
    if(bind(socketfd, (struct sockaddr *)(&any), sizeof(struct sockaddr_in)) < 0){
        printf("Bind error!\n");
        exit(1);
    }
    struct ifreq interface;
    bzero(&interface,sizeof(struct ifreq));
    strcpy(interface.ifr_ifrn.ifrn_name,device);
    if(ioctl(socketfd,0x8915,&interface)<0){
        printf("ioctl error!\n");
        exit(1);
    }
    memcpy(addr,(struct sockaddr_in *)&interface.ifr_ifru.ifru_addr,sizeof(interface.ifr_ifru.ifru_addr));
    printf("Server IP : %s\n", inet_ntoa(addr->sin_addr));
    return 0;
}

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


listenClient

decompiled_code:
__int64 __fastcall listenClient(int fd, __int64 a2, char *a3, struct sockaddr *a4)
{
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-13Ch] BYREF
struct stat v7; // [rsp+10h] [rbp-138h] BYREF
char buf[144]; // [rsp+A0h] [rbp-A8h] BYREF
int v9; // [rsp+130h] [rbp-18h]

addr_len = 16;
memset(buf, 0, sizeof(buf));
v9 = 0;
if ( recvfrom(fd, buf, 0x94uLL, 0, a4, &addr_len) < 0 )
{
perror("recvfrom error");
exit(1);
}
if ( lstat(&buf[20], &v7) < 0 )
{
printf("receive a request of unknow file : %s\n", &buf[20]);
result = 10LL;
}
else
{
strcpy(a3, &buf[20]);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, __int64 a2, char *a3, struct sockaddr *a4)
{
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-13Ch] BYREF
struct stat v7; // [rsp+10h] [rbp-138h] BYREF
char buf[144]; // [rsp+A0h] [rbp-A8h] BYREF
int v9; // [rsp+130h] [rbp-18h]

addr_len = 16;
memset(buf, 0, sizeof(buf));
v9 = 0;
if ( recvfrom(fd, buf, 0x94uLL, 0, a4, &addr_len) < 0 )
{
perror("recvfrom error");
exit(1);
}
if ( lstat(&buf[20], &v7) < 0 )
{
printf("receive a request of unknow file : %s\n", &buf[20]);
result = 10LL;
}
else
{
strcpy(a3, &buf[20]);
result = 1LL;
}
return result;
}

original_code:
int listenClient(int socketfd, int port, char *filename, struct sockaddr_in *clientaddr)
{
    int len = sizeof(struct sockaddr_in);
    struct bootServerInfo bootInfo;
    bzero(&bootInfo,sizeof(struct bootServerInfo));
    if(recvfrom(socketfd, &bootInfo, sizeof(bootInfo), 0, (struct sockaddr *)clientaddr, &len) < 0){
        perror("recvfrom error");
        exit(1);
    }
    else{
        struct stat buf;
        if(lstat(bootInfo.filename, &buf) < 0)
        {
            printf("receive a request of unknow file : %s\n", bootInfo.filename);
            return 10;
        }
        strcpy(filename,bootInfo.filename);
        return 1;
    }
    return 0;
}

variable_types:
filename
char *

variable_types: len int

variable_types: struct bootServerInfo { char servAddr[15]; int connectPort; char filename[128]; }

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

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


repo: twonly/mfs

decompiled_code:
int csdb_init()
{
memset(&csdbhtab, 0, 0x800uLL);
csdblock = (pthread_mutex_t *)malloc(0x28uLL);
return pthread_mutex_init(csdblock, 0LL);
}

canonical_decompiled_code:
int func0()
{
memset(&csdbhtab, 0, 0x800uLL);
csdblock = (pthread_mutex_t *)malloc(0x28uLL);
return pthread_mutex_init(csdblock, 0LL);
}

original_code:
void csdb_init(void) {
 uint32_t i;
 for (i=0 ; i<256 ; i++) {
  csdbhtab[i]=((void *)0);
 }
 csdblock = malloc(sizeof(pthread_mutex_t));
 pthread_mutex_init(csdblock,((void *)0));
}

canonical_original_code:
void csdb_init() {
 unsigned int i;
 for (i=0 ; i<256 ; i++) {
  csdbhtab[i]=((void *)0);
 }
 csdblock = malloc(sizeof(pthread_mutex_t));
 pthread_mutex_init(csdblock,((void *)0));
}

variable_types:
i
unsigned int


decompiled_code:
void csdb_term()
{
pthread_mutex_t *v0; // rbp
pthread_mutex_t *v1; // rdi
__int64 *v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

v0 = csdblock;
pthread_mutex_destroy(csdblock);
v1 = v0;
v2 = &csdbhtab;
free(v1);
do
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
}
++v2;
}
while ( v2 != (__int64 *)&unk_C40 );
}

canonical_decompiled_code:
void func1()
{
pthread_mutex_t *v0; // rbp
pthread_mutex_t *v1; // rdi
__int64 *v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

v0 = csdblock;
pthread_mutex_destroy(csdblock);
v1 = v0;
v2 = &csdbhtab;
free(v1);
do
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
}
++v2;
}
while ( v2 != (__int64 *)&unk_C40 );
}

original_code:
void csdb_term(void) {
 uint32_t i;
 csdbentry *cs,*csn;
 pthread_mutex_destroy(csdblock);
 free(csdblock);
 for (i=0 ; i<256 ; i++) {
  for (cs = csdbhtab[i] ; cs ; cs = csn) {
   csn = cs->next;
   free(cs);
  }
 }
}

canonical_original_code:
void csdb_term() {
 unsigned int i;
 struct _csdbentry *cs; struct _csdbentry *csn;
 pthread_mutex_destroy(csdblock);
 free(csdblock);
 for (i=0 ; i<256 ; i++) {
  for (cs = csdbhtab[i] ; cs ; cs = csn) {
   csn = cs->next;
   free(cs);
  }
 }
}

variable_types: struct _csdbentry { unsigned int ip; unsigned short port; unsigned int readopcnt; unsigned int writeopcnt; struct _csdbentry *next; } *


decompiled_code:
__int64 __fastcall csdb_getreadcnt(int a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_7;
}
v3 = *(_DWORD *)(v2 + 8);
}
else
{
LABEL_7:
v3 = 0;
}
pthread_mutex_unlock(csdblock);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_7;
}
v3 = *(_DWORD *)(v2 + 8);
}
else
{
LABEL_7:
v3 = 0;
}
pthread_mutex_unlock(csdblock);
return v3;
}

original_code:
uint32_t csdb_getreadcnt(uint32_t ip,uint16_t port) {
 uint32_t hash = (((ip)*0x7b348943+(port))%(256));
 uint32_t result = 0;
 csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   result = e->readopcnt;
   break;
  }
 }
 pthread_mutex_unlock(csdblock);
 return result;
}

canonical_original_code:
unsigned int csdb_getreadcnt(unsigned int ip, unsigned short port) {
 unsigned int hash = (((ip)*0x7b348943+(port))%(256));
 unsigned int result = 0;
 struct _csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   result = e->readopcnt;
   break;
  }
 }
 pthread_mutex_unlock(csdblock);
 return result;
}

variable_types:
ip
unsigned int

variable_types:
port
unsigned short

variable_types:
hash
unsigned int

variable_types:
result
unsigned int

return_type: unsigned int

user_defined_types: struct _csdbentry { unsigned int ip; unsigned short port; unsigned int readopcnt; unsigned int writeopcnt; struct _csdbentry *next; }


decompiled_code:
__int64 __fastcall csdb_getwritecnt(int a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_7;
}
v3 = *(_DWORD *)(v2 + 12);
}
else
{
LABEL_7:
v3 = 0;
}
pthread_mutex_unlock(csdblock);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_7;
}
v3 = *(_DWORD *)(v2 + 12);
}
else
{
LABEL_7:
v3 = 0;
}
pthread_mutex_unlock(csdblock);
return v3;
}

original_code:
uint32_t csdb_getwritecnt(uint32_t ip,uint16_t port) {
 uint32_t hash = (((ip)*0x7b348943+(port))%(256));
 uint32_t result = 0;
 csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   result = e->writeopcnt;
   break;
  }
 }
 pthread_mutex_unlock(csdblock);
 return result;
}

canonical_original_code:
unsigned int csdb_getwritecnt(unsigned int ip, unsigned short port) {
 unsigned int hash = (((ip)*0x7b348943+(port))%(256));
 unsigned int result = 0;
 struct _csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   result = e->writeopcnt;
   break;
  }
 }
 pthread_mutex_unlock(csdblock);
 return result;
}


decompiled_code:
__int64 __fastcall csdb_getopcnt(int a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_7;
}
v3 = *(_DWORD *)(v2 + 8) + *(_DWORD *)(v2 + 12);
}
else
{
LABEL_7:
v3 = 0;
}
pthread_mutex_unlock(csdblock);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_7;
}
v3 = *(_DWORD *)(v2 + 8) + *(_DWORD *)(v2 + 12);
}
else
{
LABEL_7:
v3 = 0;
}
pthread_mutex_unlock(csdblock);
return v3;
}

original_code:
uint32_t csdb_getopcnt(uint32_t ip,uint16_t port) {
 uint32_t hash = (((ip)*0x7b348943+(port))%(256));
 uint32_t result = 0;
 csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   result = e->readopcnt + e->writeopcnt;
   break;
  }
 }
 pthread_mutex_unlock(csdblock);
 return result;
}

canonical_original_code:
unsigned int csdb_getopcnt(unsigned int ip, unsigned short port) {
 unsigned int hash = (((ip)*0x7b348943+(port))%(256));
 unsigned int result = 0;
 struct _csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   result = e->readopcnt + e->writeopcnt;
   break;
  }
 }
 pthread_mutex_unlock(csdblock);
 return result;
}


decompiled_code:
int __fastcall csdb_readinc(int a1, __int16 a2)
{
__int64 v2; // rbp
__int64 v3; // r14
__int64 v4; // rax
_WORD *v5; // rax

pthread_mutex_lock(csdblock);
v2 = (unsigned __int8)(a2 + 67 * a1);
v3 = csdbhtab[(unsigned __int8)v2];
if ( v3 )
{
v4 = csdbhtab[(unsigned __int8)v2];
while ( *(_DWORD *)v4 != a1 || *(_WORD *)(v4 + 4) != a2 )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_7;
}
++*(_DWORD *)(v4 + 8);
}
else
{
LABEL_7:
v5 = malloc(0x18uLL);
*(_DWORD *)v5 = a1;
v5[2] = a2;
*((_QWORD *)v5 + 1) = 1LL;
*((_QWORD *)v5 + 2) = v3;
csdbhtab[v2] = (__int64)v5;
}
return pthread_mutex_unlock(csdblock);
}

canonical_decompiled_code:
int __fastcall func5(int a1, __int16 a2)
{
__int64 v2; // rbp
__int64 v3; // r14
__int64 v4; // rax
_WORD *v5; // rax

pthread_mutex_lock(csdblock);
v2 = (unsigned __int8)(a2 + 67 * a1);
v3 = csdbhtab[(unsigned __int8)v2];
if ( v3 )
{
v4 = csdbhtab[(unsigned __int8)v2];
while ( *(_DWORD *)v4 != a1 || *(_WORD *)(v4 + 4) != a2 )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_7;
}
++*(_DWORD *)(v4 + 8);
}
else
{
LABEL_7:
v5 = malloc(0x18uLL);
*(_DWORD *)v5 = a1;
v5[2] = a2;
*((_QWORD *)v5 + 1) = 1LL;
*((_QWORD *)v5 + 2) = v3;
csdbhtab[v2] = (__int64)v5;
}
return pthread_mutex_unlock(csdblock);
}

original_code:
void csdb_readinc(uint32_t ip,uint16_t port) {
 uint32_t hash = (((ip)*0x7b348943+(port))%(256));
 csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->readopcnt++;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 e = malloc(sizeof(csdbentry));
 e->ip = ip;
 e->port = port;
 e->readopcnt = 1;
 e->writeopcnt = 0;
 e->next = csdbhtab[hash];
 csdbhtab[hash] = e;
 pthread_mutex_unlock(csdblock);
}

canonical_original_code:
void csdb_readinc(unsigned int ip, unsigned short port) {
 unsigned int hash = (((ip)*0x7b348943+(port))%(256));
 struct _csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->readopcnt++;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 e = malloc(sizeof(csdbentry));
 e->ip = ip;
 e->port = port;
 e->readopcnt = 1;
 e->writeopcnt = 0;
 e->next = csdbhtab[hash];
 csdbhtab[hash] = e;
 pthread_mutex_unlock(csdblock);
}


decompiled_code:
int __fastcall csdb_readdec(int a1, __int16 a2)
{
__int64 v2; // rax

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return pthread_mutex_unlock(csdblock);
}
--*(_DWORD *)(v2 + 8);
}
return pthread_mutex_unlock(csdblock);
}

canonical_decompiled_code:
int __fastcall func6(int a1, __int16 a2)
{
__int64 v2; // rax

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return pthread_mutex_unlock(csdblock);
}
--*(_DWORD *)(v2 + 8);
}
return pthread_mutex_unlock(csdblock);
}

original_code:
void csdb_readdec(uint32_t ip,uint16_t port) {
 uint32_t hash = (((ip)*0x7b348943+(port))%(256));
 csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->readopcnt--;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 pthread_mutex_unlock(csdblock);
}

canonical_original_code:
void csdb_readdec(unsigned int ip, unsigned short port) {
 unsigned int hash = (((ip)*0x7b348943+(port))%(256));
 struct _csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->readopcnt--;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 pthread_mutex_unlock(csdblock);
}


decompiled_code:
int __fastcall csdb_writeinc(int a1, __int16 a2)
{
__int64 v2; // rbp
__int64 v3; // r14
__int64 v4; // rax
_WORD *v5; // rax

pthread_mutex_lock(csdblock);
v2 = (unsigned __int8)(a2 + 67 * a1);
v3 = csdbhtab[(unsigned __int8)v2];
if ( v3 )
{
v4 = csdbhtab[(unsigned __int8)v2];
while ( *(_DWORD *)v4 != a1 || *(_WORD *)(v4 + 4) != a2 )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_7;
}
++*(_DWORD *)(v4 + 12);
}
else
{
LABEL_7:
v5 = malloc(0x18uLL);
*(_DWORD *)v5 = a1;
v5[2] = a2;
*((_QWORD *)v5 + 1) = 0x100000000LL;
*((_QWORD *)v5 + 2) = v3;
csdbhtab[v2] = (__int64)v5;
}
return pthread_mutex_unlock(csdblock);
}

canonical_decompiled_code:
int __fastcall func7(int a1, __int16 a2)
{
__int64 v2; // rbp
__int64 v3; // r14
__int64 v4; // rax
_WORD *v5; // rax

pthread_mutex_lock(csdblock);
v2 = (unsigned __int8)(a2 + 67 * a1);
v3 = csdbhtab[(unsigned __int8)v2];
if ( v3 )
{
v4 = csdbhtab[(unsigned __int8)v2];
while ( *(_DWORD *)v4 != a1 || *(_WORD *)(v4 + 4) != a2 )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_7;
}
++*(_DWORD *)(v4 + 12);
}
else
{
LABEL_7:
v5 = malloc(0x18uLL);
*(_DWORD *)v5 = a1;
v5[2] = a2;
*((_QWORD *)v5 + 1) = 0x100000000LL;
*((_QWORD *)v5 + 2) = v3;
csdbhtab[v2] = (__int64)v5;
}
return pthread_mutex_unlock(csdblock);
}

original_code:
void csdb_writeinc(uint32_t ip,uint16_t port) {
 uint32_t hash = (((ip)*0x7b348943+(port))%(256));
 csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->writeopcnt++;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 e = malloc(sizeof(csdbentry));
 e->ip = ip;
 e->port = port;
 e->readopcnt = 0;
 e->writeopcnt = 1;
 e->next = csdbhtab[hash];
 csdbhtab[hash] = e;
 pthread_mutex_unlock(csdblock);
}

canonical_original_code:
void csdb_writeinc(unsigned int ip, unsigned short port) {
 unsigned int hash = (((ip)*0x7b348943+(port))%(256));
 struct _csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->writeopcnt++;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 e = malloc(sizeof(csdbentry));
 e->ip = ip;
 e->port = port;
 e->readopcnt = 0;
 e->writeopcnt = 1;
 e->next = csdbhtab[hash];
 csdbhtab[hash] = e;
 pthread_mutex_unlock(csdblock);
}


decompiled_code:
int __fastcall csdb_writedec(int a1, __int16 a2)
{
__int64 v2; // rax

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return pthread_mutex_unlock(csdblock);
}
--*(_DWORD *)(v2 + 12);
}
return pthread_mutex_unlock(csdblock);
}

canonical_decompiled_code:
int __fastcall func8(int a1, __int16 a2)
{
__int64 v2; // rax

pthread_mutex_lock(csdblock);
v2 = csdbhtab[(unsigned __int8)(67 * a1 + a2)];
if ( v2 )
{
while ( *(_DWORD *)v2 != a1 || *(_WORD *)(v2 + 4) != a2 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return pthread_mutex_unlock(csdblock);
}
--*(_DWORD *)(v2 + 12);
}
return pthread_mutex_unlock(csdblock);
}

original_code:
void csdb_writedec(uint32_t ip,uint16_t port) {
 uint32_t hash = (((ip)*0x7b348943+(port))%(256));
 csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->writeopcnt--;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 pthread_mutex_unlock(csdblock);
}

canonical_original_code:
void csdb_writedec(unsigned int ip, unsigned short port) {
 unsigned int hash = (((ip)*0x7b348943+(port))%(256));
 struct _csdbentry *e;
 pthread_mutex_lock(csdblock);
 for (e=csdbhtab[hash] ; e ; e=e->next) {
  if (e->ip == ip && e->port == port) {
   e->writeopcnt--;
   pthread_mutex_unlock(csdblock);
   return;
  }
 }
 pthread_mutex_unlock(csdblock);
}


decompiled_code:
void topology_term()
{
itree_freeall(racktree);
if ( TopologyFileName )
free(TopologyFileName);
}

canonical_decompiled_code:
void func0()
{
itree_freeall(racktree);
if ( TopologyFileName )
free(TopologyFileName);
}

original_code:
void topology_term(void) {
 itree_freeall(racktree);
 if (TopologyFileName) {
  free(TopologyFileName);
 }
}

canonical_original_code:
void topology_term() {
 itree_freeall(racktree);
 if (TopologyFileName) {
  free(TopologyFileName);
 }
}


original_code:
int topology_parsenet(char *net,uint32_t *fromip,uint32_t *toip) {
 uint32_t ip,i,octet;
 if (net[0]=='*' && net[1]==0) {
  *fromip = 0;
  *toip = 0xFFFFFFFFU;
  return 0;
 }
 ip=0;
 for (i=0 ; i<4; i++) {
  if (*net>='0' && *net<='9') {
   octet=0;
   while (*net>='0' && *net<='9') {
    octet*=10;
    octet+=(*net)-'0';
    net++;
    if (octet>255) {
     return -1;
    }
   }
  } else {
   return -1;
  }
  if (i<3) {
   if (*net!='.') {
    return -1;
   }
   net++;
  }
  ip*=256;
  ip+=octet;
 }
 if (*net==0) {
  *fromip = ip;
  *toip = ip;
  return 0;
 }
 if (*net=='/') {
  *fromip = ip;
  ip=0;
  net++;
  for (i=0 ; i<4; i++) {
   if (*net>='0' && *net<='9') {
    octet=0;
    while (*net>='0' && *net<='9') {
     octet*=10;
     octet+=(*net)-'0';
     net++;
     if (octet>255) {
      return -1;
     }
    }
   } else {
    return -1;
   }
   if (i==0 && *net==0 && octet<=32) {
    ip = 0xFFFFFFFF;
    if (octet<32) {
     ip<<=32-octet;
    }
    break;
   }
   if (i<3) {
    if (*net!='.') {
     return -1;
    }
    net++;
   }
   ip*=256;
   ip+=octet;
  }
  if (*net!=0) {
   return -1;
  }
  *fromip &= ip;
  *toip = *fromip | (ip ^ 0xFFFFFFFFU);
  return 0;
 }
 if (*net=='-') {
  *fromip = ip;
  ip=0;
  net++;
  for (i=0 ; i<4; i++) {
   if (*net>='0' && *net<='9') {
    octet=0;
    while (*net>='0' && *net<='9') {
     octet*=10;
     octet+=*net-'0';
     net++;
     if (octet>255) {
      return -1;
     }
    }
   } else {
    return -1;
   }
   if (i<3) {
    if (*net!='.') {
     return -1;
    }
    net++;
   }
   ip*=256;
   ip+=octet;
  }
  if (*net!=0) {
   return -1;
  }
  *toip = ip;
  return 0;
 }
 return -1;
}

canonical_original_code:
int topology_parsenet(char *net, unsigned int *fromip, unsigned int *toip) {
 unsigned int ip; unsigned int i; unsigned int octet;
 if (net[0]=='*' && net[1]==0) {
  *fromip = 0;
  *toip = 0xFFFFFFFFU;
  return 0;
 }
 ip=0;
 for (i=0 ; i<4; i++) {
  if (*net>='0' && *net<='9') {
   octet=0;
   while (*net>='0' && *net<='9') {
    octet*=10;
    octet+=(*net)-'0';
    net++;
    if (octet>255) {
     return -1;
    }
   }
  } else {
   return -1;
  }
  if (i<3) {
   if (*net!='.') {
    return -1;
   }
   net++;
  }
  ip*=256;
  ip+=octet;
 }
 if (*net==0) {
  *fromip = ip;
  *toip = ip;
  return 0;
 }
 if (*net=='/') {
  *fromip = ip;
  ip=0;
  net++;
  for (i=0 ; i<4; i++) {
   if (*net>='0' && *net<='9') {
    octet=0;
    while (*net>='0' && *net<='9') {
     octet*=10;
     octet+=(*net)-'0';
     net++;
     if (octet>255) {
      return -1;
     }
    }
   } else {
    return -1;
   }
   if (i==0 && *net==0 && octet<=32) {
    ip = 0xFFFFFFFF;
    if (octet<32) {
     ip<<=32-octet;
    }
    break;
   }
   if (i<3) {
    if (*net!='.') {
     return -1;
    }
    net++;
   }
   ip*=256;
   ip+=octet;
  }
  if (*net!=0) {
   return -1;
  }
  *fromip &= ip;
  *toip = *fromip | (ip ^ 0xFFFFFFFFU);
  return 0;
 }
 if (*net=='-') {
  *fromip = ip;
  ip=0;
  net++;
  for (i=0 ; i<4; i++) {
   if (*net>='0' && *net<='9') {
    octet=0;
    while (*net>='0' && *net<='9') {
     octet*=10;
     octet+=*net-'0';
     net++;
     if (octet>255) {
      return -1;
     }
    }
   } else {
    return -1;
   }
   if (i<3) {
    if (*net!='.') {
     return -1;
    }
    net++;
   }
   ip*=256;
   ip+=octet;
  }
  if (*net!=0) {
   return -1;
  }
  *toip = ip;
  return 0;
 }
 return -1;
}

variable_types:
net
char *

variable_types:
fromip
unsigned int *

variable_types:
toip
unsigned int *

variable_types:
octet
unsigned int


decompiled_code:
__int64 __fastcall topology_distance(unsigned int a1, unsigned int a2)
{
int v2; // ebx
int v3; // eax

if ( a1 == a2 )
return 0LL;
v2 = itree_find(racktree, a1);
v3 = itree_find(racktree, a2);
LOBYTE(v3) = v2 != v3;
return (unsigned int)(v3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
int v2; // ebx
int v3; // eax

if ( a1 == a2 )
return 0LL;
v2 = itree_find(racktree, a1);
v3 = itree_find(racktree, a2);
LOBYTE(v3) = v2 != v3;
return (unsigned int)(v3 + 1);
}

original_code:
uint8_t topology_distance(uint32_t ip1,uint32_t ip2) {
 uint32_t rid1,rid2;
 if (ip1==ip2) {
  return 0;
 }
 rid1 = itree_find(racktree,ip1);
 rid2 = itree_find(racktree,ip2);
 return (rid1==rid2)?1:2;
}

canonical_original_code:
unsigned char topology_distance(unsigned int ip1, unsigned int ip2) {
 unsigned int rid1; unsigned int rid2;
 if (ip1==ip2) {
  return 0;
 }
 rid1 = itree_find(racktree,ip1);
 rid2 = itree_find(racktree,ip2);
 return (rid1==rid2)?1:2;
}

return_type: unsigned char