decompiled_code:
char *mime_load()
{
mime_add("___", "application/octet-stream; charset=binary");
mime_add("7z", "application/x-7z-compressed; charset=binary");
mime_add("asf", "video/x-ms-asf; charset=binary");
mime_add("asx", "video/x-ms-asf; charset=binary");
mime_add("avi", "video/x-msvideo; charset=binary");
mime_add("bz2", "application/x-bzip2; charset=binary");
mime_add("css", "text/css");
mime_add("deb", "application/x-debian-package; charset=binary");
mime_add("divx", "video/x-msvideo; charset=binary");
mime_add("dsc", "text/plain; charset=utf-8");
mime_add("gif", "image/gif; charset=binary");
mime_add("gpg", "application/pgp-signature; charset=utf-8");
mime_add("gz", "application/x-gzip; charset=binary");
mime_add("html", "text/html; charset=utf-8");
mime_add("ico", "image/x-ico; charset=binary");
mime_add("iso", "application/x-iso9660-image; charset=binary");
mime_add("js", "application/x-javascript");
mime_add("jpg", "image/jpeg");
mime_add("jpeg", "image/jpeg");
mime_add("m3u", "text/plain; charset=utf-8");
mime_add("m4v", "video/mp4; charset=binary");
mime_add("mkv", "video/x-matroska; charset=binary");
mime_add("mov", "video/quicktime; charset=binary");
mime_add("mp3", "audio/mpeg; charset=binary");
mime_add("mp4", "video/mp4; charset=binary");
mime_add("mpeg", "video/mpeg; charset=binary");
mime_add("mpg", "video/mpeg; charset=binary");
mime_add("nfo", "text/plain; charset=utf-8");
mime_add("ogg", "application/ogg; charset=binary");
mime_add("ogm", "application/ogg; charset=binary");
mime_add("pdf", "application/pdf; charset=binary");
mime_add("pl", "text/x-perl; charset=utf-8");
mime_add("png", "image/png; charset=binary");
mime_add("rar", "application/x-rar; charset=binary");
mime_add("rss", "application/rss+xml; charset=utf-8");
mime_add("txt", "text/plain; charset=utf-8");
mime_add("wmv", "video/x-ms-asf; charset=binary");
mime_add("woff", "application/font-woff");
mime_add("xml", "application/xml; charset=utf-8");
mime_add("zip", "application/zip; charset=binary");
return mime_add("zsync", "application/octet-stream");
}

canonical_decompiled_code:
char *func3()
{
func2("___", "application/octet-stream; charset=binary");
func2("7z", "application/x-7z-compressed; charset=binary");
func2("asf", "video/x-ms-asf; charset=binary");
func2("asx", "video/x-ms-asf; charset=binary");
func2("avi", "video/x-msvideo; charset=binary");
func2("bz2", "application/x-bzip2; charset=binary");
func2("css", "text/css");
func2("deb", "application/x-debian-package; charset=binary");
func2("divx", "video/x-msvideo; charset=binary");
func2("dsc", "text/plain; charset=utf-8");
func2("gif", "image/gif; charset=binary");
func2("gpg", "application/pgp-signature; charset=utf-8");
func2("gz", "application/x-gzip; charset=binary");
func2("html", "text/html; charset=utf-8");
func2("ico", "image/x-ico; charset=binary");
func2("iso", "application/x-iso9660-image; charset=binary");
func2("js", "application/x-javascript");
func2("jpg", "image/jpeg");
func2("jpeg", "image/jpeg");
func2("m3u", "text/plain; charset=utf-8");
func2("m4v", "video/mp4; charset=binary");
func2("mkv", "video/x-matroska; charset=binary");
func2("mov", "video/quicktime; charset=binary");
func2("mp3", "audio/mpeg; charset=binary");
func2("mp4", "video/mp4; charset=binary");
func2("mpeg", "video/mpeg; charset=binary");
func2("mpg", "video/mpeg; charset=binary");
func2("nfo", "text/plain; charset=utf-8");
func2("ogg", "application/ogg; charset=binary");
func2("ogm", "application/ogg; charset=binary");
func2("pdf", "application/pdf; charset=binary");
func2("pl", "text/x-perl; charset=utf-8");
func2("png", "image/png; charset=binary");
func2("rar", "application/x-rar; charset=binary");
func2("rss", "application/rss+xml; charset=utf-8");
func2("txt", "text/plain; charset=utf-8");
func2("wmv", "video/x-ms-asf; charset=binary");
func2("woff", "application/font-woff");
func2("xml", "application/xml; charset=utf-8");
func2("zip", "application/zip; charset=binary");
return func2("zsync", "application/octet-stream");
}

original_code:
void mime_load(void)
{
 mime_add("___", "application/octet-stream; charset=binary");
 mime_add("7z", "application/x-7z-compressed; charset=binary");
 mime_add("asf", "video/x-ms-asf; charset=binary");
 mime_add("asx", "video/x-ms-asf; charset=binary");
 mime_add("avi", "video/x-msvideo; charset=binary");
 mime_add("bz2", "application/x-bzip2; charset=binary");
 mime_add("css", "text/css");
 mime_add("deb", "application/x-debian-package; charset=binary");
 mime_add("divx", "video/x-msvideo; charset=binary");
 mime_add("dsc", "text/plain; charset=utf-8");
 mime_add("gif", "image/gif; charset=binary");
 mime_add("gpg", "application/pgp-signature; charset=utf-8");
 mime_add("gz", "application/x-gzip; charset=binary");
 mime_add("html", "text/html; charset=utf-8");
 mime_add("ico", "image/x-ico; charset=binary");
 mime_add("iso", "application/x-iso9660-image; charset=binary");
 mime_add("js", "application/x-javascript");
 mime_add("jpg", "image/jpeg");
 mime_add("jpeg", "image/jpeg");
 mime_add("m3u", "text/plain; charset=utf-8");
 mime_add("m4v", "video/mp4; charset=binary");
 mime_add("mkv", "video/x-matroska; charset=binary");
 mime_add("mov", "video/quicktime; charset=binary");
 mime_add("mp3", "audio/mpeg; charset=binary");
 mime_add("mp4", "video/mp4; charset=binary");
 mime_add("mpeg", "video/mpeg; charset=binary");
 mime_add("mpg", "video/mpeg; charset=binary");
 mime_add("nfo", "text/plain; charset=utf-8");
 mime_add("ogg", "application/ogg; charset=binary");
 mime_add("ogm", "application/ogg; charset=binary");
 mime_add("pdf", "application/pdf; charset=binary");
 mime_add("pl", "text/x-perl; charset=utf-8");
 mime_add("png", "image/png; charset=binary");
 mime_add("rar", "application/x-rar; charset=binary");
 mime_add("rss", "application/rss+xml; charset=utf-8");
 mime_add("txt", "text/plain; charset=utf-8");
 mime_add("wmv", "video/x-ms-asf; charset=binary");
 mime_add("woff", "application/font-woff");
 mime_add("xml", "application/xml; charset=utf-8");
 mime_add("zip", "application/zip; charset=binary");
 mime_add("zsync", "application/octet-stream");
}

canonical_original_code:
void mime_load()
{
 mime_add("___", "application/octet-stream; charset=binary");
 mime_add("7z", "application/x-7z-compressed; charset=binary");
 mime_add("asf", "video/x-ms-asf; charset=binary");
 mime_add("asx", "video/x-ms-asf; charset=binary");
 mime_add("avi", "video/x-msvideo; charset=binary");
 mime_add("bz2", "application/x-bzip2; charset=binary");
 mime_add("css", "text/css");
 mime_add("deb", "application/x-debian-package; charset=binary");
 mime_add("divx", "video/x-msvideo; charset=binary");
 mime_add("dsc", "text/plain; charset=utf-8");
 mime_add("gif", "image/gif; charset=binary");
 mime_add("gpg", "application/pgp-signature; charset=utf-8");
 mime_add("gz", "application/x-gzip; charset=binary");
 mime_add("html", "text/html; charset=utf-8");
 mime_add("ico", "image/x-ico; charset=binary");
 mime_add("iso", "application/x-iso9660-image; charset=binary");
 mime_add("js", "application/x-javascript");
 mime_add("jpg", "image/jpeg");
 mime_add("jpeg", "image/jpeg");
 mime_add("m3u", "text/plain; charset=utf-8");
 mime_add("m4v", "video/mp4; charset=binary");
 mime_add("mkv", "video/x-matroska; charset=binary");
 mime_add("mov", "video/quicktime; charset=binary");
 mime_add("mp3", "audio/mpeg; charset=binary");
 mime_add("mp4", "video/mp4; charset=binary");
 mime_add("mpeg", "video/mpeg; charset=binary");
 mime_add("mpg", "video/mpeg; charset=binary");
 mime_add("nfo", "text/plain; charset=utf-8");
 mime_add("ogg", "application/ogg; charset=binary");
 mime_add("ogm", "application/ogg; charset=binary");
 mime_add("pdf", "application/pdf; charset=binary");
 mime_add("pl", "text/x-perl; charset=utf-8");
 mime_add("png", "image/png; charset=binary");
 mime_add("rar", "application/x-rar; charset=binary");
 mime_add("rss", "application/rss+xml; charset=utf-8");
 mime_add("txt", "text/plain; charset=utf-8");
 mime_add("wmv", "video/x-ms-asf; charset=binary");
 mime_add("woff", "application/font-woff");
 mime_add("xml", "application/xml; charset=utf-8");
 mime_add("zip", "application/zip; charset=binary");
 mime_add("zsync", "application/octet-stream");
}


repo: torrentkino/torrentkino

decompiled_code:
__int64 mime_hash()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rbp
const char **i; // rbp
const char *v4; // r12
size_t v5; // rax

