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

result = *a1;
if ( *(_QWORD *)(*a1 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x89u, "mlist_reserve2");
if ( *(_QWORD *)(result - 8) <= a2 && *(_QWORD *)(result - 16) <= a2 )
result = mlist_grow(a1, a2);
return result;
}

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

result = *a1;
if ( *(_QWORD *)(*a1 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x89u, "mlist_reserve2");
if ( *(_QWORD *)(result - 8) <= a2 && *(_QWORD *)(result - 16) <= a2 )
result = func0(a1, a2);
return result;
}

original_code:
void mlist_reserve2 (void** list, size_t len, size_t elsize)
{
 struct mlist_header_t* mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 137, __extension__ __PRETTY_FUNCTION__); }));
 if (mlist->capacity > len || len < mlist->len)
 {
  return;
 }
 mlist_grow (list, len);
}

canonical_original_code:
void mlist_reserve2(void **list, unsigned long len, unsigned long elsize)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 137, __extension__ __PRETTY_FUNCTION__); }));
 if (mlist->capacity > len || len < mlist->len)
 {
  return;
 }
 mlist_grow (list, len);
}

variable_types:
len
unsigned long


repo: nichtverstehen/cync

decompiled_code:
__int64 __fastcall arl_close(void *a1)
{
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1)
{
free(a1);
return 0LL;
}

original_code:
int arl_close (AMY* my)
{
 free (my);
 return 0;
}

canonical_original_code:
int arl_close(struct AMY *my)
{
 free (my);
 return 0;
}

variable_types: struct AMY { int fd; char buf[1024]; unsigned long start; } *

return_type: int


decompiled_code:
_QWORD *hstack_new()
{
return hstack_new2(0x400uLL);
}

canonical_decompiled_code:
_QWORD *func0()
{
return hstack_new2(0x400uLL);
}

original_code:
hstack_t hstack_new ()
{
 return hstack_new2 (1024);
}

canonical_original_code:
struct hstack_header_t *hstack_new()
{
 return hstack_new2 (1024);
}

return_type: struct hstack_header_t { unsigned long capacity; unsigned long head; } *


