decompiled_code:
bool __fastcall hashtable_key_exists(__int64 a1, __int64 a2)
{
__int64 v2; // r12
unsigned int v3; // eax

v2 = *(_QWORD *)(a1 + 56);
v3 = (*(__int64 (__fastcall **)(__int64))(a1 + 24))(a2);
return hashtable_find_bucket(
(unsigned __int8 (__fastcall **)(__int64, _QWORD))a1,
*(_QWORD **)(v2 + 8 * ((unsigned __int64)v3 % *(_QWORD *)(a1 + 32))),
a2) != 0LL;
}

canonical_decompiled_code:
bool __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // r12
unsigned int v3; // eax

v2 = *(_QWORD *)(a1 + 56);
v3 = (*(__int64 (__fastcall **)(__int64))(a1 + 24))(a2);
return hashtable_find_bucket(
(unsigned __int8 (__fastcall **)(__int64, _QWORD))a1,
*(_QWORD **)(v2 + 8 * ((unsigned __int64)v3 % *(_QWORD *)(a1 + 32))),
a2) != 0LL;
}

original_code:
_Bool
hashtable_key_exists(const HashTable *table, const void *key)
{
 ((void) (0));
 ((void) (0));
 struct _Bucket *head = table->buckets[table->hash(key) % table->size];
 return _hashtable_find_bucket(table, head, key) != ((void *)0);
}

canonical_original_code:
_Bool hashtable_key_exists(struct _HashTable *table, void *key)
{
 ((void) (0));
 ((void) (0));
 struct _Bucket *head = table->buckets[table->hash(key) % table->size];
 return _hashtable_find_bucket(table, head, key) != ((void *)0);
}


decompiled_code:
__int64 __fastcall hashtable_count(__int64 a1)
{
return *(_QWORD *)(a1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return *(_QWORD *)(a1 + 64);
}

original_code:
size_t
hashtable_count(const HashTable *table)
{
 ((void) (0));
 return table->count;
}

canonical_original_code:
unsigned long hashtable_count(struct _HashTable *table)
{
 ((void) (0));
 return table->count;
}

variable_types: struct _HashTable { _Bool (*compare_keys)(void *a, void *b); void (*free_key)(void *p); void (*free_value)(void *p); unsigned int (*hash)(void *ptr); unsigned long size; unsigned long *sizeptr; _Bool grow; struct _Bucket { void *key; void *data; struct _Bucket *next; } **buckets; unsigned long count; struct _Pool { void *(*alloc)(struct _Pool *pool); void (*free)(struct _Pool *pool, void *ptr); } *pool; struct _HashTablePair { void (*free_value)(void *p); struct _Bucket *bucket; } pair; } *

return_type: unsigned long

user_defined_types: struct _HashTable { _Bool (*compare_keys)(void *a, void *b); void (*free_key)(void *p); void (*free_value)(void *p); unsigned int (*hash)(void *ptr); unsigned long size; unsigned long *sizeptr; _Bool grow; struct _Bucket **buckets; unsigned long count; struct _Pool *pool; struct _HashTablePair pair; }


decompiled_code:
bool __fastcall hashtable_iter_next(__int64 a1)
{
bool result; // al
__int64 v2; // rax
__int64 v3; // rax

while ( !*(_BYTE *)(a1 + 24) )
{
v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
{
v3 = *(_QWORD *)(v2 + 16);
*(_QWORD *)(a1 + 16) = v3;
if ( v3 )
return 1;
}
else
{
result = hashtable_iter_get_next_bucket((__int64 *)a1);
*(_BYTE *)(a1 + 24) = !result;
if ( result )
return result;
}
}
return 0;
}

canonical_decompiled_code:
bool __fastcall func16(__int64 a1)
{
bool result; // al
__int64 v2; // rax
__int64 v3; // rax

while ( !*(_BYTE *)(a1 + 24) )
{
v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
{
v3 = *(_QWORD *)(v2 + 16);
*(_QWORD *)(a1 + 16) = v3;
if ( v3 )
return 1;
}
else
{
result = func1((__int64 *)a1);
*(_BYTE *)(a1 + 24) = !result;
if ( result )
return result;
}
}
return 0;
}

original_code:
_Bool
hashtable_iter_next(HashTableIter *iter)
{
 ((void) (0));
 _Bool success = 0;
 while(!success && !iter->finished)
 {
  if(iter->liter)
  {
   iter->liter = iter->liter->next;
   success = iter->liter != ((void *)0);
  }
  else
  {
   success = _hashtable_iter_get_next_bucket(iter);
   iter->finished = !success;
  }
 }
 return success;
}

canonical_original_code:
_Bool hashtable_iter_next(struct HashTableIter *iter)
{
 ((void) (0));
 _Bool success = 0;
 while(!success && !iter->finished)
 {
  if(iter->liter)
  {
   iter->liter = iter->liter->next;
   success = iter->liter != ((void *)0);
  }
  else
  {
   success = _hashtable_iter_get_next_bucket(iter);
   iter->finished = !success;
  }
 }
 return success;
}

variable_types: struct HashTableIter { struct _HashTable { _Bool (*compare_keys)(void *a, void *b); void (*free_key)(void *p); void (*free_value)(void *p); unsigned int (*hash)(void *ptr); unsigned long size; unsigned long *sizeptr; _Bool grow; struct _Bucket { void *key; void *data; struct _Bucket *next; } **buckets; unsigned long count; struct _Pool { void *(*alloc)(struct _Pool *pool); void (*free)(struct _Pool *pool, void *ptr); } *pool; struct _HashTablePair { void (*free_value)(void *p); struct _Bucket *bucket; } pair; } *table; unsigned long offset; struct _Bucket *liter; _Bool finished; } *

user_defined_types: struct HashTableIter { struct _HashTable *table; unsigned long offset; struct _Bucket *liter; _Bool finished; }


decompiled_code:
__int64 __fastcall hashtable_iter_get_key(__int64 a1)
{
return **(_QWORD **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return **(_QWORD **)(a1 + 16);
}

original_code:
void *
hashtable_iter_get_key(const HashTableIter *iter)
{
 ((void) (0));
 return iter->liter->key;
}

canonical_original_code:
void *hashtable_iter_get_key(struct HashTableIter *iter)
{
 ((void) (0));
 return iter->liter->key;
}

return_type: void *

user_defined_types: struct _HashTablePair { void (*free_value)(void *p); struct _Bucket *bucket; }

user_defined_types: struct _Pool { void *(*alloc)(struct _Pool *pool); void (*free)(struct _Pool *pool, void *ptr); }

user_defined_types: struct _Bucket { void *key; void *data; struct _Bucket *next; }


decompiled_code:
__int64 __fastcall hashtable_iter_get_value(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
}

original_code:
void *
hashtable_iter_get_value(const HashTableIter *iter)
{
 ((void) (0));
 return iter->liter->data;
}

canonical_original_code:
void *hashtable_iter_get_value(struct HashTableIter *iter)
{
 ((void) (0));
 return iter->liter->data;
}


decompiled_code:
__int64 __fastcall str_hash(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++a1;
v2 = v1 + 65599 * v2;
v1 = *a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++a1;
v2 = v1 + 65599 * v2;
v1 = *a1;
}
while ( *a1 );
return v2;
}

original_code:
uint32_t
str_hash(const void *ptr)
{
 ((void) (0));
 const char *plain = ptr;
 uint32_t hash = 0;
 while(*plain)
 {
  hash = *plain++ + (hash << 6) + (hash << 16) - hash;
 }
 return hash;
}

canonical_original_code:
unsigned int str_hash(void *ptr)
{
 ((void) (0));
 char *plain = ptr;
 unsigned int hash = 0;
 while(*plain)
 {
  hash = *plain++ + (hash << 6) + (hash << 16) - hash;
 }
 return hash;
}

variable_types:
ptr
void *

variable_types:
plain
char *

variable_types:
hash
unsigned int

return_type: unsigned int


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

result = a1;
if ( a1 > 0xFFFFFFFF )
{
fprintf(stderr, "%s(): integer overflow.\n", "direct_hash");
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = a1;
if ( a1 > 0xFFFFFFFF )
{
fprintf(stderr, "%s(): integer overflow.\n", "direct_hash");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
uint32_t
direct_hash(const void *ptr)
{
 uintptr_t v = (uintptr_t)ptr;
 if(v > (4294967295U))
 {
  fprintf(stderr, "%s(): integer overflow.\n", __func__);
  v = (4294967295U);
 }
 return (uint32_t)v;
}

canonical_original_code:
unsigned int direct_hash(void *ptr)
{
 unsigned long v = (uintptr_t)ptr;
 if(v > (4294967295U))
 {
  fprintf(stderr, "%s(): integer overflow.\n", __func__);
  v = (4294967295U);
 }
 return (unsigned int)v;
}

variable_types:
v
unsigned long


decompiled_code:
bool __fastcall str_equal(unsigned __int8 *a1, char *a2)
{
unsigned __int8 v2; // al
char v3; // dl

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
v3 = *a2;
if ( !*a2 )
break;
++a1;
++a2;
if ( v2 != v3 )
return 0;
}
return *a2 == (char)v2;
}

canonical_decompiled_code:
bool __fastcall func0(unsigned __int8 *a1, char *a2)
{
unsigned __int8 v2; // al
char v3; // dl

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
v3 = *a2;
if ( !*a2 )
break;
++a1;
++a2;
if ( v2 != v3 )
return 0;
}
return *a2 == (char)v2;
}

original_code:
_Bool
str_equal(const void *a, const void *b)
{
 ((void) (0));
 ((void) (0));
 const char *s0 = (const char *)a;
 const char *s1 = (const char *)b;
 while(*s0 && *s1)
 {
  if(*s0++ != *s1++)
  {
   return 0;
  }
 }
 return *s0 == *s1;
}

canonical_original_code:
_Bool str_equal(void *a, void *b)
{
 ((void) (0));
 ((void) (0));
 char *s0 = (const char *)a;
 char *s1 = (const char *)b;
 while(*s0 && *s1)
 {
  if(*s0++ != *s1++)
  {
   return 0;
  }
 }
 return *s0 == *s1;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall direct_compare(unsigned __int64 a1, unsigned __int64 a2)
{
return (a1 > a2) - (unsigned int)(a1 < a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, unsigned __int64 a2)
{
return (a1 > a2) - (unsigned int)(a1 < a2);
}

original_code:
int32_t
direct_compare(const void *a, const void *b)
{
 ((void) (0));
 ((void) (0));
 return (a > b) - (a < b);
}

canonical_original_code:
int direct_compare(void *a, void *b)
{
 ((void) (0));
 ((void) (0));
 return (a > b) - (a < b);
}

return_type: int


decompiled_code:
bool __fastcall direct_equal(__int64 a1, __int64 a2)
{
return a2 == a1;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1, __int64 a2)
{
return a2 == a1;
}

original_code:
_Bool
direct_equal(const void *a, const void *b)
{
 ((void) (0));
 ((void) (0));
 return a == b;
}

canonical_original_code:
_Bool direct_equal(void *a, void *b)
{
 ((void) (0));
 ((void) (0));
 return a == b;
}


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

a1[2] = 0LL;
a1[4] = 0LL;
a1[1] = a2;
a1[3] = 64LL;
*((_BYTE *)a1 + 32) = 1;
result = malloc(0x40uLL);
*a1 = result;
if ( !result )
{
perror("malloc()");
abort();
}
return result;
}

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

a1[2] = 0LL;
a1[4] = 0LL;
a1[1] = a2;
a1[3] = 64LL;
*((_BYTE *)a1 + 32) = 1;
result = malloc(0x40uLL);
*a1 = result;
if ( !result )
{
perror("malloc()");
abort();
}
return result;
}

original_code:
void
buffer_init(Buffer *buf, size_t max_size)
{
 ((void) (0));
 ((void) (0));
 memset(buf, 0, sizeof(Buffer));
 buf->max_size = max_size;
 buf->msize = 64;
 buf->valid = 1;
 buf->data = (char *)malloc(buf->msize);
 if(!buf->data)
 {
  perror("malloc()");
  abort();
 }
}

canonical_original_code:
void buffer_init(struct Buffer *buf, unsigned long max_size)
{
 ((void) (0));
 ((void) (0));
 memset(buf, 0, sizeof(Buffer));
 buf->max_size = max_size;
 buf->msize = 64;
 buf->valid = 1;
 buf->data = (char *)malloc(buf->msize);
 if(!buf->data)
 {
  perror("malloc()");
  abort();
 }
}

variable_types: struct Buffer { char *data; unsigned long max_size; unsigned long len; unsigned long msize; _Bool valid; } *

return_type: void


decompiled_code:
void __fastcall buffer_free(void **a1)
{
free(*a1);
}

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

original_code:
void
buffer_free(Buffer *buf)
{
 ((void) (0));
 free(buf->data);
}

canonical_original_code:
void buffer_free(struct Buffer *buf)
{
 ((void) (0));
 free(buf->data);
}

user_defined_types: struct Buffer { char *data; unsigned long max_size; unsigned long len; unsigned long msize; _Bool valid; }


decompiled_code:
void __fastcall buffer_destroy(void *ptr)
{
buffer_free((void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
func3((void **)ptr);
free(ptr);
}

original_code:
void
buffer_destroy(Buffer *buf)
{
 ((void) (0));
 buffer_free(buf);
 free(buf);
}

canonical_original_code:
void buffer_destroy(struct Buffer *buf)
{
 ((void) (0));
 buffer_free(buf);
 free(buf);
}


decompiled_code:
void __fastcall buffer_clear(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_BYTE *)(a1 + 32) = 1;
}

original_code:
void
buffer_clear(Buffer *buf)
{
 ((void) (0));
 buf->len = 0;
 buf->valid = 1;
}

canonical_original_code:
void buffer_clear(struct Buffer *buf)
{
 ((void) (0));
 buf->len = 0;
 buf->valid = 1;
}


decompiled_code:
__int64 __fastcall buffer_is_valid(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 32);
}

original_code:
_Bool
buffer_is_valid(const Buffer *buf)
{
 ((void) (0));
 return buf->valid;
}

canonical_original_code:
_Bool buffer_is_valid(struct Buffer *buf)
{
 ((void) (0));
 return buf->valid;
}


decompiled_code:
__int64 __fastcall buffer_len(__int64 a1)
{
char v1; // dl
__int64 result; // rax

v1 = buffer_is_valid(a1);
result = 0LL;
if ( v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
char v1; // dl
__int64 result; // rax

v1 = func6(a1);
result = 0LL;
if ( v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
size_t
buffer_len(const Buffer *buf)
{
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 return buf->len;
}

canonical_original_code:
unsigned long buffer_len(struct Buffer *buf)
{
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 return buf->len;
}


decompiled_code:
char __fastcall buffer_is_empty(__int64 a1)
{
char result; // al

result = buffer_is_valid(a1);
if ( result )
result = *(_QWORD *)(a1 + 16) == 0LL;
return result;
}

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

result = func6(a1);
if ( result )
result = *(_QWORD *)(a1 + 16) == 0LL;
return result;
}

original_code:
_Bool
buffer_is_empty(const Buffer *buf)
{
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 return buf->len == 0;
}

canonical_original_code:
_Bool buffer_is_empty(struct Buffer *buf)
{
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 return buf->len == 0;
}


decompiled_code:
__int64 __fastcall buffer_fill(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
__int64 v6; // rdx
unsigned __int64 v7; // rdi
unsigned __int64 v8; // rax
void *v9; // rax

result = buffer_is_valid(a1);
if ( (_BYTE)result )
{
v6 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 8) - v6 < a3 )
{
fprintf(stderr, "%s(): buffer exceeds allowed maximum size.\n", "buffer_fill");
*(_BYTE *)(a1 + 32) = 0;
}
else
{
v7 = *(_QWORD *)(a1 + 24);
if ( *(_QWORD *)(a1 + 24) - v6 < a3 )
{
v8 = buffer_new_realloc_size(v7, v7 + a3);
*(_QWORD *)(a1 + 24) = v8;
v9 = realloc(*(void **)a1, v8);
*(_QWORD *)a1 = v9;
if ( !v9 )
{
perror("realloc()");
abort();
}
}
memcpy((void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 16)), a2, a3);
*(_QWORD *)(a1 + 16) += a3;
}
result = *(unsigned __int8 *)(a1 + 32);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
__int64 v6; // rdx
unsigned __int64 v7; // rdi
unsigned __int64 v8; // rax
void *v9; // rax

result = func6(a1);
if ( (_BYTE)result )
{
v6 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 8) - v6 < a3 )
{
fprintf(stderr, "%s(): buffer exceeds allowed maximum size.\n", "buffer_fill");
*(_BYTE *)(a1 + 32) = 0;
}
else
{
v7 = *(_QWORD *)(a1 + 24);
if ( *(_QWORD *)(a1 + 24) - v6 < a3 )
{
v8 = func0(v7, v7 + a3);
*(_QWORD *)(a1 + 24) = v8;
v9 = realloc(*(void **)a1, v8);
*(_QWORD *)a1 = v9;
if ( !v9 )
{
perror("realloc()");
abort();
}
}
memcpy((void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 16)), a2, a3);
*(_QWORD *)(a1 + 16) += a3;
}
result = *(unsigned __int8 *)(a1 + 32);
}
return result;
}