result = list_size(**((_QWORD **)main + 5));
if ( result > 0 )
{
v1 = list_size(**((_QWORD **)main + 5));
v2 = *((_QWORD *)main + 5);
*(_QWORD *)(v2 + 8) = hash_init(v1 + 10);
result = list_start(**((_QWORD **)main + 5));
for ( i = (const char **)result; result; i = (const char **)result )
{
v4 = *i;
v5 = strlen(*i);
hash_put(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v4, v5, v4 + 9);
result = list_next(i);
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rbp
const char **i; // rbp
const char *v4; // r12
size_t v5; // rax

result = list_size(**((_QWORD **)main + 5));
if ( result > 0 )
{
v1 = list_size(**((_QWORD **)main + 5));
v2 = *((_QWORD *)main + 5);
*(_QWORD *)(v2 + 8) = hash_init(v1 + 10);
result = list_start(**((_QWORD **)main + 5));
for ( i = (const char **)result; result; i = (const char **)result )
{
v4 = *i;
v5 = strlen(*i);
hash_put(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v4, v5, v4 + 9);
result = list_next(i);
}
}
return result;
}

original_code:
void mime_hash(void)
{
 ITEM *item = ((void *)0);
 struct obj_mime *tuple = ((void *)0);
 if (list_size(_main->mime->list) < 1) {
  return;
 }
 _main->mime->hash = hash_init(list_size(_main->mime->list) + 10);
 item = list_start(_main->mime->list);
 while (item != ((void *)0)) {
  tuple = item->val;
  hash_put(_main->mime->hash, (UCHAR *) tuple->key,
    strlen(tuple->key), tuple->val);
  item = list_next(item);
 }
}

canonical_original_code:
void mime_hash()
{
 struct obj_item *item = ((void *)0);
 struct obj_mime *tuple = ((void *)0);
 if (list_size(_main->mime->list) < 1) {
  return;
 }
 _main->mime->hash = hash_init(list_size(_main->mime->list) + 10);
 item = list_start(_main->mime->list);
 while (item != ((void *)0)) {
  tuple = item->val;
  hash_put(_main->mime->hash, (unsigned char *) tuple->key,
    strlen(tuple->key), tuple->val);
  item = list_next(item);
 }
}

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

variable_types: struct obj_mime { char key[-1]; char val[-1]; } *

return_type: void


decompiled_code:
char *__fastcall mime_extension(char *s)
{
int i; // ebx
char *v3; // rax

while ( 1 )
{
for ( i = 0; ; ++i )
{
v3 = strchr(s, 46);
if ( !v3 )
break;
s = v3 + 1;
}
if ( !i )
break;
if ( !(unsigned int)str_isNumber(s) )
{
if ( strlen(s) <= 5 )
return s;
return 0LL;
}
*(s - 1) = 0;
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func6(char *s)
{
int i; // ebx
char *v3; // rax

while ( 1 )
{
for ( i = 0; ; ++i )
{
v3 = strchr(s, 46);
if ( !v3 )
break;
s = v3 + 1;
}
if ( !i )
break;
if ( !(unsigned int)str_isNumber(s) )
{
if ( strlen(s) <= 5 )
return s;
return 0LL;
}
*(s - 1) = 0;
}
return 0LL;
}

original_code:
char *mime_extension(char *filename)
{
 char *key = filename;
 char *dot = filename;
 int i = 0;
 while ((dot = strchr(key, '.')) != ((void *)0)) {
  key = dot + 1;
  i++;
 }
 if (i == 0) {
  return ((void *)0);
 }
 if (str_isNumber(key)) {
  key--;
  *key = '\0';
  return mime_extension(filename);
 }
 if (strlen(key) > 5) {
  return ((void *)0);
 }
 return key;
}

variable_types:
filename
char *

variable_types:
key
char *

variable_types:
dot
char *

variable_types: i int

return_type: char *


decompiled_code:
__int64 __fastcall mime_find(const char *a1)
{
char *v1; // rax
char *v2; // rbp
size_t v3; // rax
__int64 result; // rax
size_t v5; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v6, 0x400uLL, "%s", a1);
v1 = mime_extension(v6);
if ( !v1
|| (v2 = v1, v3 = strlen(v1), (result = hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v2, v3)) == 0)
&& (mime_magic((__int64)a1, v2),
v5 = strlen(v2),
(result = hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v2, v5)) == 0) )
{
result = hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), "___", 3LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
char *v1; // rax
char *v2; // rbp
size_t v3; // rax
__int64 result; // rax
size_t v5; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v6, 0x400uLL, "%s", a1);
v1 = func6(v6);
if ( !v1
|| (v2 = v1, v3 = strlen(v1), (result = hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v2, v3)) == 0)
&& (func5((__int64)a1, v2),
v5 = strlen(v2),
(result = hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v2, v5)) == 0) )
{
result = hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), "___", 3LL);
}
return result;
}

original_code:
const char *mime_find(char *filename)
{
 char filecopy[1024];
 char *key = ((void *)0);
 char *mime = ((void *)0);
 snprintf(filecopy, 1024, "%s", filename);
 if ((key = mime_extension(filecopy)) == ((void *)0)) {
  return hash_get(_main->mime->hash, (UCHAR *) "___", 3);
 }
 if ((mime =
      hash_get(_main->mime->hash, (UCHAR *) key, strlen(key))) != ((void *)0)) {
  return mime;
 }
 mime_magic(filename, key);
 if ((mime =
      hash_get(_main->mime->hash, (UCHAR *) key, strlen(key))) != ((void *)0)) {
  return mime;
 }
 return hash_get(_main->mime->hash, (UCHAR *) "___", 3);
}

canonical_original_code:
char *mime_find(char *filename)
{
 char filecopy[1024];
 char *key = ((void *)0);
 char *mime = ((void *)0);
 snprintf(filecopy, 1024, "%s", filename);
 if ((key = mime_extension(filecopy)) == ((void *)0)) {
  return hash_get(_main->mime->hash, (unsigned char *) "___", 3);
 }
 if ((mime =
      hash_get(_main->mime->hash, (unsigned char *) key, strlen(key))) != ((void *)0)) {
  return mime;
 }
 mime_magic(filename, key);
 if ((mime =
      hash_get(_main->mime->hash, (unsigned char *) key, strlen(key))) != ((void *)0)) {
  return mime;
 }
 return hash_get(_main->mime->hash, (unsigned char *) "___", 3);
}

variable_types:
filecopy
char [1024]

variable_types:
mime
char *


original_code:
void hash_free(HASH * map)
{
 LONG i = 0;
 BUCKET *bucket = ((void *)0);
 if (map == ((void *)0)) {
  return;
 }
 bucket = map->buckets;
 for (i = 0; i < map->size; i++) {
  myfree(bucket->pairs);
  bucket++;
 }
 myfree(map->buckets);
 myfree(map);
 map = ((void *)0);
}

canonical_original_code:
void hash_free(struct HASH *map)
{
 long i = 0;
 struct BUCKET *bucket = ((void *)0);
 if (map == ((void *)0)) {
  return;
 }
 bucket = map->buckets;
 for (i = 0; i < map->size; i++) {
  myfree(bucket->pairs);
  bucket++;
 }
 myfree(map->buckets);
 myfree(map);
 map = ((void *)0);
}

variable_types: struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *

variable_types: i long

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

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


original_code:
PAIR *hash_getpair(BUCKET * bucket, UCHAR * key, LONG size)
{
 LONG i = 0;
 PAIR *pair = ((void *)0);
 if (bucket->size == 0) {
  return ((void *)0);
 }
 pair = bucket->pairs;
 for (i = 0; i < bucket->size; i++) {
  if (pair->size == size) {
   if (pair->key != ((void *)0) && pair->value != ((void *)0)) {
    if (memcmp(pair->key, key, size) == 0) {
     return pair;
    }
   }
  }
  pair++;
 }
 return ((void *)0);
}

canonical_original_code:
struct PAIR *hash_getpair(struct BUCKET *bucket, unsigned char *key, long size)
{
 long i = 0;
 struct PAIR *pair = ((void *)0);
 if (bucket->size == 0) {
  return ((void *)0);
 }
 pair = bucket->pairs;
 for (i = 0; i < bucket->size; i++) {
  if (pair->size == size) {
   if (pair->key != ((void *)0) && pair->value != ((void *)0)) {
    if (memcmp(pair->key, key, size) == 0) {
     return pair;
    }
   }
  }
  pair++;
 }
 return ((void *)0);
}

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

variable_types:
key
unsigned char *

variable_types: size long

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


original_code:
ULONG hash_this(UCHAR * key, LONG size)
{
 ULONG result = 5381;
 LONG i = 0;
 for (i = 0; i < size; i++) {
  result = ((result << 5) + result) + *(key++);
 }
 return result;
}

canonical_original_code:
unsigned long hash_this(unsigned char *key, long size)
{
 unsigned long result = 5381;
 long i = 0;
 for (i = 0; i < size; i++) {
  result = ((result << 5) + result) + *(key++);
 }
 return result;
}