decompiled_code:
// attributes: thunk
void hstack_delete(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
void hstack_delete(hstack_t hstack)
{
 free (hstack);
}

canonical_original_code:
void hstack_delete(struct hstack_header_t *hstack)
{
 free (hstack);
}

variable_types: struct hstack_header_t { unsigned long capacity; unsigned long head; } *

return_type: void


decompiled_code:
unsigned __int64 *__fastcall hstack_push2(unsigned __int64 **a1, const void *a2, size_t a3)
{
unsigned __int64 *v4; // r8
unsigned __int64 v5; // rdx
unsigned __int64 v6; // rax
unsigned __int64 v7; // r13
unsigned __int64 v9; // r14
unsigned __int64 v10; // rax
unsigned __int64 *v12; // rdi
unsigned __int64 *v13; // rax

v4 = *a1;
v5 = (*a1)[1];
v6 = **a1;
v7 = v5 + a3 + 16;
if ( v6 < v7 )
{
v9 = v5 + 2 * a3 + 24;
v10 = 2 * v6;
v12 = *a1;
if ( v9 < v10 )
v9 = v10;
v13 = (unsigned __int64 *)realloc(v12, v9 + 16);
v4 = v13;
if ( !v13 )
return v4;
*v13 = v9;
*a1 = v13;
if ( v7 > v9 )
_assert_fail("need_capacity <= hstack->capacity", "hstack.c", 0x52u, "hstack_push2");
v5 = v13[1];
}
*(unsigned __int64 *)((char *)v4 + v5 + a3 + 24) = a3 + 8;
v4[1] = v5 + a3 + 8;
if ( a2 )
return (unsigned __int64 *)memcpy((char *)v4 + v5 + 24, a2, a3);
return (unsigned __int64 *)memset((char *)v4 + v5 + 24, 0, a3);
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func2(unsigned __int64 **a1, const void *a2, size_t a3)
{
unsigned __int64 *v4; // r8
unsigned __int64 v5; // rdx
unsigned __int64 v6; // rax
unsigned __int64 v7; // r13
unsigned __int64 v9; // r14
unsigned __int64 v10; // rax
unsigned __int64 *v12; // rdi
unsigned __int64 *v13; // rax

v4 = *a1;
v5 = (*a1)[1];
v6 = **a1;
v7 = v5 + a3 + 16;
if ( v6 < v7 )
{
v9 = v5 + 2 * a3 + 24;
v10 = 2 * v6;
v12 = *a1;
if ( v9 < v10 )
v9 = v10;
v13 = (unsigned __int64 *)realloc(v12, v9 + 16);
v4 = v13;
if ( !v13 )
return v4;
*v13 = v9;
*a1 = v13;
if ( v7 > v9 )
_assert_fail("need_capacity <= hstack->capacity", "hstack.c", 0x52u, "hstack_push2");
v5 = v13[1];
}
*(unsigned __int64 *)((char *)v4 + v5 + a3 + 24) = a3 + 8;
v4[1] = v5 + a3 + 8;
if ( a2 )
return (unsigned __int64 *)memcpy((char *)v4 + v5 + 24, a2, a3);
return (unsigned __int64 *)memset((char *)v4 + v5 + 24, 0, a3);
}

original_code:
void* hstack_push2 (hstack_t* phstack, void* elem, size_t elsize)
{
 struct hstack_header_t* hstack = *phstack;
 const size_t need_capacity = hstack->head + 2 * sizeof (struct hstack_frame_t) + elsize;
 if (need_capacity > hstack->capacity)
 {
  const size_t new_capacity = ((hstack->capacity * 2) > (hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize) ? hstack->capacity * 2 : hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize);
  hstack = realloc (hstack, sizeof (struct hstack_header_t) + new_capacity);
  if (!hstack)
  {
   return ((void *)0);
  }
  hstack->capacity = new_capacity;
  *phstack = hstack;
 }
 ((void) sizeof ((need_capacity <= hstack->capacity) ? 1 : 0), __extension__ ({ if (need_capacity <= hstack->capacity) ; else __assert_fail ("need_capacity <= hstack->capacity", "hstack.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 struct hstack_frame_t* topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 size_t framesize = sizeof (struct hstack_frame_t) + elsize;
 struct hstack_frame_t* dummyframe = (struct hstack_frame_t*) ((char*) topframe + framesize);
 dummyframe->prev_offset = framesize;
 hstack->head += framesize;
 if (elem)
 {
  memcpy ((&(topframe)->data[0]), elem, elsize);
 }
 else
 {
  memset ((&(topframe)->data[0]), 0, elsize);
 }
 return (&(topframe)->data[0]);
}

canonical_original_code:
void *hstack_push2(struct hstack_header_t **phstack, void *elem, unsigned long elsize)
{
 struct hstack_header_t *hstack = *phstack;
 unsigned long need_capacity = hstack->head + 2 * sizeof (struct hstack_frame_t) + elsize;
 if (need_capacity > hstack->capacity)
 {
  unsigned long new_capacity = ((hstack->capacity * 2) > (hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize) ? hstack->capacity * 2 : hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize);
  hstack = realloc (hstack, sizeof (struct hstack_header_t) + new_capacity);
  if (!hstack)
  {
   return ((void *)0);
  }
  hstack->capacity = new_capacity;
  *phstack = hstack;
 }
 ((void) sizeof ((need_capacity <= hstack->capacity) ? 1 : 0), __extension__ ({ if (need_capacity <= hstack->capacity) ; else __assert_fail ("need_capacity <= hstack->capacity", "hstack.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 struct hstack_frame_t *topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 unsigned long framesize = sizeof (struct hstack_frame_t) + elsize;
 struct hstack_frame_t *dummyframe = (struct hstack_frame_t*) ((char*) topframe + framesize);
 dummyframe->prev_offset = framesize;
 hstack->head += framesize;
 if (elem)
 {
  memcpy ((&(topframe)->data[0]), elem, elsize);
 }
 else
 {
  memset ((&(topframe)->data[0]), 0, elsize);
 }
 return (&(topframe)->data[0]);
}

variable_types: struct hstack_header_t { unsigned long capacity; unsigned long head; } **

variable_types:
elem
void *

variable_types:
elsize
unsigned long

variable_types: struct hstack_frame_t { unsigned long prev_offset; char data[]; } *

variable_types:
framesize
unsigned long

return_type: void *


decompiled_code:
__int64 __fastcall hstack_pop2(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rcx

v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v2 = *(_QWORD *)(*(_QWORD *)a1 + v1 + 16);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( v1 < v2 )
_assert_fail("hstack->head >= topframe->prev_offset", "hstack.c", 0x70u, "hstack_pop2");
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = v1 - v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rcx

v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v2 = *(_QWORD *)(*(_QWORD *)a1 + v1 + 16);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( v1 < v2 )
_assert_fail("hstack->head >= topframe->prev_offset", "hstack.c", 0x70u, "hstack_pop2");
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = v1 - v2;
return 0LL;
}

original_code:
int hstack_pop2 (hstack_t* phstack)
{
 struct hstack_header_t* hstack = *phstack;
 struct hstack_frame_t* topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 if (topframe->prev_offset == 0)
 {
  return -1;
 }
 ((void) sizeof ((hstack->head >= topframe->prev_offset) ? 1 : 0), __extension__ ({ if (hstack->head >= topframe->prev_offset) ; else __assert_fail ("hstack->head >= topframe->prev_offset", "hstack.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 hstack->head = hstack->head - topframe->prev_offset;
 return 0;
}

canonical_original_code:
int hstack_pop2(struct hstack_header_t **phstack)
{
 struct hstack_header_t *hstack = *phstack;
 struct hstack_frame_t *topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 if (topframe->prev_offset == 0)
 {
  return -1;
 }
 ((void) sizeof ((hstack->head >= topframe->prev_offset) ? 1 : 0), __extension__ ({ if (hstack->head >= topframe->prev_offset) ; else __assert_fail ("hstack->head >= topframe->prev_offset", "hstack.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 hstack->head = hstack->head - topframe->prev_offset;
 return 0;
}

user_defined_types: struct hstack_header_t { unsigned long capacity; unsigned long head; }

user_defined_types: struct hstack_frame_t { unsigned long prev_offset; char data[]; }


repo: nickappleton/digest

variable_types:
state
unsigned long *

variable_types:
words
unsigned char *

variable_types:
work
unsigned long [80]

variable_types:
h
unsigned long [8]

variable_types:
i
unsigned int

variable_types:
ch
unsigned long

variable_types:
maj
unsigned long


decompiled_code:
__int64 __fastcall sha2_query_digest_size(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)a1 + 136LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)a1 + 136LL);
}

original_code:
static
unsigned
sha2_query_digest_size(const struct hash_s *hash)
{
 return hash->state->digest_bits;
}

canonical_original_code:
static unsigned int sha2_query_digest_size(struct hash_s *hash)
{
 return hash->state->digest_bits;
}

variable_types: struct hash_s { struct hash_pvt_s { unsigned int buffer_length; unsigned int buffer_index; unsigned char buffer_data[128]; unsigned int digest_bits; unsigned long length; union { unsigned long *h512; unsigned int *h256; } initial; union { unsigned long h512[8]; unsigned int h256[8]; } hash; unsigned long ivt[8]; } *state; void (*begin)(struct hash_s *hash); void (*process)(struct hash_s *hash, unsigned char *data, unsigned long size); void (*end)(struct hash_s *hash, unsigned char *result); void (*destroy)(struct hash_s *hash); unsigned int (*query_digest_size)(struct hash_s *hash); } *

return_type: unsigned int

user_defined_types: struct hash_s { struct hash_pvt_s *state; void (*begin)(struct hash_s *hash); void (*process)(struct hash_s *hash, unsigned char *data, unsigned long size); void (*end)(struct hash_s *hash, unsigned char *result); void (*destroy)(struct hash_s *hash); unsigned int (*query_digest_size)(struct hash_s *hash); }


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

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

original_code:
static
void
sha2_destroy(struct hash_s *hash)
{
 free(hash->state);
}

user_defined_types: struct hash_pvt_s { unsigned int buffer_length; unsigned int buffer_index; unsigned char buffer_data[128]; unsigned int digest_bits; unsigned long length; union { unsigned long *h512; unsigned int *h256; } initial; union { unsigned long h512[8]; unsigned int h256[8]; } hash; unsigned long ivt[8]; }


original_code:
static
void
sha2_process(struct hash_s *hash, const unsigned char *data, size_t size)
{
 struct hash_pvt_s *context = hash->state;
 const UINT64 incr = ((((UINT64)((0) & 0xFFFFFFFFu)) << 32u) | (UINT64)((8 * context->buffer_length) & 0xFFFFFFFFu));
 if (size && context->buffer_index) {
  size_t cpy = context->buffer_length - context->buffer_index;
  if (cpy > size)
   cpy = size;
  memcpy
   (context->buffer_data + context->buffer_index
   ,data
   ,cpy
   );
  size -= cpy;
  data += cpy;
  context->buffer_index += cpy;
  if (context->buffer_index == context->buffer_length) {
   if (context->buffer_length == 128)
    sha2_512_process_block(context->hash.h512, context->buffer_data);
   else
    sha2_256_process_block(context->hash.h256, context->buffer_data);
   context->length = (((UINT64)(context->length)) + (incr));
   ((void) (0));
   context->buffer_index = 0;
  }
 }
 while (size >= context->buffer_length) {
  if (context->buffer_length == 128)
   sha2_512_process_block(context->hash.h512, data);
  else
   sha2_256_process_block(context->hash.h256, data);
  context->length = (((UINT64)(context->length)) + (incr));
  ((void) (0));
  data += context->buffer_length;
  size -= context->buffer_length;
 }
 if (size) {
  memcpy
   (context->buffer_data
   ,data
   ,size
   );
  context->buffer_index = size;
 }
}

canonical_original_code:
static void sha2_process(struct hash_s *hash, unsigned char *data, unsigned long size)
{
 struct hash_pvt_s *context = hash->state;
 unsigned long incr = ((((UINT64)((0) & 0xFFFFFFFFu)) << 32u) | (UINT64)((8 * context->buffer_length) & 0xFFFFFFFFu));
 if (size && context->buffer_index) {
  unsigned long cpy = context->buffer_length - context->buffer_index;
  if (cpy > size)
   cpy = size;
  memcpy
   (context->buffer_data + context->buffer_index
   ,data
   ,cpy
   );
  size -= cpy;
  data += cpy;
  context->buffer_index += cpy;
  if (context->buffer_index == context->buffer_length) {
   if (context->buffer_length == 128)
    sha2_512_process_block(context->hash.h512, context->buffer_data);
   else
    sha2_256_process_block(context->hash.h256, context->buffer_data);
   context->length = (((UINT64)(context->length)) + (incr));
   ((void) (0));
   context->buffer_index = 0;
  }
 }
 while (size >= context->buffer_length) {
  if (context->buffer_length == 128)
   sha2_512_process_block(context->hash.h512, data);
  else
   sha2_256_process_block(context->hash.h256, data);
  context->length = (((UINT64)(context->length)) + (incr));
  ((void) (0));
  data += context->buffer_length;
  size -= context->buffer_length;
 }
 if (size) {
  memcpy
   (context->buffer_data
   ,data
   ,size
   );
  context->buffer_index = size;
 }
}

variable_types:
data
unsigned char *

variable_types:
size
unsigned long

variable_types: struct hash_pvt_s { unsigned int buffer_length; unsigned int buffer_index; unsigned char buffer_data[128]; unsigned int digest_bits; unsigned long length; union { unsigned long *h512; unsigned int *h256; } initial; union { unsigned long h512[8]; unsigned int h256[8]; } hash; unsigned long ivt[8]; } *

variable_types:
incr
unsigned long

variable_types:
cpy
unsigned long


original_code:
static
void
sha2_end(struct hash_s *hash, unsigned char *result)
{
 unsigned i;
 struct hash_pvt_s *context = hash->state;
 const UINT64 incr = ((((UINT64)((0) & 0xFFFFFFFFu)) << 32u) | (UINT64)((8*context->buffer_index) & 0xFFFFFFFFu));
 context->length = (((UINT64)(context->length)) + (incr));
 ((void) (0));
 context->buffer_data[context->buffer_index++] = 0x80;
 if (context->buffer_index > context->buffer_length - 16) {
  while (context->buffer_index < context->buffer_length)
   context->buffer_data[context->buffer_index++] = 0;
  if (context->buffer_length == 128)
   sha2_512_process_block(context->hash.h512, context->buffer_data);
  else
   sha2_256_process_block(context->hash.h256, context->buffer_data);
  context->buffer_index = 0;
 }
 while (context->buffer_index < context->buffer_length - 16)
  context->buffer_data[context->buffer_index++] = 0;
 context->buffer_index = context->buffer_length - 1;
 while (context->buffer_index >= context->buffer_length - 16) {
  context->buffer_data[context->buffer_index--] = (unsigned char)(((mccl_uif32)(((UINT64)(context->length)) & 0xFFFFFFFFu)) & 0xFFu);
  context->length = (((UINT64)(context->length)) >> (8));
 }
 if (context->buffer_length == 128) {
  sha2_512_process_block(context->hash.h512, context->buffer_data);
  for (i = 0; i < context->digest_bits / 8; i++)
   result[i] = (unsigned char)(((mccl_uif32)(((UINT64)((((UINT64)(context->hash.h512[i/8])) >> (8u * (7u - (i & 0x07u)))))) & 0xFFFFFFFFu)) & 0xFFu);
 } else {
  sha2_256_process_block(context->hash.h256, context->buffer_data);
  for (i = 0; i < context->digest_bits / 8; i++)
   result[i] = (unsigned char)((context->hash.h256[i/4] >> 8u * (3u - (i & 0x03u))) & 0xFFu);
 }
}

canonical_original_code:
static void sha2_end(struct hash_s *hash, unsigned char *result)
{
 unsigned int i;
 struct hash_pvt_s *context = hash->state;
 unsigned long incr = ((((UINT64)((0) & 0xFFFFFFFFu)) << 32u) | (UINT64)((8*context->buffer_index) & 0xFFFFFFFFu));
 context->length = (((UINT64)(context->length)) + (incr));
 ((void) (0));
 context->buffer_data[context->buffer_index++] = 0x80;
 if (context->buffer_index > context->buffer_length - 16) {
  while (context->buffer_index < context->buffer_length)
   context->buffer_data[context->buffer_index++] = 0;
  if (context->buffer_length == 128)
   sha2_512_process_block(context->hash.h512, context->buffer_data);
  else
   sha2_256_process_block(context->hash.h256, context->buffer_data);
  context->buffer_index = 0;
 }
 while (context->buffer_index < context->buffer_length - 16)
  context->buffer_data[context->buffer_index++] = 0;
 context->buffer_index = context->buffer_length - 1;
 while (context->buffer_index >= context->buffer_length - 16) {
  context->buffer_data[context->buffer_index--] = (unsigned char)(((mccl_uif32)(((UINT64)(context->length)) & 0xFFFFFFFFu)) & 0xFFu);
  context->length = (((UINT64)(context->length)) >> (8));
 }
 if (context->buffer_length == 128) {
  sha2_512_process_block(context->hash.h512, context->buffer_data);
  for (i = 0; i < context->digest_bits / 8; i++)
   result[i] = (unsigned char)(((mccl_uif32)(((UINT64)((((UINT64)(context->hash.h512[i/8])) >> (8u * (7u - (i & 0x07u)))))) & 0xFFFFFFFFu)) & 0xFFu);
 } else {
  sha2_256_process_block(context->hash.h256, context->buffer_data);
  for (i = 0; i < context->digest_bits / 8; i++)
   result[i] = (unsigned char)((context->hash.h256[i/4] >> 8u * (3u - (i & 0x03u))) & 0xFFu);
 }
}

variable_types:
result
unsigned char *


original_code:
int sha2_create(struct hash_s *hash, unsigned digest_bits, int force_512)
{
 struct hash_pvt_s *ctx = malloc(sizeof(struct hash_pvt_s));
 if (ctx == ((void *)0))
  return -1;
 if ((digest_bits < 1) || (digest_bits > 512))
  return -2;
 hash->state = ctx;
 hash->destroy = sha2_destroy;
 hash->query_digest_size = sha2_query_digest_size;
 hash->begin = sha2_begin;
 hash->process = sha2_process;
 hash->end = sha2_end;
 ctx->digest_bits = digest_bits;
 ctx->buffer_length = 64;
 if ((digest_bits == 256) && (!force_512))
  ctx->initial.h256 = sha256_256_initial;
 else if ((digest_bits == 224) && (!force_512))
  ctx->initial.h256 = sha256_224_initial;
 else {
  ctx->buffer_length = 128;
  switch (digest_bits) {
  case 512:
   ctx->initial.h512 = sha512_512_initial;
   break;
  case 384:
   ctx->initial.h512 = sha512_384_initial;
   break;
  case 256:
   ctx->initial.h512 = sha512_256_initial;
   break;
  case 224:
   ctx->initial.h512 = sha512_224_initial;
   break;
  default:
   {
    static const UINT64 z = ((((UINT64)((0xA5A5A5A5u) & 0xFFFFFFFFu)) << 32u) | (UINT64)((0xA5A5A5A5u) & 0xFFFFFFFFu));
    unsigned i;
    unsigned char buf[64];
    create_gen_string(buf, digest_bits);
    for (i = 0; i < 8; i++)
     hash->state->hash.h512[i] = (((UINT64)(sha512_512_initial[i])) ^ (z));
    ctx->digest_bits = 512;
    ctx->buffer_index = 0;
    ctx->length = ((((UINT64)((0) & 0xFFFFFFFFu)) << 32u) | (UINT64)((0) & 0xFFFFFFFFu));
    sha2_process(hash, buf, strlen((const char *)buf));
    sha2_end(hash, buf);
    memcpy(ctx->ivt, ctx->hash.h512, sizeof(ctx->ivt));
    ctx->digest_bits = digest_bits;
    ctx->initial.h512 = ctx->ivt;
   }
   break;
  }
 }
 return 0;
}

canonical_original_code:
int sha2_create(struct hash_s *hash, unsigned int digest_bits, int force_512)
{
 struct hash_pvt_s *ctx = malloc(sizeof(struct hash_pvt_s));
 if (ctx == ((void *)0))
  return -1;
 if ((digest_bits < 1) || (digest_bits > 512))
  return -2;
 hash->state = ctx;
 hash->destroy = sha2_destroy;
 hash->query_digest_size = sha2_query_digest_size;
 hash->begin = sha2_begin;
 hash->process = sha2_process;
 hash->end = sha2_end;
 ctx->digest_bits = digest_bits;
 ctx->buffer_length = 64;
 if ((digest_bits == 256) && (!force_512))
  ctx->initial.h256 = sha256_256_initial;
 else if ((digest_bits == 224) && (!force_512))
  ctx->initial.h256 = sha256_224_initial;
 else {
  ctx->buffer_length = 128;
  switch (digest_bits) {
  case 512:
   ctx->initial.h512 = sha512_512_initial;
   break;
  case 384:
   ctx->initial.h512 = sha512_384_initial;
   break;
  case 256:
   ctx->initial.h512 = sha512_256_initial;
   break;
  case 224:
   ctx->initial.h512 = sha512_224_initial;
   break;
  default:
   {
    static unsigned long z = ((((UINT64)((0xA5A5A5A5u) & 0xFFFFFFFFu)) << 32u) | (UINT64)((0xA5A5A5A5u) & 0xFFFFFFFFu));
    unsigned int i;
    unsigned char buf[64];
    create_gen_string(buf, digest_bits);
    for (i = 0; i < 8; i++)
     hash->state->hash.h512[i] = (((UINT64)(sha512_512_initial[i])) ^ (z));
    ctx->digest_bits = 512;
    ctx->buffer_index = 0;
    ctx->length = ((((UINT64)((0) & 0xFFFFFFFFu)) << 32u) | (UINT64)((0) & 0xFFFFFFFFu));
    sha2_process(hash, buf, strlen((char *)buf));
    sha2_end(hash, buf);
    memcpy(ctx->ivt, ctx->hash.h512, sizeof(ctx->ivt));
    ctx->digest_bits = digest_bits;
    ctx->initial.h512 = ctx->ivt;
   }
   break;
  }
 }
 return 0;
}

variable_types:
z
unsigned long

variable_types:
buf
unsigned char [64]


repo: nickflink/tesr

decompiled_code:
void *create_queue()
{
return malloc(0x38uLL);
}

canonical_decompiled_code:
void *func2()
{
return malloc(0x38uLL);
}

original_code:
tesr_queue_t *create_queue() {
    tesr_queue_t *thiz = ((void *)0);
    thiz = (tesr_queue_t*)malloc(sizeof(tesr_queue_t));
    do{}while(0);
    return thiz;
}

canonical_original_code:
struct tesr_queue_t *create_queue() {
    struct tesr_queue_t *thiz = ((void *)0);
    thiz = (struct tesr_queue_t *)malloc(sizeof(tesr_queue_t));
    do{}while(0);
    return thiz;
}

variable_types: struct tesr_queue_t { struct queue_data_t { char buffer[1024]; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int bytes; int addr_len; int worker_idx; struct queue_data_t *next; } *queue; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct queue_data_t *next; } *

user_defined_types: struct tesr_queue_t { struct queue_data_t *queue; union pthread_mutex_t mutex; struct queue_data_t *next; }

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

user_defined_types: struct queue_data_t { char buffer[1024]; struct sockaddr_in addr; unsigned int bytes; int addr_len; int worker_idx; struct queue_data_t *next; }

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

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


decompiled_code:
__int64 __fastcall init_queue(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL);
return 1LL;
}

original_code:
int init_queue(tesr_queue_t *thiz) {
    thiz->queue = ((void *)0);
    pthread_mutex_init(&thiz->mutex, ((void *)0));
    return 1;
}

canonical_original_code:
int init_queue(struct tesr_queue_t *thiz) {
    thiz->queue = ((void *)0);
    pthread_mutex_init(&thiz->mutex, ((void *)0));
    return 1;
}

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


decompiled_code:
void __fastcall destroy_queue(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free tesr_queue_t * as it is NULL", 1uLL, 0x29uLL, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free tesr_queue_t * as it is NULL", 1uLL, 0x29uLL, stderr);
fflush(stderr);
}
}

original_code:
void destroy_queue(tesr_queue_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free tesr_queue_t * as it is NULL");fflush(stderr);}while(0);
    }
}

canonical_original_code:
void destroy_queue(struct tesr_queue_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free tesr_queue_t * as it is NULL");fflush(stderr);}while(0);
    }
}


decompiled_code:
int __fastcall log_queue(__int64 *a1)
{
__int64 v1; // rbx

fwrite("filters=[", 1uLL, 9uLL, stdout);
fflush(stdout);
v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
fputs((const char *)v1, stdout);
fflush(stdout);
v1 = *(_QWORD *)(v1 + 1056);
if ( !v1 )
break;
fputc(44, stdout);
fflush(stdout);
}
}
fwrite("]\n", 1uLL, 2uLL, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func5(__int64 *a1)
{
__int64 v1; // rbx

fwrite("filters=[", 1uLL, 9uLL, stdout);
fflush(stdout);
v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
fputs((const char *)v1, stdout);
fflush(stdout);
v1 = *(_QWORD *)(v1 + 1056);
if ( !v1 )
break;
fputc(44, stdout);
fflush(stdout);
}
}
fwrite("]\n", 1uLL, 2uLL, stdout);
return fflush(stdout);
}

original_code:
void log_queue(tesr_queue_t *thiz) {
    int print_comma = 0;
    do{;fprintf(stdout,"filters=[");fflush(stdout);}while(0);
    queue_data_t *data = ((void *)0);
    for(data=thiz->queue;data;data=(data)->next) {
        if(print_comma) {
            do{;fprintf(stdout,",");fflush(stdout);}while(0);
        } else {
            print_comma = 1;
        }
        do{;fprintf(stdout,"%s", data->buffer);fflush(stdout);}while(0);
    }
    do{;fprintf(stdout,"]\n");fflush(stdout);}while(0);
}

canonical_original_code:
void log_queue(struct tesr_queue_t *thiz) {
    int print_comma = 0;
    do{;fprintf(stdout,"filters=[");fflush(stdout);}while(0);
    struct queue_data_t *data = ((void *)0);
    for(data=thiz->queue;data;data=(data)->next) {
        if(print_comma) {
            do{;fprintf(stdout,",");fflush(stdout);}while(0);
        } else {
            print_comma = 1;
        }
        do{;fprintf(stdout,"%s", data->buffer);fflush(stdout);}while(0);
    }
    do{;fprintf(stdout,"]\n");fflush(stdout);}while(0);
}

variable_types: struct queue_data_t { char buffer[1024]; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int bytes; int addr_len; int worker_idx; struct queue_data_t *next; } *


decompiled_code:
__int64 __fastcall init_config_from_defaults(_QWORD *a1)
{
__int64 result; // rax

result = 0x700000000LL;
a1[1] = 0LL;
*a1 = 0x700000000LL;
a1[2] = 0LL;
a1[3] = 0LL;
return result;
}

original_code:
static void init_config_from_defaults(tesr_config_t *thiz) {
    thiz->daemonize = 0;
    thiz->recv_port = 7;
    thiz->irl_max = 0;
    thiz->irl_inactivity_timeout = 0;
    thiz->irl_garbage_collect_count = 0;
    thiz->num_workers = 0;
    thiz->filters = ((void *)0);
}

canonical_original_code:
static void init_config_from_defaults(struct tesr_config_t *thiz) {
    thiz->daemonize = 0;
    thiz->recv_port = 7;
    thiz->irl_max = 0;
    thiz->irl_inactivity_timeout = 0;
    thiz->irl_garbage_collect_count = 0;
    thiz->num_workers = 0;
    thiz->filters = ((void *)0);
}

variable_types: struct tesr_config_t { int daemonize; int recv_port; int irl_max; int irl_inactivity_timeout; int irl_garbage_collect_count; int num_workers; struct tesr_filter_t { char filter[16]; struct tesr_filter_t *next; } *filters; } *

user_defined_types: struct tesr_config_t { int daemonize; int recv_port; int irl_max; int irl_inactivity_timeout; int irl_garbage_collect_count; int num_workers; struct tesr_filter_t *filters; }


decompiled_code:
__int64 __fastcall load_config_file(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
const char *v4; // rsi
unsigned int v5; // er12

v2 = config_read_file();
v4 = "using config %s\n";
v5 = v2;
if ( !v2 )
v4 = "no config found at %s\n";
fprintf(stdout, v4, a2);
fflush(stdout);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
const char *v4; // rsi
unsigned int v5; // er12

v2 = config_read_file();
v4 = "using config %s\n";
v5 = v2;
if ( !v2 )
v4 = "no config found at %s\n";
fprintf(stdout, v4, a2);
fflush(stdout);
return v5;
}

original_code:
static int load_config_file(config_t* cfg, const char *file_name) {
    int config_loaded = config_read_file(cfg, file_name);
    if(config_loaded) {
        do{;fprintf(stdout,"using config %s\n", file_name);fflush(stdout);}while(0);
    } else {
        do{;fprintf(stdout,"no config found at %s\n", file_name);fflush(stdout);}while(0);
    }
    return config_loaded;
}

canonical_original_code:
static int load_config_file(struct config_t *cfg, char *file_name) {
    int config_loaded = config_read_file(cfg, file_name);
    if(config_loaded) {
        do{;fprintf(stdout,"using config %s\n", file_name);fflush(stdout);}while(0);
    } else {
        do{;fprintf(stdout,"no config found at %s\n", file_name);fflush(stdout);}while(0);
    }
    return config_loaded;
}

variable_types: struct config_t { struct config_setting_t { char *name; short type; short format; union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t { unsigned int length; struct config_setting_t **elements; } *list; } value; struct config_setting_t *parent; struct config_t *config; void *hook; unsigned int line; char *file; } *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t { CONFIG_ERR_NONE=0, CONFIG_ERR_FILE_IO=1, CONFIG_ERR_PARSE=2 } error_type; char **filenames; unsigned int num_filenames; } *

user_defined_types: struct config_t { struct config_setting_t *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t error_type; char **filenames; unsigned int num_filenames; }

user_defined_types: struct config_setting_t { char *name; short type; short format; union config_value_t value; struct config_setting_t *parent; struct config_t *config; void *hook; unsigned int line; char *file; }

user_defined_types: union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t *list; }


decompiled_code:
__int64 __fastcall override_config_from_args(_DWORD *a1, int a2, char *const *a3)
{
unsigned int v3; // er13
int v5; // eax
char *v6; // r14
int v7; // eax
__int64 i; // rax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = 0;
while ( 1 )
{
longind[0] = 0;
v5 = getopt_long(a2, a3, "p:w:dh", &long_options_0, longind);
if ( v5 == -1 )
break;
if ( v5 == 104 )
{
v3 = 5;
}
else if ( v5 > 104 )
{
if ( v5 == 112 )
{
v6 = optarg;
v7 = atoi(optarg);
a1[1] = v7;
if ( !v7 )
{
v3 = 1;
fprintf(stderr, "[KO] non-numeric port '%s'", v6);
fflush(stderr);
}
}
else if ( v5 == 119 )
{
a1[5] = atoi(optarg);
}
else
{
LABEL_12:
v3 = 3;
fprintf(stderr, "?? getopt returned character code 0%o ??\n", (unsigned int)v5);
fflush(stderr);
}
}
else if ( v5 == 63 )
{
v3 = 2;
fprintf(stderr, "?? invalid option 0%o ??\n", 63LL);
fflush(stderr);
}
else
{
if ( v5 != 100 )
goto LABEL_12;
*a1 = 1;
}
}
if ( optind >= a2 )
return v3;
fwrite("non-option ARGV-elements: ", 1uLL, 0x1AuLL, stderr);
fflush(stderr);
for ( i = optind; optind < a2; i = optind )
{
optind = i + 1;
fprintf(stderr, "%s ", a3[i]);
fflush(stderr);
}
fputc(10, stderr);
fflush(stderr);
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, int a2, char *const *a3)
{
unsigned int v3; // er13
int v5; // eax
char *v6; // r14
int v7; // eax
__int64 i; // rax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = 0;
while ( 1 )
{
longind[0] = 0;
v5 = getopt_long(a2, a3, "p:w:dh", &long_options_0, longind);
if ( v5 == -1 )
break;
if ( v5 == 104 )
{
v3 = 5;
}
else if ( v5 > 104 )
{
if ( v5 == 112 )
{
v6 = optarg;
v7 = atoi(optarg);
a1[1] = v7;
if ( !v7 )
{
v3 = 1;
fprintf(stderr, "[KO] non-numeric port '%s'", v6);
fflush(stderr);
}
}
else if ( v5 == 119 )
{
a1[5] = atoi(optarg);
}
else
{
LABEL_12:
v3 = 3;
fprintf(stderr, "?? getopt returned character code 0%o ??\n", (unsigned int)v5);
fflush(stderr);
}
}
else if ( v5 == 63 )
{
v3 = 2;
fprintf(stderr, "?? invalid option 0%o ??\n", 63LL);
fflush(stderr);
}
else
{
if ( v5 != 100 )
goto LABEL_12;
*a1 = 1;
}
}
if ( optind >= a2 )
return v3;
fwrite("non-option ARGV-elements: ", 1uLL, 0x1AuLL, stderr);
fflush(stderr);
for ( i = optind; optind < a2; i = optind )
{
optind = i + 1;
fprintf(stderr, "%s ", a3[i]);
fflush(stderr);
}
fputc(10, stderr);
fflush(stderr);
return 4LL;
}

original_code:
static int override_config_from_args(tesr_config_t *thiz, int argc, char **argv) {
    int config_err = 0;
    int c;
    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            {"port", 1, 0, 'p'},
            {"workers", 1, 0, 'w'},
            {"help", 0, 0, 'h'},
            {"daemon", 0, 0, 'd'},
            {0, 0, 0, 0 }
        };
        c = getopt_long(argc, argv, "p:w:dh", long_options, &option_index);
        if (c == -1)
            break;
        switch (c) {
        case 'h':
            config_err = 5;
            break;
        case 'd':
            thiz->daemonize = 1;
            break;
        case 'p':
            thiz->recv_port = atoi(optarg);
            if(thiz->recv_port == 0) {
                do{;fprintf(stderr,"[KO] non-numeric port '%s'", optarg);fflush(stderr);}while(0);
                config_err = 1;
            } else {
                do{}while(0);
            }
            break;
        case 'w':
            thiz->num_workers = atoi(optarg);
            do{}while(0);
            break;
        case '?':
            config_err = 2;
            do{;fprintf(stderr,"?? invalid option 0%o ??\n", c);fflush(stderr);}while(0);
            break;
        default:
            do{;fprintf(stderr,"?? getopt returned character code 0%o ??\n", c);fflush(stderr);}while(0);
            config_err = 3;
        }
    }
   if (optind < argc) {
        do{;fprintf(stderr,"non-option ARGV-elements: ");fflush(stderr);}while(0);
        while (optind < argc)
            do{;fprintf(stderr,"%s ", argv[optind++]);fflush(stderr);}while(0);
        do{;fprintf(stderr,"\n");fflush(stderr);}while(0);
        config_err = 4;
    }
    return config_err;
}

canonical_original_code:
static int override_config_from_args(struct tesr_config_t *thiz, int argc, char **argv) {
    int config_err = 0;
    int c;
    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            {"port", 1, 0, 'p'},
            {"workers", 1, 0, 'w'},
            {"help", 0, 0, 'h'},
            {"daemon", 0, 0, 'd'},
            {0, 0, 0, 0 }
        };
        c = getopt_long(argc, argv, "p:w:dh", long_options, &option_index);
        if (c == -1)
            break;
        switch (c) {
        case 'h':
            config_err = 5;
            break;
        case 'd':
            thiz->daemonize = 1;
            break;
        case 'p':
            thiz->recv_port = atoi(optarg);
            if(thiz->recv_port == 0) {
                do{;fprintf(stderr,"[KO] non-numeric port '%s'", optarg);fflush(stderr);}while(0);
                config_err = 1;
            } else {
                do{}while(0);
            }
            break;
        case 'w':
            thiz->num_workers = atoi(optarg);
            do{}while(0);
            break;
        case '?':
            config_err = 2;
            do{;fprintf(stderr,"?? invalid option 0%o ??\n", c);fflush(stderr);}while(0);
            break;
        default:
            do{;fprintf(stderr,"?? getopt returned character code 0%o ??\n", c);fflush(stderr);}while(0);
            config_err = 3;
        }
    }
   if (optind < argc) {
        do{;fprintf(stderr,"non-option ARGV-elements: ");fflush(stderr);}while(0);
        while (optind < argc)
            do{;fprintf(stderr,"%s ", argv[optind++]);fflush(stderr);}while(0);
        do{;fprintf(stderr,"\n");fflush(stderr);}while(0);
        config_err = 4;
    }
    return config_err;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

user_defined_types: struct tesr_filter_t { char filter[16]; struct tesr_filter_t *next; }


decompiled_code:
void *create_config()
{
return malloc(0x20uLL);
}

canonical_decompiled_code:
void *func6()
{
return malloc(0x20uLL);
}

original_code:
tesr_config_t *create_config() {
    tesr_config_t* thiz = ((void *)0);
    thiz = (tesr_config_t*)malloc(sizeof(tesr_config_t));
    do{}while(0);
    return thiz;
}

canonical_original_code:
struct tesr_config_t *create_config() {
    struct tesr_config_t *thiz = ((void *)0);
    thiz = (struct tesr_config_t *)malloc(sizeof(tesr_config_t));
    do{}while(0);
    return thiz;
}

return_type: struct tesr_config_t { int daemonize; int recv_port; int irl_max; int irl_inactivity_timeout; int irl_garbage_collect_count; int num_workers; struct tesr_filter_t { char filter[16]; struct tesr_filter_t *next; } *filters; } *


decompiled_code:
__int64 __fastcall init_config(_QWORD *a1, int a2, char *const *a3)
{
__int64 result; // rax
int v5; // ebp

init_config_from_defaults(a1);
override_config_from_file_isra_0((__int64)a1);
result = override_config_from_args(a1, a2, a3);
if ( (_DWORD)result )
{
v5 = result;
fwrite(
"\n"
"USAGE tesr [T]hreaded [E]cho [S]erve[R]\n"
"-d (daemonize)\n"
"-p --port (override the port)\n"
"-w --workers (override the number of workers)\n",
1uLL,
0x84uLL,
stderr);
fflush(stderr);
exit(v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2, char *const *a3)
{
__int64 result; // rax
int v5; // ebp

func0(a1);
func5((__int64)a1);
result = func2(a1, a2, a3);
if ( (_DWORD)result )
{
v5 = result;
fwrite(
"\n"
"USAGE tesr [T]hreaded [E]cho [S]erve[R]\n"
"-d (daemonize)\n"
"-p --port (override the port)\n"
"-w --workers (override the number of workers)\n",
1uLL,
0x84uLL,
stderr);
fflush(stderr);
exit(v5);
}
return result;
}

original_code:
void init_config(tesr_config_t *thiz, int argc, char **argv) {
    init_config_from_defaults(thiz);
    override_config_from_file(thiz);
    int config_err = override_config_from_args(thiz, argc, argv);
    if(config_err) {
        do{;fprintf(stderr,"\nUSAGE tesr [T]hreaded [E]cho [S]erve[R]\n-d (daemonize)\n-p --port (override the port)\n-w --workers (override the number of workers)\n");fflush(stderr);}while(0);
        exit(config_err);
    }
}

canonical_original_code:
void init_config(struct tesr_config_t *thiz, int argc, char **argv) {
    init_config_from_defaults(thiz);
    override_config_from_file(thiz);
    int config_err = override_config_from_args(thiz, argc, argv);
    if(config_err) {
        do{;fprintf(stderr,"\nUSAGE tesr [T]hreaded [E]cho [S]erve[R]\n-d (daemonize)\n-p --port (override the port)\n-w --workers (override the number of workers)\n");fflush(stderr);}while(0);
        exit(config_err);
    }
}


decompiled_code:
void __fastcall destroy_config(void *ptr)
{
if ( ptr )
{
destroy_filters_list(*((_QWORD *)ptr + 3));
free(ptr);
}
else
{
fwrite("can not free tesr_config_t* as it is NULL", 1uLL, 0x29uLL, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
if ( ptr )
{
destroy_filters_list(*((_QWORD *)ptr + 3));
free(ptr);
}
else
{
fwrite("can not free tesr_config_t* as it is NULL", 1uLL, 0x29uLL, stderr);
fflush(stderr);
}
}

original_code:
void destroy_config(tesr_config_t *thiz) {
    if(thiz) {
        destroy_filters_list(thiz->filters);
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free tesr_config_t* as it is NULL");fflush(stderr);}while(0);
    }
}

canonical_original_code:
void destroy_config(struct tesr_config_t *thiz) {
    if(thiz) {
        destroy_filters_list(thiz->filters);
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free tesr_config_t* as it is NULL");fflush(stderr);}while(0);
    }
}


decompiled_code:
int __fastcall log_config(__int64 a1)
{
__int64 v1; // rbx

fprintf(stdout, "recv_port=%d\n", *(unsigned int *)(a1 + 4));
fflush(stdout);
fprintf(stdout, "num_workers=%d\n", *(unsigned int *)(a1 + 20));
fflush(stdout);
fwrite("filters=[", 1uLL, 9uLL, stdout);
fflush(stdout);
v1 = *(_QWORD *)(a1 + 24);
if ( v1 )
{
while ( 1 )
{
fputs((const char *)v1, stdout);
fflush(stdout);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
fputc(44, stdout);
fflush(stdout);
}
}
fwrite("]\n", 1uLL, 2uLL, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
__int64 v1; // rbx

fprintf(stdout, "recv_port=%d\n", *(unsigned int *)(a1 + 4));
fflush(stdout);
fprintf(stdout, "num_workers=%d\n", *(unsigned int *)(a1 + 20));
fflush(stdout);
fwrite("filters=[", 1uLL, 9uLL, stdout);
fflush(stdout);
v1 = *(_QWORD *)(a1 + 24);
if ( v1 )
{
while ( 1 )
{
fputs((const char *)v1, stdout);
fflush(stdout);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
fputc(44, stdout);
fflush(stdout);
}
}
fwrite("]\n", 1uLL, 2uLL, stdout);
return fflush(stdout);
}

original_code:
void log_config(tesr_config_t *thiz) {
    do{;fprintf(stdout,"recv_port=%d\n", thiz->recv_port);fflush(stdout);}while(0);
    do{;fprintf(stdout,"num_workers=%d\n", thiz->num_workers);fflush(stdout);}while(0);
    int print_comma = 0;
    tesr_filter_t *filter = ((void *)0);
    do{;fprintf(stdout,"filters=[");fflush(stdout);}while(0);
    for(filter=thiz->filters;filter;filter=(filter)->next) {
        if(print_comma) {
            do{;fprintf(stdout,",");fflush(stdout);}while(0);
        } else {
            print_comma = 1;
        }
        do{;fprintf(stdout,"%s", filter->filter);fflush(stdout);}while(0);
    }
    do{;fprintf(stdout,"]\n");fflush(stdout);}while(0);
}

canonical_original_code:
void log_config(struct tesr_config_t *thiz) {
    do{;fprintf(stdout,"recv_port=%d\n", thiz->recv_port);fflush(stdout);}while(0);
    do{;fprintf(stdout,"num_workers=%d\n", thiz->num_workers);fflush(stdout);}while(0);
    int print_comma = 0;
    struct tesr_filter_t *filter = ((void *)0);
    do{;fprintf(stdout,"filters=[");fflush(stdout);}while(0);
    for(filter=thiz->filters;filter;filter=(filter)->next) {
        if(print_comma) {
            do{;fprintf(stdout,",");fflush(stdout);}while(0);
        } else {
            print_comma = 1;
        }
        do{;fprintf(stdout,"%s", filter->filter);fflush(stdout);}while(0);
    }
    do{;fprintf(stdout,"]\n");fflush(stdout);}while(0);
}

variable_types: struct tesr_filter_t { char filter[16]; struct tesr_filter_t *next; } *


decompiled_code:
__int64 __fastcall bind_dgram_socket(int *a1, __m128i *a2, unsigned int a3)
{
int v4; // ebx
socklen_t v5; // edx
int v6; // er8
__int64 result; // rax
__m128i v8; // xmm1
struct sockaddr v9; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 2, 0);
v9 = 0LL;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = _bswap_16(a3);
v6 = bind(v4, &v9, v5);
result = 1LL;
if ( v6 )
{
fprintf(stderr, "binding to port %d failed\n", a3);
fflush(stderr);
result = 0LL;
}
v8 = _mm_loadu_si128((const __m128i *)&v9);
*a1 = v4;
*a2 = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, __m128i *a2, unsigned int a3)
{
int v4; // ebx
socklen_t v5; // edx
int v6; // er8
__int64 result; // rax
__m128i v8; // xmm1
struct sockaddr v9; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 2, 0);
v9 = 0LL;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = func0(a3);
v6 = bind(v4, &v9, v5);
result = 1LL;
if ( v6 )
{
fprintf(stderr, "binding to port %d failed\n", a3);
fflush(stderr);
result = 0LL;
}
v8 = _mm_loadu_si128((const __m128i *)&v9);
*a1 = v4;
*a2 = v8;
return result;
}

original_code:
int bind_dgram_socket(int *sd, struct sockaddr_in *addr, int port) {
    int ret = 1;
    int sockd;
    struct sockaddr_in inaddr;
    sockd = socket(2, SOCK_DGRAM, 0);
    bzero(&inaddr, sizeof(inaddr));
    inaddr.sin_family = 2;
    inaddr.sin_port = htons(port);
    inaddr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    if (bind(sockd, (struct sockaddr*) &inaddr, sizeof(inaddr)) != 0) {
        do{;fprintf(stderr,"binding to port %d failed\n", port);fflush(stderr);}while(0);
        ret = 0;
    }
    *sd = sockd;
    *addr = inaddr;
    return ret;
}

canonical_original_code:
int bind_dgram_socket(int *sd, struct sockaddr_in *addr, int port) {
    int ret = 1;
    int sockd;
    struct sockaddr_in inaddr;
    sockd = socket(2, SOCK_DGRAM, 0);
    bzero(&inaddr, sizeof(inaddr));
    inaddr.sin_family = 2;
    inaddr.sin_port = htons(port);
    inaddr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    if (bind(sockd, (struct sockaddr *) &inaddr, sizeof(inaddr)) != 0) {
        do{;fprintf(stderr,"binding to port %d failed\n", port);fflush(stderr);}while(0);
        ret = 0;
    }
    *sd = sockd;
    *addr = inaddr;
    return ret;
}

variable_types:
sd
int *

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

variable_types: port int

variable_types: ret int

variable_types: sockd int

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


decompiled_code:
__int64 __fastcall is_correctly_formatted(const char *a1)
{
__int64 v1; // rax
char *v2; // rcx
__int64 v3; // r9
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

endptr = 0LL;
v1 = strtoll(a1, &endptr, 10);
v2 = endptr;
v3 = v1;
if ( !*a1 )
{
if ( endptr )
{
LABEL_8:
fprintf(stdout, "[KO] incorrectly formatted payload stroll(%s, %s, %d) = %llu", a1, v2, 10LL, v3);
fflush(stdout);
return 0LL;
}
LABEL_7:
endptr = "NULL";
v2 = "NULL";
goto LABEL_8;
}
if ( !endptr )
goto LABEL_7;
if ( *endptr )
goto LABEL_8;
result = 1LL;
if ( v3 <= 0 )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v1; // rax
char *v2; // rcx
__int64 v3; // r9
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

endptr = 0LL;
v1 = strtoll(a1, &endptr, 10);
v2 = endptr;
v3 = v1;
if ( !*a1 )
{
if ( endptr )
{
LABEL_8:
fprintf(stdout, "[KO] incorrectly formatted payload stroll(%s, %s, %d) = %llu", a1, v2, 10LL, v3);
fflush(stdout);
return 0LL;
}
LABEL_7:
endptr = "NULL";
v2 = "NULL";
goto LABEL_8;
}
if ( !endptr )
goto LABEL_7;
if ( *endptr )
goto LABEL_8;
result = 1LL;
if ( v3 <= 0 )
goto LABEL_8;
return result;
}

original_code:
int is_correctly_formatted(char *buffer) {
    int ret = 0;
    char *endptr = ((void *)0);
    int base = 10;
    long long int echo = strtoll(buffer, &endptr, base);
    if(buffer != ((void *)0) && buffer[0] != '\0' && endptr != ((void *)0) && endptr[0] == '\0' && echo > 0) {
        ret = 1;
    } else {
        if(endptr == ((void *)0)) {
            endptr = "NULL";
        }
        do{;fprintf(stdout,"[KO] incorrectly formatted payload stroll(%s, %s, %d) = %llu", buffer, endptr, base, echo);fflush(stdout);}while(0);
    }
    return ret;
}

canonical_original_code:
int is_correctly_formatted(char *buffer) {
    int ret = 0;
    char *endptr = ((void *)0);
    int base = 10;
    long long echo = strtoll(buffer, &endptr, base);
    if(buffer != ((void *)0) && buffer[0] != '\0' && endptr != ((void *)0) && endptr[0] == '\0' && echo > 0) {
        ret = 1;
    } else {
        if(endptr == ((void *)0)) {
            endptr = "NULL";
        }
        do{;fprintf(stdout,"[KO] incorrectly formatted payload stroll(%s, %s, %d) = %llu", buffer, endptr, base, echo);fflush(stdout);}while(0);
    }
    return ret;
}

variable_types:
buffer
char *

variable_types:
endptr
char *

variable_types: base int

variable_types:
echo
long long


decompiled_code:
_BOOL8 __fastcall should_echo(const char *a1, int a2, unsigned __int16 *a3, char *a4, __int64 a5)
{
_BOOL8 result; // rax
char v8[40]; // [rsp-28h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
a1[a2] = 0;
inet_ntop(*a3, a3 + 2, v8, 0x10u);
if ( (unsigned int)is_correctly_formatted(a1) && (unsigned int)passes_filters(v8, a4) )
result = (unsigned int)is_under_rate_limit(a5, v8) != 0;
else
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, int a2, unsigned __int16 *a3, char *a4, __int64 a5)
{
_BOOL8 result; // rax
char v8[40]; // [rsp-28h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
a1[a2] = 0;
inet_ntop(*a3, a3 + 2, v8, 0x10u);
if ( (unsigned int)func2(a1) && (unsigned int)func3(v8, a4) )
result = (unsigned int)is_under_rate_limit(a5, v8) != 0;
else
result = 0LL;
}
return result;
}

original_code:
int should_echo(char *buffer, socklen_t bytes, struct sockaddr_in *addr, tesr_filter_t *filters, rate_limiter_t *rate_limiter) {
    int ret = 0;
    if(buffer != ((void *)0)) {
        buffer[bytes] = '\0';
        char ip[16];
        inet_ntop(addr->sin_family, &addr->sin_addr, ip, 16);
        do{}while(0);
        if(is_correctly_formatted(buffer) && passes_filters(ip, filters) && is_under_rate_limit(rate_limiter, ip)) {
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int should_echo(char *buffer, unsigned int bytes, struct sockaddr_in *addr, struct tesr_filter_t *filters, struct rate_limiter_t *rate_limiter) {
    int ret = 0;
    if(buffer != ((void *)0)) {
        buffer[bytes] = '\0';
        char ip[16];
        inet_ntop(addr->sin_family, &addr->sin_addr, ip, 16);
        do{}while(0);
        if(is_correctly_formatted(buffer) && passes_filters(ip, filters) && is_under_rate_limit(rate_limiter, ip)) {
            ret = 1;
        }
    }
    return ret;
}

variable_types:
bytes
unsigned int

variable_types: struct rate_limiter_t { struct rate_limit_struct_t { char ip[16]; long last_check; int count; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *rate_limit_map; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; int irl_max; int irl_inactivity_timeout; int irl_garbage_collect_count; } *

variable_types:
ip
char [16]

user_defined_types: struct rate_limiter_t { struct rate_limit_struct_t *rate_limit_map; union pthread_mutex_t lock; int irl_max; int irl_inactivity_timeout; int irl_garbage_collect_count; }

user_defined_types: struct rate_limit_struct_t { char ip[16]; long last_check; int count; struct UT_hash_handle hh; }

user_defined_types: struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; }

user_defined_types: struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; }


decompiled_code:
const char *__fastcall get_lock_error_string(unsigned int a1)
{
const char *result; // rax

result = "UNKNOWN lock failure state.";
if ( a1 <= 0x23 )
result = CSWTCH_30[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(unsigned int a1)
{
const char *result; // rax

result = "UNKNOWN lock failure state.";
if ( a1 <= 0x23 )
result = CSWTCH_30[a1];
return result;
}

original_code:
const char *get_lock_error_string(int lock_error) {
    switch(lock_error) {
        case 22:
            return "The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority ceiling.\n-- OR --\nThe value specified by mutex does not refer to an initialized mutex object.";
        case 16:
            return "The mutex could not be acquired because it was already locked.";
        break;
        case 11:
            return "The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded.";
        break;
        case 35:
            return "A deadlock condition was detected or the current thread already owns the mutex.";
        break;
        case 1:
            return "The current thread does not own the mutex.";
        break;
        case 0:
            return "Success";
        default:
        break;
    }
    return "UNKNOWN lock failure state.";
}

return_type: char *


decompiled_code:
__int64 __fastcall connect_pipe(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) )
{
fwrite("Can't create notify pipe", 1uLL, 0x18uLL, stderr);
fflush(stderr);
result = 0LL;
}
else
{
*a1 = pipedes[0];
*a2 = pipedes[1];
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) )
{
fwrite("Can't create notify pipe", 1uLL, 0x18uLL, stderr);
fflush(stderr);
result = 0LL;
}
else
{
*a1 = pipedes[0];
*a2 = pipedes[1];
result = 1LL;
}
return result;
}

original_code:
int connect_pipe(int *int_fd, int *ext_fd) {
    int fds[2];
    if(pipe(fds)) {
        do{;fprintf(stderr,"Can't create notify pipe");fflush(stderr);}while(0);
        return 0;
    }
    *int_fd = fds[0];
    *ext_fd = fds[1];
     return 1;
}

variable_types:
fds
int [2]


decompiled_code:
void *create_queue_data()
{
return malloc(0x428uLL);
}

canonical_decompiled_code:
void *func7()
{
return malloc(0x428uLL);
}

original_code:
queue_data_t *create_queue_data() {
    queue_data_t *thiz = ((void *)0);
    thiz = (queue_data_t*)malloc(sizeof(queue_data_t));
    do{}while(0);
    return thiz;
}

canonical_original_code:
struct queue_data_t *create_queue_data() {
    struct queue_data_t *thiz = ((void *)0);
    thiz = (struct queue_data_t *)malloc(sizeof(queue_data_t));
    do{}while(0);
    return thiz;
}

variable_types: struct queue_data_t { char buffer[1024]; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int bytes; int addr_len; int worker_idx; struct queue_data_t *next; } *


decompiled_code:
void __fastcall destroy_queue_data(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free queue_data_t * as it is NULL", 1uLL, 0x29uLL, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free queue_data_t * as it is NULL", 1uLL, 0x29uLL, stderr);
fflush(stderr);
}
}

original_code:
void destroy_queue_data(queue_data_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free queue_data_t * as it is NULL");fflush(stderr);}while(0);
    }
}

canonical_original_code:
void destroy_queue_data(struct queue_data_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free queue_data_t * as it is NULL");fflush(stderr);}while(0);
    }
}


decompiled_code:
void *create_filter()
{
return malloc(0x18uLL);
}

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

original_code:
tesr_filter_t *create_filter() {
    tesr_filter_t *thiz = ((void *)0);
    thiz = (tesr_filter_t*)malloc(sizeof(tesr_filter_t));
    do{}while(0);
    return thiz;
}

canonical_original_code:
struct tesr_filter_t *create_filter() {
    struct tesr_filter_t *thiz = ((void *)0);
    thiz = (struct tesr_filter_t *)malloc(sizeof(tesr_filter_t));
    do{}while(0);
    return thiz;
}

return_type: struct tesr_filter_t { char filter[16]; struct tesr_filter_t *next; } *


decompiled_code:
__int64 __fastcall init_filter(char *a1, const char *a2)
{
strncpy(a1, a2, 0x10uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, const char *a2)
{
strncpy(a1, a2, 0x10uLL);
return 1LL;
}

original_code:
int init_filter(tesr_filter_t *thiz, const char *filter) {
    strncpy(thiz->filter, filter, 16);
    return 1;
}

canonical_original_code:
int init_filter(struct tesr_filter_t *thiz, char *filter) {
    strncpy(thiz->filter, filter, 16);
    return 1;
}

variable_types:
filter
char *


decompiled_code:
void __fastcall destroy_filter(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free tesr_filter_t * as it is NULL", 1uLL, 0x2AuLL, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free tesr_filter_t * as it is NULL", 1uLL, 0x2AuLL, stderr);
fflush(stderr);
}
}

original_code:
void destroy_filter(tesr_filter_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free tesr_filter_t * as it is NULL");fflush(stderr);}while(0);
    }
}