original_code:
_Bool
buffer_fill(Buffer *buf, const char *data, size_t len)
{
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 if(buf->max_size - buf->len < len)
 {
  fprintf(stderr, "%s(): buffer exceeds allowed maximum size.\n", __func__);
  buf->valid = 0;
 }
 else
 {
  if(len > buf->msize - buf->len)
  {
   size_t new_size = _buffer_new_realloc_size(buf->msize, buf->msize + len);
   buf->msize = new_size;
   buf->data = (char *)realloc(buf->data, new_size);
   if(!buf->data)
   {
    perror("realloc()");
    abort();
   }
  }
  memcpy(buf->data + buf->len, data, len);
  buf->len += len;
 }
 return buf->valid;
}

canonical_original_code:
_Bool buffer_fill(struct Buffer *buf, char *data, unsigned long len)
{
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 if(buf->max_size - buf->len < len)
 {
  fprintf(stderr, "%s(): buffer exceeds allowed maximum size.\n", __func__);
  buf->valid = 0;
 }
 else
 {
  if(len > buf->msize - buf->len)
  {
   unsigned long new_size = _buffer_new_realloc_size(buf->msize, buf->msize + len);
   buf->msize = new_size;
   buf->data = (char *)realloc(buf->data, new_size);
   if(!buf->data)
   {
    perror("realloc()");
    abort();
   }
  }
  memcpy(buf->data + buf->len, data, len);
  buf->len += len;
 }
 return buf->valid;
}

variable_types:
data
char *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall buffer_fill_from_fd(__int64 a1, int a2, size_t a3)
{
__int64 v4; // rbx
void *v6; // rsp
signed __int64 v7; // rax
_BYTE v8[48]; // [rsp+0h] [rbp-30h] BYREF

v4 = 0LL;
if ( (unsigned __int8)buffer_is_valid(a1) )
{
v6 = alloca(a3);
v7 = read(a2, v8, a3);
v4 = v7;
if ( v7 > 0 )
{
if ( !(unsigned __int8)buffer_fill(a1, v8, v7) )
v4 = -1LL;
}
else if ( v7 == -1 )
{
perror("read()");
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, size_t a3)
{
__int64 v4; // rbx
void *v6; // rsp
signed __int64 v7; // rax
_BYTE v8[48]; // [rsp+0h] [rbp-30h] BYREF

v4 = 0LL;
if ( (unsigned __int8)func6(a1) )
{
v6 = alloca(a3);
v7 = read(a2, v8, a3);
v4 = v7;
if ( v7 > 0 )
{
if ( !(unsigned __int8)func9(a1, v8, v7) )
v4 = -1LL;
}
else if ( v7 == -1 )
{
perror("read()");
}
}
return v4;
}

original_code:
ssize_t
buffer_fill_from_fd(Buffer *buf, int fd, size_t count)
{
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 ssize_t bytes;
 char data[count];
 if((bytes = read(fd, data, count)) > 0)
 {
  if(!buffer_fill(buf, data, bytes))
  {
   bytes = -1;
  }
 }
 else if(bytes == -1)
 {
  perror("read()");
 }
 return bytes;
}

canonical_original_code:
long buffer_fill_from_fd(struct Buffer *buf, int fd, unsigned long count)
{
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 long bytes;
 char data[-1];
 if((bytes = read(fd, data, count)) > 0)
 {
  if(!buffer_fill(buf, data, bytes))
  {
   bytes = -1;
  }
 }
 else if(bytes == -1)
 {
  perror("read()");
 }
 return bytes;
}

variable_types: fd int

variable_types:
count
unsigned long

variable_types: bytes long

variable_types:
data
char [-1]

return_type: long


decompiled_code:
__int64 __fastcall buffer_read_line(__int64 a1, void **a2, size_t *a3)
{
unsigned int v4; // ebp
_BYTE *v5; // r15
_BYTE *v6; // rax
_BYTE *v7; // r12
signed __int64 v8; // r14
size_t v9; // rdx

v4 = buffer_is_valid(a1);
if ( (_BYTE)v4 )
{
v5 = *(_BYTE **)a1;
v6 = memchr(*(const void **)a1, 10, *(_QWORD *)(a1 + 16));
v7 = v6;
if ( v6 )
{
v8 = v6 - v5;
buffer_copy_to_string((const void **)a1, v6 - v5, a2, a3);
v9 = *(_QWORD *)(a1 + 16) + ~v8;
*(_QWORD *)(a1 + 16) = v9;
memmove(*(void **)a1, v7 + 1, v9);
}
else
{
v4 = 0;
}
}
return v4;
}

original_code:
_Bool
buffer_read_line(Buffer *buf, char **dst, size_t *len)
{
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 char *ptr;
 _Bool found = 0;
 if((ptr = memchr(buf->data, '\n', buf->len)))
 {
  size_t slen = ptr - buf->data;
  _buffer_copy_to_string(buf, slen, dst, len);
  buf->len -= slen + 1;
  memmove(buf->data, ptr + 1, buf->len);
  found = 1;
 }
 return found;
}

canonical_original_code:
_Bool buffer_read_line(struct Buffer *buf, char **dst, unsigned long *len)
{
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 char *ptr;
 _Bool found = 0;
 if((ptr = memchr(buf->data, '\n', buf->len)))
 {
  unsigned long slen = ptr - buf->data;
  _buffer_copy_to_string(buf, slen, dst, len);
  buf->len -= slen + 1;
  memmove(buf->data, ptr + 1, buf->len);
  found = 1;
 }
 return found;
}

variable_types:
dst
char **

variable_types:
len
unsigned long *

variable_types:
ptr
char *

variable_types:
slen
unsigned long


decompiled_code:
__int64 __fastcall buffer_flush(__int64 a1, void **a2, size_t *a3)
{
unsigned int v5; // ebx
size_t v6; // rsi

v5 = buffer_is_valid(a1);
if ( (_BYTE)v5 )
{
v6 = *(_QWORD *)(a1 + 16);
if ( v6 )
buffer_copy_to_string((const void **)a1, v6, a2, a3);
else
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, void **a2, size_t *a3)
{
unsigned int v5; // ebx
size_t v6; // rsi

v5 = func6(a1);
if ( (_BYTE)v5 )
{
v6 = *(_QWORD *)(a1 + 16);
if ( v6 )
func1((const void **)a1, v6, a2, a3);
else
v5 = 0;
}
return v5;
}

original_code:
_Bool
buffer_flush(const Buffer *buf, char **dst, size_t *len)
{
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 _Bool flushed = 0;
 if(buf->len)
 {
  _buffer_copy_to_string(buf, buf->len, dst, len);
  flushed = 1;
 }
 return flushed;
}

canonical_original_code:
_Bool buffer_flush(struct Buffer *buf, char **dst, unsigned long *len)
{
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if(!buffer_is_valid(buf)) return 0;
 _Bool flushed = 0;
 if(buf->len)
 {
  _buffer_copy_to_string(buf, buf->len, dst, len);
  flushed = 1;
 }
 return flushed;
}


decompiled_code:
void __fastcall memory_pool_destroy(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp
__int64 v3; // rbx
void **v4; // rbp

v1 = *((_QWORD *)ptr + 2);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 16);
free(*v2);
free(v2);
}
v3 = *((_QWORD *)ptr + 3);
while ( v3 )
{
v4 = (void **)v3;
v3 = *(_QWORD *)(v3 + 16);
free(*v4);
free(v4);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp
__int64 v3; // rbx
void **v4; // rbp

v1 = *((_QWORD *)ptr + 2);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 16);
free(*v2);
free(v2);
}
v3 = *((_QWORD *)ptr + 3);
while ( v3 )
{
v4 = (void **)v3;
v3 = *(_QWORD *)(v3 + 16);
free(*v4);
free(v4);
}
free(ptr);
}