variable_types:
result
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall hash_get(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int64 v3; // rax
_QWORD *v4; // rcx
const void *v5; // r9
size_t v6; // r10
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v3 = hash_this(a2, a3);
result = hash_getpair((__int64 *)(16 * (v3 % v4[1]) + *v4), v5, v6);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int64 v3; // rax
_QWORD *v4; // rcx
const void *v5; // r9
size_t v6; // r10
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v3 = func2(a2, a3);
result = func1((__int64 *)(16 * (v3 % v4[1]) + *v4), v5, v6);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
void *hash_get(const HASH * map, UCHAR * key, LONG size)
{
 LONG index = 0;
 BUCKET *bucket = ((void *)0);
 PAIR *pair = ((void *)0);
 if (map == ((void *)0) || key == ((void *)0)) {
  return ((void *)0);
 }
 index = hash_this(key, size) % map->size;
 bucket = &(map->buckets[index]);
 pair = hash_getpair(bucket, key, size);
 if (pair == ((void *)0)) {
  return ((void *)0);
 }
 return pair->value;
}

canonical_original_code:
void *hash_get(struct HASH *map, unsigned char *key, long size)
{
 long index = 0;
 struct BUCKET *bucket = ((void *)0);
 struct PAIR *pair = ((void *)0);
 if (map == ((void *)0) || key == ((void *)0)) {
  return ((void *)0);
 }
 index = hash_this(key, size) % map->size;
 bucket = &(map->buckets[index]);
 pair = hash_getpair(bucket, key, size);
 if (pair == ((void *)0)) {
  return ((void *)0);
 }
 return pair->value;
}

variable_types: index long

variable_types: struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *

return_type: void *


decompiled_code:
_BOOL8 __fastcall hash_exists(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
_BOOL8 result; // rax

if ( a1 )
result = hash_get(a1, a2, a3) != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
_BOOL8 result; // rax

if ( a1 )
result = func3(a1, a2, a3) != 0;
else
result = 0LL;
return result;
}

original_code:
int hash_exists(const HASH * map, UCHAR * key, LONG size)
{
 if (map == ((void *)0)) {
  return 0;
 }
 if (hash_get(map, key, size) != ((void *)0)) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int hash_exists(struct HASH *map, unsigned char *key, long size)
{
 if (map == ((void *)0)) {
  return 0;
 }
 if (hash_get(map, key, size) != ((void *)0)) {
  return 1;
 }
 return 0;
}

return_type: int

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


original_code:
int hash_put(HASH * map, UCHAR * key, LONG size, void *value)
{
 LONG index = 0;
 BUCKET *bucket = ((void *)0);
 PAIR *pair = ((void *)0);
 if (map == ((void *)0) || key == ((void *)0) || value == ((void *)0)) {
  return 0;
 }
 index = hash_this(key, size) % map->size;
 bucket = &(map->buckets[index]);
 if ((pair = hash_getpair(bucket, key, size)) != ((void *)0)) {
  pair->value = value;
  return 1;
 }
 if (bucket->size == 0) {
  bucket->pairs = myalloc(sizeof(PAIR));
  bucket->size = 1;
 } else if (bucket->size == 0x7fffffffffffffffL) {
  return 0;
 } else {
  bucket->pairs =
      myrealloc(bucket->pairs, (bucket->size + 1) * sizeof(PAIR));
  bucket->size++;
 }
 pair = &(bucket->pairs[bucket->size - 1]);
 pair->key = key;
 pair->size = size;
 pair->value = value;
 return 1;
}

canonical_original_code:
int hash_put(struct HASH *map, unsigned char *key, long size, void *value)
{
 long index = 0;
 struct BUCKET *bucket = ((void *)0);
 struct PAIR *pair = ((void *)0);
 if (map == ((void *)0) || key == ((void *)0) || value == ((void *)0)) {
  return 0;
 }
 index = hash_this(key, size) % map->size;
 bucket = &(map->buckets[index]);
 if ((pair = hash_getpair(bucket, key, size)) != ((void *)0)) {
  pair->value = value;
  return 1;
 }
 if (bucket->size == 0) {
  bucket->pairs = myalloc(sizeof(PAIR));
  bucket->size = 1;
 } else if (bucket->size == 0x7fffffffffffffffL) {
  return 0;
 } else {
  bucket->pairs =
      myrealloc(bucket->pairs, (bucket->size + 1) * sizeof(PAIR));
  bucket->size++;
 }
 pair = &(bucket->pairs[bucket->size - 1]);
 pair->key = key;
 pair->size = size;
 pair->value = value;
 return 1;
}

variable_types:
value
void *


original_code:
void hash_del(HASH * map, UCHAR * key, LONG size)
{
 BUCKET *bucket = ((void *)0);
 PAIR *thispair = ((void *)0);
 PAIR *oldpair = ((void *)0);
 PAIR *newpair = ((void *)0);
 PAIR *p_old = ((void *)0);
 PAIR *p_new = ((void *)0);
 LONG index = 0;
 LONG i = 0;
 if (map == ((void *)0) || key == ((void *)0)) {
  return;
 }
 index = hash_this(key, size) % map->size;
 bucket = &(map->buckets[index]);
 if ((thispair = hash_getpair(bucket, key, size)) == ((void *)0)) {
  return;
 }
 if (bucket->size == 1) {
  myfree(bucket->pairs);
  bucket->pairs = ((void *)0);
  bucket->size = 0;
 } else if (bucket->size > 1) {
  oldpair = bucket->pairs;
  newpair = myalloc((bucket->size - 1) * sizeof(PAIR));
  p_old = oldpair;
  p_new = newpair;
  for (i = 0; i < bucket->size; i++) {
   if (p_old != thispair) {
    memcpy(p_new++, p_old, sizeof(PAIR));
   }
   p_old++;
  }
  myfree(oldpair);
  bucket->pairs = newpair;
  bucket->size--;
 }
}

canonical_original_code:
void hash_del(struct HASH *map, unsigned char *key, long size)
{
 struct BUCKET *bucket = ((void *)0);
 struct PAIR *thispair = ((void *)0);
 struct PAIR *oldpair = ((void *)0);
 struct PAIR *newpair = ((void *)0);
 struct PAIR *p_old = ((void *)0);
 struct PAIR *p_new = ((void *)0);
 long index = 0;
 long i = 0;
 if (map == ((void *)0) || key == ((void *)0)) {
  return;
 }
 index = hash_this(key, size) % map->size;
 bucket = &(map->buckets[index]);
 if ((thispair = hash_getpair(bucket, key, size)) == ((void *)0)) {
  return;
 }
 if (bucket->size == 1) {
  myfree(bucket->pairs);
  bucket->pairs = ((void *)0);
  bucket->size = 0;
 } else if (bucket->size > 1) {
  oldpair = bucket->pairs;
  newpair = myalloc((bucket->size - 1) * sizeof(PAIR));
  p_old = oldpair;
  p_new = newpair;
  for (i = 0; i < bucket->size; i++) {
   if (p_old != thispair) {
    memcpy(p_new++, p_old, sizeof(PAIR));
   }
   p_old++;
  }
  myfree(oldpair);
  bucket->pairs = newpair;
  bucket->size--;
 }
}


decompiled_code:
__int64 work_stop()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rbp

pthread_attr_destroy((pthread_attr_t *)(*((_QWORD *)main + 3) + 24LL));
v0 = *((_QWORD *)main + 3);
if ( *(int *)v0 > 0 )
{
v1 = 0LL;
do
{
v2 = 8 * v1;
if ( pthread_join(**(_QWORD **)(*(_QWORD *)(v0 + 16) + 8 * v1), 0LL) )
fail("pthread_join() failed");
++v1;
myfree(*(_QWORD *)(*(_QWORD *)(*((_QWORD *)main + 3) + 16LL) + v2));
v0 = *((_QWORD *)main + 3);
}
while ( *(_DWORD *)v0 > (int)v1 );
}
return myfree(*(_QWORD *)(v0 + 16));
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rbp

pthread_attr_destroy((pthread_attr_t *)(*((_QWORD *)main + 3) + 24LL));
v0 = *((_QWORD *)main + 3);
if ( *(int *)v0 > 0 )
{
v1 = 0LL;
do
{
v2 = 8 * v1;
if ( pthread_join(**(_QWORD **)(*(_QWORD *)(v0 + 16) + 8 * v1), 0LL) )
fail("pthread_join() failed");
++v1;
myfree(*(_QWORD *)(*(_QWORD *)(*((_QWORD *)main + 3) + 16LL) + v2));
v0 = *((_QWORD *)main + 3);
}
while ( *(_DWORD *)v0 > (int)v1 );
}
return myfree(*(_QWORD *)(v0 + 16));
}

original_code:
void work_stop(void)
{
 int i = 0;
 pthread_attr_destroy(&_main->work->attr);
 for (i = 0; i < _main->work->number_of_threads; i++) {
  if (pthread_join(*_main->work->threads[i], ((void *)0)) != 0) {
   fail("pthread_join() failed");
  }
  myfree(_main->work->threads[i]);
 }
 myfree(_main->work->threads);
}

canonical_original_code:
void work_stop()
{
 int i = 0;
 pthread_attr_destroy(&_main->work->attr);
 for (i = 0; i < _main->work->number_of_threads; i++) {
  if (pthread_join(*_main->work->threads[i], ((void *)0)) != 0) {
   fail("pthread_join() failed");
  }
  myfree(_main->work->threads[i]);
 }
 myfree(_main->work->threads);
}


original_code:
LIST *bckt_init(void)
{
 BUCK *b = (BUCK *) myalloc(sizeof(BUCK));
 LIST *l = list_init();
 memset(b->id, '\0', 20);
 b->nodes = list_init();
 list_put(l, b);
 return l;
}

canonical_original_code:
struct obj_list *bckt_init()
{
 struct obj_neighboorhood_bucket *b = (BUCK *) myalloc(sizeof(BUCK));
 struct obj_list *l = list_init();
 memset(b->id, '\0', 20);
 b->nodes = list_init();
 list_put(l, b);
 return l;
}

variable_types: struct obj_neighboorhood_bucket { unsigned char id[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *nodes; } *

user_defined_types: struct obj_neighboorhood_bucket { unsigned char id[20]; struct obj_list *nodes; }

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


decompiled_code:
__int64 __fastcall bckt_free(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx

v1 = list_start();
if ( v1 )
{
v2 = v1;
do
{
v3 = list_value(v2);
list_clear(*(_QWORD *)(v3 + 24));
list_free(*(_QWORD *)(v3 + 24));
v2 = list_next(v2);
}
while ( v2 );
}
list_clear(a1);
return list_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx

v1 = list_start();
if ( v1 )
{
v2 = v1;
do
{
v3 = list_value(v2);
list_clear(*(_QWORD *)(v3 + 24));
list_free(*(_QWORD *)(v3 + 24));
v2 = list_next(v2);
}
while ( v2 );
}
list_clear(a1);
return list_free(a1);
}

original_code:
void bckt_free(LIST * thislist)
{
 ITEM *i = ((void *)0);
 BUCK *b = ((void *)0);
 i = list_start(thislist);
 while (i != ((void *)0)) {
  b = list_value(i);
  list_clear(b->nodes);
  list_free(b->nodes);
  i = list_next(i);
 }
 list_clear(thislist);
 list_free(thislist);
}

canonical_original_code:
void bckt_free(struct obj_list *thislist)
{
 struct obj_item *i = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 i = list_start(thislist);
 while (i != ((void *)0)) {
  b = list_value(i);
  list_clear(b->nodes);
  list_free(b->nodes);
  i = list_next(i);
 }
 list_clear(thislist);
 list_free(thislist);
}

variable_types: struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *


decompiled_code:
__int64 __fastcall bckt_find_best_match(__int64 a1, const void *a2)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax
const void *v6; // rsi

v3 = list_start();
if ( !*(_QWORD *)(v3 + 8) )
return list_stop(a1);
v4 = v3;
while ( 1 )
{
v5 = list_next(v4);
v6 = (const void *)list_value(v5);
if ( memcmp(a2, v6, 0x14uLL) < 0 )
break;
v4 = list_next(v4);
if ( !*(_QWORD *)(v4 + 8) )
return list_stop(a1);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax
const void *v6; // rsi

v3 = list_start();
if ( !*(_QWORD *)(v3 + 8) )
return list_stop(a1);
v4 = v3;
while ( 1 )
{
v5 = list_next(v4);
v6 = (const void *)list_value(v5);
if ( memcmp(a2, v6, 0x14uLL) < 0 )
break;
v4 = list_next(v4);
if ( !*(_QWORD *)(v4 + 8) )
return list_stop(a1);
}
return v4;
}

original_code:
ITEM *bckt_find_best_match(LIST * thislist, const UCHAR * id)
{
 ITEM *item = ((void *)0);
 BUCK *b = ((void *)0);
 item = list_start(thislist);
 while (item->next != ((void *)0)) {
  b = list_value(list_next(item));
  if (memcmp(id, b->id, 20) < 0) {
   return item;
  }
  item = list_next(item);
 }
 return list_stop(thislist);
}

canonical_original_code:
struct obj_item *bckt_find_best_match(struct obj_list *thislist, unsigned char *id)
{
 struct obj_item *item = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 item = list_start(thislist);
 while (item->next != ((void *)0)) {
  b = list_value(list_next(item));
  if (memcmp(id, b->id, 20) < 0) {
   return item;
  }
  item = list_next(item);
 }
 return list_stop(thislist);
}

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

variable_types:
id
unsigned char *

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


decompiled_code:
__int64 __fastcall bckt_find_any_match(__int64 a1, const void *a2)
{
__int64 v2; // rbp

v2 = bckt_find_best_match(a1, a2);
if ( **(_QWORD **)(list_value(v2) + 24) )
return v2;
while ( v2 )
{
if ( **(_QWORD **)(list_value(v2) + 24) )
return v2;
v2 = list_prev(v2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const void *a2)
{
__int64 v2; // rbp

v2 = func2(a1, a2);
if ( **(_QWORD **)(list_value(v2) + 24) )
return v2;
while ( v2 )
{
if ( **(_QWORD **)(list_value(v2) + 24) )
return v2;
v2 = list_prev(v2);
}
return 0LL;
}

original_code:
ITEM *bckt_find_any_match(LIST * thislist, const UCHAR * id)
{
 ITEM *i = ((void *)0);
 BUCK *b = ((void *)0);
 i = bckt_find_best_match(thislist, id);
 b = list_value(i);
 if (b->nodes->item != ((void *)0)) {
  return i;
 }
 while (i != ((void *)0)) {
  b = list_value(i);
  if (b->nodes->item != ((void *)0)) {
   return i;
  }
  i = list_prev(i);
 }
 return ((void *)0);
}

canonical_original_code:
struct obj_item *bckt_find_any_match(struct obj_list *thislist, unsigned char *id)
{
 struct obj_item *i = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 i = bckt_find_best_match(thislist, id);
 b = list_value(i);
 if (b->nodes->item != ((void *)0)) {
  return i;
 }
 while (i != ((void *)0)) {
  b = list_value(i);
  if (b->nodes->item != ((void *)0)) {
   return i;
  }
  i = list_prev(i);
 }
 return ((void *)0);
}

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


decompiled_code:
__int64 __fastcall bckt_find_node(__int64 a1, const void *a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax

v2 = bckt_find_best_match(a1, a2);
if ( !v2 )
return 0LL;
v3 = list_value(v2);
v4 = list_start(*(_QWORD *)(v3 + 24));
if ( !v4 )
return 0LL;
while ( 1 )
{
v5 = list_value(v4);
if ( (unsigned int)node_equal(v5, a2) )
break;
v4 = list_next(v4);
if ( !v4 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const void *a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax

v2 = func2(a1, a2);
if ( !v2 )
return 0LL;
v3 = list_value(v2);
v4 = list_start(*(_QWORD *)(v3 + 24));
if ( !v4 )
return 0LL;
while ( 1 )
{
v5 = list_value(v4);
if ( (unsigned int)node_equal(v5, a2) )
break;
v4 = list_next(v4);
if ( !v4 )
return 0LL;
}
return v4;
}

original_code:
ITEM *bckt_find_node(LIST * thislist, const UCHAR * id)
{
 ITEM *item_b = ((void *)0);
 ITEM *item_n = ((void *)0);
 BUCK *b = ((void *)0);
 LIST *list_n = ((void *)0);
 UDP_NODE *n = ((void *)0);
 if ((item_b = bckt_find_best_match(thislist, id)) == ((void *)0)) {
  return ((void *)0);
 }
 b = list_value(item_b);
 list_n = b->nodes;
 item_n = list_start(list_n);
 while (item_n != ((void *)0)) {
  n = list_value(item_n);
  if (node_equal(n->id, id)) {
   return item_n;
  }
  item_n = list_next(item_n);
 }
 return ((void *)0);
}

canonical_original_code:
struct obj_item *bckt_find_node(struct obj_list *thislist, unsigned char *id)
{
 struct obj_item *item_b = ((void *)0);
 struct obj_item *item_n = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 struct obj_list *list_n = ((void *)0);
 struct UDP_NODE *n = ((void *)0);
 if ((item_b = bckt_find_best_match(thislist, id)) == ((void *)0)) {
  return ((void *)0);
 }
 b = list_value(item_b);
 list_n = b->nodes;
 item_n = list_start(list_n);
 while (item_n != ((void *)0)) {
  n = list_value(item_n);
  if (node_equal(n->id, id)) {
   return item_n;
  }
  item_n = list_next(item_n);
 }
 return ((void *)0);
}

variable_types: struct UDP_NODE { unsigned char id[20]; 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; long time_ping; long time_find; int pinged; } *

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

user_defined_types: struct UDP_NODE { unsigned char id[20]; struct sockaddr_in c_addr; long time_ping; long time_find; int pinged; }

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


decompiled_code:
_BOOL8 __fastcall bckt_put(__int64 a1, const void *a2)
{
__int64 v3; // rdi
__int64 v4; // rbx

if ( !a2 )
return 0LL;
v3 = bckt_find_best_match(a1, a2);
if ( v3 )
{
v4 = list_value(v3);
if ( !bckt_find_node(a1, a2) && list_size(*(_QWORD *)(v4 + 24)) <= 19 )
return list_put(*(_QWORD *)(v4 + 24), a2) != 0;
}
else
{
fail("Something is terribly broken: No appropriate bucket found for ID");
}
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, const void *a2)
{
__int64 v3; // rdi
__int64 v4; // rbx

if ( !a2 )
return 0LL;
v3 = func2(a1, a2);
if ( v3 )
{
v4 = list_value(v3);
if ( !func4(a1, a2) && list_size(*(_QWORD *)(v4 + 24)) <= 19 )
return list_put(*(_QWORD *)(v4 + 24), a2) != 0;
}
else
{
fail("Something is terribly broken: No appropriate bucket found for ID");
}
return 0LL;
}

original_code:
int bckt_put(LIST * l, UDP_NODE * n)
{
 ITEM *i = ((void *)0);
 BUCK *b = ((void *)0);
 if (n == ((void *)0)) {
  return 0;
 }
 if ((i = bckt_find_best_match(l, n->id)) == ((void *)0)) {
  fail("Something is terribly broken: No appropriate bucket found for ID");
  return 0;
 }
 b = list_value(i);
 if (bckt_find_node(l, n->id) != ((void *)0)) {
  return 0;
 }
 if (list_size(b->nodes) >= 20) {
  return 0;
 }
 if (list_put(b->nodes, n) == ((void *)0)) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int bckt_put(struct obj_list *l, struct UDP_NODE *n)
{
 struct obj_item *i = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 if (n == ((void *)0)) {
  return 0;
 }
 if ((i = bckt_find_best_match(l, n->id)) == ((void *)0)) {
  fail("Something is terribly broken: No appropriate bucket found for ID");
  return 0;
 }
 b = list_value(i);
 if (bckt_find_node(l, n->id) != ((void *)0)) {
  return 0;
 }
 if (list_size(b->nodes) >= 20) {
  return 0;
 }
 if (list_put(b->nodes, n) == ((void *)0)) {
  return 0;
 }
 return 1;
}


decompiled_code:
void __fastcall bckt_del(__int64 a1, const void *a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
__int64 v5; // rsi

if ( a2 )
{
v3 = bckt_find_best_match(a1, a2);
if ( v3 )
{
v4 = list_value(v3);
v5 = bckt_find_node(a1, a2);
if ( v5 )
list_del(*(_QWORD *)(v4 + 24), v5);
}
else
{
fail("Something is terribly broken: No appropriate bucket found for ID");
}
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, const void *a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
__int64 v5; // rsi

if ( a2 )
{
v3 = func2(a1, a2);
if ( v3 )
{
v4 = list_value(v3);
v5 = func4(a1, a2);
if ( v5 )
list_del(*(_QWORD *)(v4 + 24), v5);
}
else
{
fail("Something is terribly broken: No appropriate bucket found for ID");
}
}
}

original_code:
void bckt_del(LIST * l, UDP_NODE * n)
{
 ITEM *item_b = ((void *)0);
 ITEM *item_n = ((void *)0);
 BUCK *b = ((void *)0);
 if (n == ((void *)0)) {
  return;
 }
 if ((item_b = bckt_find_best_match(l, n->id)) == ((void *)0)) {
  fail("Something is terribly broken: No appropriate bucket found for ID");
  return;
 }
 b = list_value(item_b);
 if ((item_n = bckt_find_node(l, n->id)) == ((void *)0)) {
  return;
 }
 list_del(b->nodes, item_n);
}

canonical_original_code:
void bckt_del(struct obj_list *l, struct UDP_NODE *n)
{
 struct obj_item *item_b = ((void *)0);
 struct obj_item *item_n = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 if (n == ((void *)0)) {
  return;
 }
 if ((item_b = bckt_find_best_match(l, n->id)) == ((void *)0)) {
  fail("Something is terribly broken: No appropriate bucket found for ID");
  return;
 }
 b = list_value(item_b);
 if ((item_n = bckt_find_node(l, n->id)) == ((void *)0)) {
  return;
 }
 list_del(b->nodes, item_n);
}


decompiled_code:
__int64 __fastcall bckt_split_print(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 i; // rbp
__int64 v5; // rbx
const char *v6; // rax
__int128 v7; // [rsp+0h] [rbp-68h] BYREF
char v8; // [rsp+10h] [rbp-58h]
char v9[72]; // [rsp+20h] [rbp-48h] BYREF

v8 = 0;
v7 = 0LL;
info(log, 0LL, "Bucket split:");
result = list_start(a1);
if ( result )
{
v2 = result;
do
{
v3 = list_value(v2);
hex_hash_encode(v9, v3);
info(log, 0LL, " Bucket: %s", v9);
for ( i = list_start(*(_QWORD *)(v3 + 24)); i; i = list_next(i) )
{
v5 = list_value(i);
hex_hash_encode(v9, v5);
v6 = inet_ntop(2, (const void *)(v5 + 24), (char *)&v7, 0x10u);
info(log, 0LL, " Node: %s %s", v9, v6);
}
result = list_next(v2);
v2 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 i; // rbp
__int64 v5; // rbx
const char *v6; // rax
__int128 v7; // [rsp+0h] [rbp-68h] BYREF
char v8; // [rsp+10h] [rbp-58h]
char v9[72]; // [rsp+20h] [rbp-48h] BYREF

v8 = 0;
v7 = 0LL;
info(log, 0LL, "Bucket split:");
result = list_start(a1);
if ( result )
{
v2 = result;
do
{
v3 = list_value(v2);
hex_hash_encode(v9, v3);
info(log, 0LL, " Bucket: %s", v9);
for ( i = list_start(*(_QWORD *)(v3 + 24)); i; i = list_next(i) )
{
v5 = list_value(i);
hex_hash_encode(v9, v5);
v6 = inet_ntop(2, (const void *)(v5 + 24), (char *)&v7, 0x10u);
info(log, 0LL, " Node: %s %s", v9, v6);
}
result = list_next(v2);
v2 = result;
}
while ( result );
}
return result;
}

original_code:
void bckt_split_print(LIST * l)
{
 ITEM *item_b = ((void *)0);
 BUCK *b = ((void *)0);
 ITEM *item_n = ((void *)0);
 UDP_NODE *n = ((void *)0);
 char hex[2*20 +1];
 char ip_buf[16 + 1];
 memset(ip_buf, '\0', 16 + 1);
 info(_log, ((void *)0), "Bucket split:");
 item_b = list_start(l);
 while (item_b != ((void *)0)) {
  b = list_value(item_b);
  hex_hash_encode(hex, b->id);
  info(_log, ((void *)0), " Bucket: %s", hex);
  item_n = list_start(b->nodes);
  while (item_n != ((void *)0)) {
   n = list_value(item_n);
   hex_hash_encode(hex, n->id);
   info(_log, ((void *)0), "  Node: %s %s", hex,
        inet_ntop(2, &n->c_addr.sin_addr, ip_buf,
           16)
       );
   item_n = list_next(item_n);
  }
  item_b = list_next(item_b);
 }
}

canonical_original_code:
void bckt_split_print(struct obj_list *l)
{
 struct obj_item *item_b = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 struct obj_item *item_n = ((void *)0);
 struct UDP_NODE *n = ((void *)0);
 char hex[-1];
 char ip_buf[-1];
 memset(ip_buf, '\0', 16 + 1);
 info(_log, ((void *)0), "Bucket split:");
 item_b = list_start(l);
 while (item_b != ((void *)0)) {
  b = list_value(item_b);
  hex_hash_encode(hex, b->id);
  info(_log, ((void *)0), " Bucket: %s", hex);
  item_n = list_start(b->nodes);
  while (item_n != ((void *)0)) {
   n = list_value(item_n);
   hex_hash_encode(hex, n->id);
   info(_log, ((void *)0), "  Node: %s %s", hex,
        inet_ntop(2, &n->c_addr.sin_addr, ip_buf,
           16)
       );
   item_n = list_next(item_n);
  }
  item_b = list_next(item_b);
 }
}

variable_types:
hex
char [-1]


decompiled_code:
__int64 __fastcall bckt_is_empty(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = list_start(a1);
if ( !v1 )
return 1LL;
v2 = v1;
while ( !**(_QWORD **)(list_value(v2) + 24) )
{
v2 = list_next(v2);
if ( !v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = list_start(a1);
if ( !v1 )
return 1LL;
v2 = v1;
while ( !**(_QWORD **)(list_value(v2) + 24) )
{
v2 = list_next(v2);
if ( !v2 )
return 1LL;
}
return 0LL;
}

original_code:
int bckt_is_empty(LIST * l)
{
 ITEM *i = ((void *)0);
 BUCK *b = ((void *)0);
 i = list_start(l);
 while (i != ((void *)0)) {
  b = list_value(i);
  if (b->nodes->item != ((void *)0)) {
   return 0;
  }
  i = list_next(i);
 }
 return 1;
}

canonical_original_code:
int bckt_is_empty(struct obj_list *l)
{
 struct obj_item *i = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 i = list_start(l);
 while (i != ((void *)0)) {
  b = list_value(i);
  if (b->nodes->item != ((void *)0)) {
   return 0;
  }
  i = list_next(i);
 }
 return 1;
}


decompiled_code:
__int64 __fastcall bckt_significant_bit(__int64 a1)
{
__int64 result; // rax
bool v2; // cf
int v3; // edx
int v4; // ecx

result = 19LL;
while ( 1 )
{
v3 = *(unsigned __int8 *)(a1 + result);
if ( (_BYTE)v3 )
break;
v2 = result-- == 0;
if ( v2 )
return result;
}
v4 = 7;
do
{
if ( (v3 & (128 >> v4)) != 0 )
break;
v2 = v4-- == 0;
}
while ( !v2 );
return (unsigned int)(v4 + 8 * result);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
bool v2; // cf
int v3; // edx
int v4; // ecx

result = 19LL;
while ( 1 )
{
v3 = *(unsigned __int8 *)(a1 + result);
if ( (_BYTE)v3 )
break;
v2 = result-- == 0;
if ( v2 )
return result;
}
v4 = 7;
do
{
if ( (v3 & (128 >> v4)) != 0 )
break;
v2 = v4-- == 0;
}
while ( !v2 );
return (unsigned int)(v4 + 8 * result);
}

original_code:
int bckt_significant_bit(const UCHAR * id)
{
 int i = 0, j = 0;
 for (i = 19; i >= 0; i--) {
  if (id[i] != 0) {
   break;
  }
 }
 if (i < 0) {
  return -1;
 }
 for (j = 7; j >= 0; j--) {
  if ((id[i] & (0x80 >> j)) != 0) {
   break;
  }
 }
 return 8 * i + j;
}

canonical_original_code:
int bckt_significant_bit(unsigned char *id)
{
 int i = 0; int j = 0;
 for (i = 19; i >= 0; i--) {
  if (id[i] != 0) {
   break;
  }
 }
 if (i < 0) {
  return -1;
 }
 for (j = 7; j >= 0; j--) {
  if ((id[i] & (0x80 >> j)) != 0) {
   break;
  }
 }
 return 8 * i + j;
}

variable_types: i int

variable_types: j int


original_code:
int bckt_compute_id(LIST * thislist, ITEM * item_b, UCHAR * id)
{
 BUCK *b = list_value(item_b);
 ITEM *item_next = ((void *)0);
 BUCK *b_next = ((void *)0);
 int bit1 = 0;
 int bit2 = 0;
 int bit = 0;
 if (item_b->next != ((void *)0)) {
  item_next = list_next(item_b);
  b_next = list_value(item_next);
 }
 bit1 = bckt_significant_bit(b->id);
 bit2 = (b_next != ((void *)0)) ? bckt_significant_bit(b_next->id) : -1;
 bit = (bit1 >= bit2) ? bit1 : bit2;
 bit++;
 if (bit >= 160) {
  return -1;
 }
 memcpy(id, b->id, 20);
 id[bit / 8] |= (0x80 >> (bit % 8));
 return 1;
}

canonical_original_code:
int bckt_compute_id(struct obj_list *thislist, struct obj_item *item_b, unsigned char *id)
{
 struct obj_neighboorhood_bucket *b = list_value(item_b);
 struct obj_item *item_next = ((void *)0);
 struct obj_neighboorhood_bucket *b_next = ((void *)0);
 int bit1 = 0;
 int bit2 = 0;
 int bit = 0;
 if (item_b->next != ((void *)0)) {
  item_next = list_next(item_b);
  b_next = list_value(item_next);
 }
 bit1 = bckt_significant_bit(b->id);
 bit2 = (b_next != ((void *)0)) ? bckt_significant_bit(b_next->id) : -1;
 bit = (bit1 >= bit2) ? bit1 : bit2;
 bit++;
 if (bit >= 160) {
  return -1;
 }
 memcpy(id, b->id, 20);
 id[bit / 8] |= (0x80 >> (bit % 8));
 return 1;
}

variable_types: bit int


decompiled_code:
__int64 __fastcall bckt_split(__int64 a1, const void *a2)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // r12
__m128i *v6; // r13
__int64 v7; // r13
__int64 i; // rbp
const void *v9; // r12
__int64 v10; // rax
__int64 v11; // rax
__m128i v12; // [rsp+0h] [rbp-48h] BYREF
int v13; // [rsp+10h] [rbp-38h]

v2 = bckt_find_best_match(a1, a2);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = list_value(v2);
if ( list_size(*(_QWORD *)(v4 + 24)) <= 8 || (int)bckt_compute_id(a1, v3, &v12) < 0 )
return 0LL;
v6 = (__m128i *)myalloc(32LL);
*v6 = _mm_loadu_si128(&v12);
v6[1].m128i_i32[0] = v13;
v6[1].m128i_i64[1] = list_init();
list_add(a1, v3, v6);
v7 = *(_QWORD *)(v4 + 24);
*(_QWORD *)(v4 + 24) = list_init();
for ( i = list_start(v7); i; i = list_next(i) )
{
v9 = (const void *)list_value(i);
v10 = bckt_find_best_match(a1, v9);
v11 = list_value(v10);
list_put(*(_QWORD *)(v11 + 24), v9);
}
list_free(v7);
return 1LL;
}

original_code:
int bckt_split(LIST * thislist, const UCHAR * target)
{
 ITEM *item_b = ((void *)0);
 BUCK *b = ((void *)0);
 LIST *list_n = ((void *)0);
 ITEM *item_n = ((void *)0);
 UDP_NODE *n = ((void *)0);
 BUCK *b_new = ((void *)0);
 UCHAR id_new[20];
 if ((item_b = bckt_find_best_match(thislist, target)) == ((void *)0)) {
  return 0;
 }
 b = list_value(item_b);
 if (list_size(b->nodes) <= 8) {
  return 0;
 }
 if (bckt_compute_id(thislist, item_b, id_new) < 0) {
  return 0;
 }
 b_new = (BUCK *) myalloc(sizeof(BUCK));
 memcpy(b_new->id, id_new, 20);
 b_new->nodes = list_init();
 list_add(thislist, item_b, b_new);
 list_n = b->nodes;
 b->nodes = list_init();
 item_n = list_start(list_n);
 while (item_n != ((void *)0)) {
  n = list_value(item_n);
  item_b = bckt_find_best_match(thislist, n->id);
  b = list_value(item_b);
  list_put(b->nodes, n);
  item_n = list_next(item_n);
 }
 list_free(list_n);
 return 1;
}

canonical_original_code:
int bckt_split(struct obj_list *thislist, unsigned char *target)
{
 struct obj_item *item_b = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 struct obj_list *list_n = ((void *)0);
 struct obj_item *item_n = ((void *)0);
 struct UDP_NODE *n = ((void *)0);
 struct obj_neighboorhood_bucket *b_new = ((void *)0);
 unsigned char id_new[20];
 if ((item_b = bckt_find_best_match(thislist, target)) == ((void *)0)) {
  return 0;
 }
 b = list_value(item_b);
 if (list_size(b->nodes) <= 8) {
  return 0;
 }
 if (bckt_compute_id(thislist, item_b, id_new) < 0) {
  return 0;
 }
 b_new = (struct obj_neighboorhood_bucket *) myalloc(sizeof(BUCK));
 memcpy(b_new->id, id_new, 20);
 b_new->nodes = list_init();
 list_add(thislist, item_b, b_new);
 list_n = b->nodes;
 b->nodes = list_init();
 item_n = list_start(list_n);
 while (item_n != ((void *)0)) {
  n = list_value(item_n);
  item_b = bckt_find_best_match(thislist, n->id);
  b = list_value(item_b);
  list_put(b->nodes, n);
  item_n = list_next(item_n);
 }
 list_free(list_n);
 return 1;
}

variable_types:
target
unsigned char *


decompiled_code:
__int64 __fastcall bckt_split_loop(__int64 a1, const void *a2, int a3)
{
int i; // er12
__int64 result; // rax

for ( i = 0; ; i = 1 )
{
result = bckt_split(a1, a2);
if ( !(_DWORD)result )
break;
}
if ( a3 == 1 )
{
if ( i )
result = bckt_split_print(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const void *a2, int a3)
{
int i; // er12
__int64 result; // rax

for ( i = 0; ; i = 1 )
{
result = func11(a1, a2);
if ( !(_DWORD)result )
break;
}
if ( a3 == 1 )
{
if ( i )
result = func7(a1);
}
return result;
}

original_code:
void bckt_split_loop(LIST * l, UCHAR * target, int verbose)
{
 int change = 0;
 for (;;) {
  if (bckt_split(l, target)) {
   change = 1;
  } else {
   break;
  }
 }
 if (change == 1 && verbose == 1) {
  bckt_split_print(l);
 }
}

canonical_original_code:
void bckt_split_loop(struct obj_list *l, unsigned char *target, int verbose)
{
 int change = 0;
 for (;;) {
  if (bckt_split(l, target)) {
   change = 1;
  } else {
   break;
  }
 }
 if (change == 1 && verbose == 1) {
  bckt_split_print(l);
 }
}

variable_types: verbose int

variable_types: change int


decompiled_code:
__int64 __fastcall bckt_compact_list(__int64 a1, __m128i *a2, const void *a3)
{
unsigned int v4; // er13
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
int v8; // er12
const __m128i *v9; // rbx

v4 = 0;
v5 = bckt_find_any_match(a1, a3);
if ( v5 )
{
v6 = list_value(v5);
v7 = list_start(*(_QWORD *)(v6 + 24));
if ( v7 )
{
v8 = 0;
do
{
v9 = (const __m128i *)list_value(v7);
if ( (unsigned int)node_ok(v9) )
{
v4 += 26;
++v8;
*a2 = _mm_loadu_si128(v9);
a2[1].m128i_i32[0] = v9[1].m128i_i32[0];
a2 = (__m128i *)ip_sin_to_tuple((char *)v9[1].m128i_i64 + 4, (char *)a2[1].m128i_i64 + 4);
v7 = list_next(v7);
if ( !v7 )
return v4;
}
else
{
v7 = list_next(v7);
if ( !v7 )
return v4;
}
}
while ( v8 <= 7 );
}
}
return v4;
}

original_code:
int bckt_compact_list(LIST * l, UCHAR * nodes_compact_list, UCHAR * target)
{
 UCHAR *p = nodes_compact_list;
 ITEM *item = ((void *)0);
 BUCK *b = ((void *)0);
 UDP_NODE *n = ((void *)0);
 int j = 0;
 int size = 0;
 if ((item = bckt_find_any_match(l, target)) == ((void *)0)) {
  return 0;
 } else {
  b = list_value(item);
 }
 item = list_start(b->nodes);
 while (item != ((void *)0) && j < 8) {
  n = list_value(item);
  if (!node_ok(n)) {
   item = list_next(item);
   continue;
  }
  memcpy(p, n->id, 20);
  p += 20;
  p = ip_sin_to_tuple(&n->c_addr, p);
  size += 26;
  item = list_next(item);
  j++;
 }
 return size;
}

canonical_original_code:
int bckt_compact_list(struct obj_list *l, unsigned char *nodes_compact_list, unsigned char *target)
{
 unsigned char *p = nodes_compact_list;
 struct obj_item *item = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 struct UDP_NODE *n = ((void *)0);
 int j = 0;
 int size = 0;
 if ((item = bckt_find_any_match(l, target)) == ((void *)0)) {
  return 0;
 } else {
  b = list_value(item);
 }
 item = list_start(b->nodes);
 while (item != ((void *)0) && j < 8) {
  n = list_value(item);
  if (!node_ok(n)) {
   item = list_next(item);
   continue;
  }
  memcpy(p, n->id, 20);
  p += 20;
  p = ip_sin_to_tuple(&n->c_addr, p);
  size += 26;
  item = list_next(item);
  j++;
 }
 return size;
}

variable_types:
p
unsigned char *

variable_types: size int


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

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

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

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

original_code:
struct obj_transaction *tdb_init(void)
{
 struct obj_transaction *transaction = (struct obj_transaction *)
     myalloc(sizeof(struct obj_transaction));
 transaction->list = list_init();
 transaction->hash = hash_init(1000);
 return transaction;
}

canonical_original_code:
struct obj_transaction *tdb_init()
{
 struct obj_transaction *transaction = (struct obj_transaction *)
     myalloc(sizeof(struct obj_transaction));
 transaction->list = list_init();
 transaction->hash = hash_init(1000);
 return transaction;
}

variable_types: struct obj_transaction { 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_transaction { struct obj_list *list; struct HASH *hash; }


decompiled_code:
__int64 __fastcall tdb_item(__int64 a1)
{
return hash_get(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL), a1, 4LL);
}

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

original_code:
ITEM *tdb_item(UCHAR * id)
{
 return hash_get(_main->transaction->hash, id, 4);
}

canonical_original_code:
struct obj_item *tdb_item(unsigned char *id)
{
 return hash_get(_main->transaction->hash, id, 4);
}


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

result = list_value();
*(_QWORD *)(result + 24) = a2;
return result;
}

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

result = list_value();
*(_QWORD *)(result + 24) = a2;
return result;
}

original_code:
void tdb_link_ldb(ITEM * i, LOOKUP * l)
{
 TID *tid = list_value(i);
 tid->lookup = l;
}

canonical_original_code:
void tdb_link_ldb(struct obj_item *i, struct LOOKUP *l)
{
 struct obj_tid *tid = list_value(i);
 tid->lookup = l;
}

variable_types: struct LOOKUP { 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; 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: struct obj_tid { unsigned char id[4]; long time; int type; 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; } *lookup; } *

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 obj_tid { unsigned char id[4]; long time; int type; struct LOOKUP *lookup; }

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 DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD rd_data; }


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

if ( a1 )
result = *(unsigned int *)(list_value() + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(list_value() + 16);
else
result = 0LL;
return result;
}

original_code:
int tdb_type(ITEM * i)
{
 TID *tid = ((void *)0);
 if (i == ((void *)0)) {
  return 0;
 } else {
  tid = list_value(i);
 }
 return tid->type;
}

canonical_original_code:
int tdb_type(struct obj_item *i)
{
 struct obj_tid *tid = ((void *)0);
 if (i == ((void *)0)) {
  return 0;
 } else {
  tid = list_value(i);
 }
 return tid->type;
}

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 tdb_ldb()
{
return *(_QWORD *)(list_value() + 24);
}

canonical_decompiled_code:
__int64 func4()
{
return *(_QWORD *)(list_value() + 24);
}

original_code:
LOOKUP *tdb_ldb(ITEM * i)
{
 TID *tid = list_value(i);
 return tid->lookup;
}

canonical_original_code:
struct LOOKUP *tdb_ldb(struct obj_item *i)
{
 struct obj_tid *tid = list_value(i);
 return tid->lookup;
}

variable_types:
i
struct obj_item *

return_type: 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; } *


decompiled_code:
__int64 tdb_tid()
{
return list_value();
}

canonical_decompiled_code:
__int64 func5()
{
return list_value();
}

original_code:
UCHAR *tdb_tid(ITEM * i)
{
 TID *tid = list_value(i);
 return tid->id;
}

canonical_original_code:
unsigned char *tdb_tid(struct obj_item *i)
{
 struct obj_tid *tid = list_value(i);
 return tid->id;
}

return_type: unsigned char *


decompiled_code:
void __fastcall tdb_del(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax

if ( a1 )
{
v1 = list_value();
if ( (unsigned int)tdb_type(a1) - 4 <= 1 )
{
v3 = tdb_ldb(a1);
ldb_free(v3);
}
v2 = tdb_tid(a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL), v2, 4LL);
list_del(**((_QWORD **)main + 4), a1);
myfree(v1);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax

if ( a1 )
{
v1 = list_value();
if ( (unsigned int)func3(a1) - 4 <= 1 )
{
v3 = func4(a1);
ldb_free(v3);
}
v2 = func5(a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL), v2, 4LL);
list_del(**((_QWORD **)main + 4), a1);
myfree(v1);
}
}

original_code:
void tdb_del(ITEM * i)
{
 TID *tid = ((void *)0);
 if (i == ((void *)0)) {
  return;
 } else {
  tid = list_value(i);
 }
 switch (tdb_type(i)) {
 case 4:
 case 5:
  ldb_free(tdb_ldb(i));
  break;
 }
 hash_del(_main->transaction->hash, tdb_tid(i), 4);
 list_del(_main->transaction->list, i);
 myfree(tid);
}

canonical_original_code:
void tdb_del(struct obj_item *i)
{
 struct obj_tid *tid = ((void *)0);
 if (i == ((void *)0)) {
  return;
 } else {
  tid = list_value(i);
 }
 switch (tdb_type(i)) {
 case 4:
 case 5:
  ldb_free(tdb_ldb(i));
  break;
 }
 hash_del(_main->transaction->hash, tdb_tid(i), 4);
 list_del(_main->transaction->list, i);
 myfree(tid);
}


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

result = (__int64 *)**((_QWORD **)main + 4);
for ( i = *result; *result; i = *result )
{
tdb_del(i);
result = (__int64 *)**((_QWORD **)main + 4);
}
return result;
}

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

result = (__int64 *)**((_QWORD **)main + 4);
for ( i = *result; *result; i = *result )
{
func6(i);
result = (__int64 *)**((_QWORD **)main + 4);
}
return result;
}

original_code:
void tdb_clean(void)
{
 while (_main->transaction->list->item != ((void *)0)) {
  tdb_del(_main->transaction->list->item);
 }
}

canonical_original_code:
void tdb_clean()
{
 while (_main->transaction->list->item != ((void *)0)) {
  tdb_del(_main->transaction->list->item);
 }
}


decompiled_code:
__int64 tdb_free()
{
tdb_clean();
list_clear(**((_QWORD **)main + 4));
list_free(**((_QWORD **)main + 4));
hash_free(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL));
return myfree(*((_QWORD *)main + 4));
}

canonical_decompiled_code:
__int64 func8()
{
func7();
list_clear(**((_QWORD **)main + 4));
list_free(**((_QWORD **)main + 4));
hash_free(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL));
return myfree(*((_QWORD *)main + 4));
}

original_code:
void tdb_free(void)
{
 tdb_clean();
 list_clear(_main->transaction->list);
 list_free(_main->transaction->list);
 hash_free(_main->transaction->hash);
 myfree(_main->transaction);
}

canonical_original_code:
void tdb_free()
{
 tdb_clean();
 list_clear(_main->transaction->list);
 list_free(_main->transaction->list);
 hash_free(_main->transaction->hash);
 myfree(_main->transaction);
}


decompiled_code:
void __fastcall tdb_expire(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rdi
__int64 v6; // rax

v2 = list_start(**((_QWORD **)main + 4));
if ( v2 )
{
v3 = v2;
do
{
v4 = v3;
v5 = v3;
v3 = list_next(v3);
v6 = list_value(v5);
if ( *(_QWORD *)(v6 + 8) < a1 || !status )
{
if ( *(_DWORD *)(v6 + 16) == 5 )
p2p_cron_announce(v4);
tdb_del(v4);
}
}
while ( v3 );
}
}

original_code:
void tdb_expire(time_t now)
{
 ITEM *item = ((void *)0);
 ITEM *next = ((void *)0);
 TID *tid = ((void *)0);
 item = list_start(_main->transaction->list);
 while (item != ((void *)0)) {
  next = list_next(item);
  tid = list_value(item);
  if (now > tid->time || status == 0) {
   switch (tid->type) {
   case 5:
    p2p_cron_announce(item);
    break;
   }
   tdb_del(item);
  }
  item = next;
 }
}

canonical_original_code:
void tdb_expire(long now)
{
 struct obj_item *item = ((void *)0);
 struct obj_item *next = ((void *)0);
 struct obj_tid *tid = ((void *)0);
 item = list_start(_main->transaction->list);
 while (item != ((void *)0)) {
  next = list_next(item);
  tid = list_value(item);
  if (now > tid->time || status == 0) {
   switch (tid->type) {
   case 5:
    p2p_cron_announce(item);
    break;
   }
   tdb_del(item);
  }
  item = next;
 }
}

variable_types: now long


decompiled_code:
__int64 __fastcall tdb_create_random_id(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 0;
while ( 1 )
{
++v1;
rand_urandom(a1, 4LL);
result = hash_exists(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL), a1, 4LL);
if ( !(_DWORD)result )
break;
if ( v1 == 1000 )
return info(log, 0LL, "Transaction IDs exhausted. Giving up.");
}
if ( v1 != 1000 )
return result;
return info(log, 0LL, "Transaction IDs exhausted. Giving up.");
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 0;
while ( 1 )
{
++v1;
rand_urandom(a1, 4LL);
result = hash_exists(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL), a1, 4LL);
if ( !(_DWORD)result )
break;
if ( v1 == 1000 )
return info(log, 0LL, "Transaction IDs exhausted. Giving up.");
}
if ( v1 != 1000 )
return result;
return info(log, 0LL, "Transaction IDs exhausted. Giving up.");
}

original_code:
void tdb_create_random_id(UCHAR * id)
{
 int i = 0;
 int max = 1000;
 do {
  rand_urandom(id, 4);
  i++;
 } while (hash_exists(_main->transaction->hash, id, 4)
   && i < max);
 if (i >= max) {
  info(_log, ((void *)0), "Transaction IDs exhausted. Giving up.");
 }
}

canonical_original_code:
void tdb_create_random_id(unsigned char *id)
{
 int i = 0;
 int max = 1000;
 do {
  rand_urandom(id, 4);
  i++;
 } while (hash_exists(_main->transaction->hash, id, 4)
   && i < max);
 if (i >= max) {
  info(_log, ((void *)0), "Transaction IDs exhausted. Giving up.");
 }
}

variable_types:
id
unsigned char *

variable_types: max int


decompiled_code:
__int64 __fastcall tdb_put(int a1)
{
__int64 v1; // rbp
int (__cdecl *v2)(int, const char **, const char **); // rax
__int64 v3; // r12

v1 = myalloc(32LL);
tdb_create_random_id(v1);
*(_DWORD *)(v1 + 16) = a1;
time_add_1_min(v1 + 8);
v2 = main;
*(_QWORD *)(v1 + 24) = 0LL;
v3 = list_put(**((_QWORD **)v2 + 4), v1);
hash_put(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL), v1, 4LL, v3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rbp
int (__cdecl *v2)(int, const char **, const char **); // rax
__int64 v3; // r12

v1 = myalloc(32LL);
func10(v1);
*(_DWORD *)(v1 + 16) = a1;
time_add_1_min(v1 + 8);
v2 = main;
*(_QWORD *)(v1 + 24) = 0LL;
v3 = list_put(**((_QWORD **)v2 + 4), v1);
hash_put(*(_QWORD *)(*((_QWORD *)main + 4) + 8LL), v1, 4LL, v3);
return v3;
}

original_code:
ITEM *tdb_put(int type)
{
 ITEM *item = ((void *)0);
 TID *tid = ((void *)0);
 tid = (TID *) myalloc(sizeof(TID));
 tdb_create_random_id(tid->id);
 tid->type = type;
 time_add_1_min(&tid->time);
 tid->lookup = ((void *)0);
 item = list_put(_main->transaction->list, tid);
 hash_put(_main->transaction->hash, tid->id, 4, item);
 return item;
}

canonical_original_code:
struct obj_item *tdb_put(int type)
{
 struct obj_item *item = ((void *)0);
 struct obj_tid *tid = ((void *)0);
 tid = (struct obj_tid *) myalloc(sizeof(TID));
 tdb_create_random_id(tid->id);
 tid->type = type;
 time_add_1_min(&tid->time);
 tid->lookup = ((void *)0);
 item = list_put(_main->transaction->list, tid);
 hash_put(_main->transaction->hash, tid->id, 4, item);
 return item;
}

variable_types: type int

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


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

if ( a1 )
{
hash_free(*(_QWORD *)(a1 + 32));
list_clear(*(_QWORD *)(a1 + 24));
list_free(*(_QWORD *)(a1 + 24));
result = myfree(a1);
}
return result;
}

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

if ( a1 )
{
hash_free(*(_QWORD *)(a1 + 32));
list_clear(*(_QWORD *)(a1 + 24));
list_free(*(_QWORD *)(a1 + 24));
result = myfree(a1);
}
return result;
}