canonical_original_code:
void destroy_filter(struct tesr_filter_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free tesr_filter_t * as it is NULL");fflush(stderr);}while(0);
    }
}


decompiled_code:
char *__fastcall copy_filters_list(__int64 a1)
{
__int64 v1; // rbx
char *v2; // r12
char *v3; // rbp

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0LL;
do
{
v3 = v2;
v2 = (char *)create_filter();
init_filter(v2, (const char *)v1);
*((_QWORD *)v2 + 2) = v3;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1)
{
__int64 v1; // rbx
char *v2; // r12
char *v3; // rbp

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0LL;
do
{
v3 = v2;
v2 = (char *)func9();
func10(v2, (const char *)v1);
*((_QWORD *)v2 + 2) = v3;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

original_code:
tesr_filter_t *copy_filters_list(tesr_filter_t *head) {
    tesr_filter_t *copy_head = ((void *)0);
    tesr_filter_t *copy = ((void *)0);
    tesr_filter_t *filter = ((void *)0);
    for(filter=head;filter;filter=(filter)->next) {
        do{}while(0);
        copy = create_filter();
        init_filter(copy, filter->filter);
        do { (copy)->next = copy_head; copy_head = copy; } while (0);
    }
    return copy_head;
}

canonical_original_code:
struct tesr_filter_t *copy_filters_list(struct tesr_filter_t *head) {
    struct tesr_filter_t *copy_head = ((void *)0);
    struct tesr_filter_t *copy = ((void *)0);
    struct tesr_filter_t *filter = ((void *)0);
    for(filter=head;filter;filter=(filter)->next) {
        do{}while(0);
        copy = create_filter();
        init_filter(copy, filter->filter);
        do { (copy)->next = copy_head; copy_head = copy; } while (0);
    }
    return copy_head;
}

variable_types:
head
struct tesr_filter_t *


decompiled_code:
void *create_rate_limit()
{
return malloc(0x58uLL);
}

canonical_decompiled_code:
void *func14()
{
return malloc(0x58uLL);
}

original_code:
rate_limit_struct_t *create_rate_limit() {
    rate_limit_struct_t *thiz = ((void *)0);
    thiz = (rate_limit_struct_t*)malloc(sizeof(rate_limit_struct_t));
    do{}while(0);
    return thiz;
}

canonical_original_code:
struct rate_limit_struct_t *create_rate_limit() {
    struct rate_limit_struct_t *thiz = ((void *)0);
    thiz = (struct rate_limit_struct_t *)malloc(sizeof(rate_limit_struct_t));
    do{}while(0);
    return thiz;
}

variable_types: struct rate_limit_struct_t { char ip[16]; long last_check; int count; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *


decompiled_code:
__int64 __fastcall init_rate_limit(char *a1, const char *a2)
{
char *v2; // rax

v2 = strncpy(a1, a2, 0x10uLL);
*((_DWORD *)v2 + 6) = 0;
time((time_t *)v2 + 2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1, const char *a2)
{
char *v2; // rax

v2 = strncpy(a1, a2, 0x10uLL);
*((_DWORD *)v2 + 6) = 0;
time((time_t *)v2 + 2);
return 1LL;
}

original_code:
int init_rate_limit(rate_limit_struct_t *thiz, const char *ip) {
    strncpy(thiz->ip, ip, 16);
    thiz->count = 0;
    time(&thiz->last_check);
    return 1;
}

canonical_original_code:
int init_rate_limit(struct rate_limit_struct_t *thiz, char *ip) {
    strncpy(thiz->ip, ip, 16);
    thiz->count = 0;
    time(&thiz->last_check);
    return 1;
}

variable_types:
ip
char *

user_defined_types: struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; }


decompiled_code:
void __fastcall destroy_rate_limit(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free rate_limit_struct_t * as it is NULL", 1uLL, 0x30uLL, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func16(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fwrite("can not free rate_limit_struct_t * as it is NULL", 1uLL, 0x30uLL, stderr);
fflush(stderr);
}
}

original_code:
void destroy_rate_limit(rate_limit_struct_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free rate_limit_struct_t * as it is NULL");fflush(stderr);}while(0);
    }
}

canonical_original_code:
void destroy_rate_limit(struct rate_limit_struct_t *thiz) {
    if(thiz) {
        do{}while(0);
        free(thiz);
        thiz = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free rate_limit_struct_t * as it is NULL");fflush(stderr);}while(0);
    }
}


original_code:
void destroy_rate_limit_map(rate_limit_struct_t *map) {
    rate_limit_struct_t *rl = ((void *)0);
    rate_limit_struct_t *tmp = ((void *)0);
    for((rl)=(map),(tmp)=(__typeof(rl))((map)?(map)->hh.next:((void *)0)); rl; (rl)=(tmp),(tmp)=(__typeof(rl))((tmp)?(tmp)->hh.next:((void *)0))) {
        do { unsigned _hd_bkt; struct UT_hash_handle *_hd_hh_del; if ( ((rl)->hh.prev == ((void *)0)) && ((rl)->hh.next == ((void *)0)) ) { free((map)->hh.tbl->buckets); ; free((map)->hh.tbl); map = ((void *)0); } else { _hd_hh_del = &((rl)->hh); if ((rl) == ((void*)(((char*)((map)->hh.tbl->tail)) - (((map)->hh.tbl)->hho)))) { (map)->hh.tbl->tail = (UT_hash_handle*)((ptrdiff_t)((rl)->hh.prev) + (map)->hh.tbl->hho); } if ((rl)->hh.prev) { ((UT_hash_handle*)((ptrdiff_t)((rl)->hh.prev) + (map)->hh.tbl->hho))->next = (rl)->hh.next; } else { do { (map) = (__typeof(map))((rl)->hh.next); } while(0); } if (_hd_hh_del->next) { ((UT_hash_handle*)((ptrdiff_t)_hd_hh_del->next + (map)->hh.tbl->hho))->prev = _hd_hh_del->prev; } do { _hd_bkt = ((_hd_hh_del->hashv) & (((map)->hh.tbl->num_buckets) - 1)); } while(0); ((map)->hh.tbl->buckets[_hd_bkt]).count--; if (((map)->hh.tbl->buckets[_hd_bkt]).hh_head == _hd_hh_del) { ((map)->hh.tbl->buckets[_hd_bkt]).hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { _hd_hh_del->hh_prev->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { _hd_hh_del->hh_next->hh_prev = _hd_hh_del->hh_prev; }; (map)->hh.tbl->num_items--; } ; } while (0);
        destroy_rate_limit(rl);
    }
}

canonical_original_code:
void destroy_rate_limit_map(struct rate_limit_struct_t *map) {
    struct rate_limit_struct_t *rl = ((void *)0);
    struct rate_limit_struct_t *tmp = ((void *)0);
    for((rl)=(map),(tmp)=(__typeof(rl))((map)?(map)->hh.next:((void *)0)); rl; (rl)=(tmp),(tmp)=(__typeof(rl))((tmp)?(tmp)->hh.next:((void *)0))) {
        do { unsigned int _hd_bkt; struct UT_hash_handle *_hd_hh_del; if ( ((rl)->hh.prev == ((void *)0)) && ((rl)->hh.next == ((void *)0)) ) { free((map)->hh.tbl->buckets); ; free((map)->hh.tbl); map = ((void *)0); } else { _hd_hh_del = &((rl)->hh); if ((rl) == ((void *)(((char *)((map)->hh.tbl->tail)) - (((map)->hh.tbl)->hho)))) { (map)->hh.tbl->tail = (struct UT_hash_handle *)((long)((rl)->hh.prev) + (map)->hh.tbl->hho); } if ((rl)->hh.prev) { ((struct UT_hash_handle *)((long)((rl)->hh.prev) + (map)->hh.tbl->hho))->next = (rl)->hh.next; } else { do { (map) = (__typeof(map))((rl)->hh.next); } while(0); } if (_hd_hh_del->next) { ((struct UT_hash_handle *)((long)_hd_hh_del->next + (map)->hh.tbl->hho))->prev = _hd_hh_del->prev; } do { _hd_bkt = ((_hd_hh_del->hashv) & (((map)->hh.tbl->num_buckets) - 1)); } while(0); ((map)->hh.tbl->buckets[_hd_bkt]).count--; if (((map)->hh.tbl->buckets[_hd_bkt]).hh_head == _hd_hh_del) { ((map)->hh.tbl->buckets[_hd_bkt]).hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { _hd_hh_del->hh_prev->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { _hd_hh_del->hh_next->hh_prev = _hd_hh_del->hh_prev; }; (map)->hh.tbl->num_items--; } ; } while (0);
        destroy_rate_limit(rl);
    }
}

variable_types: struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } *


decompiled_code:
void destroy_worker_array()
{
if ( worker_threads )
{
num_threads = 0;
free(worker_threads);
worker_threads = 0LL;
}
else
{
fwrite("can not free worker_threads ** as it is NULL\n", 1uLL, 0x2DuLL, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void func4()
{
if ( worker_threads )
{
num_threads = 0;
free(worker_threads);
worker_threads = 0LL;
}
else
{
fwrite("can not free worker_threads ** as it is NULL\n", 1uLL, 0x2DuLL, stderr);
fflush(stderr);
}
}

original_code:
void destroy_worker_array() {
    if(worker_threads) {
        num_threads = 0;
        do{}while(0);
        free(worker_threads);
        worker_threads = ((void *)0);
    } else {
        do{;fprintf(stderr,"can not free worker_threads ** as it is NULL\n");fflush(stderr);}while(0);
    }
}


daemonize

decompiled_code:
FILE *daemonize()
{
unsigned int v0; // eax
__pid_t v1; // eax
unsigned int v2; // eax
__int64 v4; // [rsp+0h] [rbp-8h]

if ( getppid() == 1 )
return (FILE *)v4;
v0 = getpid();
fprintf(stdout, "prefork pid = %d\n", v0);
fflush(stdout);
v1 = fork();
if ( v1 < 0 )
goto LABEL_9;
if ( v1 )
exit(0);
v2 = getpid();
fprintf(stdout, "daemon pid = %d\n", v2);
fflush(stdout);
umask(0);
if ( setsid() < 0 || chdir("/") < 0 )
LABEL_9:
exit(1);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
return freopen("/dev/null", "w", stderr);
}

canonical_decompiled_code:
FILE *func0()
{
unsigned int v0; // eax
__pid_t v1; // eax
unsigned int v2; // eax
__int64 v4; // [rsp+0h] [rbp-8h]

if ( getppid() == 1 )
return (FILE *)v4;
v0 = getpid();
fprintf(stdout, "prefork pid = %d\n", v0);
fflush(stdout);
v1 = fork();
if ( v1 < 0 )
goto LABEL_9;
if ( v1 )
exit(0);
v2 = getpid();
fprintf(stdout, "daemon pid = %d\n", v2);
fflush(stdout);
umask(0);
if ( setsid() < 0 || chdir("/") < 0 )
LABEL_9:
exit(1);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
return freopen("/dev/null", "w", stderr);
}

original_code:
static void daemonize(void) {
    pid_t pid, sid;
    if ( getppid() == 1 ) return;
    do{;fprintf(stdout,"prefork pid = %d\n", getpid());fflush(stdout);}while(0);
    pid = fork();
    if (pid < 0) {
        exit(1);
    }
    if (pid > 0) {
        exit(0);
    }
    do{;fprintf(stdout,"daemon pid = %d\n", getpid());fflush(stdout);}while(0);
    umask(0);
    sid = setsid();
    if (sid < 0) {
        exit(1);
    }
    if ((chdir("/")) < 0) {
        exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/dev/null", "w", stderr);
}

canonical_original_code:
static void daemonize() {
    int pid; int sid;
    if ( getppid() == 1 ) return;
    do{;fprintf(stdout,"prefork pid = %d\n", getpid());fflush(stdout);}while(0);
    pid = fork();
    if (pid < 0) {
        exit(1);
    }
    if (pid > 0) {
        exit(0);
    }
    do{;fprintf(stdout,"daemon pid = %d\n", getpid());fflush(stdout);}while(0);
    umask(0);
    sid = setsid();
    if (sid < 0) {
        exit(1);
    }
    if ((chdir("/")) < 0) {
        exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/dev/null", "w", stderr);
}

variable_types: pid int

variable_types: sid int


nodeCounter

decompiled_code:
__int64 __fastcall nodeCounter(__int64 a1, int a2)
{
unsigned int v2; // er8
_QWORD *v3; // rax
_QWORD *v4; // rdi

if ( a2 < 0 )
return 0LL;
v2 = 0;
v3 = (_QWORD *)(a1 + 8LL * a2);
v4 = (_QWORD *)(a1 - 8);
do
v2 -= (*v3-- == 0LL) - 1;
while ( v3 != v4 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
unsigned int v2; // er8
_QWORD *v3; // rax
_QWORD *v4; // rdi

if ( a2 < 0 )
return 0LL;
v2 = 0;
v3 = (_QWORD *)(a1 + 8LL * a2);
v4 = (_QWORD *)(a1 - 8);
do
v2 -= (*v3-- == 0LL) - 1;
while ( v3 != v4 );
return v2;
}

original_code:
int nodeCounter(struct node **hashArray, int hashSize)
  {
    int filledNodes = 0;
    for (; hashSize >= 0; hashSize--)
    {
      if (hashArray[hashSize] != ((void *)0))
      {
        filledNodes++;
      }
    }
    return filledNodes;
  }

variable_types: struct node { char token[16]; struct node *next; } **

variable_types: hashSize int

variable_types: filledNodes int


maxNodes

original_code:
int maxNodes(struct node **hashArray, int filledNodes, int hashSize)
  {
   int nodeCounter = 0;
   int maxEntries = 0;
   int i = 0;
   struct node* temp;
    for (i=0; i<hashSize; i++)
    {
    temp = hashArray[i];
 if(temp != ((void *)0))
        {
  while(temp != ((void *)0))
  {
   nodeCounter++;
   temp = temp->next;
  }
   if (nodeCounter > maxEntries)
   {
     maxEntries = nodeCounter;
   }
 }
 nodeCounter = 0;
    }
  return maxEntries;
  }

canonical_original_code:
int maxNodes(struct node **hashArray, int filledNodes, int hashSize)
  {
   int nodeCounter = 0;
   int maxEntries = 0;
   int i = 0;
   struct node *temp;
    for (i=0; i<hashSize; i++)
    {
    temp = hashArray[i];
 if(temp != ((void *)0))
        {
  while(temp != ((void *)0))
  {
   nodeCounter++;
   temp = temp->next;
  }
   if (nodeCounter > maxEntries)
   {
     maxEntries = nodeCounter;
   }
 }
 nodeCounter = 0;
    }
  return maxEntries;
  }

variable_types: nodeCounter int

variable_types: maxEntries int

variable_types: i int

variable_types: struct node { char token[16]; struct node *next; } *


minNodes

original_code:
int minNodes(struct node **hashArray, int filledNodes, int hashSize, int maxEntries)
  {
    int nodeCounter = 0;
    int minEntries = maxEntries;
    int i = 0;
    struct node* temp;
    for (i=0; i<hashSize; i++)
    {
    temp = hashArray[i];
 if(temp != ((void *)0))
        {
  while(temp != ((void *)0))
  {
   nodeCounter++;
   temp = temp->next;
  }
   if (nodeCounter <= minEntries && nodeCounter != 0)
   {
     minEntries = nodeCounter;
   }
 }
 nodeCounter = 0;
    }
     return minEntries;
  }

canonical_original_code:
int minNodes(struct node **hashArray, int filledNodes, int hashSize, int maxEntries)
  {
    int nodeCounter = 0;
    int minEntries = maxEntries;
    int i = 0;
    struct node *temp;
    for (i=0; i<hashSize; i++)
    {
    temp = hashArray[i];
 if(temp != ((void *)0))
        {
  while(temp != ((void *)0))
  {
   nodeCounter++;
   temp = temp->next;
  }
   if (nodeCounter <= minEntries && nodeCounter != 0)
   {
     minEntries = nodeCounter;
   }
 }
 nodeCounter = 0;
    }
     return minEntries;
  }

variable_types: minEntries int

user_defined_types: struct node { char token[16]; struct node *next; }


totalNode

original_code:
int totalNode(struct node **hashArray, int filledNodes, int hashSize)
  {
   int totalNodes = 0;
   int i = 0;
   struct node* temp;
    for (i=0; i<hashSize; i++)
    {
    temp = hashArray[i];
 if(temp != ((void *)0))
        {
  while(temp != ((void *)0))
  {
    totalNodes++;
    temp = temp->next;
  }
 }
    }
  return totalNodes;
  }

canonical_original_code:
int totalNode(struct node **hashArray, int filledNodes, int hashSize)
  {
   int totalNodes = 0;
   int i = 0;
   struct node *temp;
    for (i=0; i<hashSize; i++)
    {
    temp = hashArray[i];
 if(temp != ((void *)0))
        {
  while(temp != ((void *)0))
  {
    totalNodes++;
    temp = temp->next;
  }
 }
    }
  return totalNodes;
  }

variable_types: totalNodes int


repo: nickleefly/experiment

decompiled_code:
double *__fastcall skip_list_alloc(int a1, __int64 a2, double a3)
{
double *v4; // rax
double *v5; // r12
int v6; // ebx
void *v7; // rax
double v9; // [rsp+0h] [rbp-30h]

v4 = (double *)malloc(0x30uLL);
v4[2] = a3;
v5 = v4;
*((_QWORD *)v4 + 4) = a2;
v9 = log((double)a1);
v6 = (int)(COERCE_DOUBLE(*(_QWORD *)&v9 ^ LC0) / log(a3));
*((_DWORD *)v5 + 6) = v6;
v7 = malloc(8LL * v6);
*(_QWORD *)v5 = v7;
if ( v6 > 0 )
memset(v7, 0, 8LL * v6);
*((_DWORD *)v5 + 10) = 0;
*((_QWORD *)v5 + 1) = malloc(8LL * v6);
return v5;
}

canonical_decompiled_code:
double *__fastcall func0(int a1, __int64 a2, double a3)
{
double *v4; // rax
double *v5; // r12
int v6; // ebx
void *v7; // rax
double v9; // [rsp+0h] [rbp-30h]

v4 = (double *)malloc(0x30uLL);
v4[2] = a3;
v5 = v4;
*((_QWORD *)v4 + 4) = a2;
v9 = log((double)a1);
v6 = (int)(COERCE_DOUBLE(*(_QWORD *)&v9 ^ LC0) / log(a3));
*((_DWORD *)v5 + 6) = v6;
v7 = malloc(8LL * v6);
*(_QWORD *)v5 = v7;
if ( v6 > 0 )
memset(v7, 0, 8LL * v6);
*((_DWORD *)v5 + 10) = 0;
*((_QWORD *)v5 + 1) = malloc(8LL * v6);
return v5;
}

original_code:
skip_list_t *skip_list_alloc(int max_n, double prob,
        int (* compar)(const void *, const void *))
{
    int i, max_level;
    skip_list_t *t;
    skip_node_t **head_ptrs;
    t = malloc(sizeof(skip_list_t));
    t->p = prob;
    t->compar = compar;
    max_level = t->max_level = -log(max_n)/log(prob);
    head_ptrs = t->head_ptrs = malloc(max_level * sizeof(skip_node_t *));
    for(i = 0; i < max_level; i++) {
 head_ptrs[i] = ((void *)0);
    }
    t->n = 0;
    t->update = malloc(max_level * sizeof(skip_node_t **));
    return t;
}

canonical_original_code:
struct skip_list *skip_list_alloc(int max_n, double prob, int (*compar)(void *, void *))
{
    int i; int max_level;
    struct skip_list *t;
    struct skip_node **head_ptrs;
    t = malloc(sizeof(skip_list_t));
    t->p = prob;
    t->compar = compar;
    max_level = t->max_level = -log(max_n)/log(prob);
    head_ptrs = t->head_ptrs = malloc(max_level * sizeof(struct skip_node *));
    for(i = 0; i < max_level; i++) {
 head_ptrs[i] = ((void *)0);
    }
    t->n = 0;
    t->update = malloc(max_level * sizeof(struct skip_node **));
    return t;
}

variable_types: prob double

variable_types:
compar
int (*)(void *, void *)

variable_types: struct skip_list { struct skip_node { void *item; struct skip_node **forward; int size; } **head_ptrs; struct skip_node ***update; double p; int max_level; int (*compar)(void *, void *); int n; } *

user_defined_types: struct skip_list { struct skip_node **head_ptrs; struct skip_node ***update; double p; int max_level; int (*compar)(void *, void *); int n; }


decompiled_code:
void __fastcall skip_list_free(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
_QWORD *v4; // rdi
void *v5; // rbp

v2 = *(_QWORD **)ptr;
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = (_QWORD *)v3[1];
v5 = v3;
v3 = (_QWORD *)*v4;
free(v4);
free(v5);
}
while ( v3 );
v2 = *(_QWORD **)ptr;
}
free(v2);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
_QWORD *v4; // rdi
void *v5; // rbp

v2 = *(_QWORD **)ptr;
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = (_QWORD *)v3[1];
v5 = v3;
v3 = (_QWORD *)*v4;
free(v4);
free(v5);
}
while ( v3 );
v2 = *(_QWORD **)ptr;
}
free(v2);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void skip_list_free(skip_list_t *t)
{
    skip_node_t *remove_node, *next;
    next = t->head_ptrs[0];
    while(next) {
 remove_node = next;
 next = remove_node->forward[0];
 free(remove_node->forward);
 free(remove_node);
    }
    free(t->head_ptrs);
    free(t->update);
    free(t);
}

canonical_original_code:
void skip_list_free(struct skip_list *t)
{
    struct skip_node *remove_node; struct skip_node *next;
    next = t->head_ptrs[0];
    while(next) {
 remove_node = next;
 next = remove_node->forward[0];
 free(remove_node->forward);
 free(remove_node);
    }
    free(t->head_ptrs);
    free(t->update);
    free(t);
}

variable_types: struct skip_node { void *item; struct skip_node **forward; int size; } *


original_code:
void *skip_list_find(skip_list_t *t, void *key_item)
{
    skip_node_t **forward;
    int (* compar)(const void *, const void *);
    int cmp_result;
    int i;
    int max_level;
    compar = t->compar;
    max_level = t->max_level;
    forward = t->head_ptrs;
    i = max_level - 1;
    for(;;) {
 while(forward[i] == ((void *)0)) {
     i--;
            if(i < 0) goto end_find_loop;
 }
        while((cmp_result = compar(forward[i]->item, key_item)) >= 0) {
     i--;
     if(i < 0) goto end_find_loop;
 }
 forward = forward[i]->forward;
    }
  end_find_loop:
    if(forward[0] && cmp_result == 0) return forward[0]->item;
    return ((void *)0);
}

canonical_original_code:
void *skip_list_find(struct skip_list *t, void *key_item)
{
    struct skip_node **forward;
    int (*compar)(void *, void *);
    int cmp_result;
    int i;
    int max_level;
    compar = t->compar;
    max_level = t->max_level;
    forward = t->head_ptrs;
    i = max_level - 1;
    for(;;) {
 while(forward[i] == ((void *)0)) {
     i--;
            if(i < 0) goto end_find_loop;
 }
        while((cmp_result = compar(forward[i]->item, key_item)) >= 0) {
     i--;
     if(i < 0) goto end_find_loop;
 }
 forward = forward[i]->forward;
    }
  end_find_loop:
    if(forward[0] && cmp_result == 0) return forward[0]->item;
    return ((void *)0);
}

variable_types: struct skip_node { void *item; struct skip_node **forward; int size; } **


decompiled_code:
__int64 __fastcall skip_list_find_min(__int64 a1)
{
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return **(_QWORD **)a1;
}

original_code:
void *skip_list_find_min(skip_list_t *t)
{
    return t->head_ptrs[0];
}

canonical_original_code:
void *skip_list_find_min(struct skip_list *t)
{
    return t->head_ptrs[0];
}

user_defined_types: struct skip_node { void *item; struct skip_node **forward; int size; }


original_code:
void *skip_list_delete(skip_list_t *t, void *item)
{
    skip_node_t *remove_node, **forward, ***update;
    int (* compar)(const void *, const void *);
    int cmp_result;
    int i;
    int max_level, l;
    void *return_item;
    compar = t->compar;
    update = t->update;
    max_level = t->max_level;
    forward = t->head_ptrs;
    i = max_level - 1;
    for(;;) {
 while(forward[i] == ((void *)0)) {
     update[i] = &forward[i];
     i--;
            if(i < 0) goto end_find_loop;
 }
        while((cmp_result = compar(forward[i]->item, item)) >= 0) {
     update[i] = &forward[i];
     i--;
     if(i < 0) goto end_find_loop;
 }
 forward = forward[i]->forward;
    }
  end_find_loop:
    remove_node = forward[0];
    if(remove_node == ((void *)0) || cmp_result != 0) return ((void *)0);
    l = remove_node->size;
    forward = remove_node->forward;
    for(i = 0; i < l; i++) {
        *update[i] = forward[i];
    }
    return_item = remove_node->item;
    free(forward);
    free(remove_node);
    t->n--;
    return return_item;
}

canonical_original_code:
void *skip_list_delete(struct skip_list *t, void *item)
{
    struct skip_node *remove_node; struct skip_node **forward; struct skip_node ***update;
    int (*compar)(void *, void *);
    int cmp_result;
    int i;
    int max_level; int l;
    void *return_item;
    compar = t->compar;
    update = t->update;
    max_level = t->max_level;
    forward = t->head_ptrs;
    i = max_level - 1;
    for(;;) {
 while(forward[i] == ((void *)0)) {
     update[i] = &forward[i];
     i--;
            if(i < 0) goto end_find_loop;
 }
        while((cmp_result = compar(forward[i]->item, item)) >= 0) {
     update[i] = &forward[i];
     i--;
     if(i < 0) goto end_find_loop;
 }
 forward = forward[i]->forward;
    }
  end_find_loop:
    remove_node = forward[0];
    if(remove_node == ((void *)0) || cmp_result != 0) return ((void *)0);
    l = remove_node->size;
    forward = remove_node->forward;
    for(i = 0; i < l; i++) {
        *update[i] = forward[i];
    }
    return_item = remove_node->item;
    free(forward);
    free(remove_node);
    t->n--;
    return return_item;
}

variable_types:
item
void *

variable_types: struct skip_node { void *item; struct skip_node **forward; int size; } ***

variable_types: l int


original_code:
void *skip_list_delete_min(skip_list_t *t)
{
    skip_node_t *remove_node, **forward, **head_ptrs;
    int i;
    int l;
    void *return_item;
    remove_node = t->head_ptrs[0];
    if(!remove_node) return ((void *)0);
    l = remove_node->size;
    head_ptrs = t->head_ptrs;
    forward = remove_node->forward;
    for(i = 0; i < l; i++) {
        head_ptrs[i] = forward[i];
    }
    return_item = remove_node->item;
    free(forward);
    free(remove_node);
    t->n--;
    return return_item;
}

canonical_original_code:
void *skip_list_delete_min(struct skip_list *t)
{
    struct skip_node *remove_node; struct skip_node **forward; struct skip_node **head_ptrs;
    int i;
    int l;
    void *return_item;
    remove_node = t->head_ptrs[0];
    if(!remove_node) return ((void *)0);
    l = remove_node->size;
    head_ptrs = t->head_ptrs;
    forward = remove_node->forward;
    for(i = 0; i < l; i++) {
        head_ptrs[i] = forward[i];
    }
    return_item = remove_node->item;
    free(forward);
    free(remove_node);
    t->n--;
    return return_item;
}


decompiled_code:
__int64 __fastcall skip_list_rand_level(int a1, double a2)
{
double v2; // xmm0_8
unsigned int i; // er12

v2 = a2 * 2147483647.0;
if ( a1 <= 1 )
return 1;
for ( i = 1; i != a1; ++i )
{
if ( rand() > (int)v2 )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, double a2)
{
double v2; // xmm0_8
unsigned int i; // er12

v2 = a2 * 2147483647.0;
if ( a1 <= 1 )
return 1;
for ( i = 1; i != a1; ++i )
{
if ( rand() > (int)v2 )
break;
}
return i;
}

original_code:
int skip_list_rand_level(double p, int max_level)
{
    int i, rand_mark;
    rand_mark = p * 2147483647;
    for(i = 1; i < max_level; i++) {
        if(rand() > rand_mark) break;
    }
    return i;
}

canonical_original_code:
int skip_list_rand_level(double p, int max_level)
{
    int i; int rand_mark;
    rand_mark = p * 2147483647;
    for(i = 1; i < max_level; i++) {
        if(rand() > rand_mark) break;
    }
    return i;
}

variable_types: p double


original_code:
void *skip_list_insert(skip_list_t *t, void *item)
{
    skip_node_t *new_node, **forward, ***update;
    int (* compar)(const void *, const void *);
    int cmp_result;
    int i;
    int max_level, l;
    compar = t->compar;
    update = t->update;
    max_level = t->max_level;
    forward = t->head_ptrs;
    i = max_level - 1;
    for(;;) {
 while(forward[i] == ((void *)0)) {
     update[i] = &forward[i];
     i--;
            if(i < 0) goto end_find_loop;
 }
        while((cmp_result = compar(forward[i]->item, item)) >= 0) {
     update[i] = &forward[i];
     i--;
     if(i < 0) goto end_find_loop;
 }
 forward = forward[i]->forward;
    }
  end_find_loop:
    if(forward[0] && cmp_result == 0) return forward[0]->item;
    new_node = malloc(sizeof(skip_node_t));
    l = new_node->size = skip_list_rand_level(t->p, max_level);
    forward = new_node->forward = malloc(l * sizeof(skip_node_t *));
    new_node->item = item;
    for(i = 0; i < l; i++) {
 forward[i] = *update[i];
 *update[i] = new_node;
    }
    t->n++;
    return ((void *)0);
}

canonical_original_code:
void *skip_list_insert(struct skip_list *t, void *item)
{
    struct skip_node *new_node; struct skip_node **forward; struct skip_node ***update;
    int (*compar)(void *, void *);
    int cmp_result;
    int i;
    int max_level; int l;
    compar = t->compar;
    update = t->update;
    max_level = t->max_level;
    forward = t->head_ptrs;
    i = max_level - 1;
    for(;;) {
 while(forward[i] == ((void *)0)) {
     update[i] = &forward[i];
     i--;
            if(i < 0) goto end_find_loop;
 }
        while((cmp_result = compar(forward[i]->item, item)) >= 0) {
     update[i] = &forward[i];
     i--;
     if(i < 0) goto end_find_loop;
 }
 forward = forward[i]->forward;
    }
  end_find_loop:
    if(forward[0] && cmp_result == 0) return forward[0]->item;
    new_node = malloc(sizeof(skip_node_t));
    l = new_node->size = skip_list_rand_level(t->p, max_level);
    forward = new_node->forward = malloc(l * sizeof(struct skip_node *));
    new_node->item = item;
    for(i = 0; i < l; i++) {
 forward[i] = *update[i];
 *update[i] = new_node;
    }
    t->n++;
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall sc_recursive(int a1)
{
__int64 v1; // r13
__int64 v2; // rbp
_DWORD *v3; // rdx
char *v4; // rsi
int v5; // ecx
_DWORD *v6; // r9
unsigned int *v7; // rdi
int *v8; // r8
int *v9; // r11
__int64 v10; // rcx
int *v11; // rbx
__int64 v12; // r12
int v13; // eax
__int64 result; // rax
int v15; // edx
int v16; // edx
_DWORD *v17; // r8
__int64 v18; // rdi
_DWORD *v19; // rsi
int v20; // eax
int v21; // ecx

v1 = a1;
v2 = 4LL * a1;
v3 = visit_nos;
v4 = (char *)low_link_nos;
v5 = n_visited;
v6 = p;
v7 = (unsigned int *)((char *)visit_nos + v2);
v8 = (int *)((char *)low_link_nos + v2);
v9 = (int *)unvisited;
*(_DWORD *)((char *)visit_nos + v2) = n_visited;
*v8 = v5;
++n_visited;
v10 = v9[--n_unvisited];
v9[v6[(unsigned __int64)v2 / 4]] = v10;
v6[v10] = v6[(unsigned __int64)v2 / 4];
*((_DWORD *)sc_stack + tos) = v1;
LODWORD(v10) = tos;
*((_DWORD *)ptr + v1) = tos;
v11 = *(int **)(vertices + 16 * v1);
tos = v10 + 1;
if ( v11 )
{
do
{
while ( 1 )
{
v12 = *v11;
v13 = v3[v12];
if ( v13 == -1 )
break;
if ( v13 < v3[(unsigned __int64)v2 / 4] && *((_DWORD *)ptr + v12) != -1 && v13 < *(_DWORD *)&v4[v2] )
*(_DWORD *)&v4[v2] = v13;
v11 = (int *)*((_QWORD *)v11 + 1);
if ( !v11 )
goto LABEL_8;
}
sc_recursive(*v11);
v4 = (char *)low_link_nos;
v15 = *((_DWORD *)low_link_nos + v12);
if ( v15 < *(_DWORD *)((char *)low_link_nos + v2) )
*(_DWORD *)((char *)low_link_nos + v2) = v15;
v11 = (int *)*((_QWORD *)v11 + 1);
v3 = visit_nos;
}
while ( v11 );
LABEL_8:
v8 = (int *)&v4[v2];
v7 = &v3[(unsigned __int64)v2 / 4];
}
result = *v7;
if ( *v8 == (_DWORD)result )
{
v16 = n_written;
v17 = sc_stack;
v18 = sc_vertices;
v19 = ptr;
*(_DWORD *)(sets_s + 4LL * n_sets) = n_written;
do
{
v20 = v17[--tos];
*(_DWORD *)(v18 + 4LL * v16) = v20;
v19[v20] = -1;
v21 = n_written;
v16 = ++n_written;
}
while ( v20 != (_DWORD)v1 );
result = sets_f;
*(_DWORD *)(sets_f + 4LL * n_sets++) = v21;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // r13
__int64 v2; // rbp
_DWORD *v3; // rdx
char *v4; // rsi
int v5; // ecx
_DWORD *v6; // r9
unsigned int *v7; // rdi
int *v8; // r8
int *v9; // r11
__int64 v10; // rcx
int *v11; // rbx
__int64 v12; // r12
int v13; // eax
__int64 result; // rax
int v15; // edx
int v16; // edx
_DWORD *v17; // r8
__int64 v18; // rdi
_DWORD *v19; // rsi
int v20; // eax
int v21; // ecx

v1 = a1;
v2 = 4LL * a1;
v3 = visit_nos;
v4 = (char *)low_link_nos;
v5 = n_visited;
v6 = p;
v7 = (unsigned int *)((char *)visit_nos + v2);
v8 = (int *)((char *)low_link_nos + v2);
v9 = (int *)unvisited;
*(_DWORD *)((char *)visit_nos + v2) = n_visited;
*v8 = v5;
++n_visited;
v10 = v9[--n_unvisited];
v9[v6[(unsigned __int64)v2 / 4]] = v10;
v6[v10] = v6[(unsigned __int64)v2 / 4];
*((_DWORD *)sc_stack + tos) = v1;
LODWORD(v10) = tos;
*((_DWORD *)ptr + v1) = tos;
v11 = *(int **)(vertices + 16 * v1);
tos = v10 + 1;
if ( v11 )
{
do
{
while ( 1 )
{
v12 = *v11;
v13 = v3[v12];
if ( v13 == -1 )
break;
if ( v13 < v3[(unsigned __int64)v2 / 4] && *((_DWORD *)ptr + v12) != -1 && v13 < *(_DWORD *)&v4[v2] )
*(_DWORD *)&v4[v2] = v13;
v11 = (int *)*((_QWORD *)v11 + 1);
if ( !v11 )
goto LABEL_8;
}
func0(*v11);
v4 = (char *)low_link_nos;
v15 = *((_DWORD *)low_link_nos + v12);
if ( v15 < *(_DWORD *)((char *)low_link_nos + v2) )
*(_DWORD *)((char *)low_link_nos + v2) = v15;
v11 = (int *)*((_QWORD *)v11 + 1);
v3 = visit_nos;
}
while ( v11 );
LABEL_8:
v8 = (int *)&v4[v2];
v7 = &v3[(unsigned __int64)v2 / 4];
}
result = *v7;
if ( *v8 == (_DWORD)result )
{
v16 = n_written;
v17 = sc_stack;
v18 = sc_vertices;
v19 = ptr;
*(_DWORD *)(sets_s + 4LL * n_sets) = n_written;
do
{
v20 = v17[--tos];
*(_DWORD *)(v18 + 4LL * v16) = v20;
v19[v20] = -1;
v21 = n_written;
v16 = ++n_written;
}
while ( v20 != (_DWORD)v1 );
result = sets_f;
*(_DWORD *)(sets_f + 4LL * n_sets++) = v21;
}
return result;
}

original_code:
void sc_recursive(int v)
{
    dgraph_edge_t *edge_ptr;
    int w, replace_v;
    low_link_nos[v] = visit_nos[v] = n_visited;
    n_visited++;
    n_unvisited--;
    replace_v = unvisited[p[v]] = unvisited[n_unvisited];
    p[replace_v] = p[v];
    sc_stack[tos] = v;
    sp[v] = tos;
    tos++;
    edge_ptr = vertices[v].first_edge;
    while(edge_ptr) {
        w = edge_ptr->vertex_no;
        if(visit_nos[w] == -1) {
     sc_recursive(w);
     if(low_link_nos[w] < low_link_nos[v])
  low_link_nos[v] = low_link_nos[w];
 }
 else if(visit_nos[w] < visit_nos[v] && sp[w] != -1) {
            if(visit_nos[w] < low_link_nos[v]) low_link_nos[v] = visit_nos[w];
 }
        edge_ptr = edge_ptr->next;
    }
    if(low_link_nos[v] == visit_nos[v]) {
 sets_s[n_sets] = n_written;
        do {
     tos--;
            replace_v = sc_vertices[n_written] = sc_stack[tos];
     sp[replace_v] = -1;
     n_written++;
 } while(replace_v != v);
 sets_f[n_sets] = n_written - 1;
 n_sets++;
    }
}

canonical_original_code:
void sc_recursive(int v)
{
    struct dgraph_edge *edge_ptr;
    int w; int replace_v;
    low_link_nos[v] = visit_nos[v] = n_visited;
    n_visited++;
    n_unvisited--;
    replace_v = unvisited[p[v]] = unvisited[n_unvisited];
    p[replace_v] = p[v];
    sc_stack[tos] = v;
    sp[v] = tos;
    tos++;
    edge_ptr = vertices[v].first_edge;
    while(edge_ptr) {
        w = edge_ptr->vertex_no;
        if(visit_nos[w] == -1) {
     sc_recursive(w);
     if(low_link_nos[w] < low_link_nos[v])
  low_link_nos[v] = low_link_nos[w];
 }
 else if(visit_nos[w] < visit_nos[v] && sp[w] != -1) {
            if(visit_nos[w] < low_link_nos[v]) low_link_nos[v] = visit_nos[w];
 }
        edge_ptr = edge_ptr->next;
    }
    if(low_link_nos[v] == visit_nos[v]) {
 sets_s[n_sets] = n_written;
        do {
     tos--;
            replace_v = sc_vertices[n_written] = sc_stack[tos];
     sp[replace_v] = -1;
     n_written++;
 } while(replace_v != v);
 sets_f[n_sets] = n_written - 1;
 n_sets++;
    }
}

variable_types: v int

variable_types: struct dgraph_edge { int vertex_no; int dist; struct dgraph_edge *next; } *

variable_types: w int


decompiled_code:
void __fastcall sc_result_free(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void sc_result_free(sc_result_t *r)
{
    free(r->vertices);
    free(r->sets_s);
    free(r->sets_f);
    free(r);
}

canonical_original_code:
void sc_result_free(struct sc_result *r)
{
    free(r->vertices);
    free(r->sets_s);
    free(r->sets_f);
    free(r);
}

variable_types: struct sc_result { int size; int *vertices; int *sets_s; } *


decompiled_code:
int __fastcall sc_result_print(__int64 a1)
{
__int64 v1; // r14
int result; // eax
__int64 i; // r13
int v4; // ebx
__int64 v5; // rbp
__int64 v6; // rsi

v1 = *(int *)(a1 + 4);
result = printf("%d SC components:\n\n", (unsigned int)v1);
if ( (int)v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
printf("SC%d =", (unsigned int)i);
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 4 * i);
if ( v4 <= *(_DWORD *)(*(_QWORD *)(a1 + 24) + 4 * i) )
{
v5 = 4LL * v4;
do
{
++v4;
v6 = *(unsigned int *)(*(_QWORD *)(a1 + 8) + v5);
v5 += 4LL;
printf(" %3d", v6);
}
while ( *(_DWORD *)(*(_QWORD *)(a1 + 24) + 4 * i) >= v4 );
}
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // r14
int result; // eax
__int64 i; // r13
int v4; // ebx
__int64 v5; // rbp
__int64 v6; // rsi

v1 = *(int *)(a1 + 4);
result = printf("%d SC components:\n\n", (unsigned int)v1);
if ( (int)v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
printf("SC%d =", (unsigned int)i);
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 4 * i);
if ( v4 <= *(_DWORD *)(*(_QWORD *)(a1 + 24) + 4 * i) )
{
v5 = 4LL * v4;
do
{
++v4;
v6 = *(unsigned int *)(*(_QWORD *)(a1 + 8) + v5);
v5 += 4LL;
printf(" %3d", v6);
}
while ( *(_DWORD *)(*(_QWORD *)(a1 + 24) + 4 * i) >= v4 );
}
result = putchar(10);
}
}
return result;
}

original_code:
void sc_result_print(sc_result_t *r)
{
    int i, j, n_sets;
    n_sets = r->n_sets;
    printf("%d SC components:\n\n", n_sets);
    for(i = 0; i < n_sets; i++) {
 printf("SC%d =", i);
 for(j = r->sets_s[i]; j <= r->sets_f[i]; j++) {
            printf(" %3d", r->vertices[j]);
 }
 putchar('\n');
    }
}

canonical_original_code:
void sc_result_print(struct sc_result *r)
{
    int i; int j; int n_sets;
    n_sets = r->n_sets;
    printf("%d SC components:\n\n", n_sets);
    for(i = 0; i < n_sets; i++) {
 printf("SC%d =", i);
 for(j = r->sets_s[i]; j <= r->sets_f[i]; j++) {
            printf(" %3d", r->vertices[j]);
 }
 putchar('\n');
    }
}

variable_types: i int

variable_types: j int

user_defined_types: struct sc_result { int size; int *vertices; int *sets_s; }


decompiled_code:
__int64 __fastcall item_value(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned int item_value(const void *item)
{
    return ((test_item_t *)item)->data1;
}

canonical_original_code:
unsigned int item_value(void *item)
{
    return ((struct test_item *)item)->data1;
}

user_defined_types: struct test_item { int data1; int data2; }


indent

decompiled_code:
int __fastcall indent(int a1)
{
int v1; // ebx
int result; // eax

if ( 2 * a1 > 0 )
{
v1 = 0;
do
{
++v1;
result = putchar(32);
}
while ( v1 != 2 * a1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
int v1; // ebx
int result; // eax

if ( 2 * a1 > 0 )
{
v1 = 0;
do
{
++v1;
result = putchar(32);
}
while ( v1 != 2 * a1 );
}
return result;
}

original_code:
void indent(int l) {
    int i;
    for(i = 0; i < 2*l; i++) {
        putchar(' ');
    }
}