original_code:
void
memory_pool_destroy(MemoryPool *pool)
{
 struct _MemoryBlock *iter;
 struct _MemoryPtrBlock *piter;
 ((void) (0));
 iter = pool->block;
 while(iter)
 {
  struct _MemoryBlock *block;
  block = iter;
  iter = iter->next;
  free(block->items);
  free(block);
 }
 piter = pool->free_block;
 while(piter)
 {
  struct _MemoryPtrBlock *pblock;
  pblock = piter;
  piter = piter->next;
  free(pblock->items);
  free(pblock);
 }
 free(pool);
}

canonical_original_code:
void memory_pool_destroy(struct MemoryPool *pool)
{
 struct _MemoryBlock *iter;
 struct _MemoryPtrBlock *piter;
 ((void) (0));
 iter = pool->block;
 while(iter)
 {
  struct _MemoryBlock *block;
  block = iter;
  iter = iter->next;
  free(block->items);
  free(block);
 }
 piter = pool->free_block;
 while(piter)
 {
  struct _MemoryPtrBlock *pblock;
  pblock = piter;
  piter = piter->next;
  free(pblock->items);
  free(pblock);
 }
 free(pool);
}

variable_types: struct MemoryPool { struct _Pool { void *(*alloc)(struct _Pool *pool); void (*free)(struct _Pool *pool, void *ptr); } padding; struct _MemoryBlock { char *items; unsigned long offset; struct _MemoryBlock *next; } *block; struct _MemoryPtrBlock { void **items; unsigned long offset; struct _MemoryPtrBlock *next; } *free_block; unsigned long block_size; unsigned long item_size; } *

user_defined_types: struct MemoryPool { struct _Pool padding; struct _MemoryBlock *block; struct _MemoryPtrBlock *free_block; unsigned long block_size; unsigned long item_size; }


waz

decompiled_code:
__int64 __fastcall waz(const char *a1)
{
bool v1; // zf
unsigned int v2; // ecx

v1 = strcmp(a1, "LOOKUP") == 0;
v2 = 3;
if ( strcmp(a1, "UPDATE") )
v2 = v1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
bool v1; // zf
unsigned int v2; // ecx

v1 = strcmp(a1, "LOOKUP") == 0;
v2 = 3;
if ( strcmp(a1, "UPDATE") )
v2 = v1;
return v2;
}

original_code:
int
waz(char *up) {
 int upbit;
 upbit = NONE;
 upbit = (strcmp(up , "LOOKUP")) ? upbit : LOOKUP;
 upbit = (strcmp(up , "UPDATE")) ? upbit : UPDATE;
 return upbit;
}

variable_types:
up
char *

variable_types: upbit int


decompiled_code:
char *__fastcall mk_btreel(char *dest, char *src, int a3, const char *a4, const char *a5, const char *a6)
{
Dlog("mk_btreel");
if ( a3 == 1 )
{
*(_WORD *)dest = 49;
}
else if ( a3 == 3 )
{
*(_WORD *)dest = 51;
}
strcat(dest, src);
strcat(dest, a4);
strcat(dest, src);
strcat(dest, a5);
strcat(dest, src);
return strcat(dest, a6);
}

canonical_decompiled_code:
char *__fastcall func1(char *dest, char *src, int a3, const char *a4, const char *a5, const char *a6)
{
Dlog("mk_btreel");
if ( a3 == 1 )
{
*(_WORD *)dest = 49;
}
else if ( a3 == 3 )
{
*(_WORD *)dest = 51;
}
strcat(dest, src);
strcat(dest, a4);
strcat(dest, src);
strcat(dest, a5);
strcat(dest, src);
return strcat(dest, a6);
}

original_code:
char *
mk_btreel(char *l, char *delim, int op, char *phon, char *name, char *last) {
 Dlog("mk_btreel");
 switch (op) {
  case LOOKUP:
   l = strcpy(l, "1");
   break;
  case UPDATE:
   l = strcpy(l, "3");
   break;
  default:
   break;
 }
 l = strcat(l, delim);
 l = strcat(l, phon);
 l = strcat(l, delim);
 l = strcat(l, name);
 l = strcat(l, delim);
 l = strcat(l, last);
 return l;
}

canonical_original_code:
char *mk_btreel(char *l, char *delim, int op, char *phon, char *name, char *last) {
 Dlog("mk_btreel");
 switch (op) {
  case LOOKUP:
   l = strcpy(l, "1");
   break;
  case UPDATE:
   l = strcpy(l, "3");
   break;
  default:
   break;
 }
 l = strcat(l, delim);
 l = strcat(l, phon);
 l = strcat(l, delim);
 l = strcat(l, name);
 l = strcat(l, delim);
 l = strcat(l, last);
 return l;
}

variable_types:
l
char *

variable_types:
delim
char *

variable_types: op int

variable_types:
phon
char *

variable_types:
name
char *

variable_types:
last
char *

return_type: char *