original_code:
void ldb_free(LOOKUP * l)
{
 if (l == ((void *)0)) {
  return;
 }
 hash_free(l->hash);
 list_clear(l->list);
 list_free(l->list);
 myfree(l);
}

canonical_original_code:
void ldb_free(struct LOOKUP *l)
{
 if (l == ((void *)0)) {
  return;
 }
 hash_free(l->hash);
 list_clear(l->list);
 list_free(l->list);
 myfree(l);
}

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


original_code:
LONG ldb_put(LOOKUP * l, UCHAR * node_id, IP * from)
{
 ITEM *i = ((void *)0);
 NODE_L *new = ((void *)0);
 NODE_L *n = ((void *)0);
 LONG index = 0;
 if (list_size(l->list) >= 32767) {
  info(_log, from,
       "ldb_put(): Too many nodes without end in sight.");
  return 32767;
 }
 new = (NODE_L *) myalloc(sizeof(NODE_L));
 memcpy(new->id, node_id, 20);
 memcpy(&new->c_addr, from, sizeof(IP));
 memset(new->token, '\0', 20);
 new->token_size = 0;
 i = list_start(l->list);
 while (i != ((void *)0)) {
  n = list_value(i);
  if (str_sha1_compare(node_id, n->id, l->target) < 0) {
   list_ins(l->list, i, new);
   hash_put(l->hash, new->id, 20, new);
   return index;
  }
  i = list_next(i);
  index++;
 }
 list_put(l->list, new);
 hash_put(l->hash, new->id, 20, new);
 return index;
}

