decompiled_code:
__int64 *cache_clean()
{
__int64 *result; // rax
__int64 i; // rdi

result = (__int64 *)**((_QWORD **)main + 5);
for ( i = *result; *result; i = *result )
{
cache_del(i);
result = (__int64 *)**((_QWORD **)main + 5);
}
return result;
}

canonical_decompiled_code:
__int64 *func5()
{
__int64 *result; // rax
__int64 i; // rdi

result = (__int64 *)**((_QWORD **)main + 5);
for ( i = *result; *result; i = *result )
{
func4(i);
result = (__int64 *)**((_QWORD **)main + 5);
}
return result;
}

original_code:
void cache_clean(void)
{
 while (_main->cache->list->item != ((void *)0)) {
  cache_del(_main->cache->list->item);
 }
}

canonical_original_code:
void cache_clean()
{
 while (_main->cache->list->item != ((void *)0)) {
  cache_del(_main->cache->list->item);
 }
}


repo: torrentkino/torrentkino

decompiled_code:
__int64 cache_free()
{
cache_clean();
list_clear(**((_QWORD **)main + 5));
list_free(**((_QWORD **)main + 5));
hash_free(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL));
return myfree(*((_QWORD *)main + 5));
}

canonical_decompiled_code:
__int64 func6()
{
func5();
list_clear(**((_QWORD **)main + 5));
list_free(**((_QWORD **)main + 5));
hash_free(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL));
return myfree(*((_QWORD *)main + 5));
}

original_code:
void cache_free(void)
{
 cache_clean();
 list_clear(_main->cache->list);
 list_free(_main->cache->list);
 hash_free(_main->cache->hash);
 myfree(_main->cache);
}

canonical_original_code:
void cache_free()
{
 cache_clean();
 list_clear(_main->cache->list);
 list_free(_main->cache->list);
 hash_free(_main->cache->hash);
 myfree(_main->cache);
}

return_type: void


decompiled_code:
__int64 __fastcall tgt_c_print(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
_BYTE v4[24]; // [rsp+0h] [rbp-18h] BYREF

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v2 = result;
do
{
v3 = list_value(v2);
ip_tuple_to_sin(v4, v3);
info(log, v4, " IP:");
result = list_next(v2);
v2 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
_BYTE v4[24]; // [rsp+0h] [rbp-18h] BYREF

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v2 = result;
do
{
v3 = list_value(v2);
ip_tuple_to_sin(v4, v3);
info(log, v4, " IP:");
result = list_next(v2);
v2 = result;
}
while ( result );
}
return result;
}

original_code:
void tgt_c_print(TARGET_C * target)
{
 ITEM *i = ((void *)0);
 NODE_C *node = ((void *)0);
 IP sin;
 i = list_start(target->list);
 while (i != ((void *)0)) {
  node = list_value(i);
  ip_tuple_to_sin(&sin, node->pair);
  info(_log, &sin, "  IP:");
  i = list_next(i);
 }
}

canonical_original_code:
void tgt_c_print(struct TARGET_C *target)
{
 struct obj_item *i = ((void *)0);
 struct NODE_C *node = ((void *)0);
 struct sockaddr_in sin;
 i = list_start(target->list);
 while (i != ((void *)0)) {
  node = list_value(i);
  ip_tuple_to_sin(&sin, node->pair);
  info(_log, &sin, "  IP:");
  i = list_next(i);
 }
}

variable_types: struct TARGET_C { unsigned char target[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; long lifetime; long refresh; } *

variable_types: struct NODE_C { unsigned char pair[6]; long eol; } *

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

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 TARGET_C { unsigned char target[20]; struct obj_list *list; struct HASH *hash; long lifetime; long refresh; }

user_defined_types: struct obj_list { struct obj_item *item; long size; }

user_defined_types: struct HASH { struct BUCKET *buckets; long size; }

user_defined_types: struct BUCKET { struct PAIR *pairs; long size; }


decompiled_code:
__int64 cache_print()
{
__int64 result; // rax
__int64 i; // rbp
__int64 v2; // r12
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = log_verbosely(log);
if ( !(_DWORD)result )
{
info(log, 0LL, "Cache renewal triggered:");
result = list_start(**((_QWORD **)main + 5));
for ( i = result; result; i = result )
{
v2 = list_value(i);
hex_hash_encode(v3, v2);
info(log, 0LL, " Target: %s", v3);
tgt_c_print(v2);
result = list_next(i);
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
__int64 i; // rbp
__int64 v2; // r12
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = log_verbosely(log);
if ( !(_DWORD)result )
{
info(log, 0LL, "Cache renewal triggered:");
result = list_start(**((_QWORD **)main + 5));
for ( i = result; result; i = result )
{
v2 = list_value(i);
hex_hash_encode(v3, v2);
info(log, 0LL, " Target: %s", v3);
func7(v2);
result = list_next(i);
}
}
return result;
}

original_code:
void cache_print(void)
{
 ITEM *i = ((void *)0);
 TARGET_C *t = ((void *)0);
 char hex[2*20 +1];
 if (log_verbosely(_log)) {
  return;
 }
 info(_log, ((void *)0), "Cache renewal triggered:");
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  hex_hash_encode(hex, t->target);
  info(_log, ((void *)0), " Target: %s", hex);
  tgt_c_print(t);
  i = list_next(i);
 }
}

canonical_original_code:
void cache_print()
{
 struct obj_item *i = ((void *)0);
 struct TARGET_C *t = ((void *)0);
 char hex[-1];
 if (log_verbosely(_log)) {
  return;
 }
 info(_log, ((void *)0), "Cache renewal triggered:");
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  hex_hash_encode(hex, t->target);
  info(_log, ((void *)0), " Target: %s", hex);
  tgt_c_print(t);
  i = list_next(i);
 }
}

variable_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *

variable_types:
hex
char [-1]

user_defined_types: struct PAIR { unsigned char *key; long size; void *value; }


decompiled_code:
__int64 __fastcall cache_renew(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
int v3; // er13
__int64 v4; // rax
__int64 v5; // rbx

result = list_start(**((_QWORD **)main + 5));
if ( result )
{
v2 = result;
v3 = 0;
do
{
while ( 1 )
{
v4 = list_value(v2);
v5 = v4;
if ( *(_QWORD *)(v4 + 48) < a1 )
break;
result = list_next(v2);
v2 = result;
if ( !result )
goto LABEL_6;
}
v3 = 1;
p2p_cron_lookup(v4, 4LL);
time_add_5_min_approx(v5 + 48);
result = list_next(v2);
v2 = result;
}
while ( result );
LABEL_6:
if ( v3 )
result = cache_print();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
int v3; // er13
__int64 v4; // rax
__int64 v5; // rbx

result = list_start(**((_QWORD **)main + 5));
if ( result )
{
v2 = result;
v3 = 0;
do
{
while ( 1 )
{
v4 = list_value(v2);
v5 = v4;
if ( *(_QWORD *)(v4 + 48) < a1 )
break;
result = list_next(v2);
v2 = result;
if ( !result )
goto LABEL_6;
}
v3 = 1;
p2p_cron_lookup(v4, 4LL);
time_add_5_min_approx(v5 + 48);
result = list_next(v2);
v2 = result;
}
while ( result );
LABEL_6:
if ( v3 )
result = func8();
}
return result;
}

original_code:
void cache_renew(time_t now)
{
 ITEM *i = ((void *)0);
 TARGET_C *t = ((void *)0);
 int changes = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  if (now > t->refresh) {
   p2p_cron_lookup(t->target, 4);
   time_add_5_min_approx(&t->refresh);
   changes = 1;
  }
  i = list_next(i);
 }
 if (changes) {
  cache_print();
 }
}

canonical_original_code:
void cache_renew(long now)
{
 struct obj_item *i = ((void *)0);
 struct TARGET_C *t = ((void *)0);
 int changes = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  if (now > t->refresh) {
   p2p_cron_lookup(t->target, 4);
   time_add_5_min_approx(&t->refresh);
   changes = 1;
  }
  i = list_next(i);
 }
 if (changes) {
  cache_print();
 }
}

variable_types: now long

variable_types: changes int

user_defined_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; }