decompiled_code:
__int64 __fastcall parse_up(char *dest, const char *a2, const char *a3, const char *a4, const char *a5)
{
__int64 v8; // rbx
char *v9; // rax
__int64 result; // rax
char *v11; // rax
__int64 v12; // [rsp+0h] [rbp-E8h] BYREF
__int64 v13; // [rsp+8h] [rbp-E0h]
__int64 v14; // [rsp+10h] [rbp-D8h]
__int64 v15; // [rsp+18h] [rbp-D0h]
__int64 v16; // [rsp+20h] [rbp-C8h]
__int64 v17; // [rsp+28h] [rbp-C0h]
__int64 v18; // [rsp+30h] [rbp-B8h]
__int64 v19; // [rsp+38h] [rbp-B0h]
__int64 v20; // [rsp+40h] [rbp-A8h]
__int64 v21; // [rsp+48h] [rbp-A0h]
__int16 v22; // [rsp+50h] [rbp-98h]
char v23; // [rsp+52h] [rbp-96h]
char v24[20]; // [rsp+5Ch] [rbp-8Ch] BYREF
char v25[120]; // [rsp+70h] [rbp-78h] BYREF

Dlog("parse_up");
strcpy(&v25[16], "Alice doesn't live here anymore!\n");
strcpy(v25, "now lives here\n");
strcpy(&v24[11], "up2date\n");
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up");
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, 3LL);
fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, 1LL);
v8 = (unsigned int)waz(a2);
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, v8);
strcpy(v24, "5143169147");
if ( (_DWORD)v8 == 1 )
{
if ( (unsigned int)isfield(a2, v24, a4, a5) )
{
Dlog("after isfield");
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0;
v23 = 0;
v11 = mk_btreel(dest, delim, 1, v24, a4, a5);
send_recv_2pbk_skt(v11, &v12);
if ( (_BYTE)v12 == 48 )
printf("%s", &v25[16]);
else
puts((const char *)&v12);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( (unsigned int)isfield(a2, a3, a4, a5) )
{
Dlog("after isfield");
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0;
v23 = 0;
v9 = mk_btreel(dest, delim, v8, a3, a4, a5);
send_recv_2pbk_skt(v9, &v12);
result = 0LL;
if ( (_DWORD)v8 == 3 )
{
if ( (_BYTE)v12 == 48 )
printf("%s %s %s", a4, a5, v25);
else
printf("%s %s %s %s", a4, a5, a3, &v24[11]);
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *dest, const char *a2, const char *a3, const char *a4, const char *a5)
{
__int64 v8; // rbx
char *v9; // rax
__int64 result; // rax
char *v11; // rax
__int64 v12; // [rsp+0h] [rbp-E8h] BYREF
__int64 v13; // [rsp+8h] [rbp-E0h]
__int64 v14; // [rsp+10h] [rbp-D8h]
__int64 v15; // [rsp+18h] [rbp-D0h]
__int64 v16; // [rsp+20h] [rbp-C8h]
__int64 v17; // [rsp+28h] [rbp-C0h]
__int64 v18; // [rsp+30h] [rbp-B8h]
__int64 v19; // [rsp+38h] [rbp-B0h]
__int64 v20; // [rsp+40h] [rbp-A8h]
__int64 v21; // [rsp+48h] [rbp-A0h]
__int16 v22; // [rsp+50h] [rbp-98h]
char v23; // [rsp+52h] [rbp-96h]
char v24[20]; // [rsp+5Ch] [rbp-8Ch] BYREF
char v25[120]; // [rsp+70h] [rbp-78h] BYREF

Dlog("parse_up");
strcpy(&v25[16], "Alice doesn't live here anymore!\n");
strcpy(v25, "now lives here\n");
strcpy(&v24[11], "up2date\n");
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up");
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, 3LL);
fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, 1LL);
v8 = (unsigned int)func0(a2);
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, v8);
strcpy(v24, "5143169147");
if ( (_DWORD)v8 == 1 )
{
if ( (unsigned int)isfield(a2, v24, a4, a5) )
{
Dlog("after isfield");
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0;
v23 = 0;
v11 = func1(dest, delim, 1, v24, a4, a5);
send_recv_2pbk_skt(v11, &v12);
if ( (_BYTE)v12 == 48 )
printf("%s", &v25[16]);
else
puts((const char *)&v12);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( (unsigned int)isfield(a2, a3, a4, a5) )
{
Dlog("after isfield");
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0;
v23 = 0;
v9 = func1(dest, delim, v8, a3, a4, a5);
send_recv_2pbk_skt(v9, &v12);
result = 0LL;
if ( (_DWORD)v8 == 3 )
{
if ( (_BYTE)v12 == 48 )
printf("%s %s %s", a4, a5, v25);
else
printf("%s %s %s %s", a4, a5, a3, &v24[11]);
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
parse_up(char *qstrp, char *up, char *phon, char *name, char *last) {
 Dlog("parse_up");
 char noalice[] = "Alice doesn't live here anymore!\n";
 char havealice[] = "now lives here\n";
 char upalice[] = "up2date\n";
 int upbit = UPDATE;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, LOOKUP));
 upbit = waz(up);
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 char myphon[] = "5143169147";
 char *myphonp = myphon;
 if(upbit == LOOKUP)
  phon = myphonp;
 if (!(isfield(up, phon, name, last)))
  return -1;
 Dlog("after isfield");
 char buf[((4*20) + 2 + 1)] = {0};
 char *bufp = buf;
 qstrp = mk_btreel(qstrp, delim, upbit, phon, name, last);
 send_recv_2pbk_skt(qstrp, bufp);
 switch (upbit) {
  case LOOKUP:
   if ((buf[0] - '0') == 0)
    printf("%s", noalice);
   else
    printf("%s\n", bufp);
   break;
  case UPDATE:
   if ((buf[0] - '0') == 0)
    printf("%s %s %s", name, last, havealice);
   else
    printf("%s %s %s %s", name, last, phon, upalice);
   break;
  default:
   break;
 }
 return 0;
}

canonical_original_code:
int parse_up(char *qstrp, char *up, char *phon, char *name, char *last) {
 Dlog("parse_up");
 char noalice[] = "Alice doesn't live here anymore!\n";
 char havealice[] = "now lives here\n";
 char upalice[] = "up2date\n";
 int upbit = UPDATE;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, LOOKUP));
 upbit = waz(up);
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 char myphon[] = "5143169147";
 char *myphonp = myphon;
 if(upbit == LOOKUP)
  phon = myphonp;
 if (!(isfield(up, phon, name, last)))
  return -1;
 Dlog("after isfield");
 char buf[-1] = {0};
 char *bufp = buf;
 qstrp = mk_btreel(qstrp, delim, upbit, phon, name, last);
 send_recv_2pbk_skt(qstrp, bufp);
 switch (upbit) {
  case LOOKUP:
   if ((buf[0] - '0') == 0)
    printf("%s", noalice);
   else
    printf("%s\n", bufp);
   break;
  case UPDATE:
   if ((buf[0] - '0') == 0)
    printf("%s %s %s", name, last, havealice);
   else
    printf("%s %s %s %s", name, last, phon, upalice);
   break;
  default:
   break;
 }
 return 0;
}

variable_types:
qstrp
char *

variable_types:
noalice
char []

variable_types:
havealice
char []

variable_types:
upalice
char []

variable_types:
myphon
char []

variable_types:
myphonp
char *

variable_types:
buf
char [-1]

variable_types:
bufp
char *


decompiled_code:
int mk_socket()
{
int result; // eax

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

original_code:
int
mk_socket() {
 int s;
 if ((s = socket(1, SOCK_STREAM, 0)) == -1) {
  perror("socket");
  exit(1);
 }
 return s;
}

variable_types: s int


decompiled_code:
void *__fastcall send_recv_2pbk_skt(void *buf, void *a2)
{
int v2; // ebp
int v3; // eax
size_t v4; // rax
int v5; // eax
int v6; // ebp
struct sockaddr v8[8]; // [rsp+0h] [rbp-88h] BYREF

v2 = mk_socket();
v8[0].sa_family = 1;
strcpy(v8[0].sa_data, "/tmp/22294");
v3 = strlen(v8[0].sa_data);
if ( connect(v2, v8, v3 + 2) == -1 )
{
perror("connect");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, (const char *)buf);
v4 = strlen((const char *)buf);
if ( send(v2, buf, v4, 0) == -1 )
{
perror("send");
exit(1);
}
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
v5 = recv(v2, a2, 0x53uLL, 0);
v6 = v5;
if ( v5 <= 0 )
{
if ( v5 < 0 )
perror("recv");
else
printf("\x1B[31mpbkc:\tServer closed connection\n\x1B[0m");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()");
*((_BYTE *)a2 + v6) = 0;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
return a2;
}

canonical_decompiled_code:
void *__fastcall func1(void *buf, void *a2)
{
int v2; // ebp
int v3; // eax
size_t v4; // rax
int v5; // eax
int v6; // ebp
struct sockaddr v8[8]; // [rsp+0h] [rbp-88h] BYREF

v2 = func0();
v8[0].sa_family = 1;
strcpy(v8[0].sa_data, "/tmp/22294");
v3 = strlen(v8[0].sa_data);
if ( connect(v2, v8, v3 + 2) == -1 )
{
perror("connect");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, (const char *)buf);
v4 = strlen((const char *)buf);
if ( send(v2, buf, v4, 0) == -1 )
{
perror("send");
exit(1);
}
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
v5 = recv(v2, a2, 0x53uLL, 0);
v6 = v5;
if ( v5 <= 0 )
{
if ( v5 < 0 )
perror("recv");
else
printf("\x1B[31mpbkc:\tServer closed connection\n\x1B[0m");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()");
*((_BYTE *)a2 + v6) = 0;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
return a2;
}

original_code:
char *
send_recv_2pbk_skt(char *qstrp, char *bufp) {
 int s, len;
 int t;
 struct sockaddr_un remote;
 s = mk_socket();
 remote.sun_family = 1;
 strcpy(remote.sun_path, "/tmp/22294");
 len = strlen(remote.sun_path) + sizeof(remote.sun_family);
 if (connect(s, (struct sockaddr *)&remote, len) == -1) {
  perror("connect");
  exit(1);
 }
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
 (fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, qstrp));
 if (send(s, qstrp, strlen(qstrp), 0) == -1) {
  perror("send");
  exit(1);
 }
 (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
 if ((t = recv(s, bufp, ((4*20) + 2 + 1), 0)) > 0) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()"));
  bufp[t] = '\0';
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  return bufp;
 } else {
  if (t < 0) perror("recv");
  else printf("\033[31m" "pbkc:\tServer closed connection\n" "\033[0m");
  exit(1);
 }
 close(s);
}

canonical_original_code:
char *send_recv_2pbk_skt(char *qstrp, char *bufp) {
 int s; int len;
 int t;
 struct sockaddr_un remote;
 s = mk_socket();
 remote.sun_family = 1;
 strcpy(remote.sun_path, "/tmp/22294");
 len = strlen(remote.sun_path) + sizeof(remote.sun_family);
 if (connect(s, (struct sockaddr *)&remote, len) == -1) {
  perror("connect");
  exit(1);
 }
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
 (fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, qstrp));
 if (send(s, qstrp, strlen(qstrp), 0) == -1) {
  perror("send");
  exit(1);
 }
 (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
 if ((t = recv(s, bufp, ((4*20) + 2 + 1), 0)) > 0) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()"));
  bufp[t] = '\0';
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  return bufp;
 } else {
  if (t < 0) perror("recv");
  else printf("\033[31m" "pbkc:\tServer closed connection\n" "\033[0m");
  exit(1);
 }
 close(s);
}

variable_types: len int

variable_types: t int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

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


cgigetval

decompiled_code:
char *__fastcall cgigetval(const char *a1)
{
int v1; // er15
char *v2; // rbx
char *v3; // rbx
int v4; // er13
char v5; // r14
char *v6; // r12
char *v7; // rax
char *v8; // rbp
int v9; // er13
char *v10; // rax

if ( querystring_0 || (v3 = getenv("QUERY_STRING"), (querystring_0 = v3) != 0LL) )
{
if ( a1 )
{
v1 = strlen(a1);
v2 = querystring_0;
while ( 2 )
{
v5 = *v2;
do
{
if ( !v5 )
return 0LL;
v6 = strchr(v2, 61);
v7 = strchr(v2, 38);
v8 = v7;
if ( v7 )
v4 = (_DWORD)v7 - (_DWORD)v2;
else
v4 = strlen(v2);
}
while ( (v8 != 0LL || v6 == 0LL) && v6 > v8 );
if ( v1 != (_DWORD)v6 - (_DWORD)v2 || strncmp(a1, v2, (int)v6 - (int)v2) )
{
v2 += (v2[v4] == 38) + (__int64)v4;
continue;
}
break;
}
v9 = v4 - ((_DWORD)v6 - (_DWORD)v2);
v10 = (char *)malloc(v9);
v3 = v10;
if ( v10 )
unescstring(v6 + 1, (unsigned int)(v9 - 1), v10, (unsigned int)v9);
}
else
{
v3 = 0LL;
}
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
int v1; // er15
char *v2; // rbx
char *v3; // rbx
int v4; // er13
char v5; // r14
char *v6; // r12
char *v7; // rax
char *v8; // rbp
int v9; // er13
char *v10; // rax

if ( querystring_0 || (v3 = getenv("QUERY_STRING"), (querystring_0 = v3) != 0LL) )
{
if ( a1 )
{
v1 = strlen(a1);
v2 = querystring_0;
while ( 2 )
{
v5 = *v2;
do
{
if ( !v5 )
return 0LL;
v6 = strchr(v2, 61);
v7 = strchr(v2, 38);
v8 = v7;
if ( v7 )
v4 = (_DWORD)v7 - (_DWORD)v2;
else
v4 = strlen(v2);
}
while ( (v8 != 0LL || v6 == 0LL) && v6 > v8 );
if ( v1 != (_DWORD)v6 - (_DWORD)v2 || strncmp(a1, v2, (int)v6 - (int)v2) )
{
v2 += (v2[v4] == 38) + (__int64)v4;
continue;
}
break;
}
v9 = v4 - ((_DWORD)v6 - (_DWORD)v2);
v10 = (char *)malloc(v9);
v3 = v10;
if ( v10 )
unescstring(v6 + 1, (unsigned int)(v9 - 1), v10, (unsigned int)v9);
}
else
{
v3 = 0LL;
}
}
return v3;
}

original_code:
char *cgigetval(char *fieldname)
{
 int fnamelen;
 char *p, *p2, *p3;
 int len1, len2;
 static char *querystring = ((void *)0);
 if(querystring == ((void *)0))
 {
  querystring = getenv("QUERY_STRING");
  if(querystring == ((void *)0))
   return ((void *)0);
 }
 if(fieldname == ((void *)0))
  return ((void *)0);
 fnamelen = strlen(fieldname);
 for(p = querystring; *p != '\0';)
 {
  p2 = strchr(p, '=');
  p3 = strchr(p, '&');
  if(p3 != ((void *)0))
   len2 = p3 - p;
  else
   len2 = strlen(p);
  if((p2 == ((void *)0) || p3 != ((void *)0)) && (p2 > p3))
  {
   p3 += len2;
   continue;
  }
  len1 = p2 - p;
  if(len1 == fnamelen && strncmp(fieldname, p, len1) == 0)
  {
   int retlen = len2 - len1 - 1;
   char *retbuf = malloc(retlen + 1);
   if(retbuf == ((void *)0))
    return ((void *)0);
   unescstring(p2 + 1, retlen, retbuf, retlen+1);
   return retbuf;
  }
  p += len2;
  if(*p == '&')
   p++;
 }
 return ((void *)0);
}

canonical_original_code:
char *cgigetval(char *fieldname)
{
 int fnamelen;
 char *p; char *p2; char *p3;
 int len1; int len2;
 static char *querystring = ((void *)0);
 if(querystring == ((void *)0))
 {
  querystring = getenv("QUERY_STRING");
  if(querystring == ((void *)0))
   return ((void *)0);
 }
 if(fieldname == ((void *)0))
  return ((void *)0);
 fnamelen = strlen(fieldname);
 for(p = querystring; *p != '\0';)
 {
  p2 = strchr(p, '=');
  p3 = strchr(p, '&');
  if(p3 != ((void *)0))
   len2 = p3 - p;
  else
   len2 = strlen(p);
  if((p2 == ((void *)0) || p3 != ((void *)0)) && (p2 > p3))
  {
   p3 += len2;
   continue;
  }
  len1 = p2 - p;
  if(len1 == fnamelen && strncmp(fieldname, p, len1) == 0)
  {
   int retlen = len2 - len1 - 1;
   char *retbuf = malloc(retlen + 1);
   if(retbuf == ((void *)0))
    return ((void *)0);
   unescstring(p2 + 1, retlen, retbuf, retlen+1);
   return retbuf;
  }
  p += len2;
  if(*p == '&')
   p++;
 }
 return ((void *)0);
}

variable_types:
fieldname
char *

variable_types: fnamelen int

variable_types:
p
char *

variable_types:
querystring
char *

variable_types: retlen int

variable_types:
retbuf
char *


isop

decompiled_code:
_BOOL8 __fastcall isop(unsigned __int64 a1)
{
return a1 <= 5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int64 a1)
{
return a1 <= 5;
}

original_code:
unsigned short int
isop(long long op) {
 if ((NONE <= op) && (op <= BOP))
  return 1;
 else
  return 0;
}

canonical_original_code:
unsigned short isop(long long op) {
 if ((NONE <= op) && (op <= BOP))
  return 1;
 else
  return 0;
}

variable_types:
op
long long

return_type: unsigned short


decompiled_code:
__int64 no_up()
{
puts("Naughty Naughty srv!");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
puts("Naughty Naughty srv!");
return 0LL;
}

original_code:
int
no_up() {
 printf("Naughty Naughty srv!\n");
 return FALSE;
}


isup

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

result = 1LL;
if ( !a1 )
result = no_up();
return result;
}

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

result = 1LL;
if ( !a1 )
result = func1();
return result;
}

original_code:
int
isup(char *up) {
 if(up == ((void *)0))
  return no_up();
 return TRUE;
}

variable_types:
up
char *


decompiled_code:
__int64 long_phon()
{
printf("Bad phone!\nneed exactly %d digits!\n", 10LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
printf("Bad phone!\nneed exactly %d digits!\n", 10LL);
return 0LL;
}

original_code:
int
long_phon() {
 printf("Bad phone!\nneed exactly %d digits!\n", 10);
 return FALSE;
}


decompiled_code:
__int64 bad_phon_dig()
{
puts("Only digits for phon, please!");
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
puts("Only digits for phon, please!");
return 0LL;
}

original_code:
int
bad_phon_dig() {
 printf("Only digits for phon, please!\n");
 return FALSE;
}


decompiled_code:
__int64 phon_with_zero_start()
{
puts("No phon starts with 0");
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
puts("No phon starts with 0");
return 0LL;
}

original_code:
int
phon_with_zero_start() {
 printf("No phon starts with 0\n");
 return FALSE;
}


isphdigit

decompiled_code:
__int64 __fastcall isphdigit(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rdx
_BYTE *v3; // rcx
__int64 result; // rax

v2 = a1;
v3 = a1 + 10;
do
{
if ( (unsigned __int8)(*v2 - 48) > 9u )
return bad_phon_dig(a1, a2, v2, v3);
++v2;
}
while ( v2 != v3 );
result = 1LL;
if ( *a1 == 48 )
result = phon_with_zero_start();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rdx
_BYTE *v3; // rcx
__int64 result; // rax

v2 = a1;
v3 = a1 + 10;
do
{
if ( (unsigned __int8)(*v2 - 48) > 9u )
return func4(a1, a2, v2, v3);
++v2;
}
while ( v2 != v3 );
result = 1LL;
if ( *a1 == 48 )
result = func5();
return result;
}

original_code:
int
isphdigit(char *phon, int len) {
 for(len = 0; len < 10; len++)
  if (!(phon[len] >= '0' && phon[len] <= '9'))
   return bad_phon_dig();
 if(phon[0] == '0')
  return phon_with_zero_start();
 return TRUE;
}

variable_types:
phon
char *


decompiled_code:
__int64 no_input_phon()
{
printf("No %s !\n", (const char *)&unk_288);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
printf("No %s !\n", (const char *)&unk_288);
return 0LL;
}

original_code:
int
no_input_phon() {
 printf("No %s !\n", "");
 return FALSE;
}


isph

decompiled_code:
__int64 __fastcall isph(char *a1)
{
if ( !a1 )
return no_input_phon();
if ( (unsigned int)strlen(a1) == 10 )
return isphdigit(a1, 10LL);
return long_phon();
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
if ( !a1 )
return func7();
if ( (unsigned int)strlen(a1) == 10 )
return func6(a1, 10LL);
return func3();
}

original_code:
int
isph(char *phon) {
 if(phon == ((void *)0))
  return no_input_phon();
 int len = strlen(phon);
 if(len != 10) {
  return long_phon();
 }
 else
  return isphdigit(phon, len);
}


decompiled_code:
__int64 name_is_long()
{
printf("long long %s !\n", "name");
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
printf("long long %s !\n", "name");
return 0LL;
}

original_code:
int
name_is_long(char *name) {
 printf("long long %s !\n" , "name");
 return FALSE;
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall is_name_alpha(char *a1, int a2)
{
const unsigned __int16 *v2; // rcx
char *v3; // rax
__int64 v4; // rsi

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
while ( (v2[*v3] & 0x400) != 0 )
{
if ( ++v3 == (char *)v4 )
return 1LL;
}
puts("only alpha chars!");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, int a2)
{
const unsigned __int16 *v2; // rcx
char *v3; // rax
__int64 v4; // rsi

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
while ( (v2[*v3] & 0x400) != 0 )
{
if ( ++v3 == (char *)v4 )
return 1LL;
}
puts("only alpha chars!");
return 0LL;
}

original_code:
int
is_name_alpha(char *name, int len) {
 int i;
 for(i = 0; i < len; i++)
  if(!(((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short int) _ISalpha))) {
   printf("only alpha chars!\n");
   return FALSE;
  }
 return TRUE;
}

canonical_original_code:
int is_name_alpha(char *name, int len) {
 int i;
 for(i = 0; i < len; i++)
  if(!(((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short) _ISalpha))) {
   printf("only alpha chars!\n");
   return FALSE;
  }
 return TRUE;
}

variable_types: i int


decompiled_code:
__int64 no_name()
{
printf("No %s!, No man! Naland\n", "name");
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
printf("No %s!, No man! Naland\n", "name");
return 0LL;
}

original_code:
int
no_name() {
 printf("No %s!, No man! Naland\n", "name");
 return FALSE;
}


isn

decompiled_code:
__int64 __fastcall isn(char *a1)
{
int v1; // eax
__int64 result; // rax

if ( !a1 )
return no_name();
v1 = strlen(a1);
if ( v1 <= 20 )
result = is_name_alpha(a1, v1);
else
result = name_is_long("name");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
int v1; // eax
__int64 result; // rax

if ( !a1 )
return func11();
v1 = strlen(a1);
if ( v1 <= 20 )
result = func10(a1, v1);
else
result = func9("name");
return result;
}

original_code:
int
isn(char *name) {
 if(name == ((void *)0))
  return no_name();
 else {
  int len = strlen(name);
  if(20 < len)
   return name_is_long("name");
  else
   return is_name_alpha(name, len);
 }
 return TRUE;
}


isfield

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

result = isup(a1);
if ( (_DWORD)result )
{
result = isph(a2);
if ( (_DWORD)result )
{
result = isn(a3);
if ( (_DWORD)result )
result = (unsigned int)isn(a4) != 0;
}
}
return result;
}

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

result = func2(a1);
if ( (_DWORD)result )
{
result = func8(a2);
if ( (_DWORD)result )
{
result = func12(a3);
if ( (_DWORD)result )
result = (unsigned int)func12(a4) != 0;
}
}
return result;
}

original_code:
int
isfield(char *up, char *ph, char *n, char *l) {
 if (isup(up) && isph(ph) && isn(n) && isn(l))
  return TRUE;
 return FALSE;
}

variable_types:
ph
char *

variable_types:
n
char *

variable_types:
l
char *


isl

decompiled_code:
__int64 __fastcall isl(char *a1)
{
return isn(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1)
{
return func12(a1);
}

original_code:
int
isl(char *last) {
 return isn(last);
}

variable_types:
last
char *


decompiled_code:
__int64 __fastcall addnode_2root(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // eax
int v4; // edx

result = a2;
if ( a1 )
{
v3 = strcmp(*(const char **)(a2 + 8), *(const char **)(a1 + 8));
if ( v3 )
{
if ( v3 < 0 )
*(_QWORD *)(a1 + 40) = addnode_2root(*(_QWORD *)(a1 + 40), a2);
else
*(_QWORD *)(a1 + 56) = addnode_2root(*(_QWORD *)(a1 + 56), a2);
result = a1;
}
else
{
++*(_DWORD *)(a1 + 32);
v4 = strcmp(*(const char **)(a2 + 16), *(const char **)(a1 + 16));
result = a1;
if ( v4 )
{
if ( v4 < 0 )
*(_QWORD *)(a1 + 40) = addnode_2root(*(_QWORD *)(a1 + 40), a2);
else
*(_QWORD *)(a1 + 56) = addnode_2root(*(_QWORD *)(a1 + 56), a2);
result = a1;
}
}
}
return result;
}

original_code:
tnode *
addnode_2root(tnode *root, tnode *node) {
 int cond;
 if (root == ((void *)0)) {
  root = node;
 } else if ((cond = strcmp(node->name, root->name)) == 0) {
  root->count++;
  if ((cond = strcmp(node->last, root->last)) == 0) {
   return root;
  } else if (cond < 0)
   root->left = addnode_2root(root->left, node);
  else
   root->right = addnode_2root(root->right, node);
  return root;
 } else if (cond < 0)
  root->left = addnode_2root(root->left, node);
 else
  root->right = addnode_2root(root->right, node);
 return root;
}

canonical_original_code:
struct tnode *addnode_2root(struct tnode *root, struct tnode *node) {
 int cond;
 if (root == ((void *)0)) {
  root = node;
 } else if ((cond = strcmp(node->name, root->name)) == 0) {
  root->count++;
  if ((cond = strcmp(node->last, root->last)) == 0) {
   return root;
  } else if (cond < 0)
   root->left = addnode_2root(root->left, node);
  else
   root->right = addnode_2root(root->right, node);
  return root;
 } else if (cond < 0)
  root->left = addnode_2root(root->left, node);
 else
  root->right = addnode_2root(root->right, node);
 return root;
}

variable_types:
root
struct tnode *

variable_types:
node
struct tnode *

variable_types: cond int

return_type: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; } *


decompiled_code:
int __fastcall hit_print(__int64 a1)
{
return printf("%d\n", *(unsigned int *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
return printf("%d\n", *(unsigned int *)(a1 + 32));
}

original_code:
void
hit_print(tnode *node) {
 printf("%d\n", node->count);
}

canonical_original_code:
void hit_print(struct tnode *node) {
 printf("%d\n", node->count);
}

variable_types: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; } *


decompiled_code:
int __fastcall node_printf(_QWORD *a1)
{
const char *v1; // r12
const char *v2; // rbp
const char *v3; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = nodef_print(a1, 0LL, 4);
v2 = nodef_print(a1, 0LL, 2);
v3 = nodef_print(a1, v5, 1);
return printf("%s:%s:%s\n", v3, v2, v1);
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1)
{
const char *v1; // r12
const char *v2; // rbp
const char *v3; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = nodef_print(a1, 0LL, 4);
v2 = nodef_print(a1, 0LL, 2);
v3 = nodef_print(a1, v5, 1);
return printf("%s:%s:%s\n", v3, v2, v1);
}

original_code:
void
node_printf(tnode *node) {
 char phon[20];
 char *phonp = phon;
 printf("%s:%s:%s\n",
 nodef_print(node, phonp, PHON),
 nodef_print(node, ((void *)0), NAME),
 nodef_print(node, ((void *)0), LAST));
}

canonical_original_code:
void node_printf(struct tnode *node) {
 char phon[20];
 char *phonp = phon;
 printf("%s:%s:%s\n",
 nodef_print(node, phonp, PHON),
 nodef_print(node, ((void *)0), NAME),
 nodef_print(node, ((void *)0), LAST));
}

variable_types:
phon
char [20]

variable_types:
phonp
char *

user_defined_types: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; }


treeprint

decompiled_code:
int __fastcall treeprint(_QWORD *a1, int a2)
{
int result; // eax

if ( a1 )
{
switch ( a2 )
{
case 1:
treeprint(a1[5], 1LL);
node_printf(a1);
result = treeprint(a1[7], 1LL);
break;
case 2:
treeprint(a1[5], 2LL);
treeprint(a1[7], 2LL);
result = node_printf(a1);
break;
case 0:
node_printf(a1);
treeprint(a1[5], 0LL);
result = treeprint(a1[7], 0LL);
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1, int a2)
{
int result; // eax

if ( a1 )
{
switch ( a2 )
{
case 1:
func3(a1[5], 1LL);
func2(a1);
result = func3(a1[7], 1LL);
break;
case 2:
func3(a1[5], 2LL);
func3(a1[7], 2LL);
result = func2(a1);
break;
case 0:
func2(a1);
func3(a1[5], 0LL);
result = func3(a1[7], 0LL);
break;
}
}
return result;
}

original_code:
void
treeprint(tnode *root, int order) {
 if (root != ((void *)0)) {
  switch (order) {
   case PRE:
    node_printf(root);
    treeprint(root->left, order);
    treeprint(root->right, order);
    break;
   case IN:
    treeprint(root->left, order);
    node_printf(root);
    treeprint(root->right, order);
    break;
   case POST:
    treeprint(root->left, order);
    treeprint(root->right, order);
    node_printf(root);
    break;
   default:
    break;
  }
 }
}

canonical_original_code:
void treeprint(struct tnode *root, int order) {
 if (root != ((void *)0)) {
  switch (order) {
   case PRE:
    node_printf(root);
    treeprint(root->left, order);
    treeprint(root->right, order);
    break;
   case IN:
    treeprint(root->left, order);
    node_printf(root);
    treeprint(root->right, order);
    break;
   case POST:
    treeprint(root->left, order);
    treeprint(root->right, order);
    node_printf(root);
    break;
   default:
    break;
  }
 }
}

variable_types: order int


decompiled_code:
char *__fastcall node2line(unsigned int *a1, const char *a2, char *a3)
{
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

if ( !a1 )
return 0LL;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line");
fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, *a1);
v4 = nodef_print(a1, a3, 0);
strcpy(a3, v4);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v5 = nodef_print(a1, a3, 1);
strcat(a3, v5);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v6 = nodef_print(a1, a3, 2);
strcat(a3, v6);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v7 = nodef_print(a1, a3, 4);
return strcat(a3, v7);
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int *a1, const char *a2, char *a3)
{
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

if ( !a1 )
return 0LL;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line");
fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, *a1);
v4 = nodef_print(a1, a3, 0);
strcpy(a3, v4);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v5 = nodef_print(a1, a3, 1);
strcat(a3, v5);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v6 = nodef_print(a1, a3, 2);
strcat(a3, v6);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v7 = nodef_print(a1, a3, 4);
return strcat(a3, v7);
}

original_code:
char *
node2line(tnode *node, char *delim, char *lbuf) {
 if (node == ((void *)0))
  return ((void *)0);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, node->op));
 lbuf = strcpy(lbuf, nodef_print(node, lbuf, OP));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, PHON));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, NAME));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, LAST));
 return lbuf;
}