canonical_original_code:
long ldb_put(struct LOOKUP *l, unsigned char *node_id, struct sockaddr_in *from)
{
 struct obj_item *i = ((void *)0);
 struct NODE_L *new = ((void *)0);
 struct NODE_L *n = ((void *)0);
 long index = 0;
 if (list_size(l->list) >= 32767) {
  info(_log, from,
       "ldb_put(): Too many nodes without end in sight.");
  return 32767;
 }
 new = (struct NODE_L *) myalloc(sizeof(NODE_L));
 memcpy(new->id, node_id, 20);
 memcpy(&new->c_addr, from, sizeof(IP));
 memset(new->token, '\0', 20);
 new->token_size = 0;
 i = list_start(l->list);
 while (i != ((void *)0)) {
  n = list_value(i);
  if (str_sha1_compare(node_id, n->id, l->target) < 0) {
   list_ins(l->list, i, new);
   hash_put(l->hash, new->id, 20, new);
   return index;
  }
  i = list_next(i);
  index++;
 }
 list_put(l->list, new);
 hash_put(l->hash, new->id, 20, new);
 return index;
}

variable_types:
from
struct sockaddr_in *

variable_types: struct NODE_L { unsigned char id[20]; 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; unsigned char token[20]; int token_size; } *

variable_types: index long