decompiled_code:
__int64 __fastcall tgt_c_find(__int64 a1, __int64 a2)
{
return hash_get(*(_QWORD *)(a1 + 32), a2, 6LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
return hash_get(*(_QWORD *)(a1 + 32), a2, 6LL);
}

original_code:
ITEM *tgt_c_find(TARGET_C * target, UCHAR * pair)
{
 return hash_get(target->hash, pair, 6);
}

canonical_original_code:
struct obj_item *tgt_c_find(struct TARGET_C *target, unsigned char *pair)
{
 return hash_get(target->hash, pair, 6);
}

variable_types: struct TARGET_C { unsigned char target[20]; struct obj_list { struct obj_item *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; long lifetime; long refresh; } *

variable_types:
pair
unsigned char *

return_type: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *


decompiled_code:
// attributes: thunk
__int64 __fastcall node_c_free(__int64 a1)
{
return myfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return myfree(a1);
}

original_code:
void node_c_free(NODE_C * node_c)
{
 myfree(node_c);
}

canonical_original_code:
void node_c_free(struct NODE_C *node_c)
{
 myfree(node_c);
}

user_defined_types: struct NODE_C { unsigned char pair[6]; long eol; }


decompiled_code:
__int64 __fastcall tgt_c_del(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = list_value(a2);
hash_del(*(_QWORD *)(a1 + 32), v2, 6LL);
list_del(*(_QWORD *)(a1 + 24), a2);
return node_c_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = list_value(a2);
hash_del(*(_QWORD *)(a1 + 32), v2, 6LL);
list_del(*(_QWORD *)(a1 + 24), a2);
return func11(v2);
}

original_code:
void tgt_c_del(TARGET_C * target, ITEM * i)
{
 NODE_C *node_c = list_value(i);
 hash_del(target->hash, node_c->pair, 6);
 list_del(target->list, i);
 node_c_free(node_c);
}

canonical_original_code:
void tgt_c_del(struct TARGET_C *target, struct obj_item *i)
{
 struct NODE_C *node_c = list_value(i);
 hash_del(target->hash, node_c->pair, 6);
 list_del(target->list, i);
 node_c_free(node_c);
}

variable_types:
i
struct obj_item *


decompiled_code:
__int64 __fastcall tgt_c_expire(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdi

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v4 = result;
do
{
while ( 1 )
{
v5 = v4;
v6 = v4;
v4 = list_next(v4);
result = list_value(v6);
if ( *(_QWORD *)(result + 8) < a2 )
break;
if ( !v4 )
return result;
}
result = tgt_c_del(a1, v5);
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdi

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v4 = result;
do
{
while ( 1 )
{
v5 = v4;
v6 = v4;
v4 = list_next(v4);
result = list_value(v6);
if ( *(_QWORD *)(result + 8) < a2 )
break;
if ( !v4 )
return result;
}
result = func12(a1, v5);
}
while ( v4 );
}
return result;
}

original_code:
void tgt_c_expire(TARGET_C * target, time_t now)
{
 ITEM *i = ((void *)0);
 ITEM *n = ((void *)0);
 NODE_C *node = ((void *)0);
 i = list_start(target->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  node = list_value(i);
  if (now > node->eol) {
   tgt_c_del(target, i);
  }
  i = n;
 }
}

canonical_original_code:
void tgt_c_expire(struct TARGET_C *target, long now)
{
 struct obj_item *i = ((void *)0);
 struct obj_item *n = ((void *)0);
 struct NODE_C *node = ((void *)0);
 i = list_start(target->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  node = list_value(i);
  if (now > node->eol) {
   tgt_c_del(target, i);
  }
  i = n;
 }
}


decompiled_code:
__int64 __fastcall cache_expire(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rbp

result = list_start(**((_QWORD **)main + 5));
if ( result )
{
v3 = result;
do
{
while ( 1 )
{
v4 = v3;
v5 = v3;
v3 = list_next(v3);
v6 = list_value(v5);
result = tgt_c_expire(v6, a1);
if ( *(_QWORD *)(v6 + 40) < a1 )
break;
if ( !v3 )
return result;
}
result = cache_del(v4);
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rbp

result = list_start(**((_QWORD **)main + 5));
if ( result )
{
v3 = result;
do
{
while ( 1 )
{
v4 = v3;
v5 = v3;
v3 = list_next(v3);
v6 = list_value(v5);
result = func13(v6, a1);
if ( *(_QWORD *)(v6 + 40) < a1 )
break;
if ( !v3 )
return result;
}
result = func4(v4);
}
while ( v3 );
}
return result;
}

original_code:
void cache_expire(time_t now)
{
 ITEM *i = ((void *)0), *n = ((void *)0);
 TARGET_C *target = ((void *)0);
 int index = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  target = list_value(i);
  tgt_c_expire(target, now);
  if (now > target->lifetime) {
   cache_del(i);
  }
  i = n;
  index++;
 }
}

canonical_original_code:
void cache_expire(long now)
{
 struct obj_item *i = ((void *)0); struct obj_item *n = ((void *)0);
 struct TARGET_C *target = ((void *)0);
 int index = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  target = list_value(i);
  tgt_c_expire(target, now);
  if (now > target->lifetime) {
   cache_del(i);
  }
  i = n;
  index++;
 }
}

variable_types: index int


original_code:
void node_c_update(NODE_C * node_c, UCHAR * pair)
{
 memcpy(node_c->pair, pair, 6);
 time_add_30_min(&node_c->eol);
}

canonical_original_code:
void node_c_update(struct NODE_C *node_c, unsigned char *pair)
{
 memcpy(node_c->pair, pair, 6);
 time_add_30_min(&node_c->eol);
}


decompiled_code:
__int64 __fastcall node_c_init(__int64 a1)
{
__int64 v1; // r12

v1 = myalloc(16LL);
node_c_update(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 v1; // r12

v1 = myalloc(16LL);
func15(v1, a1);
return v1;
}

original_code:
NODE_C *node_c_init(UCHAR * pair)
{
 NODE_C *node_c = (NODE_C *) myalloc(sizeof(NODE_C));
 node_c_update(node_c, pair);
 return node_c;
}

canonical_original_code:
struct NODE_C *node_c_init(unsigned char *pair)
{
 struct NODE_C *node_c = (NODE_C *) myalloc(sizeof(NODE_C));
 node_c_update(node_c, pair);
 return node_c;
}

return_type: struct NODE_C { unsigned char pair[6]; long eol; } *


decompiled_code:
__int64 __fastcall tgt_c_put(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax
__int64 v6; // rax

v2 = node_c_init(a2);
v3 = list_start(*(_QWORD *)(a1 + 24));
v4 = list_ins(*(_QWORD *)(a1 + 24), v3, v2);
hash_put(*(_QWORD *)(a1 + 32), v2, 6LL, v4);
time_add_30_min(a1 + 40);
time_add_5_min_approx(a1 + 48);
result = list_size(*(_QWORD *)(a1 + 24));
if ( result > 10 )
{
v6 = list_stop(*(_QWORD *)(a1 + 24));
result = tgt_c_del(a1, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax
__int64 v6; // rax

v2 = func16(a2);
v3 = list_start(*(_QWORD *)(a1 + 24));
v4 = list_ins(*(_QWORD *)(a1 + 24), v3, v2);
hash_put(*(_QWORD *)(a1 + 32), v2, 6LL, v4);
time_add_30_min(a1 + 40);
time_add_5_min_approx(a1 + 48);
result = list_size(*(_QWORD *)(a1 + 24));
if ( result > 10 )
{
v6 = list_stop(*(_QWORD *)(a1 + 24));
result = func12(a1, v6);
}
return result;
}

original_code:
void tgt_c_put(TARGET_C * target, UCHAR * pair)
{
 NODE_C *node = ((void *)0);
 ITEM *i = ((void *)0);
 ITEM *s = ((void *)0);
 node = node_c_init(pair);
 s = list_start(target->list);
 i = list_ins(target->list, s, node);
 hash_put(target->hash, node->pair, 6, i);
 time_add_30_min(&target->lifetime);
 time_add_5_min_approx(&target->refresh);
 if (list_size(target->list) > 10) {
  s = list_stop(target->list);
  tgt_c_del(target, s);
 }
}

canonical_original_code:
void tgt_c_put(struct TARGET_C *target, unsigned char *pair)
{
 struct NODE_C *node = ((void *)0);
 struct obj_item *i = ((void *)0);
 struct obj_item *s = ((void *)0);
 node = node_c_init(pair);
 s = list_start(target->list);
 i = list_ins(target->list, s, node);
 hash_put(target->hash, node->pair, 6, i);
 time_add_30_min(&target->lifetime);
 time_add_5_min_approx(&target->refresh);
 if (list_size(target->list) > 10) {
  s = list_stop(target->list);
  tgt_c_del(target, s);
 }
}


decompiled_code:
__int64 __fastcall tgt_c_update(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // rax
__int64 v6; // rax

v2 = tgt_c_find(a1, a2);
if ( !v2 )
return tgt_c_put(a1, a2);
v3 = v2;
v4 = list_value(v2);
node_c_update(v4, a2);
list_del(*(_QWORD *)(a1 + 24), v3);
v5 = list_start(*(_QWORD *)(a1 + 24));
v6 = list_ins(*(_QWORD *)(a1 + 24), v5, v4);
return hash_put(*(_QWORD *)(a1 + 32), v4, 6LL, v6);
}

original_code:
void tgt_c_update(TARGET_C * target, UCHAR * pair)
{
 NODE_C *node = ((void *)0);
 ITEM *i = ((void *)0);
 if ((i = tgt_c_find(target, pair)) == ((void *)0)) {
  tgt_c_put(target, pair);
 } else {
  node = list_value(i);
  node_c_update(node, pair);
  list_del(target->list, i);
  i = list_ins(target->list, list_start(target->list), node);
  hash_put(target->hash, node->pair, 6, i);
 }
}

canonical_original_code:
void tgt_c_update(struct TARGET_C *target, unsigned char *pair)
{
 struct NODE_C *node = ((void *)0);
 struct obj_item *i = ((void *)0);
 if ((i = tgt_c_find(target, pair)) == ((void *)0)) {
  tgt_c_put(target, pair);
 } else {
  node = list_value(i);
  node_c_update(node, pair);
  list_del(target->list, i);
  i = list_ins(target->list, list_start(target->list), node);
  hash_put(target->hash, node->pair, 6, i);
 }
}


decompiled_code:
__int64 __fastcall cache_put(const __m128i *a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v6; // r12
int v7; // ebp
__int64 v8; // rsi
__int64 v9; // rax

result = (__int64)cache_prepare(a1);
if ( result )
{
if ( a3 > 0 )
{
v6 = result;
v7 = 0;
do
{
v8 = a2;
v7 += 6;
a2 += 6LL;
tgt_c_update(v6, v8);
}
while ( a3 > v7 );
}
result = list_size(**((_QWORD **)main + 5));
if ( result > 50 )
{
v9 = list_stop(**((_QWORD **)main + 5));
result = cache_del(v9);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(const __m128i *a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v6; // r12
int v7; // ebp
__int64 v8; // rsi
__int64 v9; // rax

result = (__int64)cache_prepare(a1);
if ( result )
{
if ( a3 > 0 )
{
v6 = result;
v7 = 0;
do
{
v8 = a2;
v7 += 6;
a2 += 6LL;
func18(v6, v8);
}
while ( a3 > v7 );
}
result = list_size(**((_QWORD **)main + 5));
if ( result > 50 )
{
v9 = list_stop(**((_QWORD **)main + 5));
result = func4(v9);
}
}
return result;
}

original_code:
void cache_put(UCHAR * target_id, UCHAR * nodes_compact_list,
        int nodes_compact_size)
{
 TARGET_C *target = cache_prepare(target_id);
 UCHAR *pair = ((void *)0);
 int j = 0;
 if (target == ((void *)0)) {
  return;
 }
 pair = nodes_compact_list;
 for (j = 0; j < nodes_compact_size; j += 6) {
  tgt_c_update(target, pair);
  pair += 6;
 }
 if (list_size(_main->cache->list) > 50) {
  cache_del(list_stop(_main->cache->list));
 }
}

canonical_original_code:
void cache_put(unsigned char *target_id, unsigned char *nodes_compact_list, int nodes_compact_size)
{
 struct TARGET_C *target = cache_prepare(target_id);
 unsigned char *pair = ((void *)0);
 int j = 0;
 if (target == ((void *)0)) {
  return;
 }
 pair = nodes_compact_list;
 for (j = 0; j < nodes_compact_size; j += 6) {
  tgt_c_update(target, pair);
  pair += 6;
 }
 if (list_size(_main->cache->list) > 50) {
  cache_del(list_stop(_main->cache->list));
 }
}

variable_types: j int


decompiled_code:
void unix_sig_stop()
{
status = 0;
}

canonical_decompiled_code:
void func0()
{
status = 0;
}

original_code:
void unix_sig_stop(int signo)
{
 status = 0;
}

variable_types: signo int


decompiled_code:
// attributes: thunk
void unix_sig_time()
{
unix_sig_stop();
}

canonical_decompiled_code:
void func1()
{
func0();
}

original_code:
void unix_sig_time(int signo)
{
 status = 0;
}


decompiled_code:
__sighandler_t __fastcall unix_signal(struct sigaction *act, struct sigaction *a2)
{
__sigset_t *v3; // rdi

v3 = &act->sa_mask;
v3[-1].__val[15] = (unsigned __int64)unix_sig_stop;
LODWORD(v3[1].__val[0]) = 0;
if ( sigemptyset(v3) == -1 || sigaction(2, act, 0LL) )
fail("Failed to set SIGINT to handle Ctrl-C");
a2->sa_handler = (__sighandler_t)unix_sig_time;
a2->sa_flags = 0;
if ( sigemptyset(&a2->sa_mask) == -1 || sigaction(14, a2, 0LL) )
fail("Failed to set SIGALRM to handle Timeouts");
return signal(13, (__sighandler_t)((char *)unix_sig_stop + 1));
}

canonical_decompiled_code:
__sighandler_t __fastcall func2(struct sigaction *act, struct sigaction *a2)
{
__sigset_t *v3; // rdi

v3 = &act->sa_mask;
v3[-1].__val[15] = (unsigned __int64)unix_sig_stop;
LODWORD(v3[1].__val[0]) = 0;
if ( sigemptyset(v3) == -1 || sigaction(2, act, 0LL) )
fail("Failed to set SIGINT to handle Ctrl-C");
a2->sa_handler = (__sighandler_t)unix_sig_time;
a2->sa_flags = 0;
if ( sigemptyset(&a2->sa_mask) == -1 || sigaction(14, a2, 0LL) )
fail("Failed to set SIGALRM to handle Timeouts");
return signal(13, (__sighandler_t)((char *)unix_sig_stop + 1));
}

original_code:
void unix_signal(struct sigaction *sig_stop, struct sigaction *sig_time)
{
 sig_stop->__sigaction_handler.sa_handler = unix_sig_stop;
 sig_stop->sa_flags = 0;
 if ((sigemptyset(&sig_stop->sa_mask) == -1)
     || (sigaction(2, sig_stop, ((void *)0)) != 0)) {
  fail("Failed to set SIGINT to handle Ctrl-C");
 }
 sig_time->__sigaction_handler.sa_handler = unix_sig_time;
 sig_time->sa_flags = 0;
 if ((sigemptyset(&sig_time->sa_mask) == -1)
     || (sigaction(14, sig_time, ((void *)0)) != 0)) {
  fail("Failed to set SIGALRM to handle Timeouts");
 }
 signal(13, ((__sighandler_t) 1));
}

canonical_original_code:
void unix_signal(struct sigaction *sig_stop, struct sigaction *sig_time)
{
 sig_stop->__sigaction_handler.sa_handler = unix_sig_stop;
 sig_stop->sa_flags = 0;
 if ((sigemptyset(&sig_stop->sa_mask) == -1)
     || (sigaction(2, sig_stop, ((void *)0)) != 0)) {
  fail("Failed to set SIGINT to handle Ctrl-C");
 }
 sig_time->__sigaction_handler.sa_handler = unix_sig_time;
 sig_time->sa_flags = 0;
 if ((sigemptyset(&sig_time->sa_mask) == -1)
     || (sigaction(14, sig_time, ((void *)0)) != 0)) {
  fail("Failed to set SIGALRM to handle Timeouts");
 }
 signal(13, ((void (*)(int)) 1));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); } *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
// attributes: thunk
unsigned int unix_set_time(unsigned int seconds)
{
return alarm(seconds);
}

canonical_decompiled_code:
unsigned int func3(unsigned int seconds)
{
return alarm(seconds);
}

original_code:
void unix_set_time(int seconds)
{
 alarm(seconds);
}

variable_types: seconds int


decompiled_code:
void __fastcall unix_fork(int a1)
{
__pid_t v1; // eax

if ( a1 != 1 )
{
v1 = fork();
if ( v1 < 0 )
{
fail("fork() failed");
setsid();
umask(0);
}
else
{
if ( v1 )
exit(0);
setsid();
umask(0);
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
__pid_t v1; // eax

if ( a1 != 1 )
{
v1 = fork();
if ( v1 < 0 )
{
fail("fork() failed");
setsid();
umask(0);
}
else
{
if ( v1 )
exit(0);
setsid();
umask(0);
}
}
}

original_code:
void unix_fork(int mode)
{
 pid_t pid = 0;
 if (mode == 1) {
  return;
 }
 pid = fork();
 if (pid < 0) {
  fail("fork() failed");
 } else if (pid != 0) {
  exit(0);
 }
 setsid();
 umask(0);
}

canonical_original_code:
void unix_fork(int mode)
{
 int pid = 0;
 if (mode == 1) {
  return;
 }
 pid = fork();
 if (pid < 0) {
  fail("fork() failed");
 } else if (pid != 0) {
  exit(0);
 }
 setsid();
 umask(0);
}

variable_types: mode int

variable_types: pid int


decompiled_code:
__uid_t __fastcall unix_limits(int a1, int a2)
{
__uid_t result; // eax
int v3; // er12
int *v4; // rax
char *v5; // rax
struct rlimit v6; // [rsp+0h] [rbp-28h] BYREF

result = getuid();
if ( !result )
{
v3 = 2 * a1 * a2 + 50;
if ( v3 < 4096 )
v3 = 4096;
v6.rlim_cur = v3;
v6.rlim_max = v3;
if ( setrlimit(RLIMIT_NOFILE, &v6) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fail(v5);
}
result = info(log, 0LL, "Max open files: %i", (unsigned int)v3);
}
return result;
}

canonical_decompiled_code:
__uid_t __fastcall func5(int a1, int a2)
{
__uid_t result; // eax
int v3; // er12
int *v4; // rax
char *v5; // rax
struct rlimit v6; // [rsp+0h] [rbp-28h] BYREF

result = getuid();
if ( !result )
{
v3 = 2 * a1 * a2 + 50;
if ( v3 < 4096 )
v3 = 4096;
v6.rlim_cur = v3;
v6.rlim_max = v3;
if ( setrlimit(RLIMIT_NOFILE, &v6) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fail(v5);
}
result = info(log, 0LL, "Max open files: %i", (unsigned int)v3);
}
return result;
}

original_code:
void unix_limits(int cores, int max_events)
{
 struct rlimit rl;
 int guess = 2 * max_events * cores + 50;
 int limit = (guess < 4096) ? 4096 : guess;
 if (getuid() != 0) {
  return;
 }
 rl.rlim_cur = limit;
 rl.rlim_max = limit;
 if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
  fail(strerror((*__errno_location ())));
 }
 info(_log, ((void *)0), "Max open files: %i", limit);
}

variable_types: cores int

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: guess int

variable_types: limit int


decompiled_code:
__uid_t unix_dropuid0()
{
__uid_t result; // eax
struct passwd *v1; // rbx

result = getuid();
if ( result )
return result;
v1 = getpwnam("nobody");
if ( !v1 )
fail("Dropping uid 0 failed.");
if ( !setenv("HOME", v1->pw_dir, 1) )
{
if ( !setgid(v1->pw_gid) )
goto LABEL_6;
LABEL_13:
fail("setgid: Unable to drop group privileges");
if ( !setuid(v1->pw_uid) )
goto LABEL_7;
LABEL_14:
fail("setuid: Unable to drop user privileges");
goto LABEL_7;
}
fail("setenv: Setting new $HOME failed.");
if ( setgid(v1->pw_gid) )
goto LABEL_13;
LABEL_6:
if ( setuid(v1->pw_uid) )
goto LABEL_14;
LABEL_7:
if ( setuid(0) != -1 )
fail("ERROR: Managed to regain root privileges?");
if ( setgid(0) != -1 )
fail("ERROR: Managed to regain root privileges?");
return info(log, 0LL, "uid: %i, gid: %i", v1->pw_uid, v1->pw_gid);
}

canonical_decompiled_code:
__uid_t func6()
{
__uid_t result; // eax
struct passwd *v1; // rbx

result = getuid();
if ( result )
return result;
v1 = getpwnam("nobody");
if ( !v1 )
fail("Dropping uid 0 failed.");
if ( !setenv("HOME", v1->pw_dir, 1) )
{
if ( !setgid(v1->pw_gid) )
goto LABEL_6;
LABEL_13:
fail("setgid: Unable to drop group privileges");
if ( !setuid(v1->pw_uid) )
goto LABEL_7;
LABEL_14:
fail("setuid: Unable to drop user privileges");
goto LABEL_7;
}
fail("setenv: Setting new $HOME failed.");
if ( setgid(v1->pw_gid) )
goto LABEL_13;
LABEL_6:
if ( setuid(v1->pw_uid) )
goto LABEL_14;
LABEL_7:
if ( setuid(0) != -1 )
fail("ERROR: Managed to regain root privileges?");
if ( setgid(0) != -1 )
fail("ERROR: Managed to regain root privileges?");
return info(log, 0LL, "uid: %i, gid: %i", v1->pw_uid, v1->pw_gid);
}

original_code:
void unix_dropuid0(void)
{
 struct passwd *pw = ((void *)0);
 if (getuid() != 0) {
  return;
 }
 if ((pw = getpwnam("nobody")) == ((void *)0)) {
  fail("Dropping uid 0 failed.");
 }
 if (setenv("HOME", pw->pw_dir, 1) != 0) {
  fail("setenv: Setting new $HOME failed.");
 }
 if (setgid(pw->pw_gid) != 0) {
  fail("setgid: Unable to drop group privileges");
 }
 if (setuid(pw->pw_uid) != 0) {
  fail("setuid: Unable to drop user privileges");
 }
 if (setuid(0) != -1) {
  fail("ERROR: Managed to regain root privileges?");
 }
 if (setgid(0) != -1) {
  fail("ERROR: Managed to regain root privileges?");
 }
 info(_log, ((void *)0), "uid: %i, gid: %i", pw->pw_uid, pw->pw_gid);
}

canonical_original_code:
void unix_dropuid0()
{
 struct passwd *pw = ((void *)0);
 if (getuid() != 0) {
  return;
 }
 if ((pw = getpwnam("nobody")) == ((void *)0)) {
  fail("Dropping uid 0 failed.");
 }
 if (setenv("HOME", pw->pw_dir, 1) != 0) {
  fail("setenv: Setting new $HOME failed.");
 }
 if (setgid(pw->pw_gid) != 0) {
  fail("setgid: Unable to drop group privileges");
 }
 if (setuid(pw->pw_uid) != 0) {
  fail("setuid: Unable to drop user privileges");
 }
 if (setuid(0) != -1) {
  fail("ERROR: Managed to regain root privileges?");
 }
 if (setgid(0) != -1) {
  fail("ERROR: Managed to regain root privileges?");
 }
 info(_log, ((void *)0), "uid: %i, gid: %i", pw->pw_uid, pw->pw_gid);
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 unix_cpus()
{
return sysconf(84);
}

canonical_decompiled_code:
__int64 func7()
{
return sysconf(84);
}

original_code:
int unix_cpus(void)
{
 return sysconf(_SC_NPROCESSORS_ONLN);
}

canonical_original_code:
int unix_cpus()
{
 return sysconf(_SC_NPROCESSORS_ONLN);
}

return_type: int


decompiled_code:
__int64 __fastcall r_lookup_remote(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 v6; // r13
__int64 v7; // r14
__int64 result; // rax
int v9; // er15
char *v10; // rbx
char *v11; // rsi
__int64 v12; // rax
int v13; // [rsp+Ch] [rbp-11Ch]
char v14[16]; // [rsp+10h] [rbp-118h] BYREF
char v15[264]; // [rsp+20h] [rbp-108h] BYREF

v13 = bckt_compact_list(**((_QWORD **)main + 7), v15, a1);
v6 = tdb_put(a2);
v7 = ldb_init(a1, a3, a4);
result = tdb_link_ldb(v6, v7);
if ( v13 > 0 )
{
v9 = 0;
v10 = v15;
do
{
v9 += 26;
v11 = v10;
v10 = (char *)ip_tuple_to_sin(v14, v10 + 20);
ldb_put(v7, v11, v14);
v12 = tdb_tid(v6);
result = send_get_peers_request(v14, a1, v12);
}
while ( v13 > v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 v6; // r13
__int64 v7; // r14
__int64 result; // rax
int v9; // er15
char *v10; // rbx
char *v11; // rsi
__int64 v12; // rax
int v13; // [rsp+Ch] [rbp-11Ch]
char v14[16]; // [rsp+10h] [rbp-118h] BYREF
char v15[264]; // [rsp+20h] [rbp-108h] BYREF

v13 = bckt_compact_list(**((_QWORD **)main + 7), v15, a1);
v6 = tdb_put(a2);
v7 = ldb_init(a1, a3, a4);
result = tdb_link_ldb(v6, v7);
if ( v13 > 0 )
{
v9 = 0;
v10 = v15;
do
{
v9 += 26;
v11 = v10;
v10 = (char *)ip_tuple_to_sin(v14, v10 + 20);
ldb_put(v7, v11, v14);
v12 = tdb_tid(v6);
result = send_get_peers_request(v14, a1, v12);
}
while ( v13 > v9 );
}
return result;
}

original_code:
void r_lookup_remote(UCHAR * target, int type, IP * from, DNS_MSG * msg)
{
 UCHAR nodes_compact_list[208];
 int nodes_compact_size = 0;
 LOOKUP *l = ((void *)0);
 UCHAR *p = ((void *)0);
 UCHAR *id = ((void *)0);
 ITEM *ti = ((void *)0);
 int j = 0;
 IP sin;
 nodes_compact_size = bckt_compact_list(_main->nbhd->bucket,
            nodes_compact_list, target);
 ti = tdb_put(type);
 l = ldb_init(target, from, msg);
 tdb_link_ldb(ti, l);
 p = nodes_compact_list;
 for (j = 0; j < nodes_compact_size; j += 26) {
  id = p;
  p += 20;
  p = ip_tuple_to_sin(&sin, p);
  ldb_put(l, id, &sin);
  send_get_peers_request(&sin, target, tdb_tid(ti));
 }
}

canonical_original_code:
void r_lookup_remote(unsigned char *target, int type, struct sockaddr_in *from, struct DNS_MSG *msg)
{
 unsigned char nodes_compact_list[208];
 int nodes_compact_size = 0;
 struct LOOKUP *l = ((void *)0);
 unsigned char *p = ((void *)0);
 unsigned char *id = ((void *)0);
 struct obj_item *ti = ((void *)0);
 int j = 0;
 struct sockaddr_in sin;
 nodes_compact_size = bckt_compact_list(_main->nbhd->bucket,
            nodes_compact_list, target);
 ti = tdb_put(type);
 l = ldb_init(target, from, msg);
 tdb_link_ldb(ti, l);
 p = nodes_compact_list;
 for (j = 0; j < nodes_compact_size; j += 26) {
  id = p;
  p += 20;
  p = ip_tuple_to_sin(&sin, p);
  ldb_put(l, id, &sin);
  send_get_peers_request(&sin, target, tdb_tid(ti));
 }
}

variable_types:
target
unsigned char *

variable_types: type 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 DNS_MSG { unsigned short id; unsigned short qr; unsigned short opcode; unsigned short aa; unsigned short tc; unsigned short rd; unsigned short ra; unsigned short rcode; unsigned short qdCount; unsigned short anCount; unsigned short nsCount; unsigned short arCount; struct DNS_Q { char *qName; unsigned int qType; unsigned int qClass; } question; struct DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD { struct { char *txt_data; } txt_record; struct { char *name; } name_server_record; struct { char *name; } cname_record; struct { char *name; } ptr_record; struct { unsigned int preference; char *exchange; } mx_record; struct { unsigned char addr[4]; } x_record; struct { unsigned short priority; unsigned short weight; unsigned short port; char *target; } srv_record; } rd_data; } answer[16]; char qName_buffer[256]; } *

variable_types: struct LOOKUP { unsigned char target[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; 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]; } c_addr; struct DNS_MSG { unsigned short id; unsigned short qr; unsigned short opcode; unsigned short aa; unsigned short tc; unsigned short rd; unsigned short ra; unsigned short rcode; unsigned short qdCount; unsigned short anCount; unsigned short nsCount; unsigned short arCount; struct DNS_Q { char *qName; unsigned int qType; unsigned int qClass; } question; struct DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD { struct { char *txt_data; } txt_record; struct { char *name; } name_server_record; struct { char *name; } cname_record; struct { char *name; } ptr_record; struct { unsigned int preference; char *exchange; } mx_record; struct { unsigned char addr[4]; } x_record; struct { unsigned short priority; unsigned short weight; unsigned short port; char *target; } srv_record; } rd_data; } answer[16]; char qName_buffer[256]; } msg; int send_response_to_initiator; int number_of_dns_responses; } *

variable_types:
p
unsigned char *

variable_types:
id
unsigned char *

user_defined_types: struct DNS_MSG { unsigned short id; unsigned short qr; unsigned short opcode; unsigned short aa; unsigned short tc; unsigned short rd; unsigned short ra; unsigned short rcode; unsigned short qdCount; unsigned short anCount; unsigned short nsCount; unsigned short arCount; struct DNS_Q question; struct DNS_RR answer[16]; char qName_buffer[256]; }

user_defined_types: struct LOOKUP { unsigned char target[20]; struct obj_list *list; struct HASH *hash; struct sockaddr_in c_addr; struct DNS_MSG msg; int send_response_to_initiator; int number_of_dns_responses; }

user_defined_types: struct DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD rd_data; }


decompiled_code:
void __fastcall r_success(struct sockaddr *addr, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // rax
__int64 v5; // rbp
_BYTE v6[1496]; // [rsp-5D8h] [rbp-5D8h] BYREF

if ( a4 )
{
p_reply_msg(a2, a3, a4);
v4 = p_encode_response(a2, v6);
v5 = v4 - (_QWORD)v6;
info(log, addr, "Send %d bytes DNS packet to", (unsigned int)v4 - (unsigned int)v6);
sendto(*(_DWORD *)(*((_QWORD *)main + 9) + 20LL), v6, (int)v5, 0, addr, 0x10u);
}
}

canonical_decompiled_code:
void __fastcall func1(struct sockaddr *addr, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // rax
__int64 v5; // rbp
_BYTE v6[1496]; // [rsp-5D8h] [rbp-5D8h] BYREF

if ( a4 )
{
p_reply_msg(a2, a3, a4);
v4 = p_encode_response(a2, v6);
v5 = v4 - (_QWORD)v6;
info(log, addr, "Send %d bytes DNS packet to", (unsigned int)v4 - (unsigned int)v6);
sendto(*(_DWORD *)(*((_QWORD *)main + 9) + 20LL), v6, (int)v5, 0, addr, 0x10u);
}
}

original_code:
void r_success(IP * from, DNS_MSG * msg, UCHAR * nodes_compact_list,
        int nodes_compact_size)
{
 UCHAR buffer[1460];
 UCHAR *p = ((void *)0);
 int buflen = 0;
 if (nodes_compact_size == 0) {
  return;
 }
 p_reply_msg(msg, nodes_compact_list, nodes_compact_size);
 p = p_encode_response(msg, buffer);
 buflen = p - buffer;
 info(_log, from, "Send %d bytes DNS packet to", buflen);
 sendto(_main->dns->sockfd, buffer, buflen, 0,
        (struct sockaddr *)from, sizeof(IP));
}

canonical_original_code:
void r_success(struct sockaddr_in *from, struct DNS_MSG *msg, unsigned char *nodes_compact_list, int nodes_compact_size)
{
 unsigned char buffer[1460];
 unsigned char *p = ((void *)0);
 int buflen = 0;
 if (nodes_compact_size == 0) {
  return;
 }
 p_reply_msg(msg, nodes_compact_list, nodes_compact_size);
 p = p_encode_response(msg, buffer);
 buflen = p - buffer;
 info(_log, from, "Send %d bytes DNS packet to", buflen);
 sendto(_main->dns->sockfd, buffer, buflen, 0,
        (struct sockaddr *)from, sizeof(IP));
}

variable_types:
buffer
unsigned char [1460]

variable_types: buflen int

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

user_defined_types: struct DNS_Q { char *qName; unsigned int qType; unsigned int qClass; }

user_defined_types: union DNS_RD { struct { char *txt_data; } txt_record; struct { char *name; } name_server_record; struct { char *name; } cname_record; struct { char *name; } ptr_record; struct { unsigned int preference; char *exchange; } mx_record; struct { unsigned char addr[4]; } x_record; struct { unsigned short priority; unsigned short weight; unsigned short port; char *target; } srv_record; }


decompiled_code:
__int64 __fastcall r_lookup_cache_db(__int64 a1, struct sockaddr *a2, __int64 a3)
{
signed int v4; // ecx
__int64 result; // rax
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

v4 = cache_compact_list(v6, a1);
result = 0LL;
if ( v4 > 0 )
{
r_success(a2, a3, (__int64)v6, v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, struct sockaddr *a2, __int64 a3)
{
signed int v4; // ecx
__int64 result; // rax
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

v4 = cache_compact_list(v6, a1);
result = 0LL;
if ( v4 > 0 )
{
func1(a2, a3, (__int64)v6, v4);
result = 1LL;
}
return result;
}

original_code:
int r_lookup_cache_db(UCHAR * target, IP * from, DNS_MSG * msg)
{
 UCHAR nodes_compact_list[48];
 int nodes_compact_size = 0;
 nodes_compact_size = cache_compact_list(nodes_compact_list, target);
 if (nodes_compact_size <= 0) {
  return 0;
 }
 r_success(from, msg, nodes_compact_list, nodes_compact_size);
 return 1;
}

canonical_original_code:
int r_lookup_cache_db(unsigned char *target, struct sockaddr_in *from, struct DNS_MSG *msg)
{
 unsigned char nodes_compact_list[48];
 int nodes_compact_size = 0;
 nodes_compact_size = cache_compact_list(nodes_compact_list, target);
 if (nodes_compact_size <= 0) {
  return 0;
 }
 r_success(from, msg, nodes_compact_list, nodes_compact_size);
 return 1;
}


decompiled_code:
__int64 __fastcall r_lookup_local_db(__int64 a1, struct sockaddr *a2, __int64 a3)
{
signed int v4; // ecx
__int64 result; // rax
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

v4 = val_compact_list(v6, a1);
result = 0LL;
if ( v4 > 0 )
{
r_success(a2, a3, (__int64)v6, v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, struct sockaddr *a2, __int64 a3)
{
signed int v4; // ecx
__int64 result; // rax
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

v4 = val_compact_list(v6, a1);
result = 0LL;
if ( v4 > 0 )
{
func1(a2, a3, (__int64)v6, v4);
result = 1LL;
}
return result;
}

original_code:
int r_lookup_local_db(UCHAR * target, IP * from, DNS_MSG * msg)
{
 UCHAR nodes_compact_list[48];
 int nodes_compact_size = 0;
 nodes_compact_size = val_compact_list(nodes_compact_list, target);
 if (nodes_compact_size <= 0) {
  return 0;
 }
 r_success(from, msg, nodes_compact_list, nodes_compact_size);
 return 1;
}

canonical_original_code:
int r_lookup_local_db(unsigned char *target, struct sockaddr_in *from, struct DNS_MSG *msg)
{
 unsigned char nodes_compact_list[48];
 int nodes_compact_size = 0;
 nodes_compact_size = val_compact_list(nodes_compact_list, target);
 if (nodes_compact_size <= 0) {
  return 0;
 }
 r_success(from, msg, nodes_compact_list, nodes_compact_size);
 return 1;
}


decompiled_code:
__int64 __fastcall r_lookup(const char *a1, struct sockaddr *a2, __int64 a3)
{
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

id_hostid(v5, a1, *((_QWORD *)main + 2), *(unsigned int *)(*((_QWORD *)main + 2) + 5168LL));
if ( (unsigned int)r_lookup_cache_db((__int64)v5, a2, a3) == 1 )
return info(log, a2, "LOOKUP %s (cached)", a1);
if ( (unsigned int)r_lookup_local_db((__int64)v5, a2, a3) == 1 )
return info(log, a2, "LOOKUP %s (local)", a1);
r_lookup_remote((__int64)v5, 4u, (__int64)a2, a3);
return info(log, a2, "LOOKUP %s (remote)", a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, struct sockaddr *a2, __int64 a3)
{
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

id_hostid(v5, a1, *((_QWORD *)main + 2), *(unsigned int *)(*((_QWORD *)main + 2) + 5168LL));
if ( (unsigned int)func2((__int64)v5, a2, a3) == 1 )
return info(log, a2, "LOOKUP %s (cached)", a1);
if ( (unsigned int)func3((__int64)v5, a2, a3) == 1 )
return info(log, a2, "LOOKUP %s (local)", a1);
func0((__int64)v5, 4u, (__int64)a2, a3);
return info(log, a2, "LOOKUP %s (remote)", a1);
}

original_code:
void r_lookup(char *hostname, IP * from, DNS_MSG * msg)
{
 UCHAR target[20];
 int result = 0;
 id_hostid(target, hostname,
    _main->conf->realm, _main->conf->bool_realm);
 result = r_lookup_cache_db(target, from, msg);
 if (result == 1) {
  info(_log, from, "LOOKUP %s (cached)", hostname);
  return;
 }
 result = r_lookup_local_db(target, from, msg);
 if (result == 1) {
  info(_log, from, "LOOKUP %s (local)", hostname);
  return;
 }
 r_lookup_remote(target, 4, from, msg);
 info(_log, from, "LOOKUP %s (remote)", hostname);
}

canonical_original_code:
void r_lookup(char *hostname, struct sockaddr_in *from, struct DNS_MSG *msg)
{
 unsigned char target[20];
 int result = 0;
 id_hostid(target, hostname,
    _main->conf->realm, _main->conf->bool_realm);
 result = r_lookup_cache_db(target, from, msg);
 if (result == 1) {
  info(_log, from, "LOOKUP %s (cached)", hostname);
  return;
 }
 result = r_lookup_local_db(target, from, msg);
 if (result == 1) {
  info(_log, from, "LOOKUP %s (local)", hostname);
  return;
 }
 r_lookup_remote(target, 4, from, msg);
 info(_log, from, "LOOKUP %s (remote)", hostname);
}

variable_types:
hostname
char *

variable_types:
target
unsigned char [20]

variable_types: result int


decompiled_code:
ssize_t __fastcall r_failure(struct sockaddr *addr, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
_BYTE v5[1512]; // [rsp+0h] [rbp-5E8h] BYREF

p_reset_msg(a2);
v2 = p_encode_response(a2, v5);
v3 = v2 - (_QWORD)v5;
info(log, addr, "Send %d bytes DNS packet to", (unsigned int)v2 - (unsigned int)v5);
return sendto(*(_DWORD *)(*((_QWORD *)main + 9) + 20LL), v5, (int)v3, 0, addr, 0x10u);
}

canonical_decompiled_code:
ssize_t __fastcall func5(struct sockaddr *addr, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
_BYTE v5[1512]; // [rsp+0h] [rbp-5E8h] BYREF

p_reset_msg(a2);
v2 = p_encode_response(a2, v5);
v3 = v2 - (_QWORD)v5;
info(log, addr, "Send %d bytes DNS packet to", (unsigned int)v2 - (unsigned int)v5);
return sendto(*(_DWORD *)(*((_QWORD *)main + 9) + 20LL), v5, (int)v3, 0, addr, 0x10u);
}

original_code:
void r_failure(IP * from, DNS_MSG * msg)
{
 UCHAR buffer[1460];
 UCHAR *p = buffer;
 int buflen = 0;
 p_reset_msg(msg);
 p = p_encode_response(msg, buffer);
 buflen = p - buffer;
 info(_log, from, "Send %d bytes DNS packet to", buflen);
 sendto(_main->dns->sockfd, buffer, buflen, 0,
        (struct sockaddr *)from, sizeof(IP));
}

canonical_original_code:
void r_failure(struct sockaddr_in *from, struct DNS_MSG *msg)
{
 unsigned char buffer[1460];
 unsigned char *p = buffer;
 int buflen = 0;
 p_reset_msg(msg);
 p = p_encode_response(msg, buffer);
 buflen = p - buffer;
 info(_log, from, "Send %d bytes DNS packet to", buflen);
 sendto(_main->dns->sockfd, buffer, buflen, 0,
        (struct sockaddr *)from, sizeof(IP));
}


decompiled_code:
__int64 __fastcall r_parse(__int64 a1, unsigned __int64 a2, struct sockaddr *a3)
{
const char *v4; // rdx
__int64 result; // rax
char *v6; // r12
size_t v7; // rax
_BYTE v8[24]; // [rsp+0h] [rbp-348h] BYREF
char *s; // [rsp+18h] [rbp-330h]
int v10; // [rsp+20h] [rbp-328h]

v4 = "DNS: Too few bytes to even start from";
if ( a2 <= 0xB )
return info(log, a3, v4);
v4 = "DNS: Packet greater than 512 bytes from";
if ( a2 > 0x200 )
return info(log, a3, v4);
if ( (unsigned int)ip_is_linklocal(a3, a2, "DNS: Packet greater than 512 bytes from") )
{
v4 = "DNS: Drop LINK-LOCAL message from";
return info(log, a3, v4);
}
switch ( (unsigned int)p_decode_query(v8, a1, (unsigned int)a2) )
{
case 0xFFFFFFFB:
result = info(log, a3, "DNS Decoder: Broken size");
break;
case 0xFFFFFFFC:
result = info(log, a3, "DNS Decoder: Decoding domain failed");
break;
case 0xFFFFFFFD:
result = info(log, a3, "DNS Decoder: Received multiple questions");
break;
case 0xFFFFFFFE:
result = info(log, a3, "DNS Decoder: Received authority");
break;
case 0xFFFFFFFF:
result = info(log, a3, "DNS Decoder: Received answer");
break;
case 0u:
result = info(log, a3, "DNS Decoder: Decoding header failed");
break;
case 1u:
v6 = s;
if ( s )
{
v7 = strlen(s);
if ( v7 > 0xFF )
{
result = info(log, a3, "DNS: Hostname too long from");
}
else if ( (unsigned int)str_valid_hostname(v6, (unsigned int)v7) )
{
if ( v10 == 1 || v10 == 33 )
result = r_lookup(v6, a3, (__int64)v8);
else
result = r_failure(a3, (__int64)v8);
}
else
{
result = info(log, a3, "DNS: Invalid hostname for lookup: '%s'", v6);
}
}
else
{
result = info(log, a3, "DNS: Missing hostname");
}
break;
default:
result = info(log, a3, "DNS Decoder: Something wicked happened");
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int64 a2, struct sockaddr *a3)
{
const char *v4; // rdx
__int64 result; // rax
char *v6; // r12
size_t v7; // rax
_BYTE v8[24]; // [rsp+0h] [rbp-348h] BYREF
char *s; // [rsp+18h] [rbp-330h]
int v10; // [rsp+20h] [rbp-328h]

v4 = "DNS: Too few bytes to even start from";
if ( a2 <= 0xB )
return info(log, a3, v4);
v4 = "DNS: Packet greater than 512 bytes from";
if ( a2 > 0x200 )
return info(log, a3, v4);
if ( (unsigned int)ip_is_linklocal(a3, a2, "DNS: Packet greater than 512 bytes from") )
{
v4 = "DNS: Drop LINK-LOCAL message from";
return info(log, a3, v4);
}
switch ( (unsigned int)p_decode_query(v8, a1, (unsigned int)a2) )
{
case 0xFFFFFFFB:
result = info(log, a3, "DNS Decoder: Broken size");
break;
case 0xFFFFFFFC:
result = info(log, a3, "DNS Decoder: Decoding domain failed");
break;
case 0xFFFFFFFD:
result = info(log, a3, "DNS Decoder: Received multiple questions");
break;
case 0xFFFFFFFE:
result = info(log, a3, "DNS Decoder: Received authority");
break;
case 0xFFFFFFFF:
result = info(log, a3, "DNS Decoder: Received answer");
break;
case 0u:
result = info(log, a3, "DNS Decoder: Decoding header failed");
break;
case 1u:
v6 = s;
if ( s )
{
v7 = strlen(s);
if ( v7 > 0xFF )
{
result = info(log, a3, "DNS: Hostname too long from");
}
else if ( (unsigned int)str_valid_hostname(v6, (unsigned int)v7) )
{
if ( v10 == 1 || v10 == 33 )
result = func4(v6, a3, (__int64)v8);
else
result = func5(a3, (__int64)v8);
}
else
{
result = info(log, a3, "DNS: Invalid hostname for lookup: '%s'", v6);
}
}
else
{
result = info(log, a3, "DNS: Missing hostname");
}
break;
default:
result = info(log, a3, "DNS Decoder: Something wicked happened");
break;
}
return result;
}

original_code:
void r_parse(UCHAR * buffer, size_t bufsize, IP * from)
{
 DNS_MSG msg;
 const char *hostname = ((void *)0);
 int result = 0;
 if (bufsize < 12) {
  info(_log, from, "DNS: Too few bytes to even start from");
  return;
 }
 if (bufsize > 512) {
  info(_log, from, "DNS: Packet greater than 512 bytes from");
  return;
 }
 if (ip_is_linklocal(from)) {
  info(_log, from, "DNS: Drop LINK-LOCAL message from");
  return;
 }
 result = p_decode_query(&msg, buffer, bufsize);
 switch (result) {
 case 1:
  break;
 case 0:
  info(_log, from, "DNS Decoder: Decoding header failed");
  return;
 case -1:
  info(_log, from, "DNS Decoder: Received answer");
  return;
 case -2:
  info(_log, from, "DNS Decoder: Received authority");
  return;
 case -3:
  info(_log, from, "DNS Decoder: Received multiple questions");
  return;
 case -4:
  info(_log, from, "DNS Decoder: Decoding domain failed");
  return;
 case -5:
  info(_log, from, "DNS Decoder: Broken size");
  return;
 default:
  info(_log, from, "DNS Decoder: Something wicked happened");
  return;
 }
 hostname = msg.question.qName;
 if (hostname == ((void *)0)) {
  info(_log, from, "DNS: Missing hostname");
  return;
 }
 if (strlen(hostname) > 255) {
  info(_log, from, "DNS: Hostname too long from");
  return;
 }
 if (!str_valid_hostname(hostname, strlen(hostname))) {
  info(_log, from, "DNS: Invalid hostname for lookup: '%s'",
       hostname);
  return;
 }
 switch (msg.question.qType) {
 case A_Resource_RecordType:
  r_lookup((char *)hostname, from, &msg);
  break;
 case SRV_Resource_RecordType:
  r_lookup((char *)hostname, from, &msg);
  break;
 default:
  r_failure(from, &msg);
 }
}

canonical_original_code:
void r_parse(unsigned char *buffer, unsigned long bufsize, struct sockaddr_in *from)
{
 struct DNS_MSG msg;
 char *hostname = ((void *)0);
 int result = 0;
 if (bufsize < 12) {
  info(_log, from, "DNS: Too few bytes to even start from");
  return;
 }
 if (bufsize > 512) {
  info(_log, from, "DNS: Packet greater than 512 bytes from");
  return;
 }
 if (ip_is_linklocal(from)) {
  info(_log, from, "DNS: Drop LINK-LOCAL message from");
  return;
 }
 result = p_decode_query(&msg, buffer, bufsize);
 switch (result) {
 case 1:
  break;
 case 0:
  info(_log, from, "DNS Decoder: Decoding header failed");
  return;
 case -1:
  info(_log, from, "DNS Decoder: Received answer");
  return;
 case -2:
  info(_log, from, "DNS Decoder: Received authority");
  return;
 case -3:
  info(_log, from, "DNS Decoder: Received multiple questions");
  return;
 case -4:
  info(_log, from, "DNS Decoder: Decoding domain failed");
  return;
 case -5:
  info(_log, from, "DNS Decoder: Broken size");
  return;
 default:
  info(_log, from, "DNS Decoder: Something wicked happened");
  return;
 }
 hostname = msg.question.qName;
 if (hostname == ((void *)0)) {
  info(_log, from, "DNS: Missing hostname");
  return;
 }
 if (strlen(hostname) > 255) {
  info(_log, from, "DNS: Hostname too long from");
  return;
 }
 if (!str_valid_hostname(hostname, strlen(hostname))) {
  info(_log, from, "DNS: Invalid hostname for lookup: '%s'",
       hostname);
  return;
 }
 switch (msg.question.qType) {
 case A_Resource_RecordType:
  r_lookup((char *)hostname, from, &msg);
  break;
 case SRV_Resource_RecordType:
  r_lookup((char *)hostname, from, &msg);
  break;
 default:
  r_failure(from, &msg);
 }
}

variable_types:
buffer
unsigned char *

variable_types:
bufsize
unsigned long

variable_types: struct DNS_MSG { unsigned short id; unsigned short qr; unsigned short opcode; unsigned short aa; unsigned short tc; unsigned short rd; unsigned short ra; unsigned short rcode; unsigned short qdCount; unsigned short anCount; unsigned short nsCount; unsigned short arCount; struct DNS_Q { char *qName; unsigned int qType; unsigned int qClass; } question; struct DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD { struct { char *txt_data; } txt_record; struct { char *name; } name_server_record; struct { char *name; } cname_record; struct { char *name; } ptr_record; struct { unsigned int preference; char *exchange; } mx_record; struct { unsigned char addr[4]; } x_record; struct { unsigned short priority; unsigned short weight; unsigned short port; char *target; } srv_record; } rd_data; } answer[16]; char qName_buffer[256]; }


decompiled_code:
__int64 str_isValidUTF8()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
int str_isValidUTF8(char *string)
{
 unsigned int i = 0, j = 0, n = 0;
 unsigned int length = strlen(string);
 for (i = 0; i < length; i++) {
  if (string[i] < 0x80)
   n = 0;
  else if ((string[i] & 0xE0) == 0xC0)
   n = 1;
  else if ((string[i] & 0xF0) == 0xE0)
   n = 2;
  else if ((string[i] & 0xF8) == 0xF0)
   n = 3;
  else if ((string[i] & 0xFC) == 0xF8)
   n = 4;
  else if ((string[i] & 0xFE) == 0xFC)
   n = 5;
  else
   return 0;
  for (j = 0; j < n; j++) {
   if ((++i == length) || ((string[i] & 0xC0) != 0x80)) {
    return 0;
   }
  }
 }
 return 1;
}

canonical_original_code:
int str_isValidUTF8(char *string)
{
 unsigned int i = 0; unsigned int j = 0; unsigned int n = 0;
 unsigned int length = strlen(string);
 for (i = 0; i < length; i++) {
  if (string[i] < 0x80)
   n = 0;
  else if ((string[i] & 0xE0) == 0xC0)
   n = 1;
  else if ((string[i] & 0xF0) == 0xE0)
   n = 2;
  else if ((string[i] & 0xF8) == 0xF0)
   n = 3;
  else if ((string[i] & 0xFC) == 0xF8)
   n = 4;
  else if ((string[i] & 0xFE) == 0xFC)
   n = 5;
  else
   return 0;
  for (j = 0; j < n; j++) {
   if ((++i == length) || ((string[i] & 0xC0) != 0x80)) {
    return 0;
   }
  }
 }
 return 1;
}

variable_types:
string
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
n
unsigned int

variable_types:
length
unsigned int


decompiled_code:
__int64 __fastcall str_isNumber(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 1LL;
if ( (unsigned __int8)(*a1 - 48) > 9u )
break;
++a1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 1LL;
if ( (unsigned __int8)(*a1 - 48) > 9u )
break;
++a1;
}
return 0LL;
}

original_code:
int str_isNumber(char *string)
{
 char *p = string;
 while (*p != '\0') {
  if (*p < '0' || *p > '9') {
   return 0;
  }
  p++;
 }
 return 1;
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall str_safe_port(char *nptr)
{
__int64 result; // rax
int *v2; // rax
int *v3; // rbp
__int64 v4; // rdx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
result = str_isNumber(nptr);
if ( (_DWORD)result )
{
v2 = _errno_location();
*v2 = 0;
v3 = v2;
v4 = strtol(nptr, &endptr, 10);
result = (unsigned int)*v3;
if ( (_DWORD)result )
{
result = 0LL;
}
else if ( endptr != nptr && !*endptr && (unsigned __int64)(v4 - 1) <= 0xFFFE )
{
result = (unsigned int)v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *nptr)
{
__int64 result; // rax
int *v2; // rax
int *v3; // rbp
__int64 v4; // rdx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
result = func1(nptr);
if ( (_DWORD)result )
{
v2 = _errno_location();
*v2 = 0;
v3 = v2;
v4 = strtol(nptr, &endptr, 10);
result = (unsigned int)*v3;
if ( (_DWORD)result )
{
result = 0LL;
}
else if ( endptr != nptr && !*endptr && (unsigned __int64)(v4 - 1) <= 0xFFFE )
{
result = (unsigned int)v4;
}
}
return result;
}

original_code:
int str_safe_port(char *string)
{
 LONG number = 0;
 char *end = ((void *)0);
 if (str_isNumber(string)) {
  (*__errno_location ()) = 0;
  number = strtol(string, &end, 10);
  if ((*__errno_location ()) != 0) {
   return 0;
  }
  if (end == string) {
   return 0;
  }
  if (*end != '\0') {
   return 0;
  }
  if (number < 1 || number > 65535) {
   return 0;
  }
 }
 return number;
}

canonical_original_code:
int str_safe_port(char *string)
{
 long number = 0;
 char *end = ((void *)0);
 if (str_isNumber(string)) {
  (*__errno_location ()) = 0;
  number = strtol(string, &end, 10);
  if ((*__errno_location ()) != 0) {
   return 0;
  }
  if (end == string) {
   return 0;
  }
  if (*end != '\0') {
   return 0;
  }
  if (number < 1 || number > 65535) {
   return 0;
  }
 }
 return number;
}

variable_types: number long

variable_types:
end
char *


decompiled_code:
__int64 __fastcall str_isValidFilename(const char *a1)
{
size_t v2; // rax
unsigned int v3; // ecx
__int64 v4; // rdi

v2 = strlen(a1);
v3 = 0;
v4 = 0x4000000001FFBLL;
while ( v3 < v2 )
{
if ( (unsigned __int8)((a1[v3] & 0xDF) - 65) > 0x19u
&& ((unsigned __int8)(a1[v3] - 45) > 0x32u || !_bittest64(&v4, (unsigned int)(unsigned __int8)a1[v3] - 45)) )
{
return 0LL;
}
++v3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
size_t v2; // rax
unsigned int v3; // ecx
__int64 v4; // rdi

v2 = strlen(a1);
v3 = 0;
v4 = 0x4000000001FFBLL;
while ( v3 < v2 )
{
if ( (unsigned __int8)((a1[v3] & 0xDF) - 65) > 0x19u
&& ((unsigned __int8)(a1[v3] - 45) > 0x32u || !_bittest64(&v4, (unsigned int)(unsigned __int8)a1[v3] - 45)) )
{
return 0LL;
}
++v3;
}
return 1LL;
}

original_code:
int str_isValidFilename(char *string)
{
 unsigned int i = 0;
 for (i = 0; i < strlen(string); i++) {
  if (string[i] >= '0' && string[i] <= '9') {
   continue;
  } else if (string[i] >= 'A' && string[i] <= 'Z') {
   continue;
  } else if (string[i] >= 'a' && string[i] <= 'z') {
   continue;
  } else if (string[i] == '-') {
   continue;
  } else if (string[i] == '_') {
   continue;
  } else if (string[i] == '.') {
   continue;
  } else {
   return 0;
  }
 }
 return 1;
}


decompiled_code:
__int64 __fastcall str_valid_hostname(_BYTE *a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rsi
__int64 v4; // rcx

if ( a2 <= 0 )
return 1LL;
v2 = (unsigned int)(a2 - 1);
v3 = 0x4000000001FFBLL;
v4 = (__int64)&a1[v2 + 1];
while ( (unsigned __int8)((*a1 & 0xDF) - 65) <= 0x19u
|| (unsigned __int8)(*a1 - 45) <= 0x32u && _bittest64(&v3, (unsigned int)(unsigned __int8)*a1 - 45) )
{
if ( (_BYTE *)v4 == ++a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rsi
__int64 v4; // rcx

if ( a2 <= 0 )
return 1LL;
v2 = (unsigned int)(a2 - 1);
v3 = 0x4000000001FFBLL;
v4 = (__int64)&a1[v2 + 1];
while ( (unsigned __int8)((*a1 & 0xDF) - 65) <= 0x19u
|| (unsigned __int8)(*a1 - 45) <= 0x32u && _bittest64(&v3, (unsigned int)(unsigned __int8)*a1 - 45) )
{
if ( (_BYTE *)v4 == ++a1 )
return 1LL;
}
return 0LL;
}

original_code:
int str_valid_hostname(const char *hostname, int hostsize)
{
 int i = 0;
 for (i = 0; i < hostsize; i++) {
  if (hostname[i] >= '0' && hostname[i] <= '9') {
   continue;
  } else if (hostname[i] >= 'A' && hostname[i] <= 'Z') {
   continue;
  } else if (hostname[i] >= 'a' && hostname[i] <= 'z') {
   continue;
  } else if (hostname[i] == '-') {
   continue;
  } else if (hostname[i] == '_') {
   continue;
  } else if (hostname[i] == '.') {
   continue;
  } else {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int str_valid_hostname(char *hostname, int hostsize)
{
 int i = 0;
 for (i = 0; i < hostsize; i++) {
  if (hostname[i] >= '0' && hostname[i] <= '9') {
   continue;
  } else if (hostname[i] >= 'A' && hostname[i] <= 'Z') {
   continue;
  } else if (hostname[i] >= 'a' && hostname[i] <= 'z') {
   continue;
  } else if (hostname[i] == '-') {
   continue;
  } else if (hostname[i] == '_') {
   continue;
  } else if (hostname[i] == '.') {
   continue;
  } else {
   return 0;
  }
 }
 return 1;
}

variable_types: hostsize int

variable_types: i int


decompiled_code:
_BOOL8 __fastcall str_valid_tld(char *s1, int a2, const char *a3)
{
char *v5; // rax

if ( a2 <= 4 )
return 0LL;
while ( 1 )
{
v5 = strchr(s1, 46);
if ( !v5 )
break;
s1 = v5 + 1;
}
return strcmp(s1, a3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(char *s1, int a2, const char *a3)
{
char *v5; // rax

if ( a2 <= 4 )
return 0LL;
while ( 1 )
{
v5 = strchr(s1, 46);
if ( !v5 )
break;
s1 = v5 + 1;
}
return strcmp(s1, a3) == 0;
}

original_code:
int str_valid_tld(const char *hostname, int hostsize, const char *domain)
{
 const char *p0 = ((void *)0);
 char *p1 = ((void *)0);
 if (hostsize < 5) {
  return 0;
 }
 p0 = hostname;
 while ((p1 = strchr(p0, '.')) != ((void *)0)) {
  p0 = p1 + 1;
 }
 if (strcmp(p0, domain) != 0) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int str_valid_tld(char *hostname, int hostsize, char *domain)
{
 char *p0 = ((void *)0);
 char *p1 = ((void *)0);
 if (hostsize < 5) {
  return 0;
 }
 p0 = hostname;
 while ((p1 = strchr(p0, '.')) != ((void *)0)) {
  p0 = p1 + 1;
 }
 if (strcmp(p0, domain) != 0) {
  return 0;
 }
 return 1;
}

variable_types:
domain
char *


decompiled_code:
__int64 __fastcall str_count(char *haystack, char *needle)
{
unsigned int v2; // er12
__int64 v4; // r13
char *v5; // rax

v2 = 0;
v4 = (int)strlen(needle);
while ( 1 )
{
v5 = strstr(haystack, needle);
if ( !v5 )
break;
haystack = &v5[v4];
++v2;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *haystack, char *needle)
{
unsigned int v2; // er12
__int64 v4; // r13
char *v5; // rax

v2 = 0;
v4 = (int)strlen(needle);
while ( 1 )
{
v5 = strstr(haystack, needle);
if ( !v5 )
break;
haystack = &v5[v4];
++v2;
}
return v2;
}

original_code:
int str_count(char *buffer, const char *search)
{
 int counter = 0;
 int size = strlen(search);
 char *p = buffer;
 while ((p = strstr(p, search)) != ((void *)0)) {
  p += size;
  counter++;
 }
 if (counter < 0) {
  fail("str_count(): Integer overflow?");
 }
 return counter;
}

canonical_original_code:
int str_count(char *buffer, char *search)
{
 int counter = 0;
 int size = strlen(search);
 char *p = buffer;
 while ((p = strstr(p, search)) != ((void *)0)) {
  p += size;
  counter++;
 }
 if (counter < 0) {
  fail("str_count(): Integer overflow?");
 }
 return counter;
}

variable_types:
buffer
char *

variable_types:
search
char *

variable_types: counter int

variable_types: size int


decompiled_code:
__int64 __fastcall str_gmttime(char *dest, int a2, time_t a3)
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char src[16]; // [rsp+10h] [rbp-78h] BYREF
char v6[16]; // [rsp+20h] [rbp-68h] BYREF
struct tm tp; // [rsp+30h] [rbp-58h] BYREF

timer = a3;
strcpy(v6, " 00:00:00 GMT");
*(__m128i *)src = _mm_load_si128((const __m128i *)&LC1);
memset(dest, 0, a2);
if ( !gmtime_r(&timer, &tp) || (result = strftime(dest, 0x400uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp)) == 0 )
result = (__int64)strncpy(dest, src, a2 - 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *dest, int a2, time_t a3)
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char src[16]; // [rsp+10h] [rbp-78h] BYREF
char v6[16]; // [rsp+20h] [rbp-68h] BYREF
struct tm tp; // [rsp+30h] [rbp-58h] BYREF

timer = a3;
strcpy(v6, " 00:00:00 GMT");
*(__m128i *)src = _mm_load_si128((const __m128i *)&LC1);
memset(dest, 0, a2);
if ( !gmtime_r(&timer, &tp) || (result = strftime(dest, 0x400uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp)) == 0 )
result = (__int64)strncpy(dest, src, a2 - 1);
return result;
}

original_code:
void str_gmttime(char *buffer, int size, time_t timestamp)
{
 char fallback[] = "Thu, 01 Jan 1970 00:00:00 GMT";
 struct tm date;
 memset(buffer, '\0', size);
 if (gmtime_r(&timestamp, &date) != ((void *)0)) {
  if (strftime
      (buffer, 1024, "%a, %d %b %Y %H:%M:%S %Z",
       &date) == 0) {
   strncpy(buffer, fallback, size - 1);
  }
 } else {
  strncpy(buffer, fallback, size - 1);
 }
}

canonical_original_code:
void str_gmttime(char *buffer, int size, long timestamp)
{
 char fallback[] = "Thu, 01 Jan 1970 00:00:00 GMT";
 struct tm date;
 memset(buffer, '\0', size);
 if (gmtime_r(&timestamp, &date) != ((void *)0)) {
  if (strftime
      (buffer, 1024, "%a, %d %b %Y %H:%M:%S %Z",
       &date) == 0) {
   strncpy(buffer, fallback, size - 1);
  }
 } else {
  strncpy(buffer, fallback, size - 1);
 }
}

variable_types: timestamp long

variable_types:
fallback
char []

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
int __fastcall str_GMTtime(char *dest, int a2)
{
int result; // eax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
__m128i v4; // [rsp+10h] [rbp-38h] BYREF
char v5[16]; // [rsp+20h] [rbp-28h] BYREF

strcpy(v5, " 00:00:00 GMT");
v4 = _mm_load_si128((const __m128i *)&LC1);
if ( time(&timer) <= 0 )
result = snprintf(dest, a2, "%s", v4.m128i_i8);
else
result = str_gmttime(dest, a2, timer);
return result;
}

canonical_decompiled_code:
int __fastcall func8(char *dest, int a2)
{
int result; // eax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
__m128i v4; // [rsp+10h] [rbp-38h] BYREF
char v5[16]; // [rsp+20h] [rbp-28h] BYREF

strcpy(v5, " 00:00:00 GMT");
v4 = _mm_load_si128((const __m128i *)&LC1);
if ( time(&timer) <= 0 )
result = snprintf(dest, a2, "%s", v4.m128i_i8);
else
result = func7(dest, a2, timer);
return result;
}

original_code:
void str_GMTtime(char *buffer, int size)
{
 char fallback[] = "Thu, 01 Jan 1970 00:00:00 GMT";
 time_t timestamp;
 if (time(&timestamp) > 0) {
  str_gmttime(buffer, size, timestamp);
 } else {
  snprintf(buffer, size, "%s", fallback);
 }
}

canonical_original_code:
void str_GMTtime(char *buffer, int size)
{
 char fallback[] = "Thu, 01 Jan 1970 00:00:00 GMT";
 long timestamp;
 if (time(&timestamp) > 0) {
  str_gmttime(buffer, size, timestamp);
 } else {
  snprintf(buffer, size, "%s", fallback);
 }
}


decompiled_code:
int __fastcall str_prettySize(void *a1, int a2, unsigned __int64 a3)
{
char *v4; // rax
unsigned __int64 v5; // rcx
const char *v6; // rdx

v4 = (char *)memset(a1, 0, a2);
v5 = a3;
if ( a3 > 0x40000000 )
return snprintf(v4, a2, "%lu GiB", a3 >> 30);
if ( a3 > 0x100000 )
return snprintf(v4, a2, "%lu MiB", a3 >> 20);
v6 = "%lu B";
if ( a3 > 0x400 )
{
v5 = a3 >> 10;
v6 = "%lu KiB";
}
return snprintf(v4, a2, v6, v5);
}

canonical_decompiled_code:
int __fastcall func9(void *a1, int a2, unsigned __int64 a3)
{
char *v4; // rax
unsigned __int64 v5; // rcx
const char *v6; // rdx

v4 = (char *)memset(a1, 0, a2);
v5 = a3;
if ( a3 > 0x40000000 )
return snprintf(v4, a2, "%lu GiB", a3 >> 30);
if ( a3 > 0x100000 )
return snprintf(v4, a2, "%lu MiB", a3 >> 20);
v6 = "%lu B";
if ( a3 > 0x400 )
{
v5 = a3 >> 10;
v6 = "%lu KiB";
}
return snprintf(v4, a2, v6, v5);
}

original_code:
void str_prettySize(char *buffer, int size, unsigned long filesize)
{
 long int thissize = 0;
 memset(buffer, '\0', size);
 if (filesize > 1073741824) {
  thissize = filesize / 1073741824;
  snprintf(buffer, size, "%lu GiB", thissize);
 } else if (filesize > 1048576) {
  thissize = filesize / 1048576;
  snprintf(buffer, size, "%lu MiB", thissize);
 } else if (filesize > 1024) {
  thissize = filesize / 1024;
  snprintf(buffer, size, "%lu KiB", thissize);
 } else {
  snprintf(buffer, size, "%lu B", filesize);
 }
}

canonical_original_code:
void str_prettySize(char *buffer, int size, unsigned long filesize)
{
 long thissize = 0;
 memset(buffer, '\0', size);
 if (filesize > 1073741824) {
  thissize = filesize / 1073741824;
  snprintf(buffer, size, "%lu GiB", thissize);
 } else if (filesize > 1048576) {
  thissize = filesize / 1048576;
  snprintf(buffer, size, "%lu MiB", thissize);
 } else if (filesize > 1024) {
  thissize = filesize / 1024;
  snprintf(buffer, size, "%lu KiB", thissize);
 } else {
  snprintf(buffer, size, "%lu B", filesize);
 }
}

variable_types:
filesize
unsigned long

variable_types: thissize long


original_code:
int str_sha1_compare(UCHAR * id1, UCHAR * id2, UCHAR * target)
{
 UCHAR xor1;
 UCHAR xor2;
 int i = 0;
 for (i = 0; i < 20; i++) {
  if (id1[i] == id2[i]) {
   continue;
  }
  xor1 = id1[i] ^ target[i];
  xor2 = id2[i] ^ target[i];
  if (xor1 < xor2) {
   return -1;
  } else {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int str_sha1_compare(unsigned char *id1, unsigned char *id2, unsigned char *target)
{
 unsigned char xor1;
 unsigned char xor2;
 int i = 0;
 for (i = 0; i < 20; i++) {
  if (id1[i] == id2[i]) {
   continue;
  }
  xor1 = id1[i] ^ target[i];
  xor2 = id2[i] ^ target[i];
  if (xor1 < xor2) {
   return -1;
  } else {
   return 1;
  }
 }
 return 0;
}

variable_types:
target
unsigned char *


decompiled_code:
_QWORD *val_init()
{
_QWORD *v0; // r12

v0 = (_QWORD *)myalloc(16LL);
*v0 = list_init();
v0[1] = hash_init(51LL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = (_QWORD *)myalloc(16LL);
*v0 = list_init();
v0[1] = hash_init(51LL);
return v0;
}

original_code:
VALUE *val_init(void)
{
 VALUE *value = (VALUE *) myalloc(sizeof(VALUE));
 value->list = list_init();
 value->hash = hash_init(50 + 1);
 return value;
}

canonical_original_code:
struct obj_val *val_init()
{
 struct obj_val *value = (VALUE *) myalloc(sizeof(VALUE));
 value->list = list_init();
 value->hash = hash_init(50 + 1);
 return value;
}

variable_types: struct obj_val { struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; } *

user_defined_types: struct obj_val { struct obj_list *list; struct HASH *hash; }


decompiled_code:
__int64 __fastcall val_find(__int64 a1)
{
return hash_get(*(_QWORD *)(*((_QWORD *)main + 11) + 8LL), a1, 20LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return hash_get(*(_QWORD *)(*((_QWORD *)main + 11) + 8LL), a1, 20LL);
}

original_code:
TARGET_V *val_find(UCHAR * target_id)
{
 return hash_get(_main->value->hash, target_id, 20);
}

canonical_original_code:
struct TARGET_V *val_find(unsigned char *target_id)
{
 return hash_get(_main->value->hash, target_id, 20);
}

return_type: struct TARGET_V { unsigned char target[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; } *

user_defined_types: struct TARGET_V { unsigned char target[20]; struct obj_list *list; struct HASH *hash; }


original_code:
int val_compact_list(UCHAR * nodes_compact_list, UCHAR * target_id)
{
 UCHAR *p = nodes_compact_list;
 NODE_V *node_v = ((void *)0);
 TARGET_V *target = ((void *)0);
 ITEM *item = ((void *)0);
 int j = 0;
 int size = 0;
 if ((target = val_find(target_id)) == ((void *)0)) {
  return 0;
 }
 item = list_start(target->list);
 while (item != ((void *)0) && j < 8) {
  node_v = list_value(item);
  memcpy(p, node_v->pair, 6);
  p += 6;
  size += 6;
  item = list_next(item);
  j++;
 }
 return size;
}

canonical_original_code:
int val_compact_list(unsigned char *nodes_compact_list, unsigned char *target_id)
{
 unsigned char *p = nodes_compact_list;
 struct NODE_V *node_v = ((void *)0);
 struct TARGET_V *target = ((void *)0);
 struct obj_item *item = ((void *)0);
 int j = 0;
 int size = 0;
 if ((target = val_find(target_id)) == ((void *)0)) {
  return 0;
 }
 item = list_start(target->list);
 while (item != ((void *)0) && j < 8) {
  node_v = list_value(item);
  memcpy(p, node_v->pair, 6);
  p += 6;
  size += 6;
  item = list_next(item);
  j++;
 }
 return size;
}

variable_types:
p
unsigned char *

variable_types: struct NODE_V { unsigned char id[20]; unsigned char pair[6]; long eol; } *

variable_types: struct TARGET_V { unsigned char target[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; } *

variable_types: j int


decompiled_code:
__int64 __fastcall tgt_v_free(__int64 a1)
{
list_clear(*(_QWORD *)(a1 + 24));
list_free(*(_QWORD *)(a1 + 24));
hash_free(*(_QWORD *)(a1 + 32));
return myfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
list_clear(*(_QWORD *)(a1 + 24));
list_free(*(_QWORD *)(a1 + 24));
hash_free(*(_QWORD *)(a1 + 32));
return myfree(a1);
}

original_code:
void tgt_v_free(TARGET_V * target)
{
 list_clear(target->list);
 list_free(target->list);
 hash_free(target->hash);
 myfree(target);
}

canonical_original_code:
void tgt_v_free(struct TARGET_V *target)
{
 list_clear(target->list);
 list_free(target->list);
 hash_free(target->hash);
 myfree(target);
}


decompiled_code:
__int64 __fastcall val_del(__int64 a1)
{
__int64 v1; // rbp

v1 = list_value(a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 11) + 8LL), v1, 20LL);
list_del(**((_QWORD **)main + 11), a1);
return tgt_v_free(v1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbp

v1 = list_value(a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 11) + 8LL), v1, 20LL);
list_del(**((_QWORD **)main + 11), a1);
return func3(v1);
}

original_code:
void val_del(ITEM * i)
{
 TARGET_V *target = list_value(i);
 hash_del(_main->value->hash, target->target, 20);
 list_del(_main->value->list, i);
 tgt_v_free(target);
}

canonical_original_code:
void val_del(struct obj_item *i)
{
 struct TARGET_V *target = list_value(i);
 hash_del(_main->value->hash, target->target, 20);
 list_del(_main->value->list, i);
 tgt_v_free(target);
}

variable_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *


decompiled_code:
__int64 *val_clean()
{
__int64 *result; // rax
__int64 i; // rdi

result = (__int64 *)**((_QWORD **)main + 11);
for ( i = *result; *result; i = *result )
{
val_del(i);
result = (__int64 *)**((_QWORD **)main + 11);
}
return result;
}

canonical_decompiled_code:
__int64 *func5()
{
__int64 *result; // rax
__int64 i; // rdi

result = (__int64 *)**((_QWORD **)main + 11);
for ( i = *result; *result; i = *result )
{
func4(i);
result = (__int64 *)**((_QWORD **)main + 11);
}
return result;
}

original_code:
void val_clean(void)
{
 while (_main->value->list->item != ((void *)0)) {
  val_del(_main->value->list->item);
 }
}

canonical_original_code:
void val_clean()
{
 while (_main->value->list->item != ((void *)0)) {
  val_del(_main->value->list->item);
 }
}


decompiled_code:
__int64 val_free()
{
val_clean();
list_clear(**((_QWORD **)main + 11));
list_free(**((_QWORD **)main + 11));
hash_free(*(_QWORD *)(*((_QWORD *)main + 11) + 8LL));
return myfree(*((_QWORD *)main + 11));
}

canonical_decompiled_code:
__int64 func6()
{
func5();
list_clear(**((_QWORD **)main + 11));
list_free(**((_QWORD **)main + 11));
hash_free(*(_QWORD *)(*((_QWORD *)main + 11) + 8LL));
return myfree(*((_QWORD *)main + 11));
}

original_code:
void val_free(void)
{
 val_clean();
 list_clear(_main->value->list);
 list_free(_main->value->list);
 hash_free(_main->value->hash);
 myfree(_main->value);
}

canonical_original_code:
void val_free()
{
 val_clean();
 list_clear(_main->value->list);
 list_free(_main->value->list);
 hash_free(_main->value->hash);
 myfree(_main->value);
}


decompiled_code:
__int64 __fastcall tgt_v_print(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
unsigned __int16 v4; // ax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v2 = result;
do
{
v3 = list_value(v2);
ip_tuple_to_sin(v5, v3 + 20);
ip_sin_to_string(v5, v6);
v4 = ip_sin_to_port(v5);
info(log, 0LL, " %s:%i", v6, v4);
result = list_next(v2);
v2 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
unsigned __int16 v4; // ax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v2 = result;
do
{
v3 = list_value(v2);
ip_tuple_to_sin(v5, v3 + 20);
ip_sin_to_string(v5, v6);
v4 = ip_sin_to_port(v5);
info(log, 0LL, " %s:%i", v6, v4);
result = list_next(v2);
v2 = result;
}
while ( result );
}
return result;
}

original_code:
void tgt_v_print(TARGET_V * target)
{
 ITEM *i = ((void *)0);
 NODE_V *node = ((void *)0);
 IP sin;
 char ip_buf[16 + 1];
 USHORT port = 0;
 i = list_start(target->list);
 while (i != ((void *)0)) {
  node = list_value(i);
  ip_tuple_to_sin(&sin, node->pair);
  ip_sin_to_string(&sin, ip_buf);
  port = ip_sin_to_port(&sin);
  info(_log, ((void *)0), "  %s:%i", ip_buf, port);
  i = list_next(i);
 }
}

canonical_original_code:
void tgt_v_print(struct TARGET_V *target)
{
 struct obj_item *i = ((void *)0);
 struct NODE_V *node = ((void *)0);
 struct sockaddr_in sin;
 char ip_buf[-1];
 unsigned short port = 0;
 i = list_start(target->list);
 while (i != ((void *)0)) {
  node = list_value(i);
  ip_tuple_to_sin(&sin, node->pair);
  ip_sin_to_string(&sin, ip_buf);
  port = ip_sin_to_port(&sin);
  info(_log, ((void *)0), "  %s:%i", ip_buf, port);
  i = list_next(i);
 }
}

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:
port
unsigned short

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 NODE_V { unsigned char id[20]; unsigned char pair[6]; long eol; }


decompiled_code:
__int64 val_print()
{
__int64 result; // rax
__int64 i; // rbp
__int64 v2; // r12
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = log_verbosely(log);
if ( !(_DWORD)result )
{
info(log, 0LL, "Values:");
result = list_start(**((_QWORD **)main + 11));
for ( i = result; result; i = result )
{
v2 = list_value(i);
hex_hash_encode(v3, v2);
info(log, 0LL, " Target: %s", v3);
tgt_v_print(v2);
result = list_next(i);
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
__int64 i; // rbp
__int64 v2; // r12
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = log_verbosely(log);
if ( !(_DWORD)result )
{
info(log, 0LL, "Values:");
result = list_start(**((_QWORD **)main + 11));
for ( i = result; result; i = result )
{
v2 = list_value(i);
hex_hash_encode(v3, v2);
info(log, 0LL, " Target: %s", v3);
func7(v2);
result = list_next(i);
}
}
return result;
}

original_code:
void val_print(void)
{
 ITEM *i = ((void *)0);
 TARGET_V *target = ((void *)0);
 char hex[2*20 +1];
 if (log_verbosely(_log)) {
  return;
 }
 info(_log, ((void *)0), "Values:");
 i = list_start(_main->value->list);
 while (i != ((void *)0)) {
  target = list_value(i);
  hex_hash_encode(hex, target->target);
  info(_log, ((void *)0), " Target: %s", hex);
  tgt_v_print(target);
  i = list_next(i);
 }
}

canonical_original_code:
void val_print()
{
 struct obj_item *i = ((void *)0);
 struct TARGET_V *target = ((void *)0);
 char hex[-1];
 if (log_verbosely(_log)) {
  return;
 }
 info(_log, ((void *)0), "Values:");
 i = list_start(_main->value->list);
 while (i != ((void *)0)) {
  target = list_value(i);
  hex_hash_encode(hex, target->target);
  info(_log, ((void *)0), " Target: %s", hex);
  tgt_v_print(target);
  i = list_next(i);
 }
}

variable_types:
hex
char [-1]

user_defined_types: struct obj_list { struct obj_item *item; long size; }

user_defined_types: struct HASH { struct BUCKET *buckets; long size; }


decompiled_code:
__int64 __fastcall tgt_v_find(__int64 a1, __int64 a2)
{
return hash_get(*(_QWORD *)(a1 + 32), a2, 20LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return hash_get(*(_QWORD *)(a1 + 32), a2, 20LL);
}

original_code:
ITEM *tgt_v_find(TARGET_V * target, UCHAR * node_id)
{
 return hash_get(target->hash, node_id, 20);
}

canonical_original_code:
struct obj_item *tgt_v_find(struct TARGET_V *target, unsigned char *node_id)
{
 return hash_get(target->hash, node_id, 20);
}

variable_types: struct TARGET_V { unsigned char target[20]; struct obj_list { struct obj_item *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; } *

user_defined_types: struct BUCKET { struct PAIR *pairs; long size; }


decompiled_code:
// attributes: thunk
__int64 __fastcall node_v_free(__int64 a1)
{
return myfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return myfree(a1);
}

original_code:
void node_v_free(NODE_V * node_v)
{
 myfree(node_v);
}

canonical_original_code:
void node_v_free(struct NODE_V *node_v)
{
 myfree(node_v);
}


decompiled_code:
__int64 __fastcall tgt_v_del(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = list_value(a2);
hash_del(*(_QWORD *)(a1 + 32), v2, 20LL);
list_del(*(_QWORD *)(a1 + 24), a2);
return node_v_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = list_value(a2);
hash_del(*(_QWORD *)(a1 + 32), v2, 20LL);
list_del(*(_QWORD *)(a1 + 24), a2);
return func10(v2);
}

original_code:
void tgt_v_del(TARGET_V * target, ITEM * i)
{
 NODE_V *node_v = list_value(i);
 hash_del(target->hash, node_v->id, 20);
 list_del(target->list, i);
 node_v_free(node_v);
}

canonical_original_code:
void tgt_v_del(struct TARGET_V *target, struct obj_item *i)
{
 struct NODE_V *node_v = list_value(i);
 hash_del(target->hash, node_v->id, 20);
 list_del(target->list, i);
 node_v_free(node_v);
}

variable_types:
i
struct obj_item *

user_defined_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; }

user_defined_types: struct PAIR { unsigned char *key; long size; void *value; }


decompiled_code:
__int64 __fastcall tgt_v_expire(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdi

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v4 = result;
do
{
while ( 1 )
{
v5 = v4;
v6 = v4;
v4 = list_next(v4);
result = list_value(v6);
if ( *(_QWORD *)(result + 32) < a2 )
break;
if ( !v4 )
return result;
}
result = tgt_v_del(a1, v5);
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdi

result = list_start(*(_QWORD *)(a1 + 24));
if ( result )
{
v4 = result;
do
{
while ( 1 )
{
v5 = v4;
v6 = v4;
v4 = list_next(v4);
result = list_value(v6);
if ( *(_QWORD *)(result + 32) < a2 )
break;
if ( !v4 )
return result;
}
result = func11(a1, v5);
}
while ( v4 );
}
return result;
}

original_code:
void tgt_v_expire(TARGET_V * target, time_t now)
{
 ITEM *i = ((void *)0);
 ITEM *n = ((void *)0);
 NODE_V *node = ((void *)0);
 i = list_start(target->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  node = list_value(i);
  if (now > node->eol) {
   tgt_v_del(target, i);
  }
  i = n;
 }
}

canonical_original_code:
void tgt_v_expire(struct TARGET_V *target, long now)
{
 struct obj_item *i = ((void *)0);
 struct obj_item *n = ((void *)0);
 struct NODE_V *node = ((void *)0);
 i = list_start(target->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  node = list_value(i);
  if (now > node->eol) {
   tgt_v_del(target, i);
  }
  i = n;
 }
}

variable_types: now long


decompiled_code:
__int64 __fastcall val_expire(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rbp

result = list_start(**((_QWORD **)main + 11));
if ( result )
{
v3 = result;
do
{
while ( 1 )
{
v4 = v3;
v5 = v3;
v3 = list_next(v3);
v6 = list_value(v5);
tgt_v_expire(v6, a1);
result = list_size(*(_QWORD *)(v6 + 24));
if ( !result )
break;
if ( !v3 )
return result;
}
result = val_del(v4);
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rbp

result = list_start(**((_QWORD **)main + 11));
if ( result )
{
v3 = result;
do
{
while ( 1 )
{
v4 = v3;
v5 = v3;
v3 = list_next(v3);
v6 = list_value(v5);
func12(v6, a1);
result = list_size(*(_QWORD *)(v6 + 24));
if ( !result )
break;
if ( !v3 )
return result;
}
result = func4(v4);
}
while ( v3 );
}
return result;
}

original_code:
void val_expire(time_t now)
{
 ITEM *i = ((void *)0), *n = ((void *)0);
 TARGET_V *target = ((void *)0);
 int index = 0;
 i = list_start(_main->value->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  target = list_value(i);
  tgt_v_expire(target, now);
  if (list_size(target->list) == 0) {
   val_del(i);
  }
  i = n;
  index++;
 }
}

canonical_original_code:
void val_expire(long now)
{
 struct obj_item *i = ((void *)0); struct obj_item *n = ((void *)0);
 struct TARGET_V *target = ((void *)0);
 int index = 0;
 i = list_start(_main->value->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  target = list_value(i);
  tgt_v_expire(target, now);
  if (list_size(target->list) == 0) {
   val_del(i);
  }
  i = n;
  index++;
 }
}

variable_types: index int


original_code:
void node_v_update(NODE_V * node_v, UCHAR * node_id, IP * from, int port)
{
 UCHAR *p = node_v->pair;
 ip_merge_port_to_sin(from, port);
 ip_sin_to_tuple(from, p);
 memcpy(node_v->id, node_id, 20);
 time_add_30_min(&node_v->eol);
}

canonical_original_code:
void node_v_update(struct NODE_V *node_v, unsigned char *node_id, struct sockaddr_in *from, int port)
{
 unsigned char *p = node_v->pair;
 ip_merge_port_to_sin(from, port);
 ip_sin_to_tuple(from, p);
 memcpy(node_v->id, node_id, 20);
 time_add_30_min(&node_v->eol);
}

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: port int


decompiled_code:
__int64 __fastcall tgt_v_put(__int64 a1, const __m128i *a2, __int64 a3, unsigned __int16 a4)
{
__m128i *v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // rax

v4 = node_v_init(a2, a3, a4);
v5 = list_start(*(_QWORD *)(a1 + 24));
v6 = list_ins(*(_QWORD *)(a1 + 24), v5, v4);
hash_put(*(_QWORD *)(a1 + 32), v4, 20LL, v6);
result = list_size(*(_QWORD *)(a1 + 24));
if ( result > 10 )
{
v8 = list_stop(*(_QWORD *)(a1 + 24));
result = tgt_v_del(a1, v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const __m128i *a2, __int64 a3, unsigned __int16 a4)
{
__m128i *v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // rax

v4 = node_v_init(a2, a3, a4);
v5 = list_start(*(_QWORD *)(a1 + 24));
v6 = list_ins(*(_QWORD *)(a1 + 24), v5, v4);
hash_put(*(_QWORD *)(a1 + 32), v4, 20LL, v6);
result = list_size(*(_QWORD *)(a1 + 24));
if ( result > 10 )
{
v8 = list_stop(*(_QWORD *)(a1 + 24));
result = func11(a1, v8);
}
return result;
}

original_code:
void tgt_v_put(TARGET_V * target, UCHAR * node_id, IP * from, int port)
{
 NODE_V *node = ((void *)0);
 ITEM *i = ((void *)0);
 ITEM *s = ((void *)0);
 node = node_v_init(node_id, from, port);
 s = list_start(target->list);
 i = list_ins(target->list, s, node);
 hash_put(target->hash, node->id, 20, i);
 if (list_size(target->list) > 10) {
  s = list_stop(target->list);
  tgt_v_del(target, s);
 }
}

canonical_original_code:
void tgt_v_put(struct TARGET_V *target, unsigned char *node_id, struct sockaddr_in *from, int port)
{
 struct NODE_V *node = ((void *)0);
 struct obj_item *i = ((void *)0);
 struct obj_item *s = ((void *)0);
 node = node_v_init(node_id, from, port);
 s = list_start(target->list);
 i = list_ins(target->list, s, node);
 hash_put(target->hash, node->id, 20, i);
 if (list_size(target->list) > 10) {
  s = list_stop(target->list);
  tgt_v_del(target, s);
 }
}


original_code:
void tgt_v_update(TARGET_V * target, UCHAR * node_id, IP * from, int port)
{
 NODE_V *node = ((void *)0);
 ITEM *i = ((void *)0);
 if ((i = tgt_v_find(target, node_id)) == ((void *)0)) {
  tgt_v_put(target, node_id, from, port);
 } else {
  node = list_value(i);
  node_v_update(node, node_id, from, port);
  list_del(target->list, i);
  i = list_ins(target->list, list_start(target->list), node);
  hash_put(target->hash, node->id, 20, i);
 }
}

canonical_original_code:
void tgt_v_update(struct TARGET_V *target, unsigned char *node_id, struct sockaddr_in *from, int port)
{
 struct NODE_V *node = ((void *)0);
 struct obj_item *i = ((void *)0);
 if ((i = tgt_v_find(target, node_id)) == ((void *)0)) {
  tgt_v_put(target, node_id, from, port);
 } else {
  node = list_value(i);
  node_v_update(node, node_id, from, port);
  list_del(target->list, i);
  i = list_ins(target->list, list_start(target->list), node);
  hash_put(target->hash, node->id, 20, i);
 }
}


decompiled_code:
__int64 __fastcall val_put(const __m128i *a1, const __m128i *a2, unsigned __int16 a3, __int64 a4)
{
__int64 v7; // rdi
__int64 result; // rax

v7 = val_find((__int64)a1);
if ( v7 || (result = (__int64)val_ins_sort(a1), (v7 = result) != 0) )
result = tgt_v_update(v7, a2, a4, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(const __m128i *a1, const __m128i *a2, unsigned __int16 a3, __int64 a4)
{
__int64 v7; // rdi
__int64 result; // rax

v7 = func1((__int64)a1);
if ( v7 || (result = (__int64)val_ins_sort(a1), (v7 = result) != 0) )
result = func16(v7, a2, a4, a3);
return result;
}

original_code:
void val_put(UCHAR * target_id, UCHAR * node_id, int port, IP * from)
{
 TARGET_V *target = val_find(target_id);
 if (target == ((void *)0)) {
  target = val_ins_sort(target_id);
 }
 if (target == ((void *)0)) {
  return;
 }
 tgt_v_update(target, node_id, from, port);
}

canonical_original_code:
void val_put(unsigned char *target_id, unsigned char *node_id, int port, struct sockaddr_in *from)
{
 struct TARGET_V *target = val_find(target_id);
 if (target == ((void *)0)) {
  target = val_ins_sort(target_id);
 }
 if (target == ((void *)0)) {
  return;
 }
 tgt_v_update(target, node_id, from, port);
}


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

result = myalloc(36LL);
*(_QWORD *)(result + 16) = 0xFFFFFFFF00000010LL;
*(_QWORD *)(result + 28) = 0x100000000LL;
*(_OWORD *)result = 0LL;
return result;
}

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

result = myalloc(36LL);
*(_QWORD *)(result + 16) = 0xFFFFFFFF00000010LL;
*(_QWORD *)(result + 28) = 0x100000000LL;
*(_OWORD *)result = 0LL;
return result;
}

original_code:
UDP *udp_init(void)
{
 UDP *udp = (UDP *) myalloc(sizeof(UDP));
 udp->s_addrlen = sizeof(IP);
 memset((char *)&udp->s_addr, '\0', udp->s_addrlen);
 udp->sockfd = -1;
 udp->multicast = 0;
 udp->type = udp_p2p_worker;
 return udp;
}

canonical_original_code:
struct obj_udp *udp_init()
{
 struct obj_udp *udp = (UDP *) myalloc(sizeof(UDP));
 udp->s_addrlen = sizeof(IP);
 memset((char *)&udp->s_addr, '\0', udp->s_addrlen);
 udp->sockfd = -1;
 udp->multicast = 0;
 udp->type = udp_p2p_worker;
 return udp;
}

variable_types: struct obj_udp { 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]; } s_addr; unsigned int s_addrlen; int sockfd; int epollfd; int multicast; int type; } *

user_defined_types: struct obj_udp { struct sockaddr_in s_addr; unsigned int s_addrlen; int sockfd; int epollfd; int multicast; int type; }


decompiled_code:
// attributes: thunk
__int64 udp_free()
{
return myfree();
}

canonical_decompiled_code:
__int64 func3()
{
return myfree();
}

original_code:
void udp_free(UDP * udp)
{
 myfree(udp);
}

canonical_original_code:
void udp_free(struct obj_udp *udp)
{
 myfree(udp);
}


decompiled_code:
int __fastcall udp_event(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
int v3; // edi
int result; // eax
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v1 = epoll_create(23);
*(_DWORD *)(a1 + 24) = v1;
if ( v1 == -1 )
fail("epoll_create() failed");
v2 = *(_DWORD *)(a1 + 20);
v3 = *(_DWORD *)(a1 + 24);
event.events = -1073741823;
event.data.u64 = v2;
result = epoll_ctl(v3, 1, v2, &event);
if ( result == -1 )
result = fail("udp_event: epoll_ctl() failed");
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
int v3; // edi
int result; // eax
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v1 = epoll_create(23);
*(_DWORD *)(a1 + 24) = v1;
if ( v1 == -1 )
fail("epoll_create() failed");
v2 = *(_DWORD *)(a1 + 20);
v3 = *(_DWORD *)(a1 + 24);
event.events = -1073741823;
event.data.u64 = v2;
result = epoll_ctl(v3, 1, v2, &event);
if ( result == -1 )
result = fail("udp_event: epoll_ctl() failed");
return result;
}

original_code:
void udp_event(UDP * udp)
{
 struct epoll_event ev;
 udp->epollfd = epoll_create(23);
 if (udp->epollfd == -1) {
  fail("epoll_create() failed");
 }
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET | EPOLLONESHOT;
 ev.data.fd = udp->sockfd;
 if (epoll_ctl(udp->epollfd, 1, udp->sockfd, &ev) == -1) {
  fail("udp_event: epoll_ctl() failed");
 }
}

canonical_original_code:
void udp_event(struct obj_udp *udp)
{
 struct epoll_event ev;
 udp->epollfd = epoll_create(23);
 if (udp->epollfd == -1) {
  fail("epoll_create() failed");
 }
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET | EPOLLONESHOT;
 ev.data.fd = udp->sockfd;
 if (epoll_ctl(udp->epollfd, 1, udp->sockfd, &ev) == -1) {
  fail("udp_event: epoll_ctl() failed");
 }
}

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }


decompiled_code:
void __fastcall __noreturn udp_client(__int64 a1)
{
if ( *(_DWORD *)(a1 + 32) == 1 )
p2p_bootstrap();
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(__int64 a1)
{
if ( *(_DWORD *)(a1 + 32) == 1 )
p2p_bootstrap();
pthread_exit(0LL);
}

original_code:
void *udp_client(void *arg)
{
 UDP *udp = arg;
 if (udp->type != udp_p2p_worker) {
  pthread_exit(((void *)0));
 }
 p2p_bootstrap();
 pthread_exit(((void *)0));
}

canonical_original_code:
void *udp_client(void *arg)
{
 struct obj_udp *udp = arg;
 if (udp->type != udp_p2p_worker) {
  pthread_exit(((void *)0));
 }
 p2p_bootstrap();
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

return_type: void *


decompiled_code:
int __fastcall udp_rearm(__int64 a1, unsigned int a2)
{
int v2; // edi
int result; // eax
int *v4; // rax
char *v5; // rax
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v2 = *(_DWORD *)(a1 + 24);
event.data.u64 = a2;
event.events = -1073741823;
result = epoll_ctl(v2, 3, a2, &event);
if ( result == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
result = fail("udp_rearm: epoll_ctl() failed / %s", v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, unsigned int a2)
{
int v2; // edi
int result; // eax
int *v4; // rax
char *v5; // rax
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v2 = *(_DWORD *)(a1 + 24);
event.data.u64 = a2;
event.events = -1073741823;
result = epoll_ctl(v2, 3, a2, &event);
if ( result == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
result = fail("udp_rearm: epoll_ctl() failed / %s", v5);
}
return result;
}

original_code:
void udp_rearm(UDP * udp, int sockfd)
{
 struct epoll_event ev;
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = EPOLLET | EPOLLIN | EPOLLONESHOT;
 ev.data.fd = sockfd;
 if (epoll_ctl(udp->epollfd, 3, sockfd, &ev) == -1) {
  fail("udp_rearm: epoll_ctl() failed / %s", strerror((*__errno_location ())));
 }
}

canonical_original_code:
void udp_rearm(struct obj_udp *udp, int sockfd)
{
 struct epoll_event ev;
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = EPOLLET | EPOLLIN | EPOLLONESHOT;
 ev.data.fd = sockfd;
 if (epoll_ctl(udp->epollfd, 3, sockfd, &ev) == -1) {
  fail("udp_rearm: epoll_ctl() failed / %s", strerror((*__errno_location ())));
 }
}

variable_types: sockfd int

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }


decompiled_code:
__int64 __fastcall udp_nonblocking(int fd)
{
int v1; // eax
int v2; // er8
__int64 result; // rax

v1 = fcntl(fd, 3);
if ( v1 < 0 || (BYTE1(v1) |= 8u, v2 = fcntl(fd, 4, (unsigned int)v1), result = 1LL, v2 < 0) )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd)
{
int v1; // eax
int v2; // er8
__int64 result; // rax

v1 = fcntl(fd, 3);
if ( v1 < 0 || (BYTE1(v1) |= 8u, v2 = fcntl(fd, 4, (unsigned int)v1), result = 1LL, v2 < 0) )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int udp_nonblocking(int sock)
{
 int opts = fcntl(sock, 3);
 if (opts < 0) {
  return -1;
 }
 opts = opts | 04000;
 if (fcntl(sock, 4, opts) < 0) {
  return -1;
 }
 return 1;
}

variable_types: sock int

variable_types: opts int


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

if ( *(_DWORD *)(a1 + 32) == 1 )
{
mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
p2p_cron();
result = mutex_unblock(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
}
return result;
}

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

if ( *(_DWORD *)(a1 + 32) == 1 )
{
mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
p2p_cron();
result = mutex_unblock(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
}
return result;
}

original_code:
void udp_cron(UDP * udp)
{
 if (udp->type != udp_p2p_worker) {
  return;
 }
 mutex_block(_main->work->mutex);
 p2p_cron();
 mutex_unblock(_main->work->mutex);
}

canonical_original_code:
void udp_cron(struct obj_udp *udp)
{
 if (udp->type != udp_p2p_worker) {
  return;
 }
 mutex_block(_main->work->mutex);
 p2p_cron();
 mutex_unblock(_main->work->mutex);
}