canonical_original_code:
char *node2line(struct tnode *node, char *delim, char *lbuf) {
 if (node == ((void *)0))
  return ((void *)0);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, node->op));
 lbuf = strcpy(lbuf, nodef_print(node, lbuf, OP));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, PHON));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, NAME));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, LAST));
 return lbuf;
}

variable_types:
delim
char *

variable_types:
lbuf
char *


decompiled_code:
char *__fastcall kr_strdup(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

original_code:
char *kr_strdup(char *s)
{
     char *p;
      p = (char *) malloc(strlen(s)+1);
      if (p != ((void *)0))
          strcpy(p, s);
      return p;
}

variable_types:
s
char *

variable_types:
p
char *


talloc

decompiled_code:
void *talloc()
{
return malloc(0x40uLL);
}

canonical_decompiled_code:
void *func9()
{
return malloc(0x40uLL);
}

original_code:
tnode *
talloc(void) {
 return (tnode *) malloc(sizeof(tnode));
}

canonical_original_code:
struct tnode *talloc() {
 return (struct tnode *) malloc(sizeof(tnode));
}


decompiled_code:
__int64 __fastcall ins_node(__int64 a1, const char **a2)
{
__int64 *v2; // rax
__int64 *v3; // rbp
const char *v4; // rsi
__int64 result; // rax
_DWORD *v6; // rax
_QWORD *v7; // rax

v2 = lookup(a1, (__int64)a2);
if ( *v2 )
{
v3 = v2;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("found a match updating\n", 1uLL, 0x17uLL, stderr);
v4 = a2[3];
*(_QWORD *)(*v3 + 24) = v4;
strcpy(*(char **)(*v3 + 24), v4);
result = 3LL;
}
else
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("NO match inserting here\n", 1uLL, 0x18uLL, stderr);
v6 = mk_node(0LL, 0, 0, a2[3], a2[1], a2[2]);
v7 = (_QWORD *)addnode_2root(a1, (__int64)v6);
treeprint(v7, 1);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char **a2)
{
__int64 *v2; // rax
__int64 *v3; // rbp
const char *v4; // rsi
__int64 result; // rax
_DWORD *v6; // rax
_QWORD *v7; // rax

v2 = lookup(a1, (__int64)a2);
if ( *v2 )
{
v3 = v2;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("found a match updating\n", 1uLL, 0x17uLL, stderr);
v4 = a2[3];
*(_QWORD *)(*v3 + 24) = v4;
strcpy(*(char **)(*v3 + 24), v4);
result = 3LL;
}
else
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("NO match inserting here\n", 1uLL, 0x18uLL, stderr);
v6 = mk_node(0LL, 0, 0, a2[3], a2[1], a2[2]);
v7 = (_QWORD *)func0(a1, (__int64)v6);
func3(v7, 1);
result = 2LL;
}
return result;
}