return_type: long

user_defined_types: struct NODE_L { unsigned char id[20]; struct sockaddr_in c_addr; unsigned char token[20]; int token_size; }


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

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

original_code:
NODE_L *ldb_find(LOOKUP * l, UCHAR * node_id)
{
 return hash_get(l->hash, node_id, 20);
}

canonical_original_code:
struct NODE_L *ldb_find(struct LOOKUP *l, unsigned char *node_id)
{
 return hash_get(l->hash, node_id, 20);
}

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

return_type: struct NODE_L { unsigned char id[20]; 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; unsigned char token[20]; int token_size; } *


decompiled_code:
__int64 __fastcall ldb_update(__int64 a1, __int64 a2, __int64 a3, const __m128i *a4)
{
__int64 result; // rax
__int64 v7; // rbx
size_t v8; // r12
const void *v9; // rsi

result = hash_get(*(_QWORD *)(a1 + 32), a2, 20LL);
if ( result )
{
v7 = result;
*(__m128i *)(result + 20) = _mm_loadu_si128(a4);
v8 = ben_str_i(a3);
v9 = (const void *)ben_str_s(a3);
memcpy((void *)(v7 + 36), v9, v8);
result = ben_str_i(a3);
*(_DWORD *)(v7 + 56) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, const __m128i *a4)
{
__int64 result; // rax
__int64 v7; // rbx
size_t v8; // r12
const void *v9; // rsi

result = hash_get(*(_QWORD *)(a1 + 32), a2, 20LL);
if ( result )
{
v7 = result;
*(__m128i *)(result + 20) = _mm_loadu_si128(a4);
v8 = ben_str_i(a3);
v9 = (const void *)ben_str_s(a3);
memcpy((void *)(v7 + 36), v9, v8);
result = ben_str_i(a3);
*(_DWORD *)(v7 + 56) = result;
}
return result;
}

original_code:
void ldb_update(LOOKUP * l, UCHAR * node_id, BEN * token, IP * from)
{
 NODE_L *n = ((void *)0);
 if ((n = hash_get(l->hash, node_id, 20)) == ((void *)0)) {
  return;
 }
 memcpy(&n->c_addr, from, sizeof(IP));
 memcpy(&n->token, ben_str_s(token), ben_str_i(token));
 n->token_size = ben_str_i(token);
}

canonical_original_code:
void ldb_update(struct LOOKUP *l, unsigned char *node_id, struct BEN *token, struct sockaddr_in *from)
{
 struct NODE_L *n = ((void *)0);
 if ((n = hash_get(l->hash, node_id, 20)) == ((void *)0)) {
  return;
 }
 memcpy(&n->c_addr, from, sizeof(IP));
 memcpy(&n->token, ben_str_s(token), ben_str_i(token));
 n->token_size = ben_str_i(token);
}

variable_types: struct BEN { int t; union { long i; struct STR { unsigned char *s; long i; } *s; struct obj_list *d; struct obj_list *l; } v; } *

user_defined_types: struct BEN { int t; union { long i; struct STR *s; struct obj_list *d; struct obj_list *l; } v; }


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

result = *(unsigned int *)(a1 + 868);
*(_DWORD *)(a1 + 868) = result + 1;
return result;
}

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