original_code:
int
ins_node(tnode *root, tnode *node) {
 int insbit;
 tnode **place_in_tree = lookup(root, node);
 if ((*place_in_tree) == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "NO match inserting here\n"));
  tnode *nnode = ((void *)0);
  nnode = mk_node(nnode, NONE, NONE, node->phon, node->name, node->last);
  root = addnode_2root(root, nnode);
  treeprint(root, IN);
  insbit = INS;
 } else {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "found a match updating\n"));
  (*place_in_tree)->phon = node->phon;
  strcpy((*place_in_tree)->phon, node->phon);
  insbit = UPDATE;
 }
 return insbit;
}

canonical_original_code:
int ins_node(struct tnode *root, struct tnode *node) {
 int insbit;
 struct tnode **place_in_tree = lookup(root, node);
 if ((*place_in_tree) == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "NO match inserting here\n"));
  struct tnode *nnode = ((void *)0);
  nnode = mk_node(nnode, NONE, NONE, node->phon, node->name, node->last);
  root = addnode_2root(root, nnode);
  treeprint(root, IN);
  insbit = INS;
 } else {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "found a match updating\n"));
  (*place_in_tree)->phon = node->phon;
  strcpy((*place_in_tree)->phon, node->phon);
  insbit = UPDATE;
 }
 return insbit;
}

variable_types: insbit int

variable_types: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; } **


decompiled_code:
__int64 __fastcall init_pbook(__int64 a1)
{
FILE *v1; // rax
__int64 v2; // rbx

datafile = fs_house_keeping();
v1 = fopen((const char *)datafile, "r");
dbfp = v1;
if ( !v1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("dbfp is null\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
v2 = grow_btree(v1, a1);
fclose(dbfp);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
FILE *v1; // rax
__int64 v2; // rbx

datafile = fs_house_keeping();
v1 = fopen((const char *)datafile, "r");
dbfp = v1;
if ( !v1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("dbfp is null\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
v2 = grow_btree(v1, a1);
fclose(dbfp);
return v2;
}

original_code:
tnode *
init_pbook(tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "r");
 if(dbfp == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "dbfp is null\n"));
  exit(1);
 }
 root = grow_btree(dbfp, root);
 fclose(dbfp);
 return root;
}

canonical_original_code:
struct tnode *init_pbook(struct tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "r");
 if(dbfp == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "dbfp is null\n"));
  exit(1);
 }
 root = grow_btree(dbfp, root);
 fclose(dbfp);
 return root;
}


decompiled_code:
__int64 __fastcall uinit_pbook(__int64 a1)
{
datafile = fs_house_keeping();
dbfp = fopen((const char *)datafile, "wb");
ugrow_btree(a1, dbfp);
fclose(dbfp);
return datafile;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
datafile = fs_house_keeping();
dbfp = fopen((const char *)datafile, "wb");
ugrow_btree(a1, dbfp);
fclose(dbfp);
return datafile;
}

original_code:
char *
uinit_pbook(tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "wb");
 ugrow_btree(root, dbfp);
 fclose(dbfp);
 return datafile;
}

canonical_original_code:
char *uinit_pbook(struct tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "wb");
 ugrow_btree(root, dbfp);
 fclose(dbfp);
 return datafile;
}