result = *(unsigned int *)(a1 + 868);
*(_DWORD *)(a1 + 868) = result + 1;
return result;
}

original_code:
int ldb_number_of_dns_responses(LOOKUP * l)
{
 int current_number = l->number_of_dns_responses;
 l->number_of_dns_responses++;
 return current_number;
}

canonical_original_code:
int ldb_number_of_dns_responses(struct LOOKUP *l)
{
 int current_number = l->number_of_dns_responses;
 l->number_of_dns_responses++;
 return current_number;
}

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


decompiled_code:
_BOOL8 __fastcall ip_is_localhost(__int64 a1)
{
return *(unsigned __int128 *)&_mm_load_si128((const __m128i *)&LC0) == *(_OWORD *)(a1 + 8);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(unsigned __int128 *)&_mm_load_si128((const __m128i *)&LC0) == *(_OWORD *)(a1 + 8);
}

original_code:
int ip_is_localhost(IP * from)
{
 const UCHAR localhost[] =
     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
 if (memcmp(&from->sin6_addr.__in6_u.__u6_addr8, localhost, 16) == 0) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int ip_is_localhost(struct sockaddr_in6 *from)
{
 unsigned char localhost[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
 if (memcmp(&from->sin6_addr.__in6_u.__u6_addr8, localhost, 16) == 0) {
  return 1;
 }
 return 0;
}

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *

variable_types:
localhost
unsigned char []

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
_BOOL8 __fastcall ip_is_linklocal(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == 33022LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == 33022LL;
}

original_code:
int ip_is_linklocal(IP * from)
{
 const UCHAR linklocal[] =
     { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 if (memcmp(from->sin6_addr.__in6_u.__u6_addr8, linklocal, 8) == 0) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int ip_is_linklocal(struct sockaddr_in6 *from)
{
 unsigned char linklocal[] = { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 if (memcmp(from->sin6_addr.__in6_u.__u6_addr8, linklocal, 8) == 0) {
  return 1;
 }
 return 0;
}

variable_types:
linklocal
unsigned char []

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int16 __fastcall ip_merge_port_to_sin(__int64 a1, __int16 a2)
{
__int16 result; // ax
__int64 v3; // rdx

result = _bswap_16(a2);
*(_WORD *)(v3 + 2) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func4(__int64 a1, __int16 a2)
{
__int16 result; // ax
__int64 v3; // rdx

result = func0(a2);
*(_WORD *)(v3 + 2) = result;
return result;
}

original_code:
void ip_merge_port_to_sin(IP * sin, USHORT port)
{
 sin->sin6_port = htons(port);
}

canonical_original_code:
void ip_merge_port_to_sin(struct sockaddr_in6 *sin, unsigned short port)
{
 sin->sin6_port = htons(port);
}

variable_types:
port
unsigned short


decompiled_code:
__int16 __fastcall ip_sin_to_port(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 2));
}

canonical_decompiled_code:
__int16 __fastcall func5(__int64 a1)
{
return func0(*(_WORD *)(a1 + 2));
}

original_code:
USHORT ip_sin_to_port(IP * sin)
{
 return ntohs(sin->sin6_port);
}

canonical_original_code:
unsigned short ip_sin_to_port(struct sockaddr_in6 *sin)
{
 return ntohs(sin->sin6_port);
}

return_type: unsigned short


decompiled_code:
const char *__fastcall ip_sin_to_string(__int64 a1, __int64 a2)
{
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 39) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 47) >> 3));
return inet_ntop(10, (const void *)(a1 + 8), (char *)a2, 0x2Eu);
}

canonical_decompiled_code:
const char *__fastcall func6(__int64 a1, __int64 a2)
{
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 39) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 47) >> 3));
return inet_ntop(10, (const void *)(a1 + 8), (char *)a2, 0x2Eu);
}

original_code:
void ip_sin_to_string(IP * sin, char *buf)
{
 memset(buf, '\0', 46 + 1);
 inet_ntop(10, &sin->sin6_addr, buf, 46);
}

canonical_original_code:
void ip_sin_to_string(struct sockaddr_in6 *sin, char *buf)
{
 memset(buf, '\0', 46 + 1);
 inet_ntop(10, &sin->sin6_addr, buf, 46);
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall sha1_hash(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[120]; // [rsp+0h] [rbp-78h] BYREF

blk_SHA1_Init(v5);
blk_SHA1_Update(v5, a2, a3);
return blk_SHA1_Final(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[120]; // [rsp+0h] [rbp-78h] BYREF

blk_SHA1_Init(v5);
blk_SHA1_Update(v5, a2, a3);
return blk_SHA1_Final(a1, v5);
}

original_code:
void sha1_hash(UCHAR * hash, const char *buffer, long int bytes)
{
 blk_SHA_CTX c;
 blk_SHA1_Init(&c);
 blk_SHA1_Update(&c, buffer, bytes);
 blk_SHA1_Final(hash, &c);
}

canonical_original_code:
void sha1_hash(unsigned char *hash, char *buffer, long bytes)
{
 struct blk_SHA_CTX c;
 blk_SHA1_Init(&c);
 blk_SHA1_Update(&c, buffer, bytes);
 blk_SHA1_Final(hash, &c);
}

variable_types:
hash
unsigned char *

variable_types:
buffer
char *

variable_types: bytes long

variable_types: struct blk_SHA_CTX { unsigned long long size; unsigned int H[5]; unsigned int W[16]; }


decompiled_code:
_BOOL8 __fastcall file_isdir(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

original_code:
int file_isdir(const char *dirname)
{
 struct stat statbuf;
 if (lstat(dirname, &statbuf) == 0 && ((((statbuf.st_mode)) & 0170000) == (0040000)))
  return 1;
 return 0;
}

canonical_original_code:
int file_isdir(char *dirname)
{
 struct stat statbuf;
 if (lstat(dirname, &statbuf) == 0 && ((((statbuf.st_mode)) & 0170000) == (0040000)))
  return 1;
 return 0;
}

variable_types:
dirname
char *

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

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


decompiled_code:
_BOOL8 __fastcall file_isreg(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

original_code:
int file_isreg(const char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0 && ((((statbuf.st_mode)) & 0170000) == (0100000)))
  return 1;
 return 0;
}

canonical_original_code:
int file_isreg(char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0 && ((((statbuf.st_mode)) & 0170000) == (0100000)))
  return 1;
 return 0;
}

variable_types:
filename
char *

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
_BOOL8 __fastcall file_islink(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 40960;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 40960;
return result;
}

original_code:
int file_islink(const char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0 && ((((statbuf.st_mode)) & 0170000) == (0120000)))
  return 1;
 return 0;
}

canonical_original_code:
int file_islink(char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0 && ((((statbuf.st_mode)) & 0170000) == (0120000)))
  return 1;
 return 0;
}