decompiled_code:
__int64 __fastcall load_pbook(const char *a1, unsigned int a2)
{
__int64 result; // rax

if ( a2 == 1 )
{
dbfp = fopen(a1, "r+b");
result = 0LL;
if ( dbfp )
return result;
LABEL_6:
puts("File cannot be opened.\n");
return a2;
}
result = 0LL;
if ( a2 == 2 )
{
dbfp = fopen(a1, "wb");
result = 0LL;
if ( !dbfp )
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, unsigned int a2)
{
__int64 result; // rax

if ( a2 == 1 )
{
dbfp = fopen(a1, "r+b");
result = 0LL;
if ( dbfp )
return result;
LABEL_6:
puts("File cannot be opened.\n");
return a2;
}
result = 0LL;
if ( a2 == 2 )
{
dbfp = fopen(a1, "wb");
result = 0LL;
if ( !dbfp )
goto LABEL_6;
}
return result;
}

original_code:
int
load_pbook(char *datafile, int prm) {
 int ret = 0;
 switch (prm) {
  case RB:
   if ((dbfp = fopen(datafile, "r+b")) == ((void *)0)) {
    puts("File cannot be opened.\n");
    ret = RB;
   }
   break;
  case WB:
   if ((dbfp = fopen(datafile, "wb")) == ((void *)0)) {
    puts("File cannot be opened.\n");
    ret = WB;
   }
   break;
  default:
   break;
 }
 return ret;
}

variable_types:
datafile
char *

variable_types: prm int

variable_types: ret int


decompiled_code:
int __fastcall html_header(const char *a1)
{
puts("Content-Type: text/html; charset=utf-8\n");
puts("<html>");
puts("<head>");
printf("<title>%s</title>\n", a1);
puts("</head>");
puts("<body>");
return puts("<pre>");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts("Content-Type: text/html; charset=utf-8\n");
puts("<html>");
puts("<head>");
printf("<title>%s</title>\n", a1);
puts("</head>");
puts("<body>");
return puts("<pre>");
}

original_code:
void
html_header(char *title){
 printf("Content-Type: text/html; charset=utf-8\n\n");
 printf("<html>\n");
 printf("<head>\n");
 printf("<title>%s</title>\n", title);
 printf("</head>\n");
 printf("<body>\n");
 printf("<pre>\n");
}

variable_types:
title
char *


decompiled_code:
int html_footer()
{
puts("
");
puts("");
return puts("");
}

canonical_decompiled_code:
int func1()
{
puts("
");
puts("");
return puts("");
}

original_code:
void
html_footer(void) {
 printf("
\n");
 printf("\n");
 printf("\n");
}

canonical_original_code:
void html_footer() {
 printf("
\n");
 printf("\n");
 printf("\n");
}


decompiled_code:
int create_pbook_directory()
{
size_t v0; // rax

dir = datafile_path;
strcpy(datafile_path, ".");
v0 = strlen(datafile_path);
*(_QWORD *)&datafile_path[v0] = 0x6769666E6F632E2FLL;
datafile_path[v0 + 8] = 0;
mkdir(datafile_path, 0x1C0u);
strcat(dir, "/pbook");
return mkdir(dir, 0x1C0u);
}

canonical_decompiled_code:
int func0()
{
size_t v0; // rax

dir = datafile_path;
strcpy(datafile_path, ".");
v0 = strlen(datafile_path);
*(_QWORD *)&datafile_path[v0] = 0x6769666E6F632E2FLL;
datafile_path[v0 + 8] = 0;
mkdir(datafile_path, 0x1C0u);
strcat(dir, "/pbook");
return mkdir(dir, 0x1C0u);
}

original_code:
void
create_pbook_directory()
{
 dir = ((void *)0);
 dir = datafile_path;
 strcpy(dir, ".");
 strcat(dir, "/.config");
 mkdir(dir, 0700);
 strcat(dir, "/pbook");
 mkdir(dir, 0700);
}


decompiled_code:
char *set_filename()
{
char *v0; // rbx
char *result; // rax

datafile = (__int64)&datafile_path_name;
v0 = dir;
result = &v0[strlen(dir)];
strcpy(result, "/phonebook");
datafile = (__int64)v0;
return result;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbx
char *result; // rax

datafile = (__int64)&datafile_path_name;
v0 = dir;
result = &v0[strlen(dir)];
strcpy(result, "/phonebook");
datafile = (__int64)v0;
return result;
}

original_code:
void
set_filename() {
 datafile = ((void *)0);
 datafile = datafile_path_name;
 datafile = strcat(dir, "/phonebook");
}


decompiled_code:
__int64 fs_house_keeping()
{
create_pbook_directory();
set_filename();
return datafile;
}

canonical_decompiled_code:
__int64 func2()
{
func0();
func1();
return datafile;
}

original_code:
char *
fs_house_keeping() {
 create_pbook_directory();
 set_filename();
 return datafile;
}

canonical_original_code:
char *fs_house_keeping() {
 create_pbook_directory();
 set_filename();
 return datafile;
}


decompiled_code:
int mk_socket()
{
int result; // eax

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

original_code:
int
mk_socket() {
 int s;
 if ((s = socket(1, SOCK_STREAM, 0)) == -1) {
  perror("socket");
  exit(1);
 }
 return s;
}

variable_types: s int


decompiled_code:
__int64 __fastcall parse_op(char *dest)
{
unsigned int v1; // er12
_DWORD *v2; // rbx
__int64 v4; // rax

v2 = (_DWORD *)l2node(dest, delim);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op");
if ( *v2 == 1 )
{
v4 = *(_QWORD *)lookup(root, v2);
v1 = 0;
if ( v4 )
strcpy(dest, *(const char **)(v4 + 24));
}
else if ( *v2 == 3 )
{
v1 = ins_node(root, v2);
uinit_pbook(root);
if ( v1 == 2 )
v1 = 0;
}
free(v2);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *dest)
{
unsigned int v1; // er12
_DWORD *v2; // rbx
__int64 v4; // rax

v2 = (_DWORD *)l2node(dest, delim);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op");
if ( *v2 == 1 )
{
v4 = *(_QWORD *)lookup(root, v2);
v1 = 0;
if ( v4 )
strcpy(dest, *(const char **)(v4 + 24));
}
else if ( *v2 == 3 )
{
v1 = ins_node(root, v2);
uinit_pbook(root);
if ( v1 == 2 )
v1 = 0;
}
free(v2);
return v1;
}

original_code:
int
parse_op(char *bufp) {
 int insbit;
 tnode *qn = ((void *)0);
 tnode **qnp = ((void *)0);
 qn = l2node(bufp, delim);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op"));
 switch (qn->op) {
  case LOOKUP:
   if ((*(qnp = lookup(root, qn))) != ((void *)0))
    strcpy(bufp, (*qnp)->phon);
   else
    insbit = NONE;
   break;
  case UPDATE:
   insbit = ins_node(root, qn);
   uinit_pbook(root);
   switch (insbit) {
    case INS:
     insbit = NONE;
     break;
    case UPDATE:
     insbit = UPDATE;
     break;
    default:
     break;
   }
  default:
   break;
 }
 free(qn);
 return insbit;
}

canonical_original_code:
int parse_op(char *bufp) {
 int insbit;
 struct tnode *qn = ((void *)0);
 struct tnode **qnp = ((void *)0);
 qn = l2node(bufp, delim);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op"));
 switch (qn->op) {
  case LOOKUP:
   if ((*(qnp = lookup(root, qn))) != ((void *)0))
    strcpy(bufp, (*qnp)->phon);
   else
    insbit = NONE;
   break;
  case UPDATE:
   insbit = ins_node(root, qn);
   uinit_pbook(root);
   switch (insbit) {
    case INS:
     insbit = NONE;
     break;
    case UPDATE:
     insbit = UPDATE;
     break;
    default:
     break;
   }
  default:
   break;
 }
 free(qn);
 return insbit;
}

variable_types:
bufp
char *


decompiled_code:
__int64 __fastcall read_from_client(int fd)
{
int v1; // eax
size_t v2; // rax
ssize_t v3; // rdx
__int64 result; // rax
char src[2]; // [rsp+Eh] [rbp-6Ah] BYREF
__int64 buf[10]; // [rsp+10h] [rbp-68h] BYREF
__int16 v7; // [rsp+60h] [rbp-18h]
char v8; // [rsp+62h] [rbp-16h]

buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
buf[5] = 0LL;
buf[6] = 0LL;
buf[7] = 0LL;
buf[8] = 0LL;
buf[9] = 0LL;
v7 = 0;
v8 = 0;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "read()");
v1 = read(fd, buf, 0x53uLL);
*((_BYTE *)buf + v1) = 0;
if ( v1 < 0 )
{
perror("read");
exit(1);
}
if ( !v1 )
return 0xFFFFFFFFLL;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
if ( !(unsigned int)parse_op((char *)buf) )
{
strcpy(src, "0");
strcpy((char *)buf, src);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
v2 = strlen((const char *)buf);
v3 = send(fd, buf, v2 + 1, 0);
result = 0LL;
if ( v3 < 0 )
{
perror("send");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
int v1; // eax
size_t v2; // rax
ssize_t v3; // rdx
__int64 result; // rax
char src[2]; // [rsp+Eh] [rbp-6Ah] BYREF
__int64 buf[10]; // [rsp+10h] [rbp-68h] BYREF
__int16 v7; // [rsp+60h] [rbp-18h]
char v8; // [rsp+62h] [rbp-16h]

buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
buf[5] = 0LL;
buf[6] = 0LL;
buf[7] = 0LL;
buf[8] = 0LL;
buf[9] = 0LL;
v7 = 0;
v8 = 0;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "read()");
v1 = read(fd, buf, 0x53uLL);
*((_BYTE *)buf + v1) = 0;
if ( v1 < 0 )
{
perror("read");
exit(1);
}
if ( !v1 )
return 0xFFFFFFFFLL;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
if ( !(unsigned int)func1((char *)buf) )
{
strcpy(src, "0");
strcpy((char *)buf, src);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
v2 = strlen((const char *)buf);
v3 = send(fd, buf, v2 + 1, 0);
result = 0LL;
if ( v3 < 0 )
{
perror("send");
result = 0LL;
}
return result;
}

original_code:
int
read_from_client(int filedes) {
 char buf[((4*20) + 2 + 1)] = {0};
 char *bufp = buf;
 int nbytes;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "read()"));
 nbytes = read (filedes, buf, ((4*20) + 2 + 1));
 bufp[nbytes] = '\0';
 if (nbytes < 0) {
    perror ("read");
    exit (1);
 }
 else if (nbytes == 0)
  return -1;
 else {
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (parse_op(bufp) == NONE) {
   char none[] = "0";
   char *nonep = none;
   strcpy(bufp, nonep);
  }
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (send(filedes, bufp, (strlen(bufp)+1), 0) < 0) {
   perror("send");
  }
  return 0;
 }
}

canonical_original_code:
int read_from_client(int filedes) {
 char buf[-1] = {0};
 char *bufp = buf;
 int nbytes;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "read()"));
 nbytes = read (filedes, buf, ((4*20) + 2 + 1));
 bufp[nbytes] = '\0';
 if (nbytes < 0) {
    perror ("read");
    exit (1);
 }
 else if (nbytes == 0)
  return -1;
 else {
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (parse_op(bufp) == NONE) {
   char none[] = "0";
   char *nonep = none;
   strcpy(bufp, nonep);
  }
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (send(filedes, bufp, (strlen(bufp)+1), 0) < 0) {
   perror("send");
  }
  return 0;
 }
}

variable_types: filedes int

variable_types:
buf
char [-1]

variable_types: nbytes int

variable_types:
nonep
char *


decompiled_code:
int recv_send_2pbk_skt()
{
int v0; // er14
int v1; // eax
int v2; // er15
__int64 v3; // rsi
__int64 v4; // rdx
int v5; // er13
__int64 v6; // rax
int i; // ebx
int v8; // ebp
int v10; // [rsp+Ch] [rbp-2ACh]
__int64 v11[16]; // [rsp+10h] [rbp-2A8h] BYREF
fd_set readfds; // [rsp+90h] [rbp-228h] BYREF
__m128i v13[8]; // [rsp+110h] [rbp-1A8h] BYREF
struct sockaddr v14; // [rsp+190h] [rbp-128h] BYREF
struct sockaddr addr; // [rsp+200h] [rbp-B8h] BYREF
socklen_t addr_len[2]; // [rsp+278h] [rbp-40h] BYREF

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt");
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("creating the socket\n", 1uLL, 0x14uLL, stderr);
v0 = mk_socket();
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
addr.sa_family = 1;
strcpy(addr.sa_data, "/tmp/22294");
unlink(addr.sa_data);
v1 = strlen(addr.sa_data);
if ( bind(v0, &addr, v1 + 2) == -1 )
{
perror("bind");
exit(1);
}
if ( listen(v0, 5) == -1 )
{
perror("listen");
exit(1);
}
memset(v13, 0, sizeof(v13));
v2 = fileno(stdin);
v13[0].m128i_i64[v2 / 64] |= 1LL << (v2 % 64);
v3 = 1LL << (v0 % 64);
v4 = v0 / 64;
v13[0].m128i_i64[v4] |= v3;
memset(v11, 0, sizeof(v11));
v11[v4] |= v3;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("send \"EOF\" with Ctrl-D to stop the daemon or\n", 1uLL, 0x2DuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Waiting for a connection...\n", 1uLL, 0x1CuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("selecting the set\n", 1uLL, 0x12uLL, stderr);
v10 = 0;
while ( 2 )
{
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v13);
*(__m128i *)&readfds.fds_bits[2] = _mm_loadu_si128(&v13[1]);
*(__m128i *)&readfds.fds_bits[4] = _mm_loadu_si128(&v13[2]);
*(__m128i *)&readfds.fds_bits[6] = _mm_loadu_si128(&v13[3]);
*(__m128i *)&readfds.fds_bits[8] = _mm_loadu_si128(&v13[4]);
*(__m128i *)&readfds.fds_bits[10] = _mm_loadu_si128(&v13[5]);
*(__m128i *)&readfds.fds_bits[12] = _mm_loadu_si128(&v13[6]);
*(__m128i *)&readfds.fds_bits[14] = _mm_loadu_si128(&v13[7]);
if ( select(1024, &readfds, 0LL, 0LL, 0LL) < 0 )
{
perror("select");
exit(1);
}
v8 = 1;
for ( i = 0; ; ++i )
{
v6 = i / 64;
if ( (readfds.fds_bits[v6] & (1LL << (i % 64))) == 0 )
break;
if ( v0 == i )
{
*(_QWORD *)addr_len = 110LL;
v5 = accept(i, &v14, addr_len);
if ( v5 < 0 )
{
perror("accept");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Connected.\n", 1uLL, 0xBuLL, stderr);
read_from_client(v5);
v6 = v5 / 64;
v13[0].m128i_i64[v6] |= 1LL << (v5 % 64);
break;
}
if ( v2 != i )
break;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("not sock\n", 1uLL, 9uLL, stderr);
LODWORD(v6) = getchar();
if ( (_DWORD)v6 != -1 )
break;
LODWORD(v6) = close(v0);
if ( v8 > 1023 )
return v6;
v10 = 1;
LABEL_10:
++v8;
}
if ( v8 <= 1023 )
goto LABEL_10;
if ( v10 != 1 )
continue;
return v6;
}
}

canonical_decompiled_code:
int func3()
{
int v0; // er14
int v1; // eax
int v2; // er15
__int64 v3; // rsi
__int64 v4; // rdx
int v5; // er13
__int64 v6; // rax
int i; // ebx
int v8; // ebp
int v10; // [rsp+Ch] [rbp-2ACh]
__int64 v11[16]; // [rsp+10h] [rbp-2A8h] BYREF
fd_set readfds; // [rsp+90h] [rbp-228h] BYREF
__m128i v13[8]; // [rsp+110h] [rbp-1A8h] BYREF
struct sockaddr v14; // [rsp+190h] [rbp-128h] BYREF
struct sockaddr addr; // [rsp+200h] [rbp-B8h] BYREF
socklen_t addr_len[2]; // [rsp+278h] [rbp-40h] BYREF

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt");
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("creating the socket\n", 1uLL, 0x14uLL, stderr);
v0 = func0();
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
addr.sa_family = 1;
strcpy(addr.sa_data, "/tmp/22294");
unlink(addr.sa_data);
v1 = strlen(addr.sa_data);
if ( bind(v0, &addr, v1 + 2) == -1 )
{
perror("bind");
exit(1);
}
if ( listen(v0, 5) == -1 )
{
perror("listen");
exit(1);
}
memset(v13, 0, sizeof(v13));
v2 = fileno(stdin);
v13[0].m128i_i64[v2 / 64] |= 1LL << (v2 % 64);
v3 = 1LL << (v0 % 64);
v4 = v0 / 64;
v13[0].m128i_i64[v4] |= v3;
memset(v11, 0, sizeof(v11));
v11[v4] |= v3;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("send \"EOF\" with Ctrl-D to stop the daemon or\n", 1uLL, 0x2DuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Waiting for a connection...\n", 1uLL, 0x1CuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("selecting the set\n", 1uLL, 0x12uLL, stderr);
v10 = 0;
while ( 2 )
{
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v13);
*(__m128i *)&readfds.fds_bits[2] = _mm_loadu_si128(&v13[1]);
*(__m128i *)&readfds.fds_bits[4] = _mm_loadu_si128(&v13[2]);
*(__m128i *)&readfds.fds_bits[6] = _mm_loadu_si128(&v13[3]);
*(__m128i *)&readfds.fds_bits[8] = _mm_loadu_si128(&v13[4]);
*(__m128i *)&readfds.fds_bits[10] = _mm_loadu_si128(&v13[5]);
*(__m128i *)&readfds.fds_bits[12] = _mm_loadu_si128(&v13[6]);
*(__m128i *)&readfds.fds_bits[14] = _mm_loadu_si128(&v13[7]);
if ( select(1024, &readfds, 0LL, 0LL, 0LL) < 0 )
{
perror("select");
exit(1);
}
v8 = 1;
for ( i = 0; ; ++i )
{
v6 = i / 64;
if ( (readfds.fds_bits[v6] & (1LL << (i % 64))) == 0 )
break;
if ( v0 == i )
{
*(_QWORD *)addr_len = 110LL;
v5 = accept(i, &v14, addr_len);
if ( v5 < 0 )
{
perror("accept");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Connected.\n", 1uLL, 0xBuLL, stderr);
func2(v5);
v6 = v5 / 64;
v13[0].m128i_i64[v6] |= 1LL << (v5 % 64);
break;
}
if ( v2 != i )
break;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("not sock\n", 1uLL, 9uLL, stderr);
LODWORD(v6) = getchar();
if ( (_DWORD)v6 != -1 )
break;
LODWORD(v6) = close(v0);
if ( v8 > 1023 )
return v6;
v10 = 1;
LABEL_10:
++v8;
}
if ( v8 <= 1023 )
goto LABEL_10;
if ( v10 != 1 )
continue;
return v6;
}
}

original_code:
void
recv_send_2pbk_skt() {
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt"));
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 int len;
 size_t size;
 struct sockaddr_un local, pbkc;
 int sock;
 fd_set active_fd_set, read_fd_set, write_fd_set;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "creating the socket\n"));
 sock = mk_socket();
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 local.sun_family = 1;
 strcpy(local.sun_path, "/tmp/22294");
 unlink(local.sun_path);
 len = strlen(local.sun_path) + sizeof(local.sun_family);
 if (bind(sock, (struct sockaddr *)&local, len) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(sock, 5) == -1) {
  perror("listen");
  exit(1);
 }
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&active_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 int stdinfd = fileno(stdin);
 ((void) (((&active_fd_set)->__fds_bits)[((stdinfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((stdinfd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&active_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&write_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "send \"EOF\" with Ctrl-D to stop the daemon or\n"));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Waiting for a connection...\n"));
 int i;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "selecting the set\n"));
 int sig = START;
 while(sig != KILL) {
 read_fd_set = active_fd_set;
 if (select (1024, &read_fd_set, ((void *)0), ((void *)0), ((void *)0)) < 0) {
  perror ("select");
  exit (1);
 }
 for (i = 0; i < 1024; ++i) {
  if (((((&read_fd_set)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (i == sock) {
    int new;
    size = sizeof(pbkc);
    new = accept (sock,
      (struct sockaddr *) &pbkc,
      &size);
    if (new < 0) {
     perror ("accept");
     exit (1);
    }
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Connected.\n"));
    read_from_client (new);
    ((void) (((&active_fd_set)->__fds_bits)[((new) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new) % (8 * (int) sizeof (__fd_mask)))))));
   }
   else if (i == stdinfd) {
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "not sock\n"));
    int c;
    if((c=getchar()) == (-1)) {
     close(sock);
     sig = KILL;
    }
   }
  }
 }
 }
}

canonical_original_code:
void recv_send_2pbk_skt() {
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt"));
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 int len;
 unsigned long size;
 struct sockaddr_un local; struct sockaddr_un pbkc;
 int sock;
 struct fd_set active_fd_set; struct fd_set read_fd_set; struct fd_set write_fd_set;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "creating the socket\n"));
 sock = mk_socket();
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 local.sun_family = 1;
 strcpy(local.sun_path, "/tmp/22294");
 unlink(local.sun_path);
 len = strlen(local.sun_path) + sizeof(local.sun_family);
 if (bind(sock, (struct sockaddr *)&local, len) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(sock, 5) == -1) {
  perror("listen");
  exit(1);
 }
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&active_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 int stdinfd = fileno(stdin);
 ((void) (((&active_fd_set)->__fds_bits)[((stdinfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((stdinfd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&active_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&write_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "send \"EOF\" with Ctrl-D to stop the daemon or\n"));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Waiting for a connection...\n"));
 int i;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "selecting the set\n"));
 int sig = START;
 while(sig != KILL) {
 read_fd_set = active_fd_set;
 if (select (1024, &read_fd_set, ((void *)0), ((void *)0), ((void *)0)) < 0) {
  perror ("select");
  exit (1);
 }
 for (i = 0; i < 1024; ++i) {
  if (((((&read_fd_set)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (i == sock) {
    int new;
    size = sizeof(pbkc);
    new = accept (sock,
      (struct sockaddr *) &pbkc,
      &size);
    if (new < 0) {
     perror ("accept");
     exit (1);
    }
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Connected.\n"));
    read_from_client (new);
    ((void) (((&active_fd_set)->__fds_bits)[((new) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new) % (8 * (int) sizeof (__fd_mask)))))));
   }
   else if (i == stdinfd) {
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "not sock\n"));
    int c;
    if((c=getchar()) == (-1)) {
     close(sock);
     sig = KILL;
    }
   }
  }
 }
 }
}

variable_types: len int

variable_types:
size
unsigned long

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: sock int

variable_types: stdinfd int

variable_types: i int

variable_types: sig int

variable_types: new int

variable_types: c int


pbkd

decompiled_code:
size_t __fastcall pbkd(int a1)
{
size_t result; // rax

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "pbkd");
result = fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
if ( !a1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("started pbd in foreground mode\n", 1uLL, 0x1FuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("calling recv_send_2pbk_skt\n", 1uLL, 0x1BuLL, stderr);
result = recv_send_2pbk_skt();
}
return result;
}

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

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "pbkd");
result = fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
if ( !a1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("started pbd in foreground mode\n", 1uLL, 0x1FuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("calling recv_send_2pbk_skt\n", 1uLL, 0x1BuLL, stderr);
result = recv_send_2pbk_skt();
}
return result;
}

original_code:
void
pbkd(int mode) {
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "pbkd"));
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 switch (mode) {
  case START:
   (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "started pbd in foreground mode\n"));
   (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "calling recv_send_2pbk_skt\n"));
   recv_send_2pbk_skt();
   break;
  case KILL:
   break;
  default:
   break;
 }
}

variable_types: mode int


decompiled_code:
__int64 __fastcall pb_getline(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // eax

v2 = 0LL;
while ( 1 )
{
v3 = getchar();
if ( v3 == 10 || v3 == -1 )
break;
if ( a2 - 1 > (int)v2 )
*(_BYTE *)(a1 + v2++) = v3;
}
if ( (_DWORD)v2 || v3 != -1 )
{
*(_BYTE *)(a1 + (int)v2) = 0;
exit(1);
}
return 0xFFFFFFFFLL;
}

original_code:
int pb_getline(char line[], int max)
{
 int nch = 0;
 int c;
 max = max - 1;
  while((c = getchar()) != (-1)) {
   if(c == '\n')
    break;
   if(nch < max) {
    line[nch] = c;
    nch = nch + 1;
   }
  }
 if(c == (-1) && nch == 0)
  return (-1);
 line[nch] = '\0';
 exit(1);
}

variable_types:
line
char []

variable_types: max int

variable_types: nch int


xctod

decompiled_code:
__int64 __fastcall xctod(int a1)
{
unsigned __int16 v1; // ax
bool v2; // zf
__int64 result; // rax

v1 = (*_ctype_b_loc())[a1];
if ( (v1 & 0x800) != 0 )
return (unsigned int)(a1 - 48);
if ( (v1 & 0x100) != 0 )
return (unsigned int)(a1 - 55);
v2 = (v1 & 0x200) == 0;
result = 0LL;
if ( !v2 )
result = (unsigned int)(a1 - 87);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int16 v1; // ax
bool v2; // zf
__int64 result; // rax

v1 = (*_ctype_b_loc())[a1];
if ( (v1 & 0x800) != 0 )
return (unsigned int)(a1 - 48);
if ( (v1 & 0x100) != 0 )
return (unsigned int)(a1 - 55);
v2 = (v1 & 0x200) == 0;
result = 0LL;
if ( !v2 )
result = (unsigned int)(a1 - 87);
return result;
}

original_code:
static int xctod(int c)
{
 if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
  return c - '0';
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISupper))
  return c - 'A' + 10;
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISlower))
  return c - 'a' + 10;
 else
  return 0;
}

canonical_original_code:
static int xctod(int c)
{
 if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
  return c - '0';
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISupper))
  return c - 'A' + 10;
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISlower))
  return c - 'a' + 10;
 else
  return 0;
}


canonical_original_code:
void hexdump_addr(unsigned char *buf, int len, unsigned int addr_start)
{
  int i;
  unsigned char str[17];
  str[16] = 0;
  for(i = 0; i < len; i++) {
    if(!(i % 16)) printf("%08x  ", i + addr_start);
    str[i % 16] = ((buf[i] >= 32 && buf[i] <= 126) ? buf[i] : '.');
    printf("%02x ", buf[i]);
    if(!((i+1) % 8)) {
      if(!((i+1) % 16))
        printf(" %s\n", str);
      else
        printf(" ");
    }
  }
  i = 16 - (i % 16);
  str[16 - i] = 0;
  if(i > 0 && i < 16) {
    if(i > 8) printf(" ");
    while(i--)
      printf("   ");
    printf(" %s\n", str);
  }
}

variable_types:
buf
unsigned char *

variable_types:
str
unsigned char [17]


decompiled_code:
unsigned __int64 __fastcall read_data(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 i; // rbx
ssize_t v5; // rax

if ( !a3 )
return 0LL;
for ( i = 0LL; i < a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( !v5 )
break;
}
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 i; // rbx
ssize_t v5; // rax

if ( !a3 )
return 0LL;
for ( i = 0LL; i < a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( !v5 )
break;
}
return i;
}

original_code:
size_t read_data( int fd , void * buf , size_t size )
{
 size_t sr = 0;
 while( sr < size )
 {
  size_t ret = read( fd , ((char*)buf)+sr , size - sr );
  if( ret == 0 ) break;
  sr += ret;
 }
 return sr;
}

canonical_original_code:
unsigned long read_data(int fd, void *buf, unsigned long size)
{
 unsigned long sr = 0;
 while( sr < size )
 {
  unsigned long ret = read( fd , ((char*)buf)+sr , size - sr );
  if( ret == 0 ) break;
  sr += ret;
 }
 return sr;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
sr
unsigned long

variable_types:
ret
unsigned long


decompiled_code:
__int64 __fastcall read_termios(int fd, __int64 a2)
{
__int64 v2; // rbx

read_data(fd, a2, 0x20uLL);
v2 = a2 + 17;
do
read_data(fd, v2++, 1uLL);
while ( v2 != a2 + 36 );
return 51LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2)
{
__int64 v2; // rbx

func0(fd, a2, 0x20uLL);
v2 = a2 + 17;
do
func0(fd, v2++, 1uLL);
while ( v2 != a2 + 36 );
return 51LL;
}

original_code:
size_t read_termios( int fd , struct termios* buf )
{
 read_data( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  read_data( fd , buf->c_cc + i , sizeof(cc_t) );
 return 32 + 19;
}

canonical_original_code:
unsigned long read_termios(int fd, struct termios *buf)
{
 read_data( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  read_data( fd , buf->c_cc + i , sizeof(cc_t) );
 return 32 + 19;
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *


decompiled_code:
__int64 __fastcall write_termios(int fd, char *a2)
{
char *v2; // rbx

write(fd, a2, 0x20uLL);
v2 = a2 + 17;
do
write(fd, v2++, 1uLL);
while ( v2 != a2 + 36 );
return 51LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, char *a2)
{
char *v2; // rbx

write(fd, a2, 0x20uLL);
v2 = a2 + 17;
do
write(fd, v2++, 1uLL);
while ( v2 != a2 + 36 );
return 51LL;
}

original_code:
size_t write_termios( int fd , const struct termios *buf )
{
 write( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  write( fd , buf->c_cc + i , 1 );
 return 32 + 19;
}

canonical_original_code:
unsigned long write_termios(int fd, struct termios *buf)
{
 write( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  write( fd , buf->c_cc + i , 1 );
 return 32 + 19;
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
unsigned __int64 __fastcall read_vdata(int fd, _QWORD *a2)
{
unsigned __int64 v2; // r12
void *v3; // rax
size_t size[3]; // [rsp+Ch] [rbp-1Ch] BYREF

read_data(fd, (__int64)size, 4uLL);
v2 = LODWORD(size[0]);
v3 = malloc(LODWORD(size[0]));
*a2 = v3;
return read_data(fd, (__int64)v3, v2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(int fd, _QWORD *a2)
{
unsigned __int64 v2; // r12
void *v3; // rax
size_t size[3]; // [rsp+Ch] [rbp-1Ch] BYREF

func0(fd, (__int64)size, 4uLL);
v2 = LODWORD(size[0]);
v3 = malloc(LODWORD(size[0]));
*a2 = v3;
return func0(fd, (__int64)v3, v2);
}

original_code:
size_t read_vdata( int fd , char **buf)
{
 unsigned int sz;
 size_t ret = 0;
 read_data( fd , &sz , sizeof(sz) );
 *buf = (char*)malloc(sz);
 ret += read_data( fd , *buf , sz );
 return ret;
}

canonical_original_code:
unsigned long read_vdata(int fd, char **buf)
{
 unsigned int sz;
 unsigned long ret = 0;
 read_data( fd , &sz , sizeof(sz) );
 *buf = (char *)malloc(sz);
 ret += read_data( fd , *buf , sz );
 return ret;
}

variable_types:
buf
char **

variable_types:
sz
unsigned int


decompiled_code:
ssize_t __fastcall write_vdata(int fd, void *buf, unsigned int a3)
{
ssize_t v3; // rbp
unsigned int bufa[7]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
v3 = write(fd, bufa, 4uLL);
return v3 + write(fd, buf, bufa[0]);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, void *buf, unsigned int a3)
{
ssize_t v3; // rbp
unsigned int bufa[7]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
v3 = write(fd, bufa, 4uLL);
return v3 + write(fd, buf, bufa[0]);
}

original_code:
size_t write_vdata( int fd , char *buf , unsigned int size)
{
 size_t ret = write( fd , &size , sizeof(unsigned int) );
 ret += write( fd , buf , size );
 return ret;
}

canonical_original_code:
unsigned long write_vdata(int fd, char *buf, unsigned int size)
{
 unsigned long ret = write( fd , &size , sizeof(unsigned int) );
 ret += write( fd , buf , size );
 return ret;
}

variable_types:
buf
char *

variable_types:
size
unsigned int


decompiled_code:
unsigned __int64 __fastcall read_concmd(int a1, __int64 a2)
{
return read_data(a1, a2, 0x1CuLL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(int a1, __int64 a2)
{
return func0(a1, a2, 0x1CuLL);
}

original_code:
size_t read_concmd( int fd , struct concmd *buf )
{
 size_t ret = 0;
 ret += read_data( fd , buf , sizeof(struct concmd) );
 return ret;
}

canonical_original_code:
unsigned long read_concmd(int fd, struct concmd *buf)
{
 unsigned long ret = 0;
 ret += read_data( fd , buf , sizeof(struct concmd) );
 return ret;
}

variable_types: struct concmd { int cc_flag; int cc_cdword; char cc_signature[20]; } *