decompiled_code:
_BOOL8 __fastcall file_mkdir(char *path)
{
_BOOL4 v1; // er8
_BOOL8 result; // rax

v1 = file_isdir(path);
result = 1LL;
if ( !v1 )
result = mkdir(path, 0x1C0u) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *path)
{
_BOOL4 v1; // er8
_BOOL8 result; // rax

v1 = func0(path);
result = 1LL;
if ( !v1 )
result = mkdir(path, 0x1C0u) == 0;
return result;
}

original_code:
int file_mkdir(const char *dirname)
{
 if (!file_isdir(dirname)) {
  if (mkdir(dirname, 0400 | 0200 | 0100) == 0) {
   return 1;
  }
 } else {
  return 1;
 }
 return 0;
}

canonical_original_code:
int file_mkdir(char *dirname)
{
 if (!file_isdir(dirname)) {
  if (mkdir(dirname, 0400 | 0200 | 0100) == 0) {
   return 1;
  }
 } else {
  return 1;
 }
 return 0;
}


decompiled_code:
__off_t __fastcall file_size(const char *a1)
{
bool v1; // zf
__off_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = v3.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func4(const char *a1)
{
bool v1; // zf
__off_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = v3.st_size;
return result;
}

original_code:
size_t file_size(const char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0) {
  return statbuf.st_size;
 }
 return 0;
}

canonical_original_code:
unsigned long file_size(char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0) {
  return statbuf.st_size;
 }
 return 0;
}


decompiled_code:
__time_t __fastcall file_mod(const char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3) == 0;
result = -1LL;
if ( v1 )
result = v3.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func5(const char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3) == 0;
result = -1LL;
if ( v1 )
result = v3.st_mtim.tv_sec;
return result;
}

original_code:
time_t file_mod(const char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0) {
  return statbuf.st_mtim.tv_sec;
 }
 return -1;
}

canonical_original_code:
long file_mod(char *filename)
{
 struct stat statbuf;
 if (lstat(filename, &statbuf) == 0) {
  return statbuf.st_mtim.tv_sec;
 }
 return -1;
}


decompiled_code:
pthread_mutex_t *mutex_init()
{
pthread_mutex_t *v0; // r12

v0 = (pthread_mutex_t *)myalloc(40LL);
if ( pthread_mutex_init(v0, 0LL) )
fail("pthread_mutex_init() failed.");
return v0;
}

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

v0 = (pthread_mutex_t *)myalloc(40LL);
if ( pthread_mutex_init(v0, 0LL) )
fail("pthread_mutex_init() failed.");
return v0;
}

original_code:
pthread_mutex_t *mutex_init(void)
{
 pthread_mutex_t *mutex =
     (pthread_mutex_t *) myalloc(sizeof(pthread_mutex_t));
 if (pthread_mutex_init(mutex, ((void *)0)) != 0)
  fail("pthread_mutex_init() failed.");
 return mutex;
}

canonical_original_code:
union pthread_mutex_t *mutex_init()
{
 union pthread_mutex_t *mutex = (pthread_mutex_t *) myalloc(sizeof(pthread_mutex_t));
 if (pthread_mutex_init(mutex, ((void *)0)) != 0)
  fail("pthread_mutex_init() failed.");
 return mutex;
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall mutex_destroy(pthread_mutex_t *a1)
{
__int64 result; // rax

if ( a1 )
{
pthread_mutex_destroy(a1);
result = myfree(a1);
}
return result;
}

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

if ( a1 )
{
pthread_mutex_destroy(a1);
result = myfree(a1);
}
return result;
}

original_code:
void mutex_destroy(pthread_mutex_t * mutex)
{
 if (mutex != ((void *)0)) {
  pthread_mutex_destroy(mutex);
  myfree(mutex);
 }
}

canonical_original_code:
void mutex_destroy(union pthread_mutex_t *mutex)
{
 if (mutex != ((void *)0)) {
  pthread_mutex_destroy(mutex);
  myfree(mutex);
 }
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
// attributes: thunk
int mutex_block(pthread_mutex_t *mutex)
{
return pthread_mutex_lock(mutex);
}

canonical_decompiled_code:
int func2(pthread_mutex_t *mutex)
{
return pthread_mutex_lock(mutex);
}

original_code:
void mutex_block(pthread_mutex_t * mutex)
{
 pthread_mutex_lock(mutex);
}

canonical_original_code:
void mutex_block(union pthread_mutex_t *mutex)
{
 pthread_mutex_lock(mutex);
}


decompiled_code:
// attributes: thunk
int mutex_unblock(pthread_mutex_t *mutex)
{
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int func3(pthread_mutex_t *mutex)
{
return pthread_mutex_unlock(mutex);
}

original_code:
void mutex_unblock(pthread_mutex_t * mutex)
{
 pthread_mutex_unlock(mutex);
}

canonical_original_code:
void mutex_unblock(union pthread_mutex_t *mutex)
{
 pthread_mutex_unlock(mutex);
}


fail

decompiled_code:
void __noreturn fail(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
fprintf(stderr, "%s\n", s);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
fprintf(stderr, "%s\n", s);
exit(1);
}

original_code:
void fail(const char *format, ...)
{
 char va_buf[1024];
 va_list vlist;
 __builtin_va_start(vlist,format);
 vsnprintf(va_buf, 1024, format, vlist);
 __builtin_va_end(vlist);
 fprintf(stderr, "%s\n", va_buf);
 exit(1);
}

canonical_original_code:
void fail(char *format, ...)
{
 char va_buf[1024];
 __builtin_va_list vlist;
 __builtin_va_start(vlist,format);
 vsnprintf(va_buf, 1024, format, vlist);
 __builtin_va_end(vlist);
 fprintf(stderr, "%s\n", va_buf);
 exit(1);
}

variable_types:
format
char *


decompiled_code:
__int64 conf_free()
{
return myfree(*((_QWORD *)main + 2));
}

canonical_decompiled_code:
__int64 func0()
{
return myfree(*((_QWORD *)main + 2));
}

original_code:
void conf_free(void)
{
 myfree(_main->conf);
}

canonical_original_code:
void conf_free()
{
 myfree(_main->conf);
}


decompiled_code:
int __fastcall conf_home_from_env(char *s)
{
char *v2; // rax

if ( !getenv("HOME") || !getuid() )
return (unsigned int)strncpy(s, "/var/www", 0x3FFuLL);
v2 = getenv("HOME");
return snprintf(s, 0x400uLL, "%s/%s", v2, "Public");
}

canonical_decompiled_code:
int __fastcall func1(char *s)
{
char *v2; // rax

if ( !getenv("HOME") || !getuid() )
return (unsigned int)strncpy(s, "/var/www", 0x3FFuLL);
v2 = getenv("HOME");
return snprintf(s, 0x400uLL, "%s/%s", v2, "Public");
}

original_code:
void conf_home_from_env(struct obj_conf *conf)
{
 if (getenv("HOME") == ((void *)0) || getuid() == 0) {
  strncpy(conf->home, "/var/www", 1023);
 } else {
  snprintf(conf->home, 1024, "%s/%s", getenv("HOME"),
    "Public");
 }
}

variable_types: struct obj_conf { char home[1024]; char file[1024]; int cores; unsigned int port; } *


decompiled_code:
unsigned int __fastcall conf_home_from_arg(char *s, const char *a2)
{
char *v2; // rax

if ( *a2 == 47 )
return snprintf(s, 0x400uLL, "%s", a2);
if ( !getenv("PWD") )
return (unsigned int)strncpy(s, "/var/www", 0x3FFuLL);
v2 = getenv("PWD");
return snprintf(s, 0x400uLL, "%s/%s", v2, a2);
}

canonical_decompiled_code:
unsigned int __fastcall func2(char *s, const char *a2)
{
char *v2; // rax

if ( *a2 == 47 )
return snprintf(s, 0x400uLL, "%s", a2);
if ( !getenv("PWD") )
return (unsigned int)strncpy(s, "/var/www", 0x3FFuLL);
v2 = getenv("PWD");
return snprintf(s, 0x400uLL, "%s/%s", v2, a2);
}

original_code:
void conf_home_from_arg(struct obj_conf *conf, char *optarg)
{
 char *p = optarg;
 if (*p == '/') {
  snprintf(conf->home, 1024, "%s", p);
 } else if (getenv("PWD") != ((void *)0)) {
  snprintf(conf->home, 1024, "%s/%s", getenv("PWD"), p);
 } else {
  strncpy(conf->home, "/var/www", 1023);
 }
}

variable_types:
optarg
char *

variable_types:
p
char *

user_defined_types: struct obj_conf { char home[1024]; char file[1024]; int cores; unsigned int port; }


decompiled_code:
__int64 main_free()
{
return myfree(*(_QWORD *)main);
}

canonical_decompiled_code:
__int64 func1()
{
return myfree(*(_QWORD *)main);
}

original_code:
void main_free(void)
{
 myfree(_main);
}

canonical_original_code:
void main_free()
{
 myfree(_main);
}


decompiled_code:
int __fastcall hex_hash_encode(char *s, unsigned __int8 *a2)
{
char *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rcx
char *v5; // rdi
int result; // eax

v2 = s;
v3 = a2;
*((_QWORD *)s + 4) = 0LL;
s[40] = 0;
*(_OWORD *)s = 0LL;
*((_OWORD *)s + 1) = 0LL;
do
{
v4 = *v3;
v5 = v2;
++v3;
v2 += 2;
result = snprintf(v5, 3uLL, "%02x", v4);
}
while ( a2 + 20 != v3 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s, unsigned __int8 *a2)
{
char *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rcx
char *v5; // rdi
int result; // eax

v2 = s;
v3 = a2;
*((_QWORD *)s + 4) = 0LL;
s[40] = 0;
*(_OWORD *)s = 0LL;
*((_OWORD *)s + 1) = 0LL;
do
{
v4 = *v3;
v5 = v2;
++v3;
v2 += 2;
result = snprintf(v5, 3uLL, "%02x", v4);
}
while ( a2 + 20 != v3 );
return result;
}

original_code:
void hex_hash_encode(char *out, const UCHAR * in)
{
 UCHAR *p0 = (UCHAR *) in;
 char *p1 = out;
 long int i = 0;
 memset(out, '\0', 2*20 +1);
 for (i = 0; i < 20; i++) {
  snprintf(p1, 3, "%02x", *p0);
  p0++;
  p1 += 2;
 }
}

canonical_original_code:
void hex_hash_encode(char *out, unsigned char *in)
{
 unsigned char *p0 = (UCHAR *) in;
 char *p1 = out;
 long i = 0;
 memset(out, '\0', 2*20 +1);
 for (i = 0; i < 20; i++) {
  snprintf(p1, 3, "%02x", *p0);
  p0++;
  p1 += 2;
 }
}

variable_types:
out
char *

variable_types:
in
unsigned char *

variable_types: i long